am 8714a343: am ef6c9470: Merge "docs: Added step to get JDK to the Android Studio install instructions." into klp-docs

* commit '8714a3437e13b4a403e49c4c624f272dd6dc8f4e':
  docs: Added step to get JDK to the Android Studio install instructions.
diff --git a/Android.mk b/Android.mk
index 9f8afb9..7cbc339 100644
--- a/Android.mk
+++ b/Android.mk
@@ -59,6 +59,8 @@
 	core/java/android/accounts/IAccountManagerResponse.aidl \
 	core/java/android/accounts/IAccountAuthenticator.aidl \
 	core/java/android/accounts/IAccountAuthenticatorResponse.aidl \
+	core/java/android/app/IActivityContainer.aidl \
+	core/java/android/app/IActivityContainerCallback.aidl \
 	core/java/android/app/IActivityController.aidl \
 	core/java/android/app/IActivityPendingResult.aidl \
 	core/java/android/app/IAlarmManager.aidl \
@@ -174,6 +176,7 @@
 	core/java/android/print/IWriteResultCallback.aidl \
 	core/java/android/printservice/IPrintService.aidl \
 	core/java/android/printservice/IPrintServiceClient.aidl \
+	core/java/android/service/dreams/IDozeHardware.aidl \
 	core/java/android/service/dreams/IDreamManager.aidl \
 	core/java/android/service/dreams/IDreamService.aidl \
 	core/java/android/service/wallpaper/IWallpaperConnection.aidl \
@@ -462,8 +465,8 @@
 # Common sources for doc check and api check
 common_src_files := \
 	$(call find-other-html-files, $(html_dirs)) \
-	$(addprefix ../../libcore/, $(call libcore_to_document, $(LOCAL_PATH)/../../libcore)) \
-	$(addprefix ../../external/junit/, $(call junit_to_document, $(LOCAL_PATH)/../../external/junit))
+	$(addprefix ../../libcore/, $(libcore_to_document)) \
+	$(addprefix ../../external/junit/, $(junit_to_document))
 
 # These are relative to frameworks/base
 framework_docs_LOCAL_SRC_FILES := \
diff --git a/CleanSpec.mk b/CleanSpec.mk
index cfa8be9..ef3f4ae 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -184,7 +184,7 @@
 $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/media/audio/effects/)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/framework-res_intermediates)
 $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework-base_intermediates/src/core/java/android/print/IPrintClient.*)
-
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/services_intermediates)
 # ************************************************
 # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
 # ************************************************
diff --git a/api/current.txt b/api/current.txt
index 8e69592..391cb9b 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -311,6 +311,7 @@
     field public static final int backgroundSplit = 16843659; // 0x101038b
     field public static final int backgroundStacked = 16843658; // 0x101038a
     field public static final int backupAgent = 16843391; // 0x101027f
+    field public static final int banner = 16843762; // 0x10103f2
     field public static final int baseline = 16843548; // 0x101031c
     field public static final int baselineAlignBottom = 16843042; // 0x1010122
     field public static final int baselineAligned = 16843046; // 0x1010126
@@ -2850,6 +2851,7 @@
     method public void onUserInteraction();
     method protected void onUserLeaveHint();
     method public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams);
+    method public void onWindowDismissed();
     method public void onWindowFocusChanged(boolean);
     method public android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback);
     method public void openContextMenu(android.view.View);
@@ -3366,6 +3368,7 @@
     method public boolean onTouchEvent(android.view.MotionEvent);
     method public boolean onTrackballEvent(android.view.MotionEvent);
     method public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams);
+    method public void onWindowDismissed();
     method public void onWindowFocusChanged(boolean);
     method public android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback);
     method public void openContextMenu(android.view.View);
@@ -3941,6 +3944,7 @@
     field public static final int FLAG_FOREGROUND_SERVICE = 64; // 0x40
     field public static final deprecated int FLAG_HIGH_PRIORITY = 128; // 0x80
     field public static final int FLAG_INSISTENT = 4; // 0x4
+    field public static final int FLAG_LOCAL_ONLY = 256; // 0x100
     field public static final int FLAG_NO_CLEAR = 32; // 0x20
     field public static final int FLAG_ONGOING_EVENT = 2; // 0x2
     field public static final int FLAG_ONLY_ALERT_ONCE = 8; // 0x8
@@ -4007,7 +4011,9 @@
   public static class Notification.Builder {
     ctor public Notification.Builder(android.content.Context);
     method public android.app.Notification.Builder addAction(int, java.lang.CharSequence, android.app.PendingIntent);
+    method public android.app.Notification.Builder addExtras(android.os.Bundle);
     method public android.app.Notification build();
+    method public android.os.Bundle getExtras();
     method public deprecated android.app.Notification getNotification();
     method public android.app.Notification.Builder setAutoCancel(boolean);
     method public android.app.Notification.Builder setContent(android.widget.RemoteViews);
@@ -4021,6 +4027,7 @@
     method public android.app.Notification.Builder setFullScreenIntent(android.app.PendingIntent, boolean);
     method public android.app.Notification.Builder setLargeIcon(android.graphics.Bitmap);
     method public android.app.Notification.Builder setLights(int, int, int);
+    method public android.app.Notification.Builder setLocalOnly(boolean);
     method public android.app.Notification.Builder setNumber(int);
     method public android.app.Notification.Builder setOngoing(boolean);
     method public android.app.Notification.Builder setOnlyAlertOnce(boolean);
@@ -6442,6 +6449,7 @@
     field public static final java.lang.String CATEGORY_HOME = "android.intent.category.HOME";
     field public static final java.lang.String CATEGORY_INFO = "android.intent.category.INFO";
     field public static final java.lang.String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
+    field public static final java.lang.String CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER";
     field public static final java.lang.String CATEGORY_LE_DESK_DOCK = "android.intent.category.LE_DESK_DOCK";
     field public static final java.lang.String CATEGORY_MONKEY = "android.intent.category.MONKEY";
     field public static final java.lang.String CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
@@ -7072,6 +7080,7 @@
     ctor public ComponentInfo();
     ctor public ComponentInfo(android.content.pm.ComponentInfo);
     ctor protected ComponentInfo(android.os.Parcel);
+    method public final int getBannerResource();
     method public final int getIconResource();
     method public final int getLogoResource();
     method public boolean isEnabled();
@@ -7175,11 +7184,13 @@
     ctor protected PackageItemInfo(android.os.Parcel);
     method protected void dumpBack(android.util.Printer, java.lang.String);
     method protected void dumpFront(android.util.Printer, java.lang.String);
+    method public android.graphics.drawable.Drawable loadBanner(android.content.pm.PackageManager);
     method public android.graphics.drawable.Drawable loadIcon(android.content.pm.PackageManager);
     method public java.lang.CharSequence loadLabel(android.content.pm.PackageManager);
     method public android.graphics.drawable.Drawable loadLogo(android.content.pm.PackageManager);
     method public android.content.res.XmlResourceParser loadXmlMetaData(android.content.pm.PackageManager, java.lang.String);
     method public void writeToParcel(android.os.Parcel, int);
+    field public int banner;
     field public int icon;
     field public int labelRes;
     field public int logo;
@@ -7207,12 +7218,16 @@
     method public abstract void clearPackagePreferredActivities(java.lang.String);
     method public abstract java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
     method public abstract void extendVerificationTimeout(int, int, long);
+    method public abstract android.graphics.drawable.Drawable getActivityBanner(android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public abstract android.graphics.drawable.Drawable getActivityBanner(android.content.Intent) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.graphics.drawable.Drawable getActivityIcon(android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.graphics.drawable.Drawable getActivityIcon(android.content.Intent) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.pm.ActivityInfo getActivityInfo(android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.graphics.drawable.Drawable getActivityLogo(android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.graphics.drawable.Drawable getActivityLogo(android.content.Intent) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract java.util.List<android.content.pm.PermissionGroupInfo> getAllPermissionGroups(int);
+    method public abstract android.graphics.drawable.Drawable getApplicationBanner(android.content.pm.ApplicationInfo);
+    method public abstract android.graphics.drawable.Drawable getApplicationBanner(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract int getApplicationEnabledSetting(java.lang.String);
     method public abstract android.graphics.drawable.Drawable getApplicationIcon(android.content.pm.ApplicationInfo);
     method public abstract android.graphics.drawable.Drawable getApplicationIcon(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -7277,6 +7292,7 @@
     field public static final java.lang.String EXTRA_VERIFICATION_RESULT = "android.content.pm.extra.VERIFICATION_RESULT";
     field public static final java.lang.String FEATURE_APP_WIDGETS = "android.software.app_widgets";
     field public static final java.lang.String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
+    field public static final java.lang.String FEATURE_BACKUP = "android.software.backup";
     field public static final java.lang.String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
     field public static final java.lang.String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
     field public static final java.lang.String FEATURE_CAMERA = "android.hardware.camera";
@@ -7298,6 +7314,7 @@
     field public static final java.lang.String FEATURE_MICROPHONE = "android.hardware.microphone";
     field public static final java.lang.String FEATURE_NFC = "android.hardware.nfc";
     field public static final java.lang.String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
+    field public static final java.lang.String FEATURE_PRINTING = "android.software.print";
     field public static final java.lang.String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
     field public static final java.lang.String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
     field public static final java.lang.String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
@@ -7320,6 +7337,7 @@
     field public static final java.lang.String FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND = "android.hardware.touchscreen.multitouch.jazzhand";
     field public static final java.lang.String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
     field public static final java.lang.String FEATURE_USB_HOST = "android.hardware.usb.host";
+    field public static final java.lang.String FEATURE_WATCH = "android.hardware.type.watch";
     field public static final java.lang.String FEATURE_WIFI = "android.hardware.wifi";
     field public static final java.lang.String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
     field public static final int GET_ACTIVITIES = 1; // 0x1
@@ -10870,6 +10888,7 @@
     method public void registerDisplayListener(android.hardware.display.DisplayManager.DisplayListener, android.os.Handler);
     method public void unregisterDisplayListener(android.hardware.display.DisplayManager.DisplayListener);
     field public static final java.lang.String DISPLAY_CATEGORY_PRESENTATION = "android.hardware.display.category.PRESENTATION";
+    field public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 8; // 0x8
     field public static final int VIRTUAL_DISPLAY_FLAG_PRESENTATION = 2; // 0x2
     field public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1; // 0x1
     field public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 4; // 0x4
@@ -11027,7 +11046,10 @@
     method public int getDeviceSubclass();
     method public android.hardware.usb.UsbInterface getInterface(int);
     method public int getInterfaceCount();
+    method public java.lang.String getManufacturerName();
     method public int getProductId();
+    method public java.lang.String getProductName();
+    method public java.lang.String getSerialNumber();
     method public int getVendorId();
     method public void writeToParcel(android.os.Parcel, int);
     field public static final android.os.Parcelable.Creator CREATOR;
@@ -17648,6 +17670,7 @@
     method public static void startMethodTracing(java.lang.String);
     method public static void startMethodTracing(java.lang.String, int);
     method public static void startMethodTracing(java.lang.String, int, int);
+    method public static void startMethodTracingSampling(java.lang.String, int, int);
     method public static void startNativeTracing();
     method public static deprecated void stopAllocCounting();
     method public static void stopMethodTracing();
@@ -22691,6 +22714,7 @@
     method public boolean onPreparePanel(int, android.view.View, android.view.Menu);
     method public boolean onSearchRequested();
     method public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams);
+    method public void onWindowDismissed();
     method public void onWindowFocusChanged(boolean);
     method public android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback);
     method public void setContentView(int);
@@ -24053,12 +24077,16 @@
     method public void clearPackagePreferredActivities(java.lang.String);
     method public java.lang.String[] currentToCanonicalPackageNames(java.lang.String[]);
     method public void extendVerificationTimeout(int, int, long);
+    method public android.graphics.drawable.Drawable getActivityBanner(android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
+    method public android.graphics.drawable.Drawable getActivityBanner(android.content.Intent) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.graphics.drawable.Drawable getActivityIcon(android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.graphics.drawable.Drawable getActivityIcon(android.content.Intent) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.content.pm.ActivityInfo getActivityInfo(android.content.ComponentName, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.graphics.drawable.Drawable getActivityLogo(android.content.ComponentName) throws android.content.pm.PackageManager.NameNotFoundException;
     method public android.graphics.drawable.Drawable getActivityLogo(android.content.Intent) throws android.content.pm.PackageManager.NameNotFoundException;
     method public java.util.List<android.content.pm.PermissionGroupInfo> getAllPermissionGroups(int);
+    method public android.graphics.drawable.Drawable getApplicationBanner(android.content.pm.ApplicationInfo);
+    method public android.graphics.drawable.Drawable getApplicationBanner(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public int getApplicationEnabledSetting(java.lang.String);
     method public android.graphics.drawable.Drawable getApplicationIcon(android.content.pm.ApplicationInfo);
     method public android.graphics.drawable.Drawable getApplicationIcon(java.lang.String) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -26171,7 +26199,6 @@
     method public final java.lang.CharSequence coerceToString();
     method public static final java.lang.String coerceToString(int, int);
     method public static float complexToDimension(int, android.util.DisplayMetrics);
-    method public static float complexToDimensionNoisy(int, android.util.DisplayMetrics);
     method public static int complexToDimensionPixelOffset(int, android.util.DisplayMetrics);
     method public static int complexToDimensionPixelSize(int, android.util.DisplayMetrics);
     method public static float complexToFloat(int);
@@ -26889,6 +26916,7 @@
     field public static final int KEYCODE_SHIFT_LEFT = 59; // 0x3b
     field public static final int KEYCODE_SHIFT_RIGHT = 60; // 0x3c
     field public static final int KEYCODE_SLASH = 76; // 0x4c
+    field public static final int KEYCODE_SLEEP = 223; // 0xdf
     field public static final int KEYCODE_SOFT_LEFT = 1; // 0x1
     field public static final int KEYCODE_SOFT_RIGHT = 2; // 0x2
     field public static final int KEYCODE_SPACE = 62; // 0x3e
@@ -26910,6 +26938,7 @@
     field public static final int KEYCODE_VOLUME_MUTE = 164; // 0xa4
     field public static final int KEYCODE_VOLUME_UP = 24; // 0x18
     field public static final int KEYCODE_W = 51; // 0x33
+    field public static final int KEYCODE_WAKEUP = 224; // 0xe0
     field public static final int KEYCODE_WINDOW = 171; // 0xab
     field public static final int KEYCODE_X = 52; // 0x34
     field public static final int KEYCODE_Y = 53; // 0x35
@@ -28639,6 +28668,7 @@
     field public static final int FEATURE_OPTIONS_PANEL = 0; // 0x0
     field public static final int FEATURE_PROGRESS = 2; // 0x2
     field public static final int FEATURE_RIGHT_ICON = 4; // 0x4
+    field public static final int FEATURE_SWIPE_TO_DISMISS = 11; // 0xb
     field public static final int ID_ANDROID_CONTENT = 16908290; // 0x1020002
     field public static final int PROGRESS_END = 10000; // 0x2710
     field public static final int PROGRESS_INDETERMINATE_OFF = -4; // 0xfffffffc
@@ -28670,6 +28700,7 @@
     method public abstract boolean onPreparePanel(int, android.view.View, android.view.Menu);
     method public abstract boolean onSearchRequested();
     method public abstract void onWindowAttributesChanged(android.view.WindowManager.LayoutParams);
+    method public abstract void onWindowDismissed();
     method public abstract void onWindowFocusChanged(boolean);
     method public abstract android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback);
   }
@@ -42716,11 +42747,11 @@
   }
 
   public class ConcurrentHashMap extends java.util.AbstractMap implements java.util.concurrent.ConcurrentMap java.io.Serializable {
-    ctor public ConcurrentHashMap(int, float, int);
-    ctor public ConcurrentHashMap(int, float);
-    ctor public ConcurrentHashMap(int);
     ctor public ConcurrentHashMap();
+    ctor public ConcurrentHashMap(int);
     ctor public ConcurrentHashMap(java.util.Map<? extends K, ? extends V>);
+    ctor public ConcurrentHashMap(int, float);
+    ctor public ConcurrentHashMap(int, float, int);
     method public boolean contains(java.lang.Object);
     method public java.util.Enumeration<V> elements();
     method public java.util.Set<java.util.Map.Entry<K, V>> entrySet();
@@ -44160,12 +44191,12 @@
   public final class Matcher implements java.util.regex.MatchResult {
     method public java.util.regex.Matcher appendReplacement(java.lang.StringBuffer, java.lang.String);
     method public java.lang.StringBuffer appendTail(java.lang.StringBuffer);
-    method public int end(int);
     method public int end();
+    method public int end(int);
     method public boolean find(int);
     method public boolean find();
-    method public java.lang.String group(int);
     method public java.lang.String group();
+    method public java.lang.String group(int);
     method public int groupCount();
     method public boolean hasAnchoringBounds();
     method public boolean hasTransparentBounds();
@@ -44182,8 +44213,8 @@
     method public boolean requireEnd();
     method public java.util.regex.Matcher reset();
     method public java.util.regex.Matcher reset(java.lang.CharSequence);
-    method public int start(int) throws java.lang.IllegalStateException;
     method public int start();
+    method public int start(int) throws java.lang.IllegalStateException;
     method public java.util.regex.MatchResult toMatchResult();
     method public java.util.regex.Matcher useAnchoringBounds(boolean);
     method public java.util.regex.Matcher usePattern(java.util.regex.Pattern);
@@ -50924,7 +50955,7 @@
     method public java.lang.String getString(java.lang.String) throws org.json.JSONException;
     method public boolean has(java.lang.String);
     method public boolean isNull(java.lang.String);
-    method public java.util.Iterator keys();
+    method public java.util.Iterator<java.lang.String> keys();
     method public int length();
     method public org.json.JSONArray names();
     method public static java.lang.String numberToString(java.lang.Number) throws org.json.JSONException;
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 0344d26..89e15d2 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -19,8 +19,9 @@
 package com.android.commands.am;
 
 import android.app.ActivityManager;
-import android.app.ActivityManager.StackBoxInfo;
+import android.app.ActivityManager.StackInfo;
 import android.app.ActivityManagerNative;
+import android.app.IActivityContainer;
 import android.app.IActivityController;
 import android.app.IActivityManager;
 import android.app.IInstrumentationWatcher;
@@ -31,9 +32,11 @@
 import android.content.Intent;
 import android.content.pm.IPackageManager;
 import android.content.pm.ResolveInfo;
+import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Bundle;
+import android.os.IBinder;
 import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -106,11 +109,11 @@
                 "       am to-intent-uri [INTENT]\n" +
                 "       am switch-user <USER_ID>\n" +
                 "       am stop-user <USER_ID>\n" +
-                "       am stack create <TASK_ID> <RELATIVE_STACK_BOX_ID> <POSITION> <WEIGHT>\n" +
+                "       am stack start <DISPLAY_ID> <INTENT>\n" +
                 "       am stack movetask <TASK_ID> <STACK_ID> [true|false]\n" +
-                "       am stack resize <STACK_ID> <WEIGHT>\n" +
-                "       am stack boxes\n" +
-                "       am stack box <STACK_BOX_ID>\n" +
+                "       am stack resize <STACK_ID> <LEFT,TOP,RIGHT,BOTTOM>\n" +
+                "       am stack list\n" +
+                "       am stack info <STACK_ID>\n" +
                 "\n" +
                 "am start: start an Activity.  Options are:\n" +
                 "    -D: enable debugging\n" +
@@ -204,24 +207,16 @@
                 "am stop-user: stop execution of USER_ID, not allowing it to run any\n" +
                 "  code until a later explicit switch to it.\n" +
                 "\n" +
-                "am stack create: create a new stack relative to an existing one.\n" +
-                "   <TASK_ID>: the task to populate the new stack with. Must exist.\n" +
-                "   <RELATIVE_STACK_BOX_ID>: existing stack box's id.\n" +
-                "   <POSITION>: 0: before <RELATIVE_STACK_BOX_ID>, per RTL/LTR configuration,\n" +
-                "               1: after <RELATIVE_STACK_BOX_ID>, per RTL/LTR configuration,\n" +
-                "               2: to left of <RELATIVE_STACK_BOX_ID>,\n" +
-                "               3: to right of <RELATIVE_STACK_BOX_ID>," +
-                "               4: above <RELATIVE_STACK_BOX_ID>, 5: below <RELATIVE_STACK_BOX_ID>\n" +
-                "   <WEIGHT>: float between 0.2 and 0.8 inclusive.\n" +
+                "am stack start: start a new activity on <DISPLAY_ID> using <INTENT>.\n" +
                 "\n" +
                 "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> relative size to new <WEIGHT>.\n" +
+                "am stack resize: change <STACK_ID> size and position to <LEFT,TOP,RIGHT,BOTTOM>.\n" +
                 "\n" +
-                "am stack boxes: list the hierarchy of stack boxes and their contents.\n" +
+                "am stack list: list all of the activity stacks and their sizes.\n" +
                 "\n" +
-                "am stack box: list the hierarchy of stack boxes rooted at <STACK_BOX_ID>.\n" +
+                "am stack info: display the information about activity stack <STACK_ID>.\n" +
                 "\n" +
                 "<INTENT> specifications include these flags and arguments:\n" +
                 "    [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" +
@@ -1546,35 +1541,32 @@
 
     private void runStack() throws Exception {
         String op = nextArgRequired();
-        if (op.equals("create")) {
-            runStackCreate();
+        if (op.equals("start")) {
+            runStackStart();
         } else if (op.equals("movetask")) {
             runStackMoveTask();
         } else if (op.equals("resize")) {
-            runStackBoxResize();
-        } else if (op.equals("boxes")) {
-            runStackBoxes();
-        } else if (op.equals("box")) {
-            runStackBoxInfo();
+            runStackResize();
+        } else if (op.equals("list")) {
+            runStackList();
+        } else if (op.equals("info")) {
+            runStackInfo();
         } else {
             showError("Error: unknown command '" + op + "'");
             return;
         }
     }
 
-    private void runStackCreate() throws Exception {
-        String taskIdStr = nextArgRequired();
-        int taskId = Integer.valueOf(taskIdStr);
-        String relativeToStr = nextArgRequired();
-        int relativeTo = Integer.valueOf(relativeToStr);
-        String positionStr = nextArgRequired();
-        int position = Integer.valueOf(positionStr);
-        String weightStr = nextArgRequired();
-        float weight = Float.valueOf(weightStr);
+    private void runStackStart() throws Exception {
+        String displayIdStr = nextArgRequired();
+        int displayId = Integer.valueOf(displayIdStr);
+        Intent intent = makeIntent(UserHandle.USER_CURRENT);
 
         try {
-            int stackId = mAm.createStack(taskId, relativeTo, position, weight);
-            System.out.println("createStack returned new stackId=" + stackId + "\n\n");
+            IBinder homeActivityToken = mAm.getHomeActivityToken();
+            IActivityContainer container = mAm.createActivityContainer(homeActivityToken, null);
+            container.attachToDisplay(displayId);
+            container.startActivity(intent);
         } catch (RemoteException e) {
         }
     }
@@ -1601,34 +1593,40 @@
         }
     }
 
-    private void runStackBoxResize() throws Exception {
-        String stackBoxIdStr = nextArgRequired();
-        int stackBoxId = Integer.valueOf(stackBoxIdStr);
-        String weightStr = nextArgRequired();
-        float weight = Float.valueOf(weightStr);
+    private void runStackResize() throws Exception {
+        String stackIdStr = nextArgRequired();
+        int stackId = Integer.valueOf(stackIdStr);
+        String leftStr = nextArgRequired();
+        int left = Integer.valueOf(leftStr);
+        String topStr = nextArgRequired();
+        int top = Integer.valueOf(topStr);
+        String rightStr = nextArgRequired();
+        int right = Integer.valueOf(rightStr);
+        String bottomStr = nextArgRequired();
+        int bottom = Integer.valueOf(bottomStr);
 
         try {
-            mAm.resizeStackBox(stackBoxId, weight);
+            mAm.resizeStack(stackId, new Rect(left, top, right, bottom));
         } catch (RemoteException e) {
         }
     }
 
-    private void runStackBoxes() throws Exception {
+    private void runStackList() throws Exception {
         try {
-            List<StackBoxInfo> stackBoxes = mAm.getStackBoxes();
-            for (StackBoxInfo info : stackBoxes) {
+            List<StackInfo> stacks = mAm.getAllStackInfos();
+            for (StackInfo info : stacks) {
                 System.out.println(info);
             }
         } catch (RemoteException e) {
         }
     }
 
-    private void runStackBoxInfo() throws Exception {
+    private void runStackInfo() throws Exception {
         try {
-            String stackBoxIdStr = nextArgRequired();
-            int stackBoxId = Integer.valueOf(stackBoxIdStr);
-            StackBoxInfo stackBoxInfo = mAm.getStackBoxInfo(stackBoxId); 
-            System.out.println(stackBoxInfo);
+            String stackIdStr = nextArgRequired();
+            int stackId = Integer.valueOf(stackIdStr);
+            StackInfo info = mAm.getStackInfo(stackId);
+            System.out.println(info);
         } catch (RemoteException e) {
         }
     }
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp
index 28752a5..8d2b739 100644
--- a/cmds/app_process/app_main.cpp
+++ b/cmds/app_process/app_main.cpp
@@ -7,7 +7,6 @@
 
 #define LOG_TAG "appproc"
 
-#include <cutils/properties.h>
 #include <binder/IPCThreadState.h>
 #include <binder/ProcessState.h>
 #include <utils/Log.h>
@@ -15,7 +14,6 @@
 #include <cutils/memory.h>
 #include <cutils/trace.h>
 #include <android_runtime/AndroidRuntime.h>
-#include <sys/personality.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -137,33 +135,6 @@
 
 int main(int argc, char* const argv[])
 {
-#ifdef __arm__
-    /*
-     * b/7188322 - Temporarily revert to the compat memory layout
-     * to avoid breaking third party apps.
-     *
-     * THIS WILL GO AWAY IN A FUTURE ANDROID RELEASE.
-     *
-     * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7dbaa466
-     * changes the kernel mapping from bottom up to top-down.
-     * This breaks some programs which improperly embed
-     * an out of date copy of Android's linker.
-     */
-    char value[PROPERTY_VALUE_MAX];
-    property_get("ro.kernel.qemu", value, "");
-    bool is_qemu = (strcmp(value, "1") == 0);
-    if ((getenv("NO_ADDR_COMPAT_LAYOUT_FIXUP") == NULL) && !is_qemu) {
-        int current = personality(0xFFFFFFFF);
-        if ((current & ADDR_COMPAT_LAYOUT) == 0) {
-            personality(current | ADDR_COMPAT_LAYOUT);
-            setenv("NO_ADDR_COMPAT_LAYOUT_FIXUP", "1", 1);
-            execv("/system/bin/app_process", argv);
-            return -1;
-        }
-    }
-    unsetenv("NO_ADDR_COMPAT_LAYOUT_FIXUP");
-#endif
-
     // These are global variables in ProcessState.cpp
     mArgC = argc;
     mArgV = argv;
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index ad4e4c8..1a2ab81 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -52,7 +52,6 @@
 
 #include "BootAnimation.h"
 
-#define USER_BOOTANIMATION_FILE "/data/local/bootanimation.zip"
 #define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"
 #define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip"
 #define EXIT_PROP_NAME "service.bootanim.exit"
@@ -63,14 +62,19 @@
 
 namespace android {
 
+static const int ANIM_ENTRY_NAME_MAX = 256;
+
 // ---------------------------------------------------------------------------
 
-BootAnimation::BootAnimation() : Thread(false)
+BootAnimation::BootAnimation() : Thread(false), mZip(NULL)
 {
     mSession = new SurfaceComposerClient();
 }
 
 BootAnimation::~BootAnimation() {
+    if (mZip != NULL) {
+        delete mZip;
+    }
 }
 
 void BootAnimation::onFirstRef() {
@@ -86,7 +90,7 @@
 }
 
 
-void BootAnimation::binderDied(const wp<IBinder>& who)
+void BootAnimation::binderDied(const wp<IBinder>&)
 {
     // woah, surfaceflinger died!
     ALOGD("SurfaceFlinger died, exiting...");
@@ -159,8 +163,8 @@
     SkBitmap bitmap;
     SkMemoryStream  stream(buffer, len);
     SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
-    codec->setDitherImage(false);
     if (codec) {
+        codec->setDitherImage(false);
         codec->decode(&stream, &bitmap,
                 SkBitmap::kARGB_8888_Config,
                 SkImageDecoder::kDecodePixels_Mode);
@@ -268,25 +272,21 @@
     mFlingerSurfaceControl = control;
     mFlingerSurface = s;
 
-    mAndroidAnimation = true;
-
-    // If the device has encryption turned on or is in process 
+    // If the device has encryption turned on or is in process
     // of being encrypted we show the encrypted boot animation.
     char decrypt[PROPERTY_VALUE_MAX];
     property_get("vold.decrypt", decrypt, "");
 
     bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt);
 
+    ZipFileRO* zipFile = NULL;
     if ((encryptedAnimation &&
             (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0) &&
-            (mZip.open(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE) == NO_ERROR)) ||
-
-            ((access(USER_BOOTANIMATION_FILE, R_OK) == 0) &&
-            (mZip.open(USER_BOOTANIMATION_FILE) == NO_ERROR)) ||
+            ((zipFile = ZipFileRO::open(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE)) != NULL)) ||
 
             ((access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) &&
-            (mZip.open(SYSTEM_BOOTANIMATION_FILE) == NO_ERROR))) {
-        mAndroidAnimation = false;
+            ((zipFile = ZipFileRO::open(SYSTEM_BOOTANIMATION_FILE)) != NULL))) {
+        mZip = zipFile;
     }
 
     return NO_ERROR;
@@ -295,15 +295,14 @@
 bool BootAnimation::threadLoop()
 {
     bool r;
-    if (mAndroidAnimation) {
+    // We have no bootanimation file, so we use the stock android logo
+    // animation.
+    if (mZip == NULL) {
         r = android();
     } else {
         r = movie();
     }
 
-    // No need to force exit anymore
-    property_set(EXIT_PROP_NAME, "0");
-
     eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
     eglDestroyContext(mDisplay, mContext);
     eglDestroySurface(mDisplay, mSurface);
@@ -392,11 +391,14 @@
 
 bool BootAnimation::movie()
 {
-    ZipFileRO& zip(mZip);
+    ZipEntryRO desc = mZip->findEntryByName("desc.txt");
+    ALOGE_IF(!desc, "couldn't find desc.txt");
+    if (!desc) {
+        return false;
+    }
 
-    size_t numEntries = zip.getNumEntries();
-    ZipEntryRO desc = zip.findEntryByName("desc.txt");
-    FileMap* descMap = zip.createEntryFileMap(desc);
+    FileMap* descMap = mZip->createEntryFileMap(desc);
+    mZip->releaseEntry(desc);
     ALOGE_IF(!descMap, "descMap is null");
     if (!descMap) {
         return false;
@@ -415,7 +417,7 @@
         String8 line(s, endl - s);
         const char* l = line.string();
         int fps, width, height, count, pause;
-        char path[256];
+        char path[ANIM_ENTRY_NAME_MAX];
         char pathType;
         if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
             //LOGD("> w=%d, h=%d, fps=%d", width, height, fps);
@@ -438,28 +440,37 @@
 
     // read all the data structures
     const size_t pcount = animation.parts.size();
-    for (size_t i=0 ; i<numEntries ; i++) {
-        char name[256];
-        ZipEntryRO entry = zip.findEntryByIndex(i);
-        if (zip.getEntryFileName(entry, name, 256) == 0) {
-            const String8 entryName(name);
-            const String8 path(entryName.getPathDir());
-            const String8 leaf(entryName.getPathLeaf());
-            if (leaf.size() > 0) {
-                for (int j=0 ; j<pcount ; j++) {
-                    if (path == animation.parts[j].path) {
-                        int method;
-                        // supports only stored png files
-                        if (zip.getEntryInfo(entry, &method, 0, 0, 0, 0, 0)) {
-                            if (method == ZipFileRO::kCompressStored) {
-                                FileMap* map = zip.createEntryFileMap(entry);
-                                if (map) {
-                                    Animation::Frame frame;
-                                    frame.name = leaf;
-                                    frame.map = map;
-                                    Animation::Part& part(animation.parts.editItemAt(j));
-                                    part.frames.add(frame);
-                                }
+    void *cookie = NULL;
+    if (!mZip->startIteration(&cookie)) {
+        return false;
+    }
+
+    ZipEntryRO entry;
+    char name[ANIM_ENTRY_NAME_MAX];
+    while ((entry = mZip->nextEntry(cookie)) != NULL) {
+        const int foundEntryName = mZip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
+        if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
+            ALOGE("Error fetching entry file name");
+            continue;
+        }
+
+        const String8 entryName(name);
+        const String8 path(entryName.getPathDir());
+        const String8 leaf(entryName.getPathLeaf());
+        if (leaf.size() > 0) {
+            for (size_t j=0 ; j<pcount ; j++) {
+                if (path == animation.parts[j].path) {
+                    int method;
+                    // supports only stored png files
+                    if (mZip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) {
+                        if (method == ZipFileRO::kCompressStored) {
+                            FileMap* map = mZip->createEntryFileMap(entry);
+                            if (map) {
+                                Animation::Frame frame;
+                                frame.name = leaf;
+                                frame.map = map;
+                                Animation::Part& part(animation.parts.editItemAt(j));
+                                part.frames.add(frame);
                             }
                         }
                     }
@@ -468,6 +479,8 @@
         }
     }
 
+    mZip->endIteration(cookie);
+
     // clear screen
     glShadeModel(GL_FLAT);
     glDisable(GL_DITHER);
@@ -494,7 +507,7 @@
     Region clearReg(Rect(mWidth, mHeight));
     clearReg.subtractSelf(Rect(xc, yc, xc+animation.width, yc+animation.height));
 
-    for (int i=0 ; i<pcount ; i++) {
+    for (size_t i=0 ; i<pcount ; i++) {
         const Animation::Part& part(animation.parts[i]);
         const size_t fcount = part.frames.size();
         glBindTexture(GL_TEXTURE_2D, 0);
@@ -504,7 +517,7 @@
             if(exitPending() && !part.playUntilComplete)
                 break;
 
-            for (int j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) {
+            for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) {
                 const Animation::Frame& frame(part.frames[j]);
                 nsecs_t lastFrame = systemTime();
 
@@ -564,7 +577,7 @@
 
         // free the textures for this part
         if (part.count != 1) {
-            for (int j=0 ; j<fcount ; j++) {
+            for (size_t j=0 ; j<fcount ; j++) {
                 const Animation::Frame& frame(part.frames[j]);
                 glDeleteTextures(1, &frame.tid);
             }
diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h
index fa908eb..22963c2 100644
--- a/cmds/bootanimation/BootAnimation.h
+++ b/cmds/bootanimation/BootAnimation.h
@@ -95,8 +95,7 @@
     EGLDisplay  mSurface;
     sp<SurfaceControl> mFlingerSurfaceControl;
     sp<Surface> mFlingerSurface;
-    bool        mAndroidAnimation;
-    ZipFileRO   mZip;
+    ZipFileRO   *mZip;
 };
 
 // ---------------------------------------------------------------------------
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index d6db8c2..ec58fb0 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -2402,6 +2402,13 @@
         }
         return false;
     }
+
+    /**
+     * Called when the main window associated with the activity has been dismissed.
+     */
+    public void onWindowDismissed() {
+        finish();
+    }
     
     /**
      * Called to process key events.  You can override this to intercept all 
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 7ca3459..c877cd3 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -1289,106 +1289,15 @@
     }
 
     /**
-     * Information you can retrieve about the WindowManager StackBox hierarchy.
-     * @hide
-     */
-    public static class StackBoxInfo implements Parcelable {
-        public int stackBoxId;
-        public float weight;
-        public boolean vertical;
-        public Rect bounds;
-        public StackBoxInfo[] children;
-        public int stackId;
-        public StackInfo stack;
-
-        @Override
-        public int describeContents() {
-            return 0;
-        }
-
-        @Override
-        public void writeToParcel(Parcel dest, int flags) {
-            dest.writeInt(stackBoxId);
-            dest.writeFloat(weight);
-            dest.writeInt(vertical ? 1 : 0);
-            bounds.writeToParcel(dest, flags);
-            dest.writeInt(stackId);
-            if (children != null) {
-                children[0].writeToParcel(dest, flags);
-                children[1].writeToParcel(dest, flags);
-            } else {
-                stack.writeToParcel(dest, flags);
-            }
-        }
-
-        public void readFromParcel(Parcel source) {
-            stackBoxId = source.readInt();
-            weight = source.readFloat();
-            vertical = source.readInt() == 1;
-            bounds = Rect.CREATOR.createFromParcel(source);
-            stackId = source.readInt();
-            if (stackId == -1) {
-                children = new StackBoxInfo[2];
-                children[0] = StackBoxInfo.CREATOR.createFromParcel(source);
-                children[1] = StackBoxInfo.CREATOR.createFromParcel(source);
-            } else {
-                stack = StackInfo.CREATOR.createFromParcel(source);
-            }
-        }
-
-        public static final Creator<StackBoxInfo> CREATOR =
-                new Creator<ActivityManager.StackBoxInfo>() {
-
-            @Override
-            public StackBoxInfo createFromParcel(Parcel source) {
-                return new StackBoxInfo(source);
-            }
-
-            @Override
-            public StackBoxInfo[] newArray(int size) {
-                return new StackBoxInfo[size];
-            }
-        };
-
-        public StackBoxInfo() {
-        }
-
-        public StackBoxInfo(Parcel source) {
-            readFromParcel(source);
-        }
-
-        public String toString(String prefix) {
-            StringBuilder sb = new StringBuilder(256);
-            sb.append(prefix); sb.append("Box id=" + stackBoxId); sb.append(" weight=" + weight);
-            sb.append(" vertical=" + vertical); sb.append(" bounds=" + bounds.toShortString());
-            sb.append("\n");
-            if (children != null) {
-                sb.append(prefix); sb.append("First child=\n");
-                sb.append(children[0].toString(prefix + "  "));
-                sb.append(prefix); sb.append("Second child=\n");
-                sb.append(children[1].toString(prefix + "  "));
-            } else {
-                sb.append(prefix); sb.append("Stack=\n");
-                sb.append(stack.toString(prefix + "  "));
-            }
-            return sb.toString();
-        }
-
-        @Override
-        public String toString() {
-            return toString("");
-        }
-    }
-
-    /**
      * Information you can retrieve about an ActivityStack in the system.
      * @hide
      */
     public static class StackInfo implements Parcelable {
         public int stackId;
-        public Rect bounds;
+        public Rect bounds = new Rect();
         public int[] taskIds;
         public String[] taskNames;
+        public int displayId;
 
         @Override
         public int describeContents() {
@@ -1404,6 +1313,7 @@
             dest.writeInt(bounds.bottom);
             dest.writeIntArray(taskIds);
             dest.writeStringArray(taskNames);
+            dest.writeInt(displayId);
         }
 
         public void readFromParcel(Parcel source) {
@@ -1412,6 +1322,7 @@
                     source.readInt(), source.readInt(), source.readInt(), source.readInt());
             taskIds = source.createIntArray();
             taskNames = source.createStringArray();
+            displayId = source.readInt();
         }
 
         public static final Creator<StackInfo> CREATOR = new Creator<StackInfo>() {
@@ -1435,7 +1346,9 @@
         public String toString(String prefix) {
             StringBuilder sb = new StringBuilder(256);
             sb.append(prefix); sb.append("Stack id="); sb.append(stackId);
-                    sb.append(" bounds="); sb.append(bounds.toShortString()); sb.append("\n");
+                    sb.append(" bounds="); sb.append(bounds.toShortString());
+                    sb.append(" displayId="); sb.append(displayId);
+                    sb.append("\n");
             prefix = prefix + "  ";
             for (int i = 0; i < taskIds.length; ++i) {
                 sb.append(prefix); sb.append("taskId="); sb.append(taskIds[i]);
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 74266cc..7695ecc 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -16,7 +16,7 @@
 
 package android.app;
 
-import android.app.ActivityManager.StackBoxInfo;
+import android.app.ActivityManager.StackInfo;
 import android.content.ComponentName;
 import android.content.IIntentReceiver;
 import android.content.IIntentSender;
@@ -31,6 +31,7 @@
 import android.content.pm.UserInfo;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
+import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Bundle;
@@ -611,18 +612,6 @@
             return true;
         }
 
-        case CREATE_STACK_TRANSACTION: {
-            data.enforceInterface(IActivityManager.descriptor);
-            int taskId = data.readInt();
-            int relativeStackId = data.readInt();
-            int position = data.readInt();
-            float weight = data.readFloat();
-            int res = createStack(taskId, relativeStackId, position, weight);
-            reply.writeNoException();
-            reply.writeInt(res);
-            return true;
-        }
-
         case MOVE_TASK_TO_STACK_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
             int taskId = data.readInt();
@@ -635,25 +624,26 @@
 
         case RESIZE_STACK_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
-            int stackBoxId = data.readInt();
+            int stackId = data.readInt();
             float weight = data.readFloat();
-            resizeStackBox(stackBoxId, weight);
+            Rect r = Rect.CREATOR.createFromParcel(data);
+            resizeStack(stackId, r);
             reply.writeNoException();
             return true;
         }
 
-        case GET_STACK_BOXES_TRANSACTION: {
+        case GET_ALL_STACK_INFOS_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
-            List<StackBoxInfo> list = getStackBoxes();
+            List<StackInfo> list = getAllStackInfos();
             reply.writeNoException();
             reply.writeTypedList(list);
             return true;
         }
 
-        case GET_STACK_BOX_INFO_TRANSACTION: {
+        case GET_STACK_INFO_TRANSACTION: {
             data.enforceInterface(IActivityManager.descriptor);
-            int stackBoxId = data.readInt();
-            StackBoxInfo info = getStackBoxInfo(stackBoxId);
+            int stackId = data.readInt();
+            StackInfo info = getStackInfo(stackId);
             reply.writeNoException();
             if (info != null) {
                 reply.writeInt(1);
@@ -2028,6 +2018,54 @@
             reply.writeNoException();
             return true;
         }
+
+        case CREATE_ACTIVITY_CONTAINER_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            IBinder parentActivityToken = data.readStrongBinder();
+            IActivityContainerCallback callback =
+                    (IActivityContainerCallback) data.readStrongBinder();
+            IActivityContainer activityContainer =
+                    createActivityContainer(parentActivityToken, callback);
+            reply.writeNoException();
+            if (activityContainer != null) {
+                reply.writeInt(1);
+                reply.writeStrongBinder(activityContainer.asBinder());
+            } else {
+                reply.writeInt(0);
+            }
+            return true;
+        }
+
+        case DELETE_ACTIVITY_CONTAINER_TRANSACTION:  {
+            data.enforceInterface(IActivityManager.descriptor);
+            IActivityContainer activityContainer =
+                    IActivityContainer.Stub.asInterface(data.readStrongBinder());
+            deleteActivityContainer(activityContainer);
+            reply.writeNoException();
+            return true;
+        }
+
+        case GET_ACTIVITY_CONTAINER_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            IBinder activityToken = data.readStrongBinder();
+            IActivityContainer activityContainer = getEnclosingActivityContainer(activityToken);
+            reply.writeNoException();
+            if (activityContainer != null) {
+                reply.writeInt(1);
+                reply.writeStrongBinder(activityContainer.asBinder());
+            } else {
+                reply.writeInt(0);
+            }
+            return true;
+        }
+
+        case GET_HOME_ACTIVITY_TOKEN_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            IBinder homeActivityToken = getHomeActivityToken();
+            reply.writeNoException();
+            reply.writeStrongBinder(homeActivityToken);
+            return true;
+        }
         }
 
         return super.onTransact(code, data, reply, flags);
@@ -2715,24 +2753,6 @@
         reply.recycle();
     }
     @Override
-    public int createStack(int taskId, int relativeStackBoxId, int position, float weight)
-            throws RemoteException
-    {
-        Parcel data = Parcel.obtain();
-        Parcel reply = Parcel.obtain();
-        data.writeInterfaceToken(IActivityManager.descriptor);
-        data.writeInt(taskId);
-        data.writeInt(relativeStackBoxId);
-        data.writeInt(position);
-        data.writeFloat(weight);
-        mRemote.transact(CREATE_STACK_TRANSACTION, data, reply, 0);
-        reply.readException();
-        int res = reply.readInt();
-        data.recycle();
-        reply.recycle();
-        return res;
-    }
-    @Override
     public void moveTaskToStack(int taskId, int stackId, boolean toTop) throws RemoteException
     {
         Parcel data = Parcel.obtain();
@@ -2747,44 +2767,44 @@
         reply.recycle();
     }
     @Override
-    public void resizeStackBox(int stackBoxId, float weight) throws RemoteException
+    public void resizeStack(int stackBoxId, Rect r) throws RemoteException
     {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
         data.writeInterfaceToken(IActivityManager.descriptor);
         data.writeInt(stackBoxId);
-        data.writeFloat(weight);
+        r.writeToParcel(data, 0);
         mRemote.transact(RESIZE_STACK_TRANSACTION, data, reply, IBinder.FLAG_ONEWAY);
         reply.readException();
         data.recycle();
         reply.recycle();
     }
     @Override
-    public List<StackBoxInfo> getStackBoxes() throws RemoteException
+    public List<StackInfo> getAllStackInfos() throws RemoteException
     {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
         data.writeInterfaceToken(IActivityManager.descriptor);
-        mRemote.transact(GET_STACK_BOXES_TRANSACTION, data, reply, 0);
+        mRemote.transact(GET_ALL_STACK_INFOS_TRANSACTION, data, reply, 0);
         reply.readException();
-        ArrayList<StackBoxInfo> list = reply.createTypedArrayList(StackBoxInfo.CREATOR);
+        ArrayList<StackInfo> list = reply.createTypedArrayList(StackInfo.CREATOR);
         data.recycle();
         reply.recycle();
         return list;
     }
     @Override
-    public StackBoxInfo getStackBoxInfo(int stackBoxId) throws RemoteException
+    public StackInfo getStackInfo(int stackId) throws RemoteException
     {
         Parcel data = Parcel.obtain();
         Parcel reply = Parcel.obtain();
         data.writeInterfaceToken(IActivityManager.descriptor);
-        data.writeInt(stackBoxId);
-        mRemote.transact(GET_STACK_BOX_INFO_TRANSACTION, data, reply, 0);
+        data.writeInt(stackId);
+        mRemote.transact(GET_STACK_INFO_TRANSACTION, data, reply, 0);
         reply.readException();
         int res = reply.readInt();
-        StackBoxInfo info = null;
+        StackInfo info = null;
         if (res != 0) {
-            info = StackBoxInfo.CREATOR.createFromParcel(reply);
+            info = StackInfo.CREATOR.createFromParcel(reply);
         }
         data.recycle();
         reply.recycle();
@@ -4660,5 +4680,70 @@
         reply.recycle();
     }
 
+    public IActivityContainer createActivityContainer(IBinder parentActivityToken,
+            IActivityContainerCallback callback) throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeStrongBinder(parentActivityToken);
+        data.writeStrongBinder((IBinder)callback);
+        mRemote.transact(CREATE_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
+        reply.readException();
+        final int result = reply.readInt();
+        final IActivityContainer res;
+        if (result == 1) {
+            res = IActivityContainer.Stub.asInterface(reply.readStrongBinder());
+        } else {
+            res = null;
+        }
+        data.recycle();
+        reply.recycle();
+        return res;
+    }
+
+    public void deleteActivityContainer(IActivityContainer activityContainer)
+            throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeStrongBinder(activityContainer.asBinder());
+        mRemote.transact(DELETE_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
+        reply.readException();
+        data.recycle();
+        reply.recycle();
+    }
+
+    public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
+            throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeStrongBinder(activityToken);
+        mRemote.transact(GET_ACTIVITY_CONTAINER_TRANSACTION, data, reply, 0);
+        reply.readException();
+        final int result = reply.readInt();
+        final IActivityContainer res;
+        if (result == 1) {
+            res = IActivityContainer.Stub.asInterface(reply.readStrongBinder());
+        } else {
+            res = null;
+        }
+        data.recycle();
+        reply.recycle();
+        return res;
+    }
+
+    public IBinder getHomeActivityToken() throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        mRemote.transact(GET_HOME_ACTIVITY_TOKEN_TRANSACTION, data, reply, 0);
+        reply.readException();
+        IBinder res = reply.readStrongBinder();
+        data.recycle();
+        reply.recycle();
+        return res;
+    }
+
     private IBinder mRemote;
 }
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 4825c56..b038f9e 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -93,10 +93,11 @@
 import com.android.internal.os.RuntimeInit;
 import com.android.internal.os.SamplingProfilerIntegration;
 import com.android.internal.util.FastPrintWriter;
-import com.android.internal.util.Objects;
 import com.android.org.conscrypt.OpenSSLSocketImpl;
 import com.google.android.collect.Lists;
 
+import dalvik.system.VMRuntime;
+
 import java.io.File;
 import java.io.FileDescriptor;
 import java.io.FileOutputStream;
@@ -109,6 +110,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 import java.util.TimeZone;
 import java.util.regex.Pattern;
 
@@ -117,6 +119,7 @@
 import libcore.io.IoUtils;
 
 import dalvik.system.CloseGuard;
+import dalvik.system.VMRuntime;
 
 final class RemoteServiceException extends AndroidRuntimeException {
     public RemoteServiceException(String msg) {
@@ -221,7 +224,7 @@
         public boolean equals(Object o) {
             if (o instanceof ProviderKey) {
                 final ProviderKey other = (ProviderKey) o;
-                return Objects.equal(authority, other.authority) && userId == other.userId;
+                return Objects.equals(authority, other.authority) && userId == other.userId;
             }
             return false;
         }
@@ -739,6 +742,9 @@
 
             setCoreSettings(coreSettings);
 
+            // Tell the VMRuntime about the application.
+            VMRuntime.registerAppInfo(appInfo.dataDir, appInfo.processName);
+
             AppBindData data = new AppBindData();
             data.processName = processName;
             data.appInfo = appInfo;
@@ -1068,8 +1074,15 @@
             synchronized (this) {
                 if (mLastProcessState != processState) {
                     mLastProcessState = processState;
-
-                    // Update Dalvik state here based on ActivityManager.PROCESS_STATE_* constants.
+                    // Update Dalvik state based on ActivityManager.PROCESS_STATE_* constants.
+                    final int DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE = 0;
+                    final int DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE = 1;
+                    int dalvikProcessState = DALVIK_PROCESS_STATE_JANK_IMPERCEPTIBLE;
+                    // TODO: Tune this since things like gmail sync are important background but not jank perceptible.
+                    if (processState <= ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
+                        dalvikProcessState = DALVIK_PROCESS_STATE_JANK_PERCEPTIBLE;
+                    }
+                    VMRuntime.getRuntime().updateProcessState(dalvikProcessState);
                     if (false) {
                         Slog.i(TAG, "******************* PROCESS STATE CHANGED TO: " + processState
                                 + (fromIpc ? " (from ipc": ""));
@@ -2194,15 +2207,27 @@
             final Activity activity) {
         ContextImpl appContext = ContextImpl.createActivityContext(this, r.packageInfo, r.token);
         appContext.setOuterContext(activity);
+        Context baseContext = appContext;
+
+        final DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
+        try {
+            IActivityContainer container =
+                    ActivityManagerNative.getDefault().getEnclosingActivityContainer(r.token);
+            final int displayId =
+                    container == null ? Display.DEFAULT_DISPLAY : container.getDisplayId();
+            if (displayId > Display.DEFAULT_DISPLAY) {
+                Display display = dm.getRealDisplay(displayId, r.token);
+                baseContext = appContext.createDisplayContext(display);
+            }
+        } catch (RemoteException e) {
+        }
 
         // For debugging purposes, if the activity's package name contains the value of
         // the "debug.use-second-display" system property as a substring, then show
         // its content on a secondary display if there is one.
-        Context baseContext = appContext;
         String pkgName = SystemProperties.get("debug.second-display.pkg");
         if (pkgName != null && !pkgName.isEmpty()
                 && r.packageInfo.mPackageName.contains(pkgName)) {
-            DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
             for (int displayId : dm.getDisplayIds()) {
                 if (displayId != Display.DEFAULT_DISPLAY) {
                     Display display = dm.getRealDisplay(displayId, r.token);
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
new file mode 100644
index 0000000..113f123
--- /dev/null
+++ b/core/java/android/app/ActivityView.java
@@ -0,0 +1,285 @@
+/*
+ * Copyright (C) 2013 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.app;
+
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.IIntentSender;
+import android.content.Intent;
+import android.content.IntentSender;
+import android.graphics.SurfaceTexture;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.InputDevice;
+import android.view.InputEvent;
+import android.view.MotionEvent;
+import android.view.Surface;
+import android.view.TextureView;
+import android.view.TextureView.SurfaceTextureListener;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+
+/** @hide */
+public class ActivityView extends ViewGroup {
+    private final String TAG = "ActivityView";
+    private final boolean DEBUG = false;
+
+    private final TextureView mTextureView;
+    private IActivityContainer mActivityContainer;
+    private Activity mActivity;
+    private int mWidth;
+    private int mHeight;
+    private Surface mSurface;
+
+    // Only one IIntentSender or Intent may be queued at a time. Most recent one wins.
+    IIntentSender mQueuedPendingIntent;
+    Intent mQueuedIntent;
+
+    public ActivityView(Context context) {
+        this(context, null);
+    }
+
+    public ActivityView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public ActivityView(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+
+        while (context instanceof ContextWrapper) {
+            if (context instanceof Activity) {
+                mActivity = (Activity)context;
+                break;
+            }
+            context = ((ContextWrapper)context).getBaseContext();
+        }
+        if (mActivity == null) {
+            throw new IllegalStateException("The ActivityView's Context is not an Activity.");
+        }
+
+        mTextureView = new TextureView(context);
+        mTextureView.setSurfaceTextureListener(new ActivityViewSurfaceTextureListener());
+        addView(mTextureView);
+        if (DEBUG) Log.v(TAG, "ctor()");
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int l, int t, int r, int b) {
+        mTextureView.layout(0, 0, r - l, b - t);
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        if (DEBUG) Log.v(TAG, "onAttachedToWindow()");
+        super.onAttachedToWindow();
+        try {
+            final IBinder token = mActivity.getActivityToken();
+            mActivityContainer =
+                    ActivityManagerNative.getDefault().createActivityContainer(token, null);
+        } catch (RemoteException e) {
+            throw new IllegalStateException("ActivityView: Unable to create ActivityContainer. "
+                    + e);
+        }
+
+        attachToSurfaceWhenReady();
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        if (DEBUG) Log.v(TAG, "onDetachedFromWindow(): mActivityContainer=" + mActivityContainer);
+        super.onDetachedFromWindow();
+        if (mActivityContainer != null) {
+            detach();
+            try {
+                ActivityManagerNative.getDefault().deleteActivityContainer(mActivityContainer);
+            } catch (RemoteException e) {
+            }
+            mActivityContainer = null;
+        }
+    }
+
+    @Override
+    protected void onWindowVisibilityChanged(int visibility) {
+        if (DEBUG) Log.v(TAG, "onWindowVisibilityChanged(): visibility=" + visibility);
+        super.onWindowVisibilityChanged(visibility);
+        switch (visibility) {
+            case  View.VISIBLE:
+                attachToSurfaceWhenReady();
+                break;
+            case  View.INVISIBLE:
+                break;
+            case View.GONE:
+                break;
+        }
+    }
+
+    private boolean injectInputEvent(InputEvent event) {
+        try {
+            return mActivityContainer != null && mActivityContainer.injectEvent(event);
+        } catch (RemoteException e) {
+            return false;
+        }
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        return injectInputEvent(event) || super.onTouchEvent(event);
+    }
+
+    @Override
+    public boolean onGenericMotionEvent(MotionEvent event) {
+        if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
+            if (injectInputEvent(event)) {
+                return true;
+            }
+        }
+        return super.onGenericMotionEvent(event);
+    }
+
+    public boolean isAttachedToDisplay() {
+        return mSurface != null;
+    }
+
+    public void startActivity(Intent intent) {
+        if (DEBUG) Log.v(TAG, "startActivity(): intent=" + intent + " " +
+                (isAttachedToDisplay() ? "" : "not") + " attached");
+        if (mSurface != null) {
+            try {
+                mActivityContainer.startActivity(intent);
+            } catch (RemoteException e) {
+                throw new IllegalStateException("ActivityView: Unable to startActivity. " + e);
+            }
+        } else {
+            mQueuedIntent = intent;
+            mQueuedPendingIntent = null;
+        }
+    }
+
+    private void startActivityIntentSender(IIntentSender iIntentSender) {
+        try {
+            mActivityContainer.startActivityIntentSender(iIntentSender);
+        } catch (RemoteException e) {
+            throw new IllegalStateException(
+                    "ActivityView: Unable to startActivity from IntentSender. " + e);
+        }
+    }
+
+    public void startActivity(IntentSender intentSender) {
+        if (DEBUG) Log.v(TAG, "startActivityIntentSender(): intentSender=" + intentSender + " " +
+                (isAttachedToDisplay() ? "" : "not") + " attached");
+        final IIntentSender iIntentSender = intentSender.getTarget();
+        if (mSurface != null) {
+            startActivityIntentSender(iIntentSender);
+        } else {
+            mQueuedPendingIntent = iIntentSender;
+            mQueuedIntent = null;
+        }
+    }
+
+    public void startActivity(PendingIntent pendingIntent) {
+        if (DEBUG) Log.v(TAG, "startActivityPendingIntent(): PendingIntent=" + pendingIntent + " "
+                + (isAttachedToDisplay() ? "" : "not") + " attached");
+        final IIntentSender iIntentSender = pendingIntent.getTarget();
+        if (mSurface != null) {
+            startActivityIntentSender(iIntentSender);
+        } else {
+            mQueuedPendingIntent = iIntentSender;
+            mQueuedIntent = null;
+        }
+    }
+
+    private void attachToSurfaceWhenReady() {
+        final SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
+        if (mActivityContainer == null || surfaceTexture == null || mSurface != null) {
+            // Either not ready to attach, or already attached.
+            return;
+        }
+
+        WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE);
+        DisplayMetrics metrics = new DisplayMetrics();
+        wm.getDefaultDisplay().getMetrics(metrics);
+
+        mSurface = new Surface(surfaceTexture);
+        try {
+            mActivityContainer.attachToSurface(mSurface, mWidth, mHeight, metrics.densityDpi);
+        } catch (RemoteException e) {
+            mSurface.release();
+            mSurface = null;
+            throw new IllegalStateException(
+                    "ActivityView: Unable to create ActivityContainer. " + e);
+        }
+
+        if (DEBUG) Log.v(TAG, "attachToSurfaceWhenReady: " + (mQueuedIntent != null ||
+                mQueuedPendingIntent != null ? "" : "no") + " queued intent");
+        if (mQueuedIntent != null) {
+            startActivity(mQueuedIntent);
+            mQueuedIntent = null;
+        } else if (mQueuedPendingIntent != null) {
+            startActivityIntentSender(mQueuedPendingIntent);
+            mQueuedPendingIntent = null;
+        }
+    }
+
+    private void detach() {
+        if (DEBUG) Log.d(TAG, "detach: attached=" + isAttachedToDisplay());
+        if (mSurface != null) {
+            try {
+                mActivityContainer.detachFromDisplay();
+            } catch (RemoteException e) {
+            }
+            mSurface.release();
+            mSurface = null;
+        }
+    }
+
+    private class ActivityViewSurfaceTextureListener implements SurfaceTextureListener {
+        @Override
+        public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
+                int height) {
+            if (DEBUG) Log.d(TAG, "onSurfaceTextureAvailable: width=" + width + " height="
+                    + height);
+            mWidth = width;
+            mHeight = height;
+            if (mActivityContainer != null) {
+                attachToSurfaceWhenReady();
+            }
+        }
+
+        @Override
+        public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width,
+                int height) {
+            if (DEBUG) Log.d(TAG, "onSurfaceTextureSizeChanged: w=" + width + " h=" + height);
+        }
+
+        @Override
+        public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
+            if (DEBUG) Log.d(TAG, "onSurfaceTextureDestroyed");
+            detach();
+            return true;
+        }
+
+        @Override
+        public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
+//            Log.d(TAG, "onSurfaceTextureUpdated");
+        }
+
+    }
+}
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 286bde0..079cf7a 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -369,8 +369,8 @@
             android.Manifest.permission.WRITE_CALL_LOG,
             android.Manifest.permission.READ_CALENDAR,
             android.Manifest.permission.WRITE_CALENDAR,
-            null, // no permission required for notifications
             android.Manifest.permission.ACCESS_WIFI_STATE,
+            null, // no permission required for notifications
             null, // neighboring cells shares the coarse location perm
             android.Manifest.permission.CALL_PHONE,
             android.Manifest.permission.READ_SMS,
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index b505d4f..6f53df4 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -729,6 +729,39 @@
     }
 
     @Override
+    public Drawable getActivityBanner(ComponentName activityName)
+            throws NameNotFoundException {
+        return getActivityInfo(activityName, 0).loadBanner(this);
+    }
+
+    @Override
+    public Drawable getActivityBanner(Intent intent)
+            throws NameNotFoundException {
+        if (intent.getComponent() != null) {
+            return getActivityBanner(intent.getComponent());
+        }
+
+        ResolveInfo info = resolveActivity(
+                intent, PackageManager.MATCH_DEFAULT_ONLY);
+        if (info != null) {
+            return info.activityInfo.loadBanner(this);
+        }
+
+        throw new NameNotFoundException(intent.toUri(0));
+    }
+
+    @Override
+    public Drawable getApplicationBanner(ApplicationInfo info) {
+        return info.loadBanner(this);
+    }
+
+    @Override
+    public Drawable getApplicationBanner(String packageName)
+            throws NameNotFoundException {
+        return getApplicationBanner(getApplicationInfo(packageName, 0));
+    }
+
+    @Override
     public Drawable getActivityLogo(ComponentName activityName)
             throws NameNotFoundException {
         return getActivityInfo(activityName, 0).loadLogo(this);
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java
index cda2c5f..a8277b5 100644
--- a/core/java/android/app/Dialog.java
+++ b/core/java/android/app/Dialog.java
@@ -695,6 +695,10 @@
     
     public void onDetachedFromWindow() {
     }
+
+    public void onWindowDismissed() {
+        dismiss();
+    }
     
     /**
      * Called to process key events.  You can override this to intercept all 
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index d626e5f..af8f177 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -1402,6 +1402,7 @@
         mRestored = false;
         mBackStackNesting = 0;
         mFragmentManager = null;
+        mChildFragmentManager = null;
         mActivity = null;
         mFragmentId = 0;
         mContainerId = 0;
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 4371907..76f9d97 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -574,12 +574,12 @@
             return null;
         }
         if (index >= mActive.size()) {
-            throwException(new IllegalStateException("Fragement no longer exists for key "
+            throwException(new IllegalStateException("Fragment no longer exists for key "
                     + key + ": index " + index));
         }
         Fragment f = mActive.get(index);
         if (f == null) {
-            throwException(new IllegalStateException("Fragement no longer exists for key "
+            throwException(new IllegalStateException("Fragment no longer exists for key "
                     + key + ": index " + index));
         }
         return f;
@@ -1026,6 +1026,7 @@
                                     f.mActivity = null;
                                     f.mParentFragment = null;
                                     f.mFragmentManager = null;
+                                    f.mChildFragmentManager = null;
                                 }
                             }
                         }
diff --git a/core/java/android/app/IActivityContainer.aidl b/core/java/android/app/IActivityContainer.aidl
new file mode 100644
index 0000000..5b80e06
--- /dev/null
+++ b/core/java/android/app/IActivityContainer.aidl
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2013, 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.app;
+
+import android.app.IActivityContainerCallback;
+import android.content.Intent;
+import android.content.IIntentSender;
+import android.os.IBinder;
+import android.view.InputEvent;
+import android.view.Surface;
+
+/** @hide */
+interface IActivityContainer {
+    void attachToDisplay(int displayId);
+    void attachToSurface(in Surface surface, int width, int height, int density);
+    void detachFromDisplay();
+    int startActivity(in Intent intent);
+    int startActivityIntentSender(in IIntentSender intentSender);
+    int getDisplayId();
+    boolean injectEvent(in InputEvent event);
+}
diff --git a/core/java/android/app/IActivityContainerCallback.aidl b/core/java/android/app/IActivityContainerCallback.aidl
new file mode 100644
index 0000000..55c2001
--- /dev/null
+++ b/core/java/android/app/IActivityContainerCallback.aidl
@@ -0,0 +1,24 @@
+/**
+ * Copyright (c) 2013, 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.app;
+
+import android.os.IBinder;
+
+/** @hide */
+interface IActivityContainerCallback {
+    oneway void onLastActivityRemoved(IBinder container);
+}
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 77c2ea0..02a6343 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -18,7 +18,7 @@
 
 import android.app.ActivityManager.RunningTaskInfo;
 import android.app.ActivityManager.RunningServiceInfo;
-import android.app.ActivityManager.StackBoxInfo;
+import android.app.ActivityManager.StackInfo;
 import android.content.ComponentName;
 import android.content.ContentProviderNative;
 import android.content.IContentProvider;
@@ -36,6 +36,7 @@
 import android.content.pm.UserInfo;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
+import android.graphics.Rect;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Debug;
@@ -117,12 +118,10 @@
     public void moveTaskToBack(int task) throws RemoteException;
     public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) throws RemoteException;
     public void moveTaskBackwards(int task) throws RemoteException;
-    public int createStack(int taskId, int relativeStackBoxId, int position, float weight)
-            throws RemoteException;
     public void moveTaskToStack(int taskId, int stackId, boolean toTop) throws RemoteException;
-    public void resizeStackBox(int stackBoxId, float weight) throws RemoteException;
-    public List<StackBoxInfo> getStackBoxes() throws RemoteException;
-    public StackBoxInfo getStackBoxInfo(int stackBoxId) throws RemoteException;
+    public void resizeStack(int stackId, Rect bounds) throws RemoteException;
+    public List<StackInfo> getAllStackInfos() throws RemoteException;
+    public StackInfo getStackInfo(int stackId) throws RemoteException;
     public void setFocusedStack(int stackId) throws RemoteException;
     public int getTaskForActivity(IBinder token, boolean onlyRoot) throws RemoteException;
     /* oneway */
@@ -408,6 +407,18 @@
 
     public void performIdleMaintenance() throws RemoteException;
 
+    /** @hide */
+    public IActivityContainer createActivityContainer(IBinder parentActivityToken,
+            IActivityContainerCallback callback) throws RemoteException;
+
+    /** @hide */
+    public void deleteActivityContainer(IActivityContainer container) throws RemoteException;
+
+    public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
+            throws RemoteException;
+
+    public IBinder getHomeActivityToken() throws RemoteException;
+
     /*
      * Private non-Binder interfaces
      */
@@ -678,12 +689,12 @@
     int KILL_UID_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+164;
     int SET_USER_IS_MONKEY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+165;
     int HANG_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+166;
-    int CREATE_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+167;
+    int CREATE_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+167;
     int MOVE_TASK_TO_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+168;
     int RESIZE_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+169;
-    int GET_STACK_BOXES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+170;
+    int GET_ALL_STACK_INFOS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+170;
     int SET_FOCUSED_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+171;
-    int GET_STACK_BOX_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+172;
+    int GET_STACK_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+172;
     int CONVERT_FROM_TRANSLUCENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+173;
     int CONVERT_TO_TRANSLUCENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+174;
     int NOTIFY_ACTIVITY_DRAWN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+175;
@@ -694,4 +705,7 @@
     int RELEASE_PERSISTABLE_URI_PERMISSION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+180;
     int GET_PERSISTED_URI_PERMISSIONS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+181;
     int APP_NOT_RESPONDING_VIA_PROVIDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+182;
+    int GET_HOME_ACTIVITY_TOKEN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+183;
+    int GET_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+184;
+    int DELETE_ACTIVITY_CONTAINER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+185;
 }
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl
index 3efd3c0..181eb63 100644
--- a/core/java/android/app/IWallpaperManager.aidl
+++ b/core/java/android/app/IWallpaperManager.aidl
@@ -71,4 +71,14 @@
      * Returns the desired minimum height for the wallpaper.
      */
     int getHeightHint();
+
+    /**
+     * Returns the name of the wallpaper. Private API.
+     */
+    String getName();
+
+    /**
+     * Informs the service that wallpaper settings have been restored. Private API.
+     */
+    void settingsRestored();
 }
diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java
index 4ca3747..2e05edb 100644
--- a/core/java/android/app/NativeActivity.java
+++ b/core/java/android/app/NativeActivity.java
@@ -76,7 +76,7 @@
     private NativeContentView mNativeContentView;
     private InputMethodManager mIMM;
 
-    private int mNativeHandle;
+    private long mNativeHandle;
     
     private InputQueue mCurInputQueue;
     private SurfaceHolder mCurSurfaceHolder;
@@ -91,27 +91,26 @@
 
     private boolean mDestroyed;
     
-    private native int loadNativeCode(String path, String funcname, MessageQueue queue,
+    private native long loadNativeCode(String path, String funcname, MessageQueue queue,
             String internalDataPath, String obbPath, String externalDataPath, int sdkVersion,
             AssetManager assetMgr, byte[] savedState);
-    private native void unloadNativeCode(int handle);
-    
-    private native void onStartNative(int handle);
-    private native void onResumeNative(int handle);
-    private native byte[] onSaveInstanceStateNative(int handle);
-    private native void onPauseNative(int handle);
-    private native void onStopNative(int handle);
-    private native void onConfigurationChangedNative(int handle);
-    private native void onLowMemoryNative(int handle);
-    private native void onWindowFocusChangedNative(int handle, boolean focused);
-    private native void onSurfaceCreatedNative(int handle, Surface surface);
-    private native void onSurfaceChangedNative(int handle, Surface surface,
+    private native void unloadNativeCode(long handle);
+    private native void onStartNative(long handle);
+    private native void onResumeNative(long handle);
+    private native byte[] onSaveInstanceStateNative(long handle);
+    private native void onPauseNative(long handle);
+    private native void onStopNative(long handle);
+    private native void onConfigurationChangedNative(long handle);
+    private native void onLowMemoryNative(long handle);
+    private native void onWindowFocusChangedNative(long handle, boolean focused);
+    private native void onSurfaceCreatedNative(long handle, Surface surface);
+    private native void onSurfaceChangedNative(long handle, Surface surface,
             int format, int width, int height);
-    private native void onSurfaceRedrawNeededNative(int handle, Surface surface);
-    private native void onSurfaceDestroyedNative(int handle);
-    private native void onInputQueueCreatedNative(int handle, int queuePtr);
-    private native void onInputQueueDestroyedNative(int handle, int queuePtr);
-    private native void onContentRectChangedNative(int handle, int x, int y, int w, int h);
+    private native void onSurfaceRedrawNeededNative(long handle, Surface surface);
+    private native void onSurfaceDestroyedNative(long handle);
+    private native void onInputQueueCreatedNative(long handle, long queuePtr);
+    private native void onInputQueueDestroyedNative(long handle, long queuePtr);
+    private native void onContentRectChangedNative(long handle, int x, int y, int w, int h);
 
     static class NativeContentView extends View {
         NativeActivity mActivity;
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index cce6fc4..6be2b7b 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -348,6 +348,13 @@
      */
     public static final int FLAG_HIGH_PRIORITY      = 0x00000080;
 
+    /**
+     * Bit to be bitswise-ored into the {@link #flags} field that should be
+     * set if this notification is relevant to the current device only
+     * and it is not recommended that it bridge to other devices.
+     */
+    public static final int FLAG_LOCAL_ONLY         = 0x00000100;
+
     public int flags;
 
     /**
@@ -1532,6 +1539,17 @@
         }
 
         /**
+         * Set whether or not this notification should not bridge to other devices.
+         *
+         * <p>Some notifications can be bridged to other devices for remote display.
+         * This hint can be set to recommend this notification not be bridged.
+         */
+        public Builder setLocalOnly(boolean localOnly) {
+            setFlag(FLAG_LOCAL_ONLY, localOnly);
+            return this;
+        }
+
+        /**
          * Set which notification properties will be inherited from system defaults.
          * <p>
          * The value should be one or more of the following fields combined with
@@ -1568,12 +1586,31 @@
         }
 
         /**
-         * Add metadata to this notification.
+         * Merge additional metadata into this notification.
          *
-         * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
+         * <p>Values within the Bundle will replace existing extras values in this Builder.
+         *
+         * @see Notification#extras
+         */
+        public Builder addExtras(Bundle bag) {
+            if (mExtras == null) {
+                mExtras = new Bundle(bag);
+            } else {
+                mExtras.putAll(bag);
+            }
+            return this;
+        }
+
+        /**
+         * Set metadata for this notification.
+         *
+         * <p>A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's
          * current contents are copied into the Notification each time {@link #build()} is
          * called.
          *
+         * <p>Replaces any existing extras values with those from the provided Bundle.
+         * Use {@link #addExtras} to merge in metadata instead.
+         *
          * @see Notification#extras
          */
         public Builder setExtras(Bundle bag) {
@@ -1582,6 +1619,23 @@
         }
 
         /**
+         * Get the current metadata Bundle used by this notification Builder.
+         *
+         * <p>The returned Bundle is shared with this Builder.
+         *
+         * <p>The current contents of this Bundle are copied into the Notification each time
+         * {@link #build()} is called.
+         *
+         * @see Notification#extras
+         */
+        public Bundle getExtras() {
+            if (mExtras == null) {
+                mExtras = new Bundle();
+            }
+            return mExtras;
+        }
+
+        /**
          * Add an action to this notification. Actions are typically displayed by
          * the system as a button adjacent to the notification content.
          * <p>
@@ -1839,7 +1893,7 @@
          * this Notification object.
          * @hide
          */
-        public void addExtras(Bundle extras) {
+        public void populateExtras(Bundle extras) {
             // Store original information used in the construction of this object
             extras.putCharSequence(EXTRA_TITLE, mContentTitle);
             extras.putCharSequence(EXTRA_TEXT, mContentText);
@@ -1877,7 +1931,7 @@
 
             n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle();
 
-            addExtras(n.extras);
+            populateExtras(n.extras);
             if (mStyle != null) {
                 mStyle.addExtras(n.extras);
             }
@@ -1900,8 +1954,7 @@
      * An object that can apply a rich notification style to a {@link Notification.Builder}
      * object.
      */
-    public static abstract class Style
-    {
+    public static abstract class Style {
         private CharSequence mBigContentTitle;
         private CharSequence mSummaryText = null;
         private boolean mSummaryTextSet = false;
diff --git a/core/java/android/app/SharedPreferencesImpl.java b/core/java/android/app/SharedPreferencesImpl.java
index 86fd7b9..a292ecb 100644
--- a/core/java/android/app/SharedPreferencesImpl.java
+++ b/core/java/android/app/SharedPreferencesImpl.java
@@ -421,13 +421,15 @@
                     for (Map.Entry<String, Object> e : mModified.entrySet()) {
                         String k = e.getKey();
                         Object v = e.getValue();
-                        if (v == this) {  // magic value for a removal mutation
+                        // "this" is the magic value for a removal mutation. In addition,
+                        // setting a value to "null" for a given key is specified to be
+                        // equivalent to calling remove on that key.
+                        if (v == this || v == null) {
                             if (!mMap.containsKey(k)) {
                                 continue;
                             }
                             mMap.remove(k);
                         } else {
-                            boolean isSame = false;
                             if (mMap.containsKey(k)) {
                                 Object existingValue = mMap.get(k);
                                 if (existingValue != null && existingValue.equals(v)) {
diff --git a/core/java/android/app/backup/BackupDataInput.java b/core/java/android/app/backup/BackupDataInput.java
index 43b920a..03205fb 100644
--- a/core/java/android/app/backup/BackupDataInput.java
+++ b/core/java/android/app/backup/BackupDataInput.java
@@ -59,7 +59,7 @@
  * }</pre>
  */
 public class BackupDataInput {
-    int mBackupReader;
+    long mBackupReader;
 
     private EntityHeader mHeader = new EntityHeader();
     private boolean mHeaderReady;
@@ -185,10 +185,10 @@
         }
     }
 
-    private native static int ctor(FileDescriptor fd);
-    private native static void dtor(int mBackupReader);
+    private native static long ctor(FileDescriptor fd);
+    private native static void dtor(long mBackupReader);
 
-    private native int readNextHeader_native(int mBackupReader, EntityHeader entity);
-    private native int readEntityData_native(int mBackupReader, byte[] data, int offset, int size);
-    private native int skipEntityData_native(int mBackupReader);
+    private native int readNextHeader_native(long mBackupReader, EntityHeader entity);
+    private native int readEntityData_native(long mBackupReader, byte[] data, int offset, int size);
+    private native int skipEntityData_native(long mBackupReader);
 }
diff --git a/core/java/android/app/backup/BackupDataOutput.java b/core/java/android/app/backup/BackupDataOutput.java
index 22668b6..3a070b6 100644
--- a/core/java/android/app/backup/BackupDataOutput.java
+++ b/core/java/android/app/backup/BackupDataOutput.java
@@ -62,7 +62,7 @@
  * @see BackupAgent
  */
 public class BackupDataOutput {
-    int mBackupWriter;
+    long mBackupWriter;
 
     /** @hide */
     public BackupDataOutput(FileDescriptor fd) {
@@ -121,11 +121,11 @@
         }
     }
 
-    private native static int ctor(FileDescriptor fd);
-    private native static void dtor(int mBackupWriter);
+    private native static long ctor(FileDescriptor fd);
+    private native static void dtor(long mBackupWriter);
 
-    private native static int writeEntityHeader_native(int mBackupWriter, String key, int dataSize);
-    private native static int writeEntityData_native(int mBackupWriter, byte[] data, int size);
-    private native static void setKeyPrefix_native(int mBackupWriter, String keyPrefix);
+    private native static int writeEntityHeader_native(long mBackupWriter, String key, int dataSize);
+    private native static int writeEntityData_native(long mBackupWriter, byte[] data, int size);
+    private native static void setKeyPrefix_native(long mBackupWriter, String keyPrefix);
 }
 
diff --git a/core/java/android/app/backup/FileBackupHelperBase.java b/core/java/android/app/backup/FileBackupHelperBase.java
index 887a2e6..4ed5197 100644
--- a/core/java/android/app/backup/FileBackupHelperBase.java
+++ b/core/java/android/app/backup/FileBackupHelperBase.java
@@ -29,7 +29,7 @@
 class FileBackupHelperBase {
     private static final String TAG = "FileBackupHelperBase";
 
-    int mPtr;
+    long mPtr;
     Context mContext;
     boolean mExceptionLogged;
     
@@ -115,14 +115,13 @@
         return false;
     }
 
-    private static native int ctor();
-    private static native void dtor(int ptr);
+    private static native long ctor();
+    private static native void dtor(long ptr);
 
     native private static int performBackup_native(FileDescriptor oldState,
-            int data, FileDescriptor newState, String[] files, String[] keys);
-    
-    private static native int writeFile_native(int ptr, String filename, int backupReader);
-    private static native int writeSnapshot_native(int ptr, FileDescriptor fd);
+            long data, FileDescriptor newState, String[] files, String[] keys);
+    private static native int writeFile_native(long ptr, String filename, long backupReader);
+    private static native int writeSnapshot_native(long ptr, FileDescriptor fd);
 }
 
 
diff --git a/core/java/android/bluetooth/BluetoothInputDevice.java b/core/java/android/bluetooth/BluetoothInputDevice.java
index 844f432..c48b15d 100644
--- a/core/java/android/bluetooth/BluetoothInputDevice.java
+++ b/core/java/android/bluetooth/BluetoothInputDevice.java
@@ -76,6 +76,19 @@
     public static final String ACTION_PROTOCOL_MODE_CHANGED =
         "android.bluetooth.input.profile.action.PROTOCOL_MODE_CHANGED";
 
+    /**
+     * @hide
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_HANDSHAKE =
+        "android.bluetooth.input.profile.action.HANDSHAKE";
+
+    /**
+     * @hide
+     */
+    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+    public static final String ACTION_REPORT =
+        "android.bluetooth.input.profile.action.REPORT";
 
     /**
      * @hide
@@ -130,17 +143,17 @@
     /**
      * @hide
      */
-    public static final byte REPORT_TYPE_INPUT = 0;
+    public static final byte REPORT_TYPE_INPUT = 1;
 
     /**
      * @hide
      */
-    public static final byte REPORT_TYPE_OUTPUT = 1;
+    public static final byte REPORT_TYPE_OUTPUT = 2;
 
     /**
      * @hide
      */
-    public static final byte REPORT_TYPE_FEATURE = 2;
+    public static final byte REPORT_TYPE_FEATURE = 3;
 
     /**
      * @hide
@@ -180,6 +193,11 @@
     /**
      * @hide
      */
+    public static final String EXTRA_STATUS = "android.bluetooth.BluetoothInputDevice.extra.STATUS";
+
+    /**
+     * @hide
+     */
     public static final String EXTRA_VIRTUAL_UNPLUG_STATUS = "android.bluetooth.BluetoothInputDevice.extra.VIRTUAL_UNPLUG_STATUS";
 
     private Context mContext;
@@ -603,7 +621,7 @@
      * @hide
      */
     public boolean setReport(BluetoothDevice device, byte reportType, String report) {
-        if (DBG) log("setReport(" + device + "), reportType=" + reportType + " report=" + report);
+        if (VDBG) log("setReport(" + device + "), reportType=" + reportType + " report=" + report);
         if (mService != null && isEnabled() && isValidDevice(device)) {
             try {
                 return mService.setReport(device, reportType, report);
diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java
index d10eaea..1e75fc2 100644
--- a/core/java/android/bluetooth/BluetoothSocket.java
+++ b/core/java/android/bluetooth/BluetoothSocket.java
@@ -417,27 +417,28 @@
      *             if an i/o error occurs.
      */
     /*package*/ void flush() throws IOException {
+        if (mSocketOS == null) throw new IOException("flush is called on null OutputStream");
         if (VDBG) Log.d(TAG, "flush: " + mSocketOS);
         mSocketOS.flush();
     }
 
     /*package*/ int read(byte[] b, int offset, int length) throws IOException {
-
-            if (VDBG) Log.d(TAG, "read in:  " + mSocketIS + " len: " + length);
-            int ret = mSocketIS.read(b, offset, length);
-            if(ret < 0)
-                throw new IOException("bt socket closed, read return: " + ret);
-            if (VDBG) Log.d(TAG, "read out:  " + mSocketIS + " ret: " + ret);
-            return ret;
+        if (mSocketIS == null) throw new IOException("read is called on null InputStream");
+        if (VDBG) Log.d(TAG, "read in:  " + mSocketIS + " len: " + length);
+        int ret = mSocketIS.read(b, offset, length);
+        if(ret < 0)
+            throw new IOException("bt socket closed, read return: " + ret);
+        if (VDBG) Log.d(TAG, "read out:  " + mSocketIS + " ret: " + ret);
+        return ret;
     }
 
     /*package*/ int write(byte[] b, int offset, int length) throws IOException {
-
-            if (VDBG) Log.d(TAG, "write: " + mSocketOS + " length: " + length);
-            mSocketOS.write(b, offset, length);
-            // There is no good way to confirm since the entire process is asynchronous anyway
-            if (VDBG) Log.d(TAG, "write out: " + mSocketOS + " length: " + length);
-            return length;
+        if (mSocketOS == null) throw new IOException("write is called on null OutputStream");
+        if (VDBG) Log.d(TAG, "write: " + mSocketOS + " length: " + length);
+        mSocketOS.write(b, offset, length);
+        // There is no good way to confirm since the entire process is asynchronous anyway
+        if (VDBG) Log.d(TAG, "write out: " + mSocketOS + " length: " + length);
+        return length;
     }
 
     @Override
diff --git a/core/java/android/content/ContentProviderNative.java b/core/java/android/content/ContentProviderNative.java
index bcf0b63..39286d6 100644
--- a/core/java/android/content/ContentProviderNative.java
+++ b/core/java/android/content/ContentProviderNative.java
@@ -112,17 +112,24 @@
                     Cursor cursor = query(callingPkg, url, projection, selection, selectionArgs,
                             sortOrder, cancellationSignal);
                     if (cursor != null) {
+                        CursorToBulkCursorAdaptor adaptor = null;
+
                         try {
-                            CursorToBulkCursorAdaptor adaptor = new CursorToBulkCursorAdaptor(
-                                    cursor, observer, getProviderName());
-                            BulkCursorDescriptor d = adaptor.getBulkCursorDescriptor();
+                            adaptor = new CursorToBulkCursorAdaptor(cursor, observer,
+                                    getProviderName());
                             cursor = null;
 
+                            BulkCursorDescriptor d = adaptor.getBulkCursorDescriptor();
+                            adaptor = null;
+
                             reply.writeNoException();
                             reply.writeInt(1);
                             d.writeToParcel(reply, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
                         } finally {
                             // Close cursor if an exception was thrown while constructing the adaptor.
+                            if (adaptor != null) {
+                                adaptor.close();
+                            }
                             if (cursor != null) {
                                 cursor.close();
                             }
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 3c66b68..590ccf89 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -2765,6 +2765,12 @@
     @SdkConstant(SdkConstantType.INTENT_CATEGORY)
     public static final String CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
     /**
+     * Indicates an activity optimized for Leanback mode, and that should
+     * be displayed in the Leanback launcher.
+     */
+    @SdkConstant(SdkConstantType.INTENT_CATEGORY)
+    public static final String CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER";
+    /**
      * Provides information about the package it is in; typically used if
      * a package does not contain a {@link #CATEGORY_LAUNCHER} to provide
      * a front-door to the user without having to be shown in the all apps list.
@@ -3538,6 +3544,11 @@
      * it will be finished so that the user does not return to them, but
      * instead returns to whatever activity preceeded it.
      *
+     * <p>When this flag is assigned to the root activity all activities up
+     * to, but not including the root activity, will be cleared. This prevents
+     * this flag from being used to finish all activities in a task and thereby
+     * ending the task.
+     *
      * <p>This is useful for cases where you have a logical break in your
      * application.  For example, an e-mail application may have a command
      * to view an attachment, which launches an image view activity to
diff --git a/core/java/android/content/pm/ComponentInfo.java b/core/java/android/content/pm/ComponentInfo.java
index 4dbcf23..7e8f285 100644
--- a/core/java/android/content/pm/ComponentInfo.java
+++ b/core/java/android/content/pm/ComponentInfo.java
@@ -128,6 +128,17 @@
         return logo != 0 ? logo : applicationInfo.logo;
     }
     
+    /**
+     * Return the banner resource identifier to use for this component. If the
+     * component defines a banner, that is used; else, the application banner is
+     * used.
+     *
+     * @return The banner associated with this component.
+     */
+    public final int getBannerResource() {
+        return banner != 0 ? banner : applicationInfo.banner;
+    }
+
     protected void dumpFront(Printer pw, String prefix) {
         super.dumpFront(pw, prefix);
         pw.println(prefix + "enabled=" + enabled + " exported=" + exported
@@ -175,6 +186,13 @@
     /**
      * @hide
      */
+    @Override protected Drawable loadDefaultBanner(PackageManager pm) {
+        return applicationInfo.loadBanner(pm);
+    }
+
+    /**
+     * @hide
+     */
     @Override
     protected Drawable loadDefaultLogo(PackageManager pm) {
         return applicationInfo.loadLogo(pm);
diff --git a/core/java/android/content/pm/PackageItemInfo.java b/core/java/android/content/pm/PackageItemInfo.java
index a67326e..58f1c84 100644
--- a/core/java/android/content/pm/PackageItemInfo.java
+++ b/core/java/android/content/pm/PackageItemInfo.java
@@ -68,6 +68,12 @@
     
     /**
      * A drawable resource identifier (in the package's resources) of this
+     * component's banner.  From the "banner" attribute or, if not set, 0.
+     */
+    public int banner;
+
+    /**
+     * A drawable resource identifier (in the package's resources) of this
      * component's logo. Logos may be larger/wider than icons and are
      * displayed by certain UI elements in place of a name or name/icon
      * combination. From the "logo" attribute or, if not set, 0. 
@@ -92,6 +98,7 @@
         nonLocalizedLabel = orig.nonLocalizedLabel;
         if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();
         icon = orig.icon;
+        banner = orig.banner;
         logo = orig.logo;
         metaData = orig.metaData;
     }
@@ -146,6 +153,27 @@
     }
     
     /**
+     * Retrieve the current graphical banner associated with this item.  This
+     * will call back on the given PackageManager to load the banner from
+     * the application.
+     *
+     * @param pm A PackageManager from which the banner can be loaded; usually
+     * the PackageManager from which you originally retrieved this item.
+     *
+     * @return Returns a Drawable containing the item's banner.  If the item
+     * does not have a banner, this method will return null.
+     */
+    public Drawable loadBanner(PackageManager pm) {
+        if (banner != 0) {
+            Drawable dr = pm.getDrawable(packageName, banner, getApplicationInfo());
+            if (dr != null) {
+                return dr;
+            }
+        }
+        return loadDefaultBanner(pm);
+    }
+
+    /**
      * Retrieve the default graphical icon associated with this item.
      * 
      * @param pm A PackageManager from which the icon can be loaded; usually
@@ -159,7 +187,22 @@
     protected Drawable loadDefaultIcon(PackageManager pm) {
         return pm.getDefaultActivityIcon();
     }
-    
+
+    /**
+     * Retrieve the default graphical banner associated with this item.
+     *
+     * @param pm A PackageManager from which the banner can be loaded; usually
+     * the PackageManager from which you originally retrieved this item.
+     *
+     * @return Returns a Drawable containing the item's default banner
+     * or null if no default logo is available.
+     *
+     * @hide
+     */
+    protected Drawable loadDefaultBanner(PackageManager pm) {
+        return null;
+    }
+
     /**
      * Retrieve the current graphical logo associated with this item. This
      * will call back on the given PackageManager to load the logo from
@@ -224,10 +267,11 @@
             pw.println(prefix + "name=" + name);
         }
         pw.println(prefix + "packageName=" + packageName);
-        if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {
+        if (labelRes != 0 || nonLocalizedLabel != null || icon != 0 || banner != 0) {
             pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)
                     + " nonLocalizedLabel=" + nonLocalizedLabel
-                    + " icon=0x" + Integer.toHexString(icon));
+                    + " icon=0x" + Integer.toHexString(icon)
+                    + " banner=0x" + Integer.toHexString(banner));
         }
     }
     
@@ -243,6 +287,7 @@
         dest.writeInt(icon);
         dest.writeInt(logo);
         dest.writeBundle(metaData);
+        dest.writeInt(banner);
     }
     
     protected PackageItemInfo(Parcel source) {
@@ -254,6 +299,7 @@
         icon = source.readInt();
         logo = source.readInt();
         metaData = source.readBundle();
+        banner = source.readInt();
     }
 
     /**
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index c97c2b8..6440f0b 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -1249,6 +1249,29 @@
     public static final String FEATURE_TELEVISION = "android.hardware.type.television";
 
     /**
+     * Feature for {@link #getSystemAvailableFeatures} and
+     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
+     * on a watch. A watch here is defined to be a device worn on the body, perhaps on
+     * the wrist. The user is very close when interacting with the device.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_WATCH = "android.hardware.type.watch";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
+     * The device supports printing.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_PRINTING = "android.software.print";
+
+    /**
+     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
+     * The device can perform backup and restore operations on installed applications.
+     */
+    @SdkConstant(SdkConstantType.FEATURE)
+    public static final String FEATURE_BACKUP = "android.software.backup";
+
+    /**
      * Action to external storage service to clean out removed apps.
      * @hide
      */
@@ -2369,9 +2392,43 @@
             throws NameNotFoundException;
 
     /**
+     * Retrieve the banner associated with an activity. Given the full name of
+     * an activity, retrieves the information about it and calls
+     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its
+     * banner. If the activity cannot be found, NameNotFoundException is thrown.
+     *
+     * @param activityName Name of the activity whose banner is to be retrieved.
+     * @return Returns the image of the banner, or null if the activity has no
+     *         banner specified.
+     * @throws NameNotFoundException Thrown if the resources for the given
+     *             activity could not be loaded.
+     * @see #getActivityBanner(Intent)
+     */
+    public abstract Drawable getActivityBanner(ComponentName activityName)
+            throws NameNotFoundException;
+
+    /**
+     * Retrieve the banner associated with an Intent. If intent.getClassName()
+     * is set, this simply returns the result of
+     * getActivityBanner(intent.getClassName()). Otherwise it resolves the
+     * intent's component and returns the banner associated with the resolved
+     * component. If intent.getClassName() cannot be found or the Intent cannot
+     * be resolved to a component, NameNotFoundException is thrown.
+     *
+     * @param intent The intent for which you would like to retrieve a banner.
+     * @return Returns the image of the banner, or null if the activity has no
+     *         banner specified.
+     * @throws NameNotFoundException Thrown if the resources for application
+     *             matching the given intent could not be loaded.
+     * @see #getActivityBanner(ComponentName)
+     */
+    public abstract Drawable getActivityBanner(Intent intent)
+            throws NameNotFoundException;
+
+    /**
      * Return the generic icon for an activity that is used when no specific
      * icon is defined.
-     *
+     * 
      * @return Drawable Image of the icon.
      */
     public abstract Drawable getDefaultActivityIcon();
@@ -2409,19 +2466,43 @@
             throws NameNotFoundException;
 
     /**
-     * Retrieve the logo associated with an activity.  Given the full name of
-     * an activity, retrieves the information about it and calls
-     * {@link ComponentInfo#loadLogo ComponentInfo.loadLogo()} to return its logo.
-     * If the activity cannot be found, NameNotFoundException is thrown.
+     * Retrieve the banner associated with an application.
+     *
+     * @param info Information about application being queried.
+     * @return Returns the image of the banner or null if the application has no
+     *         banner specified.
+     * @see #getApplicationBanner(String)
+     */
+    public abstract Drawable getApplicationBanner(ApplicationInfo info);
+
+    /**
+     * Retrieve the banner associated with an application. Given the name of the
+     * application's package, retrieves the information about it and calls
+     * getApplicationIcon() to return its banner. If the application cannot be
+     * found, NameNotFoundException is thrown.
+     *
+     * @param packageName Name of the package whose application banner is to be
+     *            retrieved.
+     * @return Returns the image of the banner or null if the application has no
+     *         banner specified.
+     * @throws NameNotFoundException Thrown if the resources for the given
+     *             application could not be loaded.
+     * @see #getApplicationBanner(ApplicationInfo)
+     */
+    public abstract Drawable getApplicationBanner(String packageName)
+            throws NameNotFoundException;
+
+    /**
+     * Retrieve the logo associated with an activity. Given the full name of an
+     * activity, retrieves the information about it and calls
+     * {@link ComponentInfo#loadLogo ComponentInfo.loadLogo()} to return its
+     * logo. If the activity cannot be found, NameNotFoundException is thrown.
      *
      * @param activityName Name of the activity whose logo is to be retrieved.
-     *
-     * @return Returns the image of the logo or null if the activity has no
-     * logo specified.
-     *
+     * @return Returns the image of the logo or null if the activity has no logo
+     *         specified.
      * @throws NameNotFoundException Thrown if the resources for the given
-     * activity could not be loaded.
-     *
+     *             activity could not be loaded.
      * @see #getActivityLogo(Intent)
      */
     public abstract Drawable getActivityLogo(ComponentName activityName)
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index e6da288..4f1983e 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -58,7 +58,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
+import java.util.jar.StrictJarFile;
 import java.util.zip.ZipEntry;
 
 import com.android.internal.util.XmlUtils;
@@ -167,18 +167,20 @@
         final int labelRes;
         final int iconRes;
         final int logoRes;
+        final int bannerRes;
         
         String tag;
         TypedArray sa;
         
         ParsePackageItemArgs(Package _owner, String[] _outError,
-                int _nameRes, int _labelRes, int _iconRes, int _logoRes) {
+                int _nameRes, int _labelRes, int _iconRes, int _logoRes, int _bannerRes) {
             owner = _owner;
             outError = _outError;
             nameRes = _nameRes;
             labelRes = _labelRes;
             iconRes = _iconRes;
             logoRes = _logoRes;
+            bannerRes = _bannerRes;
         }
     }
     
@@ -190,10 +192,10 @@
         int flags;
         
         ParseComponentArgs(Package _owner, String[] _outError,
-                int _nameRes, int _labelRes, int _iconRes, int _logoRes,
+                int _nameRes, int _labelRes, int _iconRes, int _logoRes, int _bannerRes,
                 String[] _sepProcesses, int _processRes,
                 int _descriptionRes, int _enabledRes) {
-            super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes);
+            super(_owner, _outError, _nameRes, _labelRes, _iconRes, _logoRes, _bannerRes);
             sepProcesses = _sepProcesses;
             processRes = _processRes;
             descriptionRes = _descriptionRes;
@@ -456,7 +458,7 @@
         return pi;
     }
 
-    private Certificate[] loadCertificates(JarFile jarFile, JarEntry je,
+    private Certificate[] loadCertificates(StrictJarFile jarFile, ZipEntry je,
             byte[] readBuffer) {
         try {
             // We must read the stream for the JarEntry to retrieve
@@ -466,13 +468,11 @@
                 // not using
             }
             is.close();
-            return je != null ? je.getCertificates() : null;
+            return je != null ? jarFile.getCertificates(je) : null;
         } catch (IOException e) {
-            Slog.w(TAG, "Exception reading " + je.getName() + " in "
-                    + jarFile.getName(), e);
+            Slog.w(TAG, "Exception reading " + je.getName() + " in " + jarFile, e);
         } catch (RuntimeException e) {
-            Slog.w(TAG, "Exception reading " + je.getName() + " in "
-                    + jarFile.getName(), e);
+            Slog.w(TAG, "Exception reading " + je.getName() + " in " + jarFile, e);
         }
         return null;
     }
@@ -591,9 +591,9 @@
      */
     public boolean collectManifestDigest(Package pkg) {
         try {
-            final JarFile jarFile = new JarFile(mArchiveSourcePath);
+            final StrictJarFile jarFile = new StrictJarFile(mArchiveSourcePath);
             try {
-                final ZipEntry je = jarFile.getEntry(ANDROID_MANIFEST_FILENAME);
+                final ZipEntry je = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
                 if (je != null) {
                     pkg.manifestDigest = ManifestDigest.fromInputStream(jarFile.getInputStream(je));
                 }
@@ -624,7 +624,7 @@
         }
 
         try {
-            JarFile jarFile = new JarFile(mArchiveSourcePath);
+            StrictJarFile jarFile = new StrictJarFile(mArchiveSourcePath);
 
             Certificate[] certs = null;
 
@@ -633,7 +633,7 @@
                 // can trust it...  we'll just use the AndroidManifest.xml
                 // to retrieve its signatures, not validating all of the
                 // files.
-                JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
+                ZipEntry jarEntry = jarFile.findEntry(ANDROID_MANIFEST_FILENAME);
                 certs = loadCertificates(jarFile, jarEntry, readBuffer);
                 if (certs == null) {
                     Slog.e(TAG, "Package " + pkg.packageName
@@ -656,9 +656,9 @@
                     }
                 }
             } else {
-                Enumeration<JarEntry> entries = jarFile.entries();
-                while (entries.hasMoreElements()) {
-                    final JarEntry je = entries.nextElement();
+                Iterator<ZipEntry> entries = jarFile.iterator();
+                while (entries.hasNext()) {
+                    final ZipEntry je = entries.next();
                     if (je.isDirectory()) continue;
 
                     final String name = je.getName();
@@ -744,6 +744,10 @@
             Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
             mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
             return false;
+        } catch (SecurityException e) {
+            Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
+            mParseError = PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
+            return false;
         } catch (RuntimeException e) {
             Slog.w(TAG, "Exception reading " + mArchiveSourcePath, e);
             mParseError = PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION;
@@ -1654,7 +1658,8 @@
                 com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
                 com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
                 com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
-                com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo)) {
+                com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo,
+                com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) {
             sa.recycle();
             mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
             return null;
@@ -1697,7 +1702,8 @@
                 com.android.internal.R.styleable.AndroidManifestPermission_name,
                 com.android.internal.R.styleable.AndroidManifestPermission_label,
                 com.android.internal.R.styleable.AndroidManifestPermission_icon,
-                com.android.internal.R.styleable.AndroidManifestPermission_logo)) {
+                com.android.internal.R.styleable.AndroidManifestPermission_logo,
+                com.android.internal.R.styleable.AndroidManifestPermission_banner)) {
             sa.recycle();
             mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
             return null;
@@ -1766,7 +1772,8 @@
                 com.android.internal.R.styleable.AndroidManifestPermissionTree_name,
                 com.android.internal.R.styleable.AndroidManifestPermissionTree_label,
                 com.android.internal.R.styleable.AndroidManifestPermissionTree_icon,
-                com.android.internal.R.styleable.AndroidManifestPermissionTree_logo)) {
+                com.android.internal.R.styleable.AndroidManifestPermissionTree_logo,
+                com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) {
             sa.recycle();
             mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
             return null;
@@ -1811,7 +1818,8 @@
                     com.android.internal.R.styleable.AndroidManifestInstrumentation_name,
                     com.android.internal.R.styleable.AndroidManifestInstrumentation_label,
                     com.android.internal.R.styleable.AndroidManifestInstrumentation_icon,
-                    com.android.internal.R.styleable.AndroidManifestInstrumentation_logo);
+                    com.android.internal.R.styleable.AndroidManifestInstrumentation_logo,
+                    com.android.internal.R.styleable.AndroidManifestInstrumentation_banner);
             mParseInstrumentationArgs.tag = "<instrumentation>";
         }
         
@@ -1927,6 +1935,8 @@
                 com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
         ai.logo = sa.getResourceId(
                 com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
+        ai.banner = sa.getResourceId(
+                com.android.internal.R.styleable.AndroidManifestApplication_banner, 0);
         ai.theme = sa.getResourceId(
                 com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
         ai.descriptionRes = sa.getResourceId(
@@ -2220,7 +2230,7 @@
 
     private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo,
             String[] outError, String tag, TypedArray sa,
-            int nameRes, int labelRes, int iconRes, int logoRes) {
+            int nameRes, int labelRes, int iconRes, int logoRes, int bannerRes) {
         String name = sa.getNonConfigurationString(nameRes, 0);
         if (name == null) {
             outError[0] = tag + " does not specify android:name";
@@ -2244,6 +2254,11 @@
             outInfo.logo = logoVal;
         }
 
+        int bannerVal = sa.getResourceId(bannerRes, 0);
+        if (bannerVal != 0) {
+            outInfo.banner = bannerVal;
+        }
+
         TypedValue v = sa.peekValue(labelRes);
         if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
             outInfo.nonLocalizedLabel = v.coerceToString();
@@ -2267,6 +2282,7 @@
                     com.android.internal.R.styleable.AndroidManifestActivity_label,
                     com.android.internal.R.styleable.AndroidManifestActivity_icon,
                     com.android.internal.R.styleable.AndroidManifestActivity_logo,
+                    com.android.internal.R.styleable.AndroidManifestActivity_banner,
                     mSeparateProcesses,
                     com.android.internal.R.styleable.AndroidManifestActivity_process,
                     com.android.internal.R.styleable.AndroidManifestActivity_description,
@@ -2552,6 +2568,7 @@
                     com.android.internal.R.styleable.AndroidManifestActivityAlias_label,
                     com.android.internal.R.styleable.AndroidManifestActivityAlias_icon,
                     com.android.internal.R.styleable.AndroidManifestActivityAlias_logo,
+                    com.android.internal.R.styleable.AndroidManifestActivityAlias_banner,
                     mSeparateProcesses,
                     0,
                     com.android.internal.R.styleable.AndroidManifestActivityAlias_description,
@@ -2586,6 +2603,7 @@
         info.flags = target.info.flags;
         info.icon = target.info.icon;
         info.logo = target.info.logo;
+        info.banner = target.info.banner;
         info.labelRes = target.info.labelRes;
         info.nonLocalizedLabel = target.info.nonLocalizedLabel;
         info.launchMode = target.info.launchMode;
@@ -2699,6 +2717,7 @@
                     com.android.internal.R.styleable.AndroidManifestProvider_label,
                     com.android.internal.R.styleable.AndroidManifestProvider_icon,
                     com.android.internal.R.styleable.AndroidManifestProvider_logo,
+                    com.android.internal.R.styleable.AndroidManifestProvider_banner,
                     mSeparateProcesses,
                     com.android.internal.R.styleable.AndroidManifestProvider_process,
                     com.android.internal.R.styleable.AndroidManifestProvider_description,
@@ -3005,6 +3024,7 @@
                     com.android.internal.R.styleable.AndroidManifestService_label,
                     com.android.internal.R.styleable.AndroidManifestService_icon,
                     com.android.internal.R.styleable.AndroidManifestService_logo,
+                    com.android.internal.R.styleable.AndroidManifestService_banner,
                     mSeparateProcesses,
                     com.android.internal.R.styleable.AndroidManifestService_process,
                     com.android.internal.R.styleable.AndroidManifestService_description,
@@ -3302,6 +3322,9 @@
         outInfo.logo = sa.getResourceId(
                 com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);
 
+        outInfo.banner = sa.getResourceId(
+                com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0);
+
         sa.recycle();
 
         int outerDepth = parser.getDepth();
@@ -3664,6 +3687,11 @@
                 outInfo.logo = logoVal;
             }
 
+            int bannerVal = args.sa.getResourceId(args.bannerRes, 0);
+            if (bannerVal != 0) {
+                outInfo.banner = bannerVal;
+            }
+
             TypedValue v = args.sa.peekValue(args.labelRes);
             if (v != null && (outInfo.labelRes=v.resourceId) == 0) {
                 outInfo.nonLocalizedLabel = v.coerceToString();
@@ -4088,6 +4116,7 @@
         public CharSequence nonLocalizedLabel;
         public int icon;
         public int logo;
+        public int banner;
         public int preferred;
     }
 
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index fc9e486..93ce633 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -70,7 +70,6 @@
     
     // For communication with native code.
     private int mObject;
-    private int mNObject;  // used by the NDK
 
     private StringBlock mStringBlocks[] = null;
     
@@ -540,6 +539,12 @@
         public final int getAssetInt() {
             return mAsset;
         }
+        /**
+         * @hide
+         */
+        public final long getNativeAsset() {
+            return mAsset;
+        }
         private AssetInputStream(int asset)
         {
             mAsset = asset;
diff --git a/core/java/android/database/CursorWindow.java b/core/java/android/database/CursorWindow.java
index f1f3017..197e3ff 100644
--- a/core/java/android/database/CursorWindow.java
+++ b/core/java/android/database/CursorWindow.java
@@ -27,6 +27,7 @@
 import android.os.Process;
 import android.util.Log;
 import android.util.SparseIntArray;
+import android.util.LongSparseArray;
 
 /**
  * A buffer containing multiple cursor rows.
@@ -52,40 +53,40 @@
      * The native CursorWindow object pointer.  (FOR INTERNAL USE ONLY)
      * @hide
      */
-    public int mWindowPtr;
+    public long mWindowPtr;
 
     private int mStartPos;
     private final String mName;
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
-    private static native int nativeCreate(String name, int cursorWindowSize);
-    private static native int nativeCreateFromParcel(Parcel parcel);
-    private static native void nativeDispose(int windowPtr);
-    private static native void nativeWriteToParcel(int windowPtr, Parcel parcel);
+    private static native long nativeCreate(String name, int cursorWindowSize);
+    private static native long nativeCreateFromParcel(Parcel parcel);
+    private static native void nativeDispose(long windowPtr);
+    private static native void nativeWriteToParcel(long windowPtr, Parcel parcel);
 
-    private static native void nativeClear(int windowPtr);
+    private static native void nativeClear(long windowPtr);
 
-    private static native int nativeGetNumRows(int windowPtr);
-    private static native boolean nativeSetNumColumns(int windowPtr, int columnNum);
-    private static native boolean nativeAllocRow(int windowPtr);
-    private static native void nativeFreeLastRow(int windowPtr);
+    private static native int nativeGetNumRows(long windowPtr);
+    private static native boolean nativeSetNumColumns(long windowPtr, int columnNum);
+    private static native boolean nativeAllocRow(long windowPtr);
+    private static native void nativeFreeLastRow(long windowPtr);
 
-    private static native int nativeGetType(int windowPtr, int row, int column);
-    private static native byte[] nativeGetBlob(int windowPtr, int row, int column);
-    private static native String nativeGetString(int windowPtr, int row, int column);
-    private static native long nativeGetLong(int windowPtr, int row, int column);
-    private static native double nativeGetDouble(int windowPtr, int row, int column);
-    private static native void nativeCopyStringToBuffer(int windowPtr, int row, int column,
+    private static native int nativeGetType(long windowPtr, int row, int column);
+    private static native byte[] nativeGetBlob(long windowPtr, int row, int column);
+    private static native String nativeGetString(long windowPtr, int row, int column);
+    private static native long nativeGetLong(long windowPtr, int row, int column);
+    private static native double nativeGetDouble(long windowPtr, int row, int column);
+    private static native void nativeCopyStringToBuffer(long windowPtr, int row, int column,
             CharArrayBuffer buffer);
 
-    private static native boolean nativePutBlob(int windowPtr, byte[] value, int row, int column);
-    private static native boolean nativePutString(int windowPtr, String value, int row, int column);
-    private static native boolean nativePutLong(int windowPtr, long value, int row, int column);
-    private static native boolean nativePutDouble(int windowPtr, double value, int row, int column);
-    private static native boolean nativePutNull(int windowPtr, int row, int column);
+    private static native boolean nativePutBlob(long windowPtr, byte[] value, int row, int column);
+    private static native boolean nativePutString(long windowPtr, String value, int row, int column);
+    private static native boolean nativePutLong(long windowPtr, long value, int row, int column);
+    private static native boolean nativePutDouble(long windowPtr, double value, int row, int column);
+    private static native boolean nativePutNull(long windowPtr, int row, int column);
 
-    private static native String nativeGetName(int windowPtr);
+    private static native String nativeGetName(long windowPtr);
 
     /**
      * Creates a new empty cursor window and gives it a name.
@@ -713,9 +714,9 @@
         dispose();
     }
 
-    private static final SparseIntArray sWindowToPidMap = new SparseIntArray();
+    private static final LongSparseArray<Integer> sWindowToPidMap = new LongSparseArray<Integer>();
 
-    private void recordNewWindow(int pid, int window) {
+    private void recordNewWindow(int pid, long window) {
         synchronized (sWindowToPidMap) {
             sWindowToPidMap.put(window, pid);
             if (Log.isLoggable(STATS_TAG, Log.VERBOSE)) {
@@ -724,7 +725,7 @@
         }
     }
 
-    private void recordClosingOfWindow(int window) {
+    private void recordClosingOfWindow(long window) {
         synchronized (sWindowToPidMap) {
             if (sWindowToPidMap.size() == 0) {
                 // this means we are not in the ContentProvider.
@@ -771,6 +772,6 @@
 
     @Override
     public String toString() {
-        return getName() + " {" + Integer.toHexString(mWindowPtr) + "}";
+        return getName() + " {" + Long.toHexString(mWindowPtr) + "}";
     }
 }
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java
index 725a1ff..24a7d33 100644
--- a/core/java/android/database/sqlite/SQLiteConnection.java
+++ b/core/java/android/database/sqlite/SQLiteConnection.java
@@ -107,7 +107,7 @@
     private final OperationLog mRecentOperations = new OperationLog();
 
     // The native SQLiteConnection pointer.  (FOR INTERNAL USE ONLY)
-    private int mConnectionPtr;
+    private long mConnectionPtr;
 
     private boolean mOnlyAllowReadOnlyOperations;
 
@@ -117,45 +117,45 @@
     // we can ensure that we detach the signal at the right time.
     private int mCancellationSignalAttachCount;
 
-    private static native int nativeOpen(String path, int openFlags, String label,
+    private static native long nativeOpen(String path, int openFlags, String label,
             boolean enableTrace, boolean enableProfile);
-    private static native void nativeClose(int connectionPtr);
-    private static native void nativeRegisterCustomFunction(int connectionPtr,
+    private static native void nativeClose(long connectionPtr);
+    private static native void nativeRegisterCustomFunction(long connectionPtr,
             SQLiteCustomFunction function);
-    private static native void nativeRegisterLocalizedCollators(int connectionPtr, String locale);
-    private static native int nativePrepareStatement(int connectionPtr, String sql);
-    private static native void nativeFinalizeStatement(int connectionPtr, int statementPtr);
-    private static native int nativeGetParameterCount(int connectionPtr, int statementPtr);
-    private static native boolean nativeIsReadOnly(int connectionPtr, int statementPtr);
-    private static native int nativeGetColumnCount(int connectionPtr, int statementPtr);
-    private static native String nativeGetColumnName(int connectionPtr, int statementPtr,
+    private static native void nativeRegisterLocalizedCollators(long connectionPtr, String locale);
+    private static native long nativePrepareStatement(long connectionPtr, String sql);
+    private static native void nativeFinalizeStatement(long connectionPtr, long statementPtr);
+    private static native int nativeGetParameterCount(long connectionPtr, long statementPtr);
+    private static native boolean nativeIsReadOnly(long connectionPtr, long statementPtr);
+    private static native int nativeGetColumnCount(long connectionPtr, long statementPtr);
+    private static native String nativeGetColumnName(long connectionPtr, long statementPtr,
             int index);
-    private static native void nativeBindNull(int connectionPtr, int statementPtr,
+    private static native void nativeBindNull(long connectionPtr, long statementPtr,
             int index);
-    private static native void nativeBindLong(int connectionPtr, int statementPtr,
+    private static native void nativeBindLong(long connectionPtr, long statementPtr,
             int index, long value);
-    private static native void nativeBindDouble(int connectionPtr, int statementPtr,
+    private static native void nativeBindDouble(long connectionPtr, long statementPtr,
             int index, double value);
-    private static native void nativeBindString(int connectionPtr, int statementPtr,
+    private static native void nativeBindString(long connectionPtr, long statementPtr,
             int index, String value);
-    private static native void nativeBindBlob(int connectionPtr, int statementPtr,
+    private static native void nativeBindBlob(long connectionPtr, long statementPtr,
             int index, byte[] value);
     private static native void nativeResetStatementAndClearBindings(
-            int connectionPtr, int statementPtr);
-    private static native void nativeExecute(int connectionPtr, int statementPtr);
-    private static native long nativeExecuteForLong(int connectionPtr, int statementPtr);
-    private static native String nativeExecuteForString(int connectionPtr, int statementPtr);
+            long connectionPtr, long statementPtr);
+    private static native void nativeExecute(long connectionPtr, long statementPtr);
+    private static native long nativeExecuteForLong(long connectionPtr, long statementPtr);
+    private static native String nativeExecuteForString(long connectionPtr, long statementPtr);
     private static native int nativeExecuteForBlobFileDescriptor(
-            int connectionPtr, int statementPtr);
-    private static native int nativeExecuteForChangedRowCount(int connectionPtr, int statementPtr);
+            long connectionPtr, long statementPtr);
+    private static native int nativeExecuteForChangedRowCount(long connectionPtr, long statementPtr);
     private static native long nativeExecuteForLastInsertedRowId(
-            int connectionPtr, int statementPtr);
+            long connectionPtr, long statementPtr);
     private static native long nativeExecuteForCursorWindow(
-            int connectionPtr, int statementPtr, int windowPtr,
+            long connectionPtr, long statementPtr, long windowPtr,
             int startPos, int requiredPos, boolean countAllRows);
-    private static native int nativeGetDbLookaside(int connectionPtr);
-    private static native void nativeCancel(int connectionPtr);
-    private static native void nativeResetCancel(int connectionPtr, boolean cancelable);
+    private static native int nativeGetDbLookaside(long connectionPtr);
+    private static native void nativeCancel(long connectionPtr);
+    private static native void nativeResetCancel(long connectionPtr, boolean cancelable);
 
     private SQLiteConnection(SQLiteConnectionPool pool,
             SQLiteDatabaseConfiguration configuration,
@@ -886,7 +886,7 @@
             skipCache = true;
         }
 
-        final int statementPtr = nativePrepareStatement(mConnectionPtr, sql);
+        final long statementPtr = nativePrepareStatement(mConnectionPtr, sql);
         try {
             final int numParameters = nativeGetParameterCount(mConnectionPtr, statementPtr);
             final int type = DatabaseUtils.getSqlStatementType(sql);
@@ -987,7 +987,7 @@
             return;
         }
 
-        final int statementPtr = statement.mStatementPtr;
+        final long statementPtr = statement.mStatementPtr;
         for (int i = 0; i < count; i++) {
             final Object arg = bindArgs[i];
             switch (DatabaseUtils.getTypeOfObject(arg)) {
@@ -1072,7 +1072,7 @@
     void dumpUnsafe(Printer printer, boolean verbose) {
         printer.println("Connection #" + mConnectionId + ":");
         if (verbose) {
-            printer.println("  connectionPtr: 0x" + Integer.toHexString(mConnectionPtr));
+            printer.println("  connectionPtr: 0x" + Long.toHexString(mConnectionPtr));
         }
         printer.println("  isPrimaryConnection: " + mIsPrimaryConnection);
         printer.println("  onlyAllowReadOnlyOperations: " + mOnlyAllowReadOnlyOperations);
@@ -1178,7 +1178,7 @@
         return "SQLiteConnection: " + mConfiguration.path + " (" + mConnectionId + ")";
     }
 
-    private PreparedStatement obtainPreparedStatement(String sql, int statementPtr,
+    private PreparedStatement obtainPreparedStatement(String sql, long statementPtr,
             int numParameters, int type, boolean readOnly) {
         PreparedStatement statement = mPreparedStatementPool;
         if (statement != null) {
@@ -1225,7 +1225,7 @@
 
         // The native sqlite3_stmt object pointer.
         // Lifetime is managed explicitly by the connection.
-        public int mStatementPtr;
+        public long mStatementPtr;
 
         // The number of parameters that the prepared statement has.
         public int mNumParameters;
@@ -1271,7 +1271,7 @@
                     if (statement.mInCache) { // might be false due to a race with entryRemoved
                         String sql = entry.getKey();
                         printer.println("    " + i + ": statementPtr=0x"
-                                + Integer.toHexString(statement.mStatementPtr)
+                                + Long.toHexString(statement.mStatementPtr)
                                 + ", numParameters=" + statement.mNumParameters
                                 + ", type=" + statement.mType
                                 + ", readOnly=" + statement.mReadOnly
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 60ccc61..433d5d1c 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -738,14 +738,16 @@
         File dir = file.getParentFile();
         if (dir != null) {
             final String prefix = file.getName() + "-mj";
-            final FileFilter filter = new FileFilter() {
+            File[] files = dir.listFiles(new FileFilter() {
                 @Override
                 public boolean accept(File candidate) {
                     return candidate.getName().startsWith(prefix);
                 }
-            };
-            for (File masterJournal : dir.listFiles(filter)) {
-                deleted |= masterJournal.delete();
+            });
+            if (files != null) {
+                for (File masterJournal : files) {
+                    deleted |= masterJournal.delete();
+                }
             }
         }
         return deleted;
diff --git a/core/java/android/ddm/DdmHandleProfiling.java b/core/java/android/ddm/DdmHandleProfiling.java
index ec08393..537763d 100644
--- a/core/java/android/ddm/DdmHandleProfiling.java
+++ b/core/java/android/ddm/DdmHandleProfiling.java
@@ -37,6 +37,7 @@
     public static final int CHUNK_SPSS = type("SPSS");
     public static final int CHUNK_SPSE = type("SPSE");
 
+    private static final boolean DEBUG = false;
     private static DdmHandleProfiling mInstance = new DdmHandleProfiling();
 
 
@@ -72,7 +73,7 @@
      * Handle a chunk of data.
      */
     public Chunk handleChunk(Chunk request) {
-        if (false)
+        if (DEBUG)
             Log.v("ddm-heap", "Handling " + name(request.type) + " chunk");
         int type = request.type;
 
@@ -83,13 +84,13 @@
         } else if (type == CHUNK_MPSS) {
             return handleMPSS(request);
         } else if (type == CHUNK_MPSE) {
-            return handleMPSE(request);
+            return handleMPSEOrSPSE(request, "Method");
         } else if (type == CHUNK_MPRQ) {
             return handleMPRQ(request);
         } else if (type == CHUNK_SPSS) {
             return handleSPSS(request);
         } else if (type == CHUNK_SPSE) {
-            return handleSPSE(request);
+            return handleMPSEOrSPSE(request, "Sample");
         } else {
             throw new RuntimeException("Unknown packet "
                 + ChunkHandler.name(type));
@@ -106,7 +107,7 @@
         int flags = in.getInt();
         int len = in.getInt();
         String fileName = getString(in, len);
-        if (false)
+        if (DEBUG)
             Log.v("ddm-heap", "Method profiling start: filename='" + fileName
                 + "', size=" + bufferSize + ", flags=" + flags);
 
@@ -146,7 +147,7 @@
 
         int bufferSize = in.getInt();
         int flags = in.getInt();
-        if (false) {
+        if (DEBUG) {
             Log.v("ddm-heap", "Method prof stream start: size=" + bufferSize
                 + ", flags=" + flags);
         }
@@ -160,20 +161,18 @@
     }
 
     /*
-     * Handle a "Method Profiling w/Streaming End" request.
+     * Handle a "Method Profiling w/Streaming End" request or a
+     * "Sample Profiling w/Streaming End" request.
      */
-    private Chunk handleMPSE(Chunk request) {
-        byte result;
-
-        if (false) {
-            Log.v("ddm-heap", "Method prof stream end");
+    private Chunk handleMPSEOrSPSE(Chunk request, String type) {
+        if (DEBUG) {
+            Log.v("ddm-heap", type + " prof stream end");
         }
 
         try {
             Debug.stopMethodTracing();
-            result = 0;
         } catch (RuntimeException re) {
-            Log.w("ddm-heap", "Method prof stream end failed: "
+            Log.w("ddm-heap", type + " prof stream end failed: "
                 + re.getMessage());
             return createFailChunk(1, re.getMessage());
         }
@@ -202,7 +201,7 @@
         int bufferSize = in.getInt();
         int flags = in.getInt();
         int interval = in.getInt();
-        if (false) {
+        if (DEBUG) {
             Log.v("ddm-heap", "Sample prof stream start: size=" + bufferSize
                 + ", flags=" + flags + ", interval=" + interval);
         }
@@ -214,25 +213,5 @@
             return createFailChunk(1, re.getMessage());
         }
     }
-
-    /*
-     * Handle a "Sample Profiling w/Streaming End" request.
-     */
-    private Chunk handleSPSE(Chunk request) {
-        if (false) {
-            Log.v("ddm-heap", "Sample prof stream end");
-        }
-
-        try {
-            Debug.stopMethodTracing();
-        } catch (RuntimeException re) {
-            Log.w("ddm-heap", "Sample prof stream end failed: "
-                + re.getMessage());
-            return createFailChunk(1, re.getMessage());
-        }
-
-        /* VM sent the (perhaps very large) response directly */
-        return null;
-    }
 }
 
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index feb47aa..111062d 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -151,7 +151,7 @@
     private static final int CAMERA_MSG_PREVIEW_METADATA = 0x400;
     private static final int CAMERA_MSG_FOCUS_MOVE       = 0x800;
 
-    private int mNativeContext; // accessed by native methods
+    private long mNativeContext; // accessed by native methods
     private EventHandler mEventHandler;
     private ShutterCallback mShutterCallback;
     private PictureCallback mRawImageCallback;
diff --git a/core/java/android/hardware/SystemSensorManager.java b/core/java/android/hardware/SystemSensorManager.java
index 50fdb41..8684a04 100644
--- a/core/java/android/hardware/SystemSensorManager.java
+++ b/core/java/android/hardware/SystemSensorManager.java
@@ -222,14 +222,14 @@
      * the queues and the listeners.
      */
     private static abstract class BaseEventQueue {
-        private native int nativeInitBaseEventQueue(BaseEventQueue eventQ, MessageQueue msgQ,
+        private native long nativeInitBaseEventQueue(BaseEventQueue eventQ, MessageQueue msgQ,
                 float[] scratch);
-        private static native int nativeEnableSensor(int eventQ, int handle, int rateUs,
+        private static native int nativeEnableSensor(long eventQ, int handle, int rateUs,
                 int maxBatchReportLatencyUs, int reservedFlags);
-        private static native int nativeDisableSensor(int eventQ, int handle);
-        private static native void nativeDestroySensorEventQueue(int eventQ);
-        private static native int nativeFlushSensor(int eventQ);
-        private int nSensorEventQueue;
+        private static native int nativeDisableSensor(long eventQ, int handle);
+        private static native void nativeDestroySensorEventQueue(long eventQ);
+        private static native int nativeFlushSensor(long eventQ);
+        private long nSensorEventQueue;
         private final SparseBooleanArray mActiveSensors = new SparseBooleanArray();
         protected final SparseIntArray mSensorAccuracies = new SparseIntArray();
         protected final SparseBooleanArray mFirstEvent = new SparseBooleanArray();
diff --git a/core/java/android/hardware/display/DisplayManager.java b/core/java/android/hardware/display/DisplayManager.java
index 093e0e9..a517bc5 100644
--- a/core/java/android/hardware/display/DisplayManager.java
+++ b/core/java/android/hardware/display/DisplayManager.java
@@ -115,6 +115,7 @@
       * </p>
      *
      * @see #createVirtualDisplay
+     * @see #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY
      */
     public static final int VIRTUAL_DISPLAY_FLAG_PUBLIC = 1 << 0;
 
@@ -171,6 +172,22 @@
      */
     public static final int VIRTUAL_DISPLAY_FLAG_SECURE = 1 << 2;
 
+    /**
+     * Virtual display flag: Only show this display's own content; do not mirror
+     * the content of another display.
+     *
+     * <p>
+     * This flag is used in conjunction with {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}.
+     * Ordinarily public virtual displays will automatically mirror the content of the
+     * default display if they have no windows of their own.  When this flag is
+     * specified, the virtual display will only ever show its own content and
+     * will be blanked instead if it has no windows.
+     * </p>
+     *
+     * @see #createVirtualDisplay
+     */
+    public static final int VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY = 1 << 3;
+
     /** @hide */
     public DisplayManager(Context context) {
         mContext = context;
@@ -429,8 +446,8 @@
      * @param surface The surface to which the content of the virtual display should
      * be rendered, must be non-null.
      * @param flags A combination of virtual display flags:
-     * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION}
-     * or {@link #VIRTUAL_DISPLAY_FLAG_SECURE}.
+     * {@link #VIRTUAL_DISPLAY_FLAG_PUBLIC}, {@link #VIRTUAL_DISPLAY_FLAG_PRESENTATION},
+     * {@link #VIRTUAL_DISPLAY_FLAG_SECURE}, or {@link #VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY}.
      * @return The newly created virtual display, or null if the application could
      * not create the virtual display.
      *
diff --git a/core/java/android/hardware/display/DisplayManagerInternal.java b/core/java/android/hardware/display/DisplayManagerInternal.java
new file mode 100644
index 0000000..8430973
--- /dev/null
+++ b/core/java/android/hardware/display/DisplayManagerInternal.java
@@ -0,0 +1,109 @@
+/*
+ * 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 android.hardware.display;
+
+import android.view.DisplayInfo;
+
+/**
+ * Display manager local system service interface.
+ *
+ * @hide Only for use within the system server.
+ */
+public abstract class DisplayManagerInternal {
+    /**
+     * Called by the power manager to blank all displays.
+     */
+    public abstract void blankAllDisplaysFromPowerManager();
+
+    /**
+     * Called by the power manager to unblank all displays.
+     */
+    public abstract void unblankAllDisplaysFromPowerManager();
+
+    /**
+     * Returns information about the specified logical display.
+     *
+     * @param displayId The logical display id.
+     * @return The logical display info, or null if the display does not exist.  The
+     * returned object must be treated as immutable.
+     */
+    public abstract DisplayInfo getDisplayInfo(int displayId);
+
+    /**
+     * Registers a display transaction listener to provide the client a chance to
+     * update its surfaces within the same transaction as any display layout updates.
+     *
+     * @param listener The listener to register.
+     */
+    public abstract void registerDisplayTransactionListener(DisplayTransactionListener listener);
+
+    /**
+     * Unregisters a display transaction listener to provide the client a chance to
+     * update its surfaces within the same transaction as any display layout updates.
+     *
+     * @param listener The listener to unregister.
+     */
+    public abstract void unregisterDisplayTransactionListener(DisplayTransactionListener listener);
+
+    /**
+     * Overrides the display information of a particular logical display.
+     * This is used by the window manager to control the size and characteristics
+     * of the default display.  It is expected to apply the requested change
+     * to the display information synchronously so that applications will immediately
+     * observe the new state.
+     *
+     * NOTE: This method must be the only entry point by which the window manager
+     * influences the logical configuration of displays.
+     *
+     * @param displayId The logical display id.
+     * @param info The new data to be stored.
+     */
+    public abstract void setDisplayInfoOverrideFromWindowManager(
+            int displayId, DisplayInfo info);
+
+    /**
+     * Called by the window manager to perform traversals while holding a
+     * surface flinger transaction.
+     */
+    public abstract void performTraversalInTransactionFromWindowManager();
+
+    /**
+     * Tells the display manager whether there is interesting unique content on the
+     * specified logical display.  This is used to control automatic mirroring.
+     * <p>
+     * If the display has unique content, then the display manager arranges for it
+     * to be presented on a physical display if appropriate.  Otherwise, the display manager
+     * may choose to make the physical display mirror some other logical display.
+     * </p>
+     *
+     * @param displayId The logical display id to update.
+     * @param hasContent True if the logical display has content.
+     * @param inTraversal True if called from WindowManagerService during a window traversal
+     * prior to call to performTraversalInTransactionFromWindowManager.
+     */
+    public abstract void setDisplayHasContent(int displayId, boolean hasContent,
+            boolean inTraversal);
+
+    /**
+     * Called within a Surface transaction whenever the size or orientation of a
+     * display may have changed.  Provides an opportunity for the client to
+     * update the position of its surfaces as part of the same transaction.
+     */
+    public interface DisplayTransactionListener {
+        void onDisplayTransaction();
+    }
+}
diff --git a/core/java/android/hardware/display/DisplayViewport.java b/core/java/android/hardware/display/DisplayViewport.java
new file mode 100644
index 0000000..c2d498b
--- /dev/null
+++ b/core/java/android/hardware/display/DisplayViewport.java
@@ -0,0 +1,77 @@
+/*
+ * 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.hardware.display;
+
+import android.graphics.Rect;
+
+/**
+ * Describes how the pixels of physical display device reflects the content of
+ * a logical display.
+ * <p>
+ * This information is used by the input system to translate touch input from
+ * physical display coordinates into logical display coordinates.
+ * </p>
+ *
+ * @hide Only for use within the system server.
+ */
+public final class DisplayViewport {
+    // True if this viewport is valid.
+    public boolean valid;
+
+    // The logical display id.
+    public int displayId;
+
+    // The rotation applied to the physical coordinate system.
+    public int orientation;
+
+    // The portion of the logical display that are presented on this physical display.
+    public final Rect logicalFrame = new Rect();
+
+    // The portion of the (rotated) physical display that shows the logical display contents.
+    // The relation between logical and physical frame defines how the coordinate system
+    // should be scaled or translated after rotation.
+    public final Rect physicalFrame = new Rect();
+
+    // The full width and height of the display device, rotated in the same
+    // manner as physicalFrame.  This expresses the full native size of the display device.
+    // The physical frame should usually fit within this area.
+    public int deviceWidth;
+    public int deviceHeight;
+
+    public void copyFrom(DisplayViewport viewport) {
+        valid = viewport.valid;
+        displayId = viewport.displayId;
+        orientation = viewport.orientation;
+        logicalFrame.set(viewport.logicalFrame);
+        physicalFrame.set(viewport.physicalFrame);
+        deviceWidth = viewport.deviceWidth;
+        deviceHeight = viewport.deviceHeight;
+    }
+
+    // For debugging purposes.
+    @Override
+    public String toString() {
+        return "DisplayViewport{valid=" + valid
+                + ", displayId=" + displayId
+                + ", orientation=" + orientation
+                + ", logicalFrame=" + logicalFrame
+                + ", physicalFrame=" + physicalFrame
+                + ", deviceWidth=" + deviceWidth
+                + ", deviceHeight=" + deviceHeight
+                + "}";
+    }
+}
diff --git a/core/java/android/hardware/input/IInputManager.aidl b/core/java/android/hardware/input/IInputManager.aidl
index 9b6f82a..f1e7e98 100644
--- a/core/java/android/hardware/input/IInputManager.aidl
+++ b/core/java/android/hardware/input/IInputManager.aidl
@@ -16,6 +16,7 @@
 
 package android.hardware.input;
 
+import android.hardware.input.InputDeviceIdentifier;
 import android.hardware.input.KeyboardLayout;
 import android.hardware.input.IInputDevicesChangedListener;
 import android.os.IBinder;
@@ -41,13 +42,13 @@
     // Keyboard layouts configuration.
     KeyboardLayout[] getKeyboardLayouts();
     KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor);
-    String getCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor);
-    void setCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+    String getCurrentKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier);
+    void setCurrentKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
             String keyboardLayoutDescriptor);
-    String[] getKeyboardLayoutsForInputDevice(String inputDeviceDescriptor);
-    void addKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+    String[] getKeyboardLayoutsForInputDevice(in InputDeviceIdentifier identifier);
+    void addKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
             String keyboardLayoutDescriptor);
-    void removeKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+    void removeKeyboardLayoutForInputDevice(in InputDeviceIdentifier identifier,
             String keyboardLayoutDescriptor);
 
     // Registers an input devices changed listener.
diff --git a/core/java/android/hardware/input/InputDeviceIdentifier.aidl b/core/java/android/hardware/input/InputDeviceIdentifier.aidl
new file mode 100644
index 0000000..7234a91
--- /dev/null
+++ b/core/java/android/hardware/input/InputDeviceIdentifier.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2013 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.hardware.input;
+
+parcelable InputDeviceIdentifier;
diff --git a/core/java/android/hardware/input/InputDeviceIdentifier.java b/core/java/android/hardware/input/InputDeviceIdentifier.java
new file mode 100644
index 0000000..5e832e3
--- /dev/null
+++ b/core/java/android/hardware/input/InputDeviceIdentifier.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2013 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.hardware.input;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Wrapper for passing identifying information for input devices.
+ *
+ * @hide
+ */
+public final class InputDeviceIdentifier implements Parcelable {
+    private final String mDescriptor;
+    private final int mVendorId;
+    private final int mProductId;
+
+    public InputDeviceIdentifier(String descriptor, int vendorId, int productId) {
+        this.mDescriptor = descriptor;
+        this.mVendorId = vendorId;
+        this.mProductId = productId;
+    }
+
+    private InputDeviceIdentifier(Parcel src) {
+        mDescriptor = src.readString();
+        mVendorId = src.readInt();
+        mProductId = src.readInt();
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeString(mDescriptor);
+        dest.writeInt(mVendorId);
+        dest.writeInt(mProductId);
+    }
+
+    public String getDescriptor() {
+        return mDescriptor;
+    }
+
+    public int getVendorId() {
+        return mVendorId;
+    }
+
+    public int getProductId() {
+        return mProductId;
+    }
+
+    public static final Parcelable.Creator<InputDeviceIdentifier> CREATOR =
+            new Parcelable.Creator<InputDeviceIdentifier>() {
+
+        @Override
+        public InputDeviceIdentifier createFromParcel(Parcel source) {
+            return new InputDeviceIdentifier(source);
+        }
+
+        @Override
+        public InputDeviceIdentifier[] newArray(int size) {
+            return new InputDeviceIdentifier[size];
+        }
+
+    };
+}
diff --git a/core/java/android/hardware/input/InputManager.java b/core/java/android/hardware/input/InputManager.java
index 30e69a6..a2aeafb 100644
--- a/core/java/android/hardware/input/InputManager.java
+++ b/core/java/android/hardware/input/InputManager.java
@@ -26,6 +26,8 @@
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.Vibrator;
@@ -373,20 +375,17 @@
     }
 
     /**
-     * Gets the current keyboard layout descriptor for the specified input device.
+     * Gets the current keyboard layout descriptor for the specified input
+     * device.
      *
-     * @param inputDeviceDescriptor The input device descriptor.
-     * @return The keyboard layout descriptor, or null if no keyboard layout has been set.
-     *
+     * @param identifier Identifier for the input device
+     * @return The keyboard layout descriptor, or null if no keyboard layout has
+     *         been set.
      * @hide
      */
-    public String getCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor) {
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
-        }
-
+    public String getCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier) {
         try {
-            return mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
+            return mIm.getCurrentKeyboardLayoutForInputDevice(identifier);
         } catch (RemoteException ex) {
             Log.w(TAG, "Could not get current keyboard layout for input device.", ex);
             return null;
@@ -394,28 +393,29 @@
     }
 
     /**
-     * Sets the current keyboard layout descriptor for the specified input device.
+     * Sets the current keyboard layout descriptor for the specified input
+     * device.
      * <p>
-     * This method may have the side-effect of causing the input device in question
-     * to be reconfigured.
+     * This method may have the side-effect of causing the input device in
+     * question to be reconfigured.
      * </p>
      *
-     * @param inputDeviceDescriptor The input device descriptor.
-     * @param keyboardLayoutDescriptor The keyboard layout descriptor to use, must not be null.
-     *
+     * @param identifier The identifier for the input device.
+     * @param keyboardLayoutDescriptor The keyboard layout descriptor to use,
+     *            must not be null.
      * @hide
      */
-    public void setCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+    public void setCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             String keyboardLayoutDescriptor) {
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
+        if (identifier == null) {
+            throw new IllegalArgumentException("identifier must not be null");
         }
         if (keyboardLayoutDescriptor == null) {
             throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
         }
 
         try {
-            mIm.setCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor,
+            mIm.setCurrentKeyboardLayoutForInputDevice(identifier,
                     keyboardLayoutDescriptor);
         } catch (RemoteException ex) {
             Log.w(TAG, "Could not set current keyboard layout for input device.", ex);
@@ -423,20 +423,20 @@
     }
 
     /**
-     * Gets all keyboard layout descriptors that are enabled for the specified input device.
+     * Gets all keyboard layout descriptors that are enabled for the specified
+     * input device.
      *
-     * @param inputDeviceDescriptor The input device descriptor.
+     * @param identifier The identifier for the input device.
      * @return The keyboard layout descriptors.
-     *
      * @hide
      */
-    public String[] getKeyboardLayoutsForInputDevice(String inputDeviceDescriptor) {
-        if (inputDeviceDescriptor == null) {
+    public String[] getKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier) {
+        if (identifier == null) {
             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
         }
 
         try {
-            return mIm.getKeyboardLayoutsForInputDevice(inputDeviceDescriptor);
+            return mIm.getKeyboardLayoutsForInputDevice(identifier);
         } catch (RemoteException ex) {
             Log.w(TAG, "Could not get keyboard layouts for input device.", ex);
             return ArrayUtils.emptyArray(String.class);
@@ -446,18 +446,18 @@
     /**
      * Adds the keyboard layout descriptor for the specified input device.
      * <p>
-     * This method may have the side-effect of causing the input device in question
-     * to be reconfigured.
+     * This method may have the side-effect of causing the input device in
+     * question to be reconfigured.
      * </p>
      *
-     * @param inputDeviceDescriptor The input device descriptor.
-     * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to add.
-     *
+     * @param identifier The identifier for the input device.
+     * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to
+     *            add.
      * @hide
      */
-    public void addKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+    public void addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             String keyboardLayoutDescriptor) {
-        if (inputDeviceDescriptor == null) {
+        if (identifier == null) {
             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
         }
         if (keyboardLayoutDescriptor == null) {
@@ -465,7 +465,7 @@
         }
 
         try {
-            mIm.addKeyboardLayoutForInputDevice(inputDeviceDescriptor, keyboardLayoutDescriptor);
+            mIm.addKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
         } catch (RemoteException ex) {
             Log.w(TAG, "Could not add keyboard layout for input device.", ex);
         }
@@ -474,18 +474,18 @@
     /**
      * Removes the keyboard layout descriptor for the specified input device.
      * <p>
-     * This method may have the side-effect of causing the input device in question
-     * to be reconfigured.
+     * This method may have the side-effect of causing the input device in
+     * question to be reconfigured.
      * </p>
      *
-     * @param inputDeviceDescriptor The input device descriptor.
-     * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to remove.
-     *
+     * @param identifier The identifier for the input device.
+     * @param keyboardLayoutDescriptor The descriptor of the keyboard layout to
+     *            remove.
      * @hide
      */
-    public void removeKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
+    public void removeKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
             String keyboardLayoutDescriptor) {
-        if (inputDeviceDescriptor == null) {
+        if (identifier == null) {
             throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
         }
         if (keyboardLayoutDescriptor == null) {
@@ -493,7 +493,7 @@
         }
 
         try {
-            mIm.removeKeyboardLayoutForInputDevice(inputDeviceDescriptor, keyboardLayoutDescriptor);
+            mIm.removeKeyboardLayoutForInputDevice(identifier, keyboardLayoutDescriptor);
         } catch (RemoteException ex) {
             Log.w(TAG, "Could not remove keyboard layout for input device.", ex);
         }
diff --git a/core/java/android/hardware/input/InputManagerInternal.java b/core/java/android/hardware/input/InputManagerInternal.java
new file mode 100644
index 0000000..8be94d0
--- /dev/null
+++ b/core/java/android/hardware/input/InputManagerInternal.java
@@ -0,0 +1,36 @@
+/*
+ * 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 android.hardware.input;
+
+import android.hardware.display.DisplayViewport;
+import android.view.InputEvent;
+
+/**
+ * Input manager local system service interface.
+ *
+ * @hide Only for use within the system server.
+ */
+public abstract class InputManagerInternal {
+    /**
+     * Sets information about the displays as needed by the input system.
+     * The input system should copy this information if required.
+     */
+    public abstract void setDisplayViewports(DisplayViewport defaultViewport,
+            DisplayViewport externalTouchViewport);
+
+    public abstract boolean injectInputEvent(InputEvent event, int displayId, int mode);
+}
diff --git a/core/java/android/hardware/usb/UsbDevice.java b/core/java/android/hardware/usb/UsbDevice.java
index 9bd38f9..d1e63f6 100644
--- a/core/java/android/hardware/usb/UsbDevice.java
+++ b/core/java/android/hardware/usb/UsbDevice.java
@@ -46,6 +46,9 @@
     private static final String TAG = "UsbDevice";
 
     private final String mName;
+    private final String mManufacturerName;
+    private final String mProductName;
+    private final String mSerialNumber;
     private final int mVendorId;
     private final int mProductId;
     private final int mClass;
@@ -58,13 +61,18 @@
      * @hide
      */
     public UsbDevice(String name, int vendorId, int productId,
-            int Class, int subClass, int protocol, Parcelable[] interfaces) {
+            int Class, int subClass, int protocol,
+            String manufacturerName, String productName, String serialNumber,
+            Parcelable[] interfaces) {
         mName = name;
         mVendorId = vendorId;
         mProductId = productId;
         mClass = Class;
         mSubclass = subClass;
         mProtocol = protocol;
+        mManufacturerName = manufacturerName;
+        mProductName = productName;
+        mSerialNumber = serialNumber;
         mInterfaces = interfaces;
     }
 
@@ -80,6 +88,33 @@
     }
 
     /**
+     * Returns the manufacturer name of the device.
+     *
+     * @return the manufacturer name
+     */
+    public String getManufacturerName() {
+        return mManufacturerName;
+    }
+
+    /**
+     * Returns the product name of the device.
+     *
+     * @return the product name
+     */
+    public String getProductName() {
+        return mProductName;
+    }
+
+    /**
+     * Returns the serial number of the device.
+     *
+     * @return the serial number name
+     */
+    public String getSerialNumber() {
+        return mSerialNumber;
+    }
+
+    /**
      * Returns a unique integer ID for the device.
      * This is a convenience for clients that want to use an integer to represent
      * the device, rather than the device name.
@@ -176,7 +211,8 @@
         return "UsbDevice[mName=" + mName + ",mVendorId=" + mVendorId +
                 ",mProductId=" + mProductId + ",mClass=" + mClass +
                 ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol +
-                ",mInterfaces=" + mInterfaces + "]";
+                ",mManufacturerName=" + mManufacturerName + ",mProductName=" + mProductName +
+                ",mSerialNumber=" + mSerialNumber + ",mInterfaces=" + mInterfaces + "]";
     }
 
     public static final Parcelable.Creator<UsbDevice> CREATOR =
@@ -188,8 +224,12 @@
             int clasz = in.readInt();
             int subClass = in.readInt();
             int protocol = in.readInt();
+            String manufacturerName = in.readString();
+            String productName = in.readString();
+            String serialNumber = in.readString();
             Parcelable[] interfaces = in.readParcelableArray(UsbInterface.class.getClassLoader());
-            return new UsbDevice(name, vendorId, productId, clasz, subClass, protocol, interfaces);
+            return new UsbDevice(name, vendorId, productId, clasz, subClass, protocol,
+                                 manufacturerName, productName, serialNumber, interfaces);
         }
 
         public UsbDevice[] newArray(int size) {
@@ -208,6 +248,9 @@
         parcel.writeInt(mClass);
         parcel.writeInt(mSubclass);
         parcel.writeInt(mProtocol);
+        parcel.writeString(mManufacturerName);
+        parcel.writeString(mProductName);
+        parcel.writeString(mSerialNumber);
         parcel.writeParcelableArray(mInterfaces, 0);
    }
 
diff --git a/core/java/android/hardware/usb/UsbDeviceConnection.java b/core/java/android/hardware/usb/UsbDeviceConnection.java
index b2034b2..389475f 100644
--- a/core/java/android/hardware/usb/UsbDeviceConnection.java
+++ b/core/java/android/hardware/usb/UsbDeviceConnection.java
@@ -32,7 +32,7 @@
     private final UsbDevice mDevice;
 
     // used by the JNI code
-    private int mNativeContext;
+    private long mNativeContext;
 
     /**
      * UsbDevice should only be instantiated by UsbService implementation
diff --git a/core/java/android/hardware/usb/UsbRequest.java b/core/java/android/hardware/usb/UsbRequest.java
index 3646715..ce66084 100644
--- a/core/java/android/hardware/usb/UsbRequest.java
+++ b/core/java/android/hardware/usb/UsbRequest.java
@@ -37,7 +37,7 @@
     private static final String TAG = "UsbRequest";
 
     // used by the JNI code
-    private int mNativeContext;
+    private long mNativeContext;
 
     private UsbEndpoint mEndpoint;
 
diff --git a/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java b/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java
index 726dcec..bbea8ff 100644
--- a/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java
+++ b/core/java/android/inputmethodservice/IInputMethodSessionWrapper.java
@@ -75,7 +75,15 @@
     @Override
     public void executeMessage(Message msg) {
         if (mInputMethodSession == null) {
-            // The session has been finished.
+            // The session has been finished. Args needs to be recycled
+            // for cases below.
+            switch (msg.what) {
+                case DO_UPDATE_SELECTION:
+                case DO_APP_PRIVATE_COMMAND: {
+                    SomeArgs args = (SomeArgs)msg.obj;
+                    args.recycle();
+                }
+            }
             return;
         }
 
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 70c8750..4eecfa9 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -361,11 +361,17 @@
      */
     public static final int TYPE_MOBILE_IA = 14;
 
-    /** {@hide} */
-    public static final int MAX_RADIO_TYPE   = TYPE_MOBILE_IA;
+    /**
+     * The network that uses proxy to achieve connectivity.
+     * {@hide}
+     */
+    public static final int TYPE_PROXY = 16;
 
     /** {@hide} */
-    public static final int MAX_NETWORK_TYPE = TYPE_MOBILE_IA;
+    public static final int MAX_RADIO_TYPE   = TYPE_PROXY;
+
+    /** {@hide} */
+    public static final int MAX_NETWORK_TYPE = TYPE_PROXY;
 
     /**
      * If you want to set the default network preference,you can directly
@@ -446,6 +452,8 @@
                 return "WIFI_P2P";
             case TYPE_MOBILE_IA:
                 return "MOBILE_IA";
+            case TYPE_PROXY:
+                return "PROXY";
             default:
                 return Integer.toString(type);
         }
diff --git a/core/java/android/net/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java
index 501484c..cc8c771 100644
--- a/core/java/android/net/EthernetDataTracker.java
+++ b/core/java/android/net/EthernetDataTracker.java
@@ -402,7 +402,7 @@
      * for this network.
      */
     public String getTcpBufferSizesPropName() {
-        return "net.tcp.buffersize.wifi";
+        return "net.tcp.buffersize.ethernet";
     }
 
     public void setDependencyMet(boolean met) {
diff --git a/core/java/android/net/INetworkManagementEventObserver.aidl b/core/java/android/net/INetworkManagementEventObserver.aidl
index b76e4c2..5b16f8b 100644
--- a/core/java/android/net/INetworkManagementEventObserver.aidl
+++ b/core/java/android/net/INetworkManagementEventObserver.aidl
@@ -16,6 +16,8 @@
 
 package android.net;
 
+import android.net.LinkAddress;
+
 /**
  * Callback class for receiving events from an INetworkManagementService
  *
@@ -55,24 +57,20 @@
 
 
     /**
-     * An interface address has been added or updated
+     * An interface address has been added or updated.
      *
-     * @param address The address.
      * @param iface The interface.
-     * @param flags The address flags.
-     * @param scope The address scope.
+     * @param address The address.
      */
-    void addressUpdated(String address, String iface, int flags, int scope);
+    void addressUpdated(String iface, in LinkAddress address);
 
     /**
-     * An interface address has been removed
+     * An interface address has been removed.
      *
-     * @param address The address.
      * @param iface The interface.
-     * @param flags The address flags.
-     * @param scope The address scope.
+     * @param address The address.
      */
-    void addressRemoved(String address, String iface, int flags, int scope);
+    void addressRemoved(String iface, in LinkAddress address);
 
     /**
      * A networking quota limit has been reached. The quota might not
@@ -90,4 +88,13 @@
      * @param active  True if the interface is actively transmitting data, false if it is idle.
      */
     void interfaceClassDataActivityChanged(String label, boolean active);
+
+    /**
+     * Information about available DNS servers has been received.
+     *
+     * @param iface The interface on which the information was received.
+     * @param lifetime The time in seconds for which the DNS servers may be used.
+     * @param servers The IP addresses of the DNS servers.
+     */
+    void interfaceDnsServerInfo(String iface, long lifetime, in String[] servers);
 }
diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java
index a390add..22543e3 100644
--- a/core/java/android/net/LinkAddress.java
+++ b/core/java/android/net/LinkAddress.java
@@ -24,8 +24,32 @@
 import java.net.InterfaceAddress;
 import java.net.UnknownHostException;
 
+import static libcore.io.OsConstants.IFA_F_DADFAILED;
+import static libcore.io.OsConstants.IFA_F_DEPRECATED;
+import static libcore.io.OsConstants.IFA_F_TENTATIVE;
+import static libcore.io.OsConstants.RT_SCOPE_HOST;
+import static libcore.io.OsConstants.RT_SCOPE_LINK;
+import static libcore.io.OsConstants.RT_SCOPE_SITE;
+import static libcore.io.OsConstants.RT_SCOPE_UNIVERSE;
+
 /**
- * Identifies an address of a network link
+ * Identifies an IP address on a network link.
+ *
+ * A {@code LinkAddress} consists of:
+ * <ul>
+ * <li>An IP address and prefix length (e.g., {@code 2001:db8::1/64} or {@code 192.0.2.1/24}).
+ * The address must be unicast, as multicast addresses cannot be assigned to interfaces.
+ * <li>Address flags: A bitmask of {@code IFA_F_*} values representing properties of the address.
+ * <li>Address scope: An integer defining the scope in which the address is unique (e.g.,
+ * {@code RT_SCOPE_LINK} or {@code RT_SCOPE_SITE}).
+ * <ul>
+ *<p>
+ * When constructing a {@code LinkAddress}, the IP address and prefix are required. The flags and
+ * scope are optional. If they are not specified, the flags are set to zero, and the scope will be
+ * determined based on the IP address (e.g., link-local addresses will be created with a scope of
+ * {@code RT_SCOPE_LINK}, global addresses with {@code RT_SCOPE_UNIVERSE}, etc.) If they are
+ * specified, they are not checked for validity.
+ *
  * @hide
  */
 public class LinkAddress implements Parcelable {
@@ -35,12 +59,50 @@
     private InetAddress address;
 
     /**
-     * Network prefix length
+     * Prefix length.
      */
     private int prefixLength;
 
-    private void init(InetAddress address, int prefixLength) {
-        if (address == null || prefixLength < 0 ||
+    /**
+     * Address flags. A bitmask of IFA_F_* values.
+     */
+    private int flags;
+
+    /**
+     * Address scope. One of the RT_SCOPE_* constants.
+     */
+    private int scope;
+
+    /**
+     * Utility function to determines the scope of a unicast address. Per RFC 4291 section 2.5 and
+     * RFC 6724 section 3.2.
+     * @hide
+     */
+    static int scopeForUnicastAddress(InetAddress addr) {
+        if (addr.isAnyLocalAddress()) {
+            return RT_SCOPE_HOST;
+        }
+
+        if (addr.isLoopbackAddress() || addr.isLinkLocalAddress()) {
+            return RT_SCOPE_LINK;
+        }
+
+        // isSiteLocalAddress() returns true for private IPv4 addresses, but RFC 6724 section 3.2
+        // says that they are assigned global scope.
+        if (!(addr instanceof Inet4Address) && addr.isSiteLocalAddress()) {
+            return RT_SCOPE_SITE;
+        }
+
+        return RT_SCOPE_UNIVERSE;
+    }
+
+    /**
+     * Utility function for the constructors.
+     */
+    private void init(InetAddress address, int prefixLength, int flags, int scope) {
+        if (address == null ||
+                address.isMulticastAddress() ||
+                prefixLength < 0 ||
                 ((address instanceof Inet4Address) && prefixLength > 32) ||
                 (prefixLength > 128)) {
             throw new IllegalArgumentException("Bad LinkAddress params " + address +
@@ -48,23 +110,59 @@
         }
         this.address = address;
         this.prefixLength = prefixLength;
+        this.flags = flags;
+        this.scope = scope;
     }
 
+    /**
+     * Constructs a new {@code LinkAddress} from an {@code InetAddress} and prefix length, with
+     * the specified flags and scope. Flags and scope are not checked for validity.
+     * @param address The IP address.
+     * @param prefixLength The prefix length.
+     */
+    public LinkAddress(InetAddress address, int prefixLength, int flags, int scope) {
+        init(address, prefixLength, flags, scope);
+    }
+
+    /**
+     * Constructs a new {@code LinkAddress} from an {@code InetAddress} and a prefix length.
+     * The flags are set to zero and the scope is determined from the address.
+     * @param address The IP address.
+     * @param prefixLength The prefix length.
+     */
     public LinkAddress(InetAddress address, int prefixLength) {
-        init(address, prefixLength);
+        this(address, prefixLength, 0, 0);
+        this.scope = scopeForUnicastAddress(address);
     }
 
+    /**
+     * Constructs a new {@code LinkAddress} from an {@code InterfaceAddress}.
+     * The flags are set to zero and the scope is determined from the address.
+     * @param interfaceAddress The interface address.
+     */
     public LinkAddress(InterfaceAddress interfaceAddress) {
-        init(interfaceAddress.getAddress(),
+        this(interfaceAddress.getAddress(),
              interfaceAddress.getNetworkPrefixLength());
     }
 
     /**
      * Constructs a new {@code LinkAddress} from a string such as "192.0.2.5/24" or
-     * "2001:db8::1/64".
+     * "2001:db8::1/64". The flags are set to zero and the scope is determined from the address.
      * @param string The string to parse.
      */
     public LinkAddress(String address) {
+        this(address, 0, 0);
+        this.scope = scopeForUnicastAddress(this.address);
+    }
+
+    /**
+     * Constructs a new {@code LinkAddress} from a string such as "192.0.2.5/24" or
+     * "2001:db8::1/64", with the specified flags and scope.
+     * @param string The string to parse.
+     * @param flags The address flags.
+     * @param scope The address scope.
+     */
+    public LinkAddress(String address, int flags, int scope) {
         InetAddress inetAddress = null;
         int prefixLength = -1;
         try {
@@ -81,18 +179,22 @@
             throw new IllegalArgumentException("Bad LinkAddress params " + address);
         }
 
-        init(inetAddress, prefixLength);
-    }
-
-    @Override
-    public String toString() {
-        return (address == null ? "" : (address.getHostAddress() + "/" + prefixLength));
+        init(inetAddress, prefixLength, flags, scope);
     }
 
     /**
-     * Compares this {@code LinkAddress} instance against the specified address
-     * in {@code obj}. Two addresses are equal if their InetAddress and prefixLength
-     * are equal
+     * Returns a string representation of this address, such as "192.0.2.1/24" or "2001:db8::1/64".
+     * The string representation does not contain the flags and scope, just the address and prefix
+     * length.
+     */
+    @Override
+    public String toString() {
+        return address.getHostAddress() + "/" + prefixLength;
+    }
+
+    /**
+     * Compares this {@code LinkAddress} instance against {@code obj}. Two addresses are equal if
+     * their address, prefix length, flags and scope are equal.
      *
      * @param obj the object to be tested for equality.
      * @return {@code true} if both objects are equal, {@code false} otherwise.
@@ -104,33 +206,70 @@
         }
         LinkAddress linkAddress = (LinkAddress) obj;
         return this.address.equals(linkAddress.address) &&
-            this.prefixLength == linkAddress.prefixLength;
-    }
-
-    @Override
-    /*
-     * generate hashcode based on significant fields
-     */
-    public int hashCode() {
-        return ((null == address) ? 0 : address.hashCode()) + prefixLength;
+            this.prefixLength == linkAddress.prefixLength &&
+            this.flags == linkAddress.flags &&
+            this.scope == linkAddress.scope;
     }
 
     /**
-     * Returns the InetAddress for this address.
+     * Returns a hashcode for this address.
+     */
+    @Override
+    public int hashCode() {
+        return address.hashCode() + 11 * prefixLength + 19 * flags + 43 * scope;
+    }
+
+    /**
+     * Determines whether this {@code LinkAddress} and the provided {@code LinkAddress} represent
+     * the same address. Two LinkAddresses represent the same address if they have the same IP
+     * address and prefix length, even if their properties are different.
+     *
+     * @param other the {@code LinkAddress} to compare to.
+     * @return {@code true} if both objects have the same address and prefix length, {@code false}
+     * otherwise.
+     */
+    public boolean isSameAddressAs(LinkAddress other) {
+        return address.equals(other.address) && prefixLength == other.prefixLength;
+    }
+
+    /**
+     * Returns the InetAddress of this address.
      */
     public InetAddress getAddress() {
         return address;
     }
 
     /**
-     * Get network prefix length
+     * Returns the prefix length of this address.
      */
     public int getNetworkPrefixLength() {
         return prefixLength;
     }
 
     /**
-     * Implement the Parcelable interface
+     * Returns the flags of this address.
+     */
+    public int getFlags() {
+        return flags;
+    }
+
+    /**
+     * Returns the scope of this address.
+     */
+    public int getScope() {
+        return scope;
+    }
+
+    /**
+     * Returns true if this {@code LinkAddress} is global scope and preferred.
+     */
+    public boolean isGlobalPreferred() {
+        return (scope == RT_SCOPE_UNIVERSE &&
+                (flags & (IFA_F_DADFAILED | IFA_F_DEPRECATED | IFA_F_TENTATIVE)) == 0L);
+    }
+
+    /**
+     * Implement the Parcelable interface.
      * @hide
      */
     public int describeContents() {
@@ -142,13 +281,10 @@
      * @hide
      */
     public void writeToParcel(Parcel dest, int flags) {
-        if (address != null) {
-            dest.writeByte((byte)1);
-            dest.writeByteArray(address.getAddress());
-            dest.writeInt(prefixLength);
-        } else {
-            dest.writeByte((byte)0);
-        }
+        dest.writeByteArray(address.getAddress());
+        dest.writeInt(prefixLength);
+        dest.writeInt(this.flags);
+        dest.writeInt(scope);
     }
 
     /**
@@ -159,14 +295,17 @@
         new Creator<LinkAddress>() {
             public LinkAddress createFromParcel(Parcel in) {
                 InetAddress address = null;
-                int prefixLength = 0;
-                if (in.readByte() == 1) {
-                    try {
-                        address = InetAddress.getByAddress(in.createByteArray());
-                        prefixLength = in.readInt();
-                    } catch (UnknownHostException e) { }
+                try {
+                    address = InetAddress.getByAddress(in.createByteArray());
+                } catch (UnknownHostException e) {
+                    // Nothing we can do here. When we call the constructor, we'll throw an
+                    // IllegalArgumentException, because a LinkAddress can't have a null
+                    // InetAddress.
                 }
-                return new LinkAddress(address, prefixLength);
+                int prefixLength = in.readInt();
+                int flags = in.readInt();
+                int scope = in.readInt();
+                return new LinkAddress(address, prefixLength, flags, scope);
             }
 
             public LinkAddress[] newArray(int size) {
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index b4d07a1..4dfd3d9 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -61,10 +61,10 @@
 public class LinkProperties implements Parcelable {
     // The interface described by the network link.
     private String mIfaceName;
-    private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
-    private Collection<InetAddress> mDnses = new ArrayList<InetAddress>();
+    private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
+    private ArrayList<InetAddress> mDnses = new ArrayList<InetAddress>();
     private String mDomains;
-    private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
+    private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
     private ProxyProperties mHttpProxy;
     private int mMtu;
 
@@ -156,28 +156,52 @@
         return addresses;
     }
 
-    /**
-     * Adds a link address if it does not exist, or update it if it does.
-     * @param address The {@code LinkAddress} to add.
-     * @return true if the address was added, false if it already existed.
-     */
-    public boolean addLinkAddress(LinkAddress address) {
-        // TODO: when the LinkAddress has other attributes beyond the
-        // address and the prefix length, update them here.
-        if (address != null && !mLinkAddresses.contains(address)) {
-            mLinkAddresses.add(address);
-            return true;
+    private int findLinkAddressIndex(LinkAddress address) {
+        for (int i = 0; i < mLinkAddresses.size(); i++) {
+            if (mLinkAddresses.get(i).isSameAddressAs(address)) {
+                return i;
+            }
         }
-        return false;
+        return -1;
     }
 
     /**
-     * Removes a link address.
-     * @param address The {@code LinkAddress} to remove.
+     * Adds a link address if it does not exist, or updates it if it does.
+     * @param address The {@code LinkAddress} to add.
+     * @return true if {@code address} was added or updated, false otherwise.
+     */
+    public boolean addLinkAddress(LinkAddress address) {
+        if (address == null) {
+            return false;
+        }
+        int i = findLinkAddressIndex(address);
+        if (i < 0) {
+            // Address was not present. Add it.
+            mLinkAddresses.add(address);
+            return true;
+        } else if (mLinkAddresses.get(i).equals(address)) {
+            // Address was present and has same properties. Do nothing.
+            return false;
+        } else {
+            // Address was present and has different properties. Update it.
+            mLinkAddresses.set(i, address);
+            return true;
+        }
+    }
+
+    /**
+     * Removes a link address. Specifically, removes the link address, if any, for which
+     * {@code isSameAddressAs(toRemove)} returns true.
+     * @param address A {@code LinkAddress} specifying the address to remove.
      * @return true if the address was removed, false if it did not exist.
      */
     public boolean removeLinkAddress(LinkAddress toRemove) {
-        return mLinkAddresses.remove(toRemove);
+        int i = findLinkAddressIndex(toRemove);
+        if (i >= 0) {
+            mLinkAddresses.remove(i);
+            return true;
+        }
+        return false;
     }
 
     /**
diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java
index 3c67bf9..36dd2fdfb 100644
--- a/core/java/android/net/NetworkIdentity.java
+++ b/core/java/android/net/NetworkIdentity.java
@@ -26,7 +26,7 @@
 import android.os.Build;
 import android.telephony.TelephonyManager;
 
-import com.android.internal.util.Objects;
+import java.util.Objects;
 
 /**
  * Network definition that includes strong identity. Analogous to combining
@@ -60,7 +60,7 @@
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(mType, mSubType, mSubscriberId, mNetworkId, mRoaming);
+        return Objects.hash(mType, mSubType, mSubscriberId, mNetworkId, mRoaming);
     }
 
     @Override
@@ -68,8 +68,8 @@
         if (obj instanceof NetworkIdentity) {
             final NetworkIdentity ident = (NetworkIdentity) obj;
             return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
-                    && Objects.equal(mSubscriberId, ident.mSubscriberId)
-                    && Objects.equal(mNetworkId, ident.mNetworkId);
+                    && Objects.equals(mSubscriberId, ident.mSubscriberId)
+                    && Objects.equals(mNetworkId, ident.mNetworkId);
         }
         return false;
     }
diff --git a/core/java/android/net/NetworkPolicy.java b/core/java/android/net/NetworkPolicy.java
index 441db7a..10c686b 100644
--- a/core/java/android/net/NetworkPolicy.java
+++ b/core/java/android/net/NetworkPolicy.java
@@ -21,7 +21,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 
-import com.android.internal.util.Objects;
+import java.util.Objects;
 
 /**
  * Policy for networks matching a {@link NetworkTemplate}, including usage cycle
@@ -146,7 +146,7 @@
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(template, cycleDay, cycleTimezone, warningBytes, limitBytes,
+        return Objects.hash(template, cycleDay, cycleTimezone, warningBytes, limitBytes,
                 lastWarningSnooze, lastLimitSnooze, metered, inferred);
     }
 
@@ -159,8 +159,8 @@
                     && lastWarningSnooze == other.lastWarningSnooze
                     && lastLimitSnooze == other.lastLimitSnooze && metered == other.metered
                     && inferred == other.inferred
-                    && Objects.equal(cycleTimezone, other.cycleTimezone)
-                    && Objects.equal(template, other.template);
+                    && Objects.equals(cycleTimezone, other.cycleTimezone)
+                    && Objects.equals(template, other.template);
         }
         return false;
     }
diff --git a/core/java/android/net/NetworkStats.java b/core/java/android/net/NetworkStats.java
index 9cb904d..a7aae2a 100644
--- a/core/java/android/net/NetworkStats.java
+++ b/core/java/android/net/NetworkStats.java
@@ -23,12 +23,12 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.Objects;
 
 import java.io.CharArrayWriter;
 import java.io.PrintWriter;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.Objects;
 
 /**
  * Collection of active network statistics. Can contain summary details across
@@ -337,7 +337,7 @@
     public int findIndex(String iface, int uid, int set, int tag) {
         for (int i = 0; i < size; i++) {
             if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i]
-                    && Objects.equal(iface, this.iface[i])) {
+                    && Objects.equals(iface, this.iface[i])) {
                 return i;
             }
         }
@@ -362,7 +362,7 @@
             }
 
             if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i]
-                    && Objects.equal(iface, this.iface[i])) {
+                    && Objects.equals(iface, this.iface[i])) {
                 return i;
             }
         }
diff --git a/core/java/android/net/NetworkTemplate.java b/core/java/android/net/NetworkTemplate.java
index c189ba4..27197cc 100644
--- a/core/java/android/net/NetworkTemplate.java
+++ b/core/java/android/net/NetworkTemplate.java
@@ -34,8 +34,9 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 
+import java.util.Objects;
+
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.Objects;
 
 /**
  * Template definition used to generically match {@link NetworkIdentity},
@@ -176,7 +177,7 @@
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(mMatchRule, mSubscriberId, mNetworkId);
+        return Objects.hash(mMatchRule, mSubscriberId, mNetworkId);
     }
 
     @Override
@@ -184,8 +185,8 @@
         if (obj instanceof NetworkTemplate) {
             final NetworkTemplate other = (NetworkTemplate) obj;
             return mMatchRule == other.mMatchRule
-                    && Objects.equal(mSubscriberId, other.mSubscriberId)
-                    && Objects.equal(mNetworkId, other.mNetworkId);
+                    && Objects.equals(mSubscriberId, other.mSubscriberId)
+                    && Objects.equals(mNetworkId, other.mNetworkId);
         }
         return false;
     }
@@ -235,7 +236,7 @@
             return true;
         } else {
             return ((sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType))
-                    && Objects.equal(mSubscriberId, ident.mSubscriberId));
+                    && Objects.equals(mSubscriberId, ident.mSubscriberId));
         }
     }
 
@@ -280,7 +281,7 @@
     private boolean matchesWifi(NetworkIdentity ident) {
         switch (ident.mType) {
             case TYPE_WIFI:
-                return Objects.equal(
+                return Objects.equals(
                         removeDoubleQuotes(mNetworkId), removeDoubleQuotes(ident.mNetworkId));
             default:
                 return false;
diff --git a/core/java/android/net/ProxyDataTracker.java b/core/java/android/net/ProxyDataTracker.java
new file mode 100644
index 0000000..461e8b8
--- /dev/null
+++ b/core/java/android/net/ProxyDataTracker.java
@@ -0,0 +1,204 @@
+/*
+ * 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 android.net;
+
+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.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.util.Log;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A data tracker responsible for bringing up and tearing down the system proxy server.
+ *
+ * {@hide}
+ */
+public class ProxyDataTracker extends BaseNetworkStateTracker {
+    private static final String TAG = "ProxyDataTracker";
+    private static final String NETWORK_TYPE = "PROXY";
+
+    // TODO: investigate how to get these DNS addresses from the system.
+    private static final String DNS1 = "8.8.8.8";
+    private static final String DNS2 = "8.8.4.4";
+    private static final String REASON_ENABLED = "enabled";
+    private static final String REASON_DISABLED = "disabled";
+    private static final String REASON_PROXY_DOWN = "proxy_down";
+
+    private static final int MSG_TEAR_DOWN_REQUEST = 1;
+    private static final int MSG_SETUP_REQUEST = 2;
+
+    private static final String PERMISSION_PROXY_STATUS_SENDER =
+            "android.permission.ACCESS_NETWORK_CONDITIONS";
+    private static final String ACTION_PROXY_STATUS_CHANGE =
+            "com.android.net.PROXY_STATUS_CHANGE";
+    private static final String KEY_IS_PROXY_AVAILABLE = "is_proxy_available";
+    private static final String KEY_REPLY_TO_MESSENGER_BINDER = "reply_to_messenger_binder";
+    private static final String KEY_REPLY_TO_MESSENGER_BINDER_BUNDLE =
+            "reply_to_messenger_binder_bundle";
+
+    private Handler mTarget;
+    private Messenger mProxyStatusService;
+    private AtomicBoolean mReconnectRequested = new AtomicBoolean(false);
+    private AtomicBoolean mIsProxyAvailable = new AtomicBoolean(false);
+    private final AtomicInteger mDefaultGatewayAddr = new AtomicInteger(0);
+
+    private final BroadcastReceiver mProxyStatusServiceListener = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(ACTION_PROXY_STATUS_CHANGE)) {
+                mIsProxyAvailable.set(intent.getBooleanExtra(KEY_IS_PROXY_AVAILABLE, false));
+                if (mIsProxyAvailable.get()) {
+                    Bundle bundle = intent.getBundleExtra(KEY_REPLY_TO_MESSENGER_BINDER_BUNDLE);
+                    if (bundle == null || bundle.getBinder(KEY_REPLY_TO_MESSENGER_BINDER) == null) {
+                        Log.e(TAG, "no messenger binder in the intent to send future requests");
+                        mIsProxyAvailable.set(false);
+                        return;
+                    }
+                    mProxyStatusService =
+                            new Messenger(bundle.getBinder(KEY_REPLY_TO_MESSENGER_BINDER));
+                    // If there is a pending reconnect request, do it now.
+                    if (mReconnectRequested.get()) {
+                        reconnect();
+                    }
+                } else {
+                    setDetailedState(NetworkInfo.DetailedState.DISCONNECTED,
+                            REASON_PROXY_DOWN, null);
+                }
+            } else {
+                Log.d(TAG, "Unrecognized broadcast intent");
+            }
+        }
+    };
+
+    /**
+     * Create a new ProxyDataTracker
+     */
+    public ProxyDataTracker() {
+        mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_PROXY, 0, NETWORK_TYPE, "");
+        mLinkProperties = new LinkProperties();
+        mLinkCapabilities = new LinkCapabilities();
+        mNetworkInfo.setIsAvailable(true);
+        try {
+          mLinkProperties.addDns(InetAddress.getByName(DNS1));
+          mLinkProperties.addDns(InetAddress.getByName(DNS2));
+        } catch (UnknownHostException e) {
+          Log.e(TAG, "Could not add DNS address", e);
+        }
+    }
+
+    public Object Clone() throws CloneNotSupportedException {
+        throw new CloneNotSupportedException();
+    }
+
+    @Override
+    public void startMonitoring(Context context, Handler target) {
+        mContext = context;
+        mTarget = target;
+        mContext.registerReceiver(mProxyStatusServiceListener,
+                new IntentFilter(ACTION_PROXY_STATUS_CHANGE),
+                PERMISSION_PROXY_STATUS_SENDER,
+                null);
+    }
+
+    /**
+     * Disable connectivity to the network.
+     */
+    public boolean teardown() {
+        setTeardownRequested(true);
+        mReconnectRequested.set(false);
+        try {
+            if (mIsProxyAvailable.get() && mProxyStatusService != null) {
+                mProxyStatusService.send(Message.obtain(null, MSG_TEAR_DOWN_REQUEST));
+            }
+        } catch (RemoteException e) {
+            Log.e(TAG, "Unable to connect to proxy status service", e);
+            return false;
+        }
+        setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, REASON_DISABLED, null);
+        return true;
+    }
+
+    /**
+     * Re-enable proxy data connectivity after a {@link #teardown()}.
+     */
+    public boolean reconnect() {
+        mReconnectRequested.set(true);
+        setTeardownRequested(false);
+        if (!mIsProxyAvailable.get()) {
+            Log.w(TAG, "Reconnect requested even though proxy service is not up. Bailing.");
+            return false;
+        }
+        setDetailedState(NetworkInfo.DetailedState.CONNECTING, REASON_ENABLED, null);
+
+        try {
+            mProxyStatusService.send(Message.obtain(null, MSG_SETUP_REQUEST));
+        } catch (RemoteException e) {
+            Log.e(TAG, "Unable to connect to proxy status service", e);
+            setDetailedState(NetworkInfo.DetailedState.DISCONNECTED, REASON_PROXY_DOWN, null);
+            return false;
+        }
+        // We'll assume proxy is set up successfully. If not, a status change broadcast will be
+        // received afterwards to indicate any failure.
+        setDetailedState(NetworkInfo.DetailedState.CONNECTED, REASON_ENABLED, null);
+        return true;
+    }
+
+    /**
+     * Fetch default gateway address for the network
+     */
+    public int getDefaultGatewayAddr() {
+        return mDefaultGatewayAddr.get();
+    }
+
+    /**
+     * Return the system properties name associated with the tcp buffer sizes
+     * for this network.
+     */
+    public String getTcpBufferSizesPropName() {
+        return "net.tcp.buffersize.wifi";
+    }
+
+    /**
+     * Record the detailed state of a network, and if it is a
+     * change from the previous state, send a notification to
+     * any listeners.
+     * @param state the new @{code DetailedState}
+     * @param reason a {@code String} indicating a reason for the state change,
+     * if one was supplied. May be {@code null}.
+     * @param extraInfo optional {@code String} providing extra information about the state change
+     */
+    private void setDetailedState(NetworkInfo.DetailedState state, String reason,
+            String extraInfo) {
+        mNetworkInfo.setDetailedState(state, reason, extraInfo);
+        Message msg = mTarget.obtainMessage(EVENT_STATE_CHANGED, mNetworkInfo);
+        msg.sendToTarget();
+    }
+}
diff --git a/core/java/android/net/SSLCertificateSocketFactory.java b/core/java/android/net/SSLCertificateSocketFactory.java
index 208b212..b0278d3 100644
--- a/core/java/android/net/SSLCertificateSocketFactory.java
+++ b/core/java/android/net/SSLCertificateSocketFactory.java
@@ -533,7 +533,7 @@
 
     @Override
     public String[] getDefaultCipherSuites() {
-        return getDelegate().getSupportedCipherSuites();
+        return getDelegate().getDefaultCipherSuites();
     }
 
     @Override
diff --git a/core/java/android/net/arp/ArpPeer.java b/core/java/android/net/arp/ArpPeer.java
deleted file mode 100644
index 2013b11..0000000
--- a/core/java/android/net/arp/ArpPeer.java
+++ /dev/null
@@ -1,174 +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.net.arp;
-
-import android.net.LinkAddress;
-import android.net.LinkProperties;
-import android.net.RouteInfo;
-import android.os.SystemClock;
-import android.util.Log;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Inet6Address;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Arrays;
-
-import libcore.net.RawSocket;
-
-/**
- * This class allows simple ARP exchanges over an uninitialized network
- * interface.
- *
- * @hide
- */
-public class ArpPeer {
-    private static final boolean DBG = false;
-    private static final String TAG = "ArpPeer";
-    private String mInterfaceName;
-    private final InetAddress mMyAddr;
-    private final byte[] mMyMac = new byte[6];
-    private final InetAddress mPeer;
-    private final RawSocket mSocket;
-    private final byte[] L2_BROADCAST;  // TODO: refactor from DhcpClient.java
-    private static final int MAX_LENGTH = 1500; // refactor from DhcpPacket.java
-    private static final int ETHERNET_TYPE = 1;
-    private static final int ARP_LENGTH = 28;
-    private static final int MAC_ADDR_LENGTH = 6;
-    private static final int IPV4_LENGTH = 4;
-
-    public ArpPeer(String interfaceName, InetAddress myAddr, String mac,
-                   InetAddress peer) throws SocketException {
-        mInterfaceName = interfaceName;
-        mMyAddr = myAddr;
-
-        if (mac != null) {
-            for (int i = 0; i < MAC_ADDR_LENGTH; i++) {
-                mMyMac[i] = (byte) Integer.parseInt(mac.substring(
-                            i*3, (i*3) + 2), 16);
-            }
-        }
-
-        if (myAddr instanceof Inet6Address || peer instanceof Inet6Address) {
-            throw new IllegalArgumentException("IPv6 unsupported");
-        }
-
-        mPeer = peer;
-        L2_BROADCAST = new byte[MAC_ADDR_LENGTH];
-        Arrays.fill(L2_BROADCAST, (byte) 0xFF);
-
-        mSocket = new RawSocket(mInterfaceName, RawSocket.ETH_P_ARP);
-    }
-
-    /**
-     * Returns the MAC address (or null if timeout) for the requested
-     * peer.
-     */
-    public byte[] doArp(int timeoutMillis) {
-        ByteBuffer buf = ByteBuffer.allocate(MAX_LENGTH);
-        byte[] desiredIp = mPeer.getAddress();
-        long timeout = SystemClock.elapsedRealtime() + timeoutMillis;
-
-        // construct ARP request packet, using a ByteBuffer as a
-        // convenient container
-        buf.clear();
-        buf.order(ByteOrder.BIG_ENDIAN);
-
-        buf.putShort((short) ETHERNET_TYPE); // Ethernet type, 16 bits
-        buf.putShort(RawSocket.ETH_P_IP); // Protocol type IP, 16 bits
-        buf.put((byte)MAC_ADDR_LENGTH);  // MAC address length, 6 bytes
-        buf.put((byte)IPV4_LENGTH);  // IPv4 protocol size
-        buf.putShort((short) 1); // ARP opcode 1: 'request'
-        buf.put(mMyMac);        // six bytes: sender MAC
-        buf.put(mMyAddr.getAddress());  // four bytes: sender IP address
-        buf.put(new byte[MAC_ADDR_LENGTH]); // target MAC address: unknown
-        buf.put(desiredIp); // target IP address, 4 bytes
-        buf.flip();
-        mSocket.write(L2_BROADCAST, buf.array(), 0, buf.limit());
-
-        byte[] recvBuf = new byte[MAX_LENGTH];
-
-        while (SystemClock.elapsedRealtime() < timeout) {
-            long duration = (long) timeout - SystemClock.elapsedRealtime();
-            int readLen = mSocket.read(recvBuf, 0, recvBuf.length, -1,
-                (int) duration);
-
-            // Verify packet details. see RFC 826
-            if ((readLen >= ARP_LENGTH) // trailing bytes at times
-                && (recvBuf[0] == 0) && (recvBuf[1] == ETHERNET_TYPE) // type Ethernet
-                && (recvBuf[2] == 8) && (recvBuf[3] == 0) // protocol IP
-                && (recvBuf[4] == MAC_ADDR_LENGTH) // mac length
-                && (recvBuf[5] == IPV4_LENGTH) // IPv4 protocol size
-                && (recvBuf[6] == 0) && (recvBuf[7] == 2) // ARP reply
-                // verify desired IP address
-                && (recvBuf[14] == desiredIp[0]) && (recvBuf[15] == desiredIp[1])
-                && (recvBuf[16] == desiredIp[2]) && (recvBuf[17] == desiredIp[3]))
-            {
-                // looks good.  copy out the MAC
-                byte[] result = new byte[MAC_ADDR_LENGTH];
-                System.arraycopy(recvBuf, 8, result, 0, MAC_ADDR_LENGTH);
-                return result;
-            }
-        }
-
-        return null;
-    }
-
-    public static boolean doArp(String myMacAddress, LinkProperties linkProperties,
-            int timeoutMillis, int numArpPings, int minArpResponses) {
-        String interfaceName = linkProperties.getInterfaceName();
-        InetAddress inetAddress = null;
-        InetAddress gateway = null;
-        boolean success;
-
-        for (LinkAddress la : linkProperties.getLinkAddresses()) {
-            inetAddress = la.getAddress();
-            break;
-        }
-
-        for (RouteInfo route : linkProperties.getRoutes()) {
-            gateway = route.getGateway();
-            break;
-        }
-
-        try {
-            ArpPeer peer = new ArpPeer(interfaceName, inetAddress, myMacAddress, gateway);
-            int responses = 0;
-            for (int i=0; i < numArpPings; i++) {
-                if(peer.doArp(timeoutMillis) != null) responses++;
-            }
-            if (DBG) Log.d(TAG, "ARP test result: " + responses + "/" + numArpPings);
-            success = (responses >= minArpResponses);
-            peer.close();
-        } catch (SocketException se) {
-            //Consider an Arp socket creation issue as a successful Arp
-            //test to avoid any wifi connectivity issues
-            Log.e(TAG, "ARP test initiation failure: " + se);
-            success = true;
-        }
-        return success;
-    }
-
-    public void close() {
-        try {
-            mSocket.close();
-        } catch (IOException ex) {
-        }
-    }
-}
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 9ada6e6..b1a9ea30 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -460,7 +460,7 @@
         public byte batteryHealth;
         public byte batteryPlugType;
         
-        public char batteryTemperature;
+        public short batteryTemperature;
         public char batteryVoltage;
         
         // Constants from SCREEN_BRIGHTNESS_*
@@ -537,7 +537,7 @@
             batteryHealth = (byte)((bat>>20)&0xf);
             batteryPlugType = (byte)((bat>>24)&0xf);
             bat = src.readInt();
-            batteryTemperature = (char)(bat&0xffff);
+            batteryTemperature = (short)(bat&0xffff);
             batteryVoltage = (char)((bat>>16)&0xffff);
             states = src.readInt();
         }
@@ -606,7 +606,7 @@
                 if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x"
                         + Integer.toHexString(batteryLevelInt)
                         + " batteryLevel=" + batteryLevel
-                        + " batteryTemp=" + (int)batteryTemperature
+                        + " batteryTemp=" + batteryTemperature
                         + " batteryVolt=" + (int)batteryVoltage);
             }
             if (stateIntChanged) {
@@ -621,8 +621,8 @@
         }
         
         private int buildBatteryLevelInt() {
-            return ((((int)batteryLevel)<<24)&0xff000000)
-                    | ((((int)batteryTemperature)<<14)&0x00ffc000)
+            return ((((int)batteryLevel)<<25)&0xfe000000)
+                    | ((((int)batteryTemperature)<<14)&0x01ffc000)
                     | (((int)batteryVoltage)&0x00003fff);
         }
         
@@ -658,13 +658,13 @@
             
             if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) {
                 int batteryLevelInt = src.readInt();
-                batteryLevel = (byte)((batteryLevelInt>>24)&0xff);
-                batteryTemperature = (char)((batteryLevelInt>>14)&0x3ff);
+                batteryLevel = (byte)((batteryLevelInt>>25)&0x7f);
+                batteryTemperature = (short)((batteryLevelInt<<7)>>21);
                 batteryVoltage = (char)(batteryLevelInt&0x3fff);
                 if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x"
                         + Integer.toHexString(batteryLevelInt)
                         + " batteryLevel=" + batteryLevel
-                        + " batteryTemp=" + (int)batteryTemperature
+                        + " batteryTemp=" + batteryTemperature
                         + " batteryVolt=" + (int)batteryVoltage);
             }
             
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index f4a8391..ba71605 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -56,7 +56,7 @@
     private static String sDumpDisabled = null;
 
     /* mObject is used by native code, do not remove or rename */
-    private int mObject;
+    private long mObject;
     private IInterface mOwner;
     private String mDescriptor;
     
@@ -390,7 +390,7 @@
     private native final void destroy();
 
     // Entry point from android_util_Binder.cpp's onTransact
-    private boolean execTransact(int code, int dataObj, int replyObj,
+    private boolean execTransact(int code, long dataObj, long replyObj,
             int flags) {
         Parcel data = Parcel.obtain(dataObj);
         Parcel reply = Parcel.obtain(replyObj);
@@ -499,6 +499,6 @@
     }
     
     final private WeakReference mSelf;
-    private int mObject;
-    private int mOrgue;
+    private long mObject;
+    private long mOrgue;
 }
diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java
index f9c1d31..af57507 100644
--- a/core/java/android/os/Bundle.java
+++ b/core/java/android/os/Bundle.java
@@ -380,7 +380,7 @@
                         SparseArray<? extends Parcelable> array =
                                 (SparseArray<? extends Parcelable>) obj;
                         for (int n = array.size() - 1; n >= 0; n--) {
-                            if ((array.get(n).describeContents()
+                            if ((array.valueAt(n).describeContents()
                                     & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
                                 fdFound = true;
                                 break;
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 974bf8d..2de1204 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -578,7 +578,7 @@
      * tracing.
      */
     public static void startMethodTracing() {
-        VMDebug.startMethodTracing(DEFAULT_TRACE_FILE_PATH, 0, 0);
+        VMDebug.startMethodTracing(DEFAULT_TRACE_FILE_PATH, 0, 0, false, 0);
     }
 
     /**
@@ -589,7 +589,7 @@
      * information about reading trace files.
      *
      * @param traceName Name for the trace log file to create.
-     * If no name argument is given, this value defaults to "/sdcard/dmtrace.trace".
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
      * If the files already exist, they will be truncated.
      * If the trace file given does not end in ".trace", it will be appended for you.
      */
@@ -604,7 +604,7 @@
        href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for
      * information about reading trace files.
      * @param traceName    Name for the trace log file to create.
-     * If no name argument is given, this value defaults to "/sdcard/dmtrace.trace".
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
      * If the files already exist, they will be truncated.
      * If the trace file given does not end in ".trace", it will be appended for you.
      *
@@ -627,26 +627,54 @@
      * in relative terms (e.g. was run #1 faster than run #2).  The times
      * for native methods will not change, so don't try to use this to
      * compare the performance of interpreted and native implementations of the
-     * same method.  As an alternative, consider using "native" tracing
-     * in the emulator via {@link #startNativeTracing()}.
+     * same method.  As an alternative, consider using sampling-based method
+     * tracing via {@link #startMethodTracingSampling(String, int, int)} or
+     * "native" tracing in the emulator via {@link #startNativeTracing()}.
      * </p>
      *
      * @param traceName    Name for the trace log file to create.
-     * If no name argument is given, this value defaults to "/sdcard/dmtrace.trace".
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
      * If the files already exist, they will be truncated.
      * If the trace file given does not end in ".trace", it will be appended for you.
      * @param bufferSize    The maximum amount of trace data we gather. If not given, it defaults to 8MB.
+     * @param flags    Flags to control method tracing. The only one that is currently defined is {@link #TRACE_COUNT_ALLOCS}.
      */
     public static void startMethodTracing(String traceName, int bufferSize,
         int flags) {
+        VMDebug.startMethodTracing(fixTraceName(traceName), bufferSize, flags, false, 0);
+    }
 
-        String pathName = traceName;
-        if (pathName.charAt(0) != '/')
-            pathName = DEFAULT_TRACE_PATH_PREFIX + pathName;
-        if (!pathName.endsWith(DEFAULT_TRACE_EXTENSION))
-            pathName = pathName + DEFAULT_TRACE_EXTENSION;
+    /**
+     * Start sampling-based method tracing, specifying the trace log file name,
+     * the buffer size, and the sampling interval. The trace files will be put
+     * under "/sdcard" unless an absolute path is given. See <a
+       href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a>
+     * for information about reading trace files.
+     *
+     * @param traceName    Name for the trace log file to create.
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
+     * If the files already exist, they will be truncated.
+     * If the trace file given does not end in ".trace", it will be appended for you.
+     * @param bufferSize    The maximum amount of trace data we gather. If not given, it defaults to 8MB.
+     * @param intervalUs    The amount of time between each sample in microseconds.
+     */
+    public static void startMethodTracingSampling(String traceName,
+        int bufferSize, int intervalUs) {
+        VMDebug.startMethodTracing(fixTraceName(traceName), bufferSize, 0, true, intervalUs);
+    }
 
-        VMDebug.startMethodTracing(pathName, bufferSize, flags);
+    /**
+     * Formats name of trace log file for method tracing.
+     */
+    private static String fixTraceName(String traceName) {
+        if (traceName == null)
+            traceName = DEFAULT_TRACE_FILE_PATH;
+        if (traceName.charAt(0) != '/')
+            traceName = DEFAULT_TRACE_PATH_PREFIX + traceName;
+        if (!traceName.endsWith(DEFAULT_TRACE_EXTENSION))
+            traceName = traceName + DEFAULT_TRACE_EXTENSION;
+
+        return traceName;
     }
 
     /**
@@ -660,7 +688,7 @@
      */
     public static void startMethodTracing(String traceName, FileDescriptor fd,
         int bufferSize, int flags) {
-        VMDebug.startMethodTracing(traceName, fd, bufferSize, flags);
+        VMDebug.startMethodTracing(traceName, fd, bufferSize, flags, false, 0);
     }
 
     /**
diff --git a/core/java/android/os/FactoryTest.java b/core/java/android/os/FactoryTest.java
index ec99697..7a252f9 100644
--- a/core/java/android/os/FactoryTest.java
+++ b/core/java/android/os/FactoryTest.java
@@ -25,6 +25,20 @@
  * {@hide}
  */
 public final class FactoryTest {
+    public static final int FACTORY_TEST_OFF = 0;
+    public static final int FACTORY_TEST_LOW_LEVEL = 1;
+    public static final int FACTORY_TEST_HIGH_LEVEL = 2;
+
+    /**
+     * Gets the current factory test mode.
+     *
+     * @return One of: {@link #FACTORY_TEST_OFF}, {@link #FACTORY_TEST_LOW_LEVEL},
+     * or {@link #FACTORY_TEST_HIGH_LEVEL}.
+     */
+    public static int getMode() {
+        return SystemProperties.getInt("ro.factorytest", FACTORY_TEST_OFF);
+    }
+
     /**
      * When true, long-press on power should immediately cause the device to
      * shut down, without prompting the user.
diff --git a/core/java/android/os/MemoryFile.java b/core/java/android/os/MemoryFile.java
index e8148f7..ee7a4c6 100644
--- a/core/java/android/os/MemoryFile.java
+++ b/core/java/android/os/MemoryFile.java
@@ -43,19 +43,19 @@
 
     private static native FileDescriptor native_open(String name, int length) throws IOException;
     // returns memory address for ashmem region
-    private static native int native_mmap(FileDescriptor fd, int length, int mode)
+    private static native long native_mmap(FileDescriptor fd, int length, int mode)
             throws IOException;
-    private static native void native_munmap(int addr, int length) throws IOException;
+    private static native void native_munmap(long addr, int length) throws IOException;
     private static native void native_close(FileDescriptor fd);
-    private static native int native_read(FileDescriptor fd, int address, byte[] buffer,
+    private static native int native_read(FileDescriptor fd, long address, byte[] buffer,
             int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
-    private static native void native_write(FileDescriptor fd, int address, byte[] buffer,
+    private static native void native_write(FileDescriptor fd, long address, byte[] buffer,
             int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
     private static native void native_pin(FileDescriptor fd, boolean pin) throws IOException;
     private static native int native_get_size(FileDescriptor fd) throws IOException;
 
     private FileDescriptor mFD;        // ashmem file descriptor
-    private int mAddress;   // address of ashmem memory
+    private long mAddress;   // address of ashmem memory
     private int mLength;    // total length of our ashmem region
     private boolean mAllowPurging = false;  // true if our ashmem region is unpinned
 
diff --git a/core/java/android/os/MessageQueue.java b/core/java/android/os/MessageQueue.java
index 799de5c..75f9813 100644
--- a/core/java/android/os/MessageQueue.java
+++ b/core/java/android/os/MessageQueue.java
@@ -35,7 +35,7 @@
     private final boolean mQuitAllowed;
 
     @SuppressWarnings("unused")
-    private int mPtr; // used by native code
+    private long mPtr; // used by native code
 
     Message mMessages;
     private final ArrayList<IdleHandler> mIdleHandlers = new ArrayList<IdleHandler>();
@@ -49,11 +49,11 @@
     // Barriers are indicated by messages with a null target whose arg1 field carries the token.
     private int mNextBarrierToken;
 
-    private native static int nativeInit();
-    private native static void nativeDestroy(int ptr);
-    private native static void nativePollOnce(int ptr, int timeoutMillis);
-    private native static void nativeWake(int ptr);
-    private native static boolean nativeIsIdling(int ptr);
+    private native static long nativeInit();
+    private native static void nativeDestroy(long ptr);
+    private native static void nativePollOnce(long ptr, int timeoutMillis);
+    private native static void nativeWake(long ptr);
+    private native static boolean nativeIsIdling(long ptr);
 
     /**
      * Callback interface for discovering when a thread is going to block
diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java
index 94b9617..6716098 100644
--- a/core/java/android/os/Parcel.java
+++ b/core/java/android/os/Parcel.java
@@ -182,7 +182,7 @@
     private static final String TAG = "Parcel";
 
     @SuppressWarnings({"UnusedDeclaration"})
-    private int mNativePtr; // used by native code
+    private long mNativePtr; // used by native code
 
     /**
      * Flag indicating if {@link #mNativePtr} was allocated by this object,
@@ -232,47 +232,47 @@
     private static final int EX_NETWORK_MAIN_THREAD = -6;
     private static final int EX_HAS_REPLY_HEADER = -128;  // special; see below
 
-    private static native int nativeDataSize(int nativePtr);
-    private static native int nativeDataAvail(int nativePtr);
-    private static native int nativeDataPosition(int nativePtr);
-    private static native int nativeDataCapacity(int nativePtr);
-    private static native void nativeSetDataSize(int nativePtr, int size);
-    private static native void nativeSetDataPosition(int nativePtr, int pos);
-    private static native void nativeSetDataCapacity(int nativePtr, int size);
+    private static native int nativeDataSize(long nativePtr);
+    private static native int nativeDataAvail(long nativePtr);
+    private static native int nativeDataPosition(long nativePtr);
+    private static native int nativeDataCapacity(long nativePtr);
+    private static native void nativeSetDataSize(long nativePtr, int size);
+    private static native void nativeSetDataPosition(long nativePtr, int pos);
+    private static native void nativeSetDataCapacity(long nativePtr, int size);
 
-    private static native boolean nativePushAllowFds(int nativePtr, boolean allowFds);
-    private static native void nativeRestoreAllowFds(int nativePtr, boolean lastValue);
+    private static native boolean nativePushAllowFds(long nativePtr, boolean allowFds);
+    private static native void nativeRestoreAllowFds(long nativePtr, boolean lastValue);
 
-    private static native void nativeWriteByteArray(int nativePtr, byte[] b, int offset, int len);
-    private static native void nativeWriteInt(int nativePtr, int val);
-    private static native void nativeWriteLong(int nativePtr, long val);
-    private static native void nativeWriteFloat(int nativePtr, float val);
-    private static native void nativeWriteDouble(int nativePtr, double val);
-    private static native void nativeWriteString(int nativePtr, String val);
-    private static native void nativeWriteStrongBinder(int nativePtr, IBinder val);
-    private static native void nativeWriteFileDescriptor(int nativePtr, FileDescriptor val);
+    private static native void nativeWriteByteArray(long nativePtr, byte[] b, int offset, int len);
+    private static native void nativeWriteInt(long nativePtr, int val);
+    private static native void nativeWriteLong(long nativePtr, long val);
+    private static native void nativeWriteFloat(long nativePtr, float val);
+    private static native void nativeWriteDouble(long nativePtr, double val);
+    private static native void nativeWriteString(long nativePtr, String val);
+    private static native void nativeWriteStrongBinder(long nativePtr, IBinder val);
+    private static native void nativeWriteFileDescriptor(long nativePtr, FileDescriptor val);
 
-    private static native byte[] nativeCreateByteArray(int nativePtr);
-    private static native int nativeReadInt(int nativePtr);
-    private static native long nativeReadLong(int nativePtr);
-    private static native float nativeReadFloat(int nativePtr);
-    private static native double nativeReadDouble(int nativePtr);
-    private static native String nativeReadString(int nativePtr);
-    private static native IBinder nativeReadStrongBinder(int nativePtr);
-    private static native FileDescriptor nativeReadFileDescriptor(int nativePtr);
+    private static native byte[] nativeCreateByteArray(long nativePtr);
+    private static native int nativeReadInt(long nativePtr);
+    private static native long nativeReadLong(long nativePtr);
+    private static native float nativeReadFloat(long nativePtr);
+    private static native double nativeReadDouble(long nativePtr);
+    private static native String nativeReadString(long nativePtr);
+    private static native IBinder nativeReadStrongBinder(long nativePtr);
+    private static native FileDescriptor nativeReadFileDescriptor(long nativePtr);
 
-    private static native int nativeCreate();
-    private static native void nativeFreeBuffer(int nativePtr);
-    private static native void nativeDestroy(int nativePtr);
+    private static native long nativeCreate();
+    private static native void nativeFreeBuffer(long nativePtr);
+    private static native void nativeDestroy(long nativePtr);
 
-    private static native byte[] nativeMarshall(int nativePtr);
+    private static native byte[] nativeMarshall(long nativePtr);
     private static native void nativeUnmarshall(
-            int nativePtr, byte[] data, int offest, int length);
+            long nativePtr, byte[] data, int offest, int length);
     private static native void nativeAppendFrom(
-            int thisNativePtr, int otherNativePtr, int offset, int length);
-    private static native boolean nativeHasFileDescriptors(int nativePtr);
-    private static native void nativeWriteInterfaceToken(int nativePtr, String interfaceName);
-    private static native void nativeEnforceInterface(int nativePtr, String interfaceName);
+            long thisNativePtr, long otherNativePtr, int offset, int length);
+    private static native boolean nativeHasFileDescriptors(long nativePtr);
+    private static native void nativeWriteInterfaceToken(long nativePtr, String interfaceName);
+    private static native void nativeEnforceInterface(long nativePtr, String interfaceName);
 
     public final static Parcelable.Creator<String> STRING_CREATOR
              = new Parcelable.Creator<String>() {
@@ -2229,6 +2229,11 @@
         mCreators = new HashMap<ClassLoader,HashMap<String,Parcelable.Creator>>();
 
     static protected final Parcel obtain(int obj) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** @hide */
+    static protected final Parcel obtain(long obj) {
         final Parcel[] pool = sHolderPool;
         synchronized (pool) {
             Parcel p;
@@ -2247,7 +2252,7 @@
         return new Parcel(obj);
     }
 
-    private Parcel(int nativePtr) {
+    private Parcel(long nativePtr) {
         if (DEBUG_RECYCLE) {
             mStack = new RuntimeException();
         }
@@ -2255,7 +2260,7 @@
         init(nativePtr);
     }
 
-    private void init(int nativePtr) {
+    private void init(long nativePtr) {
         if (nativePtr != 0) {
             mNativePtr = nativePtr;
             mOwnsNativeParcelObject = false;
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 5e0d489..86ef479 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -191,6 +191,18 @@
     public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = 0x00000020;
 
     /**
+     * Wake lock level: Put the screen in a low power state and allow the CPU to suspend
+     * if no other wake locks are held.
+     * <p>
+     * This is used by the dream manager to implement doze mode.  It currently
+     * has no effect unless the power manager is in the dozing state.
+     * </p>
+     *
+     * {@hide}
+     */
+    public static final int DOZE_WAKE_LOCK = 0x00000040;
+
+    /**
      * Mask for the wake lock level component of a combined wake lock level and flags integer.
      *
      * @hide
@@ -418,6 +430,7 @@
             case SCREEN_BRIGHT_WAKE_LOCK:
             case FULL_WAKE_LOCK:
             case PROXIMITY_SCREEN_OFF_WAKE_LOCK:
+            case DOZE_WAKE_LOCK:
                 break;
             default:
                 throw new IllegalArgumentException("Must specify a valid wake lock level.");
diff --git a/core/java/android/os/PowerManagerInternal.java b/core/java/android/os/PowerManagerInternal.java
new file mode 100644
index 0000000..cb3d528
--- /dev/null
+++ b/core/java/android/os/PowerManagerInternal.java
@@ -0,0 +1,60 @@
+/*
+ * 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 android.os;
+
+import android.view.WindowManagerPolicy;
+
+/**
+ * Power manager local system service interface.
+ *
+ * @hide Only for use within the system server.
+ */
+public abstract class PowerManagerInternal {
+    /**
+     * Used by the window manager to override the screen brightness based on the
+     * current foreground activity.
+     *
+     * This method must only be called by the window manager.
+     *
+     * @param brightness The overridden brightness, or -1 to disable the override.
+     */
+    public abstract void setScreenBrightnessOverrideFromWindowManager(int brightness);
+
+    /**
+     * Used by the window manager to override the button brightness based on the
+     * current foreground activity.
+     *
+     * This method must only be called by the window manager.
+     *
+     * @param brightness The overridden brightness, or -1 to disable the override.
+     */
+    public abstract void setButtonBrightnessOverrideFromWindowManager(int brightness);
+
+    /**
+     * Used by the window manager to override the user activity timeout based on the
+     * current foreground activity.  It can only be used to make the timeout shorter
+     * than usual, not longer.
+     *
+     * This method must only be called by the window manager.
+     *
+     * @param timeoutMillis The overridden timeout, or -1 to disable the override.
+     */
+    public abstract void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis);
+
+    // TODO: Remove this and retrieve as a local service instead.
+    public abstract void setPolicy(WindowManagerPolicy policy);
+}
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index cf9ddb3..057f516 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -377,7 +377,7 @@
      * @param gids Additional group-ids associated with the process.
      * @param debugFlags Additional flags.
      * @param targetSdkVersion The target SDK version for the app.
-     * @param seInfo null-ok SE Android information for the new process.
+     * @param seInfo null-ok SELinux information for the new process.
      * @param zygoteArgs Additional arguments to supply to the zygote process.
      * 
      * @return An object that describes the result of the attempt to start the process.
@@ -557,7 +557,7 @@
      * new process should setgroup() to.
      * @param debugFlags Additional flags.
      * @param targetSdkVersion The target SDK version for the app.
-     * @param seInfo null-ok SE Android information for the new process.
+     * @param seInfo null-ok SELinux information for the new process.
      * @param extraArgs Additional arguments to supply to the zygote process.
      * @return An object that describes the result of the attempt to start the process.
      * @throws ZygoteStartFailedEx if process start failed for any reason
@@ -892,19 +892,6 @@
     }
 
     /**
-     * Set the out-of-memory badness adjustment for a process.
-     * 
-     * @param pid The process identifier to set.
-     * @param amt Adjustment value -- linux allows -16 to +15.
-     * 
-     * @return Returns true if the underlying system supports this
-     *         feature, else false.
-     *         
-     * {@hide}
-     */
-    public static final native boolean setOomAdj(int pid, int amt);
-
-    /**
      * Adjust the swappiness level for a process.
      *
      * @param pid The process identifier to set.
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index 5e20dec..b692ffde 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -32,10 +32,8 @@
 import java.security.PublicKey;
 import java.security.Signature;
 import java.security.SignatureException;
-import java.security.cert.Certificate;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
-import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -48,7 +46,7 @@
 import org.apache.harmony.security.pkcs7.ContentInfo;
 import org.apache.harmony.security.pkcs7.SignedData;
 import org.apache.harmony.security.pkcs7.SignerInfo;
-import org.apache.harmony.security.provider.cert.X509CertImpl;
+import org.apache.harmony.security.x509.Certificate;
 
 /**
  * RecoverySystem contains methods for interacting with the Android
@@ -93,9 +91,9 @@
     }
 
     /** @return the set of certs that can be used to sign an OTA package. */
-    private static HashSet<Certificate> getTrustedCerts(File keystore)
+    private static HashSet<X509Certificate> getTrustedCerts(File keystore)
         throws IOException, GeneralSecurityException {
-        HashSet<Certificate> trusted = new HashSet<Certificate>();
+        HashSet<X509Certificate> trusted = new HashSet<X509Certificate>();
         if (keystore == null) {
             keystore = DEFAULT_KEYSTORE;
         }
@@ -107,7 +105,7 @@
                 ZipEntry entry = entries.nextElement();
                 InputStream is = zip.getInputStream(entry);
                 try {
-                    trusted.add(cf.generateCertificate(is));
+                    trusted.add((X509Certificate) cf.generateCertificate(is));
                 } finally {
                     is.close();
                 }
@@ -201,21 +199,23 @@
             if (signedData == null) {
                 throw new IOException("signedData is null");
             }
-            Collection encCerts = signedData.getCertificates();
+            List<Certificate> encCerts = signedData.getCertificates();
             if (encCerts.isEmpty()) {
                 throw new IOException("encCerts is empty");
             }
             // Take the first certificate from the signature (packages
             // should contain only one).
-            Iterator it = encCerts.iterator();
+            Iterator<Certificate> it = encCerts.iterator();
             X509Certificate cert = null;
             if (it.hasNext()) {
-                cert = new X509CertImpl((org.apache.harmony.security.x509.Certificate)it.next());
+                CertificateFactory cf = CertificateFactory.getInstance("X.509");
+                InputStream is = new ByteArrayInputStream(it.next().getEncoded());
+                cert = (X509Certificate) cf.generateCertificate(is);
             } else {
                 throw new SignatureException("signature contains no certificates");
             }
 
-            List sigInfos = signedData.getSignerInfos();
+            List<SignerInfo> sigInfos = signedData.getSignerInfos();
             SignerInfo sigInfo;
             if (!sigInfos.isEmpty()) {
                 sigInfo = (SignerInfo)sigInfos.get(0);
@@ -226,12 +226,12 @@
             // Check that the public key of the certificate contained
             // in the package equals one of our trusted public keys.
 
-            HashSet<Certificate> trusted = getTrustedCerts(
+            HashSet<X509Certificate> trusted = getTrustedCerts(
                 deviceCertsZipFile == null ? DEFAULT_KEYSTORE : deviceCertsZipFile);
 
             PublicKey signatureKey = cert.getPublicKey();
             boolean verified = false;
-            for (Certificate c : trusted) {
+            for (X509Certificate c : trusted) {
                 if (c.getPublicKey().equals(signatureKey)) {
                     verified = true;
                     break;
diff --git a/core/java/android/os/SELinux.java b/core/java/android/os/SELinux.java
index c05a974..c9dd5d7 100644
--- a/core/java/android/os/SELinux.java
+++ b/core/java/android/os/SELinux.java
@@ -45,7 +45,7 @@
 
     /**
      * Set whether SELinux is permissive or enforcing.
-     * @param boolean representing whether to set SELinux to enforcing
+     * @param value representing whether to set SELinux to enforcing
      * @return a boolean representing whether the desired mode was set
      */
     public static final native boolean setSELinuxEnforce(boolean value);
@@ -60,7 +60,7 @@
     /**
      * Change the security context of an existing file object.
      * @param path representing the path of file object to relabel.
-     * @param con new security context given as a String.
+     * @param context new security context given as a String.
      * @return a boolean indicating whether the operation succeeded.
      */
     public static final native boolean setFileContext(String path, String context);
@@ -87,8 +87,6 @@
 
     /**
      * Gets the security context of a given process id.
-     * Use of this function is discouraged for Binder transactions.
-     * Use Binder.getCallingSecctx() instead.
      * @param pid an int representing the process id to check.
      * @return a String representing the security context of the given pid.
      */
@@ -102,15 +100,15 @@
 
     /**
      * Gets the value for the given SELinux boolean name.
-     * @param String The name of the SELinux boolean.
+     * @param name The name of the SELinux boolean.
      * @return a boolean indicating whether the SELinux boolean is set.
      */
     public static final native boolean getBooleanValue(String name);
 
     /**
      * Sets the value for the given SELinux boolean name.
-     * @param String The name of the SELinux boolean.
-     * @param Boolean The new value of the SELinux boolean.
+     * @param name The name of the SELinux boolean.
+     * @param value The new value of the SELinux boolean.
      * @return a boolean indicating whether or not the operation succeeded.
      */
     public static final native boolean setBooleanValue(String name, boolean value);
diff --git a/core/java/android/os/storage/StorageVolume.java b/core/java/android/os/storage/StorageVolume.java
index 0285cb9..06565f1 100644
--- a/core/java/android/os/storage/StorageVolume.java
+++ b/core/java/android/os/storage/StorageVolume.java
@@ -216,7 +216,7 @@
             return -1;
         }
         try {
-            return Integer.parseInt(mUuid.replace("-", ""), 16);
+            return (int)Long.parseLong(mUuid.replace("-", ""), 16);
         } catch (NumberFormatException e) {
             return -1;
         }
diff --git a/core/java/android/service/dreams/DozeHardware.java b/core/java/android/service/dreams/DozeHardware.java
new file mode 100644
index 0000000..b5e7f43
--- /dev/null
+++ b/core/java/android/service/dreams/DozeHardware.java
@@ -0,0 +1,77 @@
+/**
+ * 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 android.service.dreams;
+
+import android.os.RemoteException;
+import android.util.Log;
+
+/**
+ * Provides access to low-level hardware features that a dream may use to provide
+ * a richer user experience while dozing.
+ * <p>
+ * This class contains functions that should be called by the dream to configure
+ * hardware before starting to doze and allowing the application processor to suspend.
+ * For example, the dream may provide the hardware with enough information to render
+ * some content on its own without any further assistance from the application processor.
+ * </p><p>
+ * This object is obtained by calling {@link DreamService#getDozeHardware()}.
+ * </p>
+ *
+ * @hide experimental
+ */
+public final class DozeHardware {
+    private static final String TAG = "DozeHardware";
+
+    public static final String MSG_ENABLE_MCU = "enable_mcu";
+
+    public static final byte[] VALUE_ON = "on".getBytes();
+    public static final byte[] VALUE_OFF = "off".getBytes();
+
+    private final IDozeHardware mHardware;
+
+    DozeHardware(IDozeHardware hardware) {
+        mHardware = hardware;
+    }
+
+    /**
+     * Sets whether to enable the microcontroller.
+     *
+     * @param enable If true, enables the MCU otherwise disables it.
+     */
+    public void setEnableMcu(boolean enable) {
+        sendMessage(MSG_ENABLE_MCU, enable ? VALUE_ON : VALUE_OFF);
+    }
+
+    /**
+     * Sends a message to the doze hardware module.
+     *
+     * @param msg The name of the message to send.
+     * @param arg An optional argument data blob, may be null.
+     * @return A result data blob, may be null.
+     */
+    public byte[] sendMessage(String msg, byte[] arg) {
+        if (msg == null) {
+            throw new IllegalArgumentException("msg must not be null");
+        }
+
+        try {
+            return mHardware.sendMessage(msg, arg);
+        } catch (RemoteException ex) {
+            Log.e(TAG, "Failed to send message to doze hardware module.", ex);
+            return null;
+        }
+    }
+}
diff --git a/core/java/android/service/dreams/DreamManagerInternal.java b/core/java/android/service/dreams/DreamManagerInternal.java
new file mode 100644
index 0000000..9f7ddba
--- /dev/null
+++ b/core/java/android/service/dreams/DreamManagerInternal.java
@@ -0,0 +1,39 @@
+/*
+ * 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 android.service.dreams;
+
+/**
+ * Dream manager local system service interface.
+ *
+ * @hide Only for use within the system server.
+ */
+public abstract class DreamManagerInternal {
+    /**
+     * Called by the power manager to start a dream.
+     */
+    public abstract void startDream(boolean doze);
+
+    /**
+     * Called by the power manager to stop a dream.
+     */
+    public abstract void stopDream();
+
+    /**
+     * Called by the power manager to determine whether a dream is running.
+     */
+    public abstract boolean isDreaming();
+}
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java
index f6b6c89..7647c22 100644
--- a/core/java/android/service/dreams/DreamService.java
+++ b/core/java/android/service/dreams/DreamService.java
@@ -20,12 +20,14 @@
 
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
+import android.app.AlarmManager;
 import android.app.Service;
 import android.content.Intent;
 import android.graphics.PixelFormat;
 import android.graphics.drawable.ColorDrawable;
 import android.os.Handler;
 import android.os.IBinder;
+import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.util.Slog;
 import android.view.ActionMode;
@@ -42,6 +44,8 @@
 import android.view.accessibility.AccessibilityEvent;
 
 import com.android.internal.policy.PolicyManager;
+import com.android.internal.util.DumpUtils;
+import com.android.internal.util.DumpUtils.Dump;
 
 /**
  * Extend this class to implement a custom dream (available to the user as a "Daydream").
@@ -145,19 +149,26 @@
      */
     public static final String DREAM_META_DATA = "android.service.dream";
 
+    private final IDreamManager mSandman;
     private final Handler mHandler = new Handler();
     private IBinder mWindowToken;
     private Window mWindow;
     private WindowManager mWindowManager;
-    private IDreamManager mSandman;
     private boolean mInteractive = false;
     private boolean mLowProfile = true;
     private boolean mFullscreen = false;
     private boolean mScreenBright = true;
     private boolean mFinished;
+    private boolean mCanDoze;
+    private boolean mDozing;
+    private DozeHardware mDozeHardware;
 
     private boolean mDebug = false;
 
+    public DreamService() {
+        mSandman = IDreamManager.Stub.asInterface(ServiceManager.getService(DREAM_SERVICE));
+    }
+
     /**
      * @hide
      */
@@ -289,6 +300,10 @@
     public void onDetachedFromWindow() {
     }
 
+    @Override
+    public void onWindowDismissed() {
+    }
+
     /** {@inheritDoc} */
     @Override
     public void onPanelClosed(int featureId, Menu menu) {
@@ -444,9 +459,11 @@
      * correct interactions with it (seeing when it is cleared etc).
      */
     public void setLowProfile(boolean lowProfile) {
-        mLowProfile = lowProfile;
-        int flag = View.SYSTEM_UI_FLAG_LOW_PROFILE;
-        applySystemUiVisibilityFlags(mLowProfile ? flag : 0, flag);
+        if (mLowProfile != lowProfile) {
+            mLowProfile = lowProfile;
+            int flag = View.SYSTEM_UI_FLAG_LOW_PROFILE;
+            applySystemUiVisibilityFlags(mLowProfile ? flag : 0, flag);
+        }
     }
 
     /**
@@ -467,9 +484,11 @@
      * will be cleared.
      */
     public void setFullscreen(boolean fullscreen) {
-        mFullscreen = fullscreen;
-        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
-        applyWindowFlags(mFullscreen ? flag : 0, flag);
+        if (mFullscreen != fullscreen) {
+            mFullscreen = fullscreen;
+            int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
+            applyWindowFlags(mFullscreen ? flag : 0, flag);
+        }
     }
 
     /**
@@ -487,14 +506,16 @@
      * @param screenBright True to keep the screen bright while dreaming.
      */
     public void setScreenBright(boolean screenBright) {
-        mScreenBright = screenBright;
-        int flag = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
-        applyWindowFlags(mScreenBright ? flag : 0, flag);
+        if (mScreenBright != screenBright) {
+            mScreenBright = screenBright;
+            int flag = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
+            applyWindowFlags(mScreenBright ? flag : 0, flag);
+        }
     }
 
     /**
-     * Returns whether or not this dream keeps the screen bright while dreaming. Defaults to false,
-     * allowing the screen to dim if necessary.
+     * Returns whether or not this dream keeps the screen bright while dreaming.
+     * Defaults to false, allowing the screen to dim if necessary.
      *
      * @see #setScreenBright(boolean)
      */
@@ -503,6 +524,119 @@
     }
 
     /**
+     * Returns true if this dream is allowed to doze.
+     * <p>
+     * The value returned by this method is only meaningful when the dream has started.
+     * </p>
+     *
+     * @return True if this dream can doze.
+     * @see #startDozing
+     * @hide experimental
+     */
+    public boolean canDoze() {
+        return mCanDoze;
+    }
+
+    /**
+     * Starts dozing, entering a deep dreamy sleep.
+     * <p>
+     * Dozing enables the system to conserve power while the user is not actively interacting
+     * with the device.  While dozing, the display will remain on in a low-power state
+     * and will continue to show its previous contents but the application processor and
+     * other system components will be allowed to suspend when possible.
+     * </p><p>
+     * While the application processor is suspended, the dream may stop executing code
+     * for long periods of time.  Prior to being suspended, the dream may schedule periodic
+     * wake-ups to render new content by scheduling an alarm with the {@link AlarmManager}.
+     * The dream may also keep the CPU awake by acquiring a
+     * {@link android.os.PowerManager#PARTIAL_WAKE_LOCK partial wake lock} when necessary.
+     * Note that since the purpose of doze mode is to conserve power (especially when
+     * running on battery), the dream should not wake the CPU very often or keep it
+     * awake for very long.
+     * </p><p>
+     * It is a good idea to call this method some time after the dream's entry animation
+     * has completed and the dream is ready to doze.  It is important to completely
+     * finish all of the work needed before dozing since the application processor may
+     * be suspended at any moment once this method is called unless other wake locks
+     * are being held.
+     * </p><p>
+     * Call {@link #stopDozing} or {@link #finish} to stop dozing.
+     * </p>
+     *
+     * @see #stopDozing
+     * @hide experimental
+     */
+    public void startDozing() {
+        if (mCanDoze && !mDozing) {
+            mDozing = true;
+            try {
+                mSandman.startDozing(mWindowToken);
+            } catch (RemoteException ex) {
+                // system server died
+            }
+        }
+    }
+
+    /**
+     * Stops dozing, returns to active dreaming.
+     * <p>
+     * This method reverses the effect of {@link #startDozing}.  From this moment onward,
+     * the application processor will be kept awake as long as the dream is running
+     * or until the dream starts dozing again.
+     * </p>
+     *
+     * @see #startDozing
+     * @hide experimental
+     */
+    public void stopDozing() {
+        if (mDozing) {
+            mDozing = false;
+            try {
+                mSandman.stopDozing(mWindowToken);
+            } catch (RemoteException ex) {
+                // system server died
+            }
+        }
+    }
+
+    /**
+     * Returns true if the dream will allow the system to enter a low-power state while
+     * it is running without actually turning off the screen.  Defaults to false,
+     * keeping the application processor awake while the dream is running.
+     *
+     * @return True if the dream is dozing.
+     *
+     * @see #setDozing(boolean)
+     * @hide experimental
+     */
+    public boolean isDozing() {
+        return mDozing;
+    }
+
+    /**
+     * Gets an object that may be used to access low-level hardware features that a
+     * dream may use to provide a richer user experience while dozing.
+     *
+     * @return An instance of {@link DozeHardware} or null if this device does not offer
+     * hardware support for dozing.
+     *
+     * @hide experimental
+     */
+    public DozeHardware getDozeHardware() {
+        if (mCanDoze && mDozeHardware == null) {
+            try {
+                IDozeHardware hardware = mSandman.getDozeHardware(mWindowToken);
+                if (hardware != null) {
+                    mDozeHardware = new DozeHardware(hardware);
+                }
+            } catch (RemoteException ex) {
+                // system server died
+            }
+        }
+        return mDozeHardware;
+    }
+
+    /**
      * Called when this Dream is constructed.
      */
     @Override
@@ -536,7 +670,11 @@
     }
 
     /**
-     * Stops the dream, detaches from the window, and wakes up.
+     * Stops the dream and detaches from the window.
+     * <p>
+     * When the dream ends, the system will be allowed to go to sleep fully unless there
+     * is a reason for it to be awake such as recent user activity or wake locks being held.
+     * </p>
      */
     public final void finish() {
         if (mDebug) Slog.v(TAG, "finish()");
@@ -557,10 +695,6 @@
 
     // end public api
 
-    private void loadSandman() {
-        mSandman = IDreamManager.Stub.asInterface(ServiceManager.getService(DREAM_SERVICE));
-    }
-
     /**
      * Called by DreamController.stopDream() when the Dream is about to be unbound and destroyed.
      *
@@ -572,23 +706,16 @@
             return;
         }
 
-        try {
-            onDreamingStopped();
-        } catch (Throwable t) {
-            Slog.w(TAG, "Crashed in onDreamingStopped()", t);
-            // we were going to stop anyway
-        }
+        if (mDebug) Slog.v(TAG, "detach(): Calling onDreamingStopped()");
+        onDreamingStopped();
 
         if (mDebug) Slog.v(TAG, "detach(): Removing window from window manager");
-        try {
-            // force our window to be removed synchronously
-            mWindowManager.removeViewImmediate(mWindow.getDecorView());
-            // the following will print a log message if it finds any other leaked windows
-            WindowManagerGlobal.getInstance().closeAll(mWindowToken,
-                    this.getClass().getName(), "Dream");
-        } catch (Throwable t) {
-            Slog.w(TAG, "Crashed removing window view", t);
-        }
+
+        // force our window to be removed synchronously
+        mWindowManager.removeViewImmediate(mWindow.getDecorView());
+        // the following will print a log message if it finds any other leaked windows
+        WindowManagerGlobal.getInstance().closeAll(mWindowToken,
+                this.getClass().getName(), "Dream");
 
         mWindow = null;
         mWindowToken = null;
@@ -601,23 +728,30 @@
      *
      * @param windowToken A window token that will allow a window to be created in the correct layer.
      */
-    private final void attach(IBinder windowToken) {
+    private final void attach(IBinder windowToken, boolean canDoze) {
         if (mWindowToken != null) {
             Slog.e(TAG, "attach() called when already attached with token=" + mWindowToken);
             return;
         }
+        if (mFinished) {
+            Slog.w(TAG, "attach() called after dream already finished");
+            try {
+                mSandman.finishSelf(windowToken);
+            } catch (RemoteException ex) {
+                // system server died
+            }
+            return;
+        }
 
         if (mDebug) Slog.v(TAG, "Attached on thread " + Thread.currentThread().getId());
 
-        if (mSandman == null) {
-            loadSandman();
-        }
         mWindowToken = windowToken;
         mWindow = PolicyManager.makeNewWindow(this);
         mWindow.setCallback(this);
         mWindow.requestFeature(Window.FEATURE_NO_TITLE);
         mWindow.setBackgroundDrawable(new ColorDrawable(0xFF000000));
         mWindow.setFormat(PixelFormat.OPAQUE);
+        mCanDoze = canDoze;
 
         if (mDebug) Slog.v(TAG, String.format("Attaching window token: %s to window of type %s",
                 windowToken, WindowManager.LayoutParams.TYPE_DREAM));
@@ -642,40 +776,25 @@
         mWindowManager = mWindow.getWindowManager();
 
         if (mDebug) Slog.v(TAG, "Window added on thread " + Thread.currentThread().getId());
-        try {
-            applySystemUiVisibilityFlags(
-                    (mLowProfile ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0),
-                    View.SYSTEM_UI_FLAG_LOW_PROFILE);
-            getWindowManager().addView(mWindow.getDecorView(), mWindow.getAttributes());
-        } catch (Throwable t) {
-            Slog.w(TAG, "Crashed adding window view", t);
-            safelyFinish();
-            return;
-        }
+        applySystemUiVisibilityFlags(
+                (mLowProfile ? View.SYSTEM_UI_FLAG_LOW_PROFILE : 0),
+                View.SYSTEM_UI_FLAG_LOW_PROFILE);
+        getWindowManager().addView(mWindow.getDecorView(), mWindow.getAttributes());
 
         // start it up
         mHandler.post(new Runnable() {
             @Override
             public void run() {
-                try {
-                    onDreamingStarted();
-                } catch (Throwable t) {
-                    Slog.w(TAG, "Crashed in onDreamingStarted()", t);
-                    safelyFinish();
-                }
+                if (mDebug) Slog.v(TAG, "Calling onDreamingStarted()");
+                onDreamingStarted();
             }
         });
     }
 
     private void safelyFinish() {
         if (mDebug) Slog.v(TAG, "safelyFinish()");
-        try {
-            finish();
-        } catch (Throwable t) {
-            Slog.w(TAG, "Crashed in safelyFinish()", t);
-            finishInternal();
-            return;
-        }
+
+        finish();
 
         if (!mFinished) {
             Slog.w(TAG, "Bad dream, did not call super.finish()");
@@ -685,19 +804,21 @@
 
     private void finishInternal() {
         if (mDebug) Slog.v(TAG, "finishInternal() mFinished = " + mFinished);
-        if (mFinished) return;
-        try {
+
+        if (!mFinished) {
             mFinished = true;
 
-            if (mSandman != null) {
-                mSandman.finishSelf(mWindowToken);
+            if (mWindowToken == null) {
+                Slog.w(TAG, "Finish was called before the dream was attached.");
             } else {
-                Slog.w(TAG, "No dream manager found");
+                try {
+                    mSandman.finishSelf(mWindowToken);
+                } catch (RemoteException ex) {
+                    // system server died
+                }
             }
-            stopSelf(); // if launched via any other means
 
-        } catch (Throwable t) {
-            Slog.w(TAG, "Crashed in finishInternal()", t);
+            stopSelf(); // if launched via any other means
         }
     }
 
@@ -732,32 +853,39 @@
 
     @Override
     protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        super.dump(fd, pw, args);
-
-        pw.print(TAG + ": ");
-        if (mWindowToken == null) {
-            pw.println("stopped");
-        } else {
-            pw.println("running (token=" + mWindowToken + ")");
-        }
-        pw.println("  window: " + mWindow);
-        pw.print("  flags:");
-        if (isInteractive()) pw.print(" interactive");
-        if (isLowProfile()) pw.print(" lowprofile");
-        if (isFullscreen()) pw.print(" fullscreen");
-        if (isScreenBright()) pw.print(" bright");
-        pw.println();
+        DumpUtils.dumpAsync(mHandler, new Dump() {
+            @Override
+            public void dump(PrintWriter pw) {
+                pw.print(TAG + ": ");
+                if (mWindowToken == null) {
+                    pw.println("stopped");
+                } else {
+                    pw.println("running (token=" + mWindowToken + ")");
+                }
+                pw.println("  window: " + mWindow);
+                pw.print("  flags:");
+                if (isInteractive()) pw.print(" interactive");
+                if (isLowProfile()) pw.print(" lowprofile");
+                if (isFullscreen()) pw.print(" fullscreen");
+                if (isScreenBright()) pw.print(" bright");
+                if (isDozing()) pw.print(" dozing");
+                pw.println();
+            }
+        }, pw, 1000);
     }
 
-    private class DreamServiceWrapper extends IDreamService.Stub {
-        public void attach(final IBinder windowToken) {
+    private final class DreamServiceWrapper extends IDreamService.Stub {
+        @Override
+        public void attach(final IBinder windowToken, final boolean canDoze) {
             mHandler.post(new Runnable() {
                 @Override
                 public void run() {
-                    DreamService.this.attach(windowToken);
+                    DreamService.this.attach(windowToken, canDoze);
                 }
             });
         }
+
+        @Override
         public void detach() {
             mHandler.post(new Runnable() {
                 @Override
diff --git a/core/java/android/service/dreams/IDozeHardware.aidl b/core/java/android/service/dreams/IDozeHardware.aidl
new file mode 100644
index 0000000..f5a657b
--- /dev/null
+++ b/core/java/android/service/dreams/IDozeHardware.aidl
@@ -0,0 +1,24 @@
+/*
+ * 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 android.service.dreams;
+
+/**
+ * @hide
+ */
+interface IDozeHardware {
+    byte[] sendMessage(String msg, in byte[] arg);
+}
diff --git a/core/java/android/service/dreams/IDreamManager.aidl b/core/java/android/service/dreams/IDreamManager.aidl
index 1c1b390..2718e316 100644
--- a/core/java/android/service/dreams/IDreamManager.aidl
+++ b/core/java/android/service/dreams/IDreamManager.aidl
@@ -16,10 +16,11 @@
 
 package android.service.dreams;
 
+import android.content.ComponentName;
 import android.os.Bundle;
 import android.os.ParcelFileDescriptor;
-import android.content.ComponentName;
 import android.os.IBinder;
+import android.service.dreams.IDozeHardware;
 
 /** @hide */
 interface IDreamManager {
@@ -31,4 +32,7 @@
     void testDream(in ComponentName componentName);
     boolean isDreaming();
     void finishSelf(in IBinder token);
+    void startDozing(in IBinder token);
+    void stopDozing(in IBinder token);
+    IDozeHardware getDozeHardware(in IBinder token);
 }
\ No newline at end of file
diff --git a/core/java/android/service/dreams/IDreamService.aidl b/core/java/android/service/dreams/IDreamService.aidl
index 99dc0b7..bd58f1d 100644
--- a/core/java/android/service/dreams/IDreamService.aidl
+++ b/core/java/android/service/dreams/IDreamService.aidl
@@ -20,6 +20,6 @@
  * @hide
  */
 oneway interface IDreamService {
-    void attach(IBinder windowToken);
+    void attach(IBinder windowToken, boolean canDoze);
     void detach();
 }
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index 2e0e59b..cf862b8 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -112,6 +112,7 @@
      *     {@link android.app.NotificationManager#notify(String, int, android.app.Notification)}.
      */
     public final void cancelNotification(String pkg, String tag, int id) {
+        if (!isBound()) return;
         try {
             getNotificationInterface().cancelNotificationFromListener(mWrapper, pkg, tag, id);
         } catch (android.os.RemoteException ex) {
@@ -131,6 +132,7 @@
      * {@see #cancelNotification(String, String, int)}
      */
     public final void cancelAllNotifications() {
+        if (!isBound()) return;
         try {
             getNotificationInterface().cancelAllNotificationsFromListener(mWrapper);
         } catch (android.os.RemoteException ex) {
@@ -145,6 +147,7 @@
      * @return An array of active notifications.
      */
     public StatusBarNotification[] getActiveNotifications() {
+        if (!isBound()) return null;
         try {
             return getNotificationInterface().getActiveNotificationsFromListener(mWrapper);
         } catch (android.os.RemoteException ex) {
@@ -161,6 +164,14 @@
         return mWrapper;
     }
 
+    private boolean isBound() {
+        if (mWrapper == null) {
+            Log.w(TAG, "Notification listener service not yet bound.");
+            return false;
+        }
+        return true;
+    }
+
     private class INotificationListenerWrapper extends INotificationListener.Stub {
         @Override
         public void onNotificationPosted(StatusBarNotification sbn) {
diff --git a/core/java/android/speech/srec/MicrophoneInputStream.java b/core/java/android/speech/srec/MicrophoneInputStream.java
index fab77a9..94db176 100644
--- a/core/java/android/speech/srec/MicrophoneInputStream.java
+++ b/core/java/android/speech/srec/MicrophoneInputStream.java
@@ -34,7 +34,7 @@
     }
     
     private final static String TAG = "MicrophoneInputStream";
-    private int mAudioRecord = 0;
+    private long mAudioRecord = 0;
     private byte[] mOneByte = new byte[1];
     
     /**
@@ -102,9 +102,9 @@
     //
     // AudioRecord JNI interface
     //
-    private static native int AudioRecordNew(int sampleRate, int fifoDepth);
-    private static native int AudioRecordStart(int audioRecord);
-    private static native int AudioRecordRead(int audioRecord, byte[] b, int offset, int length) throws IOException;
-    private static native void AudioRecordStop(int audioRecord) throws IOException;
-    private static native void AudioRecordDelete(int audioRecord) throws IOException;
+    private static native long AudioRecordNew(int sampleRate, int fifoDepth);
+    private static native int AudioRecordStart(long audioRecord);
+    private static native int AudioRecordRead(long audioRecord, byte[] b, int offset, int length) throws IOException;
+    private static native void AudioRecordStop(long audioRecord) throws IOException;
+    private static native void AudioRecordDelete(long audioRecord) throws IOException;
 }
diff --git a/core/java/android/speech/srec/Recognizer.java b/core/java/android/speech/srec/Recognizer.java
index db5d8fd..1396204 100644
--- a/core/java/android/speech/srec/Recognizer.java
+++ b/core/java/android/speech/srec/Recognizer.java
@@ -125,10 +125,10 @@
     public static final String KEY_MEANING = "meaning";
 
     // handle to SR_Vocabulary object
-    private int mVocabulary = 0;
+    private long mVocabulary = 0;
     
     // handle to SR_Recognizer object
-    private int mRecognizer = 0;
+    private long mRecognizer = 0;
     
     // Grammar currently associated with Recognizer via SR_GrammarSetupRecognizer
     private Grammar mActiveGrammar = null;
@@ -174,7 +174,7 @@
      * Represents a grammar loaded into the Recognizer.
      */
     public class Grammar {
-        private int mGrammar = 0;
+        private long mGrammar = 0;
 
         /**
          * Create a <code>Grammar</code> instance.
@@ -603,116 +603,116 @@
     //
     // SR_Recognizer methods
     //
-    private static native void SR_RecognizerStart(int recognizer);
-    private static native void SR_RecognizerStop(int recognizer);
-    private static native int SR_RecognizerCreate();
-    private static native void SR_RecognizerDestroy(int recognizer);
-    private static native void SR_RecognizerSetup(int recognizer);
-    private static native void SR_RecognizerUnsetup(int recognizer);
-    private static native boolean SR_RecognizerIsSetup(int recognizer);
-    private static native String SR_RecognizerGetParameter(int recognizer, String key);
-    private static native int SR_RecognizerGetSize_tParameter(int recognizer, String key);
-    private static native boolean SR_RecognizerGetBoolParameter(int recognizer, String key);
-    private static native void SR_RecognizerSetParameter(int recognizer, String key, String value);
-    private static native void SR_RecognizerSetSize_tParameter(int recognizer,
+    private static native void SR_RecognizerStart(long recognizer);
+    private static native void SR_RecognizerStop(long recognizer);
+    private static native long SR_RecognizerCreate();
+    private static native void SR_RecognizerDestroy(long recognizer);
+    private static native void SR_RecognizerSetup(long recognizer);
+    private static native void SR_RecognizerUnsetup(long recognizer);
+    private static native boolean SR_RecognizerIsSetup(long recognizer);
+    private static native String SR_RecognizerGetParameter(long recognizer, String key);
+    private static native int SR_RecognizerGetSize_tParameter(long recognizer, String key);
+    private static native boolean SR_RecognizerGetBoolParameter(long recognizer, String key);
+    private static native void SR_RecognizerSetParameter(long recognizer, String key, String value);
+    private static native void SR_RecognizerSetSize_tParameter(long recognizer,
             String key, int value);
-    private static native void SR_RecognizerSetBoolParameter(int recognizer, String key,
+    private static native void SR_RecognizerSetBoolParameter(long recognizer, String key,
             boolean value);
-    private static native void SR_RecognizerSetupRule(int recognizer, int grammar,
+    private static native void SR_RecognizerSetupRule(long recognizer, long grammar,
             String ruleName);
-    private static native boolean SR_RecognizerHasSetupRules(int recognizer);
-    private static native void SR_RecognizerActivateRule(int recognizer, int grammar,
+    private static native boolean SR_RecognizerHasSetupRules(long recognizer);
+    private static native void SR_RecognizerActivateRule(long recognizer, long grammar,
             String ruleName, int weight);
-    private static native void SR_RecognizerDeactivateRule(int recognizer, int grammar,
+    private static native void SR_RecognizerDeactivateRule(long recognizer, long grammar,
             String ruleName);
-    private static native void SR_RecognizerDeactivateAllRules(int recognizer);
-    private static native boolean SR_RecognizerIsActiveRule(int recognizer, int grammar,
+    private static native void SR_RecognizerDeactivateAllRules(long recognizer);
+    private static native boolean SR_RecognizerIsActiveRule(long recognizer, long grammar,
             String ruleName);
-    private static native boolean SR_RecognizerCheckGrammarConsistency(int recognizer,
-            int grammar);
-    private static native int SR_RecognizerPutAudio(int recognizer, byte[] buffer, int offset,
+    private static native boolean SR_RecognizerCheckGrammarConsistency(long recognizer,
+            long grammar);
+    private static native int SR_RecognizerPutAudio(long recognizer, byte[] buffer, int offset,
             int length, boolean isLast);
-    private static native int SR_RecognizerAdvance(int recognizer);
-    // private static native void SR_RecognizerLoadUtterance(int recognizer,
+    private static native int SR_RecognizerAdvance(long recognizer);
+    // private static native void SR_RecognizerLoadUtterance(long recognizer,
     //         const LCHAR* filename);
-    // private static native void SR_RecognizerLoadWaveFile(int recognizer,
+    // private static native void SR_RecognizerLoadWaveFile(long recognizer,
     //         const LCHAR* filename);
-    // private static native void SR_RecognizerSetLockFunction(int recognizer,
+    // private static native void SR_RecognizerSetLockFunction(long recognizer,
     //         SR_RecognizerLockFunction function, void* data);
-    private static native boolean SR_RecognizerIsSignalClipping(int recognizer);
-    private static native boolean SR_RecognizerIsSignalDCOffset(int recognizer);
-    private static native boolean SR_RecognizerIsSignalNoisy(int recognizer);
-    private static native boolean SR_RecognizerIsSignalTooQuiet(int recognizer);
-    private static native boolean SR_RecognizerIsSignalTooFewSamples(int recognizer);
-    private static native boolean SR_RecognizerIsSignalTooManySamples(int recognizer);
+    private static native boolean SR_RecognizerIsSignalClipping(long recognizer);
+    private static native boolean SR_RecognizerIsSignalDCOffset(long recognizer);
+    private static native boolean SR_RecognizerIsSignalNoisy(long recognizer);
+    private static native boolean SR_RecognizerIsSignalTooQuiet(long recognizer);
+    private static native boolean SR_RecognizerIsSignalTooFewSamples(long recognizer);
+    private static native boolean SR_RecognizerIsSignalTooManySamples(long recognizer);
     // private static native void SR_Recognizer_Change_Sample_Rate (size_t new_sample_rate);
     
     
     //
     // SR_AcousticState native methods
     //
-    private static native void SR_AcousticStateReset(int recognizer);
-    private static native void SR_AcousticStateSet(int recognizer, String state);
-    private static native String SR_AcousticStateGet(int recognizer);
+    private static native void SR_AcousticStateReset(long recognizer);
+    private static native void SR_AcousticStateSet(long recognizer, String state);
+    private static native String SR_AcousticStateGet(long recognizer);
 
 
     //
     // SR_Grammar native methods
     //
-    private static native void SR_GrammarCompile(int grammar);
-    private static native void SR_GrammarAddWordToSlot(int grammar, String slot,
+    private static native void SR_GrammarCompile(long grammar);
+    private static native void SR_GrammarAddWordToSlot(long grammar, String slot,
             String word, String pronunciation, int weight, String tag);
-    private static native void SR_GrammarResetAllSlots(int grammar);
-    // private static native void SR_GrammarAddNametagToSlot(int grammar, String slot,
+    private static native void SR_GrammarResetAllSlots(long grammar);
+    // private static native void SR_GrammarAddNametagToSlot(long grammar, String slot,
     // const struct SR_Nametag_t* nametag, int weight, String tag);
-    private static native void SR_GrammarSetupVocabulary(int grammar, int vocabulary);
-    // private static native void SR_GrammarSetupModels(int grammar, SR_AcousticModels* models);
-    private static native void SR_GrammarSetupRecognizer(int grammar, int recognizer);
-    private static native void SR_GrammarUnsetupRecognizer(int grammar);
-    // private static native void SR_GrammarGetModels(int grammar,SR_AcousticModels** models);
-    private static native int SR_GrammarCreate();
-    private static native void SR_GrammarDestroy(int grammar);
-    private static native int SR_GrammarLoad(String filename);
-    private static native void SR_GrammarSave(int grammar, String filename);
-    // private static native void SR_GrammarSetDispatchFunction(int grammar,
+    private static native void SR_GrammarSetupVocabulary(long grammar, long vocabulary);
+    // private static native void SR_GrammarSetupModels(long grammar, SR_AcousticModels* models);
+    private static native void SR_GrammarSetupRecognizer(long grammar, long recognizer);
+    private static native void SR_GrammarUnsetupRecognizer(long grammar);
+    // private static native void SR_GrammarGetModels(long grammar,SR_AcousticModels** models);
+    private static native long SR_GrammarCreate();
+    private static native void SR_GrammarDestroy(long grammar);
+    private static native long SR_GrammarLoad(String filename);
+    private static native void SR_GrammarSave(long grammar, String filename);
+    // private static native void SR_GrammarSetDispatchFunction(long grammar,
     //         const LCHAR* name, void* userData, SR_GrammarDispatchFunction function);
-    // private static native void SR_GrammarSetParameter(int grammar, const
+    // private static native void SR_GrammarSetParameter(long grammar, const
     //         LCHAR* key, void* value);
-    // private static native void SR_GrammarSetSize_tParameter(int grammar,
+    // private static native void SR_GrammarSetSize_tParameter(long grammar,
     //         const LCHAR* key, size_t value);
-    // private static native void SR_GrammarGetParameter(int grammar, const
+    // private static native void SR_GrammarGetParameter(long grammar, const
     //         LCHAR* key, void** value);
-    // private static native void SR_GrammarGetSize_tParameter(int grammar,
+    // private static native void SR_GrammarGetSize_tParameter(long grammar,
     //         const LCHAR* key, size_t* value);
-    // private static native void SR_GrammarCheckParse(int grammar, const LCHAR*
+    // private static native void SR_GrammarCheckParse(long grammar, const LCHAR*
     //         transcription, SR_SemanticResult** result, size_t* resultCount);
-    private static native void SR_GrammarAllowOnly(int grammar, String transcription);
-    private static native void SR_GrammarAllowAll(int grammar);
+    private static native void SR_GrammarAllowOnly(long grammar, String transcription);
+    private static native void SR_GrammarAllowAll(long grammar);
 
 
     //
     // SR_Vocabulary native methods
     //
     // private static native int SR_VocabularyCreate();
-    private static native int SR_VocabularyLoad();
+    private static native long SR_VocabularyLoad();
     // private static native void SR_VocabularySave(SR_Vocabulary* self,
     //         const LCHAR* filename);
     // private static native void SR_VocabularyAddWord(SR_Vocabulary* self,
     //         const LCHAR* word);
     // private static native void SR_VocabularyGetLanguage(SR_Vocabulary* self,
     //         ESR_Locale* locale);
-    private static native void SR_VocabularyDestroy(int vocabulary);
-    private static native String SR_VocabularyGetPronunciation(int vocabulary, String word);
+    private static native void SR_VocabularyDestroy(long vocabulary);
+    private static native String SR_VocabularyGetPronunciation(long vocabulary, String word);
 
 
     //
     // SR_RecognizerResult native methods
     //
-    private static native byte[] SR_RecognizerResultGetWaveform(int recognizer);
-    private static native int SR_RecognizerResultGetSize(int recognizer);
-    private static native int SR_RecognizerResultGetKeyCount(int recognizer, int nbest);
-    private static native String[] SR_RecognizerResultGetKeyList(int recognizer, int nbest);
-    private static native String SR_RecognizerResultGetValue(int recognizer,
+    private static native byte[] SR_RecognizerResultGetWaveform(long recognizer);
+    private static native int SR_RecognizerResultGetSize(long recognizer);
+    private static native int SR_RecognizerResultGetKeyCount(long recognizer, int nbest);
+    private static native String[] SR_RecognizerResultGetKeyList(long recognizer, int nbest);
+    private static native String SR_RecognizerResultGetValue(long recognizer,
             int nbest, String key);
-    // private static native void SR_RecognizerResultGetLocale(int recognizer, ESR_Locale* locale);
+    // private static native void SR_RecognizerResultGetLocale(long recognizer, ESR_Locale* locale);
 }
diff --git a/core/java/android/text/MeasuredText.java b/core/java/android/text/MeasuredText.java
index bd9310c1..101d6a2 100644
--- a/core/java/android/text/MeasuredText.java
+++ b/core/java/android/text/MeasuredText.java
@@ -46,7 +46,7 @@
     }
 
     private static final Object[] sLock = new Object[0];
-    private static MeasuredText[] sCached = new MeasuredText[3];
+    private static final MeasuredText[] sCached = new MeasuredText[3];
 
     static MeasuredText obtain() {
         MeasuredText mt;
diff --git a/core/java/android/util/CharsetUtils.java b/core/java/android/util/CharsetUtils.java
deleted file mode 100644
index a763a69..0000000
--- a/core/java/android/util/CharsetUtils.java
+++ /dev/null
@@ -1,198 +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.
- */
-
-package android.util;
-
-import android.os.Build;
-import android.text.TextUtils;
-
-import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-import java.nio.charset.UnsupportedCharsetException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * <p>
- * A class containing utility methods related to character sets. This
- * class is primarily useful for code that wishes to be vendor-aware
- * in its interpretation of Japanese charset names (used in DoCoMo,
- * KDDI, and SoftBank).
- * </p>
- *
- * <p>
- * <b>Note:</b> Developers will need to add an appropriate mapping for
- * each vendor-specific charset. You may need to modify the C libraries
- * like icu4c in order to let Android support an additional charset.
- * </p>
- *
- * @hide
- */
-public final class CharsetUtils {
-    /**
-     * name of the vendor "DoCoMo". <b>Note:</b> This isn't a public
-     * constant, in order to keep this class from becoming a de facto
-     * reference list of vendor names.
-     */
-    private static final String VENDOR_DOCOMO = "docomo";
-    /**
-     * Name of the vendor "KDDI".
-     */
-    private static final String VENDOR_KDDI = "kddi";
-    /**
-     * Name of the vendor "SoftBank".
-     */
-    private static final String VENDOR_SOFTBANK = "softbank";
-
-    /**
-     * Represents one-to-one mapping from a vendor name to a charset specific to the vendor.
-     */
-    private static final Map<String, String> sVendorShiftJisMap = new HashMap<String, String>();
-
-    static {
-        // These variants of Shift_JIS come from icu's mapping data (convrtrs.txt)
-        sVendorShiftJisMap.put(VENDOR_DOCOMO, "docomo-shift_jis-2007");
-        sVendorShiftJisMap.put(VENDOR_KDDI, "kddi-shift_jis-2007");
-        sVendorShiftJisMap.put(VENDOR_SOFTBANK, "softbank-shift_jis-2007");
-    }
-
-    /**
-     * This class is uninstantiable.
-     */
-    private CharsetUtils() {
-        // This space intentionally left blank.
-    }
-
-    /**
-     * Returns the name of the vendor-specific character set
-     * corresponding to the given original character set name and
-     * vendor. If there is no vendor-specific character set for the
-     * given name/vendor pair, this returns the original character set name.
-     *
-     * @param charsetName the base character set name
-     * @param vendor the vendor to specialize for. All characters should be lower-cased.
-     * @return the specialized character set name, or {@code charsetName} if
-     * there is no specialized name
-     */
-    public static String nameForVendor(String charsetName, String vendor) {
-        if (!TextUtils.isEmpty(charsetName) && !TextUtils.isEmpty(vendor)) {
-            // You can add your own mapping here.
-            if (isShiftJis(charsetName)) {
-                final String vendorShiftJis = sVendorShiftJisMap.get(vendor);
-                if (vendorShiftJis != null) {
-                    return vendorShiftJis;
-                }
-            }
-        }
-
-        return charsetName;
-    }
-
-    /**
-     * Returns the name of the vendor-specific character set
-     * corresponding to the given original character set name and the
-     * default vendor (that is, the targeted vendor of the device this
-     * code is running on). This method merely calls through to
-     * {@link #nameForVendor(String,String)}, passing the default vendor
-     * as the second argument.
-     * 
-     * @param charsetName the base character set name
-     * @return the specialized character set name, or {@code charsetName} if
-     * there is no specialized name
-     */
-    public static String nameForDefaultVendor(String charsetName) {
-        return nameForVendor(charsetName, getDefaultVendor());
-    }
-
-    /**
-     * Returns the vendor-specific character set corresponding to the
-     * given original character set name and vendor. If there is no
-     * vendor-specific character set for the given name/vendor pair,
-     * this returns the character set corresponding to the original
-     * name. The vendor name is matched case-insensitively. This
-     * method merely calls {@code Charset.forName()} on a name
-     * transformed by a call to {@link #nameForVendor(String,String)}.
-     * 
-     * @param charsetName the base character set name
-     * @param vendor the vendor to specialize for
-     * @return the specialized character set, or the one corresponding
-     * directly to {@code charsetName} if there is no specialized
-     * variant
-     * @throws UnsupportedCharsetException thrown if the named character
-     * set is not supported by the system
-     * @throws IllegalCharsetNameException thrown if {@code charsetName}
-     * has invalid syntax
-     */
-    public static Charset charsetForVendor(String charsetName, String vendor)
-            throws UnsupportedCharsetException, IllegalCharsetNameException {
-        charsetName = nameForVendor(charsetName, vendor);
-        return Charset.forName(charsetName);
-    }
-    
-    /**
-     * Returns the vendor-specific character set corresponding to the
-     * given original character set name and default vendor (that is,
-     * the targeted vendor of the device this code is running on). 
-     * This method merely calls through to {@link
-     * #charsetForVendor(String,String)}, passing the default vendor
-     * as the second argument.
-     * 
-     * @param charsetName the base character set name
-     * @return the specialized character set, or the one corresponding
-     * directly to {@code charsetName} if there is no specialized
-     * variant
-     * @throws UnsupportedCharsetException thrown if the named character
-     * set is not supported by the system
-     * @throws IllegalCharsetNameException thrown if {@code charsetName}
-     * has invalid syntax
-     */
-    public static Charset charsetForVendor(String charsetName)
-            throws UnsupportedCharsetException, IllegalCharsetNameException {
-        return charsetForVendor(charsetName, getDefaultVendor());
-    }
-
-    /**
-     * Returns whether the given character set name indicates the Shift-JIS
-     * encoding. Returns false if the name is null.
-     * 
-     * @param charsetName the character set name
-     * @return {@code true} if the name corresponds to Shift-JIS or
-     * {@code false} if not
-     */
-    private static boolean isShiftJis(String charsetName) {
-        // Bail quickly if the length doesn't match.
-        if (charsetName == null) {
-            return false;
-        }
-        int length = charsetName.length();
-        if (length != 4 && length != 9) {
-            return false;
-        }
-
-        return charsetName.equalsIgnoreCase("shift_jis")
-            || charsetName.equalsIgnoreCase("shift-jis")
-            || charsetName.equalsIgnoreCase("sjis");
-    }
-
-    /**
-     * Gets the default vendor for this build.
-     * 
-     * @return the default vendor name
-     */
-    private static String getDefaultVendor() {
-        return Build.BRAND;
-    }
-}
diff --git a/core/java/android/util/TypedValue.java b/core/java/android/util/TypedValue.java
index ed45298..931fb81 100644
--- a/core/java/android/util/TypedValue.java
+++ b/core/java/android/util/TypedValue.java
@@ -290,18 +290,14 @@
         return -1;
     }
 
+    /**
+     * @hide Was accidentally exposed in API level 1 for debugging purposes.
+     * Kept for compatibility just in case although the debugging code has been removed.
+     */
+    @Deprecated
     public static float complexToDimensionNoisy(int data, DisplayMetrics metrics)
     {
-        float res = complexToDimension(data, metrics);
-        System.out.println(
-            "Dimension (0x" + ((data>>TypedValue.COMPLEX_MANTISSA_SHIFT)
-                               & TypedValue.COMPLEX_MANTISSA_MASK)
-            + "*" + (RADIX_MULTS[(data>>TypedValue.COMPLEX_RADIX_SHIFT)
-                                & TypedValue.COMPLEX_RADIX_MASK] / MANTISSA_MULT)
-            + ")" + DIMENSION_UNIT_STRS[(data>>COMPLEX_UNIT_SHIFT)
-                                & COMPLEX_UNIT_MASK]
-            + " = " + res);
-        return res;
+        return complexToDimension(data, metrics);
     }
 
     /**
diff --git a/core/java/android/view/DisplayAdjustments.java b/core/java/android/view/DisplayAdjustments.java
index 041d9e0..35fb504 100644
--- a/core/java/android/view/DisplayAdjustments.java
+++ b/core/java/android/view/DisplayAdjustments.java
@@ -19,7 +19,7 @@
 import android.content.res.CompatibilityInfo;
 import android.os.IBinder;
 
-import com.android.internal.util.Objects;
+import java.util.Objects;
 
 /** @hide */
 public class DisplayAdjustments {
@@ -91,7 +91,7 @@
             return false;
         }
         DisplayAdjustments daj = (DisplayAdjustments)o;
-        return Objects.equal(daj.mCompatInfo, mCompatInfo) &&
-                Objects.equal(daj.mActivityToken, mActivityToken);
+        return Objects.equals(daj.mCompatInfo, mCompatInfo) &&
+                Objects.equals(daj.mActivityToken, mActivityToken);
     }
 }
diff --git a/core/java/android/view/DisplayEventReceiver.java b/core/java/android/view/DisplayEventReceiver.java
index 4dade20..de46a4a 100644
--- a/core/java/android/view/DisplayEventReceiver.java
+++ b/core/java/android/view/DisplayEventReceiver.java
@@ -36,16 +36,16 @@
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
-    private int mReceiverPtr;
+    private long mReceiverPtr;
 
     // We keep a reference message queue object here so that it is not
     // GC'd while the native peer of the receiver is using them.
     private MessageQueue mMessageQueue;
 
-    private static native int nativeInit(DisplayEventReceiver receiver,
+    private static native long nativeInit(DisplayEventReceiver receiver,
             MessageQueue messageQueue);
-    private static native void nativeDispose(int receiverPtr);
-    private static native void nativeScheduleVsync(int receiverPtr);
+    private static native void nativeDispose(long receiverPtr);
+    private static native void nativeScheduleVsync(long receiverPtr);
 
     /**
      * Creates a display event receiver.
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index beefc21..6a15fa6 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -49,7 +49,7 @@
     private static final int MODIFIER_COLOR_FILTER = 4;
 
     private final boolean mOpaque;
-    private int mRenderer;
+    private long mRenderer;
 
     // The native renderer will be destroyed when this object dies.
     // DO NOT overwrite this reference once it is set.
@@ -92,7 +92,7 @@
     /**
      * Creates a canvas to render into an FBO.
      */
-    GLES20Canvas(int layer, boolean translucent) {
+    GLES20Canvas(long layer, boolean translucent) {
         mOpaque = !translucent;
         mRenderer = nCreateLayerRenderer(layer);
         setupFinalizer();
@@ -122,16 +122,16 @@
         nResetDisplayListRenderer(mRenderer);
     }
 
-    private static native int nCreateRenderer();
-    private static native int nCreateLayerRenderer(int layer);
-    private static native int nCreateDisplayListRenderer();
-    private static native void nResetDisplayListRenderer(int renderer);
-    private static native void nDestroyRenderer(int renderer);
+    private static native long nCreateRenderer();
+    private static native long nCreateLayerRenderer(long layer);
+    private static native long nCreateDisplayListRenderer();
+    private static native void nResetDisplayListRenderer(long renderer);
+    private static native void nDestroyRenderer(long renderer);
 
     private static final class CanvasFinalizer {
-        private final int mRenderer;
+        private final long mRenderer;
 
-        public CanvasFinalizer(int renderer) {
+        public CanvasFinalizer(long renderer) {
             mRenderer = renderer;
         }
 
@@ -151,7 +151,7 @@
         nSetName(mRenderer, name);
     }
 
-    private static native void nSetName(int renderer, String name);
+    private static native void nSetName(long renderer, String name);
 
     ///////////////////////////////////////////////////////////////////////////
     // Hardware layers
@@ -177,26 +177,26 @@
         nClearLayerUpdates(mRenderer);
     }
 
-    static native int nCreateTextureLayer(boolean opaque, int[] layerInfo);
-    static native int nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo);
-    static native boolean nResizeLayer(int layerId, int width, int height, int[] layerInfo);
-    static native void nSetOpaqueLayer(int layerId, boolean isOpaque);
-    static native void nSetLayerPaint(int layerId, int nativePaint);
-    static native void nSetLayerColorFilter(int layerId, int nativeColorFilter);
-    static native void nUpdateTextureLayer(int layerId, int width, int height, boolean opaque,
+    static native long nCreateTextureLayer(boolean opaque, int[] layerInfo);
+    static native long nCreateLayer(int width, int height, boolean isOpaque, int[] layerInfo);
+    static native boolean nResizeLayer(long layerId, int width, int height, int[] layerInfo);
+    static native void nSetOpaqueLayer(long layerId, boolean isOpaque);
+    static native void nSetLayerPaint(long layerId, long nativePaint);
+    static native void nSetLayerColorFilter(long layerId, long nativeColorFilter);
+    static native void nUpdateTextureLayer(long layerId, int width, int height, boolean opaque,
             SurfaceTexture surface);
-    static native void nClearLayerTexture(int layerId);
-    static native void nSetTextureLayerTransform(int layerId, int matrix);
-    static native void nDestroyLayer(int layerId);
-    static native void nDestroyLayerDeferred(int layerId);
-    static native void nUpdateRenderLayer(int layerId, int renderer, int displayList,
+    static native void nClearLayerTexture(long layerId);
+    static native void nSetTextureLayerTransform(long layerId, long matrix);
+    static native void nDestroyLayer(long layerId);
+    static native void nDestroyLayerDeferred(long layerId);
+    static native void nUpdateRenderLayer(long layerId, long renderer, long displayList,
             int left, int top, int right, int bottom);
-    static native boolean nCopyLayer(int layerId, int bitmap);
+    static native boolean nCopyLayer(long layerId, long bitmap);
 
-    private static native void nClearLayerUpdates(int renderer);
-    private static native void nFlushLayerUpdates(int renderer);
-    private static native void nPushLayerUpdate(int renderer, int layer);
-    private static native void nCancelLayerUpdate(int renderer, int layer);
+    private static native void nClearLayerUpdates(long renderer);
+    private static native void nFlushLayerUpdates(long renderer);
+    private static native void nPushLayerUpdate(long renderer, long layer);
+    private static native void nCancelLayerUpdate(long renderer, long layer);
 
     ///////////////////////////////////////////////////////////////////////////
     // Canvas management
@@ -233,7 +233,7 @@
     /**
      * Returns the native OpenGLRenderer object.
      */
-    int getRenderer() {
+    long getRenderer() {
         return mRenderer;
     }
 
@@ -249,7 +249,7 @@
         nSetViewport(mRenderer, width, height);
     }
     
-    private static native void nSetViewport(int renderer, int width, int height);
+    private static native void nSetViewport(long renderer, int width, int height);
 
     @Override
     public int onPreDraw(Rect dirty) {
@@ -261,8 +261,8 @@
         }
     }
 
-    private static native int nPrepare(int renderer, boolean opaque);
-    private static native int nPrepareDirty(int renderer, int left, int top, int right, int bottom,
+    private static native int nPrepare(long renderer, boolean opaque);
+    private static native int nPrepareDirty(long renderer, int left, int top, int right, int bottom,
             boolean opaque);
 
     @Override
@@ -270,7 +270,7 @@
         nFinish(mRenderer);
     }
 
-    private static native void nFinish(int renderer);
+    private static native void nFinish(long renderer);
 
     /**
      * Returns the size of the stencil buffer required by the underlying
@@ -290,45 +290,45 @@
         nSetCountOverdrawEnabled(mRenderer, enabled);
     }
 
-    static native void nSetCountOverdrawEnabled(int renderer, boolean enabled);
+    static native void nSetCountOverdrawEnabled(long renderer, boolean enabled);
 
     float getOverdraw() {
         return nGetOverdraw(mRenderer);
     }
 
-    static native float nGetOverdraw(int renderer);
+    static native float nGetOverdraw(long renderer);
 
     ///////////////////////////////////////////////////////////////////////////
     // Functor
     ///////////////////////////////////////////////////////////////////////////
 
     @Override
-    public int callDrawGLFunction(int drawGLFunction) {
+    public int callDrawGLFunction(long drawGLFunction) {
         return nCallDrawGLFunction(mRenderer, drawGLFunction);
     }
 
-    private static native int nCallDrawGLFunction(int renderer, int drawGLFunction);
+    private static native int nCallDrawGLFunction(long renderer, long drawGLFunction);
 
     @Override
     public int invokeFunctors(Rect dirty) {
         return nInvokeFunctors(mRenderer, dirty);
     }
 
-    private static native int nInvokeFunctors(int renderer, Rect dirty);
+    private static native int nInvokeFunctors(long renderer, Rect dirty);
 
     @Override
-    public void detachFunctor(int functor) {
+    public void detachFunctor(long functor) {
         nDetachFunctor(mRenderer, functor);
     }
 
-    private static native void nDetachFunctor(int renderer, int functor);
+    private static native void nDetachFunctor(long renderer, long functor);
 
     @Override
-    public void attachFunctor(int functor) {
+    public void attachFunctor(long functor) {
         nAttachFunctor(mRenderer, functor);
     }
 
-    private static native void nAttachFunctor(int renderer, int functor);
+    private static native void nAttachFunctor(long renderer, long functor);
 
     ///////////////////////////////////////////////////////////////////////////
     // Memory
@@ -402,18 +402,18 @@
     // Display list
     ///////////////////////////////////////////////////////////////////////////
 
-    int getDisplayList(int displayList) {
+    long getDisplayList(long displayList) {
         return nGetDisplayList(mRenderer, displayList);
     }
 
-    private static native int nGetDisplayList(int renderer, int displayList);
+    private static native long nGetDisplayList(long renderer, long displayList);
 
     @Override
     void outputDisplayList(DisplayList displayList) {
         nOutputDisplayList(mRenderer, ((GLES20DisplayList) displayList).getNativeDisplayList());
     }
 
-    private static native void nOutputDisplayList(int renderer, int displayList);
+    private static native void nOutputDisplayList(long renderer, long displayList);
 
     @Override
     public int drawDisplayList(DisplayList displayList, Rect dirty, int flags) {
@@ -421,7 +421,7 @@
                 dirty, flags);
     }
 
-    private static native int nDrawDisplayList(int renderer, int displayList,
+    private static native int nDrawDisplayList(long renderer, long displayList,
             Rect dirty, int flags);
 
     ///////////////////////////////////////////////////////////////////////////
@@ -435,7 +435,7 @@
         nDrawLayer(mRenderer, glLayer.getLayer(), x, y);
     }
 
-    private static native void nDrawLayer(int renderer, int layer, float x, float y);
+    private static native void nDrawLayer(long renderer, long layer, float x, float y);
 
     void interrupt() {
         nInterrupt(mRenderer);
@@ -445,8 +445,8 @@
         nResume(mRenderer);
     }
 
-    private static native void nInterrupt(int renderer);
-    private static native void nResume(int renderer);
+    private static native void nInterrupt(long renderer);
+    private static native void nResume(long renderer);
 
     ///////////////////////////////////////////////////////////////////////////
     // Support
@@ -487,14 +487,14 @@
         return nClipPath(mRenderer, path.mNativePath, op.nativeInt);
     }
 
-    private static native boolean nClipPath(int renderer, int path, int op);
+    private static native boolean nClipPath(long renderer, long path, int op);
 
     @Override
     public boolean clipRect(float left, float top, float right, float bottom) {
         return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
     }
     
-    private static native boolean nClipRect(int renderer, float left, float top,
+    private static native boolean nClipRect(long renderer, float left, float top,
             float right, float bottom, int op);
 
     @Override
@@ -507,7 +507,7 @@
         return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
     }
     
-    private static native boolean nClipRect(int renderer, int left, int top,
+    private static native boolean nClipRect(long renderer, int left, int top,
             int right, int bottom, int op);
 
     @Override
@@ -542,21 +542,21 @@
         return nClipRegion(mRenderer, region.mNativeRegion, op.nativeInt);
     }
 
-    private static native boolean nClipRegion(int renderer, int region, int op);
+    private static native boolean nClipRegion(long renderer, long region, int op);
 
     @Override
     public boolean getClipBounds(Rect bounds) {
         return nGetClipBounds(mRenderer, bounds);
     }
 
-    private static native boolean nGetClipBounds(int renderer, Rect bounds);
+    private static native boolean nGetClipBounds(long renderer, Rect bounds);
 
     @Override
     public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) {
         return nQuickReject(mRenderer, left, top, right, bottom);
     }
     
-    private static native boolean nQuickReject(int renderer, float left, float top,
+    private static native boolean nQuickReject(long renderer, float left, float top,
             float right, float bottom);
 
     @Override
@@ -581,35 +581,35 @@
         if (dx != 0.0f || dy != 0.0f) nTranslate(mRenderer, dx, dy);
     }
     
-    private static native void nTranslate(int renderer, float dx, float dy);
+    private static native void nTranslate(long renderer, float dx, float dy);
 
     @Override
     public void skew(float sx, float sy) {
         nSkew(mRenderer, sx, sy);
     }
 
-    private static native void nSkew(int renderer, float sx, float sy);
+    private static native void nSkew(long renderer, float sx, float sy);
 
     @Override
     public void rotate(float degrees) {
         nRotate(mRenderer, degrees);
     }
     
-    private static native void nRotate(int renderer, float degrees);
+    private static native void nRotate(long renderer, float degrees);
 
     @Override
     public void scale(float sx, float sy) {
         nScale(mRenderer, sx, sy);
     }
     
-    private static native void nScale(int renderer, float sx, float sy);
+    private static native void nScale(long renderer, float sx, float sy);
 
     @Override
     public void setMatrix(Matrix matrix) {
         nSetMatrix(mRenderer, matrix == null ? 0 : matrix.native_instance);
     }
     
-    private static native void nSetMatrix(int renderer, int matrix);
+    private static native void nSetMatrix(long renderer, long matrix);
 
     @SuppressWarnings("deprecation")
     @Override
@@ -617,14 +617,14 @@
         nGetMatrix(mRenderer, matrix.native_instance);
     }
     
-    private static native void nGetMatrix(int renderer, int matrix);
+    private static native void nGetMatrix(long renderer, long matrix);
 
     @Override
     public void concat(Matrix matrix) {
         if (matrix != null) nConcatMatrix(mRenderer, matrix.native_instance);
     }
     
-    private static native void nConcatMatrix(int renderer, int matrix);
+    private static native void nConcatMatrix(long renderer, long matrix);
     
     ///////////////////////////////////////////////////////////////////////////
     // State management
@@ -640,7 +640,7 @@
         return nSave(mRenderer, saveFlags);
     }
 
-    private static native int nSave(int renderer, int flags);
+    private static native int nSave(long renderer, int flags);
     
     @Override
     public int saveLayer(RectF bounds, Paint paint, int saveFlags) {
@@ -651,7 +651,7 @@
         int count;
         int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             count = nSaveLayer(mRenderer, nativePaint, saveFlags);
         } finally {
             if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier);
@@ -659,7 +659,7 @@
         return count;
     }
 
-    private static native int nSaveLayer(int renderer, int paint, int saveFlags);    
+    private static native int nSaveLayer(long renderer, long paint, int saveFlags);
 
     @Override
     public int saveLayer(float left, float top, float right, float bottom, Paint paint,
@@ -668,7 +668,7 @@
             int count;
             int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
             try {
-                final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+                final long nativePaint = paint == null ? 0 : paint.mNativePaint;
                 count = nSaveLayer(mRenderer, left, top, right, bottom, nativePaint, saveFlags);
             } finally {
                 if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier);
@@ -678,8 +678,8 @@
         return save(saveFlags);
     }
 
-    private static native int nSaveLayer(int renderer, float left, float top,
-            float right, float bottom, int paint, int saveFlags);
+    private static native int nSaveLayer(long renderer, float left, float top,
+            float right, float bottom, long paint, int saveFlags);
 
     @Override
     public int saveLayerAlpha(RectF bounds, int alpha, int saveFlags) {
@@ -690,7 +690,7 @@
         return nSaveLayerAlpha(mRenderer, alpha, saveFlags);
     }
 
-    private static native int nSaveLayerAlpha(int renderer, int alpha, int saveFlags);    
+    private static native int nSaveLayerAlpha(long renderer, int alpha, int saveFlags);
 
     @Override
     public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
@@ -701,7 +701,7 @@
         return save(saveFlags);
     }
 
-    private static native int nSaveLayerAlpha(int renderer, float left, float top, float right,
+    private static native int nSaveLayerAlpha(long renderer, float left, float top, float right,
             float bottom, int alpha, int saveFlags);
     
     @Override
@@ -709,21 +709,21 @@
         nRestore(mRenderer);
     }
     
-    private static native void nRestore(int renderer);
+    private static native void nRestore(long renderer);
 
     @Override
     public void restoreToCount(int saveCount) {
         nRestoreToCount(mRenderer, saveCount);
     }
 
-    private static native void nRestoreToCount(int renderer, int saveCount);
+    private static native void nRestoreToCount(long renderer, int saveCount);
     
     @Override
     public int getSaveCount() {
         return nGetSaveCount(mRenderer);
     }
     
-    private static native int nGetSaveCount(int renderer);
+    private static native int nGetSaveCount(long renderer);
 
     ///////////////////////////////////////////////////////////////////////////
     // Filtering
@@ -740,8 +740,8 @@
         }
     }
 
-    private static native void nResetPaintFilter(int renderer);
-    private static native void nSetupPaintFilter(int renderer, int clearBits, int setBits);
+    private static native void nResetPaintFilter(long renderer);
+    private static native void nSetupPaintFilter(long renderer, int clearBits, int setBits);
 
     @Override
     public DrawFilter getDrawFilter() {
@@ -764,9 +764,9 @@
         }
     }
 
-    private static native void nDrawArc(int renderer, float left, float top,
+    private static native void nDrawArc(long renderer, float left, float top,
             float right, float bottom, float startAngle, float sweepAngle,
-            boolean useCenter, int paint);
+            boolean useCenter, long paint);
 
     @Override
     public void drawARGB(int a, int r, int g, int b) {
@@ -780,7 +780,7 @@
         // Shaders are ignored when drawing patches
         int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             nDrawPatch(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, patch.mNativeChunk,
                     dst.left, dst.top, dst.right, dst.bottom, nativePaint);
         } finally {
@@ -795,7 +795,7 @@
         // Shaders are ignored when drawing patches
         int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             nDrawPatch(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, patch.mNativeChunk,
                     dst.left, dst.top, dst.right, dst.bottom, nativePaint);
         } finally {
@@ -803,8 +803,8 @@
         }
     }
 
-    private static native void nDrawPatch(int renderer, int bitmap, byte[] buffer, int chunk,
-            float left, float top, float right, float bottom, int paint);
+    private static native void nDrawPatch(long renderer, long bitmap, byte[] buffer, long chunk,
+            float left, float top, float right, float bottom, long paint);
 
     @Override
     public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
@@ -812,15 +812,15 @@
         // Shaders are ignored when drawing bitmaps
         int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, left, top, nativePaint);
         } finally {
             if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
         }
     }
 
-    private static native void nDrawBitmap(int renderer, int bitmap, byte[] buffer,
-            float left, float top, int paint);
+    private static native void nDrawBitmap(long renderer, long bitmap, byte[] buffer,
+            float left, float top, long paint);
 
     @Override
     public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
@@ -828,7 +828,7 @@
         // Shaders are ignored when drawing bitmaps
         int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer,
                     matrix.native_instance, nativePaint);
         } finally {
@@ -836,8 +836,8 @@
         }
     }
 
-    private static native void nDrawBitmap(int renderer, int bitmap, byte[] buffer,
-            int matrix, int paint);
+    private static native void nDrawBitmap(long renderer, long bitmap, byte[] buffer,
+            long matrix, long paint);
 
     @Override
     public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
@@ -845,7 +845,7 @@
         // Shaders are ignored when drawing bitmaps
         int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
 
             int left, top, right, bottom;
             if (src == null) {
@@ -872,7 +872,7 @@
         // Shaders are ignored when drawing bitmaps
         int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
     
             float left, top, right, bottom;
             if (src == null) {
@@ -893,9 +893,9 @@
         }
     }
 
-    private static native void nDrawBitmap(int renderer, int bitmap, byte[] buffer,
+    private static native void nDrawBitmap(long renderer, long bitmap, byte[] buffer,
             float srcLeft, float srcTop, float srcRight, float srcBottom,
-            float left, float top, float right, float bottom, int paint);
+            float left, float top, float right, float bottom, long paint);
 
     @Override
     public void drawBitmap(int[] colors, int offset, int stride, float x, float y,
@@ -923,7 +923,7 @@
         // Shaders are ignored when drawing bitmaps
         int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             nDrawBitmap(mRenderer, colors, offset, stride, x, y,
                     width, height, hasAlpha, nativePaint);
         } finally {
@@ -931,8 +931,8 @@
         }
     }
 
-    private static native void nDrawBitmap(int renderer, int[] colors, int offset, int stride,
-            float x, float y, int width, int height, boolean hasAlpha, int nativePaint);
+    private static native void nDrawBitmap(long renderer, int[] colors, int offset, int stride,
+            float x, float y, int width, int height, boolean hasAlpha, long nativePaint);
 
     @Override
     public void drawBitmap(int[] colors, int offset, int stride, int x, int y,
@@ -962,7 +962,7 @@
 
         int modifiers = paint != null ? setupModifiers(bitmap, paint) : MODIFIER_NONE;
         try {
-            final int nativePaint = paint == null ? 0 : paint.mNativePaint;
+            final long nativePaint = paint == null ? 0 : paint.mNativePaint;
             nDrawBitmapMesh(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, meshWidth, meshHeight,
                     verts, vertOffset, colors, colorOffset, nativePaint);
         } finally {
@@ -970,9 +970,9 @@
         }
     }
 
-    private static native void nDrawBitmapMesh(int renderer, int bitmap, byte[] buffer,
+    private static native void nDrawBitmapMesh(long renderer, long bitmap, byte[] buffer,
             int meshWidth, int meshHeight, float[] verts, int vertOffset,
-            int[] colors, int colorOffset, int paint);
+            int[] colors, int colorOffset, long paint);
 
     @Override
     public void drawCircle(float cx, float cy, float radius, Paint paint) {
@@ -984,8 +984,8 @@
         }
     }
 
-    private static native void nDrawCircle(int renderer, float cx, float cy,
-            float radius, int paint);
+    private static native void nDrawCircle(long renderer, float cx, float cy,
+            float radius, long paint);
 
     @Override
     public void drawColor(int color) {
@@ -997,7 +997,7 @@
         nDrawColor(mRenderer, color, mode.nativeInt);
     }
     
-    private static native void nDrawColor(int renderer, int color, int mode);
+    private static native void nDrawColor(long renderer, int color, int mode);
 
     @Override
     public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
@@ -1024,8 +1024,8 @@
         }
     }
 
-    private static native void nDrawLines(int renderer, float[] points,
-            int offset, int count, int paint);
+    private static native void nDrawLines(long renderer, float[] points,
+            int offset, int count, long paint);
 
     @Override
     public void drawLines(float[] pts, Paint paint) {
@@ -1042,8 +1042,8 @@
         }
     }
 
-    private static native void nDrawOval(int renderer, float left, float top,
-            float right, float bottom, int paint);
+    private static native void nDrawOval(long renderer, float left, float top,
+            float right, float bottom, long paint);
 
     @Override
     public void drawPaint(Paint paint) {
@@ -1068,8 +1068,8 @@
         }
     }
 
-    private static native void nDrawPath(int renderer, int path, int paint);
-    private static native void nDrawRects(int renderer, int region, int paint);
+    private static native void nDrawPath(long renderer, long path, long paint);
+    private static native void nDrawRects(long renderer, long region, long paint);
 
     void drawRects(float[] rects, int count, Paint paint) {
         int modifiers = setupModifiers(paint, MODIFIER_COLOR_FILTER | MODIFIER_SHADER);
@@ -1080,7 +1080,7 @@
         }
     }
 
-    private static native void nDrawRects(int renderer, float[] rects, int count, int paint);
+    private static native void nDrawRects(long renderer, float[] rects, int count, long paint);
 
     @Override
     public void drawPicture(Picture picture) {
@@ -1147,8 +1147,8 @@
         }
     }
 
-    private static native void nDrawPoints(int renderer, float[] points,
-            int offset, int count, int paint);
+    private static native void nDrawPoints(long renderer, float[] points,
+            int offset, int count, long paint);
 
     @SuppressWarnings("deprecation")
     @Override
@@ -1165,8 +1165,8 @@
         }
     }
 
-    private static native void nDrawPosText(int renderer, char[] text, int index, int count,
-            float[] pos, int paint);
+    private static native void nDrawPosText(long renderer, char[] text, int index, int count,
+            float[] pos, long paint);
 
     @SuppressWarnings("deprecation")
     @Override
@@ -1183,8 +1183,8 @@
         }
     }
 
-    private static native void nDrawPosText(int renderer, String text, int start, int end,
-            float[] pos, int paint);
+    private static native void nDrawPosText(long renderer, String text, int start, int end,
+            float[] pos, long paint);
 
     @Override
     public void drawRect(float left, float top, float right, float bottom, Paint paint) {
@@ -1197,8 +1197,8 @@
         }
     }
 
-    private static native void nDrawRect(int renderer, float left, float top,
-            float right, float bottom, int paint);
+    private static native void nDrawRect(long renderer, float left, float top,
+            float right, float bottom, long paint);
 
     @Override
     public void drawRect(Rect r, Paint paint) {
@@ -1226,8 +1226,8 @@
         }
     }
 
-    private static native void nDrawRoundRect(int renderer, float left, float top,
-            float right, float bottom, float rx, float y, int paint);
+    private static native void nDrawRoundRect(long renderer, float left, float top,
+            float right, float bottom, float rx, float y, long paint);
 
     @Override
     public void drawText(char[] text, int index, int count, float x, float y, Paint paint) {
@@ -1243,8 +1243,8 @@
         }
     }
     
-    private static native void nDrawText(int renderer, char[] text, int index, int count,
-            float x, float y, int bidiFlags, int paint);
+    private static native void nDrawText(long renderer, char[] text, int index, int count,
+            float x, float y, int bidiFlags, long paint);
 
     @Override
     public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
@@ -1283,8 +1283,8 @@
         }
     }
 
-    private static native void nDrawText(int renderer, String text, int start, int end,
-            float x, float y, int bidiFlags, int paint);
+    private static native void nDrawText(long renderer, String text, int start, int end,
+            float x, float y, int bidiFlags, long paint);
 
     @Override
     public void drawText(String text, float x, float y, Paint paint) {
@@ -1313,8 +1313,8 @@
         }
     }
 
-    private static native void nDrawTextOnPath(int renderer, char[] text, int index, int count,
-            int path, float hOffset, float vOffset, int bidiFlags, int nativePaint);
+    private static native void nDrawTextOnPath(long renderer, char[] text, int index, int count,
+            long path, float hOffset, float vOffset, int bidiFlags, long nativePaint);
 
     @Override
     public void drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint) {
@@ -1329,8 +1329,8 @@
         }
     }
 
-    private static native void nDrawTextOnPath(int renderer, String text, int start, int end,
-            int path, float hOffset, float vOffset, int bidiFlags, int nativePaint);
+    private static native void nDrawTextOnPath(long renderer, String text, int start, int end,
+            long path, float hOffset, float vOffset, int bidiFlags, long nativePaint);
 
     @Override
     public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount,
@@ -1351,8 +1351,8 @@
         }
     }
 
-    private static native void nDrawTextRun(int renderer, char[] text, int index, int count,
-            int contextIndex, int contextCount, float x, float y, int dir, int nativePaint);
+    private static native void nDrawTextRun(long renderer, char[] text, int index, int count,
+            int contextIndex, int contextCount, float x, float y, int dir, long nativePaint);
 
     @Override
     public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd,
@@ -1385,8 +1385,8 @@
         }
     }
 
-    private static native void nDrawTextRun(int renderer, String text, int start, int end,
-            int contextStart, int contextEnd, float x, float y, int flags, int nativePaint);
+    private static native void nDrawTextRun(long renderer, String text, int start, int end,
+            int contextStart, int contextEnd, float x, float y, int flags, long nativePaint);
 
     @Override
     public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,
@@ -1466,10 +1466,10 @@
         return MODIFIER_NONE;
     }
 
-    private static native void nSetupShader(int renderer, int shader);
-    private static native void nSetupColorFilter(int renderer, int colorFilter);
-    private static native void nSetupShadow(int renderer, float radius,
+    private static native void nSetupShader(long renderer, long shader);
+    private static native void nSetupColorFilter(long renderer, long colorFilter);
+    private static native void nSetupShadow(long renderer, float radius,
             float dx, float dy, int color);
 
-    private static native void nResetModifiers(int renderer, int modifiers);
+    private static native void nResetModifiers(long renderer, int modifiers);
 }
diff --git a/core/java/android/view/GLES20DisplayList.java b/core/java/android/view/GLES20DisplayList.java
index c652bac..7f8b3bd 100644
--- a/core/java/android/view/GLES20DisplayList.java
+++ b/core/java/android/view/GLES20DisplayList.java
@@ -44,7 +44,7 @@
         return mValid && mFinalizer != null;
     }
 
-    int getNativeDisplayList() {
+    long getNativeDisplayList() {
         if (!mValid || mFinalizer == null) {
             throw new IllegalStateException("The display list is not valid.");
         }
@@ -124,9 +124,9 @@
         return nGetDisplayListSize(mFinalizer.mNativeDisplayList);
     }
 
-    private static native void nDestroyDisplayList(int displayList);
-    private static native int nGetDisplayListSize(int displayList);
-    private static native void nSetDisplayListName(int displayList, String name);
+    private static native void nDestroyDisplayList(long displayList);
+    private static native int nGetDisplayListSize(long displayList);
+    private static native void nSetDisplayListName(long displayList, String name);
 
     ///////////////////////////////////////////////////////////////////////////
     // Native View Properties
@@ -440,62 +440,62 @@
         }
     }
 
-    private static native void nReset(int displayList);
-    private static native void nOffsetTopAndBottom(int displayList, float offset);
-    private static native void nOffsetLeftAndRight(int displayList, float offset);
-    private static native void nSetLeftTopRightBottom(int displayList, int left, int top,
+    private static native void nReset(long displayList);
+    private static native void nOffsetTopAndBottom(long displayList, float offset);
+    private static native void nOffsetLeftAndRight(long displayList, float offset);
+    private static native void nSetLeftTopRightBottom(long displayList, int left, int top,
             int right, int bottom);
-    private static native void nSetBottom(int displayList, int bottom);
-    private static native void nSetRight(int displayList, int right);
-    private static native void nSetTop(int displayList, int top);
-    private static native void nSetLeft(int displayList, int left);
-    private static native void nSetCameraDistance(int displayList, float distance);
-    private static native void nSetPivotY(int displayList, float pivotY);
-    private static native void nSetPivotX(int displayList, float pivotX);
-    private static native void nSetCaching(int displayList, boolean caching);
-    private static native void nSetClipToBounds(int displayList, boolean clipToBounds);
-    private static native void nSetAlpha(int displayList, float alpha);
-    private static native void nSetHasOverlappingRendering(int displayList,
+    private static native void nSetBottom(long displayList, int bottom);
+    private static native void nSetRight(long displayList, int right);
+    private static native void nSetTop(long displayList, int top);
+    private static native void nSetLeft(long displayList, int left);
+    private static native void nSetCameraDistance(long displayList, float distance);
+    private static native void nSetPivotY(long displayList, float pivotY);
+    private static native void nSetPivotX(long displayList, float pivotX);
+    private static native void nSetCaching(long displayList, boolean caching);
+    private static native void nSetClipToBounds(long displayList, boolean clipToBounds);
+    private static native void nSetAlpha(long displayList, float alpha);
+    private static native void nSetHasOverlappingRendering(long displayList,
             boolean hasOverlappingRendering);
-    private static native void nSetTranslationX(int displayList, float translationX);
-    private static native void nSetTranslationY(int displayList, float translationY);
-    private static native void nSetRotation(int displayList, float rotation);
-    private static native void nSetRotationX(int displayList, float rotationX);
-    private static native void nSetRotationY(int displayList, float rotationY);
-    private static native void nSetScaleX(int displayList, float scaleX);
-    private static native void nSetScaleY(int displayList, float scaleY);
-    private static native void nSetTransformationInfo(int displayList, float alpha,
+    private static native void nSetTranslationX(long displayList, float translationX);
+    private static native void nSetTranslationY(long displayList, float translationY);
+    private static native void nSetRotation(long displayList, float rotation);
+    private static native void nSetRotationX(long displayList, float rotationX);
+    private static native void nSetRotationY(long displayList, float rotationY);
+    private static native void nSetScaleX(long displayList, float scaleX);
+    private static native void nSetScaleY(long displayList, float scaleY);
+    private static native void nSetTransformationInfo(long displayList, float alpha,
             float translationX, float translationY, float rotation, float rotationX,
             float rotationY, float scaleX, float scaleY);
-    private static native void nSetStaticMatrix(int displayList, int nativeMatrix);
-    private static native void nSetAnimationMatrix(int displayList, int animationMatrix);
+    private static native void nSetStaticMatrix(long displayList, long nativeMatrix);
+    private static native void nSetAnimationMatrix(long displayList, long animationMatrix);
 
-    private static native boolean nHasOverlappingRendering(int displayList);
-    private static native void nGetMatrix(int displayList, int matrix);
-    private static native float nGetAlpha(int displayList);
-    private static native float nGetLeft(int displayList);
-    private static native float nGetTop(int displayList);
-    private static native float nGetRight(int displayList);
-    private static native float nGetBottom(int displayList);
-    private static native float nGetCameraDistance(int displayList);
-    private static native float nGetScaleX(int displayList);
-    private static native float nGetScaleY(int displayList);
-    private static native float nGetTranslationX(int displayList);
-    private static native float nGetTranslationY(int displayList);
-    private static native float nGetRotation(int displayList);
-    private static native float nGetRotationX(int displayList);
-    private static native float nGetRotationY(int displayList);
-    private static native float nGetPivotX(int displayList);
-    private static native float nGetPivotY(int displayList);
+    private static native boolean nHasOverlappingRendering(long displayList);
+    private static native void nGetMatrix(long displayList, long matrix);
+    private static native float nGetAlpha(long displayList);
+    private static native float nGetLeft(long displayList);
+    private static native float nGetTop(long displayList);
+    private static native float nGetRight(long displayList);
+    private static native float nGetBottom(long displayList);
+    private static native float nGetCameraDistance(long displayList);
+    private static native float nGetScaleX(long displayList);
+    private static native float nGetScaleY(long displayList);
+    private static native float nGetTranslationX(long displayList);
+    private static native float nGetTranslationY(long displayList);
+    private static native float nGetRotation(long displayList);
+    private static native float nGetRotationX(long displayList);
+    private static native float nGetRotationY(long displayList);
+    private static native float nGetPivotX(long displayList);
+    private static native float nGetPivotY(long displayList);
 
     ///////////////////////////////////////////////////////////////////////////
     // Finalization
     ///////////////////////////////////////////////////////////////////////////
 
     private static class DisplayListFinalizer {
-        final int mNativeDisplayList;
+        final long mNativeDisplayList;
 
-        public DisplayListFinalizer(int nativeDisplayList) {
+        public DisplayListFinalizer(long nativeDisplayList) {
             mNativeDisplayList = nativeDisplayList;
         }
 
diff --git a/core/java/android/view/GLES20Layer.java b/core/java/android/view/GLES20Layer.java
index 0e3311c..37154eb 100644
--- a/core/java/android/view/GLES20Layer.java
+++ b/core/java/android/view/GLES20Layer.java
@@ -24,7 +24,7 @@
  * An OpenGL ES 2.0 implementation of {@link HardwareLayer}.
  */
 abstract class GLES20Layer extends HardwareLayer {
-    int mLayer;
+    long mLayer;
     Finalizer mFinalizer;
 
     GLES20Layer() {
@@ -39,7 +39,7 @@
      * 
      * @return A pointer to the native layer object, or 0 if the object is NULL
      */
-    public int getLayer() {
+    public long getLayer() {
         return mLayer;
     }
 
@@ -75,9 +75,9 @@
     }
 
     static class Finalizer {
-        private int mLayerId;
+        private long mLayerId;
 
-        public Finalizer(int layerId) {
+        public Finalizer(long layerId) {
             mLayerId = layerId;
         }
 
diff --git a/core/java/android/view/GLES20RecordingCanvas.java b/core/java/android/view/GLES20RecordingCanvas.java
index b6fc38d..e3e1c76 100644
--- a/core/java/android/view/GLES20RecordingCanvas.java
+++ b/core/java/android/view/GLES20RecordingCanvas.java
@@ -58,7 +58,7 @@
         mDisplayList.clearReferences();
     }
 
-    int end(int nativeDisplayList) {
+    long end(long nativeDisplayList) {
         return getDisplayList(nativeDisplayList);
     }
 
diff --git a/core/java/android/view/GraphicBuffer.java b/core/java/android/view/GraphicBuffer.java
index 30c077c..5f2a9cd 100644
--- a/core/java/android/view/GraphicBuffer.java
+++ b/core/java/android/view/GraphicBuffer.java
@@ -56,7 +56,7 @@
     private final int mFormat;
     private final int mUsage;
     // Note: do not rename, this field is used by native code
-    private final int mNativeObject;
+    private final long mNativeObject;
 
     // These two fields are only used by lock/unlockCanvas()
     private Canvas mCanvas;
@@ -77,7 +77,7 @@
      * @return A <code>GraphicBuffer</code> instance or null
      */
     public static GraphicBuffer create(int width, int height, int format, int usage) {
-        int nativeObject = nCreateGraphicBuffer(width, height, format, usage);
+        long nativeObject = nCreateGraphicBuffer(width, height, format, usage);
         if (nativeObject != 0) {
             return new GraphicBuffer(width, height, format, usage, nativeObject);
         }
@@ -87,7 +87,7 @@
     /**
      * Private use only. See {@link #create(int, int, int, int)}.
      */
-    private GraphicBuffer(int width, int height, int format, int usage, int nativeObject) {
+    private GraphicBuffer(int width, int height, int format, int usage, long nativeObject) {
         mWidth = width;
         mHeight = height;
         mFormat = format;
@@ -271,7 +271,7 @@
             int height = in.readInt();
             int format = in.readInt();
             int usage = in.readInt();
-            int nativeObject = nReadGraphicBufferFromParcel(in);
+            long nativeObject = nReadGraphicBufferFromParcel(in);
             if (nativeObject != 0) {
                 return new GraphicBuffer(width, height, format, usage, nativeObject);
             }
@@ -283,10 +283,10 @@
         }
     };
 
-    private static native int nCreateGraphicBuffer(int width, int height, int format, int usage);
-    private static native void nDestroyGraphicBuffer(int nativeObject);
-    private static native void nWriteGraphicBufferToParcel(int nativeObject, Parcel dest);
-    private static native int nReadGraphicBufferFromParcel(Parcel in);
-    private static native boolean nLockCanvas(int nativeObject, Canvas canvas, Rect dirty);
-    private static native boolean nUnlockCanvasAndPost(int nativeObject, Canvas canvas);
+    private static native long nCreateGraphicBuffer(int width, int height, int format, int usage);
+    private static native void nDestroyGraphicBuffer(long nativeObject);
+    private static native void nWriteGraphicBufferToParcel(long nativeObject, Parcel dest);
+    private static native long nReadGraphicBufferFromParcel(Parcel in);
+    private static native boolean nLockCanvas(long nativeObject, Canvas canvas, Rect dirty);
+    private static native boolean nUnlockCanvasAndPost(long nativeObject, Canvas canvas);
 }
diff --git a/core/java/android/view/HardwareCanvas.java b/core/java/android/view/HardwareCanvas.java
index 259e1cd..10f700c 100644
--- a/core/java/android/view/HardwareCanvas.java
+++ b/core/java/android/view/HardwareCanvas.java
@@ -145,7 +145,7 @@
      *
      * @hide
      */
-    public int callDrawGLFunction(int drawGLFunction) {
+    public int callDrawGLFunction(long drawGLFunction) {
         // Noop - this is done in the display list recorder subclass
         return DisplayList.STATUS_DONE;
     }
@@ -170,12 +170,12 @@
      * @param functor The native functor to remove from the execution queue.
      *
      * @see #invokeFunctors(android.graphics.Rect)
-     * @see #callDrawGLFunction(int)
-     * @see #detachFunctor(int)
+     * @see #callDrawGLFunction(long)
+     * @see #detachFunctor(long)
      *
      * @hide
      */
-    abstract void detachFunctor(int functor);
+    abstract void detachFunctor(long functor);
 
     /**
      * Attaches the specified functor to the current functor execution queue.
@@ -183,12 +183,12 @@
      * @param functor The native functor to add to the execution queue.
      *
      * @see #invokeFunctors(android.graphics.Rect)
-     * @see #callDrawGLFunction(int)
-     * @see #detachFunctor(int)
+     * @see #callDrawGLFunction(long)
+     * @see #detachFunctor(long)
      *
      * @hide
      */
-    abstract void attachFunctor(int functor);
+    abstract void attachFunctor(long functor);
 
     /**
      * Indicates that the specified layer must be updated as soon as possible.
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index f215189..3781bdb 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -568,7 +568,7 @@
      * @see HardwareCanvas#callDrawGLFunction(int)
      * @see #attachFunctor(android.view.View.AttachInfo, int)
      */
-    abstract void detachFunctor(int functor);
+    abstract void detachFunctor(long functor);
 
     /**
      * Schedules the specified functor in the functors execution queue.
@@ -581,7 +581,7 @@
      *
      * @return true if the functor was attached successfully
      */
-    abstract boolean attachFunctor(View.AttachInfo attachInfo, int functor);
+    abstract boolean attachFunctor(View.AttachInfo attachInfo, long functor);
 
     /**
      * Initializes the hardware renderer for the specified surface and setup the
@@ -1712,14 +1712,14 @@
         }
 
         @Override
-        void detachFunctor(int functor) {
+        void detachFunctor(long functor) {
             if (mCanvas != null) {
                 mCanvas.detachFunctor(functor);
             }
         }
 
         @Override
-        boolean attachFunctor(View.AttachInfo attachInfo, int functor) {
+        boolean attachFunctor(View.AttachInfo attachInfo, long functor) {
             if (mCanvas != null) {
                 mCanvas.attachFunctor(functor);
                 mFunctorsRunnable.attachInfo = attachInfo;
diff --git a/core/java/android/view/InputChannel.java b/core/java/android/view/InputChannel.java
index 40ee1ad..de195ae 100644
--- a/core/java/android/view/InputChannel.java
+++ b/core/java/android/view/InputChannel.java
@@ -46,7 +46,7 @@
     };
     
     @SuppressWarnings("unused")
-    private int mPtr; // used by native code
+    private long mPtr; // used by native code
     
     private static native InputChannel[] nativeOpenInputChannelPair(String name);
     
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java
index e829116..0b12cbe 100644
--- a/core/java/android/view/InputDevice.java
+++ b/core/java/android/view/InputDevice.java
@@ -17,6 +17,7 @@
 package android.view;
 
 import android.content.Context;
+import android.hardware.input.InputDeviceIdentifier;
 import android.hardware.input.InputManager;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -49,6 +50,7 @@
     private final int mVendorId;
     private final int mProductId;
     private final String mDescriptor;
+    private final InputDeviceIdentifier mIdentifier;
     private final boolean mIsExternal;
     private final int mSources;
     private final int mKeyboardType;
@@ -61,7 +63,7 @@
 
     /**
      * A mask for input source classes.
-     * 
+     *
      * Each distinct input source constant has one or more input source class bits set to
      * specify the desired interpretation for its input events.
      */
@@ -77,46 +79,46 @@
     /**
      * The input source has buttons or keys.
      * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
-     * 
+     *
      * A {@link KeyEvent} should be interpreted as a button or key press.
-     * 
+     *
      * Use {@link #getKeyCharacterMap} to query the device's button and key mappings.
      */
     public static final int SOURCE_CLASS_BUTTON = 0x00000001;
-    
+
     /**
      * The input source is a pointing device associated with a display.
      * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
-     * 
+     *
      * A {@link MotionEvent} should be interpreted as absolute coordinates in
      * display units according to the {@link View} hierarchy.  Pointer down/up indicated when
      * the finger touches the display or when the selection button is pressed/released.
-     * 
+     *
      * Use {@link #getMotionRange} to query the range of the pointing device.  Some devices permit
      * touches outside the display area so the effective range may be somewhat smaller or larger
      * than the actual display size.
      */
     public static final int SOURCE_CLASS_POINTER = 0x00000002;
-    
+
     /**
      * The input source is a trackball navigation device.
      * Examples: {@link #SOURCE_TRACKBALL}.
-     * 
+     *
      * A {@link MotionEvent} should be interpreted as relative movements in device-specific
      * units used for navigation purposes.  Pointer down/up indicates when the selection button
      * is pressed/released.
-     * 
+     *
      * Use {@link #getMotionRange} to query the range of motion.
      */
     public static final int SOURCE_CLASS_TRACKBALL = 0x00000004;
-    
+
     /**
      * The input source is an absolute positioning device not associated with a display
      * (unlike {@link #SOURCE_CLASS_POINTER}).
-     * 
+     *
      * A {@link MotionEvent} should be interpreted as absolute coordinates in
      * device-specific surface units.
-     * 
+     *
      * Use {@link #getMotionRange} to query the range of positions.
      */
     public static final int SOURCE_CLASS_POSITION = 0x00000008;
@@ -134,7 +136,7 @@
      * The input source is unknown.
      */
     public static final int SOURCE_UNKNOWN = 0x00000000;
-    
+
     /**
      * The input source is a keyboard.
      *
@@ -145,10 +147,10 @@
      * @see #SOURCE_CLASS_BUTTON
      */
     public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON;
-    
+
     /**
      * The input source is a DPad.
-     * 
+     *
      * @see #SOURCE_CLASS_BUTTON
      */
     public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON;
@@ -163,16 +165,16 @@
 
     /**
      * The input source is a touch screen pointing device.
-     * 
+     *
      * @see #SOURCE_CLASS_POINTER
      */
     public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER;
-    
+
     /**
      * The input source is a mouse pointing device.
      * This code is also used for other mouse-like pointing devices such as trackpads
      * and trackpoints.
-     * 
+     *
      * @see #SOURCE_CLASS_POINTER
      */
     public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;
@@ -199,15 +201,15 @@
 
     /**
      * The input source is a trackball.
-     * 
+     *
      * @see #SOURCE_CLASS_TRACKBALL
      */
     public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL;
-    
+
     /**
      * The input source is a touch pad or digitizer tablet that is not
      * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}).
-     * 
+     *
      * @see #SOURCE_CLASS_POSITION
      */
     public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION;
@@ -239,7 +241,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_X} instead.
      */
@@ -248,7 +250,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_Y} instead.
      */
@@ -257,7 +259,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead.
      */
@@ -266,7 +268,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_SIZE} instead.
      */
@@ -275,7 +277,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead.
      */
@@ -284,7 +286,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead.
      */
@@ -293,7 +295,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} instead.
      */
@@ -302,7 +304,7 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} instead.
      */
@@ -311,24 +313,24 @@
 
     /**
      * Constant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}.
-     * 
+     *
      * @see #getMotionRange
      * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} instead.
      */
     @Deprecated
     public static final int MOTION_RANGE_ORIENTATION = MotionEvent.AXIS_ORIENTATION;
-    
+
     /**
      * There is no keyboard.
      */
     public static final int KEYBOARD_TYPE_NONE = 0;
-    
+
     /**
      * The keyboard is not fully alphabetic.  It may be a numeric keypad or an assortment
      * of buttons that are not mapped as alphabetic keys suitable for text input.
      */
     public static final int KEYBOARD_TYPE_NON_ALPHABETIC = 1;
-    
+
     /**
      * The keyboard supports a complement of alphabetic keys.
      */
@@ -361,6 +363,7 @@
         mKeyCharacterMap = keyCharacterMap;
         mHasVibrator = hasVibrator;
         mHasButtonUnderPad = hasButtonUnderPad;
+        mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId);
     }
 
     private InputDevice(Parcel in) {
@@ -377,6 +380,7 @@
         mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
         mHasVibrator = in.readInt() != 0;
         mHasButtonUnderPad = in.readInt() != 0;
+        mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId);
 
         for (;;) {
             int axis = in.readInt();
@@ -396,7 +400,7 @@
     public static InputDevice getDevice(int id) {
         return InputManager.getInstance().getInputDevice(id);
     }
-    
+
     /**
      * Gets the ids of all input devices in the system.
      * @return The input device ids.
@@ -441,6 +445,18 @@
     }
 
     /**
+     * The set of identifying information for type of input device. This
+     * information can be used by the system to configure appropriate settings
+     * for the device.
+     *
+     * @return The identifier object for this device
+     * @hide
+     */
+    public InputDeviceIdentifier getIdentifier() {
+        return mIdentifier;
+    }
+
+    /**
      * Gets a generation number for this input device.
      * The generation number is incremented whenever the device is reconfigured and its
      * properties may have changed.
@@ -553,7 +569,7 @@
     public String getName() {
         return mName;
     }
-    
+
     /**
      * Gets the input sources supported by this input device as a combined bitfield.
      * @return The supported input sources.
@@ -561,7 +577,7 @@
     public int getSources() {
         return mSources;
     }
-    
+
     /**
      * Gets the keyboard type.
      * @return The keyboard type.
@@ -569,7 +585,7 @@
     public int getKeyboardType() {
         return mKeyboardType;
     }
-    
+
     /**
      * Gets the key character map associated with this input device.
      * @return The key character map.
diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java
index 25972e7..91ef50d 100644
--- a/core/java/android/view/InputEventReceiver.java
+++ b/core/java/android/view/InputEventReceiver.java
@@ -34,7 +34,7 @@
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
-    private int mReceiverPtr;
+    private long mReceiverPtr;
 
     // We keep references to the input channel and message queue objects here so that
     // they are not GC'd while the native peer of the receiver is using them.
@@ -44,11 +44,11 @@
     // Map from InputEvent sequence numbers to dispatcher sequence numbers.
     private final SparseIntArray mSeqMap = new SparseIntArray();
 
-    private static native int nativeInit(WeakReference<InputEventReceiver> receiver,
+    private static native long nativeInit(WeakReference<InputEventReceiver> receiver,
             InputChannel inputChannel, MessageQueue messageQueue);
-    private static native void nativeDispose(int receiverPtr);
-    private static native void nativeFinishInputEvent(int receiverPtr, int seq, boolean handled);
-    private static native boolean nativeConsumeBatchedInputEvents(int receiverPtr,
+    private static native void nativeDispose(long receiverPtr);
+    private static native void nativeFinishInputEvent(long receiverPtr, int seq, boolean handled);
+    private static native boolean nativeConsumeBatchedInputEvents(long receiverPtr,
             long frameTimeNanos);
 
     /**
diff --git a/core/java/android/view/InputEventSender.java b/core/java/android/view/InputEventSender.java
index be6a623..304ea3f 100644
--- a/core/java/android/view/InputEventSender.java
+++ b/core/java/android/view/InputEventSender.java
@@ -33,18 +33,18 @@
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
-    private int mSenderPtr;
+    private long mSenderPtr;
 
     // We keep references to the input channel and message queue objects here so that
     // they are not GC'd while the native peer of the receiver is using them.
     private InputChannel mInputChannel;
     private MessageQueue mMessageQueue;
 
-    private static native int nativeInit(WeakReference<InputEventSender> sender,
+    private static native long nativeInit(WeakReference<InputEventSender> sender,
             InputChannel inputChannel, MessageQueue messageQueue);
-    private static native void nativeDispose(int senderPtr);
-    private static native boolean nativeSendKeyEvent(int senderPtr, int seq, KeyEvent event);
-    private static native boolean nativeSendMotionEvent(int senderPtr, int seq, MotionEvent event);
+    private static native void nativeDispose(long senderPtr);
+    private static native boolean nativeSendKeyEvent(long senderPtr, int seq, KeyEvent event);
+    private static native boolean nativeSendMotionEvent(long senderPtr, int seq, MotionEvent event);
 
     /**
      * Creates an input event sender bound to the specified input channel.
diff --git a/core/java/android/view/InputQueue.java b/core/java/android/view/InputQueue.java
index e3de89d..d5cec49 100644
--- a/core/java/android/view/InputQueue.java
+++ b/core/java/android/view/InputQueue.java
@@ -23,7 +23,7 @@
 import android.os.MessageQueue;
 import android.util.Pools.Pool;
 import android.util.Pools.SimplePool;
-import android.util.SparseArray;
+import android.util.LongSparseArray;
 
 import java.lang.ref.WeakReference;
 
@@ -32,20 +32,20 @@
  * input events.  Currently only usable from native code.
  */
 public final class InputQueue {
-    private final SparseArray<ActiveInputEvent> mActiveEventArray =
-            new SparseArray<ActiveInputEvent>(20);
+    private final LongSparseArray<ActiveInputEvent> mActiveEventArray =
+            new LongSparseArray<ActiveInputEvent>(20);
     private final Pool<ActiveInputEvent> mActiveInputEventPool =
             new SimplePool<ActiveInputEvent>(20);
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
 
-    private int mPtr;
+    private long mPtr;
 
-    private static native int nativeInit(WeakReference<InputQueue> weakQueue,
+    private static native long nativeInit(WeakReference<InputQueue> weakQueue,
             MessageQueue messageQueue);
-    private static native int nativeSendKeyEvent(int ptr, KeyEvent e, boolean preDispatch);
-    private static native int nativeSendMotionEvent(int ptr, MotionEvent e);
-    private static native void nativeDispose(int ptr);
+    private static native long nativeSendKeyEvent(long ptr, KeyEvent e, boolean preDispatch);
+    private static native long nativeSendMotionEvent(long ptr, MotionEvent e);
+    private static native void nativeDispose(long ptr);
 
     /** @hide */
     public InputQueue() {
@@ -84,7 +84,7 @@
     }
 
     /** @hide */
-    public int getNativePtr() {
+    public long getNativePtr() {
         return mPtr;
     }
 
@@ -92,7 +92,7 @@
     public void sendInputEvent(InputEvent e, Object token, boolean predispatch,
             FinishedInputEventCallback callback) {
         ActiveInputEvent event = obtainActiveInputEvent(token, callback);
-        int id;
+        long id;
         if (e instanceof KeyEvent) {
             id = nativeSendKeyEvent(mPtr, (KeyEvent) e, predispatch);
         } else {
@@ -101,7 +101,7 @@
         mActiveEventArray.put(id, event);
     }
 
-    private void finishInputEvent(int id, boolean handled) {
+    private void finishInputEvent(long id, boolean handled) {
         int index = mActiveEventArray.indexOfKey(id);
         if (index >= 0) {
             ActiveInputEvent e = mActiveEventArray.valueAt(index);
diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java
index 9e5f25a..55dd6bb 100644
--- a/core/java/android/view/KeyCharacterMap.java
+++ b/core/java/android/view/KeyCharacterMap.java
@@ -282,20 +282,20 @@
         }
     };
 
-    private int mPtr;
+    private long mPtr;
 
-    private static native int nativeReadFromParcel(Parcel in);
-    private static native void nativeWriteToParcel(int ptr, Parcel out);
-    private static native void nativeDispose(int ptr);
+    private static native long nativeReadFromParcel(Parcel in);
+    private static native void nativeWriteToParcel(long ptr, Parcel out);
+    private static native void nativeDispose(long ptr);
 
-    private static native char nativeGetCharacter(int ptr, int keyCode, int metaState);
-    private static native boolean nativeGetFallbackAction(int ptr, int keyCode, int metaState,
+    private static native char nativeGetCharacter(long ptr, int keyCode, int metaState);
+    private static native boolean nativeGetFallbackAction(long ptr, int keyCode, int metaState,
             FallbackAction outFallbackAction);
-    private static native char nativeGetNumber(int ptr, int keyCode);
-    private static native char nativeGetMatch(int ptr, int keyCode, char[] chars, int metaState);
-    private static native char nativeGetDisplayLabel(int ptr, int keyCode);
-    private static native int nativeGetKeyboardType(int ptr);
-    private static native KeyEvent[] nativeGetEvents(int ptr, char[] chars);
+    private static native char nativeGetNumber(long ptr, int keyCode);
+    private static native char nativeGetMatch(long ptr, int keyCode, char[] chars, int metaState);
+    private static native char nativeGetDisplayLabel(long ptr, int keyCode);
+    private static native int nativeGetKeyboardType(long ptr);
+    private static native KeyEvent[] nativeGetEvents(long ptr, char[] chars);
 
     private KeyCharacterMap(Parcel in) {
         if (in == null) {
@@ -308,7 +308,7 @@
     }
 
     // Called from native
-    private KeyCharacterMap(int ptr) {
+    private KeyCharacterMap(long ptr) {
         mPtr = ptr;
     }
 
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index 5a5fc10..6a6c127 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -629,11 +629,19 @@
     /** Key code constant: Brightness Up key.
      * Adjusts the screen brightness up. */
     public static final int KEYCODE_BRIGHTNESS_UP   = 221;
-    /** Key code constant: Audio Track key
+    /** Key code constant: Audio Track key.
      * Switches the audio tracks. */
     public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222;
+    /** Key code constant: Sleep key.
+     * Puts the device to sleep.  Behaves somewhat like {@link #KEYCODE_POWER} but it
+     * has no effect if the device is already asleep. */
+    public static final int KEYCODE_SLEEP           = 223;
+    /** Key code constant: Wakeup key.
+     * Wakes up the device.  Behaves somewhat like {@link #KEYCODE_POWER} but it
+     * has no effect if the device is already awake. */
+    public static final int KEYCODE_WAKEUP          = 224;
 
-    private static final int LAST_KEYCODE           = KEYCODE_MEDIA_AUDIO_TRACK;
+    private static final int LAST_KEYCODE = KEYCODE_WAKEUP;
 
     // NOTE: If you add a new keycode here you must also add it to:
     //  isSystem()
@@ -878,6 +886,8 @@
         names.append(KEYCODE_BRIGHTNESS_DOWN, "KEYCODE_BRIGHTNESS_DOWN");
         names.append(KEYCODE_BRIGHTNESS_UP, "KEYCODE_BRIGHTNESS_UP");
         names.append(KEYCODE_MEDIA_AUDIO_TRACK, "KEYCODE_MEDIA_AUDIO_TRACK");
+        names.append(KEYCODE_SLEEP, "KEYCODE_SLEEP");
+        names.append(KEYCODE_WAKEUP, "KEYCODE_WAKEUP");
     };
 
     // Symbolic names of all metakeys in bit order from least significant to most significant.
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index db577f3..ddce3ce 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -1311,63 +1311,63 @@
     }
 
     // Pointer to the native MotionEvent object that contains the actual data.
-    private int mNativePtr;
+    private long mNativePtr;
 
     private MotionEvent mNext;
 
-    private static native int nativeInitialize(int nativePtr,
+    private static native long nativeInitialize(long nativePtr,
             int deviceId, int source, int action, int flags, int edgeFlags,
             int metaState, int buttonState,
             float xOffset, float yOffset, float xPrecision, float yPrecision,
             long downTimeNanos, long eventTimeNanos,
             int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
-    private static native int nativeCopy(int destNativePtr, int sourceNativePtr,
+    private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
             boolean keepHistory);
-    private static native void nativeDispose(int nativePtr);
-    private static native void nativeAddBatch(int nativePtr, long eventTimeNanos,
+    private static native void nativeDispose(long nativePtr);
+    private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
             PointerCoords[] pointerCoords, int metaState);
 
-    private static native int nativeGetDeviceId(int nativePtr);
-    private static native int nativeGetSource(int nativePtr);
-    private static native int nativeSetSource(int nativePtr, int source);
-    private static native int nativeGetAction(int nativePtr);
-    private static native void nativeSetAction(int nativePtr, int action);
-    private static native boolean nativeIsTouchEvent(int nativePtr);
-    private static native int nativeGetFlags(int nativePtr);
-    private static native void nativeSetFlags(int nativePtr, int flags);
-    private static native int nativeGetEdgeFlags(int nativePtr);
-    private static native void nativeSetEdgeFlags(int nativePtr, int action);
-    private static native int nativeGetMetaState(int nativePtr);
-    private static native int nativeGetButtonState(int nativePtr);
-    private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY);
-    private static native float nativeGetXOffset(int nativePtr);
-    private static native float nativeGetYOffset(int nativePtr);
-    private static native float nativeGetXPrecision(int nativePtr);
-    private static native float nativeGetYPrecision(int nativePtr);
-    private static native long nativeGetDownTimeNanos(int nativePtr);
-    private static native void nativeSetDownTimeNanos(int nativePtr, long downTime);
+    private static native int nativeGetDeviceId(long nativePtr);
+    private static native int nativeGetSource(long nativePtr);
+    private static native int nativeSetSource(long nativePtr, int source);
+    private static native int nativeGetAction(long nativePtr);
+    private static native void nativeSetAction(long nativePtr, int action);
+    private static native boolean nativeIsTouchEvent(long nativePtr);
+    private static native int nativeGetFlags(long nativePtr);
+    private static native void nativeSetFlags(long nativePtr, int flags);
+    private static native int nativeGetEdgeFlags(long nativePtr);
+    private static native void nativeSetEdgeFlags(long nativePtr, int action);
+    private static native int nativeGetMetaState(long nativePtr);
+    private static native int nativeGetButtonState(long nativePtr);
+    private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
+    private static native float nativeGetXOffset(long nativePtr);
+    private static native float nativeGetYOffset(long nativePtr);
+    private static native float nativeGetXPrecision(long nativePtr);
+    private static native float nativeGetYPrecision(long nativePtr);
+    private static native long nativeGetDownTimeNanos(long nativePtr);
+    private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
 
-    private static native int nativeGetPointerCount(int nativePtr);
-    private static native int nativeGetPointerId(int nativePtr, int pointerIndex);
-    private static native int nativeGetToolType(int nativePtr, int pointerIndex);
-    private static native int nativeFindPointerIndex(int nativePtr, int pointerId);
+    private static native int nativeGetPointerCount(long nativePtr);
+    private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
+    private static native int nativeGetToolType(long nativePtr, int pointerIndex);
+    private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
 
-    private static native int nativeGetHistorySize(int nativePtr);
-    private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos);
-    private static native float nativeGetRawAxisValue(int nativePtr,
+    private static native int nativeGetHistorySize(long nativePtr);
+    private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
+    private static native float nativeGetRawAxisValue(long nativePtr,
             int axis, int pointerIndex, int historyPos);
-    private static native float nativeGetAxisValue(int nativePtr,
+    private static native float nativeGetAxisValue(long nativePtr,
             int axis, int pointerIndex, int historyPos);
-    private static native void nativeGetPointerCoords(int nativePtr,
+    private static native void nativeGetPointerCoords(long nativePtr,
             int pointerIndex, int historyPos, PointerCoords outPointerCoords);
-    private static native void nativeGetPointerProperties(int nativePtr,
+    private static native void nativeGetPointerProperties(long nativePtr,
             int pointerIndex, PointerProperties outPointerProperties);
 
-    private static native void nativeScale(int nativePtr, float scale);
-    private static native void nativeTransform(int nativePtr, Matrix matrix);
+    private static native void nativeScale(long nativePtr, float scale);
+    private static native void nativeTransform(long nativePtr, Matrix matrix);
 
-    private static native int nativeReadFromParcel(int nativePtr, Parcel parcel);
-    private static native void nativeWriteToParcel(int nativePtr, Parcel parcel);
+    private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
+    private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
 
     private MotionEvent() {
     }
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 1bfda2d..91645e7 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -32,19 +32,19 @@
 public class Surface implements Parcelable {
     private static final String TAG = "Surface";
 
-    private static native int nativeCreateFromSurfaceTexture(SurfaceTexture surfaceTexture)
+    private static native long nativeCreateFromSurfaceTexture(SurfaceTexture surfaceTexture)
             throws OutOfResourcesException;
-    private static native int nativeCreateFromSurfaceControl(int surfaceControlNativeObject);
+    private static native long nativeCreateFromSurfaceControl(long surfaceControlNativeObject);
 
-    private static native int nativeLockCanvas(int nativeObject, Canvas canvas, Rect dirty)
+    private static native long nativeLockCanvas(long nativeObject, Canvas canvas, Rect dirty)
             throws OutOfResourcesException;
-    private static native void nativeUnlockCanvasAndPost(int nativeObject, Canvas canvas);
+    private static native void nativeUnlockCanvasAndPost(long nativeObject, Canvas canvas);
 
-    private static native void nativeRelease(int nativeObject);
-    private static native boolean nativeIsValid(int nativeObject);
-    private static native boolean nativeIsConsumerRunningBehind(int nativeObject);
-    private static native int nativeReadFromParcel(int nativeObject, Parcel source);
-    private static native void nativeWriteToParcel(int nativeObject, Parcel dest);
+    private static native void nativeRelease(long nativeObject);
+    private static native boolean nativeIsValid(long nativeObject);
+    private static native boolean nativeIsConsumerRunningBehind(long nativeObject);
+    private static native long nativeReadFromParcel(long nativeObject, Parcel source);
+    private static native void nativeWriteToParcel(long nativeObject, Parcel dest);
 
     public static final Parcelable.Creator<Surface> CREATOR =
             new Parcelable.Creator<Surface>() {
@@ -71,8 +71,8 @@
     // Guarded state.
     final Object mLock = new Object(); // protects the native state
     private String mName;
-    int mNativeObject; // package scope only for SurfaceControl access
-    private int mLockedObject;
+    long mNativeObject; // package scope only for SurfaceControl access
+    private long mLockedObject;
     private int mGenerationId; // incremented each time mNativeObject changes
     private final Canvas mCanvas = new CompatibleCanvas();
 
@@ -130,7 +130,7 @@
     }
 
     /* called from android_view_Surface_createFromIGraphicBufferProducer() */
-    private Surface(int nativeObject) {
+    private Surface(long nativeObject) {
         synchronized (mLock) {
             setNativeObjectLocked(nativeObject);
         }
@@ -261,8 +261,8 @@
             checkNotReleasedLocked();
             if (mNativeObject != mLockedObject) {
                 Log.w(TAG, "WARNING: Surface's mNativeObject (0x" +
-                        Integer.toHexString(mNativeObject) + ") != mLockedObject (0x" +
-                        Integer.toHexString(mLockedObject) +")");
+                        Long.toHexString(mNativeObject) + ") != mLockedObject (0x" +
+                        Long.toHexString(mLockedObject) +")");
             }
             if (mLockedObject == 0) {
                 throw new IllegalStateException("Surface was not locked");
@@ -307,12 +307,12 @@
             throw new IllegalArgumentException("other must not be null");
         }
 
-        int surfaceControlPtr = other.mNativeObject;
+        long surfaceControlPtr = other.mNativeObject;
         if (surfaceControlPtr == 0) {
             throw new NullPointerException(
                     "SurfaceControl native object is null. Are you using a released SurfaceControl?");
         }
-        int newNativeObject = nativeCreateFromSurfaceControl(surfaceControlPtr);
+        long newNativeObject = nativeCreateFromSurfaceControl(surfaceControlPtr);
 
         synchronized (mLock) {
             if (mNativeObject != 0) {
@@ -334,7 +334,7 @@
             throw new IllegalArgumentException("other must not be null");
         }
         if (other != this) {
-            final int newPtr;
+            final long newPtr;
             synchronized (other.mLock) {
                 newPtr = other.mNativeObject;
                 other.setNativeObjectLocked(0);
@@ -391,7 +391,7 @@
         }
     }
 
-    private void setNativeObjectLocked(int ptr) {
+    private void setNativeObjectLocked(long ptr) {
         if (mNativeObject != ptr) {
             if (mNativeObject == 0 && ptr != 0) {
                 mCloseGuard.open("release");
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index b22d5cf..eea5884 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -33,11 +33,11 @@
 public class SurfaceControl {
     private static final String TAG = "SurfaceControl";
 
-    private static native int nativeCreate(SurfaceSession session, String name,
+    private static native long nativeCreate(SurfaceSession session, String name,
             int w, int h, int format, int flags)
             throws OutOfResourcesException;
-    private static native void nativeRelease(int nativeObject);
-    private static native void nativeDestroy(int nativeObject);
+    private static native void nativeRelease(long nativeObject);
+    private static native void nativeDestroy(long nativeObject);
 
     private static native Bitmap nativeScreenshot(IBinder displayToken,
             int width, int height, int minLayer, int maxLayer, boolean allLayers);
@@ -48,21 +48,21 @@
     private static native void nativeCloseTransaction();
     private static native void nativeSetAnimationTransaction();
 
-    private static native void nativeSetLayer(int nativeObject, int zorder);
-    private static native void nativeSetPosition(int nativeObject, float x, float y);
-    private static native void nativeSetSize(int nativeObject, int w, int h);
-    private static native void nativeSetTransparentRegionHint(int nativeObject, Region region);
-    private static native void nativeSetAlpha(int nativeObject, float alpha);
-    private static native void nativeSetMatrix(int nativeObject, float dsdx, float dtdx, float dsdy, float dtdy);
-    private static native void nativeSetFlags(int nativeObject, int flags, int mask);
-    private static native void nativeSetWindowCrop(int nativeObject, int l, int t, int r, int b);
-    private static native void nativeSetLayerStack(int nativeObject, int layerStack);
+    private static native void nativeSetLayer(long nativeObject, int zorder);
+    private static native void nativeSetPosition(long nativeObject, float x, float y);
+    private static native void nativeSetSize(long nativeObject, int w, int h);
+    private static native void nativeSetTransparentRegionHint(long nativeObject, Region region);
+    private static native void nativeSetAlpha(long nativeObject, float alpha);
+    private static native void nativeSetMatrix(long nativeObject, float dsdx, float dtdx, float dsdy, float dtdy);
+    private static native void nativeSetFlags(long nativeObject, int flags, int mask);
+    private static native void nativeSetWindowCrop(long nativeObject, int l, int t, int r, int b);
+    private static native void nativeSetLayerStack(long nativeObject, int layerStack);
 
     private static native IBinder nativeGetBuiltInDisplay(int physicalDisplayId);
     private static native IBinder nativeCreateDisplay(String name, boolean secure);
     private static native void nativeDestroyDisplay(IBinder displayToken);
     private static native void nativeSetDisplaySurface(
-            IBinder displayToken, int nativeSurfaceObject);
+            IBinder displayToken, long nativeSurfaceObject);
     private static native void nativeSetDisplayLayerStack(
             IBinder displayToken, int layerStack);
     private static native void nativeSetDisplayProjection(
@@ -77,10 +77,7 @@
 
     private final CloseGuard mCloseGuard = CloseGuard.get();
     private final String mName;
-    int mNativeObject; // package visibility only for Surface.java access
-
-    private static final boolean HEADLESS = "1".equals(
-        SystemProperties.get("ro.config.headless", "0"));
+    long mNativeObject; // package visibility only for Surface.java access
 
     /* flags used in constructor (keep in sync with ISurfaceComposerClient.h) */
 
@@ -106,18 +103,18 @@
      * surfaces are pre-multiplied, which means that each color component is
      * already multiplied by its alpha value. In this case the blending
      * equation used is:
-     *
-     *    DEST = SRC + DEST * (1-SRC_ALPHA)
-     *
+     * <p>
+     *    <code>DEST = SRC + DEST * (1-SRC_ALPHA)</code>
+     * <p>
      * By contrast, non pre-multiplied surfaces use the following equation:
-     *
-     *    DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)
-     *
+     * <p>
+     *    <code>DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA)</code>
+     * <p>
      * pre-multiplied surfaces must always be used if transparent pixels are
      * composited on top of each-other into the surface. A pre-multiplied
      * surface can never lower the value of the alpha component of a given
      * pixel.
-     *
+     * <p>
      * In some rare situations, a non pre-multiplied surface is preferable.
      *
      */
@@ -128,7 +125,17 @@
      * even if its pixel format is set to translucent. This can be useful if an
      * application needs full RGBA 8888 support for instance but will
      * still draw every pixel opaque.
-     *
+     * <p>
+     * This flag is ignored if setAlpha() is used to make the surface non-opaque.
+     * Combined effects are (assuming a buffer format with an alpha channel):
+     * <ul>
+     * <li>OPAQUE + alpha(1.0) == opaque composition
+     * <li>OPAQUE + alpha(0.x) == blended composition
+     * <li>!OPAQUE + alpha(1.0) == blended composition
+     * <li>!OPAQUE + alpha(0.x) == blended composition
+     * </ul>
+     * If the underlying buffer lacks an alpha channel, the OPAQUE flag is effectively
+     * set automatically.
      */
     public static final int OPAQUE = 0x00000400;
 
@@ -169,9 +176,16 @@
     /**
      * Surface flag: Hide the surface.
      * Equivalent to calling hide().
+     * Updates the value set during Surface creation (see {@link #HIDDEN}).
      */
     public static final int SURFACE_HIDDEN = 0x01;
 
+    /**
+     * Surface flag: composite without blending when possible.
+     * Updates the value set during Surface creation (see {@link #OPAQUE}).
+     */
+    public static final int SURFACE_OPAQUE = 0x02;
+
 
     /* built-in physical display ids (keep in sync with ISurfaceComposer.h)
      * these are different from the logical display ids used elsewhere in the framework */
@@ -192,14 +206,14 @@
 
     /**
      * Create a surface with a name.
-     *
+     * <p>
      * The surface creation flags specify what kind of surface to create and
      * certain options such as whether the surface can be assumed to be opaque
      * and whether it should be initially hidden.  Surfaces should always be
      * created with the {@link #HIDDEN} flag set to ensure that they are not
      * made visible prematurely before all of the surface's properties have been
      * configured.
-     *
+     * <p>
      * Good practice is to first create the surface with the {@link #HIDDEN} flag
      * specified, open a transaction, set the surface layer, layer stack, alpha,
      * and position, call {@link #show} if appropriate, and close the transaction.
@@ -232,8 +246,6 @@
                     new Throwable());
         }
 
-        checkHeadless();
-
         mName = name;
         mNativeObject = nativeCreate(session, name, w, h, format, flags);
         if (mNativeObject == 0) {
@@ -344,6 +356,10 @@
         nativeSetTransparentRegionHint(mNativeObject, region);
     }
 
+    /**
+     * Sets an alpha value for the entire Surface.  This value is combined with the
+     * per-pixel alpha.  It may be used with opaque Surfaces.
+     */
     public void setAlpha(float alpha) {
         checkNotReleased();
         nativeSetAlpha(mNativeObject, alpha);
@@ -354,6 +370,13 @@
         nativeSetMatrix(mNativeObject, dsdx, dtdx, dsdy, dtdy);
     }
 
+    /**
+     * Sets and clears flags, such as {@link #SURFACE_HIDDEN}.  The new value will be:
+     * <p>
+     *   <code>newFlags = (oldFlags & ~mask) | (flags & mask)</code>
+     * <p>
+     * Note this does not take the same set of flags as the constructor.
+     */
     public void setFlags(int flags, int mask) {
         checkNotReleased();
         nativeSetFlags(mNativeObject, flags, mask);
@@ -374,6 +397,19 @@
         nativeSetLayerStack(mNativeObject, layerStack);
     }
 
+    /**
+     * Sets the opacity of the surface.  Setting the flag is equivalent to creating the
+     * Surface with the {@link #OPAQUE} flag.
+     */
+    public void setOpaque(boolean isOpaque) {
+        checkNotReleased();
+        if (isOpaque) {
+            nativeSetFlags(mNativeObject, SURFACE_OPAQUE, SURFACE_OPAQUE);
+        } else {
+            nativeSetFlags(mNativeObject, 0, SURFACE_OPAQUE);
+        }
+    }
+
     /*
      * set display parameters.
      * needs to be inside open/closeTransaction block
@@ -619,10 +655,4 @@
         }
         nativeScreenshot(display, consumer, width, height, minLayer, maxLayer, allLayers);
     }
-
-    private static void checkHeadless() {
-        if (HEADLESS) {
-            throw new UnsupportedOperationException("Device is headless");
-        }
-    }
 }
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 47f7628..b78af2e 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -127,7 +127,7 @@
     private final Object[] mNativeWindowLock = new Object[0];
     // Used from native code, do not write!
     @SuppressWarnings({"UnusedDeclaration"})
-    private int mNativeWindow;
+    private long mNativeWindow;
 
     /**
      * Creates a new TextureView.
@@ -816,6 +816,6 @@
     private native void nCreateNativeWindow(SurfaceTexture surface);
     private native void nDestroyNativeWindow();
 
-    private static native boolean nLockCanvas(int nativeWindow, Canvas canvas, Rect dirty);
-    private static native void nUnlockCanvasAndPost(int nativeWindow, Canvas canvas);
+    private static native boolean nLockCanvas(long nativeWindow, Canvas canvas, Rect dirty);
+    private static native void nUnlockCanvasAndPost(long nativeWindow, Canvas canvas);
 }
diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java
index eb81f72..22b5cca 100644
--- a/core/java/android/view/VelocityTracker.java
+++ b/core/java/android/view/VelocityTracker.java
@@ -34,17 +34,17 @@
 
     private static final int ACTIVE_POINTER_ID = -1;
 
-    private int mPtr;
+    private long mPtr;
     private final String mStrategy;
 
-    private static native int nativeInitialize(String strategy);
-    private static native void nativeDispose(int ptr);
-    private static native void nativeClear(int ptr);
-    private static native void nativeAddMovement(int ptr, MotionEvent event);
-    private static native void nativeComputeCurrentVelocity(int ptr, int units, float maxVelocity);
-    private static native float nativeGetXVelocity(int ptr, int id);
-    private static native float nativeGetYVelocity(int ptr, int id);
-    private static native boolean nativeGetEstimator(int ptr, int id, Estimator outEstimator);
+    private static native long nativeInitialize(String strategy);
+    private static native void nativeDispose(long ptr);
+    private static native void nativeClear(long ptr);
+    private static native void nativeAddMovement(long ptr, MotionEvent event);
+    private static native void nativeComputeCurrentVelocity(long ptr, int units, float maxVelocity);
+    private static native float nativeGetXVelocity(long ptr, int id);
+    private static native float nativeGetYVelocity(long ptr, int id);
+    private static native boolean nativeGetEstimator(long ptr, int id, Estimator outEstimator);
 
     /**
      * Retrieve a new VelocityTracker object to watch the velocity of a
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index b0bae46..9b47cbe 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -16499,7 +16499,7 @@
             } else {
                 long value = mMeasureCache.valueAt(cacheIndex);
                 // Casting a long to int drops the high 32 bits, no mask needed
-                setMeasuredDimension((int) (value >> 32), (int) value);
+                setMeasuredDimensionRaw((int) (value >> 32), (int) value);
                 mPrivateFlags3 |= PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;
             }
 
@@ -16594,6 +16594,22 @@
             measuredWidth  += optical ? opticalWidth  : -opticalWidth;
             measuredHeight += optical ? opticalHeight : -opticalHeight;
         }
+        setMeasuredDimensionRaw(measuredWidth, measuredHeight);
+    }
+
+    /**
+     * Sets the measured dimension without extra processing for things like optical bounds.
+     * Useful for reapplying consistent values that have already been cooked with adjustments
+     * for optical bounds, etc. such as those from the measurement cache.
+     *
+     * @param measuredWidth The measured width of this view.  May be a complex
+     * bit mask as defined by {@link #MEASURED_SIZE_MASK} and
+     * {@link #MEASURED_STATE_TOO_SMALL}.
+     * @param measuredHeight The measured height of this view.  May be a complex
+     * bit mask as defined by {@link #MEASURED_SIZE_MASK} and
+     * {@link #MEASURED_STATE_TOO_SMALL}.
+     */
+    private void setMeasuredDimensionRaw(int measuredWidth, int measuredHeight) {
         mMeasuredWidth = measuredWidth;
         mMeasuredHeight = measuredHeight;
 
@@ -18361,7 +18377,18 @@
         }
 
         static int adjust(int measureSpec, int delta) {
-            return makeMeasureSpec(getSize(measureSpec + delta), getMode(measureSpec));
+            final int mode = getMode(measureSpec);
+            if (mode == UNSPECIFIED) {
+                // No need to adjust size for UNSPECIFIED mode.
+                return makeMeasureSpec(0, UNSPECIFIED);
+            }
+            int size = getSize(measureSpec) + delta;
+            if (size < 0) {
+                Log.e(VIEW_LOG_TAG, "MeasureSpec.adjust: new size would be negative! (" + size +
+                        ") spec: " + toString(measureSpec) + " delta: " + delta);
+                size = 0;
+            }
+            return makeMeasureSpec(size, mode);
         }
 
         /**
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 9414237..5763e72 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -463,13 +463,13 @@
     public ViewGroup(Context context, AttributeSet attrs) {
         super(context, attrs);
         initViewGroup();
-        initFromAttributes(context, attrs);
+        initFromAttributes(context, attrs, 0);
     }
 
     public ViewGroup(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         initViewGroup();
-        initFromAttributes(context, attrs);
+        initFromAttributes(context, attrs, defStyle);
     }
 
     private boolean debugDraw() {
@@ -499,9 +499,8 @@
         mPersistentDrawingCache = PERSISTENT_SCROLLING_CACHE;
     }
 
-    private void initFromAttributes(Context context, AttributeSet attrs) {
-        TypedArray a = context.obtainStyledAttributes(attrs,
-                R.styleable.ViewGroup);
+    private void initFromAttributes(Context context, AttributeSet attrs, int defStyle) {
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewGroup, defStyle, 0);
 
         final int N = a.getIndexCount();
         for (int i = 0; i < N; i++) {
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index b3a0699..c450f3c 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -91,10 +91,15 @@
     public static final int FEATURE_ACTION_MODE_OVERLAY = 10;
 
     /**
+     * Flag for requesting a decoration-free window that is dismissed by swiping from the left.
+     */
+    public static final int FEATURE_SWIPE_TO_DISMISS = 11;
+
+    /**
      * Max value used as a feature ID
      * @hide
      */
-    public static final int FEATURE_MAX = FEATURE_ACTION_MODE_OVERLAY;
+    public static final int FEATURE_MAX = FEATURE_SWIPE_TO_DISMISS;
 
     /** Flag for setting the progress bar's visibility to VISIBLE */
     public static final int PROGRESS_VISIBILITY_ON = -1;
@@ -385,6 +390,12 @@
          * @param mode The mode that was just finished.
          */
         public void onActionModeFinished(ActionMode mode);
+
+        /**
+         * Called when a window is dismissed. This informs the callback that the
+         * window is gone, and it should finish itself.
+         */
+        public void onWindowDismissed();
     }
 
     public Window(Context context) {
diff --git a/core/java/android/view/WindowManagerInternal.java b/core/java/android/view/WindowManagerInternal.java
new file mode 100644
index 0000000..a1bd4bd
--- /dev/null
+++ b/core/java/android/view/WindowManagerInternal.java
@@ -0,0 +1,33 @@
+/*
+ * 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 android.view;
+
+import android.hardware.display.DisplayManagerInternal;
+
+/**
+ * Window manager local system service interface.
+ *
+ * @hide Only for use within the system server.
+ */
+public abstract class WindowManagerInternal {
+    /**
+     * Request that the window manager call
+     * {@link DisplayManagerInternal#performTraversalInTransactionFromWindowManager}
+     * within a surface transaction at a later time.
+     */
+    public abstract void requestTraversalFromDisplayManager();
+}
\ No newline at end of file
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index c5a1b86c..74dda77 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -115,20 +115,6 @@
     public final static int ACTION_PASS_TO_USER = 0x00000001;
 
     /**
-     * This key event should wake the device.
-     * To be returned from {@link #interceptKeyBeforeQueueing}.
-     * Do not return this and {@link #ACTION_GO_TO_SLEEP} or {@link #ACTION_PASS_TO_USER}.
-     */
-    public final static int ACTION_WAKE_UP = 0x00000002;
-
-    /**
-     * This key event should put the device to sleep (and engage keyguard if necessary)
-     * To be returned from {@link #interceptKeyBeforeQueueing}.
-     * Do not return this and {@link #ACTION_WAKE_UP} or {@link #ACTION_PASS_TO_USER}.
-     */
-    public final static int ACTION_GO_TO_SLEEP = 0x00000004;
-
-    /**
      * Interface to the Window Manager state associated with a particular
      * window.  You can hold on to an instance of this interface from the call
      * to prepareAddWindow() until removeWindow().
@@ -751,8 +737,7 @@
      * @param policyFlags The policy flags associated with the key.
      * @param isScreenOn True if the screen is already on
      *
-     * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
-     *      {@link #ACTION_WAKE_UP} and {@link #ACTION_GO_TO_SLEEP} flags.
+     * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
      */
     public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn);
 
@@ -765,10 +750,9 @@
      * because it's the most fragile.
      * @param policyFlags The policy flags associated with the motion.
      *
-     * @return The bitwise or of the {@link #ACTION_PASS_TO_USER},
-     *      {@link #ACTION_WAKE_UP} and {@link #ACTION_GO_TO_SLEEP} flags.
+     * @return Actions flags: may be {@link #ACTION_PASS_TO_USER}.
      */
-    public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags);
+    public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags);
 
     /**
      * Called from the input dispatcher thread before a key is dispatched to a window.
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 00f4adb..879e58f 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -177,7 +177,8 @@
                     userId = UserHandle.myUserId();
                 }
                 IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
-                IAccessibilityManager service = IAccessibilityManager.Stub.asInterface(iBinder);
+                IAccessibilityManager service = iBinder == null
+                        ? null : IAccessibilityManager.Stub.asInterface(iBinder);
                 sInstance = new AccessibilityManager(context, service, userId);
             }
         }
@@ -197,10 +198,14 @@
         mHandler = new MyHandler(context.getMainLooper());
         mService = service;
         mUserId = userId;
-
+        if (mService == null) {
+            mIsEnabled = false;
+        }
         try {
-            final int stateFlags = mService.addClient(mClient, userId);
-            setState(stateFlags);
+            if (mService != null) {
+                final int stateFlags = mService.addClient(mClient, userId);
+                setState(stateFlags);
+            }
         } catch (RemoteException re) {
             Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
         }
@@ -322,14 +327,16 @@
     public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList() {
         List<AccessibilityServiceInfo> services = null;
         try {
-            services = mService.getInstalledAccessibilityServiceList(mUserId);
-            if (DEBUG) {
-                Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
+            if (mService != null) {
+                services = mService.getInstalledAccessibilityServiceList(mUserId);
+                if (DEBUG) {
+                    Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
+                }
             }
         } catch (RemoteException re) {
             Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re);
         }
-        return Collections.unmodifiableList(services);
+        return services != null ? Collections.unmodifiableList(services) : Collections.EMPTY_LIST;
     }
 
     /**
@@ -349,14 +356,16 @@
             int feedbackTypeFlags) {
         List<AccessibilityServiceInfo> services = null;
         try {
-            services = mService.getEnabledAccessibilityServiceList(feedbackTypeFlags, mUserId);
-            if (DEBUG) {
-                Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
+            if (mService != null) {
+                services = mService.getEnabledAccessibilityServiceList(feedbackTypeFlags, mUserId);
+                if (DEBUG) {
+                    Log.i(LOG_TAG, "Installed AccessibilityServices " + services);
+                }
             }
         } catch (RemoteException re) {
             Log.e(LOG_TAG, "Error while obtaining the installed AccessibilityServices. ", re);
         }
-        return Collections.unmodifiableList(services);
+        return services != null ? Collections.unmodifiableList(services) : Collections.EMPTY_LIST;
     }
 
     /**
@@ -466,6 +475,9 @@
      */
     public int addAccessibilityInteractionConnection(IWindow windowToken,
             IAccessibilityInteractionConnection connection) {
+        if (mService == null) {
+            return View.NO_ID;
+        }
         try {
             return mService.addAccessibilityInteractionConnection(windowToken, connection, mUserId);
         } catch (RemoteException re) {
@@ -482,7 +494,9 @@
      */
     public void removeAccessibilityInteractionConnection(IWindow windowToken) {
         try {
-            mService.removeAccessibilityInteractionConnection(windowToken);
+            if (mService != null) {
+                mService.removeAccessibilityInteractionConnection(windowToken);
+            }
         } catch (RemoteException re) {
             Log.e(LOG_TAG, "Error while removing an accessibility interaction connection. ", re);
         }
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 082ff3d..abddc90 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -363,8 +363,6 @@
 
     @Override
     public Parcelable onSaveInstanceState() {
-        // Force our ancestor class to save its state
-        setFreezesText(true);
         Parcelable superState = super.onSaveInstanceState();
 
         SavedState ss = new SavedState(superState);
diff --git a/core/java/android/widget/CursorTreeAdapter.java b/core/java/android/widget/CursorTreeAdapter.java
old mode 100644
new mode 100755
index 44d1656..405e45a
--- a/core/java/android/widget/CursorTreeAdapter.java
+++ b/core/java/android/widget/CursorTreeAdapter.java
@@ -497,7 +497,7 @@
 
             @Override
             public void onChange(boolean selfChange) {
-                if (mAutoRequery && mCursor != null) {
+                if (mAutoRequery && mCursor != null && !mCursor.isClosed()) {
                     if (false) Log.v("Cursor", "Auto requerying " + mCursor +
                             " due to update");
                     mDataValid = mCursor.requery();
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 9dab7b4..748af7b 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -317,7 +317,7 @@
 
                 mErrorPopup = null;
             }
-
+            mShowErrorAfterAttach = false;
         } else {
             setErrorIcon(icon);
             if (mTextView.isFocused()) {
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index c0fde2e..9c6a2e3 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -427,12 +427,12 @@
      * Flag whether to ignore move events - we ignore such when we show in IME
      * to prevent the content from scrolling.
      */
-    private boolean mIngonreMoveEvents;
+    private boolean mIgnoreMoveEvents;
 
     /**
-     * Flag whether to show soft input on tap.
+     * Flag whether to perform a click on tap.
      */
-    private boolean mShowSoftInputOnTap;
+    private boolean mPerformClickOnTap;
 
     /**
      * The top of the top selection divider.
@@ -808,8 +808,8 @@
                 mInputText.setVisibility(View.INVISIBLE);
                 mLastDownOrMoveEventY = mLastDownEventY = event.getY();
                 mLastDownEventTime = event.getEventTime();
-                mIngonreMoveEvents = false;
-                mShowSoftInputOnTap = false;
+                mIgnoreMoveEvents = false;
+                mPerformClickOnTap = false;
                 // Handle pressed state before any state change.
                 if (mLastDownEventY < mTopSelectionDividerTop) {
                     if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) {
@@ -840,7 +840,7 @@
                     postChangeCurrentByOneFromLongPress(
                             true, ViewConfiguration.getLongPressTimeout());
                 } else {
-                    mShowSoftInputOnTap = true;
+                    mPerformClickOnTap = true;
                     postBeginSoftInputOnLongPressCommand();
                 }
                 return true;
@@ -861,7 +861,7 @@
         int action = event.getActionMasked();
         switch (action) {
             case MotionEvent.ACTION_MOVE: {
-                if (mIngonreMoveEvents) {
+                if (mIgnoreMoveEvents) {
                     break;
                 }
                 float currentMoveY = event.getY();
@@ -893,9 +893,9 @@
                     int deltaMoveY = (int) Math.abs(eventY - mLastDownEventY);
                     long deltaTime = event.getEventTime() - mLastDownEventTime;
                     if (deltaMoveY <= mTouchSlop && deltaTime < ViewConfiguration.getTapTimeout()) {
-                        if (mShowSoftInputOnTap) {
-                            mShowSoftInputOnTap = false;
-                            showSoftInput();
+                        if (mPerformClickOnTap) {
+                            mPerformClickOnTap = false;
+                            performClick();
                         } else {
                             int selectorIndexOffset = (eventY / mSelectorElementHeight)
                                     - SELECTOR_MIDDLE_ITEM_INDEX;
@@ -1188,6 +1188,27 @@
         setValueInternal(value, false);
     }
 
+    @Override
+    public boolean performClick() {
+        if (!mHasSelectorWheel) {
+            return super.performClick();
+        } else if (!super.performClick()) {
+            showSoftInput();
+        }
+        return true;
+    }
+
+    @Override
+    public boolean performLongClick() {
+        if (!mHasSelectorWheel) {
+            return super.performLongClick();
+        } else if (!super.performLongClick()) {
+            showSoftInput();
+            mIgnoreMoveEvents = true;
+        }
+        return true;
+    }
+
     /**
      * Shows the soft input for its input text.
      */
@@ -2166,8 +2187,7 @@
 
         @Override
         public void run() {
-            showSoftInput();
-            mIngonreMoveEvents = true;
+            performLongClick();
         }
     }
 
@@ -2295,7 +2315,14 @@
                         }
                         case AccessibilityNodeInfo.ACTION_CLICK: {
                             if (NumberPicker.this.isEnabled()) {
-                                showSoftInput();
+                                performClick();
+                                return true;
+                            }
+                            return false;
+                        }
+                        case AccessibilityNodeInfo.ACTION_LONG_CLICK: {
+                            if (NumberPicker.this.isEnabled()) {
+                                performLongClick();
                                 return true;
                             }
                             return false;
diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java
index 1cda631..b204dfd 100644
--- a/core/java/android/widget/SpellChecker.java
+++ b/core/java/android/widget/SpellChecker.java
@@ -731,14 +731,10 @@
                 }
             }
 
-            if (scheduleOtherSpellCheck && wordStart <= end) {
+            if (scheduleOtherSpellCheck) {
                 // Update range span: start new spell check from last wordStart
                 setRangeSpan(editable, wordStart, end);
             } else {
-                if (DBG && scheduleOtherSpellCheck) {
-                    Log.w(TAG, "Trying to schedule spellcheck for invalid region, from "
-                            + wordStart + " to " + end);
-                }
                 removeRangeSpan(editable);
             }
 
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java
index b75d36f..5cbabef 100644
--- a/core/java/android/widget/Spinner.java
+++ b/core/java/android/widget/Spinner.java
@@ -952,8 +952,10 @@
         private CharSequence mPrompt;
 
         public void dismiss() {
-            mPopup.dismiss();
-            mPopup = null;
+            if (mPopup != null) {
+                mPopup.dismiss();
+                mPopup = null;
+            }
         }
 
         public boolean isShowing() {
diff --git a/core/java/com/android/internal/app/ProcessStats.java b/core/java/com/android/internal/app/ProcessStats.java
index 0aad0b5..0cad33c 100644
--- a/core/java/com/android/internal/app/ProcessStats.java
+++ b/core/java/com/android/internal/app/ProcessStats.java
@@ -1004,7 +1004,7 @@
                 for (int iproc=pkgState.mProcesses.size()-1; iproc>=0; iproc--) {
                     ProcessState ps = pkgState.mProcesses.valueAt(iproc);
                     if (ps.isInUse() || ps.mCommonProcess.isInUse()) {
-                        ps.resetSafely(now);
+                        pkgState.mProcesses.valueAt(iproc).resetSafely(now);
                     } else {
                         pkgState.mProcesses.valueAt(iproc).makeDead();
                         pkgState.mProcesses.removeAt(iproc);
@@ -1013,7 +1013,7 @@
                 for (int isvc=pkgState.mServices.size()-1; isvc>=0; isvc--) {
                     ServiceState ss = pkgState.mServices.valueAt(isvc);
                     if (ss.isInUse()) {
-                        ss.resetSafely(now);
+                        pkgState.mServices.valueAt(isvc).resetSafely(now);
                     } else {
                         pkgState.mServices.removeAt(isvc);
                     }
@@ -3014,7 +3014,7 @@
         }
 
         public boolean isInUse() {
-            return mOwner != null || mRestarting;
+            return mOwner != null;
         }
 
         void add(ServiceState other) {
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 0a702ff..8728610 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -26,6 +26,7 @@
 import android.os.BatteryStats;
 import android.os.FileUtils;
 import android.os.Handler;
+import android.os.Looper;
 import android.os.Message;
 import android.os.Parcel;
 import android.os.ParcelFormatException;
@@ -113,6 +114,10 @@
     }
 
     final class MyHandler extends Handler {
+        public MyHandler(Looper looper) {
+            super(looper, null, true);
+        }
+
         @Override
         public void handleMessage(Message msg) {
             BatteryCallback cb = mCallback;
@@ -4487,9 +4492,9 @@
         }
     }
 
-    public BatteryStatsImpl(String filename) {
+    public BatteryStatsImpl(String filename, Handler handler) {
         mFile = new JournaledFile(new File(filename), new File(filename + ".tmp"));
-        mHandler = new MyHandler();
+        mHandler = new MyHandler(handler.getLooper());
         mStartCount++;
         mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables);
         for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
@@ -4839,7 +4844,7 @@
                 mHistoryCur.batteryStatus = (byte)status;
                 mHistoryCur.batteryHealth = (byte)health;
                 mHistoryCur.batteryPlugType = (byte)plugType;
-                mHistoryCur.batteryTemperature = (char)temp;
+                mHistoryCur.batteryTemperature = (short)temp;
                 mHistoryCur.batteryVoltage = (char)volt;
                 setOnBatteryLocked(onBattery, oldStatus, level);
             } else {
@@ -4862,7 +4867,7 @@
                 }
                 if (temp >= (mHistoryCur.batteryTemperature+10)
                         || temp <= (mHistoryCur.batteryTemperature-10)) {
-                    mHistoryCur.batteryTemperature = (char)temp;
+                    mHistoryCur.batteryTemperature = (short)temp;
                     changed = true;
                 }
                 if (volt > (mHistoryCur.batteryVoltage+20)
diff --git a/core/java/com/android/internal/os/BinderInternal.java b/core/java/com/android/internal/os/BinderInternal.java
index f54a3e9..3b0f0f4 100644
--- a/core/java/com/android/internal/os/BinderInternal.java
+++ b/core/java/com/android/internal/os/BinderInternal.java
@@ -16,18 +16,11 @@
 
 package com.android.internal.os;
 
-import android.os.Binder;
 import android.os.IBinder;
 import android.os.SystemClock;
 import android.util.EventLog;
-import android.util.Log;
 
-import java.io.FileDescriptor;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.lang.ref.WeakReference;
-import java.lang.reflect.Modifier;
 
 /**
  * Private and debugging Binder APIs.
diff --git a/core/java/com/android/internal/os/LoggingPrintStream.java b/core/java/com/android/internal/os/LoggingPrintStream.java
index 451340b..f14394a 100644
--- a/core/java/com/android/internal/os/LoggingPrintStream.java
+++ b/core/java/com/android/internal/os/LoggingPrintStream.java
@@ -293,7 +293,7 @@
 
     @Override
     public synchronized void println(String s) {
-        if (builder.length() == 0) {
+        if (builder.length() == 0 && s != null) {
             // Optimization for a simple println.
             int length = s.length();
 
diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java
index fd7e3b0..4f3b5b3 100644
--- a/core/java/com/android/internal/os/ZygoteConnection.java
+++ b/core/java/com/android/internal/os/ZygoteConnection.java
@@ -197,10 +197,14 @@
 
         try {
             parsedArgs = new Arguments(args);
+            if (parsedArgs.permittedCapabilities != 0 || parsedArgs.effectiveCapabilities != 0) {
+                throw new ZygoteSecurityException("Client may not specify capabilities: " +
+                        "permitted=0x" + Long.toHexString(parsedArgs.permittedCapabilities) +
+                        ", effective=0x" + Long.toHexString(parsedArgs.effectiveCapabilities));
+            }
 
             applyUidSecurityPolicy(parsedArgs, peer, peerSecurityContext);
             applyRlimitSecurityPolicy(parsedArgs, peer, peerSecurityContext);
-            applyCapabilitiesSecurityPolicy(parsedArgs, peer, peerSecurityContext);
             applyInvokeWithSecurityPolicy(parsedArgs, peer, peerSecurityContext);
             applyseInfoSecurityPolicy(parsedArgs, peer, peerSecurityContext);
 
@@ -703,71 +707,6 @@
     }
 
     /**
-     * Applies zygote security policy per bug #1042973. A root peer may
-     * spawn an instance with any capabilities. All other uids may spawn
-     * instances with any of the capabilities in the peer's permitted set
-     * but no more.
-     *
-     * @param args non-null; zygote spawner arguments
-     * @param peer non-null; peer credentials
-     * @throws ZygoteSecurityException
-     */
-    private static void applyCapabilitiesSecurityPolicy(
-            Arguments args, Credentials peer, String peerSecurityContext)
-            throws ZygoteSecurityException {
-
-        if (args.permittedCapabilities == 0
-                && args.effectiveCapabilities == 0) {
-            // nothing to check
-            return;
-        }
-
-        boolean allowed = SELinux.checkSELinuxAccess(peerSecurityContext,
-                                                     peerSecurityContext,
-                                                     "zygote",
-                                                     "specifycapabilities");
-        if (!allowed) {
-            throw new ZygoteSecurityException(
-                    "Peer may not specify capabilities");
-        }
-
-        if (peer.getUid() == 0) {
-            // root may specify anything
-            return;
-        }
-
-        long permittedCaps;
-
-        try {
-            permittedCaps = ZygoteInit.capgetPermitted(peer.getPid());
-        } catch (IOException ex) {
-            throw new ZygoteSecurityException(
-                    "Error retrieving peer's capabilities.");
-        }
-
-        /*
-         * Ensure that the client did not specify an effective set larger
-         * than the permitted set. The kernel will enforce this too, but we
-         * do it here to make the following check easier.
-         */
-        if (((~args.permittedCapabilities) & args.effectiveCapabilities) != 0) {
-            throw new ZygoteSecurityException(
-                    "Effective capabilities cannot be superset of "
-                            + " permitted capabilities" );
-        }
-
-        /*
-         * Ensure that the new permitted (and thus the new effective) set is
-         * a subset of the peer process's permitted set
-         */
-
-        if (((~permittedCaps) & args.permittedCapabilities) != 0) {
-            throw new ZygoteSecurityException(
-                    "Peer specified unpermitted capabilities" );
-        }
-    }
-
-    /**
      * Applies zygote security policy.
      * Based on the credentials of the process issuing a zygote command:
      * <ol>
@@ -803,7 +742,7 @@
     }
 
     /**
-     * Applies zygote security policy for SEAndroid information.
+     * Applies zygote security policy for SELinux information.
      *
      * @param args non-null; zygote spawner arguments
      * @param peer non-null; peer credentials
@@ -822,7 +761,7 @@
         if (!(peerUid == 0 || peerUid == Process.SYSTEM_UID)) {
             // All peers with UID other than root or SYSTEM_UID
             throw new ZygoteSecurityException(
-                    "This UID may not specify SEAndroid info.");
+                    "This UID may not specify SELinux info.");
         }
 
         boolean allowed = SELinux.checkSELinuxAccess(peerSecurityContext,
@@ -831,7 +770,7 @@
                                                      "specifyseinfo");
         if (!allowed) {
             throw new ZygoteSecurityException(
-                    "Peer may not specify SEAndroid info");
+                    "Peer may not specify SELinux info");
         }
 
         return;
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 1548f1b..9dc9116 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -495,6 +495,7 @@
     private static boolean startSystemServer()
             throws MethodAndArgsCaller, RuntimeException {
         long capabilities = posixCapabilitiesAsBits(
+            OsConstants.CAP_BLOCK_SUSPEND,
             OsConstants.CAP_KILL,
             OsConstants.CAP_NET_ADMIN,
             OsConstants.CAP_NET_BIND_SERVICE,
@@ -728,15 +729,6 @@
             throws IOException;
 
     /**
-     * Retrieves the permitted capability set from another process.
-     *
-     * @param pid &gt;=0 process ID or 0 for this process
-     * @throws IOException on error
-     */
-    static native long capgetPermitted(int pid)
-            throws IOException;
-
-    /**
      * Invokes select() on the provider array of file descriptors (selecting
      * for readability only). Array elements of null are ignored.
      *
diff --git a/core/java/com/android/internal/util/Objects.java b/core/java/com/android/internal/util/Objects.java
deleted file mode 100644
index 2664182..0000000
--- a/core/java/com/android/internal/util/Objects.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2007 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.internal.util;
-
-import java.util.Arrays;
-
-/**
- * Object utility methods.
- */
-public class Objects {
-
-    /**
-     * Determines whether two possibly-null objects are equal. Returns:
-     *
-     * <ul>
-     * <li>{@code true} if {@code a} and {@code b} are both null.
-     * <li>{@code true} if {@code a} and {@code b} are both non-null and they are
-     *     equal according to {@link Object#equals(Object)}.
-     * <li>{@code false} in all other situations.
-     * </ul>
-     *
-     * <p>This assumes that any non-null objects passed to this function conform
-     * to the {@code equals()} contract.
-     */
-    public static boolean equal(Object a, Object b) {
-        return a == b || (a != null && a.equals(b));
-    }
-
-    /**
-     * Generates a hash code for multiple values. The hash code is generated by
-     * calling {@link Arrays#hashCode(Object[])}.
-     *
-     * <p>This is useful for implementing {@link Object#hashCode()}. For example,
-     * in an object that has three properties, {@code x}, {@code y}, and
-     * {@code z}, one could write:
-     * <pre>
-     * public int hashCode() {
-     *   return Objects.hashCode(getX(), getY(), getZ());
-     * }</pre>
-     *
-     * <b>Warning</b>: When a single object is supplied, the returned hash code
-     * does not equal the hash code of that object.
-     */
-    public static int hashCode(Object... objects) {
-        return Arrays.hashCode(objects);
-    }
-
-}
diff --git a/core/java/com/android/internal/util/XmlUtils.java b/core/java/com/android/internal/util/XmlUtils.java
index 0b74cf3..b35de93 100644
--- a/core/java/com/android/internal/util/XmlUtils.java
+++ b/core/java/com/android/internal/util/XmlUtils.java
@@ -482,12 +482,13 @@
      * @see #readThisMapXml
      * #see #writeMapXml
      */
-    public static final HashMap readMapXml(InputStream in)
+    @SuppressWarnings("unchecked")
+    public static final HashMap<String, ?> readMapXml(InputStream in)
     throws XmlPullParserException, java.io.IOException
     {
         XmlPullParser   parser = Xml.newPullParser();
         parser.setInput(in, null);
-        return (HashMap)readValueXml(parser, new String[1]);
+        return (HashMap<String, ?>) readValueXml(parser, new String[1]);
     }
 
     /**
@@ -548,22 +549,16 @@
      *
      * @see #readMapXml
      */
-    public static final HashMap readThisMapXml(XmlPullParser parser, String endTag, String[] name)
-    throws XmlPullParserException, java.io.IOException
+    public static final HashMap<String, ?> readThisMapXml(XmlPullParser parser, String endTag,
+            String[] name) throws XmlPullParserException, java.io.IOException
     {
-        HashMap map = new HashMap();
+        HashMap<String, Object> map = new HashMap<String, Object>();
 
         int eventType = parser.getEventType();
         do {
             if (eventType == parser.START_TAG) {
                 Object val = readThisValueXml(parser, name);
-                if (name[0] != null) {
-                    //System.out.println("Adding to map: " + name + " -> " + val);
-                    map.put(name[0], val);
-                } else {
-                    throw new XmlPullParserException(
-                        "Map value without name attribute: " + parser.getName());
-                }
+                map.put(name[0], val);
             } else if (eventType == parser.END_TAG) {
                 if (parser.getName().equals(endTag)) {
                     return map;
diff --git a/core/java/com/android/internal/view/RotationPolicy.java b/core/java/com/android/internal/view/RotationPolicy.java
index 70e2bfc..6295314 100644
--- a/core/java/com/android/internal/view/RotationPolicy.java
+++ b/core/java/com/android/internal/view/RotationPolicy.java
@@ -21,7 +21,6 @@
 import android.database.ContentObserver;
 import android.net.Uri;
 import android.os.AsyncTask;
-import android.os.Build;
 import android.os.Handler;
 import android.os.RemoteException;
 import android.os.UserHandle;
@@ -52,7 +51,9 @@
         PackageManager pm = context.getPackageManager();
         return pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER)
                 && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT)
-                && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE);
+                && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE)
+                && context.getResources().getBoolean(
+                        com.android.internal.R.bool.config_supportAutoRotation);
     }
 
     /**
@@ -176,6 +177,7 @@
      */
     public static abstract class RotationPolicyListener {
         final ContentObserver mObserver = new ContentObserver(new Handler()) {
+            @Override
             public void onChange(boolean selfChange, Uri uri) {
                 RotationPolicyListener.this.onChange();
             }
diff --git a/core/java/com/android/internal/widget/SwipeDismissLayout.java b/core/java/com/android/internal/widget/SwipeDismissLayout.java
new file mode 100644
index 0000000..467d42e
--- /dev/null
+++ b/core/java/com/android/internal/widget/SwipeDismissLayout.java
@@ -0,0 +1,308 @@
+/*
+ * 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.internal.widget;
+
+import android.animation.TimeInterpolator;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.view.ViewGroup;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.DecelerateInterpolator;
+import android.widget.FrameLayout;
+
+/**
+ * Special layout that finishes its activity when swiped away.
+ */
+public class SwipeDismissLayout extends FrameLayout {
+    private static final String TAG = "SwipeDismissLayout";
+
+    private static final float TRANSLATION_MIN_ALPHA = 0.5f;
+
+    public interface OnDismissedListener {
+        void onDismissed(SwipeDismissLayout layout);
+    }
+
+    public interface OnSwipeProgressChangedListener {
+        /**
+         * Called when the layout has been swiped and the position of the window should change.
+         *
+         * @param progress A number in [-1, 1] representing how far to the left
+         * or right the window has been swiped. Negative values are swipes
+         * left, and positives are right.
+         * @param translate A number in [-w, w], where w is the width of the
+         * layout. This is equivalent to progress * layout.getWidth().
+         */
+        void onSwipeProgressChanged(SwipeDismissLayout layout, float progress, float translate);
+
+        void onSwipeCancelled(SwipeDismissLayout layout);
+    }
+
+    // Cached ViewConfiguration and system-wide constant values
+    private int mSlop;
+    private int mMinFlingVelocity;
+    private int mMaxFlingVelocity;
+    private long mAnimationTime;
+    private TimeInterpolator mCancelInterpolator;
+    private TimeInterpolator mDismissInterpolator;
+
+    // Transient properties
+    private int mActiveTouchId;
+    private float mDownX;
+    private float mDownY;
+    private boolean mSwiping;
+    private boolean mDismissed;
+    private boolean mDiscardIntercept;
+    private VelocityTracker mVelocityTracker;
+    private float mTranslationX;
+
+    private OnDismissedListener mDismissedListener;
+    private OnSwipeProgressChangedListener mProgressListener;
+
+    public SwipeDismissLayout(Context context) {
+        super(context);
+        init(context);
+    }
+
+    public SwipeDismissLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        init(context);
+    }
+
+    public SwipeDismissLayout(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        init(context);
+    }
+
+    private void init(Context context) {
+        ViewConfiguration vc = ViewConfiguration.get(getContext());
+        mSlop = vc.getScaledTouchSlop();
+        mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
+        mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
+        mAnimationTime = getContext().getResources().getInteger(
+                android.R.integer.config_shortAnimTime);
+        mCancelInterpolator = new DecelerateInterpolator(1.5f);
+        mDismissInterpolator = new AccelerateInterpolator(1.5f);
+    }
+
+    public void setOnDismissedListener(OnDismissedListener listener) {
+        mDismissedListener = listener;
+    }
+
+    public void setOnSwipeProgressChangedListener(OnSwipeProgressChangedListener listener) {
+        mProgressListener = listener;
+    }
+
+    @Override
+    public boolean onInterceptTouchEvent(MotionEvent ev) {
+        // offset because the view is translated during swipe
+        ev.offsetLocation(mTranslationX, 0);
+
+        switch (ev.getActionMasked()) {
+            case MotionEvent.ACTION_DOWN:
+                resetMembers();
+                mDownX = ev.getRawX();
+                mDownY = ev.getRawY();
+                mActiveTouchId = ev.getPointerId(0);
+                mVelocityTracker = VelocityTracker.obtain();
+                mVelocityTracker.addMovement(ev);
+                break;
+
+            case MotionEvent.ACTION_POINTER_DOWN:
+                int actionIndex = ev.getActionIndex();
+                mActiveTouchId = ev.getPointerId(actionIndex);
+                break;
+            case MotionEvent.ACTION_POINTER_UP:
+                actionIndex = ev.getActionIndex();
+                int pointerId = ev.getPointerId(actionIndex);
+                if (pointerId == mActiveTouchId) {
+                    // This was our active pointer going up. Choose a new active pointer.
+                    int newActionIndex = actionIndex == 0 ? 1 : 0;
+                    mActiveTouchId = ev.getPointerId(newActionIndex);
+                }
+                break;
+
+            case MotionEvent.ACTION_CANCEL:
+            case MotionEvent.ACTION_UP:
+                resetMembers();
+                break;
+
+            case MotionEvent.ACTION_MOVE:
+                if (mVelocityTracker == null || mDiscardIntercept) {
+                    break;
+                }
+
+                int pointerIndex = ev.findPointerIndex(mActiveTouchId);
+                if (pointerIndex == -1) {
+                    Log.e(TAG, "Invalid pointer index: ignoring.");
+                    mDiscardIntercept = true;
+                    break;
+                }
+                float dx = ev.getRawX() - mDownX;
+                float x = ev.getX(pointerIndex);
+                float y = ev.getY(pointerIndex);
+                if (dx != 0 && canScroll(this, false, dx, x, y)) {
+                    mDiscardIntercept = true;
+                    break;
+                }
+                updateSwiping(ev);
+                break;
+        }
+
+        return !mDiscardIntercept && mSwiping;
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        if (mVelocityTracker == null) {
+            return super.onTouchEvent(ev);
+        }
+        switch (ev.getActionMasked()) {
+            case MotionEvent.ACTION_UP:
+                updateDismiss(ev);
+                if (mDismissed) {
+                    dismiss();
+                } else if (mSwiping) {
+                    cancel();
+                }
+                resetMembers();
+                break;
+
+            case MotionEvent.ACTION_CANCEL:
+                cancel();
+                resetMembers();
+                break;
+
+            case MotionEvent.ACTION_MOVE:
+                mVelocityTracker.addMovement(ev);
+                updateSwiping(ev);
+                updateDismiss(ev);
+                if (mSwiping) {
+                    setProgress(ev.getRawX() - mDownX);
+                    break;
+                }
+        }
+        return true;
+    }
+
+    private void setProgress(float deltaX) {
+        mTranslationX = deltaX;
+        if (mProgressListener != null) {
+            mProgressListener.onSwipeProgressChanged(this, deltaX / getWidth(), deltaX);
+        }
+    }
+
+    private void dismiss() {
+        if (mDismissedListener != null) {
+            mDismissedListener.onDismissed(this);
+        }
+    }
+
+    protected void cancel() {
+        if (mProgressListener != null) {
+            mProgressListener.onSwipeCancelled(this);
+        }
+    }
+
+    /**
+     * Resets internal members when canceling.
+     */
+    private void resetMembers() {
+        if (mVelocityTracker != null) {
+            mVelocityTracker.recycle();
+        }
+        mVelocityTracker = null;
+        mTranslationX = 0;
+        mDownX = 0;
+        mDownY = 0;
+        mSwiping = false;
+        mDismissed = false;
+        mDiscardIntercept = false;
+    }
+
+    private void updateSwiping(MotionEvent ev) {
+        if (!mSwiping) {
+            float deltaX = ev.getRawX() - mDownX;
+            float deltaY = ev.getRawY() - mDownY;
+            mSwiping = deltaX > mSlop * 2 && Math.abs(deltaY) < mSlop * 2;
+        }
+    }
+
+    private void updateDismiss(MotionEvent ev) {
+        float deltaX = ev.getRawX() - mDownX;
+        if (!mDismissed) {
+            mVelocityTracker.addMovement(ev);
+            mVelocityTracker.computeCurrentVelocity(1000);
+
+            float velocityX = mVelocityTracker.getXVelocity();
+            float absVelocityX = Math.abs(velocityX);
+            float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
+
+            if (deltaX > getWidth() / 2) {
+                mDismissed = true;
+            } else if (absVelocityX >= mMinFlingVelocity
+                    && absVelocityX <= mMaxFlingVelocity
+                    && absVelocityY < absVelocityX / 2
+                    && velocityX > 0
+                    && deltaX > 0) {
+                mDismissed = true;
+            }
+        }
+        // Check if the user tried to undo this.
+        if (mDismissed && mSwiping) {
+            // Check if the user's finger is actually back
+            if (deltaX < getWidth() / 2) {
+                mDismissed = false;
+            }
+        }
+    }
+
+    /**
+     * Tests scrollability within child views of v in the direction of dx.
+     *
+     * @param v View to test for horizontal scrollability
+     * @param checkV Whether the view v passed should itself be checked for scrollability (true),
+     *               or just its children (false).
+     * @param dx Delta scrolled in pixels. Only the sign of this is used.
+     * @param x X coordinate of the active touch point
+     * @param y Y coordinate of the active touch point
+     * @return true if child views of v can be scrolled by delta of dx.
+     */
+    protected boolean canScroll(View v, boolean checkV, float dx, float x, float y) {
+        if (v instanceof ViewGroup) {
+            final ViewGroup group = (ViewGroup) v;
+            final int scrollX = v.getScrollX();
+            final int scrollY = v.getScrollY();
+            final int count = group.getChildCount();
+            for (int i = count - 1; i >= 0; i--) {
+                final View child = group.getChildAt(i);
+                if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
+                        y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
+                        canScroll(child, true, dx, x + scrollX - child.getLeft(),
+                                y + scrollY - child.getTop())) {
+                    return true;
+                }
+            }
+        }
+
+        return checkV && v.canScrollHorizontally((int) -dx);
+    }
+}
diff --git a/core/java/com/android/server/LocalServices.java b/core/java/com/android/server/LocalServices.java
new file mode 100644
index 0000000..25dcb30
--- /dev/null
+++ b/core/java/com/android/server/LocalServices.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.util.ArrayMap;
+
+/**
+ * This class is used in a similar way as ServiceManager, except the services registered here
+ * are not Binder objects and are only available in the same process.
+ *
+ * Once all services are converted to the SystemService interface, this class can be absorbed
+ * into SystemServiceManager.
+ *
+ * {@hide}
+ */
+public final class LocalServices {
+    private LocalServices() {}
+
+    private static final ArrayMap<Class<?>, Object> sLocalServiceObjects =
+            new ArrayMap<Class<?>, Object>();
+
+    /**
+     * Returns a local service instance that implements the specified interface.
+     *
+     * @param type The type of service.
+     * @return The service object.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T getService(Class<T> type) {
+        synchronized (sLocalServiceObjects) {
+            return (T) sLocalServiceObjects.get(type);
+        }
+    }
+
+    /**
+     * Adds a service instance of the specified interface to the global registry of local services.
+     */
+    public static <T> void addService(Class<T> type, T service) {
+        synchronized (sLocalServiceObjects) {
+            if (sLocalServiceObjects.containsKey(type)) {
+                throw new IllegalStateException("Overriding service registration");
+            }
+            sLocalServiceObjects.put(type, service);
+        }
+    }
+}
diff --git a/core/java/com/android/server/SystemService.java b/core/java/com/android/server/SystemService.java
new file mode 100644
index 0000000..e374563
--- /dev/null
+++ b/core/java/com/android/server/SystemService.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.content.Context;
+import android.os.IBinder;
+import android.os.ServiceManager;
+
+/**
+ * The base class for services running in the system process. Override and implement
+ * the lifecycle event callback methods as needed.
+ * <p>
+ * The lifecycle of a SystemService:
+ * </p><ul>
+ * <li>The constructor is called and provided with the system {@link Context}
+ * to initialize the system service.
+ * <li>{@link #onStart()} is called to get the service running.  The service should
+ * publish its binder interface at this point using
+ * {@link #publishBinderService(String, IBinder)}.  It may also publish additional
+ * local interfaces that other services within the system server may use to access
+ * privileged internal functions.
+ * <li>Then {@link #onBootPhase(int)} is called as many times as there are boot phases
+ * until {@link #PHASE_BOOT_COMPLETE} is sent, which is the last boot phase. Each phase
+ * is an opportunity to do special work, like acquiring optional service dependencies,
+ * waiting to see if SafeMode is enabled, or registering with a service that gets
+ * started after this one.
+ * </ul><p>
+ * NOTE: All lifecycle methods are called from the system server's main looper thread.
+ * </p>
+ *
+ * {@hide}
+ */
+public abstract class SystemService {
+    /*
+     * Boot Phases
+     */
+    public static final int PHASE_WAIT_FOR_DEFAULT_DISPLAY = 100; // maybe should be a dependency?
+
+    /**
+     * After receiving this boot phase, services can obtain lock settings data.
+     */
+    public static final int PHASE_LOCK_SETTINGS_READY = 480;
+
+    /**
+     * After receiving this boot phase, services can safely call into core system services
+     * such as the PowerManager or PackageManager.
+     */
+    public static final int PHASE_SYSTEM_SERVICES_READY = 500;
+
+    /**
+     * After receiving this boot phase, services can broadcast Intents.
+     */
+    public static final int PHASE_ACTIVITY_MANAGER_READY = 550;
+
+    /**
+     * After receiving this boot phase, services can start/bind to third party apps.
+     * Apps will be able to make Binder calls into services at this point.
+     */
+    public static final int PHASE_THIRD_PARTY_APPS_CAN_START = 600;
+
+    /**
+     * After receiving this boot phase, services must have finished all boot-related work.
+     */
+    public static final int PHASE_BOOT_COMPLETE = 1000;
+
+    private final Context mContext;
+
+    /**
+     * Initializes the system service.
+     * <p>
+     * Subclasses must define a single argument constructor that accepts the context
+     * and passes it to super.
+     * </p>
+     *
+     * @param context The system server context.
+     */
+    public SystemService(Context context) {
+        mContext = context;
+    }
+
+    /**
+     * Gets the system context.
+     */
+    public final Context getContext() {
+        return mContext;
+    }
+
+    /**
+     * Returns true if the system is running in safe mode.
+     * TODO: we should define in which phase this becomes valid
+     */
+    public final boolean isSafeMode() {
+        return getManager().isSafeMode();
+    }
+
+    /**
+     * Called when the dependencies listed in the @Service class-annotation are available
+     * and after the chosen start phase.
+     * When this method returns, the service should be published.
+     */
+    public abstract void onStart();
+
+    /**
+     * Called on each phase of the boot process. Phases before the service's start phase
+     * (as defined in the @Service annotation) are never received.
+     *
+     * @param phase The current boot phase.
+     */
+    public void onBootPhase(int phase) {}
+
+    /**
+     * Publish the service so it is accessible to other services and apps.
+     */
+    protected final void publishBinderService(String name, IBinder service) {
+        publishBinderService(name, service, false);
+    }
+
+    /**
+     * Publish the service so it is accessible to other services and apps.
+     */
+    protected final void publishBinderService(String name, IBinder service,
+            boolean allowIsolated) {
+        ServiceManager.addService(name, service, allowIsolated);
+    }
+
+    /**
+     * Get a binder service by its name.
+     */
+    protected final IBinder getBinderService(String name) {
+        return ServiceManager.getService(name);
+    }
+
+    /**
+     * Publish the service so it is only accessible to the system process.
+     */
+    protected final <T> void publishLocalService(Class<T> type, T service) {
+        LocalServices.addService(type, service);
+    }
+
+    /**
+     * Get a local service by interface.
+     */
+    protected final <T> T getLocalService(Class<T> type) {
+        return LocalServices.getService(type);
+    }
+
+    private SystemServiceManager getManager() {
+        return LocalServices.getService(SystemServiceManager.class);
+    }
+
+//    /**
+//     * Called when a new user has been created. If your service deals with multiple users, this
+//     * method should be overridden.
+//     *
+//     * @param userHandle The user that was created.
+//     */
+//    public void onUserCreated(int userHandle) {
+//    }
+//
+//    /**
+//     * Called when an existing user has started a new session. If your service deals with multiple
+//     * users, this method should be overridden.
+//     *
+//     * @param userHandle The user who started a new session.
+//     */
+//    public void onUserStarted(int userHandle) {
+//    }
+//
+//    /**
+//     * Called when a background user session has entered the foreground. If your service deals with
+//     * multiple users, this method should be overridden.
+//     *
+//     * @param userHandle The user who's session entered the foreground.
+//     */
+//    public void onUserForeground(int userHandle) {
+//    }
+//
+//    /**
+//     * Called when a foreground user session has entered the background. If your service deals with
+//     * multiple users, this method should be overridden;
+//     *
+//     * @param userHandle The user who's session entered the background.
+//     */
+//    public void onUserBackground(int userHandle) {
+//    }
+//
+//    /**
+//     * Called when a user's active session has stopped. If your service deals with multiple users,
+//     * this method should be overridden.
+//     *
+//     * @param userHandle The user who's session has stopped.
+//     */
+//    public void onUserStopped(int userHandle) {
+//    }
+//
+//    /**
+//     * Called when a user has been removed from the system. If your service deals with multiple
+//     * users, this method should be overridden.
+//     *
+//     * @param userHandle The user who has been removed.
+//     */
+//    public void onUserRemoved(int userHandle) {
+//    }
+}
diff --git a/core/java/com/android/server/SystemServiceManager.java b/core/java/com/android/server/SystemServiceManager.java
new file mode 100644
index 0000000..eb8df0e
--- /dev/null
+++ b/core/java/com/android/server/SystemServiceManager.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.content.Context;
+import android.util.Slog;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+
+/**
+ * Manages creating, starting, and other lifecycle events of
+ * {@link com.android.server.SystemService system services}.
+ *
+ * {@hide}
+ */
+public class SystemServiceManager {
+    private static final String TAG = "SystemServiceManager";
+
+    private final Context mContext;
+    private boolean mSafeMode;
+
+    // Services that should receive lifecycle events.
+    private final ArrayList<SystemService> mServices = new ArrayList<SystemService>();
+
+    private int mCurrentPhase = -1;
+
+    public SystemServiceManager(Context context) {
+        mContext = context;
+    }
+
+    /**
+     * Starts a service by class name.
+     *
+     * @return The service instance.
+     */
+    @SuppressWarnings("unchecked")
+    public SystemService startService(String className) throws ClassNotFoundException {
+        return startService((Class<SystemService>) Class.forName(className));
+    }
+
+    /**
+     * Creates and starts a system service. The class must be a subclass of
+     * {@link com.android.server.SystemService}.
+     *
+     * @param serviceClass A Java class that implements the SystemService interface.
+     * @return The service instance, never null.
+     * @throws RuntimeException if the service fails to start.
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends SystemService> T startService(Class<T> serviceClass) {
+        final String name = serviceClass.getName();
+        Slog.i(TAG, "Starting " + name);
+
+        // Create the service.
+        if (!SystemService.class.isAssignableFrom(serviceClass)) {
+            throw new RuntimeException("Failed to create " + name
+                    + ": service must extend " + SystemService.class.getName());
+        }
+        final T service;
+        try {
+            Constructor<T> constructor = serviceClass.getConstructor(Context.class);
+            service = constructor.newInstance(mContext);
+        } catch (InstantiationException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service could not be instantiated", ex);
+        } catch (IllegalAccessException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service must have a public constructor with a Context argument", ex);
+        } catch (NoSuchMethodException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service must have a public constructor with a Context argument", ex);
+        } catch (InvocationTargetException ex) {
+            throw new RuntimeException("Failed to create service " + name
+                    + ": service constructor threw an exception", ex);
+        }
+
+        // Register it.
+        mServices.add(service);
+
+        // Start it.
+        try {
+            service.onStart();
+        } catch (RuntimeException ex) {
+            throw new RuntimeException("Failed to start service " + name
+                    + ": onStart threw an exception", ex);
+        }
+        return service;
+    }
+
+    /**
+     * Starts the specified boot phase for all system services that have been started up to
+     * this point.
+     *
+     * @param phase The boot phase to start.
+     */
+    public void startBootPhase(final int phase) {
+        if (phase <= mCurrentPhase) {
+            throw new IllegalArgumentException("Next phase must be larger than previous");
+        }
+        mCurrentPhase = phase;
+
+        Slog.i(TAG, "Starting phase " + mCurrentPhase);
+
+        final int serviceLen = mServices.size();
+        for (int i = 0; i < serviceLen; i++) {
+            final SystemService service = mServices.get(i);
+            try {
+                service.onBootPhase(mCurrentPhase);
+            } catch (Exception ex) {
+                throw new RuntimeException("Failed to boot service "
+                        + service.getClass().getName()
+                        + ": onBootPhase threw an exception during phase "
+                        + mCurrentPhase, ex);
+            }
+        }
+    }
+
+    /** Sets the safe mode flag for services to query. */
+    public void setSafeMode(boolean safeMode) {
+        mSafeMode = safeMode;
+    }
+
+    /**
+     * Returns whether we are booting into safe mode.
+     * @return safe mode flag
+     */
+    public boolean isSafeMode() {
+        return mSafeMode;
+    }
+
+    /**
+     * Outputs the state of this manager to the System log.
+     */
+    public void dump() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("Current phase: ").append(mCurrentPhase).append("\n");
+        builder.append("Services:\n");
+        final int startedLen = mServices.size();
+        for (int i = 0; i < startedLen; i++) {
+            final SystemService service = mServices.get(i);
+            builder.append("\t")
+                    .append(service.getClass().getSimpleName())
+                    .append("\n");
+        }
+
+        Slog.e(TAG, builder.toString());
+    }
+}
diff --git a/core/java/com/android/server/net/BaseNetworkObserver.java b/core/java/com/android/server/net/BaseNetworkObserver.java
index fa54c5f..5502a17 100644
--- a/core/java/com/android/server/net/BaseNetworkObserver.java
+++ b/core/java/com/android/server/net/BaseNetworkObserver.java
@@ -17,6 +17,7 @@
 package com.android.server.net;
 
 import android.net.INetworkManagementEventObserver;
+import android.net.LinkAddress;
 
 /**
  * Base {@link INetworkManagementEventObserver} that provides no-op
@@ -36,12 +37,12 @@
     }
 
     @Override
-    public void addressUpdated(String address, String iface, int flags, int scope) {
+    public void addressUpdated(String iface, LinkAddress address) {
         // default no-op
     }
 
     @Override
-    public void addressRemoved(String address, String iface, int flags, int scope) {
+    public void addressRemoved(String iface, LinkAddress address) {
         // default no-op
     }
 
@@ -64,4 +65,9 @@
     public void limitReached(String limitName, String iface) {
         // default no-op
     }
+
+    @Override
+    public void interfaceDnsServerInfo(String iface, long lifetime, String[] servers) {
+        // default no-op
+    }
 }
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 5983120..2e0acb1 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -4,6 +4,9 @@
 LOCAL_CFLAGS += -DHAVE_CONFIG_H -DKHTML_NO_EXCEPTIONS -DGKWQ_NO_JAVA
 LOCAL_CFLAGS += -DNO_SUPPORT_JS_BINDING -DQT_NO_WHEELEVENT -DKHTML_NO_XBL
 LOCAL_CFLAGS += -U__APPLE__
+LOCAL_CFLAGS += -Wno-unused-parameter -Wno-int-to-pointer-cast
+LOCAL_CFLAGS += -Wno-maybe-uninitialized -Wno-parentheses
+LOCAL_CPPFLAGS += -Wno-conversion-null
 
 ifeq ($(TARGET_ARCH), arm)
 	LOCAL_CFLAGS += -DPACKED="__attribute__ ((packed))"
@@ -206,7 +209,6 @@
 	libicuuc \
 	libicui18n \
 	libmedia \
-	libwpa_client \
 	libjpeg \
 	libusbhost \
 	libharfbuzz_ng \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 09577da..97ea5e6 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -447,6 +447,7 @@
     char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
     char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
     char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
+    char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
     char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
     char jitcodecachesizeOptsBuf[sizeof("-Xjitcodecachesize:")-1 + PROPERTY_VALUE_MAX];
     char extraOptsBuf[PROPERTY_VALUE_MAX];
@@ -582,6 +583,13 @@
       mOptions.add(opt);
     }
 
+    strcpy(gctypeOptsBuf, "-Xgc:");
+    property_get("dalvik.vm.gctype", gctypeOptsBuf+5, "");
+    if (gctypeOptsBuf[5] != '\0') {
+        opt.optionString = gctypeOptsBuf;
+        mOptions.add(opt);
+    }
+
     /*
      * Enable or disable dexopt features, such as bytecode verification and
      * calculation of register maps for precise GC.
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 2125763..7143a8a 100644
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -227,7 +227,7 @@
     do {

         *dst++ = SkUnPreMultiply::PMColorToColor(colors[*s++]);

     } while (--width != 0);

-    ctable->unlockColors();

+    ctable->unlockColors(false);

 }

 

 static void ToColor_SI8_Raw(SkColor dst[], const void* src, int width,

@@ -240,7 +240,7 @@
         *dst++ = SkColorSetARGB(SkGetPackedA32(c), SkGetPackedR32(c),

                                 SkGetPackedG32(c), SkGetPackedB32(c));

     } while (--width != 0);

-    ctable->unlockColors();

+    ctable->unlockColors(false);

 }

 

 static void ToColor_SI8_Opaque(SkColor dst[], const void* src, int width,

@@ -253,7 +253,7 @@
         *dst++ = SkColorSetRGB(SkGetPackedR32(c), SkGetPackedG32(c),

                                SkGetPackedB32(c));

     } while (--width != 0);

-    ctable->unlockColors();

+    ctable->unlockColors(false);

 }

 

 // can return NULL

@@ -289,8 +289,9 @@
 }

 

 static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors,

-                              int offset, int stride, int width, int height,

-                              SkBitmap::Config config, jboolean isMutable) {

+                              jint offset, jint stride, jint width, jint height,

+                              jint configHandle, jboolean isMutable) {

+    SkBitmap::Config config = static_cast<SkBitmap::Config>(configHandle);

     if (NULL != jColors) {

         size_t n = env->GetArrayLength(jColors);

         if (n < SkAbs32(stride) * (size_t)height) {

@@ -321,8 +322,10 @@
             getPremulBitmapCreateFlags(isMutable), NULL, NULL);

 }

 

-static jobject Bitmap_copy(JNIEnv* env, jobject, const SkBitmap* src,

-                           SkBitmap::Config dstConfig, jboolean isMutable) {

+static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,

+                           jint dstConfigHandle, jboolean isMutable) {

+    const SkBitmap* src = reinterpret_cast<SkBitmap*>(srcHandle);

+    SkBitmap::Config dstConfig = static_cast<SkBitmap::Config>(dstConfigHandle);

     SkBitmap            result;

     JavaPixelAllocator  allocator(env);

 

@@ -333,7 +336,8 @@
             getPremulBitmapCreateFlags(isMutable), NULL, NULL);

 }

 

-static void Bitmap_destructor(JNIEnv* env, jobject, SkBitmap* bitmap) {

+static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

 #ifdef USE_OPENGL_RENDERER

     if (android::uirenderer::Caches::hasInstance()) {

         android::uirenderer::Caches::getInstance().resourceCache.destructor(bitmap);

@@ -343,24 +347,28 @@
     delete bitmap;

 }

 

-static jboolean Bitmap_recycle(JNIEnv* env, jobject, SkBitmap* bitmap) {

+static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

 #ifdef USE_OPENGL_RENDERER

     if (android::uirenderer::Caches::hasInstance()) {

-        return android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap);

+        bool result;

+        result = android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap);

+        return result ? JNI_TRUE : JNI_FALSE;

     }

 #endif // USE_OPENGL_RENDERER

     bitmap->setPixels(NULL, NULL);

-    return true;

+    return JNI_TRUE;

 }

 

-static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jint bitmapInt,

-        int width, int height, SkBitmap::Config config, int allocSize) {

+static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle,

+        jint width, jint height, jint configHandle, jint allocSize) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    SkBitmap::Config config = static_cast<SkBitmap::Config>(configHandle);    

     if (width * height * SkBitmap::ComputeBytesPerPixel(config) > allocSize) {

         // done in native as there's no way to get BytesPerPixel in Java

         doThrowIAE(env, "Bitmap not large enough to support new configuration");

         return;

     }

-    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapInt);

     SkPixelRef* ref = bitmap->pixelRef();

     SkSafeRef(ref);

     bitmap->setConfig(config, width, height);

@@ -380,9 +388,10 @@
     kWEBP_JavaEncodeFormat = 2

 };

 

-static bool Bitmap_compress(JNIEnv* env, jobject clazz, SkBitmap* bitmap,

-                            int format, int quality,

-                            jobject jstream, jbyteArray jstorage) {

+static jboolean Bitmap_compress(JNIEnv* env, jobject clazz, jlong bitmapHandle,

+                                jint format, jint quality,

+                                jobject jstream, jbyteArray jstorage) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     SkImageEncoder::Type fm;

 

     switch (format) {

@@ -396,7 +405,7 @@
         fm = SkImageEncoder::kWEBP_Type;

         break;

     default:

-        return false;

+        return JNI_FALSE;

     }

 

     bool success = false;

@@ -404,12 +413,12 @@
         SkAutoLockPixels alp(*bitmap);

 

         if (NULL == bitmap->getPixels()) {

-            return false;

+            return JNI_FALSE;

         }

 

         SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);

         if (NULL == strm) {

-            return false;

+            return JNI_FALSE;

         }

 

         SkImageEncoder* encoder = SkImageEncoder::Create(fm);

@@ -419,46 +428,48 @@
         }

         delete strm;

     }

-    return success;

+    return success ? JNI_TRUE : JNI_FALSE;

 }

 

-static void Bitmap_erase(JNIEnv* env, jobject, SkBitmap* bitmap, jint color) {

+static void Bitmap_erase(JNIEnv* env, jobject, jlong bitmapHandle, jint color) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     bitmap->eraseColor(color);

 }

 

-static int Bitmap_rowBytes(JNIEnv* env, jobject, SkBitmap* bitmap) {

-    return bitmap->rowBytes();

+static jint Bitmap_rowBytes(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    return static_cast<jint>(bitmap->rowBytes());

 }

 

-static int Bitmap_config(JNIEnv* env, jobject, SkBitmap* bitmap) {

-    return bitmap->config();

+static jint Bitmap_config(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    return static_cast<jint>(bitmap->config());

 }

 

-static int Bitmap_getGenerationId(JNIEnv* env, jobject, SkBitmap* bitmap) {

-    return bitmap->getGenerationID();

+static jint Bitmap_getGenerationId(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    return static_cast<jint>(bitmap->getGenerationID());

 }

 

-static jboolean Bitmap_hasAlpha(JNIEnv* env, jobject, SkBitmap* bitmap) {

-    return !bitmap->isOpaque();

+static jboolean Bitmap_hasAlpha(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    return !bitmap->isOpaque() ? JNI_TRUE : JNI_FALSE;

 }

 

-static void Bitmap_setAlphaAndPremultiplied(JNIEnv* env, jobject, SkBitmap* bitmap,

-                                            jboolean hasAlpha, jboolean isPremul) {

-    if (!hasAlpha) {

-        bitmap->setAlphaType(kOpaque_SkAlphaType);

-    } else if (isPremul) {

-        bitmap->setAlphaType(kPremul_SkAlphaType);

-    } else {

-        bitmap->setAlphaType(kUnpremul_SkAlphaType);

-    }

+static void Bitmap_setHasAlpha(JNIEnv* env, jobject, jlong bitmapHandle,

+                               jboolean hasAlpha) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    bitmap->setIsOpaque(!hasAlpha);

 }

 

-static jboolean Bitmap_hasMipMap(JNIEnv* env, jobject, SkBitmap* bitmap) {

-    return bitmap->hasHardwareMipMap();

+static jboolean Bitmap_hasMipMap(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    return bitmap->hasHardwareMipMap() ? JNI_TRUE : JNI_FALSE;

 }

 

-static void Bitmap_setHasMipMap(JNIEnv* env, jobject, SkBitmap* bitmap,

+static void Bitmap_setHasMipMap(JNIEnv* env, jobject, jlong bitmapHandle,

                                 jboolean hasMipMap) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     bitmap->setHasHardwareMipMap(hasMipMap);

 }

 

@@ -532,12 +543,13 @@
 }

 

 static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,

-                                     const SkBitmap* bitmap,

+                                     jlong bitmapHandle,

                                      jboolean isMutable, jint density,

                                      jobject parcel) {

+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     if (parcel == NULL) {

         SkDebugf("------- writeToParcel null parcel\n");

-        return false;

+        return JNI_FALSE;

     }

 

     android::Parcel* p = android::parcelForJavaObject(env, parcel);

@@ -549,14 +561,14 @@
     p->writeInt32(bitmap->rowBytes());

     p->writeInt32(density);

 

-    if (bitmap->config() == SkBitmap::kIndex8_Config) {

+    if (bitmap->getConfig() == SkBitmap::kIndex8_Config) {

         SkColorTable* ctable = bitmap->getColorTable();

         if (ctable != NULL) {

             int count = ctable->count();

             p->writeInt32(count);

             memcpy(p->writeInplace(count * sizeof(SkPMColor)),

                    ctable->lockColors(), count * sizeof(SkPMColor));

-            ctable->unlockColors();

+            ctable->unlockColors(false);

         } else {

             p->writeInt32(0);   // indicate no ctable

         }

@@ -568,7 +580,7 @@
     android::status_t status = p->writeBlob(size, &blob);

     if (status) {

         doThrowRE(env, "Could not write bitmap to parcel blob.");

-        return false;

+        return JNI_FALSE;

     }

 

     bitmap->lockPixels();

@@ -581,12 +593,14 @@
     bitmap->unlockPixels();

 

     blob.release();

-    return true;

+    return JNI_TRUE;

 }

 

 static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz,

-                                   const SkBitmap* src, const SkPaint* paint,

+                                   jlong srcHandle, jlong paintHandle,

                                    jintArray offsetXY) {

+    const SkBitmap* src = reinterpret_cast<SkBitmap*>(srcHandle);

+    const SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);

     SkIPoint  offset;

     SkBitmap* dst = new SkBitmap;

     JavaPixelAllocator allocator(env);

@@ -612,8 +626,9 @@
 

 ///////////////////////////////////////////////////////////////////////////////

 

-static int Bitmap_getPixel(JNIEnv* env, jobject, const SkBitmap* bitmap,

-        int x, int y, bool isPremultiplied) {

+static jint Bitmap_getPixel(JNIEnv* env, jobject, jlong bitmapHandle,

+        jint x, jint y, jboolean isPremultiplied) {

+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     SkAutoLockPixels alp(*bitmap);

 

     ToColorProc proc = ChooseToColorProc(*bitmap, isPremultiplied);

@@ -627,12 +642,13 @@
 

     SkColor dst[1];

     proc(dst, src, 1, bitmap->getColorTable());

-    return dst[0];

+    return static_cast<jint>(dst[0]);

 }

 

-static void Bitmap_getPixels(JNIEnv* env, jobject, const SkBitmap* bitmap,

-        jintArray pixelArray, int offset, int stride,

-        int x, int y, int width, int height, bool isPremultiplied) {

+static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle,

+        jintArray pixelArray, jint offset, jint stride,

+        jint x, jint y, jint width, jint height, jboolean isPremultiplied) {

+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     SkAutoLockPixels alp(*bitmap);

 

     ToColorProc proc = ChooseToColorProc(*bitmap, isPremultiplied);

@@ -657,8 +673,10 @@
 

 ///////////////////////////////////////////////////////////////////////////////

 

-static void Bitmap_setPixel(JNIEnv* env, jobject, const SkBitmap* bitmap,

-        int x, int y, SkColor color, bool isPremultiplied) {

+static void Bitmap_setPixel(JNIEnv* env, jobject, jlong bitmapHandle,

+        jint x, jint y, jint colorHandle, jboolean isPremultiplied) {

+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

+    SkColor color = static_cast<SkColor>(colorHandle);

     SkAutoLockPixels alp(*bitmap);

     if (NULL == bitmap->getPixels()) {

         return;

@@ -673,15 +691,17 @@
     bitmap->notifyPixelsChanged();

 }

 

-static void Bitmap_setPixels(JNIEnv* env, jobject, const SkBitmap* bitmap,

-        jintArray pixelArray, int offset, int stride,

-        int x, int y, int width, int height, bool isPremultiplied) {

+static void Bitmap_setPixels(JNIEnv* env, jobject, jlong bitmapHandle,

+        jintArray pixelArray, jint offset, jint stride,

+        jint x, jint y, jint width, jint height, jboolean isPremultiplied) {

+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     GraphicsJNI::SetPixels(env, pixelArray, offset, stride,

             x, y, width, height, *bitmap, isPremultiplied);

 }

 

 static void Bitmap_copyPixelsToBuffer(JNIEnv* env, jobject,

-                                      const SkBitmap* bitmap, jobject jbuffer) {

+                                      jlong bitmapHandle, jobject jbuffer) {

+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     SkAutoLockPixels alp(*bitmap);

     const void* src = bitmap->getPixels();

 

@@ -694,7 +714,8 @@
 }

 

 static void Bitmap_copyPixelsFromBuffer(JNIEnv* env, jobject,

-                                    const SkBitmap* bitmap, jobject jbuffer) {

+                                        jlong bitmapHandle, jobject jbuffer) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     SkAutoLockPixels alp(*bitmap);

     void* dst = bitmap->getPixels();

 

@@ -706,12 +727,14 @@
     }

 }

 

-static bool Bitmap_sameAs(JNIEnv* env, jobject, const SkBitmap* bm0,

-                             const SkBitmap* bm1) {

+static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle,

+                              jlong bm1Handle) {

+    const SkBitmap* bm0 = reinterpret_cast<SkBitmap*>(bm0Handle);

+    const SkBitmap* bm1 = reinterpret_cast<SkBitmap*>(bm1Handle);

     if (bm0->width() != bm1->width() ||

         bm0->height() != bm1->height() ||

         bm0->config() != bm1->config()) {

-        return false;

+        return JNI_FALSE;

     }

 

     SkAutoLockPixels alp0(*bm0);

@@ -719,24 +742,24 @@
 

     // if we can't load the pixels, return false

     if (NULL == bm0->getPixels() || NULL == bm1->getPixels()) {

-        return false;

+        return JNI_FALSE;

     }

 

     if (bm0->config() == SkBitmap::kIndex8_Config) {

         SkColorTable* ct0 = bm0->getColorTable();

         SkColorTable* ct1 = bm1->getColorTable();

         if (NULL == ct0 || NULL == ct1) {

-            return false;

+            return JNI_FALSE;

         }

         if (ct0->count() != ct1->count()) {

-            return false;

+            return JNI_FALSE;

         }

 

         SkAutoLockColors alc0(ct0);

         SkAutoLockColors alc1(ct1);

         const size_t size = ct0->count() * sizeof(SkPMColor);

         if (memcmp(alc0.colors(), alc1.colors(), size) != 0) {

-            return false;

+            return JNI_FALSE;

         }

     }

 

@@ -747,13 +770,14 @@
     const size_t size = bm0->width() * bm0->bytesPerPixel();

     for (int y = 0; y < h; y++) {

         if (memcmp(bm0->getAddr(0, y), bm1->getAddr(0, y), size) != 0) {

-            return false;

+            return JNI_FALSE;

         }

     }

-    return true;

+    return JNI_TRUE;

 }

 

-static void Bitmap_prepareToDraw(JNIEnv* env, jobject, SkBitmap* bitmap) {

+static void Bitmap_prepareToDraw(JNIEnv* env, jobject, jlong bitmapHandle) {

+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);

     bitmap->lockPixels();

     bitmap->unlockPixels();

 }

@@ -765,38 +789,38 @@
 static JNINativeMethod gBitmapMethods[] = {

     {   "nativeCreate",             "([IIIIIIZ)Landroid/graphics/Bitmap;",

         (void*)Bitmap_creator },

-    {   "nativeCopy",               "(IIZ)Landroid/graphics/Bitmap;",

+    {   "nativeCopy",               "(JIZ)Landroid/graphics/Bitmap;",

         (void*)Bitmap_copy },

-    {   "nativeDestructor",         "(I)V", (void*)Bitmap_destructor },

-    {   "nativeRecycle",            "(I)Z", (void*)Bitmap_recycle },

-    {   "nativeReconfigure",        "(IIIII)V", (void*)Bitmap_reconfigure },

-    {   "nativeCompress",           "(IIILjava/io/OutputStream;[B)Z",

+    {   "nativeDestructor",         "(J)V", (void*)Bitmap_destructor },

+    {   "nativeRecycle",            "(J)Z", (void*)Bitmap_recycle },

+    {   "nativeReconfigure",        "(JIIII)V", (void*)Bitmap_reconfigure },

+    {   "nativeCompress",           "(JIILjava/io/OutputStream;[B)Z",

         (void*)Bitmap_compress },

-    {   "nativeErase",              "(II)V", (void*)Bitmap_erase },

-    {   "nativeRowBytes",           "(I)I", (void*)Bitmap_rowBytes },

-    {   "nativeConfig",             "(I)I", (void*)Bitmap_config },

-    {   "nativeHasAlpha",           "(I)Z", (void*)Bitmap_hasAlpha },

-    {   "nativeSetAlphaAndPremultiplied", "(IZZ)V", (void*)Bitmap_setAlphaAndPremultiplied},

-    {   "nativeHasMipMap",          "(I)Z", (void*)Bitmap_hasMipMap },

-    {   "nativeSetHasMipMap",       "(IZ)V", (void*)Bitmap_setHasMipMap },

+    {   "nativeErase",              "(JI)V", (void*)Bitmap_erase },

+    {   "nativeRowBytes",           "(J)I", (void*)Bitmap_rowBytes },

+    {   "nativeConfig",             "(J)I", (void*)Bitmap_config },

+    {   "nativeHasAlpha",           "(J)Z", (void*)Bitmap_hasAlpha },

+    {   "nativeSetHasAlpha",        "(JZ)V", (void*)Bitmap_setHasAlpha },

+    {   "nativeHasMipMap",          "(J)Z", (void*)Bitmap_hasMipMap },

+    {   "nativeSetHasMipMap",       "(JZ)V", (void*)Bitmap_setHasMipMap },

     {   "nativeCreateFromParcel",

         "(Landroid/os/Parcel;)Landroid/graphics/Bitmap;",

         (void*)Bitmap_createFromParcel },

-    {   "nativeWriteToParcel",      "(IZILandroid/os/Parcel;)Z",

+    {   "nativeWriteToParcel",      "(JZILandroid/os/Parcel;)Z",

         (void*)Bitmap_writeToParcel },

-    {   "nativeExtractAlpha",       "(II[I)Landroid/graphics/Bitmap;",

+    {   "nativeExtractAlpha",       "(JJ[I)Landroid/graphics/Bitmap;",

         (void*)Bitmap_extractAlpha },

-    {   "nativeGenerationId",       "(I)I", (void*)Bitmap_getGenerationId },

-    {   "nativeGetPixel",           "(IIIZ)I", (void*)Bitmap_getPixel },

-    {   "nativeGetPixels",          "(I[IIIIIIIZ)V", (void*)Bitmap_getPixels },

-    {   "nativeSetPixel",           "(IIIIZ)V", (void*)Bitmap_setPixel },

-    {   "nativeSetPixels",          "(I[IIIIIIIZ)V", (void*)Bitmap_setPixels },

-    {   "nativeCopyPixelsToBuffer", "(ILjava/nio/Buffer;)V",

+    {   "nativeGenerationId",       "(J)I", (void*)Bitmap_getGenerationId },

+    {   "nativeGetPixel",           "(JIIZ)I", (void*)Bitmap_getPixel },

+    {   "nativeGetPixels",          "(J[IIIIIIIZ)V", (void*)Bitmap_getPixels },

+    {   "nativeSetPixel",           "(JIIIZ)V", (void*)Bitmap_setPixel },

+    {   "nativeSetPixels",          "(J[IIIIIIIZ)V", (void*)Bitmap_setPixels },

+    {   "nativeCopyPixelsToBuffer", "(JLjava/nio/Buffer;)V",

                                             (void*)Bitmap_copyPixelsToBuffer },

-    {   "nativeCopyPixelsFromBuffer", "(ILjava/nio/Buffer;)V",

+    {   "nativeCopyPixelsFromBuffer", "(JLjava/nio/Buffer;)V",

                                             (void*)Bitmap_copyPixelsFromBuffer },

-    {   "nativeSameAs",             "(II)Z", (void*)Bitmap_sameAs },

-    {   "nativePrepareToDraw",      "(I)V", (void*)Bitmap_prepareToDraw },

+    {   "nativeSameAs",             "(JJ)Z", (void*)Bitmap_sameAs },

+    {   "nativePrepareToDraw",      "(J)V", (void*)Bitmap_prepareToDraw },

 };

 

 #define kClassPathName  "android/graphics/Bitmap"

diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 709de5c..56d903c 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -21,7 +21,6 @@
 #include <androidfw/Asset.h>
 #include <androidfw/ResourceTypes.h>
 #include <netinet/in.h>
-#include <stdio.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 
@@ -125,18 +124,12 @@
 static SkPixelRef* installPixelRef(SkBitmap* bitmap, SkStreamRewindable* stream,
         int sampleSize, bool ditherImage) {
 
-    SkImageInfo bitmapInfo;
-    if (!bitmap->asImageInfo(&bitmapInfo)) {
-        ALOGW("bitmap has unknown configuration so no memory has been allocated");
-        return NULL;
-    }
-
     SkImageRef* pr;
     // only use ashmem for large images, since mmaps come at a price
     if (bitmap->getSize() >= 32 * 1024) {
-        pr = new SkImageRef_ashmem(bitmapInfo, stream, sampleSize);
+        pr = new SkImageRef_ashmem(stream, bitmap->config(), sampleSize);
     } else {
-        pr = new SkImageRef_GlobalPool(bitmapInfo, stream, sampleSize);
+        pr = new SkImageRef_GlobalPool(stream, bitmap->config(), sampleSize);
     }
     pr->setDitherImage(ditherImage);
     bitmap->setPixelRef(pr)->unref();
@@ -164,7 +157,7 @@
     virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
         // accounts for scale in final allocation, using eventual size and config
         const int bytesPerPixel = SkBitmap::ComputeBytesPerPixel(
-                configForScaledOutput(bitmap->config()));
+                configForScaledOutput(bitmap->getConfig()));
         const int requestedSize = bytesPerPixel *
                 int(bitmap->width() * mScale + 0.5f) *
                 int(bitmap->height() * mScale + 0.5f);
@@ -198,15 +191,8 @@
             return false;
         }
 
-        SkImageInfo bitmapInfo;
-        if (!bitmap->asImageInfo(&bitmapInfo)) {
-            ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration");
-            return false;
-        }
-
         // Create a new pixelref with the new ctable that wraps the previous pixelref
-        SkPixelRef* pr = new AndroidPixelRef(*static_cast<AndroidPixelRef*>(mPixelRef),
-                bitmapInfo, bitmap->rowBytes(), ctable);
+        SkPixelRef* pr = new AndroidPixelRef(*static_cast<AndroidPixelRef*>(mPixelRef), ctable);
 
         bitmap->setPixelRef(pr)->unref();
         // since we're already allocated, we lockPixels right away
@@ -286,7 +272,7 @@
     SkBitmap* outputBitmap = NULL;
     unsigned int existingBufferSize = 0;
     if (javaBitmap != NULL) {
-        outputBitmap = (SkBitmap*) env->GetIntField(javaBitmap, gBitmap_nativeBitmapFieldID);
+        outputBitmap = (SkBitmap*) env->GetLongField(javaBitmap, gBitmap_nativeBitmapFieldID);
         if (outputBitmap->isImmutable()) {
             ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
             javaBitmap = NULL;
@@ -415,11 +401,8 @@
 
         // TODO: avoid copying when scaled size equals decodingBitmap size
         SkBitmap::Config config = configForScaledOutput(decodingBitmap.config());
-        // FIXME: If the alphaType is kUnpremul and the image has alpha, the
-        // colors may not be correct, since Skia does not yet support drawing
-        // to/from unpremultiplied bitmaps.
-        outputBitmap->setConfig(config, scaledWidth, scaledHeight, 0,
-                                decodingBitmap.alphaType());
+        outputBitmap->setConfig(config, scaledWidth, scaledHeight);
+        outputBitmap->setIsOpaque(decodingBitmap.isOpaque());
         if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
             return nullObjectReturn("allocation failed for scaled bitmap");
         }
@@ -431,7 +414,7 @@
         }
 
         SkPaint paint;
-        paint.setFilterLevel(SkPaint::kLow_FilterLevel);
+        paint.setFilterBitmap(true);
 
         SkCanvas canvas(*outputBitmap);
         canvas.scale(sx, sy);
@@ -487,12 +470,6 @@
             bitmapCreateFlags, ninePatchChunk, layoutBounds, -1);
 }
 
-// Need to buffer enough input to be able to rewind as much as might be read by a decoder
-// trying to determine the stream's format. Currently the most is 64, read by
-// SkImageDecoder_libwebp.
-// FIXME: Get this number from SkImageDecoder
-#define BYTES_TO_BUFFER 64
-
 static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteArray storage,
         jobject padding, jobject options) {
 
@@ -500,8 +477,11 @@
     SkAutoTUnref<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage));
 
     if (stream.get()) {
-        SkAutoTUnref<SkStreamRewindable> bufferedStream(
-                SkFrontBufferedStream::Create(stream, BYTES_TO_BUFFER));
+        // Need to buffer enough input to be able to rewind as much as might be read by a decoder
+        // trying to determine the stream's format. Currently the most is 64, read by
+        // SkImageDecoder_libwebp.
+        // FIXME: Get this number from SkImageDecoder
+        SkAutoTUnref<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Create(stream, 64));
         SkASSERT(bufferedStream.get() != NULL);
         // for now we don't allow purgeable with java inputstreams
         bitmap = doDecode(env, bufferedStream, padding, options, false, false);
@@ -522,51 +502,30 @@
         return nullObjectReturn("fstat return -1");
     }
 
-    // Restore the descriptor's offset on exiting this function.
-    AutoFDSeek autoRestore(descriptor);
-
-    FILE* file = fdopen(descriptor, "r");
-    if (file == NULL) {
-        return nullObjectReturn("Could not open file");
+    bool isPurgeable = optionsPurgeable(env, bitmapFactoryOptions);
+    bool isShareable = optionsShareable(env, bitmapFactoryOptions);
+    bool weOwnTheFD = false;
+    if (isPurgeable && isShareable) {
+        int newFD = ::dup(descriptor);
+        if (-1 != newFD) {
+            weOwnTheFD = true;
+            descriptor = newFD;
+        }
     }
 
-    SkAutoTUnref<SkFILEStream> fileStream(new SkFILEStream(file,
-                         SkFILEStream::kCallerRetains_Ownership));
-
-    SkAutoTUnref<SkStreamRewindable> stream;
-
-    // Retain the old behavior of allowing purgeable if both purgeable and
-    // shareable are set to true.
-    bool isPurgeable = optionsPurgeable(env, bitmapFactoryOptions)
-                       && optionsShareable(env, bitmapFactoryOptions);
-    if (isPurgeable) {
-        // Copy the stream, so the image can be decoded multiple times without
-        // continuing to modify the original file descriptor.
-        // Copy beginning from the current position.
-        const size_t fileSize = fileStream->getLength() - fileStream->getPosition();
-        void* buffer = sk_malloc_flags(fileSize, 0);
-        if (buffer == NULL) {
-            return nullObjectReturn("Could not make a copy for ashmem");
-        }
-
-        SkAutoTUnref<SkData> data(SkData::NewFromMalloc(buffer, fileSize));
-
-        if (fileStream->read(buffer, fileSize) != fileSize) {
-            return nullObjectReturn("Could not read the file.");
-        }
-
-        stream.reset(new SkMemoryStream(data));
-    } else {
-        // Use a buffered stream. Although an SkFILEStream can be rewound, this
-        // ensures that SkImageDecoder::Factory never rewinds beyond the
-        // current position of the file descriptor.
-        stream.reset(SkFrontBufferedStream::Create(fileStream, BYTES_TO_BUFFER));
+    SkAutoTUnref<SkData> data(SkData::NewFromFD(descriptor));
+    if (data.get() == NULL) {
+        return nullObjectReturn("NewFromFD failed in nativeDecodeFileDescriptor");
     }
+    SkAutoTUnref<SkMemoryStream> stream(new SkMemoryStream(data));
 
-    return doDecode(env, stream, padding, bitmapFactoryOptions, isPurgeable);
+    /* Allow purgeable iff we own the FD, i.e., in the puregeable and
+       shareable case.
+    */
+    return doDecode(env, stream, padding, bitmapFactoryOptions, weOwnTheFD);
 }
 
-static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jint native_asset,
+static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jlong native_asset,
         jobject padding, jobject options) {
 
     SkStreamRewindable* stream;
@@ -582,16 +541,14 @@
     } else {
         // since we know we'll be done with the asset when we return, we can
         // just use a simple wrapper
-        stream = new AssetStreamAdaptor(asset,
-                                        AssetStreamAdaptor::kNo_OwnAsset,
-                                        AssetStreamAdaptor::kNo_HasMemoryBase);
+        stream = new AssetStreamAdaptor(asset);
     }
     SkAutoUnref aur(stream);
     return doDecode(env, stream, padding, options, forcePurgeable, forcePurgeable);
 }
 
 static jobject nativeDecodeByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
-        int offset, int length, jobject options) {
+        jint offset, jint length, jobject options) {
 
     /*  If optionsShareable() we could decide to just wrap the java array and
         share it, but that means adding a globalref to the java array object
@@ -628,7 +585,7 @@
     },
 
     {   "nativeDecodeAsset",
-        "(ILandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
+        "(JLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
         (void*)nativeDecodeAsset
     },
 
@@ -681,7 +638,7 @@
 
     jclass bitmap_class = env->FindClass("android/graphics/Bitmap");
     SkASSERT(bitmap_class);
-    gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "I");
+    gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "J");
     gBitmap_layoutBoundsFieldID = getFieldIDCheck(env, bitmap_class, "mLayoutBounds", "[I");
     int ret = AndroidRuntime::registerNativeMethods(env,
                                     "android/graphics/BitmapFactory$Options",
diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp
index 1412a0e..e7d2422 100644
--- a/core/jni/android/graphics/BitmapRegionDecoder.cpp
+++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp
@@ -29,6 +29,7 @@
 #include "CreateJavaOutputStreamAdaptor.h"
 #include "Utils.h"
 #include "JNIHelp.h"
+#include "SkTScopedPtr.h"
 
 #include <android_runtime/AndroidRuntime.h>
 #include "android_util_Binder.h"
@@ -75,7 +76,7 @@
     int fHeight;
 };
 
-static jobject createBitmapRegionDecoder(JNIEnv* env, SkStreamRewindable* stream) {
+static jobject createBitmapRegionDecoder(JNIEnv* env, SkStream* stream) {
     SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
     int width, height;
     if (NULL == decoder) {
@@ -101,13 +102,13 @@
 }
 
 static jobject nativeNewInstanceFromByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
-                                     int offset, int length, jboolean isShareable) {
+                                     jint offset, jint length, jboolean isShareable) {
     /*  If isShareable we could decide to just wrap the java array and
         share it, but that means adding a globalref to the java array object
         For now we just always copy the array's data if isShareable.
      */
     AutoJavaByteArray ar(env, byteArray);
-    SkStreamRewindable* stream = new SkMemoryStream(ar.ptr() + offset, length, true);
+    SkStream* stream = new SkMemoryStream(ar.ptr() + offset, length, true);
 
     jobject brd = createBitmapRegionDecoder(env, stream);
     SkSafeUnref(stream); // the decoder now holds a reference
@@ -150,7 +151,7 @@
 }
 
 static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz,
-                                 jint native_asset, // Asset
+                                 jlong native_asset, // Asset
                                  jboolean isShareable) {
     Asset* asset = reinterpret_cast<Asset*>(native_asset);
     SkAutoTUnref<SkMemoryStream> stream(CopyAssetToStream(asset));
@@ -169,8 +170,9 @@
  * purgeable not supported
  * reportSizeToVM not supported
  */
-static jobject nativeDecodeRegion(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd,
-                                int start_x, int start_y, int width, int height, jobject options) {
+static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle,
+                                jint start_x, jint start_y, jint width, jint height, jobject options) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
     jobject tileBitmap = NULL;
     SkImageDecoder *decoder = brd->getDecoder();
     int sampleSize = 1;
@@ -214,7 +216,7 @@
     region.fRight = start_x + width;
     region.fBottom = start_y + height;
     SkBitmap* bitmap = NULL;
-    SkAutoTDelete<SkBitmap> adb;
+    SkTScopedPtr<SkBitmap> adb;
 
     if (tileBitmap != NULL) {
         // Re-use bitmap.
@@ -245,7 +247,7 @@
     }
 
     // detach bitmap from its autodeleter, since we want to own it now
-    adb.detach();
+    adb.release();
 
     JavaPixelAllocator* allocator = (JavaPixelAllocator*) decoder->getAllocator();
     jbyteArray buff = allocator->getStorageObjAndReset();
@@ -255,15 +257,18 @@
     return GraphicsJNI::createBitmap(env, bitmap, buff, bitmapCreateFlags, NULL, NULL, -1);
 }
 
-static int nativeGetHeight(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) {
-    return brd->getHeight();
+static jint nativeGetHeight(JNIEnv* env, jobject, jlong brdHandle) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+    return static_cast<jint>(brd->getHeight());
 }
 
-static int nativeGetWidth(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) {
-    return brd->getWidth();
+static jint nativeGetWidth(JNIEnv* env, jobject, jlong brdHandle) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+    return static_cast<jint>(brd->getWidth());
 }
 
-static void nativeClean(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) {
+static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
     delete brd;
 }
 
@@ -273,14 +278,14 @@
 
 static JNINativeMethod gBitmapRegionDecoderMethods[] = {
     {   "nativeDecodeRegion",
-        "(IIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
+        "(JIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
         (void*)nativeDecodeRegion},
 
-    {   "nativeGetHeight", "(I)I", (void*)nativeGetHeight},
+    {   "nativeGetHeight", "(J)I", (void*)nativeGetHeight},
 
-    {   "nativeGetWidth", "(I)I", (void*)nativeGetWidth},
+    {   "nativeGetWidth", "(J)I", (void*)nativeGetWidth},
 
-    {   "nativeClean", "(I)V", (void*)nativeClean},
+    {   "nativeClean", "(J)V", (void*)nativeClean},
 
     {   "nativeNewInstance",
         "([BIIZ)Landroid/graphics/BitmapRegionDecoder;",
@@ -298,7 +303,7 @@
     },
 
     {   "nativeNewInstance",
-        "(IZ)Landroid/graphics/BitmapRegionDecoder;",
+        "(JZ)Landroid/graphics/BitmapRegionDecoder;",
         (void*)nativeNewInstanceFromAsset
     },
 };
diff --git a/core/jni/android/graphics/Camera.cpp b/core/jni/android/graphics/Camera.cpp
index 5176d9a..54d448e 100644
--- a/core/jni/android/graphics/Camera.cpp
+++ b/core/jni/android/graphics/Camera.cpp
@@ -7,84 +7,102 @@
 
 static void Camera_constructor(JNIEnv* env, jobject obj) {
     Sk3DView* view = new Sk3DView;
-    env->SetIntField(obj, gNativeInstanceFieldID, (int)view);
+    env->SetLongField(obj, gNativeInstanceFieldID, reinterpret_cast<jlong>(view));
 }
 
 static void Camera_destructor(JNIEnv* env, jobject obj) {
-    delete (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* view = reinterpret_cast<Sk3DView*>(viewHandle);
+    delete view;
 }
 
 static void Camera_save(JNIEnv* env, jobject obj) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->save();
 }
 
 static void Camera_restore(JNIEnv* env, jobject obj) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->restore();
 }
 
 static void Camera_translate(JNIEnv* env, jobject obj,
-                             float dx, float dy, float dz) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+                             jfloat dx, jfloat dy, jfloat dz) {
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->translate(SkFloatToScalar(dx), SkFloatToScalar(dy), SkFloatToScalar(dz));
 }
 
-static void Camera_rotateX(JNIEnv* env, jobject obj, float degrees) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+static void Camera_rotateX(JNIEnv* env, jobject obj, jfloat degrees) {
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->rotateX(SkFloatToScalar(degrees));
 }
 
-static void Camera_rotateY(JNIEnv* env, jobject obj, float degrees) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+static void Camera_rotateY(JNIEnv* env, jobject obj, jfloat degrees) {
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->rotateY(SkFloatToScalar(degrees));
 }
 
-static void Camera_rotateZ(JNIEnv* env, jobject obj, float degrees) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+static void Camera_rotateZ(JNIEnv* env, jobject obj, jfloat degrees) {
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->rotateZ(SkFloatToScalar(degrees));
 }
 
 static void Camera_rotate(JNIEnv* env, jobject obj, jfloat x, jfloat y, jfloat z) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->rotateX(SkFloatToScalar(x));
     v->rotateY(SkFloatToScalar(y));
     v->rotateZ(SkFloatToScalar(z));
 }
 
 static void Camera_setLocation(JNIEnv* env, jobject obj, jfloat x, jfloat y, jfloat z) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->setCameraLocation(SkFloatToScalar(x), SkFloatToScalar(y), SkFloatToScalar(z));
 }
 
 static jfloat Camera_getLocationX(JNIEnv* env, jobject obj) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     return SkScalarToFloat(v->getCameraLocationX());
 }
 
 static jfloat Camera_getLocationY(JNIEnv* env, jobject obj) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     return SkScalarToFloat(v->getCameraLocationY());
 }
 
 static jfloat Camera_getLocationZ(JNIEnv* env, jobject obj) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     return SkScalarToFloat(v->getCameraLocationZ());
 }
 
-static void Camera_getMatrix(JNIEnv* env, jobject obj, int native_matrix) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
-    v->getMatrix((SkMatrix*)native_matrix);
+static void Camera_getMatrix(JNIEnv* env, jobject obj, jlong matrixHandle) {
+    SkMatrix* native_matrix =  reinterpret_cast<SkMatrix*>(matrixHandle);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
+    v->getMatrix(native_matrix);
 }
 
-static void Camera_applyToCanvas(JNIEnv* env, jobject obj, int native_canvas) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+static void Camera_applyToCanvas(JNIEnv* env, jobject obj, jlong canvasHandle) {
+    SkCanvas* native_canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     v->applyToCanvas((SkCanvas*)native_canvas);
 }
 
-static float Camera_dotWithNormal(JNIEnv* env, jobject obj,
-                                  float x, float y, float z) {
-    Sk3DView* v = (Sk3DView*)env->GetIntField(obj, gNativeInstanceFieldID);
+static jfloat Camera_dotWithNormal(JNIEnv* env, jobject obj,
+                                  jfloat x, jfloat y, jfloat z) {
+    jlong viewHandle = env->GetLongField(obj, gNativeInstanceFieldID);
+    Sk3DView* v = reinterpret_cast<Sk3DView*>(viewHandle);
     SkScalar dot = v->dotWithNormal(SkFloatToScalar(x), SkFloatToScalar(y),
                                     SkFloatToScalar(z));
     return SkScalarToFloat(dot);
@@ -111,8 +129,8 @@
     { "getLocationX",        "()F",    (void*)Camera_getLocationX  },
     { "getLocationY",        "()F",    (void*)Camera_getLocationY  },
     { "getLocationZ",        "()F",    (void*)Camera_getLocationZ  },
-    { "nativeGetMatrix",     "(I)V",   (void*)Camera_getMatrix     },
-    { "nativeApplyToCanvas", "(I)V",   (void*)Camera_applyToCanvas },
+    { "nativeGetMatrix",     "(J)V",   (void*)Camera_getMatrix     },
+    { "nativeApplyToCanvas", "(J)V",   (void*)Camera_applyToCanvas },
     { "dotWithNormal",       "(FFF)F", (void*)Camera_dotWithNormal }
 };
 
@@ -121,7 +139,7 @@
     if (clazz == 0) {
         return -1;
     }
-    gNativeInstanceFieldID = env->GetFieldID(clazz, "native_instance", "I");
+    gNativeInstanceFieldID = env->GetFieldID(clazz, "native_instance", "J");
     if (gNativeInstanceFieldID == 0) {
         return -1;
     }
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index edf3b4a..89490bc 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -38,13 +38,13 @@
 static uint32_t get_thread_msec() {
 #if defined(HAVE_POSIX_CLOCKS)
     struct timespec tm;
-    
+
     clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm);
-    
+
     return tm.tv_sec * 1000LL + tm.tv_nsec / 1000000;
 #else
     struct timeval tv;
-    
+
     gettimeofday(&tv, NULL);
     return tv.tv_sec * 1000LL + tv.tv_usec / 1000;
 #endif
@@ -70,23 +70,27 @@
 class SkCanvasGlue {
 public:
 
-    static void finalizer(JNIEnv* env, jobject clazz, SkCanvas* canvas) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong canvasHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         canvas->unref();
     }
 
-    static SkCanvas* initRaster(JNIEnv* env, jobject, SkBitmap* bitmap) {
+    static jlong initRaster(JNIEnv* env, jobject, jlong bitmapHandle) {
+        SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
         if (bitmap) {
-            return new SkCanvas(*bitmap);
+            return reinterpret_cast<jlong>(new SkCanvas(*bitmap));
         } else {
             // Create an empty bitmap device to prevent callers from crashing
             // if they attempt to draw into this canvas.
             SkBitmap emptyBitmap;
-            return new SkCanvas(emptyBitmap);
+            return reinterpret_cast<jlong>(new SkCanvas(emptyBitmap));
         }
     }
-    
+
     static void copyCanvasState(JNIEnv* env, jobject clazz,
-                                SkCanvas* srcCanvas, SkCanvas* dstCanvas) {
+                                jlong srcCanvasHandle, jlong dstCanvasHandle) {
+        SkCanvas* srcCanvas = reinterpret_cast<SkCanvas*>(srcCanvasHandle);
+        SkCanvas* dstCanvas = reinterpret_cast<SkCanvas*>(dstCanvasHandle);
         if (srcCanvas && dstCanvas) {
             dstCanvas->setMatrix(srcCanvas->getTotalMatrix());
             if (NULL != srcCanvas->getDevice() && NULL != dstCanvas->getDevice()) {
@@ -110,73 +114,89 @@
     static jboolean isOpaque(JNIEnv* env, jobject jcanvas) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
         SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
-        return canvas->getDevice()->accessBitmap(false).isOpaque();
-    }
-    
-    static int getWidth(JNIEnv* env, jobject jcanvas) {
-        NPE_CHECK_RETURN_ZERO(env, jcanvas);
-        SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
-        return canvas->getDevice()->accessBitmap(false).width();
-    }
-    
-    static int getHeight(JNIEnv* env, jobject jcanvas) {
-        NPE_CHECK_RETURN_ZERO(env, jcanvas);
-        SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
-        return canvas->getDevice()->accessBitmap(false).height();
+        bool result = canvas->getDevice()->accessBitmap(false).isOpaque();
+        return result ? JNI_TRUE : JNI_FALSE;
     }
 
-    static int saveAll(JNIEnv* env, jobject jcanvas) {
+    static jint getWidth(JNIEnv* env, jobject jcanvas) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
-        return GraphicsJNI::getNativeCanvas(env, jcanvas)->save();
+        SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
+        int width = canvas->getDevice()->accessBitmap(false).width();
+        return static_cast<jint>(width);
     }
-    
-    static int save(JNIEnv* env, jobject jcanvas, SkCanvas::SaveFlags flags) {
+
+    static jint getHeight(JNIEnv* env, jobject jcanvas) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
-        return GraphicsJNI::getNativeCanvas(env, jcanvas)->save(flags);
+        SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
+        int height = canvas->getDevice()->accessBitmap(false).height();
+        return static_cast<jint>(height);
     }
-    
-    static int saveLayer(JNIEnv* env, jobject, SkCanvas* canvas, jobject bounds,
-                         SkPaint* paint, int flags) {
+
+    static jint saveAll(JNIEnv* env, jobject jcanvas) {
+        NPE_CHECK_RETURN_ZERO(env, jcanvas);
+        int result = GraphicsJNI::getNativeCanvas(env, jcanvas)->save();
+        return static_cast<jint>(result);
+    }
+
+    static jint save(JNIEnv* env, jobject jcanvas, jint flagsHandle) {
+        SkCanvas::SaveFlags flags = static_cast<SkCanvas::SaveFlags>(flagsHandle);
+        NPE_CHECK_RETURN_ZERO(env, jcanvas);
+        int result = GraphicsJNI::getNativeCanvas(env, jcanvas)->save(flags);
+        return static_cast<jint>(result);
+    }
+
+    static jint saveLayer(JNIEnv* env, jobject, jlong canvasHandle, jobject bounds,
+                         jlong paintHandle, jint flags) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint  = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect* bounds_ = NULL;
         SkRect  storage;
         if (bounds != NULL) {
             GraphicsJNI::jrectf_to_rect(env, bounds, &storage);
             bounds_ = &storage;
         }
-        return canvas->saveLayer(bounds_, paint, (SkCanvas::SaveFlags)flags);
+        return canvas->saveLayer(bounds_, paint, static_cast<SkCanvas::SaveFlags>(flags));
     }
- 
-    static int saveLayer4F(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static jint saveLayer4F(JNIEnv* env, jobject, jlong canvasHandle,
                            jfloat l, jfloat t, jfloat r, jfloat b,
-                           SkPaint* paint, int flags) {
+                           jlong paintHandle, jint flags) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint  = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect bounds;
         bounds.set(SkFloatToScalar(l), SkFloatToScalar(t), SkFloatToScalar(r),
                    SkFloatToScalar(b));
-        return canvas->saveLayer(&bounds, paint, (SkCanvas::SaveFlags)flags);
+        int result = canvas->saveLayer(&bounds, paint,
+                                      static_cast<SkCanvas::SaveFlags>(flags));
+        return static_cast<jint>(result);
     }
- 
-    static int saveLayerAlpha(JNIEnv* env, jobject, SkCanvas* canvas,
-                              jobject bounds, int alpha, int flags) {
+
+    static jint saveLayerAlpha(JNIEnv* env, jobject, jlong canvasHandle,
+                              jobject bounds, jint alpha, jint flags) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         SkRect* bounds_ = NULL;
         SkRect  storage;
         if (bounds != NULL) {
             GraphicsJNI::jrectf_to_rect(env, bounds, &storage);
             bounds_ = &storage;
         }
-        return canvas->saveLayerAlpha(bounds_, alpha,
-                                      (SkCanvas::SaveFlags)flags);
+        int result = canvas->saveLayerAlpha(bounds_, alpha,
+                                      static_cast<SkCanvas::SaveFlags>(flags));
+        return static_cast<jint>(result);
     }
- 
-    static int saveLayerAlpha4F(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static jint saveLayerAlpha4F(JNIEnv* env, jobject, jlong canvasHandle,
                                 jfloat l, jfloat t, jfloat r, jfloat b,
-                                int alpha, int flags) {
+                                jint alpha, jint flags) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         SkRect  bounds;
         bounds.set(SkFloatToScalar(l), SkFloatToScalar(t), SkFloatToScalar(r),
                    SkFloatToScalar(b));
-        return canvas->saveLayerAlpha(&bounds, alpha,
-                                      (SkCanvas::SaveFlags)flags);
+        int result = canvas->saveLayerAlpha(&bounds, alpha,
+                                      static_cast<SkCanvas::SaveFlags>(flags));
+        return static_cast<jint>(result);
     }
- 
+
     static void restore(JNIEnv* env, jobject jcanvas) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
@@ -186,13 +206,14 @@
         }
         canvas->restore();
     }
- 
-    static int getSaveCount(JNIEnv* env, jobject jcanvas) {
+
+    static jint getSaveCount(JNIEnv* env, jobject jcanvas) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
-        return GraphicsJNI::getNativeCanvas(env, jcanvas)->getSaveCount();
+        int result = GraphicsJNI::getNativeCanvas(env, jcanvas)->getSaveCount();
+        return static_cast<jint>(result);
     }
- 
-    static void restoreToCount(JNIEnv* env, jobject jcanvas, int restoreCount) {
+
+    static void restoreToCount(JNIEnv* env, jobject jcanvas, jint restoreCount) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
         if (restoreCount < 1) {
@@ -201,48 +222,52 @@
         }
         canvas->restoreToCount(restoreCount);
     }
- 
+
     static void translate(JNIEnv* env, jobject jcanvas, jfloat dx, jfloat dy) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         (void)GraphicsJNI::getNativeCanvas(env, jcanvas)->translate(dx_, dy_);
     }
- 
+
     static void scale__FF(JNIEnv* env, jobject jcanvas, jfloat sx, jfloat sy) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
         (void)GraphicsJNI::getNativeCanvas(env, jcanvas)->scale(sx_, sy_);
     }
- 
+
     static void rotate__F(JNIEnv* env, jobject jcanvas, jfloat degrees) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         SkScalar degrees_ = SkFloatToScalar(degrees);
         (void)GraphicsJNI::getNativeCanvas(env, jcanvas)->rotate(degrees_);
     }
- 
+
     static void skew__FF(JNIEnv* env, jobject jcanvas, jfloat sx, jfloat sy) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
         (void)GraphicsJNI::getNativeCanvas(env, jcanvas)->skew(sx_, sy_);
     }
- 
-    static void concat(JNIEnv* env, jobject, SkCanvas* canvas,
-                       const SkMatrix* matrix) {
+
+    static void concat(JNIEnv* env, jobject, jlong canvasHandle,
+                       jlong matrixHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         canvas->concat(*matrix);
     }
-    
-    static void setMatrix(JNIEnv* env, jobject, SkCanvas* canvas,
-                          const SkMatrix* matrix) {
+
+    static void setMatrix(JNIEnv* env, jobject, jlong canvasHandle,
+                          jlong matrixHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         if (NULL == matrix) {
             canvas->resetMatrix();
         } else {
             canvas->setMatrix(*matrix);
         }
     }
-    
+
     static jboolean clipRect_FFFF(JNIEnv* env, jobject jcanvas, jfloat left,
                                   jfloat top, jfloat right, jfloat bottom) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
@@ -250,122 +275,149 @@
         r.set(SkFloatToScalar(left), SkFloatToScalar(top),
               SkFloatToScalar(right), SkFloatToScalar(bottom));
         SkCanvas* c = GraphicsJNI::getNativeCanvas(env, jcanvas);
-        return c->clipRect(r);
+        bool result = c->clipRect(r);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
-    
+
     static jboolean clipRect_IIII(JNIEnv* env, jobject jcanvas, jint left,
                                   jint top, jint right, jint bottom) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
         SkRect  r;
         r.set(SkIntToScalar(left), SkIntToScalar(top),
               SkIntToScalar(right), SkIntToScalar(bottom));
-        return GraphicsJNI::getNativeCanvas(env, jcanvas)->clipRect(r);
+        bool result = GraphicsJNI::getNativeCanvas(env, jcanvas)->clipRect(r);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
-    
+
     static jboolean clipRect_RectF(JNIEnv* env, jobject jcanvas, jobject rectf) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
         NPE_CHECK_RETURN_ZERO(env, rectf);
         SkCanvas* c = GraphicsJNI::getNativeCanvas(env, jcanvas);
         SkRect tmp;
-        return c->clipRect(*GraphicsJNI::jrectf_to_rect(env, rectf, &tmp));
+        bool result = c->clipRect(*GraphicsJNI::jrectf_to_rect(env, rectf, &tmp));
+        return result ? JNI_TRUE : JNI_FALSE;
     }
-    
+
     static jboolean clipRect_Rect(JNIEnv* env, jobject jcanvas, jobject rect) {
         NPE_CHECK_RETURN_ZERO(env, jcanvas);
         NPE_CHECK_RETURN_ZERO(env, rect);
         SkCanvas* c = GraphicsJNI::getNativeCanvas(env, jcanvas);
         SkRect tmp;
-        return c->clipRect(*GraphicsJNI::jrect_to_rect(env, rect, &tmp));
+        bool result = c->clipRect(*GraphicsJNI::jrect_to_rect(env, rect, &tmp));
+        return result ? JNI_TRUE : JNI_FALSE;
+
     }
-    
-    static jboolean clipRect(JNIEnv* env, jobject, SkCanvas* canvas,
-                             float left, float top, float right, float bottom,
-                             int op) {
+
+    static jboolean clipRect(JNIEnv* env, jobject, jlong canvasHandle,
+                             jfloat left, jfloat top, jfloat right, jfloat bottom,
+                             jint op) {
         SkRect rect;
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         rect.set(SkFloatToScalar(left), SkFloatToScalar(top),
                  SkFloatToScalar(right), SkFloatToScalar(bottom));
-        return canvas->clipRect(rect, (SkRegion::Op)op);
+        bool result = canvas->clipRect(rect, static_cast<SkRegion::Op>(op));
+        return result ? JNI_TRUE : JNI_FALSE;
+
     }
- 
-    static jboolean clipPath(JNIEnv* env, jobject, SkCanvas* canvas,
-                             SkPath* path, int op) {
-        return canvas->clipPath(*path, (SkRegion::Op)op);
+
+    static jboolean clipPath(JNIEnv* env, jobject, jlong canvasHandle,
+                             SkPath* path, jint op) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        bool result = canvas->clipPath(*path, static_cast<SkRegion::Op>(op));
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean clipRegion(JNIEnv* env, jobject, SkCanvas* canvas,
-                               SkRegion* deviceRgn, int op) {
-        return canvas->clipRegion(*deviceRgn, (SkRegion::Op)op);
+
+    static jboolean clipRegion(JNIEnv* env, jobject, jlong canvasHandle,
+                               jlong deviceRgnHandle, jint op) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkRegion* deviceRgn = reinterpret_cast<SkRegion*>(deviceRgnHandle);
+        bool result = canvas->clipRegion(*deviceRgn, static_cast<SkRegion::Op>(op));
+        return result ? JNI_TRUE : JNI_FALSE;
     }
-    
-    static void setDrawFilter(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void setDrawFilter(JNIEnv* env, jobject, jlong canvasHandle,
                               SkDrawFilter* filter) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         canvas->setDrawFilter(filter);
     }
-    
-    static jboolean quickReject__RectF(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static jboolean quickReject__RectF(JNIEnv* env, jobject, jlong canvasHandle,
                                         jobject rect) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         SkRect rect_;
         GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
         return canvas->quickReject(rect_);
     }
 
-    static jboolean quickReject__Path(JNIEnv* env, jobject, SkCanvas* canvas,
+    static jboolean quickReject__Path(JNIEnv* env, jobject, jlong canvasHandle,
                                        SkPath* path) {
-        return canvas->quickReject(*path);
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        bool result = canvas->quickReject(*path);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
 
-    static jboolean quickReject__FFFF(JNIEnv* env, jobject, SkCanvas* canvas,
+    static jboolean quickReject__FFFF(JNIEnv* env, jobject, jlong canvasHandle,
                                        jfloat left, jfloat top, jfloat right,
                                        jfloat bottom) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         SkRect r;
         r.set(SkFloatToScalar(left), SkFloatToScalar(top),
               SkFloatToScalar(right), SkFloatToScalar(bottom));
-        return canvas->quickReject(r);
+        bool result = canvas->quickReject(r);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static void drawRGB(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void drawRGB(JNIEnv* env, jobject, jlong canvasHandle,
                         jint r, jint g, jint b) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         canvas->drawARGB(0xFF, r, g, b);
     }
- 
-    static void drawARGB(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void drawARGB(JNIEnv* env, jobject, jlong canvasHandle,
                          jint a, jint r, jint g, jint b) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         canvas->drawARGB(a, r, g, b);
     }
- 
-    static void drawColor__I(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void drawColor__I(JNIEnv* env, jobject, jlong canvasHandle,
                              jint color) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         canvas->drawColor(color);
     }
- 
-    static void drawColor__II(JNIEnv* env, jobject, SkCanvas* canvas,
-                              jint color, SkPorterDuff::Mode mode) {
+
+    static void drawColor__II(JNIEnv* env, jobject, jlong canvasHandle,
+                              jint color, jint modeHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPorterDuff::Mode mode = static_cast<SkPorterDuff::Mode>(modeHandle);
         canvas->drawColor(color, SkPorterDuff::ToXfermodeMode(mode));
     }
- 
-    static void drawPaint(JNIEnv* env, jobject, SkCanvas* canvas,
-                          SkPaint* paint) {
+
+    static void drawPaint(JNIEnv* env, jobject, jlong canvasHandle,
+                          jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         canvas->drawPaint(*paint);
     }
-    
+
     static void doPoints(JNIEnv* env, jobject jcanvas, jfloatArray jptsArray,
                          jint offset, jint count, jobject jpaint,
-                         SkCanvas::PointMode mode) {
+                         jint modeHandle) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         NPE_CHECK_RETURN_VOID(env, jptsArray);
         NPE_CHECK_RETURN_VOID(env, jpaint);
+        SkCanvas::PointMode mode = static_cast<SkCanvas::PointMode>(modeHandle);
         SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
         const SkPaint& paint = *GraphicsJNI::getNativePaint(env, jpaint);
-        
+
         AutoJavaFloatArray autoPts(env, jptsArray);
         float* floats = autoPts.ptr();
         const int length = autoPts.length();
-        
+
         if ((offset | count) < 0 || offset + count > length) {
             doThrowAIOOBE(env);
             return;
         }
-        
+
         // now convert the floats into SkPoints
         count >>= 1;    // now it is the number of points
         SkAutoSTMalloc<32, SkPoint> storage(count);
@@ -374,98 +426,118 @@
         for (int i = 0; i < count; i++) {
             pts[i].set(SkFloatToScalar(src[0]), SkFloatToScalar(src[1]));
             src += 2;
-        }        
+        }
         canvas->drawPoints(mode, count, pts, paint);
     }
-    
+
     static void drawPoints(JNIEnv* env, jobject jcanvas, jfloatArray jptsArray,
                            jint offset, jint count, jobject jpaint) {
         doPoints(env, jcanvas, jptsArray, offset, count, jpaint,
                  SkCanvas::kPoints_PointMode);
     }
-    
+
     static void drawLines(JNIEnv* env, jobject jcanvas, jfloatArray jptsArray,
                            jint offset, jint count, jobject jpaint) {
         doPoints(env, jcanvas, jptsArray, offset, count, jpaint,
                  SkCanvas::kLines_PointMode);
     }
-    
-    static void drawPoint(JNIEnv* env, jobject jcanvas, float x, float y,
+
+    static void drawPoint(JNIEnv* env, jobject jcanvas, jfloat x, jfloat y,
                           jobject jpaint) {
         NPE_CHECK_RETURN_VOID(env, jcanvas);
         NPE_CHECK_RETURN_VOID(env, jpaint);
         SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
         const SkPaint& paint = *GraphicsJNI::getNativePaint(env, jpaint);
-        
+
         canvas->drawPoint(SkFloatToScalar(x), SkFloatToScalar(y), paint);
     }
- 
-    static void drawLine__FFFFPaint(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void drawLine__FFFFPaint(JNIEnv* env, jobject, jlong canvasHandle,
                                     jfloat startX, jfloat startY, jfloat stopX,
-                                    jfloat stopY, SkPaint* paint) {
+                                    jfloat stopY, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         canvas->drawLine(SkFloatToScalar(startX), SkFloatToScalar(startY),
                          SkFloatToScalar(stopX), SkFloatToScalar(stopY),
                          *paint);
     }
- 
-    static void drawRect__RectFPaint(JNIEnv* env, jobject, SkCanvas* canvas,
-                                     jobject rect, SkPaint* paint) {
+
+    static void drawRect__RectFPaint(JNIEnv* env, jobject, jlong canvasHandle,
+                                     jobject rect, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect rect_;
         GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
         canvas->drawRect(rect_, *paint);
     }
- 
-    static void drawRect__FFFFPaint(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void drawRect__FFFFPaint(JNIEnv* env, jobject, jlong canvasHandle,
                                     jfloat left, jfloat top, jfloat right,
-                                    jfloat bottom, SkPaint* paint) {
+                                    jfloat bottom, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkScalar left_ = SkFloatToScalar(left);
         SkScalar top_ = SkFloatToScalar(top);
         SkScalar right_ = SkFloatToScalar(right);
         SkScalar bottom_ = SkFloatToScalar(bottom);
         canvas->drawRectCoords(left_, top_, right_, bottom_, *paint);
     }
- 
-    static void drawOval(JNIEnv* env, jobject, SkCanvas* canvas, jobject joval,
-                         SkPaint* paint) {
+
+    static void drawOval(JNIEnv* env, jobject, jlong canvasHandle, jobject joval,
+                         jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect oval;
         GraphicsJNI::jrectf_to_rect(env, joval, &oval);
         canvas->drawOval(oval, *paint);
     }
- 
-    static void drawCircle(JNIEnv* env, jobject, SkCanvas* canvas, jfloat cx,
-                           jfloat cy, jfloat radius, SkPaint* paint) {
+
+    static void drawCircle(JNIEnv* env, jobject, jlong canvasHandle, jfloat cx,
+                           jfloat cy, jfloat radius, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         canvas->drawCircle(SkFloatToScalar(cx), SkFloatToScalar(cy),
                            SkFloatToScalar(radius), *paint);
     }
- 
-    static void drawArc(JNIEnv* env, jobject, SkCanvas* canvas, jobject joval,
+
+    static void drawArc(JNIEnv* env, jobject, jlong canvasHandle, jobject joval,
                         jfloat startAngle, jfloat sweepAngle,
-                        jboolean useCenter, SkPaint* paint) {
+                        jboolean useCenter, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect oval;
         GraphicsJNI::jrectf_to_rect(env, joval, &oval);
         canvas->drawArc(oval, SkFloatToScalar(startAngle),
                         SkFloatToScalar(sweepAngle), useCenter, *paint);
     }
- 
-    static void drawRoundRect(JNIEnv* env, jobject, SkCanvas* canvas,
+
+    static void drawRoundRect(JNIEnv* env, jobject, jlong canvasHandle,
                               jobject jrect, jfloat rx, jfloat ry,
-                              SkPaint* paint) {
+                              jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect rect;
         GraphicsJNI::jrectf_to_rect(env, jrect, &rect);
         canvas->drawRoundRect(rect, SkFloatToScalar(rx), SkFloatToScalar(ry),
                               *paint);
     }
- 
-    static void drawPath(JNIEnv* env, jobject, SkCanvas* canvas, SkPath* path,
-                         SkPaint* paint) {
+
+    static void drawPath(JNIEnv* env, jobject, jlong canvasHandle, jlong pathHandle,
+                         jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         canvas->drawPath(*path, *paint);
     }
- 
+
     static void drawBitmap__BitmapFFPaint(JNIEnv* env, jobject jcanvas,
-                                          SkCanvas* canvas, SkBitmap* bitmap,
+                                          jlong canvasHandle, jlong bitmapHandle,
                                           jfloat left, jfloat top,
-                                          SkPaint* paint, jint canvasDensity,
+                                          jlong paintHandle, jint canvasDensity,
                                           jint screenDensity, jint bitmapDensity) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkScalar left_ = SkFloatToScalar(left);
         SkScalar top_ = SkFloatToScalar(top);
 
@@ -476,7 +548,7 @@
                 if (paint) {
                     filteredPaint = *paint;
                 }
-                filteredPaint.setFilterLevel(SkPaint::kLow_FilterLevel);
+                filteredPaint.setFilterBitmap(true);
                 canvas->drawBitmap(*bitmap, left_, top_, &filteredPaint);
             } else {
                 canvas->drawBitmap(*bitmap, left_, top_, paint);
@@ -491,7 +563,7 @@
             if (paint) {
                 filteredPaint = *paint;
             }
-            filteredPaint.setFilterLevel(SkPaint::kLow_FilterLevel);
+            filteredPaint.setFilterBitmap(true);
 
             canvas->drawBitmap(*bitmap, 0, 0, &filteredPaint);
 
@@ -508,44 +580,52 @@
             GraphicsJNI::jrect_to_irect(env, srcIRect, &src);
             srcPtr = &src;
         }
-        
+
         if (screenDensity != 0 && screenDensity != bitmapDensity) {
             SkPaint filteredPaint;
             if (paint) {
                 filteredPaint = *paint;
             }
-            filteredPaint.setFilterLevel(SkPaint::kLow_FilterLevel);
+            filteredPaint.setFilterBitmap(true);
             canvas->drawBitmapRect(*bitmap, srcPtr, dst, &filteredPaint);
         } else {
             canvas->drawBitmapRect(*bitmap, srcPtr, dst, paint);
         }
     }
 
-    static void drawBitmapRF(JNIEnv* env, jobject, SkCanvas* canvas,
-                             SkBitmap* bitmap, jobject srcIRect,
-                             jobject dstRectF, SkPaint* paint,
+    static void drawBitmapRF(JNIEnv* env, jobject, jlong canvasHandle,
+                             jlong bitmapHandle, jobject srcIRect,
+                             jobject dstRectF, jlong paintHandle,
                              jint screenDensity, jint bitmapDensity) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect      dst;
         GraphicsJNI::jrectf_to_rect(env, dstRectF, &dst);
         doDrawBitmap(env, canvas, bitmap, srcIRect, dst, paint,
                 screenDensity, bitmapDensity);
     }
-    
-    static void drawBitmapRR(JNIEnv* env, jobject, SkCanvas* canvas,
-                             SkBitmap* bitmap, jobject srcIRect,
-                             jobject dstRect, SkPaint* paint,
+
+    static void drawBitmapRR(JNIEnv* env, jobject, jlong canvasHandle,
+                             jlong bitmapHandle, jobject srcIRect,
+                             jobject dstRect, jlong paintHandle,
                              jint screenDensity, jint bitmapDensity) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkRect      dst;
         GraphicsJNI::jrect_to_rect(env, dstRect, &dst);
         doDrawBitmap(env, canvas, bitmap, srcIRect, dst, paint,
                 screenDensity, bitmapDensity);
     }
-    
-    static void drawBitmapArray(JNIEnv* env, jobject, SkCanvas* canvas,
-                                jintArray jcolors, int offset, int stride,
-                                jfloat x, jfloat y, int width, int height,
-                                jboolean hasAlpha, SkPaint* paint)
+
+    static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle,
+                                jintArray jcolors, jint offset, jint stride,
+                                jfloat x, jfloat y, jint width, jint height,
+                                jboolean hasAlpha, jlong paintHandle)
     {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkBitmap    bitmap;
         bitmap.setConfig(hasAlpha ? SkBitmap::kARGB_8888_Config :
                          SkBitmap::kRGB_565_Config, width, height);
@@ -561,24 +641,31 @@
         canvas->drawBitmap(bitmap, SkFloatToScalar(x), SkFloatToScalar(y),
                            paint);
     }
-    
-    static void drawBitmapMatrix(JNIEnv* env, jobject, SkCanvas* canvas,
-                                 const SkBitmap* bitmap, const SkMatrix* matrix,
-                                 const SkPaint* paint) {
+
+    static void drawBitmapMatrix(JNIEnv* env, jobject, jlong canvasHandle,
+                                 jlong bitmapHandle, jlong matrixHandle,
+                                 jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        const SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         canvas->drawBitmapMatrix(*bitmap, *matrix, paint);
     }
-    
-    static void drawBitmapMesh(JNIEnv* env, jobject, SkCanvas* canvas,
-                          const SkBitmap* bitmap, int meshWidth, int meshHeight,
-                          jfloatArray jverts, int vertIndex, jintArray jcolors,
-                          int colorIndex, const SkPaint* paint) {
+
+    static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle,
+                          jlong bitmapHandle, jint meshWidth, jint meshHeight,
+                          jfloatArray jverts, jint vertIndex, jintArray jcolors,
+                          jint colorIndex, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        const SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
 
         const int ptCount = (meshWidth + 1) * (meshHeight + 1);
         const int indexCount = meshWidth * meshHeight * 6;
 
         AutoJavaFloatArray  vertA(env, jverts, vertIndex + (ptCount << 1));
         AutoJavaIntArray    colorA(env, jcolors, colorIndex + ptCount);
-        
+
         /*  Our temp storage holds 2 or 3 arrays.
             texture points [ptCount * sizeof(SkPoint)]
             optionally vertex points [ptCount * sizeof(SkPoint)] if we need a
@@ -617,7 +704,7 @@
             const SkScalar h = SkIntToScalar(bitmap->height());
             const SkScalar dx = w / meshWidth;
             const SkScalar dy = h / meshHeight;
-            
+
             SkPoint* texsPtr = texs;
             SkScalar y = 0;
             for (int i = 0; i <= meshHeight; i++) {
@@ -636,7 +723,7 @@
             }
             SkASSERT(texsPtr - texs == ptCount);
         }
-        
+
         // cons up indices
         {
             uint16_t* indexPtr = indices;
@@ -684,13 +771,16 @@
                              indexCount, tmpPaint);
     }
 
-    static void drawVertices(JNIEnv* env, jobject, SkCanvas* canvas,
-                             SkCanvas::VertexMode mode, int vertexCount,
-                             jfloatArray jverts, int vertIndex,
-                             jfloatArray jtexs, int texIndex,
-                             jintArray jcolors, int colorIndex,
-                             jshortArray jindices, int indexIndex,
-                             int indexCount, const SkPaint* paint) {
+    static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle,
+                             jint modeHandle, jint vertexCount,
+                             jfloatArray jverts, jint vertIndex,
+                             jfloatArray jtexs, jint texIndex,
+                             jintArray jcolors, jint colorIndex,
+                             jshortArray jindices, jint indexIndex,
+                             jint indexCount, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkCanvas::VertexMode mode = static_cast<SkCanvas::VertexMode>(modeHandle);
+        const SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
 
         AutoJavaFloatArray  vertA(env, jverts, vertIndex + vertexCount);
         AutoJavaFloatArray  texA(env, jtexs, texIndex + vertexCount);
@@ -712,7 +802,7 @@
             count += ptCount;   // += for texs
         }
         SkAutoMalloc storage(count * sizeof(SkPoint));
-        verts = (SkPoint*)storage.get();        
+        verts = (SkPoint*)storage.get();
         const float* src = vertA.ptr() + vertIndex;
         for (int i = 0; i < ptCount; i++) {
             verts[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
@@ -742,18 +832,22 @@
     }
 
 
-    static void drawText___CIIFFIPaint(JNIEnv* env, jobject, SkCanvas* canvas,
-                                      jcharArray text, int index, int count,
-                                      jfloat x, jfloat y, int flags, SkPaint* paint) {
+    static void drawText___CIIFFIPaint(JNIEnv* env, jobject, jlong canvasHandle,
+                                      jcharArray text, jint index, jint count,
+                                      jfloat x, jfloat y, jint flags, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         jchar* textArray = env->GetCharArrayElements(text, NULL);
         drawTextWithGlyphs(canvas, textArray + index, 0, count, x, y, flags, paint);
         env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
     }
 
     static void drawText__StringIIFFIPaint(JNIEnv* env, jobject,
-                                          SkCanvas* canvas, jstring text,
-                                          int start, int end,
-                                          jfloat x, jfloat y, int flags, SkPaint* paint) {
+                                          jlong canvasHandle, jstring text,
+                                          jint start, jint end,
+                                          jfloat x, jfloat y, jint flags, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetStringChars(text, NULL);
         drawTextWithGlyphs(canvas, textArray, start, end, x, y, flags, paint);
         env->ReleaseStringChars(text, textArray);
@@ -843,9 +937,11 @@
     }
 
     static void drawTextRun___CIIIIFFIPaint(
-        JNIEnv* env, jobject, SkCanvas* canvas, jcharArray text, int index,
-        int count, int contextIndex, int contextCount,
-        jfloat x, jfloat y, int dirFlags, SkPaint* paint) {
+        JNIEnv* env, jobject, jlong canvasHandle, jcharArray text, jint index,
+        jint count, jint contextIndex, jint contextCount,
+        jfloat x, jfloat y, jint dirFlags, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
 
         jchar* chars = env->GetCharArrayElements(text, NULL);
         drawTextWithGlyphs(canvas, chars + contextIndex, index - contextIndex,
@@ -854,9 +950,11 @@
     }
 
     static void drawTextRun__StringIIIIFFIPaint(
-        JNIEnv* env, jobject obj, SkCanvas* canvas, jstring text, jint start,
+        JNIEnv* env, jobject obj, jlong canvasHandle, jstring text, jint start,
         jint end, jint contextStart, jint contextEnd,
-        jfloat x, jfloat y, jint dirFlags, SkPaint* paint) {
+        jfloat x, jfloat y, jint dirFlags, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
 
         jint count = end - start;
         jint contextCount = contextEnd - contextStart;
@@ -866,9 +964,11 @@
         env->ReleaseStringChars(text, chars);
     }
 
-    static void drawPosText___CII_FPaint(JNIEnv* env, jobject, SkCanvas* canvas,
-                                         jcharArray text, int index, int count,
-                                         jfloatArray pos, SkPaint* paint) {
+    static void drawPosText___CII_FPaint(JNIEnv* env, jobject, jlong canvasHandle,
+                                         jcharArray text, jint index, jint count,
+                                         jfloatArray pos, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         jchar* textArray = text ? env->GetCharArrayElements(text, NULL) : NULL;
         jsize textCount = text ? env->GetArrayLength(text) : NULL;
         float* posArray = pos ? env->GetFloatArrayElements(pos, NULL) : NULL;
@@ -879,12 +979,12 @@
             posPtr[indx].fX = SkFloatToScalar(posArray[indx << 1]);
             posPtr[indx].fY = SkFloatToScalar(posArray[(indx << 1) + 1]);
         }
-        
+
         SkPaint::TextEncoding encoding = paint->getTextEncoding();
         paint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
         canvas->drawPosText(textArray + index, count << 1, posPtr, *paint);
         paint->setTextEncoding(encoding);
-        
+
         if (text) {
             env->ReleaseCharArrayElements(text, textArray, 0);
         }
@@ -895,9 +995,11 @@
     }
 
     static void drawPosText__String_FPaint(JNIEnv* env, jobject,
-                                           SkCanvas* canvas, jstring text,
+                                           jlong canvasHandle, jstring text,
                                            jfloatArray pos,
-                                           SkPaint* paint) {
+                                           jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const void* text_ = text ? env->GetStringChars(text, NULL) : NULL;
         int byteLength = text ? env->GetStringLength(text) : 0;
         float* posArray = pos ? env->GetFloatArrayElements(pos, NULL) : NULL;
@@ -924,8 +1026,11 @@
     }
 
     static void drawTextOnPath___CIIPathFFPaint(JNIEnv* env, jobject,
-            SkCanvas* canvas, jcharArray text, int index, int count,
-            SkPath* path, jfloat hOffset, jfloat vOffset, jint bidiFlags, SkPaint* paint) {
+            jlong canvasHandle, jcharArray text, jint index, jint count,
+            jlong pathHandle, jfloat hOffset, jfloat vOffset, jint bidiFlags, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
 
         jchar* textArray = env->GetCharArrayElements(text, NULL);
         TextLayout::drawTextOnPath(paint, textArray + index, count, bidiFlags, hOffset, vOffset,
@@ -934,8 +1039,11 @@
     }
 
     static void drawTextOnPath__StringPathFFPaint(JNIEnv* env, jobject,
-            SkCanvas* canvas, jstring text, SkPath* path,
-            jfloat hOffset, jfloat vOffset, jint bidiFlags, SkPaint* paint) {
+            jlong canvasHandle, jstring text, jlong pathHandle,
+            jfloat hOffset, jfloat vOffset, jint bidiFlags, jlong paintHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* text_ = env->GetStringChars(text, NULL);
         int count = env->GetStringLength(text);
         TextLayout::drawTextOnPath(paint, text_, count, bidiFlags, hOffset, vOffset,
@@ -970,8 +1078,9 @@
         return true;
     }
 
-    static bool getClipBounds(JNIEnv* env, jobject, SkCanvas* canvas,
-                              jobject bounds) {
+    static jboolean getClipBounds(JNIEnv* env, jobject, jlong canvasHandle,
+                                  jobject bounds) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         SkRect   r;
         SkIRect ir;
         bool result = getHardClipBounds(canvas, &r);
@@ -982,30 +1091,32 @@
         r.round(&ir);
 
         (void)GraphicsJNI::irect_to_jrect(ir, env, bounds);
-        return result;
+        return result ? JNI_TRUE : JNI_FALSE;
     }
 
-    static void getCTM(JNIEnv* env, jobject, SkCanvas* canvas,
-                       SkMatrix* matrix) {
+    static void getCTM(JNIEnv* env, jobject, jlong canvasHandle,
+                       jlong matrixHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         *matrix = canvas->getTotalMatrix();
     }
 };
 
 static JNINativeMethod gCanvasMethods[] = {
-    {"finalizer", "(I)V", (void*) SkCanvasGlue::finalizer},
-    {"initRaster","(I)I", (void*) SkCanvasGlue::initRaster},
-    {"copyNativeCanvasState","(II)V", (void*) SkCanvasGlue::copyCanvasState},
+    {"finalizer", "(J)V", (void*) SkCanvasGlue::finalizer},
+    {"initRaster","(J)J", (void*) SkCanvasGlue::initRaster},
+    {"copyNativeCanvasState","(JJ)V", (void*) SkCanvasGlue::copyCanvasState},
     {"isOpaque","()Z", (void*) SkCanvasGlue::isOpaque},
     {"getWidth","()I", (void*) SkCanvasGlue::getWidth},
     {"getHeight","()I", (void*) SkCanvasGlue::getHeight},
     {"save","()I", (void*) SkCanvasGlue::saveAll},
     {"save","(I)I", (void*) SkCanvasGlue::save},
-    {"native_saveLayer","(ILandroid/graphics/RectF;II)I",
+    {"native_saveLayer","(JLandroid/graphics/RectF;JI)I",
         (void*) SkCanvasGlue::saveLayer},
-    {"native_saveLayer","(IFFFFII)I", (void*) SkCanvasGlue::saveLayer4F},
-    {"native_saveLayerAlpha","(ILandroid/graphics/RectF;II)I",
+    {"native_saveLayer","(JFFFFJI)I", (void*) SkCanvasGlue::saveLayer4F},
+    {"native_saveLayerAlpha","(JLandroid/graphics/RectF;II)I",
         (void*) SkCanvasGlue::saveLayerAlpha},
-    {"native_saveLayerAlpha","(IFFFFII)I",
+    {"native_saveLayerAlpha","(JFFFFII)I",
         (void*) SkCanvasGlue::saveLayerAlpha4F},
     {"restore","()V", (void*) SkCanvasGlue::restore},
     {"getSaveCount","()I", (void*) SkCanvasGlue::getSaveCount},
@@ -1014,77 +1125,77 @@
     {"scale","(FF)V", (void*) SkCanvasGlue::scale__FF},
     {"rotate","(F)V", (void*) SkCanvasGlue::rotate__F},
     {"skew","(FF)V", (void*) SkCanvasGlue::skew__FF},
-    {"native_concat","(II)V", (void*) SkCanvasGlue::concat},
-    {"native_setMatrix","(II)V", (void*) SkCanvasGlue::setMatrix},
+    {"native_concat","(JJ)V", (void*) SkCanvasGlue::concat},
+    {"native_setMatrix","(JJ)V", (void*) SkCanvasGlue::setMatrix},
     {"clipRect","(FFFF)Z", (void*) SkCanvasGlue::clipRect_FFFF},
     {"clipRect","(IIII)Z", (void*) SkCanvasGlue::clipRect_IIII},
     {"clipRect","(Landroid/graphics/RectF;)Z",
         (void*) SkCanvasGlue::clipRect_RectF},
     {"clipRect","(Landroid/graphics/Rect;)Z",
         (void*) SkCanvasGlue::clipRect_Rect},
-    {"native_clipRect","(IFFFFI)Z", (void*) SkCanvasGlue::clipRect},
-    {"native_clipPath","(III)Z", (void*) SkCanvasGlue::clipPath},
-    {"native_clipRegion","(III)Z", (void*) SkCanvasGlue::clipRegion},
-    {"nativeSetDrawFilter", "(II)V", (void*) SkCanvasGlue::setDrawFilter},
-    {"native_getClipBounds","(ILandroid/graphics/Rect;)Z",
+    {"native_clipRect","(JFFFFI)Z", (void*) SkCanvasGlue::clipRect},
+    {"native_clipPath","(JJI)Z", (void*) SkCanvasGlue::clipPath},
+    {"native_clipRegion","(JJI)Z", (void*) SkCanvasGlue::clipRegion},
+    {"nativeSetDrawFilter", "(JJ)V", (void*) SkCanvasGlue::setDrawFilter},
+    {"native_getClipBounds","(JLandroid/graphics/Rect;)Z",
         (void*) SkCanvasGlue::getClipBounds},
-    {"native_getCTM", "(II)V", (void*)SkCanvasGlue::getCTM},
-    {"native_quickReject","(ILandroid/graphics/RectF;)Z",
+    {"native_getCTM", "(JJ)V", (void*)SkCanvasGlue::getCTM},
+    {"native_quickReject","(JLandroid/graphics/RectF;)Z",
         (void*) SkCanvasGlue::quickReject__RectF},
-    {"native_quickReject","(II)Z", (void*) SkCanvasGlue::quickReject__Path},
-    {"native_quickReject","(IFFFF)Z", (void*)SkCanvasGlue::quickReject__FFFF},
-    {"native_drawRGB","(IIII)V", (void*) SkCanvasGlue::drawRGB},
-    {"native_drawARGB","(IIIII)V", (void*) SkCanvasGlue::drawARGB},
-    {"native_drawColor","(II)V", (void*) SkCanvasGlue::drawColor__I},
-    {"native_drawColor","(III)V", (void*) SkCanvasGlue::drawColor__II},
-    {"native_drawPaint","(II)V", (void*) SkCanvasGlue::drawPaint},
+    {"native_quickReject","(JJ)Z", (void*) SkCanvasGlue::quickReject__Path},
+    {"native_quickReject","(JFFFF)Z", (void*)SkCanvasGlue::quickReject__FFFF},
+    {"native_drawRGB","(JIII)V", (void*) SkCanvasGlue::drawRGB},
+    {"native_drawARGB","(JIIII)V", (void*) SkCanvasGlue::drawARGB},
+    {"native_drawColor","(JI)V", (void*) SkCanvasGlue::drawColor__I},
+    {"native_drawColor","(JII)V", (void*) SkCanvasGlue::drawColor__II},
+    {"native_drawPaint","(JJ)V", (void*) SkCanvasGlue::drawPaint},
     {"drawPoint", "(FFLandroid/graphics/Paint;)V",
     (void*) SkCanvasGlue::drawPoint},
     {"drawPoints", "([FIILandroid/graphics/Paint;)V",
         (void*) SkCanvasGlue::drawPoints},
     {"drawLines", "([FIILandroid/graphics/Paint;)V",
         (void*) SkCanvasGlue::drawLines},
-    {"native_drawLine","(IFFFFI)V", (void*) SkCanvasGlue::drawLine__FFFFPaint},
-    {"native_drawRect","(ILandroid/graphics/RectF;I)V",
+    {"native_drawLine","(JFFFFJ)V", (void*) SkCanvasGlue::drawLine__FFFFPaint},
+    {"native_drawRect","(JLandroid/graphics/RectF;J)V",
         (void*) SkCanvasGlue::drawRect__RectFPaint},
-    {"native_drawRect","(IFFFFI)V", (void*) SkCanvasGlue::drawRect__FFFFPaint},
-    {"native_drawOval","(ILandroid/graphics/RectF;I)V",
+    {"native_drawRect","(JFFFFJ)V", (void*) SkCanvasGlue::drawRect__FFFFPaint},
+    {"native_drawOval","(JLandroid/graphics/RectF;J)V",
         (void*) SkCanvasGlue::drawOval},
-    {"native_drawCircle","(IFFFI)V", (void*) SkCanvasGlue::drawCircle},
-    {"native_drawArc","(ILandroid/graphics/RectF;FFZI)V",
+    {"native_drawCircle","(JFFFJ)V", (void*) SkCanvasGlue::drawCircle},
+    {"native_drawArc","(JLandroid/graphics/RectF;FFZJ)V",
         (void*) SkCanvasGlue::drawArc},
-    {"native_drawRoundRect","(ILandroid/graphics/RectF;FFI)V",
+    {"native_drawRoundRect","(JLandroid/graphics/RectF;FFJ)V",
         (void*) SkCanvasGlue::drawRoundRect},
-    {"native_drawPath","(III)V", (void*) SkCanvasGlue::drawPath},
-    {"native_drawBitmap","(IIFFIIII)V",
+    {"native_drawPath","(JJJ)V", (void*) SkCanvasGlue::drawPath},
+    {"native_drawBitmap","(JJFFJIII)V",
         (void*) SkCanvasGlue::drawBitmap__BitmapFFPaint},
-    {"native_drawBitmap","(IILandroid/graphics/Rect;Landroid/graphics/RectF;III)V",
+    {"native_drawBitmap","(JJLandroid/graphics/Rect;Landroid/graphics/RectF;JII)V",
         (void*) SkCanvasGlue::drawBitmapRF},
-    {"native_drawBitmap","(IILandroid/graphics/Rect;Landroid/graphics/Rect;III)V",
+    {"native_drawBitmap","(JJLandroid/graphics/Rect;Landroid/graphics/Rect;JII)V",
         (void*) SkCanvasGlue::drawBitmapRR},
-    {"native_drawBitmap", "(I[IIIFFIIZI)V",
+    {"native_drawBitmap", "(J[IIIFFIIZJ)V",
     (void*)SkCanvasGlue::drawBitmapArray},
-    {"nativeDrawBitmapMatrix", "(IIII)V",
+    {"nativeDrawBitmapMatrix", "(JJJJ)V",
         (void*)SkCanvasGlue::drawBitmapMatrix},
-    {"nativeDrawBitmapMesh", "(IIII[FI[III)V",
+    {"nativeDrawBitmapMesh", "(JJII[FI[IIJ)V",
         (void*)SkCanvasGlue::drawBitmapMesh},
-    {"nativeDrawVertices", "(III[FI[FI[II[SIII)V",
+    {"nativeDrawVertices", "(JII[FI[FI[II[SIIJ)V",
         (void*)SkCanvasGlue::drawVertices},
-    {"native_drawText","(I[CIIFFII)V",
+    {"native_drawText","(J[CIIFFIJ)V",
         (void*) SkCanvasGlue::drawText___CIIFFIPaint},
-    {"native_drawText","(ILjava/lang/String;IIFFII)V",
+    {"native_drawText","(JLjava/lang/String;IIFFIJ)V",
         (void*) SkCanvasGlue::drawText__StringIIFFIPaint},
-    {"native_drawTextRun","(I[CIIIIFFII)V",
+    {"native_drawTextRun","(J[CIIIIFFIJ)V",
         (void*) SkCanvasGlue::drawTextRun___CIIIIFFIPaint},
-    {"native_drawTextRun","(ILjava/lang/String;IIIIFFII)V",
+    {"native_drawTextRun","(JLjava/lang/String;IIIIFFIJ)V",
         (void*) SkCanvasGlue::drawTextRun__StringIIIIFFIPaint},
-    {"native_drawPosText","(I[CII[FI)V",
+    {"native_drawPosText","(J[CII[FJ)V",
         (void*) SkCanvasGlue::drawPosText___CII_FPaint},
-    {"native_drawPosText","(ILjava/lang/String;[FI)V",
+    {"native_drawPosText","(JLjava/lang/String;[FJ)V",
         (void*) SkCanvasGlue::drawPosText__String_FPaint},
-    {"native_drawTextOnPath","(I[CIIIFFII)V",
+    {"native_drawTextOnPath","(J[CIIJFFIJ)V",
         (void*) SkCanvasGlue::drawTextOnPath___CIIPathFFPaint},
-    {"native_drawTextOnPath","(ILjava/lang/String;IFFII)V",
+    {"native_drawTextOnPath","(JLjava/lang/String;JFFIJ)V",
         (void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint},
 
     {"freeCaches", "()V", (void*) SkCanvasGlue::freeCaches},
@@ -1105,7 +1216,7 @@
     int result;
 
     REG(env, "android/graphics/Canvas", gCanvasMethods);
-    
+
     return result;
 }
 
diff --git a/core/jni/android/graphics/ColorFilter.cpp b/core/jni/android/graphics/ColorFilter.cpp
index dd1177b..f9cefd6 100644
--- a/core/jni/android/graphics/ColorFilter.cpp
+++ b/core/jni/android/graphics/ColorFilter.cpp
@@ -32,7 +32,9 @@
 
 class SkColorFilterGlue {
 public:
-    static void finalizer(JNIEnv* env, jobject clazz, SkColorFilter* obj, SkiaColorFilter* f) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle, jlong fHandle) {
+        SkColorFilter* obj = reinterpret_cast<SkColorFilter *>(objHandle);
+        SkiaColorFilter* f = reinterpret_cast<SkiaColorFilter *>(fHandle);
         SkSafeUnref(obj);
         // f == NULL when not !USE_OPENGL_RENDERER, so no need to delete outside the ifdef
 #ifdef USE_OPENGL_RENDERER
@@ -44,26 +46,30 @@
 #endif
     }
 
-    static SkiaColorFilter* glCreatePorterDuffFilter(JNIEnv* env, jobject, SkColorFilter *skFilter,
-            jint srcColor, SkPorterDuff::Mode mode) {
+    static jlong glCreatePorterDuffFilter(JNIEnv* env, jobject, jlong skFilterHandle,
+            jint srcColor, jint modeHandle) {
+        SkColorFilter *skFilter = reinterpret_cast<SkColorFilter *>(skFilterHandle);
+        SkPorterDuff::Mode mode = static_cast<SkPorterDuff::Mode>(modeHandle);
 #ifdef USE_OPENGL_RENDERER
-        return new SkiaBlendFilter(skFilter, srcColor, SkPorterDuff::ToXfermodeMode(mode));
+        return reinterpret_cast<jlong>(new SkiaBlendFilter(skFilter, srcColor, SkPorterDuff::ToXfermodeMode(mode)));
 #else
         return NULL;
 #endif
     }
 
-    static SkiaColorFilter* glCreateLightingFilter(JNIEnv* env, jobject, SkColorFilter *skFilter,
+    static jlong glCreateLightingFilter(JNIEnv* env, jobject, jlong skFilterHandle,
             jint mul, jint add) {
+        SkColorFilter *skFilter = reinterpret_cast<SkColorFilter *>(skFilterHandle);
 #ifdef USE_OPENGL_RENDERER
-        return new SkiaLightingFilter(skFilter, mul, add);
+        return reinterpret_cast<jlong>(new SkiaLightingFilter(skFilter, mul, add));
 #else
         return NULL;
 #endif
     }
 
-    static SkiaColorFilter* glCreateColorMatrixFilter(JNIEnv* env, jobject, SkColorFilter *skFilter,
+    static jlong glCreateColorMatrixFilter(JNIEnv* env, jobject, jlong skFilterHandle,
             jfloatArray jarray) {
+        SkColorFilter *skFilter = reinterpret_cast<SkColorFilter *>(skFilterHandle);
 #ifdef USE_OPENGL_RENDERER
         AutoJavaFloatArray autoArray(env, jarray, 20);
         const float* src = autoArray.ptr();
@@ -80,22 +86,23 @@
         colorVector[2] = src[14];
         colorVector[3] = src[19];
 
-        return new SkiaColorMatrixFilter(skFilter, colorMatrix, colorVector);
+        return reinterpret_cast<jlong>(new SkiaColorMatrixFilter(skFilter, colorMatrix, colorVector));
 #else
         return NULL;
 #endif
     }
 
-    static SkColorFilter* CreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor,
-            SkPorterDuff::Mode mode) {
-        return SkColorFilter::CreateModeFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode));
+    static jlong CreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor,
+            jint modeHandle) {
+        SkPorterDuff::Mode mode = (SkPorterDuff::Mode) modeHandle;
+        return reinterpret_cast<jlong>(SkColorFilter::CreateModeFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode)));
     }
 
-    static SkColorFilter* CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) {
-        return SkColorFilter::CreateLightingFilter(mul, add);
+    static jlong CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) {
+        return reinterpret_cast<jlong>(SkColorFilter::CreateLightingFilter(mul, add));
     }
 
-    static SkColorFilter* CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) {
+    static jlong CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) {
         AutoJavaFloatArray autoArray(env, jarray, 20);
         const float* src = autoArray.ptr();
 
@@ -104,30 +111,30 @@
         for (int i = 0; i < 20; i++) {
             array[i] = SkFloatToScalar(src[i]);
         }
-        return new SkColorMatrixFilter(array);
+        return reinterpret_cast<jlong>(new SkColorMatrixFilter(array));
 #else
-        return new SkColorMatrixFilter(src);
+        return reinterpret_cast<jlong>(new SkColorMatrixFilter(src));
 #endif
     }
 };
 
 static JNINativeMethod colorfilter_methods[] = {
-    {"finalizer", "(II)V", (void*) SkColorFilterGlue::finalizer}
+    {"finalizer", "(JJ)V", (void*) SkColorFilterGlue::finalizer}
 };
 
 static JNINativeMethod porterduff_methods[] = {
-    { "native_CreatePorterDuffFilter", "(II)I", (void*) SkColorFilterGlue::CreatePorterDuffFilter   },
-    { "nCreatePorterDuffFilter",       "(III)I", (void*) SkColorFilterGlue::glCreatePorterDuffFilter }
+    { "native_CreatePorterDuffFilter", "(II)J", (void*) SkColorFilterGlue::CreatePorterDuffFilter   },
+    { "nCreatePorterDuffFilter",       "(JII)J", (void*) SkColorFilterGlue::glCreatePorterDuffFilter }
 };
 
 static JNINativeMethod lighting_methods[] = {
-    { "native_CreateLightingFilter", "(II)I", (void*) SkColorFilterGlue::CreateLightingFilter   },
-    { "nCreateLightingFilter",       "(III)I", (void*) SkColorFilterGlue::glCreateLightingFilter },
+    { "native_CreateLightingFilter", "(II)J", (void*) SkColorFilterGlue::CreateLightingFilter   },
+    { "nCreateLightingFilter",       "(JII)J", (void*) SkColorFilterGlue::glCreateLightingFilter },
 };
 
 static JNINativeMethod colormatrix_methods[] = {
-    { "nativeColorMatrixFilter", "([F)I", (void*) SkColorFilterGlue::CreateColorMatrixFilter   },
-    { "nColorMatrixFilter",      "(I[F)I", (void*) SkColorFilterGlue::glCreateColorMatrixFilter }
+    { "nativeColorMatrixFilter", "([F)J", (void*) SkColorFilterGlue::CreateColorMatrixFilter   },
+    { "nColorMatrixFilter",      "(J[F)J", (void*) SkColorFilterGlue::glCreateColorMatrixFilter }
 };
 
 #define REG(env, name, array) \
diff --git a/core/jni/android/graphics/DrawFilter.cpp b/core/jni/android/graphics/DrawFilter.cpp
index 2f9fe7e..fbfa2ec 100644
--- a/core/jni/android/graphics/DrawFilter.cpp
+++ b/core/jni/android/graphics/DrawFilter.cpp
@@ -33,18 +33,20 @@
 class SkDrawFilterGlue {
 public:
 
-    static void finalizer(JNIEnv* env, jobject clazz, SkDrawFilter* obj) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkDrawFilter* obj = reinterpret_cast<SkDrawFilter*>(objHandle);
         SkSafeUnref(obj);
     }
 
-    static SkDrawFilter* CreatePaintFlagsDF(JNIEnv* env, jobject clazz,
-                                           int clearFlags, int setFlags) {
+    static jlong CreatePaintFlagsDF(JNIEnv* env, jobject clazz,
+                                    jint clearFlags, jint setFlags) {
         // trim off any out-of-range bits
         clearFlags &= SkPaint::kAllFlags;
         setFlags &= SkPaint::kAllFlags;
 
         if (clearFlags | setFlags) {
-            return new SkPaintFlagsDrawFilter(clearFlags, setFlags);
+            SkDrawFilter* filter = new SkPaintFlagsDrawFilter(clearFlags, setFlags);
+            return reinterpret_cast<jlong>(filter);
         } else {
             return NULL;
         }
@@ -52,11 +54,11 @@
 };
 
 static JNINativeMethod drawfilter_methods[] = {
-    {"nativeDestructor", "(I)V", (void*) SkDrawFilterGlue::finalizer}
+    {"nativeDestructor", "(J)V", (void*) SkDrawFilterGlue::finalizer}
 };
 
 static JNINativeMethod paintflags_methods[] = {
-    {"nativeConstructor","(II)I", (void*) SkDrawFilterGlue::CreatePaintFlagsDF}
+    {"nativeConstructor","(II)J", (void*) SkDrawFilterGlue::CreatePaintFlagsDF}
 };
 
 #define REG(env, name, array)                                                                       \
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 3090ad2..2f4fd29 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -174,6 +174,12 @@
 static jfieldID gRegion_nativeInstanceID;
 static jmethodID gRegion_constructorMethodID;
 
+static jclass    gByte_class;
+static jobject   gVMRuntime;
+static jclass    gVMRuntime_class;
+static jmethodID gVMRuntime_newNonMovableArray;
+static jmethodID gVMRuntime_addressOf;
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void GraphicsJNI::get_jrect(JNIEnv* env, jobject obj, int* L, int* T, int* R, int* B)
@@ -287,7 +293,8 @@
     SkASSERT(env);
     SkASSERT(bitmap);
     SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
-    SkBitmap* b = (SkBitmap*)env->GetIntField(bitmap, gBitmap_nativeInstanceID);
+    jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativeInstanceID);
+    SkBitmap* b = reinterpret_cast<SkBitmap*>(bitmapHandle);
     SkASSERT(b);
     return b;
 }
@@ -310,7 +317,8 @@
     SkASSERT(env);
     SkASSERT(canvas);
     SkASSERT(env->IsInstanceOf(canvas, gCanvas_class));
-    SkCanvas* c = (SkCanvas*)env->GetIntField(canvas, gCanvas_nativeInstanceID);
+    jlong canvasHandle = env->GetLongField(canvas, gCanvas_nativeInstanceID);
+    SkCanvas* c = reinterpret_cast<SkCanvas*>(canvasHandle);
     SkASSERT(c);
     return c;
 }
@@ -319,7 +327,8 @@
     SkASSERT(env);
     SkASSERT(paint);
     SkASSERT(env->IsInstanceOf(paint, gPaint_class));
-    SkPaint* p = (SkPaint*)env->GetIntField(paint, gPaint_nativeInstanceID);
+    jlong paintHandle = env->GetLongField(paint, gPaint_nativeInstanceID);
+    SkPaint* p = reinterpret_cast<SkPaint*>(paintHandle);
     SkASSERT(p);
     return p;
 }
@@ -329,7 +338,8 @@
     SkASSERT(env);
     SkASSERT(picture);
     SkASSERT(env->IsInstanceOf(picture, gPicture_class));
-    SkPicture* p = (SkPicture*)env->GetIntField(picture, gPicture_nativeInstanceID);
+    jlong pictureHandle = env->GetLongField(picture, gPicture_nativeInstanceID);
+    SkPicture* p = reinterpret_cast<SkPicture*>(pictureHandle);
     SkASSERT(p);
     return p;
 }
@@ -339,25 +349,14 @@
     SkASSERT(env);
     SkASSERT(region);
     SkASSERT(env->IsInstanceOf(region, gRegion_class));
-    SkRegion* r = (SkRegion*)env->GetIntField(region, gRegion_nativeInstanceID);
+    jlong regionHandle = env->GetLongField(region, gRegion_nativeInstanceID);
+    SkRegion* r = reinterpret_cast<SkRegion*>(regionHandle);
     SkASSERT(r);
     return r;
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////
 
-// Assert that bitmap's SkAlphaType is consistent with isPremultiplied.
-static void assert_premultiplied(const SkBitmap& bitmap, bool isPremultiplied) {
-    // kOpaque_SkAlphaType and kIgnore_SkAlphaType mean that isPremultiplied is
-    // irrelevant. This just tests to ensure that the SkAlphaType is not
-    // opposite of isPremultiplied.
-    if (isPremultiplied) {
-        SkASSERT(bitmap.alphaType() != kUnpremul_SkAlphaType);
-    } else {
-        SkASSERT(bitmap.alphaType() != kPremul_SkAlphaType);
-    }
-}
-
 jobject GraphicsJNI::createBitmap(JNIEnv* env, SkBitmap* bitmap, jbyteArray buffer,
         int bitmapCreateFlags, jbyteArray ninepatch, jintArray layoutbounds, int density)
 {
@@ -366,12 +365,8 @@
     bool isMutable = bitmapCreateFlags & kBitmapCreateFlag_Mutable;
     bool isPremultiplied = bitmapCreateFlags & kBitmapCreateFlag_Premultiplied;
 
-    // The caller needs to have already set the alpha type properly, so the
-    // native SkBitmap stays in sync with the Java Bitmap.
-    assert_premultiplied(*bitmap, isPremultiplied);
-
     jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID,
-            static_cast<jint>(reinterpret_cast<uintptr_t>(bitmap)), buffer,
+            reinterpret_cast<jlong>(bitmap), buffer,
             bitmap->width(), bitmap->height(), density, isMutable, isPremultiplied,
             ninepatch, layoutbounds);
     hasException(env); // For the side effect of logging.
@@ -387,10 +382,6 @@
 void GraphicsJNI::reinitBitmap(JNIEnv* env, jobject javaBitmap, SkBitmap* bitmap,
         bool isPremultiplied)
 {
-    // The caller needs to have already set the alpha type properly, so the
-    // native SkBitmap stays in sync with the Java Bitmap.
-    assert_premultiplied(*bitmap, isPremultiplied);
-
     env->CallVoidMethod(javaBitmap, gBitmap_reinitMethodID,
             bitmap->width(), bitmap->height(), isPremultiplied);
 }
@@ -406,7 +397,7 @@
 
     jobject obj = env->NewObject(gBitmapRegionDecoder_class,
             gBitmapRegionDecoder_constructorMethodID,
-            static_cast<jint>(reinterpret_cast<uintptr_t>(bitmap)));
+            reinterpret_cast<jlong>(bitmap));
     hasException(env); // For the side effect of logging.
     return obj;
 }
@@ -415,7 +406,7 @@
 {
     SkASSERT(region != NULL);
     jobject obj = env->NewObject(gRegion_class, gRegion_constructorMethodID,
-            static_cast<jint>(reinterpret_cast<uintptr_t>(region)), 0);
+                                 reinterpret_cast<jlong>(region), 0);
     hasException(env); // For the side effect of logging.
     return obj;
 }
@@ -433,9 +424,8 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-AndroidPixelRef::AndroidPixelRef(JNIEnv* env, const SkImageInfo& info, void* storage,
-        size_t rowBytes, jbyteArray storageObj, SkColorTable* ctable) :
-        SkMallocPixelRef(info, storage, rowBytes, ctable, (storageObj == NULL)),
+AndroidPixelRef::AndroidPixelRef(JNIEnv* env, void* storage, size_t size, jbyteArray storageObj,
+        SkColorTable* ctable) : SkMallocPixelRef(storage, size, ctable, (storageObj == NULL)),
         fWrappedPixelRef(NULL) {
     SkASSERT(storage);
     SkASSERT(env);
@@ -450,13 +440,13 @@
 
     // If storageObj is NULL, the memory was NOT allocated on the Java heap
     fOnJavaHeap = (storageObj != NULL);
+
 }
 
-AndroidPixelRef::AndroidPixelRef(AndroidPixelRef& wrappedPixelRef, const SkImageInfo& info,
-        size_t rowBytes, SkColorTable* ctable) :
-        SkMallocPixelRef(info, wrappedPixelRef.getAddr(), rowBytes, ctable, false),
+AndroidPixelRef::AndroidPixelRef(AndroidPixelRef& wrappedPixelRef, SkColorTable* ctable) :
+        SkMallocPixelRef(wrappedPixelRef.getAddr(), wrappedPixelRef.getSize(), ctable, false),
         fWrappedPixelRef(wrappedPixelRef.fWrappedPixelRef ?
-                wrappedPixelRef.fWrappedPixelRef : &wrappedPixelRef)
+            wrappedPixelRef.fWrappedPixelRef : &wrappedPixelRef)
 {
     SkASSERT(fWrappedPixelRef);
     SkSafeRef(fWrappedPixelRef);
@@ -550,8 +540,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-extern "C" jbyte* jniGetNonMovableArrayElements(C_JNIEnv* env, jarray arrayObj);
-
 jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
                                              SkColorTable* ctable) {
     Sk64 size64 = bitmap->getSize64();
@@ -560,28 +548,24 @@
                           "bitmap size exceeds 32bits");
         return NULL;
     }
-
-    SkImageInfo bitmapInfo;
-    if (!bitmap->asImageInfo(&bitmapInfo)) {
-        jniThrowException(env, "java/lang/IllegalArgumentException",
-                "unknown bitmap configuration");
+    size_t size = size64.get32();
+    jbyteArray arrayObj = (jbyteArray) env->CallObjectMethod(gVMRuntime,
+                                                             gVMRuntime_newNonMovableArray,
+                                                             gByte_class, size);
+    if (env->ExceptionCheck() != 0) {
         return NULL;
     }
-
-    size_t size = size64.get32();
-    jbyteArray arrayObj = env->NewByteArray(size);
-    if (arrayObj) {
-        // TODO: make this work without jniGetNonMovableArrayElements
-        jbyte* addr = jniGetNonMovableArrayElements(&env->functions, arrayObj);
-        if (addr) {
-            SkPixelRef* pr = new AndroidPixelRef(env, bitmapInfo, (void*) addr,
-                    bitmap->rowBytes(), arrayObj, ctable);
-            bitmap->setPixelRef(pr)->unref();
-            // since we're already allocated, we lockPixels right away
-            // HeapAllocator behaves this way too
-            bitmap->lockPixels();
-        }
+    SkASSERT(arrayObj);
+    jbyte* addr = (jbyte*) env->CallLongMethod(gVMRuntime, gVMRuntime_addressOf, arrayObj);
+    if (env->ExceptionCheck() != 0) {
+        return NULL;
     }
+    SkASSERT(addr);
+    SkPixelRef* pr = new AndroidPixelRef(env, (void*) addr, size, arrayObj, ctable);
+    bitmap->setPixelRef(pr)->unref();
+    // since we're already allocated, we lockPixels right away
+    // HeapAllocator behaves this way too
+    bitmap->lockPixels();
 
     return arrayObj;
 }
@@ -630,7 +614,7 @@
 {
     jclass c = env->FindClass(classname);
     SkASSERT(c);
-    return (jclass)env->NewGlobalRef(c);
+    return (jclass) env->NewGlobalRef(c);
 }
 
 static jfieldID getFieldIDCheck(JNIEnv* env, jclass clazz,
@@ -667,30 +651,41 @@
     gPointF_yFieldID = getFieldIDCheck(env, gPointF_class, "y", "F");
 
     gBitmap_class = make_globalref(env, "android/graphics/Bitmap");
-    gBitmap_nativeInstanceID = getFieldIDCheck(env, gBitmap_class, "mNativeBitmap", "I");
-    gBitmap_constructorMethodID = env->GetMethodID(gBitmap_class, "<init>", "(I[BIIIZZ[B[I)V");
+    gBitmap_nativeInstanceID = getFieldIDCheck(env, gBitmap_class, "mNativeBitmap", "J");
+    gBitmap_constructorMethodID = env->GetMethodID(gBitmap_class, "<init>", "(J[BIIIZZ[B[I)V");
     gBitmap_reinitMethodID = env->GetMethodID(gBitmap_class, "reinit", "(IIZ)V");
     gBitmap_getAllocationByteCountMethodID = env->GetMethodID(gBitmap_class, "getAllocationByteCount", "()I");
     gBitmapRegionDecoder_class = make_globalref(env, "android/graphics/BitmapRegionDecoder");
-    gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "<init>", "(I)V");
+    gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "<init>", "(J)V");
 
     gBitmapConfig_class = make_globalref(env, "android/graphics/Bitmap$Config");
     gBitmapConfig_nativeInstanceID = getFieldIDCheck(env, gBitmapConfig_class,
                                                      "nativeInt", "I");
 
     gCanvas_class = make_globalref(env, "android/graphics/Canvas");
-    gCanvas_nativeInstanceID = getFieldIDCheck(env, gCanvas_class, "mNativeCanvas", "I");
+    gCanvas_nativeInstanceID = getFieldIDCheck(env, gCanvas_class, "mNativeCanvas", "J");
 
     gPaint_class = make_globalref(env, "android/graphics/Paint");
-    gPaint_nativeInstanceID = getFieldIDCheck(env, gPaint_class, "mNativePaint", "I");
+    gPaint_nativeInstanceID = getFieldIDCheck(env, gPaint_class, "mNativePaint", "J");
 
     gPicture_class = make_globalref(env, "android/graphics/Picture");
-    gPicture_nativeInstanceID = getFieldIDCheck(env, gPicture_class, "mNativePicture", "I");
+    gPicture_nativeInstanceID = getFieldIDCheck(env, gPicture_class, "mNativePicture", "J");
 
     gRegion_class = make_globalref(env, "android/graphics/Region");
-    gRegion_nativeInstanceID = getFieldIDCheck(env, gRegion_class, "mNativeRegion", "I");
+    gRegion_nativeInstanceID = getFieldIDCheck(env, gRegion_class, "mNativeRegion", "J");
     gRegion_constructorMethodID = env->GetMethodID(gRegion_class, "<init>",
-        "(II)V");
+        "(JI)V");
+
+    c = env->FindClass("java/lang/Byte");
+    gByte_class = (jclass) env->NewGlobalRef(
+        env->GetStaticObjectField(c, env->GetStaticFieldID(c, "TYPE", "Ljava/lang/Class;")));
+
+    gVMRuntime_class = make_globalref(env, "dalvik/system/VMRuntime");
+    m = env->GetStaticMethodID(gVMRuntime_class, "getRuntime", "()Ldalvik/system/VMRuntime;");
+    gVMRuntime = env->NewGlobalRef(env->CallStaticObjectMethod(gVMRuntime_class, m));
+    gVMRuntime_newNonMovableArray = env->GetMethodID(gVMRuntime_class, "newNonMovableArray",
+                                                     "(Ljava/lang/Class;I)Ljava/lang/Object;");
+    gVMRuntime_addressOf = env->GetMethodID(gVMRuntime_class, "addressOf", "(Ljava/lang/Object;)J");
 
     return 0;
 }
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index cb154aa..f4590b9 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -57,7 +57,6 @@
 
     /** Create a java Bitmap object given the native bitmap (required) and optional
         storage array (may be null).
-        bitmap's SkAlphaType must already be in sync with bitmapCreateFlags.
     */
     static jobject createBitmap(JNIEnv* env, SkBitmap* bitmap, jbyteArray buffer,
             int bitmapCreateFlags, jbyteArray ninepatch, jintArray layoutbounds, int density = -1);
@@ -65,9 +64,6 @@
     static jobject createBitmap(JNIEnv* env, SkBitmap* bitmap, int bitmapCreateFlags,
             jbyteArray ninepatch, int density = -1);
 
-    /** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in
-        sync with isPremultiplied
-    */
     static void reinitBitmap(JNIEnv* env, jobject javaBitmap, SkBitmap* bitmap,
             bool isPremultiplied);
 
@@ -92,16 +88,15 @@
 
 class AndroidPixelRef : public SkMallocPixelRef {
 public:
-    AndroidPixelRef(JNIEnv* env, const SkImageInfo& info, void* storage, size_t rowBytes,
-            jbyteArray storageObj, SkColorTable* ctable);
+    AndroidPixelRef(JNIEnv* env, void* storage, size_t size, jbyteArray storageObj,
+                    SkColorTable* ctable);
 
     /**
      * Creates an AndroidPixelRef that wraps (and refs) another to reuse/share
      * the same storage and java byte array refcounting, yet have a different
      * color table.
      */
-    AndroidPixelRef(AndroidPixelRef& wrappedPixelRef, const SkImageInfo& info,
-            size_t rowBytes, SkColorTable* ctable);
+    AndroidPixelRef(AndroidPixelRef& wrappedPixelRef, SkColorTable* ctable);
 
     virtual ~AndroidPixelRef();
 
diff --git a/core/jni/android/graphics/Interpolator.cpp b/core/jni/android/graphics/Interpolator.cpp
index aa33c3d..ca04dfe 100644
--- a/core/jni/android/graphics/Interpolator.cpp
+++ b/core/jni/android/graphics/Interpolator.cpp
@@ -5,23 +5,26 @@
 #include "SkInterpolator.h"
 #include "SkTemplates.h"
 
-static SkInterpolator* Interpolator_constructor(JNIEnv* env, jobject clazz, int valueCount, int frameCount)
+static jlong Interpolator_constructor(JNIEnv* env, jobject clazz, jint valueCount, jint frameCount)
 {
-    return new SkInterpolator(valueCount, frameCount);
+    return reinterpret_cast<jlong>(new SkInterpolator(valueCount, frameCount));
 }
 
-static void Interpolator_destructor(JNIEnv* env, jobject clazz, SkInterpolator* interp)
+static void Interpolator_destructor(JNIEnv* env, jobject clazz, jlong interpHandle)
 {
+    SkInterpolator* interp = reinterpret_cast<SkInterpolator*>(interpHandle);
     delete interp;
 }
 
-static void Interpolator_reset(JNIEnv* env, jobject clazz, SkInterpolator* interp, int valueCount, int frameCount)
+static void Interpolator_reset(JNIEnv* env, jobject clazz, jlong interpHandle, jint valueCount, jint frameCount)
 {
+    SkInterpolator* interp = reinterpret_cast<SkInterpolator*>(interpHandle);
     interp->reset(valueCount, frameCount);
 }
 
-static void Interpolator_setKeyFrame(JNIEnv* env, jobject clazz, SkInterpolator* interp, int index, int msec, jfloatArray valueArray, jfloatArray blendArray)
+static void Interpolator_setKeyFrame(JNIEnv* env, jobject clazz, jlong interpHandle, jint index, jint msec, jfloatArray valueArray, jfloatArray blendArray)
 {
+    SkInterpolator* interp = reinterpret_cast<SkInterpolator*>(interpHandle);
     SkScalar    blendStorage[4];
     SkScalar*   blend = NULL;
 
@@ -46,8 +49,9 @@
     interp->setKeyFrame(index, msec, scalars, blend);
 }
 
-static void Interpolator_setRepeatMirror(JNIEnv* env, jobject clazz, SkInterpolator* interp, float repeatCount, jboolean mirror)
+static void Interpolator_setRepeatMirror(JNIEnv* env, jobject clazz, jlong interpHandle, jfloat repeatCount, jboolean mirror)
 {
+    SkInterpolator* interp = reinterpret_cast<SkInterpolator*>(interpHandle);
     if (repeatCount > 32000)
         repeatCount = 32000;
 
@@ -55,8 +59,9 @@
     interp->setMirror(mirror != 0);
 }
 
-static int Interpolator_timeToValues(JNIEnv* env, jobject clazz, SkInterpolator* interp, int msec, jfloatArray valueArray)
+static jint Interpolator_timeToValues(JNIEnv* env, jobject clazz, jlong interpHandle, jint msec, jfloatArray valueArray)
 {
+    SkInterpolator* interp = reinterpret_cast<SkInterpolator*>(interpHandle);
     SkInterpolatorBase::Result result;
 
     float* values = valueArray ? env->GetFloatArrayElements(valueArray, NULL) : NULL;
@@ -70,7 +75,7 @@
         env->ReleaseFloatArrayElements(valueArray, values, 0);
     }
 
-    return result;
+    return static_cast<jint>(result);
 }
 
 // ----------------------------------------------------------------------------
@@ -79,12 +84,12 @@
  * JNI registration.
  */
 static JNINativeMethod gInterpolatorMethods[] = {
-    { "nativeConstructor",      "(II)I",        (void*)Interpolator_constructor     },
-    { "nativeDestructor",       "(I)V",         (void*)Interpolator_destructor      },
-    { "nativeReset",            "(III)V",       (void*)Interpolator_reset           },
-    { "nativeSetKeyFrame",      "(III[F[F)V",   (void*)Interpolator_setKeyFrame     },
-    { "nativeSetRepeatMirror",  "(IFZ)V",       (void*)Interpolator_setRepeatMirror },
-    { "nativeTimeToValues",     "(II[F)I",      (void*)Interpolator_timeToValues    }
+    { "nativeConstructor",      "(II)J",        (void*)Interpolator_constructor     },
+    { "nativeDestructor",       "(J)V",         (void*)Interpolator_destructor      },
+    { "nativeReset",            "(JII)V",       (void*)Interpolator_reset           },
+    { "nativeSetKeyFrame",      "(JII[F[F)V",   (void*)Interpolator_setKeyFrame     },
+    { "nativeSetRepeatMirror",  "(JFZ)V",       (void*)Interpolator_setRepeatMirror },
+    { "nativeTimeToValues",     "(JI[F)I",      (void*)Interpolator_timeToValues    }
 };
 
 int register_android_graphics_Interpolator(JNIEnv* env)
diff --git a/core/jni/android/graphics/LayerRasterizer.cpp b/core/jni/android/graphics/LayerRasterizer.cpp
index e5bc6f8..29e7db1 100644
--- a/core/jni/android/graphics/LayerRasterizer.cpp
+++ b/core/jni/android/graphics/LayerRasterizer.cpp
@@ -3,11 +3,13 @@
 
 class SkLayerRasterizerGlue {
 public:
-    static SkRasterizer* create(JNIEnv* env, jobject) {
-        return new SkLayerRasterizer();
+    static jlong create(JNIEnv* env, jobject) {
+        return reinterpret_cast<jlong>(new SkLayerRasterizer());
     }
 
-    static void addLayer(JNIEnv* env, jobject, SkLayerRasterizer* layer, const SkPaint* paint, float dx, float dy) {
+    static void addLayer(JNIEnv* env, jobject, jlong layerHandle, jlong paintHandle, jfloat dx, jfloat dy) {
+        SkLayerRasterizer* layer = reinterpret_cast<SkLayerRasterizer *>(layerHandle);
+        const SkPaint* paint = reinterpret_cast<SkPaint *>(paintHandle);
         SkASSERT(layer);
         SkASSERT(paint);
         layer->addLayer(*paint, SkFloatToScalar(dx), SkFloatToScalar(dy));
@@ -19,8 +21,8 @@
 #include <android_runtime/AndroidRuntime.h>
 
 static JNINativeMethod gLayerRasterizerMethods[] = {
-    { "nativeConstructor",  "()I",      (void*)SkLayerRasterizerGlue::create    },
-    { "nativeAddLayer",     "(IIFF)V",  (void*)SkLayerRasterizerGlue::addLayer  }
+    { "nativeConstructor",  "()J",      (void*)SkLayerRasterizerGlue::create    },
+    { "nativeAddLayer",     "(JJFF)V",  (void*)SkLayerRasterizerGlue::addLayer  }
 };
 
 int register_android_graphics_LayerRasterizer(JNIEnv* env)
diff --git a/core/jni/android/graphics/MaskFilter.cpp b/core/jni/android/graphics/MaskFilter.cpp
index d954ddf..f331af7 100644
--- a/core/jni/android/graphics/MaskFilter.cpp
+++ b/core/jni/android/graphics/MaskFilter.cpp
@@ -13,18 +13,19 @@
 
 class SkMaskFilterGlue {
 public:
-    static void destructor(JNIEnv* env, jobject, SkMaskFilter* filter) {
+    static void destructor(JNIEnv* env, jobject, jlong filterHandle) {
+        SkMaskFilter* filter = reinterpret_cast<SkMaskFilter *>(filterHandle);
         SkSafeUnref(filter);
     }
 
-    static SkMaskFilter* createBlur(JNIEnv* env, jobject, float radius, int blurStyle) {
+    static jlong createBlur(JNIEnv* env, jobject, jfloat radius, jint blurStyle) {
         SkMaskFilter* filter = SkBlurMaskFilter::Create(SkFloatToScalar(radius),
                                         (SkBlurMaskFilter::BlurStyle)blurStyle);
         ThrowIAE_IfNull(env, filter);
-        return filter;
+        return reinterpret_cast<jlong>(filter);
     }
 
-    static SkMaskFilter* createEmboss(JNIEnv* env, jobject, jfloatArray dirArray, float ambient, float specular, float radius) {
+    static jlong createEmboss(JNIEnv* env, jobject, jfloatArray dirArray, jfloat ambient, jfloat specular, jfloat radius) {
         SkScalar direction[3];
 
         AutoJavaFloatArray autoDir(env, dirArray, 3);
@@ -38,39 +39,42 @@
                                                       SkFloatToScalar(specular),
                                                       SkFloatToScalar(radius));
         ThrowIAE_IfNull(env, filter);
-        return filter;
+        return reinterpret_cast<jlong>(filter);
     }
 
-    static SkMaskFilter* createTable(JNIEnv* env, jobject, jbyteArray jtable) {
+    static jlong createTable(JNIEnv* env, jobject, jbyteArray jtable) {
         AutoJavaByteArray autoTable(env, jtable, 256);
-        return new SkTableMaskFilter((const uint8_t*)autoTable.ptr());
+        SkMaskFilter* filter = new SkTableMaskFilter((const uint8_t*)autoTable.ptr());
+        return reinterpret_cast<jlong>(filter);
     }
 
-    static SkMaskFilter* createClipTable(JNIEnv* env, jobject, int min, int max) {
-        return SkTableMaskFilter::CreateClip(min, max);
+    static jlong createClipTable(JNIEnv* env, jobject, jint min, jint max) {
+        SkMaskFilter* filter = SkTableMaskFilter::CreateClip(min, max);
+        return reinterpret_cast<jlong>(filter);
     }
 
-    static SkMaskFilter* createGammaTable(JNIEnv* env, jobject, float gamma) {
-        return SkTableMaskFilter::CreateGamma(gamma);
+    static jlong createGammaTable(JNIEnv* env, jobject, jfloat gamma) {
+        SkMaskFilter* filter = SkTableMaskFilter::CreateGamma(gamma);
+        return reinterpret_cast<jlong>(filter);
     }
 };
 
 static JNINativeMethod gMaskFilterMethods[] = {
-    { "nativeDestructor",   "(I)V",     (void*)SkMaskFilterGlue::destructor      }
+    { "nativeDestructor",   "(J)V",     (void*)SkMaskFilterGlue::destructor      }
 };
 
 static JNINativeMethod gBlurMaskFilterMethods[] = {
-    { "nativeConstructor",  "(FI)I",    (void*)SkMaskFilterGlue::createBlur      }
+    { "nativeConstructor",  "(FI)J",    (void*)SkMaskFilterGlue::createBlur      }
 };
 
 static JNINativeMethod gEmbossMaskFilterMethods[] = {
-    { "nativeConstructor",  "([FFFF)I", (void*)SkMaskFilterGlue::createEmboss    }
+    { "nativeConstructor",  "([FFFF)J", (void*)SkMaskFilterGlue::createEmboss    }
 };
 
 static JNINativeMethod gTableMaskFilterMethods[] = {
-    { "nativeNewTable", "([B)I", (void*)SkMaskFilterGlue::createTable    },
-    { "nativeNewClip",  "(II)I", (void*)SkMaskFilterGlue::createClipTable    },
-    { "nativeNewGamma", "(F)I", (void*)SkMaskFilterGlue::createGammaTable    }
+    { "nativeNewTable", "([B)J", (void*)SkMaskFilterGlue::createTable    },
+    { "nativeNewClip",  "(II)J", (void*)SkMaskFilterGlue::createClipTable    },
+    { "nativeNewGamma", "(F)J", (void*)SkMaskFilterGlue::createGammaTable    }
 };
 
 #include <android_runtime/AndroidRuntime.h>
diff --git a/core/jni/android/graphics/Matrix.cpp b/core/jni/android/graphics/Matrix.cpp
index d0871ac5..a667499 100644
--- a/core/jni/android/graphics/Matrix.cpp
+++ b/core/jni/android/graphics/Matrix.cpp
@@ -31,218 +31,246 @@
 class SkMatrixGlue {
 public:
 
-    static void finalizer(JNIEnv* env, jobject clazz, SkMatrix* obj) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         delete obj;
     }
 
-    static SkMatrix* create(JNIEnv* env, jobject clazz, const SkMatrix* src) {
+    static jlong create(JNIEnv* env, jobject clazz, jlong srcHandle) {
+        const SkMatrix* src = reinterpret_cast<SkMatrix*>(srcHandle);
         SkMatrix* obj = new SkMatrix();
         if (src)
             *obj = *src;
         else
             obj->reset();
-        return obj;
+        return reinterpret_cast<jlong>(obj);
     }
- 
-    static jboolean isIdentity(JNIEnv* env, jobject clazz, SkMatrix* obj) {
-        return obj->isIdentity();
+
+    static jboolean isIdentity(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
+        return obj->isIdentity() ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean rectStaysRect(JNIEnv* env, jobject clazz, SkMatrix* obj) {
-        return obj->rectStaysRect();
+    static jboolean rectStaysRect(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
+        return obj->rectStaysRect() ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static void reset(JNIEnv* env, jobject clazz, SkMatrix* obj) {
+    static void reset(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         obj->reset();
     }
- 
-    static void set(JNIEnv* env, jobject clazz, SkMatrix* obj, SkMatrix* other) {
+     static void set(JNIEnv* env, jobject clazz, jlong objHandle, jlong otherHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
+        SkMatrix* other = reinterpret_cast<SkMatrix*>(otherHandle);
         *obj = *other;
     }
- 
-    static void setTranslate(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat dx, jfloat dy) {
+     static void setTranslate(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->setTranslate(dx_, dy_);
     }
- 
-    static void setScale__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sx, jfloat sy, jfloat px, jfloat py) {
+     static void setScale__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sx, jfloat sy, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
         obj->setScale(sx_, sy_, px_, py_);
     }
- 
-    static void setScale__FF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sx, jfloat sy) {
+     static void setScale__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sx, jfloat sy) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
         obj->setScale(sx_, sy_);
     }
- 
-    static void setRotate__FFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat degrees, jfloat px, jfloat py) {
+     static void setRotate__FFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat degrees, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar degrees_ = SkFloatToScalar(degrees);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
         obj->setRotate(degrees_, px_, py_);
     }
- 
-    static void setRotate__F(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat degrees) {
+     static void setRotate__F(JNIEnv* env, jobject clazz, jlong objHandle, jfloat degrees) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar degrees_ = SkFloatToScalar(degrees);
         obj->setRotate(degrees_);
     }
- 
-    static void setSinCos__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sinValue, jfloat cosValue, jfloat px, jfloat py) {
+     static void setSinCos__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sinValue, jfloat cosValue, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sinValue_ = SkFloatToScalar(sinValue);
         SkScalar cosValue_ = SkFloatToScalar(cosValue);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
         obj->setSinCos(sinValue_, cosValue_, px_, py_);
     }
- 
-    static void setSinCos__FF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sinValue, jfloat cosValue) {
+     static void setSinCos__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sinValue, jfloat cosValue) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sinValue_ = SkFloatToScalar(sinValue);
         SkScalar cosValue_ = SkFloatToScalar(cosValue);
         obj->setSinCos(sinValue_, cosValue_);
     }
- 
-    static void setSkew__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat kx, jfloat ky, jfloat px, jfloat py) {
+     static void setSkew__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat kx, jfloat ky, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar kx_ = SkFloatToScalar(kx);
         SkScalar ky_ = SkFloatToScalar(ky);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
         obj->setSkew(kx_, ky_, px_, py_);
     }
- 
-    static void setSkew__FF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat kx, jfloat ky) {
+     static void setSkew__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat kx, jfloat ky) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar kx_ = SkFloatToScalar(kx);
         SkScalar ky_ = SkFloatToScalar(ky);
         obj->setSkew(kx_, ky_);
     }
- 
-    static jboolean setConcat(JNIEnv* env, jobject clazz, SkMatrix* obj, SkMatrix* a, SkMatrix* b) {
-        return obj->setConcat(*a, *b);
+     static jboolean setConcat(JNIEnv* env, jobject clazz, jlong objHandle, jlong aHandle, jlong bHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
+        SkMatrix* a = reinterpret_cast<SkMatrix*>(aHandle);
+        SkMatrix* b = reinterpret_cast<SkMatrix*>(bHandle);
+        return obj->setConcat(*a, *b) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preTranslate(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat dx, jfloat dy) {
+
+    static jboolean preTranslate(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
-        return obj->preTranslate(dx_, dy_);
+        return obj->preTranslate(dx_, dy_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preScale__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sx, jfloat sy, jfloat px, jfloat py) {
+
+    static jboolean preScale__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sx, jfloat sy, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
-        return obj->preScale(sx_, sy_, px_, py_);
+        return obj->preScale(sx_, sy_, px_, py_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preScale__FF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sx, jfloat sy) {
+
+    static jboolean preScale__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sx, jfloat sy) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
-        return obj->preScale(sx_, sy_);
+        return obj->preScale(sx_, sy_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preRotate__FFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat degrees, jfloat px, jfloat py) {
+
+    static jboolean preRotate__FFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat degrees, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar degrees_ = SkFloatToScalar(degrees);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
-        return obj->preRotate(degrees_, px_, py_);
+        return obj->preRotate(degrees_, px_, py_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preRotate__F(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat degrees) {
+
+    static jboolean preRotate__F(JNIEnv* env, jobject clazz, jlong objHandle, jfloat degrees) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar degrees_ = SkFloatToScalar(degrees);
-        return obj->preRotate(degrees_);
+        return obj->preRotate(degrees_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preSkew__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat kx, jfloat ky, jfloat px, jfloat py) {
+
+    static jboolean preSkew__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat kx, jfloat ky, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar kx_ = SkFloatToScalar(kx);
         SkScalar ky_ = SkFloatToScalar(ky);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
-        return obj->preSkew(kx_, ky_, px_, py_);
+        return obj->preSkew(kx_, ky_, px_, py_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preSkew__FF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat kx, jfloat ky) {
+
+    static jboolean preSkew__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat kx, jfloat ky) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar kx_ = SkFloatToScalar(kx);
         SkScalar ky_ = SkFloatToScalar(ky);
-        return obj->preSkew(kx_, ky_);
+        return obj->preSkew(kx_, ky_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean preConcat(JNIEnv* env, jobject clazz, SkMatrix* obj, SkMatrix* other) {
-        return obj->preConcat(*other);
+
+    static jboolean preConcat(JNIEnv* env, jobject clazz, jlong objHandle, jlong otherHandle) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
+        SkMatrix* other = reinterpret_cast<SkMatrix*>(otherHandle);
+        return obj->preConcat(*other) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postTranslate(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat dx, jfloat dy) {
+
+    static jboolean postTranslate(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
-        return obj->postTranslate(dx_, dy_);
+        return obj->postTranslate(dx_, dy_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postScale__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sx, jfloat sy, jfloat px, jfloat py) {
+
+    static jboolean postScale__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sx, jfloat sy, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
-        return obj->postScale(sx_, sy_, px_, py_);
+        return obj->postScale(sx_, sy_, px_, py_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postScale__FF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat sx, jfloat sy) {
+
+    static jboolean postScale__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat sx, jfloat sy) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar sx_ = SkFloatToScalar(sx);
         SkScalar sy_ = SkFloatToScalar(sy);
-        return obj->postScale(sx_, sy_);
+        return obj->postScale(sx_, sy_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postRotate__FFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat degrees, jfloat px, jfloat py) {
+
+    static jboolean postRotate__FFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat degrees, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar degrees_ = SkFloatToScalar(degrees);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
-        return obj->postRotate(degrees_, px_, py_);
+        return obj->postRotate(degrees_, px_, py_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postRotate__F(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat degrees) {
+
+    static jboolean postRotate__F(JNIEnv* env, jobject clazz, jlong objHandle, jfloat degrees) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar degrees_ = SkFloatToScalar(degrees);
-        return obj->postRotate(degrees_);
+        return obj->postRotate(degrees_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postSkew__FFFF(JNIEnv* env, jobject clazz, SkMatrix* obj, jfloat kx, jfloat ky, jfloat px, jfloat py) {
+
+    static jboolean postSkew__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat kx, jfloat ky, jfloat px, jfloat py) {
+        SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
         SkScalar kx_ = SkFloatToScalar(kx);
         SkScalar ky_ = SkFloatToScalar(ky);
         SkScalar px_ = SkFloatToScalar(px);
         SkScalar py_ = SkFloatToScalar(py);
-        return obj->postSkew(kx_, ky_, px_, py_);
+        return obj->postSkew(kx_, ky_, px_, py_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postSkew__FF(JNIEnv* env, jobject clazz, SkMatrix* matrix, jfloat kx, jfloat ky) {
+
+    static jboolean postSkew__FF(JNIEnv* env, jobject clazz, jlong matrixHandle, jfloat kx, jfloat ky) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         SkScalar kx_ = SkFloatToScalar(kx);
         SkScalar ky_ = SkFloatToScalar(ky);
-        return matrix->postSkew(kx_, ky_);
+        return matrix->postSkew(kx_, ky_) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean postConcat(JNIEnv* env, jobject clazz, SkMatrix* matrix, SkMatrix* other) {
-        return matrix->postConcat(*other);
+
+    static jboolean postConcat(JNIEnv* env, jobject clazz, jlong matrixHandle, jlong otherHandle) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        SkMatrix* other = reinterpret_cast<SkMatrix*>(otherHandle);
+        return matrix->postConcat(*other) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean setRectToRect(JNIEnv* env, jobject clazz, SkMatrix* matrix, jobject src, jobject dst, SkMatrix::ScaleToFit stf) {
+
+    static jboolean setRectToRect(JNIEnv* env, jobject clazz, jlong matrixHandle, jobject src, jobject dst, jint stfHandle) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        SkMatrix::ScaleToFit stf = static_cast<SkMatrix::ScaleToFit>(stfHandle);
         SkRect src_;
         GraphicsJNI::jrectf_to_rect(env, src, &src_);
         SkRect dst_;
         GraphicsJNI::jrectf_to_rect(env, dst, &dst_);
-        return matrix->setRectToRect(src_, dst_, stf);
+        return matrix->setRectToRect(src_, dst_, stf) ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean setPolyToPoly(JNIEnv* env, jobject clazz, SkMatrix* matrix,
-                                  jfloatArray jsrc, int srcIndex,
-                                  jfloatArray jdst, int dstIndex, int ptCount) {
+
+    static jboolean setPolyToPoly(JNIEnv* env, jobject clazz, jlong matrixHandle,
+                                  jfloatArray jsrc, jint srcIndex,
+                                  jfloatArray jdst, jint dstIndex, jint ptCount) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         SkASSERT(srcIndex >= 0);
         SkASSERT(dstIndex >= 0);
         SkASSERT((unsigned)ptCount <= 4);
 
-        AutoJavaFloatArray autoSrc(env, jsrc, srcIndex + (ptCount << 1));
-        AutoJavaFloatArray autoDst(env, jdst, dstIndex + (ptCount << 1));
+        AutoJavaFloatArray autoSrc(env, jsrc, srcIndex + (ptCount << 1), kRO_JNIAccess);
+        AutoJavaFloatArray autoDst(env, jdst, dstIndex + (ptCount << 1), kRW_JNIAccess);
         float* src = autoSrc.ptr() + srcIndex;
         float* dst = autoDst.ptr() + dstIndex;
+        bool result;
 
 #ifdef SK_SCALAR_IS_FIXED        
         SkPoint srcPt[4], dstPt[4];
@@ -252,24 +280,28 @@
             srcPt[i].set(SkFloatToScalar(src[x]), SkFloatToScalar(src[y]));
             dstPt[i].set(SkFloatToScalar(dst[x]), SkFloatToScalar(dst[y]));
         }
-        return matrix->setPolyToPoly(srcPt, dstPt, ptCount);
+        result = matrix->setPolyToPoly(srcPt, dstPt, ptCount);
 #else
-        return matrix->setPolyToPoly((const SkPoint*)src, (const SkPoint*)dst,
+        result = matrix->setPolyToPoly((const SkPoint*)src, (const SkPoint*)dst,
                                      ptCount);
 #endif
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean invert(JNIEnv* env, jobject clazz, SkMatrix* matrix, SkMatrix* inverse) {
+
+    static jboolean invert(JNIEnv* env, jobject clazz, jlong matrixHandle, jlong inverseHandle) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        SkMatrix* inverse = reinterpret_cast<SkMatrix*>(inverseHandle);
         return matrix->invert(inverse);
     }
- 
-    static void mapPoints(JNIEnv* env, jobject clazz, SkMatrix* matrix,
-                              jfloatArray dst, int dstIndex,
-                              jfloatArray src, int srcIndex,
-                              int ptCount, bool isPts) {
+
+    static void mapPoints(JNIEnv* env, jobject clazz, jlong matrixHandle,
+                              jfloatArray dst, jint dstIndex,
+                              jfloatArray src, jint srcIndex,
+                              jint ptCount, jboolean isPts) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         SkASSERT(ptCount >= 0);
-        AutoJavaFloatArray autoSrc(env, src, srcIndex + (ptCount << 1));
-        AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1));
+        AutoJavaFloatArray autoSrc(env, src, srcIndex + (ptCount << 1), kRO_JNIAccess);
+        AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1), kRW_JNIAccess);
         float* srcArray = autoSrc.ptr() + srcIndex;
         float* dstArray = autoDst.ptr() + dstIndex;
         
@@ -304,21 +336,26 @@
                                ptCount);
 #endif
     }
- 
-    static jboolean mapRect__RectFRectF(JNIEnv* env, jobject clazz, SkMatrix* matrix, jobjectArray dst, jobject src) {
+
+    static jboolean mapRect__RectFRectF(JNIEnv* env, jobject clazz, jlong matrixHandle, jobjectArray dst, jobject src) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         SkRect dst_, src_;
         GraphicsJNI::jrectf_to_rect(env, src, &src_);
         jboolean rectStaysRect = matrix->mapRect(&dst_, src_);
         GraphicsJNI::rect_to_jrectf(dst_, env, dst);
-        return rectStaysRect;
+        return rectStaysRect ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jfloat mapRadius(JNIEnv* env, jobject clazz, SkMatrix* matrix, jfloat radius) {
-        return SkScalarToFloat(matrix->mapRadius(SkFloatToScalar(radius)));
+
+    static jfloat mapRadius(JNIEnv* env, jobject clazz, jlong matrixHandle, jfloat radius) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        float result;
+        result = SkScalarToFloat(matrix->mapRadius(SkFloatToScalar(radius)));
+        return static_cast<jfloat>(result);
     }
- 
-    static void getValues(JNIEnv* env, jobject clazz, SkMatrix* matrix, jfloatArray values) {
-        AutoJavaFloatArray autoValues(env, values, 9);
+
+    static void getValues(JNIEnv* env, jobject clazz, jlong matrixHandle, jfloatArray values) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        AutoJavaFloatArray autoValues(env, values, 9, kRW_JNIAccess);
         float* dst = autoValues.ptr();
 
 #ifdef SK_SCALAR_IS_FIXED
@@ -334,9 +371,10 @@
         }
 #endif
     }
- 
-    static void setValues(JNIEnv* env, jobject clazz, SkMatrix* matrix, jfloatArray values) {
-        AutoJavaFloatArray autoValues(env, values, 9);
+
+    static void setValues(JNIEnv* env, jobject clazz, jlong matrixHandle, jfloatArray values) {
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        AutoJavaFloatArray autoValues(env, values, 9, kRO_JNIAccess);
         const float* src = autoValues.ptr();
 
 #ifdef SK_SCALAR_IS_FIXED
@@ -353,53 +391,55 @@
 #endif
     }
 
-    static jboolean equals(JNIEnv* env, jobject clazz, const SkMatrix* a, const SkMatrix* b) {
+    static jboolean equals(JNIEnv* env, jobject clazz, jlong aHandle, jlong bHandle) {
+        const SkMatrix* a = reinterpret_cast<SkMatrix*>(aHandle);
+        const SkMatrix* b = reinterpret_cast<SkMatrix*>(bHandle);
         return *a == *b;
     }
  };
 
 static JNINativeMethod methods[] = {
-    {"finalizer", "(I)V", (void*) SkMatrixGlue::finalizer},
-    {"native_create","(I)I", (void*) SkMatrixGlue::create},
-    {"native_isIdentity","(I)Z", (void*) SkMatrixGlue::isIdentity},
-    {"native_rectStaysRect","(I)Z", (void*) SkMatrixGlue::rectStaysRect},
-    {"native_reset","(I)V", (void*) SkMatrixGlue::reset},
-    {"native_set","(II)V", (void*) SkMatrixGlue::set},
-    {"native_setTranslate","(IFF)V", (void*) SkMatrixGlue::setTranslate},
-    {"native_setScale","(IFFFF)V", (void*) SkMatrixGlue::setScale__FFFF},
-    {"native_setScale","(IFF)V", (void*) SkMatrixGlue::setScale__FF},
-    {"native_setRotate","(IFFF)V", (void*) SkMatrixGlue::setRotate__FFF},
-    {"native_setRotate","(IF)V", (void*) SkMatrixGlue::setRotate__F},
-    {"native_setSinCos","(IFFFF)V", (void*) SkMatrixGlue::setSinCos__FFFF},
-    {"native_setSinCos","(IFF)V", (void*) SkMatrixGlue::setSinCos__FF},
-    {"native_setSkew","(IFFFF)V", (void*) SkMatrixGlue::setSkew__FFFF},
-    {"native_setSkew","(IFF)V", (void*) SkMatrixGlue::setSkew__FF},
-    {"native_setConcat","(III)Z", (void*) SkMatrixGlue::setConcat},
-    {"native_preTranslate","(IFF)Z", (void*) SkMatrixGlue::preTranslate},
-    {"native_preScale","(IFFFF)Z", (void*) SkMatrixGlue::preScale__FFFF},
-    {"native_preScale","(IFF)Z", (void*) SkMatrixGlue::preScale__FF},
-    {"native_preRotate","(IFFF)Z", (void*) SkMatrixGlue::preRotate__FFF},
-    {"native_preRotate","(IF)Z", (void*) SkMatrixGlue::preRotate__F},
-    {"native_preSkew","(IFFFF)Z", (void*) SkMatrixGlue::preSkew__FFFF},
-    {"native_preSkew","(IFF)Z", (void*) SkMatrixGlue::preSkew__FF},
-    {"native_preConcat","(II)Z", (void*) SkMatrixGlue::preConcat},
-    {"native_postTranslate","(IFF)Z", (void*) SkMatrixGlue::postTranslate},
-    {"native_postScale","(IFFFF)Z", (void*) SkMatrixGlue::postScale__FFFF},
-    {"native_postScale","(IFF)Z", (void*) SkMatrixGlue::postScale__FF},
-    {"native_postRotate","(IFFF)Z", (void*) SkMatrixGlue::postRotate__FFF},
-    {"native_postRotate","(IF)Z", (void*) SkMatrixGlue::postRotate__F},
-    {"native_postSkew","(IFFFF)Z", (void*) SkMatrixGlue::postSkew__FFFF},
-    {"native_postSkew","(IFF)Z", (void*) SkMatrixGlue::postSkew__FF},
-    {"native_postConcat","(II)Z", (void*) SkMatrixGlue::postConcat},
-    {"native_setRectToRect","(ILandroid/graphics/RectF;Landroid/graphics/RectF;I)Z", (void*) SkMatrixGlue::setRectToRect},
-    {"native_setPolyToPoly","(I[FI[FII)Z", (void*) SkMatrixGlue::setPolyToPoly},
-    {"native_invert","(II)Z", (void*) SkMatrixGlue::invert},
-    {"native_mapPoints","(I[FI[FIIZ)V", (void*) SkMatrixGlue::mapPoints},
-    {"native_mapRect","(ILandroid/graphics/RectF;Landroid/graphics/RectF;)Z", (void*) SkMatrixGlue::mapRect__RectFRectF},
-    {"native_mapRadius","(IF)F", (void*) SkMatrixGlue::mapRadius},
-    {"native_getValues","(I[F)V", (void*) SkMatrixGlue::getValues},
-    {"native_setValues","(I[F)V", (void*) SkMatrixGlue::setValues},
-    {"native_equals", "(II)Z", (void*) SkMatrixGlue::equals}
+    {"finalizer", "(J)V", (void*) SkMatrixGlue::finalizer},
+    {"native_create","(J)J", (void*) SkMatrixGlue::create},
+    {"native_isIdentity","(J)Z", (void*) SkMatrixGlue::isIdentity},
+    {"native_rectStaysRect","(J)Z", (void*) SkMatrixGlue::rectStaysRect},
+    {"native_reset","(J)V", (void*) SkMatrixGlue::reset},
+    {"native_set","(JJ)V", (void*) SkMatrixGlue::set},
+    {"native_setTranslate","(JFF)V", (void*) SkMatrixGlue::setTranslate},
+    {"native_setScale","(JFFFF)V", (void*) SkMatrixGlue::setScale__FFFF},
+    {"native_setScale","(JFF)V", (void*) SkMatrixGlue::setScale__FF},
+    {"native_setRotate","(JFFF)V", (void*) SkMatrixGlue::setRotate__FFF},
+    {"native_setRotate","(JF)V", (void*) SkMatrixGlue::setRotate__F},
+    {"native_setSinCos","(JFFFF)V", (void*) SkMatrixGlue::setSinCos__FFFF},
+    {"native_setSinCos","(JFF)V", (void*) SkMatrixGlue::setSinCos__FF},
+    {"native_setSkew","(JFFFF)V", (void*) SkMatrixGlue::setSkew__FFFF},
+    {"native_setSkew","(JFF)V", (void*) SkMatrixGlue::setSkew__FF},
+    {"native_setConcat","(JJJ)Z", (void*) SkMatrixGlue::setConcat},
+    {"native_preTranslate","(JFF)Z", (void*) SkMatrixGlue::preTranslate},
+    {"native_preScale","(JFFFF)Z", (void*) SkMatrixGlue::preScale__FFFF},
+    {"native_preScale","(JFF)Z", (void*) SkMatrixGlue::preScale__FF},
+    {"native_preRotate","(JFFF)Z", (void*) SkMatrixGlue::preRotate__FFF},
+    {"native_preRotate","(JF)Z", (void*) SkMatrixGlue::preRotate__F},
+    {"native_preSkew","(JFFFF)Z", (void*) SkMatrixGlue::preSkew__FFFF},
+    {"native_preSkew","(JFF)Z", (void*) SkMatrixGlue::preSkew__FF},
+    {"native_preConcat","(JJ)Z", (void*) SkMatrixGlue::preConcat},
+    {"native_postTranslate","(JFF)Z", (void*) SkMatrixGlue::postTranslate},
+    {"native_postScale","(JFFFF)Z", (void*) SkMatrixGlue::postScale__FFFF},
+    {"native_postScale","(JFF)Z", (void*) SkMatrixGlue::postScale__FF},
+    {"native_postRotate","(JFFF)Z", (void*) SkMatrixGlue::postRotate__FFF},
+    {"native_postRotate","(JF)Z", (void*) SkMatrixGlue::postRotate__F},
+    {"native_postSkew","(JFFFF)Z", (void*) SkMatrixGlue::postSkew__FFFF},
+    {"native_postSkew","(JFF)Z", (void*) SkMatrixGlue::postSkew__FF},
+    {"native_postConcat","(JJ)Z", (void*) SkMatrixGlue::postConcat},
+    {"native_setRectToRect","(JLandroid/graphics/RectF;Landroid/graphics/RectF;I)Z", (void*) SkMatrixGlue::setRectToRect},
+    {"native_setPolyToPoly","(J[FI[FII)Z", (void*) SkMatrixGlue::setPolyToPoly},
+    {"native_invert","(JJ)Z", (void*) SkMatrixGlue::invert},
+    {"native_mapPoints","(J[FI[FIIZ)V", (void*) SkMatrixGlue::mapPoints},
+    {"native_mapRect","(JLandroid/graphics/RectF;Landroid/graphics/RectF;)Z", (void*) SkMatrixGlue::mapRect__RectFRectF},
+    {"native_mapRadius","(JF)F", (void*) SkMatrixGlue::mapRadius},
+    {"native_getValues","(J[F)V", (void*) SkMatrixGlue::getValues},
+    {"native_setValues","(J[F)V", (void*) SkMatrixGlue::setValues},
+    {"native_equals", "(JJ)Z", (void*) SkMatrixGlue::equals}
 };
 
 static jfieldID sNativeInstanceField;
@@ -409,13 +449,13 @@
         sizeof(methods) / sizeof(methods[0]));
 
     jclass clazz = env->FindClass("android/graphics/Matrix");
-    sNativeInstanceField = env->GetFieldID(clazz, "native_instance", "I");
+    sNativeInstanceField = env->GetFieldID(clazz, "native_instance", "J");
 
     return result;
 }
 
 SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrixObj) {
-    return reinterpret_cast<SkMatrix*>(env->GetIntField(matrixObj, sNativeInstanceField));
+    return reinterpret_cast<SkMatrix*>(env->GetLongField(matrixObj, sNativeInstanceField));
 }
 
 }
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index 55be7c1..0040b6f 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -27,43 +27,43 @@
         return NULL;
     }
     return env->NewObject(gMovie_class, gMovie_constructorMethodID,
-            static_cast<jint>(reinterpret_cast<uintptr_t>(moov)));
+            static_cast<jlong>(reinterpret_cast<uintptr_t>(moov)));
 }
 
 static SkMovie* J2Movie(JNIEnv* env, jobject movie) {
     SkASSERT(env);
     SkASSERT(movie);
     SkASSERT(env->IsInstanceOf(movie, gMovie_class));
-    SkMovie* m = (SkMovie*)env->GetIntField(movie, gMovie_nativeInstanceID);
+    SkMovie* m = (SkMovie*)env->GetLongField(movie, gMovie_nativeInstanceID);
     SkASSERT(m);
     return m;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static int movie_width(JNIEnv* env, jobject movie) {
+static jint movie_width(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->width();
+    return static_cast<jint>(J2Movie(env, movie)->width());
 }
 
-static int movie_height(JNIEnv* env, jobject movie) {
+static jint movie_height(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->height();
+    return static_cast<jint>(J2Movie(env, movie)->height());
 }
 
 static jboolean movie_isOpaque(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->isOpaque();
+    return J2Movie(env, movie)->isOpaque() ? JNI_TRUE : JNI_FALSE;
 }
 
-static int movie_duration(JNIEnv* env, jobject movie) {
+static jint movie_duration(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->duration();
+    return static_cast<jint>(J2Movie(env, movie)->duration());
 }
 
-static jboolean movie_setTime(JNIEnv* env, jobject movie, int ms) {
+static jboolean movie_setTime(JNIEnv* env, jobject movie, jint ms) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->setTime(ms);
+    return J2Movie(env, movie)->setTime(ms) ? JNI_TRUE : JNI_FALSE;
 }
 
 static void movie_draw(JNIEnv* env, jobject movie, jobject canvas,
@@ -82,12 +82,10 @@
     c->drawBitmap(b, sx, sy, p);
 }
 
-static jobject movie_decodeAsset(JNIEnv* env, jobject clazz, jint native_asset) {
+static jobject movie_decodeAsset(JNIEnv* env, jobject clazz, jlong native_asset) {
     android::Asset* asset = reinterpret_cast<android::Asset*>(native_asset);
     if (asset == NULL) return NULL;
-    SkAutoTUnref<SkStreamRewindable> stream (new android::AssetStreamAdaptor(asset,
-            android::AssetStreamAdaptor::kNo_OwnAsset,
-            android::AssetStreamAdaptor::kNo_HasMemoryBase));
+    SkAutoTUnref<SkStreamRewindable> stream (new android::AssetStreamAdaptor(asset));
     SkMovie* moov = SkMovie::DecodeStream(stream.get());
     return create_jmovie(env, moov);
 }
@@ -117,7 +115,7 @@
 
 static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz,
                                      jbyteArray byteArray,
-                                     int offset, int length) {
+                                     jint offset, jint length) {
 
     NPE_CHECK_RETURN_ZERO(env, byteArray);
 
@@ -132,7 +130,8 @@
     return create_jmovie(env, moov);
 }
 
-static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
+static void movie_destructor(JNIEnv* env, jobject, jlong movieHandle) {
+    SkMovie* movie = (SkMovie*) movieHandle;
     delete movie;
 }
 
@@ -148,11 +147,11 @@
     {   "setTime",  "(I)Z", (void*)movie_setTime  },
     {   "draw",     "(Landroid/graphics/Canvas;FFLandroid/graphics/Paint;)V",
                             (void*)movie_draw  },
-    { "nativeDecodeAsset", "(I)Landroid/graphics/Movie;",
+    { "nativeDecodeAsset", "(J)Landroid/graphics/Movie;",
                             (void*)movie_decodeAsset },
     { "nativeDecodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
                             (void*)movie_decodeStream },
-    { "nativeDestructor","(I)V", (void*)movie_destructor },
+    { "nativeDestructor","(J)V", (void*)movie_destructor },
     { "decodeByteArray", "([BII)Landroid/graphics/Movie;",
                             (void*)movie_decodeByteArray },
 };
@@ -167,10 +166,10 @@
     RETURN_ERR_IF_NULL(gMovie_class);
     gMovie_class = (jclass)env->NewGlobalRef(gMovie_class);
 
-    gMovie_constructorMethodID = env->GetMethodID(gMovie_class, "<init>", "(I)V");
+    gMovie_constructorMethodID = env->GetMethodID(gMovie_class, "<init>", "(J)V");
     RETURN_ERR_IF_NULL(gMovie_constructorMethodID);
 
-    gMovie_nativeInstanceID = env->GetFieldID(gMovie_class, "mNativeMovie", "I");
+    gMovie_nativeInstanceID = env->GetFieldID(gMovie_class, "mNativeMovie", "J");
     RETURN_ERR_IF_NULL(gMovie_nativeInstanceID);
 
     return android::AndroidRuntime::registerNativeMethods(env, kClassPathName,
diff --git a/core/jni/android/graphics/NinePatch.cpp b/core/jni/android/graphics/NinePatch.cpp
index 7e6aeae..871e24d 100644
--- a/core/jni/android/graphics/NinePatch.cpp
+++ b/core/jni/android/graphics/NinePatch.cpp
@@ -46,22 +46,22 @@
 public:
     static jboolean isNinePatchChunk(JNIEnv* env, jobject, jbyteArray obj) {
         if (NULL == obj) {
-            return false;
+            return JNI_FALSE;
         }
         if (env->GetArrayLength(obj) < (int)sizeof(Res_png_9patch)) {
-            return false;
+            return JNI_FALSE;
         }
         const jbyte* array = env->GetByteArrayElements(obj, 0);
         if (array != NULL) {
             const Res_png_9patch* chunk = reinterpret_cast<const Res_png_9patch*>(array);
             int8_t wasDeserialized = chunk->wasDeserialized;
             env->ReleaseByteArrayElements(obj, const_cast<jbyte*>(array), JNI_ABORT);
-            return wasDeserialized != -1;
+            return (wasDeserialized != -1) ? JNI_TRUE : JNI_FALSE;
         }
-        return false;
+        return JNI_FALSE;
     }
 
-    static int8_t* validateNinePatchChunk(JNIEnv* env, jobject, jint, jbyteArray obj) {
+    static jlong validateNinePatchChunk(JNIEnv* env, jobject, jlong, jbyteArray obj) {
         size_t chunkSize = env->GetArrayLength(obj);
         if (chunkSize < (int) (sizeof(Res_png_9patch))) {
             jniThrowRuntimeException(env, "Array too small for chunk.");
@@ -72,10 +72,11 @@
         // This call copies the content of the jbyteArray
         env->GetByteArrayRegion(obj, 0, chunkSize, reinterpret_cast<jbyte*>(storage));
         // Deserialize in place, return the array we just allocated
-        return (int8_t*) Res_png_9patch::deserialize(storage);
+        return reinterpret_cast<jlong>(Res_png_9patch::deserialize(storage));
     }
 
-    static void finalize(JNIEnv* env, jobject, int8_t* patch) {
+    static void finalize(JNIEnv* env, jobject, jlong patchHandle) {
+        int8_t* patch = reinterpret_cast<int8_t*>(patchHandle);
 #ifdef USE_OPENGL_RENDERER
         if (android::uirenderer::Caches::hasInstance()) {
             Res_png_9patch* p = (Res_png_9patch*) patch;
@@ -115,9 +116,13 @@
         }
     }
 
-    static void drawF(JNIEnv* env, jobject, SkCanvas* canvas, jobject boundsRectF,
-            const SkBitmap* bitmap, Res_png_9patch* chunk, const SkPaint* paint,
+    static void drawF(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRectF,
+            jlong bitmapHandle, jlong chunkHandle, jlong paintHandle,
             jint destDensity, jint srcDensity) {
+        SkCanvas* canvas       = reinterpret_cast<SkCanvas*>(canvasHandle);
+        const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        Res_png_9patch* chunk  = reinterpret_cast<Res_png_9patch*>(chunkHandle);
+        const SkPaint* paint   = reinterpret_cast<SkPaint*>(paintHandle);
         SkASSERT(canvas);
         SkASSERT(boundsRectF);
         SkASSERT(bitmap);
@@ -130,9 +135,13 @@
         draw(env, canvas, bounds, bitmap, chunk, paint, destDensity, srcDensity);
     }
 
-    static void drawI(JNIEnv* env, jobject, SkCanvas* canvas, jobject boundsRect,
-            const SkBitmap* bitmap, Res_png_9patch* chunk, const SkPaint* paint,
+    static void drawI(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRect,
+            jlong bitmapHandle, jlong chunkHandle, jlong paintHandle,
             jint destDensity, jint srcDensity) {
+        SkCanvas* canvas       = reinterpret_cast<SkCanvas*>(canvasHandle);
+        const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        Res_png_9patch* chunk  = reinterpret_cast<Res_png_9patch*>(chunkHandle);
+        const SkPaint* paint   = reinterpret_cast<SkPaint*>(paintHandle);
         SkASSERT(canvas);
         SkASSERT(boundsRect);
         SkASSERT(bitmap);
@@ -144,8 +153,10 @@
         draw(env, canvas, bounds, bitmap, chunk, paint, destDensity, srcDensity);
     }
 
-    static jint getTransparentRegion(JNIEnv* env, jobject, const SkBitmap* bitmap,
-            Res_png_9patch* chunk, jobject boundsRect) {
+    static jlong getTransparentRegion(JNIEnv* env, jobject, jlong bitmapHandle,
+            jlong chunkHandle, jobject boundsRect) {
+        const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+        Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
         SkASSERT(bitmap);
         SkASSERT(chunk);
         SkASSERT(boundsRect);
@@ -156,7 +167,7 @@
         SkRegion* region = NULL;
         NinePatch_Draw(NULL, bounds, *bitmap, *chunk, NULL, &region);
 
-        return (jint) region;
+        return reinterpret_cast<jlong>(region);
     }
 
 };
@@ -167,11 +178,11 @@
 
 static JNINativeMethod gNinePatchMethods[] = {
     { "isNinePatchChunk", "([B)Z",                        (void*) SkNinePatchGlue::isNinePatchChunk },
-    { "validateNinePatchChunk", "(I[B)I",                 (void*) SkNinePatchGlue::validateNinePatchChunk },
-    { "nativeFinalize", "(I)V",                           (void*) SkNinePatchGlue::finalize },
-    { "nativeDraw", "(ILandroid/graphics/RectF;IIIII)V",  (void*) SkNinePatchGlue::drawF },
-    { "nativeDraw", "(ILandroid/graphics/Rect;IIIII)V",   (void*) SkNinePatchGlue::drawI },
-    { "nativeGetTransparentRegion", "(IILandroid/graphics/Rect;)I",
+    { "validateNinePatchChunk", "(J[B)J",                 (void*) SkNinePatchGlue::validateNinePatchChunk },
+    { "nativeFinalize", "(J)V",                           (void*) SkNinePatchGlue::finalize },
+    { "nativeDraw", "(JLandroid/graphics/RectF;JJJII)V",  (void*) SkNinePatchGlue::drawF },
+    { "nativeDraw", "(JLandroid/graphics/Rect;JJJII)V",   (void*) SkNinePatchGlue::drawI },
+    { "nativeGetTransparentRegion", "(JJLandroid/graphics/Rect;)J",
                                                           (void*) SkNinePatchGlue::getTransparentRegion }
 };
 
diff --git a/core/jni/android/graphics/NinePatchPeeker.cpp b/core/jni/android/graphics/NinePatchPeeker.cpp
index d3482da..df996af 100644
--- a/core/jni/android/graphics/NinePatchPeeker.cpp
+++ b/core/jni/android/graphics/NinePatchPeeker.cpp
@@ -40,14 +40,15 @@
         // now update our host to force index or 32bit config
         // 'cause we don't want 565 predithered, since as a 9patch, we know
         // we will be stretched, and therefore we want to dither afterwards.
-        SkImageDecoder::PrefConfigTable table;
-        table.fPrefFor_8Index_NoAlpha_src   = SkBitmap::kIndex8_Config;
-        table.fPrefFor_8Index_YesAlpha_src  = SkBitmap::kIndex8_Config;
-        table.fPrefFor_8Gray_src            = SkBitmap::kARGB_8888_Config;
-        table.fPrefFor_8bpc_NoAlpha_src     = SkBitmap::kARGB_8888_Config;
-        table.fPrefFor_8bpc_YesAlpha_src    = SkBitmap::kARGB_8888_Config;
-
-        fHost->setPrefConfigTable(table);
+        static const SkBitmap::Config gNo565Pref[] = {
+            SkBitmap::kIndex8_Config,
+            SkBitmap::kIndex8_Config,
+            SkBitmap::kARGB_8888_Config,
+            SkBitmap::kARGB_8888_Config,
+            SkBitmap::kARGB_8888_Config,
+            SkBitmap::kARGB_8888_Config,
+        };
+        fHost->setPrefConfigTable(gNo565Pref);
     } else if (strcmp("npLb", tag) == 0 && length == sizeof(int) * 4) {
         fLayoutBounds = new int[4];
         memcpy(fLayoutBounds, data, sizeof(int) * 4);
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 4f6cc37..25234813 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -70,33 +70,40 @@
         AFTER, AT_OR_AFTER, BEFORE, AT_OR_BEFORE, AT
     };
 
-    static void finalizer(JNIEnv* env, jobject clazz, SkPaint* obj) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
         delete obj;
     }
 
-    static SkPaint* init(JNIEnv* env, jobject clazz) {
+    static jlong init(JNIEnv* env, jobject clazz) {
         SkPaint* obj = new SkPaint();
         defaultSettingsForAndroid(obj);
-        return obj;
+        return reinterpret_cast<jlong>(obj);
     }
 
-    static SkPaint* intiWithPaint(JNIEnv* env, jobject clazz, SkPaint* paint) {
+    static jlong initWithPaint(JNIEnv* env, jobject clazz, jlong paintHandle) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         SkPaint* obj = new SkPaint(*paint);
-        return obj;
+        return reinterpret_cast<jlong>(obj);
     }
 
-    static void reset(JNIEnv* env, jobject clazz, SkPaint* obj) {
+    static void reset(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
         obj->reset();
         defaultSettingsForAndroid(obj);
     }
 
-    static void assign(JNIEnv* env, jobject clazz, SkPaint* dst, const SkPaint* src) {
+    static void assign(JNIEnv* env, jobject clazz, jlong dstPaintHandle, jlong srcPaintHandle) {
+        SkPaint* dst = reinterpret_cast<SkPaint*>(dstPaintHandle);
+        const SkPaint* src = reinterpret_cast<SkPaint*>(srcPaintHandle);
         *dst = *src;
     }
 
     static jint getFlags(JNIEnv* env, jobject paint) {
         NPE_CHECK_RETURN_ZERO(env, paint);
-        return GraphicsJNI::getNativePaint(env, paint)->getFlags();
+        int result;
+        result = GraphicsJNI::getNativePaint(env, paint)->getFlags();
+        return static_cast<jint>(result);
     }
 
     static void setFlags(JNIEnv* env, jobject paint, jint flags) {
@@ -148,8 +155,7 @@
 
     static void setFilterBitmap(JNIEnv* env, jobject paint, jboolean filterBitmap) {
         NPE_CHECK_RETURN_VOID(env, paint);
-        GraphicsJNI::getNativePaint(env, paint)->setFilterLevel(
-                filterBitmap ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
+        GraphicsJNI::getNativePaint(env, paint)->setFilterBitmap(filterBitmap);
     }
 
     static void setDither(JNIEnv* env, jobject paint, jboolean dither) {
@@ -157,22 +163,29 @@
         GraphicsJNI::getNativePaint(env, paint)->setDither(dither);
     }
 
-    static jint getStyle(JNIEnv* env, jobject clazz, SkPaint* obj) {
-        return obj->getStyle();
+    static jint getStyle(JNIEnv* env, jobject clazz,jlong objHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        return static_cast<jint>(obj->getStyle());
     }
 
-    static void setStyle(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Style style) {
+    static void setStyle(JNIEnv* env, jobject clazz, jlong objHandle, jint styleHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkPaint::Style style = static_cast<SkPaint::Style>(styleHandle);
         obj->setStyle(style);
     }
 
     static jint getColor(JNIEnv* env, jobject paint) {
         NPE_CHECK_RETURN_ZERO(env, paint);
-        return GraphicsJNI::getNativePaint(env, paint)->getColor();
+        int color;
+        color = GraphicsJNI::getNativePaint(env, paint)->getColor();
+        return static_cast<jint>(color);
     }
 
     static jint getAlpha(JNIEnv* env, jobject paint) {
         NPE_CHECK_RETURN_ZERO(env, paint);
-        return GraphicsJNI::getNativePaint(env, paint)->getAlpha();
+        int alpha;
+        alpha = GraphicsJNI::getNativePaint(env, paint)->getAlpha();
+        return static_cast<jint>(alpha);
     }
 
     static void setColor(JNIEnv* env, jobject paint, jint color) {
@@ -205,59 +218,85 @@
         GraphicsJNI::getNativePaint(env, paint)->setStrokeMiter(SkFloatToScalar(miter));
     }
 
-    static jint getStrokeCap(JNIEnv* env, jobject clazz, SkPaint* obj) {
-        return obj->getStrokeCap();
+    static jint getStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        return static_cast<jint>(obj->getStrokeCap());
     }
 
-    static void setStrokeCap(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Cap cap) {
+    static void setStrokeCap(JNIEnv* env, jobject clazz, jlong objHandle, jint capHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkPaint::Cap cap = static_cast<SkPaint::Cap>(capHandle);
         obj->setStrokeCap(cap);
     }
 
-    static jint getStrokeJoin(JNIEnv* env, jobject clazz, SkPaint* obj) {
-        return obj->getStrokeJoin();
+    static jint getStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        return static_cast<jint>(obj->getStrokeJoin());
     }
 
-    static void setStrokeJoin(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Join join) {
+    static void setStrokeJoin(JNIEnv* env, jobject clazz, jlong objHandle, jint joinHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkPaint::Join join = (SkPaint::Join) joinHandle;
         obj->setStrokeJoin(join);
     }
 
-    static jboolean getFillPath(JNIEnv* env, jobject clazz, SkPaint* obj, SkPath* src, SkPath* dst) {
-        return obj->getFillPath(*src, dst);
+    static jboolean getFillPath(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle, jlong dstHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkPath* src = reinterpret_cast<SkPath*>(srcHandle);
+        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
+        return obj->getFillPath(*src, dst) ? JNI_TRUE : JNI_FALSE;
     }
 
-    static SkShader* setShader(JNIEnv* env, jobject clazz, SkPaint* obj, SkShader* shader) {
-        return obj->setShader(shader);
+    static jlong setShader(JNIEnv* env, jobject clazz, jlong objHandle, jlong shaderHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
+        return reinterpret_cast<jlong>(obj->setShader(shader));
     }
 
-    static SkColorFilter* setColorFilter(JNIEnv* env, jobject clazz, SkPaint* obj, SkColorFilter* filter) {
-        return obj->setColorFilter(filter);
+    static jlong setColorFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong filterHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint *>(objHandle);
+        SkColorFilter* filter  = reinterpret_cast<SkColorFilter *>(filterHandle);
+        return reinterpret_cast<jlong>(obj->setColorFilter(filter));
     }
 
-    static SkXfermode* setXfermode(JNIEnv* env, jobject clazz, SkPaint* obj, SkXfermode* xfermode) {
-        return obj->setXfermode(xfermode);
+    static jlong setXfermode(JNIEnv* env, jobject clazz, jlong objHandle, jlong xfermodeHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkXfermode* xfermode = reinterpret_cast<SkXfermode*>(xfermodeHandle);
+        return reinterpret_cast<jlong>(obj->setXfermode(xfermode));
     }
 
-    static SkPathEffect* setPathEffect(JNIEnv* env, jobject clazz, SkPaint* obj, SkPathEffect* effect) {
-        return obj->setPathEffect(effect);
+    static jlong setPathEffect(JNIEnv* env, jobject clazz, jlong objHandle, jlong effectHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkPathEffect* effect  = reinterpret_cast<SkPathEffect*>(effectHandle);
+        return reinterpret_cast<jlong>(obj->setPathEffect(effect));
     }
 
-    static SkMaskFilter* setMaskFilter(JNIEnv* env, jobject clazz, SkPaint* obj, SkMaskFilter* maskfilter) {
-        return obj->setMaskFilter(maskfilter);
+    static jlong setMaskFilter(JNIEnv* env, jobject clazz, jlong objHandle, jlong maskfilterHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkMaskFilter* maskfilter  = reinterpret_cast<SkMaskFilter*>(maskfilterHandle);
+        return reinterpret_cast<jlong>(obj->setMaskFilter(maskfilter));
     }
 
-    static SkTypeface* setTypeface(JNIEnv* env, jobject clazz, SkPaint* obj, SkTypeface* typeface) {
-        return obj->setTypeface(typeface);
+    static jlong setTypeface(JNIEnv* env, jobject clazz, jlong objHandle, jlong typefaceHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkTypeface* typeface = reinterpret_cast<SkTypeface*>(typefaceHandle);
+        return reinterpret_cast<jlong>(obj->setTypeface(typeface));
     }
 
-    static SkRasterizer* setRasterizer(JNIEnv* env, jobject clazz, SkPaint* obj, SkRasterizer* rasterizer) {
-        return obj->setRasterizer(rasterizer);
+    static jlong setRasterizer(JNIEnv* env, jobject clazz, jlong objHandle, jlong rasterizerHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkRasterizer* rasterizer = reinterpret_cast<SkRasterizer*>(rasterizerHandle);
+        return reinterpret_cast<jlong>(obj->setRasterizer(rasterizer));
     }
 
-    static jint getTextAlign(JNIEnv* env, jobject clazz, SkPaint* obj) {
-        return obj->getTextAlign();
+    static jint getTextAlign(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        return static_cast<jint>(obj->getTextAlign());
     }
 
-    static void setTextAlign(JNIEnv* env, jobject clazz, SkPaint* obj, SkPaint::Align align) {
+    static void setTextAlign(JNIEnv* env, jobject clazz, jlong objHandle, jint alignHandle) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
+        SkPaint::Align align = static_cast<SkPaint::Align>(alignHandle);
         obj->setTextAlign(align);
     }
 
@@ -301,7 +340,8 @@
         output[0] = '\0';
     }
 
-    static void setTextLocale(JNIEnv* env, jobject clazz, SkPaint* obj, jstring locale) {
+    static void setTextLocale(JNIEnv* env, jobject clazz, jlong objHandle, jstring locale) {
+        SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
         ScopedUtfChars localeChars(env, locale);
         char langTag[ULOC_FULLNAME_CAPACITY];
         toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, localeChars.c_str());
@@ -391,7 +431,7 @@
         return descent - ascent + leading;
     }
 
-    static jfloat measureText_CIII(JNIEnv* env, jobject jpaint, jcharArray text, int index, int count,
+    static jfloat measureText_CIII(JNIEnv* env, jobject jpaint, jcharArray text, jint index, jint count,
             jint bidiFlags) {
         NPE_CHECK_RETURN_ZERO(env, jpaint);
         NPE_CHECK_RETURN_ZERO(env, text);
@@ -416,7 +456,7 @@
         return result;
     }
 
-    static jfloat measureText_StringIII(JNIEnv* env, jobject jpaint, jstring text, int start, int end,
+    static jfloat measureText_StringIII(JNIEnv* env, jobject jpaint, jstring text, jint start, jint end,
             jint bidiFlags) {
         NPE_CHECK_RETURN_ZERO(env, jpaint);
         NPE_CHECK_RETURN_ZERO(env, text);
@@ -489,8 +529,9 @@
         return count;
     }
 
-    static int getTextWidths___CIII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text,
-            int index, int count, jint bidiFlags, jfloatArray widths) {
+    static jint getTextWidths___CIII_F(JNIEnv* env, jobject clazz, jlong paintHandle, jcharArray text,
+            jint index, jint count, jint bidiFlags, jfloatArray widths) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetCharArrayElements(text, NULL);
         count = dotextwidths(env, paint, textArray + index, count, widths, bidiFlags);
         env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray),
@@ -498,8 +539,9 @@
         return count;
     }
 
-    static int getTextWidths__StringIII_F(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text,
-            int start, int end, jint bidiFlags, jfloatArray widths) {
+    static jint getTextWidths__StringIII_F(JNIEnv* env, jobject clazz, jlong paintHandle, jstring text,
+            jint start, jint end, jint bidiFlags, jfloatArray widths) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetStringChars(text, NULL);
         int count = dotextwidths(env, paint, textArray + start, end - start, widths, bidiFlags);
         env->ReleaseStringChars(text, textArray);
@@ -536,9 +578,10 @@
         return glyphsCount;
     }
 
-    static int getTextGlyphs__StringIIIII_C(JNIEnv* env, jobject clazz, SkPaint* paint,
+    static jint getTextGlyphs__StringIIIII_C(JNIEnv* env, jobject clazz, jlong paintHandle,
             jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags,
             jcharArray glyphs) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetStringChars(text, NULL);
         int count = doTextGlyphs(env, paint, textArray + contextStart, start - contextStart,
                 end - start, contextEnd - contextStart, flags, glyphs);
@@ -578,9 +621,10 @@
         return totalAdvance;
     }
 
-    static float getTextRunAdvances___CIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint,
+    static jfloat getTextRunAdvances___CIIIII_FI(JNIEnv* env, jobject clazz, jlong paintHandle,
             jcharArray text, jint index, jint count, jint contextIndex, jint contextCount,
             jint flags, jfloatArray advances, jint advancesIndex) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         jchar* textArray = env->GetCharArrayElements(text, NULL);
         jfloat result = doTextRunAdvances(env, paint, textArray + contextIndex,
                 index - contextIndex, count, contextCount, flags, advances, advancesIndex);
@@ -588,9 +632,10 @@
         return result;
     }
 
-    static float getTextRunAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, SkPaint* paint,
+    static jfloat getTextRunAdvances__StringIIIII_FI(JNIEnv* env, jobject clazz, jlong paintHandle,
             jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint flags,
             jfloatArray advances, jint advancesIndex) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetStringChars(text, NULL);
         jfloat result = doTextRunAdvances(env, paint, textArray + contextStart,
                 start - contextStart, end - start, contextEnd - contextStart, flags,
@@ -643,8 +688,9 @@
         return pos;
     }
 
-    static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, SkPaint* paint, jcharArray text,
+    static jint getTextRunCursor___C(JNIEnv* env, jobject clazz, jlong paintHandle, jcharArray text,
             jint contextStart, jint contextCount, jint flags, jint offset, jint cursorOpt) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         jchar* textArray = env->GetCharArrayElements(text, NULL);
         jint result = doTextRunCursor(env, paint, textArray, contextStart, contextCount, flags,
                 offset, cursorOpt);
@@ -652,8 +698,9 @@
         return result;
     }
 
-    static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, SkPaint* paint, jstring text,
+    static jint getTextRunCursor__String(JNIEnv* env, jobject clazz, jlong paintHandle, jstring text,
             jint contextStart, jint contextEnd, jint flags, jint offset, jint cursorOpt) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetStringChars(text, NULL);
         jint result = doTextRunCursor(env, paint, textArray, contextStart,
                 contextEnd - contextStart, flags, offset, cursorOpt);
@@ -666,22 +713,26 @@
         TextLayout::getTextPath(paint, text, count, bidiFlags, x, y, path);
     }
 
-    static void getTextPath___C(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags,
-            jcharArray text, int index, int count, jfloat x, jfloat y, SkPath* path) {
+    static void getTextPath___C(JNIEnv* env, jobject clazz, jlong paintHandle, jint bidiFlags,
+            jcharArray text, jint index, jint count, jfloat x, jfloat y, jlong pathHandle) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
+        SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
         const jchar* textArray = env->GetCharArrayElements(text, NULL);
         getTextPath(env, paint, textArray + index, count, bidiFlags, x, y, path);
         env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray), JNI_ABORT);
     }
 
-    static void getTextPath__String(JNIEnv* env, jobject clazz, SkPaint* paint, jint bidiFlags,
-            jstring text, int start, int end, jfloat x, jfloat y, SkPath* path) {
+    static void getTextPath__String(JNIEnv* env, jobject clazz, jlong paintHandle, jint bidiFlags,
+            jstring text, jint start, jint end, jfloat x, jfloat y, jlong pathHandle) {
+        SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
+        SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
         const jchar* textArray = env->GetStringChars(text, NULL);
         getTextPath(env, paint, textArray + start, end - start, bidiFlags, x, y, path);
         env->ReleaseStringChars(text, textArray);
     }
 
     static void setShadowLayer(JNIEnv* env, jobject jpaint, jfloat radius,
-                               jfloat dx, jfloat dy, int color) {
+                               jfloat dx, jfloat dy, jint color) {
         NPE_CHECK_RETURN_VOID(env, jpaint);
 
         SkPaint* paint = GraphicsJNI::getNativePaint(env, jpaint);
@@ -717,8 +768,8 @@
         return bytes >> 1;
     }
 
-    static int breakTextC(JNIEnv* env, jobject jpaint, jcharArray jtext,
-            int index, int count, float maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) {
+    static jint breakTextC(JNIEnv* env, jobject jpaint, jcharArray jtext,
+            jint index, jint count, jfloat maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) {
         NPE_CHECK_RETURN_ZERO(env, jpaint);
         NPE_CHECK_RETURN_ZERO(env, jtext);
 
@@ -745,8 +796,8 @@
         return count;
     }
 
-    static int breakTextS(JNIEnv* env, jobject jpaint, jstring jtext,
-                bool forwards, float maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) {
+    static jint breakTextS(JNIEnv* env, jobject jpaint, jstring jtext,
+                jboolean forwards, jfloat maxWidth, jint bidiFlags, jfloatArray jmeasuredWidth) {
         NPE_CHECK_RETURN_ZERO(env, jpaint);
         NPE_CHECK_RETURN_ZERO(env, jtext);
 
@@ -777,15 +828,17 @@
         GraphicsJNI::irect_to_jrect(ir, env, bounds);
     }
 
-    static void getStringBounds(JNIEnv* env, jobject, const SkPaint* paint,
-                                jstring text, int start, int end, jint bidiFlags, jobject bounds) {
+    static void getStringBounds(JNIEnv* env, jobject, jlong paintHandle,
+                                jstring text, jint start, jint end, jint bidiFlags, jobject bounds) {
+        const SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);;
         const jchar* textArray = env->GetStringChars(text, NULL);
         doTextBounds(env, textArray + start, end - start, bounds, *paint, bidiFlags);
         env->ReleaseStringChars(text, textArray);
     }
 
-    static void getCharArrayBounds(JNIEnv* env, jobject, const SkPaint* paint,
-                        jcharArray text, int index, int count, jint bidiFlags, jobject bounds) {
+    static void getCharArrayBounds(JNIEnv* env, jobject, jlong paintHandle,
+                        jcharArray text, jint index, jint count, jint bidiFlags, jobject bounds) {
+        const SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
         const jchar* textArray = env->GetCharArrayElements(text, NULL);
         doTextBounds(env, textArray + index, count, bounds, *paint, bidiFlags);
         env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray),
@@ -795,11 +848,11 @@
 };
 
 static JNINativeMethod methods[] = {
-    {"finalizer", "(I)V", (void*) SkPaintGlue::finalizer},
-    {"native_init","()I", (void*) SkPaintGlue::init},
-    {"native_initWithPaint","(I)I", (void*) SkPaintGlue::intiWithPaint},
-    {"native_reset","(I)V", (void*) SkPaintGlue::reset},
-    {"native_set","(II)V", (void*) SkPaintGlue::assign},
+    {"finalizer", "(J)V", (void*) SkPaintGlue::finalizer},
+    {"native_init","()J", (void*) SkPaintGlue::init},
+    {"native_initWithPaint","(J)J", (void*) SkPaintGlue::initWithPaint},
+    {"native_reset","(J)V", (void*) SkPaintGlue::reset},
+    {"native_set","(JJ)V", (void*) SkPaintGlue::assign},
     {"getFlags","()I", (void*) SkPaintGlue::getFlags},
     {"setFlags","(I)V", (void*) SkPaintGlue::setFlags},
     {"getHinting","()I", (void*) SkPaintGlue::getHinting},
@@ -812,8 +865,8 @@
     {"setFakeBoldText","(Z)V", (void*) SkPaintGlue::setFakeBoldText},
     {"setFilterBitmap","(Z)V", (void*) SkPaintGlue::setFilterBitmap},
     {"setDither","(Z)V", (void*) SkPaintGlue::setDither},
-    {"native_getStyle","(I)I", (void*) SkPaintGlue::getStyle},
-    {"native_setStyle","(II)V", (void*) SkPaintGlue::setStyle},
+    {"native_getStyle","(J)I", (void*) SkPaintGlue::getStyle},
+    {"native_setStyle","(JI)V", (void*) SkPaintGlue::setStyle},
     {"getColor","()I", (void*) SkPaintGlue::getColor},
     {"setColor","(I)V", (void*) SkPaintGlue::setColor},
     {"getAlpha","()I", (void*) SkPaintGlue::getAlpha},
@@ -822,21 +875,21 @@
     {"setStrokeWidth","(F)V", (void*) SkPaintGlue::setStrokeWidth},
     {"getStrokeMiter","()F", (void*) SkPaintGlue::getStrokeMiter},
     {"setStrokeMiter","(F)V", (void*) SkPaintGlue::setStrokeMiter},
-    {"native_getStrokeCap","(I)I", (void*) SkPaintGlue::getStrokeCap},
-    {"native_setStrokeCap","(II)V", (void*) SkPaintGlue::setStrokeCap},
-    {"native_getStrokeJoin","(I)I", (void*) SkPaintGlue::getStrokeJoin},
-    {"native_setStrokeJoin","(II)V", (void*) SkPaintGlue::setStrokeJoin},
-    {"native_getFillPath","(III)Z", (void*) SkPaintGlue::getFillPath},
-    {"native_setShader","(II)I", (void*) SkPaintGlue::setShader},
-    {"native_setColorFilter","(II)I", (void*) SkPaintGlue::setColorFilter},
-    {"native_setXfermode","(II)I", (void*) SkPaintGlue::setXfermode},
-    {"native_setPathEffect","(II)I", (void*) SkPaintGlue::setPathEffect},
-    {"native_setMaskFilter","(II)I", (void*) SkPaintGlue::setMaskFilter},
-    {"native_setTypeface","(II)I", (void*) SkPaintGlue::setTypeface},
-    {"native_setRasterizer","(II)I", (void*) SkPaintGlue::setRasterizer},
-    {"native_getTextAlign","(I)I", (void*) SkPaintGlue::getTextAlign},
-    {"native_setTextAlign","(II)V", (void*) SkPaintGlue::setTextAlign},
-    {"native_setTextLocale","(ILjava/lang/String;)V", (void*) SkPaintGlue::setTextLocale},
+    {"native_getStrokeCap","(J)I", (void*) SkPaintGlue::getStrokeCap},
+    {"native_setStrokeCap","(JI)V", (void*) SkPaintGlue::setStrokeCap},
+    {"native_getStrokeJoin","(J)I", (void*) SkPaintGlue::getStrokeJoin},
+    {"native_setStrokeJoin","(JI)V", (void*) SkPaintGlue::setStrokeJoin},
+    {"native_getFillPath","(JJJ)Z", (void*) SkPaintGlue::getFillPath},
+    {"native_setShader","(JJ)J", (void*) SkPaintGlue::setShader},
+    {"native_setColorFilter","(JJ)J", (void*) SkPaintGlue::setColorFilter},
+    {"native_setXfermode","(JJ)J", (void*) SkPaintGlue::setXfermode},
+    {"native_setPathEffect","(JJ)J", (void*) SkPaintGlue::setPathEffect},
+    {"native_setMaskFilter","(JJ)J", (void*) SkPaintGlue::setMaskFilter},
+    {"native_setTypeface","(JJ)J", (void*) SkPaintGlue::setTypeface},
+    {"native_setRasterizer","(JJ)J", (void*) SkPaintGlue::setRasterizer},
+    {"native_getTextAlign","(J)I", (void*) SkPaintGlue::getTextAlign},
+    {"native_setTextAlign","(JI)V", (void*) SkPaintGlue::setTextAlign},
+    {"native_setTextLocale","(JLjava/lang/String;)V", (void*) SkPaintGlue::setTextLocale},
     {"getTextSize","()F", (void*) SkPaintGlue::getTextSize},
     {"setTextSize","(F)V", (void*) SkPaintGlue::setTextSize},
     {"getTextScaleX","()F", (void*) SkPaintGlue::getTextScaleX},
@@ -852,24 +905,24 @@
     {"native_measureText","(Ljava/lang/String;III)F", (void*) SkPaintGlue::measureText_StringIII},
     {"native_breakText","([CIIFI[F)I", (void*) SkPaintGlue::breakTextC},
     {"native_breakText","(Ljava/lang/String;ZFI[F)I", (void*) SkPaintGlue::breakTextS},
-    {"native_getTextWidths","(I[CIII[F)I", (void*) SkPaintGlue::getTextWidths___CIII_F},
-    {"native_getTextWidths","(ILjava/lang/String;III[F)I", (void*) SkPaintGlue::getTextWidths__StringIII_F},
-    {"native_getTextRunAdvances","(I[CIIIII[FI)F",
+    {"native_getTextWidths","(J[CIII[F)I", (void*) SkPaintGlue::getTextWidths___CIII_F},
+    {"native_getTextWidths","(JLjava/lang/String;III[F)I", (void*) SkPaintGlue::getTextWidths__StringIII_F},
+    {"native_getTextRunAdvances","(J[CIIIII[FI)F",
         (void*) SkPaintGlue::getTextRunAdvances___CIIIII_FI},
-    {"native_getTextRunAdvances","(ILjava/lang/String;IIIII[FI)F",
+    {"native_getTextRunAdvances","(JLjava/lang/String;IIIII[FI)F",
         (void*) SkPaintGlue::getTextRunAdvances__StringIIIII_FI},
 
 
-    {"native_getTextGlyphs","(ILjava/lang/String;IIIII[C)I",
+    {"native_getTextGlyphs","(JLjava/lang/String;IIIII[C)I",
         (void*) SkPaintGlue::getTextGlyphs__StringIIIII_C},
-    {"native_getTextRunCursor", "(I[CIIIII)I", (void*) SkPaintGlue::getTextRunCursor___C},
-    {"native_getTextRunCursor", "(ILjava/lang/String;IIIII)I",
+    {"native_getTextRunCursor", "(J[CIIIII)I", (void*) SkPaintGlue::getTextRunCursor___C},
+    {"native_getTextRunCursor", "(JLjava/lang/String;IIIII)I",
         (void*) SkPaintGlue::getTextRunCursor__String},
-    {"native_getTextPath","(II[CIIFFI)V", (void*) SkPaintGlue::getTextPath___C},
-    {"native_getTextPath","(IILjava/lang/String;IIFFI)V", (void*) SkPaintGlue::getTextPath__String},
-    {"nativeGetStringBounds", "(ILjava/lang/String;IIILandroid/graphics/Rect;)V",
+    {"native_getTextPath","(JI[CIIFFJ)V", (void*) SkPaintGlue::getTextPath___C},
+    {"native_getTextPath","(JILjava/lang/String;IIFFJ)V", (void*) SkPaintGlue::getTextPath__String},
+    {"nativeGetStringBounds", "(JLjava/lang/String;IIILandroid/graphics/Rect;)V",
                                         (void*) SkPaintGlue::getStringBounds },
-    {"nativeGetCharArrayBounds", "(I[CIIILandroid/graphics/Rect;)V",
+    {"nativeGetCharArrayBounds", "(J[CIIILandroid/graphics/Rect;)V",
                                     (void*) SkPaintGlue::getCharArrayBounds },
     {"nSetShadowLayer", "(FFFI)V", (void*)SkPaintGlue::setShadowLayer}
 };
diff --git a/core/jni/android/graphics/Path.cpp b/core/jni/android/graphics/Path.cpp
index ab7f1dc..54b6996 100644
--- a/core/jni/android/graphics/Path.cpp
+++ b/core/jni/android/graphics/Path.cpp
@@ -34,7 +34,8 @@
 class SkPathGlue {
 public:
 
-    static void finalizer(JNIEnv* env, jobject clazz, SkPath* obj) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
 #ifdef USE_OPENGL_RENDERER
         if (android::uirenderer::Caches::hasInstance()) {
             android::uirenderer::Caches::getInstance().resourceCache.destructor(obj);
@@ -44,79 +45,96 @@
         delete obj;
     }
 
-    static SkPath* init1(JNIEnv* env, jobject clazz) {
-        return new SkPath();
+    static jlong init1(JNIEnv* env, jobject clazz) {
+        return reinterpret_cast<jlong>(new SkPath());
     }
- 
-    static SkPath* init2(JNIEnv* env, jobject clazz, SkPath* val) {
-        return new SkPath(*val);
+
+    static jlong init2(JNIEnv* env, jobject clazz, jlong valHandle) {
+        SkPath* val = reinterpret_cast<SkPath*>(valHandle);
+        return reinterpret_cast<jlong>(new SkPath(*val));
     }
- 
-    static void reset(JNIEnv* env, jobject clazz, SkPath* obj) {
+
+    static void reset(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         obj->reset();
     }
 
-    static void rewind(JNIEnv* env, jobject clazz, SkPath* obj) {
+    static void rewind(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         obj->rewind();
     }
 
-    static void assign(JNIEnv* env, jobject clazz, SkPath* dst, const SkPath* src) {
+    static void assign(JNIEnv* env, jobject clazz, jlong dstHandle, jlong srcHandle) {
+        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
+        const SkPath* src = reinterpret_cast<SkPath*>(srcHandle);
         *dst = *src;
     }
- 
-    static jint getFillType(JNIEnv* env, jobject clazz, SkPath* obj) {
+
+    static jint getFillType(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         return obj->getFillType();
     }
  
-    static void setFillType(JNIEnv* env, jobject clazz, SkPath* path, SkPath::FillType ft) {
+    static void setFillType(JNIEnv* env, jobject clazz, jlong pathHandle, jint ftHandle) {
+        SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        SkPath::FillType ft = static_cast<SkPath::FillType>(ftHandle);
         path->setFillType(ft);
     }
- 
-    static jboolean isEmpty(JNIEnv* env, jobject clazz, SkPath* obj) {
+
+    static jboolean isEmpty(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         return obj->isEmpty();
     }
  
-    static jboolean isRect(JNIEnv* env, jobject clazz, SkPath* obj, jobject rect) {
+    static jboolean isRect(JNIEnv* env, jobject clazz, jlong objHandle, jobject rect) {
         SkRect rect_;
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         jboolean result = obj->isRect(&rect_);
         GraphicsJNI::rect_to_jrectf(rect_, env, rect);
         return result;
     }
  
-    static void computeBounds(JNIEnv* env, jobject clazz, SkPath* obj, jobject bounds) {
+    static void computeBounds(JNIEnv* env, jobject clazz, jlong objHandle, jobject bounds) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         const SkRect& bounds_ = obj->getBounds();
         GraphicsJNI::rect_to_jrectf(bounds_, env, bounds);
     }
  
-    static void incReserve(JNIEnv* env, jobject clazz, SkPath* obj, jint extraPtCount) {
+    static void incReserve(JNIEnv* env, jobject clazz, jlong objHandle, jint extraPtCount) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         obj->incReserve(extraPtCount);
     }
  
-    static void moveTo__FF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x, jfloat y) {
+    static void moveTo__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat x, jfloat y) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar x_ = SkFloatToScalar(x);
         SkScalar y_ = SkFloatToScalar(y);
         obj->moveTo(x_, y_);
     }
  
-    static void rMoveTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
+    static void rMoveTo(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->rMoveTo(dx_, dy_);
     }
  
-    static void lineTo__FF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x, jfloat y) {
+    static void lineTo__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat x, jfloat y) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar x_ = SkFloatToScalar(x);
         SkScalar y_ = SkFloatToScalar(y);
         obj->lineTo(x_, y_);
     }
  
-    static void rLineTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
+    static void rLineTo(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->rLineTo(dx_, dy_);
     }
  
-    static void quadTo__FFFF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x1, jfloat y1, jfloat x2, jfloat y2) {
+    static void quadTo__FFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat x1, jfloat y1, jfloat x2, jfloat y2) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar x1_ = SkFloatToScalar(x1);
         SkScalar y1_ = SkFloatToScalar(y1);
         SkScalar x2_ = SkFloatToScalar(x2);
@@ -124,7 +142,8 @@
         obj->quadTo(x1_, y1_, x2_, y2_);
     }
  
-    static void rQuadTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) {
+    static void rQuadTo(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar dx1_ = SkFloatToScalar(dx1);
         SkScalar dy1_ = SkFloatToScalar(dy1);
         SkScalar dx2_ = SkFloatToScalar(dx2);
@@ -132,7 +151,8 @@
         obj->rQuadTo(dx1_, dy1_, dx2_, dy2_);
     }
  
-    static void cubicTo__FFFFFF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
+    static void cubicTo__FFFFFF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar x1_ = SkFloatToScalar(x1);
         SkScalar y1_ = SkFloatToScalar(y1);
         SkScalar x2_ = SkFloatToScalar(x2);
@@ -142,7 +162,8 @@
         obj->cubicTo(x1_, y1_, x2_, y2_, x3_, y3_);
     }
  
-    static void rCubicTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
+    static void rCubicTo(JNIEnv* env, jobject clazz, jlong objHandle, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar x1_ = SkFloatToScalar(x1);
         SkScalar y1_ = SkFloatToScalar(y1);
         SkScalar x2_ = SkFloatToScalar(x2);
@@ -152,7 +173,8 @@
         obj->rCubicTo(x1_, y1_, x2_, y2_, x3_, y3_);
     }
  
-    static void arcTo(JNIEnv* env, jobject clazz, SkPath* obj, jobject oval, jfloat startAngle, jfloat sweepAngle, jboolean forceMoveTo) {
+    static void arcTo(JNIEnv* env, jobject clazz, jlong objHandle, jobject oval, jfloat startAngle, jfloat sweepAngle, jboolean forceMoveTo) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkRect oval_;
         GraphicsJNI::jrectf_to_rect(env, oval, &oval_);
         SkScalar startAngle_ = SkFloatToScalar(startAngle);
@@ -160,17 +182,22 @@
         obj->arcTo(oval_, startAngle_, sweepAngle_, forceMoveTo);
     }
  
-    static void close(JNIEnv* env, jobject clazz, SkPath* obj) {
+    static void close(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         obj->close();
     }
  
-    static void addRect__RectFI(JNIEnv* env, jobject clazz, SkPath* obj, jobject rect, SkPath::Direction dir) {
+    static void addRect__RectFI(JNIEnv* env, jobject clazz, jlong objHandle, jobject rect, jint dirHandle) {
         SkRect rect_;
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath::Direction dir = static_cast<SkPath::Direction>(dirHandle);
         GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
         obj->addRect(rect_, dir);
     }
  
-    static void addRect__FFFFI(JNIEnv* env, jobject clazz, SkPath* obj, jfloat left, jfloat top, jfloat right, jfloat bottom, SkPath::Direction dir) {
+    static void addRect__FFFFI(JNIEnv* env, jobject clazz, jlong objHandle, jfloat left, jfloat top, jfloat right, jfloat bottom, jint dirHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath::Direction dir = static_cast<SkPath::Direction>(dirHandle);
         SkScalar left_ = SkFloatToScalar(left);
         SkScalar top_ = SkFloatToScalar(top);
         SkScalar right_ = SkFloatToScalar(right);
@@ -178,39 +205,48 @@
         obj->addRect(left_, top_, right_, bottom_, dir);
     }
  
-    static void addOval(JNIEnv* env, jobject clazz, SkPath* obj, jobject oval, SkPath::Direction dir) {
+    static void addOval(JNIEnv* env, jobject clazz, jlong objHandle, jobject oval, jint dirHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath::Direction dir = static_cast<SkPath::Direction>(dirHandle);
         SkRect oval_;
         GraphicsJNI::jrectf_to_rect(env, oval, &oval_);
         obj->addOval(oval_, dir);
     }
  
-    static void addCircle(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x, jfloat y, jfloat radius, SkPath::Direction dir) {
+    static void addCircle(JNIEnv* env, jobject clazz, jlong objHandle, jfloat x, jfloat y, jfloat radius, jint dirHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath::Direction dir = static_cast<SkPath::Direction>(dirHandle);
         SkScalar x_ = SkFloatToScalar(x);
         SkScalar y_ = SkFloatToScalar(y);
         SkScalar radius_ = SkFloatToScalar(radius);
         obj->addCircle(x_, y_, radius_, dir);
     }
  
-    static void addArc(JNIEnv* env, jobject clazz, SkPath* obj, jobject oval, jfloat startAngle, jfloat sweepAngle) {
+    static void addArc(JNIEnv* env, jobject clazz, jlong objHandle, jobject oval, jfloat startAngle, jfloat sweepAngle) {
         SkRect oval_;
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         GraphicsJNI::jrectf_to_rect(env, oval, &oval_);
         SkScalar startAngle_ = SkFloatToScalar(startAngle);
         SkScalar sweepAngle_ = SkFloatToScalar(sweepAngle);
         obj->addArc(oval_, startAngle_, sweepAngle_);
     }
  
-    static void addRoundRectXY(JNIEnv* env, jobject clazz, SkPath* obj, jobject rect,
-            jfloat rx, jfloat ry, SkPath::Direction dir) {
+    static void addRoundRectXY(JNIEnv* env, jobject clazz, jlong objHandle, jobject rect,
+            jfloat rx, jfloat ry, jint dirHandle) {
         SkRect rect_;
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath::Direction dir = static_cast<SkPath::Direction>(dirHandle);
         GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
         SkScalar rx_ = SkFloatToScalar(rx);
         SkScalar ry_ = SkFloatToScalar(ry);
         obj->addRoundRect(rect_, rx_, ry_, dir);
     }
     
-    static void addRoundRect8(JNIEnv* env, jobject, SkPath* obj, jobject rect,
-            jfloatArray array, SkPath::Direction dir) {
+    static void addRoundRect8(JNIEnv* env, jobject, jlong objHandle, jobject rect,
+            jfloatArray array, jint dirHandle) {
         SkRect rect_;
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath::Direction dir = static_cast<SkPath::Direction>(dirHandle);
         GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
         AutoJavaFloatArray  afa(env, array, 8);
         const float* src = afa.ptr();
@@ -222,90 +258,110 @@
         obj->addRoundRect(rect_, dst, dir);
     }
     
-    static void addPath__PathFF(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src, jfloat dx, jfloat dy) {
+    static void addPath__PathFF(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle, jfloat dx, jfloat dy) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath* src = reinterpret_cast<SkPath*>(srcHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->addPath(*src, dx_, dy_);
     }
  
-    static void addPath__Path(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src) {
+    static void addPath__Path(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath* src = reinterpret_cast<SkPath*>(srcHandle);
         obj->addPath(*src);
     }
  
-    static void addPath__PathMatrix(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src, SkMatrix* matrix) {
+    static void addPath__PathMatrix(JNIEnv* env, jobject clazz, jlong objHandle, jlong srcHandle, jlong matrixHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath* src = reinterpret_cast<SkPath*>(srcHandle);
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         obj->addPath(*src, *matrix);
     }
  
-    static void offset__FFPath(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy, SkPath* dst) {
+    static void offset__FFPath(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy, jlong dstHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->offset(dx_, dy_, dst);
     }
  
-    static void offset__FF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
+    static void offset__FF(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->offset(dx_, dy_);
     }
 
-    static void setLastPoint(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
+    static void setLastPoint(JNIEnv* env, jobject clazz, jlong objHandle, jfloat dx, jfloat dy) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
         SkScalar dx_ = SkFloatToScalar(dx);
         SkScalar dy_ = SkFloatToScalar(dy);
         obj->setLastPt(dx_, dy_);
     }
  
-    static void transform__MatrixPath(JNIEnv* env, jobject clazz, SkPath* obj, SkMatrix* matrix, SkPath* dst) {
+    static void transform__MatrixPath(JNIEnv* env, jobject clazz, jlong objHandle, jlong matrixHandle, jlong dstHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
         obj->transform(*matrix, dst);
     }
  
-    static void transform__Matrix(JNIEnv* env, jobject clazz, SkPath* obj, SkMatrix* matrix) {
+    static void transform__Matrix(JNIEnv* env, jobject clazz, jlong objHandle, jlong matrixHandle) {
+        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
         obj->transform(*matrix);
     }
 
-    static jboolean op(JNIEnv* env, jobject clazz, SkPath* p1, SkPath* p2, SkPathOp op, SkPath* r) {
-         return Op(*p1, *p2, op, r);
+    static jboolean op(JNIEnv* env, jobject clazz, jlong p1Handle, jlong p2Handle, jint opHandle, jlong rHandle) {
+        SkPath* p1  = reinterpret_cast<SkPath*>(p1Handle);
+        SkPath* p2  = reinterpret_cast<SkPath*>(p2Handle);
+        SkPathOp op = static_cast<SkPathOp>(opHandle);
+        SkPath* r   = reinterpret_cast<SkPath*>(rHandle);
+        return Op(*p1, *p2, op, r);
      }
 };
 
 static JNINativeMethod methods[] = {
-    {"finalizer", "(I)V", (void*) SkPathGlue::finalizer},
-    {"init1","()I", (void*) SkPathGlue::init1},
-    {"init2","(I)I", (void*) SkPathGlue::init2},
-    {"native_reset","(I)V", (void*) SkPathGlue::reset},
-    {"native_rewind","(I)V", (void*) SkPathGlue::rewind},
-    {"native_set","(II)V", (void*) SkPathGlue::assign},
-    {"native_getFillType","(I)I", (void*) SkPathGlue::getFillType},
-    {"native_setFillType","(II)V", (void*) SkPathGlue::setFillType},
-    {"native_isEmpty","(I)Z", (void*) SkPathGlue::isEmpty},
-    {"native_isRect","(ILandroid/graphics/RectF;)Z", (void*) SkPathGlue::isRect},
-    {"native_computeBounds","(ILandroid/graphics/RectF;)V", (void*) SkPathGlue::computeBounds},
-    {"native_incReserve","(II)V", (void*) SkPathGlue::incReserve},
-    {"native_moveTo","(IFF)V", (void*) SkPathGlue::moveTo__FF},
-    {"native_rMoveTo","(IFF)V", (void*) SkPathGlue::rMoveTo},
-    {"native_lineTo","(IFF)V", (void*) SkPathGlue::lineTo__FF},
-    {"native_rLineTo","(IFF)V", (void*) SkPathGlue::rLineTo},
-    {"native_quadTo","(IFFFF)V", (void*) SkPathGlue::quadTo__FFFF},
-    {"native_rQuadTo","(IFFFF)V", (void*) SkPathGlue::rQuadTo},
-    {"native_cubicTo","(IFFFFFF)V", (void*) SkPathGlue::cubicTo__FFFFFF},
-    {"native_rCubicTo","(IFFFFFF)V", (void*) SkPathGlue::rCubicTo},
-    {"native_arcTo","(ILandroid/graphics/RectF;FFZ)V", (void*) SkPathGlue::arcTo},
-    {"native_close","(I)V", (void*) SkPathGlue::close},
-    {"native_addRect","(ILandroid/graphics/RectF;I)V", (void*) SkPathGlue::addRect__RectFI},
-    {"native_addRect","(IFFFFI)V", (void*) SkPathGlue::addRect__FFFFI},
-    {"native_addOval","(ILandroid/graphics/RectF;I)V", (void*) SkPathGlue::addOval},
-    {"native_addCircle","(IFFFI)V", (void*) SkPathGlue::addCircle},
-    {"native_addArc","(ILandroid/graphics/RectF;FF)V", (void*) SkPathGlue::addArc},
-    {"native_addRoundRect","(ILandroid/graphics/RectF;FFI)V", (void*) SkPathGlue::addRoundRectXY},
-    {"native_addRoundRect","(ILandroid/graphics/RectF;[FI)V", (void*) SkPathGlue::addRoundRect8},
-    {"native_addPath","(IIFF)V", (void*) SkPathGlue::addPath__PathFF},
-    {"native_addPath","(II)V", (void*) SkPathGlue::addPath__Path},
-    {"native_addPath","(III)V", (void*) SkPathGlue::addPath__PathMatrix},
-    {"native_offset","(IFFI)V", (void*) SkPathGlue::offset__FFPath},
-    {"native_offset","(IFF)V", (void*) SkPathGlue::offset__FF},
-    {"native_setLastPoint","(IFF)V", (void*) SkPathGlue::setLastPoint},
-    {"native_transform","(III)V", (void*) SkPathGlue::transform__MatrixPath},
-    {"native_transform","(II)V", (void*) SkPathGlue::transform__Matrix},
-    {"native_op","(IIII)Z", (void*) SkPathGlue::op}
+    {"finalizer", "(J)V", (void*) SkPathGlue::finalizer},
+    {"init1","()J", (void*) SkPathGlue::init1},
+    {"init2","(J)J", (void*) SkPathGlue::init2},
+    {"native_reset","(J)V", (void*) SkPathGlue::reset},
+    {"native_rewind","(J)V", (void*) SkPathGlue::rewind},
+    {"native_set","(JJ)V", (void*) SkPathGlue::assign},
+    {"native_getFillType","(J)I", (void*) SkPathGlue::getFillType},
+    {"native_setFillType","(JI)V", (void*) SkPathGlue::setFillType},
+    {"native_isEmpty","(J)Z", (void*) SkPathGlue::isEmpty},
+    {"native_isRect","(JLandroid/graphics/RectF;)Z", (void*) SkPathGlue::isRect},
+    {"native_computeBounds","(JLandroid/graphics/RectF;)V", (void*) SkPathGlue::computeBounds},
+    {"native_incReserve","(JI)V", (void*) SkPathGlue::incReserve},
+    {"native_moveTo","(JFF)V", (void*) SkPathGlue::moveTo__FF},
+    {"native_rMoveTo","(JFF)V", (void*) SkPathGlue::rMoveTo},
+    {"native_lineTo","(JFF)V", (void*) SkPathGlue::lineTo__FF},
+    {"native_rLineTo","(JFF)V", (void*) SkPathGlue::rLineTo},
+    {"native_quadTo","(JFFFF)V", (void*) SkPathGlue::quadTo__FFFF},
+    {"native_rQuadTo","(JFFFF)V", (void*) SkPathGlue::rQuadTo},
+    {"native_cubicTo","(JFFFFFF)V", (void*) SkPathGlue::cubicTo__FFFFFF},
+    {"native_rCubicTo","(JFFFFFF)V", (void*) SkPathGlue::rCubicTo},
+    {"native_arcTo","(JLandroid/graphics/RectF;FFZ)V", (void*) SkPathGlue::arcTo},
+    {"native_close","(J)V", (void*) SkPathGlue::close},
+    {"native_addRect","(JLandroid/graphics/RectF;I)V", (void*) SkPathGlue::addRect__RectFI},
+    {"native_addRect","(JFFFFI)V", (void*) SkPathGlue::addRect__FFFFI},
+    {"native_addOval","(JLandroid/graphics/RectF;I)V", (void*) SkPathGlue::addOval},
+    {"native_addCircle","(JFFFI)V", (void*) SkPathGlue::addCircle},
+    {"native_addArc","(JLandroid/graphics/RectF;FF)V", (void*) SkPathGlue::addArc},
+    {"native_addRoundRect","(JLandroid/graphics/RectF;FFI)V", (void*) SkPathGlue::addRoundRectXY},
+    {"native_addRoundRect","(JLandroid/graphics/RectF;[FI)V", (void*) SkPathGlue::addRoundRect8},
+    {"native_addPath","(JJFF)V", (void*) SkPathGlue::addPath__PathFF},
+    {"native_addPath","(JJ)V", (void*) SkPathGlue::addPath__Path},
+    {"native_addPath","(JJJ)V", (void*) SkPathGlue::addPath__PathMatrix},
+    {"native_offset","(JFFJ)V", (void*) SkPathGlue::offset__FFPath},
+    {"native_offset","(JFF)V", (void*) SkPathGlue::offset__FF},
+    {"native_setLastPoint","(JFF)V", (void*) SkPathGlue::setLastPoint},
+    {"native_transform","(JJJ)V", (void*) SkPathGlue::transform__MatrixPath},
+    {"native_transform","(JJ)V", (void*) SkPathGlue::transform__Matrix},
+    {"native_op","(JJIJ)Z", (void*) SkPathGlue::op}
 };
 
 int register_android_graphics_Path(JNIEnv* env) {
diff --git a/core/jni/android/graphics/PathEffect.cpp b/core/jni/android/graphics/PathEffect.cpp
index 0503614..2803758 100644
--- a/core/jni/android/graphics/PathEffect.cpp
+++ b/core/jni/android/graphics/PathEffect.cpp
@@ -11,22 +11,29 @@
 class SkPathEffectGlue {
 public:
 
-    static void destructor(JNIEnv* env, jobject, SkPathEffect* effect) {
+    static void destructor(JNIEnv* env, jobject, jlong effectHandle) {
+        SkPathEffect* effect = reinterpret_cast<SkPathEffect*>(effectHandle);
         SkSafeUnref(effect);
     }
 
-    static SkPathEffect* Compose_constructor(JNIEnv* env, jobject,
-                                   SkPathEffect* outer, SkPathEffect* inner) {
-        return new SkComposePathEffect(outer, inner);
+    static jlong Compose_constructor(JNIEnv* env, jobject,
+                                     jlong outerHandle, jlong innerHandle) {
+        SkPathEffect* outer = reinterpret_cast<SkPathEffect*>(outerHandle);
+        SkPathEffect* inner = reinterpret_cast<SkPathEffect*>(innerHandle);
+        SkPathEffect* effect = new SkComposePathEffect(outer, inner);
+        return reinterpret_cast<jlong>(effect);
     }
 
-    static SkPathEffect* Sum_constructor(JNIEnv* env, jobject,
-                                  SkPathEffect* first, SkPathEffect* second) {
-        return new SkSumPathEffect(first, second);
+    static jlong Sum_constructor(JNIEnv* env, jobject,
+                                 jlong firstHandle, jlong secondHandle) {
+        SkPathEffect* first = reinterpret_cast<SkPathEffect*>(firstHandle);
+        SkPathEffect* second = reinterpret_cast<SkPathEffect*>(secondHandle);
+        SkPathEffect* effect = new SkSumPathEffect(first, second);
+        return reinterpret_cast<jlong>(effect);
     }
 
-    static SkPathEffect* Dash_constructor(JNIEnv* env, jobject,
-                                      jfloatArray intervalArray, float phase) {
+    static jlong Dash_constructor(JNIEnv* env, jobject,
+                                      jfloatArray intervalArray, jfloat phase) {
         AutoJavaFloatArray autoInterval(env, intervalArray);
         int     count = autoInterval.length() & ~1;  // even number
         float*  values = autoInterval.ptr();
@@ -36,24 +43,29 @@
         for (int i = 0; i < count; i++) {
             intervals[i] = SkFloatToScalar(values[i]);
         }
-        return new SkDashPathEffect(intervals, count, SkFloatToScalar(phase));
+        SkPathEffect* effect = new SkDashPathEffect(intervals, count, SkFloatToScalar(phase));
+        return reinterpret_cast<jlong>(effect);
     }
 
-    static SkPathEffect* OneD_constructor(JNIEnv* env, jobject,
-                  const SkPath* shape, float advance, float phase, int style) {
+    static jlong OneD_constructor(JNIEnv* env, jobject,
+                  jlong shapeHandle, jfloat advance, jfloat phase, jint style) {
+        const SkPath* shape = reinterpret_cast<SkPath*>(shapeHandle);
         SkASSERT(shape != NULL);
-        return new SkPath1DPathEffect(*shape, SkFloatToScalar(advance),
+        SkPathEffect* effect = new SkPath1DPathEffect(*shape, SkFloatToScalar(advance),
                      SkFloatToScalar(phase), (SkPath1DPathEffect::Style)style);
+        return reinterpret_cast<jlong>(effect);
     }
 
-    static SkPathEffect* Corner_constructor(JNIEnv* env, jobject, float radius){
-        return new SkCornerPathEffect(SkFloatToScalar(radius));
+    static jlong Corner_constructor(JNIEnv* env, jobject, jfloat radius){
+        SkPathEffect* effect = new SkCornerPathEffect(SkFloatToScalar(radius));
+        return reinterpret_cast<jlong>(effect);
     }
 
-    static SkPathEffect* Discrete_constructor(JNIEnv* env, jobject,
-                                              float length, float deviation) {
-        return new SkDiscretePathEffect(SkFloatToScalar(length),
+    static jlong Discrete_constructor(JNIEnv* env, jobject,
+                                      jfloat length, jfloat deviation) {
+        SkPathEffect* effect = new SkDiscretePathEffect(SkFloatToScalar(length),
                                         SkFloatToScalar(deviation));
+        return reinterpret_cast<jlong>(effect);
     }
 
 };
@@ -61,31 +73,31 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 static JNINativeMethod gPathEffectMethods[] = {
-    { "nativeDestructor", "(I)V", (void*)SkPathEffectGlue::destructor }
+    { "nativeDestructor", "(J)V", (void*)SkPathEffectGlue::destructor }
 };
 
 static JNINativeMethod gComposePathEffectMethods[] = {
-    { "nativeCreate", "(II)I", (void*)SkPathEffectGlue::Compose_constructor }
+    { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Compose_constructor }
 };
 
 static JNINativeMethod gSumPathEffectMethods[] = {
-    { "nativeCreate", "(II)I", (void*)SkPathEffectGlue::Sum_constructor }
+    { "nativeCreate", "(JJ)J", (void*)SkPathEffectGlue::Sum_constructor }
 };
 
 static JNINativeMethod gDashPathEffectMethods[] = {
-    { "nativeCreate", "([FF)I", (void*)SkPathEffectGlue::Dash_constructor }
+    { "nativeCreate", "([FF)J", (void*)SkPathEffectGlue::Dash_constructor }
 };
 
 static JNINativeMethod gPathDashPathEffectMethods[] = {
-    { "nativeCreate", "(IFFI)I", (void*)SkPathEffectGlue::OneD_constructor }
+    { "nativeCreate", "(JFFI)J", (void*)SkPathEffectGlue::OneD_constructor }
 };
 
 static JNINativeMethod gCornerPathEffectMethods[] = {
-    { "nativeCreate", "(F)I", (void*)SkPathEffectGlue::Corner_constructor }
+    { "nativeCreate", "(F)J", (void*)SkPathEffectGlue::Corner_constructor }
 };
 
 static JNINativeMethod gDiscretePathEffectMethods[] = {
-    { "nativeCreate", "(FF)I", (void*)SkPathEffectGlue::Discrete_constructor }
+    { "nativeCreate", "(FF)J", (void*)SkPathEffectGlue::Discrete_constructor }
 };
 
 #include <android_runtime/AndroidRuntime.h>
diff --git a/core/jni/android/graphics/PathMeasure.cpp b/core/jni/android/graphics/PathMeasure.cpp
index 51a3f3a..8478a02 100644
--- a/core/jni/android/graphics/PathMeasure.cpp
+++ b/core/jni/android/graphics/PathMeasure.cpp
@@ -52,11 +52,24 @@
 class SkPathMeasureGlue {
 public:
 
-    static PathMeasurePair* create(JNIEnv* env, jobject clazz, const SkPath* path, jboolean forceClosed) {
-        return path ? new PathMeasurePair(*path, forceClosed) : new PathMeasurePair;
+    static jlong create(JNIEnv* env, jobject clazz, jlong pathHandle,
+                        jboolean forceClosedHandle) {
+        const SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        bool forceClosed = (forceClosedHandle == JNI_TRUE);
+        PathMeasurePair* pair;
+        if(path)
+            pair = new PathMeasurePair(*path, forceClosed);
+        else
+            pair = new PathMeasurePair;
+        return reinterpret_cast<jlong>(pair);
     }
- 
-    static void setPath(JNIEnv* env, jobject clazz, PathMeasurePair* pair, const SkPath* path, jboolean forceClosed) {
+
+    static void setPath(JNIEnv* env, jobject clazz, jlong pairHandle,
+                        jlong pathHandle, jboolean forceClosedHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        const SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        bool forceClosed = (forceClosedHandle == JNI_TRUE);
+
         if (NULL == path) {
             pair->fPath.reset();
         } else {
@@ -64,11 +77,12 @@
         }
         pair->fMeasure.setPath(&pair->fPath, forceClosed);
     }
- 
-    static jfloat getLength(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
-        return SkScalarToFloat(pair->fMeasure.getLength());
+
+    static jfloat getLength(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        return static_cast<jfloat>(SkScalarToFloat(pair->fMeasure.getLength()));
     }
- 
+
     static void convertTwoElemFloatArray(JNIEnv* env, jfloatArray array, const SkScalar src[2]) {
         AutoJavaFloatArray autoArray(env, array, 2);
         jfloat* ptr = autoArray.ptr();
@@ -76,13 +90,14 @@
         ptr[1] = SkScalarToFloat(src[1]);
     }
 
-    static jboolean getPosTan(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat dist, jfloatArray pos, jfloatArray tan) {
+    static jboolean getPosTan(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat dist, jfloatArray pos, jfloatArray tan) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
         SkScalar    tmpPos[2], tmpTan[2];
         SkScalar*   posPtr = pos ? tmpPos : NULL;
         SkScalar*   tanPtr = tan ? tmpTan : NULL;
         
         if (!pair->fMeasure.getPosTan(SkFloatToScalar(dist), (SkPoint*)posPtr, (SkVector*)tanPtr)) {
-            return false;
+            return JNI_FALSE;
         }
     
         if (pos) {
@@ -91,42 +106,53 @@
         if (tan) {
             convertTwoElemFloatArray(env, tan, tmpTan);
         }
-        return true;
+        return JNI_TRUE;
     }
- 
-    static jboolean getMatrix(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat dist,
-                          SkMatrix* matrix, int flags) {
-        return pair->fMeasure.getMatrix(SkFloatToScalar(dist), matrix, (SkPathMeasure::MatrixFlags)flags);
+
+    static jboolean getMatrix(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat dist,
+                          jlong matrixHandle, jint flags) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        bool result = pair->fMeasure.getMatrix(SkFloatToScalar(dist), matrix, (SkPathMeasure::MatrixFlags)flags);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean getSegment(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat startF,
-                               jfloat stopF, SkPath* dst, jboolean startWithMoveTo) {
-        return pair->fMeasure.getSegment(SkFloatToScalar(startF), SkFloatToScalar(stopF), dst, startWithMoveTo);
+
+    static jboolean getSegment(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat startF,
+                               jfloat stopF, jlong dstHandle, jboolean startWithMoveTo) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
+        bool result = pair->fMeasure.getSegment(SkFloatToScalar(startF), SkFloatToScalar(stopF), dst, startWithMoveTo);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean isClosed(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
-        return pair->fMeasure.isClosed();
+
+    static jboolean isClosed(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        bool result = pair->fMeasure.isClosed();
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean nextContour(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
-        return pair->fMeasure.nextContour();
+
+    static jboolean nextContour(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        bool result = pair->fMeasure.nextContour();
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static void destroy(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
+
+    static void destroy(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
         delete pair;
     } 
 };
 
 static JNINativeMethod methods[] = {
-    {"native_create",       "(IZ)I",        (void*) SkPathMeasureGlue::create      },
-    {"native_setPath",      "(IIZ)V",       (void*) SkPathMeasureGlue::setPath     },
-    {"native_getLength",    "(I)F",         (void*) SkPathMeasureGlue::getLength   },
-    {"native_getPosTan",    "(IF[F[F)Z",    (void*) SkPathMeasureGlue::getPosTan   },
-    {"native_getMatrix",    "(IFII)Z",      (void*) SkPathMeasureGlue::getMatrix   },
-    {"native_getSegment",   "(IFFIZ)Z",     (void*) SkPathMeasureGlue::getSegment  },
-    {"native_isClosed",     "(I)Z",         (void*) SkPathMeasureGlue::isClosed    },
-    {"native_nextContour",  "(I)Z",         (void*) SkPathMeasureGlue::nextContour },
-    {"native_destroy",      "(I)V",         (void*) SkPathMeasureGlue::destroy     }
+    {"native_create",       "(JZ)J",        (void*) SkPathMeasureGlue::create      },
+    {"native_setPath",      "(JJZ)V",       (void*) SkPathMeasureGlue::setPath     },
+    {"native_getLength",    "(J)F",         (void*) SkPathMeasureGlue::getLength   },
+    {"native_getPosTan",    "(JF[F[F)Z",    (void*) SkPathMeasureGlue::getPosTan   },
+    {"native_getMatrix",    "(JFJI)Z",      (void*) SkPathMeasureGlue::getMatrix   },
+    {"native_getSegment",   "(JFFJZ)Z",     (void*) SkPathMeasureGlue::getSegment  },
+    {"native_isClosed",     "(J)Z",         (void*) SkPathMeasureGlue::isClosed    },
+    {"native_nextContour",  "(J)Z",         (void*) SkPathMeasureGlue::nextContour },
+    {"native_destroy",      "(J)V",         (void*) SkPathMeasureGlue::destroy     }
 };
 
 int register_android_graphics_PathMeasure(JNIEnv* env) {
diff --git a/core/jni/android/graphics/Picture.cpp b/core/jni/android/graphics/Picture.cpp
index fcf22b8..bac8ef7 100644
--- a/core/jni/android/graphics/Picture.cpp
+++ b/core/jni/android/graphics/Picture.cpp
@@ -28,71 +28,80 @@
 
 class SkPictureGlue {
 public:
-    static SkPicture* newPicture(JNIEnv* env, jobject, const SkPicture* src) {
+    static jlong newPicture(JNIEnv* env, jobject, jlong srcHandle) {
+        const SkPicture* src = reinterpret_cast<SkPicture*>(srcHandle);
         if (src) {
-            return new SkPicture(*src);
+            return reinterpret_cast<jlong>(new SkPicture(*src));
         } else {
-            return new SkPicture;
+            return reinterpret_cast<jlong>(new SkPicture);
         }
     }
-    
-    static SkPicture* deserialize(JNIEnv* env, jobject, jobject jstream,
-                                  jbyteArray jstorage) {
+
+    static jlong deserialize(JNIEnv* env, jobject, jobject jstream,
+                             jbyteArray jstorage) {
         SkPicture* picture = NULL;
         SkStream* strm = CreateJavaInputStreamAdaptor(env, jstream, jstorage);
         if (strm) {
             picture = SkPicture::CreateFromStream(strm);
             delete strm;
         }
-        return picture;
+        return reinterpret_cast<jlong>(picture);
     }
-    
-    static void killPicture(JNIEnv* env, jobject, SkPicture* picture) {
+
+    static void killPicture(JNIEnv* env, jobject, jlong pictureHandle) {
+        SkPicture* picture = reinterpret_cast<SkPicture*>(pictureHandle);
         SkASSERT(picture);
         picture->unref();
     }
-    
-    static void draw(JNIEnv* env, jobject, SkCanvas* canvas,
-                            SkPicture* picture) {
+
+    static void draw(JNIEnv* env, jobject, jlong canvasHandle,
+                            jlong pictureHandle) {
+        SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
+        SkPicture* picture = reinterpret_cast<SkPicture*>(pictureHandle);
         SkASSERT(canvas);
         SkASSERT(picture);
         picture->draw(canvas);
     }
-    
-    static bool serialize(JNIEnv* env, jobject, SkPicture* picture,
+
+    static jboolean serialize(JNIEnv* env, jobject, jlong pictureHandle,
                           jobject jstream, jbyteArray jstorage) {
+        SkPicture* picture = reinterpret_cast<SkPicture*>(pictureHandle);
         SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
         
         if (NULL != strm) {
             picture->serialize(strm);
             delete strm;
-            return true;
+            return JNI_TRUE;
         }
-        return false;
+        return JNI_FALSE;
     }
-        
-    static int getWidth(JNIEnv* env, jobject jpic) {
+
+    static jint getWidth(JNIEnv* env, jobject jpic) {
         NPE_CHECK_RETURN_ZERO(env, jpic);
-        return GraphicsJNI::getNativePicture(env, jpic)->width();
+        int width = GraphicsJNI::getNativePicture(env, jpic)->width();
+        return static_cast<jint>(width);
     }
-    
-    static int getHeight(JNIEnv* env, jobject jpic) {
+
+    static jint getHeight(JNIEnv* env, jobject jpic) {
         NPE_CHECK_RETURN_ZERO(env, jpic);
-        return GraphicsJNI::getNativePicture(env, jpic)->height();
+        int height = GraphicsJNI::getNativePicture(env, jpic)->height();
+        return static_cast<jint>(height);
     }
-    
-    static SkCanvas* beginRecording(JNIEnv* env, jobject, SkPicture* pict,
-                                    int w, int h) {
+
+    static jlong beginRecording(JNIEnv* env, jobject, jlong pictHandle,
+                                    jint w, jint h) {
+        SkPicture* pict = reinterpret_cast<SkPicture*>(pictHandle);
         // beginRecording does not ref its return value, it just returns it.
         SkCanvas* canvas = pict->beginRecording(w, h);
         // the java side will wrap this guy in a Canvas.java, which will call
         // unref in its finalizer, so we have to ref it here, so that both that
         // Canvas.java and our picture can both be owners
         canvas->ref();
-        return canvas;
+        return reinterpret_cast<jlong>(canvas);
     }
-    
-    static void endRecording(JNIEnv* env, jobject, SkPicture* pict) {
+
+    static void endRecording(JNIEnv* env, jobject, jlong pictHandle) {
+        SkPicture* pict = reinterpret_cast<SkPicture*>(pictHandle);
         pict->endRecording();
     }
 };
@@ -100,30 +109,30 @@
 static JNINativeMethod gPictureMethods[] = {
     {"getWidth", "()I", (void*) SkPictureGlue::getWidth},
     {"getHeight", "()I", (void*) SkPictureGlue::getHeight},
-    {"nativeConstructor", "(I)I", (void*) SkPictureGlue::newPicture},
-    {"nativeCreateFromStream", "(Ljava/io/InputStream;[B)I", (void*)SkPictureGlue::deserialize},
-    {"nativeBeginRecording", "(III)I", (void*) SkPictureGlue::beginRecording},
-    {"nativeEndRecording", "(I)V", (void*) SkPictureGlue::endRecording},
-    {"nativeDraw", "(II)V", (void*) SkPictureGlue::draw},
-    {"nativeWriteToStream", "(ILjava/io/OutputStream;[B)Z", (void*)SkPictureGlue::serialize},
-    {"nativeDestructor","(I)V", (void*) SkPictureGlue::killPicture}
+    {"nativeConstructor", "(J)J", (void*) SkPictureGlue::newPicture},
+    {"nativeCreateFromStream", "(Ljava/io/InputStream;[B)J", (void*)SkPictureGlue::deserialize},
+    {"nativeBeginRecording", "(JII)J", (void*) SkPictureGlue::beginRecording},
+    {"nativeEndRecording", "(J)V", (void*) SkPictureGlue::endRecording},
+    {"nativeDraw", "(JJ)V", (void*) SkPictureGlue::draw},
+    {"nativeWriteToStream", "(JLjava/io/OutputStream;[B)Z", (void*)SkPictureGlue::serialize},
+    {"nativeDestructor","(J)V", (void*) SkPictureGlue::killPicture}
 };
 
 #include <android_runtime/AndroidRuntime.h>
-    
+
 #define REG(env, name, array) \
     result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
     SK_ARRAY_COUNT(array));  \
     if (result < 0) return result
-    
+
 int register_android_graphics_Picture(JNIEnv* env) {
     int result;
-    
+
     REG(env, "android/graphics/Picture", gPictureMethods);
-    
+
     return result;
 }
-    
+
 }
 
 
diff --git a/core/jni/android/graphics/PorterDuff.cpp b/core/jni/android/graphics/PorterDuff.cpp
index 47de601..8a49eb5 100644
--- a/core/jni/android/graphics/PorterDuff.cpp
+++ b/core/jni/android/graphics/PorterDuff.cpp
@@ -31,15 +31,15 @@
 class SkPorterDuffGlue {
 public:
 
-    static SkXfermode* CreateXfermode(JNIEnv* env, jobject,
-                                      SkPorterDuff::Mode mode) {
-        return SkPorterDuff::CreateXfermode(mode);
+    static jlong CreateXfermode(JNIEnv* env, jobject, jint modeHandle) {
+        SkPorterDuff::Mode mode = static_cast<SkPorterDuff::Mode>(modeHandle);
+        return reinterpret_cast<jlong>(SkPorterDuff::CreateXfermode(mode));
     }
  
 };
 
 static JNINativeMethod methods[] = {
-    {"nativeCreateXfermode","(I)I", (void*) SkPorterDuffGlue::CreateXfermode},
+    {"nativeCreateXfermode","(I)J", (void*) SkPorterDuffGlue::CreateXfermode},
 };
 
 int register_android_graphics_PorterDuff(JNIEnv* env) {
diff --git a/core/jni/android/graphics/Rasterizer.cpp b/core/jni/android/graphics/Rasterizer.cpp
index 4e1b36a..b6450d0 100644
--- a/core/jni/android/graphics/Rasterizer.cpp
+++ b/core/jni/android/graphics/Rasterizer.cpp
@@ -31,14 +31,15 @@
 class SkRasterizerGlue {
 public:
 
-    static void finalizer(JNIEnv* env, jobject clazz, SkRasterizer* obj) {
+    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
+        SkRasterizer* obj = reinterpret_cast<SkRasterizer *>(objHandle);
         SkSafeUnref(obj);
     }
  
 };
 
 static JNINativeMethod methods[] = {
-    {"finalizer", "(I)V", (void*) SkRasterizerGlue::finalizer}
+    {"finalizer", "(J)V", (void*) SkRasterizerGlue::finalizer}
 };
 
 int register_android_graphics_Rasterizer(JNIEnv* env) {
diff --git a/core/jni/android/graphics/Region.cpp b/core/jni/android/graphics/Region.cpp
index f0a7baf..bcf1273 100644
--- a/core/jni/android/graphics/Region.cpp
+++ b/core/jni/android/graphics/Region.cpp
@@ -29,95 +29,131 @@
 
 static jfieldID gRegion_nativeInstanceFieldID;
 
+static inline jboolean boolTojboolean(bool value) {
+    return value ? JNI_TRUE : JNI_FALSE;
+}
+
 static inline SkRegion* GetSkRegion(JNIEnv* env, jobject regionObject) {
-    SkRegion* rgn = (SkRegion*)env->GetIntField(regionObject, gRegion_nativeInstanceFieldID);
-    SkASSERT(rgn != NULL);
-    return rgn;
+    jlong regionHandle = env->GetLongField(regionObject, gRegion_nativeInstanceFieldID);
+    SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
+    SkASSERT(region != NULL);
+    return region;
 }
 
-static SkRegion* Region_constructor(JNIEnv* env, jobject) {
-    return new SkRegion;
+static jlong Region_constructor(JNIEnv* env, jobject) {
+    return reinterpret_cast<jlong>(new SkRegion);
 }
 
-static void Region_destructor(JNIEnv* env, jobject, SkRegion* region) {
+static void Region_destructor(JNIEnv* env, jobject, jlong regionHandle) {
+    SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
     SkASSERT(region);
     delete region;
 }
 
-static void Region_setRegion(JNIEnv* env, jobject, SkRegion* dst, const SkRegion* src) {
+static void Region_setRegion(JNIEnv* env, jobject, jlong dstHandle, jlong srcHandle) {
+    SkRegion* dst = reinterpret_cast<SkRegion*>(dstHandle);
+    const SkRegion* src = reinterpret_cast<SkRegion*>(srcHandle);
     SkASSERT(dst && src);
     *dst = *src;
 }
 
-static jboolean Region_setRect(JNIEnv* env, jobject, SkRegion* dst, int left, int top, int right, int bottom) {
-    return dst->setRect(left, top, right, bottom);
+static jboolean Region_setRect(JNIEnv* env, jobject, jlong dstHandle, jint left, jint top, jint right, jint bottom) {
+    SkRegion* dst = reinterpret_cast<SkRegion*>(dstHandle);
+    bool result = dst->setRect(left, top, right, bottom);
+    return boolTojboolean(result);
 }
 
-static jboolean Region_setPath(JNIEnv* env, jobject, SkRegion* dst,
-                               const SkPath* path, const SkRegion* clip) {
+static jboolean Region_setPath(JNIEnv* env, jobject, jlong dstHandle,
+                               jlong pathHandle, jlong clipHandle) {
+    SkRegion*       dst  = reinterpret_cast<SkRegion*>(dstHandle);
+    const SkPath*   path = reinterpret_cast<SkPath*>(pathHandle);
+    const SkRegion* clip = reinterpret_cast<SkRegion*>(clipHandle);
     SkASSERT(dst && path && clip);
-    return dst->setPath(*path, *clip);
+    bool result = dst->setPath(*path, *clip);
+    return boolTojboolean(result);
+
 }
 
-static jboolean Region_getBounds(JNIEnv* env, jobject, SkRegion* region, jobject rectBounds) {
+static jboolean Region_getBounds(JNIEnv* env, jobject, jlong regionHandle, jobject rectBounds) {
+    SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
     GraphicsJNI::irect_to_jrect(region->getBounds(), env, rectBounds);
-    return !region->isEmpty();
+    bool result = !region->isEmpty();
+    return boolTojboolean(result);
 }
 
-static jboolean Region_getBoundaryPath(JNIEnv* env, jobject, const SkRegion* region, SkPath* path) {
-    return region->getBoundaryPath(path);
+static jboolean Region_getBoundaryPath(JNIEnv* env, jobject, jlong regionHandle, jlong pathHandle) {
+    const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
+    SkPath*   path = reinterpret_cast<SkPath*>(pathHandle);
+    bool result = region->getBoundaryPath(path);
+    return boolTojboolean(result);
 }
 
-static jboolean Region_op0(JNIEnv* env, jobject, SkRegion* dst, int left, int top, int right, int bottom, int op) {
+static jboolean Region_op0(JNIEnv* env, jobject, jlong dstHandle, jint left, jint top, jint right, jint bottom, jint op) {
+    SkRegion* dst = reinterpret_cast<SkRegion*>(dstHandle);
     SkIRect ir;
 
     ir.set(left, top, right, bottom);
-    return dst->op(ir, (SkRegion::Op)op);
+    bool result = dst->op(ir, (SkRegion::Op)op);
+    return boolTojboolean(result);
 }
 
-static jboolean Region_op1(JNIEnv* env, jobject, SkRegion* dst, jobject rectObject, const SkRegion* region, int op) {
+static jboolean Region_op1(JNIEnv* env, jobject, jlong dstHandle, jobject rectObject, jlong regionHandle, jint op) {
+    SkRegion* dst = reinterpret_cast<SkRegion*>(dstHandle);
+    const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
     SkIRect    ir;
     GraphicsJNI::jrect_to_irect(env, rectObject, &ir);
-    return dst->op(ir, *region, (SkRegion::Op)op);
+    bool result = dst->op(ir, *region, (SkRegion::Op)op);
+    return boolTojboolean(result);
 }
 
-static jboolean Region_op2(JNIEnv* env, jobject, SkRegion* dst, const SkRegion* region1, const SkRegion* region2, int op) {
-    return dst->op(*region1, *region2, (SkRegion::Op)op);
+static jboolean Region_op2(JNIEnv* env, jobject, jlong dstHandle, jlong region1Handle, jlong region2Handle, jint op) {
+    SkRegion* dst = reinterpret_cast<SkRegion*>(dstHandle);
+    const SkRegion* region1 = reinterpret_cast<SkRegion*>(region1Handle);
+    const SkRegion* region2 = reinterpret_cast<SkRegion*>(region2Handle);
+    bool result = dst->op(*region1, *region2, (SkRegion::Op)op);
+    return boolTojboolean(result);
 }
 
 ////////////////////////////////////  These are methods, not static
 
 static jboolean Region_isEmpty(JNIEnv* env, jobject region) {
-    return GetSkRegion(env, region)->isEmpty();
+    bool result = GetSkRegion(env, region)->isEmpty();
+    return boolTojboolean(result);
 }
 
 static jboolean Region_isRect(JNIEnv* env, jobject region) {
-    return GetSkRegion(env, region)->isRect();
+    bool result = GetSkRegion(env, region)->isRect();
+    return boolTojboolean(result);
 }
 
 static jboolean Region_isComplex(JNIEnv* env, jobject region) {
-    return GetSkRegion(env, region)->isComplex();
+    bool result = GetSkRegion(env, region)->isComplex();
+    return boolTojboolean(result);
 }
 
-static jboolean Region_contains(JNIEnv* env, jobject region, int x, int y) {
-    return GetSkRegion(env, region)->contains(x, y);
+static jboolean Region_contains(JNIEnv* env, jobject region, jint x, jint y) {
+    bool result = GetSkRegion(env, region)->contains(x, y);
+    return boolTojboolean(result);
 }
 
-static jboolean Region_quickContains(JNIEnv* env, jobject region, int left, int top, int right, int bottom) {
-    return GetSkRegion(env, region)->quickContains(left, top, right, bottom);
+static jboolean Region_quickContains(JNIEnv* env, jobject region, jint left, jint top, jint right, jint bottom) {
+    bool result = GetSkRegion(env, region)->quickContains(left, top, right, bottom);
+    return boolTojboolean(result);
 }
 
-static jboolean Region_quickRejectIIII(JNIEnv* env, jobject region, int left, int top, int right, int bottom) {
+static jboolean Region_quickRejectIIII(JNIEnv* env, jobject region, jint left, jint top, jint right, jint bottom) {
     SkIRect ir;
     ir.set(left, top, right, bottom);
-    return GetSkRegion(env, region)->quickReject(ir);
+    bool result = GetSkRegion(env, region)->quickReject(ir);
+    return boolTojboolean(result);
 }
 
 static jboolean Region_quickRejectRgn(JNIEnv* env, jobject region, jobject other) {
-    return GetSkRegion(env, region)->quickReject(*GetSkRegion(env, other));
+    bool result = GetSkRegion(env, region)->quickReject(*GetSkRegion(env, other));
+    return boolTojboolean(result);
 }
 
-static void Region_translate(JNIEnv* env, jobject region, int x, int y, jobject dst) {
+static void Region_translate(JNIEnv* env, jobject region, jint x, jint y, jobject dst) {
     SkRegion* rgn = GetSkRegion(env, region);
     if (dst)
         rgn->translate(x, y, GetSkRegion(env, dst));
@@ -155,7 +191,8 @@
         scale_rgn(rgn, *rgn, scale);
 }
 
-static jstring Region_toString(JNIEnv* env, jobject clazz, SkRegion* region) {
+static jstring Region_toString(JNIEnv* env, jobject clazz, jlong regionHandle) {
+    SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
     char* str = region->toString();
     if (str == NULL) {
         return NULL;
@@ -167,7 +204,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-static SkRegion* Region_createFromParcel(JNIEnv* env, jobject clazz, jobject parcel)
+static jlong Region_createFromParcel(JNIEnv* env, jobject clazz, jobject parcel)
 {
     if (parcel == NULL) {
         return NULL;
@@ -177,15 +214,16 @@
 
     SkRegion* region = new SkRegion;
     size_t size = p->readInt32();
-    region->readFromMemory(p->readInplace(size), size);
+    region->readFromMemory(p->readInplace(size));
 
-    return region;
+    return reinterpret_cast<jlong>(region);
 }
 
-static jboolean Region_writeToParcel(JNIEnv* env, jobject clazz, const SkRegion* region, jobject parcel)
+static jboolean Region_writeToParcel(JNIEnv* env, jobject clazz, jlong regionHandle, jobject parcel)
 {
+    const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
     if (parcel == NULL) {
-        return false;
+        return JNI_FALSE;
     }
 
     android::Parcel* p = android::parcelForJavaObject(env, parcel);
@@ -194,14 +232,16 @@
     p->writeInt32(size);
     region->writeToMemory(p->writeInplace(size));
 
-    return true;
+    return JNI_TRUE;
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-static jboolean Region_equals(JNIEnv* env, jobject clazz, const SkRegion *r1, const SkRegion* r2)
+static jboolean Region_equals(JNIEnv* env, jobject clazz, jlong r1Handle, jlong r2Handle)
 {
-  return (jboolean) (*r1 == *r2);
+    const SkRegion *r1 = reinterpret_cast<SkRegion*>(r1Handle);
+    const SkRegion *r2 = reinterpret_cast<SkRegion*>(r2Handle);
+    return boolTojboolean(*r1 == *r2);
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -217,20 +257,23 @@
     }
 };
 
-static RgnIterPair* RegionIter_constructor(JNIEnv* env, jobject, const SkRegion* region)
+static jlong RegionIter_constructor(JNIEnv* env, jobject, jlong regionHandle)
 {
+    const SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
     SkASSERT(region);
-    return new RgnIterPair(*region);
+    return reinterpret_cast<jlong>(new RgnIterPair(*region));
 }
 
-static void RegionIter_destructor(JNIEnv* env, jobject, RgnIterPair* pair)
+static void RegionIter_destructor(JNIEnv* env, jobject, jlong pairHandle)
 {
+    RgnIterPair* pair = reinterpret_cast<RgnIterPair*>(pairHandle);
     SkASSERT(pair);
     delete pair;
 }
 
-static jboolean RegionIter_next(JNIEnv* env, jobject, RgnIterPair* pair, jobject rectObject)
+static jboolean RegionIter_next(JNIEnv* env, jobject, jlong pairHandle, jobject rectObject)
 {
+    RgnIterPair* pair = reinterpret_cast<RgnIterPair*>(pairHandle);
     // the caller has checked that rectObject is not nul
     SkASSERT(pair);
     SkASSERT(rectObject);
@@ -238,31 +281,31 @@
     if (!pair->fIter.done()) {
         GraphicsJNI::irect_to_jrect(pair->fIter.rect(), env, rectObject);
         pair->fIter.next();
-        return true;
+        return JNI_TRUE;
     }
-    return false;
+    return JNI_FALSE;
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 static JNINativeMethod gRegionIterMethods[] = {
-    { "nativeConstructor",  "(I)I",                         (void*)RegionIter_constructor   },
-    { "nativeDestructor",   "(I)V",                         (void*)RegionIter_destructor    },
-    { "nativeNext",         "(ILandroid/graphics/Rect;)Z",  (void*)RegionIter_next          }
+    { "nativeConstructor",  "(J)J",                         (void*)RegionIter_constructor   },
+    { "nativeDestructor",   "(J)V",                         (void*)RegionIter_destructor    },
+    { "nativeNext",         "(JLandroid/graphics/Rect;)Z",  (void*)RegionIter_next          }
 };
 
 static JNINativeMethod gRegionMethods[] = {
     // these are static methods
-    { "nativeConstructor",      "()I",                              (void*)Region_constructor       },
-    { "nativeDestructor",       "(I)V",                             (void*)Region_destructor        },
-    { "nativeSetRegion",        "(II)V",                            (void*)Region_setRegion         },
-    { "nativeSetRect",          "(IIIII)Z",                         (void*)Region_setRect           },
-    { "nativeSetPath",          "(III)Z",                           (void*)Region_setPath           },
-    { "nativeGetBounds",        "(ILandroid/graphics/Rect;)Z",      (void*)Region_getBounds         },
-    { "nativeGetBoundaryPath",  "(II)Z",                            (void*)Region_getBoundaryPath   },
-    { "nativeOp",               "(IIIIII)Z",                        (void*)Region_op0               },
-    { "nativeOp",               "(ILandroid/graphics/Rect;II)Z",    (void*)Region_op1               },
-    { "nativeOp",               "(IIII)Z",                          (void*)Region_op2               },
+    { "nativeConstructor",      "()J",                              (void*)Region_constructor       },
+    { "nativeDestructor",       "(J)V",                             (void*)Region_destructor        },
+    { "nativeSetRegion",        "(JJ)V",                            (void*)Region_setRegion         },
+    { "nativeSetRect",          "(JIIII)Z",                         (void*)Region_setRect           },
+    { "nativeSetPath",          "(JJJ)Z",                           (void*)Region_setPath           },
+    { "nativeGetBounds",        "(JLandroid/graphics/Rect;)Z",      (void*)Region_getBounds         },
+    { "nativeGetBoundaryPath",  "(JJ)Z",                            (void*)Region_getBoundaryPath   },
+    { "nativeOp",               "(JIIIII)Z",                        (void*)Region_op0               },
+    { "nativeOp",               "(JLandroid/graphics/Rect;JI)Z",    (void*)Region_op1               },
+    { "nativeOp",               "(JJJI)Z",                          (void*)Region_op2               },
     // these are methods that take the java region object
     { "isEmpty",                "()Z",                              (void*)Region_isEmpty           },
     { "isRect",                 "()Z",                              (void*)Region_isRect            },
@@ -273,11 +316,11 @@
     { "quickReject",            "(Landroid/graphics/Region;)Z",     (void*)Region_quickRejectRgn    },
     { "scale",                  "(FLandroid/graphics/Region;)V",    (void*)Region_scale             },
     { "translate",              "(IILandroid/graphics/Region;)V",   (void*)Region_translate         },
-    { "nativeToString",         "(I)Ljava/lang/String;",            (void*)Region_toString          },
+    { "nativeToString",         "(J)Ljava/lang/String;",            (void*)Region_toString          },
     // parceling methods
-    { "nativeCreateFromParcel", "(Landroid/os/Parcel;)I",           (void*)Region_createFromParcel  },
-    { "nativeWriteToParcel",    "(ILandroid/os/Parcel;)Z",          (void*)Region_writeToParcel     },
-    { "nativeEquals",           "(II)Z",                            (void*)Region_equals            },
+    { "nativeCreateFromParcel", "(Landroid/os/Parcel;)J",           (void*)Region_createFromParcel  },
+    { "nativeWriteToParcel",    "(JLandroid/os/Parcel;)Z",          (void*)Region_writeToParcel     },
+    { "nativeEquals",           "(JJ)Z",                            (void*)Region_equals            },
 };
 
 int register_android_graphics_Region(JNIEnv* env)
@@ -285,7 +328,7 @@
     jclass clazz = env->FindClass("android/graphics/Region");
     SkASSERT(clazz);
 
-    gRegion_nativeInstanceFieldID = env->GetFieldID(clazz, "mNativeRegion", "I");
+    gRegion_nativeInstanceFieldID = env->GetFieldID(clazz, "mNativeRegion", "J");
     SkASSERT(gRegion_nativeInstanceFieldID);
 
     int result = android::AndroidRuntime::registerNativeMethods(env, "android/graphics/Region",
diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp
index 6323ab3..3047440 100644
--- a/core/jni/android/graphics/Shader.cpp
+++ b/core/jni/android/graphics/Shader.cpp
@@ -24,7 +24,7 @@
     }
 }
 
-static void Color_RGBToHSV(JNIEnv* env, jobject, int red, int green, int blue, jfloatArray hsvArray)
+static void Color_RGBToHSV(JNIEnv* env, jobject, jint red, jint green, jint blue, jfloatArray hsvArray)
 {
     SkScalar hsv[3];
     SkRGBToHSV(red, green, blue, hsv);
@@ -36,7 +36,7 @@
     }
 }
 
-static int Color_HSVToColor(JNIEnv* env, jobject, int alpha, jfloatArray hsvArray)
+static jint Color_HSVToColor(JNIEnv* env, jobject, jint alpha, jfloatArray hsvArray)
 {
     AutoJavaFloatArray  autoHSV(env, hsvArray, 3);
     float*      values = autoHSV.ptr();;
@@ -46,13 +46,15 @@
         hsv[i] = SkFloatToScalar(values[i]);
     }
 
-    return SkHSVToColor(alpha, hsv);
+    return static_cast<jint>(SkHSVToColor(alpha, hsv));
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-static void Shader_destructor(JNIEnv* env, jobject o, SkShader* shader, SkiaShader* skiaShader)
+static void Shader_destructor(JNIEnv* env, jobject o, jlong shaderHandle, jlong skiaShaderHandle)
 {
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
+    SkiaShader* skiaShader = reinterpret_cast<SkiaShader*>(skiaShaderHandle);
     SkSafeUnref(shader);
     // skiaShader == NULL when not !USE_OPENGL_RENDERER, so no need to delete it outside the ifdef
 #ifdef USE_OPENGL_RENDERER
@@ -64,9 +66,12 @@
 #endif
 }
 
-static void Shader_setLocalMatrix(JNIEnv* env, jobject o, SkShader* shader, SkiaShader* skiaShader,
-        const SkMatrix* matrix)
+static void Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle,
+        jlong skiaShaderHandle, jlong matrixHandle)
 {
+    SkShader* shader       = reinterpret_cast<SkShader*>(shaderHandle);
+    SkiaShader* skiaShader = reinterpret_cast<SkiaShader*>(skiaShaderHandle);
+    const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     if (shader) {
         if (NULL == matrix) {
             shader->resetLocalMatrix();
@@ -82,24 +87,27 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-static SkShader* BitmapShader_constructor(JNIEnv* env, jobject o, const SkBitmap* bitmap,
-                                          int tileModeX, int tileModeY)
+static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong bitmapHandle,
+                                      jint tileModeX, jint tileModeY)
 {
+    const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
     SkShader* s = SkShader::CreateBitmapShader(*bitmap,
                                         (SkShader::TileMode)tileModeX,
                                         (SkShader::TileMode)tileModeY);
 
     ThrowIAE_IfNull(env, s);
-    return s;
+    return reinterpret_cast<jlong>(s);
 }
 
-static SkiaShader* BitmapShader_postConstructor(JNIEnv* env, jobject o, SkShader* shader,
-        SkBitmap* bitmap, int tileModeX, int tileModeY) {
+static jlong BitmapShader_postConstructor(JNIEnv* env, jobject o, jlong shaderHandle,
+        jlong bitmapHandle, jint tileModeX, jint tileModeY) {
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
 #ifdef USE_OPENGL_RENDERER
     SkiaShader* skiaShader = new SkiaBitmapShader(bitmap, shader,
             static_cast<SkShader::TileMode>(tileModeX), static_cast<SkShader::TileMode>(tileModeY),
             NULL, (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
@@ -107,9 +115,9 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-static SkShader* LinearGradient_create1(JNIEnv* env, jobject o,
-                                        float x0, float y0, float x1, float y1,
-                                        jintArray colorArray, jfloatArray posArray, int tileMode)
+static jlong LinearGradient_create1(JNIEnv* env, jobject o,
+                                    jfloat x0, jfloat y0, jfloat x1, jfloat y1,
+                                    jintArray colorArray, jfloatArray posArray, jint tileMode)
 {
     SkPoint pts[2];
     pts[0].set(SkFloatToScalar(x0), SkFloatToScalar(y0));
@@ -137,13 +145,14 @@
 
     env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
     ThrowIAE_IfNull(env, shader);
-    return shader;
+    return reinterpret_cast<jlong>(shader);
 }
 
-static SkiaShader* LinearGradient_postCreate1(JNIEnv* env, jobject o, SkShader* shader,
-        float x0, float y0, float x1, float y1, jintArray colorArray,
-        jfloatArray posArray, int tileMode) {
+static jlong LinearGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
+        jfloat x0, jfloat y0, jfloat x1, jfloat y1, jintArray colorArray,
+        jfloatArray posArray, jint tileMode) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
     size_t count = env->GetArrayLength(colorArray);
     const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
 
@@ -206,15 +215,16 @@
             (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
 
     env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
 }
 
-static SkiaShader* LinearGradient_postCreate2(JNIEnv* env, jobject o, SkShader* shader,
-        float x0, float y0, float x1, float y1, int color0, int color1, int tileMode) {
+static jlong LinearGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
+        jfloat x0, jfloat y0, jfloat x1, jfloat y1, jint color0, jint color1, jint tileMode) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
     float* storedBounds = new float[4];
     storedBounds[0] = x0; storedBounds[1] = y0;
     storedBounds[2] = x1; storedBounds[3] = y1;
@@ -231,15 +241,15 @@
             storedPositions, 2, shader, static_cast<SkShader::TileMode>(tileMode), NULL,
             (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
 
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
 }
 
-static SkShader* LinearGradient_create2(JNIEnv* env, jobject o,
-                                        float x0, float y0, float x1, float y1,
-                                        int color0, int color1, int tileMode)
+static jlong LinearGradient_create2(JNIEnv* env, jobject o,
+                                    jfloat x0, jfloat y0, jfloat x1, jfloat y1,
+                                    jint color0, jint color1, jint tileMode)
 {
     SkPoint pts[2];
     pts[0].set(SkFloatToScalar(x0), SkFloatToScalar(y0));
@@ -252,13 +262,13 @@
     SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, (SkShader::TileMode)tileMode);
 
     ThrowIAE_IfNull(env, s);
-    return s;
+    return reinterpret_cast<jlong>(s);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-static SkShader* RadialGradient_create1(JNIEnv* env, jobject, float x, float y, float radius,
-        jintArray colorArray, jfloatArray posArray, int tileMode) {
+static jlong RadialGradient_create1(JNIEnv* env, jobject, jfloat x, jfloat y, jfloat radius,
+        jintArray colorArray, jfloatArray posArray, jint tileMode) {
     SkPoint center;
     center.set(SkFloatToScalar(x), SkFloatToScalar(y));
 
@@ -285,11 +295,11 @@
                                  JNI_ABORT);
 
     ThrowIAE_IfNull(env, shader);
-    return shader;
+    return reinterpret_cast<jlong>(shader);
 }
 
-static SkShader* RadialGradient_create2(JNIEnv* env, jobject, float x, float y, float radius,
-        int color0, int color1, int tileMode) {
+static jlong RadialGradient_create2(JNIEnv* env, jobject, jfloat x, jfloat y, jfloat radius,
+        jint color0, jint color1, jint tileMode) {
     SkPoint center;
     center.set(SkFloatToScalar(x), SkFloatToScalar(y));
 
@@ -300,12 +310,13 @@
     SkShader* s = SkGradientShader::CreateRadial(center, SkFloatToScalar(radius), colors, NULL,
                                           2, (SkShader::TileMode)tileMode);
     ThrowIAE_IfNull(env, s);
-    return s;
+    return reinterpret_cast<jlong>(s);
 }
 
-static SkiaShader* RadialGradient_postCreate1(JNIEnv* env, jobject o, SkShader* shader,
-        float x, float y, float radius, jintArray colorArray, jfloatArray posArray, int tileMode) {
+static jlong RadialGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
+        jfloat x, jfloat y, jfloat radius, jintArray colorArray, jfloatArray posArray, jint tileMode) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
     size_t count = env->GetArrayLength(colorArray);
     const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
 
@@ -335,15 +346,16 @@
             (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
 
     env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
 }
 
-static SkiaShader* RadialGradient_postCreate2(JNIEnv* env, jobject o, SkShader* shader,
-        float x, float y, float radius, int color0, int color1, int tileMode) {
+static jlong RadialGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
+        jfloat x, jfloat y, jfloat radius, jint color0, jint color1, jint tileMode) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
     float* storedPositions = new float[2];
     storedPositions[0] = 0.0f;
     storedPositions[1] = 1.0f;
@@ -356,7 +368,7 @@
             storedPositions, 2, shader, (SkShader::TileMode) tileMode, NULL,
             (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
 
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
@@ -364,7 +376,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static SkShader* SweepGradient_create1(JNIEnv* env, jobject, float x, float y,
+static jlong SweepGradient_create1(JNIEnv* env, jobject, jfloat x, jfloat y,
         jintArray jcolors, jfloatArray jpositions) {
     size_t      count = env->GetArrayLength(jcolors);
     const jint* colors = env->GetIntArrayElements(jcolors, NULL);
@@ -388,10 +400,10 @@
     env->ReleaseIntArrayElements(jcolors, const_cast<jint*>(colors),
                                  JNI_ABORT);
     ThrowIAE_IfNull(env, shader);
-    return shader;
+    return reinterpret_cast<jlong>(shader);
 }
 
-static SkShader* SweepGradient_create2(JNIEnv* env, jobject, float x, float y,
+static jlong SweepGradient_create2(JNIEnv* env, jobject, jfloat x, jfloat y,
         int color0, int color1) {
     SkColor colors[2];
     colors[0] = color0;
@@ -399,12 +411,13 @@
     SkShader* s = SkGradientShader::CreateSweep(SkFloatToScalar(x), SkFloatToScalar(y),
                                          colors, NULL, 2);
     ThrowIAE_IfNull(env, s);
-    return s;
+    return reinterpret_cast<jlong>(s);
 }
 
-static SkiaShader* SweepGradient_postCreate1(JNIEnv* env, jobject o, SkShader* shader,
-        float x, float y, jintArray colorArray, jfloatArray posArray) {
+static jlong SweepGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
+        jfloat x, jfloat y, jintArray colorArray, jfloatArray posArray) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
     size_t count = env->GetArrayLength(colorArray);
     const jint* colorValues = env->GetIntArrayElements(colorArray, NULL);
 
@@ -433,15 +446,16 @@
             shader, NULL, (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
 
     env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
 }
 
-static SkiaShader* SweepGradient_postCreate2(JNIEnv* env, jobject o, SkShader* shader,
-        float x, float y, int color0, int color1) {
+static jlong SweepGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
+        jfloat x, jfloat y, jint color0, jint color1) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
     float* storedPositions = new float[2];
     storedPositions[0] = 0.0f;
     storedPositions[1] = 1.0f;
@@ -453,7 +467,7 @@
     SkiaShader* skiaShader = new SkiaSweepGradientShader(x, y, storedColors, storedPositions, 2,
             shader, NULL, (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
 
-    return skiaShader;
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
@@ -461,39 +475,57 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////
 
-static SkShader* ComposeShader_create1(JNIEnv* env, jobject o,
-        SkShader* shaderA, SkShader* shaderB, SkXfermode* mode)
+static jlong ComposeShader_create1(JNIEnv* env, jobject o,
+        jlong shaderAHandle, jlong shaderBHandle, jlong modeHandle)
 {
-    return new SkComposeShader(shaderA, shaderB, mode);
+    SkShader* shaderA = reinterpret_cast<SkShader *>(shaderAHandle);
+    SkShader* shaderB = reinterpret_cast<SkShader *>(shaderBHandle);
+    SkXfermode* mode = reinterpret_cast<SkXfermode *>(modeHandle);
+    SkShader* shader = new SkComposeShader(shaderA, shaderB, mode);
+    return reinterpret_cast<jlong>(shader);
 }
 
-static SkShader* ComposeShader_create2(JNIEnv* env, jobject o,
-        SkShader* shaderA, SkShader* shaderB, SkPorterDuff::Mode porterDuffMode)
+static jlong ComposeShader_create2(JNIEnv* env, jobject o,
+        jlong shaderAHandle, jlong shaderBHandle, jint porterDuffModeHandle)
 {
+    SkShader* shaderA = reinterpret_cast<SkShader *>(shaderAHandle);
+    SkShader* shaderB = reinterpret_cast<SkShader *>(shaderBHandle);
+    SkPorterDuff::Mode porterDuffMode = static_cast<SkPorterDuff::Mode>(porterDuffModeHandle);
     SkAutoUnref au(SkPorterDuff::CreateXfermode(porterDuffMode));
     SkXfermode* mode = (SkXfermode*) au.get();
-    return new SkComposeShader(shaderA, shaderB, mode);
+    SkShader* shader = new SkComposeShader(shaderA, shaderB, mode);
+    return reinterpret_cast<jlong>(shader);
 }
 
-static SkiaShader* ComposeShader_postCreate2(JNIEnv* env, jobject o, SkShader* shader,
-        SkiaShader* shaderA, SkiaShader* shaderB, SkPorterDuff::Mode porterDuffMode) {
+static jlong ComposeShader_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle,
+        jlong shaderAHandle, jlong shaderBHandle, jint porterDuffModeHandle) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader *>(shaderHandle);
+    SkiaShader* shaderA = reinterpret_cast<SkiaShader *>(shaderAHandle);
+    SkiaShader* shaderB = reinterpret_cast<SkiaShader *>(shaderBHandle);
+    SkPorterDuff::Mode porterDuffMode = static_cast<SkPorterDuff::Mode>(porterDuffModeHandle);
     SkXfermode::Mode mode = SkPorterDuff::ToXfermodeMode(porterDuffMode);
-    return new SkiaComposeShader(shaderA, shaderB, mode, shader);
+    SkiaShader* skiaShader = new SkiaComposeShader(shaderA, shaderB, mode, shader);
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
 }
 
-static SkiaShader* ComposeShader_postCreate1(JNIEnv* env, jobject o, SkShader* shader,
-        SkiaShader* shaderA, SkiaShader* shaderB, SkXfermode* mode) {
+static jlong ComposeShader_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle,
+        jlong shaderAHandle, jlong shaderBHandle, jlong modeHandle) {
 #ifdef USE_OPENGL_RENDERER
+    SkShader* shader = reinterpret_cast<SkShader *>(shaderHandle);
+    SkiaShader* shaderA = reinterpret_cast<SkiaShader *>(shaderAHandle);
+    SkiaShader* shaderB = reinterpret_cast<SkiaShader *>(shaderBHandle);
+    SkXfermode* mode = reinterpret_cast<SkXfermode *>(modeHandle);
     SkXfermode::Mode skiaMode;
     if (!SkXfermode::IsMode(mode, &skiaMode)) {
         // TODO: Support other modes
         skiaMode = SkXfermode::kSrcOver_Mode;
     }
-    return new SkiaComposeShader(shaderA, shaderB, skiaMode, shader);
+    SkiaShader* skiaShader = new SkiaComposeShader(shaderA, shaderB, skiaMode, shader);
+    return reinterpret_cast<jlong>(skiaShader);
 #else
     return NULL;
 #endif
@@ -507,41 +539,41 @@
 };
 
 static JNINativeMethod gShaderMethods[] = {
-    { "nativeDestructor",        "(II)V",    (void*)Shader_destructor        },
-    { "nativeSetLocalMatrix",    "(III)V",   (void*)Shader_setLocalMatrix    }
+    { "nativeDestructor",        "(JJ)V",    (void*)Shader_destructor        },
+    { "nativeSetLocalMatrix",    "(JJJ)V",   (void*)Shader_setLocalMatrix    }
 };
 
 static JNINativeMethod gBitmapShaderMethods[] = {
-    { "nativeCreate",     "(III)I",  (void*)BitmapShader_constructor },
-    { "nativePostCreate", "(IIII)I", (void*)BitmapShader_postConstructor }
+    { "nativeCreate",     "(JII)J",  (void*)BitmapShader_constructor },
+    { "nativePostCreate", "(JJII)J", (void*)BitmapShader_postConstructor }
 };
 
 static JNINativeMethod gLinearGradientMethods[] = {
-    { "nativeCreate1",     "(FFFF[I[FI)I",  (void*)LinearGradient_create1     },
-    { "nativeCreate2",     "(FFFFIII)I",    (void*)LinearGradient_create2     },
-    { "nativePostCreate1", "(IFFFF[I[FI)I", (void*)LinearGradient_postCreate1 },
-    { "nativePostCreate2", "(IFFFFIII)I",   (void*)LinearGradient_postCreate2 }
+    { "nativeCreate1",     "(FFFF[I[FI)J",  (void*)LinearGradient_create1     },
+    { "nativeCreate2",     "(FFFFIII)J",    (void*)LinearGradient_create2     },
+    { "nativePostCreate1", "(JFFFF[I[FI)J", (void*)LinearGradient_postCreate1 },
+    { "nativePostCreate2", "(JFFFFIII)J",   (void*)LinearGradient_postCreate2 }
 };
 
 static JNINativeMethod gRadialGradientMethods[] = {
-    { "nativeCreate1",     "(FFF[I[FI)I",  (void*)RadialGradient_create1     },
-    { "nativeCreate2",     "(FFFIII)I",    (void*)RadialGradient_create2     },
-    { "nativePostCreate1", "(IFFF[I[FI)I", (void*)RadialGradient_postCreate1 },
-    { "nativePostCreate2", "(IFFFIII)I",   (void*)RadialGradient_postCreate2 }
+    { "nativeCreate1",     "(FFF[I[FI)J",  (void*)RadialGradient_create1     },
+    { "nativeCreate2",     "(FFFIII)J",    (void*)RadialGradient_create2     },
+    { "nativePostCreate1", "(JFFF[I[FI)J", (void*)RadialGradient_postCreate1 },
+    { "nativePostCreate2", "(JFFFIII)J",   (void*)RadialGradient_postCreate2 }
 };
 
 static JNINativeMethod gSweepGradientMethods[] = {
-    { "nativeCreate1",     "(FF[I[F)I",  (void*)SweepGradient_create1     },
-    { "nativeCreate2",     "(FFII)I",    (void*)SweepGradient_create2     },
-    { "nativePostCreate1", "(IFF[I[F)I", (void*)SweepGradient_postCreate1 },
-    { "nativePostCreate2", "(IFFII)I",   (void*)SweepGradient_postCreate2 }
+    { "nativeCreate1",     "(FF[I[F)J",  (void*)SweepGradient_create1     },
+    { "nativeCreate2",     "(FFII)J",    (void*)SweepGradient_create2     },
+    { "nativePostCreate1", "(JFF[I[F)J", (void*)SweepGradient_postCreate1 },
+    { "nativePostCreate2", "(JFFII)J",   (void*)SweepGradient_postCreate2 }
 };
 
 static JNINativeMethod gComposeShaderMethods[] = {
-    { "nativeCreate1",      "(III)I",   (void*)ComposeShader_create1     },
-    { "nativeCreate2",      "(III)I",   (void*)ComposeShader_create2     },
-    { "nativePostCreate1",  "(IIII)I",  (void*)ComposeShader_postCreate1 },
-    { "nativePostCreate2",  "(IIII)I",  (void*)ComposeShader_postCreate2 }
+    { "nativeCreate1",      "(JJJ)J",   (void*)ComposeShader_create1     },
+    { "nativeCreate2",      "(JJI)J",   (void*)ComposeShader_create2     },
+    { "nativePostCreate1",  "(JJJJ)J",  (void*)ComposeShader_postCreate1 },
+    { "nativePostCreate2",  "(JJJI)J",  (void*)ComposeShader_postCreate2 }
 };
 
 #include <android_runtime/AndroidRuntime.h>
diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp
index 0c9b3bc..3116955 100644
--- a/core/jni/android/graphics/SurfaceTexture.cpp
+++ b/core/jni/android/graphics/SurfaceTexture.cpp
@@ -55,28 +55,28 @@
         const sp<GLConsumer>& surfaceTexture)
 {
     GLConsumer* const p =
-        (GLConsumer*)env->GetIntField(thiz, fields.surfaceTexture);
+        (GLConsumer*)env->GetLongField(thiz, fields.surfaceTexture);
     if (surfaceTexture.get()) {
         surfaceTexture->incStrong((void*)SurfaceTexture_setSurfaceTexture);
     }
     if (p) {
         p->decStrong((void*)SurfaceTexture_setSurfaceTexture);
     }
-    env->SetIntField(thiz, fields.surfaceTexture, (int)surfaceTexture.get());
+    env->SetLongField(thiz, fields.surfaceTexture, (jlong)surfaceTexture.get());
 }
 
 static void SurfaceTexture_setBufferQueue(JNIEnv* env, jobject thiz,
         const sp<BufferQueue>& bq)
 {
     BufferQueue* const p =
-        (BufferQueue*)env->GetIntField(thiz, fields.bufferQueue);
+        (BufferQueue*)env->GetLongField(thiz, fields.bufferQueue);
     if (bq.get()) {
         bq->incStrong((void*)SurfaceTexture_setBufferQueue);
     }
     if (p) {
         p->decStrong((void*)SurfaceTexture_setBufferQueue);
     }
-    env->SetIntField(thiz, fields.bufferQueue, (int)bq.get());
+    env->SetLongField(thiz, fields.bufferQueue, (jlong)bq.get());
 }
 
 static void SurfaceTexture_setFrameAvailableListener(JNIEnv* env,
@@ -84,22 +84,22 @@
 {
     GLConsumer::FrameAvailableListener* const p =
         (GLConsumer::FrameAvailableListener*)
-            env->GetIntField(thiz, fields.frameAvailableListener);
+            env->GetLongField(thiz, fields.frameAvailableListener);
     if (listener.get()) {
         listener->incStrong((void*)SurfaceTexture_setSurfaceTexture);
     }
     if (p) {
         p->decStrong((void*)SurfaceTexture_setSurfaceTexture);
     }
-    env->SetIntField(thiz, fields.frameAvailableListener, (int)listener.get());
+    env->SetLongField(thiz, fields.frameAvailableListener, (jlong)listener.get());
 }
 
 sp<GLConsumer> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz) {
-    return (GLConsumer*)env->GetIntField(thiz, fields.surfaceTexture);
+    return (GLConsumer*)env->GetLongField(thiz, fields.surfaceTexture);
 }
 
 sp<IGraphicBufferProducer> SurfaceTexture_getProducer(JNIEnv* env, jobject thiz) {
-    return (BufferQueue*)env->GetIntField(thiz, fields.bufferQueue);
+    return (BufferQueue*)env->GetLongField(thiz, fields.bufferQueue);
 }
 
 sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(JNIEnv* env, jobject thiz) {
@@ -201,19 +201,19 @@
 static void SurfaceTexture_classInit(JNIEnv* env, jclass clazz)
 {
     fields.surfaceTexture = env->GetFieldID(clazz,
-            ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I");
+            ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "J");
     if (fields.surfaceTexture == NULL) {
         ALOGE("can't find android/graphics/SurfaceTexture.%s",
                 ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID);
     }
     fields.bufferQueue = env->GetFieldID(clazz,
-            ANDROID_GRAPHICS_BUFFERQUEUE_JNI_ID, "I");
+            ANDROID_GRAPHICS_BUFFERQUEUE_JNI_ID, "J");
     if (fields.bufferQueue == NULL) {
         ALOGE("can't find android/graphics/SurfaceTexture.%s",
                 ANDROID_GRAPHICS_BUFFERQUEUE_JNI_ID);
     }
     fields.frameAvailableListener = env->GetFieldID(clazz,
-            ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID, "I");
+            ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID, "J");
     if (fields.frameAvailableListener == NULL) {
         ALOGE("can't find android/graphics/SurfaceTexture.%s",
                 ANDROID_GRAPHICS_FRAMEAVAILABLELISTENER_JNI_ID);
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index 144ac39..92d253f 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -20,7 +20,6 @@
 
 #include "TextLayoutCache.h"
 #include "TextLayout.h"
-#include "SkGlyphCache.h"
 #include "SkTypeface_android.h"
 #include "HarfBuzzNGFaceSkia.h"
 #include <unicode/unistr.h>
@@ -758,8 +757,8 @@
             outPos->add(ypos);
             totalAdvance += xAdvance;
 
-            SkAutoGlyphCache autoCache(mShapingPaint, NULL, NULL);
-            const SkGlyph& metrics = autoCache.getCache()->getGlyphIDMetrics(glyphId);
+            // TODO: consider using glyph cache
+            const SkGlyph& metrics = mShapingPaint.getGlyphMetrics(glyphId, NULL);
             outBounds->join(xpos + metrics.fLeft, ypos + metrics.fTop,
                     xpos + metrics.fLeft + metrics.fWidth, ypos + metrics.fTop + metrics.fHeight);
 
diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp
index d10a960..d096c2a 100644
--- a/core/jni/android/graphics/Typeface.cpp
+++ b/core/jni/android/graphics/Typeface.cpp
@@ -4,7 +4,6 @@
 #include "GraphicsJNI.h"
 #include "SkStream.h"
 #include "SkTypeface.h"
-#include "Utils.h"
 #include <android_runtime/android_util_AssetManager.h>
 #include <androidfw/AssetManager.h>
 
@@ -28,8 +27,9 @@
     const char* fCStr;
 };
 
-static SkTypeface* Typeface_create(JNIEnv* env, jobject, jstring name,
-                                   SkTypeface::Style style) {
+static jlong Typeface_create(JNIEnv* env, jobject, jstring name,
+                             jint styleHandle) {
+    SkTypeface::Style style = static_cast<SkTypeface::Style>(styleHandle);
     SkTypeface* face = NULL;
 
     if (NULL != name) {
@@ -48,10 +48,11 @@
     if (NULL == face) {
         face = SkTypeface::CreateFromName(NULL, style);
     }
-    return face;
+    return reinterpret_cast<jlong>(face);
 }
 
-static SkTypeface* Typeface_createFromTypeface(JNIEnv* env, jobject, SkTypeface* family, int style) {
+static jlong Typeface_createFromTypeface(JNIEnv* env, jobject, jlong familyHandle, jint style) {
+    SkTypeface* family = reinterpret_cast<SkTypeface*>(familyHandle);
     SkTypeface* face = SkTypeface::CreateFromTypeface(family, (SkTypeface::Style)style);
     // Try to find the closest matching font, using the standard heuristic
     if (NULL == face) {
@@ -63,20 +64,81 @@
     if (NULL == face) {
         face = SkTypeface::CreateFromName(NULL, (SkTypeface::Style)style);
     }
-    return face;
+    return reinterpret_cast<jlong>(face);
 }
 
-static void Typeface_unref(JNIEnv* env, jobject obj, SkTypeface* face) {
+static void Typeface_unref(JNIEnv* env, jobject obj, jlong faceHandle) {
+    SkTypeface* face = reinterpret_cast<SkTypeface*>(faceHandle);
     SkSafeUnref(face);
 }
 
-static int Typeface_getStyle(JNIEnv* env, jobject obj, SkTypeface* face) {
-    return face->style();
+static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) {
+    SkTypeface* face = reinterpret_cast<SkTypeface*>(faceHandle);
+    return static_cast<jint>(face->style());
 }
 
-static SkTypeface* Typeface_createFromAsset(JNIEnv* env, jobject,
-                                            jobject jassetMgr,
-                                            jstring jpath) {
+class AssetStream : public SkStream {
+public:
+    AssetStream(Asset* asset, bool hasMemoryBase) : fAsset(asset)
+    {
+        fMemoryBase = hasMemoryBase ? fAsset->getBuffer(false) : NULL;
+    }
+
+    virtual ~AssetStream()
+    {
+        delete fAsset;
+    }
+
+    virtual const void* getMemoryBase()
+    {
+        return fMemoryBase;
+    }
+
+	virtual bool rewind()
+    {
+        off64_t pos = fAsset->seek(0, SEEK_SET);
+        return pos != (off64_t)-1;
+    }
+
+	virtual size_t read(void* buffer, size_t size)
+    {
+        ssize_t amount;
+
+        if (NULL == buffer)
+        {
+            if (0 == size)  // caller is asking us for our total length
+                return fAsset->getLength();
+
+            // asset->seek returns new total offset
+            // we want to return amount that was skipped
+
+            off64_t oldOffset = fAsset->seek(0, SEEK_CUR);
+            if (-1 == oldOffset)
+                return 0;
+            off64_t newOffset = fAsset->seek(size, SEEK_CUR);
+            if (-1 == newOffset)
+                return 0;
+
+            amount = newOffset - oldOffset;
+        }
+        else
+        {
+            amount = fAsset->read(buffer, size);
+        }
+
+        if (amount < 0)
+            amount = 0;
+        return amount;
+    }
+
+private:
+    Asset*      fAsset;
+    const void* fMemoryBase;
+};
+
+static jlong Typeface_createFromAsset(JNIEnv* env, jobject,
+                                      jobject jassetMgr,
+                                      jstring jpath) {
 
     NPE_CHECK_RETURN_ZERO(env, jassetMgr);
     NPE_CHECK_RETURN_ZERO(env, jpath);
@@ -92,35 +154,33 @@
         return NULL;
     }
 
-    SkStream* stream = new AssetStreamAdaptor(asset,
-                                              AssetStreamAdaptor::kYes_OwnAsset,
-                                              AssetStreamAdaptor::kYes_HasMemoryBase);
+    SkStream* stream = new AssetStream(asset, true);
     SkTypeface* face = SkTypeface::CreateFromStream(stream);
     // SkTypeFace::CreateFromStream calls ref() on the stream, so we
     // need to unref it here or it won't be freed later on
     stream->unref();
 
-    return face;
+    return reinterpret_cast<jlong>(face);
 }
 
-static SkTypeface* Typeface_createFromFile(JNIEnv* env, jobject, jstring jpath) {
+static jlong Typeface_createFromFile(JNIEnv* env, jobject, jstring jpath) {
     NPE_CHECK_RETURN_ZERO(env, jpath);
 
     AutoJavaStringToUTF8 str(env, jpath);
 
-    return SkTypeface::CreateFromFile(str.c_str());
+    return reinterpret_cast<jlong>(SkTypeface::CreateFromFile(str.c_str()));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 static JNINativeMethod gTypefaceMethods[] = {
-    { "nativeCreate",        "(Ljava/lang/String;I)I", (void*)Typeface_create },
-    { "nativeCreateFromTypeface", "(II)I", (void*)Typeface_createFromTypeface },
-    { "nativeUnref",              "(I)V",  (void*)Typeface_unref },
-    { "nativeGetStyle",           "(I)I",  (void*)Typeface_getStyle },
-    { "nativeCreateFromAsset",    "(Landroid/content/res/AssetManager;Ljava/lang/String;)I",
+    { "nativeCreate",        "(Ljava/lang/String;I)J", (void*)Typeface_create },
+    { "nativeCreateFromTypeface", "(JI)J", (void*)Typeface_createFromTypeface },
+    { "nativeUnref",              "(J)V",  (void*)Typeface_unref },
+    { "nativeGetStyle",           "(J)I",  (void*)Typeface_getStyle },
+    { "nativeCreateFromAsset",    "(Landroid/content/res/AssetManager;Ljava/lang/String;)J",
                                            (void*)Typeface_createFromAsset },
-    { "nativeCreateFromFile",     "(Ljava/lang/String;)I",
+    { "nativeCreateFromFile",     "(Ljava/lang/String;)J",
                                            (void*)Typeface_createFromFile },
 };
 
diff --git a/core/jni/android/graphics/Utils.cpp b/core/jni/android/graphics/Utils.cpp
index eb416cb..b7d1f3a 100644
--- a/core/jni/android/graphics/Utils.cpp
+++ b/core/jni/android/graphics/Utils.cpp
@@ -19,21 +19,6 @@
 
 using namespace android;
 
-AssetStreamAdaptor::AssetStreamAdaptor(Asset* asset, OwnAsset ownAsset,
-                                       HasMemoryBase hasMemoryBase)
-    : fAsset(asset)
-    , fMemoryBase(kYes_HasMemoryBase == hasMemoryBase ?
-                  asset->getBuffer(false) : NULL)
-    , fOwnAsset(ownAsset)
-{
-}
-
-AssetStreamAdaptor::~AssetStreamAdaptor() {
-    if (kYes_OwnAsset == fOwnAsset) {
-        delete fAsset;
-    }
-}
-
 bool AssetStreamAdaptor::rewind() {
     off64_t pos = fAsset->seek(0, SEEK_SET);
     if (pos == (off64_t)-1) {
diff --git a/core/jni/android/graphics/Utils.h b/core/jni/android/graphics/Utils.h
index b90593c..a1ac72a 100644
--- a/core/jni/android/graphics/Utils.h
+++ b/core/jni/android/graphics/Utils.h
@@ -28,36 +28,16 @@
 
 class AssetStreamAdaptor : public SkStreamRewindable {
 public:
-    // Enum passed to constructor. If set to kYes_OwnAsset,
-    // the passed in Asset will be deleted upon destruction.
-    enum OwnAsset {
-        kYes_OwnAsset,
-        kNo_OwnAsset,
-    };
-
-    // Enum passed to constructor. If set to kYes_HasMemoryBase,
-    // getMemoryBase will return the Asset's buffer.
-    enum HasMemoryBase {
-        kYes_HasMemoryBase,
-        kNo_HasMemoryBase,
-    };
-
-    AssetStreamAdaptor(Asset*, OwnAsset, HasMemoryBase);
-    ~AssetStreamAdaptor();
-
+    AssetStreamAdaptor(Asset* a) : fAsset(a) {}
     virtual bool rewind();
     virtual size_t read(void* buffer, size_t size);
     virtual bool hasLength() const { return true; }
     virtual size_t getLength() const;
     virtual bool isAtEnd() const;
 
-    virtual const void* getMemoryBase() { return fMemoryBase; }
-
     virtual SkStreamRewindable* duplicate() const;
 private:
-    Asset*              fAsset;
-    const void* const   fMemoryBase;
-    const OwnAsset      fOwnAsset;
+    Asset*  fAsset;
 };
 
 /**
diff --git a/core/jni/android/graphics/Xfermode.cpp b/core/jni/android/graphics/Xfermode.cpp
index 976a91f..eedceb7 100644
--- a/core/jni/android/graphics/Xfermode.cpp
+++ b/core/jni/android/graphics/Xfermode.cpp
@@ -26,35 +26,37 @@
 class SkXfermodeGlue {
 public:
 
-    static void finalizer(JNIEnv* env, jobject, SkXfermode* obj)
+    static void finalizer(JNIEnv* env, jobject, jlong objHandle)
     {
+        SkXfermode* obj = reinterpret_cast<SkXfermode *>(objHandle);
         SkSafeUnref(obj);
     }
     
-    static SkXfermode* avoid_create(JNIEnv* env, jobject, SkColor opColor,
-                                U8CPU tolerance, SkAvoidXfermode::Mode mode)
+    static jlong avoid_create(JNIEnv* env, jobject, jint opColor,
+                                jint tolerance, jint modeHandle)
     {
-        return new SkAvoidXfermode(opColor, tolerance, mode);
+        SkAvoidXfermode::Mode mode = static_cast<SkAvoidXfermode::Mode>(modeHandle);
+        return reinterpret_cast<jlong>(new SkAvoidXfermode(opColor, tolerance, mode));
     }
-    
-    static SkXfermode* pixelxor_create(JNIEnv* env, jobject, SkColor opColor)
+
+    static jlong pixelxor_create(JNIEnv* env, jobject, jint opColor)
     {
-        return new SkPixelXorXfermode(opColor);
+        return reinterpret_cast<jlong>(new SkPixelXorXfermode(opColor));
     }
 };
 
 ///////////////////////////////////////////////////////////////////////////////
 
 static JNINativeMethod gXfermodeMethods[] = {
-    {"finalizer", "(I)V", (void*) SkXfermodeGlue::finalizer}
+    {"finalizer", "(J)V", (void*) SkXfermodeGlue::finalizer}
 };
 
 static JNINativeMethod gAvoidMethods[] = {
-    {"nativeCreate", "(III)I", (void*) SkXfermodeGlue::avoid_create}
+    {"nativeCreate", "(III)J", (void*) SkXfermodeGlue::avoid_create}
 };
 
 static JNINativeMethod gPixelXorMethods[] = {
-    {"nativeCreate", "(I)I", (void*) SkXfermodeGlue::pixelxor_create}
+    {"nativeCreate", "(I)J", (void*) SkXfermodeGlue::pixelxor_create}
 };
 
 #include <android_runtime/AndroidRuntime.h>
diff --git a/core/jni/android/graphics/YuvToJpegEncoder.cpp b/core/jni/android/graphics/YuvToJpegEncoder.cpp
index f386905..799782d 100644
--- a/core/jni/android/graphics/YuvToJpegEncoder.cpp
+++ b/core/jni/android/graphics/YuvToJpegEncoder.cpp
@@ -217,8 +217,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 static jboolean YuvImage_compressToJpeg(JNIEnv* env, jobject, jbyteArray inYuv,
-        int format, int width, int height, jintArray offsets,
-        jintArray strides, int jpegQuality, jobject jstream,
+        jint format, jint width, jint height, jintArray offsets,
+        jintArray strides, jint jpegQuality, jobject jstream,
         jbyteArray jstorage) {
     jbyte* yuv = env->GetByteArrayElements(inYuv, NULL);
     SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
@@ -227,7 +227,7 @@
     jint* imgStrides = env->GetIntArrayElements(strides, NULL);
     YuvToJpegEncoder* encoder = YuvToJpegEncoder::create(format, imgStrides);
     if (encoder == NULL) {
-        return false;
+        return JNI_FALSE;
     }
     encoder->encode(strm, yuv, width, height, imgOffsets, jpegQuality);
 
@@ -235,7 +235,7 @@
     env->ReleaseByteArrayElements(inYuv, yuv, 0);
     env->ReleaseIntArrayElements(offsets, imgOffsets, 0);
     env->ReleaseIntArrayElements(strides, imgStrides, 0);
-    return true;
+    return JNI_TRUE;
 }
 ///////////////////////////////////////////////////////////////////////////////
 
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp
index 4bb091d..48367ff 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -389,7 +389,7 @@
 }
 
 static
-int util_frustumCullSpheres(JNIEnv *env, jclass clazz,
+jint util_frustumCullSpheres(JNIEnv *env, jclass clazz,
         jfloatArray mvp_ref, jint mvpOffset,
         jfloatArray spheres_ref, jint spheresOffset, jint spheresCount,
         jintArray results_ref, jint resultsOffset, jint resultsCapacity) {
@@ -436,7 +436,7 @@
  */
 
 static
-int util_visibilityTest(JNIEnv *env, jclass clazz,
+jint util_visibilityTest(JNIEnv *env, jclass clazz,
         jfloatArray ws_ref, jint wsOffset,
         jfloatArray positions_ref, jint positionsOffset,
         jcharArray indices_ref, jint indicesOffset, jint indexCount) {
@@ -553,7 +553,7 @@
 void nativeUtilsClassInit(JNIEnv *env, jclass clazz)
 {
     jclass bitmapClass = env->FindClass("android/graphics/Bitmap");
-    nativeBitmapID = env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
+    nativeBitmapID = env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
 }
 
 extern void setGLDebugLevel(int level);
@@ -630,9 +630,9 @@
         jobject jbitmap)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID);
+            (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
-    SkBitmap::Config config = bitmap.config();
+    SkBitmap::Config config = bitmap.getConfig();
     return getInternalFormat(config);
 }
 
@@ -640,9 +640,9 @@
         jobject jbitmap)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID);
+            (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
-    SkBitmap::Config config = bitmap.config();
+    SkBitmap::Config config = bitmap.getConfig();
     return getType(config);
 }
 
@@ -651,9 +651,9 @@
         jobject jbitmap, jint type, jint border)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID);
+            (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
-    SkBitmap::Config config = bitmap.config();
+    SkBitmap::Config config = bitmap.getConfig();
     if (internalformat < 0) {
         internalformat = getInternalFormat(config);
     }
@@ -681,7 +681,7 @@
             SkColorTable* ctable = bitmap.getColorTable();
             memcpy(data, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
             memcpy(pixels, p, size);
-            ctable->unlockColors();
+            ctable->unlockColors(false);
             glCompressedTexImage2D(target, level, internalformat, w, h, border, imageSize, data);
             free(data);
         } else {
@@ -700,9 +700,9 @@
         jobject jbitmap, jint format, jint type)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID);
+            (SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
-    SkBitmap::Config config = bitmap.config();
+    SkBitmap::Config config = bitmap.getConfig();
     if (format < 0) {
         format = getInternalFormat(config);
         if (format == GL_PALETTE8_RGBA8_OES)
@@ -773,7 +773,7 @@
     pointer = _env->CallStaticLongMethod(nioAccessClass,
             getBasePointerID, buffer);
     if (pointer != 0L) {
-        return (void *) (jint) pointer;
+        return reinterpret_cast<void *>(pointer);
     }
     return NULL;
 }
@@ -974,7 +974,7 @@
             result = etc1_pkm_is_valid((etc1_byte*) headerB.getData());
         }
     }
-    return result;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 /**
@@ -997,7 +997,7 @@
 /**
  * Read the image height from a PKM header
  */
-static int etc1_getHeight(JNIEnv *env, jclass clazz,
+static jint etc1_getHeight(JNIEnv *env, jclass clazz,
         jobject header) {
     jint result = 0;
     BufferHelper headerB(env, header);
diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp
index 5418006..9c44093 100644
--- a/core/jni/android_app_NativeActivity.cpp
+++ b/core/jni/android_app_NativeActivity.cpp
@@ -241,10 +241,10 @@
 
 // ------------------------------------------------------------------------
 
-static jint
+static jlong
 loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jstring funcName,
         jobject messageQueue, jstring internalDataDir, jstring obbDir,
-        jstring externalDataDir, int sdkVersion,
+        jstring externalDataDir, jint sdkVersion,
         jobject jAssetMgr, jbyteArray savedState)
 {
     LOG_TRACE("loadNativeCode_native");
@@ -338,11 +338,11 @@
         }
     }
     
-    return (jint)code;
+    return (jlong)code;
 }
 
 static void
-unloadNativeCode_native(JNIEnv* env, jobject clazz, jint handle)
+unloadNativeCode_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("unloadNativeCode_native");
     if (handle != 0) {
@@ -352,7 +352,7 @@
 }
 
 static void
-onStart_native(JNIEnv* env, jobject clazz, jint handle)
+onStart_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onStart_native");
     if (handle != 0) {
@@ -364,7 +364,7 @@
 }
 
 static void
-onResume_native(JNIEnv* env, jobject clazz, jint handle)
+onResume_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onResume_native");
     if (handle != 0) {
@@ -376,7 +376,7 @@
 }
 
 static jbyteArray
-onSaveInstanceState_native(JNIEnv* env, jobject clazz, jint handle)
+onSaveInstanceState_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onSaveInstanceState_native");
 
@@ -403,7 +403,7 @@
 }
 
 static void
-onPause_native(JNIEnv* env, jobject clazz, jint handle)
+onPause_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onPause_native");
     if (handle != 0) {
@@ -415,7 +415,7 @@
 }
 
 static void
-onStop_native(JNIEnv* env, jobject clazz, jint handle)
+onStop_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onStop_native");
     if (handle != 0) {
@@ -427,7 +427,7 @@
 }
 
 static void
-onConfigurationChanged_native(JNIEnv* env, jobject clazz, jint handle)
+onConfigurationChanged_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onConfigurationChanged_native");
     if (handle != 0) {
@@ -439,7 +439,7 @@
 }
 
 static void
-onLowMemory_native(JNIEnv* env, jobject clazz, jint handle)
+onLowMemory_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onLowMemory_native");
     if (handle != 0) {
@@ -451,7 +451,7 @@
 }
 
 static void
-onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jint handle, jboolean focused)
+onWindowFocusChanged_native(JNIEnv* env, jobject clazz, jlong handle, jboolean focused)
 {
     LOG_TRACE("onWindowFocusChanged_native");
     if (handle != 0) {
@@ -463,7 +463,7 @@
 }
 
 static void
-onSurfaceCreated_native(JNIEnv* env, jobject clazz, jint handle, jobject surface)
+onSurfaceCreated_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface)
 {
     LOG_TRACE("onSurfaceCreated_native");
     if (handle != 0) {
@@ -483,7 +483,7 @@
 }
 
 static void
-onSurfaceChanged_native(JNIEnv* env, jobject clazz, jint handle, jobject surface,
+onSurfaceChanged_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface,
         jint format, jint width, jint height)
 {
     LOG_TRACE("onSurfaceChanged_native");
@@ -524,7 +524,7 @@
 }
 
 static void
-onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jint handle)
+onSurfaceRedrawNeeded_native(JNIEnv* env, jobject clazz, jlong handle)
 {
     LOG_TRACE("onSurfaceRedrawNeeded_native");
     if (handle != 0) {
@@ -536,7 +536,7 @@
 }
 
 static void
-onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jint handle, jobject surface)
+onSurfaceDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jobject surface)
 {
     LOG_TRACE("onSurfaceDestroyed_native");
     if (handle != 0) {
@@ -550,7 +550,7 @@
 }
 
 static void
-onInputQueueCreated_native(JNIEnv* env, jobject clazz, jint handle, jint queuePtr)
+onInputQueueCreated_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
 {
     LOG_TRACE("onInputChannelCreated_native");
     if (handle != 0) {
@@ -563,7 +563,7 @@
 }
 
 static void
-onInputQueueDestroyed_native(JNIEnv* env, jobject clazz, jint handle, jint queuePtr)
+onInputQueueDestroyed_native(JNIEnv* env, jobject clazz, jlong handle, jlong queuePtr)
 {
     LOG_TRACE("onInputChannelDestroyed_native");
     if (handle != 0) {
@@ -576,7 +576,7 @@
 }
 
 static void
-onContentRectChanged_native(JNIEnv* env, jobject clazz, jint handle,
+onContentRectChanged_native(JNIEnv* env, jobject clazz, jlong handle,
         jint x, jint y, jint w, jint h)
 {
     LOG_TRACE("onContentRectChanged_native");
@@ -594,26 +594,26 @@
 }
 
 static const JNINativeMethod g_methods[] = {
-    { "loadNativeCode", "(Ljava/lang/String;Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILandroid/content/res/AssetManager;[B)I",
+    { "loadNativeCode", "(Ljava/lang/String;Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILandroid/content/res/AssetManager;[B)J",
             (void*)loadNativeCode_native },
-    { "unloadNativeCode", "(I)V", (void*)unloadNativeCode_native },
-    { "onStartNative", "(I)V", (void*)onStart_native },
-    { "onResumeNative", "(I)V", (void*)onResume_native },
-    { "onSaveInstanceStateNative", "(I)[B", (void*)onSaveInstanceState_native },
-    { "onPauseNative", "(I)V", (void*)onPause_native },
-    { "onStopNative", "(I)V", (void*)onStop_native },
-    { "onConfigurationChangedNative", "(I)V", (void*)onConfigurationChanged_native },
-    { "onLowMemoryNative", "(I)V", (void*)onLowMemory_native },
-    { "onWindowFocusChangedNative", "(IZ)V", (void*)onWindowFocusChanged_native },
-    { "onSurfaceCreatedNative", "(ILandroid/view/Surface;)V", (void*)onSurfaceCreated_native },
-    { "onSurfaceChangedNative", "(ILandroid/view/Surface;III)V", (void*)onSurfaceChanged_native },
-    { "onSurfaceRedrawNeededNative", "(ILandroid/view/Surface;)V", (void*)onSurfaceRedrawNeeded_native },
-    { "onSurfaceDestroyedNative", "(I)V", (void*)onSurfaceDestroyed_native },
-    { "onInputQueueCreatedNative", "(II)V",
+    { "unloadNativeCode", "(J)V", (void*)unloadNativeCode_native },
+    { "onStartNative", "(J)V", (void*)onStart_native },
+    { "onResumeNative", "(J)V", (void*)onResume_native },
+    { "onSaveInstanceStateNative", "(J)[B", (void*)onSaveInstanceState_native },
+    { "onPauseNative", "(J)V", (void*)onPause_native },
+    { "onStopNative", "(J)V", (void*)onStop_native },
+    { "onConfigurationChangedNative", "(J)V", (void*)onConfigurationChanged_native },
+    { "onLowMemoryNative", "(J)V", (void*)onLowMemory_native },
+    { "onWindowFocusChangedNative", "(JZ)V", (void*)onWindowFocusChanged_native },
+    { "onSurfaceCreatedNative", "(JLandroid/view/Surface;)V", (void*)onSurfaceCreated_native },
+    { "onSurfaceChangedNative", "(JLandroid/view/Surface;III)V", (void*)onSurfaceChanged_native },
+    { "onSurfaceRedrawNeededNative", "(JLandroid/view/Surface;)V", (void*)onSurfaceRedrawNeeded_native },
+    { "onSurfaceDestroyedNative", "(J)V", (void*)onSurfaceDestroyed_native },
+    { "onInputQueueCreatedNative", "(JJ)V",
         (void*)onInputQueueCreated_native },
-    { "onInputQueueDestroyedNative", "(II)V",
+    { "onInputQueueDestroyedNative", "(JJ)V",
         (void*)onInputQueueDestroyed_native },
-    { "onContentRectChangedNative", "(IIIII)V", (void*)onContentRectChanged_native },
+    { "onContentRectChangedNative", "(JIIII)V", (void*)onContentRectChanged_native },
 };
 
 static const char* const kNativeActivityPathName = "android/app/NativeActivity";
diff --git a/core/jni/android_app_backup_FullBackup.cpp b/core/jni/android_app_backup_FullBackup.cpp
index 2ca645a..3cfaa82 100644
--- a/core/jni/android_app_backup_FullBackup.cpp
+++ b/core/jni/android_app_backup_FullBackup.cpp
@@ -70,7 +70,7 @@
  * path:        absolute path to the file to be saved
  * dataOutput:  the BackupDataOutput object that we're saving into
  */
-static int backupToTar(JNIEnv* env, jobject clazz, jstring packageNameObj,
+static jint backupToTar(JNIEnv* env, jobject clazz, jstring packageNameObj,
         jstring domainObj, jstring linkdomain,
         jstring rootpathObj, jstring pathObj, jobject dataOutputObj) {
     int ret;
@@ -92,22 +92,22 @@
     if (packagenamechars) env->ReleaseStringUTFChars(packageNameObj, packagenamechars);
 
     // Extract the data output fd
-    BackupDataWriter* writer = (BackupDataWriter*) env->GetIntField(dataOutputObj,
+    BackupDataWriter* writer = (BackupDataWriter*) env->GetLongField(dataOutputObj,
             sBackupDataOutput.mBackupWriter);
 
     // Validate
     if (!writer) {
         ALOGE("No output stream provided [%s]", path.string());
-        return -1;
+        return (jint) -1;
     }
 
     if (path.length() < rootpath.length()) {
         ALOGE("file path [%s] shorter than root path [%s]",
                 path.string(), rootpath.string());
-        return -1;
+        return (jint) -1;
     }
 
-    return write_tarfile(packageName, domain, rootpath, path, writer);
+    return (jint) write_tarfile(packageName, domain, rootpath, path, writer);
 }
 
 static const JNINativeMethod g_methods[] = {
@@ -121,7 +121,7 @@
     jclass clazz = env->FindClass("android/app/backup/BackupDataOutput");
     LOG_FATAL_IF(clazz == NULL, "Unable to find class android.app.backup.BackupDataOutput");
 
-    sBackupDataOutput.mBackupWriter = env->GetFieldID(clazz, "mBackupWriter", "I");
+    sBackupDataOutput.mBackupWriter = env->GetFieldID(clazz, "mBackupWriter", "J");
     LOG_FATAL_IF(sBackupDataOutput.mBackupwriter == NULL,
             "Unable to find mBackupWriter field in android.app.backup.BackupDataOutput");
 
diff --git a/core/jni/android_backup_BackupDataInput.cpp b/core/jni/android_backup_BackupDataInput.cpp
index 25b0007..90763b0 100644
--- a/core/jni/android_backup_BackupDataInput.cpp
+++ b/core/jni/android_backup_BackupDataInput.cpp
@@ -29,25 +29,25 @@
 static jfieldID s_keyField = 0;
 static jfieldID s_dataSizeField = 0;
 
-static int
+static jlong
 ctor_native(JNIEnv* env, jobject clazz, jobject fileDescriptor)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
     if (fd == -1) {
-        return NULL;
+        return (jlong)NULL;
     }
 
-    return (int)new BackupDataReader(fd);
+    return (jlong)new BackupDataReader(fd);
 }
 
 static void
-dtor_native(JNIEnv* env, jobject clazz, int r)
+dtor_native(JNIEnv* env, jobject clazz, jlong r)
 {
     delete (BackupDataReader*)r;
 }
 
 static jint
-readNextHeader_native(JNIEnv* env, jobject clazz, int r, jobject entity)
+readNextHeader_native(JNIEnv* env, jobject clazz, jlong r, jobject entity)
 {
     int err;
     bool done;
@@ -89,7 +89,7 @@
 }
 
 static jint
-readEntityData_native(JNIEnv* env, jobject clazz, int r, jbyteArray data, int offset, int size)
+readEntityData_native(JNIEnv* env, jobject clazz, jlong r, jbyteArray data, jint offset, jint size)
 {
     int err;
     BackupDataReader* reader = (BackupDataReader*)r;
@@ -112,7 +112,7 @@
 }
 
 static jint
-skipEntityData_native(JNIEnv* env, jobject clazz, int r)
+skipEntityData_native(JNIEnv* env, jobject clazz, jlong r)
 {
     int err;
     BackupDataReader* reader = (BackupDataReader*)r;
@@ -123,12 +123,12 @@
 }
 
 static const JNINativeMethod g_methods[] = {
-    { "ctor", "(Ljava/io/FileDescriptor;)I", (void*)ctor_native },
-    { "dtor", "(I)V", (void*)dtor_native },
-    { "readNextHeader_native", "(ILandroid/app/backup/BackupDataInput$EntityHeader;)I",
+    { "ctor", "(Ljava/io/FileDescriptor;)J", (void*)ctor_native },
+    { "dtor", "(J)V", (void*)dtor_native },
+    { "readNextHeader_native", "(JLandroid/app/backup/BackupDataInput$EntityHeader;)I",
             (void*)readNextHeader_native },
-    { "readEntityData_native", "(I[BII)I", (void*)readEntityData_native },
-    { "skipEntityData_native", "(I)I", (void*)skipEntityData_native },
+    { "readEntityData_native", "(J[BII)I", (void*)readEntityData_native },
+    { "skipEntityData_native", "(J)I", (void*)skipEntityData_native },
 };
 
 int register_android_backup_BackupDataInput(JNIEnv* env)
diff --git a/core/jni/android_backup_BackupDataOutput.cpp b/core/jni/android_backup_BackupDataOutput.cpp
index e8f0fb8..8244e1b 100644
--- a/core/jni/android_backup_BackupDataOutput.cpp
+++ b/core/jni/android_backup_BackupDataOutput.cpp
@@ -25,25 +25,25 @@
 namespace android
 {
 
-static int
+static jlong
 ctor_native(JNIEnv* env, jobject clazz, jobject fileDescriptor)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
     if (fd == -1) {
-        return NULL;
+        return (jlong)NULL;
     }
 
-    return (int)new BackupDataWriter(fd);
+    return (jlong)new BackupDataWriter(fd);
 }
 
 static void
-dtor_native(JNIEnv* env, jobject clazz, int w)
+dtor_native(JNIEnv* env, jobject clazz, jlong w)
 {
     delete (BackupDataWriter*)w;
 }
 
 static jint
-writeEntityHeader_native(JNIEnv* env, jobject clazz, int w, jstring key, int dataSize)
+writeEntityHeader_native(JNIEnv* env, jobject clazz, jlong w, jstring key, jint dataSize)
 {
     int err;
     BackupDataWriter* writer = (BackupDataWriter*)w;
@@ -56,11 +56,11 @@
 
     env->ReleaseStringUTFChars(key, keyUTF);
 
-    return err;
+    return (jint)err;
 }
 
 static jint
-writeEntityData_native(JNIEnv* env, jobject clazz, int w, jbyteArray data, int size)
+writeEntityData_native(JNIEnv* env, jobject clazz, jlong w, jbyteArray data, jint size)
 {
     int err;
     BackupDataWriter* writer = (BackupDataWriter*)w;
@@ -79,11 +79,11 @@
 
     env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT);
 
-    return err;
+    return (jint)err;
 }
 
 static void
-setKeyPrefix_native(JNIEnv* env, jobject clazz, int w, jstring keyPrefixObj)
+setKeyPrefix_native(JNIEnv* env, jobject clazz, jlong w, jstring keyPrefixObj)
 {
     int err;
     BackupDataWriter* writer = (BackupDataWriter*)w;
@@ -97,11 +97,11 @@
 }
 
 static const JNINativeMethod g_methods[] = {
-    { "ctor", "(Ljava/io/FileDescriptor;)I", (void*)ctor_native },
-    { "dtor", "(I)V", (void*)dtor_native },
-    { "writeEntityHeader_native", "(ILjava/lang/String;I)I", (void*)writeEntityHeader_native },
-    { "writeEntityData_native", "(I[BI)I", (void*)writeEntityData_native },
-    { "setKeyPrefix_native", "(ILjava/lang/String;)V", (void*)setKeyPrefix_native },
+    { "ctor", "(Ljava/io/FileDescriptor;)J", (void*)ctor_native },
+    { "dtor", "(J)V", (void*)dtor_native },
+    { "writeEntityHeader_native", "(JLjava/lang/String;I)I", (void*)writeEntityHeader_native },
+    { "writeEntityData_native", "(J[BI)I", (void*)writeEntityData_native },
+    { "setKeyPrefix_native", "(JLjava/lang/String;)V", (void*)setKeyPrefix_native },
 };
 
 int register_android_backup_BackupDataOutput(JNIEnv* env)
diff --git a/core/jni/android_backup_BackupHelperDispatcher.cpp b/core/jni/android_backup_BackupHelperDispatcher.cpp
index 3e36677..a8b7d44 100644
--- a/core/jni/android_backup_BackupHelperDispatcher.cpp
+++ b/core/jni/android_backup_BackupHelperDispatcher.cpp
@@ -40,7 +40,7 @@
 static jfieldID s_chunkSizeField = 0;
 static jfieldID s_keyPrefixField = 0;
 
-static int
+static jint
 readHeader_native(JNIEnv* env, jobject clazz, jobject headerObj, jobject fdObj)
 {
     chunk_header_v1 flattenedHeader;
@@ -52,7 +52,7 @@
 
     amt = read(fd, &flattenedHeader.headerSize, sizeof(flattenedHeader.headerSize));
     if (amt != sizeof(flattenedHeader.headerSize)) {
-        return -1;
+        return (jint) -1;
     }
 
     int remainingHeader = flattenedHeader.headerSize - sizeof(flattenedHeader.headerSize);
@@ -62,7 +62,7 @@
         if (remainingHeader > 0) {
             lseek(fd, remainingHeader, SEEK_CUR);
             // >0 means skip this chunk
-            return 1;
+            return (jint) 1;
         }
     }
 
@@ -70,7 +70,7 @@
             sizeof(chunk_header_v1)-sizeof(flattenedHeader.headerSize));
     if (amt <= 0) {
         ALOGW("Failed reading chunk header");
-        return -1;
+        return (jint) -1;
     }
     remainingHeader -= sizeof(chunk_header_v1)-sizeof(flattenedHeader.headerSize);
 
@@ -80,7 +80,7 @@
         if (remainingHeader > 0) {
             lseek(fd, remainingHeader, SEEK_CUR);
             // >0 means skip this chunk
-            return 1;
+            return (jint) 1;
         }
     }
 
@@ -96,13 +96,13 @@
             remainingHeader < flattenedHeader.nameLength) {
         ALOGW("Malformed V1 header remainingHeader=%d dataSize=%d nameLength=%d", remainingHeader,
                 flattenedHeader.dataSize, flattenedHeader.nameLength);
-        return -1;
+        return (jint) -1;
     }
 
     buf = keyPrefix.lockBuffer(flattenedHeader.nameLength);
     if (buf == NULL) {
         ALOGW("unable to allocate %d bytes", flattenedHeader.nameLength);
-        return -1;
+        return (jint) -1;
     }
 
     amt = read(fd, buf, flattenedHeader.nameLength);
@@ -119,17 +119,17 @@
     env->SetIntField(headerObj, s_chunkSizeField, flattenedHeader.dataSize);
     env->SetObjectField(headerObj, s_keyPrefixField, env->NewStringUTF(keyPrefix.string()));
 
-    return 0;
+    return (jint) 0;
 }
 
-static int
+static jint
 skipChunk_native(JNIEnv* env, jobject clazz, jobject fdObj, jint bytesToSkip)
 {
     int fd = jniGetFDFromFileDescriptor(env, fdObj);
 
     lseek(fd, bytesToSkip, SEEK_CUR);
 
-    return 0;
+    return (jint) 0;
 }
 
 static int
@@ -139,7 +139,7 @@
     return len == 0 ? len : 4 - len;
 }
 
-static int
+static jint
 allocateHeader_native(JNIEnv* env, jobject clazz, jobject headerObj, jobject fdObj)
 {
     int pos;
@@ -161,10 +161,10 @@
 
     lseek(fd, headerSize, SEEK_CUR);
 
-    return pos;
+    return (jint) pos;
 }
 
-static int
+static jint
 writeHeader_native(JNIEnv* env, jobject clazz, jobject headerObj, jobject fdObj, jint pos)
 {
     int err;
@@ -188,26 +188,26 @@
     lseek(fd, pos, SEEK_SET);
     err = write(fd, &header, sizeof(chunk_header_v1));
     if (err != sizeof(chunk_header_v1)) {
-        return errno;
+        return (jint) errno;
     }
 
     buf = env->GetStringUTFChars(nameObj, NULL);
     err = write(fd, buf, header.nameLength);
     env->ReleaseStringUTFChars(nameObj, buf);
     if (err != header.nameLength) {
-        return errno;
+        return (jint) errno;
     }
 
     if (namePadding != 0) {
         int zero = 0;
         err = write(fd, &zero, namePadding);
         if (err != namePadding) {
-            return errno;
+            return (jint) errno;
         }
     }
 
     lseek(fd, prevPos, SEEK_SET);
-    return 0;
+    return (jint) 0;
 }
 
 static const JNINativeMethod g_methods[] = {
diff --git a/core/jni/android_backup_FileBackupHelperBase.cpp b/core/jni/android_backup_FileBackupHelperBase.cpp
index bb3a751..66e3e9d 100644
--- a/core/jni/android_backup_FileBackupHelperBase.cpp
+++ b/core/jni/android_backup_FileBackupHelperBase.cpp
@@ -25,20 +25,20 @@
 namespace android
 {
 
-static int
+static jlong
 ctor(JNIEnv* env, jobject clazz)
 {
-    return (int)new RestoreHelperBase();
+    return (jlong)new RestoreHelperBase();
 }
 
 static void
-dtor(JNIEnv* env, jobject clazz, jint ptr)
+dtor(JNIEnv* env, jobject clazz, jlong ptr)
 {
     delete (RestoreHelperBase*)ptr;
 }
 
-static int
-performBackup_native(JNIEnv* env, jobject clazz, jobject oldState, int data,
+static jint
+performBackup_native(JNIEnv* env, jobject clazz, jobject oldState, jlong data,
         jobject newState, jobjectArray files, jobjectArray keys)
 {
     int err;
@@ -72,12 +72,12 @@
     }
     free(keysUTF);
 
-    return err;
+    return (jint) err;
 }
 
 
-static int
-writeFile_native(JNIEnv* env, jobject clazz, jint ptr, jstring filenameObj, int backupReaderPtr)
+static jint
+writeFile_native(JNIEnv* env, jobject clazz, jlong ptr, jstring filenameObj, jlong backupReaderPtr)
 {
     int err;
     RestoreHelperBase* restore = (RestoreHelperBase*)ptr;
@@ -90,11 +90,11 @@
 
     env->ReleaseStringUTFChars(filenameObj, filename);
 
-    return err;
+    return (jint) err;
 }
 
-static int
-writeSnapshot_native(JNIEnv* env, jobject clazz, jint ptr, jobject fileDescriptor)
+static jint
+writeSnapshot_native(JNIEnv* env, jobject clazz, jlong ptr, jobject fileDescriptor)
 {
     int err;
 
@@ -103,17 +103,17 @@
 
     err = restore->WriteSnapshot(fd);
 
-    return err;
+    return (jint) err;
 }
 
 static const JNINativeMethod g_methods[] = {
-    { "ctor", "()I", (void*)ctor },
-    { "dtor", "(I)V", (void*)dtor },
+    { "ctor", "()J", (void*)ctor },
+    { "dtor", "(J)V", (void*)dtor },
     { "performBackup_native",
-       "(Ljava/io/FileDescriptor;ILjava/io/FileDescriptor;[Ljava/lang/String;[Ljava/lang/String;)I",
+       "(Ljava/io/FileDescriptor;JLjava/io/FileDescriptor;[Ljava/lang/String;[Ljava/lang/String;)I",
        (void*)performBackup_native },
-    { "writeFile_native", "(ILjava/lang/String;I)I", (void*)writeFile_native },
-    { "writeSnapshot_native", "(ILjava/io/FileDescriptor;)I", (void*)writeSnapshot_native },
+    { "writeFile_native", "(JLjava/lang/String;J)I", (void*)writeFile_native },
+    { "writeSnapshot_native", "(JLjava/io/FileDescriptor;)I", (void*)writeSnapshot_native },
 };
 
 int register_android_backup_FileBackupHelperBase(JNIEnv* env)
diff --git a/core/jni/android_database_CursorWindow.cpp b/core/jni/android_database_CursorWindow.cpp
index ea02f53..67f3879 100644
--- a/core/jni/android_database_CursorWindow.cpp
+++ b/core/jni/android_database_CursorWindow.cpp
@@ -58,7 +58,7 @@
     jniThrowException(env, "java/lang/IllegalStateException", msg.string());
 }
 
-static jint nativeCreate(JNIEnv* env, jclass clazz, jstring nameObj, jint cursorWindowSize) {
+static jlong nativeCreate(JNIEnv* env, jclass clazz, jstring nameObj, jint cursorWindowSize) {
     String8 name;
     const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
     name.setTo(nameStr);
@@ -73,10 +73,10 @@
     }
 
     LOG_WINDOW("nativeInitializeEmpty: window = %p", window);
-    return reinterpret_cast<jint>(window);
+    return reinterpret_cast<jlong>(window);
 }
 
-static jint nativeCreateFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
+static jlong nativeCreateFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj) {
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
 
     CursorWindow* window;
@@ -88,10 +88,10 @@
 
     LOG_WINDOW("nativeInitializeFromBinder: numRows = %d, numColumns = %d, window = %p",
             window->getNumRows(), window->getNumColumns(), window);
-    return reinterpret_cast<jint>(window);
+    return reinterpret_cast<jlong>(window);
 }
 
-static void nativeDispose(JNIEnv* env, jclass clazz, jint windowPtr) {
+static void nativeDispose(JNIEnv* env, jclass clazz, jlong windowPtr) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     if (window) {
         LOG_WINDOW("Closing window %p", window);
@@ -99,12 +99,12 @@
     }
 }
 
-static jstring nativeGetName(JNIEnv* env, jclass clazz, jint windowPtr) {
+static jstring nativeGetName(JNIEnv* env, jclass clazz, jlong windowPtr) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     return env->NewStringUTF(window->name().string());
 }
 
-static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jint windowPtr,
+static void nativeWriteToParcel(JNIEnv * env, jclass clazz, jlong windowPtr,
         jobject parcelObj) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
@@ -117,7 +117,7 @@
     }
 }
 
-static void nativeClear(JNIEnv * env, jclass clazz, jint windowPtr) {
+static void nativeClear(JNIEnv * env, jclass clazz, jlong windowPtr) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("Clearing window %p", window);
     status_t status = window->clear();
@@ -126,30 +126,30 @@
     }
 }
 
-static jint nativeGetNumRows(JNIEnv* env, jclass clazz, jint windowPtr) {
+static jint nativeGetNumRows(JNIEnv* env, jclass clazz, jlong windowPtr) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     return window->getNumRows();
 }
 
-static jboolean nativeSetNumColumns(JNIEnv* env, jclass clazz, jint windowPtr,
+static jboolean nativeSetNumColumns(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint columnNum) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     status_t status = window->setNumColumns(columnNum);
     return status == OK;
 }
 
-static jboolean nativeAllocRow(JNIEnv* env, jclass clazz, jint windowPtr) {
+static jboolean nativeAllocRow(JNIEnv* env, jclass clazz, jlong windowPtr) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     status_t status = window->allocRow();
     return status == OK;
 }
 
-static void nativeFreeLastRow(JNIEnv* env, jclass clazz, jint windowPtr) {
+static void nativeFreeLastRow(JNIEnv* env, jclass clazz, jlong windowPtr) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     window->freeLastRow();
 }
 
-static jint nativeGetType(JNIEnv* env, jclass clazz, jint windowPtr,
+static jint nativeGetType(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("returning column type affinity for %d,%d from %p", row, column, window);
@@ -164,7 +164,7 @@
     return window->getFieldSlotType(fieldSlot);
 }
 
-static jbyteArray nativeGetBlob(JNIEnv* env, jclass clazz, jint windowPtr,
+static jbyteArray nativeGetBlob(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("Getting blob for %d,%d from %p", row, column, window);
@@ -199,7 +199,7 @@
     return NULL;
 }
 
-static jstring nativeGetString(JNIEnv* env, jclass clazz, jint windowPtr,
+static jstring nativeGetString(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("Getting string for %d,%d from %p", row, column, window);
@@ -291,7 +291,7 @@
     }
 }
 
-static void nativeCopyStringToBuffer(JNIEnv* env, jclass clazz, jint windowPtr,
+static void nativeCopyStringToBuffer(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column, jobject bufferObj) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("Copying string for %d,%d from %p", row, column, window);
@@ -330,7 +330,7 @@
     }
 }
 
-static jlong nativeGetLong(JNIEnv* env, jclass clazz, jint windowPtr,
+static jlong nativeGetLong(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("Getting long for %d,%d from %p", row, column, window);
@@ -361,7 +361,7 @@
     }
 }
 
-static jdouble nativeGetDouble(JNIEnv* env, jclass clazz, jint windowPtr,
+static jdouble nativeGetDouble(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     LOG_WINDOW("Getting double for %d,%d from %p", row, column, window);
@@ -392,7 +392,7 @@
     }
 }
 
-static jboolean nativePutBlob(JNIEnv* env, jclass clazz, jint windowPtr,
+static jboolean nativePutBlob(JNIEnv* env, jclass clazz, jlong windowPtr,
         jbyteArray valueObj, jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     jsize len = env->GetArrayLength(valueObj);
@@ -410,7 +410,7 @@
     return true;
 }
 
-static jboolean nativePutString(JNIEnv* env, jclass clazz, jint windowPtr,
+static jboolean nativePutString(JNIEnv* env, jclass clazz, jlong windowPtr,
         jstring valueObj, jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
 
@@ -432,7 +432,7 @@
     return true;
 }
 
-static jboolean nativePutLong(JNIEnv* env, jclass clazz, jint windowPtr,
+static jboolean nativePutLong(JNIEnv* env, jclass clazz, jlong windowPtr,
         jlong value, jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     status_t status = window->putLong(row, column, value);
@@ -446,7 +446,7 @@
     return true;
 }
 
-static jboolean nativePutDouble(JNIEnv* env, jclass clazz, jint windowPtr,
+static jboolean nativePutDouble(JNIEnv* env, jclass clazz, jlong windowPtr,
         jdouble value, jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     status_t status = window->putDouble(row, column, value);
@@ -460,7 +460,7 @@
     return true;
 }
 
-static jboolean nativePutNull(JNIEnv* env, jclass clazz, jint windowPtr,
+static jboolean nativePutNull(JNIEnv* env, jclass clazz, jlong windowPtr,
         jint row, jint column) {
     CursorWindow* window = reinterpret_cast<CursorWindow*>(windowPtr);
     status_t status = window->putNull(row, column);
@@ -477,47 +477,47 @@
 static JNINativeMethod sMethods[] =
 {
     /* name, signature, funcPtr */
-    { "nativeCreate", "(Ljava/lang/String;I)I",
+    { "nativeCreate", "(Ljava/lang/String;I)J",
             (void*)nativeCreate },
-    { "nativeCreateFromParcel", "(Landroid/os/Parcel;)I",
+    { "nativeCreateFromParcel", "(Landroid/os/Parcel;)J",
             (void*)nativeCreateFromParcel },
-    { "nativeDispose", "(I)V",
+    { "nativeDispose", "(J)V",
             (void*)nativeDispose },
-    { "nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
+    { "nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
             (void*)nativeWriteToParcel },
-    { "nativeGetName", "(I)Ljava/lang/String;",
+    { "nativeGetName", "(J)Ljava/lang/String;",
             (void*)nativeGetName },
-    { "nativeClear", "(I)V",
+    { "nativeClear", "(J)V",
             (void*)nativeClear },
-    { "nativeGetNumRows", "(I)I",
+    { "nativeGetNumRows", "(J)I",
             (void*)nativeGetNumRows },
-    { "nativeSetNumColumns", "(II)Z",
+    { "nativeSetNumColumns", "(JI)Z",
             (void*)nativeSetNumColumns },
-    { "nativeAllocRow", "(I)Z",
+    { "nativeAllocRow", "(J)Z",
             (void*)nativeAllocRow },
-    { "nativeFreeLastRow", "(I)V",
+    { "nativeFreeLastRow", "(J)V",
             (void*)nativeFreeLastRow },
-    { "nativeGetType", "(III)I",
+    { "nativeGetType", "(JII)I",
             (void*)nativeGetType },
-    { "nativeGetBlob", "(III)[B",
+    { "nativeGetBlob", "(JII)[B",
             (void*)nativeGetBlob },
-    { "nativeGetString", "(III)Ljava/lang/String;",
+    { "nativeGetString", "(JII)Ljava/lang/String;",
             (void*)nativeGetString },
-    { "nativeGetLong", "(III)J",
+    { "nativeGetLong", "(JII)J",
             (void*)nativeGetLong },
-    { "nativeGetDouble", "(III)D",
+    { "nativeGetDouble", "(JII)D",
             (void*)nativeGetDouble },
-    { "nativeCopyStringToBuffer", "(IIILandroid/database/CharArrayBuffer;)V",
+    { "nativeCopyStringToBuffer", "(JIILandroid/database/CharArrayBuffer;)V",
             (void*)nativeCopyStringToBuffer },
-    { "nativePutBlob", "(I[BII)Z",
+    { "nativePutBlob", "(J[BII)Z",
             (void*)nativePutBlob },
-    { "nativePutString", "(ILjava/lang/String;II)Z",
+    { "nativePutString", "(JLjava/lang/String;II)Z",
             (void*)nativePutString },
-    { "nativePutLong", "(IJII)Z",
+    { "nativePutLong", "(JJII)Z",
             (void*)nativePutLong },
-    { "nativePutDouble", "(IDII)Z",
+    { "nativePutDouble", "(JDII)Z",
             (void*)nativePutDouble },
-    { "nativePutNull", "(III)Z",
+    { "nativePutNull", "(JII)Z",
             (void*)nativePutNull },
 };
 
diff --git a/core/jni/android_database_SQLiteConnection.cpp b/core/jni/android_database_SQLiteConnection.cpp
index 6e496fd..ae56432 100644
--- a/core/jni/android_database_SQLiteConnection.cpp
+++ b/core/jni/android_database_SQLiteConnection.cpp
@@ -109,7 +109,7 @@
 }
 
 
-static jint nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFlags,
+static jlong nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFlags,
         jstring labelStr, jboolean enableTrace, jboolean enableProfile) {
     int sqliteFlags;
     if (openFlags & SQLiteConnection::CREATE_IF_NECESSARY) {
@@ -170,10 +170,10 @@
     }
 
     ALOGV("Opened connection %p with label '%s'", db, label.string());
-    return reinterpret_cast<jint>(connection);
+    return reinterpret_cast<jlong>(connection);
 }
 
-static void nativeClose(JNIEnv* env, jclass clazz, jint connectionPtr) {
+static void nativeClose(JNIEnv* env, jclass clazz, jlong connectionPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
 
     if (connection) {
@@ -243,7 +243,7 @@
     env->DeleteGlobalRef(functionObjGlobal);
 }
 
-static void nativeRegisterCustomFunction(JNIEnv* env, jclass clazz, jint connectionPtr,
+static void nativeRegisterCustomFunction(JNIEnv* env, jclass clazz, jlong connectionPtr,
         jobject functionObj) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
 
@@ -267,7 +267,7 @@
     }
 }
 
-static void nativeRegisterLocalizedCollators(JNIEnv* env, jclass clazz, jint connectionPtr,
+static void nativeRegisterLocalizedCollators(JNIEnv* env, jclass clazz, jlong connectionPtr,
         jstring localeStr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
 
@@ -280,7 +280,7 @@
     }
 }
 
-static jint nativePrepareStatement(JNIEnv* env, jclass clazz, jint connectionPtr,
+static jlong nativePrepareStatement(JNIEnv* env, jclass clazz, jlong connectionPtr,
         jstring sqlString) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
 
@@ -308,11 +308,11 @@
     }
 
     ALOGV("Prepared statement %p on connection %p", statement, connection->db);
-    return reinterpret_cast<jint>(statement);
+    return reinterpret_cast<jlong>(statement);
 }
 
-static void nativeFinalizeStatement(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr) {
+static void nativeFinalizeStatement(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -323,32 +323,32 @@
     sqlite3_finalize(statement);
 }
 
-static jint nativeGetParameterCount(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr) {
+static jint nativeGetParameterCount(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
     return sqlite3_bind_parameter_count(statement);
 }
 
-static jboolean nativeIsReadOnly(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr) {
+static jboolean nativeIsReadOnly(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
     return sqlite3_stmt_readonly(statement) != 0;
 }
 
-static jint nativeGetColumnCount(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr) {
+static jint nativeGetColumnCount(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
     return sqlite3_column_count(statement);
 }
 
-static jstring nativeGetColumnName(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr, jint index) {
+static jstring nativeGetColumnName(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr, jint index) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -363,8 +363,8 @@
     return NULL;
 }
 
-static void nativeBindNull(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr, jint index) {
+static void nativeBindNull(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr, jint index) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -374,8 +374,8 @@
     }
 }
 
-static void nativeBindLong(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr, jint index, jlong value) {
+static void nativeBindLong(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr, jint index, jlong value) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -385,8 +385,8 @@
     }
 }
 
-static void nativeBindDouble(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr, jint index, jdouble value) {
+static void nativeBindDouble(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr, jint index, jdouble value) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -396,8 +396,8 @@
     }
 }
 
-static void nativeBindString(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr, jint index, jstring valueString) {
+static void nativeBindString(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr, jint index, jstring valueString) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -411,8 +411,8 @@
     }
 }
 
-static void nativeBindBlob(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr, jint index, jbyteArray valueArray) {
+static void nativeBindBlob(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr, jint index, jbyteArray valueArray) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -425,8 +425,8 @@
     }
 }
 
-static void nativeResetStatementAndClearBindings(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr) {
+static void nativeResetStatementAndClearBindings(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -450,8 +450,8 @@
     return err;
 }
 
-static void nativeExecute(JNIEnv* env, jclass clazz, jint connectionPtr,
-        jint statementPtr) {
+static void nativeExecute(JNIEnv* env, jclass clazz, jlong connectionPtr,
+        jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -459,7 +459,7 @@
 }
 
 static jint nativeExecuteForChangedRowCount(JNIEnv* env, jclass clazz,
-        jint connectionPtr, jint statementPtr) {
+        jlong connectionPtr, jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -468,7 +468,7 @@
 }
 
 static jlong nativeExecuteForLastInsertedRowId(JNIEnv* env, jclass clazz,
-        jint connectionPtr, jint statementPtr) {
+        jlong connectionPtr, jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -486,7 +486,7 @@
 }
 
 static jlong nativeExecuteForLong(JNIEnv* env, jclass clazz,
-        jint connectionPtr, jint statementPtr) {
+        jlong connectionPtr, jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -498,7 +498,7 @@
 }
 
 static jstring nativeExecuteForString(JNIEnv* env, jclass clazz,
-        jint connectionPtr, jint statementPtr) {
+        jlong connectionPtr, jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -548,7 +548,7 @@
 }
 
 static jint nativeExecuteForBlobFileDescriptor(JNIEnv* env, jclass clazz,
-        jint connectionPtr, jint statementPtr) {
+        jlong connectionPtr, jlong statementPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
 
@@ -665,7 +665,7 @@
 }
 
 static jlong nativeExecuteForCursorWindow(JNIEnv* env, jclass clazz,
-        jint connectionPtr, jint statementPtr, jint windowPtr,
+        jlong connectionPtr, jlong statementPtr, jlong windowPtr,
         jint startPos, jint requiredPos, jboolean countAllRows) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     sqlite3_stmt* statement = reinterpret_cast<sqlite3_stmt*>(statementPtr);
@@ -760,7 +760,7 @@
     return result;
 }
 
-static jint nativeGetDbLookaside(JNIEnv* env, jobject clazz, jint connectionPtr) {
+static jint nativeGetDbLookaside(JNIEnv* env, jobject clazz, jlong connectionPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
 
     int cur = -1;
@@ -769,12 +769,12 @@
     return cur;
 }
 
-static void nativeCancel(JNIEnv* env, jobject clazz, jint connectionPtr) {
+static void nativeCancel(JNIEnv* env, jobject clazz, jlong connectionPtr) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     connection->canceled = true;
 }
 
-static void nativeResetCancel(JNIEnv* env, jobject clazz, jint connectionPtr,
+static void nativeResetCancel(JNIEnv* env, jobject clazz, jlong connectionPtr,
         jboolean cancelable) {
     SQLiteConnection* connection = reinterpret_cast<SQLiteConnection*>(connectionPtr);
     connection->canceled = false;
@@ -791,57 +791,57 @@
 static JNINativeMethod sMethods[] =
 {
     /* name, signature, funcPtr */
-    { "nativeOpen", "(Ljava/lang/String;ILjava/lang/String;ZZ)I",
+    { "nativeOpen", "(Ljava/lang/String;ILjava/lang/String;ZZ)J",
             (void*)nativeOpen },
-    { "nativeClose", "(I)V",
+    { "nativeClose", "(J)V",
             (void*)nativeClose },
-    { "nativeRegisterCustomFunction", "(ILandroid/database/sqlite/SQLiteCustomFunction;)V",
+    { "nativeRegisterCustomFunction", "(JLandroid/database/sqlite/SQLiteCustomFunction;)V",
             (void*)nativeRegisterCustomFunction },
-    { "nativeRegisterLocalizedCollators", "(ILjava/lang/String;)V",
+    { "nativeRegisterLocalizedCollators", "(JLjava/lang/String;)V",
             (void*)nativeRegisterLocalizedCollators },
-    { "nativePrepareStatement", "(ILjava/lang/String;)I",
+    { "nativePrepareStatement", "(JLjava/lang/String;)J",
             (void*)nativePrepareStatement },
-    { "nativeFinalizeStatement", "(II)V",
+    { "nativeFinalizeStatement", "(JJ)V",
             (void*)nativeFinalizeStatement },
-    { "nativeGetParameterCount", "(II)I",
+    { "nativeGetParameterCount", "(JJ)I",
             (void*)nativeGetParameterCount },
-    { "nativeIsReadOnly", "(II)Z",
+    { "nativeIsReadOnly", "(JJ)Z",
             (void*)nativeIsReadOnly },
-    { "nativeGetColumnCount", "(II)I",
+    { "nativeGetColumnCount", "(JJ)I",
             (void*)nativeGetColumnCount },
-    { "nativeGetColumnName", "(III)Ljava/lang/String;",
+    { "nativeGetColumnName", "(JJI)Ljava/lang/String;",
             (void*)nativeGetColumnName },
-    { "nativeBindNull", "(III)V",
+    { "nativeBindNull", "(JJI)V",
             (void*)nativeBindNull },
-    { "nativeBindLong", "(IIIJ)V",
+    { "nativeBindLong", "(JJIJ)V",
             (void*)nativeBindLong },
-    { "nativeBindDouble", "(IIID)V",
+    { "nativeBindDouble", "(JJID)V",
             (void*)nativeBindDouble },
-    { "nativeBindString", "(IIILjava/lang/String;)V",
+    { "nativeBindString", "(JJILjava/lang/String;)V",
             (void*)nativeBindString },
-    { "nativeBindBlob", "(III[B)V",
+    { "nativeBindBlob", "(JJI[B)V",
             (void*)nativeBindBlob },
-    { "nativeResetStatementAndClearBindings", "(II)V",
+    { "nativeResetStatementAndClearBindings", "(JJ)V",
             (void*)nativeResetStatementAndClearBindings },
-    { "nativeExecute", "(II)V",
+    { "nativeExecute", "(JJ)V",
             (void*)nativeExecute },
-    { "nativeExecuteForLong", "(II)J",
+    { "nativeExecuteForLong", "(JJ)J",
             (void*)nativeExecuteForLong },
-    { "nativeExecuteForString", "(II)Ljava/lang/String;",
+    { "nativeExecuteForString", "(JJ)Ljava/lang/String;",
             (void*)nativeExecuteForString },
-    { "nativeExecuteForBlobFileDescriptor", "(II)I",
+    { "nativeExecuteForBlobFileDescriptor", "(JJ)I",
             (void*)nativeExecuteForBlobFileDescriptor },
-    { "nativeExecuteForChangedRowCount", "(II)I",
+    { "nativeExecuteForChangedRowCount", "(JJ)I",
             (void*)nativeExecuteForChangedRowCount },
-    { "nativeExecuteForLastInsertedRowId", "(II)J",
+    { "nativeExecuteForLastInsertedRowId", "(JJ)J",
             (void*)nativeExecuteForLastInsertedRowId },
-    { "nativeExecuteForCursorWindow", "(IIIIIZ)J",
+    { "nativeExecuteForCursorWindow", "(JJJIIZ)J",
             (void*)nativeExecuteForCursorWindow },
-    { "nativeGetDbLookaside", "(I)I",
+    { "nativeGetDbLookaside", "(J)I",
             (void*)nativeGetDbLookaside },
-    { "nativeCancel", "(I)V",
+    { "nativeCancel", "(J)V",
             (void*)nativeCancel },
-    { "nativeResetCancel", "(IZ)V",
+    { "nativeResetCancel", "(JZ)V",
             (void*)nativeResetCancel },
 };
 
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index 09d8d0f..58b61ba 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -113,7 +113,7 @@
 {
     sp<Camera> camera;
     Mutex::Autolock _l(sLock);
-    JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context));
+    JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
     if (context != NULL) {
         camera = context->getCamera();
     }
@@ -500,7 +500,7 @@
     camera->setListener(context);
 
     // save context in opaque field
-    env->SetIntField(thiz, fields.context, (int)context.get());
+    env->SetLongField(thiz, fields.context, (jlong)context.get());
 }
 
 // disconnect from camera service
@@ -515,10 +515,10 @@
     sp<Camera> camera;
     {
         Mutex::Autolock _l(sLock);
-        context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context));
+        context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
 
         // Make sure we do not attempt to callback on a deleted Java object.
-        env->SetIntField(thiz, fields.context, 0);
+        env->SetLongField(thiz, fields.context, 0);
     }
 
     // clean up if release has not been called before
@@ -627,13 +627,13 @@
     c->stopPreview();
 }
 
-static bool android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz)
+static jboolean android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz)
 {
     ALOGV("previewEnabled");
     sp<Camera> c = get_native_camera(env, thiz, NULL);
-    if (c == 0) return false;
+    if (c == 0) return JNI_FALSE;
 
-    return c->previewEnabled();
+    return c->previewEnabled() ? JNI_TRUE : JNI_FALSE;
 }
 
 static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer)
@@ -651,10 +651,10 @@
     context->setCallbackMode(env, installed, manualBuffer);
 }
 
-static void android_hardware_Camera_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, int msgType) {
+static void android_hardware_Camera_addCallbackBuffer(JNIEnv *env, jobject thiz, jbyteArray bytes, jint msgType) {
     ALOGV("addCallbackBuffer: 0x%x", msgType);
 
-    JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetIntField(thiz, fields.context));
+    JNICameraContext* context = reinterpret_cast<JNICameraContext*>(env->GetLongField(thiz, fields.context));
 
     if (context != NULL) {
         context->addCallbackBuffer(env, bytes, msgType);
@@ -685,7 +685,7 @@
     }
 }
 
-static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz, int msgType)
+static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz, jint msgType)
 {
     ALOGV("takePicture");
     JNICameraContext* context;
@@ -999,7 +999,7 @@
 int register_android_hardware_Camera(JNIEnv *env)
 {
     field fields_to_find[] = {
-        { "android/hardware/Camera", "mNativeContext",   "I", &fields.context },
+        { "android/hardware/Camera", "mNativeContext",   "J", &fields.context },
         { "android/hardware/Camera$CameraInfo", "facing",   "I", &fields.facing },
         { "android/hardware/Camera$CameraInfo", "orientation",   "I", &fields.orientation },
         { "android/hardware/Camera$CameraInfo", "canDisableShutterSound",   "Z",
diff --git a/core/jni/android_hardware_SensorManager.cpp b/core/jni/android_hardware_SensorManager.cpp
index 793d1bf..24e0b0a 100644
--- a/core/jni/android_hardware_SensorManager.cpp
+++ b/core/jni/android_hardware_SensorManager.cpp
@@ -187,7 +187,7 @@
     }
 };
 
-static jint nativeInitSensorEventQueue(JNIEnv *env, jclass clazz, jobject eventQ, jobject msgQ, jfloatArray scratch) {
+static jlong nativeInitSensorEventQueue(JNIEnv *env, jclass clazz, jobject eventQ, jobject msgQ, jfloatArray scratch) {
     SensorManager& mgr(SensorManager::getInstance());
     sp<SensorEventQueue> queue(mgr.createEventQueue());
 
@@ -199,28 +199,28 @@
 
     sp<Receiver> receiver = new Receiver(queue, messageQueue, eventQ, scratch);
     receiver->incStrong((void*)nativeInitSensorEventQueue);
-    return jint(receiver.get());
+    return jlong(receiver.get());
 }
 
-static jint nativeEnableSensor(JNIEnv *env, jclass clazz, jint eventQ, jint handle, jint rate_us,
+static jint nativeEnableSensor(JNIEnv *env, jclass clazz, jlong eventQ, jint handle, jint rate_us,
                                jint maxBatchReportLatency, jint reservedFlags) {
     sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ));
     return receiver->getSensorEventQueue()->enableSensor(handle, rate_us, maxBatchReportLatency,
                                                          reservedFlags);
 }
 
-static jint nativeDisableSensor(JNIEnv *env, jclass clazz, jint eventQ, jint handle) {
+static jint nativeDisableSensor(JNIEnv *env, jclass clazz, jlong eventQ, jint handle) {
     sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ));
     return receiver->getSensorEventQueue()->disableSensor(handle);
 }
 
-static void nativeDestroySensorEventQueue(JNIEnv *env, jclass clazz, jint eventQ, jint handle) {
+static void nativeDestroySensorEventQueue(JNIEnv *env, jclass clazz, jlong eventQ, jint handle) {
     sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ));
     receiver->destroy();
     receiver->decStrong((void*)nativeInitSensorEventQueue);
 }
 
-static jint nativeFlushSensor(JNIEnv *env, jclass clazz, jint eventQ) {
+static jint nativeFlushSensor(JNIEnv *env, jclass clazz, jlong eventQ) {
     sp<Receiver> receiver(reinterpret_cast<Receiver *>(eventQ));
     return receiver->getSensorEventQueue()->flush();
 }
@@ -239,23 +239,23 @@
 
 static JNINativeMethod gBaseEventQueueMethods[] = {
     {"nativeInitBaseEventQueue",
-            "(Landroid/hardware/SystemSensorManager$BaseEventQueue;Landroid/os/MessageQueue;[F)I",
+            "(Landroid/hardware/SystemSensorManager$BaseEventQueue;Landroid/os/MessageQueue;[F)J",
             (void*)nativeInitSensorEventQueue },
 
     {"nativeEnableSensor",
-            "(IIIII)I",
+            "(JIIII)I",
             (void*)nativeEnableSensor },
 
     {"nativeDisableSensor",
-            "(II)I",
+            "(JI)I",
             (void*)nativeDisableSensor },
 
     {"nativeDestroySensorEventQueue",
-            "(I)V",
+            "(J)V",
             (void*)nativeDestroySensorEventQueue },
 
     {"nativeFlushSensor",
-            "(I)I",
+            "(J)I",
             (void*)nativeFlushSensor },
 };
 
diff --git a/core/jni/android_hardware_UsbDeviceConnection.cpp b/core/jni/android_hardware_UsbDeviceConnection.cpp
index cea5bbf..c10b963f 100644
--- a/core/jni/android_hardware_UsbDeviceConnection.cpp
+++ b/core/jni/android_hardware_UsbDeviceConnection.cpp
@@ -35,7 +35,7 @@
 
 struct usb_device* get_device_from_object(JNIEnv* env, jobject connection)
 {
-    return (struct usb_device*)env->GetIntField(connection, field_context);
+    return (struct usb_device*)env->GetLongField(connection, field_context);
 }
 
 static jboolean
@@ -46,19 +46,19 @@
     // duplicate the file descriptor, since ParcelFileDescriptor will eventually close its copy
     fd = dup(fd);
     if (fd < 0)
-        return false;
+        return JNI_FALSE;
 
     const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
     struct usb_device* device = usb_device_new(deviceNameStr, fd);
     if (device) {
-        env->SetIntField(thiz, field_context, (int)device);
+        env->SetLongField(thiz, field_context, (jlong)device);
     } else {
         ALOGE("usb_device_open failed for %s", deviceNameStr);
         close(fd);
     }
 
     env->ReleaseStringUTFChars(deviceName, deviceNameStr);
-    return (device != NULL);
+    return (device != NULL) ? JNI_TRUE : JNI_FALSE;
 }
 
 static void
@@ -68,7 +68,7 @@
     struct usb_device* device = get_device_from_object(env, thiz);
     if (device) {
         usb_device_close(device);
-        env->SetIntField(thiz, field_context, 0);
+        env->SetLongField(thiz, field_context, 0);
     }
 }
 
@@ -106,12 +106,12 @@
 
 static jboolean
 android_hardware_UsbDeviceConnection_claim_interface(JNIEnv *env, jobject thiz,
-        int interfaceID, jboolean force)
+        jint interfaceID, jboolean force)
 {
     struct usb_device* device = get_device_from_object(env, thiz);
     if (!device) {
         ALOGE("device is closed in native_claim_interface");
-        return -1;
+        return JNI_FALSE;
     }
 
     int ret = usb_device_claim_interface(device, interfaceID);
@@ -120,11 +120,11 @@
         usb_device_connect_kernel_driver(device, interfaceID, false);
         ret = usb_device_claim_interface(device, interfaceID);
     }
-    return ret == 0;
+    return (ret == 0) ? JNI_TRUE : JNI_FALSE;
 }
 
 static jint
-android_hardware_UsbDeviceConnection_release_interface(JNIEnv *env, jobject thiz, int interfaceID)
+android_hardware_UsbDeviceConnection_release_interface(JNIEnv *env, jobject thiz, jint interfaceID)
 {
     struct usb_device* device = get_device_from_object(env, thiz);
     if (!device) {
@@ -246,7 +246,7 @@
         ALOGE("Can't find android/hardware/usb/UsbDeviceConnection");
         return -1;
     }
-    field_context = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_context == NULL) {
         ALOGE("Can't find UsbDeviceConnection.mNativeContext");
         return -1;
diff --git a/core/jni/android_hardware_UsbRequest.cpp b/core/jni/android_hardware_UsbRequest.cpp
index 32d5135..01eaec4 100644
--- a/core/jni/android_hardware_UsbRequest.cpp
+++ b/core/jni/android_hardware_UsbRequest.cpp
@@ -32,7 +32,7 @@
 
 struct usb_request* get_request_from_object(JNIEnv* env, jobject java_request)
 {
-    return (struct usb_request*)env->GetIntField(java_request, field_context);
+    return (struct usb_request*)env->GetLongField(java_request, field_context);
 }
 
 // in android_hardware_UsbDeviceConnection.cpp
@@ -61,7 +61,7 @@
 
     struct usb_request* request = usb_request_new(device, &desc);
     if (request)
-        env->SetIntField(thiz, field_context, (int)request);
+        env->SetLongField(thiz, field_context, (jlong)request);
     return (request != NULL);
 }
 
@@ -72,7 +72,7 @@
     struct usb_request* request = get_request_from_object(env, thiz);
     if (request) {
         usb_request_free(request);
-        env->SetIntField(thiz, field_context, 0);
+        env->SetLongField(thiz, field_context, 0);
     }
 }
 
@@ -114,14 +114,14 @@
     }
 }
 
-static int
+static jint
 android_hardware_UsbRequest_dequeue_array(JNIEnv *env, jobject thiz,
         jbyteArray buffer, jint length, jboolean out)
 {
     struct usb_request* request = get_request_from_object(env, thiz);
     if (!request) {
         ALOGE("request is closed in native_dequeue");
-        return -1;
+        return (jint) -1;
     }
 
     if (buffer && length && request->buffer && !out) {
@@ -130,7 +130,7 @@
     }
     free(request->buffer);
     env->DeleteGlobalRef((jobject)request->client_data);
-    return request->actual_length;
+    return (jint) request->actual_length;
 }
 
 static jboolean
@@ -164,17 +164,17 @@
     }
 }
 
-static int
+static jint
 android_hardware_UsbRequest_dequeue_direct(JNIEnv *env, jobject thiz)
 {
     struct usb_request* request = get_request_from_object(env, thiz);
     if (!request) {
         ALOGE("request is closed in native_dequeue");
-        return -1;
+        return (jint) -1;
     }
     // all we need to do is delete our global ref
     env->DeleteGlobalRef((jobject)request->client_data);
-    return request->actual_length;
+    return (jint) request->actual_length;
 }
 
 static jboolean
@@ -207,7 +207,7 @@
         ALOGE("Can't find android/hardware/usb/UsbRequest");
         return -1;
     }
-    field_context = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_context == NULL) {
         ALOGE("Can't find UsbRequest.mNativeContext");
         return -1;
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 1c43cc5..b22668b 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -136,7 +136,7 @@
 {
     Mutex::Autolock l(sLock);
     AudioRecord* const ar =
-            (AudioRecord*)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
+            (AudioRecord*)env->GetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
     return sp<AudioRecord>(ar);
 }
 
@@ -144,19 +144,19 @@
 {
     Mutex::Autolock l(sLock);
     sp<AudioRecord> old =
-            (AudioRecord*)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
+            (AudioRecord*)env->GetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
     if (ar.get()) {
         ar->incStrong((void*)setAudioRecord);
     }
     if (old != 0) {
         old->decStrong((void*)setAudioRecord);
     }
-    env->SetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (int)ar.get());
+    env->SetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (jlong)ar.get());
     return old;
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         jint source, jint sampleRateInHertz, jint channelMask,
                 // Java channel masks map directly to the native definition
@@ -168,7 +168,7 @@
 
     if (!audio_is_input_channel(channelMask)) {
         ALOGE("Error creating AudioRecord: channel mask %#x is not valid.", channelMask);
-        return AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
     }
     uint32_t nbChannels = popcount(channelMask);
 
@@ -176,7 +176,7 @@
     if ((audioFormat != ENCODING_PCM_16BIT)
         && (audioFormat != ENCODING_PCM_8BIT)) {
         ALOGE("Error creating AudioRecord: unsupported audio format.");
-        return AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
     }
 
     int bytesPerSample = audioFormat == ENCODING_PCM_16BIT ? 2 : 1;
@@ -185,31 +185,31 @@
 
     if (buffSizeInBytes == 0) {
          ALOGE("Error creating AudioRecord: frameCount is 0.");
-        return AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
+        return (jint) AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
     }
     int frameSize = nbChannels * bytesPerSample;
     size_t frameCount = buffSizeInBytes / frameSize;
 
     if ((uint32_t(source) >= AUDIO_SOURCE_CNT) && (uint32_t(source) != AUDIO_SOURCE_HOTWORD)) {
         ALOGE("Error creating AudioRecord: unknown source.");
-        return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
     }
 
     jclass clazz = env->GetObjectClass(thiz);
     if (clazz == NULL) {
         ALOGE("Can't find %s when setting up callback.", kClassPathName);
-        return AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
+        return (jint) AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
     }
 
     if (jSession == NULL) {
         ALOGE("Error creating AudioRecord: invalid session ID pointer");
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
 
     jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
     if (nSession == NULL) {
         ALOGE("Error creating AudioRecord: Error retrieving session id pointer");
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
     int sessionId = nSession[0];
     env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
@@ -262,33 +262,33 @@
 
     // save our newly created callback information in the "nativeCallbackCookie" field
     // of the Java object (in mNativeCallbackCookie) so we can free the memory in finalize()
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, (int)lpCallbackData);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, (jlong)lpCallbackData);
 
-    return AUDIORECORD_SUCCESS;
+    return (jint) AUDIORECORD_SUCCESS;
 
     // failure:
 native_init_failure:
     env->DeleteGlobalRef(lpCallbackData->audioRecord_class);
     env->DeleteGlobalRef(lpCallbackData->audioRecord_ref);
     delete lpCallbackData;
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
 
-    return AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
+    return (jint) AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
 }
 
 
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioRecord_start(JNIEnv *env, jobject thiz, jint event, jint triggerSession)
 {
     sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);
     if (lpRecorder == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
 
-    return android_media_translateRecorderErrorCode(
+    return (jint) android_media_translateRecorderErrorCode(
             lpRecorder->start((AudioSystem::sync_event_t)event, triggerSession));
 }
 
@@ -319,12 +319,12 @@
     ALOGV("About to delete lpRecorder: %x\n", (int)lpRecorder.get());
     lpRecorder->stop();
 
-    audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetIntField(
+    audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetLongField(
         thiz, javaAudioRecordFields.nativeCallbackCookie);
 
     // reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
 
     // delete the callback information
     if (lpCookie) {
@@ -585,7 +585,7 @@
     //    mNativeRecorderInJavaObj
     javaAudioRecordFields.nativeRecorderInJavaObj =
         env->GetFieldID(audioRecordClass,
-                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "I");
+                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J");
     if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
         ALOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
         return -1;
@@ -593,7 +593,7 @@
     //     mNativeCallbackCookie
     javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID(
             audioRecordClass,
-            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "I");
+            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J");
     if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
         ALOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 7d99464..a19d111 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -52,10 +52,10 @@
     return kAudioStatusError;
 }
 
-static int
+static jint
 android_media_AudioSystem_muteMicrophone(JNIEnv *env, jobject thiz, jboolean on)
 {
-    return check_AudioSystem_Command(AudioSystem::muteMicrophone(on));
+    return (jint) check_AudioSystem_Command(AudioSystem::muteMicrophone(on));
 }
 
 static jboolean
@@ -91,7 +91,7 @@
     return state;
 }
 
-static int
+static jint
 android_media_AudioSystem_setParameters(JNIEnv *env, jobject thiz, jstring keyValuePairs)
 {
     const jchar* c_keyValuePairs = env->GetStringCritical(keyValuePairs, 0);
@@ -101,7 +101,7 @@
         env->ReleaseStringCritical(keyValuePairs, c_keyValuePairs);
     }
     int status = check_AudioSystem_Command(AudioSystem::setParameters(0, c_keyValuePairs8));
-    return status;
+    return (jint) status;
 }
 
 static jstring
@@ -131,7 +131,7 @@
                               check_AudioSystem_Command(err));
 }
 
-static int
+static jint
 android_media_AudioSystem_setDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jint state, jstring device_address)
 {
     const char *c_address = env->GetStringUTFChars(device_address, NULL);
@@ -139,60 +139,60 @@
                                           static_cast <audio_policy_dev_state_t>(state),
                                           c_address));
     env->ReleaseStringUTFChars(device_address, c_address);
-    return status;
+    return (jint) status;
 }
 
-static int
+static jint
 android_media_AudioSystem_getDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jstring device_address)
 {
     const char *c_address = env->GetStringUTFChars(device_address, NULL);
     int state = static_cast <int>(AudioSystem::getDeviceConnectionState(static_cast <audio_devices_t>(device),
                                           c_address));
     env->ReleaseStringUTFChars(device_address, c_address);
-    return state;
+    return (jint) state;
 }
 
-static int
+static jint
 android_media_AudioSystem_setPhoneState(JNIEnv *env, jobject thiz, jint state)
 {
-    return check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state));
+    return (jint) check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state));
 }
 
-static int
+static jint
 android_media_AudioSystem_setForceUse(JNIEnv *env, jobject thiz, jint usage, jint config)
 {
-    return check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
+    return (jint) check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
                                                            static_cast <audio_policy_forced_cfg_t>(config)));
 }
 
-static int
+static jint
 android_media_AudioSystem_getForceUse(JNIEnv *env, jobject thiz, jint usage)
 {
-    return static_cast <int>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
+    return static_cast <jint>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
 }
 
-static int
+static jint
 android_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint stream, jint indexMin, jint indexMax)
 {
-    return check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
+    return (jint) check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
                                                                    indexMin,
                                                                    indexMax));
 }
 
-static int
+static jint
 android_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env,
                                                jobject thiz,
                                                jint stream,
                                                jint index,
                                                jint device)
 {
-    return check_AudioSystem_Command(
+    return (jint) check_AudioSystem_Command(
             AudioSystem::setStreamVolumeIndex(static_cast <audio_stream_type_t>(stream),
                                               index,
                                               (audio_devices_t)device));
 }
 
-static int
+static jint
 android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env,
                                                jobject thiz,
                                                jint stream,
@@ -205,13 +205,13 @@
             != NO_ERROR) {
         index = -1;
     }
-    return index;
+    return (jint) index;
 }
 
-static int
+static jint
 android_media_AudioSystem_setMasterVolume(JNIEnv *env, jobject thiz, jfloat value)
 {
-    return check_AudioSystem_Command(AudioSystem::setMasterVolume(value));
+    return (jint) check_AudioSystem_Command(AudioSystem::setMasterVolume(value));
 }
 
 static jfloat
@@ -224,10 +224,10 @@
     return value;
 }
 
-static int
+static jint
 android_media_AudioSystem_setMasterMute(JNIEnv *env, jobject thiz, jboolean mute)
 {
-    return check_AudioSystem_Command(AudioSystem::setMasterMute(mute));
+    return (jint) check_AudioSystem_Command(AudioSystem::setMasterMute(mute));
 }
 
 static jfloat
@@ -275,10 +275,10 @@
     return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice);
 }
 
-static int
+static jint
 android_media_AudioSystem_checkAudioFlinger(JNIEnv *env, jobject clazz)
 {
-    return check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
+    return (jint) check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
 }
 
 // ----------------------------------------------------------------------------
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 225bf06..dc8d9d8 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -174,7 +174,7 @@
 {
     Mutex::Autolock l(sLock);
     AudioTrack* const at =
-            (AudioTrack*)env->GetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
+            (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
     return sp<AudioTrack>(at);
 }
 
@@ -182,19 +182,19 @@
 {
     Mutex::Autolock l(sLock);
     sp<AudioTrack> old =
-            (AudioTrack*)env->GetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
+            (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
     if (at.get()) {
         at->incStrong((void*)setAudioTrack);
     }
     if (old != 0) {
         old->decStrong((void*)setAudioTrack);
     }
-    env->SetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (int)at.get());
+    env->SetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (jlong)at.get());
     return old;
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         jint streamType, jint sampleRateInHertz, jint javaChannelMask,
         jint audioFormat, jint buffSizeInBytes, jint memoryMode, jintArray jSession)
@@ -206,11 +206,11 @@
 
     if (AudioSystem::getOutputFrameCount(&afFrameCount, (audio_stream_type_t) streamType) != NO_ERROR) {
         ALOGE("Error creating AudioTrack: Could not get AudioSystem frame count.");
-        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
+        return (jint) AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
     }
     if (AudioSystem::getOutputSamplingRate(&afSampleRate, (audio_stream_type_t) streamType) != NO_ERROR) {
         ALOGE("Error creating AudioTrack: Could not get AudioSystem sampling rate.");
-        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
+        return (jint) AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
     }
 
     // Java channel masks don't map directly to the native definition, but it's a simple shift
@@ -219,7 +219,7 @@
 
     if (!audio_is_output_channel(nativeChannelMask)) {
         ALOGE("Error creating AudioTrack: invalid channel mask %#x.", javaChannelMask);
-        return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
     }
 
     int nbChannels = popcount(nativeChannelMask);
@@ -239,7 +239,7 @@
         break;
     default:
         ALOGE("Error creating AudioTrack: unknown stream type.");
-        return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
     }
 
     // check the format.
@@ -247,7 +247,7 @@
     if ((audioFormat != ENCODING_PCM_16BIT) && (audioFormat != ENCODING_PCM_8BIT)) {
 
         ALOGE("Error creating AudioTrack: unsupported audio format.");
-        return AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
     }
 
     // for the moment 8bitPCM in MODE_STATIC is not supported natively in the AudioTrack C++ class
@@ -272,18 +272,18 @@
     jclass clazz = env->GetObjectClass(thiz);
     if (clazz == NULL) {
         ALOGE("Can't find %s when setting up callback.", kClassPathName);
-        return AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
+        return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
     }
 
     if (jSession == NULL) {
         ALOGE("Error creating AudioTrack: invalid session ID pointer");
-        return AUDIOTRACK_ERROR;
+        return (jint) AUDIOTRACK_ERROR;
     }
 
     jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
     if (nSession == NULL) {
         ALOGE("Error creating AudioTrack: Error retrieving session id pointer");
-        return AUDIOTRACK_ERROR;
+        return (jint) AUDIOTRACK_ERROR;
     }
     int sessionId = nSession[0];
     env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
@@ -370,10 +370,10 @@
     setAudioTrack(env, thiz, lpTrack);
 
     // save the JNI resources so we can free them later
-    //ALOGV("storing lpJniStorage: %x\n", (int)lpJniStorage);
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, (int)lpJniStorage);
+    //ALOGV("storing lpJniStorage: %x\n", (long)lpJniStorage);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, (jlong)lpJniStorage);
 
-    return AUDIOTRACK_SUCCESS;
+    return (jint) AUDIOTRACK_SUCCESS;
 
     // failures:
 native_init_failure:
@@ -383,9 +383,9 @@
     env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_class);
     env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_ref);
     delete lpJniStorage;
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, 0);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, 0);
 
-    return AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
+    return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
 }
 
 
@@ -474,11 +474,11 @@
     lpTrack->stop();
 
     // delete the JNI data
-    AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetIntField(
+    AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetLongField(
         thiz, javaAudioTrackFields.jniData);
     // reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, 0);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, 0);
 
     if (pJniStorage) {
         Mutex::Autolock l(sLock);
@@ -955,7 +955,7 @@
     //      nativeTrackInJavaObj
     javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID(
             audioTrackClass,
-            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "I");
+            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J");
     if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
         ALOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
         return -1;
@@ -963,7 +963,7 @@
     //      jniData;
     javaAudioTrackFields.jniData = env->GetFieldID(
             audioTrackClass,
-            JAVA_JNIDATA_FIELD_NAME, "I");
+            JAVA_JNIDATA_FIELD_NAME, "J");
     if (javaAudioTrackFields.jniData == NULL) {
         ALOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_JetPlayer.cpp b/core/jni/android_media_JetPlayer.cpp
index 5795aba..69f5711 100644
--- a/core/jni/android_media_JetPlayer.cpp
+++ b/core/jni/android_media_JetPlayer.cpp
@@ -87,12 +87,12 @@
     if (result==EAS_SUCCESS) {
         // save our newly created C++ JetPlayer in the "nativePlayerInJavaObj" field
         // of the Java object (in mNativePlayerInJavaObj)
-        env->SetIntField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, (int)lpJet);
+        env->SetLongField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, (jlong)lpJet);
         return JNI_TRUE;
     } else {
         ALOGE("android_media_JetPlayer_setup(): initialization failed with EAS error code %d", (int)result);
         delete lpJet;
-        env->SetIntField(weak_this, javaJetPlayerFields.nativePlayerInJavaObj, 0);
+        env->SetLongField(weak_this, javaJetPlayerFields.nativePlayerInJavaObj, 0);
         return JNI_FALSE;
     }
 }
@@ -103,7 +103,7 @@
 android_media_JetPlayer_finalize(JNIEnv *env, jobject thiz)
 {
     ALOGV("android_media_JetPlayer_finalize(): entering.");
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet != NULL) {
         lpJet->release();
@@ -119,7 +119,7 @@
 android_media_JetPlayer_release(JNIEnv *env, jobject thiz)
 {
     android_media_JetPlayer_finalize(env, thiz);
-    env->SetIntField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, 0);
+    env->SetLongField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, 0);
     ALOGV("android_media_JetPlayer_release() done");
 }
 
@@ -128,7 +128,7 @@
 static jboolean
 android_media_JetPlayer_loadFromFile(JNIEnv *env, jobject thiz, jstring path)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -165,7 +165,7 @@
 android_media_JetPlayer_loadFromFileD(JNIEnv *env, jobject thiz,
     jobject fileDescriptor, jlong offset, jlong length)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -195,7 +195,7 @@
 static jboolean
 android_media_JetPlayer_closeFile(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -217,7 +217,7 @@
 static jboolean
 android_media_JetPlayer_play(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -241,7 +241,7 @@
 static jboolean
 android_media_JetPlayer_pause(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -271,7 +271,7 @@
         jint segmentNum, jint libNum, jint repeatCount, jint transpose, jint muteFlags,
         jbyte userID)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -298,7 +298,7 @@
         jint segmentNum, jint libNum, jint repeatCount, jint transpose, jbooleanArray muteArray,
         jbyte userID)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -344,7 +344,7 @@
 android_media_JetPlayer_setMuteFlags(JNIEnv *env, jobject thiz,
          jint muteFlags /*unsigned?*/, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -369,7 +369,7 @@
 android_media_JetPlayer_setMuteArray(JNIEnv *env, jobject thiz,
         jbooleanArray muteArray, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -415,7 +415,7 @@
 android_media_JetPlayer_setMuteFlag(JNIEnv *env, jobject thiz,
          jint trackId, jboolean muteFlag, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -441,7 +441,7 @@
 static jboolean
 android_media_JetPlayer_triggerClip(JNIEnv *env, jobject thiz, jint clipId)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -466,7 +466,7 @@
 static jboolean
 android_media_JetPlayer_clearQueue(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -533,7 +533,7 @@
     // Get the mNativePlayerInJavaObj variable field
     javaJetPlayerFields.nativePlayerInJavaObj = env->GetFieldID(
             jetPlayerClass,
-            JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "I");
+            JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J");
     if (javaJetPlayerFields.nativePlayerInJavaObj == NULL) {
         ALOGE("Can't find JetPlayer.%s", JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_RemoteDisplay.cpp b/core/jni/android_media_RemoteDisplay.cpp
index 463be5e..1cd3fbb 100644
--- a/core/jni/android_media_RemoteDisplay.cpp
+++ b/core/jni/android_media_RemoteDisplay.cpp
@@ -134,7 +134,7 @@
 
 // ----------------------------------------------------------------------------
 
-static jint nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
+static jlong nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
     ScopedUtfChars iface(env, ifaceStr);
 
     sp<IServiceManager> sm = defaultServiceManager();
@@ -155,20 +155,20 @@
     }
 
     NativeRemoteDisplay* wrapper = new NativeRemoteDisplay(display, client);
-    return reinterpret_cast<jint>(wrapper);
+    return reinterpret_cast<jlong>(wrapper);
 }
 
-static void nativePause(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativePause(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     wrapper->pause();
 }
 
-static void nativeResume(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativeResume(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     wrapper->resume();
 }
 
-static void nativeDispose(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativeDispose(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     delete wrapper;
 }
@@ -176,13 +176,13 @@
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gMethods[] = {
-    {"nativeListen", "(Ljava/lang/String;)I",
+    {"nativeListen", "(Ljava/lang/String;)J",
             (void*)nativeListen },
-    {"nativeDispose", "(I)V",
+    {"nativeDispose", "(J)V",
             (void*)nativeDispose },
-    {"nativePause", "(I)V",
+    {"nativePause", "(J)V",
             (void*)nativePause },
-    {"nativeResume", "(I)V",
+    {"nativeResume", "(J)V",
             (void*)nativeResume },
 };
 
diff --git a/core/jni/android_media_ToneGenerator.cpp b/core/jni/android_media_ToneGenerator.cpp
index 76e42bc..ca00709 100644
--- a/core/jni/android_media_ToneGenerator.cpp
+++ b/core/jni/android_media_ToneGenerator.cpp
@@ -39,9 +39,9 @@
 static fields_t fields;
 
 static jboolean android_media_ToneGenerator_startTone(JNIEnv *env, jobject thiz, jint toneType, jint durationMs) {
-    ALOGV("android_media_ToneGenerator_startTone: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_startTone: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
@@ -52,12 +52,12 @@
 }
 
 static void android_media_ToneGenerator_stopTone(JNIEnv *env, jobject thiz) {
-    ALOGV("android_media_ToneGenerator_stopTone: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_stopTone: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
 
-    ALOGV("ToneGenerator lpToneGen: %x", (unsigned int)lpToneGen);
+    ALOGV("ToneGenerator lpToneGen: %p", lpToneGen);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
         return;
@@ -66,7 +66,7 @@
 }
 
 static jint android_media_ToneGenerator_getAudioSessionId(JNIEnv *env, jobject thiz) {
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
@@ -76,11 +76,11 @@
 }
 
 static void android_media_ToneGenerator_release(JNIEnv *env, jobject thiz) {
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
-    ALOGV("android_media_ToneGenerator_release lpToneGen: %x", (int)lpToneGen);
+    ALOGV("android_media_ToneGenerator_release lpToneGen: %p", lpToneGen);
 
-    env->SetIntField(thiz, fields.context, 0);
+    env->SetLongField(thiz, fields.context, 0);
 
     delete lpToneGen;
 }
@@ -89,11 +89,11 @@
         jint streamType, jint volume) {
     ToneGenerator *lpToneGen = new ToneGenerator((audio_stream_type_t) streamType, AudioSystem::linearToLog(volume), true);
 
-    env->SetIntField(thiz, fields.context, 0);
+    env->SetLongField(thiz, fields.context, 0);
 
-    ALOGV("android_media_ToneGenerator_native_setup jobject: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_native_setup jobject: %p", thiz);
 
-    ALOGV("ToneGenerator lpToneGen: %x", (unsigned int)lpToneGen);
+    ALOGV("ToneGenerator lpToneGen: %p", lpToneGen);
 
     if (!lpToneGen->isInited()) {
         ALOGE("ToneGenerator init failed");
@@ -103,16 +103,16 @@
     }
 
     // Stow our new C++ ToneGenerator in an opaque field in the Java object.
-    env->SetIntField(thiz, fields.context, (int)lpToneGen);
+    env->SetLongField(thiz, fields.context, (jlong)lpToneGen);
 
-    ALOGV("ToneGenerator fields.context: %x", env->GetIntField(thiz, fields.context));
+    ALOGV("ToneGenerator fields.context: %p", (void*) env->GetLongField(thiz, fields.context));
 }
 
 static void android_media_ToneGenerator_native_finalize(JNIEnv *env,
         jobject thiz) {
-    ALOGV("android_media_ToneGenerator_native_finalize jobject: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_native_finalize jobject: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
 
     if (lpToneGen != NULL) {
@@ -142,12 +142,12 @@
         return -1;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         ALOGE("Can't find ToneGenerator.mNativeContext");
         return -1;
     }
-    ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %x", (unsigned int)fields.context);
+    ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %p", fields.context);
 
     return AndroidRuntime::registerNativeMethods(env,
             "android/media/ToneGenerator", gMethods, NELEM(gMethods));
diff --git a/core/jni/android_net_LocalSocketImpl.cpp b/core/jni/android_net_LocalSocketImpl.cpp
index b9ed28e..9f79f74 100644
--- a/core/jni/android_net_LocalSocketImpl.cpp
+++ b/core/jni/android_net_LocalSocketImpl.cpp
@@ -35,6 +35,7 @@
 
 #include <cutils/sockets.h>
 #include <netinet/tcp.h>
+#include <ScopedUtfChars.h>
 
 namespace android {
 
@@ -52,25 +53,22 @@
                         jobject fileDescriptor, jstring name, jint namespaceId)
 {
     int ret;
-    const char *nameUtf8;
     int fd;
 
-    nameUtf8 = env->GetStringUTFChars(name, NULL);
-
     fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
 
     if (env->ExceptionOccurred() != NULL) {
         return;
     }
 
+    ScopedUtfChars nameUtf8(env, name);
+
     ret = socket_local_client_connect(
                 fd,
-                nameUtf8,
+                nameUtf8.c_str(),
                 namespaceId,
                 SOCK_STREAM);
 
-    env->ReleaseStringUTFChars(name, nameUtf8);
-
     if (ret < 0) {
         jniThrowIOException(env, errno);
         return;
@@ -89,11 +87,10 @@
 {
     int ret;
     int fd;
-    const char *nameUtf8;
-
 
     if (name == NULL) {
         jniThrowNullPointerException(env, NULL);
+        return;
     }
 
     fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
@@ -102,11 +99,9 @@
         return;
     }
 
-    nameUtf8 = env->GetStringUTFChars(name, NULL);
+    ScopedUtfChars nameUtf8(env, name);
 
-    ret = socket_local_server_bind(fd, nameUtf8, namespaceId);
-
-    env->ReleaseStringUTFChars(name, nameUtf8);
+    ret = socket_local_server_bind(fd, nameUtf8.c_str(), namespaceId);
 
     if (ret < 0) {
         jniThrowIOException(env, errno);
@@ -451,6 +446,7 @@
             if (count < 0) {
                 jniThrowException(env, "java/io/IOException",
                     "invalid cmsg length");
+                return -1;
             }
 
             fdArray = env->NewObjectArray(count, class_FileDescriptor, NULL);
diff --git a/core/jni/android_opengl_GLES20.cpp b/core/jni/android_opengl_GLES20.cpp
index 9bc69ae..db03b70 100644
--- a/core/jni/android_opengl_GLES20.cpp
+++ b/core/jni/android_opengl_GLES20.cpp
@@ -353,6 +353,7 @@
     const char* _nativename = 0;
 
     if (!name) {
+        _exception = 1;
         _exceptionType = "java/lang/IllegalArgumentException";
         _exceptionMessage = "name == null";
         goto exit;
@@ -2454,6 +2455,7 @@
     const char* _nativename = 0;
 
     if (!name) {
+        _exception = 1;
         _exceptionType = "java/lang/IllegalArgumentException";
         _exceptionMessage = "name == null";
         goto exit;
@@ -3602,6 +3604,7 @@
     const char* _nativename = 0;
 
     if (!name) {
+        _exception = 1;
         _exceptionType = "java/lang/IllegalArgumentException";
         _exceptionMessage = "name == null";
         goto exit;
diff --git a/core/jni/android_opengl_GLES30.cpp b/core/jni/android_opengl_GLES30.cpp
index 832d643..4c62a75 100644
--- a/core/jni/android_opengl_GLES30.cpp
+++ b/core/jni/android_opengl_GLES30.cpp
@@ -2511,6 +2511,7 @@
     const char* _nativename = 0;
 
     if (!name) {
+        _exception = 1;
         _exceptionType = "java/lang/IllegalArgumentException";
         _exceptionMessage = "name == null";
         goto exit;
@@ -3361,6 +3362,7 @@
     const char* _nativeuniformBlockName = 0;
 
     if (!uniformBlockName) {
+        _exception = 1;
         _exceptionType = "java/lang/IllegalArgumentException";
         _exceptionMessage = "uniformBlockName == null";
         goto exit;
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp
index 054ee4f6..a041693 100644
--- a/core/jni/android_os_Debug.cpp
+++ b/core/jni/android_os_Debug.cpp
@@ -675,6 +675,7 @@
     // loop until we have the block that represents this process
     do {
         if (fgets(line, 1024, fp) == 0) {
+            fclose(fp);
             return -1;
         }
     } while (strncmp(compare, line, len));
@@ -684,13 +685,16 @@
 
     do {
         if (fgets(line, 1024, fp) == 0) {
+            fclose(fp);
             return -1;
         }
     } while (strncmp(compare, line, len));
 
     // we have the line, now increment the line ptr to the value
     char* ptr = line + len;
-    return atoi(ptr);
+    jint result = atoi(ptr);
+    fclose(fp);
+    return result;
 }
 
 static jint android_os_Debug_getBinderSentTransactions(JNIEnv *env, jobject clazz)
diff --git a/core/jni/android_os_MemoryFile.cpp b/core/jni/android_os_MemoryFile.cpp
index 7134191..27b29bc 100644
--- a/core/jni/android_os_MemoryFile.cpp
+++ b/core/jni/android_os_MemoryFile.cpp
@@ -43,19 +43,20 @@
     return jniCreateFileDescriptor(env, result);
 }
 
-static jint android_os_MemoryFile_mmap(JNIEnv* env, jobject clazz, jobject fileDescriptor,
+static jlong android_os_MemoryFile_mmap(JNIEnv* env, jobject clazz, jobject fileDescriptor,
         jint length, jint prot)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-    jint result = (jint)mmap(NULL, length, prot, MAP_SHARED, fd, 0);
-    if (!result)
+    void* result = mmap(NULL, length, prot, MAP_SHARED, fd, 0);
+    if (result == MAP_FAILED) {
         jniThrowException(env, "java/io/IOException", "mmap failed");
-    return result;
+    }
+    return reinterpret_cast<jlong>(result);
 }
 
-static void android_os_MemoryFile_munmap(JNIEnv* env, jobject clazz, jint addr, jint length)
+static void android_os_MemoryFile_munmap(JNIEnv* env, jobject clazz, jlong addr, jint length)
 {
-    int result = munmap((void *)addr, length);
+    int result = munmap(reinterpret_cast<void *>(addr), length);
     if (result < 0)
         jniThrowException(env, "java/io/IOException", "munmap failed");
 }
@@ -70,7 +71,7 @@
 }
 
 static jint android_os_MemoryFile_read(JNIEnv* env, jobject clazz,
-        jobject fileDescriptor, jint address, jbyteArray buffer, jint srcOffset, jint destOffset,
+        jobject fileDescriptor, jlong address, jbyteArray buffer, jint srcOffset, jint destOffset,
         jint count, jboolean unpinned)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
@@ -89,7 +90,7 @@
 }
 
 static jint android_os_MemoryFile_write(JNIEnv* env, jobject clazz,
-        jobject fileDescriptor, jint address, jbyteArray buffer, jint srcOffset, jint destOffset,
+        jobject fileDescriptor, jlong address, jbyteArray buffer, jint srcOffset, jint destOffset,
         jint count, jboolean unpinned)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
@@ -138,11 +139,11 @@
 
 static const JNINativeMethod methods[] = {
     {"native_open",  "(Ljava/lang/String;I)Ljava/io/FileDescriptor;", (void*)android_os_MemoryFile_open},
-    {"native_mmap",  "(Ljava/io/FileDescriptor;II)I", (void*)android_os_MemoryFile_mmap},
-    {"native_munmap", "(II)V", (void*)android_os_MemoryFile_munmap},
+    {"native_mmap",  "(Ljava/io/FileDescriptor;II)J", (void*)android_os_MemoryFile_mmap},
+    {"native_munmap", "(JI)V", (void*)android_os_MemoryFile_munmap},
     {"native_close", "(Ljava/io/FileDescriptor;)V", (void*)android_os_MemoryFile_close},
-    {"native_read",  "(Ljava/io/FileDescriptor;I[BIIIZ)I", (void*)android_os_MemoryFile_read},
-    {"native_write", "(Ljava/io/FileDescriptor;I[BIIIZ)V", (void*)android_os_MemoryFile_write},
+    {"native_read",  "(Ljava/io/FileDescriptor;J[BIIIZ)I", (void*)android_os_MemoryFile_read},
+    {"native_write", "(Ljava/io/FileDescriptor;J[BIIIZ)V", (void*)android_os_MemoryFile_write},
     {"native_pin",   "(Ljava/io/FileDescriptor;Z)V", (void*)android_os_MemoryFile_pin},
     {"native_get_size", "(Ljava/io/FileDescriptor;)I",
             (void*)android_os_MemoryFile_get_size}
diff --git a/core/jni/android_os_MessageQueue.cpp b/core/jni/android_os_MessageQueue.cpp
index c9c3720..a8ed895 100644
--- a/core/jni/android_os_MessageQueue.cpp
+++ b/core/jni/android_os_MessageQueue.cpp
@@ -110,11 +110,11 @@
 // ----------------------------------------------------------------------------
 
 sp<MessageQueue> android_os_MessageQueue_getMessageQueue(JNIEnv* env, jobject messageQueueObj) {
-    jint intPtr = env->GetIntField(messageQueueObj, gMessageQueueClassInfo.mPtr);
-    return reinterpret_cast<NativeMessageQueue*>(intPtr);
+    jlong ptr = env->GetLongField(messageQueueObj, gMessageQueueClassInfo.mPtr);
+    return reinterpret_cast<NativeMessageQueue*>(ptr);
 }
 
-static jint android_os_MessageQueue_nativeInit(JNIEnv* env, jclass clazz) {
+static jlong android_os_MessageQueue_nativeInit(JNIEnv* env, jclass clazz) {
     NativeMessageQueue* nativeMessageQueue = new NativeMessageQueue();
     if (!nativeMessageQueue) {
         jniThrowRuntimeException(env, "Unable to allocate native queue");
@@ -122,26 +122,26 @@
     }
 
     nativeMessageQueue->incStrong(env);
-    return reinterpret_cast<jint>(nativeMessageQueue);
+    return reinterpret_cast<jlong>(nativeMessageQueue);
 }
 
-static void android_os_MessageQueue_nativeDestroy(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_os_MessageQueue_nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     nativeMessageQueue->decStrong(env);
 }
 
 static void android_os_MessageQueue_nativePollOnce(JNIEnv* env, jclass clazz,
-        jint ptr, jint timeoutMillis) {
+        jlong ptr, jint timeoutMillis) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     nativeMessageQueue->pollOnce(env, timeoutMillis);
 }
 
-static void android_os_MessageQueue_nativeWake(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_os_MessageQueue_nativeWake(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     return nativeMessageQueue->wake();
 }
 
-static jboolean android_os_MessageQueue_nativeIsIdling(JNIEnv* env, jclass clazz, jint ptr) {
+static jboolean android_os_MessageQueue_nativeIsIdling(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     return nativeMessageQueue->getLooper()->isIdling();
 }
@@ -150,11 +150,11 @@
 
 static JNINativeMethod gMessageQueueMethods[] = {
     /* name, signature, funcPtr */
-    { "nativeInit", "()I", (void*)android_os_MessageQueue_nativeInit },
-    { "nativeDestroy", "(I)V", (void*)android_os_MessageQueue_nativeDestroy },
-    { "nativePollOnce", "(II)V", (void*)android_os_MessageQueue_nativePollOnce },
-    { "nativeWake", "(I)V", (void*)android_os_MessageQueue_nativeWake },
-    { "nativeIsIdling", "(I)Z", (void*)android_os_MessageQueue_nativeIsIdling }
+    { "nativeInit", "()J", (void*)android_os_MessageQueue_nativeInit },
+    { "nativeDestroy", "(J)V", (void*)android_os_MessageQueue_nativeDestroy },
+    { "nativePollOnce", "(JI)V", (void*)android_os_MessageQueue_nativePollOnce },
+    { "nativeWake", "(J)V", (void*)android_os_MessageQueue_nativeWake },
+    { "nativeIsIdling", "(J)Z", (void*)android_os_MessageQueue_nativeIsIdling }
 };
 
 #define FIND_CLASS(var, className) \
@@ -174,7 +174,7 @@
     FIND_CLASS(clazz, "android/os/MessageQueue");
 
     GET_FIELD_ID(gMessageQueueClassInfo.mPtr, clazz,
-            "mPtr", "I");
+            "mPtr", "J");
     
     return 0;
 }
diff --git a/core/jni/android_os_Parcel.cpp b/core/jni/android_os_Parcel.cpp
index aa451e3..50f6c73 100644
--- a/core/jni/android_os_Parcel.cpp
+++ b/core/jni/android_os_Parcel.cpp
@@ -69,7 +69,7 @@
 Parcel* parcelForJavaObject(JNIEnv* env, jobject obj)
 {
     if (obj) {
-        Parcel* p = (Parcel*)env->GetIntField(obj, gParcelOffsets.mNativePtr);
+        Parcel* p = (Parcel*)env->GetLongField(obj, gParcelOffsets.mNativePtr);
         if (p != NULL) {
             return p;
         }
@@ -88,31 +88,31 @@
     env->CallVoidMethod(parcelObj, gParcelOffsets.recycle);
 }
 
-static jint android_os_Parcel_dataSize(JNIEnv* env, jclass clazz, jint nativePtr)
+static jint android_os_Parcel_dataSize(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     return parcel ? parcel->dataSize() : 0;
 }
 
-static jint android_os_Parcel_dataAvail(JNIEnv* env, jclass clazz, jint nativePtr)
+static jint android_os_Parcel_dataAvail(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     return parcel ? parcel->dataAvail() : 0;
 }
 
-static jint android_os_Parcel_dataPosition(JNIEnv* env, jclass clazz, jint nativePtr)
+static jint android_os_Parcel_dataPosition(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     return parcel ? parcel->dataPosition() : 0;
 }
 
-static jint android_os_Parcel_dataCapacity(JNIEnv* env, jclass clazz, jint nativePtr)
+static jint android_os_Parcel_dataCapacity(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     return parcel ? parcel->dataCapacity() : 0;
 }
 
-static void android_os_Parcel_setDataSize(JNIEnv* env, jclass clazz, jint nativePtr, jint size)
+static void android_os_Parcel_setDataSize(JNIEnv* env, jclass clazz, jlong nativePtr, jint size)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -123,7 +123,7 @@
     }
 }
 
-static void android_os_Parcel_setDataPosition(JNIEnv* env, jclass clazz, jint nativePtr, jint pos)
+static void android_os_Parcel_setDataPosition(JNIEnv* env, jclass clazz, jlong nativePtr, jint pos)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -131,7 +131,7 @@
     }
 }
 
-static void android_os_Parcel_setDataCapacity(JNIEnv* env, jclass clazz, jint nativePtr, jint size)
+static void android_os_Parcel_setDataCapacity(JNIEnv* env, jclass clazz, jlong nativePtr, jint size)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -142,7 +142,7 @@
     }
 }
 
-static jboolean android_os_Parcel_pushAllowFds(JNIEnv* env, jclass clazz, jint nativePtr, jboolean allowFds)
+static jboolean android_os_Parcel_pushAllowFds(JNIEnv* env, jclass clazz, jlong nativePtr, jboolean allowFds)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     jboolean ret = JNI_TRUE;
@@ -152,7 +152,7 @@
     return ret;
 }
 
-static void android_os_Parcel_restoreAllowFds(JNIEnv* env, jclass clazz, jint nativePtr, jboolean lastValue)
+static void android_os_Parcel_restoreAllowFds(JNIEnv* env, jclass clazz, jlong nativePtr, jboolean lastValue)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -160,7 +160,7 @@
     }
 }
 
-static void android_os_Parcel_writeNative(JNIEnv* env, jclass clazz, jint nativePtr, jobject data,
+static void android_os_Parcel_writeNative(JNIEnv* env, jclass clazz, jlong nativePtr, jobject data,
                                           jint offset, jint length)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
@@ -187,7 +187,7 @@
     }
 }
 
-static void android_os_Parcel_writeInt(JNIEnv* env, jclass clazz, jint nativePtr, jint val) {
+static void android_os_Parcel_writeInt(JNIEnv* env, jclass clazz, jlong nativePtr, jint val) {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     const status_t err = parcel->writeInt32(val);
     if (err != NO_ERROR) {
@@ -195,7 +195,7 @@
     }
 }
 
-static void android_os_Parcel_writeLong(JNIEnv* env, jclass clazz, jint nativePtr, jlong val)
+static void android_os_Parcel_writeLong(JNIEnv* env, jclass clazz, jlong nativePtr, jlong val)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -206,7 +206,7 @@
     }
 }
 
-static void android_os_Parcel_writeFloat(JNIEnv* env, jclass clazz, jint nativePtr, jfloat val)
+static void android_os_Parcel_writeFloat(JNIEnv* env, jclass clazz, jlong nativePtr, jfloat val)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -217,7 +217,7 @@
     }
 }
 
-static void android_os_Parcel_writeDouble(JNIEnv* env, jclass clazz, jint nativePtr, jdouble val)
+static void android_os_Parcel_writeDouble(JNIEnv* env, jclass clazz, jlong nativePtr, jdouble val)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -228,7 +228,7 @@
     }
 }
 
-static void android_os_Parcel_writeString(JNIEnv* env, jclass clazz, jint nativePtr, jstring val)
+static void android_os_Parcel_writeString(JNIEnv* env, jclass clazz, jlong nativePtr, jstring val)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -248,7 +248,7 @@
     }
 }
 
-static void android_os_Parcel_writeStrongBinder(JNIEnv* env, jclass clazz, jint nativePtr, jobject object)
+static void android_os_Parcel_writeStrongBinder(JNIEnv* env, jclass clazz, jlong nativePtr, jobject object)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -259,7 +259,7 @@
     }
 }
 
-static void android_os_Parcel_writeFileDescriptor(JNIEnv* env, jclass clazz, jint nativePtr, jobject object)
+static void android_os_Parcel_writeFileDescriptor(JNIEnv* env, jclass clazz, jlong nativePtr, jobject object)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -271,7 +271,7 @@
     }
 }
 
-static jbyteArray android_os_Parcel_createByteArray(JNIEnv* env, jclass clazz, jint nativePtr)
+static jbyteArray android_os_Parcel_createByteArray(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     jbyteArray ret = NULL;
 
@@ -297,7 +297,7 @@
     return ret;
 }
 
-static jint android_os_Parcel_readInt(JNIEnv* env, jclass clazz, jint nativePtr)
+static jint android_os_Parcel_readInt(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -306,7 +306,7 @@
     return 0;
 }
 
-static jlong android_os_Parcel_readLong(JNIEnv* env, jclass clazz, jint nativePtr)
+static jlong android_os_Parcel_readLong(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -315,7 +315,7 @@
     return 0;
 }
 
-static jfloat android_os_Parcel_readFloat(JNIEnv* env, jclass clazz, jint nativePtr)
+static jfloat android_os_Parcel_readFloat(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -324,7 +324,7 @@
     return 0;
 }
 
-static jdouble android_os_Parcel_readDouble(JNIEnv* env, jclass clazz, jint nativePtr)
+static jdouble android_os_Parcel_readDouble(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -333,7 +333,7 @@
     return 0;
 }
 
-static jstring android_os_Parcel_readString(JNIEnv* env, jclass clazz, jint nativePtr)
+static jstring android_os_Parcel_readString(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -347,7 +347,7 @@
     return NULL;
 }
 
-static jobject android_os_Parcel_readStrongBinder(JNIEnv* env, jclass clazz, jint nativePtr)
+static jobject android_os_Parcel_readStrongBinder(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -356,7 +356,7 @@
     return NULL;
 }
 
-static jobject android_os_Parcel_readFileDescriptor(JNIEnv* env, jclass clazz, jint nativePtr)
+static jobject android_os_Parcel_readFileDescriptor(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -468,13 +468,13 @@
     }
 }
 
-static jint android_os_Parcel_create(JNIEnv* env, jclass clazz)
+static jlong android_os_Parcel_create(JNIEnv* env, jclass clazz)
 {
     Parcel* parcel = new Parcel();
-    return reinterpret_cast<jint>(parcel);
+    return reinterpret_cast<jlong>(parcel);
 }
 
-static void android_os_Parcel_freeBuffer(JNIEnv* env, jclass clazz, jint nativePtr)
+static void android_os_Parcel_freeBuffer(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel != NULL) {
@@ -482,13 +482,13 @@
     }
 }
 
-static void android_os_Parcel_destroy(JNIEnv* env, jclass clazz, jint nativePtr)
+static void android_os_Parcel_destroy(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     delete parcel;
 }
 
-static jbyteArray android_os_Parcel_marshall(JNIEnv* env, jclass clazz, jint nativePtr)
+static jbyteArray android_os_Parcel_marshall(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
     if (parcel == NULL) {
@@ -517,7 +517,7 @@
     return ret;
 }
 
-static void android_os_Parcel_unmarshall(JNIEnv* env, jclass clazz, jint nativePtr,
+static void android_os_Parcel_unmarshall(JNIEnv* env, jclass clazz, jlong nativePtr,
                                          jbyteArray data, jint offset, jint length)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
@@ -538,8 +538,8 @@
     }
 }
 
-static void android_os_Parcel_appendFrom(JNIEnv* env, jclass clazz, jint thisNativePtr,
-                                         jint otherNativePtr, jint offset, jint length)
+static void android_os_Parcel_appendFrom(JNIEnv* env, jclass clazz, jlong thisNativePtr,
+                                         jlong otherNativePtr, jint offset, jint length)
 {
     Parcel* thisParcel = reinterpret_cast<Parcel*>(thisNativePtr);
     if (thisParcel == NULL) {
@@ -556,7 +556,7 @@
     }
 }
 
-static jboolean android_os_Parcel_hasFileDescriptors(JNIEnv* env, jclass clazz, jint nativePtr)
+static jboolean android_os_Parcel_hasFileDescriptors(JNIEnv* env, jclass clazz, jlong nativePtr)
 {
     jboolean ret = JNI_FALSE;
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
@@ -568,7 +568,7 @@
     return ret;
 }
 
-static void android_os_Parcel_writeInterfaceToken(JNIEnv* env, jclass clazz, jint nativePtr,
+static void android_os_Parcel_writeInterfaceToken(JNIEnv* env, jclass clazz, jlong nativePtr,
                                                   jstring name)
 {
     Parcel* parcel = reinterpret_cast<Parcel*>(nativePtr);
@@ -583,7 +583,7 @@
     }
 }
 
-static void android_os_Parcel_enforceInterface(JNIEnv* env, jclass clazz, jint nativePtr, jstring name)
+static void android_os_Parcel_enforceInterface(JNIEnv* env, jclass clazz, jlong nativePtr, jstring name)
 {
     jboolean ret = JNI_FALSE;
 
@@ -622,50 +622,50 @@
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod gParcelMethods[] = {
-    {"nativeDataSize",            "(I)I", (void*)android_os_Parcel_dataSize},
-    {"nativeDataAvail",           "(I)I", (void*)android_os_Parcel_dataAvail},
-    {"nativeDataPosition",        "(I)I", (void*)android_os_Parcel_dataPosition},
-    {"nativeDataCapacity",        "(I)I", (void*)android_os_Parcel_dataCapacity},
-    {"nativeSetDataSize",         "(II)V", (void*)android_os_Parcel_setDataSize},
-    {"nativeSetDataPosition",     "(II)V", (void*)android_os_Parcel_setDataPosition},
-    {"nativeSetDataCapacity",     "(II)V", (void*)android_os_Parcel_setDataCapacity},
+    {"nativeDataSize",            "(J)I", (void*)android_os_Parcel_dataSize},
+    {"nativeDataAvail",           "(J)I", (void*)android_os_Parcel_dataAvail},
+    {"nativeDataPosition",        "(J)I", (void*)android_os_Parcel_dataPosition},
+    {"nativeDataCapacity",        "(J)I", (void*)android_os_Parcel_dataCapacity},
+    {"nativeSetDataSize",         "(JI)V", (void*)android_os_Parcel_setDataSize},
+    {"nativeSetDataPosition",     "(JI)V", (void*)android_os_Parcel_setDataPosition},
+    {"nativeSetDataCapacity",     "(JI)V", (void*)android_os_Parcel_setDataCapacity},
 
-    {"nativePushAllowFds",        "(IZ)Z", (void*)android_os_Parcel_pushAllowFds},
-    {"nativeRestoreAllowFds",     "(IZ)V", (void*)android_os_Parcel_restoreAllowFds},
+    {"nativePushAllowFds",        "(JZ)Z", (void*)android_os_Parcel_pushAllowFds},
+    {"nativeRestoreAllowFds",     "(JZ)V", (void*)android_os_Parcel_restoreAllowFds},
 
-    {"nativeWriteByteArray",      "(I[BII)V", (void*)android_os_Parcel_writeNative},
-    {"nativeWriteInt",            "(II)V", (void*)android_os_Parcel_writeInt},
-    {"nativeWriteLong",           "(IJ)V", (void*)android_os_Parcel_writeLong},
-    {"nativeWriteFloat",          "(IF)V", (void*)android_os_Parcel_writeFloat},
-    {"nativeWriteDouble",         "(ID)V", (void*)android_os_Parcel_writeDouble},
-    {"nativeWriteString",         "(ILjava/lang/String;)V", (void*)android_os_Parcel_writeString},
-    {"nativeWriteStrongBinder",   "(ILandroid/os/IBinder;)V", (void*)android_os_Parcel_writeStrongBinder},
-    {"nativeWriteFileDescriptor", "(ILjava/io/FileDescriptor;)V", (void*)android_os_Parcel_writeFileDescriptor},
+    {"nativeWriteByteArray",      "(J[BII)V", (void*)android_os_Parcel_writeNative},
+    {"nativeWriteInt",            "(JI)V", (void*)android_os_Parcel_writeInt},
+    {"nativeWriteLong",           "(JJ)V", (void*)android_os_Parcel_writeLong},
+    {"nativeWriteFloat",          "(JF)V", (void*)android_os_Parcel_writeFloat},
+    {"nativeWriteDouble",         "(JD)V", (void*)android_os_Parcel_writeDouble},
+    {"nativeWriteString",         "(JLjava/lang/String;)V", (void*)android_os_Parcel_writeString},
+    {"nativeWriteStrongBinder",   "(JLandroid/os/IBinder;)V", (void*)android_os_Parcel_writeStrongBinder},
+    {"nativeWriteFileDescriptor", "(JLjava/io/FileDescriptor;)V", (void*)android_os_Parcel_writeFileDescriptor},
 
-    {"nativeCreateByteArray",     "(I)[B", (void*)android_os_Parcel_createByteArray},
-    {"nativeReadInt",             "(I)I", (void*)android_os_Parcel_readInt},
-    {"nativeReadLong",            "(I)J", (void*)android_os_Parcel_readLong},
-    {"nativeReadFloat",           "(I)F", (void*)android_os_Parcel_readFloat},
-    {"nativeReadDouble",          "(I)D", (void*)android_os_Parcel_readDouble},
-    {"nativeReadString",          "(I)Ljava/lang/String;", (void*)android_os_Parcel_readString},
-    {"nativeReadStrongBinder",    "(I)Landroid/os/IBinder;", (void*)android_os_Parcel_readStrongBinder},
-    {"nativeReadFileDescriptor",  "(I)Ljava/io/FileDescriptor;", (void*)android_os_Parcel_readFileDescriptor},
+    {"nativeCreateByteArray",     "(J)[B", (void*)android_os_Parcel_createByteArray},
+    {"nativeReadInt",             "(J)I", (void*)android_os_Parcel_readInt},
+    {"nativeReadLong",            "(J)J", (void*)android_os_Parcel_readLong},
+    {"nativeReadFloat",           "(J)F", (void*)android_os_Parcel_readFloat},
+    {"nativeReadDouble",          "(J)D", (void*)android_os_Parcel_readDouble},
+    {"nativeReadString",          "(J)Ljava/lang/String;", (void*)android_os_Parcel_readString},
+    {"nativeReadStrongBinder",    "(J)Landroid/os/IBinder;", (void*)android_os_Parcel_readStrongBinder},
+    {"nativeReadFileDescriptor",  "(J)Ljava/io/FileDescriptor;", (void*)android_os_Parcel_readFileDescriptor},
 
     {"openFileDescriptor",        "(Ljava/lang/String;I)Ljava/io/FileDescriptor;", (void*)android_os_Parcel_openFileDescriptor},
     {"dupFileDescriptor",         "(Ljava/io/FileDescriptor;)Ljava/io/FileDescriptor;", (void*)android_os_Parcel_dupFileDescriptor},
     {"closeFileDescriptor",       "(Ljava/io/FileDescriptor;)V", (void*)android_os_Parcel_closeFileDescriptor},
     {"clearFileDescriptor",       "(Ljava/io/FileDescriptor;)V", (void*)android_os_Parcel_clearFileDescriptor},
 
-    {"nativeCreate",              "()I", (void*)android_os_Parcel_create},
-    {"nativeFreeBuffer",          "(I)V", (void*)android_os_Parcel_freeBuffer},
-    {"nativeDestroy",             "(I)V", (void*)android_os_Parcel_destroy},
+    {"nativeCreate",              "()J", (void*)android_os_Parcel_create},
+    {"nativeFreeBuffer",          "(J)V", (void*)android_os_Parcel_freeBuffer},
+    {"nativeDestroy",             "(J)V", (void*)android_os_Parcel_destroy},
 
-    {"nativeMarshall",            "(I)[B", (void*)android_os_Parcel_marshall},
-    {"nativeUnmarshall",          "(I[BII)V", (void*)android_os_Parcel_unmarshall},
-    {"nativeAppendFrom",          "(IIII)V", (void*)android_os_Parcel_appendFrom},
-    {"nativeHasFileDescriptors",  "(I)Z", (void*)android_os_Parcel_hasFileDescriptors},
-    {"nativeWriteInterfaceToken", "(ILjava/lang/String;)V", (void*)android_os_Parcel_writeInterfaceToken},
-    {"nativeEnforceInterface",    "(ILjava/lang/String;)V", (void*)android_os_Parcel_enforceInterface},
+    {"nativeMarshall",            "(J)[B", (void*)android_os_Parcel_marshall},
+    {"nativeUnmarshall",          "(J[BII)V", (void*)android_os_Parcel_unmarshall},
+    {"nativeAppendFrom",          "(JJII)V", (void*)android_os_Parcel_appendFrom},
+    {"nativeHasFileDescriptors",  "(J)Z", (void*)android_os_Parcel_hasFileDescriptors},
+    {"nativeWriteInterfaceToken", "(JLjava/lang/String;)V", (void*)android_os_Parcel_writeInterfaceToken},
+    {"nativeEnforceInterface",    "(JLjava/lang/String;)V", (void*)android_os_Parcel_enforceInterface},
 };
 
 const char* const kParcelPathName = "android/os/Parcel";
@@ -678,7 +678,7 @@
     LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.Parcel");
 
     gParcelOffsets.clazz = (jclass) env->NewGlobalRef(clazz);
-    gParcelOffsets.mNativePtr = env->GetFieldID(clazz, "mNativePtr", "I");
+    gParcelOffsets.mNativePtr = env->GetFieldID(clazz, "mNativePtr", "J");
     gParcelOffsets.obtain = env->GetStaticMethodID(clazz, "obtain",
                                                    "()Landroid/os/Parcel;");
     gParcelOffsets.recycle = env->GetMethodID(clazz, "recycle", "()V");
diff --git a/core/jni/android_os_SystemClock.cpp b/core/jni/android_os_SystemClock.cpp
index d20b800..5f4d570 100644
--- a/core/jni/android_os_SystemClock.cpp
+++ b/core/jni/android_os_SystemClock.cpp
@@ -43,16 +43,77 @@
 
 namespace android {
 
+static int setCurrentTimeMillisAlarmDriver(struct timeval *tv)
+{
+    struct timespec ts;
+    int fd;
+    int res;
+
+    fd = open("/dev/alarm", O_RDWR);
+    if(fd < 0) {
+        ALOGV("Unable to open alarm driver: %s\n", strerror(errno));
+        return -1;
+    }
+    ts.tv_sec = tv->tv_sec;
+    ts.tv_nsec = tv->tv_usec * 1000;
+    res = ioctl(fd, ANDROID_ALARM_SET_RTC, &ts);
+    if (res < 0)
+        ALOGV("ANDROID_ALARM_SET_RTC ioctl failed: %s\n", strerror(errno));
+    close(fd);
+    return res;
+}
+
+static int setCurrentTimeMillisRtc(struct timeval *tv)
+{
+    struct rtc_time rtc;
+    struct tm tm, *gmtime_res;
+    int fd;
+    int res;
+
+    fd = open("/dev/rtc0", O_RDWR);
+    if (fd < 0) {
+        ALOGV("Unable to open RTC driver: %s\n", strerror(errno));
+        return -1;
+    }
+
+    res = settimeofday(tv, NULL);
+    if (res < 0) {
+        ALOGV("settimeofday() failed: %s\n", strerror(errno));
+        goto done;
+    }
+
+    gmtime_res = gmtime_r(&tv->tv_sec, &tm);
+    if (!gmtime_res) {
+        ALOGV("gmtime_r() failed: %s\n", strerror(errno));
+        res = -1;
+        goto done;
+    }
+
+    memset(&rtc, 0, sizeof(rtc));
+    rtc.tm_sec = tm.tm_sec;
+    rtc.tm_min = tm.tm_min;
+    rtc.tm_hour = tm.tm_hour;
+    rtc.tm_mday = tm.tm_mday;
+    rtc.tm_mon = tm.tm_mon;
+    rtc.tm_year = tm.tm_year;
+    rtc.tm_wday = tm.tm_wday;
+    rtc.tm_yday = tm.tm_yday;
+    rtc.tm_isdst = tm.tm_isdst;
+    res = ioctl(fd, RTC_SET_TIME, &rtc);
+    if (res < 0)
+        ALOGV("RTC_SET_TIME ioctl failed: %s\n", strerror(errno));
+done:
+    close(fd);
+    return res;
+}
+
 /*
  * Set the current time.  This only works when running as root.
  */
 static int setCurrentTimeMillis(int64_t millis)
 {
     struct timeval tv;
-    struct timespec ts;
-    int fd;
-    int res;
-    int ret = 0;
+    int ret;
 
     if (millis <= 0 || millis / 1000LL >= INT_MAX) {
         return -1;
@@ -63,19 +124,14 @@
 
     ALOGD("Setting time of day to sec=%d\n", (int) tv.tv_sec);
 
-    fd = open("/dev/alarm", O_RDWR);
-    if(fd < 0) {
-        ALOGW("Unable to open alarm driver: %s\n", strerror(errno));
-        return -1;
-    }
-    ts.tv_sec = tv.tv_sec;
-    ts.tv_nsec = tv.tv_usec * 1000;
-    res = ioctl(fd, ANDROID_ALARM_SET_RTC, &ts);
-    if(res < 0) {
+    ret = setCurrentTimeMillisAlarmDriver(&tv);
+    if (ret < 0)
+        ret = setCurrentTimeMillisRtc(&tv);
+
+    if(ret < 0) {
         ALOGW("Unable to set rtc to %ld: %s\n", tv.tv_sec, strerror(errno));
         ret = -1;
     }
-    close(fd);
     return ret;
 }
 
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 2c23f9d..8836918 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -229,7 +229,8 @@
     }
 
     Asset* a = cookie
-        ? am->openNonAsset((void*)cookie, fileName8.c_str(), (Asset::AccessMode)mode)
+        ? am->openNonAsset(static_cast<int32_t>(cookie), fileName8.c_str(),
+                (Asset::AccessMode)mode)
         : am->openNonAsset(fileName8.c_str(), (Asset::AccessMode)mode);
 
     if (a == NULL) {
@@ -260,7 +261,7 @@
     }
 
     Asset* a = cookie
-        ? am->openNonAsset((void*)cookie, fileName8.c_str(), Asset::ACCESS_RANDOM)
+        ? am->openNonAsset(static_cast<int32_t>(cookie), fileName8.c_str(), Asset::ACCESS_RANDOM)
         : am->openNonAsset(fileName8.c_str(), Asset::ACCESS_RANDOM);
 
     if (a == NULL) {
@@ -435,10 +436,10 @@
         return 0;
     }
 
-    void* cookie;
+    int32_t cookie;
     bool res = am->addAssetPath(String8(path8.c_str()), &cookie);
 
-    return (res) ? (jint)cookie : 0;
+    return (res) ? static_cast<jint>(cookie) : 0;
 }
 
 static jboolean android_content_AssetManager_isUpToDate(JNIEnv* env, jobject clazz)
@@ -800,7 +801,7 @@
     if (am == NULL) {
         return NULL;
     }
-    String8 name(am->getAssetPath((void*)cookie));
+    String8 name(am->getAssetPath(static_cast<int32_t>(cookie)));
     if (name.length() == 0) {
         jniThrowException(env, "java/lang/IndexOutOfBoundsException", "Empty cookie name");
         return NULL;
@@ -1386,7 +1387,7 @@
     }
 
     Asset* a = cookie
-        ? am->openNonAsset((void*)cookie, fileName8.c_str(), Asset::ACCESS_BUFFER)
+        ? am->openNonAsset(static_cast<int32_t>(cookie), fileName8.c_str(), Asset::ACCESS_BUFFER)
         : am->openNonAsset(fileName8.c_str(), Asset::ACCESS_BUFFER);
 
     if (a == NULL) {
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 3ac2225..475e926 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -267,7 +267,7 @@
         //data.print();
         //printf("\n");
         jboolean res = env->CallBooleanMethod(mObject, gBinderOffsets.mExecTransact,
-            code, (int32_t)&data, (int32_t)reply, flags);
+            code, reinterpret_cast<jlong>(&data), reinterpret_cast<jlong>(reply), flags);
         jthrowable excep = env->ExceptionOccurred();
 
         if (excep) {
@@ -577,7 +577,7 @@
     if (object != NULL) {
         LOGDEATH("objectForBinder %p: created new proxy %p !\n", val.get(), object);
         // The proxy holds a reference to the native object.
-        env->SetIntField(object, gBinderProxyOffsets.mObject, (int)val.get());
+        env->SetLongField(object, gBinderProxyOffsets.mObject, (jlong)val.get());
         val->incStrong((void*)javaObjectForIBinder);
 
         // The native object needs to hold a weak reference back to the
@@ -590,7 +590,7 @@
         // Also remember the death recipients registered on this proxy
         sp<DeathRecipientList> drl = new DeathRecipientList;
         drl->incStrong((void*)javaObjectForIBinder);
-        env->SetIntField(object, gBinderProxyOffsets.mOrgue, reinterpret_cast<jint>(drl.get()));
+        env->SetLongField(object, gBinderProxyOffsets.mOrgue, reinterpret_cast<jlong>(drl.get()));
 
         // Note that a new object reference has been created.
         android_atomic_inc(&gNumProxyRefs);
@@ -606,13 +606,13 @@
 
     if (env->IsInstanceOf(obj, gBinderOffsets.mClass)) {
         JavaBBinderHolder* jbh = (JavaBBinderHolder*)
-            env->GetIntField(obj, gBinderOffsets.mObject);
+            env->GetLongField(obj, gBinderOffsets.mObject);
         return jbh != NULL ? jbh->get(env, obj) : NULL;
     }
 
     if (env->IsInstanceOf(obj, gBinderProxyOffsets.mClass)) {
         return (IBinder*)
-            env->GetIntField(obj, gBinderProxyOffsets.mObject);
+            env->GetLongField(obj, gBinderProxyOffsets.mObject);
     }
 
     ALOGW("ibinderForJavaObject: %p is not a Binder object", obj);
@@ -764,15 +764,15 @@
     }
     ALOGV("Java Binder %p: acquiring first ref on holder %p", obj, jbh);
     jbh->incStrong((void*)android_os_Binder_init);
-    env->SetIntField(obj, gBinderOffsets.mObject, (int)jbh);
+    env->SetLongField(obj, gBinderOffsets.mObject, (jlong)jbh);
 }
 
 static void android_os_Binder_destroy(JNIEnv* env, jobject obj)
 {
     JavaBBinderHolder* jbh = (JavaBBinderHolder*)
-        env->GetIntField(obj, gBinderOffsets.mObject);
+        env->GetLongField(obj, gBinderOffsets.mObject);
     if (jbh != NULL) {
-        env->SetIntField(obj, gBinderOffsets.mObject, 0);
+        env->SetLongField(obj, gBinderOffsets.mObject, 0);
         ALOGV("Java Binder %p: removing ref on holder %p", obj, jbh);
         jbh->decStrong((void*)android_os_Binder_init);
     } else {
@@ -812,11 +812,11 @@
 
     gBinderOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
     gBinderOffsets.mExecTransact
-        = env->GetMethodID(clazz, "execTransact", "(IIII)Z");
+        = env->GetMethodID(clazz, "execTransact", "(IJJI)Z");
     assert(gBinderOffsets.mExecTransact);
 
     gBinderOffsets.mObject
-        = env->GetFieldID(clazz, "mObject", "I");
+        = env->GetFieldID(clazz, "mObject", "J");
     assert(gBinderOffsets.mObject);
 
     return AndroidRuntime::registerNativeMethods(
@@ -911,7 +911,7 @@
 static jboolean android_os_BinderProxy_pingBinder(JNIEnv* env, jobject obj)
 {
     IBinder* target = (IBinder*)
-        env->GetIntField(obj, gBinderProxyOffsets.mObject);
+        env->GetLongField(obj, gBinderProxyOffsets.mObject);
     if (target == NULL) {
         return JNI_FALSE;
     }
@@ -921,7 +921,7 @@
 
 static jstring android_os_BinderProxy_getInterfaceDescriptor(JNIEnv* env, jobject obj)
 {
-    IBinder* target = (IBinder*) env->GetIntField(obj, gBinderProxyOffsets.mObject);
+    IBinder* target = (IBinder*) env->GetLongField(obj, gBinderProxyOffsets.mObject);
     if (target != NULL) {
         const String16& desc = target->getInterfaceDescriptor();
         return env->NewString(desc.string(), desc.size());
@@ -934,7 +934,7 @@
 static jboolean android_os_BinderProxy_isBinderAlive(JNIEnv* env, jobject obj)
 {
     IBinder* target = (IBinder*)
-        env->GetIntField(obj, gBinderProxyOffsets.mObject);
+        env->GetLongField(obj, gBinderProxyOffsets.mObject);
     if (target == NULL) {
         return JNI_FALSE;
     }
@@ -943,13 +943,20 @@
 }
 
 static int getprocname(pid_t pid, char *buf, size_t len) {
-    char filename[20];
+    char filename[32];
     FILE *f;
 
-    sprintf(filename, "/proc/%d/cmdline", pid);
+    snprintf(filename, sizeof(filename), "/proc/%d/cmdline", pid);
     f = fopen(filename, "r");
-    if (!f) { *buf = '\0'; return 1; }
-    if (!fgets(buf, len, f)) { *buf = '\0'; return 2; }
+    if (!f) {
+        *buf = '\0';
+        return 1;
+    }
+    if (!fgets(buf, len, f)) {
+        *buf = '\0';
+        fclose(f);
+        return 2;
+    }
     fclose(f);
     return 0;
 }
@@ -1055,7 +1062,7 @@
     }
 
     IBinder* target = (IBinder*)
-        env->GetIntField(obj, gBinderProxyOffsets.mObject);
+        env->GetLongField(obj, gBinderProxyOffsets.mObject);
     if (target == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", "Binder has been finalized!");
         return JNI_FALSE;
@@ -1102,7 +1109,7 @@
     }
 
     IBinder* target = (IBinder*)
-        env->GetIntField(obj, gBinderProxyOffsets.mObject);
+        env->GetLongField(obj, gBinderProxyOffsets.mObject);
     if (target == NULL) {
         ALOGW("Binder has been finalized when calling linkToDeath() with recip=%p)\n", recipient);
         assert(false);
@@ -1112,7 +1119,7 @@
 
     if (!target->localBinder()) {
         DeathRecipientList* list = (DeathRecipientList*)
-                env->GetIntField(obj, gBinderProxyOffsets.mOrgue);
+                env->GetLongField(obj, gBinderProxyOffsets.mOrgue);
         sp<JavaDeathRecipient> jdr = new JavaDeathRecipient(env, recipient, list);
         status_t err = target->linkToDeath(jdr, NULL, flags);
         if (err != NO_ERROR) {
@@ -1134,7 +1141,7 @@
     }
 
     IBinder* target = (IBinder*)
-        env->GetIntField(obj, gBinderProxyOffsets.mObject);
+        env->GetLongField(obj, gBinderProxyOffsets.mObject);
     if (target == NULL) {
         ALOGW("Binder has been finalized when calling linkToDeath() with recip=%p)\n", recipient);
         return JNI_FALSE;
@@ -1147,7 +1154,7 @@
 
         // If we find the matching recipient, proceed to unlink using that
         DeathRecipientList* list = (DeathRecipientList*)
-                env->GetIntField(obj, gBinderProxyOffsets.mOrgue);
+                env->GetLongField(obj, gBinderProxyOffsets.mOrgue);
         sp<JavaDeathRecipient> origJDR = list->find(recipient);
         LOGDEATH("   unlink found list %p and JDR %p", list, origJDR.get());
         if (origJDR != NULL) {
@@ -1176,13 +1183,13 @@
 static void android_os_BinderProxy_destroy(JNIEnv* env, jobject obj)
 {
     IBinder* b = (IBinder*)
-            env->GetIntField(obj, gBinderProxyOffsets.mObject);
+            env->GetLongField(obj, gBinderProxyOffsets.mObject);
     DeathRecipientList* drl = (DeathRecipientList*)
-            env->GetIntField(obj, gBinderProxyOffsets.mOrgue);
+            env->GetLongField(obj, gBinderProxyOffsets.mOrgue);
 
     LOGDEATH("Destroying BinderProxy %p: binder=%p drl=%p\n", obj, b, drl);
-    env->SetIntField(obj, gBinderProxyOffsets.mObject, 0);
-    env->SetIntField(obj, gBinderProxyOffsets.mOrgue, 0);
+    env->SetLongField(obj, gBinderProxyOffsets.mObject, 0);
+    env->SetLongField(obj, gBinderProxyOffsets.mOrgue, 0);
     drl->decStrong((void*)javaObjectForIBinder);
     b->decStrong((void*)javaObjectForIBinder);
 
@@ -1224,13 +1231,13 @@
     assert(gBinderProxyOffsets.mSendDeathNotice);
 
     gBinderProxyOffsets.mObject
-        = env->GetFieldID(clazz, "mObject", "I");
+        = env->GetFieldID(clazz, "mObject", "J");
     assert(gBinderProxyOffsets.mObject);
     gBinderProxyOffsets.mSelf
         = env->GetFieldID(clazz, "mSelf", "Ljava/lang/ref/WeakReference;");
     assert(gBinderProxyOffsets.mSelf);
     gBinderProxyOffsets.mOrgue
-        = env->GetFieldID(clazz, "mOrgue", "I");
+        = env->GetFieldID(clazz, "mOrgue", "J");
     assert(gBinderProxyOffsets.mOrgue);
 
     clazz = env->FindClass("java/lang/Class");
diff --git a/core/jni/android_util_EventLog.cpp b/core/jni/android_util_EventLog.cpp
index 83d8aa2..2593420 100644
--- a/core/jni/android_util_EventLog.cpp
+++ b/core/jni/android_util_EventLog.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2007-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.
@@ -21,6 +21,8 @@
 #include "jni.h"
 #include "log/logger.h"
 
+#define UNUSED  __attribute__((__unused__))
+
 // The size of the tag number comes out of the payload size.
 #define MAX_EVENT_PAYLOAD (LOGGER_ENTRY_MAX_PAYLOAD - sizeof(int32_t))
 
@@ -44,7 +46,8 @@
  * In class android.util.EventLog:
  *  static native int writeEvent(int tag, int value)
  */
-static jint android_util_EventLog_writeEvent_Integer(JNIEnv* env, jobject clazz,
+static jint android_util_EventLog_writeEvent_Integer(JNIEnv* env UNUSED,
+                                                     jobject clazz UNUSED,
                                                      jint tag, jint value)
 {
     return android_btWriteLog(tag, EVENT_TYPE_INT, &value, sizeof(value));
@@ -54,7 +57,8 @@
  * In class android.util.EventLog:
  *  static native int writeEvent(long tag, long value)
  */
-static jint android_util_EventLog_writeEvent_Long(JNIEnv* env, jobject clazz,
+static jint android_util_EventLog_writeEvent_Long(JNIEnv* env UNUSED,
+                                                  jobject clazz UNUSED,
                                                   jint tag, jlong value)
 {
     return android_btWriteLog(tag, EVENT_TYPE_LONG, &value, sizeof(value));
@@ -64,7 +68,8 @@
  * In class android.util.EventLog:
  *  static native int writeEvent(int tag, String value)
  */
-static jint android_util_EventLog_writeEvent_String(JNIEnv* env, jobject clazz,
+static jint android_util_EventLog_writeEvent_String(JNIEnv* env,
+                                                    jobject clazz UNUSED,
                                                     jint tag, jstring value) {
     uint8_t buf[MAX_EVENT_PAYLOAD];
 
@@ -142,18 +147,21 @@
  * In class android.util.EventLog:
  *  static native void readEvents(int[] tags, Collection<Event> output)
  *
- *  Reads events from the event log, typically /dev/log/events
+ *  Reads events from the event log
  */
-static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz,
+static void android_util_EventLog_readEvents(JNIEnv* env, jobject clazz UNUSED,
                                              jintArray tags,
                                              jobject out) {
+
     if (tags == NULL || out == NULL) {
         jniThrowNullPointerException(env, NULL);
         return;
     }
 
-    int fd = open("/dev/" LOGGER_LOG_EVENTS, O_RDONLY | O_NONBLOCK);
-    if (fd < 0) {
+    struct logger_list *logger_list = android_logger_list_open(
+        LOG_ID_EVENTS, O_RDONLY | O_NONBLOCK, 0, 0);
+
+    if (!logger_list) {
         jniThrowIOException(env, errno);
         return;
     }
@@ -161,41 +169,26 @@
     jsize tagLength = env->GetArrayLength(tags);
     jint *tagValues = env->GetIntArrayElements(tags, NULL);
 
-    uint8_t buf[LOGGER_ENTRY_MAX_LEN];
-    struct timeval timeout = {0, 0};
-    fd_set readset;
-    FD_ZERO(&readset);
+    while (1) {
+        log_msg log_msg;
+        int ret = android_logger_list_read(logger_list, &log_msg);
 
-    for (;;) {
-        // Use a short select() to try to avoid problems hanging on read().
-        // This means we block for 5ms at the end of the log -- oh well.
-        timeout.tv_usec = 5000;
-        FD_SET(fd, &readset);
-        int r = select(fd + 1, &readset, NULL, NULL, &timeout);
-        if (r == 0) {
-            break;  // no more events
-        } else if (r < 0 && errno == EINTR) {
-            continue;  // interrupted by signal, try again
-        } else if (r < 0) {
-            jniThrowIOException(env, errno);  // Will throw on return
+        if (ret == 0) {
+            break;
+        }
+        if (ret < 0) {
+            if (errno == EINTR) {
+                continue;
+            }
+            if (errno == EINVAL) {
+                jniThrowException(env, "java/io/IOException", "Event too short");
+            } else if (errno != EAGAIN) {
+                jniThrowIOException(env, errno);  // Will throw on return
+            }
             break;
         }
 
-        int len = read(fd, buf, sizeof(buf));
-        if (len == 0 || (len < 0 && errno == EAGAIN)) {
-            break;  // no more events
-        } else if (len < 0 && errno == EINTR) {
-            continue;  // interrupted by signal, try again
-        } else if (len < 0) {
-            jniThrowIOException(env, errno);  // Will throw on return
-            break;
-        } else if ((size_t) len < sizeof(logger_entry) + sizeof(int32_t)) {
-            jniThrowException(env, "java/io/IOException", "Event too short");
-            break;
-        }
-
-        logger_entry* entry = (logger_entry*) buf;
-        int32_t tag = * (int32_t*) (buf + sizeof(*entry));
+        int32_t tag = * (int32_t *) log_msg.msg();
 
         int found = 0;
         for (int i = 0; !found && i < tagLength; ++i) {
@@ -203,16 +196,20 @@
         }
 
         if (found) {
-            jsize len = sizeof(*entry) + entry->len;
+            jsize len = ret;
             jbyteArray array = env->NewByteArray(len);
-            if (array == NULL) break;
+            if (array == NULL) {
+                break;
+            }
 
             jbyte *bytes = env->GetByteArrayElements(array, NULL);
-            memcpy(bytes, buf, len);
+            memcpy(bytes, log_msg.buf, len);
             env->ReleaseByteArrayElements(array, bytes, 0);
 
             jobject event = env->NewObject(gEventClass, gEventInitID, array);
-            if (event == NULL) break;
+            if (event == NULL) {
+                break;
+            }
 
             env->CallBooleanMethod(out, gCollectionAddID, event);
             env->DeleteLocalRef(event);
@@ -220,7 +217,8 @@
         }
     }
 
-    close(fd);
+    android_logger_list_close(logger_list);
+
     env->ReleaseIntArrayElements(tags, tagValues, 0);
 }
 
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index 8325217..cbed99f 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -344,23 +344,6 @@
     return pri;
 }
 
-jboolean android_os_Process_setOomAdj(JNIEnv* env, jobject clazz,
-                                      jint pid, jint adj)
-{
-#ifdef HAVE_OOM_ADJ
-    char text[64];
-    sprintf(text, "/proc/%d/oom_adj", pid);
-    int fd = open(text, O_WRONLY);
-    if (fd >= 0) {
-        sprintf(text, "%d", adj);
-        write(fd, text, strlen(text));
-        close(fd);
-    }
-    return true;
-#endif
-    return false;
-}
-
 jboolean android_os_Process_setSwappiness(JNIEnv *env, jobject clazz,
                                           jint pid, jboolean is_increased)
 {
@@ -422,7 +405,7 @@
     return *((const jint*)v1) - *((const jint*)v2);
 }
 
-static jlong getFreeMemoryImpl(const char* const sums[], const int sumsLen[], int num)
+static jlong getFreeMemoryImpl(const char* const sums[], const size_t sumsLen[], size_t num)
 {
     int fd = open("/proc/meminfo", O_RDONLY);
 
@@ -441,7 +424,7 @@
     }
     buffer[len] = 0;
 
-    int numFound = 0;
+    size_t numFound = 0;
     jlong mem = 0;
 
     char* p = buffer;
@@ -473,14 +456,14 @@
 static jlong android_os_Process_getFreeMemory(JNIEnv* env, jobject clazz)
 {
     static const char* const sums[] = { "MemFree:", "Cached:", NULL };
-    static const int sumsLen[] = { strlen("MemFree:"), strlen("Cached:"), 0 };
+    static const size_t sumsLen[] = { strlen("MemFree:"), strlen("Cached:"), 0 };
     return getFreeMemoryImpl(sums, sumsLen, 2);
 }
 
 static jlong android_os_Process_getTotalMemory(JNIEnv* env, jobject clazz)
 {
     static const char* const sums[] = { "MemTotal:", NULL };
-    static const int sumsLen[] = { strlen("MemTotal:"), 0 };
+    static const size_t sumsLen[] = { strlen("MemTotal:"), 0 };
     return getFreeMemoryImpl(sums, sumsLen, 1);
 }
 
@@ -745,7 +728,7 @@
 
         jsize end = -1;
         if ((mode&PROC_PARENS) != 0) {
-            while (buffer[i] != ')' && i < endIndex) {
+            while (i < endIndex && buffer[i] != ')') {
                 i++;
             }
             end = i;
@@ -757,7 +740,7 @@
             end = i;
             i++;
         }
-        while (buffer[i] != term && i < endIndex) {
+        while (i < endIndex && buffer[i] != term) {
             i++;
         }
         if (end < 0) {
@@ -767,7 +750,7 @@
         if (i < endIndex) {
             i++;
             if ((mode&PROC_COMBINE) != 0) {
-                while (buffer[i] == term && i < endIndex) {
+                while (i < endIndex && buffer[i] == term) {
                     i++;
                 }
             }
@@ -1023,7 +1006,6 @@
     {"setThreadGroup",      "(II)V", (void*)android_os_Process_setThreadGroup},
     {"setProcessGroup",     "(II)V", (void*)android_os_Process_setProcessGroup},
     {"getProcessGroup",     "(I)I", (void*)android_os_Process_getProcessGroup},
-    {"setOomAdj",   "(II)Z", (void*)android_os_Process_setOomAdj},
     {"setSwappiness",   "(IZ)Z", (void*)android_os_Process_setSwappiness},
     {"setArgV0",    "(Ljava/lang/String;)V", (void*)android_os_Process_setArgV0},
     {"setUid", "(I)I", (void*)android_os_Process_setUid},
diff --git a/core/jni/android_view_DisplayEventReceiver.cpp b/core/jni/android_view_DisplayEventReceiver.cpp
index 64fb27b..d4cc159 100644
--- a/core/jni/android_view_DisplayEventReceiver.cpp
+++ b/core/jni/android_view_DisplayEventReceiver.cpp
@@ -87,7 +87,7 @@
         return result;
     }
 
-    int rc = mMessageQueue->getLooper()->addFd(mReceiver.getFd(), 0, ALOOPER_EVENT_INPUT,
+    int rc = mMessageQueue->getLooper()->addFd(mReceiver.getFd(), 0, Looper::EVENT_INPUT,
             this, NULL);
     if (rc < 0) {
         return UNKNOWN_ERROR;
@@ -125,13 +125,13 @@
 }
 
 int NativeDisplayEventReceiver::handleEvent(int receiveFd, int events, void* data) {
-    if (events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP)) {
+    if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
         ALOGE("Display event receiver pipe was closed or an error occurred.  "
                 "events=0x%x", events);
         return 0; // remove the callback
     }
 
-    if (!(events & ALOOPER_EVENT_INPUT)) {
+    if (!(events & Looper::EVENT_INPUT)) {
         ALOGW("Received spurious callback for unhandled poll event.  "
                 "events=0x%x", events);
         return 1; // keep the callback
@@ -207,7 +207,7 @@
 }
 
 
-static jint nativeInit(JNIEnv* env, jclass clazz, jobject receiverObj,
+static jlong nativeInit(JNIEnv* env, jclass clazz, jobject receiverObj,
         jobject messageQueueObj) {
     sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
     if (messageQueue == NULL) {
@@ -226,17 +226,17 @@
     }
 
     receiver->incStrong(gDisplayEventReceiverClassInfo.clazz); // retain a reference for the object
-    return reinterpret_cast<jint>(receiver.get());
+    return reinterpret_cast<jlong>(receiver.get());
 }
 
-static void nativeDispose(JNIEnv* env, jclass clazz, jint receiverPtr) {
+static void nativeDispose(JNIEnv* env, jclass clazz, jlong receiverPtr) {
     sp<NativeDisplayEventReceiver> receiver =
             reinterpret_cast<NativeDisplayEventReceiver*>(receiverPtr);
     receiver->dispose();
     receiver->decStrong(gDisplayEventReceiverClassInfo.clazz); // drop reference held by the object
 }
 
-static void nativeScheduleVsync(JNIEnv* env, jclass clazz, jint receiverPtr) {
+static void nativeScheduleVsync(JNIEnv* env, jclass clazz, jlong receiverPtr) {
     sp<NativeDisplayEventReceiver> receiver =
             reinterpret_cast<NativeDisplayEventReceiver*>(receiverPtr);
     status_t status = receiver->scheduleVsync();
@@ -251,12 +251,12 @@
 static JNINativeMethod gMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInit",
-            "(Landroid/view/DisplayEventReceiver;Landroid/os/MessageQueue;)I",
+            "(Landroid/view/DisplayEventReceiver;Landroid/os/MessageQueue;)J",
             (void*)nativeInit },
     { "nativeDispose",
-            "(I)V",
+            "(J)V",
             (void*)nativeDispose },
-    { "nativeScheduleVsync", "(I)V",
+    { "nativeScheduleVsync", "(J)V",
             (void*)nativeScheduleVsync }
 };
 
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index b720e73..118af1b 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -94,17 +94,17 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_flushCaches(JNIEnv* env, jobject clazz,
-        Caches::FlushMode mode) {
+        jint mode) {
     if (Caches::hasInstance()) {
-        Caches::getInstance().flush(mode);
+        Caches::getInstance().flush(static_cast<Caches::FlushMode>(mode));
     }
 }
 
-static bool android_view_GLES20Canvas_initCaches(JNIEnv* env, jobject clazz) {
+static jboolean android_view_GLES20Canvas_initCaches(JNIEnv* env, jobject clazz) {
     if (Caches::hasInstance()) {
-        return Caches::getInstance().init();
+        return Caches::getInstance().init() ? JNI_TRUE : JNI_FALSE;
     }
-    return false;
+    return JNI_FALSE;
 }
 
 static void android_view_GLES20Canvas_terminateCaches(JNIEnv* env, jobject clazz) {
@@ -132,15 +132,16 @@
 // Constructors
 // ----------------------------------------------------------------------------
 
-static OpenGLRenderer* android_view_GLES20Canvas_createRenderer(JNIEnv* env, jobject clazz) {
+static jlong android_view_GLES20Canvas_createRenderer(JNIEnv* env, jobject clazz) {
     RENDERER_LOGD("Create OpenGLRenderer");
     OpenGLRenderer* renderer = new OpenGLRenderer();
     renderer->initProperties();
-    return renderer;
+    return reinterpret_cast<jlong>(renderer);
 }
 
 static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     RENDERER_LOGD("Destroy OpenGLRenderer");
     delete renderer;
 }
@@ -150,23 +151,27 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint width, jint height) {
+        jlong rendererHandle, jint width, jint height) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->setViewport(width, height);
 }
 
-static int android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jboolean opaque) {
+static jint android_view_GLES20Canvas_prepare(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jboolean opaque) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     return renderer->prepare(opaque);
 }
 
-static int android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom,
+static jint android_view_GLES20Canvas_prepareDirty(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jint left, jint top, jint right, jint bottom,
         jboolean opaque) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     return renderer->prepareDirty(left, top, right, bottom, opaque);
 }
 
 static void android_view_GLES20Canvas_finish(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->finish();
 }
 
@@ -175,7 +180,8 @@
 }
 
 static void android_view_GLES20Canvas_setName(JNIEnv* env,
-        jobject clazz, OpenGLRenderer* renderer, jstring name) {
+        jobject clazz, jlong rendererHandle, jstring name) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     if (name != NULL) {
         const char* textArray = env->GetStringUTFChars(name, NULL);
         renderer->setName(textArray);
@@ -186,12 +192,14 @@
 }
 
 static void android_view_GLES20Canvas_setCountOverdrawEnabled(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jboolean enabled) {
+        jlong rendererHandle, jboolean enabled) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->setCountOverdrawEnabled(enabled);
 }
 
 static jfloat android_view_GLES20Canvas_getOverdraw(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     return renderer->getOverdraw();
 }
 
@@ -200,23 +208,30 @@
 // ----------------------------------------------------------------------------
 
 static jint android_view_GLES20Canvas_callDrawGLFunction(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, Functor* functor) {
+        jlong rendererHandle, jlong functorHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    Functor* functor = reinterpret_cast<Functor*>(functorHandle);
     android::uirenderer::Rect dirty;
     return renderer->callDrawGLFunction(functor, dirty);
 }
 
 static void android_view_GLES20Canvas_detachFunctor(JNIEnv* env,
-        jobject clazz, OpenGLRenderer* renderer, Functor* functor) {
+        jobject clazz, jlong rendererHandle, jlong functorHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    Functor* functor = reinterpret_cast<Functor*>(functorHandle);
     renderer->detachFunctor(functor);
 }
 
 static void android_view_GLES20Canvas_attachFunctor(JNIEnv* env,
-        jobject clazz, OpenGLRenderer* renderer, Functor* functor) {
+        jobject clazz, jlong rendererHandle, jlong functorHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    Functor* functor = reinterpret_cast<Functor*>(functorHandle);
     renderer->attachFunctor(functor);
 }
 
 static jint android_view_GLES20Canvas_invokeFunctors(JNIEnv* env,
-        jobject clazz, OpenGLRenderer* renderer, jobject dirty) {
+        jobject clazz, jlong rendererHandle, jobject dirty) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     android::uirenderer::Rect bounds;
     status_t status = renderer->invokeFunctors(bounds);
     if (status != DrawGlInfo::kStatusDone && dirty != NULL) {
@@ -242,23 +257,27 @@
 // State
 // ----------------------------------------------------------------------------
 
-static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject clazz, OpenGLRenderer* renderer,
+static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject clazz, jlong rendererHandle,
         jint flags) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     return renderer->save(flags);
 }
 
 static jint android_view_GLES20Canvas_getSaveCount(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     return renderer->getSaveCount();
 }
 
 static void android_view_GLES20Canvas_restore(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->restore();
 }
 
 static void android_view_GLES20Canvas_restoreToCount(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint saveCount) {
+        jlong rendererHandle, jint saveCount) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->restoreToCount(saveCount);
 }
 
@@ -267,26 +286,32 @@
 // ----------------------------------------------------------------------------
 
 static jint android_view_GLES20Canvas_saveLayer(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
-        SkPaint* paint, jint saveFlags) {
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jlong paintHandle, jint saveFlags) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     return renderer->saveLayer(left, top, right, bottom, paint, saveFlags);
 }
 
 static jint android_view_GLES20Canvas_saveLayerClip(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkPaint* paint, jint saveFlags) {
+        jlong rendererHandle, jlong paintHandle, jint saveFlags) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     const android::uirenderer::Rect& bounds(renderer->getClipBounds());
     return renderer->saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom,
             paint, saveFlags);
 }
 
 static jint android_view_GLES20Canvas_saveLayerAlpha(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
         jint alpha, jint saveFlags) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     return renderer->saveLayerAlpha(left, top, right, bottom, alpha, saveFlags);
 }
 
 static jint android_view_GLES20Canvas_saveLayerAlphaClip(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint alpha, jint saveFlags) {
+        jlong rendererHandle, jint alpha, jint saveFlags) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     const android::uirenderer::Rect& bounds(renderer->getClipBounds());
     return renderer->saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom,
             alpha, saveFlags);
@@ -296,41 +321,57 @@
 // Clipping
 // ----------------------------------------------------------------------------
 
-static bool android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom) {
-    return renderer->quickRejectNoScissor(left, top, right, bottom);
+static jboolean android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    bool result = renderer->quickRejectNoScissor(left, top, right, bottom);
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
-static bool android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
-        SkRegion::Op op) {
-    return renderer->clipRect(left, top, right, bottom, op);
+static jboolean android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jint opHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkRegion::Op op = static_cast<SkRegion::Op>(opHandle);
+    bool result;
+    result = renderer->clipRect(left, top, right, bottom, op);
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
-static bool android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom,
-        SkRegion::Op op) {
-    return renderer->clipRect(float(left), float(top), float(right), float(bottom), op);
+static jboolean android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jint left, jint top, jint right, jint bottom,
+        jint opHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkRegion::Op op = static_cast<SkRegion::Op>(opHandle);
+    bool result = renderer->clipRect(float(left), float(top), float(right), float(bottom), op);
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
-static bool android_view_GLES20Canvas_clipPath(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkPath* path, SkRegion::Op op) {
-    return renderer->clipPath(path, op);
+static jboolean android_view_GLES20Canvas_clipPath(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jlong pathHandle, jint opHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+    SkRegion::Op op = static_cast<SkRegion::Op>(opHandle);
+    return renderer->clipPath(path, op) ? JNI_TRUE : JNI_FALSE;
 }
 
-static bool android_view_GLES20Canvas_clipRegion(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkRegion* region, SkRegion::Op op) {
-    return renderer->clipRegion(region, op);
+static jboolean android_view_GLES20Canvas_clipRegion(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jlong regionHandle, jint opHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
+    SkRegion::Op op = static_cast<SkRegion::Op>(opHandle);
+    return renderer->clipRegion(region, op) ? JNI_TRUE : JNI_FALSE;
 }
 
-static bool android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jobject rect) {
+static jboolean android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject clazz,
+        jlong rendererHandle, jobject rect) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     const android::uirenderer::Rect& bounds(renderer->getClipBounds());
 
     env->CallVoidMethod(rect, gRectClassInfo.set,
             int(bounds.left), int(bounds.top), int(bounds.right), int(bounds.bottom));
 
-    return !bounds.isEmpty();
+    return !bounds.isEmpty() ? JNI_TRUE : JNI_FALSE;
 }
 
 // ----------------------------------------------------------------------------
@@ -338,37 +379,47 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_translate(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat dx, jfloat dy) {
+        jlong rendererHandle, jfloat dx, jfloat dy) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->translate(dx, dy);
 }
 
 static void android_view_GLES20Canvas_rotate(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat degrees) {
+        jlong rendererHandle, jfloat degrees) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->rotate(degrees);
 }
 
 static void android_view_GLES20Canvas_scale(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat sx, jfloat sy) {
+        jlong rendererHandle, jfloat sx, jfloat sy) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->scale(sx, sy);
 }
 
 static void android_view_GLES20Canvas_skew(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat sx, jfloat sy) {
+        jlong rendererHandle, jfloat sx, jfloat sy) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->skew(sx, sy);
 }
 
 static void android_view_GLES20Canvas_setMatrix(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkMatrix* matrix) {
+        jlong rendererHandle, jlong matrixHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     renderer->setMatrix(matrix);
 }
 
 static void android_view_GLES20Canvas_getMatrix(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkMatrix* matrix) {
+        jlong rendererHandle, jlong matrixHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     renderer->getMatrix(matrix);
 }
 
 static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkMatrix* matrix) {
+        jlong rendererHandle, jlong matrixHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     renderer->concatMatrix(matrix);
 }
 
@@ -377,8 +428,11 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer,
-        jfloat left, jfloat top, SkPaint* paint) {
+        jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer,
+        jfloat left, jfloat top, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     // This object allows the renderer to allocate a global JNI ref to the buffer object.
     JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
 
@@ -386,9 +440,12 @@
 }
 
 static void android_view_GLES20Canvas_drawBitmapRect(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer,
-        float srcLeft, float srcTop, float srcRight, float srcBottom,
-        float dstLeft, float dstTop, float dstRight, float dstBottom, SkPaint* paint) {
+        jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer,
+        jfloat srcLeft, jfloat srcTop, jfloat srcRight, jfloat srcBottom,
+        jfloat dstLeft, jfloat dstTop, jfloat dstRight, jfloat dstBottom, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     // This object allows the renderer to allocate a global JNI ref to the buffer object.
     JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
 
@@ -397,8 +454,12 @@
 }
 
 static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer,
-        SkMatrix* matrix, SkPaint* paint) {
+        jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer,
+        jlong matrixHandle, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     // This object allows the renderer to allocate a global JNI ref to the buffer object.
     JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
 
@@ -406,8 +467,10 @@
 }
 
 static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jintArray colors, jint offset, jint stride,
-        jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, SkPaint* paint) {
+        jlong rendererHandle, jintArray colors, jint offset, jint stride,
+        jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     SkBitmap* bitmap = new SkBitmap;
     bitmap->setConfig(hasAlpha ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config,
             width, height);
@@ -431,9 +494,12 @@
 }
 
 static void android_view_GLES20Canvas_drawBitmapMesh(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer,
+        jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer,
         jint meshWidth, jint meshHeight, jfloatArray vertices, jint offset, jintArray colors,
-        jint colorOffset, SkPaint* paint) {
+        jint colorOffset, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     // This object allows the renderer to allocate a global JNI ref to the buffer object.
     JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
 
@@ -447,8 +513,13 @@
 }
 
 static void android_view_GLES20Canvas_drawPatch(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, Res_png_9patch* patch,
-        float left, float top, float right, float bottom, SkPaint* paint) {
+        jlong rendererHandle, jlong bitmapHandle, jbyteArray buffer, jlong patchHandle,
+        jfloat left, jfloat top, jfloat right, jfloat bottom, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
+    Res_png_9patch* patch  = reinterpret_cast<Res_png_9patch*>(patchHandle);
+    SkPaint* paint  = reinterpret_cast<SkPaint*>(paintHandle);
+
     // This object allows the renderer to allocate a global JNI ref to the buffer object.
     JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
 
@@ -456,41 +527,56 @@
 }
 
 static void android_view_GLES20Canvas_drawColor(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint color, SkXfermode::Mode mode) {
+        jlong rendererHandle, jint color, SkXfermode::Mode mode) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->drawColor(color, mode);
 }
 
 static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
-        SkPaint* paint) {
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     renderer->drawRect(left, top, right, bottom, paint);
 }
 
 static void android_view_GLES20Canvas_drawRoundRect(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
-        jfloat rx, jfloat ry, SkPaint* paint) {
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jfloat rx, jfloat ry, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     renderer->drawRoundRect(left, top, right, bottom, rx, ry, paint);
 }
 
 static void android_view_GLES20Canvas_drawCircle(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat x, jfloat y, jfloat radius, SkPaint* paint) {
+        jlong rendererHandle, jfloat x, jfloat y, jfloat radius, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     renderer->drawCircle(x, y, radius, paint);
 }
 
 static void android_view_GLES20Canvas_drawOval(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
-        SkPaint* paint) {
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     renderer->drawOval(left, top, right, bottom, paint);
 }
 
 static void android_view_GLES20Canvas_drawArc(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom,
-        jfloat startAngle, jfloat sweepAngle, jboolean useCenter, SkPaint* paint) {
+        jlong rendererHandle, jfloat left, jfloat top, jfloat right, jfloat bottom,
+        jfloat startAngle, jfloat sweepAngle, jboolean useCenter, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     renderer->drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint);
 }
 
 static void android_view_GLES20Canvas_drawRegionAsRects(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkRegion* region, SkPaint* paint) {
+        jlong rendererHandle, jlong regionHandle, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkRegion* region = reinterpret_cast<SkRegion*>(regionHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
+
     if (paint->getStyle() != SkPaint::kFill_Style ||
             (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) {
         SkRegion::Iterator it(*region);
@@ -517,26 +603,35 @@
 }
 
 static void android_view_GLES20Canvas_drawRects(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloatArray rects, jint count, SkPaint* paint) {
+        jlong rendererHandle, jfloatArray rects, jint count, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jfloat* storage = env->GetFloatArrayElements(rects, NULL);
     renderer->drawRects(storage, count, paint);
     env->ReleaseFloatArrayElements(rects, storage, 0);
 }
 
 static void android_view_GLES20Canvas_drawPoints(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloatArray points, jint offset, jint count, SkPaint* paint) {
+        jlong rendererHandle, jfloatArray points, jint offset, jint count, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jfloat* storage = env->GetFloatArrayElements(points, NULL);
     renderer->drawPoints(storage + offset, count, paint);
     env->ReleaseFloatArrayElements(points, storage, 0);
 }
 
 static void android_view_GLES20Canvas_drawPath(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkPath* path, SkPaint* paint) {
+        jlong rendererHandle, jlong pathHandle, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     renderer->drawPath(path, paint);
 }
 
 static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloatArray points, jint offset, jint count, SkPaint* paint) {
+        jlong rendererHandle, jfloatArray points, jint offset, jint count, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jfloat* storage = env->GetFloatArrayElements(points, NULL);
     renderer->drawLines(storage + offset, count, paint);
     env->ReleaseFloatArrayElements(points, storage, 0);
@@ -547,24 +642,30 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_resetModifiers(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint modifiers) {
+        jlong rendererHandle, jint modifiers) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     if (modifiers & MODIFIER_SHADOW) renderer->resetShadow();
     if (modifiers & MODIFIER_SHADER) renderer->resetShader();
     if (modifiers & MODIFIER_COLOR_FILTER) renderer->resetColorFilter();
 }
 
 static void android_view_GLES20Canvas_setupShader(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkiaShader* shader) {
+        jlong rendererHandle, jlong shaderHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkiaShader* shader = reinterpret_cast<SkiaShader*>(shaderHandle);
     renderer->setupShader(shader);
 }
 
 static void android_view_GLES20Canvas_setupColorFilter(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, SkiaColorFilter* filter) {
+        jlong rendererHandle, jlong filterHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkiaColorFilter* filter = reinterpret_cast<SkiaColorFilter*>(filterHandle);
     renderer->setupColorFilter(filter);
 }
 
 static void android_view_GLES20Canvas_setupShadow(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jfloat radius, jfloat dx, jfloat dy, jint color) {
+        jlong rendererHandle, jfloat radius, jfloat dx, jfloat dy, jint color) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->setupShadow(radius, dx, dy, color);
 }
 
@@ -573,12 +674,14 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_setupPaintFilter(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jint clearBits, jint setBits) {
+        jlong rendererHandle, jint clearBits, jint setBits) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->setupPaintFilter(clearBits, setBits);
 }
 
 static void android_view_GLES20Canvas_resetPaintFilter(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->resetPaintFilter();
 }
 
@@ -658,24 +761,31 @@
 }
 
 static void android_view_GLES20Canvas_drawTextArray(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jcharArray text, jint index, jint count,
-        jfloat x, jfloat y, jint flags, SkPaint* paint) {
+        jlong rendererHandle, jcharArray text, jint index, jint count,
+        jfloat x, jfloat y, jint flags, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jchar* textArray = env->GetCharArrayElements(text, NULL);
     renderText(renderer, textArray + index, count, x, y, flags, paint);
     env->ReleaseCharArrayElements(text, textArray, JNI_ABORT);
 }
 
 static void android_view_GLES20Canvas_drawText(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jstring text, jint start, jint end,
-        jfloat x, jfloat y, jint flags, SkPaint* paint) {
+        jlong rendererHandle, jstring text, jint start, jint end,
+        jfloat x, jfloat y, jint flags, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     const jchar* textArray = env->GetStringChars(text, NULL);
     renderText(renderer, textArray + start, end - start, x, y, flags, paint);
     env->ReleaseStringChars(text, textArray);
 }
 
 static void android_view_GLES20Canvas_drawTextArrayOnPath(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jcharArray text, jint index, jint count,
-        SkPath* path, jfloat hOffset, jfloat vOffset, jint flags, SkPaint* paint) {
+        jlong rendererHandle, jcharArray text, jint index, jint count,
+        jlong pathHandle, jfloat hOffset, jfloat vOffset, jint flags, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jchar* textArray = env->GetCharArrayElements(text, NULL);
     renderTextOnPath(renderer, textArray + index, count, path,
             hOffset, vOffset, flags, paint);
@@ -683,8 +793,11 @@
 }
 
 static void android_view_GLES20Canvas_drawTextOnPath(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jstring text, jint start, jint end,
-        SkPath* path, jfloat hOffset, jfloat vOffset, jint flags, SkPaint* paint) {
+        jlong rendererHandle, jstring text, jint start, jint end,
+        jlong pathHandle, jfloat hOffset, jfloat vOffset, jint flags, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     const jchar* textArray = env->GetStringChars(text, NULL);
     renderTextOnPath(renderer, textArray + start, end - start, path,
             hOffset, vOffset, flags, paint);
@@ -692,9 +805,11 @@
 }
 
 static void android_view_GLES20Canvas_drawTextRunArray(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jcharArray text, jint index, jint count,
+        jlong rendererHandle, jcharArray text, jint index, jint count,
         jint contextIndex, jint contextCount, jfloat x, jfloat y, jint dirFlags,
-        SkPaint* paint) {
+        jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jchar* textArray = env->GetCharArrayElements(text, NULL);
     renderTextRun(renderer, textArray + contextIndex, index - contextIndex,
             count, contextCount, x, y, dirFlags, paint);
@@ -702,9 +817,11 @@
  }
 
 static void android_view_GLES20Canvas_drawTextRun(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jstring text, jint start, jint end,
-        jint contextStart, int contextEnd, jfloat x, jfloat y, jint dirFlags,
-        SkPaint* paint) {
+        jlong rendererHandle, jstring text, jint start, jint end,
+        jint contextStart, jint contextEnd, jfloat x, jfloat y, jint dirFlags,
+        jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     const jchar* textArray = env->GetStringChars(text, NULL);
     jint count = end - start;
     jint contextCount = contextEnd - contextStart;
@@ -729,8 +846,10 @@
 }
 
 static void android_view_GLES20Canvas_drawPosTextArray(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jcharArray text, jint index, jint count,
-        jfloatArray pos, SkPaint* paint) {
+        jlong rendererHandle, jcharArray text, jint index, jint count,
+        jfloatArray pos, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     jchar* textArray = env->GetCharArrayElements(text, NULL);
     jfloat* positions = env->GetFloatArrayElements(pos, NULL);
 
@@ -741,8 +860,10 @@
 }
 
 static void android_view_GLES20Canvas_drawPosText(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, jstring text, jint start, jint end,
-        jfloatArray pos, SkPaint* paint) {
+        jlong rendererHandle, jstring text, jint start, jint end,
+        jfloatArray pos, jlong paintHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     const jchar* textArray = env->GetStringChars(text, NULL);
     jfloat* positions = env->GetFloatArrayElements(pos, NULL);
 
@@ -756,24 +877,31 @@
 // Display lists
 // ----------------------------------------------------------------------------
 
-static DisplayList* android_view_GLES20Canvas_getDisplayList(JNIEnv* env,
-        jobject clazz, DisplayListRenderer* renderer, DisplayList* displayList) {
-    return renderer->getDisplayList(displayList);
+static jlong android_view_GLES20Canvas_getDisplayList(JNIEnv* env,
+        jobject clazz, jlong rendererHandle, jlong displayListHandle) {
+    DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererHandle);
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
+    DisplayList* list = renderer->getDisplayList(displayList);
+    return reinterpret_cast<jlong>(list);
 }
 
-static OpenGLRenderer* android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env,
+static jlong android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env,
         jobject clazz) {
-    return new DisplayListRenderer;
+    OpenGLRenderer* renderer = new DisplayListRenderer;
+    return reinterpret_cast<jlong>(renderer);
 }
 
 static void android_view_GLES20Canvas_resetDisplayListRenderer(JNIEnv* env,
-        jobject clazz, DisplayListRenderer* renderer) {
+        jobject clazz, jlong rendererHandle) {
+    DisplayListRenderer* renderer = reinterpret_cast<DisplayListRenderer*>(rendererHandle);
     renderer->reset();
 }
 
 static jint android_view_GLES20Canvas_drawDisplayList(JNIEnv* env,
-        jobject clazz, OpenGLRenderer* renderer, DisplayList* displayList,
+        jobject clazz, jlong rendererHandle, jlong displayListHandle,
         jobject dirty, jint flags) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     android::uirenderer::Rect bounds;
     status_t status = renderer->drawDisplayList(displayList, bounds, flags);
     if (status != DrawGlInfo::kStatusDone && dirty != NULL) {
@@ -784,7 +912,9 @@
 }
 
 static void android_view_GLES20Canvas_outputDisplayList(JNIEnv* env,
-        jobject clazz, OpenGLRenderer* renderer, DisplayList* displayList) {
+        jobject clazz, jlong rendererHandle, jlong displayListHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     renderer->outputDisplayList(displayList);
 }
 
@@ -793,26 +923,29 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20Canvas_interrupt(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->interrupt();
 }
 
 static void android_view_GLES20Canvas_resume(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->resume();
 }
 
-static OpenGLRenderer* android_view_GLES20Canvas_createLayerRenderer(JNIEnv* env,
-        jobject clazz, Layer* layer) {
+static jlong android_view_GLES20Canvas_createLayerRenderer(JNIEnv* env,
+        jobject clazz, jlong layerHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     if (layer) {
         OpenGLRenderer* renderer = new LayerRenderer(layer);
         renderer->initProperties();
-        return renderer;
+        return reinterpret_cast<jlong>(renderer);
     }
     return NULL;
 }
 
-static Layer* android_view_GLES20Canvas_createTextureLayer(JNIEnv* env, jobject clazz,
+static jlong android_view_GLES20Canvas_createTextureLayer(JNIEnv* env, jobject clazz,
         jboolean isOpaque, jintArray layerInfo) {
     Layer* layer = LayerRenderer::createTextureLayer(isOpaque);
 
@@ -822,10 +955,10 @@
         env->ReleaseIntArrayElements(layerInfo, storage, 0);
     }
 
-    return layer;
+    return reinterpret_cast<jlong>(layer);
 }
 
-static Layer* android_view_GLES20Canvas_createLayer(JNIEnv* env, jobject clazz,
+static jlong android_view_GLES20Canvas_createLayer(JNIEnv* env, jobject clazz,
         jint width, jint height, jboolean isOpaque, jintArray layerInfo) {
     Layer* layer = LayerRenderer::createLayer(width, height, isOpaque);
 
@@ -836,44 +969,51 @@
         env->ReleaseIntArrayElements(layerInfo, storage, 0);
     }
 
-    return layer;
+    return reinterpret_cast<jlong>(layer);
 }
 
-static bool android_view_GLES20Canvas_resizeLayer(JNIEnv* env, jobject clazz,
-        Layer* layer, jint width, jint height, jintArray layerInfo) {
+static jboolean android_view_GLES20Canvas_resizeLayer(JNIEnv* env, jobject clazz,
+        jlong layerHandle, jint width, jint height, jintArray layerInfo) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     if (LayerRenderer::resizeLayer(layer, width, height)) {
         jint* storage = env->GetIntArrayElements(layerInfo, NULL);
         storage[0] = layer->getWidth();
         storage[1] = layer->getHeight();
         env->ReleaseIntArrayElements(layerInfo, storage, 0);
-        return true;
+        return JNI_TRUE;
     }
-    return false;
+    return JNI_FALSE;
 }
 
 static void android_view_GLES20Canvas_setLayerPaint(JNIEnv* env, jobject clazz,
-        Layer* layer, SkPaint* paint) {
+        jlong layerHandle, jlong paintHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
+    SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
     if (layer) {
         layer->setPaint(paint);
     }
 }
 
 static void android_view_GLES20Canvas_setLayerColorFilter(JNIEnv* env, jobject clazz,
-        Layer* layer, SkiaColorFilter* colorFilter) {
+        jlong layerHandle, jlong colorFilterHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
+    SkiaColorFilter* colorFilter = reinterpret_cast<SkiaColorFilter*>(colorFilterHandle);
     if (layer) {
         layer->setColorFilter(colorFilter);
     }
 }
 
 static void android_view_GLES20Canvas_setOpaqueLayer(JNIEnv* env, jobject clazz,
-        Layer* layer, jboolean isOpaque) {
+        jlong layerHandle, jboolean isOpaque) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     if (layer) {
         layer->setBlend(!isOpaque);
     }
 }
 
 static void android_view_GLES20Canvas_updateTextureLayer(JNIEnv* env, jobject clazz,
-        Layer* layer, jint width, jint height, jboolean isOpaque, jobject surface) {
+        jlong layerHandle, jint width, jint height, jboolean isOpaque, jobject surface) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     float transform[16];
     sp<GLConsumer> surfaceTexture(SurfaceTexture_getSurfaceTexture(env, surface));
 
@@ -903,57 +1043,75 @@
 }
 
 static void android_view_GLES20Canvas_updateRenderLayer(JNIEnv* env, jobject clazz,
-        Layer* layer, OpenGLRenderer* renderer, DisplayList* displayList,
+        jlong layerHandle, jlong rendererHandle, jlong displayListHandle,
         jint left, jint top, jint right, jint bottom) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     layer->updateDeferred(renderer, displayList, left, top, right, bottom);
 }
 
 static void android_view_GLES20Canvas_clearLayerTexture(JNIEnv* env, jobject clazz,
-        Layer* layer) {
+        jlong layerHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     layer->clearTexture();
 }
 
 static void android_view_GLES20Canvas_setTextureLayerTransform(JNIEnv* env, jobject clazz,
-        Layer* layer, SkMatrix* matrix) {
+        jlong layerHandle, jlong matrixHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     layer->getTransform().load(*matrix);
 }
 
-static void android_view_GLES20Canvas_destroyLayer(JNIEnv* env, jobject clazz, Layer* layer) {
+static void android_view_GLES20Canvas_destroyLayer(JNIEnv* env, jobject clazz, jlong layerHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     LayerRenderer::destroyLayer(layer);
 }
 
 static void android_view_GLES20Canvas_destroyLayerDeferred(JNIEnv* env,
-        jobject clazz, Layer* layer) {
+        jobject clazz, jlong layerHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     LayerRenderer::destroyLayerDeferred(layer);
 }
 
 static void android_view_GLES20Canvas_drawLayer(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, Layer* layer, jfloat x, jfloat y) {
+        jlong rendererHandle, jlong layerHandle, jfloat x, jfloat y) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     renderer->drawLayer(layer, x, y);
 }
 
 static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz,
-        Layer* layer, SkBitmap* bitmap) {
+        jlong layerHandle, jlong bitmapHandle) {
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
+    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
     return LayerRenderer::copyLayer(layer, bitmap);
 }
 
 static void android_view_GLES20Canvas_pushLayerUpdate(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, Layer* layer) {
+        jlong rendererHandle, jlong layerHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     renderer->pushLayerUpdate(layer);
 }
 
 static void android_view_GLES20Canvas_cancelLayerUpdate(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer, Layer* layer) {
+        jlong rendererHandle, jlong layerHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
+    Layer* layer = reinterpret_cast<Layer*>(layerHandle);
     renderer->cancelLayerUpdate(layer);
 }
 
 static void android_view_GLES20Canvas_clearLayerUpdates(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->clearLayerUpdates();
 }
 
 static void android_view_GLES20Canvas_flushLayerUpdates(JNIEnv* env, jobject clazz,
-        OpenGLRenderer* renderer) {
+        jlong rendererHandle) {
+    OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererHandle);
     renderer->flushLayerUpdates();
 }
 
@@ -1008,132 +1166,132 @@
     { "nInitAtlas",         "(Landroid/view/GraphicBuffer;[II)V",
             (void*) android_view_GLES20Canvas_initAtlas },
 
-    { "nCreateRenderer",    "()I",             (void*) android_view_GLES20Canvas_createRenderer },
-    { "nDestroyRenderer",   "(I)V",            (void*) android_view_GLES20Canvas_destroyRenderer },
-    { "nSetViewport",       "(III)V",          (void*) android_view_GLES20Canvas_setViewport },
-    { "nPrepare",           "(IZ)I",           (void*) android_view_GLES20Canvas_prepare },
-    { "nPrepareDirty",      "(IIIIIZ)I",       (void*) android_view_GLES20Canvas_prepareDirty },
-    { "nFinish",            "(I)V",            (void*) android_view_GLES20Canvas_finish },
-    { "nSetName",           "(ILjava/lang/String;)V",
+    { "nCreateRenderer",    "()J",             (void*) android_view_GLES20Canvas_createRenderer },
+    { "nDestroyRenderer",   "(J)V",            (void*) android_view_GLES20Canvas_destroyRenderer },
+    { "nSetViewport",       "(JII)V",          (void*) android_view_GLES20Canvas_setViewport },
+    { "nPrepare",           "(JZ)I",           (void*) android_view_GLES20Canvas_prepare },
+    { "nPrepareDirty",      "(JIIIIZ)I",       (void*) android_view_GLES20Canvas_prepareDirty },
+    { "nFinish",            "(J)V",            (void*) android_view_GLES20Canvas_finish },
+    { "nSetName",           "(JLjava/lang/String;)V",
             (void*) android_view_GLES20Canvas_setName },
 
-    { "nSetCountOverdrawEnabled", "(IZ)V",     (void*) android_view_GLES20Canvas_setCountOverdrawEnabled },
-    { "nGetOverdraw",             "(I)F",      (void*) android_view_GLES20Canvas_getOverdraw },
+    { "nSetCountOverdrawEnabled", "(JZ)V",     (void*) android_view_GLES20Canvas_setCountOverdrawEnabled },
+    { "nGetOverdraw",             "(J)F",      (void*) android_view_GLES20Canvas_getOverdraw },
 
     { "nGetStencilSize",    "()I",             (void*) android_view_GLES20Canvas_getStencilSize },
 
-    { "nCallDrawGLFunction", "(II)I",          (void*) android_view_GLES20Canvas_callDrawGLFunction },
-    { "nDetachFunctor",      "(II)V",          (void*) android_view_GLES20Canvas_detachFunctor },
-    { "nAttachFunctor",      "(II)V",          (void*) android_view_GLES20Canvas_attachFunctor },
-    { "nInvokeFunctors",     "(ILandroid/graphics/Rect;)I",
+    { "nCallDrawGLFunction", "(JJ)I",          (void*) android_view_GLES20Canvas_callDrawGLFunction },
+    { "nDetachFunctor",      "(JJ)V",          (void*) android_view_GLES20Canvas_detachFunctor },
+    { "nAttachFunctor",      "(JJ)V",          (void*) android_view_GLES20Canvas_attachFunctor },
+    { "nInvokeFunctors",     "(JLandroid/graphics/Rect;)I",
             (void*) android_view_GLES20Canvas_invokeFunctors },
 
-    { "nSave",              "(II)I",           (void*) android_view_GLES20Canvas_save },
-    { "nRestore",           "(I)V",            (void*) android_view_GLES20Canvas_restore },
-    { "nRestoreToCount",    "(II)V",           (void*) android_view_GLES20Canvas_restoreToCount },
-    { "nGetSaveCount",      "(I)I",            (void*) android_view_GLES20Canvas_getSaveCount },
+    { "nSave",              "(JI)I",           (void*) android_view_GLES20Canvas_save },
+    { "nRestore",           "(J)V",            (void*) android_view_GLES20Canvas_restore },
+    { "nRestoreToCount",    "(JI)V",           (void*) android_view_GLES20Canvas_restoreToCount },
+    { "nGetSaveCount",      "(J)I",            (void*) android_view_GLES20Canvas_getSaveCount },
 
-    { "nSaveLayer",         "(IFFFFII)I",      (void*) android_view_GLES20Canvas_saveLayer },
-    { "nSaveLayer",         "(III)I",          (void*) android_view_GLES20Canvas_saveLayerClip },
-    { "nSaveLayerAlpha",    "(IFFFFII)I",      (void*) android_view_GLES20Canvas_saveLayerAlpha },
-    { "nSaveLayerAlpha",    "(III)I",          (void*) android_view_GLES20Canvas_saveLayerAlphaClip },
+    { "nSaveLayer",         "(JFFFFJI)I",      (void*) android_view_GLES20Canvas_saveLayer },
+    { "nSaveLayer",         "(JJI)I",          (void*) android_view_GLES20Canvas_saveLayerClip },
+    { "nSaveLayerAlpha",    "(JFFFFII)I",      (void*) android_view_GLES20Canvas_saveLayerAlpha },
+    { "nSaveLayerAlpha",    "(JII)I",          (void*) android_view_GLES20Canvas_saveLayerAlphaClip },
 
-    { "nQuickReject",       "(IFFFF)Z",        (void*) android_view_GLES20Canvas_quickReject },
-    { "nClipRect",          "(IFFFFI)Z",       (void*) android_view_GLES20Canvas_clipRectF },
-    { "nClipRect",          "(IIIIII)Z",       (void*) android_view_GLES20Canvas_clipRect },
-    { "nClipPath",          "(III)Z",          (void*) android_view_GLES20Canvas_clipPath },
-    { "nClipRegion",        "(III)Z",          (void*) android_view_GLES20Canvas_clipRegion },
+    { "nQuickReject",       "(JFFFF)Z",        (void*) android_view_GLES20Canvas_quickReject },
+    { "nClipRect",          "(JFFFFI)Z",       (void*) android_view_GLES20Canvas_clipRectF },
+    { "nClipRect",          "(JIIIII)Z",       (void*) android_view_GLES20Canvas_clipRect },
+    { "nClipPath",          "(JJI)Z",          (void*) android_view_GLES20Canvas_clipPath },
+    { "nClipRegion",        "(JJI)Z",          (void*) android_view_GLES20Canvas_clipRegion },
 
-    { "nTranslate",         "(IFF)V",          (void*) android_view_GLES20Canvas_translate },
-    { "nRotate",            "(IF)V",           (void*) android_view_GLES20Canvas_rotate },
-    { "nScale",             "(IFF)V",          (void*) android_view_GLES20Canvas_scale },
-    { "nSkew",              "(IFF)V",          (void*) android_view_GLES20Canvas_skew },
+    { "nTranslate",         "(JFF)V",          (void*) android_view_GLES20Canvas_translate },
+    { "nRotate",            "(JF)V",           (void*) android_view_GLES20Canvas_rotate },
+    { "nScale",             "(JFF)V",          (void*) android_view_GLES20Canvas_scale },
+    { "nSkew",              "(JFF)V",          (void*) android_view_GLES20Canvas_skew },
 
-    { "nSetMatrix",         "(II)V",           (void*) android_view_GLES20Canvas_setMatrix },
-    { "nGetMatrix",         "(II)V",           (void*) android_view_GLES20Canvas_getMatrix },
-    { "nConcatMatrix",      "(II)V",           (void*) android_view_GLES20Canvas_concatMatrix },
+    { "nSetMatrix",         "(JJ)V",           (void*) android_view_GLES20Canvas_setMatrix },
+    { "nGetMatrix",         "(JJ)V",           (void*) android_view_GLES20Canvas_getMatrix },
+    { "nConcatMatrix",      "(JJ)V",           (void*) android_view_GLES20Canvas_concatMatrix },
 
-    { "nDrawBitmap",        "(II[BFFI)V",      (void*) android_view_GLES20Canvas_drawBitmap },
-    { "nDrawBitmap",        "(II[BFFFFFFFFI)V",(void*) android_view_GLES20Canvas_drawBitmapRect },
-    { "nDrawBitmap",        "(II[BII)V",       (void*) android_view_GLES20Canvas_drawBitmapMatrix },
-    { "nDrawBitmap",        "(I[IIIFFIIZI)V",  (void*) android_view_GLES20Canvas_drawBitmapData },
+    { "nDrawBitmap",        "(JJ[BFFJ)V",      (void*) android_view_GLES20Canvas_drawBitmap },
+    { "nDrawBitmap",        "(JJ[BFFFFFFFFJ)V",(void*) android_view_GLES20Canvas_drawBitmapRect },
+    { "nDrawBitmap",        "(JJ[BJJ)V",       (void*) android_view_GLES20Canvas_drawBitmapMatrix },
+    { "nDrawBitmap",        "(J[IIIFFIIZJ)V",  (void*) android_view_GLES20Canvas_drawBitmapData },
 
-    { "nDrawBitmapMesh",    "(II[BII[FI[III)V",(void*) android_view_GLES20Canvas_drawBitmapMesh },
+    { "nDrawBitmapMesh",    "(JJ[BII[FI[IIJ)V",(void*) android_view_GLES20Canvas_drawBitmapMesh },
 
-    { "nDrawPatch",         "(II[BIFFFFI)V",   (void*) android_view_GLES20Canvas_drawPatch },
+    { "nDrawPatch",         "(JJ[BJFFFFJ)V",   (void*) android_view_GLES20Canvas_drawPatch },
 
-    { "nDrawColor",         "(III)V",          (void*) android_view_GLES20Canvas_drawColor },
-    { "nDrawRect",          "(IFFFFI)V",       (void*) android_view_GLES20Canvas_drawRect },
-    { "nDrawRects",         "(III)V",          (void*) android_view_GLES20Canvas_drawRegionAsRects },
-    { "nDrawRects",         "(I[FII)V",        (void*) android_view_GLES20Canvas_drawRects },
-    { "nDrawRoundRect",     "(IFFFFFFI)V",     (void*) android_view_GLES20Canvas_drawRoundRect },
-    { "nDrawCircle",        "(IFFFI)V",        (void*) android_view_GLES20Canvas_drawCircle },
-    { "nDrawOval",          "(IFFFFI)V",       (void*) android_view_GLES20Canvas_drawOval },
-    { "nDrawArc",           "(IFFFFFFZI)V",    (void*) android_view_GLES20Canvas_drawArc },
-    { "nDrawPoints",        "(I[FIII)V",       (void*) android_view_GLES20Canvas_drawPoints },
+    { "nDrawColor",         "(JII)V",          (void*) android_view_GLES20Canvas_drawColor },
+    { "nDrawRect",          "(JFFFFJ)V",       (void*) android_view_GLES20Canvas_drawRect },
+    { "nDrawRects",         "(JJJ)V",          (void*) android_view_GLES20Canvas_drawRegionAsRects },
+    { "nDrawRects",         "(J[FIJ)V",        (void*) android_view_GLES20Canvas_drawRects },
+    { "nDrawRoundRect",     "(JFFFFFFJ)V",     (void*) android_view_GLES20Canvas_drawRoundRect },
+    { "nDrawCircle",        "(JFFFJ)V",        (void*) android_view_GLES20Canvas_drawCircle },
+    { "nDrawOval",          "(JFFFFJ)V",       (void*) android_view_GLES20Canvas_drawOval },
+    { "nDrawArc",           "(JFFFFFFZJ)V",    (void*) android_view_GLES20Canvas_drawArc },
+    { "nDrawPoints",        "(J[FIIJ)V",       (void*) android_view_GLES20Canvas_drawPoints },
 
-    { "nDrawPath",          "(III)V",          (void*) android_view_GLES20Canvas_drawPath },
-    { "nDrawLines",         "(I[FIII)V",       (void*) android_view_GLES20Canvas_drawLines },
+    { "nDrawPath",          "(JJJ)V",          (void*) android_view_GLES20Canvas_drawPath },
+    { "nDrawLines",         "(J[FIIJ)V",       (void*) android_view_GLES20Canvas_drawLines },
 
-    { "nResetModifiers",    "(II)V",           (void*) android_view_GLES20Canvas_resetModifiers },
-    { "nSetupShader",       "(II)V",           (void*) android_view_GLES20Canvas_setupShader },
-    { "nSetupColorFilter",  "(II)V",           (void*) android_view_GLES20Canvas_setupColorFilter },
-    { "nSetupShadow",       "(IFFFI)V",        (void*) android_view_GLES20Canvas_setupShadow },
+    { "nResetModifiers",    "(JI)V",           (void*) android_view_GLES20Canvas_resetModifiers },
+    { "nSetupShader",       "(JJ)V",           (void*) android_view_GLES20Canvas_setupShader },
+    { "nSetupColorFilter",  "(JJ)V",           (void*) android_view_GLES20Canvas_setupColorFilter },
+    { "nSetupShadow",       "(JFFFI)V",        (void*) android_view_GLES20Canvas_setupShadow },
 
-    { "nSetupPaintFilter",  "(III)V",          (void*) android_view_GLES20Canvas_setupPaintFilter },
-    { "nResetPaintFilter",  "(I)V",            (void*) android_view_GLES20Canvas_resetPaintFilter },
+    { "nSetupPaintFilter",  "(JII)V",          (void*) android_view_GLES20Canvas_setupPaintFilter },
+    { "nResetPaintFilter",  "(J)V",            (void*) android_view_GLES20Canvas_resetPaintFilter },
 
-    { "nDrawText",          "(I[CIIFFII)V",    (void*) android_view_GLES20Canvas_drawTextArray },
-    { "nDrawText",          "(ILjava/lang/String;IIFFII)V",
+    { "nDrawText",          "(J[CIIFFIJ)V",    (void*) android_view_GLES20Canvas_drawTextArray },
+    { "nDrawText",          "(JLjava/lang/String;IIFFIJ)V",
             (void*) android_view_GLES20Canvas_drawText },
 
-    { "nDrawTextOnPath",    "(I[CIIIFFII)V",   (void*) android_view_GLES20Canvas_drawTextArrayOnPath },
-    { "nDrawTextOnPath",    "(ILjava/lang/String;IIIFFII)V",
+    { "nDrawTextOnPath",    "(J[CIIJFFIJ)V",   (void*) android_view_GLES20Canvas_drawTextArrayOnPath },
+    { "nDrawTextOnPath",    "(JLjava/lang/String;IIJFFIJ)V",
             (void*) android_view_GLES20Canvas_drawTextOnPath },
 
-    { "nDrawTextRun",       "(I[CIIIIFFII)V",  (void*) android_view_GLES20Canvas_drawTextRunArray },
-    { "nDrawTextRun",       "(ILjava/lang/String;IIIIFFII)V",
+    { "nDrawTextRun",       "(J[CIIIIFFIJ)V",  (void*) android_view_GLES20Canvas_drawTextRunArray },
+    { "nDrawTextRun",       "(JLjava/lang/String;IIIIFFIJ)V",
             (void*) android_view_GLES20Canvas_drawTextRun },
 
-    { "nDrawPosText",       "(I[CII[FI)V",     (void*) android_view_GLES20Canvas_drawPosTextArray },
-    { "nDrawPosText",       "(ILjava/lang/String;II[FI)V",
+    { "nDrawPosText",       "(J[CII[FJ)V",     (void*) android_view_GLES20Canvas_drawPosTextArray },
+    { "nDrawPosText",       "(JLjava/lang/String;II[FJ)V",
             (void*) android_view_GLES20Canvas_drawPosText },
 
-    { "nGetClipBounds",     "(ILandroid/graphics/Rect;)Z",
+    { "nGetClipBounds",     "(JLandroid/graphics/Rect;)Z",
             (void*) android_view_GLES20Canvas_getClipBounds },
 
-    { "nGetDisplayList",         "(II)I",      (void*) android_view_GLES20Canvas_getDisplayList },
-    { "nOutputDisplayList",      "(II)V",      (void*) android_view_GLES20Canvas_outputDisplayList },
-    { "nDrawDisplayList",        "(IILandroid/graphics/Rect;I)I",
+    { "nGetDisplayList",         "(JJ)J",      (void*) android_view_GLES20Canvas_getDisplayList },
+    { "nOutputDisplayList",      "(JJ)V",      (void*) android_view_GLES20Canvas_outputDisplayList },
+    { "nDrawDisplayList",        "(JJLandroid/graphics/Rect;I)I",
             (void*) android_view_GLES20Canvas_drawDisplayList },
 
-    { "nCreateDisplayListRenderer", "()I",     (void*) android_view_GLES20Canvas_createDisplayListRenderer },
-    { "nResetDisplayListRenderer",  "(I)V",    (void*) android_view_GLES20Canvas_resetDisplayListRenderer },
+    { "nCreateDisplayListRenderer", "()J",     (void*) android_view_GLES20Canvas_createDisplayListRenderer },
+    { "nResetDisplayListRenderer",  "(J)V",    (void*) android_view_GLES20Canvas_resetDisplayListRenderer },
 
-    { "nInterrupt",              "(I)V",       (void*) android_view_GLES20Canvas_interrupt },
-    { "nResume",                 "(I)V",       (void*) android_view_GLES20Canvas_resume },
+    { "nInterrupt",              "(J)V",       (void*) android_view_GLES20Canvas_interrupt },
+    { "nResume",                 "(J)V",       (void*) android_view_GLES20Canvas_resume },
 
-    { "nCreateLayerRenderer",    "(I)I",       (void*) android_view_GLES20Canvas_createLayerRenderer },
-    { "nCreateLayer",            "(IIZ[I)I",   (void*) android_view_GLES20Canvas_createLayer },
-    { "nResizeLayer",            "(III[I)Z" ,  (void*) android_view_GLES20Canvas_resizeLayer },
-    { "nSetLayerPaint",          "(II)V",      (void*) android_view_GLES20Canvas_setLayerPaint },
-    { "nSetLayerColorFilter",    "(II)V",      (void*) android_view_GLES20Canvas_setLayerColorFilter },
-    { "nSetOpaqueLayer",         "(IZ)V",      (void*) android_view_GLES20Canvas_setOpaqueLayer },
-    { "nCreateTextureLayer",     "(Z[I)I",     (void*) android_view_GLES20Canvas_createTextureLayer },
-    { "nUpdateTextureLayer",     "(IIIZLandroid/graphics/SurfaceTexture;)V",
+    { "nCreateLayerRenderer",    "(J)J",       (void*) android_view_GLES20Canvas_createLayerRenderer },
+    { "nCreateLayer",            "(IIZ[I)J",   (void*) android_view_GLES20Canvas_createLayer },
+    { "nResizeLayer",            "(JII[I)Z" ,  (void*) android_view_GLES20Canvas_resizeLayer },
+    { "nSetLayerPaint",          "(JJ)V",      (void*) android_view_GLES20Canvas_setLayerPaint },
+    { "nSetLayerColorFilter",    "(JJ)V",      (void*) android_view_GLES20Canvas_setLayerColorFilter },
+    { "nSetOpaqueLayer",         "(JZ)V",      (void*) android_view_GLES20Canvas_setOpaqueLayer },
+    { "nCreateTextureLayer",     "(Z[I)J",     (void*) android_view_GLES20Canvas_createTextureLayer },
+    { "nUpdateTextureLayer",     "(JIIZLandroid/graphics/SurfaceTexture;)V",
             (void*) android_view_GLES20Canvas_updateTextureLayer },
-    { "nUpdateRenderLayer",      "(IIIIIII)V", (void*) android_view_GLES20Canvas_updateRenderLayer },
-    { "nClearLayerTexture",      "(I)V",       (void*) android_view_GLES20Canvas_clearLayerTexture },
-    { "nDestroyLayer",           "(I)V",       (void*) android_view_GLES20Canvas_destroyLayer },
-    { "nDestroyLayerDeferred",   "(I)V",       (void*) android_view_GLES20Canvas_destroyLayerDeferred },
-    { "nDrawLayer",              "(IIFF)V",    (void*) android_view_GLES20Canvas_drawLayer },
-    { "nCopyLayer",              "(II)Z",      (void*) android_view_GLES20Canvas_copyLayer },
-    { "nClearLayerUpdates",      "(I)V",       (void*) android_view_GLES20Canvas_clearLayerUpdates },
-    { "nFlushLayerUpdates",      "(I)V",       (void*) android_view_GLES20Canvas_flushLayerUpdates },
-    { "nPushLayerUpdate",        "(II)V",      (void*) android_view_GLES20Canvas_pushLayerUpdate },
-    { "nCancelLayerUpdate",      "(II)V",      (void*) android_view_GLES20Canvas_cancelLayerUpdate },
+    { "nUpdateRenderLayer",      "(JJJIIII)V", (void*) android_view_GLES20Canvas_updateRenderLayer },
+    { "nClearLayerTexture",      "(J)V",       (void*) android_view_GLES20Canvas_clearLayerTexture },
+    { "nDestroyLayer",           "(J)V",       (void*) android_view_GLES20Canvas_destroyLayer },
+    { "nDestroyLayerDeferred",   "(J)V",       (void*) android_view_GLES20Canvas_destroyLayerDeferred },
+    { "nDrawLayer",              "(JJFF)V",    (void*) android_view_GLES20Canvas_drawLayer },
+    { "nCopyLayer",              "(JJ)Z",      (void*) android_view_GLES20Canvas_copyLayer },
+    { "nClearLayerUpdates",      "(J)V",       (void*) android_view_GLES20Canvas_clearLayerUpdates },
+    { "nFlushLayerUpdates",      "(J)V",       (void*) android_view_GLES20Canvas_flushLayerUpdates },
+    { "nPushLayerUpdate",        "(JJ)V",      (void*) android_view_GLES20Canvas_pushLayerUpdate },
+    { "nCancelLayerUpdate",      "(JJ)V",      (void*) android_view_GLES20Canvas_cancelLayerUpdate },
 
-    { "nSetTextureLayerTransform", "(II)V",    (void*) android_view_GLES20Canvas_setTextureLayerTransform },
+    { "nSetTextureLayerTransform", "(JJ)V",    (void*) android_view_GLES20Canvas_setTextureLayerTransform },
 
     { "nGetMaximumTextureWidth",  "()I",       (void*) android_view_GLES20Canvas_getMaxTextureWidth },
     { "nGetMaximumTextureHeight", "()I",       (void*) android_view_GLES20Canvas_getMaxTextureHeight },
diff --git a/core/jni/android_view_GLES20DisplayList.cpp b/core/jni/android_view_GLES20DisplayList.cpp
index 4ce2e24..8e19efd 100644
--- a/core/jni/android_view_GLES20DisplayList.cpp
+++ b/core/jni/android_view_GLES20DisplayList.cpp
@@ -42,17 +42,20 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20DisplayList_reset(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->reset();
 }
 
 static jint android_view_GLES20DisplayList_getDisplayListSize(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getSize();
 }
 
 static void android_view_GLES20DisplayList_setDisplayListName(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, jstring name) {
+        jobject clazz, jlong displayListHandle, jstring name) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     if (name != NULL) {
         const char* textArray = env->GetStringUTFChars(name, NULL);
         displayList->setName(textArray);
@@ -61,7 +64,8 @@
 }
 
 static void android_view_GLES20DisplayList_destroyDisplayList(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     DisplayList::destroyDisplayListDeferred(displayList);
 }
 
@@ -70,74 +74,91 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GLES20DisplayList_setCaching(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, jboolean caching) {
+        jobject clazz, jlong displayListHandle, jboolean caching) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setCaching(caching);
 }
 
+//serban
 static void android_view_GLES20DisplayList_setStaticMatrix(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
+        jobject clazz, jlong displayListHandle, jlong matrixHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     displayList->setStaticMatrix(matrix);
 }
 
 static void android_view_GLES20DisplayList_setAnimationMatrix(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
+        jobject clazz, jlong displayListHandle, jlong matrixHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     displayList->setAnimationMatrix(matrix);
 }
 
 static void android_view_GLES20DisplayList_setClipToBounds(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, jboolean clipToBounds) {
+        jobject clazz, jlong displayListHandle, jboolean clipToBounds) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setClipToBounds(clipToBounds);
 }
 
 static void android_view_GLES20DisplayList_setAlpha(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float alpha) {
+        jobject clazz, jlong displayListHandle, jfloat alpha) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setAlpha(alpha);
 }
 
 static void android_view_GLES20DisplayList_setHasOverlappingRendering(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, bool hasOverlappingRendering) {
+        jobject clazz, jlong displayListHandle, jboolean hasOverlappingRendering) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setHasOverlappingRendering(hasOverlappingRendering);
 }
 
 static void android_view_GLES20DisplayList_setTranslationX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float tx) {
+        jobject clazz, jlong displayListHandle, jfloat tx) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setTranslationX(tx);
 }
 
 static void android_view_GLES20DisplayList_setTranslationY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float ty) {
+        jobject clazz, jlong displayListHandle, jfloat ty) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setTranslationY(ty);
 }
 
 static void android_view_GLES20DisplayList_setRotation(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float rotation) {
+        jobject clazz, jlong displayListHandle, jfloat rotation) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setRotation(rotation);
 }
 
 static void android_view_GLES20DisplayList_setRotationX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float rx) {
+        jobject clazz, jlong displayListHandle, jfloat rx) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setRotationX(rx);
 }
 
 static void android_view_GLES20DisplayList_setRotationY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float ry) {
+        jobject clazz, jlong displayListHandle, jfloat ry) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setRotationY(ry);
 }
 
 static void android_view_GLES20DisplayList_setScaleX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float sx) {
+        jobject clazz, jlong displayListHandle, jfloat sx) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setScaleX(sx);
 }
 
 static void android_view_GLES20DisplayList_setScaleY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float sy) {
+        jobject clazz, jlong displayListHandle, jfloat sy) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setScaleY(sy);
 }
 
 static void android_view_GLES20DisplayList_setTransformationInfo(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float alpha,
-        float translationX, float translationY, float rotation, float rotationX, float rotationY,
-        float scaleX, float scaleY) {
+        jobject clazz, jlong displayListHandle, jfloat alpha,
+        jfloat translationX, jfloat translationY, jfloat rotation, jfloat rotationX, jfloat rotationY,
+        jfloat scaleX, jfloat scaleY) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setAlpha(alpha);
     displayList->setTranslationX(translationX);
     displayList->setTranslationY(translationY);
@@ -149,58 +170,70 @@
 }
 
 static void android_view_GLES20DisplayList_setPivotX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float px) {
+        jobject clazz, jlong displayListHandle, jfloat px) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setPivotX(px);
 }
 
 static void android_view_GLES20DisplayList_setPivotY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float py) {
+        jobject clazz, jlong displayListHandle, jfloat py) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setPivotY(py);
 }
 
 static void android_view_GLES20DisplayList_setCameraDistance(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float distance) {
+        jobject clazz, jlong displayListHandle, jfloat distance) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setCameraDistance(distance);
 }
 
 static void android_view_GLES20DisplayList_setLeft(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, int left) {
+        jobject clazz, jlong displayListHandle, jint left) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setLeft(left);
 }
 
 static void android_view_GLES20DisplayList_setTop(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, int top) {
+        jobject clazz, jlong displayListHandle, jint top) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setTop(top);
 }
 
 static void android_view_GLES20DisplayList_setRight(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, int right) {
+        jobject clazz, jlong displayListHandle, jint right) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setRight(right);
 }
 
 static void android_view_GLES20DisplayList_setBottom(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, int bottom) {
+        jobject clazz, jlong displayListHandle, jint bottom) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setBottom(bottom);
 }
 
 static void android_view_GLES20DisplayList_setLeftTopRightBottom(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, int left, int top,
+        jobject clazz, jlong displayListHandle, jint left, jint top,
         int right, int bottom) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->setLeftTopRightBottom(left, top, right, bottom);
 }
 
 static void android_view_GLES20DisplayList_offsetLeftAndRight(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float offset) {
+        jobject clazz, jlong displayListHandle, jfloat offset) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->offsetLeftRight(offset);
 }
 
 static void android_view_GLES20DisplayList_offsetTopAndBottom(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, float offset) {
+        jobject clazz, jlong displayListHandle, jfloat offset) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     displayList->offsetTopBottom(offset);
 }
 
 static void android_view_GLES20DisplayList_getMatrix(JNIEnv* env,
-        jobject clazz, DisplayList* displayList, SkMatrix* matrix) {
+        jobject clazz, jlong displayListHandle, jlong matrixHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
+    SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
     SkMatrix* source = displayList->getStaticMatrix();
     if (source) {
         matrix->setConcat(SkMatrix::I(), *source);
@@ -210,82 +243,98 @@
 }
 
 static jboolean android_view_GLES20DisplayList_hasOverlappingRendering(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->hasOverlappingRendering();
 }
 
 static jfloat android_view_GLES20DisplayList_getAlpha(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getAlpha();
 }
 
 static jfloat android_view_GLES20DisplayList_getLeft(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getLeft();
 }
 
 static jfloat android_view_GLES20DisplayList_getTop(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getTop();
 }
 
 static jfloat android_view_GLES20DisplayList_getRight(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getRight();
 }
 
 static jfloat android_view_GLES20DisplayList_getBottom(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getBottom();
 }
 
 static jfloat android_view_GLES20DisplayList_getCameraDistance(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getCameraDistance();
 }
 
 static jfloat android_view_GLES20DisplayList_getScaleX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getScaleX();
 }
 
 static jfloat android_view_GLES20DisplayList_getScaleY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getScaleY();
 }
 
 static jfloat android_view_GLES20DisplayList_getTranslationX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getTranslationX();
 }
 
 static jfloat android_view_GLES20DisplayList_getTranslationY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getTranslationY();
 }
 
 static jfloat android_view_GLES20DisplayList_getRotation(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getRotation();
 }
 
 static jfloat android_view_GLES20DisplayList_getRotationX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getRotationX();
 }
 
 static jfloat android_view_GLES20DisplayList_getRotationY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getRotationY();
 }
 
 static jfloat android_view_GLES20DisplayList_getPivotX(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getPivotX();
 }
 
 static jfloat android_view_GLES20DisplayList_getPivotY(JNIEnv* env,
-        jobject clazz, DisplayList* displayList) {
+        jobject clazz, jlong displayListHandle) {
+    DisplayList* displayList = reinterpret_cast<DisplayList*>(displayListHandle);
     return displayList->getPivotY();
 }
 
@@ -299,58 +348,58 @@
 
 static JNINativeMethod gMethods[] = {
 #ifdef USE_OPENGL_RENDERER
-    { "nDestroyDisplayList",   "(I)V",   (void*) android_view_GLES20DisplayList_destroyDisplayList },
-    { "nGetDisplayListSize",   "(I)I",   (void*) android_view_GLES20DisplayList_getDisplayListSize },
-    { "nSetDisplayListName",   "(ILjava/lang/String;)V",
+    { "nDestroyDisplayList",   "(J)V",   (void*) android_view_GLES20DisplayList_destroyDisplayList },
+    { "nGetDisplayListSize",   "(J)I",   (void*) android_view_GLES20DisplayList_getDisplayListSize },
+    { "nSetDisplayListName",   "(JLjava/lang/String;)V",
             (void*) android_view_GLES20DisplayList_setDisplayListName },
 
-    { "nReset",                "(I)V",   (void*) android_view_GLES20DisplayList_reset },
-    { "nSetCaching",           "(IZ)V",  (void*) android_view_GLES20DisplayList_setCaching },
-    { "nSetStaticMatrix",      "(II)V",  (void*) android_view_GLES20DisplayList_setStaticMatrix },
-    { "nSetAnimationMatrix",   "(II)V",  (void*) android_view_GLES20DisplayList_setAnimationMatrix },
-    { "nSetClipToBounds",      "(IZ)V",  (void*) android_view_GLES20DisplayList_setClipToBounds },
-    { "nSetAlpha",             "(IF)V",  (void*) android_view_GLES20DisplayList_setAlpha },
-    { "nSetHasOverlappingRendering", "(IZ)V",
+    { "nReset",                "(J)V",   (void*) android_view_GLES20DisplayList_reset },
+    { "nSetCaching",           "(JZ)V",  (void*) android_view_GLES20DisplayList_setCaching },
+    { "nSetStaticMatrix",      "(JJ)V",  (void*) android_view_GLES20DisplayList_setStaticMatrix },
+    { "nSetAnimationMatrix",   "(JJ)V",  (void*) android_view_GLES20DisplayList_setAnimationMatrix },
+    { "nSetClipToBounds",      "(JZ)V",  (void*) android_view_GLES20DisplayList_setClipToBounds },
+    { "nSetAlpha",             "(JF)V",  (void*) android_view_GLES20DisplayList_setAlpha },
+    { "nSetHasOverlappingRendering", "(JZ)V",
             (void*) android_view_GLES20DisplayList_setHasOverlappingRendering },
-    { "nSetTranslationX",      "(IF)V",  (void*) android_view_GLES20DisplayList_setTranslationX },
-    { "nSetTranslationY",      "(IF)V",  (void*) android_view_GLES20DisplayList_setTranslationY },
-    { "nSetRotation",          "(IF)V",  (void*) android_view_GLES20DisplayList_setRotation },
-    { "nSetRotationX",         "(IF)V",  (void*) android_view_GLES20DisplayList_setRotationX },
-    { "nSetRotationY",         "(IF)V",  (void*) android_view_GLES20DisplayList_setRotationY },
-    { "nSetScaleX",            "(IF)V",  (void*) android_view_GLES20DisplayList_setScaleX },
-    { "nSetScaleY",            "(IF)V",  (void*) android_view_GLES20DisplayList_setScaleY },
-    { "nSetTransformationInfo","(IFFFFFFFF)V",
+    { "nSetTranslationX",      "(JF)V",  (void*) android_view_GLES20DisplayList_setTranslationX },
+    { "nSetTranslationY",      "(JF)V",  (void*) android_view_GLES20DisplayList_setTranslationY },
+    { "nSetRotation",          "(JF)V",  (void*) android_view_GLES20DisplayList_setRotation },
+    { "nSetRotationX",         "(JF)V",  (void*) android_view_GLES20DisplayList_setRotationX },
+    { "nSetRotationY",         "(JF)V",  (void*) android_view_GLES20DisplayList_setRotationY },
+    { "nSetScaleX",            "(JF)V",  (void*) android_view_GLES20DisplayList_setScaleX },
+    { "nSetScaleY",            "(JF)V",  (void*) android_view_GLES20DisplayList_setScaleY },
+    { "nSetTransformationInfo","(JFFFFFFFF)V",
             (void*) android_view_GLES20DisplayList_setTransformationInfo },
-    { "nSetPivotX",            "(IF)V",  (void*) android_view_GLES20DisplayList_setPivotX },
-    { "nSetPivotY",            "(IF)V",  (void*) android_view_GLES20DisplayList_setPivotY },
-    { "nSetCameraDistance",    "(IF)V",  (void*) android_view_GLES20DisplayList_setCameraDistance },
-    { "nSetLeft",              "(II)V",  (void*) android_view_GLES20DisplayList_setLeft },
-    { "nSetTop",               "(II)V",  (void*) android_view_GLES20DisplayList_setTop },
-    { "nSetRight",             "(II)V",  (void*) android_view_GLES20DisplayList_setRight },
-    { "nSetBottom",            "(II)V",  (void*) android_view_GLES20DisplayList_setBottom },
-    { "nSetLeftTopRightBottom","(IIIII)V",
+    { "nSetPivotX",            "(JF)V",  (void*) android_view_GLES20DisplayList_setPivotX },
+    { "nSetPivotY",            "(JF)V",  (void*) android_view_GLES20DisplayList_setPivotY },
+    { "nSetCameraDistance",    "(JF)V",  (void*) android_view_GLES20DisplayList_setCameraDistance },
+    { "nSetLeft",              "(JI)V",  (void*) android_view_GLES20DisplayList_setLeft },
+    { "nSetTop",               "(JI)V",  (void*) android_view_GLES20DisplayList_setTop },
+    { "nSetRight",             "(JI)V",  (void*) android_view_GLES20DisplayList_setRight },
+    { "nSetBottom",            "(JI)V",  (void*) android_view_GLES20DisplayList_setBottom },
+    { "nSetLeftTopRightBottom","(JIIII)V",
             (void*) android_view_GLES20DisplayList_setLeftTopRightBottom },
-    { "nOffsetLeftAndRight",   "(IF)V",  (void*) android_view_GLES20DisplayList_offsetLeftAndRight },
-    { "nOffsetTopAndBottom",   "(IF)V",  (void*) android_view_GLES20DisplayList_offsetTopAndBottom },
+    { "nOffsetLeftAndRight",   "(JF)V",  (void*) android_view_GLES20DisplayList_offsetLeftAndRight },
+    { "nOffsetTopAndBottom",   "(JF)V",  (void*) android_view_GLES20DisplayList_offsetTopAndBottom },
 
 
-    { "nGetMatrix",               "(II)V", (void*) android_view_GLES20DisplayList_getMatrix },
-    { "nHasOverlappingRendering", "(I)Z",  (void*) android_view_GLES20DisplayList_hasOverlappingRendering },
-    { "nGetAlpha",                "(I)F",  (void*) android_view_GLES20DisplayList_getAlpha },
-    { "nGetLeft",                 "(I)F",  (void*) android_view_GLES20DisplayList_getLeft },
-    { "nGetTop",                  "(I)F",  (void*) android_view_GLES20DisplayList_getTop },
-    { "nGetRight",                "(I)F",  (void*) android_view_GLES20DisplayList_getRight },
-    { "nGetBottom",               "(I)F",  (void*) android_view_GLES20DisplayList_getBottom },
-    { "nGetCameraDistance",       "(I)F",  (void*) android_view_GLES20DisplayList_getCameraDistance },
-    { "nGetScaleX",               "(I)F",  (void*) android_view_GLES20DisplayList_getScaleX },
-    { "nGetScaleY",               "(I)F",  (void*) android_view_GLES20DisplayList_getScaleY },
-    { "nGetTranslationX",         "(I)F",  (void*) android_view_GLES20DisplayList_getTranslationX },
-    { "nGetTranslationY",         "(I)F",  (void*) android_view_GLES20DisplayList_getTranslationY },
-    { "nGetRotation",             "(I)F",  (void*) android_view_GLES20DisplayList_getRotation },
-    { "nGetRotationX",            "(I)F",  (void*) android_view_GLES20DisplayList_getRotationX },
-    { "nGetRotationY",            "(I)F",  (void*) android_view_GLES20DisplayList_getRotationY },
-    { "nGetPivotX",               "(I)F",  (void*) android_view_GLES20DisplayList_getPivotX },
-    { "nGetPivotY",               "(I)F",  (void*) android_view_GLES20DisplayList_getPivotY },
+    { "nGetMatrix",               "(JJ)V", (void*) android_view_GLES20DisplayList_getMatrix },
+    { "nHasOverlappingRendering", "(J)Z",  (void*) android_view_GLES20DisplayList_hasOverlappingRendering },
+    { "nGetAlpha",                "(J)F",  (void*) android_view_GLES20DisplayList_getAlpha },
+    { "nGetLeft",                 "(J)F",  (void*) android_view_GLES20DisplayList_getLeft },
+    { "nGetTop",                  "(J)F",  (void*) android_view_GLES20DisplayList_getTop },
+    { "nGetRight",                "(J)F",  (void*) android_view_GLES20DisplayList_getRight },
+    { "nGetBottom",               "(J)F",  (void*) android_view_GLES20DisplayList_getBottom },
+    { "nGetCameraDistance",       "(J)F",  (void*) android_view_GLES20DisplayList_getCameraDistance },
+    { "nGetScaleX",               "(J)F",  (void*) android_view_GLES20DisplayList_getScaleX },
+    { "nGetScaleY",               "(J)F",  (void*) android_view_GLES20DisplayList_getScaleY },
+    { "nGetTranslationX",         "(J)F",  (void*) android_view_GLES20DisplayList_getTranslationX },
+    { "nGetTranslationY",         "(J)F",  (void*) android_view_GLES20DisplayList_getTranslationY },
+    { "nGetRotation",             "(J)F",  (void*) android_view_GLES20DisplayList_getRotation },
+    { "nGetRotationX",            "(J)F",  (void*) android_view_GLES20DisplayList_getRotationX },
+    { "nGetRotationY",            "(J)F",  (void*) android_view_GLES20DisplayList_getRotationY },
+    { "nGetPivotX",               "(J)F",  (void*) android_view_GLES20DisplayList_getPivotX },
+    { "nGetPivotY",               "(J)F",  (void*) android_view_GLES20DisplayList_getPivotY },
 #endif
 };
 
diff --git a/core/jni/android_view_GraphicBuffer.cpp b/core/jni/android_view_GraphicBuffer.cpp
index d68c0b2..2e8dccf 100644
--- a/core/jni/android_view_GraphicBuffer.cpp
+++ b/core/jni/android_view_GraphicBuffer.cpp
@@ -89,6 +89,12 @@
 #define SET_INT(object, field, value) \
     env->SetIntField(object, field, value)
 
+#define GET_LONG(object, field) \
+    env->GetLongField(object, field)
+
+#define SET_LONG(object, field, value) \
+    env->SetLongField(object, field, value)
+
 #define INVOKEV(object, method, ...) \
     env->CallVoidMethod(object, method, __VA_ARGS__)
 
@@ -108,7 +114,7 @@
 // GraphicBuffer lifecycle
 // ----------------------------------------------------------------------------
 
-static GraphicBufferWrapper* android_view_GraphiceBuffer_create(JNIEnv* env, jobject clazz,
+static jlong android_view_GraphiceBuffer_create(JNIEnv* env, jobject clazz,
         jint width, jint height, jint format, jint usage) {
 
     sp<ISurfaceComposer> composer(ComposerService::getComposerService());
@@ -125,11 +131,14 @@
         return NULL;
     }
 
-    return new GraphicBufferWrapper(buffer);
+    GraphicBufferWrapper* wrapper = new GraphicBufferWrapper(buffer);
+    return reinterpret_cast<jlong>(wrapper);
 }
 
 static void android_view_GraphiceBuffer_destroy(JNIEnv* env, jobject clazz,
-        GraphicBufferWrapper* wrapper) {
+        jlong wrapperHandle) {
+    GraphicBufferWrapper* wrapper =
+                reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle);
     delete wrapper;
 }
 
@@ -140,9 +149,9 @@
 static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCanvas) {
     jobject canvasFinalizerObj = env->GetObjectField(canvasObj, gCanvasClassInfo.mFinalizer);
     SkCanvas* previousCanvas = reinterpret_cast<SkCanvas*>(
-            GET_INT(canvasObj, gCanvasClassInfo.mNativeCanvas));
-    SET_INT(canvasObj, gCanvasClassInfo.mNativeCanvas, (int) newCanvas);
-    SET_INT(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (int) newCanvas);
+            GET_LONG(canvasObj, gCanvasClassInfo.mNativeCanvas));
+    SET_LONG(canvasObj, gCanvasClassInfo.mNativeCanvas, (long) newCanvas);
+    SET_LONG(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (long) newCanvas);
     SkSafeUnref(previousCanvas);
 }
 
@@ -160,10 +169,12 @@
 }
 
 static jboolean android_view_GraphicBuffer_lockCanvas(JNIEnv* env, jobject,
-        GraphicBufferWrapper* wrapper, jobject canvas, jobject dirtyRect) {
+        jlong wrapperHandle, jobject canvas, jobject dirtyRect) {
 
+    GraphicBufferWrapper* wrapper =
+                reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle);
     if (!wrapper) {
-        return false;
+        return JNI_FALSE;
     }
 
     sp<GraphicBuffer> buffer(wrapper->buffer);
@@ -181,10 +192,10 @@
     void* bits = NULL;
     status_t status = buffer->lock(LOCK_CANVAS_USAGE, rect, &bits);
 
-    if (status) return false;
+    if (status) return JNI_FALSE;
     if (!bits) {
         buffer->unlock();
-        return false;
+        return JNI_FALSE;
     }
 
     ssize_t bytesCount = buffer->getStride() * bytesPerPixel(buffer->getPixelFormat());
@@ -213,21 +224,23 @@
                 int(rect.left), int(rect.top), int(rect.right), int(rect.bottom));
     }
 
-    return true;
+    return JNI_TRUE;
 }
 
 static jboolean android_view_GraphicBuffer_unlockCanvasAndPost(JNIEnv* env, jobject,
-        GraphicBufferWrapper* wrapper, jobject canvas) {
+        jlong wrapperHandle, jobject canvas) {
 
+    GraphicBufferWrapper* wrapper =
+                reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle);
     SkCanvas* nativeCanvas = SkNEW(SkCanvas);
     swapCanvasPtr(env, canvas, nativeCanvas);
 
     if (wrapper) {
         status_t status = wrapper->buffer->unlock();
-        return status == 0;
+        return status == 0 ? JNI_TRUE : JNI_FALSE;
     }
 
-    return false;
+    return JNI_FALSE;
 }
 
 // ----------------------------------------------------------------------------
@@ -235,21 +248,23 @@
 // ----------------------------------------------------------------------------
 
 static void android_view_GraphiceBuffer_write(JNIEnv* env, jobject clazz,
-        GraphicBufferWrapper* wrapper, jobject dest) {
+        jlong wrapperHandle, jobject dest) {
+    GraphicBufferWrapper* wrapper =
+                reinterpret_cast<GraphicBufferWrapper*>(wrapperHandle);
     Parcel* parcel = parcelForJavaObject(env, dest);
     if (parcel) {
         parcel->write(*wrapper->buffer);
     }
 }
 
-static GraphicBufferWrapper* android_view_GraphiceBuffer_read(JNIEnv* env, jobject clazz,
+static jlong android_view_GraphiceBuffer_read(JNIEnv* env, jobject clazz,
         jobject in) {
 
     Parcel* parcel = parcelForJavaObject(env, in);
     if (parcel) {
         sp<GraphicBuffer> buffer = new GraphicBuffer();
         parcel->read(*buffer);
-        return new GraphicBufferWrapper(buffer);
+        return reinterpret_cast<jlong>(new GraphicBufferWrapper(buffer));
     }
 
     return NULL;
@@ -261,7 +276,7 @@
 
 sp<GraphicBuffer> graphicBufferForJavaObject(JNIEnv* env, jobject obj) {
     if (obj) {
-        jint nativeObject = env->GetIntField(obj, gGraphicBufferClassInfo.mNativeObject);
+        jlong nativeObject = env->GetLongField(obj, gGraphicBufferClassInfo.mNativeObject);
         GraphicBufferWrapper* wrapper = (GraphicBufferWrapper*) nativeObject;
         if (wrapper != NULL) {
             sp<GraphicBuffer> buffer(wrapper->buffer);
@@ -290,24 +305,24 @@
 const char* const kClassPathName = "android/view/GraphicBuffer";
 
 static JNINativeMethod gMethods[] = {
-    { "nCreateGraphicBuffer",  "(IIII)I", (void*) android_view_GraphiceBuffer_create },
-    { "nDestroyGraphicBuffer", "(I)V",    (void*) android_view_GraphiceBuffer_destroy },
+    { "nCreateGraphicBuffer",  "(IIII)J", (void*) android_view_GraphiceBuffer_create },
+    { "nDestroyGraphicBuffer", "(J)V",    (void*) android_view_GraphiceBuffer_destroy },
 
-    { "nWriteGraphicBufferToParcel",  "(ILandroid/os/Parcel;)V",
+    { "nWriteGraphicBufferToParcel",  "(JLandroid/os/Parcel;)V",
             (void*) android_view_GraphiceBuffer_write },
-    { "nReadGraphicBufferFromParcel", "(Landroid/os/Parcel;)I",
+    { "nReadGraphicBufferFromParcel", "(Landroid/os/Parcel;)J",
             (void*) android_view_GraphiceBuffer_read },
 
-    { "nLockCanvas", "(ILandroid/graphics/Canvas;Landroid/graphics/Rect;)Z",
+    { "nLockCanvas", "(JLandroid/graphics/Canvas;Landroid/graphics/Rect;)Z",
             (void*) android_view_GraphicBuffer_lockCanvas },
-    { "nUnlockCanvasAndPost", "(ILandroid/graphics/Canvas;)Z",
+    { "nUnlockCanvasAndPost", "(JLandroid/graphics/Canvas;)Z",
             (void*) android_view_GraphicBuffer_unlockCanvasAndPost },
 };
 
 int register_android_view_GraphicBuffer(JNIEnv* env) {
     jclass clazz;
     FIND_CLASS(clazz, "android/view/GraphicBuffer");
-    GET_FIELD_ID(gGraphicBufferClassInfo.mNativeObject, clazz, "mNativeObject", "I");
+    GET_FIELD_ID(gGraphicBufferClassInfo.mNativeObject, clazz, "mNativeObject", "J");
 
     FIND_CLASS(clazz, "android/graphics/Rect");
     GET_METHOD_ID(gRectClassInfo.set, clazz, "set", "(IIII)V");
@@ -319,11 +334,11 @@
     FIND_CLASS(clazz, "android/graphics/Canvas");
     GET_FIELD_ID(gCanvasClassInfo.mFinalizer, clazz, "mFinalizer",
             "Landroid/graphics/Canvas$CanvasFinalizer;");
-    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
+    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "J");
     GET_FIELD_ID(gCanvasClassInfo.mSurfaceFormat, clazz, "mSurfaceFormat", "I");
 
     FIND_CLASS(clazz, "android/graphics/Canvas$CanvasFinalizer");
-    GET_FIELD_ID(gCanvasFinalizerClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
+    GET_FIELD_ID(gCanvasFinalizerClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "J");
 
     return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
 }
diff --git a/core/jni/android_view_InputChannel.cpp b/core/jni/android_view_InputChannel.cpp
index ce475e0..d667920 100644
--- a/core/jni/android_view_InputChannel.cpp
+++ b/core/jni/android_view_InputChannel.cpp
@@ -81,14 +81,14 @@
 
 static NativeInputChannel* android_view_InputChannel_getNativeInputChannel(JNIEnv* env,
         jobject inputChannelObj) {
-    jint intPtr = env->GetIntField(inputChannelObj, gInputChannelClassInfo.mPtr);
-    return reinterpret_cast<NativeInputChannel*>(intPtr);
+    jlong longPtr = env->GetLongField(inputChannelObj, gInputChannelClassInfo.mPtr);
+    return reinterpret_cast<NativeInputChannel*>(longPtr);
 }
 
 static void android_view_InputChannel_setNativeInputChannel(JNIEnv* env, jobject inputChannelObj,
         NativeInputChannel* nativeInputChannel) {
-    env->SetIntField(inputChannelObj, gInputChannelClassInfo.mPtr,
-             reinterpret_cast<jint>(nativeInputChannel));
+    env->SetLongField(inputChannelObj, gInputChannelClassInfo.mPtr,
+             reinterpret_cast<jlong>(nativeInputChannel));
 }
 
 sp<InputChannel> android_view_InputChannel_getInputChannel(JNIEnv* env, jobject inputChannelObj) {
@@ -296,7 +296,7 @@
     FIND_CLASS(gInputChannelClassInfo.clazz, "android/view/InputChannel");
 
     GET_FIELD_ID(gInputChannelClassInfo.mPtr, gInputChannelClassInfo.clazz,
-            "mPtr", "I");
+            "mPtr", "J");
     
     GET_METHOD_ID(gInputChannelClassInfo.ctor, gInputChannelClassInfo.clazz,
             "<init>", "()V");
diff --git a/core/jni/android_view_InputEventReceiver.cpp b/core/jni/android_view_InputEventReceiver.cpp
index 92a3e62..f36bf31 100644
--- a/core/jni/android_view_InputEventReceiver.cpp
+++ b/core/jni/android_view_InputEventReceiver.cpp
@@ -330,7 +330,7 @@
 }
 
 
-static jint nativeInit(JNIEnv* env, jclass clazz, jobject receiverWeak,
+static jlong nativeInit(JNIEnv* env, jclass clazz, jobject receiverWeak,
         jobject inputChannelObj, jobject messageQueueObj) {
     sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
             inputChannelObj);
@@ -356,17 +356,17 @@
     }
 
     receiver->incStrong(gInputEventReceiverClassInfo.clazz); // retain a reference for the object
-    return reinterpret_cast<jint>(receiver.get());
+    return reinterpret_cast<jlong>(receiver.get());
 }
 
-static void nativeDispose(JNIEnv* env, jclass clazz, jint receiverPtr) {
+static void nativeDispose(JNIEnv* env, jclass clazz, jlong receiverPtr) {
     sp<NativeInputEventReceiver> receiver =
             reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
     receiver->dispose();
     receiver->decStrong(gInputEventReceiverClassInfo.clazz); // drop reference held by the object
 }
 
-static void nativeFinishInputEvent(JNIEnv* env, jclass clazz, jint receiverPtr,
+static void nativeFinishInputEvent(JNIEnv* env, jclass clazz, jlong receiverPtr,
         jint seq, jboolean handled) {
     sp<NativeInputEventReceiver> receiver =
             reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
@@ -378,7 +378,7 @@
     }
 }
 
-static bool nativeConsumeBatchedInputEvents(JNIEnv* env, jclass clazz, jint receiverPtr,
+static jboolean nativeConsumeBatchedInputEvents(JNIEnv* env, jclass clazz, jlong receiverPtr,
         jlong frameTimeNanos) {
     sp<NativeInputEventReceiver> receiver =
             reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
@@ -389,22 +389,22 @@
         String8 message;
         message.appendFormat("Failed to consume batched input event.  status=%d", status);
         jniThrowRuntimeException(env, message.string());
-        return false;
+        return JNI_FALSE;
     }
-    return consumedBatch;
+    return consumedBatch ? JNI_TRUE : JNI_FALSE;
 }
 
 
 static JNINativeMethod gMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInit",
-            "(Ljava/lang/ref/WeakReference;Landroid/view/InputChannel;Landroid/os/MessageQueue;)I",
+            "(Ljava/lang/ref/WeakReference;Landroid/view/InputChannel;Landroid/os/MessageQueue;)J",
             (void*)nativeInit },
-    { "nativeDispose", "(I)V",
+    { "nativeDispose", "(J)V",
             (void*)nativeDispose },
-    { "nativeFinishInputEvent", "(IIZ)V",
+    { "nativeFinishInputEvent", "(JIZ)V",
             (void*)nativeFinishInputEvent },
-    { "nativeConsumeBatchedInputEvents", "(IJ)Z",
+    { "nativeConsumeBatchedInputEvents", "(JJ)Z",
             (void*)nativeConsumeBatchedInputEvents },
 };
 
diff --git a/core/jni/android_view_InputEventSender.cpp b/core/jni/android_view_InputEventSender.cpp
index e4b65a1..f156b9a 100644
--- a/core/jni/android_view_InputEventSender.cpp
+++ b/core/jni/android_view_InputEventSender.cpp
@@ -230,7 +230,7 @@
 }
 
 
-static jint nativeInit(JNIEnv* env, jclass clazz, jobject senderWeak,
+static jlong nativeInit(JNIEnv* env, jclass clazz, jobject senderWeak,
         jobject inputChannelObj, jobject messageQueueObj) {
     sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
             inputChannelObj);
@@ -256,17 +256,17 @@
     }
 
     sender->incStrong(gInputEventSenderClassInfo.clazz); // retain a reference for the object
-    return reinterpret_cast<jint>(sender.get());
+    return reinterpret_cast<jlong>(sender.get());
 }
 
-static void nativeDispose(JNIEnv* env, jclass clazz, jint senderPtr) {
+static void nativeDispose(JNIEnv* env, jclass clazz, jlong senderPtr) {
     sp<NativeInputEventSender> sender =
             reinterpret_cast<NativeInputEventSender*>(senderPtr);
     sender->dispose();
     sender->decStrong(gInputEventSenderClassInfo.clazz); // drop reference held by the object
 }
 
-static jboolean nativeSendKeyEvent(JNIEnv* env, jclass clazz, jint senderPtr,
+static jboolean nativeSendKeyEvent(JNIEnv* env, jclass clazz, jlong senderPtr,
         jint seq, jobject eventObj) {
     sp<NativeInputEventSender> sender =
             reinterpret_cast<NativeInputEventSender*>(senderPtr);
@@ -276,7 +276,7 @@
     return !status;
 }
 
-static jboolean nativeSendMotionEvent(JNIEnv* env, jclass clazz, jint senderPtr,
+static jboolean nativeSendMotionEvent(JNIEnv* env, jclass clazz, jlong senderPtr,
         jint seq, jobject eventObj) {
     sp<NativeInputEventSender> sender =
             reinterpret_cast<NativeInputEventSender*>(senderPtr);
@@ -289,13 +289,13 @@
 static JNINativeMethod gMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInit",
-            "(Ljava/lang/ref/WeakReference;Landroid/view/InputChannel;Landroid/os/MessageQueue;)I",
+            "(Ljava/lang/ref/WeakReference;Landroid/view/InputChannel;Landroid/os/MessageQueue;)J",
             (void*)nativeInit },
-    { "nativeDispose", "(I)V",
+    { "nativeDispose", "(J)V",
             (void*)nativeDispose },
-    { "nativeSendKeyEvent", "(IILandroid/view/KeyEvent;)Z",
+    { "nativeSendKeyEvent", "(JILandroid/view/KeyEvent;)Z",
             (void*)nativeSendKeyEvent },
-    { "nativeSendMotionEvent", "(IILandroid/view/MotionEvent;)Z",
+    { "nativeSendMotionEvent", "(JILandroid/view/MotionEvent;)Z",
             (void*)nativeSendMotionEvent },
 };
 
diff --git a/core/jni/android_view_InputQueue.cpp b/core/jni/android_view_InputQueue.cpp
index 7532c9d..21b73b1 100644
--- a/core/jni/android_view_InputQueue.cpp
+++ b/core/jni/android_view_InputQueue.cpp
@@ -151,7 +151,7 @@
                 mFinishedEvents.removeAt(0);
             }
             env->CallVoidMethod(inputQueueObj.get(), gInputQueueClassInfo.finishInputEvent,
-                    reinterpret_cast<jint>(event), handled);
+                    reinterpret_cast<jlong>(event), handled);
             recycleInputEvent(event);
         }
         break;
@@ -193,7 +193,7 @@
     return new InputQueue(inputQueueObj, looper, pipeFds[0], pipeFds[1]);
 }
 
-static jint nativeInit(JNIEnv* env, jobject clazz, jobject queueWeak, jobject jMsgQueue) {
+static jlong nativeInit(JNIEnv* env, jobject clazz, jobject queueWeak, jobject jMsgQueue) {
     sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, jMsgQueue);
     if (messageQueue == NULL) {
         jniThrowRuntimeException(env, "MessageQueue is not initialized.");
@@ -205,16 +205,16 @@
         return 0;
     }
     queue->incStrong(&gInputQueueClassInfo);
-    return reinterpret_cast<jint>(queue.get());
+    return reinterpret_cast<jlong>(queue.get());
 }
 
-static void nativeDispose(JNIEnv* env, jobject clazz, jint ptr) {
+static void nativeDispose(JNIEnv* env, jobject clazz, jlong ptr) {
     sp<InputQueue> queue = reinterpret_cast<InputQueue*>(ptr);
     queue->detachLooper();
     queue->decStrong(&gInputQueueClassInfo);
 }
 
-static jint nativeSendKeyEvent(JNIEnv* env, jobject clazz, jint ptr, jobject eventObj,
+static jlong nativeSendKeyEvent(JNIEnv* env, jobject clazz, jlong ptr, jobject eventObj,
         jboolean predispatch) {
     InputQueue* queue = reinterpret_cast<InputQueue*>(ptr);
     KeyEvent* event = queue->createKeyEvent();
@@ -230,10 +230,10 @@
     }
 
     queue->enqueueEvent(event);
-    return reinterpret_cast<jint>(event);
+    return reinterpret_cast<jlong>(event);
 }
 
-static jint nativeSendMotionEvent(JNIEnv* env, jobject clazz, jint ptr, jobject eventObj) {
+static jlong nativeSendMotionEvent(JNIEnv* env, jobject clazz, jlong ptr, jobject eventObj) {
     sp<InputQueue> queue = reinterpret_cast<InputQueue*>(ptr);
     MotionEvent* originalEvent = android_view_MotionEvent_getNativePtr(env, eventObj);
     if (!originalEvent) {
@@ -243,15 +243,15 @@
     MotionEvent* event = queue->createMotionEvent();
     event->copyFrom(originalEvent, true /* keepHistory */);
     queue->enqueueEvent(event);
-    return reinterpret_cast<jint>(event);
+    return reinterpret_cast<jlong>(event);
 }
 
 static const JNINativeMethod g_methods[] = {
-    { "nativeInit", "(Ljava/lang/ref/WeakReference;Landroid/os/MessageQueue;)I",
+    { "nativeInit", "(Ljava/lang/ref/WeakReference;Landroid/os/MessageQueue;)J",
         (void*) nativeInit },
-    { "nativeDispose", "(I)V", (void*) nativeDispose },
-    { "nativeSendKeyEvent", "(ILandroid/view/KeyEvent;Z)I", (void*) nativeSendKeyEvent },
-    { "nativeSendMotionEvent", "(ILandroid/view/MotionEvent;)I", (void*) nativeSendMotionEvent },
+    { "nativeDispose", "(J)V", (void*) nativeDispose },
+    { "nativeSendKeyEvent", "(JLandroid/view/KeyEvent;Z)J", (void*) nativeSendKeyEvent },
+    { "nativeSendMotionEvent", "(JLandroid/view/MotionEvent;)J", (void*) nativeSendMotionEvent },
 };
 
 static const char* const kInputQueuePathName = "android/view/InputQueue";
@@ -272,7 +272,7 @@
 {
     jclass clazz;
     FIND_CLASS(clazz, kInputQueuePathName);
-    GET_METHOD_ID(gInputQueueClassInfo.finishInputEvent, clazz, "finishInputEvent", "(IZ)V");
+    GET_METHOD_ID(gInputQueueClassInfo.finishInputEvent, clazz, "finishInputEvent", "(JZ)V");
 
     return AndroidRuntime::registerNativeMethods(
         env, kInputQueuePathName,
diff --git a/core/jni/android_view_KeyCharacterMap.cpp b/core/jni/android_view_KeyCharacterMap.cpp
index ffe2dea..62d5129 100644
--- a/core/jni/android_view_KeyCharacterMap.cpp
+++ b/core/jni/android_view_KeyCharacterMap.cpp
@@ -75,10 +75,10 @@
     }
 
     return env->NewObject(gKeyCharacterMapClassInfo.clazz, gKeyCharacterMapClassInfo.ctor,
-            reinterpret_cast<jint>(map));
+            reinterpret_cast<jlong>(map));
 }
 
-static jint nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) {
+static jlong nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) {
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
     if (!parcel) {
         return 0;
@@ -95,10 +95,10 @@
     }
 
     NativeKeyCharacterMap* map = new NativeKeyCharacterMap(deviceId, kcm);
-    return reinterpret_cast<jint>(map);
+    return reinterpret_cast<jlong>(map);
 }
 
-static void nativeWriteToParcel(JNIEnv* env, jobject clazz, jint ptr, jobject parcelObj) {
+static void nativeWriteToParcel(JNIEnv* env, jobject clazz, jlong ptr, jobject parcelObj) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
     if (parcel) {
@@ -107,18 +107,18 @@
     }
 }
 
-static void nativeDispose(JNIEnv *env, jobject clazz, jint ptr) {
+static void nativeDispose(JNIEnv *env, jobject clazz, jlong ptr) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     delete map;
 }
 
-static jchar nativeGetCharacter(JNIEnv *env, jobject clazz, jint ptr,
+static jchar nativeGetCharacter(JNIEnv *env, jobject clazz, jlong ptr,
         jint keyCode, jint metaState) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getCharacter(keyCode, metaState);
 }
 
-static jboolean nativeGetFallbackAction(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
+static jboolean nativeGetFallbackAction(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode,
         jint metaState, jobject fallbackActionObj) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     KeyCharacterMap::FallbackAction fallbackAction;
@@ -133,12 +133,12 @@
     return result;
 }
 
-static jchar nativeGetNumber(JNIEnv *env, jobject clazz, jint ptr, jint keyCode) {
+static jchar nativeGetNumber(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getNumber(keyCode);
 }
 
-static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
+static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode,
         jcharArray charsArray, jint metaState) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
 
@@ -154,17 +154,17 @@
     return result;
 }
 
-static jchar nativeGetDisplayLabel(JNIEnv *env, jobject clazz, jint ptr, jint keyCode) {
+static jchar nativeGetDisplayLabel(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getDisplayLabel(keyCode);
 }
 
-static jint nativeGetKeyboardType(JNIEnv *env, jobject clazz, jint ptr) {
+static jint nativeGetKeyboardType(JNIEnv *env, jobject clazz, jlong ptr) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getKeyboardType();
 }
 
-static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr,
+static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jlong ptr,
         jcharArray charsArray) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
 
@@ -199,25 +199,25 @@
 
 static JNINativeMethod g_methods[] = {
     /* name, signature, funcPtr */
-    { "nativeReadFromParcel", "(Landroid/os/Parcel;)I",
+    { "nativeReadFromParcel", "(Landroid/os/Parcel;)J",
             (void*)nativeReadFromParcel },
-    { "nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
+    { "nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
             (void*)nativeWriteToParcel },
-    { "nativeDispose", "(I)V",
+    { "nativeDispose", "(J)V",
             (void*)nativeDispose },
-    { "nativeGetCharacter", "(III)C",
+    { "nativeGetCharacter", "(JII)C",
             (void*)nativeGetCharacter },
-    { "nativeGetFallbackAction", "(IIILandroid/view/KeyCharacterMap$FallbackAction;)Z",
+    { "nativeGetFallbackAction", "(JIILandroid/view/KeyCharacterMap$FallbackAction;)Z",
             (void*)nativeGetFallbackAction },
-    { "nativeGetNumber", "(II)C",
+    { "nativeGetNumber", "(JI)C",
             (void*)nativeGetNumber },
-    { "nativeGetMatch", "(II[CI)C",
+    { "nativeGetMatch", "(JI[CI)C",
             (void*)nativeGetMatch },
-    { "nativeGetDisplayLabel", "(II)C",
+    { "nativeGetDisplayLabel", "(JI)C",
             (void*)nativeGetDisplayLabel },
-    { "nativeGetKeyboardType", "(I)I",
+    { "nativeGetKeyboardType", "(J)I",
             (void*)nativeGetKeyboardType },
-    { "nativeGetEvents", "(I[C)[Landroid/view/KeyEvent;",
+    { "nativeGetEvents", "(J[C)[Landroid/view/KeyEvent;",
             (void*)nativeGetEvents },
 };
 
@@ -239,7 +239,7 @@
     gKeyCharacterMapClassInfo.clazz = jclass(env->NewGlobalRef(gKeyCharacterMapClassInfo.clazz));
 
     GET_METHOD_ID(gKeyCharacterMapClassInfo.ctor, gKeyCharacterMapClassInfo.clazz,
-            "<init>", "(I)V");
+            "<init>", "(J)V");
 
     FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
     gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp
index f1b90e1..76e145b 100644
--- a/core/jni/android_view_MotionEvent.cpp
+++ b/core/jni/android_view_MotionEvent.cpp
@@ -67,13 +67,13 @@
         return NULL;
     }
     return reinterpret_cast<MotionEvent*>(
-            env->GetIntField(eventObj, gMotionEventClassInfo.mNativePtr));
+            env->GetLongField(eventObj, gMotionEventClassInfo.mNativePtr));
 }
 
 static void android_view_MotionEvent_setNativePtr(JNIEnv* env, jobject eventObj,
         MotionEvent* event) {
-    env->SetIntField(eventObj, gMotionEventClassInfo.mNativePtr,
-            reinterpret_cast<int>(event));
+    env->SetLongField(eventObj, gMotionEventClassInfo.mNativePtr,
+            reinterpret_cast<jlong>(event));
 }
 
 jobject android_view_MotionEvent_obtainAsCopy(JNIEnv* env, const MotionEvent* event) {
@@ -334,8 +334,8 @@
 
 // ----------------------------------------------------------------------------
 
-static jint android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
-        jint nativePtr,
+static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
+        jlong nativePtr,
         jint deviceId, jint source, jint action, jint flags, jint edgeFlags,
         jint metaState, jint buttonState,
         jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
@@ -377,7 +377,7 @@
             xOffset, yOffset, xPrecision, yPrecision,
             downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, rawPointerCoords);
 
-    return reinterpret_cast<jint>(event);
+    return reinterpret_cast<jlong>(event);
 
 Error:
     if (!nativePtr) {
@@ -386,25 +386,25 @@
     return 0;
 }
 
-static jint android_view_MotionEvent_nativeCopy(JNIEnv* env, jclass clazz,
-        jint destNativePtr, jint sourceNativePtr, jboolean keepHistory) {
+static jlong android_view_MotionEvent_nativeCopy(JNIEnv* env, jclass clazz,
+        jlong destNativePtr, jlong sourceNativePtr, jboolean keepHistory) {
     MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr);
     if (!destEvent) {
         destEvent = new MotionEvent();
     }
     MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr);
     destEvent->copyFrom(sourceEvent, keepHistory);
-    return reinterpret_cast<jint>(destEvent);
+    return reinterpret_cast<jlong>(destEvent);
 }
 
 static void android_view_MotionEvent_nativeDispose(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     delete event;
 }
 
 static void android_view_MotionEvent_nativeAddBatch(JNIEnv* env, jclass clazz,
-        jint nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray,
+        jlong nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray,
         jint metaState) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
@@ -430,127 +430,127 @@
 }
 
 static jint android_view_MotionEvent_nativeGetDeviceId(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getDeviceId();
 }
 
 static jint android_view_MotionEvent_nativeGetSource(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getSource();
 }
 
 static void android_view_MotionEvent_nativeSetSource(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint source) {
+        jlong nativePtr, jint source) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setSource(source);
 }
 
 static jint android_view_MotionEvent_nativeGetAction(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getAction();
 }
 
 static void android_view_MotionEvent_nativeSetAction(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint action) {
+        jlong nativePtr, jint action) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setAction(action);
 }
 
 static jboolean android_view_MotionEvent_nativeIsTouchEvent(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->isTouchEvent();
 }
 
 static jint android_view_MotionEvent_nativeGetFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getFlags();
 }
 
 static void android_view_MotionEvent_nativeSetFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint flags) {
+        jlong nativePtr, jint flags) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setFlags(flags);
 }
 
 static jint android_view_MotionEvent_nativeGetEdgeFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getEdgeFlags();
 }
 
 static void android_view_MotionEvent_nativeSetEdgeFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint edgeFlags) {
+        jlong nativePtr, jint edgeFlags) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setEdgeFlags(edgeFlags);
 }
 
 static jint android_view_MotionEvent_nativeGetMetaState(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getMetaState();
 }
 
 static jint android_view_MotionEvent_nativeGetButtonState(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getButtonState();
 }
 
 static void android_view_MotionEvent_nativeOffsetLocation(JNIEnv* env, jclass clazz,
-        jint nativePtr, jfloat deltaX, jfloat deltaY) {
+        jlong nativePtr, jfloat deltaX, jfloat deltaY) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->offsetLocation(deltaX, deltaY);
 }
 
 static jfloat android_view_MotionEvent_nativeGetXOffset(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getXOffset();
 }
 
 static jfloat android_view_MotionEvent_nativeGetYOffset(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getYOffset();
 }
 
 static jfloat android_view_MotionEvent_nativeGetXPrecision(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getXPrecision();
 }
 
 static jfloat android_view_MotionEvent_nativeGetYPrecision(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getYPrecision();
 }
 
 static jlong android_view_MotionEvent_nativeGetDownTimeNanos(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getDownTime();
 }
 
 static void android_view_MotionEvent_nativeSetDownTimeNanos(JNIEnv* env, jclass clazz,
-        jint nativePtr, jlong downTimeNanos) {
+        jlong nativePtr, jlong downTimeNanos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setDownTime(downTimeNanos);
 }
 
 static jint android_view_MotionEvent_nativeGetPointerCount(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return jint(event->getPointerCount());
 }
 
 static jint android_view_MotionEvent_nativeGetPointerId(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex) {
+        jlong nativePtr, jint pointerIndex) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -560,7 +560,7 @@
 }
 
 static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex) {
+        jlong nativePtr, jint pointerIndex) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -570,19 +570,19 @@
 }
 
 static jint android_view_MotionEvent_nativeFindPointerIndex(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerId) {
+        jlong nativePtr, jint pointerId) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return jint(event->findPointerIndex(pointerId));
 }
 
 static jint android_view_MotionEvent_nativeGetHistorySize(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return jint(event->getHistorySize());
 }
 
 static jlong android_view_MotionEvent_nativeGetEventTimeNanos(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint historyPos) {
+        jlong nativePtr, jint historyPos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     if (historyPos == HISTORY_CURRENT) {
         return event->getEventTime();
@@ -596,7 +596,7 @@
 }
 
 static jfloat android_view_MotionEvent_nativeGetRawAxisValue(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint axis, jint pointerIndex, jint historyPos) {
+        jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -615,7 +615,7 @@
 }
 
 static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint axis, jint pointerIndex, jint historyPos) {
+        jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -634,7 +634,7 @@
 }
 
 static void android_view_MotionEvent_nativeGetPointerCoords(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) {
+        jlong nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)
@@ -657,7 +657,7 @@
 }
 
 static void android_view_MotionEvent_nativeGetPointerProperties(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) {
+        jlong nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)
@@ -670,13 +670,13 @@
 }
 
 static void android_view_MotionEvent_nativeScale(JNIEnv* env, jclass clazz,
-        jint nativePtr, jfloat scale) {
+        jlong nativePtr, jfloat scale) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->scale(scale);
 }
 
 static void android_view_MotionEvent_nativeTransform(JNIEnv* env, jclass clazz,
-        jint nativePtr, jobject matrixObj) {
+        jlong nativePtr, jobject matrixObj) {
     SkMatrix* matrix = android_graphics_Matrix_getSkMatrix(env, matrixObj);
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
 
@@ -693,8 +693,8 @@
     event->transform(m);
 }
 
-static jint android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz,
-        jint nativePtr, jobject parcelObj) {
+static jlong android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz,
+        jlong nativePtr, jobject parcelObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     if (!event) {
         event = new MotionEvent();
@@ -710,11 +710,11 @@
         jniThrowRuntimeException(env, "Failed to read MotionEvent parcel.");
         return 0;
     }
-    return reinterpret_cast<jint>(event);
+    return reinterpret_cast<jlong>(event);
 }
 
 static void android_view_MotionEvent_nativeWriteToParcel(JNIEnv* env, jclass clazz,
-        jint nativePtr, jobject parcelObj) {
+        jlong nativePtr, jobject parcelObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
 
@@ -729,116 +729,116 @@
 static JNINativeMethod gMotionEventMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInitialize",
-            "(IIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
-                    "[Landroid/view/MotionEvent$PointerCoords;)I",
+            "(JIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
+                    "[Landroid/view/MotionEvent$PointerCoords;)J",
             (void*)android_view_MotionEvent_nativeInitialize },
     { "nativeCopy",
-            "(IIZ)I",
+            "(JJZ)J",
             (void*)android_view_MotionEvent_nativeCopy },
     { "nativeDispose",
-            "(I)V",
+            "(J)V",
             (void*)android_view_MotionEvent_nativeDispose },
     { "nativeAddBatch",
-            "(IJ[Landroid/view/MotionEvent$PointerCoords;I)V",
+            "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V",
             (void*)android_view_MotionEvent_nativeAddBatch },
     { "nativeGetDeviceId",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetDeviceId },
     { "nativeGetSource",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetSource },
     { "nativeSetSource",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeSetSource },
     { "nativeGetAction",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetAction },
     { "nativeSetAction",
-            "(II)V",
+            "(JI)V",
             (void*)android_view_MotionEvent_nativeSetAction },
     { "nativeIsTouchEvent",
-            "(I)Z",
+            "(J)Z",
             (void*)android_view_MotionEvent_nativeIsTouchEvent },
     { "nativeGetFlags",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetFlags },
     { "nativeSetFlags",
-            "(II)V",
+            "(JI)V",
             (void*)android_view_MotionEvent_nativeSetFlags },
     { "nativeGetEdgeFlags",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetEdgeFlags },
     { "nativeSetEdgeFlags",
-            "(II)V",
+            "(JI)V",
             (void*)android_view_MotionEvent_nativeSetEdgeFlags },
     { "nativeGetMetaState",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetMetaState },
     { "nativeGetButtonState",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetButtonState },
     { "nativeOffsetLocation",
-            "(IFF)V",
+            "(JFF)V",
             (void*)android_view_MotionEvent_nativeOffsetLocation },
     { "nativeGetXOffset",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetXOffset },
     { "nativeGetYOffset",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetYOffset },
     { "nativeGetXPrecision",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetXPrecision },
     { "nativeGetYPrecision",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetYPrecision },
     { "nativeGetDownTimeNanos",
-            "(I)J",
+            "(J)J",
             (void*)android_view_MotionEvent_nativeGetDownTimeNanos },
     { "nativeSetDownTimeNanos",
-            "(IJ)V",
+            "(JJ)V",
             (void*)android_view_MotionEvent_nativeSetDownTimeNanos },
     { "nativeGetPointerCount",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetPointerCount },
     { "nativeGetPointerId",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeGetPointerId },
     { "nativeGetToolType",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeGetToolType },
     { "nativeFindPointerIndex",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeFindPointerIndex },
     { "nativeGetHistorySize",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetHistorySize },
     { "nativeGetEventTimeNanos",
-            "(II)J",
+            "(JI)J",
             (void*)android_view_MotionEvent_nativeGetEventTimeNanos },
     { "nativeGetRawAxisValue",
-            "(IIII)F",
+            "(JIII)F",
             (void*)android_view_MotionEvent_nativeGetRawAxisValue },
     { "nativeGetAxisValue",
-            "(IIII)F",
+            "(JIII)F",
             (void*)android_view_MotionEvent_nativeGetAxisValue },
     { "nativeGetPointerCoords",
-            "(IIILandroid/view/MotionEvent$PointerCoords;)V",
+            "(JIILandroid/view/MotionEvent$PointerCoords;)V",
             (void*)android_view_MotionEvent_nativeGetPointerCoords },
     { "nativeGetPointerProperties",
-            "(IILandroid/view/MotionEvent$PointerProperties;)V",
+            "(JILandroid/view/MotionEvent$PointerProperties;)V",
             (void*)android_view_MotionEvent_nativeGetPointerProperties },
     { "nativeScale",
-            "(IF)V",
+            "(JF)V",
             (void*)android_view_MotionEvent_nativeScale },
     { "nativeTransform",
-            "(ILandroid/graphics/Matrix;)V",
+            "(JLandroid/graphics/Matrix;)V",
             (void*)android_view_MotionEvent_nativeTransform },
     { "nativeReadFromParcel",
-            "(ILandroid/os/Parcel;)I",
+            "(JLandroid/os/Parcel;)J",
             (void*)android_view_MotionEvent_nativeReadFromParcel },
     { "nativeWriteToParcel",
-            "(ILandroid/os/Parcel;)V",
+            "(JLandroid/os/Parcel;)V",
             (void*)android_view_MotionEvent_nativeWriteToParcel },
 };
 
@@ -871,7 +871,7 @@
     GET_METHOD_ID(gMotionEventClassInfo.recycle, gMotionEventClassInfo.clazz,
             "recycle", "()V");
     GET_FIELD_ID(gMotionEventClassInfo.mNativePtr, gMotionEventClassInfo.clazz,
-            "mNativePtr", "I");
+            "mNativePtr", "J");
 
     jclass clazz;
     FIND_CLASS(clazz, "android/view/MotionEvent$PointerCoords");
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index dd178d8..3342bab 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -39,7 +39,6 @@
 
 #include <SkCanvas.h>
 #include <SkBitmap.h>
-#include <SkImage.h>
 #include <SkRegion.h>
 
 #include <utils/misc.h>
@@ -97,7 +96,7 @@
             gSurfaceClassInfo.mLock);
     if (env->MonitorEnter(lock) == JNI_OK) {
         sur = reinterpret_cast<Surface *>(
-                env->GetIntField(surfaceObj, gSurfaceClassInfo.mNativeObject));
+                env->GetLongField(surfaceObj, gSurfaceClassInfo.mNativeObject));
         env->MonitorExit(lock);
     }
     return sur;
@@ -135,7 +134,7 @@
 
 // ----------------------------------------------------------------------------
 
-static jint nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz,
+static jlong nativeCreateFromSurfaceTexture(JNIEnv* env, jclass clazz,
         jobject surfaceTextureObj) {
     sp<IGraphicBufferProducer> producer(SurfaceTexture_getProducer(env, surfaceTextureObj));
     if (producer == NULL) {
@@ -151,20 +150,20 @@
     }
 
     surface->incStrong(&sRefBaseOwner);
-    return int(surface.get());
+    return jlong(surface.get());
 }
 
-static void nativeRelease(JNIEnv* env, jclass clazz, jint nativeObject) {
+static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
     sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject));
     sur->decStrong(&sRefBaseOwner);
 }
 
-static jboolean nativeIsValid(JNIEnv* env, jclass clazz, jint nativeObject) {
+static jboolean nativeIsValid(JNIEnv* env, jclass clazz, jlong nativeObject) {
     sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject));
     return isSurfaceValid(sur) ? JNI_TRUE : JNI_FALSE;
 }
 
-static jboolean nativeIsConsumerRunningBehind(JNIEnv* env, jclass clazz, jint nativeObject) {
+static jboolean nativeIsConsumerRunningBehind(JNIEnv* env, jclass clazz, jlong nativeObject) {
     sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject));
     if (!isSurfaceValid(sur)) {
         doThrowIAE(env);
@@ -179,8 +178,7 @@
 static inline SkBitmap::Config convertPixelFormat(PixelFormat format) {
     /* note: if PIXEL_FORMAT_RGBX_8888 means that all alpha bytes are 0xFF, then
         we can map to SkBitmap::kARGB_8888_Config, and optionally call
-        bitmap.setAlphaType(kOpaque_SkAlphaType) on the resulting SkBitmap
-        (as an accelerator)
+        bitmap.setIsOpaque(true) on the resulting SkBitmap (as an accelerator)
     */
     switch (format) {
     case PIXEL_FORMAT_RGBX_8888:    return SkBitmap::kARGB_8888_Config;
@@ -193,14 +191,14 @@
 static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCanvas) {
   jobject canvasFinalizerObj = env->GetObjectField(canvasObj, gCanvasClassInfo.mFinalizer);
   SkCanvas* previousCanvas = reinterpret_cast<SkCanvas*>(
-          env->GetIntField(canvasObj, gCanvasClassInfo.mNativeCanvas));
-  env->SetIntField(canvasObj, gCanvasClassInfo.mNativeCanvas, (int)newCanvas);
-  env->SetIntField(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (int)newCanvas);
+          env->GetLongField(canvasObj, gCanvasClassInfo.mNativeCanvas));
+  env->SetLongField(canvasObj, gCanvasClassInfo.mNativeCanvas, (jlong)newCanvas);
+  env->SetLongField(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (jlong)newCanvas);
   SkSafeUnref(previousCanvas);
 }
 
-static jint nativeLockCanvas(JNIEnv* env, jclass clazz,
-        jint nativeObject, jobject canvasObj, jobject dirtyRectObj) {
+static jlong nativeLockCanvas(JNIEnv* env, jclass clazz,
+        jlong nativeObject, jobject canvasObj, jobject dirtyRectObj) {
     sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject));
 
     if (!isSurfaceValid(surface)) {
@@ -236,7 +234,7 @@
     ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
     bitmap.setConfig(convertPixelFormat(outBuffer.format), outBuffer.width, outBuffer.height, bpr);
     if (outBuffer.format == PIXEL_FORMAT_RGBX_8888) {
-        bitmap.setAlphaType(kOpaque_SkAlphaType);
+        bitmap.setIsOpaque(true);
     }
     if (outBuffer.width > 0 && outBuffer.height > 0) {
         bitmap.setPixels(outBuffer.bits);
@@ -264,11 +262,11 @@
     // because the latter could be replaced while the surface is locked.
     sp<Surface> lockedSurface(surface);
     lockedSurface->incStrong(&sRefBaseOwner);
-    return (int) lockedSurface.get();
+    return (jlong) lockedSurface.get();
 }
 
 static void nativeUnlockCanvasAndPost(JNIEnv* env, jclass clazz,
-        jint nativeObject, jobject canvasObj) {
+        jlong nativeObject, jobject canvasObj) {
     sp<Surface> surface(reinterpret_cast<Surface *>(nativeObject));
     if (!isSurfaceValid(surface)) {
         return;
@@ -287,8 +285,8 @@
 
 // ----------------------------------------------------------------------------
 
-static jint nativeCreateFromSurfaceControl(JNIEnv* env, jclass clazz,
-        jint surfaceControlNativeObj) {
+static jlong nativeCreateFromSurfaceControl(JNIEnv* env, jclass clazz,
+        jlong surfaceControlNativeObj) {
     /*
      * This is used by the WindowManagerService just after constructing
      * a Surface and is necessary for returning the Surface reference to
@@ -300,11 +298,11 @@
     if (surface != NULL) {
         surface->incStrong(&sRefBaseOwner);
     }
-    return reinterpret_cast<jint>(surface.get());
+    return reinterpret_cast<jlong>(surface.get());
 }
 
-static jint nativeReadFromParcel(JNIEnv* env, jclass clazz,
-        jint nativeObject, jobject parcelObj) {
+static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz,
+        jlong nativeObject, jobject parcelObj) {
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
     if (parcel == NULL) {
         doThrowNPE(env);
@@ -319,7 +317,7 @@
     if (self != NULL
             && (self->getIGraphicBufferProducer()->asBinder() == binder)) {
         // same IGraphicBufferProducer, return ourselves
-        return int(self.get());
+        return jlong(self.get());
     }
 
     sp<Surface> sur;
@@ -336,11 +334,11 @@
         self->decStrong(&sRefBaseOwner);
     }
 
-    return int(sur.get());
+    return jlong(sur.get());
 }
 
 static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
-        jint nativeObject, jobject parcelObj) {
+        jlong nativeObject, jobject parcelObj) {
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
     if (parcel == NULL) {
         doThrowNPE(env);
@@ -353,23 +351,23 @@
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gSurfaceMethods[] = {
-    {"nativeCreateFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)I",
+    {"nativeCreateFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)J",
             (void*)nativeCreateFromSurfaceTexture },
-    {"nativeRelease", "(I)V",
+    {"nativeRelease", "(J)V",
             (void*)nativeRelease },
-    {"nativeIsValid", "(I)Z",
+    {"nativeIsValid", "(J)Z",
             (void*)nativeIsValid },
-    {"nativeIsConsumerRunningBehind", "(I)Z",
+    {"nativeIsConsumerRunningBehind", "(J)Z",
             (void*)nativeIsConsumerRunningBehind },
-    {"nativeLockCanvas", "(ILandroid/graphics/Canvas;Landroid/graphics/Rect;)I",
+    {"nativeLockCanvas", "(JLandroid/graphics/Canvas;Landroid/graphics/Rect;)J",
             (void*)nativeLockCanvas },
-    {"nativeUnlockCanvasAndPost", "(ILandroid/graphics/Canvas;)V",
+    {"nativeUnlockCanvasAndPost", "(JLandroid/graphics/Canvas;)V",
             (void*)nativeUnlockCanvasAndPost },
-    {"nativeCreateFromSurfaceControl", "(I)I",
+    {"nativeCreateFromSurfaceControl", "(J)J",
             (void*)nativeCreateFromSurfaceControl },
-    {"nativeReadFromParcel", "(ILandroid/os/Parcel;)I",
+    {"nativeReadFromParcel", "(JLandroid/os/Parcel;)J",
             (void*)nativeReadFromParcel },
-    {"nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
+    {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
             (void*)nativeWriteToParcel },
 };
 
@@ -381,18 +379,18 @@
     jclass clazz = env->FindClass("android/view/Surface");
     gSurfaceClassInfo.clazz = jclass(env->NewGlobalRef(clazz));
     gSurfaceClassInfo.mNativeObject =
-            env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObject", "I");
+            env->GetFieldID(gSurfaceClassInfo.clazz, "mNativeObject", "J");
     gSurfaceClassInfo.mLock =
             env->GetFieldID(gSurfaceClassInfo.clazz, "mLock", "Ljava/lang/Object;");
-    gSurfaceClassInfo.ctor = env->GetMethodID(gSurfaceClassInfo.clazz, "<init>", "(I)V");
+    gSurfaceClassInfo.ctor = env->GetMethodID(gSurfaceClassInfo.clazz, "<init>", "(J)V");
 
     clazz = env->FindClass("android/graphics/Canvas");
     gCanvasClassInfo.mFinalizer = env->GetFieldID(clazz, "mFinalizer", "Landroid/graphics/Canvas$CanvasFinalizer;");
-    gCanvasClassInfo.mNativeCanvas = env->GetFieldID(clazz, "mNativeCanvas", "I");
+    gCanvasClassInfo.mNativeCanvas = env->GetFieldID(clazz, "mNativeCanvas", "J");
     gCanvasClassInfo.mSurfaceFormat = env->GetFieldID(clazz, "mSurfaceFormat", "I");
 
     clazz = env->FindClass("android/graphics/Canvas$CanvasFinalizer");
-    gCanvasFinalizerClassInfo.mNativeCanvas = env->GetFieldID(clazz, "mNativeCanvas", "I");
+    gCanvasFinalizerClassInfo.mNativeCanvas = env->GetFieldID(clazz, "mNativeCanvas", "J");
 
     clazz = env->FindClass("android/graphics/Rect");
     gRectClassInfo.left = env->GetFieldID(clazz, "left", "I");
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index b8d3c20..bd53095 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -61,21 +61,51 @@
 
 class ScreenshotPixelRef : public SkPixelRef {
 public:
-    ScreenshotPixelRef(const SkImageInfo& info, ScreenshotClient* screenshot) :
-      SkPixelRef(info),
-      mScreenshot(screenshot) {
+    ScreenshotPixelRef(SkColorTable* ctable) {
+        fCTable = ctable;
+        SkSafeRef(ctable);
         setImmutable();
     }
 
     virtual ~ScreenshotPixelRef() {
-        delete mScreenshot;
+        SkSafeUnref(fCTable);
+    }
+
+    status_t update(const sp<IBinder>& display, int width, int height,
+            int minLayer, int maxLayer, bool allLayers) {
+        status_t res = (width > 0 && height > 0)
+                ? (allLayers
+                        ? mScreenshot.update(display, width, height)
+                        : mScreenshot.update(display, width, height, minLayer, maxLayer))
+                : mScreenshot.update(display);
+        if (res != NO_ERROR) {
+            return res;
+        }
+
+        return NO_ERROR;
+    }
+
+    uint32_t getWidth() const {
+        return mScreenshot.getWidth();
+    }
+
+    uint32_t getHeight() const {
+        return mScreenshot.getHeight();
+    }
+
+    uint32_t getStride() const {
+        return mScreenshot.getStride();
+    }
+
+    uint32_t getFormat() const {
+        return mScreenshot.getFormat();
     }
 
 protected:
     // overrides from SkPixelRef
     virtual void* onLockPixels(SkColorTable** ct) {
-        *ct = NULL;
-        return (void*)mScreenshot->getPixels();
+        *ct = fCTable;
+        return (void*)mScreenshot.getPixels();
     }
 
     virtual void onUnlockPixels() {
@@ -83,7 +113,8 @@
 
     SK_DECLARE_UNFLATTENABLE_OBJECT()
 private:
-    ScreenshotClient* mScreenshot;
+    ScreenshotClient mScreenshot;
+    SkColorTable*    fCTable;
 
     typedef SkPixelRef INHERITED;
 };
@@ -91,7 +122,7 @@
 
 // ----------------------------------------------------------------------------
 
-static jint nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
+static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
         jstring nameStr, jint w, jint h, jint format, jint flags) {
     ScopedUtfChars name(env, nameStr);
     sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
@@ -102,20 +133,33 @@
         return 0;
     }
     surface->incStrong((void *)nativeCreate);
-    return int(surface.get());
+    return reinterpret_cast<jlong>(surface.get());
 }
 
-static void nativeRelease(JNIEnv* env, jclass clazz, jint nativeObject) {
+static void nativeRelease(JNIEnv* env, jclass clazz, jlong nativeObject) {
     sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
     ctrl->decStrong((void *)nativeCreate);
 }
 
-static void nativeDestroy(JNIEnv* env, jclass clazz, jint nativeObject) {
+static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
     sp<SurfaceControl> ctrl(reinterpret_cast<SurfaceControl *>(nativeObject));
     ctrl->clear();
     ctrl->decStrong((void *)nativeCreate);
 }
 
+static inline SkBitmap::Config convertPixelFormat(PixelFormat format) {
+    /* note: if PIXEL_FORMAT_RGBX_8888 means that all alpha bytes are 0xFF, then
+        we can map to SkBitmap::kARGB_8888_Config, and optionally call
+        bitmap.setIsOpaque(true) on the resulting SkBitmap (as an accelerator)
+    */
+    switch (format) {
+    case PIXEL_FORMAT_RGBX_8888:    return SkBitmap::kARGB_8888_Config;
+    case PIXEL_FORMAT_RGBA_8888:    return SkBitmap::kARGB_8888_Config;
+    case PIXEL_FORMAT_RGB_565:      return SkBitmap::kRGB_565_Config;
+    default:                        return SkBitmap::kNo_Config;
+    }
+}
+
 static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz, jobject displayTokenObj,
         jint width, jint height, jint minLayer, jint maxLayer, bool allLayers) {
     sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
@@ -123,50 +167,26 @@
         return NULL;
     }
 
-    ScreenshotClient* screenshot = new ScreenshotClient();
-    status_t res = (width > 0 && height > 0)
-            ? (allLayers
-                    ? screenshot->update(displayToken, width, height)
-                    : screenshot->update(displayToken, width, height, minLayer, maxLayer))
-            : screenshot->update(displayToken);
-    if (res != NO_ERROR) {
-        delete screenshot;
+    ScreenshotPixelRef* pixels = new ScreenshotPixelRef(NULL);
+    if (pixels->update(displayToken, width, height,
+            minLayer, maxLayer, allLayers) != NO_ERROR) {
+        delete pixels;
         return NULL;
     }
 
-    SkImageInfo screenshotInfo;
-    screenshotInfo.fWidth = screenshot->getWidth();
-    screenshotInfo.fHeight = screenshot->getHeight();
-
-    switch (screenshot->getFormat()) {
-        case PIXEL_FORMAT_RGBX_8888: {
-            screenshotInfo.fColorType = kRGBA_8888_SkColorType;
-            screenshotInfo.fAlphaType = kIgnore_SkAlphaType;
-            break;
-        }
-        case PIXEL_FORMAT_RGBA_8888: {
-            screenshotInfo.fColorType = kRGBA_8888_SkColorType;
-            screenshotInfo.fAlphaType = kPremul_SkAlphaType;
-            break;
-        }
-        case PIXEL_FORMAT_RGB_565: {
-            screenshotInfo.fColorType = kRGB_565_SkColorType;
-            screenshotInfo.fAlphaType = kIgnore_SkAlphaType;
-            break;
-        }
-        default: {
-            delete screenshot;
-            return NULL;
-        }
-    }
-
-    // takes ownership of ScreenshotClient
-    ScreenshotPixelRef* pixels = new ScreenshotPixelRef(screenshotInfo, screenshot);
-    ssize_t rowBytes = screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
+    uint32_t w = pixels->getWidth();
+    uint32_t h = pixels->getHeight();
+    uint32_t s = pixels->getStride();
+    uint32_t f = pixels->getFormat();
+    ssize_t bpr = s * android::bytesPerPixel(f);
 
     SkBitmap* bitmap = new SkBitmap();
-    bitmap->setConfig(screenshotInfo, rowBytes);
-    if (screenshotInfo.fWidth > 0 && screenshotInfo.fHeight > 0) {
+    bitmap->setConfig(convertPixelFormat(f), w, h, bpr);
+    if (f == PIXEL_FORMAT_RGBX_8888) {
+        bitmap->setIsOpaque(true);
+    }
+
+    if (w > 0 && h > 0) {
         bitmap->setPixelRef(pixels)->unref();
         bitmap->lockPixels();
     } else {
@@ -209,7 +229,7 @@
     SurfaceComposerClient::setAnimationTransaction();
 }
 
-static void nativeSetLayer(JNIEnv* env, jclass clazz, jint nativeObject, jint zorder) {
+static void nativeSetLayer(JNIEnv* env, jclass clazz, jlong nativeObject, jint zorder) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setLayer(zorder);
     if (err < 0 && err != NO_INIT) {
@@ -217,7 +237,7 @@
     }
 }
 
-static void nativeSetPosition(JNIEnv* env, jclass clazz, jint nativeObject, jfloat x, jfloat y) {
+static void nativeSetPosition(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat x, jfloat y) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setPosition(x, y);
     if (err < 0 && err != NO_INIT) {
@@ -225,7 +245,7 @@
     }
 }
 
-static void nativeSetSize(JNIEnv* env, jclass clazz, jint nativeObject, jint w, jint h) {
+static void nativeSetSize(JNIEnv* env, jclass clazz, jlong nativeObject, jint w, jint h) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setSize(w, h);
     if (err < 0 && err != NO_INIT) {
@@ -233,7 +253,7 @@
     }
 }
 
-static void nativeSetFlags(JNIEnv* env, jclass clazz, jint nativeObject, jint flags, jint mask) {
+static void nativeSetFlags(JNIEnv* env, jclass clazz, jlong nativeObject, jint flags, jint mask) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setFlags(flags, mask);
     if (err < 0 && err != NO_INIT) {
@@ -241,7 +261,7 @@
     }
 }
 
-static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jint nativeObject, jobject regionObj) {
+static void nativeSetTransparentRegionHint(JNIEnv* env, jclass clazz, jlong nativeObject, jobject regionObj) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
     if (!region) {
@@ -266,7 +286,7 @@
     }
 }
 
-static void nativeSetAlpha(JNIEnv* env, jclass clazz, jint nativeObject, jfloat alpha) {
+static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong nativeObject, jfloat alpha) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setAlpha(alpha);
     if (err < 0 && err != NO_INIT) {
@@ -274,7 +294,7 @@
     }
 }
 
-static void nativeSetMatrix(JNIEnv* env, jclass clazz, jint nativeObject,
+static void nativeSetMatrix(JNIEnv* env, jclass clazz, jlong nativeObject,
         jfloat dsdx, jfloat dtdx, jfloat dsdy, jfloat dtdy) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setMatrix(dsdx, dtdx, dsdy, dtdy);
@@ -283,7 +303,7 @@
     }
 }
 
-static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jint nativeObject,
+static void nativeSetWindowCrop(JNIEnv* env, jclass clazz, jlong nativeObject,
         jint l, jint t, jint r, jint b) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     Rect crop(l, t, r, b);
@@ -293,7 +313,7 @@
     }
 }
 
-static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jint nativeObject, jint layerStack) {
+static void nativeSetLayerStack(JNIEnv* env, jclass clazz, jlong nativeObject, jint layerStack) {
     SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
     status_t err = ctrl->setLayerStack(layerStack);
     if (err < 0 && err != NO_INIT) {
@@ -321,7 +341,7 @@
 }
 
 static void nativeSetDisplaySurface(JNIEnv* env, jclass clazz,
-        jobject tokenObj, jint nativeSurfaceObject) {
+        jobject tokenObj, jlong nativeSurfaceObject) {
     sp<IBinder> token(ibinderForJavaObject(env, tokenObj));
     if (token == NULL) return;
     sp<IGraphicBufferProducer> bufferProducer;
@@ -390,11 +410,11 @@
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod sSurfaceControlMethods[] = {
-    {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)I",
+    {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIII)J",
             (void*)nativeCreate },
-    {"nativeRelease", "(I)V",
+    {"nativeRelease", "(J)V",
             (void*)nativeRelease },
-    {"nativeDestroy", "(I)V",
+    {"nativeDestroy", "(J)V",
             (void*)nativeDestroy },
     {"nativeScreenshot", "(Landroid/os/IBinder;IIIIZ)Landroid/graphics/Bitmap;",
             (void*)nativeScreenshotBitmap },
@@ -406,23 +426,23 @@
             (void*)nativeCloseTransaction },
     {"nativeSetAnimationTransaction", "()V",
             (void*)nativeSetAnimationTransaction },
-    {"nativeSetLayer", "(II)V",
+    {"nativeSetLayer", "(JI)V",
             (void*)nativeSetLayer },
-    {"nativeSetPosition", "(IFF)V",
+    {"nativeSetPosition", "(JFF)V",
             (void*)nativeSetPosition },
-    {"nativeSetSize", "(III)V",
+    {"nativeSetSize", "(JII)V",
             (void*)nativeSetSize },
-    {"nativeSetTransparentRegionHint", "(ILandroid/graphics/Region;)V",
+    {"nativeSetTransparentRegionHint", "(JLandroid/graphics/Region;)V",
             (void*)nativeSetTransparentRegionHint },
-    {"nativeSetAlpha", "(IF)V",
+    {"nativeSetAlpha", "(JF)V",
             (void*)nativeSetAlpha },
-    {"nativeSetMatrix", "(IFFFF)V",
+    {"nativeSetMatrix", "(JFFFF)V",
             (void*)nativeSetMatrix },
-    {"nativeSetFlags", "(III)V",
+    {"nativeSetFlags", "(JII)V",
             (void*)nativeSetFlags },
-    {"nativeSetWindowCrop", "(IIIII)V",
+    {"nativeSetWindowCrop", "(JIIII)V",
             (void*)nativeSetWindowCrop },
-    {"nativeSetLayerStack", "(II)V",
+    {"nativeSetLayerStack", "(JI)V",
             (void*)nativeSetLayerStack },
     {"nativeGetBuiltInDisplay", "(I)Landroid/os/IBinder;",
             (void*)nativeGetBuiltInDisplay },
@@ -430,7 +450,7 @@
             (void*)nativeCreateDisplay },
     {"nativeDestroyDisplay", "(Landroid/os/IBinder;)V",
             (void*)nativeDestroyDisplay },
-    {"nativeSetDisplaySurface", "(Landroid/os/IBinder;I)V",
+    {"nativeSetDisplaySurface", "(Landroid/os/IBinder;J)V",
             (void*)nativeSetDisplaySurface },
     {"nativeSetDisplayLayerStack", "(Landroid/os/IBinder;I)V",
             (void*)nativeSetDisplayLayerStack },
diff --git a/core/jni/android_view_TextureView.cpp b/core/jni/android_view_TextureView.cpp
index 7a4a20a..54f9278 100644
--- a/core/jni/android_view_TextureView.cpp
+++ b/core/jni/android_view_TextureView.cpp
@@ -27,7 +27,6 @@
 
 #include <SkBitmap.h>
 #include <SkCanvas.h>
-#include <SkImage.h>
 
 namespace android {
 
@@ -60,9 +59,15 @@
 #define GET_INT(object, field) \
     env->GetIntField(object, field)
 
+#define GET_LONG(object, field) \
+    env->GetLongField(object, field)
+
 #define SET_INT(object, field, value) \
     env->SetIntField(object, field, value)
 
+#define SET_LONG(object, field, value) \
+    env->SetLongField(object, field, value)
+
 #define INVOKEV(object, method, ...) \
     env->CallVoidMethod(object, method, __VA_ARGS__)
 
@@ -104,35 +109,35 @@
     sp<ANativeWindow> window = new Surface(producer, true);
 
     window->incStrong((void*)android_view_TextureView_createNativeWindow);
-    SET_INT(textureView, gTextureViewClassInfo.nativeWindow, jint(window.get()));
+    SET_LONG(textureView, gTextureViewClassInfo.nativeWindow, jlong(window.get()));
 }
 
 static void android_view_TextureView_destroyNativeWindow(JNIEnv* env, jobject textureView) {
 
     ANativeWindow* nativeWindow = (ANativeWindow*)
-            GET_INT(textureView, gTextureViewClassInfo.nativeWindow);
+            GET_LONG(textureView, gTextureViewClassInfo.nativeWindow);
 
     if (nativeWindow) {
         sp<ANativeWindow> window(nativeWindow);
             window->decStrong((void*)android_view_TextureView_createNativeWindow);
-        SET_INT(textureView, gTextureViewClassInfo.nativeWindow, 0);
+        SET_LONG(textureView, gTextureViewClassInfo.nativeWindow, 0);
     }
 }
 
 static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCanvas) {
     jobject canvasFinalizerObj = env->GetObjectField(canvasObj, gCanvasClassInfo.mFinalizer);
     SkCanvas* previousCanvas = reinterpret_cast<SkCanvas*>(
-          env->GetIntField(canvasObj, gCanvasClassInfo.mNativeCanvas));
-    env->SetIntField(canvasObj, gCanvasClassInfo.mNativeCanvas, (int)newCanvas);
-    env->SetIntField(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (int)newCanvas);
+          env->GetLongField(canvasObj, gCanvasClassInfo.mNativeCanvas));
+    env->SetLongField(canvasObj, gCanvasClassInfo.mNativeCanvas, (jlong)newCanvas);
+    env->SetLongField(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (jlong)newCanvas);
     SkSafeUnref(previousCanvas);
 }
 
 static jboolean android_view_TextureView_lockCanvas(JNIEnv* env, jobject,
-        jint nativeWindow, jobject canvas, jobject dirtyRect) {
+        jlong nativeWindow, jobject canvas, jobject dirtyRect) {
 
     if (!nativeWindow) {
-        return false;
+        return JNI_FALSE;
     }
 
     ANativeWindow_Buffer buffer;
@@ -149,7 +154,7 @@
 
     sp<ANativeWindow> window((ANativeWindow*) nativeWindow);
     int32_t status = native_window_lock(window.get(), &buffer, &rect);
-    if (status) return false;
+    if (status) return JNI_FALSE;
 
     ssize_t bytesCount = buffer.stride * bytesPerPixel(buffer.format);
 
@@ -157,7 +162,7 @@
     bitmap.setConfig(convertPixelFormat(buffer.format), buffer.width, buffer.height, bytesCount);
 
     if (buffer.format == WINDOW_FORMAT_RGBX_8888) {
-        bitmap.setAlphaType(kOpaque_SkAlphaType);
+        bitmap.setIsOpaque(true);
     }
 
     if (buffer.width > 0 && buffer.height > 0) {
@@ -180,11 +185,11 @@
                 int(rect.left), int(rect.top), int(rect.right), int(rect.bottom));
     }
 
-    return true;
+    return JNI_TRUE;
 }
 
 static void android_view_TextureView_unlockCanvasAndPost(JNIEnv* env, jobject,
-        jint nativeWindow, jobject canvas) {
+        jlong nativeWindow, jobject canvas) {
 
     SkCanvas* nativeCanvas = SkNEW(SkCanvas);
     swapCanvasPtr(env, canvas, nativeCanvas);
@@ -207,9 +212,9 @@
     {   "nDestroyNativeWindow", "()V",
             (void*) android_view_TextureView_destroyNativeWindow },
 
-    {   "nLockCanvas", "(ILandroid/graphics/Canvas;Landroid/graphics/Rect;)Z",
+    {   "nLockCanvas", "(JLandroid/graphics/Canvas;Landroid/graphics/Rect;)Z",
             (void*) android_view_TextureView_lockCanvas },
-    {   "nUnlockCanvasAndPost", "(ILandroid/graphics/Canvas;)V",
+    {   "nUnlockCanvasAndPost", "(JLandroid/graphics/Canvas;)V",
             (void*) android_view_TextureView_unlockCanvasAndPost },
 };
 
@@ -237,14 +242,14 @@
     FIND_CLASS(clazz, "android/graphics/Canvas");
     GET_FIELD_ID(gCanvasClassInfo.mFinalizer, clazz, "mFinalizer",
             "Landroid/graphics/Canvas$CanvasFinalizer;");
-    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
+    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "J");
     GET_FIELD_ID(gCanvasClassInfo.mSurfaceFormat, clazz, "mSurfaceFormat", "I");
 
     FIND_CLASS(clazz, "android/graphics/Canvas$CanvasFinalizer");
-    GET_FIELD_ID(gCanvasFinalizerClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
+    GET_FIELD_ID(gCanvasFinalizerClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "J");
 
     FIND_CLASS(clazz, "android/view/TextureView");
-    GET_FIELD_ID(gTextureViewClassInfo.nativeWindow, clazz, "mNativeWindow", "I");
+    GET_FIELD_ID(gTextureViewClassInfo.nativeWindow, clazz, "mNativeWindow", "J");
 
     return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
 }
diff --git a/core/jni/android_view_VelocityTracker.cpp b/core/jni/android_view_VelocityTracker.cpp
index 90ba2ba..1e36932 100644
--- a/core/jni/android_view_VelocityTracker.cpp
+++ b/core/jni/android_view_VelocityTracker.cpp
@@ -138,26 +138,26 @@
 
 // --- JNI Methods ---
 
-static jint android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz,
+static jlong android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz,
         jstring strategyStr) {
     if (strategyStr) {
         ScopedUtfChars strategy(env, strategyStr);
-        return reinterpret_cast<jint>(new VelocityTrackerState(strategy.c_str()));
+        return reinterpret_cast<jlong>(new VelocityTrackerState(strategy.c_str()));
     }
-    return reinterpret_cast<jint>(new VelocityTrackerState(NULL));
+    return reinterpret_cast<jlong>(new VelocityTrackerState(NULL));
 }
 
-static void android_view_VelocityTracker_nativeDispose(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_view_VelocityTracker_nativeDispose(JNIEnv* env, jclass clazz, jlong ptr) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     delete state;
 }
 
-static void android_view_VelocityTracker_nativeClear(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_view_VelocityTracker_nativeClear(JNIEnv* env, jclass clazz, jlong ptr) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     state->clear();
 }
 
-static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jint ptr,
+static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jlong ptr,
         jobject eventObj) {
     const MotionEvent* event = android_view_MotionEvent_getNativePtr(env, eventObj);
     if (!event) {
@@ -170,13 +170,13 @@
 }
 
 static void android_view_VelocityTracker_nativeComputeCurrentVelocity(JNIEnv* env, jclass clazz,
-        jint ptr, jint units, jfloat maxVelocity) {
+        jlong ptr, jint units, jfloat maxVelocity) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     state->computeCurrentVelocity(units, maxVelocity);
 }
 
 static jfloat android_view_VelocityTracker_nativeGetXVelocity(JNIEnv* env, jclass clazz,
-        jint ptr, jint id) {
+        jlong ptr, jint id) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     float vx;
     state->getVelocity(id, &vx, NULL);
@@ -184,7 +184,7 @@
 }
 
 static jfloat android_view_VelocityTracker_nativeGetYVelocity(JNIEnv* env, jclass clazz,
-        jint ptr, jint id) {
+        jlong ptr, jint id) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     float vy;
     state->getVelocity(id, NULL, &vy);
@@ -192,7 +192,7 @@
 }
 
 static jboolean android_view_VelocityTracker_nativeGetEstimator(JNIEnv* env, jclass clazz,
-        jint ptr, jint id, jobject outEstimatorObj) {
+        jlong ptr, jint id, jobject outEstimatorObj) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     VelocityTracker::Estimator estimator;
     bool result = state->getEstimator(id, &estimator);
@@ -217,28 +217,28 @@
 static JNINativeMethod gVelocityTrackerMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInitialize",
-            "(Ljava/lang/String;)I",
+            "(Ljava/lang/String;)J",
             (void*)android_view_VelocityTracker_nativeInitialize },
     { "nativeDispose",
-            "(I)V",
+            "(J)V",
             (void*)android_view_VelocityTracker_nativeDispose },
     { "nativeClear",
-            "(I)V",
+            "(J)V",
             (void*)android_view_VelocityTracker_nativeClear },
     { "nativeAddMovement",
-            "(ILandroid/view/MotionEvent;)V",
+            "(JLandroid/view/MotionEvent;)V",
             (void*)android_view_VelocityTracker_nativeAddMovement },
     { "nativeComputeCurrentVelocity",
-            "(IIF)V",
+            "(JIF)V",
             (void*)android_view_VelocityTracker_nativeComputeCurrentVelocity },
     { "nativeGetXVelocity",
-            "(II)F",
+            "(JI)F",
             (void*)android_view_VelocityTracker_nativeGetXVelocity },
     { "nativeGetYVelocity",
-            "(II)F",
+            "(JI)F",
             (void*)android_view_VelocityTracker_nativeGetYVelocity },
     { "nativeGetEstimator",
-            "(IILandroid/view/VelocityTracker$Estimator;)Z",
+            "(JILandroid/view/VelocityTracker$Estimator;)Z",
             (void*)android_view_VelocityTracker_nativeGetEstimator },
 };
 
diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
index bf5accd..a860918 100644
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -21,7 +21,9 @@
 
 #include <utils/Log.h>
 #include <androidfw/ZipFileRO.h>
+#include <androidfw/ZipUtils.h>
 #include <ScopedUtfChars.h>
+#include <UniquePtr.h>
 
 #include <zlib.h>
 
@@ -143,7 +145,7 @@
 }
 
 static install_status_t
-sumFiles(JNIEnv* env, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntry, const char* fileName)
+sumFiles(JNIEnv*, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntry, const char*)
 {
     size_t* total = (size_t*) arg;
     size_t uncompLen;
@@ -178,7 +180,7 @@
         return INSTALL_FAILED_INVALID_APK;
     } else {
         struct tm t;
-        ZipFileRO::zipTimeToTimespec(when, &t);
+        ZipUtils::zipTimeToTimespec(when, &t);
         modTime = mktime(&t);
     }
 
@@ -200,7 +202,7 @@
     }
 
     // Only copy out the native file if it's different.
-    struct stat st;
+    struct stat64 st;
     if (!isFileDifferent(localFileName, uncompLen, modTime, crc, &st)) {
         return INSTALL_SUCCEEDED;
     }
@@ -273,26 +275,25 @@
     ScopedUtfChars cpuAbi(env, javaCpuAbi);
     ScopedUtfChars cpuAbi2(env, javaCpuAbi2);
 
-    ZipFileRO zipFile;
-
-    if (zipFile.open(filePath.c_str()) != NO_ERROR) {
+    UniquePtr<ZipFileRO> zipFile(ZipFileRO::open(filePath.c_str()));
+    if (zipFile.get() == NULL) {
         ALOGI("Couldn't open APK %s\n", filePath.c_str());
         return INSTALL_FAILED_INVALID_APK;
     }
 
-    const int N = zipFile.getNumEntries();
-
     char fileName[PATH_MAX];
     bool hasPrimaryAbi = false;
 
-    for (int i = 0; i < N; i++) {
-        const ZipEntryRO entry = zipFile.findEntryByIndex(i);
-        if (entry == NULL) {
-            continue;
-        }
+    void* cookie = NULL;
+    if (!zipFile->startIteration(&cookie)) {
+        ALOGI("Couldn't iterate over APK%s\n", filePath.c_str());
+        return INSTALL_FAILED_INVALID_APK;
+    }
 
+    ZipEntryRO entry = NULL;
+    while ((entry = zipFile->nextEntry(cookie)) != NULL) {
         // Make sure this entry has a filename.
-        if (zipFile.getEntryFileName(entry, fileName, sizeof(fileName))) {
+        if (zipFile->getEntryFileName(entry, fileName, sizeof(fileName))) {
             continue;
         }
 
@@ -346,15 +347,18 @@
                     && isFilenameSafe(lastSlash + 1))
                 || !strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) {
 
-            install_status_t ret = callFunc(env, callArg, &zipFile, entry, lastSlash + 1);
+            install_status_t ret = callFunc(env, callArg, zipFile.get(), entry, lastSlash + 1);
 
             if (ret != INSTALL_SUCCEEDED) {
                 ALOGV("Failure for entry %s", lastSlash + 1);
+                zipFile->endIteration(cookie);
                 return ret;
             }
         }
     }
 
+    zipFile->endIteration(cookie);
+
     return INSTALL_SUCCEEDED;
 }
 
diff --git a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp
index ec19f0a..0b9ad9b 100644
--- a/core/jni/com_android_internal_net_NetworkStatsFactory.cpp
+++ b/core/jni/com_android_internal_net_NetworkStatsFactory.cpp
@@ -80,7 +80,7 @@
         stats_line s;
         int64_t rawTag;
         if (sscanf(buffer, "%d %31s 0x%llx %u %u %llu %llu %llu %llu", &s.idx,
-                &s.iface, &rawTag, &s.uid, &s.set, &s.rxBytes, &s.rxPackets,
+                s.iface, &rawTag, &s.uid, &s.set, &s.rxBytes, &s.rxPackets,
                 &s.txBytes, &s.txPackets) == 9) {
             if (s.idx != lastIdx + 1) {
                 ALOGE("inconsistent idx=%d after lastIdx=%d", s.idx, lastIdx);
diff --git a/core/jni/com_android_internal_os_ZygoteInit.cpp b/core/jni/com_android_internal_os_ZygoteInit.cpp
index 44452f0..2233ee3 100644
--- a/core/jni/com_android_internal_os_ZygoteInit.cpp
+++ b/core/jni/com_android_internal_os_ZygoteInit.cpp
@@ -159,29 +159,6 @@
     }
 }
 
-static jlong com_android_internal_os_ZygoteInit_capgetPermitted (JNIEnv *env,
-    jobject clazz, jint pid)
-{
-    struct __user_cap_header_struct capheader;
-    struct __user_cap_data_struct capdata;
-    int err;
-
-    memset (&capheader, 0, sizeof(capheader));
-    memset (&capdata, 0, sizeof(capdata));
-
-    capheader.version = _LINUX_CAPABILITY_VERSION;
-    capheader.pid = pid;
-
-    err = capget (&capheader, &capdata);
-
-    if (err < 0) {
-        jniThrowIOException(env, errno);
-        return 0;
-    }
-
-    return (jlong) capdata.permitted;
-}
-
 static jint com_android_internal_os_ZygoteInit_selectReadable (
         JNIEnv *env, jobject clazz, jobjectArray fds)
 {
@@ -274,8 +251,6 @@
             (void *) com_android_internal_os_ZygoteInit_reopenStdio},
     { "setCloseOnExec", "(Ljava/io/FileDescriptor;Z)V",
         (void *)  com_android_internal_os_ZygoteInit_setCloseOnExec},
-    { "capgetPermitted", "(I)J",
-        (void *) com_android_internal_os_ZygoteInit_capgetPermitted },
     { "selectReadable", "([Ljava/io/FileDescriptor;)I",
         (void *) com_android_internal_os_ZygoteInit_selectReadable },
     { "createFileDescriptor", "(I)Ljava/io/FileDescriptor;",
diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
index 50b3302..a0982bd 100644
--- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp
+++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
@@ -82,7 +82,7 @@
     gSurface_NativePixelRefFieldID = _env->GetFieldID(surface_class, "mNativePixelRef", "I");
 
     jclass bitmap_class = _env->FindClass("android/graphics/Bitmap");
-    gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "I");
+    gBitmap_NativeBitmapFieldID = _env->GetFieldID(bitmap_class, "mNativeBitmap", "J");
 }
 
 static const jint gNull_attrib_base[] = {EGL_NONE};
@@ -276,7 +276,7 @@
     jint* base = 0;
 
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)_env->GetIntField(native_pixmap,
+            (SkBitmap const *)_env->GetLongField(native_pixmap,
                     gBitmap_NativeBitmapFieldID);
     SkPixelRef* ref = nativeBitmap ? nativeBitmap->pixelRef() : 0;
     if (ref == NULL) {
diff --git a/core/jni/com_google_android_gles_jni_GLImpl.cpp b/core/jni/com_google_android_gles_jni_GLImpl.cpp
index b0c26c51..b3b0049 100644
--- a/core/jni/com_google_android_gles_jni_GLImpl.cpp
+++ b/core/jni/com_google_android_gles_jni_GLImpl.cpp
@@ -183,7 +183,7 @@
             if (array) {
                 releasePointer(_env, array, buf, 0);
             }
-            buf = buf + offset;
+            buf = (char*)buf + offset;
         } else {
             jniThrowException(_env, "java/lang/IllegalArgumentException",
                               "Must use a native order direct Buffer");
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index daff390..05c9b17 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1056,9 +1056,8 @@
         android:permissionGroupFlags="personalInfo"
         android:priority="370" />
 
-    <!-- Allows an application to see the number being dialed during an outgoing
-         call with the option to redirect the call to a different number or
-         abort the call altogether. -->
+    <!-- Allows an application to modify or abort outgoing
+         calls. -->
     <permission android:name="android.permission.PROCESS_OUTGOING_CALLS"
         android:permissionGroup="android.permission-group.PHONE_CALLS"
         android:protectionLevel="dangerous"
@@ -1289,7 +1288,7 @@
     <!-- @hide Allows an application to create/manage/remove stacks -->
     <permission android:name="android.permission.MANAGE_ACTIVITY_STACKS"
         android:permissionGroup="android.permission-group.APP_INFO"
-        android:protectionLevel="signature"
+        android:protectionLevel="signature|system"
         android:label="@string/permlab_manageActivityStacks"
         android:description="@string/permdesc_manageActivityStacks" />
 
@@ -2357,13 +2356,13 @@
          @hide -->
     <permission android:name="android.permission.READ_DREAM_STATE"
         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
-        android:protectionLevel="signature" />
+        android:protectionLevel="signature|system" />
 
     <!-- Allows applications to write dream settings, and start or stop dreaming.
          @hide -->
     <permission android:name="android.permission.WRITE_DREAM_STATE"
         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
-        android:protectionLevel="signature" />
+        android:protectionLevel="signature|system" />
 
     <!-- Allow an application to read and write the cache partition.
          @hide -->
@@ -2523,7 +2522,7 @@
                  android:hasCode="false"
                  android:label="@string/android_system_label"
                  android:allowClearUserData="false"
-                 android:backupAgent="com.android.server.SystemBackupAgent"
+                 android:backupAgent="com.android.server.backup.SystemBackupAgent"
                  android:killAfterRestore="false"
                  android:icon="@drawable/ic_launcher_android"
                  android:supportsRtl="true">
diff --git a/core/res/res/anim/swipe_window_enter.xml b/core/res/res/anim/swipe_window_enter.xml
new file mode 100644
index 0000000..e1617e2
--- /dev/null
+++ b/core/res/res/anim/swipe_window_enter.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2007, 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+        android:interpolator="@interpolator/decelerate_quad" >
+    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
+        android:fillEnabled="true" android:fillBefore="true"
+        android:fillAfter="true"
+        android:duration="@android:integer/config_activityDefaultDur" />
+</set>
diff --git a/core/res/res/anim/swipe_window_exit.xml b/core/res/res/anim/swipe_window_exit.xml
new file mode 100644
index 0000000..ed0c5d3
--- /dev/null
+++ b/core/res/res/anim/swipe_window_exit.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2007, 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+        android:interpolator="@interpolator/decelerate_quad" >
+    <translate android:fromXDelta="0%" android:toXDelta="100%"
+        android:fillEnabled="true" android:fillBefore="true"
+        android:fillAfter="true"
+        android:duration="400" />
+</set>
diff --git a/core/res/res/layout/number_picker_with_selector_wheel_micro.xml b/core/res/res/layout/number_picker_with_selector_wheel_micro.xml
new file mode 100644
index 0000000..a1c09214
--- /dev/null
+++ b/core/res/res/layout/number_picker_with_selector_wheel_micro.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+**
+** Copyright 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.
+*/
+-->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <view class="android.widget.NumberPicker$CustomEditText"
+        android:textAppearance="?android:attr/textAppearanceLarge"
+        android:id="@+id/numberpicker_input"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:singleLine="true"
+        android:background="@null" />
+
+</merge>
diff --git a/core/res/res/layout/screen_swipe_dismiss.xml b/core/res/res/layout/screen_swipe_dismiss.xml
new file mode 100644
index 0000000..90e970fe
--- /dev/null
+++ b/core/res/res/layout/screen_swipe_dismiss.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!--
+This is a layout for a window whose resident activity is finished when swiped away.
+-->
+
+<com.android.internal.widget.SwipeDismissLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@android:id/content"
+    android:fitsSystemWindows="true"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    />
diff --git a/core/res/res/values-af/strings.xml b/core/res/res/values-af/strings.xml
index f384e24..1a9acd3 100644
--- a/core/res/res/values-af/strings.xml
+++ b/core/res/res/values-af/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Probeer weer oor <xliff:g id="COUNT">%d</xliff:g> sekondes"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Probeer later weer"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Sleep van bo af na onder om volskerm te verlaat"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Sleep van bo af na onder om volskerm te verlaat."</string>
 </resources>
diff --git a/core/res/res/values-am/strings.xml b/core/res/res/values-am/strings.xml
index d913063..e64b6f5 100644
--- a/core/res/res/values-am/strings.xml
+++ b/core/res/res/values-am/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"በ<xliff:g id="COUNT">%d</xliff:g> ሰከንዶች ውስጥ እንደገና ይሞክሩ"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"ቆይተው እንደገና ይሞክሩ"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"ከሙሉ ገጽ ማያ ለመውጣት ከላይ ወደታች ጣትዎን ያንቀሳቅሱ"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"ከሙሉ ገጽ ማያ ለመውጣት ጣትዎን ከላይ ወደታች ያንሸራትቱ።"</string>
 </resources>
diff --git a/core/res/res/values-ar/strings.xml b/core/res/res/values-ar/strings.xml
index 6ef77d8..2d91e28 100644
--- a/core/res/res/values-ar/strings.xml
+++ b/core/res/res/values-ar/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"أعد المحاولة خلال <xliff:g id="COUNT">%d</xliff:g> ثانية"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"أعد المحاولة لاحقًا"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"التمرير من أعلى لأسفل للخروج من وضع ملء الشاشة"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"مرر بسرعة من أعلى لأسفل للخروج من وضع ملء الشاشة."</string>
 </resources>
diff --git a/core/res/res/values-az-rAZ/strings.xml b/core/res/res/values-az-rAZ/strings.xml
deleted file mode 100644
index 7772887..0000000
--- a/core/res/res/values-az-rAZ/strings.xml
+++ /dev/null
@@ -1,1588 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"Başlıqsız"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"..."</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(Telefon nömrəsi yoxdur)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(Naməlum)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"Səsli poçt"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"Bağlantı problemi və ya yalnış MM kodu."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"Əməliyyat yalnız sabit nömrələrə yığımla məhdudlaşıb."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"Servis işə salındı."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"Xidmət aktiv edilmişdir:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"Xidmət deaktiv edilib."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"Qeydiyyat uğurlu oldu."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"Silinmə uğurlu olmuşdur."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"Yanlış parol"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI tamamdır."</string>
-    <string name="badPin" msgid="9015277645546710014">"Daxil etdiyiniz köhnə PİN düzgün deyil."</string>
-    <string name="badPuk" msgid="5487257647081132201">"Daxil etdiyiniz PUK düzgün deyil."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"Daxil etdiyiniz PİN kodlar uyğun gəlmir."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"4-dən 8-ə qədər rəqəmi olan PIN yazın."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"8 və daha çox rəqəmi olan PUK yazın."</string>
-    <string name="needPuk" msgid="919668385956251611">"Sizin SİM kart PUK ilə kilidlənib. Onu açmaq üçün PUK kodu yazın."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM kartın kilidini açmaq üçün PUK2 yazın"</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"Daxil olan zəng edənin ID\'si"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"Gedən Zəng ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"Zəng yönləndirmə"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"Zəng gözləyir"</string>
-    <string name="BaMmi" msgid="455193067926770581">"Zəng qadağası"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"Parolu dəyiş"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PİN dəyişmək"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"Hazırdakı nömrəyə zəng edilir"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"Zənglərin sayı məhdudlaşdırılıb"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"Üç yollu zəng"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"Xoşagəlməz zənglərdən imtina"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"Çatdırılma zəngi"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"Narahat etməyin"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"Adətən zəng edənin ID\'si məhdudlaşdırılır. Növbəti zəng: Məhdudlaşdırılıb"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"Adətən zəng edənin ID\'si məhdudlaşdırılır. Növbəti zəng: Məhdudlaşdırılmayıb"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"Adətən zəng edənin ID\'si məhdudlaşdırılmır. Növbəti zəng: Məhdudlaşdırılıb"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"Adətən zəng edənin ID\'si məhdudlaşdırılmır. Növbəti zəng: Məhdudlaşdırılmayıb"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"Xidmət təmin edilməyib."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"Siz zəng edənin ID nizamlarını dəyişə bilməzsiz."</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"Məhdudlaşdırılmış keçid dəyişdi"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"Data xidmət bağlıdır."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"Təcili xidmət bağlıdır."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"Səs xidməti bağlıdır."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"Bütün Səs xidmətləri bağlıdır"</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS xidməti bloklanıb."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"Səs/data xidmətləri bloklanıb."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"Səs/SMS xidmətləri bloklanıb."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"Bütün səs/data/SMS xidmətləri bağlıdır."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"Səs"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"Məlumat"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"FAKS"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"Async"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"Sinx"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"Paket"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"Rominq göstəricisi işləkdir"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"Rominq göstəricisi işlək deyil"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"Rominq göstəricisi yanır"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"Qonşuluqdan Kənar"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"Binadan kənar"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"Rominq - Arzuolunan sistem"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"Rominq - Mümkün sistem"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"Rominq - Alyans partnyoru"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"Rominq - Premium partnyor"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"Rouminq - Tam Xidmət Funksionallığı"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"Rouminq - Qismən Xidmət Funksionallığı"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"Rouminq Banneri Açıqdır"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"Roaming Banner Off"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"Xidmət axtarılır"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: Yönləndirilmədi"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> <xliff:g id="TIME_DELAY">{2}</xliff:g> saniyə sonra"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: Yönləndirilmədi"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: Yönləndirilmədi"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"Özəllik kodu tamamlandı."</string>
-    <string name="fcError" msgid="3327560126588500777">"Əlaqə problemi və ya yanlış funksiya kodu."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"OK"</string>
-    <string name="httpError" msgid="7956392511146698522">"Şəbəkə xətası var idi."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL tapıla bilmədi."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"Sayt autentifikasiya sxemi dəstəklənmir."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"Təsdiq edilə bilmədi."</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"Proksi server vasitəsilə təsdiqlənmə uğursuz oldu."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"Serverə qoşula bilmədi."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"Serverlə əlaqə alınmadı. Sonra cəhd edin."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"Server ilə olan əlaqə zaman aşımına məruz qaldı."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"Bu səhifədə həddindən çox server yönləndirilmələri var."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"Protokol dəstəklənmir."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"Güvənli bağlantı yaradıla bilmədi."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"URL yanlış olduğu üçün səhifəni açmaq mümkün olmadı."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"Fayla giriş baş tutmadı."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"Tələb olunan fayl tapılmadı."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Həddindən çox sorğu işlənilir. Daha sonra yoxlayın."</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g> üçün giriş xətası"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"Sinxronlaşdırma"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"Sinxronlaşdırma"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"Həddindən çox <xliff:g id="CONTENT_TYPE">%s</xliff:g> silinmələri var."</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"Planşetin yaddaşı doludur. Boş yer üçün bəzi faylları silin."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"Telefonun yaddaşı doludur. Boş yer üçün bəzi faylları silin."</string>
-    <string name="me" msgid="6545696007631404292">"Mən"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"Planşet seçimləri"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"Telefon seçimləri"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"Səssiz rejim"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"Simsizi işə salın"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"Simsiz rabitəni söndürün"</string>
-    <string name="screen_lock" msgid="799094655496098153">"Ekran kilidi"</string>
-    <string name="power_off" msgid="4266614107412865048">"Söndür"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"Zəng deaktivdir"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"Zəng vibrasiyadadır"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"Zəngvuran açıqdır"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"Söndürülür..."</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"Planşetiniz sönəcək."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"Telefonunuz sönəcək."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"Söndürmək istəyirsiz?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"Təhlükəsiz rejimdə yenidən başlayın"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"Təhlükəsiz rejimdə yenidən başlamaq istəyirsiniz mi? Bu, quraşdırdığınız bütün üçüncü tərəf tətbiqlərini deaktiv edəcək."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"Son"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"Heç bir son tətbiq yoxdur."</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"Planşet seçimləri"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"Telefon seçimləri"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"Ekran kilidi"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"Söndür"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"Baq hesabatı"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"Baqı xəbər verin"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"Bu, sizin hazırkı cihaz durumu haqqında məlumat toplayacaq ki, elektron məktub şəklində göndərsin. Baq raportuna başlamaq üçün bir az vaxt lazım ola bilər, bir az səbr edin."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"Səssiz rejim"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"Səs qapalıdır"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"Səs Aktivdir"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"Təyyarə rejimi"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"Uçuş rejimi açıqdır"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"Təyyarə rejimi qapalıdır"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"Təhlükəsiz rejim"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Android sistemi"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"Ödənişli xidmətlər"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"Xərc tutulacaq əməliyyatlar edir"</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"Sizin mesajlarınız"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"SMS, elektron poçt və digər mesajları oxuyur və yazır."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"Şəxsi məlumatınız"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"Kontakt kartınızda saxlanılan məlumatlarınıza birbaşa giriş."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"Sosial məlumatınız"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"Kontaktlarınız və sosial əlaqələriniz haqqında məlumata birbaşa giriş."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"Yerləşməniz"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"Fiziki adresinizi monitorinq edir."</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"Şəbəkə kommunikasiyası"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"Müxtəlif şəbəkə xüsusiyyətlərinə daxil ol."</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"Bluetooth"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"Bluetooth üzərindən cihazlara və şəbəkələrə daxil ol."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"Audio Ayarlar"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"Audio ayarları dəyişin."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"Batareyaya təsir edir"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"Batareyanızın tez qurtarmasına səbəb olan funksiyalar istifadə edir"</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"Təqvim"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"Təqvimə və tədbirlərə birbaşa giriş."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"İstifadəçi Lüğətini Oxu"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"İstifadəçi lüğətindəki sözləri oxuyur."</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"İstifadəçi Lüğətini Yaz"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"İstifadəçi lüğətinə sözlər əlavə edin."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"Əlfəcinlər və Tarixçə"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"Əlfəcinlərə və brauzer tarixinə birbaşa icazə."</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"Zəng"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"Alarm qur."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"Səsli poçt"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"Səs poçtuna birbaşa çıxış."</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"Mikrofon"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"Audio yazmaq üçün mikrofona birbaşa giriş."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"Kamera"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"Şəkil və ya video çəkmək üçün kameraya birbaşa çıxış."</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"Ekran kilidi"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"Cihazınızdakı kilid ekranının hərəkətinə təsir etmə bacarığı"</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"Tətbiq məlumatlarınız"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"Cihazınızdakı digər tətbiqlərin davranışına təsir etmək bacarığı."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"Divar kağızı"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"Cihazın divar kağızı ayarlarını dəyişin."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"Saat"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"Cihazın vaxt və zaman zolağını dəyişir."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"Status paneli"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"Cihazın status paneli ayarlarınızı dəyişir."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"Sinx Ayarları"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"Sinxronizasiya nizamlarına çıxış."</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"Hesablarınız"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"Əlçatımlı hesablara daxil olun."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"Hardware kontrolları"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"Dəstəkdəki avadanlığa birbaşa giriş."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"Telefon zəngləri"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"Telefon zənglərinə nəzarət edin, qeydə alın və idarə edin."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"Sistem alətləri"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"Aşağı səviyyəli çıxış və sistem idarəetməsi."</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"İnkişaf alətləri"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"Özəlliklər yalnız tətbiq developerləri üçün lazımdır."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"Digər tətbiq İstifadəçi İnterfeysi"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"Digər tətbiqlərin İstifadəçi İnterfeysinə təsir edir."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"Yaddaş"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB yaddaşa daxil ol."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD karta daxil ol."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"Əlçatımlılıq funksiyaları"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"Yardımçı texnologiya tələb edə biləcəyi funksiyalar."</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"Pəncərənin məzmununu əldə edin"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"Əlaqədə olduğunuz pəncərənin məzmununu nəzərdən keçirin."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"Toxunaraq Kəşf et funksiyasını yandırın"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"Toxunulan hissələr səsləndiriləcək və ekran jestlərlə idarə oluna biləcək."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"İnkişaf etmiş veb əlçatımlılığı yandırın"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"Skriptlər tətbiq məzmununun daha əlçatımlı olması üçün quraşdırıla bilər."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"Yazdığınız mətni izləyin"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"Kredit kartı nömrələri və parollar kimi şəxsi məlumatlar daxildir."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"status panelini deaktivləşdir və ya dəyişdir"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"Tətbiqə status panelini deaktiv etməyə və ya sistem ikonalarını əlavə etmək və ya silmək imkanı verir."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"status paneli"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"Tətbiqə status paneli olmağa imkan verir."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"status panelini genişlətmək və ya yığmaq"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"Tətbiqə status panelini genişləndirməyə və ya yox etməyə imkan verir."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"gedən zənglərin marşrutunu dəyişmək"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"Tətbiqə zəng etməyə və zəng edilən nömrəni dəyişməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək gedən zəngləri izləyə, yönləndirə və ya qarşısını ala bilər."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"SMS qəbul etmək"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"Tətbiqə MMS mesajlarını almaq və emal etmək icazəsi verir. Bu o deməkdir ki, tətbiq sizin mesajlarınızı sizə göstərmədən monitorinq edə və ya silə bilər."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"mətn mesajlarını qəbul edir (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"Tətbiqə MMS mesajlarını qəbul və emal üçün imkan verir. Bu o deməkdir ki, bu tətbiq sizə göstərmədən cihazınıza göndərilən mesajları silə bilər."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"təcili yayımları qəbul edir"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"Tətbiqə təcili yayım mesajlarını qəbul və emal etmək icazəsi verir. Bu icazə ancaq sistem tətbiqləri üçün mümkündür."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"mobil yayım mesajlarını oxuyur"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"Tətbiqə sizin telefonunuz tərəfindən alınmış yayım mesajlarını oxuma icazəsi verir. Telefon yayımı bəzi məkanlarda olan fövqəladə hadisələrlə bağlı sizi xəbərdar etmək üçün qəbul edilir. Zərərli tətbiqlər fövqəladə mobil yayım qəbul edildiyi zaman telefonunun performansına və əməliyyatına müdaxilə edə bilər."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS mesajlarını göndərir"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"Tətbiqə SMS mesajı göndərmə icazəsi verir. Bu gözlənilməyən ödənişlərə səbəb ola bilər. Zərərli tətbiqlər sizin təsdiqiniz olmadan mesaj göndərməklə sizə ödənişə səbəb ola bilərlər."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"mesajla cavab verilməli tədbirlər göndərmək"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"Tətbiqə zənglər üçün \"mesajla cavabla\" hadisələrini idarə etmək üçün digər mesajlaşma tətbiqlərinə sorğuların göndərilməsi icazəsi verir."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"tekst mesajlarınızı oxuyur (SMS və ya MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"Tətbiqə planşetinizdə və ya SIM kartınızda saxlanan SMS mesajları oxumağa imkan verir. Bu bütün SMS mesajların, onların məzmunundan və konfidensiallığından asılı olmadan oxunması imkanı deməkdir."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"Tətbiqə telefonunuzda və ya SIM kartınızda saxlanan SMS mesajları oxumağa imkan verir. Bu bütün SMS mesajların, onların məzmunundan və konfidensiallığından asılı olmadan oxunması imkanı deməkdir."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"mətn mesajlarınızı redaktə edir (SMS və ya MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"Tətbiqə telefonunuzda və ya SİM kartınızda yerləşən SMS mesajlara yazma icazəsi verir. Zərərli tətbiqlər sizin mesajlarınızı silə bilər."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"Tətbiqə telefonunuzda və ya SİM kartınızda yerləşən SMS mesajlara yazma icazəsi verir. Zərərli tətbiqlər sizin mesajlarınızı silə bilər."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"mətn mesajları qəbul etmək (WAP)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"Tətbiqə WAP mesajlar göndərmək və ya qəbul etmək imkanı verir. Buna mesajları izləmək və Sizə xəbər vermədən silmək imkanları da daxildir."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"işlənən tətbiqlər əldə etmək"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"Tətbiqə hazırda və az öncə işləyən tapşırıqlar haqqında ətraflı məlumat əldə etməyə imkan verir. Bu da cihazda hansı tətbiqlərin istifadə olunması haqqında məlumatların əldə edilməsinə imkan verir."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"istifadəçilər arasında əlaqə qurur"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"Tətbiqə bu cihazdakı digər istifadəçilərlə müxtəlif işləri görməyə icazə verir. Zərərli tətbiqlər bundan istifadəçilər arasındakı qorunmanı pozmaq üçün istifadə edə bilər."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"bütün istifadəçilər ilə əlaqə saxlamaq üçün tam hüquq"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"İstifadəçilər arasında bütün mümkün əlaqələrə imkan verir."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"istifadəçiləri idarə edir"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"Tətbiqlərə cihazda olan istifadəçiləri, habelə sorğu göndərmə, yaratma və silmə izni verir."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"işlənən tətbiqlərin detallarını əldə etmək"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"Tətbiqə hazırda və az öncə işləyən tapşırıqlar haqqında ətraflı məlumat əldə etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək şəxsi məlumatları oğurlaya bilər."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"işlənən tətbiqlərin sırasını dəyişmək"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"Tətbiqə tapşırıqları ön plandan arxa plana keçirməyə imkan verir. Tətbiq bunu Sizin daxiletməniz olmadan da edə bilər."</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"işlək tətbiqləri dayandırır"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"Tətbiqə tapşırıqları silməyə və onların tətbiqlərini məhv etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək digər tətbiqlərin işlərini dayandıra bilər."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"fəaliyyət toplularını idarə edin"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"Tətbiqə digər tətbiqlərin fəaliyyəti daxilində fəaliyyət toplularını əlavə etmək, silmək və dəyişmək imkanı verir."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"hər hansı bir fəaliyyət başlat"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"İcazə qorunması və ya eksport edilmiş statusdan asılı olmayaraq, tətbiqə hər hansı fəaliyyəti başlatmağa imkan verir."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"ekran uyğunluğunu yerləşdirir"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"Tətbiqə digər tətbiqlərin ekran uyğunluğunu yoxlamaq imkanı verir. Zərərli tətbiqlər digər tətbiqlərin fəaliyyətini poza bilər."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"tətbiq sazlanmasını aktiv edir"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"Tətbiqə digər bir tətbiq üçün sazlamanı açmaq üçün imkan verir. Zərərli tətbiqlər bunu digər tətbiqləri yox etmək üçün istifadə edə bilər."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"sistem ekran nizamlarını dəyiş"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"Tətbiqə yerli parametrlər və ya şriftin ölçüsü kimi cari konfiqurasiyanı dəyişməyə imkan verir."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"avtomobil rejimini aktivləşdirir"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"Tətbiqə avtomobil rejimini aktivləşdirməyə imkan verir."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"digər tətbiqləri qapatmaq"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"Tətbiqə başqa tətbiqlərin arxafon proseslərini dayandırmaq icazəsi verir. Bu digər tətbiqlərin dayanmasına səbəb ola bilər."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"Digər tətbiqləri dayanmağa məcbur et"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"Tətbiqə digər tətbiqləri məcburi şəkildə dayandırmağa imkan verir."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"tətbiqi qapanmağa məcbur etmək"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"Tətbiqə ön planda olan istənilən tətbiqi bağlayaraq geriyə dönməyə imkan verir. Normal tətbiqlər tərəfindən heç vaxt istifadə olunmamalıdır."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"sistemin daxili durumunu bərpa et"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"Tətbiqə sistemin daxili statusunu bərpa etməyə imkan verir. Zərərli tətbiqlər lazım olmadığı halda müxtəlif şəxsi və güvənli məlumatları bərpa edə bilər."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"ekran kontentini bərpa edir"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"Tətbiqə aktiv pəncərənin məzmununu əldə etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək pəncərə məzmununu ələ keçirib parollları oxuya bilər."</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"giriş imkanını müvəqqəti açmaq"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"Tətbiqə cihaza girişi müvəqqəti olaraq aktivləşdirməyə imkan verir. Zərərli tətbiqlər istifadəçi razılığı olmadan girişi aktivləşdirə bilər."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"pəncərə infosunu bərpa edir"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"Tətbiqə pəncərə idarəçisindən gələn windows haqqında olan məlumatı bərpa etməyə imkan verir. Zərərli tətbiqlər daxili sistem istifadəsi üçün nəzərdə tutulan məlumatı bərpa edə bilər."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"tədbirləri filtr edir"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"Tətbiqə daxiletmə filtrini qeydiyyat etdirməyə imkan verir, bu filtr bütün istifadəçi tədbirlərini göndərilməmişdən əvvəl filtrdən keçirir. Zərərli tətbiq istifadəçi müdaxiləsi olmadan İstifadəçi İnterfeysi sisteminə nəzarət edə bilər."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"ekranı böyüdür"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"Tətbiqə ekran kontentini böyütmək icazəsi verir. Zərərli tətbiqlər bundan istifadə edərək ekranda kontenti böyüdərək cihazın qeyri-stabilliyinə səbəb ola bilər."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"qismən söndürür"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"Aktivlik idarəçiliyini qapanmış hala gətirir. Tam qapanmanı həyata keçirmir."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"tətbiqdən tətbiqə keçidin qarşısını almaq"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"İstifadəçinin başqa tətbiqə keçməsinin qarşısını alır."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"cari tətbiq informasiyası əldə etmək"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="2512448855496067131">"Sahibinə ekranda öndə olan cari tətbiq haqda gizli məlumatı almaq icazəsi verir."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"işə salınan bütün tətbiqləri izləyir və idarə edir"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"Tətbiqə sistemin fəaliyyətləri necə başlatdığını nəzarət və kontrol etməyə imkan verir. Zərərli tətbiqlər sistemi tamamilə kompromis edə bilər. Bu icazə yalnız inkişaf üçündür, heç vaxt normal istifadə üçün deyil."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"qaldırılmış yayım paketini göndər"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"Tətbiqə tətbiq paketinin silinməsi haqqında bildiriş translasiya etmə icazəsi verir. Zərərli tətbiqlər bundan digər işlək tətbiqləri dayandırmaq üçün istifadə edə bilər."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS tərəfindən qəbul edilən yayım göndər"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"Tətbiqə mesaj gəlməsi haqqında bildirişi yayımlamaq imkanı verir. Zərərli tətbiqlər bundan gələn SMS mesajlarını saxtalaşdırmaq üçün istifadə edə bilər."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH tərəfindən qəbul edilən yayım göndər"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"Tətbiqə WAP PUSH mesajın alındığı haqda bildiriş translasiya etməyə icazə verir. Zərərli tətbiqlər bundan istifadə edərək saxta MMS mesaj alışı və ya səssizcə istənilən veb səhifəni zərərverici variantlarla dəyişmək üçün istifadə edə bilər."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"çalışan proseslərin sayını məhdudlaşdırır"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"Tətbiqə işlədiləcək maksimum proses sayını idarə etmə izni verir. Normal tətbiqlər tərəfindən tələb olunmur."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"arxafon tətbiqlərini dayanmağa məcbur edir"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"Tətbiqə aktivitilərin arxa fona getdiyi zaman bitməsini yoxlayır. Normal tətbiqlər tərəfindən tələn olunmur."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"batareya statistikalarını oxumaq"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"Tətbiqə cari aşağı səviyyəli data sitifadəsini oxumaq imkanı verir. Tətbiqə hansı tətbiqi istifadə etdiyiniz haqqında ətraflı məlumat tapmağa imkan verə bilər."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"batareya statistikalarını dəyişmək"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"Tətbiqə yığılmış batareya statistikasını redaktə etmə icazəsi verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"tətbiq əməliyyat statistikalarını əldə etmək"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"Toplanmış tətbiq əməliyyat statistikalarının bərpa edilməsinə imkan verir. Normal tətbiqlər tərəfindən istifadə üçün deyil."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"tətbiq əməliyyat statistikasını dəyişmək"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"Tətbiqə toplanmış tətbiq əməliyyat statistikasını dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"sistem yedəkləməsi və bərpasını idarə edir"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"Tətbiqə sistemi rezerv etməyə və mexanizmi bərpa etməyə imkan verir. Normal tətbiqlər tərəfindən istifadə edilmək üçün nəzərdə tutulmayıb.."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"tam rezervi təsdiq etmək və ya əməliyyatı bərpa etmək"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"Tətbiqə İstifadəçi İnterfeysi tam rezerv təsdiqini işə salmağa imkan verir. Heç bir tətbiq tərəfindən istifadə olunmamalıdır."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"icazəsiz pəncərələri görüntüləyir"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"Tətbiqə daxili sistem interfeysi tərəfindən istifadə edilməsi üçün nəzərdə tutulmuş pəncərələri yaratmağa icazə verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"digər tətbiqlər üzərində çəkmək"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"Tətbiqə digər tətbiqlərin və ya onların hissələrinin yuxarısında şəkil çəkməyə imkan verir. Onlar istənilən tətbiqin interfeysinin istifadəsinə müdaxilə edə və ya digər tətbiqlərdə axtardıqlarınızı dəyişə bilər."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"qlobal animasiya sürətini dəyişir"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"Tətbiqə istənilən vaxt qlobal animasiya sürətini (sürətli və ya yavaş animasiyalar) dəyişdirmək imkanı verir."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"tətbiq nişanlarını idarə etmək"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"Tətbiqlərə onların normal Z-orderinqi keçərək markerlərini yaratma və idarəetmə icazəsi verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"ekranı dondurur"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"Tətbiqə tam ekranlı yayım üçün ekranı müvəqqəti olaraq dondurma icazəsi verir."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"düymələri və idarəetmə düymələrini basır"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"Tətbiqə özünün daxiletmə tədbirlərini digər tətbiqlərə çatdırmağa imkan verir. Zərərli tətbiqlər planşeti ələ keçirmək üçün bundan istifadə edə bilər."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"Tətbiqə özünün daxiletmə tədbirlərini digər tətbiqlərə çatdırmağa imkan verir. Zərərli tətbiqlər telefonu ələ keçirmək üçün bundan istifadə edə bilər."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"yazdıqlarınızı və etdiklərinizi izləyir"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"Tətbiqə basdığınız düymələri izləmək imkanı verilir. Buna parolların və kredit kartı nömrələrinin yazılması da aiddir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"daxiletmə metoduna bağlanır"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"Sahibinə daxiletmə metodunun ən üst səviyyə interfeysinə bağlamaq imkanı verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"giriş xidmətinə bağlı qal"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"Sahibə giriş xidmətin ən üst səviyyə interfeysi bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"çap servisini qoşma"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"Sahibinə bir çap xidmətinin ən üst səviyə araüzünü bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindPrintSpoolerService" msgid="6807762783744125954">"çap spuler servisinə qoş"</string>
-    <string name="permdesc_bindPrintSpoolerService" msgid="3680552285933318372">"Sahibinə çap spuler xidmətinin ən üst səviyyə interfeysinə bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC xidmətlərinə qoşun"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Sahibinə NFC kartlarını emulyasiya edən tətbiqləri bir-birinə qoşmağa icazə verin. Normal tətbiqlər üçün lazım deyil."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"mətn servisini qoşma"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"Sahibinə bir mətn xidmətinin ən üst səviyyə araüzünü bağlamağa imkan verir(məsələn, SpellCheckerService). Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN xidmətə əlaqələndirmək"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"Sahibinə bir Vpn xidmətinin ən üst səviyyə araüzünü bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"divar kağızına bağlanır"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"Cihaz sahibinə yuxarı səviyyəli divar kağızı interfeysini cildləməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmamalıdır."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"widget servisini qoşma"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"Sahibinə vidcet servisin yüksək səviyyəli interfeysi ilə əlaqə saxlamaq icazəsi verir. Normal tətbiqlər tərəfindən heç vaxt istənilməməlidir."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"cihaz admini ilə ünsiyyət qurmaq"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"Sahibinə bir cihaz idarəçisinə planlar göndərmək üçün imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"cihaz admini əlavə edin və ya silin"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"Sahibinə aktiv cihaz administratorlarını əlavə etməyə və ya silməyə icazə verir. Normal tətbiqlər üçün tələb olunmamalıdır."</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"ekran oriyentasiyasını dəyişir"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"Tətbiqə istənilən zaman ekranın vəziyyətini dəyişmə icazəsi verir. Normal tətbiqlər tərəfindən tələb olunmur."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"kursor sürətini dəyişmək"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"Tətbiqə mausun və ya trekpedin kursor sürətini istənilən zaman dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmamalıdır."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"klaviatura sxemini dəyişir"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"Tətbiqə klaviatura sxemini dəyişmək imkanı verir. Normal tətbiqlər tərəfindən tələb olunmur."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"tətbiqlərə Linux siqnalları göndərir"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"Tətbiqə bütün davamlı proseslərə siqnal soğrusu göndərməyə imkan verir."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"təbiqi həmişə çalışdır"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"Tətbiqə öz komponentlərini yaddaşda saxlama icazəsi verir. Bu planşetin sürətini zəiflətməklə, digər tətbiqlər üçün mövcud olan yaddaşı limitləyə bilər."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"Tətbiqə öz komponentlərini yaddaşda saxlama icazəsi verir. Bu digər tətbiqlər üçün mövcud olan yaddaşı limitləyə bilər."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"tətbiqləri sil"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"Tətbiqə Android paketləri silmə icazəsi verir. Zərərli tətbiqlər bundan digər vacib tətbiqləri silmək üçün istifadə edə bilər."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"digər tətbiqlərin məlumatını silir"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"Tətbiqə istifadəçi datasını təmizləməyə imkan verir."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"digər tətbiqlərin keşini sil"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"Tətbiqə keş faylları silmə icazəsi verir."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"tətbiq saxlama yaddaşını ölçmək"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"Tətbiqə özünün kodunu, məlumatını və keş ölçüsünü alma icazəsi verir."</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"birbaşa tətbiqlər quraşdırmaq"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"Tətbiqə yeni və ya güncəllənmiş Android paketlərini quraşdırmağa imkan verir. Zərərli tətbiqlər bundan istifadə edərək güclü səlahiyyətlərə malik tətbiqləri endirə bilər."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"bütün tətbiq keş datasını silir"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"Tətbiqə planşetin yaddaşını boşaltmaq üçün digər tətbiqlərin keş fayllarını silmək imkanı verir. Bu da digər tətbiqlərin dataları yenidən əldə etmələri səbəbindən daha yavaş işləmələrinə səbəb ola bilər."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"Tətbiqə digər tətbiqlərin keş qovluğunu təmizləyərək telefonun yaddaşını boşaltmaq icazəsi verir. Bu digər tətbiqlərin məlumatlarını yenidən əldə etməli olduqlarına görə daha yavaş başlamasına səbəb olur."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"tətbiq resurslarının yerini dəyişir"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"Tətbiqə tətbiq resurslarını daxili mediadan xarici mediaya və əksinə daşımağa imkan verir."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"məxfi loq datasını oxuyur"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"Tətbiqə sistemin müxtəlif jurnal fayllarını oxumağa imkan verir. Bu da Sizin planşetdə etdikləriniz haqqında məlumatlar, həmçinin şəxsi və konfidensial məlumatlar ola bilər."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"Tətbiqə sistemin müxtəlif jurnal fayllarını oxumağa imkan verir. Bu da Sizin planşetdə etdikləriniz haqqında məlumatlar, həmçinin şəxsi və konfidensial məlumatlar ola bilər."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"oxutmaq üçün istənilən media dekoderi istifadə edir"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"Tətbiqə playback\'i deşifrə etmək üçün hər hansı bir quraşdırılmış media deşifrələyicisini istifadə etmık imkanı verir."</string>
-    <string name="permlab_manageCaCertificates" msgid="1678391896786882014">"etibarlı etimadnamələri idarə et"</string>
-    <string name="permdesc_manageCaCertificates" msgid="4015644047196937014">"Tətbiqə etibarlı etimadnamələr kimi CA sertifikatlarını quraşdırmaq və sistemdən silməyə icazə verir."</string>
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"diaga məxsus olan mənbələri yaz/oxu"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"Tətbiqə diag qrupa məsus olan resursları yazmaq və oxumaq icazəsi verir; məsələn  /dev qovluğundakı fayllar. Bu sistemin stabilliyinə və təhlükəsizliyinə təsir edə bilər. Bu ancaq istehsalçı və ya operator tərəfindən avadanlığa xas diaqnostika üçün olmalıdır."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"tətbiq komponentlərini aktivləşdirmə və ya deaktivləşdirmə"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"Tətbiqə digər tətbiq komponentinin aktiv olub-olmadığını dəyişmək imkanı verir. Zərərli tətbiqlər bundan əhəmiyyətli planşet imkanlarını deaktiv etmək üçün istifadə edə bilər. Bu icazə ilə ehtiyatlı olmaq lazımdır, çünki tətbiq komponentləri yararsız, ziddiyyətli, və ya qeyri-sabit statusa çevrilə bilər."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"Tətbiqə digər tətbiq komponentinin aktiv olub-olmadığını dəyişmək imkanı verir. Zərərli tətbiqlər bundan əhəmiyyətli telefon imkanlarını deaktiv etmək üçün istifadə edə bilər. Bu icazə ilə ehtiyatlı olmaq lazımdır, çünki tətbiq komponentləri yararsız, ziddiyyətli, və ya qeyri-sabit statusa çevrilə bilər."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"icazələr vermək və ya ləğv etmək"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"Tətbiqə bu və ya digər tətbiqlərə xüsusi iznlər verməyə icazə verir. Zərərli tətbiqlər  bundan izin vermədiyiniz özəllikləri özlərinə vermək üçün istifadə edə bilər."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"tərcih edilən tətbiqlər qur"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"Tətbiqə tərcih etdiyiniz tətbiqləri dəyişmək imkanı verir. Zərərli tətbiqlər şəxsi məlumatlarınızı toplamaq üçün cari tətbiqlərinizi aldadaraq işləyən tətbiqləri xəbərsiz dəyişə bilər."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"sistem ayarlarında dəyişiklik etmək"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"Tətbiqə sistem ayarları datasını redaktə etmə icazəsi verir. Zərərli tətbiqlər sistem ayarlarını korlaya bilər."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"təhlükəsiz sistem nizamlarını dəyişir"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"Tətbiqə sistemin təhlükəsiz ayarlar datasını dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə üçün deyil."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google xidmətlər xəritəsini dəyişdir"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"Tətbiqə Google xidmətlər xəritəsini dəyişdirmək imkanı verir. Normal tətbiqlərin istifadəsi üçün deyil."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"başlanğıcda işləyir"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"Tətbiqə sistem yükləməni bitirdiyi zaman dərhal özünü başlatmağa imkan verir. Bu planşeti başlatmağın uzun çəkməsinə səbəb ola bilər və tətbiqə həmişə çalışdıraraq bütün planşeti yavaşlatmağa imkan verir."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"Tətbiqə sistem bootinqi bitirdikdən dərhal sonra özünü başlatmaq icazəsi verir. Bu telefonun açılmasını ləngidə və daima işlək qalaraq telefonun sürətini aşağı sala bilər."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"daimi siqnal göndərmək"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"Tətbiqə yayım bitdikdən sonra da qalan çətin yayımlar göndərməyə imkan verir. Hədsiz istifadə çox yaddaş istifadəsinə səbəb olmaqla planşeti yavaş və qeyri-stabil edə bilər."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"Tətbiqə yayım bitdikdən sonra da qalan çətin yayımlar göndərməyə imkan verir. Hədsiz istifadə çox yaddaş istifadəsinə səbəb olmaqla telefonu yavaş və qeyri-stabil edə bilər."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"kontakrlatınızı oxumaq"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"Tətbiqə planşetinizdə yerləşən kontaktları oxumaq icazəsi verir, tez-tez zəng elədiyiniz, emailləşdiyiniz və ya əlaqə saxladığınız xüsusi individuallar daxil olmaqla. Bu icazə tətbiqlərə kontakt məlumatlarınızı saxlamağa və zərərli tətbiqlərə kontakt məlumatlarını sizin bilginiz olmada paylaşma imkanı yaradır."</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"Tətbiqə tez-tez zəng elədiyiniz, e-məktub göndərdiyiniz və ya əlaqə saxladığınız xüsusi individuallar daxil olmaqla telefonunuzda yerləşən kontaktları oxumaq icazəsi verir. Bu icazə tətbiqlərə kontakt məlumatlarınızı saxlamağa və zərərli tətbiqlərə kontakt məlumatlarını sizin xəbəriniz olmada paylaşma imkanı yaradır."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"kontaktlarınızı dəyişdirir"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"Tətbiqə planşetinizdəki zəng etmək tezliyiniz, elektron poçtlarınız, ünsiyyətləriniz haqqında məlumatları dəyişməyə imkan verir. Bu icazə kontakt məlumatlarının silinməsinə də imkan verir."</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"Tətbiqə Sizin zəng etmək tezliyiniz, elektron poçtlarınız, ünsiyyətləriniz haqqında məlumatları dəyişməyə imkan verir. Buna kontaktların silinməsi imkanı də daxildir."</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"zəng qeydiyyatını oxu"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"Tətbiqə gələn və gedən zənglər haqqında olan data daxil olmaqla bərabər planşetinizin zəng qeydiyyatını oxumağa imkan verir. Bu icazə tətbiqlərə zəng qeydiyyatınızı saxlamağa imkan verir və zərərli tətbiqlər zəng qeydiyyat datasını sizdən xəbərsiz paylaşa bilər."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"Tətbiqə telefon jurnalınızı oxumağa imkan verir, buna gələn və gedən zənglər haqqında məlumatlar da daxildir. Bu icazə tətbiqə zəng jurnalı datasını saxlamağa imkan verir ki, Zərərli tətbiqlər bundan istifadə edərək Sizdən xəbərsiz bütün məlumatlarnızı paylaşa bilər."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"zəng loqu yazır"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"Tətbiqə planşetinizdəki zəng jurnalını, həmçinin gedən və gələn zənglərin siyahısını dəyişməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək, zəng jurnalınıza dəyişiklik edə bilər."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"Tətbiqə sizin daxil olan və gedən zənglər daxil olmaqla telefon zəngi loqlarınızı redaktə etmək icazəsi verir. Zərərli tətbiqlər bundan telefon loqlarınızı silmək və ya redaktə etmək üçün istifadə edə bilər."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"öz kontakt kartınızı oxuyun"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"Tətbiqə cihazınızda yerləşən adınız və kontakt məlumatlarınız kimi şəxsi profil məlumatlarını oxuma icazəsi verir. Bu o deməkdir ki, tətbiq sizi tanıya və sizin profil məlumatlarınızı başqalarına göndərə bilər."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"sizin kontakt kartınızda dəyişiklik etmək"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"Tətbiqə cihazınızda yerləşən adınız və kontakt məlumatlarınız kimi şəxsi profil məlumatlarını dəyişmək və ya əlavə etmək icazəsi verir. Bu o deməkdir ki, tətbiq sizi tanıya və sizin profil məlumatlarınızı başqalarına göndərə bilər."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"sosial lentinizi oxuyur"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"Tətbiqə Sizin və dostlarınızın sosial güncəllərini əldə etmək və sinxronizə etmək icazəsi verir. Məlumat paylaşarkən diqqətli olun - konfidensiallıqdan asılı olmayaraq bu, Siz və dostlarınız arasında sosial şəbəkələrdəki danışığı oxumaq imkanı verir. Qeyd: bu icazə bütün sosial şəbəkələrdə icra edilə bilməz."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"sosial axınınıza yazır"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"Tətbiqə dostlarınızdan sosial yenilənmələri göstərmə icazəsi verir. Məlumat paylaşarkən diqqətli olun - bu dostlarınızdan gələn mesajı emal etməyə izn verir. Qeyd: bu icazə bütün sosial şəbəkələrə şamil olunmaya bilər."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"təqvim tədbirlərini və konfidensial məlumatları oxuyur"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"Tətbiqə dostlarınızın və əməkdaşlarınızın planşetinizdə yerləşən kalendar tədbirlərini oxumağa icazə verir. Bu tətbiqə konfidensiallıq və ya həssaslıqdan asılı olmayaraq sizin kalendar məlumatlarınızı paylaşmaq və ya saxlamağa imkan yaradır."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"Tətbiqə dost və əməkdaşlara məxsus olanlar daxil olmaqla planşetdə yerləşən bütün kalendar tətbiqlərini oxumaq icazəsi verir. Bu tətbiqə konfidensiallıq və ya həssaslıqdan asılı olmayaraq, Sizin kalendar məlumatlarınızı paylaşmaq və ya saxlamaq imkanı yaradır."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"cihaz sahibinin icazəsi olmadan təqvim tədbirləri əlavə etmək və ya dəyişmək, bunun haqqında bildirişlər göndərmək"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"Tətbiqə planşetinizdəki tədbirləri dəyişməyə, tədbir əlavə etməyə və ya silməyə imkan verir. Buna Sizin dostlarınızla və həmkarlarınızla birlikdə hazırladığınız tədbirlər də daxildir. Bu, tədbirə Sizin adınızdan və Sizdən xəbərsiz, təqvim sahibi kimi mesaj göndərmək imkanını verir."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"Dostlarınız və həmkarlarınıza məxsus olanlar da daxil olmaqla, tətbiqə telefonunuzdakı tədbirləri dəyişməyə, tədbir əlavə etməyə və ya silməyə imkan verir. Bu, tədbirə Sizin adınızdan və Sizdən xəbərsiz, təqvim sahibi kimi mesaj göndərmək imkanı verir."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"test üçün saxta məkan mənbələri"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"Test üçün saxta məkan mənbələri yaradın və ya yeni məkan provayderi quraşdırın. Bu tətbiqlərə GPS və məkan provayderləri kimi məkan mənbələrindən alınan məkan və/ya statusları yenidən yazmağa icazə verir."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"əlavə məkan provayderi əmrlərinə çıxış"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"Tətbiqə əlavə məkan provayderi əmrlərinə daxil olmaq imkanı verir. Bu tətbiqə GPS əməliyyatına və ya digər məkan mənbələrinə mane olmaq imkanı verə bilər."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"Məkan provayderini quraşdırmaq icazəsi"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"Yeni yerləşmə təchizatçısını test etmək və ya quraşdırmaq üçün mock yerləşmə mənbələri yarat. Bu tətbiqə yerləşmənin və/ya digər yerləşmə mənbələrindən GPS və ya yerləşmə təchizatçıları qayıtmış statusların ləğv etməsinə imkan verir."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"dəqiq yeri (GPS və şəbəkə-əsaslı)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"Qlobal Pozisiya Sistemini və ya şəbəkə qüllələri və Wi-Fi kimi şəbəkə məkanını istifadə edərək tətbiqə Sizin dəqiq yerinizi təyin etməyə imkan verir. Bu məkan xidmətləri aktivləşdirilməlidirlər ki, Siz tətbiqi istifadə edən zaman tətbiq onları istifadə edə bilsin. Tətbiqlər Sizin harada olmağınızı bunun vasitəsilə təyin edəcək, eyni zamanda, bu xidmət əlavə batareya enerjisi apara bilər."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"təxmini məkan (şəbəkə əsaslı)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"Tətbiqə təxmini yerinizi almaq üçün imkan verir. Bu yer, yerləşmə xidmətləri tərəfindən mobil qüllələr və Wi-Fi kimi şəbəkə yerləşmə mənbələrdən istifadə etməklə əldə edilir. Bu yerləşmə xidmətləri tətbiqin onlardan istifadəsi üçün açıq və cihazınızın onları istifadəsi üçün mövcud olmalıdır. Tətbiqlər bundan sizin təxminən harada olduğunuzu müəyyənləşdirmək üçün istifadə edə bilər."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger\'ə daxil olmaq"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"Tətbiqə aşağı səviyyəli SurfaceFnger özəlliklərini istifadə etməyə icazə verir."</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"freym buferi oxuyur"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"Tətbiqə freym buferinin kontentini oxumaq icazəsi verir."</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"Wifi görüntülərini quraşdır"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"Tətbiqə Wifi görüntülərini quraşdırmağa və onlara qoşulmağa imkan verir."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"WiFi görüntülərini dəyişir"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Tətbiqə Wifi displeylərinin aşağı səviyyəli funksiyalarını idarə etmək imkanı verir."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"audio çıxışı alın"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"Tətbiqə audio çıxışı almaq və yenidən yönləndirmək imkanı verir."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"video çıxışı alın"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"Tətbiqə video çıxışı almaq və yenidən yönləndirmək imkanı verir."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"təhlükəsiz video çıxışı alın"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"Tətbiqə güvənli video çıxışı almaq və yenidən yönləndirmək imkanı verir."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"audio ayarlarınızı dəyişir"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"Tətbiqə səs və hansı spikerin çıxış üçün istifadə olunduğu kimi qlobal səs ayarlarını dəyişdirməyə imkan verir."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"səs yaz"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"Tətbiqə mikrofonla audio yazmaq icazəsi verir. İcazə tətbiqə sizin təsdiqiniz olmadan istənilən zaman səs yazma izni verir."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"şəkil və video çəkmək"</string>
-    <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_cameraDisableTransmitLed" msgid="2651072630501126222">"kamera istifadə edildikdə LED göstərici ötürülməsini deaktiv edir"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"Öncədən quraşdırılmış sistem tətbiqinə kamera tərəfindən istifadə edilən LED indikatorunu söndürmək icazəsi verir."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"planşeti daimi olaraq aradan qaldır"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"telefonu həmişəlik deaktiv etmək"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"Tətbiqə planşeti birdəfəlik deaktiv etməyə imkan verir. Bu da çox təhlükəlidir."</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"Tətbiqə bütün telefonu birdəfəlik deaktivləşdirməyə imkan verir. Bu çox təhlükəlidir."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"planşeti yenidən yüklənməyə məcbur edir"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"telefonu yenidən yüklənməyə məcbur edir"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"Tətbiqə planşeti yenidən yükləməyə məcbur etmək imkanı verir."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"Tətbiqə telefonu yenidən yükləməyə məcbur etmək üçün imkan verir."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB yaddaş fayl sisteminə daxil olmaq"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD Kart fayl sisteminə daxil olmaq"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"Tətbiqə silinəbilən yaddaşları və ya fayl sistemini quraşdırma və ayırma icazəsi verir."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB yaddaşı silir"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD kartı silir"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"Tətbiqə çıxarıla bilən yaddaşı format etməyə imkan verir."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"daxili yaddaşınız haqqında məlumat əldə etmək"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"Tətbiqə daxili yaddaş haqqında məlumat almağa imkan verir."</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"daxili yaddaş yaratmaq"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"Tətbiqə daxili yaddaş yaratmaq üçün imkan verir."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"daxili yaddaşı məhv etmə"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"Tətbiqə daxili yaddaşı məhv etmə icazəsi verir."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"daxili yaddaşı montaj və ya demontaj etmək"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"Tətbiqə daxili yaddaşı quraşdırma/ayırma icazəsi verir."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"daxili yaddaşın adını dəyiş"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"Tətbiqə daxili yaddaşın adını dəyişmək imkanı 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_manageUsb" msgid="1113453430645402723">"USB cihazlar üçün tərcihləri və icazələri idarə etmək"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"Tətbiqə USB cihazlar üçün olan tərcihləri və icazələri idarə etməyə imkan verir."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP protokol həyata keçirmək"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"Kernel MTP drayverə girişə imkan verir ki, MTP USB protokolunu həyata keçirsin."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"avadanlığı sınaq edir"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"Tətbiqə avadanlığı yoxlamaq üçün müxtəlif periferiyaları kontrol 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_callPrivileged" msgid="4198349211108497879">"istənilən nömrəyə birbaşa zəng edir"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"Tətbiqə Sizin müdaxiləniz olmadan, təcili zənglər də daxil olmaqla, istənilən telefon zəngini etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək, təcili nömrələrə qanunsuz zəng vurmaqla Sizin üçün hüquqi problemlər yarada bilər."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA planşet ayarlarına birbaşa başlamaq"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA telefon quraşdırmalarına birbaşa başlamaq"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"Tətbiqə CDMA hazırlığını başlatma icazəsi verir. Zərərli tətbiqlər ehtiyac olmadıqda CDMA hazırlığını başlada bilərlər."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"məkan güncəlləmə bildirişlərini idarə edir"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"Tətbiqə radiodan gələn məkan güncəllənmələrini aktiv və ya deaktiv etməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"qeydiyyat xüsusiyyətlərini əldə edir"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"Tətbiqə giriş qeydi servisi tərəfindən yüklənmiş mülkiyyətə girişi oxumaq/yazmaq imkanl verir. Normal tətbiqlər üçün nəzərdə tutulmayıb."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"vidcetlər seç"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"Tətbiqə sistemə hansı vidcetin hansı tətbiq tərəfindən istifadə edilə bilməsini deməyə icazə verir. Bu icazəli tətbiqlər şəxsi məlumatlara və digər tətbiqlərə çıxış verə bilər. Normal tətbiqlər tərəfindən istifadə üçün deyil."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"telefon statusunu dəyişmək"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"Tətbiqə cihazın telefon funksiyalarını idarə etmək imkanı verir. Belə icazəli tətbiq Sizi xəbərdar etmədən şəbəkələri qoşa, telefon radiosunu yandırıb-söndürə bilər."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"telefon statusunu və identifikasiyanı oxuyur"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"Tətbiqə cihazın telefon funksiyalarına giriş icazəsi verir. Belə icazəli tətbiq bu telefonun nömrəsini və cihaz İD\'ni, zəngin aktiv olub-olmadığını və zəng edilən nömrəni müəyyən edə bilər."</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"planşetin yuxu rejiminin qarşısını almaq"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"telefonun yuxu rejiminə keçməsini əngəllə"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"Tətbiqə planşetin yuxu rejimini qadağan etməyə imkan verir."</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"Tətbiqə telefonun yuxu rejimini qadağan etmək imkanı verir."</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"planşeti yandırma və ya söndürmə"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"telefonu yandırmaq və ya söndürmək"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"Tətbiqə planşeti yandırmağa və söndürməyə imkan verir."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"Tətbiqə telefonu yandırıb söndürmə icazəsi verir."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"zavod test rejimində işləyir"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"Planşet avadanlığına tam girişə imkan verməklə aşağı səviyyəli istehsalçı sınağı kimi işləyir. Yalnız planşet istehsalçı sınaq rejimində olduqda işləyir."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"Bir aşağı səviyyəli istehsalçı testi kimi çalışdırın, telefon hardware üçün tam giriş imkanı verir. Ancaq telefon, istehsalçı test rejimində çalışdığı zaman aktivdir."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"divar kağızı yerləşdirir"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"Tətbiqə sistemə divar kağızı yerləşdirmək icazəsi verir."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"divar kağızı ölçüsünü verir"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"Tətbiqə sistem divar kağızı ölçüsü göstərişlərini müəyyən etməyə imkan verir."</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"fabrik defoltuna sıfırlamaq"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"Tətbiqə bütün məlumatları, nizamları və quraşdırılmış tətbiqləri silərək sistemi fabrik nizamlarına qaytarmaq imkanı verir."</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"vaxtı təyin edir"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"Tətbiqə planşetin saat vaxtını dəyişməyə imkan verir."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"Tətbiqə telefonun saat vaxtını dəyişməyə imkan verir."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"vaxt zonasını quraşdırır"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"Tətbiqə planşetin vaxt zonasını dəyişmə icazəsi verir."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"Tətbiqə telefon saat zolağını dəyişmək üçün imkan verir."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService kimi davranır"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"Tətbiqə AccountAuthenticators\'ə zəng etməyə imkan verir."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"cihazda hesabları tapır"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"Tətbiqə planşet tərəfindən bilinən hesabların siyahısını alma icazəsi verir. Bu quraşdırdığınız tətbiqlər tərəfindən yaradılmış istənilən hesab ola bilər."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"Tətbiqə telefonda olan hesabların siyahısını əldə etməyə imkan verir. Buna quraşdırdığınız istənilən tətbiq tərəfindən yaradılan hesablar da aiddir."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"hesablar yaradır və parollar təyin edir"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"Tətbiqə AccountManager\'in hesab yaratmaq və parol almaq və açmaq daxil olmaqla bərabər, hesab təsdiqləyici imkanlarını istifadə etməyə icazə verir."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"hesabları əlavə edir və ya silir"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"Tətbiqə hesabların əlavə olunması və ya silinməsi, həmçinin onların parollarının silinməsi kimi əməliyyatları icra etməyə imkan verir."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"cihazda hesablar istifadə etmək"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"Tətbiqə autentifikasiya tokenləri sorğularını göndərməyə icazə verir."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"şəbəkə bağlantılarına baxmaq"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"Tətbiqə mövcud olan və qoşulan şəbəkələr kimi qoşulmalar haqqında məlumatı görməyə icazə verir."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"tam şəbəkə girişi"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"Tətbiqə şəbəkə soketlərini yaratmağa və fərdi şəbəkə protokollarını istifadə etməyə imkan verir. Brauzer və digər tətbiqlər datanın internetə ötürülməsini təmin edən vəsaitlər verir, ona görə də datanın internetə gönrədilməsi üçün bu icazə tələb olunmur."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"şəbəkə nizamlarını və trafiki dəyişdirir/qarşısını alır"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"Tətbiqə şəbəkə trafikinin qarşısını almaq üçün şəbəkə nizamlarını dəyişmə icazəsi verir, məsələn proksini və ya istənilən APN-in portunu. Zərərli tətbiqlər şəbəkə paketlərini sizin bilginiz olmadan monitorinq edə, yönləndirə və ya redaktə edə bilər."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"şəbəkə bağlantısını dəyişir"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"Tətbiqə şəbəkə vəziyyətini dəyişməyə icazə verir."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"Sərhədli bağlantını dəyişir"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"Tətbiqə birləşilmiş şəbəkə bağlantısının statusunu dəyişməyə imkan verir."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"arxafon data istifadəsi ayarını dəyişir"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"Tətbiqə fon rejimi nizamlarını dəyişməyə icazə verir."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"Wi-Fi bağlantılarına baxmaq"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"Tətbiqə Wi-Fi şəbəkələri haqqında məlumatı görməyə icazə verir, məsələn, Wi-Fi mövcudluğu və qoşulmuş Wi-Fi cihazlarının adları."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"Wi-Fi şəbəkəsinə qoşulmaq və ya ayrılmaq"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"Tətbiqə Wi-Fi çıxış nöqtəsinə qoşulmaq və ondan ayrılmaq və cihazın Wi-Fi şəbəkə nizamlarını dəyişməyə icazə verir."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"Wi-Fi Multicast qəbuluna icazə ver"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"Tətbiqə Wi-Fi şəbəkədə sizin planşetdən başqa digər multikast adreslərə yönləndirilmiş paketləri almaq icazəsi verir. Bu qeyri-çoxadresli rejimdən fəqli olaraq daha çox enerji işlədir."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"Tətbiqə qrup ünvanlar istifadə etməklə, Wi-Fi şəbəkəsində olan bütün cihazlara göndərilmiş paketləri qəbul etməyə imkan verir. Buna daha çox enerji sərf olunur."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"Bluetooth ayarlarını əldə edir"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"Tətbiqə yerli Bluetooth planşetinin konfiqurasiyasını görməyə və məsafədən cihazları tapmağa və cütləməyə imkan verir."</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"Tətbiqə lokal Bluetooth telefonunu konfiqurə etməyə və uzaq cihazları kəşf etmək və onlara qoşulmaq icazəsi verir."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX\'a qoşul və bağlantını kəs"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"Tətbiqə WiMAX mövcudluğu və qoşulmuş WiMAX şəbəkələrini təyin etməyə icazə verir."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"WiMAX vəziyyətini dəyişir"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"Tətbiqə planşeti WiMAX şəbəkələrinə qoşmaq və onlardan ayırmaq icazəsi verir."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"Tətbiqə telefonu WiMAX şəbəkəsinə qoşmağa və ya WiMAX şəbəkəsindən ayırmağa imkan verir."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"Bluetooth cihazları ilə cütləndirmək"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"Tətbiqə yerli Bluetooth planşetinin konfiqurasiyasını görməyə və cütlənmiş cihazlarla bağlantılar etməyə və qəbul etməyə imkan verir."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"Tətbiqə Bluetooth və ya telefon konfiqurasiyalarını görməyə və qoşulmuş cihazlarla əlaqə qurmağa və qəbul etməyə icazə verir."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"Near Field Communication\'ı kontrol et"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"Tətbiqə Yaxın Məsafə Kommunikasiyası (NFC) teqləri, kartları və oxuyucuları ilə əlaqə qurmağa icazə verir."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"Ekran kilidini deaktiv edir"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"Tətbiqə kilid açarını və təhlükəsizlik parolunu deaktiv etməyə imkan verir. Qanuni misal budur ki, telefon zəng qəbul edən zaman kilidi açır və zəng qurtarandan sonra kilidi bağlayır."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"sinx ayarlarını oxu"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"Tətbiqə hesablar üçün sinxronizasiya nizamlarını oxuma icazəsi verir. Məsələn, bu Şəxslər tətbiqinin sinxronizə olunub-olunmadığını təyin edə bilər."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"sinxronizasiyaya davam edir və onu söndürür"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"Tətbiqə hesab üçün sinxronizasiya nizamlarını dəyişməyə icazə verir. Məsələn, bu istifadəçi hesablı Şəxslər tətbiqinin sinxronizasiyasını başlamaq üçün istifadə edilə bilər."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"sinxronizasiya statistikasını oxumaq"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"Tətbiqə sync tədbirlərinin tarixçəsi və nə qədər datanın sinx olduğu da daxil olmaqla bərabər, hər hansı bir hesab üçün olan sinx statlarını oxumağa imkan verir."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"abunə olunmuş xəbərləri oxuyur"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"Tətbiqə hazırda sinxron lentlər haqqında ətraflı məlumat almaq üçün imkan verir."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"abunə olunmuş xəbərləri yazır"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"Tətbiqə cari sinxronlaşmış lentlərinizə dəyişiklik etmək imkanı verir. Zərərli tətbiqlər sixronlaşmış lentlərinizi dəyişə bilər."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"lüğətə əlavə etdiyiniz şərtləri oxumaq"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"Tətbiqə istifadəçinin lüğətdə saxladığı bütün sözləri, adları və frazaları oxumaq icazəsi verir."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"istifadəçi lüğətinə sözlər əlavə etmək"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"Tətbiqə istifadəçi lüğətinə yeni sözlər yazmağa imkan verir."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"qorunmuş yaddaşa daxil olmağa cəhd etmək"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"qorunmuş yaddaşa daxil olmağa cəhd etmək"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"Tətbiqə gələcək cihazlarda əlçatımlı olacaq USB yaddaş üçün icazə testi etməyə imkan verir."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"Tətbiqə gələcək cihazlarda mövcud olacaq SD kart üçün icazəni test etmək üçün imkan verir."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"USB yaddaşınızın məzmununu dəyişmək və ya silmək"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"SD kart kontentlərini dəyişir və ya silir"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"Tətbiqə USB yaddaşa yazmağa imkan verir."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"Tətbiqə SD karta yazma icazəsi verir."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"daxili media yaddaşı kontentini dəyişir/silir"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"Tətbiqə daxili media yaddaşdakı kontenti redaktə etmək icazəsi verir."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"sənəd yaddaşını nizamlayır"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"Tətbiqə sənəd yaddaşını idarə etməyə imkan verir."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"bütün istifadəçilərin xarici yaddaşına daxil ol"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"Tətbiqə bütün istifadəçilər üçün olan xarici yaddaşa giriş imkanı verir."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"keş fayl sisteminə girmək"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"Tətbiqə keş fayl sistemini oxumağa və yazmağa icazə verir."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"İnternet zəngləri etmək və ya qəbul etmək"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"Tətbiqə internet zənglərinin göndərilməsi və qəbul edilməsi üçün SIP servisindən istifadə icazəsi verir."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"tarixi şəbəkə istifadəsini oxu"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"Tətbiqə xüsusi şəbəkələr və tətbiqlər üçün tarixi şəbəkə istifadəsini oxumağa icazə verir."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"şəbəkə siyasətini idarə etmək"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"Tətbiqə şəbəkə qanunlarını və tətbiqin xüsusi qaydalarını idarə etmək imkanı verir."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"şəbəkə istifadə hesabını dəyişmək"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"Tətbiqə şəbəkə istifadəsinin tətbiqlərə qarşı nizamlarını redaktə etməyə icazə verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"soket işarələrini dəyişin"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"Tətbiqə araşdırma üçün soket işarələrini dəyişmək imkanı verir"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"bildirişlərə daxil ol"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"Tətbiqə bildirişləri əldə etməyə, sınamağa və təmizləməyə imkan verir, buna digər tətbiqlər tərəfindən verilmiş bildirişlər də daxildir."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"bildiriş dinləmə xidmətinə bağlanır"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"Sahibinə yüksək səviyyəli bildiriş dinləmə servisi ilə əlaqə saxlamağa icazə verir. Normal tətbiqlər tərəfindən heç vaxt istənilməməlidir."</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"operator xidmətli konfiurasiya tətbiqinə müraciət edin"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"Sahibinə operator xidmətli tətbiq konfiqurasiyasına  müraciət imkanı verir. Normal tətbiqlər üçün tələb olunmamalıdır."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"şəbəkə şəraiti haqqında müşahidələr üçün qulaq asmaq"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"Tətbiqə şəbəkə şəraiti üzrə müşahidələr üçün qulaq asmaq imkanı verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_hotwordRecognition" msgid="3225080408746361313">"isti söz tanınması tələb et"</string>
-    <string name="permdesc_hotwordRecognition" msgid="3716741260195364252">"Tətbiqə isti söz tanınması tələb etməyə imkan verir. Normal tətbiq üçün lazım ola bilməz."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"Parol qaydalarını təyin edin"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"Ekran kilidini açan şifrələrin uzunluğunu və onlardakı icazə verilən işarələrə nəzarət edir."</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"Ekran kilidi cəhdlərini monitorinq et"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"Ekan kilidini açarkən daxil edilmiş yanlış parollara baxın və əgər həddindən çox yanlış parollar daxil edilibsə, planşeti kilidləyin və ya bütün planşet datasını silin."</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"Ekan kilidini açarkən daxil edilmiş yanlış parollara baxın və əgər həddindən çox yanlış parollar daxil edilibsə, telefonu kilidləyin və ya bütün telefon datasını silin."</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"Ekran kilid parolunu dəyişin"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"Ekran kilidini açan şifrəni dəyişdirin."</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"Ekranı kilidləyin"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"Ekranın nə vaxt və necə kilidlənməsinə nəzarət edir."</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"Bütün məlumatları silin"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"Planşetin datasını xəbərdarlıq olmadan, zavod data sıfırlaması ilə silin."</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"Telefonun datasını xəbərdarlıq olmadan, zavod data sıfırlaması ilə silin"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"Cihazın qlobal proksisini ayarlayın"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"Siyasət aktiv olarkən cihazın qlobal proksisini istifadə üçün qurun. Yalnız ilk cihaz admini effektiv qlobal proksini təyin edir."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"Ekran kilidi şifrəsinə son zaman seç"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"Ekran kilidi parolunun nə qədər tez-tez dəyişməsini kontrol edin."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"Yaddaş şifrələnməsini ayarlayın"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"Tətbiq məlumatlarının şifrələnməsini tələb edir."</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"Kameraları dekativ edin"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"Bütün cihaz kameralarının istifadəsini əngəllə."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"Klaviatura kilidində funksiyaları deaktiv edin"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"Klaviatura kilidində bəzi funksiyaların qarşısını alın."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"Əsas səhifə"</item>
-    <item msgid="869923650527136615">"Mobil"</item>
-    <item msgid="7897544654242874543">"İş"</item>
-    <item msgid="1103601433382158155">"İş Faksı"</item>
-    <item msgid="1735177144948329370">"Ev Faksı"</item>
-    <item msgid="603878674477207394">"Peycer"</item>
-    <item msgid="1650824275177931637">"Digər"</item>
-    <item msgid="9192514806975898961">"Şəxsi"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"Ana səhifə"</item>
-    <item msgid="7084237356602625604">"İş"</item>
-    <item msgid="1112044410659011023">"Digər"</item>
-    <item msgid="2374913952870110618">"Fərdi"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"Əsas səhifə"</item>
-    <item msgid="5629153956045109251">"İş"</item>
-    <item msgid="4966604264500343469">"Digər"</item>
-    <item msgid="4932682847595299369">"Düzənləyin"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"Əsas səhifə"</item>
-    <item msgid="1359644565647383708">"İş"</item>
-    <item msgid="7868549401053615677">"Digər"</item>
-    <item msgid="3145118944639869809">"Fərdi"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"İş"</item>
-    <item msgid="4378074129049520373">"Digər"</item>
-    <item msgid="3455047468583965104">"Fərdi"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Söhbət"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"Şəxsi"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"Ev"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"Mobil"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"İş"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"İş Faksı"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"Ev Faksı"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"Peycer"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"Digər"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"Geriyə zəng"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"Avtomobil"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"Şirkət"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"Əsas"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"Digər faks"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"Radio"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"Teleks"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"Mobil iş telefonu"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"İş Peyceri"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"Köməkçi"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"Fərdi"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"Doğum günü"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"İldönümü"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"Digər"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"Fərdi"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"Əsas səhifə"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"İş"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"Digər"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"Mobil"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"Fərdi"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"Əsas səhifə"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"İş"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"Digər"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"Fərdi"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"Ana səhifə"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"İş"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"Digər"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"Şəxsi"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Görüşlər"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"İş"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"Digər"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"Fərdi"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"Şəxsi"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"Köməkçi"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"Qardaş"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"Uşaq"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"Ev yoldaşı"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"Ata"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"Dost"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"Müdir"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"Ana"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"Valideyn"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"Ortaq"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"Dəvət edən"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"Qohum"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"Bacı"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"Həyat yoldaşı"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"Fərdi"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"Əsas səhifə"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"İş"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"Digər"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PİN kodu daxil edin"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK və yeni PİN kod daxil edin"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK kod"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Yeni PIN kodu"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Şifrə daxil etmək üçün toxunun"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Kilidi açmaq üçün parol yazın"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Kilidi açmaq üçün PIN daxil edin"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Yanlış PIN kodu."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Kilidi açmaq üçün Menyu, sonra 0 basın."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"Təcili nömrə"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"Xidmət yoxdur."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"Ekran kilidlənib."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"Təcili zəng kilidini açmaq və ya yerləşdirmək üçün Menyu düyməsinə basın."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"Kilidi açmaq üçün Menyu düyməsinə basın."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"Kilidi açmaq üçün model çəkin"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"Təcili zəng"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"Zəngə qayıt"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"Düzdür!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Bir də cəhd edin"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Bir daha cəhd et"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Sifət kilidi cəhdləriniz bitdi"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"Batareya yığılır, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"Dolub"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"Elektrikə qoşun."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM kart yoxdur."</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"Planşetdə SIM kart yoxdur."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"Telefonda SİM kart yoxdur."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SİM kart daxil edin."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SİM kart yoxdur və ya oxuna bilinmir. SİM kart daxil edin."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"Yararsız SIM kart."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"Sizin SİM kartınız daimi olaraq deaktivləşib.\n Başqa SİM kart üçün simsiz xidmət provayderinizə müraciət edin."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"Əvvəlki trek düyməsi"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"Növbəti trek düyməsi"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"Pauza düyməsi"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"Oxutma düyməsi"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"Dayandırma düyməsi"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"Yalnız təcili zənglər"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"Şəbəkə kilidlidir"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM kart PUK ilə kilidlənib."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"İstifadəçi Təlimatlarına baxın və ya Müştəri Xidmətlərinə müraciət edin."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM kart kilidlənib."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SİM kartın kilidi açılır..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"Siz kilid modelini <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış çəkdiniz. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə içində yenidən sınayın."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"Şifrənizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz.\n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın"</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"Siz PIN nömrənizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz. \n \n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə içində təkrar sınayın."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"Siz kilidi açmaq üçün şablonu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə səhv çəkdiniz. <xliff:g id="NUMBER_1">%d</xliff:g> daha uğursuz cəhddən sonra planşetin kilidini Google hesabınıza daxil olmaqla açmağınız istəniləcək.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində bir daha yoxlayın."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"Siz kilidi açmaq üçün şablonu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə səhv çəkdiniz. <xliff:g id="NUMBER_1">%d</xliff:g> daha uğursuz cəhddən sonra planşetin kilidini Google hesabınıza daxil olmaqla açmağınız tələb olunacaq.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində bir daha yoxlayın."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"Siz planşet kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, planşet fabrik ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"Siz telefon kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, telefon zavod ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"Siz planşetin kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> yanlış cəhd etmisiniz. Planşet artıq defolt zavod halına sıfırlanacaq."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"Siz telefonun kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> dəfə səhv cəhd etdiniz. Telefonunuz indi zavod nizamlarına yenilənəcək."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"<xliff:g id="NUMBER">%d</xliff:g> saniyə ərzində bir daha cəhd edin."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"Şablonu unutdunuz?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"Hesab kilid açma"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"Həddindən çox cəhd edildi!"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"Kilidi açmaq üçün Google hesabınız ilə daxil olun."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"İstifadəçi adı (e-poçt)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"Şifrə"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"Daxil olun"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"Yanlış istifadəçi adı və parol."</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"İstifadəçi adınızı və ya parolunuzu unutmusunuz?\n "<b>"google.com/accounts/recovery"</b>" linkinə daxil olun."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"Yoxlanır..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"Kilidi aç"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"Səs açıqdır"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"Səs sönülüdür"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"Model başlandı"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"Model təmizləndi"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"Xana əlavə edildi"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"Model tamamlandı"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Widget %2$d of %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Widget əlavə edin."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Boş"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Kilidi açma sahəsi genişləndi."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Kilidi açma sahəsi çökdü."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> vidcet."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"İstifadəçi selektoru"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Status"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Kamera"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Media kontrolları"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Yenidən sıralama vidceti başladıldı."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Vidcetin təkrar sifarişi sona çatdı."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Vidcet <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> silindi."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Kilidi açma sahəsini genişləndir."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Sürüşdürmə kilidi."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Kild açma modeli."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Sifət Kilidi"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin kilid açması."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Şifrə kilidi."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Model sahəsi."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Sürüşdürmə sahəsi."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"simvol"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"söz"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"link"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"xətt"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"Zavod testi alınmadı"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"Bu FACTORY_TEST fəaliyyəti yalnızca/sistemdə/tətbiqdə quraşdırılmış paketlər üçün dəstəklənir."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"FACTORY_TEST əməliyyatını təsdiqləyən heç bir paket tapılmadı."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"Yenidən yükləyin"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"\"<xliff:g id="TITLE">%s</xliff:g>\"dakı səhifədə deyilir:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"Naviqasiyanı Təsdiq edin"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"Bu Səhifəni Tərk edin"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"Bu səhifədə qalın"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nBu səhifədən kənara naviqasiya etmək istədiyinizə əminsiniz mi?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"Təsdiqlə"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"Məsləhət: Böyütmək və kiçiltmək üçün iki dəfə tıklayın."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"Avtodoldurma"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"AvtoDoldurmanı ayarla"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"Vilayət"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"Poçt kodu"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"Dövlət"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"Poçt indeksi"</string>
-    <string name="autofill_county" msgid="237073771020362891">"Ölkə"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"Ada"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"Sahə"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"Departament"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"Prefektura"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"Pariş"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"Sahə"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"Əmirlik"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"Veb əlfəcinlərinizi və tarixçələrinizi oxumaq"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"Tətbiqə Brauzerin daxil olduğu bütün linkləri və bütün Brauzer əlfəcinlərini oxumaq imkanı verir. Qeyd: bu icazə veb brauzer imkanları olan üçüncü tərəf brazuerləri və digər tətbiqlər tərəfindən yerinə yetirilə bilməz."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"veb əlfəcinləri və tarixçəsi yazmaq"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"Tətbiqə planşetinizdəki brauzer tarixini və əlfəcinləri redaktə etmək icazəsi verir. Bu tətbizə brauzer məlumatlarını silmək və ya redaktə etmək imkanı verə bilər. Qeyd: Bu icazə 3-cü partiya brauzerlərə və ya veb brauzing xüsusiyyətli digər tətbiqlərə şamil olunmaya bilər."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"Tətbiqə Brauzer tarixçəsi və telefonunuzda saxlanılan əlfəcinlərə dəyişiklik etmək imkanı verir. Bununla tətbiqlə Brauzer datanızı silə və ya dəyişdirə bilər. Qeyd: bu icazə veb brauzer imkanları olan üçüncü tərəf brazuerləri və digər tətbiqlər tərəfindən yerinə yetirilə bilməz."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"siqnal qurur"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"Tətbiqə quraşdırlmış zəngli saata alarm ayarlamağa imkan verir. Bəzi zəngli saat tətbiqləri bu özəlliyi dəstəkləməyə bilər."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"Səsli poçt əlavə et"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"Tətbiqə səsli poçt qutunuza mesaj əlavə etməyə imkan verir."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"Brauzerin geolokasiya icazələrini dəyişir"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"Tətbiqə Brauzerin geolokasiya icazələrini dəyişməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək məkan məlumatlarını təsadüfi saytlara göndərə bilər."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"paketləri təsdiqlə"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"Tətbiqə paketin quraşdırılabilən olmasını yoxlamağa imkan verir."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"paket doğrulayıcıya bağlanır"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"Sahibinə paket yoxlayıcılarına sorğu göndərmək icazəsi verir. Normal tətbiqlər tərəfindən heç vaxt istənilməməlidir."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"serial porta çıxır"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"Sahibinə SerialManager API vasitəsilə serial portlara icazə izni verir."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"xarici kontent provayderlərinə giriş"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"Məzmun provayderlərinə örtükdən daxil olmaq üçün cihaz sahibinə imkan verir. Normal tətbiqlər üçün lazım deyil."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"avtomatik cihaz yenilənmələrini pozur"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"Sahibinə yeni versiyaya yenilənmək üçün nə vaxt qeyri-interaktiv reboot məlumatını sistemə təklif etmə icazəsi verir."</string>
-    <string name="save_password_message" msgid="767344687139195790">"Brauzerin bu şifrəni yadda saxlamasını istəyirsiz?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"İndi yox"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"Yadda saxla"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"Heç vaxt"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"Bu səhifəni açmaq üçün icazəniz yoxdur."</string>
-    <string name="text_copied" msgid="4985729524670131385">"Mətn panoya kopyalandı."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"Daha çox"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"Menyu+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"boşluq"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"daxil olun"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"sil"</string>
-    <string name="search_go" msgid="8298016669822141719">"Axtar"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"Axtarış"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"Axtarış sorğusu"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"Sorğunu təmizlə"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"Sorğunu göndərin"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"Səsli axtarış"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"Toxunaraq Kəşf et funksiyası aktiv edilsin?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> Toxunaraq Kəşf Et rejimini aktivləşdirmək istəyir. Toxunaraq Kəşf Et açıldığı zaman, barmağınızın altında nə olduğu haqda olan təsvirləri eşidə və ya görə bilərsiniz və yaplanşetdə insanlarla əlaqəyə keçmək üçün jestlər həyata keçirə bilərsiniz."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> Toxunaraq Kəşf Et rejimini aktivləşdirmək istəyir. Toxunaraq Kəşf Et açıldığı zaman, barmağınızın altında nə olduğu haqda olan təsvirləri eşidə və ya görə bilərsiniz və ya telefonda insanlarla əlaqəyə keçmək üçün jestlər həyata keçirə bilərsiniz"</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"1 ay öncə"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"1 ay əvvəl"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"1 saniyə əvvəl"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> saniyə əvvəl"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"1 dəqiqə əvvəl"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə əvvəl"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"1 saat əvvəl"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> saat əvvəl"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"Son <xliff:g id="COUNT">%d</xliff:g> gün"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"Keçən ay"</string>
-    <string name="older" msgid="5211975022815554840">"Köhnə"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"dünən"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> gün əvvəl"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"1 saniyə ərzində"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> saniyə içində"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"1 dəqiqə içində"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə ərzində"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"1 saata"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> saata"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"sabah"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> gün ərzində"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"1 saniyə əvvəl"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> san əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"1 dəqiqə əvvəl"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"1 saat əvvəl"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> saat əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"dünən"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> gün əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"1 san ərzində"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> san ərzində"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"1 dəq ərzində"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> dəqiqəyə"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"1 saat ərzində"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> saata"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"sabah"</item>
-    <item quantity="other" msgid="2973062968038355991">"<xliff:g id="COUNT">%d</xliff:g> günə"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g> tarixində"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"saat <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> ilində"</string>
-    <string name="day" msgid="8144195776058119424">"gün"</string>
-    <string name="days" msgid="4774547661021344602">"günlər"</string>
-    <string name="hour" msgid="2126771916426189481">"saat"</string>
-    <string name="hours" msgid="894424005266852993">"saatlar"</string>
-    <string name="minute" msgid="9148878657703769868">"dəq."</string>
-    <string name="minutes" msgid="5646001005827034509">"dəqiqə"</string>
-    <string name="second" msgid="3184235808021478">"sn"</string>
-    <string name="seconds" msgid="3161515347216589235">"san"</string>
-    <string name="week" msgid="5617961537173061583">"həftə"</string>
-    <string name="weeks" msgid="6509623834583944518">"həftə"</string>
-    <string name="year" msgid="4001118221013892076">"il"</string>
-    <string name="years" msgid="6881577717993213522">"il"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 saniyə"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> saniyə"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"1 dəqiqə"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"1 saat"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> saat"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"Video problemi"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"Bu video bu cihaza strim olunmaq üçün uyğun deyil."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"Bu video oxumur"</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"OK"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"günorta"</string>
-    <string name="Noon" msgid="3342127745230013127">"Günorta"</string>
-    <string name="midnight" msgid="7166259508850457595">"gecəyarı"</string>
-    <string name="Midnight" msgid="5630806906897892201">"Gecəyarı"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"Hamısını seç"</string>
-    <string name="cut" msgid="3092569408438626261">"Kəs"</string>
-    <string name="copy" msgid="2681946229533511987">"Kopyala"</string>
-    <string name="paste" msgid="5629880836805036433">"Yerləşdir"</string>
-    <string name="replace" msgid="5781686059063148930">"Əvəz et..."</string>
-    <string name="delete" msgid="6098684844021697789">"Sil"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL kopyala"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"Mətn seçin"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"Mətn seçimi"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"Lüğətə əlavə et"</string>
-    <string name="deleteText" msgid="6979668428458199034">"Sil"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"Daxiletmə metodu"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"Mətn əməliyyatları"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"Yaddaş yeri bitir"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"Bəzi sistem funksiyaları işləməyə bilər"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> işlənir"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"Daha çox məlumat üçün və ya tətbiqi dayandırmaq üçün toxunun."</string>
-    <string name="ok" msgid="5970060430562524910">"OK"</string>
-    <string name="cancel" msgid="6442560571259935130">"Ləğv et"</string>
-    <string name="yes" msgid="5362982303337969312">"OK"</string>
-    <string name="no" msgid="5141531044935541497">"Ləğv et"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"Diqqət"</string>
-    <string name="loading" msgid="7933681260296021180">"Yüklənir…"</string>
-    <string name="capital_on" msgid="1544682755514494298">"AÇIQ"</string>
-    <string name="capital_off" msgid="6815870386972805832">"QAPALI"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"Əməliyyatı tamamlayın:"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"Bu fəaliyyət üçün defolt istifadə edin"</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"Sistem ayarlarında, Tətbiqlərdə və Endirilmişlərdə defoltu təmizləyin."</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"Fəaliyyət seçin"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB cihaz üçün tətbiq seçin"</string>
-    <string name="noApplications" msgid="2991814273936504689">"Heç bir tətbiq bu əməliyyatı apara bilmir."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"Təəssüf ki, <xliff:g id="APPLICATION">%1$s</xliff:g> dayandı."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"Təəssüf ki, <xliff:g id="PROCESS">%1$s</xliff:g> prosesi dayandı."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> cavab vermir.\n\nOnu bağlamaq istəyirsiniz?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> aktivitisi cavab vermir. \n\nOnu bağlamaq istəyirsiniz?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> cavab vermir. Onu bağlamaq istəyirsiniz?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"Proses <xliff:g id="PROCESS">%1$s</xliff:g> cavab vermir. \n \n Onu bağlamaq istəyirsiniz?"</string>
-    <string name="force_close" msgid="8346072094521265605">"OK"</string>
-    <string name="report" msgid="4060218260984795706">"Şikayət edin"</string>
-    <string name="wait" msgid="7147118217226317732">"Gözlə"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"Bu səhifə yararsızlaşıb.\n\nBağlamaq istəyirsiz?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"Tətbiq yönləndirildi"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> indi çalışır."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ilk başladıldı."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"Miqyas"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"Həmişə göstər"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"Bunları Sistem ayarlarında yenidən aktivləşdir Yüklənmiş &gt; Tətbiqlər &gt;."</string>
-    <string name="smv_application" msgid="3307209192155442829">"Tətbiq <xliff:g id="APPLICATION">%1$s</xliff:g> (proses <xliff:g id="PROCESS">%2$s</xliff:g>) StrictMode siyasətini pozdu."</string>
-    <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> prosesi StrictMode siyasətini pozdu."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android təkmilləşdirilir..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"<xliff:g id="NUMBER_1">%2$d</xliff:g> əddədən <xliff:g id="NUMBER_0">%1$d</xliff:g> tətbiq optimallaşır."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"Tətbiqlər başladılır."</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"Yükləmə başa çatır."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> çalışır"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"Tətbiqə keçmək üçün toxunun"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"Tətbiqlərə keçilsin?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"Bir tətbiq artıq işləyir. Digərini başlatmaq üçün onu dayandırmalısınız."</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g> bölməsinə qayıdın"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"Yeni tətbiqi başlatmayın."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> tətbiqini başladın"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"Köhnə tətbiqi yadda saxlamadan dayandırın."</string>
-    <string name="sendText" msgid="5209874571959469142">"Mətn üçün əməliyyat seçin"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"Zəngin səs gücü"</string>
-    <string name="volume_music" msgid="5421651157138628171">"Media həcmi"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"Bluetooth vasitəsilə oynadılır"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"Səssiz zəng"</string>
-    <string name="volume_call" msgid="3941680041282788711">"Daxili zəng səsi"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"Bluetooth zəng həcmi"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"Siqnal səsi"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"Bildiriş səsi"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"Həcm"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"Bluetooth həcmi"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"Zəng səsi gücü"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"Zəng həcmi"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"Media həcmi"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"Bildiriş səsi"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"Defolt rinqton"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"Defolt rinqton (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"Heç biri"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"Zəng səsləri"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"Naməlum rinqton"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi şəbəkəsi mövcuddur"</item>
-    <item quantity="other" msgid="4192424489168397386">"Wi-Fi şəbəkələri mövcuddur"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"Wi-Fi şəbəkəni açın"</item>
-    <item quantity="other" msgid="7915895323644292768">"Açıq Wi-Fi şəbəkələri mövcuddur"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Wi-Fi şəbəkəsinə daxil ol"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"Şəbəkəyə daxil olun"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Wi-Fi\'a qoşulmaq alınmadı"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" internet bağlantısı keyfiyyətsizdir."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"Wi-Fi Direct"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"Wi-Fi Direct əməliyyatını başlat. Bu Wi-Fi müştəri/hotspotu bağlayacaq."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"Wi-Fi Direct başladıla bilmədi."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi Direct aktivdir"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"Ayarlar üçün toxunun"</string>
-    <string name="accept" msgid="1645267259272829559">"Qəbul edin"</string>
-    <string name="decline" msgid="2112225451706137894">"İmtina edin"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"Dəvətnamə göndərildi"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"Qoşulmaq üçün dəvət"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"Kimdən:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"Kimə:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"Tələb olunan PİN kodu daxil edin:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PİN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"Bu planşet <xliff:g id="DEVICE_NAME">%1$s</xliff:g> cihazına qoşulan zaman Wi-Fi şəbəkəsindən müvəqqəti ayrılmış olacaq"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"Bu telefon <xliff:g id="DEVICE_NAME">%1$s</xliff:g> cihazına qoşulan zaman Wi-Fi şəbəkəsindən müvəqqəti ayrılmış olacaq"</string>
-    <string name="select_character" msgid="3365550120617701745">"Simvol daxil edin"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS mesaj göndərilir"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; çox sayda SMS mesaj göndərir. Bu tətbiqin mesaj göndərməyə davam etməsinə icazə verirsiniz?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"İcazə verin"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"Rədd edin"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt; ünvanına mesaj göndərmək istəyir."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"Bu, mobil hesabınıza "<font fgcolor="#ffffb060">"əlavə tariflərin tətbiq olunması"</font>" ilə nəticələnə bilər."</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"Bu mobil hesabınızda ödənişlərə səbəb olacaq."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"Göndər"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"Ləğv et"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"Mənim seçimimi yadda saxla"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"Bunu sonra Ayarlarda dəyişə bilərsiniz &gt; Tətbiqlər"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"Həmişə icazə ver"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"Heç vaxt icazə verməyin"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM kart çıxarıldı"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"Cihazınızı etibarlı SIM kart ilə başladana kimi mobil şəbəkə əlçatmaz olacaq."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"Bitdi"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SİM kart əlavə edildi"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"Mobil şəbəkəyə qoşulmaq üçün cihazınızı yenidən başladın."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"Yenidən başlat"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"Vaxt ayarlayın"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"Tarixi quraşdır"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"Ayarlayın"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"Hazırdır"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"YENİ: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g> tərəfindən təmin edilib."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"Heç bir icazə tələb olunmur"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"bununla sizdən xərc tutula bilər"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB toplu yaddaş"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB qoşuludur"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"Siz USB vasitəsilə kompütere bağlandınız. Kompüter və Androidinizin USB yaddaşı arasında faylları kopyalamaq istəyirsinizsə, aşağıdakı düyməyə toxunun."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"Kompüterinizə USB ilə qoşulmusunuz. Faylları Androidinizin SD kartı ilə kompüteriniz arasında kopyalamaq istəyirsinizsə aşağıdakı düyməyə toxunun."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB yaddaşı aktivləşdirin"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB yaddaşınızı USB kütləvi yaddaşı üçün istifadə edən zaman problem yarandı."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"SD kartınızı USB kütləvi yaddaşı üçün istifadə edən zaman problem yarandı."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB qoşuludur"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"Faylları kompüterinizə kopyalamaq və ya kompüterinizdən kopyalamaq üçün toxunun."</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB yaddaşı söndürün"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB yaddaşı söndürmək üçün toxunun."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB yaddaş istifadə olunur"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB yaddaşı söndürmədən öncə Android\'in USB yaddaşını kompüterdən demontaj etdiyinizə (çıxardığınıza) əmin olun."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB yaddaşı söndürmədən öncə Android\'in USB yaddaşını kompüterdən demontaj etdiyinizə (çıxardığınıza) əmin olun."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB yaddaşını söndür"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB yaddaşı söndürən zaman problem oldu. USB hostu demontaj etmənizi yoxlayın və yenidən cəhd edin."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB yaddaşı aktivləşdirin"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"USB yaddaşı aktivləşdirsəniz, istifadə etdiyiniz bəzi tətbiqlər dayana bilər və USB yaddaş deaktiv edilənə qədər işləməyə bilər."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB əməliyyatı uğursuzdur"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"OK"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"Media cihazı kimi qoşuldu"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"Kamera kimi bağlanıldı"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"Quraşdırıcı kimi qoşulub"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB aksesuara qoşuldu"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"Digər USB seçimləri üçün toxunun."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB yaddaşına format atılsın?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD kart format edilsin?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"USB yaddaşınızda yerləşdirilmiş bütün fayllar silinəcək. Bu addım geri dönülməzdir."</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"Kartınızdakı bütün məlumatlar itəcək."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"Format"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB sazlama qoşuludur"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB debaqı deaktivasiya etmək üçün toxunun."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"Daxiletmə metodunu seçin"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"Daxiletmə üsullarını ayarlayın"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"Fiziki klaviatura"</string>
-    <string name="hardware" msgid="7517821086888990278">"Hardware"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"Klaviatura sxemi seçin"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"Klaviatura tərtibatı seçmək üçün toxunun."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCÇDEƏFGĞHXIİJKQLMNOÖPRSŞTUÜVYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCÇDEƏFGĞHİIJKLMNOÖPQRSŞTUÜVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"namizədlər"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB yaddaş hazırlanır"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD kart hazırlanır"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"Səhvlər yoxlanılır."</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"Boş USB yaddaşı"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"Boş SD kart"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB yaddaş boşdur və ya sistem tərəfindən dəstəklənməyən fayl sisteminə malikdir."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD kart boşdur və ya sistem tərəfindən dəstəklənməyən fayl sisteminə malikdir."</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"Zədəli USB yaddaş"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"Zədəli SD kart"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"SD yaddaş zədələnib. Onu format etməyə çalışın."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD kart zədələnib. Onu format etməyə çalışın."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB yaddaşı gözlənilmədən çıxarıldı"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD kart gözlənilmədən çıxarıldı"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"Məlumat itkisinin qarşısını almaq üçün USB yaddaşı çıxarmazdan əvvəl onu demontaj edin."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"Data itkisinin qarşısını almaq üçün SD kartı çıxarmadan öncə demontaj edin."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB yaddaş çıxarmaq üçün təhlükəsizdir"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD kart təhlükəsiz çıxarıla bilər"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"Siz USB yaddaşı təhlükəsiz çıxara bilərsiniz."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"Siz SD kartı təhlükəsiz çıxara bilərsiniz."</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"Silinmiş USB yaddaş"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"SD kart çıxarıldı"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB yaddaş çıxarıldı. Yeni media əlavə edin."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD kart çıxarıldı. Yenisini daxil edin."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"Uyğun gələn fəaliyyət tapılmadı."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"komponent istifadəsi statistikasını güncəlləyir"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"Tətbiqə toplanmış istifadə statistikasını dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"məzmunu kopyala"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"Tətbiqə kontenti kopyalamaq üçün defolt konteyner servisini çağırmaq icazəsi verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"Media çıxışını yönləndirir"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"Tətbiqə media çıxışını digər xarici cihazlara yönləndirmək imkanı verir."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"Keyguard təhlükəsiz yaddaşa çıxış"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"Tətbiqə keguard təhlükəsiz yaddaşa çatmağa icazə verir."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"Klaviatura kilidinin görülməsini və gizlədilməsini idarə edir"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"Tətbiqə keguardı idarə etmək icazəsi verir."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"Zoom nəzarəti üçün iki dəfə toxunun"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"Widget əlavə edilə bilmədi."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"Get"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"Axtar"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"Göndər"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"Növbəti"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"Tamam"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"Əvvəlki"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"İcra edin"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"<xliff:g id="NUMBER">%s</xliff:g> istifadə etməklə\nnömrə yığın"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"<xliff:g id="NUMBER">%s</xliff:g>istifadə edərək kontakt yaradın\n"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"Aşağıdakı bir və ya daha çox tətbiqlər indi və gələcəkdə hesabınıza daxil olmaq üçün icazə istəyir."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"Bu istəyə izn vermək istəyirsiniz?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"Giriş sorğusu"</string>
-    <string name="allow" msgid="7225948811296386551">"İcazə verin"</string>
-    <string name="deny" msgid="2081879885755434506">"Rədd et"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"İcazə tələb olunur"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">\n" hesabı üçün<xliff:g id="ACCOUNT">%s</xliff:g> icazə sorğusu göndərildi."</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"Daxiletmə metodu"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"Sinxronizasiya"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"Əlçatımlılıq"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"Divar kağızı"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"Divar kağızını dəyişin"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"Bildiriş dinləyən"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN aktivləşdirildi"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN <xliff:g id="APP">%s</xliff:g> tərəfindən aktivləşdirilib"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"Şəbəkəni idarə etmək üçün toxunun."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g> sessiyaya qoşuludur. Şəbəkəni idarə etmək üçün toxunun."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"Həmişə aktiv VPN bağlanır..."</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"VPN bağlantısı həmişə aktiv"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"Həmişə aktiv VPN xətası"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"Konfiqurə etmək üçün toxun"</string>
-    <string name="upload_file" msgid="2897957172366730416">"Fayl seçin"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"Heç bir fayl seçilməyib"</string>
-    <string name="reset" msgid="2448168080964209908">"Sıfırlayın"</string>
-    <string name="submit" msgid="1602335572089911941">"Göndər"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"Avtomobil rejimi aktivdir"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"Avtomobil rejimindən çıxmaq üçün toxunun."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"Tezerinq və ya hotspot aktivdir"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"Quraşdırmaq üçün toxunun."</string>
-    <string name="back_button_label" msgid="2300470004503343439">"Geri"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"Növbəti"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"Keç"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"Yüksək mobil data istifadəsi"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"Mobil data istifadəsi haqqında daha çox öyrənmək üçün toxunun."</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"Mobil data limiti keçildi"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"Mobil data istifadəsi haqqında daha çox öyrənmək üçün toxunun."</string>
-    <string name="no_matches" msgid="8129421908915840737">"Uyğunluq yoxdur"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"Səhifədə tap"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"1 uyğunluq"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="INDEX">%d</xliff:g> ədəddən <xliff:g id="TOTAL">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"Hazırdır"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB yaddaşı qaldırılır..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD kart demontaj edilir..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB yaddaş silinir..."</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD kart silinir..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB yaddaşı silinə bilmədi."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD kartı silmək mümkün olmadı."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD kart demontaj edilmədən öncə çıxarıldı."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB yaddaş hazırda yoxlanılır."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD kart hazırda yoxlanılır."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD kart çıxarılıb."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"SD kart hazırda kompüter tərəfindən istifadə edilir."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD kart hal-hazırda kompüter tərəfindən istifadə edilir."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"Naməlum vəziyyətdə xarici media."</string>
-    <string name="share" msgid="1778686618230011964">"Paylaşın"</string>
-    <string name="find" msgid="4808270900322985960">"Tapın"</string>
-    <string name="websearch" msgid="4337157977400211589">"Veb Axtarış"</string>
-    <string name="find_next" msgid="5742124618942193978">"Sonrakını tap"</string>
-    <string name="find_previous" msgid="2196723669388360506">"Əvvəlkini tap"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> tərəfindən məkan sorğusu"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"Məkan sorğusu"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) tərəfindən tələb edilib"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"Bəli"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"Xeyr"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"Limiti keçəni silin"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g> üçün <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> silinmiş fayl var, <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g> hesabı. Nə etmək istəyirsiniz?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"Elementləri sil"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"Silinənləri geri qaytar"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"İndilik heç nə etmə"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"Hesab seçin"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"Hesab əlavə et"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"Hesab əlavə edin"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"Artır"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"Azaldın"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> toxunun və basaraq saxlayın."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"Artırmaq üçün yuxarı, azaltmaq üçün aşağı sürüşdürün."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"Dəqiqə artırın"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"Dəqiqəni azalt"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"Saatı artırın"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"Saatı azaldın"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"PM qurun"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"AM qurun"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"Artma ayı"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"Ayı azaldın"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"Artma günü"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"Azalma günü"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"Artım ili"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"Azalma ili"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Ləğv et"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Sil"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Hazırdır"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Rejim dəyişikliyi"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Daxil olun"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"Tətbiq seçin"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"Bununla paylaşın"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g> ilə paylaşın"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"Sürüşən qulp. Toxunaraq basılı tutun."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün yuxarı sürüşdürün."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün aşağı sürüşdürün."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün sola sürüşdür."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün sağa sürüşdür."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Kilidi aç"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Kamera"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Səssiz"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Səs açıqdır"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Axtar"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"Kilidi açmaq üçün vurun."</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"Parolların səsləndirilməsi üçün qulaqlıqları taxın."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"Nöqtə."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"Evə gedin"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"Yuxarı gedin"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"Əlavə seçimlər"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"Daxili yaddaş"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD kart"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB yaddaş"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"Redaktə et"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"Data istifadə xəbərdarlığı"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"İstifadə və ayarları görmək üçün toxunun"</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G data deaktivdir"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G data deaktiv edildi"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"Mobil data deaktivdir"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi-Fi data deaktiv edildi"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"Aktivləşdirmək üçün toxunun."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G data limiti aşılıb"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G data limiti keçildi"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"Mobil data limiti keçildi"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi-Fi data limiti keçildi"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> müəyyən edilmiş limit aşır."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"Arxaplan datası məhdudlaşdırıldı"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"Məhdudiyyəti aradan qaldırmaq üçün toxunun"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"Təhlükəsizlik sertifikatı"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"Bu sertifikat etibarlıdır."</string>
-    <string name="issued_to" msgid="454239480274921032">"Verilib:"</string>
-    <string name="common_name" msgid="2233209299434172646">"Ümumi ad:"</string>
-    <string name="org_name" msgid="6973561190762085236">"Təşkilat:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"Təşkilati vahid:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"Tərəfindən verilib:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"Keçərlilik:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"Dərc olunub:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"Bitmə vaxtı:"</string>
-    <string name="serial_number" msgid="758814067660862493">"Seriya nömrəsi:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"Barmaq izləri:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 barmaq izi:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 barmaq izi:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"Hamısını seçın"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"Fəaliyyəti seçin"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"Bununla paylaşın"</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"Göndərilir..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"Brauzer işə salınsın?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"Zəngi qəbul edək?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"Həmişə"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"Sadəcə bir dəfə"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"Planşet"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"Telefon"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"Qulaqlıq"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"Dok spikerlər"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"Sistem"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"Bluetooth audio"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"Simsiz ekran"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"Hazırdır"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"Media çıxışı"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"Skan edilir..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"Qoşulur..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"Əlçatımlı"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"Əlçatımlı deyil"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"İstifadə olunur"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"Daxili ekran"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI Ekran"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"Örtük #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", təhlükəsiz"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"Simsiz ekran qoşulub"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"Bu ekran digər cihazda göstərir"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"Bağlantını kəsin"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Təcili zəng"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Şablonu unutmuşam"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Yanlış Model"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Yanlış Şifrə"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN səhvdir"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%1$d</xliff:g> saniyə sonra yenidən cəhd edin."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Şablonunuzu çəkin"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN kodu daxil edin"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PİN kodu daxil edin"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Parol daxil edin"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM indi deaktivdir. Davam etmək üçün PUK kodu daxil edin. Əlavə məlumat üçün operatora müraciət edin."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"İstədiyiniz PİN kodu daxil edin"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"İstədiyiniz PIN kodu təsdiqləyin"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SİM kartın kilidi açılır..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Yanlış PİN kod."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"4-dən 8-ə qədər rəqəmi olan PIN yazın."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK kod 8 rəqəm və ya daha çox olmalıdır."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Düzgün PUK kodu yenidən daxil edin. Təkrarlanan cəhdlər SIM\'i birdəfəlik sıradan çıxaracaq."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN kodları uyğun deyil"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Həddindən çox cəhd edildi!"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Kilidi açmaq üçün Google hesabınız ilə daxil olun."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"İstifadəçi adı (e-poçt)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Şifrə"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Daxil ol"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Yanlış istifadəçi adı və ya parol."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"İstifadəçi adınızı və ya parolunuzu unutmusunuz?\n "<b>"google.com/accounts/recovery"</b>" linkinə daxil olun."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Hesab yoxlanılır..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"PIN kodunuzu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz.\n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Şifrənizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Modelinizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış çəkmisiniz.\n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Siz planşet kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, planşet fabrik ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Siz telefon kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, telefon fabrik ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Siz planşet kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. Planşet fabrik ayarlarına sıfırlanacaq."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Siz telefonun kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> yanlış cəhd etmisiniz. Telefon artıq defolt zavod halına sıfırlanacaq."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Siz kilidi açmaq üçün şablonu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə səhv çəkdiniz. <xliff:g id="NUMBER_1">%d</xliff:g> daha uğursuz cəhddən sonra planşetinizin kilidini e-poçt hesabınızla açmaq tələb olunacaq.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində bir daha yoxlayın."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Siz artıq modeli <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etmisiniz.<xliff:g id="NUMBER_1">%d</xliff:g> dəfə də yanlış daxil etsəniz, telefonun kilidinin açılması üçün elektron poçt ünvanınız tələb olunacaq.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində yenidən cəhd edin."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" - "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Yığışdır"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"Səs gücü tövsiyə edilən səviyyədən artırılsın?\nUzun müddət yüksək səs gücü ilə dinləmə Sizin eşitmə qabiliyyətinizə mənfi təsir edə bilər."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"Əlçatımlığı aktivləşdirmək üçün iki barmağınızı basılı saxlayın."</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"Əlçatımlılıq aktivləşdirildi"</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"Giriş imkanı ləğv edilib."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Cari istifadəçi <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="owner_name" msgid="2716755460376028154">"Sahib"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"Xəta"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"Bu tətbiq məhdud profillər üçün hesabları dəstəkləmir."</string>
-    <string name="app_not_found" msgid="3429141853498927379">"Bu əməliyyatı idarə etmək üçün heç bir tətbiq tapılmadı."</string>
-    <string name="revoke" msgid="5404479185228271586">"Ləğv edin"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"B4 ISO"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"Məktub"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"Hökumət Məktubu"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"Hüquqi"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Kiçik Hüquq"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Qovluq"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Qısa"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"Ləğv edildi"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"Kontent yazmna xətası"</string>
-    <string name="reason_unknown" msgid="6048913880184628119">"naməlum"</string>
-    <string name="restr_pin_enter_admin_pin" msgid="783643731895143970">"Administrator PIN kodunu daxil edin"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN daxil edin"</string>
-    <string name="restr_pin_incorrect" msgid="8571512003955077924">"Səhv"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"Cari PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"Yeni PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"Yeni PIN\'i təsdiq edin"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"Dəyişmə məhdudiyyətləri üçün PİN yaradın"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PİN uyğun gəlmir. Yenidən cəhd edin."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PİN çox qısadır. Ən azı 4 rəqəm olmalıdır."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="311050995198548675">"1 saniyə sonra təkrar yoxlayın"</item>
-    <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> saniyə sonra təkrar yoxlayın"</item>
-  </plurals>
-    <string name="restr_pin_try_later" msgid="973144472490532377">"Daha sonra yenidən yoxlayın."</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Paneli göstərmək üçün ekranın küncünü sürüşdürün"</string>
-</resources>
diff --git a/core/res/res/values-az/strings.xml b/core/res/res/values-az/strings.xml
deleted file mode 100644
index 82bf400..0000000
--- a/core/res/res/values-az/strings.xml
+++ /dev/null
@@ -1,1583 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"Başlıqsız"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"..."</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(Telefon nömrəsi yoxdur)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(Naməlum)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"Səsli poçt"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"Bağlantı problemi və ya yalnış MM kodu."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"Əməliyyat yalnız sabit nömrələrə yığımla məhdudlaşıb."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"Servis işə salındı."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"Xidmət aktiv edilmişdir:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"Xidmət deaktiv edilib."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"Qeydiyyat uğurlu oldu."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"Silinmə uğurlu olmuşdur."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"Yanlış parol"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI tamamdır."</string>
-    <string name="badPin" msgid="9015277645546710014">"Daxil etdiyiniz köhnə PİN düzgün deyil."</string>
-    <string name="badPuk" msgid="5487257647081132201">"Daxil etdiyiniz PUK düzgün deyil."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"Daxil etdiyiniz PİN kodlar uyğun gəlmir."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"4-dən 8-ə qədər rəqəmi olan PIN yazın."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"8 və daha çox rəqəmi olan PUK yazın."</string>
-    <string name="needPuk" msgid="919668385956251611">"Sizin SİM kart PUK ilə kilidlənib. Onu açmaq üçün PUK kodu yazın."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM kartın kilidini açmaq üçün PUK2 yazın"</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"Daxil olan zəng edənin ID\'si"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"Gedən Zəng ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"Zəng yönləndirmə"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"Zəng gözləyir"</string>
-    <string name="BaMmi" msgid="455193067926770581">"Zəng qadağası"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"Parolu dəyiş"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PİN dəyişmək"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"Hazırdakı nömrəyə zəng edilir"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"Zənglərin sayı məhdudlaşdırılıb"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"Üç yollu zəng"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"Xoşagəlməz zənglərdən imtina"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"Çatdırılma zəngi"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"Narahat etməyin"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"Adətən zəng edənin ID\'si məhdudlaşdırılır. Növbəti zəng: Məhdudlaşdırılıb"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"Adətən zəng edənin ID\'si məhdudlaşdırılır. Növbəti zəng: Məhdudlaşdırılmayıb"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"Adətən zəng edənin ID\'si məhdudlaşdırılmır. Növbəti zəng: Məhdudlaşdırılıb"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"Adətən zəng edənin ID\'si məhdudlaşdırılmır. Növbəti zəng: Məhdudlaşdırılmayıb"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"Xidmət təmin edilməyib."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"Siz zəng edənin ID nizamlarını dəyişə bilməzsiz."</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"Məhdudlaşdırılmış keçid dəyişdi"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"Data xidmət bağlıdır."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"Təcili xidmət bağlıdır."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"Səs xidməti bağlıdır."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"Bütün Səs xidmətləri bağlıdır"</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS xidməti bloklanıb."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"Səs/data xidmətləri bloklanıb."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"Səs/SMS xidmətləri bloklanıb."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"Bütün səs/data/SMS xidmətləri bağlıdır."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"Səs"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"Məlumat"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"FAKS"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"Async"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"Sinx"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"Paket"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"Rominq göstəricisi işləkdir"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"Rominq göstəricisi işlək deyil"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"Rominq göstəricisi yanır"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"Qonşuluqdan Kənar"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"Binadan kənar"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"Rominq - Arzuolunan sistem"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"Rominq - Mümkün sistem"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"Rominq - Alyans partnyoru"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"Rominq - Premium partnyor"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"Rouminq - Tam Xidmət Funksionallığı"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"Rouminq - Qismən Xidmət Funksionallığı"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"Rouminq Banneri Açıqdır"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"Roaming Banner Off"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"Xidmət axtarılır"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: Yönləndirilmədi"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> <xliff:g id="TIME_DELAY">{2}</xliff:g> saniyə sonra"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: Yönləndirilmədi"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: Yönləndirilmədi"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"Özəllik kodu tamamlandı."</string>
-    <string name="fcError" msgid="3327560126588500777">"Əlaqə problemi və ya yanlış funksiya kodu."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"OK"</string>
-    <string name="httpError" msgid="7956392511146698522">"Şəbəkə xətası var idi."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL tapıla bilmədi."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"Sayt autentifikasiya sxemi dəstəklənmir."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"Təsdiq edilə bilmədi."</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"Proksi server vasitəsilə təsdiqlənmə uğursuz oldu."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"Serverə qoşula bilmədi."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"Serverlə əlaqə alınmadı. Sonra cəhd edin."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"Server ilə olan əlaqə zaman aşımına məruz qaldı."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"Bu səhifədə həddindən çox server yönləndirilmələri var."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"Protokol dəstəklənmir."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"Güvənli bağlantı yaradıla bilmədi."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"URL yanlış olduğu üçün səhifəni açmaq mümkün olmadı."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"Fayla giriş baş tutmadı."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"Tələb olunan fayl tapılmadı."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Həddindən çox sorğu işlənilir. Daha sonra yoxlayın."</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g> üçün giriş xətası"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"Sinxronlaşdırma"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"Sinxronlaşdırma"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"Həddindən çox <xliff:g id="CONTENT_TYPE">%s</xliff:g> silinmələri var."</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"Planşetin yaddaşı doludur. Boş yer üçün bəzi faylları silin."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"Telefonun yaddaşı doludur. Boş yer üçün bəzi faylları silin."</string>
-    <string name="me" msgid="6545696007631404292">"Mən"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"Planşet seçimləri"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"Telefon seçimləri"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"Səssiz rejim"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"Simsizi işə salın"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"Simsiz rabitəni söndürün"</string>
-    <string name="screen_lock" msgid="799094655496098153">"Ekran kilidi"</string>
-    <string name="power_off" msgid="4266614107412865048">"Söndür"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"Zəng deaktivdir"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"Zəng vibrasiyadadır"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"Zəngvuran açıqdır"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"Söndürülür..."</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"Planşetiniz sönəcək."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"Telefonunuz sönəcək."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"Söndürmək istəyirsiz?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"Təhlükəsiz rejimdə yenidən başlayın"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"Təhlükəsiz rejimdə yenidən başlamaq istəyirsiniz mi? Bu, quraşdırdığınız bütün üçüncü tərəf tətbiqlərini deaktiv edəcək."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"Son"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"Heç bir son tətbiq yoxdur."</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"Planşet seçimləri"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"Telefon seçimləri"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"Ekran kilidi"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"Söndür"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"Baq hesabatı"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"Baqı xəbər verin"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"Bu, sizin hazırkı cihaz durumu haqqında məlumat toplayacaq ki, elektron məktub şəklində göndərsin. Baq raportuna başlamaq üçün bir az vaxt lazım ola bilər, bir az səbr edin."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"Səssiz rejim"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"Səs qapalıdır"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"Səs Aktivdir"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"Təyyarə rejimi"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"Uçuş rejimi açıqdır"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"Təyyarə rejimi qapalıdır"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"Təhlükəsiz rejim"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Android sistemi"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"Ödənişli xidmətlər"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"Xərc tutulacaq əməliyyatlar edir"</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"Sizin mesajlarınız"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"SMS, elektron poçt və digər mesajları oxuyur və yazır."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"Şəxsi məlumatınız"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"Kontakt kartınızda saxlanılan məlumatlarınıza birbaşa giriş."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"Sosial məlumatınız"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"Kontaktlarınız və sosial əlaqələriniz haqqında məlumata birbaşa giriş."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"Yerləşməniz"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"Fiziki adresinizi monitorinq edir."</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"Şəbəkə kommunikasiyası"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"Müxtəlif şəbəkə xüsusiyyətlərinə daxil ol."</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"Bluetooth"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"Bluetooth üzərindən cihazlara və şəbəkələrə daxil ol."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"Audio Ayarlar"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"Audio ayarları dəyişin."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"Batareyaya təsir edir"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"Batareyanızın tez qurtarmasına səbəb olan funksiyalar istifadə edir"</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"Təqvim"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"Təqvimə və tədbirlərə birbaşa giriş."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"İstifadəçi Lüğətini Oxu"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"İstifadəçi lüğətindəki sözləri oxuyur."</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"İstifadəçi Lüğətini Yaz"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"İstifadəçi lüğətinə sözlər əlavə edin."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"Əlfəcinlər və Tarixçə"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"Əlfəcinlərə və brauzer tarixinə birbaşa icazə."</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"Zəng"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"Alarm qur."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"Səsli poçt"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"Səs poçtuna birbaşa çıxış."</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"Mikrofon"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"Audio yazmaq üçün mikrofona birbaşa giriş."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"Kamera"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"Şəkil və ya video çəkmək üçün kameraya birbaşa çıxış."</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"Ekran kilidi"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"Cihazınızdakı kilid ekranının hərəkətinə təsir etmə bacarığı"</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"Tətbiq məlumatlarınız"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"Cihazınızdakı digər tətbiqlərin davranışına təsir etmək bacarığı."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"Divar kağızı"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"Cihazın divar kağızı ayarlarını dəyişin."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"Saat"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"Cihazın vaxt və zaman zolağını dəyişir."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"Status paneli"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"Cihazın status paneli ayarlarınızı dəyişir."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"Sinx Ayarları"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"Sinxronizasiya nizamlarına çıxış."</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"Hesablarınız"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"Əlçatımlı hesablara daxil olun."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"Hardware kontrolları"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"Dəstəkdəki avadanlığa birbaşa giriş."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"Telefon zəngləri"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"Telefon zənglərinə nəzarət edin, qeydə alın və idarə edin."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"Sistem alətləri"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"Aşağı səviyyəli çıxış və sistem idarəetməsi."</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"İnkişaf alətləri"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"Özəlliklər yalnız tətbiq developerləri üçün lazımdır."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"Digər tətbiq İstifadəçi İnterfeysi"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"Digər tətbiqlərin İstifadəçi İnterfeysinə təsir edir."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"Yaddaş"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB yaddaşa daxil ol."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD karta daxil ol."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"Əlçatımlılıq funksiyaları"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"Yardımçı texnologiya tələb edə biləcəyi funksiyalar."</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"Pəncərənin məzmununu əldə edin"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"Əlaqədə olduğunuz pəncərənin məzmununu nəzərdən keçirin."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"Toxunaraq Kəşf et funksiyasını yandırın"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"Toxunulan hissələr səsləndiriləcək və ekran jestlərlə idarə oluna biləcək."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"İnkişaf etmiş veb əlçatımlılığı yandırın"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"Skriptlər tətbiq məzmununun daha əlçatımlı olması üçün quraşdırıla bilər."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"Yazdığınız mətni izləyin"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"Kredit kartı nömrələri və parollar kimi şəxsi məlumatlar daxildir."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"status panelini deaktivləşdir və ya dəyişdir"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"Tətbiqə status panelini deaktiv etməyə və ya sistem ikonalarını əlavə etmək və ya silmək imkanı verir."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"status paneli"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"Tətbiqə status paneli olmağa imkan verir."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"status panelini genişlətmək və ya yığmaq"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"Tətbiqə status panelini genişləndirməyə və ya yox etməyə imkan verir."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"gedən zənglərin marşrutunu dəyişmək"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"Tətbiqə zəng etməyə və zəng edilən nömrəni dəyişməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək gedən zəngləri izləyə, yönləndirə və ya qarşısını ala bilər."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"SMS qəbul etmək"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"Tətbiqə MMS mesajlarını almaq və emal etmək icazəsi verir. Bu o deməkdir ki, tətbiq sizin mesajlarınızı sizə göstərmədən monitorinq edə və ya silə bilər."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"mətn mesajlarını qəbul edir (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"Tətbiqə MMS mesajlarını qəbul və emal üçün imkan verir. Bu o deməkdir ki, bu tətbiq sizə göstərmədən cihazınıza göndərilən mesajları silə bilər."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"təcili yayımları qəbul edir"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"Tətbiqə təcili yayım mesajlarını qəbul və emal etmək icazəsi verir. Bu icazə ancaq sistem tətbiqləri üçün mümkündür."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"mobil yayım mesajlarını oxuyur"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"Tətbiqə sizin telefonunuz tərəfindən alınmış yayım mesajlarını oxuma icazəsi verir. Telefon yayımı bəzi məkanlarda olan fövqəladə hadisələrlə bağlı sizi xəbərdar etmək üçün qəbul edilir. Zərərli tətbiqlər fövqəladə mobil yayım qəbul edildiyi zaman telefonunun performansına və əməliyyatına müdaxilə edə bilər."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS mesajlarını göndərir"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"Tətbiqə SMS mesajı göndərmə icazəsi verir. Bu gözlənilməyən ödənişlərə səbəb ola bilər. Zərərli tətbiqlər sizin təsdiqiniz olmadan mesaj göndərməklə sizə ödənişə səbəb ola bilərlər."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"mesajla cavab verilməli tədbirlər göndərmək"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"Tətbiqə zənglər üçün \"mesajla cavabla\" hadisələrini idarə etmək üçün digər mesajlaşma tətbiqlərinə sorğuların göndərilməsi icazəsi verir."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"tekst mesajlarınızı oxuyur (SMS və ya MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"Tətbiqə planşetinizdə və ya SIM kartınızda saxlanan SMS mesajları oxumağa imkan verir. Bu bütün SMS mesajların, onların məzmunundan və konfidensiallığından asılı olmadan oxunması imkanı deməkdir."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"Tətbiqə telefonunuzda və ya SIM kartınızda saxlanan SMS mesajları oxumağa imkan verir. Bu bütün SMS mesajların, onların məzmunundan və konfidensiallığından asılı olmadan oxunması imkanı deməkdir."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"mətn mesajlarınızı redaktə edir (SMS və ya MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"Tətbiqə telefonunuzda və ya SİM kartınızda yerləşən SMS mesajlara yazma icazəsi verir. Zərərli tətbiqlər sizin mesajlarınızı silə bilər."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"Tətbiqə telefonunuzda və ya SİM kartınızda yerləşən SMS mesajlara yazma icazəsi verir. Zərərli tətbiqlər sizin mesajlarınızı silə bilər."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"mətn mesajları qəbul etmək (WAP)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"Tətbiqə WAP mesajlar göndərmək və ya qəbul etmək imkanı verir. Buna mesajları izləmək və Sizə xəbər vermədən silmək imkanları da daxildir."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"işlənən tətbiqlər əldə etmək"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"Tətbiqə hazırda və az öncə işləyən tapşırıqlar haqqında ətraflı məlumat əldə etməyə imkan verir. Bu da cihazda hansı tətbiqlərin istifadə olunması haqqında məlumatların əldə edilməsinə imkan verir."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"istifadəçilər arasında əlaqə qurur"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"Tətbiqə bu cihazdakı digər istifadəçilərlə müxtəlif işləri görməyə icazə verir. Zərərli tətbiqlər bundan istifadəçilər arasındakı qorunmanı pozmaq üçün istifadə edə bilər."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"bütün istifadəçilər ilə əlaqə saxlamaq üçün tam hüquq"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"İstifadəçilər arasında bütün mümkün əlaqələrə imkan verir."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"istifadəçiləri idarə edir"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"Tətbiqlərə cihazda olan istifadəçiləri, habelə sorğu göndərmə, yaratma və silmə izni verir."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"işlənən tətbiqlərin detallarını əldə etmək"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"Tətbiqə hazırda və az öncə işləyən tapşırıqlar haqqında ətraflı məlumat əldə etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək şəxsi məlumatları oğurlaya bilər."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"işlənən tətbiqlərin sırasını dəyişmək"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"Tətbiqə tapşırıqları ön plandan arxa plana keçirməyə imkan verir. Tətbiq bunu Sizin daxiletməniz olmadan da edə bilər."</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"işlək tətbiqləri dayandırır"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"Tətbiqə tapşırıqları silməyə və onların tətbiqlərini məhv etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək digər tətbiqlərin işlərini dayandıra bilər."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"fəaliyyət toplularını idarə edin"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"Tətbiqə digər tətbiqlərin fəaliyyəti daxilində fəaliyyət toplularını əlavə etmək, silmək və dəyişmək imkanı verir."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"hər hansı bir fəaliyyət başlat"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"İcazə qorunması və ya eksport edilmiş statusdan asılı olmayaraq, tətbiqə hər hansı fəaliyyəti başlatmağa imkan verir."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"ekran uyğunluğunu yerləşdirir"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"Tətbiqə digər tətbiqlərin ekran uyğunluğunu yoxlamaq imkanı verir. Zərərli tətbiqlər digər tətbiqlərin fəaliyyətini poza bilər."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"tətbiq sazlanmasını aktiv edir"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"Tətbiqə digər bir tətbiq üçün sazlamanı açmaq üçün imkan verir. Zərərli tətbiqlər bunu digər tətbiqləri yox etmək üçün istifadə edə bilər."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"sistem ekran nizamlarını dəyiş"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"Tətbiqə yerli parametrlər və ya şriftin ölçüsü kimi cari konfiqurasiyanı dəyişməyə imkan verir."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"avtomobil rejimini aktivləşdirir"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"Tətbiqə avtomobil rejimini aktivləşdirməyə imkan verir."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"digər tətbiqləri qapatmaq"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"Tətbiqə başqa tətbiqlərin arxafon proseslərini dayandırmaq icazəsi verir. Bu digər tətbiqlərin dayanmasına səbəb ola bilər."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"Digər tətbiqləri dayanmağa məcbur et"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"Tətbiqə digər tətbiqləri məcburi şəkildə dayandırmağa imkan verir."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"tətbiqi qapanmağa məcbur etmək"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"Tətbiqə ön planda olan istənilən tətbiqi bağlayaraq geriyə dönməyə imkan verir. Normal tətbiqlər tərəfindən heç vaxt istifadə olunmamalıdır."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"sistemin daxili durumunu bərpa et"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"Tətbiqə sistemin daxili statusunu bərpa etməyə imkan verir. Zərərli tətbiqlər lazım olmadığı halda müxtəlif şəxsi və güvənli məlumatları bərpa edə bilər."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"ekran kontentini bərpa edir"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"Tətbiqə aktiv pəncərənin məzmununu əldə etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək pəncərə məzmununu ələ keçirib parollları oxuya bilər."</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"giriş imkanını müvəqqəti açmaq"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"Tətbiqə cihaza girişi müvəqqəti olaraq aktivləşdirməyə imkan verir. Zərərli tətbiqlər istifadəçi razılığı olmadan girişi aktivləşdirə bilər."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"pəncərə infosunu bərpa edir"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"Tətbiqə pəncərə idarəçisindən gələn windows haqqında olan məlumatı bərpa etməyə imkan verir. Zərərli tətbiqlər daxili sistem istifadəsi üçün nəzərdə tutulan məlumatı bərpa edə bilər."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"tədbirləri filtr edir"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"Tətbiqə daxiletmə filtrini qeydiyyat etdirməyə imkan verir, bu filtr bütün istifadəçi tədbirlərini göndərilməmişdən əvvəl filtrdən keçirir. Zərərli tətbiq istifadəçi müdaxiləsi olmadan İstifadəçi İnterfeysi sisteminə nəzarət edə bilər."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"ekranı böyüdür"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"Tətbiqə ekran kontentini böyütmək icazəsi verir. Zərərli tətbiqlər bundan istifadə edərək ekranda kontenti böyüdərək cihazın qeyri-stabilliyinə səbəb ola bilər."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"qismən söndürür"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"Aktivlik idarəçiliyini qapanmış hala gətirir. Tam qapanmanı həyata keçirmir."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"tətbiqdən tətbiqə keçidin qarşısını almaq"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"İstifadəçinin başqa tətbiqə keçməsinin qarşısını alır."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"cari tətbiq informasiyası əldə etmək"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"Sahibə ekran önündə cari tətbiq və xidmətlər haqqında şəxsi məlumat əldə etməyə imkan verir."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"işə salınan bütün tətbiqləri izləyir və idarə edir"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"Tətbiqə sistemin fəaliyyətləri necə başlatdığını nəzarət və kontrol etməyə imkan verir. Zərərli tətbiqlər sistemi tamamilə kompromis edə bilər. Bu icazə yalnız inkişaf üçündür, heç vaxt normal istifadə üçün deyil."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"qaldırılmış yayım paketini göndər"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"Tətbiqə tətbiq paketinin silinməsi haqqında bildiriş translasiya etmə icazəsi verir. Zərərli tətbiqlər bundan digər işlək tətbiqləri dayandırmaq üçün istifadə edə bilər."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS tərəfindən qəbul edilən yayım göndər"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"Tətbiqə mesaj gəlməsi haqqında bildirişi yayımlamaq imkanı verir. Zərərli tətbiqlər bundan gələn SMS mesajlarını saxtalaşdırmaq üçün istifadə edə bilər."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH tərəfindən qəbul edilən yayım göndər"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"Tətbiqə WAP PUSH mesajın alındığı haqda bildiriş translasiya etməyə icazə verir. Zərərli tətbiqlər bundan istifadə edərək saxta MMS mesaj alışı və ya səssizcə istənilən veb səhifəni zərərverici variantlarla dəyişmək üçün istifadə edə bilər."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"çalışan proseslərin sayını məhdudlaşdırır"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"Tətbiqə işlədiləcək maksimum proses sayını idarə etmə izni verir. Normal tətbiqlər tərəfindən tələb olunmur."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"arxafon tətbiqlərini dayanmağa məcbur edir"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"Tətbiqə aktivitilərin arxa fona getdiyi zaman bitməsini yoxlayır. Normal tətbiqlər tərəfindən tələn olunmur."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"batareya statistikalarını oxumaq"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"Tətbiqə cari aşağı səviyyəli data sitifadəsini oxumaq imkanı verir. Tətbiqə hansı tətbiqi istifadə etdiyiniz haqqında ətraflı məlumat tapmağa imkan verə bilər."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"batareya statistikalarını dəyişmək"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"Tətbiqə yığılmış batareya statistikasını redaktə etmə icazəsi verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"tətbiq əməliyyat statistikalarını əldə etmək"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"Toplanmış tətbiq əməliyyat statistikalarının bərpa edilməsinə imkan verir. Normal tətbiqlər tərəfindən istifadə üçün deyil."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"tətbiq əməliyyat statistikasını dəyişmək"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"Tətbiqə toplanmış tətbiq əməliyyat statistikasını dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"sistem yedəkləməsi və bərpasını idarə edir"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"Tətbiqə sistemi rezerv etməyə və mexanizmi bərpa etməyə imkan verir. Normal tətbiqlər tərəfindən istifadə edilmək üçün nəzərdə tutulmayıb.."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"tam rezervi təsdiq etmək və ya əməliyyatı bərpa etmək"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"Tətbiqə İstifadəçi İnterfeysi tam rezerv təsdiqini işə salmağa imkan verir. Heç bir tətbiq tərəfindən istifadə olunmamalıdır."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"icazəsiz pəncərələri görüntüləyir"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"Tətbiqə daxili sistem interfeysi tərəfindən istifadə edilməsi üçün nəzərdə tutulmuş pəncərələri yaratmağa icazə verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"digər tətbiqlər üzərində çəkmək"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"Tətbiqə digər tətbiqlərin və ya onların hissələrinin yuxarısında şəkil çəkməyə imkan verir. Onlar istənilən tətbiqin interfeysinin istifadəsinə müdaxilə edə və ya digər tətbiqlərdə axtardıqlarınızı dəyişə bilər."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"qlobal animasiya sürətini dəyişir"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"Tətbiqə istənilən vaxt qlobal animasiya sürətini (sürətli və ya yavaş animasiyalar) dəyişdirmək imkanı verir."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"tətbiq nişanlarını idarə etmək"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"Tətbiqlərə onların normal Z-orderinqi keçərək markerlərini yaratma və idarəetmə icazəsi verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"ekranı dondurur"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"Tətbiqə tam ekranlı yayım üçün ekranı müvəqqəti olaraq dondurma icazəsi verir."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"düymələri və idarəetmə düymələrini basır"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"Tətbiqə özünün daxiletmə tədbirlərini digər tətbiqlərə çatdırmağa imkan verir. Zərərli tətbiqlər planşeti ələ keçirmək üçün bundan istifadə edə bilər."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"Tətbiqə özünün daxiletmə tədbirlərini digər tətbiqlərə çatdırmağa imkan verir. Zərərli tətbiqlər telefonu ələ keçirmək üçün bundan istifadə edə bilər."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"yazdıqlarınızı və etdiklərinizi izləyir"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"Tətbiqə basdığınız düymələri izləmək imkanı verilir. Buna parolların və kredit kartı nömrələrinin yazılması da aiddir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"daxiletmə metoduna bağlanır"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"Sahibinə daxiletmə metodunun ən üst səviyyə interfeysinə bağlamaq imkanı verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"giriş xidmətinə bağlı qal"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"Sahibə giriş xidmətin ən üst səviyyə interfeysi bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"çap servisini qoşma"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"Sahibinə bir çap xidmətinin ən üst səviyə araüzünü bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"bütün çap işlərinə giriş əldə et"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"Sahibinə digər tətbiqlər tərəfindən yaradılan çap işlərinə giriş hüququ verir. Normal tətbiqlər üçün tələb olunmamalıdır."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC xidmətlərinə qoşun"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Sahibinə NFC kartlarını emulyasiya edən tətbiqləri bir-birinə qoşmağa icazə verin. Normal tətbiqlər üçün lazım deyil."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"mətn servisini qoşma"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"Sahibinə bir mətn xidmətinin ən üst səviyyə araüzünü bağlamağa imkan verir(məsələn, SpellCheckerService). Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN xidmətə əlaqələndirmək"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"Sahibinə bir Vpn xidmətinin ən üst səviyyə araüzünü bağlamağa imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"divar kağızına bağlanır"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"Cihaz sahibinə yuxarı səviyyəli divar kağızı interfeysini cildləməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmamalıdır."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"widget servisini qoşma"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"Sahibinə vidcet servisin yüksək səviyyəli interfeysi ilə əlaqə saxlamaq icazəsi verir. Normal tətbiqlər tərəfindən heç vaxt istənilməməlidir."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"cihaz admini ilə ünsiyyət qurmaq"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"Sahibinə bir cihaz idarəçisinə planlar göndərmək üçün imkan verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"cihaz admini əlavə edin və ya silin"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"Sahibinə aktiv cihaz administratorlarını əlavə etməyə və ya silməyə icazə verir. Normal tətbiqlər üçün tələb olunmamalıdır."</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"ekran oriyentasiyasını dəyişir"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"Tətbiqə istənilən zaman ekranın vəziyyətini dəyişmə icazəsi verir. Normal tətbiqlər tərəfindən tələb olunmur."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"kursor sürətini dəyişmək"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"Tətbiqə mausun və ya trekpedin kursor sürətini istənilən zaman dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmamalıdır."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"klaviatura sxemini dəyişir"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"Tətbiqə klaviatura sxemini dəyişmək imkanı verir. Normal tətbiqlər tərəfindən tələb olunmur."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"tətbiqlərə Linux siqnalları göndərir"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"Tətbiqə bütün davamlı proseslərə siqnal soğrusu göndərməyə imkan verir."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"təbiqi həmişə çalışdır"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"Tətbiqə öz komponentlərini yaddaşda saxlama icazəsi verir. Bu planşetin sürətini zəiflətməklə, digər tətbiqlər üçün mövcud olan yaddaşı limitləyə bilər."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"Tətbiqə öz komponentlərini yaddaşda saxlama icazəsi verir. Bu digər tətbiqlər üçün mövcud olan yaddaşı limitləyə bilər."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"tətbiqləri sil"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"Tətbiqə Android paketləri silmə icazəsi verir. Zərərli tətbiqlər bundan digər vacib tətbiqləri silmək üçün istifadə edə bilər."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"digər tətbiqlərin məlumatını silir"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"Tətbiqə istifadəçi datasını təmizləməyə imkan verir."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"digər tətbiqlərin keşini sil"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"Tətbiqə keş faylları silmə icazəsi verir."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"tətbiq saxlama yaddaşını ölçmək"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"Tətbiqə özünün kodunu, məlumatını və keş ölçüsünü alma icazəsi verir."</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"birbaşa tətbiqlər quraşdırmaq"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"Tətbiqə yeni və ya güncəllənmiş Android paketlərini quraşdırmağa imkan verir. Zərərli tətbiqlər bundan istifadə edərək güclü səlahiyyətlərə malik tətbiqləri endirə bilər."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"bütün tətbiq keş datasını silir"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"Tətbiqə planşetin yaddaşını boşaltmaq üçün digər tətbiqlərin keş fayllarını silmək imkanı verir. Bu da digər tətbiqlərin dataları yenidən əldə etmələri səbəbindən daha yavaş işləmələrinə səbəb ola bilər."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"Tətbiqə digər tətbiqlərin keş qovluğunu təmizləyərək telefonun yaddaşını boşaltmaq icazəsi verir. Bu digər tətbiqlərin məlumatlarını yenidən əldə etməli olduqlarına görə daha yavaş başlamasına səbəb olur."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"tətbiq resurslarının yerini dəyişir"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"Tətbiqə tətbiq resurslarını daxili mediadan xarici mediaya və əksinə daşımağa imkan verir."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"məxfi loq datasını oxuyur"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"Tətbiqə sistemin müxtəlif jurnal fayllarını oxumağa imkan verir. Bu da Sizin planşetdə etdikləriniz haqqında məlumatlar, həmçinin şəxsi və konfidensial məlumatlar ola bilər."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"Tətbiqə sistemin müxtəlif jurnal fayllarını oxumağa imkan verir. Bu da Sizin planşetdə etdikləriniz haqqında məlumatlar, həmçinin şəxsi və konfidensial məlumatlar ola bilər."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"oxutmaq üçün istənilən media dekoderi istifadə edir"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"Tətbiqə playback\'i deşifrə etmək üçün hər hansı bir quraşdırılmış media deşifrələyicisini istifadə etmık imkanı verir."</string>
-    <string name="permlab_manageCaCertificates" msgid="1678391896786882014">"etibarlı etimadnamələri idarə et"</string>
-    <string name="permdesc_manageCaCertificates" msgid="4015644047196937014">"Tətbiqə etibarlı etimadnamələr kimi CA sertifikatlarını quraşdırmaq və sistemdən silməyə icazə verir."</string>
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"diaga məxsus olan mənbələri yaz/oxu"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"Tətbiqə diag qrupa məsus olan resursları yazmaq və oxumaq icazəsi verir; məsələn  /dev qovluğundakı fayllar. Bu sistemin stabilliyinə və təhlükəsizliyinə təsir edə bilər. Bu ancaq istehsalçı və ya operator tərəfindən avadanlığa xas diaqnostika üçün olmalıdır."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"tətbiq komponentlərini aktivləşdirmə və ya deaktivləşdirmə"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"Tətbiqə digər tətbiq komponentinin aktiv olub-olmadığını dəyişmək imkanı verir. Zərərli tətbiqlər bundan əhəmiyyətli planşet imkanlarını deaktiv etmək üçün istifadə edə bilər. Bu icazə ilə ehtiyatlı olmaq lazımdır, çünki tətbiq komponentləri yararsız, ziddiyyətli, və ya qeyri-sabit statusa çevrilə bilər."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"Tətbiqə digər tətbiq komponentinin aktiv olub-olmadığını dəyişmək imkanı verir. Zərərli tətbiqlər bundan əhəmiyyətli telefon imkanlarını deaktiv etmək üçün istifadə edə bilər. Bu icazə ilə ehtiyatlı olmaq lazımdır, çünki tətbiq komponentləri yararsız, ziddiyyətli, və ya qeyri-sabit statusa çevrilə bilər."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"icazələr vermək və ya ləğv etmək"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"Tətbiqə bu və ya digər tətbiqlərə xüsusi iznlər verməyə icazə verir. Zərərli tətbiqlər  bundan izin vermədiyiniz özəllikləri özlərinə vermək üçün istifadə edə bilər."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"tərcih edilən tətbiqlər qur"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"Tətbiqə tərcih etdiyiniz tətbiqləri dəyişmək imkanı verir. Zərərli tətbiqlər şəxsi məlumatlarınızı toplamaq üçün cari tətbiqlərinizi aldadaraq işləyən tətbiqləri xəbərsiz dəyişə bilər."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"sistem ayarlarında dəyişiklik etmək"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"Tətbiqə sistem ayarları datasını redaktə etmə icazəsi verir. Zərərli tətbiqlər sistem ayarlarını korlaya bilər."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"təhlükəsiz sistem nizamlarını dəyişir"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"Tətbiqə sistemin təhlükəsiz ayarlar datasını dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə üçün deyil."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google xidmətlər xəritəsini dəyişdir"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"Tətbiqə Google xidmətlər xəritəsini dəyişdirmək imkanı verir. Normal tətbiqlərin istifadəsi üçün deyil."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"başlanğıcda işləyir"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"Tətbiqə sistem yükləməni bitirdiyi zaman dərhal özünü başlatmağa imkan verir. Bu planşeti başlatmağın uzun çəkməsinə səbəb ola bilər və tətbiqə həmişə çalışdıraraq bütün planşeti yavaşlatmağa imkan verir."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"Tətbiqə sistem bootinqi bitirdikdən dərhal sonra özünü başlatmaq icazəsi verir. Bu telefonun açılmasını ləngidə və daima işlək qalaraq telefonun sürətini aşağı sala bilər."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"daimi siqnal göndərmək"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"Tətbiqə yayım bitdikdən sonra da qalan çətin yayımlar göndərməyə imkan verir. Hədsiz istifadə çox yaddaş istifadəsinə səbəb olmaqla planşeti yavaş və qeyri-stabil edə bilər."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"Tətbiqə yayım bitdikdən sonra da qalan çətin yayımlar göndərməyə imkan verir. Hədsiz istifadə çox yaddaş istifadəsinə səbəb olmaqla telefonu yavaş və qeyri-stabil edə bilər."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"kontakrlatınızı oxumaq"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"Tətbiqə planşetinizdə yerləşən kontaktları oxumaq icazəsi verir, tez-tez zəng elədiyiniz, emailləşdiyiniz və ya əlaqə saxladığınız xüsusi individuallar daxil olmaqla. Bu icazə tətbiqlərə kontakt məlumatlarınızı saxlamağa və zərərli tətbiqlərə kontakt məlumatlarını sizin bilginiz olmada paylaşma imkanı yaradır."</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"Tətbiqə tez-tez zəng elədiyiniz, e-məktub göndərdiyiniz və ya əlaqə saxladığınız xüsusi individuallar daxil olmaqla telefonunuzda yerləşən kontaktları oxumaq icazəsi verir. Bu icazə tətbiqlərə kontakt məlumatlarınızı saxlamağa və zərərli tətbiqlərə kontakt məlumatlarını sizin xəbəriniz olmada paylaşma imkanı yaradır."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"kontaktlarınızı dəyişdirir"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"Tətbiqə planşetinizdəki zəng etmək tezliyiniz, elektron poçtlarınız, ünsiyyətləriniz haqqında məlumatları dəyişməyə imkan verir. Bu icazə kontakt məlumatlarının silinməsinə də imkan verir."</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"Tətbiqə Sizin zəng etmək tezliyiniz, elektron poçtlarınız, ünsiyyətləriniz haqqında məlumatları dəyişməyə imkan verir. Buna kontaktların silinməsi imkanı də daxildir."</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"zəng qeydiyyatını oxu"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"Tətbiqə gələn və gedən zənglər haqqında olan data daxil olmaqla bərabər planşetinizin zəng qeydiyyatını oxumağa imkan verir. Bu icazə tətbiqlərə zəng qeydiyyatınızı saxlamağa imkan verir və zərərli tətbiqlər zəng qeydiyyat datasını sizdən xəbərsiz paylaşa bilər."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"Tətbiqə telefon jurnalınızı oxumağa imkan verir, buna gələn və gedən zənglər haqqında məlumatlar da daxildir. Bu icazə tətbiqə zəng jurnalı datasını saxlamağa imkan verir ki, Zərərli tətbiqlər bundan istifadə edərək Sizdən xəbərsiz bütün məlumatlarnızı paylaşa bilər."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"zəng loqu yazır"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"Tətbiqə planşetinizdəki zəng jurnalını, həmçinin gedən və gələn zənglərin siyahısını dəyişməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək, zəng jurnalınıza dəyişiklik edə bilər."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"Tətbiqə sizin daxil olan və gedən zənglər daxil olmaqla telefon zəngi loqlarınızı redaktə etmək icazəsi verir. Zərərli tətbiqlər bundan telefon loqlarınızı silmək və ya redaktə etmək üçün istifadə edə bilər."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"öz kontakt kartınızı oxuyun"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"Tətbiqə cihazınızda yerləşən adınız və kontakt məlumatlarınız kimi şəxsi profil məlumatlarını oxuma icazəsi verir. Bu o deməkdir ki, tətbiq sizi tanıya və sizin profil məlumatlarınızı başqalarına göndərə bilər."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"sizin kontakt kartınızda dəyişiklik etmək"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"Tətbiqə cihazınızda yerləşən adınız və kontakt məlumatlarınız kimi şəxsi profil məlumatlarını dəyişmək və ya əlavə etmək icazəsi verir. Bu o deməkdir ki, tətbiq sizi tanıya və sizin profil məlumatlarınızı başqalarına göndərə bilər."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"sosial lentinizi oxuyur"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"Tətbiqə Sizin və dostlarınızın sosial güncəllərini əldə etmək və sinxronizə etmək icazəsi verir. Məlumat paylaşarkən diqqətli olun - konfidensiallıqdan asılı olmayaraq bu, Siz və dostlarınız arasında sosial şəbəkələrdəki danışığı oxumaq imkanı verir. Qeyd: bu icazə bütün sosial şəbəkələrdə icra edilə bilməz."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"sosial axınınıza yazır"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"Tətbiqə dostlarınızdan sosial yenilənmələri göstərmə icazəsi verir. Məlumat paylaşarkən diqqətli olun - bu dostlarınızdan gələn mesajı emal etməyə izn verir. Qeyd: bu icazə bütün sosial şəbəkələrə şamil olunmaya bilər."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"təqvim tədbirlərini və konfidensial məlumatları oxuyur"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"Tətbiqə dostlarınızın və əməkdaşlarınızın planşetinizdə yerləşən kalendar tədbirlərini oxumağa icazə verir. Bu tətbiqə konfidensiallıq və ya həssaslıqdan asılı olmayaraq sizin kalendar məlumatlarınızı paylaşmaq və ya saxlamağa imkan yaradır."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"Tətbiqə dost və əməkdaşlara məxsus olanlar daxil olmaqla planşetdə yerləşən bütün kalendar tətbiqlərini oxumaq icazəsi verir. Bu tətbiqə konfidensiallıq və ya həssaslıqdan asılı olmayaraq, Sizin kalendar məlumatlarınızı paylaşmaq və ya saxlamaq imkanı yaradır."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"cihaz sahibinin icazəsi olmadan təqvim tədbirləri əlavə etmək və ya dəyişmək, bunun haqqında bildirişlər göndərmək"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"Tətbiqə planşetinizdəki tədbirləri dəyişməyə, tədbir əlavə etməyə və ya silməyə imkan verir. Buna Sizin dostlarınızla və həmkarlarınızla birlikdə hazırladığınız tədbirlər də daxildir. Bu, tədbirə Sizin adınızdan və Sizdən xəbərsiz, təqvim sahibi kimi mesaj göndərmək imkanını verir."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"Dostlarınız və həmkarlarınıza məxsus olanlar da daxil olmaqla, tətbiqə telefonunuzdakı tədbirləri dəyişməyə, tədbir əlavə etməyə və ya silməyə imkan verir. Bu, tədbirə Sizin adınızdan və Sizdən xəbərsiz, təqvim sahibi kimi mesaj göndərmək imkanı verir."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"test üçün saxta məkan mənbələri"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"Test üçün saxta məkan mənbələri yaradın və ya yeni məkan provayderi quraşdırın. Bu tətbiqlərə GPS və məkan provayderləri kimi məkan mənbələrindən alınan məkan və/ya statusları yenidən yazmağa icazə verir."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"əlavə məkan provayderi əmrlərinə çıxış"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"Tətbiqə əlavə məkan provayderi əmrlərinə daxil olmaq imkanı verir. Bu tətbiqə GPS əməliyyatına və ya digər məkan mənbələrinə mane olmaq imkanı verə bilər."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"Məkan provayderini quraşdırmaq icazəsi"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"Yeni yerləşmə təchizatçısını test etmək və ya quraşdırmaq üçün mock yerləşmə mənbələri yarat. Bu tətbiqə yerləşmənin və/ya digər yerləşmə mənbələrindən GPS və ya yerləşmə təchizatçıları qayıtmış statusların ləğv etməsinə imkan verir."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"dəqiq yeri (GPS və şəbəkə-əsaslı)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"Qlobal Pozisiya Sistemini və ya şəbəkə qüllələri və Wi-Fi kimi şəbəkə məkanını istifadə edərək tətbiqə Sizin dəqiq yerinizi təyin etməyə imkan verir. Bu məkan xidmətləri aktivləşdirilməlidirlər ki, Siz tətbiqi istifadə edən zaman tətbiq onları istifadə edə bilsin. Tətbiqlər Sizin harada olmağınızı bunun vasitəsilə təyin edəcək, eyni zamanda, bu xidmət əlavə batareya enerjisi apara bilər."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"təxmini məkan (şəbəkə əsaslı)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"Tətbiqə təxmini yerinizi almaq üçün imkan verir. Bu yer, yerləşmə xidmətləri tərəfindən mobil qüllələr və Wi-Fi kimi şəbəkə yerləşmə mənbələrdən istifadə etməklə əldə edilir. Bu yerləşmə xidmətləri tətbiqin onlardan istifadəsi üçün açıq və cihazınızın onları istifadəsi üçün mövcud olmalıdır. Tətbiqlər bundan sizin təxminən harada olduğunuzu müəyyənləşdirmək üçün istifadə edə bilər."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger\'ə daxil olmaq"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"Tətbiqə aşağı səviyyəli SurfaceFnger özəlliklərini istifadə etməyə icazə verir."</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"freym buferi oxuyur"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"Tətbiqə freym buferinin kontentini oxumaq icazəsi verir."</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"Wifi görüntülərini quraşdır"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"Tətbiqə Wifi görüntülərini quraşdırmağa və onlara qoşulmağa imkan verir."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"WiFi görüntülərini dəyişir"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Tətbiqə Wifi displeylərinin aşağı səviyyəli funksiyalarını idarə etmək imkanı verir."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"audio çıxışı alın"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"Tətbiqə audio çıxışı almaq və yenidən yönləndirmək imkanı verir."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"video çıxışı alın"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"Tətbiqə video çıxışı almaq və yenidən yönləndirmək imkanı verir."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"təhlükəsiz video çıxışı alın"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"Tətbiqə güvənli video çıxışı almaq və yenidən yönləndirmək imkanı verir."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"audio ayarlarınızı dəyişir"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"Tətbiqə səs və hansı spikerin çıxış üçün istifadə olunduğu kimi qlobal səs ayarlarını dəyişdirməyə imkan verir."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"səs yaz"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"Tətbiqə mikrofonla audio yazmaq icazəsi verir. İcazə tətbiqə sizin təsdiqiniz olmadan istənilən zaman səs yazma izni verir."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"şəkil və video çəkmək"</string>
-    <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_cameraDisableTransmitLed" msgid="2651072630501126222">"kamera istifadə edildikdə LED göstərici ötürülməsini deaktiv edir"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"Öncədən quraşdırılmış sistem tətbiqinə kamera tərəfindən istifadə edilən LED indikatorunu söndürmək icazəsi verir."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"planşeti daimi olaraq aradan qaldır"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"telefonu həmişəlik deaktiv etmək"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"Tətbiqə planşeti birdəfəlik deaktiv etməyə imkan verir. Bu da çox təhlükəlidir."</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"Tətbiqə bütün telefonu birdəfəlik deaktivləşdirməyə imkan verir. Bu çox təhlükəlidir."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"planşeti yenidən yüklənməyə məcbur edir"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"telefonu yenidən yüklənməyə məcbur edir"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"Tətbiqə planşeti yenidən yükləməyə məcbur etmək imkanı verir."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"Tətbiqə telefonu yenidən yükləməyə məcbur etmək üçün imkan verir."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB yaddaş fayl sisteminə daxil olmaq"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD Kart fayl sisteminə daxil olmaq"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"Tətbiqə silinəbilən yaddaşları və ya fayl sistemini quraşdırma və ayırma icazəsi verir."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB yaddaşı silir"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD kartı silir"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"Tətbiqə çıxarıla bilən yaddaşı format etməyə imkan verir."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"daxili yaddaşınız haqqında məlumat əldə etmək"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"Tətbiqə daxili yaddaş haqqında məlumat almağa imkan verir."</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"daxili yaddaş yaratmaq"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"Tətbiqə daxili yaddaş yaratmaq üçün imkan verir."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"daxili yaddaşı məhv etmə"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"Tətbiqə daxili yaddaşı məhv etmə icazəsi verir."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"daxili yaddaşı montaj və ya demontaj etmək"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"Tətbiqə daxili yaddaşı quraşdırma/ayırma icazəsi verir."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"daxili yaddaşın adını dəyiş"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"Tətbiqə daxili yaddaşın adını dəyişmək imkanı 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_manageUsb" msgid="1113453430645402723">"USB cihazlar üçün tərcihləri və icazələri idarə etmək"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"Tətbiqə USB cihazlar üçün olan tərcihləri və icazələri idarə etməyə imkan verir."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP protokol həyata keçirmək"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"Kernel MTP drayverə girişə imkan verir ki, MTP USB protokolunu həyata keçirsin."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"avadanlığı sınaq edir"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"Tətbiqə avadanlığı yoxlamaq üçün müxtəlif periferiyaları kontrol 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_callPrivileged" msgid="4198349211108497879">"istənilən nömrəyə birbaşa zəng edir"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"Tətbiqə Sizin müdaxiləniz olmadan, təcili zənglər də daxil olmaqla, istənilən telefon zəngini etməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək, təcili nömrələrə qanunsuz zəng vurmaqla Sizin üçün hüquqi problemlər yarada bilər."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA planşet ayarlarına birbaşa başlamaq"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA telefon quraşdırmalarına birbaşa başlamaq"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"Tətbiqə CDMA hazırlığını başlatma icazəsi verir. Zərərli tətbiqlər ehtiyac olmadıqda CDMA hazırlığını başlada bilərlər."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"məkan güncəlləmə bildirişlərini idarə edir"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"Tətbiqə radiodan gələn məkan güncəllənmələrini aktiv və ya deaktiv etməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"qeydiyyat xüsusiyyətlərini əldə edir"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"Tətbiqə giriş qeydi servisi tərəfindən yüklənmiş mülkiyyətə girişi oxumaq/yazmaq imkanl verir. Normal tətbiqlər üçün nəzərdə tutulmayıb."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"vidcetlər seç"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"Tətbiqə sistemə hansı vidcetin hansı tətbiq tərəfindən istifadə edilə bilməsini deməyə icazə verir. Bu icazəli tətbiqlər şəxsi məlumatlara və digər tətbiqlərə çıxış verə bilər. Normal tətbiqlər tərəfindən istifadə üçün deyil."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"telefon statusunu dəyişmək"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"Tətbiqə cihazın telefon funksiyalarını idarə etmək imkanı verir. Belə icazəli tətbiq Sizi xəbərdar etmədən şəbəkələri qoşa, telefon radiosunu yandırıb-söndürə bilər."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"telefon statusunu və identifikasiyanı oxuyur"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"Tətbiqə cihazın telefon funksiyalarına giriş icazəsi verir. Belə icazəli tətbiq bu telefonun nömrəsini və cihaz İD\'ni, zəngin aktiv olub-olmadığını və zəng edilən nömrəni müəyyən edə bilər."</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"planşetin yuxu rejiminin qarşısını almaq"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"telefonun yuxu rejiminə keçməsini əngəllə"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"Tətbiqə planşetin yuxu rejimini qadağan etməyə imkan verir."</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"Tətbiqə telefonun yuxu rejimini qadağan etmək imkanı verir."</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"planşeti yandırma və ya söndürmə"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"telefonu yandırmaq və ya söndürmək"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"Tətbiqə planşeti yandırmağa və söndürməyə imkan verir."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"Tətbiqə telefonu yandırıb söndürmə icazəsi verir."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"zavod test rejimində işləyir"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"Planşet avadanlığına tam girişə imkan verməklə aşağı səviyyəli istehsalçı sınağı kimi işləyir. Yalnız planşet istehsalçı sınaq rejimində olduqda işləyir."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"Bir aşağı səviyyəli istehsalçı testi kimi çalışdırın, telefon hardware üçün tam giriş imkanı verir. Ancaq telefon, istehsalçı test rejimində çalışdığı zaman aktivdir."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"divar kağızı yerləşdirir"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"Tətbiqə sistemə divar kağızı yerləşdirmək icazəsi verir."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"divar kağızı ölçüsünü verir"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"Tətbiqə sistem divar kağızı ölçüsü göstərişlərini müəyyən etməyə imkan verir."</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"fabrik defoltuna sıfırlamaq"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"Tətbiqə bütün məlumatları, nizamları və quraşdırılmış tətbiqləri silərək sistemi fabrik nizamlarına qaytarmaq imkanı verir."</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"vaxtı təyin edir"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"Tətbiqə planşetin saat vaxtını dəyişməyə imkan verir."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"Tətbiqə telefonun saat vaxtını dəyişməyə imkan verir."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"vaxt zonasını quraşdırır"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"Tətbiqə planşetin vaxt zonasını dəyişmə icazəsi verir."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"Tətbiqə telefon saat zolağını dəyişmək üçün imkan verir."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService kimi davranır"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"Tətbiqə AccountAuthenticators\'ə zəng etməyə imkan verir."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"cihazda hesabları tapır"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"Tətbiqə planşet tərəfindən bilinən hesabların siyahısını alma icazəsi verir. Bu quraşdırdığınız tətbiqlər tərəfindən yaradılmış istənilən hesab ola bilər."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"Tətbiqə telefonda olan hesabların siyahısını əldə etməyə imkan verir. Buna quraşdırdığınız istənilən tətbiq tərəfindən yaradılan hesablar da aiddir."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"hesablar yaradır və parollar təyin edir"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"Tətbiqə AccountManager\'in hesab yaratmaq və parol almaq və açmaq daxil olmaqla bərabər, hesab təsdiqləyici imkanlarını istifadə etməyə icazə verir."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"hesabları əlavə edir və ya silir"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"Tətbiqə hesabların əlavə olunması və ya silinməsi, həmçinin onların parollarının silinməsi kimi əməliyyatları icra etməyə imkan verir."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"cihazda hesablar istifadə etmək"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"Tətbiqə autentifikasiya tokenləri sorğularını göndərməyə icazə verir."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"şəbəkə bağlantılarına baxmaq"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"Tətbiqə mövcud olan və qoşulan şəbəkələr kimi qoşulmalar haqqında məlumatı görməyə icazə verir."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"tam şəbəkə girişi"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"Tətbiqə şəbəkə soketlərini yaratmağa və fərdi şəbəkə protokollarını istifadə etməyə imkan verir. Brauzer və digər tətbiqlər datanın internetə ötürülməsini təmin edən vəsaitlər verir, ona görə də datanın internetə gönrədilməsi üçün bu icazə tələb olunmur."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"şəbəkə nizamlarını və trafiki dəyişdirir/qarşısını alır"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"Tətbiqə şəbəkə trafikinin qarşısını almaq üçün şəbəkə nizamlarını dəyişmə icazəsi verir, məsələn proksini və ya istənilən APN-in portunu. Zərərli tətbiqlər şəbəkə paketlərini sizin bilginiz olmadan monitorinq edə, yönləndirə və ya redaktə edə bilər."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"şəbəkə bağlantısını dəyişir"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"Tətbiqə şəbəkə vəziyyətini dəyişməyə icazə verir."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"Sərhədli bağlantını dəyişir"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"Tətbiqə birləşilmiş şəbəkə bağlantısının statusunu dəyişməyə imkan verir."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"arxafon data istifadəsi ayarını dəyişir"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"Tətbiqə fon rejimi nizamlarını dəyişməyə icazə verir."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"Wi-Fi bağlantılarına baxmaq"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"Tətbiqə Wi-Fi şəbəkələri haqqında məlumatı görməyə icazə verir, məsələn, Wi-Fi mövcudluğu və qoşulmuş Wi-Fi cihazlarının adları."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"Wi-Fi şəbəkəsinə qoşulmaq və ya ayrılmaq"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"Tətbiqə Wi-Fi çıxış nöqtəsinə qoşulmaq və ondan ayrılmaq və cihazın Wi-Fi şəbəkə nizamlarını dəyişməyə icazə verir."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"Wi-Fi Multicast qəbuluna icazə ver"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"Tətbiqə Wi-Fi şəbəkədə sizin planşetdən başqa digər multikast adreslərə yönləndirilmiş paketləri almaq icazəsi verir. Bu qeyri-çoxadresli rejimdən fəqli olaraq daha çox enerji işlədir."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"Tətbiqə qrup ünvanlar istifadə etməklə, Wi-Fi şəbəkəsində olan bütün cihazlara göndərilmiş paketləri qəbul etməyə imkan verir. Buna daha çox enerji sərf olunur."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"Bluetooth ayarlarını əldə edir"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"Tətbiqə yerli Bluetooth planşetinin konfiqurasiyasını görməyə və məsafədən cihazları tapmağa və cütləməyə imkan verir."</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"Tətbiqə lokal Bluetooth telefonunu konfiqurə etməyə və uzaq cihazları kəşf etmək və onlara qoşulmaq icazəsi verir."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX\'a qoşul və bağlantını kəs"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"Tətbiqə WiMAX mövcudluğu və qoşulmuş WiMAX şəbəkələrini təyin etməyə icazə verir."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"WiMAX vəziyyətini dəyişir"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"Tətbiqə planşeti WiMAX şəbəkələrinə qoşmaq və onlardan ayırmaq icazəsi verir."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"Tətbiqə telefonu WiMAX şəbəkəsinə qoşmağa və ya WiMAX şəbəkəsindən ayırmağa imkan verir."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"Bluetooth cihazları ilə cütləndirmək"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"Tətbiqə yerli Bluetooth planşetinin konfiqurasiyasını görməyə və cütlənmiş cihazlarla bağlantılar etməyə və qəbul etməyə imkan verir."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"Tətbiqə Bluetooth və ya telefon konfiqurasiyalarını görməyə və qoşulmuş cihazlarla əlaqə qurmağa və qəbul etməyə icazə verir."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"Near Field Communication\'ı kontrol et"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"Tətbiqə Yaxın Məsafə Kommunikasiyası (NFC) teqləri, kartları və oxuyucuları ilə əlaqə qurmağa icazə verir."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"Ekran kilidini deaktiv edir"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"Tətbiqə kilid açarını və təhlükəsizlik parolunu deaktiv etməyə imkan verir. Qanuni misal budur ki, telefon zəng qəbul edən zaman kilidi açır və zəng qurtarandan sonra kilidi bağlayır."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"sinx ayarlarını oxu"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"Tətbiqə hesablar üçün sinxronizasiya nizamlarını oxuma icazəsi verir. Məsələn, bu Şəxslər tətbiqinin sinxronizə olunub-olunmadığını təyin edə bilər."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"sinxronizasiyaya davam edir və onu söndürür"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"Tətbiqə hesab üçün sinxronizasiya nizamlarını dəyişməyə icazə verir. Məsələn, bu istifadəçi hesablı Şəxslər tətbiqinin sinxronizasiyasını başlamaq üçün istifadə edilə bilər."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"sinxronizasiya statistikasını oxumaq"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"Tətbiqə sync tədbirlərinin tarixçəsi və nə qədər datanın sinx olduğu da daxil olmaqla bərabər, hər hansı bir hesab üçün olan sinx statlarını oxumağa imkan verir."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"abunə olunmuş xəbərləri oxuyur"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"Tətbiqə hazırda sinxron lentlər haqqında ətraflı məlumat almaq üçün imkan verir."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"abunə olunmuş xəbərləri yazır"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"Tətbiqə cari sinxronlaşmış lentlərinizə dəyişiklik etmək imkanı verir. Zərərli tətbiqlər sixronlaşmış lentlərinizi dəyişə bilər."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"lüğətə əlavə etdiyiniz şərtləri oxumaq"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"Tətbiqə istifadəçinin lüğətdə saxladığı bütün sözləri, adları və frazaları oxumaq icazəsi verir."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"istifadəçi lüğətinə sözlər əlavə etmək"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"Tətbiqə istifadəçi lüğətinə yeni sözlər yazmağa imkan verir."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"qorunmuş yaddaşa daxil olmağa cəhd etmək"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"qorunmuş yaddaşa daxil olmağa cəhd etmək"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"Tətbiqə gələcək cihazlarda əlçatımlı olacaq USB yaddaş üçün icazə testi etməyə imkan verir."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"Tətbiqə gələcək cihazlarda mövcud olacaq SD kart üçün icazəni test etmək üçün imkan verir."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"USB yaddaşınızın məzmununu dəyişmək və ya silmək"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"SD kart kontentlərini dəyişir və ya silir"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"Tətbiqə USB yaddaşa yazmağa imkan verir."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"Tətbiqə SD karta yazma icazəsi verir."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"daxili media yaddaşı kontentini dəyişir/silir"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"Tətbiqə daxili media yaddaşdakı kontenti redaktə etmək icazəsi verir."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"sənəd yaddaşını nizamlayır"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"Tətbiqə sənəd yaddaşını idarə etməyə imkan verir."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"bütün istifadəçilərin xarici yaddaşına daxil ol"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"Tətbiqə bütün istifadəçilər üçün olan xarici yaddaşa giriş imkanı verir."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"keş fayl sisteminə girmək"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"Tətbiqə keş fayl sistemini oxumağa və yazmağa icazə verir."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"İnternet zəngləri etmək və ya qəbul etmək"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"Tətbiqə internet zənglərinin göndərilməsi və qəbul edilməsi üçün SIP servisindən istifadə icazəsi verir."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"tarixi şəbəkə istifadəsini oxu"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"Tətbiqə xüsusi şəbəkələr və tətbiqlər üçün tarixi şəbəkə istifadəsini oxumağa icazə verir."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"şəbəkə siyasətini idarə etmək"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"Tətbiqə şəbəkə qanunlarını və tətbiqin xüsusi qaydalarını idarə etmək imkanı verir."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"şəbəkə istifadə hesabını dəyişmək"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"Tətbiqə şəbəkə istifadəsinin tətbiqlərə qarşı nizamlarını redaktə etməyə icazə verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"soket işarələrini dəyişin"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"Tətbiqə araşdırma üçün soket işarələrini dəyişmək imkanı verir"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"bildirişlərə daxil ol"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"Tətbiqə bildirişləri əldə etməyə, sınamağa və təmizləməyə imkan verir, buna digər tətbiqlər tərəfindən verilmiş bildirişlər də daxildir."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"bildiriş dinləmə xidmətinə bağlanır"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"Sahibinə yüksək səviyyəli bildiriş dinləmə servisi ilə əlaqə saxlamağa icazə verir. Normal tətbiqlər tərəfindən heç vaxt istənilməməlidir."</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"operator xidmətli konfiurasiya tətbiqinə müraciət edin"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"Sahibinə operator xidmətli tətbiq konfiqurasiyasına  müraciət imkanı verir. Normal tətbiqlər üçün tələb olunmamalıdır."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"şəbəkə şəraiti haqqında müşahidələr üçün qulaq asmaq"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"Tətbiqə şəbəkə şəraiti üzrə müşahidələr üçün qulaq asmaq imkanı verir. Normal tətbiqlər üçün heç vaxt lazım olmamalıdır."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"Parol qaydalarını təyin edin"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"Ekran kilidini açan şifrələrin uzunluğunu və onlardakı icazə verilən işarələrə nəzarət edir."</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"Ekran kilidi cəhdlərini monitorinq et"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"Ekan kilidini açarkən daxil edilmiş yanlış parollara baxın və əgər həddindən çox yanlış parollar daxil edilibsə, planşeti kilidləyin və ya bütün planşet datasını silin."</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"Ekan kilidini açarkən daxil edilmiş yanlış parollara baxın və əgər həddindən çox yanlış parollar daxil edilibsə, telefonu kilidləyin və ya bütün telefon datasını silin."</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"Ekran kilid parolunu dəyişin"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"Ekran kilidini açan şifrəni dəyişdirin."</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"Ekranı kilidləyin"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"Ekranın nə vaxt və necə kilidlənməsinə nəzarət edir."</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"Bütün məlumatları silin"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"Planşetin datasını xəbərdarlıq olmadan, zavod data sıfırlaması ilə silin."</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"Telefonun datasını xəbərdarlıq olmadan, zavod data sıfırlaması ilə silin"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"Cihazın qlobal proksisini ayarlayın"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"Siyasət aktiv olarkən cihazın qlobal proksisini istifadə üçün qurun. Yalnız ilk cihaz admini effektiv qlobal proksini təyin edir."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"Ekran kilidi şifrəsinə son zaman seç"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"Ekran kilidi parolunun nə qədər tez-tez dəyişməsini kontrol edin."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"Yaddaş şifrələnməsini ayarlayın"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"Tətbiq məlumatlarının şifrələnməsini tələb edir."</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"Kameraları dekativ edin"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"Bütün cihaz kameralarının istifadəsini əngəllə."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"Klaviatura kilidində funksiyaları deaktiv edin"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"Klaviatura kilidində bəzi funksiyaların qarşısını alın."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"Əsas səhifə"</item>
-    <item msgid="869923650527136615">"Mobil"</item>
-    <item msgid="7897544654242874543">"İş"</item>
-    <item msgid="1103601433382158155">"İş Faksı"</item>
-    <item msgid="1735177144948329370">"Ev Faksı"</item>
-    <item msgid="603878674477207394">"Peycer"</item>
-    <item msgid="1650824275177931637">"Digər"</item>
-    <item msgid="9192514806975898961">"Şəxsi"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"Ana səhifə"</item>
-    <item msgid="7084237356602625604">"İş"</item>
-    <item msgid="1112044410659011023">"Digər"</item>
-    <item msgid="2374913952870110618">"Fərdi"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"Əsas səhifə"</item>
-    <item msgid="5629153956045109251">"İş"</item>
-    <item msgid="4966604264500343469">"Digər"</item>
-    <item msgid="4932682847595299369">"Düzənləyin"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"Əsas səhifə"</item>
-    <item msgid="1359644565647383708">"İş"</item>
-    <item msgid="7868549401053615677">"Digər"</item>
-    <item msgid="3145118944639869809">"Fərdi"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"İş"</item>
-    <item msgid="4378074129049520373">"Digər"</item>
-    <item msgid="3455047468583965104">"Fərdi"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Söhbət"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"Şəxsi"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"Ev"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"Mobil"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"İş"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"İş Faksı"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"Ev Faksı"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"Peycer"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"Digər"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"Geriyə zəng"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"Avtomobil"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"Şirkət"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"Əsas"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"Digər faks"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"Radio"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"Teleks"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"Mobil iş telefonu"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"İş Peyceri"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"Köməkçi"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"Fərdi"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"Doğum günü"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"İldönümü"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"Digər"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"Fərdi"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"Əsas səhifə"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"İş"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"Digər"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"Mobil"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"Fərdi"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"Əsas səhifə"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"İş"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"Digər"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"Fərdi"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"Ana səhifə"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"İş"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"Digər"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"Şəxsi"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Görüşlər"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"İş"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"Digər"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"Fərdi"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"Şəxsi"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"Köməkçi"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"Qardaş"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"Uşaq"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"Ev yoldaşı"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"Ata"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"Dost"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"Müdir"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"Ana"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"Valideyn"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"Ortaq"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"Dəvət edən"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"Qohum"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"Bacı"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"Həyat yoldaşı"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"Fərdi"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"Əsas səhifə"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"İş"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"Digər"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PİN kodu daxil edin"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK və yeni PİN kod daxil edin"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK kod"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Yeni PIN kodu"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Şifrə daxil etmək üçün toxunun"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Kilidi açmaq üçün parol yazın"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Kilidi açmaq üçün PIN daxil edin"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Yanlış PIN kodu."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Kilidi açmaq üçün Menyu, sonra 0 basın."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"Təcili nömrə"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"Xidmət yoxdur."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"Ekran kilidlənib."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"Təcili zəng kilidini açmaq və ya yerləşdirmək üçün Menyu düyməsinə basın."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"Kilidi açmaq üçün Menyu düyməsinə basın."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"Kilidi açmaq üçün model çəkin"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"Təcili zəng"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"Zəngə qayıt"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"Düzdür!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Bir də cəhd edin"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Bir daha cəhd et"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Sifət kilidi cəhdləriniz bitdi"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"Batareya yığılır, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"Dolub"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"Elektrikə qoşun."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM kart yoxdur."</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"Planşetdə SIM kart yoxdur."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"Telefonda SİM kart yoxdur."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SİM kart daxil edin."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SİM kart yoxdur və ya oxuna bilinmir. SİM kart daxil edin."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"Yararsız SIM kart."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"Sizin SİM kartınız daimi olaraq deaktivləşib.\n Başqa SİM kart üçün simsiz xidmət provayderinizə müraciət edin."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"Əvvəlki trek düyməsi"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"Növbəti trek düyməsi"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"Pauza düyməsi"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"Oxutma düyməsi"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"Dayandırma düyməsi"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"Yalnız təcili zənglər"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"Şəbəkə kilidlidir"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM kart PUK ilə kilidlənib."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"İstifadəçi Təlimatlarına baxın və ya Müştəri Xidmətlərinə müraciət edin."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM kart kilidlənib."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SİM kartın kilidi açılır..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"Siz kilid modelini <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış çəkdiniz. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə içində yenidən sınayın."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"Şifrənizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz.\n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın"</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"Siz PIN nömrənizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz. \n \n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə içində təkrar sınayın."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"Siz kilidi açmaq üçün şablonu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə səhv çəkdiniz. <xliff:g id="NUMBER_1">%d</xliff:g> daha uğursuz cəhddən sonra planşetin kilidini Google hesabınıza daxil olmaqla açmağınız istəniləcək.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində bir daha yoxlayın."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"Siz kilidi açmaq üçün şablonu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə səhv çəkdiniz. <xliff:g id="NUMBER_1">%d</xliff:g> daha uğursuz cəhddən sonra planşetin kilidini Google hesabınıza daxil olmaqla açmağınız tələb olunacaq.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində bir daha yoxlayın."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"Siz planşet kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, planşet fabrik ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"Siz telefon kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, telefon zavod ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"Siz planşetin kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> yanlış cəhd etmisiniz. Planşet artıq defolt zavod halına sıfırlanacaq."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"Siz telefonun kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> dəfə səhv cəhd etdiniz. Telefonunuz indi zavod nizamlarına yenilənəcək."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"<xliff:g id="NUMBER">%d</xliff:g> saniyə ərzində bir daha cəhd edin."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"Şablonu unutdunuz?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"Hesab kilid açma"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"Həddindən çox cəhd edildi!"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"Kilidi açmaq üçün Google hesabınız ilə daxil olun."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"İstifadəçi adı (e-poçt)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"Şifrə"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"Daxil olun"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"Yanlış istifadəçi adı və parol."</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"İstifadəçi adınızı və ya parolunuzu unutmusunuz?\n "<b>"google.com/accounts/recovery"</b>" linkinə daxil olun."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"Yoxlanır..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"Kilidi aç"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"Səs açıqdır"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"Səs sönülüdür"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"Model başlandı"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"Model təmizləndi"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"Xana əlavə edildi"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"Model tamamlandı"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Widget %2$d of %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Widget əlavə edin."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Boş"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Kilidi açma sahəsi genişləndi."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Kilidi açma sahəsi çökdü."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> vidcet."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"İstifadəçi selektoru"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Status"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Kamera"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Media kontrolları"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Yenidən sıralama vidceti başladıldı."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Vidcetin təkrar sifarişi sona çatdı."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Vidcet <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> silindi."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Kilidi açma sahəsini genişləndir."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Sürüşdürmə kilidi."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Kild açma modeli."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Sifət Kilidi"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin kilid açması."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Şifrə kilidi."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Model sahəsi."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Sürüşdürmə sahəsi."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"simvol"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"söz"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"link"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"xətt"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"Zavod testi alınmadı"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"Bu FACTORY_TEST fəaliyyəti yalnızca/sistemdə/tətbiqdə quraşdırılmış paketlər üçün dəstəklənir."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"FACTORY_TEST əməliyyatını təsdiqləyən heç bir paket tapılmadı."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"Yenidən yükləyin"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"\"<xliff:g id="TITLE">%s</xliff:g>\"dakı səhifədə deyilir:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"Naviqasiyanı Təsdiq edin"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"Bu Səhifəni Tərk edin"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"Bu səhifədə qalın"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nBu səhifədən kənara naviqasiya etmək istədiyinizə əminsiniz mi?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"Təsdiqlə"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"Məsləhət: Böyütmək və kiçiltmək üçün iki dəfə tıklayın."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"Avtodoldurma"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"AvtoDoldurmanı ayarla"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"Vilayət"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"Poçt kodu"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"Dövlət"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"Poçt indeksi"</string>
-    <string name="autofill_county" msgid="237073771020362891">"Ölkə"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"Ada"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"Sahə"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"Departament"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"Prefektura"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"Pariş"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"Sahə"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"Əmirlik"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"Veb əlfəcinlərinizi və tarixçələrinizi oxumaq"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"Tətbiqə Brauzerin daxil olduğu bütün linkləri və bütün Brauzer əlfəcinlərini oxumaq imkanı verir. Qeyd: bu icazə veb brauzer imkanları olan üçüncü tərəf brazuerləri və digər tətbiqlər tərəfindən yerinə yetirilə bilməz."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"veb əlfəcinləri və tarixçəsi yazmaq"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"Tətbiqə planşetinizdəki brauzer tarixini və əlfəcinləri redaktə etmək icazəsi verir. Bu tətbizə brauzer məlumatlarını silmək və ya redaktə etmək imkanı verə bilər. Qeyd: Bu icazə 3-cü partiya brauzerlərə və ya veb brauzing xüsusiyyətli digər tətbiqlərə şamil olunmaya bilər."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"Tətbiqə Brauzer tarixçəsi və telefonunuzda saxlanılan əlfəcinlərə dəyişiklik etmək imkanı verir. Bununla tətbiqlə Brauzer datanızı silə və ya dəyişdirə bilər. Qeyd: bu icazə veb brauzer imkanları olan üçüncü tərəf brazuerləri və digər tətbiqlər tərəfindən yerinə yetirilə bilməz."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"siqnal qurur"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"Tətbiqə quraşdırlmış zəngli saata alarm ayarlamağa imkan verir. Bəzi zəngli saat tətbiqləri bu özəlliyi dəstəkləməyə bilər."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"Səsli poçt əlavə et"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"Tətbiqə səsli poçt qutunuza mesaj əlavə etməyə imkan verir."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"Brauzerin geolokasiya icazələrini dəyişir"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"Tətbiqə Brauzerin geolokasiya icazələrini dəyişməyə imkan verir. Zərərli tətbiqlər bundan istifadə edərək məkan məlumatlarını təsadüfi saytlara göndərə bilər."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"paketləri təsdiqlə"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"Tətbiqə paketin quraşdırılabilən olmasını yoxlamağa imkan verir."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"paket doğrulayıcıya bağlanır"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"Sahibinə paket yoxlayıcılarına sorğu göndərmək icazəsi verir. Normal tətbiqlər tərəfindən heç vaxt istənilməməlidir."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"serial porta çıxır"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"Sahibinə SerialManager API vasitəsilə serial portlara icazə izni verir."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"xarici kontent provayderlərinə giriş"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"Məzmun provayderlərinə örtükdən daxil olmaq üçün cihaz sahibinə imkan verir. Normal tətbiqlər üçün lazım deyil."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"avtomatik cihaz yenilənmələrini pozur"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"Sahibinə yeni versiyaya yenilənmək üçün nə vaxt qeyri-interaktiv reboot məlumatını sistemə təklif etmə icazəsi verir."</string>
-    <string name="save_password_message" msgid="767344687139195790">"Brauzerin bu şifrəni yadda saxlamasını istəyirsiz?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"İndi yox"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"Yadda saxla"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"Heç vaxt"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"Bu səhifəni açmaq üçün icazəniz yoxdur."</string>
-    <string name="text_copied" msgid="4985729524670131385">"Mətn panoya kopyalandı."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"Daha çox"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"Menyu+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"boşluq"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"daxil olun"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"sil"</string>
-    <string name="search_go" msgid="8298016669822141719">"Axtar"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"Axtarış"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"Axtarış sorğusu"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"Sorğunu təmizlə"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"Sorğunu göndərin"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"Səsli axtarış"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"Toxunaraq Kəşf et funksiyası aktiv edilsin?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> Toxunaraq Kəşf Et rejimini aktivləşdirmək istəyir. Toxunaraq Kəşf Et açıldığı zaman, barmağınızın altında nə olduğu haqda olan təsvirləri eşidə və ya görə bilərsiniz və yaplanşetdə insanlarla əlaqəyə keçmək üçün jestlər həyata keçirə bilərsiniz."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> Toxunaraq Kəşf Et rejimini aktivləşdirmək istəyir. Toxunaraq Kəşf Et açıldığı zaman, barmağınızın altında nə olduğu haqda olan təsvirləri eşidə və ya görə bilərsiniz və ya telefonda insanlarla əlaqəyə keçmək üçün jestlər həyata keçirə bilərsiniz"</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"1 ay öncə"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"1 ay əvvəl"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"1 saniyə əvvəl"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> saniyə əvvəl"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"1 dəqiqə əvvəl"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə əvvəl"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"1 saat əvvəl"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> saat əvvəl"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"Son <xliff:g id="COUNT">%d</xliff:g> gün"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"Keçən ay"</string>
-    <string name="older" msgid="5211975022815554840">"Köhnə"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"dünən"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> gün əvvəl"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"1 saniyə ərzində"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> saniyə içində"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"1 dəqiqə içində"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə ərzində"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"1 saata"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> saata"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"sabah"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> gün ərzində"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"1 saniyə əvvəl"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> san əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"1 dəqiqə əvvəl"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"1 saat əvvəl"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> saat əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"dünən"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> gün əvvəl"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"1 san ərzində"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> san ərzində"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"1 dəq ərzində"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> dəqiqəyə"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"1 saat ərzində"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> saata"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"sabah"</item>
-    <item quantity="other" msgid="2973062968038355991">"<xliff:g id="COUNT">%d</xliff:g> günə"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g> tarixində"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"saat <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> ilində"</string>
-    <string name="day" msgid="8144195776058119424">"gün"</string>
-    <string name="days" msgid="4774547661021344602">"günlər"</string>
-    <string name="hour" msgid="2126771916426189481">"saat"</string>
-    <string name="hours" msgid="894424005266852993">"saatlar"</string>
-    <string name="minute" msgid="9148878657703769868">"dəq."</string>
-    <string name="minutes" msgid="5646001005827034509">"dəqiqə"</string>
-    <string name="second" msgid="3184235808021478">"sn"</string>
-    <string name="seconds" msgid="3161515347216589235">"san"</string>
-    <string name="week" msgid="5617961537173061583">"həftə"</string>
-    <string name="weeks" msgid="6509623834583944518">"həftə"</string>
-    <string name="year" msgid="4001118221013892076">"il"</string>
-    <string name="years" msgid="6881577717993213522">"il"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 saniyə"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> saniyə"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"1 dəqiqə"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> dəqiqə"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"1 saat"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> saat"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"Video problemi"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"Bu video bu cihaza strim olunmaq üçün uyğun deyil."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"Bu video oxumur"</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"OK"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"günorta"</string>
-    <string name="Noon" msgid="3342127745230013127">"Günorta"</string>
-    <string name="midnight" msgid="7166259508850457595">"gecəyarı"</string>
-    <string name="Midnight" msgid="5630806906897892201">"Gecəyarı"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"Hamısını seç"</string>
-    <string name="cut" msgid="3092569408438626261">"Kəs"</string>
-    <string name="copy" msgid="2681946229533511987">"Kopyala"</string>
-    <string name="paste" msgid="5629880836805036433">"Yerləşdir"</string>
-    <string name="replace" msgid="5781686059063148930">"Əvəz et..."</string>
-    <string name="delete" msgid="6098684844021697789">"Sil"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL kopyala"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"Mətn seçin"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"Mətn seçimi"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"Lüğətə əlavə et"</string>
-    <string name="deleteText" msgid="6979668428458199034">"Sil"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"Daxiletmə metodu"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"Mətn əməliyyatları"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"Yaddaş yeri bitir"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"Bəzi sistem funksiyaları işləməyə bilər"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> işlənir"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"Daha çox məlumat üçün və ya tətbiqi dayandırmaq üçün toxunun."</string>
-    <string name="ok" msgid="5970060430562524910">"OK"</string>
-    <string name="cancel" msgid="6442560571259935130">"Ləğv et"</string>
-    <string name="yes" msgid="5362982303337969312">"OK"</string>
-    <string name="no" msgid="5141531044935541497">"Ləğv et"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"Diqqət"</string>
-    <string name="loading" msgid="7933681260296021180">"Yüklənir…"</string>
-    <string name="capital_on" msgid="1544682755514494298">"AÇIQ"</string>
-    <string name="capital_off" msgid="6815870386972805832">"QAPALI"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"Əməliyyatı tamamlayın:"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"Bu fəaliyyət üçün defolt istifadə edin"</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"Sistem ayarlarında, Tətbiqlərdə və Endirilmişlərdə defoltu təmizləyin."</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"Fəaliyyət seçin"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB cihaz üçün tətbiq seçin"</string>
-    <string name="noApplications" msgid="2991814273936504689">"Heç bir tətbiq bu əməliyyatı apara bilmir."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"Təəssüf ki, <xliff:g id="APPLICATION">%1$s</xliff:g> dayandı."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"Təəssüf ki, <xliff:g id="PROCESS">%1$s</xliff:g> prosesi dayandı."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> cavab vermir.\n\nOnu bağlamaq istəyirsiniz?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> aktivitisi cavab vermir. \n\nOnu bağlamaq istəyirsiniz?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> cavab vermir. Onu bağlamaq istəyirsiniz?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"Proses <xliff:g id="PROCESS">%1$s</xliff:g> cavab vermir. \n \n Onu bağlamaq istəyirsiniz?"</string>
-    <string name="force_close" msgid="8346072094521265605">"OK"</string>
-    <string name="report" msgid="4060218260984795706">"Şikayət edin"</string>
-    <string name="wait" msgid="7147118217226317732">"Gözlə"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"Bu səhifə yararsızlaşıb.\n\nBağlamaq istəyirsiz?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"Tətbiq yönləndirildi"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> indi çalışır."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ilk başladıldı."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"Miqyas"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"Həmişə göstər"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"Bunları Sistem ayarlarında yenidən aktivləşdir Yüklənmiş &gt; Tətbiqlər &gt;."</string>
-    <string name="smv_application" msgid="3307209192155442829">"Tətbiq <xliff:g id="APPLICATION">%1$s</xliff:g> (proses <xliff:g id="PROCESS">%2$s</xliff:g>) StrictMode siyasətini pozdu."</string>
-    <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> prosesi StrictMode siyasətini pozdu."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android təkmilləşdirilir..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"<xliff:g id="NUMBER_1">%2$d</xliff:g> əddədən <xliff:g id="NUMBER_0">%1$d</xliff:g> tətbiq optimallaşır."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"Tətbiqlər başladılır."</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"Yükləmə başa çatır."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> çalışır"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"Tətbiqə keçmək üçün toxunun"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"Tətbiqlərə keçilsin?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"Bir tətbiq artıq işləyir. Digərini başlatmaq üçün onu dayandırmalısınız."</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g> bölməsinə qayıdın"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"Yeni tətbiqi başlatmayın."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> tətbiqini başladın"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"Köhnə tətbiqi yadda saxlamadan dayandırın."</string>
-    <string name="sendText" msgid="5209874571959469142">"Mətn üçün əməliyyat seçin"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"Zəngin səs gücü"</string>
-    <string name="volume_music" msgid="5421651157138628171">"Media həcmi"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"Bluetooth vasitəsilə oynadılır"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"Səssiz zəng"</string>
-    <string name="volume_call" msgid="3941680041282788711">"Daxili zəng səsi"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"Bluetooth zəng həcmi"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"Siqnal səsi"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"Bildiriş səsi"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"Həcm"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"Bluetooth həcmi"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"Zəng səsi gücü"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"Zəng həcmi"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"Media həcmi"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"Bildiriş səsi"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"Defolt rinqton"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"Defolt rinqton (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"Heç biri"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"Zəng səsləri"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"Naməlum rinqton"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi şəbəkəsi mövcuddur"</item>
-    <item quantity="other" msgid="4192424489168397386">"Wi-Fi şəbəkələri mövcuddur"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"Wi-Fi şəbəkəni açın"</item>
-    <item quantity="other" msgid="7915895323644292768">"Açıq Wi-Fi şəbəkələri mövcuddur"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Wi-Fi şəbəkəsinə daxil ol"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"Şəbəkəyə daxil olun"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Wi-Fi\'a qoşulmaq alınmadı"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" internet bağlantısı keyfiyyətsizdir."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"Wi-Fi Direct"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"Wi-Fi Direct əməliyyatını başlat. Bu Wi-Fi müştəri/hotspotu bağlayacaq."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"Wi-Fi Direct başladıla bilmədi."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi Direct aktivdir"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"Ayarlar üçün toxunun"</string>
-    <string name="accept" msgid="1645267259272829559">"Qəbul edin"</string>
-    <string name="decline" msgid="2112225451706137894">"İmtina edin"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"Dəvətnamə göndərildi"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"Qoşulmaq üçün dəvət"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"Kimdən:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"Kimə:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"Tələb olunan PİN kodu daxil edin:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PİN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"Bu planşet <xliff:g id="DEVICE_NAME">%1$s</xliff:g> cihazına qoşulan zaman Wi-Fi şəbəkəsindən müvəqqəti ayrılmış olacaq"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"Bu telefon <xliff:g id="DEVICE_NAME">%1$s</xliff:g> cihazına qoşulan zaman Wi-Fi şəbəkəsindən müvəqqəti ayrılmış olacaq"</string>
-    <string name="select_character" msgid="3365550120617701745">"Simvol daxil edin"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS mesaj göndərilir"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; çox sayda SMS mesaj göndərir. Bu tətbiqin mesaj göndərməyə davam etməsinə icazə verirsiniz?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"İcazə verin"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"Rədd edin"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt; ünvanına mesaj göndərmək istəyir."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"Bu, mobil hesabınıza "<font fgcolor="#ffffb060">"əlavə tariflərin tətbiq olunması"</font>" ilə nəticələnə bilər."</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"Bu mobil hesabınızda ödənişlərə səbəb olacaq."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"Göndər"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"Ləğv et"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"Mənim seçimimi yadda saxla"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"Bunu sonra Ayarlarda dəyişə bilərsiniz &gt; Tətbiqlər"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"Həmişə icazə ver"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"Heç vaxt icazə verməyin"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM kart çıxarıldı"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"Cihazınızı etibarlı SIM kart ilə başladana kimi mobil şəbəkə əlçatmaz olacaq."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"Bitdi"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SİM kart əlavə edildi"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"Mobil şəbəkəyə qoşulmaq üçün cihazınızı yenidən başladın."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"Yenidən başlat"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"Vaxt ayarlayın"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"Tarixi quraşdır"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"Ayarlayın"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"Hazırdır"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"YENİ: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g> tərəfindən təmin edilib."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"Heç bir icazə tələb olunmur"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"bununla sizdən xərc tutula bilər"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB toplu yaddaş"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB qoşuludur"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"Siz USB vasitəsilə kompütere bağlandınız. Kompüter və Androidinizin USB yaddaşı arasında faylları kopyalamaq istəyirsinizsə, aşağıdakı düyməyə toxunun."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"Kompüterinizə USB ilə qoşulmusunuz. Faylları Androidinizin SD kartı ilə kompüteriniz arasında kopyalamaq istəyirsinizsə aşağıdakı düyməyə toxunun."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB yaddaşı aktivləşdirin"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB yaddaşınızı USB kütləvi yaddaşı üçün istifadə edən zaman problem yarandı."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"SD kartınızı USB kütləvi yaddaşı üçün istifadə edən zaman problem yarandı."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB qoşuludur"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"Faylları kompüterinizə kopyalamaq və ya kompüterinizdən kopyalamaq üçün toxunun."</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB yaddaşı söndürün"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB yaddaşı söndürmək üçün toxunun."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB yaddaş istifadə olunur"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB yaddaşı söndürmədən öncə Android\'in USB yaddaşını kompüterdən demontaj etdiyinizə (çıxardığınıza) əmin olun."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB yaddaşı söndürmədən öncə Android\'in USB yaddaşını kompüterdən demontaj etdiyinizə (çıxardığınıza) əmin olun."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB yaddaşını söndür"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB yaddaşı söndürən zaman problem oldu. USB hostu demontaj etmənizi yoxlayın və yenidən cəhd edin."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB yaddaşı aktivləşdirin"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"USB yaddaşı aktivləşdirsəniz, istifadə etdiyiniz bəzi tətbiqlər dayana bilər və USB yaddaş deaktiv edilənə qədər işləməyə bilər."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB əməliyyatı uğursuzdur"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"OK"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"Media cihazı kimi qoşuldu"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"Kamera kimi bağlanıldı"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"Quraşdırıcı kimi qoşulub"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB aksesuara qoşuldu"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"Digər USB seçimləri üçün toxunun."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB yaddaşına format atılsın?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD kart format edilsin?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"USB yaddaşınızda yerləşdirilmiş bütün fayllar silinəcək. Bu addım geri dönülməzdir."</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"Kartınızdakı bütün məlumatlar itəcək."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"Format"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB sazlama qoşuludur"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB debaqı deaktivasiya etmək üçün toxunun."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"Daxiletmə metodunu seçin"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"Daxiletmə üsullarını ayarlayın"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"Fiziki klaviatura"</string>
-    <string name="hardware" msgid="7517821086888990278">"Hardware"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"Klaviatura sxemi seçin"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"Klaviatura tərtibatı seçmək üçün toxunun."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCÇDEƏFGĞHXIİJKQLMNOÖPRSŞTUÜVYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCÇDEƏFGĞHİIJKLMNOÖPQRSŞTUÜVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"namizədlər"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB yaddaş hazırlanır"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD kart hazırlanır"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"Səhvlər yoxlanılır."</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"Boş USB yaddaşı"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"Boş SD kart"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB yaddaş boşdur və ya sistem tərəfindən dəstəklənməyən fayl sisteminə malikdir."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD kart boşdur və ya sistem tərəfindən dəstəklənməyən fayl sisteminə malikdir."</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"Zədəli USB yaddaş"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"Zədəli SD kart"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"SD yaddaş zədələnib. Onu format etməyə çalışın."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD kart zədələnib. Onu format etməyə çalışın."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB yaddaşı gözlənilmədən çıxarıldı"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD kart gözlənilmədən çıxarıldı"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"Məlumat itkisinin qarşısını almaq üçün USB yaddaşı çıxarmazdan əvvəl onu demontaj edin."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"Data itkisinin qarşısını almaq üçün SD kartı çıxarmadan öncə demontaj edin."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB yaddaş çıxarmaq üçün təhlükəsizdir"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD kart təhlükəsiz çıxarıla bilər"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"Siz USB yaddaşı təhlükəsiz çıxara bilərsiniz."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"Siz SD kartı təhlükəsiz çıxara bilərsiniz."</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"Silinmiş USB yaddaş"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"SD kart çıxarıldı"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB yaddaş çıxarıldı. Yeni media əlavə edin."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD kart çıxarıldı. Yenisini daxil edin."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"Uyğun gələn fəaliyyət tapılmadı."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"komponent istifadəsi statistikasını güncəlləyir"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"Tətbiqə toplanmış istifadə statistikasını dəyişməyə imkan verir. Normal tətbiqlər tərəfindən istifadə olunmur."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"məzmunu kopyala"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"Tətbiqə kontenti kopyalamaq üçün defolt konteyner servisini çağırmaq icazəsi verir. Normal tətbiqlər tərəfindən istifadə edilmir."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"Media çıxışını yönləndirir"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"Tətbiqə media çıxışını digər xarici cihazlara yönləndirmək imkanı verir."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"Keyguard təhlükəsiz yaddaşa çıxış"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"Tətbiqə keguard təhlükəsiz yaddaşa çatmağa icazə verir."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"Klaviatura kilidinin görülməsini və gizlədilməsini idarə edir"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"Tətbiqə keguardı idarə etmək icazəsi verir."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"Zoom nəzarəti üçün iki dəfə toxunun"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"Widget əlavə edilə bilmədi."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"Get"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"Axtar"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"Göndər"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"Növbəti"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"Tamam"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"Əvvəlki"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"İcra edin"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"<xliff:g id="NUMBER">%s</xliff:g> istifadə etməklə\nnömrə yığın"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"<xliff:g id="NUMBER">%s</xliff:g>istifadə edərək kontakt yaradın\n"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"Aşağıdakı bir və ya daha çox tətbiqlər indi və gələcəkdə hesabınıza daxil olmaq üçün icazə istəyir."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"Bu istəyə izn vermək istəyirsiniz?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"Giriş sorğusu"</string>
-    <string name="allow" msgid="7225948811296386551">"İcazə verin"</string>
-    <string name="deny" msgid="2081879885755434506">"Rədd et"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"İcazə tələb olunur"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">\n" hesabı üçün<xliff:g id="ACCOUNT">%s</xliff:g> icazə sorğusu göndərildi."</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"Daxiletmə metodu"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"Sinxronizasiya"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"Əlçatımlılıq"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"Divar kağızı"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"Divar kağızını dəyişin"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"Bildiriş dinləyən"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN aktivləşdirildi"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN <xliff:g id="APP">%s</xliff:g> tərəfindən aktivləşdirilib"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"Şəbəkəni idarə etmək üçün toxunun."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g> sessiyaya qoşuludur. Şəbəkəni idarə etmək üçün toxunun."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"Həmişə aktiv VPN bağlanır..."</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"VPN bağlantısı həmişə aktiv"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"Həmişə aktiv VPN xətası"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"Konfiqurə etmək üçün toxun"</string>
-    <string name="upload_file" msgid="2897957172366730416">"Fayl seçin"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"Heç bir fayl seçilməyib"</string>
-    <string name="reset" msgid="2448168080964209908">"Sıfırlayın"</string>
-    <string name="submit" msgid="1602335572089911941">"Göndər"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"Avtomobil rejimi aktivdir"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"Avtomobil rejimindən çıxmaq üçün toxunun."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"Tezerinq və ya hotspot aktivdir"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"Quraşdırmaq üçün toxunun."</string>
-    <string name="back_button_label" msgid="2300470004503343439">"Geri"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"Növbəti"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"Keç"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"Yüksək mobil data istifadəsi"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"Mobil data istifadəsi haqqında daha çox öyrənmək üçün toxunun."</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"Mobil data limiti keçildi"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"Mobil data istifadəsi haqqında daha çox öyrənmək üçün toxunun."</string>
-    <string name="no_matches" msgid="8129421908915840737">"Uyğunluq yoxdur"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"Səhifədə tap"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"1 uyğunluq"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="INDEX">%d</xliff:g> ədəddən <xliff:g id="TOTAL">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"Hazırdır"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB yaddaşı qaldırılır..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD kart demontaj edilir..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB yaddaş silinir..."</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD kart silinir..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB yaddaşı silinə bilmədi."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD kartı silmək mümkün olmadı."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD kart demontaj edilmədən öncə çıxarıldı."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB yaddaş hazırda yoxlanılır."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD kart hazırda yoxlanılır."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD kart çıxarılıb."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"SD kart hazırda kompüter tərəfindən istifadə edilir."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD kart hal-hazırda kompüter tərəfindən istifadə edilir."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"Naməlum vəziyyətdə xarici media."</string>
-    <string name="share" msgid="1778686618230011964">"Paylaşın"</string>
-    <string name="find" msgid="4808270900322985960">"Tapın"</string>
-    <string name="websearch" msgid="4337157977400211589">"Veb Axtarış"</string>
-    <string name="find_next" msgid="5742124618942193978">"Sonrakını tap"</string>
-    <string name="find_previous" msgid="2196723669388360506">"Əvvəlkini tap"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> tərəfindən məkan sorğusu"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"Məkan sorğusu"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) tərəfindən tələb edilib"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"Bəli"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"Xeyr"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"Limiti keçəni silin"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g> üçün <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> silinmiş fayl var, <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g> hesabı. Nə etmək istəyirsiniz?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"Elementləri sil"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"Silinənləri geri qaytar"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"İndilik heç nə etmə"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"Hesab seçin"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"Hesab əlavə et"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"Hesab əlavə edin"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"Artır"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"Azaldın"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> toxunun və basaraq saxlayın."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"Artırmaq üçün yuxarı, azaltmaq üçün aşağı sürüşdürün."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"Dəqiqə artırın"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"Dəqiqəni azalt"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"Saatı artırın"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"Saatı azaldın"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"PM qurun"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"AM qurun"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"Artma ayı"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"Ayı azaldın"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"Artma günü"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"Azalma günü"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"Artım ili"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"Azalma ili"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Ləğv et"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Sil"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Hazırdır"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Rejim dəyişikliyi"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Daxil olun"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"Tətbiq seçin"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"Bununla paylaşın"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g> ilə paylaşın"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"Sürüşən qulp. Toxunaraq basılı tutun."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün yuxarı sürüşdürün."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün aşağı sürüşdürün."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün sola sürüşdür."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> üçün sağa sürüşdür."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Kilidi aç"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Kamera"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Səssiz"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Səs açıqdır"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Axtar"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"Kilidi açmaq üçün vurun."</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"Parolların səsləndirilməsi üçün qulaqlıqları taxın."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"Nöqtə."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"Evə gedin"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"Yuxarı gedin"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"Əlavə seçimlər"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"Daxili yaddaş"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD kart"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB yaddaş"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"Redaktə et"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"Data istifadə xəbərdarlığı"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"İstifadə və ayarları görmək üçün toxunun"</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G data deaktivdir"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G data deaktiv edildi"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"Mobil data deaktivdir"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi-Fi data deaktiv edildi"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"Aktivləşdirmək üçün toxunun."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G data limiti aşılıb"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G data limiti keçildi"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"Mobil data limiti keçildi"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi-Fi data limiti keçildi"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> müəyyən edilmiş limit aşır."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"Arxaplan datası məhdudlaşdırıldı"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"Məhdudiyyəti aradan qaldırmaq üçün toxunun"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"Təhlükəsizlik sertifikatı"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"Bu sertifikat etibarlıdır."</string>
-    <string name="issued_to" msgid="454239480274921032">"Verilib:"</string>
-    <string name="common_name" msgid="2233209299434172646">"Ümumi ad:"</string>
-    <string name="org_name" msgid="6973561190762085236">"Təşkilat:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"Təşkilati vahid:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"Tərəfindən verilib:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"Keçərlilik:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"Dərc olunub:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"Bitmə vaxtı:"</string>
-    <string name="serial_number" msgid="758814067660862493">"Seriya nömrəsi:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"Barmaq izləri:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 barmaq izi:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 barmaq izi:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"Hamısını seçın"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"Fəaliyyəti seçin"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"Bununla paylaşın"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"Cihaz kilidləndi."</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"Göndərilir..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"Brauzer işə salınsın?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"Zəngi qəbul edək?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"Həmişə"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"Sadəcə bir dəfə"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"Planşet"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"Telefon"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"Qulaqlıq"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"Dok spikerlər"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"Sistem"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"Bluetooth audio"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"Simsiz ekran"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"Hazırdır"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"Media çıxışı"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"Skan edilir..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"Qoşulur..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"Əlçatımlı"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"Əlçatımlı deyil"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"İstifadə olunur"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"Daxili ekran"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI Ekran"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"Örtük #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", təhlükəsiz"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"Simsiz ekran qoşulub"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"Bu ekran digər cihazda göstərir"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"Bağlantını kəsin"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Təcili zəng"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Şablonu unutmuşam"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Yanlış Model"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Yanlış Şifrə"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN səhvdir"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%1$d</xliff:g> saniyə sonra yenidən cəhd edin."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Şablonunuzu çəkin"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN kodu daxil edin"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PİN kodu daxil edin"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Parol daxil edin"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM indi deaktivdir. Davam etmək üçün PUK kodu daxil edin. Əlavə məlumat üçün operatora müraciət edin."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"İstədiyiniz PİN kodu daxil edin"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"İstədiyiniz PIN kodu təsdiqləyin"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SİM kartın kilidi açılır..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Yanlış PİN kod."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"4-dən 8-ə qədər rəqəmi olan PIN yazın."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK kod 8 rəqəm və ya daha çox olmalıdır."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Düzgün PUK kodu yenidən daxil edin. Təkrarlanan cəhdlər SIM\'i birdəfəlik sıradan çıxaracaq."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN kodları uyğun deyil"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Həddindən çox cəhd edildi!"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Kilidi açmaq üçün Google hesabınız ilə daxil olun."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"İstifadəçi adı (e-poçt)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Şifrə"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Daxil ol"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Yanlış istifadəçi adı və ya parol."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"İstifadəçi adınızı və ya parolunuzu unutmusunuz?\n "<b>"google.com/accounts/recovery"</b>" linkinə daxil olun."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Hesab yoxlanılır..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"PIN kodunuzu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz.\n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Şifrənizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etdiniz. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Modelinizi <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış çəkmisiniz.\n\n <xliff:g id="NUMBER_1">%d</xliff:g> saniyə ərzində yenidən yoxlayın"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Siz planşet kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, planşet fabrik ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Siz telefon kilidini açmaq üçün <xliff:g id="NUMBER_0">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. <xliff:g id="NUMBER_1">%d</xliff:g> dəfə də uğursuz cəhd etsəniz, telefon fabrik ayarlarına sıfırlanacaq və bütün məlumatlarınız itəcək."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Siz planşet kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> dəfə uğursuz cəhd etmisiniz. Planşet fabrik ayarlarına sıfırlanacaq."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Siz telefonun kilidini açmaq üçün <xliff:g id="NUMBER">%d</xliff:g> yanlış cəhd etmisiniz. Telefon artıq defolt zavod halına sıfırlanacaq."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Siz kilidi açmaq üçün şablonu <xliff:g id="NUMBER_0">%d</xliff:g> dəfə səhv çəkdiniz. <xliff:g id="NUMBER_1">%d</xliff:g> daha uğursuz cəhddən sonra planşetinizin kilidini e-poçt hesabınızla açmaq tələb olunacaq.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində bir daha yoxlayın."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Siz artıq modeli <xliff:g id="NUMBER_0">%d</xliff:g> dəfə yanlış daxil etmisiniz.<xliff:g id="NUMBER_1">%d</xliff:g> dəfə də yanlış daxil etsəniz, telefonun kilidinin açılması üçün elektron poçt ünvanınız tələb olunacaq.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> saniyə ərzində yenidən cəhd edin."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" - "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Yığışdır"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"Səs gücü tövsiyə edilən səviyyədən artırılsın?\nUzun müddət yüksək səs gücü ilə dinləmə Sizin eşitmə qabiliyyətinizə mənfi təsir edə bilər."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"Əlçatımlığı aktivləşdirmək üçün iki barmağınızı basılı saxlayın."</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"Əlçatımlılıq aktivləşdirildi"</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"Giriş imkanı ləğv edilib."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Cari istifadəçi <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="owner_name" msgid="2716755460376028154">"Sahib"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"Xəta"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"Bu tətbiq məhdud profillər üçün hesabları dəstəkləmir."</string>
-    <string name="app_not_found" msgid="3429141853498927379">"Bu əməliyyatı idarə etmək üçün heç bir tətbiq tapılmadı."</string>
-    <string name="revoke" msgid="5404479185228271586">"Ləğv edin"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"B4 ISO"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"Məktub"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"Hökumət Məktubu"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"Hüquqi"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Kiçik Hüquq"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Qovluq"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Qısa"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"Ləğv edildi"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"Kontent yazmna xətası"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN daxil edin"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"Cari PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"Yeni PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"Yeni PIN\'i təsdiq edin"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"Dəyişmə məhdudiyyətləri üçün PİN yaradın"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PİN uyğun gəlmir. Yenidən cəhd edin."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PİN çox qısadır. Ən azı 4 rəqəm olmalıdır."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"Yanlış PİN. 1 saniyə sonra təkrar sınayın."</item>
-    <item quantity="other" msgid="8030607343223287654">"Yanlış PİN. <xliff:g id="COUNT">%d</xliff:g> saniyə sonra təkrar sınayın."</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Paneli göstərmək üçün ekranın küncünü sürüşdürün"</string>
-</resources>
diff --git a/core/res/res/values-be/strings.xml b/core/res/res/values-be/strings.xml
index e7e52e4..ccc2986 100644
--- a/core/res/res/values-be/strings.xml
+++ b/core/res/res/values-be/strings.xml
@@ -1795,6 +1795,7 @@
     <!-- no translation found for restr_pin_countdown:other (4730868920742952817) -->
     <!-- no translation found for restr_pin_try_later (973144472490532377) -->
     <skip />
+    <!-- no translation found for immersive_mode_confirmation (7227416894979047467) -->
     <!-- no translation found for immersive_mode_confirmation (8554991488096662508) -->
     <skip />
 </resources>
diff --git a/core/res/res/values-bg/strings.xml b/core/res/res/values-bg/strings.xml
index e9f0d78..99ba922 100644
--- a/core/res/res/values-bg/strings.xml
+++ b/core/res/res/values-bg/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Опитайте отново след <xliff:g id="COUNT">%d</xliff:g> секунди"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Опитайте отново по-късно"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"За изх. от цял екр. прeк. пръст отгоре надолу"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"За изход от цял екран прекарайте пръст отгоре надолу."</string>
 </resources>
diff --git a/core/res/res/values-ca/strings.xml b/core/res/res/values-ca/strings.xml
index 3bf7b2f..8b46e84 100644
--- a/core/res/res/values-ca/strings.xml
+++ b/core/res/res/values-ca/strings.xml
@@ -440,7 +440,7 @@
     <string name="permlab_readContacts" msgid="8348481131899886131">"lectura dels contactes"</string>
     <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"Permet que l\'aplicació llegeixi dades sobre els contactes que tinguis emmagatzemats a la tauleta, inclosa la freqüència amb què has trucat, has enviat correus electrònics o t\'has comunicat d\'altres maneres amb persones concretes. Aquest permís permet que les aplicacions desin les dades dels teus contactes, i és possible que les aplicacions malicioses comparteixin dades dels contactes sense el teu coneixement."</string>
     <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"Permet que l\'aplicació llegeixi dades sobre els contactes que tinguis emmagatzemats al telèfon, inclosa la freqüència amb què has trucat, has enviat correus electrònics o t\'has comunicat d\'altres maneres amb persones concretes. Aquest permís permet que les aplicacions desin les dades dels teus contactes, i és possible que les aplicacions malicioses comparteixin dades dels contactes sense el teu coneixement."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"modificació dels contactes"</string>
+    <string name="permlab_writeContacts" msgid="5107492086416793544">"modificar els teus contactes"</string>
     <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"Permet que l\'aplicació modifiqui les dades sobre contactes emmagatzemades a la tauleta, inclosa la freqüència amb què has trucat, has enviat correus electrònics o t\'has comunicat d\'altres maneres amb contactes concrets. Aquest permís permet que les aplicacions suprimeixin dades de contactes."</string>
     <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"Permet que l\'aplicació modifiqui les dades sobre contactes emmagatzemades al telèfon, inclosa la freqüència amb què has trucat, has enviat correus electrònics o t\'has comunicat d\'altres maneres amb contactes concrets. Aquest permís permet que les aplicacions suprimeixin dades de contactes."</string>
     <string name="permlab_readCallLog" msgid="3478133184624102739">"lectura del registre de trucades"</string>
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Torna-ho a provar d\'aquí a <xliff:g id="COUNT">%d</xliff:g> segons"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Torna-ho a provar més tard"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Fes llis. dit avall per sortir de pant. comp."</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Fes lliscar el dit cap avall per sortir de la pantalla completa."</string>
 </resources>
diff --git a/core/res/res/values-cs/strings.xml b/core/res/res/values-cs/strings.xml
index b52fd91..73ca02b 100644
--- a/core/res/res/values-cs/strings.xml
+++ b/core/res/res/values-cs/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Zkuste to znovu za <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Zkuste to znovu později"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Režim celé obrazovky ukončíte přejetím dolů"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Režim celé obrazovky ukončíte přejetím dolů."</string>
 </resources>
diff --git a/core/res/res/values-da/strings.xml b/core/res/res/values-da/strings.xml
index 72d31e2..0cf5bc5 100644
--- a/core/res/res/values-da/strings.xml
+++ b/core/res/res/values-da/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Prøv igen om <xliff:g id="COUNT">%d</xliff:g> sekunder"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Prøv igen senere"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Stryg ned fra toppen for at stoppe fuld skærm"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Stryg ned fra toppen for at afslutte fuld skærm"</string>
 </resources>
diff --git a/core/res/res/values-de/strings.xml b/core/res/res/values-de/strings.xml
index 7503e83..f799be4 100644
--- a/core/res/res/values-de/strings.xml
+++ b/core/res/res/values-de/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"In <xliff:g id="COUNT">%d</xliff:g> Sek. wiederholen"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Später erneut versuchen"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Zum Schließen des Vollbilds von oben nach unten wischen"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Zum Schließen des Vollbilds von oben nach unten wischen"</string>
 </resources>
diff --git a/core/res/res/values-el/strings.xml b/core/res/res/values-el/strings.xml
index 40efe0a..605d845 100644
--- a/core/res/res/values-el/strings.xml
+++ b/core/res/res/values-el/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Επανάληψη σε <xliff:g id="COUNT">%d</xliff:g> δευτ."</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Δοκιμάστε ξανά αργότερα"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Σάρωση προς τα κάτω για έξοδο από πλήρη οθόνη"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Σάρωση προς τα κάτω για έξοδο από πλήρη οθόνη"</string>
 </resources>
diff --git a/core/res/res/values-en-rGB/strings.xml b/core/res/res/values-en-rGB/strings.xml
index ecafaaf..ca8509a 100644
--- a/core/res/res/values-en-rGB/strings.xml
+++ b/core/res/res/values-en-rGB/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Try again in <xliff:g id="COUNT">%d</xliff:g> seconds"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Try again later"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Swipe down from the top to exit full screen"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Swipe down from the top to exit full screen."</string>
 </resources>
diff --git a/core/res/res/values-en-rIN/strings.xml b/core/res/res/values-en-rIN/strings.xml
index ecafaaf..ca8509a 100644
--- a/core/res/res/values-en-rIN/strings.xml
+++ b/core/res/res/values-en-rIN/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Try again in <xliff:g id="COUNT">%d</xliff:g> seconds"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Try again later"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Swipe down from the top to exit full screen"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Swipe down from the top to exit full screen."</string>
 </resources>
diff --git a/core/res/res/values-es-rUS/strings.xml b/core/res/res/values-es-rUS/strings.xml
index e9d23ab..eb731a3 100644
--- a/core/res/res/values-es-rUS/strings.xml
+++ b/core/res/res/values-es-rUS/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Intentar en <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Vuelve a intentar más tarde."</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Salir de pantalla completa: deslizar abajo"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Salir de pantalla completa: deslizar abajo"</string>
 </resources>
diff --git a/core/res/res/values-es/strings.xml b/core/res/res/values-es/strings.xml
index bb3ae94..a89f35a 100644
--- a/core/res/res/values-es/strings.xml
+++ b/core/res/res/values-es/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Inténtalo en <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Volver a intentar más tarde"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Desliza hacia abajo para salir de la pantalla completa"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Desliza el dedo hacia abajo para salir de la pantalla completa"</string>
 </resources>
diff --git a/core/res/res/values-et-rEE/strings.xml b/core/res/res/values-et-rEE/strings.xml
index ccb12d1..742d3da 100644
--- a/core/res/res/values-et-rEE/strings.xml
+++ b/core/res/res/values-et-rEE/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Proovige uuesti <xliff:g id="COUNT">%d</xliff:g> sekundi pärast"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Proovige hiljem uuesti"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Täisekraani sulgemiseks pühkige ülevalt alla"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Täisekraani sulgemiseks pühkige ülevalt alla"</string>
 </resources>
diff --git a/core/res/res/values-et/strings.xml b/core/res/res/values-et/strings.xml
index ec0d930..71832c8 100644
--- a/core/res/res/values-et/strings.xml
+++ b/core/res/res/values-et/strings.xml
@@ -314,7 +314,7 @@
     <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"väldi rakenduste ümberlülitamist"</string>
     <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"Takistab kasutaja lülitumist teisele rakendusele."</string>
     <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"aktiivse rakenduse teabe hankimine"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"Lubab õiguse omanikul hankida privaatset teavet ekraani esiplaanil oleva aktiivse rakenduse ja teenuste kohta."</string>
+    <string name="permdesc_getTopActivityInfo" msgid="2512448855496067131">"Lubab õiguste saajal hankida privaatset teavet ekraanil esiplaanil oleva aktiivse rakenduse kohta."</string>
     <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"Kõigi rakenduste käivitumise jälgimine ja juhtimine"</string>
     <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"Võimaldab rakendusel jälgida ja juhtida, kuidas süsteem tegevusi käivitab. Pahatahtlikud rakendused võivad süsteemi täielikult rikkuda. Seda õigust on vaja ainult arenduseks, mitte tavakasutuse korral."</string>
     <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"saada paketist eemaldatud saade"</string>
@@ -363,7 +363,7 @@
     <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"juurdepääs kõikidele printimistöödele"</string>
     <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"Lubab omanikule juurdepääsu teise rakenduse loodud printimistöödele. Tavarakenduste puhul ei peaks seda kunagi vaja minema."</string>
     <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC-teenusega sidumine"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Lubab õiguste omajal luua seosed rakendustega, mis emuleerivad NFC-kaarte. Pole kunagi vajalik tavaliste rakenduste korral."</string>
+    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Lubab kasutajal luua seosed rakendustega, mis jäljendavad NFC-kaarte. Pole kunagi vajalik tavaliste rakenduste korral."</string>
     <string name="permlab_bindTextService" msgid="7358378401915287938">"tekstiteenusega sidumine"</string>
     <string name="permdesc_bindTextService" msgid="8151968910973998670">"Võimaldab omanikul siduda tekstiteenuse (nt SpellCheckerService) ülataseme liidesega. Tavarakenduste puhul ei peaks seda kunagi vaja minema."</string>
     <string name="permlab_bindVpnService" msgid="4708596021161473255">"seo VPN-teenusega"</string>
@@ -407,10 +407,6 @@
     <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"Võimaldab rakendusel lugeda süsteemi erinevaid logifaile. Nii on võimalik avastada üldist teavet selle kohta, mida te telefoniga teete, mis võib kaasata ka isiklikku või privaatset teavet."</string>
     <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"Mis tahes meediumidekooderi kasutamine taasesituseks"</string>
     <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"Võimaldab rakendusel taasesituseks kasutada mis tahes installitud meediumidekooderit."</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
     <string name="permlab_diagnostic" msgid="8076743953908000342">"loe/kirjuta valija allikaid"</string>
     <string name="permdesc_diagnostic" msgid="6608295692002452283">"Võimaldab rakendusel lugeda valimisrühma mis tahes ressurssi ja sellesse kirjutada (näiteks kaustas /dev olevad failid). See võib mõjutada süsteemi stabiilsust ja turvet. Seda tohiks kasutada tootja või operaator AINULT riistvaraspetsiifiliseks diagnostikaks."</string>
     <string name="permlab_changeComponentState" msgid="6335576775711095931">"Rakenduse komponentide lubamine või keelamine"</string>
@@ -476,14 +472,18 @@
     <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"Lubab rakendusel kasutada InputFlingeri madalatasemelisi funktsioone."</string>
     <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"WiFi-ekraanide seadistamine"</string>
     <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"Lubab rakendusel seadistada WiFi-ekraane ja nendega ühendus luua."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"WiFi-ekraanide juhtimine"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Lubab rakendusel juhtida WiFi-ekraanide madala taseme funktsioone."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"heliväljundi jäädvustamine"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"Lubab rakendusel jäädvustada ja ümber suunata heliväljundit."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"videoväljundi jäädvustamine"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"Lubab rakendusel jäädvustada ja ümber suunata videoväljundit."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"kaitstud videoväljundi jäädvustamine"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"Lubab rakendusel jäädvustada ja ümber suunata kaitstud videoväljundit."</string>
+    <!-- no translation found for permlab_captureAudioOutput (6857134498402346708) -->
+    <skip />
+    <!-- no translation found for permdesc_captureAudioOutput (6210597754212208853) -->
+    <skip />
+    <!-- no translation found for permlab_captureVideoOutput (2246828773589094023) -->
+    <skip />
+    <!-- no translation found for permdesc_captureVideoOutput (359481658034149860) -->
+    <skip />
+    <!-- no translation found for permlab_captureSecureVideoOutput (7815398969303382016) -->
+    <skip />
+    <!-- no translation found for permdesc_captureSecureVideoOutput (2779793064709350289) -->
+    <skip />
     <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"muuda heliseadeid"</string>
     <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"Võimaldab rakendusel muuta üldiseid heliseadeid, näiteks helitugevust ja seda, millist kõlarit kasutatakse väljundiks."</string>
     <string name="permlab_recordAudio" msgid="3876049771427466323">"salvesta heli"</string>
@@ -657,8 +657,6 @@
     <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"Võimaldab omanikul siduda märguannete kuulamisteenuse ülemise taseme kasutajaliidese. Seda ei tohiks tavarakenduste puhul kunagi vaja olla."</string>
     <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"operaatoripoolse konfiguratsioonirakenduse aktiveerimine"</string>
     <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"Lubab omanikul aktiveerida operaatoripoolse konfiguratsioonirakenduse. Tavarakenduste puhul ei peaks seda kunagi vaja minema."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"võrgutingimuste teabe kuulamine"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"Lubab rakendusel kuulata võrgutingimuste teavet. Ei ole kunagi vajalik tavaliste rakenduste puhul."</string>
     <string name="policylab_limitPassword" msgid="4497420728857585791">"Parooli reeglite määramine"</string>
     <string name="policydesc_limitPassword" msgid="3252114203919510394">"Kontrollige ekraaniluku avamise paroolide pikkust ja tähemärke."</string>
     <string name="policylab_watchLogin" msgid="914130646942199503">"Ekraani avamiskatsed"</string>
@@ -1583,5 +1581,4 @@
     <item quantity="one" msgid="4835639969503729874">"Vale PIN-kood. Proovige 1 s pärast."</item>
     <item quantity="other" msgid="8030607343223287654">"Vale PIN-kood. Proovige <xliff:g id="COUNT">%d</xliff:g> s pärast."</item>
   </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Riba kuvam. pühkige ekraani serva"</string>
 </resources>
diff --git a/core/res/res/values-fa/strings.xml b/core/res/res/values-fa/strings.xml
index f57ef46..92d687f 100644
--- a/core/res/res/values-fa/strings.xml
+++ b/core/res/res/values-fa/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"امتحان پس از <xliff:g id="COUNT">%d</xliff:g> ثانیه"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"بعداً دوباره امتحان کنید"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"برای خروج از تمام صفحه از بالا به پایین بکشید"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"برای خروج از تمام صفحه از بالا به پایین بکشید"</string>
 </resources>
diff --git a/core/res/res/values-fi/strings.xml b/core/res/res/values-fi/strings.xml
index 40d4bdf..3130cba 100644
--- a/core/res/res/values-fi/strings.xml
+++ b/core/res/res/values-fi/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Yritä uud. <xliff:g id="COUNT">%d</xliff:g> s kul."</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Yritä myöhemmin uudelleen"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Poistu koko näytön tilasta liu\'uttamalla alas"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Poistu koko näytön tilasta liu\'uttamalla alas."</string>
 </resources>
diff --git a/core/res/res/values-fr-rCA/strings.xml b/core/res/res/values-fr-rCA/strings.xml
index 8a325ed..385ed4b 100644
--- a/core/res/res/values-fr-rCA/strings.xml
+++ b/core/res/res/values-fr-rCA/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Réessayer dans <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Réessayez plus tard"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Balayez vers le bas pour quitter plein écran"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Balayez vers le bas pour quitter plein écran"</string>
 </resources>
diff --git a/core/res/res/values-fr/strings.xml b/core/res/res/values-fr/strings.xml
index 4046d3d..9a44a31 100644
--- a/core/res/res/values-fr/strings.xml
+++ b/core/res/res/values-fr/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Réessayer dans <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Veuillez réessayer ultérieurement."</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Balayer vers le bas pour quitter le plein écran"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Balayer vers le bas pour quitter le plein écran"</string>
 </resources>
diff --git a/core/res/res/values-hi/strings.xml b/core/res/res/values-hi/strings.xml
index af2f2e3..73575bd 100644
--- a/core/res/res/values-hi/strings.xml
+++ b/core/res/res/values-hi/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> सेकंड में पुन: प्रयास करें"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"बाद में पुनः प्रयास करें"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"पूर्ण स्क्रीन से बाहर आने हेतु ऊपर से नीचे स्वाइप करें"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"पूर्ण स्क्रीन से बाहर आने के लिए ऊपर से नीचे स्वाइप करें."</string>
 </resources>
diff --git a/core/res/res/values-hr/strings.xml b/core/res/res/values-hr/strings.xml
index 198416b..37dc141 100644
--- a/core/res/res/values-hr/strings.xml
+++ b/core/res/res/values-hr/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Ponovite za <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Pokušajte ponovo kasnije"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Prijeđite prstom s vrha prema dolje za izlaz"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Prijeđite prstom s vrha prema dolje za izlaz iz cijelog zaslona."</string>
 </resources>
diff --git a/core/res/res/values-hu/strings.xml b/core/res/res/values-hu/strings.xml
index 89f8878..4ae5938 100644
--- a/core/res/res/values-hu/strings.xml
+++ b/core/res/res/values-hu/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Próbálja újra <xliff:g id="COUNT">%d</xliff:g> másodperc múlva"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Próbálkozzon később"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"A kilépéshez húzza ujját a tetejétől lefelé"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"A teljes képernyős nézetből való kilépéshez húzza ujját a tetejétől lefelé."</string>
 </resources>
diff --git a/core/res/res/values-hy-rAM/strings.xml b/core/res/res/values-hy-rAM/strings.xml
index 695ad0f..96ff31e 100644
--- a/core/res/res/values-hy-rAM/strings.xml
+++ b/core/res/res/values-hy-rAM/strings.xml
@@ -1114,7 +1114,7 @@
     <string name="loading" msgid="7933681260296021180">"Բեռնում..."</string>
     <string name="capital_on" msgid="1544682755514494298">"I"</string>
     <string name="capital_off" msgid="6815870386972805832">"O"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"ավարտել գործողությունը` օգտագործելով"</string>
+    <string name="whichApplication" msgid="4533185947064773386">"Ավարտել գործողությունը` օգտագործելով"</string>
     <string name="whichHomeApplication" msgid="4616420172727326782">"Ընտրեք հիմնական հավելվածը"</string>
     <string name="alwaysUse" msgid="4583018368000610438">"Օգտագործել լռելյայն այս գործողության համար:"</string>
     <string name="clearDefaultHintMsg" msgid="3252584689512077257">"Մաքրել լռելյայնը Համակարգի կարգավորումներ &gt; Ծրագրեր &gt;Ներբեռնված էջից:"</string>
@@ -1142,7 +1142,7 @@
     <string name="smv_application" msgid="3307209192155442829">"<xliff:g id="APPLICATION">%1$s</xliff:g> ծրագիրը (գործընթաց <xliff:g id="PROCESS">%2$s</xliff:g>) խախտել է իր ինքնահարկադրված Խիստ ռեժիմ  քաղաքականությունը:"</string>
     <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> գործընթացը խախտել է իր ինքնահարկադրված Խիստ ռեժիմ քաղաքականությունը:"</string>
     <string name="android_upgrading_title" msgid="1584192285441405746">"Android-ը նորացվում է..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"Հավելվածը օպտիմալացվում է <xliff:g id="NUMBER_0">%1$d</xliff:g>-ից <xliff:g id="NUMBER_1">%2$d</xliff:g>-ի:"</string>
+    <string name="android_upgrading_apk" msgid="7904042682111526169">"Օպտիմալացվում է հավելված <xliff:g id="NUMBER_0">%1$d</xliff:g>-ը <xliff:g id="NUMBER_1">%2$d</xliff:g>-ից:"</string>
     <string name="android_upgrading_starting_apps" msgid="451464516346926713">"Հավելվածները մեկնարկում են:"</string>
     <string name="android_upgrading_complete" msgid="1405954754112999229">"Բեռնումն ավարտվում է:"</string>
     <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g>-ն աշխատում է"</string>
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Կրկին փորձեք <xliff:g id="COUNT">%d</xliff:g> վայրկյանից"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Կրկին փորձեք մի փոքր ուշ"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Սահահարվածեք վերից վար՝ ամբողջական էկրանից դուրս գալու համար"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Սահահարվածեք վերից վար՝ ամբողջական էկրանից դուրս գալու համար:"</string>
 </resources>
diff --git a/core/res/res/values-hy/strings.xml b/core/res/res/values-hy/strings.xml
deleted file mode 100644
index 1b04923..0000000
--- a/core/res/res/values-hy/strings.xml
+++ /dev/null
@@ -1,1585 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"Բ"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"Կբ"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"Մբ"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"Գբ"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"Տբ"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"Պբ"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;Անանուն&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(Հեռախոսահամար չկա)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(Անհայտ)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"Ձայնային փոստ"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"Միացման խնդիր կամ անվավեր MMI ծածակագիր:"</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"Գործողությունը սահմանափակված է միայն ամրակայված հեռախոսահամարների համար:"</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"Ծառայությունը միացված է:"</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"Ծառայությունը միացված է`"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"Ծառայությունն անջատվել է:"</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"Գրանցումը հաջողված է:"</string>
-    <string name="serviceErased" msgid="1288584695297200972">"Ջնջումը հաջող էր:"</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"Սխալ գաղտնաբառ:"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI-ը ավարտված է:"</string>
-    <string name="badPin" msgid="9015277645546710014">"Ձեր մուտքագրած հին PIN-ը ճիշտ չէ:"</string>
-    <string name="badPuk" msgid="5487257647081132201">"Ձեր մուտքագրած PUK-ը ճիշտ չէ:"</string>
-    <string name="mismatchPin" msgid="609379054496863419">"Ձեր մուտքագրած PIN-երը չեն համընկնում:"</string>
-    <string name="invalidPin" msgid="3850018445187475377">"Մուտքագրեք PIN, որը 4-ից 8 թիվ է:"</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"Մուտքագրեք PUK, որն 8 կամ ավել թիվ ունի:"</string>
-    <string name="needPuk" msgid="919668385956251611">"Ձեր SIM քարտը PUK-ով կողպված է: Մուտքագրեք PUK կոդը այն ապակողպելու համար:"</string>
-    <string name="needPuk2" msgid="4526033371987193070">"Մուտքագրեք PUK2-ը` SIM քարտն արգելաբացելու համար:"</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"Մուտքային զանգողի ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"Ելքային զանգողի ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"Զանգի վերահասցեավորում"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"Զանգի սպասում"</string>
-    <string name="BaMmi" msgid="455193067926770581">"Զանգի արգելափակում"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"Գաղտնաբառի փոփոխում"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN-ի փոփոխություն"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"Զանգող համարը առկա է"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"Զանգող հեռախոսահամարը սահմանափակված է"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"Երեք կողմով զանգ"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"Անցանկալի վրդովեցնող զանգերի մերժում"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"Զանգող համարի առաքում"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"Չխանգարել"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"Զանգողի ID-ն լռելյայն սահմանափակված է: Հաջորդ զանգը` սահմանափակված"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"Զանգողի ID-ն լռելյայն սահմանափակված է: Հաջորդ զանգը` չսահմանափակված"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"Զանգողի ID-ն լռելյայն չսահմանափակված է: Հաջորդ զանգը` Սահմանափակված"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"Զանգողի ID-ն լռելյայն չսահմանափակված է: Հաջորդ զանգը` չսահմանափակված"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"Ծառայությունը չի տրամադրվում:"</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"Դուք չեք կարող փոխել զանգողի ID-ի կարգավորումները:"</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"Սահմանափակված մուտքը փոխված է"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"Տվյալների ծառայությունն արգելափակված է:"</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"Արտակարգ իրավիճակի ծառայությունն արգելափակված է:"</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"Ձայնային ծառայությունը արգելափակված է:"</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"Բոլոր ձայնային ծառայությունները արգելափակված են:"</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS ծառայությունն արգելափակված է:"</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"Ձայնային կամ տվյալների ծառայություններն արգելափակված են:"</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"Ձայնային/SMS ծառայությունները արգելափակված են:"</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"Բոլոր ձայնային/տվյալների/SMS ծառայությունները արգելափակված են:"</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"Ձայնային"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"Տվյալներ"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"Ֆաքս"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"Չհամաժամեցված"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"Համաժամել"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"Փաթեթ"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"Հարթակ"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"Ռոումինգի ցուցիչը միացված է"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"Ռոումինգի ցուցիչը անջատված է"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"Ռոումինգի ցուցիչը թարթում է"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"Շրջակայքից դուրս"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"Շենքից դուրս"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"Ռոումինգ` նախընտրելի համակարգ"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"Ռոումինգ` հասանելի համակարգ"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"Ռոումինգ` դաշնային գործընկեր"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"Ռոումինգ` առաջնակարգ գործընկեր"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"Ռոումինգ` լիարժեք ծառայության գործառություն"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"Ռոումինգ` Մասնակի ծառայության գործառություն"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"Ռոումինգի ազդերիզը միացված է"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"Ռոումինգի ազդերիզն անջատված է"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"Ծառայության որոնում..."</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>. Չի վերահասցեավորվել"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>. <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>. <xliff:g id="DIALING_NUMBER">{1}</xliff:g> <xliff:g id="TIME_DELAY">{2}</xliff:g> վայրկյանից"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>. Չի վերահասցեավորվել"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>. Չի վերահասցեավորվել"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"Հատկության կոդը ամբողջական է:"</string>
-    <string name="fcError" msgid="3327560126588500777">"Կապի խնդիր կամ անվավեր գործառույթի կոդ:"</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"Լավ"</string>
-    <string name="httpError" msgid="7956392511146698522">"Ցանցային սխալ էր տեղի ունեցել:"</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL-ը չհաջողվեց գտնել:"</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"Կայքի նույնականացման սխեման չի աջակցվում:"</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"Չհաջողվեց նույնականացնել:"</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"Նույնականացումը պրոքսի սերվերի միջոցով անհաջող էր:"</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"Չհաջողվեց միանալ սերվերին:"</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"Կապը սերվերի հետ չհաջողվեց: Փորձեք կրկին ավելի ուշ:"</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"Սերվերի հետ կապակցման ժամանակը սպառվել է:"</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"Էջը պարունակում է չափազանց շատ սերվերի վերահղում:"</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"Պրոտոկոլը չի աջակցվում:"</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"Չհաջողվեց հաստատել ապահով կապ:"</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"Չհաջողվեց բացել էջը, որովհետև URL-ը անվավեր է:"</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"Չհաջողվեց մուտք գործել ֆայլ:"</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"Չհաջողվեց գտնել հարցվող ֆայլը:"</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Չափից շատ հարցումներ են մշակվում: Փորձեք կրկին ավելի ուշ:"</string>
-    <string name="notification_title" msgid="8967710025036163822">"Մուտք գործելու սխալ` <xliff:g id="ACCOUNT">%1$s</xliff:g>-ի համար"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"Համաժամեցնել"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"Համաժամել"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"Չափից շատ <xliff:g id="CONTENT_TYPE">%s</xliff:g> հեռացումներ:"</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"Գրասալիկի պահոցը լիքն է: Ջնջեք մի քանի ֆայլ` տարածք ազատելու համար:"</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"Հեռախոսի պահոցը լիքն է: Ջնջեք մի քանի ֆայլեր` տարածություն ազատելու համար:"</string>
-    <string name="me" msgid="6545696007631404292">"Իմ"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"Գրասալիկի ընտրանքները"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"Հեռախոսի ընտրանքներ"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"Անձայն ռեժիմ"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"Միացնել անլար"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"Անլարը անջատել"</string>
-    <string name="screen_lock" msgid="799094655496098153">"էկրանի կողպեք"</string>
-    <string name="power_off" msgid="4266614107412865048">"Անջատել"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"Զանգակն անջատված է"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"Զանգակի թրթռոց"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"Զանգակը միացված է"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"Անջատվում է…"</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"Ձեր գրասալիկը կանջատվի:"</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"Ձեր հեռախոսը կանջատվի:"</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"Ցանկանու՞մ եք անջատել:"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"Վերաբեռնել անվտանգ ռեժիմի"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"Ցանկանու՞մ եք վերաբեռնել անվտանգ ռեժիմի: Սա կկասեցնի ձեր տեղադրած բոլոր կողմնակի ծրագրերը: Դրանք կվերականգնվեն, երբ դուք կրկին վերաբեռնեք:"</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"Վերջին"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"Նոր հավելվածեր չկան:"</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"Գրասալիկի ընտրանքները"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"Հեռախոսի ընտրանքներ"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"Էկրանի փական"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"Անջատել"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"Վրիպակի զեկույց"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"Գրել սխալի զեկույց"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"Սա տեղեկություններ կհավաքագրի ձեր սարքի առկա կարգավիճակի մասին և կուղարկի այն էլեկտրոնային նամակով: Որոշակի ժամանակ կպահանջվի վրիպակի մասին զեկուցելու պահից սկսած մինչ ուղարկելը: Խնդրում ենք փոքր-ինչ համբերատար լինել:"</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"Անձայն ռեժիմ"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"Ձայնը անջատված է"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"Ձայնը միացված է"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"Ինքնաթիռային ռեժիմը միացված է"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"Ինքնաթիռային ռեժիմը անջատված է"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"Անվտանգ ռեժիմ"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Android համակարգ"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"Ծառայություններ, որոնց համար կգանձվեք"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"Կատարել գործողություններ, որի դիմաց ձեր հաշվից գումար կծախսվի:"</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"Ձեր հաղորդագրությունները"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"Կարդալ և գրել ձեր SMS-ը, նամակը և այլ հաղորդագրություններ:"</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"Ձեր անձնական տեղեկությունները"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"Ուղղակի մուտք ձեր մասին տեղեկություններ` պահված ձեր կոնտակտային քարտում:"</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"Ձեր սոցիալական տեղեկությունները"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"Ուղղակի մուտք ձեր կոնտակտների մասին տեղեկություններ և սոցիալական կապեր:"</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"Ձեր տեղադրությունը"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"Վերահսկել ձեր ֆիզիկական տեղադրությունը:"</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"Ցանցային հաղորդակցություն"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"Մուտք գործել ցանցի տարբեր գործառույթներ:"</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"Bluetooth"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"Մուտք գործել սարքեր և ցանցեր Bluetooth-ի միջոցով:"</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"Ձայնանյութի կարգավորումներ"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"Փոխել ձայնանյութի կարգավորումները:"</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"Ազդում է մարտկոցի վրա"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"Օգտագործել գործիքները, որոնք կարող են արագ սպառել մարտկոցը:"</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"Օրացույց"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"Անմիջական մուտք օրացույց և իրադարձություններ:"</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"Կարդալ օգտվողի բառարանը"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"Կարդալ բառերը օգտվողի բառարանում:"</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"Գրել օգտվողի բառարանում"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"Ավելացնել բառեր օգտվողի բառարանում:"</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"Էջանիշեր և պատմություն"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"Ուղղակի մուտք դեպի էջանիշեր և դիտարկչի պատմություն:"</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"Ազդանշան"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"Կարգավորել զարթուցիչի ժամացույցը:"</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"Ձայնային փոստ"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"Ուղղակի մուտք դեպի ձայնային փոստ:"</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"Բարձրախոս"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"Ուղղակի մուտք դեպի բարձրախոս` ձայնանյութ ձայնագրելու համար:"</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"Ֆոտոխցիկ"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"Ուղղակի մուտք դեպի ֆոտոխցիկ` լուսանկարելու կամ տեսանկարելու համար:"</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"Կողպել էկրանը"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"Հնարավորություն ունի ազդելու ձեր սարքի կողպէկրանի ռեժիմի վրա:"</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"Ձեր հավելվածների տեղեկությունները"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"Հնարավորություն` ազդելու մյուս հավելվածների վարքագծի վրա ձեր սարքում:"</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"Պաստառ"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"Փոխել սարքի պաստառի կարգավորումները:"</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"Ժամացույց"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"Փոխել սարքի ժամը կամ ժամային գոտին:"</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"Կարգավիճակի գոտի"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"Փոխել սարքի կարգավիճակի գոտու կարգավորումները:"</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"Համաժամեցման կարգավորումներ"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"Մուտք գործել համաժամեցման կարգավորումներ:"</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"Ձեր հաշիվները"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"Մուտքի հնարավորություն առկա հաշիվներ:"</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"Սարքաշարի կարգավորումներ"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"Անմիջական մուտք հեռախոսի սարքաշար:"</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"Հեռախոսային զանգերը"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"Վերահսկել, ձայնագրելել և կատարել հեռախոսազանգեր:"</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"Համակարգի գործիքները"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"Համակարգի ավելի ցածր մակարդակի մատչում և վերահսկողություն:"</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"Ծրագրավորման գործիքներ"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"Գործառույթներ, որ անհրաժեշտ են միայն հավելվածների ծրագրավորողներին:"</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"Այլ հավելվածի UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"Ազդել այլ հավելվածների UI-ներին:"</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"Պահոց"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"Մուտք գործել USB պահոց:"</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"Մուտք գործել SD քարտ:"</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"Մատչելիության գործիքներ"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"Հատկություններ, որ օժանդակող տեխնոլոգիան կարող է հայցել:"</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"Առբերել պատուհանի բովանդակությունը"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"Ստուգեք պատուհանի բովանդակությունը, որի հետ փոխգործակցում եք:"</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"Միացնել Հպման միջոցով հետազոտումը"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"Տարրերը, որոնց հպեք, բարձրաձայն կխոսեն, և էկրանը հնարավոր կլինի ուսումնասիրել ժեստերով:"</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"Միացնել ընդլայնված վեբ մատչելիությունը"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"Հնարավոր է սկրիպտներ տեղադրվեն` ծրագրի բովանդակությունն ավելի մատչելի դարձնելու համար:"</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"Զննել ձեր մուտքագրած տեքստը"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"Ներառում է անձնական տվյալներ, ինչպիսիք են վարկային քարտերի համարները և գաղտնաբառերը:"</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"անջատել կամ փոփոխել կարգավիճակի գոտին"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"Թույլ է տալիս հավելվածին անջատել կարգավիճակի գոտին կամ ավելացնել ու հեռացնել համակարգի պատկերակները:"</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"կարգավիճակի գոտի"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"Թույլ է տալիս հավելվածին կարգավիճակի գոտին լինել:"</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"ընդլայնել կամ ետ ծալել կարգավիճակի գոտին"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"Թույլ է տալիս ծրագրին ընդլայնել կամ ետ ծալել կարգավիճակի գոտին:"</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"վերաուղղել ելքային զանգերը"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"Թույլ է տալիս հավելվածին մշակել ելքային զանգերը և փոխել համարհավաքումը: Վնասարար հավելվածները կարող են վերահսկել, վերահասցեավորել կամ կանխել ելքային զանգերը:"</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"ստանալ տեքստային հաղորդագրություններ (SMS)"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"Թույլ է տալիս հավելվածին ստանալ և մշակել SMS հաղորդագրությունները: Սա նշանակում է, որ հավելվածը կարող է ստուգել կամ ջնջել ձեր սարքին ուղարկված հաղորդագրությունները` առանց դրանք ձեզ ցուցադրելու:"</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"ստանալ տեքստային հաղորդագրություններ (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"Թույլ է տալիս հավելվածին ստանալ և մշակել MMS հաղորդագրությունները: Սա նշանակում է, որ հավելվածը կարող է ստուգել կամ ջնջել ձեր սարքին ուղարկված հաղորդագրությունները` առանց դրանք ձեզ ցուցադրելու:"</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"ստանալ արտակարգ իրավիճակների հաղորդումներ"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"Թույլ է տալիս հավելվածին ստանալ և մշակել ծանուցվող արտակարգ հաղորդակցությունները: Այս թույլտվությունը հասանելի է միայն համակարգային ծրագրերին:"</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"կարդալ բջջային զեկուցվող հաղորդագրությունները"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"Թույլ է տալիս հավելվածին կարդալ ձեր սարքի կողմից ստացված բջջային հեռարձակվող հաղորդագրությունները: Բջջային հեռարձակվող զգուշացումները ուղարկվում են որոշ վայրերում` արտակարգ իրավիճակների մասին ձեզ զգուշացնելու համար: Վնասարար հավելվածները կարող են խանգարել ձեր սարքի արդյունավետությանը կամ շահագործմանը, երբ ստացվում է արտակարգ իրավիճակի մասին բջջային հաղորդում:"</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"ուղարկել SMS հաղորդագրություններ"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"Թույլ է տալիս հավելվածին ուղարկել SMS հաղորդագրություններ: Այն կարող է անսպասելի ծախսերի պատճառ դառնալ: Վնասարար հավելվածները կարող են ձեր հաշվից գումար ծախսել` ուղարկելով հաղորդագրություններ`  առանց ձեր հաստատման:"</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"պատասխանել հաղորդագրության միջոցով իրադարձություններ ուղարկել"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"Թույլ է տալիս հավելվածին հարցումներ ուղարկել այլ հաղորդագրությունների հավելվածներին` կառավարելու մուտքային զանգերին հաղորդագրության միջոցով պատասխանելու դեպքերը:"</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"կարդալ ձեր տեքստային հաղորդագրությունները (SMS կամ MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"Թույլ է տալիս հավելվածին կարդալ ձեր գրասալիկում կամ SIM քարտում պահված SMS հաղորդագրությունները: Սա թույլ է տալիս հավելվածին կարդալ բոլոր SMS հաղորդագրությունները` անկախ բովանդակությունից կամ գաղտնիությունից:"</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"Թույլ է տալիս հավելվածին կարդալ ձեր հեռախոսում կամ SIM քարտում պահված SMS հաղորդագրությունները: Սա թույլ է տալիս հավելվածին կարդալ բոլոր SMS հաղորդագրությունները` անկախ բովանդակությունից կամ գաղտնիությունից:"</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"խմբագրել ձեր տեքստային հաղորդագրությունները (SMS կամ MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"Թույլ է տալիս հավելվածին պատասխանել ձեր գրասալիկում կամ SIM քարտում պահված SMS հաղորդագրություններին: Վնասարար հավելվածները կարող են ջնջել ձեր հաղորդագրությունները:"</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"Թույլ է տալիս հավելվածին պատասխանել ձեր հեռախոսում կամ SIM քարտում պահված SMS հաղորդագրություններին: Վնասարար հավելվածները կարող են ջնջել ձեր հաղորդագրությունները:"</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"ստանալ տեքստային հաղորդագրություններ (WAP)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"Թույլ է տալիս հավելվածին ստանալ և գործարկել WAP հաղորդագրությունները: Այս թույլտվությունը ներառում է ձեզ ուղարկված հաղորդագրությունները հետևելու կամ ջնջելու կարողությունը` առանց ձեր տեսնելու:"</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"առբերել աշխատող հավելվածները"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"Թույլ է տալիս հավելվածին առբերել մանրամասն տեղեկություններ առկա և վերջերս աշխատող առաջադրանքների մասին: Սա կարող է թույլ տալ հավելվածին հայտնաբերել անձնական տեղեկություններ այլ հավելվածների վերաբերյալ:"</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"հաղորդակցվել օգտվողների միջև"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"Թույլ է տալիս հավելվածին իրականացնել գործողություններ սարքի տարբեր օգտվողների միջոցով: Վնասարար հավելվածները կարող են օգտագործել սա` խախտելու օգտվողների միջև պաշտպանությունը:"</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"ամբողջական հաղորդակցվելու արտոնություն օգտվողների միջև"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"Թույլ է տալիս բոլոր հնարավոր հաղորդակցության եղանակները օգտվողների միջև:"</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"կառավարել օգտվողներին"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"Թույլ է տալիս հավելվածներին կառավարել սարքի օգտագործողներին, այդ թվում` հարցումները, ստեղծումն ու ջնջումը:"</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"առբերել աշխատող հավելվածների մանրամասները"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"Թույլ է տալիս հավելվածին առբերել մանրամասն տեղեկություններ առկա և վերջերս աշխատող առաջադրանքների մասին: Վնասարար հավելվածները կարող են հայտնաբերել անձնական տեղեկություններ այլ հավելվածների վերաբերյալ:"</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"վերադասավորել աշխատող հավելվածները"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"Թույլ է տալիս հավելվածին փոխանցել առաջադրանքները առջևք և հետնաշերտ: Հավելվածը կարող է սա անել առանց ձեր ներածման:"</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"դադարեցնել հավելվածների աշխատանքը"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"Թույլ է տալիս հավելվածին հեռացնել առաջադրաքները և վերացնել դրանց հավելվածները: Վնասարար հավելվածները կարող են խանգարել այլ հավելվածների գործունեությանը:"</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"կառավարել գործունեության կույտերը"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"Թույլ է տալիս ծրագրին ավելացնել, հեռացնել և փոփոխել գործունեության կույտերը, որոնցում աշխատում են այլ ծրագրեր: Վնասակար ծրագրերը կարող են խաթարել այլ ծրագրերի վարքագիծը:"</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"մեկնարկել ցանկացած գործունեություն"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"Թույլ է տալիս հավելվածին մեկնարկել ցանկացած գործունեություն` անկախ թույլտվության պաշտպանվածությունից կամ արտահանման կարգավիճակից:"</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"կարգավորել էկրանի համատեղելիությունը"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"Թույլ է տալիս հավելվածին վերահսկել այլ հավելվածների էկրանի համատեղելիության ռեժիմը: Վնասարար հավելվածները կարող են խաթարել այլ հավելվածների վարքագիծը:"</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"միացնել հավելվածի վրիպազերծումը"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"Թույլ է տալիս հավելվածին միացնել վրիպազերծումը այլ հավելվածի համար: Վնասարար հավելվածները կարող են օգտագործել սա` մյուս հավելվածները վերացնելու համար:"</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"փոխել համակարգի ցուցադրման կարգավորումները"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"Թույլ է տալիս հավելվածին փոխել առկա կարգավորումը, ինչպես օրինակ տեղույթի կամ ընդհանուր տառաչափը:"</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"միացնել մեքենայի ռեժիմը"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"Թույլ է տալիս հավելվածին միացնել մեքենայի ռեժիմը:"</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"փակել այլ հավելվածները"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"Թույլ է տալիս հավելվածին վերջ տալ այլ հավելվածների հետնաշերտի գործընթացները: Սա կարող է պատճառ դառնալ, որ այլ հավելվածները դադարեն աշխատել:"</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"ստիպել դադարեցնել այլ հավելվածները"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"Թույլ է տալիս հավելվածին ստիպողաբար դադարեցնել այլ հավելվածները:"</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"ստիպել, որ հավելվածը փակվի"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"Թույլ է տալիս հավելվածին ստիպել որևէ գործունեություն, որը գտնվում է առջևքում, փակել ու ետ գնալ: Սովորական հավելվածների համար երբևէ  անհրաժեշտ չպետք է լինի:"</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"առբերել համակարգի ներքին կարգավիճակը"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"Թույլ է տալիս հավելվածին առբերել համակարգի ներքին կարգավիճակը: Վնասարար հավելվածները կարող են առբերել բազմաթիվ անձնական և ապահով տեղեկություններ, որոնք երբեք սովորաբար անհրաժեշտ չեն:"</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"առբերել էկրանի բովանդակությունը"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"Թույլ է տալիս հավելվածին առբերել ակտիվ պատուհանի պարունակությունը: Վնասարար հավելվածները կարող են առբերել պատուհանի լրիվ պարունակությունը և հետազոտել դրա ամբողջ տեքստը` բացառությամբ գաղտնաբառերի:"</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"ժամանակավոր միացնել մուտքի հնարավորությունը"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"Թույլ է տալիս հավելվածին ժամանակավորապես մուտքի հնարավորություն տալ սարքին: Վնասարար հավելվածները կարող են մուտքի հնարավորություն ընձեռել առանց օգտվողի համաձայնության:"</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"առբերել պատուհանի տեղեկություները"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"Թույլ է տալիս հավելվածին առբերել պատուհանների մասին տեղեկատվություններ  պատուհանի կառավարչից: Վնասարար հավելվածները կարող են առբերել տեղեկություններ, որը նախատեսված է ներքին համակարգի օգտագործման համար:"</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"զտել իրադարձությունները"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"Թույլ է տալիս հավելվածին գրանցել մուտքագրման զտիչ, որը զտում է օգտվողի իրադարձությունների ամբողջ հոսքը` նախքան դրանք կուղարկվեն: Վնասարար հավելվածը կարող է կառավարել համակարգի UI-ը` առանց ձեր միջամտության:"</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"խոշորացնել ցուցադրիչը"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"Թույլ է տալիս հավելվածին խոշորացնել ցուցադրիչի բովանդակությունը: Վնասարար հավելվածները կարող են փոխակերպել ցուցադրիչի բովանդակությունը այնպես, որ սարքը դառնա անպիտան:"</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"մասնակի անջատում"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"Դնում է գործունեության կառավարչին անջատման կարգավիճակի մեջ: Չի իրականացնում ամբողջական անջատում:"</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"կանխել ծրագրի փոխարկումները"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"Կանխում է օգտվողի անցումը այլ հավելվածի:"</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"ստանալ ընթացիկ հավելվածի մասին տեղեկություններ"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"Թույլ է տալիս սեփականատիրոջը առբերել գաղտնի տեղեկություններ ընթացիկ հավելվածի և ծառայությունների մասին էկրանի առաջին պլանում:"</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"վերահսկել և կառավարել բոլոր հավելվածների թողարկումը"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"Թույլ է տալիս հավելվածին հետևել և վերահսկել, թե ինչպես է համակարգը գործարկում գործողությունները: Վնասարար հավելվածները կարող են ամբողջությամբ վնասել համակարգը: Այս թույլտվությունը անհրաժեշտ է միայն ծրագրավորման համար և ոչ երբեք սովորական օգտագործման համար:"</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"ուղարկել հեռացված փաթեթի մասին հաղորդում"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"Թույլ է տալիս հավելվածին հաղորդել ծանուցում, որ հեռացվել է հավելվածի փաթեթ: Վնասարար հավելվածները կարող են օգտագործել սա ցանկացած այլ աշխատող հավելված սպանելու համար:"</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"ուղարկել ստացված SMS-ի հաղորդում"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"Թույլ է տալիս հավելվածին հաղորդել ծանուցում, որ ստացվել է SMS հաղորդագրություն: Վնասարար հավելվածները կարող են օգտագործել սա` կեղծելու մուտքային SMS հաղորդագրությունները:"</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"ուղարկել ստացված WAP-PUSH-ի  հաղորդում"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"Թույլ է տալիս հավելվածին հաղորդել ծանուցում, որ ստացվել է WAP PUSH հաղորդագրություն: Վնասարար հավելվածները կարող են օգտագործել սա` կեղծելու MMS հաղորդագրության ստացումը կամ աննկատ փոխարինելու ցանկացած կայքի բովանդակությունը վնասարար տարբերակներով:"</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"սահմանափակել աշխատող գործընթացների թիվը"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"Թույլ է տալիս հավելվածին վերահսկել գործընթացների առավելագույն թիվը, որ աշխատելու են: Երբևէ անհրաժեշտ չէ սովորական հավելվածների համար:"</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"ստիպել, որ առաջին պլանի հավելվածները փակվեն"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"Թույլ է տալիս հավելվածին վերահսկել արդյոք գործողությունները միշտ ավարտված են, երբ գնում են հետին պլան: Երբևէ անհրաժեշտ չէ սովորական հավելվածների համար:"</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"կարդալ մարտկոցի կարգավիճակը"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"Թույլ է տալիս հավելվածին կարդալ ընթացիկ ցածր մակարդակի մարտկոցի օգտագործման տվյալները: Կարող է թույլ տալ հավելվածին պարզել մանրամասն տեղեկություններ, թե որ հավելվածներն եք օգտագործում:"</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"փոփոխել մարտկոցի վիճակագրությունը"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"Թույլ է տալիս հավելվածին փոփոխել մարտկոցի հավաքագրված վիճակագրությունը: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"առբերել ծրագրի ops վիճակագրությունը"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"Թույլ է տալիս հավելվածին առբերել հավելվածի հավաքագրված գործողության կարգավիճակը: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"փոփոխել ծրագրի գործողությունների վիճակագրությունը"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"Թույլ է տալիս հավելվածին փոփոխել գործողությունների հավաքագրված վիճակագրությունը: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_backup" msgid="470013022865453920">"հսկել համակարգի պահուստավորումը և վերականգնումը"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"Թույլ է տալիս հավելվածին վերահսկել համակարգի պահուստավորման և վերականգնման մեխանիզմը: Սովորական հավելվածների կողմից օգտագործման համար չէ:"</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"հաստատել ամբողջական պահուստավորման կամ վերականգնման գործողությունը"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"Թույլ է տալիս հավելվածին գործարկել ամբողջական պահուստավորման հաստատման UI-ը: Որևէ հավելվածի կողմից օգտագործման համար չէ:"</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"ցուցադրել չարտոնված պատուհանները"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"Թույլ է տալիս հավելվածին ստեղծել պատուհաններ, որոնք նախատեսված են ներքին համակարգի օգտվողի ինտերֆեյսի օգտագործման համար: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"անցնել այլ ծրագրերի վրայով"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"Թույլ է տալիս հավելվածին երևալ այլ հավելվածների վերևում կամ օգտվողի ինտերֆեյսի մասերում: Դրանք կարող են խոչընդոտել ձեր ինտերֆեյսի օգտագործմանը ցանկացած հավելվածում կամ փոխել այն, ինչը կարծում եք, որ տեսնում եք այլ հավելվածներում:"</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"փոփոխել համաշխարհային անիմացիոն արագությունը"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"Թույլ է տալիս հավելվածին փոխել համաշխարհային անիմացիոն արագությունը (ավելի արագ կամ դանդաղ անիմացիաներ) ցանկացած ժամանակ:"</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"կառավարել ծրագրի այլանիշերը"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"Թույլ է տալիս հավելվածին ստեղծել և կառավարել իրենց սեփական նշանները` շրջանցելով իրենց սովորական Z հերթականությունը: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"սառեցնել էկրանը"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"Թույլ է տալիս հավելվածին ժամանակավորապես սառեցնել էկրանը` լրիվ էկրանին անցնելու համար:"</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"սեղմել ստեղները և կառավարման կոճակները"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"Թույլ է տալիս հավելվածին տրամադրել իր սեփական մուտքագրված իրադարձություններն (ստեղների սեղմումներ և այլն) այլ հավելվածներին: Վնասարար հավելվածները կարող են սա օգտագործել գրասալիկի աշխատանքին միջամտելու համար:"</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"Թույլ է տալիս հավելվածին առաքել իր սեփական ներածման իրադարձությունները (ստեղնի սեղմումներ և այլն) այլ հավելվածներին: Վնասարար հավելվածները կարող են սա օգտագործել գրասալիկը վնասելու համար:"</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"գրառել ձեր մուտքագրումները և գործողությունները"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"Թույլ է տալիս հավելվածին տեսնել ձեր սեղմած ստեղները, նույնիսկ այն ժամանակ, երբ փոխգործակցում եք այլ հավելվածի հետ (օրինակ` գաղտնաբառի մուտքագրումը): Երբեք անհրաժեշտ չպետք է լինի սովորական հավելվածների համար:"</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"միանալ մուտքագրման եղանակին"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"Թույլ է տալիս սեփականատիրոջը միանալ մուտքագրման եղանակի վերին մակարդակի ինտերֆեյսին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"կապվել մատչելիության ծառայության հետ"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"Թույլ է տալիս սեփականատիրոջը միանալ հասանելիության ծառայության վերին մակարդակի ինտերֆեյսին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"միանալ տպման ծառայությանը"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"Թույլ է տալիս սեփականատիրոջը միանալ տպման ծառայության վերին մակարդակի ինտերֆեյսին: Սովորական ծրագրերի համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"մուտքի գործել բոլոր տպման աշխատանքներ"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"Թույլ է տալիս սեփականատիրոջը մուտք ունենալ մեկ այլ ծրագրի կողմից ստեղծված տպման աշխատանքներ: Սովորական ծրագրերի համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"կապվել NFC ծառայությանը"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Թույլ է տալիս տիրոջը կապվել ծրագրերին, որոնք օգտագործում են NFC քարտեր: Սովորական ծրագրերի համար երբեք անհրաժեշտ չէ:"</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"միանալ տեքստային ծառայությանը"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"Թույլ է տալիս սեփականատիրոջը կապվել տեքստային ծառայության բարձր մակարդակի ինտերֆեյսին (օրինակ` Ուղղագրության ստուգման ծառայությանը): Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"կապվել VPN ծառայությանը"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"Թույլ է տալիս սեփականատիրոջը միանալ Vpn ծառայության վերին մակարդակի ինտերֆեյսին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"միանալ պաստառին"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"Թույլ է տալիս սեփականատիրոջը միանալ պաստառի վերին մակարդակի ինտերֆեյսին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"միանալ վիջեթ ծառայությանը"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"Թույլ է տալիս սեփականատիրոջը միանալ վիջեթ ծառայության վերին մակարդակի ինտերֆեյսին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"փոխգործակցել սարքի կառավարչի հետ"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"Թույլ է տալիս սեփականատիրոջը ուղարկել մտադրություններ սարքի կառավարչին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"ավելացնել կամ հեռացնել սարքի արդմինիստրատոր"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"Թույլ է տալիս սեփականատիրոջը ավելացնել կամ հեռացնել սարքի ակտիվ ադմինիստրատորներ: Երբեք չպետք է անհրաժեշտ լինի սովորական ծրագրերին:"</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"փոխել էկրանի դիրքավորումը"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"Թույլ է տալիս հավելվածին փոխել էկրանի պտտումը ցանկացած ժամանակ: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"փոխել ցուցչի արագությունը"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"Թույլ է տալիս հավելվածին փոխել մկնիկի կամ հպահարթակի սլաքի արագությունը ցանկացած ժամանակ: Երբևէ անհրաժեշտ չպետք է լինի սովորական հավելվածների համար:"</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"փոխել ստեղնաշարի դիրքը"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"Թույլ է տալիս հավելվածին փոխել ստեղնաշարի դիրքը: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"ուղարկել Linux ազդանշաններ հավելվածներին"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"Թույլ է տալիս հավելվածին հայցել, որ տրամադրված ազդանշանը ուղարկվի բոլոր մշտական գործընթացներին:"</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"միշտ աշխատեցնել հավելվածը"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"Թույլ է տալիս հավելվածին մնայուն դարձնել իր մասերը հիշողության մեջ: Սա կարող է սահմանափակել այլ հավելվածներին հասանելի հիշողությունը` դանդաղեցնելով գրասալիկի աշխատանքը:"</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"Թույլ է տալիս հավելվածին մնայուն դարձնել իր մասերը հիշողության մեջ: Սա կարող է սահմանափակել այլ հավելվածներին հասանելի հիշողությունը` դանդաղեցնելով հեռախոսի աշխատանքը:"</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"ջնջել հավելվածները"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"Թույլ է տալիս հավելվածին ջնջել Android փաթեթները: Վնասարար հավելվածները կարող են օգտագործել սա` կարևոր հավելվածները ջնջելու համար:"</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"ջնջել այլ հավելվածների տվյալները"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"Թույլ է տալիս հավելվածին մաքրել օգտվողի տվյալները:"</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"ջնջել այլ հավելվածների քեշերը"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"Թույլ է տալիս հավելվածին ջնջել քեշ ֆայլերը:"</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"չափել հավելվածի պահոցի տարածքը"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"Թույլ է տալիս հավելվածին առբերել իր կոդը, տվյալները և քեշի չափերը"</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"ուղղակիորեն տեղադրել հավելվածները"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"Թույլ է տալիս հավելվածին տեղադրել նոր կամ թարմացված Android փաթեթներ: Վնասարար հավելվածները կարող են օգտագործել սա` ավելացնելու նոր հավելվածներ` կամայականորեն հզոր թույլտվություններով:"</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"ջնջել հավելվածի քեշի բոլոր տվյալները"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"Թույլ է տալիս հավելվածին ազատել գրասալիկի պահոցը` ջնջելով ֆայլերը այլ հավելվածների քեշ գրացուցակներում: Սա կարող է պատճառ դառնալ, որ այլ հավելվածները ավելի դանդաղ մեկնարկեն, քանի որ դրանք պետք է նորից առբերեն իրենց տվյալները:"</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"Թույլ է տալիս հավելվածին ազատել հեռախոսի պահուստը` ջնջելով ֆայլերը այլ հավելվածների քեշ գրացուցակներում: Սա կարող է պատճառ դառնալ, որ այլ հավելվածները ավելի դանդաղ մեկնարկեն, քանի որ նրանք պետք է նորից առբերեն իրենց տվյալները:"</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"Տեղափոխել հավելվածի ռեսուրսները"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"Թույլ է տալիս հավելվածին տեղափոխել ծրագրային ռեսուրսները ներքին մեդիաներից արտաքինին և հակառակը:"</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"կարդալ հոսքի զգայուն տվյալները"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"Թույլ է տալիս հավելվածին կարդալ համակարգի տարբեր գրանցամատյանային ֆայլերից: Սա թույլ է տալիս ստանալ ընդհանուր տեղեկություններ այն մասին, թե ինչ եք անում գրասալիկով, այդ թվում` անձնական կամ գաղտնի տեղեկություններ:"</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"Թույլ է տալիս հավելվածին կարդալ համակարգի տարբեր գրանցամատյանային ֆայլերից: Սա թույլ է տալիս ստանալ ընդհանուր տեղեկություններ այն մասին, թե ինչ եք անում հեռախոսով, այդ թվում` անձնական կամ գաղտնի տեղեկություններ:"</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"օգտագործել ցանկացած մեդիա վերծանիչ նվագարկման համար"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"Թույլ է տալիս հավելվածին օգտագործել ցանկացած տեղադրված մեդիա վերծանիչ` նվագարկումը ապակոդավորելու համար:"</string>
-    <string name="permlab_manageCaCertificates" msgid="1678391896786882014">"կառավարեք վստահելի վկայագրերը"</string>
-    <string name="permdesc_manageCaCertificates" msgid="4015644047196937014">"Թույլատրում է հավելվածին տեղադրել և ապատեղադրել CA վկայագրերը՝ որպես վստահելի:"</string>
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"կարդալ կամ գրել ախտորոշիչին պատկանող ռեսուրսները"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"Թույլ է տալիս հավելվածին կարդալ և գրել ախտորոշիչ խմբին պատկանող ցանկացած ռեսուրսում, ինչպես օրինակ ֆայլերը /dev-ում: Դա կարող է ազդել համակարգի կայունության և անվտանգության վրա: Սա պետք է օգտագործել միայն արտադրողի կամ օպերատորի կողմից սարքին հատուկ ախտորոշման համար:"</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"միացնել կամ անջատել հավելվածի բաղադրիչները"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"Թույլ է տալիս հավելվածին փոխել, արդյոք այլ հավելվածի բաղադրիչը լինի միացված թե անջատված: Վնասարար հավելվածները կարող են սա օգտագործել` անջատելու գրասալիկի կարևոր հնարավորությունները: Այս թույլտվությունը պետք է օգտագործել զգուշությամբ, քանի որ հնարավոր է հավելվածի բաղադրիչները հայտնվեն անպիտան, անհամապատասխան կամ անկայուն կարգավիճակում:"</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"Թույլ է տալիս հավելվածին փոխել, արդյոք այլ հավելվածի բաղադրիչը լինի միացված թե անջատված: Վնասարար հավելվածները կարող են սա օգտագործել` անջատելու հեռախոսի կարևոր հնարավորությունները: Այս թույլտվությունը պետք է օգտագործել զգուշությամբ, քանի որ հնարավոր է հավելվածի բաղադրիչները հայտնվեն անպիտան, անհամապատասխան կամ անկայուն կարգավիճակում:"</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"շնորհել կամ չեղարկել թույլտվություններ"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"Թույլ է տալիս հավելվածին հատուկ թույլտվություն շնորհել կամ չեղարկել այդ կամ այլ հավելվածների համար: Վնասարար հավելվածները կարող են օգտագործել սա` մուտք գործելու ձեր կողմից չթույլատրված գործիքներ:"</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"սահմանել նախընտրած հավելվածները"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"Թույլ է տալիս հավելվածին փոփոխել ձեր նախընտրած հավելվածները: Վնասարար հավելվածները կարող են աննկատ փոխել հավելվածները, որոնք կեղծում են ձեր առկա հավելվածների աշխատանքը` ձեզանից անձնական տվյալներ հավաքագրելու համար:"</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"փոփոխել համակարգի կարգավորումները"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"Թույլ է տալիս հավելվածին փոփոխել համակարգի կարգավորումների տվյալները: Վնասարար հավելվածները կարող են վնասել ձեր համակարգի կարգավորումները:"</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"փոփոխել անվտանգ համակարգի կարգավորումները"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"Թույլ է տալիս հավելվածին փոփոխել համակարգի անվտանգ կարգավորումների տվյալները: Նախատեսված չէ սովորական հավելվածների կողմից օգտագործման համար:"</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"փոփոխել Google ծառայությունների քարտեզը"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"Թույլ է տալիս հավելվածին փոփոխել Google-ի ծառայությունների քարտեզը: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"աշխատել մեկնարկային ռեժիմով"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"Թույլ է տալիս հավելվածին ինքնուրույն մեկնարկել համակարգի բեռնման ավարտից հետո: Սա կարող է երկարացնել գրասալիկի մեկնարկը և թույլ տալ հավելավածին դանդաղեցնել ամբողջ գրասալիկի աշխատանքը` միշտ աշխատելով:"</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"Թույլ է տալիս հավելվածին ինքն իրեն սկսել` համակարգի բեռնումն ավարտվելուն պես: Սա կարող է հեռախոսի մեկնարկը դարձնել ավելի երկար և թույլ տալ, որ հավելվածը դանդաղեցնի ընդհանուր հեռախոսի աշխատանքը` միշտ աշխատելով:"</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"ուղարկել կպչուն հաղորդում"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"Թույլ է տալիս հավելվածին ուղարկել կպչուն հաղորդումներ, որոնք մնում են հաղորդման ավարտից հետո: Չափազանց շատ օգտագործումը կարող է գրասալիկի աշխատանքը դանդաղեցնել կամ դարձնել անկայուն` պատճառ դառնալով չափազանց մեծ հիշողության օգտագործման:"</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"Թույլ է տալիս հավելվածին ուղարկել կպչուն հաղորդումներ, որոնք մնում են հաղորդման ավարտից հետո: Չափազանց շատ օգտագործումը կարող է հեռախոսի աշխատանքը դանդաղեցնել կամ դարձնել անկայուն` պատճառ դառնալով չափազանց մեծ հիշողության օգտագործման:"</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"կարդալ ձեր կոնտակտները"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"Թույլ է տալիս հավելվածին կարդալ ձեր գրասալիկում պահված կոնտակտների մասին տվյալները, այդ թվում` ձեր կատարած զանգերի, գրած նամակների կամ որոշակի անհատների հետ այլ եղանակով շփման հաճախականությունը: Այս թույլտվությունը հնարավորություն է տալիս հավելվածներին պահել ձեր կոնտակտային տվյալները, իսկ վնասարար հավելվածները կարող են տարածել կոնտակտային տվյալները` առանց ձեր իմացության:"</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"Թույլ է տալիս հավելվածին կարդալ ձեր հեռախոսում պահված կոնտակտների մասին տվյալները, այդ թվում` ձեր կատարած զանգերի, գրած նամակների կամ որոշակի անհատների հետ այլ եղանակով շփման հաճախականությունը: Այս թույլտվությունը հնարավորություն է տալիս հավելվածներին պահել ձեր կոնտակտային տվյալները, իսկ վնասարար հավելվածները կարող են տարածել կոնտակտային տվյալները` առանց ձեր իմացության:"</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"փոփոխել ձեր կոնտակտները"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"Թույլ է տալիս հավելվածին փոփոխել ձեր գրասալիկում պահված կոնտակտների մասին տվյալները, այդ թվում` ձեր կատարած զանգերի, գրած նամակների կամ որոշակի անհատների հետ այլ եղանակով շփման հաճախականությունը: Այս թույլտվությունը հնարավորություն է տալիս հավելվածներին ջնջել կոնտակտային տվյալները:"</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"Թույլ է տալիս հավելվածին փոփոխել ձեր գրասալիկում պահված կոնտակտների տվյալները, այդ թվում` ձեր կատարած զանգերի, գրած նամակների կամ որոշակի անհատների հետ այլ եղանակով շփման հաճախականությունը: Այս թույլտվությունը հնարավորություն է տալիս հավելվածներին ջնջել կոնտակտային տվյալները:"</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"կարդալ զանգերի մատյանը"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"Թույլ է տալիս հավելվածին կարդալ ձեր գրասալիկի զանգերի գրանցամատյանը, այդ թվում` մուտքային և ելքային զանգերի տվյալները: Սա թույլ է տալիս հավելվածին պահել ձեր զանգերի գրանցամատյանի տվյալները, և վնասարար հավելվածները կարող են տարածել դրանք` առանց ձեր իմացության:"</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"Թույլ է տալիս հավելվածին կարդալ ձեր հեռախոսի զանգերի գրանցամատյանը, այդ թվում` մուտքային և ելքային զանգերի տվյալները: Թույլտվությունը հնարավորություն է տալիս հավելվածին պահպանել ձեր զանգերի գրանցամատյանի տվյալները, և վնասարար հավելվածները կարող են տարածել գրանցամատյանի տվյալներն առանց ձեր իմացության:"</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"տեսնել զանգերի գրանցամատյանը"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"Թույլ է տալիս հավելվածին փոփոխել ձեր գրասալիկի զանգերի մատյանը, այդ թվում` մուտքային և ելքային զանգերի մասին տվյալները: Վնասարար հավելվածները կարող են սա օգտագործել` ձեր զանգերի մատյանը ջնջելու կամ փոփոխելու համար:"</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"Թույլ է տալիս հավելվածին փոփոխել ձեր հեռախոսի զանգերի մատյանը, այդ թվում` մուտքային և ելքային զանգերի մասին տվյալները: Վնասարար հավելվածները կարող են սա օգտագործել` ձեր զանգերի մատյանը ջնջելու կամ փոփոխելու համար:"</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"կարդալ ձեր սեփական կոնտակտային քարտը"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"Թույլ է տալիս հավելվածին կարդալ ձեր սարքում պահված անհատական ​​պրոֆիլի տվյալները, ինչպիսիք են ձեր անունը և կոնտակտային տվյալները: Սա նշանակում է, որ հավելվածը կարող է ձեզ ճանաչել և ուղարկել ձեր պրոֆիլի տվյալները ուրիշներին:"</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"փոփոխել ձեր սեփական կոնտակտային քարտը"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"Թույլ է տալիս հավելվածին փոխել կամ ավելացնել ձեր սարքում պահված անհատական ​​պրոֆիլի տվյալները, ինչպիսիք են ձեր անունը և կոնտակտային տվյալները: Սա նշանակում է, որ հավելվածը կարող է ձեզ ճանաչել և ուղարկել ձեր պրոֆիլի տվյալները ուրիշներին:"</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"կարդալ ձեր սոցիալական հոսքը"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"Թույլ է տալիս հավելվածին մուտք գործել և համաժամեցնել ձեր և ձեր ընկերների սոցիալական թարմացումները: Զգույշ եղեք տեղեկություններ տարածելիս. այն թույլ է տալիս հավելվածին կարդալ ձեր և ձեր ընկերների միջև անձնական հաղորդագրությունները սոցիալական ցանցերում` անկախ գաղտնիությունից: Նշում. այս թույլտվությունը չի կարող գործածվել բոլոր սոցիալական ցանցերում:"</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"գրել ձեր սոցիալական հոսքում"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"Թույլ է տալիս հավելվածին ցուցադրել ձեր ընկերների սոցիալական թարմացումները: Զգույշ եղեք տեղեկություններ տարածելիս. այն թույլ է տալիս հավելվածին հաղորդագություններ ստեղծել, որոնք իբրև ստացվում են ընկերոջից: Նշում. այս թույլտվությունը չի կարող գործածվել բոլոր սոցիալական ցանցերում:"</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"կարդալ օրացուցային իրադարձությունները և գաղտնի տեղեկությունները"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"Թույլ է տալիս հավելվածին կարդալ ձեր գրասալիկում պահված բոլոր օրացուցային իրադարձությունները, այդ թվում` ընկերների կամ գործընկերների: Սա կարող է թույլ տալ հավելվածին տարածել կամ պահել ձեր օրացուցային տվյալները` անկախ գաղտնիությունից կամ զգայունությունից:"</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"Թույլ է տալիս հավելվածին կարդալ ձեր հեռախոսում պահված բոլոր օրացուցային իրադարձությունները, այդ թվում` ընկերների կամ գործընկերների: Սա կարող է թույլ տալ հավելվածին տարածել կամ պահել ձեր օրացուցային տվյալները` անկախ գաղտնիությունից կամ զգայունությունից:"</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"ավելացնել կամ փոփոխել օրացուցային իրադարձությունները և ուղարկել նամակ հյուրերին` առանց սեփականատերերի իմացության"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"Թույլ է տալիս հավելվածին ավելացնել, հեռացնել, փոխել իրադարձություններ, որոնք դուք կարող եք փոփոխել ձեր գրասալիկում, այդ թվում ընկերների կամ աշխատակիցների իրադարձությունները: Սա կարող է թույլ տալ հավելվածին ուղարկել հաղորդագրություններ, որոնք երևում են որպես օրացույցի սեփականատերերից ուղարկված, կամ փոփոխել իրադարձություններն առանց սեփականատերերի իմացության:"</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"Թույլ է տալիս հավելվածին ավելացնել, հեռացնել, փոխել այն իրադարձությունները, որոնք կարող եք փոփոխել ձեր հեռախոսից, այդ թվում` ընկերների կամ գործընկերների: Սա կարող է թույլ տալ հավելվածին ուղարկել հաղորդագրություններ, որոնք իբրև գալիս են օրացույցի սեփականատիրոջից, կամ փոփոխել իրադարձությունները` առանց սեփականատիրոջ իմացության:"</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"կեղծ տեղանքի աղբյուրներ փորձարկման համար"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"Ստեղծել կեղծ տեղանքի աղբյուրներ` փորձարկման կամ տեղադրության նոր ծառայություն մատուցողի տեղադրման համար: Սա հնարավորություն է տալիս, որ ծրագիրը անտեսի տեղադրությունը և/կամ կարգավիճակը` տրամադրված տեղանքի այլ աղբյուրների կողմից, ինչպիսիք են GPS-ը կամ տեղադրության ծառայություն մատուցողները:"</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"օգտագործել տեղադրություն տրամադրող հավելվյալ հրամաններ"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"Թույլ է տալիս հավելվածին օգտագործել տեղադրության ծառայություն մատուցողների լրացուցիչ հրամանները: Սա կարող է թույլ տալհավելվածին խանգարել GPS-ի կամ այլ տեղանքի աղբյուրների աշխատանքին:"</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"տեղադրության ծառայություն մատուցողի տեղադրման թույլտվություն"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"Ստեղծել կեղծ տեղանքի աղբյուրներ` փորձարկման կամ տեղադրության նոր ծառայություն մատուցողի տեղադրման համար: Սա հնարավորություն է տալիս, որ հավելվածն անտեսի տեղադրությունը և/կամ կարգավիճակը` տրամադրված տեղանքի այլ աղբյուրների կողմից, ինչպիսիք են GPS-ը կամ տեղադրության ծառայություն մատուցողները:"</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"ճշգրիտ վայրը (ըստ GPS-ի և ցանցի)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"Թույլ է տալիս հավելվածին ստանալ ձեր ճշգրիտ տեղադրությունը` օգտագործելով Գլոբալ Դիրքավորման Համակարգը (GPS) կամ ցանցային տեղանքի աղբյուրները, ինչպես օրինակ` բջջային աշտարակները և Wi-Fi-ը: Այս տեղադրության ծառայությունները պետք է միացվեն և հասանելի լինեն ձեր սարքի համար, որպեսզի հավելվածն օգտագործի դրանք: Հավելվածները կարող են սա օգտագործել` որոշելու համար ձեր գտնվելու վայրը և կարող են սպառել մարտկոցի լրացուցիչ լիցք:"</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"մոտավոր տեղադրությունը (ցանցային)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"Թույլ է տալիս հավելվածին ստանալ ձեր մոտավոր տեղադրությունը: Այս տեղադրությունը ստացվում է տեղանքի ծառայությունների կողմից, ինչպես օրինակ` բջջային աշտարակներից և Wi-Fi-ից: Այս տեղանքի ծառայությունները պետք է միացված և հասանելի լինեն ձեր սարքին, որպեսզի հավելվածն օգտագործի դրանք: Հավելվածները կարող են սա օգտագործել` ձեր մոտավոր գտնվելու վայրը որոշելու համար:"</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"մուտք SurfaceFlinger"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"Թույլ է տալիս հավելվածին օգտագործել SurfaceFlinger ցածր մակարդակի գործառույթները:"</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"կարդալ շրջանակի պահնակը"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"Թույլ է տալիս հավելվածին կարդալ շրջանակի պահնակի բովանդակությունը:"</string>
-    <string name="permlab_accessInputFlinger" msgid="5348635270689553857">"մուտք գործել InputFlinger"</string>
-    <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"Թույլ է տալիս ծրագրին օգտագործել InputFlinger ցածր մակարդակի գործառույթները:"</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"կարգավորել WiFi-ի ցուցադրումը"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"Թույլ է տալիս հավելվածին կարգավորել և միանալ WiFi ցուցադրիչներին:"</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"կառավարել Wifi-ի ցուցադրումը"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Թույլ է տալիս հավելվածին կառավարել WiFi ցուցադրիչների ցածր մակարդակի գործառույթները:"</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"պահել աուդիո արտածումը"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"Թույլ է տալիս ծրագրին պահել և վերահղել աուդիո արտածումը:"</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"պահել վիդեո արտածումը"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"Թույլ է տալիս ծրագրին պահել և վերահղել վիդեո արտածումը:"</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"պահել անվտանգ վիդեո արտածումը"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"Թույլ է տալիս ծրագրին պահել և վերահղել անվտանգ վիդեո արտածումը:"</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"փոխել ձեր աուդիո կարգավորումները"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"Թույլ է տալիս հավելվածին փոփոխել ձայնանյութի գլոբալ կարգավորումները, ինչպես օրինակ` ձայնը և թե որ խոսափողն է օգտագործված արտածման համար:"</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"ձայնագրել ձայնանյութ"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"Թույլ է տալիս հավելվածին բարձրախոսով ձայնագրել ձայնանյութ: Այս թույլտվությունը հնարավորություն է տալիս հավելվածին ձայնանյութ ձայնագրել ցանկացած ժամանակ` առանց ձեր հաստատման:"</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"լուսանկարել և տեսանկարել"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"Թույլ է տալիս հավելվածին ֆոտոխցիկով լուսանկարել և տեսանկարել: Այս թույլտվությունը հնարավորություն է տալիս հավելվածին օգտագործել ֆոտոխցիկը ցանկացած ժամանակ` առանց ձեր հաստատման:"</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"անջատել փոխանցող LED ցուցիչը, երբ ֆոտոխցիկը օգտագործվում է"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"Թույլ է տալիս նախապես տեղադրված համակարգային ծրագրին անջատել ֆոտոխցիկի օգտագործման LED ցուցիչը:"</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"մշտապես անջատել գրասալիկը"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"ընդմիշտ կասեցնել հեռախոսը"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"Թույլ է տալիս հավելվածին ընդմիշտ անջատել ամբողջ գրասալիկը: Սա շատ վտանգավոր է:"</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"Թույլ է տալիս հավելվածին ընդմիշտ անջատել ամբողջ հեռախոսը: Սա շատ վտանգավոր է:"</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ստիպել, որ գրասալիկը վերաբեռնվի"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"ստիպել, որ հեռախոսը վերաբեռնվի"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"Թույլ է տալիս հավելվածին ստիպել, որ գրասալիկը վերաբեռնվի:"</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"Թույլ է տալիս հավելվածին ստիպել, որ հեռախոսը վերաբեռնվի:"</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"մուտք ունենալ USB կրիչի ֆայլային համակարգ"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"մուտք ունենալ SD քարտի ֆայլային համակարգ"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"Թույլ է տալիս հավելվածին միացնել և անջատել շարժական կրիչների ֆայլային համակարգերը:"</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"ջնջել USB կրիչը"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"ջնջել SD քարտը"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"Թույլ է տալիս հավելվածին ֆորմատավորել շարժական կրիչը:"</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"տեղեկություններ ստանալ ներքին պահոցի վերաբերյալ"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"Թույլ է տալիս հավելվածին ստանալ տեղեկություններ ներքին պահոցի վերաբերյալ:"</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"ստեղծել ներքին պահոց"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"Թույլ է տալիս հավելվածին ստեղծել ներքին պահոց:"</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"ոչնչացնել ներքին պահոցը"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"Թույլ է տալիս հավելվածին ոչնչացնել ներքին պահոցը:"</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"միացնել կամ անջատել ներքին պահոցը"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"Թույլ է տալիս հավելվածին միացնել/անջատել ներքին պահոցը:"</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"վերանվանել ներքին պահոցը"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"Թույլ է տալիս հավելվածին վերանվանել ներքին պահոցը:"</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_manageUsb" msgid="1113453430645402723">"կառավարել նախապատվությունները և թույլտվությունները USB սարքերի համար"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"Թույլ է տալիս հավելվածին կառավարել նախասիրություններն ու թույլտվությունները USB սարքերի համար:"</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"կիրառել MTP պրոտոկոլը"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"Մուտքի հնարավորություն է տալիս միջուկի MTP սարքավարին MTP USB պրոտոկոլը կիրառելու համար:"</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"փորձարկել սարքը"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"Թույլ է տալիս հավելվածին կառավարել տարբեր արտաքին սարքավորումեր` սարքաշարի փորձարկման նպատակով:"</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"ուղղակիորեն զանգել հեռախոսահամարներին"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"Թույլ է տալիս հավելվածին զանգել հեռախոսահամարներին առանց ձեր միջամտության: Սա կարող է հանգեցնել անկանխատեսելի գանձումների կամ զանգերի: Նկատի ունեցեք, որ սա թույլ չի տալիս հավելվածին զանգել արտակարգ իրավիճակների համարներին: Վնասարար հավելվածները կարող են ձեր հաշվից զանգեր կատարել` առանց ձեր հաստատման:"</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"ուղղակիորեն զանգահարել որևէ հեռախոսահամարի"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"Թույլ է տալիս հավելվածին զանգել ցանկացած հեռախոսահամարի, այդ թվում` արտակարգ իրավիճակների համարներին` առանց ձեր միջամտության: Վնասարար հավելվածները կարող են կատարել անցանկալի և անօրինական զանգեր արտակարգ իրավիճակների ծառայություններին:"</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"ուղղակիորեն սկսել CDMA գրասալիկի կագավորումը"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"ուղղակիորեն սկսել CDMA հեռախոսի կարգավորումը"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"Թույլ է տալիս հավելվածին մեկնարկել CDMA-ի տրամադրումը: Վնասարար հավելվածները կարող են անտեղի սկսել CDMA-ի տրամադրում:"</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"վերահսկել տեղանքի թարմացման ծանուցումները"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"Թույլ է տալիս հավելվածին միացնել կամ անջատել տեղանքի թարմացման ծանուցումները ռադիոյից: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"մուտք գործել գրանցանշման կարգավորումներ"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"Թույլ է տալիս հավելվածին կարդալ/գրել գրանցանշման ծառայության կողմից վերբեռնված հատկությունների մուտքը: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"ընտրել վիջեթներ"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"Թույլ է տալիս հավելվածին թելադրել համակարգին, թե որ վիջեթները որ հավելվածի միջոցով է հնարավոր օգտագործել: Այս թույլտվությամբ հավելվածը կարող է այլ հավելվածներին մուտք տալ դեպի անձնական տվյալներ: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"փոփոխել հեռախոսի կարգավիճակը"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"Թույլ է տալիս հավելվածին կառավարել սարքի հեռախոսային գործիքները: Այս թույլտվությամբ հավելվածը կարող է փոխարկել ցանցերը, միացնելև անջատել հեռախոսի ռադիոն և նման այլ բաներ` առանց ձեզ երբևէ տեղեկացնելու:"</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"կարդալ հեռախոսի կարգավիճակը և ինքնությունը"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"Թույլ է տալիս հավելվածին օգտագործել սարքի հեռախոսային գործիքները: Այս թույլտվությունը հավելվածին հնարավորություն է տալիս որոշել հեռախոսահամարը և սարքի ID-ները, արդյոք զանգը ակտիվ է և միացված զանգի հեռակա հեռախոսահամարը:"</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"զերծ պահել գրասալիկը քնելուց"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"կանխել հեռախոսի քնի ռեժիմին անցնելը"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"Թույլ է տալիս հավելվածին կանխել գրասալիկի` քնի ռեժիմին անցնելը:"</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"Թույլ է տալիս հավելվածին կանխել հեռախոսի` քնի ռեժիմին անցնելը:"</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"գրասալիկը միացնել կամ անջատել"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"հեռախոսը միացնել կամ անջատել"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"Թույլ է տալիս հավելվածին միացնել կամ անջատել գրասալիկը:"</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"Թույլ է տալիս հավելվածին միացնել կամ անջատել հեռախոսը:"</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"աշխատել գործարանային փորձնական ռեժիմում"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"Աշխատեցնել որպես արտադրողի ցածր մակարդակի փորձարկում` թույլատրելով գրասալիկի սարքին լիարժեք մուտք: Հասանելի է միայն այն ժամանակ, երբ գրասալիկը աշխատում է արտադրողի փորձնական ռեժիմում:"</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"Աշխատեցնել որպես արտադրողի ցածր մակարդակի փորձարկում` թույլատրելով լիարժեք մուտք հեռախոսի սարքաշարին: Հասանելի է միայն այն ժամանակ, երբ հեռախոսն աշխատում է արտադրողի փորձնական ռեժիմում:"</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"դնել պաստառ"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"Թույլ է տալիս հավելվածին տեղադրել համակարգի պաստառը:"</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"կարգաբերել ձեր պաստառի չափերը"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"Թույլ է տալիս հավելվածին տեղադրել համակարգի պաստառի չափի հուշումները:"</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"վերակայել համակարգը գործարանային լռելյայնի"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"Թույլ է տալիս հավելվածին ամբողջությամբ վերակայել համակարգը իր գործարանային կարգավորումներին` ջնջելով բոլոր տվյալները, կարգավորումները և տեղադրված հավելվածները:"</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"կարգավորել ժամը"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"Թույլ է տալիս հավելվածին փոխել գրասալիկի ժամացույցի ժամանակը:"</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"Թույլ է տալիս հավելվածին փոխել հեռախոսի ժամացույցի ժամանակը:"</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"կարգավորել ժամային գոտին"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"Թույլ է տալիս հավելվածին փոխել գրասալիկի ժամային գոտին:"</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"Թույլ է տալիս հավելվածին փոխել հեռախոսի ժամային գոտին:"</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"գործել որպես Հաշվի կառավարիչ ծառայություն"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"Թույլ է տալիս հավելվածին զանգել Հաշվի իսկորոշիչներին:"</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"գտնել հաշիվներ սարքում"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"Թույլ է տալիս հավելվածին ստանալ գրասալիկի կողմից ճանաչված հաշիվների ցանկը: Սա կարող է ներառել ցանկացած հաշիվ, որ ստեղծվել է ձեր տեղադրած հավելվածների կողմից:"</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"Թույլ է տալիս հավելվածին ստանալ հեռախոսի կողմից ճանաչված հաշիվների ցանկը: Սա կարող է ներառել ցանկացած հաշիվ, որ ստեղծվել է ձեր տեղադրած հավելվածների կողմից:"</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"ստեղծել հաշիվներ և դնել գաղտնաբառեր"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"Թույլ է տալիս հավելվածին օգտագործել հաշվի կառավարչի նույնականացնող հնարավորությունները, ինչպես նաև ստեղծել հաշիվներ, ստանալ և կարգավորել դրանց գաղտնաբառերը:"</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"ավելացնել կամ հեռացնել հաշիվներ"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"Թույլ է տալիս հավելվածին իրականացնել գործողություններ, ինչպիսիք են` ավելացնել և հեռացնել հաշիվներ և ջնջել դրանց գաղտնաբառերը:"</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"օգտագործել սարքի հաշիվները"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"Թույլ է տալիս հավելվածին հայցել նույնականացման նշաններ:"</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"դիտել ցանցային միացումները"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"Թույլ է տալիս հավելվածին տեսնել ցանցային կապերի մասին տեղեկություններ, ինչպես օրինակ, թե ինչ կապեր կան և որոնք են միացված:"</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"լրիվ ցանցային մուտք"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"Թույլ է տալիս հավելվածին ստեղծել ցանցային բնիկներ և օգտագործել հատուկ ցանցային պրոտոկոլներ: Զննարկիչը և այլ հավելվածները միջոցներ են տրամադրում ինտերնետին տվյալներ ուղարկելու համար, ուստի այս թույլտվությունը չի պահանջվում ինտերնետին տվյալներ ուղարկելու համար:"</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"փոխել/կասեցնել ցանցային կարգավորումները և շարժը"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"Թույլ է տալիս հավելվածին փոխել ցանցային կարգավորումները և կասեցնել ու ստուգել ամբողջ ցանցային շարժը, օրինակ` փոխել ցանկացած APN-ի պրոքսին և միացքը: Վնասարար հավելվածները կարող են հետևել, վերահասցեավորել կամ փոփոխել ցանցային փաթեթները` առանց ձեր իմացության:"</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"փոխել ցանցի կապը"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"Թույլ է տալիս հավելվածին փոխել ցանցի միացման կարգավիճակը:"</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"փոխել միացված կապը"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"Թույլ է տալիս հավելվածին փոխել կապված ցանցի միացման կարգավիճակը:"</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"փոխել ֆոնային տվյալների օգտագործման կարգավորումը"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"Թույլ է տալիս հավելվածին փոխել ֆոնային տվյալների օգտագործման կարգավորումները:"</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"դիտել Wi-Fi կապերը"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"Թույլ է տալիս հավելվածին տեսնել Wi-Fi ցանցի տեղեկություններ, ինչպես օրինակ` արդյոք Wi-Fi-ը միացված է, թե` ոչ, և միացված Wi-Fi սարքի անունը:"</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"միանալ Wi-Fi-ին և անջատվել դրանից"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"Թույլ է տալիս հավելվածին միանալ Wi-Fi մուտքի կետերին և անջատվել այդ կետերից, ինչպես նաև կատարել սարքի կարգավորման փոփոխություններ Wi-Fi ցանցերի համար:"</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"թույլատրել Բազմասփյուռ Wi-Fi-ի ընդունումը"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"Թույլ է տալիս հավելվածին ստանալ Wi-Fi ցանցի բոլոր սարքերին ուղարկված փաթեթները` օգտագործելով ոչ միայն ձեր գրասալիկը, այլ նաև բազմասփյուռ հասցեները: Այն օգտագործում է ավելի շատ լիցք, քան ոչ բազմասփյուռ ռեժիմը:"</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"Թույլ է տալիս հավելվածին ստանալ Wi-Fi ցանցի բոլոր սարքերին ուղարկված փաթեթները` օգտագործելով ոչ միայն ձեր հեռախոսը, այլ նաև բազմասփյուռ հասցեները: Այն օգտագործում է ավելի շատ լիցք, քան ոչ բազմասփյուռ ռեժիմը:"</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"մուտք գործել Bluetooth-ի կարգավորումներ"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"Թույլ է տալիս հավելվածին կարգավորել տեղային Bluetooth գրասալիկը և հայտնաբերել ու զուգակցվել հեռակա սարքերի հետ:"</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"Թույլ է տալիս հավելվածին կարգավորել տեղային Bluetooth հեռախոսը և հայտնաբերել ու զուգակցվել հեռակա սարքերի հետ:"</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"միանալ WiMAX-ին և անջատվել դրանից"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"Թույլ է տալիս հավելվածին պարզել, արդյոք WiMAX-ը միացված է և ցանկացած միացված WiMAX ցանցի մասին տեղեկություններ:"</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"Փոխել WiMAX-ի կարգավիճակը"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"Թույլ է տալիս հավելվածին գրասալիկը միացնել WiMAX ցանցին և անջատվել այդ ցանցից:"</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"Թույլ է տալիս հավելվածին հեռախոսը միացնել WiMAX ցանցին և անջատել այդ ցանցից:"</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"զուգակցվել Bluetooth սարքերի հետ"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"Թույլ է տալիս հավելվածին տեսնել Bluetooth-ի կարգավորումը գրասալիկի վրա և կապվել ու կապեր ընդունել զուգակցված սարքերի հետ:"</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"Թույլ է տալիս հավելվածին տեսնել Bluetooth-ի կարգավորումը հեռախոսի վրա և կապվել ու կապեր ընդունել զուգակցված սարքերի հետ:"</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"վերահսկել Մոտ Տարածությամբ Հաղորդակցումը"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"Թույլ է տալիս հավելվածին հաղորդակցվել Մոտ տարածությամբ հաղորդակցման (NFC) պիտակների, քարտերի և ընթերցիչների հետ:"</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"անջատել ձեր էկրանի կողպեքը"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"Թույլ է տալիս հավելվածին անջատել ստեղնաշարի կողպումը և ցանկացած համակցված գաղտնաբառի պաշտպանվածությունը: Սրա ճիշտ օրինակն է, երբ հեռախոսը անջատում է ստեղնաշարի կողպումը մուտքային զանգ ստանալիս, հետո այն կրկին միացնում է, երբ զանգը ավարտվում է:"</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"կարդալ համաժամեցման կարգավորումները"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"Թույլ է տալիս հավելվածին կարդալ համաժամեցման կարգավորումները հաշվի համար: Օրինակ` այն կարող է որոշել, արդյոք Մարդիկ հավելվածը համաժամեցված է հաշվի հետ:"</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"համաժամեցումը փոխարկել միացվածի և անջատվածի"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"Թույլ է տալիս հավելվածին փոփոխել համաժամեցման կարգավորումները հաշվի համար: Օրինակ, այն կարող է օգտագործվել` միացնելու Մարդիկ հավելվածի համաժամեցումը հաշվի հետ:"</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"կարդալ համաժամեցման վիճակագրությունը"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"Թույլ է տալիս հավելվածին կարդալ հաշվի համաժամեցման վիճակագրությունը, այդ թվում` համաժամեցման իրադարձությունների պատմությունը և թե որքան տվյալ է համաժամեցված:"</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"կարդալ բաժանորդագրված հոսքերը"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"Թույլ է տալիս հավելվածին մանրամասներ ստանալ ընթացիկ համաժամեցված հոսքերի մասին:"</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"գրել բաժանորդագրված հոսքերը"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"Թույլ է տալիս հավելվածին փոփոխել ձեր ներկայումս համաժամեցված հոսքերը: Վնասարար հավելվածները կարող են փոխել ձեր համաժամեցված հոսքերը:"</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"կարդալ պայմանները, որ ավելացրել եք բառարանում"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"Թույլ է տալիս հավելվածին կարդալ բոլոր բառերը, անունները և արտահայտությունները, որոնք օգտագործողը հնարավոր է պահել է օգտվողի բառարանում:"</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"ավելացնել բառեր օգտվողի համար սահմանված բառարանում"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"Թույլ է տալիս հավելվածին գրել նոր բառեր օգտվողի բառարանում:"</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"փորձարկել մուտքը դեպի պաշտպանված պահոց"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"փորձարկել մուտքը դեպի պաշտպանված պահոց"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"Թույլ է տալիս հավելվածին փորձարկել USB կրիչի թույլտվությունը, որը հասանելի կլինի հետագա սարքերում:"</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"Թույլ է տալիս հավելվածին փորձարկել SD քարտի թույլտվությունը, որը հասանելի կլինի հետագա սարքերի վրա:"</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"փոփոխել կամ ջնջել ձեր USB կրիչի բովանդակությունը"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"փոփոխել կամ ջնջել ձեր SD քարտի բովանդակությունը"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"Թույլ է տալիս հավելվածին գրել USB կրիչի վրա:"</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"Թույլ է տալիս հավելվածին գրել SD քարտի վրա:"</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"փոփոխել/ջնջել ներքին մեդիա կրիչի բովանդակությունը"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"Թույլ է տալիս հավելվածին փոփոխել ներքին մեդիա պահոցի բովանդակությունը:"</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"կառավարել փաստաթղթերի պահոցը"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"Թույլ է տալիս հավելվածին կառավարել փաստաթղթի պահոցը:"</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"մուտք ունենալ բոլոր օգտվողների արտաքին պահոց"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"Թույլ է տալիս հավելվածին մուտք գործել արտաքին պահոց բոլոր օգտվողների համար:"</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"մուտք քեշի ֆայլերի համակարգ"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"Թույլ է տալիս հավելվածին գրել և կարդալ քեշ ֆայլային համակարգը:"</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"կատարել կամ ստանալ ինտերնետային զանգեր"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"Թույլ է տալիս հավելվածին օգտագործել SIP ծառայությունը` ինտերնետային զանգեր կատարելու/ստանալու համար:"</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"կարդալ պատմական ցանցի օգտագործումը"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"Թույլ է տալիս հավելվածին կարդալ հատուկ ցանցերի և հավելվածների համար ցանցի օգտագործման պատմությունը:"</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"կառավարել ցանցի քաղաքականությունը"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"Թույլ է տալիս հավելվածին կառավարել ցանցային քաղաքականությունը և սահմանել հավելվածի հատուկ կանոնները:"</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"փոփոխել ցանցի օգտագործման հաշվառումը"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"Թույլ է տալիս հավելվածին փոփոխել, թե ինչպես է ցանցի օգտագործումը հաշվարկվում հավելվածների համար: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"փոփոխել բնիկի նշանները"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"Թույլ է տալիս ծրագրին փոփոխել բնիկի նշանները երթուղման համար"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"մուտք գործել ծանուցումներ"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"Թույլ է տալիս հավելվածին առբերել, ուսումնասիրել և մաքրել ծանուցումներն, այդ թվում նաև այլ հավելվածների կողմից գրառվածները:"</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"միանալ ծանուցումների ունկնդրիչ ծառայությանը"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"Թույլ է տալիս սեփականատիրոջը միանալ ծանուցումները ունկնդրող ծառայության վերին մակարդակի ինտերֆեյսին: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"գործարկել օպերատորի կողմից տրամադրված կազմաձևման ծրագիրը"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"Թույլ է տալիս սեփականատիրոջը գործարկել օպերատորի կողմից տրամադրված կազմաձևման ծրագիրը: Սովորական ծրագրերի համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"լսել դիտարկումներ ցանցային պայմանների վերաբերյալ"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"Հավելվածին թույլ է տալիս լսել դիտարկումներ ցանցային պայմանների վերաբերյալ: Սովորական հավելվածների համար երբեք պետք չի գալիս:"</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"Սահմանել գաղտնաբառի կանոնները"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"Վերահսկել էկրանի ապակողպման գաղտնաբառերի թույլատրելի երկարությունն ու գրանշանները:"</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"Վերահսկել էկրանի ապակողպման փորձերը"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"Վերահսկել սխալ գաղտնաբառերի թիվը, որոնք մուտքագրվել են էկրանն ապակողպելիս, և կողպել գրասալիկը կամ ջնջել գրասալիկի բոլոր տվյալները, եթե մուտքագրվել են չափից շատ սխալ գաղտնաբառեր:"</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"Վերահսկել սխալ գաղտնաբառերի թիվը, որոնք մուտքագրվել են էկրանն ապակողպելիս, և կողպել հեռախոսը կամ ջնջել հեռախոսի բոլոր տվյալները, եթե մուտքագրվել են չափից շատ սխալ գաղտնաբառեր:"</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"Փոխել էկրանի ապակողպման գաղտնաբառը"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"Փոխել էկրանի ապակողպման գաղտնաբառը:"</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"Կողպել էկրանը"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"Վերահսկել` ինչպես և երբ է էկրանը կողպվում:"</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"Ջնջել բոլոր տվյալները"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"Ջնջել գրասալիկի տվյալներն առանց նախազգուշացման` կատարելով գործարանային տվյալների վերակայում:"</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"Ջնջել հեռախոսի տվյալներն առանց նախազգուշացման` կատարելով գործարանային տվյալների վերակայում:"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"Կարգավորել սարքի համաշխարհային պրոքսին"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"Սարքը կարգավորել, որ համաշխարհային պրոքսին օգտագործվի, երբ քաղաքականությունը միացված է: Միայն առաջին սարքի կառավարիչն է կարգավորում գործող համաշխարհային պրոքսին:"</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"Սահմանել էկրանի կողպման գաղտնաբառի սպառման ժամկետը"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"Վերահսկել` ինչ հաճախականությամբ պետք է էկրանի կողպման գաղտնաբառը փոխվի:"</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"Կարգավորել պահոցի կոդավորումը"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"Պահանջել, որ պահվող հավելվածների տվյալները լինեն կոդավորված:"</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"Կասեցնել տեսախցիկները"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"Կանխել բոլոր սարքերի ֆոտոխցիկների օգտագործումը:"</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"Անջատել ստեղնակողպեքի գործառույթները"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"Կանխել ստեղնակողպեքի որոշ գործառույթների օգտագործումը:"</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"Տնային"</item>
-    <item msgid="869923650527136615">"Բջջային"</item>
-    <item msgid="7897544654242874543">"Աշխատանքային"</item>
-    <item msgid="1103601433382158155">"Աշխատանքային ֆաքս"</item>
-    <item msgid="1735177144948329370">"Տնային ֆաքս"</item>
-    <item msgid="603878674477207394">"Փեյջեր"</item>
-    <item msgid="1650824275177931637">"Այլ"</item>
-    <item msgid="9192514806975898961">"Հատուկ"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"Տուն"</item>
-    <item msgid="7084237356602625604">"Աշխատանքային"</item>
-    <item msgid="1112044410659011023">"Այլ"</item>
-    <item msgid="2374913952870110618">"Հատուկ"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"Տնային"</item>
-    <item msgid="5629153956045109251">"Աշխատանքային"</item>
-    <item msgid="4966604264500343469">"Այլ"</item>
-    <item msgid="4932682847595299369">"Հատուկ"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"Տնային"</item>
-    <item msgid="1359644565647383708">"Աշխատանքային"</item>
-    <item msgid="7868549401053615677">"Այլ"</item>
-    <item msgid="3145118944639869809">"Հատուկ"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"Աշխատանքային"</item>
-    <item msgid="4378074129049520373">"Այլ"</item>
-    <item msgid="3455047468583965104">"Հատուկ"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"Հատուկ"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"Տնային"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"Բջջային"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"Աշխատանքային"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"Աշխատանքային ֆաքս"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"Տնային ֆաքս"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"Փեյջեր"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"Այլ"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"Ետզանգ"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"Մեքենա"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"Ընկերության գլխավոր"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"Հիմնական"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"Այլ ֆաքս"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"Ռադիո"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"Տելեքս"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"Աշխատանքային բջջային համար"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"Աշխատանքային փեյջեր"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"Օգնական"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"Հատուկ"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"Ծննդյան օր"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"Տարեդարձ"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"Այլ"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"Հատուկ"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"Տնային"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"Աշխատանքային"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"Այլ"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"Բջջային"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"Հատուկ"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"Տնային"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"Աշխատանքային"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"Այլ"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"Հատուկ"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"Տուն"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"Աշխատանքային"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"Այլ"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"Հատուկ"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Hangouts"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"Աշխատանքային"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"Այլ"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"Հատուկ"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"Հատուկ"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"Օգնական"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"Եղբայր"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"Երեխա"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"Տեղական գործընկեր"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"Հայր"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"Ընկեր"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"Կառավարիչ"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"Մայր"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"Ծնող"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"Գործընկեր"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"Հղված է"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"Բարեկամ"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"Քույր"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"Ամուսին"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"Հատուկ"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"Տնային"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"Աշխատանքային"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"Այլ"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"Մուտքագրեք PIN կոդը"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"Մուտքագրեք PUK-ը և նոր PIN կոդը"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK կոդ"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Նոր PIN ծածկագիր"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Հպեք` գաղտնաբառը մուտքագրելու համար"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Մուտքագրեք գաղտնաբառը ապակողպման համար"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Մուտքագրեք PIN-ը ապակողպման համար"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Սխալ PIN ծածկագիր:"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Ապակողպման համար սեղմեք Ցանկ, ապա 0:"</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"Արտակարգ իրավիճակների հեռախոսահամար"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"Ծառայություն չկա:"</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"Էկրանը կողպված է:"</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"Սեղմեք Ցանկ` ապակողպելու համար, կամ կատարեք արտակարգ իրավիճակների զանգ:"</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"Ապակողպելու համար սեղմեք Ցանկը:"</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"Հավաքեք սխեման` ապակողպելու համար"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"Արտակարգ իրավիճակների հեռախոսազանգ"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"Վերադառնալ զանգին"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"Ճիշտ է:"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Կրկին փորձեք"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Կրկին փորձեք"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Առավելագույն Դեմքով ապակողպման փորձերը գերազանցված են"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"Լիցքավորում, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"Լիցքավորված է"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"Միացրեք ձեր լիցքավորիչը:"</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM քարտ չկա"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"Գրասալիկում SIM քարտ չկա:"</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"Հեռախոսում SIM քարտ չկա:"</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"Մտցրեք SIM քարտը:"</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM քարտը բացակայում է կամ չի կարող կարդացվել: Մտցրեք SIM քարտ:"</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"Անպիտան SIM քարտ:"</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"Ձեր SIM քարտը ընդմիշտ կասեցված է:\n Կապվեք ձեր անլար ծառայությունների մատակարարի հետ մեկ այլ SIM քարտի համար:"</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"Նախորդ հետքի կոճակ"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"Հաջորդ հետագծի կոճակ"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"Դադարի կոճակ"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"Նվագարկման կոճակ"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"Կանգի կոճակ"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"Միայն արտակարգ իրավիճակների զանգեր"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"Ցանցը կողպված է"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM քարտը PUK-ով կողպված է:"</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"Տեսեք Օգտվողի ուղեցույցը կամ դիմեք Բաժանորդների սպասարկման կենտրոն:"</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM քարտը կողպված է:"</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM քարտը ապակողպվում է…"</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման սխեման: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"Դուք սխալ եք մուտքագրել ձեր գաղտնաբառը <xliff:g id="NUMBER_0">%d</xliff:g> անգամ: \n\n Փորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք մուտքագրել ձեր PIN-ը: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման սխեման: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո ձեզ կառաջարկվի ապակողպել ձեր գրասալիկը` օգտագործելով ձեր Google-ի մուտքի օգտանունը:\n \n Փորձեք կրկին <xliff:g id="NUMBER_2">%d</xliff:g> վայրկյանից:"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման սխեման: Եվս <xliff:g id="NUMBER_1">%d</xliff:g> անհաջող փորձից հետո ձեզ կառաջարկվի ապակողպել ձեր հեռախոսը` օգտագործելով Google-ի ձեր մուտքը:\n \n Փորձեք կրկին <xliff:g id="NUMBER_2">%d</xliff:g> վայրկյանից:"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ գրասալիկն ապակողպելու սխալ փորձ եք արել: Եվս <xliff:g id="NUMBER_1">%d</xliff:g> անհաջող փորձից հետո գրասալիկը կվերակարգավորվի գործարանային լռելյայնի, և օգտվողի բոլոր տվյալները կկորեն:"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ հեռախոսը ապակողպելու սխալ փորձ եք արել: Եվս <xliff:g id="NUMBER_1">%d</xliff:g> անհաջող փորձից հետո հեռախոսը կվերակարգավորվի գործարանային սկզբնադիր ռեժիմի, և օգտվողի բոլոր տվյալները կկորեն:"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"Դուք <xliff:g id="NUMBER">%d</xliff:g> անգամ սխալ փորձ եք արել գրասալիկն ապակողպելու համար: Գրասալիկն այժմ կվերակարգավորվի գործարանային լռելյայնի:"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"Դուք <xliff:g id="NUMBER">%d</xliff:g> անգամ հեռախոսը ապակողպելու սխալ փորձ եք արել: Հեռախոսն այժմ կվերակարգավորվի գործարանային սկզբնադիր ռեժիմի:"</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"Փորձեք կրկին <xliff:g id="NUMBER">%d</xliff:g> վայրկյանից:"</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"Մոռացե՞լ եք սխեման:"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"Հաշվի ապակողպում"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"Չափից շատ սխեմայի փորձեր"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"Ապակողպելու համար` մուտք գործեք ձեր Google հաշվով:"</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"Օգտանուն (էլփոստ)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"Գաղտնաբառ"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"Մուտք գործել"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"Անվավեր օգտանուն կամ գաղտնաբառ:"</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"Մոռացե՞լ եք ձեր օգտանունը կամ գաղտնաբառը:\nԱյցելեք "<b>"google.com/accounts/recovery"</b>":"</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"Ստուգվում է..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"Ապակողպել"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"Ձայնը միացնել"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"Անձայն"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"Սխեմայի հավաքումը սկսված է"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"Սխեման մաքրված է"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"Ավելացվել է վանդակ"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"Սխեմայի հավաքումն ավարտված է"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Վիջեթ %2$d of %3$d:"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Ավելացնել վիջեթ:"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Դատարկ"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Ապակողպման տարածքն ընդլայնված է:"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Ապակողպման տարածքը ետ է ծալված:"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> վիջեթ:"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Օգտվողի ընտրիչ"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Կարգավիճակ"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Ֆոտոխցիկ"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Մեդիա կարգավորումներ"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Վիջեթների վերադասավորումը մեկնարկել է:"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Վիջեթի վերադասավորումն ավարտվեց:"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Վիջեթ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>-ը ջնջված է:"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Ընդլայնել ապակողպման տարածությունը:"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Էջի ապակողպում:"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Սխեմայով ապակողպում:"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Դեմքով ապակողպում:"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin-ն ապակողպված է:"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Գաղտնաբառի ապակողպում:"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Սխեմայի տարածք:"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Սահեցման տարածք:"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"բնույթը"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"բառ"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"հղում"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"գիծ"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"Գործարանային թեստը ձախողվեց"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"FACTORY_TEST գործողությունը միայն աջակցվում է /համակարգում/ծրագրում տեղադրված փաթեթների համար:"</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"Չի գտնվել ոչ մի փաթեթ, որը ապահովում է FACTORY_TEST գործողությունը:"</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"Վերաբեռնել"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"«<xliff:g id="TITLE">%s</xliff:g>»-ի էջում ասվում է`"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"Հաստատել կողմնորոշումը"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"Լքել այս էջը"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"Մնալ այս էջում"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nՎստա՞հ եք, որ ցանկանում եք հեռանալ այս էջից:"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"Հաստատել"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"Հուշակ` կրկնակի հպեք` մեծացնելու և փոքրացնելու համար:"</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"Ինքնալրացում"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"Դնել ինքնալրացում"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"Գավառ"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"Փոստային ինդեքս"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"Նահանգ"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"Փոստային կոդ"</string>
-    <string name="autofill_county" msgid="237073771020362891">"Մարզ"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"Կղզի"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"Շրջան"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"Դեպարտամենտ"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"Պրեֆեկտուրա"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"Ծուխ"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"Տարածք"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"Էմիրություն"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"կարդալ ձեր վեբ էջանիշերը և պատմությունը"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"Թույլ է տալիս հավելվածին կարդալ դիտարկչի այցելած բոլոր URL-ների պատմությունը և դիտարկչի բոլոր էջանիշերը: Նշում. այս թույլտվությունը չի կարող գործածվել կողմնակի դիտարկիչների կամ վեբ զննարկման հնարավորություններով այլ հավելվածների կողմից:"</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"գրել վեբ էջանիշերը և պատմությունը"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"Թույլ է տալիս հավելվածին փոփոխել դիտարկչի պատմությունը կամ ձեր գրասալիկում պահված էջանիշերը: Այն կարող է թույլ տալ հավելվածին ջնջել կամ փոփոխել դիտարկչի տվյալները: Նշում. այս թույլտվությունը չի կարող գործածվել կողմնակի դիտարկիչների կամ վեբ զննարկման հնարավորություններով այլ հավելվածների կողմից:"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"Թույլ է տալիս հավելվածին փոփոխել դիտարկչի պատմությունը կամ ձեր հեռախոսում պահված էջանիշերը: Այն կարող է թույլ տալ հավելվածին ջնջել կամ փոփոխել դիտարկչի տվյալները: Նշում. այս թույլտվությունը չի կարող գործածվել կողմնակի դիտարկիչների կամ վեբ զննարկման հնարավորություններով այլ հավելվածների կողմից:"</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"դնել ազդանշան"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"Թույլ է տալիս հավելվածին սահմանել զարթուցիչի ծրագրում տեղադրված ազդանշանը: Զարթուցիչի որոշ հավելվածներ չեն կարող կիրառել այս հատկությունը:"</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"ավելացնել ձայնային փոստ"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"Թույլ է տալիս հավելվածին ավելացնել հաղորդագրություններ ձեր ձայնային փոստի արկղում:"</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"փոփոխել դիտարկչի աշխարհագրական տեղանքի թույլտվությունները"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"Թույլ է տալիս հավելվածին փոփոխել զննարկչի աշխարհագրական դիրքի թույլտվությունները: Վնասարար հավելվածները կարող են օգտագործել սա` թույլատրելու ուղարկել տեղադրության վերաբերյալ տեղեկությունները կամայական վեբ կայքերին:"</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"հաստատել փաթեթները"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"Թույլ է տալիս հավելվածին հաստատել, որ փաթեթը տեղադրելի է:"</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"միանալ փաթեթի ստուգիչին"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"Թույլ է տալիս սեփականատիրոջը փաթեթի ստուգիչների հարցում կատարել: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"մուտք գործել հաջորդական միացքներ"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"Թույլ է տալիս սեփականատիրոջը մուտք գործել հաջորդական միացքներ` օգտագործելով SerialManager API-ը:"</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"դրսից մատչել բովանդակություն տրամադրողներին"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"Սեփականատիրոջը հնարավորություն է տալիս կապվել ծառայության մատակարարների հետ վահանակից: Սովորական հավելվածների համար երբևէ չպետք է անհրաժեշտ լինի:"</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"կասեցնել սարքի ավտոմատ թարմացումները"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"Թույլ է տալիս սեփականատիրոջը համակարգին տեղեկացնել հարմար ժամանակի մասին` սարքը նորացնելու նպատակով ոչ փոխազդական վերաբեռնման համար:"</string>
-    <string name="save_password_message" msgid="767344687139195790">"Ցանկանու՞մ եք, որ դիտարկիչը հիշի այս գաղտնաբառը:"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"Ոչ հիմա"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"Հիշել"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"Երբեք"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"Դուք չունեք այս էջը բացելու թույլտվություն:"</string>
-    <string name="text_copied" msgid="4985729524670131385">"Տեքստը պատճենված է սեղմատախտակին:"</string>
-    <string name="more_item_label" msgid="4650918923083320495">"Ավելին"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"Ցանկ+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"բացակ"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"մուտք"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"ջնջել"</string>
-    <string name="search_go" msgid="8298016669822141719">"Որոնել"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"Որոնել"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"Որոնել հարցումը"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"Մաքրել հարցումը"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"Ուղարկել հարցումը"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"Ձայնային որոնում"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"Միացնե՞լ  Հպման միջոցով հետազոտումը:"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>-ը ցանկանում է միացնել «Հետազոտում հպման միջոցով» ռեժիմը: Երբ միացված է «Հետազոտում հպման միջոցով» ռեժիմը, դուք կարող եք լսել կամ տեսնել նկարագրությունը, թե ինչ է ձեր մատի տակ, կամ կատարել ժեստեր`  գրասալիկի հետ փոխգործակցելու համար:"</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>-ը ցանկանում է միացնել «Հետազոտում հպման միջոցով» ռեժիմը: Երբ միացված է «Հետազոտում հպման միջոցով» ռեժիմը, դուք կարող եք լսել կամ տեսնել նկարագրությունը, թե ինչ է ձեր մատի տակ, կամ կատարել ժեստեր`  հեռախոսի հետ փոխգործակցելու համար:"</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"1 ամիս առաջ"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"Ավելի շուտ քան 1 ամիս"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"1 վայրկյան առաջ"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> վայրկյան առաջ"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"1 րոպե առաջ"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> րոպե առաջ"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"1 ժամ առաջ"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> ժամ առաջ"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"Վերջին <xliff:g id="COUNT">%d</xliff:g> օրերին"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"Անցյալ ամիս"</string>
-    <string name="older" msgid="5211975022815554840">"Ավելի հին"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"երեկ"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> օր առաջ"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"1 վայրկյանից"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> վայրկյանից"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"1 րոպեից"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g> րոպեից"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"1 ժամից"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> ժամից"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"վաղը"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> օրից"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"1 վրկ առաջ"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> վրկ. առաջ"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"1 րոպե առաջ"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> րոպե առաջ"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"1 ժամ առաջ"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> ժամ առաջ"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"երեկ"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> օր առաջ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"1 վրկ-ից"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> վրկ-ից"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"1 րոպեից"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> րոպեից"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"1 ժամից"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> ժամից"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"վաղը"</item>
-    <item quantity="other" msgid="2973062968038355991">"<xliff:g id="COUNT">%d</xliff:g> օրից"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g>-ին"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"ժամը <xliff:g id="TIME">%s</xliff:g>-ին"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> թվականին"</string>
-    <string name="day" msgid="8144195776058119424">"օր"</string>
-    <string name="days" msgid="4774547661021344602">"օր"</string>
-    <string name="hour" msgid="2126771916426189481">"ժամ"</string>
-    <string name="hours" msgid="894424005266852993">"ժամ"</string>
-    <string name="minute" msgid="9148878657703769868">"րոպե"</string>
-    <string name="minutes" msgid="5646001005827034509">"րոպե"</string>
-    <string name="second" msgid="3184235808021478">"վրկ"</string>
-    <string name="seconds" msgid="3161515347216589235">"վրկ"</string>
-    <string name="week" msgid="5617961537173061583">"շաբաթ"</string>
-    <string name="weeks" msgid="6509623834583944518">"շաբաթ"</string>
-    <string name="year" msgid="4001118221013892076">"տարի"</string>
-    <string name="years" msgid="6881577717993213522">"տարի"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 վայրկյան"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> վայրկյան"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"1 րոպե"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> րոպե"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"1 ժամ"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> ժամ"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"Տեսանյութի խնդիր"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"Այս տեսանյութը հեռարձակման ենթակա չէ այս սարքով:"</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"Այս տեսանյութը հնարավոր չէ նվագարկել:"</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"Լավ"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"կեսօր"</string>
-    <string name="Noon" msgid="3342127745230013127">"Կեսօր"</string>
-    <string name="midnight" msgid="7166259508850457595">"կեսգիշեր"</string>
-    <string name="Midnight" msgid="5630806906897892201">"Կեսգիշեր"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"Ընտրել բոլորը"</string>
-    <string name="cut" msgid="3092569408438626261">"Կտրել"</string>
-    <string name="copy" msgid="2681946229533511987">"Պատճենել"</string>
-    <string name="paste" msgid="5629880836805036433">"Տեղադրել"</string>
-    <string name="replace" msgid="5781686059063148930">"Փոխարինել..."</string>
-    <string name="delete" msgid="6098684844021697789">"Ջնջել"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"Պատճենել URL-ը"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"Ընտրել տեքստ"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"Տեքստի ընտրություն"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"Ավելացնել բառարանում"</string>
-    <string name="deleteText" msgid="6979668428458199034">"Ջնջել"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"Մուտքագրման եղանակը"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"Տեքստի գործողությունները"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"Պահոցային տարածքը սպառվում է"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"Համակարգի որոշ գործառույթներ հնարավոր է չաշխատեն"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g>-ն աշխատեցվում է"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"Հպեք` լրացուցիչ տեղեկությունները կամ ծրագիրը դադարեցնելու համար:"</string>
-    <string name="ok" msgid="5970060430562524910">"Լավ"</string>
-    <string name="cancel" msgid="6442560571259935130">"Չեղարկել"</string>
-    <string name="yes" msgid="5362982303337969312">"Լավ"</string>
-    <string name="no" msgid="5141531044935541497">"Չեղարկել"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"Ուշադրություն"</string>
-    <string name="loading" msgid="7933681260296021180">"Բեռնում..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"Միացնել"</string>
-    <string name="capital_off" msgid="6815870386972805832">"Անջատել"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"ավարտել գործողությունը` օգտագործելով"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"Օգտագործել լռելյայն այս գործողության համար:"</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"Մաքրել լռելյայնը Համակարգի կարգավորումներ &gt; Ծրագրեր &gt;Ներբեռնված էջից:"</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"Ընտրել գործողություն"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"Ընտրեք հավելված USB սարքի համար"</string>
-    <string name="noApplications" msgid="2991814273936504689">"Ոչ մի հավելված չի կարող կատարել այս գործողությունը:"</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"Ցավոք, <xliff:g id="APPLICATION">%1$s</xliff:g>-ը ընդհատվել է:"</string>
-    <string name="aerr_process" msgid="4507058997035697579">"Ցավոք, <xliff:g id="PROCESS">%1$s</xliff:g> գործընթացը դադարել է:"</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g>-ը չի արձագանքում:\n\nՑանկանու՞մ եք փակել այն:"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> գործողությունը չի պատասխանում:\n\nՑանկանու՞մ եք այն փակել:"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g>-ը չի արձագանքում: Ցանկանու՞մ եք փակել այն:"</string>
-    <string name="anr_process" msgid="6513209874880517125">"<xliff:g id="PROCESS">%1$s</xliff:g> գործընթացը չի արձագանքում:\n\nՑանկանու՞մ եք փակել այն:"</string>
-    <string name="force_close" msgid="8346072094521265605">"Լավ"</string>
-    <string name="report" msgid="4060218260984795706">"Զեկույց"</string>
-    <string name="wait" msgid="7147118217226317732">"Սպասեք"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"Էջը չի պատասխանում:\n\nՑանկանու՞մ եք փակել այն:"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"Հավելվածը վերահղվել է"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g>-ն այժմ աշխատում է:"</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g>-ը ի սկզբանե թողարկվել է:"</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"Աստիճանակարգել"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"Միշտ ցույց տալ"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"Կրկին ակտիվացնել սա Համակարգի կարգավորումներում &amp;gt Ծրագրեր &gt; Ներբեռնումներ:"</string>
-    <string name="smv_application" msgid="3307209192155442829">"<xliff:g id="APPLICATION">%1$s</xliff:g> ծրագիրը (գործընթաց <xliff:g id="PROCESS">%2$s</xliff:g>) խախտել է իր ինքնահարկադրված Խիստ ռեժիմ  քաղաքականությունը:"</string>
-    <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> գործընթացը խախտել է իր ինքնահարկադրված Խիստ ռեժիմ քաղաքականությունը:"</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android-ը նորացվում է..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"Հավելվածը օպտիմալացվում է <xliff:g id="NUMBER_0">%1$d</xliff:g>-ից <xliff:g id="NUMBER_1">%2$d</xliff:g>-ի:"</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"Հավելվածները մեկնարկում են:"</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"Բեռնումն ավարտվում է:"</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g>-ն աշխատում է"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"Հպեք` հավելվածին անցնելու համար"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"Փոխարկե՞լ հավելվածները:"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"Մեկ այլ ծրագիր արդեն աշխատում է, որը պետք է դադարեցնել, նախքան դուք կկարողանաք սկսել նորը:"</string>
-    <string name="old_app_action" msgid="493129172238566282">"Վերադառնալ <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"Չսկսել նոր հավելված:"</string>
-    <string name="new_app_action" msgid="5472756926945440706">"Սկիզբ <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"Դադարեցնել նախկին ծրագիրն առանց պահպանման:"</string>
-    <string name="sendText" msgid="5209874571959469142">"Ընտրեք գործողություն տեքստի համար"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"Զանգակի ձայնի ուժգնությունը"</string>
-    <string name="volume_music" msgid="5421651157138628171">"Մեդիա ձայնի բարձրություն"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"Նվագարկում է Bluetooth-ի միջոցով"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"Սահմանվել է անձայն զանգերանգ"</string>
-    <string name="volume_call" msgid="3941680041282788711">"Մուտքային զանգի ձայնի ուժգնությունը"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"Bluetooth-ի ներզանգի բարձրություն"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"Զարթուցիչի ձայնի ուժգնությունը"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"Ծանուցումների ձայնի ուժգնությունը"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"Ձայն"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"Bluetooth-ի ձայնի ուժգնությունը"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"Զանգերանգի բարձրություն"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"Զանգի ձայնի բարձրություն"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"Մեդիա ձայնի բարձրություն"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"Ծանուցումների ձայնի ուժգնությունը"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"Լռելյայն զանգերանգ"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"Լռելյայն զանգերանգ (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"Ոչ մեկը"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"Զանգերանգներ"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"Անհայտ զանգերանգ"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi ցանցը հասանելի է"</item>
-    <item quantity="other" msgid="4192424489168397386">"հասանելի են Wi-Fi ցանցեր"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"Բաց Wi-Fi ցանցը հասանելի է"</item>
-    <item quantity="other" msgid="7915895323644292768">"Հասանելի են բաց Wi-Fi ցանցեր"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Մուտք գործեք Wi-Fi ցանց"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"Մուտք գործել ցանց"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Չհաջողվեց միանալ Wi-Fi-ին"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" ունի թույլ ինտերնետ կապ:"</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"Wi-Fi ուղիղ"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"Մեկնարկել Wi-Fi ուղին: Այն կանջատի Wi-Fi հաճախորդ/թեժ կետ գործողությունը:"</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"Չհաջողվեց մեկնարկել Wi-Fi ուղին:"</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi ուղիղն առցանց է"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"Հպեք կարգավորումների համար"</string>
-    <string name="accept" msgid="1645267259272829559">"Ընդունել"</string>
-    <string name="decline" msgid="2112225451706137894">"Մերժել"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"Հրավերն ուղարկված է"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"Միացման հրավեր"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"Ուղարկող`"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"Ում`"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"Մուտքագրեք պահանջվող PIN-ը:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN-ը`"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"Գրասալիկը ժամանակավորապես կանջատվի Wi-Fi-ից, քանի դեռ այն կապակցված է <xliff:g id="DEVICE_NAME">%1$s</xliff:g>-ին"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"Հեռախոսը ժամանակավորապես կանջատվի Wi-Fi-ից, քանի դեռ այն միացված է <xliff:g id="DEVICE_NAME">%1$s</xliff:g>-ին"</string>
-    <string name="select_character" msgid="3365550120617701745">"Զետեղել նշան"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS հաղորդագրությունների ուղարկում"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt;-ը ուղարկում է մեծ թվով SMS հաղորդագրություններ: Ցանկանու՞մ եք թույլատրել այս հավելվածին շարունակել ուղարկել հաղորդագրություններ:"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"Թույլատրել"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"Ժխտել"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>-ը&lt;/b&gt; ուզում է հաղորդագրություն ուղարկել &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>-ին&lt;/b&gt;:"</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"Այս "<font fgcolor="#ffffb060">"-ը կարող է գանձումներ առաջացնել"</font>" ձեր բջջային հաշվի վրա:"</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"Սրա հետևանքով ձեր բջջային հաշվին կներկայացվի հաշիվ:"</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"Ուղարկել"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"Չեղարկել"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"Հիշել իմ ընտրությունը"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"Դուք կարող եք փոխել սա ավելի ուշ Կարգավորումներում  &gt; Ծրագրերում"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"Միշտ թույլատրել"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"Երբեք չթույլատրել"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM քարտը հեռացված է"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"Բջջային ցանցը անհասանելի կլինի, մինչև չվերագործարկեք վավեր SIM քարտ տեղադրելուց հետո:"</string>
-    <string name="sim_done_button" msgid="827949989369963775">"Կատարված"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM քարտը ավելացվել է"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"Վերագործարկեք ձեր սարքը` բջջային ցանց մուտք ունենալու համար:"</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"Վերագործարկել"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"Սահմանել ժամը"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"Սահմանել ամսաթիվը"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"Սահմանել"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"Կատարված է"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"Նոր` "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"Տրամադրված է <xliff:g id="APP_NAME">%1$s</xliff:g>-ի կողմից:"</string>
-    <string name="no_permissions" msgid="7283357728219338112">"Թույլտվություններ չեն պահանջվում"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"Սա կարող է գումար պահանջել"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB զանգվածային կրիչ"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB-ն կապակցված  է"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"Դուք կապակցվել եք ձեր համակարգչին USB-ի միջոցով: Հպեք ներքևի կոճակը, եթե ցանկանում եք պատճենել ֆայլերը ձեր համակարգչի և ձեր Android-ի USB կրիչի միջև:"</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"Դուք միացել եք ձեր համակարգչին USB-ի միջոցով: Հպեք ներքևի կոճակին, եթե ցանկանում եք պատճենել ֆայլերը ձեր համակարգչի և ձեր Android-ի SD քարտի միջև:"</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"Միացնել USB կրիչը"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"Խնդիր է ծագել ձեր USB կրիչը USB զանգվածային կրիչի համար օգտագործելիս:"</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"Խնդիր է ծագել ձեր SD քարտը USB զանգվածային կրիչի համար օգտագործելիս:"</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB-ն կապակցված է"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"Հպեք` ֆայլերը պատճենելու համար ձեր համակարգչում կամ համակարգչից:"</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"Անջատել USB կրիչը"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"Հպեք` USB կրիչն անջատելու համար:"</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB կրիչը օգտագործվում է"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"Նախքան USB կրիչն անջատելը, անջատեք («հանեք») ձեր Android-ի USB կրիչը համակարգչից:"</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"Նախքան USB կրիչն անջատելը, անջատեք («հանեք») ձեր Android-ի SD քարտը համակարգչից:"</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"Անջատել USB կրիչը"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"Խնդիր առաջացավ USB կրիչն անջատելիս: Ստուգեք, արդյոք անջատել եք USB հանգույցը, ապա փորձեք կրկին:"</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"Միացնել USB կրիչը"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"Եթե ​​դուք միացնեք USB կրիչը, որոշ ծրագրեր,որոնցից օգտվում եք, կդադարեն աշխատել և կարող են անհասանելի լինել, քանի դեռ չեք անջատել USB կրիչը:"</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB գործողությունը անհաջող էր"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"Լավ"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"Կապակցված է որպես մեդիա սարք"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"Միացված է որպես ֆոտոխցիկ"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"Միացված է որպես տեղադրիչ"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"Կապակցված է USB լրասարքի"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"Հպեք` այլ USB ընտրանքների համար:"</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"Ֆորմատավորե՞լ USB կրիչը:"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"Ֆորմատավորե՞լ SD քարտը:"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"Ձեր USB կրիչում պահվող բոլոր ֆայլերը կջնջվեն: Այս գործողությունը անշրջելի է:"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"Ձեր քարտի բոլոր տվյալները կկորեն:"</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"Ձևաչափ"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB վրիպազերծումը միացված է"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"Հպեք` USB կարգաբերումը կասեցնելու համար:"</string>
-    <string name="select_input_method" msgid="4653387336791222978">"Ընտրեք մուտքագրման եղանակը"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"Կարգավորել ներածման եղանակները"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"Ֆիզիկական ստեղնաշար"</string>
-    <string name="hardware" msgid="7517821086888990278">"Սարքաշար"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"Ընտրեք ստեղնաշարի դիրքը"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"Հպեք` ստեղնաշարի դիրքը ընտրելու համար:"</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՈՒՓՔԵւՕՖ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"թեկնածուները"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"Պատրաստում է USB կրիչը"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"Պատրաստվում է SD քարտը"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"Սխալների ստուգում:"</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"USB կրիչը դատարկ է"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"Դատարկ SD քարտ"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB կրիչը դատարկ է կամ ունի չաջակցվող ֆայլային համակարգ:"</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD քարտը դատարկ է կամ ունի չաջակցվող ֆայլային համակարգ:"</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"Վնասված USB կրիչ"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"Վնասված SD քարտ"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB կրիչը վնասված է: Փորձեք վերաֆորմատավորել այն:"</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD քարտը վնասված է: Փորձեք վերաֆորմատավորել այն:"</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB կրիչն անսպասելիորեն հեռացվել է"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD քարտը անսպասելիորեն հեռացվել է"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"Անջատել USB կրիչը հեռացնելուց առաջ` տվյալների կորստից խուսափելու համար:"</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"Անջատել SD քարտը հեռացնելուց առաջ` տվյալների կորստից խուսափելու համար:"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB կրիչը կարող է անվտանգ հեռացվել"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD քարտն անվտանգ է հեռացման համար"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"Դուք կարող եք ապահով հեռացնել USB կրիչը:"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"Դուք կարող եք անվտանգ հեռացնել SD քարտը:"</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"USB կրիչը հեռացված է"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"SD քարտը հեռացված է"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB կրիչը հեռացված է: Մտցրեք նոր կրիչ:"</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD քարտը հեռացված է: Տեղադրեք նորը:"</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"Համընկնող գործունեություններ չգտնվեցին:"</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"թարմացնել բաղադրիչի օգտագործման վիճակագրությունը"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"Թույլ է տալիս հավելվածին փոփոխել հավաքագրված բաղադրիչի վիճակագրությունը: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"պատճենել բովանդակությունը"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"Թույլ է տալիս հայցել լռելյայն զետեղարանի ծառայությունը` բովանդակությունը պատճենելու համար: Սովորական հավելվածների օգտագործման համար չէ:"</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"Երթուղել մեդիա արտածումը"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"Թույլ է տալիս հավելվածին մեդիա արտածումը երթուղել այլ արտաքին սարքեր:"</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"Մուտք գործել ստեղնակողպեքով պաշտպանված պահոց"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"Թույլ է տալիս հավելվածին մուտք գործել ստեղնակողպեքով պաշտպանված պահոց:"</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"Կառավարել ստեղնակողպեքի ցուցադրումը և թաքցնումը"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"Թույլ է տալիս հավելվածին կառավարել ստեղնաշարի պաշտպանիչը:"</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"Հպեք երկու անգամ` դիտափոխման կարգավորման համար"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"Չհաջողվեց վիջեթ ավելացնել:"</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"Առաջ"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"Որոնել"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"Ուղարկել"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"Հաջորդը"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"Կատարված է"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"Նախորդ"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"Կատարել"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"Հավաքել հեռախոսահամարը`\nօգտագործելով <xliff:g id="NUMBER">%s</xliff:g>-ը"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"Ստեղծել կոնտակտ`\nօգտագործելով <xliff:g id="NUMBER">%s</xliff:g>-ը"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"Հետևյալ մեկ կամ ավել հավելվածներ մուտքի թույլտվության հարցում են անում` այժմ և հետագայում ձեր հաշվին մուտք ունենալու համար:"</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"Ցանկանու՞մ եք թույլատրել այս հարցումը:"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"Մուտքի հարցում"</string>
-    <string name="allow" msgid="7225948811296386551">"Թույլատրել"</string>
-    <string name="deny" msgid="2081879885755434506">"Մերժել"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"Թույլտվության հարցում է արված"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"Թույլտվության հարցում է արված\n<xliff:g id="ACCOUNT">%s</xliff:g> հաշվի համար:"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"Ներածման եղանակը"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"Համաժամել"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"Մատչելիությունը"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"Պաստառ"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"Փոխել պաստառը"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"Ծանուցման ունկնդիր"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN-ը ակտիվացված է"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN-ն ակտիվացված է <xliff:g id="APP">%s</xliff:g>-ի կողմից"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"Հպեք` ցանցի կառավարման համար:"</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"Միացված է <xliff:g id="SESSION">%s</xliff:g>-ին: Հպեք` ցանցը կառավարելու համար:"</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"Միշտ-միացված VPN-ը կապվում է..."</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"Միշտ-առցանց VPN-ը կապակցված է"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"VPN սխալը միշտ միացված"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"Հպեք կարգավորելու համար"</string>
-    <string name="upload_file" msgid="2897957172366730416">"Ընտրել ֆայլը"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"Ոչ մի ֆայլ չի ընտրված"</string>
-    <string name="reset" msgid="2448168080964209908">"Վերակայել"</string>
-    <string name="submit" msgid="1602335572089911941">"Ուղարկել"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"Մեքենայի ռեժիմը միացված է"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"Հպեք` մեքենայի ռեժիմից դուրս գալու համար:"</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"Մուտքը կամ թեժ կետը ակտիվ է"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"Հպեք կարգավորելու համար:"</string>
-    <string name="back_button_label" msgid="2300470004503343439">"Հետ"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"Հաջորդը"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"Բաց թողնել"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"Շարժական տվյալների օգտագործման բարձր մակարդակ"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"Հպեք` շարժական տվյալների օգտագործման մասին ավելին իմանալու համար:"</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"Շարժական տվյալների սահմանը գերազանցված է"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"Հպել` շարժական տվյալների օգտագործման մասին ավելին իմանալու համար:"</string>
-    <string name="no_matches" msgid="8129421908915840737">"Համընկնում չկա"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"Գտեք էջում"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"1 համընկնում"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="TOTAL">%d</xliff:g>-ից <xliff:g id="INDEX">%d</xliff:g>-ը"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"Կատարված է"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"Անջատվում է USB կրիչը..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"Անջատում է SD քարտը..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"Ջնջում է USB կրիչը..."</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"Ջնջում է SD քարտը..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"Չհաջողվեց ջնջել USB կրիչը:"</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD քարտը չհաջողվեց ջնջել:"</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD քարտը հեռացվել է նախքան անջատելը:"</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB կրիչն այժմ ստուգվում է:"</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD քարտը այժմ ստուգվում է:"</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD քարտը հեռացվել է:"</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"USB կրիչն այժմ օգտագործվում է համակարգչի կողմից:"</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD քարտն այժմ օգտագործվում է համակարգչի կողմից:"</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"Արտաքին մեդիան անհայտ է վիճակում է:"</string>
-    <string name="share" msgid="1778686618230011964">"Տարածել"</string>
-    <string name="find" msgid="4808270900322985960">"Գտնել"</string>
-    <string name="websearch" msgid="4337157977400211589">"Վեբի որոնում"</string>
-    <string name="find_next" msgid="5742124618942193978">"Գտնել հաջորդը"</string>
-    <string name="find_previous" msgid="2196723669388360506">"Գտնել նախորդը"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"Տեղադրության հարցում <xliff:g id="NAME">%s</xliff:g>-ից"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"Տեղադրության հարցում"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>)-ի հարցմամբ"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"Այո"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"Ոչ"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"Ջնջելու սահմանը գերազանցվել է"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> ջնջված տարր կա <xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g>-ի համար, <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g>-ի հաշիվ: Ի՞նչ եք ցանկանում անել:"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"Ջնջել տարրերը"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"Հետարկել ջնջումները"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"Առայժմ ոչինչ չանեք"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"Ընտրել հաշիվը"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"Ավելացնել հաշիվ"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"Ավելացնել հաշիվ"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"Ավելացնել"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"Նվազեցնել"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> հպեք և պահեք:"</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"Սահեցրեք վերև` ավելացնելու համար, և ներքև` նվազեցնելու համար:"</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"Աճեցնել րոպեն"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"Նվազեցնել րոպեն"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"Աճեցնել ժամը"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"Նվազեցնել ժամը"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"Դնել PM"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"Դնել AM"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"Աճեցնել ամիսը"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"Նվազեցնել ամիսը"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"Աճեցնել օրը"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"Նվազեցնել օրը"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"Աճեցնել տարին"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"Նվազեցնել տարին"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Չեղարկել"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Ջնջել"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Կատարված է"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Ռեժիմի փոփոխում"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Մուտք"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"Ընտրել ծրագիր"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"Տարածել"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"Համօգտագործել <xliff:g id="APPLICATION_NAME">%s</xliff:g>-ի հետ"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"Սահող բռնակ: Հպել &amp; պահել:"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"Սահեցրեք վերև <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"Սահեցրեք ցած <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"Սահեցրեք ձախ` <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"Սահեցրեք աջ` <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Ապակողպել"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Ֆոտոխցիկ"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Լուռ"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Ձայնը միացնել"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Որոնել"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"Սահեցրեք` ապակողպելու համար:"</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"Միացրեք ականջակալները` արտասանվող գաղտնաբառը լսելու համար:"</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"Կետ:"</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"Ուղղվել տուն"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"Ուղղվել վերև"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"Ավելի շատ ընտրանքներ"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"Ներքին պահոց"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD քարտ"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB կրիչ"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"Խմբագրել"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"Տվյալների օգտագործման նախազգուշացում"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"Հպեք` օգտագործումը և կարգավորումները տեսնելու համար:"</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G տվյալները կասեցված են"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G տվյալները անջատված են"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"Շարժական տվյալները կասեցված են"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi-Fi տվյալները անջատված են"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"Հպեք` միացնելու համար:"</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G տվյալների սահմանը գերազանցված է"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G տվյալների սահմանը գերազանցվել է"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"Շարժական տվյալների սահմանը գերազանցվել է"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi-Fi տվյալների սահմանը գերազանցվել է"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g>-ը գերազանցում է նշված սահմանաչափը:"</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"Հետնաշերտային տվյալները սահմանափակ են"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"Հպեք` սահմանափակումը հեռացնելու համար:"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"Անվտանգության վկայական"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"Այս վկայականը վավեր է:"</string>
-    <string name="issued_to" msgid="454239480274921032">"Թողարկվել է`"</string>
-    <string name="common_name" msgid="2233209299434172646">"Ընդհանուր անունը`"</string>
-    <string name="org_name" msgid="6973561190762085236">"Կազմակերպություն`"</string>
-    <string name="org_unit" msgid="7265981890422070383">"Կազմակերպական միավոր`"</string>
-    <string name="issued_by" msgid="2647584988057481566">"Թողարկվել է`"</string>
-    <string name="validity_period" msgid="8818886137545983110">"Վավերականություն`"</string>
-    <string name="issued_on" msgid="5895017404361397232">"Թողարկվել է`"</string>
-    <string name="expires_on" msgid="3676242949915959821">"Սպառվում է`"</string>
-    <string name="serial_number" msgid="758814067660862493">"Հերթական համարը`"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"Մատնահետքերը`"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 մատնահետք`"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1մատնահետք`"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"Տեսնել բոլորը"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"Ընտրել գործունեությունը"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"Տարածել"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"Սարքը կողպված է:"</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"Ուղարկվում է..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"Գործարկե՞լ զննարկիչը:"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"Ընդունե՞լ զանգը:"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"Միշտ"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"Միայն մեկ անգամ"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"Գրասալիկ"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"Հեռախոս"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"Ականջակալներ"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"Համակցված բարձրախոսներ"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"Համակարգ"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"Bluetooth-ի ձայնանյութ"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"Անլար էկրան"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"Կատարված է"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"Մեդիա արտածում"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"Սկանավորում..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"Միանում է..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"Հասանելի է"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"Հասանելի չէ"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"Զբաղեցված է"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"Ներկառուցված էկրան"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI էկրան"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"Վերածածկ #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>. <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> կմվ"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", անվտանգ"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"Անլար ցուցադրումը կապակցված է"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"Այս էկրանը ցուցադրվում է այլ սարքում"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"Անջատել"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Արտակարգ իրավիճակի հեռախոսազանգ"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Մոռացել եմ սխեման"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Սխալ սխեմա"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Սխալ գաղտնաբառ"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"Սխալ PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Փորձեք կրկին <xliff:g id="NUMBER">%1$d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Հավաքեք ձեր սխեման"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Մուտքագրեք SIM-ի PIN-ը"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"Մուտքագրեք PIN-ը"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Մուտքագրեք գաղտնաբառը"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM-ը այս պահին անջատված է: Մուտքագրեք PUK կոդը շարունակելու համար: Մանրամասների համար կապվեք օպերատորի հետ:"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Մուտքագրեք ցանկալի PIN ծածկագիրը"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Հաստատեք ցանկալի PIN ծածկագիրը"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"Ապակողպում է SIM քարտը ..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Սխալ PIN ծածկագիր:"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"Մուտքագրեք PIN, որը 4-ից 8 թիվ է:"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK կոդը պետք է լինի 8 կամ ավելի թիվ:"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Վերամուտքագրեք ճիշտ PUK ծածկագիրը: Կրկնվող փորձերը ընդմիշտ կկասեցնեն SIM քարտը:"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN ծածկագրերը չեն համընկնում"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Չափից շատ սխեմայի փորձեր"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Ապակողպելու համար` մուտք գործեք ձեր Google հաշվով:"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Օգտանուն (էլփոստ)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Գաղտնաբառը"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Մուտք գործել"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Սխալ օգտանուն կամ գաղտնաբառ:"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Մոռացե՞լ եք ձեր օգտանունը կամ գաղտնաբառը:\nԱյցելեք "<b>"google.com /accounts/recovery"</b>":"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Հաշիվը ստուգվում է..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք մուտքագրել ձեր PIN-ը: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Դուք սխալ եք մուտքագրել ձեր գաղտնաբառը <xliff:g id="NUMBER_0">%d</xliff:g> անգամ: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման սխեման: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ փորձ եք արել գրասալիկն ապակողպելու համար: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո գրասալիկը կվերակարգավորվի գործարանային լռելյայնի, և օգտվողի բոլոր տվյալները կկորեն:"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ փորձ եք արել հեռախոսն ապակողպելու համար: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո հեռախոսը կվերակարգավորվի գործարանային լռելյայնի, և օգտվողի բոլոր տվյալները կկորեն:"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Դուք <xliff:g id="NUMBER">%d</xliff:g> անգամ սխալ փորձ եք արել գրասալիկն ապակողպելու համար: Գրասալիկն այժմ կվերակարգավորվի գործարանային լռելյայնի:"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Դուք <xliff:g id="NUMBER">%d</xliff:g> անգամ սխալ փորձ եք արել հեռախոսն ապակողպելու համար: Հեռախոսն այժմ կվերակարգավորվի գործարանային լռելյայնի:"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Դուք սխալ եք հավաքել ձեր ապակողպման սխեման <xliff:g id="NUMBER_0">%d</xliff:g> անգամ: Եվս <xliff:g id="NUMBER_1">%d</xliff:g> անհաջող փորձից հետո ձեզանից կպահանջվի ապակողպել ձեր գրասալիկը` օգտագործելով էլփոստի հաշիվ:\n\n Փորձեք կրկին <xliff:g id="NUMBER_2">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման նմուշը: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո ձեզ կառաջարկվի ապակողպել ձեր հեռախոսը` օգտագործելով էլփոստի հաշիվ:\n\n Փորձեք կրկին <xliff:g id="NUMBER_2">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Հեռացնել"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"Բարձրացնե՞լ ձայնը առաջարկվող շեմից բարձր:\nԵրկար ժամանակ բարձրաձայն լսելը կարող է վնասել ձեր լսողությունը:"</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"Սեղմած պահեք երկու մատները` մատչելիությունը միացնելու համար:"</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"Մատչելիությունը միացված է:"</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"Մուտքի հնարավորությունը չեղարկված է:"</string>
-    <string name="user_switched" msgid="3768006783166984410">"Ներկայիս օգտվողը <xliff:g id="NAME">%1$s</xliff:g>:"</string>
-    <string name="owner_name" msgid="2716755460376028154">"Սեփականատեր"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"Սխալ"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"Այս ծրագիրը չի աջակցում սահմանափակված պրոֆիլների հաշիվներ:"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"Այս գործողությունը կատարելու համար ոչ մի ծրագիր չի գտնվել:"</string>
-    <string name="revoke" msgid="5404479185228271586">"Չեղարկել"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"Letter"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"Government Letter"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"Legal"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Junior Legal"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Ledger"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Tabloid"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"Չեղարկված է"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"Բովանդակության գրելու սխալ"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"Մուտքագրեք PIN-ը"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"Ընթացիկ PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"Նոր PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"Հաստատեք նոր PIN-ը"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"Ստեղծել PIN՝ սահմանափակումները փոփոխելու համար"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN-երը չեն համընկնում: Փորձեք կրկին:"</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN-ը չափազանց կարճ է: Պետք է ունենա առնվազն 4 թվանիշ:"</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"PIN-ը սխալ է: Փորձեք կրկին 1 վայրկյանից:"</item>
-    <item quantity="other" msgid="8030607343223287654">"PIN-ը սխալ է: Փորձեք կրկին <xliff:g id="COUNT">%d</xliff:g> վայրկյանից:"</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Սահեցրեք էկրանի եզրով՝ գոտին բացելու համար"</string>
-</resources>
diff --git a/core/res/res/values-in/strings.xml b/core/res/res/values-in/strings.xml
index 9a1c641..417c18e 100644
--- a/core/res/res/values-in/strings.xml
+++ b/core/res/res/values-in/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Coba <xliff:g id="COUNT">%d</xliff:g> detik lagi"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Coba lagi nanti"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Gesek ke bawah untuk keluar dari layar penuh"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Gesek ke bawah untuk keluar dari layar penuh"</string>
 </resources>
diff --git a/core/res/res/values-it/strings.xml b/core/res/res/values-it/strings.xml
index b05046b..d2dbfc3 100644
--- a/core/res/res/values-it/strings.xml
+++ b/core/res/res/values-it/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Riprova tra <xliff:g id="COUNT">%d</xliff:g> s."</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Riprova più tardi"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Uscita schermo intero: scorri in basso da alto"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Scorri dall\'alto verso il basso per uscire dalla modalità schermo intero."</string>
 </resources>
diff --git a/core/res/res/values-iw/strings.xml b/core/res/res/values-iw/strings.xml
index bef3386..51f3889 100644
--- a/core/res/res/values-iw/strings.xml
+++ b/core/res/res/values-iw/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"נסה שוב בעוד <xliff:g id="COUNT">%d</xliff:g> שניות"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"נסה שוב מאוחר יותר"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"החלק מטה מהחלק העליון כדי לצאת ממסך מלא"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"החלק מטה מהחלק העליון כדי לצאת ממסך מלא."</string>
 </resources>
diff --git a/core/res/res/values-ja/strings.xml b/core/res/res/values-ja/strings.xml
index 634ca2c..246a82e 100644
--- a/core/res/res/values-ja/strings.xml
+++ b/core/res/res/values-ja/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g>秒後に再試行"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"しばらくしてから再試行"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"全画面表示を終了するには、上から下にスワイプ"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"全画面表示を終了するには、上から下にスワイプ"</string>
 </resources>
diff --git a/core/res/res/values-ka-rGE/strings.xml b/core/res/res/values-ka-rGE/strings.xml
index b3e7c7d..a8025d8 100644
--- a/core/res/res/values-ka-rGE/strings.xml
+++ b/core/res/res/values-ka-rGE/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"კიდევ ერთხელ სცადეთ <xliff:g id="COUNT">%d</xliff:g> წამში"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"სცადეთ მოგვიანებით"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"ჩამოასრიალეთ ზევიდან სრული ეკრანის დასახურად"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"ჩამოასრიალეთ ზევიდან სრული ეკრანის დასახურად"</string>
 </resources>
diff --git a/core/res/res/values-ka/strings.xml b/core/res/res/values-ka/strings.xml
deleted file mode 100644
index a7c16ed..0000000
--- a/core/res/res/values-ka/strings.xml
+++ /dev/null
@@ -1,1587 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"კბაიტი"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"მბაიტი"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"გბაიტი"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"ტბაიტი"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"უსათაურო"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(ტელეფონის ნომრის გარეშე)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"უცნობი"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"ხმოვანი ფოსტა"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"კავშირის პრობლემა ან არასწორი MMI კოდი."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"ოპერაცია შეზღუდულია მხოლოდ დაშვებულ ნომრებზე."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"სერვისი ჩართულია."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"სერვისი ჩართულია შემდეგისთვის:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"სერვისი გამორთულია."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"რეგისტრაცია წარმატებით განხორციელდა."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"წაშლა წარმატებით განხორციელდა."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"პაროლი არასწორია"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI დასრულდა."</string>
-    <string name="badPin" msgid="9015277645546710014">"თქვენ მიერ შეყვანილი ძველი პინ-კოდი არასწორია."</string>
-    <string name="badPuk" msgid="5487257647081132201">"თქვენ მიერ შეყვანილი PUK კოდი არასწორია."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"თქვენ მიერ შეყვანილი PIN კოდები არ შეესატყვისება."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"აკრიფეთ PIN, რომელიც შედგება 4-დან 8 ციფრამდე."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"აკრიფეთ PUK, რომელიც რვა ან მეტი ციფრისგან შედგება."</string>
-    <string name="needPuk" msgid="919668385956251611">"თქვენი SIM ბარათი დაბლოკილია PUK კოდით. განბლოკვისთვის შეიყვანეთ PUK კოდი."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM ბარათის განსაბლოკად აკრიფეთ PUK2."</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"შემომავალი ზარის აბონენტის ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"გამავალი მრეკავის ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"ზარის გადამისამართება"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"ზარის ლოდინი"</string>
-    <string name="BaMmi" msgid="455193067926770581">"ზარის აკრძალვა"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"პაროლის შეცვლა"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN-ის შეცვლა"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"გამომძახებლის ნომერი წარმოდგენილია"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"შემოსული ზარი შეზღუდულია"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"დარეკვის სამი გზა"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"არასასურველი მომაბეზრებელი ზარების უარყოფა"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"დამრეკავი ნომრის მოწოდება"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"არ შემაწუხოთ"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"მრეკავის ID ნაგულისხმევად შეზღუდულია. შემდეგი ზარი: შეზღუდულია."</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"აბონენტის ID ნაგულისხმევად შეზღუდულია. შემდეგი ზარი: შეუზღუდავი."</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"აბონენტის ID უპირობოდ შეზღუდული არ არის. შემდეგი ზარი: შეზღუდულია."</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"აბონენტის ID ნაგულისხმევად შეზღუდული არ არის. შემდეგი ზარი: შეუზღუდავი."</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"სერვისი არ არის მიწოდებული."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"არ შეგიძლიათ აბონენტის ID პარამეტრების შეცვლა."</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"წვდომის შეზღუდვები შეცვლილია"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"ინტერნეტი დაბლოკილია."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"გადაუდებელი სამსახური დაბლოკილია."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"ხმოვანი მომსახურება დაბლოკილია."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"ყველა ხმოვანი სერვისი დაბლოკილია."</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS მომსახურება დაბლოკილია."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"ხმის/მონაცემების სერვისები დაბლოკილია."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"ყველა ხმოვანი/SMS-ის სერვისი დაბლოკილია."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"ხმის/მონაცემების/SMS-ის ყველა სერვისი დაბლოკილია."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"ხმა"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"მონაცემები"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"ფაქსი"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"ასინქრონული"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"სინქრონიზაცია"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"პაკეტი"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"როუმინგის მაჩვენებელი ჩართულია."</string>
-    <string name="roamingText1" msgid="5314861519752538922">"როუმინგის მაჩვენებელი გამორთულია."</string>
-    <string name="roamingText2" msgid="8969929049081268115">"როუმინგის მაჩვენებლის ციმციმი"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"სამეზობლოს მიღმა"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"შენობის გარეთ"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"როუმინგი - უპირატესი სისტემა"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"როუმინგი - ხელმისაწვდომი სისტემა"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"როუმინგი - ალიანსის პარტნიორი"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"როუმინგი - პრემიუმ პარტნიორი"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"Roaming - Full Service Functionality"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"Roaming - Partial Service Functionality"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"Roaming Banner ჩართულია"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"როუმინგის ბანერი გამორთულია"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"სერვისის ძიება"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: არ არის გადამისამართებული"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> <xliff:g id="TIME_DELAY">{2}</xliff:g> წამის შემდეგ"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: არ არის გადამისამართებული"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: არ არის გადამისამართებული"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"ფუნქციის კოდი შესრულდა."</string>
-    <string name="fcError" msgid="3327560126588500777">"კავშირის პრობლემაა ან არასწორი ფუნქციური კოდია."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"კარგი"</string>
-    <string name="httpError" msgid="7956392511146698522">"ქსელის შეცდომა იყო."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL-ის მოძიება ვერ მოხერხდა."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"საიტის ავტორიზაციის სქემას მხარდაჭერა არ აქვს."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"ავტორიზაცია ვერ ხერხდება."</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"ავტორიზაცია პროქსი-სერვერის გამოყენებით წარუმატებელად დასრულდა."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"სერვერთან დაკავშირება ვერ მოხერხდა."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"სერვერთან კომუნიკაცია ვერ განახორციელა. სცადეთ ხელახლა."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"სერვერთან დაკავშირებისას ამოიწურა ლოდინის დრო."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"ეს გვერდი შეიცავს სერვერის ძალიან ბევრ გადამისამართებას."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"პროტოკოლს მხარდაჭერა არ აქვს."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"დაცული კავშირის დამყარება შეუძლებელია."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"გვერდი ვერ გაიხსნა, რადგანაც URL არასწორია."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"ფაილთან წვდომა ვერ ხერხდება."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"მოთხოვნილი ფაილის მოძიება ვერ მოხერხდა."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"ძალიან ბევრი მოთხოვნა მუშავდება. სცადეთ მოგვიანებით."</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g> ანგარიშის ავტორიზაციის შეცდომა"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"სინქრონიზაცია"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"სინქრონიზაცია"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"<xliff:g id="CONTENT_TYPE">%s</xliff:g>-ის ძალიან ბევრი წაშლილები."</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ტაბლეტის მეხსიერება გავსებულია. ადგილის გასათავისუფლებლად წაშალეთ ფაილების ნაწილი."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"ტელეფონის მეხსიერება გავსებულია. ადგილის გასათავისუფლებლად წაშალეთ ფაილების ნაწილი."</string>
-    <string name="me" msgid="6545696007631404292">"მე"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ტაბლეტის პარამეტრები"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"ტელეფონის პარამეტრები"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"ჩუმი რეჟიმი"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"უსადენოს ჩართვა"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"უსადენო ინტერნეტის გამორთვა"</string>
-    <string name="screen_lock" msgid="799094655496098153">"ეკრანის დაბლოკვა"</string>
-    <string name="power_off" msgid="4266614107412865048">"გამორთვა"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"მრეკავი გათიშულია"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"ვიბრაციის რეჟიმი"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"ზარი ჩართულია"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"გამორთვა…"</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"თქვენი ტაბლეტი გაითიშება."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"თქვენი ტელეფონი გაითიშება."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"გსურთ გამორთვა?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"უსაფრთხო რეჟიმის ჩატვირთვა"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"გსურთ, უსაფრთხო რეჟიმის ხელახალი ჩატვირთვა? ამით გაითიშება ყველა მესამე პირი აპლიკაცია, რომელიც დაყენებული გაქვთ. ისინი აღდგება მომდევნო ხელახალი ჩატვირთვის შემდეგ."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"უახლესი"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"არ არის ბოლოს გამოყენებული აპები."</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ტაბლეტის პარამეტრები"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"ტელეფონის პარამეტრები"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"ეკრანის დაბლოკვა"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"გამორთულია"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"ხარვეზის შესახებ ანგარიში"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"შექმენით შეცდომის ანგარიში"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"იგი შეაგროვებს ინფორმაციას თქვენი მოწყობილობის ამჟამინდელი მდგომარეობის შესახებ, რათა ის ელფოსტის შეტყობინების სახით გააგზავნოს. ხარვეზის ანგარიშის მომზადებასა და შეტყობინების გაგზავნას გარკვეული დრო სჭირდება. გთხოვთ, მოითმინოთ."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"ჩუმი რეჟიმი"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"ხმა გამორთულია"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"ხმა ჩართულია"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"თვითმფრინავის რეჟიმი"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"თვითმფრინავის რეჟიმი ჩართულია."</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"თვითმფრინავის რეჟიმი გამორთულია."</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"უსაფრთხო რეჟიმი"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Android-ის სისტემა"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"სერვისები, რომელშიც ფულის გადახდა გიწევთ"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"ისეთი აქტივობების განხორციელება, რომლებშიც ფულის გადახდა მოგიწევთ."</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"თქვენი შეტყობინებები"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"თქვენი SMS-ის, ელფოტის და სხვა შეტყობინებების წაკითხვა და დაწერა."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"თქვენი პირადი ინფორმაცია"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"პირდაპირი წვდომა თქვენ შესახებ ინფორმაციაზე, რომელიც საკონტაქტო ბარათზეა შენახული."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"თქვენი სოციალური ინფორმაცია"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"თქვენს კონტაქტებისა და სოციალურ კავშირების შესახებ ინფორმაციაზე პირდაპირი წვდომა."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"თქვენი მდებარეობა"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"თქვენი ფიზიკური მდებარეობის მონიტორინგი"</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"ქსელის კომუნიკაცია"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"წვდომა ქსელის სხვადასხვა პარამეტრთან."</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"Bluetooth"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"მოწყობილობებთან და ქსელებთან წვდომა Bluetooth მეშვეობით."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"აუდიო პარამეტრები"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"აუდიო პარამეტრების შეცვლა."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"აზიანებს ელემენტს"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"იმ ფუნქციების გამოყენება, რომელიც ელემენტს სწრაფად დახლის."</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"კალენდარი"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"კალენდარსა და ღონისძიებებზე პირდაპირი წვდომა."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"მომხმარებლის ლექსიკონის წაკითხვა"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"მომხმარებლის ლექსიკონში სიტყვების წაკითხვა"</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"მომხმარებლის ლექსიკონში ჩაწერა"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"მომხმარებლის ლექსიკონში სიტყვების დამატება."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"სანიშნეები და ისტორია"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"პირდაპირი წვდომა სანიშნეებსა და ბრაუზერის ისტორიაზე"</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"მაღვიძარა"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"მაღვიძარის დაყენება."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"ხმოვანი ფოსტა"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"პირდაპირი წვდომა ხმოვან ფოსტაზე"</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"მიკროფონი"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"პირდაპირი წვდომა მიკროფონზე აუდიოს ჩასაწერად."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"კამერა"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"პირდაპირი წვდომა კამერაზე სურათის ან ვიდეოს გადასაღებად"</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"ჩაკეტილი ეკრანი"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"მოწყობილობის ეკრანის ჩამკეტის ქცევის შეცვლის შესაძლებლობა."</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"თქვენი აპლიკაციების ინფორმაცია"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"თქვენს მოწყობილობაზე სხვა აპლიკაციების ქცევის შეცვლის შესაძლებლობა."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"ფონი"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"მოწყობილობის ფონის პარამეტრების შეცვლა."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"საათი"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"მოწყობილობის დროის ან დროითი სარტყლის შეცვლა."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"სტატუსის ზოლი"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"მოწყობილობის სტატუსების ზოლის პარამეტრების შეცვლა."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"სინქრონიზაციის პარამეტრები"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"სინქრონიზაციის პარამეტრებზე წვდომა"</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"თქვენი ანგარიშები"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"ხელმისაწვდომ ანგარიშებზე წვდომა."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"მოწყობილობების მართვა"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"ყურსაცვამის აპარატურულ მოწყობილობაზე პირდაპირი წვდომა."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"სატელეფონო ზარები"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"სატელეფონო ზარების მონიტორინგი, ჩაწერა და განხორციელება."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"სისტემის ხელსაწყოები"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"დაბალი წვდომა და სისტემის კონტროლი"</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"დეველოპმენტის ინსტრუმენტები"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"ელემენტები, რომლებიც მხოლოდ აპების დეველოპერებს სჭირდებათ."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"სხვა აპლიკაციის UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"სხვა აპლიკაციების UI-ის ეფექტი."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"შესანახი სივრცე"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB მეხსიერებასთან წვდომა."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD ბარათთან წვდომა."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"წვდომის ფუნქციები"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"ფუნქციები, რომელიც შესაძლოა მოითხოვოს დამხმარე ტექნოლოგიამ."</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"ფანჯრის კონტენტის მოძიება"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"შეამოწმეთ იმ ფანჯრის კონტექტი, რომელშიც მუშაობთ."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"„შეხებით აღმოჩენის“ ჩართვა"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"ის ერთეულები, რომლებსაც შეეხებით, წაიკითხება ხმამაღლა და ეკრანის კვლევა შეიძლება ჟესტების გამოყენებით."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"ვებზე გამარტივებული წვდომის დამატებითი შესაძლებლობების ჩართვა"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"შესაძლებელია სკრიპტების ინსტალაცია აპის კონტენტის წვდომადობის უზრუნველსაყოფად."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"თქვენ მიერ აკრეფილ ტექსტზე დაკვირვება"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"შეიცავს ისეთ პირად მონაცემებს, როგორიცაა საკრედიტო ბარათის ნომრები და პაროლები."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"სტატუსის ზოლის გათიშვა ან ცვლილება"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"აპს შეეძლება სტატუსების ზოლის გათიშვა და სისტემის ხატულების დამატება/წაშლა."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"სტატუსის ზოლი"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"აპს შეეძლება სტატუსის ზოლის ჩანაცვლება."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"სტატუსების ზოლის გაფართოება/აკეცვა"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"აპს შეეძლება სტატუსის ზოლის გახსნა-დახურვა."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"გამავალი ზარების გადამისამართება"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"აპს შეეძლება გამავალი ზარების დამუშავება და ასაკრეფი ნომრის შეცვლა. ეს უფლება აპს აძლევს შესაძლებლობას აკონტროლოს, გადაამისამართოს ან აღკვეთოს გამავალი ზარები."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"ტექსტური შეტყობინებების (SMS) მიღება"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"აპს შეეძლება SMS შეტყობინებების მიღება და დამუშავება. ეს ნიშნავს, რომ აპს შეეძლება თქვენ მოწყობილობაზე გამოგზავნილი შეტყობინებების მონიტორინგი და მათი წაშლა თქვენთვის ჩვენების გარეშე."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"ტექსტური შეტყობინებების (MMS) მიღება"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"აპს შეეძლება MMS შეტყობინებების მიღება და დამუშავება. ეს ნიშნავს, რომ აპს შეეძლება შეტყობინებების მონიტორინგი და მათი წაშლა თქვენთვის ჩვენების გარეშე."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"გადაუდებელი შეტყობინებების მიღება"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"აპს შეეძლება, მიიღოს და დაამუშაოს საგანგებო სამაუწყებლო შეტყობინებები. ეს ნებართვა ხელმისაწვდომია მხოლოდ  სისტემის აპებისთვის."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"მასიური დაგზავნის შეტყობინებების წაკითხვა"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"აპს შეეძლება, წაიკითხოს თქვენს მოწყობილობაზე გამოგზავნილი ქსელის სამაუწყებლო შეტყობინებები. სამაუწყებლო გაფრთხილებები მოგეწოდებათ ზოგიერთ ადგილზე ექსტრემალური სიტუაციების შესახებ გასაფრთხილებლად. ქსელის გადაუდებელი შეტყონიბენის მიღების დროს მავნე აპებმა შეიძლება ხელი შეუშალონ თქვენი მოწყობილობის ფუნქციონირებას ან ოპერაციებს."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS შეტყობის გაგზავნა"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"აპს შეეძლება, გაგზავნოს SMS შეტყობინებები, რამაც შეიძლება გაუთვალისწინებელი ხარჯები გამოიწვიოს. მავნე აპებმა შეიძლება დაგიხარჯონ ფული შეტყობინებების თქვენი თანხმობის გარეშე გაგზავნით."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"ღონისძიებების გაგზავნა (პასუხის მიღება მხოლოდ შეტყობინებით)"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"აპს შეეძლება, გაუგზავნოს მოთხოვნები სხვა შეტყობინებების აპებს შემომავალ ზარებზე შეტყობინებით პასუხის მოვლენებთან გასამკლავებლად."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"თქვენი ტექსტური შეტყობინებების (SMS ან MMS) წაკითხვა"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"აპს შეეძლება თქვენს ტაბლეტში ან SIM ბარათში შენახული SMS შეტყობინებების წაკითხვა. ამგვარად, აპს ექნება შესაძლებლობა წაიკითხოს ყველა SMS შეტყობინება, მათი კონტენტისა და კონფიდენციალურობის მიუხედავად."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"აპს შეეძლება თქვენს ტაბლეტში ან SIM ბარათში შენახული SMS შეტყობინებების წაკითხვა. ამგვარად, აპს ექნება შესაძლებლობა წაიკითხოს ყველა SMS შეტყობინება, მათი კონტენტისა და კონფიდენციალურობის მიუხედავად."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"თქვენი ტექსტური შეტყობინებების (SMS ან MMS) რედაქტირება"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"აპს შეეძლება, უპასუხოს თქვენ ტაბლეტში ან SIM ბარათზე შენახულ SMS შეტყობინებებს. მავნე აპებმა შეიძლება წაშალონ თქვენი შეტყობინებები."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"აპს უფლება ექნება , უპასუხოს თქვენ ტაბლეტში ან SIM ბარათზე შენახულ SMS შეტყობინებებს. მავნე აპებმა შეიძლება წაშალონ თქვენი შეტყობინებები."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"ტექსტური შეტყობინებების (WAP) მიღება"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"აპს შეეძლება WAP შეტყობინებების მიღება და გენერირება. ამ უფლებით აპი ისე დააკვირდება და წაშლის თქვენთვის გამოგზავნილ შეტყობინებებს, რომ თქვენ ვერც ნახავთ."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"მოქმედი აპების მოძიება"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"აპს შეეძლება მოიძიოს ინფორმაცია ამჟამად და უახლოეს წარსულში მიმდინარე ამოცანების შესახებ. ამგვარად, აპს აქვს შესაძლებლობა აღმოაჩინოს ინფორმაცია იმის შესახებ, თუ რომელი აპლიკაციებია გამოყენებული მოწყობილობაზე."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"მომხმარებლებს შორის ინტერაქცია"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"აპს შეეძლება, სხვადასხვა მომხმარებლის მოქმედებები შეასრულოს მოწყობილობაზე. მავნე აპებმა შეიძლება მომხმარებლებს შორის დაცვის დასარღვევად გამოიყენონ."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"მომხმარებლებთან ინტერაქციის სრული ლიცენზია"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"აძლევს მომხმარებლებს შორის ყველა შესაძლო ინტერაქციის უფლებას."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"მომხმარებლების მართვა"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"აპს შეუძლია მომხმარებლების მართვა მოწყობილობაზე, მათ შორის მოთხოვნის, შექმნის და წაშლის."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"მოქმედი აპების დეტალების მოძიება"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"აპს შეეძლება მოიძიოს დეტალური ინფორმაცია ამჟამად და უახლოეს წარსულში მიმდინარე ამოცანების შესახებ. მავნე აპებს შეუძლიათ აღმოაჩინონ პირადი ინფორმაცია სხვა აპების შესახებ."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"მოქმედი აპების წყობის შეცვლა"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"აპს შეეძლება ამოცანების გადატანა წინა და უკანა პლანზე. ამას თქვენი ჩარევის გარეშე გააკეთებს."</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"გაშვებული აპების შეწყვეტა"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"აპს შეეძლება ამოცანების წაშლა და მათი აპების გაუქმება. მავნე აპებმა შესაძლოა დაარღვიონ სხვა აპების მოქმედება."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"აქტივობის დასტების მართვა"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"საშუალებას აძლევს აპს დაამატოს, ამოშალოს და შეცვალოს აქტივობის დასტები, რაშიც სხვა აპები ეშვება. მავნე აპები სხვა აპებს ქცევის ხელის შეშლას შეძლებს."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"ნებისმიერი აქტივობის წამოწყება"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"აპს შეეძლება დაიწყოს ნებისმიერი აქტივობა, ყოველგვარი უფლებისა და სტატუსის გარეშე."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"ეკრანის თავსებადობის დაყენება"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"აპს შეეძლება სხვა აპლიკაციებთან ეკრანის თავსებადობის რეჟიმის კონტროლი. მავნე აპლიკაციებმა შესაძლოა სხვა აპლიაკციების ქცევა შეცვალოს."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"აპის გამართვის გააქტიურება"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"აპს შეეძლება სხვა აპისთვის გამართვის რეჟიმის ჩართვა. მავნე აპლიკაციებს ამ ფუნქციით შეეძლებათ სხვა აპების გათიშვა."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"სისტემის ინტერფეისის პარამეტრების შეცვლა"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"აპს შეეძლება, შეცვალოს ამჟამინდელი კონფიგურაცია, მაგალითად, ენა და ქვეყნის კოდი ან შრიფტის ზომა."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"მანქანის რეჟიმის ჩართვა"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"აპს შეეძლება მანქანის რეჟიმის ჩართვა."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"სხვა აპების დახურვა"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"აპს შეეძლება, დაასრულოს სხვა აპების ფონური პროცესები. ამან შეიძლება სხვა აპების შეჩერება გამოიწვიოს."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"სხვა აპების იძულებითი შეჩერება"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"აპს შეეძლება იძულებით შეწყვიტოს სხვა აპების მუშაობა."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"აპის ძალით დახურვა"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"აპს შეეძლება იძულებით დაასრულოს წინა პლანზე მიმდინარე ნებისმიერი აქტივობა და დაბრუნდეს უკან. ჩვეულებრივ აპებს მსგავსი რამ არასოდეს სჭირდება."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"სისტემის მდგომარეობის შესახებ ინფორმაციის მიღება"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"აპს შეეძლება სისტემის შიდა მდგომარეობის ნახვა. მავნე პროგრამები შეძლებენ პირადი და დაცული ინფორმაციის ნახვას, რომელთან წვდომის საშუალებაც მათ არ უნდა ჰქონდეთ."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"ეკრანის კონტენტის მოძიება"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"აპს შეეძლება აქტიური ფანჯრიდან კონტენტის მოძიება. მავნე აპებს შეუძლიათ ფანჯრის სრული კონტენტის მოძიება და ყველა ტექსტის წაკითხვა პაროლების გარდა."</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"მარტივი წვდომის დროებით გააქტიურება"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"აპს შეეძლება მოწყობილობაზე გამარტივებული რეჟიმის ჩართვა. მავნე აპებს შეეძლებათ ამ რეჟიმის ჩართვა მომხმარებლის გაფრთხილების გარეშე."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"ფანჯრის ინფორმაციის მოძიება"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"აპს შეეძლება ფანჯრების მენეჯერის მეშვეობით ფანჯრების შესახებ ინფორმაციის მოპოვება. მავნე აპლიკაციებს შეეძლებათ ისეთი ინფორმაციის მოპოვება, რომელიც შიდა სისტემური მოხმარებისთვის არის განკუთვნილი."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"ღონისძიებების გაფილტვრა"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"აპლიკაციას შეეძლება რეგისტრაცია შეტანის ფილტრებისა, რომლებიც ასუფთავებენ მომხმარებლის ღონისძიების ყველა დინებას. მავნე აპმა შესაძლოა ეს ფუნქცია სისტემის UI კონტროლისთვის გამოიყენოს, მომხმარებლის ინტერვენციის გარეშე."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"ეკრანის გადიდება"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"აპლიკაციას შეეძლება, შეცვალოს დისპლეის კონტენტი. მავნე აპებმა შეიძლება იმგვარად გარდაქმნან დისპლეის კონტენტი, რომ  მოწყობილობა გამოუსადეგარი გახდეს."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"ნაწილობრივი გამორთვა"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"აქტივობების მენეჯერს გათიშვის რეჟიმში აყენებს. სრულ გათიშვას არ ახორციელებს."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"აპის გადართვებისგან დაცვა"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"ხელს უშლის მომხმარებლის სხვა აპზე გადართვას."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"ამჟამინდელი აპის ინფორმაციის მიღება"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"ნებას რთავს მფლობელს, მოიპოვოს მიმდინარე აპლიკაციის და სერვისების შესახებ პირადი ინფორმაცია ეკრანის წინა პლანზე."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"ყველა აპის გაშვების მონიტორინგი დ კონტროლი"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"აპს შეეძლება სისტემის მიერ გამოძახებული აქტივობების მონიტორინგი და მართვა. მავნე აპლიკაციებს შეეძლებათ სისტემის სრული კონტროლი. ეს ნებართვა საჭროა მხოლოდ დეველოპმენტისთვის და ჩვეულებრივი მოხმარებისთის არ გამოიყენება."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"პაკეტების წაშლის შესახებ შეტყობინებების გაგზავნა"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"აპს შეეძლება, გაგზავნოს შეტყობინება, რომ აპის პაკეტი წაიშალა. მავნე აპებმა ეს უფლება შეიძლება გამოიყენონ სხვა ნებისმიერი გაშვებული აპების შესაწყვეტად."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS-ით მიღებული სამაუწყებლო შეტყობინების გაგზავნა"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"აპს საშუალებას აძლევს გააგზავნოს შეტყობინება SMS შეტყობინების მიღების თაობაზე. მავნე აპლიკაციებში ეს ფუნქცია შეიძლება გამოყენებული იქნას SMS შეტყობინებების მიღების იმიტაციიისათვის."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH-ით მიღებული სამაუწყებლო შეტყობინების გაგზავნა"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"აპს შეეძლება, გაგზავნოს შეტყობინება WAP PUSH შეტყობინების მიღების თაობაზე. მავნე აპებმა ეს შეიძლება გამოიყენონ MMS შეტყობინების მიღების გასაყალბებლად ან ნებისმიერი ვებგვერდის კონტენტის სახიფათო ვარიანტებით ჩუმად ჩასანაცვლებლად."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"მიმდინარე პროცესების რაოდენობის ლიმიტი"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"აპს შეეძლება, გააკონტროლოს მიმდინარე პროცესების მაქსიმალური რაოდენობა. ჩვეულებრივ აპებში არასდროს არის საჭირო."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"უკანა ფონის აპის იძულებით დახურვა"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"აპს შეეძლება გააკონტროლოს, არის თუ არა აქტივობები ყოველთვის დასრულებული მათი უკანა ფონზე გადასვლის დროს. არასდროს არის საჭირო ჩვეულებრივ აპებში."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"ელემენტის სტატისტიკის წაკითხვა"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"აპლიკაციას შეეძლება ამჟამინდელი დაბალი დამუხტვის ელემენტის გამოყენების მონაცემების წაკითხვა. აპლიკაციამ შესაძლოა მოახერხოს თქვენ მიერ გამოყენებული აპების შესახებ დეტალური ინფორმაციის მოძიება."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"ელემენტის სტატისტიკის შეცვლა"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"აპს შეეძლება, შეცვალოს ბატარეის გამოყენების შეგროვებული სტატისტიკა. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"აპის სამუშაო ჟურნალის სტატისტიკის მოძიება"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"აპს შეეძლება აპლიკაციათა ოპერაციების შეგროვებული სტატისტიკის მოპოვება. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"აპის სამუშაო ჟურნალის სტატისტიკის შეცვლა"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"აპს შეეძლება აპლიკაციის ოპერაციების შეგროვებული სტატისტიკის მოპოვება. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"სისტემის სარეზერვო ასლების კონტროლი და აღდგენა"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"აპს შეეძლება სისტემის სარეზერვო ასლების კონტროლი და მექანიზმის აღდგენა. ჩვეულებრივი აპები მსგავს შესაძლებლობებს არ იყენებენ."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"სრული სარეზერვო ასლების დადასტურება ან ოპერაციის აღდგენა"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"აპს შეეძლება გაუშვას სრული სარეზერვო ასლების UI დადასტურება. არ იყენებს არც ერთი სხვა აპი."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"არაავტორიზებული ფანჯრების ჩვენება"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"აპს შეეძლება, შექმნას შიდა სისტემის მომხმარებლის ინტერფეისის მიერ გამოყენებისთვის განკუთვნილი ფანჯრები. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"სხვა აპების ინტერფეისზე გადაწერა"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"აპს შეეძლება თავისი ინტერფეისი ზემოდან გადააწეროს სხვა აპლიკაციებს ან მომხმარებლის ინტერფეისის ნაწილებს. ამგვარად, შესაძლოა შეიცვალოს სხვა აპლიკაციის ინტერფეისი და ხელი შეგეშალოთ სხვა მასთან მუშაობისას."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"ანიმაციის გლობალური სიჩქარის შეცვლა"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"აპს შეეძლება გლობალური ანიმაციის სიჩქარის შეცვლა (სწრაფი ან ნელი ანიმაცია) ნებისმიერ დროს."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"აპის წინასწარი გადახდის ბარათების მართვა"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"აპს შეეძლება, შექმნას და მართოს საკუთარი იდენტიფიკაციის ნიშნები, ჩვეულებრივი Z-წყობის უგულვებელყოფით. ჩვეულებრივი აპებისთვის მისი გამოყენება არასდროს არის საჭირო."</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"ეკრანის გაყინვა"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"აპლიკაციას შეეძლება ეკრანის დროებით გაშეშება სრულ ეკრანზე გადასასვლელად."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"გასაღებზე დაჭერა და ღილაკების მართვა"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"აპს შეეძლება შეყვანის საკუთარი მოვლენების (გასაღები და ა.შ.) სხვა აპებისთვის გადაცემა. მავნე აპებმა შესაძლოა ეს გამოიყენონ ტაბლეტის საკონტროლოდ."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"აპს შეეძლება შეყვანის საკუთარი მოვლენების (გასაღები და ა.შ.) სხვა აპებისთვის გადაცემა. მავნე აპებმა შესაძლოა ეს გამოიყენონ ტელეფონის საკონტროლოდ."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"ჩაწერეთ რასაც ბეჭდავთ და რა ქმედებებსაც მიმართავთ."</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"აპს შეეძლება დაინახოს გასაღები, როდესაც მას ბეჭდავთ თუნდაც სხვა აპში მუშაობის დროს (მაგალითად, პაროლის აკრეფა). ჩვეულებრივ აპებს მსგავსი რამ არასოდეს სჭირდება."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"შეტანის მეთოდთან დაკავშირება"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"აპს შეეძლება ზედა დონის ინტერფეისის წვდომის სისტემასთან დაკავშირება. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"გამარტივებული წვდომის სერვისთან მიერთება"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"აპს შეეძლება გამარტივებული წვდომის სერვისის ზედა დონის ინტერფეისთან დაკავშირება. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"ბეჭდვის სევისზე მიბმა"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"მფლობელს შეეძლება მიებას ბეჭდვის სერვისების ზედა დონის ინტერფეისს. ჩვეულებრივ აპს ეს წესით არასოდეს არ უნდა დაჭირდეს."</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"ბეჭდვის ყველა დავალებაზე წვდომა"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"საშუალებას აძლევს მფლობელს იქონიოს წვდომა სხვა აპის მიერ შექმნილ ბეჭდვის დავალებებზე. ჩვეულებრივ აპს ეს წესით არასოდეს არ უნდა დაჭირდეს."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC სერვისთან შეკავშირება"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"საშუალებას აძლევს მფლობელს შეკავშირდეს აპლიკაციებთან, რომლებიც NFC ბარათების სიმულაციას ახდენს. ჩვეულებრივ აპებს უმეტეს შემთხვევაში არ დაჭირდება."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"ტექსტ სერვისთან დაკავშირება"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"აპს შეეძლება ზედა დონის ინტერფეისის ტექსტური სამსახურთან (მაგ. SpellCheckerService) დაკავშირება. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN სერვისთან დაკავშირება"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"აპს შეეძლება Vpn სერვისის ზედა დონის ინტერფეისთან დაკავშირება. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"ფონზე მიჭედება"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"მფლობელს შეეძლება ფონის ზედა დონის ინტერფეისთან დაკავშირება. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"ვიჯეტ სერვისთან დაკავშირება"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"აპს შეეძლება ზედა დონის ინტერფეისის ვიჯეტთან დაკავშირება. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"მოწყობილობის ადმინთან ინტერაქცია"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"აპს შეეძლება მოწყობილობის ადმინისტრატორისთვის intent ობიექტების გაგზავნა. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"მოწყობილობის ადმინისტრატორს დამატება ან ამოშლა"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"საშუალებას აძლევს მფლობელს დაამატოს ან ამოშალოს მოწყობილობის აქტიური ადმინისტრატორები. ჩვეულებრივ აპებს, ალბათ, არასოდეს დაჭირდება"</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"ეკრანის ორიენტაციის შეცვლა"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"აპს შეეძლება, ატრიალოს ეკრანი ნებისმიერ დროს. არასდროს იქნება საჭირო ჩვეულებრივ აპებში."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"მაჩვენებლის სიჩქარის შეცვლა"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"აპს შეეძლება, შეცვალოს მაუსის ან თრექპედის კურსორის სიჩქარე ნებისმიერ დროს. არასდროს იქნება საჭირო ჩვეულებრივ აპებში."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"კლავიატურის განლაგების შეცვლა"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"აპს შეეძლება შეცვალოს კლავიატურის განლაგება. ეს ფუნქცია არასდროს იქნება საჭირო ჩვეულებრივ აპებში."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"აპებისთვის Linux-ის სიგნალების გაგზავნა"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"აპს შეეძლება მოითხოვოს უზრუნველყოფილი სიგნალის მუდმივ პროცესებისთვის გაგზავნა."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"დააყენოს აპი მუდმივად ჩართულად"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"აპს შეეძლება, საკუთარი ნაწილები მუდმივად ჩაწეროს მეხსიერებაში. ეს შეზღუდავს მეხსიერების ხელმისაწვდომობას სხვა აპებისთვის და შეანელებს ტაბლეტს."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"აპს შეეძლება, საკუთარი ნაწილები მუდმივად ჩაწეროს მეხსიერებაში. ეს შეზღუდავს მეხსიერების ხელმისაწვდომობას სხვა აპებისთვის და შეანელებს ტელეფონს."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"აპების წაშლა"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"აპს შეეძლება Android პაკეტების წაშლა. მავნე აპებმა შეიძლება გამოიყენონ მნიშვნელოვანი აპების წასაშლელად."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"სხვა აპების მონაცემების წაშლა"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"აპს შეეძლება მომხმარებლის მონაცემების წაშლა."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"სხვა აპების ქეშის წაშლა"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"აპს შეეძლება ქეშის ფაილების წაშლა."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"აპის მეხსიერების სივრცის გაზომვა"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"აპს შეეძლება, მოიპოვოს თავისი კოდი, მონაცემები და ქეშის ზომები."</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"აპების პირდაპირი ინსტალაცია"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"აპს შეეძლება Android-ის ახალი ან განახლებული პაკეტების ინსტალაცია. მავნე აპებმა შესაძლოა ეს გამოიყენონ ახალი აპების დასამატებლად თვითნებურად, მნიშვნელოვანი უფლებებით."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"ყველა აპის მონაცემთა ქეშის წაშლა"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"აპს შეეძლება, გაასუფთავოს ტაბლეტის მეხსიერება სხვა აპლიკაციების ქეშის საქაღალდეებში ფაილების წაშლით. ამან შეიძლება გამოიწვიოს სხვა აპლიკაციების უფრო ნელი გაშვება, რადგანაც მათ მონაცემების ხელახლა პოვნა სჭირდებათ."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"აპს შეეძლება, გაასუფთავოს ტელეფონის მეხსიერება სხვა აპლიკაციების ქეშის საქაღალდეებში ფაილების წაშლით. ამან შეიძლება გამოიწვიოს სხვა აპლიკაციების უფრო ნელი გაშვება, რადგანაც მათ მონაცემების ხელახლა პოვნა სჭირდებათ."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"აპის რესურსების გადატანა"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"აპს შეეძლება აპების რესურსსების გადატანა გარედან შიდა მეხსიერებაზე და პირიქით."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"ჟურნალის სენსიტიური მონაცემების წაკითხვა"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"აპს შეეძლება სისტემის სხვადასხვა ჟურნალის ფაილების წაკითხვა. ეს უფლებას აძლევს, გაიგოს ზოგადი ინფორმაცია იმის შესახებ, თუ რას აკეთებთ ტაბლეტზე და, პოტენციურად, პირადი ან კონფიდენციალური ინფორმაციაც."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"აპს შეეძლება სისტემის სხვადასხვა ჟურნალის ფაილების წაკითხვა. ეს უფლებას აძლევს, გაიგოს ზოგადი ინფორმაცია იმის შესახებ, თუ რას აკეთებთ ტელეფონზე და, პოტენციურად, პირადი ან კონფიდენციალური ინფორმაციაც."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"ნებისმიერი მედია დეკოდერის გამოყენება"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"აპს დასაკრავად შეეძლება გამოიყენოს ნებისმიერი დაყენებული მედია დეკოდერი."</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"სისტემის დიაგნოსტიკის რესურსებში წაკითხვა/ჩაწერის უფლება"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"აპს შეეძლება, წაიკითხოს ან ჩაწეროს ნებისმიერ რესურსში, რომელიც დიაგნოსტიკის ჯგუფს ეკუთვნის, მაგალითად, ფაილები /dev-ში. ამან შესაძლოა იმოქმედოს სისტემის სტაბილურობასა და უსაფრთხოებაზე. მისი გამოყენება მხოლოდ მწარმოებლის ან ოპერატორის მიერ ტექნიკის სპეციფიკური დიაგნოსტიკისთვის უნდა მოხდეს."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"აპის კომპონენტების ჩართვა ან გამორთვა"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"აპებს საშუალებას აძლევს, შეცვალონ სხვა აპების კომპონენტები. ამ გზით მავნე აპები შეძლებენ ტაბლეტის მნიშვნელვანი ფუნქციების გათიშვას. ეს ნებართვა სიფრთხილით გამოიყენეთ, რათა შემთხვევით არ დაარღვიოთ აპლიკაციის კომპონენტების მუშაობა."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"აპებს საშუალებას აძლევს, შეცვალონ სხვა აპების კომპონენტები. ამ გზით მავნე აპები შეძლებენ ტელეფონის მნიშვნელვანი ფუნქციების გათიშვას. ეს ნებართვა სიფრთხილით გამოიყენეთ, რათა შემთხვევით არ დაარღვიოთ აპლიკაციის კომპონენტების მუშაობა."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"ნებართვების მიცემა ან გაუქმება"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"აპლიკაციას შეეძლება, გასცეს ან გააუქმოს განსაკუთრებული ნებართვები მისთვის ან სხვა აპლიკაციებისთვის. მავნე აპლიკაციებმა შეიძლება გამოიყენონ იმ თვისებებზე წვდომისთვის, რომლებიც მათ არ მიანიჭეთ."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"სასურველი აპების დაყენება"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"აპს შეეძლება შეცვალოს თქვენი სასურველი აპები. მავნე აპებმა ეს შესაძლოა გამოიყენონ თქვენ მიერ მოხმარებადი აპების ჩუმად შესაცვლელად, თქვენგან პირადი ინფორმაციის მოსაგროვებლად."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"სისტემის პარამეტრების შეცვლა"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"აპს შეეძლება, შეცვალოს სისტემის პარამეტრების მონაცემები. მავნე აპებს შეუძლიათ დააზიანონ თქვენი სისტემის კონფიგურაცია."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"სისტემის უზრუნველყოფის პარამეტრების შეცვლა"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"აპს შეეძლება სისტემის უსაფრთხოების პარამეტრების მონაცემების შეცვლა. ამ შესაძლებლობას ჩვეულებრივი აპების არასოდეს იყენებენ."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google სერვისების რუკის შეცვლა"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"აპს შეეძლება Google სერვისების რუკის შეცვლა. არ გამოიყენება ჩვეულებრივ აპლიკაციებში."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"გაშვება სისტემის ჩართვისას"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"აპს შეეძლება საკუთარი თავის სისტემის ჩატვირთვისას ჩართვა. ამან შეიძლება გამოიწვიოს ჩატვირთვის დროის გაზრდა და ტაბლეტის შენელება, რადგან აპი ყოველთვის ჩართული იქნება."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"აპს შეეძლება საკუთარი თავის ჩართვა სისტემის ჩატვირთვისთანავე. ამან შეიძლება გამოიწვიოს ტელეფონის ჩატვირთვის დროის გაზრდა და ზოგადად ტელეფონის შენელება, რადგან აპი ყოველთვის ჩართული იქნება."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"ისეთი შეტყობინებების გაგზავნა, რომლებიც არ იშლება"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"აპს შეეძლება არასაჩქარო შეტყობინებების გაგზავნა, რომლებიც რჩებიან გაგზავნის დასრულების შემდეგაც. ამ გადაგზავნის ზომაზე მეტად გამოყენებამ შეიძლება შეანელოს ან შეაფერხოს თქვენი ტაბლეტის მუშაობა ზედმეტად დიდი მოცულობის მეხსიერების გამოყენების შედეგად."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"აპს შეეძლება არასაჩქარო შეტყობინებების გაგზავნა, რომელიც რჩებიან გაგზავნის დასრულების შემდეგაც. მავნე აპლიკაციებს შეუძლიათ თქვენი ტელეფონის მუშაობის შენელება ან შეფერხება ზედმეტად დიდი მოცულობის მეხსიერების გამოყენების შედეგად."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"თქვენი კონტაქტების წაკითხვა"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"აპს შეეძლება, წაიკითხოს თქვენ ტაბლეტზე შენახული კონტაქტების მონაცემები, მათ შორის ინფორმაცია კონკრეტულ ადამიანებთან თქვენი დარეკვის, ელფოსტის გაგზავნის ან კომუნიკაციის სიხშირის შესახებ. ეს ნებართვა უფლებას აძლევს აპებს, შეინახონ თქვენი კონტაქტების მონაცემები და მავნე აპებმა შეიძლება გააზიარონ საკონტაქტო მონაცემები თქვენგან დამოუკიდებლად. "</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"აპს შეეძლება, წაიკითხოს თქვენ ტელეფონზე შენახული კონტაქტების მონაცემები, მათ შორის ინფორმაცია კონკრეტულ ადამიანებთან თქვენი დარეკვის, ელფოსტის გაგზავნის ან კომუნიკაციის სიხშირის შესახებ. ეს ნებართვა უფლებას აძლევს აპებს, შეინახონ თქვენი კონტაქტების მონაცემები და მავნე აპებმა შეიძლება გააზიარონ საკონტაქტო მონაცემები თქვენგან დამოუკიდებლად. "</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"თქვენი კონტაქტების შეცვლა"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"აპს შეეძლება, შეცვალოს თქვენ ტაბლეტზე შენახული კონტაქტების მონაცემები, მათ შორის ინფორმაცია კონკრეტულ ინდივიდუალებთან თქვენი დარეკვის, ელფოსტის გაგზავნის ან კომუნიკაციის სიხშირის შესახებ. ეს ნებართვა უფლებას აძლევს აპებს, წაშალოს საკონტაქტო მონაცემები. "</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"აპს შეეძლება, შეცვალოს თქვენ ტელეფონზე შენახული კონტაქტების მონაცემები, მათ შორის ინფორმაცია კონკრეტულ ინდივიდუალებთან თქვენი დარეკვის, ელფოსტის გაგზავნის ან კომუნიკაციის სიხშირის შესახებ. ეს ნებართვა უფლებას აძლევს აპებს, წაშალოს საკონტაქტო მონაცემები. "</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"ზარების ჟურნალის წაკითხვა"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"აპს შეეძლება თქვენი ტაბლეტის გამავალი და შემომავალი ზარების ჟურნალის ნახვა, ასევე ექნება ამ ჟურნალის შენახვის უფლება. ეს მავნე აპლიკაციებს საშუალებას მისცემს ნებართვის გარეშე გააზიარონ თქვენი ზარების ჟურნალი."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"აპს შეეძლება თქვენი ტელეფონის გამავალი და შემომავალი ზარების ჟურნალის ნახვა, ასევე ექნება ამ ჟურნალის შენახვის უფლება. ეს მავნე აპლიკაციებს საშუალებას მისცემს ნებართვის გარეშე გააზიარონ თქვენი ზარების ჟურნალი."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"ზარების ჟურნალში ჩაწერა"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"აპს შეეძლება, შეცვალოს თქვენი ტაბლეტის ზარების ჟურნალი, მათ შორის შემომავალი და გამავალი ზარების მონაცემები. მავნე აპებმა შეიძლება გამოიყენონ ეს თქვენი ზარების ჟურნალის წასაშლელად ან შესაცვლელად."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"აპს შეეძლება, შეცვალოს თქვენი ტელეფონის ზარების ჟურნალი, მათ შორის შემომავალი და გამავალი ზარების მონაცემები. მავნე აპებმა შეიძლება გამოიყენონ ეს თქვენი ზარების ჟურნალის წასაშლელად ან შესაცვლელად."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"თქვენი საკონტაქტო ინფორმაციის ნახვა"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"აპს შეეძლება მოწყობილობაზე შენახული პირადი პროფილის ინფორმაციის წაკითხვა, მაგალითად, თქვენი სახელისა და საკონტაქტო ინფორმაციის. ეს ნიშნავს, რომ აპს შეუძლია თქვენი იდენტიფიცირება და თქვენი პირადი ინფორმაციის სხვებისთვის გაგზავნა."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"თქვენი საკონტაქტო ინფორმაციის შეცვლა"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"აპს შეეძლება მოწყობილობაზე შენახული პირადი პროფილის ინფორმაციის შეცვლა ან დამატება, მაგალითად, თქვენი სახელისა და საკონტაქტო ინფორმაციის. ეს ნიშნავს, რომ აპს შეუძლია თქვენი იდენტიფიცირება და თქვენი პირადი ინფორმაციის სხვებისთვის გაგზავნა."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"სოციალური ნაკადის წაკითხვა"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"აპს შეეძლება თქვენი და თქვენი მეგობრების სოციალური განახლებებთან წვდომა და სინქრონიზაცია. ინფორმაციის გაზიარებისას იყავით ფრთხიად - აპს ექნება შესაძლებლობა, რომ წაიკითხოს სოციალურ ქსელებში კომუნიკაცია თქვენსა და თქვენს მეგობრებს შორის კონფიდენციალურობის მიუხედავად. შენიშვნა: ეს უფლება შესაძლოა ვერ იყოს გამოყენებული ყველა სოციალურ ქსელში."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"თქვენს სოციალურ მაუწყებლობაზე დაწერა"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"აპს შეეძლება, გიჩვენოთ თქვენი მეგობრების სოციალური სიახლეები. ფრთხილად იყავით ინფორმაციის გაზიარებისას - აპს შეუძლია შექმნას შეტყობინება, რომელიც თითქოსდა მეგობრისგან არის მოწერილი. შენიშვნა: ეს ნებართვა არ შეიძლება შესრულდეს ყველა სოციალურ ქსელში."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"კალენდრის ღონისძიებებისა და კონფიდენციალური ინფორმაციის წაკითხვა"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"აპს შეეძლება, წაიკითხოს თქვენ ტაბლეტზე შენახული კალენდრის ყველა მოვლენა, მათ შორის მეგობრებისა და თანამშრომლების მოვლენებიც. ამან შეიძლება უფლება მისცეს აპს, გააზიაროს ან შეინახოს თქვენი კალენდრის მონაცემები, მიუხედავად კონფიდენციალურობისა თუ მგრძობიარობისა."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"აპს შეეძლება, წაიკითხოს თქვენს ტელეფონზე შენახული კალენდრის ყველა მოვლენა, მათ შორის მეგობრებისა და თანამშრომლების მოვლენებიც. ამან შეიძლება უფლება მისცეს აპს, გააზიაროს ან შეინახოს თქვენი კალენდრის მონაცემები, მიუხედავად კონფიდენციალურობისა თუ მგრძობიარობისა."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"კალენდრის ღონისძიებების დამატება და შეცვლა და მფლობელის გარეშე ელფოსტის გაგზავნა სტუმრებთან."</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"აპს შეეძლება იმ ღონისძიებების დამატება, წაშლა და შეცვლა, რომლებსაც თქვენს ტაბლეტზე ქმნით, ასევე თქვენი მეგობრების და თანამშრომლების ღონისძიებებიც. ამგვარად, აპს ექნება შესაძლებლობა ისე დააგზავნოს შეტყობინებები კალენდრის მფლობელის სახელით ან შეცვალოს ღონისძიებები, რომ მფლობელმა ამის შესახებ არაფერი იცოდეს."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"აპს შეეძლება იმ ღონისძიებების დამატება, წაშლა და შეცვლა, რომლებსაც თქვენს ტელეფონზე ქმნით, ასევე თქვენი მეგობრების და თანამშრომლების ღონისძიებებიც. ამგვარად, აპს ექნება შესაძლებლობა ისე დააგზავნოს შეტყობინებები კალენდრის მფლობელის სახელით ან შეცვალოს ღონისძიებები, რომ მფლობელმა ამის შესახებ არაფერი იცოდეს."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"მდებარეობის წყაროების იმიტირება ტესტირებისთვის"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"აპს შეეძლება ტესტირებისთვის ყალბი ლოკაციების შექმნა, ან მდებარეობის ახალი პროვაიდერის დაყენება. ეს უფლებას მისცემს აპს, შეცვალოს მდებარეობის სხვა წყაროების მიერ, მაგ. GPS  ან მდებარეობის პროვაიდერების მიერ მოწოდებული მდებარეობა და/ ან სტატუსი."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"მდებარეობის პროვაიდერის დამატებით ბრძანებებზე წვდომა"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"აპს შეეძლება წვდომა ჰქონდეს მდებარეობის სერვისის დამატებით ბრძანებებზე. შესაძლოა აპმა ეს გამოიყენოს GPS-ისა და მდებარეობის სხვა წყაროების მუშაობის პროცესში ჩარევისთვის."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"მდებარეობის პროვაიდერის ინსტალაციის უფლება"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"აპს შეეძლება ტესტირებისთვის ყალბი ლოკაციების შექმნა, ან მდებარეობის ახალი პროვაიდერის დაყენება. აპს საშუალება მიეცემა გადააკეთოს სხვა წყაროების მაგ.: GPS ან მდებარეობის პროვაიდერების მოწოდებული მდებარეობა ან/და სტატუსი."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"ზუსტი მდებარეობა (GPS და ქსელის კოორდინატების მიხედვით)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"აძლევს აპს უფლებას მოიპოვოს ზუსტი მდებარეობა გლობალური პოზიციონირების სისტემის (GPS) გამოყენებით ან ქსელის მდებარეობის წყაროს მიხედვით, როგორიცაა ქსელის ანძები და Wi-Fi. მდებარეობის ეს სერვისები ჩართული უნდა იყოს და თქვენს მოწყობილობაზე აპისთვის მისაწვდომი, რათა შეძლოს მათი გამოყენება. აპებში შესაძლებელია მათი გამოყენება თქვენი მდებარეობის განსასაზღვრად და ამან ელემენტის დამატებითი ხარჯვა შეიძლება გამოიწვიოს."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"სავარაუდო (ქსელის კოორდინატების მიხედვით) მდებარეობა"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"აპს შეეძლება გაიგოს თქვენი სავარაუდო მდებარეობა. ის გამოითვლება მდებარეობის სერვისის მიერ ქსელის მონაცემების - მობილური კავშირგაბმულობის ანძებისა და Wi-Fi-ის მიხედვით. ეს სერვისები ჩართული უნდა იყოს თქვენს მოწყობილობაზე, ხოლო აპებს უნდა ჰქონდეთ მათი გამოყენების უფლება. აპები მათი მონაცემების მიხედვით სავარაუდო მდებარეობის გამოთვლას შეძლებენ."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger-ზე წვდომა"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"აპს შეეძლება, გამოიყენოს SurfaceFlinger-ის დაბალი დონის ელემენტები."</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"ჩარჩოს ბუფერის წაკითხვა"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"აპს შეეძლება წაიკითხოს ბუფერული ჩარჩოს კონტენტი."</string>
-    <string name="permlab_accessInputFlinger" msgid="5348635270689553857">"InputFlinger-ზე წვდომა"</string>
-    <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"აპს შეეძლება, გამოიყენოს InputFlinger-ის დაბალი დონის ფუნქციები."</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"Wifi ეკრანის კონფიგურაცია"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"აპს შეეძლება Wifi ეკრანებთან დაკავშირება და დაკონფიგურირება."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"Wifi ეკრანების მართვა"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"აპს შეეძლება აკონტროლოს Wifi ეკრანების დაბალი დონის ფუნქციები."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"გამომავალი აუდიოს დაჭერა"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"საშუალებას აძლევს აპს დაიჭიროს და გადაამისამართოს გამომავალი აუდიო."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"გამომავალი ვიდეოს დაჭერა"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"საშუალებას აძლევს აპს დაიჭიროს და გადაამისამართოს გამომავალი ვიდეო."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"გამომავალი დაცული ვიდეოს დაჭერა"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"საშუალებას აძლევს აპს დაიჭიროს და გადაამისამართოს გამომავალი დაცული ვიდეო."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"თქვენი აუდიო პარამეტრების შეცვლა"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"აპს შეეძლება აუდიოს გლობალური პარამეტრების შეცვლა. მაგ.: ხმის სიმაღლე და რომელი დინამიკი გამოიყენება სიგნალის გამოსტანად."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"აუდიოს ჩაწერა"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"აპს შეეძლება აუდიო ჩაწერა მიკროფონით. ნებართვა აპს აუდიო ჩაწერის უფლებას აძლევს ნებისმიერ დროს, თქვენი თანხმობის გარეშე."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"სურათებისა და ვიდეოების გადაღება"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"აპს შეეძლება კამერით სურათისა და ვიდეოს გადაღება. ეს ნებართვა აპს უფლებას აძლევს, ნებისმიერ დროს გამოიყენოს კამერა თქვენი დადასტურების გარეშე."</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"კამერის გამოყენებისას გადამცემი ინდიკატორის LED გათიშვა"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"ნებას რთავს წინასწარ დაყენებული სისტემის აპლიკაციას, გამორთოს კამერის გამოყენების ინდიკატორი LED."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"მუდმივად გამორთული ტაბლეტი"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"ტელეფონის სამუდამოდ დეაქტივაცია"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"აპს შეეძლება მთელი ტაბლეტის სამუდამოდ გათიშვა. ეს ძალიან სახიფათოა."</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"აპს შეეძლება მთელი ტელეფონის სამუდამოდ გათიშვა. ეს ძალიან სახიფათოა."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ტაბლეტის გადატვირთვის იძულება"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"ტელეფონის გადატვირთვის იძულება"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"აპს შეეძლება ტაბლეტის იძულებითი გადატვირთვა."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"აპს შეეძლება მოწყობილობის იძულებითი გადატვირთვა."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"UBS ბარათის ფაილურ სისტემაზე წვდომა"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD ბარათის ფაილურ სისტემაზე წვდომა"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"აპს შეეძლება, მიუერთოს და გამოაერთოს ფაილების სისტემები მოსახსნელი მეხსიერებისთვის."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB მეხსიერების წაშლა"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD ბარათის წაშლა"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"აპს შეეძლება, დააფორმატოს მოსახსნელი მეხსიერება."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"შიდა მეხსიერების შესახებ ინფორმაციის მიღება"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"აპს შეეძლება, მიიღოს ინფორმაცია შიდა მეხსიერებაზე."</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"შიდა მეხსიერების შექმნა"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"აპს შეეძლება მეხსიერების შიდა საცავის შექმნა."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"შიდა მეხსიერების განადგურება"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"აპს შეეძლება შიდა მეხსიერების განადგურება."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"შიდა მეხსიერების მიერთება/გამოერთება"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"აპს შეეძლება შიდა მეხსიერების მიერთება / გამოერთება."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"შიდა მეხსიერებისთვის სახელის გადარქმევა"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"აპს შეეძლება შიდა მეხსიერებისთვის სახელის გადარქმევა."</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_manageUsb" msgid="1113453430645402723">"USB მოწყობილობების უფლებებისა და სასურველი პარამეტრების მართვა"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"აპს შეეძლება USB მოწყობილობების პარამეტრებისა და ნებართვების მართვა."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP პროტოკოლის დანერგვა"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"ანიჭებს წვდომას kernel MTP დრაივერს MTP USB პროტოკოლის იმპლემენტაციისთვის."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"აპარატურული აღჭურვილობის ტესტირება"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"აპს შეეძლება, მართოს სხვადასხვა პერიფერიული მოწყობილობა აპარატურის ტესტირების მიზნით."</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"პირდაპირი დარეკვა ტელეფონის ნომრებზე"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"აპს შეეძლება დარეკოს ტელეფონის ნომრებზე თქვენი ჩარევის გარეშე. ამან შესაძლოა გამოიწვიოს თქვენს სატელეფონი ქვითარზე მოულოდნელი ხარჯებისა და ზარების გაჩენა. გაითვალისწინეთ, რომ აპს გადაუდებელი დახმარების ნომრებზე დარეკვა არ შეუძლია. მავნე აპებს შეეძლება თქვენი დადასტურების გარეშე ზარების განხორციელება და შესაბამისი საფასურის გადახდაც მოგიწევთ."</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"პირდაპირი დარეკვა ტელეფონის ნებისმიერ ნომერზე"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"აპს შეეძლება თქვენი მონაწილეობის გარეშე დარეკოს ნებისმიერ ტელეფონის ნომერზე, მათ შორის საგანგებო ნომრებზე. მავნე აპები შეძლებენ არასასურველი ან უკანონო ზარების საგანგებო სამსახურების სიებში განთავსებას."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA ტაბლეტის დაყენების პირდაპირ დაწყება"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA ტელეფონის დაყენების პირდაპირ დაწყება"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"აპს შეეძლება, დაიწყოს CDMA უზრუნველყოფა. მავნე აპებმა შეიძლება ზედმეტად, საჭიროების გარეშე დაიწყონ CDMA უზრუნველყოფა."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"მდებარეობის განახლების შეტყობინებების კონტროლი"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"აპს შეეძლება მდებარეობის განახლების შესახებ რადიო შეტყობინებების აქტივაცია/დეაქტივაცია. ჩვეულებრივი აპები ამ ფუნქციას არ იყენებენ."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"სარეგისტრაციო პარამეტრებზე წვდომა"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"აპებს შეეძლებათ რეგისტრაციის სამსახურის მეშვეობით დამატებული თვისებების წასაკითხად ან ჩასაწერად წვდომა. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"ვიჯეტების არჩევა"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"აპს შეეძლება უთხრას სისტემას, თუ რომელმა აპმა რომელი ვიჯეტი შეიძლება გამოიყენოს. ამ ნებართვის მქონე აპს შეუძლია, პირად მონაცემებზე წვდომა მისცეს სხვა აპებს. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"ტელეფონის მდგომარეობის შეცვლა"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"აპს შეეძლება აკონტროლოს მოწყობილობაზე ტელეფონის ფუნქციები. ამ უფლების მქონე აპს შეუძლია ქსელების გადართვა, ტელეფონის რადიოს ჩართვა და გამორთვა, მომხმარებლისათვის შეტყობინების გარეშე."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"ტელეფონის სტატუსისა და იდენტობის წაკითხვა"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"აპს შეეძლება ჰქონდეს წვდომა მოწყობილობის სატელეფონო ფუნქციებზე. აპმა მსგავსი უფლებით შეძლებს დაადგინოს ტელეფონის ნომერი, მისი სერიული გამოცემა, აქტიური ზარი, დაკავშირებული ნომერი და მსგავსი."</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"დაიცავით ტაბლეტი დაძინებისგან"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"ტელეფონის ძილის რეჟიმში გადასვლის აღკვეთა"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"აპს შეეძლება ხელი შეუშალოს ტაბლეტის დაძინებას."</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"აპს შეეძლება ხელი შეუშალოს ტელეფონის დაძინებას."</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"ტაბლეტის ჩართვა ან გამორთვა"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"ტელეფონის ჩართვა ან გამორთვა"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"აპს შეეძლება, ჩართოს ან გამორთოს ტაბლეტი."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"აპს შეეძლება, ჩართოს ან გამორთოს ტელეფონი."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"ქარხნულ სატესტო რეჟიმში გაშვება"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"მწარმოებლის დაბალი დონის ტესტის რეჟიმში გაშვება, რომლის დროსაც სრულად არის ხელმისაწვდომი ტაბლეტის აპარატული უზრუნველყოფა. ხელმისაწვდომია მხოლოდ მწარმოებლის ტესტის რეჟიმში ჩართულ ტაბლეტზე."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"მწარმოებლის დაბალი დონის ტესტის რეჟიმში გაშვება, რომლის დროსაც სრულად არის ხელმისაწვდომი ტელეფონის აპარატული უზრუნველყოფა. ხელმისაწვდომია მხოლოდ მწარმოებლის ტესტის რეჟიმში ჩართულ ტელეფონზე."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"ფონის დაყენება"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"აპს შეეძლება, დააყენოს სისტემის ფონი."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"ფონის ზომის შესწორება"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"აპს შეეძლება მინიშნებების დაყენება სისტემის ფონის ზომის მიხედვით."</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"სისტემის დაბრუნება ქარხნულ ნაგულისხმევ მდგომარეობაში"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"აპს შეეძლება, სისტემა სრულად გადაყენოს ქარხნულ პარამეტრებზე და წაშალოს ყველა მონაცემი, კონფიგურაცია და დაყენებული აპები."</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"დროის დაყენება"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"აპს შეეძლება ტაბლეტის საათის დროის შეცვლა."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"აპს შეეძლება ტელეფონის საათის დროის შეცვლა."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"დროის სარტყლის დაყენება"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"აპს შეეძლება, შეცვალოს ტაბლეტის დროის სარტყელი."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"აპს შეეძლება ტელეფონის დროის სარტყელის შეცვლა."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"იმოქმედეთ როგორც AccountManagerService"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"აპს შეეძლება განახორციელოს ზარები AccountAuthenticators-ზე."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"მოწყობილობაზე ანგარიშების მოძიება"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"აპს შეეძლება, მიიღოს ტაბლეტისთვის ცნობილი ანგარიშების სია. ეს შეიძლება მოიცავდეს ნებისმიერ ანგარიშს, რომელიც თქვენ მიერ დაყენებული აპლიკაციებით შეიქმნა."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"აპს შეეძლება, მიიღოს ტელეფონისთვის ცნობილი ანგარიშების სია. ეს შეიძლება მოიცავდეს ნებისმიერ ანგარიშს, რომელიც თქვენ მიერ დაყენებული აპლიკაციებით შეიქმნა."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"ანგარიშების შექმნა და პაროლების დაყენება"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"აპს შეეძლება ანგარიშების მენეჯერის ავტორიზაციის შესაძლებლობების გამოყენება. მათ შორის ანგარიშების შექმნა და მათთვის პაროლების მიღება და დაყენება."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"ანგარიშების დამატება ან წაშლა"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"აპს შეეძლება ისეთი ოპერაციების განხორციელება, როგორიცაა ანგარიშების დამატება და წაშლა, ასევე მათი პაროლების წაშლაც."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"მოწყობილობაზე ანგარიშების გამოყენება"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"აპს შეეძლება, მოითხოვოს ავტორიზაციის საიდენტიფიკაციო ნიშნები."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"ქსელის კავშირების ნახვა"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"აპს შეეძლება ქსელის კავშირის შესახებ ინფორმაციის ნახვა, მაგ. რომელი ქსელები არსებობს და რომელია დაკავშირებული."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"ქსელზე სრული წვდომა"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"აპს შეეძლება შექმნას ქსელური ბუდეები და გამოიყენოს მორგებული ქსელის პროტოკოლები. ბრაუზერი და სხვა აპლიკაციები უზრუნველყოფს ინტერნეტში მონაცემების გაგზავნის საშუალებას, ამგვარად ეს უფლება ინფორმაციის გასაგზავნად საჭირო არაა."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"ქსელის პარამეტრებისა და ტრაფიკის შეცვლა / შეწყვეტა"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"აპს შეეძლება ქსელის პარამეტრების შეცვლა, მთელი ქსელის ტრაფიკის შეწყვეტა და ინსპექტირება, მაგალითად, ნებისმიერი APN-ის პორტისა და პროქსის შეცვლა. მავნე აპებს შეეძლებათ ქსელის პაკეტების მონიტორინგი, გადამისამართება ან შეცვლა თქვენთვის შეტყობინების გარეშე."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"ქსელის დაკავშირებულობის შეცვლა"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"აპს შეეძლება, შეცვალოს ქსელის კავშირის მდგომარეობა."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"მიერთებული კავშირის შეცვლა"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"აპს შეეძლება, შეცვალოს მობილური ქსელის კავშირის მდგომარეობა."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"ფონური მონაცემების გამოყენების პარამეტრების შეცვლა"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"აპს შეეძლება, შეცვალოს უკანა ფონის მონაცემების გამოყენების პარამეტრები."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"Wi-Fi კავშირების ნახვა"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"აპს შეეძლება Wi-Fi ქსელის შესახებ ინფორმაციის ნახვა, მაგალითად, Wi-Fi ჩართულია თუ არა, ასევე დაკავშირებული Wi-Fi მოწყობილობის სახელის ნახვა."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"Wi-Fi-ისთან დაკავშირება ან კავშირის შეწყვეტა"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"აპს შეეძლება Wi-Fi წვდომის წერტილებთან დაკავშირება და კავშირის გაწყვეტა და მოწყობილობის კონფიგურაციის შეცვლა Wi-Fi ქსელებისთვის."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"ნებართვა Wi-Fi მრავალმისამართიან მიღებაზე"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"აპს შეეძლება, მიიღოს Wi-Fi ქსელში ყველა მოწყობილობაზე გაგზავნილი პაკეტები ჯგუფური მისამართების გამოყენებით. მოიხმარს მეტ ენერგიას, ვიდრე არამრავალმისამართიანი რეჟიმი."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"აპს შეეძლება, მიიღოს Wi-Fi ქსელში ყველა მოწყობილობაზე გაგზავნილი პაკეტები ჯგუფური მისამართების გამოყენებით. მოიხმარს მეტ ენერგიას, ვიდრე არამრავალმისამართიანი რეჟიმი."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"Bluetooth-ის პარამეტრებზე წვდომა"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"აპს შეეძლება ადგილობრივი Bluetooth ტაბლეტის პარამეტრების დაყენება და დისტანციური მოწყობილობების აღმოჩენა და დაწყვილება."</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"აპს შეეძლება ტელეფონის ადგილობრივი Bluetooth პარამეტრების დაყენება და დისტანციური მოწყობილობების აღმოჩენა და დაწყვილება."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX-თან დაკავშირება და კავშირის გაწყვეტა"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"აპს შეეძლება განსაზღვროს, WiMAX არის თუ არა ჩართული და ასევე ინფორმაცია ნებისმიერი დაკავშირებული WiMAX ქსელის შესახებ."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"WiMAX მდგომარეობის შეცვლა"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"აპს შეეძლება, დაუკავშიროს და გამოაერთოს ტაბლეტი WiMAX ქსელებიდან."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"აპს შეეძლება, დაუკავშიროს და გამოაერთოს ტელეფონი WiMAX ქსელებიდან."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"Bluetooth მოწყობილობებთან დაწყვილება"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"აპს შეეძლება, ნახოს Bluetooth-ის კონფიგურაცია ტაბლეტზე, შექმნას და მიიღოს კავშირები დაწყვილებულ მოწყობილობებთან."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"აპს შეეძლება, ნახოს Bluetooth-ის კონფიგურაცია ტელეფონზე და შექმნას და მიიღოს კავშირები დაწყვილებულ მოწყობილობებთან."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"ახლო მოქმედების რადიოკავშირი (NFC) მართვა"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"აპს შეეძლება ახლო მოქმედების რადიოკავშირის (NFC) მეშვეობით ტეგების, ბარათებისა და წამკითხველების შემცველი მონაცემების მიმოცვლა."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"თქვენი ეკრანის ბლოკის გათიშვა"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"შეეძლება კლავიატურის დაბლოკვისა და პაროლით უზრუნველყოფილი ნებისმიერი უსაფრთხოების ფუნქციის დეაქტივაცია. მაგალითად, ტელეფონი შემომავალი ზარის დროს აუქმებს კლავიატურის დაბლოკვას და კვლავ ააქტიურებს მას, როგორც კი ზარი დასრულდება."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"სინქრონიზაციის პარამეტრების წაკითხვა"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"აპს შეეძლება, წაიკითხოს ანგარიშის სინქრონიზაციის პარამეტრები. მაგალითად, მას შეეძლება განსაზღვროს, არის თუ არა People აპი სინქრონიზებული ანგარიშთან."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"სინქრონიზაციის ჩართვა და გამორთვა"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"აპს შეეძლება, შეცვალოს ანგარიშის სინქრონიზაციის პარამეტრები. მაგალითად, მისი გამოყენება შეიძლება ანგარიშის People აპთან სინქრონიზაციის ჩასართავად."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"სინქრონიზაციის სტატისტიკების წაკითხვა"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"აპს შეეძლება ანგარიშის სინქრონიზაციის სტატისტიკის, მათ შორის სინქრონიზაციის მოვლენების ისტორიისა და სინქრონიზაციისას გადაცემული მონაცემების რაოდენობის წაკითხვა."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"გამოწერილი არხების წაკითხვა"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"აპს შეეძლება ინფორმაციის მოპოვება ბოლოს სინქრონიზებული არხების შესახებ."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"გამოწერილი არხების შეცვლა"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"აპს შეეძლება თქვენი ამჟამინდელი სინქრონიზებული არხების შეცვლა. მავნე აპებმა შესაძოა შეცვალონ თქვენი სინქრონიზებული არხები."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"ლექსიკონში თქვენი დამატებული ტერმინების ნახვა"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"აპს შეეძლება წაიკითხოს ყველა სიტყვა, სახელი და ფრაზა, რომელიც შეიძლება მომხმარებელმა შეიტანა მომხმარებლის ლექსიკონში."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"მომხმარებლისთვის განკუთვნილ ლექსიკონში სიტყვების დამატება."</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"აპს შეეძლება ახალი სიტყვების დამატება მომხმარებლის ლექსიკონში."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"დაცულ მეხსიერებაზე საცდელი წვდომა"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"დაცულ მეხსიერებაზე საცდელი წვდომა"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"აპს შეეძლება, მიაწოდოს USB მეხსიერებას ნებართვა, რომლებიც შემდგომ სხვა მოწყობილობებზეც იქნება ხელმისაწვდომი."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"აპს შეეძლება SD ბარათის ნებართვების შემოწმება, რომლებიც შემდგომ სხვა მოწყობილობებზეც გავრცელდება."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"თქვენი USB მეხსიერების კონტენტის შეცვლა ან წაშლა"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"თქვენი SD ბარათის კონტენტის შეცვლა ან წაშლა"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"უფლებას აძლევს აპს, ჩაწეროს USB მეხსიერებაზე."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"უფლებას აძლევს აპს, ჩაწეროს SD ბარათზე."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"შიდა მედია მეხსიერების კონტენტის შეცვლა/წაშლა"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"აპლიკაციას შეეძლება შიდა მედია მეხსიერების კონტენტის შეცვლა."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"დოკუმენტების საცავის მართვა"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"აპს შეეძლება დოკუმენტების საცავის მართვა."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"ყველა მომხმარებლის გარე მეხსიერებაზე წვდომა"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"აპს შეეძლება ყველა მომხმარებლის გარე მეხსიერებასთან წვდომა."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"ქეშის ფაილურ სისტემაზე წვდომა"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"აპებს აძლევს ქეშირებული სისტემური ფაილების წაკითხვისა და მათში ჩანაწერების გაკეთების საშუალებას."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"ინტერნეტ-ზარების წამოწყება/მიღება"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"აპს შეეძლება, გამოიყენოს SIP სერვისი ინტერნეტ ზარების განსახორციელებლად / საპასუხოდ."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"ქსელის გამოყენების ისტორიის წაკითხვა"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"აპს შეეძლება კონკრეტული ქსელისა და აპების ისტორიული ქსელის გამოყენების წაკითხვას."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"ქსელის დებულების მართვა"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"აპს საშუალება ექნება მართოს ქსელის პოლიტიკა და დააწესოს წესები ცალკეული აპებისთვის."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"ქსელის გამოყენების აღრიცხვის შეცვლა"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"აპს შეეძლება, შეცვალოს ქსელის გამოყენების აღრიცხვა აპებთან მიმართებაში. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"სოკეტის ნიშნების შეცვლა"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"საშუალებას აძლევს აპს შეცვალოს მარშრუტიზაციის სოკეტის ნიშნები"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"წვდომა შეტყობინებებთან"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"აპს შეეძლება მოიძიოს, გამოიკვლიოს და წაშალოს შეტყობინებები, მათ შორის სხვა აპების მიერ გამოქვეყნებული."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"შეტყობინებების მოსმენის სერვისთან დაკავშირება"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"მფლობელს შეეძლება შეტყობინებების მსმენლის სერვისის ზედა დონის ინტერფეისთან დაკავშირება. არ უნდა მოხდეს მისი გამოყენება ჩვეუელებრივი აპებისთვის.ფ"</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"ოპერატორის მიერ მოწოდებული კოფიგურაციის აპის გამოხმობა"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"საშუალებას აძლევს მფლობელს გამოიწვიოს ოპერატორის მიერ მოწოდებული კონფიგურაციის აპი. ჩვეულებრივ აპს ეს წესით არასოდეს არ უნდა დაჭირდეს."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"განხორციელდეს ქსელის მდგომარეობის მონიტორინგი"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"საშუალებას აძლევს აპლიკაციებს განახორციელოს ქსელის მდგომარეობის მონიტორინგი. ეს ფუნქცია ჩვეულებრივ აპებს არ ჭირდება."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"პაროლის წესების დაყენება"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"გააკონტროლეთ ეკრანის განბლოკვის პაროლში დაშვებული სიმბოლოები და მისი სიგრძე."</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"ეკრანის განბლოკვის მცდელობების გაკონტროლება"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"ეკრანის განბლოკვისთვის არასწორად აკრეფილი პაროლების რაოდენობის მონიტორინგი. ტაბლეტის დაბლოკვა ან მასზე არსებული ყველა მონაცემის წაშლა ძალიან ბევრჯერ არასწორი პაროლის შეყვანის შემთხვევაში."</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"ეკრანის განბლოკვისთვის არასწორად აკრეფილი პაროლების რაოდენობის მონიტორინგი. ტელეფონის დაბლოკვა ან მასზე არსებული ყველა მონაცემის წაშლა ძალიან ბევრჯერ არასწორი პაროლის შეყვანის შემთხვევაში."</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"ეკრანის განბლოკვის პაროლის შეცვლა"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"შეცვალეთ ეკრანის განბლოკვის პაროლი."</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"ეკრანის დაბლოკვა"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"გააკონტროლეთ, როგორ და როდის დაიბლოკოს ეკრანი."</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"ყველა მონაცემის წაშლა"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"ტაბლეტის მონაცემების გაუფრთხილებლად წაშლა, ქარხნული მონაცემების აღდგენით"</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"ტელეფონის მონაცემების გაუფრთხილებლად წაშლა, ქარხნული მონაცემების აღდგენით"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"მოწყობილობის გლობალური პროქსის დაყენება"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"დააყენეთ მოწყობილობა გლობალურ პროქსის სერვერის გამოსაყენებლად, როდესაც დებულება გააქტიურებულია. მხოლოდ მოწყობილობის პირველი ადმინი აყენებს ეფექტურ გლობალურ პროქსი სერვერს."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"ეკრანის პაროლის ვადის დაყენება"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"გააკონტროლეთ, თუ რამდენად ხშირად უნდა შეიცვალოს ეკრანის დაბლოკვის პაროლი."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"მეხსიერების დაშიფრვის დაყენება"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"საჭიროა შენახული აპის მონაცემების დაშიფრვა."</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"კამერების გათიშვა"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"მოწყობილობის კამერების გამოყენების აღკვეთა."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"დაბლოკვის ფუნქციების გათიშვა"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"დაბლოკვისას ზოგიერთი ფუნქციის გამოყენების თავიდან აცილება."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"სახლი"</item>
-    <item msgid="869923650527136615">"მობილური"</item>
-    <item msgid="7897544654242874543">"სამსახური"</item>
-    <item msgid="1103601433382158155">"სამსახურის ფაქსი"</item>
-    <item msgid="1735177144948329370">"სახლის ფაქსი"</item>
-    <item msgid="603878674477207394">"პეიჯერი"</item>
-    <item msgid="1650824275177931637">"სხვა"</item>
-    <item msgid="9192514806975898961">"მორგებული"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"სახლი"</item>
-    <item msgid="7084237356602625604">"სამსახური"</item>
-    <item msgid="1112044410659011023">"სხვა"</item>
-    <item msgid="2374913952870110618">"მორგებული"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"სახლი"</item>
-    <item msgid="5629153956045109251">"სამსახური"</item>
-    <item msgid="4966604264500343469">"სხვა"</item>
-    <item msgid="4932682847595299369">"მორგებული"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"სახლი"</item>
-    <item msgid="1359644565647383708">"სამსახური"</item>
-    <item msgid="7868549401053615677">"სხვა"</item>
-    <item msgid="3145118944639869809">"მორგებული"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"სამსახური"</item>
-    <item msgid="4378074129049520373">"სხვა"</item>
-    <item msgid="3455047468583965104">"მორგებული"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"მორგებული"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"სახლი"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"მობილური"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"სამსახური"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"სამსახურის ფაქსი"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"სახლის ფაქსი"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"პეიჯერი"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"სხვა"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"გადმოსარეკი"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"მანქანა"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"კომპანიის ძირ. ნომერი"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"მთავარი"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"სხვა ფაქსი"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"რადიო"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"Telex"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"სამსახურის მობილური"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"სამუშაო პეიჯერი"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"დამხმარე"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"მორგებული"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"დაბადების დღე"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"იუბილე"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"სხვა"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"მორგებული"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"სახლი"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"სამსახური"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"სხვა"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"მობილური"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"მორგებული"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"სახლი"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"სამსახური"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"სხვა"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"მორგებული"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"სახლი"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"სამსახური"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"სხვა"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"მორგებული"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Hangouts"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"Netmeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"სამსახური"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"სხვა"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"მორგებული"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"მორგებული"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"ასისტენტი"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"ძმა"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"შვილი"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"საოჯახო პარტნიორი"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"მამა"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"მეგობარი"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"მენეჯერი"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"დედა"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"მშობელი"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"პარტნიორი"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"რეკომენდატორი:"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"ნათესავი"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"და"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"მეუღლე"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"მორგებული"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"სახლი"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"სამსახური"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"სხვა"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"აკრიფეთ PIN კოდი"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"დაბეჭდეთ PUK კოდი და ახალი PIN კოდი."</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK კოდი"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"ახალი PIN კოდი"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384">"შეეხეთ "<font size="17">"-ს პაროლის"</font>" დასაბეჭდად."</string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"განსაბლოკად აკრიფეთ პაროლი"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"განსაბლოკად აკრიფეთ PIN კოდი"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"არასწორი PIN კოდი."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"განბლოკვისათვის დააჭირეთ მენიუს და შემდეგ 0-ს."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"გადაუდებელი დახმარების ნომრები"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"სერვისი არ არის."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"ეკრანი დაბლოკილია."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"განბლოკვისთვის ან გადაუდებელი ზარისთვის დააჭირეთ მენიუს."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"განბლოკვისთვის დააჭირეთ მენიუს."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"განსაბლოკად დახატეთ ნიმუში"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"გადაუდებელი ზარი"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"ზარზე დაბრუნება"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"სწორია!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"კიდევ სცადეთ"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"კიდევ სცადეთ"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"სახის ამოცნობით განბლოკვის მცდელობამ დაშვებულ რაოდენობას გადააჭარბა"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"დამუხტვა, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"დამუხტულია"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"შეაერთეთ დამტენი."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM ბარათი არ არის"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"ტაბლეტში არ დევს SIM ბარათი."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"არ არის SIM ბარათი ტელეფონში."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"ჩადეთ SIM ბარათი."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM ბარათი არ არის ან არ იკითხება. ჩადეთ SIM ბარათი."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"არამოხმარებადი SIM ბარათი."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"თქვენი SIM ბარათი გამუდმებით გამორთული იყო.\n დაუკავშირდით თქვენი უკაბელო სერვისის პროვაიდერს სხვა SIM ბარათისთვის."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"წინა ჩანაწერი"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"შემდეგი ჩანაწერი"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"პაუზა"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"დაკვრის ღილაკი"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"შეწყვეტა"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"მხოლოდ გადაუდებელი დახმარების ზარები"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"ქსელი ჩაკეტილია"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM ბარათი არის PUK-ით დაბლოკილი."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"იხილეთ მომხმარებლის სახელმძღვანელო ან დაუკავშირდით კლიენტების მომსახურებას."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM ბარათი დაბლოკილია."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM ბარათის განბლოკვა…"</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ დახატეთ განბლოკვის ნიმუში. \n\nსცადეთ ხელახლა <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"თქვენ არასწორად დაბეჭდეთ თქვენი პაროლი <xliff:g id="NUMBER_0">%d</xliff:g> ჯერ. \n\nხელახლა სცადეთ <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ არასწორად შეიყვანეთ PIN კოდი. \n\nსცადეთ ხელახლა <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"თქვენ არასწორად დახატეთ განბლოკვის ნიმუში <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ დაგჭირდებათ თქვენი ტაბლეტის განბლოკვა Google-ში შესვლით.\n\n გთხოვთ, ხელახლა სცადოთ <xliff:g id="NUMBER_2">%d</xliff:g> წამში."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"თქვენ არასწორად დახატეთ განბლოკვის ნიმუში <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ დაგჭირდებათ თქვენი ტელეფონის განბლოკვა Google-ში შესვლით.\n\n გთხოვთ, ხელახლა სცადოთ <xliff:g id="NUMBER_2">%d</xliff:g> წამში."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"თქვენ არასწორად სცადეთ ტაბლეტის განბლოკვა <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ ტაბლეტზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"თქვენ არასწორად სცადეთ ტელეფონის განბლოკვა <xliff:g id="NUMBER_0">%d</xliff:g> ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ ტელეფონზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"თქვენ <xliff:g id="NUMBER">%d</xliff:g>-ჯერ არასწორად სცადეთ ტაბლეტის განბლოკვა. ამიტომ ტაბლეტზე დადგება საწყისი, ქარხნული პარამეტრები."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"თქვენ არასწორად სცადეთ ტელეფონის განბლოკვა <xliff:g id="NUMBER">%d</xliff:g> ჯერ. ახლა ტელეფონზე დაყენდება საწყისი, ქარხნული პარამეტრები."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"კიდევ სცადეთ <xliff:g id="NUMBER">%d</xliff:g> წამში."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"დაგავიწყდათ ნიმუში?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"ანგარიშით განბლოკვა"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"ნახატი ნიმუშის ძალიან ბევრი მცდელობა"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"განბლოკვისთვის გაიარეთ ავტორიზაცია თქვენი Google  ანგარიშით."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"მომხმარებლის სახელი (ელფოსტა)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"პაროლი"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"შესვლა"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"მომხმარებლის არასწორი სახელი ან პაროლი"</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"დაგავიწყდათ მომხმარებლის სახელი და პაროლი?\nეწვიეთ ბმულს "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"შემოწმება..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"განბლოკვა"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"ხმების ჩართვა"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"ხმის გამორთვა"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"ნიმუშის შექმნა დაწყებულია"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"ნიმუში წაიშალა"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"უჯრედი დაემატა."</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"ნიმუშის შექმნა დასრულებულია"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. ვიჯეტი %2$d of %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"ვიჯეტის დამატება"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"ცარიელი"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"განბლოკვის სივრცე გაშლილია."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"განბლოკვის სივრცე ჩაკეცილია."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ვიჯეტი."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"მომხმარებლის ამომრჩეველი"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"სტატუსი"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"კამერა"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"მედიის მართვის ელემენტები"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"დაიწყო ვიჯეტის ხელახლა განლაგება."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"ვიჯეტების გადახარისხება დასრულებულია."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"ვიჯეტი <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> წაიშალა."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"განბლოკვის სივრცის გაშლა."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"გასრიალებით განბლოკვა"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"განბლოკვა ნიმუშით."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"განბლოკვა სახით"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"განბლოკვა Pin-ით."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"პაროლის განბლოკვა"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ნიმუშების სივრცე."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"გადასრიალების სივრცე."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"სიმბოლო"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"სიტყვა"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"ბმული"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"სტრიქონი"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"წარმოების ტესტი ვერ განხორციელდა"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"აქტივობა FACTORY_TEST მხარდაჭერილია მხოლოდ იმ პაკეტებისთვის, რომლებიც მოთავსებულია /system/app."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"ვერ მოიძებნა პაკეტი, რომელიც უზრუნველყოფს ქარხნულ ტესტ ქმედებას."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"გადატვირთვა"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"„<xliff:g id="TITLE">%s</xliff:g>“-თან გვერდი ამბობს:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"ნავიგაციის დადასტურება"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"გვერდის დატოვება"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"ამ გვერდზე დარჩენა"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nდარწმუნებული ხართ, რომ გსურთ ამ გვერდიდან გადასვლა?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"დადასტურება"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"რჩევა: მასშტაბის შესაცვლელად გამოიყენეთ ორმაგი შეხება."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"ავტოშევსება"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"ავტოშევსების დაყენება"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"პროვინცია"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"საფოსტი მისამართი"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"შტატი"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ZIP კოდი"</string>
-    <string name="autofill_county" msgid="237073771020362891">"ქვეყანა"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"კუნძული"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"ოლქი"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"დეპარტამენტი"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"პრეფექტურა"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"სამოქალაქო ოლქი"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"რეგიონი"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"ემირატი"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"თქვენი ვებ სანიშნეებისა და ისტორიის წაკითხვა"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"აპს შეეძლება წაიკითხოს ყველა URL-ის ისტორია, სადაც კი ბრაუზერი შესულა, ასევე ბრაუზერის სანიშნეები. შენიშვნა: ეს უფლება შესაძლოა არ მოიცავდეს მესამე მხარის ბრაუზერებს ან სხვა აპლიკაციებს, რომლებსაც ვებში ძიება შეუძლიათ."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"ვებ სანიშნეებისა და ისტორიის ჩაწერა"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"აპს შეეძლება, შეცვალოს ბრაუზერის ისტორია და თქვენ ტაბლეტში შენახული სანიშნეები. ამან შეიძლება უფლება მისცეს აპს, წაშალოს ან შეცვალოს ბრაუზერის მონაცემები. შენიშვნა: ეს ნებართვა არ შეიძლება შესრულდეს მესამე მხარის ბრაუზერების ან ვებ დათვალიერების შესაძლებლობის მქონე სხვა აპლიკაციების მიერ."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"აპს შეეძლება, შეცვალოს ბრაუზერის ისტორია და თქვენ ტელეფონში შენახული სანიშნეები. ამან შეიძლება უფლება მისცეს აპს, წაშალოს ან შეცვალოს ბრაუზერის მონაცემები. შენიშვნა: ეს ნებართვა არ შეიძლება შესრულდეს მესამე მხარის ბრაუზერების ან ვებ დათვალიერების შესაძლებლობის მქონე სხვა აპლიკაციების მიერ."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"მაღვიძარას დაყენება"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"აპს შეეძლება მაღვიძარას დაყენება დაინსტალირებული მაღვიძარას აპლიკაციაში. ამ ფუნქციას მაღვიძარას ზოგიერთი აპი არ იყენებს."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"ხმოვანი ფოსტის დამატება"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"აპს შეეძლება დაამატოს შეტყობინებები თქვენი ხმოვანი ფოსტის შემოსულებში."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"ბრაუზერის გეოლოკაციის უფლებების შეცვლა"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"აპს შეეძლება ბრაუზერის გეოლოკაციის უფლებების შეცვლა. მავნე აპებმა ეს შესაძლოა გამოიყენონ  ნებისმიერი ვებსაიტისთვის მდებარეობის შესახებ ინფორმაციის გასაგზავნად."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"პაკეტების გადამოწმება"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"აპს შეუძლია დაადასტუროს პაკეტის დაყანების შესაძლებლობა."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"პაკეტების ვერიფიკატორებთან დაკავშირება"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"მფლობელს შეეძლება პაკეტის ვერიფიკატორების მოთხოვნა. არასდროს გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"სერიულ პორტებზე წვდომა"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"მფლობელს შეეძლება სერიულ პორტებზე წვდომა სერიული მენეჯერის  API-ის გამოყენებით."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"კონტენტის მომწოდებლებთან გარედან წვდომა"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"მფლობელს აძლევს კონტენტ პროვაიდერებზე წვდომას გარემოდან. ჩვეულებრივ აპებში არასოდეს გამოიყენება."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"მოწყობილობის ავტომატური განახლების დაშლა"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"მფლობელს შეეძლება სისტემისთვის ინფორმაციის მიწოდება, თუ როდის იქნება შესაფერისი დრო მოწყობილობის გასაახლებლად არაინტერაქტიული გადატვირთვისთვის."</string>
-    <string name="save_password_message" msgid="767344687139195790">"გსურთ, რომ ბრაუზერმა დაიმახსოვროს პაროლი?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"ახლა არა"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"დამახსოვრება"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"არასოდეს"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"ამ გვერდის გახსნის უფლება არ გაქვთ."</string>
-    <string name="text_copied" msgid="4985729524670131385">"ტექსტი დაკოპირებულია გაცვლის ბუფერში."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"მეტი"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"მენიუ+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"[ინტერვალი]"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"enter"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"წაშლა"</string>
-    <string name="search_go" msgid="8298016669822141719">"ძიება"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"ძიება"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"მოთხოვნის ძიება"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"რიგის გასუფთავება"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"შეკითხვის გაგზავნა"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"ხმოვანი ძიება"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"ჩავრთოთ შეხებით დათვალიერება?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>-ს სურს „შეხებით შესწავლის“ რეჟიმის ჩრთვა. ეს ტელეფონის ჟესტებით მართვისა და იმ ელემენტების აღწერის მოსმენის შესაძლებლობას მოგცემთ, რომელსაც შეეხებით."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>-ს სურს „შეხებით შესწავლის“ რეჟიმის ჩრთვა. ეს ტელეფონის ჟესტებით მართვისა და იმ ელემენტების აღწერის მოსმენის შესაძლებლობას მოგცემთ, რომელსაც შეეხებით."</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"ერთი თვის წინ"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"უფრო ადრე, ვიდრე ერთი თვის წინ"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"1 წამის წინ"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> წამის წინ"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"1 წუთის უკან"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> წუთის წინ"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"1 საათის წინ"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> საათის წინ"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"ბოლო <xliff:g id="COUNT">%d</xliff:g> დღე"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"გასული თვე"</string>
-    <string name="older" msgid="5211975022815554840">"უფრო ძველი"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"გუშინ"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> დღის წინ"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"1 წამში"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> წამში"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"1 წუთში"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g> წუთში"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"1 საათში"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> საათში"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"ხვალ"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> დღეში"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"1 წმ. წინ"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> წამის წინ"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"1 წუთის წინ"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> წუთის წინ"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"1 საათის წინ"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> საათის წინ"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"გუშინ"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> დღის წინ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"1 წამში"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> წამის წინ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"1 წუთში"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> წუთში"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"1 საათში"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> საათში"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"ხვალ"</item>
-    <item quantity="other" msgid="2973062968038355991">"<xliff:g id="COUNT">%d</xliff:g> დღეში"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"თარიღი: <xliff:g id="DATE">%s</xliff:g>"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"<xliff:g id="TIME">%s</xliff:g>-ზე"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> წელს"</string>
-    <string name="day" msgid="8144195776058119424">"დღე"</string>
-    <string name="days" msgid="4774547661021344602">"დღეები"</string>
-    <string name="hour" msgid="2126771916426189481">"საათი"</string>
-    <string name="hours" msgid="894424005266852993">"საათი"</string>
-    <string name="minute" msgid="9148878657703769868">"წთ"</string>
-    <string name="minutes" msgid="5646001005827034509">"წუთი"</string>
-    <string name="second" msgid="3184235808021478">"წმ."</string>
-    <string name="seconds" msgid="3161515347216589235">"წამები"</string>
-    <string name="week" msgid="5617961537173061583">"კვირა"</string>
-    <string name="weeks" msgid="6509623834583944518">"კვირები"</string>
-    <string name="year" msgid="4001118221013892076">"წელი"</string>
-    <string name="years" msgid="6881577717993213522">"წელი"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 წამი"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> წამი"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"1 წუთი"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> წუთი"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"1 საათი"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> საათში"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"პრობლემები ვიდეოსთან"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"ეს ვიდეო არ გამოდგება ამ მოწყობილობაზე სტრიმინგისთვის."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"ვიდეოს დაკვრა არ არის შესაძლებელი."</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"კარგი"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"შუადღე"</string>
-    <string name="Noon" msgid="3342127745230013127">"შუადღე"</string>
-    <string name="midnight" msgid="7166259508850457595">"შუაღამე"</string>
-    <string name="Midnight" msgid="5630806906897892201">"შუაღამე"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"ყველას არჩევა"</string>
-    <string name="cut" msgid="3092569408438626261">"ამოჭრა"</string>
-    <string name="copy" msgid="2681946229533511987">"კოპირება"</string>
-    <string name="paste" msgid="5629880836805036433">"ჩასმა"</string>
-    <string name="replace" msgid="5781686059063148930">"ჩანაცვლება…"</string>
-    <string name="delete" msgid="6098684844021697789">"წაშლა"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL კოპირება"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"ტექსტის მონიშვნა"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"ტექსტის მონიშვნა"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"ლექსიკონში დამატება"</string>
-    <string name="deleteText" msgid="6979668428458199034">"წაშლა"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"შეყვანის მეთოდი"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"ქმედებები ტექსტზე"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"თავისუფალი ადგილი იწურება"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"სისტემის ზოგიერთმა ფუნქციამ შესაძლოა არ იმუშავოს"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> გაშვებულია"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"შეეხეთ მეტი ინფორმაციისათვის ან აპის შესაწყვეტად."</string>
-    <string name="ok" msgid="5970060430562524910">"OK"</string>
-    <string name="cancel" msgid="6442560571259935130">"გაუქმება"</string>
-    <string name="yes" msgid="5362982303337969312">"OK"</string>
-    <string name="no" msgid="5141531044935541497">"გაუქმება"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"ყურადღება"</string>
-    <string name="loading" msgid="7933681260296021180">"ჩატვირთვა…"</string>
-    <string name="capital_on" msgid="1544682755514494298">"ჩართ."</string>
-    <string name="capital_off" msgid="6815870386972805832">"გამორთულია"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"მოქმედების დასრულება შემდეგი საშუალებით:"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"ამ ქმედებისთვის ნაგულისხმევად გამოყენება."</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"ნაგულისხმევი პარამეტრების წაშლა სისტემის პარამეტრებში &gt; აპებში &gt; ჩამოტვირთულებში."</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"აირჩიეთ მოქმედება"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB მოწყობილობისათვის აპის შერჩევა"</string>
-    <string name="noApplications" msgid="2991814273936504689">"ვერც ერთი აპი ვერ შეასრულებს ამ ქმედებას."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"სამწუხაროდ, <xliff:g id="APPLICATION">%1$s</xliff:g> შეწყდა."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"სამწუხაროდ, პროცესი <xliff:g id="PROCESS">%1$s</xliff:g> შეწყდა."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> არ რეაგირებს.\n\nგსურთ, მისი დახურვა?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> აქტივობა არ რეაგირებს.\n\nგსურთ მისი დახურვა?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> არ რეაგირებს. გსურთ მისი დახურვა?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"პროცესი <xliff:g id="PROCESS">%1$s</xliff:g> არ რეაგირებს.\n\nგსურთ, მისი დახურვა?"</string>
-    <string name="force_close" msgid="8346072094521265605">"OK"</string>
-    <string name="report" msgid="4060218260984795706">"ანგარიში"</string>
-    <string name="wait" msgid="7147118217226317732">"მოცდა"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"გვერდი აღარ რეაგირებს.\n\nგსურთ მისი დახურვა?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"აპი გადამისამართებულია"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> გაშვებულია."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> თავდაპირველად გაეშვა."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"მასშტაბი"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"ყოველთვის ჩვენება"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"ხელახალი გააქტიურება განყოფილებაში: სისტემის პარამეტრები &gt; აპები &gt; ჩამოტვირთულები."</string>
-    <string name="smv_application" msgid="3307209192155442829">"აპმა <xliff:g id="APPLICATION">%1$s</xliff:g> (პროცესი <xliff:g id="PROCESS">%2$s</xliff:g>) დაარღვია საკუთარი StrictMode დებულება."</string>
-    <string name="smv_process" msgid="5120397012047462446">"ამ პროცესმა <xliff:g id="PROCESS">%1$s</xliff:g> დააზიანა საკუთარი StrictMode დებულება."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android ახალ ვერსიაზე გადადის…"</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"<xliff:g id="NUMBER_0">%1$d</xliff:g> აპლიკაციის (სულ <xliff:g id="NUMBER_1">%2$d</xliff:g>-დან)  ოპტიმიზაცია."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"აპების ჩართვა"</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"ჩატვირთვის დასასრული."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> გაშვებულია"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"აპზე გადასართველად შეეხეთ"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"გსურთ, აპების გადართვა?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"სხვა აპი არის უკვე გაშვებული, რომელიც უნდა შეჩერდეს ახლის დაწყებამდე."</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g>-თან დაბრუნება"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"არ ჩართოთ ახალი აპი."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"დასაწყისი <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"შეაჩერე ძველი აპი ცვლილებების შენახვის გარეშე."</string>
-    <string name="sendText" msgid="5209874571959469142">"შეარჩიეთ ქმედება ტექსტისთვის."</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"მრეკავის ხმა"</string>
-    <string name="volume_music" msgid="5421651157138628171">"მედიის ხმა"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"დაკვრა Bluetooth-ის გამოყენებით"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"არჩეულია უხმო რეჟიმი"</string>
-    <string name="volume_call" msgid="3941680041282788711">"ხმის სიმაღლე ზარის დროს"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"Bluetooth ხმის სიმაღლე ზარის დროს"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"მაღვიძარას ხმა"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"შეტყობინების ხმა"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"ხმა"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"Bluetooth-ის ხმა"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"ზარის სიმაღლე"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"ზარის ხმა"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"მედიის ხმა"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"შეტყობინების ხმა"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"ნაგულისხმევი ზარი"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"ნაგულისხმევი ზარი (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"არც ერთი"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"ზარები"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"უცნობი ზარი"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi ქსელი ხელმისაწვდომია"</item>
-    <item quantity="other" msgid="4192424489168397386">"Wi-Fi ქსელები ხელმისაწვდომია."</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"ხელმისაწვდომი Wi-Fi ქსელების გახსნა"</item>
-    <item quantity="other" msgid="7915895323644292768">"ხელმისაწვდომი Wi-Fi ქსელების გახსნა"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Wi-Fi ქსელთან დაკავშირება"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"ქსელში შესვლა"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Wi-Fi-თან დაკავშირება ვერ მოხერხდა"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" აქვს ცუდი ინტერნეტ კავშირი."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"Wi-Fi Direct"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"ჩართეთ Wi-Fi Direct. ეს გამოიწვევს Wi-Fi კლიენტისა/უსადენო ქსელის გამორთვას."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"ვერ მოხერხდა Wi-Fi Direct-ის გაშვება."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi Direct ჩართულია"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"პარამეტრებისთვის შეეხეთ"</string>
-    <string name="accept" msgid="1645267259272829559">"მიღება"</string>
-    <string name="decline" msgid="2112225451706137894">"უარყოფა"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"მოწვევა გაგზავნილია"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"მოწვევა დასაკავშირებლად"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"გამგზავნი:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"მიმღები:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"შეიყვანეთ საჭირო PIN:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"პინ-კოდი:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"ტაბლეტი დროებით გაითიშება Wi-Fi-დან, სანამ მიერთებულია <xliff:g id="DEVICE_NAME">%1$s</xliff:g>-ზე"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"ტელეფონი დროებით გაითიშება Wi-Fi-დან, სანამ მიერთებულია <xliff:g id="DEVICE_NAME">%1$s</xliff:g>-ზე"</string>
-    <string name="select_character" msgid="3365550120617701745">"სიმბოლოს ჩასმა"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS შეტყობინებები იგზავნება"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt;აგზავნის დიდი რაოდენობის SMS შეტყობინებებს. გსურთ, მისცეთ ამ აპს უფლება გააგრძელოს შეტყობინეების დაგზავნა?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"უფლების მიცემა"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"უარყოფა"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; სურს შეტყობინების გაგზავნა &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt;-ისთვის."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"ამან "<font fgcolor="#ffffb060">"შესაძლოა გამოიწვიოს ცვლილებები"</font>" თქვენი მობილურის ანგარიშზე."</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"ეს გამოიწვევს დანახარჯებს თქვენ მობილურ ანგარიშზე."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"გაგზავნა"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"გაუქმება"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"ჩემი არჩევანის დამახსოვრება"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"ამის შეცვლა შეგიძლიათ მოგვიანებით აპების პარამეტრებიდან."</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"ნებართვის მიცემა - ყოველთვის"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"არასოდეს მისცე უფლება"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM ბარათი ამოღებულია"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"მობილური კავშირი არ იქნება ხელმისაწვდომი, ვიდრე არ ჩადებთ ქმედით SIM ბარათს და გადატვირთავთ."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"დასრულდა"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM ბარათი დაემატა"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"გადატვირთეთ თქვენი მოწყობილობა მობილურ ქსელზე წვდომისთვის."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"გადატვირთვა"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"დროის დაყენება"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"თარიღის დაყენება"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"დაყენება"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"დასრულდა"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"ახალი: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"მომწოდებელი: <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"ნებართვა საჭირო არ არის"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"ამისათვის შესაძლოა მოგიწიოთ თანხის გადახდა"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB მასიური მეხსიერება"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB დაკავშირებულია"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"თქვენ დაკავშირებული ხართ კომპიუტერთან USB-ის მეშვეობით. თუ გსურთ კომპიუტერსა და თქვენს Android USB მოწყობილობას შორის ფაილების კოპირება შეეხეთ ქვემოთ მდებარე ღილაკს."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"თქვენ დაუკავშირდით კომპიუტერს USB-ის მეშვეობით. შეეხეთ ქვემოთ მდებარე ღილაკს, თუ გსურთ ფაილების კოპირება თქვენ კომპიუტერსა და Android SD ბარათს შორის."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB მეხსიერების ჩართვა"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB მასიური მეხსიერებისთვის თქვენი USB მეხსიერების გამოყენება პრობლემას ქმნის."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"USB მასიური მეხსიერებისთვის თქვენი SD ბარათის გამოყენება პრობლემას ქმნის."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB დაკავშირებულია"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"შეეხეთ ფაილების კოპირებისათვის კომპიუტერში/კომპიუტერიდან."</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB მეხსიერების გამორთვა"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"შეეხეთ USB მეხსიერების გამოსართველად."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"ხდება USB მეხსიერების გამოყენება"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB მეხსიერების გამორთვამდე, გამოიღეთ თქვენი Android-ის USB თქვენი კომპიუტერიდან."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB მეხსიერების გამორთვამდე, გამოაერთეთ თქვენი Android SD ბარათი კომპიუტერიდან."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB მეხსიერების გამორთვა"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB-გამორთვისას წარმოიშვა შეცდომა. შეამოწმეთ, რომ გათიშეთ თქვენი USB ჰოსტი, შემდეგ სცადეთ ხელახლა."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB მეხსიერების ჩართვა"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"თუ USB მეხსიერებას ჩართავთ, თქვენ მიერ მოხმარებადი რამდენიმე აპი შეწყვეტს მუშაობას და შესაძლოა მიუწვდომელი გახდეს USB მეხსიერების გამორთვამდე."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB ოპერაცია წარუმატებელი იყო"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"OK"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"დაკავშირებულია როგორც მედია მოწყობილობა"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"დაკავშირებულია როგორც კამერა"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"დაკავშირებულია როგორც დამყენებელი"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"დაკავშირებულია USB აქსესუართან"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"შეეხეთ USB-ის სხვა პარამეტრების სანახავად."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"დავაფორმატო USB მეხსიერება?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"გსურთ SD ბარათის დაფორმატება?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"თქვენ USB მეხსიერებაში შენახული ყველა ფაილი წაიშლება. ეს მოქმედება ვეღარ შეიცვლება!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"თქვენს ბარათზე ყველა მონაცემი დაიკარგება."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"დაფორმატება"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB გამართვა შეერთებულია"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"შეეხეთ, რათა შეწყვიტოთ USB-ის გამართვა."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"აირჩიეთ შეყვანის მეთოდი"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"შეყვანის მეთოდების დაყენება"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"ფიზიკური კლავიატურა"</string>
-    <string name="hardware" msgid="7517821086888990278">"მოწყობილობა"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"შეარჩიეთ კლავიატურის განლაგება."</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"კლავიატურის განლაგების შესარჩევად შეეხეთ."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"კანდიდატები"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB მეხსიერების მომზადება"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD ბარათის მომზადება"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"შეცდომების შემოწმება"</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"ცარიელი USB მეხსიერება"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"ცარიელი SD ბარათი"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB მეხსიერება ცარიელია ან მხარდაუჭერელი ფაილური სისტემა აქვს."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD ბარათი ცარიელია ან ფაილური სისტემა მხარდაუჭერელია."</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"დაზიანებული USB მეხსიერება"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"დაზიანებული SD ბარათი"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB მეხსიერება დაზიანებულია. სცადეთ მისი ხელახლა დაფორმატება."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD ბარათი დაზიანებულია. სცადეთ მისი ხელახლა დაფორმატება."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB მეხსიერება მოულოდნელად გამოირთო"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD ბარათი მოულოდნელად მოიხსნა"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"გამოერთებამდე გათიშეთ USB მეხსიერება, რათა თავიდან აიცილოთ მონაცემების დაკარგვა."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"გამოერთებამდე გათიშეთ SD ბარათი, რათა თავიდან აიცილოთ მონაცემების დაკარგვა."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB მეხსიერების გამორთვა უსაფრთხოა"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD ბარათის მოხსნა უსაფრთხოა"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"შეგიძლიათ უსაფრთხოდ გამოაერთოთ USB მეხსიერება."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"შეგიძლიათ უსაფრთხოდ გამოაერთოთ SD ბარათი."</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"გამორთული USB მეხსიერება"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"გამოღებულია SD ბარათი."</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB მეხსიერება გამოერთებულია. მიუერთეთ ახალი მედია."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD ბარათი მოხსნილია. ჩასვით ახალი."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"შესატყვისი აქტივობები არ არის."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"კომპონენტების გამოყენების სტატისტიკის განახლება"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"აპს შეეძლება, შეცვალოს კომპონენტის გამოყენების შეგროვებული სტატისტიკა. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"კონტენტის კოპირება"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"აპს შეეძლება კონტენტის კოპირებისთვის კონტეინერის ნაგულისხმევი სერვისის გამოძახება. არ გამოიყენება ჩვეულებრივ აპებში."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"მულტიმედია მონაცემების გადამისამართება"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"აპლიკაციას შეეძლება გადაამისამართოს მულტიმედია მონაცემები სხვა გარე მოწყობილობებისკენ."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"ღილაკების დამცავის უსაფრთხო საცავზე წვდომა"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"აპლიკაციას ღილაკების დამცავის უსაფრთხო საცავზე წვდომის უფლება ექნება."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"ღილაკების დამცავის გამოჩენისა და დამალვის მართვა"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"აპლიკაციას შეეძლება ღილაკების დამცავის კონტროლი."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"მასშტაბის მართვისთვის შეეხეთ ორჯერ."</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"ვერ დაემატა ვიჯეტი."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"გადასვლა"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"ძებნა"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"გაგზავნა"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"მომდევნო"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"დასრულდა"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"წინა"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"განხორციელება"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"ნომერზე დარეკვა\n<xliff:g id="NUMBER">%s</xliff:g>-ის გამოყენებით"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"კონტაქტის შექმნა\n <xliff:g id="NUMBER">%s</xliff:g>-ის გამოყენებით"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"მითითებული ერთი ან რამდენიმე აპი ითხოვს თქვენს ანგარიშზე წვდომის უფლებას, ახლა და მომავალში."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"გსურთ ამ მოთხოვნის დაკმაყოფილება?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"წვდომის მოთხოვნა"</string>
-    <string name="allow" msgid="7225948811296386551">"უფლების მიცემა"</string>
-    <string name="deny" msgid="2081879885755434506">"აკრძალვა"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"მოთხოვნილია ნებართვა"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"მოთხოვნილია ნებრათვა \nანგარიშისთვის: <xliff:g id="ACCOUNT">%s</xliff:g>"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"შეყვანის მეთოდი"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"სინქრონიზაცია"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"წვდომა"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"ფონი"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"ფონის შეცვლა"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"შეტყობინებების მსმენელი"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN გააქტიურებულია"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN გააქტიურებულია <xliff:g id="APP">%s</xliff:g>-ის მიერ"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"შეეხეთ ქსელის სამართავად."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"მიერთებულია <xliff:g id="SESSION">%s</xliff:g>-ზე. შეეხეთ ქსელის სამართავად."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"მიმდინარეობს მუდმივად ჩართული VPN-ის მიერთება…"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"მუდმივად ჩართული VPN-ის მიერთებულია"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"შეცდომა მუდამ VPN-ზე"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"კონფიგურაციისთვის შეეხეთ"</string>
-    <string name="upload_file" msgid="2897957172366730416">"ფაილის არჩევა"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"ფაილი არჩეული არ არის"</string>
-    <string name="reset" msgid="2448168080964209908">"საწყისზე დაბრუნება"</string>
-    <string name="submit" msgid="1602335572089911941">"გაგზავნა"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"მანქანის რეჟიმი ჩართულია"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"შეეხეთ მანქანის რეჟიმიდან გამოსასვლელად."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"ინტერნეტის მიერთება ან უსადენო ქსელი აქტიურია."</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"შესაქმნელად შეეხეთ"</string>
-    <string name="back_button_label" msgid="2300470004503343439">"უკან"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"მომდევნო"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"გამოტოვება"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"მობილური ინტერნეტის მაღალი მოხმარება"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"შეეხეთ, რათა შეიტყოთ მეტი მობილურის ინტერნეტის გამოყენების შესახებ."</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"მობილური ინტერნეტის ლიმიტი გადაჭარბებულია"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"შეეხეთ, რათა შეიტყოთ მეტი მობილურის ინტერნეტის გამოყენების შესახებ."</string>
-    <string name="no_matches" msgid="8129421908915840737">"შესატყვისები არ არის."</string>
-    <string name="find_on_page" msgid="1946799233822820384">"გვერდზე ძებნა"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"1 დამთხვევა"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="INDEX">%d</xliff:g> <xliff:g id="TOTAL">%d</xliff:g>-დან"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"დასრულდა"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB მეხსიერების გათიშვა…"</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"მიმდინარეობს SD ბარათის მოხსნა…"</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"მიმდინარეობს USB მეხსიერების გასუფთავება…"</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD ბარათის წაშლა..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB მეხსიერების წაშლა ვერ მოხერხდა."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD ბარათის წაშლა ვერ მოხერხდა."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD ბარათი მანამ მოიხსნა, ვიდრე გამოერთებული იქნებოდა."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB მეხსიერება ამჟამად შემოწმების პროცესშია."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"ამჟამად მიმდინარეობს SD ბარათის შემოწმება."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD ბარათი გამოერთებულია."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"USB მეხსიერებას კომპიუტერი იყენებს ამჟამად."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD ბარათს კომპიუტერი იყენებს ამჟამად."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"გარე მედია უცნობ მდგომარეობაშია."</string>
-    <string name="share" msgid="1778686618230011964">"გაზიარება"</string>
-    <string name="find" msgid="4808270900322985960">"ძიება"</string>
-    <string name="websearch" msgid="4337157977400211589">"ვებ-ძიება"</string>
-    <string name="find_next" msgid="5742124618942193978">"მომდევნოს მოძებნა"</string>
-    <string name="find_previous" msgid="2196723669388360506">"წინას პოვნა"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"მდებარეობა მოთხოვნილი იყო <xliff:g id="NAME">%s</xliff:g>-ისგან"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"მდებარეობის მოთხოვნა"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"მოთხოვნილია <xliff:g id="NAME">%1$s</xliff:g>-ის მიერ (<xliff:g id="SERVICE">%2$s</xliff:g>)"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"დიახ"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"არა"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"წაშლის შეზღუდვა გადაჭარბებულია"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> წაშლილი ერთეულია <xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g>-თვის, ანგარიში <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g>. რისი გაკეთება გსურთ?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"ერთეულების წაშლა"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"წაშლების გაუქმება"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"ამჟამად არაფერი გააკეთო"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"ანგარიშის არჩევა"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"ანგარიშის დამატება"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"ანგარიშის დამატება &amp;raquo;"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"გაზრდა"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"შემცირება"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g>-ს შეეხეთ და არ აუშვათ."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"აასრიალეთ ზემოთ გასაზრდელად და ჩაასრიალეთ ქვემოთ შესამცირებლად."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"ერთი წუთით წინ"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"წუთების შემცირება"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"საათის მომატება"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"საათით უკან"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"PM-ის დაყენება"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"AM-ის დაყენება"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"თვის მომატება"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"ერთი თვით უკან"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"დღის მომატება"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"დღის მოკლება"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"წლის მომატება"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"წლის მოკლება"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"გაუქმება"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"წაშლა"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"დასრულდა"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"რეჟიმის შეცვლა"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift-"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"შეყვანა"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"აპის არჩევა"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"გაზიარება"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"გაუზიარეთ <xliff:g id="APPLICATION_NAME">%s</xliff:g>-ს"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"გასრიალებით მართვა. შეეხეთ &amp; არ აუშვათ."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"გაასრიალეთ ზემოთ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"გაასრიალეთ ქვემოთ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"გაასრიალეთ მარცხნივ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"გაასრიალეთ მარჯვნივ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"განბლოკვა"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"კამერა"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"უხმო"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"ხმის ჩართვა"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"ძიება"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"განბლოკვისათვის გადაფურცლეთ"</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"შეაერთედ ყურსასმენები, პაროლის ღილაკები რომ გაიგოთ."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"წერტილი."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"მთავარზე ნავიგაცია"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"ზემოთ ნავიგაცია"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"მეტი ვარიანტები"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"შიდა მეხსიერება"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD ბარათი"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB მეხსიერება"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"რედაქტირება"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"ინტერნეტის გამოყენების გაფრთხილება"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"შეეხეთ მოხმარებისა და პარამეტრების სანახავად."</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G მონაცემები გათიშულია"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"მობილური ინტერნეტი გაითიშა"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi‑Fi მონაცემთა გამორთვა"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"გასააქტიურებლად შეეხეთ."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"გადაჭარბებულია 2G-3G მონაცემების ლიმიტი"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G ლიმიტი გადაჭარბებულია"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"მობილური ინტერნეტის ლიმიტი გადაჭარბებულია."</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi‑Fi მონაცემთა ლიმიტი გადაჭარბებულია"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"ლიმიტი გადაჭარბებულია <xliff:g id="SIZE">%s</xliff:g>-ით."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"მონაცემთა ფონური გადაცემა შეზღუდულია"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"შეეხეთ შეზღუდვის მოსახსნელად"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"უსაფრთხოების სერტიფიკატი"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"ეს სერტიფიკატი სწორია."</string>
-    <string name="issued_to" msgid="454239480274921032">"მიეცა:"</string>
-    <string name="common_name" msgid="2233209299434172646">"სტანდარტული სახელი:"</string>
-    <string name="org_name" msgid="6973561190762085236">"ორგანიზაცია:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"ორგანიზაციული ერთეული:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"გამცემი:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"ვალიდურობა:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"გაცემული:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"ვადა იწურება:"</string>
-    <string name="serial_number" msgid="758814067660862493">"სერიული ნომერი:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"ანაბეჭდები:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 ანაბეჭდი:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 თითის ანაბეჭდი:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"ყველას ნახვა"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"აქტივობის არჩევა"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"გაზიარება"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"მოწყობილობა ჩაკეტილია."</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"იგზავნება..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"გსურთ ბრაუზერის გაშვება?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"უპასუხებთ ზარს?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"ყოველთვის"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"მხოლოდ ერთხელ"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"ტაბლეტი"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"ტელეფონი"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"ყურსასმენები"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"სპიკერების მიმაგრება"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"სისტემა"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"Bluetooth აუდიო"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"უსადენო ეკრანი"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"დასრულდა"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"მედია გამომავალი"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"სკანირება..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"დაკავშირება..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"ხელმისაწვდომი"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"მიუწვდომელი"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"გამოიყენება"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"ჩამონტაჟებული ეკრანი"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI ეკრანი"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"გადაფარვა #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", დაცული"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"უსადენო ეკრანი დაკავშირებულია"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"გამოსახულება გადაეცემა სხვა მოწყობილობას"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"კავშირის გაწყვეტა"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"გადაუდებელი დახმარების ზარი"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"დაგავიწყდათ ნიმუში"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"არასწორი ნიმუში"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"არასწორი პაროლი"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"არასწორი PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"კიდევ სცადეთ <xliff:g id="NUMBER">%1$d</xliff:g> წამში."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"დახატეთ თქვენი ნიმუში."</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN-ის შეყვანა"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"შეიყვანეთ PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"პაროლის შეყვანა"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM ამჟამად დეაქტივირებულია. გასაგრძელებლად შეიყვანეთ PUK კოდი. დეტალებისთვის მიმართეთ მობილურ ოპერატორს."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"სასურველი PIN კოდის შეყვანა"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"სასურველი PIN კოდის დადასტურება"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM ბარათის განბლოკვა…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"არასწორი PIN კოდი."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"აკრიფეთ PIN, რომელიც შედგება 4-დან 8 ციფრამდე."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK კოდი უნდა იყოს რვა ან მეტი ციფრისგან შემდგარი."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"ხელახლა შეიყვანეთ სწორი PUK კოდი. რამდენიმე წარუმატებელი მცდელობა გამოიწვევს SIM ბარათის დაბლოკვას."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN კოდები არ ემთხვევა"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"ნახატი ნიმუშის ძალიან ბევრი მცდელობა"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"განბლოკვისთვის გაიარეთ ავტორიზაცია თქვენი Google  ანგარიშით."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"მომხმარებლის სახელი (ელფოსტა)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"პაროლი"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"შესვლა"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"არასწორი სახელი, ან პაროლი."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"დაგავიწყდათ მომხმარებლის სახელი და პაროლი?\nეწვიეთ "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"მიმდინარეობს ანგარიშის შემოწმება…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ არასწორად შეიყვანეთ PIN კოდი. \n\nსცადეთ ხელახლა <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ არასწორად დაბეჭდეთ თქვენი პაროლი. \n\nხელახლა სცადეთ <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ დახატეთ განბლოკვის ნიმუში. \n\nსცადეთ ხელახლა <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"თქვენ არასწორად სცადეთ ტაბლეტის განბლოკვა <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ ტაბლეტზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"თქვენ არასწორად სცადეთ ტელეფონის განბლოკვა <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ ტელეფონზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"თქვენ არასწორად სცადეთ ტაბლეტის განბლოკვა <xliff:g id="NUMBER">%d</xliff:g>-ჯერ. ტაბლეტზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"თქვენ <xliff:g id="NUMBER">%d</xliff:g>-ჯერ არასწორად სცადეთ ტელეფონის განბლოკვა. ამიტომ ტელეფონზე დადგება საწყისი, ქარხნული პარამეტრები."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"თქვენ არასწორად დახატეთ თქვენი განბლოკვის ნიმუში <xliff:g id="NUMBER_0">%d</xliff:g> ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ მოგთხოვთ ტაბლეტის განბლოკვას ელფოსტის ანგარიშის გამოყენებით.\n\n ხელახლა სცადეთ <xliff:g id="NUMBER_2">%d</xliff:g> წამში."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"თქვენ არასწორად დახატეთ თქვენი განბლოკვის ნიმუში <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ, დაგჭირდებათ თქვენი ტელეფონის განბლოკვა ელფოსტის ანგარიშის გამოყენებით.\n\n ხელახლა სცადეთ <xliff:g id="NUMBER_2">%d</xliff:g> წამში."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"ამოშლა"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"რეკომენდებულ დონეზე მაღლა გსურთ ხმის აწევა?\nდიდი ხნის განმავლობაში ძალიან ხმამაღლა მოსმენამ შესაძლოა სმენა დაგიზიანოთ."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"გეჭიროთ ორი თითი მარტივი წვდომის ჩასართავად."</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"მარტივი წვდომა ჩართულია."</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"მარტივი წვდომა გაუქმდა."</string>
-    <string name="user_switched" msgid="3768006783166984410">"ამჟამინდელი მომხმარებელი <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="owner_name" msgid="2716755460376028154">"მფლობელი"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"შეცდომა"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"ამ აპს შეზღუდული პროფილების ანგარიშების მხარდაჭერა არ აქვს"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"ამ მოქმედების შესასრულებლად აპლიკაცია ვერ მოიძებნა"</string>
-    <string name="revoke" msgid="5404479185228271586">"გაუქმება"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"Letter"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"Government Letter"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"Legal"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Junior Legal"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Ledger"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Tabloid"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"გაუქმებული"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"შეცდომა კონტენტის ჩაწერისას"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"შეიყვანეთ PIN"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"ამჟამინდელი PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"ახალი PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"გაიმეორეთ ახალი PIN"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"შექმენით PIN შეზღუდვების ცვლილებებისათვის"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN-ები არ ემთხვევა. სცადეთ ხელახლა."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN ძალიან მოკლეა. უნდა შედგებოდეს სულ ცოტა 4 ციფრისგან."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"არასწორი PIN. სცადეთ ისევ 1 წამში."</item>
-    <item quantity="other" msgid="8030607343223287654">"არასწორი PIN. სცადეთ ისევ <xliff:g id="COUNT">%d</xliff:g> წამში."</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"გაასრიალეთ ეკრანის კიდეზე ზოლის გამოსაჩენად"</string>
-</resources>
diff --git a/core/res/res/values-km-rKH/strings.xml b/core/res/res/values-km-rKH/strings.xml
index 0a98a08..6dace3c 100644
--- a/core/res/res/values-km-rKH/strings.xml
+++ b/core/res/res/values-km-rKH/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"សូម​ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈពេល <xliff:g id="COUNT">%d</xliff:g> វិនាទី"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"សូម​ព្យាយាម​ម្ដងទៀត​នៅ​ពេល​ក្រោយ។"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"អូស​​​ចុះក្រោម ដើម្បី​ចេញ​ពី​ការ​បង្ហាញ​ពេញ​អេក្រង់"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"អូស​​​ចុះក្រោម ដើម្បី​ចេញ​ពី​ការ​បង្ហាញ​ពេញ​អេក្រង់"</string>
 </resources>
diff --git a/core/res/res/values-km/strings.xml b/core/res/res/values-km/strings.xml
deleted file mode 100644
index 3d62d1a..0000000
--- a/core/res/res/values-km/strings.xml
+++ /dev/null
@@ -1,1587 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"គីឡូបៃ"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"មេកាបៃ"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"ជីកាបៃ"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"តេរ៉ាបៃ"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;គ្មាន​ចំណង​ជើង&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(គ្មាន​លេខ​ទូរស័ព្ទ)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(មិន​ស្គាល់)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"សារ​ជា​សំឡេង"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"បញ្ហា​ក្នុង​ការ​តភ្ជាប់​ ឬ​កូដ MMI មិន​ត្រឹមត្រូវ។"</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"ប្រតិបត្តិការ​ត្រូវ​បាន​ដាក់​កម្រិត​​​ចំពោះ​លេខ​ហៅ​ថេរ​តែ​ប៉ុណ្ណោះ។"</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"បាន​បើក​សេវាកម្ម។"</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"បាន​បើក​សេវាកម្ម​សម្រាប់៖"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"បាន​បិទ​សេវាកម្ម។"</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"ការ​ចុះឈ្មោះ​ជោគ​ជ័យ។"</string>
-    <string name="serviceErased" msgid="1288584695297200972">"ការ​លុប​បាន​ជោគជ័យ។"</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"ពាក្យ​សម្ងាត់​មិន​ត្រឹម​ត្រូវ"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI បញ្ចប់​។"</string>
-    <string name="badPin" msgid="9015277645546710014">"កូដ PIN ចាស់​ដែល​អ្នក​បាន​បញ្ចូល​មិន​ត្រឹមត្រូវ។"</string>
-    <string name="badPuk" msgid="5487257647081132201">"កូដ PUK ដែល​អ្នក​បាន​បញ្ចូល​មិន​ត្រឹមត្រូវ។"</string>
-    <string name="mismatchPin" msgid="609379054496863419">"កូដ​ PIN ដែល​អ្នក​បាន​បញ្ចូល​​មិន​ដូច​គ្នា។"</string>
-    <string name="invalidPin" msgid="3850018445187475377">"បញ្ចូល​កូដ PIN ដែល​មាន​​​ពី ៤ ដល់ ៨​លេខ"</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"បញ្ចូល​កូដ PUK ដែល​មាន​ពី​ ៨ លេខ​ ឬ​វែង​ជាង​នេះ។"</string>
-    <string name="needPuk" msgid="919668385956251611">"ស៊ីមកាត​​របស់​អ្នក​ជាប់​កូដ PUK ។ បញ្ចូល​កូដ PUK ដើម្បី​ដោះ​សោ។"</string>
-    <string name="needPuk2" msgid="4526033371987193070">"បញ្ចូល​កូដ PUK2 ដើម្បី​ដោះ​សោ​ស៊ីម​កាត។"</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"លេខ​សម្គាល់​អ្នក​ហៅ​​ចូល"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"លេខ​សម្គាល់​អ្នក​ហៅ​ចេញ"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"បញ្ជូន​ការ​ហៅ​បន្ត"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"រង់ចាំ​ការ​ហៅ"</string>
-    <string name="BaMmi" msgid="455193067926770581">"រារាំង​ការ​ហៅ"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"ប្ដូរ​ពាក្យ​សម្ងាត់"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"ប្ដូរ​កូដ PIN"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"បង្ហាញ​ការ​ហៅ​លេខ"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"បាន​ដាក់​កម្រិត​ការ​ហៅ​លេខ"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"ការ​ហៅ​បី​ផ្លូវ"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"បដិសេធ​ការ​ហៅ​រំខាន​ដែល​មិន​ចង់បាន"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"ការ​បញ្ជូន​លេខ​ហៅ"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"កុំ​រំខាន"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"បាន​ដាក់​កម្រិត​លំនាំដើម​លេខ​សម្គាល់​អ្នក​ហៅ។​​​ ការ​ហៅ​បន្ទាប់៖​ បាន​ដាក់កម្រិត"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"មិន​បាន​ដាក់កម្រិត​លំនាំដើម​លេខ​សម្គាល់​អ្នក​ហៅ។ ការ​ហៅ​បន្ទាប់៖ មិន​បាន​ដាក់​កម្រិត។"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"មិន​បាន​ដាក់​កម្រិត​លេខ​សម្គាល់​អ្នក​ហៅ​លំនាំ​ដើម។ ការ​ហៅ​បន្ទាប់៖​ បាន​ដាក់កម្រិត"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"មិន​បាន​ដាក់កម្រិត​លំនាំដើម​លេខ​សម្គាល់​អ្នក​ហៅ។ ការ​ហៅ​បន្ទាប់៖ មិន​បាន​ដាក់​កម្រិត។"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"មិន​បាន​ផ្ដល់​សេវាកម្ម។"</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"អ្នក​មិន​អាច​ប្ដូរ​ការ​កំណត់​លេខ​សម្គាល់​អ្នក​ហៅ​បានទេ។"</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"បាន​ប្ដូរ​ការ​ចូល​ដំណើរការ​ដែល​បាន​ដាក់​​កម្រិត"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"បាន​ទប់ស្កាត់​សេវាកម្ម​ទិន្នន័យ។"</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"បាន​ទប់ស្កាត់​សេវាកម្ម​ពេល​អាសន្ន។"</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"សេវាកម្ម​សំឡេង​ត្រូវ​បាន​ទប់ស្កាត់។"</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"បាន​ទប់ស្កាត់​សេវាកម្ម​សំឡេង​ទាំងអស់។"</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"បាន​ទប់ស្កាត់​សេវាកម្ម​ SMS ។"</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"បាន​ទប់​ស្កាត់​សេវាកម្ម​សំឡេង/ទិន្នន័យ។"</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"បាន​ទប់ស្កាត់​សេវាកម្ម​សំឡេង/សារ SMS ។"</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"សំឡេង/ទិន្នន័យ/សេវាកម្ម SMS ទាំងអស់​ត្រូវ​បាន​ទប់​ស្កាត់។"</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"សំឡេង"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"ទិន្នន័យ"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"ទូរសារ"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"សារ SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"អ​សម​កាលកម្ម"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"កញ្ចប់​ព័ត៌មាន"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"បើក​ទ្រនិច​បង្ហាញ​រ៉ូមីង"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"បិទ​ទ្រនិច​បង្ហាញ​រ៉ូមីង"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"ពន្លឺ​​ទ្រនិច​បង្ហាញ​រ៉ូមីង"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"ចេញ​ពី​អ្នកជិតខាង"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"ក្រៅ​​អាគារ"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"រ៉ូមីង - ប្រព័ន្ធ​ពេញចិត្ត"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"រ៉ូ​មីង - ប្រព័ន្ធ​​អាច​ប្រើ​បាន"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"រ៉ូ​មីង - ​សម្ពន្ធភាព"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"រ៉ូ​មីង - ដៃគូ​ពិសេស"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"រ៉ូ​មីង - មុខងារ​សេវា​កម្ម​ពេញលេញ"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"រ៉ូ​មីង - មុខងារ​សេវា​តាម​​ផ្នែក"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"បើក​បដា​រ៉ូមីង"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"បិទ​បដា​រ៉ូមីង"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"​ស្វែង​រក​សេវាកម្ម"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g> ៖ មិន​បាន​បញ្ជូន​បន្ត"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> បន្ទាប់​ពី <xliff:g id="TIME_DELAY">{2}</xliff:g> វិនាទី"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g> ៖ មិន​បាន​បញ្ជូន​បន្ត"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g> ៖ មិន​បាន​បញ្ជូន​បន្ត"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"កូដ​លក្ខណៈ​ពេញលេញ។"</string>
-    <string name="fcError" msgid="3327560126588500777">"បញ្ហា​ការ​តភ្ជាប់​ ឬ​កូដ​លក្ខណៈ​​​មិន​ត្រឹមត្រូវ​។"</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"យល់​ព្រម"</string>
-    <string name="httpError" msgid="7956392511146698522">"មាន​កំហុស​បណ្ដាញ។"</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"រក​មិន​ឃើញ URL ។"</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"គ្រោងការណ៍​ផ្ទៀងផ្ទាត់​តំបន់បណ្ដាញ​មិន​ត្រូវ​បាន​គាំទ្រ។"</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"មិន​អាច​ផ្ទៀងផ្ទាត់។"</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"ការ​ផ្ទៀងផ្ទាត់​​តាម​រយៈ​ម៉ាស៊ីន​​មេ​​ប្រូកស៊ី​មិន​បាន​ជោគជ័យ​។"</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"មិន​អាច​ភ្ជាប់​ម៉ាស៊ីន​មេ។"</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"មិន​អាច​ទាក់ទង​ជា​មួយ​ម៉ាស៊ីន​មេ។ ព្យាយាម​ម្ដង​ទៀត​ពេល​ក្រោយ។"</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"អស់​ពេល​តភ្ជាប់​ទៅ​ម៉ាស៊ីន​មេ។"</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"ទំព័រ​មាន​ការ​បញ្ជូន​ម៉ាស៊ីន​មេ​បន្ត​ច្រើន​ពេក។"</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"មិន​បាន​គាំទ្រ​ពិធីការ។"</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"មិន​អាច​បង្កើត​ការ​តភ្ជាប់​មាន​សុវត្ថិភាព។"</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"មិន​អាច​បើក​ទំព័រ​បាន​ទេ ព្រោះ​ URL ត្រឹមត្រូវ។"</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"មិន​អាច​ចូល​ដំណើរការ​ឯកសារ​។"</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"រក​មិន​ឃើញ​ឯកសារ​បាន​ស្នើ។"</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"កំពុង​ដំណើរការ​សំណើ​​​ច្រើន​ពេក។ ព្យាយាម​ម្ដង​ទៀត​ពេល​ក្រោយ។"</string>
-    <string name="notification_title" msgid="8967710025036163822">"កំហុស​ក្នុង​ការ​ចូល​សម្រាប់ <xliff:g id="ACCOUNT">%1$s</xliff:g>"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"មាន​ការ​លុប <xliff:g id="CONTENT_TYPE">%s</xliff:g> ច្រើន​ពេក។"</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ឧបករណ៍​ផ្ទុក​នៃ​​កុំព្យូទ័រ​បន្ទះ​ពេញ។ លុប​ឯកសារ​មួយ​ចំនួន​។"</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"ឧបករណ៍​ផ្ទុក​ទូរស័ព្ទ​ពេញ! លុប​ឯកសារ​មួយ​ចំនួន​ដើម្បី​បង្កើន​ទំហំ។"</string>
-    <string name="me" msgid="6545696007631404292">"ខ្ញុំ"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ជម្រើស​កុំព្យូទ័រ​បន្ទះ"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"ជម្រើស​ទូរស័ព្ទ"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"របៀប​ស្ងាត់"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"បើក​បណ្ដាញ​ឥត​ខ្សែ"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"បិទ​បណ្ដាញ​ឥតខ្សែ"</string>
-    <string name="screen_lock" msgid="799094655496098153">"ចាក់​សោ​អេក្រង់"</string>
-    <string name="power_off" msgid="4266614107412865048">"បិទ"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"បិទ​កម្ម​វិធី​រោទ៍"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"កម្មវិធី​រោទ៍​ញ័រ"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"បើក​កម្មវិធី​រោទ៍"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"កំពុង​បិទ..."</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក​នឹង​បិទ។"</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"ទូរស័ព្ទ​របស់​អ្នក​នឹង​បិទ។"</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"តើ​អ្នក​ចង់​បិទ​?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"ចាប់ផ្ដើម​ឡើងវិញ​ដើម្បី​ចូល​របៀប​សុវត្ថិភាព"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"តើ​អ្នក​ចង់​ចាប់ផ្ដើម​ឡើងវិញ​ចូល​របៀប​សុវត្ថិភាព? វា​នឹង​បិទ​កម្មវិធី​ភាគី​ទី​បី​ដែល​អ្នក​បាន​ដំឡើង។ ពួក​វា​នឹង​ត្រូវ​បាន​ស្ដារ​ឡើងវិញ​ពេល​អ្នក​ចាប់ផ្ដើម​ម្ដង​ទៀត។"</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"ថ្មី"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"គ្មាន​កម្មវិធី​ថ្មី​​ៗ​​។"</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ជម្រើស​កុំព្យូទ័រ​បន្ទះ"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"ជម្រើស​ទូរស័ព្ទ"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"ចាក់​សោ​អេក្រង់"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"បិទ"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"របាយការណ៍​កំហុស"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"យក​របាយការណ៍​កំហុស"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"វា​នឹង​​ប្រមូល​ព័ត៌មាន​អំពី​ស្ថានភាព​ឧបករណ៍​របស់​អ្នក ដើម្បី​ផ្ញើ​ជា​សារ​អ៊ីមែល។ វា​នឹង​ចំណាយ​ពេល​តិច​ពី​ពេល​ចាប់ផ្ដើម​របាយការណ៍​រហូត​ដល់​ពេល​វា​រួចរាល់​ដើម្បី​ផ្ញើ សូម​អត់ធ្មត់។"</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"របៀប​ស្ងាត់"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"បិទ​សំឡេង"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"បើក​សំឡេង"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"របៀប​ជិះ​យន្តហោះ"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"បាន​បើក​របៀប​ពេល​ជិះ​យន្ត​ហោះ"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"បាន​បិទ​របៀប​យន្តហោះ"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"របៀប​​​សុវត្ថិភាព"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"ប្រព័ន្ធ​​ Android"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"សេវាកម្ម​ដែល​កាត់​លុយ​របស់​អ្នក"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"ធ្វើ​អ្វី​ដែល​អាច​កាត់​លុយ​របស់​អ្នក។"</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"សារ​របស់​អ្នក"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"អាន និង​សរសេរ​សារ SMS, អ៊ីមែល និង​សារ​ផ្សេងៗ​ទៀត​របស់​អ្នក។"</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"ព័ត៌មាន​ផ្ទាល់ខ្លួន​របស់​អ្នក"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"ចូល​ដំណើរការ​ព័ត៌មាន​ដោយ​ផ្ទាល់​អំពី​អ្នក​ ដែល​បា​ន​រក្សាទុក​ក្នុង​កាត​ទំនាក់ទំនង​របស់​អ្នក។"</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"ព័ត៌មាន​សង្គម​របស់​អ្នក"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"ចូល​ដំណើរការ​ព័ត៌មាន​ដោយ​ផ្ទាល់​អំពី​ទំនាក់ទំនង និង​ការ​ភ្ជាប់​សង្គម​របស់​អ្នក។"</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"ទីតាំង​របស់​អ្នក"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"តាមដាន​ទីតាំង​ជាក់ស្ដែង​របស់​អ្នក។"</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"ការ​ទាក់ទង​បណ្ដាញ"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"ចូល​ដំណើរការ​លក្ខណៈ​​បណ្ដាញ​ផ្សេងៗ។"</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"ប៊្លូធូស"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"ចូល​ដំណើរការ​ឧបករណ៍ និង​បណ្ដាញ​តាម​ប៊្លូធូស។"</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"ការ​កំណត់​អូឌីយ៉ូ"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"ប្ដូរ​ការ​កំណត់​អូឌីយ៉ូ។"</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"ប៉ះពាល់​ដល់​ថ្ម"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"ប្រើ​លក្ខណៈ​ដែល​អាច​ប្រើ​ថាមពល​ថ្ម​យ៉ាង​រហ័ស។"</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"ប្រតិទិន"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"​ចូល​ដំណើរការ​​ប្រតិទិន​\"និង​ព្រឹត្តិការណ៍​ដោយ​ផ្ទាល់​។"</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"អាន​វចនានុក្រម​អ្នក​ប្រើ"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"អាន​ពាក្យ​នៅ​ក្នុង​វចនានុក្រម​​អ្នក​ប្រើ​។"</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"សរសេរ​វចនានុក្រម​អ្នក​ប្រើ"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"បន្ថែម​ពាក្យ​ទៅ​វចនានុក្រម​អ្នក​ប្រើ។"</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"ចំណាំ​ និង​ប្រវត្តិ"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"ចូល​​ដំណើរការ​ចំណាំ និង​ប្រវត្តិ​កម្មវិធី​អ៊ីនធឺណិត​ដោយ​ផ្ទាល់។"</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"រោទ៍"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"កំណត់​នាឡិកា​រោទ៍"</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"សារ​ជា​សំឡេង"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"ចូល​ដំណើរការ​សារ​ជា​សំឡេង​ដោយ​ផ្ទាល់។"</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"មីក្រូ​ហ្វូន"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"ចូល​ដំណើរការ​​មីក្រូហ្វូន​ដោយ​ផ្ទាល់ ​ដើម្បី​ថត​សំឡេង​។"</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"ម៉ាស៊ីន​ថត"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"ចូល​ដំណើរការ​ម៉ាស៊ីន​ថត​រូប ឬ​វីដេអូ​ដោយ​ផ្ទាល់។"</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"ចាក់សោ​​អេក្រង់"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"មាន​សមត្ថភាព​ប៉ះពាល់​ឥរិយាបថ​ការ​ចាក់​សោ​អេក្រង់​លើ​ឧបករណ៍​របស់​អ្នក។"</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"ព័ត៌មាន​កម្មវិធី​របស់​អ្នក"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"លទ្ធភាព​ប៉ះពាល់​ដល់​ឥរិយាបថ​កម្មវិធី​ផ្សេងៗ​លើ​ឧបករណ៍​របស់​អ្នក។"</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"ផ្ទាំង​រូបភាព"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"ប្ដូរ​ការ​កំណត់​ផ្ទាំង​រូបភាព​ឧបករណ៍"</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"នាឡិកា"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"ប្ដូរ​ពេលវេលា ឬ​តំបន់​ពេលវេលា​ឧបករណ៍"</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"របារ​ស្ថានភាព"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"ប្ដូរ​ការ​កំណត់​របារ​ស្ថានភាព​ឧបករណ៍។"</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"ការ​កំណត់​​​ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"ចូល​ដំណើរការ​ការ​កំណត់​ធ្វើ​សម​កាល​កម្ម។"</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"គណនី​របស់​អ្នក"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"ចូល​ដំណើរការ​គណនី​ដែល​មាន។"</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"ពិនិត្យ​ផ្នែករឹង"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"ចូល​ដំណើរការ​ផ្នែក​រឹង​ដោយ​ផ្ទាល់​ក្នុង​ទូរស័ព្ទ។"</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"ហៅ​ទូរស័ព្ទ"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"តាមដាន ថត និង​ដំណើរការ​ការ​ហៅ​ទូរស័ព្ទ។"</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"ឧបករណ៍​ប្រព័ន្ធ"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"ចូល​ដំណើរការ​កម្រិត​ទាប និង​ពិនិត្យ​ប្រព័ន្ធ។"</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"ឧបករណ៍​​អភិវឌ្ឍ"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"លក្ខណៈ​ចាំបាច់​សម្រាប់​តែ​អ្នក​អភិវឌ្ឍ​កម្មវិធី។"</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"ចំណុច​ប្រទាក់​អ្នក​ប្រើ​កម្មវិធី​ផ្សេងៗ"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"ប្រសិទ្ធ​ភាព​ចំណុច​ប្រទាក់​អ្នក​ប្រើ​នៃ​កម្មវិធី​ផ្សេងៗ។"</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"ការ​ផ្ទុក"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"ចូល​ដំណើរការ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"ចូល​ដំណើរការ​កាត​អេសឌី"</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"លក្ខណៈ​ភាព​ងាយស្រួល"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"លក្ខណៈ​ដែល​ជា​បច្ចេកវិទ្យា​ជំនួយ​អាច​ស្នើ។"</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"ទៅ​យក​មាតិកា​បង្អួច"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"ពិនិត្យ​មាតិកា​បង្អួច​ដែល​អ្នក​កំពុង​ទាក់ទង​ជា​មួយ។"</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"បើក​ការ​រក​មើល​​ដោយ​ប៉ះ"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"ធាតុ​បាន​ប៉ះ​នឹង​ត្រូវ​បាន​អាន​ឮ​ៗ អេក្រង់​អាច​ត្រូវ​បាន​ស្វែងរក​ដោយ​ប្រើ​កាយវិការ។"</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"បើក​ការ​ចូល​ដំណើរការ​បណ្ដាញ​ដែល​បាន​ធ្វើ​ឲ្យ​ប្រសើរ"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"ស្គ្រីប​អាច​ត្រូវ​បាន​ដំឡើង​ ដើម្បី​ធ្វើ​ឲ្យ​មាតិកា​កម្មវិធី​អាច​ចូល​ដំណើរការ​បាន​កាន់តែ​ច្រើន។"</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"មើល​អត្ថបទ​ដែល​វាយ"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"រួម​បញ្ចូល​ទិន្នន័យ​ផ្ទាល់​ខ្លួន​ ដូចជា​លេខ​កាត​ឥណទាន និង​ពាក្យ​សម្ងាត់។"</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"បិទ ឬ​កែ​របារ​ស្ថានភាព"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"ឲ្យ​កម្មវិធី​បិទ​របារ​ស្ថានភាព ឬ​បន្ថែម និង​លុប​រូប​តំណាង​ប្រព័ន្ធ។"</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"របារ​ស្ថានភាព"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"ឲ្យ​កម្មវិធី​ក្លាយ​ជា​របារ​ស្ថានភាព។"</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"ពង្រីក/បង្រួម​របារ​ស្ថាន​ភាព"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"ឲ្យ​កម្មវិធី​ពង្រីក ឬ​បង្រួម​របារ​ស្ថានភាព។"</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"នាំ​ផ្លូវ​ការ​ហៅ​ចេញ​ឡើងវិញ"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"ឲ្យ​កម្មវិធី​ដំណើរការ​ការ​ហៅ​ចេញ និង​ប្ដូរ​លេខ​ត្រូវ​ហៅ។ សិទ្ធិ​នេះ​អនុញ្ញាត​ឲ្យ​កម្មវិធី​តាមដាន ប្ដូរ​ទិស ឬ​ការពារ​ការ​ហៅ​ចេញ។"</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"ទទួល​សារ​អត្ថបទ (សារ SMS​)"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"ឲ្យ​កម្មវិធី​ទទួល និង​ដំណើរការ​​សារ MMS ។ មាន​ន័យ​ថា កម្មវិធី​អាច​ត្រួតពិនិត្យ​ ឬ​លុប​សារ​ដែល​បាន​ផ្ញើ​ទៅ​ឧបករណ៍​របស់​អ្នក ដោយ​​មិន​បង្ហាញ​អ្នក។"</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"ទទួល​សារ​អត្ថបទ (MMS​)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"ឲ្យ​កម្មវិធី​ទទួល និង​ដំណើរការ​​សារ​ MMS ។ វា​មាន​ន័យ​ថា កម្មវិធី​អាច​តាមដាន​ ឬ​លុប​សារ​ដែល​បាន​ផ្ញើ​ទៅ​ឧបករណ៍​របស់​អ្នក​ដោយ​មិន​បង្ហាញ​ពួកវា។"</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"ទទួល​ការ​ប្រកាស​ពេល​​​អាសន្ន"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"ឲ្យ​កម្មវិធី​ទទួល​​ដំណើរការ​សារ​ប្រកាស​ពេល​អាសន្ន។ សិទ្ធិ​នេះ​មាន​តែ​​កម្មវិធី​ប្រព័ន្ធ​ប៉ុណ្ណោះ​​អាច​ប្រើ​បាន​។"</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"អាន​សារ​ប្រកាស​ចល័ត"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"ឲ្យ​កម្មវិធី​អាន​សារ​ប្រកាស​ការ​ហៅ​ដែល​ឧបករណ៍​របស់​​អ្នក​បាន​ទទួល។ ការ​ជូន​ដំណឹង​ប្រកាស​ចល័ត​ត្រូវ​បាន​បញ្ជូន​ទៅ​ទីតាំង​មួយ​ចំនួន ដើម្បី​ព្រមាន​អ្នក​អំពី​ស្ថានភាព​អាសន្ន។ កម្មវិធី​ព្យាបាទ​អាច​ជ្រៀតជ្រែក​ការ​អនុវត្ត ឬ​ប្រតិបត្តិការ​ឧបករណ៍​របស់​អ្នក​​ពេល​ទទួល​ការ​ប្រកាស​ចល័ត​ពេល​អាសន្ន។"</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"ផ្ញើ​សារ SMS"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"ឲ្យ​កម្មវិធី​ផ្ញើ​សារ​ SMS ។ វា​អាច​គិត​ថ្លៃ​សេវាកម្ម​ដែល​មិន​រំពឹង​ទុក។ កម្មវិធី​ព្យាបាទ​អាច​គិត​ថ្លៃ​សេវាកម្ម​ពី​អ្នក​ ដោយ​ផ្ញើ​សារ​ដោយ​គ្មាន​ការ​បញ្ជាក់​របស់​អ្នក។"</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"ផ្ញើ​ព្រឹត្តិការណ៍​សារ​តាមរយៈ​ការ​ឆ្លើយតប"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"ឲ្យ​កម្មវិធី​ផ្ញើ​សំណើ​ទៅ​កម្មវិធី​ផ្ញើ​សារ ដើម្បី​គ្រប់គ្រង​ព្រឹត្តិការណ៍​សារ​តាម​រយៈ​ការ​ឆ្លើយតប​សម្រាប់​ការ​ហៅ​ចូល។"</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"អាន​សារ​អត្ថបទ​របស់​អ្នក (SMS ឬ MMS​)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"ឲ្យ​កម្មវិធី​​អាន​សារ SMS ដែល​មាន​ក្នុង​កុំព្យូទ័រ​បន្ទះ ឬ​ស៊ីម​កាត។ វា​ឲ្យ​កម្មវិធី​អាន​សារ SMS ទាក់ទង​នឹង​មាតិកា ឬ​ព័ត៌មាន​សម្ងាត់។"</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"ឲ្យ​​កម្មវិធី​អាន​សារ SMS ដែល​បាន​រក្សាទុក​ក្នុង​ទូរស័ព្ទ ឬ​​ស៊ីម​កាត​។ វា​ឲ្យ​កម្មវិធី​អាន​សារ SMS ទាំង​អស់​ ទាក់ទង​នឹង​មាតិកា​ ឬ​ព័ត៌មាន​សម្ងាត់។"</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"កែសម្រួល​សារ​អត្ថបទ​របស់​អ្នក (សារ SMS ឬ MMS​)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"ឲ្យ​កម្មវិធី​សរសេរ​សារ SMS ដែល​​បាន​រក្សាទុក​ក្នុង​កុំព្យូទ័រ​បន្ទះ ឬ​ស៊ីម​កាត​របស់​អ្នក។ កម្មវិធី​ព្យាបាទ​អាច​លុប​សារ​របស់​អ្នក។"</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"ឲ្យ​កម្មវិធី​សរសេរ​សារ SMS ដែល​បាន​រក្សាទុក​ក្នុង​ទូរស័ព្ទ ឬ​​ស៊ីម​កាត។ កម្មវិធី​ព្យាបាទ​អាច​លុប​សារ​របស់​អ្នក។"</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"ទទួល​សារ​អត្ថបទ (WAP​)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"ឲ្យ​កម្មវិធី​ទទួល និង​ដំណើរការ​សារ WAP ។ សិទ្ធិ​នេះ​​មានលទ្ធភាព​តាមដាន ឬ​លុប​សារ​ដែល​បាន​ផ្ញើ​ឲ្យ​អ្នក​ដោយ​មិន​បង្ហា​ញ។"</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"ទៅ​យក​កម្មវិធី​កំពុង​ដំណើរការ"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"ឲ្យ​កម្មវិធី​ទៅ​យក​ព័ត៌មាន​លម្អិត​អំពី​កិច្ចការ​ដែល​កំពុង​ដំណើរការ​បច្ចុប្បន្ន។ វា​អាច​ឲ្យ​កម្មវិធី​រកមើល​ព័ត៌មាន​ថា​តើ​កម្មវិធី​ណាមួយ​ត្រូវ​បាន​ប្រើ​លើ​ឧបករណ៍។"</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"អន្តរកម្ម​តាម​​អ្នក​ប្រើ"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"ឲ្យ​កម្មវិធី​អនុវត្ត​សកម្មភាព​ឆ្លង​អ្នកប្រើ​ផ្សេងៗ​​លើ​ឧបករណ៍។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​បំពាន​ការ​ការពារ​រវាង​អ្នក​ប្រើ។"</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"អាជ្ញាប័ណ្ណ​ពេញលេញ​ ដើម្បី​ទាក់ទង​អ្នក​ប្រើ"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"ឲ្យ​អន្តរកម្ម​ដែល​មាន​ទាំង​អស់​គ្រប់​អ្នក​ប្រើ។"</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"គ្រប់គ្រង​អ្នក​ប្រើ"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"ឲ្យ​កម្មវិធី​គ្រប់គ្រង​អ្នកប្រើ​លើ​ឧបករណ៍ រួមមាន​ការ​ច្រោះ បង្កើត និង​លុប។"</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"ទៅ​យក​សេចក្ដី​លម្អិត​កម្មវិធី​កំពុង​ដំណើរការ"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"ឲ្យ​កម្មវិធី​ទៅ​យក​ព័ត៌មាន​លម្អិត​អំពី​កិច្ចការ​ដែល​កំពុង​ដំណើរការ​បច្ចុប្បន្ន។ កម្មវិធី​ព្យាបាទ​អាច​រកមើល​ព័ត៌មាន​ឯកជន​អំពី​កម្មវិធី​ផ្សេងៗ។"</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"តម្រៀប​កម្មវិធី​កំពុង​ដំណើរការ​ឡើងវិញ"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"ឲ្យ​កម្មវិធី​ផ្លាស់ទី​ភារកិច្ច​​ទៅ​ផ្ទៃ​ខាង​មុខ។​ កម្មវិធី​អាច​ធ្វើ​វា​ដោយ​គ្មាន​ការ​បញ្ចូល​របស់​អ្នក។"</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"បញ្ឈប់​ដំណើរការ​កម្មវិធី"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"ឲ្យ​កម្មវិធី​លុប​ភារកិច្ច​ និង​បញ្ឈប់​កម្មវិធី​របស់​ពួកវា។ កម្មវិធី​ព្យាបាទ​អាច​រំខាន​ឥរិយាបថ​កម្មវិធី​ផ្សេងៗ។"</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"គ្រប់គ្រង​ជង់​សកម្មភាព"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"ឲ្យ​កម្មវិធី​បន្ថែម, លុប និង​កែ​ជង់​សកម្មភាព​ដែល​កម្មវិធី​ផ្សេង​ដំណើរការ។ កម្មវិធី​ព្យាបាទ​អាច​រំខាន​ឥរិយាបថ​កម្មវិធី។"</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"ចាប់ផ្ដើម​សកម្មភាព​ណា​មួយ"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"ឲ្យ​កម្មវិធី​ចាប់ផ្ដើម​សកម្មភាព​ណា​មួយ ទាក់ទង​នឹង​សិទ្ធិ​ការពារ​ ឬ​ស្ថានភាព​បាន​នាំចេញ។"</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"កំណត់​ភាព​ឆប​គ្នា​នៃ​អេក្រង់"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"ឲ្យ​កម្មវិធី​ពិនិត្យ​របៀប​​ត្រូវ​​គ្នា​របស់​​អេក្រង់​នៃ​កម្មវិធី​ផ្សេងៗ។ កម្មវិធី​ព្យាបាទ​អាច​បំផ្លាញ​ឥរិយាបថ​នៃ​កម្មវិធី​ផ្សេងៗ។"</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"បើក​ការ​កែ​កំហុស​កម្មវិធី"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"ឲ្យ​កម្មវិធី​បើក​ការ​កែ​កំហុស​សម្រាប់​កម្មវិធី​ផ្សេង​ទៀត។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​បញ្ឈប់​កម្មវិធី​ផ្សេង។"</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"ប្ដូរ​ការ​កំណត់​បង្ហាញ​ប្រព័ន្ធ"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"ឲ្យ​កម្មវិធី​ប្ដូរ​ការ​កំណត់​​រចនាសម្ព័ន្ធ​បច្ចុប្បន្ន ដូច​ជា​មូលដ្ឋាន ឬ​ទំហំ​ពុម្ពអក្សរ​ទាំងអស់។"</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"បើក​របៀប​រថយន្ត"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"ឲ្យ​កម្មវិធី​បើក​របៀប​រថយន្ត។"</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"បិទ​កម្មវិធី​ផ្សេងៗ"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"ឲ្យ​កម្មវិធី​បញ្ឈប់​ដំណើរការ​​ផ្ទៃ​ខាង​ក្រោយ​នៃ​កម្មវិធី​ផ្សេងៗ​។ វា​អាច​ធ្វើ​ឲ្យ​កម្មវិធី​ផ្សេង​ឈប់​ដំណើរការ។"</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"បង្ខំ​ឲ្យ​បញ្ឈប់​កម្មវិធី​ផ្សេង"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"ឲ្យ​កម្មវិធី​បញ្ឈប់​កម្មវិធី​ផ្សេង​ដោយ​បង្ខំ។"</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"បង្ខំ​ឲ្យ​កម្មវិធី​បិទ"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"ឲ្យ​កម្មវិធី​បង្ខំ​សកម្មភាព​ផ្សេងៗ​ដែល​នៅ​ក្នុង​ផ្ទៃ​ខាង​មុខ​បិទ និង​ទៅ​ក្នុង​ផ្ទៃ​ខាង​ក្រោយ។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"ទៅ​យក​ស្ថានភាព​ខាង​ក្នុង​ប្រព័ន្ធ"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"ឲ្យ​កម្មវិធី​ទៅ​យក​ស្ថានភាព​ខាង​ក្នុង​នៃ​ប្រព័ន្ធ។ កម្មវិធី​ព្យាបាទ​អាច​ទៅ​យក​ព័ត៌មាន​ឯកជន​និង​មាន​សុវត្ថិភាព​ផ្សេងៗ​ដែល​ពួកវា​មិន​គួរ​ត្រូវការ​តាម​ធម្មតា។"</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"ទៅ​យក​មាតិកា​អេក្រង់"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"ឲ្យ​កម្មវិធី​ទៅ​យក​មាតិកា​បង្អួច​សកម្ម។ កម្មវិធី​ព្យាបាទ​អាច​ទៅ​យក​មាតិកា​បង្អួច​ទាំង​មូល និង​ពិនិត្យ​អត្ថបទ​ទាំងអស់ លើកលែង​តែ​ពាក្យ​សម្ងាត់។"</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"បើក​មធ្យោបាយ​ងាយស្រួល​ជា​បណ្ដោះ​អាសន្ន"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"ឲ្យ​កម្មវិធី​បើក​ភាព​ងាយស្រួល​លើ​ឧបករណ៍​ជា​បណ្ដោះអាសន្ន។ កម្មវិធី​ព្យាបាទ​អាច​បើក​ភាព​ងាយស្រួល​ដោយ​មិន​ឲ្យ​អ្នក​ប្រើ​ដឹង។"</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"ទៅ​យក​ព័ត៌មាន​បង្អួច"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"ឲ្យ​កម្មវិធី ទៅ​យក​ព័ត៌មាន​អំពី​បង្អួច​ពី​កម្មវិធី​គ្រប់គ្រង​បង្អួច។ កម្មវិធី​ព្យាបាទ​អាច​ទៅ​យក​ព័ត៌មាន​ដែល​មាន​បំណង​សម្រាប់​ការ​ប្រើ​ប្រព័ន្ធ​ខាង​ក្នុង។"</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"ច្រោះ​ព្រឹត្តិការណ៍"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"ឲ្យ​កម្មវិធី​ចុះ​ឈ្មោះ​តម្រង​បញ្ចូល​​ដែល​ច្រោះ​​ព្រឹត្តិការណ៍​របស់​អ្នក​ប្រើ​ទាំងអស់​មុន​ពេល​ពួក​វា​ត្រូវ​បាន​ផ្ដាច់។ កម្មវិធី​ព្យាបាទ​អាច​ពិនិត្យ​ចំណុច​ប្រទាក់​ប្រព័ន្ធ​ដោយ​គ្មាន​អំពើ​ពី​អ្នក​ប្រើ។"</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"ពង្រីក​ការ​បង្ហាញ"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"ឲ្យ​កម្មវិធី​ពង្រីក​មាតិកា​នៃ​ការ​បង្ហាញ។ កម្មវិធី​ព្យាបាទ​អាច​ប្ដូរ​មាតិកា​ការ​បង្ហាញ​តាមវិធី​ដែល​បង្ហាញ​ថា​ឧបករណ៍​មិន​អាច​ប្រើ​បាន។"</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"បិទ​​ដោយ​ផ្នែក"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"ដាក់​កម្មវិធី​គ្រប់គ្រង​​សកម្មភាព​ក្នុង​ស្ថាន​ភាព​បិទ។ មិន​អនុវត្ត​ការ​បិទ​ពេញលេញ​ទេ។"</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"ការ​ពារ​​ការ​ប្ដូរ​កម្មវិធី"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"ការ​ពារ​អ្នក​ប្រើ​មិន​ឲ្យ​ប្ដូរ​​ទៅ​កម្មវិធី​ផ្សេង។"</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"យក​ព័ត៌មាន​កម្មវិធី​បច្ចុប្បន្ន"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"អនុញ្ញាត​ឱ្យ​ម្ចាស់ទៅ​យក​ព័​ត៌​មាន​ឯកជន​អំពី​កម្មវិធី​បច្ចុប្បន្ន ​និង​សេវាកម្ម​នៅ​ក្នុង​ផ្ទៃ​ខាងមុខ​របស់​អេក្រង់​។"</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"តាមដាន និង​ពិនិត្យ​ការ​ចាប់ផ្ដើម​កម្មវិធី"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"ឲ្យ​កម្មវិធី​តាមដាន និង​ពិនិត្យ​វិធី​ដែល​ប្រព័ន្ធ​ចាប់ផ្ដើម​​សកម្មភាព។ កម្មវិធី​ព្យាបាទ​អាច​​សម្របសម្រួល​ប្រព័ន្ធ​ទាំង​ស្រុង។ សិទ្ធិ​នេះ​ចាំបាច់​សម្រាប់​តែ​ការ​អភិវឌ្ឍ មិន​សម្រាប់​​ប្រើ​ធម្ម​តា​ទេ។"</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"ផ្ញើ​កញ្ចប់​​ការ​ប្រកាស​បាន​យកចេញ"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"ឲ្យ​កម្មវិធី​ប្រកាស​ការ​ជូន​ដំណឹង​ថា កញ្ចប់​កម្មវិធី​ត្រូវ​បាន​លុប​។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​​បញ្ឈប់​កម្មវិធី​ដែល​កំពុង​ដំណើរ​ការ​ផ្សេង​ៗ។"</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"ផ្ញើ​ការ​ប្រកាស​បាន​ទទួល SMS"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"ឲ្យ​កម្មវិធី​ប្រកាស​ការ​ជូន​ដំណឹង​​ការ​ទទួល​សារ​ SMS ។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​​ដើម្បី​​បន្លំ​សារ SMS ចូល។"</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"ផ្ញើ​ការ​ប្រកាស​បាន​ទទួល​ WAP-PUSH"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"ឲ្យ​កម្មវិធី​ប្រកាស​ការ​ជូន​ដំណឹង​ថា​បាន​ទទួល​សារ WAP PUSH ។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​ដើម្បី​​ក្លែង​​បង្កាន់ដៃ​សារ MMS ឬ​ជំនួស​មាតិកា​ទំព័រ​បណ្ដាញ​ណាមួយ​ស្ងាត់​ៗ​​​ដោយ​អ្វី​ដែល​ក្លែងក្លាយ។"</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"កំណត់​ចំនួន​ដំណើរការ​ដែល​កំពុង​ដំណើរការ"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"ឲ្យ​កម្មវិធី​ពិនិត្យ​ចំនួន​ដំណើរការ​អតិបរមា​ដែល​នឹង​ដំណើរការ។ មិន​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"បង្ខំ​​ឲ្យ​បិទ​កម្មវិធី​ក្នុង​ផ្ទៃ​ខាង​ក្រោយ"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"ឲ្យ​កម្មវិធី​ពិនិត្យ​ថា​តើ​សកម្មភាព​​ត្រូវ​បាន​បញ្ចប់​ជា​និច្ច​ដរាប​ណា​ពួកគេ​​ទៅ​ក្នុង​ផ្ទៃ​ខាង​ក្រោយ។ មិន​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"អាន​ស្ថិតិ​ថ្ម"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"ឲ្យ​កម្មវិធី​អាន​ទិន្នន័យ​ប្រើ​ថ្ម​កម្រិត​ទាប​បច្ចុប្បន្ន។ អាច​ឲ្យ​កម្មវិធី​ស្វែងយល់​ព័ត៌មាន​លម្អិត​អំពី​កម្មវិធី​ដែល​អ្នក​ប្រើ។"</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"កែ​ស្ថិតិ​ថ្ម"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"ឲ្យ​កម្មវិធី​កែ​ស្ថិតិ​ថ្ម​ដែល​បាន​ប្រមូល។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"ទៅ​យក​ស្ថិតិ​ប្រតិបត្តិការ​កម្មវិធី"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"ឲ្យ​កម្មវិធី​ទៅ​យក​ស្ថិតិ​ប្រតិបត្តិការ​កម្មវិធី​បាន​ប្រមូល។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា។"</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"កែ​ស្ថិតិ​ប្រតិបត្តិការ​​កម្មវិធី"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"ឲ្យ​កម្មវិធី​កែ​ស្ថិតិ​ប្រតិបត្តិការ​កម្មវិធី​បាន​ប្រមូល។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា។"</string>
-    <string name="permlab_backup" msgid="470013022865453920">"ពិនិត្យ​ការ​ស្ដារ និង​បម្រុង​ទុក​ប្រព័ន្ធ"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"ឲ្យ​កម្មវិធី​ពិនិត្យ​​យន្តការ​​បម្រុងទុក​ និង​ស្ដារ​ឡើងវិញ​របស់​ប្រព័ន្ធ។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"បញ្ជាក់​​ប្រតិបត្តិការ​ស្ដារ​ឡើងវិញ ឬ​បម្រុង​ទុក​ពេញលេញ"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"ឲ្យ​កម្មវិធី​ចាប់ផ្ដើម​ចំណុច​ប្រទាក់​​បញ្ជាក់​ការ​បម្រុង​ទុក​ពេញលេញ។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"បង្ហាញ​បង្អួច​គ្មាន​សិទ្ធិ"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"ឲ្យ​កម្មវិធី​បង្កើត​បង្អួច​​សម្រាប់​ប្រើ​ដោយ​ចំណុច​ប្រទាក់​អ្នកប្រើ​ប្រព័ន្ធ​ខាង​ក្នុង។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"គូរ​លើ​កម្មវិធី​ផ្សេង"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"ឲ្យ​​កម្មវិធី​គូរ​លើ​ផ្នែក​ខាង​លើ​នៃ​កម្មវិធី​ផ្សេងៗ ឬ​ជា​ផ្នែក​នៃ​ចំណុច​ប្រទាក់។ វា​អាច​រំខាន​ការ​ប្រើ​ចំណុច​ប្រទាក់​របស់​អ្នក​​ក្នុង​កម្មវិធី​ណាមួយ ឬ​ប្ដូរ​អ្វី​ដែល​អ្នក​គិត​ថា​អ្នក​កំពុង​មើល​ក្នុង​កម្មវិធី​ផ្សេងៗ។"</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"កែ​ល្បឿន​ចលនា​សកល"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"ឲ្យ​កម្មវិធី​ប្ដូរ​ល្បឿន​ចលនា​សកល (ចលនា​លឿន​ ឬ​យឺត) នៅ​ពេលណា​មួយ។"</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"គ្រប់គ្រង​និមិត្តសញ្ញា​កម្មវិធី"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"ឲ្យ​កម្មវិធី​បង្កើត និង​គ្រប់គ្រង​និមិត្តសញ្ញា​ផ្ទាល់​របស់​ពួក​វា ដោយ​ឆ្លង​កាត់​លំដាប់ Z ធម្មតា​របស់​វា។ មិន​គួរ​​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"បង្ក​ក​​អេក្រង់"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"ឲ្យ​កម្មវិធី​បង្កក​អេក្រង់​ជា​បណ្ដោះអាសន្ន​សម្រាប់​​ការ​​ផ្លាស់ប្ដូរ​ពេញ​អេក្រង់។"</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"ចុច​គ្រាប់ចុច និង​គ្រប់គ្រង​ប៊ូតុង"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"ឲ្យ​កម្មវិធី​ផ្ដល់​ព្រឹត្តិការណ៍​បញ្ចូល​ផ្ទាល់​ខ្លួន​(ចុច​គ្រាប់ចុច ។ល។) ទៅ​កម្មវិធី​ផ្សេង។​ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​ដើម្បី​គ្រប់គ្រង​កុំព្យូទ័រ​បន្ទះ។"</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"ឲ្យ​កម្មវិធី​ផ្ដល់​ព្រឹត្តិការណ៍​បញ្ចូល​ផ្ទាល់​ខ្លួន​របស់​វា (ចុច​គ្រាប់​ចុច ។ល។) ចំពោះ​កម្មវិធី​ផ្សេងៗ។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​ដើម្បី​គ្រប់គ្រង​ទូរស័ព្ទ។"</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"កត់ត្រា​នូវ​អ្វី​ដែល​អ្នក​វាយ​ និង​សកម្មភាព​ដែល​អ្នក​បាន​យក"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"ឲ្យ​កម្មវិធី​មើល​គ្រាប់​ចុច​ដែល​អ្នក​ចុច​ពេល​មាន​អន្តរកម្ម​ជា​មួយ​កម្មវិធី​ផ្សេង (ដូចជា បញ្ចូល​ពាក្យ​សម្ងាត់)។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"ចង​ទៅ​វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"ឲ្យ​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​វិធី​សាស្ត្រ​បញ្ចូល។ មិន​គួរ​​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"ចង​សេវា​កម្ម​ភាព​មធ្យោបាយ​ងាយស្រួល"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"ឲ្យ​​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​សេវាកម្ម​ភាព​ងាយស្រួល។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"ចង​សេវាកម្ម​​បោះពុម្ព"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"ឲ្យ​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​សេវាកម្ម​ធាតុ​ក្រាហ្វិក។ មិន​គួរ​​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"ចូល​ដំណើរការ​​ការងារ​បោះពុម្ព​ទាំងអស់"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"អនុញ្ញាត​ឲ្យ​ម្ចាស់​អាច​បោះពុម្ព​ការងារ​ដែល​បាន​បង្កើត​ដោយ​កម្មវិធី​ផ្សេង។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"ភ្ជាប់​ជាមួយ​សេវាកម្ម NFC"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"អនុញ្ញាត​ឲ្យ​​ភ្ជាប់​​​បញ្ជី​ជាមួយ​​កម្មវិធី​ដែល​ត្រូវ​បាន​ត្រាប់​តាម​​កាត NFC ។ មិន​គួរ​ត្រូវ​​ការ​សម្រាប់​កម្មវិធី​ធម្មតា​។"</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"ចង​សេវា​កម្ម​អត្ថបទ"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"ឲ្យ​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​សេវាកម្ម​អត្ថបទ (ឧ. SpellCheckerService) ។ មិន​គួរ​ប្រើ​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"ចង​ជា​មួយ​សេវាកម្ម VPN"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"ឲ្យ​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​សេវាកម្ម Vpn ។​ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"ចង​ទៅ​ផ្ទាំង​រូបភាព"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"ឲ្យ​ម្ចាស់​ចង​ចំណុចប្រទាក់​កម្រិត​កំពូល​នៃ​ផ្ទាំង​រូបភាព។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"ចង​សេវា​កម្ម​ធាតុ​ក្រាហ្វិក"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"ឲ្យ​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​សេវាកម្ម​ធាតុ​ក្រាហ្វិក។ មិន​គួរ​​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"ទាក់ទង​ជា​មួយ​អ្នកគ្រប់គ្រង​ឧបករណ៍"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"ឲ្យ​ម្ចាស់​ផ្ញើ​គោលបំណង​​ទៅ​អ្នក​គ្រប់គ្រង​ឧបករណ៍។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"បន្ថែម​ ឬ​លុប​កម្មវិធី​គ្រប់គ្រង​​​ឧបករណ៍"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"អនុញ្ញាត​​​ឲ្យ​ម្ចាស់​​​បន្ថែម​ ឬ​លុប​កម្មវិធី​គ្រប់គ្រង​ឧបករណ៍​សកម្ម​ចេញ​។ មិន​គួរ​ប្រើ​សម្រាប់​កម្មវិធី​​ធម្មតា​ទេ​។"</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"ប្ដូរ​ទិស​អេក្រង់"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"ឲ្យ​កម្មវិធី​ប្ដូរ​ការ​បង្វិល​អេក្រង់​នៅ​ពេល​ណា​មួយ។ មិន​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"ប្ដូរ​ល្បឿន​ទ្រនិច"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"ឲ្យ​កម្មវិធី​ប្ដូរ​ល្បឿន​ទ្រនិច​​កណ្ដុរ ឬ​បន្ទះ​ប៉ះ​​​នៅ​ពេល​ណា​មួយ។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"ប្ដូរ​ប្លង់​ក្ដារ​ចុច"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"ឲ្យ​កម្មវិធី​ប្ដូរ​ប្លង់​ក្ដារ​ចុច។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"ផ្ញើ​សញ្ញា​លីនុច​ទៅ​កម្មវិធី"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"ឲ្យ​កម្មវិធី​ស្នើ​​សញ្ញា​ដែល​បាន​ផ្ដល់​ត្រូវ​ផ្ញើ​ទៅ​ដំណើរការ​ស្ថិតស្ថេរ​​ទាំង​អស់។"</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"ធ្វើ​ឲ្យ​កម្មវិធី​ដំណើរការ​ជា​និច្ច"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"ឲ្យ​កម្មវិធី​ធ្វើជា​ផ្នែក​​ស្ថិតស្ថេរ​ដោយ​ខ្លួន​ឯង​ក្នុង​អង្គ​ចងចាំ។ វា​អាច​កំណត់​អង្គ​ចងចាំ​ដែល​អាច​ប្រើ​បាន​ចំពោះ​កម្មវិធី​ផ្សេងៗ​ ដោយ​ធ្វើឲ្យ​កុំព្យូទ័រ​បន្ទះ​យឺត។"</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"ឲ្យ​កម្មវិធី ធ្វើជា​ផ្នែក​អចិន្ត្រៃយ៍​នៃ​ខ្លួន​ក្នុង​អង្គ​ចងចាំ។ វា​អាច​កម្រិត​អង្គ​ចងចាំ​អាច​ប្រើ​បាន​ ដើម្បី​ធ្វើ​ឲ្យ​កម្មវិធី​ផ្សេង​ធ្វើ​ឲ្យ​ទូរស័ព្ទ​របស់​អ្នក​យឺត។"</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"លុប​កម្មវិធី"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"ឲ្យ​កម្មវិធី​លុប​កញ្ចប់ Android ។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​លុប​កម្មវិធី​សំខាន់​ៗ។"</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"លុប​ទិន្នន័យ​របស់​​កម្មវិធី​ផ្សេង"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"ឲ្យ​កម្មវិធី​សម្អាត​ទិន្នន័យ​អ្នក​ប្រើ។"</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"លុប​ឃ្លាំង​សម្ងាត់​កម្មវិធី​ផ្សេងៗ"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"ឲ្យ​កម្មវិធី​លុប​ឯកសារ​ឃ្លាំង​សម្ងាត់។"</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"វាស់​ទំហំ​ការ​ផ្ទុក​​កម្មវិធី"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"ឲ្យ​កម្មវិធី​ទៅ​យក​កូដ ទិន្នន័យ និង​ទំហំ​ឃ្លាំង​សម្ងាត់​របស់​វា"</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"ដំឡើង​កម្មវិធី​ដោយ​ផ្ទាល់"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"ឲ្យ​កម្មវិធី​ដំឡើង​កញ្ចប់​ Android ដែល​បាន​ធ្វើ​បច្ចុប្បន្ន ឬ​ថ្មី។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​បន្ថែម​កម្មវិធី​ដែល​មាន​សិទ្ធិ​ដោយ​បំពាន។"</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"លុប​ទិន្នន័យ​ឃ្លាំង​សម្ងាត់​កម្មវិធី​ទាំងអស់"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"ឲ្យ​កម្មវិធី​បង្កើន​ទំហំ​ផ្ទុក​កុំព្យូទ័រ​បន្ទះ ដោយ​លុប​ឯកសារ​ក្នុង​ថត​ឃ្លាំង​សម្ងាត់​នៃ​កម្មវិធី​ផ្សេង។ វា​អាច​ធ្វើ​ឲ្យ​កម្មវិធី​ផ្សេង​ចាប់ផ្ដើម​យឺត​ព្រោះថា​​ពួកវា​ត្រូវ​ទៅ​យក​ទិន្នន័យ​ឡើងវិញ។"</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"ឲ្យ​កម្មវិធី​បង្កើន​ទំហំ​ផ្ទុក​ទូរស័ព្ទ​ ដោយ​លុប​ឯកសារ​ក្នុង​ថត​ឃ្លាំង​សម្ងាត់​កម្មវិធី។ វា​អាច​ធ្វើ​ឲ្យ​កម្មវិធី​ផ្សេង​កាន់​តែ​យឺត ព្រោះ​ថា​ពួកវា​​ត្រូវ​ទៅ​យក​ទិន្នន័យ​របស់​ពួកវា។"</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"ផ្លាស់ទី​ធនធាន​កម្មវិធី"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"ឲ្យ​កម្មវិធី​ផ្លាស់ទី​ប្រភព​កម្មវិធី​ពី​មេឌៀ​ខាង​ក្នុង​ទៅ​ខាង​ក្រៅ​​ និង​ផ្ទុយ​មក​វិញ។"</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"អាន​ទិន្នន័យ​កំណត់​ហេតុ​ប្រែប្រួល"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"ឲ្យ​កម្មវិធី​អាន​ពី​ឯកសារ​កំណត់ហេតុ​ប្រព័ន្ធ។ វា​អនុញ្ញាត​ឲ្យ​រក​មើល​ព័ត៌មាន​ទូទៅ​អំពី​អ្វី​ដែល​អ្នក​កំពុង​ធ្វើជា​មួយ​កុំព្យូទ័រ​បន្ទះ សំខាន់​រួមមាន​ព័ត៌មាន​ផ្ទាល់​ខ្លួន​ ឬ​ឯកជន។"</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"ឲ្យ​កម្មវិធី​អាន​ពី​ឯកសារ​កំណត់ហេតុ​ប្រព័ន្ធ។ វា​អនុញ្ញាត​ឲ្យ​រក​មើល​ព័ត៌មាន​ទូទៅ​អំពី​អ្វី​ដែល​អ្នក​កំពុង​ធ្វើជា​មួយ​កុំព្យូទ័រ​បន្ទះ សំខាន់​រួមមាន​ព័ត៌មាន​ផ្ទាល់​ខ្លួន​ ឬ​ឯកជន។"</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"ប្រើ​កម្មវិធី​ឌិកូដ​​មេឌៀ​ណា​មួយ​សម្រាប់​ចាក់​ឡើងវិញ"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"ឲ្យ​កម្មវិធី​ប្រើ​កម្មវិធី​ឌិកូដ​មេឌៀ​ដែល​បាន​ដំឡើង ដើម្បី​ឌិកូដ​សម្រាប់​ការ​ចាក់​ឡើងវិញ។"</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"អាន/សរសេរ​ធនធាន​គ្រប់គ្រង​ប្រអប់"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"ឲ្យ​កម្មវិធី​អាន និង​សរសេរ​ប្រភព​ណាមួយ​ដែល​គ្រប់គ្រង​ដោយ​ក្រុម​អ្នក​វិនិច្ឆ័យ ឧទាហរណ៍ ឯកសារ​នៅ​ក្នុង /dev ។ វា​អាច​ប៉ះពាល់​យ៉ាង​ខ្លាំង​ដល់​ស្ថេរ​ភាព​ និង​សុវត្ថិភាព​ប្រព័ន្ធ។ វា​គួរ​ត្រូវ​បាន​ប្រើ​សម្រាប់​វិនិច្ឆ័យ​ផ្នែក​រឹង​ជាក់​លាក់​ដោយ​ក្រុមហ៊ុន​ផលិត ឬ​ប្រតិបត្តិ​ករ។"</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"បិទ ឬ​បើក​សមាសធាតុ​កម្មវិធី"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"ឲ្យ​កម្មវិធី​ប្ដូរ​ថា​តើ​សមាសធាតុ​កម្មវិធី​ផ្សេង​ត្រូវ​បាន​បើក​​ ឬ​ក៏​អត់។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​បិទ​សមត្ថភាព​ទូរស័ព្ទ​សំខាន់។ ប្រើ​ដោយ​ប្រុងប្រយ័ត្ន​ជា​មួយ​​សិទ្ធិ​នេះ ព្រោះ​ថា​វា​អាច​ធ្វើ​ឲ្យ​សមាសធាតុ​មិន​អាច​ប្រើ​បាន​ ស្ថិតស្ថេរ ឬ​​មិន​ស្ថិតស្ថេរ។"</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"ឲ្យ​កម្មវិធី​ប្ដូរ​ថាតើ​សមាសធាតុ​កម្មវិធី​ផ្សេង​ត្រូវ​បាន​បើក​​ ឬ​ក៏​អត់។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​បិទ​សមត្ថភាព​ទូរស័ព្ទ​សំខាន់។ ប្រើ​ដោយ​ប្រុងប្រយ័ត្ន​ជា​មួយ​​សិទ្ធិ​នេះ ព្រោះ​ថា​វា​អាច​ធ្វើ​ឲ្យ​សមាសធាតុ​មិន​អាច​ប្រើ​បាន​ ស្ថិតស្ថេរ ឬ​​មិន​ស្ថិតស្ថេរ។"</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"ផ្ដល់ ឬ​ដក​សិទ្ធិ"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"ឲ្យ​កម្មវិធី​ផ្ដល់ ឬ​ដក​សិទ្ធិ​ជាក់លាក់​សម្រាប់​វា ឬ​កម្មវិធី​ផ្សេង។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​ដើម្បី​ចូល​លក្ខណៈ​ដែល​អ្នក​មិន​បាន​ផ្ដល់​ឲ្យ​ពួកវា។"</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"កំណត់​កម្មវិធី​ពេញ​ចិត្ត"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"ឲ្យ​កម្មវិធី​កែ​កម្មវិធី​ដែល​អ្នក​ពេញ​ចិត្ត។ កម្មវិធី​ព្យាបាទ​អាច​ប្ដូរ​កម្មវិធី​ដែល​ដំណើរការ​ស្ងាត់​ៗ ដោយ​​​បញ្ឆោត​កម្មវិធី​ដែល​មាន​ស្រាប់​​របស់​អ្នក​ ដើម្បី​ប្រមូល​ទិន្នន័យ​ឯកជន​​ពី​អ្នក។"</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"កែ​​ការ​កំណត់​ប្រព័ន្ធ"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"ឲ្យ​កម្មវិធី​កែ​ទិន្នន័យ​កំណត់​ប្រព័ន្ធ។ កម្មវិធី​ព្យាបាទ​អាច​បង្ខូច​ការ​កំណត់​រចនាសម័្ពន្ធ​នៃ​ប្រព័ន្ធ​របស់​អ្នក។"</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"កែ​ការ​កំណត់​ប្រព័ន្ធ​សុវត្ថិភាព"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"ឲ្យ​កម្មវិធី​កែ​ទិន្នន័យ​កំណត់​​សុវត្ថិភាព​​របស់​ប្រព័ន្ធ។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"កែ​ផែនទី​សេវាកម្ម​ Google"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"ឲ្យ​កម្មវិធី​កែ​ផែនទី​សេវាកម្ម​ Google ។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"ដំណើរការ​ពេល​ចាប់ផ្ដើម"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"ឲ្យ​កម្មវិធី​ចាប់ផ្ដើម​ដោយ​ខ្លួន​វា​ផ្ទាល់​ដរាប​​ណា​ប្រព័ន្ធ​​បាន​ចាប់ផ្ដើម​​រួចរាល់។ វា​អាច​​ចំណាយ​ពេល​យូរ​ដើម្បី​ចាប់ផ្ដើម​កុំព្យូទ័រ​បន្ទះ និង​ឲ្យ​កម្មវិធី​ធ្វើ​ឲ្យ​កុំព្យូទ័រ​បន្ទះ​យឺត​ដោយ​ដំណើរការ​ជា​និច្ច។"</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"ឲ្យ​​កម្មវិធី​​ចាប់ផ្ដើម​ដោយ​ខ្លួន​វា​​ភ្លាម​ៗ​ពេល​ប្រព័ន្ធ​​ចាប់ផ្ដើម​ចប់។ ​វា​អាច​ធ្វើ​ឲ្យ​ចំណាយ​ពេល​យូរ​ដើម្បី​ចាប់ផ្ដើម​ទូរស័ព្ទ ​និង​ឲ្យ​កម្មវិធី​ធ្វើ​ឲ្យ​ទូរស័ព្ទ​យឺត​ដោយ​ដំណើរការ​ជា​និច្ច។"</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"ផ្ញើ​ការ​ប្រកាស​ទាក់ទាញ"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"ឲ្យ​កម្មវិធី​ផ្ញើ​ការប្រកាស​​ដែល​ទាក់ទាញ ដែល​មាន​បន្ទាប់​ពី​ការ​ប្រកាស​ចប់។ ការ​ប្រើ​លើស​​អាច​ធ្វើឲ្យ​ទូរស័ព្ទ​យឺត ឬ​មិន​ស្ថិតស្ថេរ​ដោយធ្វើ​ឲ្យ​វា​ប្រើ​អង្គ​ចងចាំ​ធំ​ពេក។"</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"ឲ្យ​កម្មវិធី​ផ្ញើ​ការប្រកាស​​ដែល​ទាក់ទាញ ដែល​មាន​បន្ទាប់​ពី​ការ​ប្រកាស​ចប់។ ការ​ប្រើ​លើស​​អាច​ធ្វើឲ្យ​ទូរស័ព្ទ​យឺត ឬ​មិន​ស្ថិតស្ថេរ​ដោយធ្វើ​ឲ្យ​វា​ប្រើ​អង្គ​ចងចាំ​ធំ​ពេក។"</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"អាន​ទំនាក់ទំនង​របស់​អ្នក"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"ឲ្យ​កម្មវិធី​អាន​ទិន្នន័យ​អំពី​ទំនាក់ទំនង​របស់​អ្នក​ដែល​មាន​ក្នុង​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក រួមមាន​ប្រេកង់​ដែល​អ្នក​បាន​ហៅ​ អ៊ីមែល ឬ​ទាក់ទង​តាម​វិធី​ផ្សេងៗ​ជា​មួយ​មនុស្ស​ណា​ម្នាក់។ សិទ្ធិ​នេះ​អនុញ្ញាត​ឲ្យ​កម្មវិធី​រក្សាទុក​ទិន្នន័យ​ទំនាក់ទំនង​របស់​អ្នក ហើយ​កម្មវិធី​ព្យាបាទ​អាច​ចែករំលែក​ទិន្នន័យ​ទំនាក់ទំនង​ដោយ​មិន​ឲ្យ​អ្នក​ដឹង។"</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"ឲ្យ​​កម្មវិធី​អាន​ទិន្នន័យ​អំពី​ទំនាក់ទំនង​របស់​អ្នក​ដែល​បាន​រក្សាទុក​ក្នុង​ទូរស័ព្ទ រួមមាន​ប្រេកង់​ដែល​អ្នក​បាន​ហៅ អ៊ីមែល ឬ​ទាក់ទង​តាម​វិធី​ផ្សេងៗ​ជា​មួយ​​អ្នក​ណា​ម្នាក់។ សិទ្ធិ​នេះ​ឲ្យ​កម្មវិធី​រក្សាទុក​ទិន្នន័យ​ទំនាក់ទំនង​របស់​អ្នក ហើយ​កម្មវិធី​ព្យាបាទ​អាច​ចែករំលែក​ទិន្នន័យ​ទំនាក់ទំនង​​ដោយ​មិន​ឲ្យ​អ្នកដឹង។"</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"កែ​ទំនាក់ទំនង​របស់​អ្នក"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"ឲ្យ​កម្មវិធី​កែ​ទិន្នន័យ​អំពី​ទំនាក់ទំនង​របស់​អ្នក​ដែល​បាន​រក្សាទុក​ក្នុង​កុំព្យូទ័រ​បន្ទះ រួមមាន​ប្រេកង់​​ដែល​អ្នក​បាន​ហៅ អ៊ីមែល ឬ​ទាក់ទង​តាម​វិធី​ផ្សេងៗ​ជា​មួយ​ទំនាក់ទំនង​ជាក់លាក់។ សិទ្ធិ​​នេះ​អនុញ្ញាត​ឲ្យ​​​កម្មវិធី​លុប​ទិន្នន័យ​ទំនាក់ទំនង​របស់​អ្នក។"</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"ឲ្យ​កម្មវិធី​កែ​ទិន្នន័យ​អំពី​ទំនាក់ទំនង​របស់​អ្នក​ដែល​បាន​រក្សាទុក​ក្នុង​ទូរស័ព្ទ​របស់​អ្នក រួមមាន​ប្រេកង់​ដែល​អ្នក​បាន​ហៅ អ៊ីមែល ឬ​បាន​ទាក់ទង​​តាម​វិធី​ផ្សេងៗ​ជា​មួយ​ទំនាក់​ទំនាក់​ជាក់លាក់។ សិទ្ធិ​នេះ​ឲ្យ​កម្មវិធី​លុប​ទិន្នន័យ​ទំនាក់ទំនង។"</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"អាន​​កំណត់​ហេតុ​​​ហៅ"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"ឲ្យ​កម្មវិធី​អាន​បញ្ជី​ហៅ​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក រួមមាន​ទិន្នន័យ​អំពី​ការ​ហៅ​ចូល និង​ចេញ។ សិទ្ធិ​នេះ​អនុញ្ញាត​ឲ្យ​កម្មវិធី​រក្សាទុក​ទិន្នន័យ​បញ្ជី​ហៅ​របស់​អ្នក ហើយ​កម្មវិធី​ព្យាបាទ​អាច​ចែករំលែក​ទិន្នន័យ​បញ្ជី​ហៅ​ដោយ​មិន​ឲ្យ​អ្នក​ដឹង។"</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"ឲ្យ​កម្មវិធី​អាន​​​បញ្ជី​ហៅ​ទូរស័ព្ទ​របស់​អ្នក រួមមាន​ទិន្នន័យ​អំពី​ការ​ហៅ​ចូល និង​ចេញ។ សិទ្ធិ​នេះ​អនុញ្ញាត​ឲ្យ​កម្មវិធី​រក្សាទុក​ទិន្នន័យ​បញ្ជី​ហៅ​របស់​អ្នក ហើយ​កម្មវិធី​ព្យាបាទ​អាច​ចែករំលែក​ទិន្នន័យ​បញ្ជី​ហៅ​ដោយ​មិន​ឲ្យ​អ្នកដឹង។"</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"សរសេរ​បញ្ជី​ហៅ"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"ឲ្យ​កម្មវិធី​កែ​បញ្ជី​ហៅ​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក​រួមមាន​ទិន្នន័យ​អំពី​ការ​ហៅ​ចូល និង​ចេញ។​កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​លុប ឬ​កែ​បញ្ជី​ហៅ​របស់​អ្នក។"</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"ឲ្យ​កម្មវិធី​កែ​បញ្ជី​ហៅ​នៃ​ទូរស័ព្ទ​របស់​អ្នក រួមមាន​ទិន្នន័យ​អំពី​ការ​ហៅ​ចូល និង​ចេញ។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​លុប ឬ​កែ​បញ្ជី​ការ​ហៅ​របស់​អ្នក។"</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"អាន​កាត​ទំនាក់ទំនង​ផ្ទាល់ខ្លួន​​របស់​អ្នក"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"ឲ្យ​កម្មវិធី​អាន​ព័ត៌មាន​ប្រវត្តិរូប​ផ្ទាល់ខ្លួន​ដែល​មាន​លើ​ឧបករណ៍​របស់​អ្នក ដូច​ជា ឈ្មោះ និង​ព័ត៌មាន​ទំនាក់ទំនង។ វា​មាន​ន័យ​ថា កម្មវិធី​អាច​កំណត់​អ្នក និង​អាច​ផ្ញើ​ព័ត៌មាន​ប្រវត្តិរូប​របស់​អ្នក​ទៅ​អ្នក​ផ្សេង។"</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"កែ​កាត​ទំនាក់ទំនង​ផ្ទាល់​ខ្លួន​របស់​អ្នក"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"ឲ្យ​កម្មវិធី​ប្ដូរ ឬ​បន្ថែម​ព័ត៌មាន​ប្រវត្តិរូប​ផ្ទាល់​ខ្លួន​ដែល​បាន​រក្សាទុក​ក្នុង​ឧបករណ៍​របស់​អ្នក ដូចជា ឈ្មោះ និង​ព័ត៌មាន​ទំនាក់ទំនង​របស់​អ្នក។ នេះ​មាន​ន័យ​ថា​កម្មវិធី​អាច​កំណត់​អ្នក និង​ផ្ញើ​ព័ត៌មាន​ប្រវត្តិរូប​របស់​អ្នក​ទៅ​អ្នក​ផ្សេង។"</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"អាន​ចរន្ត​​សង្គម​របស់​អ្នក"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"ឲ្យ​កម្មវិធី​ចូល​ដំណើរការ និង​ធ្វើ​សម​កាល​កម្ម​បច្ចុប្បន្នភាព​សង្គម​ពី​អ្នក​ និង​មិត្តភ័ក្ដិ។ ប្រយ័ត្ន​ពេល​ចែករំលែក​ព័ត៌មាន វា​អនុញ្ញាត​ឲ្យ​កម្មវិធី​អាន​ការ​ទាក់ទង​រវាង​អ្នក​ និង​មិត្តភ័ក្ដិ​លើ​បណ្ដាញ​សង្គម ទាក់ទង​នឹង​ព័ត៌មាន​សម្ងាត់។ ចំណាំ៖​ សិទ្ធិ​នេះ​មិន​អាច​ត្រូវ​បាន​​អនុវត្ត​លើ​បណ្ដាញ​សង្គម​ទាំង​អស់​បាន​ទេ។"</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"សរសេរ​ទៅ​ចរន្ត​សង្គម​របស់​អ្នក"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"ឲ្យ​កម្មវិធី​បង្ហាញ​បច្ចុប្បន្នភាព​សង្គម​ពី​មិត្តភ័ក្ដិ​របស់​អ្នក។ ប្រយ័ត្ន​ពេល​ចែករំលែក​ព័ត៌មាន វា​ឲ្យ​កម្មវិធី​បង្កើត​​​សារ​​ដែល​អាច​បង្ហាញ​ថា​មក​ពី​មិត្តភ័ក្ដិ។ ចំណាំ៖ សិទ្ធិ​នេះ​មិន​អាច​ប្រើ​លើ​បណ្ដាញ​សង្គម​បាន​ទេ។"</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"អាន​ព្រឹត្តិការណ៍​ប្រតិទិន​​និង​ព័ត៌មាន​សម្ងាត់"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"ឲ្យ​កម្មវិធី​អាច​​ព្រឹត្តិការណ៍​ប្រតិទិន​ទាំងអស់​ដែល​បាន​រក្សាទុក​ក្នុង​ទូរស័ព្ទ​របស់​អ្នក  រួមមាន​មិត្តភ័ក្ដិ និង​មិត្ត​រួម​ការងារ។ វា​អាច​ឲ្យ​កម្មវិធី​ចែករំលែក​ ឬ​រក្សាទុក​ទិន្នន័យ​ប្រតិទិន​របស់​អ្នក​​ដោយ​មិន​គិត​ពី​ការ​សម្ងាត់ ឬ​ការ​យល់​ដឹង។"</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"ឲ្យ​កម្មវិធី​អាន​ព្រឹត្តិការណ៍​ប្រតិទិន​ទាំងអស់​ដែល​មាន​ក្នុង​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក រួមមាន​មិត្តភ័ក្ដិ ឬ​មិត្ត​រួម​ការងារ។ វា​អាច​អនុញ្ញាត​ឲ្យ​យ​កម្ម​វិធី​ចែករំលែក ឬ​រក្សាទុក​ទិន្នន័យ​ប្រតិទិន​របស់​អ្នក​ដែល​ទាក់ទង​នឹង​ព័ត៌មាន​សម្ងាត់ ឬ​​ការ​ប្រែប្រួល។"</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"បន្ថែម ឬ​កែ​ព្រឹត្តិការណ៍​ប្រតិទិន​ និង​ផ្ញើ​អ៊ីមែល​ទៅ​ភ្ញៀវ​ដោយ​មិន​ឲ្យ​ម្ចាស់​ដឹង"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"ឲ្យ​កម្មវិធី​បន្ថែម លុប ឬ​ប្ដូរ​ព្រឹត្តិការណ៍​ដែល​អ្នក​អាច​កែ​លើ​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក រួមមាន​មិត្តភ័ក្ដិ ឬ​មិត្ត​រួម​ការងារ។ វា​អាច​ឲ្យ​កម្មវិធី​ផ្ញើ​សារ​ដែល​បង្ហាញ​ថា​មក​ពី​ម្ចាស់​ប្រតិទិន​ ឬ​កែ​ព្រឹត្តិការណ៍​ដោយ​មិន​ឲ្យ​ម្ចាស់​ដឹង។"</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"ឲ្យ​កម្មវិធី​បន្ថែម លុប ឬ​ប្ដូរ​ព្រឹត្តិការណ៍​ដែល​អ្នក​អាច​កែប្រែ​លើ​ទូរស័ព្ទ​របស់​អ្នក រួមមាន​មិត្តភ័ក្ដិ ឬ​មិត្ត​រួម​ការងារ។ វា​​អាច​ឲ្យ​កម្មវិធី​ផ្ញើ​សារ​ដែល​បង្ហាញ​ថា​មក​ពី​ម្ចាស់​ប្រតិទិន ឬ​កែ​ព្រឹត្តិការណ៍​ដោយ​មិន​ឲ្យ​​អ្នក​ដឹង។"</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"ក្លែង​ប្រភព​ទីតាំង​សម្រាប់​សាកល្បង"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"បង្កើត​ប្រភព​ទីតាំង​ក្លែង​ក្លាយ​សម្រាប់​សាកល្បង ឬ​ដំឡើង​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង​ថ្មី។ វា​អនុញ្ញាត​ឲ្យ​កម្មវិធី​បដិសេធ​ទីតាំង​​ និង/ឬ​ស្ថានភាព​បាន​ត្រឡប់​ដោយ​ប្រភព​ទីតាំង​ផ្សេង​ដូច​ជា GPS ឬ​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង។"</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"ចូល​ដំណើរការ​ពាក្យ​បញ្ជា​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"ឲ្យ​កម្មវិធី​ចូល​ពាក្យ​បញ្ជា​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង​បន្ថែម។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​ដើម្បី​ជ្រៀតជ្រែក​ជា​មួយ​ប្រតិបត្តិការ​ GPS ឬ​ប្រភព​ទីតាំង​ផ្សេង​ទៀត។"</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"សិទ្ធិ ដើម្បី​ដំឡើង​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"បង្កើត​ប្រភព​ទីតាំង​ក្លែងក្លាយ​សម្រាប់​សាកល្បង ឬ​ដំឡើង​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង​ថ្មី។ វា​អនុញ្ញាត​ឲ្យ​កម្មវិធី​បដិសេធ​ទីតាំង​ និង/ឬ​ស្ថានភាព​បាន​ត្រឡប់​ដោយ​ប្រភព​ទីតាំង​ផ្សេងៗ​ដូចជា GPS ឬ​ក្រុមហ៊ុន​ផ្ដល់​ទីតាំង។"</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"ទីតាំង​ពិតប្រាកដ (GPS និង​មាន​មូលដ្ឋាន​លើ​បណ្ដាញ)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"ឲ្យ​កម្មវិធី​ទទួល​ទីតាំង​ពិតប្រាកដ​របស់​អ្នក ដោយ​ប្រើ​ប្រព័ន្ធ​កំណត់​ទីតាំង​សកម្ម (GPS) ឬ​ប្រភព​ទីតាំង​បណ្ដាញ​ដូច​ជា អង់តែន​ចល័ត និង​វ៉ាយហ្វាយ។ សេវាកម្ម​ទីតាំង​ទាំង​នេះ​ត្រូវតែ​បើក និង​អាច​ប្រើ​ចំពោះ​ឧបករណ៍​របស់​អ្នក​សម្រាប់​កម្មវិធី​ដែល​ប្រើ​ពួក​វា។ កម្មវិធី​អាច​ប្រើ​វា ដើម្បី​កំណត់​​ទីកន្លែង​របស់​អ្នក និង​អាច​ប្រើ​ថាមពល​ថ្ម​បន្ថែម។"</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"ទីតាំង​ប្រហាក់ប្រហែល (​​មាន​មូលដ្ឋាន​លើ​បណ្ដាញ)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"ឲ្យ​កម្មវិធី​ទទួល​ទីតាំង​ប្រហាក់ប្រហែល។ ទីតាំង​នេះ​ត្រូវ​បាន​ទទួល​តាម​សេវាកម្ម​ទីតាំង​ដោយ​ប្រើ​ប្រភព​ទីតាំង​បណ្ដាញ​ដូច​ជា អង់តែន និង​វ៉ាយហ្វាយ។ សេវាកម្ម​ទីតាំង​ទាំង​នេះ​ត្រូវ​តែ​បើក និង​អាច​ប្រើ​បាន​ចំពោះ​ឧបករណ៍​របស់​អ្នក​សម្រាប់​កម្មវិធី​ដែល​ប្រើ​ពួកវា។ កម្មវិធី​អាច​ប្រើ​វា ដើម្បី​កំណត់កន្លែង​ដែល​អ្នក​នៅ​ប្រហាក់ប្រហែល។"</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"ចូល​ដំណើរការ​ SurfaceFlinger"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"ឲ្យ​កម្មវិធី​ប្រើ​លក្ខណៈ​កម្រិត​ទាប​របស់ SurfaceFlinger ។"</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"អាន​អង្គ​ចងចាំ​បណ្ដោះ​អាសន្ន"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"ឲ្យ​កម្មវិធី​អាន​មាតិកា​នៃ​អង្គ​ចងចាំ​បណ្ដោះ​អាសន្ន។"</string>
-    <string name="permlab_accessInputFlinger" msgid="5348635270689553857">"ចូល​ដំណើរការ InputFlinger"</string>
-    <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"ឲ្យ​កម្មវិធី​ប្រើ​លក្ខណៈ​កម្រិត​ទាប InputFlinger ។"</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"កំណត់​រចនាសម្ព័ន្ធ​ការ​បង្ហាញ​វ៉ាយហ្វាយ"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"ឲ្យ​កម្មវិធី​កំណត់​រចនាសម្ព័ន្ធ​ និង​ភ្ជាប់​ទៅ​ការ​បង្ហាញ​វ៉ាយហ្វាយ។"</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"ពិនិត្យ​ការ​បង្ហាញ​វ៉ាយហ្វាយ"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"ឲ្យ​កម្មវិធី​ពិនិត្យ​លក្ខណៈ​កម្រិត​ទាប​​នៃ​ការ​បង្ហាញ​វ៉ាយហ្វាយ។"</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"ចាប់​យក​លទ្ធផល​អូឌីយ៉ូ"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"​ឱ្យ​កម្មវិធី​ដើម្បី​ចាប់​យក​ និង​​ប្ដូរ​​ទិស​លទ្ធផល​អូឌីយ៉ូ​។"</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"ចាប់​យក​លទ្ធផល​វីដេអូ"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"ឲ្យ​កម្មវិធី​ចាប់​យក​ និង​ប្ដូរ​​ទិស​លទ្ធផល​វីដេអូ​។"</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"ចាប់​យក​លទ្ធផល​វីដេអូ​សុវត្ថិភាព"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"ឲ្យ​​កម្មវិធី​​​ចាប់​យក ​និង​ប្ដូរ​ទិស​លទ្ធផល​វីដេអូ​ដែល​មាន​សុវត្ថិភាព​។"</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"ប្ដូរ​ការ​កំណត់​អូឌីយូ​របស់​អ្នក"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"ឲ្យ​កម្មវិធី​កែ​ការ​កំណត់​សំឡេង​សកល ដូច​ជា​កម្រិត​សំឡេង និង​អូប៉ាល័រ​ដែល​បាន​ប្រើ​សម្រាប់​លទ្ធផល។"</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"ថត​សំឡេង"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"​ឱ្យ​កម្មវិធី​ថត​សំឡេង​​ជាមួយ​មីក្រូហ្វូន​​​។ សិទ្ធិ​នេះ​អនុញ្ញាត​ឲ្យ​កម្មវិធី​ថត​សំឡេង​​នៅ​ពេល​ណា​មួយ​ដោយ​គ្មាន​ការ​បញ្ជាក់​របស់​អ្នក។"</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"ថត​រូប និងវីដេអូ"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"ឲ្យ​កម្មវិធី​ថត​រូប និង​វីដេអូ​ដោយ​ប្រើ​ម៉ាស៊ីន​ថត។ វា​ឲ្យ​កម្មវិធី​​ប្រើ​ម៉ាស៊ីន​ថត​នៅ​ពេល​​ណាមួយ​ដោយ​គ្មាន​ការ​បញ្ជាក់​របស់​អ្នក។"</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"បិទ​​ពន្លឺ​បង្ហាញ​ការ​បញ្ជូន​​ពេល​ម៉ាស៊ីន​ថត​កំពុង​ប្រើ"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"ឲ្យ​កម្មវិធី​ប្រព័ន្ធ​ដែល​បាន​ដំឡើង​រួច​បិទ​​ LED បង្ហាញ​ការ​ប្រើ​ម៉ាស៊ីន​ថត។"</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"បិទ​កុំព្យូទ័រ​បន្ទះ​ជា​អចិន្ត្រៃយ៍"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"បិទ​ទូរស័ព្ទ​ជា​អចិន្ត្រៃយ៍"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"ឲ្យ​កម្មវិធី​បិទ​កុំព្យូទ័រ​បន្ទះ​​​ជា​អចិន្ត្រៃយ៍។ វា​មាន​គ្រោះថ្នាក់​ណាស់។"</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"ឲ្យ​កម្មវិធី​បិទ​ទូរស័ព្ទ​ទាំង​មូល​​ជា​អចិន្ត្រៃយ៍។ វា​មាន​គ្រោះ​ថ្នាក់​ណាស់។"</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"បង្ខំ​ឲ្យ​ចាប់ផ្ដើម​កុំព្យូទ័រ​បន្ទះ​ឡើង​វិញ"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"បង្ខំ​ឲ្យ​ទូរស័ព្ទ​ចាប់ផ្ដើម​ឡើងវិញ"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"ឲ្យ​កម្មវិធី​បង្ខំ​ឲ្យ​​កុំព្យូទ័រ​បន្ទះ​ចាប់ផ្ដើម​ឡើងវិញ។"</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"ឲ្យ​កម្មវិធី​បង្ខំ​​ឲ្យ​ទូរស័ព្ទ​ចាប់ផ្ដើម​ឡើងវិញ។"</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"ការ​ចូល​ដំណើរការ​ប្រព័ន្ធ​ឯកសារ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"ការ​ចូល​ដំណើរការ​ប្រព័ន្ធ​ឯកសារ​កាត​អេសឌី"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"ឲ្យ​កម្មវិធី​ភ្ជាប់ និង​ផ្ដាច់​ប្រព័ន្ធ​ឯកសារ​សម្រាប់​ឧបករណ៍​ផ្ទុក​ចល័ត។"</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"លុប​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"លុប​កាត​អេសឌី"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"ឲ្យ​កម្មវិធី​ធ្វើ​ទ្រង់ទ្រាយ​ឧបករណ៍​ផ្ទុក​ចល័ត។"</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"យក​​ព័ត៌មាន​នៅ​លើ​ឧបករណ៍​​ផ្ទុក​ខាងក្នុង"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"ឲ្យ​កម្មវិធី​យក​ព័ត៌មាន​លើ​ការ​​ផ្ទុក​ខាង​ក្នុង។"</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"បង្កើត​​ឧបករណ៍​ផ្ទុក​ខាងក្នុង"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"ឲ្យ​កម្មវិធី​បង្កើត​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង។"</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"បំផ្លាញ​​ឧបករណ៍​​ផ្ទុក​ខាងក្នុង"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"ឲ្យ​កម្មវិធី​បំផ្លាញ​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង។"</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"ភ្ជាប់/ផ្ដាច់​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"ឲ្យ​កម្មវិធី​ភ្ជាប់/ផ្ដាច់​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង។"</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"ប្ដូរ​ឈ្មោះ​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"ឲ្យ​កម្មវិធី​ប្ដូរ​ឈ្មោះ​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង។"</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_manageUsb" msgid="1113453430645402723">"គ្រប់គ្រង​ចំណូល​ចិត្ត និង​សិទ្ធិ​សម្រាប់​ឧបករណ៍​យូអេសប៊ី"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"ឲ្យ​កម្មវិធី​គ្រប់គ្រង​ចំណូល​ចិត្ត និង​សិទ្ធិ​ឧបករណ៍​យូអេសប៊ី។"</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"អនុវត្ត​ពិធីការ MTP"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"ចូល​ដំណើរការ​កម្មវិធី​បញ្ជា kernel MTP ដើម្បី​អនុវត្ត​ពិធីការ​យូអេសប៊ី MTP ។"</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"សាកល្បង​ផ្នែក​រឹង"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"ឲ្យ​កម្មវិធី​ពិនិត្យ​គ្រឿង​ផ្សេងៗ​​សម្រាប់​សាកល្បង​ផ្នែក​រឹង។"</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"ហៅ​លេខ​ទូរស័ព្ទ​ដោយ​ផ្ទាល់"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"ឲ្យ​កម្មវិធី​ហៅ​លេខ​ទូរស័ព្ទ​ដោយ​គ្មាន​សកម្មភាព​របស់​អ្នក។​ វា​អាច​កាត់​លុយ​ ឬ​ហៅ​ដោយ​មិន​រំពឹង​ទុក។ ចំណាំ​ថា​ វា​មិន​អនុញ្ញាត​ឲ្យ​កម្មវិធី​ហៅ​លេខ​ពេល​អាសន្ន​ទេ។ កម្មវិធី​ព្យាបាទ​អាច​កាត់​លុយ​របស់​អ្នក​ ដោយ​ធ្វើការ​ហៅ​ដោយ​គ្មាន​ការ​បញ្ជាក់​របស់​អ្នក។"</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"ហៅ​លេខ​ទូរស័ព្ទ​ណាមួយ​ដោយ​ផ្ទាល់"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"ឲ្យ​កម្មវិធី​ហៅ​លេខ​ទូរស័ព្ទ រួមមាន​លេខ​ពេល​អាសន្ន​ដោយ​គ្មាន​​អំពើ​របស់​អ្នក។ កម្មវិធី​ព្យាបាទ​អាច​ដាក់​ការ​ហៅ​មិន​ត្រឹមត្រូវ និង​ចាំបាច់​ទៅ​សេវាកម្ម​ពេល​អាសន្ន។"</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"ចាប់ផ្ដើម​រៀបចំ​កុំព្យូទ័រ​បន្ទះ CDMA ដោយ​ផ្ទាល់"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"ចាប់ផ្ដើម​រៀបចំ​កុំព្យូទ័រ​បន្ទះ CDMA ដោយ​ផ្ទាល់"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"ឲ្យ​កម្មវិធី​ចាប់ផ្ដើម​ការ​ផ្ដល់ CDMA ។ កម្មវិធី​ព្យាបាទ​អាច​មិន​ចាំបាច់​ចាប់ផ្ដើម​ការ​ផ្ដល់ CDMA ។"</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"ពិនិត្យ​​ការ​ជូន​ដំណឹង​បច្ចុប្បន្ន​ភាព​ទីតាំង"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"ឲ្យ​កម្មវិធី​បិទ/បើក​ការ​ជូន​ដំណឹង​បច្ចុប្បន្នភាព​ទីតាំង​ពី​វិទ្យុ។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។។"</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"ចូល​ដំណើរការ​លក្ខណៈ​សម្បត្តិ​ពិនិត្យ​មើល"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"ឲ្យ​កម្មវិធី​អាន/សរសេរ​លក្ខណសម្បត្តិ​បាន​ផ្ទុក​ឡើង​ដោយ​សេវាកម្ម​ពិនិត្យ​មើល។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា។"</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"ជ្រើស​​ធាតុ​ក្រាហ្វិក"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"ឲ្យ​កម្មវិធី​ប្រាប់​ប្រព័ន្ធ​ថា​ធាតុ​ក្រាហ្វិក​ណាមួយ​​អាច​ត្រូវ​បាន​ប្រើ​ដោយ​​កម្មវិធី​ណា​មួយ។​កម្មវិធី​ដែល​មាន​សិទ្ធិ​នេះ​អាច​ឲ្យ​កម្មវិធី​ផ្សេង​ចូល​ដំណើរការ​ទិន្នន័យ​ផ្ទាល់ខ្លួន។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា។"</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"កែ​ស្ថានភាព​ទូរស័ព្ទ"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"ឲ្យ​កម្មវិធី​ពិនិត្យ​លក្ខណៈ​ទូរស័ព្ទ​នៃ​ឧបករណ៍។ កម្មវិធី​ដែល​មាន​សិទ្ធិ​នេះ​អាច​ប្ដូរ​បណ្ដាញ បិទ និង​បើកវិទ្យុ​ក្នុង​ទូរស័ព្ទ​ដោយ​មិន​ជូន​ដំណឹង​អ្នក។"</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"អាន​ស្ថានភាព និង​អត្តសញ្ញាណ​ទូរស័ព្ទ"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"ឲ្យ​កម្មវិធី​ចូល​ដំណើរការ​លក្ខណៈ​ទូរស័ព្ទ​នៃ​ឧបករណ៍។ សិទ្ធិ​នេះ​​ឲ្យ​កម្មវិធី​កំណត់​លេខ​ទូរស័ព្ទ និង​លេខ​សម្គាល់​ឧបករណ៍ ថា​តើ​ការ​ហៅ​សកម្ម និង​លេខ​ពី​ចម្ងាយ​បាន​ភ្ជាប់​ដោយ​ការ​ហៅ។"</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"ការពារ​​កុំព្យូទ័រ​បន្ទះ​មិន​ឲ្យ​ដេក"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"ការ​ពារ​ទូរស័ព្ទ​មិន​ឲ្យ​ដេក"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"ឲ្យ​​កម្មវិធី​ការពារ​កុំព្យូទ័រ​បន្ទះ​មិន​ឲ្យ​ដេក។"</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"ឲ្យ​កម្មវិធី​ការពារ​ទូរស័ព្ទ​មិន​ឲ្យ​ដេក។"</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"បិទ/បើក​កុំព្យូទ័រ​បន្ទះ"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"បិទ/បើក​ទូរស័ព្ទ"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"ឲ្យ​កម្មវិធី​បិទ/បើក​កុំព្យូទ័រ​បន្ទះ។"</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"ឲ្យ​កម្មវិធី​បិទ/បើក​ទូរស័ព្ទ។"</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"ដំណើរការ​ក្នុង​របៀប​សាកល្បង​ពី​រោងចក្រ"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"ដំណើរការ​សាកល្បង​ក្រុមហ៊ុន​ផលិត​កម្រិត​ទាប ដោយ​អនុញ្ញាត​ឲ្យ​ចូល​ផ្នែក​រឹង​កុំព្យូទ័រ​បន្ទះ។ អាច​ប្រើ​​បាន​តែ​ពេល​កុំព្យូទ័រ​កំពុង​ដំណើរការ​ក្នុង​របៀប​សាកល្បង​ក្រុមហ៊ុន​ផលិត។"</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"ដំណើរ​ការ​ការ​សាកល្បង​ក្រុមហ៊ុន​ផលិត​កម្រិត​ទាប ដោយ​អនុញ្ញាត​ការ​ចូល​ដំណើរការ​ផ្នែក​រឹង​ទូរស័ព្ទ។ អាច​ប្រើ​បាន​តែ​នៅ​ពេល​ទូរស័ព្ទ​កំពុង​ដំណើរការ​របៀប​សាកល្បង​ក្រុមហ៊ុន​ផលិត។"</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"កំណត់​ផ្ទាំង​រូបភាព"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"ឲ្យ​កម្មវិធី​កំណត់​ផ្ទាំង​រូបភាព​ប្រព័ន្ធ។"</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"កែតម្រូវ​ទំហំ​ផ្ទាំង​រូបភាព​របស់​អ្នក"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"ឲ្យ​កម្មវិធី​កំណត់​ជំនួយ​ទំហំ​ផ្ទាំង​រូបភាព​ប្រព័ន្ធ។"</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"កំណត់​ប្រព័ន្ធ​ទៅ​លំនាំដើម​រោងចក្រ​ឡើងវិញ"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"ឲ្យ​កម្មវិធី​កំណត់​ប្រព័ន្ធ​​ដូច​ការ​កំណត់​ចេញ​ពី​រោងចក្រ​ឡើងវិញ​ពេញលេញ ដោយ​លុប​ទិន្នន័យ ការ​កំណត់​រចនាសម្ព័ន្ធ និង​កម្មវិធី​បាន​ដំឡើង។"</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"កំណត់​​ម៉ោង"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"ឲ្យ​កម្មវិធី​ប្ដូរ​ម៉ោង​កុំព្យូទ័រ​បន្ទះ។"</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"ឲ្យ​កម្មវិធី​ប្ដូរ​ម៉ោង​ទូរស័ព្ទ។"</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"កំណត់​តំបន់​ពេលវេលា"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"ឲ្យ​កម្មវិធី​ប្ដូរ​តំបន់​ពេលវេលា​របស់​កុំព្យូទ័រ​បន្ទះ​នេះ។"</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"ឲ្យ​កម្មវិធី​ប្ដូរ​តំបន់​ពេលវេលា​របស់​ទូរស័ព្ទ។"</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"ដើរ​តួ​ជា AccountManagerService"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"ឲ្យ​កម្មវិធី​ហៅ​ទៅ​​កម្មវិធី​​ផ្ទៀងផ្ទាត់​គណនី។"</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"រក​គណនី​លើ​ឧបករណ៍"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"ឲ្យ​កម្មវិធី​ទទួល​បញ្ជី​គណនី​ដែល​បាន​ស្គាល់​ដោយ​កុំព្យូទ័រ​បន្ទះ។ វា​អាច​រួម​មាន​គណនី​ណាមួយ​ដែល​បាន​បង្កើត​ដោយ​កម្មវិធី​ដែល​អ្នក​បាន​ដំឡើង។"</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"ឲ្យ​កម្មវិធី​ទទួល​បញ្ជី​គណនី​ដែល​ទូរស័ព្ទ​​បាន​ស្គាល់​។ វា​អាច​មាន​គណនី​ដែល​បាន​បង្កើត​ដោយ​កម្មវិធី​ដែល​អ្នក​បាន​ដំឡើង។"</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"បង្កើត​គណនី និង​កំណត់​ពាក្យ​សម្ងាត់"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"ឲ្យ​កម្មវិធី​ប្រើ​សមត្ថភាព​កម្មវិធី​ផ្ទៀងផ្ទាត់​គណនី​នៃ​កម្មវិធី​គ្រប់គ្រង​គណនី រួមមាន​បង្កើត​គណនី និង​ទទួល ព្រម​ទាំង​កំណត់​ពាក្យ​សម្ងាត់​។"</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"បន្ថែម​ ឬ​លុប​​គណនី"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"ឲ្យ​កម្មវិធី​​អនុវត្ត​ប្រតិបត្តិការ​ដូចជា បន្ថែម និង​លុប​គណនី ព្រម​ទាំង​លុប​ពាក្យ​សម្ងាត់។"</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"ប្រើ​គណនី​​​លើ​ឧបករណ៍"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"ឲ្យ​កម្មវិធី​ស្នើ​និមិត្តសញ្ញា​ផ្ទៀងផ្ទាត់។"</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"មើល​ការ​តភ្ជាប់​បណ្ដាញ"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"ឲ្យ​កម្មវិធី​មើល​ព័ត៌មាន​អំពី​ការ​តភ្ជាប់​បណ្ដាញ​ដូចជា​​មាន​បណ្ដាញ​ណាមួយ​ និង​បណ្ដាញ​ត្រូវ​បាន​ភ្ជាប់។"</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"ចូល​ដំណើរការ​បណ្ដាញ​ពេញ​លេញ"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"ឲ្យ​កម្មវិធី​បង្កើត​រន្ធ​បណ្ដាញ​ និង​ប្រើ​ពិធីការ​បណ្ដាញ​តាម​បំណង។ កម្មវិធី​អ៊ីនធឺណិត​ និង​កម្មវិធី​ផ្សេង​ៗ​ផ្ដល់​វិធី​ផ្ញើ​ទិន្នន័យ​ទៅ​អ៊ីនធឺណិត ដូច្នេះ​សិទ្ធិ​នេះ​មិន​ទាមទារ​ឲ្យ​ផ្ញើ​ទិន្នន័យ​ទៅ​អ៊ីនធឺណិត។"</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"ប្ដូរ/បញ្ឈប់​ចរាចរណ៍ និង​ការ​កំណត់​​បណ្ដាញ"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"ឲ្យ​កម្មវិធី​ប្ដូរ​ការ​កំណត់​បណ្ដាញ និង​រារាំង​ និង​តាមដាន​ចរាចរណ៍​បណ្ដាញ ឧទាហរណ៍ ដើម្បី​ប្ដូរ​ប្រូកស៊ី និង​ច្រក APN ។​ កម្មវិធី​ព្យាបាទ​អាច​ពិនិត្យ បញ្ជូន​បន្ត ឬ​កែ​កញ្ចប់​ព័ត៌មាន​បណ្ដាញ​ដោយ​មិន​ឲ្យ​អ្នក​ដឹង។"</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"ប្ដូរ​ការ​តភ្ជាប់​បណ្ដាញ"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"ឲ្យ​កម្មវិធី​ប្ដូរ​ស្ថានភាព​តភ្ជាប់​បណ្ដាញ។"</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"ប្ដូរ​ការ​តភ្ជាប់​ដែល​បាន​​ភ្ជាប់"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"ឲ្យ​កម្មវិធី​ប្ដូរ​ស្ថានភាព​ការ​តភ្ជាប់​បណ្ដាញ​ដែល​បាន​ភ្ជាប់។"</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"ប្ដូរ​ការ​កំណត់​ប្រើ​ទិន្នន័យ​ផ្ទៃ​ខាង​ក្រោយ"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"ឲ្យ​កម្មវិធី​ប្ដូរ​ការ​កំណត់​ការ​ប្រើ​ទិន្នន័យ​ផ្ទៃ​ខាង​ក្រោយ។"</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"មើល​ការ​តភ្ជាប់​វ៉ាយហ្វាយ"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"ឲ្យ​កម្មវិធី​មើល​ព័ត៌មាន​អំពី​បណ្ដាញ​វ៉ាយហ្វាយ ដូច​ជា​ថា​តើ​វ៉ាយហ្វាយ​បាន​បើក​ដែរ​ឬទេ និង​ឈ្មោះ​ឧបករណ៍​វ៉ាយហ្វាយ​ដែល​បាន​តភ្ជាប់។"</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"ភ្ជាប់ និង​ផ្ដាច់​ពី​វ៉ាយហ្វាយ"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"ឲ្យ​កម្មវិធី​តភ្ជាប់ និង​ផ្ដាច់​ពី​ចំណុច​ចូល​ដំណើរការ​វ៉ាយហ្វាយ និង​​ធ្វើការ​ផ្លាស់ប្ដូរ​ការ​កំណត់​រចនាសម្ព័ន្ធ​ឧបករណ៍​សម្រាប់​បណ្ដាញ​វ៉ាយហ្វាយ។"</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"អនុញ្ញាត​ទទួល​​ម៉ាល់ធីខាស​វ៉ាយហ្វាយ"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"ឲ្យ​កម្មវិធី​ទទួល​កញ្ចប់​ព័ត៌មាន​ដែល​បាន​ផ្ញើ​ទៅ​ឧបករណ៍​ទាំងអស់​លើ​បណ្ដាញ​វ៉ាយ​ហ្វាយ ដោយ​ប្រើ​អាសយដ្ឋាន​ប្រកាស​ច្រើន មិន​គ្រាន់តែ​សម្រាប់​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក​ទេ។ វា​ប្រើ​ថាមពល​ច្រើន​ជាង​របៀប​មិន​ប្រកាស​ច្រើន។"</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"ឲ្យ​កម្មវិធី​ទទួល​កញ្ចប់​ព័ត៌មាន​បាន​ផ្ញើ​ឧបករណ៍​ទាំងអស់​​លើ​បណ្ដាញ​​វ៉ាយហ្វាយ ​ដោយ​ប្រើ​អាសយដ្ឋាន​​ម៉ាល់ធីខាស មិន​សម្រាប់​តែ​ទូរស័ព្ទ​របស់​អ្នក​ទេ។ វា​ប្រើ​ថាមពល​ច្រើន​ជាង​របៀប​មិន​​ម៉ាល់ធីខាស។"</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"ចូល​ដំណើរការ​​ការ​កំណត់​ប៊្លូធូស"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"ឲ្យ​កម្មវិធី​កំណត់​រចនាសម្ព័ន្ធ​កុំព្យូទ័រ​បន្ទះ​ប៊្លូធូស​មូលដ្ឋាន និង​រកមើល ព្រម​ទាំង​ផ្គូផ្គង​ជា​មួយ​ឧបករណ៍​ពី​ចម្ងាយ។"</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"ឲ្យ​កម្មវិធី​មើល​​ការ​កំណត់​រចនាសម្ព័ន្ធ​ប៊្លូធូស​ក្នុង​ទូរស័ព្ទ ដើម្បី​រកមើល និង​ផ្គូផ្គង​ជា​មួយ​ឧបករណ៍​ពី​ចម្ងាយ។"</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"ភ្ជាប់ និង​ផ្ដាច់​ពី WiMAX"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"ឲ្យ​កម្មវិធី​កំណត់​ថា​តើ WiMAX ត្រូវ​បាន​បើក និង​ព័ត៌មាន​អំពី​បណ្ដាញ WiMAX ដែល​ត្រូវ​បាន​តភ្ជាប់។"</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"ប្ដូរ​ស្ថានភាព WiMAX"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"ឲ្យ​កម្មវិធី​តភ្ជាប់​ និង​ផ្ដាច់​កុំព្យូទ័រ​បន្ទះ​ពី​បណ្ដាញ WiMAX ។"</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"ឲ្យ​កម្មវិធី​ភ្ជាប់​ទូរស័ព្ទ​ និង​ផ្ដាច់​ពី​បណ្ដាញ WiMAX ។"</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"ផ្គូផ្គង​ជា​មួយ​ឧបករណ៍​ប៊្លូធូស"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"ឲ្យ​កម្មវិធី​មើល​ការ​កំណត់​រចនាសម្ព័ន្ធ​​ប៊្លូធូស​លើ​​កុំព្យូទ័រ​បន្ទះ ព្រម​ទាំង​ធ្វើ​ការ​តភ្ជាប់ និង​ទទួល​​ជា​មួយ​ឧបករណ៍​បាន​ផ្គូផ្គង។"</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"ឲ្យ​កម្មវិធី​មើល​​ការ​កំណត់​រចនាសម្ព័ន្ធ​ប៊្លូធូស​ក្នុង​ទូរស័ព្ទ ដើម្បី​ទទួល និង​តភ្ជាប់​ជា​មួយ​ឧបករណ៍​បាន​ផ្គូផ្គង។"</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"ពិនិត្យ​ការ​ទាក់ទង​នៅ​ក្បែរ (NFC)"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"ឲ្យ​កម្មវិធី​ទាក់ទង​ជា​មួយ​ស្លាក (NFC) កាត និង​កម្មវិធី​អាន។"</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"បិទ​ការ​ចាក់​សោ​អេក្រង់​របស់​អ្នក"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"ឲ្យ​កម្មវិធី​បិទ​ការ​ចាក់សោ​សុវត្ថិភាព​ពាក្យ​សម្ងាត់​ដែល​បាន​ភ្ជាប់​ណា​មួយ។ ​ឧទាហរណ៍​ត្រឹមត្រូវ​​​នៃ​ការ​បិទ​ទូរស័ព្ទ​ពេល​ទទួលការ​ហៅ​ចូល បន្ទាប់​ម​បើក​សោ​ពេល​ការ​ហៅ​បាន​បញ្ចប់។"</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"អាន​ការ​កំណត់​ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"ឲ្យ​កម្មវិធី​អាន​ការ​កំណត់​ធ្វើ​សម​កាល​កម្ម​សម្រាប់​គណនី។ ឧទាហរណ៍ វា​អាច​កំណត់​ថា​តើ​​​កម្មវិធី​ត្រូវ​បាន​បើក​ជា​មួយ​គណនី​ដែរ​ឬទេ។"</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"បិទ/បើក​ការ​ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"ឲ្យ​កម្មវិធី​កែ​ការ​កំណត់​ធ្វើ​សម​កាល​កម្ម​សម្រាប់​គណនី។ ឧទាហរណ៍ វា​អាច​ត្រូវ​បាន​ប្រើ​ដើម្បី​បើក​ការ​ធ្វើ​សម​កាល​កម្ម​កម្មវិធី​របស់​មនុស្ស​ជា​មួយ​គណនី។"</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"អាន​ស្ថិតិ​ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"ឲ្យ​កម្មវិធី​អាន​ស្ថានភាព​ធ្វើ​សម​កាល​កម្ម​សម្រាប់​គណនី រួមមាន​ព្រឹត្តិការណ៍​ប្រវត្តិ​ធ្វើ​សម​កាល​កម្ម ​និង​ទំហំ​ទិន្នន័យ​បាន​ធ្វើ​សម​កាល​កម្ម។"</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"អាន​អត្ថបទ​ព័ត៌មាន​បាន​ជាវ"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"ឲ្យ​កម្មវិធី​ទទួល​ព័ត៌មាន​លម្អិត​អំពី​អត្ថបទ​ព័ត៌មាន​​បាន​ធ្វើ​សម​កាល​កម្ម​បច្ចុប្បន្ន។"</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"សរសេរ​​អត្ថបទ​ព័ត៌មាន​ដែល​​បាន​ជាវ"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"ឲ្យ​កម្មវិធី​កែ​អត្ថបទ​ព័ត៌មាន​បាន​ធ្វើ​សម​កាល​កម្ម​បច្ចុប្បន្ន​របស់​អ្នក។ កម្មវិធី​ព្យាបាទ​អាច​ប្ដូរ​អត្ថបទ​បាន​ធ្វើ​សម​កាល​កម្ម​របស់​អ្នក។"</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"អាន​ពាក្យ​ដែល​អ្នក​បាន​បន្ថែម​ទៅ​វចនានុក្រម"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"ឲ្យ​កម្មវិធី​អាន​ពាក្យ ឈ្មោះ និង​ឃ្លា​ទាំងអស់​ដែល​អ្នកប្រើ​អាច​​រក្សាទុក​ក្នុង​វចនានុក្រម​​អ្នកប្រើ។"</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"បន្ថែម​ពាក្យ​ទៅ​វចនានុក្រម​កំណត់​ដោយ​អ្នកប្រើ"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"ឲ្យ​កម្មវិធី​សរសេរ​ពាក្យ​ថ្មី​ក្នុង​វចនានុក្រម​អ្នកប្រើ។"</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"សាកល្បង​ចូល​ដំណើរការ​ការ​ផ្ទុក​ដែល​បាន​ការពារ"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"សាកល្បង​ចូល​ដំណើរការ​ការ​ផ្ទុក​ដែល​បាន​ការពារ"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"ឲ្យ​កម្មវិធី​សាកល្បង​សិទ្ធិ​សម្រាប់​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី ដែល​នឹង​អាច​ប្រើ​បាន​លើ​ឧបករណ៍​​ពេល​អនាគត។"</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"ឲ្យ​កម្មវិធី​សាកល្បង​សិទ្ធិ​សម្រាប់​កាត​អេសឌី​ដែល​នឹង​អាច​ប្រើ​បាន​លើ​ឧបករណ៍​នា​ពេល​អនាគត។"</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"កែ​ ឬ​លុប​មាតិកា​នៃ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​របស់​អ្នក"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"កែ ឬ​លុប​មាតិកា​កាត​អេសឌី"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"ឲ្យ​កម្មវិធី​សរសេរ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"ឲ្យ​​កម្មវិធី​សរសេរ​ទៅ​កាត​អេសឌី។"</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"កែ/លុប​មាតិកា​ឧបករណ៍​ផ្ទុក​មេឌៀ​ខាង​ក្នុង"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"ឲ្យ​កម្មវិធី​កែ​មាតិកា​នៃ​ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង។"</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"គ្រប់គ្រង​ការ​ផ្ទុក​ឯកសារ"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"ឲ្យ​កម្មវិធី​គ្រប់គ្រង​ការ​ផ្ទុក​ឯកសារ។"</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"ចូល​ដំណើរការ​ឧបករណ៍​ផ្ទុក​ខាង​ក្រៅ​នៃ​អ្នកប្រើ​ទាំងអស់"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"ឲ្យ​កម្មវិធី​ចូល​ដំណើរការ​ឧបករណ៍​ផ្ទុក​ខាង​ក្រៅ​សម្រាប់​អ្នកប្រើ​ទាំងអស់។"</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"ចូល​ដំណើរការ​ប្រព័ន្ធ​​​ឯកសារ​ឃ្លាំង​សម្ងាត់"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"ឲ្យ​កម្មវិធី​អាន និង​សរសេរ​ប្រព័ន្ធ​ឯកសារ​ឃ្លាំង​សម្ងាត់។"</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"ធ្វើ​ការ​ហៅ/ទទួល​តាម​អ៊ីនធឺណិត"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"ឲ្យ​កម្មវិធី​ប្រើ​សេវាកម្ម SIP ដើម្បី​​​ហៅ/ទទួល​​​តាម​អ៊ីនធឺណិត។"</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"អាន​ការ​ប្រើ​បណ្ដាញ​ពិសេស"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"ឲ្យ​កម្មវិធី​អាន​ការ​ប្រើ​បណ្ដាញ​ជា​ប្រវត្តិ​សាស្ត្រ​សម្រាប់​បណ្ដាញ និង​កម្មវិធី​ជាក់លាក់។"</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"គ្រប់គ្រង​គោលនយោបាយ​បណ្ដាញ"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"ឲ្យ​កម្មវិធី​គ្រប់គ្រង​គោលនយោបាយ​បណ្ដាញ និង​កំណត់​ក្បួន​ជាក់លាក់​សម្រាប់​កម្មវិធី។"</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"កែ​គណនី​ប្រើ​បណ្ដាញ"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"ឲ្យ​កម្មវិធី​កែ​វិធី​គិត​ថ្លៃ​សេវាកម្ម​ប្រើ​បណ្ដាញ​​តាម​កម្មវិធី។ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា។"</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"កែប្រែ​សញ្ញា​រន្ធ"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"ឲ្យ​កម្មវិធី​កែ​សញ្ញា​រន្ធ​​សម្រាប់​នាំ​ផ្លូវ"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"ចូល​ដំណើរ​ការ​ការ​ជូន​ដំណឹង"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"ឲ្យ​កម្មវិធី​ទៅ​យក ពិនិត្យ និង​សម្អាត​ការ​ជូន​ដំណឹង រួមមាន​​ប្រកាស​ដោយ​កម្មវិធី​ផ្សេងៗ។"</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"ចង​ទៅ​សេវាកម្ម​ស្ដាប់​ការ​ជូន​ដំណឹង"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"ឲ្យ​ម្ចាស់​ចង​ចំណុច​ប្រទាក់​កម្រិត​កំពូល​នៃ​សេវាកម្ម​កម្មវិធី​ស្ដាប់​ការ​ជូន​ដំណឹង។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​​ទេ។"</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"ដកហូត​កម្មវិធី​កំណត់​រចនាសម្ព័ន្ធ​ដែល​បាន​ផ្ដល់​ដោយ​ក្រុមហ៊ុន​បញ្ជូន"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"អនុញ្ញាត​ឲ្យ​ម្ចាស់​ដក​ហូត​កម្មវិធី​កំណត់​រចនាសម្ព័ន្ធ​ដែល​បាន​ផ្ដល់​ដោយ​ក្រុមហ៊ុន​បញ្ជូន។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"សង្កេត​មើល​លើ​លក្ខខណ្ឌ​បណ្ដាញ"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"ឲ្យ​កម្មវិធី​សង្កេត​មើល​​លើ​លក្ខខណ្ឌ​បណ្ដាញ​។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"កំណត់​ក្បួន​ពាក្យ​សម្ងាត់"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"ពិនិត្យ​ប្រវែង និង​តួអក្សរ​ដែល​បាន​អនុញ្ញាត​ក្នុង​ពាក្យ​សម្ងាត់​ចាក់​សោ​អេក្រង់។"</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"ពិនិត្យ​ការ​ព្យាយាម​ដោះ​សោ​អេក្រង់"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"ពិនិត្យ​ចំនួន​​បញ្ចូល​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ។ ពេល​ដោះ​សោ​អេក្រង់ និង​ចាក់​សោ​ទូរស័ព្ទ ឬ​លុប​ទិន្នន័យ​ទូរស័ព្ទ​ទាំងអស់​ ប្រសិន​បើ​មាន​ពាក្យ​សម្ងាត់​បញ្ចូល​មិន​ត្រឹមត្រូវ​ច្រើន​ដង​ពេក។"</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"ពិនិត្យ​ចំនួន​​បញ្ចូល​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ។ ពេល​ដោះ​សោ​អេក្រង់ និង​ចាក់​សោ​ទូរស័ព្ទ ឬ​លុប​ទិន្នន័យ​ទូរស័ព្ទ​ទាំងអស់​ ប្រសិន​បើ​មាន​ពាក្យ​សម្ងាត់​បញ្ចូល​មិន​ត្រឹមត្រូវ​ច្រើន​ដង​ពេក។"</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"ប្ដូរ​ពាក្យ​សម្ងាត់​ដោះ​សោ​អេក្រង់"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"ប្ដូរ​ពាក្យ​សម្ងាត់​​ដោះ​សោ​អេក្រង់។"</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"ចាក់សោ​អេក្រង់"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"ពិនិត្យ​វិធី និង​ពេលវេលា​ចាក់សោ​អេក្រង់។"</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"លុប​ទិន្នន័យ​ទាំង​អស់"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"លុប​ទិន្នន័យ​កុំព្យូទ័រ​បន្ទះ​ដោយ​មិន​​ព្រមាន​ដោយ​អនុវត្ត​ការ​កំណត់​ទិន្នន័យ​ដូច​ចេញ​ពី​រោងចក្រ។"</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"លុប​ទិន្នន័យ​ទូរស័ព្ទ​ដោយ​មិន​ព្រមាន ដោយ​អនុវត្ត​ការ​កំណត់​ទិន្នន័យ​ដូច​ចេញ​ពី​រោងចក្រ ។"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"កំណត់​ប្រូកស៊ី​សកល​របស់​ឧបករណ៍"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"កំណត់​ប្រូកស៊ី​សកល​របស់​ឧបករណ៍​ត្រូវ​ប្រើ​ពេល​បាន​បើក​គោលនយោបាយ។ មាន​តែ​អ្នក​គ្រប់គ្រង​ឧបករណ៍​ដំបូង​ប៉ុណ្ណោះ​កំណត់​ប្រូកស៊ី​សកល​ត្រឹមត្រូវ។"</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"កំណត់​សុពលភាព​ពាក្យ​សម្ងាត់​ចាក់សោ​អេក្រង់"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"ពិនិត្យ​វិធី​ដែល​ប្ដូរ​ពាក្យ​សម្ងាត់​ចាក់​សោ​អេក្រង់​ញឹកញាប់។"</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"កំណត់​ការ​ដាក់លេខ​កូដ​ការ​ផ្ទុក"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"តម្រូវ​ឲ្យ​ដាក់​លេខ​កូដ​ទិន្នន័យ​កម្មវិធី​បាន​រក្សាទុក។"</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"បិទ​ម៉ាស៊ីន​ថត"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"ការពារ​ការ​ប្រើ​ម៉ាស៊ីន​ថត​ឧបករណ៍​ទាំងអស់។"</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"បិទ​លក្ខណៈ​ក្នុង​ការ​ចាក់សោ"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"ការ​ពារ​មិន​ឲ្យ​ប្រើ​លក្ខណៈ​មួយ​ចំនួន​ក្នុង​ការ​ចាក់សោ។"</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"ផ្ទះ"</item>
-    <item msgid="869923650527136615">"​ចល័ត"</item>
-    <item msgid="7897544654242874543">"កន្លែង​ធ្វើការ"</item>
-    <item msgid="1103601433382158155">"ទូរសារ​កន្លែង​ធ្វើ"</item>
-    <item msgid="1735177144948329370">"ទូរសារ​ផ្ទះ"</item>
-    <item msgid="603878674477207394">"ភេយ័រ"</item>
-    <item msgid="1650824275177931637">"ផ្សេងៗ"</item>
-    <item msgid="9192514806975898961">"តាម​បំណង"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"ផ្ទះ"</item>
-    <item msgid="7084237356602625604">"កន្លែង​ធ្វើការ"</item>
-    <item msgid="1112044410659011023">"ផ្សេងៗ"</item>
-    <item msgid="2374913952870110618">"តាម​តម្រូវ​ការ"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"ផ្ទះ"</item>
-    <item msgid="5629153956045109251">"កន្លែង​ធ្វើការ"</item>
-    <item msgid="4966604264500343469">"ផ្សេងៗ"</item>
-    <item msgid="4932682847595299369">"តាម​បំណង"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"ផ្ទះ"</item>
-    <item msgid="1359644565647383708">"កន្លែង​ធ្វើការ"</item>
-    <item msgid="7868549401053615677">"ផ្សេងៗ"</item>
-    <item msgid="3145118944639869809">"តាម​តម្រូវការ"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"កន្លែង​ធ្វើការ"</item>
-    <item msgid="4378074129049520373">"ផ្សេងៗ"</item>
-    <item msgid="3455047468583965104">"តាម​តម្រូវ​ការ"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"ជជែក​ Google"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"តាម​បំណង"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"ផ្ទះ"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"​ចល័ត"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"កន្លែង​ធ្វើការ"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"ទូរសារ​កន្លែង​ធ្វើការ"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"ទូរសារ​ផ្ទះ"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"ភេយ័រ"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"ផ្សេងៗ"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"ហៅ​មក​វិញ"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"រថយន្ត"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"លេខ​សំខាន់​ក្រុមហ៊ុន"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"លេខ​សំខាន់"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"ទូរសារ​ផ្សេង"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"វិទ្យុ"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"ទូរសារ"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"ទូរស័ព្ទ​​កន្លែងធ្វើការ"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"ភេយ័រ​កន្លែង​ធ្វើ​ការ"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"អ្នក​ជំនួយ​ការ"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"សារ MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"តាម​តម្រូវ​ការ"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"ថ្ងៃ​ខួប​កំណើត"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"បុណ្យខួប"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"ផ្សេងៗ"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"តាម​តម្រូវ​ការ"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"ផ្ទះ"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"កន្លែង​ធ្វើការ"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"ផ្សេងៗ"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"ចល័ត"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"តាម​តម្រូវ​ការ"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"ផ្ទះ"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"កន្លែង​ធ្វើការ"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"ផ្សេងៗ"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"តាម​បំណង"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"ផ្ទះ"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"កន្លែង​ធ្វើការ"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"ផ្សេងៗ"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"តាម​បំណង"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"ការ​ជជែក"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"កន្លែង​ធ្វើការ"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"ផ្សេងៗ"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"តាម​តម្រូវការ"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"តាម​បំណង"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"អ្នក​ជំនួយ​ការ"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"បងប្អូន​ប្រុស"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"កូន"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"ដៃគូ​ក្នុងស្រុក"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"ឪពុក"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"មិត្តភ័ក្ដិ"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"អ្នក​គ្រប់គ្រង"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"ម្ដាយ"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"ឪពុកម្ដាយ"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"ដៃគូ"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"យោង​ដោយ"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"សាច់ញាតិ"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"បងប្អូន​ស្រី"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"ប្ដី/​​ប្រពន្ធ"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"តាម​បំណង"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"គេហ​ទំព័រ"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"កន្លែង​ធ្វើការ"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"ផ្សេងៗ"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"បញ្ចូល​កូដ PIN"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"បញ្ចូល​កូដ PUK និង​ PIN ថ្មី"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"កូដ PUK"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"កូដ PIN ថ្មី"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"ប៉ះ ដើម្បី​បញ្ចូល​ពាក្យ​សម្ងាត់"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"បញ្ចូល​ពាក្យ​សម្ងាត់​ ​ដើម្បី​ដោះ​សោ"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"បញ្ចូល​កូដ PIN ដើម្បី​ដោះ​សោ"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"កូដ PIN មិន​ត្រឹមត្រូវ។"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"ដើម្បី​ដោះ​សោ​​ ចុច​ម៉ឺនុយ​ បន្ទាប់មក 0 ។"</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"លេខ​ពេល​អាសន្ន"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"គ្មាន​សេវា។"</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"ចាក់​អេក្រង់។"</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"ចុច​ម៉ឺនុយ ដើម្បី​ដោះ​សោ​ ឬ​ហៅ​ពេល​អាសន្ន។"</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"ចុច​ម៉ឺនុយ ដើម្បី​ដោះ​សោ។"</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"គូរ​លំនាំ ដើម្បី​ដោះ​សោ"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"ការ​ហៅ​​ពេល​អាសន្ន"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"ត្រឡប់​ទៅ​ការ​ហៅ"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"ត្រឹមត្រូវ!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"ព្យាយាម​ម្ដង​ទៀត"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"ព្យាយាម​ម្ដង​ទៀត"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"បាន​លើស​ការ​ព្យាយាម​ដោះ​សោ​តាម​ទម្រង់​មុខ"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"បញ្ចូល​ថ្ម <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"បាន​បញ្ចូល​ពេញ។"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"ភ្ជាប់​ឧបករណ៍​បញ្ចូល​ថ្ម។"</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"គ្មាន​ស៊ី​ម​កាត"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"គ្មាន​ស៊ីម​កាត​ក្នុង​កុំព្យូទ័រ​បន្ទះ។"</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"គ្មាន​ស៊ីម​កាត​ក្នុង​ទូរស័ព្ទ។"</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"បញ្ចូល​​ស៊ី​ម​កាត។"</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"បាត់​ ឬ​មិន​អាច​អាន​ស៊ីម​កាត។ បញ្ចូល​ស៊ីម​កាត។"</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"ស៊ី​ម​កាត​មិន​អាច​ប្រើ​បាន​។"</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"ស៊ីម​កាត​របស់​អ្នក​ត្រូវ​បាន​បិទ​ជា​អចិន្ត្រៃយ៍។\n ទាក់ទង​ក្រុមហ៊ុន​ផ្ដល់​សេវាកម្ម​ឥត​ខ្សែ​របស់​អ្នក​សម្រាប់​ស៊ីម​កាត​ផ្សេង។"</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"ប៊ូតុង​បទ​មុន"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"ប៊ូតុង​បទ​បន្ទាប់"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"ប៊ូតុង​​ផ្អាក"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"ប៊ូតុង​ចាក់"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"ប៊ូតុង​បញ្ឈប់"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"សម្រាប់​តែ​ហៅ​ពេល​អាសន្ន​ប៉ុណ្ណោះ"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"បណ្ដាញ​ជាប់​សោ"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"ស៊ីម​កាត​ជាប់​សោ PUK។"</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"មើល​មគ្គុទ្ទេសក៍​អ្នក​ប្រើ ឬ​ទាក់ទង​សេវា​អតិថិជន។"</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"ស៊ីមកាត​​ជាប់​សោ។"</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"កំពុង​ដោះ​សោ​ស៊ីមកាត..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​សោ​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ \n\nព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"អ្នក​បាន​បញ្ចូល​ពាក្យ​សម្ងាត់​របស់​អ្នក​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ \n\nព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"អ្នក​បាន​បញ្ចូល​កូដ​ PIN មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ \n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​សោ​របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើន​ជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង អ្នក​នឹង​ត្រូវ​បាន​ស្នើ​ឲ្យ​ដោះ​សោ​​កុំព្យូទ័រ​បន្ទះ​​របស់​អ្នក ដោយ​ប្រើ​ការ​ចូល​ក្នុង​គណនី Google របស់​អ្នក។\n\n សូម​ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_2">%d</xliff:g> វិនាទី។"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​សោ​របស់​អ្នក​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ <xliff:g id="NUMBER_1">%d</xliff:g> ដង​ទៀត អ្នក​នឹង​ត្រូវ​បាន​ស្នើ​ឲ្យ​ដោះ​សោ​ទូរស័ព្ទ​របស់​អ្នក​ដោយ​ប្រើ​ការ​ចូល​ Google ។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_2">%d</xliff:g> វិនាទី។"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​កុំព្យូទ័រ​បន្ទះ​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​ <xliff:g id="NUMBER_1">%d</xliff:g> ដង​ទៀត កុំព្យូទ័រ​បន្ទះ​នឹង​ត្រូវ​បាន​កំណត់​ដូច​ចេញ​ពី​រោងចក្រ​ឡើងវិញ ហើយ​ទិន្នន័យ​អ្នក​ប្រើ​ទាំងអស់​នឹង​បាត់បង់។"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"អ្នក​បាន​ព្យាយាម​​ដោះ​សោ​​ទូរស័ព្ទ​មិន​ត្រឹមត្រូវ​ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ <xliff:g id="NUMBER_1">%d</xliff:g> ទូរស័ព្ទ​នឹង​ត្រូវ​បាន​កំណត់​ដូច​ចេញ​ពី​រោងចក្រ​ឡើងវិញ ហើយ​បាត់បង់​ទិន្នន័យ​អ្នក​ប្រើ​ទាំងអស់។"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​កុំព្យូទ័រ​បន្ទះ​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER">%d</xliff:g> ដង។ ឥឡូវ​កុំព្យូទ័រ​បន្ទះ​នឹង​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោង​ចក្រ។"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​ទូរស័ព្ទ​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER">%d</xliff:g> ដង។ ឥឡូវ​ទូរស័ព្ទ​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​​ដូច​ចេញ​ពី​រោងចក្រ។"</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ <xliff:g id="NUMBER">%d</xliff:g> វិនាទី​។"</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"ភ្លេច​លំនាំ​?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"ដោះ​សោ​គណនី"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"ព្យាយាម​លំនាំ​ច្រើន​ពេក"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"ដើម្បី​ដោះ​សោ ចូល​គណនី Google របស់​អ្នក។"</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"ឈ្មោះ​អ្នក​ប្រើ (អ៊ីមែល​)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"ពាក្យសម្ងាត់"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"ចូល"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"ឈ្មោះ​អ្នកប្រើ ឬ​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ។"</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"ភ្លេច​ឈ្មោះ​អ្នក​ប្រើ ឬ​ពាក្យ​សម្ងាត់​របស់​អ្នក?\nមើល "<b>"google.com/accounts/recovery"</b>" ។"</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"កំពុង​ពិនិត្យ..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"ដោះ​សោ"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"បើក​សំឡេង"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"បិទសំឡេង"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"បាន​ចាប់​ផ្ដើម​លំនាំ"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"បាន​សម្អាត​លំនាំ"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"បាន​បន្ថែម​ក្រឡា"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"បាន​បញ្ចប់​លំនាំ"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. ធាតុ​ក្រាហ្វិក %2$d នៃ %3$d ។"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"បន្ថែម​ធាតុ​ក្រាហ្វិក​។"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"ទទេ"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"បាន​ពង្រីក​ផ្ទៃ​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"បាន​បង្រួម​ផ្ទៃ​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ធាតុ​ក្រាហ្វិក។"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"ឧបករណ៍​ជ្រើស​អ្នក​ប្រើ"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"ស្ថានភាព"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"ម៉ាស៊ីន​ថត"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"ពិនិត្យ​មេឌៀ"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"បាន​ចាប់ផ្ដើម​តម្រៀប​ធាតុ​ក្រាហ្វិក​ឡើងវិញ។"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"បាន​បញ្ចប់​ការ​បង្ហាញ​ធាតុ​ក្រាហ្វិក។"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"បាន​លុប​ធាតុ​ក្រាហ្វិក <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ។"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"ពង្រីក​តំបន់​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"រុញ​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"លំនាំ​ដោះ​សោ​។"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"ដោះ​សោ​តាម​​ទម្រង់​មុខ។"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"កូដ PIN ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"ពាក្យ​សម្ងាត់​ដោះ​សោ​។"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ផ្ទៃ​លំនាំ។"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"ផ្ទៃ​រុញ។"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"តួអក្សរ"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"ពាក្យ"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"តំណ"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"បន្ទាត់"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"បាន​បរាជ័យ​ក្នុង​ការ​សាកល្បង​រោងចក្រ"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"សកម្មភាព FACTORY_TEST ត្រូវ​បាន​គាំទ្រ​សម្រាប់​តែ​កញ្ចប់​បាន​ដំឡើង​ក្នុង /system/app."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"រក​មិន​ឃើញ​កញ្ចប់​ដែល​ផ្ដល់​សកម្មភាព FACTORY_TEST ។"</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"ចាប់​ផ្ដើម​ឡើង​វិញ"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"ទំព័រ​មាន​ចំណងជើង \"<xliff:g id="TITLE">%s</xliff:g>\" សរសេរ៖"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"បញ្ជាក់​ការ​រុករក"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"ចាកចេញ​ពី​ទំព័រ​នេះ"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"នៅ​លើ​ទំព័រ​នេះ"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nតើ​អ្នក​ប្រាកដ​ជា​ចង់​ចេញ​ពី​ទំព័រ​នេះ​ឬ?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"បញ្ជាក់"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"ជំនួយ៖ ប៉ះ​ពីរ​ដង ដើម្បី​ពង្រីក និង​បង្រួម។"</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"បំពេញ​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"រៀបចំ​ការ​បំពេញ​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"ខេត្ត"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"លេខ​ប្រៃសណីយ៍"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"រដ្ឋ"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"កូដ​តំបន់"</string>
-    <string name="autofill_county" msgid="237073771020362891">"ប្រទេស"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"កោះ"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"ស្រុក"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"ផ្នែក"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"Prefecture"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"Parish"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"តំបន់"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"Emirate"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"អាន​ប្រវត្តិ និង​ចំណាំ​បណ្ដាញ"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"ឲ្យ​កម្មវិធី​អាន​ប្រវត្តិ URLs ទាំង​អស់​ដែល​កម្មវិធី​អ៊ីនធឺណិត​បាន​ទស្សនា ព្រម​ទាំង​ចំណាំ​របស់​​កម្មវិធី​អ៊ីនធឺណិត។ ចំណាំ៖ សិទ្ធិ​នេះ​​មិន​អាច​ត្រូវ​បាន​អនុវត្ត​ដោយ​កម្មវិធី​អ៊ីនធឺណិត​ភាគី​ទីបី ឬ​កម្មវិធី​ដែល​មាន​សមត្ថភាព​រុករក​បណ្ដាញ។"</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"សរសេរ​ចំណាំ និង​ប្រវត្តិ​បណ្ដាញ"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"ឲ្យ​កម្មវិធី​កែ​ប្រវត្តិ​កម្មវិធី​អ៊ីនធឺណិត ឬ​ចំណាំ​ដែល​មាន​ក្នុង​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក។ វា​អាច​ឲ្យ​កម្មវិធី​លុប ឬ​កែ​​ទិន្នន័យ​កម្មវិធី​អ៊ីនធឺណិត។ ចំណាំ៖ សិទ្ធិ​នេះ​​អាច​កត់​សម្គាល់​ថា​ត្រូវ​បាន​អនុវត្ត​ដោយ​កម្មវិធី​អ៊ីនធឺណិត​ភាគី​ទី​បី ឬ​កម្មវិធី​ផ្សេង​ដែល​មាន​សមត្ថភាព​​រុករក​បណ្ដាញ។"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"ឲ្យ​កម្មវិធី​កែ​ប្រវត្តិ ឬ​ចំណាំ​របស់​កម្មវិធី​អ៊ីនធឺណិត​ដែល​បាន​រក្សាទុក​ក្នុង​ទូរស័ព្ទ​​របស់​អ្នក។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា​ដើម្បី​លុប ឬ​កែ​ទិន្នន័យ​នៃ​កម្មវិធី​អ៊ីនធឺណិត​របស់​អ្នក។ ចំណាំ៖ សិទ្ធិ​នេះ​អាច​ត្រូវ​បាន​បង្ខំ​ដោយ​កម្មវិធី​អ៊ីនធឺណិត​​ភាគី​ទីបី​ ឬ​​កម្មវិធី​ផ្សេង​ដែល​មាន​សមត្ថភាព​រុករក​បណ្ដាញ។ស"</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"កំណត់​សំឡេង​រោទ៍"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"ឲ្យ​កម្មវិធី​កំណត់​​សំឡេង​រោទ៍​ក្នុង​កម្មវិធី​នាឡិកា​រោទ៍​បាន​ដំឡើង។​ កម្មវិធី​នាឡិកា​រោទ៍​មួយ​ចំនួន​អាច​មិន​អនុវត្ត​លក្ខណៈ​នេះ។"</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"បន្ថែម​សារ​ជា​សំឡេង"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"ឲ្យ​កម្មវិធី​បន្ថែម​សារ​ទៅ​ប្រអប់​ទទួល​សារ​ជា​សំឡេង​របស់​អ្នក។"</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"កែ​សិទ្ធិ​ទីតាំង​ភូមិសាស្ត្រ​របស់​​កម្មវិធី​អ៊ីនធឺណិត"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"ឲ្យ​កម្មវិធី​កែ​​សិទ្ធិ​ទី​តាំង​ភូមិសាស្ត្រ​របស់​កម្មវិធី​អ៊ីនធឺណិត។ កម្មវិធី​ព្យាបាទ​អាច​ប្រើ​វា ដើម្បី​ឲ្យ​ផ្ញើ​ព័ត៌មាន​ទីតាំង​ទៅ​តំបន់បណ្ដាញ​ដោយ​បំពាន។"</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"ផ្ទៀងផ្ទាត់​កញ្ចប់"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"ឲ្យ​កម្មវិធី​ផ្ទៀងផ្ទាត់​កញ្ចប់​ដែល​អាច​ដំឡើង​បាន។"</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"ចង​ទៅ​កម្មវិធី​ផ្ទៀងផ្ទាត់​កញ្ចប់"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"ឲ្យ​ម្ចាស់​ស្នើ​កម្មវិធី​ផ្ទៀងផ្ទាត់​កញ្ចប់។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"ចូល​ដំណើរការ​ច្រក​ស៊េរី"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"អនុញ្ញាត​ឱ្យ​ចូល​ដំណើរ​ការ​ទៅ​កាន់​ច្រក​សៀរៀល​ដោយ​ប្រើ SerialManager API ។"</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"ចូល​ដំណើរការ​ក្រុមហ៊ុន​ផ្ដល់​មាតិកា​ខាង​ក្រៅ"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"ឲ្យ​ម្ចាស់​ចូល​ដំណើរការ​ក្រុមហ៊ុន​ផ្ដល់​មាតិកា​ពី​សែល។ មិន​គួរ​ចាំបាច់​សម្រាប់​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"ការ​ពារ​បច្ចុប្បន្នភាព​ឧបករណ៍​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"ឲ្យ​ម្ចាស់​ផ្ដល់​ព័ត៌មាន​ទៅ​ប្រព័ន្ធ​អំពី​ពេលវេលា​ដែល​ល្អ​សម្រាប់​ចាប់ផ្ដើម​ឡើងវិញ​ដោយ​គ្មាន​អន្តរកម្ម ដើម្បី​ធ្វើ​បច្ចុប្បន្ន​ឧបករណ៍។"</string>
-    <string name="save_password_message" msgid="767344687139195790">"តើ​អ្នក​ចង់​ឲ្យ​កម្មវិធី​អ៊ីនធឺណិត​ចងចាំ​ពាក្យ​សម្ងាត់​នេះ?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"មិនមែន​ឥឡូវ"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"ចងចាំ"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"កុំ"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"អ្នក​មិន​មាន​សិទ្ធិ ដើម្បី​បើក​ទំព័រ​នេះ។"</string>
-    <string name="text_copied" msgid="4985729524670131385">"បាន​ចម្លង​អត្ថបទ​ទៅ​ក្ដារ​តម្បៀត​ខ្ទាស់។"</string>
-    <string name="more_item_label" msgid="4650918923083320495">"ច្រើន​ទៀត"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"ម៉ឺនុយ +"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"ដកឃ្លា"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"enter"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"លុប"</string>
-    <string name="search_go" msgid="8298016669822141719">"ស្វែងរក"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"ស្វែងរក"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"ស្វែងរក​សំណួរ"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"សម្អាត​សំណួរ"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"ដាក់​​​ស្នើ​សំណួរ"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"ការស្វែងរក​សំឡេង"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"បើក​ការ​រក​មើល ដោយ​ប៉ះ?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>ចង់​បើក​ការ​រុករ​ក​ដោយ​ប៉ះ។ ពេល​រុករក​ដោយ​ប៉ះ​ត្រូវ​បាន​បើក​​ អ្នក​អាច​ស្ដាប់​ឮ​ ឬ​ឃើញ​ការ​ពណ៌នា​អ្វី​ដែល​នៅ​ក្រោម​ម្រាមដៃ​របស់​អ្នក​​ ឬ​អនុវត្ត​កាយវិការ​ដើម្បី​មាន​អន្តរកម្ម​ជា​មួយ​កុំព្យូទ័រ​បន្ទះ។"</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ចង់​បើក​ការ​រុករ​ក​ដោយ​ប៉ះ។ ពេល​រុករក​ដោយ​ប៉ះ​ត្រូវ​បាន​បើក​​ អ្នក​អាច​ស្ដាប់​ឮ​ ឬ​ឃើញ​ការ​ពណ៌នា​អ្វី​ដែល​នៅ​ក្រោម​ម្រាមដៃ​របស់​អ្នក​​ ឬ​អនុវត្ត​កាយវិការ​ដើម្បី​មាន​អន្តរកម្ម​ជា​មួយ​ទូរស័ព្ទ។"</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"1 ខែ​មុន"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"មុន​ពេល ១ ខែ​មុន"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"១ វិនាទី​មុន"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> វិនាទី​មុន"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"១ នាទី​មុន"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> នាទី​​មុន"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"១ ម៉ោង​មុន"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> ម៉ោង​មុន"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"<xliff:g id="COUNT">%d</xliff:g> ថ្ងៃ​ចុងក្រោយ"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"ខែ​មុន"</string>
-    <string name="older" msgid="5211975022815554840">"ចាស់​ជាង"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"ម្សិលមិញ"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> ថ្ងៃ​មុន"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"ក្នុង​រយៈ​ពេល ១ វិនាទី"</item>
-    <item quantity="other" msgid="1241926116443974687">"ក្នុង​រយៈ​ពេល <xliff:g id="COUNT">%d</xliff:g> វិនាទី"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"ក្នុង​រយៈពេល ១ នាទី"</item>
-    <item quantity="other" msgid="3330713936399448749">"រយៈពេល <xliff:g id="COUNT">%d</xliff:g> នាទី"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"រយៈពេល ១ ម៉ោង"</item>
-    <item quantity="other" msgid="547290677353727389">"រយៈពេល <xliff:g id="COUNT">%d</xliff:g> ម៉ោង"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"ថ្ងៃស្អែក"</item>
-    <item quantity="other" msgid="5109449375100953247">"រយៈពេល <xliff:g id="COUNT">%d</xliff:g> ថ្ងៃ"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"១ វិនាទី​មុន"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> វិនាទី​មុន"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"១ នាទី​មុន"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> នាទី​​មុន"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"១ ម៉ោង​មុន"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> ម៉ោង​មុន"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"ម្សិលមិញ"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> ថ្ងៃ​​មុន"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"ក្នុង​ពេល​ 1 វិនាទី"</item>
-    <item quantity="other" msgid="5495880108825805108">"ក្នុង​ពេល <xliff:g id="COUNT">%d</xliff:g> វិនាទី"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"ក្នុង​ពេល 1 នាទី"</item>
-    <item quantity="other" msgid="4216113292706568726">"នៅ​រយៈពេល <xliff:g id="COUNT">%d</xliff:g> នាទី"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"ក្នុង​រយៈ​ពេល ១ ម៉ោង"</item>
-    <item quantity="other" msgid="3705373766798013406">"ក្នុង​រយៈ​ពេល <xliff:g id="COUNT">%d</xliff:g> ម៉ោង"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"ថ្ងៃស្អែក"</item>
-    <item quantity="other" msgid="2973062968038355991">"ក្នុង​រយៈ​ពេល <xliff:g id="COUNT">%d</xliff:g> ថ្ងៃ"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"នៅ <xliff:g id="DATE">%s</xliff:g>"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"នៅ​ម៉ោង <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"ក្នុង​ឆ្នាំ <xliff:g id="YEAR">%s</xliff:g>"</string>
-    <string name="day" msgid="8144195776058119424">"ថ្ងៃ"</string>
-    <string name="days" msgid="4774547661021344602">"​ថ្ងៃ"</string>
-    <string name="hour" msgid="2126771916426189481">"ម៉ោង"</string>
-    <string name="hours" msgid="894424005266852993">"ម៉ោង"</string>
-    <string name="minute" msgid="9148878657703769868">"នាទី"</string>
-    <string name="minutes" msgid="5646001005827034509">"នាទី"</string>
-    <string name="second" msgid="3184235808021478">"វិនាទី"</string>
-    <string name="seconds" msgid="3161515347216589235">"វិនាទី"</string>
-    <string name="week" msgid="5617961537173061583">"សប្ដាហ៍"</string>
-    <string name="weeks" msgid="6509623834583944518">"សប្ដាហ៍"</string>
-    <string name="year" msgid="4001118221013892076">"ឆ្នាំ"</string>
-    <string name="years" msgid="6881577717993213522">"ឆ្នាំ"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 វិនាទី"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> វិនាទី"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"១ នាទី"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> នាទី"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"១ ម៉ោង"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> ម៉ោង"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"បញ្ហា​វីដេអូ"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"វីដេអូ​នេះ​មិន​ត្រឹមត្រូវ​សម្រាប់​​ចរន្ត​ចូល​ឧបករណ៍​នេះ។"</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"មិន​អាច​ចាក់​វីដេអូ​នេះ។"</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"យល់​ព្រម"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"រសៀល"</string>
-    <string name="Noon" msgid="3342127745230013127">"រសៀល"</string>
-    <string name="midnight" msgid="7166259508850457595">"កណ្ដាលអធ្រាត្រ"</string>
-    <string name="Midnight" msgid="5630806906897892201">"កណ្ដាល​អធ្រាត្រ"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"ជ្រើស​ទាំងអស់"</string>
-    <string name="cut" msgid="3092569408438626261">"កាត់"</string>
-    <string name="copy" msgid="2681946229533511987">"ចម្លង"</string>
-    <string name="paste" msgid="5629880836805036433">"បិទ​ភ្ជាប់"</string>
-    <string name="replace" msgid="5781686059063148930">"ជំនួស..."</string>
-    <string name="delete" msgid="6098684844021697789">"លុប"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"ចម្លង URL"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"ជ្រើស​អត្ថបទ"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"ការ​ជ្រើស​អត្ថបទ"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"បន្ថែម​ទៅ​វចនានុក្រម"</string>
-    <string name="deleteText" msgid="6979668428458199034">"លុប"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"សកម្មភាព​អត្ថបទ"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"អស់​ទំហំ​ផ្ទុក"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"មុខងារ​ប្រព័ន្ធ​មួយ​ចំនួន​អាច​មិន​ដំណើរការ"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> កំពុង​ដំណើរការ"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"ប៉ះ​ ដើម្បី​មើល​ព័ត៌មាន​បន្ថែម ឬ​បញ្ឈប់​កម្មវិធី។"</string>
-    <string name="ok" msgid="5970060430562524910">"យល់​ព្រម"</string>
-    <string name="cancel" msgid="6442560571259935130">"បោះ​បង់"</string>
-    <string name="yes" msgid="5362982303337969312">"យល់​ព្រម"</string>
-    <string name="no" msgid="5141531044935541497">"បោះ​បង់"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"ប្រយ័ត្ន"</string>
-    <string name="loading" msgid="7933681260296021180">"កំពុង​ផ្ទុក..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"បើក"</string>
-    <string name="capital_off" msgid="6815870386972805832">"បិទ"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"បញ្ចប់​សកម្មភាព​ដោយ​ប្រើ"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"ប្រើ​តាម​លំនាំដើម​សម្រាប់​សកម្មភាព​នេះ។"</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"សម្អាត​លំនាំដើម​ក្នុង​ការកំណត់​ប្រព័ន្ធ &gt; កម្មវិធី &gt; ទាញ​យក។"</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"ជ្រើស​សកម្មភាព"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"ជ្រើស​កម្មវិធី​សម្រាប់​ឧបករណ៍​យូអេសប៊ី"</string>
-    <string name="noApplications" msgid="2991814273936504689">"គ្មាន​កម្មវិធី​អាច​អនុវត្ត​សកម្មភាព​នេះ។"</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"ដោយ​បរាជ័យ <xliff:g id="APPLICATION">%1$s</xliff:g> បាន​បញ្ឈប់។"</string>
-    <string name="aerr_process" msgid="4507058997035697579">"ជា​អកុសល ដំណើរការ <xliff:g id="PROCESS">%1$s</xliff:g> បាន​បញ្ឈប់។"</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> មិន​ឆ្លើយតប។\n\nតើ​អ្នក​ចង់​បិទ​វា​ឬ?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"សកម្មភាព <xliff:g id="ACTIVITY">%1$s</xliff:g> មិន​ឆ្លើយតប។\n\nតើ​អ្នក​ចង់​បិទ​វា?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> មិន​ឆ្លើយតប។ តើ​អ្នក​ចង់​បិទ​វា?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"ដំណើរការ <xliff:g id="PROCESS">%1$s</xliff:g> មិន​ឆ្លើយតប។ \n\nតើ​អ្នក​ចង់​បិទ​វា​ឬ?"</string>
-    <string name="force_close" msgid="8346072094521265605">"យល់​ព្រម"</string>
-    <string name="report" msgid="4060218260984795706">"របាយការណ៍"</string>
-    <string name="wait" msgid="7147118217226317732">"រង់ចាំ"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"ទំព័រ​ក្លាយ​ជា​មិន​ឆ្លើយតប។\n\nតើ​អ្នក​​ចង់​បិទ​វា?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"បាន​ប្ដូរ​ទិស​កម្មវិធី"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> ឥឡូវ​កំពុង​ដំណើរការ។"</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ត្រូវ​បាន​ចាប់ផ្ដើម​ពី​ដំបូង។"</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"មាត្រដ្ឋាន"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"បង្ហាញ​ជា​និច្ច"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"បើក​វា​ឡើងវិញ​ក្នុង​ការ​កំណត់​ប្រព័ន្ធ &gt; កម្មវិធី &gt; ទាញ​យក។"</string>
-    <string name="smv_application" msgid="3307209192155442829">"កម្មវិធី <xliff:g id="APPLICATION">%1$s</xliff:g> (ដំណើរការ <xliff:g id="PROCESS">%2$s</xliff:g>) បាន​បំពាន​គោលនយោបាយ​របៀប​តឹងរ៉ឹង​អនុវត្ត​ដោយ​ខ្លួន​​ឯង។"</string>
-    <string name="smv_process" msgid="5120397012047462446">"ដំណើរការ <xliff:g id="PROCESS">%1$s</xliff:g> បាន​បំពាន​គោលនយោបាយ​​របៀប​​តឹង​រឹង​​​បង្ខំ​ដោយ​ខ្លួន​ឯង"</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android កំពុង​ធ្វើ​បច្ចុប្បន្នភាព..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"ធ្វើ​ឲ្យ​កម្មវិធី​ប្រសើរ​ឡើង <xliff:g id="NUMBER_0">%1$d</xliff:g> នៃ <xliff:g id="NUMBER_1">%2$d</xliff:g> ។"</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"ចាប់ផ្ដើម​កម្មវិធី។"</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"បញ្ចប់​ការ​ចាប់ផ្ដើម។"</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> កំពុង​ដំណើរការ"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"ប៉ះ​ ដើម្បី​ប្ដូរ​​​កម្មវិធី"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"ប្ដូរ​កម្មវិធី?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"កម្មវិធី​ផ្សេង​កំពុង​ដំណើរការ​រួច​ហើយ​ ដែល​តម្រូវ​ឲ្យ​បញ្ឈប់​មុន​ពេល​អ្នក​អាច​ចាប់ផ្ដើម​ថ្មី។"</string>
-    <string name="old_app_action" msgid="493129172238566282">"ត្រឡប់​ទៅ <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"កុំ​ចាប់ផ្ដើម​កម្មវិធី​ថ្មី។"</string>
-    <string name="new_app_action" msgid="5472756926945440706">"ចាប់ផ្ដើម <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"បញ្ឈប់​កម្មវិធី​ចាស់​ដោយ​មិន​រក្សាទុក"</string>
-    <string name="sendText" msgid="5209874571959469142">"ជ្រើស​សកម្មភាព​សម្រាប់​អត្ថបទ"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"កម្រិត​សំឡេង​រោទ៍"</string>
-    <string name="volume_music" msgid="5421651157138628171">"កម្រិត​សំឡេង​មេឌៀ"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"ចាក់​តាម​ប៊្លូធូស"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"កំណត់​សំឡេង​រោទ៍​ស្ងាត់"</string>
-    <string name="volume_call" msgid="3941680041282788711">"កម្រិត​សំឡេង​ហៅ​ចូល"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"កម្រិត​សំឡេង​ហៅ​ចូល​តាម​ប៊្លូធូស"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"កម្រិត​សំឡេង​រោទ៍"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"កម្រិត​សំឡេង​ការ​ជូន​ដំណឹង"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"កម្រិត​សំឡេង"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"កម្រិត​សំឡេង​ប៊្លូធូស"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"កម្រិត​សំឡេង​រោទ៍"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"កម្រិត​សំឡេង​ហៅ"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"កម្រិត​សំឡេង​មេឌៀ"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"កម្រិត​សំឡេង​ការ​ជូន​ដំណឹង"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"សំឡេង​រោទ៍​លំនាំដើម"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"សំឡេង​រោទ៍​លំនាំដើម (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"គ្មាន"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"សំឡេង​រោទ៍"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"សំឡេង​រោទ៍​មិន​ស្គាល់"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"មាន​បណ្ដាញ​វ៉ាយហ្វាយ"</item>
-    <item quantity="other" msgid="4192424489168397386">"មាន​បណ្ដាញ​វ៉ាយហ្វាយ"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"បើក​បណ្ដាញ​វ៉ាយហ្វាយ​​ដែល​មាន"</item>
-    <item quantity="other" msgid="7915895323644292768">"មាន​បណ្ដាញ​វ៉ាយហ្វាយ​បើក"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"ចូល​បណ្ដាញ​វ៉ាយហ្វាយ"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"ចូល​ក្នុង​បណ្ដាញ"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"មិន​​អាច​តភ្ជាប់​វ៉ាយហ្វាយ"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" មាន​ការ​តភ្ជាប់​អ៊ីនធឺណិត​មិន​ល្អ។"</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"វ៉ាយហ្វាយ​ផ្ទាល់"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"ចាប់ផ្ដើម​វ៉ាយហ្វាយ​ដោយ​ផ្ទាល់។ វា​នឹង​បិទ​វ៉ាយហ្វាយ ។"</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"មិន​អាច​ចាប់ផ្ដើម​វ៉ាយហ្វា​ដោយ​ផ្ទាល់។"</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"បើក​​វ៉ាយហ្វាយ​ផ្ទាល់"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"ប៉ះ​ ដើម្បី​កំណត់"</string>
-    <string name="accept" msgid="1645267259272829559">"ទទួល"</string>
-    <string name="decline" msgid="2112225451706137894">"បដិសេធ"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"បា​ន​ផ្ញើ​លិខិត​អញ្ជើញ"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"អញ្ជើញ​ឲ្យ​ភ្ជាប់"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"ពី៖"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"ទៅ៖"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"បញ្ចូល​កូដ PIN ដែល​ទាមទារ៖"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"កូដ PIN ៖"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"កុំព្យូទ័រ​បន្ទះ​នឹង​ផ្ដាច់​ជា​បណ្ដោះអាសន្ន​ពី​វ៉ាយហ្វាយ ខណៈ​ដែល​វា​ភ្ជាប់​ <xliff:g id="DEVICE_NAME">%1$s</xliff:g>"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"ទូរស័ព្ទ​នឹង​​ផ្ដាច់​ពី​វ៉ាយហ្វាយ​ខណៈ​ដែល​វា​ត្រូវ​បាន​តភ្ជាប់​ទៅ <xliff:g id="DEVICE_NAME">%1$s</xliff:g>"</string>
-    <string name="select_character" msgid="3365550120617701745">"បញ្ចូល​តួអក្សរ"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"ផ្ញើ​សារ SMS"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; កំពុង​ផ្ញើ​សារ​ SMS មួយ​ចំនួន​ធំ។ តើ​អ្នក​ចង់​ឲ្យ​​កម្មវិធី​នេះ​បន្ត​ផ្ញើ​សារ?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"អនុញ្ញាត"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"បដិសេធ"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; ចង់​ផ្ញើ​សារ​ទៅ &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt; ។"</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457"><font fgcolor="#ffffb060">"នេះ​អាច​កាត់​លុយ"</font>" លើ​គណនី​ចល័ត​របស់​អ្នក។"</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"វា​នឹង​គិត​ថ្លៃ​សេវាកម្ម​លើ​គណនី​ចល័ត​របស់​អ្នក។"</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"ផ្ញើ"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"បោះ​បង់"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"ចងចាំ​ជម្រើស​របស់​ខ្ញុំ"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"អ្នក​អាច​ប្ដូរ​វា​ពេល​ក្រោយ​ក្នុង​ការ​កំណត់ &gt; កម្មវិធី"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"អនុញ្ញាត​ជា​និច្ច"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"កុំ​អនុញ្ញាត"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"បាន​ដក​ស៊ីម​កាត​ចេញ"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"បណ្ដាញ​ចល័ត​នឹង​ប្រើ​លែង​បាន​រហូត​ដល់​អ្នក​ចាប់ផ្ដើម​ជា​មួយ​ស៊ីម​កាត​ដែល​បា​បញ្ចូល​ត្រឹមត្រូវ។"</string>
-    <string name="sim_done_button" msgid="827949989369963775">"រួចរាល់"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"បាន​បន្ថែម​ស៊ីម​កាត"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"ចាប់ផ្ដើម​ឧបករណ៍​របស់​អ្នក​ឡើង​វិញ ដើម្បី​ចូល​ដំណើរការ​បណ្ដាញ​ចល័ត។"</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"ចាប់ផ្ដើម​ឡើងវិញ"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"កំណត់​ម៉ោង"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"កំណត់​កាល​បរិច្ឆេទ"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"កំណត់"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"រួចរាល់"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"ថ្មី៖ "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"បាន​ផ្ដល់​ដោយ <xliff:g id="APP_NAME">%1$s</xliff:g> ។"</string>
-    <string name="no_permissions" msgid="7283357728219338112">"មិន​ទាមទារ​សិទ្ធិ"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"វា​អាច​កាត់​លុយ​​អ្នក"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"ឧបករណ៍​យូអេសប៊ី"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"បាន​ភ្ជាប់​យូអេសប៊ី"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"អ្នក​បាន​ភ្ជាប់​កុំព្យូទ័រ​របស់​អ្នក​តាម​​យូអេសប៊ី។ ប៉ះ ប៊ូតុង​ខាង​ក្រោម បើ​អ្នក​ចង់​ចម្លង​ឯកសារ​រវាង​កុំព្យូទ័រ និង​ឧបករណ៍​ផ្ទុក Android របស់​អ្នក។"</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"អ្នក​បាន​ភ្ជាប់​កុំព្យូទ័រ​របស់​អ្នក​តាម​យូអេសប៊ី។ ប៉ះ ប៊ូតុង​ខាង​ក្រោម​ប្រសិន​បើ​អ្នក​ចង់​ចម្លង​ឯកសារ​រវាង​កុំព្យូទ័រ​របស់​អ្នក និង​កាត​អេសឌី​នៃ Android របស់​អ្នក។"</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"បើក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"មាន​បញ្ហា​ក្នុង​ការ​ផ្អាក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​សម្រាប់​ជា​ឧបករណ៍​ផ្ទុក។"</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"មាន​បញ្ហា​ក្នុង​ការ​ប្រើ​កាត​អេសឌី​សម្រាប់​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"បាន​ភ្ជាប់​យូអេសប៊ី"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"ប៉ះ ដើម្បី​ចម្លង​ឯកសារ​ទៅ/ពី​កុំព្យូទ័រ​របស់​​អ្នក។"</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"បិទ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"ប៉ះ ដើម្បី​បិទ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​កំពុង​ប្រើ"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"មុន​ពេល​បិទ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី ផ្ដាច់ (\"បដិសេធ\") ឧបករណ៍​ផ្ទុក​យូអេសប៊ី Android របស់​អ្នក​ពី​កុំព្យូទ័រ។"</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"មុន​ពេល​បិទ​​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី ផ្ដាច់ (\"បដិសេធ\") កាត​អេសឌី Android របស់​អ្នក​ពី​កុំព្យូទ័រ។"</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"បិទ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"មាន​បញ្ហា​ក្នុង​ការ​បិទ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។ ពិនិត្យ​ថា​អ្នក​បាន​ផ្ដាច់​យូអេសប៊ី បន្ទាប់​មក​ព្យាយាម​ម្ដង​ទៀត។"</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"បើក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"បើ​អ្នក​បើក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី កម្មវិធី​មួយ​ចំនួន​ដែល​អ្នក​កំពុង​ប្រើ​នឹង​បញ្ឈប់ ហើយ​អាច​ប្រើ​លែង​បាន​រហូត​ដល់​អ្នក​បិទ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"ប្រតិបត្តិការ​យូអេសប៊ី​​បរាជ័យ"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"យល់ព្រម"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"បាន​តភ្ជាប់​ជា​ឧបករណ៍​​ផ្ទុក"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"បាន​ភ្ជាប់​ជា​ម៉ាស៊ីន​ថត"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"បាន​ភ្ជាប់​ជា​កម្មវិធី​ដំឡើង"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"បាន​ភ្ជាប់​ឧបករណ៍​យូអេសប៊ី"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"ប៉ះ ដើម្បី​មើល​ជម្រើស​យូអេសប៊ី​ផ្សេង។"</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"ធ្វើ​ទ្រង់ទ្រាយ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"ធ្វើ​ទ្រង់ទ្រាយ​កាត​អេសឌី?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"ឯកសារ​ទាំងអស់​ដែល​បាន​រក្សាទុក​ក្នុង​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​នឹង​ត្រូវ​បាន​លុប។ សកម្មភាព​នេះ​មិន​អាច​ត្រឡប់​វិញ​បាន​ទេ!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"ទិន្នន័យ​ទាំងអស់​ក្នុង​កាត​របស់​អ្នក​នឹង​បាត់បង់។"</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"ធ្វើ​ទ្រង់ទ្រាយ"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"បាន​ភ្ជាប់​ការ​កែ​កំហុស​យូអេសប៊ី"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"ប៉ះ ដើម្បី​បិទ​ការ​កែ​កំហុស​យូអេសប៊ី។"</string>
-    <string name="select_input_method" msgid="4653387336791222978">"ជ្រើស​វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"រៀបចំ​វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"ក្ដារ​ចុច​​ពិតប្រាកដ"</string>
-    <string name="hardware" msgid="7517821086888990278">"ផ្នែក​រឹង"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"ជ្រើស​ប្លង់​ក្ដារ​ចុច"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"ប៉ះ ​ដើម្បី​ជ្រើស​ប្លង់​​ក្ដារចុច។"</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"បេក្ខជន"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"រៀបចំ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"រៀបចំ​កាត​អេសឌី"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"ពិនិត្យ​រក​កំហុស។"</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​ទទេ"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"ការ​​អេសឌី​ទទេ"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​ទទេ ឬ​មាន​ប្រព័ន្ធ​ឯកសារ​ដែល​មិន​បា​គាំទ្រ។"</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"កាត​អេសឌី​ទទេ ឬ​មាន​ប្រព័ន្ធ​ឯកសារ​មិន​បាន​គាំទ្រ។"</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​ខូច"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"កាត​អេសឌី​ខូច"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​ខូច។ ព្យាយាម​ធ្វើ​ទ្រង់ទ្រាយ​វា​ឡើងវិញ។"</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"កាត​អេសឌី​ខូច។ ព្យាយាម​ធ្វើ​ទ្រង់ទ្រាយ​វា​ឡើងវិញ។"</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"បាន​ដក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​ដោយ​មិន​រំពឹង​ទុក"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"បាន​ដក​កាត​អេសឌី​ដោយ​មិន​រំពឹង​ទុក"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"ផ្ដាច់​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​មុន​នឹង​​លុប​​​ជៀសវាង​ការ​បាត់​ទិន្នន័យ។"</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"ផ្ដាច់​កាត​អេសឌី​មុន​នឹង​ដក់​ចេញ ជៀសវាង​បាត់បង់​ទិន្នន័យ។"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"ឧបករណ៍​យូអេសប៊ី​មាន​សុវត្ថិភាព ដើម្បី​ដក"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"មាន​សុវត្ថិភាព​ក្នុង​ការ​ដក​កាត​អេសឌី"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"អ្នក​អាច​ដក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​ដោយ​សុវត្ថិភាព។"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"អ្នក​អាច​ដក​កាត​អេសឌី​ដោយ​មាន​សុវត្ថិភាព។"</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"បាន​លុប​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"បាន​ដក​កាត​អេសឌី"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"បាន​ដក​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។ បញ្ចូល​មេឌៀ​ថ្មី។"</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"បាន​ដក​កាត​អេសឌី។ បញ្ចូល​ថ្មី​មួយ។"</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"រក​មិន​ឃើញ​សកម្មភាព​ផ្គូផ្គង។"</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"ធ្វើ​បច្ចុប្បន្ន​សមាសធាតុ​ស្ថិតិ​ការ​ប្រើ"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"ឲ្យ​កម្មវិធី​កែ​ស្ថិតិ​ប្រើ​សមាសភាគ​ដែល​បា​ន​ប្រមូល។​​ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​ធម្មតា​ទេ។"</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"ចម្លង​មាតិកា"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"ឲ្យ​កម្មវិធី​ដក​សេវាកម្ម​នៃ​កម្មវិធី​ផ្ទុក​​លំនាំដើម ដើម្បី​ចម្លង​មាតិកា។​ មិន​សម្រាប់​ប្រើ​ដោយ​កម្មវិធី​លំនាំដើម។"</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"នាំ​ផ្លូវ​លទ្ធផល​មេឌៀ"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"ឲ្យ​កម្មវិធី​នាំ​ផ្លូវ​លទ្ធផល​មេឌៀ​ទៅ​ឧបករណ៍​​ខាង​ក្រៅ​ផ្សេង។"</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"ចូល​ដំណើរការ​ឧបករណ៍​ផ្ទុក​សុវត្ថិភាព"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"ឲ្យ​កម្មវិធី​ចូល​​ការ​ផ្ទុក​មាន​សុវត្ថិភាព keguard ។"</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"ពិនិត្យ​ការ​បង្ហាញ និង​លាក់​ការ​ការពារ"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"ឲ្យ​កម្មវិធី​គ្រប់គ្រង keguard ។"</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"ប៉ះ​ពីរ​ដង ​​ដើម្បី​គ្រប់គ្រង​ការ​ពង្រីក"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"មិន​អាច​បន្ថែម​ធាតុ​ក្រាហ្វិក។"</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"ទៅ"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"ស្វែងរក"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"ផ្ញើ"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"បន្ទាប់"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"រួចរាល់"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"មុន"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"អនុវត្ត"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"ចុច​លេខ​\nដោយ​ប្រើ <xliff:g id="NUMBER">%s</xliff:g>"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"បង្កើត​ទំនាក់ទំនង\nដោយ​ប្រើ <xliff:g id="NUMBER">%s</xliff:g>"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"កម្មវិធី​មួយ ឬ​ច្រើន​ដូច​ខាង​ក្រោម​ស្នើ​សិទ្ធិ ដើម្បី​ចូល​គណនី​របស់​អ្នក​ឥឡូវ និង​ពេល​អនាគត។"</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"តើ​អ្នក​ចង់​អនុញ្ញាត​សំណើ​នេះ?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"ស្នើ​ចូល"</string>
-    <string name="allow" msgid="7225948811296386551">"អនុញ្ញាត"</string>
-    <string name="deny" msgid="2081879885755434506">"បដិសេធ"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"បាន​ស្នើ​សិទ្ធិ"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"បាន​ស្នើ​សិទ្ធិ\nសម្រាប់​គណនី <xliff:g id="ACCOUNT">%s</xliff:g> ។"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"ធ្វើ​សម​កាល​កម្ម"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"ភាព​ងាយស្រួល"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"ផ្ទាំង​រូបភាព"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"ប្ដូរ​ផ្ទាំង​រូបភាព"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"កម្មវិធី​ស្ដាប់​ការ​ជូន​ដំណឹង"</string>
-    <string name="vpn_title" msgid="19615213552042827">"បាន​ធ្វើ​ឲ្យ VPN សកម្ម"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"បាន​ធ្វើ​ឲ្យ VPN សកម្ម​ដោយ <xliff:g id="APP">%s</xliff:g>"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"ប៉ះ ដើម្បី​គ្រប់គ្រង​បណ្ដាញ។"</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"បាន​តភ្ជាប់​ទៅ <xliff:g id="SESSION">%s</xliff:g> ។ ប៉ះ ដើម្បី​គ្រប់គ្រង​បណ្ដាញ។"</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"បើក​ការ​តភ្ជាប់ VPN ជា​និច្ច..។"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"ភ្ជាប់ VPN ជា​និច្ច"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"បើក​កំហុស VPN ជា​និច្ច"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"ប៉ះ ​ដើម្បី​កំណត់​រចនា​សម្ព័ន្ធ"</string>
-    <string name="upload_file" msgid="2897957172366730416">"ជ្រើស​​ឯកសារ"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"គ្មាន​ឯកសារ​បាន​ជ្រើស"</string>
-    <string name="reset" msgid="2448168080964209908">"កំណត់​ឡើងវិញ"</string>
-    <string name="submit" msgid="1602335572089911941">"ដាក់​ស្នើ"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"បាន​បើក​របៀប​រថយន្ត"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"ប៉ះ​ ដើម្បី​ចេញ​ពី​របៀប​រថយន្ត​។"</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"​ភ្ជាប់ ឬ​ hotspot សកម្ម"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"ប៉ះ​ ដើម្បី​រៀបចំ។"</string>
-    <string name="back_button_label" msgid="2300470004503343439">"ថយក្រោយ"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"បន្ទាប់"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"រំលង"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"ការ​ប្រើ​ទិន្នន័យ​ចល័ត​ខ្ពស់"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"ប៉ះ​ ដើម្បី​​ស្វែងយល់​បន្ថែម​អំពី​ការ​ប្រើ​​​ទិន្នន័យ​ចល័ត​។"</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"លើក​ដែន​កំណត់​ទិន្នន័យ​ចល័ត"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"ប៉ះ ដើម្បី​ស្វែងយល់​បន្ថែម​អំពី​ការ​ប្រើ​ទិន្នន័យ​ចល័ត។"</string>
-    <string name="no_matches" msgid="8129421908915840737">"គ្មាន​ការ​ផ្គូផ្គង"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"រក​ក្នុង​ទំព័រ"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"១ ប្រកួត"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="INDEX">%d</xliff:g> នៃ <xliff:g id="TOTAL">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"រួចរាល់"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"កំពុង​ផ្ដាច់​ឧបករណ៍​យូអេសប៊ី..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"កំពុង​ផ្ដាច់​កាត​អេសឌី..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"កំពុង​លុប​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី..."</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"កំពុង​លុប​កាត​អេសឌី..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"មិន​​អាច​លុប​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"មិន​អាច​លុប​កាត​អេសឌី។"</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"បាន​ដក​កាត​អេសឌី​មុន​នឹង​ផ្ដាច់។"</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"បច្ចុប្បន្ន​កំពុង​ពិនិត្យ​ឧបករណ៍​ផ្ទុក​យូអេសប៊ី។"</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"បច្ចុប្បន្ន​កំពុង​ពិនិត្យ​មើល​កាត​អេសឌី។"</string>
-    <string name="media_removed" msgid="7001526905057952097">"បាន​ដក​កាត​អេសឌី។"</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី​បច្ចុប្បន្ន​កំពុង​ប្រើ​ដោយ​កុំព្យូទ័រ។"</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"បច្ចុប្បន្ន​កាត​អេសឌី​កំពុង​ប្រើ​ដោយ​កុំព្យូទ័រ"</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"មិន​ស្គាល់​ស្ថានភាព​មេឌៀ​ខាង​ក្រៅ។"</string>
-    <string name="share" msgid="1778686618230011964">"ចែក​រំលែក"</string>
-    <string name="find" msgid="4808270900322985960">"រក"</string>
-    <string name="websearch" msgid="4337157977400211589">"ស្វែងរក​តាម​បណ្ដាញ"</string>
-    <string name="find_next" msgid="5742124618942193978">"រក​បន្ទាប់"</string>
-    <string name="find_previous" msgid="2196723669388360506">"រក​ពី​មុន"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"ស្នើ​ទីតាំង​ពី <xliff:g id="NAME">%s</xliff:g>"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"សំណើ​ទីតាំង"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"បាន​ស្នើ​ដោយ <xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>)"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"បាទ/ចាស"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"ទេ"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"លុប​​លើស​ដែន​កំណត់"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"មាន​ធាតុ​បាន​លុប <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> សម្រាប់ <xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g> គណនី <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g> ។ តើ​អ្នក​ចង់​ធ្វើ​អ្វី​ខ្លះ​?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"លុប​ធាតុ"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"មិន​ធ្វើ​ការ​លុប​វិញ"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"មិន​ធ្វើអ្វី​ទេ​ឥឡូវ"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"ជ្រើស​គណនី"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"បន្ថែម​គណនី​ថ្មី"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"បន្ថែម​គណនី"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"បង្កើន"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"បន្ថយ"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> ប៉ះ និង​សង្កត់។"</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"រុញ​ឡើងលើ ដើម្បី​បង្កើន និង​ចុះក្រោម​ដើម្បី​បន្ថយ។"</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"បង្កើន​នាទី"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"បន្ថយ​នាទី"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"បង្កើន​ម៉ោង"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"បន្ថយ​ម៉ោង"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"កំណត់​ PM"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"កំណត់ AM"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"បង្កើន​ខែ"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"បន្ថយ​ខែ"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"បង្កើន​ថ្ងៃ"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"បន្ថយ​ថ្ងៃ"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"បង្កើន​​ឆ្នាំ"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"បន្ថយ​ឆ្នាំ"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"បោះ​បង់"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"លុប"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"រួចរាល់"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"ប្ដូរ​របៀប"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Enter"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"ជ្រើស​កម្មវិធី"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"ចែករំលែក​ជា​មួយ"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"ចែក​រំលែក​ជា​មួយ <xliff:g id="APPLICATION_NAME">%s</xliff:g>"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"គ្រប់គ្រង​ការ​រុញ។ ប៉ះ &amp; សង្កត់។"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"រុញ​ឡើង​លើ​ដើម្បី <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"រុញ​ចុះក្រោម​សម្រាប់ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"រុញ​ទៅ​ឆ្វេង​ដើម្បី <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"រុញ​​ទៅ​ស្ដាំ​ដើម្បី <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"ដោះ​​សោ"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"ម៉ាស៊ីន​ថត"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"ស្ងាត់"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"បើក​សំឡេង"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"ស្វែងរក"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"អូស​ ដើម្បី​ដោះ​សោ។"</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"ដោត​កាស​ដើម្បី​ស្ដាប់​ពាក្យ​សម្ងាត់​បាន​និយាយ។"</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"Dot."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"រកមើល​ទៅ​ដើម"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"រកមើល​ឡើងលើ"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"ជម្រើស​ច្រើន​ទៀត"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"កាត​អេសឌី"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"ឧបករណ៍​ផ្ទុក​យូអេសប៊ី"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"កែសម្រួល"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"ការព្រមាន​ប្រើ​ទិន្នន័យ"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"ប៉ះ ដើម្បី​មើល​ការ​ប្រើ និង​ការ​កំណត់។"</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"បាន​បិទ​ទិន្នន័យ 2G​-3G"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"បាន​បិទ​ទិន្នន័យ 4G"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"បាន​បិទ​ទិន្នន័យ​ចល័ត"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"បាន​បិទ​ទិន្នន័យ​វ៉ាយហ្វាយ"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"ប៉ះ​​ ដើម្បី​បើក​។"</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"លើស​ដែន​កំណត់​ទិន្នន័យ 2G​-3G"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"បាន​លើស​ដែន​កំណត់​ទិន្នន័យ 4G"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"បាន​លើស​ដែន​កំណត់​ទិន្នន័យ​ចល័ត"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"លើស​ដែន​កំណត់​ទិន្នន័យ​វ៉ាយហ្វាយ"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> លើ​ដែន​កំណត់​បាន​បញ្ជាក់។"</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"បាន​ដាក់​កម្រិត​ទិន្នន័យ​ផ្ទៃ​ខាង​ក្រោយ"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"ប៉ះ ដើម្បី​លុប​ការ​ដាក់កម្រិត។"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"វិញ្ញាបនបត្រ​សុវត្ថិភាព"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"វិញ្ញាបនបត្រ​នេះ​​​​ត្រឹមត្រូវ​។"</string>
-    <string name="issued_to" msgid="454239480274921032">"បាន​ចេញ​ឲ្យ​៖"</string>
-    <string name="common_name" msgid="2233209299434172646">"ឈ្មោះ​ទូទៅ៖"</string>
-    <string name="org_name" msgid="6973561190762085236">"ស្ថាប័ន៖"</string>
-    <string name="org_unit" msgid="7265981890422070383">"ផ្នែក​នៃ​ស្ថាប័ន៖"</string>
-    <string name="issued_by" msgid="2647584988057481566">"បាន​ចេញ​ដោយ​៖"</string>
-    <string name="validity_period" msgid="8818886137545983110">"សុពលភាព៖"</string>
-    <string name="issued_on" msgid="5895017404361397232">"ចេញ​នៅ៖"</string>
-    <string name="expires_on" msgid="3676242949915959821">"ផុត​កំណត់​នៅ៖"</string>
-    <string name="serial_number" msgid="758814067660862493">"លេខ​ស៊េរី៖"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"ស្នាម​ម្រាមដៃ​៖"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"ស្នាម​ម្រាមដៃ SHA​-256 ​៖"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"ស្នាម​ម្រាម​ដៃ SHA-1 ៖"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"មើល​ទាំងអស់"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"ជ្រើស​សកម្មភាព"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"ចែករំលែក​ជា​មួយ"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"ឧបករណ៍​ជាប់​សោ​។"</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"កំពុង​ផ្ញើ..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"ចាប់ផ្ដើម​កម្មវិធី​អ៊ីនធឺណិត?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"ទទួល​ការ​ហៅ​?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"ជា​និច្ច"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"តែ​ម្ដង"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"កុំព្យូទ័រ​បន្ទះ"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"ទូរស័ព្ទ"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"កាស"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"ភ្ជាប់​អូប៉ាល័រ"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"ប្រព័ន្ធ"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"សំឡេង​ប៊្លូធូស"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"បង្ហាញ​បណ្ដាញ​ឥត​ខ្សែ"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"រួចរាល់"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"លទ្ធផល​មេឌៀ"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"កំពុង​វិភាគ​រក…"</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"កំពុង​​​ភ្ជាប់​…"</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"ទំនេរ"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"មិន​ទំនេរ"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"កំពុង​ប្រើ"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"អេក្រង់​ជាប់"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"អេក្រង់ HDMI"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"#<xliff:g id="ID">%1$d</xliff:g> ត្រួត​គ្នា"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", សុវត្ថិភាព"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"បាន​ភ្ជាប់​ការ​បង្ហាញ​បណ្ដាញ​ឥត​ខ្សែ"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"អេក្រង់​នេះ​បង្ហាញ​លើ​ឧបករណ៍​ផ្សេង"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"ផ្ដាច់"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"ការ​ហៅ​ពេល​អាសន្ន"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"ភ្លេច​​លំនាំ"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"លំនាំ​មិន​ត្រឹមត្រូវ"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"កូដ PIN មិន​ត្រឹមត្រូវ"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER">%1$d</xliff:g> វិនាទី។"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"គូរ​លំនាំ​របស់​អ្នក"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"បញ្ចូល​កូដ PIN ស៊ីម​កាត"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"បញ្ចូល​​កូដ PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"បញ្ចូល​ពាក្យ​សម្ងាត់"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"ឥឡូវ​ស៊ីមកាត​ត្រូវ​បាន​បិទ។ បញ្ចូល​កូដ PUK ដើម្បី​បន្ត។ ចំពោះ​ព័ត៌មាន​លម្អិត​ទាក់ទង​ក្រុមហ៊ុន​បញ្ជូន​របស់​អ្នក។"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"បញ្ចូល​កូដ PIN ដែល​ចង់​បាន"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"បញ្ជាក់​កូដ PIN ដែល​ចង់​បាន"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"កំពុង​ដោះ​សោ​​ស៊ីម​កាត..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"កូដ PIN មិន​ត្រឹមត្រូវ។"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"បញ្ចូល​កូដ PIN ដែល​មាន​ពី ៤ ដល់ ៨ លេខ។"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"កូដ PUK គួរ​តែ​មាន​​ ៨ លេខ ឬ​​ច្រើន​ជាង​នេះ។"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"បញ្ចូល​កូដ PUK ម្ដង​ទៀត។ ការ​ព្យាយាម​ដដែល​ច្រើន​ដឹង​នឹង​បិទ​ស៊ីម​កាត​ជា​អចិន្ត្រៃយ៍។"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"កូដ PIN មិន​ដូច​គ្នា"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"ព្យាយាម​លំនាំ​ច្រើន​ពេក"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"ដើម្បី​ដោះ​សោ ចូល​ក្នុង​គណនី Google ។"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"ឈ្មោះ​អ្នក​ប្រើ (អ៊ី​ម៉ែ​ល​)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"ពាក្យសម្ងាត់"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"ចូល"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"ឈ្មោះ​អ្នកប្រើ ឬ​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ។"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"ភ្លេច​ឈ្មោះ​អ្នកប្រើ ឬ​ពាក្យ​សម្ងាត់​របស់​អ្នក?\nមើល "<b>"google.com/accounts/recovery"</b>" ។"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"កំពុង​ពិនិត្យ​មើល​គណនី..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"អ្នក​បាន​បញ្ចូល​កូដ PIN របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"អ្នក​បាន​បញ្ចូល​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។\n\nព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"អ្នក​បាន​​គូរ​លំនាំ​ដោះ​សោ​របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។\n\nព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​​កុំព្យូទ័រ​បន្ទះ​​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើន​ជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង កុំព្យូទ័រ​បន្ទះ​​នឹង​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោងចក្រ ហើយ​ទិន្នន័យ​អ្នកប្រើ​នឹង​បាត់បង់។"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​ទូរស័ព្ទ​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើន​ជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង ទូរស័ព្ទ​នឹង​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោងចក្រ ហើយ​ទិន្នន័យ​អ្នកប្រើ​នឹង​បាត់បង់។"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​កុំព្យូទ័រ​បន្ទះ​មិន​ត្រឹមត្រូវ​ចំនួន​ <xliff:g id="NUMBER">%d</xliff:g> ដង។ កុំព្យូទ័រ​បន្ទះ​នឹង​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោងចក្រ"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​ទូរស័ព្ទ​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER">%d</xliff:g> ដង។ ឥឡូវ​ទូរស័ព្ទ​នឹង​កំណត់​ទៅ​លំនាំ​ដើម​ដូច​ចេញ​ពី​រោងចក្រ។"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​សោ​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម <xliff:g id="NUMBER_1">%d</xliff:g> ដង​មិន​ជោគជ័យ អ្នក​នឹង​ត្រូវ​បាន​ស្នើ​ឲ្យ​ដោះ​សោ​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក ដោយ​ប្រើ​គណនី​អ៊ីមែល។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_2">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​​សោ​របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើនជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង អ្នក​នឹង​ត្រូវ​បាន​​ស្នើ​ឲ្យ​ដោះ​សោ​ទូរស័ព្ទ​របស់​អ្នក​ដោយ​ប្រើ​គណនី​អ៊ីមែល។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_2">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"លុប​ចេញ"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"បង្កើន​កម្រិត​សំឡេង​ខាង​លើ​កម្រិត​បាន​​ណែនាំ?\nស្ដាប់​កម្រិត​សំឡេង​ខ្ពស់​រយៈ​ពេល​យូរ​អាច​ឲ្យ​ខូច​ត្រចៀក។"</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"សង្កត់​ដោយ​ម្រាមដៃ​ពីរ ដើម្បី​បើក​ភាព​ងាយស្រួល។"</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"បាន​បើក​មធ្យោបាយ​ងាយស្រួល​។"</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"បាន​បោះបង់​ភាព​ងាយស្រួល។"</string>
-    <string name="user_switched" msgid="3768006783166984410">"អ្នក​ប្រើ​បច្ចុប្បន្ន <xliff:g id="NAME">%1$s</xliff:g> ។"</string>
-    <string name="owner_name" msgid="2716755460376028154">"ម្ចាស់"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"កំហុស"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"កម្មវិធី​នេះ​មិន​គាំទ្រ​គណនី​សម្រាប់​ប្រវត្តិរូប​ដែល​បាន​ដាក់​កម្រិត​ទេ"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"រក​មិន​ឃើញ​កម្មវិធី​ ដើម្បី​គ្រប់គ្រង​សកម្មភាព​នេះ"</string>
-    <string name="revoke" msgid="5404479185228271586">"ដកហូត"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"Letter"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"លិខិត​រដ្ឋាភិបាល"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"Legal"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Junior Legal"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Ledger"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Tabloid"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"បាន​បោះ​បង់"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"កំហុស​ក្នុង​ការ​សរសេរ​មាតិកា"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"បញ្ចូល​​កូដ PIN"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"កូដ PIN បច្ចុប្បន្ន"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"កូដ PIN ថ្មី"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"បញ្ជាក់​កូដ PIN ថ្មី"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"បង្កើត​កូដ PIN សម្រាប់​កែ​ការ​ដាក់​កម្រិត"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"កូដ PIN មិន​ដូច​គ្នា។ ព្យាយាម​ម្ដង​ទៀត។"</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"កូដ​ PIN ខ្លី​ពេក។ ត្រូវ​តែ​មាន​យ៉ាង​ហោច​ណាស់ ៤ តួ។"</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"លេខ​កូដ​ PIN មិន​ត្រឹមត្រូវ។ ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល ១ វិនាទី។"</item>
-    <item quantity="other" msgid="8030607343223287654">"លេខ​កូដ​ PIN មិន​ត្រឹមត្រូវ។ ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="COUNT">%d</xliff:g> វិនាទី​។"</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"អូស​គែម​អេក្រង់ ដើម្បី​បង្ហាញ​របារ"</string>
-</resources>
diff --git a/core/res/res/values-ko/strings.xml b/core/res/res/values-ko/strings.xml
index 0900446..1a0b2d9 100644
--- a/core/res/res/values-ko/strings.xml
+++ b/core/res/res/values-ko/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g>초 후에 다시 시도하세요."</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"나중에 다시 시도"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"전체화면을 종료하려면 위에서 아래로 스와이프"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"전체화면을 종료하려면 위에서 아래로 스와이프"</string>
 </resources>
diff --git a/core/res/res/values-lo-rLA/strings.xml b/core/res/res/values-lo-rLA/strings.xml
index 46e2fa9..003b3f9 100644
--- a/core/res/res/values-lo-rLA/strings.xml
+++ b/core/res/res/values-lo-rLA/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"ລອງໃໝ່ໃນອີກ <xliff:g id="COUNT">%d</xliff:g> ວິນາທີ"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"ລອງໃໝ່ອີກຄັ້ງໃນພາຍຫລັງ."</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"ປັດລົງຈາກເທິງສຸດເພື່ອອກຈາກໂໝດເຕັມໜ້າຈໍ"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"ປັດລົງມາຈາກທາງເທິງເພື່ອອອກຈາກໂໝດເຕັມໜ້າຈໍ."</string>
 </resources>
diff --git a/core/res/res/values-lo/strings.xml b/core/res/res/values-lo/strings.xml
deleted file mode 100644
index 68ece0f..0000000
--- a/core/res/res/values-lo/strings.xml
+++ /dev/null
@@ -1,1587 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;ບໍ່ມີຊື່&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(ບໍ່ມີເບີໂທລະສັບ)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(ບໍ່ຮູ້)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"ຂໍ້ຄວາມສຽງ"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"ມີບັນຫາໃນການເຊື່ອມຕໍ່ ຫຼືລະຫັດ MMI ບໍ່ຖືກຕ້ອງ."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"ການດຳເນີນການຖືກຈຳກັດເປັນ ຈຳກັດໝາຍເລກໂທອອກເທົ່ານັ້ນ."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"ບໍລິການຖືກເປີດໄວ້ແລ້ວ."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"ບໍລິການຖືກເປີດໃຊ້ສຳລັບ:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"ບໍ​ລິ​ການ​ໄດ້​ຖືກ​ປິດແລ້ວ."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"ການລົງທະບຽນສຳເລັດແລ້ວ."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"ການລຶບສົມບູນແລ້ວ."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"ລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI ສຳເລັດ."</string>
-    <string name="badPin" msgid="9015277645546710014">"ລະຫັດ PIN ເກົ່າທີ່ທ່ານພິມນັ້ນບໍ່ຖືກຕ້ອງ."</string>
-    <string name="badPuk" msgid="5487257647081132201">"ລະຫັດ PUK ທີ່ທ່ານພິມນັ້ນບໍ່ຖືກຕ້ອງ."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"ລະຫັດ PIN ທີ່ທ່ານພິມໄປນັ້ນບໍ່ກົງກັນ."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"ພິມລະຫັດ PIN ທີ່ມີ 4 ຫາ 8 ໂຕເລກ."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"ພິມລະຫັດ PUK ທີ່ມີ 8 ໂຕເລກ ຫຼືຫຼາຍກວ່ານັ້ນ."</string>
-    <string name="needPuk" msgid="919668385956251611">"ຊິມກາດຂອງທ່ານຖືກລັອກດ້ວຍລະຫັດ PUK. ໃຫ້ພິມລະຫັດ PUK ເພື່ອປົດລັອກມັນ."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"ພິມ PUK2 ເພື່ອປົດລັອກ SIM card."</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"ໝາຍເລກຜູ່ໂທເຂົ້າ"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"ໝາຍເລກຜູ່ໂທອອກ"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"ການໂອນສາຍ"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"ສາຍຊ້ອນ"</string>
-    <string name="BaMmi" msgid="455193067926770581">"ການລະງັບການໂທ"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"ການປ່ຽນລະຫັດຜ່ານ"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"ການປ່ຽນແປງ PIN"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"ສະແດງໝາຍເລກທີ່ໂທ"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"ເບີໂທທີ່ຖືກຈຳກັດ"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"ການໂທສາມສາຍ"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"ປະຕິເສດສາຍທີ່ບໍ່ຕ້ອງການຮັບ"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"ການສົ່ງໝາຍເລກທີ່ໂທ"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"ຫ້າມລົບກວນ"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"ໝາຍເລກຜູ່ໂທຖືກຕັ້ງຄ່າເລີ່ມຕົ້ນໃຫ້ຖືກຈຳກັດ. ການໂທຄັ້ງຕໍ່ໄປ: ຖືກຈຳກັດ"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"ໝາຍເລກຜູ່ໂທ ໄດ້ຮັບການຕັ້ງຄ່າເລີ່ມຕົ້ນເປັນ ຖືກຈຳກັດ. ການໂທຄັ້ງຕໍ່ໄປ: ບໍ່ຖືກຈຳກັດ."</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"Caller ID ໂດຍເລີ່ມຕົ້ນຖືກປັບໃຫ້ບໍ່ມີການປິດກັ້ນ. ການໂທຕໍ່ໄປ:ປິດກັ້ນ"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"ໝາຍເລກຜູ່ໂທ ໄດ້ຮັບການຕັ້ງຄ່າເລີ່ມຕົ້ນເປັນ ບໍ່ຖືກຈຳກັດ. ການໂທຄັ້ງຕໍ່ໄປ: ບໍ່ຖືກຈຳກັດ."</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"ບໍ່ໄດ້ເປີດໃຊ້ບໍລິການ."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"ທ່ານບໍ່ສາມາດປ່ຽນແປງການຕັ້ງຄ່າ Caller ID"</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"ປ່ຽນການເຂົ້າເຖິງທີ່ຖືກຈຳກັດແລ້ວ"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"ບໍລິການຂໍ້ມູນຖືກບລັອກ."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"ບໍລິການສຸກເສີນຖືກບລັອກ."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"ບໍລິການການໂທຖືກປິດກັ້ນໄວ້."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"ບໍລິການສຽງທັງໝົດຖືກບລັອກ."</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"ບໍລິການ SMS ຖືກບລັອກ."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"ບໍລິການ ຂໍ້ມູນ/ສຽງ ຖືກບລັອກ."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"ບໍລິການ ສຽງ/SMS ຖືກບລັອກ."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"ບໍລິການ ການໂທ/ອິນເຕີເນັດ/SMS ຖືກປິດກັ້ນໄວ້."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"ສຽງ"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"ຂໍ້ມູນ"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"ແຟັກ"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"ບໍ່ກົງກັນ"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"ຊິ້ງຂໍ້ມູນ"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"ແພັກເກັດ"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"ໂຕບອກການເຊື່ອມຕໍ່ກັບເຄືອຂ່າຍພາຍນອກເປີດຢູ່"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"ໂຕບອກການເຊື່ອມຕໍ່ກັບເຄືອຂ່າຍພາຍນອກປິດຢູ່"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"ໂຕບອກການເຊື່ອມຕໍ່ກັບເຄືອຂ່າຍພາຍນອກກະພິບ"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"ຢູ່ນອກເຂດໃກ້ຄຽງ"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"ດ້ານນອກຂອງອາຄານ"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"ໂຣມມິງ - ລະບົບທີ່ຕ້ອງການ"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"ໂຣມມິງ - ລະບົບທີ່ໃຊ້ໄດ້"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"ໂຣມມິງ - ຮຸ້ນສ່ວນພັນທະມິດ"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"ໂຣມມິງ - ຮຸ້ນສ່ວນພຣີມຽມ"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"ໂຣມມິງ - ຟັງຊັນບໍລິການເຕັມຮູບແບບ"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"ໂຣມມິງ - ຟັງຊັນບໍລິການບາງສ່ວນ"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"ເປີດໂຣມມິງແບນເນີ"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"ປິດໂຣມມິງແບນເນີ"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"ຊອກຫາບໍລິການ"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ບໍ່ຖືກສົ່ງຕໍ່"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> ຫຼັງຈາກ <xliff:g id="TIME_DELAY">{2}</xliff:g> ວິນາທີ"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ບໍ່ຖືກສົ່ງຕໍ່"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ບໍ່ຖືກສົ່ງຕໍ່"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"ລະຫັດຄຸນສົມບັດສຳເລັດແລ້ວ."</string>
-    <string name="fcError" msgid="3327560126588500777">"ເກີດບັນຫາການເຊື່ອມຕໍ່ ຫຼືລະຫັດການເຮັດວຽກບໍ່ຖືກຕ້ອງ."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"ຕົກລົງ"</string>
-    <string name="httpError" msgid="7956392511146698522">"ມີຂໍ້ຜິດພາດທາງເຄືອຂ່າຍ."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"ບໍ່ພົບ URL."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"ບໍ່ຮອງຮັບຮູບແບບການພິສູດຢືນຢັນຂອງເວັບໄຊ."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"ບໍ່ສາມາດພິສູດຢືນຢັນໄດ້."</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"ການພິສູດຢືນຢັນຜ່ານເຊີບເວີ Proxy ບໍ່ສຳເລັດ."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"ບໍ່ສາມາດເຊື່ອມຕໍ່ກັບເຊີບເວີໄດ້."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"ບໍ່ສາມາດສື່ສານກັບເຊີບເວີໄດ້. ກະລຸນາລອງໃໝ່ໃນພາຍຫຼັງ."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"ໝົດເວລາການເຊື່ອມຕໍ່ຫາເຊີບເວີ."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"ໜ້ານີ້ມີການປ່ຽນເສັ້ນທາງເຊີບເວີຫຼາຍເກີນໄປ."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"ບໍ່ຮອງຮັບໂປຣໂຕຄອນດັ່ງກ່າວ."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"ບໍ່ສາມາດເປີດໃຊ້ການເຊື່ອມຕໍ່ທີ່ປອດໄພໄດ້."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"ບໍ່ສາມາດເປີດໜ້າເວັບໄດ້ເນື່ອງຈາກ URL ບໍ່ຖືກຕ້ອງ."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"ບໍ່ສາມາດເຂົ້າເຖິງໄຟລ໌ໄດ້."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"ບໍ່ພົບໄຟລ໌ທີ່ຮ້ອງຂໍ."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"ມີການຮ້ອງຂໍຫຼາຍເກີນໄປ, ກະລຸນາລອງໃໝ່ພາຍຫຼັງ."</string>
-    <string name="notification_title" msgid="8967710025036163822">"ການເຂົ້າສູ່ລະບົບຂອງ <xliff:g id="ACCOUNT">%1$s</xliff:g> ຜິດພາດ"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"ການຊິ້ງຂໍ້ມູນ"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"ຊິ້ງຂໍ້ມູນ"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"ມີການລຶບ <xliff:g id="CONTENT_TYPE">%s</xliff:g> ຫຼາຍເກີນໄປ."</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ພື້ນທີ່ຈັດເກັບຂໍ້ມູນໃນແທັບເລັດເຕັມ. ລຶບບາງໄຟລ໌ອອກເພື່ອເພີ່ມພື້ນທີ່ຫວ່າງ."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"ພື້ນທີ່ໃນໂທລະສັບເຕັມແລ້ວ. ກະລຸນາລຶບບາງໄຟລ໌ອອກເພື່ອເພີ່ມພື້ນທີ່ຫວ່າງ."</string>
-    <string name="me" msgid="6545696007631404292">"ຂ້າພະເຈົ້າ"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ໂຕເລືອກແທັບເລັດ"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"ໂຕເລືອກໂທລະສັບ"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"ໂໝດປິດສຽງ"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"ເປີດລະບົບໄຮ້ສາຍ"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"ປິດ wireless"</string>
-    <string name="screen_lock" msgid="799094655496098153">"ລັອກໜ້າຈໍ"</string>
-    <string name="power_off" msgid="4266614107412865048">"ປິດເຄື່ອງ"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"ປິດສຽງຣິງໂທນ"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"ສັ່ນພ້ອມສຽງຣິງໂທນ"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"ເປີດສຽງໂທເຂົ້າແລ້ວ"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"ກຳລັງປິດລົງ..."</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"ແທັບເລັດຂອງທ່ານຈະຖືກປິດ."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"ໂທລະສັບຂອງທ່ານຈະຖືກປິດ."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"ທ່ານຕ້ອງການທີ່ຈະປິດບໍ່?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"ຣີບູດເຂົ້າ safe mode"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"ທ່ານຕ້ອງການຣີບູດເຂົ້າ safe mode ຫຼືບໍ່? ນີ້ຈະເປັນການປິດການເຮັດວຽກຂອງແອັບພລິເຄຊັນ ຈາກພາກສ່ວນທີສາມທັງໝົດທີ່ທ່ານໄດ້ຕິດຕັ້ງໄວ້. ແອັບພລິເຄຊັນເຫຼົ່ານັ້ນ ຈະກັບມາເຮັດວຽກໄດ້ອີກຫຼັງຈາກທ່ານຣີບູດອີກຄັ້ງ."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"ຫາກໍໃຊ້"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"ບໍ່ມີແອັບຯຫຼ້າສຸດ"</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ໂຕເລືອກແທັບເລັດ"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"ໂຕເລືອກໂທລະສັບ"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"ລັອກໜ້າຈໍ"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"ປິດ"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"ລາຍງານຂໍ້ຜິດພາດ"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"ໃຊ້ລາຍງານຂໍ້ບົກພ່ອງ"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"ນີ້ຈະເປັນການເກັບກຳຂໍ້ມູນກ່ຽວກັບ ສະຖານະປັດຈຸບັນຂອງອຸປະກອນທ່ານ ເພື່ອສົ່ງເປັນຂໍ້ຄວາມທາງອີເມວ. ມັນຈະໃຊ້ເວລາໜ້ອຍນຶ່ງ ໃນການເລີ່ມຕົ້ນການລາຍງານຂໍ້ຜິດພາດ ຈົນກວ່າຈະພ້ອມທີ່ຈະສົ່ງໄດ້, ກະລຸນາລໍຖ້າ."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"ໂໝດປິດສຽງ"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"ປິດສຽງແລ້ວ"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"ເປິດສຽງແລ້ວ"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"ໂໝດໃນຍົນ"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"ເປີດໂໝດຢູ່ໃນຍົນແລ້ວ"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"ປິດໂໝດໃນຍົນແລ້ວ"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"Safe mode"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"ລະບົບ Android"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"ບໍລິການທີ່ເຮັດໃຫ້ທ່ານເສຍເງິນ"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"ເຮັດສິ່ງທີ່ທ່ານຕ້ອງເສຍຄ່າໃຊ້ຈ່າຍ."</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"ຂໍ້ຄວາມຂອງທ່ານ"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"ອ່ານ ແລະຂຽນ SMS, ອີເມວ ແລະຂໍ້ຄວາມອື່ນໆຂອງທ່ານ."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"ຂໍ້ມູນສ່ວນໂຕຂອງທ່ານ"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"ເຂົ້າເຖິງຂໍ້ມູນກ່ຽວກັບທ່ານໂດຍກົງ, ບັນທຶກໄວ້ໃນບັດລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານ."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"ຂໍ້ມູນສັງຄົມຂອງທ່ານ"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"ເຂົ້າເຖິງຂໍ້ມູນກ່ຽວກັບລາຍຊື່ຜູ່ຕິດຕໍ່ ແລະການເຊື່ອມຕໍ່ທາງສັງຄົມຂອງທ່ານໂດຍກົງ."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"ສະຖານທີ່ຂອງທ່ານ"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"ຕິດຕາມສະຖານທີ່ທາງກາຍະພາບຂອງທ່ານ."</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"ການສື່ສານເຄືອຂ່າຍ"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"ເຂົ້າເຖິງຄຸນສົມບັດຕ່າງໆຂອງເຄືອຂ່າຍ."</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"Bluetooth"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"ເຂົ້າເຖິງອຸປະກອນ ແລະເຄືອຂ່າຍຜ່ານ Bluetooth."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"ການຕັ້ງຄ່າສຽງ"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"ປ່ຽນການຕັ້ງຄ່າສຽງ."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"ສົ່ງຜົນຕໍ່ແບັດເຕີຣີ"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"ໃຊ້ຄວາມສາມາດທີ່ເຮັດໃຫ້ພະລັງງານແບັດເຕີຣີຫຼຸດລົງຢ່າງໄວວາ."</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"ປະຕິທິນ"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"ເຂົ້າເຖິງປະຕິທິນ ແລະນັດໝາຍໂດຍກົງ."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"ອ່ານວັດຈະນານຸກົມຜູ່ໃຊ້"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"ອ່ານຄຳສັບໃນວັດຈະນານຸກົມຜູ່ໃຊ້."</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"ຂຽນວັດຈະນານຸກົມຜູ່ໃຊ້"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"ເພີ່ມຄຳສັບໃສ່ວັດຈະນານຸກົມຜູ່ໃຊ້."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"ບຸກມາກ ແລະປະຫວັດເວັບໄຊ"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"ເຂົ້ານຳໃຊ້ບຸກແລະປະຫວັດການທ່ອງເວັບໂດຍກົງ."</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"ໂມງປຸກ"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"ຕັ້ງໂມງປຸກ."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"ຂໍ້ຄວາມສຽງ"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"ເຂົ້າໃຊ້ຂໍ້ຄວາມສຽງໂດຍກົງ"</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"ໄມໂຄຣໂຟນ"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"ເຂົ້າເຖິງໄມໂຄຣໂຟນໂດຍກົງເພື່ອບັນທຶກສຽງ."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"ກ້ອງ"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"ເຂົ້າໃຊ້ກ້ອງຖ່າຍຮູບສຳລັບການຖ່າຍຮູບ ແລະວິດີໂອໂດຍກົງ."</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"ລັອກໜ້າຈໍ"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"ຄວາມສາມາດໃນການສົ່ງຜົນຕໍ່ພຶດຕິກຳ ຂອງການລັອກໜ້າຈໍໃນອຸປະກອນຂອງທ່ານ."</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"ເບິ່ງຂໍ້ມູນແອັບພລິເຄຊັນຂອງທ່ານ"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"ສາມາດສົ່ງຜົນຕໍ່ການເຮັດວຽກ ຂອງແອັບພລິເຄຊັນອື່ນໃນອຸປະກອນຂອງທ່ານ."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"ພາບພື້ນຫຼັງ"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"ປ່ຽນການຕັ້ງຄ່າພາບພື້ນຫຼັງຂອງອຸປະກອນ."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"ໂມງ"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"ປ່ຽນເວລາ ຫຼືເຂດເວລາໃນອຸປະກອນ."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"ແຖບສະຖານະ"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"ປ່ຽນການຕັ້ງຄ່າແຖບສະຖານະອຸປະກອນ."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"ຕັ້ງຄ່າການຊິ້ງຂໍ້ມູນ"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"ເຂົ້າໃຊ້ການຕັ້ງຄ່າການຊິ້ງຂໍ້ມູນ"</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"ບັນຊີຂອງທ່ານ"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"ເຂົ້າເຖິງບັນຊີທີ່ໃຊ້ໄດ້."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"ການຄວບຄຸມຮາດແວ"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"ເຂົ້າເຖິງຮາດແວຂອງຊຸດຫູຟັງໂດຍກົງ."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"ການໂທ"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"ຕິດຕາມ, ເກັບກຳ ແລະປະມວນຜົນການໂທລະສັບ."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"ເຄື່ອງມືລະບົບ"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"ການເຂົ້າເຖິງ ແລະການຄວບຄຸມລະບົບໃນລະດັບຕ່ຳ."</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"ເຄື່ອງມືການພັດທະນາ"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"ມີພຽງນັກພັດທະນາແອັບຯເທົ່ານັ້ນທີ່ຈະຕ້ອງການຄວາມສາມາດເຫຼົ່ານີ້."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"ສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ຂອງແອັບພລິເຄຊັນອື່ນ"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"ສົ່ງຜົນຕໍ່ສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ຂອງແອັບພລິເຄຊັນອື່ນ."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"ພື້ນທີ່ຈັດເກັບຂໍ້ມູນ"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"ການເຂົ້າເຖິງບ່ອນຈັດເກັບຂໍ້ມູນ USB."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"ການເຂົ້າເຖິງ SD card."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"ຄວາມສາມາດການຊ່ວຍເຂົ້າເຖິງ"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"ຄຸນສົມບັດທີ່ເທັກໂນໂລຢີຄວາມຊ່ວຍເຫຼືອສາມາດຮ້ອງຂໍໄດ້."</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"ດຶງຂໍ້ມູນເນື້ອຫາໃນໜ້າຈໍ"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"ກວດກາເນື້ອຫາຂອງໜ້າຈໍທີ່ທ່ານກຳລັງມີປະຕິສຳພັນນຳ."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"ເປີດໃຊ້ \"ການສຳຫຼວດໂດຍສຳພັດ\""</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"ລາຍການທີ່ສຳພັດຈະຖືກເວົ້າອອກມາ ແລະສາມາດສຳຫຼວດໜ້າຈໍໄດ້ດ້ວຍທ່າທາງ."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"ເປີດການເຂົ້າເຖິງເວັບທີ່ມີປະສິດທິພາບຫຼາຍຂຶ້ນ"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"ສະຄຣິບອາດຖືກຕິດຕັ້ງ ເພື່ອເຮັດໃຫ້ເນື້ອຫາແອັບຯເຂົ້າເຖິງໄດ້ຫຼາຍຂຶ້ນ."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"ຕິດຕາມ​ເບິ່ງ​ຂໍ້​ຄວາມ​ທີ່​ທ່ານ​ພິມ"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"ຮວມທັງຂໍ້ມູນສ່ວນໂຕເຊັ່ນ: ເລກບັດເຄຣດິດ ແລະລະຫັດຜ່ານ."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"ປິດການນນຳໃຊ້ ຫຼື ແກ້ໄຂແຖບສະຖານະ"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"ອະນຸຍາດໃຫ້ແອັບຯປິດການເຮັດວຽກຂອງແຖບສະຖານະ ຫຼືເພີ່ມ ແລະລຶບໄອຄອນລະບົບອອກໄດ້."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"ແຖບສະຖານະ"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"ອະນຸຍາດໃຫ້ແອັບຯເປັນແຖບສະຖານະ."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"ຫຍໍ້/ຂະຫຍາຍ ແຖບສະຖານະ"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"ອະນຸຍາດໃຫ້ແອັບຯ ຂະຫຍາຍ ຫຼືຫຍໍ້ແຖບສະຖານະ."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"ປ່ຽນເສັ້ນທາງການໂທອອກ"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"ອະນຸຍາດໃຫ້ແອັບຯປະມວນຜົນສາຍທີ່ໂທອອກ ແລະປ່ຽນໝາຍເລກທີ່ຈະໂທອອກ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດກວດສອບ, ໂອນສາຍ ຫຼືຂັດຂວາງບໍ່ໃຫ້ໂທອອກໄດ້."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"ຮັບຂໍ້ຄວາມສັ້ນ (SMS)"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"ອະນຸຍາດໃຫ້ແອັບຯຮັບ ແລະປະມວນຜົນຂໍ້ຄວາມ SMS. ນີ້ໝາຍຄວາມວ່າແອັບຯສາມາດຕິດຕາມ ຫຼືລຶບຂໍ້ຄວາມທີ່ສົ່ງເຂົ້າອຸປະກອນຂອງທ່ານ ໂດຍທີ່ບໍ່ສະແດງພວກມັນໃຫ້ທ່ານເຫັນ."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"ຮັບຂໍ້ຄວາມ (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"ອະນຸຍາດໃຫ້ແອັບຯ ຮັບແລະປະມວນຜົນຂໍ້ຄວາມ MMS. ນີ້ໝາຍຄວາມວ່າແອັບຯສາມາດຕິດຕາມ ຫຼືລຶບຂໍ້ຄວາມທີ່ສົ່ງເຂົ້າອຸປະກອນຂອງທ່ານ ໂດຍທີ່ບໍ່ສະແດງພວກມັນໃຫ້ທ່ານເຫັນ."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"ຮັບການກະຈາຍສັນຍານສຸກເສີນ"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"ອະນຸຍາດໃຫ້ແອັບຯຮັບ ແລະປະມວນຜົນການກະຈາຍຂໍ້ຄວາມດ່ວນໄດ້. ການອະນຸຍາດນີ້ຈະສາມາດນຳໃຊ້ໄດ້ໂດຍແອັບຯຂອງລະບົບເທົ່ານັ້ນ."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"ອ່ານຂໍ້ຄວາມກະຈາຍສັນຍານຂອງເສົາສັນຍານ"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"ອະນຸຍາດໃຫ້ແອັບຯ ສາມາດອ່ານຂໍ້ຄວາມແຈ້ງເຕືອນເຫດສຸກເສີນ ທີ່ໄດ້ຮັບໂດຍອຸປະກອນຂອງທ່ານ. ການແຈ້ງເຕືອນສຸກເສີນທີ່ມີໃຫ້ບໍລິການໃນບາງພື້ນທີ່ ເພື່ອແຈ້ງເຕືອນໃຫ້ທ່ານຮູ້ເຖິງສະຖານະການສຸກເສີນ. ແອັບພລິເຄຊັນທີ່ເປັນອັນຕະລາຍອາດລົບກວນປະສິດທິພາບ ຫຼືການດຳເນີນງານຂອງອຸປະກອນຂອງທ່ານ ເມື່ອໄດ້ການຮັບແຈ້ງເຕືອນສຸກເສີນຈາກສະຖານີມືຖື."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"ສົ່ງຂໍ້ຄວາມ SMS"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"ອະນຸຍາດໃຫ້ແອັບຯສົ່ງຂໍ້ຄວາມ SMS ໄດ້. ນີ້ອາດເຮັດໃຫ້ທ່ານເກີດການຄິດຄ່າບໍລິການທີ່ບໍ່ຄາດຄິດໄດ້. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດເຮັດໃຫ້ທ່ານເສຍເງິນຍ້ອນການສົ່ງຂໍ້ຄວາມໂດຍທີ່ທ່ານບໍ່ຮູ້ໂຕໄດ້."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"ສົ່ງກິດຈະກຳການຕອບສະໜອງຜ່ານທາງຂໍ້ຄວາມ"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"ອະນຸຍາດໃຫ້ແອັບຯສົ່ງຄຳຂໍ ໄປຫາແອັບຯຂໍ້ຄວາມອື່ນໆເພື່ອຈັດການ ກໍລະນີການຕອບດ້ວຍຂໍ້ຄວາມ ສຳລັບສາຍທີ່ໂທເຂົ້າມາ."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"ອ່ານຂໍ້ຄວາມຂອງທ່ານ (SMS ຫຼື MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"ອະນຸຍາດໃຫ້ແອັບຯອ່ານ SMS ທີ່ບັນທຶກໄວ້ໃນແທັບເລັດ ຫຼື SIM card ຂອງທ່ານ. ຄຸນສົມບັດນີ້ຈະເຮັດໃຫ້ແອັບຯສາມາດອ່ານຂໍ້ຄວາມ SMS ທັງໝົດໄດ້ ບໍ່ເນື້ອຫາຂອງມັນຈະແມ່ນຫຍັງກໍຕາມ."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານຂໍ້ຄວາມ SMS ທີ່ເກັບໄວ້ໃນໂທລະສັບຂອງທ່ານ ຫຼືຊິມກາດ. ນີ້ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານຂໍ້ຄວາມ SMS ທັງໝົດ, ໂດຍບໍ່ຄຳນຶງເຖິງເນື້ອຫາ ຫຼືຄວາມລັບ."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"ແກ້ໄຂຂໍ້ຄວາມຂອງທ່ານ (SMS ຫຼື MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"ອະນຸຍາດໃຫ້ແອັບຯຂຽນຂໍ້ຄວາມ SMS ທີ່ບັນທຶກໄວ້ໃນແທັບເລັດຂອງທ່ານ ຫຼືຊິມກາດຂອງທ່ານ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດລຶບຂໍ້ຄວາມຂອງທ່ານໄດ້."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"ອະນຸຍາດໃຫ້ແອັບຯ ຂຽນລົງໃສ່ຂໍ້ຄວາມ SMS ທີ່ເກັບໄວ້ໃນໂທລະສັບ ຫຼືຊິມກາດຂອງທ່ານ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດລຶບຂໍ້ຄວາມຂອງທ່ານໄດ້."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"ຮັບຂໍ້ຄວາມສັ້ນ (WAP)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"ອະນຸຍາດໃຫ້ແອັບຯຮັບ ແລະປະມວນຜົນຂໍ້ຄວາມ WAP. ການອະນຸຍາດນີ້ຮວມເຖິງຄວາມສາມາດໃນການກວດເບິ່ງ ແລະລຶບຂໍ້ຄວາມທີ່ສົ່ງແລ້ວ ໂດຍບໍ່ຕ້ອງສະແດງໃຫ້ທ່ານເຫັນ."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"ດຶງແອັບຯທີ່ເຮັດວຽກຢູ່ມາ"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"ອະນຸຍາດໃຫ້ແອັບຯດຶງຂໍ້ມູນກ່ຽວກັບການເຮັດວຽກໃນປັດຈຸບັນ ແລະຫາກໍຜ່ານມາ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດຄົ້ນພົບຂໍ້ມູນ ກ່ຽວກັບແອັບພລິເຄຊັນທີ່ໃຊ້ຢູ່ໃນອຸປະກອນໄດ້."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"ການຕອບໂຕ້ລະຫວ່າງຜູ່ໃຊ້"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"ອະນຸຍາດໃຫ້ແອັບຯດຳເນີນການ ສັ່ງງານຜ່ານຜູ່ໃຊ້ອື່ນໆໃນອຸປະກອນ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອລະເມີດການປ້ອງກັນລະຫວ່າງຜູ່ໃຊ້."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"ໃບອະນຸຍາດສະບັບເຕັມໃນການໂຕ້ຕອບລະຫວ່າງຜູ່ໃຊ້"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"ອະນຸຍາດທຸກການໂຕ້ຕອບທີ່ເປັນໄປໄດ້ລະຫວ່າງຜູ່ໃຊ້."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"ຈັດການຜູ່ໃຊ້"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"ອະນຸຍາດໃຫ້ແອັບຯຈັດການຜູ່ໃຊ້ໃນອຸປະກອນ, ຮວມທັງການເອີ້ນ, ການສ້າງ ແລະການລຶບຂໍ້ມູນ."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"ດຶງລາຍລະອຽດຂອງແອັບຯທີ່ກຳລັງເຮັດວຽກຢູ່"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"ອະນຸຍາດໃຫ້ແອັບຯດຶງຂໍ້ມູນຢ່າງລະອຽດ ກ່ຽວກັບການເຮັດວຽກໃນປັດຈຸບັນ ແລະຫາກໍຜ່ານມາ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດຄົ້ນພົບຂໍ້ມູນສ່ວນໂຕ ກ່ຽວກັບແອັບຯອື່ນໄດ້."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"ຮຽງລຳດັບແອັບຯທີ່ກຳລັງເຮັດວຽກຄືນໃໝ່"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"ອະນຸຍາດໃຫ້ແອັບຯຍ້າຍການເຮັດວຽກໄປໃສ່ດ້ານໜ້າ ແລະພື້ນຫຼັງໄດ້. ແອັບຯອາດຈະດຳເນີນການໂດຍບໍ່ຕ້ອງໃຫ້ທ່ານບອກ."</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"ຢຸດແອັບຯທີ່ເຮັດວຽກຢູ່"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"ອະນຸຍາດໃຫ້ແອັບຯລຶບການເຮັດວຽກ ແລະປິດແອັບຯຂອງວຽກເຫຼົ່ານັ້ນ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ສາມາດລົບກວນການເຮັດວຽກຂອງແອັບຯອື່ນໄດ້."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"ຈັດການສະແຕັກການເຄື່ອນໄຫວ"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"ອະ​ນຸ​ຍາດ​ໃຫ້ແອັບຯເພື່ອເພີ່ມ, ລຶບ ແລະ ແກ້ໄຂສະແຕັກການເຄື່ອນໄຫວ ທີ່ແອັບຯອື່ນໆເຮັດວຽກ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດລົບກວນການເຮັດວຽກຂອງແອັບຯອື່ນ."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"ເລີ່ມການເຮັດວຽກໃດນຶ່ງ"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"ອະນຸຍາດໃຫ້ແອັບຯເລີ່ມການເຮັດວຽກໃດກໍໄດ້ ບໍ່ວ່າການອະນຸຍາດ ຫຼືສະຖານະການສົ່ງອອກຈະເປັນແນວໃດກໍຕາມ."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"ຕັ້ງຄວາມເຂົ້າກັນໄດ້ຂອງໜ້າຈໍ"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມໂໝດຄວາມເຂົ້າກັນໄດ້ ຂອງໜ້າຈໍແອັບພລິເຄຊັນອື່ນໆ. ແອັບພລິເຄຊັນທີ່ເປັນອັນຕະລາຍ ອາດເຮັດໃຫ້ແອັບພລິເຄຊັນອື່ນເຮັດວຽກຜິດພາດໄດ້."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"ເປີດການເກັບຂໍ້ມູນເພື່ອແກ້ໄຂບັນຫາ"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"ອະນຸຍາດໃຫ້ແອັບຯ ເປີດການເກັບຂໍ້ມູນແກ້ບັນຫາສຳລັບແອັບຯອື່ນ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໃຊ້ຄຸນສົມບັດນີ້ເພື່ອປິດແອັບຯອື່ນ."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"ປ່ຽນການຕັ້ງຄ່າໜ້າຈໍຂອງລະບົບ"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນແປງການຕັ້ງຄ່າໃນປັດຈຸບັນ ເຊັ່ນ: ການຕັ້ງຄ່າທ້ອງຖິ່ນ ຫຼືຂະໜາດໂຕອັກສອນໂດຍຮວມ."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"ເປີດນຳໃຊ້ໂຫມດຂັບລົດ"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"ອະນຸຍາດໃຫ້ແອັບຯເປີດໃຊ້ໂໝດໃນລົດ."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"ປິດແອັບຯອື່ນໆ"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"ອະນຸຍາດໃຫ້ແອັບຯປິດໂປຣເຊສພື້ນຫຼັງຂອງແອັບຯອື່ນໄດ້. ນີ້ອາດເຮັດໃຫ້ແອັບຯອື່ນນັ້ນຢຸດການເຮັດວຽກໄປນຳ."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"ບັງຄັບໃຫ້ແອັບຯອື່ນຢຸດເຮັດວຽກ"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"ອະນຸຍາດໃຫ້ແອັບຯບັງຄັບປິດແອັບຯອື່ນໆໄດ້."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"ບັງຄັບປິດແອັບຯ"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"ອະນຸຍາດໃຫ້ແອັບຯບັງຄັບການເຮັດວຽກທີ່ຢູ່ດ້ານໜ້າປິດ ແລະກັບຄືນໄດ້. ແອັບພລິເຄຊັນທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"ດຶງຂໍ້ມູນສະຖານະພາຍໃນຂອງລະບົບ"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"ອະນຸຍາດໃຫ້ແອັບຯ ດຶງເອົາສະຖານະພາຍໃນຂອງລະບົບ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດຈະດຶງເອົາຂໍ້ມູນສ່ວນຕົວ ແລະຂໍ້ມູນຄວາມປອດໄພ ຫຼາກຫຼາຍປະເພດທີ່ບໍ່ຈຳເປັນຕໍ່ພວກມັນເລີຍ."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"ດຶງເອົາເນື້ອຫາໜ້າຈໍ"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"ອະນຸຍາດໃຫ້ແອັບຯດຶງຂໍ້ມູນເນື້ອຫາຂອງໜ້າຈໍທີ່ໃຊ້ຢູ່ໄດ້. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດດຶງຂໍ້ມູນທັງໝົດໃນໜ້າຈໍ ແລະກວດສອບຂໍ້ຄວາມທັງໝົດໃນນັ້ນໄດ້ ຍົກເວັ້ນລະຫັດຜ່ານ."</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"ປິດການຊ່ວຍການເຂົ້າເຖິງຊົ່ວຄາວ"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ເປີດໃຊ້ການຊ່ວຍເຂົ້າເຖິງແບບຊົ່ວຄາວໃນອຸປະກອນ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດເປີດໃຊ້ການຊ່ວຍເຂົ້າເຖິງ ໂດຍບໍ່ໄດ້ຮັບການຍິນຍອມຈາກຜູ່ໃຊ້."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"ດຶງເອົາຂໍ້ມູນໜ້າຈໍ"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ດຶງເອົາຂໍ້ມູນກ່ຽວກັບໜ້າຈໍຈາກໂຕຈັດການໜ້າຈໍ. ແອັບຯທີ່ບໍ່ປອດໄພອາດດຶງເອົາຂໍ້ມູນທີ່ໃຊ້ສຳລັບພາຍໃນລະບົບໄດ້."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"ກັ່ນຕອງເຫດການ"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ລົງທະບຽນການກັ່ນຕອງຂາເຂົ້າ ທີ່ກັ່ນຕອງການສົ່ງຂໍ້ມູນເຫດການຜູ່ໃຊ້ທັງໝົດ ກ່ອນທີ່ພວກມັນຈະຖືກເຜີຍແຜ່. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດຄວບຄຸມ UI ຂອງລະບົບໂດຍບໍ່ຕ້ອງໃຫ້ຜູ່ໃຊ້ຈັດການໄດ້."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"ຂະຫຍາຍການສະແດງຜົນ"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ສາມາດຂະຫຍາຍເນື້ອຫາທີ່ສະແດງຜົນໄດ້. ແອັບພລິເຄຊັນທີ່ເປັນອັນຕະລາຍ ອາດປ່ຽນເນື້ອຫາທີ່ສະແດງໃນລັກສະນະ ທີ່ເຮັດໃຫ້ບໍ່ສາມາດນຳໃຊ້ອຸປະກອນໄດ້."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"ປິດລົງບາງສ່ວນ"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"ກຳນົດໃຫ້ໂຕຈັດການກິດຈະກຳຢູ່ໃນສະຖານະປິດລະບົບ ໂດຍບໍ່ໄດ້ປິດລະບົບຢ່າງສົມບູນ."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"ຂັດຂວາງການສະລັບແອັບຯ"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"ປ້ອງກັນບໍ່ໃຫ້ຜູ່ໃຊ້ສະຫຼັບໄປຫາແອັບຯອື່ນ."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"ດຶງຂໍ້ມູນແອັບຯໃນປັດຈຸບັນ"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງດຶງຂໍ້ມູນສ່ວນໂຕ ກ່ຽວກັບແອັບພລິເຄຊັນ ແລະ ການບໍລິການປັດຈຸບັນໃນໜ້າຈໍໄດ້."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"ຕິດຕາມ ແລະຄວບຄຸມການເປີດໂຕຂອງແອັບຯທັງໝົດ"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"ອະນຸຍາດໃຫ້ແອັບຯ ຕິດຕາມ ແລະຄວບຄຸມວິທີທີ່ລະບົບເລີ່ມການເຮັດວຽກຕ່າງໆ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດເຮັດໃຫ້ລະບົບທັງໝົດເກີດອັນຕະລາຍໄດ້. ການກຳນົດສິດນີ້ຈຳເປັນສຳລັບການພັດທະນາເທົ່ານັ້ນ, ບໍ່ແມ່ນສຳລັບການນຳໃຊ້ທົ່ວໄປ."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"ສົ່ງການກະຈ່າຍຂໍ້ມູນທີ່ເອົາແພັກເກດອອກແລ້ວ"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"ອະນຸຍາດໃຫ້ແອັບຯສົ່ງການແຈ້ງເຕືອນວ່າ ແພັກເກັດຂອງແອັບຯດັ່ງໄດ້ລຶບອອກໄປແລ້ວ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອປິດການເຮັດວຽກຂອງແອັບຯອື່ນໆ ທີ່ກຳລັງເຮັດວຽກຢູ່."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"ສົ່ງການກະຈາຍ SMS ທີ່ໄດ້ຮັບ"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"ອະນຸຍາດໃຫ້ແອັບຯ ກະຈາຍສັນຍານການແຈ້ງເຕືອນວ່າຂໍ້ຄວາມ SMS ໄດ້ຮັບແລ້ວ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດຈະໃຊ້ສິ່ງນີ້ໃນການປອມແປງຂໍ້ຄວາມ SMS ຂາເຂົ້າ."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"ສົ່ງການກະຈາຍ WAP-PUSH ທີ່ໄດ້ຮັບ"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"ອະນຸຍາດໃຫ້ແອັບຯສົ່ງການແຈ້ງເຕືອນໃນເວລາທີ່ໄດ້ຮັບຂໍ້ມຄວາມ WAP PUSH. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດໃຊ້ການກະທຳນີ້ເພື່ອປອມການໄດ້ຮັບຂໍ້ຄວາມ MMS ຫຼືລັກປ່ຽນເນື້ອຫາຂອງໜ້າເວັບຕ່າງໆ ດ້ວຍສິ່ງອັນຕະລາຍທັງຫຼາຍຢ່າງງຽບໆ."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"ຈຳກັດຈຳນວນຂອງໂປຣເຊສທີ່ເຮັດວຽກຢູ່"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມຈຳນວນສູງສຸດ ຂອງໂປຣເຊສທີ່ຈະເຮັດວຽກ. ບໍ່ຄວນຖືກໃຊ້ກັບແອັບພລິເຄຊັນທົ່ວໄປ."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"ບັງຄັບໃຫ້ແອັບຯທີ່ເຮັດວຽກຢູ່ພື້ນຫຼັງປິດໂຕລົງ"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມວ່າການເຮັດວຽກໃດ ຄວນຈະຖືກປິດລົງ ຫຼັງຈາກທີ່ພວກມັນຖືກປ່ຽນໃຫ້ໄປເຮັດວຽກໃນຫຼັງລະບົບ. ບໍ່ຄວນໃຊ້ກັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"ອ່ານສະຖິຕິແບັດເຕີຣີ"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ອ່ານຂໍ້ມູນການນຳໃຊ້ປະຈຸບັນຂອງຖ່ານໃນລະດັບຕໍ່າ. ອາດຈະເຮັດໃຫ້ແອັບພລິເຄຊັນ ສາມາດຊອກຫາຂໍ້ມູນລະອຽດ ກ່ຽວກັບແອັບຯທີ່ທ່ານໃຊ້."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"ແກ້ໄຂສະຖິຕິແບັດເຕີຣີ"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂສະຖິຕິກ່ຽວກັບແບັດເຕີຣີທີ່ເກັບກຳມາໄດ້. ບໍ່ໃຊ້ສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"ດຶງຂໍ້ມູນສະຖິຕິການເຮັດວຽກຂອງແອັບຯ"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"ອະນຸຍາດໃຫ້ແອັບຯດຶງເອົາຂໍ້ມູນ ສະຖິຕິຂອງແອັບພລິເຄຊັນທີ່ໄດ້ເກັບກຳມາ. ບໍ່ໄດ້ໃຊ້ໃນແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"ແກ້ໄຂສະຖິຕິການເຮັດວຽກຂອງແອັບຯ"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂສະຖິຕິ ການເຮັດວຽກຂອງແອັບພລິເຄຊັນທີ່ເກັບກຳມາ. ແອັບຯທົ່ວໄປບໍ່ຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"ຄວບຄຸມການສຳຮອງ ແລະການກູ້ຂໍ້ມູນລະບົບ"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມກົນໄກການສຳຮອງ ແລະກູ້ຂໍ້ມູນຂອງລະບົບໄດ້. ແອັບຯທຳມະດາບໍ່ໄດ້ໃຊ້."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"ຢືນຢັນການສຳຮອງ ຫຼືການກູ້ຂໍ້ມູນເຕັມຮູບແບບ"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"ອະນຸຍາດໃຫ້ແອັບຯເປີດການເຮັດວຽກ ຂອງສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ສຳລັບຢືນຢັນການສຳຮອງຂໍ້ມູນເຕັມຮູບແບບ. ບໍ່ມີແອັບຯໃດຕ້ອງໃຊ້ຄຸນສົມບັດນີ້."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"ສະແດງໜ້າຈໍທີ່ບໍ່ໄດ້ຮັບອະນຸຍາດ"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"ອະນຸຍາດໃຫ້ແອັບຯສ້າງໜ້າຈໍສຳລັບການນຳໃຊ້ພາຍໃນລະບົບ. ແອັບຯທົ່ວໄປບໍ່ໄດ້ໃຊ້."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"ບັງແອັບຯອື່ນໆ"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"ອະນຸຍາດໃຫ້ແອັບຯເຮັດວຽກເທິງແອັບຯ ຫຼືບ່ອນອື່ນໆຂອງສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ ເຊິ່ງອາດລົບກວນການເຮັດວຽກຂອງສ່ວນຕິດຕໍ່ ໃນແອັບພລິເຄຊັນຕ່າງໆ ຫຼືປ່ຽນສິ່ງທີ່ທ່ານຄິດວ່າທ່ານເຫັນໃນແອັບພລິເຄຊັນອື່ນໆໄດ້."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"ແກ້ໄຂຄວາມໄວຂອງອະນິເມຊັນໂດຍຮວມ"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"ອະນຸຍາດໃຫ້ແອັບຯ ປ່ຽນຄວາມໄວອະນິເມຊັນທົ່ວໄປ (ອະນິເມຊັນໄວຂຶ້ນ ຫຼືຊ້າລົງ) ໄດ້ຕະຫຼອດເວລາ."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"ຈັດການໂທເຄນຂອງແອັບຯ"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"ອະນຸຍາດໃຫ້ແອັບຯສ້າງ ແລະຈັດການໂທເຄນຂອງຕົນເອງ ໂດຍຂ້າມການຈັດຕາມລຳດັບ Z ປົກກະຕິຂອງພວກມັນໄປ. ແອັບຯທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"ຄ້າງໜ້າຈໍ"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນຄ້າງໜ້າຈໍໄວ້ຊົ່ວຄາວ ສຳລັບການປ່ຽນເປັນແບບເຕັມໜ້າຈໍ."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"ກົດປຸ່ມແລະປຸ່ມຄວບຄຸມ"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"ອະນຸຍາດໃຫ້ແອັບຯສົ່ງກິດຈະກຳການປ້ອນຂໍ້ມູນຂອງມັນ (ເຊັ່ນ: ການກົດປຸ່ມ ແລະອື່ນໆ) ຫາແອັບຯອື່ນ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໃຊ້ຄຸນສົມບັດນີ້ ເພື່ອຄວບຄຸມແທັບເລັດໄດ້."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"ອະນຸຍາດໃຫ້ແອັບຯ ສົ່ງການປ້ອນຂໍ້ມູນຂອງຕົນເອງ (ການກົດປຸ່ມ ແລະອື່ນໆ.) ໃຫ້ແອັບຯອື່ນ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ສາມາດໃຊ້ສິ່ງນີ້ເພື່ອຍຶດເອົາການຄວບຄຸມໂທລະສັບທັງໝົດໄດ້."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"ບັນທຶກສິ່ງທີ່ທ່ານພິມ ແລະການກະທຳທີ່ທ່ານເຮັດ"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"ອະນຸຍາດໃຫ້ແອັບຯເບິ່ງການກົດປຸ່ມຂອງທ່ານ ເມື່ອມີປະຕິສຳພັນກັບແອັບຯອື່ນ (ເຊັ່ນ: ການພິມລະຫັດຜ່ານ). ແອັບຯທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"ເຊື່ອມໂຍງກັບວິທີປ້ອນຂໍ້ມູນ"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"ອະນຸຍາດໃຫ້ຜູ່ຖືຜູກກັບອິນເຕີເຟດລະດັບສູງສຸດ ຂອງຮູບແບບການປ້ອນຂໍ້ມູນ. ບໍ່ຈຳເປັນສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"ເຊື່ອມໂຍງກັບບໍລິການຊ່ວຍການເຂົ້າເຖິງໃດນຶ່ງ"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງ ເຊື່ອມໂຍງສ່ວນຕິດຕໍ່ລະດັບເທິງສຸດ ຂອງບໍລິການການເຂົ້າເຖິງ. ແອັບຯທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"ຜູກ​ມັດ​ກັບ​ການ​ບໍ​ລິ​ການ​ພິມ"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງຜູກກັບສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ຂອງການບໍລິການການພິມ. ບໍ່ໜ້າຈະຕ້ອງການສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"ເຂົ້າເຖິງວຽກການພິມທັງໝົດ"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງເຂົ້າເຖິງວຽກການພິມທີ່ຖືກສ້າງໂດຍແອັບຯອື່ນ. ບໍ່ໜ້າຈະຕ້ອງການສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"ເຊື່ອມໂຍງກັບບໍລິການ NFC"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"ອະນຸຍາດໃຫ້ຜູ່ຖືອຸປະກອນໃຫ້ສາມາດເຊື່ອມໂຍງແອັບພລິເຄຊັນ ທີ່ຄ້າຍກັບບັດ NFC. ມັນບໍ່ຈຳເປັນຕ້ອງໃຊ້ໃນແອັບຯທຳມະດາ."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"ເຊື່ອມໂຍງໄປຫາບໍລິການສົ່ງຂໍ້ຄວາມ"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"ອະນຸຍາດໃຫ້ຜູ່ຖືຜູກກັບອິນເຕີເຟດລະດັບສູງສຸດ ຂອງບໍລິການຂໍ້ຄວາມ(ຕ.ຢ. SpellCheckerService). ບໍ່ຈຳເປັນສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"ເຊື່ອມໂຍງກັບບໍລິການ VPN"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງເຊື່ອມໂຍງກັບສ່ວນຕິດຕໍ່ລະດັບເທິງສຸດ ຂອງບໍລິການ VPN. ແອັບຯທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"ເຊື່ອມໂຍງກັບພາບພື້ນຫຼັງ"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"ອະນຸຍາດໃຫ້ຜູ່ໃຊ້ເຊື່ອມໂຍງກັບສ່ວນຕິດຕໍ່ລະດັບສູງສຸດ ຂອງພາບພື້ນຫຼັງໃດນຶ່ງ. ແອັບຯທຳມະດາບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"ເຊື່ອມໂຍງໄປຫາບໍລິການວິດເຈັດ"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"ອະນຸຍາດໃຫ້ຜູ່ຖືຜູກກັບອິນເຕີເຟດລະດັບສູງສຸດ ຂອງບໍລິການວິເຈັດ. ບໍ່ຈຳເປັນສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"ຕິດຕໍ່ກັບຜູ່ເບິ່ງແຍງອຸປະກອນ"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງສົ່ງເຈດຕະນາຫາຜູ່ເບິ່ງແຍງລະບົບອຸປະກອນ. ແອັບຯທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"ເພີ່ມ ຫຼືລຶບຜູ່ເບິ່ງແຍງລະບົບອຸປະກອນ"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງສາມາດລຶບ ຫຼືລຶບຂໍ້ມູນອຸປະກອນທີ່ນຳໃຊ້ໄດ້. ແອັບຯທົ່ວໄປບໍ່ຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"ປ່ຽນລວງຂອງໜ້າຈໍ"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນການໝຸນຂອງໜ້າຈໍໄດ້ທຸກເວລາ. ບໍ່ຄວນຖືກໃຊ້ໃນແອັບພລິເຄຊັນທົ່ວໄປ."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"ປ່ຽນຄວາມໄວລູກສອນ"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນຄວາມໄວເມົ້າ ຫຼືລູກສອນແທຣັກແພດໃນເວລາໃດກໍໄດ້. ແອັບຯທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"ປ່ຽນຮູບແບບແປ້ນພິມ"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນຮູບແບບຂອງແປ້ນຳພິມ. ບໍ່ຈຳເປັນສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"ສົ່ງສັນຍານ Linux ຫາແອັບຯ"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"ອະນຸຍາດໃຫ້ແອັບຯຮ້ອງຂໍໃຫ້ສົ່ງສັນຍານ ແຈ້ງໄປຫາໂປຣເຊສທີ່ຍັງເຮັດວຽກຢູ່ທັງໝົດ."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"ເຮັດໃຫ້ແອັບຯເຮັດວຽກຕະຫຼອດເວລາ"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"ອະນຸຍາດໃຫ້ແອັບຯ ສາມາດເຮັດໃຫ້ບາງພາກສ່ວນຂອງມັນເອັງ ຄົງໂຕໃນໜ່ວຍຄວາມຈຳ. ສິ່ງນີ້ສາມາດຈຳກັດໜ່ວຍຄວາມຈຳທີ່ສາມາດໃຊ້ໄດ້ໂດຍແອັບຯອື່ນ ເຮັດໃຫ້ແທັບເລັດຊ້າລົງ."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"ອະນຸຍາດໃຫ້ແອັບຯເຮັດໃຫ້ສ່ວນນຶ່ງຂອງຕົນເອງ ຄົງຢູ່ຖາວອນໃນໜ່ວຍຄວາມຈຳ ເຊິ່ງອາດສາມາດ ເຮັດໃຫ້ການນຳໃຊ້ໜ່ວຍຄວາມຈຳຂອງແອັບຯ ອື່ນຖືກຈຳກັດ ສົ່ງຜົນເຮັດໃຫ້ມືຖືຂອງທ່ານເຮັດວຽກຊ້າລົງໄດ້."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"ລຶບແອັບຯ"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"ອະນຸຍາດໃຫ້ແອັບຯລຶບແພັກເກັດ Android ຕ່າງໆໄດ້. ແອັບຯອັນຕະລາຍອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອລຶບແອັບຯທີ່ສຳຄັນໄດ້."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"ລຶບຂໍ້ມູນຂອງແອັບຯອື່ນ"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"ອະນຸຍາດໃຫ້ແອັບຯລຶບຂໍ້ມູນຜູ່ໃຊ້."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"ລຶບ cache ຂອງແອັບຯອື່ນ"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"ອະນຸຍາດໃຫ້ແອັບຯລຶບໄຟລ໌ cache ໄດ້."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"ກວດສອບພື້ນທີ່ຈັດເກັບຂໍ້ມູນແອັບຯ"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"ອະນຸຍາດໃຫ້ແອັບຯດຶງໂຄດ, ຂໍ້ມູນ ແລະຂະໜາດ cache ຂອງມັນໄດ້."</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"ຕິດຕັ້ງແອັບຯໂດຍກົງ"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"ອະນຸຍາດໃຫ້ແອັບຯຕິດຕັ້ງແພັກເກດ Android ໃໝ່ ຫຼືແພັກເກດທີ່ອັບເດດແລ້ວ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໃຊ້ຄຸນສົມບັດນີ້ ເພື່ອສ້າງແອັບຯໃໝ່ທີ່ມີສິດອະນຸຍາດສູງກວ່າໄດ້."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"ລຶບຂໍ້ມູນ cache ຂອງແອັບຯທັງໝົດ"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"ອະນຸຍາດໃຫ້ແອັບຯສ້າງພື້ນທີ່ຫວ່າງໃນແທັບເລັດ ໂດຍການລຶບໄຟລ໌ໃນໄດເຣັກທໍຣີ cache ຂອງແອັບພລິເຄຊັນອື່ນ. ຄຸນສົມບັດນີ້ອາດເຮັດໃຫ້ແອັບພລິເຄຊັນອື່ນ ເລີ່ມເຮັດວຽກຊ້າລົງເພາະຕ້ອງຂຽນຂໍ້ມູນຄືນໃໝ່."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນເພີ່ມເນື້ອທີ່ຫວ່າງໃຫ້ໂທລະສັບ ໂດຍການລຶບໄຟລ໌ໃນໄດເຣັກທໍຣີ cache ຂອງແອັບພລິເຄຊັນອື່ນໆ. ການກະທຳນີ້ອາດເຮັດໃຫ້ແອັບພລິເຄຊັນອື່ນ ເຮັດວຽກໄດ້ຊ້າລົງເນື່ອງຈາກພວກມັນຕ້ອງໄດ້ດຶງຂໍ້ມູນຄືນໃໝ່."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"ຍ້າຍຊັບພະຍາກອນແອັບຯ"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"ອະນຸຍາດໃຫ້ແອັບຯຍ້າຍແຫລ່ງຊັບພະຍາກອນແອັບຯ ຈາກບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ ສູ່ບ່ອນຈັດເກັບຂໍ້ມູນພາຍນອກ ແລະໃນທາງກັບກັນໄດ້."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"ອ່ານຂໍ້ມູນບັນທຶກທີ່ສຳຄັນ"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"ອະນຸຍາດໃຫ້ແອັບຯອ່ານໄຟລ໌ບັນທຶກລະບົບຕ່າງໆຂອງລະບົບ. ຄຸນສົມບັດນີ້ຈະອະນຸຍາດໃຫ້ແອັບຯ ສາມາດຄົ້ນພົບຂໍ້ມູນທົ່ວໄປ ກ່ຽວກັບສິ່ງທີ່ທ່ານກຳລັງເຮັດກັບແທັບເລັດ ເຊິ່ງອາດຮວມເຖິງຂໍ້ມູນສ່ວນໂຕນຳໄດ້."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"ອະນຸຍາດໃຫ້ແອັບຯອ່ານໄຟລ໌ບັນທຶກລະບົບຕ່າງໆຂອງລະບົບ. ຄຸນສົມບັດນີ້ຈະອະນຸຍາດໃຫ້ແອັບຯ ສາມາດຄົ້ນພົບຂໍ້ມູນທົ່ວໄປ ກ່ຽວກັບສິ່ງທີ່ທ່ານກຳລັງເຮັດກັບໂທລະສັບ ເຊິ່ງອາດຮວມເຖິງຂໍ້ມູນສ່ວນໂຕນຳໄດ້."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"ໃຊ້ຕົວຖອດລະຫັດໃດກໍໄດ້ເພື່ອການຫຼິ້ນ"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"ອະນຸຍາດໃຫ້ແອັບຯໃຊ້ທຸກຕົວຖອດລະຫັດສື່ທີ່ຕິດຕັ້ງໄວ້ແລ້ວ ເພື່ອການຖອດລະຫັດການຫຼິ້ນໄຟລ໌ຕ່າງໆ."</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"ອ່ານ/ຂຽນ ໃສ່ຊັບພະຍາກອນທີ່ເປັນຂອງກຸ່ມວິໄຈ"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນອ່ານ ແລະຂຽນ ໃສ່ທຸກຊັບພະຍາກອນທີ່ເປັນຂອງກຸ່ມວິນິໄສ; ຕົວຢ່າງ: ໄຟລ໌ໃນ /dev. ສິ່ງນີ້ອາດສົ່ງຜົນກະທົບຕໍ່ຄວາມສະຖຽນ ແລະຄວາມປອດໄພຂອງລະບົບ. ສິ່ງນີ້ຄວນໃຊ້ສຳຫຼັບການວິເຄາະບັນຫາຈຳເພາະ ຂອງບາງຮາດແວໂດຍຜູ່ຜະລິດ ຫຼືຜູ່ປະຕິບັດການເທົ່ານັ້ນ."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"ເປີດ ຫຼືປິດນຳໃຊ້ອົງປະກອບຂອງແອັບຯ"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"ອະນຸຍາດໃຫ້ແອັບຯ ປ່ຽນແປງອົງປະກອບຂອງແອັບຯອື່ນ ວ່າຖືກເປີດນຳໃຊ້ ຫຼືບໍ່. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອປິດການນຳໃຊ້ຄວາມສາມາດສຳຄັນຂອງແທັບເລັດ. ການກຳນົດສິດນີ້ຄວນຖືກໃຊ້ຢ່າງລະມັດລະວັງ, ເພາະມັນເປັນໄປໄດ້ທີ່ຈະເຮັດໃຫ້ອົງປະກອບຂອງແອັບຯຢູ່ໃນສະຖານະ ໃຊ້ການບໍ່ໄດ້, ບໍ່ແນ່ນອນ ຫຼືບໍ່ສະຖຽນ."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"ອະນຸຍາດໃຫ້ແອັບຯ ປ່ຽນແປງອົງປະກອບຂອງແອັບຯອື່ນ ວ່າຖືກເປີດນຳໃຊ້ ຫຼືບໍ່. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອປິດການນຳໃຊ້ຄວາມສາມາດສຳຄັນຂອງໂທລະສັບ. ການກຳນົດສິດນີ້ຄວນຖືກໃຊ້ຢ່າງລະມັດລະວັງ, ເພາະມັນເປັນໄປໄດ້ທີ່ຈະເຮັດໃຫ້ອົງປະກອບຂອງແອັບຯຢູ່ໃນສະຖານະ ໃຊ້ການບໍ່ໄດ້, ບໍ່ແນ່ນອນ ຫຼືບໍ່ສະຖຽນ."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"ອະນຸມັດ ຫຼືຖອດຖານການອະນຸຍາດ"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນອະນຸມັດ ຫຼືຖອນການອະນຸມັດສິດໃດນຶ່ງສຳລັບໂຕມັນເອງ ຫຼືແອັບພລິເຄຊັນອື່ນໆ. ແອັບພລິເຄຊັນທີ່ເປັນອັນຕະລາຍ ອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອເຂົ້າເຖິງຄຸນສົມບັດບາງຢ່າງທີ່ທ່ານບໍ່ໄດ້ອະນຸມັດໃຫ້ພວກມັນ."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"ຕັ້ງຄ່າແອັບຯທີ່ຕ້ອງການ"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂແອັບຯທີ່ທ່ານຕ້ອງການໃຊ້. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດປ່ຽນແປງແອັບທີ່ເຮັດວຽກຢູ່ໂດຍບໍ່ແຈ້ງໃຫ້ຮູ້ ໂດຍການປອມແປງວ່າເປັນແອັບຯທີ່ທ່ານຕ້ອງການ ເພື່ອເກັບຂໍ້ມູນສ່ວນໂຕ."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"ແກ້ໄຂການຕັ້ງຄ່າລະບົບ"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂຂໍ້ມູນການຕັ້ງຄ່າລະບົບ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດເຮັດໃຫ້ການຕັ້ງຄ່າຂອງລະບົບເສຍຫາຍໄດ້."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"ແກ້ໄຂການຕັ້ງຄ່າລະບົບ"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂຂໍ້ມູນການຕັ້ງຄ່າຄວາມປອດໄພຂອງລະບົບ. ແອັບຯທົ່ວໄປບໍ່ໄດ້ໃຊ້ຄຸນສົມບັດນີ້."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"ແກ້ໄຂແຜນທີ່ບໍລິການ Google"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂການວາງແຜນບໍລິການ Google. ບໍ່ໄດ້ໃຊ້ສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"ເຮັດວຽກໃນຕອນລະບົບເລີ່ມ"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"ອະນຸຍາດໃຫ້ແອັບຯ ເປີດໂຕມັນເອງທັນທີທີ່ເປີດລະບົບຂຶ້ນມາສຳເລັດ. ນີ້ສາມາດເຮັດໃຫ້ການເລີ່ມເປີດຂອງແທັບເລັດໃຊ້ເວລາດົນຂຶ້ນ ແລະເຮັດໃຫ້ການເຮັດວຽກໂດຍຮວມຂອງແທັບເລັດຊ້າລົງ ໂດຍການເຮັດວຽກຕະຫຼອດເວລາ."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"ອະນຸຍາດໃຫ້ແອັບຯ ເປີດໂຕມັນເອງທັນທີທີ່ລະບົບສຳເລັດເປີດເຄື່ອງ. ນີ້ສາມາດເຮັດໃຫ້ການເລີ່ມເປີດຂອງໂທລະສັບໃຊ້ເວລາດົນຂຶ້ນ ແລະປ່ອຍໃຫ້ແອັບຯ ເຮັດໃຫ້ໂທລະສັບໂດຍຮວມຊ້າລົງ ດ້ວຍການເຮັດວຽກຢູ່ຕະຫຼອດເວລາ."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"ສົ່ງການກະຈາຍສັນຍານແບບຍຶດຕິດ"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນສົ່ງການກະຈາຍສັນຍານແບບຍຶດຕິດ, ທີ່ຍັງຄົງເຫຼືອຫຼັງຈາກການກະຈາຍສັນຍານສິ້ນສຸດລົງ. ການນຳໃຊ້ແບບມະຫາສານອາດເຮັດໃຫ້ແທັບເລັດຊ້າ ຫຼືບໍ່ສະຖຽນ ໂດຍການໃຊ້ໜ່ວຍຄວາມຈຳຫຼາຍເກີນໄປ."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນສົ່ງການກະຈາຍສັນຍານແບບຍຶດຕິດ, ທີ່ຍັງຄົງເຫຼືອຫຼັງຈາກການກະຈາຍສັນຍານສິ້ນສຸດລົງ. ການນຳໃຊ້ແບບມະຫາສານອາດເຮັດໃຫ້ໂທລະສັບຊ້າ ຫຼືບໍ່ສະຖຽນ ໂດຍການໃຊ້ໜ່ວຍຄວາມຈຳຫຼາຍເກີນໄປ."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"ອ່ານລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານ"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"ອະນຸຍາດໃຫ້ແອັບຯອ່ານຂໍ້ມູນກ່ຽວກັບລາຍຊື່ຜູ່ຕິດຕໍ່ໃນແທັບເລັດຂອງທ່ານ, ຮວມເຖິງຂໍ້ມູນການຈຳນວນການຕິດຕໍ່ຕ່າງໆເຊັ່ນ: ການໂທ, ອີເມວ, ຫຼືຕິດຕໍ່ຫາໃນທາງອື່ນໆກັບບຸກຄົນໃດນຶ່ງໄດ້. ການອະນຸຍາດນີ້ເຮັດໃຫ້ແອັບຯ ສາມາດບັນທຶກຂໍ້ມູນຜູ່ຕິດຕໍ່ຂອງທ່ານ ແລະແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດສົ່ງຕໍ່ຂໍ້ມູນເຫຼົ່ານັ້ນໂດຍທີ່ທ່ານບໍ່ຮູ້ໂຕ."</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານຂໍ້ມູນກ່ຽວກັບລາຍຊື່ຜູ່ຕິດຕໍ່ທີ່ເກັບໄວ້ໃນໂທລະສັບຂອງທ່ານ ຮວມເຖິງຄວາມຖີ່ການໂທ, ການສົ່ງສົ່ງອີເມວ ຫຼືການສື່ສານໃນຮູບແບບອື່ນກັບບຸກຄົນໃດນຶ່ງ. ການອະນຸຍາດເຮັດໃຫ້ແອັບຯ ສາມາດບັນທຶກຂໍ້ມູນລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານ ແລະແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດເຜີຍແຜ່ຂໍ້ມູນຂອງທ່ານໂດຍທີ່ທ່ານບໍ່ໄດ້ຮັບຮູ້."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"ແກ້ໄຂລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານ"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂຂໍ້ມູນກ່ຽວກັບລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານທີ່ເກັບໄວ້ໃນແທັບເລັດ ຮວມທັງຄວາມຖີ່ໃນການໂທ, ການສົ່ງອີເມວ ຫຼືການສື່ສານໃນຮູບແບບອື່ນຂອງທ່ານກັບລາຍຊື່ຜູ່ຕິດຕໍ່ໃດນຶ່ງ. ການກຳນົດສິດນີ້ເຮັດໃຫ້ແອັບຯສາມາດລຶບຂໍ້ມູນລາຍຊື່ຜູ່ຕິດຕໍ່ໄດ້."</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂຂໍ້ມູນກ່ຽວກັບລາຍຊື່ຜູ່ຕິດຕໍ່ ທີ່ບັນທຶກໃນໂທລະສັບຂອງທ່ານ ຮວມທັງຄວາມຖີ່ຂອງການໂທ, ການອີເມວ ຫຼືການຕິດຕໍ່ໃນຮູບແບບອື່ນກັບລາຍຊື່ຜູ່ຕິດຕໍ່ໃດນຶ່ງນຳ. ການອະນຸຍາດນີ້ຈະເຮັດໃຫ້ແອັບຯ ສາມາດລຶບຂໍ້ມູນລາຍຊື່ຜູ່ຕິດຕໍ່ໄດ້."</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"ອ່ານບັນທຶກການໂທ"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານບັນທຶກການໂທຂອງແທັບເລັດທ່ານ ຮວມທັງຂໍ້ມູນການໂທເຂົ້າ ແລະການໂທອອກ. ການກຳນົດສິດນີ້ເຮັດໃຫ້ແອັບຯສາມາດ ບັນທຶກຂໍ້ມູນການໂທຂອງທ່ານ ແລະແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດຈະເຜີຍແຜ່ຂໍ້ມູນການໂທໂດຍທີ່ທ່ານບໍ່ຮັບຮູ້."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"ອະນຸຍາດໃຫ້ແອັບຯອ່ານບັນທຶກການໂທຂອງໂທລະສັບທ່ານ ຮວມທັງຂໍ້ມູນກ່ຽວກັບສາຍໂທເຂົ້າ ແລະໂທອອກ. ການອະນຸຍາດນີ້ຈະເຮັດໃຫ້ແອັບຯ ສາມາດບັນທຶກຂໍ້ມູນການໂທ ແລະເຮັດໃຫ້ແອັບຯທີ່ເປັນອັນຕະລາຍສາມາດ ສົ່ງຕໍ່ຂໍ້ມູນບັນທຶກການໂທໂດຍບໍ່ໃຫ້ທ່ານຮູ້ໄດ້."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"ຂຽນຂໍ້ມູນການໂທ"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂບັນທຶກການໂທຂອງແທັບເລັດ ຮວມທັງຂໍ້ມູນກ່ຽວກັບການໂທອອກ ແລະໂທເຂົ້ານຳ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໃຊ້ຄຸນສົມບັດນີ້ເພື່ອລຶບ ຫຼືແກ້ໄຂບັນທຶກການໂທຂອງທ່ານໄດ້."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂລາຍການການໂທໃນໂທລະສັບຂອງທ່ານ, ຮວມທັງຂໍ້ມູນກ່ຽວກັບສາຍໂທເຂົ້າ ແລະການໂທອອກ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດໃຊ້ຄວາມສາມາດນີ້ ເພື່ອລຶບ ຫຼືແກ້ໄຂລາຍການການໂທຂອງທ່ານໄດ້."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"ອ່ານບັດລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານເອງ"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານຂໍ້ມູນໂປໄຟລ໌ສ່ວນໂຕໃນອຸປະກອນຂອງທ່ານເຊັ່ນ: ຊື່ຂອງທ່ານ ແລະຂໍ້ມູນການຕິດຕໍ່ຂອງທ່ານ. ນີ້ໝາຍຄວາມວ່າແອັບຯຈະສາມາດລະບຸໂຕຕົນຂອງທ່ານ ແລະສົ່ງຂໍ້ມູນໂປຣໄຟລ໌ຂອງທ່ານໃຫ້ຜູ່ອື່ນໄດ້."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"ແກ້ໄຂບັດລາຍຊື່ຜູ່ຕິດຕໍ່ຂອງທ່ານເອງ"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"ອະນຸຍາດໃຫ້ແອັບຯ ປ່ຽນແປງ ຫຼືເພີ່ມຂໍ້ມູນໃສ່ໂປຣໄຟລ໌ສ່ວນບຸກຄົນທີ່ເກັບໄວ້ໃນອຸປະກອນຂອງທ່ານ, ເຊັ່ນ: ຊື່ ແລະຂໍ້ມູນຕິດຕໍ່ທ່ານ. ນີ້ໝາຍຄວາມວ່າແອັບຯສາມາດບົ່ງບອກໂຕທ່ານ ແລະອາດສົ່ງຂໍ້ມູນໂປຣໄຟລ໌ຂອງທ່ານໃຫ້ຜູ່ອື່ນໄດ້."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"ອ່ານການອັບເດດສັງຄົມອອນລາຍຂອງທ່ານ"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"ອະນຸຍາດໃຫ້ແອັບຯ ເຂົ້າເຖິງ ແລະຊິ້ງຂໍ້ມູນຂ່າວສານສັງຄົມຈາກທ່ານ ແລະໝູ່ຂອງທ່ານ. ຄວນລະມັດລະວັງໃນເວລາທີ່ແລກປ່ຽນຂໍ້ມູນ -- ນີ້ຈະເປັນການອະນຸຍາດໃຫ້ແອັບຯ ອ່ານການສື່ສານລະຫວ່າງທ່ານ ກັບໝູ່ຂອງທ່ານເທິງເຄືອຂ່າຍສັງຄົມ ໂດຍບໍ່ຄຳນຶງເຖິງຄວາມລັບ. ໝາຍເຫດ: ການກຳນົດສິດນີ້ອາດບໍ່ໄດ້ບັງຄັບໃຊ້ໃນທຸກເຄືອຂ່າຍສັງຄົມ."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"ຂຽນໃສ່ເຄືອຂ່າຍສັງຄົມຂອງທ່ານ"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"ອະນຸຍາດໃຫ້ແອັບຯສະແດງການອັບເດດຈາກໝູ່ຂອງທ່ານ. ຄວນລະວັງໃນການແປ່ງປັນຂໍ້ມູນ. ມັນຈະໄປອະນຸຍາດໃຫ້ແອັບຯ ສ້າງຂໍ້ຄວາມທີ່ອ້າງວ່າມາຈາກໝູ່ຂອງທ່ານ. ໝາຍເຫດ: ການອະນຸຍາດອາດບໍ່ຖືກບັງຄັບ ໃນບໍລິການເຄືອຂ່າຍສັງຄອມອອນລາຍທຸກອັນ."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"ອ່ານກຳນົດການໃນປະຕິທິນຮວມທັງຂໍ້ມູນຄວາມລັບ"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານການນັດໝາຍທັງໝົດທີ່ມີບັນທຶກໃນແທັບເລັດຂອງທ່ານ, ຮວມທັງຂອງໝູ່ ຫຼືໝູ່ທີ່ເຮັດວຽກນຳກັນໄດ້ ເຊິ່ງອາດເຮັດໃຫ້ແອັບຯສາມາດສົ່ງຕໍ່ ຫຼືບັນທຶກຂໍ້ມູນປະຕິທິນຂອງທ່ານ ບໍ່ວ່າຈະເປັນເລື່ອງຄວາມລັບ ຫຼືເລື່ອງລະອຽດອ່ອນແບບໃດກໍຕາມ."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານກຳນົດການໃນປະຕິທິນທັງໝົດ ທີ່ເກັບໄວ້ໃນໂທລະສັບຂອງທ່ານ, ຮວມເຖິງຂອງໝູ່ຄູ່ ຫຼືເພື່ອນຮ່ວມວຽກ. ນີ້ອາດຈະເຮັດໃຫ້ແອັບຯສາມາດເຜີຍແຜ່ ຫຼືບັນທຶກຂໍ້ມູນປະຕິທິນຂອງທ່ານ, ໂດຍບໍ່ຄຳນຶງເຖິງ ຄວາມລະອຽດອ່ອນ ຫຼືຄວາມລັບໃດໆໄດ້."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"ເພີ່ມ ຫຼືແກ້ໄຂນັດໝາຍໃນປະຕິທິນ ແລະສົ່ງອີເມວຫາຜູ່ເຂົ້າຮ່ວມໂດຍບໍ່ຕ້ອງໃຫ້ເຈົ້າຂອງຮັບຮູ້"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"ອະນຸຍາດໃຫ້ແອັບຯເພີ່ມ, ລຶບ ແລະປ່ຽນກິດຈະກຳທີ່ທ່ານສາມາດແກ້ໄຂ ໃນແທັບເລັດຂອງທ່ານໄດ້ ຮວມທັງກິດຈະກຳຂອງໝູ່ ຫຼືໝູ່ຮ່ວມເຮັດວຽກ ເຊິ່ງອາດອະນຸຍາດໃຫ້ແອັບຯສົ່ງຂໍ້ຄວາມທີ່ຄືກັບວ່າ ມາຈາກເຈົ້າຂອງປະຕິທິນ ຫຼືແກ້ໄຂການນັດໝາຍໄດ້ ໂດຍບໍ່ໃຫ້ເຈົ້າຂອງຮັບຮູ້."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"ອະນຸຍາດໃຫ້ແອັບຯ ເພີ່ມ, ລຶບ, ປ່ຽນແປງນັດໝາຍທີ່ທ່ານສາມາດແກ້ໄຂໄດ້ໃນໂທລະສັບຂອງທ່ານ, ຮວມທັງຂອງໝູ່ຄູ່ ຫຼືເພື່ອນຮ່ວມວຽກ. ນີ້ອາດເຮັດໃຫ້ແອັບຯສາມາດສົ່ງຂໍ້ຄວາມ ທີ່ເບິ່ງຄືວ່າມາຈາກເຈົ້າຂອງປະຕິທິນ ຫຼືແກ້ໄຂນັດໝາຍໂດຍທີ່ທ່ານບໍ່ໄດ້ຮັບຮູ້ໄດ້."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"ຈຳລອງແຫລ່ງຂໍ້ມູນສະຖານທີ່ເພື່ອການທົດສອບ"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"ສ້າງແຫລ່ງຂໍ້ມູນຈຳລອງຂອງສະຖານທີ່ ເພື່ອການທົດສອບ ຫຼືຕິດຕັ້ງແຫລ່ງຂໍ້ມູນສະຖານທີ່ໃໝ່. ນີ້ຈະອະນຸຍາດໃຫ້ແອັບຯສາມາດຂຽນທັບຂໍ້ມູນຂອງສະຖານທີ່ ແລະ/ຫຼື ຂໍ້ມູນທີ່ສົ່ງກັບມາຈາກແຫລ່ງຂໍ້ມູນສະຖານທີ່ອື່ນ ເຊັ່ນ: GPS ຫຼືແຫລ່ງຂໍ້ມູນສະຖານທີ່ອື່ນໄດ້."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"ເຂົ້າເຖິງຄຳສັ່ງຜູ່ໃຫ້ບໍລິການພິກັດສະຖານທີ່"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"ອະນຸຍາດໃຫ້ແອັບຯ ເຂົ້າເຖິງຄຳສັ່ງເພີ່ມເຕີມຂອງຜູ່ໃຫ້ບໍລິການສະຖານທີ່. ນີ້ອາດຈະເປັນການເຮັດໃຫ້ແອັບຯ ລົບກວນການເຮັດວຽກຂອງ GPS ຫຼືແຫລ່ງຂໍ້ມູນສະຖານທີ່ອື່ນໆໄດ້."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"ສິດໃນການຕິດຕັ້ງແຫຼ່ງສະໜອງສະຖານທີ່"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"ສ້າງສະຖານທີ່ຈຳລອງເພື່ອການທົດລອງ ຫຼືຕິດຕັ້ງແຫຼ່ງຂໍ້ມູນສະຖານທີ່ໃໝ່. ສິ່ງນີ້ເຮັດໃຫ້ແອັບຯສາມາດຂຽນທັບສະຖານທີ່ ແລະ/ຫຼື ສະຖານະທີ່ໄດ້ຈາກແຫຼ່ງສະຖານທີ່ອື່ນເຊັ່ນ: GPS ຫຼືຜູ່ສະໜອງສະຖານທີ່ຕ່າງໆ."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"ສະຖານທີ່ແນ່ນອນ (ອ້າງອີງຈາກ GPS ແລະເຄືອຂ່າຍ)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"ອະນຸຍາດໃຫ້ແອັບຯ ຮັບຕຳແໜ່ງສະຖານທີ່ລະອຽດຂອງທ່ານໂດຍໃຊ້ GPS ຫຼືແຫລ່ງຂໍ້ມູນເຄືອຂ່າຍສະຖານທີ່ເຊັ່ນ: ເສົາສັນຍານມືຖື ແລະ Wi-Fi. ບໍລິການສະຖານທີ່ເຫຼົ່ານີ້ຕ້ອງຖືກເປີດນຳໃຊ້ ແລະແລະມີຂໍ້ມູນໃຫ້ກັບອຸປະກອນຂອງທ່ານ ເພື່ອໃຫ້ແອັບຯໃຊ້ໄດ້. ແອັບຯຕ່າງໆອາດໃຊ້ຂໍ້ມູນນີ້ເພື່ອລະບຸສະຖານທີ່ຢູ່ຂອງທ່ານ ແລະອາດນຳໃຊ້ແບັດເຕີຣີເພີ່ມເຕີມໄດ້."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"ສະຖານທີ່ໂດຍປະມານ (ອ້າງອີງຈາກເຄືອຂ່າຍ)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"ອະນຸຍາດໃຫ້ແອັບຯ ລະບຸສະຖານທີ່ໂດຍປະມານຂອງທ່ານ. ສະຖານທີ່ນີ້ໄດ້ຮັບມາຈາກບໍລິການສະຖານທີ່ ໂດຍອາໃສສະຖານທີ່ເຄືອຂ່າຍເຊັ່ນ: ເສົາສັນຍານ ແລະ Wi-Fi. ບໍລິການສະຖານທີ່ເຫຼົ່ານີ້ຕ້ອງຖືກເປີດໃຊ້ ແລະ ມີໃນອຸປະກອນຂອງທ່ານເພື່ອທີ່ແອັບຯຈະສາມາດໃຊ້ພວກມັນໄດ້. ແອັບຯອາດຈະໃຊ້ຄຸນສົມບັດນີ້ ເພື່ອກວດສອບສະຖານທີ່ໂດຍປະມານຂອງທ່ານ."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"ເຂົ້າເຖິງ SurfaceFlinger"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"ອະນຸຍາດໃຫ້ແອັບຯນຳໃຊ້ຄວາມສາມາດລະດັບຕ່ຳ SurfaceFlinger"</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"ອ່ານເຟຣມບັບເຟີ"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"ອະນຸຍາດໃຫ້ແອັບຯອ່ານເນື້ອຫາຂອງເຟຣມບັບເຟີ."</string>
-    <string name="permlab_accessInputFlinger" msgid="5348635270689553857">"ເຂົ້າເຖິງ InputFlinger"</string>
-    <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"ອະນຸຍາດໃຫ້ແອັບຯນຳໃຊ້ຄວາມສາມາດ InputFlinger ລະດັບຕ່ຳ"</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"ປັບຄ່າການສະແດງຜົນ WiFi"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"ອະນຸຍາດໃຫ້ແອັບຯຕັ້ງຄ່າ ແລະເຊື່ອມຕໍ່ຈໍສະແດງຜົນ WiFi."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"ຄວບຄຸມການສະແດງ WiFi"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"ອະນຸຍາດໃຫ້ແອັບຯ ຄວບຄຸມຄວາມສາມາດລະດັບຕໍ່າຂອງການສະແດງຜົນ Wifi."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"ບັນທຶກສຽງອອກ"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"ອະນຸຍາດໃຫ້ແອັບຯບັນທຶກ ແລະປ່ຽນເສັ້ນທາງການປ້ອນຂໍ້ມູນອອກຂອງສຽງ."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"ບັນທຶກວິດີໂອອອກ"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"ອະນຸຍາດໃຫ້ແອັບຯບັນທຶກ ແລະປ່ຽນເສັ້ນທາງການປ້ອນຂໍ້ມູນອອກຂອງວິດີໂອ."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"ບັນທຶກວິດີໂອອອກຢ່າງປອດໄພ"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"ອະນຸຍາດໃຫ້ແອັບຯບັນທຶກ ແລະປ່ຽນເສັ້ນທາງການປ້ອນຂໍ້ມູນອອກຂອງວິດີໂອທີ່ປອດໄພ."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"ປ່ຽນການຕັ້ງຄ່າສຽງຂອງທ່ານ"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂການຕັ້ງຄ່າສຽງສ່ວນກາງ ເຊັ່ນ: ລະດັບສຽງ ແລະລຳໂພງໃດທີ່ຖືກໃຊ້ສົ່ງສຽງອອກ."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"ບັນທຶກສຽງ"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"ອະນຸຍາດໃຫ້ແອັບຯບັນທຶກສຽງດ້ວຍໄມໂຄຣໂຟນໄດ້. ການອະນຸຍາດນີ້ຈະເຮັດໃຫ້ແອັບຯ ສາມາດບັນທຶກສຽງໄດ້ຕະຫລອດເວລາ ໂດຍບໍ່ຕ້ອງຖ້າການຢືນຢັນຈາກທ່ານ."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"ຖ່າຍຮູບ ແລະວິດີໂອ"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"ອະນຸຍາດໃຫ້ແອັບຯຖ່າຍຮູບ ແລະວິດີໂອດ້ວຍກ້ອງຖ່າຍຮູບ. ການອະນຸຍາດນີ້ຈະອານຸຍາດໃຫ້ແອັບຯ ສາມາດໃຊ້ກ້ອງຖ່າຍຮູບໄດ້ຕະຫລອດເວລາ ໂດຍບໍ່ຕ້ອງຖ້າການຢືນຢັນຈາກທ່ານ."</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"ປິດໄຟສັນຍານ LED ເມື່ອນຳໃຊ້ກ້ອງ"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນທີ່ມາກັບໂຕເຄື່ອງ ປິດການນຳໃຊ້ໄຟ LED ໃນກ້ອງຖ່າຍຮູບ."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"ປິດການນຳໃຊ້ແທັບເລັດຖາວອນ"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"ປິດການເຮັດວຽກຂອງໂທລະສັບຖາວອນ"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"ອະນຸຍາດໃຫ້ແອັບຯປິດການນຳໃຊ້ແທັບເລັດທັງໝົດໂດຍຖາວອນ. ຄຸນສົມບັດນີ້ເປັນສິ່ງອັນຕະລາຍຫຼາຍ."</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"ອະນຸຍາດໃຫ້ແອັບຯປິດການນຳໃຊ້ໂທລະສັບທັງໝົດແບບຖາວອນ. ອັນຕະລາຍຫຼາຍ."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ບັງຄັບໃຫ້ແທັບເລັດປິດແລ້ວເປີດໃໝ່"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"ບັງຄັບໃຫ້ໂທລະສັບປິດແລ້ວເປີດໃໝ່"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"ອະນຸຍາດໃຫ້ແອັບຯ ບັງຄັບແທັບເລັດໃຫ້ປິດເປີດໃໝ່."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"ອະນຸຍາດໃຫ້ແອັບຯ ບັງຄັບໃຫ້ໂທລະສັບປິດເປີດໃໝ່."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"ເຂົ້າເຖິງໄຟລ໌ລະບົບຂອງບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"ເຂົ້າເຖິງໄຟລ໌ລະບົບຂອງ SD card"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"ອະນຸຍາດໃຫ້ແອັບຯ ເຊື່ອມຕໍ່ ແລະຖອນການເຊື່ອມຕໍ່ຈາກລະບົບໄຟລ໌ ຂອງອຸປະກອນເກັບຂໍ້ມູນແບບຖອດອອກໄດ້."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"ລຶບບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"ລຶບ SD card"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"ອະນຸຍາດໃຫ້ແອັບຯ ຟໍແມັດອຸປະກອນເກັບຂໍ້ມູນທີ່ສາມາດຖອດອອກໄດ້."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"ດຶງຂໍ້ມູນຈາກບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"ອະນຸຍາດໃຫ້ແອັບຯດຶງຂໍ້ມູນໃນບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນໄດ້."</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"ສ້າງບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"ອະນຸຍາດໃຫ້ແອັບຯສ້າງພື້ນທີ່ຈັດເກັບຂໍ້ມູນພາຍໃນ."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"ທຳລາຍບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"ອະນຸຍາດໃຫ້ແອັບຯທຳລາຍບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"ເຊື່ອມຕໍ່/ຖອນການເຊື່ອມຕໍ່ ບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"ອະນຸຍາດໃຫ້ແອັບຯ ເຊື່ອມຕໍ່/ຖອດການເຊື່ອມຕໍ່ ບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"ປ່ຽນຊື່ບ່ອນເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນປ່ຽນຊື່ພື້ນທີ່ເກັບຂໍ້ມູນພາຍໃນ."</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_manageUsb" msgid="1113453430645402723">"ຈັດການການກຳນົດຄ່າ ແລະການອະນຸຍາດສຳລັບອຸປະກອນ USB"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"ອະນຸຍາດໃຫ້ແອັບຯ ຈັດການການຕັ້ງຄ່າຄວາມຕ້ອງການ ແລະການກຳນົດສິດສຳລັບອຸປະກອນ USB."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"ໃຊ້ໂປຣໂຕຄອນ MTP"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"ອະນຸຍາດການເຂົ້າເຖິງ kernel MPT driver ເພື່ອໃຊ້ໂປຣໂຕຄອນ MTP USB."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"ທົດສອບຮາດແວ"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມອຸປະກອນຕໍ່ພ່ວງທັງຫຼາຍ ເພື່ອຈຸດປະສົງການທົດສອບຮາດແວ."</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"ໂທຫາເບີໂທລະສັບໂດຍກົງ"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"ອະນຸຍາດໃຫ້ແອັບຯໂທຫາເບີໂທລະສັບໄດ້ ໂດຍບໍ່ຕ້ອງຖ້າການດຳເນີນການໃດໆຈາກທ່ານ. ຄຸນສົມບັດນີ້ອາດກໍ່ໃຫ້ເກີດຄ່າໃຊ້ຈ່າຍໃນການໂທທີ່ບໍ່ຄາດຄິດໄດ້. ໝາຍເຫດ: ຄຸນສົມບັດນີ້ບໍ່ໄດ້ເປັນການອະນຸຍາດໃຫ້ແອັບຯ ສາມາດໂທຫາເບີສຸກເສີນ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດເຮັດໃຫ້ທ່ານ ຕ້ອງເສຍຄ່າໂທໂດຍທີ່ບໍ່ໄດ້ຄາດຄິດ."</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"ໂທໂດຍກົງໄປຫາເບີໂທໃດກໍໄດ້"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"ອະນຸຍາດໃຫ້ແອັບຯໂທອອກຫາເບີໂທລະສັບໃດກໍໄດ້, ຮວມທັງເບີສຸກເສີນ, ໂດຍບໍ່ມີການແຊກແຊງຂອງທ່ານ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໂທອອກໂດຍບໍ່ຈຳເປັນ ແລະໂທຫາບໍລິການເບີສຸກເສີນແບບຜິດກົດໝາຍ."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"ເລີ່ມການຕັ້ງຄ່າແທັບເລັດ CDMA ໂດຍກົງ"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"ເລີ່ມການຕັ້ງຄ່າໂທລະສັບ CDMA ໂດຍກົງ"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"ອະນຸຍາດໃຫ້ແອັບຯເລີ່ມການເຮັດວຽກຂອງ CDMA. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດເລີ່ມການເຮັດວຽກຂອງ CDMA ໂດຍບໍ່ຈຳເປັນ."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"ຄວບຄຸມການແຈ້ງເຕືອນອັບເດດສະຖານທີ່"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"ອະນຸຍາດໃຫ້ແອັບຯ ເປີດ/ປິດ ການເຮັດວຽກຂອງການແຈ້ງເຕືອນອັບເດດສະຖານທີ່ຈາກວິທະຍຸ. ແອັບຯທົ່ວໄປບໍ່ຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"ເຂົ້າເຖິງຄຸນສົມບັດການເຊັກອິນ"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"ອະນຸຍາດໃຫ້ແອັບຯໄດ້ຮັບສິດ ອ່ານ/ຂຽນ ໃສ່ສິ່ງທີ່ອັບໂຫຼດຂຶ້ນໂດຍບໍລິການເຊັກອິນ. ບໍ່ໃຊ້ໃນແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"ເລືອກວິດເຈັດ"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"ອະນຸຍາດໃຫ້ແອັບຯບອກລະບົບວ່າ ວິດເຈັດໃດສາມາດນຳໃຊ້ໂດຍແອັບຯໃດ. ແອັບຯທີ່ມີການອະນຸຍາດນີ້ຈະມອບການເຂົ້າເຖິງຂໍ້ມູນສ່ວນໂຕ ໃຫ້ກັບແອັບຯອື່ນໄດ້. ບໍ່ໄດ້ໃຊ້ໂດຍແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"ແກ້ໄຂສະຖານະໂທລະສັບ"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"ອະນຸຍາດໃຫ້ແອັບຯຄວບຄຸມຄວາມສາມາດຂອງໂທລະສັບໃນອຸປະກອນ. ແອັບຯທີ່ມີການອະນຸຍາດນີ້ຈະສາມາດສະລັບເຄືອຂ່າຍ, ເປີດ ຫຼືປິດສັນຍານວິທະຍຸ ແລະຄວາມສາມາດອື່ນທີ່ຄ້າຍກັນ ໂດຍບໍ່ມີການແຈ້ງເຕືອນທ່ານ."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"ອ່ານສະຖານະ ແລະຂໍ້ມູນລະບຸໂຕຕົນຂອງໂທລະສັບ"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"ອະນຸຍາດໃຫ້ແອັບຯ ເຂົ້າເຖິງຄວາມສາມາດການໂທລະສັບຂອງອຸປະກອນ. ການກຳນົດສິດນີ້ເຮັດໃຫ້ແອັບຯສາມາດກວດສອບເບີໂທລະສັບ ແລະ ID ຂອງອຸປະກອນ, ບໍ່ວ່າການໂທຈະຍັງດຳເນີນຢູ່ ແລະເບີປາຍທາງເຊື່ອມຕໍ່ຢູ່ຫຼືບໍ່ກໍຕາມ."</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"ຂັດຂວາງບໍ່ໃຫ້ປິດໜ້າຈໍແທັບເລັດ"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"ຂັດຂວາງບໍ່ໃຫ້ໂທລະສັບປິດໜ້າຈໍ"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"ອະນຸຍາດໃຫ້ແອັບຯ ປ້ອງກັນບໍ່ໃຫ້ປິດໜ້າຈໍແທັບເລັດ."</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"ອະນຸຍາດໃຫ້ແອັບຯປ້ອງກັນບໍ່ໃຫ້ປິດໜ້າຈໍໂທລະສັບ."</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"ເປີດ ຫຼືປິດແທັບເລັດ"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"ເປີດ ຫຼືປິດໂທລະສັບ"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"ອະນຸຍາດໃຫ້ແອັບຯເປີດ ຫຼືປິດແທັບເລັດ."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນປິດ ຫຼືເປີດແທັບເລັດໄດ້."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"ເຮັດວຽກໃນໂໝດການທົດສອບຂອງໂຮງງານ"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"ເຮັດວຽກໃນຮູບແບບທົດສອບໃນລະດັບຕໍ່າຂອງຜູ່ຜະລິດ, ອະນຸຍາດການເຂົ້າເຖິງແບບເຕັມຮູບແບບຫາຮາດແວຂອງແທັບເລັດ. ໃຊ້ໄດ້ສະເພາະໃນເວລາທີ່ແທັບເລັດກຳລັງຢູ່ໃນໂໝດ ການທົດສອບຂອງຜູ່ຜະລິດgmqjkoaho."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"ເປີດໃຊ້ໃນແບບການທົດສອບຂອງຜູ່ລະລິດໃນລະດັບຕໍ່າ, ອະນຸຍາດການເຂົ້າເຖິງຮາດແວຂອງໂທລະສັບແບບສົມບູນ. ສະເພາະເມື່ອໂທລະສັບຖືກເປີດໃຊ້ ໃນໂໝດການທົດສອບຂອງຜູ່ຜະລິດເທົ່ານັ້ນ."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"ຕັ້ງພາບພື້ນຫຼັງ"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"ອະນຸຍາດໃຫ້ແອັບຯຕັ້ງຄ່າພາບພື້ນຫຼັງຂອງລະບົບໄດ້."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"ປັບຂະໜາດພາບພື້ນຫຼັງຂອງທ່ານ"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"ອະນຸຍາດໃຫ້ແອັບຯ ຕັ້ງຄ່າຄຳແນະນຳຂະໜາດພາບພື້ນຫຼັງ."</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"ຣີເຊັດລະບົບໃຫ້ເປັນຄ່າເລີ່ມຕົ້ນທີ່ມາຈາກໂຮງງານ"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"ອະນຸຍາດໃຫ້ແອັບຯ ຣີເຊັດຄ່າທັງໝົດຂອງລະບົບໃຫ້ກັບໄປເປັນແບບທີ່ມາຈາກໂຮງງານ, ລຶບຂໍ້ມູນ, ການຕັ້ງຄ່າ ແລະແອັບຯທີ່ໄດ້ຕິດຕັ້ງໄວ້ທັງໝົດ."</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"ຕັ້ງເວລາ"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນເວລາຂອງໂມງໃນແທັບເລັດໄດ້."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນເວລາຂອງໂມງໃນໂທລະສັບໄດ້."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"ຕັ້ງເຂດເວລາ"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນເຂດເວລາຂອງແທັບເລັດ."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"ອະນຸຍາດໃຫ້ແອັບຯ ປ່ຽນເຂດເວລາຂອງໂທລະສັບ."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"ເຮັດໜ້າທີ່ເປັນ AccountManagerService"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"ອະນຸຍາດໃຫ້ແອັບຯເອີ້ນຫາ AccountAuthenticators."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"ຊອກຫາບັນຊີໃນອຸປະກອນ"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"ອະນຸຍາດໃຫ້ແອັບຯຮັບເອົາລາຍການຂອງບັນຊີທີ່ຮູ້ຈັກໂດຍແທັບເລັດ. ນີ້ອາດຮວມທັງບັນຊີຕ່າງໆ ທີ່ຖືກສ້າງໂດຍແອັບພລິເຄຊັນທີ່ທ່ານໄດ້ຕິດຕັ້ງໄວ້."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ດຶງຂໍ້ມູນລາຍຊື່ຂອງບັນຊີທີ່ໂທລະສັບມີ ເຊິ່ງອາດຮວມເຖິງບັນຊີທີ່ໃດໆທີ່ສ້າງຂຶ້ນ ໂດຍແອັບພລິເຄຊັນທີ່ທ່ານຕິດຕັ້ງໄວ້."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"ສ້າງບັນຊີ ແລະຕັ້ງລະຫັດຜ່ານ"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"ອະນຸຍາດໃຫ້ແອັບຯ ໃຊ້ຄວາມສາມາດຂອງຕົວພິສູດສິດບັນຊີຂອງ AccountManager ຮວມທັງການສ້າງບັນຊີ, ການຂໍເບິ່ງ ແລະຕັ້ງຄ່າລະຫັດຜ່ານ."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"ສ້າງ ຫຼືລຶບບັນຊີ"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"ອະນຸຍາດໃຫ້ແອັບຯດຳເນີນການເຊັ່ນ: ເພີ່ມ ຫຼືລຶບບັນຊີ ແລະລຶບລະຫັດຜ່ານຂອງບັນຊີໄດ້."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"ໃຊ້ບັນຊີໃນອຸປະກອນ"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"ອະນຸຍາດໃຫ້ແອັບຯຮ້ອງຂໍໂທເຄນການພິສູດຢືນຢັນໄດ້."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"ເບິ່ງການເຊື່ອມຕໍ່ເຄືອຂ່າຍ"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"ອະນຸຍາດໃຫ້ແອັບຯ ເບິ່ງຂໍ້ມູນກ່ຽວກັບການເຊື່ອມຕໍ່ເຄືອຂ່າຍ ເຊັ່ນວ່າມີເຄືອຂ່າຍໃດແດ່ ແລະໄດ້ເຊື່ອມຕໍ່ກັບເຄືອຂ່າຍໃດ."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"ເຂົ້າເຖິງເຄືອຂ່າຍເຕັມຮູບແບບ"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"ອະນຸຍາດໃຫ້ແອັບຯສ້າງຊັອກເກັດເຄືອຂ່າຍ ແລະໂປຣໂຕຄອນເຄືອຂ່າຍແບບກຳນົດເອງ. ໂປຣແກຣມທ່ອງເວັບ ແລະແອັບພລິເຄຊັນອື່ນໆຈະສົ່ງຂໍ້ມູນສູ່ອິນເຕີເນັດຢູ່ແລ້ວ ດັ່ງນັ້ນການອະນຸຍາດນີ້ຈຶ່ງບໍ່ຈຳເປັນຕ້ອງໃຊ້ ເພື່ອສົ່ງຂໍ້ມູນສູ່ອິນເຕີເນັດ."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"ປ່ຽນ/ສະກັດກັ້ນການຕັ້ງຄ່າເຄືອຂ່າຍ ແລະຂໍ້ມູນ"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນການຕັ້ງຄ່າເຄືອຂ່າຍ ແລະສະກັດກັ້ນ ແລະກວດສອບການເດີນທາງຂອງຂໍ້ມູນທັງໝົດ, ຍົກຕົວຢ່າງ: ໃນການປ່ຽນພອດຂອງ Proxy ຂອງ APN ໃດກໍຕາມ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດຕິດຕາມ, ປ່ຽນແປງ ແລະແກ້ໄຂແພັກເກັດຂອງທ່ານໂດຍທີ່ທ່ານບໍ່ຮູ້ໂຕ."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"ປ່ຽນການເຊື່ອມຕໍ່ເຄືອຂ່າຍ"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນສະຖານະການເຊື່ອມຕໍ່ຂອງເຄືອຂ່າຍໄດ້."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"ປ່ຽນການເຊື່ອມຕໍ່ທີ່ປ່ອຍສັນຍານໄວ້"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນແປງສະຖານະ ຂອງເຄືອຂ່າຍການເຊື່ອມຕໍ່ອິນເຕີເນັດຜ່ານມືຖື."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"ປ່ຽນການຕັ້ງຄ່າການນຳໃຊ້ຂໍ້ມູນພື້ນຫຼັງ"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"ອະນຸຍາດໃຫ້ແອັບຯປ່ຽນການຕັ້ງຄ່າການໃຊ້ອິນເຕີເນັດ ຂອງແອັບຯທີ່ເຮັດວຽກຢູ່ດ້ານຫຼັງລະບົບ."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"ເບິ່ງການເຊື່ອມຕໍ່ Wi-Fi"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"ອະນຸຍາດໃຫ້ແອັບຯເບິ່ງຂໍ້ມູນກ່ຽວກັບເຄືອຂ່າຍ Wi-Fi ເຊັ່ນວ່າ WiFi ກຳລັງຖືກນຳໃຊ້ຢູ່ບໍ່ ແລະຊື່ຂອງອຸປະກອນ WiFi ທີ່ກຳລັງເຊື່ອມຕໍ່ຢູ່."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"ເຊື່ອມຕໍ່ ແລະຕັດການເຊື່ອມຕໍ່ຈາກ Wi-Fi"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"ອະນຸຍາດໃຫ້ແອັບຯເຊື່ອມຕໍ່ ແລະຕັດການເຊື່ອມຕໍ່ຈາກຈຸດເຊື່ອມຕໍ່ Wi-Fi ແລະໃຫ້ສາມາດປ່ຽນແປງຄ່າຂອງອຸປະກອນສຳລັບເຄືອຂ່າຍ Wi-Fi."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"ອະນຸຍາດການຮັບ Wi-Fi Multicast"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"ອະນຸຍາດໃຫ້ແອັບຯຮັບຂໍ້ມູນແພັກເກັດ ທີ່ຖືກສົ່ງ ໄປຫາທຸກອຸປະກອນໃນເຄືອຂ່າຍ WiFi ໂດຍການນຳໃຊ້ການກະຈາຍຂໍ້ມູນໃນວົງກວ້າງ, ບໍ່ແມ່ນສະເພາະແທັບເລັດຂອງທ່ານ. ມັນໃຊ້ພະລັງງານຫຼາຍກວ່າໂຫມດກະຈາຍຂໍ້ມູນແບບໂດຍກົງ."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"ອະນຸຍາດໃຫ້ແອັບຯ ຮັບຂໍ້ມູນແພັກເກດທີ່ສົ່ງໄປໃຫ້ທຸກອຸປະກອນໃນເຄືອຂ່າຍ Wi-Fi ໂດຍໃຊ້ທີ່ຢູ່ multicast ບໍ່ສະເພາະພຽງໂທລະສັບຂອງທ່ານ, ເຊິ່ງຈະໃຊ້ພະລັງງານຫຼາຍກວ່າໃນໂໝດທີ່ບໍ່ແມ່ນ multicast."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"ເຂົ້າເຖິງການຕັ້ງຄ່າ Bluetooth"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"ອະນຸຍາດໃຫ້ແອັບຯຕັ້ງຄ່າແທັບເລັດ Bluetooth ພາຍໃນ ແລະຊອກຫາ ແລະເຊື່ອມຕໍ່ໄວ້ກັບອຸປະກອນພາຍນອກ."</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"ອະນຸຍາດໃຫ້ແອັບຯຕັ້ງຄ່າ Bluetooth ໃນໂທລະສັບ ເພື່ອຊອກຫາ ແລະການເຊື່ອມຕໍ່ກັບອຸປະກອນໄຮ້ສາຍພາຍນອກ."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"ເຊື່ອມຕໍ່ ແລະຕັດການເຊື່ອມຕໍ່ຈາກ WiMAX"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"ອະນຸຍາດໃຫ້ແອັບຯກວດເບິ່ງວ່າ WiMAX ຖືກເປີດນຳໃຊ້ຢູ່ບໍ່ ແລະຂໍ້ມູນກ່ຽວກັບເຄືອຂ່າຍ WiMAX ອື່ນໆທີ່ກຳລັງເຊື່ອມຕໍ່ຢູ່."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"ປ່ຽນສະຖານະ WiMAX"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"ອະນຸຍາດໃຫ້ແອັບຯເຊື່ອມຕໍ່ ແລະຕັດການເຊື່ອມຕໍ່ແທັບເລັດຈາກເຄືອຂ່າຍ WiMAX."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"ອະນຸຍາດໃຫ້ແອັບຯເຊື່ອມຕໍ່ ແລະຕັດການເຊື່ອມຕໍ່ຂອງໂທລະສັບຈາກເຄືອຂ່າຍ WiMax ໄດ້."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"ຈັບຄູ່ກັບອຸປະກອນ Bluetooth"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"ອະນຸຍາດໃຫ້ແອັບຯເບິ່ງການຕັ້ງຄ່າຂອງ Bluetooth ໃນແທັບເລັດ ຕະຫຼອດຈົນເຊື່ອມຕໍ່ ແລະຍອມຮັບການເຊື່ອມຕໍ່ກັບອຸປະກອນທີ່ຈັບຄູ່ກັນແລ້ວ."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"ອະນຸຍາດໃຫ້ແອັບຯເບິ່ງການຕັ້ງຄ່າຂອງ Bluetooth ໃນໂທລະສັບ, ຮວມທັງໃຫ້ສ້າງ ແລະຮັບການເຊື່ອມຕໍ່ຈາກອຸປະກອນທີ່ຈັບຄູ່ກັນ."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"ຄວບຄຸມ Near Field Communication"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"ອະນຸຍາດໃຫ້ແອັບຯຕິດຕໍ່ສື່ສານກັບປ້າຍກຳກັບ, ບັດ ແລະໂຕອ່ານຂອງການສື່ສານໄລຍະສັ້ນ (NFC)."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"ປິດການລັອກໜ້າຈໍ"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"ອະນຸຍາດໃຫ້ແອັບຯປິດການເຮັດວຽກຂອງປຸ່ມລັອກ ແລະລະບົບຄວາມປອດໄພຂອງລະຫັດຜ່ານທີ່ເຊື່ອມໂຍງກັນ. ໂຕຢ່າງ: ໂທລະສັບຈະປິດການເຮັດວຽກຂອງປຸ່ມລັອກເມື່ອມີສາຍໂທເຂົ້າ ຈາກນັ້ນຈຶ່ງເປີດໃຊ້ໄດ້ອີກເມື່ອວາງສາຍແລ້ວ."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"ອ່ານການຕັ້ງຄ່າຊິ້ງຂໍ້ມູນ"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານການຕັ້ງຄ່າການຊິ້ງຂໍ້ມູນຂອງບັນຊີໄດ້. ຕົວຢ່າງເຊັ່ນ: ມັນຈະສາມາດກວດສອບໄດ້ແອັບຯ People ຖືກຊິ້ງຂໍ້ມູນກັບບັນຊີໃດນຶ່ງແລ້ວຫຼືຍັງ."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"ສະລັບການເປີດ ແລະປິດການຊິ້ງຂໍ້ມູນ"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂການຕັ້ງຄ່າການຊິ້ງຂໍ້ມູນສຳລັບບັນຊີ. ຍົກຕົວຢ່າງ: ມັນສາມາດໃຊ້ເພື່ອເປີດນຳໃຊ້ການຊິ້ງຂໍ້ມູນຂອງ People ແອັບຯກັບບັນຊີໃດນຶ່ງໄດ້."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"ອ່ານສະຖິຕິການຊິ້ງຂໍ້ມູນ"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານສະຖິຕິການຊິ້ງຂໍ້ມູນຂອງບັນຊີໃດນຶ່ງ ຮວມທັງປະຫວັດການຊິ້ງຂໍ້ມູນ ແລະຈຳນວນຂໍ້ມູນທີ່ຖືກຊິ້ງ."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"ອ່ານຂໍ້ມູນຟີດທີ່ສະໝັກໄວ້"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"ອະນຸຍາດໃຫ້ແອັບຯ ດຶງລາຍລະອຽດກ່ຽວກັບຂໍ້ມູນທີ່ກຳລັງຊິ້ງຢູ່."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"ຂຽນຂໍ້ມູນຟີດທີ່ສະໝັກໄວ້"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂຟີດທີ່ຖືກຊິ້ງຂໍ້ມູນເມື່ອໄວໆນີ້ຂອງທ່ານ. ແອັບຯທີ່ເປັນອັນຕະລາຍ ອາດປ່ຽນແປງຟີດຂອງທ່ານທີ່ຊິ້ງມາ."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"ອ່ານຄຳສັບທີ່ທ່ານເພີ່ມໃສ່ວັດຈະນານຸກົມ"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"ອະນຸຍາດແອັບຯອ່ານຄຳສັບ, ຊື່ ແລະປະໂຫຍກທັງໝົດທີ່ຜູ່ໃຊ້ອາດບັນທຶກໄວ້ໃນວັດຈະນານຸກົມຜູ່ໃຊ້."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"ເພີ່ມຄຳສັບໃສ່ວັດຈະນານຸກົມທີ່ຜູ່ໃຊ້ກຳນົດເອງ"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"ອະນຸຍາດໃຫ້ແອັບຯຂຽນຄຳສັບໃໝ່ ໃສ່ວັດຈະນານຸກົມຜູ່ໃຊ້."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"ທົດສອບການເຂົ້າເຖິງບ່ອນຈັດເກັບຂໍ້ມູນທີ່ຖືກປ້ອງກັນໄວ້"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"ທົດສອບການເຂົ້າເຖິງບ່ອນຈັດເກັບຂໍ້ມູນທີ່ຖືກປ້ອງກັນໄວ້"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"ອະນຸຍາດໃຫ້ແອັບຯທົດສອບການອະນຸຍາດຂອງ ບ່ອນຈັດເກັບຂໍ້ມູນ USB ເຊິ່ງຈະຖືກໃຊ້ໃນອຸປະກອນໃນອະນາຄົດ."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"ອະນຸຍາດໃຫ້ແອັບຯ ທົດລອງສິດໃດນຶ່ງສຳລັບ SD card ທີ່ຈະມີໃນອຸປະກອນໃນອະນາຄົດ."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"ແກ້ໄຂ ຫຼືລຶບເນື້ອຫາໃນບ່ອນຈັດເກັບຂໍ້ມູນ USB ຂອງທ່ານ"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"ແກ້ໄຂ ຫຼືລຶບເນື້ອຫາຂອງ SD card ຂອງທ່ານ"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"ອະນຸຍາດໃຫ້ແອັບຯຂຽນຂໍ້ມູນໃສ່ບ່ອນຈັດເກັບຂໍ້ມູນ USB."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"ອະນຸຍາດໃຫ້ແອັບຯຂຽນຂໍ້ມູນລົງໃນ SD card ໄດ້."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"ແກ້ໄຂ/ລຶບ ເນື້ອຫາບ່ອນຈັດເກັບສື່ພາຍໃນ"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂເນື້ອຫາຂອງໂຕເກັບຂໍ້ມູນໃນໂຕເຄື່ອງ."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"ຈັດການພື້ນທີ່ຈັດເກັບເອກະສານ"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"ອະນຸຍາດໃຫ້ແອັບຯຈັດການກັບບ່ອນຈັດເກັບຂໍ້ມູນເອກະສານ."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"ເຂົ້າເຖິງພື້ນທີ່ຈັດເກັບຂໍ້ມູນພາຍນອກຂອງທຸກຜູ່ໃຊ້"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"ອະນຸຍາດໃຫ້ແອັບຯ ເຂົ້າເຖິງພື້ນທີ່ຈັດເກັບຂໍ້ມູນພາຍນອກ ສຳລັບທຸກຜູ່ໃຊ້."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"ເຂົ້າເຖິງໄຟລ໌ cache ຂອງລະບົບ"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານ ແລະຂຽນ ລະບົບໄຟລ໌ແຄດ."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"ສົ່ງ/ຮັບ ການໂທຜ່ານອິນເຕີເນັດ"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"ອະນຸຍາດໃຫ້ແອັບຯ ໃຊ້ບໍລິການ SIP ເພື່ອ ໂທອອກ/ຮັບສາຍ ການໂທຜ່ານອິນເຕີເນັດ."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"ອ່ານປະຫວັດການນຳໃຊ້ເຄືອຂ່າຍ"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານປະຫວັດການນຳໃຊ້ເຄືອຂ່າຍຂອງແອັບຯ ແລະເຄືອຂ່າຍໃດນຶ່ງ."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"ຈັດການນະໂຍບາຍເຄືອຂ່າຍ"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"ອະນຸຍາດໃຫ້ແອັບຯຈັດການກັບນະໂຍບາຍເຄືອຂ່າຍ ແລະກຳນົດກົດລະບຽບສະເພາະຂອງແອັບຯ."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"ແກ້ໄຂການຄຳນວນການນຳໃຊ້ເຄືອຂ່າຍ"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂວິທີການບັນທຶກບັນຊີ ການນຳໃຊ້ເຄືອຂ່າຍຂອງແອັບຯ. ແອັບຯທົ່ວໄປບໍ່ຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"ດັດ​ແປງຊັອກເກັດມາກ"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"ອະ​ນຸ​ຍາດ​ໃຫ້ແອັບຯແກ້ໄຂຊັອກເກັດທີ່ໝາຍໄວ້ສຳລັບກຳນົດເສັ້ນທາງ"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"ເຂົ້າເຖິງການແຈ້ງເຕືອນ"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"ອະນຸຍາດໃຫ້ແອັບຯດຶງຂໍ້ມູນ, ກວດສອບ ແລະລຶບລ້າງການແຈ້ງເຕືອນ ຮວມທັງພວກທີ່ໂພສໂດຍແອັບຯອື່ນໆນຳ."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"ເຊື່ອມໂຍງກັບບໍລິການໂຕຟັງການແຈ້ງເຕືອນ"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງເຊື່ອມໂຍງສ່ວນຕິດຕໍ່ລະດັບເທິງສຸດ ຂອງຜູ່ຟັງບໍລິການການແຈ້ງເຕືອນ. ບໍ່ຈຳເປັນສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"ຮ້ອງຂໍແອັບຯປັບຄ່າທີ່ສະໜອງໂດຍຜູ່ໃຫ້ບໍລິການ"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"ອະ​ນຸ​ຍາດ​ໃຫ້​ເຈົ້າຂອງຮ້ອງຂໍແອັບຯປັບຄ່າທີ່ສະໜອງໂດຍຜູ່ໃຫ້ບໍລິການ. ບໍ່ໜ້າຈະຕ້ອງການສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"ຕິດຕາມເພື່ອສັງເກດສະພາບຂອງເຄືອຂ່າຍ"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັ່ນຕິດຕາມເພື່ອສັງເກດສະພາບຂອງເຄືອຂ່າຍ. ປົກກະຕິແລ້ວແອັບຯທຳມະດາຈະບໍ່ຕ້ອງການໃຊ້."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"ຕັ້ງຄ່າກົດຂອງລະຫັດຜ່ານ"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"ຄວບຄຸມຄວາມຍາວຂອງໂຕອັກສອນທີ່ສາມາດໃຊ້ກັບລະຫັດປົດລັອກໜ້າຈໍ"</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"ຕິດຕາມການພະຍາຍາມປົດລັອກໜ້າຈໍ"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"ຕິດຕາມເບິ່ງຈຳນວນການພິມລະຫັດຜ່ານທີ່ບໍ່ຖືກຕ້ອງ ໃນເວລາປົດລັອກໜ້າຈໍ ແລະລັອກແທັບເລັດ ຫຼືລຶບຂໍ້ມູນທັງໝົດຂອງແທັບເລັດ ຖ້າມີການພິມລະຫັດຜ່ານບໍ່ຖືກຕ້ອງຫຼາຍເທື່ອເກີນໄປ."</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"ຕິດຕາມເບິ່ງຈຳນວນການພິມລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ ໃນເວລາປົດລັອກໜ້າຈໍ ແລະລັອກໂທລະສັບ ຫຼືລຶບຂໍ້ມູນທັງໝົດຂອງໂປລະສັບ ຖ້າມີການພິມລະຫັດຜ່ານບໍ່ຖືກຕ້ອງຫຼາຍເທື່ອເກີນໄປ."</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"ປ່ຽນລະຫັດລັອກໜ້າຈໍ"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"ປ່ຽນລະຫັດປົດລັອກໜ້າຈໍ"</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"ລັອກໜ້າຈໍ"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"ຄວບຄຸມວ່າໜ້າຈໍຄວນຈະຖືກລັອກເມື່ອໃດ ແລະແນວໃດ"</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"ລຶບຂໍ້ມູນທັງໝົດ"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"ລຶບຂໍ້ມູນຂອງແທັບເລັດໂດຍບໍ່ມີການເຕືອນ ໂດຍການຣີເຊັດກັບຄືນໃຫ້ເປັນແບບທີ່ມາຈາກໂຮງງານ."</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"ລຶບຂໍ້ມູນຂອງໂທລະສັບໂດຍບໍ່ມີການເຕືອນ ໂດຍການຣີເຊັດກັບຄືນໃຫ້ເປັນແບບທີ່ມາຈາກໂຮງງານ."</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"ປ່ຽນ proxy ຮວມຂອງອຸປະກອນ"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"ຕັ້ງໃຫ້ພຣັອກຊີສ່ວນກາງຂອງອຸປະກອນ ທີ່ຈະໃຊ້ໃນຂະນະທີ່ເປີດນຳໃຊ້ນະໂຍບາຍ. ສະເເພາະຜູ່ເບິ່ງແຍງອຸປະກອນຄົນທຳອິດເທົ່ານັ້ນ ທີ່ຈະຕັ້ງຄ່າພຣັອກຊີສ່ວນກາງທີ່ມີຜົນນຳໃຊ້ໄດ້."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"ຕັ້ງວັນໝົດກຳນົດຂອງລະຫັດລັອກໜ້າຈໍ"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"ຄວບຄຸມຄວາມຖີ່ໃນການປ່ຽນລະຫັດໜ້າຈໍລັອກ."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"ຕັ້ງຄ່າການເຂົ້າລະຫັດທີ່ເກັບຂໍ້ມູນ"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"ຮຽກຮ້ອງໃຫ້ມີການເຂົ້າລະຫັດຂໍ້ມູນທີ່ຈັດເກັບໃນແອັບຯ"</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"ປິດການໃຊ້ກ້ອງ"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"ຫ້າມການໃຊ້ກ້ອງຈາກທຸກອຸປະກອນ."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"ປິດການນຳໃຊ້ການລັອກປຸ່ມ"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"ປ້ອງກັນການໃຊ້ຄວາມສາມາດບາງສ່ວນໃນການລັອກປຸ່ມ."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"ເຮືອນ"</item>
-    <item msgid="869923650527136615">"ມືຖື"</item>
-    <item msgid="7897544654242874543">"ວຽກ"</item>
-    <item msgid="1103601433382158155">"ແຟັກບ່ອນເຮັດວຽກ"</item>
-    <item msgid="1735177144948329370">"ແຟັກເຮືອນ"</item>
-    <item msgid="603878674477207394">"ເພກເຈີ"</item>
-    <item msgid="1650824275177931637">"ອື່ນໆ"</item>
-    <item msgid="9192514806975898961">"ກຳນົດເອງ"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"ເຮືອນ"</item>
-    <item msgid="7084237356602625604">"ວຽກ"</item>
-    <item msgid="1112044410659011023">"ອື່ນໆ"</item>
-    <item msgid="2374913952870110618">"ກຳນົດເອງ"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"ເຮືອນ"</item>
-    <item msgid="5629153956045109251">"ວຽກ"</item>
-    <item msgid="4966604264500343469">"ອື່ນໆ"</item>
-    <item msgid="4932682847595299369">"ກຳນົດເອງ"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"ເຮືອນ"</item>
-    <item msgid="1359644565647383708">"ບ່ອນເຮັດວຽກ"</item>
-    <item msgid="7868549401053615677">"ອື່ນໆ"</item>
-    <item msgid="3145118944639869809">"ກຳນົດເອງ"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"ບ່ອນເຮັດວຽກ"</item>
-    <item msgid="4378074129049520373">"ອື່ນໆ"</item>
-    <item msgid="3455047468583965104">"ກຳນົດເອງ"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"ກຳນົດເອງ"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"ເຮືອນ"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"ມືຖື"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"ບ່ອນເຮັດວຽກ"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"ແຟັກບ່ອນເຮັດວຽກ"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"ແຟັກເຮືອນ"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"ເພກເຈີ"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"ອື່ນໆ"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"ໂທກັບ"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"ລົດ"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"ເບີໂທຫຼັກບໍລິສັດ"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"ຫຼັກ"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"ແຟັກອື່ນໆ"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"ວິທະຍຸ"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"ໂທລະສານ"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"ໂທລະສັບມືຖືບ່ອນເຮັດວຽກ"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"ເພກເຈີບ່ອນເຮັດວຽກ"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"ຜູ່ຊ່ວຍ"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"ກຳນົດເອງ"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"ວັນເດືອນປີເກີດ"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"ວັນຄົບຮອບ"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"ອື່ນໆ"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"ກຳນົດເອງ"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"ເຮືອນ"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"ວຽກ"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"ອື່ນໆ"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"ມືຖື"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"ກຳນົດເອງ"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"ເຮືອນ"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"ຫ້ອງການ"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"ອື່ນໆ"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"ກຳນົດເອງ"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"ເຮືອນ"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"ວຽກ"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"ອື່ນໆ"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"ກຳນົດເອງ"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Hangouts"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"ວຽກ"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"ອື່ນໆ"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"ກຳນົດເອງ"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"ກຳນົດເອງ"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"ຜູ່ຊ່ວຍ"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"ອ້າຍ-ນ້ອງ"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"ລູກ"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"ຮຸ້ນສ່ວນພາຍໃນ"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"ພໍ່"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"ໝູ່ເພື່ອນ"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"ຜູ່ຈັດການ"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"ແມ່"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"ພໍ່ແມ່"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"ຮຸ້ນສ່ວນ"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"ແນະນຳໂດຍ"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"ຍາດຕິພີ່ນ້ອງ"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"ເອື້ອຍ-ນ້ອງ"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"ຜົວເມຍ"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"ກຳນົດເອງ"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"ເຮືອນ"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"ບ່ອນເຮັດວຽກ"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"ອື່ນໆ"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"ພິມລະຫັດ PIN"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"ພິມລະຫັດ PUK ແລະ​ລະ​ຫັດ PIN ອັນໃໝ່"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"ລະ​ຫັດ PUK"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"ລະຫັດ PIN ໃໝ່"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"ແຕະເພື່ອພິມລະຫັດຜ່ານ"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"ພິມລະຫັດເພື່ອປົດລັອກ"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"ພິມລະຫັດ PIN ເພື່ອປົດລັອກ"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"ລະຫັດ PIN ບໍ່ຖືກຕ້ອງ."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"ເພື່ອປົດລັອກ, ໃຫ້ກົດເມນູ ແລ້ວກົດ 0."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"ເບີໂທສຸກເສີນ"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"ບໍ່ມີບໍລິການ."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"ລັອກໜ້າຈໍແລ້ວ."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"ກົດ ເມນູ ເພື່ອປົດລັອກ ຫຼື ໂທອອກຫາເບີສຸກເສີນ."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"ກົດ \"ເມນູ\" ເພື່ອປົດລັອກ."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"ແຕ້ມຮູບແບບເພື່ອປົດລັອກ"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"ໂທສຸກເສີນ"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"ກັບໄປຫາການໂທ"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"ຖືກຕ້ອງ!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"ລອງໃໝ່ອີກຄັ້ງ"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"ທົດລອງອີກຄັ້ງ"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"ຄວາມພະຍາຍາມປົດລັອກດ້ວຍໜ້ານັ້ນ ເກີນຈຳນວນທີ່ກຳນົດແລ້ວ"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"ກຳລັງສາກ <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"ສາກເຕັມແລ້ວ."</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"ເຊື່ອມຕໍ່ສາຍສາກຂອງທ່ານ."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"ບໍ່ມີ SIM card."</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"ບໍ່ມີຊິມກາດໃນແທັບເລັດ."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"ບໍ່ມີ SIM card ໃນໂທລະສັບ."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"ໃສ່ຊິມກາດ."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"ບໍ່ມີຊິມກາດ ຫຼືອ່ານຊິມກາດບໍ່ໄດ້. ໃສ່ຊິມກາດ."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"SIM card ບໍ່ສາມາດໃຊ້ໄດ້."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"ຊິມກາດຂອງທ່ານຖືກປິດການນຳໃຊ້ຢ່າງຖາວອນແລ້ວ.\n ກະລຸນາຕິດຕໍ່ຜູ່ໃຫ້ບໍລິການໂທລະສັບຂອງທ່ານ ເພື່ອຂໍເອົາຊິມກາດໃໝ່."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"ປຸ່ມເພງກ່ອນໜ້ານີ້"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"ປຸ່ມເພງຕໍ່ໄປ"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"ປຸ່ມຢຸດຊົ່ວຄາວ"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"ປຸ່ມຫຼິ້ນ"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"ປຸ່ມຢຸດ"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"ສຳລັບການໂທສຸກເສີນເທົ່ານັ້ນ"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"ເຄືອຂ່າຍຖືກລັອກ"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM card ຖືກລັອກດ້ວຍລະຫັດ PUK."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"ເບິ່ງຄູ່ມືຜູ່ໃຊ້ ຫຼືຕິດຕໍ່ສູນບໍລິການລູກຄ້າ."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM card ຖືກລັອກ."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"ກຳລັງປົດລັອກຊິມກາດ..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"ທ່ານແຕ້ມຮູບແບບປົດລັອກບໍ່ຖືກ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"ທ່ານພິມລະຫັດຜ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nໃຫ້ລອງໃໝ່ອີກຄັ້ງໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"ທ່ານພິມລະຫັດ PIN ຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ທ່ານຈະຖືກຖາມໃຫ້ປົດລັອກແທັບເລັດຂອງທ່ານ ດ້ວຍການເຂົ້າສູ່ລະບົບຂອງ Google.\n\n ລອງໃໝ່ອີກຄັ້ງໃນ <xliff:g id="NUMBER_2">%d</xliff:g> ວິນາທີ."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກແຕ້ມຜິດອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ, ທ່ານຈະຖືກຖາມໃຫ້ປົດລັອກໂທລະສັບຂອງທ່ານ ດ້ວຍການເຂົ້າສູ່ລະບົບ Google.\n\n ລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_2">%d</xliff:g> ວິນາທີ."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"ທ່ານພະຍາຍາມປັດລັອກແທັບເລັດຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຜິດອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ, ແທັບເລັດຈະຖືກຣີເຊັດໃຫ້ເປັນແບບທີ່ມາຈາກໂຮງງານ ແລະຂໍ້ມູນທັງໝົດຈະຖືກຫາຍໄປ."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກໂທລະສັບເປັນຈຳນວນ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກການພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອແລ້ວບໍ່ສຳເລັດຜົນ, ໂທລະສັບຈະຖືກຕັ້ງຄ່າໃຫ້ເປັນຄ່າຈາກໂຮງງານ ແລະຂໍ້ມູນທັງໝົດຈະສູນຫາຍໄປ."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"ທ່ານພະຍາຍາມປົດລັອກແທັບເລັດຜິດ <xliff:g id="NUMBER">%d</xliff:g> ເທື່ອແລ້ວ. ຕອນນີ້ແທັບເລັດຈະຖືກຣີເຊັດເປັນຄ່າຈາກໂຮງງານ."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກໂທລະສັບຜິດ <xliff:g id="NUMBER">%d</xliff:g> ເທື່ອແລ້ວ. ໂທລະສັບຈະຖືກຣີເຊັດໃຫ້ເປັນຄ່າທີ່ມາຈາກໂຮງງານ."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"ທົດລອງອີກຄັ້ງໃນອີກ <xliff:g id="NUMBER">%d</xliff:g> ວິນາທີ."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"ລືມຮູບແບບປົດລັອກ?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"ປົດລັອກບັນຊີ"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"ພະຍາຍາມໃຊ້ຮູບແບບປົດລັອກຜິດຫຼາຍເທື່ອເກີນໄປ"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"ເພື່ອປົດລັອກ, ໃຫ້ເຂົ້າສູ່ລະບົບດ້ວຍບັນຊີ Google ຂອງທ່ານ."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"ຊື່ຜູ່ໃຊ້ (ອີເມວ)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"ລະຫັດຜ່ານ"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"ເຂົ້າສູ່ລະບົບ"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"ຊື່ຜູ່ໃຊ້ ຫຼືລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ"</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"ລືມຊື່ຜູ່ໃຊ້ ຫຼືລະຫັດຜ່ານຂອງທ່ານບໍ?\nໄປທີ່ "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"ກຳລັງກວດສອບ..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"ປົດລັອກ"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"ເປີດສຽງແລ້ວ"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"ປິດສຽງ"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"ຮູບແບບເລີ່ມຕົ້ນແລ້ວ"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"ລຶບລ້າງຮູບແບບແລ້ວ"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"ຕາລາງຖືກເພີ່ມແລ້ວ"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"ຮູບແບບສຳເລັດແລ້ວ"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. ວິດເຈັດ %2$d ຈາກທັງໝົດ %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"ເພີ່ມວິດເຈັດ"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"ຫວ່າງເປົ່າ"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"ຂະຫຍາຍພື້ນທີ່ປົດລັອກແລ້ວ."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"ຫຍໍ້ພື້ນທີ່ປົດລັອກແລ້ວ."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ວິດເຈັດ."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"ໂຕເລືອກຂອງຜູ່ໃຊ້"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"ສະຖານະ"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"ກ້ອງ"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"ການຄວບຄຸມສື່"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"ການຈັດຮຽງວິເຈັດໃໝ່ເລີ່ມຕົ້ນແລ້ວ."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"ການຈັດຮຽງວິດເຈັດຄືນໃໝ່ສຳເລັດແລ້ວ."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"ລຶບວິດເຈັດ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ແລ້ວ."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"ຂະຫຍາຍຂອບເຂດປົດລັອກ."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"ການປົດລັອກດ້ວຍການເລື່ອນ."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"ປົດລັອກດ້ວຍຮູບແບບ."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"ປົດລັອກດ້ວຍໜ້າ."</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"ປົດລັອກດ້ວຍ PIN."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"ການປົດລັອກດ້ວຍລະຫັດຜ່ານ."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ພື້ນທີ່ຮູບແບບ."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"ເລື່ອນພື້ນທີ່."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"ໂຕອັກສອນ"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"ຄຳສັບ"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"ລິ້ງ"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"ເສັ້ນ"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"ການທົດສອບຈາກໂຮງງານລົ້ມເຫລວ"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"ການເຮັດ FACTORY_TEST ຮອງຮັບສະເພາະແພັກເກດທີ່ຖືກຕິດຕັ້ງໃນ /system/app ເທົ່ານັ້ນ."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"ບໍ່ພົບແພັກເກດທີ່ມີການເຮັດວຽກ FACTORY_TEST."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"ຣີບູດ"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"ໜ້າທີ່ຢູ່ທີ່ \"<xliff:g id="TITLE">%s</xliff:g>\" ເວົ້າວ່າ:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"ຢືນຢັນການນຳທາງ"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"ອອກຈາກໜ້ານີ້"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"ຢູ່ທີ່ໜ້ານີ້ຕໍ່ໄປ"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nທ່ານແນ່ໃຈບໍ່ວ່າຕ້ອງການອອກໄປຈາກໜ້ານີ້?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"ຢືນຢັນ"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"ເຄັດລັບ: ແຕະສອງຄັ້ງເພື່ອຊູມເຂົ້າ ແລະຊູມອອກ."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"ຕື່ມຂໍ້ມູນອັດຕະໂນມັດ"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"ຕັ້ງການຕື່ມຂໍ້ມູນອັດຕະໂນມັດ"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"ແຂວງ"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"ລະຫັດໄປສະນີ"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"ລັດ"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ລະຫັດ ZIP"</string>
-    <string name="autofill_county" msgid="237073771020362891">"ປະເທດ"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"ເກາະ"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"ເມືອງ"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"ພະແນກ"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"ເຂດປົກຄອງ"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"ເຂດການປົກຄອງທ້ອງຖິ່ນ"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"ພື້ນທີ່"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"ອີມິເຣດ"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"ອ່ານບຸກມາກ ແລະປະຫວັດເວັບໄຊຂອງທ່ານ"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"ອະນຸຍາດໃຫ້ແອັບຯ ອ່ານປະຫວັດຂອງ URL ທັງໝົດທີ່ໂປຣແກຣມທ່ອງເວັບເຄີຍເຂົ້າເບິ່ງ ຮວມທັງ ບຸກມາກທັງໝົດຂອງໂປຣແກຣມທ່ອງເວັບນຳ. ໝາຍເຫດ: ການກຳນົດສິດນີ້ ອາດບໍ່ໄດ້ບັງຄັບໃຊ້ໃນໂປຣແກຣມທ່ອງເວັບພາກສ່ວນທີສາມ ຫຼືແອັບພລິເຄຊັນອື່ນທີ່ມີຄວາມສາມາດທ່ອງເວັບ."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"ຂຽນຂໍ້ມູນບຸກມາກ ແລະປະຫວັດເວັບໄຊ"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂປະຫວັດໃນການທ່ອງເວັບ ຫຼືບຸກມາກທີ່ບັນທຶກໃນແທັບເລັດຂອງທ່ານ. ນີ້ອາດອະນຸຍາດໃຫ້ແອັບຯລຶບ ຫຼືແກ້ໄຂຂໍ້ມູນໂປຣແກຣມທ່ອງເວັບໄດ້. ໝາຍເຫດ: ການອະນຸຍາດນີ້ອາດເປັນຜົນບັງຄັບໃຊ້ ຈາກໂປຣແກຣມທ່ອງເວັບພາຍນອກ ຫຼືແອັບພລິເຄຊັນອື່ນທີ່ສາມາດເຂົ້າເວັບໄດ້."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"ອະນຸຍາດໃຫ້ແອັບຯ ແກ້ໄຂປະຫວັດໂປຣແກຣມທ່ອງເວັບ ຫຼືບຸກມາກທີ່ເກັບໄວ້ໃນໂທລະສັບຂອງທ່ານ. ນີ້ອາດອະນຸຍາດໃຫ້ແອັບຯລຶບ ຫຼືແກ້ໄຂຂໍ້ມູນໂປຣແກຣມທ່ອງເວັບ. ໝາຍເຫດ: ການກຳນົດສິດນີ້ ອາດບໍ່ໄດ້ຖືກບັງຄັບໃຊ້ໃນໂປຣແກຣມທ່ອງເວັບພາກສ່ວນທີສາມ ຫຼືແອັບພລິເຄຊັນອື່ນທີ່ມີຄວາມສາມາດທ່ອງເວັບ."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"ຕັ້ງການແຈ້ງເຕືອນ"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"ອະນຸຍາດໃຫ້ແອັບຯຕັ້ງໂມງປຸກໃນແອັບຯໂມງປຸກທີ່ຕິດຕັ້ງໄວ້. ບາງແອັບຯໂມງປຸກອາດບໍ່ມີຄຸນສົມບັດແບບນີ້ເທື່ອ."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"ເພີ່ມຂໍ້ຄວາມສຽງ"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"ອະນຸຍາດໃຫ້ແອັບຯ ສາມາດເພີ່ມຂໍ້ຄວາມໃສ່ອິນບັອກຂໍ້ຄວາມສຽງຂອງທ່ານໄດ້."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"ແກ້ໄຂສິດທາງສະຖານທີ່ພູມສາດຂອງໂປຣແກຣມທ່ອງເວັບ"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂ ການອະນຸຍາດຕຳແໜ່ງທາງພູມສາດ ຂອງໂປຣແກຣມທ່ອງເວັບ. ແອັບຯທີ່ເປັນອັນຕະລາຍອາດໃຊ້ຄຸນສົມບັດນີ້ ເພື່ອສົ່ງຂໍ້ມູນສະຖານທີ່ໄປໃຫ້ເວັບໄຊຕ່າງໆໄດ້."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"ຢັ້ງຢືນແພັກເກດ"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"ອະນຸຍາດໃຫ້ແອັບຯຢືນຢັນວ່າແພັກເກດໃດນຶ່ງ ສາມາດຕິດຕັ້ງໄດ້."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"ເຊື່ອມໂຍງກັບໂຕຢືນຢັນແພັກເກດ"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງເຮັດການຮ້ອງຂໍໂຕຢືນຢັນແພັກເກັດ. ບໍ່ຈຳເປັນສຳລັບແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"ເຂົ້າເຖິງພອດຊີຣຽວ"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງສາມາດເຂົ້າເບິ່ງ serial ports ໂດຍການນຳໃຊ້ SerialManager API."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"ເຂົ້າເຖິງຜູ່ສະໜອງເນື້ອຫາພາຍນອກ"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"ຊ່ວຍໃຫ້ເຈົ້າຂອງສາມາດ ເຂົ້າເຖິງຜູ່ໃຫ້ບໍລິການເນື້ອຫາຈາກໜ້າ shell ໄດ້. ແອັບພລິເຄຊັນທົ່ວໄປບໍ່ຄວນຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"ປ້ອງກັນການອັບເດດອຸປະກອນໂດຍອັດຕະໂນມັດ"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"ອະນຸຍາດໃຫ້ເຈົ້າຂອງກຳນົດຂໍ້ມູນໃນລະບົບ ກ່ຽວກັບເວລາທີ່ເໝາະສົມໃນການຣີບູດແບບບໍ່ໂຕ້ຕອບ ເພື່ອອັບເກຣດອຸປະກອນ."</string>
-    <string name="save_password_message" msgid="767344687139195790">"ທ່ານຕ້ອງການໃຫ້ໂປຣແກຣມທ່ອງເວັບນີ້ຈື່ລະຫັດຜ່ານນີ້ບໍ່?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"ບໍ່ແມ່ນຕອນນີ້"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"ຈື່ໄວ້"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"ບໍ່ຕ້ອງຈື່"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"ທ່ານບໍ່ໄດ້ຮັບອະນຸຍາດໃຫ້ເປີດໜ້ານີ້."</string>
-    <string name="text_copied" msgid="4985729524670131385">"ສຳເນົາຂໍ້ຄວາມໃສ່ຄລິບບອດແລ້ວ."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"ເພີ່ມເຕີມ"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"ເມນູ+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"Space"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"enter"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"ລຶບ"</string>
-    <string name="search_go" msgid="8298016669822141719">"ຊອກຫາ"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"ຊອກຫາ"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"ຊອກຫາ"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"ລຶບຂໍ້ຄວາມຊອກຫາ"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"ສົ່ງການຊອກຫາ"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"ຊອກຫາດ້ວຍສຽງ"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"ເປີດນຳໃຊ້ \"ການສຳຫຼວດໂດຍສຳພັດ\" ບໍ່?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ຕ້ອງການເປີດນຳໃຊ້ \"ການສຳຫຼວດໂດຍສຳພັດ\". ເມື່ອເປີດ \"ການສຳຫຼວດໂດຍສຳພັດ\" ແລ້ວ ທ່ານຈະສາມາດໄດ້ຍິນ ຫຼືເຫັນຄຳບັນຍາຍວ່າມີຫຍັງຢູ່ກ້ອງນິ້ວມືຂອງທ່ານ ຫຼືໃຊ້ຮູບແບບການເຄື່ອນໄຫວເພື່ອໂຕ້ຕອບກັບແທັບເລັດ."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ຕ້ອງການເປີດນຳໃຊ້ \"ການສຳຫຼວດໂດຍສຳພັດ\". ເມື່ອເປີດ \"ການສຳຫຼວດໂດຍສຳພັດ\" ແລ້ວ ທ່ານຈະສາມາດໄດ້ຍິນ ຫຼືເຫັນຄຳບັນຍາຍວ່າມີຫຍັງຢູ່ກ້ອງນິ້ວມືຂອງທ່ານ ຫຼືໃຊ້ຮູບແບບການເຄື່ອນໄຫວເພື່ອໂຕ້ຕອບກັບໂທລະສັບ."</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"1 ເດືອນກ່ອນຫນ້ານີ້"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"ຫຼາຍກວ່າ 1 ເດືອນກ່ອນ"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"1 ວິນາທີກ່ອນ"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> ວິນາທີກ່ອນໜ້ານີ້"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"1 ນາທີກ່ອນໜ້ານີ້"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> ນາ​ທີ​ທີ່ຜ່ານມາ"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"1 ຊົ່ວໂມງກ່ອນໜ້ານີ້"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> ຊົ່ວໂມງທີ່ຜ່ານມາ"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"<xliff:g id="COUNT">%d</xliff:g> ມື້ທີ່ຜ່ານມາ"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"ເດືອນແລ້ວ"</string>
-    <string name="older" msgid="5211975022815554840">"ເກົ່າກວ່າ"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"ມື້​ວານ​ນີ້"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> ມື້​ກ່ອນ"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"ໃນອີກ 1 ວິນາທີ"</item>
-    <item quantity="other" msgid="1241926116443974687">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ວິ​ນາ​ທີ"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"ໃນ 1 ນາທີ"</item>
-    <item quantity="other" msgid="3330713936399448749">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ນາທີ"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"ໃນ 1 ຊົ່ວໂມງ"</item>
-    <item quantity="other" msgid="547290677353727389">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ຊົ່ວໂມງ"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"ມື້ອື່ນ"</item>
-    <item quantity="other" msgid="5109449375100953247">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ມື້"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"1 ວິນາທີກ່ອນ"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> ວິ ກ່ອນໜ້ານີ້"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"1 ນທ ກ່ອນ"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> ນທ ກ່ອນໜ້ານີ້"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"1 ຊົ່ວໂມງກ່ອນ"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> ຊົ່ວໂມງກ່ອນໜ້ານີ້"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"ມື້ວານນີ້"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> ມື້ກ່ອນໜ້ານີ້"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"ໃນ 1 ວິ"</item>
-    <item quantity="other" msgid="5495880108825805108">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ວິ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"ໃນ 1 ນາທີ"</item>
-    <item quantity="other" msgid="4216113292706568726">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ນທ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"ໃນ 1 ຊົ່ວໂມງ"</item>
-    <item quantity="other" msgid="3705373766798013406">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ຊົ່ວໂມງ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"ມື້ອື່ນ"</item>
-    <item quantity="other" msgid="2973062968038355991">"ໃນ <xliff:g id="COUNT">%d</xliff:g> ມື້"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"ວັນທີ <xliff:g id="DATE">%s</xliff:g>"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"ເວລາ <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"ໃນ <xliff:g id="YEAR">%s</xliff:g>"</string>
-    <string name="day" msgid="8144195776058119424">"ມື້"</string>
-    <string name="days" msgid="4774547661021344602">"ມື້"</string>
-    <string name="hour" msgid="2126771916426189481">"ຊົ່ວໂມງ"</string>
-    <string name="hours" msgid="894424005266852993">"ຊົ່ວໂມງ"</string>
-    <string name="minute" msgid="9148878657703769868">"ນາທີ"</string>
-    <string name="minutes" msgid="5646001005827034509">"ນທ"</string>
-    <string name="second" msgid="3184235808021478">"ວິ"</string>
-    <string name="seconds" msgid="3161515347216589235">"ວິ"</string>
-    <string name="week" msgid="5617961537173061583">"ອາທິດ"</string>
-    <string name="weeks" msgid="6509623834583944518">"ອາທິດ"</string>
-    <string name="year" msgid="4001118221013892076">"ປີ"</string>
-    <string name="years" msgid="6881577717993213522">"ປິ"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 ວິນາທີ"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> ວິນາທີ"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"1 ນາ​ທີ"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> ນາທີ"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"1 ຊົ່ວ​ໂມງ"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> ຊົ່ວໂມງ"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"ບັນຫາວິດີໂອ"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"ວິດີໂອນີ້ບໍ່ຖືກຕ້ອງສຳລັບການສະແດງໃນອຸປະກອນນີ້."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"ບໍ່ສາມາດຫຼິ້ນວິດີໂອນີ້ໄດ້."</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"ຕົກລົງ"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"ທ່ຽງ"</string>
-    <string name="Noon" msgid="3342127745230013127">"ທ່ຽງ"</string>
-    <string name="midnight" msgid="7166259508850457595">"ທ່ຽງຄືນ"</string>
-    <string name="Midnight" msgid="5630806906897892201">"ທ່ຽງຄືນ"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"ເລືອກທັງໝົດ"</string>
-    <string name="cut" msgid="3092569408438626261">"ຕັດ"</string>
-    <string name="copy" msgid="2681946229533511987">"ສຳເນົາ"</string>
-    <string name="paste" msgid="5629880836805036433">"ວາງ"</string>
-    <string name="replace" msgid="5781686059063148930">"ແທນທີ່…"</string>
-    <string name="delete" msgid="6098684844021697789">"ລຶບ"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"ສຳເນົາ URL"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"ເລືອກຂໍ້ຄວາມ"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"ການເລືອກຂໍ້ຄວາມ"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"ເພີ່ມໄປທີ່ວັດຈະນານຸກົມ"</string>
-    <string name="deleteText" msgid="6979668428458199034">"ລຶບ"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"ຮູບແບບການປ້ອນຂໍ້ມູນ"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"ການເຮັດວຽກຂອງຂໍ້ຄວາມ"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"ພື້ນທີ່ຈັດເກັບຂໍ້ມູນກຳລັງຈະເຕັມ"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"ການເຮັດວຽກບາງຢ່າງຂອງລະບົບບາງອາດຈະໃຊ້ບໍ່ໄດ້"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> ກຳລັງເຮັດວຽກຢູ່"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"ແຕະເພື່ອເບິ່ງຂໍ້ມູນເພີ່ມເຕີມ ຫຼືເພື່ອຢຸດການເຮັດວຽກຂອງແອັບຯນີ້."</string>
-    <string name="ok" msgid="5970060430562524910">"ຕົກລົງ"</string>
-    <string name="cancel" msgid="6442560571259935130">"ຍົກເລີກ"</string>
-    <string name="yes" msgid="5362982303337969312">"ຕົກລົງ"</string>
-    <string name="no" msgid="5141531044935541497">"ຍົກເລີກ"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"ກະລຸນາຮັບຊາບ"</string>
-    <string name="loading" msgid="7933681260296021180">"ກຳລັງໂຫລດ..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"ເປີດ"</string>
-    <string name="capital_off" msgid="6815870386972805832">"ປິດ"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"ເຮັດວຽກໃຫ້ສຳເລັດໂດຍໃຊ້"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"ໃຊ້ໂດຍຄ່າເລີ່ມຕົນສຳລັບການເຮັດວຽກນີ້."</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"ລຶບລ້າງຄ່າເລີ່ມຕົ້ນ ໃນ ການຕັ້ງຄ່າລະບົບ &gt; ແອັບຯ &gt; ດາວໂຫລດແລ້ວ."</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"ເລືອກການປະຕິບັດ"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"ເລືອກແອັບຯສໍາລັບອຸປະກອນ USB"</string>
-    <string name="noApplications" msgid="2991814273936504689">"ບໍ່ມີແອັບຯໃດສາມາດເຮັດວຽກນີ້ໄດ້."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"ຂໍອະໄພ, <xliff:g id="APPLICATION">%1$s</xliff:g> ຢຸດການເຮັດວຽກແລ້ວ."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"ຂໍອະໄພ, ໂປຣເຊສ <xliff:g id="PROCESS">%1$s</xliff:g> ໄດ້ຢຸດການເຮັດວຽກແລ້ວ."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> ບໍ່ຕອບສະໜອງ. \n\nທ່ານຕ້ອງການປິດມັນບໍ່?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"ການເຮັດວຽກ <xliff:g id="ACTIVITY">%1$s</xliff:g> ບໍ່ຕອບສະໜອງ. \n\n ທ່ານຕ້ອງການທີ່ຈະປິດມັນບໍ່?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> ບໍ່ຕອບສະໜອງ. ທ່ານຕ້ອງການປິດມັນບໍ່?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"ໂປຣເຊສ <xliff:g id="PROCESS">%1$s</xliff:g> ບໍ່ຕອບສະໜອງ. \n\n ທ່ານຕ້ອງການປິດມັນບໍ່?"</string>
-    <string name="force_close" msgid="8346072094521265605">"ຕົກລົງ"</string>
-    <string name="report" msgid="4060218260984795706">"ລາຍງານ"</string>
-    <string name="wait" msgid="7147118217226317732">"ລໍ​ຖ້າ"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"ໜ້າເວັບບໍ່ຕອບສະໜອງ.\n\nທ່ານຕ້ອງການທີ່ຈະປິດມັນບໍ່?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"ແອັບຯຖືກປ່ຽນເສັ້ນທາງ"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> ກຳລັງເຮັດວຽກຢູ່."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ເປີດໃຊ້ໄວ້ແລ້ວ."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"ຂະໜາດ"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"ສະແດງຕະຫຼອດເວລາ"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"ເປີດການເຮັດວຽກນີ້ຄືນໄດ້ໃນ ການຕັ້ງຄ່າລະບົບ &gt; ແອັບຯ &gt; ດາວໂຫລດແລ້ວ"</string>
-    <string name="smv_application" msgid="3307209192155442829">"ແອັບຯ <xliff:g id="APPLICATION">%1$s</xliff:g> (ໂປຣເຊສ <xliff:g id="PROCESS">%2$s</xliff:g>) ໄດ້ລະເມີດນະໂຍບາຍ StrictMode ທີ່ບັງຄັບໃຊ້ດ້ວຍໂຕເອງ."</string>
-    <string name="smv_process" msgid="5120397012047462446">"ໂປຣເຊສ <xliff:g id="PROCESS">%1$s</xliff:g> ລະເມີດນະໂຍບາຍບັງຄັບໃຊ້ເອງ StrictMode."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"ກຳລັງອັບເກຣດ Android..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"ກຳລັງປັບປຸງປະສິດຕິພາບແອັບຯທີ <xliff:g id="NUMBER_0">%1$d</xliff:g> ຈາກທັງໝົດ <xliff:g id="NUMBER_1">%2$d</xliff:g>."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"ກຳລັງເປີດແອັບຯ."</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"ກຳລັງສຳເລັດການເປີດລະບົບ."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> ກຳລັງເຮັດວຽກ"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"ແຕະເພື່ອສະລັບກັບໄປຫາແອັບຯ"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"ສະລັບແອັບຯບໍ່?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"ທ່ານຈະຕ້ອງຢຸດນຳໃຊ້ແອັບຯໂຕອື່ນກ່ອນ ກ່ອນທີ່ທ່ານຈະເປີດໃຊ້ແອັບຯໃໝ່ໄດ້."</string>
-    <string name="old_app_action" msgid="493129172238566282">"ກັບໄປ <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"ຫ້າມເປີດແອັບຯໃໝ່."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"ເລີ່ມຕົ້ນ <xliff:g id="OLD_APP">%1$s</xliff:g>"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"ຢຸດແອັບຯເກົ່າໂດຍບໍ່ຕ້ອງບັນທຶກ."</string>
-    <string name="sendText" msgid="5209874571959469142">"ເລືອກການເຮັດວຽກຂອງຂໍ້ຄວາມ"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"ລະດັບສຽງເອີ້ນເຂົ້າ"</string>
-    <string name="volume_music" msgid="5421651157138628171">"ລະດັບສຽງຂອງສື່"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"ກຳລັງຫຼິ້ນຜ່ານ Bluetooth"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"ຕັ້ງໃຫ້ບໍ່ມີສຽງເອີ້ນເຂົ້າ"</string>
-    <string name="volume_call" msgid="3941680041282788711">"ລະດັບສຽງໃນການໂທ"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"ລະດັບບສຽງ Bluetooth ໃນຂະນະໂທ"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"ລະດັບສຽງແຈ້ງເຕືອນ"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"ລະດັບສຽງແຈ້ງເຕືອນ"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"ລະດັບສຽງ"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"ສຽງຂອງ Bluetooth"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"ລະດັບສຽງເອີ້ນເຂົ້າ"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"ລະດັບສຽງການໂທ"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"ລະດັບສຽງຂອງສື່"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"ລະດັບສຽງການແຈ້ງເຕືອນ"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"ຣິງໂທນເລີ່ມຕົ້ນ"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"ຣິງໂທນເລີ່ມຕົ້ນ (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"ບໍ່ມີ"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"ຣິງໂທນ"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"ຣິງໂທນທີ່ບໍ່ຮູ້ຈັກ"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"ເຄືອຂ່າຍ Wi-Fi ທີ່ພົບ"</item>
-    <item quantity="other" msgid="4192424489168397386">"ມີເຄືອຂ່າຍ Wi​-Fi ໃຫ້ໃຊ້"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"ເປີດ Wi-Fi ເຄືອຂ່າຍທີ່ມີ"</item>
-    <item quantity="other" msgid="7915895323644292768">"ເຄືອຂ່າຍ Wi-Fi ແບບເປີດທີ່ພົບ"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"ເຂົ້າສູ່ລະບົບເຄືອຂ່າຍ Wi-Fi"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"ເຂົ້າສູ່ລະບົບເຄືອຂ່າຍ"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"ບໍ່ສາມາດເຊື່ອມຕໍ່ Wi-Fi ໄດ້"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" ມີສັນຍານອິນເຕີເນັດທີ່ບໍ່ດີ."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"Wi-Fi Direct"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"ເລີ່ມ Wi-Fi Direct. ນີ້ຈະເປັນການປິດ Wi-Fi client/hotspot."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"ບໍ່ສາມາດເລີ່ມ Wi-Fi Direct ໄດ້."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"ເປີດໃຊ້ Wi-Fi Direct ແລ້ວ"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"ແຕະເພື່ອຕັ້ງຄ່າ"</string>
-    <string name="accept" msgid="1645267259272829559">"ຍອມຮັບ"</string>
-    <string name="decline" msgid="2112225451706137894">"ປະຕິເສດ"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"ການ​ເຊື້ອ​ເຊີນ​ຖືກສົ່ງໄປແລ້ວ"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"ການເຊີນຊວນເພື່ອເຊື່ອມຕໍ່"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"ຈາກ:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"ຈາກ:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"ພິມລະຫັດ PIN:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"ແທັບເລັດຈະຖືກຕັດການເຊື່ອມຕໍ່ຈາກ Wi-Fi ເປັນການຊົ່ວຄາວ ໃນຂະນະທີ່ມັນເຊື່ອມຕໍ່ກັບ <xliff:g id="DEVICE_NAME">%1$s</xliff:g> ຢູ່."</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"ໂທລະສັບຈະຖືກຢຸດການເຊື່ອມຕໍ່ຊົ່ວຄາວຈາກ Wi-Fi ໃນຂະນະທີ່ມັນເຊື່ອມຕໍ່ກັບ <xliff:g id="DEVICE_NAME">%1$s</xliff:g>"</string>
-    <string name="select_character" msgid="3365550120617701745">"ໃສ່ໂຕອັກສອນ"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"ກຳລັງສົ່ງຂໍ້ຄວາມ SMS"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; ກຳລັງສົ່ງຂໍ້ຄວາມ SMS ຈຳນວນຫຼາຍ. ທ່ານຕ້ອງການອະນຸຍາດໃຫ້ແອັບຯສືບຕໍ່ການສົ່ງຂໍ້ຄວາມບໍ່?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"ອະນຸຍາດ"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"ປະຕິເສດ"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; ຕ້ອງການສົ່ງຂໍ້ຄວາມຫາ &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt;."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"ນີ້ "<font fgcolor="#ffffb060">"ອາດເຮັດໃຫ້ເກີດຄ່າໃຊ້ຈ່າຍ"</font>" ໃນບັນຊີມືຖືຂອງທ່ານໄດ້."</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"ມັນຈະເຮັດໃຫ້ທ່ານເສຍຄ່າບໍລິການໃນບັນຊີຂອງທ່ານ."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"ສົ່ງ"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"ຍົກເລີກ"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"ຈື່ການເລືອກຂອງຂ້ອຍ"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"ທ່ານສາມາດປ່ຽນແປງໂຕເລືອກນີ້ໃນພາຍຫຼັງໄດ້ໃນ ການຕັ້ງຄ່າ &gt; ແອັບຯ"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"ອະນຸຍາດທຸກຄັ້ງ"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"ບໍ່ອະນຸຍາດເດັດຂາດ"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"ຖອດ SIM card ອອກແລ້ວ"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"ເຄືອຂ່າຍມືຖືຈະບໍ່ສາມາດໃຊ້ໄດ້ ຈົນກວ່າທ່ານຈະປິດແລ້ວເປີດໃໝ່ພ້ອມກັບໃສ່ SIM card ທີ່ຖືກຕ້ອງ."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"ແລ້ວໆ"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"ເພີ່ມຊິມກາດແລ້ວ"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"ປິດແລ້ວເປີດອຸປະກອນຂອງທ່ານ ເພື່ອເຂົ້າເຖິງເຄືອຂ່າຍມືຖື."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"ຣີສະຕາດ"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"ຕັ້ງເວລາ"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"ກໍານົດວັນທີ"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"ຕັ້ງຄ່າ"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"ແລ້ວໆ"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"ໃໝ່: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"ສະໜອງໂດຍ <xliff:g id="APP_NAME">%1$s</xliff:g> ."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"ບໍ່ຕ້ອງການການອະນຸຍາດ"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"ລາຍການນີ້ອາດມີການເກັບເງິນ"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"ເຊື່ອມຕໍ່ USB ແລ້ວ"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"ທ່ານໄດ້ເຊື່ອມຕໍ່ກັບຄອມພິວເຕີຂອງທ່ານຜ່ານ USB ແລ້ວ. ໃຫ້ແຕະປຸ່ມຂ້າງລຸ່ມຖ້າທ່ານຕ້ອງການສຳເນົາໄຟລ໌ ລະຫວ່າງຄອມພິວເຕີ ແລະບ່ອນຈັດເກັບຂໍ້ມູນ USB ຂອງ Android ທ່ານ."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"ທ່ານໄດ້ເຊື່ອມຕໍ່ກັບຄອມພິວເຕີຂອງທ່ານດ້ວຍ USB ແລ້ວ. ໃຫ້ປຸ່ມທາງດ້ານລຸ່ມນີ້ຫາກທ່ານຕ້ອງການ ທີ່ຈະສຳເນົາໄຟລ໌ຂໍ້ມູນລະຫວ່າງຄອມພິວເຕີ ແລະ SD card ຂອງ Android ຂອງທ່ານ."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"ເປີດ ບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"ມີບັນຫາໃນການໃຊ້ບ່ອນຈັດເກັບຂໍ້ມູນ USB ຂອງທ່ານເປັນບ່ອນຈັດເກັບຂໍ້ມູນຈຳນວນຫຼາຍດ້ວຍ USB."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"ມີບັນຫາໃນການໃຊ້ SD card ຂອງທ່ານເປັນບ່ອນຈັດເກັບຂໍ້ມູນຈຳນວນຫຼາຍດ້ວຍ USB."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"ເຊື່ອມຕໍ່ USB ແລ້ວ"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"ແຕະເພື່ອສຳເນົາໄຟລ໌ ໃສ່/ຈາກ ຄອມພິວເຕີຂອງທ່ານ."</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"ປິດບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"ແຕະເພື່ອປິດ ບ່ອນຈັດເກັບຂໍ້ມູນ USB ."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ກຳລັງຖືກນຳໃຊ້ຢູ່"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"ກ່ອນປິດບ່ອນຈັດເກັບຂໍ້ມູນ USB, ຖອນ (\"eject\") ບ່ອນຈັດເກັບຂໍ້ມູນ USB ຂອງ Android ຂອງທ່ານຈາກຄອມພິວເຕີຂອງທ່ານ."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"ກ່ອນການປິດບ່ອນຈັດເກັບຂໍ້ມູນ USB, ໃຫ້ຖອນການເຊື່ອມຕໍ່ (eject) SD card ຂອງ Android ທ່ານອອກຈາກຄອມພິວເຕີກ່ອນ."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"ປິດບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"ເກີດບັນຫາໃນການປິດບ່ອນຈັດເກັບຂໍ້ມູນ USB. ໃຫ້ກວດສອບວ່າທ່ານໄດ້ຖອນການເຊື່ອມຕໍ່ USB host ແລ້ວຫຼືຍັງ ຈາກນັ້ນຈຶ່ງລອງອີກຄັ້ງ."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"ເປີດໃຊ້ບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"ຫາກທ່ານເປີດນຳໃຊ້ບ່ອນຈັດເກັບຂໍ້ມູນ USB ຈະເຮັດໃຫ້ບາງແອັບຯທີ່ທ່ານເຮັດວຽກຢູ່ນັ້ນ ຢຸດເຮັດວຽກ ແລະອາດຈະບໍ່ສາມາດໃຊ້ໄດ້ຈົນກວ່າທ່ານປິດບ່ອນຈັດເກັບຂໍ້ມູນ USB ກ່ອນ."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"ປະຕິບັດການ USB ບໍ່ສຳເລັດ"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"ຕົກລົງ"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"ເຊື່ອມຕໍ່ເປັນອຸປະກອນສື່"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"ເຊື່ອມຕໍ່ເປັນກ້ອງຖ່າຍຮູບແລ້ວ"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"ເຊື່ອມຕໍ່ໃນນາມຕົວຕິດຕັ້ງ"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"ເຊື່ອມຕໍ່ກັບອຸປະກອນເສີມ USB ແລ້ວ"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"ແຕະເພື່ອເບິ່ງໂຕເລືອກເລືອກ USB ອື່ນໆ."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"ຟໍແມັດ ບ່ອນຈັດເກັບຂໍ້ມູນ USB?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"ຟໍແມັດ SD card?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"ໄຟລ໌ທັງໝົດທີ່ຢູ່ໃນບ່ອນຈັດເກັບຂໍ້ມູນ USB ຂອງທ່ານຈະຖືກລຶບອອກໝົດ. ການກະທຳຈະບໍ່ສາມາດຍົກເລີກໄດ້!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"ຂໍ້ມູນທັງໝົດໃນກາດຂອງທ່ານຈະຫາຍໄປ."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"ຟໍແມັດ"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"ເຊື່ອມຕໍ່ການດີບັ໊ກຜ່ານ USB ແລ້ວ"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"ແຕະເພື່ອປິດການດີບັ໊ກຜ່ານ USB."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"ເລືອກຮູບແບບການປ້ອນ"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"ຕັ້ງຄ່າວິທີການປ້ອນຂໍ້ມູນ"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"ແປ້ນພິມແທ້"</string>
-    <string name="hardware" msgid="7517821086888990278">"ຮາດແວ"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"ເລືອກຮູບແບບແປ້ນພິມ"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"ກົດເພື່ອເລືອກຮູບແບບແປ້ນພິມ."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"ຕົວເລືອກ"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"ກຳລັງກຽມບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"ກຳລັງກະກຽມ SD card"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"ກຳລັງກວດຫາຂໍ້ຜິດພາດ."</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ເປົ່າຫວ່າງ"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"SD card ຫວ່າງເປົ່າ"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ຫວ່າງເປົ່າ ຫຼືມີໄຟລ໌ລະບົບທີ່ບໍ່ຮອງຮັບ."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD card ຫວ່າງເປົ່າ ຫຼືມີລະບົບໄຟລ໌ທີ່ບໍ່ຮອງຮັບ."</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ທີ່ເສຍຫາຍ."</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"SD card ທີ່ເສຍຫາຍ."</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ເສຍຫາຍ. ລອງຟໍແມັດມັນອີກຄັ້ງເບິ່ງ."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD card ເສຍຫາຍ. ລອງຟໍແມັດມັນອີກຄັ້ງເບິ່ງ."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ຖືກຖອດອອກແບບບໍ່ປອດໄພ"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD card ຖືກຖອດອອກໂດຍບໍ່ຄາດຄິດ"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"ຖອດການເຊື່ອມຕໍ່ບ່ອນຈັດເກັບຂໍ້ມູນ USB ກ່ອນທີ່ຈະຖອດອອກ ເພື່ອປ້ອງກັນການສູນເສຍຂໍ້ມູນ."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"ຖອນການເຊື່ອມຕໍ່ SD card ກ່ອນຈະຖອດອອກເພື່ອປ້ອງກັນການສູນເສຍຂໍ້ມູນ."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ສາມາດຖອດອອກໄດ້ຢ່າງປອດໄພ"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"ສາມາດຖອດ SD card ອອກໄດ້ປອດໄພແລ້ວ"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"ທ່ານສາມາດຖອດບ່ອນຈັດເກັບຂໍ້ມູນ USB ອອກໄດ້ຢ່າງປອດໄພ."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"ທ່ານສາມາດຖອດ SD card ອອກໄດ້ຢ່າງປອດໄພ."</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ຖືກຖອດອອກແລ້ວ"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"SD card ຖືກຖອດອອກ"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"ບ່ອນຈັດເກບັຂໍ້ມູນ USB ຖືກຖອດອອກແລ້ວ. ໃຫ້ໃສ່ອັນໃໝ່ເຂົ້າໄປ."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD card ຖືກຖອດອອກແລ້ວ. ກະລຸນາໃສ່ອັນໃໝ່."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"ບໍ່ພົບກິດຈະກຳທີ່ກົງກັນ."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"ອັບເດດສະຖິຕິການນຳໃຊ້ອົງປະກອບ"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"ອະນຸຍາດໃຫ້ແອັບຯແກ້ໄຂສະຖິຕິ ການນຳໃຊ້ຂໍ້ມູນສ່ວນປະກອບທີ່ເກັບກຳມາ. ແອັບຯທົ່ວໄປບໍ່ຈຳເປັນຕ້ອງໃຊ້."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"ສຳເນົາເນື້ອຫາ"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"ອະນຸຍາດໃຫ້ຮ້ອງຂໍບໍລິການຄອນເທັນເນີຫຼັກ ໃນການສຳເນົາເນື້ອຫາ. ບໍ່ໃຊ້ໃນແອັບຯທົ່ວໄປ."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"ກຳນົດເສັ້ນທາງເອົ້າພຸດຂອງສື່"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ກຳນົດເສັ້ນທາງເອົ້າພຸດຂອງສື່ໄປຫາອຸປະກອນພາຍນອກອື່ນໆ."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"ເຂົ້າໃຊ້ບ່ອນຈັດເກັບຂໍ້ມູນຄວາມປອດໄພຄີກາດ"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນ ເຂົ້າເຖິງບ່ອນຈັດເກັບຂໍ້ມູນຄວາມປອດໄພດ້ວຍຄີກາດ."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"ຄວບຄຸມການສະແດງ ແລະການເຊື່ອງໂຕລັອກປຸ່ມກົດ"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"ອະນຸຍາດໃຫ້ແອັບພລິເຄຊັນສາມາດຄວບຄຸມຄີກາດໄດ້."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"ແຕະສອງເທື່ອສຳລັບການຄວບຄຸມການຊູມ"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"ບໍ່ສາມາດເພີ່ມວິດເຈັດໄດ້."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"ໄປ"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"ຊອກຫາ"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"ສົ່ງ"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"ຕໍ່ໄປ"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"ແລ້ວໆ"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"ກ່ອນໜ້າ"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"ດຳເນີນການ"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"ກົດເລກໝາຍ\nໂດຍໃຊ້ <xliff:g id="NUMBER">%s</xliff:g>"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"ສ້າງລາຍຊື່ຜູ່ຕິດຕໍ່\nໂດຍການໃຊ້ <xliff:g id="NUMBER">%s</xliff:g>"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"ມີນຶ່ງແອັບຯ ຫຼືຫຼາຍກວ່ານັ້ນກຳລັງຮ້ອງຂໍການອະນຸຍາດ ເພື່ອເຂົ້າເຖິງບັນຊີຂອງທ່ານໃນຕອນນີ້ ແລະອະນາຄົດ."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"ທ່ານຕ້ອງການອະນຸມັດຄຳຮ້ອງຂໍນີ້ບໍ່?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"ຄໍາຮ້ອງຂໍການເຂົ້າເຖິງ"</string>
-    <string name="allow" msgid="7225948811296386551">"ອະນຸຍາດ"</string>
-    <string name="deny" msgid="2081879885755434506">"ປະ​ຕິ​ເສດ"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"ຕ້ອງການການອະນຸຍາດ"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"ຮ້ອງຂໍການກຳນົດສິດ\nສຳລັບບັນຊີ <xliff:g id="ACCOUNT">%s</xliff:g> ແລ້ວ."</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"ວິທີການປ້ອນຂໍ້ມູນ"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"ຊິ້ງຂໍ້ມູນ"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"ການຊ່ວຍເຂົ້າເຖິງ"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"ພາບພື້ນຫຼັງ"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"ປ່ຽນພາບພື້ນຫຼັງ"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"ໂຕຟັງການແຈ້ງເຕືອນ"</string>
-    <string name="vpn_title" msgid="19615213552042827">"ເປີດນຳໃຊ້ VPN ແລ້ວ"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"ເປີດໃຊ້ VPN ໂດຍ <xliff:g id="APP">%s</xliff:g>"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"ແຕະເພື່ອຈັດການເຄືອຂ່າຍ."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"ເຊື່ອມຕໍ່ຢູ່ກັບ <xliff:g id="SESSION">%s</xliff:g>. ແຕະເພື່ອຈັດການເຄືອຂ່າຍ."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"ກຳລັງເຊື່ອມຕໍ່ Always-on VPN…"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"ເຊື່ອມຕໍ່ VPN ແບບເປີດຕະຫຼອດເວລາແລ້ວ"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"VPN ແບບເປີດຕະຫຼອດເກີດຄວາມຜິດພາດ"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"ແຕະເພື່ອປັບຄ່າ"</string>
-    <string name="upload_file" msgid="2897957172366730416">"ເລືອກໄຟລ໌"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"ບໍ່ໄດ້ເລືອກໄຟລ໌ເທື່ອ"</string>
-    <string name="reset" msgid="2448168080964209908">"ຣີເຊັດ"</string>
-    <string name="submit" msgid="1602335572089911941">"ສົ່ງຂໍ້ມູນ"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"ໂຫມດຂັບລົດຖືກເປີດແລ້ວ"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"ກົດເພື່ອປິດໂຫມດຂັບລົດ."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"ການປ່ອຍສັນຍານ ຫຼືຮັອດສະປອດທີ່ເຮັດວຽກຢູ່"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"ແຕະເພື່ອຕິດຕັ້ງ."</string>
-    <string name="back_button_label" msgid="2300470004503343439">"ກັບຄືນ"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"ຕໍ່ໄປ"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"ຂ້າມ"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"ມີການໃຊ້ອິນເຕີເນັດຫຼາຍ"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"ແຕະເພື່ອສຶກສາເພີ່ມເຕີມກ່ຽວກັບການໃຊ້ຂໍ້ມູນມືຖື."</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"ການນຳໃຊ້ອິນເຕີເນັດຮອດຂີດຈຳກັດແລ້ວ"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"ແຕະເພື່ອສຶກສາເພີ່ມເຕີມກ່ຽວກັບການນຳໃຊ້ຂໍ້ມູນມືຖື."</string>
-    <string name="no_matches" msgid="8129421908915840737">"ບໍ່ພົບຜົນການຊອກຫາ"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"ຊອກໃນໜ້າ"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"1 ກົງກັນ"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="INDEX">%d</xliff:g> ຈາກທັງໝົດ <xliff:g id="TOTAL">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"ແລ້ວໆ"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"ກຳລັງຖອນການເຊື່ອມຕໍ່ບ່ອນຈັດເກັບຂໍ້ມູນ USB …"</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"ຖອນການເຊື່ອມຕໍ່ SD card..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"ກຳລັງລຶບ ບ່ອນຈັດເກັບຂໍ້ມູນ USB …"</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"ກຳລັງລຶບ​ SD card..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"ບໍ່ສາມາດລຶບບ່ອນຈັດເກັບຂໍ້ມູນ USB ໄດ້."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"ບໍ່ສາມາດລຶບ SD card ໄດ້."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD card ຖືກຖອດອອກກ່ອນການຖອນການເຊື່ອມຕໍ່."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"ບ່ອນຈັດເກັບຂໍ້ມູນກຳລັງຢູ່ໃນລະຫວ່າງການກວດສອບ."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"ກຳລັງກວດສອບ SD card ຢູ່ໃນຂະນະນີ້."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD card ຖືກຖອດອອກແລ້ວ."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB ກຳລັງຖືກນຳໃຊ້ໂດຍຄອມພິວເຕີ."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD card ກຳລັງຖືກນຳໃຊ້ໂດຍຄອມພິວເຕີຢູ່."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"ຂໍ້ມູນພາຍນອກຢູ່ໃນສະຖານະທີ່ບໍ່ຮູ້ຈັກ."</string>
-    <string name="share" msgid="1778686618230011964">"ແບ່ງປັນ"</string>
-    <string name="find" msgid="4808270900322985960">"ຊອກຫາ"</string>
-    <string name="websearch" msgid="4337157977400211589">"ຊອກຫາເວັບ"</string>
-    <string name="find_next" msgid="5742124618942193978">"ຊອກຫາຕໍ່ໄປ"</string>
-    <string name="find_previous" msgid="2196723669388360506">"ຊອກກ່ອນໜ້ານີ້"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"ຄຳຮ້ອງຂໍສະຖານທີ່ຈາກ <xliff:g id="NAME">%s</xliff:g>"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"ຮ້ອງຂໍສະຖານທີ່"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"ຮ້ອງຂໍໂດຍ <xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>)"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"ຕົກລົງ"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"ບໍ່"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"ກາຍເຂດກຳນົດການລຶບ"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"ມີ <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> ລາຍການທີ່ຖືກລຶບສຳລັບ <xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g>, ບັນຊີ <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g>. ທ່ານຕ້ອງການຈະເຮັດແນວໃດ?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"ລຶບລາຍການ"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"ຍົກເລີກການລຶບ"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"ບໍ່ເຮັດຫຍັງໃນຕອນນີ້"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"ເລືອກບັນຊີ"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"ເພີ່ມບັນຊີ"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"ເພີ່ມບັນຊີ"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"ເພີ່ມ"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"ປັບລົງ"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> ສຳພັດຄ້າງໄວ້."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"ເລື່ອນຂຶ້ນເພື່ອເພີ່ມ ແລະເລື່ອນລົງເພື່ອຫຼຸດ."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"ເພີ່ມນາທີ"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"ປັບນາທີລົງ"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"ເພີ່ມຊົ່ວໂມງ"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"ຫຼຸດຊົ່ວໂມງ"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"ຕັ້ງ PM"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"ຕັ້ງ AM"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"ເພີ່ມຈຳນວນເດືອນ"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"ຫຼຸດເດືອນ"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"ເພີ່ມຈຳນວນມື້"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"ຫຼຸດຈຳນວນມື້"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"ເພີ່ມປີຂຶ້ນ"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"ຫຼຸດຈຳນວນປີ"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"ຍົກເລີກ"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"ລຶບ"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"ແລ້ວໆ"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"ປ່ຽນຮູບແບບ"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Enter"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"ເລືອກແອັບຯ"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"ແບ່ງປັນກັບ"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"ແບ່ງປັນໃຫ້ <xliff:g id="APPLICATION_NAME">%s</xliff:g>"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"ເລື່ອນບ່ອນຖື ແລ້ວແຕະຄ້າງໄວ້."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"ເລື່ອນຂຶ້ນເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"ເລື່ອນລົງເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"ເລື່ອນໄປທາງຊ້າຍເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"ເລື່ອນໄປທາງຂວາເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"ປົດລັອກ"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"ກ້ອງ"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"ປິດສຽງ"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"ເປີດສຽງ"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"ຊອກຫາ"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"ປັດເພື່ອປົດລັອກ."</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"ສຽບສາຍຫູຟັງເພື່ອຟັງລະຫັດຜ່ານ."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"ຈໍ້າເມັດ."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"ກັບໄປໜ້າຫຼັກ"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"ຂຶ້ນເທິງ"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"ໂຕເລືອກອື່ນ"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"ບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD card"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"ບ່ອນຈັດເກັບຂໍ້ມູນ USB"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"ແກ້ໄຂ"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"ເຕືອນກ່ຽວກັບການນຳໃຊ້ຂໍ້ມູນ"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"ແຕະເພື່ອເບິ່ງການນຳໃຊ້ ແລະການຕັ້ງຄ່າ."</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"ປິດການນຳໃຊ້ຂໍ້ມູນ 2G-3G"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"ການນຳໃຊ້ຂໍ້ມູນ 4G ຖືກປິດແລ້ວ"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"ຂໍ້ມູນມືຖືຖືກປິດໄວ້"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"ປິດຂໍ້ມູນ Wi-Fi ແລ້ວ"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"ແຕະເພື່ອເປີດໃຊ້."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"ຂໍ້ມູນ 2G-3G ຮອດຂີດຈຳກັດແລ້ວ"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"ໝົດກຳນົດການນຳໃຊ້ຂໍ້ມູນ 4G"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"ໝົດກຳນົດການນຳໃຊ້ຂໍ້ມູນໃນມືຖື"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"ໝົດກໍານົດການນຳໃຊ້ຂໍ້ມູນ Wi-Fi"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> ເກີນທີ່ກໍາ​ນົດໄວ້."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"ຂໍ້ມູນແບັກກຣາວຖືກຈຳກັດແລ້ວ"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"ແຕະເພື່ອເອົາການຈຳກັດອອກ"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"ໃບຮັບຮອງຄວາມປອດໄພ"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"ໃບຮັບຮອງບໍ່ຖືກຕ້ອງ."</string>
-    <string name="issued_to" msgid="454239480274921032">"ອອກໃຫ້ແກ່:"</string>
-    <string name="common_name" msgid="2233209299434172646">"ຊື່ສາມັນ:"</string>
-    <string name="org_name" msgid="6973561190762085236">"ອົງກອນ:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"ໜ່ວຍອົງກອນ:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"ອອກໃຫ້ໂດຍ:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"ອາຍຸການນຳໃຊ້:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"ອອກໃຫ້ເມື່ອ:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"ໝົດອາຍຸໃນ:"</string>
-    <string name="serial_number" msgid="758814067660862493">"ໝາຍເລກຊີຣຽວ:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"ລາຍນິ້ວມື:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"ພິມລາຍນິ້ວມື SHA-256:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"ລາຍນິ້ວມື SHA-1:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"ເບິ່ງທັງຫມົດ"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"ເລືອກກິດຈະກຳ"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"ແບ່ງປັນກັບ"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"ອຸປະກອນລັອກ."</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"ກຳລັງສົ່ງ..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"ເປີດໂປຣແກຣມທ່ອງເວັບ?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"ຮັບການໂທບໍ່?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"ທຸກຄັ້ງ"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"ຄັ້ງດຽວ"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"ແທັບເລັດ"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"ໂທລະສັບ"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"ຫູຟັງ"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"ບ່ອນຕັ້ງລຳໂພງ"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"ລະບົບ"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"ສຽງ Bluetooth"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"ການສະແດງຜົນໄຮ້ສາຍ"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"ແລ້ວໆ"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"ມີເດຍເອົ້າພຸດ"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"ກຳລັງສະແກນ..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"ກຳລັງເຊື່ອມຕໍ່..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"ສາມາດໃຊ້ໄດ້"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"ບໍ່ສາມາດໃຊ້ໄດ້"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"ກຳລັງໃຊ້ຢູ່"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"ໜ້າຈໍທີ່ຕິດມານຳ"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"ຈໍ HDMI"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"ການວາງຊ້ອນ #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", ປອດໄພ"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"ເຊື່ອມຕໍ່ການສະແດງຜົນໄຮ້ສາຍແລ້ວ"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"ຈໍນີ້ກຳລັງສະແດງຢູ່ໃນອຸປະກອນອື່ນ"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"ຢຸດການເຊື່ອມຕໍ່"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"ການໂທສຸກເສີນ"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"ລືມຮູບແບບປົດລັອກ?"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"ຮູບແບບຜິດ"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"ລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"ລະຫັດ PIN ຜິດ"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"ລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER">%1$d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"ແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານ"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"ໃສ່ລະຫັດ PIN ຂອງຊິມ"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"ໃສ່ລະຫັດ PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"ໃສ່ລະຫັດຜ່ານ"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"ຊິມຖືກປິດການນຳໃຊ້ແລ້ວ. ປ້ອນລະຫັດ PUK ເພື່ອດຳເນີນການຕໍ່. ຕິດຕໍ່ຜູ່ໃຫ້ບໍລິການສຳລັບລາຍລະອຽດ."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"ໃສ່ລະຫັດ PIN ທີ່ຕ້ອງການ."</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"ຢືນຢັນລະຫັດ PIN ທີ່ຕ້ອງການ"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"ປົດລັອກ SIM card..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"ລະຫັດ PIN ບໍ່ຖືກຕ້ອງ."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"ພິມລະຫັດ PIN ຄວາມຍາວ 4 ເຖິງ 8 ໂຕເລກ."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"ລະຫັດ PUK ຄວນມີຢ່າງໜ້ອຍ 8 ໂຕເລກ."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"ປ້ອນລະຫັດ PUK ທີ່ຖືກຕ້ອງຄືນໃໝ່. ການພະຍາຍາມໃສ່ຫຼາຍເທື່ອຈະເຮັດໃຫ້ຊິມກາດໃຊ້ບໍ່ໄດ້ຖາວອນ."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"ລະຫັດ PIN ບໍ່ກົງກັນ"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"ແຕ້ມຮູບແບບປົດລັອກຫຼາຍເກີນໄປ"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"ເພື່ອປົດລັອກ, ເຂົ້າສູ່ລະບົບດ້ວຍບັນຊີ Google ຂອງທ່ານ."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"ຊື່ຜູ່ໃຊ້ (ອີເມວ)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"ລະຫັດຜ່ານ"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"ເຂົ້າສູ່ລະບົບ"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"ຊື່ຜູ່ໃຊ້ ຫຼືລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"ລືມຊື່ຜູ່ໃຊ້ ຫຼືລະຫັດຜ່ານຂອງທ່ານບໍ່?\nໄປທີ່ "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"ກຳລັງກວດສອບບັນຊີ..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"ທ່ານພິມລະຫັດ PIN​ ຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nກະລຸນາລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"ທ່ານພິມລະຫັດຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nກະລຸນາລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກແທັບເລັດບໍ່ສຳເລັດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ແທັບເລັດຂອງທ່ານຈະຖືກຕັ້ງ ໃຫ້ກັບໄປໃຊ້ຄ່າເລີ່ມຕົ້ນຈາກໂຮງງານຄືນໃໝ່ ແລະຂໍ້ມູນຜູ່ໃຊ້ທັງໝົດຈະສູນຫາຍໄປ."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກໂທລະສັບບໍ່ສຳເລັດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ໂທລະສັບຂອງທ່ານຈະຖືກຕັ້ງ ໃຫ້ກັບໄປໃຊ້ຄ່າເລີ່ມຕົ້ນຈາກໂຮງງານຄືນໃໝ່ ແລະຂໍ້ມູນຜູ່ໃຊ້ທັງໝົດຈະສູນຫາຍໄປ."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກແທັບເລັດບໍ່ສຳເລັດ <xliff:g id="NUMBER">%d</xliff:g> ເທື່ອແລ້ວ. ຕອນນີ້ແທັບເລັດຈະຖືກຕັ້ງໃຫ້ກັບໄປໃຊ້ຄ່າເລີ່ມຕົ້ນຈາກໂຮງງານ."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກໂທລະສັບບໍ່ຖືກ <xliff:g id="NUMBER">%d</xliff:g> ເທື່ອແລ້ວ. ຕອນນີ້ໂທລະສັບຈະຖືກຣີເຊັດເປັນຄ່າຈາກໂຮງງານ."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກແຕ້ມຜິດອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ, ທ່ານຈະຖືກຖາມໃຫ້ປົດລັອກແທັບເລັດຂອງທ່ານ ດ້ວຍການເຂົ້າສູ່ລະບົບໂດຍໃຊ້ອີເມວຂອງທ່ານ.\n\n ກະລຸນາລອງໃໝ່ອີກຄັ້ງໃນອີກ <xliff:g id="NUMBER_2">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ທ່ານຈະຖືກຖາມໃຫ້ປົດລັອກໂທລະສັບຂອງທ່ານດ້ວຍບັນຊີອີເມວ.\n\n ລອງໃໝ່ອີກຄັ້ງໃນ <xliff:g id="NUMBER_2">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"ລຶບອອກ"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"ຕ້ອງການເພີ່ມລະດັບສຽງຈົນເກີນລະດັບທີ່ແນະນຳ?\nການຟັງໃນລະດັບສຽງດັງເປັນເວລາດົນ ອາດທຳລາຍການໄດ້ຍິນສຽງຂອງທ່ານໄດ້."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"ກົດສອງນິ້ວຄ້າງໄວ້ເພື່ອເປີດໃຊ້ການຊ່ວຍເຂົ້າເຖິງ"</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"ເປີດການຊ່ວຍເຂົ້າເຖິງແລ້ວ."</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"ຍົກເລີກໂຕຊ່ວຍການເຂົ້າເຖິງແລ້ວ."</string>
-    <string name="user_switched" msgid="3768006783166984410">"ຜູ່ໃຊ້ປັດຈຸບັນ <xliff:g id="NAME">%1$s</xliff:g> ."</string>
-    <string name="owner_name" msgid="2716755460376028154">"ເຈົ້າຂອງ"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"ຜິດພາດ"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"ແອັບພລິເຄຊັນນີ້ບໍ່ຮອງຮັບບັນຊີຂອງໂປຣໄຟລ໌ທີ່ຖືກຈຳກັດ."</string>
-    <string name="app_not_found" msgid="3429141853498927379">"ບໍ່ພົບແອັບພລິເຄຊັນເພື່ອຈັດການເຮັດວຽກນີ້."</string>
-    <string name="revoke" msgid="5404479185228271586">"ຖອນ"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"ຈົດໝາຍ"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"ຈົດ​ຫມາຍທາງ​ລັດ​ຖະ​ບານ"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"ກົດຫມາຍ"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"ກົດໝາຍຂັ້ນຕ່ຳ"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"ບັນ​ຊີ"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"ແຖບບລອຍ"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"ຍົກເລີກແລ້ວ"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"ເນື້ອ​ໃນ​ການຂຽນຜິດພາດ"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"ໃສ່ລະຫັດ PIN"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"PIN ປະ​ຈຸ​ບັນ"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"ລະຫັດ PIN ໃໝ່"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"ຢືນຢັນລະຫັດ PIN ໃໝ່"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"ສ້າງ PIN ສໍາ​ລັບ​ການ​ປັບ​ປຸງ​ຂໍ້ຈໍາ​ກັດ"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN ບໍ່​ກົງກັນ. ລອງໃໝ່ອີກຄັ້ງ​."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN ​ສັ້ນ​ເກີນ​ໄປ​. ຕ້ອງມີຢ່າງໜ້ອຍ 4 ຫຼັກ​."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"PIN ​ບໍ່​ຖືກ​ຕ້ອງ​. ລອງໃໝ່ໃນອີກ 1 ວິນາທີ."</item>
-    <item quantity="other" msgid="8030607343223287654">"PIN ບໍ່​ຖືກ​ຕ້ອງ​. ລອງໃໝ່ໃນອີກ <xliff:g id="COUNT">%d</xliff:g> ວິ​ນາ​ທີ​."</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"ປັດຢູ່ຂອບຂອງໜ້າຈໍເພື່ອສະແດງແຖບ"</string>
-</resources>
diff --git a/core/res/res/values-lt/strings.xml b/core/res/res/values-lt/strings.xml
index 5211311..9fa41c9 100644
--- a/core/res/res/values-lt/strings.xml
+++ b/core/res/res/values-lt/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Band. dar po <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Vėliau bandykite dar kartą"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Perbr. žemyn, kad išeit. iš viso ekr. rež."</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Perbraukite nuo viršaus žemyn, kad išeitumėte iš viso ekrano režimo"</string>
 </resources>
diff --git a/core/res/res/values-lv/strings.xml b/core/res/res/values-lv/strings.xml
index 0fb18dd..036d5d6 100644
--- a/core/res/res/values-lv/strings.xml
+++ b/core/res/res/values-lv/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Mēģ. vēl pēc <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Vēlāk mēģiniet vēlreiz."</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Lai izietu no pilnekr., velc. no augšas lejup."</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Lai izietu no pilnekrāna režīma, velciet no augšas uz leju."</string>
 </resources>
diff --git a/core/res/res/values-mn-rMN/strings.xml b/core/res/res/values-mn-rMN/strings.xml
index 2639d43..fe3d78b 100644
--- a/core/res/res/values-mn-rMN/strings.xml
+++ b/core/res/res/values-mn-rMN/strings.xml
@@ -609,7 +609,7 @@
     <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"Блютүүт тохиргоонд хандах"</string>
     <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"Апп нь дотоод блютүүт таблетын тохиргоог харах боломжтой ба хос болох төхөөрөмжтэй холболтыг зөвшөөрөх болон хийх боломжтой"</string>
     <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"Апп нь утасны дотоод блютүүтыг тохируулах боломжтой ба гадаад төхөөрөмжийг олох болон хос үүсгэх боломжтой."</string>
-    <string name="permlab_bluetoothPriv" msgid="4009494246009513828">"Аппликешнд Блютүүт хоallow Bluetooth pairing by Application"</string>
+    <string name="permlab_bluetoothPriv" msgid="4009494246009513828">"Аппликешнд bluetooth хослол хийхийг зөвшөөрнө"</string>
     <string name="permdesc_bluetoothPriv" product="tablet" msgid="8045735193417468857">"Апп-д хэрэглэгчтэй харьцахгүйгээр зайны төхөөрөмжүүдтэй хослох боломж олгоно."</string>
     <string name="permdesc_bluetoothPriv" product="default" msgid="8045735193417468857">"Апп-д хэрэглэгчтэй харьцахгүйгээр зайны төхөөрөмжүүдтэй хослох боломж олгоно."</string>
     <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX-д холбогдох болон салах"</string>
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> секундын дараа дахин оролдоно уу"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Дараа дахин оролдоно уу"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Бүтэн дэлгэцээс гарахын тулд дээрээс нь эхлэн доош шудрана уу"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Бүтэн дэлгэцээс гарахын тулд дээрээс нь эхлэн доош шудрана уу."</string>
 </resources>
diff --git a/core/res/res/values-mn/strings.xml b/core/res/res/values-mn/strings.xml
deleted file mode 100644
index e187320..0000000
--- a/core/res/res/values-mn/strings.xml
+++ /dev/null
@@ -1,1583 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"КБ"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"МБ"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"ГБ"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TБ"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"ПБ"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;Гарчиггүй&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(Утасны дугаар байхгүй)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(Тодорхойгүй)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"дуут шуудан"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"Холболтын асуудал эсвэл буруу MMI код."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"Ажиллагаа зөвөх тогтсон дугаараар хязгаарлагдсан."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"Үйлчилгээ идэвхжсэн."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"Дараах үйлчилгээ идэвхтэй болсон:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"Үйлчилгээ идэвхгүй болсон."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"Амжилттай бүртгэв."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"Амжилттай арилгалаа."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"Буруу нууц үг"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI дууссан."</string>
-    <string name="badPin" msgid="9015277645546710014">"Таны бичсэн хуучин PIN буруу байна."</string>
-    <string name="badPuk" msgid="5487257647081132201">"Таны бичсэн PUК буруу байна."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"Таны оруулсан PIN таарахгүй байна."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"4-8 тооноос бүтэх PIN-г бичнэ үү."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"8-с цөөнгүй тооноос бүтэх PUK-г бичнэ үү."</string>
-    <string name="needPuk" msgid="919668385956251611">"SIM картны PUK-түгжигдсэн. Тайлах бол PUK кодыг бичнэ үү."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM картын хаалтыг болиулах бол PUK2-г бичнэ үү."</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"Дуудлага хийгчийн ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"Гарч байгаа дуудлага хийгчийн ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"Дуудлага дамжуулах"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"дуудлага хүлээлгэх"</string>
-    <string name="BaMmi" msgid="455193067926770581">"Дуудлага хориглох"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"Нууц үг солих"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN солих"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"Дуудсан дугаар харуулах"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"Дуудлага хийгчийн дугаар хязгаарлагдсан"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"Гурван чиглэлт дуудлага"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"Хүсээгүй тааламжгүй дуудлагаас татгалзах"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"Дуудлага хийгчийн дугаарыг дамжуулах"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"Бүү саад бол"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"Дуудлага хийгчийн ID хязгаарлагдсан. Дараагийн дуудлага: Хязгаарлагдсан"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"Дуудлага хийгчийн ID хязгаарлагдсан. Дараагийн дуудлага: Хязгаарлагдаагүй"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"Дуудлага хийгчийн ID хязгаарлагдаагүй. Дараагийн дуудлага: Хязгаарлагдсан"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"Дуудлага хийгчийн ID хязгаарлагдсан. Дараагийн дуудлага: Хязгаарлагдсан"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"Үйлчилгээ провишн хийгдээгүй ."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"Та дуудлага хийгчийн ID тохиргоог солиж чадахгүй."</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"Хязгаарлагдсан хандалт өөрчлөгдөв"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"Дата үйлчилгээ хаагдсан."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"Яаралтай үйлчилгээ хаагдсан."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"Дуут үйлчилгээ хориглогдсон."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"Бүх дуут үйлчилгээнүүд хориглогдсон."</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS үйлчилгээ хаагдсан."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"Дуут/дата үйлчилгээ хаагдсан."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"Дуут/SMS үйлчилгээнүүд хориглогдсон."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"Бүх дуут/дата/SMS үйлчилгээнүүд хориглогдсон."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"Дуу"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"Дата"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"Факс"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"Синхрон бус"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"Синк"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"Пакет"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"Роуминг заагч ассан"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"Роуминг заагч унтарсан"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"Роуминг заагч анивчиж байна"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"Хөрш дотор"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"Барилгын гадна"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"Роуминг - Сонгогдсон Систем"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"Роуминг- Боломжтой Систем"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"Роуминг- Холбоотон Түнш"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"Роуминг- Урамшууллын Түнш"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"Рүүминг - Үйлчилгээний Ажиллагаа Бүрэн"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"Рүүминг - Хэсэгчилсэн үйлчилгээний функционал"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"Рүүминг Баннер Асаалттай"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"Баннергүй рүүминг"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"Үйлчилгээг хайж байна…"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: дамжуулагдаагүй"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> <xliff:g id="TIME_DELAY">{2}</xliff:g> секундын дараа"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: дамжуулагдаагүй"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: дамжуулагдаагүй"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"Онцлог код дуусав."</string>
-    <string name="fcError" msgid="3327560126588500777">"Холболтын асуудал эсвэл буруу функцын код."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"Тийм"</string>
-    <string name="httpError" msgid="7956392511146698522">"Сүлжээний алдаа гарав."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL олдсонгүй."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"Сайт гэрчлэлийн схем дэмжигдэхгүй."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"Гэрчлэж чадсангүй."</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"Прокси сервер гэрчлэл бүтэлгүйтэв."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"Сервертэй холбогдож чадсангүй."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"Сервертэй холбогдож чадсангүй. Дараа дахин оролдоно уу."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"Сервер холболтын хугацаа хэтрэв."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"Хуудас хэт олон сервер дахин чиглүүлэл агуулж байна."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"Протокол дэмжигдэхгүй байна."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"Аюулгүй холбоог үүсгэж чадсангүй."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"URL буруу тул хуудсыг нээж чадсангүй."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"Файлд хандаж чадсангүй."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"Дуудсан файл олдсонгүй."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Хэт олон хүсэлтийг боловсруулж байна. Дараа дахин оролдоно уу."</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g>-н нэвтрэлтийн алдаа"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"Синк"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"Синк"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"Хэт олон <xliff:g id="CONTENT_TYPE">%s</xliff:g> устгах."</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"Таблетийн сан дүүрсэн. Зай чөлөөлөх бол зарим файлыг устгана уу."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"Утасны сан дүүрсэн. Зай чөлөөлөх бол зарим файлыг устгана уу."</string>
-    <string name="me" msgid="6545696007631404292">"Би"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"Таблетын сонголтууд"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"Утасны сонголт"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"Чимээгүй горим"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"Утасгүй холбоог асаах"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"Утасгүй сүлжээг унтраах уу"</string>
-    <string name="screen_lock" msgid="799094655496098153">"Дэлгэцний түгжээ"</string>
-    <string name="power_off" msgid="4266614107412865048">"Унтраах"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"Хонх унтраах"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"Хонхны чичиргээ."</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"Хонх ассан"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"Унтрааж байна…"</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"Таны таблет унтрах болно."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"Таны утас унтрах болно."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"Та унтраах уу?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"Аюулгүй горимоор дахин асаах"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"Та аюулгүй горимоор дахин асаах уу? Энэ нь таны суулгасан гуравдагч талын бүх аппликешныг идэвхгүй болгоно. Та дахин асаах үед тэдгээр нь сэргээгдэнэ."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"Сүүлийн"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"Сүүлийн апп хоосон."</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"Таблет сонголт"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"Утасны сонголтууд"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"Дэлгэцний түгжээ"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"Унтраах"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"Алдаа мэдээллэх"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"Согог репорт авах"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"Энэ таны төхөөрөмжийн одоогийн статусын талаарх мэдээллийг цуглуулах ба имэйл мессеж болгон илгээнэ. Алдааны мэдэгдлээс эхэлж илгээхэд бэлэн болоход хэсэг хугацаа зарцуулагдана тэвчээртэй байна уу."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"Чимээгүй горим"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"Дуу хаагдсан"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"Дуу асав"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"Нислэгийн горим"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"Нислэгийн горим асав"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"Нислэгийн горим унтарсан"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"Аюулгүй горим"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Андройд систем"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"Танаас төлбөр авдаг үйлчилгээнүүд"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"Таны төлбөрт оруулах зүйлийг хийх."</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"Таны мессеж"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"Таны SMS, и-мэйл ба бусад мессежийг унших болон бичих."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"Таны хувийн мэдээлэл"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"Таны харилцагчдын картанд хадгалагдсан таны мэдээлэлд шууд хандах."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"Таны нийтийн мэдээлэл"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"Таны харилцагчид болон нийтийн холбооны тухай мэдээлэлд шууд хандах."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"Таны байршил"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"Таны бодит байршлыг хянах."</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"Сүлжээний холбоо"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"Төрөл бүрийн сүлжээний функцүүдэд хандах"</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"Блютүүт"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"Блютүүтээр төхөөрөмж болон сүлжээнд хандах."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"Аудио тохиргоо"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"Аудио тохиргоо солих."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"Батерейд нөлөөлөх"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"Батерей хурдан дуусгах функцийг ашиглах."</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"Календарь"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"Календар болон үйл явдалд шууд хандах."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"Хэрэглэгчийн толиос унших"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"Хэрэглэгчийн толь бичгээс үг унших."</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"Хэрэглэгчийн тольд бичих"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"Хэрэглэгчийн толь бичигт үг нэмэх."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"Хавчуурга болон түүх"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"Хавчуурга болон хөтчийн түүхрүү шууд хандах."</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"Сэрүүлэг"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"Сэрүүлэг тохируулах."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"Дуут шуудан"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"Дуут шууданд шууд хандах."</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"Микрофон"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"Аудио бичихийн тулд микрофонд шууд хандах."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"Камер"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"Зураг эвсэл бичлэг хийхээр камерт шууд хандах."</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"Дэлгэц түгжих"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"Таны төхөөрөмжийн дэлгэцийн түгжээнд нөлөөлөх чадвар."</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"Таны аппликешны мэдээлэл"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"Таны төхөөрөмжийн бусад аппликешнд нөлөөлөх чадвар."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"Ханын зураг"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"Төхөөрөмжийн ханын зургийн тохиргоог солих."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"Цаг"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"Төхөөрөмжийн цаг эсвэл цагийн бүсийг солих."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"Статус самбар"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"Төхөөрөмжийн статус самбарын тохиргоог солих."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"Синк тохиргоо"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"Синк тохиргоонд хандах."</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"Таны акаунт"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"Боломжит акаунтад хандах."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"Хардвер контрол"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"Гар төхөөрөмжийн хардверт шууд хандах."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"Утсаар ярих"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"Утасны дуудлагыг хянах, бичих болон боловсруулах."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"Системийн багаж"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"Системрүү доод төвшиний хандах болон удирдах."</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"Хөгжүүлэх багаж"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"Зөвхөн аппликешн хөгжүүлэгчдэд хэрэгтэй функц."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"Бусад аппликешн UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"Бусад аппликешны UI-д нөлөөлөх."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"Сан"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB санд хандах."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD картад хандах."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"Хялбар хандах функц"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"Туслах технологиос хүсэлт илгээх боломжтой функц"</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"Цонхны контентыг авах"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"Таны харилцан үйлчлэх цонхны контентоос шалгах."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"Хүрч танихыг асаах"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"Хүрсэн зүйлсийг чангаар дуудах ба дохио ашиглан дэлгэцийг таньж болно."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"Сайжруулсан веб хандалтыг асаах"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"Апп контентод илүү хялбар хандуулахын тулд скриптыг суулгана."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"Бичсэн текстээ ажиглах"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"Кредит картын дугаар болон нууц үг зэрэг хувийн датаг агуулж байна."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"статус самбарыг идэвхгүй болгох болон өөрчлөх"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"Апп нь статус самбарыг идэвхгүй болгох эсвэл систем дүрсийг нэмэх, хасах боломжтой."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"статус самбар"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"Апп нь статус самбар болох боломжтой."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"статус самбарыг нээх/хаах"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"Апп нь статус самбарыг дэлгэх болон хаах боломжтой."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"гарсан дуудлагыг чиглэлийг өөрчлөх"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"Апп нь дуудлага хийх болон залгаж байгаа дугаарыг өөрчлөх боломжтой. Энэ зөвшөөрөл нь апп-г залгасан дуудлагыг хаах, хянах болон дахин чиглүүлэх боломжтой болгодог."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"текст мессеж(SMS) хүлээж авах"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"Апп нь SMS мессежийг хүлээн авах болон гүйцэтгэх боломжтой. Ингэснээр апп нь таны төхөөрөмжрүү илгээсэн мессежийг танд үзүүлэхгүйгээр хянах болон устгаж чадна."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"текст мессеж(МMS) хүлээж авах"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"Апп нь MMS мессежийг хүлээн авах болон гүйцэтгэх боломжтой. Ингэснээр апп нь таны төхөөрөмжрүү илгээсэн мессежийг танд үзүүлэхгүйгээр хянах болон устгаж чадна."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"Яаралтай өргөн дамжууллыг хүлээн авах"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"Апп нь яаралтай өргөн дамжууллын мессежийг хүлээн авах болон гүйцэтгэх боломжтой. Энэ зөвшөөрөл нь зөвхөн систем аппликешнд л боломжтой."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"үүрэн өргөн дамжууллын мессеж унших"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"Апп нь таны төхөөрөмжийн хүлээн авсан үүрэн өргөн дамжуулах мессежийг унших боломжтой. Үүрэн өргөн дамжууллын мэдэгдэл нь яаралтай нөхцөл байдлыг анхааруулах зорилгоор зарим байршлуудад хүрдэг. Хортой апп нь яаралтай үүрэн өргөн дамжууллыг хүлээн авсан үед таны төхөөрөмжийн ажиллагаа болон чадамжид нөлөөлөх боломжтой."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS мессеж илгээх"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"Апп нь SMS мессеж илгээх боломжтой. Энэ нь санаандгүй төлбөрт оруулж болзошгүй. Хортой апп нь таны зөвшөөрөлгүйгээр мессеж илгээн таныг төлбөрт оруулж болзошгүй."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"мессежээр хариулах үйл явдалыг илгээх"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"Апп нь дуудлага ирэх үед мессежээр хариу өгөх үйл явдлыг зохицуулахын тулд бусад мессежийн апп-д хүсэлт илгээх боломжтой."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"таны текст мессежийг унших(SMS эсвэл MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"Апп нь таны утас эсвэл SIM картанд хадгалагдсан SMS мессежийг унших боломжтой. Энэ нь апп-д бүх мессежийг контент эсвэл нууц эсэхээс нь үл хамааран унших боломжийг олгоно."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"Апп нь таны утас эсвэл SIM картанд хадгалагдсан SMS мессежийг унших боломжтой. Энэ нь апп-д бүх мессежийг контент эсвэл нууц эсэхээс нь үл хамааран унших боломжийг олгоно."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"Текст мессежийг засах (SMS эсвэл MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"Апп нь таны таблет эсвэл SIM картанд хадгалагдсан SMS мессежрүү бичих боломжтой. Хортой апп нь таны мессежүүдийг устгах боломжтой."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"Апп нь таны утас эсвэл SIM картанд хадгалагдсан SMS мессежрүү бичих боломжтой. Хортой апп нь таны мессежүүдийг устгах боломжтой."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"текст мессеж(WAP) хүлээн авах"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"Апп нь WAP мессежийг хүлээн авах болон биелүүлэх боломжтой. Энэ зөвшөөрөл нь танд илгээсэн мессежийг танд харуулалгүйгээр хянах эсвэл устгах боломжийг агуулна."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"ажиллаж байгаа апп-г дуудах"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"Апп нь одоо ажиллаж байгаа болон сүүлд ажилласан даалгаврын талаарх мэдээллийг авах боломжтой. Ингэснээр апп нь төхөөмж дээрх ямар аппликешнүүд ашиглагдсан талаарх мэдээлийг олох боломжтой."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"хэрэглэгчидтэй харилцан үйлчлэлцэх"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"Апп нь төхөөрөмж дээрх ялгаатай хэрэглэгчдэд үйлдэл гүйцэтгэх боломжтой. Хортой апп нь энийг ашиглан хэрэглэгч хоорондын хамгаалалтыг зөрчих боломжтой."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"хэрэглэгчидтэй харилцан үйлчлэлцэх бүрэн зөвшөөрөл"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"Бүх хэрэглэгчдэд боломжит бүх харилцан үйлдлийг зөвшөөрнө."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"хэрэгчлэгч удирдах"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"Апп нь төхөөрөмж дээр асуулга, үүсгэлт болон устгалт зэргийг багтаасан хэрэглэгч удирдах боломжтой."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"ажиллаж байгаа апп-н дэлгэрэнгүйг авах"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"Апп нь одоо ажиллаж байгаа болон сүүлд ажилласан даалгаврын талаарх дэлгэрэнгүй мэдээллийг авах боломжтой. Хортой апп нь бусад апп-н хувийн мэдээлийг олох боломжтой."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"ажиллаж байгаа апп-уудыг дахин эрэмбэлэх"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"Апп нь даалгавруудыг нүүрлүү болон арлуу зөөх боломжтой. Апп нь энийг таны оролцоогүйгээр хийж болзошгүй"</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"ажиллаж байгаа апп-г зогсоох"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"Апп нь даалгаврууд устгах болон тэдгээрийн апп-г зогсоох боломжтой. Хортой апп нь бусад апп-н ажиллагааг тасалдуулж болзошгүй."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"идэвхжилтийн стекүүдийг удирдах"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"Апп-д бусад апп-уудын ажилладаг идэвхжилтийн стекүүдийг нэмэх, хасах буюу өөрчлөх боломж олгоно. Хорлонтой апп-ууд бусад апп-уудын авирт нөлөөлөх боломжтой."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"ямарч активитиг эхлүүлэх"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"Апп нь зөвшөөрөл хамгаалалтай эсвэл экспорт хийсэн статусаас үл хамааран ямарч активитиг эхлүүлэх боломжтой."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"дэлгэцний зохицолыг тохируулах"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"Апп нь бусад аппликешны дэлгэцний тохиромжит горимыг удирдах боломжтой.  Хортой аппликешн нь бусад аппликешны чадамжийг эвдэх боломжтой."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"апп дебагыг идэвхжүүлэх"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"Апп нь бусад апп-г дебаг хийхийг асаах боломжтой. Хортой апп нь энийг ашиглан бусад апп-г зогсоох боломжтой."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"системийн дэлгэцний тохиргоог солих"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"Апп нь нутагшил эсвэл фонтын хэмжээ зэрэг одоогийн тохиргоог солих боломжтой."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"машины горимыг идэвхжүүлэх"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"Апп нь машины горимыг идэвхжүүлэх боломжтой."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"бусад апп-г хаах"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"Апп нь бусад апп-н арын процессыг дуусгах боломжтой. Энэ бусад апп-г зогсоох боломжийг олгоно."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"бусад апп-г хүчээр зогсоох"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"Апп нь бусад апп-г хүчээр зогсоох боломжтой."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"апп-г хүчээр унтраах"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"Апп нь нүүрэнд ажиллаж байгаа активитиг хүчээр зогсоох болгон арлуу явуулах боломжтой. Энгийн апп-д хэрэглэхгүй."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"системийн дотоод статусыг дуудах"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"Апп нь системийн дотоод статусыг дуудах боломжтой. Хортой апп нь энийг ашиглах шаардлагагүй аюулгүй байдлын болон хувийн мэдээллийг дуудах боломжтой."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"Дэлгэцийн контентыг унших"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"Апп нь идэвхтэй цонхны контентыг авах боломжтой. Хортой апп нь цонхны контентыг бүхэлд авах болон нууц үгнээс бусад бүх текстийг шалгаж болзошгүй"</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"Хялбар байдлыг түр идэвхтэй болгох"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"Аппликешн нь төхөөрөмжийн хялбар байдлыг түр зуур идэвхжүүлэх боломжтой. Хортой апп нь хэрэглэгчийн зөвшөөрөлгүйгээр хялбар байдлыг идэвхжүүлж болзошгүй."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"цонхны мэдээллийг унших"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"Аппликешн нь цонхны менежерээс цонхны талаар мэдээллийг дуудах боломжтой. Хортой апп нь дотоод системийн хэрэглээнд зориулагдсан мэдээллийг дуудаж болзошгүй."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"үйл явдлыг шүүх"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"Аппликешн нь хэрэглэгчийн бүх үйл явдалын илгээгдэхээс өмнөх урсгалыг шүүж байгаа оролтын шүүлтйиг бүртгэх боломжтой. Хортой апп нь хэрэглэгчийн интервэшнгүйгээр системийн UI-г удирдах боломжтой."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"дэлгэц томруулах"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"Аппликешн нь дэлгэцний контентийг өсгөх боломжтой. Хортой апп нь дэлгэцийн контентыг төхөөрөмжнөөс ашиглаж болохгүй болгон хувиргах боломжтой."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"хэсэгчилсэн унтраалт"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"Активити менежерийг унтраана. Бүрэн унтраалтыг хийхгүй."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"апп шилжүүлэхийг хориглох"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"Хэрэглэгч бусад апп-руу сэлгэхийг хориглох."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"одоогийн апп-н мэдээллийг авах"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"Эзэмшигч нь дэлгэцний нүүрэнд байгаа одоогийн аппликешн болон үйлчилгээний талаарх хувийн мэдээллийг унших боломжтой."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"бүх апп-ын эхлэлийг хянах болон удирдах"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"Апп нь систем активитиг яаж эхлүүлж байгааг хянах болон удирдан боломжтой. Хортой апп нь системд бүрэн нөлөөлж болзошгүй. Энэ эрх нь зөвхөн хөгжүүлэлтийн үед л хэрэгтэй ба энгийн хэрэглээнд огт хэрэггүй."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"багц хасагдсан өргөн дамжууллыг илгээх"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"Апп нь апп багц устгагдсан талаарх мэдэгдлийг өргөн дамжуулах боломжтой. Хортой апп энийг ашиглан бусад ажиллаж байгаа апп-г зогсоох боломжтой."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS-хүлээн авав өргөн дамжууллыг илгээх"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"Апп нь SMS мессеж хүлээн авсан талаарх мэдэгдлийг өргөн дамжуулах боломжтой. Хортой апп энийг ашиглан ирсэн SMS мессежийг хуурамчаар хийх боломжтой."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH-хүлээн авав өргөн дамжууллыг илгээх"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"Аппликешн нь WAP PUSH мессеж хүлээж авсан мэдэгдлийг өргөн дамжуулах боломжтой. Хортой апп нь энийг ашиглан MMS мессеж хүлээн авсан гэж хуурамчаар мэдэгдэх эсвэл хортой хувьсагч агуулсан веб хуудасны контентыг чимээгүй орлуулах боломжтой."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"ажиллаж байгаа процессийн тоог хязгаарлах"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"Апп нь нэг зэрэг ажиллах процессийн тооны дээд утгыг удирдах боломжтой. Энгийн апп-д хэзээ ч ашиглагдахгүй."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"арын апп-г хүчээр хаах"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"Апп нь активитинүүд арын болонгуутаа дуусах эсэхийг удирдах боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"батерейны статистикийг унших"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"Аппликешн нь батерей хэрэглээний доод-төвшиний одоогийн датаг унших боломжтой. Аппликешнд таны ашиглаж байгаа апп-н талаарх дэлгэрэнгүй мэдээллийг олох боломжийг олгоно."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"батерейн статистикийг өөрчлөх"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"Апп нь батерейн цуглуулагдсан статистикийг өөрчлөх боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"апп-н ажиллагааны статистикийг авах"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"Апп нь аппликешны ажиллагааны цуглуулсан статистикийг дуудах боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"апп ажиллагааны статистикийг өөрчлөх"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"Апп нь аппликешны ажиллагааны цуглуулсан статистикийг өөрчлөх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"систем нөөшлөлт болон сэргээлтийг удирдах"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"Апп нь системийн нөөшлөх болон сэргээх тогтолцоог удирдах боломжтой. Энгийн апп-уудад хэрэглэгдэхгүй."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"бүтэн нөөшлөлтийг бататгах эсвэл ажиллагааг сэргээх"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"Апп нь бүрэн нөөшлөлтийг баталгаажуулах UI-г эхлүүлэх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"эрхжүүлэгдээгүй цонхыг үзүүлэх"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"Апп нь дотоод системийн хэрэглэгчийн интерфейст ашиглагдах цонхыг үүсгэх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"бусад апп-р зурах"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"Апп нь бусад аппликешн эсвэл хэрэглэгчийн интерфейсын дээд талд зурах боломжтой. Эдгээр нь бүх аппликешны интерфейсыг ашиглахад саад болох эсвэл   бусад аппликешн дээр таны харж байгааг солих боломжтой."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"глобал энимешн хурдыг өөрчлөх"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"Апп нь ямар ч үед глобал энимешн хурдыг(хурдан удаан энимешн) солих боломжтой."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"апп бүтвэрийг удирдах"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"Апп нь өөрийн нормал Z эрэмбийг дамжуулах замаар өөрсдийн бүтвэрийг үүсгэх болон удирдах боломжтой. Энгийн апп-д хэрэглэгдэхгүй"</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"дэлгэцийг хөдөлгөөнгүй болгох"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"Аппликешн нь бүтэн дэлгэцрүү шилжихэд дэлгэцийг хөдөлгөөнгүй болгох боломжтой."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"товч болон контрол товч дарах"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"Алл нь өөрийн оролтын үйл явдлыг(товч дарагдах г.м) бусад апп-д дамжуулах боломжтой. Хортой апп нь энийг ашиглан таблетыг удирдах боломжтой."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"Алл нь өөрийн оролтын үйл явдлыг(товч дарагдах г.м) бусад апп-д дамжуулах боломжтой. Хортой апп нь энийг ашиглан утсыг удирдах боломжтой."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"таны хийж байгаа үйлдэл болон бичиж байгааг бичлэг хийх"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"Апп нь бусад апп-тай харилцан үйлчилж(нууц үг оруулах) таны дарсан товчийг ажиглах боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"оролтын аргатай холбох"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"Эзэмшигч нь оруулах аргын дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"хандалтын үйлчилгээнд холбогдох"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"Эзэмшигч нь хандах үйлчилгээний дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"хэвлэх үйлчилгээтэй холбох"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"Эзэмшигчид хэвлэх үйлчилгээний дээд-түвшний интерфейстэй холбох боломж олгоно. Энгийн апп-уудад хэзээ ч ашиглагдахгүй."</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"бүх хэвлэх ажилд хандалт хийх"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"Эзэмшигчид өөр апп-аас үүсгэсэн хэвлэх ажилд хандалт хийх боломж олгоно. Энгийн апп-уудад хэзээ ч ашиглагдахгүй."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC үйлчилгээтэй холбох"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Эзэмшигчид NFC картуудыг дуурайлгадаг аппликешнүүдийг холбох боломж олгоно. Энгийн апп-уудад хэзээ ч шаардагдахгүй."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"текст үйлчилгээтэй холбох"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"Эзэмшигч нь текст үйлчилгээний(ж.нь. SpellCheckerService) дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN үйлчилгээтэй холбох"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"Эзэмшигч нь VPN үйлчилгээний дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"ханын зурагтай холбох"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"Эзэмшигч нь ханын зурагны дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-уудад шаардлагагүй."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"виджет үйлчилгээтэй холбох"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"Эзэмшигч нь виджет үйлчилгээний дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"төхөөрөмжийн админтай харилцан үйлчлэх"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"Эзэмшигч нь төхөөрөмжийн админруу интент илгээх боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"төхөөрөмжийн админ нэмэх, хасах"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"Эзэмшигч нь идэвхтэй төхөөрөмжийн администраторыг нэмэх, хасах боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"дэлгэцний чиглэлийг солих"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"Апп нь ямар ч үед дэлгэцний эргэлтийг солих боломжтой. Энгийн аппликешнд хэзээ ч ашиглахгүй."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"заагчийн хурдыг солих"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"Апп нь хулгана эсвэл хөдлөх самбарын заагчийн хурдыг ямарч үед солих боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"гарын схемийг солих"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"Апп нь гарын схемыг солих боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"аппруу Linux дохио илгээх"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"Апп нь бүх байнгын процессруу хангамжийн дохиог илгээх хүсэлтийг хийх боломжтой."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"апп-г байнга ажиллуулах"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"Апп нь өөрийн хэсгийн санах ойд байнга байлгах боломжтой. Энэ нь бусад апп-уудын ашиглах санах ойг хязгаарлан таблетыг удаашруулах болно."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"Апп нь өөрийн хэсгийг санах ойд байнга байлгах боломжтой. Энэ нь бусад апп-уудын ашиглах санах ойг хязгаарлан утсыг удаашруулах болно."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"апп устгах"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"Апп нь Андройд багцийг устгах боломжтой. Хортой апп нь энийг ашиглан чухал апп-г устгах боломжтой."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"бусад апп-н датаг устгах"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"Апп нь хэрэглэгчийн датаг арилгах боломжтой."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"бусад апп-н кешээс устгах"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"Апп нь кеш файлаас устгах боломжтой."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"апп сангийн хэмжээг хэмжих"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"Апп нь өөрийн код, дата болон кеш хэмжээг унших боломжтой"</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"апп-г шууд суулгах"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"Апп нь шинэ эсвэл шинэчлэгдсэн Андройд багцийг суулгах боломжтой. Хортой апп нь энийг ашиглан дурын эрхтэй шинэ апп-г суулгах боломжтой."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"бүх апп-н кеш датаг устгах"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"Апп нь бусад аппликешны кеш директороос файл устган таблетын санг чөлөөлөх боломжтой. Энэ  нь бусад аппликешнд нөлөөлж, тэдгээр нь эхлэхдээ шаардлагатай датагаа дахин дуудах тул удааширч болзошгүй."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"Апп нь бусад аппликешны кеш директороос файл устган утасны санг чөлөөлөх боломжтой. Энэ нь бусад аппликешнд нөлөөлж, тэдгээр нь эхлэхдээ шаардлагатай датагаа дахин дуудах тул удааширч болзошгүй."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"апп нөөцийг шилжүүлэх"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"Апп нь апп нөөцийг дотроос гадна медиаруу болон эсрэгээр нь зөөх боломжтой."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"нууц лог дата унших"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"Апп нь системийн төрөл бүрийн лог файлыг унших боломжтой. Энэ нь та таблет дээрээ юу хийсэн талаарх хувийн болон нууц мэдээллийг олох боломжтой болгоно."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"Апп нь системийн төрөл бүрийн лог файлыг унших боломжтой. Энэ нь та утсан дээрээ юу хийсэн талаарх хувийн болон нууц мэдээллийг олох боломжтой болгоно."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"тоглуулахын тулд дурын медиа шифрлэгчийг ашиглах"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"Апп нь тоглуулах үедээ код тайлахдаа суулгагдсан ямарч медиа код тайлагчийг ашиглах боломжтой."</string>
-    <string name="permlab_manageCaCertificates" msgid="1678391896786882014">"итгэмжлэгдсэн жуухуудыг удирдах"</string>
-    <string name="permdesc_manageCaCertificates" msgid="4015644047196937014">"Апп-д CA сертификатуудыг итгэмжлэгдсэн жуух байдлаар суулгах болон устгахыг зөвшөөрнө."</string>
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"оношлох грүпийн эзэмшдэг нөөцрүү унших/бичих"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"Апп нь оношлох грүпийн эзэмшдэг, жишээ нь /dev доторх файлууд, дурын  нөөцийг унших бичих боломжтой.Энэ нь системийн тогвортой байдал болон аюулгүй байдалд бодитоор нөлөөлнө. Энэ нь үйлдвэрлэгч болон операторын хардверт-зориулсан оношлогоонд ашиглагдана."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"апп компонентыг идэвхжүүлэх эсвэл идэвхгүй болгох"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"Апп нь өөр апп-н компонент идэвхтэй эсэхийг солих боломжтой. Хортой апп нь энийг ашиглан таблетын чухал чадамжийг идэвхгүй болгож болзошгүй. Зөвшөөрөл нь аппликешн компонентыг тогтворгүй, ашиглаж болохгүй, тохиромжгүй төлөвт оруулах боломжтой тул ашиглахдаа болгоомжтой байх шаардлагатай."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"Апп нь өөр апп-н компонент идэвхтэй эсэхийг солих боломжтой. Хортой апп нь энийг ашиглан утасны чухал чадамжийг идэвхгүй болгож болзошгүй. Зөвшөөрөл нь аппликешн компонентыг тогтворгүй, ашиглаж болохгүй, тохиромжгүй төлөвт оруулах боломжтой тул ашиглахдаа болгоомжтой байх шаардлагатай."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"зөвшөөрөл олгох эсвэл цуцлах"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"Аппликешн нь өөртэй болон бусад аппликешнд тусгай зөвшөөрлийг олгох болон цуцлах боломжтой. Хортой аппликешн нь энийг ашиглан таны олгоогүй эрхэнд хандах боломжтой."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"үндсэн апп-г тохируулах"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"Апп нь таны тусгай апп-уудыг өөрчлөх боломжтой. Хортой апп нь ажиллаж байгаа апп-г нууцаар өөрчлөн, таны хуучин апп-г таны хувийн датаг цуглуулагч болгон хуурах боломжтой."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"систем тохиргоог өөрчлөх"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"Апп нь системийн тохиргооны датаг өөрчлөх боломжтой. Хортой апп нь таны системийн тохиргоог сүйтгэх боломжтой."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"аюулгүй систем тохиргоог өөрчлөх"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"Апп нь системийн аюулгүй байдлын тохиргооны датаг өөрчлөх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google газрын зургийн үйлчилгээг өөрчлөх"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"Апп нь Google-н газрын зургийн үйлчилгээг өөрчлөх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"Эхлэхэд ажиллуулах"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"Апп нь систем асаж дуусахад шууд өөрийгөө асаах боломжтой. Ингэснээр таблетыг асахад их хугацаа орох болон байнга ажилладаг апп нь таблетийг бүхэлд нь удаашруулах боломжтой."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"Апп нь систем асаж дуусахад шууд өөрийгөө асаах боломжтой. Ингэснээр утсыг асахад их хугацаа орох болон байнга ажилладаг апп нь утсыг бүхэлд нь удаашруулах боломжтой."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"тасардаггүй өргөн дамжууллыг илгээх"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"Апп нь өргөн дамжуулал дууссаны дараа үлдсэн өргөн дамжуулалыг илгээх боломжтой. Ихээр ашиглах нь хэт их санах ой ашиглан таблетыг удаашруулах болон тогтворгүй болгох боломжтой."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"Апп нь өргөн дамжуулал дууссаны дараа үлдсэн өргөн дамжуулалыг илгээх боломжтой. Ихээр ашиглах нь хэт их санах ой ашиглан утсыг удаашруулах болон тогтворгүй болгох боломжтой."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"өөрийн харилцагчдыг унших"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"Апп нь таны утсаар ярьсан, имэйл илгээсэн давтамж эсвэл тусгай харилцагдчидтайгаа өөр аргаар холбоо барьсан байдал зэргийг агуулсан таблет дээр хадгалагдсан харилцагчдын талаарх датаг унших боломжтой. Энэ зөвшөөрөл нь апп-д таны харилцагчийн датаг хадгалах боломжийг олгох ба хортой апп нь танд мэдэгдэлгүйгээр харилцагчийн датаг хуваалцах боломжтой."</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"Апп нь таны утсаар ярьсан, имэйл илгээсэн давтамж эсвэл тусгай харилцагчидтайгаа өөр аргаар холбоо барьсан байдал зэргийг агуулсан таны утсан дээр хадгалагдсан харилцагчдын талаарх датаг унших боломжтой. Энэ зөвшөөрөл нь апп-д таны харилцагчийн датаг хадгалах боломжийг олгох ба хортой апп нь танд мэдэгдэлгүйгээр харилцагчийн датаг хуваалцах боломжтой."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"таны харилцагчдыг өөрчлөх"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"Апп нь таны утсаар ярьсан, имэйл илгээсэн давтамж эсвэл тусгай харилцагчидтайгаа өөр аргаар холбоо барьсан байдал зэргийг агуулсан таны таблет дээр хадгалагдсан харилцагчдын талаарх датаг өөрчлөх боломжтой. Энэ зөвшөөрөл нь апп-д харилцагчийн датаг устгах боломжийг олгоно."</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"Апп нь таны утсаар ярьсан, имэйл илгээсэн давтамж эсвэл харилцагдчидтайгаа өөр аргаар холбоо барьсан байдал зэргийг агуулсан утсан дээр хадгалагдсан харилцагчдын талаарх датаг өөрчлөх боломжтой. Энэ зөвшөөрөл нь апп-д харилцагчийн датаг устгах боломжийг олгоно."</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"дуудлагын логийг унших"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"Апп нь таны таблетын ирсэн гарсан дуудлага зэргийг агуулсан дуудлагын логыг унших боломжтой. Энэ зөвшөөрөл нь апп-д таны дуудлагын логын датаг хадгалах боломжийг олгох ба хортой апп нь танд мэдэгдэлгүйгээр дуудлагын лог датаг хуваалцах боломжтой."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"Апп нь таны утасны ирсэн гарсан дуудлага зэргийг агуулсан дуудлагын логыг унших боломжтой. Энэ зөвшөөрөл нь апп-д таны дуудлагын логын датаг хадгалах боломжийг олгох ба хортой апп нь танд мэдэгдэлгүйгээр дуудлагын лог датаг хуваалцах боломжтой."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"дуудлагын логруу бичих"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"Апп нь таны таблетын ирсэн гарсан дуудлага зэргийг агуулсан дуудлагын логыг унших боломжтой. Хортой апп нь энийг ашиглан таны дуудлагын логыг өөрчлөх болон арилгах боломжтой."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"Апп нь таны утасны ирсэн гарсан дуудлага зэргийг агуулсан дуудлагын логыг өөрчлөх боломжтой. Хортой апп нь энийг ашиглан таны дуудлагын логыг өөрчлөх болон арилгах боломжтой."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"та өөрийн харилцагчийн картыг унших"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"Апп нь таны нэр болон холбоо барих мэдээлэл зэрэг таны утсан дээр хадгалагдсан хувийн профайл мэдээллийг унших боломжтой. Ингэснээр апп нь танийг таньж чадах ба таны профайл мэдээллийг бусдад илгээх боломжтой."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"та өөрийн харилцагчийн картыг өөрчлөх"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"Апп нь таны нэр болон холбоо барих мэдээлэл зэрэг таны төхөөрөмж дээр хадгалагдсан хувийн профайл мэдээллийг солих эсвэл нэмэх боломжтой. Ингэснээр апп нь танийг таньж чадах ба таны профайл мэдээллийг бусдад илгээх боломжтой."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"таны нийтийн урсгалаас унших"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"Апп нь та болон таны найзуудын нийтийн шинэчлэлтэд хандах болон синк хийх боломжтой. Мэдээлэл хуваалцахдаа болгоомжтой байна уу - энэ нь апп-д нийтийн сүлжээндэх та болон таны найзууд хоорондын холбоог нууц эсэхээс үл хамааран унших боломжтой. Анхаар: энэ зөвшөөрөл нь бүх нийтийн сүлжээнд ашиглаж боломжгүй."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"Таны нийтийн урсгалруу бичих"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"Апп нь таны найзуудын нийтийн шинэчлэлтийг дүрслэх боломжтой.Мэдээлэл хуваалцахдаа болгоомжтой байна уу - энэ нь апп-д таны найзаас ирсэн мэт харагдах мессеж хийх боломжийг олгоно. Анхаар: энэ зөвшөөрөл нь бүх нийтийн сүлжээнд ашиглаж боломжгүй."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"календарийн хуваарийн нууц мэдээллийг унших"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"Апп нь таны таблет дээр хадгалагдсан найзууд болон хамтран ажиллагсдын календарийн бүх хуваарийг унших боломжтой. Энэ нь апп-д таны календарийн датаг нууц эсвэл эмзэг эсэхээс нь үл хамааран хуваалцах эсвэл хадгалах боломжийг олгоно."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"Allows the app to read all calendar events stored on your phone, including those of friends or co-workers. This may allow the app to share or save your calendar data, regardless of confidentiality or sensitivity. Апп нь таны утсан дээр хадгалагдсан найзууд болон хамтран ажиллагсдын календарийн бүх хуваарийг унших боломжтой. Энэ нь апп-д таны календарийн датаг нууц эсвэл эмзэг эсэхээс нь үл хамааран хуваалцах эсвэл хадгалах боломжийг олгоно."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"календарын хуваарийг нэмэх эсвэл өөрчлөх болон эзэмшигчид мэдэгдэлгүйгээр зочидруу имэйл илгээх"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"Апп нь таблет дээр та болон таны найзууд, хамтран ажиллагсдын өөрчилж чадах үйл явдлуудыг нэмэх, хасах болон солих боломжтой. Энэ нь апп-д, календарь эзэмшигчээс ирсэн мэт харагдах мессежийг илгээх эсвэл эзэмшигчд нь мэдэгдэлгүйгээр үйл явдлуудыг өөрчлөх боломжийг олгоно."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"Апп нь утсан дээр та болон таны найзууд, хамтран ажиллагсдын өөрчилж чадах үйл явдлуудыг нэмэх, хасах болон солих боломжтой. Энэ нь апп-д, календарь эзэмшигчээс ирсэн мэт харагдах мессежийг илгээх эсвэл эзэмшигчид нь мэдэгдэлгүйгээр үйл явдлуудыг өөрчлөх боломжийг олгоно."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"тест хийх байршлын эх үүсвэрийг үүсгэх"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"Тестэд ашиглах хуурамч байршлын эх үүсвэрийг үүсгэх болон шинэ байршил өгөгчийг суулгах боломжтой. Ингэснээр апп нь GPS эсвэл байршил өгөгч зэрэг бусад байршлын эх үүсвэрээс ирсэн байршил болон статусыг өөрчлөх боломжтой."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"байршил нийлүүлэгчийн нэмэлт тушаалд хандах"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"Апп нь байршил нийлүүлэгчийн нэмэлт тушаалд хандах боломжтой. Энэ нь апп-д GPS эсвэл бусад байршлын үйлчилгээний ажиллагаанд нөлөөлөх боломжийг олгоно."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"байршил нийлүүлэгчийг суулгах зөвшөөрөх"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"Тестэд ашиглах хуурамч байршлын эх үүсвэрийг үүсгэх болон шинэ байршил өгөгчийг суулгах боломжтой. Ингэснээр апп нь GPS эсвэл байршил өгөгч зэрэг бусад байршлын эх үүсвэрээс ирсэн байршил болон статусыг өөрчлөх боломжтой."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"Тодорхой байршил(GPS болон сүлжээнд суурилсан)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"Апп нь GPS эсвэл үүрэн цамхаг болон Wi-Fi зэрэг сүлжээний байршлын эх үүсвэрийг ашиглан таны тодорхой байршлыг авах боломжтой. Эдгээр байршлын үйлчилгээнүүд нь асаалттай байх шаардлагатай ба таны төхөөрөмж дээрх апп-ууд ашиглах боломжтой байх шаардлагатай. Апп-ууд энийг ашиглан таныг хаана байгааг тогтоох боломжтой ба батерей зарцуулалт нэмэгдэнэ."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"ойролцоох байршил(сүлжээнд суурилсан)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"Апп нь таны ойролцоох байршлыг оло боломжтой. Энэ байршил нь үүрэн цамхаг болон Wi-Fi зэрэг сүлжээний байршлын эх сурвалжийг ашигладаг байршлын үйлчилгээнээс олдоно. Эдгээр байршлын үйлчилгээнүүд нь таны төхөөрөмж дээр асаалттай байх шаардлагатай ба апп-д тэдгээрийг ашиглах боломжтой байх шаардлагатай. Апп-д тэдгээрийг ашиглан таны байршлыг ойролцоогоор олох боломжтой."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger-т хандах"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"Апп нь SurfaceFlinger доод-төвшиний функцийг ашиглах боломжтой."</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"Фрэйм буферээс унших"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"Апп нь фрэйм буферын контентыг унших боломжтой."</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"Wifi дэлгэцийг тохируулах"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"Апп нь Wifi дэлгэцийг тохируулах болон холбогдох боломжтой."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"Wifi дэлгэцийг удирдах"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Апп нь Wifi дэлгэцний доод-төвшиний функцийг удирдах боломжтой."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"аудио гаралтыг барих"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"Апп-т аудио гаралтыг барих, дахин чиглүүлэхийг зөвшөөрнө."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"видео гаралтыг барих"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"Апп-т видео гаралтыг барих, дахин чиглүүлэхийг зөвшөөрнө."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"найдвартай видео гаралтыг барих"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"Апп-т найдвартай видео гаралтыг барих, дахин чиглүүлэхийг зөвшөөрнө."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"Аудио тохиргоо солих"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"Апп нь дууны хэмжээ, спикерын гаралтад ашиглагдах глобал аудио тохиргоог өөрчлөх боломжтой."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"аудио бичих"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"Апп нь микрофоноор аудио бичих боломжтой. Энэ зөвшөөрөл нь апп-д ямар ч үед таны зөвшөөрөлгүйгээр аудио бичих боломжийг олгоно."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"зураг авах болон видео бичих"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"Апп нь камераар зураг авах болон видео бичих боломжтой. Энэ зөвшөөрөл нь апп-д ямар ч үед таны зөвшөөрөлгүйгээр камер ашиглах боломжийг олгоно."</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"камер ашиглаж байх үед дамжууллыг заагч LED-г идэвхгүй болгох"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"Урьдчилан суусан систем аппликешн нь камер ашиглалтыг заасан LED-г идэвхгүй болгох боломжтой."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"таблетыг бүрмөсөн идэвхгүй болгох"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"утсыг бүрмөсөн идэвхгүй болгох"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"Апп нь таблетыг бүхэлд нь бүрмөсөн идэвхгүй болгох боломжтой. Энэ маш аюултайэ"</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"Апп нь утсыг бүхэлд нь бүрмөсөн идэвхгүй болгох боломжтой. Энэ маш аюултай."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"таблет хүчээр дахин асаах"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"утсыг хүчээр дахин асаах"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"Апп нь таблетыг хүчээр дахин асаах боломжтой."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"Апп нь утсыг хүчээр дахин асаах боломжтой."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB сан файл системд хандах"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD карт файл системд хандах"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"Апп нь сугалдаг санг файл системд залгах болон салгах боломжтой."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB санг арилгах"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD картыг арилгах"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"Апп нь зөөврийн санг форматлах боломжтой."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"дотоод сангийн мэдээллийг авах"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"Апп нь дотоод сангаас мэдээллийг авах боломжтой"</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"дотоод санд үүсгэх"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"Апп нь дотоод сан үүсгэх боломжтой."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"дотоод сангаас устгах"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"Апп нь дотоод сангаас устгах боломжтой."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"дотоод санг залгах/салгах"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"Апп нь дотоод санг залгах/салгах боломжтой."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"дотоод сангийн нэрийг өөрчлөх"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"Апп нь дотоод сангийн нэрийг өөрчлөх боломжтой."</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_manageUsb" msgid="1113453430645402723">"USB төхөөрөмжийн тохиргоо болон зөвшөөрлийг удирдах"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"Апп нь USB төхөөрөмжийн зөвшөөрөл болон тохируулгыг удирдах боломжтой."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP протоколыг гүйцэтгэх"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"MTP USB протокол биелүүлэхээр MTP цөм драйверт хандах боломжтой."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"хардвер теслэх"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"Апп нь хардверийг тестлэх зорилгоор олон төрлийн туслах төхөөрөмжийг удирдах боломжтой."</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"утасны дугаарт шууд дуудлага хийх"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"Апп нь таны оролцоогүйгээр дуудлага хийх боломжтой. Энэ нь төлөвлөгдөөгүй төлбөрт оруулах эсвэл дуудлага хийнэ. Энэ нь апп-г яаралтай дугаарт дуудлага хийхйг зөвшөөрөхгүй. Хортой апп нь таны зөвшөөрөлгүйгээр дуудлага хийж таныг төлбөрт оруулж болзошгүй"</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"дурны утасны дугаарт шууд дуудлага хийх"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"Апп нь таны оролцоогүйгээр яаралтай тусламжийн дугааруудыг оруулаад ямарч дугаарлуу дуудлага хийх боломжтой. Хортой апп нь шаардлагагүй, хууль бус дуудлагыг яаралтай тусламжийн үйлчилгээрүү хийж болзошгүй."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA таблет тохиргоог шууд эхлүүлэх"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA утасны тохиргоог шууд эхлүүлэх"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"Апп нь CDMA провишныг эхлүүлэх боломжтой. Хортой апп нь шаардлагагүй байхад CDMA провишныг эхлүүлж болзошгүй."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"байршил шинэчлэх мэдэгдлийг удирдах"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"Апп нь радиогоос ирсэн байршил шинэчлэх мэдэгдлийг идэвхтэй/идэвхгүй болгох боломжтой. Энгийн апп-д хэрэглэглэхгүй."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"бүртгэх пропертид хандах"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"Апп нь бүртгэл үйлчилгээгээр байршуулагдсан пропертиг унших/бичих боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"виджет сонгох"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"Апп нь аль апп ямар виджетийг ашиглаж байгаа тухай системд мэдэгдэх боломжтой. Энэ зөвшөөрөлтэй апп нь бусад апп-д хувийн датад хандах эрхийг өгөх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"утасны статусыг өөрчлөх"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"Апп-н төхөөрөмжийн утасны функцийг удирдах боломжтой. Энэ зөвшөөрөлтэй апп  нь танд анхааруулахгүйгээр сүлжээг сэлгэх, утасны радиог асаах, унтраах боломжтой."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"утасны статус ба таниулбарыг унших"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"Апп нь төхөөрөмжийн утасны функцд хандах боломжтой. Энэ зөвшөөрөл нь апп-д утасны дугаар болон төхөөрөмжийн ID-г, дуудлага идэвхтэй эсэх, холын дугаар дуудлагаар холбогдсон байгаа эсэхийг тогтоох боломжийг олгоно,"</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"таблетыг унтуулахгүй байлгах"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"утсыг унтуулахгүй байлгах"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"Апп нь таблетыг унтахаас сэргийлэх боломжтой"</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"Апп нь утсыг унтахаас сэргийлэх боломжтой"</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"таблетыг унтраах эсвэл асаах"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"утсыг унтраах эсвэл асаах"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"Апп нь таблетыг асаах, унтраах боломжтой."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"Апп нь утсыг асаах, унтраах боломжтой."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"үйлдвэрийн тест горимд ажиллуулах"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"Доод төвшиний үйлдвэрийн тестийг ажиллуулан таблетын хардверт бүрэн хандах боломжтой. Таблет нь үйлдвэрийн тестийн горимд ажиллах үед л боломжтой."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"Доод төвшиний үйлдвэрийн тестийг ажиллуулан утасны хардверт бүрэн хандах боломжтой. Утас үйлдвэрийн тестийн горимд ажиллах үед л боломжтой."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"ханын зургийг тохируулах"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"Апп нь системийн ханын зургийг тохируулах боломжтой."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"Таны ханын зурагны хэмжээг тохируулах"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"Апп нь системийн ханын зургийн хэмжээний саналыг тохируулах боломжтой"</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"системийг үйлдвэрийн үндсэн утгаар тохируулах"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"Апп нь бүх датаг арилгах болон бүх суулгасан апп-г арилган системийг бүхэлд үйлдвэрийн тохиргоогоор бүрэн тохируулах боломжтой"</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"цагийн тохиргоо"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"Апп нь таблетын цагийг солих боломжтой."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"Апп нь утасны цагийг солих боломжтой."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"цагийн бүсийн тохиргоо"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"Апп нь таблетын цагийн бүсийг солих боломжтой."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"Апп нь утасны цагийн бүсийг өөрчлөх боломжтой."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService болж ажиллах"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"Апп нь Акаунт гэрчлэгчрүү дуудлага хийх боломжтой."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"төхөөрөмж дээрх акаунтыг олох"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"Апп нь таблетэд мэдэгдэж байгаа акаунтын жагсаалтыг авах боломжтой. Энд таны суулгасан аппликешнүүдийн үүсгэсэн бүх акаунтууд хамрагдана."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"Апп нь утсанд мэдэгдэж байгаа акаунтын жагсаалтыг авах боломжтой. Энд таны суулгасан аппликешнүүдийн үүсгэсэн бүх акаунтууд хамрагдана."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"акаунт үүсгэх болон нууц үг тохируулах"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"Апп нь акаунт үүсгэх, тэдгээрийн нууц үгийг тохируулах зэрэг акаунт удирдагчийн акаунт гэрчлэгчийн функцийг ашиглах боломжтой."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"акаунт нэмэх эсвэл хасах"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"Апп нь акаунт нэмэх, устгах ба тэдний нууц үгийг устгах зэрэг үйлдлийг гүйцэтгэх боломжтой."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"төхөөрөмж дээрх акаунтыг ашиглах"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"Апп нь гэрчлэлийн бүтвэрийг хүсэх боломжтой."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"сүлжээний холболтыг үзэх"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"Апп нь сүлжээ байгаа болон холбогдсон эсэх зэрэг сүлжээний холболтын талаарх мэдээллийг харах боломжтой."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"сүлжээнд бүрэн хандах"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"Апп нь сүлжээний сокетыг үүсгэх болон тусгай сүлжээний протокол ашиглах боломжтой. Хөтөч болон бусад аппликешнүүд Интернетээр дата илгээх боломжтой  тул энэ зөвшөөрөл нь Интернетээр дата илгээхэд шаардлагагүй."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"сүлжээний тохиргоо болон урсгалыг солих/таслах"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"Апп нь сүлжээний тохиргоог солих болон сүлжээний бүх урсгалыг APN-н прокси болон портыг солих замаар таслах, хянах боломжтой. Хортой апп нь танд мэдэгдэлгүйгээр сүлжээний пакетыг хянах, дахин чиглүүлэх болон өөрчлөх боломжтой."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"сүлжээний холболтыг солих"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"Апп нь сүлжээний холболтын статусыг солих боломжтой."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"модем болгосон холболтыг солих"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"Апп нь холбогдсон сүлжээний холболтын статусыг солих боломжтой."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"арын дата ашиглалтын тохиргоог солих"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"Апп нь арын дата хэрэглээний тохиргоог солих боломжтой."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"Wi-Fi холболтыг үзэх"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"Апп нь Wi-Fi идэвхтэй эсэх болон холбогдсон Wi-Fi төхөөрөмжийн нэр зэрэг Wi-Fi сүлжээний талаарх мэдээллийг харах боломжтой."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"Wi-Fi -тай холбогдох болон салах"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"Апп нь Wi-Fi холболтын цэгтэй холбогдох буюу салах боломжтой ба тохируулсан Wi-Fi сүлжээнд өөрчлөлт хийх боломжтой."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"Wi-Fi олон дамжуулалт хүлээн авахыг зөвшөөрөх"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"Апп нь олон дамжуулал ашиглан Wi-Fi сүлжээн дэх бүх төхөөрөмжрүү пакет илгээх болон хүлээн авах боломжтой. Энэ нь олон дамжуулал ашиглахгүй горимоос илүү их тэжээл зарцуулна."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"Апп нь олон дамжуулал ашиглан Wi-Fi сүлжээн дэх бүх төхөөрөмжрүү пакет илгээх болон хүлээн авах боломжтой. Энэ нь олон дамжуулал ашиглахгүй горимоос илүү их тэжээл зарцуулна."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"Блютүүт тохиргоонд хандах"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"Апп нь дотоод блютүүт таблетын тохиргоог харах боломжтой ба хос болох төхөөрөмжтэй холболтыг зөвшөөрөх болон хийх боломжтой"</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"Апп нь утасны дотоод блютүүтыг тохируулах боломжтой ба гадаад төхөөрөмжийг олох болон хос үүсгэх боломжтой."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX-д холбогдох болон салах"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"Апп нь WiMAX идэвхтэй эсэх болон холбогдсон WiMAX сүлжээний талаар мэдээллийг тодорхойлох боломжтой."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"WiMAX статусыг өөрчлөх"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"Апп нь WiMAX сүлжээнд таблетыг холбох болон салгах боломжтой."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"Апп нь WiMAX сүлжээнд утсыг холбох болон салгах боломжтой."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"Блютүүт төхөөрөмжтэй хос үүсгэх"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"Апп нь таблет дээрх блютүүт тохиргоог харах боломжтой ба хос болох төхөөрөмжтэй холболтыг зөвшөөрөх болон хийх боломжтой."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"Апп нь утсан дээрх Блютүүт тохиргоог харах боломжтой ба хос болох төхөөрөмжтэй холболтыг зөвшөөрөх болон хийх боломжтой."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"ойролцоо талбарын холбоог удирдах"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"Апп нь Ойролцоо Талбарын Холболт(NFC) таг, карт, болон уншигчтай холбогдох боломжтой."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"дэлгэцний түгжээг идэвхгүй болгох"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"Апп нь түгжээ болон бусад холбоотой нууц үгийн аюулгүй байдлыг идэвхгүй болгох боломжтой. Жишээ нь бол утас нь дуудлага ирэх үед түгжээг идэвхгүй болгох ба дуудлага дуусахад буцаан идэвхтэй болгодог."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"синк тохиргоог унших"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"Апп нь акаунтын синк тохиргоог унших боломжтой. Жишээ нь энэ нь Хүмүүс апп акаунттай синк хийгдсэн эсэхийг тодорхойлох боломжтой."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"синкийг унтрааж асаах тохиргоо"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"Апп нь акаунтын синк тохиргоог өөрчлөх боломжтой. Жишээ нь энэ нь Хүмүүс апп акаунттай синк хийхийг идэвхжүүлэх боломжтой."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"синк статистикийг унших"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"Апп нь синк үйлдэлийн түүх болон хэр их дата синк хийгдсэн зэрэг акаунтын синк статусыг унших боломжтой."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"бүртгүүлсэн хангамжийг унших"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"Апп нь одоогийн синк хийгдсэн хангамжийн талаарх мэдээллийг авах боломжтой."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"бүртгүүлсэн хангамжруу бичих"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"Апп нь таны одоогийн синк хийгдсэн хангамжийг өөрчлөх боломжтой. Хортой апп нь таны синк хийгдсэн хангамжийг өөрчлөх боломжтой."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"таны толь бичигт нэмсэн нөхцөлийг унших"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"Апп нь хэрэглэгч хэрэглэгчийн толь бичигт хадгалсан бүх үгс, нэрс болон хэлцийг унших боломжтой."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"хэрэглэгчийн толь бичигт үгс нэмэх"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"Апп нь хэрэглэгчийн толь бичигт шинэ үг бичих боломжтой."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"хамгаалагдсан санд хандах тест хийх"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"хамгаалагдсан санд хандах тест хийх"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"Апп нь дараагийн төхөөрөмжүүдэд ашиглах боломжтой болох SD карт зөвшөөрлийг тестлэх боломжтой."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"Апп нь дараагийн төхөөрөмжүүдэд ашиглах боломжтой болох SD карт эрхийг тестлэх боломжтой."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"USB сангийн контентыг өөрчлөх эсвэл устгах"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"SD картны контентыг өөрчлөх болон устгах"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"Апп нь USB санруу бичих боломжтой."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"Апп нь SD картруу бичих боломжтой."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"дотоод медиа сангийн контентыг өөрчлөх/устгах"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"Апп нь дотоод медиа сангийн контентыг өөрчлөх боломжтой."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"документ санг удирдах"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"Апп нь документ санг удирдах боломжтой."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"бүх хэрэглэгчдийн гадаар санд хандах"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"Апп нь бүх хэрэглэгчдийн гадаад санд хандах боломжтой."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"кеш файлсистемд хандах"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"Апп нь кеш файлсистемийг унших бичих боломжтой."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"Интернет дуудлага хийх/хүлээн авах"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"Апп нь Интернет дуудлага хийх/хүлээн авахын тулд SIP үйлчилгээг ашиглах боломжтой."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"сүлжээний ашиглалтын түүхийг унших"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"Апп нь тусгай сүлжээ болон апп-н сүлжээ ашиглалтын түүхийг унших боломжтой."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"сүлжээний бодлогыг удирдах"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"Апп нь сүлжээний бодлогыг удирдах болон апп-д зориулсан дүрмийг тогтоох боломжтой."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"сүлжээний хэрэглээний тайланг өөрчлөх"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"Апп нь апп-уудын сүлжээ ашиглалтын талаарх тооцоог өөрчлөх боломжтой. Энгийн апп-д ашиглагдахгүй."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"соккетын тэмдгүүдийг өөрчлөх"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"Апп-д чиглэлийн соккетын тэмдгийг өөрчлөх боломж олгоно"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"мэдэгдэлд хандах"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"Апп нь бусад апп-уудын илгээсэн мэдэгдлүүдийг дуудах, шалгах, болон цэвэрлэх боломжтой."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"мэдэгдэл сонсогч үйлчилгээтэй холбох"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"Эзэмшигч нь мэдэгдэл сонсох үйлчилгээний дээд-төвшиний интерфейстэй холбох боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"үүрэн компанийн нийлүүлсэн тохируулгын апп-г өдөөх"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"Эзэмшигчид үүрэн компанийн нийлүүлсэн тохируулах апп-г өдөөх боломж олгоно. Энгийн апп-уудад хэзээ ч ашиглагдахгүй."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"Сүлжээний байдлын талаар ажиглалтуудыг хүлээн авах"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"Аппликешнд сүлжээний байдлын талаар ажиглалтуудыг хүлээн авахыг зөвшөөрнө. Энгийн апп-уудад хэзээ ч ашиглагдахгүй."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"Нууц үгний дүрмийг тохируулах"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"Дэлгэц түгжих нууц үгэнд зөвшөөрөгдсөн тэмдэгт болон уртыг удирдах"</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"Дэлгэц тайлах оролдлогыг хянах"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"Дэлгэц түгжигдсэн үед нууц үг буруу оруулалтын тоог хянах ба хэрэв хэт олон удаа нууц үгийг буруу оруулбал таблетыг түгжих болон таблетын бүх датаг арилгана"</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"Дэлгэц түгжигдсэн үед нууц үг буруу оруулалтын тоог хянах, ба хэрэв хэт олон удаа нууц үгийг буруу оруулбал утсыг түгжих болон утасны бүх датаг арилгана"</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"Дэлгэц түгжих нууц үгийг солих"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"Дэлгэц түгжих нууц үгийг солих"</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"Дэлгэц түгжих"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"Дэлгэц хэзээ яаж түгжихийг удирдах"</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"Бүх датаг арилгах"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"Үйлдвэрийн дата утгыг өгсөнөөр таблетын дата шууд арилгагдана."</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"Үйлдвэрийн дата утгыг өгсөнөөр утасны дата шууд арилгагдана."</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"Төхөрөөмжийн глобал проксиг тохируулах"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"Бодлого идэвхтэй үед төхөөрөмжийн глобал проксиг ашиглахаар тохируулсан. Зөвхөн эхний төхөөрөмжийн админ л үр дүнтэй глобал проксиг тохируулна."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"Дэлгэц түгжих нууц үгний хүчинтэй хугацааг тохируулах"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"Дэлгэцний түгжих нууц үг хэр давтамжтай солигдохыг удирдах."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"Сангийн шифрлэхийг тохируулах"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"Хадгалагдсан апп дата шифрлэгдэх шаардлагатай"</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"Камер идэвхгүй болгох"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"Төхөөрөмжийн бүх камерийг ашиглахгүй."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"Түлхүүр хамгаалтын функцийг унтраах"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"Түлхүүр хамгаалалтын зарим функцийг ашиглахыг хориглох."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"Гэрийн"</item>
-    <item msgid="869923650527136615">"Мобайл"</item>
-    <item msgid="7897544654242874543">"Ажлын"</item>
-    <item msgid="1103601433382158155">"Ажлын факс"</item>
-    <item msgid="1735177144948329370">"Гэрийн Факс"</item>
-    <item msgid="603878674477207394">"Пэйжер"</item>
-    <item msgid="1650824275177931637">"Бусад"</item>
-    <item msgid="9192514806975898961">"Тусгай"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"Гэрийн"</item>
-    <item msgid="7084237356602625604">"Ажлын"</item>
-    <item msgid="1112044410659011023">"Бусад"</item>
-    <item msgid="2374913952870110618">"Тусгай"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"Гэрийн"</item>
-    <item msgid="5629153956045109251">"Ажлын"</item>
-    <item msgid="4966604264500343469">"Бусад"</item>
-    <item msgid="4932682847595299369">"Тусгай"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"Гэрийн"</item>
-    <item msgid="1359644565647383708">"Ажлын"</item>
-    <item msgid="7868549401053615677">"Бусад"</item>
-    <item msgid="3145118944639869809">"Тусгай"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"Ажлын"</item>
-    <item msgid="4378074129049520373">"Бусад"</item>
-    <item msgid="3455047468583965104">"Тусгай"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"Тусгай"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"Гэрийн"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"Мобайл"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"Ажлын"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"Ажлын факс"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"Гэрийн Факс"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"Пэйжер"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"Бусад"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"Буцаж холбоо барих"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"Машин"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"Байгууллагын үндсэн"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"Үндсэн"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"Бусад факс"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"Радио"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"Tелекс"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"Ажлын утас"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"Ажлын пейжер"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"Туслагч"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"Тусгай"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"Төрсөн огноо"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"Түүхэн ой"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"Бусад"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"Тусгай"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"Гэрийн"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"Ажлын"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"Бусад"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"Мобайл"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"Тусгай"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"Гэрийн"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"Ажлын"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"Бусад"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"Тусгай"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"Гэрийн"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"Ажлын"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"Бусад"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"Тусгай"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Цугларалт"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"Ажлын"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"Бусад"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"Тусгай"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"Тусгай"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"Туслагч"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"Ах"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"Хүүхэд"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"Дотоод Түнш"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"Эцэг"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"Найз"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"Менежер"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"Эх"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"Эцэг эх"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"Түнш"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"Дурдагдсан"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"Хамаатан"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"Эгч"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"Хань"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"Тусгай"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"Гэрийн"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"Ажлын"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"Бусад"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PIN кодыг бичнэ үү"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK-г бичээд шинэ PIN код оруулна уу"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK код"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Шинэ PIN код"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Нууц үг бичих бол хүрнэ үү"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Тайлах нууц үгийг бичнэ үү"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Тайлах PIN-г оруулна уу"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Буруу PIN код."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Тайлах бол Цэсийг дараад 0."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"Яаралтай дугаар"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"Үйлчилгээ байхгүй."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"Дэлгэц түгжигдсэн."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"Яаралтай дуудлага хийх буюу эсвэл түгжээг тайлах бол цэсийг дарна уу."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"Тайлах бол цэсийг дарна уу."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"Тайлах хээгээ зурна уу"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"Яаралтай дуудлага"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"Дуудлагаруу буцах"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"Зөв!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Дахин оролдох"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Дахин оролдох"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Нүүрээр түгжээ тайлах оролдлогын тоо дээд хэмжээнээс хэтэрсэн"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"Цэнэглэж байна, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"Цэнэглэгдэв"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"Цэнэглэгчээ холбоно уу."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM карт байхгүй"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"Таблет SIM картгүй."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"Утсанд SIM карт байхгүй."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SIM картыг оруулна уу."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM карт байхгүй эсвэл унших боломжгүй. SIM карт оруулна уу."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"Ашиглах боломжгүй SIM карт."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"Таны SIM карт бүрмөсөн идэвхгүй болов.\n Өөр SIM карт авах бол өөрийн утасгүй үйлчилгээний нийлүүлэгчтэй холбогдоно уу."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"Өмнөх бичлэг товч"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"Дараагийн бичлэг товч"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"Түр зогсоох товч"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"Тоглуулах товч"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"Зогсоох товч"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"Зөвхөн яаралтай дуудлага"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"Сүлжээ түгжигдсэн"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM карт нь PUK түгжээтэй."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"Хэрэглэгчийн зааврыг харах эсвэл Хэрэглэгчдэд Туслах төвтэй холбоо барина уу."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM карт түгжигдсэн."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM картны түгжээг гаргаж байна…"</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"Та нууц үгээ <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу бичив. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"Та PIN кодоо <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу бичив. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оруулбал, та таблетаа тайлахын тулд Google нэвтрэлтээ ашиглах шаардлагатай болно.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол, та таблетаа тайлахын тулд Google нэвтрэлтээ ашиглах шаардлагатай болно.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"Та таблетыг тайлах гэж <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу оролдлоо. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол таблет үйлдвэрийн үндсэн утгаараа тохируулагдах ба хэрэглэгчийн дата бүхэлдээ устана."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"Та утсыг тайлах гэж <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу оролдлоо. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол утас үйлдвэрийн үндсэн утгаараа тохируулагдах ба хэрэглэгчийн дата бүхэлдээ устана."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"Та таблетыг <xliff:g id="NUMBER">%d</xliff:g> удаа тайлах гэж буруу оролдлоо. Таблет одоо үйлдвэрийн үндсэн утгаараа тохируулагдах болно."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"Та утсыг тайлах гэж <xliff:g id="NUMBER">%d</xliff:g> удаа буруу оролдлоо. Утас одоо үйлдвэрийн үндсэн утгаараа тохируулагдах болно."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"<xliff:g id="NUMBER">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"Хээг мартсан уу?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"Акаунт тайлах"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"Хээ оруулах оролдлого хэт олон"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"Түгжээг тайлах бол Google акаунтаараа нэвтэрнэ үү."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"Хэрэглэгч (имэйл)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"Нууц үг"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"Нэвтрэх"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"Хэрэглэгчийн нэр эсвэл нууц үг буруу."</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"Хэрэглэгчийн нэр нууц үгээ мартсан уу?\n"<b>"google.com/accounts/recovery"</b>"-д зочилно уу."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"Шалгаж байна..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"Тайлах"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"Дуу идэвхтэй"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"Дууг хаагдсан"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"Хээ эхэлж байна"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"Хээ цэвэрлэгдэв"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"Нүд нэмэгдсэн"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"Хээ дуусав"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. %3$d. -н %2$d виджет"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Виджет нэмэх."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Хоосон"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Тайлах хэсэг нээгдсэн."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Тайлах хэсэг хаагдсан."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> виджет."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Хэрэглэгч сонгоч"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Статус"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Камер"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Медиа контрол"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Виджет дахин эрэмбэлж эхлэв."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Виджетийг дахин эрэмбэлж дуусав."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> виджет устсан."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Түгжээгүй хэсгийг өргөсгөх."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Тайлах гулсуулалт."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Тайлах хээ."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Нүүрээр тайлах"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Тайлах пин."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Тайлах нууц үг."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Хээний хэсэг."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Гулсуулах хэсэг."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"АБВ"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"тэмдэгт"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"үг"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"холбоос"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"Мөр"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"Үйлдлвэрийн тест бүтэлгүйтэв"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"FACTORY_TEST үйлдэл нь зөвхөн /system/app-д суусан багцуудад дэмжигдэнэ."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"FACTORY_TEST үйлдлийг хангах багц олдсонгүй."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"Дахин асаах"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"\"<xliff:g id="TITLE">%s</xliff:g>\" хуудас:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"JavaScript"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"Шилжүүлэлтийг бататгах"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"Энэ хуудсыг орхих"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"Энэ хуудсанд үлдэх"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nТа үнэхээр энэ хуудаснаас гармаар байна уу?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"Баталгаажуулах"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"Зөвлөмж: Өсгөх бол давхар товшино уу."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"Автомат бичих"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"Автомат дүүргэлтийг тохируулах"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"Муж"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"Шуудангийн код"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"Муж"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ZIP код"</string>
-    <string name="autofill_county" msgid="237073771020362891">"Муж"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"Арал"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"Дүүрэг"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"Хэлтэс"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"Муж"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"Мөргөлч"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"Хэсэг"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"Эмират"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"өөрийн Веб хавчуурга болон түүхийг унших"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"Апп нь Хөтчийн зочилж байсан бүх URL-н түүх болон Хөтчийн бүх хавчуургыг унших боломжтой. Анхаар: Энэ зөвшөөрөл нь гуравдагч талын хөтөч эсвэл вебээр хөтөчлөх чадавхтай аппликешнүүдэд ашиглагдахгүй байх боломжтой."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"веб хавчуурга болон түүхийг бичих"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"Апп нь таны таблет дээр хадгалагдсан Хөтчийн түүх эсвэл хавчуургыг өөрчлөх боломжтой. Энэ нь апп-д Хөтчийн датаг арилгах эсвэл өөрчлөх боломжийг олгоно. Анхаар: Энэ зөвшөөрөл нь гуравдагч талын хөтөч эсвэл вебээр хөтөчлөх чадвартай аппликешнд ажиллахгүй байх боломжтой."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"Апп нь таны утсан дээр хадгалагдсан Хөтчийн түүх эсвэл хавчуургыг өөрчлөх боломжтой. Энэ нь апп-д Хөтчийн датаг арилгах эсвэл өөрчлөх боломжийг олгоно. Анхаар: Энэ зөвшөөрөл нь гуравдагч талын хөтөч эсвэл вебээр хөтөчлөх чадвартай аппликешнд ажиллахгүй байх боломжтой."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"сэрүүлэг тохируулах"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"Апп нь суулгагдсан сэрүүлэгний апп дээр сэрүүлэг тохируулах боломжтой. Зарим сэрүүлэгний апп нь энэ функцийг дэмжихгүй байж болзошгүй."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"дуут шуудан нэмэх"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"Апп нь таны дуут шуудангийн ирсэн мэйлд мессеж нэмэх боломжтой."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"Хөтчийн геобайршлын зөвшөөрлийг өөрчлөх"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"Апп нь Хөтчийн гео байршлын зөвшөөрлийг өөрчлөх боломжтой. Хортой апп нь энийг ашиглан дурын веб хуудасруу байршлын мэдээллийг илгээх боломжтой."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"багцийг тулгах"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"Апп нь багцыг суулгаж болох эсэхийг шалгах боломжтой."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"багц тулгагчтэй холбох"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"Эзэмшигч нь багц тулгагчдад хүсэлт тавих боломжтой. Энгийн апп-д хэрэглэгдэхгүй."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"сериал портруу хандах"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"Эзэмшигч нь SerialManager API ашиглан сериал портод хандах боломжтой."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"контент нийлүүлэгчид гаднаас хандах"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"Эзэмшигч нь шелээс контент нийлүүлэгчид хандах боломжтой. Энгийн апп-с хэрэглэхгүй."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"төхөөрөмжийн автомат шинэчлэлтийг хориглох"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"Эзэмшигч нь төхөөрөмжийг дэвшүүлэхээр хэзээ дахин асаавал тохирох тухай системд мэдээлэл санал болгох боломжтой."</string>
-    <string name="save_password_message" msgid="767344687139195790">"Та хөтчид энэ нууц үгийг сануулах уу?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"Одоо биш"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"Санах"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"Хэзээ ч үгүй"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"Танд энэ хуудсыг нээх зөвшөөрөл байхгүй."</string>
-    <string name="text_copied" msgid="4985729524670131385">"Текст хуулагдав."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"Илүү"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"Цэс+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"зай"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"оруулах"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"устгах"</string>
-    <string name="search_go" msgid="8298016669822141719">"Хайх"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"Хайх"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"Хайх асуулга"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"Асуулгыг цэвэрлэх"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"Асуулгыг илгээх"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"Дуут хайлт"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"Хүрч хайх функцийг идэвхтэй болгох уу?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> нь Хүрч танихыг идэвхжүүлэхийг шаардаж байна. Хүрч таних идэвхжсэн үед та хуруун доороо юу байгааг сонсох, тайлбарыг харах боломжтой ба таблеттайгаа дохиогоор харилцах боломжтой."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> нь Хүрч танихыг идэвхжүүлэхийг шаардаж байна. Хүрч таних идэвхжсэн тохиолдолд та хуруун доороо юу байгааг сонсох, тайлбарыг харах боломжтой ба утастайгаа дохиогоор харилцах боломжтой."</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"1 сарын өмнө"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"1 сарын өмнө"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"1 секундын өмнө"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> секундын өмнө"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"1 минутын өмнө"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> минутын өмнө"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"1 цагийн өмнө"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> цагийн өмнө"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"Сүүлийн <xliff:g id="COUNT">%d</xliff:g> өдөр"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"Сүүлийн сар"</string>
-    <string name="older" msgid="5211975022815554840">"Хуучин"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"өчигдөр"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> өдрийн өмнө"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"1 секундын дараа"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> секундын дараа"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"1 минутын дараа"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g> минутын дараа"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"1 цагийн дараа"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> цагийн дараа"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"маргааш"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> өдрийн дараа"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"1 секундын өмнө"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> сек дараа"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"1 мин өмнө"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> минутын өмнө"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"1 цагийн өмнө"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> цагийн өмнө"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"өчигдөр"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> өдрийн өмнө"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"1 сек дараа"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> сек дараа"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"1 мин дараа"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> минутын дараа"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"1 цагийн дараа"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> цагийн дараа"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"маргааш"</item>
-    <item quantity="other" msgid="2973062968038355991">"<xliff:g id="COUNT">%d</xliff:g> өдрийн дараа"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g>"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"<xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g>"</string>
-    <string name="day" msgid="8144195776058119424">"өдөр"</string>
-    <string name="days" msgid="4774547661021344602">"өдөр"</string>
-    <string name="hour" msgid="2126771916426189481">"цаг"</string>
-    <string name="hours" msgid="894424005266852993">"цаг"</string>
-    <string name="minute" msgid="9148878657703769868">"мин"</string>
-    <string name="minutes" msgid="5646001005827034509">"минут"</string>
-    <string name="second" msgid="3184235808021478">"сек"</string>
-    <string name="seconds" msgid="3161515347216589235">"сек"</string>
-    <string name="week" msgid="5617961537173061583">"7 хоног"</string>
-    <string name="weeks" msgid="6509623834583944518">"7 хоног"</string>
-    <string name="year" msgid="4001118221013892076">"жил"</string>
-    <string name="years" msgid="6881577717993213522">"жил"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"1 секунд"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> секунд"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"1 минут"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> минут"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"1 цаг"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> цаг"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"Видео алдаа"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"Энэ видео энэ төхөөрөмж дээр урсгалаар гарч чадахгүй."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"Энэ видеог тоглуулах боломжгүй."</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"Тийм"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"үд"</string>
-    <string name="Noon" msgid="3342127745230013127">"Үд"</string>
-    <string name="midnight" msgid="7166259508850457595">"шөнө дунд"</string>
-    <string name="Midnight" msgid="5630806906897892201">"Шөнө дунд"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"Бүгдийг сонгох"</string>
-    <string name="cut" msgid="3092569408438626261">"Таслах"</string>
-    <string name="copy" msgid="2681946229533511987">"Хуулах"</string>
-    <string name="paste" msgid="5629880836805036433">"Буулгах"</string>
-    <string name="replace" msgid="5781686059063148930">"Орлуулах…"</string>
-    <string name="delete" msgid="6098684844021697789">"Устгах"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL хуулах"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"Текст сонгох"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"Текст сонгох"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"Толь бичигт нэмэх"</string>
-    <string name="deleteText" msgid="6979668428458199034">"Устгах"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"Оруулах арга"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"Текст үйлдэл"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"Сангийн хэмжээ дутагдаж байна"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"Зарим систем функц ажиллахгүй байна"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> ажиллаж байна"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"Илүү мэдээлэл авах бол хүрэх эсвэл апп-г зогсооно уу ."</string>
-    <string name="ok" msgid="5970060430562524910">"Тийм"</string>
-    <string name="cancel" msgid="6442560571259935130">"Цуцлах"</string>
-    <string name="yes" msgid="5362982303337969312">"Тийм"</string>
-    <string name="no" msgid="5141531044935541497">"Цуцлах"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"Анхаар"</string>
-    <string name="loading" msgid="7933681260296021180">"Ачааллаж байна..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"Идэвхтэй"</string>
-    <string name="capital_off" msgid="6815870386972805832">"Идэвхгүй"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"Үйлдлийг дуусгах"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"Энэ ажиллагааг үндсэн болгох."</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"Систем тохиргоо &gt; Апп &gt; Татаж авсан хэсгийн үндсэн утгуудыг цэвэрлэх"</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"Үйлдэл сонгох"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB төхөөрөмжийн апп-г сонгох"</string>
-    <string name="noApplications" msgid="2991814273936504689">"Энэ ажиллагааг гүйцэтгэх апп байхгүй."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"Харамсалтай, <xliff:g id="APPLICATION">%1$s</xliff:g> зогссон."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"Харамсалтай нь <xliff:g id="PROCESS">%1$s</xliff:g> процесс зогссон."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> хариу өгөхгүй байна.\n\nТа хаамаар байна уу?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> активити хариу өгөхгүй байна.\n\nТа энийг хаах уу?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> хариу өгөхгүй байна. Та энийг хаамаар байна уу?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"<xliff:g id="PROCESS">%1$s</xliff:g> процесс хариу өгөхгүй байн.\n\nТа хаамаар байна уу?"</string>
-    <string name="force_close" msgid="8346072094521265605">"Тийм"</string>
-    <string name="report" msgid="4060218260984795706">"Мэдэгдэх"</string>
-    <string name="wait" msgid="7147118217226317732">"Хүлээх"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"Хуудас хариу өгөхгүй байна.\n\nТа энийг хаах уу?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"Aпп дахин чиглүүлэгдэв"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> одоо ажиллаж байна."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> ажиллав."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"Цар хэмжээ"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"Байнга харуулах"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"Энийг Системийн тохиргоо &gt; Апп &gt; Татаж авсан дотроос дахин идэвхтэй болгох боломжтой."</string>
-    <string name="smv_application" msgid="3307209192155442829">"<xliff:g id="APPLICATION">%1$s</xliff:g> апп (<xliff:g id="PROCESS">%2$s</xliff:g> процесс) өөрийнхөө StrictMode бодлогыг зөрчив."</string>
-    <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> процесс өөрийнхөө StrictMode бодлогыг зөрчив."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Андройдыг дэвшүүлж байна…"</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"<xliff:g id="NUMBER_1">%2$d</xliff:g>-н <xliff:g id="NUMBER_0">%1$d</xliff:g> апп-г тохируулж байна."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"Апп-г эхлүүлж байна."</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"Эхлэлийг дуусгаж байна."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> ажиллаж байна"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"Апп сэлгэх бол хүрнэ үү"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"Апп сэлгэх үү?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"Та шинэ апп-г ажиллуулахын өмнө зогсоох ёстой өөр апп ажиллаж байна."</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g>-руу буцах"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"Шинэ апп-г эхлүүлж болохгүй."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> эхлүүлэх"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"Хуучин апп-г хадгалахгүйгээр зогсооно уу."</string>
-    <string name="sendText" msgid="5209874571959469142">"Текст илгээх үйлдлийг сонгох"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"Хонхны аяны хэмжээ"</string>
-    <string name="volume_music" msgid="5421651157138628171">"Медиа дууны хэмжээ"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"Блютүүтээр тоглож байна"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"Хонхны дууг чимээгүй болгов"</string>
-    <string name="volume_call" msgid="3941680041282788711">"Ирсэн дуудлагын дууны хэмжээ"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"Блютүүт ирсэн дуудлагын дууны хэмжээ"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"Сэрүүлгийн дууны хэмжээ"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"Мэдэгдлийн дууны хэмжээ"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"Дууны хэмжээ"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"Блютүүтын хэмжээ"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"Хонхны дууны хэмжээ"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"Дуудлагын дууны хэмжээ"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"Медиа дууны хэмжээ"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"Мэдэгдлийн дууны хэмжээ"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"Үндсэн хонхны ая"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"Үндсэн хонхны ая (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"Алийг нь ч биш"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"Хонхны ая"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"Үл мэдэгдэх хонхны ая"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi сүлжээ ашиглах боломжтой"</item>
-    <item quantity="other" msgid="4192424489168397386">"Wi-Fi сүлжээ ашиглах боломжгүй"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"Нээллтэй Wi-Fi сүлжээ ашиглах боломжтой"</item>
-    <item quantity="other" msgid="7915895323644292768">"Нээлттэй Wi-Fi сүлжээ ашиглах боломжтой"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Wi-Fi сүлжээнд нэвтэрнэ үү"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"Сүлжээнд нэвтрэх"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Wi-Fi-д холбогдож чадсангүй"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" Интернет холболт муу байна."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"Wi-Fi Шууд"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"Wi-Fi Шуудыг эхлүүлнэ үү. Энэ нь Wi-Fi клиент/холболтын цэг унтраана."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"Wi-Fi Шуудыг эхлүүлж чадсангүй."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi Шууд асав"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"Тохируулах бол хүрнэ үү"</string>
-    <string name="accept" msgid="1645267259272829559">"Зөвшөөрөх"</string>
-    <string name="decline" msgid="2112225451706137894">"Татгалзах"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"Урилга илгээгдсэн"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"Холбох урилга"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"Хэнээс:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"Хэнд:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"Шаардлагатай PIN-г бичнэ үү:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"Таблет <xliff:g id="DEVICE_NAME">%1$s</xliff:g>-тэй холбогдох үедээ түр зуур Wi-Fi-с салах болно."</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"Утас <xliff:g id="DEVICE_NAME">%1$s</xliff:g>-тай холбогдох үедээ түр зуур Wi-Fi-с салах болно."</string>
-    <string name="select_character" msgid="3365550120617701745">"Тэмдэгт оруулах"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS мессеж илгээж байна"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; их хэмжээний SMS мессежийг илгээж байна. Та энэ апп-д үргэлжлүүлэн мессеж илгээхийг зөвшөөрөх үү?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"Зөвшөөрөх"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"Татгалзах"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; нь &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt; уруу мессеж илгээх гэж байна."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"Энэ таны мобайл акаунтад "<font fgcolor="#ffffb060">"төлбөр гаргаж"</font>" болзошгүй."</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"Энэ таны мобайл акаунтад төлбөр гаргах болно."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"Илгээх"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"Цуцлах"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"Миний сонголтыг санах"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"Та дараа энийг Тохиргоо &gt; Апп дотроос солих боломжтой"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"Байнга зөвшөөрөх"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"Хэзээ ч зөвшөөрөхгүй"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM карт хасагдсан"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"Зөв SIM карт хийгээд дахин асаатал та мобайл сүлжээг ашиглах боломжгүй."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"Дуусгах"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM карт нэмэгдсэн"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"Мобайл сүлжээнд хандах бол төхөөрөмжөө дахин асаан уу."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"Дахин эхлүүлэх"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"Цагийн тохируулах"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"Огноо оруулах"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"Тохируулах"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"Дуусгах"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"ШИНЭ: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g> өгсөн."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"Зөвшөөрөл шаардахгүй"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"Энэ таныг төлбөрт оруулж болзошгүй"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB масс сан"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB холбогдсон"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"Та өөрийн компьютертээ USB-р холбогдсон байна. Хэрэв та өөрийн компьютер болон өөрийн Андройдын USB сан хооронд файл хуулах бол доорх товчинд хүрнэ үү."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"Та өөрийн компьютертээ USB-р холбогдсон байна. Хэрэв та өөрийн компьютер болон өөрийн Андройдын USB сан хооронд файл хуулах бол доорх товчинд хүрнэ үү."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB санг асаах"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB санг USB масс сан болгон ашиглахад алдаа гарав."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"SD картыг USB масс сан болгон ашиглахад алдаа гарав."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB холбогдсон"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"Өөрийн компьютер- ээс/луу файл хуулах бол хүрнэ үү"</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB санг унтраах"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB санг унтраах бол хүрнэ үү."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB сан ашиглагдаж байна"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB санг унтраахаас өмнө өөрийн Андройдын SD картыг компьютерээсээ салгана(\"гаргана\") уу."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB санг унтраахаас өмнө өөрийн Андройдын SD картыг компьютерээсээ салгана(\"гаргана\") уу."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB санг унтраах"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB санг унтраахад алдаа гарав. USB хостоо салгасан эсэхээ шалгаад дахин оролдоно уу."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB санг асаах"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"Хэрэв та USB санг асуувал таны ашиглаж байга зарим апп зогсох ба та USB сангаа унтраатал ашиглах боломжгүй байж болзошгүй."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB ажиллагаа бүтэлгүйтэв"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"Тийм"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"Медиа төхөөрөмж болон холбогдов"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"Камер болгон холбов"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"Суулгагч болгон холбогдсон"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB төхөөрөмжид холбогдов"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"Бусад USB сонголт хийх бол хүрнэ үү."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB санг форматлах уу?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD картыг форматлах уу?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"Таны USB санд хадгалагдсан бүх файл арилгагдана. Энэ үйлдлийг буцаах боломжгүй!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"Таны картан дээрх бүх дата устах болно."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"Форматлах"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB дебаг холбогдсон"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB дебаг хийхийг идэвхгүй болгох бол хүрнэ үү."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"Оруулах аргыг сонгоно уу"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"Оруулах аргыг тохируулах"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"Бодит гар"</string>
-    <string name="hardware" msgid="7517821086888990278">"Хардвер"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"Гарын схемийг сонгох"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"Гарын схемийг сонгох бол хүрнэ үү."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"нэр дэвшигч"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB санг бэлдэж байна"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD карт бэлдэж байна"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"Алдааг шалгаж байна."</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"Хоосон USB сан"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"Хоосон SD карт"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB сан хоосон эсвэл дэмжигдэхгүй файл системтэй."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD карт хоосон эсвэл дэмжигдэхгүй файл систем."</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"Гэмтсэн USB сан"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"Гэмтсэн SD карт"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB сан гэмтсэн байна. Дахин форматлаж үзнэ үү."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD карт гэмтсэн байна. Дахин форматлаж үзнэ үү."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB санг санамсаргүй хасагдав"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD карт санамсаргүй хасагдав"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"Дата хохирлоос сэргийлж USB санг сугалахаасаа өмнө салгаж байна уу."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"Дата хохирлоос сэргийлж SD картыг хасахаасаа өмнө салгаж байна уу."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB санг салгаж авахад аюулгүй."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD картыг хасахад аюулгүй"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"USB санг сугалахад аюулгүй."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"SD картаа салгаж авах аюулгүй."</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"Хасагдсан USB сан"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"Сугалсан SD карт"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB сан сугалагдав. Шинэ медиаг хийнэ үү."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD карт хасагдав. Шинийг хийнэ үү."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"Таарах активити олдсонгүй."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"компонент ашиглалтын статистикийг шинэчлэх"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"Апп нь компонент хэрэглээний цуглуулагдсан статистикийг өөрчлөх боломжтой. Энгийн апп-д шаардлагагүй."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"контент хуулах"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"Апп нь контентыг хуулах үндсэн контейнер үйлчилгээг дуудах боломжтой. Энгийн апп-д ашиглах боломжгүй."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"Медиа гаралтыг чиглүүлэх"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"Аппликешн нь медиа гаралтыг бусад гадаад төхөөрөмжрүү чиглүүлэх боломжтой."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"Түлхүүр хамгаалах аюулгүй санд хандах"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"Аппликешн нь хамгаалалттай аюулгүй санд хандах боломжтой."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"Түлхүүр хамгаалалтын харуулах болон далдлахыг удирдах"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"Аппликешн нь түлхүүр хамгаалагчыг удирдах боломжтой."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"Өсгөх контрол дээр хоёр удаа товшино уу"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"Виджет нэмж чадсангүй."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"Очих"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"Хайх"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"Илгээх"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"Дараах"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"Дуусгах"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"Өмнөх"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"Ажиллуулах"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"<xliff:g id="NUMBER">%s</xliff:g> ашиглан \n залгах"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"<xliff:g id="NUMBER">%s</xliff:g> дугаар ашиглан \n харилцагч үүсгэх"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"Дараах нэг буюу түүнээс дээш апп таны акаунтад одоо болон дараа хандах зөвшөөрлийг хүсэж байна."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"Та энэ хүсэлтийг зөвшөөрөх үү?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"Хандах хүсэлт"</string>
-    <string name="allow" msgid="7225948811296386551">"Зөвшөөрөх"</string>
-    <string name="deny" msgid="2081879885755434506">"Татгалзах"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"Зөвшөөрөл хүсэв"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"<xliff:g id="ACCOUNT">%s</xliff:g> акаунт зөвшөөрөл \n хүссэн"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"Оруулах арга"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"Синк"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"Хандалт"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"Ханын зураг"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"Ханын зураг солих"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"Мэдэгдэл сонсогч"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN идэвхтэй болов"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN-г <xliff:g id="APP">%s</xliff:g> идэвхтэй болгов"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"Сүлжээг удирдах бол хүрнэ үү."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g>-д холбогдов. Сүлжээг удирдах бол хүрнэ үү."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"Байнгын VPN-д холбогдож байна..."</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"Байнга VPN холбоотой"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"Байнгын VPN алдаа"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"Тохируулах бол хүрнэ үү"</string>
-    <string name="upload_file" msgid="2897957172366730416">"Файл сонгох"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"Сонгосон файл байхгүй"</string>
-    <string name="reset" msgid="2448168080964209908">"Бүгдийг цэвэрлэх"</string>
-    <string name="submit" msgid="1602335572089911941">"Илгээх"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"Машины горим идэвхтэй болов"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"Машины горимоос гарах бол хүрнэ үү."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"Модем болгох эсвэл идэвхтэй цэг болгох"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"Тохируулах бол хүрнэ үү."</string>
-    <string name="back_button_label" msgid="2300470004503343439">"Буцах"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"Дараах"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"Алгасах"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"Мобайл дата хэрэглээ өндөр"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"Мобайл дата хэрэглээний талаар дэлгэрэнгүй үзэх бол хүрнэ үү"</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"Мобайл дата хязгаар хэтрэв"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"Мобайл дата хэрэглээний талаар дэлгэрэнгүй үзэх бол хүрнэ үү"</string>
-    <string name="no_matches" msgid="8129421908915840737">"Илэрц алга"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"Хуудаснаас олох"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"1 утга"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="TOTAL">%d</xliff:g>-н <xliff:g id="INDEX">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"Дуусгах"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB санг салгаж байна…"</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD картыг салгаж байна…"</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB санг арилгаж байна…"</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD картыг цэвэрлэж байна…"</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB санг арилгаж чадсангүй."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD картыг арилгаж чадсангүй."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD картыг салгалгүйгээр хассан байна."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB санг одоо шалгаж байна."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD картыг одоо шалгаж байна."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD картыг сугалсан байна."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"USB санг одоо компьютерээс ашиглаж байна."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"USB санг одоо компьютерээс ашиглаж байна."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"Гадаад медиа үл мэдэгдэх статустай байна."</string>
-    <string name="share" msgid="1778686618230011964">"Хуваалцах"</string>
-    <string name="find" msgid="4808270900322985960">"Олох"</string>
-    <string name="websearch" msgid="4337157977400211589">"Веб хайлт"</string>
-    <string name="find_next" msgid="5742124618942193978">"Дараагийнхыг хайх"</string>
-    <string name="find_previous" msgid="2196723669388360506">"Өмнөхөөс олох"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g>-н байршлын хүсэлт"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"Байршлын хүсэлт"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) хүсэлт илгээсэн"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"Тийм"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"Үгүй"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"Устгах хязгаар хэтрэв"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g>-р <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g> акаунтын <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> зүйл устсан . Та юу хиймээр байна?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"Устгах"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"Устгасныг буцаах"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"Одоо юу ч хийхгүй"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"Акаунт сонгох"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"Акаунт нэмэх"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"Аккаунт нэмэх"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"Өсөх"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"Бууруулах"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> хүрээд барина уу."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"Өсгөх бол дээшээ бууруулах бол доошоо гулсуулна уу."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"Минут өсгөх"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"Минутыг бууруулах"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"Цаг өсгөх"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"Цаг бууруулах"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"PM тохируулах"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"AM тохируулах"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"Сар өсгөх"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"Сарыг бууруулах"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"Өдөр өсгөх"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"Өдрийг бууруулах"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"Жилийг өсгөх"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"Жил бууруулах"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Цуцлах"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Устгах"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Дуусгах"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Горим өөрчлөх"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Шифт"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Оруулах"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"Апп сонгох"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"Хуваалцах"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g>-тай хуваалцана уу"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"Бариулыг гулсуулна. Хүрээд хүлээнэ."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-г гулсуулах."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> хийх бол доош гулсуулах."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> хийх зүүнлүү гулсуулах."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> хийх бол баруунлуу гулсуулах."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Тайлах"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Камер"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Чимээгүй"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Дуунууд идэвхтэй"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Хайх"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"Түгжээг тайлах бол татна уу"</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"Нууц үгний дуудлагыг сонсох бол чихэвчийг залгана уу."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"Цэг."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"Нүүр хуудасруу шилжих"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"Дээш шилжих"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"Нэмэлт сонголтууд"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"Дотоод сан"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD карт"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB сан"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"Засах"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"Дата хэрэглээний анхааруулга"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"Ашиглалт болон тохиргоог харах бол хүрнэ үү."</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G дата идэвхгүй болов"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G дата идэвхгүй байна"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"Мобайл дата идэвхгүй"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi-Fi дата идэвхгүй"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"Идэвхжүүлэх бол хүрнэ үү."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G дата хязгаар хэтрэв"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G дата хязгаар хэтрэв"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"Мобайл дата хязгаар хэтрэв"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi-Fi дата хязгаар хэтрэв"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> заасан хязгаарыг давав."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"Арын дата хязгаарлагдсан"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"Хязгаарлалтыг хасах бол хүрнэ үү."</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"Аюулгүй сертификат"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"Сертификат хүчинтэй."</string>
-    <string name="issued_to" msgid="454239480274921032">"Гаргуулсан:"</string>
-    <string name="common_name" msgid="2233209299434172646">"Ерөнхий нэр:"</string>
-    <string name="org_name" msgid="6973561190762085236">"Байгууллага:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"Байгууллагын нэгж:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"Гаргасан:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"Хүчинтэй байх:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"Гаргасан:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"Хүртэл хүчинтэй:"</string>
-    <string name="serial_number" msgid="758814067660862493">"Сериал дугаар:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"Хурууны хээ:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 хурууны хээ:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 хурууны хээ:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"Бүгдийг харах"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"Активити сонгох"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"Хуваалцах"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"Төхөөрөмж түгжигдсэн."</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"Илгээж байна ..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"Хөтөч ажиллуулах уу?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"Дуудлагыг зөвшөөрөх үү?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"Байнга"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"Нэг удаа"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"Таблет"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"Утас"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"Чихэвч"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"Чанга яригчийг суулгах"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"Систем"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"Блютүүт аудио"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"Утасгүй дэлгэц"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"Дууссан"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"Медиа гаралт"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"Скан хийж байна..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"Холбогдож байна..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"Боломжтой"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"Боломжгүй"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"Ашиглаж байгаа"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"Үндсэн дэлгэц"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI Дэлгэц"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"Давхарга #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", найдвартай"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"Утасгүй дэлгэц холбогдов"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"Энэ дэлгэц өөр төхөөрөмжийг харуулж байна"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"Салгах"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Яаралтай дуудлага"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Хээг мартсан"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Буруу хээ"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Нууц үг буруу"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN буруу"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%1$d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Хээг зурах"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN оруулна уу"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN оруулна уу"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Нууц үгээ оруулна уу"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM идэвхгүй байна. Үргэлжлүүлэх бол PUK кодыг оруулна уу. Дэлгэрэнгүй мэдээллийг оператороос асууна ууу"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Хүссэн PIN кодоо оруулна уу"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Хүссэн PIN кодоо дахин оруулна уу"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM картны түгжээг гаргаж байна…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Буруу PIN код."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"4-8 тооноос бүтэх PIN-г бичнэ үү."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK код 8-с цөөнгүй тооноос бүтнэ."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Зөв PUK кодыг дахин оруулна уу. Давтан оролдвол SIM нь бүрмөсөн идэвхгүй болгоно."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN кодууд таарахгүй байна"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Хээ оруулах оролдлого хэт олон"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Түгжээг тайлах бол Google акаунтаараа нэвтэрнэ үү."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Хэрэглэгчийн нэр (имэйл)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Нууц үг"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Нэвтрэх"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Хэрэглэгчийн нэр эсвэл нууц үг буруу."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Хэрэглэгчийн нэр нууц үгээ мартсан уу?\n"<b>"google.com/accounts/recovery"</b>"-д зочилно уу."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Акаунт шалгаж байна…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Та PIN кодоо <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу бичив. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Та PIN кодоо <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу бичив. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Та таблетыг тайлах гэж <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу оролдлоо. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол таблет үйлдвэрийн үндсэн утгаараа тохируулагдах ба хэрэглэгчийн дата бүхэлдээ устана."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Та утсыг тайлах гэж <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу оролдлоо. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол утас үйлдвэрийн үндсэн утгаараа тохируулагдах ба хэрэглэгчийн дата бүхэлдээ устана."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Та таблетыг тайлах гэж <xliff:g id="NUMBER">%d</xliff:g> удаа буруу оролдлоо. Таблет одоо үйлдвэрийн үндсэн утгаараа тохируулагдах болно."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Та утсыг тайлах гэж <xliff:g id="NUMBER">%d</xliff:g> удаа буруу оролдлоо. Утас одоо үйлдвэрийн үндсэн утгаараа тохируулагдах болно."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оруулбал, та таблетаа тайлахын тулд имэйл акаунт шаардлагатай болно.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оруулбал, та утсаа тайлахын тулд имэйл акаунтаа ашиглах шаардлагатай болно.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Устгах"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"Дууг санал болгосон дээд төвшинөөс өсгөх үү. \n Өндөр дуугаар урт хугацаанд сонсох нь таны сонсголд хортой."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"Хялбар горимыг идэвхжүүлэх бол хоёр хуруугаараа доошлуулаад хүлээнэ үү."</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"Хялбаршуулсан горим идэвхжив."</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"Хандалт цуцлагдсан."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Одоогийн хэрэглэгч <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="owner_name" msgid="2716755460376028154">"Эзэмшигч"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"Алдаа"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"Энэ аппликешн хязгаарлагдсан профайлын акаунтыг дэмжихгүй."</string>
-    <string name="app_not_found" msgid="3429141853498927379">"Энэ ажиллагааг зохицуулах аппликешн олдсонгүй."</string>
-    <string name="revoke" msgid="5404479185228271586">"Цуцлах"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"Letter"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"Government Letter"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"Legal"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Junior Legal"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Ledger"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Tabloid"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"Цуцлагдсан"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"Контентыг бичих явцад алдаа гарсан"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN оруулна уу"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"Одоогийн PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"Шинэ PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"Шинэ PIN-г баталгаажуулах"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"Өөрчлөлтийг хязгаарлахад зориулан PIN үүсгэх"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN таарахгүй байна. Дахин оролдоно уу."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN хэт богино байна. Хамгийн багадаа 4 цифртэй байх ёстой."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"Буруу PIN. 1 секундын дараа дахин оролдоно уу."</item>
-    <item quantity="other" msgid="8030607343223287654">"Буруу PIN. <xliff:g id="COUNT">%d</xliff:g> секундын дараа дахин оролдоно уу."</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Баганыг харуулахын тулд дэлгэцийн ирмэгийг шудрана уу"</string>
-</resources>
diff --git a/core/res/res/values-ms-rMY/strings.xml b/core/res/res/values-ms-rMY/strings.xml
index 7a46b0c..88d76e7 100644
--- a/core/res/res/values-ms-rMY/strings.xml
+++ b/core/res/res/values-ms-rMY/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Cuba <xliff:g id="COUNT">%d</xliff:g> saat lagi"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Cuba sebentar lagi"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Leret ke bawah untuk keluar dari skrin penuh"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Leret ke bawah untuk keluar dari skrin penuh"</string>
 </resources>
diff --git a/core/res/res/values-ms/strings.xml b/core/res/res/values-ms/strings.xml
index f522a48..a9fe930 100644
--- a/core/res/res/values-ms/strings.xml
+++ b/core/res/res/values-ms/strings.xml
@@ -314,7 +314,7 @@
     <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"halang pertukaran apl"</string>
     <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"Menghalang pengguna daripada bertukar kepada apl lain."</string>
     <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"dapatkan maklumat apl semasa"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"Membenarkan pemegang mendapatkan maklumat peribadi tentang aplikasi dan perkhidmatan semasa di latar hadapan skrin."</string>
+    <string name="permdesc_getTopActivityInfo" msgid="2512448855496067131">"Membenarkan pemegang mendapatkan maklumat peribadi tentang permohonan semasa di latar hadapan skrin"</string>
     <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"pantau dan kawal semua pelancaran apl"</string>
     <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"Membenarkan apl untuk memantau dan mengawal cara sistem melancarkan aktiviti. Apl hasad boleh menjejaskan sistem sepenuhnya. Kebenaran ini hanya diperlukan untuk pembangunan, tidak sekali-kali untuk penggunaan biasa."</string>
     <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"hantar siaran bahawa pakej telah dialih keluar"</string>
@@ -362,8 +362,10 @@
     <string name="permdesc_bindPrintService" msgid="7960067623209111135">"Membenarkan pemegang terikat dengan antara muka peringkat tertinggi bagi perkhidmatan cetakan. Tidak sekali-kali diperlukan untuk apl biasa."</string>
     <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"akses semua kerja cetakan"</string>
     <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"Membenarkan pemegang mengakses kerja cetakan yang dibuat oleh apl lain. Tidak sekali-kali diperlukan untuk apl biasa."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"terikat kepada perkhidmatan NFC"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"Membenarkan pemegang untuk terikat kepada aplikasi yang mengikut kad NFC. Tidak sekali-kali diperlukan untuk apl normal."</string>
+    <!-- no translation found for permlab_bindNfcService (2752731300419410724) -->
+    <skip />
+    <!-- no translation found for permdesc_bindNfcService (6120647629174066862) -->
+    <skip />
     <string name="permlab_bindTextService" msgid="7358378401915287938">"terikat kepada perkhidmatan teks"</string>
     <string name="permdesc_bindTextService" msgid="8151968910973998670">"Membenarkan pemegang mengikat kepada antara muka peringkat atasan perkhidmatan teks(mis. PerkhidmatanPenyemakEjaan). Tidak seharusnya diperlukan untuk apl biasa."</string>
     <string name="permlab_bindVpnService" msgid="4708596021161473255">"terikat kepada perkhidmatan VPN"</string>
@@ -407,10 +409,6 @@
     <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"Membenarkan apl membaca daripada pelbagai fail log sistem. Hal ini membenarkannya menemui maklumat umum mengenai perkara yang anda lakukan dengan telefon, juga berpotensi menyertakan maklumat persendirian dan peribadi."</string>
     <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"gunakan mana-mana penyahkod media untuk main semula"</string>
     <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"Membenarkan apl untuk menggunakan sebarang penyahkod media yang dipasangkan untuk menyahkod main semula."</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
     <string name="permlab_diagnostic" msgid="8076743953908000342">"baca/tulis ke sumber yang dimiliki oleh diag"</string>
     <string name="permdesc_diagnostic" msgid="6608295692002452283">"Membenarkan apl membaca dan menulis ke sebarang sumber yang dimiliki oleh kumpulan diag; contohnya, fail dalam /dev. Hal ini berpotensi menjejaskan kestabilan dan keselamatan sistem. Perkara ini seharusnya HANYA digunakan untuk diagnosis khusus perkakasan oleh pengilang atau pengendali."</string>
     <string name="permlab_changeComponentState" msgid="6335576775711095931">"dayakan atau lumpuhkan komponen apl"</string>
@@ -476,14 +474,18 @@
     <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"Membenarkan apl menggunakan ciri peringkat rendah InputFlinger."</string>
     <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"konfigurasikan paparan Wifi"</string>
     <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"Membenarkan apl mengkonfigurasi dan menyambung ke paparan Wifi."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"kawal paparan Wifi"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Membenarkan apl mengawal ciri tahap rendah paparan Wifi."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"tangkap output audio"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"Membenarkan apl menangkap dan mengubah hala output audio."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"tangkap output video"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"Membenarkan apl menangkap dan mengubah hala output video."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"tangkap output video selamat"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"Membenarkan apl menangkap dan mengubah hala output video selamat."</string>
+    <!-- no translation found for permlab_captureAudioOutput (6857134498402346708) -->
+    <skip />
+    <!-- no translation found for permdesc_captureAudioOutput (6210597754212208853) -->
+    <skip />
+    <!-- no translation found for permlab_captureVideoOutput (2246828773589094023) -->
+    <skip />
+    <!-- no translation found for permdesc_captureVideoOutput (359481658034149860) -->
+    <skip />
+    <!-- no translation found for permlab_captureSecureVideoOutput (7815398969303382016) -->
+    <skip />
+    <!-- no translation found for permdesc_captureSecureVideoOutput (2779793064709350289) -->
+    <skip />
     <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"tukar tetapan audio anda"</string>
     <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"Membenarkan apl untuk mengubah suai tetapan audio global seperti kelantangan dan pembesar suara mana digunakan untuk output."</string>
     <string name="permlab_recordAudio" msgid="3876049771427466323">"rakam audio"</string>
@@ -657,8 +659,6 @@
     <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"Membenarkan pemegang terikat dengan antara muka peringkat tertinggi bagi perkhidmatan pendengar pemberitahuan. Tidak sekali-kali diperlukan untuk apl biasa."</string>
     <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"gunakan apl konfigurasi yang disediakan oleh pembawa"</string>
     <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"Membenarkan pemegang menggunakan apl konfigurasi yang diberikan oleh pembawa. Tidak sekali-kali diperlukan untuk apl biasa."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"dengar pemerhatian mengenai keadaan rangkaian"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"Membenarkan aplikasi mendengar pemerhatian tentang keadaan rangkaian. Tidak sekali-kali diperlukan untuk apl biasa."</string>
     <string name="policylab_limitPassword" msgid="4497420728857585791">"Tetapkan peraturan kata laluan"</string>
     <string name="policydesc_limitPassword" msgid="3252114203919510394">"Mengawal panjang dan aksara yang dibenarkan dalam kata laluan buka kunci skrin."</string>
     <string name="policylab_watchLogin" msgid="914130646942199503">"Memantau percubaan buka kunci skrin"</string>
@@ -1479,7 +1479,8 @@
     <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"Skrin HDMI"</string>
     <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"Tindih #<xliff:g id="ID">%1$d</xliff:g>"</string>
     <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", selamat"</string>
+    <!-- no translation found for display_manager_overlay_display_secure_suffix (6022119702628572080) -->
+    <skip />
     <string name="wifi_display_notification_title" msgid="2223050649240326557">"Paparan wayarles disambungkan"</string>
     <string name="wifi_display_notification_message" msgid="4498802012464170685">"Skrin ini ditunjukkan pada peranti lain"</string>
     <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"Putus sambungan"</string>
@@ -1583,5 +1584,4 @@
     <item quantity="one" msgid="4835639969503729874">"PIN salah. Cuba lagi dalam masa 1 saat."</item>
     <item quantity="other" msgid="8030607343223287654">"PIN salah. Cuba lagi dalam masa <xliff:g id="COUNT">%d</xliff:g> saat."</item>
   </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Leret bhg tepi skrin utk serlah bar"</string>
 </resources>
diff --git a/core/res/res/values-nb/strings.xml b/core/res/res/values-nb/strings.xml
index 0df98b1..3be8817 100644
--- a/core/res/res/values-nb/strings.xml
+++ b/core/res/res/values-nb/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Prøv på nytt om <xliff:g id="COUNT">%d</xliff:g> sekunder"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Prøv på nytt senere"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Sveip ned for å avslutte fullskjermvisning"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Sveip ned fra toppen av skjermen for å gå ut av fullskjermvisningen."</string>
 </resources>
diff --git a/core/res/res/values-ne-rNP/strings.xml b/core/res/res/values-ne-rNP/strings.xml
deleted file mode 100644
index fe6b669..0000000
--- a/core/res/res/values-ne-rNP/strings.xml
+++ /dev/null
@@ -1,1588 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;बिना शीर्षक&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(कुनै फोन नम्बर छैन)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(अज्ञात)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"भ्वाइस मेल"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN१"</string>
-    <string name="mmiError" msgid="5154499457739052907">"जडान समस्या वा अमान्य MMI कोड।"</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"अपरेशन निश्चित डायल नम्बरहरूको लागि मात्र प्रतिबन्धित छ।"</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"सेवा सक्षम पारियो।"</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"निम्न उल्लेखितको लागि सेवा सक्षम पारियो:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"सेवा असक्षम पारिएको छ।"</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"दर्ता सफल भयो।"</string>
-    <string name="serviceErased" msgid="1288584695297200972">"मेटाइ सफल थियो।"</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"गलत पासवर्ड।"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI पुरा भयो।"</string>
-    <string name="badPin" msgid="9015277645546710014">"तपाईंले टाइप गर्नुभएको पुरानो PIN सही छैन।"</string>
-    <string name="badPuk" msgid="5487257647081132201">"तपाईंले टाइप गर्नुभएको PUK सही छैन।"</string>
-    <string name="mismatchPin" msgid="609379054496863419">"तपाईंले टाइप गर्नुभएको PIN मेल खाँदैन।"</string>
-    <string name="invalidPin" msgid="3850018445187475377">"४ देखि ८ वटा नम्बर भएको एउटा PIN टाइप गर्नुहोस्।"</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"८ वटा नम्बरहरू वा सो भन्दा लामो एउटा PUK टाइप गर्नुहोस्।"</string>
-    <string name="needPuk" msgid="919668385956251611">"तपाईंको SIM कार्ड PUK-लक छ। यसलाई अनलक गर्न PUK कोड टाइप गर्नुहोस्।"</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM कार्ड अनलक गर्न PUK2 टाइप गर्नुहोस्।"</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"आगमन कलर ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"बाहिरिने कलर ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"कल अगाडि बढाउँदै"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"कल प्रतिक्षा"</string>
-    <string name="BaMmi" msgid="455193067926770581">"कल ब्यारिङ"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"पासवर्ड परिवर्तन"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN परिवर्तन"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"प्रस्तुत नम्बरमा कल गर्दै"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"कल गर्ने अंक रोकेको छ।"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"कल गर्ने तिन तरिका"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"नचाहिएका रिसउठ्दा कलहरूको अस्वीकार"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"कलिङ नम्बर प्रदान गर्ने"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"बाधा नगर्नुहोस्"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"सीमति गर्न पूर्वनिर्धारित कलर ID, अर्को कल: सीमति गरिएको"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"कलर ID पूर्वनिर्धारितको लागि रोकावट छ। अर्को कल: रोकावट छैन"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"कलर ID पूर्वनिर्धारितदेखि प्रतिबन्धित छैन। अर्को कल: प्रतिबन्धित छ"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"कलर ID पूर्वनिर्धारितको लागि रोकावट छैन। अर्को कल: रोकावट छैन"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"सेवाको व्यवस्था छैन।"</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"तपाईं कलर ID सेटिङ परिवर्तन गर्न सक्नुहुन्न।"</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"प्रतिबन्धित पहुँच परिवर्तन भएको छ"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"डेटा सेवा रोकिएको छ।"</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"आपतकालीन सेवा रोकिएको छ।"</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"भ्वाइस सेवा ब्लक भएको छ।"</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"सबै आवाज सेवाहरू बन्द छन्।"</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS सेवा रोकिएको छ।"</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"भ्वाइस/डेटा सेवाहरू रोकिएका छन्।"</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"आवाज/SMS सेवाहरू बन्द छन्।"</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"सबै भ्वाइस/डेटा/SMS सेवाहरू ब्लक भएका छन्।"</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"आवाज"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"डेटा"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"फ्याक्स"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"Async"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"सिङ्क गर्नुहोस्"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"प्याकेट"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"रोमिङ सूचक खुला"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"रोमिङ सूचक बन्द"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"रोमिङ सूचक फ्ल्यास गर्दै"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"छिमेकबाट बाहिर"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"बिल्डिङको बाहिर"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"रोमिङ - उपयुक्त प्रणाली"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"रोमिङ - उपलब्ध प्रणाली"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"रोमिङ - एलियन्सर पार्टनर"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"रोमिङ - प्रिमियम पार्टनर"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"रोमिङ - पूर्ण सेवा कार्यक्षमता अवस्था"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"रोमिङ - आङ्शिक सेवा प्रकार्यता"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"रोमिङ ध्वजा चालु छ"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"रोमिङ ब्यानर बन्द छ"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"सेवाको खोजी गर्दै…"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: अगाडि पठाइएको छैन"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> पछि <xliff:g id="TIME_DELAY">{2}</xliff:g> सेकेन्ड"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: अगाडि बढाइएको छैन"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: अगाडि बढाइएको छैन"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"विशेषता कोड पुरा भयो।"</string>
-    <string name="fcError" msgid="3327560126588500777">"जडान समस्या वा अमान्य सुविधा कोड।"</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"ठिक छ"</string>
-    <string name="httpError" msgid="7956392511146698522">"एउटा नेटवर्क त्रुटि थियो।"</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL भेटाउन सकेन।"</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"साइटको आधिकारिकता योजना समर्थित छैन।"</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"प्रमाणीकरण गर्न सकेन।"</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"प्रोक्सी सर्भरको माध्यमद्वारा प्रमाणिकरण असफल भएको छ।"</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"सर्भरसँग जोड्न सकेन।"</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"सर्भरसँग संचार गर्न सकेन। फेरि पछि कोसिस गर्नुहोस्।"</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"सर्भर संगको सम्पर्क प्रक्रिया समय सकियो।"</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"पृष्टमा धेरै सर्भरहरूतिर पुनः निर्देशनहरू छन्।"</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"प्रोटोकल समर्थित छैन।"</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"एउटा सुरक्षित जडान स्थापना गर्न सकेन।"</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"पृष्ठ खोल्न सकिँदैन किनभने URL अमान्य छ।"</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"फाइल भेटाउन सकेन।"</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"अनुरोध गरिएको फाइल भेटाउन सकेन।"</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"धेरै नै अनुरोधहरू प्रक्रियामा छन्। पछि फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g>को लागि साइन इन त्रुटि"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"सिङक गर्नुहोस्"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"सिङ्क गर्नुहोस्"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"अति धेरै <xliff:g id="CONTENT_TYPE">%s</xliff:g> मेट्नुहोस्।"</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ट्याब्लेट भण्डारण खाली छैन! ठाउँ खाली गर्नको लागि केही फाइलहरू मेटाउनुहोस्।"</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"फोन भण्डारण भरिएको छ! ठाउँ खाली गर्नको लागि केही फाइलहरू मेटाउनुहोस्।"</string>
-    <string name="me" msgid="6545696007631404292">"मलाई"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ट्याब्लेट विकल्पहरू"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"फोन विकल्पहरू"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"मौन मोड"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"वायरलेस अन गर्नुहोस्"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"ताररहित बन्द गर्नुहोस्"</string>
-    <string name="screen_lock" msgid="799094655496098153">"स्क्रिन लक गर्नुहोस्"</string>
-    <string name="power_off" msgid="4266614107412865048">"पावर बन्द"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"घन्टी बन्द भयो"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"घन्टी कम्पन गर्छ"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"घन्टि चालु छ"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"बन्द गर्दै..."</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"तपाईँको ट्याब्लेट बन्द हुने छ।"</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"तपाईँको फोन बन्द हुने छ।"</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"के तपाईं बन्द गर्न चाहनुहुन्छ?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"सुरक्षित मोडमा पुनःबुट गर्नुहोस्"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"सुरक्षित मोडमा तपाईँ पुनःबुट गर्न चाहनु हुन्छ? तपाईँले स्थापना गरेका सबै तेस्रो पक्षका अनुप्रयोगहरूलाई असक्षम गराउने छ।"</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"नयाँ"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"कुनै नयाँ अनुप्रयोगहरू छैनन्।"</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ट्याब्लेट विकल्पहरू"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"फोन विकल्पहरू"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"स्क्रिन बन्द"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"शक्ति बन्द"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"बग रिपोर्ट"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"बग रिपोर्ट लिनुहोस्"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"एउटा इमेल सन्देशको रूपमा पठाउनलाई यसले तपाईँको हालैको उपकरणको अवस्थाको बारेमा सूचना जम्मा गर्ने छ। बग रिपोर्ट सुरु गरेदेखि पठाउन तयार नभएसम्म यसले केही समय लिन्छ; कृपया धैर्य गर्नुहोस्।"</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"मौन मोड"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"आवाज बन्द छ"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"ध्वनि खुल्ला छ"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"हवाइजहाज मोड"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"हवाइजहाज मोड खुला छ"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"हवाइजहाज मोड बन्द छ"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"९९९+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"सुरक्षित मोड"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"एन्ड्रोइड प्रणाली"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"तपाईँले तिर्नु पर्ने सेवाहरू"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"तपाईँलाई महँगो पर्न सक्ने कामहरू गर्नुहोस्।"</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"तपाईंका सन्देशहरू"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"तपाईँका SMS, इमेल र अन्य सन्देशहरू पढ्नुहोस् र लेख्नुहोस्।"</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"तपाईँको निजी सूचना"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"तपाईँको सम्पर्क कार्डमा भण्डारण भएका तपाईँको बारेको जानकारीमा सिधा पहुँच पुर्‍याउनुहोस्।"</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"तपाईँको सामाजिक सूचना"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"तपाईँको सम्पर्कहरू र सामाजिक जडानहरूको बारेको जानकारीमा सिधा पहुँच पुर्‍याउनुहोस्।"</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"तपाईँको स्थान"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"तपाईँको भौतिक स्थान निरीक्षण गर्नुहोस्।"</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"नेटवर्क संचार"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"विभिन्न नेटवर्क सुविधाहरूमा पहुँच राख्नुहोस्।"</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"ब्लुटुथ"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"ब्लुटुथको माध्यमद्वारा उपकरणहरू र नेटवर्कहरूमाथि पहुँच राख्नुहोस्।"</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"अडियो सेटिङहरू"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"अडियो सेटिङहरू बदल्नुहोस्।"</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"ब्यट्रिलाई प्रभाव पार्छ"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"छिट्टै ब्याट्रि सकाउन सक्ने ती विशेषताहरू प्रयोग गर्नुहोस्।"</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"पात्रो"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"पात्रो तथा घटनाहरूमा प्रत्यक्ष पहुँच"</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"प्रयोगकर्ता शब्दकोश पढ्नुहोस्"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"प्रयोगकर्ता शब्दकोशमा शब्दहरू पढ्नुहोस्।"</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"प्रयोगकर्ता शब्दकोश लेख्नुहोस्"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"प्रयोगकर्ता शब्दकोशमा शब्दहरू थप्नुहोस्।"</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"बुकमार्कहरू र इतिहास"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"बुकमार्कहरू र ब्राउजर इतिहासमा सिधा पहुँच।"</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"अलार्म"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"अलार्म घडी सेट गर्नुहोस्।"</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"भ्वाइस मेल"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"भ्वाइसमेलमा सिधा पहुँच।"</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"माइक्रोफोन"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"मा[क्रोफोनबाट रेकर्ड अडियोमा सिधा पहुँच पुर्‍याउनुहोस्।"</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"क्यामेरा"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"तस्बिर वा भिडियो क्याप्चरको लागि क्यामेरामा सिधा पहुँच।"</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"स्क्रिन लक गर्नुहोस्"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"तपाईँको उपकरणमा लक स्क्रिनको व्यवहारलाई प्रभावित गर्ने क्षमता।"</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"तपाईँका अनुप्रयोगहरूको सूचना"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"तपाईँको उपकरणमा अन्य अनुप्रयोगहरूको व्यवहारमा प्रभाव पार्ने क्षमता।"</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"वालपेपर"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"उपकरण वालपेपर सेटिङहरू बदल्नुहोस्।"</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"घडी"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"उपकरण समय वा समय क्षेत्र परिवर्तन गर्नुहोस्।"</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"स्थिति पट्टी"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"उपकरण स्थिति सेटिङहरू परिवर्तन गर्नुहोस्।"</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"सिङ्क सेटिङहरू"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"सिङ्क सेटिङहरूमा पहुँच गर्नुहोस्।"</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"तपाईँका खाताहरू"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"उपलब्ध खाताहरू पहुँच गर्नुहोस्।"</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"हार्डवेयर नियन्त्रणहरू"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"ह्यान्डसेटको हार्डवेयरमा प्रत्यक्ष पहुँच।"</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"फोन कलहरू"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"अनुगमन, रेकर्ड र फोन कलहरूको प्रसोधन गर्नुहोस।"</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"प्रणाली औजारहरू"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"निम्न-स्तर पहुँच र प्रणालीको नियन्त्रण"</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"विकसित टुलहरू"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"अनुप्रयोग विकासकर्ताहरूको लागि मात्र सुविधाहरूको आवश्यकता।"</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"अन्य अनुप्रयोग UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"अन्य अनुप्रयोगहरूको UI लाई असर पार्नुहोस्"</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"भण्डारण"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB भण्डारणमाथि पहुँच गर्नुहोस्।"</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD कार्डमाथि पहुँच गर्नुहोस्।"</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"पहुँचीकरण विशेषताहरू"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"सहयोगी प्रविधि भएको विशेषताहरूले अनुरोध गर्न सक्छन्।"</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"विन्डो सामग्रीको पुनःबहाली गर्नुहोस्।"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"तपाईँको अन्तरक्रिया भइरहेको विन्डोको सामग्रीको निरीक्षण गर्नुहोस्।"</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"छोएर गरिने खोजलाई सुचारु गर्नुहोस्"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"छोइएका आइटमहरू चर्को स्वरमा बोलिने छ र स्क्रिन इशाराहरूको प्रयोगले अन्वेषण गर्न सकिन्छ।"</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"उच्च वेब पहुँचलाई सुचारु गर्नुहोस्"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"अनुप्रयोगको सामग्रीलाई थप पहुँचयोग्य बनाउन लिपिहरू स्थापना गर्न सक्नु हुन्छ।"</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"आफुले टाइप गरेको पाठको निरीक्षण गर्नुहोस्"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"व्यक्तिगत डेटा जस्तै क्रेडिट कार्ड नम्बरहरू र पासवर्डहरू समावेश गर्दछ।"</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"स्थिति पट्टिलाई अक्षम वा संशोधित गर्नुहोस्"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"स्थिति पट्टि असक्षम पार्न वा प्रणाली आइकनहरू थप्न र हटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"स्थिति पट्टि"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"अनुप्रयोगलाई स्थिति पट्टि हुन अनुमति दिन्छ।"</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"स्थिति पट्टिलाई विस्तृत/सङ्कुचित गर्नुहोस्"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"अनुप्रयोगलाई स्थिति पट्टि विस्तार वा संकुचन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"बहिर्गमन कलहरूलाई अर्को मार्ग दिनुहोस्"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"बहिर्गमन कलहरूको प्रशोधन गर्न र डायल गरिने नम्बर परिवर्तन गर्न अनुप्रयोगलाई अनुमति दिन्छ।  यो अनुमतिले अनुप्रयोगलाई मोनिटर गर्न, अन्यत्र पठाउन वा बाहिर जाने कलहरूलाई रोक्न दिन्छ।"</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"पाठ सन्देशहरू (SMS) प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"अनुप्रयोगलाई SMS सन्देशहरू प्राप्त गर्न र प्रक्रिया गर्न अनुमति दिन्छ। यसको मतलब अनुप्रयोगले तपाईंको उपकरणमा पठाइएको सन्देशहरू तपाईंलाई नदेखाईनै मोनिटर गर्न वा मेटाउन सक्दछ।"</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"पाठ सन्देश (MMS) प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"अनुप्रयोगलाई MMS सन्देशहरू प्राप्त गर्न र प्रकृया गर्न अनुमति दिन्छ। यसको मतलब अनुप्रयोगले तपाईंको उपकरणमा पठाइएको सन्देशहरू तपाईंलाई नदेखाईनै मोनिटर गर्न वा मेटाउन सक्दछ।"</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"आकस्मिक प्रसारणहरू प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"अनुप्रयोगलाई आपतकालीन प्रसारण सन्देशहरू प्राप्त गर्न र प्रक्रिया गर्न अनुमति दिन्छ। यो अनुमति प्रणाली अनुप्रयोगहरूमा मात्र उपलब्ध छ।"</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"सेल प्रसारित सन्देशहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"तपाईंको उपकरणद्वारा प्राप्त सेल प्रसारण सन्देशहरू अनुप्रयोगलाई पढ्न अनुमति दिन्छ। सेल प्रसारण चेतावनीहरू केही स्थानहरूमा तपाईंलाई आपतकालीन गतिविधिहरूको बारेमा सचेत गराउन गरिएका छन्। खराब अनुप्रयोगहरूले एउटा आपतकालीन सेल प्रसारण प्राप्त गर्दछ जब तपाईंको उपकरणको प्रदर्शन वा अपरेशनको साथ हस्तक्षेप गर्न सक्दछन्।"</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS सन्देशहरू पठाउनुहोस्"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"अनुप्रयोगलाई SMS सन्देशहरू पठाउन अनुमति दिन्छ। यसले अप्रत्यासित चार्जहरूको परिणाम दिन सक्दछ। खराब अनुप्रयोगहरूले तपाईंको पुष्टि बिना सन्देशहरू पठाएर तपाईंको पैसा खर्च गराउन सक्दछ।"</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"प्रतिक्रिया-मार्फत-सन्देश घटनाहरू पठाउनुहोस्"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"अनुप्रयोगलाई आगत कलहरूको लागि प्रतिक्रिया-मार्फत-सन्देश घटनाहरूलाई अन्य सन्देश पठाउने अनुप्रयोगहरूमा अनुरोधहरू पठाउन अनुमति दिन्छ।"</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"तपाईंका पाठ सन्देशहरू (SMS वा MMS) पढ्नुहोस्"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"तपाईँको ट्याब्लेट वा SIM कार्डमा भण्डारण भएका SMS सन्देशहरूलाई पढ्न अनुप्रयोगलाई अनुमति दिन्छ। यसले अनुप्रयोगलाई विषयवस्तु वा गोपनीयतालाई वेवास्ता गर्दै सबै SMS सन्देशहरू पढ्ने अनुमति दिन्छ।"</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"तपाईँको फोन वा SIM कार्डमा भण्डारण भएका SMS सन्देशहरूलाई पढ्न अनुप्रयोगलाई अनुमति दिन्छ। यसले सबै SMS सन्देशहरूलाई पढ्नको लागि सामग्री वा विश्वसनियता बिना नै अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"तपाईँका पाठ सन्देशहरू सम्पादन गर्नुहोस् (SMS वा MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"अनुप्रयोगलाई तपाईंको ट्याब्लेट वा SIM कार्डमा भण्डार गरिएका SMS सन्देशहरू लेख्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले तपाईंको सन्देशहरू मेटाउन सक्दछ।"</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"तपाईँको फोन वा SIM कार्डमा भण्डारण भएका SMS सन्देशहरूलाई लेख्‍नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले सायद तपाईँको सन्देशहरू मेटाउन सक्छन्।"</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"पाठ सन्देशहरू (WAP) प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"WAP सन्देशहरू प्राप्त गर्न र प्रशोधन गर्न अनुप्रयोगलाई अनुमति दिन्छ। यो अनुमतिमा मोनिटर गर्ने वा तपाईँलाई पठाइएका सन्देशहरू तपाईँलाई नदेखाई मेट्ने क्षमता समावेश हुन्छ।"</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"चलिरहेका अनुप्रयोगहरू पुनःबहाली गर्नुहोस्"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"वर्तमानमा र भरखरै चलिरहेका कार्यहरू बारेको सूचना पुनःबहाली गर्न अनुप्रयोगलाई अनुमित दिन्छ। यसले उपकरणमा प्रयोग भएका अनुप्रयोगहरूको बारेमा सूचना पत्ता लगाउन अनुप्रयोगलाई अनुमति दिन सक्छ।"</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"प्रयोगकर्ताहरू तर्फ अन्तर्क्रिया गर्नुहोस्"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"अनुप्रयोगलाई उपकरणमा विभिन्न प्रयोगकर्ताहरू मार्फत कार्यहरू गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले यो प्रयोगकर्ताहरू बिच सुरक्षा बिथोल्न प्रयोग गर्न सक्ने छन्।"</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"कुराकानी प्रयोगकर्ताहरू बिच अन्तर्क्रिया गर्न पूर्ण अनुमति"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"प्रयोगकर्तासँगको कुराकानी सबै सम्भावनालाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"प्रयोगकर्ताहरू व्यवस्थापन गर्नुहोस्"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"अनुप्रयोगलाई उपकरणमा, प्रश्न, सिर्जना र मेटाइसहित प्रयोगकर्ताहरूको प्रबन्ध गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"चलिरहेका अनुप्रयोगहरूको विवरण पुनःबहाली गर्नुहोस्"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"वर्तमानमा र भरखरै चलिरहेका कार्यहरूको बारेमा विस्तृत सूचना पुनःबहाली गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले अन्य अनुप्रयोगहरू बारेको निजी सूचना पत्ता लगाउन सक्छ।"</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"चलिरहेका अनुप्रयोगहरूलाई पुनःक्रम गराउनुहोस्"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"कामहरूलाई अग्रभाग र पृष्ठभूमिमा सार्न अनुप्रयोगलाई अनुमति दिन्छ। अनुप्रयोगले यो तपाईँको इनपुट बिना नै गर्न सक्छ।"</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"चालु भइरहेका अनुप्रयोगहरू रोक्नुहोस्"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"कामहरू हटाउन र उनीहरूको अनुप्रयोगहरूलाई बन्द गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले अन्य अनुप्रयोगहरूको व्यवहारलाई अबरोध गर्न सक्छन्।"</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"activity stacks को प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"अनुप्रयोगलाई अन्य अनुप्रयोगहरू चल्ने activity stacks लाई थप्न, हटाउन र परिवर्तन गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले अन्य अनुप्रयोगहरूको व्यवहारलाई विघटन गर्न सक्छन्।"</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"कुनै गतिविधि सुरु गर्नुहोस्"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"अनुमति सुरक्षा वा निर्यात अवस्थालाई वास्ता नगरिकन कुनै पनि कार्य सुरु गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"स्क्रिन अनुकूलता सेट गर्नुहोस्"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"अन्य अनुप्रयोहरूको स्क्रिन मिल्दो मोडलाई नियन्त्रण गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। अन्य अनुप्रयोहरूको व्यवहार खराब अनुप्रयोगहरूले टुटाउन सक्छन्।"</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"अनुप्रयोग डिबग गर्ने सक्षम गर्नुहोस्"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"अनुप्रयोगलाई अन्य अनुप्रयोगको लागि डिबग गर्ने प्रक्रिया चालु गर्ने अनुमति दिन्छ। खराब अनुप्रयोगले अरू अनुप्रयोगहरू समाप्त गर्न यसको उपयोग गर्न सक्दछ।"</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"प्रणाली प्रदर्शन सेटिङहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"वर्तमान कन्फिगरेसन जस्तै लोक्याल वा सबैतिर फन्ट आकार बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"कार मोड सक्षम गर्नुहोस्"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"कार मोडलाई सक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"अनुप्रयोगहरू बन्द गर्नुहोस्"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"अनुप्रयोगलाई अन्य अनुप्रयोगहरूको पृष्ठभूमि प्रक्रियाहरू बन्द गर्न अनुमति दिन्छ। यसले अन्य अनुप्रयोगहरूलाई चल्नबाट रोक्न सक्दछ।"</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"अन्य अनुप्रयोगहरू दबाबमा रोक्नुहोस्"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"अन्य अनुप्रयोगहरूलाई बलपूर्वक बन्द गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"अनुप्रयोग बन्द गर्न बल गर्नुहोस्"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"अग्रभागमा भएको कुनै गतिविधिलाई जबरजस्ती बन्द गर्न र फर्केर जानका लागि अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाइ कहिल्यै आवश्यकता पर्दैन।"</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"प्रणालीको आन्तरिक स्थिति प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"प्रणालीको आन्तरिक स्थिति पुनःबहाली गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले उनीहरूलाई सामान्यतः कहिल्यै नचाहिने व्यापक विविधताको निजी र सुरक्षित सूचना पुनःबहाली गर्न सक्छन्।"</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"स्क्रिन सामग्री बहाली गर्नुहोस्"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"सक्रिय विन्डोको विषयवस्तुलाई पुनःबहाली गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले पुरै विन्डोको विषयवस्तु पुनःबहाली गर्न सक्छन् र पासवर्डहरूबाहेक यसका सबै पाठको जाँच गर्न सक्छन्।"</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"पहुँचतालाई अस्थायी सक्षम गर्नुहोस्"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"अनुप्रयोगलाई अस्थायी रूपमा उपकरणमाथि पहुँच राख्न अनुमति दिन्छ। खराब अनुप्रयोगले उपयोगकर्ताको सहमति बिना नै पहुँचलाई सक्षम गर्न सक्दछ।"</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"विन्डो जानकारी बहाली गर्नुहोस्"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"अनुप्रयोगलाई विन्डो व्यवस्थापकबाट विन्डोहरूको बारेमा जानकारी प्राप्त गर्न अनुमति दिन्छ। खराब अनुप्रयोगले आन्तरिक प्रणाली उपयोगको लागि निमित्त जानकारी पनि प्राप्त गर्न सक्दछ।"</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"घटनाहरू छान्नुहोस्"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"इन्पुट फिल्टर जुन सबै प्रयोगकर्ता घटनाहरू पठाइनुभन्दा पहिले फिल्टर गर्नेलाई दर्ता गर्न अनुप्रयोगलाई अनुमति दिन्छ। प्रयोगकर्ताको हस्तक्षेप बिना नै UI प्रणाली खराब अनुप्रयोगले नियन्त्रण गर्न सक्छन्।"</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"प्रदर्शन बढाउनुहोस्"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"अनुप्रयोगलाई प्रदर्शनको सामग्री आवर्धन गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले प्रदर्शन सामग्री संक्रमण गर्न सक्दछन् जसले उपकरणलाई अनुपयोगी बनाउँदछ।"</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"आंशिक बन्द"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"गतिविधि व्यवस्थापकलाई बन्द गर्ने अवस्थामा राख्छ। पूर्ण बन्द गर्ने काम गर्दैन।"</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"अनुप्रयोग स्विचहरू जोगाउनुहोस्"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"अन्य अनुप्रयोगमा स्विच गर्नबाट प्रयोगकर्ताहरूलाई रोक्छ।"</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"वर्तमान अनुप्रयोगको जानकारी प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="2512448855496067131">"होल्डरलाई स्क्रिनको पृष्ठभूमिमा वर्तमान अनुप्रयोगको बारेमा व्यक्तिगत जानकारी पुनःप्राप्त गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"सबै अनुप्रयोग सुरुवात गर्ने निरीक्षण र नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"अनुप्रयोगलाई कसरी प्रणाली सुरुवात गतिहरू मोनिटर गर्न र नियन्त्रण गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले प्रणालीमा पूर्ण सहमत गर्न सक्दछ। यो अनुमति केवल विकासको लागि आवश्यक छ, साधारण प्रयोगको लागि कहिले होइन।"</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"प्याकेज हटाइएको प्रसारणलाई पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"अनुप्रयोगलाई सूचना प्रसारण गर्न अनुमति दिन्छ जुन अनुप्रयोग प्याकेज हटाइएको छ। खराब अनु्प्रयोगहरूले यो कुनै अन्य चालु अनु्प्रयोग बन्द गर्न प्रयोग गर्न सक्दछन्।"</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS-प्राप्त प्रसारण पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"त्यो एउटा SMS सन्देशबाट प्राप्त भएको सूचनालाई प्रसारण गर्न अनुप्रयोगलाई अनुमति दिन्छ। आउँदै गरेको SMS सन्देशहरूलाई जालसाजी गर्न सायद खराब भएका अनुप्रयोगहरूले यसलाई प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH-प्राप्त प्रसारण पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"अनुप्रयोगलाई सूचना प्रसारण गर्न अनुमति दिन्छ जुन एउटा WAP PUSH सन्देश प्राप्त भएको छ। खराब अनुप्रयोगहरूले यो MMS सन्देश बिगार्न वा मौन तरिकाले कुनै पनि वेबपृष्ठको सामग्री खराब विभेदहरूसँग बदल्न प्रयोग गर्न सक्दछन्।"</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"चालु प्रशोधनहरूको सङ्ख्या सीमति गर्नुहोस्"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"अनुप्रयोगलाई चालु हुने प्रक्रियाहरूको अधिकतम संख्या नियन्त्रण गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"पृष्ठभूमि अनुप्रयोगहरू बन्द गर्न दबाब दिनुहोस्"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"अनुप्रयोगलाई गतिविधिहरू सधैँ समाप्त भयो कि भएन जब कि जति सक्दो तिनीहरू पृष्ठभूमिमा जान्छन् भन्ने नियन्त्रण गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"ब्याट्रि तथ्याङ्हरू पढ्नुहोस्"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"वर्तमान थोरै ब्याट्री प्रयोग डेटा पढ्नको लागि एक अनुप्रयोगले अनुमति दिन्छ। जुन अनुप्रयोग तपाईँले प्रयोग गरीरहनुभएको छ त्यस्को बारेका पुर्ण जानकारी प्राप्त गर्न सायद अनुप्रयोगले अनुमति दिन्छ।"</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"ब्याट्रि तथ्याङ्कलाई परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"अनुप्रयोगलाई संकलित ब्याट्रि तथ्याङ्कहरू परिमार्जन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"अनुप्रयोग संचालनका तथ्याङ्कहरू पुनःबहाली गर्नुहोस्"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"सङ्कलन गरिएका अनुप्रयोग संचालन तथ्याङ्लाई पुनः प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगबाट प्रयोगको लागि होइन।"</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"अनुप्रयोग संचलान तथ्याङ्कहरूलाई परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"सङ्कलन गरिएका अनुप्रयोग संचालन तथ्याङ्लाई परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगबाट प्रयोगको लागि होइन।"</string>
-    <string name="permlab_backup" msgid="470013022865453920">"प्रणाली ब्यकअप नियन्त्रण गर्नुहोस् र पुनः बहाली गर्नुहोस्"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"प्रणालीको जगेडा नियन्त्रण गर्न र पुनःप्राप्तिको संयोजन गर्न अनुप्रयोगलाई अनुमित दिन्छ। सामान्य अनुप्रयोगद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"पूर्ण जगेडा गर्न वा प्रक्रिया पुनःबहाली गर्न निश्चित गर्नुहोस्"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"UI को पूर्ण जगेडा निश्चिन्तता सुरु गर्नका लागि अनुप्रयोगलाई अनुमति दिन्छ। कुनै अनुप्रयोगबाट प्रयोग नगरिने।"</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"अनधिकृत बिन्डोहरू प्रदर्शन गर्नुहोस्"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"अनुप्रयोगलाई विन्डोहरू सिर्जना गर्न अनुमति दिन्छ जुन आन्तरिक प्रणाली प्रयोगकर्ता इन्टरफेसद्वारा प्रयोग गर्न अभिप्रेरित छ। साधारण अनुप्रयोगहरूद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"अन्य अनुप्रयोगहरूमा चित्र कोर्नुहोस्"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"अरू अनुप्रयोगहरूमाथि वा प्रयोगकर्ता इन्टरफेसका भागहरूमा चित्र कोर्न अनुप्रयोगलाई अनुमति दिन्छ। तिनीहरूले कुनै अनुप्रयोगमा इन्टरफेको तपाईँको प्रयोगसँग हस्तक्षेप गर्न वा तपाईँ अन्य अनुप्रयोगहरूमा के देखिरहनु भएको छ भन्ने सोच्न हुन्छ भन्ने बदल्न सक्छन्।"</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"ग्लोबल सजीविकरण गति परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"विश्वब्यापि सजीविकरण(द्रुत वा ढिला सजीविकरणहरू) लाई कुनै पनि समय परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"अनुप्रयोग टोकनहरू प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"अनुप्रयोगलाई आफ्ना टोकनहरू सिर्जना गर्न र उनीहरूको साधारण Z-क्रमाङ्कन बाइपास गरेर प्रबन्ध गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिल्यै पनि आवश्यक नहुन सक्दछ।"</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"स्क्रिन फ्रिज गर्नुहोस्"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"अनुप्रयोगलाई पूर्ण-स्क्रिन संक्रमणको लागि अस्थायी रूपमा स्क्रिन स्थिर गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"कुञ्जीहरू र नियन्त्रण बटनहरू थिच्नुहोस्"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"यसका आफ्ना इनपुट घटनाहरू (कि थिचाइहरू, आदि) अन्य अनुप्रयोगहरूलाई वितरण गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई ट्याब्लेटसम्म लैजान प्रयोग गर्न सक्छन्।"</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"यस्को आफ्नै निवेश घटनाहरू (कि थिचाइहरू, आदि.) अन्य अनुप्रोयगहरूलाई पु्र्‍याउन अनुप्रयोगलाई अनुमति दिन्छ। फोनलाई हस्तक्षेप गर्न यसको प्रयोग खराब अनुप्रयोगहरूले गर्न सक्छन्।"</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"तपाईंले के टाइप गर्नुहुन्छ र के कार्यहरू लिनुहुन्छ रेकर्ड गर्नुहोस्"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"अर्को अनुप्रयोग(जस्तै पासवर्ड टाइप गराइ)सँग अन्तर्क्रिया गरेको बेला पनि तपाईँले थिचेका किहरूलाइ हेर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिल्यै आवश्यक हुँदैन।"</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"एउटा निवेश तरिकामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"एउटा निवेश तरिकाको उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि समाती राख्नेलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"एउटा पहुँच सेवासँग जोड्नुहोस्"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"एक पहुँच सेवाको उच्च स्तरको कुराकानीलाई पक्का गर्नको लागि समाती राख्नेले अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"एउटा प्रिन्ट सेवासँग जोड्नुहोस्"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"एउटा प्रिन्ट सेवाको उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि प्रयोगकर्तालाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindPrintSpoolerService" msgid="6807762783744125954">"प्रिन्ट स्पुलर सेवासँग बाध्नुहोस्"</string>
-    <string name="permdesc_bindPrintSpoolerService" msgid="3680552285933318372">"प्रिन्ट स्पुलर सेवाको शीर्ष तह इन्टर्फेसलाई बाहकसँग बाँध्न अनुमति दिन्छ। सामान्य अनुप्रयोगलाई कहिल्यै पनि आवाश्यक नपर्न सक्छ।"</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC सेवामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"NFC कार्डहरू इमुलेट गर्ने अनुप्रयोगहरूलाई बाँध्नका लागि होल्डरलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूका लागि कहिल्यै पनि आवश्यक पर्दैन।"</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"एउटा पाठ सेवासँग संगठित हुनुहोस्"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"एउटा पाठ सेवाको (उदाहरण शब्द परीक्षणसेवा) उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि समाती राख्नेलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN सेवासँग बाँध्नुहोस्।"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"एक Vpn सेवाको उच्च स्तरको कुराकानीलाई पक्का गर्नको लागि समाती राख्नेले अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"एउटा वालपेपरमा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"वालपेपरको माथिल्लो स्तरको इन्टरफेसमा बाँध्न धारकलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्दैन।"</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"एउटा विजेट सेवासँग संगठित हुनुहोस्"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"एउटा विजेट सेवाको उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि समाती राख्नेलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"उपकरणको प्रबन्धसँग अन्तरक्रिया गर्नुहोस्"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"उपकरण प्रशासक लाई आशय पठाउन समाती राख्‍नेलाई अनुमति दिन्छ। साधारण अनुप्रयोहरूको लागि कहिल्यै पनी आवश्यक पर्दैन।"</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"एउटा उपकरण व्यवस्थापक थप गर्नुहोस् वा हटाउनुहोस्"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"होल्डरलाई सक्रिय उपकरण व्यवस्थापकहरू थप गर्न वा हटाउन अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिल्यै पनि आवश्यक नहुन सक्दछ।"</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"स्क्रिन अभिमुखिकरण परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"अनुप्रयोगलाई कुनै पनि समयमा स्क्रिनको परिक्रमण परिवर्तन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"सङ्केतक गति बदल्नुहोस्"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"कुनै पनि समयमा माउस परिवर्तन गर्न वा ट्राकप्याड संकेतकको गति बदल्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूको लागि कहिल्यै नचाहिन सक्छ।"</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"किबोर्ड लेआउट परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"किबोर्ड लेआउटलाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई सायद कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"Linux संकेतहरू अनुप्रयोगलाई पठाउनुहोस्"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"सबै चलिरहेका प्रक्रियाहरूमा पठाइएका संकेतलाई अनुरोध गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"अनुप्रयोगहरू जहिले पनि चल्ने बनाउनुहोस्"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"यसको आफ्नै मेमोरीमा दृढ भएकोको अंश बनाउनको लागि अनुप्रयोगलाई अनुमति दिन्छ। ट्याब्लेटलाई ढिलो गराउँदै गरेका अन्य अनुप्रयोगहरूलाई सीमित मात्रामा यसले मेमोरी उपलब्ध गराउन सक्छ।"</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"अनुप्रयोगलाई मेमोरीमा आफैंको निरन्तरको अंश बनाउन अनुमति दिन्छ। यसले फोनलाई ढिला बनाएर अन्य अनुप्रयोगहरूमा मेमोरी SIMित गर्न सक्दछन्।"</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"अनुप्रयोगहरू मेटाउनुहोस्"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"अनुप्रयोगलाई एन्ड्रोइड प्याकेजहरू मेटाउन अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई महत्त्वपूर्ण अनुप्रयोगहरू मेटाउन प्रयोग गर्न सक्दछन्।"</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"अन्य अनुप्रयोगहरूको डेटा मेटाउनुहोस्"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"प्रयगकर्ता डेटा हटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"अन्य अनुप्रयोगहरूको क्यासहरू मेटाउनुहोस्"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"अनुप्रयोगलाई क्यास फाइलहरू मेटाउन अनुमति दिन्छ।"</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"अनुप्रयोग भण्डारण ठाउँको मापन गर्नुहोस्"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"अनुप्रयोगलाई यसको कोड, डेटा, र क्यास आकारहरू पुनःप्राप्त गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"अनुप्रयोगहरू सिधै स्थापना गर्नुहोस्"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"नयाँ स्थापना गर्न वा एन्ड्रोइड प्याकेजहरू अद्यावधिक गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई मनपरी रूपमा शक्तिशाली अनुमतिहरू भएका नयाँ अनुप्रयोगहरू थप्न प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"सबै अनुप्रयोग क्यास डेटा मेटाउनुहोस्"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"अन्य अनुप्रयोगहरूको क्यास डाइरेक्टरीहरूमा फाइलहरू हटाएर ट्याब्लेटको भण्डारण खाली गर्न अनुप्रयोगहरूलाई अनुमति दिन्छ। उनीहरूले आफ्नो डेटा पुनःबहाली गर्न पर्ने हुनाले यसले अन्य अनुप्रयोगहरूलाई स्टार्ट हुन निकै ढिलो गराउन सक्छ।"</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"अनुप्रयोगलाई अन्य अनुप्रयोगहरूको क्यास डाइरेक्टरीमा फाइलहरू मेटाएर फोन भण्डारण खाली गर्न अनुमति दिन्छ। यसले अन्य अनुप्रयोगहरूलाई बढी ढिला सुरु गराउँछ किनकि तिनीहरूले आफ्नो डेटा पुनःप्राप्ति गर्न आवश्यक पर्ने हुन्छ।"</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"अनुप्रयोग स्रोतहरू सार्नुहोस्"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"अनुप्रयोग स्रोतहरू आन्तरिकबाट बाह्य मेडियामा र विपरितमा लैजान अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"संवेनशील लग डेटा पढ्नुहोस्"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"प्रणालीका विभिन्न फाइलहरूबाट पढ्न अनुप्रयोगलाई अनुमति दिन्छ। सम्भाव्य रूपमा व्यक्तिगत र निजी सूचनासहित तपाईँ ट्याब्लेटसँग के गरिरहनु भएको छ भन्ने बारेको साधारण सूचना पत्ता लगाउन यसलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"प्रणालीका विभिन्न फाइलहरूबाट पढ्न अनुप्रयोगलाई अनुमति दिन्छ। सम्भाव्य रूपमा व्यक्तिगत र निजी सूचनासहित तपाईँ फोनसँग के गरिरहनु भएको छ भन्ने बारेको साधारण सूचना पत्ता लगाउन यसलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"पछाडि बजाउनको लागि कुनै मिडिया प्रयोग गर्नुहोस्"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"अनुप्रयोगलाई प्लेब्याक डिकोड गर्न कुनै पनि स्थापित मिडिया डिकोडर प्रयोगको लागि अनुमति दिन्छ।"</string>
-    <string name="permlab_manageCaCertificates" msgid="1678391896786882014">"विश्वसनीय प्रमाणहरू प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageCaCertificates" msgid="4015644047196937014">"अनुप्रयोगलाई CA प्रमाणपत्रहरू विश्वसनीय प्रमाणहरूका रूपमा स्थापना गर्न र हटाउन अनुमति दिन्छ।"</string>
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"diag को स्वामित्वमा रहेको संसाधनहरूमा पढ्नुहोस्/लेख्नुहोस्"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"अनुप्रयोगलाई diag समूहद्वारा स्वामित्व प्राप्त कुनै पनि स्रोतहरूमा पढ्न र लेख्न अनुमति दिन्छ; उदाहरणको लागि, /dev  मा फाइलहरू। यसले सम्भवतः प्रणाली स्थिरता र सुरक्षामा प्रभाव पार्न सक्दछ। यो केवल निर्माता वा संचालकद्वारा हार्डवेयर-निर्दिष्टको लागि प्रयोग हुन सक्दछ।"</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"अनुप्रयोग अंशहरू सक्षम वा अक्षम गर्नुहोस्"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"अन्य अनुप्रयोग सक्षम छ वा छैन भन्ने कुराको परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। महत्त्वपूर्ण फोन सक्षमता खराब अनुप्रोगहरूले असक्षम पार्न प्रयोग गर्न सक्छन्। यो अनुमतिसँगै होसियारी अपनाउनु पर्छ, अनुप्रयोग विषय सूचीमा प्रयोग नहुने, असंगत, अस्थिर अवस्था भएको प्राप्त हुने सम्भावना हुन्छ।"</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"अन्य अनुप्रयोगको अंश सक्षम छ वा छैन भन्नेमा परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। महत्त्वपूर्ण फोन सक्षमता खराब अनुप्रोगहरूले असक्षम पार्न प्रयोग गर्न सक्छन्। यो अनुमतिसँगै होसियारी अपनाउनु पर्छ, अनुप्रयोग विषय सूचीमा प्रयोग नहुने, असंगत, अस्थिर अवस्था भएको प्राप्त हुने सम्भावना हुन्छ।"</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"अनुमतिहरू प्रदान गर्नुहोस् वा रद्द गर्नुहोस्"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"अनुप्रयोगलाई यो वा अन्य अनुप्रयोगहरूको लागि निर्दिष्ट स्वीकृतिहरू प्रदान गर्न वा रद्द गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले यो तपाईंले अनुमति प्रदान नगर्नुभएका सुविधाहरूमा पहुँच गर्न सक्दछन्।"</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"विशेष रूपमा मान्य अनुप्रयोगहरू सेट गर्नुहोस"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"तपाईँको मनपर्ने अनुप्रयोगलाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले चलिरहेका ती अनुप्रयोहरूलाई चुपचाप रूपमा परिवर्तन गर्न सक्छन्, तपाईँबाट निजी डेटा संकलन गर्नको लागि भइरहेको अनुप्रयोगलाई स्पुफ गर्न सक्छन्।"</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"प्रणाली सेटिङहरू परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"प्रणालीका सेटिङ डेटालाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले सायद तपाईँको प्रणालीको कन्फिगरेसनलाई क्षति पुर्‍याउन सक्छन्।"</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"सुरक्षित प्रणाली सेटिङहरू परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"प्रणालीको सुरक्षित सेटिङ डेटा परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूको प्रयोगको लागि होइन्।"</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google सेवा नक्सा परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"अनुप्रयोगलाई Google सेवा नक्साहरू परिमार्जन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूद्वाराको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"स्टार्टअपमा चलाउनुहोस्"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"आनुप्रयोगलाई प्रणाली बुट प्रक्रिया पूर्ण हुने बितिकै आफैलाई सुरु गर्ने अनुमति दिन्छ। यसले ट्याब्लेट सुरु गर्नमा ढिला गर्न सक्दछ र अनुप्रयोगलाई समग्रमा ट्याब्लेट सधैँ चालु गरेर ढिला बनाउँदछ।"</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"अनुप्रयोगलाई प्रणाली बुट गरी सकेपछि जति सक्दो चाँडो आफैंमा सुरु गर्न अनुमति दिन्छ। यसले फोन सुरु गर्नमा ढिला गर्न सक्दछ र अनप्रयोगलाई समग्रमा फोन सधैँ चालु गरेर ढिला बनाउँदछ।"</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"स्टिकि प्रसारण पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"औपचारिक प्रसारणलाई पठाउनको लागि एउटा अनुप्रयोगलाई अनुमति दिन्छ, जुन प्रसारण समाप्त भएपछि बाँकी रहन्छ। अत्याधिक प्रयोगले धेरै मेमोरी प्रयोग गरेको कारणले ट्याब्लेटलाई ढिलो र अस्थिर बनाउन सक्छ।"</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"औपचारिक प्रसारणलाई पठाउनको लागि एक अनुप्रयोगलाई अनुमति दिन्छ, जुन प्रसारण समाप्त भएपछि बाँकी रहन्छ। अत्याधिक प्रयोगले धेरै मेमोरी प्रयोग गरेको कारणले फोनलाई ढिलो र अस्थिर बनाउन सक्छ।"</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"तपाईँका सम्पर्कहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"अनुप्रयोगलाई निर्दिष्ट व्यक्तिगतसँग अन्य तरिकाहरूबाट कल गर्नु भएका, इमेल गर्नु भएका वा अन्तर्क्रिया गर्नुभएका आवृतिसहितको तपाईंको ट्याब्लेटमा भण्डारण गरिएका सम्पर्कहरूको डेटा पढ्न अनुमति दिन्छ। यो अनुमतिले तपाईंको सम्पर्क डेटा बचत गर्न अनुमति दिन्छ, र खराब अनुप्रयोगहरूले तपाईंको जानकारी बिना सम्पर्क डेटा साझेदारी गर्न सक्दछन्।"</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"तपाईँले विशेष व्यक्तिहरूसँग अर्को तरिकाबाट कल गर्नुभएका, इमेल गर्नुभएका वा संचार गर्नुभएका आवृतिसहित तपाईँको फोनमा भण्डारण भएका डेटाको बारेमा पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यो अनुमतिले अनुप्रयोगलाई तपाईँको सम्पर्क डेटा बचत गर्नको लागि अनुमति दिन्छ, र तपाईँको ज्ञान बिना नै खराब अनुप्रयोगहरूले सायद सम्पर्क डेटा साझेदारी गर्न सक्छन्।"</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"तपाईँका सम्पर्कहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"अन्य तरिकाका आवृतिहरूसँग जुन तपाईँले कल, इमेल, वा विशेष सम्पर्क गर्नुभएकासहित तपाईँको ट्याब्लेटमा भण्डारण भएका सम्पर्कहरूको बारेको डेटालाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यस अनुमतिले सम्पर्क डेटालाई मेटाउनको लागि अनुमति दिन्छ।"</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"तपाईँले बारम्बार कल गरेका, इमेल गरेका, वा विशेष सम्पर्कहरूसँग सञ्चार गरेका सहित तपाईँको फोनमा भण्डारण गरेका तपाईँका सम्पर्कहरू परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। यो अनुमतिले अनुप्रयोगलाई सम्पर्क डेटा मेटाउन दिन्छ।"</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"कल लग पढ्नुहोस्"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"अनुप्रयोगलाई तपाईँको ट्याब्लेटको कल लग, आगमन र बहिर्गमन कलहरू बारे डेटा सहितको कल लग पढ्न अनुमति दिन्छ। यस अनुमतिले अनुप्रयोगहरूलाई तपाईँको कल लग डेटाहरूको बचत गर्न अनुमति दिन्छ, र खराब अनुप्रयोगहरूले तपाईँको जानकारी बिना नै यो कल लग डेटालाई अरूसँग साझेदार गर्न सक्छन्।"</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"भित्र आउने र बाहिर जाने कलहरूसहित तपाईँको फनको कल लग पढ्न अनुप्रयोगलाई अनुमति दिन्छ।  यो अनुमतिले अनुप्रयोगहरूलाई तपाईँका कल लग डेटा बचत गर्न दिन्छ र खराब अनुप्रयोगहरूले तपाईँले थाहै नपाई कल लग डेटालाई साझेदारी गर्न सक्छन्।"</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"कल लग लेख्‍नुहोस्"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"आगमन तथा बहर्गमन डेटासहित तपाईँको ट्याब्लेटको कल लगको परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई तपाईँको कल लग परिमार्जन गर्न वा मेटाउन प्रयोग गर्न सक्छन्।"</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"अनुप्रयोगलाई तपाईंको फोनको आउने र बाहिर जाने कलहरूको बारेको डेटा सहित कल लग परिमार्जन गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई तपाईंको कल लग मेटाउन वा परिमार्जन गर्न प्रयोग गर्न सक्दछ।"</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"तपाईँको आफ्नै सम्पर्क कार्ड पढ्नुहोस्"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"अनुप्रयोगलाई तपाईंको उपकरणमा भण्डारण गरिएका व्यक्तिगत प्रोफाइल जानकारी पढ्न अनुमति दिन्छ, जस्तै तपाईंको नाम र सम्पर्क जानकारी। यसको मतलब अनुप्रयोगले तपाईंलाई पहिचान गर्न सक्दछ र तपाईंको प्रोफाइल जानकारी अरूलाई पठाउन सक्दछ।"</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"तपाईँको आफ्नै सम्पर्क कार्ड परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"तपाईँको उपकरणमा भण्डार भएको व्याक्तिगत प्रोफाइल जानकारी, जस्तै तपाईँको नाम वा सम्पर्क जानकारीलाई परिवर्तन गर्न वा थप्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यसको मतलब अन्य अनुप्रयोगले तपाईँलाई चिन्न सक्छन् र सायद अन्यलाई तपाईँको प्रोफाइल जानकारी पठाउन सक्छन्।"</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"तपाईंको सामाजिक स्ट्रिम पढ्नुहोस्"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"तपाईँ र तपाईँका साथीहरूबाट सामाजिक अपडेटलाई पहुँच र सिंक गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। जानकारी साझेदारी गर्दा सावधान रहनुहोस्  -- समाजिक नेटवर्कहरूमा तपाईँ र तपाईँको साथीको  बिचमा भएका संचारलाई पढ्न विश्वासनीयता बेगरै यसले अनुप्रयोगलाई अनुमति दिन्छ। नोट: यो अनुमति बलपूर्वक सबै सामाजिक नेटवर्कहरूमा सायद नगर्न सकिन्छ।"</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"तपाईँको सामाजिक प्रवाहमा लेख्‍नुहोस्"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"अनुप्रयोगलाई तपाईंको साथीहरूबाट सामाजिक अपडेटहरू प्रदर्शन गर्न अनुमति दिन्छ। जानकारी साझेदारी गर्ने बेलामा होशियार रहनुहोस् -- यसले अनुप्रयोगलाई सन्देशहरू निर्माण गर्न अनुमति दिन्छ जुन साथीबाट आएको देखिन्छ। टिप्पणी: यो अनुमति सबै सामाजिक सञ्जालहरूमा लागू नहुन सक्दछ।"</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"गोप्य जानकारी र पात्रो घटनाहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"अनुप्रयोगलाई तपाईंको ट्याब्लेटमा भण्डारण गरिएका ती साथीहरू वा सहयोगीहरू सहितको पात्राका कार्यक्रमहरू पढ्न अनुमति दिन्छ। यसले गोपनीयता वा संवेदनशीलता बिना पनि अनुप्रयोगलाई तपाईंको पात्राका डेटा साझेदारी गर्न वा बचत गर्न अनुमति दिन्छ।"</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"ती साथीहरू वा सहकर्मीहरूसहित सबै पात्रो घटनाहरू तपाईँको ट्याब्लेटमा भण्डारण भएकालाई पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। तपाईँको पात्रो डेटा यसले सायद सेयर गर्न वा सुरक्षित गर्नको लागि विश्वासनियता वा सम्वेदनशीलता बिना नै अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"पात्रो घटनाहरू थप्नुहोस् वा परिमार्जन गर्नुहोस् र मालिकको ज्ञान बिना नै पाहुनाहरूलाई इमेल पठाउनुहोस्"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"ती साथीहरू वा सहकर्मीहरूसहितका घटनाहरू जसलाई तपाईँले आफ्नो ट्याब्लेटमा परिमार्जन गर्न सक्ने अनुमति अनुप्रयोगलाई दिन्छ। यसले अनुप्रयोगलाई सन्देशहरू जुन पात्राको मालिकहरूबाट आएका देखिनेलाई पठाउने वा मालिकहरूको ज्ञान बेगर घटनालाई परिमार्जन गर्ने अनुमित दिन्छ।"</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"ती साथीहरू वा सहकर्मीहरूसहित तपाईँको फोनका घटनाहरू जसलाई थप्न, हटाउन र परिवर्तन गर्न  अनुप्रयोगलाई अनुमति दिन्छ। पात्रो मालिकबाट देखा परेका वा मालिकको ज्ञान बिना परिवर्तन भएका घटनाहरू सन्देश पठाउन यसले अनुप्रयोगलाई अनुमति दिन सक्छ।"</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"परीक्षणको लागि स्थान स्रोतहरू मक गर्नुहोस्"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"परीक्षणको लागि मक स्थान स्रोतहरू सिर्जना गर्नुहोस् वा नयाँ स्थान प्रदायक स्थापना गर्नुहोस्। यसले अनुप्रयोगलाई स्थानमा ओभरराइड गर्दछ र/वा स्थिति अन्य स्थान स्रोतहरू जस्तै GPS वा स्थान प्रदायकबाट फर्काइएका।"</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"अधिक स्थान प्रदायक आदेशहरू पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"थप स्थान प्रदायक कमाण्डहरू सम्म पहुँच पुर्‍याउन अनुप्रयोगले अनुमति दिन्छ। यसले अनुप्रयोगलाई सायद जीपीएसको वा अन्य स्थान सेवाहरूको कार्य सँग हस्तक्षेप गर्नको लागि यसलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"एउटा स्थान प्रदाता स्थापित गर्न अनुमति"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"परीक्षणको लागि मक स्थान स्रोतहरू सिर्जना गर्नुहोस् वा नयाँ स्थान प्रदायक स्थापना गर्नुहोस्। यसले अनुप्रयोगलाई स्थानमा ओभरराइड गर्दछ र/वा स्थिति अन्य स्थान स्रोतहरू जस्तै GPS वा स्थान प्रदायकबाट फर्काइएका।"</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"सटिक स्थान (GPS र नेटवर्क आधारित)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"अनुप्रयोगले विश्वव्यापी स्थान प्रणाली (GPS) वा सेल टावरहरू र वाइ-फाइ जस्ता नेटवर्क स्थान स्रोतहरूको प्रयोग गरेर तपाईँको सही स्थान प्राप्त गर्न अनुमति दिन्छ। यी स्थान सेवाहरू खोल्नु पर्छ र अनुप्रयोगहरूका लागि प्रयोग गर्न तपाईँको उपकरणमा उपलब्ध हुनु पर्छ। अनुप्रयोगहरूले तपाईँ कहाँ हुनु हुन्छ भन्ने निर्धारण गर्न यसलाई प्रयोग गर्न सक्छ र यसले अतिरिक्त ब्याट्रि उर्जा खतप गर्न सक्छ।"</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"अनुमानित स्थान (नेटवर्क-आधारित)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"अनुप्रयोगलाई तपाईँको अनुमानित स्थान प्राप्त गर्न अनुमति दिन्छ। यो स्थान सेल टावर र वाइ-फाइजस्ता नेटवर्क स्थान स्रोतहरूको प्रोग गरी स्थान सेवाहरूबाट उत्पन्न गरिएको हो। अनुप्रयोगले यी स्थान सेवाहरूको उपयोग गर्नको लागि यी सेवाहरू तपाईँको उपकरणमा चालु र उपलब्ध हुनु आवश्यक छ। अनुप्रयोगहरूले अनुमानित रूपमा तपाईँ कहाँ हुनुहुन्छ भन्ने निर्धारण गर्न यसको प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger पहुँच गर्नुहोस्।"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"SurfaceFlinger कम-स्तर सुविधाहरू प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"फ्रेम बफर पढ्नुहोस्"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"अनुप्रयोगलाई फ्रेम बफरको सामग्री पढ्न अनुमति दिन्छ।"</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"वाइफाइ प्रदर्शनहरूलाई विन्यास गर्नुहोस"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"अनुप्रयोगलाई कन्फिगर गर्न र वाइफाइ प्रदर्शनहरूसँग जोड्न अनुमति दिन्छ।"</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"वाइफाइ प्रदर्शनहरू नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"वाइफाइ प्रदर्शनीका तल्लो तह विषेशताहरू नियन्त्रण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"अडियो आउटपुट कैद गर्नुहोस्"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"अनुप्रयोगलाई अडियो आउटपुट कैद गर्न र रिडाइरेक्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"भिडियो आउटपुट कैद गर्नुहोस्"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"अनुप्रयोगलाई भिडियो आउटपुट कैद गर्न र रिडाइरेक्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"सुरक्षित भिडियो आउटपुट कैद गर्नुहोस्"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"अनुप्रयोगलाई सुरक्षित भिडियो आउटपुट कैद गर्न र रिडाइरेक्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"तपाईँका अडियो सेटिङहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"अनुप्रयोगलाई ग्लोबल अडियो सेटिङ्हरू परिमार्जन गर्न अनुमति दिन्छ, जस्तै आवाजको मात्रा र आउटपुटको लागि कुन स्पिकर प्रयोग गर्ने।"</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"अडियो रेकर्ड गर्नुहोस्"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"अनुप्रयोगलाई माइक्रोफोनको साथ अडियो रेकर्ड गर्न अनुमति दिन्छ। यस अनुमतिले तपाईंको पुष्टिकरण बिना कुनै पनि समयमा अडियो रेकर्ड गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"तस्बिरहरू र भिडियोहरू लिनुहोस्।"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"अनुप्रयोगलाई क्यामेरासँग तस्बिर र भिडियोहरू लिन अनुमति दिन्छ। यस अनुमतिले अनुप्रयोगलाई तपाईंको पुष्टिकरण बिना कुनै पनि समयमा क्यामेरा प्रयोग गर्न स्वीकृति दिन्छ।"</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"क्यामेरा प्रयोगमा हुँदा सूचक LED प्रसारण असक्षम गर्नुहोस्"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"पूर्व-स्थापित प्रणाली अनुप्रयोगलाई क्यामेरा उपयोग सूचक LED अक्षम गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"स्थायी रूपमा ट्याब्लेट अक्षम पार्नुहोस्"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"फोनलाई स्थायी रूपमा असक्षम पार्नहोस्"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"पुरै ट्याब्लेटलाई स्थायी रूपमा असक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ। यो निकै खतरनाक हुन्छ।"</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"सम्पूर्ण फोनलाई स्थायी रूपमा असक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ। यो धेरै खतरनाक हुन्छ।"</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ट्याब्लेट पुनःबुट गर्न जोड गर्नुहोस्"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"फोन पुनःबुट गर्नु जोड गर्नुहोस्"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"ट्याब्लेटलाई बलपूर्वक पुनःबुट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"फोनलाई बलपुर्वक पुनःबुट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB भण्डारण फाइल प्रणाली पहुँच गर्नुहोस्"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD कार्ड फाइल प्रणाली पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"हटाउन मिल्ने भण्डारणको लागि फाइल प्रणालीहरू माउन्ट र अनमाउन्ट गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB भण्डारण मेट्नुहोस्"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD कार्ड मेटाउनुहोस्"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"हटाउन मिल्ने भण्डारण फर्म्याट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"आन्तरिक भण्डारणको सूचना प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"आन्तरिक भण्डारणमा सूचना प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"आन्तरिक भण्डारण सिर्जना गर्नुहोस्"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"आन्तरिक भण्डारण सिर्जना गर्नको लागि अनुप्रयोगले अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"आन्तरिक भण्डारण ध्वस्त पार्नुहोस्"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"अनुप्रयोगलाई आन्तरिक भण्डारण ध्वस्त पार्न अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"आन्तरिक भण्डारणलाई माउन्ट/अनमाउन्ट गर्नुहोस्"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"अनुप्रयोगलाई आन्तरिक भण्डारण माउन्ट/अनमाउन्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"आन्तरिक भण्डारणको पुन:नामाकरण गर्नुहोस्"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"आन्तरीक भण्डारणको पुननामाकरण गर्नको लागि अनुप्रयोगले अनुमति दिन्छ।"</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_manageUsb" msgid="1113453430645402723">"USB उपकरणहरूको लागि प्राथमिकताहरू र अनुमतिहरू प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"USB उपकरणहरूको लागि प्राथमिकताहरू र अनुमतिहरूलाई व्यवस्थापन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP प्रोटोकल कार्यान्वयन गर्नुहोस्"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"MTP USB प्रोटोकल कार्यान्वयन गर्न केर्नल MTP ड्राइभरको पहुँचको अनुमति दिन्छ।"</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"हार्डवेयर परीक्षण गर्नुहोस्"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"हार्डवेयर परीक्षणको उद्देश्यका लागि विभिन्न परिधीयहरूलाई नियन्त्रण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"फोन नम्बरहरूमा सिधै कल गर्नुहोस्"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"तपाईँको हस्तक्षेप बेगरै फोन नम्बर कल गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले अनपेक्षित शुल्क वा कलहरू गराउन सक्छ। यसले अनुप्रयोगलाई आपतकालीन नम्बरहरू कल गर्न अनुमति दिँदैन विचार गर्नुहोस्। खराब अनुप्रयोगहरूले तपाईँको स्वीकार बिना कलहरू गरेर तपाईँलाई बढी पैसा तिराउन सक्छ।"</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"कुनै पनि फोन नम्बरहरू सिधै कल गर्नुहोस्"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"कुनै पनि फोन नम्बरमा, आकस्मिक नम्बर सहित, तपाईँको हस्तक्षेप बिना कल गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले अनावश्यक र गैर कानुनी कलहरूलाई आकस्मिकमा स्थानान्तरण गर्न सक्छन्।"</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA ट्याब्लेट सेटअफ सिधै सुरु गर्नुहोस्"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA फोन सेटअप सिधै सुरु गर्नुहोस्"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"अनुप्रयोगलाई CDMA प्रावधान सुरu गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले अनावश्यक रूपमा CDMA प्रावधान सुरु गर्न सक्छन्।"</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"स्थान अपडेट सूचनाहरू नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"रेडियोबाट स्थान अद्यावधिक सूचनाहरूलाई सक्षम/असक्षम गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूबाट प्रयोग नहुने।"</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"परीक्षण विशेषताहरू पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"परीक्षण सेवाद्वारा विशेषता अपलोड भएको पहुँच पढ्न/लेख्‍न अनुप्रयोगलाई अनुमति दिन्छ। साधारण अनुप्रयोगद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"विजेटहरूको चयन गर्नुहोस्"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"अनुप्रयोगलाई प्रणालीलाई कुन विजेट कुन अनुप्रयोगद्वारा प्रयोग गर्न सकिन्छ भनेर अनुमति दिन्छ। यस अनुमतिसहितको अनुप्रयोगले अन्य अनुप्रयोगहरूलाई व्यक्तिगत डेटाको पहुँच दिन सक्दछ। सामान्य अनुप्रयोगहरूको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"फोनको स्थिति परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"उपकरणका फोन विशेषताहरूलाई नियन्त्रण गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।  यस अनुमतिले एउटा अनुप्रयोगले नेटवर्क स्विच गर्न, फोन रेडियो बन्द गर्न र खोल्न र जस्तै तपाईँ सधै सूचित नगरी गर्न सक्छ।"</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"फोन स्थिति र पहिचान पढ्नुहोस्"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"उपकरणको फोन विशेषताहरूको पहुँच गर्न अनुप्रयोगलाई अनुमति दिन्छ। यस अनुमतिले फोन नम्बर र उपकरणको IDs, कल सक्षम छ कि छैन र कलद्वारा जोडिएको टाढाको नम्बर निर्धारण गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"ट्याब्लेटलाई निन्द्रामा जानबाट रोक्नुहोस्"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"फोनलाई निदाउनबाट रोक्नुहोस्"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"ट्याब्लेटलाई निस्क्रिय हुनबाट रोक्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"फोनलाई निस्क्रिय हुनबाट रोक्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"ट्याब्लेट पावर खोल्न र बन्द गर्नुहोस्"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"फोन खोल्न वा बन्द गर्न उर्जा प्रदान गर्नुहोस"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"ट्याब्लेटलाई खोल्न र बन्द गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"अनुप्रयोगलाई फोन खोल्न र बन्द गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"फ्याक्ट्रि परीक्षण मोडमा चालु गर्नुहोस्"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"ट्याब्लेट हार्डवेयरलाई पुरा पहुँच गर्न दिँदै तल्लो स्तर उत्त्पादक परीक्षणको रूपमा चलाउनुहोस्। ट्याब्लेट उत्त्पादक परीक्षण मोडमा चलिरहेको बेला मात्र उपलब्ध हुन्छ।"</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"तल्लो स्तर उत्त्पादक जस्तै चलाउनुहोस्, पुरा पहुँच दिन फोन हार्डवेयरलाई अनुमति हुन्छ। फोन उत्पादक परीक्षण मोडमा चलिरहेको बेला मात्र उपलब्ध हुन्छ।"</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"वालपेपर सेट गर्नुहोस्"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"अनुप्रयोगलाई प्रणाली वालपेपर सेट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"तपाईंको वालपेपर आकार समायोजन गर्नुहोस्"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"प्रणाली वालपेपरको आकार सङ्केतहरू मिलाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"कार्यशाला पूर्वनिर्धारणको लागि प्रणाली पुनःसेट गर्नुहोस्"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"यसका फ्याक्ट्रि सेटिङहरू, कन्फिगरेसन र स्थापित अनुप्रयोगहरूलाई प्रणालीमा पुरै पुनःसेट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"समय सेट गर्नुहोस्"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"ट्याब्लेटको घडीको समय बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"फोनको घडीको समय बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"समय क्षेत्र सेट गर्नुहोस्"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"अनुप्रयोगलाई ट्याब्लेटको समय क्षेत्र परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"अनुप्रयोगलाई फोनको समय क्षेत्र परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService को रूपमा कार्य गर्नुहोस्"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"खाता अधिकारीहरूलाई कल गर्नको लागि अनुप्रयोगले अनुमति दिन्छ।"</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"उपकरणमा खाताहरू भेट्टाउनुहोस्"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"अनुप्रयोगलाई ट्याब्लेटद्वारा ज्ञात खाताहरूको सूची पाउन अनुमति दिन्छ। यसले अनुप्रयोगद्वारा तपाईंले स्थापित गर्नुभएको कुनै पनि खाताहरू समावेश गर्न सक्दछ।"</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"फोनलाई थाहा भएका खाताहरूको सूची प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले तपाईँले स्थापना गर्नु भएका अनुप्रयोगहरूबाट सृजित कुनै खाताहरू समावेश हुन सक्छ।"</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"खाता सिर्जना गर्नुहोस् र पासवर्ड सेट गर्नुहोस्"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"खाताहरूको सिर्जना गर्ने र प्राप्त गर्ने र उनीहरूको पासवर्डहरूको सेटिङ गर्ने सहित खाता प्रबन्धकको खाता आधिकारी सक्षमताहरू प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"खाताहरू थप्नुहोस् वा हटाउनुहोस्"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"खाताहरू थप्ने र हटाउने जस्ता प्रक्रियाहरू सम्पन्न गर्न, र उनीहरूको पासवर्ड मेटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"उपकरणमा खाताहरूको प्रयोग गर्नुहोस्"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"अनुप्रयोगलाई प्रमाणीकरण टोकनहरू अनुरोध गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"नेटवर्क जडानहरू हेर्नहोस्"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"अनुप्रयोगलाई नेटवर्क जडानहरू जस्तै कुन नेटवर्कहरू अवस्थित हुन्छन् र जडित छन् जसले हेर्नलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"पूर्ण नेटवर्क पहुँच"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"नेटवर्क सकेटहरू सिर्जना गर्न र कस्टम नेटवर्क प्रोटोकल प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ। ब्राउजर र अन्य अनुप्रयोगहरूले इन्टरनेटमा डेटा पठाउने माध्यम प्रदान गर्छन्, त्यसैले इन्टरनेटमा डेटा पठाउन यो अनुमतिको आवश्यकता पर्दैन।"</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"नेटवर्क सेटिङहरू र ट्राफिक परिवर्तन गर्नुहोस् / रोक्नुहोस्"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"अनुप्रयोगलाई नेटवर्क सेटिङहरू परिवर्तन गर्न र सबै नेटवर्क ट्राफिक रोक्न र परीक्षण गर्न अनुमति दिन्छ, उदाहरणको लागि कुनै पनि APN को प्रोक्सी र पोर्ट परिवर्तन गर्न। खराब अनुप्रयोगहरूले तपाईंको ज्ञान बिना नेटवर्क प्याकेटहरू मोनिटर गर्न, पुन:निर्देशित गर्न, वा परिमार्जन गर्न सक्दछ।"</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"नेटवर्क जडान परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"अनुप्रयोगलाई नेटवर्क जडानको स्थिति परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"टेथर्ड नेटवर्क जडान परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"टिथर गरेको नेटवर्क जडानको स्थिति बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"पृष्ठभूमि डेटा प्रयोग सेटिङहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"अनुप्रयोगलाई पृष्ठभूमि डेटा उपयोग सेटिङ परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"वाइ-फाइ जडानहरू हेर्नुहोस्"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"अनुप्रयोगलाई वाइ-फाइ नेटवर्कको बारेमा जानकारी हेर्न अनुमति दिन्छ, जस्तै कि वाइ-फाइ सक्षम छ कि छैन र जडान गरिएको वाइ-फाइ उपकरणहरूको नाम।"</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"वाइ-फाइसँग जोड्नुहोस् वा छुटाउनुहोस्"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"अनुप्रयोगलाई वाइ-फाइ पहुँच बिन्दुबाट जडान गर्न र विच्छेदन गर्न र वाइ-फाइ नेटवर्कहरूको लागि उपकरण कन्फिगरेसनमा परिवर्तनहरू गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"वाइ-फाइ Multicast स्विकृतिलाई अनुमति दिनुहोस्"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"अनुप्रयोगलाई मल्टिकाष्ट ठेगानाहरू प्रयोग गरेर वाइ-फाइ नेटवर्कमा पठाइएको प्याकेटहरू प्राप्त गर्न अनुमति दिन्छ, केवल तपाईंको ट्याब्लेट मात्र होइन। यसले गैर-मल्टिकाष्ट मोड भन्दा बढी उर्जा प्रयोग गर्दछ।"</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"तपाईँको फोन मात्र होइन, मल्टिकास्ट ठेगानाहरूको प्रयोग गरे वाइ-फाइ नेटवर्कका सबै उपकरणहरूमा पठाइएका प्याकेटहरू प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले गैर-मल्टिकास्ट मोडभन्दा बढी उर्जा प्रयोग गर्छ।"</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"ब्लुटुथ सेटिङहरूमा पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"स्थानीय ब्लुटुथ ट्याब्लेटलाई कन्फिगर गर्नको लागि र टाढाका उपकरणहरूलाई पत्ता लगाउन र जोड्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"अनुप्रयोगलाई स्थानीय ब्लुटुथ फोन कन्फिगर गर्न र टाढाका उपकरणहरूसँग खोज गर्न र जोडी गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAXसँग जोड्नुहोस् वा छुटाउनुहोस्"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"अनुप्रयोगलाई वाइम्याक्स सक्षम छ कि छैन र जडान भएको कुनै पनि वाइम्याक्स नेटवर्कहरूको बारेमा जानकारी निर्धारिण गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"वाइम्याक्स स्थिति परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"अनुप्रयोगलाई वाइम्याक्स नेटवर्कहरूबाट ट्याब्लेट जडान गर्न र ट्याब्लेट विच्छेदन गर्न अनुमति दिन्छ।"</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"वाइम्याक्स नेटवर्कहरूसँग फोन जोड्न र छुटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"ब्लुटुथ उपकरणहरूसँग जोडी मिलाउनुहोस्"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"ट्याब्लेटमा ब्लुटुथको कन्फिगुरेसनलाई हेर्न र बनाउन र जोडी उपकरणहरूसँग जडानहरूलाई स्वीकार गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"अनुप्रयोगलाई फोनमा ब्लुटुथको कन्फिगरेसन हेर्न र जोडी भएका उपकरणहरूसँग जडानहरू बनाउन र स्वीकार गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"नजिक क्षेत्र संचार नियन्त्रणहरू"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"अनुप्रयोगलाई नयाँ क्षेत्र संचार (NFC) ट्यागहरू, कार्डहरू र पाठकहरूसँग अन्तर्क्रिया गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"स्क्रिन लक असक्षम पार्नुहोस्"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"कुनै सम्बन्धित पासवर्ड सुरक्षा र किलकलाई असक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ। उदाहरणको लागि, अन्तर्गमन फोन कल प्राप्त गर्दा फोनले किलकलाई असक्षम पार्छ, त्यसपछि कल सकिएको बेला किलक पुनःसक्षम पार्छ।"</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"समीकरण सेटिङहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"अनुप्रयोगलाई खाताको लागि सिङ्क सेटिङहरू पढ्न अनुमति दिन्छ। उदाहरणको लागि यसले व्यक्तिहरको अनुप्रयोग खातासँग सिङ्क भएको नभएको निर्धारण गर्न सक्दछ।"</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"टगल सिङ्क खुला र बन्द"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"अनुप्रयोगहरूलाई खाताको लागि सिङ्क सेटिङहरू परिमार्जन गर्न अनुमति दिन्छ। उदाहरणको लागि, यो खातासँग व्यक्ति अनुप्रयोगको सिङ्क सक्षम गर्न प्रयोग गर्न सकिन्छ।"</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"सिङ्क तथ्याङ्कहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"अनुप्रयोगलाई खाताको लागि समीकरणको आँकडा समीकरण घटनाहरूको  इतिहास र समीकरण गरिएको डेटाको मापन समेत, पढ्न अनुमति दिन्छ।"</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"सदस्य बनाइका फिडहरू पढ्नुहोस्"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"अनुप्रयोगलाई अहिलेको समीकरण गरिएका सूचकहरू बारे विवरणहरू लिने अनुमति दिन्छ।"</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"सदस्य बनाइका फिडहरू लेख्नुहोस्"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"तपाईँका भर्खरै सिङ्क फिडहरूलाई परिमार्जन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। तपाईँको सिङ्क फिडहरूलाई परिवर्तन गर्नको लागि यसले  खराब अनुप्रयोगलाई अनुमति दिन सक्छ।"</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"तपाईँले शब्दकोशमा थपेका शब्दहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"अनुप्रयोगलाई प्रयोगकर्ताले प्रयोगकर्ता शब्दकोशमा भण्डारण गरेका हुन सक्ने सबै शब्दहरू, नामहरू र पदावलीहरू पढ्न अनुमति दिन्छ।"</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"प्रयोगकर्ता-परिभाषित शब्दकोशमा शब्दहरू थप्नुहोस्।"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"प्रयोगकर्ता शब्दकोशमा नयाँ शब्द लेख्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"सुरक्षित गरिएका भण्डारण पहुँचको परीक्षण गर्नुहोस्"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"सुरक्षित गरिएका भण्डारण पहुँचको परीक्षण गर्नुहोस्"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"भविष्य उपकरणहरूमा उपलब्ध हुने USB भण्डारणको लागि अनुमति परीक्षण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"भविष्य उपकरणहरूमा उपलब्ध हुने SD कार्डको लागि अनुमति परीक्षण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"तपाईँको USB भण्डारणको विषयवस्तुहरूलाई परिमार्जन गर्नुहोस् वा मेटाउनुहोस्"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"तपाईँको SD कार्डको विषयसूची परिमार्जन गर्नुहोस् वा मेट्नुहोस्"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"USB भण्डारणमा लेख्‍नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"अनुप्रयोगलाई SD कार्डमा लेख्न अनुमति दिन्छ।"</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"आन्तरिक मिडिया भण्डारण सामग्रीहरू परिमार्जन गर्नुहोस्/मेटाउनुहोस्"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"अनुप्रयोगलाई आन्तरिक मिडिया भण्डारणको सामग्रीहरू परिमार्जन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"कागजात भण्डारण प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"अनुप्रयोगलाई कागजात भण्डारण समायोजन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"सबै उपयोगकर्ताहरूको बाह्य भण्डारणको पहुँच राख्नुहोस्"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"अनुप्रयोगलाई सबै उपयोगकर्ताहरूको लागि बाह्य भण्डारणमाथि पहुँच राख्न अनुमति दिन्छ।"</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"क्यास फाइल प्रणाली पहुँच गर्नुहोस्।"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"केस फाइल प्रणालीलाई पढ्न र लेख्‍नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"इन्टरनेट कलहरू गर्नुहोस् वा प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"इन्टरनेट कल गर्न/प्राप्त गर्न SIP सेवालाई प्रयोग गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"नेटवर्क उपयोगको इतिहास पढ्नुहोस्"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"निश्चित नेटवर्कहरू र अनुप्रयोगहरूको लागि ऐतिहासिक नेटवर्क उपयोग पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"नेटवर्क नीति प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"नेटवर्क नीतिहरू व्यवस्थापन गर्न र अनुप्रयोग-विशेष नियमहरू परिभाषित गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"नेटवर्क उपयोग लेखालाई परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"अनुप्रयोगलाई कसरी अनुप्रयोगहरूको विरूद्धमा कसरी नेटवर्क उपयोगी अकाउन्टेड छ भनेर परिमार्जन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"सकेटको निशानहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"मार्ग दर्शनको लागि अनुप्रयोगलाई सकेटको निशानहरू परिवर्तन गर्न अनुमति दिन्छ"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"सूचनाहरू पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"अन्य अनुप्रयोगहरूबाट पोस्ट गरिएकासहित पुनःप्राप्त गर्न, परीक्षण गर्न र सूचनाहरू हटाउन अनुप्रयोगहरूलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"जानकारी श्रोता सेवामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"होल्डरलाई सूचना श्रोता सेवाको शीर्ष-स्तरको इन्टरफेस बाँध्न अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"वाहक-प्रदान विन्यास अनुप्रयोग सुरु गर्नुहोस्"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"प्रयोगकर्तालाई वाहक-प्रदान विन्यास अनुप्रयोग सुरु गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"सञ्जाल अवस्थाका पर्यवेक्षणका लागि सुन्नुहोस्"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"सञ्जाल अवस्थाका पर्यवेक्षण सुन्नका लागि अनुप्रयोगलाई अनुमति दिन्छ।सामान्य अनुप्रयोगलाई चाँहिदै नचाँहिन सक्छ।"</string>
-    <string name="permlab_hotwordRecognition" msgid="3225080408746361313">"जल्दोबल्दो शब्द पहिचानका लागि अनुरोध गर्नुहोस्"</string>
-    <string name="permdesc_hotwordRecognition" msgid="3716741260195364252">"जल्दाबल्दा शब्द पहिचानका लागि अनुरोध पठाउन अनुप्रयोगलाई अनुमति दिन्छ।सामान्य अनुप्रयोगका लागि यो कहिल्यै नचाहिन सक्छ।"</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"पासवर्ड नियमहरू मिलाउनुहोस्"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"स्क्रिन-अनलक पासवर्डहरूमा अनुमति दिइएको लम्बाइ र अक्षरहरू नियन्त्रण गर्नुहोस्।"</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"मोनिटर स्क्रिन-अनलक प्रयत्नहरू"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"स्क्रिन अनलक गर्दा गलत पासवर्ड टाइप भएको संख्या निरीक्षण गर्नुहोस् र यदि निकै धेरै गलत पासवर्डहरू टाइप भएका छन भने ट्याब्लेट लक गर्नुहोस् वा ट्याब्लेटका सबै डेटा मेट्नुहोस्।"</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"स्क्रिनअनलक गर्दा गलत पासवर्ड टाइप भएको संख्या निरीक्षण गर्नुहोस् र यदि निकै धेरै गलत पासवर्डहरू टाइप भएका छन भने फोन लक गर्नुहोस् वा फोनका सबै डेटा मेट्नुहोस्।"</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"स्क्रिन-अनलक पासवर्ड बदल्नुहोस्"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"स्क्रिन-अनलक पासवर्ड परिवर्तन गर्नुहोस्।"</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"स्क्रिन लक गर्नुहोस्।"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"कसरी र कहिले स्क्रिन लक गर्ने नियन्त्रण गर्नुहोस्।"</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"सबै डेटा मेट्नुहोस्"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"एउटा फ्याक्ट्रि डेटा पुनःसेट गरेर चेतावनी नआउँदै ट्याबल्टको डेटा मेट्नुहोस्।"</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"एउटा फ्याक्ट्रि डेटा पुनःसेट गरेर चेतावनी नआउँदै फोनको डेटा मेट्नुहोस्।"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"उपकरण विश्वव्यापी प्रोक्सी मिलाउनुहोस्"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"नीति सक्षम हुँदा प्रयोग हुने उपकरण  विश्वव्यापी प्रोक्सी सेट गर्नुहोस्। प्रथम उपकरण प्रशासशनले मात्र प्रभावकारी विश्वव्यापी प्रोक्सी सेट गर्छ।"</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"लक-स्क्रिन पासवर्ड अन्त सेट गर्नुहोस्"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"प्रायः कति छिटो लक-स्क्रिन पासवर्ड बदल्नु पर्छ यसलाई नियन्त्रण गर्नुहोस्।"</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"भण्डारण इन्क्रिप्सन मिलाउनुहोस्"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"भण्डार गरिएको डेटा इन्क्रिप्ट हुनु आवश्यक छ।"</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"क्यामेरालाई असक्षम गराउनुहोस्"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"सबै उपकरण क्यामराहरूको प्रयोग रोक्नुहोस्"</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"किगार्डमा भएका विशेषताहरू असक्षम पार्नुहोस्"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"केही किगार्ड विशेषताहरूको प्रयोग रोक्नुहोस्।"</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"गृह"</item>
-    <item msgid="869923650527136615">"मोबाइल"</item>
-    <item msgid="7897544654242874543">"काम गर्नुहोस्"</item>
-    <item msgid="1103601433382158155">"कार्य फ्याक्स"</item>
-    <item msgid="1735177144948329370">"घरको फ्याक्स"</item>
-    <item msgid="603878674477207394">"पेजर"</item>
-    <item msgid="1650824275177931637">"अन्य"</item>
-    <item msgid="9192514806975898961">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"गृह"</item>
-    <item msgid="7084237356602625604">"काम"</item>
-    <item msgid="1112044410659011023">"अन्य"</item>
-    <item msgid="2374913952870110618">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"गृह"</item>
-    <item msgid="5629153956045109251">"काम"</item>
-    <item msgid="4966604264500343469">"अन्य"</item>
-    <item msgid="4932682847595299369">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"गृह"</item>
-    <item msgid="1359644565647383708">"काम"</item>
-    <item msgid="7868549401053615677">"अन्य"</item>
-    <item msgid="3145118944639869809">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"काम गर्नुहोस्"</item>
-    <item msgid="4378074129049520373">"अन्य"</item>
-    <item msgid="3455047468583965104">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"स्काइप"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"अनुकूलन"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"गृह"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"मोबाइल"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"काम"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"कार्य फ्याक्स"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"घरको फ्याक्स"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"पेजर"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"अन्य"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"कलब्याक"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"कार"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"कम्पनी मुख्य"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"मुख्य"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"अन्य फ्याक्स"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"रेडियो"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"टेलेक्स"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"कार्य मोबाइल"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"कार्य पेजर"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"सहायक"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"अनुकूलन"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"जन्मदिन"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"वार्षिक समारोह"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"अन्य"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"अनुकूलन"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"गृह"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"काम"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"अन्य"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"मोबाइल"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"अनुकूलन"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"गृह"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"काम"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"अन्य"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"अनुकूलन"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"गृह"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"काम"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"अन्य"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"अनुकूलन"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"स्काइप"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"ह्याङआउटहरू"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"काम"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"अन्य"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"अनुकूलन"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"अनुकूलन"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"सहायक"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"भाइ"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"बच्चो"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"आन्तरिक साझेदार"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"बुबा"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"मित्र"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"ब्यवस्थापक"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"आमा"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"अभिभावक"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"पार्टनर"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"द्वारा उल्लिखित"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"आफन्त"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"बहिनी"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"पति-पत्नि"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"अनुकूलन"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"गृह"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"काम गर्नुहोस्"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"अन्य"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PIN कोड टाइप गर्नुहोस्"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK र नयाँ PIN कोड टाइप गर्नुहोस्"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK कोड"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"नयाँ PIN कोड"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"पासवर्ड टाइप गर्न छुनुहोस्"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"अनलक गर्न पासवर्ड टाइप गर्नुहोस्।"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"अनलक गर्न PIN कोड टाइप गर्नुहोस्"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"गलत PIN कोड।"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"अनलक गर्न मेनु थिच्नुहोस् र त्यसपछि ० थिच्नुहोस्।"</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"आपतकालीन नम्बर"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"सेवा छैन।"</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"स्क्रिन लक गरिएको।"</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"अनलक वा आपतकालीन कल गर्न मेनु थिच्नुहोस्।"</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"अनलक गर्न मेनु थिच्नुहोस्।"</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"अनलक गर्नु ढाँचा खिच्नुहोस्"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"आपतकालीन कलहरू"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"कलमा फर्किनुहोस्"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"सही!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"फेरि प्रयास गर्नुहोस्"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"फेरि प्रयास गर्नुहोस्"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"अत्याधिक मोहडा खोल्ने प्रयासहरू बढी भए।"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"चार्ज हुँदै, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"चार्ज भयो"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"तपाईँको चार्जर जोड्नुहोस्।"</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM कार्ड छैन"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"ट्याब्लेटमा SIM कार्ड छैन।"</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"फोनमा SIM कार्ड छैन।"</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SIM कार्ड घुसाउनुहोस्"</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM कार्ड छैन वा पढ्न मिल्दैन। SIM कार्ड हाल्नुहोस्।"</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"प्रयोग गर्न अयोग्य SIM कार्ड"</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"तपाईंको SIM कार्ड स्थायी रूपमा अक्षम भयो।\n अर्को SIM कार्डको लागि आफनो ताररहित सेवा प्रदायकसँग सम्पर्क गर्नुहोस्।"</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"अघिल्लो ट्रयाक बटन"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"अर्को ट्रयाक बटन"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"रोक्ने बटन"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"बजाउने बटन"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"बटन रोक्नुहोस्"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"आपतकालीन कलहरू मात्र"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"नेटवर्क लक छ"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM कार्ड PUK-लक गरिएको छ।"</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"प्रयोगकर्ता निर्देशक वा ग्राहक सेवा सम्पर्क हर्नुहोस्।"</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM कार्ड लक गरिएको छ।"</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM कार्ड अनलक गरिँदै..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"तपाईँले तपाईँको अनलक ढाँचा गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक खिच्नु भएको छ। \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि कोसिस गर्नुहोस्।"</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"तपाईंले गलत तरिकाले आफ्नो पासवर्ड <xliff:g id="NUMBER_0">%d</xliff:g> पटक टाइप गर्नुभयो। \n\n<xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"तपाईँले गलत तरिकाले तपाईँको PIN <xliff:g id="NUMBER_0">%d</xliff:g> पटक टाइप गर्नु भएको छ। \n\n<xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"तपाईँले तपाईँको अनलक ढाँचा गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक खिच्नु भएको छ। पछि <xliff:g id="NUMBER_1">%d</xliff:g> थप असफल कोसिसहरू, तपाईँको Google साइन इन प्रयोग गरी तपाईँको ट्याब्लेट अनलक गर्न भनिने छ।\n\n  <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डमा फरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"तपाईँले <xliff:g id="NUMBER_0">%d</xliff:g> पटक गलत तरिकाले तपाईँको अनलक ढाँचालाई कोर्नु भएको छ। पछि <xliff:g id="NUMBER_1">%d</xliff:g> अरू धेरै असफल कोसिसहरूपछि, तपाईँलाई तपाईँको फोन Google साइन इन प्रयोग गरेर अनलक गर्नको लागि सोधिने छ। \n\n <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डमा पुनः प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"तपाईँले <xliff:g id="NUMBER_0">%d</xliff:g> पटक ट्याब्लेटलाई अनलक गर्नको लागि गलत तरिकाले कोशिस गर्नुभएको छ। <xliff:g id="NUMBER_1">%d</xliff:g> अरू धेरै असफल कोसिसहरूपछि, ट्याब्लेट फ्याट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ र सबै प्रयोगकर्ता डेटा हराउने छन्।"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"तपाईंले गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक फोन अनलक गर्ने प्रयत्न गर्नुभयो। <xliff:g id="NUMBER_1">%d</xliff:g> बढी असफल प्रयत्नहरू पछि, फोन फ्याक्ट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ र सबै प्रयोगकर्ता डेटा हराउने छन्।"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"तपाईँले ट्यब्लेटलाई अनलक गर्न गलत तरिकाले <xliff:g id="NUMBER">%d</xliff:g> पटक प्रयास गर्नु भएको छ। अब ट्याब्लेटलाई पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ।"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"तपाईंले गलत तरिकाले फोन <xliff:g id="NUMBER">%d</xliff:g> पटक अनलक गर्ने प्रयत्न गर्नुभयो। अब फोन फ्याक्ट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ।"</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"<xliff:g id="NUMBER">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"ढाँचा बिर्सनु भयो?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"खाता अनलक"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"निकै धेरै कोसिसहरू"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"अनलक गर्नको लागि, तपाईँको Google खातासँग साइन इन गर्नुहोस्।"</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"प्रयोगकर्तानाम (इमेल)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"पासवर्ड:"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"साइन इन गर्नुहोस्"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"अमान्य प्रयोगकर्तानाम वा पासवर्ड"</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"तपाईँको प्रयोगकर्ता नाम वा पासवर्ड बिर्सनुभयो?\n भ्रमण गर्नुहोस"<b>"google.com/accounts/recovery"</b></string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"जाँच गर्दै..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"खोल्नुहोस्"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"आवाज चालु छ।"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"ध्वनि बन्द"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"ढाँचा सुरु भयो"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"ढाँचा हटाइएको"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"सेल थप गरियो"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"ढाँचा पुरा भयो"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. विजेट %2$d of %3$d।"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"विजेट थप गर्नुहोस्।"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"खाली"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"अनलक क्षेत्र विस्तार भयो।"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"अनलक क्षेत्र भत्कियो।"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> विजेट।"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"प्रयोगकर्ता छनौटकर्ता"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"स्थिति"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"क्यामेरा"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"मिडिया नियन्त्रणहरू"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"विजेट पुनःक्रम गर्ने सुरु भयो।"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"विजेट पुनःक्रम समाप्त भएको छ।"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"विजेट <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> मेटाइयो।"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"अनलक क्षेत्र बढाउनुहोस्।"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"स्लाइड अनलक।"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"ढाँचा अनलक।"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"फेस अनलक"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin अनलक"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"पासवर्ड अनलक।"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ढाँचा क्षेत्र।"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"स्लाइड क्षेत्र।"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?१२३"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"अक्षर"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"शब्द"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"लिङ्क"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"लाइन"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"कार्यशाला परीक्षण असफल भयो।"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"FACTORY_TEST कार्रवाइले /system/app मा स्थापित प्याकेजहरूको लागि मात्र समर्थन गर्छ।"</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"कुनै प्याकेज फेला पार्न सकिएन जसले FACTORY_TEST कार्य प्रदान गर्दछ।"</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"पुनःबुट गर्नुहोस्"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"यस \"<xliff:g id="TITLE">%s</xliff:g>\" मा भएको पृष्ठले बताउँछ:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"जाभास्क्रिप्ट"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"मार्गनिर्देशन पक्का गर्नुहोस्"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"यस पृष्ठलाई छोड्नुहोस्"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"यही पृष्ठमा रहनुहोस्"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nके तपाईँ यो पेजबाट नेभिगेट गर्न चाहनु हुन्छ भन्ने निश्चत छ?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"निश्चित गर्नुहोस्"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"जुक्ति: जुमलाई ठूलो र सानो पार्न दुई पटक हान्नुहोस्।"</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"स्वतः भर्ने"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"अटोफिल सेटअप गर्नुहोस्"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$१$२$३"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"प्रान्त"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"हुलाकी कोड"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"राज्य"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ZIP कोड"</string>
-    <string name="autofill_county" msgid="237073771020362891">"काउन्टी"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"टापु"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"जिल्ला"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"विभाग"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"प्रशासकीय क्षेत्र"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"पेरिस"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"क्षेत्र"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"इमिरेट"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"तपाईँका बुकमार्कहरू र इतिहास पढ्नुहोस्"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"ब्राउजरले भ्रमण गरेको सबै URL हरूको इतिहास र ब्राउजरका सबै बुकमार्कहरू पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। नोट: यो अनुमतिलाई तेस्रो पक्ष ब्राउजरहरूद्वारा वा वेब ब्राउज गर्ने क्षमताद्वारा बलपूर्वक गराउन सकिँदैन।"</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"वेब बुकमार्कहरू र इतिहास लेख्नुहोस्"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"अनुप्रयोगलाई तपाईंको ट्याब्लेटमा भण्डार गरिएको ब्राउजरको इतिहास वा बुकमार्कहरू परिमार्जन गर्न अनुमति दिन्छ। यसले अनुप्रयोगलाई ब्राजर डेटा मेटाउन वा परिमार्जन गर्न अनुमति दिन सक्दछ। टिप्पणी: यो अनुमति वेब ब्राउज गर्ने क्षमताहरूको साथ तेस्रो-पार्टी ब्राउजर वा अन्य अनुप्रयोगहरूद्वारा लागू गरिएको होइन।"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"तपाईँको फोनमा भण्डारण भएको ब्राउजरको इतिहास वा बुकमार्कहरू परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यसले सायद ब्राउजर डेटालाई मेट्न वा परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। नोट: वेब ब्राउज गर्ने क्षमतासहितका अन्य अनुप्रयोगहरू वा तेस्रो- पक्ष ब्राउजरद्वारा सायद यस अनुमतिलाई लागु गर्न सकिंदैन।"</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"एउटा आलर्म सेट गर्नुहोस्"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"स्थापना गरिएको सङ्केत घडी अनुप्रयोगमा सङ्केत समय मिलाउन अनुप्रयोगलाई अनुमति दिन्छ। केही सङ्केत घडी अनुप्रयोगहरूले यो सुविधा कार्यान्वयन नगर्न सक्छन्।"</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"भ्वाइसमेल थप गर्नुहोस्"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"तपाईँको भ्वाइसमेल इनबक्समा सन्देश थप्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"भूस्थान अनुमतिहरू ब्राउजर परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"ब्राउजरको भू-स्थान अनुमतिहरू परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले  स्थान सूचना मनपरी वेब साइटहरूमा पठाउने अनुमतिको लागि यसलाई प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"प्यकेजहरूको निरीक्षण गर्नुहोस्"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"प्याकेज स्थापना योग्य छ कि भनेर रुजु गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"एउटा प्याकेज रुजुकर्तामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"होल्डरलाई प्याकेज प्रमाणितकर्ताहरूको अनुरोधहरू बनाउन अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"पहुँच सिरियल पोर्टहरू"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"होल्डरलाई SerialManager API प्रयोग गरेर सिरियल पोर्टहरू पहुँच गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"विषयसूची प्रदातालाई बाह्य रूपमा पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"सेलबाट धारकले विषयवस्तु प्रदायकहरूसम्मको पहुँच पाउन अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्दैन।"</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"स्वचालित उपकरण अपडेटहरू हतोत्साहित गर्नुहोस्"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"होल्डरलाई उपकरण अपग्रेड गर्न गैर पारस्परिक पुनःबुटको लागि उचित समयको बारेमा प्रणालीमा जानाकारी प्रस्तावको लागि अनुमति दिन्छ।"</string>
-    <string name="save_password_message" msgid="767344687139195790">"के तपाईं ब्राउजरले यो पासवर्ड सम्झेको चाहनुहुन्छ?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"अहिले होइन"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"सम्झनुहोस्"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"कहिल्यै पनि होइन"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"यो पृष्ठ खोल्न तपाईँलाई अनुमति छैन।"</string>
-    <string name="text_copied" msgid="4985729524670131385">"क्लिपबोर्डमा प्रतिलिप गरिएको पाठ।"</string>
-    <string name="more_item_label" msgid="4650918923083320495">"बढी"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"मेनु+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"ठाउँ"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"प्रविष्टि गर्नुहोस्"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"मेटाउनुहोस्"</string>
-    <string name="search_go" msgid="8298016669822141719">"खोज्नुहोस्"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"खोज्नुहोस्"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"जिज्ञासा खोज गर्नुहोस्"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"प्रश्‍न हटाउनुहोस्"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"जिज्ञासा पेस गर्नुहोस्"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"भ्वाइस खोजी"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"छोएर अन्वेषण गर्ने सक्षम पार्न चाहनु हुन्छ?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>ले स्पर्षद्वारा अन्वेषण सक्षम गर्न चाहन्छ। स्पर्षद्वारा अन्वेषण सक्षम भएको बेला, तपाईँ आफ्नो औँलाको मुनि भएका विषयवस्तुहरू बारे सुन्न वा विवरण हेर्न सक्नुहुन्छ वा ट्याब्लेटसँग अन्तर्क्रिया गर्न इशारा गर्नुहोस्।"</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>ले स्पर्षद्वारा अन्वेषण सक्षम गर्न चाहन्छ। स्पर्षद्वारा अन्वेषण सक्षम भएको बेला तपाईँ आफ्नो औँलाको मुनि भएका विषयवस्तुहरू बारे सुन्न वा विवरण हेर्न सक्नुहुन्छ वा फोनसँग अन्तर्क्रिया गर्न इशारा गर्नुहोस्।"</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"१ महिना अघि"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"१ महिना अघि"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"१ सेकेन्ड अघि"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्ड अघि"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"१ मिनेट अघि"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> मिनेट अघि"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"१ घन्टा अघि"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> घन्टा अघि"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"अन्तिम <xliff:g id="COUNT">%d</xliff:g> दिन"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"अन्तिम महिना"</string>
-    <string name="older" msgid="5211975022815554840">"पुरानो"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"हिजो"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> दिन अघि"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"१ सेकेन्डमा"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्डमा"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"१ मिनेटमा"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g>मिनेटमा"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"१ घन्टामा"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> घन्टामा"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"भोलि"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> दिनमा"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"१ सेकेन्ड अघि"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्ड अगाडि"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"१ मिनेट अघि"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> मिनेट अघि"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"१ घन्टा अघि"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> घन्टा अघि"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"हिजो"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> दिन अघि"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"१ सेकन्ड"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्डमा"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"१ मिनेटमा"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> मिनेटमा"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"१ घन्टामा"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> घन्टामा"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"भोलि"</item>
-    <item quantity="other" msgid="2973062968038355991">"दिन<xliff:g id="COUNT">%d</xliff:g> मा"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g> मा"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"<xliff:g id="TIME">%s</xliff:g> मा"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> मा"</string>
-    <string name="day" msgid="8144195776058119424">"दिन"</string>
-    <string name="days" msgid="4774547661021344602">"दिन"</string>
-    <string name="hour" msgid="2126771916426189481">"घन्टा"</string>
-    <string name="hours" msgid="894424005266852993">"घन्टा"</string>
-    <string name="minute" msgid="9148878657703769868">"मिनेट"</string>
-    <string name="minutes" msgid="5646001005827034509">"मिनेट"</string>
-    <string name="second" msgid="3184235808021478">"सेकेन्ड"</string>
-    <string name="seconds" msgid="3161515347216589235">"सेकेन्ड"</string>
-    <string name="week" msgid="5617961537173061583">"हप्ता"</string>
-    <string name="weeks" msgid="6509623834583944518">"हप्ताहरू"</string>
-    <string name="year" msgid="4001118221013892076">"वर्ष"</string>
-    <string name="years" msgid="6881577717993213522">"वर्षहरू"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"१ सेकेन्ड"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्ड"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"१ मिनेट"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> मिनेट"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"१ घन्टा"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> घन्टा"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"भिडियो समस्या"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"यो भिडियो यस उपकरणको लागि स्ट्रिमिङ गर्न मान्य छैन।"</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"यो भिडियो चलाउन सक्दैन।"</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"ठीक छ"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"मध्यान्न"</string>
-    <string name="Noon" msgid="3342127745230013127">"मध्यान्ह"</string>
-    <string name="midnight" msgid="7166259508850457595">"मध्यरात"</string>
-    <string name="Midnight" msgid="5630806906897892201">"मध्यरात"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"सबैलाई चयन गर्नुहोस्"</string>
-    <string name="cut" msgid="3092569408438626261">"काट्नुहोस्"</string>
-    <string name="copy" msgid="2681946229533511987">"प्रतिलिपि बनाउनुहोस्"</string>
-    <string name="paste" msgid="5629880836805036433">"टाँस्नुहोस्"</string>
-    <string name="replace" msgid="5781686059063148930">"विस्थापन गर्नुहोस्…"</string>
-    <string name="delete" msgid="6098684844021697789">"मेट्नुहोस्"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL को प्रतिलिप गर्नुहोस्"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"पाठ चयन गर्नुहोस्"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"पाठ चयनता"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"शब्दकोशमा थप्नुहोस्"</string>
-    <string name="deleteText" msgid="6979668428458199034">"मेट्नुहोस्"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"निवेश विधि"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"पाठ कार्यहरू"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"भण्डारण ठाउँ सकिँदै छ"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"सायद केही प्रणाली कार्यक्रमहरूले काम गर्दैनन्"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> चलिरहेको छ"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"थप सूचनाको लागि छुनुहोस् वा अनुप्रयोग बन्द गर्नुहोस्।"</string>
-    <string name="ok" msgid="5970060430562524910">"ठिक छ"</string>
-    <string name="cancel" msgid="6442560571259935130">"रद्द गर्नुहोस्"</string>
-    <string name="yes" msgid="5362982303337969312">"ठिक छ"</string>
-    <string name="no" msgid="5141531044935541497">"रद्द गर्नुहोस्"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"सावधानी"</string>
-    <string name="loading" msgid="7933681260296021180">"लोड हुँदै..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"चालु"</string>
-    <string name="capital_off" msgid="6815870386972805832">"बन्द"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"प्रयोग गरेर कारबाही पुरा गर्नुहोस्"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"यस कार्यको लागि पूर्वनिर्धारितबाट प्रयोग गर्नुहोस्।"</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"प्रणाली सेटिङहरूमा पूर्वनिर्धारितलाई हटाउनुहोस् &gt; अनुप्रयोगहरू &gt; डाउनलोड।"</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"एउटा कार्यको चयन गर्नुहोस्"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB उपकरणको लागि एउटा अनुप्रयोग छान्नुहोस्"</string>
-    <string name="noApplications" msgid="2991814273936504689">"कुनै पनि अनुप्रयोगहरूले यो कार्य गर्न सक्दैनन्।"</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"दुर्भाग्यवश, <xliff:g id="APPLICATION">%1$s</xliff:g>ले रोकेको छ।"</string>
-    <string name="aerr_process" msgid="4507058997035697579">"दुर्भाग्यवश, प्रक्रिया <xliff:g id="PROCESS">%1$s</xliff:g> बन्द भयो।"</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g>ले कार्य गरिरहेको छैन।\n\nके तपाईँ यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"गतिविधि <xliff:g id="ACTIVITY">%1$s</xliff:g> ले प्रतिक्रिया देखाइरहेको छैन।\n\nके तपाईं यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> जवाफ दिइरहेको छैन। के तपाईँ यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"प्रक्रिया <xliff:g id="PROCESS">%1$s</xliff:g>ले कार्य गरिरहेको छैन।\n\nके तपाईँ यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="force_close" msgid="8346072094521265605">"ठिक छ"</string>
-    <string name="report" msgid="4060218260984795706">"रिपोर्ट गर्नुहोस्"</string>
-    <string name="wait" msgid="7147118217226317732">"प्रतीक्षा गर्नुहोस्"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"पृष्ठ गैर जिम्मेवारी भएको छ।\n\nके तपाईं यसलाई बन्द गर्न चाहनुहुन्छ?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"अनुप्रयोग पुनः निर्देशीत"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> अहिले चलिरहेको छ।"</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> वास्तविक सुरुवात भएको थियो।"</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"स्केल"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"सधैँ देखाउनुहोस्"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"प्रणाली सेटिङहरूमा यसलाई पुनःसक्षम गराउनुहोस् &gt; अनुप्रयोगहरू &gt; डाउनलोड गरेको।"</string>
-    <string name="smv_application" msgid="3307209192155442829">"अनुप्रयोग <xliff:g id="APPLICATION">%1$s</xliff:g> (प्रक्रिया <xliff:g id="PROCESS">%2$s</xliff:g>) ले यसको स्वयं-लागु गरिएको स्ट्रिटमोड नीति उलङ्घन गरेको छ।"</string>
-    <string name="smv_process" msgid="5120397012047462446">"प्रक्रिया <xliff:g id="PROCESS">%1$s</xliff:g> यसको आफ्नै कडामोड नीतिका कारण उल्लङ्घन गरिएको छ।"</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"एन्ड्रोइड अपग्रेड हुँदैछ…"</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"अनुप्रयोग अनुकुल हुँदै <xliff:g id="NUMBER_0">%1$d</xliff:g> को <xliff:g id="NUMBER_1">%2$d</xliff:g>।"</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"सुरुवात अनुप्रयोगहरू।"</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"बुट पुरा हुँदै।"</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> चलिरहेको छ"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"अनुप्रयोगमा स्विच गर्न छुनुहोस्"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"अनुप्रयोगहरू स्विच गर्ने हो?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"अर्को अनुप्रयोग पहिले नै चालु छ जुन तपाईंले एउटा नयाँ सुरु गर्नु अघि बन्द गर्नुपर्ने हुन्छ।"</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g> मा फर्कनुहोस्"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"नयाँ अनुप्रयोग सुरु नगर्नुहोस्।"</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> सुरु गर्नुहोस्"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"बचत नगरी पुरानो अनुप्रयोग रोक्नुहोस्।"</string>
-    <string name="sendText" msgid="5209874571959469142">"पाठको लागि एउटा प्रकार्य छान्नुहोस्"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"बजाउने मात्रा"</string>
-    <string name="volume_music" msgid="5421651157138628171">"मिडियाको मात्रा"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"ब्लुटुथको माध्यमद्वारा बजाइदै छ।"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"शान्त रिङ्गटोन सेट"</string>
-    <string name="volume_call" msgid="3941680041282788711">"इन-कल भोल्युम"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"ब्लुटुथ भित्री-कल मात्रा"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"आलर्म मात्रा"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"सूचना मात्रा"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"मात्रा"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"ब्लुटुथ भोल्युम"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"घन्टिको आवाज मात्रा"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"कला मात्रा"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"मिडियाको मात्रा"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"सूचना भोल्युम"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"पूर्वनिर्धारित रिङटोन"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"पूर्वनिर्धारित रिङटोन (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"कुनै पनि होइन"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"घन्टीका स्वरहरू"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"अज्ञात रिङटोन"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"वाइ-फाइ नेटवर्क उपलब्ध छ"</item>
-    <item quantity="other" msgid="4192424489168397386">"वाइ-फाइ नेटवर्कहरू उपलब्ध"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"खुल्ला वाइ-फाइ नेटवर्क उपलब्ध छ"</item>
-    <item quantity="other" msgid="7915895323644292768">"खुल्ला वाइ-फाइ नेटवर्क उपलब्ध छ"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"वाइ-फाइ नेटवर्कमा साइन गर्नुहोस्"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"नेटवर्कमा साइन गर्नुहोस्।"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"वाइ-फाइसँग जडान गर्न सकेन"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" कमजोर इन्टरनेट जडान छ।"</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"वाइ-फाइ प्रत्यक्ष"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"वाइ-फाइ सिधा सुरु गर्नुहोस्। यसले वाइ-फाइ ग्राहक/हट्स्पटलाई बन्द गराउने छ।"</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"वाइ-फाइ सिधा सुरु हुन सकेन।"</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"वाइ-फाइ प्रत्यक्ष खुल्ला छ"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"सेटिङहरूको लागि छुनुहोस्"</string>
-    <string name="accept" msgid="1645267259272829559">"स्वीकार्नुहोस्"</string>
-    <string name="decline" msgid="2112225451706137894">"अस्वीकार गर्नुहोस्"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"निमन्त्रणा पठाइएको"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"जडानमा निमन्त्रणा"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"बाट:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"प्रापक:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"आवश्यक PIN टाइप गर्नुहोस्:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"यो <xliff:g id="DEVICE_NAME">%1$s</xliff:g>सँग जोडिएको बेला ट्याब्लेट अस्थायी रूपमा वाइ-फाइबाट विच्छेद गरिने छ।"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"जब यो <xliff:g id="DEVICE_NAME">%1$s</xliff:g> सँग जडित हुन्छ, फोन अस्थायी रूपमा वाइ-फाइबाट विच्छेद हुने छ"</string>
-    <string name="select_character" msgid="3365550120617701745">"अक्षरहरू प्रवेश गराउनुहोस्"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS सन्देशहरू पठाइँदै"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; ले धरै संख्यामा SMS सन्देशहरू पठाउँदैछ। के तपाईँ यस अनुप्रयोगलाई सन्देशहरू पठाउन सुचारु गर्न अनुमति दिन चाहनु हुन्छ?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"अनुमति दिनुहोस्"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"अस्वीकार गर्नुहोस्"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; के तपाईँ सन्देश पठाउन चाहुनु हुन्छ &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt;."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"यसले "<font fgcolor="#ffffb060">" शुल्क लगाउन सक्छ"</font>" तपाईँको मोबाइल खातामा।"</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"यसले तपाईंको मोबाइल खातामा चार्जहरू उत्पन्न गर्दछ।"</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"पठाउनुहोस्"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"रद्द गर्नुहोस्"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"मेरो छनौट याद राख्नुहोस्"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"तपाईँ यसलाई पछि सेटिङहरूमा बदल्न सक्नु हुन्छ &gt; अनुप्रयोगहरू"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"सधैँ अनुमति दिनुहोस्"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"कहिल्यै अनुमति नदिनुहोस्"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM कार्ड हटाइयो"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"एउटा मान्य SIM कार्ड राखेर पुनःस्टार्ट नगरेसम्म मोबाइल नेटवर्क उपलब्ध हुने छैन।"</string>
-    <string name="sim_done_button" msgid="827949989369963775">"भयो"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM कार्ड थप गरियो"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"मोबाइल नेटवर्क पहुँच गर्न तपाईँको उपकरण पुनःस्टार्ट गर्नुहोस्।"</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"पुनःस्टार्ट गर्नुहोस्"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"समय मिलाउनुहोस्"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"मिति मिलाउनुहोस्"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"सेट गर्नुहोस्"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"भयो"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"नयाँ: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g>द्वारा प्रदान गरिएको।"</string>
-    <string name="no_permissions" msgid="7283357728219338112">"कुनै अनुमति आवश्यक छैन"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"सायद तपाईँलाई पैसा पर्न सक्छ।"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB ठूलो भण्डारण"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB जोडिएको छ"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"तपाईं आफ्नो कम्प्युटरमा USB मार्फत जडान हुनुभयो। तलको बटन टच गर्नुहोस् यदि तपाईं आफ्नो कम्प्युटर र एन्ड्रोइडको USB भण्डारण बीच फाइलहरू प्रतिलिपि गर्न चाहनुहुन्छ भने।"</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"तपाईं आफ्नो कम्प्युटरमा USB मार्फत जडान हुनुभयो। तलको बटन टच गर्नुहोस् यदि तपाईं आफ्नो कम्प्युटर र एन्ड्रोइडको SD कार्ड बीच फाइलहरू प्रतिलिपि गर्न चाहनुहुन्छ भने।"</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB भण्डारण चालु गर्नुहोस्"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB आम भण्डारणको लागि तपाईँको USB भण्डारण प्रयोग गर्दा एउटा समस्या भयो।"</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"USB आम भण्डारणको लागि तपाईँको SD कार्ड प्रयोग गर्दा एउटा समस्या भयो।"</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB जोडिएको छ"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"तपाईँको कम्प्युटरबाट वा तिर फाइलहरू प्रतिलिप गर्न छुनुहोस्।"</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB भण्डारण बन्द गर्नुहोस्"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB भण्डारण बन्द गर्न छुनुहोस्।"</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB भण्डारण प्रयोगमा छ"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB भण्डारण बन्द हुनुभन्दा पहीले तपाईँको कम्प्युटरबाट तपाईँको एन्ड्रोइड USB भण्डारण अनमाउन्ट (\"झिक्नुहोस्\") गर्नुहोस् ।"</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB भण्डारण बन्द गर्नुअघि तपाईँको कम्प्युटरबाट तपाईँको एन्ड्रोइडको SD कार्ड अनमाउन्ट (\"निकालेको\") गर्नुहोस्।"</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB भण्डारण बन्द गर्नुहोस्"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB भण्डारण बन्द गर्दा एउटा समस्या भयो। तपाईँले USB होस्ट अनमाउन्ट गर्नु भएको जाँच गर्नुहोस्, त्यसपछि फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB भण्डारण खोल्नुहोस्"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"यदि तपाईँले USB भण्डारण खोल्नु भयो भने तपाईँले प्रयोग गरिरहनु भएका केही अनुप्रयोगहरू रोकिने छन् र तपाईँले USB भण्डारण बन्द नगरेसम्म अनुपलब्ध हुन सक्छन्।"</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB संचालन असफल"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"ठिक छ"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"मिडिया उपकरणको रूपमा जडित"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"क्यामेराको रूपमा जडान भएको"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"एउटा स्थापनकर्ताको रूपमा जोडिएको छ"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB सहायकमा जोडिएको छ"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"अन्य USB विकल्पहरूको लागि टच गर्नुहोस्।"</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB भण्डारणलाई फर्म्याट  गर्न चाहनु हुन्छ?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD कार्ड फर्म्याट गर्ने?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"तपाईंको USBमा सङ्ग्रह भएका सबै फाइलहरू मेटिने छन्। यो कार्य उल्टाउन सकिँदैन!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"तपाईँको कार्डमा भएका सबै डेटाहरू हराउने छन्।"</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"फर्म्याट गर्नुहोस्"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB डिबग गर्ने जडित छ"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB डिबग गर्ने असक्षम पार्न छुनुहोस्।"</string>
-    <string name="select_input_method" msgid="4653387336791222978">"निवेश विधि छान्नुहोस्"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"इनपुट विधिहरू सेटअप गर्नुहोस्"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"भौतिक किबोर्ड"</string>
-    <string name="hardware" msgid="7517821086888990278">"हार्डवेयर"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"किबोर्ड रूपरेखा चयन गर्नुहोस्"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"किबोर्ड रूपरेखा चयन गर्न टच गर्नुहोस्।"</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"उम्मेदवार"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB भण्डारणको तयारी हुँदै"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD कार्ड तयार गर्दै"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"त्रुटिहरूको लागि जाँच गर्दै।"</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"रिक्त USB भण्डारण"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"खाली SD कार्ड"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB भण्डारण खाली वा असमर्थित फाइल प्रणाली छ।"</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD कार्ड खाली छ अथवा समर्थन नगरिएको फाइल प्रणाली छ।"</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"बिग्रिएको USB भण्डारण"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"बिग्रिएको SD कार्ड"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB भण्डारण बिग्रिएको छ। यसलाई पुनःफर्म्याट गर्न प्रयास गर्नुहोस।"</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD कार्ड बिग्रिएको छ। यसलाई पुनःफर्म्याट गर्न प्रयास गर्नुहोस।"</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB भण्डारण अप्रत्याशित रूपमा हटाइएको छ"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD कार्ड अनपेक्षित रूपमा हटाइयो"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"डेटा गुम्नबाट रोक्नको लागि USB भण्डारण हटाउनुअघि अनमाउन्ट गर्नुहोस्।"</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"डेटा नाश हुनबाट बच्न SD कार्डलाई निकाल्नुभन्दा पहिला अनमाउन्ट गर्नुहोस्।"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB भण्डारण हटाउनको लागि सुरक्षित छ"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD कार्ड हटाउन सुरक्षित छ।"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"तपाईं सुरक्षित रूपमा USB भण्डारण हटाउन सक्नुहुने छ।"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"तपाईँ SD कार्ड सुरक्षित रूपमा हटाउन सक्नु हुन्छ।"</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"USB भण्डारण हटाइयो"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"हटाइएको SD कार्ड"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USD भण्डारण हटाइयो। नयाँ मिडिया घुसाउनुहोस्।"</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD कार्ड हटाइयो। एउटा नयाँ छिराउनुहोस्।"</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"कुनै मिल्ने गतिविधि पाइएन।"</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"खण्ड प्रयोग तथ्याङ्कहरू अपडेट गर्नुहोस्"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"जम्मा गरिएको घटक उपयोग तथ्याङ्कहरूलाई परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूबाट प्रयोगको लागि होइन।"</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"सामाग्रीको नकल गर्नुहोस्"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"अनुप्रयोगलाई सामग्री प्रतिलिपि गर्न पूर्वनिर्धारित कन्टेनर सेवा आह्वान गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूद्वाराको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"मिडिया परिणाम दिशानिर्देश गर्नुहोस्"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"मिडिया परिणामलाई अन्य बाहिरी उपकरणहरूसँग लैजानको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"किगार्ड सुरक्षित भण्डारण पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"अनुप्रयोगलाई किगार्ड सुरक्षित भण्डारण पहुँच गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"किगार्ड प्रदर्शन गर्ने र लुकाउने नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"अनुप्रयोगलाई किगार्ड नियन्त्रण गर्न अनुमति दिन्छ।"</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"जुम नियन्त्रणको लागि दुई चोटि टच गर्नुहोस्"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"विजेट थप गर्न सकिँदैन।"</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"जानुहोस्"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"खोज्नुहोस्"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"पठाउनुहोस्"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"अर्को"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"भयो"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"अघिल्लो"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"चलाउनुहोस्"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">\n"नम्बर डायल गर्नुहोस् <xliff:g id="NUMBER">%s</xliff:g> प्रयोग गरेर"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"सम्पर्क सिर्जना गर्नुहोस्\nयो <xliff:g id="NUMBER">%s</xliff:g> प्रयोग गरेर"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"निम्न एउटा वा धेरै अनुप्रयोगहरूले तपाईँको खातामा पहुँचको लागि अनुमति अहिले र भविष्यमा अनुरोध गर्छन्।"</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"के तपाईँ यस अनुरोधलाई अनुमति दिन चाहनुहुन्छ?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"अनुरोध पहुँच गर्नुहोस्"</string>
-    <string name="allow" msgid="7225948811296386551">"अनुमति दिनुहोस्"</string>
-    <string name="deny" msgid="2081879885755434506">"अस्वीकार गर्नुहोस्"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"अनुरोध गरिएको अनुमति"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">\n"खाता <xliff:g id="ACCOUNT">%s</xliff:g>को लागि अनुरोध गरिएको अनुमति।"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"इनपुट विधि"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"सिङ्क गर्नुहोस्"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"उपलब्धता"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"वालपेपर"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"वालपेपर परिवर्तन गर्नुहोस्"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"सूचना सुन्नेवाला"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN सक्रिय भयो"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN <xliff:g id="APP">%s</xliff:g>द्वारा सक्रिय गरिएको हो"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"नेटवर्क प्रबन्ध गर्न छुनुहोस्।"</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g>सँग जोडिएको छ। नेटवर्क व्यवस्थापन गर्नको लागि छुनुहोस्।"</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"VPN जडान सधै जोड्दै…"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"सधैँ खुल्ला हुने VPN जोडिएको"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"सधैँ भरि VPN त्रुटिमा"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"कन्फिगर गर्न टच गर्नुहोस्"</string>
-    <string name="upload_file" msgid="2897957172366730416">"फाइल छान्नुहोस्"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"कुनै फाइल छानिएको छैन"</string>
-    <string name="reset" msgid="2448168080964209908">"पुनःसेट गर्नु"</string>
-    <string name="submit" msgid="1602335572089911941">"पेस गर्नुहोस्"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"कार मोड सक्षम पारियो।"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"कार मोडबाट निस्कन छुनुहोस्।"</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"टेथर गर्ने वा हटस्पट सक्रिय"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"सेटअप गर्न टच गर्नुहोस्।"</string>
-    <string name="back_button_label" msgid="2300470004503343439">"पछाडि"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"अर्को"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"छोड्नुहोस्"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"उच्च मोबाइल डेटा प्रयोग"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"मोबाइल डेटा प्रयोगको बारेमा अरू थप जान्नको लागि  छुनुहोस्।"</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"मोबाइल डेटा सीमा पार भयो"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"मोबाइल डेटा प्रयोग बारे थप सिक्न छुनुहोस्।"</string>
-    <string name="no_matches" msgid="8129421908915840737">"कुनै मिलेन"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"पृष्ठमा फेला पार्नुहोस्"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"१ मेल"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="TOTAL">%d</xliff:g> को <xliff:g id="INDEX">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"भयो"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB  भण्डारण अनमाउन्ट गर्दै..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD कार्ड अनमाउन्ट गर्दै…"</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB भण्डारण मेटाउँदै…"</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD कार्ड मेटाउँदै…"</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB भण्डारणलाई मेटाउन सकेन।"</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD कार्ड मेटाउन सकेन"</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD कार्ड अनमाउन्ट हुनुभन्दा पहिला निकालियो।"</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"अहिले USB भण्डारण जाँच भइरहेको छ।"</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD कार्ड अहिले परीक्षण भइरहेको छ।"</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD कार्ड हटाइयो।"</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"SD कार्ड कम्प्युटरद्वारा अहिले प्रयोगमा छ।"</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD कार्ड अहिले कम्प्युटरद्वारा प्रयोगमा छ।"</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"बाह्य मिडिया अज्ञात अवस्थामा।"</string>
-    <string name="share" msgid="1778686618230011964">"साझेदारी गर्नुहोस्"</string>
-    <string name="find" msgid="4808270900322985960">"पत्ता लगाउनुहोस्"</string>
-    <string name="websearch" msgid="4337157977400211589">"वेब खोजी"</string>
-    <string name="find_next" msgid="5742124618942193978">"अर्को भेटाउनुहोस्"</string>
-    <string name="find_previous" msgid="2196723669388360506">"अघिल्लो फेला पार्नुहोस्"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> बाट स्थान अनुरोध"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"स्थान अनुरोध"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) द्वारा अनुरोध गरिएको"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"हो"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"होइन"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"सीमा नाघेकाहरू मेट्नुहोस्"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"त्यहाँ <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> मेटाइएका आइटमहरू छन् <xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g>को लागि, खाता <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g>। तपाईं के गर्न चाहनु हुन्छ?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"वस्तुहरू मेट्नुहोस्"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"मेटिएकाहरू पूर्ववत बनाउनुहोस्।"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"अहिलेको लागि केही नगर्नुहोस्"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"एउटा खाता छान्‍नुहोस्"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"एउटा खाता थप्नुहोस्"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"खाता थप गर्नुहोस्"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"बढाउनुहोस्"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"घटाउनुहोस्"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g>छुनुहोस् र समाउनुहोस्।"</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"बढाउन माथि र घटाउन तल सार्नुहोस्।"</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"मिनेट बढाउनुहोस्"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"मिनेट घटाउनुहोस्"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"घन्टा बढाउनुहोस्"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"घन्टा घटाउनुहोस्"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"PM सेट गर्नुहोस्"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"AM सेट गर्नुहोस्"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"महिना बढाउनुहोस्"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"महिना घटाउनुहो्स्"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"दिन बढाउनुहोस्"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"दिन घटाउनुहोस्"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"वर्ष बढाउनुहोस्"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"वर्ष घटाउनुहोस्"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"रद्द गर्नुहोस्"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"मेट्नुहोस्"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"भयो"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"मोड परिवर्तन गर्नुहोस्"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"प्रविष्टि गर्नुहोस्"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"एउटा अनुप्रयोग छान्नुहोस्"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"साझेदारी गर्नुहोस्..."</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g> सँग साझेदारी गर्नुहोस्"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"धिसार्ने ह्यान्डल। छुनुहोस् &amp; समाउनुहोस्।"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>को लागि माथि धिसार्नुहोस्"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> को लागि तल स्लाइड गर्नुहोस्।"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"स्लाइड <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>को लागि बायाँ।"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"स्लाइड <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>को लागि दायाँ।"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"अनलक गर्नुहोस्"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"क्यामेरा"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"मौन"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"आवाज चालू"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"खोज्नुहोस्"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"खोल्नलाइ हुत्त्याउनुहोस्।"</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"बोलिएको पासवर्ड कुञ्जीहरू सुन्नको लागि हेडसेट प्लग इन गर्नुहोस्।"</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"डट।"</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"गृह खोज्नुहोस्"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"माथि खोज्नुहोस्"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"थप विकल्पहरू"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"आन्तरिक भण्डारण"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD कार्ड"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB भण्डारण"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"सम्पादन गर्नुहोस्"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"डेटा प्रयोग चेतावनी"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"उपयोग र सेटिङहरू हेर्न छुनुहोस्।"</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G डेटा असक्षम गरिएको"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G डेटा असक्षम गरियो"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"मोबाइल डेटा असक्षम पारियो।"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"वाइ-फाइ डेटा असक्षम गरियो"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"सक्षम पार्न छुनुहोस्।"</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G डेटा सीमा भन्दा पार भएको छ"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G डेटा SIMा नाघ्यो"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"मोवाइल डेटा SIMा नाघ्यो"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"वाइ-फाइ डेटा SIMा नाघ्यो"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> उल्लेखित सीमा भन्दा बढी छ।"</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"पृष्ठभूमिका डेटा प्रतिबन्धित गरिएको छ"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"अवरोध हटाउन छुनुहोस्।"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"सुरक्षा प्रमाणपत्र"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"प्रमाणपत्र मान्य छ।"</string>
-    <string name="issued_to" msgid="454239480274921032">"द्वारा जारी गरिएको:"</string>
-    <string name="common_name" msgid="2233209299434172646">"साधारण नाम:"</string>
-    <string name="org_name" msgid="6973561190762085236">"संगठन:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"संगठनात्मक एकाइ:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"द्वारा जारी गरिएको:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"मान्यता:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"जारी गरिएको:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"अवधि समाप्त:"</string>
-    <string name="serial_number" msgid="758814067660862493">"क्रम संख्या:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"औँठाछापहरू:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-२५६ औंठाछाप:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 औंलाछाप:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"सबै हेर्नुहोस्"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"गतिविधि छनौट गर्नुहोस्"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"साझेदारी गर्नुहोस्..."</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"पठाउँदै..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"ब्राउजर सुरु गर्ने हो?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"कल स्वीकार गर्नुहुन्छ?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"सधैँ"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"एउटा मात्र"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"ट्याब्लेट"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"फोन"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"हेडफोनहरू"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"डक स्पिकरहरू"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"प्रणाली"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"ब्लुटुथ अडियो"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"ताररहित प्रदर्शन"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"भयो"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"मिडियाको उत्पादन"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"स्क्यान गर्दै ..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"जडान हुँदै..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"उपलब्ध"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"उपलब्ध छैन"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"प्रयोगमा छ"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"पूर्व-निर्मित स्क्रिन"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI स्क्रिन"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"आवरण #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", सुरक्षित"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"ताररहित प्रदर्शन जोडिएको छ"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"अर्को उपकरणमा यो स्क्रिनले देखाइरहेको छ"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"विच्छेदन गर्नुहोस्"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"आपतकालीन कल"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"ढाँचा बिर्सनु भयो"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"गलत ढाँचा"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"गलत पासवर्ड"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"गलत PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%1$d</xliff:g>सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"आफ्नो ढाँचा कोर्नुहोस्"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"पासवर्ड प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM कार्ड अहिले असक्षम छ। सुचारु गर्नको लागि PUK कोड प्रविष्टि गर्नुहोस्।  विवरणको लागि वाहकलाई सम्पर्क गर्नुहोस्।"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"इच्छित PIN कोड प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"मनपर्दो PIN कोड निश्चित गर्नुहोस्"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM कार्ड अनलक गर्दै…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"गलत PIN कोड।"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"४ देखि ८ वाट नम्बर भएको एउटा PIN टाइप गर्नुहोस्।"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK कोड ८ वटा नम्बर वा सो भन्दा बढी हुनुपर्छ।"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"PUK कोड पुन:प्रदान गर्नुहोस्। धेरै पुन:प्रयासहरूले SIMलाई स्थायी रूपमा निष्क्रिय गरिदिने छ।"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN कोडहरू मेल खाएन"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"निकै धेरै ढाँचा कोसिसहरू"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"अनलक गर्नको लागि, तपाईँको Google खाताको साथ साइन इन गर्नुहोस्।"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"प्रयोगकर्ता नाम (इमेल)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"पासवर्ड"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"साइन इन गर्नुहोस्"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"अमान्य प्रयोगकर्तानाम वा पासवर्ड।"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"के तपाईँले उपयोगकर्ता नाम वा पासवर्ड बिर्सनुभयो?\n"<b>"google.com/accounts/recovery"</b>" मा जानुहोस्।"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"खाता जाँच हुँदै…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"तपाईँले गलत तरिकाले तपाईँको PIN <xliff:g id="NUMBER_0">%d</xliff:g> पटक टाइप गर्नु भएको छ। \n\n<xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"तपाईँले तपाईँक पासवर्ड <xliff:g id="NUMBER_0">%d</xliff:g> पटक गलत टाइप गर्नुभएको छ। \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"तपाईँले तपाईँको अनलक ढाँचा गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक खिच्नु भएको छ। \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि कोसिस गर्नुहोस्।"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"तपाईँले ट्याब्लेटलाई अनलक गर्न गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक कोसिस गर्नु भएको छ। <xliff:g id="NUMBER_1">%d</xliff:g> पछि थप असफल प्रयासहरू, ट्याब्लेट पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ र सबै प्रयोग डेटा हराउने छ।"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"तपाईँले गलतसँग फोनलाई अनलक गर्न <xliff:g id="NUMBER_0">%d</xliff:g> पटक कोसिस गर्नु भयो। <xliff:g id="NUMBER_1">%d</xliff:g> पछि थप असफल कोसिसहरू, फोनलाई पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ र सबै प्रयोग डेटा हराउने छ।"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"तपाईँले ट्यब्लेटलाई अनलक गर्न गलत तरिकाले <xliff:g id="NUMBER">%d</xliff:g> पटक प्रयास गर्नु भएको छ। अब ट्याब्लेटलाई पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ।"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"तपाईंले गलत तरिकाले फोन <xliff:g id="NUMBER">%d</xliff:g> पटक अनलक गर्ने प्रयत्न गर्नुभयो। अब फोन फ्याक्ट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ।"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"तपाईंले गलत तरिकाले आफ्नो अनलक ढाँचा <xliff:g id="NUMBER_0">%d</xliff:g> पटक कोर्नुभयो। <xliff:g id="NUMBER_1">%d</xliff:g> विफल प्रयत्नहरू पछि, तपाईंलाई आफ्नो ट्याब्लेट इमेल खाता प्रयोग गरेर अनलक गर्न सोधिने छ।\n\n फेरि प्रयास गर्नुहोस् <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डहरूमा।"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"तपाईँले आफ्नो अनलक ढाँचा गलत रूपमा <xliff:g id="NUMBER_0">%d</xliff:g> पटक तान्नु भएको छ। <xliff:g id="NUMBER_1">%d</xliff:g> धेरै असफल प्रयासहरूपछि, तपाईँलाई एउटा इमेल खाताको प्रयोग गरेर तपाईँको फोन अनलक गर्न सोधिने छ।\n\n फेरि <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डमा प्रयास गर्नुहोस्।"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"हटाउनुहोस्"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"आवाज सल्लाह दिएको तहभन्दा माथि  बढाउने हो?\nठूलो आवाजमा सुन्दा लामो समयको लागि तपाईँको सुन्ने शक्तीलाई खत्तम पार्न सक्छ।"</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"उपलब्धता सक्षम पार्न दुईवटा औंलाहरूले थिचिरहनुहोस्।"</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"पहुँच सक्षम गरिएको।"</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"पहुँचयोग्यता रद्द गरियो।"</string>
-    <string name="user_switched" msgid="3768006783166984410">"अहिलेको प्रयोगकर्ता <xliff:g id="NAME">%1$s</xliff:g>।"</string>
-    <string name="owner_name" msgid="2716755460376028154">"मालिक"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"त्रुटि"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"प्रतिबन्धित प्रोफाइलहरूको लागि यस अनुप्रयोगले खाताहरू समर्थन गर्दैन"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"यस कार्य सम्हालने कुनै अनुप्रयोग भेटिएन"</string>
-    <string name="revoke" msgid="5404479185228271586">"रद्द गर्नुहोस्"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"पत्र"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"सरकारी पत्र"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"कानूनी"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Junior Legal"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Ledger"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Tabloid"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"रद्द गरियो"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"सामाग्री लेखनमा त्रुटि"</string>
-    <string name="reason_unknown" msgid="6048913880184628119">"अज्ञात"</string>
-    <string name="restr_pin_enter_admin_pin" msgid="783643731895143970">"प्रशासक PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="restr_pin_incorrect" msgid="8571512003955077924">"गलत"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"वर्तमान PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"नयाँ PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"नयाँ PIN निश्चित गर्नुहोस्"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"प्रतिबन्धहरूलाई परिवर्तन गर्नको लागि एउटा PIN बनाउनुहोस्"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN हरू मेल खाएनन्। पुनः प्रयास गर्नुहोस्।"</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN अति छोटो भयो। कम्तीमा ४ अङ्क हुन आवश्यक छ।"</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="311050995198548675">"१ सेकेन्ड पछि पुनः प्रयास गर्नुहोस्।"</item>
-    <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्डमा पुनः प्रयास गर्नुहोस्"</item>
-  </plurals>
-    <string name="restr_pin_try_later" msgid="973144472490532377">"पछि पुनः प्रयास गर्नुहोस्"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"पट्टि देखिने बनाउन स्क्रिनको छेउमा स्वाइप गर्नुहोस्"</string>
-</resources>
diff --git a/core/res/res/values-ne/strings.xml b/core/res/res/values-ne/strings.xml
deleted file mode 100644
index 7ff8dae..0000000
--- a/core/res/res/values-ne/strings.xml
+++ /dev/null
@@ -1,1587 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;बिना शीर्षक&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(कुनै फोन नम्बर छैन)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(अज्ञात)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"भ्वाइस मेल"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN१"</string>
-    <string name="mmiError" msgid="5154499457739052907">"जडान समस्या वा अमान्य MMI कोड।"</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"अपरेशन निश्चित डायल नम्बरहरूको लागि मात्र प्रतिबन्धित छ।"</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"सेवा सक्षम पारियो।"</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"निम्न उल्लेखितको लागि सेवा सक्षम पारियो:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"सेवा असक्षम पारिएको छ।"</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"दर्ता सफल भयो।"</string>
-    <string name="serviceErased" msgid="1288584695297200972">"मेटाइ सफल थियो।"</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"गलत पासवर्ड।"</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI पुरा भयो।"</string>
-    <string name="badPin" msgid="9015277645546710014">"तपाईंले टाइप गर्नुभएको पुरानो PIN सही छैन।"</string>
-    <string name="badPuk" msgid="5487257647081132201">"तपाईंले टाइप गर्नुभएको PUK सही छैन।"</string>
-    <string name="mismatchPin" msgid="609379054496863419">"तपाईंले टाइप गर्नुभएको PIN मेल खाँदैन।"</string>
-    <string name="invalidPin" msgid="3850018445187475377">"४ देखि ८ वटा नम्बर भएको एउटा PIN टाइप गर्नुहोस्।"</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"८ वटा नम्बरहरू वा सो भन्दा लामो एउटा PUK टाइप गर्नुहोस्।"</string>
-    <string name="needPuk" msgid="919668385956251611">"तपाईंको SIM कार्ड PUK-लक छ। यसलाई अनलक गर्न PUK कोड टाइप गर्नुहोस्।"</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM कार्ड अनलक गर्न PUK2 टाइप गर्नुहोस्।"</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"आगमन कलर ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"बाहिरिने कलर ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"कल अगाडि बढाउँदै"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"कल प्रतिक्षा"</string>
-    <string name="BaMmi" msgid="455193067926770581">"कल ब्यारिङ"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"पासवर्ड परिवर्तन"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN परिवर्तन"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"प्रस्तुत नम्बरमा कल गर्दै"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"कल गर्ने अंक रोकेको छ।"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"कल गर्ने तिन तरिका"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"नचाहिएका रिसउठ्दा कलहरूको अस्वीकार"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"कलिङ नम्बर प्रदान गर्ने"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"बाधा नगर्नुहोस्"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"सीमति गर्न पूर्वनिर्धारित कलर ID, अर्को कल: सीमति गरिएको"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"कलर ID पूर्वनिर्धारितको लागि रोकावट छ। अर्को कल: रोकावट छैन"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"कलर ID पूर्वनिर्धारितदेखि प्रतिबन्धित छैन। अर्को कल: प्रतिबन्धित छ"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"कलर ID पूर्वनिर्धारितको लागि रोकावट छैन। अर्को कल: रोकावट छैन"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"सेवाको व्यवस्था छैन।"</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"तपाईं कलर ID सेटिङ परिवर्तन गर्न सक्नुहुन्न।"</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"प्रतिबन्धित पहुँच परिवर्तन भएको छ"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"डेटा सेवा रोकिएको छ।"</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"आपतकालीन सेवा रोकिएको छ।"</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"भ्वाइस सेवा ब्लक भएको छ।"</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"सबै आवाज सेवाहरू बन्द छन्।"</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS सेवा रोकिएको छ।"</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"भ्वाइस/डेटा सेवाहरू रोकिएका छन्।"</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"आवाज/SMS सेवाहरू बन्द छन्।"</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"सबै भ्वाइस/डेटा/SMS सेवाहरू ब्लक भएका छन्।"</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"आवाज"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"डेटा"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"फ्याक्स"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"Async"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"सिङ्क गर्नुहोस्"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"प्याकेट"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"रोमिङ सूचक खुला"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"रोमिङ सूचक बन्द"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"रोमिङ सूचक फ्ल्यास गर्दै"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"छिमेकबाट बाहिर"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"बिल्डिङको बाहिर"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"रोमिङ - उपयुक्त प्रणाली"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"रोमिङ - उपलब्ध प्रणाली"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"रोमिङ - एलियन्सर पार्टनर"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"रोमिङ - प्रिमियम पार्टनर"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"रोमिङ - पूर्ण सेवा कार्यक्षमता अवस्था"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"रोमिङ - आङ्शिक सेवा प्रकार्यता"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"रोमिङ ध्वजा चालु छ"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"रोमिङ ब्यानर बन्द छ"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"सेवाको खोजी गर्दै…"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: अगाडि पठाइएको छैन"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g> पछि <xliff:g id="TIME_DELAY">{2}</xliff:g> सेकेन्ड"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: अगाडि बढाइएको छैन"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: अगाडि बढाइएको छैन"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"विशेषता कोड पुरा भयो।"</string>
-    <string name="fcError" msgid="3327560126588500777">"जडान समस्या वा अमान्य सुविधा कोड।"</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"ठिक छ"</string>
-    <string name="httpError" msgid="7956392511146698522">"एउटा नेटवर्क त्रुटि थियो।"</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL भेटाउन सकेन।"</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"साइटको आधिकारिकता योजना समर्थित छैन।"</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"प्रमाणीकरण गर्न सकेन।"</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"प्रोक्सी सर्भरको माध्यमद्वारा प्रमाणिकरण असफल भएको छ।"</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"सर्भरसँग जोड्न सकेन।"</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"सर्भरसँग संचार गर्न सकेन। फेरि पछि कोसिस गर्नुहोस्।"</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"सर्भर संगको सम्पर्क प्रक्रिया समय सकियो।"</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"पृष्टमा धेरै सर्भरहरूतिर पुनः निर्देशनहरू छन्।"</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"प्रोटोकल समर्थित छैन।"</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"एउटा सुरक्षित जडान स्थापना गर्न सकेन।"</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"पृष्ठ खोल्न सकिँदैन किनभने URL अमान्य छ।"</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"फाइल भेटाउन सकेन।"</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"अनुरोध गरिएको फाइल भेटाउन सकेन।"</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"धेरै नै अनुरोधहरू प्रक्रियामा छन्। पछि फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g>को लागि साइन इन त्रुटि"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"सिङक गर्नुहोस्"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"सिङ्क गर्नुहोस्"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"अति धेरै <xliff:g id="CONTENT_TYPE">%s</xliff:g> मेट्नुहोस्।"</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ट्याब्लेट भण्डारण खाली छैन! ठाउँ खाली गर्नको लागि केही फाइलहरू मेटाउनुहोस्।"</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"फोन भण्डारण भरिएको छ! ठाउँ खाली गर्नको लागि केही फाइलहरू मेटाउनुहोस्।"</string>
-    <string name="me" msgid="6545696007631404292">"मलाई"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ट्याब्लेट विकल्पहरू"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"फोन विकल्पहरू"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"मौन मोड"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"वायरलेस अन गर्नुहोस्"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"ताररहित बन्द गर्नुहोस्"</string>
-    <string name="screen_lock" msgid="799094655496098153">"स्क्रिन लक गर्नुहोस्"</string>
-    <string name="power_off" msgid="4266614107412865048">"पावर बन्द"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"घन्टी बन्द भयो"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"घन्टी कम्पन गर्छ"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"घन्टि चालु छ"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"बन्द गर्दै..."</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"तपाईँको ट्याब्लेट बन्द हुने छ।"</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"तपाईँको फोन बन्द हुने छ।"</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"के तपाईं बन्द गर्न चाहनुहुन्छ?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"सुरक्षित मोडमा पुनःबुट गर्नुहोस्"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"सुरक्षित मोडमा तपाईँ पुनःबुट गर्न चाहनु हुन्छ? तपाईँले स्थापना गरेका सबै तेस्रो पक्षका अनुप्रयोगहरूलाई असक्षम गराउने छ।"</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"नयाँ"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"कुनै नयाँ अनुप्रयोगहरू छैनन्।"</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ट्याब्लेट विकल्पहरू"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"फोन विकल्पहरू"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"स्क्रिन बन्द"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"शक्ति बन्द"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"बग रिपोर्ट"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"बग रिपोर्ट लिनुहोस्"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"एउटा इमेल सन्देशको रूपमा पठाउनलाई यसले तपाईँको हालैको उपकरणको अवस्थाको बारेमा सूचना जम्मा गर्ने छ। बग रिपोर्ट सुरु गरेदेखि पठाउन तयार नभएसम्म यसले केही समय लिन्छ; कृपया धैर्य गर्नुहोस्।"</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"मौन मोड"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"आवाज बन्द छ"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"ध्वनि खुल्ला छ"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"हवाइजहाज मोड"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"उडान मोड खुला छ"</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"हवाइजहाज मोड बन्द छ"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"९९९+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"सुरक्षित मोड"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"एन्ड्रोइड प्रणाली"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"तपाईँले तिर्नु पर्ने सेवाहरू"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"तपाईँलाई महँगो पर्न सक्ने कामहरू गर्नुहोस्।"</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"तपाईंका सन्देशहरू"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"तपाईँका SMS, इमेल र अन्य सन्देशहरू पढ्नुहोस् र लेख्नुहोस्।"</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"तपाईँको निजी सूचना"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"तपाईँको सम्पर्क कार्डमा भण्डारण भएका तपाईँको बारेको जानकारीमा सिधा पहुँच पुर्‍याउनुहोस्।"</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"तपाईँको सामाजिक सूचना"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"तपाईँको सम्पर्कहरू र सामाजिक जडानहरूको बारेको जानकारीमा सिधा पहुँच पुर्‍याउनुहोस्।"</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"तपाईँको स्थान"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"तपाईँको भौतिक स्थान निरीक्षण गर्नुहोस्।"</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"नेटवर्क संचार"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"विभिन्न नेटवर्क सुविधाहरूमा पहुँच राख्नुहोस्।"</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"ब्लुटुथ"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"ब्लुटुथको माध्यमद्वारा उपकरणहरू र नेटवर्कहरूमाथि पहुँच राख्नुहोस्।"</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"अडियो सेटिङहरू"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"अडियो सेटिङहरू बदल्नुहोस्।"</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"ब्यट्रिलाई प्रभाव पार्छ"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"छिट्टै ब्याट्रि सकाउन सक्ने ती विशेषताहरू प्रयोग गर्नुहोस्।"</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"पात्रो"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"पात्रो तथा घटनाहरूमा प्रत्यक्ष पहुँच"</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"प्रयोगकर्ता शब्दकोश पढ्नुहोस्"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"प्रयोगकर्ता शब्दकोशमा शब्दहरू पढ्नुहोस्।"</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"प्रयोगकर्ता शब्दकोश लेख्नुहोस्"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"प्रयोगकर्ता शब्दकोशमा शब्दहरू थप्नुहोस्।"</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"बुकमार्कहरू र इतिहास"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"बुकमार्कहरू र ब्राउजर इतिहासमा सिधा पहुँच।"</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"अलार्म"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"अलार्म घडी सेट गर्नुहोस्।"</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"भ्वाइस मेल"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"भ्वाइसमेलमा सिधा पहुँच।"</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"माइक्रोफोन"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"मा[क्रोफोनबाट रेकर्ड अडियोमा सिधा पहुँच पुर्‍याउनुहोस्।"</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"क्यामेरा"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"तस्बिर वा भिडियो क्याप्चरको लागि क्यामेरामा सिधा पहुँच।"</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"स्क्रिन लक गर्नुहोस्"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"तपाईँको उपकरणमा लक स्क्रिनको व्यवहारलाई प्रभावित गर्ने क्षमता।"</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"तपाईँका अनुप्रयोगहरूको सूचना"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"तपाईँको उपकरणमा अन्य अनुप्रयोगहरूको व्यवहारमा प्रभाव पार्ने क्षमता।"</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"वालपेपर"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"उपकरण वालपेपर सेटिङहरू बदल्नुहोस्।"</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"घडी"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"उपकरण समय वा समय क्षेत्र परिवर्तन गर्नुहोस्।"</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"स्थिति पट्टी"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"उपकरण स्थिति सेटिङहरू परिवर्तन गर्नुहोस्।"</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"सिङ्क सेटिङहरू"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"सिङ्क सेटिङहरूमा पहुँच गर्नुहोस्।"</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"तपाईँका खाताहरू"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"उपलब्ध खाताहरू पहुँच गर्नुहोस्।"</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"हार्डवेयर नियन्त्रणहरू"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"ह्यान्डसेटको हार्डवेयरमा प्रत्यक्ष पहुँच।"</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"फोन कलहरू"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"अनुगमन, रेकर्ड र फोन कलहरूको प्रसोधन गर्नुहोस।"</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"प्रणाली औजारहरू"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"निम्न-स्तर पहुँच र प्रणालीको नियन्त्रण"</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"विकसित टुलहरू"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"अनुप्रयोग विकासकर्ताहरूको लागि मात्र सुविधाहरूको आवश्यकता।"</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"अन्य अनुप्रयोग UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"अन्य अनुप्रयोगहरूको UI लाई असर पार्नुहोस्"</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"भण्डारण"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB भण्डारणमाथि पहुँच गर्नुहोस्।"</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD कार्डमाथि पहुँच गर्नुहोस्।"</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"पहुँचीकरण विशेषताहरू"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"सहयोगी प्रविधि भएको विशेषताहरूले अनुरोध गर्न सक्छन्।"</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"विन्डो सामग्रीको पुनःबहाली गर्नुहोस्।"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"तपाईँको अन्तरक्रिया भइरहेको विन्डोको सामग्रीको निरीक्षण गर्नुहोस्।"</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"छोएर गरिने खोजलाई सुचारु गर्नुहोस्"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"छोइएका आइटमहरू चर्को स्वरमा बोलिने छ र स्क्रिन इशाराहरूको प्रयोगले अन्वेषण गर्न सकिन्छ।"</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"उच्च वेब पहुँचलाई सुचारु गर्नुहोस्"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"अनुप्रयोगको सामग्रीलाई थप पहुँचयोग्य बनाउन लिपिहरू स्थापना गर्न सक्नु हुन्छ।"</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"आफुले टाइप गरेको पाठको निरीक्षण गर्नुहोस्"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"व्यक्तिगत डेटा जस्तै क्रेडिट कार्ड नम्बरहरू र पासवर्डहरू समावेश गर्दछ।"</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"स्थिति पट्टिलाई अक्षम वा संशोधित गर्नुहोस्"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"स्थिति पट्टि असक्षम पार्न वा प्रणाली आइकनहरू थप्न र हटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"स्थिति पट्टि"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"अनुप्रयोगलाई स्थिति पट्टि हुन अनुमति दिन्छ।"</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"स्थिति पट्टिलाई विस्तृत/सङ्कुचित गर्नुहोस्"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"अनुप्रयोगलाई स्थिति पट्टि विस्तार वा संकुचन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"बहिर्गमन कलहरूलाई अर्को मार्ग दिनुहोस्"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"बहिर्गमन कलहरूको प्रशोधन गर्न र डायल गरिने नम्बर परिवर्तन गर्न अनुप्रयोगलाई अनुमति दिन्छ।  यो अनुमतिले अनुप्रयोगलाई मोनिटर गर्न, अन्यत्र पठाउन वा बाहिर जाने कलहरूलाई रोक्न दिन्छ।"</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"पाठ सन्देशहरू (SMS) प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"अनुप्रयोगलाई SMS सन्देशहरू प्राप्त गर्न र प्रक्रिया गर्न अनुमति दिन्छ। यसको मतलब अनुप्रयोगले तपाईंको उपकरणमा पठाइएको सन्देशहरू तपाईंलाई नदेखाईनै मोनिटर गर्न वा मेटाउन सक्दछ।"</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"पाठ सन्देश (MMS) प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"अनुप्रयोगलाई MMS सन्देशहरू प्राप्त गर्न र प्रकृया गर्न अनुमति दिन्छ। यसको मतलब अनुप्रयोगले तपाईंको उपकरणमा पठाइएको सन्देशहरू तपाईंलाई नदेखाईनै मोनिटर गर्न वा मेटाउन सक्दछ।"</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"आकस्मिक प्रसारणहरू प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"अनुप्रयोगलाई आपतकालीन प्रसारण सन्देशहरू प्राप्त गर्न र प्रक्रिया गर्न अनुमति दिन्छ। यो अनुमति प्रणाली अनुप्रयोगहरूमा मात्र उपलब्ध छ।"</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"सेल प्रसारित सन्देशहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"तपाईंको उपकरणद्वारा प्राप्त सेल प्रसारण सन्देशहरू अनुप्रयोगलाई पढ्न अनुमति दिन्छ। सेल प्रसारण चेतावनीहरू केही स्थानहरूमा तपाईंलाई आपतकालीन गतिविधिहरूको बारेमा सचेत गराउन गरिएका छन्। खराब अनुप्रयोगहरूले एउटा आपतकालीन सेल प्रसारण प्राप्त गर्दछ जब तपाईंको उपकरणको प्रदर्शन वा अपरेशनको साथ हस्तक्षेप गर्न सक्दछन्।"</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS सन्देशहरू पठाउनुहोस्"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"अनुप्रयोगलाई SMS सन्देशहरू पठाउन अनुमति दिन्छ। यसले अप्रत्यासित चार्जहरूको परिणाम दिन सक्दछ। खराब अनुप्रयोगहरूले तपाईंको पुष्टि बिना सन्देशहरू पठाएर तपाईंको पैसा खर्च गराउन सक्दछ।"</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"प्रतिक्रिया-मार्फत-सन्देश घटनाहरू पठाउनुहोस्"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"अनुप्रयोगलाई आगत कलहरूको लागि प्रतिक्रिया-मार्फत-सन्देश घटनाहरूलाई अन्य सन्देश पठाउने अनुप्रयोगहरूमा अनुरोधहरू पठाउन अनुमति दिन्छ।"</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"तपाईंका पाठ सन्देशहरू (SMS वा MMS) पढ्नुहोस्"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"तपाईँको ट्याब्लेट वा SIM कार्डमा भण्डारण भएका SMS सन्देशहरूलाई पढ्न अनुप्रयोगलाई अनुमति दिन्छ। यसले अनुप्रयोगलाई विषयवस्तु वा गोपनीयतालाई वेवास्ता गर्दै सबै SMS सन्देशहरू पढ्ने अनुमति दिन्छ।"</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"तपाईँको फोन वा SIM कार्डमा भण्डारण भएका SMS सन्देशहरूलाई पढ्न अनुप्रयोगलाई अनुमति दिन्छ। यसले सबै SMS सन्देशहरूलाई पढ्नको लागि सामग्री वा विश्वसनियता बिना नै अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"तपाईँका पाठ सन्देशहरू सम्पादन गर्नुहोस् (SMS वा MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"अनुप्रयोगलाई तपाईंको ट्याब्लेट वा SIM कार्डमा भण्डार गरिएका SMS सन्देशहरू लेख्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले तपाईंको सन्देशहरू मेटाउन सक्दछ।"</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"तपाईँको फोन वा SIM कार्डमा भण्डारण भएका SMS सन्देशहरूलाई लेख्‍नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले सायद तपाईँको सन्देशहरू मेटाउन सक्छन्।"</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"पाठ सन्देशहरू (WAP) प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"WAP सन्देशहरू प्राप्त गर्न र प्रशोधन गर्न अनुप्रयोगलाई अनुमति दिन्छ। यो अनुमतिमा मोनिटर गर्ने वा तपाईँलाई पठाइएका सन्देशहरू तपाईँलाई नदेखाई मेट्ने क्षमता समावेश हुन्छ।"</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"चलिरहेका अनुप्रयोगहरू पुनःबहाली गर्नुहोस्"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"वर्तमानमा र भरखरै चलिरहेका कार्यहरू बारेको सूचना पुनःबहाली गर्न अनुप्रयोगलाई अनुमित दिन्छ। यसले उपकरणमा प्रयोग भएका अनुप्रयोगहरूको बारेमा सूचना पत्ता लगाउन अनुप्रयोगलाई अनुमति दिन सक्छ।"</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"प्रयोगकर्ताहरू तर्फ अन्तर्क्रिया गर्नुहोस्"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"अनुप्रयोगलाई उपकरणमा विभिन्न प्रयोगकर्ताहरू मार्फत कार्यहरू गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले यो प्रयोगकर्ताहरू बिच सुरक्षा बिथोल्न प्रयोग गर्न सक्ने छन्।"</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"कुराकानी प्रयोगकर्ताहरू बिच अन्तर्क्रिया गर्न पूर्ण अनुमति"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"प्रयोगकर्तासँगको कुराकानी सबै सम्भावनालाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"प्रयोगकर्ताहरू व्यवस्थापन गर्नुहोस्"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"अनुप्रयोगलाई उपकरणमा, प्रश्न, सिर्जना र मेटाइसहित प्रयोगकर्ताहरूको प्रबन्ध गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"चलिरहेका अनुप्रयोगहरूको विवरण पुनःबहाली गर्नुहोस्"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"वर्तमानमा र भरखरै चलिरहेका कार्यहरूको बारेमा विस्तृत सूचना पुनःबहाली गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले अन्य अनुप्रयोगहरू बारेको निजी सूचना पत्ता लगाउन सक्छ।"</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"चलिरहेका अनुप्रयोगहरूलाई पुनःक्रम गराउनुहोस्"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"कामहरूलाई अग्रभाग र पृष्ठभूमिमा सार्न अनुप्रयोगलाई अनुमति दिन्छ। अनुप्रयोगले यो तपाईँको इनपुट बिना नै गर्न सक्छ।"</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"चालु भइरहेका अनुप्रयोगहरू रोक्नुहोस्"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"कामहरू हटाउन र उनीहरूको अनुप्रयोगहरूलाई बन्द गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले अन्य अनुप्रयोगहरूको व्यवहारलाई अबरोध गर्न सक्छन्।"</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"activity stacks को प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"अनुप्रयोगलाई अन्य अनुप्रयोगहरू चल्ने activity stacks लाई थप्न, हटाउन र परिवर्तन गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले अन्य अनुप्रयोगहरूको व्यवहारलाई विघटन गर्न सक्छन्।"</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"कुनै गतिविधि सुरु गर्नुहोस्"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"अनुमति सुरक्षा वा निर्यात अवस्थालाई वास्ता नगरिकन कुनै पनि कार्य सुरु गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"स्क्रिन अनुकूलता सेट गर्नुहोस्"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"अन्य अनुप्रयोहरूको स्क्रिन मिल्दो मोडलाई नियन्त्रण गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। अन्य अनुप्रयोहरूको व्यवहार खराब अनुप्रयोगहरूले टुटाउन सक्छन्।"</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"अनुप्रयोग डिबग गर्ने सक्षम गर्नुहोस्"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"अनुप्रयोगलाई अन्य अनुप्रयोगको लागि डिबग गर्ने प्रक्रिया चालु गर्ने अनुमति दिन्छ। खराब अनुप्रयोगले अरू अनुप्रयोगहरू समाप्त गर्न यसको उपयोग गर्न सक्दछ।"</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"प्रणाली प्रदर्शन सेटिङहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"वर्तमान कन्फिगरेसन जस्तै लोक्याल वा सबैतिर फन्ट आकार बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"कार मोड सक्षम गर्नुहोस्"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"कार मोडलाई सक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"अनुप्रयोगहरू बन्द गर्नुहोस्"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"अनुप्रयोगलाई अन्य अनुप्रयोगहरूको पृष्ठभूमि प्रक्रियाहरू बन्द गर्न अनुमति दिन्छ। यसले अन्य अनुप्रयोगहरूलाई चल्नबाट रोक्न सक्दछ।"</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"अन्य अनुप्रयोगहरू दबाबमा रोक्नुहोस्"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"अन्य अनुप्रयोगहरूलाई बलपूर्वक बन्द गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"अनुप्रयोग बन्द गर्न बल गर्नुहोस्"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"अग्रभागमा भएको कुनै गतिविधिलाई जबरजस्ती बन्द गर्न र फर्केर जानका लागि अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाइ कहिल्यै आवश्यकता पर्दैन।"</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"प्रणालीको आन्तरिक स्थिति प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"प्रणालीको आन्तरिक स्थिति पुनःबहाली गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले उनीहरूलाई सामान्यतः कहिल्यै नचाहिने व्यापक विविधताको निजी र सुरक्षित सूचना पुनःबहाली गर्न सक्छन्।"</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"स्क्रिन सामग्री बहाली गर्नुहोस्"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"सक्रिय विन्डोको विषयवस्तुलाई पुनःबहाली गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले पुरै विन्डोको विषयवस्तु पुनःबहाली गर्न सक्छन् र पासवर्डहरूबाहेक यसका सबै पाठको जाँच गर्न सक्छन्।"</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"पहुँचतालाई अस्थायी सक्षम गर्नुहोस्"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"अनुप्रयोगलाई अस्थायी रूपमा उपकरणमाथि पहुँच राख्न अनुमति दिन्छ। खराब अनुप्रयोगले उपयोगकर्ताको सहमति बिना नै पहुँचलाई सक्षम गर्न सक्दछ।"</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"विन्डो जानकारी बहाली गर्नुहोस्"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"अनुप्रयोगलाई विन्डो व्यवस्थापकबाट विन्डोहरूको बारेमा जानकारी प्राप्त गर्न अनुमति दिन्छ। खराब अनुप्रयोगले आन्तरिक प्रणाली उपयोगको लागि निमित्त जानकारी पनि प्राप्त गर्न सक्दछ।"</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"घटनाहरू छान्नुहोस्"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"इन्पुट फिल्टर जुन सबै प्रयोगकर्ता घटनाहरू पठाइनुभन्दा पहिले फिल्टर गर्नेलाई दर्ता गर्न अनुप्रयोगलाई अनुमति दिन्छ। प्रयोगकर्ताको हस्तक्षेप बिना नै UI प्रणाली खराब अनुप्रयोगले नियन्त्रण गर्न सक्छन्।"</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"प्रदर्शन बढाउनुहोस्"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"अनुप्रयोगलाई प्रदर्शनको सामग्री आवर्धन गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले प्रदर्शन सामग्री संक्रमण गर्न सक्दछन् जसले उपकरणलाई अनुपयोगी बनाउँदछ।"</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"आंशिक बन्द"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"गतिविधि व्यवस्थापकलाई बन्द गर्ने अवस्थामा राख्छ। पूर्ण बन्द गर्ने काम गर्दैन।"</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"अनुप्रयोग स्विचहरू जोगाउनुहोस्"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"अन्य अनुप्रयोगमा स्विच गर्नबाट प्रयोगकर्ताहरूलाई रोक्छ।"</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"वर्तमान अनुप्रयोगको जानकारी प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"स्क्रिनको अग्र भागमा हालको अनुप्रयोग र सेवाहरूका बारे निजी जानकारी निकाल्न बाहकलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"सबै अनुप्रयोग सुरुवात गर्ने निरीक्षण र नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"अनुप्रयोगलाई कसरी प्रणाली सुरुवात गतिहरू मोनिटर गर्न र नियन्त्रण गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले प्रणालीमा पूर्ण सहमत गर्न सक्दछ। यो अनुमति केवल विकासको लागि आवश्यक छ, साधारण प्रयोगको लागि कहिले होइन।"</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"प्याकेज हटाइएको प्रसारणलाई पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"अनुप्रयोगलाई सूचना प्रसारण गर्न अनुमति दिन्छ जुन अनुप्रयोग प्याकेज हटाइएको छ। खराब अनु्प्रयोगहरूले यो कुनै अन्य चालु अनु्प्रयोग बन्द गर्न प्रयोग गर्न सक्दछन्।"</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS-प्राप्त प्रसारण पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"त्यो एउटा SMS सन्देशबाट प्राप्त भएको सूचनालाई प्रसारण गर्न अनुप्रयोगलाई अनुमति दिन्छ। आउँदै गरेको SMS सन्देशहरूलाई जालसाजी गर्न सायद खराब भएका अनुप्रयोगहरूले यसलाई प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH-प्राप्त प्रसारण पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"अनुप्रयोगलाई सूचना प्रसारण गर्न अनुमति दिन्छ जुन एउटा WAP PUSH सन्देश प्राप्त भएको छ। खराब अनुप्रयोगहरूले यो MMS सन्देश बिगार्न वा मौन तरिकाले कुनै पनि वेबपृष्ठको सामग्री खराब विभेदहरूसँग बदल्न प्रयोग गर्न सक्दछन्।"</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"चालु प्रशोधनहरूको सङ्ख्या सीमति गर्नुहोस्"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"अनुप्रयोगलाई चालु हुने प्रक्रियाहरूको अधिकतम संख्या नियन्त्रण गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"पृष्ठभूमि अनुप्रयोगहरू बन्द गर्न दबाब दिनुहोस्"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"अनुप्रयोगलाई गतिविधिहरू सधैँ समाप्त भयो कि भएन जब कि जति सक्दो तिनीहरू पृष्ठभूमिमा जान्छन् भन्ने नियन्त्रण गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"ब्याट्रि तथ्याङ्हरू पढ्नुहोस्"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"वर्तमान थोरै ब्याट्री प्रयोग डेटा पढ्नको लागि एक अनुप्रयोगले अनुमति दिन्छ। जुन अनुप्रयोग तपाईँले प्रयोग गरीरहनुभएको छ त्यस्को बारेका पुर्ण जानकारी प्राप्त गर्न सायद अनुप्रयोगले अनुमति दिन्छ।"</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"ब्याट्रि तथ्याङ्कलाई परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"अनुप्रयोगलाई संकलित ब्याट्रि तथ्याङ्कहरू परिमार्जन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"अनुप्रयोग संचालनका तथ्याङ्कहरू पुनःबहाली गर्नुहोस्"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"सङ्कलन गरिएका अनुप्रयोग संचालन तथ्याङ्लाई पुनः प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगबाट प्रयोगको लागि होइन।"</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"अनुप्रयोग संचलान तथ्याङ्कहरूलाई परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"सङ्कलन गरिएका अनुप्रयोग संचालन तथ्याङ्लाई परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगबाट प्रयोगको लागि होइन।"</string>
-    <string name="permlab_backup" msgid="470013022865453920">"प्रणाली ब्यकअप नियन्त्रण गर्नुहोस् र पुनः बहाली गर्नुहोस्"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"प्रणालीको जगेडा नियन्त्रण गर्न र पुनःप्राप्तिको संयोजन गर्न अनुप्रयोगलाई अनुमित दिन्छ। सामान्य अनुप्रयोगद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"पूर्ण जगेडा गर्न वा प्रक्रिया पुनःबहाली गर्न निश्चित गर्नुहोस्"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"UI को पूर्ण जगेडा निश्चिन्तता सुरु गर्नका लागि अनुप्रयोगलाई अनुमति दिन्छ। कुनै अनुप्रयोगबाट प्रयोग नगरिने।"</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"अनधिकृत बिन्डोहरू प्रदर्शन गर्नुहोस्"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"अनुप्रयोगलाई विन्डोहरू सिर्जना गर्न अनुमति दिन्छ जुन आन्तरिक प्रणाली प्रयोगकर्ता इन्टरफेसद्वारा प्रयोग गर्न अभिप्रेरित छ। साधारण अनुप्रयोगहरूद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"अन्य अनुप्रयोगहरूमा चित्र कोर्नुहोस्"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"अरू अनुप्रयोगहरूमाथि वा प्रयोगकर्ता इन्टरफेसका भागहरूमा चित्र कोर्न अनुप्रयोगलाई अनुमति दिन्छ। तिनीहरूले कुनै अनुप्रयोगमा इन्टरफेको तपाईँको प्रयोगसँग हस्तक्षेप गर्न वा तपाईँ अन्य अनुप्रयोगहरूमा के देखिरहनु भएको छ भन्ने सोच्न हुन्छ भन्ने बदल्न सक्छन्।"</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"ग्लोबल सजीविकरण गति परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"विश्वब्यापि सजीविकरण(द्रुत वा ढिला सजीविकरणहरू) लाई कुनै पनि समय परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"अनुप्रयोग टोकनहरू प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"अनुप्रयोगलाई आफ्ना टोकनहरू सिर्जना गर्न र उनीहरूको साधारण Z-क्रमाङ्कन बाइपास गरेर प्रबन्ध गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिल्यै पनि आवश्यक नहुन सक्दछ।"</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"स्क्रिन फ्रिज गर्नुहोस्"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"अनुप्रयोगलाई पूर्ण-स्क्रिन संक्रमणको लागि अस्थायी रूपमा स्क्रिन स्थिर गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"कुञ्जीहरू र नियन्त्रण बटनहरू थिच्नुहोस्"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"यसका आफ्ना इनपुट घटनाहरू (कि थिचाइहरू, आदि) अन्य अनुप्रयोगहरूलाई वितरण गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई ट्याब्लेटसम्म लैजान प्रयोग गर्न सक्छन्।"</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"यस्को आफ्नै निवेश घटनाहरू (कि थिचाइहरू, आदि.) अन्य अनुप्रोयगहरूलाई पु्र्‍याउन अनुप्रयोगलाई अनुमति दिन्छ। फोनलाई हस्तक्षेप गर्न यसको प्रयोग खराब अनुप्रयोगहरूले गर्न सक्छन्।"</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"तपाईंले के टाइप गर्नुहुन्छ र के कार्यहरू लिनुहुन्छ रेकर्ड गर्नुहोस्"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"अर्को अनुप्रयोग(जस्तै पासवर्ड टाइप गराइ)सँग अन्तर्क्रिया गरेको बेला पनि तपाईँले थिचेका किहरूलाइ हेर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिल्यै आवश्यक हुँदैन।"</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"एउटा निवेश तरिकामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"एउटा निवेश तरिकाको उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि समाती राख्नेलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"एउटा पहुँच सेवासँग जोड्नुहोस्"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"एक पहुँच सेवाको उच्च स्तरको कुराकानीलाई पक्का गर्नको लागि समाती राख्नेले अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"एउटा प्रिन्ट सेवासँग जोड्नुहोस्"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"एउटा प्रिन्ट सेवाको उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि प्रयोगकर्तालाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"सबै प्रिन्ट कार्यहरूको पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"प्रयोगकर्तालाई अन्य अनुप्रयोगद्वारा निर्मित प्रिन्ट कार्यहरू पहुँच गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC सेवामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"NFC कार्डहरू इमुलेट गर्ने अनुप्रयोगहरूलाई बाँध्नका लागि होल्डरलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूका लागि कहिल्यै पनि आवश्यक पर्दैन।"</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"एउटा पाठ सेवासँग संगठित हुनुहोस्"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"एउटा पाठ सेवाको (उदाहरण शब्द परीक्षणसेवा) उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि समाती राख्नेलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN सेवासँग बाँध्नुहोस्।"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"एक Vpn सेवाको उच्च स्तरको कुराकानीलाई पक्का गर्नको लागि समाती राख्नेले अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"एउटा वालपेपरमा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"वालपेपरको माथिल्लो स्तरको इन्टरफेसमा बाँध्न धारकलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्दैन।"</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"एउटा विजेट सेवासँग संगठित हुनुहोस्"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"एउटा विजेट सेवाको उच्च स्तरको इन्टरफेसलाई पक्का गर्नको लागि समाती राख्नेलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"उपकरणको प्रबन्धसँग अन्तरक्रिया गर्नुहोस्"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"उपकरण प्रशासक लाई आशय पठाउन समाती राख्‍नेलाई अनुमति दिन्छ। साधारण अनुप्रयोहरूको लागि कहिल्यै पनी आवश्यक पर्दैन।"</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"एउटा उपकरण व्यवस्थापक थप गर्नुहोस् वा हटाउनुहोस्"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"होल्डरलाई सक्रिय उपकरण व्यवस्थापकहरू थप गर्न वा हटाउन अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिल्यै पनि आवश्यक नहुन सक्दछ।"</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"स्क्रिन अभिमुखिकरण परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"अनुप्रयोगलाई कुनै पनि समयमा स्क्रिनको परिक्रमण परिवर्तन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूको लागि कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"सङ्केतक गति बदल्नुहोस्"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"कुनै पनि समयमा माउस परिवर्तन गर्न वा ट्राकप्याड संकेतकको गति बदल्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूको लागि कहिल्यै नचाहिन सक्छ।"</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"किबोर्ड लेआउट परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"किबोर्ड लेआउटलाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई सायद कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"Linux संकेतहरू अनुप्रयोगलाई पठाउनुहोस्"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"सबै चलिरहेका प्रक्रियाहरूमा पठाइएका संकेतलाई अनुरोध गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"अनुप्रयोगहरू जहिले पनि चल्ने बनाउनुहोस्"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"यसको आफ्नै मेमोरीमा दृढ भएकोको अंश बनाउनको लागि अनुप्रयोगलाई अनुमति दिन्छ। ट्याब्लेटलाई ढिलो गराउँदै गरेका अन्य अनुप्रयोगहरूलाई सीमित मात्रामा यसले मेमोरी उपलब्ध गराउन सक्छ।"</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"अनुप्रयोगलाई मेमोरीमा आफैंको निरन्तरको अंश बनाउन अनुमति दिन्छ। यसले फोनलाई ढिला बनाएर अन्य अनुप्रयोगहरूमा मेमोरी SIMित गर्न सक्दछन्।"</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"अनुप्रयोगहरू मेटाउनुहोस्"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"अनुप्रयोगलाई एन्ड्रोइड प्याकेजहरू मेटाउन अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई महत्त्वपूर्ण अनुप्रयोगहरू मेटाउन प्रयोग गर्न सक्दछन्।"</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"अन्य अनुप्रयोगहरूको डेटा मेटाउनुहोस्"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"प्रयगकर्ता डेटा हटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"अन्य अनुप्रयोगहरूको क्यासहरू मेटाउनुहोस्"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"अनुप्रयोगलाई क्यास फाइलहरू मेटाउन अनुमति दिन्छ।"</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"अनुप्रयोग भण्डारण ठाउँको मापन गर्नुहोस्"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"अनुप्रयोगलाई यसको कोड, डेटा, र क्यास आकारहरू पुनःप्राप्त गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"अनुप्रयोगहरू सिधै स्थापना गर्नुहोस्"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"नयाँ स्थापना गर्न वा एन्ड्रोइड प्याकेजहरू अद्यावधिक गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई मनपरी रूपमा शक्तिशाली अनुमतिहरू भएका नयाँ अनुप्रयोगहरू थप्न प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"सबै अनुप्रयोग क्यास डेटा मेटाउनुहोस्"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"अन्य अनुप्रयोगहरूको क्यास डाइरेक्टरीहरूमा फाइलहरू हटाएर ट्याब्लेटको भण्डारण खाली गर्न अनुप्रयोगहरूलाई अनुमति दिन्छ। उनीहरूले आफ्नो डेटा पुनःबहाली गर्न पर्ने हुनाले यसले अन्य अनुप्रयोगहरूलाई स्टार्ट हुन निकै ढिलो गराउन सक्छ।"</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"अनुप्रयोगलाई अन्य अनुप्रयोगहरूको क्यास डाइरेक्टरीमा फाइलहरू मेटाएर फोन भण्डारण खाली गर्न अनुमति दिन्छ। यसले अन्य अनुप्रयोगहरूलाई बढी ढिला सुरु गराउँछ किनकि तिनीहरूले आफ्नो डेटा पुनःप्राप्ति गर्न आवश्यक पर्ने हुन्छ।"</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"अनुप्रयोग स्रोतहरू सार्नुहोस्"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"अनुप्रयोग स्रोतहरू आन्तरिकबाट बाह्य मेडियामा र विपरितमा लैजान अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"संवेनशील लग डेटा पढ्नुहोस्"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"प्रणालीका विभिन्न फाइलहरूबाट पढ्न अनुप्रयोगलाई अनुमति दिन्छ। सम्भाव्य रूपमा व्यक्तिगत र निजी सूचनासहित तपाईँ ट्याब्लेटसँग के गरिरहनु भएको छ भन्ने बारेको साधारण सूचना पत्ता लगाउन यसलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"प्रणालीका विभिन्न फाइलहरूबाट पढ्न अनुप्रयोगलाई अनुमति दिन्छ। सम्भाव्य रूपमा व्यक्तिगत र निजी सूचनासहित तपाईँ फोनसँग के गरिरहनु भएको छ भन्ने बारेको साधारण सूचना पत्ता लगाउन यसलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"पछाडि बजाउनको लागि कुनै मिडिया प्रयोग गर्नुहोस्"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"अनुप्रयोगलाई प्लेब्याक डिकोड गर्न कुनै पनि स्थापित मिडिया डिकोडर प्रयोगको लागि अनुमति दिन्छ।"</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"diag को स्वामित्वमा रहेको संसाधनहरूमा पढ्नुहोस्/लेख्नुहोस्"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"अनुप्रयोगलाई diag समूहद्वारा स्वामित्व प्राप्त कुनै पनि स्रोतहरूमा पढ्न र लेख्न अनुमति दिन्छ; उदाहरणको लागि, /dev  मा फाइलहरू। यसले सम्भवतः प्रणाली स्थिरता र सुरक्षामा प्रभाव पार्न सक्दछ। यो केवल निर्माता वा संचालकद्वारा हार्डवेयर-निर्दिष्टको लागि प्रयोग हुन सक्दछ।"</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"अनुप्रयोग अंशहरू सक्षम वा अक्षम गर्नुहोस्"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"अन्य अनुप्रयोग सक्षम छ वा छैन भन्ने कुराको परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। महत्त्वपूर्ण फोन सक्षमता खराब अनुप्रोगहरूले असक्षम पार्न प्रयोग गर्न सक्छन्। यो अनुमतिसँगै होसियारी अपनाउनु पर्छ, अनुप्रयोग विषय सूचीमा प्रयोग नहुने, असंगत, अस्थिर अवस्था भएको प्राप्त हुने सम्भावना हुन्छ।"</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"अन्य अनुप्रयोगको अंश सक्षम छ वा छैन भन्नेमा परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। महत्त्वपूर्ण फोन सक्षमता खराब अनुप्रोगहरूले असक्षम पार्न प्रयोग गर्न सक्छन्। यो अनुमतिसँगै होसियारी अपनाउनु पर्छ, अनुप्रयोग विषय सूचीमा प्रयोग नहुने, असंगत, अस्थिर अवस्था भएको प्राप्त हुने सम्भावना हुन्छ।"</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"अनुमतिहरू प्रदान गर्नुहोस् वा रद्द गर्नुहोस्"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"अनुप्रयोगलाई यो वा अन्य अनुप्रयोगहरूको लागि निर्दिष्ट स्वीकृतिहरू प्रदान गर्न वा रद्द गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले यो तपाईंले अनुमति प्रदान नगर्नुभएका सुविधाहरूमा पहुँच गर्न सक्दछन्।"</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"विशेष रूपमा मान्य अनुप्रयोगहरू सेट गर्नुहोस"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"तपाईँको मनपर्ने अनुप्रयोगलाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले चलिरहेका ती अनुप्रयोहरूलाई चुपचाप रूपमा परिवर्तन गर्न सक्छन्, तपाईँबाट निजी डेटा संकलन गर्नको लागि भइरहेको अनुप्रयोगलाई स्पुफ गर्न सक्छन्।"</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"प्रणाली सेटिङहरू परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"प्रणालीका सेटिङ डेटालाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले सायद तपाईँको प्रणालीको कन्फिगरेसनलाई क्षति पुर्‍याउन सक्छन्।"</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"सुरक्षित प्रणाली सेटिङहरू परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"प्रणालीको सुरक्षित सेटिङ डेटा परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूको प्रयोगको लागि होइन्।"</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google सेवा नक्सा परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"अनुप्रयोगलाई Google सेवा नक्साहरू परिमार्जन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूद्वाराको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"स्टार्टअपमा चलाउनुहोस्"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"आनुप्रयोगलाई प्रणाली बुट प्रक्रिया पूर्ण हुने बितिकै आफैलाई सुरु गर्ने अनुमति दिन्छ। यसले ट्याब्लेट सुरु गर्नमा ढिला गर्न सक्दछ र अनुप्रयोगलाई समग्रमा ट्याब्लेट सधैँ चालु गरेर ढिला बनाउँदछ।"</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"अनुप्रयोगलाई प्रणाली बुट गरी सकेपछि जति सक्दो चाँडो आफैंमा सुरु गर्न अनुमति दिन्छ। यसले फोन सुरु गर्नमा ढिला गर्न सक्दछ र अनप्रयोगलाई समग्रमा फोन सधैँ चालु गरेर ढिला बनाउँदछ।"</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"स्टिकि प्रसारण पठाउनुहोस्"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"औपचारिक प्रसारणलाई पठाउनको लागि एउटा अनुप्रयोगलाई अनुमति दिन्छ, जुन प्रसारण समाप्त भएपछि बाँकी रहन्छ। अत्याधिक प्रयोगले धेरै मेमोरी प्रयोग गरेको कारणले ट्याब्लेटलाई ढिलो र अस्थिर बनाउन सक्छ।"</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"औपचारिक प्रसारणलाई पठाउनको लागि एक अनुप्रयोगलाई अनुमति दिन्छ, जुन प्रसारण समाप्त भएपछि बाँकी रहन्छ। अत्याधिक प्रयोगले धेरै मेमोरी प्रयोग गरेको कारणले फोनलाई ढिलो र अस्थिर बनाउन सक्छ।"</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"तपाईँका सम्पर्कहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"अनुप्रयोगलाई निर्दिष्ट व्यक्तिगतसँग अन्य तरिकाहरूबाट कल गर्नु भएका, इमेल गर्नु भएका वा अन्तर्क्रिया गर्नुभएका आवृतिसहितको तपाईंको ट्याब्लेटमा भण्डारण गरिएका सम्पर्कहरूको डेटा पढ्न अनुमति दिन्छ। यो अनुमतिले तपाईंको सम्पर्क डेटा बचत गर्न अनुमति दिन्छ, र खराब अनुप्रयोगहरूले तपाईंको जानकारी बिना सम्पर्क डेटा साझेदारी गर्न सक्दछन्।"</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"तपाईँले विशेष व्यक्तिहरूसँग अर्को तरिकाबाट कल गर्नुभएका, इमेल गर्नुभएका वा संचार गर्नुभएका आवृतिसहित तपाईँको फोनमा भण्डारण भएका डेटाको बारेमा पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यो अनुमतिले अनुप्रयोगलाई तपाईँको सम्पर्क डेटा बचत गर्नको लागि अनुमति दिन्छ, र तपाईँको ज्ञान बिना नै खराब अनुप्रयोगहरूले सायद सम्पर्क डेटा साझेदारी गर्न सक्छन्।"</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"तपाईँका सम्पर्कहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"अन्य तरिकाका आवृतिहरूसँग जुन तपाईँले कल, इमेल, वा विशेष सम्पर्क गर्नुभएकासहित तपाईँको ट्याब्लेटमा भण्डारण भएका सम्पर्कहरूको बारेको डेटालाई परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यस अनुमतिले सम्पर्क डेटालाई मेटाउनको लागि अनुमति दिन्छ।"</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"तपाईँले बारम्बार कल गरेका, इमेल गरेका, वा विशेष सम्पर्कहरूसँग सञ्चार गरेका सहित तपाईँको फोनमा भण्डारण गरेका तपाईँका सम्पर्कहरू परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। यो अनुमतिले अनुप्रयोगलाई सम्पर्क डेटा मेटाउन दिन्छ।"</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"कल लग पढ्नुहोस्"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"अनुप्रयोगलाई तपाईँको ट्याब्लेटको कल लग, आगमन र बहिर्गमन कलहरू बारे डेटा सहितको कल लग पढ्न अनुमति दिन्छ। यस अनुमतिले अनुप्रयोगहरूलाई तपाईँको कल लग डेटाहरूको बचत गर्न अनुमति दिन्छ, र खराब अनुप्रयोगहरूले तपाईँको जानकारी बिना नै यो कल लग डेटालाई अरूसँग साझेदार गर्न सक्छन्।"</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"भित्र आउने र बाहिर जाने कलहरूसहित तपाईँको फनको कल लग पढ्न अनुप्रयोगलाई अनुमति दिन्छ।  यो अनुमतिले अनुप्रयोगहरूलाई तपाईँका कल लग डेटा बचत गर्न दिन्छ र खराब अनुप्रयोगहरूले तपाईँले थाहै नपाई कल लग डेटालाई साझेदारी गर्न सक्छन्।"</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"कल लग लेख्‍नुहोस्"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"आगमन तथा बहर्गमन डेटासहित तपाईँको ट्याब्लेटको कल लगको परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई तपाईँको कल लग परिमार्जन गर्न वा मेटाउन प्रयोग गर्न सक्छन्।"</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"अनुप्रयोगलाई तपाईंको फोनको आउने र बाहिर जाने कलहरूको बारेको डेटा सहित कल लग परिमार्जन गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले यसलाई तपाईंको कल लग मेटाउन वा परिमार्जन गर्न प्रयोग गर्न सक्दछ।"</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"तपाईँको आफ्नै सम्पर्क कार्ड पढ्नुहोस्"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"अनुप्रयोगलाई तपाईंको उपकरणमा भण्डारण गरिएका व्यक्तिगत प्रोफाइल जानकारी पढ्न अनुमति दिन्छ, जस्तै तपाईंको नाम र सम्पर्क जानकारी। यसको मतलब अनुप्रयोगले तपाईंलाई पहिचान गर्न सक्दछ र तपाईंको प्रोफाइल जानकारी अरूलाई पठाउन सक्दछ।"</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"तपाईँको आफ्नै सम्पर्क कार्ड परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"तपाईँको उपकरणमा भण्डार भएको व्याक्तिगत प्रोफाइल जानकारी, जस्तै तपाईँको नाम वा सम्पर्क जानकारीलाई परिवर्तन गर्न वा थप्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यसको मतलब अन्य अनुप्रयोगले तपाईँलाई चिन्न सक्छन् र सायद अन्यलाई तपाईँको प्रोफाइल जानकारी पठाउन सक्छन्।"</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"तपाईंको सामाजिक स्ट्रिम पढ्नुहोस्"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"तपाईँ र तपाईँका साथीहरूबाट सामाजिक अपडेटलाई पहुँच र सिंक गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। जानकारी साझेदारी गर्दा सावधान रहनुहोस्  -- समाजिक नेटवर्कहरूमा तपाईँ र तपाईँको साथीको  बिचमा भएका संचारलाई पढ्न विश्वासनीयता बेगरै यसले अनुप्रयोगलाई अनुमति दिन्छ। नोट: यो अनुमति बलपूर्वक सबै सामाजिक नेटवर्कहरूमा सायद नगर्न सकिन्छ।"</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"तपाईँको सामाजिक प्रवाहमा लेख्‍नुहोस्"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"अनुप्रयोगलाई तपाईंको साथीहरूबाट सामाजिक अपडेटहरू प्रदर्शन गर्न अनुमति दिन्छ। जानकारी साझेदारी गर्ने बेलामा होशियार रहनुहोस् -- यसले अनुप्रयोगलाई सन्देशहरू निर्माण गर्न अनुमति दिन्छ जुन साथीबाट आएको देखिन्छ। टिप्पणी: यो अनुमति सबै सामाजिक सञ्जालहरूमा लागू नहुन सक्दछ।"</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"गोप्य जानकारी र पात्रो घटनाहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"अनुप्रयोगलाई तपाईंको ट्याब्लेटमा भण्डारण गरिएका ती साथीहरू वा सहयोगीहरू सहितको पात्राका कार्यक्रमहरू पढ्न अनुमति दिन्छ। यसले गोपनीयता वा संवेदनशीलता बिना पनि अनुप्रयोगलाई तपाईंको पात्राका डेटा साझेदारी गर्न वा बचत गर्न अनुमति दिन्छ।"</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"ती साथीहरू वा सहकर्मीहरूसहित सबै पात्रो घटनाहरू तपाईँको ट्याब्लेटमा भण्डारण भएकालाई पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। तपाईँको पात्रो डेटा यसले सायद सेयर गर्न वा सुरक्षित गर्नको लागि विश्वासनियता वा सम्वेदनशीलता बिना नै अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"पात्रो घटनाहरू थप्नुहोस् वा परिमार्जन गर्नुहोस् र मालिकको ज्ञान बिना नै पाहुनाहरूलाई इमेल पठाउनुहोस्"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"ती साथीहरू वा सहकर्मीहरूसहितका घटनाहरू जसलाई तपाईँले आफ्नो ट्याब्लेटमा परिमार्जन गर्न सक्ने अनुमति अनुप्रयोगलाई दिन्छ। यसले अनुप्रयोगलाई सन्देशहरू जुन पात्राको मालिकहरूबाट आएका देखिनेलाई पठाउने वा मालिकहरूको ज्ञान बेगर घटनालाई परिमार्जन गर्ने अनुमित दिन्छ।"</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"ती साथीहरू वा सहकर्मीहरूसहित तपाईँको फोनका घटनाहरू जसलाई थप्न, हटाउन र परिवर्तन गर्न  अनुप्रयोगलाई अनुमति दिन्छ। पात्रो मालिकबाट देखा परेका वा मालिकको ज्ञान बिना परिवर्तन भएका घटनाहरू सन्देश पठाउन यसले अनुप्रयोगलाई अनुमति दिन सक्छ।"</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"परीक्षणको लागि स्थान स्रोतहरू मक गर्नुहोस्"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"परीक्षणको लागि मक स्थान स्रोतहरू सिर्जना गर्नुहोस् वा नयाँ स्थान प्रदायक स्थापना गर्नुहोस्। यसले अनुप्रयोगलाई स्थानमा ओभरराइड गर्दछ र/वा स्थिति अन्य स्थान स्रोतहरू जस्तै GPS वा स्थान प्रदायकबाट फर्काइएका।"</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"अधिक स्थान प्रदायक आदेशहरू पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"थप स्थान प्रदायक कमाण्डहरू सम्म पहुँच पुर्‍याउन अनुप्रयोगले अनुमति दिन्छ। यसले अनुप्रयोगलाई सायद जीपीएसको वा अन्य स्थान सेवाहरूको कार्य सँग हस्तक्षेप गर्नको लागि यसलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"एउटा स्थान प्रदाता स्थापित गर्न अनुमति"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"परीक्षणको लागि मक स्थान स्रोतहरू सिर्जना गर्नुहोस् वा नयाँ स्थान प्रदायक स्थापना गर्नुहोस्। यसले अनुप्रयोगलाई स्थानमा ओभरराइड गर्दछ र/वा स्थिति अन्य स्थान स्रोतहरू जस्तै GPS वा स्थान प्रदायकबाट फर्काइएका।"</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"सटिक स्थान (GPS र नेटवर्क आधारित)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"अनुप्रयोगले विश्वव्यापी स्थान प्रणाली (GPS) वा सेल टावरहरू र वाइ-फाइ जस्ता नेटवर्क स्थान स्रोतहरूको प्रयोग गरेर तपाईँको सही स्थान प्राप्त गर्न अनुमति दिन्छ। यी स्थान सेवाहरू खोल्नु पर्छ र अनुप्रयोगहरूका लागि प्रयोग गर्न तपाईँको उपकरणमा उपलब्ध हुनु पर्छ। अनुप्रयोगहरूले तपाईँ कहाँ हुनु हुन्छ भन्ने निर्धारण गर्न यसलाई प्रयोग गर्न सक्छ र यसले अतिरिक्त ब्याट्रि उर्जा खतप गर्न सक्छ।"</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"अनुमानित स्थान (नेटवर्क-आधारित)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"अनुप्रयोगलाई तपाईँको अनुमानित स्थान प्राप्त गर्न अनुमति दिन्छ। यो स्थान सेल टावर र वाइ-फाइजस्ता नेटवर्क स्थान स्रोतहरूको प्रोग गरी स्थान सेवाहरूबाट उत्पन्न गरिएको हो। अनुप्रयोगले यी स्थान सेवाहरूको उपयोग गर्नको लागि यी सेवाहरू तपाईँको उपकरणमा चालु र उपलब्ध हुनु आवश्यक छ। अनुप्रयोगहरूले अनुमानित रूपमा तपाईँ कहाँ हुनुहुन्छ भन्ने निर्धारण गर्न यसको प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger पहुँच गर्नुहोस्।"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"SurfaceFlinger कम-स्तर सुविधाहरू प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"फ्रेम बफर पढ्नुहोस्"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"अनुप्रयोगलाई फ्रेम बफरको सामग्री पढ्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessInputFlinger" msgid="5348635270689553857">"InputFlinger को पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"InputFlinger को कम-स्तर सुविधाहरू प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"वाइफाइ प्रदर्शनहरूलाई विन्यास गर्नुहोस"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"अनुप्रयोगलाई कन्फिगर गर्न र वाइफाइ प्रदर्शनहरूसँग जोड्न अनुमति दिन्छ।"</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"वाइफाइ प्रदर्शनहरू नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"वाइफाइ प्रदर्शनीका तल्लो तह विषेशताहरू नियन्त्रण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"अडियो आउटपुट कैद गर्नुहोस्"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"अनुप्रयोगलाई अडियो आउटपुट कैद गर्न र रिडाइरेक्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"भिडियो आउटपुट कैद गर्नुहोस्"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"अनुप्रयोगलाई भिडियो आउटपुट कैद गर्न र रिडाइरेक्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"सुरक्षित भिडियो आउटपुट कैद गर्नुहोस्"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"अनुप्रयोगलाई सुरक्षित भिडियो आउटपुट कैद गर्न र रिडाइरेक्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"तपाईँका अडियो सेटिङहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"अनुप्रयोगलाई ग्लोबल अडियो सेटिङ्हरू परिमार्जन गर्न अनुमति दिन्छ, जस्तै आवाजको मात्रा र आउटपुटको लागि कुन स्पिकर प्रयोग गर्ने।"</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"अडियो रेकर्ड गर्नुहोस्"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"अनुप्रयोगलाई माइक्रोफोनको साथ अडियो रेकर्ड गर्न अनुमति दिन्छ। यस अनुमतिले तपाईंको पुष्टिकरण बिना कुनै पनि समयमा अडियो रेकर्ड गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"तस्बिरहरू र भिडियोहरू लिनुहोस्।"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"अनुप्रयोगलाई क्यामेरासँग तस्बिर र भिडियोहरू लिन अनुमति दिन्छ। यस अनुमतिले अनुप्रयोगलाई तपाईंको पुष्टिकरण बिना कुनै पनि समयमा क्यामेरा प्रयोग गर्न स्वीकृति दिन्छ।"</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"क्यामेरा प्रयोगमा हुँदा सूचक LED प्रसारण असक्षम गर्नुहोस्"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"पूर्व-स्थापित प्रणाली अनुप्रयोगलाई क्यामेरा उपयोग सूचक LED अक्षम गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"स्थायी रूपमा ट्याब्लेट अक्षम पार्नुहोस्"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"फोनलाई स्थायी रूपमा असक्षम पार्नहोस्"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"पुरै ट्याब्लेटलाई स्थायी रूपमा असक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ। यो निकै खतरनाक हुन्छ।"</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"सम्पूर्ण फोनलाई स्थायी रूपमा असक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ। यो धेरै खतरनाक हुन्छ।"</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ट्याब्लेट पुनःबुट गर्न जोड गर्नुहोस्"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"फोन पुनःबुट गर्नु जोड गर्नुहोस्"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"ट्याब्लेटलाई बलपूर्वक पुनःबुट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"फोनलाई बलपुर्वक पुनःबुट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB भण्डारण फाइल प्रणाली पहुँच गर्नुहोस्"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD कार्ड फाइल प्रणाली पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"हटाउन मिल्ने भण्डारणको लागि फाइल प्रणालीहरू माउन्ट र अनमाउन्ट गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB भण्डारण मेट्नुहोस्"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD कार्ड मेटाउनुहोस्"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"हटाउन मिल्ने भण्डारण फर्म्याट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"आन्तरिक भण्डारणको सूचना प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"आन्तरिक भण्डारणमा सूचना प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"आन्तरिक भण्डारण सिर्जना गर्नुहोस्"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"आन्तरिक भण्डारण सिर्जना गर्नको लागि अनुप्रयोगले अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"आन्तरिक भण्डारण ध्वस्त पार्नुहोस्"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"अनुप्रयोगलाई आन्तरिक भण्डारण ध्वस्त पार्न अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"आन्तरिक भण्डारणलाई माउन्ट/अनमाउन्ट गर्नुहोस्"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"अनुप्रयोगलाई आन्तरिक भण्डारण माउन्ट/अनमाउन्ट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"आन्तरिक भण्डारणको पुन:नामाकरण गर्नुहोस्"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"आन्तरीक भण्डारणको पुननामाकरण गर्नको लागि अनुप्रयोगले अनुमति दिन्छ।"</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_manageUsb" msgid="1113453430645402723">"USB उपकरणहरूको लागि प्राथमिकताहरू र अनुमतिहरू प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"USB उपकरणहरूको लागि प्राथमिकताहरू र अनुमतिहरूलाई व्यवस्थापन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP प्रोटोकल कार्यान्वयन गर्नुहोस्"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"MTP USB प्रोटोकल कार्यान्वयन गर्न केर्नल MTP ड्राइभरको पहुँचको अनुमति दिन्छ।"</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"हार्डवेयर परीक्षण गर्नुहोस्"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"हार्डवेयर परीक्षणको उद्देश्यका लागि विभिन्न परिधीयहरूलाई नियन्त्रण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"फोन नम्बरहरूमा सिधै कल गर्नुहोस्"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"तपाईँको हस्तक्षेप बेगरै फोन नम्बर कल गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले अनपेक्षित शुल्क वा कलहरू गराउन सक्छ। यसले अनुप्रयोगलाई आपतकालीन नम्बरहरू कल गर्न अनुमति दिँदैन विचार गर्नुहोस्। खराब अनुप्रयोगहरूले तपाईँको स्वीकार बिना कलहरू गरेर तपाईँलाई बढी पैसा तिराउन सक्छ।"</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"कुनै पनि फोन नम्बरहरू सिधै कल गर्नुहोस्"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"कुनै पनि फोन नम्बरमा, आकस्मिक नम्बर सहित, तपाईँको हस्तक्षेप बिना कल गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले अनावश्यक र गैर कानुनी कलहरूलाई आकस्मिकमा स्थानान्तरण गर्न सक्छन्।"</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA ट्याब्लेट सेटअफ सिधै सुरु गर्नुहोस्"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA फोन सेटअप सिधै सुरु गर्नुहोस्"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"अनुप्रयोगलाई CDMA प्रावधान सुरu गर्न अनुमति दिन्छ। खराब अनुप्रयोगहरूले अनावश्यक रूपमा CDMA प्रावधान सुरु गर्न सक्छन्।"</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"स्थान अपडेट सूचनाहरू नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"रेडियोबाट स्थान अद्यावधिक सूचनाहरूलाई सक्षम/असक्षम गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूबाट प्रयोग नहुने।"</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"परीक्षण विशेषताहरू पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"परीक्षण सेवाद्वारा विशेषता अपलोड भएको पहुँच पढ्न/लेख्‍न अनुप्रयोगलाई अनुमति दिन्छ। साधारण अनुप्रयोगद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"विजेटहरूको चयन गर्नुहोस्"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"अनुप्रयोगलाई प्रणालीलाई कुन विजेट कुन अनुप्रयोगद्वारा प्रयोग गर्न सकिन्छ भनेर अनुमति दिन्छ। यस अनुमतिसहितको अनुप्रयोगले अन्य अनुप्रयोगहरूलाई व्यक्तिगत डेटाको पहुँच दिन सक्दछ। सामान्य अनुप्रयोगहरूको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"फोनको स्थिति परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"उपकरणका फोन विशेषताहरूलाई नियन्त्रण गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।  यस अनुमतिले एउटा अनुप्रयोगले नेटवर्क स्विच गर्न, फोन रेडियो बन्द गर्न र खोल्न र जस्तै तपाईँ सधै सूचित नगरी गर्न सक्छ।"</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"फोन स्थिति र पहिचान पढ्नुहोस्"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"उपकरणको फोन विशेषताहरूको पहुँच गर्न अनुप्रयोगलाई अनुमति दिन्छ। यस अनुमतिले फोन नम्बर र उपकरणको IDs, कल सक्षम छ कि छैन र कलद्वारा जोडिएको टाढाको नम्बर निर्धारण गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"ट्याब्लेटलाई निन्द्रामा जानबाट रोक्नुहोस्"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"फोनलाई निदाउनबाट रोक्नुहोस्"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"ट्याब्लेटलाई निस्क्रिय हुनबाट रोक्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"फोनलाई निस्क्रिय हुनबाट रोक्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"ट्याब्लेट पावर खोल्न र बन्द गर्नुहोस्"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"फोन खोल्न वा बन्द गर्न उर्जा प्रदान गर्नुहोस"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"ट्याब्लेटलाई खोल्न र बन्द गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"अनुप्रयोगलाई फोन खोल्न र बन्द गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"फ्याक्ट्रि परीक्षण मोडमा चालु गर्नुहोस्"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"ट्याब्लेट हार्डवेयरलाई पुरा पहुँच गर्न दिँदै तल्लो स्तर उत्त्पादक परीक्षणको रूपमा चलाउनुहोस्। ट्याब्लेट उत्त्पादक परीक्षण मोडमा चलिरहेको बेला मात्र उपलब्ध हुन्छ।"</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"तल्लो स्तर उत्त्पादक जस्तै चलाउनुहोस्, पुरा पहुँच दिन फोन हार्डवेयरलाई अनुमति हुन्छ। फोन उत्पादक परीक्षण मोडमा चलिरहेको बेला मात्र उपलब्ध हुन्छ।"</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"वालपेपर सेट गर्नुहोस्"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"अनुप्रयोगलाई प्रणाली वालपेपर सेट गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"तपाईंको वालपेपर आकार समायोजन गर्नुहोस्"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"प्रणाली वालपेपरको आकार सङ्केतहरू मिलाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"कार्यशाला पूर्वनिर्धारणको लागि प्रणाली पुनःसेट गर्नुहोस्"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"यसका फ्याक्ट्रि सेटिङहरू, कन्फिगरेसन र स्थापित अनुप्रयोगहरूलाई प्रणालीमा पुरै पुनःसेट गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"समय सेट गर्नुहोस्"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"ट्याब्लेटको घडीको समय बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"फोनको घडीको समय बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"समय क्षेत्र सेट गर्नुहोस्"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"अनुप्रयोगलाई ट्याब्लेटको समय क्षेत्र परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"अनुप्रयोगलाई फोनको समय क्षेत्र परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService को रूपमा कार्य गर्नुहोस्"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"खाता अधिकारीहरूलाई कल गर्नको लागि अनुप्रयोगले अनुमति दिन्छ।"</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"उपकरणमा खाताहरू भेट्टाउनुहोस्"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"अनुप्रयोगलाई ट्याब्लेटद्वारा ज्ञात खाताहरूको सूची पाउन अनुमति दिन्छ। यसले अनुप्रयोगद्वारा तपाईंले स्थापित गर्नुभएको कुनै पनि खाताहरू समावेश गर्न सक्दछ।"</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"फोनलाई थाहा भएका खाताहरूको सूची प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले तपाईँले स्थापना गर्नु भएका अनुप्रयोगहरूबाट सृजित कुनै खाताहरू समावेश हुन सक्छ।"</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"खाता सिर्जना गर्नुहोस् र पासवर्ड सेट गर्नुहोस्"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"खाताहरूको सिर्जना गर्ने र प्राप्त गर्ने र उनीहरूको पासवर्डहरूको सेटिङ गर्ने सहित खाता प्रबन्धकको खाता आधिकारी सक्षमताहरू प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"खाताहरू थप्नुहोस् वा हटाउनुहोस्"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"खाताहरू थप्ने र हटाउने जस्ता प्रक्रियाहरू सम्पन्न गर्न, र उनीहरूको पासवर्ड मेटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"उपकरणमा खाताहरूको प्रयोग गर्नुहोस्"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"अनुप्रयोगलाई प्रमाणीकरण टोकनहरू अनुरोध गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"नेटवर्क जडानहरू हेर्नहोस्"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"अनुप्रयोगलाई नेटवर्क जडानहरू जस्तै कुन नेटवर्कहरू अवस्थित हुन्छन् र जडित छन् जसले हेर्नलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"पूर्ण नेटवर्क पहुँच"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"नेटवर्क सकेटहरू सिर्जना गर्न र कस्टम नेटवर्क प्रोटोकल प्रयोग गर्न अनुप्रयोगलाई अनुमति दिन्छ। ब्राउजर र अन्य अनुप्रयोगहरूले इन्टरनेटमा डेटा पठाउने माध्यम प्रदान गर्छन्, त्यसैले इन्टरनेटमा डेटा पठाउन यो अनुमतिको आवश्यकता पर्दैन।"</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"नेटवर्क सेटिङहरू र ट्राफिक परिवर्तन गर्नुहोस् / रोक्नुहोस्"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"अनुप्रयोगलाई नेटवर्क सेटिङहरू परिवर्तन गर्न र सबै नेटवर्क ट्राफिक रोक्न र परीक्षण गर्न अनुमति दिन्छ, उदाहरणको लागि कुनै पनि APN को प्रोक्सी र पोर्ट परिवर्तन गर्न। खराब अनुप्रयोगहरूले तपाईंको ज्ञान बिना नेटवर्क प्याकेटहरू मोनिटर गर्न, पुन:निर्देशित गर्न, वा परिमार्जन गर्न सक्दछ।"</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"नेटवर्क जडान परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"अनुप्रयोगलाई नेटवर्क जडानको स्थिति परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"टेथर्ड नेटवर्क जडान परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"टिथर गरेको नेटवर्क जडानको स्थिति बदल्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"पृष्ठभूमि डेटा प्रयोग सेटिङहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"अनुप्रयोगलाई पृष्ठभूमि डेटा उपयोग सेटिङ परिवर्तन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"वाइ-फाइ जडानहरू हेर्नुहोस्"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"अनुप्रयोगलाई वाइ-फाइ नेटवर्कको बारेमा जानकारी हेर्न अनुमति दिन्छ, जस्तै कि वाइ-फाइ सक्षम छ कि छैन र जडान गरिएको वाइ-फाइ उपकरणहरूको नाम।"</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"वाइ-फाइसँग जोड्नुहोस् वा छुटाउनुहोस्"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"अनुप्रयोगलाई वाइ-फाइ पहुँच बिन्दुबाट जडान गर्न र विच्छेदन गर्न र वाइ-फाइ नेटवर्कहरूको लागि उपकरण कन्फिगरेसनमा परिवर्तनहरू गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"वाइ-फाइ Multicast स्विकृतिलाई अनुमति दिनुहोस्"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"अनुप्रयोगलाई मल्टिकाष्ट ठेगानाहरू प्रयोग गरेर वाइ-फाइ नेटवर्कमा पठाइएको प्याकेटहरू प्राप्त गर्न अनुमति दिन्छ, केवल तपाईंको ट्याब्लेट मात्र होइन। यसले गैर-मल्टिकाष्ट मोड भन्दा बढी उर्जा प्रयोग गर्दछ।"</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"तपाईँको फोन मात्र होइन, मल्टिकास्ट ठेगानाहरूको प्रयोग गरे वाइ-फाइ नेटवर्कका सबै उपकरणहरूमा पठाइएका प्याकेटहरू प्राप्त गर्न अनुप्रयोगलाई अनुमति दिन्छ। यसले गैर-मल्टिकास्ट मोडभन्दा बढी उर्जा प्रयोग गर्छ।"</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"ब्लुटुथ सेटिङहरूमा पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"स्थानीय ब्लुटुथ ट्याब्लेटलाई कन्फिगर गर्नको लागि र टाढाका उपकरणहरूलाई पत्ता लगाउन र जोड्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"अनुप्रयोगलाई स्थानीय ब्लुटुथ फोन कन्फिगर गर्न र टाढाका उपकरणहरूसँग खोज गर्न र जोडी गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAXसँग जोड्नुहोस् वा छुटाउनुहोस्"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"अनुप्रयोगलाई वाइम्याक्स सक्षम छ कि छैन र जडान भएको कुनै पनि वाइम्याक्स नेटवर्कहरूको बारेमा जानकारी निर्धारिण गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"वाइम्याक्स स्थिति परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"अनुप्रयोगलाई वाइम्याक्स नेटवर्कहरूबाट ट्याब्लेट जडान गर्न र ट्याब्लेट विच्छेदन गर्न अनुमति दिन्छ।"</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"वाइम्याक्स नेटवर्कहरूसँग फोन जोड्न र छुटाउन अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"ब्लुटुथ उपकरणहरूसँग जोडी मिलाउनुहोस्"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"ट्याब्लेटमा ब्लुटुथको कन्फिगुरेसनलाई हेर्न र बनाउन र जोडी उपकरणहरूसँग जडानहरूलाई स्वीकार गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"अनुप्रयोगलाई फोनमा ब्लुटुथको कन्फिगरेसन हेर्न र जोडी भएका उपकरणहरूसँग जडानहरू बनाउन र स्वीकार गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"नजिक क्षेत्र संचार नियन्त्रणहरू"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"अनुप्रयोगलाई नयाँ क्षेत्र संचार (NFC) ट्यागहरू, कार्डहरू र पाठकहरूसँग अन्तर्क्रिया गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"स्क्रिन लक असक्षम पार्नुहोस्"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"कुनै सम्बन्धित पासवर्ड सुरक्षा र किलकलाई असक्षम पार्न अनुप्रयोगलाई अनुमति दिन्छ। उदाहरणको लागि, अन्तर्गमन फोन कल प्राप्त गर्दा फोनले किलकलाई असक्षम पार्छ, त्यसपछि कल सकिएको बेला किलक पुनःसक्षम पार्छ।"</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"समीकरण सेटिङहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"अनुप्रयोगलाई खाताको लागि सिङ्क सेटिङहरू पढ्न अनुमति दिन्छ। उदाहरणको लागि यसले व्यक्तिहरको अनुप्रयोग खातासँग सिङ्क भएको नभएको निर्धारण गर्न सक्दछ।"</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"टगल सिङ्क खुला र बन्द"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"अनुप्रयोगहरूलाई खाताको लागि सिङ्क सेटिङहरू परिमार्जन गर्न अनुमति दिन्छ। उदाहरणको लागि, यो खातासँग व्यक्ति अनुप्रयोगको सिङ्क सक्षम गर्न प्रयोग गर्न सकिन्छ।"</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"सिङ्क तथ्याङ्कहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"अनुप्रयोगलाई खाताको लागि समीकरणको आँकडा समीकरण घटनाहरूको  इतिहास र समीकरण गरिएको डेटाको मापन समेत, पढ्न अनुमति दिन्छ।"</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"सदस्य बनाइका फिडहरू पढ्नुहोस्"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"अनुप्रयोगलाई अहिलेको समीकरण गरिएका सूचकहरू बारे विवरणहरू लिने अनुमति दिन्छ।"</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"सदस्य बनाइका फिडहरू लेख्नुहोस्"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"तपाईँका भर्खरै सिङ्क फिडहरूलाई परिमार्जन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। तपाईँको सिङ्क फिडहरूलाई परिवर्तन गर्नको लागि यसले  खराब अनुप्रयोगलाई अनुमति दिन सक्छ।"</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"तपाईँले शब्दकोशमा थपेका शब्दहरू पढ्नुहोस्"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"अनुप्रयोगलाई प्रयोगकर्ताले प्रयोगकर्ता शब्दकोशमा भण्डारण गरेका हुन सक्ने सबै शब्दहरू, नामहरू र पदावलीहरू पढ्न अनुमति दिन्छ।"</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"प्रयोगकर्ता-परिभाषित शब्दकोशमा शब्दहरू थप्नुहोस्।"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"प्रयोगकर्ता शब्दकोशमा नयाँ शब्द लेख्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"सुरक्षित गरिएका भण्डारण पहुँचको परीक्षण गर्नुहोस्"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"सुरक्षित गरिएका भण्डारण पहुँचको परीक्षण गर्नुहोस्"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"भविष्य उपकरणहरूमा उपलब्ध हुने USB भण्डारणको लागि अनुमति परीक्षण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"भविष्य उपकरणहरूमा उपलब्ध हुने SD कार्डको लागि अनुमति परीक्षण गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"तपाईँको USB भण्डारणको विषयवस्तुहरूलाई परिमार्जन गर्नुहोस् वा मेटाउनुहोस्"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"तपाईँको SD कार्डको विषयसूची परिमार्जन गर्नुहोस् वा मेट्नुहोस्"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"USB भण्डारणमा लेख्‍नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"अनुप्रयोगलाई SD कार्डमा लेख्न अनुमति दिन्छ।"</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"आन्तरिक मिडिया भण्डारण सामग्रीहरू परिमार्जन गर्नुहोस्/मेटाउनुहोस्"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"अनुप्रयोगलाई आन्तरिक मिडिया भण्डारणको सामग्रीहरू परिमार्जन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"कागजात भण्डारण प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"अनुप्रयोगलाई कागजात भण्डारण समायोजन गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"सबै उपयोगकर्ताहरूको बाह्य भण्डारणको पहुँच राख्नुहोस्"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"अनुप्रयोगलाई सबै उपयोगकर्ताहरूको लागि बाह्य भण्डारणमाथि पहुँच राख्न अनुमति दिन्छ।"</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"क्यास फाइल प्रणाली पहुँच गर्नुहोस्।"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"केस फाइल प्रणालीलाई पढ्न र लेख्‍नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"इन्टरनेट कलहरू गर्नुहोस् वा प्राप्त गर्नुहोस्"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"इन्टरनेट कल गर्न/प्राप्त गर्न SIP सेवालाई प्रयोग गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"नेटवर्क उपयोगको इतिहास पढ्नुहोस्"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"निश्चित नेटवर्कहरू र अनुप्रयोगहरूको लागि ऐतिहासिक नेटवर्क उपयोग पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"नेटवर्क नीति प्रबन्ध गर्नुहोस्"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"नेटवर्क नीतिहरू व्यवस्थापन गर्न र अनुप्रयोग-विशेष नियमहरू परिभाषित गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"नेटवर्क उपयोग लेखालाई परिमार्जन गर्नुहोस्"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"अनुप्रयोगलाई कसरी अनुप्रयोगहरूको विरूद्धमा कसरी नेटवर्क उपयोगी अकाउन्टेड छ भनेर परिमार्जन गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूद्वारा प्रयोगको लागि होइन।"</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"सकेटको निशानहरू परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"मार्ग दर्शनको लागि अनुप्रयोगलाई सकेटको निशानहरू परिवर्तन गर्न अनुमति दिन्छ"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"सूचनाहरू पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"अन्य अनुप्रयोगहरूबाट पोस्ट गरिएकासहित पुनःप्राप्त गर्न, परीक्षण गर्न र सूचनाहरू हटाउन अनुप्रयोगहरूलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"जानकारी श्रोता सेवामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"होल्डरलाई सूचना श्रोता सेवाको शीर्ष-स्तरको इन्टरफेस बाँध्न अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"वाहक-प्रदान विन्यास अनुप्रयोग सुरु गर्नुहोस्"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"प्रयोगकर्तालाई वाहक-प्रदान विन्यास अनुप्रयोग सुरु गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्ने छैन।"</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"सञ्जाल अवस्थाका पर्यवेक्षणका लागि सुन्नुहोस्"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"सञ्जाल अवस्थाका पर्यवेक्षण सुन्नका लागि अनुप्रयोगलाई अनुमति दिन्छ।सामान्य अनुप्रयोगलाई चाँहिदै नचाँहिन सक्छ।"</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"पासवर्ड नियमहरू मिलाउनुहोस्"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"स्क्रिन-अनलक पासवर्डहरूमा अनुमति दिइएको लम्बाइ र अक्षरहरू नियन्त्रण गर्नुहोस्।"</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"मोनिटर स्क्रिन-अनलक प्रयत्नहरू"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"स्क्रिन अनलक गर्दा गलत पासवर्ड टाइप भएको संख्या निरीक्षण गर्नुहोस् र यदि निकै धेरै गलत पासवर्डहरू टाइप भएका छन भने ट्याब्लेट लक गर्नुहोस् वा ट्याब्लेटका सबै डेटा मेट्नुहोस्।"</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"स्क्रिनअनलक गर्दा गलत पासवर्ड टाइप भएको संख्या निरीक्षण गर्नुहोस् र यदि निकै धेरै गलत पासवर्डहरू टाइप भएका छन भने फोन लक गर्नुहोस् वा फोनका सबै डेटा मेट्नुहोस्।"</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"स्क्रिन-अनलक पासवर्ड बदल्नुहोस्"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"स्क्रिन-अनलक पासवर्ड परिवर्तन गर्नुहोस्।"</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"स्क्रिन लक गर्नुहोस्।"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"कसरी र कहिले स्क्रिन लक गर्ने नियन्त्रण गर्नुहोस्।"</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"सबै डेटा मेट्नुहोस्"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"एउटा फ्याक्ट्रि डेटा पुनःसेट गरेर चेतावनी नआउँदै ट्याबल्टको डेटा मेट्नुहोस्।"</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"एउटा फ्याक्ट्रि डेटा पुनःसेट गरेर चेतावनी नआउँदै फोनको डेटा मेट्नुहोस्।"</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"उपकरण विश्वव्यापी प्रोक्सी मिलाउनुहोस्"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"नीति सक्षम हुँदा प्रयोग हुने उपकरण  विश्वव्यापी प्रोक्सी सेट गर्नुहोस्। प्रथम उपकरण प्रशासशनले मात्र प्रभावकारी विश्वव्यापी प्रोक्सी सेट गर्छ।"</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"लक-स्क्रिन पासवर्ड अन्त सेट गर्नुहोस्"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"प्रायः कति छिटो लक-स्क्रिन पासवर्ड बदल्नु पर्छ यसलाई नियन्त्रण गर्नुहोस्।"</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"भण्डारण इन्क्रिप्सन मिलाउनुहोस्"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"भण्डार गरिएको डेटा इन्क्रिप्ट हुनु आवश्यक छ।"</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"क्यामेरालाई असक्षम गराउनुहोस्"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"सबै उपकरण क्यामराहरूको प्रयोग रोक्नुहोस्"</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"किगार्डमा भएका विशेषताहरू असक्षम पार्नुहोस्"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"केही किगार्ड विशेषताहरूको प्रयोग रोक्नुहोस्।"</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"गृह"</item>
-    <item msgid="869923650527136615">"मोबाइल"</item>
-    <item msgid="7897544654242874543">"काम गर्नुहोस्"</item>
-    <item msgid="1103601433382158155">"कार्य फ्याक्स"</item>
-    <item msgid="1735177144948329370">"घरको फ्याक्स"</item>
-    <item msgid="603878674477207394">"पेजर"</item>
-    <item msgid="1650824275177931637">"अन्य"</item>
-    <item msgid="9192514806975898961">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"गृह"</item>
-    <item msgid="7084237356602625604">"काम"</item>
-    <item msgid="1112044410659011023">"अन्य"</item>
-    <item msgid="2374913952870110618">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"गृह"</item>
-    <item msgid="5629153956045109251">"काम"</item>
-    <item msgid="4966604264500343469">"अन्य"</item>
-    <item msgid="4932682847595299369">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"गृह"</item>
-    <item msgid="1359644565647383708">"काम"</item>
-    <item msgid="7868549401053615677">"अन्य"</item>
-    <item msgid="3145118944639869809">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"काम गर्नुहोस्"</item>
-    <item msgid="4378074129049520373">"अन्य"</item>
-    <item msgid="3455047468583965104">"अनुकूलन"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"स्काइप"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"अनुकूलन"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"गृह"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"मोबाइल"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"काम"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"कार्य फ्याक्स"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"घरको फ्याक्स"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"पेजर"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"अन्य"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"कलब्याक"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"कार"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"कम्पनी मुख्य"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"मुख्य"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"अन्य फ्याक्स"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"रेडियो"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"टेलेक्स"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"कार्य मोबाइल"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"कार्य पेजर"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"सहायक"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"अनुकूलन"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"जन्मदिन"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"वार्षिक समारोह"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"अन्य"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"अनुकूलन"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"गृह"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"काम"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"अन्य"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"मोबाइल"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"अनुकूलन"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"गृह"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"काम"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"अन्य"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"अनुकूलन"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"गृह"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"काम"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"अन्य"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"अनुकूलन"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"स्काइप"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"ह्याङआउटहरू"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"काम"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"अन्य"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"अनुकूलन"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"अनुकूलन"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"सहायक"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"भाइ"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"बच्चो"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"आन्तरिक साझेदार"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"बुबा"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"मित्र"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"ब्यवस्थापक"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"आमा"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"अभिभावक"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"पार्टनर"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"द्वारा उल्लिखित"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"आफन्त"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"बहिनी"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"पति-पत्नि"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"अनुकूलन"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"गृह"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"काम गर्नुहोस्"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"अन्य"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PIN कोड टाइप गर्नुहोस्"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK र नयाँ PIN कोड टाइप गर्नुहोस्"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK कोड"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"नयाँ PIN कोड"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"पासवर्ड टाइप गर्न छुनुहोस्"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"अनलक गर्न पासवर्ड टाइप गर्नुहोस्।"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"अनलक गर्न PIN कोड टाइप गर्नुहोस्"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"गलत PIN कोड।"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"अनलक गर्न मेनु थिच्नुहोस् र त्यसपछि ० थिच्नुहोस्।"</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"आपतकालीन नम्बर"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"सेवा छैन।"</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"स्क्रिन लक गरिएको।"</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"अनलक वा आपतकालीन कल गर्न मेनु थिच्नुहोस्।"</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"अनलक गर्न मेनु थिच्नुहोस्।"</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"अनलक गर्नु ढाँचा खिच्नुहोस्"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"आपतकालीन कलहरू"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"कलमा फर्किनुहोस्"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"सही!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"फेरि प्रयास गर्नुहोस्"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"फेरि प्रयास गर्नुहोस्"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"अत्याधिक मोहडा खोल्ने प्रयासहरू बढी भए।"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"चार्ज हुँदै, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"चार्ज भयो"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"तपाईँको चार्जर जोड्नुहोस्।"</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM कार्ड छैन"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"ट्याब्लेटमा SIM कार्ड छैन।"</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"फोनमा SIM कार्ड छैन।"</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SIM कार्ड घुसाउनुहोस्"</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM कार्ड छैन वा पढ्न मिल्दैन। SIM कार्ड हाल्नुहोस्।"</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"प्रयोग गर्न अयोग्य SIM कार्ड"</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"तपाईंको SIM कार्ड स्थायी रूपमा अक्षम भयो।\n अर्को SIM कार्डको लागि आफनो ताररहित सेवा प्रदायकसँग सम्पर्क गर्नुहोस्।"</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"अघिल्लो ट्रयाक बटन"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"अर्को ट्रयाक बटन"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"रोक्ने बटन"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"बजाउने बटन"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"बटन रोक्नुहोस्"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"आपतकालीन कलहरू मात्र"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"नेटवर्क लक छ"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM कार्ड PUK-लक गरिएको छ।"</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"प्रयोगकर्ता निर्देशक वा ग्राहक सेवा सम्पर्क हर्नुहोस्।"</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM कार्ड लक गरिएको छ।"</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM कार्ड अनलक गरिँदै..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"तपाईँले तपाईँको अनलक ढाँचा गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक खिच्नु भएको छ। \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि कोसिस गर्नुहोस्।"</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"तपाईंले गलत तरिकाले आफ्नो पासवर्ड <xliff:g id="NUMBER_0">%d</xliff:g> पटक टाइप गर्नुभयो। \n\n<xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"तपाईँले गलत तरिकाले तपाईँको PIN <xliff:g id="NUMBER_0">%d</xliff:g> पटक टाइप गर्नु भएको छ। \n\n<xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"तपाईँले तपाईँको अनलक ढाँचा गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक खिच्नु भएको छ। पछि <xliff:g id="NUMBER_1">%d</xliff:g> थप असफल कोसिसहरू, तपाईँको Google साइन इन प्रयोग गरी तपाईँको ट्याब्लेट अनलक गर्न भनिने छ।\n\n  <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डमा फरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"तपाईँले <xliff:g id="NUMBER_0">%d</xliff:g> पटक गलत तरिकाले तपाईँको अनलक ढाँचालाई कोर्नु भएको छ। पछि <xliff:g id="NUMBER_1">%d</xliff:g> अरू धेरै असफल कोसिसहरूपछि, तपाईँलाई तपाईँको फोन Google साइन इन प्रयोग गरेर अनलक गर्नको लागि सोधिने छ। \n\n <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डमा पुनः प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"तपाईँले <xliff:g id="NUMBER_0">%d</xliff:g> पटक ट्याब्लेटलाई अनलक गर्नको लागि गलत तरिकाले कोशिस गर्नुभएको छ। <xliff:g id="NUMBER_1">%d</xliff:g> अरू धेरै असफल कोसिसहरूपछि, ट्याब्लेट फ्याट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ र सबै प्रयोगकर्ता डेटा हराउने छन्।"</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"तपाईंले गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक फोन अनलक गर्ने प्रयत्न गर्नुभयो। <xliff:g id="NUMBER_1">%d</xliff:g> बढी असफल प्रयत्नहरू पछि, फोन फ्याक्ट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ र सबै प्रयोगकर्ता डेटा हराउने छन्।"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"तपाईँले ट्यब्लेटलाई अनलक गर्न गलत तरिकाले <xliff:g id="NUMBER">%d</xliff:g> पटक प्रयास गर्नु भएको छ। अब ट्याब्लेटलाई पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ।"</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"तपाईंले गलत तरिकाले फोन <xliff:g id="NUMBER">%d</xliff:g> पटक अनलक गर्ने प्रयत्न गर्नुभयो। अब फोन फ्याक्ट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ।"</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"<xliff:g id="NUMBER">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"ढाँचा बिर्सनु भयो?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"खाता अनलक"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"निकै धेरै कोसिसहरू"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"अनलक गर्नको लागि, तपाईँको Google खातासँग साइन इन गर्नुहोस्।"</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"प्रयोगकर्तानाम (इमेल)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"पासवर्ड:"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"साइन इन गर्नुहोस्"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"अमान्य प्रयोगकर्तानाम वा पासवर्ड"</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"तपाईँको प्रयोगकर्ता नाम वा पासवर्ड बिर्सनुभयो?\n भ्रमण गर्नुहोस"<b>"google.com/accounts/recovery"</b></string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"जाँच गर्दै..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"खोल्नुहोस्"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"आवाज चालु छ।"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"ध्वनि बन्द"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"ढाँचा सुरु भयो"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"ढाँचा हटाइएको"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"सेल थप गरियो"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"ढाँचा पुरा भयो"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. विजेट %2$d of %3$d।"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"विजेट थप गर्नुहोस्।"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"खाली"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"अनलक क्षेत्र विस्तार भयो।"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"अनलक क्षेत्र भत्कियो।"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> विजेट।"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"प्रयोगकर्ता छनौटकर्ता"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"स्थिति"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"क्यामेरा"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"मिडिया नियन्त्रणहरू"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"विजेट पुनःक्रम गर्ने सुरु भयो।"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"विजेट पुनःक्रम समाप्त भएको छ।"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"विजेट <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> मेटाइयो।"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"अनलक क्षेत्र बढाउनुहोस्।"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"स्लाइड अनलक।"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"ढाँचा अनलक।"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"फेस अनलक"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin अनलक"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"पासवर्ड अनलक।"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ढाँचा क्षेत्र।"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"स्लाइड क्षेत्र।"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?१२३"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"अक्षर"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"शब्द"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"लिङ्क"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"लाइन"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"कार्यशाला परीक्षण असफल भयो।"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"FACTORY_TEST कार्रवाइले /system/app मा स्थापित प्याकेजहरूको लागि मात्र समर्थन गर्छ।"</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"कुनै प्याकेज फेला पार्न सकिएन जसले FACTORY_TEST कार्य प्रदान गर्दछ।"</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"पुनःबुट गर्नुहोस्"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"यस \"<xliff:g id="TITLE">%s</xliff:g>\" मा भएको पृष्ठले बताउँछ:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"जाभास्क्रिप्ट"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"मार्गनिर्देशन पक्का गर्नुहोस्"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"यस पृष्ठलाई छोड्नुहोस्"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"यही पृष्ठमा रहनुहोस्"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nके तपाईँ यो पेजबाट नेभिगेट गर्न चाहनु हुन्छ भन्ने निश्चत छ?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"निश्चित गर्नुहोस्"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"जुक्ति: जुमलाई ठूलो र सानो पार्न दुई पटक हान्नुहोस्।"</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"स्वतः भर्ने"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"अटोफिल सेटअप गर्नुहोस्"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$१$२$३"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"प्रान्त"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"हुलाकी कोड"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"राज्य"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ZIP कोड"</string>
-    <string name="autofill_county" msgid="237073771020362891">"काउन्टी"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"टापु"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"जिल्ला"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"विभाग"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"प्रशासकीय क्षेत्र"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"पेरिस"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"क्षेत्र"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"इमिरेट"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"तपाईँका बुकमार्कहरू र इतिहास पढ्नुहोस्"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"ब्राउजरले भ्रमण गरेको सबै URL हरूको इतिहास र ब्राउजरका सबै बुकमार्कहरू पढ्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। नोट: यो अनुमतिलाई तेस्रो पक्ष ब्राउजरहरूद्वारा वा वेब ब्राउज गर्ने क्षमताद्वारा बलपूर्वक गराउन सकिँदैन।"</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"वेब बुकमार्कहरू र इतिहास लेख्नुहोस्"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"अनुप्रयोगलाई तपाईंको ट्याब्लेटमा भण्डार गरिएको ब्राउजरको इतिहास वा बुकमार्कहरू परिमार्जन गर्न अनुमति दिन्छ। यसले अनुप्रयोगलाई ब्राजर डेटा मेटाउन वा परिमार्जन गर्न अनुमति दिन सक्दछ। टिप्पणी: यो अनुमति वेब ब्राउज गर्ने क्षमताहरूको साथ तेस्रो-पार्टी ब्राउजर वा अन्य अनुप्रयोगहरूद्वारा लागू गरिएको होइन।"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"तपाईँको फोनमा भण्डारण भएको ब्राउजरको इतिहास वा बुकमार्कहरू परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। यसले सायद ब्राउजर डेटालाई मेट्न वा परिवर्तन गर्नको लागि अनुप्रयोगलाई अनुमति दिन्छ। नोट: वेब ब्राउज गर्ने क्षमतासहितका अन्य अनुप्रयोगहरू वा तेस्रो- पक्ष ब्राउजरद्वारा सायद यस अनुमतिलाई लागु गर्न सकिंदैन।"</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"एउटा आलर्म सेट गर्नुहोस्"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"स्थापना गरिएको सङ्केत घडी अनुप्रयोगमा सङ्केत समय मिलाउन अनुप्रयोगलाई अनुमति दिन्छ। केही सङ्केत घडी अनुप्रयोगहरूले यो सुविधा कार्यान्वयन नगर्न सक्छन्।"</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"भ्वाइसमेल थप गर्नुहोस्"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"तपाईँको भ्वाइसमेल इनबक्समा सन्देश थप्नको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"भूस्थान अनुमतिहरू ब्राउजर परिवर्तन गर्नुहोस्"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"ब्राउजरको भू-स्थान अनुमतिहरू परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। खराब अनुप्रयोगहरूले  स्थान सूचना मनपरी वेब साइटहरूमा पठाउने अनुमतिको लागि यसलाई प्रयोग गर्न सक्छन्।"</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"प्यकेजहरूको निरीक्षण गर्नुहोस्"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"प्याकेज स्थापना योग्य छ कि भनेर रुजु गर्न अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"एउटा प्याकेज रुजुकर्तामा बाँध्नुहोस्"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"होल्डरलाई प्याकेज प्रमाणितकर्ताहरूको अनुरोधहरू बनाउन अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिले पनि आवश्यक नपर्न सक्दछ।"</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"पहुँच सिरियल पोर्टहरू"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"होल्डरलाई SerialManager API प्रयोग गरेर सिरियल पोर्टहरू पहुँच गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"विषयसूची प्रदातालाई बाह्य रूपमा पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"सेलबाट धारकले विषयवस्तु प्रदायकहरूसम्मको पहुँच पाउन अनुमति दिन्छ। सामान्य अनुप्रयोगहरूलाई कहिल्यै आवश्यक पर्दैन।"</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"स्वचालित उपकरण अपडेटहरू हतोत्साहित गर्नुहोस्"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"होल्डरलाई उपकरण अपग्रेड गर्न गैर पारस्परिक पुनःबुटको लागि उचित समयको बारेमा प्रणालीमा जानाकारी प्रस्तावको लागि अनुमति दिन्छ।"</string>
-    <string name="save_password_message" msgid="767344687139195790">"के तपाईं ब्राउजरले यो पासवर्ड सम्झेको चाहनुहुन्छ?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"अहिले होइन"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"सम्झनुहोस्"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"कहिल्यै पनि होइन"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"यो पृष्ठ खोल्न तपाईँलाई अनुमति छैन।"</string>
-    <string name="text_copied" msgid="4985729524670131385">"क्लिपबोर्डमा प्रतिलिप गरिएको पाठ।"</string>
-    <string name="more_item_label" msgid="4650918923083320495">"बढी"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"मेनु+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"ठाउँ"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"प्रविष्टि गर्नुहोस्"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"मेटाउनुहोस्"</string>
-    <string name="search_go" msgid="8298016669822141719">"खोज्नुहोस्"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"खोज्नुहोस्"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"जिज्ञासा खोज गर्नुहोस्"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"प्रश्‍न हटाउनुहोस्"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"जिज्ञासा पेस गर्नुहोस्"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"भ्वाइस खोजी"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"छोएर अन्वेषण गर्ने सक्षम पार्न चाहनु हुन्छ?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>ले स्पर्षद्वारा अन्वेषण सक्षम गर्न चाहन्छ। स्पर्षद्वारा अन्वेषण सक्षम भएको बेला, तपाईँ आफ्नो औँलाको मुनि भएका विषयवस्तुहरू बारे सुन्न वा विवरण हेर्न सक्नुहुन्छ वा ट्याब्लेटसँग अन्तर्क्रिया गर्न इशारा गर्नुहोस्।"</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"<xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g>ले स्पर्षद्वारा अन्वेषण सक्षम गर्न चाहन्छ। स्पर्षद्वारा अन्वेषण सक्षम भएको बेला तपाईँ आफ्नो औँलाको मुनि भएका विषयवस्तुहरू बारे सुन्न वा विवरण हेर्न सक्नुहुन्छ वा फोनसँग अन्तर्क्रिया गर्न इशारा गर्नुहोस्।"</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"१ महिना अघि"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"१ महिना अघि"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"१ सेकेन्ड अघि"</item>
-    <item quantity="other" msgid="3903706804349556379">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्ड अघि"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"१ मिनेट अघि"</item>
-    <item quantity="other" msgid="2176942008915455116">"<xliff:g id="COUNT">%d</xliff:g> मिनेट अघि"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"१ घन्टा अघि"</item>
-    <item quantity="other" msgid="2467273239587587569">"<xliff:g id="COUNT">%d</xliff:g> घन्टा अघि"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"अन्तिम <xliff:g id="COUNT">%d</xliff:g> दिन"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"अन्तिम महिना"</string>
-    <string name="older" msgid="5211975022815554840">"पुरानो"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"हिजो"</item>
-    <item quantity="other" msgid="2479586466153314633">"<xliff:g id="COUNT">%d</xliff:g> दिन अघि"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"१ सेकेन्डमा"</item>
-    <item quantity="other" msgid="1241926116443974687">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्डमा"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"१ मिनेटमा"</item>
-    <item quantity="other" msgid="3330713936399448749">"<xliff:g id="COUNT">%d</xliff:g>मिनेटमा"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"१ घन्टामा"</item>
-    <item quantity="other" msgid="547290677353727389">"<xliff:g id="COUNT">%d</xliff:g> घन्टामा"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"भोलि"</item>
-    <item quantity="other" msgid="5109449375100953247">"<xliff:g id="COUNT">%d</xliff:g> दिनमा"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"१ सेकेन्ड अघि"</item>
-    <item quantity="other" msgid="3699169366650930415">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्ड अगाडि"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"१ मिनेट अघि"</item>
-    <item quantity="other" msgid="851164968597150710">"<xliff:g id="COUNT">%d</xliff:g> मिनेट अघि"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"१ घन्टा अघि"</item>
-    <item quantity="other" msgid="6889970745748538901">"<xliff:g id="COUNT">%d</xliff:g> घन्टा अघि"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"हिजो"</item>
-    <item quantity="other" msgid="3453342639616481191">"<xliff:g id="COUNT">%d</xliff:g> दिन अघि"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"१ सेकन्ड"</item>
-    <item quantity="other" msgid="5495880108825805108">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्डमा"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"१ मिनेटमा"</item>
-    <item quantity="other" msgid="4216113292706568726">"<xliff:g id="COUNT">%d</xliff:g> मिनेटमा"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"१ घन्टामा"</item>
-    <item quantity="other" msgid="3705373766798013406">"<xliff:g id="COUNT">%d</xliff:g> घन्टामा"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"भोलि"</item>
-    <item quantity="other" msgid="2973062968038355991">"दिन<xliff:g id="COUNT">%d</xliff:g> मा"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g> मा"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"<xliff:g id="TIME">%s</xliff:g> मा"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> मा"</string>
-    <string name="day" msgid="8144195776058119424">"दिन"</string>
-    <string name="days" msgid="4774547661021344602">"दिन"</string>
-    <string name="hour" msgid="2126771916426189481">"घन्टा"</string>
-    <string name="hours" msgid="894424005266852993">"घन्टा"</string>
-    <string name="minute" msgid="9148878657703769868">"मिनेट"</string>
-    <string name="minutes" msgid="5646001005827034509">"मिनेट"</string>
-    <string name="second" msgid="3184235808021478">"सेकेन्ड"</string>
-    <string name="seconds" msgid="3161515347216589235">"सेकेन्ड"</string>
-    <string name="week" msgid="5617961537173061583">"हप्ता"</string>
-    <string name="weeks" msgid="6509623834583944518">"हप्ताहरू"</string>
-    <string name="year" msgid="4001118221013892076">"वर्ष"</string>
-    <string name="years" msgid="6881577717993213522">"वर्षहरू"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"१ सेकेन्ड"</item>
-    <item quantity="other" msgid="1886107766577166786">"<xliff:g id="COUNT">%d</xliff:g> सेकेन्ड"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"१ मिनेट"</item>
-    <item quantity="other" msgid="3165187169224908775">"<xliff:g id="COUNT">%d</xliff:g> मिनेट"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"१ घन्टा"</item>
-    <item quantity="other" msgid="3863962854246773930">"<xliff:g id="COUNT">%d</xliff:g> घन्टा"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"भिडियो समस्या"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"यो भिडियो यस उपकरणको लागि स्ट्रिमिङ गर्न मान्य छैन।"</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"यो भिडियो चलाउन सक्दैन।"</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"ठीक छ"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"मध्यान्न"</string>
-    <string name="Noon" msgid="3342127745230013127">"मध्यान्ह"</string>
-    <string name="midnight" msgid="7166259508850457595">"मध्यरात"</string>
-    <string name="Midnight" msgid="5630806906897892201">"मध्यरात"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"सबैलाई चयन गर्नुहोस्"</string>
-    <string name="cut" msgid="3092569408438626261">"काट्नुहोस्"</string>
-    <string name="copy" msgid="2681946229533511987">"प्रतिलिपि बनाउनुहोस्"</string>
-    <string name="paste" msgid="5629880836805036433">"टाँस्नुहोस्"</string>
-    <string name="replace" msgid="5781686059063148930">"विस्थापन गर्नुहोस्…"</string>
-    <string name="delete" msgid="6098684844021697789">"मेट्नुहोस्"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL को प्रतिलिप गर्नुहोस्"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"पाठ चयन गर्नुहोस्"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"पाठ चयनता"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"शब्दकोशमा थप्नुहोस्"</string>
-    <string name="deleteText" msgid="6979668428458199034">"मेट्नुहोस्"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"निवेश विधि"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"पाठ कार्यहरू"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"भण्डारण ठाउँ सकिँदै छ"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"सायद केही प्रणाली कार्यक्रमहरूले काम गर्दैनन्"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> चलिरहेको छ"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"थप सूचनाको लागि छुनुहोस् वा अनुप्रयोग बन्द गर्नुहोस्।"</string>
-    <string name="ok" msgid="5970060430562524910">"ठिक छ"</string>
-    <string name="cancel" msgid="6442560571259935130">"रद्द गर्नुहोस्"</string>
-    <string name="yes" msgid="5362982303337969312">"ठिक छ"</string>
-    <string name="no" msgid="5141531044935541497">"रद्द गर्नुहोस्"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"सावधानी"</string>
-    <string name="loading" msgid="7933681260296021180">"लोड हुँदै..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"चालु"</string>
-    <string name="capital_off" msgid="6815870386972805832">"बन्द"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"प्रयोग गरेर कारबाही पुरा गर्नुहोस्"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"यस कार्यको लागि पूर्वनिर्धारितबाट प्रयोग गर्नुहोस्।"</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"प्रणाली सेटिङहरूमा पूर्वनिर्धारितलाई हटाउनुहोस् &gt; अनुप्रयोगहरू &gt; डाउनलोड।"</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"एउटा कार्यको चयन गर्नुहोस्"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB उपकरणको लागि एउटा अनुप्रयोग छान्नुहोस्"</string>
-    <string name="noApplications" msgid="2991814273936504689">"कुनै पनि अनुप्रयोगहरूले यो कार्य गर्न सक्दैनन्।"</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"दुर्भाग्यवश, <xliff:g id="APPLICATION">%1$s</xliff:g>ले रोकेको छ।"</string>
-    <string name="aerr_process" msgid="4507058997035697579">"दुर्भाग्यवश, प्रक्रिया <xliff:g id="PROCESS">%1$s</xliff:g> बन्द भयो।"</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g>ले कार्य गरिरहेको छैन।\n\nके तपाईँ यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"गतिविधि <xliff:g id="ACTIVITY">%1$s</xliff:g> ले प्रतिक्रिया देखाइरहेको छैन।\n\nके तपाईं यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> जवाफ दिइरहेको छैन। के तपाईँ यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"प्रक्रिया <xliff:g id="PROCESS">%1$s</xliff:g>ले कार्य गरिरहेको छैन।\n\nके तपाईँ यसलाई बन्द गर्न चाहनु हुन्छ?"</string>
-    <string name="force_close" msgid="8346072094521265605">"ठिक छ"</string>
-    <string name="report" msgid="4060218260984795706">"रिपोर्ट गर्नुहोस्"</string>
-    <string name="wait" msgid="7147118217226317732">"प्रतीक्षा गर्नुहोस्"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"पृष्ठ गैर जिम्मेवारी भएको छ।\n\nके तपाईं यसलाई बन्द गर्न चाहनुहुन्छ?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"अनुप्रयोग पुनः निर्देशीत"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> अहिले चलिरहेको छ।"</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> वास्तविक सुरुवात भएको थियो।"</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"स्केल"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"सधैँ देखाउनुहोस्"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"प्रणाली सेटिङहरूमा यसलाई पुनःसक्षम गराउनुहोस् &gt; अनुप्रयोगहरू &gt; डाउनलोड गरेको।"</string>
-    <string name="smv_application" msgid="3307209192155442829">"अनुप्रयोग <xliff:g id="APPLICATION">%1$s</xliff:g> (प्रक्रिया <xliff:g id="PROCESS">%2$s</xliff:g>) ले यसको स्वयं-लागु गरिएको स्ट्रिटमोड नीति उलङ्घन गरेको छ।"</string>
-    <string name="smv_process" msgid="5120397012047462446">"प्रक्रिया <xliff:g id="PROCESS">%1$s</xliff:g> यसको आफ्नै कडामोड नीतिका कारण उल्लङ्घन गरिएको छ।"</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"एन्ड्रोइड अपग्रेड हुँदैछ…"</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"अनुप्रयोग अनुकुल हुँदै <xliff:g id="NUMBER_0">%1$d</xliff:g> को <xliff:g id="NUMBER_1">%2$d</xliff:g>।"</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"सुरुवात अनुप्रयोगहरू।"</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"बुट पुरा हुँदै।"</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> चलिरहेको छ"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"अनुप्रयोगमा स्विच गर्न छुनुहोस्"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"अनुप्रयोगहरू स्विच गर्ने हो?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"अर्को अनुप्रयोग पहिले नै चालु छ जुन तपाईंले एउटा नयाँ सुरु गर्नु अघि बन्द गर्नुपर्ने हुन्छ।"</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g> मा फर्कनुहोस्"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"नयाँ अनुप्रयोग सुरु नगर्नुहोस्।"</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> सुरु गर्नुहोस्"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"बचत नगरी पुरानो अनुप्रयोग रोक्नुहोस्।"</string>
-    <string name="sendText" msgid="5209874571959469142">"पाठको लागि एउटा प्रकार्य छान्नुहोस्"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"बजाउने मात्रा"</string>
-    <string name="volume_music" msgid="5421651157138628171">"मिडियाको मात्रा"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"ब्लुटुथको माध्यमद्वारा बजाइदै छ।"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"शान्त रिङ्गटोन सेट"</string>
-    <string name="volume_call" msgid="3941680041282788711">"इन-कल भोल्युम"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"ब्लुटुथ भित्री-कल मात्रा"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"आलर्म मात्रा"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"सूचना मात्रा"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"मात्रा"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"ब्लुटुथ भोल्युम"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"घन्टिको आवाज मात्रा"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"कला मात्रा"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"मिडियाको मात्रा"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"सूचना भोल्युम"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"पूर्वनिर्धारित रिङटोन"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"पूर्वनिर्धारित रिङटोन (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"कुनै पनि होइन"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"घन्टीका स्वरहरू"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"अज्ञात रिङटोन"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"वाइ-फाइ नेटवर्क उपलब्ध छ"</item>
-    <item quantity="other" msgid="4192424489168397386">"वाइ-फाइ नेटवर्कहरू उपलब्ध"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"खुल्ला वाइ-फाइ नेटवर्क उपलब्ध छ"</item>
-    <item quantity="other" msgid="7915895323644292768">"खुल्ला वाइ-फाइ नेटवर्क उपलब्ध छ"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"वाइ-फाइ नेटवर्कमा साइन गर्नुहोस्"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"नेटवर्कमा साइन गर्नुहोस्।"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"वाइ-फाइसँग जडान गर्न सकेन"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" कमजोर इन्टरनेट जडान छ।"</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"वाइ-फाइ प्रत्यक्ष"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"वाइ-फाइ सिधा सुरु गर्नुहोस्। यसले वाइ-फाइ ग्राहक/हट्स्पटलाई बन्द गराउने छ।"</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"वाइ-फाइ सिधा सुरु हुन सकेन।"</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"वाइ-फाइ प्रत्यक्ष खुल्ला छ"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"सेटिङहरूको लागि छुनुहोस्"</string>
-    <string name="accept" msgid="1645267259272829559">"स्वीकार्नुहोस्"</string>
-    <string name="decline" msgid="2112225451706137894">"अस्वीकार गर्नुहोस्"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"निमन्त्रणा पठाइएको"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"जडानमा निमन्त्रणा"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"बाट:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"प्रापक:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"आवश्यक PIN टाइप गर्नुहोस्:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"यो <xliff:g id="DEVICE_NAME">%1$s</xliff:g>सँग जोडिएको बेला ट्याब्लेट अस्थायी रूपमा वाइ-फाइबाट विच्छेद गरिने छ।"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"जब यो <xliff:g id="DEVICE_NAME">%1$s</xliff:g> सँग जडित हुन्छ, फोन अस्थायी रूपमा वाइ-फाइबाट विच्छेद हुने छ"</string>
-    <string name="select_character" msgid="3365550120617701745">"अक्षरहरू प्रवेश गराउनुहोस्"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS सन्देशहरू पठाइँदै"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; ले धरै संख्यामा SMS सन्देशहरू पठाउँदैछ। के तपाईँ यस अनुप्रयोगलाई सन्देशहरू पठाउन सुचारु गर्न अनुमति दिन चाहनु हुन्छ?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"अनुमति दिनुहोस्"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"अस्वीकार गर्नुहोस्"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; के तपाईँ सन्देश पठाउन चाहुनु हुन्छ &lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;/b&gt;."</string>
-    <string name="sms_short_code_details" msgid="3492025719868078457">"यसले "<font fgcolor="#ffffb060">" शुल्क लगाउन सक्छ"</font>" तपाईँको मोबाइल खातामा।"</string>
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"यसले तपाईंको मोबाइल खातामा चार्जहरू उत्पन्न गर्दछ।"</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"पठाउनुहोस्"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"रद्द गर्नुहोस्"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"मेरो छनौट याद राख्नुहोस्"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"तपाईँ यसलाई पछि सेटिङहरूमा बदल्न सक्नु हुन्छ &gt; अनुप्रयोगहरू"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"सधैँ अनुमति दिनुहोस्"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"कहिल्यै अनुमति नदिनुहोस्"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM कार्ड हटाइयो"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"एउटा मान्य SIM कार्ड राखेर पुनःस्टार्ट नगरेसम्म मोबाइल नेटवर्क उपलब्ध हुने छैन।"</string>
-    <string name="sim_done_button" msgid="827949989369963775">"भयो"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM कार्ड थप गरियो"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"मोबाइल नेटवर्क पहुँच गर्न तपाईँको उपकरण पुनःस्टार्ट गर्नुहोस्।"</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"पुनःस्टार्ट गर्नुहोस्"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"समय मिलाउनुहोस्"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"मिति मिलाउनुहोस्"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"सेट गर्नुहोस्"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"भयो"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"नयाँ: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g>द्वारा प्रदान गरिएको।"</string>
-    <string name="no_permissions" msgid="7283357728219338112">"कुनै अनुमति आवश्यक छैन"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"सायद तपाईँलाई पैसा पर्न सक्छ।"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB ठूलो भण्डारण"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB जोडिएको छ"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"तपाईं आफ्नो कम्प्युटरमा USB मार्फत जडान हुनुभयो। तलको बटन टच गर्नुहोस् यदि तपाईं आफ्नो कम्प्युटर र एन्ड्रोइडको USB भण्डारण बीच फाइलहरू प्रतिलिपि गर्न चाहनुहुन्छ भने।"</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"तपाईं आफ्नो कम्प्युटरमा USB मार्फत जडान हुनुभयो। तलको बटन टच गर्नुहोस् यदि तपाईं आफ्नो कम्प्युटर र एन्ड्रोइडको SD कार्ड बीच फाइलहरू प्रतिलिपि गर्न चाहनुहुन्छ भने।"</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB भण्डारण चालु गर्नुहोस्"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB आम भण्डारणको लागि तपाईँको USB भण्डारण प्रयोग गर्दा एउटा समस्या भयो।"</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"USB आम भण्डारणको लागि तपाईँको SD कार्ड प्रयोग गर्दा एउटा समस्या भयो।"</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB जोडिएको छ"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"तपाईँको कम्प्युटरबाट वा तिर फाइलहरू प्रतिलिप गर्न छुनुहोस्।"</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB भण्डारण बन्द गर्नुहोस्"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB भण्डारण बन्द गर्न छुनुहोस्।"</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB भण्डारण प्रयोगमा छ"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB भण्डारण बन्द हुनुभन्दा पहीले तपाईँको कम्प्युटरबाट तपाईँको एन्ड्रोइड USB भण्डारण अनमाउन्ट (\"झिक्नुहोस्\") गर्नुहोस् ।"</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB भण्डारण बन्द गर्नुअघि तपाईँको कम्प्युटरबाट तपाईँको एन्ड्रोइडको SD कार्ड अनमाउन्ट (\"निकालेको\") गर्नुहोस्।"</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB भण्डारण बन्द गर्नुहोस्"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB भण्डारण बन्द गर्दा एउटा समस्या भयो। तपाईँले USB होस्ट अनमाउन्ट गर्नु भएको जाँच गर्नुहोस्, त्यसपछि फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB भण्डारण खोल्नुहोस्"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"यदि तपाईँले USB भण्डारण खोल्नु भयो भने तपाईँले प्रयोग गरिरहनु भएका केही अनुप्रयोगहरू रोकिने छन् र तपाईँले USB भण्डारण बन्द नगरेसम्म अनुपलब्ध हुन सक्छन्।"</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB संचालन असफल"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"ठिक छ"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"मिडिया उपकरणको रूपमा जडित"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"क्यामेराको रूपमा जडान भएको"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"एउटा स्थापनकर्ताको रूपमा जोडिएको छ"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB सहायकमा जोडिएको छ"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"अन्य USB विकल्पहरूको लागि टच गर्नुहोस्।"</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB भण्डारणलाई फर्म्याट  गर्न चाहनु हुन्छ?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD कार्ड फर्म्याट गर्ने?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"तपाईंको USBमा सङ्ग्रह भएका सबै फाइलहरू मेटिने छन्। यो कार्य उल्टाउन सकिँदैन!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"तपाईँको कार्डमा भएका सबै डेटाहरू हराउने छन्।"</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"फर्म्याट गर्नुहोस्"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB डिबग गर्ने जडित छ"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB डिबग गर्ने असक्षम पार्न छुनुहोस्।"</string>
-    <string name="select_input_method" msgid="4653387336791222978">"निवेश विधि छान्नुहोस्"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"इनपुट विधिहरू सेटअप गर्नुहोस्"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"भौतिक किबोर्ड"</string>
-    <string name="hardware" msgid="7517821086888990278">"हार्डवेयर"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"किबोर्ड रूपरेखा चयन गर्नुहोस्"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"किबोर्ड रूपरेखा चयन गर्न टच गर्नुहोस्।"</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"उम्मेदवार"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB भण्डारणको तयारी हुँदै"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD कार्ड तयार गर्दै"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"त्रुटिहरूको लागि जाँच गर्दै।"</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"रिक्त USB भण्डारण"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"खाली SD कार्ड"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"USB भण्डारण खाली वा असमर्थित फाइल प्रणाली छ।"</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD कार्ड खाली छ अथवा समर्थन नगरिएको फाइल प्रणाली छ।"</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"बिग्रिएको USB भण्डारण"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"बिग्रिएको SD कार्ड"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB भण्डारण बिग्रिएको छ। यसलाई पुनःफर्म्याट गर्न प्रयास गर्नुहोस।"</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD कार्ड बिग्रिएको छ। यसलाई पुनःफर्म्याट गर्न प्रयास गर्नुहोस।"</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"USB भण्डारण अप्रत्याशित रूपमा हटाइएको छ"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD कार्ड अनपेक्षित रूपमा हटाइयो"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"डेटा गुम्नबाट रोक्नको लागि USB भण्डारण हटाउनुअघि अनमाउन्ट गर्नुहोस्।"</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"डेटा नाश हुनबाट बच्न SD कार्डलाई निकाल्नुभन्दा पहिला अनमाउन्ट गर्नुहोस्।"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"USB भण्डारण हटाउनको लागि सुरक्षित छ"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD कार्ड हटाउन सुरक्षित छ।"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"तपाईं सुरक्षित रूपमा USB भण्डारण हटाउन सक्नुहुने छ।"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"तपाईँ SD कार्ड सुरक्षित रूपमा हटाउन सक्नु हुन्छ।"</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"USB भण्डारण हटाइयो"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"हटाइएको SD कार्ड"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USD भण्डारण हटाइयो। नयाँ मिडिया घुसाउनुहोस्।"</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD कार्ड हटाइयो। एउटा नयाँ छिराउनुहोस्।"</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"कुनै मिल्ने गतिविधि पाइएन।"</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"खण्ड प्रयोग तथ्याङ्कहरू अपडेट गर्नुहोस्"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"जम्मा गरिएको घटक उपयोग तथ्याङ्कहरूलाई परिमार्जन गर्न अनुप्रयोगलाई अनुमति दिन्छ। सामान्य अनुप्रयोगहरूबाट प्रयोगको लागि होइन।"</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"सामाग्रीको नकल गर्नुहोस्"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"अनुप्रयोगलाई सामग्री प्रतिलिपि गर्न पूर्वनिर्धारित कन्टेनर सेवा आह्वान गर्न अनुमति दिन्छ। साधारण अनुप्रयोगहरूद्वाराको प्रयोगको लागि होइन।"</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"मिडिया परिणाम दिशानिर्देश गर्नुहोस्"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"मिडिया परिणामलाई अन्य बाहिरी उपकरणहरूसँग लैजानको लागि अनुप्रयोगलाई अनुमति दिन्छ।"</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"किगार्ड सुरक्षित भण्डारण पहुँच गर्नुहोस्"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"अनुप्रयोगलाई किगार्ड सुरक्षित भण्डारण पहुँच गर्न अनुमति दिन्छ।"</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"किगार्ड प्रदर्शन गर्ने र लुकाउने नियन्त्रण गर्नुहोस्"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"अनुप्रयोगलाई किगार्ड नियन्त्रण गर्न अनुमति दिन्छ।"</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"जुम नियन्त्रणको लागि दुई चोटि टच गर्नुहोस्"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"विजेट थप गर्न सकिँदैन।"</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"जानुहोस्"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"खोज्नुहोस्"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"पठाउनुहोस्"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"अर्को"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"भयो"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"अघिल्लो"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"चलाउनुहोस्"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">\n"नम्बर डायल गर्नुहोस् <xliff:g id="NUMBER">%s</xliff:g> प्रयोग गरेर"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"सम्पर्क सिर्जना गर्नुहोस्\nयो <xliff:g id="NUMBER">%s</xliff:g> प्रयोग गरेर"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"निम्न एउटा वा धेरै अनुप्रयोगहरूले तपाईँको खातामा पहुँचको लागि अनुमति अहिले र भविष्यमा अनुरोध गर्छन्।"</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"के तपाईँ यस अनुरोधलाई अनुमति दिन चाहनुहुन्छ?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"अनुरोध पहुँच गर्नुहोस्"</string>
-    <string name="allow" msgid="7225948811296386551">"अनुमति दिनुहोस्"</string>
-    <string name="deny" msgid="2081879885755434506">"अस्वीकार गर्नुहोस्"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"अनुरोध गरिएको अनुमति"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">\n"खाता <xliff:g id="ACCOUNT">%s</xliff:g>को लागि अनुरोध गरिएको अनुमति।"</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"इनपुट विधि"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"सिङ्क गर्नुहोस्"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"उपलब्धता"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"वालपेपर"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"वालपेपर परिवर्तन गर्नुहोस्"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"सूचना सुन्नेवाला"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN सक्रिय भयो"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"VPN <xliff:g id="APP">%s</xliff:g>द्वारा सक्रिय गरिएको हो"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"नेटवर्क प्रबन्ध गर्न छुनुहोस्।"</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g>सँग जोडिएको छ। नेटवर्क व्यवस्थापन गर्नको लागि छुनुहोस्।"</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"VPN जडान सधै जोड्दै…"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"सधैँ खुल्ला हुने VPN जोडिएको"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"सधैँ भरि VPN त्रुटिमा"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"कन्फिगर गर्न टच गर्नुहोस्"</string>
-    <string name="upload_file" msgid="2897957172366730416">"फाइल छान्नुहोस्"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"कुनै फाइल छानिएको छैन"</string>
-    <string name="reset" msgid="2448168080964209908">"पुनःसेट गर्नु"</string>
-    <string name="submit" msgid="1602335572089911941">"पेस गर्नुहोस्"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"कार मोड सक्षम पारियो।"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"कार मोडबाट निस्कन छुनुहोस्।"</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"टेथर गर्ने वा हटस्पट सक्रिय"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"सेटअप गर्न टच गर्नुहोस्।"</string>
-    <string name="back_button_label" msgid="2300470004503343439">"पछाडि"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"अर्को"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"छोड्नुहोस्"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"उच्च मोबाइल डेटा प्रयोग"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"मोबाइल डेटा प्रयोगको बारेमा अरू थप जान्नको लागि  छुनुहोस्।"</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"मोबाइल डेटा सीमा पार भयो"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"मोबाइल डेटा प्रयोग बारे थप सिक्न छुनुहोस्।"</string>
-    <string name="no_matches" msgid="8129421908915840737">"कुनै मिलेन"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"पृष्ठमा फेला पार्नुहोस्"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"१ मेल"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="TOTAL">%d</xliff:g> को <xliff:g id="INDEX">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"भयो"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB  भण्डारण अनमाउन्ट गर्दै..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD कार्ड अनमाउन्ट गर्दै…"</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB भण्डारण मेटाउँदै…"</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD कार्ड मेटाउँदै…"</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB भण्डारणलाई मेटाउन सकेन।"</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD कार्ड मेटाउन सकेन"</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"SD कार्ड अनमाउन्ट हुनुभन्दा पहिला निकालियो।"</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"अहिले USB भण्डारण जाँच भइरहेको छ।"</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD कार्ड अहिले परीक्षण भइरहेको छ।"</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD कार्ड हटाइयो।"</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"SD कार्ड कम्प्युटरद्वारा अहिले प्रयोगमा छ।"</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD कार्ड अहिले कम्प्युटरद्वारा प्रयोगमा छ।"</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"बाह्य मिडिया अज्ञात अवस्थामा।"</string>
-    <string name="share" msgid="1778686618230011964">"साझेदारी गर्नुहोस्"</string>
-    <string name="find" msgid="4808270900322985960">"पत्ता लगाउनुहोस्"</string>
-    <string name="websearch" msgid="4337157977400211589">"वेब खोजी"</string>
-    <string name="find_next" msgid="5742124618942193978">"अर्को भेटाउनुहोस्"</string>
-    <string name="find_previous" msgid="2196723669388360506">"अघिल्लो फेला पार्नुहोस्"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> बाट स्थान अनुरोध"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"स्थान अनुरोध"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) द्वारा अनुरोध गरिएको"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"हो"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"होइन"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"सीमा नाघेकाहरू मेट्नुहोस्"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"त्यहाँ <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> मेटाइएका आइटमहरू छन् <xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g>को लागि, खाता <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g>। तपाईं के गर्न चाहनु हुन्छ?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"वस्तुहरू मेट्नुहोस्"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"मेटिएकाहरू पूर्ववत बनाउनुहोस्।"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"अहिलेको लागि केही नगर्नुहोस्"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"एउटा खाता छान्‍नुहोस्"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"एउटा खाता थप्नुहोस्"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"खाता थप गर्नुहोस्"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"बढाउनुहोस्"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"घटाउनुहोस्"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g>छुनुहोस् र समाउनुहोस्।"</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"बढाउन माथि र घटाउन तल सार्नुहोस्।"</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"मिनेट बढाउनुहोस्"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"मिनेट घटाउनुहोस्"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"घन्टा बढाउनुहोस्"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"घन्टा घटाउनुहोस्"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"PM सेट गर्नुहोस्"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"AM सेट गर्नुहोस्"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"महिना बढाउनुहोस्"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"महिना घटाउनुहो्स्"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"दिन बढाउनुहोस्"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"दिन घटाउनुहोस्"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"वर्ष बढाउनुहोस्"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"वर्ष घटाउनुहोस्"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"रद्द गर्नुहोस्"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"मेट्नुहोस्"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"भयो"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"मोड परिवर्तन गर्नुहोस्"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"प्रविष्टि गर्नुहोस्"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"एउटा अनुप्रयोग छान्नुहोस्"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"साझेदारी गर्नुहोस्..."</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g> सँग साझेदारी गर्नुहोस्"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"धिसार्ने ह्यान्डल। छुनुहोस् &amp; समाउनुहोस्।"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>को लागि माथि धिसार्नुहोस्"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> को लागि तल स्लाइड गर्नुहोस्।"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"स्लाइड <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>को लागि बायाँ।"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"स्लाइड <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>को लागि दायाँ।"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"अनलक गर्नुहोस्"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"क्यामेरा"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"मौन"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"आवाज चालू"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"खोज्नुहोस्"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"खोल्नलाइ हुत्त्याउनुहोस्।"</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"बोलिएको पासवर्ड कुञ्जीहरू सुन्नको लागि हेडसेट प्लग इन गर्नुहोस्।"</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"डट।"</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"गृह खोज्नुहोस्"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"माथि खोज्नुहोस्"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"थप विकल्पहरू"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"आन्तरिक भण्डारण"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD कार्ड"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB भण्डारण"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"सम्पादन गर्नुहोस्"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"डेटा प्रयोग चेतावनी"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"उपयोग र सेटिङहरू हेर्न छुनुहोस्।"</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G डेटा असक्षम गरिएको"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G डेटा असक्षम गरियो"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"मोबाइल डेटा असक्षम पारियो।"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"वाइ-फाइ डेटा असक्षम गरियो"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"सक्षम पार्न छुनुहोस्।"</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G डेटा सीमा भन्दा पार भएको छ"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G डेटा SIMा नाघ्यो"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"मोवाइल डेटा SIMा नाघ्यो"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"वाइ-फाइ डेटा SIMा नाघ्यो"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"<xliff:g id="SIZE">%s</xliff:g> उल्लेखित सीमा भन्दा बढी छ।"</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"पृष्ठभूमिका डेटा प्रतिबन्धित गरिएको छ"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"अवरोध हटाउन छुनुहोस्।"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"सुरक्षा प्रमाणपत्र"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"प्रमाणपत्र मान्य छ।"</string>
-    <string name="issued_to" msgid="454239480274921032">"द्वारा जारी गरिएको:"</string>
-    <string name="common_name" msgid="2233209299434172646">"साधारण नाम:"</string>
-    <string name="org_name" msgid="6973561190762085236">"संगठन:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"संगठनात्मक एकाइ:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"द्वारा जारी गरिएको:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"मान्यता:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"जारी गरिएको:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"अवधि समाप्त:"</string>
-    <string name="serial_number" msgid="758814067660862493">"क्रम संख्या:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"औँठाछापहरू:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-२५६ औंठाछाप:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 औंलाछाप:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"सबै हेर्नुहोस्"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"गतिविधि छनौट गर्नुहोस्"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"साझेदारी गर्नुहोस्..."</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"उपकरण लक छ।"</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"पठाउँदै..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"ब्राउजर सुरु गर्ने हो?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"कल स्वीकार गर्नुहुन्छ?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"सधैँ"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"एउटा मात्र"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"ट्याब्लेट"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"फोन"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"हेडफोनहरू"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"डक स्पिकरहरू"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"प्रणाली"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"ब्लुटुथ अडियो"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"ताररहित प्रदर्शन"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"भयो"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"मिडियाको उत्पादन"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"स्क्यान गर्दै ..."</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"जडान हुँदै..."</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"उपलब्ध"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"उपलब्ध छैन"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"प्रयोगमा छ"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"पूर्व-निर्मित स्क्रिन"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI स्क्रिन"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"आवरण #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", सुरक्षित"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"ताररहित प्रदर्शन जोडिएको छ"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"अर्को उपकरणमा यो स्क्रिनले देखाइरहेको छ"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"विच्छेदन गर्नुहोस्"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"आपतकालीन कल"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"ढाँचा बिर्सनु भयो"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"गलत ढाँचा"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"गलत पासवर्ड"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"गलत PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%1$d</xliff:g>सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"आफ्नो ढाँचा कोर्नुहोस्"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"पासवर्ड प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM कार्ड अहिले असक्षम छ। सुचारु गर्नको लागि PUK कोड प्रविष्टि गर्नुहोस्।  विवरणको लागि वाहकलाई सम्पर्क गर्नुहोस्।"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"इच्छित PIN कोड प्रविष्टि गर्नुहोस्"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"मनपर्दो PIN कोड निश्चित गर्नुहोस्"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM कार्ड अनलक गर्दै…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"गलत PIN कोड।"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"४ देखि ८ वाट नम्बर भएको एउटा PIN टाइप गर्नुहोस्।"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK कोड ८ वटा नम्बर वा सो भन्दा बढी हुनुपर्छ।"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"PUK कोड पुन:प्रदान गर्नुहोस्। धेरै पुन:प्रयासहरूले SIMलाई स्थायी रूपमा निष्क्रिय गरिदिने छ।"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN कोडहरू मेल खाएन"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"निकै धेरै ढाँचा कोसिसहरू"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"अनलक गर्नको लागि, तपाईँको Google खाताको साथ साइन इन गर्नुहोस्।"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"प्रयोगकर्ता नाम (इमेल)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"पासवर्ड"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"साइन इन गर्नुहोस्"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"अमान्य प्रयोगकर्तानाम वा पासवर्ड।"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"के तपाईँले उपयोगकर्ता नाम वा पासवर्ड बिर्सनुभयो?\n"<b>"google.com/accounts/recovery"</b>" मा जानुहोस्।"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"खाता जाँच हुँदै…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"तपाईँले गलत तरिकाले तपाईँको PIN <xliff:g id="NUMBER_0">%d</xliff:g> पटक टाइप गर्नु भएको छ। \n\n<xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"तपाईँले तपाईँक पासवर्ड <xliff:g id="NUMBER_0">%d</xliff:g> पटक गलत टाइप गर्नुभएको छ। \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि प्रयास गर्नुहोस्।"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"तपाईँले तपाईँको अनलक ढाँचा गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक खिच्नु भएको छ। \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकेन्डमा फेरि कोसिस गर्नुहोस्।"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"तपाईँले ट्याब्लेटलाई अनलक गर्न गलत तरिकाले <xliff:g id="NUMBER_0">%d</xliff:g> पटक कोसिस गर्नु भएको छ। <xliff:g id="NUMBER_1">%d</xliff:g> पछि थप असफल प्रयासहरू, ट्याब्लेट पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ र सबै प्रयोग डेटा हराउने छ।"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"तपाईँले गलतसँग फोनलाई अनलक गर्न <xliff:g id="NUMBER_0">%d</xliff:g> पटक कोसिस गर्नु भयो। <xliff:g id="NUMBER_1">%d</xliff:g> पछि थप असफल कोसिसहरू, फोनलाई पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ र सबै प्रयोग डेटा हराउने छ।"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"तपाईँले ट्यब्लेटलाई अनलक गर्न गलत तरिकाले <xliff:g id="NUMBER">%d</xliff:g> पटक प्रयास गर्नु भएको छ। अब ट्याब्लेटलाई पूर्वनिर्धारित कार्यशालामा पुनःसेट गरिने छ।"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"तपाईंले गलत तरिकाले फोन <xliff:g id="NUMBER">%d</xliff:g> पटक अनलक गर्ने प्रयत्न गर्नुभयो। अब फोन फ्याक्ट्रि पूर्वनिर्धारितमा पुनःसेट हुने छ।"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"तपाईंले गलत तरिकाले आफ्नो अनलक ढाँचा <xliff:g id="NUMBER_0">%d</xliff:g> पटक कोर्नुभयो। <xliff:g id="NUMBER_1">%d</xliff:g> विफल प्रयत्नहरू पछि, तपाईंलाई आफ्नो ट्याब्लेट इमेल खाता प्रयोग गरेर अनलक गर्न सोधिने छ।\n\n फेरि प्रयास गर्नुहोस् <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डहरूमा।"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"तपाईँले आफ्नो अनलक ढाँचा गलत रूपमा <xliff:g id="NUMBER_0">%d</xliff:g> पटक तान्नु भएको छ। <xliff:g id="NUMBER_1">%d</xliff:g> धेरै असफल प्रयासहरूपछि, तपाईँलाई एउटा इमेल खाताको प्रयोग गरेर तपाईँको फोन अनलक गर्न सोधिने छ।\n\n फेरि <xliff:g id="NUMBER_2">%d</xliff:g> सेकेन्डमा प्रयास गर्नुहोस्।"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"हटाउनुहोस्"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"आवाज सल्लाह दिएको तहभन्दा माथि  बढाउने हो?\nठूलो आवाजमा सुन्दा लामो समयको लागि तपाईँको सुन्ने शक्तीलाई खत्तम पार्न सक्छ।"</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"उपलब्धता सक्षम पार्न दुईवटा औंलाहरूले थिचिरहनुहोस्।"</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"पहुँच सक्षम गरिएको।"</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"पहुँचयोग्यता रद्द गरियो।"</string>
-    <string name="user_switched" msgid="3768006783166984410">"अहिलेको प्रयोगकर्ता <xliff:g id="NAME">%1$s</xliff:g>।"</string>
-    <string name="owner_name" msgid="2716755460376028154">"मालिक"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"त्रुटि"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"प्रतिबन्धित प्रोफाइलहरूको लागि यस अनुप्रयोगले खाताहरू समर्थन गर्दैन"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"यस कार्य सम्हालने कुनै अनुप्रयोग भेटिएन"</string>
-    <string name="revoke" msgid="5404479185228271586">"रद्द गर्नुहोस्"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"पत्र"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"सरकारी पत्र"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"कानूनी"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"Junior Legal"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"Ledger"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"Tabloid"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"रद्द गरियो"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"सामाग्री लेखनमा त्रुटि"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN प्रविष्टि गर्नुहोस्"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"वर्तमान PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"नयाँ PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"नयाँ PIN निश्चित गर्नुहोस्"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"प्रतिबन्धहरूलाई परिवर्तन गर्नको लागि एउटा PIN बनाउनुहोस्"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN हरू मेल खाएनन्। पुनः प्रयास गर्नुहोस्।"</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN अति छोटो भयो। कम्तीमा ४ अङ्क हुन आवश्यक छ।"</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"गलत PIN । १ सेकेन्डमा पुनः प्रयास गर्नुहोस्।"</item>
-    <item quantity="other" msgid="8030607343223287654">"गलत PIN । <xliff:g id="COUNT">%d</xliff:g> सेकेन्डमा पुनः प्रयास गर्नुहोस्।"</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"पट्टि देखिने बनाउन स्क्रिनको छेउमा स्वाइप गर्नुहोस्"</string>
-</resources>
diff --git a/core/res/res/values-nl/strings.xml b/core/res/res/values-nl/strings.xml
index 24d6c66..30afea7 100644
--- a/core/res/res/values-nl/strings.xml
+++ b/core/res/res/values-nl/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Probeer het over <xliff:g id="COUNT">%d</xliff:g> seconden opnieuw"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Probeer het later opnieuw"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Van boven omlaag vegen: voll. scherm sluiten"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Veeg omlaag vanaf de bovenkant om het volledige scherm te sluiten."</string>
 </resources>
diff --git a/core/res/res/values-pl/strings.xml b/core/res/res/values-pl/strings.xml
index edbbe12..0e1bee9 100644
--- a/core/res/res/values-pl/strings.xml
+++ b/core/res/res/values-pl/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Spróbuj za <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Spróbuj ponownie później"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Przesuń z góry w dół, by zamknąć pełny ekran"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Przesuń z góry w dół, by zamknąć pełny ekran."</string>
 </resources>
diff --git a/core/res/res/values-pt-rPT/strings.xml b/core/res/res/values-pt-rPT/strings.xml
index bc9dddf..f3c4020 100644
--- a/core/res/res/values-pt-rPT/strings.xml
+++ b/core/res/res/values-pt-rPT/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Tente em: <xliff:g id="COUNT">%d</xliff:g> seg"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Tente novamente mais tarde"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Deslize para baixo para sair do ecrã inteiro"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Deslize rapidamente para baixo para sair do ecrã inteiro."</string>
 </resources>
diff --git a/core/res/res/values-pt/strings.xml b/core/res/res/values-pt/strings.xml
index f81af65..15a6130 100644
--- a/core/res/res/values-pt/strings.xml
+++ b/core/res/res/values-pt/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Tente novamente em <xliff:g id="COUNT">%d</xliff:g> segundos"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Tente novamente mais tarde"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Deslize para baixo para sair da tela inteira"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Deslize para baixo para sair da tela inteira"</string>
 </resources>
diff --git a/core/res/res/values-rm/strings.xml b/core/res/res/values-rm/strings.xml
index 6607f02..9154621 100644
--- a/core/res/res/values-rm/strings.xml
+++ b/core/res/res/values-rm/strings.xml
@@ -2732,6 +2732,7 @@
     <!-- no translation found for restr_pin_countdown:other (4730868920742952817) -->
     <!-- no translation found for restr_pin_try_later (973144472490532377) -->
     <skip />
+    <!-- no translation found for immersive_mode_confirmation (7227416894979047467) -->
     <!-- no translation found for immersive_mode_confirmation (8554991488096662508) -->
     <skip />
 </resources>
diff --git a/core/res/res/values-ro/strings.xml b/core/res/res/values-ro/strings.xml
index 7d8c5f2..dc5a211 100644
--- a/core/res/res/values-ro/strings.xml
+++ b/core/res/res/values-ro/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Reîncercați în <xliff:g id="COUNT">%d</xliff:g> sec."</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Reîncercați mai târziu"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Glisați în jos pt. a ieși din ecran complet"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Glisați în jos pentru a ieși din ecran complet."</string>
 </resources>
diff --git a/core/res/res/values-ru/strings.xml b/core/res/res/values-ru/strings.xml
index 3da5950..5348084 100644
--- a/core/res/res/values-ru/strings.xml
+++ b/core/res/res/values-ru/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Повтор через <xliff:g id="COUNT">%d</xliff:g> сек."</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Повторите попытку позже."</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Чтобы вернуться в обычный режим, проведите пальцем вниз"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Чтобы вернуться в обычный режим, проведите пальцем вниз"</string>
 </resources>
diff --git a/core/res/res/values-si-rLK/strings.xml b/core/res/res/values-si-rLK/strings.xml
deleted file mode 100644
index 367de51..0000000
--- a/core/res/res/values-si-rLK/strings.xml
+++ /dev/null
@@ -1,1591 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;නම් යොදා නැත&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(දුරකථන අංකයක් නොමැත)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(නොදනී)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"කටහඬ තැපෑල"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"සම්බන්ධතා ගැටළුවක් හෝ අවලංගු MMI කේතයකි."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"ස්ථාවර ඇමතීම් අංක වලට පමණක් මෙහෙයුම සීමාකර ඇත."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"සේවාව සබල කරන ලදි."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"සේවාව සබලයි, සඳහා:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"සේවාව අබල කරන ලදි."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"ලියාපදිංචි වීම සාර්ථකයි."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"මැකීම සාර්ථක විය."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"වැරදි මුරපදයක්."</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI සම්පූර්ණයි."</string>
-    <string name="badPin" msgid="9015277645546710014">"ඔබ ටයිප් කරන ලද පරණ PIN එක වැරදිය."</string>
-    <string name="badPuk" msgid="5487257647081132201">"ඔබ ටයිප් කරන ලද PUK එක වැරදියි."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"ඔබ ටයිප් කල PIN නොගැළපේ."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"4 සිට 8 දක්වා අංක සහිත PIN එකක් ටයිප් කරන්න."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"අංක 8 ක් හෝ ඊට වැඩි PUK එකක් ටයිප් කරන්න."</string>
-    <string name="needPuk" msgid="919668385956251611">"ඔබගේ SIM පත පතට PUK අගුළු වැටී ඇත. එම අගුල ඇරීමට PUK කේතය ටයිප් කරන්න."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM පතේ අගුළු ඇරීමට PUK2 ටයිප් කරන්න."</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"පැමිණෙන අමතන්නාගේ ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"පිටතට යන අමතන්නාගේ ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"ඇමතුම ඉදිරියට යැවීම"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"ඇමතුම් රැඳීම"</string>
-    <string name="BaMmi" msgid="455193067926770581">"ඇමතුම අවහිර කිරීම"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"මුරපදය වෙනස් කිරීම"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN වෙනස් වී ඇත"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"ඇමතුම් අංකය ඇත"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"ඇමතුම් අංකය සීමා කර ඇත"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"තුන් මාර්ග ඇමතීම"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"අනවශ්‍ය හිරිහැරදායක ඇමතුම් ප්‍රතික්ෂේප කිරීම"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"ඇමතීමේ අංකය භාරදීම"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"බාධා නොකරන්න"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"අමතන්නාගේ ID සුපුරුද්ද අනුව සීමා වී ඇත. මීළඟ ඇමතුම: සීමා කර ඇත"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"අමතන්නාගේ ID සුපුරුදු අනුව සීමා වී ඇත. මීළඟ ඇමතුම: සීමා කර නැත"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"අමතන්නාගේ ID සුපුරුදු අනුව සීමා වී නැත. මීළඟ ඇමතුම: සීමා කර ඇත"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"අමතන්නාගේ ID සුපුරුදු අනුව සීමා වී නැත. මීළඟ ඇමතුම: සීමා කර ඇත"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"සේවාවන් සපයා නැත."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"අමතන්නාගේ ID සැකසීම ඔබට වෙනස්කල නොහැක."</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"සීමිත ප්‍රවේශය වෙනස් කෙරිණි"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"දත්ත සේවාව අවහිර කර ඇත."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"හදිසි සේවාව අවහිර කර ඇත."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"හඬ සේවාව බාධා කර ඇත."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"සියලු හඬ සේවා අවහිර කර ඇත."</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS සේවාව අවහිර කර ඇත."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"හඬ/දත්ත සේවා අවහිර කර ඇත."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"හඬ/SMS සේවා අවහිර කර ඇත."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"සියලුම හඬ/දත්ත/SMS සේවාවන් බාධා කර ඇත."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"හඬ"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"දත්ත"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"ෆැක්ස්"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"අසමමුහුර්ත කරන්න"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"සමමුහුර්ත කිරීම"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"පැකැට්ටුව"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"රෝමිං දර්ශකය සක්‍රියයි"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"රෝමිං දර්ශකය අක්‍රියයි"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"රෝමිං දර්ශකය සැණෙලි වෙයි"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"වටපිටාවෙන් ඉවත්ව"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"ගොඩනැගිල්ලෙන් පිටත"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"රෝමිං  - කැමති පද්ධතිය"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"රෝමිං  - ලබාගත හැකි පද්ධතිය"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"රෝමිං - මිත්‍ර හවුල්කරු"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"රෝමිං - අධිමිල හවුල්කරු"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"රෝමිං  - සම්පූර්ණ සේවා ක්‍රියාකාරිත්වය"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"රෝමිං - අසම්පූර්ණ සේවා ක්‍රියාකාරීත්වය"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"රෝමිං  බැනරය සක්‍රීයයි"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"රෝමිං බැනරය අක්‍රියයි"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"සේවාව සඳහා සොයමින්"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ඉදිරියට නොයවන ලදි"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: තත්පර <xliff:g id="TIME_DELAY">{2}</xliff:g> ට පසුව <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ඉදිරියට නොයවන ලදි"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ඉදිරියට නොයවන ලදි"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"අංග කේතය සම්පූර්ණයි."</string>
-    <string name="fcError" msgid="3327560126588500777">"සම්බන්ධතා ගැටළුවක් හෝ අවලංගු විශේෂාංග කේතයකි."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"හරි"</string>
-    <string name="httpError" msgid="7956392511146698522">"ජාල දෝෂයක් තිබුණි."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL ය සෙවිය නොහැක."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"අඩවියේ සත්‍යාපන පටිපාටිය වෙත සහය නොදක්වයි."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"සත්‍යාපනය කළ නොහැක"</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"ප්‍රොක්සි සේවාදායකය හරහා සත්‍යාපනය අසාර්ථකය."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"සේවාදායකයාට සම්බන්ධ විය නොහැක."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"සේවාදායකයා සමග සම්බන්ධ වීමට නොහැකි විය. නැවත උත්සහ කරන්න."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"සේවාදායකය වෙත සම්බන්ධතාවය කල් ඉකුත් විණි."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"පිටුවේ බොහෝ සේවාදායක නැවත හරවා යැවීම් අඩංගු වේ."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"ප්‍රොටෝකෝලය වෙත සහය නොදක්වයි."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"සුරක්ෂිත සම්බන්ධතාවයක් පිහිටුවීමට නොහැකි විය."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"URL වලංගු නොවන නිසා පිටුව විවෘත කිරීමට නොහැකි විය."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"ගොනුව වෙත පිවිසිය නොහැක."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"ඉල්ලන ලද ගොනු සෙවිය නොහැක."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"ඉල්ලීම් විශාල ප්‍රමාණයක් ක්‍රියාත්මක වෙමින් පවතියි. පසුව නැවත උත්සාහ කරන්න."</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g> සඳහා පුරනය වීමේ දෝෂයක්"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"සමමුහුර්ත කිරීම"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"සමමුහුර්ත කරන්න"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"<xliff:g id="CONTENT_TYPE">%s</xliff:g> මැකීම් වැඩිය"</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ටැබ්ලට් ආචයනය පිරි ඇත. ඉඩ නිදහස් කිරීමට සමහර ගොනු මකන්න."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"දුරකථන ආචයනය පිරී ඇත. ඉඩ නිදහස් කිරීමට සමහර ගොනු මකන්න."</string>
-    <string name="me" msgid="6545696007631404292">"මම"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ටැබ්ලට විකල්ප"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"දුරකථන විකල්පයන්"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"නිහඬ ආකාරය"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"නොරැහන් සක්‍රිය කරන්න"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"නොරැහැන් අක්‍රිය කරන්න"</string>
-    <string name="screen_lock" msgid="799094655496098153">"තිර අගුල"</string>
-    <string name="power_off" msgid="4266614107412865048">"බලය අක්‍රිය කරන්න"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"හඬ නඟනය අක්‍රියයි"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"හඬ නඟනය කම්පනය"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"හඬ නඟනය සක්‍රීයයි"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"වසා දමමින්…"</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"ඔබගේ ටැබ්ලටය වැසේ."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"ඔබගේ දුරකථනය වැසේ."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"ඔබට වසා දැමීමට අවශ්‍යද?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"ආරක්‍ෂිත ආකාරයට නැවත පණ ගන්වන්න"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"ආරක්‍ෂිත ආකාරයට නැවත පණ ගැන්වීමට ඔබට අවශ්‍යද? මෙමඟින් ඔබ ස්ථාපිත කර ඇති සියලුම තෙවන පාර්ශවීය යෙදුම් සියල්ල අබල වී යයි. ඔබ නැවත පණ ගන්වන විට ඒවා නැවත පිහිටුවීම සිදු වේ."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"මෑත"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"මෑත යෙදුම් නැත."</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ටැබ්ලට් විකල්ප"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"දුරකථන විකල්ප"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"තිර අගුල"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"බලය අක්‍රිය කරන්න"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"දෝෂ වර්තාව"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"දෝෂ වාර්තාවක් ගන්න"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"ඊ-තැපැල් පණිවිඩයක් ලෙස යැවීමට මෙය ඔබගේ වත්මන් උපාංග තත්වය ගැන තොරතුරු එකතු කරනු ඇත. දෝෂ වාර්තාව ආරම්භ කර එය යැවීමට සූදානම් කරන තෙක් එයට කිසියම් කාලයක් ගතවනු ඇත; කරුණාකර ඉවසන්න."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"නිහඬ ආකාරය"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"ශබ්දය අක්‍රියයි"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"හඬ සක්‍රියයි"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"අහස්යානා ආකාරය"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"අහස්යානා ආකාරය සක්‍රීයයි."</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"අහස්යානා අකාරය අක්‍රියයි"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"ආරක්‍ෂිත ආකාරය"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Android පද්ධතිය"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"ඔබගේ මුදල් වැයවන සේවාවන්"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"ඔබගෙන් මුදල් යන දේවල් කරන්න."</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"ඔබගේ පණිවිඩ"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"ඔබගේ SMS, ඊ-තැපැල්, සහ වෙනත් පණිවිඩ කියවන්න සහ ලියන්න."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"ඔබගේ පෞද්ගලික තොරතුරු"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"ඔබගේ සම්බන්ධතා පතේ ආචයනය කරන ලද, ඔබ ගැන තොරතුරු වලට ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"ඔබගේ සමාජයීය තොරතුරු"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"ඔබගේ සම්බන්ධතා සහ සාමාජ සම්බන්ධයන් ගැන තොරතුරු වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"ඔබගේ ස්ථානය"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"ඔබගේ භෞතික පිහිටුම නිරීක්ෂණය කරයි."</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"ජාල සන්නිවේදනය"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"විවිධ ජාල විශේෂාංග වෙත පිවිසෙන්න."</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"බ්ලූටූත්"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"බ්ලූටූත් ඔස්සේ උපාංග සහ ජාල වෙත පිවිසෙන්න."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"ශ්‍රව්‍ය සැකසීම්"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"ශ්‍රව්‍ය සැකසීම් වෙනස් කරන්න."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"බැටරිය වෙත බලපායි"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"බැටරියේ බලය ක්ෂණිකව අඩු වන විශේෂාංග භාවිත කරන්න."</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"දින දර්ශනය"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"දින දර්ශන සිද්ධින්ට සෘජුව ප්‍රවේශ වීම."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"පරිශීලක ශබ්ද කෝෂය කියවන්න"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"පරිශීලක ශබ්ද කෝෂයේ වචන කියවීම."</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"පරිශීලක ශබ්දකෝෂයට ලිවිම"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"පරිශීලක ශබ්දකෝෂයට වචන එකතු කරන්න."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"පිටුසන් සහ ඉතිහාසය"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"පිටුසන් සහ බ්‍රව්සර ඉතිහාසය වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"සීනුව"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"සීනුව සකසන්න."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"හඬ තැපෑල"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"හඬ තැපෑල වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"මයික්‍රොෆෝනය"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"ශබ්දය පටිගත කිරීමට මයික්‍රොෆෝනය වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"කැමරාව"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"ඡායාරූප හෝ වීඩියෝ ග්‍රහණය සඳහා කැමරාව වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"අගුළු තිරය"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"ඔබගේ උපාංගයේ අගුළු තිරයේ ක්‍රියාකාරිත්වයට බලපාන හැකියාව."</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"ඔබගේ යෙදුම් වල තොරතුරු"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"ඔබගේ උපාංගයේ වෙනත් යෙදුම් වල ක්‍රියාකාරිත්වයට බලපෑම් කළ හැකි බව."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"බිතුපත"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"උපාංග බිතුපතේ සැකසීම් වෙනස් කරන්න."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"ඔරලෝසුව"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"උපාංග කාල හෝ කාල කලාප වෙනස් කරන්න."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"තත්ව තීරුව"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"උපාංග තත්ව තීරු සැකසීම් වෙනස් කරන්න."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"සමමුහුර්ත සැකසීම්"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"සමමුහුර්ත සැකසීම් වෙත ප්‍රවේශය."</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"ඔබගේ ගිණුම්"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"ලබාගත හැකි ගිණුම් වලට ප්‍රවේශ වීම."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"දෘඩාංග පාලක"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"හෑන්ඩ්සෙටයේ දෘඩාංග වලට සෘජුවම ප්‍රවේශ වන්න."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"දුරකථන ඇමතුම්"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"දුරකථන ඇමතුම් නිරීක්ෂණය කරන්න, පටිගත කරන්න සහ ක්‍රියාත්මක කරන්න."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"පද්ධති මෙවලම්"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"පද්ධතියේ පහල මට්ටම් ප්‍රවේශය සහ පාලනය."</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"සංවර්ධක මෙවලම්"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"යෙදුම් සංවර්ධකයන් සඳහා පමණක් අවශ්‍ය විශේෂාංග."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"වෙනත් යෙදුම් UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"වෙනත් යෙදුම්වල UI සඳහා බලපායි."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"ආචයනය"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB ආචයනය වෙත ප්‍රවේශය."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD පත වෙත ප්‍රවේශය."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"ප්‍රවේශ්‍යතා විශේෂාංග"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"උපකාරීවන තාක්ෂණ ඉල්ලීම් කළ හැකි විශේෂාංග."</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"කවුළු අන්න්තර්ගතය ලබාගන්න"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"ඔබ අන්තර්ක්‍රියාකාරී වන කවුළුවේ අන්තර්ගතය පරීක්ෂා කරන්න."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"ස්පර්ශයෙන් ගවේෂණය සක්‍රිය කරන්න"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"ස්පර්ශ කරන අයිතම හඬ නගා කතා කෙරෙනු ඇති අතර ඉංගිති භාවිතයෙන් තිරය ගවේෂණය කිරීමට පුළුවනි."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"උසස් වෙබ් ප්‍රවේශ්‍යතාව සක්‍රිය කරන්න"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"යෙදුම් අන්තර්ගතයට ප්‍රවේශ්‍යතාවය වැඩිවන ලෙස සකස් කිරීමට ඇතැම් විට ස්ක්‍රිප්ට් ස්ථාපනය කර ඇත."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"ඔබ ටයිප් කළ පෙළ බලන්න"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"ණයවරපත් අංක සහ මුරපද වැනි පුද්ගලික දත්ත ඇතුළත් වේ."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"තත්ව තීරුව අබල කරන්න හෝ වෙනස් කරන්න"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"තත්ව තීරුව අක්‍රිය කිරීමට හෝ පද්ධති නිරූපක එකතු හෝ ඉවත් කිරීමට යෙදුමට අවසර දේ."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"තත්ව තීරුව"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"තත්ව තීරුව වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"තත්ව තීරුව දිග හැරීම/හැකිලීම"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"තත්ව තීරුව දිග හැරීමට හෝ හැකිළීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"පිටවන ඇමතුම් වල මග වෙනස් කිරීම"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"පිටවන ඇමතුම් සකස් කිරීමට සහ ඇමතීමට නියමිත අංකය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙන් යෙදුමට පිටවන ඇමතුම් නිරීක්ෂණය, නැවත හැරවීම හෝ වැළක්වීම අවසර දෙයි."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"කෙටි පණිවිඩ ලබාගැනීම (SMS)"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"SMS පණිවිඩ ලැබීමට සහ ක්‍රියාත්මක කිරීමට යෙදුමට අවසර දෙන්න. මෙහි තේරුම යෙදුමට ඔබගේ උපාංගයට ලැබෙන පණිවිඩ අධීක්ෂණය කිරීමට හැකිවීම වන අතර, ඒවා ඔබට නොපෙන්වා මකා දැමීමටද හැකි වීමයි."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"පෙළ පණිවුඩ ලබාගන්න (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"MMS පණිවිඩ සොයා ලබාගැනීමට සහ ක්‍රියාත්මක කිරීමට යෙදුමට අවසර දෙන්න. යෙදුම නිරීක්ෂණය කරනු ලබන අතර ඔබට ලැබුන පණිවිඩ පෙන්වීමෙන් තොරවම මකා දැමිය හැකි බව මෙමඟින් අදහස් කරයි."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"හදිසි විකාශන ලබා ගැනීම"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"හදිසි විකාශ පණිවිඩ ලැබීමට සහ ක්‍රියාත්මක කිරීමට යෙදුමට අවසර දෙන්න. පද්ධති යෙදුම් වලට පමණක් මෙම අවසරය අදාළ වෙයි."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"සෙල් ප්‍රචාරණ පණිවිඩ කියවීම"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"ඔබගේ උපාංගයට ලැබුණු සෙල් විකාශන පණිවිඩ කියවීමට යෙදුමට අවසර දෙන්න. ඔබට හදිසි අවස්ථාවන් පිළිබඳ අනතුරු ඇඟවීමට සෙල් විකාශන පණිවිඩ ඇතැම් ස්ථානවල සිට යවනු ලබයි. හදිසි සෙල් විකාශන ලැබෙන අවස්ථාවකදී, අනිෂ්ට යෙදුම් මඟින් ඔබගේ උපාංගයට කාර්ය සාධනයට හෝ ක්‍රියකරණයට බාධා සිදුවිය හැක."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS පණිවිඩ යැවීම"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"SMS පණිවිඩ යැවීමට යෙදුමට අවසර දෙන්න. මෙමඟින් බලාපොරොත්තු නොවූ ප්‍රතිඵල අත් විය හැක. අනිෂ්ට යෙදුම් ඔබගේ තහවුරුවකින් තොරව පණිවිඩ යැවීම මඟින් ඔබගේ මුදල් වැය කල හැක."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"පණිවිඩ සිදුවීම හරහා ප්‍රතිචාර යැවීම"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"පැමිණෙන ඇමතුම් සඳහා පණිවිඩ ඔස්සේ ප්‍රතිචාර සිදුවීම් හසුරුවීමට වෙනත් පණිවිඩ යෙදුම් සඳහා ඉල්ලීම් යැවීමට, යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"ඔබගේ පෙළ පණිවුඩ කියවන්න (SMS හෝ MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"ඔබගේ ටැබ්ලටයේ හෝ SIM පතේ ආචයනය කර ඇති SMS පණිවිඩ කියවීමට යෙදුමට අවසර දෙන්න. අන්තර්ගතය හෝ විශවාසදයි බවින් තොරවම සියලු SMS පණිවිඩ කියවීමට මෙමගින් යෙදුමට අවසර දෙයි."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"ඔබගේ දුරකථනයේ හෝ SIM පතේ ආචයනය කරන ලද SMS පණිවිඩ කියවීමට යෙදුමට අවසර දෙන්න. අන්තර්ගතය හෝ විශ්වාසදායී බවින් තොරවම සියලු SMS පණිවිඩ කියවීමට මෙමගින් යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"ඔබගේ කෙටි පණිවිඩ සංස්කරණය කිරීම (SMS හෝ MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"ඔබගේ ටැබ්ලටයේ හෝ SIM පතේ ගබඩා කර ඇති SMS පණිවිඩ වෙත ලිවීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් ඔබගේ පණිවිඩ මකා දැමිය හැක."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"ඔබගේ ටැබ්ලටයේ හෝ SIM පතේ ආචයනය කරන ලද SMS පණිවිඩ ලිවීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් ඔබගේ පණිවිඩ මකා දැමිය හැක."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"පෙළ පණිවිඩ ලබාගැනීම (WAP)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"WAP පණිවිඩ ලැබීමට සහ ක්‍රියාවලි කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙහි ඔබව ඒවාට පෙන්වීමකින් තොරව ඔබට පණිවිඩ නිරීක්ෂණයට හෝ මැකීමට හැකියාව ඇතුළත් වේ."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"ධාවනය වන යෙදුම් ලබාගැනීම"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"දැනට සහ මෑත ක්‍රියාත්මක කාර්යයන් පිළිබඳ විස්තරාත්මක තොරතුරු සොයා ලබාගැනීමට යෙදුමට ඉඩ දෙන්න. මෙය කුමන යෙදුම් උපාංගයේ භාවිතා කරන්නේද යන තොරතුරු යෙදුම්වලට සොයා ගැනීමට ඉඩ දිය හැක."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"පරිශීලකයන් අතර අන්තර්ක්‍රියාකාරී වන්න"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"උපාංගයේ විවිධ පරිශීලකයන් හරහා ක්‍රියාවන් දැක්වීමට යෙදුමට අවසර දෙන්න. පරිශීලකයන් අතර ආරක්ෂාව කඩකිරීමට අනිෂ්ට යෙදුම් විසින් මෙය භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"පරිශීලකයන් අතර අන්තර් ක්‍රියාකාරී වීමට සම්පූර්ණ බලපත්‍රය"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"පරිශීලකයන් හරහා සිදු කළ හැකි සියලු අන්තර් ක්‍රියා වලට අවසර දෙන්න."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"පරිශීලකයන් කළමනාකරණය කරන්න"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"විස්තර ලබා ගැනීම, නිර්මාණකරණය, මකාදැමීම ඇතුළු පරිශීලකයන් කළමනාකරණයට යෙදුම්වලට අවසර දෙන්න."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"ධාවනය වන යෙදුම් වල තොරතුරු සොයා ලබාගැනීම"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"දැනට සහ මෑතක ක්‍රියාත්මක කාර්යයන් පිළිබඳ විස්තරාත්මක තොරතුරු ලබාගැනීමට යෙදුමට අවසර දෙන්න අනිෂ්ට යෙදුම් අනෙකුත් යෙදුම් පිළිබඳ පුද්ගලික තොරතුරු සොයා ගැනීමට ඉඩ තිබේ."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"ධාවනය වන යෙදුම් නැවත අනුපිළිවෙලට සැකසීම"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"පෙරබිමට හෝ පසුබිමට සිදුවීම් ගෙනයාමට යෙදුමට අවසර දෙන්න. ඔබගේ ආදානයකින් තොරව යෙදුම මෙය සිදුකරයි."</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"යෙදුම් ධාවනය නවත්වන්න"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"කාර්යයන් ඉවත් කිරීමට සහ ඒවායෙහි යෙදුම් නැති කිරීමට යෙදුමට අවසර දෙන්න. අනෙක් යෙදුම් හැසිරීම බාධා කිරීමට අනිෂ්ට යෙදුම්වලට අවසර දෙන්න."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"ක්‍රියාකාරකම් අට්ටි කළමනාකරණය කරන්න"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"වෙනත් යෙදුම් ධාවනය වන ක්‍රියාකාරකම් අට්ටි වලට එකතු කිරීමට, ඉවත් කිරීමට, සහ වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම්වල හැසිරීම අනිෂ්ට යෙදුම් මගින් බාධා විය හැක."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"ඕනෑම ක්‍රියාවක් අරඹන්න"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"අවසර ආරක්ෂාව හෝ යැවුම් තත්වයෙන් තොරවම ඕනෑම ක්‍රියාවක් ආරම්භ කිරීමට යෙදුමට අවසර දේ."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"තිර ගැළපුම සැකසීම"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"වෙනත් යෙදුම්වල තිර ගැලපුම් මාදිලිය පාලනයට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම්වල හැසිරීම අනිෂ්ට යෙදුම් කැඩිය හැක."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"යෙදුම් නිදොස්කරණය සබල කිරීම"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"වෙනත් යෙදුමක් සඳහා නිදොස්කරණය සක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම් විනාශ කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"පද්ධති සංදර්ශක සැකසීම් වෙනස් කරන්න"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"පෙදෙසිය හෝ සම්පූර්ණ අකුරු ප්‍රමාණය වැනි පවතින වින්‍යාසය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"මෝටර් රථ ආකාරය ක්‍රියාත්මක කරන්න"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"කාර් ආකාරය සබල කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"වෙනත් යෙදුම් වැසීම"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"අනෙක් යෙදුම්වල පසුබිම් ක්‍රියාවලි අවසන් කිරීමට යෙදුමට අවසර දෙන්න. අනෙක් යෙදුම් ධාවනය නැවතීමට මෙය හේතුවක් වේ."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"වෙනත් යෙදුම් බලෙන් නවත්වන්න"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"යෙදුමට බලෙන් අනෙක් යෙදුම් නැවතීමට අවසර දෙන්න."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"යෙදුම වැසීමට බල කිරීම"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"නැවතීමට පෙරබිමේ ඇති ඕනෑම ක්‍රියාවක් බලෙන් නැවතීමට සහ පිටුපසට යාමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"පද්ධති අභ්‍යන්තර තත්වය සොයා ලබා ගන්න"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"පද්ධතියේ අභ්‍යන්තර තත්වය ලැබීමට යෙදුමට අවසර දෙන්න. ඔවුන් සාමාන්‍යයෙන් භාවිත නොකරන විවිධත්වයකින් යුත් පුද්ගලික සහ ආරක්‍ෂිත තොරතුරු අනිෂ්ට යෙදුම් සොයා ලබා ගත හැක."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"තිර අන්තර්ගතය සොයා ලබාගැනීම"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"ක්‍රියාකාරී කවුළුවක අන්තර්ගතය ලබාගැනීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් විසින් සම්පූර්ණ කවුළු අන්තර්ගතය ලබාගැනීම සහ මුරපදය හැර ඒවායෙහි පෙළ පරික්ෂා කිරීම සිදුකරයි."</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"ප්‍රවේශ්‍යතාවය තාවකාලිකව සබල කිරීම"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"උපාංගය වෙත ප‍්‍රවේශ්‍යතාව තාවකාලිකව සක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. පරිශීලක අවධානයකින් තොරව අනිෂ්ට යෙදුම් ප‍්‍රවේශ්‍යතාව සක්‍රිය කළ හැක."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"තිර තොරතුරු සොයා ලබාගැනීම"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"කවුළු කළමනාකරු මගින් කවුළුව ගැන තොරතුරු සොයා ලබාගැනීමට යෙදුමට අවසර දෙන්න. අභ්‍යන්තර පද්ධති භාවිතය සඳහා කැමති තොරතුරු අනිෂ්ට යෙදුම් විසින් ලබා ගත හැක."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"සිදුවීම් පෙරන්න"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"පිටත් කිරීමට පෙර සියලු පරිශීලක සිදුවීම්වල ප්‍රවාහයක් පෙරීමට යොදා ගන්නා ආදාන පෙරීමක් ලියාපදිංචි කිරීමට යෙදුමට අවසර දෙන්න. පරිශීලක මැදිහත් වීමකින් තොරව පද්ධති UI අනිෂ්ට යෙදුම් පාලනය කරයි."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"දර්ශනය විශාලනය කරන්න"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"දසුනේ අන්තර්ගතය විශාල කිරීමට යෙදුමට අවසර දෙන්න. ඇතැම් විට අනිෂ්ට යෙදුම්, උපාංගය භාවිතා කළ නොහැකි බවට පත් කරමින් දසුනේ අන්තර්ගතය වෙනස් කළ හැක."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"අඩ වශයෙන් වැහීම"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"ක්‍රියාකාරකම් කළමනාකරු වැහීමේ තත්වයට දමන්න. සම්පූර්ණ වැහීමකට පත් නොකරන්න."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"යෙදුම් මාරු වීම වැළක්වීම"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"වෙනත් යෙදුමක් වෙත පරිශීලකයාව මාරු වීම වළක්වයි."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"පවතින යෙදුමේ තොරතුරු ලබාගැනීම"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="2512448855496067131">"තිරයේ පෙරබිම තුළ තිබෙන දැන් පවත්නා යෙදුමේ පෞද්ගලික තොරතුරු ලබාගැනීමට දරන්නාට අවසර දෙන්න."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"සියලු යෙදුම් දියත් කිරීම් නිරීක්ෂණය සහ පාලනය කිරීම"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"පද්ධතිය ක්‍රියාකාරකම් දියත් කරන්නේ කෙසේදැයි නිරීක්ෂණයට සහ පාලනයට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් මගින් පද්ධතිය සම්පූර්ණයෙන්ම සම්මුතියකට එළඹිය හැක. වර්ධනය සඳහා පමණක් මෙම අවසරය අවශ්‍ය වෙයි, සාමාන්‍ය භාවිතය සඳහා කිසි විටෙකත් අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"පැකේජ ඉවත් කිරීමේ ප්‍රචාරණයක් යවන්න"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"යෙදුම් පැකේජයක් ඉවත්කොට ඇති බවට දැනුම්දීමක් විකාශනයට යෙදුමට අවසර දෙයි. ධාවනය වන අනෙකුත් යෙදුමක් නැති කිරීමට අනිෂ්ට යෙදුම් විසින් මෙය භාවිත කළ හැක."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS-ලැබීම විකාශන යැවීම"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"SMS පණිවිඩයක් හරහා ලැබුණු දැනුම්දීමක් ප්‍රචාරණයට යෙදුමට අවසර දෙන්න. පැමිණෙන SMS පණිවිඩ වංචා කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH-ලැබීම විකාශන යැවීම"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"WAP PUSH පණිවුඩයක් ලැබී ඇති බවට දැනුම්දීමක් විකාශනය කිරීමට යෙදුමට අවසර දෙන්න. වංචාකාරී MMS පණිවුඩ ලැබීම් හෝ නිහඬව ඕනෑම වෙබ් පිටුවක අන්තර්ගතය අනිෂ්ට විචල්‍යවලින් ඉවත් කිරීමට, අනිෂ්ට යෙදුම් විසින් මෙය භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"ධාවන ක්‍රියාවලි ගණන සීමා කිරීම"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"ධාවනය වන උපරිම ක්‍රියාවලි ගණන පාලනය කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"පසුබිම් යෙදුම් වලට වැසීමට බලකරන්න"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"පසුබිමට පිවිසෙනවාත් සමඟම ක්‍රියාකාරකම් නැවතීම පාලනයට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසිසේත් අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"බැටරි සංඛ්‍යාන කියවීම"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"වර්තමාන පහළ මට්ටමේ බැටරිය භාවිතා දත්ත කියවීමට යෙදුමට අවසර දෙන්න. ඔබ භාවිත කරන යෙදුම් මොනවා දැයි ගැන විස්තරාත්මක තොරතුරු ගැන දැන ගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"බැටරි සංඛ්‍යාන වෙනස් කිරීම"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"එකතු කරගන්නා ලද බැටරි සංඛ්‍යාන වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් වල භාවිතයට නොවේ."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"යෙදුමේ විකල්ප සංඛ්‍යාංක සොයා ලබාගැනීම"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"එකතු කරගත් යෙදුම් ක්‍රියාකාරිත්ව සංඛ්‍යා ලේඛන වෙනස් කිරීමට උපාංගයට ඉඩ දෙන්න. සාමාන්‍ය උපාංග භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"යෙදුම් විකල්ප සංඛ්‍යාංක වෙනස් කිරීම"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"එකතු කරගත් යෙදුම් ක්‍රියාකාරිත්ව සංඛ්‍යා ලේඛන වෙනස් කිරීමට යෙදුමට ඉඩ දෙන්න. සාමාන්‍ය යෙදුම් භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"පද්ධති උපස්ථ පාලනය කරන්න සහ නැවත පිහිටුවන්න"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"පද්ධතියේ උපස්ථය සහ උපක්‍රම නැවත පිහිටුවීම පාලනයට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"සම්පූර්ණ උපස්ථය හෝ මෙහෙයුම් නැවත පිහිටුවීම සනාථ කිරීම"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"පූර්ණ උපස්ථ තහවුරුකිරීම් UI පුරන්නට උපකරණයට ඉඩ දෙන්න. කිසිම යෙදුමක් භාවිතා නොකරනු ඇත."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"අවසර නොලත් කවුළුව දර්ශනය කරන්න"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"අභ්‍යන්තර පද්ධති පරිශීලක අතුරුමුහුණත් විසින් භාවිතා කිරීමට බලාපොරොත්තු වන කවුළු නිර්මාණය කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"වෙනත් යෙදුම් උඩින් අඳින්න"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"අනෙක් යෙදුම් මත හෝ පරිශීලක අතුරු මුහුණත් කොටස්වල ඇඳීමට යෙදුමට ඉඩ දෙන්න. එය ඔබේ භාවිතයේ ඇති ඕනෑම යෙදුමක මුහුණත සමග සම්බන්ධ වීමට හෝ අනෙක් යෙදුම් ගැන ඔබට පෙනෙන ආකාරය වෙනස් කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"ගෝලීය සජීවන වේගය වෙනස් කරන්න"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"ඕනෑම වෙලාවක පොදු සජීවීකරණ වේගය (වේගවත් හෝ මන්දගාමී සජීවීකරණ) වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"යෙදුම් ටෝකන කළමනාකරණය කිරීම"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"සාමාන්‍ය Z පටිපාටිය මඟහැරයමින් යෙදුම්වලට අයිති ටෝකන් පත් නිර්මාණයට සහ කළමනාකරණයට යෙදුම්වලට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසිසේත් අවශ්‍ය නොවේ."</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"තිරය නිශ්චල කරන්න"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"සම්පූර්ණ තිර සංක්‍රමණය සඳහා තිරය තාවකාලිකව මුදවිමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"යතුරු සහ පාලන බොත්තම් ඔබන්න"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"තමන්ගේ ආදාන සිදුවීම් (යතුරු එබිම් , ආදී ) අනෙකුත් යෙදුම්වලට භාරදීමට යෙදුමට ඉඩ දෙන්න. අනිෂ්ට යෙදුම් මෙය ටැබ්ලටය ලබා ගැනීමට භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"වෙනත් යෙදුම්වලට එහි ආදාන සිදුවීම් (යතුරු එබීම්, යනාදිය.) ආදිය යැවීමට යෙදුමට අවසර දෙන්න. දුරකථනය අත්කර ගැනීම අනිෂ්ට යෙදුම් මෙය භාවිත කරයි."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"ඔබ ටයිප් කරන දෙය සහ ඔබ ගන්නා ක්‍රියාවන් පටිගත කරන්න"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"මුරපදය ටයිප් කිරීම වැනි අනෙකුත් යෙදුම් සමඟ අන්තර්ක්‍රියාකාරී වනවිට යනාදී ඔබ ඔබන යතුරු දැකීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අදාළ නොවේ."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"ආදාන ක්‍රමයක් වෙත බඳින්න"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"ආදාන ක්‍රමය ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"ප‍්‍රවේශ්‍යතා සේවාවක් වෙත බදින්න"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"ප‍්‍රවේශ්‍යතා සේවාවේ ඉහළ මට්ටමේ අතුරුමුහුණතට බැඳීමට දරන්නාට අවසර දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිවිටක අවශ්‍ය නොවේ."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"මුද්‍රණ සේවාවකට බද්ධ වී ඇත"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"මුද්‍රණ සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindPrintSpoolerService" msgid="6807762783744125954">"මුද්‍රණ සේවාවකට බද්ධ වී ඇත"</string>
-    <string name="permdesc_bindPrintSpoolerService" msgid="3680552285933318372">"මුද්‍රණ සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC සේවාව වෙත බැඳෙන්න"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"NFC කාඩ් පත් ආදර්ශනය කරන යෙදුම් රඳවනයට සම්බන්ධ වීමට ඉඩ දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"පෙළ සේවාවකට බඳින්න"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"කෙටි පණිවිඩ සේවාවක (උදා. SpellCheckerService) ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN සේවාවකට බැඳීම"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"VPN සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"බිතුපත වෙත බඳින්න"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"බිතුපත ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"විජට සේවාවකට බඳින්න"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"විජට් සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"උපාංග පරිපාලක සමඟ අන්තර්ක්‍රියාකාරී වීම"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"උපාංග පාලකයා වෙතට අභිප්‍රායයන් යැවීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"උපාංග පරිපාලකයෙක් එක් කිරීම හෝ ඉවත් කිරීම"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"දරන්නාට උපාංග පරිපාලකයින් එක් කිරීමට හෝ ඉවත් කිරීමට අවසර දේ. සාමාන්‍ය යෙදුම් වලට කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"තිර දිශානතිය වෙනස් කිරීම"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"තිරයේ භ්‍රමණය ඕනෑම වේලාවක වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවනු ඇත."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"දර්ශකයේ වේගය වෙනස් කිරීම"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"මූසිකයේ හෝ ට්‍රැක්පෑඩයේ වේගය ඕනෑම මොහොතක වෙනස් කිරීමට උපාංගයට ඉඩ දෙන්න. සාමාන්‍ය උපාංගයන් සඳහා කිසිදා අවශ්‍ය නොවනු ඇත."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"යතුරු පුවරු පිරිසැලැස්ම වෙනස් කිරීම"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"යතුරුපුවරු මුහුණත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"යෙදුම් වෙත Linux සංඥා යැවීම"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"පවතින සියලු ක්‍රියාවලි වෙත සැපයුම් සංඥා ඉල්ලවිමට යෙදුමට අවසර දේ."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"යෙදුම සැමවිටම ධාවනය කරන්න"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"මතකයේ පවතින එහි කොටස් නොනැසී පැවතීමට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම් වලට මතකය සීමා කිරීමෙන් ටැබ්ලටය පමා කිරීම මගින්  මෙමගින් කළ හැක."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"යෙදුමට තම කොටස් මතකය තුල නොබිඳීව රඳා පවත්වාගෙන යාමට අවසර දෙන්න. මෙය දුරකථනය මන්දගාමී කරමින් අනෙකුත් උපාංගයන් සඳහා ඉතිරි මතකය සීමා කිරීමට හැක."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"යෙදුම් මකන්න"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"Android පැකේජ මැකීමට යෙදුමට අවසර දෙන්න. වැදගත් යෙදුම් මැකීමට අනිෂ්ට යෙදුම් විසින් මෙය භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"යෙදුමේ වෙනත් දත්ත මකන්න"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"පරිශීලක දත්ත හිස් කිරීමට යෙදුමකට ඉඩ දේ."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"අනෙක් යෙදුම්වල හැඹිලි මකන්න"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"හැඹිලි ගොනු මැකීමට අවසර යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"යෙදුම් ආචයනයේ ඉඩ ප්‍රමාණය මැනීම"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"යෙදුමකට එහි කේතය, දත්ත සහ හැඹිලි ප්‍රමාණ ලබාගැනීමට අවසර දෙන්න."</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"යෙදුම් කෙළින්ම ස්ථාපනය කිරීම"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"නව හෝ යාවත්කාලින කරන ලද Android පැකේජයන් ස්ථාපනය කිරීමට ඉඩ දෙන්න. බලසහිත අවසර තීන්දු සමග නව යෙදුම් එකතු කිරීමට අනිෂ්ට යෙදුම්වලට මෙය භාවිතා කිරීමට ඉඩ තිබේ."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"යෙදුමේ සියලුම හැඹිලි දත්ත මකන්න"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"අනෙක් යෙදුම්වල හැඹිලි නාමාවලි තුළ ඇති ගොනු මැකීමෙන් යෙදුමට ටැබ්ලට ආචයනය නිදහස් කිරීමට අවසර දෙන්න. මෙමගින් අනෙක් යෙදුම්වලට ඒවායේ දත්ත නැවත ලබා ගැනීමට අවශ්‍ය වන නිසා, ඒවායේ ආරම්භය තවත් සෙමින් සිදුවීමට ඉඩ ඇත."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"අනෙක් යෙදුම්වල හැඹිලි නාමාවලි තුළ ඇති ගොනු මැකීමෙන් යෙදුමට දුරකථන ආචයනය නිදහස් කිරීමට අවසර දෙන්න. මෙමඟින් අනෙක් යෙදුම්වලට ඒවායේ දත්ත නැවත ලබා ගැනීමට අවශ්‍ය වන නිසා, ඒවායේ ආරම්භය තවත් සෙමින් සිදුවීමට ඉඩ ඇත."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"යෙදුම් සම්පත් ගෙන යාම"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"අභ්‍යන්තර සහ බාහිර මාධ්‍යයන්ගෙන් යෙදුමේ සම්පත් ගෙනයාමට සහ යෙදුමේ සම්පත් වලින් අභ්‍යන්තර සහ බාහිර මාධ්‍යයන්ට යෙදුමේ සම්පත් ගෙනයාමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"සංවේදී ලොග් දත්ත කියවීම"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"පද්ධතියේ විවිධ ලොග් ගොනු කියවීමට යෙදුමට අවසර දෙන්න. පුද්ගලික සහ පෞද්ගලික තොරතුරු ඇතුළත්ව ඔබ ටැබ්ලටයෙන් කුමක් කරන්නෙහිද යනාදී සාමාන්‍ය තොරතුරු සෙවීමට මෙයට අවසර දෙන්න."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"පද්ධතියේ විවිධ ලොග් ගොනු කියවීමට යෙදුමට අවසර දෙන්න. පුද්ගලික සහ පෞද්ගලික තොරතුරු ඇතුළත්ව ඔබ දුරකථනයෙන් කුමක් කරන්නෙහිද යනාදී සාමාන්‍ය තොරතුරු සෙවීමට මෙයට අවසර දෙන්න."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"නැවත ධාවනය සඳහා ඕනෑම මාධ්‍ය විකේතකයක් හාවිතා කරන්න"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"නැවත ධාවනය සඳහා විකේතනය කිරීමට ඕනෑම ස්ථාපිත මාධ්‍ය විකේතකයක් භාවිතයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_manageCaCertificates" msgid="1678391896786882014">"විශ්වාසදායී අක්තපත්‍ර කළමනාකරණය"</string>
-    <string name="permdesc_manageCaCertificates" msgid="4015644047196937014">"යෙදුමට CA සහතික විශ්වාසදායී අක්තපත්‍ර ලෙස ස්ථාපනය සහ අස්ථාපනය කිරීමට ඉඩ දෙන්න."</string>
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"Diag විසින් හිමිකාරත්වය දරණ සම්පත්වලට කියවීම/ ලිවිම"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"Diag කණ්ඩායමට අයිති ඕනෑම සම්පතක් කියවීමට සහ ලිවීමට යෙදුමට අවසර දෙන්න. උදාහරණයක් ලෙස /dev තුල ඇති ගොනු. මෙයට පද්ධති ස්ථායිතාවට සහ ආරක්ෂාවට බලපෑම් කිරීමට හැකියාවක් ඇත. නිෂ්පාදක හෝ ක්‍රියාකරු විසින් දෘඩාංග-විශේෂිත දෝෂ නිර්ණය සඳහා පමණක් මෙය යොදාගත යුතුය."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"යෙදුම් අංග සබල හෝ අබල කිරීම"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"වෙනත් යෙදුමක අංගයක් සබල ද නැද්ද යන්න වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. වැදගත් ටැබ්ලට් අවශ්‍යතා අබල කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක. මෙම අවසරය සැලකිල්ලෙන් භාවිතා කළ යුතුය, භාවිත නොකරන, අස්ථිර හෝ අස්ථායි තත්වයට යෙදුම පත් කිරීමට එයට හැකිය."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"වෙනත් යෙදුමක අංගයක් සබල ද නැද්ද යන්න වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. වැදගත් දුරකථන අවශ්‍යතා අක්‍රිය කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක. මෙම අවසරය සැලකිල්ලෙන් භාවිත කළ යුතුය, භාවිත නොකරන, අස්ථිර හෝ අස්ථායි තත්වයට යෙදුම පත් කිරීමට එයට හැකිය."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"අවසර ප්‍රදානය කිරීම හෝ අහෝසි කිරීම"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"යෙදුමකට එයට හෝ අනෙක් යෙදුම් වලට විශේෂිත අවසර ප්‍රදානයට හෝ අහෝසි කිරීමට අවසර දෙන්න. අනිෂ්ට යෙදුම්, ඒවාට අවසර ප්‍රදානය නොකළ ගුණාංග වලට ප්‍රවේශ වීමට මෙය භාවිතා කළ හැක."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"අභිරුචි යෙදුම් සකසන්න"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"ඔබගේ අභිරුචි යෙදුම් වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ ධාවනය වන යෙදුම් වෙනස් කිරීම, පවතින යෙදුම් වලින් දත්ත එකතු කිරීම, ප්‍රෝඩා කිරීම වැනි දේ අනිෂ්ට යෙදුම් නිශ්ශබදවම සිදු කරයි."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"පද්ධති සැකසීම් වෙනස් කිරීම"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"පද්ධති සැකසීම් දත්ත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් ඔබගේ පද්ධති වින්‍යාස දෝෂ ගැන්විය හැක."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"ආරක්‍ෂිත පද්ධති සැකසීම් වෙනස් කරන්න"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"පද්ධතියේ ආරක්‍ෂිත දත්ත වෙනස් කිරීමට උපාංගයට අවසර දෙන්න. සාමාන්‍ය උපාංග සඳහා භාවිතයට නොවේ."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google සේවා සිතියම වෙනස් කරන්න"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"Google සේවා සිතියම වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා භාවිතයට නොවෙයි."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"ආරම්භයේදී ධාවනය කිරීම"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"පද්ධතිය ඇරඹුම අවසන් වූ වහාම යෙදුම ආරම්භ වීමට යෙදුමට අවසර දෙන්න. ටැබ්ලටය ආරම්භ කිරීමට මෙමඟින් පමා කළ හැකි අතර සැමවිටම ධාවනය වන නිසා සම්පූර්ණ ටැබ්ලටයම ප්‍රමාද කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"පද්ධතිය ඇරඹුම අවසන් වූ වහාම යෙදුම ආරම්භ වීමට යෙදුමට අවසර දෙන්න. දුරකථනය ආරම්භ කිරීමට මෙමඟින් පමා කළ හැකි අතර සැමවිටම ධාවනය වන නිසා සම්පූර්ණ දුරකථනයේම ක්‍රියාකාරිත්වය ප්‍රමාද කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"බැඳුණු විකාශනය යැවීම"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"ප්‍රචාරණයට පසුවද පවතින, ප්‍රචාරණයන් යැවීමට යෙදුමට අවසර දෙන්න. වැඩිපුර මතකය භාවිතය හේතු කොට, අධික භාවිතය මඟින් ටැබ්ලටය පමා කිරීම හෝ අස්ථිර කළ හැක."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"ප්‍රචාරණයට පසුවද පවතින, ප්‍රචාරණයන් යැවීමට යෙදුමට අවසර දෙන්න. වැඩිපුර මතකය භාවිතය හේතු කොට, අධික භාවිතය මඟින් දුරකථනය පමා කිරීම හෝ අස්ථිර කළ හැක."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"ඔබගේ සම්බන්ධතා කියවීම"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"සඳහන් පුද්ගලයන් හට ඔබ ඇමතුම් ගත්, ඊ-තැපැල්, හෝ  අනෙකුත් ආකාර වලින් සන්නිවේදනය කරගත් සංඛ්‍යතද ඇතුළුව, ඔබගේ ටැබ්ලටයේ ගබඩාවී ඇති සම්බන්ධතා පිළිබඳ දත්ත කියවීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් යෙදුම්වලට ඔබගේ සම්බන්ධතා පිළිබඳ දත්ත සුරැකීමට ඉඩ ලබා දෙන අතර, අනිෂ්ට යෙදුම් විසින් ඔබ නොදැනුවත්වම සම්බන්ධතා දත්ත බෙදා ගැනීමට ඉඩ ඇත."</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"නියමිත පුද්ගලයන් සමග ඔබ ඇමතු, ඊ-තැපැල් කළ හෝ වෙනත් ආකාරයකින් සන්නිවේදනය කළ සංඛ්‍යාතය ඇතුලත් ඔබගේ දුරකථනයේ ආචයනය කරන ලද ඔබගේ සම්බන්ධතා ගැන දත්ත කියවීමට යෙදුමට අවසර දෙන්න. ඔබගේ සම්බන්ධතා දත්ත උපස්ථ කිරීමට මෙම අවසරය යෙදුමට අවසර දෙන අතර ඔබගේ දැනුමකින් තොරව අනිෂ්ට යෙදුම් සම්බන්ධතා දත්ත බෙදාගැනීම කළ හැක."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"ඔබගේ සම්බන්ධතා වෙනස් කිරීම"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"නියමිත පුද්ගලයන්ට ඔබ ඇමතූ, ඊ-තැපැල් කළ හෝ ඇමතුම් කළ සංඛ්‍යාත ඇතුලත් ඔබගේ ටැබ්ලටයේ ආචයනය කරන ලද සම්බන්ධතා (ලිපින) දත්ත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙන් යෙදුමට සම්බන්ධතා දත්ත මැකීමට අවසර දෙයි."</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"සඳහන් පුද්ගලයන්ට ඔබ ඇමතූ, ඊ-තැපැල් කළ හෝ ඇමතුම් කළ සංඛ්‍යාන ඇතුලත් ඔබගේ දුරකථනයේ ආචයනය කරන ලද සම්බන්ධතා (ලිපින) දත්ත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙන් යෙදුමට සම්බන්ධතා දත්ත මැකීමට අවසර දෙයි."</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"ඇමතුම් ලොගය කියවන්න"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"පැමිණෙන සහ පිටවන ඇමතුම් ගැන දත්ත ඇතුළත්, ඔබගේ ටැබ්ලටයේ ඇමතුම් ලොග කියවීමට යෙදුමට අවසර දෙන්න. ඔබගේ ඇමතුම් ලොග දත්ත සුරක්ෂිත කිරීමට මෙම අවසරය යෙදුම්වලට අවසර දෙයි සහ ඔබගේ දැනුමකින් තොරව ඇමතුම් ලොග දත්ත අනිෂ්ට යෙදුම් බෙදා ගැනීම කළ හැක."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"ලැබෙන සහ පිටවන ඇමතුම් පිළිබඳ දත්ත ඇතුළත්ව ඔබගේ දුරකථනයේ ඇමතුම් ලොග් කියවීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය ඔබගේ ඇමතුම් ලොග් දත්ත උපස්ථ කිරීමට යෙදුමට ඉඩදෙන අතර ඔබගේ අනුදැනුමකින් තොරව අනිෂ්ට යෙදුම් විසින් ඇමතුම් ලොග් දත්ත බෙදාගැනීම කළ හැක."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"ඇමතුම් ලොගය ලිවීම"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"ලැබෙන ඇමතුම් සහ පිටවන ඇමතුම් දත්ත ඇතුළත්ව ඔබගේ ටැබ්ලටයේ ඇමතුම් ලොගය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ ඇමතුම් ලොගය මැකීමට හෝ වෙනස් කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිතා කෙරේ."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"පැමිණෙන සහ පිටවෙන ඇමතුම් දත්ත ඇතුළුව ඔබගේ දුරකථනයේ ඇමතුම් ලොගය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ ඇමතුම් ලොගය මැකීමට හෝ වෙනස් කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කල හැක."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"ඔබගේ සම්බන්ධතා පත කියවන්න"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"ඔබගේ නම සම්බන්ධතා තොරතුරු ආදී ඔබගේ උපාංගයේ ගබඩා වී ඇති පුද්ගලික පැතිකඩ තොරතුරු කියවීමට යෙදුමට අවසර දෙන්න. මෙහි තේරුම යෙදුමට ඔබව හඳුනා ගැනීමට හැකි වන බව සහ ඔබගේ පුද්ගලික තොරතුරු අනෙක් අයට යැවීමට ද හැකි වීමයි."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"ඔබගේ සම්බන්ධතා පත වෙනස් කිරීම"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"ඔබගේ නම සහ සම්බන්ධතා තොරතුරු වැනි ඔබගේ උපාංගයේ ආචයනය කරන ලද පුද්ගලික පැතිකඩ තොරතුරු වෙනස් කිරීමට හෝ එකතු කිරීමට යෙදුමට අවසර දෙන්න. මෙමගින් යෙදුමට ඔබව හඳුනා ගත හැකි අතර අනෙක් අයට ඔබගේ පැතිකඩ තොරතුරු යැවිය හැකි බව කියවෙයි."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"ඔබගේ සමාජ ප්‍රවාහය කියවන්න"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"ඔබගේ සහ ඔබගේ යහළුවන්ගේ සමාජ යාවත්කාලීනයන් වෙත පිවිසීමට හෝ සමමුහුර්ත කිරීමට යෙදුමට අවසර දෙන්න. තොරතුරු බෙදා ගැනීමේ දී සැලකිලිමත් වන්න -- විශ්වාසයකින් තොරව සමාජ ජාලවල ඔබගේ සහ ඔබගේ යහළුවන් අතර සන්නිවේදන කියවීමට මෙමගින් යෙදුමට අවසර දෙයි. සටහන: සියලු සමාජ ජාලවල මෙම අවසරය බල නොකරයි."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"ඔබගේ සමාජ ප්‍රවාහය වෙත ලිවීම"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"ඔබගේ යහළුවන්ගේ සමාජ යාවත්කාලීනයන් පෙන්වීමට යෙදුමට අවසර දෙන්න. තොරතුරු බෙදා ගැනීමේදී සැලකිලිමත් වන්න -- යහළුවෙක්ගෙන් පැමිණෙන ලෙස පණිවිඩ නිපදවීමට මෙමඟින් යෙදුමට අවසර දෙන්න. සටහන : සියලු සමාජ ජාල සඳහා මෙම අවසරය බල නොදෙයි."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"දින දර්ශනයේ සිදුවීම් සහ රහසිගත තොරතුරු කියවීම"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"ඔබගේ ටැබ්ලටය තුල ගබඩා  කර ඇති මිතුරන්ගේ සහ එක්ව ක්‍රියාකරන්නන්ගේ ද ඇතුළුව සියලුම දින දර්ශන සිද්ධි කියවීමට යෙදුමට අවසර දෙන්න. මෙය රහස්‍යභාවය හෝ සංවේදීතාවය නොසලකා ඔබගේ දින දර්ශන දත්ත බෙදා ගැනීමට හෝ සුරැකීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"යහළුවන් සහ සමකාලිනයන් ඇතුලත් ඔබගේ දුරකථනයේ ආචයනය කරන ලද සියලු දින දර්ශන සිදුවීම් කියවීමට යෙදුමට අවසර දෙන්න. විශ්වාසයකින් හෝ සංවේදීතාවකින් තොරව ඔබගේ දින දර්ශන දත්ත බෙදා ගැනීමට හෝ උපස්ථ කිරීමට මෙමගින් යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"දින දර්ශන සිද්ධි එකතු කිරීම හෝ වෙනස් කිරීමක් සිදුකර හිමිකරුගේ දැනීමකින් තොරව අමුත්තන්ට ඊ-තැපෑලක් යවීම"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"යහළුවන් හෝ එකට-වැඩකරන්නන් ඇතුළත්ව ඔබට ටැබ්ලටයේ වෙනස් කළ හැකි සිද්ධි එකතු කිරීමට, ඉවත් කිරීමට, වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙමඟින් දින දර්ශන හිමිකරුවන්ගෙන් පණිවිඩ යවන පරිදි මෙන් මවාපෑමට හෝ හිමිකරුගේ අනුදැනුමකින් තොරව සිද්ධි වෙනස් කිරීමට යෙදුමට අවසර ලැබේ."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"ඔබගේ යහළුවන් හෝ සමකාලීනයන් ඇතුළත් ඔබගේ දුරකථනයේ ඔබට වෙනස් කළ හැකි සිදු වීම් එකතු කිරීමට, ඉවත් කිරීමට, වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙමගින් දින දර්ශන හිමිකරුවන්ගෙන් පැමිණෙන සේ පෙනෙන පණිවිඩ යැවීමට හෝ හිමිකරුගේ දැනුමකින් තොරව සිදුවීම් වෙනස් කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"පරීක්ෂණ සඳහා ආදර්ශ ස්ථාන මූලාශ්‍ර"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"පරීක්ෂණයට ව්‍යාජ ස්ථාන මූලාශ්‍ර සාදන්න හෝ නව ස්ථාන සැපයුම්කරුවෙකු ස්ථාපනය කරන්න. GPS හෝ ස්ථාන සැපයුම්කරුවන් ආදී වෙනත් ස්ථාන මූලාශ්‍ර විසින් ලබා දෙන ස්ථානය සහ/හෝ තත්වය ප්‍රතිස්ථාපනය කිරීමට යෙදුමට මෙය අවසර දෙයි."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"අමතර ස්ථාන සැපයුම්කරු විධාන වෙත ප්‍රවේශ වීම"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"අමතර ස්ථාන සැපයුම්කරු විධාන වෙත පිවිසීමට යෙදුමට අවසර දෙන්න. GPS හෝ වෙනත් ස්ථාන මූලාශ්‍ර ක්‍රියාවලි වෙත බාධා කිරීමට මෙය අවසර දෙයි."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"ස්ථාන සැපයුම්කරුවෙකු ස්ථාපනයට අවසරය දෙන්න"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"පරීක්ෂණයට ව්‍යාජ ස්ථාන මූලාශ්‍ර සාදන්න හෝ නව ස්ථාන සැපයුම්කරුවෙකු ස්ථාපනය කරන්න. GPS හෝ ස්ථාන සැපයුම්කරුවන් ආදී වෙනත් ස්ථාන මූලාශ්‍ර විසින් ලබා දෙන ස්ථානය සහ/හෝ තත්ත්වය ප්‍රතිස්ථාපනය කිරීමට යෙදුමට මෙය අවසර දෙයි."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"නිවැරදි ස්ථානය (GPS සහ ජාලය පදනම් කරගත්)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"ගෝලීය ස්ථානීය පද්ධතිය (GPS) හෝ සෙල් කුළුණු සහ Wi-Fi වැනි ජාල ස්ථානීය ප්‍රභව භාවිතයෙන් ඔබගේ නිවැරදි ස්ථානය ලබාගැනීමට යෙදුම අවසර දෙන්න. යෙදුම් වලට ස්ථානීය සේවා භාවිතා කිරීමට  ඒවා සක්‍රිය විය යුතු වේ. ඔබව සොයා ගැනීමට යෙදුම් මෙය භාවිතා කරන අතර අමතර බැටරි බලයක්ද පරිභෝජනය කරයි."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"ආසන්නතම ස්ථානය (ජාලය-පාදක වූ)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"ඔබගේ දළ ස්ථානය ලබාගැනීමට යෙදුමට අවසර දෙන්න. සන්නේවේදන කුළුණු සහ Wi-Fi ආදී ජාල ස්ථාන මූලාශ්‍ර භාවිත කරන ස්ථාන සේවා විසින් මෙම ස්ථානය ව්‍යුත්පන්න කර ඇත. යෙදුමට භාවිතය සඳහා මෙම ස්ථාන සේවා සක්‍රිය කළ යුතු අතර ඔබගේ උපාංගය සඳහා පැවතිය යුතුය. ඔබ සිටින තැන දළව හඳුනා ගැනීමට යෙදුම් වලට මෙය භාවිත කළ හැකිය."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"SurfaceFlinger පහල මට්ටමේ විශේෂාංග භාවිතයට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"රාමු අන්තරාචය කියවීම"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"රාමු අන්තරාචයනයෙන් අන්තර්ගතයන් කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"Wifi සංදර්ශක වින්‍යාස කරන්න"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"වින්‍යාස කිරීමට සහ Wifi සංදර්ශක වෙත සම්බන්ධ වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"Wifi සංදර්ශක පාලනය"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Wifi සංදර්ශකයේ පහළ මට්ටමේ විශේෂාංග පාලනයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"ශබ්ද ප්‍රතිදානය ග්‍රහණය"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"යෙදුමට ශබ්ද ප්‍රතිදානය ග්‍රහණය කර හරවා යැවීමට ඉඩ දේ."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"වීඩියෝ ප්‍රතිදානය"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"යෙදුමට වීඩියෝ ප්‍රතිදානය ග්‍රහණය කර හරවා යැවීමට ඉඩ දේ."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"ආරක්‍ෂිත වීඩියෝ ප්‍රතිදානය"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"යෙදුමට ආරක්‍ෂිත වීඩියෝ ප්‍රතිදානය ග්‍රහණය කර හරවා යැවීමට ඉඩ දේ."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"ඔබගේ ශ්‍රව්‍ය සැකසීම් වෙනස් කරන්න"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"ශබ්දය ආදී ගෝලීය ශබ්ද සැකසීම් වෙනස් කිරීමට සහ ප්‍රතිදානය සඳහා භාවිත කරන්නේ කුමන නාදකය දැයි තේරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"ශබ්ද පටිගත කරන්න"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"මයික්‍රොෆෝනය මඟින් ශබ්ද පටිගත කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් යෙදුමට ඕනෑම වේලාවක ඔබගේ අනුදැනුමකින් තොරව ශබ්ද පටිගත කිරීමට ඉඩ ලබා දේ."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"පින්තූර සහ වීඩියෝ ගන්න"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"කැමරාවෙන් පින්තූර ගැනීමට සහ වීඩියෝ කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් ඔබගේ අනුදැනුමකින් තොරව ඕනෑම වේලාවකදී කැමරාව භාවිතා කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"කැමරාව භාවිතයේදී LED දර්ශක සම්ප්‍රේෂණය අබල කරන්න"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"කැමරා භාවිතය පිළිබඳ LED දර්ශකය අක්‍රිය කිරීමට, කලින් පිහිටුවා ඇති පද්ධති යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"ටැබ්ලටය ස්ථිරවම අබල කිරීම"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"දුරකථනය ස්ථිරව අබල කිරීම"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"මුළු ටැබ්ලටයම ස්ථිරවම අක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. මෙය ඉතා භයානකයි."</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"මුළු දුරකථනයම ස්ථිරවම අක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. මෙය ඉතා භයානකයි."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ටැබ්ලට් නැවත පණ ගැන්වීමට බල කරන්න"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"දුරකථන නැවත පණ ගැන්වීමට බල කරන්න"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"ටැබ්ලටය නැවත බල ගැන්වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"ටැබ්ලටය නැවත ඇරඹීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB ආචයනය ගොනු පද්ධතිය ප්‍රවේශ කිරීම"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD පත් ගොනු පද්ධතිය ප්‍රවේශ කිරීම"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"ඉවත් කළ හැකි ආචයනය සඳහා ගොනු පද්ධති ඈඳීමට සහ ගැලවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB ආචයනය මකන්න"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD පත මකන්න"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"ඉවත් කළ හැකි ආචයන ෆෝමැට් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"අභ්‍යන්තර ආචයනය පිළිබඳ තොරතුරු ලබා ගැනීම"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"අභ්‍යන්තර ආචයනයේ තොරතුරු ලබාගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"අභ්‍යන්තර ආචයනය නිර්මාණය"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"අභ්‍යන්තර ආචයනය සැදීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"අභ්‍යන්තර ආචයනය විනාශ කිරීම"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"අභ්‍යන්තර ආචයනය විනාශ කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"අභ්‍යන්තර ආචයනය නංවීම/ගැලවීම"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"අභ්‍යන්තර ආචයනය සවි කිරීමට/ගැලවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"අභ්‍යන්තර ආචයනය නැවත නම් කරන්න"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"අභ්‍යන්තර ආචයනය නැවත නම් කිරීමට යෙදුමට අවසර දෙන්න."</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_manageUsb" msgid="1113453430645402723">"USB උපාංග සඳහා කැමැත්ත සහ අවසර කළමනාකරණය කිරීම"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"USB උපාංග සඳහා අභිරුචි සහ අවසර කළමනාකරණයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP ප්‍රොටොකෝලය ක්‍රියාත්මක කිරීම"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"MTP USB ප්‍රොටෝකෝලය ක්‍රියාත්මක කිරීමට කර්නල MTP ධාවකයට ප්‍රවේශ වීමට අවසර දෙන්න."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"දෘඩාංග පරීක්ෂණය කරන්න"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"දෘඩාංග පරීක්ෂා කිරීමේ අරමුණ සඳහා යෙදුමට විවිධ පර්යන්ත පාලනය කිරීමට ඉඩ දෙන්න."</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"දුරකථන අංක වෙත ඍජුවම අමතන්න"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"ඔබගේ මැදිහත් වීමක් නොමැතිව දුරකථන අංක ඇමතීමට යෙදුමට අවසර දෙන්න. මෙහි ප්‍රතිඑලය වන්නේ අනපේක්ෂිත අයකිරීම් හෝ ඇමතුම් ඇතිවීමයි. මෙයන් හදිසි අංක වලට ඇමතුම් ගැනීමට යෙදුමට අවසර නොදෙන බවට සටහන් කරගන්න. ඔබගේ අනුදැනුමක් නොමැතිව ඇමතුම් ගැනීමෙන් අනිෂ්ට යෙදුම් ඔබගේ මුදල් නිකරුණේ වැය කරයි."</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"ඕනෑම දුරකථන අංකයකට ඍජුවම අමතන්න"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"ඔබගේ මැදිහත්වීමකින් තොරව හදිසි අංක ඇතුළත්ව ඕනෑම දුරකථන අංකයකට ඇමතීමට යෙදුමට අවසර දෙන්න. හදිසි සේවා වෙත අනවශ්‍ය සහ නීතිමය නොවන ඇමතුම ලැබීමට අනිෂ්ට යෙදුම සිදු කළ හැක."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA ටැබ්ලට පිහිටුම සෘජුව ඇරඹීම"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA දුරකථන පිහිටුම සෘජුව ඇරඹීම"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"යෙදුමට CDMA ප්‍රතිපාදන ආරම්භ කිරීමට ඉඩදෙන්න. අනිෂ්ට යෙදුම් අනවශ්‍ය ලෙස CDMA ප්‍රතිපාදන ආරම්භ කළ හැක."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"ස්ථාන යාවත්කාලීන දැනුම්දීම් පාලනය කරන්න"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"ස්ථානීය යාවත්කාලින දැනුම්දීම් රේඩියෝවෙන් සබල/අබල කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"පිරික්සුම් ගුණාංග වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"පිරික්සුම් සේවාව මගින් උත්ශ්‍රේණි කළ ගුණාංග වෙත කියවීම්/ලිවීම් පිවිසුම සඳහා යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් වල භාවිතයට නොවේ."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"විජට් තෝරන්න"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"කුමන විජටය කුමන යෙදුමෙන් භාවිතා කල හැකිද යන්න පද්ධතියට පැවසීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය ඇති යෙදුමකට අනෙක් යෙදුම්වලට පුද්ගලික දත්ත වලට ප්‍රවේශය ලබා දිය හැක. සාමාන්‍ය යෙදුම් වල භාවිතයට නොවේ."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"දුරකථනයේ තත්වය වෙනස් කිරීම"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"උපාංගයේ දුරකථන විශේෂාංග පාලනයට යෙදුමට අවසර දෙන්න. මෙම අවසරය ඇති යෙදුමට ඔබට නිවේදනයෙන් තොරව ජාල මාරු කිරීම, දුරකථන රේඩියෝව සක්‍රිය සහ අක්‍රිය කිරීම කළ හැක."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"දුරකථනයේ තත්වය සහ අනන්‍යතාවය කියවීම"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"උපාංගයේ දුරකථන විශේෂාංග වෙත පිවිසීමට යෙදුමට අවසර දෙන්න. ඇමතුම සක්‍රිය වුවත් සහ ඇමතුමකින් දුරස්ථ අංකය සම්බන්ධ වුවත් දුරකථන අංකය සහ උපාංග ID හඳුනා ගැනීමට මෙම අවසරය යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"ටැබ්ලටය නින්දෙන් වැළක්වීම"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"දුරකථනය නින්දට යාමෙන් වළකන්න"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"ටැබ්ලටය නින්දට යාමෙන් වැලැක්වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"දුරකථනය නින්දට යාමෙන් වැලැක්වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"ටැබ්ලටය සක්‍රිය හෝ අක්‍රිය කරන්න"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"දුරකථනය බල ගැන්වීම හෝ වැසීම"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"ටැබ්ලටය සක්‍රිය හෝ අක්‍රිය කිරීමට යෙදුමට අවසර දේ."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"දුරකථනය සක්‍රිය සහ අක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"කර්මාන්තශාලා පරීක්ෂණ ආකාරය තුළ ධාවනය කරන්න"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"ටැබ්ලටයේ දෘඩාංග වෙත සම්පූර්ණ පිවිසුම සඳහා අවසර දීමෙන් පහළ මට්ටමේ නිපැවුම්කරු පරීක්ෂණයක් ලෙස ධාවනය කරන්න. නිපැවුම්කරු පරීක්ෂණ ආකාරයෙන් ටැබ්ලටයේ ධාවනය වන විට පමණි."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"දුරකථනයේ දෘඩාංග වෙත සම්පූර්ණ පිවිසුම සඳහා අවසර දීමෙන් පහළ මට්ටමේ නිපැවුම්කරු පරීක්ෂණයක් ලෙස ධාවනය කරන්න. නිපැවුම්කරු පරීක්ෂණ ආකාරයෙන් දුරකථනයේ ධාවනය වන විට පමණි."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"බිතුපත සැකසීම"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"පද්ධති බිතුපත සැකසීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"ඔබගේ බිතුපතේ ප්‍රමාණය සැකසීම"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"පද්ධති බිතුපතේ ප්‍රමාණ ඉඟි සකස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"කර්මාන්තශාලා සුපුරුද්දට පද්ධතිය නැවත සකස් කිරීම"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"සියලු දත්ත මැකීමෙන්, වින්‍යාස කිරීමෙන් සහ යෙදුම් ස්ථාපනයෙන් එහි කර්මාන්ත ශාලා සැකසීම් වෙත පද්ධතිය නැවත සැකසීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"වේලාව සැකසීම"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"ටැබ්ලට ඔරලෝසුවේ වේලාව වෙනස් කිරීමට යෙදුමට ඉඩ දෙන්න."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"දුරකථන ඔරලෝසුවේ වේලාව වෙනස් කිරීමට යෙදුමකට ඉඩ දෙන්න."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"වේලා කලාපය සැකසීම"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"ටැබ්ලටයේ කාල කලාපය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"දුරකථනයේ වේලා කලාපය වෙනස් කිරීමට උපාංගයට අවසර දෙන්න."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService ලෙස පෙනී සිටින්න"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"AccountAuthenticators වෙත ඇමතුම් ගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"උපාංගයේ ඇති ගිණුම් සොයන්න"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"ටැබ්ලටය විසින් දන්නා ගිණුම් ලැයිස්තුවක් ලබාගැනීමට යෙදුමට අවසර දෙන්න. ඔබ ස්ථාපනය කොට ඇති යෙදුම් විසින් සාදා ඇති ගිණුම් මීට ඇතුළත් වේ."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"දුරකථනය විසින් දන්නා ගිණුම් ලැයිස්තුවක් ලබාගැනීමට යෙදුමට අවසර දෙන්න. ඔබ ස්ථාපනය කොට ඇති යෙදුම් විසින් සාදා ඇති ගිණුම් මීට ඇතුළත් වේ."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"ගිණුම් සාදන්න සහ මුරපද සකසන්න"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"ගිණුම් සැදීමට සහ රහස් පද ලබාගැනීම සහ සැකසීම් කිරීම ඇතුළත්ව AccountManager ගේ ගිණුම් සත්‍යාපන හැකියාවන් භාවිතා කිරීමට යෙදුමකට අවසර දෙන්න."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"ගිණුම් එකතු කරන්න හෝ ඉවත් කරන්න"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"ගිණුම් එකතු කිරීම, සහ ඉවත් කිරීම සහ ඔවුන්ගේ මුරපද මැකීම ආදී ක්‍රියාවලි සිදු කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"උපාංගයේ ඇති ගිණුම් භාවිතා කිරීම"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"සත්‍යාපන ටෝකන ඉල්ලීම සඳහා යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"ජාල සම්බන්ධතාවයන් බැලීම"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"කුමන ජාල පවතින්නේ ද සහ සම්බන්ධිත ද ආදී ජාල සබඳතා ගැන තොරතුරු බැලීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"සම්පූර්ණ ජාල ප්‍රවේශය"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"උපකරණයට ජාල කෙවනියන් සැදීමට සහ ජාල ප්‍රොටෝකෝල අභිරුචි භාවිතා කිරීමට උපකරණයට ඉඩ දෙන්න. අන්තර්ජාලයට දත්ත යැවීමට විධියන් බ්‍රව්සරය සහ අනෙකුත් යෙදුම් සපයයි, එනිසා මෙම අවසරය දත්ත අන්තර්ජාලයට යැවීමට අවශ්‍ය නොවේ."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"ජාලයේ සැකසීම් සහ ගමනාගමන වෙනස් කරන්න/අල්ලා ගැනීම"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"ඕනෑම APN එකක නියුතුව සහ තොට වෙනස් කිරීම වැනි ජාල සැකසීම් වෙනස් කිරීමට සහ සියලුම ජාල අතුරු ඇරීමට සහ සෝදිසි කිරීමට යෙදුමට අවසර දෙන්න. ඇතැම්විට ඔබගේ අනුදැනුමකින් තොරව අනිෂ්ට උපාංග ජාල පැකැට්ටු අධීක්ෂණය,ආපසු දිශාගත කිරීම හෝ වෙනස්කිරීම සිදු කිරීමට ඉඩ තිබේ."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"ජාල සම්බන්ධතාව වෙනස් කිරීම"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"ජාල සම්බන්ධතාවයේ තත්වය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"ටෙදර් කරන ලද සම්බන්ධතා වෙනස් කිරීම"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"ටෙදර් කළ ජාල සම්බන්ධතාවයේ තත්වය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"පසුබිම් දත්ත භාවිත සැකසීම් වෙනස් කිරීම"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"පසුබිම් දත්ත භාවිතා සැකසීම වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"Wi-Fi සම්බන්ධතාවන් බැලීම"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"Wi-Fi සබල බව සහ සම්බන්ධිත Wi-Fi උපාංග වල නම් ආදී Wi-Fi ජාලකරණයේ තොරතුරු බැලීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"Wi-Fi වලට සම්බන්ධ විම සහ විසන්ධි කිරීම"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"Wi-Fi ප්‍රවේශ ස්ථානයන් වෙත සම්බන්ධ වීමට සහ විසන්ධි වීමට සහ, Wi-Fi ජාල සඳහා උපාංගයේ වින්‍යාසයට වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"Wi-Fi බහුවිකාශන පිළිගැනීමට අවසර දෙන්න"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"ඔබගේ ටැබ්ලටයට පමණක් නොව Wi-Fi ජාලයේ ඇති සියලුම උපාංගවලට යැවූ පැකැට්ටු බහු විකාශ ලිපින භාවිතයෙන් ලබාගැනීමට යෙදුමට අවසර දෙන්න. non-multicast ආකාරයට වඩා වැඩි බලයක් මෙහිදී භාවිතා වේ."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"ඔබගේ දුරකථනයට පමණක් නොව Wi-Fi ජාලයේ ඇති සියලුම යෙදුම්වලට යැවූ පැකැට්ටු බහුවාහක ලිපින භාවිතයෙන් ලබාගැනීමට යෙදුමට අවසර ලැබේ. බහුවාහක නැති ආකාරයට වඩා වැඩි බලයක් මෙහිදී භාවිතා වේ."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"බ්ලූටූත් සැකසීම් ප්‍රවේශය"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"ස්ථානීය බ්ලූටූත් ටැබ්ලට්යක් සැකසීමට සහ වින්‍යාස කිරීමට සහ දුරස්ථ උපාංග සමග යුගළ කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"දුරකථනයේ පෙදෙසි බ්ලූටූත් වින්‍යාස කිරීමට, සහ දුරස්ථ උපාංග ගවේෂණයට සහ යුගල වීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX වෙතට සම්බන්ධ කරන්න හෝ විසන්ධි කරන්න"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"WiMAX සබල බව සහ සම්බන්ධිත ඕනෑම WiMAX ජාලයක තොරතුරු නිශ්චය කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"WiMAX තත්වය වෙනස් කරන්න"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"ටැබ්ලටය WiMAX ජාල වෙත සම්බන්ධ කිරීමට සහ විසන්ධි කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"WiMAX ජාලයන්ට දුරකථනය සම්බන්ධ කිරීමට සහ විසන්ධි කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"බ්ලූටූත් උපාංග සමඟ යුගල කිරීම"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"ටැබ්ලටයේ බ්ලූටූත් වින්‍යාසය බැලිමට, සැකසීමට සහ යුගල කළ උපාංග සමඟ සම්බන්ධතාවන් පිළිගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"දුරකථනයේ බ්ලූටූත් වින්‍යාසය දැකීමට, යුගල උපාංග සමඟ සම්බන්ධතාවන් සැකසීමට සහ භාරගැනීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"ආසන්න ක්ෂේත්‍ර සන්නිවේදනය පාලනය කරන්න"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"ආසන්න ක්ෂේත්‍ර සන්නිවේදන (NFC) ටැග්, පත්, සහ කියවන්නන් සමඟ සන්නිවේදනය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"ඔබගේ තිරයේ අගුල අබල කරන්න"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"යතුරු අගුල සහ ඕනෑම සම්බන්ධිත මුරපද ආරක්ෂාවක් අබල කිරීමට යෙදුමට අවසර දෙන්න. මෙහි උදාහරණයක් වන්නේ පැමිණෙන ඇමතුමක් ලැබෙද්දී, දුරකථනය අක්‍රිය වන අතර ඇමතුම අවසාන වන විට යතුරු අගුල නැවත සක්‍රිය වෙයි."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"සමමුහුර්ත සැකසීම් කියවන්න"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"ගිණුම සඳහා සමමුහුර්ත සැකසීම් කියවීමට යෙදුමට අවසර දෙන්න. උදාහරණයක් ලෙස, ගිණුමක් සමඟ පුද්ගල යෙදුම සමමුහුර්ත දැයි මෙයට හඳුනා ගත හැක."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"සමමුහුර්ත කිරීම සක්‍රිය කරන්න සහ අක්‍රිය කරන්න"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"ගිණුම සඳහා සමමුහුර්ත සැකසීම් වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. උදාහරණයක් ලෙස, ගිණුම සමඟ පුද්ගල යෙදුම සමමුහුර්ත කිරීම සක්‍රිය කිරීමට භාවිත කල හැක."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"සමමුහුර්ත කිරීමේ සංඛ්‍යාන කියවීම"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"සමමුහුර්ත කිරීමේ සිදුවීම් ඉතිහාසය සහ කෙතරම් දත්ත සමමුහුර්ත වී ඇතිදැයි ඇතුලත් ගිණුම සඳහා සමමුහුර්ත කිරීමේ සංඛ්‍යාන කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"දායක වූ සංග්‍රහ කියවීම"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"වර්තමාන සමමුහුර්ත සංග්‍රහ ගැන විස්තර ලැබීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"දායක වූ සංග්‍රහ ලිවීම"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"ඔබගේ වර්තමාන සමමුහුර්ත සංග්‍රහ වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ සමමුහුර්ත සංග්‍රහ අනිෂ්ට යෙදුම්වලින් වෙනස් කල හැක."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"ඔබ විසින් ශබ්දකෝෂයට ඇතුළත්කොට ඇති කොන්දේසි කියවීම"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"පරිශීලක ශබ්ද කෝෂයේ පරිශීලකයන් විසින් ගබඩා කර තිබිය හැකි වචන, නම්, වාක්‍යංශ කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"පරිශීලකයින් අර්ථ දැක්වූ ශබ්ද කෝෂයට වචන එකතු කිරීම"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"පරිශීලක ශබ්දකෝෂය තුළට අලුත් වචන ලිවීමට යෙදුමට ඉඩ දෙන්න."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"ආරක්‍ෂිත ආචයනය වෙත ප්‍රවේශය පරීක්ෂා කිරීම"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"ආරක්‍ෂිත ආචයනය වෙත ප්‍රවේශය පරීක්ෂා කිරීම"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"අනාගත උපාංගවල ලබාගත හැකි USB ආචයනය සඳහා අවසරයක් පරීක්ෂා කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"අනාගත උපාංගවල පැවතෙන SD කාඩ් පත සඳහා අවසරයක් පිරික්සීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"ඔබගේ USB ආචයනයේ අන්තර්ගත වෙනස් කිරීම හෝ මැකීම"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"ඔබගේ SD පතේ අන්තර්ගත වෙනස් කිරීම හෝ මැකීම"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"USB ආචයනය වෙත ලිවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"SD පත වෙත ලිවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"අභ්‍යන්තර මාධ්‍ය ආචයනය අන්තර්ගත වෙනස් කරන්න/ මකන්න"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"අභ්‍යන්තර මාධ්‍ය ආචයනයේ අන්තර්ගතය වෙනස් කිරීමට උපාංගයට අවසර දෙන්න."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"ලේඛන ආචයනය කළමනාකරණය කරන්න"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"ලේඛන ආචයනය කළමනාකරණය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"සියලුම පරිශීලකයන්ගේ බාහිර ආචයන වෙත පිවිසෙන්න"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"සියලු පරිශීලකයන් සඳහා බාහිර ආචයනය වෙත පිවිසීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"හැඹිලි ගොනු පද්ධතියට ප්‍රවේශ වීම"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"හැඹිලි ගොනු පද්ධති කියවීමට සහ ලිවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"අන්තර්ජාල ඇමතුම් ගන්න/ලබන්න"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"අන්තර්ජාල ඇමතුම් ගැනීමට/ලැබීමට SIP සේවාව භාවිතයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"ඉතිහාසගත ජාල භාවිතය කියවන්න"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"විශේෂිත ජාල සහ යෙදුම් සඳහා ඉතිහාසගත ජාල භාවිතය කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"ජාල ප්‍රතිපත්තිය කළමනාකරණය කිරීම"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"ජාල කොන්දේසි සහ සඳහන් යෙදුම් විශේෂීත රීති කළමනාකරණය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"ජාල භාවිත ගිණුම් කිරීම වෙනස් කිරීම"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"යෙදුම්වලට ජාල භාවිතයෙන් වන බලපෑම කෙසේද යන්න වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"කෙවෙනි ලකුණු වෙනස් කරන්න"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"මාර්ගගත වීම සඳහා කෙවෙනියේ ලකුණු වෙනස් කිරීමට යෙදුමට ඉඩ දෙන්න"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"ප්‍රවේශ දැනුම්දීම්"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"වෙනත් යෙදුම් විසින් කළ පල කිරීම්ද ඇතුළත්ව දැන්වීම් ලබා ගැනීමට, පරීක්ෂා කිරීමට සහ හිස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"දැනුම්දීම ඇහුම්කන් දීම් සේවාවක් වෙත බඳින්න"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"දැනුම්දීම් අසන්නාගේ සේවාවේ ඉහළ මට්ටමේ අතුරුමුහුණතට බැඳීමට දරන්නාට අවසර දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අවශ්‍ය නොවේ."</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"වාහකය සැපයු වින්‍යාසය යෙදුම ඉල්ලා සිටින්න"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"වාහකයා ලබාදුන් සැකසුම් යෙදුම් උත්පාදනයට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"ජාල තත්ව මත නිරීක්ෂණ වෙත ඇහුම්කන් දීම"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"යෙදුමකට ජාල තත්ව මත නිරීක්ෂණ වෙත ඇහුම්කන් දීමට අවසර දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_hotwordRecognition" msgid="3225080408746361313">"අණවදන හඳුනාගැනීම ඉල්ලයි"</string>
-    <string name="permdesc_hotwordRecognition" msgid="3716741260195364252">"අණවදන හඳුනාගැනීම සඳහා ඉල්ලීමට යෙදුමට ඉඩ දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"මුරපද නීති සකස් කිරීම"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"තිරය අගුළු ඇරීමේ මුරපදයට අනුමත අකුරු සහ දිග පාලනය කරන්න."</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"තිරය අගුළු ඇරීමේ උත්සාහයන් නිරීක්ෂණය කරන්න"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"තිරය අගුළු හැරීමේදී වැරදියට ටයිප් කළ මුරපද ගණන නිරීක්ෂණය කරන්න සහ ටැබ්ලටය අගුළු දමන්න හෝ වැරදි මුරපද බොහෝ ගණනක් ටයිප් කර ඇති නම් ටැබ්ලටයේ සියලු දත්ත මකන්න."</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"තිරය අගුළු හැරීමේදී වැරදියට ටයිප් කළ මුරපද ගණන නිරීක්ෂණය කරන්න සහ දුරකථනය අගුළු දමන්න හෝ වැරදි මුරපද බොහෝ ගණනක් ටයිප් කර ඇති නම් දුරකථනයේ සියලු දත්ත මකන්න."</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"තිරය අගුළු ඇරීමේ මුරපදය වෙනස් කිරීම"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"තිරය අගුළු ඇරීමේ මුරපදය වෙනස් කරන්න."</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"තිරය අගුළු දැමීම"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"තිරයට අගුළු වැටීම සිදුවන්නේ කෙසේද සහ කවදාද යන්න පාලනය කරන්න."</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"සියලු දත්ත මකන්න"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"කර්මාන්ත ශාලා දත්ත යළි පිහිටුවීමෙන් පසුව අනතුරු ඇඟවිමකින් තොරවම ටැබ්ලට් දත්ත මකා දමයි."</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"කර්මාන්ත ශාලා දත්ත යළි පිහිටුවීමෙන් පසුව අනතුරු ඇඟවිමකින් තොරවම දුරකථන දත්ත මකා දමයි."</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"උපාංග ගෝලීය නියුතුව සකස් කිරීම"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"කොන්දේසි සක්‍රිය විට පොදු නියුතු එකක් භාවිත කරන ලෙස උපාංගය සකසන්න. පළමු උපාංග පරිපාලකයා පමණක් ඵලදායි පොදු නියුතුව සකසයි."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"තිරය අගුළු දැමීමේ මුරපදය කල් ඉකුත්වීම සකසන්න"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"තිර-අගුළේ මුරපදය වෙනස්වීම කොපමණ කාල පරාසයකින් සිදුවිය යුතුද යන්න පාලනය කිරීම."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"ආචයනයේ සංකේතනය සකස් කිරීම"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"ආචයනය කළ යෙදුම් දත්ත සංකේතනය කිරීමට අවශ්‍යය."</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"කැමරා අබල කිරීම"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"සියලු උපාංග කැමරාවල භාවිතය වලක්වන්න."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"යතුරු ආරක්ෂාවේ විශේෂාංග අබල කරන්න"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"යතුරු ආරක්ෂාව හි සමහර විශේෂාංග භාවිතය වළක්වයි."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"නිවස"</item>
-    <item msgid="869923650527136615">"ජංගම"</item>
-    <item msgid="7897544654242874543">"කාර්යාලය"</item>
-    <item msgid="1103601433382158155">"කාර්යාල ෆැක්ස්"</item>
-    <item msgid="1735177144948329370">"නිවසේ ෆැක්ස්"</item>
-    <item msgid="603878674477207394">"පේජරය"</item>
-    <item msgid="1650824275177931637">"වෙනත්"</item>
-    <item msgid="9192514806975898961">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"මුල් පිටුව"</item>
-    <item msgid="7084237356602625604">"කාර්යාලය"</item>
-    <item msgid="1112044410659011023">"වෙනත්"</item>
-    <item msgid="2374913952870110618">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"නිවස"</item>
-    <item msgid="5629153956045109251">"කාර්යාලය"</item>
-    <item msgid="4966604264500343469">"වෙනත්"</item>
-    <item msgid="4932682847595299369">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"නිවස"</item>
-    <item msgid="1359644565647383708">"කාර්යාලය"</item>
-    <item msgid="7868549401053615677">"වෙනත්"</item>
-    <item msgid="3145118944639869809">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"කාර්යාලය"</item>
-    <item msgid="4378074129049520373">"වෙනත්"</item>
-    <item msgid="3455047468583965104">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"අභිරුචි"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"නිවස"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"ජංගම"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"කාර්යාලය"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"කාර්යාල ෆැක්ස්"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"නිවසේ ෆැක්ස්"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"පේජරය"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"වෙනත්"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"යළි ඇමතීම"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"මෝටර් රථය"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"ආයතනයේ මූලිකය"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"මූලික"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"වෙනත් ෆැක්ස්"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"රේඩියෝව"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"ටෙලෙක්ස්"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"කාර්යාල ජංගම"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"කාර්යාල පේජරය"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"සහායක"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"අභිරුචි"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"උපන්දිනය"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"සංවත්සරය"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"වෙනත්"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"අභිරුචි"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"නිවස"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"කාර්යාලය"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"වෙනත්"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"ජංගම"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"අභිරුචි"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"නිවස"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"කාර්යාලය"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"වෙනත්"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"අභිරුචි"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"මුල් පිටුව"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"කාර්යාලය"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"වෙනත්"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"අභිරුචි"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Hangouts"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"කාර්යාලය"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"වෙනත්"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"අභිරුචි"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"අභිරුචි"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"සහායක"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"සහෝදරයා"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"දරුවා"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"දේශීය හවුල්කරුවා"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"පියා"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"මිත්‍රයා"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"කළමනාකරු"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"මව"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"මව්පිය"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"හවුල්කරුවා"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"යොමුකරන ලද්දේ"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"නෑයා"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"සහෝදරිය"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"භාර්යාව හෝ ස්වාමිපුරුෂයා"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"අභිරුචි"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"නිවස"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"කාර්යාලය"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"වෙනත්"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PIN කේතය ටයිප් කරන්න"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK සහ නව PIN කේතය ටයිප් කරන්න"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK කේතය"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"නව PIN කේතය"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"මුරපදය ටයිප් කිරීමට ස්පර්ශ කරන්න"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"අගුළු ඇරීමට මුරපදය ටයිප් කරන්න"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"අගුළු හැරීමට PIN එක ටයිප් කරන්න"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"වැරදි PIN කේතයකි."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"අගුළු ඇරීමට, මෙනුව ඔබා පසුව 0 ද ඔබන්න."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"හදිසි ඇමතුම් අංකය"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"සේවාව නැත."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"තිරය අගුළු දමා ඇත."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"අගුළු හැරීමට මෙනුව ඔබන්න හෝ හදිසි ඇමතුම ලබාගන්න."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"අගුළු හැරීමට මෙනු ඔබන්න."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"අගුළු ඇරීමට රටාව අඳින්න"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"හදිසි ඇමතුම්"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"ඇමතුම වෙත නැවත යන්න"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"නිවැරදියි!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"නැවත උත්සාහ කරන්න"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"නැවත උත්සාහ කරන්න"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"මුහුණ භාවිතයෙන් අඟුළු හැරීමේ උපරිම ප්‍රයන්තයන් ගණන ඉක්මවා ඇත"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"ආරෝපණය වෙමින්, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"අරෝපිතයි"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"ඔබගේ ආරෝපකයට සම්බන්ධ කරන්න."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM පත නැත"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"ටැබ්ලටයේ SIM පත නොමැත."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"දුරකථනය තුළ SIM පත නැත."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SIM පතක් ඇතුල් කරන්න."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM පත නොමැත හෝ කියවිය නොහැක. SIM පතක් ඇතුලත් කරන්න."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"භාවිතා කළ නොහැකි SIM පත."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"ඔබගේ SIM පත ස්ථිරව අබල කර තිබේ.\n වෙනත් SIM පතක් සඳහා ඔබගේ සේවාදායකයා සම්බන්ධ කරගන්න."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"පෙර ගීත බොත්තම"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"ඊළඟ ගීත බොත්තම"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"විරාම බොත්තම"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"ධාවක බොත්තම"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"නැවතීමේ බොත්තම"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"හදිසි ඇමතුම් පමණි"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"ජාලය අගුළු දමා ඇත"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM පත PUK අගුළු දමා ඇත."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"පරිශීලක උපදේශය බලන්න හෝ පරිභෝගික සේවාව අමතන්න."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM පත අගුළු දමා ඇත."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM පත අගුළු අරිමින්..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"ඔබ <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් අගුළු ඇරීමේ රටාව වැරදියට ඇඳ ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"ඔබ මුරපදය වාර <xliff:g id="NUMBER_0">%d</xliff:g> ක් වැරදියට ටයිප්කොට ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> කින් නැවත උත්සහ කරන්න."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"ඔබ PIN අංකය <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් වැරදියට ටයිප් කොට ඇත.\n\n තත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"ඔබ වැරදියට <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ අගුළු හැරීමේ රටාව ඇඳ ඇත. අසාර්ථක උත්සහ කිරීම් <xliff:g id="NUMBER_1">%d</xliff:g> න් පසුව, ඔබගේ Google පුරනය වීම් භාවිතයෙන් ඔබගේ ටැබ්ලටය අගුළු හැරීමට ඔබගෙන් අසයි.\n\n තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"ඔබ වැරදියට <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ අගුළු හැරීමේ රටාව ඇඳ ඇත. අසාර්ථක උත්සහ කිරීම් <xliff:g id="NUMBER_1">%d</xliff:g> න් පසුව, ඔබගේ Google පුරනය වීම භාවිතයෙන් ඔබගේ දුරකථනය අගුළු හැරීමට ඔබගෙන් අසනු ඇත.\n\n තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"ඔබ ටැබ්ලටය අගුළු හැරීමට වැරදියට අවස්ථා <xliff:g id="NUMBER_0">%d</xliff:g> ක් උත්සාහ කර ඇත. අවස්ථා <xliff:g id="NUMBER_1">%d</xliff:g> ක් අසාර්ථකව උත්සහ කිරීමකින් පසුව, ටැබ්ලටය කර්මාන්ත ශාලා මුල් තත්වයට නැවත පත් වන අතර සියලු පරිශීලක දත්ත නැති වෙයි."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER_0">%d</xliff:g> කදී වැරදී ප්‍රයත්නයන් ගෙන තිබේ. තවත් අසාර්ථක ප්‍රයත්න <xliff:g id="NUMBER_1">%d</xliff:g> කින් පසුව, දුරකථනය කර්මාන්තශාලාවේ පෙරනිමියට යළි පිහිටුවන අතර සියලුම පරිශීලක දත්ත නැති වී යයි."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"ටැබ්ලටයේ අගුළු ඇරීමට ඔබ වැරදි ප්‍රයත්න <xliff:g id="NUMBER">%d</xliff:g> වාරයක් ගෙන ඇත. දැන් ටැබ්ලටය කර්මාන්තශාලා සුපුරුද්ද වෙත යළි පිහිටුවීම කෙරේ."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER">%d</xliff:g> කදී වැරදී ප්‍රයත්නයන් ගෙන තිබේ. දැන් දුරකථනය කර්මාන්තශාලා පෙරනිමියට පිහිටුවනු ලබයි."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"තත්පර <xliff:g id="NUMBER">%d</xliff:g> කින් නැවත උත්සාහ කරන්න."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"රටාව අමතකද?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"ගිණුමේ අගුළු අරින්න"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"රටා උත්සාහ කිරීම් වැඩිය"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"අගුළු හැරීමට, ඔබගේ Google ගිණුම සමග පුරනය වන්න."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"පරිශීලක නාමය (ඊ-තැපෑල)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"මුරපදය"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"පුරනය වෙන්න"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"වලංගු නොවන පරිශීලක නාමයක් හෝ මුරපදයක්."</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"ඔබගේ පරිශීලක නාමය හෝ මුරපදය අමතකද?\n "<b>"google.com/accounts/recovery"</b>" වෙත යන්න."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"පරික්ෂා කරමින්..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"අඟුල අරින්න"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"ශබ්දය සක්‍රීය කරන්න"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"ශ්‍රව්‍ය අක්‍රිය කරන්න"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"රටාව අරඹන ලදි"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"රටාව හිස් කරන ලදි"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"කොටුවක් එකතු කරන ලදි"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"රටාව සම්පූර්ණයි"</string>
-    <!-- String.format failed for translation -->
-    <!-- no translation found for keyguard_accessibility_widget_changed (5678624624681400191) -->
-    <skip />
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"විජටය එකතු කරන්න."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"හිස්"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"අගුළු අරින ප්‍රදේශය විදහා ඇත."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"අගුළු අරින ප්‍රදේශය හැකිලී ඇත."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> විජට්."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"පරිශීලක තෝරන්නා"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"තත්වය"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"කැමරාව"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"මාධ්‍ය පාලක"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"විජටය නැවත අනුපිළිවෙළට සැකසිම ඇරඹුණි."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"විජට් නැවත අනුපිළිවෙලට සැකසීම අවසානය."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> විජටය මැකී ඇත."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"අගුළු නොදැමූ ප්‍රදේශය පුළුල් කරන්න."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"සර්පණ අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"රටා අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"මුහුණ භාවිතයෙන් අඟුළු හැරීම."</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"PIN අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"මුරපද අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"රටා ප්‍රදේශය."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"සර්පණ ප්‍රදේශය."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"අක්ෂරය"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"වචනය"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"සබැඳිය"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"රේඛාව"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"කර්මාන්ත ශාලා පරීක්ෂණය අසාර්ථකයි"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"FACTORY_TEST ක්‍රියාව /system/app හි ස්ථාපිත පැකේජ සඳහා පමණක් සහය දක්වයි."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"FACTORY_TEST ක්‍රියාව ලබාදෙන පැකේජයක් සොයාගත නොහැකි විය."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"පුනරාරම්භ කරන්න"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"\"<xliff:g id="TITLE">%s</xliff:g>\" හි ඇති පිටුව කියන්නේ:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"ජාවාස්ක්‍රිප්ට්"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"සංචලනය තහවුරු කරන්න"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"මෙම පිටුවෙන් ඉවත් වන්න"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"මෙම පිටුවෙහි ඉන්න"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nඔබට මෙම පිටුවෙන් සංචලනය කිරීමට අවශ්‍ය බවට ඔබට විශ්වාසද?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"තහවුරු කරන්න"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"උපදෙස: විශාලනය කිරීමට සහ කුඩා කිරීමට දෙවරක් තට්ටු කරන්න."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"ස්වයංක්‍රිය පිරවුම"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"ස්වයංක්‍රිය පිරවුම සකසන්න"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"පළාත"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"තැපැල් කේතය"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"ජනපදය"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ZIP කේතය"</string>
-    <string name="autofill_county" msgid="237073771020362891">"ප්‍රාන්තය"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"දූපත"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"දිස්ත්‍රික්කය"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"දෙපාර්තමේන්තුව"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"ප්‍රාන්තය"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"කෝරලය"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"ප්‍රදේශය"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"එමිරේට්"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"ඔබගේ වෙබ් පිටුසන් සහ ඉතිහාසය කියවීම"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"බ්‍රව්සරය නැරඹූ සියලු URL සහ සියලු බ්‍රව්සර පිටුසන් වල ඉතිහාසය කියවීමට යෙදුමට අවසර දෙන්න. සටහන: වෙබ් බ්‍රව්සර අවශ්‍යතා සමග තෙවෙනි පාර්ශව බ්‍රව්සර වලට හෝ වෙනත් යෙදුම්වලට මෙම අවසරය බල නොදෙයි."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"වෙබ් පිටුසන් සහ ඉතිහාසයට ලිවිම"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"ඔබගේ ටැබ්ලටයේ ගබඩා කර ඇති බ්‍රව්සරයේ ඉතිහාසය හෝ පිටුසන් වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. බ්‍රව්සර දත්ත මැකීමට හෝ වෙනස් කිරීමට මෙමඟින් යෙදුමට අවසර දෙයි. සටහන: වෙබ් ගවේෂණ හැකියාව සහිත තෙවෙනි පාර්ශව බ්‍රව්සර හෝ වෙනත් යෙදුම් වලින් මෙම අවසරයට බල නොකරයි."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"ඔබගේ දුරකථනයේ ආචයනය කරන ලද බ්‍රව්සර ඉතිහාසය හෝ පිටුසන වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ බ්‍රව්සර දත්ත මැකීමට හෝ වෙනස් කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කරයි. සටහන: වෙබ් බ්‍රව්සර අවශ්‍යතාවය සමග තෙවෙනි පාර්ශව බ්‍රව්සර හෝ වෙනත් යෙදුම් විසින් මෙම අවසරය බල ගැන්විය හැක."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"සීනුවක් සැකසීම"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"ස්ථාපනය කරන ලද සීනු ඔරලෝසු යෙදුමේ සීනුව සකස් කරන්නට යෙදුමට ඉඩ දෙන්න. ඇතැම් සීනු ඔරලෝසු යෙදුම් මෙම අංගය ක්‍රියාවට නංවා නොතිබීමට ඉඩ තිබේ."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"හඬ තැපෑල එක් කිරීම"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"ඔබගේ හඬ තැපෑලේ එන ලිපි වෙත එන පණිවිඩ එකතු කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"බ්‍රව්සරයේ භූ අවසර වෙනස් කිරීම"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"බ්‍රවුසරයේ භූ ස්ථානීය අවසර වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. අභිමත වෙබ් අඩවි වලට ස්ථානීය තොරතුරු යැවීමට අනිෂ්ට යෙදුම් මෙය භාවිතා කෙරේ."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"පැකේජ සත්‍යාපනය කරන්න"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"ස්ථාපිත කොට ඇති පැකේජයක් සත්‍යාපනයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"පැකේජ සත්‍යාපකයක් වෙත බඳින්න"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"පැකේජ සත්‍යාපක ඉල්ලීම් වලට දරන්නාට ඉඩ ලබා දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අවශ්‍ය නොවේ."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"ශ්‍රේණිගත පොට ප්‍රවේශ කිරීම"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"SerialManager API භාවිතයෙන් අනුක්‍රම තොට වෙත ප්‍රවේශ වීමට රඳවනයට අවසර දෙන්න."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"බාහිර අන්තර්ගත සැපයුම්කරුවන් වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"අන්තර්ගත සපයන්නන්ට ප්‍රවේශ වීමට දරන්නන්ට ෂෙල් එකේ සිට ප්‍රවේශ වීමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අදාළ නොවේ."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"ස්වයංක්‍රීය උපාංග යවත්කාල කිරීම් පසුබට කරන්න"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"උපාංගය උත්ශ්‍රේණිකරණයට අන්තර්ක්‍රියාකාරී නොවන යළි ඇරඹීමක් සඳහා සුදුසු වෙලාව කුමක්ද යන්න ගැන පද්ධතියට තොරතුරු ලබාදීමට දරන්නාට අවසර දෙන්න."</string>
-    <string name="save_password_message" msgid="767344687139195790">"බ්‍රව්සරයට මෙම මුරපදය මතක තබා ගැනීමට ඔබට අවශ්‍යද?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"දැන් නොවේ"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"මතක තබා ගන්න"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"කවදාවත් නොවේ"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"මෙම පිටුව විවෘත කිරීමට ඔබට අවසර නැත."</string>
-    <string name="text_copied" msgid="4985729524670131385">"පෙළ පසුරු පුවරුවට පිටපත් කරන ලදි."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"තව"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"මෙනුව+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"space"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"ඇතුල් කරන්න"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"මකන්න"</string>
-    <string name="search_go" msgid="8298016669822141719">"සෙවීම"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"සෙවීම"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"සෙවුම් විමසුම"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"විමසුම හිස් කරන්න"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"විමසුම යොමු කරන්න"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"හඬ සෙවීම"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"ස්පර්ශ කිරීමෙන් ගවේෂණය සබල කරන්න ද?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය කිරීමට <xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ට අවශ්‍යය. ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය විට, ඔබගේ ඇඟිලිවලට පහළ විස්තර ඇසිය හෝ බැලිය හැක හෝ ටැබ්ලටය සමග අන්තර් ක්‍රියාකාරී වීමට ඉංගිති සිදු කළ හැක."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය කිරීමට <xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ට අවශ්‍යයි. ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය විට, ඔබගේ ඇඟිලිවලට පහළ විස්තර ඇසිය හෝ බැලිය හැක හෝ දුරකථනය සමග අන්තර් ක්‍රියාකාරී වීමට ඉංගිති සිදු කළ හැක."</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"මාස 1 කට පෙර"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"මාස 1 කට පෙර"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"තත්පර 1 කට පෙර"</item>
-    <item quantity="other" msgid="3903706804349556379">"තත්පර <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"මිනිත්තු 1 ට පෙර"</item>
-    <item quantity="other" msgid="2176942008915455116">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"පැය 1 කට පෙර"</item>
-    <item quantity="other" msgid="2467273239587587569">"පැය <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"අන්තිම දවස් <xliff:g id="COUNT">%d</xliff:g>"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"අවසාන මාසය"</string>
-    <string name="older" msgid="5211975022815554840">"පරණ"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"ඊයේ"</item>
-    <item quantity="other" msgid="2479586466153314633">"දින <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"තත්පර 1 කින්"</item>
-    <item quantity="other" msgid="1241926116443974687">"තත්පර <xliff:g id="COUNT">%d</xliff:g> කදී"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"මිනිත්තු 1 කදී"</item>
-    <item quantity="other" msgid="3330713936399448749">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"පැය 1 ක් තුළ"</item>
-    <item quantity="other" msgid="547290677353727389">"පැය <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"හෙට"</item>
-    <item quantity="other" msgid="5109449375100953247">"දින <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"තත්පර 1 කට පෙර"</item>
-    <item quantity="other" msgid="3699169366650930415">"තත්පර <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"මිනිත්තු 1 කට පෙර"</item>
-    <item quantity="other" msgid="851164968597150710">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"පැය 1 කට පෙර"</item>
-    <item quantity="other" msgid="6889970745748538901">"පැය <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"ඊයේ"</item>
-    <item quantity="other" msgid="3453342639616481191">"දින <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"තත්පර 1 ක් තුළ"</item>
-    <item quantity="other" msgid="5495880108825805108">"තත්පර <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"මිනිත්තු 1 ක් තුළ"</item>
-    <item quantity="other" msgid="4216113292706568726">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"පැය 1 ක් තුළ"</item>
-    <item quantity="other" msgid="3705373766798013406">"පැය <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"හෙට"</item>
-    <item quantity="other" msgid="2973062968038355991">"දින <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g> වන දා"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"<xliff:g id="TIME">%s</xliff:g> ට"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> තුළ"</string>
-    <string name="day" msgid="8144195776058119424">"දවස"</string>
-    <string name="days" msgid="4774547661021344602">"දින"</string>
-    <string name="hour" msgid="2126771916426189481">"පැය"</string>
-    <string name="hours" msgid="894424005266852993">"පැය"</string>
-    <string name="minute" msgid="9148878657703769868">"min"</string>
-    <string name="minutes" msgid="5646001005827034509">"මිනිත්තු"</string>
-    <string name="second" msgid="3184235808021478">"තත්"</string>
-    <string name="seconds" msgid="3161515347216589235">"තත්පර"</string>
-    <string name="week" msgid="5617961537173061583">"සතිය"</string>
-    <string name="weeks" msgid="6509623834583944518">"සති"</string>
-    <string name="year" msgid="4001118221013892076">"අවුරුද්ද"</string>
-    <string name="years" msgid="6881577717993213522">"අවුරුදු"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"තත්පර 1"</item>
-    <item quantity="other" msgid="1886107766577166786">"තත්පර <xliff:g id="COUNT">%d</xliff:g>"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"මිනිත්තු 1"</item>
-    <item quantity="other" msgid="3165187169224908775">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g>"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"පැය 1"</item>
-    <item quantity="other" msgid="3863962854246773930">"පැය <xliff:g id="COUNT">%d</xliff:g> ක්"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"වීඩියෝ ගැටලුව"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"මේ වීඩියෝව මෙම උපාංගයට ප්‍රවාහනය සඳහා වලංගු නැත."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"මෙම වීඩියෝව ධාවනය කළ නොහැක."</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"හරි"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"මධ්‍යහනය"</string>
-    <string name="Noon" msgid="3342127745230013127">"මධ්‍යාහනය"</string>
-    <string name="midnight" msgid="7166259508850457595">"මධ්‍යම රාත්‍රිය"</string>
-    <string name="Midnight" msgid="5630806906897892201">"මධ්‍යම රාත්‍රිය"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"සියල්ල තෝරන්න"</string>
-    <string name="cut" msgid="3092569408438626261">"කපන්න"</string>
-    <string name="copy" msgid="2681946229533511987">"පිටපත් කරන්න"</string>
-    <string name="paste" msgid="5629880836805036433">"අලවන්න"</string>
-    <string name="replace" msgid="5781686059063148930">"ප්‍රතිස්ථාපනය කරන්න..."</string>
-    <string name="delete" msgid="6098684844021697789">"මකන්න"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL පිටපත් කරන්න"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"පෙළ තෝරන්න"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"පෙළ තේරීම"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"ශබ්ද කෝෂයට එකතු කරන්න"</string>
-    <string name="deleteText" msgid="6979668428458199034">"මකන්න"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"ආදාන ක්‍රමය"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"පෙළ ක්‍රියාවන්"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"ආචයනය ඉඩ ප්‍රමාණය අඩු වී ඇත"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"සමහර පද්ධති කාර්යයන් ක්‍රියා නොකරනු ඇත"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> ධාවනය වේ"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"වැඩිපුර තොරතුරු හෝ යෙදුම නැවතීම සඳහා ස්පර්ශ කරන්න."</string>
-    <string name="ok" msgid="5970060430562524910">"හරි"</string>
-    <string name="cancel" msgid="6442560571259935130">"අවලංගු කරන්න"</string>
-    <string name="yes" msgid="5362982303337969312">"හරි"</string>
-    <string name="no" msgid="5141531044935541497">"අවලංගු කරන්න"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"අවධානය"</string>
-    <string name="loading" msgid="7933681260296021180">"පූරණය වෙමින්..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"සක්‍රීයයි"</string>
-    <string name="capital_off" msgid="6815870386972805832">"අක්‍රිය කරන්න"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"පහත භාවිතයෙන් ක්‍රියාව සම්පූර්ණ කරන්න"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"මෙම ක්‍රියාව සඳහා සුපුරුද්දෙන් භාවිත කරන්න."</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"පද්ධති සැකසීම් &gt; යෙදුම් &gt; බාගැනීම් තුළ ඇති සුපුරුද්ද හිස් කරන්න."</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"ක්‍රියාවක් තෝරන්න"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB උපාංගය සඳහා යෙදුමක් තෝරන්න"</string>
-    <string name="noApplications" msgid="2991814273936504689">"මෙම ක්‍රියාව සිදු කිරීමට කිසිදු යෙදුමකට නොහැකිය."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"අවාසනාවන්ත ලෙස <xliff:g id="APPLICATION">%1$s</xliff:g> නැවතී ඇත."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"අවාසනාවන්ත ලෙස, <xliff:g id="PROCESS">%1$s</xliff:g> ක්‍රියාවලිය නතර විණි."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> ප්‍රතිචාර නොදක්වයි.\n\nඔබට එය නතර කිරීමට අවශ්‍යද?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> ක්‍රියාකාරකම ප්‍රතිචාර නොදක්වයි.\n\nඑය වසා දැමීමට ඔබට අවශ්‍යද?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> ප්‍රතිචාර නොදක්වයි. එය වසා දැමීමට ඔබට අවශ්‍යද?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"<xliff:g id="PROCESS">%1$s</xliff:g> ක්‍රියාවලිය ප්‍රතිචාර නොදක්වයි.\n\nඔබට එය නතර කිරීමට අවශ්‍යද?"</string>
-    <string name="force_close" msgid="8346072094521265605">"හරි"</string>
-    <string name="report" msgid="4060218260984795706">"වාර්තාව"</string>
-    <string name="wait" msgid="7147118217226317732">"රැඳී සිටින්න"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"පිටුව ප්‍රතිචාර නොදක්වන තත්වයට පත්වී ඇත.\n\nඔබට එය වැසීමට අවශ්‍යද?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"යෙදුම නැවත හරවා යවා ඇත"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> දැන් ධාවනය වෙයි."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> මුලින්ම අරඹා ඇත."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"පරිමාණය"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"සැමවිටම පෙන්වන්න"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"පද්ධති සැකසීම් තුළ මෙය නැවත ක්‍රියාත්මක කරන්න &gt; යෙදුම් &gt; බාගන්නා ලදි."</string>
-    <string name="smv_application" msgid="3307209192155442829">"<xliff:g id="APPLICATION">%1$s</xliff:g> යෙදුම (<xliff:g id="PROCESS">%2$s</xliff:g> ක්‍රියාවලිය) එහි StrictMode කොන්දේසිය උල්ලංඝනය කර ඇත."</string>
-    <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> ක්‍රියාවලිය එහි StrictMode කොන්දේසිය උල්ලංඝනය කර ඇත."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android උත්ශ්‍රේණි වෙමින් පවතී..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"<xliff:g id="NUMBER_1">%2$d</xliff:g> කින් <xliff:g id="NUMBER_0">%1$d</xliff:g> වැනි යෙදුමප්‍ රශස්ත කරමින්."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"යෙදුම් ආරම්භ කරමින්."</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"ඇරඹුම අවසාන කරමින්."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> ධාවනය වෙමින්"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"යෙදුමට මාරු වීමට ස්පර්ශ කරන්න"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"යෙදුම් මාරු වනවාද?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"අලුත් යෙදුමක් ආරම්භ කිරීමට පෙර තවමත් ක්‍රියාවෙහි යෙදෙමින් පවතින යෙදුම නැවැත්විය යුතුයි."</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g> වෙත ආපසු යන්න"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"නව යෙදුම ආරම්භ නොකරන්න."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> අරඹන්න"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"සුරැකීමකින් තොරව පරණ යෙදුම නවත්වන්න."</string>
-    <string name="sendText" msgid="5209874571959469142">"පෙළ සඳහා ක්‍රියාව තෝරන්න"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"හඬ නඟනයේ ශබ්දය"</string>
-    <string name="volume_music" msgid="5421651157138628171">"මාධ්‍ය ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"බ්ලූටූත් හරහා ධාවනය වෙයි"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"නිහඬ රිගින් ටෝනයක් සකසන්න"</string>
-    <string name="volume_call" msgid="3941680041282788711">"ඇමතුම-තුළ ශබ්ද ත්‍රීවතාව"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"බ්ලූටූත් ඇමතුම-තුළ ශබ්ද ත්‍රීවතාවය"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"සීනුවේ ශබ්දය"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"දැනුම්දීමේ ශබ්දය"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"බ්ලූටූත් ශබ්ද ත්‍රීවතාව"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"රින්ටෝනයේ ශබ්දය"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"ඇමතුම් ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"මාධ්‍ය ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"දැනුම්දීමේ ශබ්ද ත්‍රීවතාව"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"සුපුරුදු රින්ටෝනය සකසන්න"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"සුපුරුදු රින්ටෝනය (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"කිසිවක් නැත"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"රිගින්ටෝන"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"නොදන්නා රින්ටෝනය"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi ජාලයක් තිබේ"</item>
-    <item quantity="other" msgid="4192424489168397386">"Wi-Fi ජාල ඇත"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"විවෘත Wi-Fi ජාලය ලබාගත හැක"</item>
-    <item quantity="other" msgid="7915895323644292768">"විවෘත Wi-Fi ජාල තිබේ"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Wi-Fi ජලයට පුරනය වන්න"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"ජාලයට පුරනය වන්න"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Wi-Fi වෙත සම්බන්ධ විය නොහැක"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" දුබල අන්තර්ජාල සම්බන්ධතාවයක් ඇත."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"ඍජු Wi-Fi"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"ඍජු Wi-Fi ආරම්භ කරන්න. මෙය Wi-Fi සේවාදායක/හොට්ස්පොට් එක අක්‍රිය කරනු ඇත."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"ඍජු Wi-Fi ආරම්භ කළ නොහැක."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi ඍජු සම්බන්ධතාව සක්‍රියයි"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"සැකසීම් සඳහා ස්පර්ශ කරන්න"</string>
-    <string name="accept" msgid="1645267259272829559">"පිළිගන්න"</string>
-    <string name="decline" msgid="2112225451706137894">"ප්‍රතික්ෂේප කරන්න"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"ආරාධනාව යවන ලදි"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"සම්බන්ධතාවයට ඇරයුමකි"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"වෙතින්:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"වෙත:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"අවශ්‍ය PIN එක ටයිප් කරන්න:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"ටැබ්ලටය <xliff:g id="DEVICE_NAME">%1$s</xliff:g> වෙත සම්බන්ධ වන අතරතුර එය Wi-Fi වලින් තාවකාලිකව විසන්ධි කෙරේ."</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"දුරකථනය <xliff:g id="DEVICE_NAME">%1$s</xliff:g> ට සම්බන්ධ වී පවතින විට Wi-Fi වලින් එය තාවකාලිකව විසන්ධි වෙයි."</string>
-    <string name="select_character" msgid="3365550120617701745">"අකුර ඇතුළත් කරන්න"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS පණිවිඩ යවමින්"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; SMS පණිවිඩ විශාල ගණනක් යවයි. මෙම යෙදුමට පණිවිඩ යැවීම නොනැවතී කරගෙන යාමට අවසර දීමට ඔබට අවශ්‍යද?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"අවසර දෙන්න"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"ප්‍රතික්ෂේප කරන්න"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;b&gt; වෙත කෙටි පණිවීඩයක් යැවීමට &lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;b&gt; කැමතිය."</string>
-    <!-- syntax error in translation for sms_short_code_details (3492025719868078457) org.xmlpull.v1.XmlPullParserException: expected: /string read: font (position:END_TAG </font>@1:83 in     <string name="sms_short_code_details" msgid="3492025719868078457">"මෙය "</font>"ඔබගේ ජංගම ගිණුමේ"<font fgcolor="#ffffb060">" අය වීම් වලට හේතුවක් වේ."</string>
-)  -->
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"මෙය ඔබගේ ජංගම ගිණුමෙන් අයවීමට හේතු වේ."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"යවන්න"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"අවලංගු කරන්න"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"මගේ තේරීම මතක තබාගන්න"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"ඔබට මෙය සැකසීම් තුළ වෙනස්කර ගැනීම පසුව කළ හැක &gt; යෙදුම්"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"සැමවිටම ඉඩ දෙන්න"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"කිසිදා අවසර නොදෙන්න"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM පත ඉවත් කරන ලදි"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"ඔබ ඇතුළත් කරන ලද වලංගු SIM පත සමඟ නැවත ඇරඹීම කරන තුරු ජංගම ජාලය නොතිබේ."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"හරි"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM පතක් එකතු කරන ලදි"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"ජංගම ජාලයට ප්‍රවේශ වීමට ඔබගේ උපාංගය නැවත අරඹන්න."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"යළි අරඹන්න"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"වේලාව සකසන්න"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"දිනය සැකසීම"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"සකසන්න"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"හරි"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"අලුත්: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g> විසින් සපයන ලදි."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"අවසර අවශ්‍ය නොමැත"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"මෙමඟින් ඔබට මුදල් වැය විය හැක"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB මහා ආචයනය"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB සම්බන්ධිතයි"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"ඔබ ඔබගේ පරිගණකයට සම්බන්ධ වී ඇත්තේ USB ස්පර්ශය හරහාය. ඔබට ඔබේ පරිගණකය හා ඔබගේ Android USB ආචයනය අතර ගොනු පිටපත් කිරීමට අවශ්‍ය නම් පහත බොත්තම ඔබන්න."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"ඔබ ඔබගේ පරිගණකයට USB හරහා සම්බන්ධ වී ඇත. ඔබට ඔබේ පරිගණකය හා ඔබගේ Android SD පත අතර ගොනු පිටපත් කිරීමට අවශ්‍ය නම් පහත බොත්තම ස්පර්ශ කරන්න."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB ආචයනය සක්‍රිය කරන්න"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB මහා ආචයනය සඳහා ඔබගේ USB ආචයනය භාවිතයේදී ගැටළුවක් තිබේ."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"USB මහා ආචයනය සඳහා ඔබගේ SD පත භාවිතයේදී ගැටළුවක් තිබේ."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB සම්බන්ධිතයි"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"ඔබගේ පරිගණකය වෙතට/වෙතින් ගොනු පිටපත් කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB ආචයනය අක්‍රිය කරන්න"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB ආචයනය අක්‍රිය කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB ආචයනය භාවිතයේ පවතී"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB ආචයනය අක්‍රිය කිරීමට පෙර, ඔබගේ පරිගණකයෙන් Android USB ආචයනය ගලවා දමන්න (\"පිට කරන්න\")."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB ආචයනය අක්‍රිය කිරීමට පෙර, ඔබගේ Android SD පත පරිගණකයෙන් ගලවන්න."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB ආචයනය අක්‍රිය කරන්න"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB ආචයනය අක්‍රිය කිරීමේදී ගැටළුවක් ඇතිවිය. USB සංග්‍රාහකය ගලවා ඇති දැයි පරීක්ෂා කරන්න, පසුව නැවතත් උත්සහ කරන්න."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB ආචයනය සක්‍රිය කරන්න"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"ඔබ USB ආචයනය සක්‍රිය නම්, ඔබ භාවිතා කරන සමහර යෙදුම් නැවතීම සහ ඔබ USB ආචයනය අක්‍රිය කරන තුරු නොතිබේවී."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB ක්‍රියාවලිය අසාර්ථකයි"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"හරි"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"මාධ්‍ය උපාංගයක් ලෙස සම්බන්ධිතයි"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"කැමරාවක් ලෙස සම්බන්ධ කර ඇත"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"ස්ථාපිතයක් ලෙස සම්බන්ධයි"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB මෙවලමකට සම්බන්ධිතයි"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"අනෙක් USB විකල්පය සඳහා ස්පර්ශ කරන්න."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB ආචයනය ෆෝමැට් කරන්නද?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD පත ෆෝමැට් කරන්නද?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"ඔබගේ USB ආචයනයේ ඇති සියලුම ගොනු මැකී යනු ඇත. මෙම ක්‍රියාව ආපසු හැරවිය නොහැක!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"ඔබගේ පතේ සියලු දත්ත නැති වනු ඇත."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"ෆෝමැට්"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB නිදොස්කරණය සම්බන්ධිතයි"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB නිදොස්කරණය අබල කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"ආදාන ක්‍රමයක් තෝරන්න"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"ආදාන ක්‍රම සකසන්න"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"භෞතික යතුරු පුවරුව"</string>
-    <string name="hardware" msgid="7517821086888990278">"දෘඨාංග"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"යතුරු පුවරුවට පිරිසැලැස්ම තෝරන්න"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"යතුරු පුවරුවට පිරිසැලැස්මක් තේරීමට ස්පර්ශ කරන්න."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"අපේක්ෂකයන්"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB ආචයනය සකසමින්"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD පත සුදානම් කරමින්"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"වැරදි සඳහා පරීක්ෂා කරමින්."</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"හිස් USB ආචයනය"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"හිස් SD පත"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"SD පත හිස් හෝ සහාය නොදක්වන ගොනු පද්ධතියක් ඇත."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD පත හිස් හෝ සහය නොදක්වන ගොනු පද්ධතියක් ඇත"</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"හානි වූ USB ආචයනය"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"හානි වූ SD පත"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB ආචයනයට හානි වී ඇත. එය නැවත ෆෝමැට් ගැන්වීමට උත්සහ කරන්න."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD පතට හානි වී ඇත. එය නැවත ෆෝමැට් ගැන්වීමට උත්සහ කරන්න."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"බලාපොරොත්තු නොවූ ලෙස USB ආචයනය ඉවත් කෙරිණි"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD පත බලාපොරොත්තු රහිතව ඉවත් කරන ලදි"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"දත්ත නැතිවීම වැළක්වීමට USB ආචයනය ඉවත්කිරීමට පෙර ගලවන්න."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"දත්ත නැතිවීම වැළක්වීමට ගැලවීමට කලින් SD පත ඉවත් කරන්න."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"ඉවත් කිරීමට USB ආචයනය ආරක්ෂිතයි"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD පත ඉවත් කිරීමට සුරක්ෂිතයි"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"ඔබට USB ආචයනය ආරක්ෂිතව ඉවත් කිරීමට පුළුවනි."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"ඔබට ආරක්ෂිතව SD පත ඉවත් කළ හැක"</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"USB ආචයනය ඉවත් කරන ලදි"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"SD පත ඉවත් කර ඇත"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB ආචයනය ඉවත්කොට ඇත. අලුත් මාධ්‍යයක් ඇතුළත් කරන්න."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD පත ඉවත් කරන ලදි. අලුත් එකක් ඇතුළත් කරන්න."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"ගැලපෙන ක්‍රියාකාරකම් හමු නොවුණි."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"සංරචකය භාවිත කිරීමේ සංඛ්‍යාන යාවත්කාලීන කරන්න"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"එකතු කරන ලද සංරචකය භාවිතා සංඛ්‍යාන වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා නොවේ."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"අන්තර්ගතය පිටපත් කරන්න"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"අන්තර්ගතය පිටපත් කිරීමට සුපුරුදු අන්තර්ගත සේවාව ඉල්වා සිටීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"මාධ්‍ය ප්‍රතිදානයේ මාර්ගගත කිරීම"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"වෙනත් බාහිර උපාංග වෙත මාධ්‍ය ප්‍රතිදානය යැවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"යතුරු පාලක ආරක්‍ෂිත ආචයනය වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"යතුරු ආරක්ෂක ආචයනයට ප්‍රවේශ වීමට යෙදුමට දෙයි."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"පෙන්වීමේ හා සැඟවීමේ යතුරු ආරක්ෂකය පාලනය කරන්න"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"යතුරු ආරක්ෂකය පාලනයට යෙදුමකට අවසර දෙන්න."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"විශාලන පාලනය සඳහා දෙවරක් ස්පර්ශ කරන්න"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"විජටය එකතු කිරීමට නොහැකි විය."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"යන්න"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"සෙවීම"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"යවන්න"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"මීලඟ"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"හරි"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"පෙර"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"ක්‍රියාකරවන්න"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"<xliff:g id="NUMBER">%s</xliff:g> භාවිතයෙන්\nඅංකය අමතන්න"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"<xliff:g id="NUMBER">%s</xliff:g> භාවිතයෙන්\nසම්බන්ධතාවයක් නිර්මාණය කරන්න"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"පහත දැක්වෙන එකක් හෝ ඊට වැඩි යෙදුම් ගණනක් ඔබගේ ගිණුමට ප්‍රවේශ වීමට, දැන් සහ ඉදිරියේදී අවසර ඉල්ලයි."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"මෙම ඉල්ලීමට අවසර දීමට ඔබට අවශ්‍යද?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"ප්‍රවේශය ඉල්ලීම"</string>
-    <string name="allow" msgid="7225948811296386551">"අවසර දෙන්න"</string>
-    <string name="deny" msgid="2081879885755434506">"ප්‍රතික්ෂේප කරන්න"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"අවසර ඉල්ලා සිටී"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"<xliff:g id="ACCOUNT">%s</xliff:g> ගිණුම සඳහා\nඅවසර ඉල්ලන ලදි."</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"ආදාන ක්‍රමය"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"සමමුහුර්තය"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"ප්‍රවේශ්‍යතාව"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"බිතුපත"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"බිතුපත වෙනස් කරන්න"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"දැනුම්දීම් අසන්නා"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN ක්‍රියාත්මකයි"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"<xliff:g id="APP">%s</xliff:g> මඟින් VPN සක්‍රීය කරන ලදි"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"ජාලය කළමනාකරණය කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g> වෙත සම්බන්ධ වුණි. ජාලය කළමනාකරණය කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"සැමවිටම VPN සම්බන්ධ වෙමින්…"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"නිරතුරුවම VPN සම්බන්ධ කර ඇත"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"සැමවිට සක්‍රිය VPN දෝෂය"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"වින්‍යාස කිරීමට ස්පර්ශ කරන්න"</string>
-    <string name="upload_file" msgid="2897957172366730416">"ගොනුව තෝරන්න"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"ගොනුවක් තෝරාගෙන නැත"</string>
-    <string name="reset" msgid="2448168080964209908">"යළි පිහිටුවන්න"</string>
-    <string name="submit" msgid="1602335572089911941">"යොමු කරන්න"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"මෝටර් රථ ආකාරය සබල කර ඇත"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"මෝටර් රථ ආකාරයෙන් පිටවීමට ස්පර්ශ කරන්න."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"ටෙදරින් හෝ හොට්ස්පොට් සක්‍රීයයි"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"සකස් කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="back_button_label" msgid="2300470004503343439">"ආපසු"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"මීලඟ"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"මඟ හරින්න"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"ඉහළ ජංගම දත්ත භාවිතය"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"ජංගම දත්ත භාවිතය ගැන තව දැනගැනීමට ස්පර්ශ කරන්න."</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"ජංගම දත්ත සීමාව ඉක්මවා ඇත"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"ජංගම දත්ත භාවිතය ගැන තව දැනගැනීමට ස්පර්ශ කරන්න."</string>
-    <string name="no_matches" msgid="8129421908915840737">"ගැලපීම් නැත"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"පිටුවෙහි සෙවීම"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"ගැළපීම් 1 යි"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="TOTAL">%d</xliff:g> කින් <xliff:g id="INDEX">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"හරි"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB ආචයනය ගැලවීම..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD පත ගලවමින්..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB ආචයනය මකමින්..."</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD පත මකමින්..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB ආචයනය මැකිය නොහැක."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD පත මැකීමට නොහැකි විය."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"ගැලවීමට පෙර SD පත ඉවත්කර ඇත."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB ආචයනය මේ වනවිට පරීක්ෂා කරමින් පවතී."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD පත දැන් පරීක්ෂා කරමින් පවතී."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD පත ඉවත් කර ඇත."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"පරිගණකයක් විසින් දැන් USB ආචයනය භාවිතා කරයි."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD පත දැනට පරිගණකයකින් පාවිච්චි කරයි."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"බාහිර මාධ්‍යය නොදන්නා අවස්ථාවේ පවතියි."</string>
-    <string name="share" msgid="1778686618230011964">"බෙදාගන්න"</string>
-    <string name="find" msgid="4808270900322985960">"සොයන්න"</string>
-    <string name="websearch" msgid="4337157977400211589">"වෙබ් සෙවුම"</string>
-    <string name="find_next" msgid="5742124618942193978">"මීළඟ සොයන්න"</string>
-    <string name="find_previous" msgid="2196723669388360506">"පෙර එක සොයන්න"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> ගෙන් ස්ථානය ඉල්ලීම"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"ස්ථාන ඉල්ලීම"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) විසින් ඉල්ලන ලද"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"ඔව්"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"නැත"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"මැකීමේ සීමාව ඉක්මවන ලදි"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g> සඳහා <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g> ගිණුමේ මකන ලද අයිතම <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> ක් ඇත. ඔබට කුමක් කිරීමට අවශ්‍යද?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"අයිතම මකන්න"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"මැකීම් අස් කරන්න"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"දැනට කිසිවක් නොකරන්න"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"ගිණුමක් තෝරන්න"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"ගිණුමක් එකතු කරන්න"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"ගිණුමක් එකතු කරන්න"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"වැඩි කරන්න"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"අඩු කරන්න"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> ස්පර්ශ කර රඳවා සිටින්න."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"වැඩි කිරීමට ඉහලට සර්පණය කරන්න සහ අඩු කිරීමට පහලට සර්පණය කරන්න."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"මිනිත්තුවක් වැඩි කරන්න"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"මිනිත්තුව අඩු කරන්න"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"පැය වැඩිකරන්න"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"පැය අඩුකරන්න"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"ප.ව.සකසන්න"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"පෙ.ව. සකස් කිරීම"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"මාසය වැඩි කරන්න"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"මාසයක් අඩු කරන්න"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"දවස වැඩි කරන්න"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"දවස අඩු කරන්න"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"වසර වැඩි කරන්න"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"වසර අඩු කරන්න"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"අවලංගු කරන්න"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"මකන්න"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"හරි"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"ආකාරය වෙනස් කරන්න"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"ඇතුල් කරන්න"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"යෙදුමක් තෝරන්න"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"සමඟ බෙදාගන්න"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g> සමඟින් බෙදා ගන්න"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"සර්පණ හැඩලය. ස්පර්ශ කර රඳවා සිටීම."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා උඩට සර්පණය කරන්න."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා පහලට සර්පණය කරන්න."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා වමට සර්පණය කරන්න."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා දකුණට සර්පණය කරන්න."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"අඟුල අරින්න"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"කැමරාව"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"නිහඬ"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"ශබ්ද සක්‍රීය කරන්න"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"සෙවීම"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"අගුළු ඇරීමට ස්වයිප් කරන්න."</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"මුරපද යතුරු කියවනු ඇසීමට ඉස් බණුවක් සම්බන්ධ කරන්න."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"නැවතුම."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"මුල් පිටුවට සංචාලනය කරන්න"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"ඉහලට සංචාලනය කරන්න"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"තවත් විකල්ප"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"අභ්‍යන්තර ආචයනය"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD පත"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB ආචයනය"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"සංස්කරණය කරන්න"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"දත්ත භාවිතා අවවාදය"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"භාවිතය සහ සැකසීම් බැලීමට ස්පර්ශ කරන්න."</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G දත්ත අබලයි"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G දත්ත අබල කරන ලදි"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"ජංගම දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi-Fi දත්ත අබල කරන ලදි"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"සබල කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G දත්ත සීමාව ඉක්මවන ලදි"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G දත්ත සීමාව ඉක්මවා යන ලදි"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"ජංගම දත්ත සීමාව ඉක්මවා යන ලදි"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi-Fi දත්ත සීමාව ඉක්මවා යන ලදි"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"සඳහන් කළ සීමාවට වඩා <xliff:g id="SIZE">%s</xliff:g> වැඩිය."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"පසුබිම් දත්ත සිමා කරන ලදි"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"සීමා කිරීම ඉවත් කිරීමට ස්පර්ශ කරන්න"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"ආරක්‍ෂිත සහතිකය"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"මෙම සහතිකය වලංගුයි."</string>
-    <string name="issued_to" msgid="454239480274921032">"ලබාදුන්නේ:"</string>
-    <string name="common_name" msgid="2233209299434172646">"පොදු නාමය:"</string>
-    <string name="org_name" msgid="6973561190762085236">"සංවිධානය:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"සංවිධානාත්මක ඒකකය:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"ලබාදෙන ලද්දේ:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"වලංගුතාවය:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"නිකුත් කරන ලද්දේ:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"කල් ඉකුත් වන්නේ:"</string>
-    <string name="serial_number" msgid="758814067660862493">"අනුක්‍රමාංකය:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"ඇඟිලි සලකුණු:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 ඇඟිලිසලකුණ:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 ඇඟිලි සලකුණ:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"සියල්ල බලන්න"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"ක්‍රියාකාරකම තෝරන්න"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"සමඟ බෙදාගන්න"</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"යවමින්..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"බ්‍රවුසරය දියත් කරන්නද?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"ඇමතුම පිළිගන්නවාද?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"සැම විටම"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"එක් වාරයයි"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"ටැබ්ලට්ය"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"දුරකථනය"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"ඉස් බණු"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"නාදක ඩොක් කරන්න"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"පද්ධතිය"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"බ්ලූටූත් ශ්‍රව්‍ය"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"රැහැන් රහිත දර්ශනය"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"හරි"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"මාධ්‍ය ප්‍රතිදානය"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"පරිලෝකනය කරමින්…"</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"සම්බන්ධ වෙමින්…"</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"ලබාගත හැක"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"ලබාගත නොහැක"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"භාවිතයේ ඇත"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"තිළැලි තිරය"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI තිරය"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"උඩැතිරිය #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", ආරක්‍ෂිත"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"නොරැහැන් සංදර්ශකය සම්බන්ධිතයි"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"වෙනත් උපාංගයක් මත මෙම තිරය පෙන්වයි"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"විසන්ධි කරන්න"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"හදිසි ඇමතුම"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"රටාව අමතකයි"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"වැරදි රටාවකි"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"වැරදි මුරපදය"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN එක වැරදියි"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"තත්පර <xliff:g id="NUMBER">%1$d</xliff:g> ට පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"ඔබගේ රටාව අඳින්න"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN ඇතුලු කරන්න"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN එක ඇතුළු කරන්න"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"මුරපදය ඇතුළු කරන්න"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"දැන් SIM එක අබල කර ඇත. ඉදිරියට යාමට PUK කේතය යොදන්න. විස්තර සඳහා වාහකයා අමතන්න."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"අපේක්ෂිත PIN කේතය ඇතුළත් කරන්න"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"අපේක්ෂිත PIN කේතය ස්ථිර කරන්න"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM පත අගුළු අරිමින්..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"වැරදි PIN කේතයකි."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"අංක 4 සිට 8 අතර වන PIN එකක් ටයිප් කරන්න."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK කේතය සංඛ්‍යා 8 ක් හෝ වැඩි විය යුතුය."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"නිවැරදි PUK කේතය නැවත ඇතුලත් කරන්න. නැවත නැවත උත්සාහ කිරීමෙන් SIM එක ස්ථිරවම අබල කරයි."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN කේත ගැලපී නැත"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"රටා උත්සාහ කිරීම් වැඩිය"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"අගුළු ඇරීමට, ඔබගේ Google ගිණුම සමග පුරනය වන්න."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"පරිශීලක නාමය (ඊ-තැපෑල)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"මුරපදය"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"පුරනය වන්න"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"වලංගු නොවන පරිශීලක නාමයක් හෝ මුරපදයක්."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"ඔබගේ පරිශීලක නාමය හෝ මුරපදය අමතකද?\n "<b>"google.com/accounts/recovery"</b>" වෙත යන්න."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"ගිණුම පරීක්ෂා කරමින්…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"ඔබ PIN අංකය <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් වැරදියට ටයිප් කොට ඇත.\n\n තත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"<xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ මුරපදය ඔබ වැරදියට ටයිප් කර ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ට පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"ඔබ <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් අගුළු ඇරීමේ රටාව වැරදියට ඇඳ ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"ඔබ ටැබ්ලටය අගුළු හැරීමට වැරදියට අවස්ථා <xliff:g id="NUMBER_0">%d</xliff:g> ක් උත්සාහ කර ඇත. අවස්ථා <xliff:g id="NUMBER_1">%d</xliff:g> ක් අසාර්ථකව උත්සහ කිරීමකින් පසුව, කර්මාන්ත ශාලා මුල් තත්වයට නැවත පත් වන අතර සියලු පරිශීලක දත්ත නැති වෙයි."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER_0">%d</xliff:g> කදී වැරදී ප්‍රයත්නයන් ගෙන තිබේ. තවත් අසාර්ථක ප්‍රයත්න <xliff:g id="NUMBER_1">%d</xliff:g> කින් පසුව, දුරකථනය කර්මාන්ත ශාලාවේ සුපුරුද්දට යළි පිහිටුවන අතර සියලුම පරිශීලක දත්ත නැති වී යයි."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"ටැබ්ලටයේ අගුළු ඇරීමට ඔබ වැරදි ප්‍රයත්න <xliff:g id="NUMBER">%d</xliff:g> වාරයක් ගෙන ඇත. දැන් ටැබ්ලටය කර්මාන්ත ශාලා සුපුරුද්ද වෙත යළි පිහිටුවීම කෙරේ."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER">%d</xliff:g> කදී වැරදී ප්‍රයන්තයන් ගෙන තිබේ. දැන් දුරකථනය කර්මාන්තශාලා සුපුරුද්දට පිහිටුවනු ලබයි."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"ඔබ අගුළු ඇරිමේ රටාව <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් වැරදියට ඇඳ ඇත. තවත් අසාර්ථක උත්සාහ <xliff:g id="NUMBER_1">%d</xliff:g> කින් පසුව, ඊ-තැපැල් ගිණුම භාවිතා කරමින් ඔබගේ ටැබ්ලටයේ අගුළු ඇරීමට ඔබට පවසනු ඇත.\n\n නැවත තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> කින් උත්සාහ කරන්න."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"ඔබ වැරදියට <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ අගුළු හැරීමේ රටාව ඇඳ ඇත. අසාර්ථක උත්සහ කිරීම් <xliff:g id="NUMBER_1">%d</xliff:g> න් පසුව, ඔබගේ ඊ-තැපැල් ලිපිනය භාවිතයෙන් ඔබගේ දුරකථනය අගුළු හැරීමට ඔබගෙන් අසයි.\n\n තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> න් පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"ඉවත් කරන්න"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"නිර්දේශිත මට්ටමෙන් ඉහළට ශබ්දය වැඩි කරනවද?\nවැඩි කාලයක් ඉහළ ශබ්දයක් ශ්‍රවනය කිරීමෙන් ඔබගේ ශ්‍රවනයට හානි විය හැක."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"ප්‍රවේශ්‍යතාවය සබල කිරීමට ඇඟිලි දෙකක් පහළට රඳවා සිටින්න."</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"ප‍්‍රවේශ්‍යතාව සබල කරන ලදි."</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"ප‍්‍රවේශ්‍යතාව අවලංගු කර ඇත."</string>
-    <string name="user_switched" msgid="3768006783166984410">"දැනට සිටින පරිශීලකයා <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="owner_name" msgid="2716755460376028154">"හිමිකරු"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"දෝෂය"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"සීමා සහිත පැතිකඩ සඳහා වන ගිණුම් වෙත මෙම යෙදුම සහය නොදක්වයි"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"මෙම ක්‍රියාව හසුරුවීමට යෙදුමක් සොයාගත්තේ නැත"</string>
-    <string name="revoke" msgid="5404479185228271586">"අහෝසි කරන්න"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"අකුරු"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"රජයේ ලිපිය"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"නීත්‍යනුකූල"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"ප්‍රාථමික නීතිමය"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"ලෙජරය"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"කුඩා පුවත්පත"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"අවලංගු කරන ලදි"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"අන්තර්ගතය ලිවීමේදී දෝෂයකි"</string>
-    <string name="reason_unknown" msgid="6048913880184628119">"නොදනී"</string>
-    <string name="restr_pin_enter_admin_pin" msgid="783643731895143970">"පරිපාලකයාගේ PIN එක ඇතුළ් කරන්න"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN එක ඇතුළු කරන්න"</string>
-    <string name="restr_pin_incorrect" msgid="8571512003955077924">"වැරදියි"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"වත්මන් PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"නව PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"නව PIN තහවුරු කරන්න"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"සිමා වැඩිදියුණු කිරීමට PIN සාදන්න"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN නොගැළපෙයි. නැවත උත්සහ කරන්න."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN කුඩා වැඩිය. ඉලක්කම් 4 වත් විය යුතුය."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="311050995198548675">"තවත් තත්පර 1 කින් යළි උත්සාහ කරන්න"</item>
-    <item quantity="other" msgid="4730868920742952817">"තත්පර <xliff:g id="COUNT">%d</xliff:g> කින් නැවත උත්සහ කරන්න"</item>
-  </plurals>
-    <string name="restr_pin_try_later" msgid="973144472490532377">"පසුව නැවත උත්සාහ කරන්න"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"තීරුව අනාවරණයට තිරයේ කෙලවර අදින්න"</string>
-</resources>
diff --git a/core/res/res/values-si/strings.xml b/core/res/res/values-si/strings.xml
deleted file mode 100644
index 7e12eab..0000000
--- a/core/res/res/values-si/strings.xml
+++ /dev/null
@@ -1,1590 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="byteShort" msgid="8340973892742019101">"B"</string>
-    <string name="kilobyteShort" msgid="5973789783504771878">"KB"</string>
-    <string name="megabyteShort" msgid="6355851576770428922">"MB"</string>
-    <string name="gigabyteShort" msgid="3259882455212193214">"GB"</string>
-    <string name="terabyteShort" msgid="231613018159186962">"TB"</string>
-    <string name="petabyteShort" msgid="5637816680144990219">"PB"</string>
-    <string name="fileSizeSuffix" msgid="9164292791500531949">"<xliff:g id="NUMBER">%1$s</xliff:g><xliff:g id="UNIT">%2$s</xliff:g>"</string>
-    <string name="untitled" msgid="4638956954852782576">"&lt;නම් යොදා නැත&gt;"</string>
-    <string name="ellipsis" msgid="7899829516048813237">"…"</string>
-    <string name="ellipsis_two_dots" msgid="1228078994866030736">"‥"</string>
-    <string name="emptyPhoneNumber" msgid="7694063042079676517">"(දුරකථන අංකයක් නොමැත)"</string>
-    <string name="unknownName" msgid="2277556546742746522">"(නොදනී)"</string>
-    <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"කටහඬ තැපෑල"</string>
-    <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
-    <string name="mmiError" msgid="5154499457739052907">"සම්බන්ධතා ගැටළුවක් හෝ අවලංගු MMI කේතයකි."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"ස්ථාවර ඇමතීම් අංක වලට පමණක් මෙහෙයුම සීමාකර ඇත."</string>
-    <string name="serviceEnabled" msgid="8147278346414714315">"සේවාව සබල කරන ලදි."</string>
-    <string name="serviceEnabledFor" msgid="6856228140453471041">"සේවාව සබලයි, සඳහා:"</string>
-    <string name="serviceDisabled" msgid="1937553226592516411">"සේවාව අබල කරන ලදි."</string>
-    <string name="serviceRegistered" msgid="6275019082598102493">"ලියාපදිංචි වීම සාර්ථකයි."</string>
-    <string name="serviceErased" msgid="1288584695297200972">"මැකීම සාර්ථක විය."</string>
-    <string name="passwordIncorrect" msgid="7612208839450128715">"වැරදි මුරපදයක්."</string>
-    <string name="mmiComplete" msgid="8232527495411698359">"MMI සම්පූර්ණයි."</string>
-    <string name="badPin" msgid="9015277645546710014">"ඔබ ටයිප් කරන ලද පරණ PIN එක වැරදිය."</string>
-    <string name="badPuk" msgid="5487257647081132201">"ඔබ ටයිප් කරන ලද PUK එක වැරදියි."</string>
-    <string name="mismatchPin" msgid="609379054496863419">"ඔබ ටයිප් කල PIN නොගැළපේ."</string>
-    <string name="invalidPin" msgid="3850018445187475377">"4 සිට 8 දක්වා අංක සහිත PIN එකක් ටයිප් කරන්න."</string>
-    <string name="invalidPuk" msgid="8761456210898036513">"අංක 8 ක් හෝ ඊට වැඩි PUK එකක් ටයිප් කරන්න."</string>
-    <string name="needPuk" msgid="919668385956251611">"ඔබගේ SIM පත පතට PUK අගුළු වැටී ඇත. එම අගුල ඇරීමට PUK කේතය ටයිප් කරන්න."</string>
-    <string name="needPuk2" msgid="4526033371987193070">"SIM පතේ අගුළු ඇරීමට PUK2 ටයිප් කරන්න."</string>
-    <string name="imei" msgid="2625429890869005782">"IMEI"</string>
-    <string name="meid" msgid="4841221237681254195">"MEID"</string>
-    <string name="ClipMmi" msgid="6952821216480289285">"පැමිණෙන අමතන්නාගේ ID"</string>
-    <string name="ClirMmi" msgid="7784673673446833091">"පිටතට යන අමතන්නාගේ ID"</string>
-    <string name="CfMmi" msgid="5123218989141573515">"ඇමතුම ඉදිරියට යැවීම"</string>
-    <string name="CwMmi" msgid="9129678056795016867">"ඇමතුම් රැඳීම"</string>
-    <string name="BaMmi" msgid="455193067926770581">"ඇමතුම අවහිර කිරීම"</string>
-    <string name="PwdMmi" msgid="7043715687905254199">"මුරපදය වෙනස් කිරීම"</string>
-    <string name="PinMmi" msgid="3113117780361190304">"PIN වෙනස් වී ඇත"</string>
-    <string name="CnipMmi" msgid="3110534680557857162">"ඇමතුම් අංකය ඇත"</string>
-    <string name="CnirMmi" msgid="3062102121430548731">"ඇමතුම් අංකය සීමා කර ඇත"</string>
-    <string name="ThreeWCMmi" msgid="9051047170321190368">"තුන් මාර්ග ඇමතීම"</string>
-    <string name="RuacMmi" msgid="7827887459138308886">"අනවශ්‍ය හිරිහැරදායක ඇමතුම් ප්‍රතික්ෂේප කිරීම"</string>
-    <string name="CndMmi" msgid="3116446237081575808">"ඇමතීමේ අංකය භාරදීම"</string>
-    <string name="DndMmi" msgid="1265478932418334331">"බාධා නොකරන්න"</string>
-    <string name="CLIRDefaultOnNextCallOn" msgid="429415409145781923">"අමතන්නාගේ ID සුපුරුද්ද අනුව සීමා වී ඇත. මීළඟ ඇමතුම: සීමා කර ඇත"</string>
-    <string name="CLIRDefaultOnNextCallOff" msgid="3092918006077864624">"අමතන්නාගේ ID සුපුරුදු අනුව සීමා වී ඇත. මීළඟ ඇමතුම: සීමා කර නැත"</string>
-    <string name="CLIRDefaultOffNextCallOn" msgid="6179425182856418465">"අමතන්නාගේ ID සුපුරුදු අනුව සීමා වී නැත. මීළඟ ඇමතුම: සීමා කර ඇත"</string>
-    <string name="CLIRDefaultOffNextCallOff" msgid="2567998633124408552">"අමතන්නාගේ ID සුපුරුදු අනුව සීමා වී නැත. මීළඟ ඇමතුම: සීමා කර ඇත"</string>
-    <string name="serviceNotProvisioned" msgid="8614830180508686666">"සේවාවන් සපයා නැත."</string>
-    <string name="CLIRPermanent" msgid="3377371145926835671">"අමතන්නාගේ ID සැකසීම ඔබට වෙනස්කල නොහැක."</string>
-    <string name="RestrictedChangedTitle" msgid="5592189398956187498">"සීමිත ප්‍රවේශය වෙනස් කෙරිණි"</string>
-    <string name="RestrictedOnData" msgid="8653794784690065540">"දත්ත සේවාව අවහිර කර ඇත."</string>
-    <string name="RestrictedOnEmergency" msgid="6581163779072833665">"හදිසි සේවාව අවහිර කර ඇත."</string>
-    <string name="RestrictedOnNormal" msgid="4953867011389750673">"හඬ සේවාව බාධා කර ඇත."</string>
-    <string name="RestrictedOnAllVoice" msgid="3396963652108151260">"සියලු හඬ සේවා අවහිර කර ඇත."</string>
-    <string name="RestrictedOnSms" msgid="8314352327461638897">"SMS සේවාව අවහිර කර ඇත."</string>
-    <string name="RestrictedOnVoiceData" msgid="996636487106171320">"හඬ/දත්ත සේවා අවහිර කර ඇත."</string>
-    <string name="RestrictedOnVoiceSms" msgid="1888588152792023873">"හඬ/SMS සේවා අවහිර කර ඇත."</string>
-    <string name="RestrictedOnAll" msgid="5643028264466092821">"සියලුම හඬ/දත්ත/SMS සේවාවන් බාධා කර ඇත."</string>
-    <string name="serviceClassVoice" msgid="1258393812335258019">"හඬ"</string>
-    <string name="serviceClassData" msgid="872456782077937893">"දත්ත"</string>
-    <string name="serviceClassFAX" msgid="5566624998840486475">"ෆැක්ස්"</string>
-    <string name="serviceClassSMS" msgid="2015460373701527489">"SMS"</string>
-    <string name="serviceClassDataAsync" msgid="4523454783498551468">"අසමමුහුර්ත කරන්න"</string>
-    <string name="serviceClassDataSync" msgid="7530000519646054776">"සමමුහුර්ත කිරීම"</string>
-    <string name="serviceClassPacket" msgid="6991006557993423453">"පැකැට්ටුව"</string>
-    <string name="serviceClassPAD" msgid="3235259085648271037">"PAD"</string>
-    <string name="roamingText0" msgid="7170335472198694945">"රෝමිං දර්ශකය සක්‍රියයි"</string>
-    <string name="roamingText1" msgid="5314861519752538922">"රෝමිං දර්ශකය අක්‍රියයි"</string>
-    <string name="roamingText2" msgid="8969929049081268115">"රෝමිං දර්ශකය සැණෙලි වෙයි"</string>
-    <string name="roamingText3" msgid="5148255027043943317">"වටපිටාවෙන් ඉවත්ව"</string>
-    <string name="roamingText4" msgid="8808456682550796530">"ගොඩනැගිල්ලෙන් පිටත"</string>
-    <string name="roamingText5" msgid="7604063252850354350">"රෝමිං  - කැමති පද්ධතිය"</string>
-    <string name="roamingText6" msgid="2059440825782871513">"රෝමිං  - ලබාගත හැකි පද්ධතිය"</string>
-    <string name="roamingText7" msgid="7112078724097233605">"රෝමිං - මිත්‍ර හවුල්කරු"</string>
-    <string name="roamingText8" msgid="5989569778604089291">"රෝමිං - අධිමිල හවුල්කරු"</string>
-    <string name="roamingText9" msgid="7969296811355152491">"රෝමිං  - සම්පූර්ණ සේවා ක්‍රියාකාරිත්වය"</string>
-    <string name="roamingText10" msgid="3992906999815316417">"රෝමිං - අසම්පූර්ණ සේවා ක්‍රියාකාරීත්වය"</string>
-    <string name="roamingText11" msgid="4154476854426920970">"රෝමිං  බැනරය සක්‍රීයයි"</string>
-    <string name="roamingText12" msgid="1189071119992726320">"රෝමිං බැනරය අක්‍රියයි"</string>
-    <string name="roamingTextSearching" msgid="8360141885972279963">"සේවාව සඳහා සොයමින්"</string>
-    <string name="cfTemplateNotForwarded" msgid="1683685883841272560">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ඉදිරියට නොයවන ලදි"</string>
-    <string name="cfTemplateForwarded" msgid="1302922117498590521">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateForwardedTime" msgid="9206251736527085256">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: තත්පර <xliff:g id="TIME_DELAY">{2}</xliff:g> ට පසුව <xliff:g id="DIALING_NUMBER">{1}</xliff:g>"</string>
-    <string name="cfTemplateRegistered" msgid="5073237827620166285">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ඉදිරියට නොයවන ලදි"</string>
-    <string name="cfTemplateRegisteredTime" msgid="6781621964320635172">"<xliff:g id="BEARER_SERVICE_CODE">{0}</xliff:g>: ඉදිරියට නොයවන ලදි"</string>
-    <string name="fcComplete" msgid="3118848230966886575">"අංග කේතය සම්පූර්ණයි."</string>
-    <string name="fcError" msgid="3327560126588500777">"සම්බන්ධතා ගැටළුවක් හෝ අවලංගු විශේෂාංග කේතයකි."</string>
-    <string name="httpErrorOk" msgid="1191919378083472204">"හරි"</string>
-    <string name="httpError" msgid="7956392511146698522">"ජාල දෝෂයක් තිබුණි."</string>
-    <string name="httpErrorLookup" msgid="4711687456111963163">"URL ය සෙවිය නොහැක."</string>
-    <string name="httpErrorUnsupportedAuthScheme" msgid="6299980280442076799">"අඩවියේ සත්‍යාපන පටිපාටිය වෙත සහය නොදක්වයි."</string>
-    <string name="httpErrorAuth" msgid="1435065629438044534">"සත්‍යාපනය කළ නොහැක"</string>
-    <string name="httpErrorProxyAuth" msgid="1788207010559081331">"ප්‍රොක්සි සේවාදායකය හරහා සත්‍යාපනය අසාර්ථකය."</string>
-    <string name="httpErrorConnect" msgid="8714273236364640549">"සේවාදායකයාට සම්බන්ධ විය නොහැක."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"සේවාදායකයා සමග සම්බන්ධ වීමට නොහැකි විය. නැවත උත්සහ කරන්න."</string>
-    <string name="httpErrorTimeout" msgid="4743403703762883954">"සේවාදායකය වෙත සම්බන්ධතාවය කල් ඉකුත් විණි."</string>
-    <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"පිටුවේ බොහෝ සේවාදායක නැවත හරවා යැවීම් අඩංගු වේ."</string>
-    <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"ප්‍රොටෝකෝලය වෙත සහය නොදක්වයි."</string>
-    <string name="httpErrorFailedSslHandshake" msgid="96549606000658641">"සුරක්ෂිත සම්බන්ධතාවයක් පිහිටුවීමට නොහැකි විය."</string>
-    <string name="httpErrorBadUrl" msgid="3636929722728881972">"URL වලංගු නොවන නිසා පිටුව විවෘත කිරීමට නොහැකි විය."</string>
-    <string name="httpErrorFile" msgid="2170788515052558676">"ගොනුව වෙත පිවිසිය නොහැක."</string>
-    <string name="httpErrorFileNotFound" msgid="6203856612042655084">"ඉල්ලන ලද ගොනු සෙවිය නොහැක."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"ඉල්ලීම් විශාල ප්‍රමාණයක් ක්‍රියාත්මක වෙමින් පවතියි. පසුව නැවත උත්සාහ කරන්න."</string>
-    <string name="notification_title" msgid="8967710025036163822">"<xliff:g id="ACCOUNT">%1$s</xliff:g> සඳහා පුරනය වීමේ දෝෂයක්"</string>
-    <string name="contentServiceSync" msgid="8353523060269335667">"සමමුහුර්ත කිරීම"</string>
-    <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"සමමුහුර්ත කරන්න"</string>
-    <string name="contentServiceTooManyDeletesNotificationDesc" msgid="8100981435080696431">"<xliff:g id="CONTENT_TYPE">%s</xliff:g> මැකීම් වැඩිය"</string>
-    <string name="low_memory" product="tablet" msgid="6494019234102154896">"ටැබ්ලට් ආචයනය පිරි ඇත. ඉඩ නිදහස් කිරීමට සමහර ගොනු මකන්න."</string>
-    <string name="low_memory" product="default" msgid="3475999286680000541">"දුරකථන ආචයනය පිරී ඇත. ඉඩ නිදහස් කිරීමට සමහර ගොනු මකන්න."</string>
-    <string name="me" msgid="6545696007631404292">"මම"</string>
-    <string name="power_dialog" product="tablet" msgid="8545351420865202853">"ටැබ්ලට විකල්ප"</string>
-    <string name="power_dialog" product="default" msgid="1319919075463988638">"දුරකථන විකල්පයන්"</string>
-    <string name="silent_mode" msgid="7167703389802618663">"නිහඬ ආකාරය"</string>
-    <string name="turn_on_radio" msgid="3912793092339962371">"නොරැහන් සක්‍රිය කරන්න"</string>
-    <string name="turn_off_radio" msgid="8198784949987062346">"නොරැහැන් අක්‍රිය කරන්න"</string>
-    <string name="screen_lock" msgid="799094655496098153">"තිර අගුල"</string>
-    <string name="power_off" msgid="4266614107412865048">"බලය අක්‍රිය කරන්න"</string>
-    <string name="silent_mode_silent" msgid="319298163018473078">"හඬ නඟනය අක්‍රියයි"</string>
-    <string name="silent_mode_vibrate" msgid="7072043388581551395">"හඬ නඟනය කම්පනය"</string>
-    <string name="silent_mode_ring" msgid="8592241816194074353">"හඬ නඟනය සක්‍රීයයි"</string>
-    <string name="shutdown_progress" msgid="2281079257329981203">"වසා දමමින්…"</string>
-    <string name="shutdown_confirm" product="tablet" msgid="3385745179555731470">"ඔබගේ ටැබ්ලටය වැසේ."</string>
-    <string name="shutdown_confirm" product="default" msgid="649792175242821353">"ඔබගේ දුරකථනය වැසේ."</string>
-    <string name="shutdown_confirm_question" msgid="2906544768881136183">"ඔබට වසා දැමීමට අවශ්‍යද?"</string>
-    <string name="reboot_safemode_title" msgid="7054509914500140361">"ආරක්‍ෂිත ආකාරයට නැවත පණ ගන්වන්න"</string>
-    <string name="reboot_safemode_confirm" msgid="55293944502784668">"ආරක්‍ෂිත ආකාරයට නැවත පණ ගැන්වීමට ඔබට අවශ්‍යද? මෙමඟින් ඔබ ස්ථාපිත කර ඇති සියලුම තෙවන පාර්ශවීය යෙදුම් සියල්ල අබල වී යයි. ඔබ නැවත පණ ගන්වන විට ඒවා නැවත පිහිටුවීම සිදු වේ."</string>
-    <string name="recent_tasks_title" msgid="3691764623638127888">"මෑත"</string>
-    <string name="no_recent_tasks" msgid="8794906658732193473">"මෑත යෙදුම් නැත."</string>
-    <string name="global_actions" product="tablet" msgid="408477140088053665">"ටැබ්ලට් විකල්ප"</string>
-    <string name="global_actions" product="default" msgid="2406416831541615258">"දුරකථන විකල්ප"</string>
-    <string name="global_action_lock" msgid="2844945191792119712">"තිර අගුල"</string>
-    <string name="global_action_power_off" msgid="4471879440839879722">"බලය අක්‍රිය කරන්න"</string>
-    <string name="global_action_bug_report" msgid="7934010578922304799">"දෝෂ වර්තාව"</string>
-    <string name="bugreport_title" msgid="2667494803742548533">"දෝෂ වාර්තාවක් ගන්න"</string>
-    <string name="bugreport_message" msgid="398447048750350456">"ඊ-තැපැල් පණිවිඩයක් ලෙස යැවීමට මෙය ඔබගේ වත්මන් උපාංග තත්වය ගැන තොරතුරු එකතු කරනු ඇත. දෝෂ වාර්තාව ආරම්භ කර එය යැවීමට සූදානම් කරන තෙක් එයට කිසියම් කාලයක් ගතවනු ඇත; කරුණාකර ඉවසන්න."</string>
-    <string name="global_action_toggle_silent_mode" msgid="8219525344246810925">"නිහඬ ආකාරය"</string>
-    <string name="global_action_silent_mode_on_status" msgid="3289841937003758806">"ශබ්දය අක්‍රියයි"</string>
-    <string name="global_action_silent_mode_off_status" msgid="1506046579177066419">"හඬ සක්‍රියයි"</string>
-    <string name="global_actions_toggle_airplane_mode" msgid="5884330306926307456">"අහස්යානා ආකාරය"</string>
-    <string name="global_actions_airplane_mode_on_status" msgid="2719557982608919750">"අහස්යානා ආකාරය සක්‍රීයයි."</string>
-    <string name="global_actions_airplane_mode_off_status" msgid="5075070442854490296">"අහස්යානා අකාරය අක්‍රියයි"</string>
-    <string name="status_bar_notification_info_overflow" msgid="5301981741705354993">"999+"</string>
-    <string name="safeMode" msgid="2788228061547930246">"ආරක්‍ෂිත ආකාරය"</string>
-    <string name="android_system_label" msgid="6577375335728551336">"Android පද්ධතිය"</string>
-    <string name="permgrouplab_costMoney" msgid="5429808217861460401">"ඔබගේ මුදල් වැයවන සේවාවන්"</string>
-    <string name="permgroupdesc_costMoney" msgid="3293301903409869495">"ඔබගෙන් මුදල් යන දේවල් කරන්න."</string>
-    <string name="permgrouplab_messages" msgid="7521249148445456662">"ඔබගේ පණිවිඩ"</string>
-    <string name="permgroupdesc_messages" msgid="7821999071003699236">"ඔබගේ SMS, ඊ-තැපැල්, සහ වෙනත් පණිවිඩ කියවන්න සහ ලියන්න."</string>
-    <string name="permgrouplab_personalInfo" msgid="3519163141070533474">"ඔබගේ පෞද්ගලික තොරතුරු"</string>
-    <string name="permgroupdesc_personalInfo" msgid="8426453129788861338">"ඔබගේ සම්බන්ධතා පතේ ආචයනය කරන ලද, ඔබ ගැන තොරතුරු වලට ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_socialInfo" msgid="5799096623412043791">"ඔබගේ සමාජයීය තොරතුරු"</string>
-    <string name="permgroupdesc_socialInfo" msgid="7129842457611643493">"ඔබගේ සම්බන්ධතා සහ සාමාජ සම්බන්ධයන් ගැන තොරතුරු වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_location" msgid="635149742436692049">"ඔබගේ ස්ථානය"</string>
-    <string name="permgroupdesc_location" msgid="5704679763124170100">"ඔබගේ භෞතික පිහිටුම නිරීක්ෂණය කරයි."</string>
-    <string name="permgrouplab_network" msgid="5808983377727109831">"ජාල සන්නිවේදනය"</string>
-    <string name="permgroupdesc_network" msgid="4478299413241861987">"විවිධ ජාල විශේෂාංග වෙත පිවිසෙන්න."</string>
-    <string name="permgrouplab_bluetoothNetwork" msgid="1585403544162128109">"බ්ලූටූත්"</string>
-    <string name="permgroupdesc_bluetoothNetwork" msgid="5625288577164282391">"බ්ලූටූත් ඔස්සේ උපාංග සහ ජාල වෙත පිවිසෙන්න."</string>
-    <string name="permgrouplab_audioSettings" msgid="8329261670151871235">"ශ්‍රව්‍ය සැකසීම්"</string>
-    <string name="permgroupdesc_audioSettings" msgid="2641515403347568130">"ශ්‍රව්‍ය සැකසීම් වෙනස් කරන්න."</string>
-    <string name="permgrouplab_affectsBattery" msgid="6209246653424798033">"බැටරිය වෙත බලපායි"</string>
-    <string name="permgroupdesc_affectsBattery" msgid="6441275320638916947">"බැටරියේ බලය ක්ෂණිකව අඩු වන විශේෂාංග භාවිත කරන්න."</string>
-    <string name="permgrouplab_calendar" msgid="5863508437783683902">"දින දර්ශනය"</string>
-    <string name="permgroupdesc_calendar" msgid="5777534316982184416">"දින දර්ශන සිද්ධින්ට සෘජුව ප්‍රවේශ වීම."</string>
-    <string name="permgrouplab_dictionary" msgid="4148597128843641379">"පරිශීලක ශබ්ද කෝෂය කියවන්න"</string>
-    <string name="permgroupdesc_dictionary" msgid="7921166355964764490">"පරිශීලක ශබ්ද කෝෂයේ වචන කියවීම."</string>
-    <string name="permgrouplab_writeDictionary" msgid="8090237702432576788">"පරිශීලක ශබ්දකෝෂයට ලිවිම"</string>
-    <string name="permgroupdesc_writeDictionary" msgid="2711561994497361646">"පරිශීලක ශබ්දකෝෂයට වචන එකතු කරන්න."</string>
-    <string name="permgrouplab_bookmarks" msgid="1949519673103968229">"පිටුසන් සහ ඉතිහාසය"</string>
-    <string name="permgroupdesc_bookmarks" msgid="4169771606257963028">"පිටුසන් සහ බ්‍රව්සර ඉතිහාසය වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_deviceAlarms" msgid="6117704629728824101">"සීනුව"</string>
-    <string name="permgroupdesc_deviceAlarms" msgid="4769356362251641175">"සීනුව සකසන්න."</string>
-    <string name="permgrouplab_voicemail" msgid="4162237145027592133">"හඬ තැපෑල"</string>
-    <string name="permgroupdesc_voicemail" msgid="2498403969862951393">"හඬ තැපෑල වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_microphone" msgid="171539900250043464">"මයික්‍රොෆෝනය"</string>
-    <string name="permgroupdesc_microphone" msgid="7106618286905738408">"ශබ්දය පටිගත කිරීමට මයික්‍රොෆෝනය වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_camera" msgid="4820372495894586615">"කැමරාව"</string>
-    <string name="permgroupdesc_camera" msgid="2933667372289567714">"ඡායාරූප හෝ වීඩියෝ ග්‍රහණය සඳහා කැමරාව වෙත ඍජු ප්‍රවේශය."</string>
-    <string name="permgrouplab_screenlock" msgid="8275500173330718168">"අගුළු තිරය"</string>
-    <string name="permgroupdesc_screenlock" msgid="7067497128925499401">"ඔබගේ උපාංගයේ අගුළු තිරයේ ක්‍රියාකාරිත්වයට බලපාන හැකියාව."</string>
-    <string name="permgrouplab_appInfo" msgid="8028789762634147725">"ඔබගේ යෙදුම් වල තොරතුරු"</string>
-    <string name="permgroupdesc_appInfo" msgid="3950378538049625907">"ඔබගේ උපාංගයේ වෙනත් යෙදුම් වල ක්‍රියාකාරිත්වයට බලපෑම් කළ හැකි බව."</string>
-    <string name="permgrouplab_wallpaper" msgid="3850280158041175998">"බිතුපත"</string>
-    <string name="permgroupdesc_wallpaper" msgid="5630417854750540154">"උපාංග බිතුපතේ සැකසීම් වෙනස් කරන්න."</string>
-    <string name="permgrouplab_systemClock" msgid="406535759236612992">"ඔරලෝසුව"</string>
-    <string name="permgroupdesc_systemClock" msgid="3944359833624094992">"උපාංග කාල හෝ කාල කලාප වෙනස් කරන්න."</string>
-    <string name="permgrouplab_statusBar" msgid="2095862568113945398">"තත්ව තීරුව"</string>
-    <string name="permgroupdesc_statusBar" msgid="6242593432226807171">"උපාංග තත්ව තීරු සැකසීම් වෙනස් කරන්න."</string>
-    <string name="permgrouplab_syncSettings" msgid="3341990986147826541">"සමමුහුර්ත සැකසීම්"</string>
-    <string name="permgroupdesc_syncSettings" msgid="7603195265129031797">"සමමුහුර්ත සැකසීම් වෙත ප්‍රවේශය."</string>
-    <string name="permgrouplab_accounts" msgid="3359646291125325519">"ඔබගේ ගිණුම්"</string>
-    <string name="permgroupdesc_accounts" msgid="4948732641827091312">"ලබාගත හැකි ගිණුම් වලට ප්‍රවේශ වීම."</string>
-    <string name="permgrouplab_hardwareControls" msgid="7998214968791599326">"දෘඩාංග පාලක"</string>
-    <string name="permgroupdesc_hardwareControls" msgid="4357057861225462702">"හෑන්ඩ්සෙටයේ දෘඩාංග වලට සෘජුවම ප්‍රවේශ වන්න."</string>
-    <string name="permgrouplab_phoneCalls" msgid="9067173988325865923">"දුරකථන ඇමතුම්"</string>
-    <string name="permgroupdesc_phoneCalls" msgid="7489701620446183770">"දුරකථන ඇමතුම් නිරීක්ෂණය කරන්න, පටිගත කරන්න සහ ක්‍රියාත්මක කරන්න."</string>
-    <string name="permgrouplab_systemTools" msgid="4652191644082714048">"පද්ධති මෙවලම්"</string>
-    <string name="permgroupdesc_systemTools" msgid="8162102602190734305">"පද්ධතියේ පහල මට්ටම් ප්‍රවේශය සහ පාලනය."</string>
-    <string name="permgrouplab_developmentTools" msgid="3446164584710596513">"සංවර්ධක මෙවලම්"</string>
-    <string name="permgroupdesc_developmentTools" msgid="7058828032358142018">"යෙදුම් සංවර්ධකයන් සඳහා පමණක් අවශ්‍ය විශේෂාංග."</string>
-    <string name="permgrouplab_display" msgid="4279909676036402636">"වෙනත් යෙදුම් UI"</string>
-    <string name="permgroupdesc_display" msgid="6051002031933013714">"වෙනත් යෙදුම්වල UI සඳහා බලපායි."</string>
-    <string name="permgrouplab_storage" msgid="1971118770546336966">"ආචයනය"</string>
-    <string name="permgroupdesc_storage" product="nosdcard" msgid="7442318502446874999">"USB ආචයනය වෙත ප්‍රවේශය."</string>
-    <string name="permgroupdesc_storage" product="default" msgid="9203302214915355774">"SD පත වෙත ප්‍රවේශය."</string>
-    <string name="permgrouplab_accessibilityFeatures" msgid="7919025602283593907">"ප්‍රවේශ්‍යතා විශේෂාංග"</string>
-    <string name="permgroupdesc_accessibilityFeatures" msgid="4205196881678144335">"උපකාරීවන තාක්ෂණ ඉල්ලීම් කළ හැකි විශේෂාංග."</string>
-    <string name="capability_title_canRetrieveWindowContent" msgid="3901717936930170320">"කවුළු අන්න්තර්ගතය ලබාගන්න"</string>
-    <string name="capability_desc_canRetrieveWindowContent" msgid="3772225008605310672">"ඔබ අන්තර්ක්‍රියාකාරී වන කවුළුවේ අන්තර්ගතය පරීක්ෂා කරන්න."</string>
-    <string name="capability_title_canRequestTouchExploration" msgid="3108723364676667320">"ස්පර්ශයෙන් ගවේෂණය සක්‍රිය කරන්න"</string>
-    <string name="capability_desc_canRequestTouchExploration" msgid="5800552516779249356">"ස්පර්ශ කරන අයිතම හඬ නගා කතා කෙරෙනු ඇති අතර ඉංගිති භාවිතයෙන් තිරය ගවේෂණය කිරීමට පුළුවනි."</string>
-    <string name="capability_title_canRequestEnhancedWebAccessibility" msgid="1739881766522594073">"උසස් වෙබ් ප්‍රවේශ්‍යතාව සක්‍රිය කරන්න"</string>
-    <string name="capability_desc_canRequestEnhancedWebAccessibility" msgid="7881063961507511765">"යෙදුම් අන්තර්ගතයට ප්‍රවේශ්‍යතාවය වැඩිවන ලෙස සකස් කිරීමට ඇතැම් විට ස්ක්‍රිප්ට් ස්ථාපනය කර ඇත."</string>
-    <string name="capability_title_canRequestFilterKeyEvents" msgid="2103440391902412174">"ඔබ ටයිප් කළ පෙළ බලන්න"</string>
-    <string name="capability_desc_canRequestFilterKeyEvents" msgid="7463135292204152818">"ණයවරපත් අංක සහ මුරපද වැනි පුද්ගලික දත්ත ඇතුළත් වේ."</string>
-    <string name="permlab_statusBar" msgid="7417192629601890791">"තත්ව තීරුව අබල කරන්න හෝ වෙනස් කරන්න"</string>
-    <string name="permdesc_statusBar" msgid="8434669549504290975">"තත්ව තීරුව අක්‍රිය කිරීමට හෝ පද්ධති නිරූපක එකතු හෝ ඉවත් කිරීමට යෙදුමට අවසර දේ."</string>
-    <string name="permlab_statusBarService" msgid="7247281911387931485">"තත්ව තීරුව"</string>
-    <string name="permdesc_statusBarService" msgid="716113660795976060">"තත්ව තීරුව වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_expandStatusBar" msgid="1148198785937489264">"තත්ව තීරුව දිග හැරීම/හැකිලීම"</string>
-    <string name="permdesc_expandStatusBar" msgid="6917549437129401132">"තත්ව තීරුව දිග හැරීමට හෝ හැකිළීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_processOutgoingCalls" msgid="3906007831192990946">"පිටවන ඇමතුම් වල මග වෙනස් කිරීම"</string>
-    <string name="permdesc_processOutgoingCalls" msgid="5331318931937402040">"පිටවන ඇමතුම් සකස් කිරීමට සහ ඇමතීමට නියමිත අංකය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙන් යෙදුමට පිටවන ඇමතුම් නිරීක්ෂණය, නැවත හැරවීම හෝ වැළක්වීම අවසර දෙයි."</string>
-    <string name="permlab_receiveSms" msgid="8673471768947895082">"කෙටි පණිවිඩ ලබාගැනීම (SMS)"</string>
-    <string name="permdesc_receiveSms" msgid="6424387754228766939">"SMS පණිවිඩ ලැබීමට සහ ක්‍රියාත්මක කිරීමට යෙදුමට අවසර දෙන්න. මෙහි තේරුම යෙදුමට ඔබගේ උපාංගයට ලැබෙන පණිවිඩ අධීක්ෂණය කිරීමට හැකිවීම වන අතර, ඒවා ඔබට නොපෙන්වා මකා දැමීමටද හැකි වීමයි."</string>
-    <string name="permlab_receiveMms" msgid="1821317344668257098">"පෙළ පණිවුඩ ලබාගන්න (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"MMS පණිවිඩ සොයා ලබාගැනීමට සහ ක්‍රියාත්මක කිරීමට යෙදුමට අවසර දෙන්න. යෙදුම නිරීක්ෂණය කරනු ලබන අතර ඔබට ලැබුන පණිවිඩ පෙන්වීමෙන් තොරවම මකා දැමිය හැකි බව මෙමඟින් අදහස් කරයි."</string>
-    <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"හදිසි විකාශන ලබා ගැනීම"</string>
-    <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"හදිසි විකාශ පණිවිඩ ලැබීමට සහ ක්‍රියාත්මක කිරීමට යෙදුමට අවසර දෙන්න. පද්ධති යෙදුම් වලට පමණක් මෙම අවසරය අදාළ වෙයි."</string>
-    <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"සෙල් ප්‍රචාරණ පණිවිඩ කියවීම"</string>
-    <string name="permdesc_readCellBroadcasts" msgid="6361972776080458979">"ඔබගේ උපාංගයට ලැබුණු සෙල් විකාශන පණිවිඩ කියවීමට යෙදුමට අවසර දෙන්න. ඔබට හදිසි අවස්ථාවන් පිළිබඳ අනතුරු ඇඟවීමට සෙල් විකාශන පණිවිඩ ඇතැම් ස්ථානවල සිට යවනු ලබයි. හදිසි සෙල් විකාශන ලැබෙන අවස්ථාවකදී, අනිෂ්ට යෙදුම් මඟින් ඔබගේ උපාංගයට කාර්ය සාධනයට හෝ ක්‍රියකරණයට බාධා සිදුවිය හැක."</string>
-    <string name="permlab_sendSms" msgid="5600830612147671529">"SMS පණිවිඩ යැවීම"</string>
-    <string name="permdesc_sendSms" msgid="7094729298204937667">"SMS පණිවිඩ යැවීමට යෙදුමට අවසර දෙන්න. මෙමඟින් බලාපොරොත්තු නොවූ ප්‍රතිඵල අත් විය හැක. අනිෂ්ට යෙදුම් ඔබගේ තහවුරුවකින් තොරව පණිවිඩ යැවීම මඟින් ඔබගේ මුදල් වැය කල හැක."</string>
-    <string name="permlab_sendRespondViaMessageRequest" msgid="8713889105305943200">"පණිවිඩ සිදුවීම හරහා ප්‍රතිචාර යැවීම"</string>
-    <string name="permdesc_sendRespondViaMessageRequest" msgid="7107648548468778734">"පැමිණෙන ඇමතුම් සඳහා පණිවිඩ ඔස්සේ ප්‍රතිචාර සිදුවීම් හසුරුවීමට වෙනත් පණිවිඩ යෙදුම් සඳහා ඉල්ලීම් යැවීමට, යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_readSms" msgid="8745086572213270480">"ඔබගේ පෙළ පණිවුඩ කියවන්න (SMS හෝ MMS)"</string>
-    <string name="permdesc_readSms" product="tablet" msgid="2467981548684735522">"ඔබගේ ටැබ්ලටයේ හෝ SIM පතේ ආචයනය කර ඇති SMS පණිවිඩ කියවීමට යෙදුමට අවසර දෙන්න. අන්තර්ගතය හෝ විශවාසදයි බවින් තොරවම සියලු SMS පණිවිඩ කියවීමට මෙමගින් යෙදුමට අවසර දෙයි."</string>
-    <string name="permdesc_readSms" product="default" msgid="3695967533457240550">"ඔබගේ දුරකථනයේ හෝ SIM පතේ ආචයනය කරන ලද SMS පණිවිඩ කියවීමට යෙදුමට අවසර දෙන්න. අන්තර්ගතය හෝ විශ්වාසදායී බවින් තොරවම සියලු SMS පණිවිඩ කියවීමට මෙමගින් යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_writeSms" msgid="3216950472636214774">"ඔබගේ කෙටි පණිවිඩ සංස්කරණය කිරීම (SMS හෝ MMS)"</string>
-    <string name="permdesc_writeSms" product="tablet" msgid="5160413947794501538">"ඔබගේ ටැබ්ලටයේ හෝ SIM පතේ ගබඩා කර ඇති SMS පණිවිඩ වෙත ලිවීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් ඔබගේ පණිවිඩ මකා දැමිය හැක."</string>
-    <string name="permdesc_writeSms" product="default" msgid="7268668709052328567">"ඔබගේ ටැබ්ලටයේ හෝ SIM පතේ ආචයනය කරන ලද SMS පණිවිඩ ලිවීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් ඔබගේ පණිවිඩ මකා දැමිය හැක."</string>
-    <string name="permlab_receiveWapPush" msgid="5991398711936590410">"පෙළ පණිවිඩ ලබාගැනීම (WAP)"</string>
-    <string name="permdesc_receiveWapPush" msgid="748232190220583385">"WAP පණිවිඩ ලැබීමට සහ ක්‍රියාවලි කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙහි ඔබව ඒවාට පෙන්වීමකින් තොරව ඔබට පණිවිඩ නිරීක්ෂණයට හෝ මැකීමට හැකියාව ඇතුළත් වේ."</string>
-    <string name="permlab_getTasks" msgid="6466095396623933906">"ධාවනය වන යෙදුම් ලබාගැනීම"</string>
-    <string name="permdesc_getTasks" msgid="7454215995847658102">"දැනට සහ මෑත ක්‍රියාත්මක කාර්යයන් පිළිබඳ විස්තරාත්මක තොරතුරු සොයා ලබාගැනීමට යෙදුමට ඉඩ දෙන්න. මෙය කුමන යෙදුම් උපාංගයේ භාවිතා කරන්නේද යන තොරතුරු යෙදුම්වලට සොයා ගැනීමට ඉඩ දිය හැක."</string>
-    <string name="permlab_interactAcrossUsers" msgid="7114255281944211682">"පරිශීලකයන් අතර අන්තර්ක්‍රියාකාරී වන්න"</string>
-    <string name="permdesc_interactAcrossUsers" msgid="364670963623385786">"උපාංගයේ විවිධ පරිශීලකයන් හරහා ක්‍රියාවන් දැක්වීමට යෙදුමට අවසර දෙන්න. පරිශීලකයන් අතර ආරක්ෂාව කඩකිරීමට අනිෂ්ට යෙදුම් විසින් මෙය භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_interactAcrossUsersFull" msgid="2567734285545074105">"පරිශීලකයන් අතර අන්තර් ක්‍රියාකාරී වීමට සම්පූර්ණ බලපත්‍රය"</string>
-    <string name="permdesc_interactAcrossUsersFull" msgid="376841368395502366">"පරිශීලකයන් හරහා සිදු කළ හැකි සියලු අන්තර් ක්‍රියා වලට අවසර දෙන්න."</string>
-    <string name="permlab_manageUsers" msgid="1676150911672282428">"පරිශීලකයන් කළමනාකරණය කරන්න"</string>
-    <string name="permdesc_manageUsers" msgid="8409306667645355638">"විස්තර ලබා ගැනීම, නිර්මාණකරණය, මකාදැමීම ඇතුළු පරිශීලකයන් කළමනාකරණයට යෙදුම්වලට අවසර දෙන්න."</string>
-    <string name="permlab_getDetailedTasks" msgid="6229468674753529501">"ධාවනය වන යෙදුම් වල තොරතුරු සොයා ලබාගැනීම"</string>
-    <string name="permdesc_getDetailedTasks" msgid="153824741440717599">"දැනට සහ මෑතක ක්‍රියාත්මක කාර්යයන් පිළිබඳ විස්තරාත්මක තොරතුරු ලබාගැනීමට යෙදුමට අවසර දෙන්න අනිෂ්ට යෙදුම් අනෙකුත් යෙදුම් පිළිබඳ පුද්ගලික තොරතුරු සොයා ගැනීමට ඉඩ තිබේ."</string>
-    <string name="permlab_reorderTasks" msgid="2018575526934422779">"ධාවනය වන යෙදුම් නැවත අනුපිළිවෙලට සැකසීම"</string>
-    <string name="permdesc_reorderTasks" msgid="7734217754877439351">"පෙරබිමට හෝ පසුබිමට සිදුවීම් ගෙනයාමට යෙදුමට අවසර දෙන්න. ඔබගේ ආදානයකින් තොරව යෙදුම මෙය සිදුකරයි."</string>
-    <string name="permlab_removeTasks" msgid="6821513401870377403">"යෙදුම් ධාවනය නවත්වන්න"</string>
-    <string name="permdesc_removeTasks" msgid="1394714352062635493">"කාර්යයන් ඉවත් කිරීමට සහ ඒවායෙහි යෙදුම් නැති කිරීමට යෙදුමට අවසර දෙන්න. අනෙක් යෙදුම් හැසිරීම බාධා කිරීමට අනිෂ්ට යෙදුම්වලට අවසර දෙන්න."</string>
-    <string name="permlab_manageActivityStacks" msgid="7391191384027303065">"ක්‍රියාකාරකම් අට්ටි කළමනාකරණය කරන්න"</string>
-    <string name="permdesc_manageActivityStacks" msgid="1615881933034084440">"වෙනත් යෙදුම් ධාවනය වන ක්‍රියාකාරකම් අට්ටි වලට එකතු කිරීමට, ඉවත් කිරීමට, සහ වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම්වල හැසිරීම අනිෂ්ට යෙදුම් මගින් බාධා විය හැක."</string>
-    <string name="permlab_startAnyActivity" msgid="2918768238045206456">"ඕනෑම ක්‍රියාවක් අරඹන්න"</string>
-    <string name="permdesc_startAnyActivity" msgid="997823695343584001">"අවසර ආරක්ෂාව හෝ යැවුම් තත්වයෙන් තොරවම ඕනෑම ක්‍රියාවක් ආරම්භ කිරීමට යෙදුමට අවසර දේ."</string>
-    <string name="permlab_setScreenCompatibility" msgid="6975387118861842061">"තිර ගැළපුම සැකසීම"</string>
-    <string name="permdesc_setScreenCompatibility" msgid="692043618693917374">"වෙනත් යෙදුම්වල තිර ගැලපුම් මාදිලිය පාලනයට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම්වල හැසිරීම අනිෂ්ට යෙදුම් කැඩිය හැක."</string>
-    <string name="permlab_setDebugApp" msgid="3022107198686584052">"යෙදුම් නිදොස්කරණය සබල කිරීම"</string>
-    <string name="permdesc_setDebugApp" msgid="4474512416299013256">"වෙනත් යෙදුමක් සඳහා නිදොස්කරණය සක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම් විනාශ කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක."</string>
-    <string name="permlab_changeConfiguration" msgid="4162092185124234480">"පද්ධති සංදර්ශක සැකසීම් වෙනස් කරන්න"</string>
-    <string name="permdesc_changeConfiguration" msgid="4372223873154296076">"පෙදෙසිය හෝ සම්පූර්ණ අකුරු ප්‍රමාණය වැනි පවතින වින්‍යාසය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_enableCarMode" msgid="5684504058192921098">"මෝටර් රථ ආකාරය ක්‍රියාත්මක කරන්න"</string>
-    <string name="permdesc_enableCarMode" msgid="4853187425751419467">"කාර් ආකාරය සබල කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_killBackgroundProcesses" msgid="3914026687420177202">"වෙනත් යෙදුම් වැසීම"</string>
-    <string name="permdesc_killBackgroundProcesses" msgid="4593353235959733119">"අනෙක් යෙදුම්වල පසුබිම් ක්‍රියාවලි අවසන් කිරීමට යෙදුමට අවසර දෙන්න. අනෙක් යෙදුම් ධාවනය නැවතීමට මෙය හේතුවක් වේ."</string>
-    <string name="permlab_forceStopPackages" msgid="2329627428832067700">"වෙනත් යෙදුම් බලෙන් නවත්වන්න"</string>
-    <string name="permdesc_forceStopPackages" msgid="5253157296183940812">"යෙදුමට බලෙන් අනෙක් යෙදුම් නැවතීමට අවසර දෙන්න."</string>
-    <string name="permlab_forceBack" msgid="652935204072584616">"යෙදුම වැසීමට බල කිරීම"</string>
-    <string name="permdesc_forceBack" msgid="3892295830419513623">"නැවතීමට පෙරබිමේ ඇති ඕනෑම ක්‍රියාවක් බලෙන් නැවතීමට සහ පිටුපසට යාමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_dump" msgid="1681799862438954752">"පද්ධති අභ්‍යන්තර තත්වය සොයා ලබා ගන්න"</string>
-    <string name="permdesc_dump" msgid="1778299088692290329">"පද්ධතියේ අභ්‍යන්තර තත්වය ලැබීමට යෙදුමට අවසර දෙන්න. ඔවුන් සාමාන්‍යයෙන් භාවිත නොකරන විවිධත්වයකින් යුත් පුද්ගලික සහ ආරක්‍ෂිත තොරතුරු අනිෂ්ට යෙදුම් සොයා ලබා ගත හැක."</string>
-    <string name="permlab_retrieve_window_content" msgid="8022588608994589938">"තිර අන්තර්ගතය සොයා ලබාගැනීම"</string>
-    <string name="permdesc_retrieve_window_content" msgid="3193269069469700265">"ක්‍රියාකාරී කවුළුවක අන්තර්ගතය ලබාගැනීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් විසින් සම්පූර්ණ කවුළු අන්තර්ගතය ලබාගැනීම සහ මුරපදය හැර ඒවායෙහි පෙළ පරික්ෂා කිරීම සිදුකරයි."</string>
-    <string name="permlab_temporary_enable_accessibility" msgid="2312612135127310254">"ප්‍රවේශ්‍යතාවය තාවකාලිකව සබල කිරීම"</string>
-    <string name="permdesc_temporary_enable_accessibility" msgid="8079456293182975464">"උපාංගය වෙත ප‍්‍රවේශ්‍යතාව තාවකාලිකව සක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. පරිශීලක අවධානයකින් තොරව අනිෂ්ට යෙදුම් ප‍්‍රවේශ්‍යතාව සක්‍රිය කළ හැක."</string>
-    <string name="permlab_retrieve_window_info" msgid="8532295199112519378">"තිර තොරතුරු සොයා ලබාගැනීම"</string>
-    <string name="permdesc_retrieve_window_info" msgid="4998836370424186849">"කවුළු කළමනාකරු මගින් කවුළුව ගැන තොරතුරු සොයා ලබාගැනීමට යෙදුමට අවසර දෙන්න. අභ්‍යන්තර පද්ධති භාවිතය සඳහා කැමති තොරතුරු අනිෂ්ට යෙදුම් විසින් ලබා ගත හැක."</string>
-    <string name="permlab_filter_events" msgid="8675535648807427389">"සිදුවීම් පෙරන්න"</string>
-    <string name="permdesc_filter_events" msgid="8006236315888347680">"පිටත් කිරීමට පෙර සියලු පරිශීලක සිදුවීම්වල ප්‍රවාහයක් පෙරීමට යොදා ගන්නා ආදාන පෙරීමක් ලියාපදිංචි කිරීමට යෙදුමට අවසර දෙන්න. පරිශීලක මැදිහත් වීමකින් තොරව පද්ධති UI අනිෂ්ට යෙදුම් පාලනය කරයි."</string>
-    <string name="permlab_magnify_display" msgid="5973626738170618775">"දර්ශනය විශාලනය කරන්න"</string>
-    <string name="permdesc_magnify_display" msgid="7121235684515003792">"දසුනේ අන්තර්ගතය විශාල කිරීමට යෙදුමට අවසර දෙන්න. ඇතැම් විට අනිෂ්ට යෙදුම්, උපාංගය භාවිතා කළ නොහැකි බවට පත් කරමින් දසුනේ අන්තර්ගතය වෙනස් කළ හැක."</string>
-    <string name="permlab_shutdown" msgid="7185747824038909016">"අඩ වශයෙන් වැහීම"</string>
-    <string name="permdesc_shutdown" msgid="7046500838746291775">"ක්‍රියාකාරකම් කළමනාකරු වැහීමේ තත්වයට දමන්න. සම්පූර්ණ වැහීමකට පත් නොකරන්න."</string>
-    <string name="permlab_stopAppSwitches" msgid="4138608610717425573">"යෙදුම් මාරු වීම වැළක්වීම"</string>
-    <string name="permdesc_stopAppSwitches" msgid="8262195802582255021">"වෙනත් යෙදුමක් වෙත පරිශීලකයාව මාරු වීම වළක්වයි."</string>
-    <string name="permlab_getTopActivityInfo" msgid="2537922311411546016">"පවතින යෙදුමේ තොරතුරු ලබාගැනීම"</string>
-    <string name="permdesc_getTopActivityInfo" msgid="8153651434145132505">"තිරයේ පෙරබිම තුළ තිබෙන දැන් පවත්නා යෙදුමේ සහ සේවාවල පෞද්ගලික තොරතුරු ලබාගැනීමට දරන්නාට අවසර දෙන්න."</string>
-    <string name="permlab_runSetActivityWatcher" msgid="892239094867182656">"සියලු යෙදුම් දියත් කිරීම් නිරීක්ෂණය සහ පාලනය කිරීම"</string>
-    <string name="permdesc_runSetActivityWatcher" msgid="6003603162578577406">"පද්ධතිය ක්‍රියාකාරකම් දියත් කරන්නේ කෙසේදැයි නිරීක්ෂණයට සහ පාලනයට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් මගින් පද්ධතිය සම්පූර්ණයෙන්ම සම්මුතියකට එළඹිය හැක. වර්ධනය සඳහා පමණක් මෙම අවසරය අවශ්‍ය වෙයි, සාමාන්‍ය භාවිතය සඳහා කිසි විටෙකත් අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_broadcastPackageRemoved" msgid="2576333434893532475">"පැකේජ ඉවත් කිරීමේ ප්‍රචාරණයක් යවන්න"</string>
-    <string name="permdesc_broadcastPackageRemoved" msgid="6621901216207931089">"යෙදුම් පැකේජයක් ඉවත්කොට ඇති බවට දැනුම්දීමක් විකාශනයට යෙදුමට අවසර දෙයි. ධාවනය වන අනෙකුත් යෙදුමක් නැති කිරීමට අනිෂ්ට යෙදුම් විසින් මෙය භාවිත කළ හැක."</string>
-    <string name="permlab_broadcastSmsReceived" msgid="5689095009030336593">"SMS-ලැබීම විකාශන යැවීම"</string>
-    <string name="permdesc_broadcastSmsReceived" msgid="4152037720034365492">"SMS පණිවිඩයක් හරහා ලැබුණු දැනුම්දීමක් ප්‍රචාරණයට යෙදුමට අවසර දෙන්න. පැමිණෙන SMS පණිවිඩ වංචා කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක."</string>
-    <string name="permlab_broadcastWapPush" msgid="3145347413028582371">"WAP-PUSH-ලැබීම විකාශන යැවීම"</string>
-    <string name="permdesc_broadcastWapPush" msgid="4783402525039442729">"WAP PUSH පණිවුඩයක් ලැබී ඇති බවට දැනුම්දීමක් විකාශනය කිරීමට යෙදුමට අවසර දෙන්න. වංචාකාරී MMS පණිවුඩ ලැබීම් හෝ නිහඬව ඕනෑම වෙබ් පිටුවක අන්තර්ගතය අනිෂ්ට විචල්‍යවලින් ඉවත් කිරීමට, අනිෂ්ට යෙදුම් විසින් මෙය භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_setProcessLimit" msgid="2451873664363662666">"ධාවන ක්‍රියාවලි ගණන සීමා කිරීම"</string>
-    <string name="permdesc_setProcessLimit" msgid="7318061314040879542">"ධාවනය වන උපරිම ක්‍රියාවලි ගණන පාලනය කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_setAlwaysFinish" msgid="550958507798796965">"පසුබිම් යෙදුම් වලට වැසීමට බලකරන්න"</string>
-    <string name="permdesc_setAlwaysFinish" msgid="7471310652868841499">"පසුබිමට පිවිසෙනවාත් සමඟම ක්‍රියාකාරකම් නැවතීම පාලනයට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසිසේත් අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_batteryStats" msgid="2789610673514103364">"බැටරි සංඛ්‍යාන කියවීම"</string>
-    <string name="permdesc_batteryStats" msgid="5897346582882915114">"වර්තමාන පහළ මට්ටමේ බැටරිය භාවිතා දත්ත කියවීමට යෙදුමට අවසර දෙන්න. ඔබ භාවිත කරන යෙදුම් මොනවා දැයි ගැන විස්තරාත්මක තොරතුරු ගැන දැන ගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_updateBatteryStats" msgid="3719689764536379557">"බැටරි සංඛ්‍යාන වෙනස් කිරීම"</string>
-    <string name="permdesc_updateBatteryStats" msgid="6862817857178025002">"එකතු කරගන්නා ලද බැටරි සංඛ්‍යාන වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් වල භාවිතයට නොවේ."</string>
-    <string name="permlab_getAppOpsStats" msgid="1508779687436585744">"යෙදුමේ විකල්ප සංඛ්‍යාංක සොයා ලබාගැනීම"</string>
-    <string name="permdesc_getAppOpsStats" msgid="6243887041577912877">"එකතු කරගත් යෙදුම් ක්‍රියාකාරිත්ව සංඛ්‍යා ලේඛන වෙනස් කිරීමට උපාංගයට ඉඩ දෙන්න. සාමාන්‍ය උපාංග භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_updateAppOpsStats" msgid="8829097373851521505">"යෙදුම් විකල්ප සංඛ්‍යාංක වෙනස් කිරීම"</string>
-    <string name="permdesc_updateAppOpsStats" msgid="50784596594403483">"එකතු කරගත් යෙදුම් ක්‍රියාකාරිත්ව සංඛ්‍යා ලේඛන වෙනස් කිරීමට යෙදුමට ඉඩ දෙන්න. සාමාන්‍ය යෙදුම් භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_backup" msgid="470013022865453920">"පද්ධති උපස්ථ පාලනය කරන්න සහ නැවත පිහිටුවන්න"</string>
-    <string name="permdesc_backup" msgid="6912230525140589891">"පද්ධතියේ උපස්ථය සහ උපක්‍රම නැවත පිහිටුවීම පාලනයට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_confirm_full_backup" msgid="5557071325804469102">"සම්පූර්ණ උපස්ථය හෝ මෙහෙයුම් නැවත පිහිටුවීම සනාථ කිරීම"</string>
-    <string name="permdesc_confirm_full_backup" msgid="1748762171637699562">"පූර්ණ උපස්ථ තහවුරුකිරීම් UI පුරන්නට උපකරණයට ඉඩ දෙන්න. කිසිම යෙදුමක් භාවිතා නොකරනු ඇත."</string>
-    <string name="permlab_internalSystemWindow" msgid="2148563628140193231">"අවසර නොලත් කවුළුව දර්ශනය කරන්න"</string>
-    <string name="permdesc_internalSystemWindow" msgid="7458387759461466397">"අභ්‍යන්තර පද්ධති පරිශීලක අතුරුමුහුණත් විසින් භාවිතා කිරීමට බලාපොරොත්තු වන කවුළු නිර්මාණය කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_systemAlertWindow" msgid="3543347980839518613">"වෙනත් යෙදුම් උඩින් අඳින්න"</string>
-    <string name="permdesc_systemAlertWindow" msgid="8584678381972820118">"අනෙක් යෙදුම් මත හෝ පරිශීලක අතුරු මුහුණත් කොටස්වල ඇඳීමට යෙදුමට ඉඩ දෙන්න. එය ඔබේ භාවිතයේ ඇති ඕනෑම යෙදුමක මුහුණත සමග සම්බන්ධ වීමට හෝ අනෙක් යෙදුම් ගැන ඔබට පෙනෙන ආකාරය වෙනස් කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_setAnimationScale" msgid="2805103241153907174">"ගෝලීය සජීවන වේගය වෙනස් කරන්න"</string>
-    <string name="permdesc_setAnimationScale" msgid="7690063428924343571">"ඕනෑම වෙලාවක පොදු සජීවීකරණ වේගය (වේගවත් හෝ මන්දගාමී සජීවීකරණ) වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_manageAppTokens" msgid="1286505717050121370">"යෙදුම් ටෝකන කළමනාකරණය කිරීම"</string>
-    <string name="permdesc_manageAppTokens" msgid="8043431713014395671">"සාමාන්‍ය Z පටිපාටිය මඟහැරයමින් යෙදුම්වලට අයිති ටෝකන් පත් නිර්මාණයට සහ කළමනාකරණයට යෙදුම්වලට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසිසේත් අවශ්‍ය නොවේ."</string>
-    <string name="permlab_freezeScreen" msgid="4708181184441880175">"තිරය නිශ්චල කරන්න"</string>
-    <string name="permdesc_freezeScreen" msgid="8558923789222670064">"සම්පූර්ණ තිර සංක්‍රමණය සඳහා තිරය තාවකාලිකව මුදවිමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_injectEvents" msgid="1378746584023586600">"යතුරු සහ පාලන බොත්තම් ඔබන්න"</string>
-    <string name="permdesc_injectEvents" product="tablet" msgid="206352565599968632">"තමන්ගේ ආදාන සිදුවීම් (යතුරු එබිම් , ආදී ) අනෙකුත් යෙදුම්වලට භාරදීමට යෙදුමට ඉඩ දෙන්න. අනිෂ්ට යෙදුම් මෙය ටැබ්ලටය ලබා ගැනීමට භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permdesc_injectEvents" product="default" msgid="653128057572326253">"වෙනත් යෙදුම්වලට එහි ආදාන සිදුවීම් (යතුරු එබීම්, යනාදිය.) ආදිය යැවීමට යෙදුමට අවසර දෙන්න. දුරකථනය අත්කර ගැනීම අනිෂ්ට යෙදුම් මෙය භාවිත කරයි."</string>
-    <string name="permlab_readInputState" msgid="469428900041249234">"ඔබ ටයිප් කරන දෙය සහ ඔබ ගන්නා ක්‍රියාවන් පටිගත කරන්න"</string>
-    <string name="permdesc_readInputState" msgid="8387754901688728043">"මුරපදය ටයිප් කිරීම වැනි අනෙකුත් යෙදුම් සමඟ අන්තර්ක්‍රියාකාරී වනවිට යනාදී ඔබ ඔබන යතුරු දැකීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අදාළ නොවේ."</string>
-    <string name="permlab_bindInputMethod" msgid="3360064620230515776">"ආදාන ක්‍රමයක් වෙත බඳින්න"</string>
-    <string name="permdesc_bindInputMethod" msgid="3250440322807286331">"ආදාන ක්‍රමය ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindAccessibilityService" msgid="5357733942556031593">"ප‍්‍රවේශ්‍යතා සේවාවක් වෙත බදින්න"</string>
-    <string name="permdesc_bindAccessibilityService" msgid="7034615928609331368">"ප‍්‍රවේශ්‍යතා සේවාවේ ඉහළ මට්ටමේ අතුරුමුහුණතට බැඳීමට දරන්නාට අවසර දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිවිටක අවශ්‍ය නොවේ."</string>
-    <string name="permlab_bindPrintService" msgid="8462815179572748761">"මුද්‍රණ සේවාවකට බද්ධ වී ඇත"</string>
-    <string name="permdesc_bindPrintService" msgid="7960067623209111135">"මුද්‍රණ සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_accessAllPrintJobs" msgid="1120792468465711159">"සියලු මුද්‍රණ කාර්යයන් වෙත පිවිසෙන්න"</string>
-    <string name="permdesc_accessAllPrintJobs" msgid="2978185311041864762">"වෙනත් යෙදුමකින් සෑදු මුද්‍රණ කාර්ය වෙත පිවිසීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindNfcService" msgid="2752731300419410724">"NFC සේවාව වෙත බැඳෙන්න"</string>
-    <string name="permdesc_bindNfcService" msgid="6120647629174066862">"NFC කාඩ් පත් ආදර්ශනය කරන යෙදුම් රඳවනයට සම්බන්ධ වීමට ඉඩ දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindTextService" msgid="7358378401915287938">"පෙළ සේවාවකට බඳින්න"</string>
-    <string name="permdesc_bindTextService" msgid="8151968910973998670">"කෙටි පණිවිඩ සේවාවක (උදා. SpellCheckerService) ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindVpnService" msgid="4708596021161473255">"VPN සේවාවකට බැඳීම"</string>
-    <string name="permdesc_bindVpnService" msgid="2067845564581693905">"VPN සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindWallpaper" msgid="8716400279937856462">"බිතුපත වෙත බඳින්න"</string>
-    <string name="permdesc_bindWallpaper" msgid="7108428692595491668">"බිතුපත ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindRemoteViews" msgid="5697987759897367099">"විජට සේවාවකට බඳින්න"</string>
-    <string name="permdesc_bindRemoteViews" msgid="4717987810137692572">"විජට් සේවාව ඉහල මට්ටමේ අතුරු මුහුණතක් වෙත සම්බන්ධ කිරීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_bindDeviceAdmin" msgid="8704986163711455010">"උපාංග පරිපාලක සමඟ අන්තර්ක්‍රියාකාරී වීම"</string>
-    <string name="permdesc_bindDeviceAdmin" msgid="569715419543907930">"උපාංග පාලකයා වෙතට අභිප්‍රායයන් යැවීමට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වලට කිසි විටෙක අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_manageDeviceAdmins" msgid="4248828900045808722">"උපාංග පරිපාලකයෙක් එක් කිරීම හෝ ඉවත් කිරීම"</string>
-    <string name="permdesc_manageDeviceAdmins" msgid="5025608167709942485">"දරන්නාට උපාංග පරිපාලකයින් එක් කිරීමට හෝ ඉවත් කිරීමට අවසර දේ. සාමාන්‍ය යෙදුම් වලට කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="permlab_setOrientation" msgid="3365947717163866844">"තිර දිශානතිය වෙනස් කිරීම"</string>
-    <string name="permdesc_setOrientation" msgid="3046126619316671476">"තිරයේ භ්‍රමණය ඕනෑම වේලාවක වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවනු ඇත."</string>
-    <string name="permlab_setPointerSpeed" msgid="9175371613322562934">"දර්ශකයේ වේගය වෙනස් කිරීම"</string>
-    <string name="permdesc_setPointerSpeed" msgid="6866563234274104233">"මූසිකයේ හෝ ට්‍රැක්පෑඩයේ වේගය ඕනෑම මොහොතක වෙනස් කිරීමට උපාංගයට ඉඩ දෙන්න. සාමාන්‍ය උපාංගයන් සඳහා කිසිදා අවශ්‍ය නොවනු ඇත."</string>
-    <string name="permlab_setKeyboardLayout" msgid="4778731703600909340">"යතුරු පුවරු පිරිසැලැස්ම වෙනස් කිරීම"</string>
-    <string name="permdesc_setKeyboardLayout" msgid="8480016771134175879">"යතුරුපුවරු මුහුණත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_signalPersistentProcesses" msgid="4539002991947376659">"යෙදුම් වෙත Linux සංඥා යැවීම"</string>
-    <string name="permdesc_signalPersistentProcesses" msgid="4896992079182649141">"පවතින සියලු ක්‍රියාවලි වෙත සැපයුම් සංඥා ඉල්ලවිමට යෙදුමට අවසර දේ."</string>
-    <string name="permlab_persistentActivity" msgid="8841113627955563938">"යෙදුම සැමවිටම ධාවනය කරන්න"</string>
-    <string name="permdesc_persistentActivity" product="tablet" msgid="8525189272329086137">"මතකයේ පවතින එහි කොටස් නොනැසී පැවතීමට යෙදුමට අවසර දෙන්න. වෙනත් යෙදුම් වලට මතකය සීමා කිරීමෙන් ටැබ්ලටය පමා කිරීම මගින්  මෙමගින් කළ හැක."</string>
-    <string name="permdesc_persistentActivity" product="default" msgid="4384760047508278272">"යෙදුමට තම කොටස් මතකය තුල නොබිඳීව රඳා පවත්වාගෙන යාමට අවසර දෙන්න. මෙය දුරකථනය මන්දගාමී කරමින් අනෙකුත් උපාංගයන් සඳහා ඉතිරි මතකය සීමා කිරීමට හැක."</string>
-    <string name="permlab_deletePackages" msgid="184385129537705938">"යෙදුම් මකන්න"</string>
-    <string name="permdesc_deletePackages" msgid="7411480275167205081">"Android පැකේජ මැකීමට යෙදුමට අවසර දෙන්න. වැදගත් යෙදුම් මැකීමට අනිෂ්ට යෙදුම් විසින් මෙය භාවිතා කිරීමට ඉඩ ඇත."</string>
-    <string name="permlab_clearAppUserData" msgid="274109191845842756">"යෙදුමේ වෙනත් දත්ත මකන්න"</string>
-    <string name="permdesc_clearAppUserData" msgid="4625323684125459488">"පරිශීලක දත්ත හිස් කිරීමට යෙදුමකට ඉඩ දේ."</string>
-    <string name="permlab_deleteCacheFiles" msgid="3128665571837408675">"අනෙක් යෙදුම්වල හැඹිලි මකන්න"</string>
-    <string name="permdesc_deleteCacheFiles" msgid="3812998599006730196">"හැඹිලි ගොනු මැකීමට අවසර යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_getPackageSize" msgid="7472921768357981986">"යෙදුම් ආචයනයේ ඉඩ ප්‍රමාණය මැනීම"</string>
-    <string name="permdesc_getPackageSize" msgid="3921068154420738296">"යෙදුමකට එහි කේතය, දත්ත සහ හැඹිලි ප්‍රමාණ ලබාගැනීමට අවසර දෙන්න."</string>
-    <string name="permlab_installPackages" msgid="2199128482820306924">"යෙදුම් කෙළින්ම ස්ථාපනය කිරීම"</string>
-    <string name="permdesc_installPackages" msgid="5628530972548071284">"නව හෝ යාවත්කාලින කරන ලද Android පැකේජයන් ස්ථාපනය කිරීමට ඉඩ දෙන්න. බලසහිත අවසර තීන්දු සමග නව යෙදුම් එකතු කිරීමට අනිෂ්ට යෙදුම්වලට මෙය භාවිතා කිරීමට ඉඩ තිබේ."</string>
-    <string name="permlab_clearAppCache" msgid="7487279391723526815">"යෙදුමේ සියලුම හැඹිලි දත්ත මකන්න"</string>
-    <string name="permdesc_clearAppCache" product="tablet" msgid="8974640871945434565">"අනෙක් යෙදුම්වල හැඹිලි නාමාවලි තුළ ඇති ගොනු මැකීමෙන් යෙදුමට ටැබ්ලට ආචයනය නිදහස් කිරීමට අවසර දෙන්න. මෙමගින් අනෙක් යෙදුම්වලට ඒවායේ දත්ත නැවත ලබා ගැනීමට අවශ්‍ය වන නිසා, ඒවායේ ආරම්භය තවත් සෙමින් සිදුවීමට ඉඩ ඇත."</string>
-    <string name="permdesc_clearAppCache" product="default" msgid="2459441021956436779">"අනෙක් යෙදුම්වල හැඹිලි නාමාවලි තුළ ඇති ගොනු මැකීමෙන් යෙදුමට දුරකථන ආචයනය නිදහස් කිරීමට අවසර දෙන්න. මෙමඟින් අනෙක් යෙදුම්වලට ඒවායේ දත්ත නැවත ලබා ගැනීමට අවශ්‍ය වන නිසා, ඒවායේ ආරම්භය තවත් සෙමින් සිදුවීමට ඉඩ ඇත."</string>
-    <string name="permlab_movePackage" msgid="3289890271645921411">"යෙදුම් සම්පත් ගෙන යාම"</string>
-    <string name="permdesc_movePackage" msgid="319562217778244524">"අභ්‍යන්තර සහ බාහිර මාධ්‍යයන්ගෙන් යෙදුමේ සම්පත් ගෙනයාමට සහ යෙදුමේ සම්පත් වලින් අභ්‍යන්තර සහ බාහිර මාධ්‍යයන්ට යෙදුමේ සම්පත් ගෙනයාමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_readLogs" msgid="6615778543198967614">"සංවේදී ලොග් දත්ත කියවීම"</string>
-    <string name="permdesc_readLogs" product="tablet" msgid="82061313293455151">"පද්ධතියේ විවිධ ලොග් ගොනු කියවීමට යෙදුමට අවසර දෙන්න. පුද්ගලික සහ පෞද්ගලික තොරතුරු ඇතුළත්ව ඔබ ටැබ්ලටයෙන් කුමක් කරන්නෙහිද යනාදී සාමාන්‍ය තොරතුරු සෙවීමට මෙයට අවසර දෙන්න."</string>
-    <string name="permdesc_readLogs" product="default" msgid="2063438140241560443">"පද්ධතියේ විවිධ ලොග් ගොනු කියවීමට යෙදුමට අවසර දෙන්න. පුද්ගලික සහ පෞද්ගලික තොරතුරු ඇතුළත්ව ඔබ දුරකථනයෙන් කුමක් කරන්නෙහිද යනාදී සාමාන්‍ය තොරතුරු සෙවීමට මෙයට අවසර දෙන්න."</string>
-    <string name="permlab_anyCodecForPlayback" msgid="715805555823881818">"නැවත ධාවනය සඳහා ඕනෑම මාධ්‍ය විකේතකයක් හාවිතා කරන්න"</string>
-    <string name="permdesc_anyCodecForPlayback" msgid="8283912488433189010">"නැවත ධාවනය සඳහා විකේතනය කිරීමට ඕනෑම ස්ථාපිත මාධ්‍ය විකේතකයක් භාවිතයට යෙදුමට අවසර දෙන්න."</string>
-    <!-- no translation found for permlab_manageCaCertificates (1678391896786882014) -->
-    <skip />
-    <!-- no translation found for permdesc_manageCaCertificates (4015644047196937014) -->
-    <skip />
-    <string name="permlab_diagnostic" msgid="8076743953908000342">"Diag විසින් හිමිකාරත්වය දරණ සම්පත්වලට කියවීම/ ලිවිම"</string>
-    <string name="permdesc_diagnostic" msgid="6608295692002452283">"Diag කණ්ඩායමට අයිති ඕනෑම සම්පතක් කියවීමට සහ ලිවීමට යෙදුමට අවසර දෙන්න. උදාහරණයක් ලෙස /dev තුල ඇති ගොනු. මෙයට පද්ධති ස්ථායිතාවට සහ ආරක්ෂාවට බලපෑම් කිරීමට හැකියාවක් ඇත. නිෂ්පාදක හෝ ක්‍රියාකරු විසින් දෘඩාංග-විශේෂිත දෝෂ නිර්ණය සඳහා පමණක් මෙය යොදාගත යුතුය."</string>
-    <string name="permlab_changeComponentState" msgid="6335576775711095931">"යෙදුම් අංග සබල හෝ අබල කිරීම"</string>
-    <string name="permdesc_changeComponentState" product="tablet" msgid="8887435740982237294">"වෙනත් යෙදුමක අංගයක් සබල ද නැද්ද යන්න වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. වැදගත් ටැබ්ලට් අවශ්‍යතා අබල කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක. මෙම අවසරය සැලකිල්ලෙන් භාවිතා කළ යුතුය, භාවිත නොකරන, අස්ථිර හෝ අස්ථායි තත්වයට යෙදුම පත් කිරීමට එයට හැකිය."</string>
-    <string name="permdesc_changeComponentState" product="default" msgid="1827232484416505615">"වෙනත් යෙදුමක අංගයක් සබල ද නැද්ද යන්න වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. වැදගත් දුරකථන අවශ්‍යතා අක්‍රිය කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කළ හැක. මෙම අවසරය සැලකිල්ලෙන් භාවිත කළ යුතුය, භාවිත නොකරන, අස්ථිර හෝ අස්ථායි තත්වයට යෙදුම පත් කිරීමට එයට හැකිය."</string>
-    <string name="permlab_grantRevokePermissions" msgid="4627315351093508795">"අවසර ප්‍රදානය කිරීම හෝ අහෝසි කිරීම"</string>
-    <string name="permdesc_grantRevokePermissions" msgid="4088642654085850662">"යෙදුමකට එයට හෝ අනෙක් යෙදුම් වලට විශේෂිත අවසර ප්‍රදානයට හෝ අහෝසි කිරීමට අවසර දෙන්න. අනිෂ්ට යෙදුම්, ඒවාට අවසර ප්‍රදානය නොකළ ගුණාංග වලට ප්‍රවේශ වීමට මෙය භාවිතා කළ හැක."</string>
-    <string name="permlab_setPreferredApplications" msgid="8463181628695396391">"අභිරුචි යෙදුම් සකසන්න"</string>
-    <string name="permdesc_setPreferredApplications" msgid="4973986762241783712">"ඔබගේ අභිරුචි යෙදුම් වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ ධාවනය වන යෙදුම් වෙනස් කිරීම, පවතින යෙදුම් වලින් දත්ත එකතු කිරීම, ප්‍රෝඩා කිරීම වැනි දේ අනිෂ්ට යෙදුම් නිශ්ශබදවම සිදු කරයි."</string>
-    <string name="permlab_writeSettings" msgid="2226195290955224730">"පද්ධති සැකසීම් වෙනස් කිරීම"</string>
-    <string name="permdesc_writeSettings" msgid="7775723441558907181">"පද්ධති සැකසීම් දත්ත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. අනිෂ්ට යෙදුම් ඔබගේ පද්ධති වින්‍යාස දෝෂ ගැන්විය හැක."</string>
-    <string name="permlab_writeSecureSettings" msgid="204676251876718288">"ආරක්‍ෂිත පද්ධති සැකසීම් වෙනස් කරන්න"</string>
-    <string name="permdesc_writeSecureSettings" msgid="8159535613020137391">"පද්ධතියේ ආරක්‍ෂිත දත්ත වෙනස් කිරීමට උපාංගයට අවසර දෙන්න. සාමාන්‍ය උපාංග සඳහා භාවිතයට නොවේ."</string>
-    <string name="permlab_writeGservices" msgid="2149426664226152185">"Google සේවා සිතියම වෙනස් කරන්න"</string>
-    <string name="permdesc_writeGservices" msgid="1287309437638380229">"Google සේවා සිතියම වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා භාවිතයට නොවෙයි."</string>
-    <string name="permlab_receiveBootCompleted" msgid="5312965565987800025">"ආරම්භයේදී ධාවනය කිරීම"</string>
-    <string name="permdesc_receiveBootCompleted" product="tablet" msgid="7390304664116880704">"පද්ධතිය ඇරඹුම අවසන් වූ වහාම යෙදුම ආරම්භ වීමට යෙදුමට අවසර දෙන්න. ටැබ්ලටය ආරම්භ කිරීමට මෙමඟින් පමා කළ හැකි අතර සැමවිටම ධාවනය වන නිසා සම්පූර්ණ ටැබ්ලටයම ප්‍රමාද කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permdesc_receiveBootCompleted" product="default" msgid="513950589102617504">"පද්ධතිය ඇරඹුම අවසන් වූ වහාම යෙදුම ආරම්භ වීමට යෙදුමට අවසර දෙන්න. දුරකථනය ආරම්භ කිරීමට මෙමඟින් පමා කළ හැකි අතර සැමවිටම ධාවනය වන නිසා සම්පූර්ණ දුරකථනයේම ක්‍රියාකාරිත්වය ප්‍රමාද කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_broadcastSticky" msgid="7919126372606881614">"බැඳුණු විකාශනය යැවීම"</string>
-    <string name="permdesc_broadcastSticky" product="tablet" msgid="7749760494399915651">"ප්‍රචාරණයට පසුවද පවතින, ප්‍රචාරණයන් යැවීමට යෙදුමට අවසර දෙන්න. වැඩිපුර මතකය භාවිතය හේතු කොට, අධික භාවිතය මඟින් ටැබ්ලටය පමා කිරීම හෝ අස්ථිර කළ හැක."</string>
-    <string name="permdesc_broadcastSticky" product="default" msgid="2825803764232445091">"ප්‍රචාරණයට පසුවද පවතින, ප්‍රචාරණයන් යැවීමට යෙදුමට අවසර දෙන්න. වැඩිපුර මතකය භාවිතය හේතු කොට, අධික භාවිතය මඟින් දුරකථනය පමා කිරීම හෝ අස්ථිර කළ හැක."</string>
-    <string name="permlab_readContacts" msgid="8348481131899886131">"ඔබගේ සම්බන්ධතා කියවීම"</string>
-    <string name="permdesc_readContacts" product="tablet" msgid="5294866856941149639">"සඳහන් පුද්ගලයන් හට ඔබ ඇමතුම් ගත්, ඊ-තැපැල්, හෝ  අනෙකුත් ආකාර වලින් සන්නිවේදනය කරගත් සංඛ්‍යතද ඇතුළුව, ඔබගේ ටැබ්ලටයේ ගබඩාවී ඇති සම්බන්ධතා පිළිබඳ දත්ත කියවීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් යෙදුම්වලට ඔබගේ සම්බන්ධතා පිළිබඳ දත්ත සුරැකීමට ඉඩ ලබා දෙන අතර, අනිෂ්ට යෙදුම් විසින් ඔබ නොදැනුවත්වම සම්බන්ධතා දත්ත බෙදා ගැනීමට ඉඩ ඇත."</string>
-    <string name="permdesc_readContacts" product="default" msgid="8440654152457300662">"නියමිත පුද්ගලයන් සමග ඔබ ඇමතු, ඊ-තැපැල් කළ හෝ වෙනත් ආකාරයකින් සන්නිවේදනය කළ සංඛ්‍යාතය ඇතුලත් ඔබගේ දුරකථනයේ ආචයනය කරන ලද ඔබගේ සම්බන්ධතා ගැන දත්ත කියවීමට යෙදුමට අවසර දෙන්න. ඔබගේ සම්බන්ධතා දත්ත උපස්ථ කිරීමට මෙම අවසරය යෙදුමට අවසර දෙන අතර ඔබගේ දැනුමකින් තොරව අනිෂ්ට යෙදුම් සම්බන්ධතා දත්ත බෙදාගැනීම කළ හැක."</string>
-    <string name="permlab_writeContacts" msgid="5107492086416793544">"ඔබගේ සම්බන්ධතා වෙනස් කිරීම"</string>
-    <string name="permdesc_writeContacts" product="tablet" msgid="897243932521953602">"නියමිත පුද්ගලයන්ට ඔබ ඇමතූ, ඊ-තැපැල් කළ හෝ ඇමතුම් කළ සංඛ්‍යාත ඇතුලත් ඔබගේ ටැබ්ලටයේ ආචයනය කරන ලද සම්බන්ධතා (ලිපින) දත්ත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙන් යෙදුමට සම්බන්ධතා දත්ත මැකීමට අවසර දෙයි."</string>
-    <string name="permdesc_writeContacts" product="default" msgid="589869224625163558">"සඳහන් පුද්ගලයන්ට ඔබ ඇමතූ, ඊ-තැපැල් කළ හෝ ඇමතුම් කළ සංඛ්‍යාන ඇතුලත් ඔබගේ දුරකථනයේ ආචයනය කරන ලද සම්බන්ධතා (ලිපින) දත්ත වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරයෙන් යෙදුමට සම්බන්ධතා දත්ත මැකීමට අවසර දෙයි."</string>
-    <string name="permlab_readCallLog" msgid="3478133184624102739">"ඇමතුම් ලොගය කියවන්න"</string>
-    <string name="permdesc_readCallLog" product="tablet" msgid="3700645184870760285">"පැමිණෙන සහ පිටවන ඇමතුම් ගැන දත්ත ඇතුළත්, ඔබගේ ටැබ්ලටයේ ඇමතුම් ලොග කියවීමට යෙදුමට අවසර දෙන්න. ඔබගේ ඇමතුම් ලොග දත්ත සුරක්ෂිත කිරීමට මෙම අවසරය යෙදුම්වලට අවසර දෙයි සහ ඔබගේ දැනුමකින් තොරව ඇමතුම් ලොග දත්ත අනිෂ්ට යෙදුම් බෙදා ගැනීම කළ හැක."</string>
-    <string name="permdesc_readCallLog" product="default" msgid="5777725796813217244">"ලැබෙන සහ පිටවන ඇමතුම් පිළිබඳ දත්ත ඇතුළත්ව ඔබගේ දුරකථනයේ ඇමතුම් ලොග් කියවීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය ඔබගේ ඇමතුම් ලොග් දත්ත උපස්ථ කිරීමට යෙදුමට ඉඩදෙන අතර ඔබගේ අනුදැනුමකින් තොරව අනිෂ්ට යෙදුම් විසින් ඇමතුම් ලොග් දත්ත බෙදාගැනීම කළ හැක."</string>
-    <string name="permlab_writeCallLog" msgid="8552045664743499354">"ඇමතුම් ලොගය ලිවීම"</string>
-    <string name="permdesc_writeCallLog" product="tablet" msgid="6661806062274119245">"ලැබෙන ඇමතුම් සහ පිටවන ඇමතුම් දත්ත ඇතුළත්ව ඔබගේ ටැබ්ලටයේ ඇමතුම් ලොගය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ ඇමතුම් ලොගය මැකීමට හෝ වෙනස් කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිතා කෙරේ."</string>
-    <string name="permdesc_writeCallLog" product="default" msgid="683941736352787842">"පැමිණෙන සහ පිටවෙන ඇමතුම් දත්ත ඇතුළුව ඔබගේ දුරකථනයේ ඇමතුම් ලොගය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ ඇමතුම් ලොගය මැකීමට හෝ වෙනස් කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කල හැක."</string>
-    <string name="permlab_readProfile" msgid="4701889852612716678">"ඔබගේ සම්බන්ධතා පත කියවන්න"</string>
-    <string name="permdesc_readProfile" product="default" msgid="5462475151849888848">"ඔබගේ නම සම්බන්ධතා තොරතුරු ආදී ඔබගේ උපාංගයේ ගබඩා වී ඇති පුද්ගලික පැතිකඩ තොරතුරු කියවීමට යෙදුමට අවසර දෙන්න. මෙහි තේරුම යෙදුමට ඔබව හඳුනා ගැනීමට හැකි වන බව සහ ඔබගේ පුද්ගලික තොරතුරු අනෙක් අයට යැවීමට ද හැකි වීමයි."</string>
-    <string name="permlab_writeProfile" msgid="907793628777397643">"ඔබගේ සම්බන්ධතා පත වෙනස් කිරීම"</string>
-    <string name="permdesc_writeProfile" product="default" msgid="5552084294598465899">"ඔබගේ නම සහ සම්බන්ධතා තොරතුරු වැනි ඔබගේ උපාංගයේ ආචයනය කරන ලද පුද්ගලික පැතිකඩ තොරතුරු වෙනස් කිරීමට හෝ එකතු කිරීමට යෙදුමට අවසර දෙන්න. මෙමගින් යෙදුමට ඔබව හඳුනා ගත හැකි අතර අනෙක් අයට ඔබගේ පැතිකඩ තොරතුරු යැවිය හැකි බව කියවෙයි."</string>
-    <string name="permlab_readSocialStream" product="default" msgid="1268920956152419170">"ඔබගේ සමාජ ප්‍රවාහය කියවන්න"</string>
-    <string name="permdesc_readSocialStream" product="default" msgid="4255706027172050872">"ඔබගේ සහ ඔබගේ යහළුවන්ගේ සමාජ යාවත්කාලීනයන් වෙත පිවිසීමට හෝ සමමුහුර්ත කිරීමට යෙදුමට අවසර දෙන්න. තොරතුරු බෙදා ගැනීමේ දී සැලකිලිමත් වන්න -- විශ්වාසයකින් තොරව සමාජ ජාලවල ඔබගේ සහ ඔබගේ යහළුවන් අතර සන්නිවේදන කියවීමට මෙමගින් යෙදුමට අවසර දෙයි. සටහන: සියලු සමාජ ජාලවල මෙම අවසරය බල නොකරයි."</string>
-    <string name="permlab_writeSocialStream" product="default" msgid="3504179222493235645">"ඔබගේ සමාජ ප්‍රවාහය වෙත ලිවීම"</string>
-    <string name="permdesc_writeSocialStream" product="default" msgid="3086557552204114849">"ඔබගේ යහළුවන්ගේ සමාජ යාවත්කාලීනයන් පෙන්වීමට යෙදුමට අවසර දෙන්න. තොරතුරු බෙදා ගැනීමේදී සැලකිලිමත් වන්න -- යහළුවෙක්ගෙන් පැමිණෙන ලෙස පණිවිඩ නිපදවීමට මෙමඟින් යෙදුමට අවසර දෙන්න. සටහන : සියලු සමාජ ජාල සඳහා මෙම අවසරය බල නොදෙයි."</string>
-    <string name="permlab_readCalendar" msgid="5972727560257612398">"දින දර්ශනයේ සිදුවීම් සහ රහසිගත තොරතුරු කියවීම"</string>
-    <string name="permdesc_readCalendar" product="tablet" msgid="4216462049057658723">"ඔබගේ ටැබ්ලටය තුල ගබඩා  කර ඇති මිතුරන්ගේ සහ එක්ව ක්‍රියාකරන්නන්ගේ ද ඇතුළුව සියලුම දින දර්ශන සිද්ධි කියවීමට යෙදුමට අවසර දෙන්න. මෙය රහස්‍යභාවය හෝ සංවේදීතාවය නොසලකා ඔබගේ දින දර්ශන දත්ත බෙදා ගැනීමට හෝ සුරැකීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_readCalendar" product="default" msgid="7434548682470851583">"යහළුවන් සහ සමකාලිනයන් ඇතුලත් ඔබගේ දුරකථනයේ ආචයනය කරන ලද සියලු දින දර්ශන සිදුවීම් කියවීමට යෙදුමට අවසර දෙන්න. විශ්වාසයකින් හෝ සංවේදීතාවකින් තොරව ඔබගේ දින දර්ශන දත්ත බෙදා ගැනීමට හෝ උපස්ථ කිරීමට මෙමගින් යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_writeCalendar" msgid="8438874755193825647">"දින දර්ශන සිද්ධි එකතු කිරීම හෝ වෙනස් කිරීමක් සිදුකර හිමිකරුගේ දැනීමකින් තොරව අමුත්තන්ට ඊ-තැපෑලක් යවීම"</string>
-    <string name="permdesc_writeCalendar" product="tablet" msgid="6679035520113668528">"යහළුවන් හෝ එකට-වැඩකරන්නන් ඇතුළත්ව ඔබට ටැබ්ලටයේ වෙනස් කළ හැකි සිද්ධි එකතු කිරීමට, ඉවත් කිරීමට, වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙමඟින් දින දර්ශන හිමිකරුවන්ගෙන් පණිවිඩ යවන පරිදි මෙන් මවාපෑමට හෝ හිමිකරුගේ අනුදැනුමකින් තොරව සිද්ධි වෙනස් කිරීමට යෙදුමට අවසර ලැබේ."</string>
-    <string name="permdesc_writeCalendar" product="default" msgid="2324469496327249376">"ඔබගේ යහළුවන් හෝ සමකාලීනයන් ඇතුළත් ඔබගේ දුරකථනයේ ඔබට වෙනස් කළ හැකි සිදු වීම් එකතු කිරීමට, ඉවත් කිරීමට, වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. මෙමගින් දින දර්ශන හිමිකරුවන්ගෙන් පැමිණෙන සේ පෙනෙන පණිවිඩ යැවීමට හෝ හිමිකරුගේ දැනුමකින් තොරව සිදුවීම් වෙනස් කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_accessMockLocation" msgid="8688334974036823330">"පරීක්ෂණ සඳහා ආදර්ශ ස්ථාන මූලාශ්‍ර"</string>
-    <string name="permdesc_accessMockLocation" msgid="5808711039482051824">"පරීක්ෂණයට ව්‍යාජ ස්ථාන මූලාශ්‍ර සාදන්න හෝ නව ස්ථාන සැපයුම්කරුවෙකු ස්ථාපනය කරන්න. GPS හෝ ස්ථාන සැපයුම්කරුවන් ආදී වෙනත් ස්ථාන මූලාශ්‍ර විසින් ලබා දෙන ස්ථානය සහ/හෝ තත්වය ප්‍රතිස්ථාපනය කිරීමට යෙදුමට මෙය අවසර දෙයි."</string>
-    <string name="permlab_accessLocationExtraCommands" msgid="2836308076720553837">"අමතර ස්ථාන සැපයුම්කරු විධාන වෙත ප්‍රවේශ වීම"</string>
-    <string name="permdesc_accessLocationExtraCommands" msgid="5945166642335800763">"අමතර ස්ථාන සැපයුම්කරු විධාන වෙත පිවිසීමට යෙදුමට අවසර දෙන්න. GPS හෝ වෙනත් ස්ථාන මූලාශ්‍ර ක්‍රියාවලි වෙත බාධා කිරීමට මෙය අවසර දෙයි."</string>
-    <string name="permlab_installLocationProvider" msgid="6578101199825193873">"ස්ථාන සැපයුම්කරුවෙකු ස්ථාපනයට අවසරය දෙන්න"</string>
-    <string name="permdesc_installLocationProvider" msgid="9066146120470591509">"පරීක්ෂණයට ව්‍යාජ ස්ථාන මූලාශ්‍ර සාදන්න හෝ නව ස්ථාන සැපයුම්කරුවෙකු ස්ථාපනය කරන්න. GPS හෝ ස්ථාන සැපයුම්කරුවන් ආදී වෙනත් ස්ථාන මූලාශ්‍ර විසින් ලබා දෙන ස්ථානය සහ/හෝ තත්ත්වය ප්‍රතිස්ථාපනය කිරීමට යෙදුමට මෙය අවසර දෙයි."</string>
-    <string name="permlab_accessFineLocation" msgid="1191898061965273372">"නිවැරදි ස්ථානය (GPS සහ ජාලය පදනම් කරගත්)"</string>
-    <string name="permdesc_accessFineLocation" msgid="5295047563564981250">"ගෝලීය ස්ථානීය පද්ධතිය (GPS) හෝ සෙල් කුළුණු සහ Wi-Fi වැනි ජාල ස්ථානීය ප්‍රභව භාවිතයෙන් ඔබගේ නිවැරදි ස්ථානය ලබාගැනීමට යෙදුම අවසර දෙන්න. යෙදුම් වලට ස්ථානීය සේවා භාවිතා කිරීමට  ඒවා සක්‍රිය විය යුතු වේ. ඔබව සොයා ගැනීමට යෙදුම් මෙය භාවිතා කරන අතර අමතර බැටරි බලයක්ද පරිභෝජනය කරයි."</string>
-    <string name="permlab_accessCoarseLocation" msgid="4887895362354239628">"ආසන්නතම ස්ථානය (ජාලය-පාදක වූ)"</string>
-    <string name="permdesc_accessCoarseLocation" msgid="2538200184373302295">"ඔබගේ දළ ස්ථානය ලබාගැනීමට යෙදුමට අවසර දෙන්න. සන්නේවේදන කුළුණු සහ Wi-Fi ආදී ජාල ස්ථාන මූලාශ්‍ර භාවිත කරන ස්ථාන සේවා විසින් මෙම ස්ථානය ව්‍යුත්පන්න කර ඇත. යෙදුමට භාවිතය සඳහා මෙම ස්ථාන සේවා සක්‍රිය කළ යුතු අතර ඔබගේ උපාංගය සඳහා පැවතිය යුතුය. ඔබ සිටින තැන දළව හඳුනා ගැනීමට යෙදුම් වලට මෙය භාවිත කළ හැකිය."</string>
-    <string name="permlab_accessSurfaceFlinger" msgid="2363969641792388947">"SurfaceFlinger වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_accessSurfaceFlinger" msgid="1041619516733293551">"SurfaceFlinger පහල මට්ටමේ විශේෂාංග භාවිතයට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_readFrameBuffer" msgid="6690504248178498136">"රාමු අන්තරාචය කියවීම"</string>
-    <string name="permdesc_readFrameBuffer" msgid="4937405521809454680">"රාමු අන්තරාචයනයෙන් අන්තර්ගතයන් කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessInputFlinger" msgid="5348635270689553857">"InputFlinger වෙත පිවිසෙන්න"</string>
-    <string name="permdesc_accessInputFlinger" msgid="2104864941201226616">"InputFlinger පහල මට්ටමේ විශේෂාංග භාවිතයට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_configureWifiDisplay" msgid="5595661694746742168">"Wifi සංදර්ශක වින්‍යාස කරන්න"</string>
-    <string name="permdesc_configureWifiDisplay" msgid="7916815158690218065">"වින්‍යාස කිරීමට සහ Wifi සංදර්ශක වෙත සම්බන්ධ වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_controlWifiDisplay" msgid="393641276723695496">"Wifi සංදර්ශක පාලනය"</string>
-    <string name="permdesc_controlWifiDisplay" msgid="4543912292681826986">"Wifi සංදර්ශකයේ පහළ මට්ටමේ විශේෂාංග පාලනයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_captureAudioOutput" msgid="6857134498402346708">"ශබ්ද ප්‍රතිදානය ග්‍රහණය"</string>
-    <string name="permdesc_captureAudioOutput" msgid="6210597754212208853">"යෙදුමට ශබ්ද ප්‍රතිදානය ග්‍රහණය කර හරවා යැවීමට ඉඩ දේ."</string>
-    <string name="permlab_captureVideoOutput" msgid="2246828773589094023">"වීඩියෝ ප්‍රතිදානය"</string>
-    <string name="permdesc_captureVideoOutput" msgid="359481658034149860">"යෙදුමට වීඩියෝ ප්‍රතිදානය ග්‍රහණය කර හරවා යැවීමට ඉඩ දේ."</string>
-    <string name="permlab_captureSecureVideoOutput" msgid="7815398969303382016">"ආරක්‍ෂිත වීඩියෝ ප්‍රතිදානය"</string>
-    <string name="permdesc_captureSecureVideoOutput" msgid="2779793064709350289">"යෙදුමට ආරක්‍ෂිත වීඩියෝ ප්‍රතිදානය ග්‍රහණය කර හරවා යැවීමට ඉඩ දේ."</string>
-    <string name="permlab_modifyAudioSettings" msgid="6095859937069146086">"ඔබගේ ශ්‍රව්‍ය සැකසීම් වෙනස් කරන්න"</string>
-    <string name="permdesc_modifyAudioSettings" msgid="3522565366806248517">"ශබ්දය ආදී ගෝලීය ශබ්ද සැකසීම් වෙනස් කිරීමට සහ ප්‍රතිදානය සඳහා භාවිත කරන්නේ කුමන නාදකය දැයි තේරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_recordAudio" msgid="3876049771427466323">"ශබ්ද පටිගත කරන්න"</string>
-    <string name="permdesc_recordAudio" msgid="4906839301087980680">"මයික්‍රොෆෝනය මඟින් ශබ්ද පටිගත කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් යෙදුමට ඕනෑම වේලාවක ඔබගේ අනුදැනුමකින් තොරව ශබ්ද පටිගත කිරීමට ඉඩ ලබා දේ."</string>
-    <string name="permlab_camera" msgid="3616391919559751192">"පින්තූර සහ වීඩියෝ ගන්න"</string>
-    <string name="permdesc_camera" msgid="8497216524735535009">"කැමරාවෙන් පින්තූර ගැනීමට සහ වීඩියෝ කිරීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය මඟින් ඔබගේ අනුදැනුමකින් තොරව ඕනෑම වේලාවකදී කැමරාව භාවිතා කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_cameraDisableTransmitLed" msgid="2651072630501126222">"කැමරාව භාවිතයේදී LED දර්ශක සම්ප්‍රේෂණය අබල කරන්න"</string>
-    <string name="permdesc_cameraDisableTransmitLed" msgid="4764585465480295341">"කැමරා භාවිතය පිළිබඳ LED දර්ශකය අක්‍රිය කිරීමට, කලින් පිහිටුවා ඇති පද්ධති යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_brick" product="tablet" msgid="2961292205764488304">"ටැබ්ලටය ස්ථිරවම අබල කිරීම"</string>
-    <string name="permlab_brick" product="default" msgid="8337817093326370537">"දුරකථනය ස්ථිරව අබල කිරීම"</string>
-    <string name="permdesc_brick" product="tablet" msgid="4334818808001699530">"මුළු ටැබ්ලටයම ස්ථිරවම අක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. මෙය ඉතා භයානකයි."</string>
-    <string name="permdesc_brick" product="default" msgid="5788903297627283099">"මුළු දුරකථනයම ස්ථිරවම අක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න. මෙය ඉතා භයානකයි."</string>
-    <string name="permlab_reboot" product="tablet" msgid="3436634972561795002">"ටැබ්ලට් නැවත පණ ගැන්වීමට බල කරන්න"</string>
-    <string name="permlab_reboot" product="default" msgid="2898560872462638242">"දුරකථන නැවත පණ ගැන්වීමට බල කරන්න"</string>
-    <string name="permdesc_reboot" product="tablet" msgid="8172056180063700741">"ටැබ්ලටය නැවත බල ගැන්වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_reboot" product="default" msgid="5326008124289989969">"ටැබ්ලටය නැවත ඇරඹීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_mount_unmount_filesystems" product="nosdcard" msgid="2927361537942591841">"USB ආචයනය ගොනු පද්ධතිය ප්‍රවේශ කිරීම"</string>
-    <string name="permlab_mount_unmount_filesystems" product="default" msgid="4402305049890953810">"SD පත් ගොනු පද්ධතිය ප්‍රවේශ කිරීම"</string>
-    <string name="permdesc_mount_unmount_filesystems" msgid="1829290701658992347">"ඉවත් කළ හැකි ආචයනය සඳහා ගොනු පද්ධති ඈඳීමට සහ ගැලවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_mount_format_filesystems" product="nosdcard" msgid="6227819582624904972">"USB ආචයනය මකන්න"</string>
-    <string name="permlab_mount_format_filesystems" product="default" msgid="262582698639274056">"SD පත මකන්න"</string>
-    <string name="permdesc_mount_format_filesystems" msgid="8784268246779198627">"ඉවත් කළ හැකි ආචයන ෆෝමැට් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_access" msgid="3411338632002193846">"අභ්‍යන්තර ආචයනය පිළිබඳ තොරතුරු ලබා ගැනීම"</string>
-    <string name="permdesc_asec_access" msgid="3094563844593878548">"අභ්‍යන්තර ආචයනයේ තොරතුරු ලබාගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_create" msgid="6414757234789336327">"අභ්‍යන්තර ආචයනය නිර්මාණය"</string>
-    <string name="permdesc_asec_create" msgid="4558869273585856876">"අභ්‍යන්තර ආචයනය සැදීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_destroy" msgid="526928328301618022">"අභ්‍යන්තර ආචයනය විනාශ කිරීම"</string>
-    <string name="permdesc_asec_destroy" msgid="7218749286145526537">"අභ්‍යන්තර ආචයනය විනාශ කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_mount_unmount" msgid="8877998101944999386">"අභ්‍යන්තර ආචයනය නංවීම/ගැලවීම"</string>
-    <string name="permdesc_asec_mount_unmount" msgid="3451360114902490929">"අභ්‍යන්තර ආචයනය සවි කිරීමට/ගැලවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_asec_rename" msgid="7496633954080472417">"අභ්‍යන්තර ආචයනය නැවත නම් කරන්න"</string>
-    <string name="permdesc_asec_rename" msgid="1794757588472127675">"අභ්‍යන්තර ආචයනය නැවත නම් කිරීමට යෙදුමට අවසර දෙන්න."</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_manageUsb" msgid="1113453430645402723">"USB උපාංග සඳහා කැමැත්ත සහ අවසර කළමනාකරණය කිරීම"</string>
-    <string name="permdesc_manageUsb" msgid="7776155430218239833">"USB උපාංග සඳහා අභිරුචි සහ අවසර කළමනාකරණයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessMtp" msgid="4953468676795917042">"MTP ප්‍රොටොකෝලය ක්‍රියාත්මක කිරීම"</string>
-    <string name="permdesc_accessMtp" msgid="6532961200486791570">"MTP USB ප්‍රොටෝකෝලය ක්‍රියාත්මක කිරීමට කර්නල MTP ධාවකයට ප්‍රවේශ වීමට අවසර දෙන්න."</string>
-    <string name="permlab_hardware_test" msgid="4148290860400659146">"දෘඩාංග පරීක්ෂණය කරන්න"</string>
-    <string name="permdesc_hardware_test" msgid="6597964191208016605">"දෘඩාංග පරීක්ෂා කිරීමේ අරමුණ සඳහා යෙදුමට විවිධ පර්යන්ත පාලනය කිරීමට ඉඩ දෙන්න."</string>
-    <string name="permlab_callPhone" msgid="3925836347681847954">"දුරකථන අංක වෙත ඍජුවම අමතන්න"</string>
-    <string name="permdesc_callPhone" msgid="3740797576113760827">"ඔබගේ මැදිහත් වීමක් නොමැතිව දුරකථන අංක ඇමතීමට යෙදුමට අවසර දෙන්න. මෙහි ප්‍රතිඑලය වන්නේ අනපේක්ෂිත අයකිරීම් හෝ ඇමතුම් ඇතිවීමයි. මෙයන් හදිසි අංක වලට ඇමතුම් ගැනීමට යෙදුමට අවසර නොදෙන බවට සටහන් කරගන්න. ඔබගේ අනුදැනුමක් නොමැතිව ඇමතුම් ගැනීමෙන් අනිෂ්ට යෙදුම් ඔබගේ මුදල් නිකරුණේ වැය කරයි."</string>
-    <string name="permlab_callPrivileged" msgid="4198349211108497879">"ඕනෑම දුරකථන අංකයකට ඍජුවම අමතන්න"</string>
-    <string name="permdesc_callPrivileged" msgid="1689024901509996810">"ඔබගේ මැදිහත්වීමකින් තොරව හදිසි අංක ඇතුළත්ව ඕනෑම දුරකථන අංකයකට ඇමතීමට යෙදුමට අවසර දෙන්න. හදිසි සේවා වෙත අනවශ්‍ය සහ නීතිමය නොවන ඇමතුම ලැබීමට අනිෂ්ට යෙදුම සිදු කළ හැක."</string>
-    <string name="permlab_performCdmaProvisioning" product="tablet" msgid="4842576994144604821">"CDMA ටැබ්ලට පිහිටුම සෘජුව ඇරඹීම"</string>
-    <string name="permlab_performCdmaProvisioning" product="default" msgid="5604848095315421425">"CDMA දුරකථන පිහිටුම සෘජුව ඇරඹීම"</string>
-    <string name="permdesc_performCdmaProvisioning" msgid="1994193538802314186">"යෙදුමට CDMA ප්‍රතිපාදන ආරම්භ කිරීමට ඉඩදෙන්න. අනිෂ්ට යෙදුම් අනවශ්‍ය ලෙස CDMA ප්‍රතිපාදන ආරම්භ කළ හැක."</string>
-    <string name="permlab_locationUpdates" msgid="7785408253364335740">"ස්ථාන යාවත්කාලීන දැනුම්දීම් පාලනය කරන්න"</string>
-    <string name="permdesc_locationUpdates" msgid="1120741557891438876">"ස්ථානීය යාවත්කාලින දැනුම්දීම් රේඩියෝවෙන් සබල/අබල කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_checkinProperties" msgid="7855259461268734914">"පිරික්සුම් ගුණාංග වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_checkinProperties" msgid="4024526968630194128">"පිරික්සුම් සේවාව මගින් උත්ශ්‍රේණි කළ ගුණාංග වෙත කියවීම්/ලිවීම් පිවිසුම සඳහා යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් වල භාවිතයට නොවේ."</string>
-    <string name="permlab_bindGadget" msgid="776905339015863471">"විජට් තෝරන්න"</string>
-    <string name="permdesc_bindGadget" msgid="8261326938599049290">"කුමන විජටය කුමන යෙදුමෙන් භාවිතා කල හැකිද යන්න පද්ධතියට පැවසීමට යෙදුමට අවසර දෙන්න. මෙම අවසරය ඇති යෙදුමකට අනෙක් යෙදුම්වලට පුද්ගලික දත්ත වලට ප්‍රවේශය ලබා දිය හැක. සාමාන්‍ය යෙදුම් වල භාවිතයට නොවේ."</string>
-    <string name="permlab_modifyPhoneState" msgid="8423923777659292228">"දුරකථනයේ තත්වය වෙනස් කිරීම"</string>
-    <string name="permdesc_modifyPhoneState" msgid="1029877529007686732">"උපාංගයේ දුරකථන විශේෂාංග පාලනයට යෙදුමට අවසර දෙන්න. මෙම අවසරය ඇති යෙදුමට ඔබට නිවේදනයෙන් තොරව ජාල මාරු කිරීම, දුරකථන රේඩියෝව සක්‍රිය සහ අක්‍රිය කිරීම කළ හැක."</string>
-    <string name="permlab_readPhoneState" msgid="9178228524507610486">"දුරකථනයේ තත්වය සහ අනන්‍යතාවය කියවීම"</string>
-    <string name="permdesc_readPhoneState" msgid="1639212771826125528">"උපාංගයේ දුරකථන විශේෂාංග වෙත පිවිසීමට යෙදුමට අවසර දෙන්න. ඇමතුම සක්‍රිය වුවත් සහ ඇමතුමකින් දුරස්ථ අංකය සම්බන්ධ වුවත් දුරකථන අංකය සහ උපාංග ID හඳුනා ගැනීමට මෙම අවසරය යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_wakeLock" product="tablet" msgid="1531731435011495015">"ටැබ්ලටය නින්දෙන් වැළක්වීම"</string>
-    <string name="permlab_wakeLock" product="default" msgid="573480187941496130">"දුරකථනය නින්දට යාමෙන් වළකන්න"</string>
-    <string name="permdesc_wakeLock" product="tablet" msgid="7311319824400447868">"ටැබ්ලටය නින්දට යාමෙන් වැලැක්වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_wakeLock" product="default" msgid="8559100677372928754">"දුරකථනය නින්දට යාමෙන් වැලැක්වීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_devicePower" product="tablet" msgid="2787034722616350417">"ටැබ්ලටය සක්‍රිය හෝ අක්‍රිය කරන්න"</string>
-    <string name="permlab_devicePower" product="default" msgid="4928622470980943206">"දුරකථනය බල ගැන්වීම හෝ වැසීම"</string>
-    <string name="permdesc_devicePower" product="tablet" msgid="6689862878984631831">"ටැබ්ලටය සක්‍රිය හෝ අක්‍රිය කිරීමට යෙදුමට අවසර දේ."</string>
-    <string name="permdesc_devicePower" product="default" msgid="6037057348463131032">"දුරකථනය සක්‍රිය සහ අක්‍රිය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_factoryTest" msgid="3715225492696416187">"කර්මාන්තශාලා පරීක්ෂණ ආකාරය තුළ ධාවනය කරන්න"</string>
-    <string name="permdesc_factoryTest" product="tablet" msgid="3952059318359653091">"ටැබ්ලටයේ දෘඩාංග වෙත සම්පූර්ණ පිවිසුම සඳහා අවසර දීමෙන් පහළ මට්ටමේ නිපැවුම්කරු පරීක්ෂණයක් ලෙස ධාවනය කරන්න. නිපැවුම්කරු පරීක්ෂණ ආකාරයෙන් ටැබ්ලටයේ ධාවනය වන විට පමණි."</string>
-    <string name="permdesc_factoryTest" product="default" msgid="8136644990319244802">"දුරකථනයේ දෘඩාංග වෙත සම්පූර්ණ පිවිසුම සඳහා අවසර දීමෙන් පහළ මට්ටමේ නිපැවුම්කරු පරීක්ෂණයක් ලෙස ධාවනය කරන්න. නිපැවුම්කරු පරීක්ෂණ ආකාරයෙන් දුරකථනයේ ධාවනය වන විට පමණි."</string>
-    <string name="permlab_setWallpaper" msgid="6627192333373465143">"බිතුපත සැකසීම"</string>
-    <string name="permdesc_setWallpaper" msgid="7373447920977624745">"පද්ධති බිතුපත සැකසීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_setWallpaperHints" msgid="3278608165977736538">"ඔබගේ බිතුපතේ ප්‍රමාණය සැකසීම"</string>
-    <string name="permdesc_setWallpaperHints" msgid="8235784384223730091">"පද්ධති බිතුපතේ ප්‍රමාණ ඉඟි සකස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_masterClear" msgid="2315750423139697397">"කර්මාන්තශාලා සුපුරුද්දට පද්ධතිය නැවත සකස් කිරීම"</string>
-    <string name="permdesc_masterClear" msgid="3665380492633910226">"සියලු දත්ත මැකීමෙන්, වින්‍යාස කිරීමෙන් සහ යෙදුම් ස්ථාපනයෙන් එහි කර්මාන්ත ශාලා සැකසීම් වෙත පද්ධතිය නැවත සැකසීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_setTime" msgid="2021614829591775646">"වේලාව සැකසීම"</string>
-    <string name="permdesc_setTime" product="tablet" msgid="1896341438151152881">"ටැබ්ලට ඔරලෝසුවේ වේලාව වෙනස් කිරීමට යෙදුමට ඉඩ දෙන්න."</string>
-    <string name="permdesc_setTime" product="default" msgid="1855702730738020">"දුරකථන ඔරලෝසුවේ වේලාව වෙනස් කිරීමට යෙදුමකට ඉඩ දෙන්න."</string>
-    <string name="permlab_setTimeZone" msgid="2945079801013077340">"වේලා කලාපය සැකසීම"</string>
-    <string name="permdesc_setTimeZone" product="tablet" msgid="1676983712315827645">"ටැබ්ලටයේ කාල කලාපය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_setTimeZone" product="default" msgid="4499943488436633398">"දුරකථනයේ වේලා කලාපය වෙනස් කිරීමට උපාංගයට අවසර දෙන්න."</string>
-    <string name="permlab_accountManagerService" msgid="4829262349691386986">"AccountManagerService ලෙස පෙනී සිටින්න"</string>
-    <string name="permdesc_accountManagerService" msgid="1948455552333615954">"AccountAuthenticators වෙත ඇමතුම් ගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_getAccounts" msgid="1086795467760122114">"උපාංගයේ ඇති ගිණුම් සොයන්න"</string>
-    <string name="permdesc_getAccounts" product="tablet" msgid="2741496534769660027">"ටැබ්ලටය විසින් දන්නා ගිණුම් ලැයිස්තුවක් ලබාගැනීමට යෙදුමට අවසර දෙන්න. ඔබ ස්ථාපනය කොට ඇති යෙදුම් විසින් සාදා ඇති ගිණුම් මීට ඇතුළත් වේ."</string>
-    <string name="permdesc_getAccounts" product="default" msgid="3448316822451807382">"දුරකථනය විසින් දන්නා ගිණුම් ලැයිස්තුවක් ලබාගැනීමට යෙදුමට අවසර දෙන්න. ඔබ ස්ථාපනය කොට ඇති යෙදුම් විසින් සාදා ඇති ගිණුම් මීට ඇතුළත් වේ."</string>
-    <string name="permlab_authenticateAccounts" msgid="5265908481172736933">"ගිණුම් සාදන්න සහ මුරපද සකසන්න"</string>
-    <string name="permdesc_authenticateAccounts" msgid="5472124296908977260">"ගිණුම් සැදීමට සහ රහස් පද ලබාගැනීම සහ සැකසීම් කිරීම ඇතුළත්ව AccountManager ගේ ගිණුම් සත්‍යාපන හැකියාවන් භාවිතා කිරීමට යෙදුමකට අවසර දෙන්න."</string>
-    <string name="permlab_manageAccounts" msgid="4983126304757177305">"ගිණුම් එකතු කරන්න හෝ ඉවත් කරන්න"</string>
-    <string name="permdesc_manageAccounts" msgid="8698295625488292506">"ගිණුම් එකතු කිරීම, සහ ඉවත් කිරීම සහ ඔවුන්ගේ මුරපද මැකීම ආදී ක්‍රියාවලි සිදු කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_useCredentials" msgid="235481396163877642">"උපාංගයේ ඇති ගිණුම් භාවිතා කිරීම"</string>
-    <string name="permdesc_useCredentials" msgid="7984227147403346422">"සත්‍යාපන ටෝකන ඉල්ලීම සඳහා යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessNetworkState" msgid="4951027964348974773">"ජාල සම්බන්ධතාවයන් බැලීම"</string>
-    <string name="permdesc_accessNetworkState" msgid="8318964424675960975">"කුමන ජාල පවතින්නේ ද සහ සම්බන්ධිත ද ආදී ජාල සබඳතා ගැන තොරතුරු බැලීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_createNetworkSockets" msgid="8018758136404323658">"සම්පූර්ණ ජාල ප්‍රවේශය"</string>
-    <string name="permdesc_createNetworkSockets" msgid="3403062187779724185">"උපකරණයට ජාල කෙවනියන් සැදීමට සහ ජාල ප්‍රොටෝකෝල අභිරුචි භාවිතා කිරීමට උපකරණයට ඉඩ දෙන්න. අන්තර්ජාලයට දත්ත යැවීමට විධියන් බ්‍රව්සරය සහ අනෙකුත් යෙදුම් සපයයි, එනිසා මෙම අවසරය දත්ත අන්තර්ජාලයට යැවීමට අවශ්‍ය නොවේ."</string>
-    <string name="permlab_writeApnSettings" msgid="505660159675751896">"ජාලයේ සැකසීම් සහ ගමනාගමන වෙනස් කරන්න/අල්ලා ගැනීම"</string>
-    <string name="permdesc_writeApnSettings" msgid="5333798886412714193">"ඕනෑම APN එකක නියුතුව සහ තොට වෙනස් කිරීම වැනි ජාල සැකසීම් වෙනස් කිරීමට සහ සියලුම ජාල අතුරු ඇරීමට සහ සෝදිසි කිරීමට යෙදුමට අවසර දෙන්න. ඇතැම්විට ඔබගේ අනුදැනුමකින් තොරව අනිෂ්ට උපාංග ජාල පැකැට්ටු අධීක්ෂණය,ආපසු දිශාගත කිරීම හෝ වෙනස්කිරීම සිදු කිරීමට ඉඩ තිබේ."</string>
-    <string name="permlab_changeNetworkState" msgid="958884291454327309">"ජාල සම්බන්ධතාව වෙනස් කිරීම"</string>
-    <string name="permdesc_changeNetworkState" msgid="6789123912476416214">"ජාල සම්බන්ධතාවයේ තත්වය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_changeTetherState" msgid="5952584964373017960">"ටෙදර් කරන ලද සම්බන්ධතා වෙනස් කිරීම"</string>
-    <string name="permdesc_changeTetherState" msgid="1524441344412319780">"ටෙදර් කළ ජාල සම්බන්ධතාවයේ තත්වය වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_changeBackgroundDataSetting" msgid="1400666012671648741">"පසුබිම් දත්ත භාවිත සැකසීම් වෙනස් කිරීම"</string>
-    <string name="permdesc_changeBackgroundDataSetting" msgid="5347729578468744379">"පසුබිම් දත්ත භාවිතා සැකසීම වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_accessWifiState" msgid="5202012949247040011">"Wi-Fi සම්බන්ධතාවන් බැලීම"</string>
-    <string name="permdesc_accessWifiState" msgid="5002798077387803726">"Wi-Fi සබල බව සහ සම්බන්ධිත Wi-Fi උපාංග වල නම් ආදී Wi-Fi ජාලකරණයේ තොරතුරු බැලීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_changeWifiState" msgid="6550641188749128035">"Wi-Fi වලට සම්බන්ධ විම සහ විසන්ධි කිරීම"</string>
-    <string name="permdesc_changeWifiState" msgid="7137950297386127533">"Wi-Fi ප්‍රවේශ ස්ථානයන් වෙත සම්බන්ධ වීමට සහ විසන්ධි වීමට සහ, Wi-Fi ජාල සඳහා උපාංගයේ වින්‍යාසයට වෙනස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_changeWifiMulticastState" msgid="1368253871483254784">"Wi-Fi බහුවිකාශන පිළිගැනීමට අවසර දෙන්න"</string>
-    <string name="permdesc_changeWifiMulticastState" product="tablet" msgid="7969774021256336548">"ඔබගේ ටැබ්ලටයට පමණක් නොව Wi-Fi ජාලයේ ඇති සියලුම උපාංගවලට යැවූ පැකැට්ටු බහු විකාශ ලිපින භාවිතයෙන් ලබාගැනීමට යෙදුමට අවසර දෙන්න. non-multicast ආකාරයට වඩා වැඩි බලයක් මෙහිදී භාවිතා වේ."</string>
-    <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"ඔබගේ දුරකථනයට පමණක් නොව Wi-Fi ජාලයේ ඇති සියලුම යෙදුම්වලට යැවූ පැකැට්ටු බහුවාහක ලිපින භාවිතයෙන් ලබාගැනීමට යෙදුමට අවසර ලැබේ. බහුවාහක නැති ආකාරයට වඩා වැඩි බලයක් මෙහිදී භාවිතා වේ."</string>
-    <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"බ්ලූටූත් සැකසීම් ප්‍රවේශය"</string>
-    <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"ස්ථානීය බ්ලූටූත් ටැබ්ලට්යක් සැකසීමට සහ වින්‍යාස කිරීමට සහ දුරස්ථ උපාංග සමග යුගළ කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"දුරකථනයේ පෙදෙසි බ්ලූටූත් වින්‍යාස කිරීමට, සහ දුරස්ථ උපාංග ගවේෂණයට සහ යුගල වීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX වෙතට සම්බන්ධ කරන්න හෝ විසන්ධි කරන්න"</string>
-    <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"WiMAX සබල බව සහ සම්බන්ධිත ඕනෑම WiMAX ජාලයක තොරතුරු නිශ්චය කිරීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_changeWimaxState" msgid="2405042267131496579">"WiMAX තත්වය වෙනස් කරන්න"</string>
-    <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"ටැබ්ලටය WiMAX ජාල වෙත සම්බන්ධ කිරීමට සහ විසන්ධි කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"WiMAX ජාලයන්ට දුරකථනය සම්බන්ධ කිරීමට සහ විසන්ධි කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"බ්ලූටූත් උපාංග සමඟ යුගල කිරීම"</string>
-    <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"ටැබ්ලටයේ බ්ලූටූත් වින්‍යාසය බැලිමට, සැකසීමට සහ යුගල කළ උපාංග සමඟ සම්බන්ධතාවන් පිළිගැනීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"දුරකථනයේ බ්ලූටූත් වින්‍යාසය දැකීමට, යුගල උපාංග සමඟ සම්බන්ධතාවන් සැකසීමට සහ භාරගැනීමට යෙදුමට අවසර දෙයි."</string>
-    <string name="permlab_nfc" msgid="4423351274757876953">"ආසන්න ක්ෂේත්‍ර සන්නිවේදනය පාලනය කරන්න"</string>
-    <string name="permdesc_nfc" msgid="7120611819401789907">"ආසන්න ක්ෂේත්‍ර සන්නිවේදන (NFC) ටැග්, පත්, සහ කියවන්නන් සමඟ සන්නිවේදනය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_disableKeyguard" msgid="3598496301486439258">"ඔබගේ තිරයේ අගුල අබල කරන්න"</string>
-    <string name="permdesc_disableKeyguard" msgid="6034203065077122992">"යතුරු අගුල සහ ඕනෑම සම්බන්ධිත මුරපද ආරක්ෂාවක් අබල කිරීමට යෙදුමට අවසර දෙන්න. මෙහි උදාහරණයක් වන්නේ පැමිණෙන ඇමතුමක් ලැබෙද්දී, දුරකථනය අක්‍රිය වන අතර ඇමතුම අවසාන වන විට යතුරු අගුල නැවත සක්‍රිය වෙයි."</string>
-    <string name="permlab_readSyncSettings" msgid="6201810008230503052">"සමමුහුර්ත සැකසීම් කියවන්න"</string>
-    <string name="permdesc_readSyncSettings" msgid="2706745674569678644">"ගිණුම සඳහා සමමුහුර්ත සැකසීම් කියවීමට යෙදුමට අවසර දෙන්න. උදාහරණයක් ලෙස, ගිණුමක් සමඟ පුද්ගල යෙදුම සමමුහුර්ත දැයි මෙයට හඳුනා ගත හැක."</string>
-    <string name="permlab_writeSyncSettings" msgid="5408694875793945314">"සමමුහුර්ත කිරීම සක්‍රිය කරන්න සහ අක්‍රිය කරන්න"</string>
-    <string name="permdesc_writeSyncSettings" msgid="8956262591306369868">"ගිණුම සඳහා සමමුහුර්ත සැකසීම් වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. උදාහරණයක් ලෙස, ගිණුම සමඟ පුද්ගල යෙදුම සමමුහුර්ත කිරීම සක්‍රිය කිරීමට භාවිත කල හැක."</string>
-    <string name="permlab_readSyncStats" msgid="7396577451360202448">"සමමුහුර්ත කිරීමේ සංඛ්‍යාන කියවීම"</string>
-    <string name="permdesc_readSyncStats" msgid="1510143761757606156">"සමමුහුර්ත කිරීමේ සිදුවීම් ඉතිහාසය සහ කෙතරම් දත්ත සමමුහුර්ත වී ඇතිදැයි ඇතුලත් ගිණුම සඳහා සමමුහුර්ත කිරීමේ සංඛ්‍යාන කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_subscribedFeedsRead" msgid="4756609637053353318">"දායක වූ සංග්‍රහ කියවීම"</string>
-    <string name="permdesc_subscribedFeedsRead" msgid="5557058907906144505">"වර්තමාන සමමුහුර්ත සංග්‍රහ ගැන විස්තර ලැබීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_subscribedFeedsWrite" msgid="9015246325408209296">"දායක වූ සංග්‍රහ ලිවීම"</string>
-    <string name="permdesc_subscribedFeedsWrite" msgid="6928930188826089413">"ඔබගේ වර්තමාන සමමුහුර්ත සංග්‍රහ වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ සමමුහුර්ත සංග්‍රහ අනිෂ්ට යෙදුම්වලින් වෙනස් කල හැක."</string>
-    <string name="permlab_readDictionary" msgid="4107101525746035718">"ඔබ විසින් ශබ්දකෝෂයට ඇතුළත්කොට ඇති කොන්දේසි කියවීම"</string>
-    <string name="permdesc_readDictionary" msgid="659614600338904243">"පරිශීලක ශබ්ද කෝෂයේ පරිශීලකයන් විසින් ගබඩා කර තිබිය හැකි වචන, නම්, වාක්‍යංශ කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_writeDictionary" msgid="2183110402314441106">"පරිශීලකයින් අර්ථ දැක්වූ ශබ්ද කෝෂයට වචන එකතු කිරීම"</string>
-    <string name="permdesc_writeDictionary" msgid="8185385716255065291">"පරිශීලක ශබ්දකෝෂය තුළට අලුත් වචන ලිවීමට යෙදුමට ඉඩ දෙන්න."</string>
-    <string name="permlab_sdcardRead" product="nosdcard" msgid="8235341515605559677">"ආරක්‍ෂිත ආචයනය වෙත ප්‍රවේශය පරීක්ෂා කිරීම"</string>
-    <string name="permlab_sdcardRead" product="default" msgid="8235341515605559677">"ආරක්‍ෂිත ආචයනය වෙත ප්‍රවේශය පරීක්ෂා කිරීම"</string>
-    <string name="permdesc_sdcardRead" product="nosdcard" msgid="3642473292348132072">"අනාගත උපාංගවල ලබාගත හැකි USB ආචයනය සඳහා අවසරයක් පරීක්ෂා කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_sdcardRead" product="default" msgid="5914402684685848828">"අනාගත උපාංගවල පැවතෙන SD කාඩ් පත සඳහා අවසරයක් පිරික්සීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_sdcardWrite" product="nosdcard" msgid="8485979062254666748">"ඔබගේ USB ආචයනයේ අන්තර්ගත වෙනස් කිරීම හෝ මැකීම"</string>
-    <string name="permlab_sdcardWrite" product="default" msgid="8805693630050458763">"ඔබගේ SD පතේ අන්තර්ගත වෙනස් කිරීම හෝ මැකීම"</string>
-    <string name="permdesc_sdcardWrite" product="nosdcard" msgid="6175406299445710888">"USB ආචයනය වෙත ලිවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permdesc_sdcardWrite" product="default" msgid="4337417790936632090">"SD පත වෙත ලිවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_mediaStorageWrite" product="default" msgid="6859839199706879015">"අභ්‍යන්තර මාධ්‍ය ආචයනය අන්තර්ගත වෙනස් කරන්න/ මකන්න"</string>
-    <string name="permdesc_mediaStorageWrite" product="default" msgid="8189160597698529185">"අභ්‍යන්තර මාධ්‍ය ආචයනයේ අන්තර්ගතය වෙනස් කිරීමට උපාංගයට අවසර දෙන්න."</string>
-    <string name="permlab_manageDocs" product="default" msgid="5778318598448849829">"ලේඛන ආචයනය කළමනාකරණය කරන්න"</string>
-    <string name="permdesc_manageDocs" product="default" msgid="8704323176914121484">"ලේඛන ආචයනය කළමනාකරණය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_sdcardAccessAll" msgid="8150613823900460576">"සියලුම පරිශීලකයන්ගේ බාහිර ආචයන වෙත පිවිසෙන්න"</string>
-    <string name="permdesc_sdcardAccessAll" msgid="3215208357415891320">"සියලු පරිශීලකයන් සඳහා බාහිර ආචයනය වෙත පිවිසීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_cache_filesystem" msgid="5656487264819669824">"හැඹිලි ගොනු පද්ධතියට ප්‍රවේශ වීම"</string>
-    <string name="permdesc_cache_filesystem" msgid="5578967642265550955">"හැඹිලි ගොනු පද්ධති කියවීමට සහ ලිවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_use_sip" msgid="5986952362795870502">"අන්තර්ජාල ඇමතුම් ගන්න/ලබන්න"</string>
-    <string name="permdesc_use_sip" msgid="4717632000062674294">"අන්තර්ජාල ඇමතුම් ගැනීමට/ලැබීමට SIP සේවාව භාවිතයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_readNetworkUsageHistory" msgid="7862593283611493232">"ඉතිහාසගත ජාල භාවිතය කියවන්න"</string>
-    <string name="permdesc_readNetworkUsageHistory" msgid="7689060749819126472">"විශේෂිත ජාල සහ යෙදුම් සඳහා ඉතිහාසගත ජාල භාවිතය කියවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_manageNetworkPolicy" msgid="2562053592339859990">"ජාල ප්‍රතිපත්තිය කළමනාකරණය කිරීම"</string>
-    <string name="permdesc_manageNetworkPolicy" msgid="7537586771559370668">"ජාල කොන්දේසි සහ සඳහන් යෙදුම් විශේෂීත රීති කළමනාකරණය කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_modifyNetworkAccounting" msgid="5088217309088729650">"ජාල භාවිත ගිණුම් කිරීම වෙනස් කිරීම"</string>
-    <string name="permdesc_modifyNetworkAccounting" msgid="5443412866746198123">"යෙදුම්වලට ජාල භාවිතයෙන් වන බලපෑම කෙසේද යන්න වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_markNetworkSocket" msgid="3658527214914959749">"කෙවෙනි ලකුණු වෙනස් කරන්න"</string>
-    <string name="permdesc_markNetworkSocket" msgid="7655568433696356578">"මාර්ගගත වීම සඳහා කෙවෙනියේ ලකුණු වෙනස් කිරීමට යෙදුමට ඉඩ දෙන්න"</string>
-    <string name="permlab_accessNotifications" msgid="7673416487873432268">"ප්‍රවේශ දැනුම්දීම්"</string>
-    <string name="permdesc_accessNotifications" msgid="458457742683431387">"වෙනත් යෙදුම් විසින් කළ පල කිරීම්ද ඇතුළත්ව දැන්වීම් ලබා ගැනීමට, පරීක්ෂා කිරීමට සහ හිස් කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_bindNotificationListenerService" msgid="7057764742211656654">"දැනුම්දීම ඇහුම්කන් දීම් සේවාවක් වෙත බඳින්න"</string>
-    <string name="permdesc_bindNotificationListenerService" msgid="985697918576902986">"දැනුම්දීම් අසන්නාගේ සේවාවේ ඉහළ මට්ටමේ අතුරුමුහුණතට බැඳීමට දරන්නාට අවසර දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අවශ්‍ය නොවේ."</string>
-    <string name="permlab_invokeCarrierSetup" msgid="3699600833975117478">"වාහකය සැපයු වින්‍යාසය යෙදුම ඉල්ලා සිටින්න"</string>
-    <string name="permdesc_invokeCarrierSetup" msgid="4159549152529111920">"වාහකයා ලබාදුන් සැකසුම් යෙදුම් උත්පාදනයට ධාරකයාට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවෙයි."</string>
-    <string name="permlab_accessNetworkConditions" msgid="8206077447838909516">"ජාල තත්ව මත නිරීක්ෂණ වෙත ඇහුම්කන් දීම"</string>
-    <string name="permdesc_accessNetworkConditions" msgid="6899102075825272211">"යෙදුමකට ජාල තත්ව මත නිරීක්ෂණ වෙත ඇහුම්කන් දීමට අවසර දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිදා අවශ්‍ය නොවේ."</string>
-    <string name="policylab_limitPassword" msgid="4497420728857585791">"මුරපද නීති සකස් කිරීම"</string>
-    <string name="policydesc_limitPassword" msgid="3252114203919510394">"තිරය අගුළු ඇරීමේ මුරපදයට අනුමත අකුරු සහ දිග පාලනය කරන්න."</string>
-    <string name="policylab_watchLogin" msgid="914130646942199503">"තිරය අගුළු ඇරීමේ උත්සාහයන් නිරීක්ෂණය කරන්න"</string>
-    <string name="policydesc_watchLogin" product="tablet" msgid="3215729294215070072">"තිරය අගුළු හැරීමේදී වැරදියට ටයිප් කළ මුරපද ගණන නිරීක්ෂණය කරන්න සහ ටැබ්ලටය අගුළු දමන්න හෝ වැරදි මුරපද බොහෝ ගණනක් ටයිප් කර ඇති නම් ටැබ්ලටයේ සියලු දත්ත මකන්න."</string>
-    <string name="policydesc_watchLogin" product="default" msgid="5712323091846761073">"තිරය අගුළු හැරීමේදී වැරදියට ටයිප් කළ මුරපද ගණන නිරීක්ෂණය කරන්න සහ දුරකථනය අගුළු දමන්න හෝ වැරදි මුරපද බොහෝ ගණනක් ටයිප් කර ඇති නම් දුරකථනයේ සියලු දත්ත මකන්න."</string>
-    <string name="policylab_resetPassword" msgid="2620077191242688955">"තිරය අගුළු ඇරීමේ මුරපදය වෙනස් කිරීම"</string>
-    <string name="policydesc_resetPassword" msgid="605963962301904458">"තිරය අගුළු ඇරීමේ මුරපදය වෙනස් කරන්න."</string>
-    <string name="policylab_forceLock" msgid="2274085384704248431">"තිරය අගුළු දැමීම"</string>
-    <string name="policydesc_forceLock" msgid="1141797588403827138">"තිරයට අගුළු වැටීම සිදුවන්නේ කෙසේද සහ කවදාද යන්න පාලනය කරන්න."</string>
-    <string name="policylab_wipeData" msgid="3910545446758639713">"සියලු දත්ත මකන්න"</string>
-    <string name="policydesc_wipeData" product="tablet" msgid="4306184096067756876">"කර්මාන්ත ශාලා දත්ත යළි පිහිටුවීමෙන් පසුව අනතුරු ඇඟවිමකින් තොරවම ටැබ්ලට් දත්ත මකා දමයි."</string>
-    <string name="policydesc_wipeData" product="default" msgid="5096895604574188391">"කර්මාන්ත ශාලා දත්ත යළි පිහිටුවීමෙන් පසුව අනතුරු ඇඟවිමකින් තොරවම දුරකථන දත්ත මකා දමයි."</string>
-    <string name="policylab_setGlobalProxy" msgid="2784828293747791446">"උපාංග ගෝලීය නියුතුව සකස් කිරීම"</string>
-    <string name="policydesc_setGlobalProxy" msgid="6387497466660154931">"කොන්දේසි සක්‍රිය විට පොදු නියුතු එකක් භාවිත කරන ලෙස උපාංගය සකසන්න. පළමු උපාංග පරිපාලකයා පමණක් ඵලදායි පොදු නියුතුව සකසයි."</string>
-    <string name="policylab_expirePassword" msgid="885279151847254056">"තිරය අගුළු දැමීමේ මුරපදය කල් ඉකුත්වීම සකසන්න"</string>
-    <string name="policydesc_expirePassword" msgid="1729725226314691591">"තිර-අගුළේ මුරපදය වෙනස්වීම කොපමණ කාල පරාසයකින් සිදුවිය යුතුද යන්න පාලනය කිරීම."</string>
-    <string name="policylab_encryptedStorage" msgid="8901326199909132915">"ආචයනයේ සංකේතනය සකස් කිරීම"</string>
-    <string name="policydesc_encryptedStorage" msgid="2637732115325316992">"ආචයනය කළ යෙදුම් දත්ත සංකේතනය කිරීමට අවශ්‍යය."</string>
-    <string name="policylab_disableCamera" msgid="6395301023152297826">"කැමරා අබල කිරීම"</string>
-    <string name="policydesc_disableCamera" msgid="2306349042834754597">"සියලු උපාංග කැමරාවල භාවිතය වලක්වන්න."</string>
-    <string name="policylab_disableKeyguardFeatures" msgid="266329104542638802">"යතුරු ආරක්ෂාවේ විශේෂාංග අබල කරන්න"</string>
-    <string name="policydesc_disableKeyguardFeatures" msgid="3467082272186534614">"යතුරු ආරක්ෂාව හි සමහර විශේෂාංග භාවිතය වළක්වයි."</string>
-  <string-array name="phoneTypes">
-    <item msgid="8901098336658710359">"නිවස"</item>
-    <item msgid="869923650527136615">"ජංගම"</item>
-    <item msgid="7897544654242874543">"කාර්යාලය"</item>
-    <item msgid="1103601433382158155">"කාර්යාල ෆැක්ස්"</item>
-    <item msgid="1735177144948329370">"නිවසේ ෆැක්ස්"</item>
-    <item msgid="603878674477207394">"පේජරය"</item>
-    <item msgid="1650824275177931637">"වෙනත්"</item>
-    <item msgid="9192514806975898961">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="emailAddressTypes">
-    <item msgid="8073994352956129127">"මුල් පිටුව"</item>
-    <item msgid="7084237356602625604">"කාර්යාලය"</item>
-    <item msgid="1112044410659011023">"වෙනත්"</item>
-    <item msgid="2374913952870110618">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="postalAddressTypes">
-    <item msgid="6880257626740047286">"නිවස"</item>
-    <item msgid="5629153956045109251">"කාර්යාලය"</item>
-    <item msgid="4966604264500343469">"වෙනත්"</item>
-    <item msgid="4932682847595299369">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="imAddressTypes">
-    <item msgid="1738585194601476694">"නිවස"</item>
-    <item msgid="1359644565647383708">"කාර්යාලය"</item>
-    <item msgid="7868549401053615677">"වෙනත්"</item>
-    <item msgid="3145118944639869809">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="organizationTypes">
-    <item msgid="7546335612189115615">"කාර්යාලය"</item>
-    <item msgid="4378074129049520373">"වෙනත්"</item>
-    <item msgid="3455047468583965104">"අභිරුචි"</item>
-  </string-array>
-  <string-array name="imProtocols">
-    <item msgid="8595261363518459565">"AIM"</item>
-    <item msgid="7390473628275490700">"Windows Live"</item>
-    <item msgid="7882877134931458217">"Yahoo"</item>
-    <item msgid="5035376313200585242">"Skype"</item>
-    <item msgid="7532363178459444943">"QQ"</item>
-    <item msgid="3713441034299660749">"Google Talk"</item>
-    <item msgid="2506857312718630823">"ICQ"</item>
-    <item msgid="1648797903785279353">"Jabber"</item>
-  </string-array>
-    <string name="phoneTypeCustom" msgid="1644738059053355820">"අභිරුචි"</string>
-    <string name="phoneTypeHome" msgid="2570923463033985887">"නිවස"</string>
-    <string name="phoneTypeMobile" msgid="6501463557754751037">"ජංගම"</string>
-    <string name="phoneTypeWork" msgid="8863939667059911633">"කාර්යාලය"</string>
-    <string name="phoneTypeFaxWork" msgid="3517792160008890912">"කාර්යාල ෆැක්ස්"</string>
-    <string name="phoneTypeFaxHome" msgid="2067265972322971467">"නිවසේ ෆැක්ස්"</string>
-    <string name="phoneTypePager" msgid="7582359955394921732">"පේජරය"</string>
-    <string name="phoneTypeOther" msgid="1544425847868765990">"වෙනත්"</string>
-    <string name="phoneTypeCallback" msgid="2712175203065678206">"යළි ඇමතීම"</string>
-    <string name="phoneTypeCar" msgid="8738360689616716982">"මෝටර් රථය"</string>
-    <string name="phoneTypeCompanyMain" msgid="540434356461478916">"ආයතනයේ මූලිකය"</string>
-    <string name="phoneTypeIsdn" msgid="8022453193171370337">"ISDN"</string>
-    <string name="phoneTypeMain" msgid="6766137010628326916">"මූලික"</string>
-    <string name="phoneTypeOtherFax" msgid="8587657145072446565">"වෙනත් ෆැක්ස්"</string>
-    <string name="phoneTypeRadio" msgid="4093738079908667513">"රේඩියෝව"</string>
-    <string name="phoneTypeTelex" msgid="3367879952476250512">"ටෙලෙක්ස්"</string>
-    <string name="phoneTypeTtyTdd" msgid="8606514378585000044">"TTY TDD"</string>
-    <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"කාර්යාල ජංගම"</string>
-    <string name="phoneTypeWorkPager" msgid="649938731231157056">"කාර්යාල පේජරය"</string>
-    <string name="phoneTypeAssistant" msgid="5596772636128562884">"සහායක"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
-    <string name="eventTypeCustom" msgid="7837586198458073404">"අභිරුචි"</string>
-    <string name="eventTypeBirthday" msgid="2813379844211390740">"උපන්දිනය"</string>
-    <string name="eventTypeAnniversary" msgid="3876779744518284000">"සංවත්සරය"</string>
-    <string name="eventTypeOther" msgid="7388178939010143077">"වෙනත්"</string>
-    <string name="emailTypeCustom" msgid="8525960257804213846">"අභිරුචි"</string>
-    <string name="emailTypeHome" msgid="449227236140433919">"නිවස"</string>
-    <string name="emailTypeWork" msgid="3548058059601149973">"කාර්යාලය"</string>
-    <string name="emailTypeOther" msgid="2923008695272639549">"වෙනත්"</string>
-    <string name="emailTypeMobile" msgid="119919005321166205">"ජංගම"</string>
-    <string name="postalTypeCustom" msgid="8903206903060479902">"අභිරුචි"</string>
-    <string name="postalTypeHome" msgid="8165756977184483097">"නිවස"</string>
-    <string name="postalTypeWork" msgid="5268172772387694495">"කාර්යාලය"</string>
-    <string name="postalTypeOther" msgid="2726111966623584341">"වෙනත්"</string>
-    <string name="imTypeCustom" msgid="2074028755527826046">"අභිරුචි"</string>
-    <string name="imTypeHome" msgid="6241181032954263892">"මුල් පිටුව"</string>
-    <string name="imTypeWork" msgid="1371489290242433090">"කාර්යාලය"</string>
-    <string name="imTypeOther" msgid="5377007495735915478">"වෙනත්"</string>
-    <string name="imProtocolCustom" msgid="6919453836618749992">"අභිරුචි"</string>
-    <string name="imProtocolAim" msgid="7050360612368383417">"AIM"</string>
-    <string name="imProtocolMsn" msgid="144556545420769442">"Windows Live"</string>
-    <string name="imProtocolYahoo" msgid="8271439408469021273">"Yahoo"</string>
-    <string name="imProtocolSkype" msgid="9019296744622832951">"Skype"</string>
-    <string name="imProtocolQq" msgid="8887484379494111884">"QQ"</string>
-    <string name="imProtocolGoogleTalk" msgid="493902321140277304">"Hangouts"</string>
-    <string name="imProtocolIcq" msgid="1574870433606517315">"ICQ"</string>
-    <string name="imProtocolJabber" msgid="2279917630875771722">"Jabber"</string>
-    <string name="imProtocolNetMeeting" msgid="8287625655986827971">"NetMeeting"</string>
-    <string name="orgTypeWork" msgid="29268870505363872">"කාර්යාලය"</string>
-    <string name="orgTypeOther" msgid="3951781131570124082">"වෙනත්"</string>
-    <string name="orgTypeCustom" msgid="225523415372088322">"අභිරුචි"</string>
-    <string name="relationTypeCustom" msgid="3542403679827297300">"අභිරුචි"</string>
-    <string name="relationTypeAssistant" msgid="6274334825195379076">"සහායක"</string>
-    <string name="relationTypeBrother" msgid="8757913506784067713">"සහෝදරයා"</string>
-    <string name="relationTypeChild" msgid="1890746277276881626">"දරුවා"</string>
-    <string name="relationTypeDomesticPartner" msgid="6904807112121122133">"දේශීය හවුල්කරුවා"</string>
-    <string name="relationTypeFather" msgid="5228034687082050725">"පියා"</string>
-    <string name="relationTypeFriend" msgid="7313106762483391262">"මිත්‍රයා"</string>
-    <string name="relationTypeManager" msgid="6365677861610137895">"කළමනාකරු"</string>
-    <string name="relationTypeMother" msgid="4578571352962758304">"මව"</string>
-    <string name="relationTypeParent" msgid="4755635567562925226">"මව්පිය"</string>
-    <string name="relationTypePartner" msgid="7266490285120262781">"හවුල්කරුවා"</string>
-    <string name="relationTypeReferredBy" msgid="101573059844135524">"යොමුකරන ලද්දේ"</string>
-    <string name="relationTypeRelative" msgid="1799819930085610271">"නෑයා"</string>
-    <string name="relationTypeSister" msgid="1735983554479076481">"සහෝදරිය"</string>
-    <string name="relationTypeSpouse" msgid="394136939428698117">"භාර්යාව හෝ ස්වාමිපුරුෂයා"</string>
-    <string name="sipAddressTypeCustom" msgid="2473580593111590945">"අභිරුචි"</string>
-    <string name="sipAddressTypeHome" msgid="6093598181069359295">"නිවස"</string>
-    <string name="sipAddressTypeWork" msgid="6920725730797099047">"කාර්යාලය"</string>
-    <string name="sipAddressTypeOther" msgid="4408436162950119849">"වෙනත්"</string>
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PIN කේතය ටයිප් කරන්න"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK සහ නව PIN කේතය ටයිප් කරන්න"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK කේතය"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"නව PIN කේතය"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"මුරපදය ටයිප් කිරීමට ස්පර්ශ කරන්න"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"අගුළු ඇරීමට මුරපදය ටයිප් කරන්න"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"අගුළු හැරීමට PIN එක ටයිප් කරන්න"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"වැරදි PIN කේතයකි."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"අගුළු ඇරීමට, මෙනුව ඔබා පසුව 0 ද ඔබන්න."</string>
-    <string name="emergency_call_dialog_number_for_display" msgid="696192103195090970">"හදිසි ඇමතුම් අංකය"</string>
-    <string name="lockscreen_carrier_default" msgid="8963839242565653192">"සේවාව නැත."</string>
-    <string name="lockscreen_screen_locked" msgid="7288443074806832904">"තිරය අගුළු දමා ඇත."</string>
-    <string name="lockscreen_instructions_when_pattern_enabled" msgid="46154051614126049">"අගුළු හැරීමට මෙනුව ඔබන්න හෝ හදිසි ඇමතුම ලබාගන්න."</string>
-    <string name="lockscreen_instructions_when_pattern_disabled" msgid="686260028797158364">"අගුළු හැරීමට මෙනු ඔබන්න."</string>
-    <string name="lockscreen_pattern_instructions" msgid="7478703254964810302">"අගුළු ඇරීමට රටාව අඳින්න"</string>
-    <string name="lockscreen_emergency_call" msgid="5347633784401285225">"හදිසි ඇමතුම්"</string>
-    <string name="lockscreen_return_to_call" msgid="5244259785500040021">"ඇමතුම වෙත නැවත යන්න"</string>
-    <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"නිවැරදියි!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"නැවත උත්සාහ කරන්න"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"නැවත උත්සාහ කරන්න"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"මුහුණ භාවිතයෙන් අඟුළු හැරීමේ උපරිම ප්‍රයන්තයන් ගණන ඉක්මවා ඇත"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"ආරෝපණය වෙමින්, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_charged" msgid="321635745684060624">"අරෝපිතයි"</string>
-    <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="lockscreen_low_battery" msgid="1482873981919249740">"ඔබගේ ආරෝපකයට සම්බන්ධ කරන්න."</string>
-    <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"SIM පත නැත"</string>
-    <string name="lockscreen_missing_sim_message" product="tablet" msgid="151659196095791474">"ටැබ්ලටයේ SIM පත නොමැත."</string>
-    <string name="lockscreen_missing_sim_message" product="default" msgid="2186920585695169078">"දුරකථනය තුළ SIM පත නැත."</string>
-    <string name="lockscreen_missing_sim_instructions" msgid="5372787138023272615">"SIM පතක් ඇතුල් කරන්න."</string>
-    <string name="lockscreen_missing_sim_instructions_long" msgid="3526573099019319472">"SIM පත නොමැත හෝ කියවිය නොහැක. SIM පතක් ඇතුලත් කරන්න."</string>
-    <string name="lockscreen_permanent_disabled_sim_message_short" msgid="5096149665138916184">"භාවිතා කළ නොහැකි SIM පත."</string>
-    <string name="lockscreen_permanent_disabled_sim_instructions" msgid="910904643433151371">"ඔබගේ SIM පත ස්ථිරව අබල කර තිබේ.\n වෙනත් SIM පතක් සඳහා ඔබගේ සේවාදායකයා සම්බන්ධ කරගන්න."</string>
-    <string name="lockscreen_transport_prev_description" msgid="201594905152746886">"පෙර ගීත බොත්තම"</string>
-    <string name="lockscreen_transport_next_description" msgid="6089297650481292363">"ඊළඟ ගීත බොත්තම"</string>
-    <string name="lockscreen_transport_pause_description" msgid="7659088786780128001">"විරාම බොත්තම"</string>
-    <string name="lockscreen_transport_play_description" msgid="5888422938351019426">"ධාවක බොත්තම"</string>
-    <string name="lockscreen_transport_stop_description" msgid="4562318378766987601">"නැවතීමේ බොත්තම"</string>
-    <string name="emergency_calls_only" msgid="6733978304386365407">"හදිසි ඇමතුම් පමණි"</string>
-    <string name="lockscreen_network_locked_message" msgid="143389224986028501">"ජාලය අගුළු දමා ඇත"</string>
-    <string name="lockscreen_sim_puk_locked_message" msgid="7441797339976230">"SIM පත PUK අගුළු දමා ඇත."</string>
-    <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"පරිශීලක උපදේශය බලන්න හෝ පරිභෝගික සේවාව අමතන්න."</string>
-    <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM පත අගුළු දමා ඇත."</string>
-    <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"SIM පත අගුළු අරිමින්..."</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"ඔබ <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් අගුළු ඇරීමේ රටාව වැරදියට ඇඳ ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"ඔබ මුරපදය වාර <xliff:g id="NUMBER_0">%d</xliff:g> ක් වැරදියට ටයිප්කොට ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> කින් නැවත උත්සහ කරන්න."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"ඔබ PIN අංකය <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් වැරදියට ටයිප් කොට ඇත.\n\n තත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"ඔබ වැරදියට <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ අගුළු හැරීමේ රටාව ඇඳ ඇත. අසාර්ථක උත්සහ කිරීම් <xliff:g id="NUMBER_1">%d</xliff:g> න් පසුව, ඔබගේ Google පුරනය වීම් භාවිතයෙන් ඔබගේ ටැබ්ලටය අගුළු හැරීමට ඔබගෙන් අසයි.\n\n තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"ඔබ වැරදියට <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ අගුළු හැරීමේ රටාව ඇඳ ඇත. අසාර්ථක උත්සහ කිරීම් <xliff:g id="NUMBER_1">%d</xliff:g> න් පසුව, ඔබගේ Google පුරනය වීම භාවිතයෙන් ඔබගේ දුරකථනය අගුළු හැරීමට ඔබගෙන් අසනු ඇත.\n\n තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"ඔබ ටැබ්ලටය අගුළු හැරීමට වැරදියට අවස්ථා <xliff:g id="NUMBER_0">%d</xliff:g> ක් උත්සාහ කර ඇත. අවස්ථා <xliff:g id="NUMBER_1">%d</xliff:g> ක් අසාර්ථකව උත්සහ කිරීමකින් පසුව, ටැබ්ලටය කර්මාන්ත ශාලා මුල් තත්වයට නැවත පත් වන අතර සියලු පරිශීලක දත්ත නැති වෙයි."</string>
-    <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER_0">%d</xliff:g> කදී වැරදී ප්‍රයත්නයන් ගෙන තිබේ. තවත් අසාර්ථක ප්‍රයත්න <xliff:g id="NUMBER_1">%d</xliff:g> කින් පසුව, දුරකථනය කර්මාන්තශාලාවේ පෙරනිමියට යළි පිහිටුවන අතර සියලුම පරිශීලක දත්ත නැති වී යයි."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"ටැබ්ලටයේ අගුළු ඇරීමට ඔබ වැරදි ප්‍රයත්න <xliff:g id="NUMBER">%d</xliff:g> වාරයක් ගෙන ඇත. දැන් ටැබ්ලටය කර්මාන්තශාලා සුපුරුද්ද වෙත යළි පිහිටුවීම කෙරේ."</string>
-    <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER">%d</xliff:g> කදී වැරදී ප්‍රයත්නයන් ගෙන තිබේ. දැන් දුරකථනය කර්මාන්තශාලා පෙරනිමියට පිහිටුවනු ලබයි."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"තත්පර <xliff:g id="NUMBER">%d</xliff:g> කින් නැවත උත්සාහ කරන්න."</string>
-    <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"රටාව අමතකද?"</string>
-    <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"ගිණුමේ අගුළු අරින්න"</string>
-    <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"රටා උත්සාහ කිරීම් වැඩිය"</string>
-    <string name="lockscreen_glogin_instructions" msgid="3931816256100707784">"අගුළු හැරීමට, ඔබගේ Google ගිණුම සමග පුරනය වන්න."</string>
-    <string name="lockscreen_glogin_username_hint" msgid="8846881424106484447">"පරිශීලක නාමය (ඊ-තැපෑල)"</string>
-    <string name="lockscreen_glogin_password_hint" msgid="5958028383954738528">"මුරපදය"</string>
-    <string name="lockscreen_glogin_submit_button" msgid="7130893694795786300">"පුරනය වෙන්න"</string>
-    <string name="lockscreen_glogin_invalid_input" msgid="1364051473347485908">"වලංගු නොවන පරිශීලක නාමයක් හෝ මුරපදයක්."</string>
-    <string name="lockscreen_glogin_account_recovery_hint" msgid="1696924763690379073">"ඔබගේ පරිශීලක නාමය හෝ මුරපදය අමතකද?\n "<b>"google.com/accounts/recovery"</b>" වෙත යන්න."</string>
-    <string name="lockscreen_glogin_checking_password" msgid="7114627351286933867">"පරික්ෂා කරමින්..."</string>
-    <string name="lockscreen_unlock_label" msgid="737440483220667054">"අඟුල අරින්න"</string>
-    <string name="lockscreen_sound_on_label" msgid="9068877576513425970">"ශබ්දය සක්‍රීය කරන්න"</string>
-    <string name="lockscreen_sound_off_label" msgid="996822825154319026">"ශ්‍රව්‍ය අක්‍රිය කරන්න"</string>
-    <string name="lockscreen_access_pattern_start" msgid="3941045502933142847">"රටාව අරඹන ලදි"</string>
-    <string name="lockscreen_access_pattern_cleared" msgid="5583479721001639579">"රටාව හිස් කරන ලදි"</string>
-    <string name="lockscreen_access_pattern_cell_added" msgid="6756031208359292487">"කොටුවක් එකතු කරන ලදි"</string>
-    <string name="lockscreen_access_pattern_detected" msgid="4988730895554057058">"රටාව සම්පූර්ණයි"</string>
-    <!-- String.format failed for translation -->
-    <!-- no translation found for keyguard_accessibility_widget_changed (5678624624681400191) -->
-    <skip />
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"විජටය එකතු කරන්න."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"හිස්"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"අගුළු අරින ප්‍රදේශය විදහා ඇත."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"අගුළු අරින ප්‍රදේශය හැකිලී ඇත."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> විජට්."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"පරිශීලක තෝරන්නා"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"තත්වය"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"කැමරාව"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"මාධ්‍ය පාලක"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"විජටය නැවත අනුපිළිවෙළට සැකසිම ඇරඹුණි."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"විජට් නැවත අනුපිළිවෙලට සැකසීම අවසානය."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> විජටය මැකී ඇත."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"අගුළු නොදැමූ ප්‍රදේශය පුළුල් කරන්න."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"සර්පණ අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"රටා අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"මුහුණ භාවිතයෙන් අඟුළු හැරීම."</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"PIN අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"මුරපද අගුළු ඇරීම."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"රටා ප්‍රදේශය."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"සර්පණ ප්‍රදේශය."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="granularity_label_character" msgid="7336470535385009523">"අක්ෂරය"</string>
-    <string name="granularity_label_word" msgid="7075570328374918660">"වචනය"</string>
-    <string name="granularity_label_link" msgid="5815508880782488267">"සබැඳිය"</string>
-    <string name="granularity_label_line" msgid="5764267235026120888">"රේඛාව"</string>
-    <string name="hour_ampm" msgid="4584338083529355982">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%P</xliff:g>"</string>
-    <string name="hour_cap_ampm" msgid="2083465992940444366">"<xliff:g id="HOUR">%-l</xliff:g><xliff:g id="AMPM">%p</xliff:g>"</string>
-    <string name="factorytest_failed" msgid="5410270329114212041">"කර්මාන්ත ශාලා පරීක්ෂණය අසාර්ථකයි"</string>
-    <string name="factorytest_not_system" msgid="4435201656767276723">"FACTORY_TEST ක්‍රියාව /system/app හි ස්ථාපිත පැකේජ සඳහා පමණක් සහය දක්වයි."</string>
-    <string name="factorytest_no_action" msgid="872991874799998561">"FACTORY_TEST ක්‍රියාව ලබාදෙන පැකේජයක් සොයාගත නොහැකි විය."</string>
-    <string name="factorytest_reboot" msgid="6320168203050791643">"පුනරාරම්භ කරන්න"</string>
-    <string name="js_dialog_title" msgid="1987483977834603872">"\"<xliff:g id="TITLE">%s</xliff:g>\" හි ඇති පිටුව කියන්නේ:"</string>
-    <string name="js_dialog_title_default" msgid="6961903213729667573">"ජාවාස්ක්‍රිප්ට්"</string>
-    <string name="js_dialog_before_unload_title" msgid="2619376555525116593">"සංචලනය තහවුරු කරන්න"</string>
-    <string name="js_dialog_before_unload_positive_button" msgid="3112752010600484130">"මෙම පිටුවෙන් ඉවත් වන්න"</string>
-    <string name="js_dialog_before_unload_negative_button" msgid="5614861293026099715">"මෙම පිටුවෙහි ඉන්න"</string>
-    <string name="js_dialog_before_unload" msgid="3468816357095378590">"<xliff:g id="MESSAGE">%s</xliff:g>\n\nඔබට මෙම පිටුවෙන් සංචලනය කිරීමට අවශ්‍ය බවට ඔබට විශ්වාසද?"</string>
-    <string name="save_password_label" msgid="6860261758665825069">"තහවුරු කරන්න"</string>
-    <string name="double_tap_toast" msgid="4595046515400268881">"උපදෙස: විශාලනය කිරීමට සහ කුඩා කිරීමට දෙවරක් තට්ටු කරන්න."</string>
-    <string name="autofill_this_form" msgid="4616758841157816676">"ස්වයංක්‍රිය පිරවුම"</string>
-    <string name="setup_autofill" msgid="7103495070180590814">"ස්වයංක්‍රිය පිරවුම සකසන්න"</string>
-    <string name="autofill_address_name_separator" msgid="6350145154779706772">" "</string>
-    <string name="autofill_address_summary_name_format" msgid="3268041054899214945">"$1$2$3"</string>
-    <string name="autofill_address_summary_separator" msgid="7483307893170324129">", "</string>
-    <string name="autofill_address_summary_format" msgid="4874459455786827344">"$1$2$3"</string>
-    <string name="autofill_province" msgid="2231806553863422300">"පළාත"</string>
-    <string name="autofill_postal_code" msgid="4696430407689377108">"තැපැල් කේතය"</string>
-    <string name="autofill_state" msgid="6988894195520044613">"ජනපදය"</string>
-    <string name="autofill_zip_code" msgid="8697544592627322946">"ZIP කේතය"</string>
-    <string name="autofill_county" msgid="237073771020362891">"ප්‍රාන්තය"</string>
-    <string name="autofill_island" msgid="4020100875984667025">"දූපත"</string>
-    <string name="autofill_district" msgid="8400735073392267672">"දිස්ත්‍රික්කය"</string>
-    <string name="autofill_department" msgid="5343279462564453309">"දෙපාර්තමේන්තුව"</string>
-    <string name="autofill_prefecture" msgid="2028499485065800419">"ප්‍රාන්තය"</string>
-    <string name="autofill_parish" msgid="8202206105468820057">"කෝරලය"</string>
-    <string name="autofill_area" msgid="3547409050889952423">"ප්‍රදේශය"</string>
-    <string name="autofill_emirate" msgid="2893880978835698818">"එමිරේට්"</string>
-    <string name="permlab_readHistoryBookmarks" msgid="3775265775405106983">"ඔබගේ වෙබ් පිටුසන් සහ ඉතිහාසය කියවීම"</string>
-    <string name="permdesc_readHistoryBookmarks" msgid="8462378226600439658">"බ්‍රව්සරය නැරඹූ සියලු URL සහ සියලු බ්‍රව්සර පිටුසන් වල ඉතිහාසය කියවීමට යෙදුමට අවසර දෙන්න. සටහන: වෙබ් බ්‍රව්සර අවශ්‍යතා සමග තෙවෙනි පාර්ශව බ්‍රව්සර වලට හෝ වෙනත් යෙදුම්වලට මෙම අවසරය බල නොදෙයි."</string>
-    <string name="permlab_writeHistoryBookmarks" msgid="3714785165273314490">"වෙබ් පිටුසන් සහ ඉතිහාසයට ලිවිම"</string>
-    <string name="permdesc_writeHistoryBookmarks" product="tablet" msgid="6825527469145760922">"ඔබගේ ටැබ්ලටයේ ගබඩා කර ඇති බ්‍රව්සරයේ ඉතිහාසය හෝ පිටුසන් වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. බ්‍රව්සර දත්ත මැකීමට හෝ වෙනස් කිරීමට මෙමඟින් යෙදුමට අවසර දෙයි. සටහන: වෙබ් ගවේෂණ හැකියාව සහිත තෙවෙනි පාර්ශව බ්‍රව්සර හෝ වෙනත් යෙදුම් වලින් මෙම අවසරයට බල නොකරයි."</string>
-    <string name="permdesc_writeHistoryBookmarks" product="default" msgid="8497389531014185509">"ඔබගේ දුරකථනයේ ආචයනය කරන ලද බ්‍රව්සර ඉතිහාසය හෝ පිටුසන වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. ඔබගේ බ්‍රව්සර දත්ත මැකීමට හෝ වෙනස් කිරීමට අනිෂ්ට යෙදුම් මෙය භාවිත කරයි. සටහන: වෙබ් බ්‍රව්සර අවශ්‍යතාවය සමග තෙවෙනි පාර්ශව බ්‍රව්සර හෝ වෙනත් යෙදුම් විසින් මෙම අවසරය බල ගැන්විය හැක."</string>
-    <string name="permlab_setAlarm" msgid="1379294556362091814">"සීනුවක් සැකසීම"</string>
-    <string name="permdesc_setAlarm" msgid="316392039157473848">"ස්ථාපනය කරන ලද සීනු ඔරලෝසු යෙදුමේ සීනුව සකස් කරන්නට යෙදුමට ඉඩ දෙන්න. ඇතැම් සීනු ඔරලෝසු යෙදුම් මෙම අංගය ක්‍රියාවට නංවා නොතිබීමට ඉඩ තිබේ."</string>
-    <string name="permlab_addVoicemail" msgid="5525660026090959044">"හඬ තැපෑල එක් කිරීම"</string>
-    <string name="permdesc_addVoicemail" msgid="6604508651428252437">"ඔබගේ හඬ තැපෑලේ එන ලිපි වෙත එන පණිවිඩ එකතු කිරීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_writeGeolocationPermissions" msgid="5962224158955273932">"බ්‍රව්සරයේ භූ අවසර වෙනස් කිරීම"</string>
-    <string name="permdesc_writeGeolocationPermissions" msgid="1083743234522638747">"බ්‍රවුසරයේ භූ ස්ථානීය අවසර වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. අභිමත වෙබ් අඩවි වලට ස්ථානීය තොරතුරු යැවීමට අනිෂ්ට යෙදුම් මෙය භාවිතා කෙරේ."</string>
-    <string name="permlab_packageVerificationAgent" msgid="5568139100645829117">"පැකේජ සත්‍යාපනය කරන්න"</string>
-    <string name="permdesc_packageVerificationAgent" msgid="8437590190990843381">"ස්ථාපිත කොට ඇති පැකේජයක් සත්‍යාපනයට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_bindPackageVerifier" msgid="4187786793360326654">"පැකේජ සත්‍යාපකයක් වෙත බඳින්න"</string>
-    <string name="permdesc_bindPackageVerifier" msgid="3180741773233862126">"පැකේජ සත්‍යාපක ඉල්ලීම් වලට දරන්නාට ඉඩ ලබා දේ. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අවශ්‍ය නොවේ."</string>
-    <string name="permlab_serialPort" msgid="546083327654631076">"ශ්‍රේණිගත පොට ප්‍රවේශ කිරීම"</string>
-    <string name="permdesc_serialPort" msgid="2991639985224598193">"SerialManager API භාවිතයෙන් අනුක්‍රම තොට වෙත ප්‍රවේශ වීමට රඳවනයට අවසර දෙන්න."</string>
-    <string name="permlab_accessContentProvidersExternally" msgid="5077774297943409285">"බාහිර අන්තර්ගත සැපයුම්කරුවන් වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_accessContentProvidersExternally" msgid="4544346486697853685">"අන්තර්ගත සපයන්නන්ට ප්‍රවේශ වීමට දරන්නන්ට ෂෙල් එකේ සිට ප්‍රවේශ වීමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා කිසිසේත් අදාළ නොවේ."</string>
-    <string name="permlab_updateLock" msgid="3527558366616680889">"ස්වයංක්‍රීය උපාංග යවත්කාල කිරීම් පසුබට කරන්න"</string>
-    <string name="permdesc_updateLock" msgid="1655625832166778492">"උපාංගය උත්ශ්‍රේණිකරණයට අන්තර්ක්‍රියාකාරී නොවන යළි ඇරඹීමක් සඳහා සුදුසු වෙලාව කුමක්ද යන්න ගැන පද්ධතියට තොරතුරු ලබාදීමට දරන්නාට අවසර දෙන්න."</string>
-    <string name="save_password_message" msgid="767344687139195790">"බ්‍රව්සරයට මෙම මුරපදය මතක තබා ගැනීමට ඔබට අවශ්‍යද?"</string>
-    <string name="save_password_notnow" msgid="6389675316706699758">"දැන් නොවේ"</string>
-    <string name="save_password_remember" msgid="6491879678996749466">"මතක තබා ගන්න"</string>
-    <string name="save_password_never" msgid="8274330296785855105">"කවදාවත් නොවේ"</string>
-    <string name="open_permission_deny" msgid="7374036708316629800">"මෙම පිටුව විවෘත කිරීමට ඔබට අවසර නැත."</string>
-    <string name="text_copied" msgid="4985729524670131385">"පෙළ පසුරු පුවරුවට පිටපත් කරන ලදි."</string>
-    <string name="more_item_label" msgid="4650918923083320495">"තව"</string>
-    <string name="prepend_shortcut_label" msgid="2572214461676015642">"මෙනුව+"</string>
-    <string name="menu_space_shortcut_label" msgid="2410328639272162537">"space"</string>
-    <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"ඇතුල් කරන්න"</string>
-    <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"මකන්න"</string>
-    <string name="search_go" msgid="8298016669822141719">"සෙවීම"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"සෙවීම"</string>
-    <string name="searchview_description_query" msgid="5911778593125355124">"සෙවුම් විමසුම"</string>
-    <string name="searchview_description_clear" msgid="1330281990951833033">"විමසුම හිස් කරන්න"</string>
-    <string name="searchview_description_submit" msgid="2688450133297983542">"විමසුම යොමු කරන්න"</string>
-    <string name="searchview_description_voice" msgid="2453203695674994440">"හඬ සෙවීම"</string>
-    <string name="enable_explore_by_touch_warning_title" msgid="7460694070309730149">"ස්පර්ශ කිරීමෙන් ගවේෂණය සබල කරන්න ද?"</string>
-    <string name="enable_explore_by_touch_warning_message" product="tablet" msgid="8655887539089910577">"ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය කිරීමට <xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ට අවශ්‍යය. ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය විට, ඔබගේ ඇඟිලිවලට පහළ විස්තර ඇසිය හෝ බැලිය හැක හෝ ටැබ්ලටය සමග අන්තර් ක්‍රියාකාරී වීමට ඉංගිති සිදු කළ හැක."</string>
-    <string name="enable_explore_by_touch_warning_message" product="default" msgid="2708199672852373195">"ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය කිරීමට <xliff:g id="ACCESSIBILITY_SERVICE_NAME">%1$s</xliff:g> ට අවශ්‍යයි. ස්පර්ශය වෙතින් ගවේෂණය සක්‍රිය විට, ඔබගේ ඇඟිලිවලට පහළ විස්තර ඇසිය හෝ බැලිය හැක හෝ දුරකථනය සමග අන්තර් ක්‍රියාකාරී වීමට ඉංගිති සිදු කළ හැක."</string>
-    <string name="oneMonthDurationPast" msgid="7396384508953779925">"මාස 1 කට පෙර"</string>
-    <string name="beforeOneMonthDurationPast" msgid="909134546836499826">"මාස 1 කට පෙර"</string>
-  <plurals name="num_seconds_ago">
-    <item quantity="one" msgid="4869870056547896011">"තත්පර 1 කට පෙර"</item>
-    <item quantity="other" msgid="3903706804349556379">"තත්පර <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="num_minutes_ago">
-    <item quantity="one" msgid="3306787433088810191">"මිනිත්තු 1 ට පෙර"</item>
-    <item quantity="other" msgid="2176942008915455116">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="num_hours_ago">
-    <item quantity="one" msgid="9150797944610821849">"පැය 1 කට පෙර"</item>
-    <item quantity="other" msgid="2467273239587587569">"පැය <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="last_num_days">
-    <item quantity="other" msgid="3069992808164318268">"අන්තිම දවස් <xliff:g id="COUNT">%d</xliff:g>"</item>
-  </plurals>
-    <string name="last_month" msgid="3959346739979055432">"අවසාන මාසය"</string>
-    <string name="older" msgid="5211975022815554840">"පරණ"</string>
-  <plurals name="num_days_ago">
-    <item quantity="one" msgid="861358534398115820">"ඊයේ"</item>
-    <item quantity="other" msgid="2479586466153314633">"දින <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="in_num_seconds">
-    <item quantity="one" msgid="2729745560954905102">"තත්පර 1 කින්"</item>
-    <item quantity="other" msgid="1241926116443974687">"තත්පර <xliff:g id="COUNT">%d</xliff:g> කදී"</item>
-  </plurals>
-  <plurals name="in_num_minutes">
-    <item quantity="one" msgid="8793095251325200395">"මිනිත්තු 1 කදී"</item>
-    <item quantity="other" msgid="3330713936399448749">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="in_num_hours">
-    <item quantity="one" msgid="7164353342477769999">"පැය 1 ක් තුළ"</item>
-    <item quantity="other" msgid="547290677353727389">"පැය <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="in_num_days">
-    <item quantity="one" msgid="5413088743009839518">"හෙට"</item>
-    <item quantity="other" msgid="5109449375100953247">"දින <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_num_seconds_ago">
-    <item quantity="one" msgid="1849036840200069118">"තත්පර 1 කට පෙර"</item>
-    <item quantity="other" msgid="3699169366650930415">"තත්පර <xliff:g id="COUNT">%d</xliff:g> කට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_num_minutes_ago">
-    <item quantity="one" msgid="6361490147113871545">"මිනිත්තු 1 කට පෙර"</item>
-    <item quantity="other" msgid="851164968597150710">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_num_hours_ago">
-    <item quantity="one" msgid="4796212039724722116">"පැය 1 කට පෙර"</item>
-    <item quantity="other" msgid="6889970745748538901">"පැය <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_num_days_ago">
-    <item quantity="one" msgid="8463161711492680309">"ඊයේ"</item>
-    <item quantity="other" msgid="3453342639616481191">"දින <xliff:g id="COUNT">%d</xliff:g> ට පෙර"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_seconds">
-    <item quantity="one" msgid="5842225370795066299">"තත්පර 1 ක් තුළ"</item>
-    <item quantity="other" msgid="5495880108825805108">"තත්පර <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_minutes">
-    <item quantity="one" msgid="562786149928284878">"මිනිත්තු 1 ක් තුළ"</item>
-    <item quantity="other" msgid="4216113292706568726">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_hours">
-    <item quantity="one" msgid="3274708118124045246">"පැය 1 ක් තුළ"</item>
-    <item quantity="other" msgid="3705373766798013406">"පැය <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-  <plurals name="abbrev_in_num_days">
-    <item quantity="one" msgid="2178576254385739855">"හෙට"</item>
-    <item quantity="other" msgid="2973062968038355991">"දින <xliff:g id="COUNT">%d</xliff:g> ක් තුළ"</item>
-  </plurals>
-    <string name="preposition_for_date" msgid="9093949757757445117">"<xliff:g id="DATE">%s</xliff:g> වන දා"</string>
-    <string name="preposition_for_time" msgid="5506831244263083793">"<xliff:g id="TIME">%s</xliff:g> ට"</string>
-    <string name="preposition_for_year" msgid="5040395640711867177">"<xliff:g id="YEAR">%s</xliff:g> තුළ"</string>
-    <string name="day" msgid="8144195776058119424">"දවස"</string>
-    <string name="days" msgid="4774547661021344602">"දින"</string>
-    <string name="hour" msgid="2126771916426189481">"පැය"</string>
-    <string name="hours" msgid="894424005266852993">"පැය"</string>
-    <string name="minute" msgid="9148878657703769868">"min"</string>
-    <string name="minutes" msgid="5646001005827034509">"මිනිත්තු"</string>
-    <string name="second" msgid="3184235808021478">"තත්"</string>
-    <string name="seconds" msgid="3161515347216589235">"තත්පර"</string>
-    <string name="week" msgid="5617961537173061583">"සතිය"</string>
-    <string name="weeks" msgid="6509623834583944518">"සති"</string>
-    <string name="year" msgid="4001118221013892076">"අවුරුද්ද"</string>
-    <string name="years" msgid="6881577717993213522">"අවුරුදු"</string>
-  <plurals name="duration_seconds">
-    <item quantity="one" msgid="6962015528372969481">"තත්පර 1"</item>
-    <item quantity="other" msgid="1886107766577166786">"තත්පර <xliff:g id="COUNT">%d</xliff:g>"</item>
-  </plurals>
-  <plurals name="duration_minutes">
-    <item quantity="one" msgid="4915414002546085617">"මිනිත්තු 1"</item>
-    <item quantity="other" msgid="3165187169224908775">"මිනිත්තු <xliff:g id="COUNT">%d</xliff:g>"</item>
-  </plurals>
-  <plurals name="duration_hours">
-    <item quantity="one" msgid="8917467491248809972">"පැය 1"</item>
-    <item quantity="other" msgid="3863962854246773930">"පැය <xliff:g id="COUNT">%d</xliff:g> ක්"</item>
-  </plurals>
-    <string name="VideoView_error_title" msgid="3534509135438353077">"වීඩියෝ ගැටලුව"</string>
-    <string name="VideoView_error_text_invalid_progressive_playback" msgid="3186670335938670444">"මේ වීඩියෝව මෙම උපාංගයට ප්‍රවාහනය සඳහා වලංගු නැත."</string>
-    <string name="VideoView_error_text_unknown" msgid="3450439155187810085">"මෙම වීඩියෝව ධාවනය කළ නොහැක."</string>
-    <string name="VideoView_error_button" msgid="2822238215100679592">"හරි"</string>
-    <string name="relative_time" msgid="1818557177829411417">"<xliff:g id="DATE">%1$s</xliff:g>, <xliff:g id="TIME">%2$s</xliff:g>"</string>
-    <string name="noon" msgid="7245353528818587908">"මධ්‍යහනය"</string>
-    <string name="Noon" msgid="3342127745230013127">"මධ්‍යාහනය"</string>
-    <string name="midnight" msgid="7166259508850457595">"මධ්‍යම රාත්‍රිය"</string>
-    <string name="Midnight" msgid="5630806906897892201">"මධ්‍යම රාත්‍රිය"</string>
-    <string name="elapsed_time_short_format_mm_ss" msgid="4431555943828711473">"<xliff:g id="MINUTES">%1$02d</xliff:g>:<xliff:g id="SECONDS">%2$02d</xliff:g>"</string>
-    <string name="elapsed_time_short_format_h_mm_ss" msgid="1846071997616654124">"<xliff:g id="HOURS">%1$d</xliff:g>:<xliff:g id="MINUTES">%2$02d</xliff:g>:<xliff:g id="SECONDS">%3$02d</xliff:g>"</string>
-    <string name="selectAll" msgid="6876518925844129331">"සියල්ල තෝරන්න"</string>
-    <string name="cut" msgid="3092569408438626261">"කපන්න"</string>
-    <string name="copy" msgid="2681946229533511987">"පිටපත් කරන්න"</string>
-    <string name="paste" msgid="5629880836805036433">"අලවන්න"</string>
-    <string name="replace" msgid="5781686059063148930">"ප්‍රතිස්ථාපනය කරන්න..."</string>
-    <string name="delete" msgid="6098684844021697789">"මකන්න"</string>
-    <string name="copyUrl" msgid="2538211579596067402">"URL පිටපත් කරන්න"</string>
-    <string name="selectTextMode" msgid="1018691815143165326">"පෙළ තෝරන්න"</string>
-    <string name="textSelectionCABTitle" msgid="5236850394370820357">"පෙළ තේරීම"</string>
-    <string name="addToDictionary" msgid="4352161534510057874">"ශබ්ද කෝෂයට එකතු කරන්න"</string>
-    <string name="deleteText" msgid="6979668428458199034">"මකන්න"</string>
-    <string name="inputMethod" msgid="1653630062304567879">"ආදාන ක්‍රමය"</string>
-    <string name="editTextMenuTitle" msgid="4909135564941815494">"පෙළ ක්‍රියාවන්"</string>
-    <string name="low_internal_storage_view_title" msgid="5576272496365684834">"ආචයනය ඉඩ ප්‍රමාණය අඩු වී ඇත"</string>
-    <string name="low_internal_storage_view_text" msgid="6640505817617414371">"සමහර පද්ධති කාර්යයන් ක්‍රියා නොකරනු ඇත"</string>
-    <string name="app_running_notification_title" msgid="8718335121060787914">"<xliff:g id="APP_NAME">%1$s</xliff:g> ධාවනය වේ"</string>
-    <string name="app_running_notification_text" msgid="4653586947747330058">"වැඩිපුර තොරතුරු හෝ යෙදුම නැවතීම සඳහා ස්පර්ශ කරන්න."</string>
-    <string name="ok" msgid="5970060430562524910">"හරි"</string>
-    <string name="cancel" msgid="6442560571259935130">"අවලංගු කරන්න"</string>
-    <string name="yes" msgid="5362982303337969312">"හරි"</string>
-    <string name="no" msgid="5141531044935541497">"අවලංගු කරන්න"</string>
-    <string name="dialog_alert_title" msgid="2049658708609043103">"අවධානය"</string>
-    <string name="loading" msgid="7933681260296021180">"පූරණය වෙමින්..."</string>
-    <string name="capital_on" msgid="1544682755514494298">"සක්‍රීයයි"</string>
-    <string name="capital_off" msgid="6815870386972805832">"අක්‍රිය කරන්න"</string>
-    <string name="whichApplication" msgid="4533185947064773386">"පහත භාවිතයෙන් ක්‍රියාව සම්පූර්ණ කරන්න"</string>
-    <string name="alwaysUse" msgid="4583018368000610438">"මෙම ක්‍රියාව සඳහා සුපුරුද්දෙන් භාවිත කරන්න."</string>
-    <string name="clearDefaultHintMsg" msgid="3252584689512077257">"පද්ධති සැකසීම් &gt; යෙදුම් &gt; බාගැනීම් තුළ ඇති සුපුරුද්ද හිස් කරන්න."</string>
-    <string name="chooseActivity" msgid="7486876147751803333">"ක්‍රියාවක් තෝරන්න"</string>
-    <string name="chooseUsbActivity" msgid="6894748416073583509">"USB උපාංගය සඳහා යෙදුමක් තෝරන්න"</string>
-    <string name="noApplications" msgid="2991814273936504689">"මෙම ක්‍රියාව සිදු කිරීමට කිසිදු යෙදුමකට නොහැකිය."</string>
-    <string name="aerr_title" msgid="1905800560317137752"></string>
-    <string name="aerr_application" msgid="932628488013092776">"අවාසනාවන්ත ලෙස <xliff:g id="APPLICATION">%1$s</xliff:g> නැවතී ඇත."</string>
-    <string name="aerr_process" msgid="4507058997035697579">"අවාසනාවන්ත ලෙස, <xliff:g id="PROCESS">%1$s</xliff:g> ක්‍රියාවලිය නතර විණි."</string>
-    <string name="anr_title" msgid="4351948481459135709"></string>
-    <string name="anr_activity_application" msgid="1904477189057199066">"<xliff:g id="APPLICATION">%2$s</xliff:g> ප්‍රතිචාර නොදක්වයි.\n\nඔබට එය නතර කිරීමට අවශ්‍යද?"</string>
-    <string name="anr_activity_process" msgid="5776209883299089767">"<xliff:g id="ACTIVITY">%1$s</xliff:g> ක්‍රියාකාරකම ප්‍රතිචාර නොදක්වයි.\n\nඑය වසා දැමීමට ඔබට අවශ්‍යද?"</string>
-    <string name="anr_application_process" msgid="8941757607340481057">"<xliff:g id="APPLICATION">%1$s</xliff:g> ප්‍රතිචාර නොදක්වයි. එය වසා දැමීමට ඔබට අවශ්‍යද?"</string>
-    <string name="anr_process" msgid="6513209874880517125">"<xliff:g id="PROCESS">%1$s</xliff:g> ක්‍රියාවලිය ප්‍රතිචාර නොදක්වයි.\n\nඔබට එය නතර කිරීමට අවශ්‍යද?"</string>
-    <string name="force_close" msgid="8346072094521265605">"හරි"</string>
-    <string name="report" msgid="4060218260984795706">"වාර්තාව"</string>
-    <string name="wait" msgid="7147118217226317732">"රැඳී සිටින්න"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"පිටුව ප්‍රතිචාර නොදක්වන තත්වයට පත්වී ඇත.\n\nඔබට එය වැසීමට අවශ්‍යද?"</string>
-    <string name="launch_warning_title" msgid="1547997780506713581">"යෙදුම නැවත හරවා යවා ඇත"</string>
-    <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> දැන් ධාවනය වෙයි."</string>
-    <string name="launch_warning_original" msgid="188102023021668683">"<xliff:g id="APP_NAME">%1$s</xliff:g> මුලින්ම අරඹා ඇත."</string>
-    <string name="screen_compat_mode_scale" msgid="3202955667675944499">"පරිමාණය"</string>
-    <string name="screen_compat_mode_show" msgid="4013878876486655892">"සැමවිටම පෙන්වන්න"</string>
-    <string name="screen_compat_mode_hint" msgid="1064524084543304459">"පද්ධති සැකසීම් තුළ මෙය නැවත ක්‍රියාත්මක කරන්න &gt; යෙදුම් &gt; බාගන්නා ලදි."</string>
-    <string name="smv_application" msgid="3307209192155442829">"<xliff:g id="APPLICATION">%1$s</xliff:g> යෙදුම (<xliff:g id="PROCESS">%2$s</xliff:g> ක්‍රියාවලිය) එහි StrictMode කොන්දේසිය උල්ලංඝනය කර ඇත."</string>
-    <string name="smv_process" msgid="5120397012047462446">"<xliff:g id="PROCESS">%1$s</xliff:g> ක්‍රියාවලිය එහි StrictMode කොන්දේසිය උල්ලංඝනය කර ඇත."</string>
-    <string name="android_upgrading_title" msgid="1584192285441405746">"Android උත්ශ්‍රේණි වෙමින් පවතී..."</string>
-    <string name="android_upgrading_apk" msgid="7904042682111526169">"<xliff:g id="NUMBER_1">%2$d</xliff:g> කින් <xliff:g id="NUMBER_0">%1$d</xliff:g> වැනි යෙදුමප්‍ රශස්ත කරමින්."</string>
-    <string name="android_upgrading_starting_apps" msgid="451464516346926713">"යෙදුම් ආරම්භ කරමින්."</string>
-    <string name="android_upgrading_complete" msgid="1405954754112999229">"ඇරඹුම අවසාන කරමින්."</string>
-    <string name="heavy_weight_notification" msgid="9087063985776626166">"<xliff:g id="APP">%1$s</xliff:g> ධාවනය වෙමින්"</string>
-    <string name="heavy_weight_notification_detail" msgid="1721681741617898865">"යෙදුමට මාරු වීමට ස්පර්ශ කරන්න"</string>
-    <string name="heavy_weight_switcher_title" msgid="7153167085403298169">"යෙදුම් මාරු වනවාද?"</string>
-    <string name="heavy_weight_switcher_text" msgid="7022631924534406403">"අලුත් යෙදුමක් ආරම්භ කිරීමට පෙර තවමත් ක්‍රියාවෙහි යෙදෙමින් පවතින යෙදුම නැවැත්විය යුතුයි."</string>
-    <string name="old_app_action" msgid="493129172238566282">"<xliff:g id="OLD_APP">%1$s</xliff:g> වෙත ආපසු යන්න"</string>
-    <string name="old_app_description" msgid="2082094275580358049">"නව යෙදුම ආරම්භ නොකරන්න."</string>
-    <string name="new_app_action" msgid="5472756926945440706">"<xliff:g id="OLD_APP">%1$s</xliff:g> අරඹන්න"</string>
-    <string name="new_app_description" msgid="1932143598371537340">"සුරැකීමකින් තොරව පරණ යෙදුම නවත්වන්න."</string>
-    <string name="sendText" msgid="5209874571959469142">"පෙළ සඳහා ක්‍රියාව තෝරන්න"</string>
-    <string name="volume_ringtone" msgid="6885421406845734650">"හඬ නඟනයේ ශබ්දය"</string>
-    <string name="volume_music" msgid="5421651157138628171">"මාධ්‍ය ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_music_hint_playing_through_bluetooth" msgid="9165984379394601533">"බ්ලූටූත් හරහා ධාවනය වෙයි"</string>
-    <string name="volume_music_hint_silent_ringtone_selected" msgid="8310739960973156272">"නිහඬ රිගින් ටෝනයක් සකසන්න"</string>
-    <string name="volume_call" msgid="3941680041282788711">"ඇමතුම-තුළ ශබ්ද ත්‍රීවතාව"</string>
-    <string name="volume_bluetooth_call" msgid="2002891926351151534">"බ්ලූටූත් ඇමතුම-තුළ ශබ්ද ත්‍රීවතාවය"</string>
-    <string name="volume_alarm" msgid="1985191616042689100">"සීනුවේ ශබ්දය"</string>
-    <string name="volume_notification" msgid="2422265656744276715">"දැනුම්දීමේ ශබ්දය"</string>
-    <string name="volume_unknown" msgid="1400219669770445902">"ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_icon_description_bluetooth" msgid="6538894177255964340">"බ්ලූටූත් ශබ්ද ත්‍රීවතාව"</string>
-    <string name="volume_icon_description_ringer" msgid="3326003847006162496">"රින්ටෝනයේ ශබ්දය"</string>
-    <string name="volume_icon_description_incall" msgid="8890073218154543397">"ඇමතුම් ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_icon_description_media" msgid="4217311719665194215">"මාධ්‍ය ශබ්දය ත්‍රීවතාවය"</string>
-    <string name="volume_icon_description_notification" msgid="7044986546477282274">"දැනුම්දීමේ ශබ්ද ත්‍රීවතාව"</string>
-    <string name="ringtone_default" msgid="3789758980357696936">"සුපුරුදු රින්ටෝනය සකසන්න"</string>
-    <string name="ringtone_default_with_actual" msgid="8129563480895990372">"සුපුරුදු රින්ටෝනය (<xliff:g id="ACTUAL_RINGTONE">%1$s</xliff:g>)"</string>
-    <string name="ringtone_silent" msgid="7937634392408977062">"කිසිවක් නැත"</string>
-    <string name="ringtone_picker_title" msgid="3515143939175119094">"රිගින්ටෝන"</string>
-    <string name="ringtone_unknown" msgid="5477919988701784788">"නොදන්නා රින්ටෝනය"</string>
-  <plurals name="wifi_available">
-    <item quantity="one" msgid="6654123987418168693">"Wi-Fi ජාලයක් තිබේ"</item>
-    <item quantity="other" msgid="4192424489168397386">"Wi-Fi ජාල ඇත"</item>
-  </plurals>
-  <plurals name="wifi_available_detailed">
-    <item quantity="one" msgid="1634101450343277345">"විවෘත Wi-Fi ජාලය ලබාගත හැක"</item>
-    <item quantity="other" msgid="7915895323644292768">"විවෘත Wi-Fi ජාල තිබේ"</item>
-  </plurals>
-    <string name="wifi_available_sign_in" msgid="4029489716605255386">"Wi-Fi ජලයට පුරනය වන්න"</string>
-    <string name="network_available_sign_in" msgid="8495155593358054676">"ජාලයට පුරනය වන්න"</string>
-    <!-- no translation found for network_available_sign_in_detailed (8000081941447976118) -->
-    <skip />
-    <string name="wifi_watchdog_network_disabled" msgid="7904214231651546347">"Wi-Fi වෙත සම්බන්ධ විය නොහැක"</string>
-    <string name="wifi_watchdog_network_disabled_detailed" msgid="5548780776418332675">" දුබල අන්තර්ජාල සම්බන්ධතාවයක් ඇත."</string>
-    <string name="wifi_p2p_dialog_title" msgid="97611782659324517">"ඍජු Wi-Fi"</string>
-    <string name="wifi_p2p_turnon_message" msgid="2909250942299627244">"ඍජු Wi-Fi ආරම්භ කරන්න. මෙය Wi-Fi සේවාදායක/හොට්ස්පොට් එක අක්‍රිය කරනු ඇත."</string>
-    <string name="wifi_p2p_failed_message" msgid="3763669677935623084">"ඍජු Wi-Fi ආරම්භ කළ නොහැක."</string>
-    <string name="wifi_p2p_enabled_notification_title" msgid="2068321881673734886">"Wi-Fi ඍජු සම්බන්ධතාව සක්‍රියයි"</string>
-    <string name="wifi_p2p_enabled_notification_message" msgid="1638949953993894335">"සැකසීම් සඳහා ස්පර්ශ කරන්න"</string>
-    <string name="accept" msgid="1645267259272829559">"පිළිගන්න"</string>
-    <string name="decline" msgid="2112225451706137894">"ප්‍රතික්ෂේප කරන්න"</string>
-    <string name="wifi_p2p_invitation_sent_title" msgid="1318975185112070734">"ආරාධනාව යවන ලදි"</string>
-    <string name="wifi_p2p_invitation_to_connect_title" msgid="4958803948658533637">"සම්බන්ධතාවයට ඇරයුමකි"</string>
-    <string name="wifi_p2p_from_message" msgid="570389174731951769">"වෙතින්:"</string>
-    <string name="wifi_p2p_to_message" msgid="248968974522044099">"වෙත:"</string>
-    <string name="wifi_p2p_enter_pin_message" msgid="5920929550367828970">"අවශ්‍ය PIN එක ටයිප් කරන්න:"</string>
-    <string name="wifi_p2p_show_pin_message" msgid="8530563323880921094">"PIN:"</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="tablet" msgid="8012981257742232475">"ටැබ්ලටය <xliff:g id="DEVICE_NAME">%1$s</xliff:g> වෙත සම්බන්ධ වන අතරතුර එය Wi-Fi වලින් තාවකාලිකව විසන්ධි කෙරේ."</string>
-    <string name="wifi_p2p_frequency_conflict_message" product="default" msgid="7363907213787469151">"දුරකථනය <xliff:g id="DEVICE_NAME">%1$s</xliff:g> ට සම්බන්ධ වී පවතින විට Wi-Fi වලින් එය තාවකාලිකව විසන්ධි වෙයි."</string>
-    <string name="select_character" msgid="3365550120617701745">"අකුර ඇතුළත් කරන්න"</string>
-    <string name="sms_control_title" msgid="7296612781128917719">"SMS පණිවිඩ යවමින්"</string>
-    <string name="sms_control_message" msgid="3867899169651496433">"&lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;/b&gt; SMS පණිවිඩ විශාල ගණනක් යවයි. මෙම යෙදුමට පණිවිඩ යැවීම නොනැවතී කරගෙන යාමට අවසර දීමට ඔබට අවශ්‍යද?"</string>
-    <string name="sms_control_yes" msgid="3663725993855816807">"අවසර දෙන්න"</string>
-    <string name="sms_control_no" msgid="625438561395534982">"ප්‍රතික්ෂේප කරන්න"</string>
-    <string name="sms_short_code_confirm_message" msgid="1645436466285310855">"&lt;b&gt;<xliff:g id="DEST_ADDRESS">%2$s</xliff:g>&lt;b&gt; වෙත කෙටි පණිවීඩයක් යැවීමට &lt;b&gt;<xliff:g id="APP_NAME">%1$s</xliff:g>&lt;b&gt; කැමතිය."</string>
-    <!-- syntax error in translation for sms_short_code_details (3492025719868078457) org.xmlpull.v1.XmlPullParserException: expected: /string read: font (position:END_TAG </font>@1:83 in     <string name="sms_short_code_details" msgid="3492025719868078457">"මෙය "</font>"ඔබගේ ජංගම ගිණුමේ"<font fgcolor="#ffffb060">" අය වීම් වලට හේතුවක් වේ."</string>
-)  -->
-    <string name="sms_premium_short_code_details" msgid="5523826349105123687"><font fgcolor="#ffffb060">"මෙය ඔබගේ ජංගම ගිණුමෙන් අයවීමට හේතු වේ."</font></string>
-    <string name="sms_short_code_confirm_allow" msgid="4458878637111023413">"යවන්න"</string>
-    <string name="sms_short_code_confirm_deny" msgid="2927389840209170706">"අවලංගු කරන්න"</string>
-    <string name="sms_short_code_remember_choice" msgid="5289538592272218136">"මගේ තේරීම මතක තබාගන්න"</string>
-    <string name="sms_short_code_remember_undo_instruction" msgid="4960944133052287484">"ඔබට මෙය සැකසීම් තුළ වෙනස්කර ගැනීම පසුව කළ හැක &gt; යෙදුම්"</string>
-    <string name="sms_short_code_confirm_always_allow" msgid="3241181154869493368">"සැමවිටම ඉඩ දෙන්න"</string>
-    <string name="sms_short_code_confirm_never_allow" msgid="446992765774269673">"කිසිදා අවසර නොදෙන්න"</string>
-    <string name="sim_removed_title" msgid="6227712319223226185">"SIM පත ඉවත් කරන ලදි"</string>
-    <string name="sim_removed_message" msgid="2333164559970958645">"ඔබ ඇතුළත් කරන ලද වලංගු SIM පත සමඟ නැවත ඇරඹීම කරන තුරු ජංගම ජාලය නොතිබේ."</string>
-    <string name="sim_done_button" msgid="827949989369963775">"හරි"</string>
-    <string name="sim_added_title" msgid="3719670512889674693">"SIM පතක් එකතු කරන ලදි"</string>
-    <string name="sim_added_message" msgid="6599945301141050216">"ජංගම ජාලයට ප්‍රවේශ වීමට ඔබගේ උපාංගය නැවත අරඹන්න."</string>
-    <string name="sim_restart_button" msgid="4722407842815232347">"යළි අරඹන්න"</string>
-    <string name="time_picker_dialog_title" msgid="8349362623068819295">"වේලාව සකසන්න"</string>
-    <string name="date_picker_dialog_title" msgid="5879450659453782278">"දිනය සැකසීම"</string>
-    <string name="date_time_set" msgid="5777075614321087758">"සකසන්න"</string>
-    <string name="date_time_done" msgid="2507683751759308828">"හරි"</string>
-    <string name="perms_new_perm_prefix" msgid="8257740710754301407"><font size="12" fgcolor="#ff33b5e5">"අලුත්: "</font></string>
-    <string name="perms_description_app" msgid="5139836143293299417">"<xliff:g id="APP_NAME">%1$s</xliff:g> විසින් සපයන ලදි."</string>
-    <string name="no_permissions" msgid="7283357728219338112">"අවසර අවශ්‍ය නොමැත"</string>
-    <string name="perm_costs_money" msgid="4902470324142151116">"මෙමඟින් ඔබට මුදල් වැය විය හැක"</string>
-    <string name="usb_storage_activity_title" msgid="4465055157209648641">"USB මහා ආචයනය"</string>
-    <string name="usb_storage_title" msgid="5901459041398751495">"USB සම්බන්ධිතයි"</string>
-    <string name="usb_storage_message" product="nosdcard" msgid="3308538094316477839">"ඔබ ඔබගේ පරිගණකයට සම්බන්ධ වී ඇත්තේ USB ස්පර්ශය හරහාය. ඔබට ඔබේ පරිගණකය හා ඔබගේ Android USB ආචයනය අතර ගොනු පිටපත් කිරීමට අවශ්‍ය නම් පහත බොත්තම ඔබන්න."</string>
-    <string name="usb_storage_message" product="default" msgid="805351000446037811">"ඔබ ඔබගේ පරිගණකයට USB හරහා සම්බන්ධ වී ඇත. ඔබට ඔබේ පරිගණකය හා ඔබගේ Android SD පත අතර ගොනු පිටපත් කිරීමට අවශ්‍ය නම් පහත බොත්තම ස්පර්ශ කරන්න."</string>
-    <string name="usb_storage_button_mount" msgid="1052259930369508235">"USB ආචයනය සක්‍රිය කරන්න"</string>
-    <string name="usb_storage_error_message" product="nosdcard" msgid="3017045217365540658">"USB මහා ආචයනය සඳහා ඔබගේ USB ආචයනය භාවිතයේදී ගැටළුවක් තිබේ."</string>
-    <string name="usb_storage_error_message" product="default" msgid="2876018512716970313">"USB මහා ආචයනය සඳහා ඔබගේ SD පත භාවිතයේදී ගැටළුවක් තිබේ."</string>
-    <string name="usb_storage_notification_title" msgid="8175892554757216525">"USB සම්බන්ධිතයි"</string>
-    <string name="usb_storage_notification_message" msgid="939822783828183763">"ඔබගේ පරිගණකය වෙතට/වෙතින් ගොනු පිටපත් කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="usb_storage_stop_notification_title" msgid="2336058396663516017">"USB ආචයනය අක්‍රිය කරන්න"</string>
-    <string name="usb_storage_stop_notification_message" msgid="1656852098555623822">"USB ආචයනය අක්‍රිය කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="usb_storage_stop_title" msgid="660129851708775853">"USB ආචයනය භාවිතයේ පවතී"</string>
-    <string name="usb_storage_stop_message" product="nosdcard" msgid="4264025280777219521">"USB ආචයනය අක්‍රිය කිරීමට පෙර, ඔබගේ පරිගණකයෙන් Android USB ආචයනය ගලවා දමන්න (\"පිට කරන්න\")."</string>
-    <string name="usb_storage_stop_message" product="default" msgid="8043969782460613114">"USB ආචයනය අක්‍රිය කිරීමට පෙර, ඔබගේ Android SD පත පරිගණකයෙන් ගලවන්න."</string>
-    <string name="usb_storage_stop_button_mount" msgid="7060218034900696029">"USB ආචයනය අක්‍රිය කරන්න"</string>
-    <string name="usb_storage_stop_error_message" msgid="1970374898263063836">"USB ආචයනය අක්‍රිය කිරීමේදී ගැටළුවක් ඇතිවිය. USB සංග්‍රාහකය ගලවා ඇති දැයි පරීක්ෂා කරන්න, පසුව නැවතත් උත්සහ කරන්න."</string>
-    <string name="dlg_confirm_kill_storage_users_title" msgid="963039033470478697">"USB ආචයනය සක්‍රිය කරන්න"</string>
-    <string name="dlg_confirm_kill_storage_users_text" msgid="5100428757107469454">"ඔබ USB ආචයනය සක්‍රිය නම්, ඔබ භාවිතා කරන සමහර යෙදුම් නැවතීම සහ ඔබ USB ආචයනය අක්‍රිය කරන තුරු නොතිබේවී."</string>
-    <string name="dlg_error_title" msgid="7323658469626514207">"USB ක්‍රියාවලිය අසාර්ථකයි"</string>
-    <string name="dlg_ok" msgid="7376953167039865701">"හරි"</string>
-    <string name="usb_mtp_notification_title" msgid="3699913097391550394">"මාධ්‍ය උපාංගයක් ලෙස සම්බන්ධිතයි"</string>
-    <string name="usb_ptp_notification_title" msgid="1960817192216064833">"කැමරාවක් ලෙස සම්බන්ධ කර ඇත"</string>
-    <string name="usb_cd_installer_notification_title" msgid="6774712827892090754">"ස්ථාපිතයක් ලෙස සම්බන්ධයි"</string>
-    <string name="usb_accessory_notification_title" msgid="7848236974087653666">"USB මෙවලමකට සම්බන්ධිතයි"</string>
-    <string name="usb_notification_message" msgid="2290859399983720271">"අනෙක් USB විකල්පය සඳහා ස්පර්ශ කරන්න."</string>
-    <string name="extmedia_format_title" product="nosdcard" msgid="9020092196061007262">"USB ආචයනය ෆෝමැට් කරන්නද?"</string>
-    <string name="extmedia_format_title" product="default" msgid="3648415921526526069">"SD පත ෆෝමැට් කරන්නද?"</string>
-    <string name="extmedia_format_message" product="nosdcard" msgid="3934016853425761078">"ඔබගේ USB ආචයනයේ ඇති සියලුම ගොනු මැකී යනු ඇත. මෙම ක්‍රියාව ආපසු හැරවිය නොහැක!"</string>
-    <string name="extmedia_format_message" product="default" msgid="14131895027543830">"ඔබගේ පතේ සියලු දත්ත නැති වනු ඇත."</string>
-    <string name="extmedia_format_button_format" msgid="4131064560127478695">"ෆෝමැට්"</string>
-    <string name="adb_active_notification_title" msgid="6729044778949189918">"USB නිදොස්කරණය සම්බන්ධිතයි"</string>
-    <string name="adb_active_notification_message" msgid="1016654627626476142">"USB නිදොස්කරණය අබල කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="select_input_method" msgid="4653387336791222978">"ආදාන ක්‍රමයක් තෝරන්න"</string>
-    <string name="configure_input_methods" msgid="9091652157722495116">"ආදාන ක්‍රම සකසන්න"</string>
-    <string name="use_physical_keyboard" msgid="6203112478095117625">"භෞතික යතුරු පුවරුව"</string>
-    <string name="hardware" msgid="7517821086888990278">"දෘඨාංග"</string>
-    <string name="select_keyboard_layout_notification_title" msgid="1407367017263030773">"යතුරු පුවරුවට පිරිසැලැස්ම තෝරන්න"</string>
-    <string name="select_keyboard_layout_notification_message" msgid="4465907700449257063">"යතුරු පුවරුවට පිරිසැලැස්මක් තේරීමට ස්පර්ශ කරන්න."</string>
-    <string name="fast_scroll_alphabet" msgid="5433275485499039199">" ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="fast_scroll_numeric_alphabet" msgid="4030170524595123610">" 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"</string>
-    <string name="candidates_style" msgid="4333913089637062257"><u>"අපේක්ෂකයන්"</u></string>
-    <string name="ext_media_checking_notification_title" product="nosdcard" msgid="3449816005351468560">"USB ආචයනය සකසමින්"</string>
-    <string name="ext_media_checking_notification_title" product="default" msgid="5457603418970994050">"SD පත සුදානම් කරමින්"</string>
-    <string name="ext_media_checking_notification_message" msgid="8287319882926737053">"වැරදි සඳහා පරීක්ෂා කරමින්."</string>
-    <string name="ext_media_nofs_notification_title" product="nosdcard" msgid="7788040745686229307">"හිස් USB ආචයනය"</string>
-    <string name="ext_media_nofs_notification_title" product="default" msgid="780477838241212997">"හිස් SD පත"</string>
-    <string name="ext_media_nofs_notification_message" product="nosdcard" msgid="7840121067427269500">"SD පත හිස් හෝ සහාය නොදක්වන ගොනු පද්ධතියක් ඇත."</string>
-    <string name="ext_media_nofs_notification_message" product="default" msgid="8641065641786923604">"SD පත හිස් හෝ සහය නොදක්වන ගොනු පද්ධතියක් ඇත"</string>
-    <string name="ext_media_unmountable_notification_title" product="nosdcard" msgid="2090046769532713563">"හානි වූ USB ආචයනය"</string>
-    <string name="ext_media_unmountable_notification_title" product="default" msgid="6410723906019100189">"හානි වූ SD පත"</string>
-    <string name="ext_media_unmountable_notification_message" product="nosdcard" msgid="1795917578395333280">"USB ආචයනයට හානි වී ඇත. එය නැවත ෆෝමැට් ගැන්වීමට උත්සහ කරන්න."</string>
-    <string name="ext_media_unmountable_notification_message" product="default" msgid="1753898567525568253">"SD පතට හානි වී ඇත. එය නැවත ෆෝමැට් ගැන්වීමට උත්සහ කරන්න."</string>
-    <string name="ext_media_badremoval_notification_title" product="nosdcard" msgid="1661683031330951073">"බලාපොරොත්තු නොවූ ලෙස USB ආචයනය ඉවත් කෙරිණි"</string>
-    <string name="ext_media_badremoval_notification_title" product="default" msgid="6872152882604407837">"SD පත බලාපොරොත්තු රහිතව ඉවත් කරන ලදි"</string>
-    <string name="ext_media_badremoval_notification_message" product="nosdcard" msgid="4329848819865594241">"දත්ත නැතිවීම වැළක්වීමට USB ආචයනය ඉවත්කිරීමට පෙර ගලවන්න."</string>
-    <string name="ext_media_badremoval_notification_message" product="default" msgid="7260183293747448241">"දත්ත නැතිවීම වැළක්වීමට ගැලවීමට කලින් SD පත ඉවත් කරන්න."</string>
-    <string name="ext_media_safe_unmount_notification_title" product="nosdcard" msgid="3967973893270360230">"ඉවත් කිරීමට USB ආචයනය ආරක්ෂිතයි"</string>
-    <string name="ext_media_safe_unmount_notification_title" product="default" msgid="6729801130790616200">"SD පත ඉවත් කිරීමට සුරක්ෂිතයි"</string>
-    <string name="ext_media_safe_unmount_notification_message" product="nosdcard" msgid="6142195361606493530">"ඔබට USB ආචයනය ආරක්ෂිතව ඉවත් කිරීමට පුළුවනි."</string>
-    <string name="ext_media_safe_unmount_notification_message" product="default" msgid="568841278138377604">"ඔබට ආරක්ෂිතව SD පත ඉවත් කළ හැක"</string>
-    <string name="ext_media_nomedia_notification_title" product="nosdcard" msgid="4486377230140227651">"USB ආචයනය ඉවත් කරන ලදි"</string>
-    <string name="ext_media_nomedia_notification_title" product="default" msgid="8902518030404381318">"SD පත ඉවත් කර ඇත"</string>
-    <string name="ext_media_nomedia_notification_message" product="nosdcard" msgid="6921126162580574143">"USB ආචයනය ඉවත්කොට ඇත. අලුත් මාධ්‍යයක් ඇතුළත් කරන්න."</string>
-    <string name="ext_media_nomedia_notification_message" product="default" msgid="3870120652983659641">"SD පත ඉවත් කරන ලදි. අලුත් එකක් ඇතුළත් කරන්න."</string>
-    <string name="activity_list_empty" msgid="1675388330786841066">"ගැලපෙන ක්‍රියාකාරකම් හමු නොවුණි."</string>
-    <string name="permlab_pkgUsageStats" msgid="8787352074326748892">"සංරචකය භාවිත කිරීමේ සංඛ්‍යාන යාවත්කාලීන කරන්න"</string>
-    <string name="permdesc_pkgUsageStats" msgid="1106612424254277630">"එකතු කරන ලද සංරචකය භාවිතා සංඛ්‍යාන වෙනස් කිරීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම් සඳහා නොවේ."</string>
-    <string name="permlab_copyProtectedData" msgid="4341036311211406692">"අන්තර්ගතය පිටපත් කරන්න"</string>
-    <string name="permdesc_copyProtectedData" msgid="4390697124288317831">"අන්තර්ගතය පිටපත් කිරීමට සුපුරුදු අන්තර්ගත සේවාව ඉල්වා සිටීමට යෙදුමට අවසර දෙන්න. සාමාන්‍ය යෙදුම්වල භාවිතය සඳහා නොවේ."</string>
-    <string name="permlab_route_media_output" msgid="1642024455750414694">"මාධ්‍ය ප්‍රතිදානයේ මාර්ගගත කිරීම"</string>
-    <string name="permdesc_route_media_output" msgid="4932818749547244346">"වෙනත් බාහිර උපාංග වෙත මාධ්‍ය ප්‍රතිදානය යැවීමට යෙදුමට අවසර දෙන්න."</string>
-    <string name="permlab_access_keyguard_secure_storage" msgid="7565552237977815047">"යතුරු පාලක ආරක්‍ෂිත ආචයනය වෙත ප්‍රවේශය"</string>
-    <string name="permdesc_access_keyguard_secure_storage" msgid="5866245484303285762">"යතුරු ආරක්ෂක ආචයනයට ප්‍රවේශ වීමට යෙදුමට දෙයි."</string>
-    <string name="permlab_control_keyguard" msgid="172195184207828387">"පෙන්වීමේ හා සැඟවීමේ යතුරු ආරක්ෂකය පාලනය කරන්න"</string>
-    <string name="permdesc_control_keyguard" msgid="3043732290518629061">"යතුරු ආරක්ෂකය පාලනයට යෙදුමකට අවසර දෙන්න."</string>
-    <string name="tutorial_double_tap_to_zoom_message_short" msgid="4070433208160063538">"විශාලන පාලනය සඳහා දෙවරක් ස්පර්ශ කරන්න"</string>
-    <string name="gadget_host_error_inflating" msgid="4882004314906466162">"විජටය එකතු කිරීමට නොහැකි විය."</string>
-    <string name="ime_action_go" msgid="8320845651737369027">"යන්න"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"සෙවීම"</string>
-    <string name="ime_action_send" msgid="2316166556349314424">"යවන්න"</string>
-    <string name="ime_action_next" msgid="3138843904009813834">"මීලඟ"</string>
-    <string name="ime_action_done" msgid="8971516117910934605">"හරි"</string>
-    <string name="ime_action_previous" msgid="1443550039250105948">"පෙර"</string>
-    <string name="ime_action_default" msgid="2840921885558045721">"ක්‍රියාකරවන්න"</string>
-    <string name="dial_number_using" msgid="5789176425167573586">"<xliff:g id="NUMBER">%s</xliff:g> භාවිතයෙන්\nඅංකය අමතන්න"</string>
-    <string name="create_contact_using" msgid="4947405226788104538">"<xliff:g id="NUMBER">%s</xliff:g> භාවිතයෙන්\nසම්බන්ධතාවයක් නිර්මාණය කරන්න"</string>
-    <string name="grant_credentials_permission_message_header" msgid="2106103817937859662">"පහත දැක්වෙන එකක් හෝ ඊට වැඩි යෙදුම් ගණනක් ඔබගේ ගිණුමට ප්‍රවේශ වීමට, දැන් සහ ඉදිරියේදී අවසර ඉල්ලයි."</string>
-    <string name="grant_credentials_permission_message_footer" msgid="3125211343379376561">"මෙම ඉල්ලීමට අවසර දීමට ඔබට අවශ්‍යද?"</string>
-    <string name="grant_permissions_header_text" msgid="6874497408201826708">"ප්‍රවේශය ඉල්ලීම"</string>
-    <string name="allow" msgid="7225948811296386551">"අවසර දෙන්න"</string>
-    <string name="deny" msgid="2081879885755434506">"ප්‍රතික්ෂේප කරන්න"</string>
-    <string name="permission_request_notification_title" msgid="6486759795926237907">"අවසර ඉල්ලා සිටී"</string>
-    <string name="permission_request_notification_with_subtitle" msgid="8530393139639560189">"<xliff:g id="ACCOUNT">%s</xliff:g> ගිණුම සඳහා\nඅවසර ඉල්ලන ලදි."</string>
-    <string name="input_method_binding_label" msgid="1283557179944992649">"ආදාන ක්‍රමය"</string>
-    <string name="sync_binding_label" msgid="3687969138375092423">"සමමුහුර්තය"</string>
-    <string name="accessibility_binding_label" msgid="4148120742096474641">"ප්‍රවේශ්‍යතාව"</string>
-    <string name="wallpaper_binding_label" msgid="1240087844304687662">"බිතුපත"</string>
-    <string name="chooser_wallpaper" msgid="7873476199295190279">"බිතුපත වෙනස් කරන්න"</string>
-    <string name="notification_listener_binding_label" msgid="2014162835481906429">"දැනුම්දීම් අසන්නා"</string>
-    <string name="vpn_title" msgid="19615213552042827">"VPN ක්‍රියාත්මකයි"</string>
-    <string name="vpn_title_long" msgid="6400714798049252294">"<xliff:g id="APP">%s</xliff:g> මඟින් VPN සක්‍රීය කරන ලදි"</string>
-    <string name="vpn_text" msgid="3011306607126450322">"ජාලය කළමනාකරණය කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="vpn_text_long" msgid="6407351006249174473">"<xliff:g id="SESSION">%s</xliff:g> වෙත සම්බන්ධ වුණි. ජාලය කළමනාකරණය කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="vpn_lockdown_connecting" msgid="6443438964440960745">"සැමවිටම VPN සම්බන්ධ වෙමින්…"</string>
-    <string name="vpn_lockdown_connected" msgid="8202679674819213931">"නිරතුරුවම VPN සම්බන්ධ කර ඇත"</string>
-    <string name="vpn_lockdown_error" msgid="6009249814034708175">"සැමවිට සක්‍රිය VPN දෝෂය"</string>
-    <string name="vpn_lockdown_config" msgid="6415899150671537970">"වින්‍යාස කිරීමට ස්පර්ශ කරන්න"</string>
-    <string name="upload_file" msgid="2897957172366730416">"ගොනුව තෝරන්න"</string>
-    <string name="no_file_chosen" msgid="6363648562170759465">"ගොනුවක් තෝරාගෙන නැත"</string>
-    <string name="reset" msgid="2448168080964209908">"යළි පිහිටුවන්න"</string>
-    <string name="submit" msgid="1602335572089911941">"යොමු කරන්න"</string>
-    <string name="car_mode_disable_notification_title" msgid="3164768212003864316">"මෝටර් රථ ආකාරය සබල කර ඇත"</string>
-    <string name="car_mode_disable_notification_message" msgid="8035230537563503262">"මෝටර් රථ ආකාරයෙන් පිටවීමට ස්පර්ශ කරන්න."</string>
-    <string name="tethered_notification_title" msgid="3146694234398202601">"ටෙදරින් හෝ හොට්ස්පොට් සක්‍රීයයි"</string>
-    <string name="tethered_notification_message" msgid="6857031760103062982">"සකස් කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="back_button_label" msgid="2300470004503343439">"ආපසු"</string>
-    <string name="next_button_label" msgid="1080555104677992408">"මීලඟ"</string>
-    <string name="skip_button_label" msgid="1275362299471631819">"මඟ හරින්න"</string>
-    <string name="throttle_warning_notification_title" msgid="4890894267454867276">"ඉහළ ජංගම දත්ත භාවිතය"</string>
-    <string name="throttle_warning_notification_message" msgid="3340822228599337743">"ජංගම දත්ත භාවිතය ගැන තව දැනගැනීමට ස්පර්ශ කරන්න."</string>
-    <string name="throttled_notification_title" msgid="6269541897729781332">"ජංගම දත්ත සීමාව ඉක්මවා ඇත"</string>
-    <string name="throttled_notification_message" msgid="5443457321354907181">"ජංගම දත්ත භාවිතය ගැන තව දැනගැනීමට ස්පර්ශ කරන්න."</string>
-    <string name="no_matches" msgid="8129421908915840737">"ගැලපීම් නැත"</string>
-    <string name="find_on_page" msgid="1946799233822820384">"පිටුවෙහි සෙවීම"</string>
-  <plurals name="matches_found">
-    <item quantity="one" msgid="8167147081136579439">"ගැළපීම් 1 යි"</item>
-    <item quantity="other" msgid="4641872797067609177">"<xliff:g id="TOTAL">%d</xliff:g> කින් <xliff:g id="INDEX">%d</xliff:g>"</item>
-  </plurals>
-    <string name="action_mode_done" msgid="7217581640461922289">"හරි"</string>
-    <string name="progress_unmounting" product="nosdcard" msgid="3923810448507612746">"USB ආචයනය ගැලවීම..."</string>
-    <string name="progress_unmounting" product="default" msgid="1327894998409537190">"SD පත ගලවමින්..."</string>
-    <string name="progress_erasing" product="nosdcard" msgid="4521573321524340058">"USB ආචයනය මකමින්..."</string>
-    <string name="progress_erasing" product="default" msgid="6596988875507043042">"SD පත මකමින්..."</string>
-    <string name="format_error" product="nosdcard" msgid="6299769563624776948">"USB ආචයනය මැකිය නොහැක."</string>
-    <string name="format_error" product="default" msgid="7315248696644510935">"SD පත මැකීමට නොහැකි විය."</string>
-    <string name="media_bad_removal" msgid="7960864061016603281">"ගැලවීමට පෙර SD පත ඉවත්කර ඇත."</string>
-    <string name="media_checking" product="nosdcard" msgid="418188720009569693">"USB ආචයනය මේ වනවිට පරීක්ෂා කරමින් පවතී."</string>
-    <string name="media_checking" product="default" msgid="7334762503904827481">"SD පත දැන් පරීක්ෂා කරමින් පවතී."</string>
-    <string name="media_removed" msgid="7001526905057952097">"SD පත ඉවත් කර ඇත."</string>
-    <string name="media_shared" product="nosdcard" msgid="5830814349250834225">"පරිගණකයක් විසින් දැන් USB ආචයනය භාවිතා කරයි."</string>
-    <string name="media_shared" product="default" msgid="5706130568133540435">"SD පත දැනට පරිගණකයකින් පාවිච්චි කරයි."</string>
-    <string name="media_unknown_state" msgid="729192782197290385">"බාහිර මාධ්‍යය නොදන්නා අවස්ථාවේ පවතියි."</string>
-    <string name="share" msgid="1778686618230011964">"බෙදාගන්න"</string>
-    <string name="find" msgid="4808270900322985960">"සොයන්න"</string>
-    <string name="websearch" msgid="4337157977400211589">"වෙබ් සෙවුම"</string>
-    <string name="find_next" msgid="5742124618942193978">"මීළඟ සොයන්න"</string>
-    <string name="find_previous" msgid="2196723669388360506">"පෙර එක සොයන්න"</string>
-    <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> ගෙන් ස්ථානය ඉල්ලීම"</string>
-    <string name="gpsNotifTitle" msgid="5446858717157416839">"ස්ථාන ඉල්ලීම"</string>
-    <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) විසින් ඉල්ලන ලද"</string>
-    <string name="gpsVerifYes" msgid="2346566072867213563">"ඔව්"</string>
-    <string name="gpsVerifNo" msgid="1146564937346454865">"නැත"</string>
-    <string name="sync_too_many_deletes" msgid="5296321850662746890">"මැකීමේ සීමාව ඉක්මවන ලදි"</string>
-    <string name="sync_too_many_deletes_desc" msgid="496551671008694245">"<xliff:g id="TYPE_OF_SYNC">%2$s</xliff:g> සඳහා <xliff:g id="ACCOUNT_NAME">%3$s</xliff:g> ගිණුමේ මකන ලද අයිතම <xliff:g id="NUMBER_OF_DELETED_ITEMS">%1$d</xliff:g> ක් ඇත. ඔබට කුමක් කිරීමට අවශ්‍යද?"</string>
-    <string name="sync_really_delete" msgid="2572600103122596243">"අයිතම මකන්න"</string>
-    <string name="sync_undo_deletes" msgid="2941317360600338602">"මැකීම් අස් කරන්න"</string>
-    <string name="sync_do_nothing" msgid="3743764740430821845">"දැනට කිසිවක් නොකරන්න"</string>
-    <string name="choose_account_label" msgid="5655203089746423927">"ගිණුමක් තෝරන්න"</string>
-    <string name="add_account_label" msgid="2935267344849993553">"ගිණුමක් එකතු කරන්න"</string>
-    <string name="add_account_button_label" msgid="3611982894853435874">"ගිණුමක් එකතු කරන්න"</string>
-    <string name="number_picker_increment_button" msgid="2412072272832284313">"වැඩි කරන්න"</string>
-    <string name="number_picker_decrement_button" msgid="476050778386779067">"අඩු කරන්න"</string>
-    <string name="number_picker_increment_scroll_mode" msgid="3073101067441638428">"<xliff:g id="VALUE">%s</xliff:g> ස්පර්ශ කර රඳවා සිටින්න."</string>
-    <string name="number_picker_increment_scroll_action" msgid="9101473045891835490">"වැඩි කිරීමට ඉහලට සර්පණය කරන්න සහ අඩු කිරීමට පහලට සර්පණය කරන්න."</string>
-    <string name="time_picker_increment_minute_button" msgid="8865885114028614321">"මිනිත්තුවක් වැඩි කරන්න"</string>
-    <string name="time_picker_decrement_minute_button" msgid="6246834937080684791">"මිනිත්තුව අඩු කරන්න"</string>
-    <string name="time_picker_increment_hour_button" msgid="3652056055810223139">"පැය වැඩිකරන්න"</string>
-    <string name="time_picker_decrement_hour_button" msgid="1377479863429214792">"පැය අඩුකරන්න"</string>
-    <string name="time_picker_increment_set_pm_button" msgid="4147590696151230863">"ප.ව.සකසන්න"</string>
-    <string name="time_picker_decrement_set_am_button" msgid="8302140353539486752">"පෙ.ව. සකස් කිරීම"</string>
-    <string name="date_picker_increment_month_button" msgid="5369998479067934110">"මාසය වැඩි කරන්න"</string>
-    <string name="date_picker_decrement_month_button" msgid="1832698995541726019">"මාසයක් අඩු කරන්න"</string>
-    <string name="date_picker_increment_day_button" msgid="7130465412308173903">"දවස වැඩි කරන්න"</string>
-    <string name="date_picker_decrement_day_button" msgid="4131881521818750031">"දවස අඩු කරන්න"</string>
-    <string name="date_picker_increment_year_button" msgid="6318697384310808899">"වසර වැඩි කරන්න"</string>
-    <string name="date_picker_decrement_year_button" msgid="4482021813491121717">"වසර අඩු කරන්න"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"අවලංගු කරන්න"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"මකන්න"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"හරි"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"ආකාරය වෙනස් කරන්න"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"ඇතුල් කරන්න"</string>
-    <string name="activitychooserview_choose_application" msgid="2125168057199941199">"යෙදුමක් තෝරන්න"</string>
-    <string name="shareactionprovider_share_with" msgid="806688056141131819">"සමඟ බෙදාගන්න"</string>
-    <string name="shareactionprovider_share_with_application" msgid="5627411384638389738">"<xliff:g id="APPLICATION_NAME">%s</xliff:g> සමඟින් බෙදා ගන්න"</string>
-    <string name="content_description_sliding_handle" msgid="415975056159262248">"සර්පණ හැඩලය. ස්පර්ශ කර රඳවා සිටීම."</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා උඩට සර්පණය කරන්න."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා පහලට සර්පණය කරන්න."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා වමට සර්පණය කරන්න."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> සඳහා දකුණට සර්පණය කරන්න."</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"අඟුල අරින්න"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"කැමරාව"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"නිහඬ"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"ශබ්ද සක්‍රීය කරන්න"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"සෙවීම"</string>
-    <string name="description_target_unlock_tablet" msgid="3833195335629795055">"අගුළු ඇරීමට ස්වයිප් කරන්න."</string>
-    <string name="keyboard_headset_required_to_hear_password" msgid="7011927352267668657">"මුරපද යතුරු කියවනු ඇසීමට ඉස් බණුවක් සම්බන්ධ කරන්න."</string>
-    <string name="keyboard_password_character_no_headset" msgid="2859873770886153678">"නැවතුම."</string>
-    <string name="action_bar_home_description" msgid="5293600496601490216">"මුල් පිටුවට සංචාලනය කරන්න"</string>
-    <string name="action_bar_up_description" msgid="2237496562952152589">"ඉහලට සංචාලනය කරන්න"</string>
-    <string name="action_menu_overflow_description" msgid="2295659037509008453">"තවත් විකල්ප"</string>
-    <string name="action_bar_home_description_format" msgid="7965984360903693903">"%1$s, %2$s"</string>
-    <string name="action_bar_home_subtitle_description_format" msgid="6985546530471780727">"%1$s, %2$s, %3$s"</string>
-    <string name="storage_internal" msgid="4891916833657929263">"අභ්‍යන්තර ආචයනය"</string>
-    <string name="storage_sd_card" msgid="3282948861378286745">"SD පත"</string>
-    <string name="storage_usb" msgid="3017954059538517278">"USB ආචයනය"</string>
-    <string name="extract_edit_menu_button" msgid="8940478730496610137">"සංස්කරණය කරන්න"</string>
-    <string name="data_usage_warning_title" msgid="1955638862122232342">"දත්ත භාවිතා අවවාදය"</string>
-    <string name="data_usage_warning_body" msgid="2814673551471969954">"භාවිතය සහ සැකසීම් බැලීමට ස්පර්ශ කරන්න."</string>
-    <string name="data_usage_3g_limit_title" msgid="7093334419518706686">"2G-3G දත්ත අබලයි"</string>
-    <string name="data_usage_4g_limit_title" msgid="7636489436819470761">"4G දත්ත අබල කරන ලදි"</string>
-    <string name="data_usage_mobile_limit_title" msgid="7869402519391631884">"ජංගම දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_wifi_limit_title" msgid="8992154736441284865">"Wi-Fi දත්ත අබල කරන ලදි"</string>
-    <string name="data_usage_limit_body" msgid="3317964706973601386">"සබල කිරීමට ස්පර්ශ කරන්න."</string>
-    <string name="data_usage_3g_limit_snoozed_title" msgid="7026739121138005231">"2G-3G දත්ත සීමාව ඉක්මවන ලදි"</string>
-    <string name="data_usage_4g_limit_snoozed_title" msgid="1106562779311209039">"4G දත්ත සීමාව ඉක්මවා යන ලදි"</string>
-    <string name="data_usage_mobile_limit_snoozed_title" msgid="279240572165412168">"ජංගම දත්ත සීමාව ඉක්මවා යන ලදි"</string>
-    <string name="data_usage_wifi_limit_snoozed_title" msgid="8743856006384825974">"Wi-Fi දත්ත සීමාව ඉක්මවා යන ලදි"</string>
-    <string name="data_usage_limit_snoozed_body" msgid="7035490278298441767">"සඳහන් කළ සීමාවට වඩා <xliff:g id="SIZE">%s</xliff:g> වැඩිය."</string>
-    <string name="data_usage_restricted_title" msgid="5965157361036321914">"පසුබිම් දත්ත සිමා කරන ලදි"</string>
-    <string name="data_usage_restricted_body" msgid="6741521330997452990">"සීමා කිරීම ඉවත් කිරීමට ස්පර්ශ කරන්න"</string>
-    <string name="ssl_certificate" msgid="6510040486049237639">"ආරක්‍ෂිත සහතිකය"</string>
-    <string name="ssl_certificate_is_valid" msgid="6825263250774569373">"මෙම සහතිකය වලංගුයි."</string>
-    <string name="issued_to" msgid="454239480274921032">"ලබාදුන්නේ:"</string>
-    <string name="common_name" msgid="2233209299434172646">"පොදු නාමය:"</string>
-    <string name="org_name" msgid="6973561190762085236">"සංවිධානය:"</string>
-    <string name="org_unit" msgid="7265981890422070383">"සංවිධානාත්මක ඒකකය:"</string>
-    <string name="issued_by" msgid="2647584988057481566">"ලබාදෙන ලද්දේ:"</string>
-    <string name="validity_period" msgid="8818886137545983110">"වලංගුතාවය:"</string>
-    <string name="issued_on" msgid="5895017404361397232">"නිකුත් කරන ලද්දේ:"</string>
-    <string name="expires_on" msgid="3676242949915959821">"කල් ඉකුත් වන්නේ:"</string>
-    <string name="serial_number" msgid="758814067660862493">"අනුක්‍රමාංකය:"</string>
-    <string name="fingerprints" msgid="4516019619850763049">"ඇඟිලි සලකුණු:"</string>
-    <string name="sha256_fingerprint" msgid="4391271286477279263">"SHA-256 ඇඟිලිසලකුණ:"</string>
-    <string name="sha1_fingerprint" msgid="7930330235269404581">"SHA-1 ඇඟිලි සලකුණ:"</string>
-    <string name="activity_chooser_view_see_all" msgid="4292569383976636200">"සියල්ල බලන්න"</string>
-    <string name="activity_chooser_view_dialog_title_default" msgid="4710013864974040615">"ක්‍රියාකාරකම තෝරන්න"</string>
-    <string name="share_action_provider_share_with" msgid="5247684435979149216">"සමඟ බෙදාගන්න"</string>
-    <string name="status_bar_device_locked" msgid="3092703448690669768">"උපාංගයට අගුළු වැටි ඇත."</string>
-    <string name="list_delimeter" msgid="3975117572185494152">", "</string>
-    <string name="sending" msgid="3245653681008218030">"යවමින්..."</string>
-    <string name="launchBrowserDefault" msgid="2057951947297614725">"බ්‍රවුසරය දියත් කරන්නද?"</string>
-    <string name="SetupCallDefault" msgid="5834948469253758575">"ඇමතුම පිළිගන්නවාද?"</string>
-    <string name="activity_resolver_use_always" msgid="8017770747801494933">"සැම විටම"</string>
-    <string name="activity_resolver_use_once" msgid="2404644797149173758">"එක් වාරයයි"</string>
-    <string name="default_audio_route_name" product="tablet" msgid="4617053898167127471">"ටැබ්ලට්ය"</string>
-    <string name="default_audio_route_name" product="default" msgid="4239291273420140123">"දුරකථනය"</string>
-    <string name="default_audio_route_name_headphones" msgid="8119971843803439110">"ඉස් බණු"</string>
-    <string name="default_audio_route_name_dock_speakers" msgid="6240602982276591864">"නාදක ඩොක් කරන්න"</string>
-    <string name="default_media_route_name_hdmi" msgid="2450970399023478055">"HDMI"</string>
-    <string name="default_audio_route_category_name" msgid="3722811174003886946">"පද්ධතිය"</string>
-    <string name="bluetooth_a2dp_audio_route_name" msgid="8575624030406771015">"බ්ලූටූත් ශ්‍රව්‍ය"</string>
-    <string name="wireless_display_route_description" msgid="9070346425023979651">"රැහැන් රහිත දර්ශනය"</string>
-    <string name="media_route_chooser_grouping_done" msgid="7966438307723317169">"හරි"</string>
-    <string name="media_route_button_content_description" msgid="5758553567065145276">"මාධ්‍ය ප්‍රතිදානය"</string>
-    <string name="media_route_status_scanning" msgid="7279908761758293783">"පරිලෝකනය කරමින්…"</string>
-    <string name="media_route_status_connecting" msgid="6422571716007825440">"සම්බන්ධ වෙමින්…"</string>
-    <string name="media_route_status_available" msgid="6983258067194649391">"ලබාගත හැක"</string>
-    <string name="media_route_status_not_available" msgid="6739899962681886401">"ලබාගත නොහැක"</string>
-    <string name="media_route_status_in_use" msgid="4533786031090198063">"භාවිතයේ ඇත"</string>
-    <string name="display_manager_built_in_display_name" msgid="2583134294292563941">"තිළැලි තිරය"</string>
-    <string name="display_manager_hdmi_display_name" msgid="1555264559227470109">"HDMI තිරය"</string>
-    <string name="display_manager_overlay_display_name" msgid="5142365982271620716">"උඩැතිරිය #<xliff:g id="ID">%1$d</xliff:g>"</string>
-    <string name="display_manager_overlay_display_title" msgid="652124517672257172">"<xliff:g id="NAME">%1$s</xliff:g>: <xliff:g id="WIDTH">%2$d</xliff:g>x<xliff:g id="HEIGHT">%3$d</xliff:g>, <xliff:g id="DPI">%4$d</xliff:g> dpi"</string>
-    <string name="display_manager_overlay_display_secure_suffix" msgid="6022119702628572080">", ආරක්‍ෂිත"</string>
-    <string name="wifi_display_notification_title" msgid="2223050649240326557">"නොරැහැන් සංදර්ශකය සම්බන්ධිතයි"</string>
-    <string name="wifi_display_notification_message" msgid="4498802012464170685">"වෙනත් උපාංගයක් මත මෙම තිරය පෙන්වයි"</string>
-    <string name="wifi_display_notification_disconnect" msgid="6183754463561153372">"විසන්ධි කරන්න"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"හදිසි ඇමතුම"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"රටාව අමතකයි"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"වැරදි රටාවකි"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"වැරදි මුරපදය"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN එක වැරදියි"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"තත්පර <xliff:g id="NUMBER">%1$d</xliff:g> ට පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"ඔබගේ රටාව අඳින්න"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN ඇතුලු කරන්න"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN එක ඇතුළු කරන්න"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"මුරපදය ඇතුළු කරන්න"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"දැන් SIM එක අබල කර ඇත. ඉදිරියට යාමට PUK කේතය යොදන්න. විස්තර සඳහා වාහකයා අමතන්න."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"අපේක්ෂිත PIN කේතය ඇතුළත් කරන්න"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"අපේක්ෂිත PIN කේතය ස්ථිර කරන්න"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM පත අගුළු අරිමින්..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"වැරදි PIN කේතයකි."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"අංක 4 සිට 8 අතර වන PIN එකක් ටයිප් කරන්න."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK කේතය සංඛ්‍යා 8 ක් හෝ වැඩි විය යුතුය."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"නිවැරදි PUK කේතය නැවත ඇතුලත් කරන්න. නැවත නැවත උත්සාහ කිරීමෙන් SIM එක ස්ථිරවම අබල කරයි."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN කේත ගැලපී නැත"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"රටා උත්සාහ කිරීම් වැඩිය"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"අගුළු ඇරීමට, ඔබගේ Google ගිණුම සමග පුරනය වන්න."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"පරිශීලක නාමය (ඊ-තැපෑල)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"මුරපදය"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"පුරනය වන්න"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"වලංගු නොවන පරිශීලක නාමයක් හෝ මුරපදයක්."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"ඔබගේ පරිශීලක නාමය හෝ මුරපදය අමතකද?\n "<b>"google.com/accounts/recovery"</b>" වෙත යන්න."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"ගිණුම පරීක්ෂා කරමින්…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"ඔබ PIN අංකය <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් වැරදියට ටයිප් කොට ඇත.\n\n තත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"<xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ මුරපදය ඔබ වැරදියට ටයිප් කර ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ට පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"ඔබ <xliff:g id="NUMBER_0">%d</xliff:g> වාරයක් අගුළු ඇරීමේ රටාව වැරදියට ඇඳ ඇත. \n\nතත්පර <xliff:g id="NUMBER_1">%d</xliff:g> ක් ඇතුළත නැවත උත්සාහ කරන්න."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"ඔබ ටැබ්ලටය අගුළු හැරීමට වැරදියට අවස්ථා <xliff:g id="NUMBER_0">%d</xliff:g> ක් උත්සාහ කර ඇත. අවස්ථා <xliff:g id="NUMBER_1">%d</xliff:g> ක් අසාර්ථකව උත්සහ කිරීමකින් පසුව, කර්මාන්ත ශාලා මුල් තත්වයට නැවත පත් වන අතර සියලු පරිශීලක දත්ත නැති වෙයි."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER_0">%d</xliff:g> කදී වැරදී ප්‍රයත්නයන් ගෙන තිබේ. තවත් අසාර්ථක ප්‍රයත්න <xliff:g id="NUMBER_1">%d</xliff:g> කින් පසුව, දුරකථනය කර්මාන්ත ශාලාවේ සුපුරුද්දට යළි පිහිටුවන අතර සියලුම පරිශීලක දත්ත නැති වී යයි."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"ටැබ්ලටයේ අගුළු ඇරීමට ඔබ වැරදි ප්‍රයත්න <xliff:g id="NUMBER">%d</xliff:g> වාරයක් ගෙන ඇත. දැන් ටැබ්ලටය කර්මාන්ත ශාලා සුපුරුද්ද වෙත යළි පිහිටුවීම කෙරේ."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"ඔබ දුරකථනය අගුළු ඇරීමට වාර <xliff:g id="NUMBER">%d</xliff:g> කදී වැරදී ප්‍රයන්තයන් ගෙන තිබේ. දැන් දුරකථනය කර්මාන්තශාලා සුපුරුද්දට පිහිටුවනු ලබයි."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"ඔබ අගුළු ඇරිමේ රටාව <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් වැරදියට ඇඳ ඇත. තවත් අසාර්ථක උත්සාහ <xliff:g id="NUMBER_1">%d</xliff:g> කින් පසුව, ඊ-තැපැල් ගිණුම භාවිතා කරමින් ඔබගේ ටැබ්ලටයේ අගුළු ඇරීමට ඔබට පවසනු ඇත.\n\n නැවත තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> කින් උත්සාහ කරන්න."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"ඔබ වැරදියට <xliff:g id="NUMBER_0">%d</xliff:g> වතාවක් ඔබගේ අගුළු හැරීමේ රටාව ඇඳ ඇත. අසාර්ථක උත්සහ කිරීම් <xliff:g id="NUMBER_1">%d</xliff:g> න් පසුව, ඔබගේ ඊ-තැපැල් ලිපිනය භාවිතයෙන් ඔබගේ දුරකථනය අගුළු හැරීමට ඔබගෙන් අසයි.\n\n තත්පර <xliff:g id="NUMBER_2">%d</xliff:g> න් පසුව නැවත උත්සහ කරන්න."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"ඉවත් කරන්න"</string>
-    <string name="safe_media_volume_warning" product="default" msgid="7324161939475478066">"නිර්දේශිත මට්ටමෙන් ඉහළට ශබ්දය වැඩි කරනවද?\nවැඩි කාලයක් ඉහළ ශබ්දයක් ශ්‍රවනය කිරීමෙන් ඔබගේ ශ්‍රවනයට හානි විය හැක."</string>
-    <string name="continue_to_enable_accessibility" msgid="1626427372316070258">"ප්‍රවේශ්‍යතාවය සබල කිරීමට ඇඟිලි දෙකක් පහළට රඳවා සිටින්න."</string>
-    <string name="accessibility_enabled" msgid="1381972048564547685">"ප‍්‍රවේශ්‍යතාව සබල කරන ලදි."</string>
-    <string name="enable_accessibility_canceled" msgid="3833923257966635673">"ප‍්‍රවේශ්‍යතාව අවලංගු කර ඇත."</string>
-    <string name="user_switched" msgid="3768006783166984410">"දැනට සිටින පරිශීලකයා <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="owner_name" msgid="2716755460376028154">"හිමිකරු"</string>
-    <string name="error_message_title" msgid="4510373083082500195">"දෝෂය"</string>
-    <string name="app_no_restricted_accounts" msgid="5739463249673727736">"සීමා සහිත පැතිකඩ සඳහා වන ගිණුම් වෙත මෙම යෙදුම සහය නොදක්වයි"</string>
-    <string name="app_not_found" msgid="3429141853498927379">"මෙම ක්‍රියාව හසුරුවීමට යෙදුමක් සොයාගත්තේ නැත"</string>
-    <string name="revoke" msgid="5404479185228271586">"අහෝසි කරන්න"</string>
-    <string name="mediaSize_iso_a0" msgid="7875427489420821793">"ISO A0"</string>
-    <string name="mediaSize_iso_a1" msgid="3760734499050875356">"ISO A1"</string>
-    <string name="mediaSize_iso_a2" msgid="5973266378020144382">"ISO A2"</string>
-    <string name="mediaSize_iso_a3" msgid="1373407105687300884">"ISO A3"</string>
-    <string name="mediaSize_iso_a4" msgid="6689772807982597254">"ISO A4"</string>
-    <string name="mediaSize_iso_a5" msgid="5353549652015741040">"ISO A5"</string>
-    <string name="mediaSize_iso_a6" msgid="8585038048674911907">"ISO A6"</string>
-    <string name="mediaSize_iso_a7" msgid="6641836716963839119">"ISO A7"</string>
-    <string name="mediaSize_iso_a8" msgid="7571139437465693355">"ISO A8"</string>
-    <string name="mediaSize_iso_a9" msgid="1378455891957115079">"ISO A9"</string>
-    <string name="mediaSize_iso_a10" msgid="2480747457429475344">"ISO A10"</string>
-    <string name="mediaSize_iso_b0" msgid="3965935097661108039">"ISO B0"</string>
-    <string name="mediaSize_iso_b1" msgid="2505753285010115437">"ISO B1"</string>
-    <string name="mediaSize_iso_b2" msgid="8763874709859458453">"ISO B2"</string>
-    <string name="mediaSize_iso_b3" msgid="4210506688191764076">"ISO B3"</string>
-    <string name="mediaSize_iso_b4" msgid="5749404165888526034">"ISO B4"</string>
-    <string name="mediaSize_iso_b5" msgid="7640627414621904733">"ISO B5"</string>
-    <string name="mediaSize_iso_b6" msgid="7342988864712748544">"ISO B6"</string>
-    <string name="mediaSize_iso_b7" msgid="5069844065235382429">"ISO B7"</string>
-    <string name="mediaSize_iso_b8" msgid="7316818922278779774">"ISO B8"</string>
-    <string name="mediaSize_iso_b9" msgid="5414727094026532341">"ISO B9"</string>
-    <string name="mediaSize_iso_b10" msgid="5251253731832048185">"ISO B10"</string>
-    <string name="mediaSize_iso_c0" msgid="4003138342671964217">"ISO C0"</string>
-    <string name="mediaSize_iso_c1" msgid="1935188063393553008">"ISO C1"</string>
-    <string name="mediaSize_iso_c2" msgid="3197307969712069904">"ISO C2"</string>
-    <string name="mediaSize_iso_c3" msgid="4335826087321913508">"ISO C3"</string>
-    <string name="mediaSize_iso_c4" msgid="3745639598281015005">"ISO C4"</string>
-    <string name="mediaSize_iso_c5" msgid="8269457765822791013">"ISO C5"</string>
-    <string name="mediaSize_iso_c6" msgid="566666105260346930">"ISO C6"</string>
-    <string name="mediaSize_iso_c7" msgid="8678413180782608498">"ISO C7"</string>
-    <string name="mediaSize_iso_c8" msgid="8392376206627041730">"ISO C8"</string>
-    <string name="mediaSize_iso_c9" msgid="9191613372324845405">"ISO C9"</string>
-    <string name="mediaSize_iso_c10" msgid="7327709699184920822">"ISO C10"</string>
-    <string name="mediaSize_na_letter" msgid="4191805615829472953">"අකුරු"</string>
-    <string name="mediaSize_na_gvrnmt_letter" msgid="7853382192649405507">"රජයේ ලිපිය"</string>
-    <string name="mediaSize_na_legal" msgid="6697982988283823150">"නීත්‍යනුකූල"</string>
-    <string name="mediaSize_na_junior_legal" msgid="3727743969902758948">"ප්‍රාථමික නීතිමය"</string>
-    <string name="mediaSize_na_ledger" msgid="281871464896601236">"ලෙජරය"</string>
-    <string name="mediaSize_na_tabloid" msgid="5775966416333578127">"කුඩා පුවත්පත"</string>
-    <string name="write_fail_reason_cancelled" msgid="7091258378121627624">"අවලංගු කරන ලදි"</string>
-    <string name="write_fail_reason_cannot_write" msgid="8132505417935337724">"අන්තර්ගතය ලිවීමේදී දෝෂයකි"</string>
-    <string name="restr_pin_enter_pin" msgid="3395953421368476103">"PIN එක ඇතුළු කරන්න"</string>
-    <string name="restr_pin_enter_old_pin" msgid="1462206225512910757">"වත්මන් PIN"</string>
-    <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"නව PIN"</string>
-    <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"නව PIN තහවුරු කරන්න"</string>
-    <string name="restr_pin_create_pin" msgid="8017600000263450337">"සිමා වැඩිදියුණු කිරීමට PIN සාදන්න"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN නොගැළපෙයි. නැවත උත්සහ කරන්න."</string>
-    <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN කුඩා වැඩිය. ඉලක්කම් 4 වත් විය යුතුය."</string>
-  <plurals name="restr_pin_countdown">
-    <item quantity="one" msgid="4835639969503729874">"වැරදි PIN. තත්පරයකින් නැවත උත්සහ කරන්න."</item>
-    <item quantity="other" msgid="8030607343223287654">"වැරදි PIN. තත්පර <xliff:g id="COUNT">%d</xliff:g> කින් නැවත උත්සහ කරන්න."</item>
-  </plurals>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"තීරුව අනාවරණයට තිරයේ කෙලවර අදින්න"</string>
-</resources>
diff --git a/core/res/res/values-sk/strings.xml b/core/res/res/values-sk/strings.xml
index df752bd..cd865aa 100644
--- a/core/res/res/values-sk/strings.xml
+++ b/core/res/res/values-sk/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Skúste to zas o <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Skúste to znova neskôr"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Režim celej obraz. ukončíte posunutím nadol"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Režim celej obraz. ukončíte posunutím nadol"</string>
 </resources>
diff --git a/core/res/res/values-sl/strings.xml b/core/res/res/values-sl/strings.xml
index 29c010d..43da811 100644
--- a/core/res/res/values-sl/strings.xml
+++ b/core/res/res/values-sl/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Poskusite znova čez <xliff:g id="COUNT">%d</xliff:g> s"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Poskusite znova pozneje"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Povlecite z vrha, da zaprete celozas. način"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Povlecite z vrha, da zaprete celozaslonski način."</string>
 </resources>
diff --git a/core/res/res/values-sr/strings.xml b/core/res/res/values-sr/strings.xml
index e7c69bf..14b22cc 100644
--- a/core/res/res/values-sr/strings.xml
+++ b/core/res/res/values-sr/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Покушајте опет за <xliff:g id="COUNT">%d</xliff:g> сек"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Покушајте поново касније"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Превуците надоле од врха за излаз из целог екрана"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Превуците прстом одозго надоле да бисте изашли из целог екрана."</string>
 </resources>
diff --git a/core/res/res/values-sv/strings.xml b/core/res/res/values-sv/strings.xml
index 4e21412..aa20a64 100644
--- a/core/res/res/values-sv/strings.xml
+++ b/core/res/res/values-sv/strings.xml
@@ -830,7 +830,7 @@
     <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Försök igen"</string>
     <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Försök igen"</string>
     <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Du har försökt låsa upp med Ansiktslås för många gånger"</string>
-    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"Laddar (<xliff:g id="PERCENT">%%</xliff:g> <xliff:g id="NUMBER">%d</xliff:g>)"</string>
+    <string name="lockscreen_plugged_in" msgid="8057762828355572315">"Laddar (<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>)"</string>
     <string name="lockscreen_charged" msgid="321635745684060624">"Batteriet har laddats"</string>
     <string name="lockscreen_battery_short" msgid="4477264849386850266">"<xliff:g id="NUMBER">%d</xliff:g> <xliff:g id="PERCENT">%%</xliff:g>"</string>
     <string name="lockscreen_low_battery" msgid="1482873981919249740">"Anslut din laddare."</string>
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Försök igen om <xliff:g id="COUNT">%d</xliff:g> sekunder"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Försök igen senare"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Dra nedåt om du vill avbryta fullskärmsläget"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Dra nedåt om du vill avbryta fullskärmsläget."</string>
 </resources>
diff --git a/core/res/res/values-sw/strings.xml b/core/res/res/values-sw/strings.xml
index 2d65199..b066758 100644
--- a/core/res/res/values-sw/strings.xml
+++ b/core/res/res/values-sw/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Jaribu tena baada ya sekunde <xliff:g id="COUNT">%d</xliff:g>"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Jaribu tena baadaye"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Telezesha kidole kwa kasi chini kuanzia juu ili uondoke kwenye skrini kamili"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Telezesha kidole kwa kasi chini kuanzia juu ili uondoke kwenye skrini kamili"</string>
 </resources>
diff --git a/core/res/res/values-th/strings.xml b/core/res/res/values-th/strings.xml
index d6135d5..58f5268 100644
--- a/core/res/res/values-th/strings.xml
+++ b/core/res/res/values-th/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"ลองอีกใน <xliff:g id="COUNT">%d</xliff:g> วินาที"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"ลองอีกครั้งในภายหลัง"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"กวาดนิ้วจากบนลงล่างเพื่อออกจากโหมดเต็มหน้าจอ"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"กวาดนิ้วจากบนลงล่างเพื่อออกจากโหมดเต็มหน้าจอ"</string>
 </resources>
diff --git a/core/res/res/values-tl/strings.xml b/core/res/res/values-tl/strings.xml
index e17c7cc..bc396ed 100644
--- a/core/res/res/values-tl/strings.xml
+++ b/core/res/res/values-tl/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Subukan muli sa <xliff:g id="COUNT">%d</xliff:g> seg"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Subukang muli sa ibang pagkakataon"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Mag-swipe pababa upang lumabas sa full screen"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Mag-swipe pababa upang lumabas sa full screen"</string>
 </resources>
diff --git a/core/res/res/values-tr/strings.xml b/core/res/res/values-tr/strings.xml
index 31ae8d8..99a137b 100644
--- a/core/res/res/values-tr/strings.xml
+++ b/core/res/res/values-tr/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> saniye içinde tekrar deneyin"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Daha sonra tekrar deneyin"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Tam ekrandan çıkmak için aşağıya hızlıca kaydırın"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Tam ekrandan çıkmak için aşağıya hızlıca kaydırın"</string>
 </resources>
diff --git a/core/res/res/values-uk/strings.xml b/core/res/res/values-uk/strings.xml
index 69f2e9e..61f45ec 100644
--- a/core/res/res/values-uk/strings.xml
+++ b/core/res/res/values-uk/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Повтор за <xliff:g id="COUNT">%d</xliff:g> с"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Спробуйте пізніше"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Проведіть пальцем зверху вниз, щоб зменшити"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Проведіть пальцем зверху вниз, щоб вийти з повноекранного режиму."</string>
 </resources>
diff --git a/core/res/res/values-vi/strings.xml b/core/res/res/values-vi/strings.xml
index 2d7ae36..82752b7 100644
--- a/core/res/res/values-vi/strings.xml
+++ b/core/res/res/values-vi/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Hãy thử lại sau <xliff:g id="COUNT">%d</xliff:g> giây"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Hãy thử lại sau"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Vuốt từ trên xuống để thoát toàn màn hình"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Vuốt từ trên xuống để thoát toàn màn hình"</string>
 </resources>
diff --git a/core/res/res/values-zh-rCN/strings.xml b/core/res/res/values-zh-rCN/strings.xml
index 533db45..dbfd039 100644
--- a/core/res/res/values-zh-rCN/strings.xml
+++ b/core/res/res/values-zh-rCN/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g>秒后重试"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"稍后重试"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"从顶部向下滑动即可退出全屏模式"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"从顶部向下滑动即可退出全屏模式"</string>
 </resources>
diff --git a/core/res/res/values-zh-rHK/strings.xml b/core/res/res/values-zh-rHK/strings.xml
index 85a2af6..2d2e77e 100644
--- a/core/res/res/values-zh-rHK/strings.xml
+++ b/core/res/res/values-zh-rHK/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> 秒後再試一次"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"稍後再試"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"從頂端往下快速滑動即可退出全螢幕"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"從頂端往下滑動即可結束全螢幕。"</string>
 </resources>
diff --git a/core/res/res/values-zh-rTW/strings.xml b/core/res/res/values-zh-rTW/strings.xml
index 377a008..3ec8d4c 100644
--- a/core/res/res/values-zh-rTW/strings.xml
+++ b/core/res/res/values-zh-rTW/strings.xml
@@ -255,7 +255,7 @@
     <string name="permlab_receiveSms" msgid="8673471768947895082">"接收簡訊 (SMS)"</string>
     <string name="permdesc_receiveSms" msgid="6424387754228766939">"允許應用程式接收和處理簡訊。這項設定可讓應用程式監控傳送至您裝置的訊息,或在您閱讀訊息前擅自刪除訊息。"</string>
     <string name="permlab_receiveMms" msgid="1821317344668257098">"接收簡訊 (MMS)"</string>
-    <string name="permdesc_receiveMms" msgid="533019437263212260">"允許應用程式接收和處理 MMS 訊息。這項設定可讓應用程式監控傳送至您裝置的訊息,或在您閱讀訊息前擅自刪除訊息。"</string>
+    <string name="permdesc_receiveMms" msgid="533019437263212260">"允許應用程式接收和處理多媒體訊息。這項設定可讓應用程式監控傳送至您裝置的訊息,或在您閱讀訊息前擅自刪除訊息。"</string>
     <string name="permlab_receiveEmergencyBroadcast" msgid="1803477660846288089">"接收緊急廣播"</string>
     <string name="permdesc_receiveEmergencyBroadcast" msgid="848524070262431974">"允許應用程式接收及處理緊急廣播訊息,只有系統應用程式可以具備這項權限。"</string>
     <string name="permlab_readCellBroadcasts" msgid="1598328843619646166">"讀取區域廣播訊息"</string>
@@ -759,7 +759,7 @@
     <string name="phoneTypeWorkMobile" msgid="1311426989184065709">"公司行動電話"</string>
     <string name="phoneTypeWorkPager" msgid="649938731231157056">"公司呼叫器"</string>
     <string name="phoneTypeAssistant" msgid="5596772636128562884">"助理"</string>
-    <string name="phoneTypeMms" msgid="7254492275502768992">"MMS"</string>
+    <string name="phoneTypeMms" msgid="7254492275502768992">"多媒體簡訊"</string>
     <string name="eventTypeCustom" msgid="7837586198458073404">"自訂"</string>
     <string name="eventTypeBirthday" msgid="2813379844211390740">"生日"</string>
     <string name="eventTypeAnniversary" msgid="3876779744518284000">"週年紀念日"</string>
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"<xliff:g id="COUNT">%d</xliff:g> 秒後再試一次"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"稍後再試"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"從頂端往下滑動即可結束全螢幕"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"從頂端往下滑動即可結束全螢幕。"</string>
 </resources>
diff --git a/core/res/res/values-zu/strings.xml b/core/res/res/values-zu/strings.xml
index 6996f31..57d59c3 100644
--- a/core/res/res/values-zu/strings.xml
+++ b/core/res/res/values-zu/strings.xml
@@ -1649,5 +1649,5 @@
     <item quantity="other" msgid="4730868920742952817">"Zama futhi kumasekhondi angu-<xliff:g id="COUNT">%d</xliff:g>"</item>
   </plurals>
     <string name="restr_pin_try_later" msgid="973144472490532377">"Zama futhi emva kwesikhathi"</string>
-    <string name="immersive_mode_confirmation" msgid="8554991488096662508">"Swayipha ngezansi kusuka ngaphezulu ukuze uphume kusikrini esigcwele"</string>
+    <string name="immersive_mode_confirmation" msgid="7227416894979047467">"Swayiphela phansi kusukela phezulu ukuze uphume kusikrini esigcwele."</string>
 </resources>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 42e3b50..1eb75d8 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -447,6 +447,10 @@
              to {@link android.view.WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION}. -->
         <attr name="windowTranslucentNavigation" format="boolean" />
 
+        <!-- Flag to indicate that a window can be swiped away to be dismissed.
+             Corresponds to {@link android.view.Window.FEATURE_SWIPE_TO_DISMISS} -->
+        <attr name="windowSwipeToDismiss" format="boolean" />
+
         <!-- ============ -->
         <!-- Alert Dialog styles -->
         <!-- ============ -->
@@ -1567,6 +1571,8 @@
         <enum name="KEYCODE_BRIGHTNESS_DOWN" value="220" />
         <enum name="KEYCODE_BRIGHTNESS_UP" value="221" />
         <enum name="KEYCODE_MEDIA_AUDIO_TRACK" value="222" />
+        <enum name="KEYCODE_MEDIA_SLEEP" value="223" />
+        <enum name="KEYCODE_MEDIA_WAKEUP" value="224" />
     </attr>
 
     <!-- ***************************************************************** -->
@@ -1604,6 +1610,7 @@
         <attr name="windowCloseOnTouchOutside" />
         <attr name="windowTranslucentStatus" />
         <attr name="windowTranslucentNavigation" />
+        <attr name="windowSwipeToDismiss" />
         <!-- The minimum width the window is allowed to be, along the major
              axis of the screen.  That is, when in landscape.  Can be either
              an absolute dimension or a fraction of the screen size in that
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index b20f5ba..cbde41c 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -62,6 +62,21 @@
          a reference to a Drawable resource containing the image definition. -->
     <attr name="icon" format="reference" />
 
+    <!-- A Drawable resource providing an extended graphical banner for its
+         associated item. Use with the application tag (to supply a default
+         banner for all application activities), or with the activity, tag to
+         supply a banner for a specific activity.
+
+         <p>The given banner will be used to display to the user a graphical
+         representation of an activity in the Leanback application launcher.
+         Since banners are displayed only in the Leanback launcher, they should
+         only be used with activities (and applications) that support Leanback
+         mode. These are activities that handle Intents of category
+         {@link android.content.Intent#CATEGORY_LEANBACK_LAUNCHER
+         Intent.CATEGORY_LEANBACK_LAUNCHER}.
+         <p>This must be a reference to a Drawable resource containing the image definition. -->
+    <attr name="banner" format="reference" />
+
     <!-- A Drawable resource providing an extended graphical logo for its
          associated item. Use with the application tag (to supply a default
          logo for all application components), or with the activity, receiver,
@@ -888,6 +903,7 @@
         <attr name="theme" />
         <attr name="label" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="description" />
         <attr name="permission" />
@@ -970,6 +986,7 @@
         <attr name="name" />
         <attr name="label" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="permissionGroup" />
         <attr name="description" />
@@ -996,6 +1013,7 @@
         <attr name="name" />
         <attr name="label" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="description" />
         <attr name="permissionGroupFlags" />
@@ -1028,6 +1046,7 @@
         <attr name="name" />
         <attr name="label" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
     </declare-styleable>
     
@@ -1294,6 +1313,7 @@
         <attr name="label" />
         <attr name="description" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="process" />
         <attr name="authorities" />
@@ -1375,6 +1395,7 @@
         <attr name="label" />
         <attr name="description" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="permission" />
         <attr name="process" />
@@ -1417,6 +1438,7 @@
         <attr name="label" />
         <attr name="description" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="permission" />
         <attr name="process" />
@@ -1451,6 +1473,7 @@
         <attr name="label" />
         <attr name="description" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="launchMode" />
         <attr name="screenOrientation" />
@@ -1514,6 +1537,7 @@
         <attr name="label" />
         <attr name="description" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="permission" />
         <!-- Specify whether the activity-alias is enabled or not (that is, can be instantiated by the system).
@@ -1585,6 +1609,7 @@
          parent="AndroidManifestActivity AndroidManifestReceiver AndroidManifestService">
         <attr name="label" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="priority" />
     </declare-styleable>
@@ -1713,6 +1738,7 @@
         <attr name="targetPackage" />
         <attr name="label" />
         <attr name="icon" />
+        <attr name="banner" />
         <attr name="logo" />
         <attr name="handleProfiling" />
         <attr name="functionalTest" />
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 50b3a35..4449b4a 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -370,6 +370,17 @@
     <!-- If this is true, key chords can be used to take a screenshot on the device. -->
     <bool name="config_enableScreenshotChord">true</bool>
 
+    <!-- Auto-rotation behavior -->
+
+    <!-- If true, enables auto-rotation features using the accelerometer.
+         Otherwise, auto-rotation is disabled.  Applications may still request
+         to use specific orientations but the sensor is ignored and sensor-based
+         orientations are not available.  Furthermore, all auto-rotation related
+         settings are omitted from the system UI.  In certain situations we may
+         still use the accelerometer to determine the orientation, such as when
+         docked if the dock is configured to enable the accelerometer. -->
+    <bool name="config_supportAutoRotation">true</bool>
+
     <!-- If true, the screen can be rotated via the accelerometer in all 4
          rotations as the default behavior. -->
     <bool name="config_allowAllRotations">false</bool>
@@ -382,57 +393,12 @@
          true here reverses that logic. -->
     <bool name="config_reverseDefaultRotation">false</bool>
 
+    <!-- Lid switch behavior -->
+
     <!-- The number of degrees to rotate the display when the keyboard is open.
          A value of -1 means no change in orientation by default. -->
     <integer name="config_lidOpenRotation">-1</integer>
 
-    <!-- The number of degrees to rotate the display when the device is in a desk dock.
-         A value of -1 means no change in orientation by default. -->
-    <integer name="config_deskDockRotation">-1</integer>
-
-    <!-- The number of degrees to rotate the display when the device is in a car dock.
-         A value of -1 means no change in orientation by default. -->
-    <integer name="config_carDockRotation">-1</integer>
-
-    <!-- The number of degrees to rotate the display when the device has HDMI connected
-         but is not in a dock.  A value of -1 means no change in orientation by default.
-         Use -1 except on older devices whose Hardware Composer HAL does not
-         provide full support for multiple displays.  -->
-    <integer name="config_undockedHdmiRotation">-1</integer>
-
-    <!-- Control the default UI mode type to use when there is no other type override
-         happening.  One of the following values (See Configuration.java):
-             1  UI_MODE_TYPE_NORMAL
-             4  UI_MODE_TYPE_TELEVISION
-             5  UI_MODE_TYPE_APPLIANCE
-         Any other values will have surprising consequences. -->
-    <integer name="config_defaultUiModeType">1</integer>
-
-    <!-- Control whether being in the desk dock (and powered) always
-         keeps the screen on.  By default it stays on when plugged in to
-         AC.  0 will not keep it on; or together 1 to stay on when plugged
-         in to AC and 2 to stay on when plugged in to USB.  (So 3 for both.) -->
-    <integer name="config_deskDockKeepsScreenOn">1</integer>
-
-    <!-- Control whether being in the car dock (and powered) always
-         keeps the screen on.  By default it stays on when plugged in to
-         AC.  0 will not keep it on; or together 1 to stay on when plugged
-         in to AC and 2 to stay on when plugged in to USB.  (So 3 for both.) -->
-    <integer name="config_carDockKeepsScreenOn">1</integer>
-
-    <!-- Control whether being in the desk dock should enable accelerometer
-         based screen orientation.  This defaults to true because it is
-         common for desk docks to be sold in a variety of form factors
-         with different orientations.  Since we cannot always tell these docks
-         apart and the docks cannot report their true orientation on their own,
-         we rely on gravity to determine the effective orientation. -->
-    <bool name="config_deskDockEnablesAccelerometer">true</bool>
-
-    <!-- Control whether being in the car dock should enable accelerometer based
-         screen orientation.  This defaults to true because putting a device in
-         a car dock make the accelerometer more a physical input (like a lid). -->
-    <bool name="config_carDockEnablesAccelerometer">true</bool>
-
     <!-- Indicate whether the lid state impacts the accessibility of
          the physical keyboard.  0 means it doesn't, 1 means it is accessible
          when the lid is open, 2 means it is accessible when the lid is
@@ -450,6 +416,60 @@
          The default is false. -->
     <bool name="config_lidControlsSleep">false</bool>
 
+    <!-- Desk dock behavior -->
+
+    <!-- The number of degrees to rotate the display when the device is in a desk dock.
+         A value of -1 means no change in orientation by default. -->
+    <integer name="config_deskDockRotation">-1</integer>
+
+    <!-- Control whether being in the desk dock (and powered) always
+         keeps the screen on.  By default it stays on when plugged in to
+         AC.  0 will not keep it on; or together 1 to stay on when plugged
+         in to AC and 2 to stay on when plugged in to USB.  (So 3 for both.) -->
+    <integer name="config_deskDockKeepsScreenOn">1</integer>
+
+    <!-- Control whether being in the desk dock should enable accelerometer
+         based screen orientation.  This defaults to true because it is
+         common for desk docks to be sold in a variety of form factors
+         with different orientations.  Since we cannot always tell these docks
+         apart and the docks cannot report their true orientation on their own,
+         we rely on gravity to determine the effective orientation. -->
+    <bool name="config_deskDockEnablesAccelerometer">true</bool>
+
+    <!-- Car dock behavior -->
+
+    <!-- The number of degrees to rotate the display when the device is in a car dock.
+         A value of -1 means no change in orientation by default. -->
+    <integer name="config_carDockRotation">-1</integer>
+
+    <!-- Control whether being in the car dock (and powered) always
+         keeps the screen on.  By default it stays on when plugged in to
+         AC.  0 will not keep it on; or together 1 to stay on when plugged
+         in to AC and 2 to stay on when plugged in to USB.  (So 3 for both.) -->
+    <integer name="config_carDockKeepsScreenOn">1</integer>
+
+    <!-- Control whether being in the car dock should enable accelerometer based
+         screen orientation.  This defaults to true because putting a device in
+         a car dock make the accelerometer more a physical input (like a lid). -->
+
+    <bool name="config_carDockEnablesAccelerometer">true</bool>
+
+    <!-- HDMI behavior -->
+
+    <!-- The number of degrees to rotate the display when the device has HDMI connected
+         but is not in a dock.  A value of -1 means no change in orientation by default.
+         Use -1 except on older devices whose Hardware Composer HAL does not
+         provide full support for multiple displays.  -->
+    <integer name="config_undockedHdmiRotation">-1</integer>
+
+    <!-- Control the default UI mode type to use when there is no other type override
+         happening.  One of the following values (See Configuration.java):
+             1  UI_MODE_TYPE_NORMAL
+             4  UI_MODE_TYPE_TELEVISION
+             5  UI_MODE_TYPE_APPLIANCE
+         Any other values will have surprising consequences. -->
+    <integer name="config_defaultUiModeType">1</integer>
+
     <!-- Indicate whether to allow the device to suspend when the screen is off
          due to the proximity sensor.  This resource should only be set to true
          if the sensor HAL correctly handles the proximity sensor as a wake-up source.
@@ -652,6 +672,11 @@
          Must be in the range specified by minimum and maximum. -->
     <integer name="config_screenBrightnessSettingDefault">102</integer>
 
+    <!-- Screen brightness used to dim the screen while dozing in a very low power state.
+         May be less than the minimum allowed brightness setting
+         that can be set by the user. -->
+    <integer name="config_screenBrightnessDoze">1</integer>
+
     <!-- Screen brightness used to dim the screen when the user activity
          timeout expires.  May be less than the minimum allowed brightness setting
          that can be set by the user. -->
@@ -1072,8 +1097,16 @@
     <!-- Name of the wimax state tracker clas -->
     <string name="config_wimaxStateTrackerClassname" translatable="false"></string>
 
-    <!-- Is the dreams feature supported? -->
+    <!-- Specifies whether the dreams feature should be supported.
+         When true, the system will allow the user to configure dreams (screensavers)
+         to launch when a user activity timeout occurs or the system is told to nap.
+         When false, the dreams feature will be disabled (this does not affect dozing).
+
+         Consider setting this resource to false or disabling dreams by default when a
+         doze component is specified below since dreaming will supercede dozing and
+         will prevent the system from entering a low power state until the dream ends. -->
     <bool name="config_dreamsSupported">true</bool>
+
     <!-- If supported, are dreams enabled? (by default) -->
     <bool name="config_dreamsEnabledByDefault">true</bool>
     <!-- If supported and enabled, are dreams activated when docked? (by default) -->
@@ -1083,6 +1116,70 @@
     <!-- ComponentName of the default dream (Settings.Secure.SCREENSAVER_COMPONENT) -->
     <string name="config_dreamsDefaultComponent">com.google.android.deskclock/com.android.deskclock.Screensaver</string>
 
+    <!-- Are we allowed to dream while not plugged in? -->
+    <bool name="config_dreamsEnabledOnBattery">false</bool>
+    <!-- Minimum battery level to allow dreaming when powered.
+         Use -1 to disable this safety feature. -->
+    <integer name="config_dreamsBatteryLevelMinimumWhenPowered">-1</integer>
+    <!-- Minimum battery level to allow dreaming when not powered.
+         Use -1 to disable this safety feature. -->
+    <integer name="config_dreamsBatteryLevelMinimumWhenNotPowered">15</integer>
+    <!-- If the battery level drops by this percentage and the user activity timeout
+         has expired, then assume the device is receiving insufficient current to charge
+         effectively and terminate the dream.  Use -1 to disable this safety feature.  -->
+    <integer name="config_dreamsBatteryLevelDrainCutoff">5</integer>
+
+    <!-- ComponentName of a dream to show whenever the system would otherwise have
+         gone to sleep.  When the PowerManager is asked to go to sleep, it will instead
+         try to start this dream if possible.  The dream should typically call startDozing()
+         to put the display into a low power state and allow the application processor
+         to be suspended.  When the dream ends, the system will go to sleep as usual.
+         Specify the component name (Settings.Secure.SCREENSAVER_COMPONENT) or an
+         empty string if none.
+
+         Note that doze dreams are not subject to the same start conditions as ordinary dreams.
+         Doze dreams will run whenever the power manager is in a dozing state. -->
+    <string name="config_dozeComponent"></string>
+
+    <!-- Power Management: Specifies whether to decouple the auto-suspend state of the
+         device from the display on/off state.
+
+         When false, autosuspend_disable() will be called before the display is turned on
+         and autosuspend_enable() will be called after the display is turned off.
+         This mode provides best compatibility for devices using legacy power management
+         features such as early suspend / late resume.
+
+         When true, autosuspend_display() and autosuspend_enable() will be called
+         independently of whether the display is being turned on or off.  This mode
+         enables the power manager to suspend the application processor while the
+         display is on.
+
+         This resource should be set to "true" when a doze component has been specified
+         to maximize power savings but not all devices support it.
+
+         Refer to autosuspend.h for details.
+    -->
+    <bool name="config_powerDecoupleAutoSuspendModeFromDisplay">false</bool>
+
+    <!-- Power Management: Specifies whether to decouple the interactive state of the
+         device from the display on/off state.
+
+         When false, setInteractive(..., true) will be called before the display is turned on
+         and setInteractive(..., false) will be called after the display is turned off.
+         This mode provides best compatibility for devices that expect the interactive
+         state to be tied to the display state.
+
+         When true, setInteractive(...) will be called independently of whether the display
+         is being turned on or off.  This mode enables the power manager to reduce
+         clocks and disable the touch controller while the display is on.
+
+         This resource should be set to "true" when a doze component has been specified
+         to maximize power savings but not all devices support it.
+
+         Refer to power.h for details.
+    -->
+    <bool name="config_powerDecoupleInteractiveModeFromDisplay">false</bool>
+
     <!-- Base "touch slop" value used by ViewConfiguration as a
          movement threshold where scrolling should begin. -->
     <dimen name="config_viewConfigurationTouchSlop">8dp</dimen>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 8187939..5e3cbe6 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2087,4 +2087,10 @@
   <public type="style" name="Theme.DeviceDefault.NoActionBar.TranslucentDecor" id="0x010301e3" />
   <public type="style" name="Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor" id="0x010301e4" />
 
+<!-- ===============================================================
+    Resources added in version 20 of the platform
+    =============================================================== -->
+  <eat-comment />
+
+  <public type="attr" name="banner" id="0x10103f2" />
 </resources>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 098fbbe..30243a4 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -625,9 +625,9 @@
     <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
     <string name="permlab_processOutgoingCalls">reroute outgoing calls</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_processOutgoingCalls">Allows the app to see the
-        number being dialed during an outgoing call with the option to redirect
-        the call to a different number or abort the call altogether.</string>
+    <string name="permdesc_processOutgoingCalls">Allows the app to process
+      outgoing calls and change the number to be dialed. This permission allows
+      the app to monitor, redirect, or prevent outgoing calls.</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_receiveSms">receive text messages (SMS)</string>
@@ -4195,7 +4195,7 @@
     <!-- Message shown when the user enters an invalid SIM pin password in PUK screen -->
     <string name="kg_invalid_sim_pin_hint">Type a PIN that is 4 to 8 numbers.</string>
     <!-- Message shown when the user enters an invalid PUK code in the PUK screen -->
-    <string name="kg_invalid_sim_puk_hint">PUK code should be 8 numbers or more.</string>
+    <string name="kg_invalid_sim_puk_hint">PUK code should be 8 numbers.</string>
     <!-- Message shown when the user enters an invalid PUK code -->
     <string name="kg_invalid_puk">Re-enter the correct PUK code. Repeated attempts will permanently disable the SIM.</string>
       <!-- String shown in PUK screen when PIN codes don't match -->
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index cb2fd6d..4d4feeee 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -225,6 +225,14 @@
         <item name="windowExitAnimation">@anim/fast_fade_out</item>
     </style>
 
+    <!-- Window animations for swipe-dismissable windows. {@hide} -->
+    <style name="Animation.SwipeDismiss">
+        <item name="taskOpenEnterAnimation">@anim/swipe_window_enter</item>
+        <item name="taskOpenExitAnimation">@anim/swipe_window_exit</item>
+        <item name="taskCloseEnterAnimation">@anim/swipe_window_enter</item>
+        <item name="taskCloseExitAnimation">@anim/swipe_window_exit</item>
+    </style>
+
     <!-- Status Bar Styles -->
     <style name="TextAppearance.StatusBar">
         <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
diff --git a/core/res/res/values/styles_micro.xml b/core/res/res/values/styles_micro.xml
new file mode 100644
index 0000000..52d90bc
--- /dev/null
+++ b/core/res/res/values/styles_micro.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+<resources>
+    <style name="Widget.Micro" parent="Widget.Holo" />
+
+    <style name="Widget.Micro.TextView">
+        <item name="android:fontFamily">sans-serif-condensed</item>
+    </style>
+
+    <style name="Widget.Micro.NumberPicker">
+        <item name="android:internalLayout">@android:layout/number_picker_with_selector_wheel_micro</item>
+        <item name="android:solidColor">@android:color/transparent</item>
+        <item name="android:selectionDivider">@android:drawable/numberpicker_selection_divider</item>
+        <item name="android:selectionDividerHeight">0dip</item>
+        <item name="android:selectionDividersDistance">104dip</item>
+        <item name="android:internalMinWidth">64dip</item>
+        <item name="android:internalMaxHeight">180dip</item>
+        <item name="virtualButtonPressedDrawable">?android:attr/selectableItemBackground</item>
+        <item name="android:descendantFocusability">blocksDescendants</item>
+    </style>
+</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 4171355..84510a8 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1307,6 +1307,7 @@
   <java-symbol type="bool" name="config_lidControlsSleep" />
   <java-symbol type="bool" name="config_reverseDefaultRotation" />
   <java-symbol type="bool" name="config_showNavigationBar" />
+  <java-symbol type="bool" name="config_supportAutoRotation" />
   <java-symbol type="bool" name="target_honeycomb_needs_options_menu" />
   <java-symbol type="dimen" name="navigation_bar_height" />
   <java-symbol type="dimen" name="navigation_bar_height_landscape" />
@@ -1374,6 +1375,7 @@
   <java-symbol type="layout" name="screen_progress" />
   <java-symbol type="layout" name="screen_simple" />
   <java-symbol type="layout" name="screen_simple_overlay_action_mode" />
+  <java-symbol type="layout" name="screen_swipe_dismiss" />
   <java-symbol type="layout" name="screen_title" />
   <java-symbol type="layout" name="screen_title_icons" />
   <java-symbol type="string" name="system_ui_date_pattern" />
@@ -1505,6 +1507,7 @@
   <java-symbol type="integer" name="config_screenBrightnessSettingMaximum" />
   <java-symbol type="integer" name="config_screenBrightnessSettingDefault" />
   <java-symbol type="integer" name="config_screenBrightnessDim" />
+  <java-symbol type="integer" name="config_screenBrightnessDoze" />
   <java-symbol type="integer" name="config_shutdownBatteryTemperature" />
   <java-symbol type="integer" name="config_undockedHdmiRotation" />
   <java-symbol type="integer" name="config_virtualKeyQuietTimeMillis" />
@@ -1609,11 +1612,18 @@
   <java-symbol type="xml" name="storage_list" />
   <java-symbol type="bool" name="config_dreamsSupported" />
   <java-symbol type="bool" name="config_dreamsEnabledByDefault" />
+  <java-symbol type="bool" name="config_dreamsEnabledOnBattery" />
   <java-symbol type="bool" name="config_dreamsActivatedOnDockByDefault" />
   <java-symbol type="bool" name="config_dreamsActivatedOnSleepByDefault" />
+  <java-symbol type="integer" name="config_dreamsBatteryLevelMinimumWhenPowered" />
+  <java-symbol type="integer" name="config_dreamsBatteryLevelMinimumWhenNotPowered" />
+  <java-symbol type="integer" name="config_dreamsBatteryLevelDrainCutoff" />
   <java-symbol type="string" name="config_dreamsDefaultComponent" />
+  <java-symbol type="string" name="config_dozeComponent" />
   <java-symbol type="string" name="enable_explore_by_touch_warning_title" />
   <java-symbol type="string" name="enable_explore_by_touch_warning_message" />
+  <java-symbol type="bool" name="config_powerDecoupleAutoSuspendModeFromDisplay" />
+  <java-symbol type="bool" name="config_powerDecoupleInteractiveModeFromDisplay" />
 
   <java-symbol type="layout" name="resolver_list" />
   <java-symbol type="id" name="resolver_list" />
diff --git a/core/res/res/values/themes_micro.xml b/core/res/res/values/themes_micro.xml
new file mode 100644
index 0000000..7c0b7bc
--- /dev/null
+++ b/core/res/res/values/themes_micro.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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.
+-->
+<resources>
+    <style name="Theme.Micro" parent="Theme.Holo.NoActionBar">
+        <item name="textViewStyle">@android:style/Widget.Micro.TextView</item>
+        <item name="numberPickerStyle">@android:style/Widget.Micro.NumberPicker</item>
+        <item name="windowAnimationStyle">@android:style/Animation.SwipeDismiss</item>
+        <item name="windowIsFloating">false</item>
+        <item name="windowIsTranslucent">true</item>
+        <item name="windowSwipeToDismiss">true</item>
+	</style>
+
+    <style name="Theme.Micro.NoActionBar" parent="Theme.Holo.NoActionBar">
+        <item name="textViewStyle">@android:style/Widget.Micro.TextView</item>
+        <item name="numberPickerStyle">@android:style/Widget.Micro.NumberPicker</item>
+        <item name="windowAnimationStyle">@android:style/Animation.SwipeDismiss</item>
+        <item name="windowIsFloating">false</item>
+        <item name="windowIsTranslucent">true</item>
+        <item name="windowSwipeToDismiss">true</item>
+    </style>
+    <style name="Theme.Micro.Light" parent="Theme.Holo.Light">
+        <item name="numberPickerStyle">@android:style/Widget.Micro.NumberPicker</item>
+        <item name="windowAnimationStyle">@android:style/Animation.SwipeDismiss</item>
+        <item name="windowIsFloating">false</item>
+        <item name="windowIsTranslucent">true</item>
+        <item name="windowSwipeToDismiss">true</item>
+	</style>
+    <style name="Theme.Micro.Light.NoActionBar" parent="Theme.Holo.Light.NoActionBar">
+        <item name="textViewStyle">@android:style/Widget.Micro.TextView</item>
+        <item name="numberPickerStyle">@android:style/Widget.Micro.NumberPicker</item>
+        <item name="windowAnimationStyle">@android:style/Animation.SwipeDismiss</item>
+        <item name="windowIsFloating">false</item>
+        <item name="windowIsTranslucent">true</item>
+        <item name="windowSwipeToDismiss">true</item>
+    </style>
+    <style name="Theme.Micro.Light.DarkActionBar" parent="Theme.Holo.Light.DarkActionBar">
+        <item name="textViewStyle">@android:style/Widget.Micro.TextView</item>
+        <item name="numberPickerStyle">@android:style/Widget.Micro.NumberPicker</item>
+        <item name="windowAnimationStyle">@android:style/Animation.SwipeDismiss</item>
+        <item name="windowIsFloating">false</item>
+        <item name="windowIsTranslucent">true</item>
+        <item name="windowSwipeToDismiss">true</item>
+    </style>
+
+</resources>
diff --git a/core/tests/coretests/src/android/net/LinkAddressTest.java b/core/tests/coretests/src/android/net/LinkAddressTest.java
new file mode 100644
index 0000000..17423be
--- /dev/null
+++ b/core/tests/coretests/src/android/net/LinkAddressTest.java
@@ -0,0 +1,331 @@
+/*
+ * Copyright (C) 2013 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.net;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.InterfaceAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import android.net.LinkAddress;
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import static libcore.io.OsConstants.IFA_F_DEPRECATED;
+import static libcore.io.OsConstants.IFA_F_PERMANENT;
+import static libcore.io.OsConstants.IFA_F_TENTATIVE;
+import static libcore.io.OsConstants.RT_SCOPE_HOST;
+import static libcore.io.OsConstants.RT_SCOPE_LINK;
+import static libcore.io.OsConstants.RT_SCOPE_SITE;
+import static libcore.io.OsConstants.RT_SCOPE_UNIVERSE;
+
+/**
+ * Tests for {@link LinkAddress}.
+ */
+public class LinkAddressTest extends AndroidTestCase {
+
+    private static final String V4 = "192.0.2.1";
+    private static final String V6 = "2001:db8::1";
+    private static final InetAddress V4_ADDRESS = NetworkUtils.numericToInetAddress(V4);
+    private static final InetAddress V6_ADDRESS = NetworkUtils.numericToInetAddress(V6);
+
+    public void testConstructors() throws SocketException {
+        LinkAddress address;
+
+        // Valid addresses work as expected.
+        address = new LinkAddress(V4_ADDRESS, 25);
+        assertEquals(V4_ADDRESS, address.getAddress());
+        assertEquals(25, address.getNetworkPrefixLength());
+        assertEquals(0, address.getFlags());
+        assertEquals(RT_SCOPE_UNIVERSE, address.getScope());
+
+        address = new LinkAddress(V6_ADDRESS, 127);
+        assertEquals(V6_ADDRESS, address.getAddress());
+        assertEquals(127, address.getNetworkPrefixLength());
+        assertEquals(0, address.getFlags());
+        assertEquals(RT_SCOPE_UNIVERSE, address.getScope());
+
+        // Nonsensical flags/scopes or combinations thereof are acceptable.
+        address = new LinkAddress(V6 + "/64", IFA_F_DEPRECATED | IFA_F_PERMANENT, RT_SCOPE_LINK);
+        assertEquals(V6_ADDRESS, address.getAddress());
+        assertEquals(64, address.getNetworkPrefixLength());
+        assertEquals(IFA_F_DEPRECATED | IFA_F_PERMANENT, address.getFlags());
+        assertEquals(RT_SCOPE_LINK, address.getScope());
+
+        address = new LinkAddress(V4 + "/23", 123, 456);
+        assertEquals(V4_ADDRESS, address.getAddress());
+        assertEquals(23, address.getNetworkPrefixLength());
+        assertEquals(123, address.getFlags());
+        assertEquals(456, address.getScope());
+
+        // InterfaceAddress doesn't have a constructor. Fetch some from an interface.
+        List<InterfaceAddress> addrs = NetworkInterface.getByName("lo").getInterfaceAddresses();
+
+        // We expect to find 127.0.0.1/8 and ::1/128, in any order.
+        LinkAddress ipv4Loopback, ipv6Loopback;
+        assertEquals(2, addrs.size());
+        if (addrs.get(0).getAddress() instanceof Inet4Address) {
+            ipv4Loopback = new LinkAddress(addrs.get(0));
+            ipv6Loopback = new LinkAddress(addrs.get(1));
+        } else {
+            ipv4Loopback = new LinkAddress(addrs.get(1));
+            ipv6Loopback = new LinkAddress(addrs.get(0));
+        }
+
+        assertEquals(NetworkUtils.numericToInetAddress("127.0.0.1"), ipv4Loopback.getAddress());
+        assertEquals(8, ipv4Loopback.getNetworkPrefixLength());
+
+        assertEquals(NetworkUtils.numericToInetAddress("::1"), ipv6Loopback.getAddress());
+        assertEquals(128, ipv6Loopback.getNetworkPrefixLength());
+
+        // Null addresses are rejected.
+        try {
+            address = new LinkAddress(null, 24);
+            fail("Null InetAddress should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress((String) null, IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
+            fail("Null string should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress((InterfaceAddress) null);
+            fail("Null string should cause NullPointerException");
+        } catch(NullPointerException expected) {}
+
+        // Invalid prefix lengths are rejected.
+        try {
+            address = new LinkAddress(V4_ADDRESS, -1);
+            fail("Negative IPv4 prefix length should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress(V6_ADDRESS, -1);
+            fail("Negative IPv6 prefix length should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress(V4_ADDRESS, 33);
+            fail("/33 IPv4 prefix length should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress(V4 + "/33", IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
+            fail("/33 IPv4 prefix length should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+
+        try {
+            address = new LinkAddress(V6_ADDRESS, 129, IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
+            fail("/129 IPv6 prefix length should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress(V6 + "/129", IFA_F_PERMANENT, RT_SCOPE_UNIVERSE);
+            fail("/129 IPv6 prefix length should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        // Multicast addresses are rejected.
+        try {
+            address = new LinkAddress("224.0.0.2/32");
+            fail("IPv4 multicast address should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+
+        try {
+            address = new LinkAddress("ff02::1/128");
+            fail("IPv6 multicast address should cause IllegalArgumentException");
+        } catch(IllegalArgumentException expected) {}
+    }
+
+    public void testAddressScopes() {
+        assertEquals(RT_SCOPE_HOST, new LinkAddress("::/128").getScope());
+        assertEquals(RT_SCOPE_HOST, new LinkAddress("0.0.0.0/32").getScope());
+
+        assertEquals(RT_SCOPE_LINK, new LinkAddress("::1/128").getScope());
+        assertEquals(RT_SCOPE_LINK, new LinkAddress("127.0.0.5/8").getScope());
+        assertEquals(RT_SCOPE_LINK, new LinkAddress("fe80::ace:d00d/64").getScope());
+        assertEquals(RT_SCOPE_LINK, new LinkAddress("169.254.5.12/16").getScope());
+
+        assertEquals(RT_SCOPE_SITE, new LinkAddress("fec0::dead/64").getScope());
+
+        assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("10.1.2.3/21").getScope());
+        assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("192.0.2.1/25").getScope());
+        assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("2001:db8::/64").getScope());
+        assertEquals(RT_SCOPE_UNIVERSE, new LinkAddress("5000::/127").getScope());
+    }
+
+    private void assertIsSameAddressAs(LinkAddress l1, LinkAddress l2) {
+        assertTrue(l1 + " unexpectedly does not have same address as " + l2,
+                l1.isSameAddressAs(l2));
+        assertTrue(l2 + " unexpectedly does not have same address as " + l1,
+                l2.isSameAddressAs(l1));
+    }
+
+    private void assertIsNotSameAddressAs(LinkAddress l1, LinkAddress l2) {
+        assertFalse(l1 + " unexpectedly has same address as " + l2,
+                l1.isSameAddressAs(l2));
+        assertFalse(l2 + " unexpectedly has same address as " + l1,
+                l1.isSameAddressAs(l2));
+    }
+
+    private void assertLinkAddressesEqual(LinkAddress l1, LinkAddress l2) {
+        assertTrue(l1 + " unexpectedly not equal to " + l2, l1.equals(l2));
+        assertTrue(l2 + " unexpectedly not equal to " + l1, l2.equals(l1));
+        assertEquals(l1.hashCode(), l2.hashCode());
+    }
+
+    private void assertLinkAddressesNotEqual(LinkAddress l1, LinkAddress l2) {
+        assertFalse(l1 + " unexpectedly equal to " + l2, l1.equals(l2));
+        assertFalse(l2 + " unexpectedly equal to " + l1, l2.equals(l1));
+    }
+
+    public void testEqualsAndSameAddressAs() {
+        LinkAddress l1, l2, l3;
+
+        l1 = new LinkAddress("2001:db8::1/64");
+        l2 = new LinkAddress("2001:db8::1/64");
+        assertLinkAddressesEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+
+        l2 = new LinkAddress("2001:db8::1/65");
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsNotSameAddressAs(l1, l2);
+
+        l2 = new LinkAddress("2001:db8::2/64");
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsNotSameAddressAs(l1, l2);
+
+
+        l1 = new LinkAddress("192.0.2.1/24");
+        l2 = new LinkAddress("192.0.2.1/24");
+        assertLinkAddressesEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+
+        l2 = new LinkAddress("192.0.2.1/23");
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsNotSameAddressAs(l1, l2);
+
+        l2 = new LinkAddress("192.0.2.2/24");
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsNotSameAddressAs(l1, l2);
+
+
+        // Check equals() and isSameAddressAs() on identical addresses with different flags.
+        l1 = new LinkAddress(V6_ADDRESS, 64);
+        l2 = new LinkAddress(V6_ADDRESS, 64, 0, RT_SCOPE_UNIVERSE);
+        assertLinkAddressesEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+
+        l2 = new LinkAddress(V6_ADDRESS, 64, IFA_F_DEPRECATED, RT_SCOPE_UNIVERSE);
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+
+        // Check equals() and isSameAddressAs() on identical addresses with different scope.
+        l1 = new LinkAddress(V4_ADDRESS, 24);
+        l2 = new LinkAddress(V4_ADDRESS, 24, 0, RT_SCOPE_UNIVERSE);
+        assertLinkAddressesEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+
+        l2 = new LinkAddress(V4_ADDRESS, 24, 0, RT_SCOPE_HOST);
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+
+        // Addresses with the same start or end bytes aren't equal between families.
+        l1 = new LinkAddress("32.1.13.184/24");
+        l2 = new LinkAddress("2001:db8::1/24");
+        l3 = new LinkAddress("::2001:db8/24");
+
+        byte[] ipv4Bytes = l1.getAddress().getAddress();
+        byte[] l2FirstIPv6Bytes = Arrays.copyOf(l2.getAddress().getAddress(), 4);
+        byte[] l3LastIPv6Bytes = Arrays.copyOfRange(l3.getAddress().getAddress(), 12, 16);
+        assertTrue(Arrays.equals(ipv4Bytes, l2FirstIPv6Bytes));
+        assertTrue(Arrays.equals(ipv4Bytes, l3LastIPv6Bytes));
+
+        assertLinkAddressesNotEqual(l1, l2);
+        assertIsNotSameAddressAs(l1, l2);
+
+        assertLinkAddressesNotEqual(l1, l3);
+        assertIsNotSameAddressAs(l1, l3);
+
+        // Because we use InetAddress, an IPv4 address is equal to its IPv4-mapped address.
+        // TODO: Investigate fixing this.
+        String addressString = V4 + "/24";
+        l1 = new LinkAddress(addressString);
+        l2 = new LinkAddress("::ffff:" + addressString);
+        assertLinkAddressesEqual(l1, l2);
+        assertIsSameAddressAs(l1, l2);
+    }
+
+    public void testHashCode() {
+        LinkAddress l;
+
+        l = new LinkAddress(V4_ADDRESS, 23);
+        assertEquals(-982787, l.hashCode());
+
+        l = new LinkAddress(V4_ADDRESS, 23, 0, RT_SCOPE_HOST);
+        assertEquals(-971865, l.hashCode());
+
+        l = new LinkAddress(V4_ADDRESS, 27);
+        assertEquals(-982743, l.hashCode());
+
+        l = new LinkAddress(V6_ADDRESS, 64);
+        assertEquals(1076522926, l.hashCode());
+
+        l = new LinkAddress(V6_ADDRESS, 128);
+        assertEquals(1076523630, l.hashCode());
+
+        l = new LinkAddress(V6_ADDRESS, 128, IFA_F_TENTATIVE, RT_SCOPE_UNIVERSE);
+        assertEquals(1076524846, l.hashCode());
+    }
+
+    private LinkAddress passThroughParcel(LinkAddress l) {
+        Parcel p = Parcel.obtain();
+        LinkAddress l2 = null;
+        try {
+            l.writeToParcel(p, 0);
+            p.setDataPosition(0);
+            l2 = LinkAddress.CREATOR.createFromParcel(p);
+        } finally {
+            p.recycle();
+        }
+        assertNotNull(l2);
+        return l2;
+    }
+
+    private void assertParcelingIsLossless(LinkAddress l) {
+      LinkAddress l2 = passThroughParcel(l);
+      assertEquals(l, l2);
+    }
+
+    public void testParceling() {
+        LinkAddress l;
+
+        l = new LinkAddress(V6_ADDRESS, 64, 123, 456);
+        assertParcelingIsLossless(l);
+
+        l = new LinkAddress(V4 + "/28", IFA_F_PERMANENT, RT_SCOPE_LINK);
+        assertParcelingIsLossless(l);
+    }
+}
diff --git a/core/tests/coretests/src/android/net/LinkPropertiesTest.java b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
index e63f6b0..a602e07 100644
--- a/core/tests/coretests/src/android/net/LinkPropertiesTest.java
+++ b/core/tests/coretests/src/android/net/LinkPropertiesTest.java
@@ -24,6 +24,8 @@
 import java.net.InetAddress;
 import java.util.ArrayList;
 
+import libcore.io.OsConstants;
+
 public class LinkPropertiesTest extends TestCase {
     private static InetAddress ADDRV4 = NetworkUtils.numericToInetAddress("75.208.6.1");
     private static InetAddress ADDRV6 = NetworkUtils.numericToInetAddress(
@@ -341,6 +343,10 @@
         assertFalse(rmnet0.removeStackedLink(clat4));
     }
 
+    private LinkAddress getFirstLinkAddress(LinkProperties lp) {
+        return lp.getLinkAddresses().iterator().next();
+    }
+
     @SmallTest
     public void testAddressMethods() {
         LinkProperties lp = new LinkProperties();
@@ -366,26 +372,56 @@
         // Addresses on the base link.
         // Check the return values of hasIPvXAddress and ensure the add/remove methods return true
         // iff something changes.
+        assertEquals(0, lp.getLinkAddresses().size());
         assertTrue(lp.addLinkAddress(LINKADDRV6));
+        assertEquals(1, lp.getLinkAddresses().size());
         assertFalse(lp.hasIPv4Address());
         assertTrue(lp.hasIPv6Address());
 
         assertTrue(lp.removeLinkAddress(LINKADDRV6));
+        assertEquals(0, lp.getLinkAddresses().size());
         assertTrue(lp.addLinkAddress(LINKADDRV4));
+        assertEquals(1, lp.getLinkAddresses().size());
         assertTrue(lp.hasIPv4Address());
         assertFalse(lp.hasIPv6Address());
 
         assertTrue(lp.addLinkAddress(LINKADDRV6));
+        assertEquals(2, lp.getLinkAddresses().size());
         assertTrue(lp.hasIPv4Address());
         assertTrue(lp.hasIPv6Address());
 
         // Adding an address twice has no effect.
         // Removing an address that's not present has no effect.
         assertFalse(lp.addLinkAddress(LINKADDRV4));
+        assertEquals(2, lp.getLinkAddresses().size());
         assertTrue(lp.hasIPv4Address());
         assertTrue(lp.removeLinkAddress(LINKADDRV4));
+        assertEquals(1, lp.getLinkAddresses().size());
         assertFalse(lp.hasIPv4Address());
         assertFalse(lp.removeLinkAddress(LINKADDRV4));
+        assertEquals(1, lp.getLinkAddresses().size());
+
+        // Adding an address that's already present but with different properties causes the
+        // existing address to be updated and returns true.
+        // Start with only LINKADDRV6.
+        assertEquals(1, lp.getLinkAddresses().size());
+        assertEquals(LINKADDRV6, getFirstLinkAddress(lp));
+
+        // Create a LinkAddress object for the same address, but with different flags.
+        LinkAddress deprecated = new LinkAddress(ADDRV6, 128,
+                OsConstants.IFA_F_DEPRECATED, OsConstants.RT_SCOPE_UNIVERSE);
+        assertTrue(deprecated.isSameAddressAs(LINKADDRV6));
+        assertFalse(deprecated.equals(LINKADDRV6));
+
+        // Check that adding it updates the existing address instead of adding a new one.
+        assertTrue(lp.addLinkAddress(deprecated));
+        assertEquals(1, lp.getLinkAddresses().size());
+        assertEquals(deprecated, getFirstLinkAddress(lp));
+        assertFalse(LINKADDRV6.equals(getFirstLinkAddress(lp)));
+
+        // Removing LINKADDRV6 removes deprecated, because removing addresses ignores properties.
+        assertTrue(lp.removeLinkAddress(LINKADDRV6));
+        assertEquals(0, lp.getLinkAddresses().size());
     }
 
     @SmallTest
diff --git a/core/tests/coretests/src/com/android/internal/util/XmlUtilsTest.java b/core/tests/coretests/src/com/android/internal/util/XmlUtilsTest.java
new file mode 100644
index 0000000..2596ece
--- /dev/null
+++ b/core/tests/coretests/src/com/android/internal/util/XmlUtilsTest.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (C) 2013 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.internal.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+
+public class XmlUtilsTest extends TestCase {
+
+    // https://code.google.com/p/android/issues/detail?id=63717
+    public void testMapWithNullKeys() throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put(null, "nullValue");
+        map.put("foo", "fooValue");
+        XmlUtils.writeMapXml(map, baos);
+
+        InputStream mapInput = new ByteArrayInputStream(baos.toByteArray());
+        HashMap<String, ?> deserialized = XmlUtils.readMapXml(mapInput);
+        assertEquals("nullValue", deserialized.get(null));
+        assertEquals("fooValue", deserialized.get("foo"));
+    }
+}
diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
index 1413319..0cdcb1c 100644
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -161,8 +161,8 @@
 key 139   MENU              WAKE_DROPPED
 key 140   CALCULATOR
 # key 141 "KEY_SETUP"
-key 142   POWER             WAKE
-key 143   POWER             WAKE
+key 142   SLEEP             WAKE
+key 143   WAKEUP            WAKE
 # key 144 "KEY_FILE"
 # key 145 "KEY_SENDFILE"
 # key 146 "KEY_DELETEFILE"
@@ -423,3 +423,16 @@
 axis 0x0a BRAKE
 axis 0x10 HAT_X
 axis 0x11 HAT_Y
+
+# LEDs
+led 0x00 NUM_LOCK
+led 0x01 CAPS_LOCK
+led 0x02 SCROLL_LOCK
+led 0x03 COMPOSE
+led 0x04 KANA
+led 0x05 SLEEP
+led 0x06 SUSPEND
+led 0x07 MUTE
+led 0x08 MISC
+led 0x09 MAIL
+led 0x0a CHARGING
diff --git a/data/keyboards/Vendor_18d1_Product_2c40.kl b/data/keyboards/Vendor_18d1_Product_2c40.kl
new file mode 100644
index 0000000..903f13b6
--- /dev/null
+++ b/data/keyboards/Vendor_18d1_Product_2c40.kl
@@ -0,0 +1,42 @@
+# Copyright (C) 2013 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.
+
+# Odie
+
+key 304 BUTTON_A
+key 305 BUTTON_B
+key 307 BUTTON_X
+key 308 BUTTON_Y
+key 310 BUTTON_L1
+key 311 BUTTON_R1
+key 316 BUTTON_MODE
+key 317 BUTTON_THUMBL
+key 318 BUTTON_THUMBR
+
+key 158 BACK            WAKE_DROPPED
+key 172 HOME
+
+axis 0x00 X
+axis 0x01 Y
+axis 0x02 Z
+axis 0x05 RZ
+axis 0x09 RTRIGGER
+axis 0x0a LTRIGGER
+axis 0x10 HAT_X
+axis 0x11 HAT_Y
+
+led 0x00 CONTROLLER_1
+led 0x01 CONTROLLER_2
+led 0x02 CONTROLLER_3
+led 0x03 CONTROLLER_4
diff --git a/docs/html/guide/topics/ui/accessibility/services.jd b/docs/html/guide/topics/ui/accessibility/services.jd
index 4bd752f..c868080 100644
--- a/docs/html/guide/topics/ui/accessibility/services.jd
+++ b/docs/html/guide/topics/ui/accessibility/services.jd
@@ -81,7 +81,8 @@
 <pre>
 &lt;application&gt;
   &lt;service android:name=&quot;.MyAccessibilityService&quot;
-      android:label=&quot;@string/accessibility_service_label&quot;&gt;
+      android:label=&quot;@string/accessibility_service_label&quot;
+      android:permission=&quot;android.permission.BIND_ACCESSIBILITY_SERVICE&quot&gt;
     &lt;intent-filter&gt;
       &lt;action android:name=&quot;android.accessibilityservice.AccessibilityService&quot; /&gt;
     &lt;/intent-filter&gt;
diff --git a/docs/html/guide/topics/ui/drag-drop.jd b/docs/html/guide/topics/ui/drag-drop.jd
index e989374..9a6b0e9 100644
--- a/docs/html/guide/topics/ui/drag-drop.jd
+++ b/docs/html/guide/topics/ui/drag-drop.jd
@@ -873,7 +873,7 @@
 
 ...
 
-protected class myDragEventListener implements View.OnDragEventListener {
+protected class myDragEventListener implements View.OnDragListener {
 
     // This is the method that the system calls when it dispatches a drag event to the
     // listener.
@@ -899,18 +899,15 @@
                     v.invalidate();
 
                     // returns true to indicate that the View can accept the dragged data.
-                    return(true);
+                    return true;
 
-                    } else {
+                }
 
-                    // Returns false. During the current drag and drop operation, this View will
-                    // not receive events again until ACTION_DRAG_ENDED is sent.
-                    return(false);
+                // Returns false. During the current drag and drop operation, this View will
+                // not receive events again until ACTION_DRAG_ENDED is sent.
+                return false;
 
-                    }
-                break;
-
-            case DragEvent.ACTION_DRAG_ENTERED: {
+            case DragEvent.ACTION_DRAG_ENTERED:
 
                 // Applies a green tint to the View. Return true; the return value is ignored.
 
@@ -919,79 +916,70 @@
                 // Invalidate the view to force a redraw in the new tint
                 v.invalidate();
 
-                return(true);
+                return true;
 
-                break;
-
-                case DragEvent.ACTION_DRAG_LOCATION:
+            case DragEvent.ACTION_DRAG_LOCATION:
 
                 // Ignore the event
-                    return(true);
+                return true;
 
+            case DragEvent.ACTION_DRAG_EXITED:
+
+                // Re-sets the color tint to blue. Returns true; the return value is ignored.
+                v.setColorFilter(Color.BLUE);
+
+                // Invalidate the view to force a redraw in the new tint
+                v.invalidate();
+
+                return true;
+
+            case DragEvent.ACTION_DROP:
+
+                // Gets the item containing the dragged data
+                ClipData.Item item = event.getClipData().getItemAt(0);
+
+                // Gets the text data from the item.
+                dragData = item.getText();
+
+                // Displays a message containing the dragged data.
+                Toast.makeText(this, "Dragged data is " + dragData, Toast.LENGTH_LONG);
+
+                // Turns off any color tints
+                v.clearColorFilter();
+
+                // Invalidates the view to force a redraw
+                v.invalidate();
+
+                // Returns true. DragEvent.getResult() will return true.
+                return true;
+
+            case DragEvent.ACTION_DRAG_ENDED:
+
+                // Turns off any color tinting
+                v.clearColorFilter();
+
+                // Invalidates the view to force a redraw
+                v.invalidate();
+
+                // Does a getResult(), and displays what happened.
+                if (event.getResult()) {
+                    Toast.makeText(this, "The drop was handled.", Toast.LENGTH_LONG);
+
+                } else {
+                    Toast.makeText(this, "The drop didn't work.", Toast.LENGTH_LONG);
+
+                }
+
+                // returns true; the value is ignored.
+                return true;
+
+            // An unknown action type was received.
+            default:
+                Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
                 break;
-
-                case DragEvent.ACTION_DRAG_EXITED:
-
-                    // Re-sets the color tint to blue. Returns true; the return value is ignored.
-                    v.setColorFilter(Color.BLUE);
-
-                    // Invalidate the view to force a redraw in the new tint
-                    v.invalidate();
-
-                    return(true);
-
-                break;
-
-                case DragEvent.ACTION_DROP:
-
-                    // Gets the item containing the dragged data
-                    ClipData.Item item = event.getClipData().getItemAt(0);
-
-                    // Gets the text data from the item.
-                    dragData = item.getText();
-
-                    // Displays a message containing the dragged data.
-                    Toast.makeText(this, "Dragged data is " + dragData, Toast.LENGTH_LONG);
-
-                    // Turns off any color tints
-                    v.clearColorFilter();
-
-                    // Invalidates the view to force a redraw
-                    v.invalidate();
-
-                    // Returns true. DragEvent.getResult() will return true.
-                    return(true);
-
-                break;
-
-                case DragEvent.ACTION_DRAG_ENDED:
-
-                    // Turns off any color tinting
-                    v.clearColorFilter();
-
-                    // Invalidates the view to force a redraw
-                    v.invalidate();
-
-                    // Does a getResult(), and displays what happened.
-                    if (event.getResult()) {
-                        Toast.makeText(this, "The drop was handled.", Toast.LENGTH_LONG);
-
-                    } else {
-                        Toast.makeText(this, "The drop didn't work.", Toast.LENGTH_LONG);
-
-                    };
-
-                    // returns true; the value is ignored.
-                    return(true);
-
-                break;
-
-                // An unknown action type was received.
-                default:
-                    Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
-
-                break;
-        };
-    };
+        }
+        
+        return false;
+    }
 };
 </pre>
diff --git a/docs/html/training/articles/perf-tips.jd b/docs/html/training/articles/perf-tips.jd
index 7ff6c5c..1660b7f 100644
--- a/docs/html/training/articles/perf-tips.jd
+++ b/docs/html/training/articles/perf-tips.jd
@@ -16,7 +16,6 @@
   <li><a href="#AvoidFloat">Avoid Using Floating-Point</a></li>
   <li><a href="#UseLibraries">Know and Use the Libraries</a></li>
   <li><a href="#NativeMethods">Use Native Methods Carefully</a></li>
-  <li><a href="#library">Know And Use The Libraries</a></li>
   <li><a href="#native_methods">Use Native Methods Judiciously</a></li>
   <li><a href="#closing_notes">Closing Notes</a></li>
 </ol>
diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java
index 10cdab0..c05ea2e 100644
--- a/drm/java/android/drm/DrmManagerClient.java
+++ b/drm/java/android/drm/DrmManagerClient.java
@@ -116,7 +116,7 @@
     private static final int ACTION_PROCESS_DRM_INFO = 1002;
 
     private int mUniqueId;
-    private int mNativeContext;
+    private long mNativeContext;
     private volatile boolean mReleased;
     private Context mContext;
     private InfoHandler mInfoHandler;
diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp
index baddf62..de8531b 100644
--- a/drm/jni/android_drm_DrmManagerClient.cpp
+++ b/drm/jni/android_drm_DrmManagerClient.cpp
@@ -182,25 +182,27 @@
             JNIEnv* env, jobject thiz, const sp<DrmManagerClientImpl>& client) {
     Mutex::Autolock l(sLock);
     jclass clazz = env->FindClass("android/drm/DrmManagerClient");
-    jfieldID fieldId = env->GetFieldID(clazz, "mNativeContext", "I");
+    jfieldID fieldId = env->GetFieldID(clazz, "mNativeContext", "J");
 
-    sp<DrmManagerClientImpl> old = (DrmManagerClientImpl*)env->GetIntField(thiz, fieldId);
+    jlong oldHandle = env->GetLongField(thiz, fieldId);
+    sp<DrmManagerClientImpl> old = reinterpret_cast<DrmManagerClientImpl*>(oldHandle);
     if (client.get()) {
         client->incStrong(thiz);
     }
     if (old != 0) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, fieldId, (int)client.get());
+    env->SetLongField(thiz, fieldId, reinterpret_cast<jlong>(client.get()));
     return old;
 }
 
 static sp<DrmManagerClientImpl> getDrmManagerClientImpl(JNIEnv* env, jobject thiz) {
     Mutex::Autolock l(sLock);
     jclass clazz = env->FindClass("android/drm/DrmManagerClient");
-    jfieldID fieldId = env->GetFieldID(clazz, "mNativeContext", "I");
+    jfieldID fieldId = env->GetFieldID(clazz, "mNativeContext", "J");
 
-    DrmManagerClientImpl* const client = (DrmManagerClientImpl*)env->GetIntField(thiz, fieldId);
+    jlong clientHandle = env->GetLongField(thiz, fieldId);
+    DrmManagerClientImpl* const client = reinterpret_cast<DrmManagerClientImpl*>(clientHandle);
     return sp<DrmManagerClientImpl>(client);
 }
 
@@ -214,7 +216,7 @@
 
     setDrmManagerClientImpl(env, thiz, drmManager);
     ALOGV("initialize - Exit");
-    return uniqueId;
+    return static_cast<jint>(uniqueId);
 }
 
 static void android_drm_DrmManagerClient_setListeners(
@@ -406,7 +408,7 @@
 
     delete[] mData; mData = NULL;
     ALOGV("saveRights - Exit");
-    return result;
+    return static_cast<jint>(result);
 }
 
 static jboolean android_drm_DrmManagerClient_canHandle(
@@ -583,7 +585,7 @@
             ->getDrmObjectType(uniqueId, Utility::getStringValue(env, path),
                                 Utility::getStringValue(env, mimeType));
     ALOGV("getDrmObjectType Exit");
-    return drmObjectType;
+    return static_cast<jint>(drmObjectType);
 }
 
 static jstring android_drm_DrmManagerClient_getOriginalMimeType(
@@ -609,20 +611,21 @@
         = getDrmManagerClientImpl(env, thiz)
             ->checkRightsStatus(uniqueId, Utility::getStringValue(env, path), action);
     ALOGV("checkRightsStatus Exit");
-    return rightsStatus;
+    return static_cast<jint>(rightsStatus);
 }
 
 static jint android_drm_DrmManagerClient_removeRights(
             JNIEnv* env, jobject thiz, jint uniqueId, jstring path) {
     ALOGV("removeRights");
-    return getDrmManagerClientImpl(env, thiz)
-               ->removeRights(uniqueId, Utility::getStringValue(env, path));
+    return static_cast<jint>(getDrmManagerClientImpl(env, thiz)
+               ->removeRights(uniqueId, Utility::getStringValue(env, path)));
 }
 
 static jint android_drm_DrmManagerClient_removeAllRights(
             JNIEnv* env, jobject thiz, jint uniqueId) {
     ALOGV("removeAllRights");
-    return getDrmManagerClientImpl(env, thiz)->removeAllRights(uniqueId);
+    return static_cast<jint>(getDrmManagerClientImpl(env, thiz)
+                ->removeAllRights(uniqueId));
 }
 
 static jint android_drm_DrmManagerClient_openConvertSession(
@@ -632,7 +635,7 @@
         = getDrmManagerClientImpl(env, thiz)
             ->openConvertSession(uniqueId, Utility::getStringValue(env, mimeType));
     ALOGV("openConvertSession Exit");
-    return convertId;
+    return static_cast<jint>(convertId);
 }
 
 static jobject GetConvertedStatus(JNIEnv* env, DrmConvertedStatus* pDrmConvertedStatus) {
@@ -686,7 +689,7 @@
 }
 
 static jobject android_drm_DrmManagerClient_closeConvertSession(
-            JNIEnv* env, jobject thiz, int uniqueId, jint convertId) {
+            JNIEnv* env, jobject thiz, jint uniqueId, jint convertId) {
 
     ALOGV("closeConvertSession Enter");
 
diff --git a/graphics/java/android/graphics/AvoidXfermode.java b/graphics/java/android/graphics/AvoidXfermode.java
index 5a59e36..206c959 100644
--- a/graphics/java/android/graphics/AvoidXfermode.java
+++ b/graphics/java/android/graphics/AvoidXfermode.java
@@ -56,6 +56,6 @@
         native_instance = nativeCreate(opColor, tolerance, mode.nativeInt);
     }
 
-    private static native int nativeCreate(int opColor, int tolerance,
-                                           int nativeMode);
+    private static native long nativeCreate(int opColor, int tolerance,
+                                            int nativeMode);
 }
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index b566699..efce606 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -41,7 +41,7 @@
      * 
      * @hide
      */
-    public final int mNativeBitmap;
+    public final long mNativeBitmap;
 
     /**
      * Backing buffer for the Bitmap.
@@ -67,16 +67,6 @@
      * setPremultiplied() aren't order dependent, despite being setters.
      */
     private boolean mIsPremultiplied;
-
-    /**
-     * Whether the Bitmap's content is expected to have alpha. Note that hasAlpha()
-     * does not directly return this value, because hasAlpha() may never return true
-     * for a 565 Bitmap.
-     *
-     * Any time this or mIsPremultiplied is changed, both are passed to native so they
-     * are not order dependent.
-     */
-    private boolean mHasAlpha;
     private byte[] mNinePatchChunk;   // may be null
     private int[] mLayoutBounds;   // may be null
     private int mWidth;
@@ -113,7 +103,7 @@
      * int (pointer).
      */
     @SuppressWarnings({"UnusedDeclaration"}) // called from JNI
-    Bitmap(int nativeBitmap, byte[] buffer, int width, int height, int density,
+    Bitmap(long nativeBitmap, byte[] buffer, int width, int height, int density,
             boolean isMutable, boolean isPremultiplied,
             byte[] ninePatchChunk, int[] layoutBounds) {
         if (nativeBitmap == 0) {
@@ -400,7 +390,7 @@
          * No color information is stored.
          * With this configuration, each pixel requires 1 byte of memory.
          */
-        ALPHA_8     (1),
+        ALPHA_8     (2),
 
         /**
          * Each pixel is stored on 2 bytes and only the RGB channels are
@@ -416,7 +406,7 @@
          * This configuration may be useful when using opaque bitmaps
          * that do not require high color fidelity.
          */
-        RGB_565     (3),
+        RGB_565     (4),
 
         /**
          * Each pixel is stored on 2 bytes. The three RGB color channels
@@ -438,7 +428,7 @@
          *             it is advised to use {@link #ARGB_8888} instead.
          */
         @Deprecated
-        ARGB_4444   (4),
+        ARGB_4444   (5),
 
         /**
          * Each pixel is stored on 4 bytes. Each channel (RGB and alpha
@@ -448,13 +438,13 @@
          * This configuration is very flexible and offers the best
          * quality. It should be used whenever possible.
          */
-        ARGB_8888   (5);
+        ARGB_8888   (6);
 
         final int nativeInt;
 
         @SuppressWarnings({"deprecation"})
         private static Config sConfigs[] = {
-            null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
+            null, null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
         };
         
         Config(int ni) {
@@ -564,7 +554,7 @@
         checkRecycled("Can't copy a recycled bitmap");
         Bitmap b = nativeCopy(mNativeBitmap, config.nativeInt, isMutable);
         if (b != null) {
-            b.setAlphaAndPremultiplied(mHasAlpha, mIsPremultiplied);
+            b.mIsPremultiplied = mIsPremultiplied;
             b.mDensity = mDensity;
         }
         return b;
@@ -737,12 +727,12 @@
                 paint.setAntiAlias(true);
             }
         }
-
+        
         // The new bitmap was created from a known bitmap source so assume that
         // they use the same density
         bitmap.mDensity = source.mDensity;
-        bitmap.setAlphaAndPremultiplied(source.mHasAlpha, source.mIsPremultiplied);
-
+        bitmap.mIsPremultiplied = source.mIsPremultiplied;
+        
         canvas.setBitmap(bitmap);
         canvas.drawBitmap(source, srcR, dstR, paint);
         canvas.setBitmap(null);
@@ -820,9 +810,9 @@
         if (display != null) {
             bm.mDensity = display.densityDpi;
         }
-        bm.setHasAlpha(hasAlpha);
         if (config == Config.ARGB_8888 && !hasAlpha) {
             nativeErase(bm.mNativeBitmap, 0xff000000);
+            nativeSetHasAlpha(bm.mNativeBitmap, hasAlpha);
         }
         // No need to initialize the bitmap to zeroes with other configs;
         // it is backed by a VM byte array which is by definition preinitialized
@@ -894,7 +884,6 @@
         if (display != null) {
             bm.mDensity = display.densityDpi;
         }
-        bm.mHasAlpha = true;
         return bm;
     }
 
@@ -1052,24 +1041,11 @@
      * <p>This method will not affect the behavior of a bitmap without an alpha
      * channel, or if {@link #hasAlpha()} returns false.</p>
      *
-     * <p>Calling createBitmap() or createScaledBitmap() with a source
-     * Bitmap whose colors are not pre-multiplied may result in a RuntimeException,
-     * since those functions require drawing the source, which is not supported for
-     * un-pre-multiplied Bitmaps.</p>
-     *
      * @see Bitmap#isPremultiplied()
      * @see BitmapFactory.Options#inPremultiplied
      */
     public final void setPremultiplied(boolean premultiplied) {
         mIsPremultiplied = premultiplied;
-        nativeSetAlphaAndPremultiplied(mNativeBitmap, mHasAlpha, premultiplied);
-    }
-
-    /** Helper function to set both alpha and premultiplied. **/
-    private final void setAlphaAndPremultiplied(boolean hasAlpha, boolean premultiplied) {
-        mHasAlpha = hasAlpha;
-        mIsPremultiplied = premultiplied;
-        nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha, premultiplied);
     }
 
     /** Returns the bitmap's width */
@@ -1230,8 +1206,7 @@
      * non-opaque per-pixel alpha values.
      */
     public void setHasAlpha(boolean hasAlpha) {
-        mHasAlpha = hasAlpha;
-        nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha, mIsPremultiplied);
+        nativeSetHasAlpha(mNativeBitmap, hasAlpha);
     }
 
     /**
@@ -1536,7 +1511,7 @@
      */
     public Bitmap extractAlpha(Paint paint, int[] offsetXY) {
         checkRecycled("Can't extractAlpha on a recycled bitmap");
-        int nativePaint = paint != null ? paint.mNativePaint : 0;
+        long nativePaint = paint != null ? paint.mNativePaint : 0;
         Bitmap bm = nativeExtractAlpha(mNativeBitmap, nativePaint, offsetXY);
         if (bm == null) {
             throw new RuntimeException("Failed to extractAlpha on Bitmap");
@@ -1570,9 +1545,9 @@
     }
 
     private static class BitmapFinalizer {
-        private final int mNativeBitmap;
+        private final long mNativeBitmap;
 
-        BitmapFinalizer(int nativeBitmap) {
+        BitmapFinalizer(long nativeBitmap) {
             mNativeBitmap = nativeBitmap;
         }
 
@@ -1593,56 +1568,55 @@
     private static native Bitmap nativeCreate(int[] colors, int offset,
                                               int stride, int width, int height,
                                               int nativeConfig, boolean mutable);
-    private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig,
+    private static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig,
                                             boolean isMutable);
-    private static native void nativeDestructor(int nativeBitmap);
-    private static native boolean nativeRecycle(int nativeBitmap);
-    private static native void nativeReconfigure(int nativeBitmap, int width, int height,
+    private static native void nativeDestructor(long nativeBitmap);
+    private static native boolean nativeRecycle(long nativeBitmap);
+    private static native void nativeReconfigure(long nativeBitmap, int width, int height,
                                                  int config, int allocSize);
 
-    private static native boolean nativeCompress(int nativeBitmap, int format,
+    private static native boolean nativeCompress(long nativeBitmap, int format,
                                             int quality, OutputStream stream,
                                             byte[] tempStorage);
-    private static native void nativeErase(int nativeBitmap, int color);
-    private static native int nativeRowBytes(int nativeBitmap);
-    private static native int nativeConfig(int nativeBitmap);
+    private static native void nativeErase(long nativeBitmap, int color);
+    private static native int nativeRowBytes(long nativeBitmap);
+    private static native int nativeConfig(long nativeBitmap);
 
-    private static native int nativeGetPixel(int nativeBitmap, int x, int y,
+    private static native int nativeGetPixel(long nativeBitmap, int x, int y,
                                              boolean isPremultiplied);
-    private static native void nativeGetPixels(int nativeBitmap, int[] pixels,
+    private static native void nativeGetPixels(long nativeBitmap, int[] pixels,
                                                int offset, int stride, int x, int y,
                                                int width, int height, boolean isPremultiplied);
 
-    private static native void nativeSetPixel(int nativeBitmap, int x, int y,
+    private static native void nativeSetPixel(long nativeBitmap, int x, int y,
                                               int color, boolean isPremultiplied);
-    private static native void nativeSetPixels(int nativeBitmap, int[] colors,
+    private static native void nativeSetPixels(long nativeBitmap, int[] colors,
                                                int offset, int stride, int x, int y,
                                                int width, int height, boolean isPremultiplied);
-    private static native void nativeCopyPixelsToBuffer(int nativeBitmap,
+    private static native void nativeCopyPixelsToBuffer(long nativeBitmap,
                                                         Buffer dst);
-    private static native void nativeCopyPixelsFromBuffer(int nb, Buffer src);
-    private static native int nativeGenerationId(int nativeBitmap);
+    private static native void nativeCopyPixelsFromBuffer(long nativeBitmap, Buffer src);
+    private static native int nativeGenerationId(long nativeBitmap);
 
     private static native Bitmap nativeCreateFromParcel(Parcel p);
     // returns true on success
-    private static native boolean nativeWriteToParcel(int nativeBitmap,
+    private static native boolean nativeWriteToParcel(long nativeBitmap,
                                                       boolean isMutable,
                                                       int density,
                                                       Parcel p);
     // returns a new bitmap built from the native bitmap's alpha, and the paint
-    private static native Bitmap nativeExtractAlpha(int nativeBitmap,
-                                                    int nativePaint,
+    private static native Bitmap nativeExtractAlpha(long nativeBitmap,
+                                                    long nativePaint,
                                                     int[] offsetXY);
 
-    private static native void nativePrepareToDraw(int nativeBitmap);
-    private static native boolean nativeHasAlpha(int nativeBitmap);
-    private static native void nativeSetAlphaAndPremultiplied(int nBitmap, boolean hasAlpha,
-                                                              boolean isPremul);
-    private static native boolean nativeHasMipMap(int nativeBitmap);
-    private static native void nativeSetHasMipMap(int nBitmap, boolean hasMipMap);
-    private static native boolean nativeSameAs(int nb0, int nb1);
-    
-    /* package */ final int ni() {
+    private static native void nativePrepareToDraw(long nativeBitmap);
+    private static native boolean nativeHasAlpha(long nativeBitmap);
+    private static native void nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha);
+    private static native boolean nativeHasMipMap(long nativeBitmap);
+    private static native void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap);
+    private static native boolean nativeSameAs(long nativeBitmap0, long nativeBitmap1);
+
+    /* package */ final long ni() {
         return mNativeBitmap;
     }
 }
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index 4575364..1f35e50 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -153,12 +153,8 @@
          *
          * <p>This does not affect bitmaps without an alpha channel.</p>
          *
-         * <p>Setting this flag to false while setting {@link #inScaled} to true
-         * may result in incorrect colors.</p>
-         *
          * @see Bitmap#hasAlpha()
          * @see Bitmap#isPremultiplied()
-         * @see #inScaled
          */
         public boolean inPremultiplied;
 
@@ -253,9 +249,6 @@
          * <p>This flag is turned on by default and should be turned off if you need
          * a non-scaled version of the bitmap.  Nine-patch bitmaps ignore this
          * flag and are always scaled.
-         *
-         * <p>If {@link #inPremultiplied} is set to false, and the image has alpha,
-         * setting this flag to true may result in incorrect colors.
          */
         public boolean inScaled;
 
@@ -590,7 +583,7 @@
         Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
         try {
             if (is instanceof AssetManager.AssetInputStream) {
-                final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
+                final long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
                 bm = nativeDecodeAsset(asset, outPadding, opts);
             } else {
                 bm = decodeStreamInternal(is, outPadding, opts);
@@ -693,7 +686,7 @@
             Rect padding, Options opts);
     private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,
             Rect padding, Options opts);
-    private static native Bitmap nativeDecodeAsset(int asset, Rect padding, Options opts);
+    private static native Bitmap nativeDecodeAsset(long nativeAsset, Rect padding, Options opts);
     private static native Bitmap nativeDecodeByteArray(byte[] data, int offset,
             int length, Options opts);
     private static native boolean nativeIsSeekable(FileDescriptor fd);
diff --git a/graphics/java/android/graphics/BitmapRegionDecoder.java b/graphics/java/android/graphics/BitmapRegionDecoder.java
index 3a99977..e689b08 100644
--- a/graphics/java/android/graphics/BitmapRegionDecoder.java
+++ b/graphics/java/android/graphics/BitmapRegionDecoder.java
@@ -33,7 +33,7 @@
  *
  */
 public final class BitmapRegionDecoder {
-    private int mNativeBitmapRegionDecoder;
+    private long mNativeBitmapRegionDecoder;
     private boolean mRecycled;
     // ensures that the native decoder object exists and that only one decode can
     // occur at a time.
@@ -114,7 +114,7 @@
             boolean isShareable) throws IOException {
         if (is instanceof AssetManager.AssetInputStream) {
             return nativeNewInstance(
-                    ((AssetManager.AssetInputStream) is).getAssetInt(),
+                    ((AssetManager.AssetInputStream) is).getNativeAsset(),
                     isShareable);
         } else {
             // pass some temp storage down to the native code. 1024 is made up,
@@ -165,7 +165,7 @@
 
         This can be called from JNI code.
     */
-    private BitmapRegionDecoder(int decoder) {
+    private BitmapRegionDecoder(long decoder) {
         mNativeBitmapRegionDecoder = decoder;
         mRecycled = false;
     }
@@ -254,12 +254,12 @@
         }
     }
 
-    private static native Bitmap nativeDecodeRegion(int lbm,
+    private static native Bitmap nativeDecodeRegion(long lbm,
             int start_x, int start_y, int width, int height,
             BitmapFactory.Options options);
-    private static native int nativeGetWidth(int lbm);
-    private static native int nativeGetHeight(int lbm);
-    private static native void nativeClean(int lbm);
+    private static native int nativeGetWidth(long lbm);
+    private static native int nativeGetHeight(long lbm);
+    private static native void nativeClean(long lbm);
 
     private static native BitmapRegionDecoder nativeNewInstance(
             byte[] data, int offset, int length, boolean isShareable);
@@ -268,5 +268,5 @@
     private static native BitmapRegionDecoder nativeNewInstance(
             InputStream is, byte[] storage, boolean isShareable);
     private static native BitmapRegionDecoder nativeNewInstance(
-            int asset, boolean isShareable);
+            long asset, boolean isShareable);
 }
diff --git a/graphics/java/android/graphics/BitmapShader.java b/graphics/java/android/graphics/BitmapShader.java
index a4f75b9..b7673d8 100644
--- a/graphics/java/android/graphics/BitmapShader.java
+++ b/graphics/java/android/graphics/BitmapShader.java
@@ -42,7 +42,7 @@
         mBitmap = bitmap;
         mTileX = tileX;
         mTileY = tileY;
-        final int b = bitmap.ni();
+        final long b = bitmap.ni();
         native_instance = nativeCreate(b, tileX.nativeInt, tileY.nativeInt);
         native_shader = nativePostCreate(native_instance, b, tileX.nativeInt, tileY.nativeInt);
     }
@@ -57,8 +57,8 @@
         return copy;
     }
 
-    private static native int nativeCreate(int native_bitmap, int shaderTileModeX,
+    private static native long nativeCreate(long native_bitmap, int shaderTileModeX,
             int shaderTileModeY);
-    private static native int nativePostCreate(int native_shader, int native_bitmap,
+    private static native long nativePostCreate(long native_shader, long native_bitmap,
             int shaderTileModeX, int shaderTileModeY);
 }
diff --git a/graphics/java/android/graphics/BlurMaskFilter.java b/graphics/java/android/graphics/BlurMaskFilter.java
index 5eafe76..939af52 100644
--- a/graphics/java/android/graphics/BlurMaskFilter.java
+++ b/graphics/java/android/graphics/BlurMaskFilter.java
@@ -47,5 +47,5 @@
         native_instance = nativeConstructor(radius, style.native_int);
     }
 
-    private static native int nativeConstructor(float radius, int style);
+    private static native long nativeConstructor(float radius, int style);
 }
diff --git a/graphics/java/android/graphics/Camera.java b/graphics/java/android/graphics/Camera.java
index 9e07bd4..c263a84 100644
--- a/graphics/java/android/graphics/Camera.java
+++ b/graphics/java/android/graphics/Camera.java
@@ -159,7 +159,7 @@
     }
 
     public native float dotWithNormal(float dx, float dy, float dz);
-    
+
     protected void finalize() throws Throwable {
         try {
             nativeDestructor();
@@ -170,8 +170,8 @@
 
     private native void nativeConstructor();
     private native void nativeDestructor();
-    private native void nativeGetMatrix(int native_matrix);
-    private native void nativeApplyToCanvas(int native_canvas);
-    
-    int native_instance;
+    private native void nativeGetMatrix(long native_matrix);
+    private native void nativeApplyToCanvas(long native_canvas);
+
+    long native_instance;
 }
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index d46238f..f86840e 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -40,7 +40,7 @@
 
     // assigned in constructors or setBitmap, freed in finalizer
     /** @hide */
-    public int mNativeCanvas;
+    public long mNativeCanvas;
 
     // may be null
     private Bitmap mBitmap;
@@ -84,9 +84,9 @@
     private final CanvasFinalizer mFinalizer;
 
     private static final class CanvasFinalizer {
-        private int mNativeCanvas;
+        private long mNativeCanvas;
 
-        public CanvasFinalizer(int nativeCanvas) {
+        public CanvasFinalizer(long nativeCanvas) {
             mNativeCanvas = nativeCanvas;
         }
 
@@ -144,7 +144,7 @@
     }
 
     /** @hide */
-    public Canvas(int nativeCanvas) {
+    public Canvas(long nativeCanvas) {
         if (nativeCanvas == 0) {
             throw new IllegalStateException();
         }
@@ -157,8 +157,8 @@
      * Replace existing canvas while ensuring that the swap has occurred before
      * the previous native canvas is unreferenced.
      */
-    private void safeCanvasSwap(int nativeCanvas, boolean copyState) {
-        final int oldCanvas = mNativeCanvas;
+    private void safeCanvasSwap(long nativeCanvas, boolean copyState) {
+        final long oldCanvas = mNativeCanvas;
         mNativeCanvas = nativeCanvas;
         mFinalizer.mNativeCanvas = nativeCanvas;
         if (copyState) {
@@ -174,7 +174,7 @@
      *
      * @hide
      */
-    public int getNativeCanvas() {
+    public long getNativeCanvas() {
         return mNativeCanvas;
     }
 
@@ -712,7 +712,7 @@
     }
     
     public void setDrawFilter(DrawFilter filter) {
-        int nativeFilter = 0;
+        long nativeFilter = 0;
         if (filter != null) {
             nativeFilter = filter.mNativeInt;
         }
@@ -1387,7 +1387,7 @@
                 vertOffset, texs, texOffset, colors, colorOffset,
                 indices, indexOffset, indexCount, paint.mNativePaint);
     }
-    
+
     /**
      * Draw the text, with origin at (x,y), using the specified paint. The
      * origin is interpreted based on the Align setting in the paint.
@@ -1713,137 +1713,155 @@
      */
     public static native void freeTextLayoutCaches();
 
-    private static native int initRaster(int nativeBitmapOrZero);
-    private static native void copyNativeCanvasState(int srcCanvas, int dstCanvas);
-    private static native int native_saveLayer(int nativeCanvas, RectF bounds,
-                                               int paint, int layerFlags);
-    private static native int native_saveLayer(int nativeCanvas, float l,
+    private static native long initRaster(long nativeBitmapOrZero);
+    private static native void copyNativeCanvasState(long nativeSrcCanvas,
+                                                     long nativeDstCanvas);
+    private static native int native_saveLayer(long nativeCanvas,
+                                               RectF bounds,
+                                               long nativePaint,
+                                               int layerFlags);
+    private static native int native_saveLayer(long nativeCanvas, float l,
                                                float t, float r, float b,
-                                               int paint, int layerFlags);
-    private static native int native_saveLayerAlpha(int nativeCanvas,
+                                               long nativePaint,
+                                               int layerFlags);
+    private static native int native_saveLayerAlpha(long nativeCanvas,
                                                     RectF bounds, int alpha,
                                                     int layerFlags);
-    private static native int native_saveLayerAlpha(int nativeCanvas, float l,
+    private static native int native_saveLayerAlpha(long nativeCanvas, float l,
                                                     float t, float r, float b,
                                                     int alpha, int layerFlags);
 
-    private static native void native_concat(int nCanvas, int nMatrix);
-    private static native void native_setMatrix(int nCanvas, int nMatrix);
-    private static native boolean native_clipRect(int nCanvas,
+    private static native void native_concat(long nativeCanvas,
+                                             long nativeMatrix);
+    private static native void native_setMatrix(long nativeCanvas,
+                                                long nativeMatrix);
+    private static native boolean native_clipRect(long nativeCanvas,
                                                   float left, float top,
                                                   float right, float bottom,
                                                   int regionOp);
-    private static native boolean native_clipPath(int nativeCanvas,
-                                                  int nativePath,
+    private static native boolean native_clipPath(long nativeCanvas,
+                                                  long nativePath,
                                                   int regionOp);
-    private static native boolean native_clipRegion(int nativeCanvas,
-                                                    int nativeRegion,
+    private static native boolean native_clipRegion(long nativeCanvas,
+                                                    long nativeRegion,
                                                     int regionOp);
-    private static native void nativeSetDrawFilter(int nativeCanvas,
-                                                   int nativeFilter);
-    private static native boolean native_getClipBounds(int nativeCanvas,
+    private static native void nativeSetDrawFilter(long nativeCanvas,
+                                                   long nativeFilter);
+    private static native boolean native_getClipBounds(long nativeCanvas,
                                                        Rect bounds);
-    private static native void native_getCTM(int canvas, int matrix);
-    private static native boolean native_quickReject(int nativeCanvas,
+    private static native void native_getCTM(long nativeCanvas,
+                                             long nativeMatrix);
+    private static native boolean native_quickReject(long nativeCanvas,
                                                      RectF rect);
-    private static native boolean native_quickReject(int nativeCanvas,
-                                                     int path);
-    private static native boolean native_quickReject(int nativeCanvas,
+    private static native boolean native_quickReject(long nativeCanvas,
+                                                     long nativePath);
+    private static native boolean native_quickReject(long nativeCanvas,
                                                      float left, float top,
                                                      float right, float bottom);
-    private static native void native_drawRGB(int nativeCanvas, int r, int g,
+    private static native void native_drawRGB(long nativeCanvas, int r, int g,
                                               int b);
-    private static native void native_drawARGB(int nativeCanvas, int a, int r,
+    private static native void native_drawARGB(long nativeCanvas, int a, int r,
                                                int g, int b);
-    private static native void native_drawColor(int nativeCanvas, int color);
-    private static native void native_drawColor(int nativeCanvas, int color,
+    private static native void native_drawColor(long nativeCanvas, int color);
+    private static native void native_drawColor(long nativeCanvas, int color,
                                                 int mode);
-    private static native void native_drawPaint(int nativeCanvas, int paint);
-    private static native void native_drawLine(int nativeCanvas, float startX,
+    private static native void native_drawPaint(long nativeCanvas,
+                                                long nativePaint);
+    private static native void native_drawLine(long nativeCanvas, float startX,
                                                float startY, float stopX,
-                                               float stopY, int paint);
-    private static native void native_drawRect(int nativeCanvas, RectF rect,
-                                               int paint);
-    private static native void native_drawRect(int nativeCanvas, float left,
+                                               float stopY, long nativePaint);
+    private static native void native_drawRect(long nativeCanvas, RectF rect,
+                                               long nativePaint);
+    private static native void native_drawRect(long nativeCanvas, float left,
                                                float top, float right,
-                                               float bottom, int paint);
-    private static native void native_drawOval(int nativeCanvas, RectF oval,
-                                               int paint);
-    private static native void native_drawCircle(int nativeCanvas, float cx,
+                                               float bottom,
+                                               long nativePaint);
+    private static native void native_drawOval(long nativeCanvas, RectF oval,
+                                               long nativePaint);
+    private static native void native_drawCircle(long nativeCanvas, float cx,
                                                  float cy, float radius,
-                                                 int paint);
-    private static native void native_drawArc(int nativeCanvas, RectF oval,
+                                                 long nativePaint);
+    private static native void native_drawArc(long nativeCanvas, RectF oval,
                                               float startAngle, float sweep,
-                                              boolean useCenter, int paint);
-    private static native void native_drawRoundRect(int nativeCanvas,
+                                              boolean useCenter,
+                                              long nativePaint);
+    private static native void native_drawRoundRect(long nativeCanvas,
                                                     RectF rect, float rx,
-                                                    float ry, int paint);
-    private static native void native_drawPath(int nativeCanvas, int path,
-                                               int paint);
-    private native void native_drawBitmap(int nativeCanvas, int bitmap,
+                                                    float ry, long nativePaint);
+    private static native void native_drawPath(long nativeCanvas,
+                                               long nativePath,
+                                               long nativePaint);
+    private native void native_drawBitmap(long nativeCanvas, long nativeBitmap,
                                                  float left, float top,
-                                                 int nativePaintOrZero,
+                                                 long nativePaintOrZero,
                                                  int canvasDensity,
                                                  int screenDensity,
                                                  int bitmapDensity);
-    private native void native_drawBitmap(int nativeCanvas, int bitmap,
+    private native void native_drawBitmap(long nativeCanvas, long nativeBitmap,
                                                  Rect src, RectF dst,
-                                                 int nativePaintOrZero,
+                                                 long nativePaintOrZero,
                                                  int screenDensity,
                                                  int bitmapDensity);
-    private static native void native_drawBitmap(int nativeCanvas, int bitmap,
+    private static native void native_drawBitmap(long nativeCanvas,
+                                                 long nativeBitmap,
                                                  Rect src, Rect dst,
-                                                 int nativePaintOrZero,
+                                                 long nativePaintOrZero,
                                                  int screenDensity,
                                                  int bitmapDensity);
-    private static native void native_drawBitmap(int nativeCanvas, int[] colors,
+    private static native void native_drawBitmap(long nativeCanvas, int[] colors,
                                                 int offset, int stride, float x,
                                                  float y, int width, int height,
                                                  boolean hasAlpha,
-                                                 int nativePaintOrZero);
-    private static native void nativeDrawBitmapMatrix(int nCanvas, int nBitmap,
-                                                      int nMatrix, int nPaint);
-    private static native void nativeDrawBitmapMesh(int nCanvas, int nBitmap,
+                                                 long nativePaintOrZero);
+    private static native void nativeDrawBitmapMatrix(long nativeCanvas,
+                                                      long nativeBitmap,
+                                                      long nativeMatrix,
+                                                      long nativePaint);
+    private static native void nativeDrawBitmapMesh(long nativeCanvas,
+                                                    long nativeBitmap,
                                                     int meshWidth, int meshHeight,
                                                     float[] verts, int vertOffset,
-                                                    int[] colors, int colorOffset, int nPaint);
-    private static native void nativeDrawVertices(int nCanvas, int mode, int n,
+                                                    int[] colors, int colorOffset,
+                                                    long nativePaint);
+    private static native void nativeDrawVertices(long nativeCanvas, int mode, int n,
                    float[] verts, int vertOffset, float[] texs, int texOffset,
                    int[] colors, int colorOffset, short[] indices,
-                   int indexOffset, int indexCount, int nPaint);
-    
-    private static native void native_drawText(int nativeCanvas, char[] text,
+                   int indexOffset, int indexCount, long nativePaint);
+
+    private static native void native_drawText(long nativeCanvas, char[] text,
                                                int index, int count, float x,
-                                               float y, int flags, int paint);
-    private static native void native_drawText(int nativeCanvas, String text,
+                                               float y, int flags,
+                                               long nativePaint);
+    private static native void native_drawText(long nativeCanvas, String text,
                                                int start, int end, float x,
-                                               float y, int flags, int paint);
+                                               float y, int flags,
+                                               long nativePaint);
 
-    private static native void native_drawTextRun(int nativeCanvas, String text,
+    private static native void native_drawTextRun(long nativeCanvas, String text,
             int start, int end, int contextStart, int contextEnd,
-            float x, float y, int flags, int paint);
+            float x, float y, int flags, long nativePaint);
 
-    private static native void native_drawTextRun(int nativeCanvas, char[] text,
+    private static native void native_drawTextRun(long nativeCanvas, char[] text,
             int start, int count, int contextStart, int contextCount,
-            float x, float y, int flags, int paint);
+            float x, float y, int flags, long nativePaint);
 
-    private static native void native_drawPosText(int nativeCanvas,
+    private static native void native_drawPosText(long nativeCanvas,
                                                   char[] text, int index,
                                                   int count, float[] pos,
-                                                  int paint);
-    private static native void native_drawPosText(int nativeCanvas,
+                                                  long nativePaint);
+    private static native void native_drawPosText(long nativeCanvas,
                                                   String text, float[] pos,
-                                                  int paint);
-    private static native void native_drawTextOnPath(int nativeCanvas,
+                                                  long nativePaint);
+    private static native void native_drawTextOnPath(long nativeCanvas,
                                                      char[] text, int index,
-                                                     int count, int path,
+                                                     int count, long nativePath,
                                                      float hOffset,
                                                      float vOffset, int bidiFlags,
-                                                     int paint);
-    private static native void native_drawTextOnPath(int nativeCanvas,
-                                                     String text, int path,
-                                                     float hOffset, 
-                                                     float vOffset, 
-                                                     int flags, int paint);
-    private static native void finalizer(int nativeCanvas);
+                                                     long nativePaint);
+    private static native void native_drawTextOnPath(long nativeCanvas,
+                                                     String text, long nativePath,
+                                                     float hOffset,
+                                                     float vOffset,
+                                                     int flags, long nativePaint);
+    private static native void finalizer(long nativeCanvas);
 }
diff --git a/graphics/java/android/graphics/ColorFilter.java b/graphics/java/android/graphics/ColorFilter.java
index e5cf830..8e432da 100644
--- a/graphics/java/android/graphics/ColorFilter.java
+++ b/graphics/java/android/graphics/ColorFilter.java
@@ -23,12 +23,12 @@
 
 
 public class ColorFilter {
-    int native_instance;
+    long native_instance;
 
     /**
      * @hide
      */
-    public int nativeColorFilter;
+    public long nativeColorFilter;
 
     protected void finalize() throws Throwable {
         try {
@@ -38,5 +38,5 @@
         }
     }
 
-    private static native void finalizer(int native_instance, int nativeColorFilter);
+    private static native void finalizer(long native_instance, long nativeColorFilter);
 }
diff --git a/graphics/java/android/graphics/ColorMatrixColorFilter.java b/graphics/java/android/graphics/ColorMatrixColorFilter.java
index 4f32342..21b7721 100644
--- a/graphics/java/android/graphics/ColorMatrixColorFilter.java
+++ b/graphics/java/android/graphics/ColorMatrixColorFilter.java
@@ -45,6 +45,6 @@
         nativeColorFilter = nColorMatrixFilter(native_instance, array);
     }
 
-    private static native int nativeColorMatrixFilter(float[] array);
-    private static native int nColorMatrixFilter(int nativeFilter, float[] array);
+    private static native long nativeColorMatrixFilter(float[] array);
+    private static native long nColorMatrixFilter(long nativeFilter, float[] array);
 }
diff --git a/graphics/java/android/graphics/ComposePathEffect.java b/graphics/java/android/graphics/ComposePathEffect.java
index beac78e..3fc9eb5 100644
--- a/graphics/java/android/graphics/ComposePathEffect.java
+++ b/graphics/java/android/graphics/ComposePathEffect.java
@@ -27,6 +27,7 @@
                                        innerpe.native_instance);
     }
     
-    private static native int nativeCreate(int outerpe, int innerpe);
+    private static native long nativeCreate(long nativeOuterpe,
+                                            long nativeInnerpe);
 }
 
diff --git a/graphics/java/android/graphics/ComposeShader.java b/graphics/java/android/graphics/ComposeShader.java
index de0d3d6..5109ffd 100644
--- a/graphics/java/android/graphics/ComposeShader.java
+++ b/graphics/java/android/graphics/ComposeShader.java
@@ -104,12 +104,12 @@
         return copy;
     }
 
-    private static native int nativeCreate1(int native_shaderA, int native_shaderB,
-            int native_mode);
-    private static native int nativeCreate2(int native_shaderA, int native_shaderB,
+    private static native long nativeCreate1(long native_shaderA, long native_shaderB,
+            long native_mode);
+    private static native long nativeCreate2(long native_shaderA, long native_shaderB,
             int porterDuffMode);
-    private static native int nativePostCreate1(int native_shader, int native_skiaShaderA,
-            int native_skiaShaderB, int native_mode);
-    private static native int nativePostCreate2(int native_shader, int native_skiaShaderA,
-            int native_skiaShaderB, int porterDuffMode);
+    private static native long nativePostCreate1(long native_shader, long native_skiaShaderA,
+            long native_skiaShaderB, long native_mode);
+    private static native long nativePostCreate2(long native_shader, long native_skiaShaderA,
+            long native_skiaShaderB, int porterDuffMode);
 }
diff --git a/graphics/java/android/graphics/CornerPathEffect.java b/graphics/java/android/graphics/CornerPathEffect.java
index 400c886..8f4d7d9 100644
--- a/graphics/java/android/graphics/CornerPathEffect.java
+++ b/graphics/java/android/graphics/CornerPathEffect.java
@@ -28,6 +28,6 @@
         native_instance = nativeCreate(radius);
     }
     
-    private static native int nativeCreate(float radius);
+    private static native long nativeCreate(float radius);
 }
 
diff --git a/graphics/java/android/graphics/DashPathEffect.java b/graphics/java/android/graphics/DashPathEffect.java
index 2bdecce..ef3ebe8 100644
--- a/graphics/java/android/graphics/DashPathEffect.java
+++ b/graphics/java/android/graphics/DashPathEffect.java
@@ -38,6 +38,6 @@
         native_instance = nativeCreate(intervals, phase);
     }
     
-    private static native int nativeCreate(float intervals[], float phase);
+    private static native long nativeCreate(float intervals[], float phase);
 }
 
diff --git a/graphics/java/android/graphics/DiscretePathEffect.java b/graphics/java/android/graphics/DiscretePathEffect.java
index de8b2f0..3b3c9c9 100644
--- a/graphics/java/android/graphics/DiscretePathEffect.java
+++ b/graphics/java/android/graphics/DiscretePathEffect.java
@@ -26,6 +26,6 @@
         native_instance = nativeCreate(segmentLength, deviation);
     }
     
-    private static native int nativeCreate(float length, float deviation);
+    private static native long nativeCreate(float length, float deviation);
 }
 
diff --git a/graphics/java/android/graphics/DrawFilter.java b/graphics/java/android/graphics/DrawFilter.java
index 1f64539..ed38f37 100644
--- a/graphics/java/android/graphics/DrawFilter.java
+++ b/graphics/java/android/graphics/DrawFilter.java
@@ -25,7 +25,7 @@
 public class DrawFilter {
 
     // this is set by subclasses, but don't make it public
-    /* package */ int mNativeInt;    // pointer to native object
+    /* package */ long mNativeInt;    // pointer to native object
 
     protected void finalize() throws Throwable {
         try {
@@ -35,6 +35,6 @@
         }
     }
     
-    private static native void nativeDestructor(int nativeDrawFilter);
+    private static native void nativeDestructor(long nativeDrawFilter);
 }
 
diff --git a/graphics/java/android/graphics/EmbossMaskFilter.java b/graphics/java/android/graphics/EmbossMaskFilter.java
index 5dd8611..a9e180f 100644
--- a/graphics/java/android/graphics/EmbossMaskFilter.java
+++ b/graphics/java/android/graphics/EmbossMaskFilter.java
@@ -33,6 +33,6 @@
         native_instance = nativeConstructor(direction, ambient, specular, blurRadius);
     }
 
-    private static native int nativeConstructor(float[] direction, float ambient, float specular, float blurRadius);
+    private static native long nativeConstructor(float[] direction, float ambient, float specular, float blurRadius);
 }
 
diff --git a/graphics/java/android/graphics/Interpolator.java b/graphics/java/android/graphics/Interpolator.java
index 75851a6..f695a9e 100644
--- a/graphics/java/android/graphics/Interpolator.java
+++ b/graphics/java/android/graphics/Interpolator.java
@@ -151,13 +151,13 @@
     
     private int mValueCount;
     private int mFrameCount;
-    private final int native_instance;
+    private final long native_instance;
 
-    private static native int  nativeConstructor(int valueCount, int frameCount);
-    private static native void nativeDestructor(int native_instance);
-    private static native void nativeReset(int native_instance, int valueCount, int frameCount);
-    private static native void nativeSetKeyFrame(int native_instance, int index, int msec, float[] values, float[] blend);
-    private static native void nativeSetRepeatMirror(int native_instance, float repeatCount, boolean mirror);
-    private static native int  nativeTimeToValues(int native_instance, int msec, float[] values);
+    private static native long nativeConstructor(int valueCount, int frameCount);
+    private static native void nativeDestructor(long native_instance);
+    private static native void nativeReset(long native_instance, int valueCount, int frameCount);
+    private static native void nativeSetKeyFrame(long native_instance, int index, int msec, float[] values, float[] blend);
+    private static native void nativeSetRepeatMirror(long native_instance, float repeatCount, boolean mirror);
+    private static native int  nativeTimeToValues(long native_instance, int msec, float[] values);
 }
 
diff --git a/graphics/java/android/graphics/LargeBitmap.java b/graphics/java/android/graphics/LargeBitmap.java
index 6656b17..238b32a 100644
--- a/graphics/java/android/graphics/LargeBitmap.java
+++ b/graphics/java/android/graphics/LargeBitmap.java
@@ -37,7 +37,7 @@
  * @hide
  */
 public final class LargeBitmap {
-    private int mNativeLargeBitmap;
+    private long mNativeLargeBitmap;
     private boolean mRecycled;
 
     /*  Private constructor that must received an already allocated native
@@ -45,8 +45,8 @@
 
         This can be called from JNI code.
     */
-    private LargeBitmap(int lbm) {
-        mNativeLargeBitmap = lbm;
+    private LargeBitmap(long nativeLbm) {
+        mNativeLargeBitmap = nativeLbm;
         mRecycled = false;
     }
 
@@ -119,10 +119,10 @@
         recycle();
     }
 
-    private static native Bitmap nativeDecodeRegion(int lbm,
+    private static native Bitmap nativeDecodeRegion(long nativeLbm,
             int start_x, int start_y, int width, int height,
             BitmapFactory.Options options);
-    private static native int nativeGetWidth(int lbm);
-    private static native int nativeGetHeight(int lbm);
-    private static native void nativeClean(int lbm);
+    private static native int nativeGetWidth(long nativeLbm);
+    private static native int nativeGetHeight(long nativeLbm);
+    private static native void nativeClean(long nativeLbm);
 }
diff --git a/graphics/java/android/graphics/LayerRasterizer.java b/graphics/java/android/graphics/LayerRasterizer.java
index 9bd55a5..dc307c6 100644
--- a/graphics/java/android/graphics/LayerRasterizer.java
+++ b/graphics/java/android/graphics/LayerRasterizer.java
@@ -34,7 +34,7 @@
         nativeAddLayer(native_instance, paint.mNativePaint, 0, 0);
     }
 
-    private static native int nativeConstructor();
-    private static native void nativeAddLayer(int native_layer, int native_paint, float dx, float dy);
+    private static native long nativeConstructor();
+    private static native void nativeAddLayer(long native_layer, long native_paint, float dx, float dy);
 }
 
diff --git a/graphics/java/android/graphics/LightingColorFilter.java b/graphics/java/android/graphics/LightingColorFilter.java
index c621de6..fbd2694 100644
--- a/graphics/java/android/graphics/LightingColorFilter.java
+++ b/graphics/java/android/graphics/LightingColorFilter.java
@@ -33,6 +33,6 @@
         nativeColorFilter = nCreateLightingFilter(native_instance, mul, add);
     }
 
-    private static native int native_CreateLightingFilter(int mul, int add);
-    private static native int nCreateLightingFilter(int nativeFilter, int mul, int add);
+    private static native long native_CreateLightingFilter(int mul, int add);
+    private static native long nCreateLightingFilter(long nativeFilter, int mul, int add);
 }
diff --git a/graphics/java/android/graphics/LinearGradient.java b/graphics/java/android/graphics/LinearGradient.java
index 4c88de3..9ad3e49 100644
--- a/graphics/java/android/graphics/LinearGradient.java
+++ b/graphics/java/android/graphics/LinearGradient.java
@@ -116,12 +116,12 @@
         return copy;
     }
 
-    private native int nativeCreate1(float x0, float y0, float x1, float y1,
+    private native long nativeCreate1(float x0, float y0, float x1, float y1,
             int colors[], float positions[], int tileMode);
-	private native int nativeCreate2(float x0, float y0, float x1, float y1,
+	private native long nativeCreate2(float x0, float y0, float x1, float y1,
             int color0, int color1, int tileMode);
-    private native int nativePostCreate1(int native_shader, float x0, float y0, float x1, float y1,
+    private native long nativePostCreate1(long native_shader, float x0, float y0, float x1, float y1,
             int colors[], float positions[], int tileMode);
-    private native int nativePostCreate2(int native_shader, float x0, float y0, float x1, float y1,
+    private native long nativePostCreate2(long native_shader, float x0, float y0, float x1, float y1,
             int color0, int color1, int tileMode);
 }
diff --git a/graphics/java/android/graphics/MaskFilter.java b/graphics/java/android/graphics/MaskFilter.java
index 4ebb619..27a7dda 100644
--- a/graphics/java/android/graphics/MaskFilter.java
+++ b/graphics/java/android/graphics/MaskFilter.java
@@ -27,6 +27,6 @@
         nativeDestructor(native_instance);
     }
 
-    private static native void nativeDestructor(int native_filter);
-    int native_instance;
+    private static native void nativeDestructor(long native_filter);
+    long native_instance;
 }
diff --git a/graphics/java/android/graphics/Matrix.java b/graphics/java/android/graphics/Matrix.java
index 32e0c01..c8bcf26 100644
--- a/graphics/java/android/graphics/Matrix.java
+++ b/graphics/java/android/graphics/Matrix.java
@@ -219,7 +219,7 @@
     /**
      * @hide
      */
-    public int native_instance;
+    public long native_instance;
 
     /**
      * Create an identity matrix
@@ -800,83 +800,86 @@
         }
     }
 
-    /*package*/ final int ni() {
+    /*package*/ final long ni() {
         return native_instance;
     }
 
-    private static native int native_create(int native_src_or_zero);
-    private static native boolean native_isIdentity(int native_object);
-    private static native boolean native_rectStaysRect(int native_object);
-    private static native void native_reset(int native_object);
-    private static native void native_set(int native_object, int other);
-    private static native void native_setTranslate(int native_object,
+    private static native long native_create(long native_src_or_zero);
+    private static native boolean native_isIdentity(long native_object);
+    private static native boolean native_rectStaysRect(long native_object);
+    private static native void native_reset(long native_object);
+    private static native void native_set(long native_object,
+                                          long native_other);
+    private static native void native_setTranslate(long native_object,
                                                    float dx, float dy);
-    private static native void native_setScale(int native_object,
+    private static native void native_setScale(long native_object,
                                         float sx, float sy, float px, float py);
-    private static native void native_setScale(int native_object,
+    private static native void native_setScale(long native_object,
                                                float sx, float sy);
-    private static native void native_setRotate(int native_object,
+    private static native void native_setRotate(long native_object,
                                             float degrees, float px, float py);
-    private static native void native_setRotate(int native_object,
+    private static native void native_setRotate(long native_object,
                                                 float degrees);
-    private static native void native_setSinCos(int native_object,
+    private static native void native_setSinCos(long native_object,
                             float sinValue, float cosValue, float px, float py);
-    private static native void native_setSinCos(int native_object,
+    private static native void native_setSinCos(long native_object,
                                                 float sinValue, float cosValue);
-    private static native void native_setSkew(int native_object,
+    private static native void native_setSkew(long native_object,
                                         float kx, float ky, float px, float py);
-    private static native void native_setSkew(int native_object,
+    private static native void native_setSkew(long native_object,
                                               float kx, float ky);
-    private static native boolean native_setConcat(int native_object,
-                                                   int a, int b);
-    private static native boolean native_preTranslate(int native_object,
+    private static native boolean native_setConcat(long native_object,
+                                                   long native_a,
+                                                   long native_b);
+    private static native boolean native_preTranslate(long native_object,
                                                       float dx, float dy);
-    private static native boolean native_preScale(int native_object,
+    private static native boolean native_preScale(long native_object,
                                         float sx, float sy, float px, float py);
-    private static native boolean native_preScale(int native_object,
+    private static native boolean native_preScale(long native_object,
                                                   float sx, float sy);
-    private static native boolean native_preRotate(int native_object,
+    private static native boolean native_preRotate(long native_object,
                                             float degrees, float px, float py);
-    private static native boolean native_preRotate(int native_object,
+    private static native boolean native_preRotate(long native_object,
                                                    float degrees);
-    private static native boolean native_preSkew(int native_object,
+    private static native boolean native_preSkew(long native_object,
                                         float kx, float ky, float px, float py);
-    private static native boolean native_preSkew(int native_object,
+    private static native boolean native_preSkew(long native_object,
                                                  float kx, float ky);
-    private static native boolean native_preConcat(int native_object,
-                                                   int other_matrix);
-    private static native boolean native_postTranslate(int native_object,
+    private static native boolean native_preConcat(long native_object,
+                                                   long native_other_matrix);
+    private static native boolean native_postTranslate(long native_object,
                                                        float dx, float dy);
-    private static native boolean native_postScale(int native_object,
+    private static native boolean native_postScale(long native_object,
                                         float sx, float sy, float px, float py);
-    private static native boolean native_postScale(int native_object,
+    private static native boolean native_postScale(long native_object,
                                                    float sx, float sy);
-    private static native boolean native_postRotate(int native_object,
+    private static native boolean native_postRotate(long native_object,
                                             float degrees, float px, float py);
-    private static native boolean native_postRotate(int native_object,
+    private static native boolean native_postRotate(long native_object,
                                                     float degrees);
-    private static native boolean native_postSkew(int native_object,
+    private static native boolean native_postSkew(long native_object,
                                         float kx, float ky, float px, float py);
-    private static native boolean native_postSkew(int native_object,
+    private static native boolean native_postSkew(long native_object,
                                                   float kx, float ky);
-    private static native boolean native_postConcat(int native_object,
-                                                    int other_matrix);
-    private static native boolean native_setRectToRect(int native_object,
+    private static native boolean native_postConcat(long native_object,
+                                                    long native_other_matrix);
+    private static native boolean native_setRectToRect(long native_object,
                                                 RectF src, RectF dst, int stf);
-    private static native boolean native_setPolyToPoly(int native_object,
+    private static native boolean native_setPolyToPoly(long native_object,
         float[] src, int srcIndex, float[] dst, int dstIndex, int pointCount);
-    private static native boolean native_invert(int native_object, int inverse);
-    private static native void native_mapPoints(int native_object,
+    private static native boolean native_invert(long native_object,
+                                                long native_inverse);
+    private static native void native_mapPoints(long native_object,
                         float[] dst, int dstIndex, float[] src, int srcIndex,
                         int ptCount, boolean isPts);
-    private static native boolean native_mapRect(int native_object,
+    private static native boolean native_mapRect(long native_object,
                                                  RectF dst, RectF src);
-    private static native float native_mapRadius(int native_object,
+    private static native float native_mapRadius(long native_object,
                                                  float radius);
-    private static native void native_getValues(int native_object,
+    private static native void native_getValues(long native_object,
                                                 float[] values);
-    private static native void native_setValues(int native_object,
+    private static native void native_setValues(long native_object,
                                                 float[] values);
-    private static native boolean native_equals(int native_a, int native_b);
-    private static native void finalizer(int native_instance);
+    private static native boolean native_equals(long native_a, long native_b);
+    private static native void finalizer(long native_instance);
 }
diff --git a/graphics/java/android/graphics/Movie.java b/graphics/java/android/graphics/Movie.java
index 9419faf..b0a4553 100644
--- a/graphics/java/android/graphics/Movie.java
+++ b/graphics/java/android/graphics/Movie.java
@@ -21,9 +21,9 @@
 import java.io.FileInputStream;
 
 public class Movie {
-    private final int mNativeMovie;
+    private final long mNativeMovie;
 
-    private Movie(int nativeMovie) {
+    private Movie(long nativeMovie) {
         if (nativeMovie == 0) {
             throw new RuntimeException("native movie creation failed");
         }
@@ -48,19 +48,19 @@
             return null;
         }
         if (is instanceof AssetManager.AssetInputStream) {
-            final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
+            final long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
             return nativeDecodeAsset(asset);
         }
 
         return nativeDecodeStream(is);
     }
 
-    private static native Movie nativeDecodeAsset(int asset);
+    private static native Movie nativeDecodeAsset(long asset);
     private static native Movie nativeDecodeStream(InputStream is);
     public static native Movie decodeByteArray(byte[] data, int offset,
                                                int length);
 
-    private static native void nativeDestructor(int nativeMovie);
+    private static native void nativeDestructor(long nativeMovie);
 
     public static Movie decodeFile(String pathName) {
         InputStream is;
diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java
index 528d9de..69089b1 100644
--- a/graphics/java/android/graphics/NinePatch.java
+++ b/graphics/java/android/graphics/NinePatch.java
@@ -39,7 +39,7 @@
      *
      * @hide
      */
-    public final int mNativeChunk;
+    public final long mNativeChunk;
 
     private Paint mPaint;
     private String mSrcName;
@@ -217,7 +217,7 @@
      * that are transparent.
      */
     public final Region getTransparentRegion(Rect bounds) {
-        int r = nativeGetTransparentRegion(mBitmap.ni(), mNativeChunk, bounds);
+        long r = nativeGetTransparentRegion(mBitmap.ni(), mNativeChunk, bounds);
         return r != 0 ? new Region(r) : null;
     }
 
@@ -236,11 +236,11 @@
      * If validation is successful, this method returns a native Res_png_9patch*
      * object used by the renderers.
      */
-    private static native int validateNinePatchChunk(int bitmap, byte[] chunk);
-    private static native void nativeFinalize(int chunk);
-    private static native void nativeDraw(int canvas_instance, RectF loc, int bitmap_instance,
-            int c, int paint_instance_or_null, int destDensity, int srcDensity);
-    private static native void nativeDraw(int canvas_instance, Rect loc, int bitmap_instance,
-            int c, int paint_instance_or_null, int destDensity, int srcDensity);
-    private static native int nativeGetTransparentRegion(int bitmap, int chunk, Rect location);
+    private static native long validateNinePatchChunk(long bitmap, byte[] chunk);
+    private static native void nativeFinalize(long chunk);
+    private static native void nativeDraw(long canvas_instance, RectF loc, long bitmap_instance,
+            long c, long paint_instance_or_null, int destDensity, int srcDensity);
+    private static native void nativeDraw(long canvas_instance, Rect loc, long bitmap_instance,
+            long c, long paint_instance_or_null, int destDensity, int srcDensity);
+    private static native long nativeGetTransparentRegion(long bitmap, long chunk, Rect location);
 }
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 5fc2588..33832a7 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -32,7 +32,7 @@
     /**
      * @hide
      */
-    public int mNativePaint;
+    public long mNativePaint;
 
     private ColorFilter mColorFilter;
     private MaskFilter  mMaskFilter;
@@ -943,7 +943,7 @@
      * @return       shader
      */
     public Shader setShader(Shader shader) {
-        int shaderNative = 0;
+        long shaderNative = 0;
         if (shader != null)
             shaderNative = shader.native_instance;
         native_setShader(mNativePaint, shaderNative);
@@ -967,7 +967,7 @@
      * @return       filter
      */
     public ColorFilter setColorFilter(ColorFilter filter) {
-        int filterNative = 0;
+        long filterNative = 0;
         if (filter != null)
             filterNative = filter.native_instance;
         native_setColorFilter(mNativePaint, filterNative);
@@ -994,7 +994,7 @@
      * @return         xfermode
      */
     public Xfermode setXfermode(Xfermode xfermode) {
-        int xfermodeNative = 0;
+        long xfermodeNative = 0;
         if (xfermode != null)
             xfermodeNative = xfermode.native_instance;
         native_setXfermode(mNativePaint, xfermodeNative);
@@ -1021,7 +1021,7 @@
      * @return       effect
      */
     public PathEffect setPathEffect(PathEffect effect) {
-        int effectNative = 0;
+        long effectNative = 0;
         if (effect != null) {
             effectNative = effect.native_instance;
         }
@@ -1050,7 +1050,7 @@
      * @return           maskfilter
      */
     public MaskFilter setMaskFilter(MaskFilter maskfilter) {
-        int maskfilterNative = 0;
+        long maskfilterNative = 0;
         if (maskfilter != null) {
             maskfilterNative = maskfilter.native_instance;
         }
@@ -1081,7 +1081,7 @@
      * @return         typeface
      */
     public Typeface setTypeface(Typeface typeface) {
-        int typefaceNative = 0;
+        long typefaceNative = 0;
         if (typeface != null) {
             typefaceNative = typeface.native_instance;
         }
@@ -1112,7 +1112,7 @@
      * @return           rasterizer
      */
     public Rasterizer setRasterizer(Rasterizer rasterizer) {
-        int rasterizerNative = 0;
+        long rasterizerNative = 0;
         if (rasterizer != null) {
             rasterizerNative = rasterizer.native_instance;
         }
@@ -2207,68 +2207,68 @@
         }
     }
 
-    private static native int native_init();
-    private static native int native_initWithPaint(int paint);
-    private static native void native_reset(int native_object);
-    private static native void native_set(int native_dst, int native_src);
-    private static native int native_getStyle(int native_object);
-    private static native void native_setStyle(int native_object, int style);
-    private static native int native_getStrokeCap(int native_object);
-    private static native void native_setStrokeCap(int native_object, int cap);
-    private static native int native_getStrokeJoin(int native_object);
-    private static native void native_setStrokeJoin(int native_object,
+    private static native long native_init();
+    private static native long native_initWithPaint(long paint);
+    private static native void native_reset(long native_object);
+    private static native void native_set(long native_dst, long native_src);
+    private static native int native_getStyle(long native_object);
+    private static native void native_setStyle(long native_object, int style);
+    private static native int native_getStrokeCap(long native_object);
+    private static native void native_setStrokeCap(long native_object, int cap);
+    private static native int native_getStrokeJoin(long native_object);
+    private static native void native_setStrokeJoin(long native_object,
                                                     int join);
-    private static native boolean native_getFillPath(int native_object,
-                                                     int src, int dst);
-    private static native int native_setShader(int native_object, int shader);
-    private static native int native_setColorFilter(int native_object,
-                                                    int filter);
-    private static native int native_setXfermode(int native_object,
-                                                 int xfermode);
-    private static native int native_setPathEffect(int native_object,
-                                                   int effect);
-    private static native int native_setMaskFilter(int native_object,
-                                                   int maskfilter);
-    private static native int native_setTypeface(int native_object,
-                                                 int typeface);
-    private static native int native_setRasterizer(int native_object,
-                                                   int rasterizer);
+    private static native boolean native_getFillPath(long native_object,
+                                                     long src, long dst);
+    private static native long native_setShader(long native_object, long shader);
+    private static native long native_setColorFilter(long native_object,
+                                                    long filter);
+    private static native long native_setXfermode(long native_object,
+                                                  long xfermode);
+    private static native long native_setPathEffect(long native_object,
+                                                    long effect);
+    private static native long native_setMaskFilter(long native_object,
+                                                    long maskfilter);
+    private static native long native_setTypeface(long native_object,
+                                                  long typeface);
+    private static native long native_setRasterizer(long native_object,
+                                                   long rasterizer);
 
-    private static native int native_getTextAlign(int native_object);
-    private static native void native_setTextAlign(int native_object,
+    private static native int native_getTextAlign(long native_object);
+    private static native void native_setTextAlign(long native_object,
                                                    int align);
 
-    private static native void native_setTextLocale(int native_object,
+    private static native void native_setTextLocale(long native_object,
                                                     String locale);
 
-    private static native int native_getTextWidths(int native_object,
+    private static native int native_getTextWidths(long native_object,
                             char[] text, int index, int count, int bidiFlags, float[] widths);
-    private static native int native_getTextWidths(int native_object,
+    private static native int native_getTextWidths(long native_object,
                             String text, int start, int end, int bidiFlags, float[] widths);
 
-    private static native int native_getTextGlyphs(int native_object,
+    private static native int native_getTextGlyphs(long native_object,
             String text, int start, int end, int contextStart, int contextEnd,
             int flags, char[] glyphs);
 
-    private static native float native_getTextRunAdvances(int native_object,
+    private static native float native_getTextRunAdvances(long native_object,
             char[] text, int index, int count, int contextIndex, int contextCount,
             int flags, float[] advances, int advancesIndex);
-    private static native float native_getTextRunAdvances(int native_object,
+    private static native float native_getTextRunAdvances(long native_object,
             String text, int start, int end, int contextStart, int contextEnd,
             int flags, float[] advances, int advancesIndex);
 
-    private native int native_getTextRunCursor(int native_object, char[] text,
+    private native int native_getTextRunCursor(long native_object, char[] text,
             int contextStart, int contextLength, int flags, int offset, int cursorOpt);
-    private native int native_getTextRunCursor(int native_object, String text,
+    private native int native_getTextRunCursor(long native_object, String text,
             int contextStart, int contextEnd, int flags, int offset, int cursorOpt);
 
-    private static native void native_getTextPath(int native_object, int bidiFlags,
-                char[] text, int index, int count, float x, float y, int path);
-    private static native void native_getTextPath(int native_object, int bidiFlags,
-                String text, int start, int end, float x, float y, int path);
-    private static native void nativeGetStringBounds(int nativePaint,
+    private static native void native_getTextPath(long native_object, int bidiFlags,
+                char[] text, int index, int count, float x, float y, long path);
+    private static native void native_getTextPath(long native_object, int bidiFlags,
+                String text, int start, int end, float x, float y, long path);
+    private static native void nativeGetStringBounds(long nativePaint,
                                 String text, int start, int end, int bidiFlags, Rect bounds);
-    private static native void nativeGetCharArrayBounds(int nativePaint,
+    private static native void nativeGetCharArrayBounds(long nativePaint,
                                 char[] text, int index, int count, int bidiFlags, Rect bounds);
-    private static native void finalizer(int nativePaint);
+    private static native void finalizer(long nativePaint);
 }
diff --git a/graphics/java/android/graphics/PaintFlagsDrawFilter.java b/graphics/java/android/graphics/PaintFlagsDrawFilter.java
index c833a12..65a6218 100644
--- a/graphics/java/android/graphics/PaintFlagsDrawFilter.java
+++ b/graphics/java/android/graphics/PaintFlagsDrawFilter.java
@@ -38,6 +38,6 @@
         mNativeInt = nativeConstructor(clearBits, setBits);
     }
     
-    private static native int nativeConstructor(int clearBits, int setBits);
+    private static native long nativeConstructor(int clearBits, int setBits);
 }
 
diff --git a/graphics/java/android/graphics/Path.java b/graphics/java/android/graphics/Path.java
index 5b04a91..b5a1f64 100644
--- a/graphics/java/android/graphics/Path.java
+++ b/graphics/java/android/graphics/Path.java
@@ -29,7 +29,7 @@
     /**
      * @hide
      */
-    public final int mNativePath;
+    public final long mNativePath;
 
     /**
      * @hide
@@ -56,7 +56,7 @@
      * @param src The path to copy from when initializing the new path
      */
     public Path(Path src) {
-        int valNative = 0;
+        long valNative = 0;
         if (src != null) {
             valNative = src.mNativePath;
             isSimplePath = src.isSimplePath;
@@ -634,7 +634,7 @@
      *            the original path is modified.
      */
     public void offset(float dx, float dy, Path dst) {
-        int dstNative = 0;
+        long dstNative = 0;
         if (dst != null) {
             dstNative = dst.mNativePath;
             dst.isSimplePath = false;
@@ -673,7 +673,7 @@
      *               then the the original path is modified
      */
     public void transform(Matrix matrix, Path dst) {
-        int dstNative = 0;
+        long dstNative = 0;
         if (dst != null) {
             dst.isSimplePath = false;
             dstNative = dst.mNativePath;
@@ -699,54 +699,54 @@
         }
     }
 
-    final int ni() {
+    final long ni() {
         return mNativePath;
     }
 
-    private static native int init1();
-    private static native int init2(int nPath);
-    private static native void native_reset(int nPath);
-    private static native void native_rewind(int nPath);
-    private static native void native_set(int native_dst, int native_src);
-    private static native int native_getFillType(int nPath);
-    private static native void native_setFillType(int nPath, int ft);
-    private static native boolean native_isEmpty(int nPath);
-    private static native boolean native_isRect(int nPath, RectF rect);
-    private static native void native_computeBounds(int nPath, RectF bounds);
-    private static native void native_incReserve(int nPath, int extraPtCount);
-    private static native void native_moveTo(int nPath, float x, float y);
-    private static native void native_rMoveTo(int nPath, float dx, float dy);
-    private static native void native_lineTo(int nPath, float x, float y);
-    private static native void native_rLineTo(int nPath, float dx, float dy);
-    private static native void native_quadTo(int nPath, float x1, float y1,
+    private static native long init1();
+    private static native long init2(long nPath);
+    private static native void native_reset(long nPath);
+    private static native void native_rewind(long nPath);
+    private static native void native_set(long native_dst, long native_src);
+    private static native int native_getFillType(long nPath);
+    private static native void native_setFillType(long nPath, int ft);
+    private static native boolean native_isEmpty(long nPath);
+    private static native boolean native_isRect(long nPath, RectF rect);
+    private static native void native_computeBounds(long nPath, RectF bounds);
+    private static native void native_incReserve(long nPath, int extraPtCount);
+    private static native void native_moveTo(long nPath, float x, float y);
+    private static native void native_rMoveTo(long nPath, float dx, float dy);
+    private static native void native_lineTo(long nPath, float x, float y);
+    private static native void native_rLineTo(long nPath, float dx, float dy);
+    private static native void native_quadTo(long nPath, float x1, float y1,
                                              float x2, float y2);
-    private static native void native_rQuadTo(int nPath, float dx1, float dy1,
+    private static native void native_rQuadTo(long nPath, float dx1, float dy1,
                                               float dx2, float dy2);
-    private static native void native_cubicTo(int nPath, float x1, float y1,
+    private static native void native_cubicTo(long nPath, float x1, float y1,
                                         float x2, float y2, float x3, float y3);
-    private static native void native_rCubicTo(int nPath, float x1, float y1,
+    private static native void native_rCubicTo(long nPath, float x1, float y1,
                                         float x2, float y2, float x3, float y3);
-    private static native void native_arcTo(int nPath, RectF oval,
+    private static native void native_arcTo(long nPath, RectF oval,
                     float startAngle, float sweepAngle, boolean forceMoveTo);
-    private static native void native_close(int nPath);
-    private static native void native_addRect(int nPath, RectF rect, int dir);
-    private static native void native_addRect(int nPath, float left, float top,
+    private static native void native_close(long nPath);
+    private static native void native_addRect(long nPath, RectF rect, int dir);
+    private static native void native_addRect(long nPath, float left, float top,
                                             float right, float bottom, int dir);
-    private static native void native_addOval(int nPath, RectF oval, int dir);
-    private static native void native_addCircle(int nPath, float x, float y, float radius, int dir);
-    private static native void native_addArc(int nPath, RectF oval,
+    private static native void native_addOval(long nPath, RectF oval, int dir);
+    private static native void native_addCircle(long nPath, float x, float y, float radius, int dir);
+    private static native void native_addArc(long nPath, RectF oval,
                                             float startAngle, float sweepAngle);
-    private static native void native_addRoundRect(int nPath, RectF rect,
+    private static native void native_addRoundRect(long nPath, RectF rect,
                                                    float rx, float ry, int dir);
-    private static native void native_addRoundRect(int nPath, RectF r, float[] radii, int dir);
-    private static native void native_addPath(int nPath, int src, float dx, float dy);
-    private static native void native_addPath(int nPath, int src);
-    private static native void native_addPath(int nPath, int src, int matrix);
-    private static native void native_offset(int nPath, float dx, float dy, int dst_path);
-    private static native void native_offset(int nPath, float dx, float dy);
-    private static native void native_setLastPoint(int nPath, float dx, float dy);
-    private static native void native_transform(int nPath, int matrix, int dst_path);
-    private static native void native_transform(int nPath, int matrix);
-    private static native boolean native_op(int path1, int path2, int op, int result);
-    private static native void finalizer(int nPath);
+    private static native void native_addRoundRect(long nPath, RectF r, float[] radii, int dir);
+    private static native void native_addPath(long nPath, long src, float dx, float dy);
+    private static native void native_addPath(long nPath, long src);
+    private static native void native_addPath(long nPath, long src, long matrix);
+    private static native void native_offset(long nPath, float dx, float dy, long dst_path);
+    private static native void native_offset(long nPath, float dx, float dy);
+    private static native void native_setLastPoint(long nPath, float dx, float dy);
+    private static native void native_transform(long nPath, long matrix, long dst_path);
+    private static native void native_transform(long nPath, long matrix);
+    private static native boolean native_op(long path1, long path2, int op, long result);
+    private static native void finalizer(long nPath);
 }
diff --git a/graphics/java/android/graphics/PathDashPathEffect.java b/graphics/java/android/graphics/PathDashPathEffect.java
index e8ad5fd8..4f43f68 100644
--- a/graphics/java/android/graphics/PathDashPathEffect.java
+++ b/graphics/java/android/graphics/PathDashPathEffect.java
@@ -45,7 +45,7 @@
                                        style.native_style);
     }
     
-    private static native int nativeCreate(int native_path, float advance,
+    private static native long nativeCreate(long native_path, float advance,
                                            float phase, int native_style);
 }
 
diff --git a/graphics/java/android/graphics/PathEffect.java b/graphics/java/android/graphics/PathEffect.java
index 9b2cd66..617dfca 100644
--- a/graphics/java/android/graphics/PathEffect.java
+++ b/graphics/java/android/graphics/PathEffect.java
@@ -27,6 +27,6 @@
         nativeDestructor(native_instance);
     }
 
-    private static native void nativeDestructor(int native_patheffect);
-    int native_instance;
+    private static native void nativeDestructor(long native_patheffect);
+    long native_instance;
 }
diff --git a/graphics/java/android/graphics/PathMeasure.java b/graphics/java/android/graphics/PathMeasure.java
index 7062824..e56716f 100644
--- a/graphics/java/android/graphics/PathMeasure.java
+++ b/graphics/java/android/graphics/PathMeasure.java
@@ -138,16 +138,16 @@
         native_destroy(native_instance);
     }
 
-    private static native int native_create(int native_path, boolean forceClosed);
-    private static native void native_setPath(int native_instance, int native_path, boolean forceClosed);
-    private static native float native_getLength(int native_instance);
-    private static native boolean native_getPosTan(int native_instance, float distance, float pos[], float tan[]);
-    private static native boolean native_getMatrix(int native_instance, float distance, int native_matrix, int flags);
-    private static native boolean native_getSegment(int native_instance, float startD, float stopD, int native_path, boolean startWithMoveTo);
-    private static native boolean native_isClosed(int native_instance);
-    private static native boolean native_nextContour(int native_instance);
-    private static native void native_destroy(int native_instance);
+    private static native long native_create(long native_path, boolean forceClosed);
+    private static native void native_setPath(long native_instance, long native_path, boolean forceClosed);
+    private static native float native_getLength(long native_instance);
+    private static native boolean native_getPosTan(long native_instance, float distance, float pos[], float tan[]);
+    private static native boolean native_getMatrix(long native_instance, float distance, long native_matrix, int flags);
+    private static native boolean native_getSegment(long native_instance, float startD, float stopD, long native_path, boolean startWithMoveTo);
+    private static native boolean native_isClosed(long native_instance);
+    private static native boolean native_nextContour(long native_instance);
+    private static native void native_destroy(long native_instance);
 
-    /* package */private final int native_instance;
+    /* package */private final long native_instance;
 }
 
diff --git a/graphics/java/android/graphics/Picture.java b/graphics/java/android/graphics/Picture.java
index 71e02f6..25188e0 100644
--- a/graphics/java/android/graphics/Picture.java
+++ b/graphics/java/android/graphics/Picture.java
@@ -29,7 +29,7 @@
  */
 public class Picture {
     private Canvas mRecordingCanvas;
-    private final int mNativePicture;
+    private final long mNativePicture;
 
     /**
      * @hide
@@ -63,7 +63,7 @@
      * into it.
      */
     public Canvas beginRecording(int width, int height) {
-        int ni = nativeBeginRecording(mNativePicture, width, height);
+        long ni = nativeBeginRecording(mNativePicture, width, height);
         mRecordingCanvas = new RecordingCanvas(this, ni);
         return mRecordingCanvas;
     }
@@ -164,11 +164,11 @@
         }
     }
 
-    final int ni() {
+    final long ni() {
         return mNativePicture;
     }
     
-    private Picture(int nativePicture, boolean fromStream) {
+    private Picture(long nativePicture, boolean fromStream) {
         if (nativePicture == 0) {
             throw new RuntimeException();
         }
@@ -177,21 +177,21 @@
     }
 
     // return empty picture if src is 0, or a copy of the native src
-    private static native int nativeConstructor(int nativeSrcOr0);
-    private static native int nativeCreateFromStream(InputStream stream,
+    private static native long nativeConstructor(long nativeSrcOr0);
+    private static native long nativeCreateFromStream(InputStream stream,
                                                 byte[] storage);
-    private static native int nativeBeginRecording(int nativeCanvas,
+    private static native long nativeBeginRecording(long nativeCanvas,
                                                     int w, int h);
-    private static native void nativeEndRecording(int nativeCanvas);
-    private static native void nativeDraw(int nativeCanvas, int nativePicture);
-    private static native boolean nativeWriteToStream(int nativePicture,
+    private static native void nativeEndRecording(long nativeCanvas);
+    private static native void nativeDraw(long nativeCanvas, long nativePicture);
+    private static native boolean nativeWriteToStream(long nativePicture,
                                            OutputStream stream, byte[] storage);
-    private static native void nativeDestructor(int nativePicture);
+    private static native void nativeDestructor(long nativePicture);
     
     private static class RecordingCanvas extends Canvas {
         private final Picture mPicture;
 
-        public RecordingCanvas(Picture pict, int nativeCanvas) {
+        public RecordingCanvas(Picture pict, long nativeCanvas) {
             super(nativeCanvas);
             mPicture = pict;
         }
diff --git a/graphics/java/android/graphics/PixelXorXfermode.java b/graphics/java/android/graphics/PixelXorXfermode.java
index 6075ec3..0080e65 100644
--- a/graphics/java/android/graphics/PixelXorXfermode.java
+++ b/graphics/java/android/graphics/PixelXorXfermode.java
@@ -29,5 +29,5 @@
         native_instance = nativeCreate(opColor);
     }
 
-    private static native int nativeCreate(int opColor);
+    private static native long nativeCreate(int opColor);
 }
diff --git a/graphics/java/android/graphics/PorterDuffColorFilter.java b/graphics/java/android/graphics/PorterDuffColorFilter.java
index ecc7c24..894284f 100644
--- a/graphics/java/android/graphics/PorterDuffColorFilter.java
+++ b/graphics/java/android/graphics/PorterDuffColorFilter.java
@@ -29,7 +29,7 @@
         nativeColorFilter = nCreatePorterDuffFilter(native_instance, srcColor, mode.nativeInt);
     }
 
-    private static native int native_CreatePorterDuffFilter(int srcColor, int porterDuffMode);
-    private static native int nCreatePorterDuffFilter(int nativeFilter, int srcColor,
+    private static native long native_CreatePorterDuffFilter(int srcColor, int porterDuffMode);
+    private static native long nCreatePorterDuffFilter(long nativeFilter, int srcColor,
             int porterDuffMode);
 }
diff --git a/graphics/java/android/graphics/PorterDuffXfermode.java b/graphics/java/android/graphics/PorterDuffXfermode.java
index 6ba064c..d9d7689 100644
--- a/graphics/java/android/graphics/PorterDuffXfermode.java
+++ b/graphics/java/android/graphics/PorterDuffXfermode.java
@@ -32,5 +32,5 @@
         native_instance = nativeCreateXfermode(mode.nativeInt);
     }
     
-    private static native int nativeCreateXfermode(int mode);
+    private static native long nativeCreateXfermode(int mode);
 }
diff --git a/graphics/java/android/graphics/RadialGradient.java b/graphics/java/android/graphics/RadialGradient.java
index f011e5c..f10e5d6 100644
--- a/graphics/java/android/graphics/RadialGradient.java
+++ b/graphics/java/android/graphics/RadialGradient.java
@@ -117,14 +117,14 @@
         return copy;
     }
 
-    private static native int nativeCreate1(float x, float y, float radius,
+    private static native long nativeCreate1(float x, float y, float radius,
             int colors[], float positions[], int tileMode);
-	private static native int nativeCreate2(float x, float y, float radius,
+	private static native long nativeCreate2(float x, float y, float radius,
             int color0, int color1, int tileMode);
 
-    private static native int nativePostCreate1(int native_shader, float x, float y, float radius,
+    private static native long nativePostCreate1(long native_shader, float x, float y, float radius,
             int colors[], float positions[], int tileMode);
-    private static native int nativePostCreate2(int native_shader, float x, float y, float radius,
+    private static native long nativePostCreate2(long native_shader, float x, float y, float radius,
             int color0, int color1, int tileMode);
 }
 
diff --git a/graphics/java/android/graphics/Rasterizer.java b/graphics/java/android/graphics/Rasterizer.java
index feb5f0c..817814c 100644
--- a/graphics/java/android/graphics/Rasterizer.java
+++ b/graphics/java/android/graphics/Rasterizer.java
@@ -27,7 +27,7 @@
         finalizer(native_instance);
     }
 
-    private static native void finalizer(int native_instance);
+    private static native void finalizer(long native_instance);
 
-    int native_instance;
+    long native_instance;
 }
diff --git a/graphics/java/android/graphics/Region.java b/graphics/java/android/graphics/Region.java
index 72d0c43..727723d 100644
--- a/graphics/java/android/graphics/Region.java
+++ b/graphics/java/android/graphics/Region.java
@@ -30,7 +30,7 @@
     /**
      * @hide
      */
-    public final int mNativeRegion;
+    public final long mNativeRegion;
 
     // the native values for these must match up with the enum in SkRegion.h
     public enum Op {
@@ -342,7 +342,7 @@
              * @return a new region created from the data in the parcel
              */
             public Region createFromParcel(Parcel p) {
-                int ni = nativeCreateFromParcel(p);
+                long ni = nativeCreateFromParcel(p);
                 if (ni == 0) {
                     throw new RuntimeException();
                 }
@@ -385,7 +385,7 @@
         }
     }
     
-    Region(int ni) {
+    Region(long ni) {
         if (ni == 0) {
             throw new RuntimeException();
         }
@@ -394,38 +394,38 @@
 
     /* add dummy parameter so constructor can be called from jni without
        triggering 'not cloneable' exception */
-    private Region(int ni, int dummy) {
+    private Region(long ni, int dummy) {
         this(ni);
     }
 
-    final int ni() {
+    final long ni() {
         return mNativeRegion;
     }
 
-    private static native boolean nativeEquals(int native_r1, int native_r2);
+    private static native boolean nativeEquals(long native_r1, long native_r2);
 
-    private static native int nativeConstructor();
-    private static native void nativeDestructor(int native_region);
+    private static native long nativeConstructor();
+    private static native void nativeDestructor(long native_region);
 
-    private static native void nativeSetRegion(int native_dst, int native_src);
-    private static native boolean nativeSetRect(int native_dst, int left,
+    private static native void nativeSetRegion(long native_dst, long native_src);
+    private static native boolean nativeSetRect(long native_dst, int left,
                                                 int top, int right, int bottom);
-    private static native boolean nativeSetPath(int native_dst, int native_path,
-                                                int native_clip);
-    private static native boolean nativeGetBounds(int native_region, Rect rect);
-    private static native boolean nativeGetBoundaryPath(int native_region,
-                                                        int native_path);
+    private static native boolean nativeSetPath(long native_dst, long native_path,
+                                                long native_clip);
+    private static native boolean nativeGetBounds(long native_region, Rect rect);
+    private static native boolean nativeGetBoundaryPath(long native_region,
+                                                        long native_path);
 
-    private static native boolean nativeOp(int native_dst, int left, int top,
+    private static native boolean nativeOp(long native_dst, int left, int top,
                                            int right, int bottom, int op);
-    private static native boolean nativeOp(int native_dst, Rect rect,
-                                           int native_region, int op);
-    private static native boolean nativeOp(int native_dst, int native_region1,
-                                           int native_region2, int op);
+    private static native boolean nativeOp(long native_dst, Rect rect,
+                                           long native_region, int op);
+    private static native boolean nativeOp(long native_dst, long native_region1,
+                                           long native_region2, int op);
 
-    private static native int nativeCreateFromParcel(Parcel p);
-    private static native boolean nativeWriteToParcel(int native_region,
+    private static native long nativeCreateFromParcel(Parcel p);
+    private static native boolean nativeWriteToParcel(long native_region,
                                                       Parcel p);
 
-    private static native String nativeToString(int native_region);
+    private static native String nativeToString(long native_region);
 }
diff --git a/graphics/java/android/graphics/RegionIterator.java b/graphics/java/android/graphics/RegionIterator.java
index 817f853..8401adb 100644
--- a/graphics/java/android/graphics/RegionIterator.java
+++ b/graphics/java/android/graphics/RegionIterator.java
@@ -45,10 +45,10 @@
         nativeDestructor(mNativeIter);
     }
     
-    private static native int nativeConstructor(int native_region);
-    private static native void nativeDestructor(int native_iter);
-    private static native boolean nativeNext(int native_iter, Rect r);
-    
-    private final int mNativeIter;
+    private static native long nativeConstructor(long native_region);
+    private static native void nativeDestructor(long native_iter);
+    private static native boolean nativeNext(long native_iter, Rect r);
+
+    private final long mNativeIter;
 }
 
diff --git a/graphics/java/android/graphics/Shader.java b/graphics/java/android/graphics/Shader.java
index afc68d8..94b4c4a 100644
--- a/graphics/java/android/graphics/Shader.java
+++ b/graphics/java/android/graphics/Shader.java
@@ -28,11 +28,11 @@
      * 
      * @hide 
      */
-    public int native_instance;
+    public long native_instance;
     /**
      * @hide
      */
-    public int native_shader;
+    public long native_shader;
 
     private Matrix mLocalMatrix;
 
@@ -112,7 +112,7 @@
         }
     }
 
-    private static native void nativeDestructor(int native_shader, int native_skiaShader);
-    private static native void nativeSetLocalMatrix(int native_shader,
-            int native_skiaShader, int matrix_instance);
+    private static native void nativeDestructor(long native_shader, long native_skiaShader);
+    private static native void nativeSetLocalMatrix(long native_shader,
+            long native_skiaShader, long matrix_instance);
 }
diff --git a/graphics/java/android/graphics/SumPathEffect.java b/graphics/java/android/graphics/SumPathEffect.java
index cc7c778..8fedc31 100644
--- a/graphics/java/android/graphics/SumPathEffect.java
+++ b/graphics/java/android/graphics/SumPathEffect.java
@@ -27,6 +27,6 @@
                                        second.native_instance);
     }
     
-    private static native int nativeCreate(int first, int second);
+    private static native long nativeCreate(long first, long second);
 }
 
diff --git a/graphics/java/android/graphics/SurfaceTexture.java b/graphics/java/android/graphics/SurfaceTexture.java
index b910a24..1f8e223 100644
--- a/graphics/java/android/graphics/SurfaceTexture.java
+++ b/graphics/java/android/graphics/SurfaceTexture.java
@@ -69,9 +69,9 @@
     /**
      * These fields are used by native code, do not access or modify.
      */
-    private int mSurfaceTexture;
-    private int mBufferQueue;
-    private int mFrameAvailableListener;
+    private long mSurfaceTexture;
+    private long mBufferQueue;
+    private long mFrameAvailableListener;
 
     /**
      * Callback interface for being notified that a new stream frame is available.
diff --git a/graphics/java/android/graphics/SweepGradient.java b/graphics/java/android/graphics/SweepGradient.java
index e9cda39..21239f7 100644
--- a/graphics/java/android/graphics/SweepGradient.java
+++ b/graphics/java/android/graphics/SweepGradient.java
@@ -106,12 +106,12 @@
         return copy;
     }
 
-    private static native int nativeCreate1(float x, float y, int colors[], float positions[]);
-    private static native int nativeCreate2(float x, float y, int color0, int color1);
+    private static native long nativeCreate1(float x, float y, int colors[], float positions[]);
+    private static native long nativeCreate2(float x, float y, int color0, int color1);
 
-    private static native int nativePostCreate1(int native_shader, float cx, float cy,
+    private static native long nativePostCreate1(long native_shader, float cx, float cy,
             int[] colors, float[] positions);    
-    private static native int nativePostCreate2(int native_shader, float cx, float cy,
+    private static native long nativePostCreate2(long native_shader, float cx, float cy,
             int color0, int color1);
 }
 
diff --git a/graphics/java/android/graphics/TableMaskFilter.java b/graphics/java/android/graphics/TableMaskFilter.java
index a8a7ff0..d0c1438 100644
--- a/graphics/java/android/graphics/TableMaskFilter.java
+++ b/graphics/java/android/graphics/TableMaskFilter.java
@@ -28,7 +28,7 @@
         native_instance = nativeNewTable(table);
     }
     
-    private TableMaskFilter(int ni) {
+    private TableMaskFilter(long ni) {
         native_instance = ni;
     }
     
@@ -40,7 +40,7 @@
         return new TableMaskFilter(nativeNewGamma(gamma));
     }
 
-    private static native int nativeNewTable(byte[] table);
-    private static native int nativeNewClip(int min, int max);
-    private static native int nativeNewGamma(float gamma);
+    private static native long nativeNewTable(byte[] table);
+    private static native long nativeNewClip(int min, int max);
+    private static native long nativeNewGamma(float gamma);
 }
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index c68c9f7..936ea4f 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -18,6 +18,7 @@
 
 import android.content.res.AssetManager;
 import android.util.SparseArray;
+import android.util.LongSparseArray;
 
 import java.io.File;
 
@@ -45,10 +46,10 @@
     public static final Typeface MONOSPACE;
 
     static Typeface[] sDefaults;
-    private static final SparseArray<SparseArray<Typeface>> sTypefaceCache =
-            new SparseArray<SparseArray<Typeface>>(3);
+    private static final LongSparseArray<SparseArray<Typeface>> sTypefaceCache =
+            new LongSparseArray<SparseArray<Typeface>>(3);
 
-    int native_instance;
+    long native_instance;
 
     // Style
     public static final int NORMAL = 0;
@@ -100,7 +101,7 @@
      * @return The best matching typeface.
      */
     public static Typeface create(Typeface family, int style) {
-        int ni = 0;        
+        long ni = 0;
         if (family != null) {
             // Return early if we're asked for the same face/style
             if (family.mStyle == style) {
@@ -170,7 +171,7 @@
     }
 
     // don't allow clients to call this directly
-    private Typeface(int ni) {
+    private Typeface(long ni) {
         if (ni == 0) {
             throw new RuntimeException("native typeface cannot be made");
         }
@@ -214,15 +215,20 @@
 
     @Override
     public int hashCode() {
-        int result = native_instance;
+        /*
+         * Modified method for hashCode with long native_instance derived from
+         * http://developer.android.com/reference/java/lang/Object.html
+         */
+        int result = 17;
+        result = 31 * result + (int) (native_instance ^ (native_instance >>> 32));
         result = 31 * result + mStyle;
         return result;
     }
 
-    private static native int  nativeCreate(String familyName, int style);
-    private static native int  nativeCreateFromTypeface(int native_instance, int style); 
-    private static native void nativeUnref(int native_instance);
-    private static native int  nativeGetStyle(int native_instance);
-    private static native int  nativeCreateFromAsset(AssetManager mgr, String path);
-    private static native int nativeCreateFromFile(String path);
+    private static native long nativeCreate(String familyName, int style);
+    private static native long nativeCreateFromTypeface(long native_instance, int style);
+    private static native void nativeUnref(long native_instance);
+    private static native int  nativeGetStyle(long native_instance);
+    private static native long nativeCreateFromAsset(AssetManager mgr, String path);
+    private static native long nativeCreateFromFile(String path);
 }
diff --git a/graphics/java/android/graphics/Xfermode.java b/graphics/java/android/graphics/Xfermode.java
index 2467bdc..883350d 100644
--- a/graphics/java/android/graphics/Xfermode.java
+++ b/graphics/java/android/graphics/Xfermode.java
@@ -38,7 +38,7 @@
         }
     }
 
-    private static native void finalizer(int native_instance);
+    private static native void finalizer(long native_instance);
 
-    int native_instance;
+    long native_instance;
 }
diff --git a/graphics/java/android/renderscript/Byte2.java b/graphics/java/android/renderscript/Byte2.java
index cf34f3a..f796de3 100644
--- a/graphics/java/android/renderscript/Byte2.java
+++ b/graphics/java/android/renderscript/Byte2.java
@@ -25,6 +25,9 @@
  *
  **/
 public class Byte2 {
+    public byte x;
+    public byte y;
+
     public Byte2() {
     }
 
@@ -33,8 +36,357 @@
         y = initY;
     }
 
-    public byte x;
-    public byte y;
+    /** @hide */
+    public Byte2(Byte2 source) {
+        this.x = source.x;
+        this.y = source.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Byte2 a) {
+        this.x += a.x;
+        this.y += a.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 add(Byte2 a, Byte2 b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x + b.x);
+        result.y = (byte)(a.y + b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(byte value) {
+        x += value;
+        y += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 add(Byte2 a, byte b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x + b);
+        result.y = (byte)(a.y + b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Byte2 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 sub(Byte2 a, Byte2 b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x - b.x);
+        result.y = (byte)(a.y - b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(byte value) {
+        x -= value;
+        y -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 sub(Byte2 a, byte b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x - b);
+        result.y = (byte)(a.y - b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Byte2 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 mul(Byte2 a, Byte2 b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x * b.x);
+        result.y = (byte)(a.y * b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(byte value) {
+        x *= value;
+        y *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 mul(Byte2 a, byte b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x * b);
+        result.y = (byte)(a.y * b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Byte2 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 div(Byte2 a, Byte2 b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x / b.x);
+        result.y = (byte)(a.y / b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(byte value) {
+        x /= value;
+        y /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte2 div(Byte2 a, byte b) {
+        Byte2 result = new Byte2();
+        result.x = (byte)(a.x / b);
+        result.y = (byte)(a.y / b);
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public byte length() {
+        return 2;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = (byte)(-x);
+        this.y = (byte)(-y);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public byte dotProduct(Byte2 a) {
+        return (byte)((x * a.x) + (y * a.y));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static byte dotProduct(Byte2 a, Byte2 b) {
+        return (byte)((b.x * a.x) + (b.y * a.y));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Byte2 a, byte factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+    }
+
+    /** @hide
+     * set vector value by Byte2
+     *
+     * @param a
+     */
+    public void set(Byte2 a) {
+        this.x = a.x;
+        this.y = a.y;
+    }
+
+    /** @hide
+     * set the vector field value by Char
+     *
+     * @param a
+     * @param b
+     */
+    public void setValues(byte a, byte b) {
+        this.x = a;
+        this.y = b;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public byte elementSum() {
+        return (byte)(x + y);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public byte get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, byte value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, byte value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to Char array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(byte[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+    }
+
 }
 
 
diff --git a/graphics/java/android/renderscript/Byte3.java b/graphics/java/android/renderscript/Byte3.java
index 266e94d..f2a95ac 100644
--- a/graphics/java/android/renderscript/Byte3.java
+++ b/graphics/java/android/renderscript/Byte3.java
@@ -25,6 +25,10 @@
  *
  **/
 public class Byte3 {
+    public byte x;
+    public byte y;
+    public byte z;
+
     public Byte3() {
     }
 
@@ -34,9 +38,387 @@
         z = initZ;
     }
 
-    public byte x;
-    public byte y;
-    public byte z;
+    /** @hide */
+    public Byte3(Byte3 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Byte3 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 add(Byte3 a, Byte3 b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x + b.x);
+        result.y = (byte)(a.y + b.y);
+        result.z = (byte)(a.z + b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(byte value) {
+        x += value;
+        y += value;
+        z += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 add(Byte3 a, byte b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x + b);
+        result.y = (byte)(a.y + b);
+        result.z = (byte)(a.z + b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Byte3 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 sub(Byte3 a, Byte3 b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x - b.x);
+        result.y = (byte)(a.y - b.y);
+        result.z = (byte)(a.z - b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(byte value) {
+        x -= value;
+        y -= value;
+        z -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 sub(Byte3 a, byte b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x - b);
+        result.y = (byte)(a.y - b);
+        result.z = (byte)(a.z - b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Byte3 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 mul(Byte3 a, Byte3 b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x * b.x);
+        result.y = (byte)(a.y * b.y);
+        result.z = (byte)(a.z * b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(byte value) {
+        x *= value;
+        y *= value;
+        z *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 mul(Byte3 a, byte b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x * b);
+        result.y = (byte)(a.y * b);
+        result.z = (byte)(a.z * b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Byte3 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 div(Byte3 a, Byte3 b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x / b.x);
+        result.y = (byte)(a.y / b.y);
+        result.z = (byte)(a.z / b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(byte value) {
+        x /= value;
+        y /= value;
+        z /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte3 div(Byte3 a, byte b) {
+        Byte3 result = new Byte3();
+        result.x = (byte)(a.x / b);
+        result.y = (byte)(a.y / b);
+        result.z = (byte)(a.z / b);
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public byte length() {
+        return 3;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = (byte)(-x);
+        this.y = (byte)(-y);
+        this.z = (byte)(-z);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public byte dotProduct(Byte3 a) {
+        return (byte)((byte)((byte)(x * a.x) + (byte)(y * a.y)) + (byte)(z * a.z));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static byte dotProduct(Byte3 a, Byte3 b) {
+        return (byte)((byte)((byte)(b.x * a.x) + (byte)(b.y * a.y)) + (byte)(b.z * a.z));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Byte3 a, byte factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+    }
+
+    /** @hide
+     * set vector value by Byte3
+     *
+     * @param a
+     */
+    public void set(Byte3 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+    }
+
+    /** @hide
+     * set the vector field value by Char
+     *
+     * @param a
+     * @param b
+     * @param c
+     */
+    public void setValues(byte a, byte b, byte c) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public byte elementSum() {
+        return (byte)(x + y + z);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public byte get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        case 2:
+            return z;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, byte value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, byte value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to Char array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(byte[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+        data[offset + 2] = z;
+    }
 }
 
 
diff --git a/graphics/java/android/renderscript/Byte4.java b/graphics/java/android/renderscript/Byte4.java
index 68c8f52..b8a8a6b 100644
--- a/graphics/java/android/renderscript/Byte4.java
+++ b/graphics/java/android/renderscript/Byte4.java
@@ -25,6 +25,11 @@
  *
  **/
 public class Byte4 {
+    public byte x;
+    public byte y;
+    public byte z;
+    public byte w;
+
     public Byte4() {
     }
 
@@ -34,11 +39,418 @@
         z = initZ;
         w = initW;
     }
+    /** @hide */
+    public Byte4(Byte4 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+        this.w = source.w;
+    }
 
-    public byte x;
-    public byte y;
-    public byte z;
-    public byte w;
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Byte4 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+        this.w += a.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 add(Byte4 a, Byte4 b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x + b.x);
+        result.y = (byte)(a.y + b.y);
+        result.z = (byte)(a.z + b.z);
+        result.w = (byte)(a.w + b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(byte value) {
+        x += value;
+        y += value;
+        z += value;
+        w += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 add(Byte4 a, byte b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x + b);
+        result.y = (byte)(a.y + b);
+        result.z = (byte)(a.z + b);
+        result.w = (byte)(a.w + b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Byte4 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+        this.w -= a.w;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 sub(Byte4 a, Byte4 b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x - b.x);
+        result.y = (byte)(a.y - b.y);
+        result.z = (byte)(a.z - b.z);
+        result.w = (byte)(a.w - b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(byte value) {
+        x -= value;
+        y -= value;
+        z -= value;
+        w -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 sub(Byte4 a, byte b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x - b);
+        result.y = (byte)(a.y - b);
+        result.z = (byte)(a.z - b);
+        result.w = (byte)(a.w - b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Byte4 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+        this.w *= a.w;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 mul(Byte4 a, Byte4 b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x * b.x);
+        result.y = (byte)(a.y * b.y);
+        result.z = (byte)(a.z * b.z);
+        result.w = (byte)(a.w * b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(byte value) {
+        x *= value;
+        y *= value;
+        z *= value;
+        w *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 mul(Byte4 a, byte b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x * b);
+        result.y = (byte)(a.y * b);
+        result.z = (byte)(a.z * b);
+        result.w = (byte)(a.w * b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Byte4 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+        this.w /= a.w;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 div(Byte4 a, Byte4 b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x / b.x);
+        result.y = (byte)(a.y / b.y);
+        result.z = (byte)(a.z / b.z);
+        result.w = (byte)(a.w / b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(byte value) {
+        x /= value;
+        y /= value;
+        z /= value;
+        w /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Byte4 div(Byte4 a, byte b) {
+        Byte4 result = new Byte4();
+        result.x = (byte)(a.x / b);
+        result.y = (byte)(a.y / b);
+        result.z = (byte)(a.z / b);
+        result.w = (byte)(a.w / b);
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public byte length() {
+        return 4;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = (byte)(-x);
+        this.y = (byte)(-y);
+        this.z = (byte)(-z);
+        this.w = (byte)(-w);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public byte dotProduct(Byte4 a) {
+        return (byte)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static byte dotProduct(Byte4 a, Byte4 b) {
+        return (byte)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Byte4 a, byte factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+        w += a.w * factor;
+    }
+
+    /** @hide
+     * set vector value by Byte4
+     *
+     * @param a
+     */
+    public void set(Byte4 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+        this.w = a.w;
+    }
+
+    /** @hide
+     * set the vector field values
+     *
+     * @param a
+     * @param b
+     * @param c
+     * @param d
+     */
+    public void setValues(byte a, byte b, byte c, byte d) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+        this.w = d;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public byte elementSum() {
+        return (byte)(x + y + z + w);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public byte get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        case 2:
+            return z;
+        case 3:
+            return w;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, byte value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        case 3:
+            w = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, byte value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        case 3:
+            w += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to Char array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(byte[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+        data[offset + 2] = z;
+        data[offset + 3] = w;
+    }
 }
 
 
diff --git a/graphics/java/android/renderscript/Double2.java b/graphics/java/android/renderscript/Double2.java
index 29fd515..4c7319d 100644
--- a/graphics/java/android/renderscript/Double2.java
+++ b/graphics/java/android/renderscript/Double2.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,28 +16,370 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript double2 type back
- * to the Android system.
- *
- **/
+ * Vector version of the basic double type.
+ * Provides two double fields packed.
+ */
 public class Double2 {
+    public double x;
+    public double y;
+
     public Double2() {
     }
 
-    public Double2(double initX, double initY) {
-        x = initX;
-        y = initY;
+    /** @hide */
+    public Double2(Double2 data) {
+        this.x = data.x;
+        this.y = data.y;
     }
 
-    public double x;
-    public double y;
+    public Double2(double x, double y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 add(Double2 a, Double2 b) {
+        Double2 res = new Double2();
+        res.x = a.x + b.x;
+        res.y = a.y + b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(Double2 value) {
+        x += value.x;
+        y += value.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(double value) {
+        x += value;
+        y += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 add(Double2 a, double b) {
+        Double2 res = new Double2();
+        res.x = a.x + b;
+        res.y = a.y + b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(Double2 value) {
+        x -= value.x;
+        y -= value.y;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 sub(Double2 a, Double2 b) {
+        Double2 res = new Double2();
+        res.x = a.x - b.x;
+        res.y = a.y - b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(double value) {
+        x -= value;
+        y -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 sub(Double2 a, double b) {
+        Double2 res = new Double2();
+        res.x = a.x - b;
+        res.y = a.y - b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(Double2 value) {
+        x *= value.x;
+        y *= value.y;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 mul(Double2 a, Double2 b) {
+        Double2 res = new Double2();
+        res.x = a.x * b.x;
+        res.y = a.y * b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(double value) {
+        x *= value;
+        y *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 mul(Double2 a, double b) {
+        Double2 res = new Double2();
+        res.x = a.x * b;
+        res.y = a.y * b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(Double2 value) {
+        x /= value.x;
+        y /= value.y;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 div(Double2 a, Double2 b) {
+        Double2 res = new Double2();
+        res.x = a.x / b.x;
+        res.y = a.y / b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(double value) {
+        x /= value;
+        y /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double2 div(Double2 a, double b) {
+        Double2 res = new Double2();
+        res.x = a.x / b;
+        res.y = a.y / b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public double dotProduct(Double2 a) {
+        return (x * a.x) + (y * a.y);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double dotProduct(Double2 a, Double2 b) {
+        return (b.x * a.x) + (b.y * a.y);
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Double2 a, double factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+    }
+
+    /** @hide
+     * Set vector value by double2
+     *
+     * @param a
+     */
+    public void set(Double2 a) {
+        this.x = a.x;
+        this.y = a.y;
+    }
+
+    /** @hide
+     * Set vector negate
+     */
+    public void negate() {
+        x = -x;
+        y = -y;
+    }
+
+    /** @hide
+     * Get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 2;
+    }
+
+    /** @hide
+     * Return the element sum of vector
+     *
+     * @return
+     */
+    public double elementSum() {
+        return x + y;
+    }
+
+    /** @hide
+     * Get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public double get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, double value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, double value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Set the vector field value
+     *
+     * @param x
+     * @param y
+     */
+    public void setValues(double x, double y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide
+     * Copy the vector to double array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(double[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Double3.java b/graphics/java/android/renderscript/Double3.java
index 818952e..b819716 100644
--- a/graphics/java/android/renderscript/Double3.java
+++ b/graphics/java/android/renderscript/Double3.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,30 +16,402 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript double3 type back
- * to the Android system.
- *
- **/
+ * Vector version of the basic double type.
+ * Provides three double fields packed.
+ */
 public class Double3 {
-    public Double3() {
-    }
-
-    public Double3(double initX, double initY, double initZ) {
-        x = initX;
-        y = initY;
-        z = initZ;
-    }
-
     public double x;
     public double y;
     public double z;
+
+    public Double3() {
+    }
+    /** @hide */
+    public Double3(Double3 data) {
+        this.x = data.x;
+        this.y = data.y;
+        this.z = data.z;
+    }
+
+    public Double3(double x, double y, double z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 add(Double3 a, Double3 b) {
+        Double3 res = new Double3();
+        res.x = a.x + b.x;
+        res.y = a.y + b.y;
+        res.z = a.z + b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(Double3 value) {
+        x += value.x;
+        y += value.y;
+        z += value.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(double value) {
+        x += value;
+        y += value;
+        z += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 add(Double3 a, double b) {
+        Double3 res = new Double3();
+        res.x = a.x + b;
+        res.y = a.y + b;
+        res.z = a.z + b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(Double3 value) {
+        x -= value.x;
+        y -= value.y;
+        z -= value.z;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 sub(Double3 a, Double3 b) {
+        Double3 res = new Double3();
+        res.x = a.x - b.x;
+        res.y = a.y - b.y;
+        res.z = a.z - b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(double value) {
+        x -= value;
+        y -= value;
+        z -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 sub(Double3 a, double b) {
+        Double3 res = new Double3();
+        res.x = a.x - b;
+        res.y = a.y - b;
+        res.z = a.z - b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(Double3 value) {
+        x *= value.x;
+        y *= value.y;
+        z *= value.z;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 mul(Double3 a, Double3 b) {
+        Double3 res = new Double3();
+        res.x = a.x * b.x;
+        res.y = a.y * b.y;
+        res.z = a.z * b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(double value) {
+        x *= value;
+        y *= value;
+        z *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 mul(Double3 a, double b) {
+        Double3 res = new Double3();
+        res.x = a.x * b;
+        res.y = a.y * b;
+        res.z = a.z * b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(Double3 value) {
+        x /= value.x;
+        y /= value.y;
+        z /= value.z;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 div(Double3 a, Double3 b) {
+        Double3 res = new Double3();
+        res.x = a.x / b.x;
+        res.y = a.y / b.y;
+        res.z = a.z / b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(double value) {
+        x /= value;
+        y /= value;
+        z /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double3 div(Double3 a, double b) {
+        Double3 res = new Double3();
+        res.x = a.x / b;
+        res.y = a.y / b;
+        res.z = a.z / b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public double dotProduct(Double3 a) {
+        return (x * a.x) + (y * a.y) + (z * a.z);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static double dotProduct(Double3 a, Double3 b) {
+        return (b.x * a.x) + (b.y * a.y) + (b.z * a.z);
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Double3 a, double factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+    }
+
+    /** @hide
+     * Set vector value by double3
+     *
+     * @param a
+     */
+    public void set(Double3 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+    }
+
+    /** @hide
+     * Set vector negate
+     */
+    public void negate() {
+        x = -x;
+        y = -y;
+        z = -z;
+    }
+
+    /** @hide
+     * Get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 3;
+    }
+
+    /** @hide
+     * Return the element sum of vector
+     *
+     * @return
+     */
+    public double elementSum() {
+        return x + y + z;
+    }
+
+    /** @hide
+     * Get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public double get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        case 2:
+            return z;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, double value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, double value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Set the vector field value
+     *
+     * @param x
+     * @param y
+     * @param z
+     */
+    public void setValues(double x, double y, double z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide
+     * Copy the vector to double array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(double[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+        data[offset + 2] = z;
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Double4.java b/graphics/java/android/renderscript/Double4.java
index 7775ab7..e4829f7 100644
--- a/graphics/java/android/renderscript/Double4.java
+++ b/graphics/java/android/renderscript/Double4.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,31 +16,435 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript double4 type back
- * to the Android system.
- *
- **/
+ * Vector version of the basic double type.
+ * Provides four double fields packed.
+ */
 public class Double4 {
-    public Double4() {
-    }
-
-    public Double4(double initX, double initY, double initZ, double initW) {
-        x = initX;
-        y = initY;
-        z = initZ;
-        w = initW;
-    }
-
     public double x;
     public double y;
     public double z;
     public double w;
+
+    public Double4() {
+    }
+    /** @hide */
+    public Double4(Double4 data) {
+        this.x = data.x;
+        this.y = data.y;
+        this.z = data.z;
+        this.w = data.w;
+    }
+
+    public Double4(double x, double y, double z, double w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 add(Double4 a, Double4 b) {
+        Double4 res = new Double4();
+        res.x = a.x + b.x;
+        res.y = a.y + b.y;
+        res.z = a.z + b.z;
+        res.w = a.w + b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(Double4 value) {
+        x += value.x;
+        y += value.y;
+        z += value.z;
+        w += value.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(double value) {
+        x += value;
+        y += value;
+        z += value;
+        w += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 add(Double4 a, double b) {
+        Double4 res = new Double4();
+        res.x = a.x + b;
+        res.y = a.y + b;
+        res.z = a.z + b;
+        res.w = a.w + b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(Double4 value) {
+        x -= value.x;
+        y -= value.y;
+        z -= value.z;
+        w -= value.w;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(double value) {
+        x -= value;
+        y -= value;
+        z -= value;
+        w -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 sub(Double4 a, double b) {
+        Double4 res = new Double4();
+        res.x = a.x - b;
+        res.y = a.y - b;
+        res.z = a.z - b;
+        res.w = a.w - b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 sub(Double4 a, Double4 b) {
+        Double4 res = new Double4();
+        res.x = a.x - b.x;
+        res.y = a.y - b.y;
+        res.z = a.z - b.z;
+        res.w = a.w - b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(Double4 value) {
+        x *= value.x;
+        y *= value.y;
+        z *= value.z;
+        w *= value.w;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(double value) {
+        x *= value;
+        y *= value;
+        z *= value;
+        w *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 mul(Double4 a, Double4 b) {
+        Double4 res = new Double4();
+        res.x = a.x * b.x;
+        res.y = a.y * b.y;
+        res.z = a.z * b.z;
+        res.w = a.w * b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 mul(Double4 a, double b) {
+        Double4 res = new Double4();
+        res.x = a.x * b;
+        res.y = a.y * b;
+        res.z = a.z * b;
+        res.w = a.w * b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(Double4 value) {
+        x /= value.x;
+        y /= value.y;
+        z /= value.z;
+        w /= value.w;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(double value) {
+        x /= value;
+        y /= value;
+        z /= value;
+        w /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 div(Double4 a, double b) {
+        Double4 res = new Double4();
+        res.x = a.x / b;
+        res.y = a.y / b;
+        res.z = a.z / b;
+        res.w = a.w / b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Double4 div(Double4 a, Double4 b) {
+        Double4 res = new Double4();
+        res.x = a.x / b.x;
+        res.y = a.y / b.y;
+        res.z = a.z / b.z;
+        res.w = a.w / b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public double dotProduct(Double4 a) {
+        return (x * a.x) + (y * a.y) + (z * a.z) + (w * a.w);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static double dotProduct(Double4 a, Double4 b) {
+        return (b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w);
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Double4 a, double factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+        w += a.w * factor;
+    }
+
+    /** @hide
+     * Set vector value by double4
+     *
+     * @param a
+     */
+    public void set(Double4 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+        this.w = a.w;
+    }
+
+    /** @hide
+     * Set vector negate
+     */
+    public void negate() {
+        x = -x;
+        y = -y;
+        z = -z;
+        w = -w;
+    }
+
+    /** @hide
+     * Get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 4;
+    }
+
+    /** @hide
+     * Return the element sum of vector
+     *
+     * @return
+     */
+    public double elementSum() {
+        return x + y + z + w;
+    }
+
+    /** @hide
+     * Get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public double get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        case 2:
+            return z;
+        case 3:
+            return w;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, double value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        case 3:
+            w = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, double value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        case 3:
+            w += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * Set the vector field value
+     *
+     * @param x
+     * @param y
+     * @param z
+     * @param w
+     */
+    public void setValues(double x, double y, double z, double w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide
+     * Copy the vector to double array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(double[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+        data[offset + 2] = z;
+        data[offset + 3] = w;
+    }
 }
-
-
-
diff --git a/graphics/java/android/renderscript/Float2.java b/graphics/java/android/renderscript/Float2.java
index 0f730fe..26193d2 100644
--- a/graphics/java/android/renderscript/Float2.java
+++ b/graphics/java/android/renderscript/Float2.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,27 +16,369 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript float2 type back to the Android system.
- *
- **/
-public class Float2 {
-    public Float2() {
-    }
-
-    public Float2(float initX, float initY) {
-        x = initX;
-        y = initY;
-    }
-
+ * Vector version of the basic float type.
+ * Provides two float fields packed.
+ */
+public  class Float2 {
     public float x;
     public float y;
+
+    public Float2() {
+    }
+    /** @hide */ 
+    public Float2(Float2 data) {
+        this.x = data.x;
+        this.y = data.y;
+    }
+
+    public Float2(float x, float y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 add(Float2 a, Float2 b) {
+        Float2 res = new Float2();
+        res.x = a.x + b.x;
+        res.y = a.y + b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(Float2 value) {
+        x += value.x;
+        y += value.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(float value) {
+        x += value;
+        y += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 add(Float2 a, float b) {
+        Float2 res = new Float2();
+        res.x = a.x + b;
+        res.y = a.y + b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(Float2 value) {
+        x -= value.x;
+        y -= value.y;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 sub(Float2 a, Float2 b) {
+        Float2 res = new Float2();
+        res.x = a.x - b.x;
+        res.y = a.y - b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(float value) {
+        x -= value;
+        y -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 sub(Float2 a, float b) {
+        Float2 res = new Float2();
+        res.x = a.x - b;
+        res.y = a.y - b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(Float2 value) {
+        x *= value.x;
+        y *= value.y;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 mul(Float2 a, Float2 b) {
+        Float2 res = new Float2();
+        res.x = a.x * b.x;
+        res.y = a.y * b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(float value) {
+        x *= value;
+        y *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 mul(Float2 a, float b) {
+        Float2 res = new Float2();
+        res.x = a.x * b;
+        res.y = a.y * b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(Float2 value) {
+        x /= value.x;
+        y /= value.y;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 div(Float2 a, Float2 b) {
+        Float2 res = new Float2();
+        res.x = a.x / b.x;
+        res.y = a.y / b.y;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(float value) {
+        x /= value;
+        y /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float2 div(Float2 a, float b) {
+        Float2 res = new Float2();
+        res.x = a.x / b;
+        res.y = a.y / b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public float dotProduct(Float2 a) {
+        return (x * a.x) + (y * a.y);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static float dotProduct(Float2 a, Float2 b) {
+        return (b.x * a.x) + (b.y * a.y);
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Float2 a, float factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+    }
+
+    /** @hide
+     * set vector value by float2
+     *
+     * @param a
+     */
+    public void set(Float2 a) {
+        this.x = a.x;
+        this.y = a.y;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        x = -x;
+        y = -y;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 2;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public float elementSum() {
+        return x + y;
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public float get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, float value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, float value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value
+     *
+     * @param x
+     * @param y
+     */
+    public void setValues(float x, float y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide
+     * copy the vector to float array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(float[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Float3.java b/graphics/java/android/renderscript/Float3.java
index 749865f1..555bdf6 100644
--- a/graphics/java/android/renderscript/Float3.java
+++ b/graphics/java/android/renderscript/Float3.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,28 +16,402 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript float2 type back to the Android system.
- *
- **/
+ * Vector version of the basic float type.
+ * Provides three float fields packed.
+ */
 public class Float3 {
-    public Float3() {
-    }
-    public Float3(float initX, float initY, float initZ) {
-        x = initX;
-        y = initY;
-        z = initZ;
-    }
-
     public float x;
     public float y;
     public float z;
+
+    public Float3() {
+    }
+    /** @hide */
+    public Float3(Float3 data) {
+        this.x = data.x;
+        this.y = data.y;
+        this.z = data.z;
+    }
+
+    public Float3(float x, float y, float z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 add(Float3 a, Float3 b) {
+        Float3 res = new Float3();
+        res.x = a.x + b.x;
+        res.y = a.y + b.y;
+        res.z = a.z + b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(Float3 value) {
+        x += value.x;
+        y += value.y;
+        z += value.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(float value) {
+        x += value;
+        y += value;
+        z += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 add(Float3 a, float b) {
+        Float3 res = new Float3();
+        res.x = a.x + b;
+        res.y = a.y + b;
+        res.z = a.z + b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(Float3 value) {
+        x -= value.x;
+        y -= value.y;
+        z -= value.z;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 sub(Float3 a, Float3 b) {
+        Float3 res = new Float3();
+        res.x = a.x - b.x;
+        res.y = a.y - b.y;
+        res.z = a.z - b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(float value) {
+        x -= value;
+        y -= value;
+        z -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 sub(Float3 a, float b) {
+        Float3 res = new Float3();
+        res.x = a.x - b;
+        res.y = a.y - b;
+        res.z = a.z - b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(Float3 value) {
+        x *= value.x;
+        y *= value.y;
+        z *= value.z;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 mul(Float3 a, Float3 b) {
+        Float3 res = new Float3();
+        res.x = a.x * b.x;
+        res.y = a.y * b.y;
+        res.z = a.z * b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(float value) {
+        x *= value;
+        y *= value;
+        z *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 mul(Float3 a, float b) {
+        Float3 res = new Float3();
+        res.x = a.x * b;
+        res.y = a.y * b;
+        res.z = a.z * b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(Float3 value) {
+        x /= value.x;
+        y /= value.y;
+        z /= value.z;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 div(Float3 a, Float3 b) {
+        Float3 res = new Float3();
+        res.x = a.x / b.x;
+        res.y = a.y / b.y;
+        res.z = a.z / b.z;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(float value) {
+        x /= value;
+        y /= value;
+        z /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float3 div(Float3 a, float b) {
+        Float3 res = new Float3();
+        res.x = a.x / b;
+        res.y = a.y / b;
+        res.z = a.z / b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public Float dotProduct(Float3 a) {
+        return new Float((x * a.x) + (y * a.y) + (z * a.z));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float dotProduct(Float3 a, Float3 b) {
+        return new Float((b.x * a.x) + (b.y * a.y) + (b.z * a.z));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Float3 a, float factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+    }
+
+    /** @hide
+     * set vector value by float3
+     *
+     * @param a
+     */
+    public void set(Float3 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        x = -x;
+        y = -y;
+        z = -z;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 3;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public Float elementSum() {
+        return new Float(x + y + z);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public float get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        case 2:
+            return z;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, float value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, float value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value
+     *
+     * @param x
+     * @param y
+     * @param z
+     */
+    public void setValues(float x, float y, float z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide
+     * copy the vector to float array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(float[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+        data[offset + 2] = z;
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Float4.java b/graphics/java/android/renderscript/Float4.java
index 7ddf6aa..6541b2e 100644
--- a/graphics/java/android/renderscript/Float4.java
+++ b/graphics/java/android/renderscript/Float4.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,30 +16,435 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript float2 type back to the Android system.
- *
- **/
+ * Vector version of the basic float type.
+ * Provides four float fields packed.
+ */
 public class Float4 {
-    public Float4() {
-    }
-
-    public Float4(float initX, float initY, float initZ, float initW) {
-        x = initX;
-        y = initY;
-        z = initZ;
-        w = initW;
-    }
-
     public float x;
     public float y;
     public float z;
     public float w;
+
+    public Float4() {
+    }
+    /** @hide */
+    public Float4(Float4 data) {
+        this.x = data.x;
+        this.y = data.y;
+        this.z = data.z;
+        this.w = data.w;
+    }
+
+    public Float4(float x, float y, float z, float w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 add(Float4 a, Float4 b) {
+        Float4 res = new Float4();
+        res.x = a.x + b.x;
+        res.y = a.y + b.y;
+        res.z = a.z + b.z;
+        res.w = a.w + b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(Float4 value) {
+        x += value.x;
+        y += value.y;
+        z += value.z;
+        w += value.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(float value) {
+        x += value;
+        y += value;
+        z += value;
+        w += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 add(Float4 a, float b) {
+        Float4 res = new Float4();
+        res.x = a.x + b;
+        res.y = a.y + b;
+        res.z = a.z + b;
+        res.w = a.w + b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(Float4 value) {
+        x -= value.x;
+        y -= value.y;
+        z -= value.z;
+        w -= value.w;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(float value) {
+        x -= value;
+        y -= value;
+        z -= value;
+        w -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 sub(Float4 a, float b) {
+        Float4 res = new Float4();
+        res.x = a.x - b;
+        res.y = a.y - b;
+        res.z = a.z - b;
+        res.w = a.w - b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 sub(Float4 a, Float4 b) {
+        Float4 res = new Float4();
+        res.x = a.x - b.x;
+        res.y = a.y - b.y;
+        res.z = a.z - b.z;
+        res.w = a.w - b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(Float4 value) {
+        x *= value.x;
+        y *= value.y;
+        z *= value.z;
+        w *= value.w;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(float value) {
+        x *= value;
+        y *= value;
+        z *= value;
+        w *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 mul(Float4 a, Float4 b) {
+        Float4 res = new Float4();
+        res.x = a.x * b.x;
+        res.y = a.y * b.y;
+        res.z = a.z * b.z;
+        res.w = a.w * b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 mul(Float4 a, float b) {
+        Float4 res = new Float4();
+        res.x = a.x * b;
+        res.y = a.y * b;
+        res.z = a.z * b;
+        res.w = a.w * b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(Float4 value) {
+        x /= value.x;
+        y /= value.y;
+        z /= value.z;
+        w /= value.w;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(float value) {
+        x /= value;
+        y /= value;
+        z /= value;
+        w /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 div(Float4 a, float b) {
+        Float4 res = new Float4();
+        res.x = a.x / b;
+        res.y = a.y / b;
+        res.z = a.z / b;
+        res.w = a.w / b;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Float4 div(Float4 a, Float4 b) {
+        Float4 res = new Float4();
+        res.x = a.x / b.x;
+        res.y = a.y / b.y;
+        res.z = a.z / b.z;
+        res.w = a.w / b.w;
+
+        return res;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public float dotProduct(Float4 a) {
+        return (x * a.x) + (y * a.y) + (z * a.z) + (w * a.w);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static float dotProduct(Float4 a, Float4 b) {
+        return (b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w);
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Float4 a, float factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+        w += a.w * factor;
+    }
+
+    /** @hide
+     * set vector value by float4
+     *
+     * @param a
+     */
+    public void set(Float4 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+        this.w = a.w;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        x = -x;
+        y = -y;
+        z = -z;
+        w = -w;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 4;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public float elementSum() {
+        return x + y + z + w;
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public float get(int i) {
+        switch (i) {
+        case 0:
+            return x;
+        case 1:
+            return y;
+        case 2:
+            return z;
+        case 3:
+            return w;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, float value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        case 3:
+            w = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, float value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        case 3:
+            w += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value
+     *
+     * @param x
+     * @param y
+     * @param z
+     * @param w
+     */
+    public void setValues(float x, float y, float z, float w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide
+     * copy the vector to float array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(float[] data, int offset) {
+        data[offset] = x;
+        data[offset + 1] = y;
+        data[offset + 2] = z;
+        data[offset + 3] = w;
+    }
 }
-
-
-
diff --git a/graphics/java/android/renderscript/Int2.java b/graphics/java/android/renderscript/Int2.java
index 71b5dd5..120957b 100644
--- a/graphics/java/android/renderscript/Int2.java
+++ b/graphics/java/android/renderscript/Int2.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,27 +16,425 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript int2 type back to the Android system.
- *
- **/
+ * Vector version of the basic int type.
+ * Provides two int fields packed.
+ */
 public class Int2 {
+    public int x;
+    public int y;
+
     public Int2() {
     }
 
-    public Int2(int initX, int initY) {
-        x = initX;
-        y = initY;
+    /** @hide */
+    public Int2(int i) {
+        this.x = this.y = i;
     }
 
-    public int x;
-    public int y;
+    public Int2(int x, int y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide */
+    public Int2(Int2 source) {
+        this.x = source.x;
+        this.y = source.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Int2 a) {
+        this.x += a.x;
+        this.y += a.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 add(Int2 a, Int2 b) {
+        Int2 result = new Int2();
+        result.x = a.x + b.x;
+        result.y = a.y + b.y;
+
+        return result;
+    }
+
+    /**  @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(int value) {
+        x += value;
+        y += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 add(Int2 a, int b) {
+        Int2 result = new Int2();
+        result.x = a.x + b;
+        result.y = a.y + b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Int2 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 sub(Int2 a, Int2 b) {
+        Int2 result = new Int2();
+        result.x = a.x - b.x;
+        result.y = a.y - b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(int value) {
+        x -= value;
+        y -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 sub(Int2 a, int b) {
+        Int2 result = new Int2();
+        result.x = a.x - b;
+        result.y = a.y - b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Int2 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 mul(Int2 a, Int2 b) {
+        Int2 result = new Int2();
+        result.x = a.x * b.x;
+        result.y = a.y * b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(int value) {
+        x *= value;
+        y *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 mul(Int2 a, int b) {
+        Int2 result = new Int2();
+        result.x = a.x * b;
+        result.y = a.y * b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Int2 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 div(Int2 a, Int2 b) {
+        Int2 result = new Int2();
+        result.x = a.x / b.x;
+        result.y = a.y / b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(int value) {
+        x /= value;
+        y /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 div(Int2 a, int b) {
+        Int2 result = new Int2();
+        result.x = a.x / b;
+        result.y = a.y / b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Int2 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 mod(Int2 a, Int2 b) {
+        Int2 result = new Int2();
+        result.x = a.x % b.x;
+        result.y = a.y % b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(int value) {
+        x %= value;
+        y %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int2 mod(Int2 a, int b) {
+        Int2 result = new Int2();
+        result.x = a.x % b;
+        result.y = a.y % b;
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 2;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = -x;
+        this.y = -y;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public int dotProduct(Int2 a) {
+        return (int)((x * a.x) + (y * a.y));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static int dotProduct(Int2 a, Int2 b) {
+        return (int)((b.x * a.x) + (b.y * a.y));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Int2 a, int factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+    }
+
+    /** @hide
+     * set vector value by Int2
+     *
+     * @param a
+     */
+    public void set(Int2 a) {
+        this.x = a.x;
+        this.y = a.y;
+    }
+
+    /** @hide
+     * set the vector field value by Int
+     *
+     * @param a
+     * @param b
+     */
+    public void setValues(int a, int b) {
+        this.x = a;
+        this.y = b;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public int elementSum() {
+        return (int)(x + y);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public int get(int i) {
+        switch (i) {
+        case 0:
+            return (int)(x);
+        case 1:
+            return (int)(y);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, int value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, int value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to int array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(int[] data, int offset) {
+        data[offset] = (int)(x);
+        data[offset + 1] = (int)(y);
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Int3.java b/graphics/java/android/renderscript/Int3.java
index 719c908..c770395 100644
--- a/graphics/java/android/renderscript/Int3.java
+++ b/graphics/java/android/renderscript/Int3.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,29 +16,462 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript int3 type back to the Android system.
- *
- **/
+ * Vector version of the basic int type.
+ * Provides three int fields packed.
+ */
 public class Int3 {
-    public Int3() {
-    }
-
-    public Int3(int initX, int initY, int initZ) {
-        x = initX;
-        y = initY;
-        z = initZ;
-    }
-
     public int x;
     public int y;
     public int z;
+
+    public Int3() {
+    }
+    
+    /** @hide */
+    public Int3(int i) {
+        this.x = this.y = this.z = i;
+    }
+
+    public Int3(int x, int y, int z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide */
+    public Int3(Int3 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Int3 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 add(Int3 a, Int3 b) {
+        Int3 result = new Int3();
+        result.x = a.x + b.x;
+        result.y = a.y + b.y;
+        result.z = a.z + b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(int value) {
+        x += value;
+        y += value;
+        z += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 add(Int3 a, int b) {
+        Int3 result = new Int3();
+        result.x = a.x + b;
+        result.y = a.y + b;
+        result.z = a.z + b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Int3 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 sub(Int3 a, Int3 b) {
+        Int3 result = new Int3();
+        result.x = a.x - b.x;
+        result.y = a.y - b.y;
+        result.z = a.z - b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(int value) {
+        x -= value;
+        y -= value;
+        z -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 sub(Int3 a, int b) {
+        Int3 result = new Int3();
+        result.x = a.x - b;
+        result.y = a.y - b;
+        result.z = a.z - b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Int3 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 mul(Int3 a, Int3 b) {
+        Int3 result = new Int3();
+        result.x = a.x * b.x;
+        result.y = a.y * b.y;
+        result.z = a.z * b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(int value) {
+        x *= value;
+        y *= value;
+        z *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 mul(Int3 a, int b) {
+        Int3 result = new Int3();
+        result.x = a.x * b;
+        result.y = a.y * b;
+        result.z = a.z * b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Int3 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 div(Int3 a, Int3 b) {
+        Int3 result = new Int3();
+        result.x = a.x / b.x;
+        result.y = a.y / b.y;
+        result.z = a.z / b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(int value) {
+        x /= value;
+        y /= value;
+        z /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 div(Int3 a, int b) {
+        Int3 result = new Int3();
+        result.x = a.x / b;
+        result.y = a.y / b;
+        result.z = a.z / b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Int3 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+        this.z %= a.z;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 mod(Int3 a, Int3 b) {
+        Int3 result = new Int3();
+        result.x = a.x % b.x;
+        result.y = a.y % b.y;
+        result.z = a.z % b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(int value) {
+        x %= value;
+        y %= value;
+        z %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int3 mod(Int3 a, int b) {
+        Int3 result = new Int3();
+        result.x = a.x % b;
+        result.y = a.y % b;
+        result.z = a.z % b;
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 3;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = -x;
+        this.y = -y;
+        this.z = -z;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public int dotProduct(Int3 a) {
+        return (int)((x * a.x) + (y * a.y) + (z * a.z));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static int dotProduct(Int3 a, Int3 b) {
+        return (int)((b.x * a.x) + (b.y * a.y) + (b.z * a.z));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Int3 a, int factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+    }
+
+    /** @hide
+     * set vector value by Int3
+     *
+     * @param a
+     */
+    public void set(Int3 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+    }
+
+    /** @hide
+     * set the vector field value by Int
+     *
+     * @param a
+     * @param b
+     * @param c
+     */
+    public void setValues(int a, int b, int c) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public int elementSum() {
+        return (int)(x + y + z);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public int get(int i) {
+        switch (i) {
+        case 0:
+            return (int)(x);
+        case 1:
+            return (int)(y);
+        case 2:
+            return (int)(z);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, int value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, int value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to int array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(int[] data, int offset) {
+        data[offset] = (int)(x);
+        data[offset + 1] = (int)(y);
+        data[offset + 2] = (int)(z);
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Int4.java b/graphics/java/android/renderscript/Int4.java
index eefb349..1c0e2e2 100644
--- a/graphics/java/android/renderscript/Int4.java
+++ b/graphics/java/android/renderscript/Int4.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,30 +16,499 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript int4 type back to the Android system.
- *
- **/
+ * Vector version of the basic int type.
+ * Provides four int fields packed.
+ */
 public class Int4 {
-    public Int4() {
-    }
-
-    public Int4(int initX, int initY, int initZ, int initW) {
-        x = initX;
-        y = initY;
-        z = initZ;
-        w = initW;
-    }
-
     public int x;
     public int y;
     public int z;
     public int w;
+
+    public Int4() {
+    }
+
+    /** @hide */
+    public Int4(int i) {
+        this.x = this.y = this.z = this.w = i;
+    }
+
+    public Int4(int x, int y, int z, int w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide */
+    public Int4(Int4 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+        this.w = source.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Int4 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+        this.w += a.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 add(Int4 a, Int4 b) {
+        Int4 result = new Int4();
+        result.x = a.x + b.x;
+        result.y = a.y + b.y;
+        result.z = a.z + b.z;
+        result.w = a.w + b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(int value) {
+        x += value;
+        y += value;
+        z += value;
+        w += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 add(Int4 a, int b) {
+        Int4 result = new Int4();
+        result.x = a.x + b;
+        result.y = a.y + b;
+        result.z = a.z + b;
+        result.w = a.w + b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Int4 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+        this.w -= a.w;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 sub(Int4 a, Int4 b) {
+        Int4 result = new Int4();
+        result.x = a.x - b.x;
+        result.y = a.y - b.y;
+        result.z = a.z - b.z;
+        result.w = a.w - b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(int value) {
+        x -= value;
+        y -= value;
+        z -= value;
+        w -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 sub(Int4 a, int b) {
+        Int4 result = new Int4();
+        result.x = a.x - b;
+        result.y = a.y - b;
+        result.z = a.z - b;
+        result.w = a.w - b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Int4 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+        this.w *= a.w;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 mul(Int4 a, Int4 b) {
+        Int4 result = new Int4();
+        result.x = a.x * b.x;
+        result.y = a.y * b.y;
+        result.z = a.z * b.z;
+        result.w = a.w * b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(int value) {
+        x *= value;
+        y *= value;
+        z *= value;
+        w *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 mul(Int4 a, int b) {
+        Int4 result = new Int4();
+        result.x = a.x * b;
+        result.y = a.y * b;
+        result.z = a.z * b;
+        result.w = a.w * b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Int4 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+        this.w /= a.w;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 div(Int4 a, Int4 b) {
+        Int4 result = new Int4();
+        result.x = a.x / b.x;
+        result.y = a.y / b.y;
+        result.z = a.z / b.z;
+        result.w = a.w / b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(int value) {
+        x /= value;
+        y /= value;
+        z /= value;
+        w /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 div(Int4 a, int b) {
+        Int4 result = new Int4();
+        result.x = a.x / b;
+        result.y = a.y / b;
+        result.z = a.z / b;
+        result.w = a.w / b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Int4 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+        this.z %= a.z;
+        this.w %= a.w;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 mod(Int4 a, Int4 b) {
+        Int4 result = new Int4();
+        result.x = a.x % b.x;
+        result.y = a.y % b.y;
+        result.z = a.z % b.z;
+        result.w = a.w % b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(int value) {
+        x %= value;
+        y %= value;
+        z %= value;
+        w %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Int4 mod(Int4 a, int b) {
+        Int4 result = new Int4();
+        result.x = a.x % b;
+        result.y = a.y % b;
+        result.z = a.z % b;
+        result.w = a.w % b;
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public int length() {
+        return 4;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = -x;
+        this.y = -y;
+        this.z = -z;
+        this.w = -w;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public int dotProduct(Int4 a) {
+        return (int)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static int dotProduct(Int4 a, Int4 b) {
+        return (int)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Int4 a, int factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+        w += a.w * factor;
+    }
+
+    /** @hide
+     * set vector value by Int4
+     *
+     * @param a
+     */
+    public void set(Int4 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+        this.w = a.w;
+    }
+
+    /** @hide
+     * set the vector field value by Int
+     *
+     * @param a
+     * @param b
+     * @param c
+     * @param d
+     */
+    public void setValues(int a, int b, int c, int d) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+        this.w = d;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public int elementSum() {
+        return (int)(x + y + z + w);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public int get(int i) {
+        switch (i) {
+        case 0:
+            return (int)(x);
+        case 1:
+            return (int)(y);
+        case 2:
+            return (int)(z);
+        case 3:
+            return (int)(w);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, int value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        case 3:
+            w = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, int value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        case 3:
+            w += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to int array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(int[] data, int offset) {
+        data[offset] = (int)(x);
+        data[offset + 1] = (int)(y);
+        data[offset + 2] = (int)(z);
+        data[offset + 3] = (int)(w);
+    }
 }
-
-
-
diff --git a/graphics/java/android/renderscript/Long2.java b/graphics/java/android/renderscript/Long2.java
index bd8382d..fabf204 100644
--- a/graphics/java/android/renderscript/Long2.java
+++ b/graphics/java/android/renderscript/Long2.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,26 +16,425 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript long2 type back to the Android system.
- **/
+ * Vector version of the basic long type.
+ * Provides two long fields packed.
+ */
 public class Long2 {
+    public long x;
+    public long y;
+
     public Long2() {
     }
 
-    public Long2(long initX, long initY) {
-        x = initX;
-        y = initY;
+    /** @hide */
+    public Long2(long i) {
+        this.x = this.y = i;
     }
 
-    public long x;
-    public long y;
+    public Long2(long x, long y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide */
+    public Long2(Long2 source) {
+        this.x = source.x;
+        this.y = source.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Long2 a) {
+        this.x += a.x;
+        this.y += a.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 add(Long2 a, Long2 b) {
+        Long2 result = new Long2();
+        result.x = a.x + b.x;
+        result.y = a.y + b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(long value) {
+        x += value;
+        y += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 add(Long2 a, long b) {
+        Long2 result = new Long2();
+        result.x = a.x + b;
+        result.y = a.y + b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Long2 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 sub(Long2 a, Long2 b) {
+        Long2 result = new Long2();
+        result.x = a.x - b.x;
+        result.y = a.y - b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(long value) {
+        x -= value;
+        y -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 sub(Long2 a, long b) {
+        Long2 result = new Long2();
+        result.x = a.x - b;
+        result.y = a.y - b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Long2 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 mul(Long2 a, Long2 b) {
+        Long2 result = new Long2();
+        result.x = a.x * b.x;
+        result.y = a.y * b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(long value) {
+        x *= value;
+        y *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 mul(Long2 a, long b) {
+        Long2 result = new Long2();
+        result.x = a.x * b;
+        result.y = a.y * b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Long2 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 div(Long2 a, Long2 b) {
+        Long2 result = new Long2();
+        result.x = a.x / b.x;
+        result.y = a.y / b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(long value) {
+        x /= value;
+        y /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 div(Long2 a, long b) {
+        Long2 result = new Long2();
+        result.x = a.x / b;
+        result.y = a.y / b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Long2 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 mod(Long2 a, Long2 b) {
+        Long2 result = new Long2();
+        result.x = a.x % b.x;
+        result.y = a.y % b.y;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(long value) {
+        x %= value;
+        y %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long2 mod(Long2 a, long b) {
+        Long2 result = new Long2();
+        result.x = a.x % b;
+        result.y = a.y % b;
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public long length() {
+        return 2;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = -x;
+        this.y = -y;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public long dotProduct(Long2 a) {
+        return (long)((x * a.x) + (y * a.y));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static long dotProduct(Long2 a, Long2 b) {
+        return (long)((b.x * a.x) + (b.y * a.y));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Long2 a, long factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+    }
+
+    /** @hide
+     * set vector value by Long2
+     *
+     * @param a
+     */
+    public void set(Long2 a) {
+        this.x = a.x;
+        this.y = a.y;
+    }
+
+    /** @hide
+     * set the vector field value by Long
+     *
+     * @param a
+     * @param b
+     */
+    public void setValues(long a, long b) {
+        this.x = a;
+        this.y = b;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public long elementSum() {
+        return (long)(x + y);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public long get(int i) {
+        switch (i) {
+        case 0:
+            return (long)(x);
+        case 1:
+            return (long)(y);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, long value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, long value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to long array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(long[] data, int offset) {
+        data[offset] = (long)(x);
+        data[offset + 1] = (long)(y);
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Long3.java b/graphics/java/android/renderscript/Long3.java
index 3e94942..88ff855 100644
--- a/graphics/java/android/renderscript/Long3.java
+++ b/graphics/java/android/renderscript/Long3.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,28 +16,462 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript long3 type back to the Android system.
- **/
+ * Vector version of the basic long type.
+ * Provides three long fields packed.
+ */
 public class Long3 {
-    public Long3() {
-    }
-
-    public Long3(long initX, long initY, long initZ) {
-        x = initX;
-        y = initY;
-        z = initZ;
-    }
-
     public long x;
     public long y;
     public long z;
+
+    public Long3() {
+    }
+    
+    /** @hide */
+    public Long3(long i) {
+        this.x = this.y = this.z = i;
+    }
+
+    public Long3(long x, long y, long z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide */
+    public Long3(Long3 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Long3 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 add(Long3 a, Long3 b) {
+        Long3 result = new Long3();
+        result.x = a.x + b.x;
+        result.y = a.y + b.y;
+        result.z = a.z + b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(long value) {
+        x += value;
+        y += value;
+        z += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 add(Long3 a, long b) {
+        Long3 result = new Long3();
+        result.x = a.x + b;
+        result.y = a.y + b;
+        result.z = a.z + b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Long3 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 sub(Long3 a, Long3 b) {
+        Long3 result = new Long3();
+        result.x = a.x - b.x;
+        result.y = a.y - b.y;
+        result.z = a.z - b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(long value) {
+        x -= value;
+        y -= value;
+        z -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 sub(Long3 a, long b) {
+        Long3 result = new Long3();
+        result.x = a.x - b;
+        result.y = a.y - b;
+        result.z = a.z - b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Long3 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 mul(Long3 a, Long3 b) {
+        Long3 result = new Long3();
+        result.x = a.x * b.x;
+        result.y = a.y * b.y;
+        result.z = a.z * b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(long value) {
+        x *= value;
+        y *= value;
+        z *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 mul(Long3 a, long b) {
+        Long3 result = new Long3();
+        result.x = a.x * b;
+        result.y = a.y * b;
+        result.z = a.z * b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Long3 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 div(Long3 a, Long3 b) {
+        Long3 result = new Long3();
+        result.x = a.x / b.x;
+        result.y = a.y / b.y;
+        result.z = a.z / b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(long value) {
+        x /= value;
+        y /= value;
+        z /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 div(Long3 a, long b) {
+        Long3 result = new Long3();
+        result.x = a.x / b;
+        result.y = a.y / b;
+        result.z = a.z / b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Long3 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+        this.z %= a.z;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 mod(Long3 a, Long3 b) {
+        Long3 result = new Long3();
+        result.x = a.x % b.x;
+        result.y = a.y % b.y;
+        result.z = a.z % b.z;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(long value) {
+        x %= value;
+        y %= value;
+        z %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long3 mod(Long3 a, long b) {
+        Long3 result = new Long3();
+        result.x = a.x % b;
+        result.y = a.y % b;
+        result.z = a.z % b;
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public long length() {
+        return 3;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = -x;
+        this.y = -y;
+        this.z = -z;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public long dotProduct(Long3 a) {
+        return (long)((x * a.x) + (y * a.y) + (z * a.z));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static long dotProduct(Long3 a, Long3 b) {
+        return (long)((b.x * a.x) + (b.y * a.y) + (b.z * a.z));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Long3 a, long factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+    }
+
+    /** @hide
+     * set vector value by Long3
+     *
+     * @param a
+     */
+    public void set(Long3 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+    }
+
+    /** @hide
+     * set the vector field value by Long
+     *
+     * @param a
+     * @param b
+     * @param c
+     */
+    public void setValues(long a, long b, long c) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public long elementSum() {
+        return (long)(x + y + z);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public long get(int i) {
+        switch (i) {
+        case 0:
+            return (long)(x);
+        case 1:
+            return (long)(y);
+        case 2:
+            return (long)(z);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, long value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, long value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to long array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(long[] data, int offset) {
+        data[offset] = (long)(x);
+        data[offset + 1] = (long)(y);
+        data[offset + 2] = (long)(z);
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Long4.java b/graphics/java/android/renderscript/Long4.java
index 00fb7e6..757b910 100644
--- a/graphics/java/android/renderscript/Long4.java
+++ b/graphics/java/android/renderscript/Long4.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,29 +16,499 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript long4 type back to the Android system.
- **/
+ * Vector version of the basic long type.
+ * Provides four long fields packed.
+ */
 public class Long4 {
-    public Long4() {
-    }
-
-    public Long4(long initX, long initY, long initZ, long initW) {
-        x = initX;
-        y = initY;
-        z = initZ;
-        w = initW;
-    }
-
     public long x;
     public long y;
     public long z;
     public long w;
+
+    public Long4() {
+    }
+
+    /** @hide */
+    public Long4(long i) {
+        this.x = this.y = this.z = this.w = i;
+    }
+
+    public Long4(long x, long y, long z, long w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide */
+    public Long4(Long4 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+        this.w = source.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Long4 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+        this.w += a.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 add(Long4 a, Long4 b) {
+        Long4 result = new Long4();
+        result.x = a.x + b.x;
+        result.y = a.y + b.y;
+        result.z = a.z + b.z;
+        result.w = a.w + b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(long value) {
+        x += value;
+        y += value;
+        z += value;
+        w += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 add(Long4 a, long b) {
+        Long4 result = new Long4();
+        result.x = a.x + b;
+        result.y = a.y + b;
+        result.z = a.z + b;
+        result.w = a.w + b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Long4 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+        this.w -= a.w;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 sub(Long4 a, Long4 b) {
+        Long4 result = new Long4();
+        result.x = a.x - b.x;
+        result.y = a.y - b.y;
+        result.z = a.z - b.z;
+        result.w = a.w - b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(long value) {
+        x -= value;
+        y -= value;
+        z -= value;
+        w -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 sub(Long4 a, long b) {
+        Long4 result = new Long4();
+        result.x = a.x - b;
+        result.y = a.y - b;
+        result.z = a.z - b;
+        result.w = a.w - b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Long4 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+        this.w *= a.w;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 mul(Long4 a, Long4 b) {
+        Long4 result = new Long4();
+        result.x = a.x * b.x;
+        result.y = a.y * b.y;
+        result.z = a.z * b.z;
+        result.w = a.w * b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(long value) {
+        x *= value;
+        y *= value;
+        z *= value;
+        w *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 mul(Long4 a, long b) {
+        Long4 result = new Long4();
+        result.x = a.x * b;
+        result.y = a.y * b;
+        result.z = a.z * b;
+        result.w = a.w * b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Long4 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+        this.w /= a.w;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 div(Long4 a, Long4 b) {
+        Long4 result = new Long4();
+        result.x = a.x / b.x;
+        result.y = a.y / b.y;
+        result.z = a.z / b.z;
+        result.w = a.w / b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(long value) {
+        x /= value;
+        y /= value;
+        z /= value;
+        w /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 div(Long4 a, long b) {
+        Long4 result = new Long4();
+        result.x = a.x / b;
+        result.y = a.y / b;
+        result.z = a.z / b;
+        result.w = a.w / b;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Long4 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+        this.z %= a.z;
+        this.w %= a.w;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 mod(Long4 a, Long4 b) {
+        Long4 result = new Long4();
+        result.x = a.x % b.x;
+        result.y = a.y % b.y;
+        result.z = a.z % b.z;
+        result.w = a.w % b.w;
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(long value) {
+        x %= value;
+        y %= value;
+        z %= value;
+        w %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Long4 mod(Long4 a, long b) {
+        Long4 result = new Long4();
+        result.x = a.x % b;
+        result.y = a.y % b;
+        result.z = a.z % b;
+        result.w = a.w % b;
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public long length() {
+        return 4;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = -x;
+        this.y = -y;
+        this.z = -z;
+        this.w = -w;
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public long dotProduct(Long4 a) {
+        return (long)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static long dotProduct(Long4 a, Long4 b) {
+        return (long)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Long4 a, long factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+        w += a.w * factor;
+    }
+
+    /** @hide
+     * set vector value by Long4
+     *
+     * @param a
+     */
+    public void set(Long4 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+        this.w = a.w;
+    }
+
+    /** @hide
+     * set the vector field value by Long
+     *
+     * @param a
+     * @param b
+     * @param c
+     * @param d
+     */
+    public void setValues(long a, long b, long c, long d) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+        this.w = d;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public long elementSum() {
+        return (long)(x + y + z + w);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public long get(int i) {
+        switch (i) {
+        case 0:
+            return (long)(x);
+        case 1:
+            return (long)(y);
+        case 2:
+            return (long)(z);
+        case 3:
+            return (long)(w);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, long value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        case 3:
+            w = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, long value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        case 3:
+            w += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to long array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(Long[] data, int offset) {
+        data[offset] = (long)(x);
+        data[offset + 1] = (long)(y);
+        data[offset + 2] = (long)(z);
+        data[offset + 3] = (long)(w);
+    }
 }
-
-
-
diff --git a/graphics/java/android/renderscript/Short2.java b/graphics/java/android/renderscript/Short2.java
index 7c6027f..070d608 100644
--- a/graphics/java/android/renderscript/Short2.java
+++ b/graphics/java/android/renderscript/Short2.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,27 +16,425 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
-/**
- * Class for exposing the native RenderScript Short2 type back to the Android system.
- *
- **/
+/** 
+ * Vector version of the basic short type.
+ * Provides two short fields packed.
+ */
 public class Short2 {
+    public short x;
+    public short y;
+
     public Short2() {
     }
 
-    public Short2(short initX, short initY) {
-        x = initX;
-        y = initY;
+    /** @hide */
+    public Short2(short i) {
+        this.x = this.y = i;
     }
 
-    public short x;
-    public short y;
+    public Short2(short x, short y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    /** @hide */
+    public Short2(Short2 source) {
+        this.x = source.x;
+        this.y = source.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Short2 a) {
+        this.x += a.x;
+        this.y += a.y;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 add(Short2 a, Short2 b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x + b.x);
+        result.y = (short)(a.y + b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(short value) {
+        x += value;
+        y += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 add(Short2 a, short b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x + b);
+        result.y = (short)(a.y + b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Short2 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 sub(Short2 a, Short2 b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x - b.x);
+        result.y = (short)(a.y - b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(short value) {
+        x -= value;
+        y -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 sub(Short2 a, short b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x - b);
+        result.y = (short)(a.y - b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Short2 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 mul(Short2 a, Short2 b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x * b.x);
+        result.y = (short)(a.y * b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(short value) {
+        x *= value;
+        y *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 mul(Short2 a, short b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x * b);
+        result.y = (short)(a.y * b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Short2 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 div(Short2 a, Short2 b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x / b.x);
+        result.y = (short)(a.y / b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(short value) {
+        x /= value;
+        y /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 div(Short2 a, short b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x / b);
+        result.y = (short)(a.y / b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Short2 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 mod(Short2 a, Short2 b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x % b.x);
+        result.y = (short)(a.y % b.y);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(short value) {
+        x %= value;
+        y %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short2 mod(Short2 a, short b) {
+        Short2 result = new Short2();
+        result.x = (short)(a.x % b);
+        result.y = (short)(a.y % b);
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public short length() {
+        return 2;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = (short)(-x);
+        this.y = (short)(-y);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public short dotProduct(Short2 a) {
+        return (short)((x * a.x) + (y * a.y));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static short dotProduct(Short2 a, Short2 b) {
+        return (short)((b.x * a.x) + (b.y * a.y));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Short2 a, short factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+    }
+
+    /** @hide
+     * set vector value by Short2
+     *
+     * @param a
+     */
+    public void set(Short2 a) {
+        this.x = a.x;
+        this.y = a.y;
+    }
+
+    /** @hide
+     * set the vector field value by Short
+     *
+     * @param a
+     * @param b
+     */
+    public void setValues(short a, short b) {
+        this.x = a;
+        this.y = b;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public short elementSum() {
+        return (short)(x + y);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public short get(int i) {
+        switch (i) {
+        case 0:
+            return (short)(x);
+        case 1:
+            return (short)(y);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, short value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, short value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to short array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(short[] data, int offset) {
+        data[offset] = (short)(x);
+        data[offset + 1] = (short)(y);
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Short3.java b/graphics/java/android/renderscript/Short3.java
index 49de05e..661db0a 100644
--- a/graphics/java/android/renderscript/Short3.java
+++ b/graphics/java/android/renderscript/Short3.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,29 +16,462 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript short3 type back to the Android system.
- *
- **/
+ * Vector version of the basic short type.
+ * Provides three short fields packed.
+ */
 public class Short3 {
-    public Short3() {
-    }
-
-    public Short3(short initX, short initY, short initZ) {
-        x = initX;
-        y = initY;
-        z = initZ;
-    }
-
     public short x;
     public short y;
     public short z;
+
+    public Short3() {
+    }
+
+    /** @hide */
+    public Short3(short i) {
+        this.x = this.y = this.z = i;
+    }
+
+    public Short3(short x, short y, short z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    /** @hide */
+    public Short3(Short3 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Short3 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 add(Short3 a, Short3 b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x + b.x);
+        result.y = (short)(a.y + b.y);
+        result.z = (short)(a.z + b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(short value) {
+        x += value;
+        y += value;
+        z += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 add(Short3 a, short b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x + b);
+        result.y = (short)(a.y + b);
+        result.z = (short)(a.z + b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Short3 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 sub(Short3 a, Short3 b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x - b.x);
+        result.y = (short)(a.y - b.y);
+        result.z = (short)(a.z - b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(short value) {
+        x -= value;
+        y -= value;
+        z -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 sub(Short3 a, short b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x - b);
+        result.y = (short)(a.y - b);
+        result.z = (short)(a.z - b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Short3 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 mul(Short3 a, Short3 b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x * b.x);
+        result.y = (short)(a.y * b.y);
+        result.z = (short)(a.z * b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(short value) {
+        x *= value;
+        y *= value;
+        z *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 mul(Short3 a, short b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x * b);
+        result.y = (short)(a.y * b);
+        result.z = (short)(a.z * b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Short3 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 div(Short3 a, Short3 b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x / b.x);
+        result.y = (short)(a.y / b.y);
+        result.z = (short)(a.z / b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(short value) {
+        x /= value;
+        y /= value;
+        z /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 div(Short3 a, short b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x / b);
+        result.y = (short)(a.y / b);
+        result.z = (short)(a.z / b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Short3 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+        this.z %= a.z;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 mod(Short3 a, Short3 b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x % b.x);
+        result.y = (short)(a.y % b.y);
+        result.z = (short)(a.z % b.z);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(short value) {
+        x %= value;
+        y %= value;
+        z %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short3 mod(Short3 a, short b) {
+        Short3 result = new Short3();
+        result.x = (short)(a.x % b);
+        result.y = (short)(a.y % b);
+        result.z = (short)(a.z % b);
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public short length() {
+        return 3;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = (short)(-x);
+        this.y = (short)(-y);
+        this.z = (short)(-z);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public short dotProduct(Short3 a) {
+        return (short)((x * a.x) + (y * a.y) + (z * a.z));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static short dotProduct(Short3 a, Short3 b) {
+        return (short)((b.x * a.x) + (b.y * a.y) + (b.z * a.z));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Short3 a, short factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+    }
+
+    /** @hide
+     * set vector value by Short3
+     *
+     * @param a
+     */
+    public void set(Short3 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+    }
+
+    /** @hide
+     * set the vector field value by Short
+     *
+     * @param a
+     * @param b
+     * @param c
+     */
+    public void setValues(short a, short b, short c) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public short elementSum() {
+        return (short)(x + y + z);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public short get(int i) {
+        switch (i) {
+        case 0:
+            return (short)(x);
+        case 1:
+            return (short)(y);
+        case 2:
+            return (short)(z);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, short value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, short value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to short array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(short[] data, int offset) {
+        data[offset] = (short)(x);
+        data[offset + 1] = (short)(y);
+        data[offset + 2] = (short)(z);
+    }
 }
-
-
-
-
diff --git a/graphics/java/android/renderscript/Short4.java b/graphics/java/android/renderscript/Short4.java
index a7807a4..a2d74f2 100644
--- a/graphics/java/android/renderscript/Short4.java
+++ b/graphics/java/android/renderscript/Short4.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2013 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.
@@ -16,30 +16,499 @@
 
 package android.renderscript;
 
-import java.lang.Math;
-import android.util.Log;
-
-
 /**
- * Class for exposing the native RenderScript short4 type back to the Android system.
- *
- **/
+ * Vector version of the basic short type.
+ * Provides four short fields packed.
+ */
 public class Short4 {
-    public Short4() {
-    }
-
-    public Short4(short initX, short initY, short initZ, short initW) {
-        x = initX;
-        y = initY;
-        z = initZ;
-        w = initW;
-    }
-
     public short x;
     public short y;
     public short z;
     public short w;
+
+    public Short4() {
+    }
+
+    /** @hide */
+    public Short4(short i) {
+        this.x = this.y = this.z = this.w = i;
+    }
+
+    public Short4(short x, short y, short z, short w) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+        this.w = w;
+    }
+
+    /** @hide */
+    public Short4(Short4 source) {
+        this.x = source.x;
+        this.y = source.y;
+        this.z = source.z;
+        this.w = source.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     */
+    public void add(Short4 a) {
+        this.x += a.x;
+        this.y += a.y;
+        this.z += a.z;
+        this.w += a.w;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 add(Short4 a, Short4 b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x + b.x);
+        result.y = (short)(a.y + b.y);
+        result.z = (short)(a.z + b.z);
+        result.w = (short)(a.w + b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param value
+     */
+    public void add(short value) {
+        x += value;
+        y += value;
+        z += value;
+        w += value;
+    }
+
+    /** @hide
+     * Vector add
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 add(Short4 a, short b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x + b);
+        result.y = (short)(a.y + b);
+        result.z = (short)(a.z + b);
+        result.w = (short)(a.w + b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     */
+    public void sub(Short4 a) {
+        this.x -= a.x;
+        this.y -= a.y;
+        this.z -= a.z;
+        this.w -= a.w;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 sub(Short4 a, Short4 b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x - b.x);
+        result.y = (short)(a.y - b.y);
+        result.z = (short)(a.z - b.z);
+        result.w = (short)(a.w - b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param value
+     */
+    public void sub(short value) {
+        x -= value;
+        y -= value;
+        z -= value;
+        w -= value;
+    }
+
+    /** @hide
+     * Vector subtraction
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 sub(Short4 a, short b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x - b);
+        result.y = (short)(a.y - b);
+        result.z = (short)(a.z - b);
+        result.w = (short)(a.w - b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     */
+    public void mul(Short4 a) {
+        this.x *= a.x;
+        this.y *= a.y;
+        this.z *= a.z;
+        this.w *= a.w;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 mul(Short4 a, Short4 b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x * b.x);
+        result.y = (short)(a.y * b.y);
+        result.z = (short)(a.z * b.z);
+        result.w = (short)(a.w * b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param value
+     */
+    public void mul(short value) {
+        x *= value;
+        y *= value;
+        z *= value;
+        w *= value;
+    }
+
+    /** @hide
+     * Vector multiplication
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 mul(Short4 a, short b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x * b);
+        result.y = (short)(a.y * b);
+        result.z = (short)(a.z * b);
+        result.w = (short)(a.w * b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     */
+    public void div(Short4 a) {
+        this.x /= a.x;
+        this.y /= a.y;
+        this.z /= a.z;
+        this.w /= a.w;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 div(Short4 a, Short4 b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x / b.x);
+        result.y = (short)(a.y / b.y);
+        result.z = (short)(a.z / b.z);
+        result.w = (short)(a.w / b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param value
+     */
+    public void div(short value) {
+        x /= value;
+        y /= value;
+        z /= value;
+        w /= value;
+    }
+
+    /** @hide
+     * Vector division
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 div(Short4 a, short b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x / b);
+        result.y = (short)(a.y / b);
+        result.z = (short)(a.z / b);
+        result.w = (short)(a.w / b);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     */
+    public void mod(Short4 a) {
+        this.x %= a.x;
+        this.y %= a.y;
+        this.z %= a.z;
+        this.w %= a.w;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 mod(Short4 a, Short4 b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x % b.x);
+        result.y = (short)(a.y % b.y);
+        result.z = (short)(a.z % b.z);
+        result.w = (short)(a.w % b.w);
+
+        return result;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param value
+     */
+    public void mod(short value) {
+        x %= value;
+        y %= value;
+        z %= value;
+        w %= value;
+    }
+
+    /** @hide
+     * Vector Modulo
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static Short4 mod(Short4 a, short b) {
+        Short4 result = new Short4();
+        result.x = (short)(a.x % b);
+        result.y = (short)(a.y % b);
+        result.z = (short)(a.z % b);
+        result.w = (short)(a.w % b);
+
+        return result;
+    }
+
+    /** @hide
+     * get vector length
+     *
+     * @return
+     */
+    public short length() {
+        return 4;
+    }
+
+    /** @hide
+     * set vector negate
+     */
+    public void negate() {
+        this.x = (short)(-x);
+        this.y = (short)(-y);
+        this.z = (short)(-z);
+        this.w = (short)(-w);
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @return
+     */
+    public short dotProduct(Short4 a) {
+        return (short)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
+    }
+
+    /** @hide
+     * Vector dot Product
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static short dotProduct(Short4 a, Short4 b) {
+        return (short)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
+    }
+
+    /** @hide
+     * Vector add Multiple
+     *
+     * @param a
+     * @param factor
+     */
+    public void addMultiple(Short4 a, short factor) {
+        x += a.x * factor;
+        y += a.y * factor;
+        z += a.z * factor;
+        w += a.w * factor;
+    }
+
+    /** @hide
+     * set vector value by Short4
+     *
+     * @param a
+     */
+    public void set(Short4 a) {
+        this.x = a.x;
+        this.y = a.y;
+        this.z = a.z;
+        this.w = a.w;
+    }
+
+    /** @hide
+     * set the vector field value by Short
+     *
+     * @param a
+     * @param b
+     * @param c
+     * @param d
+     */
+    public void setValues(short a, short b, short c, short d) {
+        this.x = a;
+        this.y = b;
+        this.z = c;
+        this.w = d;
+    }
+
+    /** @hide
+     * return the element sum of vector
+     *
+     * @return
+     */
+    public short elementSum() {
+        return (short)(x + y + z + w);
+    }
+
+    /** @hide
+     * get the vector field value by index
+     *
+     * @param i
+     * @return
+     */
+    public short get(int i) {
+        switch (i) {
+        case 0:
+            return (short)(x);
+        case 1:
+            return (short)(y);
+        case 2:
+            return (short)(z);
+        case 3:
+            return (short)(w);
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * set the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void setAt(int i, short value) {
+        switch (i) {
+        case 0:
+            x = value;
+            return;
+        case 1:
+            y = value;
+            return;
+        case 2:
+            z = value;
+            return;
+        case 3:
+            w = value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * add the vector field value by index
+     *
+     * @param i
+     * @param value
+     */
+    public void addAt(int i, short value) {
+        switch (i) {
+        case 0:
+            x += value;
+            return;
+        case 1:
+            y += value;
+            return;
+        case 2:
+            z += value;
+            return;
+        case 3:
+            w += value;
+            return;
+        default:
+            throw new IndexOutOfBoundsException("Index: i");
+        }
+    }
+
+    /** @hide
+     * copy the vector to short array
+     *
+     * @param data
+     * @param offset
+     */
+    public void copyTo(short[] data, int offset) {
+        data[offset] = (short)(x);
+        data[offset + 1] = (short)(y);
+        data[offset + 2] = (short)(z);
+        data[offset + 3] = (short)(w);
+    }
 }
-
-
-
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index cbc4e5a..afba1a6 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -116,7 +116,7 @@
     gContextId             = _env->GetFieldID(_this, "mContext", "I");
 
     jclass bitmapClass = _env->FindClass("android/graphics/Bitmap");
-    gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "I");
+    gNativeBitmapID = _env->GetFieldID(bitmapClass, "mNativeBitmap", "J");
 }
 
 // ---------------------------------------------------------------------------
@@ -522,7 +522,7 @@
 nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+            (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
 
     bitmap.lockPixels();
@@ -538,7 +538,7 @@
 nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+            (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
 
     bitmap.lockPixels();
@@ -554,7 +554,7 @@
 nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint type, jint mip, jobject jbitmap, jint usage)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+            (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
 
     bitmap.lockPixels();
@@ -570,7 +570,7 @@
 nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+            (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
     int w = bitmap.width();
     int h = bitmap.height();
@@ -587,7 +587,7 @@
 nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc, jobject jbitmap)
 {
     SkBitmap const * nativeBitmap =
-            (SkBitmap const *)_env->GetIntField(jbitmap, gNativeBitmapID);
+            (SkBitmap const *)_env->GetLongField(jbitmap, gNativeBitmapID);
     const SkBitmap& bitmap(*nativeBitmap);
 
     bitmap.lockPixels();
diff --git a/include/androidfw/AssetManager.h b/include/androidfw/AssetManager.h
index d95b45e..a010957 100644
--- a/include/androidfw/AssetManager.h
+++ b/include/androidfw/AssetManager.h
@@ -92,7 +92,7 @@
      * then on success, *cookie is set to the value corresponding to the
      * newly-added asset source.
      */
-    bool addAssetPath(const String8& path, void** cookie);
+    bool addAssetPath(const String8& path, int32_t* cookie);
 
     /*                                                                       
      * Convenience for adding the standard system assets.  Uses the
@@ -103,17 +103,17 @@
     /*                                                                       
      * Iterate over the asset paths in this manager.  (Previously
      * added via addAssetPath() and addDefaultAssets().)  On first call,
-     * 'cookie' must be NULL, resulting in the first cookie being returned.
-     * Each next cookie will be returned there-after, until NULL indicating
+     * 'cookie' must be 0, resulting in the first cookie being returned.
+     * Each next cookie will be returned there-after, until -1 indicating
      * the end has been reached.
      */
-    void* nextAssetPath(void* cookie) const;
+    int32_t nextAssetPath(const int32_t cookie) const;
 
     /*                                                                       
      * Return an asset path in the manager.  'which' must be between 0 and
      * countAssetPaths().
      */
-    String8 getAssetPath(void* cookie) const;
+    String8 getAssetPath(const int32_t cookie) const;
 
     /*
      * Set the current locale and vendor.  The locale can change during
@@ -159,7 +159,7 @@
      * Explicit non-asset file.  The file explicitly named by the cookie (the
      * resource set to look in) and fileName will be opened and returned.
      */
-    Asset* openNonAsset(void* cookie, const char* fileName, AccessMode mode);
+    Asset* openNonAsset(const int32_t cookie, const char* fileName, AccessMode mode);
 
     /*
      * Open a directory within the asset hierarchy.
@@ -183,7 +183,7 @@
      *
      * To open the top-level directory, pass in "".
      */
-    AssetDir* openNonAssetDir(void* cookie, const char* dirName);
+    AssetDir* openNonAssetDir(const int32_t cookie, const char* dirName);
 
     /*
      * Get the type of a file in the asset hierarchy.  They will either
diff --git a/include/androidfw/ResourceTypes.h b/include/androidfw/ResourceTypes.h
index 97afa59..5151b06 100644
--- a/include/androidfw/ResourceTypes.h
+++ b/include/androidfw/ResourceTypes.h
@@ -1020,7 +1020,7 @@
     // attrs_manifest.xml.
     enum {
         CONFIG_MCC = ACONFIGURATION_MCC,
-        CONFIG_MNC = ACONFIGURATION_MCC,
+        CONFIG_MNC = ACONFIGURATION_MNC,
         CONFIG_LOCALE = ACONFIGURATION_LOCALE,
         CONFIG_TOUCHSCREEN = ACONFIGURATION_TOUCHSCREEN,
         CONFIG_KEYBOARD = ACONFIGURATION_KEYBOARD,
diff --git a/include/androidfw/ZipFileRO.h b/include/androidfw/ZipFileRO.h
index 547e36a..ad5be12 100644
--- a/include/androidfw/ZipFileRO.h
+++ b/include/androidfw/ZipFileRO.h
@@ -40,6 +40,8 @@
 #include <unistd.h>
 #include <time.h>
 
+typedef void* ZipArchiveHandle;
+
 namespace android {
 
 /*
@@ -51,18 +53,13 @@
 /*
  * Open a Zip archive for reading.
  *
- * We want "open" and "find entry by name" to be fast operations, and we
- * want to use as little memory as possible.  We memory-map the file,
- * and load a hash table with pointers to the filenames (which aren't
- * null-terminated).  The other fields are at a fixed offset from the
- * filename, so we don't need to extract those (but we do need to byte-read
- * and endian-swap them every time we want them).
+ * Implemented as a thin wrapper over system/core/libziparchive.
  *
- * To speed comparisons when doing a lookup by name, we could make the mapping
- * "private" (copy-on-write) and null-terminate the filenames after verifying
- * the record structure.  However, this requires a private mapping of
- * every page that the Central Directory touches.  Easier to tuck a copy
- * of the string length into the hash table entry.
+ * "open" and "find entry by name" are fast operations and use as little
+ * memory as possible.
+ *
+ * We also support fast iteration over all entries in the file (with a
+ * stable, but unspecified iteration order).
  *
  * NOTE: If this is used on file descriptors inherited from a fork() operation,
  * you must be on a platform that implements pread() to guarantee correctness
@@ -70,48 +67,44 @@
  */
 class ZipFileRO {
 public:
-    ZipFileRO()
-        : mFd(-1), mFileName(NULL), mFileLength(-1),
-          mDirectoryMap(NULL),
-          mNumEntries(-1), mDirectoryOffset(-1),
-          mHashTableSize(-1), mHashTable(NULL)
-        {}
-
-    ~ZipFileRO();
+    /* Zip compression methods we support */
+    enum {
+        kCompressStored     = 0,        // no compression
+        kCompressDeflated   = 8,        // standard deflate
+    };
 
     /*
      * Open an archive.
      */
-    status_t open(const char* zipFileName);
+    static ZipFileRO* open(const char* zipFileName);
 
     /*
      * Find an entry, by name.  Returns the entry identifier, or NULL if
      * not found.
-     *
-     * If two entries have the same name, one will be chosen at semi-random.
      */
-    ZipEntryRO findEntryByName(const char* fileName) const;
+    ZipEntryRO findEntryByName(const char* entryName) const;
+
+
+    /*
+     * Start iterating over the list of entries in the zip file. Requires
+     * a matching call to endIteration with the same cookie.
+     */
+    bool startIteration(void** cookie);
+
+    /**
+     * Return the next entry in iteration order, or NULL if there are no more
+     * entries in this archive.
+     */
+    ZipEntryRO nextEntry(void* cookie);
+
+    void endIteration(void* cookie);
+
+    void releaseEntry(ZipEntryRO entry) const;
 
     /*
      * Return the #of entries in the Zip archive.
      */
-    int getNumEntries(void) const {
-        return mNumEntries;
-    }
-
-    /*
-     * Return the Nth entry.  Zip file entries are not stored in sorted
-     * order, and updated entries may appear at the end, so anyone walking
-     * the archive needs to avoid making ordering assumptions.  We take
-     * that further by returning the Nth non-empty entry in the hash table
-     * rather than the Nth entry in the archive.
-     *
-     * Valid values are [0..numEntries).
-     *
-     * [This is currently O(n).  If it needs to be fast we can allocate an
-     * additional data structure or provide an iterator interface.]
-     */
-    ZipEntryRO findEntryByIndex(int idx) const;
+    int getNumEntries();
 
     /*
      * Copy the filename into the supplied buffer.  Returns 0 on success,
@@ -149,112 +142,27 @@
      *
      * Returns "true" on success.
      */
-    bool uncompressEntry(ZipEntryRO entry, void* buffer) const;
+    bool uncompressEntry(ZipEntryRO entry, void* buffer, size_t size) const;
 
     /*
      * Uncompress the data to an open file descriptor.
      */
     bool uncompressEntry(ZipEntryRO entry, int fd) const;
 
-    /* Zip compression methods we support */
-    enum {
-        kCompressStored     = 0,        // no compression
-        kCompressDeflated   = 8,        // standard deflate
-    };
-
-    /*
-     * Utility function: uncompress deflated data, buffer to buffer.
-     */
-    static bool inflateBuffer(void* outBuf, const void* inBuf,
-        size_t uncompLen, size_t compLen);
-
-    /*
-     * Utility function: uncompress deflated data, buffer to fd.
-     */
-    static bool inflateBuffer(int fd, const void* inBuf,
-        size_t uncompLen, size_t compLen);
-
-    /*
-     * Utility function to convert ZIP's time format to a timespec struct.
-     */
-    static inline void zipTimeToTimespec(long when, struct tm* timespec) {
-        const long date = when >> 16;
-        timespec->tm_year = ((date >> 9) & 0x7F) + 80; // Zip is years since 1980
-        timespec->tm_mon = (date >> 5) & 0x0F;
-        timespec->tm_mday = date & 0x1F;
-
-        timespec->tm_hour = (when >> 11) & 0x1F;
-        timespec->tm_min = (when >> 5) & 0x3F;
-        timespec->tm_sec = (when & 0x1F) << 1;
-    }
-
-    /*
-     * Some basic functions for raw data manipulation.  "LE" means
-     * Little Endian.
-     */
-    static inline unsigned short get2LE(const unsigned char* buf) {
-        return buf[0] | (buf[1] << 8);
-    }
-    static inline unsigned long get4LE(const unsigned char* buf) {
-        return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
-    }
+    ~ZipFileRO();
 
 private:
-    /* these are private and not defined */ 
+    /* these are private and not defined */
     ZipFileRO(const ZipFileRO& src);
     ZipFileRO& operator=(const ZipFileRO& src);
 
-    /* locate and parse the central directory */
-    bool mapCentralDirectory(void);
+    ZipFileRO(ZipArchiveHandle handle, char* fileName) : mHandle(handle),
+        mFileName(fileName)
+    {
+    }
 
-    /* parse the archive, prepping internal structures */
-    bool parseZipArchive(void);
-
-    /* add a new entry to the hash table */
-    void addToHash(const char* str, int strLen, unsigned int hash);
-
-    /* compute string hash code */
-    static unsigned int computeHash(const char* str, int len);
-
-    /* convert a ZipEntryRO back to a hash table index */
-    int entryToIndex(const ZipEntryRO entry) const;
-
-    /*
-     * One entry in the hash table.
-     */
-    typedef struct HashEntry {
-        const char*     name;
-        unsigned short  nameLen;
-        //unsigned int    hash;
-    } HashEntry;
-
-    /* open Zip archive */
-    int         mFd;
-
-    /* Lock for handling the file descriptor (seeks, etc) */
-    mutable Mutex mFdLock;
-
-    /* zip file name */
-    char*       mFileName;
-
-    /* length of file */
-    size_t      mFileLength;
-
-    /* mapped file */
-    FileMap*    mDirectoryMap;
-
-    /* number of entries in the Zip archive */
-    int         mNumEntries;
-
-    /* CD directory offset in the Zip archive */
-    off64_t     mDirectoryOffset;
-
-    /*
-     * We know how many entries are in the Zip archive, so we have a
-     * fixed-size hash table.  We probe for an empty slot.
-     */
-    int         mHashTableSize;
-    HashEntry*  mHashTable;
+    const ZipArchiveHandle mHandle;
+    char* mFileName;
 };
 
 }; // namespace android
diff --git a/include/androidfw/ZipUtils.h b/include/androidfw/ZipUtils.h
index 42c42b6..6bea25a 100644
--- a/include/androidfw/ZipUtils.h
+++ b/include/androidfw/ZipUtils.h
@@ -21,6 +21,7 @@
 #define __LIBS_ZIPUTILS_H
 
 #include <stdio.h>
+#include <time.h>
 
 namespace android {
 
@@ -33,9 +34,11 @@
      * General utility function for uncompressing "deflate" data from a file
      * to a buffer.
      */
+    static bool inflateToBuffer(FILE* fp, void* buf, long uncompressedLen,
+        long compressedLen);
     static bool inflateToBuffer(int fd, void* buf, long uncompressedLen,
         long compressedLen);
-    static bool inflateToBuffer(FILE* fp, void* buf, long uncompressedLen,
+    static bool inflateToBuffer(void *in, void* buf, long uncompressedLen,
         long compressedLen);
 
     /*
@@ -57,6 +60,19 @@
     static bool examineGzip(FILE* fp, int* pCompressionMethod,
         long* pUncompressedLen, long* pCompressedLen, unsigned long* pCRC32);
 
+    /*
+     * Utility function to convert ZIP's time format to a timespec struct.
+     */
+    static inline void zipTimeToTimespec(long when, struct tm* timespec) {
+        const long date = when >> 16;
+        timespec->tm_year = ((date >> 9) & 0x7F) + 80; // Zip is years since 1980
+        timespec->tm_mon = (date >> 5) & 0x0F;
+        timespec->tm_mday = date & 0x1F;
+
+        timespec->tm_hour = (when >> 11) & 0x1F;
+        timespec->tm_min = (when >> 5) & 0x3F;
+        timespec->tm_sec = (when & 0x1F) << 1;
+    }
 private:
     ZipUtils() {}
     ~ZipUtils() {}
diff --git a/libs/androidfw/Android.mk b/libs/androidfw/Android.mk
index d80612b..d21197e 100644
--- a/libs/androidfw/Android.mk
+++ b/libs/androidfw/Android.mk
@@ -53,7 +53,7 @@
 LOCAL_C_INCLUDES := \
 	external/zlib
 
-LOCAL_STATIC_LIBRARIES := liblog
+LOCAL_STATIC_LIBRARIES := liblog libziparchive-host libutils
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
@@ -72,9 +72,12 @@
 	libutils \
 	libz
 
+LOCAL_STATIC_LIBRARIES := libziparchive
+
 LOCAL_C_INCLUDES := \
     external/icu4c/common \
-	external/zlib
+    external/zlib \
+    system/core/include
 
 LOCAL_MODULE:= libandroidfw
 
diff --git a/libs/androidfw/Asset.cpp b/libs/androidfw/Asset.cpp
index cb7628d..ce6cc38 100644
--- a/libs/androidfw/Asset.cpp
+++ b/libs/androidfw/Asset.cpp
@@ -843,7 +843,7 @@
  * The first time this is called, we expand the compressed data into a
  * buffer.
  */
-const void* _CompressedAsset::getBuffer(bool wordAligned)
+const void* _CompressedAsset::getBuffer(bool)
 {
     unsigned char* buf = NULL;
 
@@ -860,7 +860,7 @@
     }
 
     if (mMap != NULL) {
-        if (!ZipFileRO::inflateBuffer(buf, mMap->getDataPtr(),
+        if (!ZipUtils::inflateToBuffer(mMap->getDataPtr(), buf,
                 mUncompressedLen, mCompressedLen))
             goto bail;
     } else {
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index 6667daf..52ab361 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -165,7 +165,7 @@
     delete[] mVendor;
 }
 
-bool AssetManager::addAssetPath(const String8& path, void** cookie)
+bool AssetManager::addAssetPath(const String8& path, int32_t* cookie)
 {
     AutoMutex _l(mLock);
 
@@ -192,7 +192,7 @@
     for (size_t i=0; i<mAssetPaths.size(); i++) {
         if (mAssetPaths[i].path == ap.path) {
             if (cookie) {
-                *cookie = (void*)(i+1);
+                *cookie = static_cast<int32_t>(i+1);
             }
             return true;
         }
@@ -205,7 +205,7 @@
 
     // new paths are always added at the end
     if (cookie) {
-        *cookie = (void*)mAssetPaths.size();
+        *cookie = static_cast<int32_t>(mAssetPaths.size());
     }
 
     // add overlay packages for /system/framework; apps are handled by the
@@ -305,10 +305,11 @@
     if (entry == NULL) {
         return false;
     }
-    if (!zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)pCrc)) {
-        return false;
-    }
-    return true;
+
+    const bool gotInfo = zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)pCrc);
+    zip->releaseEntry(entry);
+
+    return gotInfo;
 }
 
 bool AssetManager::createIdmapFileLocked(const String8& originalPath, const String8& overlayPath,
@@ -394,17 +395,17 @@
     return addAssetPath(path, NULL);
 }
 
-void* AssetManager::nextAssetPath(void* cookie) const
+int32_t AssetManager::nextAssetPath(const int32_t cookie) const
 {
     AutoMutex _l(mLock);
-    size_t next = ((size_t)cookie)+1;
-    return next > mAssetPaths.size() ? NULL : (void*)next;
+    const size_t next = static_cast<size_t>(cookie) + 1;
+    return next > mAssetPaths.size() ? -1 : next;
 }
 
-String8 AssetManager::getAssetPath(void* cookie) const
+String8 AssetManager::getAssetPath(const int32_t cookie) const
 {
     AutoMutex _l(mLock);
-    const size_t which = ((size_t)cookie)-1;
+    const size_t which = static_cast<size_t>(cookie) - 1;
     if (which < mAssetPaths.size()) {
         return mAssetPaths[which].path;
     }
@@ -432,7 +433,7 @@
         delete[] mLocale;
     }
     mLocale = strdupNew(locale);
-    
+
     updateResourceParamsLocked();
 }
 
@@ -574,15 +575,14 @@
     return NULL;
 }
 
-Asset* AssetManager::openNonAsset(void* cookie, const char* fileName, AccessMode mode)
+Asset* AssetManager::openNonAsset(const int32_t cookie, const char* fileName, AccessMode mode)
 {
-    const size_t which = ((size_t)cookie)-1;
+    const size_t which = static_cast<size_t>(cookie) - 1;
 
     AutoMutex _l(mLock);
 
     LOG_FATAL_IF(mAssetPaths.size() == 0, "No assets added to AssetManager");
 
-
     if (mCacheMode != CACHE_OFF && !mCacheValid)
         loadFileNameCacheLocked();
 
@@ -675,7 +675,7 @@
                             mZipSet.setZipResourceTableAsset(ap.path, ass);
                     }
                 }
-                
+
                 if (i == 0 && ass != NULL) {
                     // If this is the first resource table in the asset
                     // manager, then we are going to cache it so that we
@@ -689,7 +689,7 @@
             }
         } else {
             ALOGV("loading resource table %s\n", ap.path.string());
-            Asset* ass = const_cast<AssetManager*>(this)->
+            ass = const_cast<AssetManager*>(this)->
                 openNonAssetInPathLocked("resources.arsc",
                                          Asset::ACCESS_BUFFER,
                                          ap);
@@ -821,16 +821,14 @@
         String8 path(fileName);
 
         /* check the appropriate Zip file */
-        ZipFileRO* pZip;
-        ZipEntryRO entry;
-
-        pZip = getZipFileLocked(ap);
+        ZipFileRO* pZip = getZipFileLocked(ap);
         if (pZip != NULL) {
             //printf("GOT zip, checking NA '%s'\n", (const char*) path);
-            entry = pZip->findEntryByName(path.string());
+            ZipEntryRO entry = pZip->findEntryByName(path.string());
             if (entry != NULL) {
                 //printf("FOUND NA in Zip file for %s\n", appName ? appName : kAppCommon);
                 pAsset = openAssetFromZipLocked(pZip, entry, mode, path);
+                pZip->releaseEntry(entry);
             }
         }
 
@@ -891,7 +889,7 @@
             /* look at the filesystem on disk */
             String8 path(createPathNameLocked(ap, locale, vendor));
             path.appendPath(fileName);
-    
+
             String8 excludeName(path);
             excludeName.append(kExcludeExtension);
             if (::getFileType(excludeName.string()) != kFileTypeNonexistent) {
@@ -899,28 +897,28 @@
                 //printf("+++ excluding '%s'\n", (const char*) excludeName);
                 return kExcludedAsset;
             }
-    
+
             pAsset = openAssetFromFileLocked(path, mode);
-    
+
             if (pAsset == NULL) {
                 /* try again, this time with ".gz" */
                 path.append(".gz");
                 pAsset = openAssetFromFileLocked(path, mode);
             }
-    
+
             if (pAsset != NULL)
                 pAsset->setAssetSource(path);
         } else {
             /* find in cache */
             String8 path(createPathNameLocked(ap, locale, vendor));
             path.appendPath(fileName);
-    
+
             AssetDir::FileInfo tmpInfo;
             bool found = false;
-    
+
             String8 excludeName(path);
             excludeName.append(kExcludeExtension);
-    
+
             if (mCache.indexOf(excludeName) != NAME_NOT_FOUND) {
                 /* go no farther */
                 //printf("+++ Excluding '%s'\n", (const char*) excludeName);
@@ -975,17 +973,15 @@
         path.appendPath(fileName);
 
         /* check the appropriate Zip file */
-        ZipFileRO* pZip;
-        ZipEntryRO entry;
-
-        pZip = getZipFileLocked(ap);
+        ZipFileRO* pZip = getZipFileLocked(ap);
         if (pZip != NULL) {
             //printf("GOT zip, checking '%s'\n", (const char*) path);
-            entry = pZip->findEntryByName(path.string());
+            ZipEntryRO entry = pZip->findEntryByName(path.string());
             if (entry != NULL) {
                 //printf("FOUND in Zip file for %s/%s-%s\n",
                 //    appName, locale, vendor);
                 pAsset = openAssetFromZipLocked(pZip, entry, mode, path);
+                pZip->releaseEntry(entry);
             }
         }
 
@@ -1209,7 +1205,7 @@
  *
  * Pass in "" for the root dir.
  */
-AssetDir* AssetManager::openNonAssetDir(void* cookie, const char* dirName)
+AssetDir* AssetManager::openNonAssetDir(const int32_t cookie, const char* dirName)
 {
     AutoMutex _l(mLock);
 
@@ -1228,7 +1224,7 @@
 
     pMergedInfo = new SortedVector<AssetDir::FileInfo>;
 
-    const size_t which = ((size_t)cookie)-1;
+    const size_t which = static_cast<size_t>(cookie) - 1;
 
     if (which < mAssetPaths.size()) {
         const asset_path& ap = mAssetPaths.itemAt(which);
@@ -1487,11 +1483,16 @@
      * semantics.
      */
     int dirNameLen = dirName.length();
-    for (int i = 0; i < pZip->getNumEntries(); i++) {
-        ZipEntryRO entry;
+    void *iterationCookie;
+    if (!pZip->startIteration(&iterationCookie)) {
+        ALOGW("ZipFileRO::startIteration returned false");
+        return false;
+    }
+
+    ZipEntryRO entry;
+    while ((entry = pZip->nextEntry(iterationCookie)) != NULL) {
         char nameBuf[256];
 
-        entry = pZip->findEntryByIndex(i);
         if (pZip->getEntryFileName(entry, nameBuf, sizeof(nameBuf)) != 0) {
             // TODO: fix this if we expect to have long names
             ALOGE("ARGH: name too long?\n");
@@ -1541,6 +1542,8 @@
         }
     }
 
+    pZip->endIteration(iterationCookie);
+
     /*
      * Add the set of unique directories.
      */
@@ -1739,7 +1742,7 @@
 
     // XXX This is broken -- the filename cache needs to hold the base
     // asset path separately from its filename.
-    
+
     partialPath = createPathNameLocked(ap, locale, vendor);
     if (dirName[0] != '\0') {
         partialPath.appendPath(dirName);
@@ -1814,12 +1817,10 @@
       mResourceTableAsset(NULL), mResourceTable(NULL)
 {
     //ALOGI("Creating SharedZip %p %s\n", this, (const char*)mPath);
-    mZipFile = new ZipFileRO;
     ALOGV("+++ opening zip '%s'\n", mPath.string());
-    if (mZipFile->open(mPath.string()) != NO_ERROR) {
+    mZipFile = ZipFileRO::open(mPath.string());
+    if (mZipFile == NULL) {
         ALOGD("failed to open Zip archive '%s'\n", mPath.string());
-        delete mZipFile;
-        mZipFile = NULL;
     }
 }
 
diff --git a/libs/androidfw/ObbFile.cpp b/libs/androidfw/ObbFile.cpp
index 21e06c8..ec59f06 100644
--- a/libs/androidfw/ObbFile.cpp
+++ b/libs/androidfw/ObbFile.cpp
@@ -133,7 +133,7 @@
     {
         lseek64(fd, fileLength - kFooterTagSize, SEEK_SET);
 
-        char *footer = new char[kFooterTagSize];
+        char footer[kFooterTagSize];
         actual = TEMP_FAILURE_RETRY(read(fd, footer, kFooterTagSize));
         if (actual != kFooterTagSize) {
             ALOGW("couldn't read footer signature: %s\n", strerror(errno));
diff --git a/libs/androidfw/ZipFileRO.cpp b/libs/androidfw/ZipFileRO.cpp
index ec5f95c..1ab18ad 100644
--- a/libs/androidfw/ZipFileRO.cpp
+++ b/libs/androidfw/ZipFileRO.cpp
@@ -24,6 +24,7 @@
 #include <utils/Compat.h>
 #include <utils/misc.h>
 #include <utils/threads.h>
+#include <ziparchive/zip_archive.h>
 
 #include <zlib.h>
 
@@ -43,460 +44,55 @@
 
 using namespace android;
 
-/*
- * Zip file constants.
- */
-#define kEOCDSignature       0x06054b50
-#define kEOCDLen             22
-#define kEOCDDiskNumber      4               // number of the current disk
-#define kEOCDDiskNumberForCD 6               // disk number with the Central Directory
-#define kEOCDNumEntries      8               // offset to #of entries in file
-#define kEOCDTotalNumEntries 10              // offset to total #of entries in spanned archives
-#define kEOCDSize            12              // size of the central directory
-#define kEOCDFileOffset      16              // offset to central directory
-#define kEOCDCommentSize     20              // offset to the length of the file comment
+class _ZipEntryRO {
+public:
+    ZipEntry entry;
+    ZipEntryName name;
+    void *cookie;
 
-#define kMaxCommentLen       65535           // longest possible in ushort
-#define kMaxEOCDSearch       (kMaxCommentLen + kEOCDLen)
+    _ZipEntryRO() : cookie(NULL) {
+    }
 
-#define kLFHSignature        0x04034b50
-#define kLFHLen              30              // excluding variable-len fields
-#define kLFHGPBFlags          6              // offset to GPB flags
-#define kLFHNameLen          26              // offset to filename length
-#define kLFHExtraLen         28              // offset to extra length
-
-#define kCDESignature        0x02014b50
-#define kCDELen              46              // excluding variable-len fields
-#define kCDEGPBFlags          8              // offset to GPB flags
-#define kCDEMethod           10              // offset to compression method
-#define kCDEModWhen          12              // offset to modification timestamp
-#define kCDECRC              16              // offset to entry CRC
-#define kCDECompLen          20              // offset to compressed length
-#define kCDEUncompLen        24              // offset to uncompressed length
-#define kCDENameLen          28              // offset to filename length
-#define kCDEExtraLen         30              // offset to extra length
-#define kCDECommentLen       32              // offset to comment length
-#define kCDELocalOffset      42              // offset to local hdr
-
-/* General Purpose Bit Flag */
-#define kGPFEncryptedFlag    (1 << 0)
-#define kGPFUnsupportedMask  (kGPFEncryptedFlag)
-
-/*
- * The values we return for ZipEntryRO use 0 as an invalid value, so we
- * want to adjust the hash table index by a fixed amount.  Using a large
- * value helps insure that people don't mix & match arguments, e.g. to
- * findEntryByIndex().
- */
-#define kZipEntryAdj        10000
+private:
+    _ZipEntryRO(const _ZipEntryRO& other);
+    _ZipEntryRO& operator=(const _ZipEntryRO& other);
+};
 
 ZipFileRO::~ZipFileRO() {
-    free(mHashTable);
-    if (mDirectoryMap)
-        mDirectoryMap->release();
-    if (mFd >= 0)
-        TEMP_FAILURE_RETRY(close(mFd));
-    if (mFileName)
-        free(mFileName);
+    CloseArchive(mHandle);
+    free(mFileName);
 }
 
 /*
- * Convert a ZipEntryRO to a hash table index, verifying that it's in a
- * valid range.
- */
-int ZipFileRO::entryToIndex(const ZipEntryRO entry) const
-{
-    long ent = ((intptr_t) entry) - kZipEntryAdj;
-    if (ent < 0 || ent >= mHashTableSize || mHashTable[ent].name == NULL) {
-        ALOGW("Invalid ZipEntryRO %p (%ld)\n", entry, ent);
-        return -1;
-    }
-    return ent;
-}
-
-
-/*
  * Open the specified file read-only.  We memory-map the entire thing and
  * close the file before returning.
  */
-status_t ZipFileRO::open(const char* zipFileName)
+/* static */ ZipFileRO* ZipFileRO::open(const char* zipFileName)
 {
-    int fd = -1;
-
-    assert(mDirectoryMap == NULL);
-
-    /*
-     * Open and map the specified file.
-     */
-    fd = TEMP_FAILURE_RETRY(::open(zipFileName, O_RDONLY | O_BINARY));
-    if (fd < 0) {
-        ALOGW("Unable to open zip '%s': %s\n", zipFileName, strerror(errno));
-        return NAME_NOT_FOUND;
-    }
-
-    mFileLength = lseek64(fd, 0, SEEK_END);
-    if (mFileLength < kEOCDLen) {
-        TEMP_FAILURE_RETRY(close(fd));
-        return UNKNOWN_ERROR;
-    }
-
-    if (mFileName != NULL) {
-        free(mFileName);
-    }
-    mFileName = strdup(zipFileName);
-
-    mFd = fd;
-
-    /*
-     * Find the Central Directory and store its size and number of entries.
-     */
-    if (!mapCentralDirectory()) {
-        goto bail;
-    }
-
-    /*
-     * Verify Central Directory and create data structures for fast access.
-     */
-    if (!parseZipArchive()) {
-        goto bail;
-    }
-
-    return OK;
-
-bail:
-    free(mFileName);
-    mFileName = NULL;
-    TEMP_FAILURE_RETRY(close(fd));
-    return UNKNOWN_ERROR;
-}
-
-/*
- * Parse the Zip archive, verifying its contents and initializing internal
- * data structures.
- */
-bool ZipFileRO::mapCentralDirectory(void)
-{
-    ssize_t readAmount = kMaxEOCDSearch;
-    if (readAmount > (ssize_t) mFileLength)
-        readAmount = mFileLength;
-
-    if (readAmount < kEOCDSize) {
-        ALOGW("File too short to be a zip file");
-        return false;
-    }
-
-    unsigned char* scanBuf = (unsigned char*) malloc(readAmount);
-    if (scanBuf == NULL) {
-        ALOGW("couldn't allocate scanBuf: %s", strerror(errno));
-        free(scanBuf);
-        return false;
-    }
-
-    /*
-     * Make sure this is a Zip archive.
-     */
-    if (lseek64(mFd, 0, SEEK_SET) != 0) {
-        ALOGW("seek to start failed: %s", strerror(errno));
-        free(scanBuf);
-        return false;
-    }
-
-    ssize_t actual = TEMP_FAILURE_RETRY(read(mFd, scanBuf, sizeof(int32_t)));
-    if (actual != (ssize_t) sizeof(int32_t)) {
-        ALOGI("couldn't read first signature from zip archive: %s", strerror(errno));
-        free(scanBuf);
-        return false;
-    }
-
-    unsigned int header = get4LE(scanBuf);
-    if (header != kLFHSignature) {
-        ALOGV("Not a Zip archive (found 0x%08x)\n", header);
-        free(scanBuf);
-        return false;
-    }
-
-    /*
-     * Perform the traditional EOCD snipe hunt.
-     *
-     * We're searching for the End of Central Directory magic number,
-     * which appears at the start of the EOCD block.  It's followed by
-     * 18 bytes of EOCD stuff and up to 64KB of archive comment.  We
-     * need to read the last part of the file into a buffer, dig through
-     * it to find the magic number, parse some values out, and use those
-     * to determine the extent of the CD.
-     *
-     * We start by pulling in the last part of the file.
-     */
-    off64_t searchStart = mFileLength - readAmount;
-
-    if (lseek64(mFd, searchStart, SEEK_SET) != searchStart) {
-        ALOGW("seek %ld failed: %s\n",  (long) searchStart, strerror(errno));
-        free(scanBuf);
-        return false;
-    }
-    actual = TEMP_FAILURE_RETRY(read(mFd, scanBuf, readAmount));
-    if (actual != (ssize_t) readAmount) {
-        ALOGW("Zip: read " ZD ", expected " ZD ". Failed: %s\n",
-            (ZD_TYPE) actual, (ZD_TYPE) readAmount, strerror(errno));
-        free(scanBuf);
-        return false;
-    }
-
-    /*
-     * Scan backward for the EOCD magic.  In an archive without a trailing
-     * comment, we'll find it on the first try.  (We may want to consider
-     * doing an initial minimal read; if we don't find it, retry with a
-     * second read as above.)
-     */
-    int i;
-    for (i = readAmount - kEOCDLen; i >= 0; i--) {
-        if (scanBuf[i] == 0x50 && get4LE(&scanBuf[i]) == kEOCDSignature) {
-            ALOGV("+++ Found EOCD at buf+%d\n", i);
-            break;
-        }
-    }
-    if (i < 0) {
-        ALOGD("Zip: EOCD not found, %s is not zip\n", mFileName);
-        free(scanBuf);
-        return false;
-    }
-
-    off64_t eocdOffset = searchStart + i;
-    const unsigned char* eocdPtr = scanBuf + i;
-
-    assert(eocdOffset < mFileLength);
-
-    /*
-     * Grab the CD offset and size, and the number of entries in the
-     * archive. After that, we can release our EOCD hunt buffer.
-     */
-    unsigned int diskNumber = get2LE(eocdPtr + kEOCDDiskNumber);
-    unsigned int diskWithCentralDir = get2LE(eocdPtr + kEOCDDiskNumberForCD);
-    unsigned int numEntries = get2LE(eocdPtr + kEOCDNumEntries);
-    unsigned int totalNumEntries = get2LE(eocdPtr + kEOCDTotalNumEntries);
-    unsigned int centralDirSize = get4LE(eocdPtr + kEOCDSize);
-    unsigned int centralDirOffset = get4LE(eocdPtr + kEOCDFileOffset);
-    unsigned int commentSize = get2LE(eocdPtr + kEOCDCommentSize);
-    free(scanBuf);
-
-    // Verify that they look reasonable.
-    if ((long long) centralDirOffset + (long long) centralDirSize > (long long) eocdOffset) {
-        ALOGW("bad offsets (dir %ld, size %u, eocd %ld)\n",
-            (long) centralDirOffset, centralDirSize, (long) eocdOffset);
-        return false;
-    }
-    if (numEntries == 0) {
-        ALOGW("empty archive?\n");
-        return false;
-    } else if (numEntries != totalNumEntries || diskNumber != 0 || diskWithCentralDir != 0) {
-        ALOGW("spanned archives not supported");
-        return false;
-    }
-
-    // Check to see if comment is a sane size
-    if ((commentSize > (mFileLength - kEOCDLen))
-            || (eocdOffset > (mFileLength - kEOCDLen) - commentSize)) {
-        ALOGW("comment size runs off end of file");
-        return false;
-    }
-
-    ALOGV("+++ numEntries=%d dirSize=%d dirOffset=%d\n",
-        numEntries, centralDirSize, centralDirOffset);
-
-    mDirectoryMap = new FileMap();
-    if (mDirectoryMap == NULL) {
-        ALOGW("Unable to create directory map: %s", strerror(errno));
-        return false;
-    }
-
-    if (!mDirectoryMap->create(mFileName, mFd, centralDirOffset, centralDirSize, true)) {
-        ALOGW("Unable to map '%s' (" ZD " to " ZD "): %s\n", mFileName,
-                (ZD_TYPE) centralDirOffset, (ZD_TYPE) (centralDirOffset + centralDirSize), strerror(errno));
-        return false;
-    }
-
-    mNumEntries = numEntries;
-    mDirectoryOffset = centralDirOffset;
-
-    return true;
-}
-
-
-/*
- * Round up to the next highest power of 2.
- *
- * Found on http://graphics.stanford.edu/~seander/bithacks.html.
- */
-static unsigned int roundUpPower2(unsigned int val)
-{
-    val--;
-    val |= val >> 1;
-    val |= val >> 2;
-    val |= val >> 4;
-    val |= val >> 8;
-    val |= val >> 16;
-    val++;
-
-    return val;
-}
-
-bool ZipFileRO::parseZipArchive(void)
-{
-    bool result = false;
-    const unsigned char* cdPtr = (const unsigned char*) mDirectoryMap->getDataPtr();
-    size_t cdLength = mDirectoryMap->getDataLength();
-    int numEntries = mNumEntries;
-
-    /*
-     * Create hash table.  We have a minimum 75% load factor, possibly as
-     * low as 50% after we round off to a power of 2.
-     */
-    mHashTableSize = roundUpPower2(1 + (numEntries * 4) / 3);
-    mHashTable = (HashEntry*) calloc(mHashTableSize, sizeof(HashEntry));
-
-    /*
-     * Walk through the central directory, adding entries to the hash
-     * table.
-     */
-    const unsigned char* ptr = cdPtr;
-    for (int i = 0; i < numEntries; i++) {
-        if (get4LE(ptr) != kCDESignature) {
-            ALOGW("Missed a central dir sig (at %d)\n", i);
-            goto bail;
-        }
-        if (ptr + kCDELen > cdPtr + cdLength) {
-            ALOGW("Ran off the end (at %d)\n", i);
-            goto bail;
-        }
-
-        long localHdrOffset = (long) get4LE(ptr + kCDELocalOffset);
-        if (localHdrOffset >= mDirectoryOffset) {
-            ALOGW("bad LFH offset %ld at entry %d\n", localHdrOffset, i);
-            goto bail;
-        }
-
-        unsigned int gpbf = get2LE(ptr + kCDEGPBFlags);
-        if ((gpbf & kGPFUnsupportedMask) != 0) {
-            ALOGW("Invalid General Purpose Bit Flag: %d", gpbf);
-            goto bail;
-        }
-
-        unsigned int nameLen = get2LE(ptr + kCDENameLen);
-        unsigned int extraLen = get2LE(ptr + kCDEExtraLen);
-        unsigned int commentLen = get2LE(ptr + kCDECommentLen);
-
-        const char *name = (const char *) ptr + kCDELen;
-
-        /* Check name for NULL characters */
-        if (memchr(name, 0, nameLen) != NULL) {
-            ALOGW("Filename contains NUL byte");
-            goto bail;
-        }
-
-        /* add the CDE filename to the hash table */
-        unsigned int hash = computeHash(name, nameLen);
-        addToHash(name, nameLen, hash);
-
-        /* We don't care about the comment or extra data. */
-        ptr += kCDELen + nameLen + extraLen + commentLen;
-        if ((size_t)(ptr - cdPtr) > cdLength) {
-            ALOGW("bad CD advance (%d vs " ZD ") at entry %d\n",
-                (int) (ptr - cdPtr), (ZD_TYPE) cdLength, i);
-            goto bail;
-        }
-    }
-    ALOGV("+++ zip good scan %d entries\n", numEntries);
-    result = true;
-
-bail:
-    return result;
-}
-
-/*
- * Simple string hash function for non-null-terminated strings.
- */
-/*static*/ unsigned int ZipFileRO::computeHash(const char* str, int len)
-{
-    unsigned int hash = 0;
-
-    while (len--)
-        hash = hash * 31 + *str++;
-
-    return hash;
-}
-
-/*
- * Add a new entry to the hash table.
- */
-void ZipFileRO::addToHash(const char* str, int strLen, unsigned int hash)
-{
-    int ent = hash & (mHashTableSize-1);
-
-    /*
-     * We over-allocate the table, so we're guaranteed to find an empty slot.
-     */
-    while (mHashTable[ent].name != NULL)
-        ent = (ent + 1) & (mHashTableSize-1);
-
-    mHashTable[ent].name = str;
-    mHashTable[ent].nameLen = strLen;
-}
-
-/*
- * Find a matching entry.
- *
- * Returns NULL if not found.
- */
-ZipEntryRO ZipFileRO::findEntryByName(const char* fileName) const
-{
-    /*
-     * If the ZipFileRO instance is not initialized, the entry number will
-     * end up being garbage since mHashTableSize is -1.
-     */
-    if (mHashTableSize <= 0) {
+    ZipArchiveHandle handle;
+    const int32_t error = OpenArchive(zipFileName, &handle);
+    if (error) {
+        ALOGW("Error opening archive %s: %s", zipFileName, ErrorCodeString(error));
         return NULL;
     }
 
-    int nameLen = strlen(fileName);
-    unsigned int hash = computeHash(fileName, nameLen);
-    int ent = hash & (mHashTableSize-1);
-
-    while (mHashTable[ent].name != NULL) {
-        if (mHashTable[ent].nameLen == nameLen &&
-            memcmp(mHashTable[ent].name, fileName, nameLen) == 0)
-        {
-            /* match */
-            return (ZipEntryRO)(long)(ent + kZipEntryAdj);
-        }
-
-        ent = (ent + 1) & (mHashTableSize-1);
-    }
-
-    return NULL;
+    return new ZipFileRO(handle, strdup(zipFileName));
 }
 
-/*
- * Find the Nth entry.
- *
- * This currently involves walking through the sparse hash table, counting
- * non-empty entries.  If we need to speed this up we can either allocate
- * a parallel lookup table or (perhaps better) provide an iterator interface.
- */
-ZipEntryRO ZipFileRO::findEntryByIndex(int idx) const
+
+ZipEntryRO ZipFileRO::findEntryByName(const char* entryName) const
 {
-    if (idx < 0 || idx >= mNumEntries) {
-        ALOGW("Invalid index %d\n", idx);
+    _ZipEntryRO* data = new _ZipEntryRO;
+    const int32_t error = FindEntry(mHandle, entryName, &(data->entry));
+    if (error) {
+        delete data;
         return NULL;
     }
 
-    for (int ent = 0; ent < mHashTableSize; ent++) {
-        if (mHashTable[ent].name != NULL) {
-            if (idx-- == 0)
-                return (ZipEntryRO) (intptr_t)(ent + kZipEntryAdj);
-        }
-    }
+    data->name.name = entryName;
+    data->name.name_length = strlen(entryName);
 
-    return NULL;
+    return (ZipEntryRO) data;
 }
 
 /*
@@ -508,172 +104,86 @@
 bool ZipFileRO::getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen,
     size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32) const
 {
-    bool ret = false;
+    const _ZipEntryRO* zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
+    const ZipEntry& ze = zipEntry->entry;
 
-    const int ent = entryToIndex(entry);
-    if (ent < 0) {
-        ALOGW("cannot find entry");
-        return false;
+    if (pMethod != NULL) {
+        *pMethod = ze.method;
     }
-
-    HashEntry hashEntry = mHashTable[ent];
-
-    /*
-     * Recover the start of the central directory entry from the filename
-     * pointer.  The filename is the first entry past the fixed-size data,
-     * so we can just subtract back from that.
-     */
-    const unsigned char* ptr = (const unsigned char*) hashEntry.name;
-    off64_t cdOffset = mDirectoryOffset;
-
-    ptr -= kCDELen;
-
-    int method = get2LE(ptr + kCDEMethod);
-    if (pMethod != NULL)
-        *pMethod = method;
-
-    if (pModWhen != NULL)
-        *pModWhen = get4LE(ptr + kCDEModWhen);
-    if (pCrc32 != NULL)
-        *pCrc32 = get4LE(ptr + kCDECRC);
-
-    size_t compLen = get4LE(ptr + kCDECompLen);
-    if (pCompLen != NULL)
-        *pCompLen = compLen;
-    size_t uncompLen = get4LE(ptr + kCDEUncompLen);
-    if (pUncompLen != NULL)
-        *pUncompLen = uncompLen;
-
-    /*
-     * If requested, determine the offset of the start of the data.  All we
-     * have is the offset to the Local File Header, which is variable size,
-     * so we have to read the contents of the struct to figure out where
-     * the actual data starts.
-     *
-     * We also need to make sure that the lengths are not so large that
-     * somebody trying to map the compressed or uncompressed data runs
-     * off the end of the mapped region.
-     *
-     * Note we don't verify compLen/uncompLen if they don't request the
-     * dataOffset, because dataOffset is expensive to determine.  However,
-     * if they don't have the file offset, they're not likely to be doing
-     * anything with the contents.
-     */
+    if (pUncompLen != NULL) {
+        *pUncompLen = ze.uncompressed_length;
+    }
+    if (pCompLen != NULL) {
+        *pCompLen = ze.compressed_length;
+    }
     if (pOffset != NULL) {
-        long localHdrOffset = get4LE(ptr + kCDELocalOffset);
-        if (localHdrOffset + kLFHLen >= cdOffset) {
-            ALOGE("ERROR: bad local hdr offset in zip\n");
-            return false;
-        }
-
-        unsigned char lfhBuf[kLFHLen];
-
-#ifdef HAVE_PREAD
-        /*
-         * This file descriptor might be from zygote's preloaded assets,
-         * so we need to do an pread64() instead of a lseek64() + read() to
-         * guarantee atomicity across the processes with the shared file
-         * descriptors.
-         */
-        ssize_t actual =
-                TEMP_FAILURE_RETRY(pread64(mFd, lfhBuf, sizeof(lfhBuf), localHdrOffset));
-
-        if (actual != sizeof(lfhBuf)) {
-            ALOGW("failed reading lfh from offset %ld\n", localHdrOffset);
-            return false;
-        }
-
-        if (get4LE(lfhBuf) != kLFHSignature) {
-            ALOGW("didn't find signature at start of lfh; wanted: offset=%ld data=0x%08x; "
-                    "got: data=0x%08lx\n",
-                    localHdrOffset, kLFHSignature, get4LE(lfhBuf));
-            return false;
-        }
-#else /* HAVE_PREAD */
-        /*
-         * For hosts don't have pread64() we cannot guarantee atomic reads from
-         * an offset in a file. Android should never run on those platforms.
-         * File descriptors inherited from a fork() share file offsets and
-         * there would be nothing to protect from two different processes
-         * calling lseek64() concurrently.
-         */
-
-        {
-            AutoMutex _l(mFdLock);
-
-            if (lseek64(mFd, localHdrOffset, SEEK_SET) != localHdrOffset) {
-                ALOGW("failed seeking to lfh at offset %ld\n", localHdrOffset);
-                return false;
-            }
-
-            ssize_t actual =
-                    TEMP_FAILURE_RETRY(read(mFd, lfhBuf, sizeof(lfhBuf)));
-            if (actual != sizeof(lfhBuf)) {
-                ALOGW("failed reading lfh from offset %ld\n", localHdrOffset);
-                return false;
-            }
-
-            if (get4LE(lfhBuf) != kLFHSignature) {
-                off64_t actualOffset = lseek64(mFd, 0, SEEK_CUR);
-                ALOGW("didn't find signature at start of lfh; wanted: offset=%ld data=0x%08x; "
-                        "got: offset=" ZD " data=0x%08lx\n",
-                        localHdrOffset, kLFHSignature, (ZD_TYPE) actualOffset, get4LE(lfhBuf));
-                return false;
-            }
-        }
-#endif /* HAVE_PREAD */
-
-        unsigned int gpbf = get2LE(lfhBuf + kLFHGPBFlags);
-        if ((gpbf & kGPFUnsupportedMask) != 0) {
-            ALOGW("Invalid General Purpose Bit Flag: %d", gpbf);
-            return false;
-        }
-
-        off64_t dataOffset = localHdrOffset + kLFHLen
-            + get2LE(lfhBuf + kLFHNameLen) + get2LE(lfhBuf + kLFHExtraLen);
-        if (dataOffset >= cdOffset) {
-            ALOGW("bad data offset %ld in zip\n", (long) dataOffset);
-            return false;
-        }
-
-        /* check lengths */
-        if ((dataOffset >= cdOffset) || (compLen > (cdOffset - dataOffset))) {
-            ALOGW("bad compressed length in zip (%ld + " ZD " > %ld)\n",
-                (long) dataOffset, (ZD_TYPE) compLen, (long) cdOffset);
-            return false;
-        }
-
-        if (method == kCompressStored &&
-            ((dataOffset >= cdOffset) ||
-             (uncompLen > (cdOffset - dataOffset))))
-        {
-            ALOGE("ERROR: bad uncompressed length in zip (%ld + " ZD " > %ld)\n",
-                (long) dataOffset, (ZD_TYPE) uncompLen, (long) cdOffset);
-            return false;
-        }
-
-        *pOffset = dataOffset;
+        *pOffset = ze.offset;
+    }
+    if (pModWhen != NULL) {
+        *pModWhen = ze.mod_time;
+    }
+    if (pCrc32 != NULL) {
+        *pCrc32 = ze.crc32;
     }
 
     return true;
 }
 
+bool ZipFileRO::startIteration(void** cookie)
+{
+    _ZipEntryRO* ze = new _ZipEntryRO;
+    int32_t error = StartIteration(mHandle, &(ze->cookie), NULL /* prefix */);
+    if (error) {
+        ALOGW("Could not start iteration over %s: %s", mFileName, ErrorCodeString(error));
+        delete ze;
+        return false;
+    }
+
+    *cookie = ze;
+    return true;
+}
+
+ZipEntryRO ZipFileRO::nextEntry(void* cookie)
+{
+    _ZipEntryRO* ze = reinterpret_cast<_ZipEntryRO*>(cookie);
+    int32_t error = Next(ze->cookie, &(ze->entry), &(ze->name));
+    if (error) {
+        if (error != -1) {
+            ALOGW("Error iteration over %s: %s", mFileName, ErrorCodeString(error));
+        }
+        return NULL;
+    }
+
+    return &(ze->entry);
+}
+
+void ZipFileRO::endIteration(void* cookie)
+{
+    delete reinterpret_cast<_ZipEntryRO*>(cookie);
+}
+
+void ZipFileRO::releaseEntry(ZipEntryRO entry) const
+{
+    delete reinterpret_cast<_ZipEntryRO*>(entry);
+}
+
 /*
  * Copy the entry's filename to the buffer.
  */
 int ZipFileRO::getEntryFileName(ZipEntryRO entry, char* buffer, int bufLen)
     const
 {
-    int ent = entryToIndex(entry);
-    if (ent < 0)
-        return -1;
+    const _ZipEntryRO* zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
+    const uint16_t requiredSize = zipEntry->name.name_length + 1;
 
-    int nameLen = mHashTable[ent].nameLen;
-    if (bufLen < nameLen+1)
-        return nameLen+1;
+    if (bufLen < requiredSize) {
+        ALOGW("Buffer too short, requires %d bytes for entry name", requiredSize);
+        return requiredSize;
+    }
 
-    memcpy(buffer, mHashTable[ent].name, nameLen);
-    buffer[nameLen] = '\0';
+    memcpy(buffer, zipEntry->name.name, requiredSize - 1);
+    buffer[requiredSize - 1] = '\0';
+
     return 0;
 }
 
@@ -682,32 +192,19 @@
  */
 FileMap* ZipFileRO::createEntryFileMap(ZipEntryRO entry) const
 {
-    /*
-     * TODO: the efficient way to do this is to modify FileMap to allow
-     * sub-regions of a file to be mapped.  A reference-counting scheme
-     * can manage the base memory mapping.  For now, we just create a brand
-     * new mapping off of the Zip archive file descriptor.
-     */
+    const _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
+    const ZipEntry& ze = zipEntry->entry;
+    int fd = GetFileDescriptor(mHandle);
+    size_t actualLen = 0;
 
-    FileMap* newMap;
-    int method;
-    size_t uncompLen;
-    size_t compLen;
-    off64_t offset;
-
-    if (!getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL)) {
-        return NULL;
-    }
-
-    size_t actualLen;
-    if (method == kCompressStored) {
-        actualLen = uncompLen;
+    if (ze.method == kCompressStored) {
+        actualLen = ze.uncompressed_length;
     } else {
-        actualLen = compLen;
+        actualLen = ze.compressed_length;
     }
 
-    newMap = new FileMap();
-    if (!newMap->create(mFileName, mFd, offset, actualLen, true)) {
+    FileMap* newMap = new FileMap();
+    if (!newMap->create(mFileName, fd, ze.offset, actualLen, true)) {
         newMap->release();
         return NULL;
     }
@@ -721,64 +218,17 @@
  * This doesn't verify the data's CRC, which might be useful for
  * uncompressed data.  The caller should be able to manage it.
  */
-bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer) const
+bool ZipFileRO::uncompressEntry(ZipEntryRO entry, void* buffer, size_t size) const
 {
-    const size_t kSequentialMin = 32768;
-    bool result = false;
-    int ent = entryToIndex(entry);
-    if (ent < 0) {
+    _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
+    const int32_t error = ExtractToMemory(mHandle, &(zipEntry->entry),
+        (uint8_t*) buffer, size);
+    if (error) {
+        ALOGW("ExtractToMemory failed with %s", ErrorCodeString(error));
         return false;
     }
 
-    int method;
-    size_t uncompLen, compLen;
-    off64_t offset;
-    const unsigned char* ptr;
-    FileMap *file;
-
-    if (!getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL)) {
-        goto bail;
-    }
-
-    file = createEntryFileMap(entry);
-    if (file == NULL) {
-        goto bail;
-    }
-
-    ptr = (const unsigned char*) file->getDataPtr();
-
-    /*
-     * Experiment with madvise hint.  When we want to uncompress a file,
-     * we pull some stuff out of the central dir entry and then hit a
-     * bunch of compressed or uncompressed data sequentially.  The CDE
-     * visit will cause a limited amount of read-ahead because it's at
-     * the end of the file.  We could end up doing lots of extra disk
-     * access if the file we're prying open is small.  Bottom line is we
-     * probably don't want to turn MADV_SEQUENTIAL on and leave it on.
-     *
-     * So, if the compressed size of the file is above a certain minimum
-     * size, temporarily boost the read-ahead in the hope that the extra
-     * pair of system calls are negated by a reduction in page faults.
-     */
-    if (compLen > kSequentialMin)
-        file->advise(FileMap::SEQUENTIAL);
-
-    if (method == kCompressStored) {
-        memcpy(buffer, ptr, uncompLen);
-    } else {
-        if (!inflateBuffer(buffer, ptr, uncompLen, compLen))
-            goto unmap;
-    }
-
-    if (compLen > kSequentialMin)
-        file->advise(FileMap::NORMAL);
-
-    result = true;
-
-unmap:
-    file->release();
-bail:
-    return result;
+    return true;
 }
 
 /*
@@ -788,208 +238,12 @@
  */
 bool ZipFileRO::uncompressEntry(ZipEntryRO entry, int fd) const
 {
-    bool result = false;
-    int ent = entryToIndex(entry);
-    if (ent < 0) {
+    _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry);
+    const int32_t error = ExtractEntryToFile(mHandle, &(zipEntry->entry), fd);
+    if (error) {
+        ALOGW("ExtractToMemory failed with %s", ErrorCodeString(error));
         return false;
     }
 
-    int method;
-    size_t uncompLen, compLen;
-    off64_t offset;
-    const unsigned char* ptr;
-    FileMap *file;
-
-    if (!getEntryInfo(entry, &method, &uncompLen, &compLen, &offset, NULL, NULL)) {
-        goto bail;
-    }
-
-    file = createEntryFileMap(entry);
-    if (file == NULL) {
-        goto bail;
-    }
-
-    ptr = (const unsigned char*) file->getDataPtr();
-
-    if (method == kCompressStored) {
-        ssize_t actual = TEMP_FAILURE_RETRY(write(fd, ptr, uncompLen));
-        if (actual < 0) {
-            ALOGE("Write failed: %s\n", strerror(errno));
-            goto unmap;
-        } else if ((size_t) actual != uncompLen) {
-            ALOGE("Partial write during uncompress (" ZD " of " ZD ")\n",
-                (ZD_TYPE) actual, (ZD_TYPE) uncompLen);
-            goto unmap;
-        } else {
-            ALOGI("+++ successful write\n");
-        }
-    } else {
-        if (!inflateBuffer(fd, ptr, uncompLen, compLen)) {
-            goto unmap;
-        }
-    }
-
-    result = true;
-
-unmap:
-    file->release();
-bail:
-    return result;
-}
-
-/*
- * Uncompress "deflate" data from one buffer to another.
- */
-/*static*/ bool ZipFileRO::inflateBuffer(void* outBuf, const void* inBuf,
-    size_t uncompLen, size_t compLen)
-{
-    bool result = false;
-    z_stream zstream;
-    int zerr;
-
-    /*
-     * Initialize the zlib stream struct.
-     */
-    memset(&zstream, 0, sizeof(zstream));
-    zstream.zalloc = Z_NULL;
-    zstream.zfree = Z_NULL;
-    zstream.opaque = Z_NULL;
-    zstream.next_in = (Bytef*)inBuf;
-    zstream.avail_in = compLen;
-    zstream.next_out = (Bytef*) outBuf;
-    zstream.avail_out = uncompLen;
-    zstream.data_type = Z_UNKNOWN;
-
-    /*
-     * Use the undocumented "negative window bits" feature to tell zlib
-     * that there's no zlib header waiting for it.
-     */
-    zerr = inflateInit2(&zstream, -MAX_WBITS);
-    if (zerr != Z_OK) {
-        if (zerr == Z_VERSION_ERROR) {
-            ALOGE("Installed zlib is not compatible with linked version (%s)\n",
-                ZLIB_VERSION);
-        } else {
-            ALOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
-        }
-        goto bail;
-    }
-
-    /*
-     * Expand data.
-     */
-    zerr = inflate(&zstream, Z_FINISH);
-    if (zerr != Z_STREAM_END) {
-        ALOGW("Zip inflate failed, zerr=%d (nIn=%p aIn=%u nOut=%p aOut=%u)\n",
-            zerr, zstream.next_in, zstream.avail_in,
-            zstream.next_out, zstream.avail_out);
-        goto z_bail;
-    }
-
-    /* paranoia */
-    if (zstream.total_out != uncompLen) {
-        ALOGW("Size mismatch on inflated file (%ld vs " ZD ")\n",
-            zstream.total_out, (ZD_TYPE) uncompLen);
-        goto z_bail;
-    }
-
-    result = true;
-
-z_bail:
-    inflateEnd(&zstream);        /* free up any allocated structures */
-
-bail:
-    return result;
-}
-
-/*
- * Uncompress "deflate" data from one buffer to an open file descriptor.
- */
-/*static*/ bool ZipFileRO::inflateBuffer(int fd, const void* inBuf,
-    size_t uncompLen, size_t compLen)
-{
-    bool result = false;
-    const size_t kWriteBufSize = 32768;
-    unsigned char writeBuf[kWriteBufSize];
-    z_stream zstream;
-    int zerr;
-
-    /*
-     * Initialize the zlib stream struct.
-     */
-    memset(&zstream, 0, sizeof(zstream));
-    zstream.zalloc = Z_NULL;
-    zstream.zfree = Z_NULL;
-    zstream.opaque = Z_NULL;
-    zstream.next_in = (Bytef*)inBuf;
-    zstream.avail_in = compLen;
-    zstream.next_out = (Bytef*) writeBuf;
-    zstream.avail_out = sizeof(writeBuf);
-    zstream.data_type = Z_UNKNOWN;
-
-    /*
-     * Use the undocumented "negative window bits" feature to tell zlib
-     * that there's no zlib header waiting for it.
-     */
-    zerr = inflateInit2(&zstream, -MAX_WBITS);
-    if (zerr != Z_OK) {
-        if (zerr == Z_VERSION_ERROR) {
-            ALOGE("Installed zlib is not compatible with linked version (%s)\n",
-                ZLIB_VERSION);
-        } else {
-            ALOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
-        }
-        goto bail;
-    }
-
-    /*
-     * Loop while we have more to do.
-     */
-    do {
-        /*
-         * Expand data.
-         */
-        zerr = inflate(&zstream, Z_NO_FLUSH);
-        if (zerr != Z_OK && zerr != Z_STREAM_END) {
-            ALOGW("zlib inflate: zerr=%d (nIn=%p aIn=%u nOut=%p aOut=%u)\n",
-                zerr, zstream.next_in, zstream.avail_in,
-                zstream.next_out, zstream.avail_out);
-            goto z_bail;
-        }
-
-        /* write when we're full or when we're done */
-        if (zstream.avail_out == 0 ||
-            (zerr == Z_STREAM_END && zstream.avail_out != sizeof(writeBuf)))
-        {
-            long writeSize = zstream.next_out - writeBuf;
-            int cc = TEMP_FAILURE_RETRY(write(fd, writeBuf, writeSize));
-            if (cc < 0) {
-                ALOGW("write failed in inflate: %s", strerror(errno));
-                goto z_bail;
-            } else if (cc != (int) writeSize) {
-                ALOGW("write failed in inflate (%d vs %ld)", cc, writeSize);
-                goto z_bail;
-            }
-
-            zstream.next_out = writeBuf;
-            zstream.avail_out = sizeof(writeBuf);
-        }
-    } while (zerr == Z_OK);
-
-    assert(zerr == Z_STREAM_END);       /* other errors should've been caught */
-
-    /* paranoia */
-    if (zstream.total_out != uncompLen) {
-        ALOGW("Size mismatch on inflated file (%ld vs " ZD ")\n",
-            zstream.total_out, (ZD_TYPE) uncompLen);
-        goto z_bail;
-    }
-
-    result = true;
-
-z_bail:
-    inflateEnd(&zstream);        /* free up any allocated structures */
-
-bail:
-    return result;
+    return true;
 }
diff --git a/libs/androidfw/ZipUtils.cpp b/libs/androidfw/ZipUtils.cpp
index 997eb7d..e9ac2fe 100644
--- a/libs/androidfw/ZipUtils.cpp
+++ b/libs/androidfw/ZipUtils.cpp
@@ -33,115 +33,13 @@
 
 using namespace android;
 
-/*
- * Utility function that expands zip/gzip "deflate" compressed data
- * into a buffer.
- *
- * "fd" is an open file positioned at the start of the "deflate" data
- * "buf" must hold at least "uncompressedLen" bytes.
- */
-/*static*/ bool ZipUtils::inflateToBuffer(int fd, void* buf,
-    long uncompressedLen, long compressedLen)
-{
-    bool result = false;
-	const unsigned long kReadBufSize = 32768;
-	unsigned char* readBuf = NULL;
-    z_stream zstream;
-    int zerr;
-    unsigned long compRemaining;
-
-    assert(uncompressedLen >= 0);
-    assert(compressedLen >= 0);
-
-	readBuf = new unsigned char[kReadBufSize];
-	if (readBuf == NULL)
-        goto bail;
-    compRemaining = compressedLen;
-
-    /*
-     * Initialize the zlib stream.
-     */
-	memset(&zstream, 0, sizeof(zstream));
-    zstream.zalloc = Z_NULL;
-    zstream.zfree = Z_NULL;
-    zstream.opaque = Z_NULL;
-    zstream.next_in = NULL;
-    zstream.avail_in = 0;
-    zstream.next_out = (Bytef*) buf;
-    zstream.avail_out = uncompressedLen;
-    zstream.data_type = Z_UNKNOWN;
-
-	/*
-	 * Use the undocumented "negative window bits" feature to tell zlib
-	 * that there's no zlib header waiting for it.
-	 */
-    zerr = inflateInit2(&zstream, -MAX_WBITS);
-    if (zerr != Z_OK) {
-        if (zerr == Z_VERSION_ERROR) {
-            ALOGE("Installed zlib is not compatible with linked version (%s)\n",
-                ZLIB_VERSION);
-        } else {
-            ALOGE("Call to inflateInit2 failed (zerr=%d)\n", zerr);
-        }
-        goto bail;
-    }
-
-    /*
-     * Loop while we have data.
-     */
-    do {
-        unsigned long getSize;
-
-        /* read as much as we can */
-        if (zstream.avail_in == 0) {
-            getSize = (compRemaining > kReadBufSize) ?
-                        kReadBufSize : compRemaining;
-            ALOGV("+++ reading %ld bytes (%ld left)\n",
-                getSize, compRemaining);
-
-            int cc = TEMP_FAILURE_RETRY(read(fd, readBuf, getSize));
-            if (cc < 0) {
-                ALOGW("inflate read failed: %s", strerror(errno));
-            } else if (cc != (int) getSize) {
-                ALOGW("inflate read failed (%d vs %ld)", cc, getSize);
-                goto z_bail;
-            }
-
-            compRemaining -= getSize;
-
-            zstream.next_in = readBuf;
-            zstream.avail_in = getSize;
-        }
-
-        /* uncompress the data */
-        zerr = inflate(&zstream, Z_NO_FLUSH);
-        if (zerr != Z_OK && zerr != Z_STREAM_END) {
-            ALOGD("zlib inflate call failed (zerr=%d)\n", zerr);
-            goto z_bail;
-        }
-
-		/* output buffer holds all, so no need to write the output */
-    } while (zerr == Z_OK);
-
-    assert(zerr == Z_STREAM_END);       /* other errors should've been caught */
-
-    if ((long) zstream.total_out != uncompressedLen) {
-        ALOGW("Size mismatch on inflated file (%ld vs %ld)\n",
-            zstream.total_out, uncompressedLen);
-        goto z_bail;
-    }
-
-    // success!
-    result = true;
-
-z_bail:
-    inflateEnd(&zstream);        /* free up any allocated structures */
-
-bail:
-	delete[] readBuf;
-    return result;
+static inline unsigned long get4LE(const unsigned char* buf) {
+    return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
 }
 
+
+static const unsigned long kReadBufSize = 32768;
+
 /*
  * Utility function that expands zip/gzip "deflate" compressed data
  * into a buffer.
@@ -153,12 +51,11 @@
  * "fp" is an open file positioned at the start of the "deflate" data
  * "buf" must hold at least "uncompressedLen" bytes.
  */
-/*static*/ bool ZipUtils::inflateToBuffer(FILE* fp, void* buf,
+/*static*/ template<typename T> bool inflateToBuffer(T& reader, void* buf,
     long uncompressedLen, long compressedLen)
 {
     bool result = false;
-	const unsigned long kReadBufSize = 32768;
-	unsigned char* readBuf = NULL;
+
     z_stream zstream;
     int zerr;
     unsigned long compRemaining;
@@ -166,15 +63,12 @@
     assert(uncompressedLen >= 0);
     assert(compressedLen >= 0);
 
-	readBuf = new unsigned char[kReadBufSize];
-	if (readBuf == NULL)
-        goto bail;
     compRemaining = compressedLen;
 
     /*
      * Initialize the zlib stream.
      */
-	memset(&zstream, 0, sizeof(zstream));
+    memset(&zstream, 0, sizeof(zstream));
     zstream.zalloc = Z_NULL;
     zstream.zfree = Z_NULL;
     zstream.opaque = Z_NULL;
@@ -184,10 +78,10 @@
     zstream.avail_out = uncompressedLen;
     zstream.data_type = Z_UNKNOWN;
 
-	/*
-	 * Use the undocumented "negative window bits" feature to tell zlib
-	 * that there's no zlib header waiting for it.
-	 */
+    /*
+     * Use the undocumented "negative window bits" feature to tell zlib
+     * that there's no zlib header waiting for it.
+     */
     zerr = inflateInit2(&zstream, -MAX_WBITS);
     if (zerr != Z_OK) {
         if (zerr == Z_VERSION_ERROR) {
@@ -212,17 +106,18 @@
             ALOGV("+++ reading %ld bytes (%ld left)\n",
                 getSize, compRemaining);
 
-            int cc = fread(readBuf, 1, getSize, fp);
-            if (cc != (int) getSize) {
-                ALOGD("inflate read failed (%d vs %ld)\n",
-                    cc, getSize);
+            unsigned char* nextBuffer = NULL;
+            const unsigned long nextSize = reader.read(&nextBuffer, getSize);
+
+            if (nextSize < getSize || nextBuffer == NULL) {
+                ALOGD("inflate read failed (%ld vs %ld)\n", nextSize, getSize);
                 goto z_bail;
             }
 
-            compRemaining -= getSize;
+            compRemaining -= nextSize;
 
-            zstream.next_in = readBuf;
-            zstream.avail_in = getSize;
+            zstream.next_in = nextBuffer;
+            zstream.avail_in = nextSize;
         }
 
         /* uncompress the data */
@@ -250,10 +145,100 @@
     inflateEnd(&zstream);        /* free up any allocated structures */
 
 bail:
-	delete[] readBuf;
     return result;
 }
 
+class FileReader {
+public:
+   FileReader(FILE* fp) :
+       mFp(fp), mReadBuf(new unsigned char[kReadBufSize])
+   {
+   }
+
+   ~FileReader() {
+       delete[] mReadBuf;
+   }
+
+   long read(unsigned char** nextBuffer, long readSize) const {
+       *nextBuffer = mReadBuf;
+       return fread(mReadBuf, 1, readSize, mFp);
+   }
+
+   FILE* mFp;
+   unsigned char* mReadBuf;
+};
+
+class FdReader {
+public:
+   FdReader(int fd) :
+       mFd(fd), mReadBuf(new unsigned char[kReadBufSize])
+   {
+   }
+
+   ~FdReader() {
+       delete[] mReadBuf;
+   }
+
+   long read(unsigned char** nextBuffer, long readSize) const {
+       *nextBuffer = mReadBuf;
+       return TEMP_FAILURE_RETRY(::read(mFd, mReadBuf, readSize));
+   }
+
+   int mFd;
+   unsigned char* mReadBuf;
+};
+
+class BufferReader {
+public:
+    BufferReader(void* input, size_t inputSize) :
+        mInput(reinterpret_cast<unsigned char*>(input)),
+        mInputSize(inputSize),
+        mBufferReturned(false)
+    {
+    }
+
+    long read(unsigned char** nextBuffer, long readSize) {
+        if (!mBufferReturned) {
+            mBufferReturned = true;
+            *nextBuffer = mInput;
+            return mInputSize;
+        }
+
+        *nextBuffer = NULL;
+        return 0;
+    }
+
+    unsigned char* mInput;
+    const size_t mInputSize;
+    bool mBufferReturned;
+};
+
+/*static*/ bool ZipUtils::inflateToBuffer(FILE* fp, void* buf,
+    long uncompressedLen, long compressedLen)
+{
+    FileReader reader(fp);
+    return ::inflateToBuffer<FileReader>(reader, buf,
+        uncompressedLen, compressedLen);
+}
+
+/*static*/ bool ZipUtils::inflateToBuffer(int fd, void* buf,
+    long uncompressedLen, long compressedLen)
+{
+    FdReader reader(fd);
+    return ::inflateToBuffer<FdReader>(reader, buf,
+        uncompressedLen, compressedLen);
+}
+
+/*static*/ bool ZipUtils::inflateToBuffer(void* in, void* buf,
+    long uncompressedLen, long compressedLen)
+{
+    BufferReader reader(in, compressedLen);
+    return ::inflateToBuffer<BufferReader>(reader, buf,
+        uncompressedLen, compressedLen);
+}
+
+
+
 /*
  * Look at the contents of a gzip archive.  We want to know where the
  * data starts, and how long it will be after it is uncompressed.
@@ -338,8 +323,8 @@
     fseek(fp, curPosn, SEEK_SET);
 
     *pCompressionMethod = method;
-    *pCRC32 = ZipFileRO::get4LE(&buf[0]);
-    *pUncompressedLen = ZipFileRO::get4LE(&buf[4]);
+    *pCRC32 = get4LE(&buf[0]);
+    *pUncompressedLen = get4LE(&buf[4]);
 
     return true;
 }
diff --git a/libs/androidfw/tests/Android.mk b/libs/androidfw/tests/Android.mk
index 0522212..3c55375 100644
--- a/libs/androidfw/tests/Android.mk
+++ b/libs/androidfw/tests/Android.mk
@@ -5,7 +5,7 @@
 # Build the unit tests.
 test_src_files := \
     ObbFile_test.cpp \
-    ZipFileRO_test.cpp
+    ZipUtils_test.cpp
 
 shared_libraries := \
     libandroidfw \
diff --git a/libs/androidfw/tests/ZipFileRO_test.cpp b/libs/androidfw/tests/ZipFileRO_test.cpp
deleted file mode 100644
index cb9c721..0000000
--- a/libs/androidfw/tests/ZipFileRO_test.cpp
+++ /dev/null
@@ -1,64 +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.
- */
-
-#define LOG_TAG "ZipFileRO_test"
-#include <utils/Log.h>
-#include <androidfw/ZipFileRO.h>
-
-#include <gtest/gtest.h>
-
-#include <fcntl.h>
-#include <string.h>
-
-namespace android {
-
-class ZipFileROTest : public testing::Test {
-protected:
-    virtual void SetUp() {
-    }
-
-    virtual void TearDown() {
-    }
-};
-
-TEST_F(ZipFileROTest, ZipTimeConvertSuccess) {
-    struct tm t;
-
-    // 2011-06-29 14:40:40
-    long when = 0x3EDD7514;
-
-    ZipFileRO::zipTimeToTimespec(when, &t);
-
-    EXPECT_EQ(2011, t.tm_year + 1900)
-            << "Year was improperly converted.";
-
-    EXPECT_EQ(6, t.tm_mon)
-            << "Month was improperly converted.";
-
-    EXPECT_EQ(29, t.tm_mday)
-            << "Day was improperly converted.";
-
-    EXPECT_EQ(14, t.tm_hour)
-            << "Hour was improperly converted.";
-
-    EXPECT_EQ(40, t.tm_min)
-            << "Minute was improperly converted.";
-
-    EXPECT_EQ(40, t.tm_sec)
-            << "Second was improperly converted.";
-}
-
-}
diff --git a/libs/androidfw/tests/ZipUtils_test.cpp b/libs/androidfw/tests/ZipUtils_test.cpp
new file mode 100644
index 0000000..c6038b5
--- /dev/null
+++ b/libs/androidfw/tests/ZipUtils_test.cpp
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "ZipUtils_test"
+#include <utils/Log.h>
+#include <androidfw/ZipUtils.h>
+
+#include <gtest/gtest.h>
+
+#include <fcntl.h>
+#include <string.h>
+
+namespace android {
+
+class ZipUtilsTest : public testing::Test {
+protected:
+    virtual void SetUp() {
+    }
+
+    virtual void TearDown() {
+    }
+};
+
+TEST_F(ZipUtilsTest, ZipTimeConvertSuccess) {
+    struct tm t;
+
+    // 2011-06-29 14:40:40
+    long when = 0x3EDD7514;
+
+    ZipUtils::zipTimeToTimespec(when, &t);
+
+    EXPECT_EQ(2011, t.tm_year + 1900)
+            << "Year was improperly converted.";
+
+    EXPECT_EQ(6, t.tm_mon)
+            << "Month was improperly converted.";
+
+    EXPECT_EQ(29, t.tm_mday)
+            << "Day was improperly converted.";
+
+    EXPECT_EQ(14, t.tm_hour)
+            << "Hour was improperly converted.";
+
+    EXPECT_EQ(40, t.tm_min)
+            << "Minute was improperly converted.";
+
+    EXPECT_EQ(40, t.tm_sec)
+            << "Second was improperly converted.";
+}
+
+}
diff --git a/services/common_time/Android.mk b/libs/common_time/Android.mk
similarity index 100%
rename from services/common_time/Android.mk
rename to libs/common_time/Android.mk
diff --git a/services/common_time/clock_recovery.cpp b/libs/common_time/clock_recovery.cpp
similarity index 100%
rename from services/common_time/clock_recovery.cpp
rename to libs/common_time/clock_recovery.cpp
diff --git a/services/common_time/clock_recovery.h b/libs/common_time/clock_recovery.h
similarity index 100%
rename from services/common_time/clock_recovery.h
rename to libs/common_time/clock_recovery.h
diff --git a/services/common_time/common_clock.cpp b/libs/common_time/common_clock.cpp
similarity index 100%
rename from services/common_time/common_clock.cpp
rename to libs/common_time/common_clock.cpp
diff --git a/services/common_time/common_clock.h b/libs/common_time/common_clock.h
similarity index 100%
rename from services/common_time/common_clock.h
rename to libs/common_time/common_clock.h
diff --git a/services/common_time/common_clock_service.cpp b/libs/common_time/common_clock_service.cpp
similarity index 100%
rename from services/common_time/common_clock_service.cpp
rename to libs/common_time/common_clock_service.cpp
diff --git a/services/common_time/common_clock_service.h b/libs/common_time/common_clock_service.h
similarity index 100%
rename from services/common_time/common_clock_service.h
rename to libs/common_time/common_clock_service.h
diff --git a/services/common_time/common_time_config_service.cpp b/libs/common_time/common_time_config_service.cpp
similarity index 100%
rename from services/common_time/common_time_config_service.cpp
rename to libs/common_time/common_time_config_service.cpp
diff --git a/services/common_time/common_time_config_service.h b/libs/common_time/common_time_config_service.h
similarity index 100%
rename from services/common_time/common_time_config_service.h
rename to libs/common_time/common_time_config_service.h
diff --git a/services/common_time/common_time_server.cpp b/libs/common_time/common_time_server.cpp
similarity index 100%
rename from services/common_time/common_time_server.cpp
rename to libs/common_time/common_time_server.cpp
diff --git a/services/common_time/common_time_server.h b/libs/common_time/common_time_server.h
similarity index 100%
rename from services/common_time/common_time_server.h
rename to libs/common_time/common_time_server.h
diff --git a/services/common_time/common_time_server_api.cpp b/libs/common_time/common_time_server_api.cpp
similarity index 100%
rename from services/common_time/common_time_server_api.cpp
rename to libs/common_time/common_time_server_api.cpp
diff --git a/services/common_time/common_time_server_packets.cpp b/libs/common_time/common_time_server_packets.cpp
similarity index 100%
rename from services/common_time/common_time_server_packets.cpp
rename to libs/common_time/common_time_server_packets.cpp
diff --git a/services/common_time/common_time_server_packets.h b/libs/common_time/common_time_server_packets.h
similarity index 100%
rename from services/common_time/common_time_server_packets.h
rename to libs/common_time/common_time_server_packets.h
diff --git a/services/common_time/diag_thread.cpp b/libs/common_time/diag_thread.cpp
similarity index 100%
rename from services/common_time/diag_thread.cpp
rename to libs/common_time/diag_thread.cpp
diff --git a/services/common_time/diag_thread.h b/libs/common_time/diag_thread.h
similarity index 100%
rename from services/common_time/diag_thread.h
rename to libs/common_time/diag_thread.h
diff --git a/services/common_time/main.cpp b/libs/common_time/main.cpp
similarity index 100%
rename from services/common_time/main.cpp
rename to libs/common_time/main.cpp
diff --git a/services/common_time/utils.cpp b/libs/common_time/utils.cpp
similarity index 100%
rename from services/common_time/utils.cpp
rename to libs/common_time/utils.cpp
diff --git a/services/common_time/utils.h b/libs/common_time/utils.h
similarity index 100%
rename from services/common_time/utils.h
rename to libs/common_time/utils.h
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 00e7870..0be17ff 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -732,7 +732,9 @@
 
         if (mRs == 0) {
             mRs = new RSC::RS();
-            if (!mRs->init(RSC::RS_INIT_LOW_LATENCY | RSC::RS_INIT_SYNCHRONOUS)) {
+            // a null path is OK because there are no custom kernels used
+            // hence nothing gets cached by RS
+            if (!mRs->init("", RSC::RS_INIT_LOW_LATENCY | RSC::RS_INIT_SYNCHRONOUS)) {
                 ALOGE("blur RS failed to init");
             }
 
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 35fc804..4d76bed 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1076,7 +1076,13 @@
         }
     } else if (!rect.isEmpty()) {
         dirtyLayer(rect.left, rect.top, rect.right, rect.bottom);
+
+        save(0);
+        // the layer contains screen buffer content that shouldn't be alpha modulated
+        // (and any necessary alpha modulation was handled drawing into the layer)
+        mSnapshot->alpha = 1.0f;
         composeLayerRect(layer, rect, true);
+        restore();
     }
 
     dirtyClip();
diff --git a/libs/hwui/SkiaShader.h b/libs/hwui/SkiaShader.h
index a63431c..cc56c50 100644
--- a/libs/hwui/SkiaShader.h
+++ b/libs/hwui/SkiaShader.h
@@ -145,7 +145,7 @@
             GLuint* textureUnit);
 
 private:
-    SkiaBitmapShader() {
+    SkiaBitmapShader() : mBitmap(NULL), mTexture(NULL) {
     }
 
     SkBitmap* mBitmap;
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 8d0874f..ed0a79a 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -285,9 +285,10 @@
 void TextureCache::uploadLoFiTexture(bool resize, SkBitmap* bitmap,
         uint32_t width, uint32_t height) {
     SkBitmap rgbaBitmap;
-    rgbaBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0, bitmap->alphaType());
+    rgbaBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
     rgbaBitmap.allocPixels();
     rgbaBitmap.eraseColor(0);
+    rgbaBitmap.setIsOpaque(bitmap->isOpaque());
 
     SkCanvas canvas(rgbaBitmap);
     canvas.drawBitmap(*bitmap, 0.0f, 0.0f, NULL);
diff --git a/libs/hwui/font/Font.cpp b/libs/hwui/font/Font.cpp
index 12a9c23..18983d8 100644
--- a/libs/hwui/font/Font.cpp
+++ b/libs/hwui/font/Font.cpp
@@ -23,7 +23,6 @@
 #include <utils/Trace.h>
 
 #include <SkGlyph.h>
-#include <SkGlyphCache.h>
 #include <SkUtils.h>
 
 #include "FontUtil.h"
@@ -272,9 +271,9 @@
     if (cachedGlyph) {
         // Is the glyph still in texture cache?
         if (!cachedGlyph->mIsValid) {
-            SkAutoGlyphCache autoCache(*paint, NULL, &mDescription.mLookupTransform);
-            const SkGlyph& skiaGlyph = GET_METRICS(autoCache.getCache(), textUnit);
-            updateGlyphCache(paint, skiaGlyph, autoCache.getCache(), cachedGlyph, precaching);
+            const SkGlyph& skiaGlyph = GET_METRICS(paint, textUnit,
+                    &mDescription.mLookupTransform);
+            updateGlyphCache(paint, skiaGlyph, cachedGlyph, precaching);
         }
     } else {
         cachedGlyph = cacheGlyph(paint, textUnit, precaching);
@@ -416,8 +415,8 @@
     }
 }
 
-void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, SkGlyphCache* skiaGlyphCache,
-        CachedGlyphInfo* glyph, bool precaching) {
+void Font::updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyphInfo* glyph,
+        bool precaching) {
     glyph->mAdvanceX = skiaGlyph.fAdvanceX;
     glyph->mAdvanceY = skiaGlyph.fAdvanceY;
     glyph->mBitmapLeft = skiaGlyph.fLeft;
@@ -430,7 +429,7 @@
 
     // Get the bitmap for the glyph
     if (!skiaGlyph.fImage) {
-        skiaGlyphCache->findImage(skiaGlyph);
+        paint->findImage(skiaGlyph, &mDescription.mLookupTransform);
     }
     mState->cacheBitmap(skiaGlyph, glyph, &startX, &startY, precaching);
 
@@ -464,12 +463,11 @@
     CachedGlyphInfo* newGlyph = new CachedGlyphInfo();
     mCachedGlyphs.add(glyph, newGlyph);
 
-    SkAutoGlyphCache autoCache(*paint, NULL, &mDescription.mLookupTransform);
-    const SkGlyph& skiaGlyph = GET_METRICS(autoCache.getCache(), glyph);
+    const SkGlyph& skiaGlyph = GET_METRICS(paint, glyph, &mDescription.mLookupTransform);
     newGlyph->mIsValid = false;
     newGlyph->mGlyphIndex = skiaGlyph.fID;
 
-    updateGlyphCache(paint, skiaGlyph, autoCache.getCache(), newGlyph, precaching);
+    updateGlyphCache(paint, skiaGlyph, newGlyph, precaching);
 
     return newGlyph;
 }
diff --git a/libs/hwui/font/Font.h b/libs/hwui/font/Font.h
index f68b430..9e7ec2d 100644
--- a/libs/hwui/font/Font.h
+++ b/libs/hwui/font/Font.h
@@ -19,7 +19,6 @@
 
 #include <utils/KeyedVector.h>
 
-#include <SkGlyphCache.h>
 #include <SkScalerContext.h>
 #include <SkPaint.h>
 #include <SkPathMeasure.h>
@@ -118,8 +117,8 @@
     void invalidateTextureCache(CacheTexture* cacheTexture = NULL);
 
     CachedGlyphInfo* cacheGlyph(SkPaint* paint, glyph_t glyph, bool precaching);
-    void updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, SkGlyphCache* skiaGlyphCache,
-            CachedGlyphInfo* glyph, bool precaching);
+    void updateGlyphCache(SkPaint* paint, const SkGlyph& skiaGlyph, CachedGlyphInfo* glyph,
+            bool precaching);
 
     void measureCachedGlyph(CachedGlyphInfo* glyph, int x, int y,
             uint8_t *bitmap, uint32_t bitmapW, uint32_t bitmapH,
diff --git a/libs/hwui/font/FontUtil.h b/libs/hwui/font/FontUtil.h
index c2fd5f5..cdcb23c 100644
--- a/libs/hwui/font/FontUtil.h
+++ b/libs/hwui/font/FontUtil.h
@@ -40,7 +40,7 @@
 #if RENDER_TEXT_AS_GLYPHS
     typedef uint16_t glyph_t;
     #define TO_GLYPH(g) g
-    #define GET_METRICS(cache, glyph) cache->getGlyphIDMetrics(glyph)
+    #define GET_METRICS(paint, glyph, matrix) paint->getGlyphMetrics(glyph, matrix)
     #define GET_GLYPH(text) nextGlyph((const uint16_t**) &text)
     #define IS_END_OF_STRING(glyph) false
 
@@ -53,7 +53,7 @@
 #else
     typedef SkUnichar glyph_t;
     #define TO_GLYPH(g) ((SkUnichar) g)
-    #define GET_METRICS(cache, glyph) cache->getUnicharMetrics(glyph)
+    #define GET_METRICS(paint, glyph, matrix) paint->getUnicharMetrics(glyph, matrix)
     #define GET_GLYPH(text) SkUTF16_NextUnichar((const uint16_t**) &text)
     #define IS_END_OF_STRING(glyph) glyph < 0
 #endif
diff --git a/services/input/Android.mk b/libs/input/Android.mk
similarity index 100%
rename from services/input/Android.mk
rename to libs/input/Android.mk
diff --git a/libs/input/EventHub.cpp b/libs/input/EventHub.cpp
new file mode 100644
index 0000000..fc324f8
--- /dev/null
+++ b/libs/input/EventHub.cpp
@@ -0,0 +1,1679 @@
+/*
+ * Copyright (C) 2005 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.
+ */
+
+#define LOG_TAG "EventHub"
+
+// #define LOG_NDEBUG 0
+
+#include "EventHub.h"
+
+#include <hardware_legacy/power.h>
+
+#include <cutils/properties.h>
+#include <utils/Log.h>
+#include <utils/Timers.h>
+#include <utils/threads.h>
+#include <utils/Errors.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <memory.h>
+#include <errno.h>
+#include <assert.h>
+
+#include <input/KeyLayoutMap.h>
+#include <input/KeyCharacterMap.h>
+#include <input/VirtualKeyMap.h>
+
+#include <string.h>
+#include <stdint.h>
+#include <dirent.h>
+
+#include <sys/inotify.h>
+#include <sys/epoll.h>
+#include <sys/ioctl.h>
+#include <sys/limits.h>
+#include <sys/sha1.h>
+
+/* this macro is used to tell if "bit" is set in "array"
+ * it selects a byte from the array, and does a boolean AND
+ * operation with a byte that only has the relevant bit set.
+ * eg. to check for the 12th bit, we do (array[1] & 1<<4)
+ */
+#define test_bit(bit, array)    (array[bit/8] & (1<<(bit%8)))
+
+/* this macro computes the number of bytes needed to represent a bit array of the specified size */
+#define sizeof_bit_array(bits)  ((bits + 7) / 8)
+
+#define INDENT "  "
+#define INDENT2 "    "
+#define INDENT3 "      "
+
+namespace android {
+
+static const char *WAKE_LOCK_ID = "KeyEvents";
+static const char *DEVICE_PATH = "/dev/input";
+
+/* return the larger integer */
+static inline int max(int v1, int v2)
+{
+    return (v1 > v2) ? v1 : v2;
+}
+
+static inline const char* toString(bool value) {
+    return value ? "true" : "false";
+}
+
+static String8 sha1(const String8& in) {
+    SHA1_CTX ctx;
+    SHA1Init(&ctx);
+    SHA1Update(&ctx, reinterpret_cast<const u_char*>(in.string()), in.size());
+    u_char digest[SHA1_DIGEST_LENGTH];
+    SHA1Final(digest, &ctx);
+
+    String8 out;
+    for (size_t i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+        out.appendFormat("%02x", digest[i]);
+    }
+    return out;
+}
+
+static void setDescriptor(InputDeviceIdentifier& identifier) {
+    // Compute a device descriptor that uniquely identifies the device.
+    // The descriptor is assumed to be a stable identifier.  Its value should not
+    // change between reboots, reconnections, firmware updates or new releases of Android.
+    // Ideally, we also want the descriptor to be short and relatively opaque.
+    String8 rawDescriptor;
+    rawDescriptor.appendFormat(":%04x:%04x:", identifier.vendor, identifier.product);
+    if (!identifier.uniqueId.isEmpty()) {
+        rawDescriptor.append("uniqueId:");
+        rawDescriptor.append(identifier.uniqueId);
+    } if (identifier.vendor == 0 && identifier.product == 0) {
+        // If we don't know the vendor and product id, then the device is probably
+        // built-in so we need to rely on other information to uniquely identify
+        // the input device.  Usually we try to avoid relying on the device name or
+        // location but for built-in input device, they are unlikely to ever change.
+        if (!identifier.name.isEmpty()) {
+            rawDescriptor.append("name:");
+            rawDescriptor.append(identifier.name);
+        } else if (!identifier.location.isEmpty()) {
+            rawDescriptor.append("location:");
+            rawDescriptor.append(identifier.location);
+        }
+    }
+    identifier.descriptor = sha1(rawDescriptor);
+    ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.string(),
+            identifier.descriptor.string());
+}
+
+// --- Global Functions ---
+
+uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses) {
+    // Touch devices get dibs on touch-related axes.
+    if (deviceClasses & INPUT_DEVICE_CLASS_TOUCH) {
+        switch (axis) {
+        case ABS_X:
+        case ABS_Y:
+        case ABS_PRESSURE:
+        case ABS_TOOL_WIDTH:
+        case ABS_DISTANCE:
+        case ABS_TILT_X:
+        case ABS_TILT_Y:
+        case ABS_MT_SLOT:
+        case ABS_MT_TOUCH_MAJOR:
+        case ABS_MT_TOUCH_MINOR:
+        case ABS_MT_WIDTH_MAJOR:
+        case ABS_MT_WIDTH_MINOR:
+        case ABS_MT_ORIENTATION:
+        case ABS_MT_POSITION_X:
+        case ABS_MT_POSITION_Y:
+        case ABS_MT_TOOL_TYPE:
+        case ABS_MT_BLOB_ID:
+        case ABS_MT_TRACKING_ID:
+        case ABS_MT_PRESSURE:
+        case ABS_MT_DISTANCE:
+            return INPUT_DEVICE_CLASS_TOUCH;
+        }
+    }
+
+    // Joystick devices get the rest.
+    return deviceClasses & INPUT_DEVICE_CLASS_JOYSTICK;
+}
+
+// --- EventHub::Device ---
+
+EventHub::Device::Device(int fd, int32_t id, const String8& path,
+        const InputDeviceIdentifier& identifier) :
+        next(NULL),
+        fd(fd), id(id), path(path), identifier(identifier),
+        classes(0), configuration(NULL), virtualKeyMap(NULL),
+        ffEffectPlaying(false), ffEffectId(-1), controllerNumber(0),
+        timestampOverrideSec(0), timestampOverrideUsec(0) {
+    memset(keyBitmask, 0, sizeof(keyBitmask));
+    memset(absBitmask, 0, sizeof(absBitmask));
+    memset(relBitmask, 0, sizeof(relBitmask));
+    memset(swBitmask, 0, sizeof(swBitmask));
+    memset(ledBitmask, 0, sizeof(ledBitmask));
+    memset(ffBitmask, 0, sizeof(ffBitmask));
+    memset(propBitmask, 0, sizeof(propBitmask));
+}
+
+EventHub::Device::~Device() {
+    close();
+    delete configuration;
+    delete virtualKeyMap;
+}
+
+void EventHub::Device::close() {
+    if (fd >= 0) {
+        ::close(fd);
+        fd = -1;
+    }
+}
+
+
+// --- EventHub ---
+
+const uint32_t EventHub::EPOLL_ID_INOTIFY;
+const uint32_t EventHub::EPOLL_ID_WAKE;
+const int EventHub::EPOLL_SIZE_HINT;
+const int EventHub::EPOLL_MAX_EVENTS;
+
+EventHub::EventHub(void) :
+        mBuiltInKeyboardId(NO_BUILT_IN_KEYBOARD), mNextDeviceId(1), mControllerNumbers(),
+        mOpeningDevices(0), mClosingDevices(0),
+        mNeedToSendFinishedDeviceScan(false),
+        mNeedToReopenDevices(false), mNeedToScanDevices(true),
+        mPendingEventCount(0), mPendingEventIndex(0), mPendingINotify(false) {
+    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
+
+    mEpollFd = epoll_create(EPOLL_SIZE_HINT);
+    LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance.  errno=%d", errno);
+
+    mINotifyFd = inotify_init();
+    int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
+    LOG_ALWAYS_FATAL_IF(result < 0, "Could not register INotify for %s.  errno=%d",
+            DEVICE_PATH, errno);
+
+    struct epoll_event eventItem;
+    memset(&eventItem, 0, sizeof(eventItem));
+    eventItem.events = EPOLLIN;
+    eventItem.data.u32 = EPOLL_ID_INOTIFY;
+    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add INotify to epoll instance.  errno=%d", errno);
+
+    int wakeFds[2];
+    result = pipe(wakeFds);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe.  errno=%d", errno);
+
+    mWakeReadPipeFd = wakeFds[0];
+    mWakeWritePipeFd = wakeFds[1];
+
+    result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking.  errno=%d",
+            errno);
+
+    result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking.  errno=%d",
+            errno);
+
+    eventItem.data.u32 = EPOLL_ID_WAKE;
+    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);
+    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance.  errno=%d",
+            errno);
+}
+
+EventHub::~EventHub(void) {
+    closeAllDevicesLocked();
+
+    while (mClosingDevices) {
+        Device* device = mClosingDevices;
+        mClosingDevices = device->next;
+        delete device;
+    }
+
+    ::close(mEpollFd);
+    ::close(mINotifyFd);
+    ::close(mWakeReadPipeFd);
+    ::close(mWakeWritePipeFd);
+
+    release_wake_lock(WAKE_LOCK_ID);
+}
+
+InputDeviceIdentifier EventHub::getDeviceIdentifier(int32_t deviceId) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device == NULL) return InputDeviceIdentifier();
+    return device->identifier;
+}
+
+uint32_t EventHub::getDeviceClasses(int32_t deviceId) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device == NULL) return 0;
+    return device->classes;
+}
+
+int32_t EventHub::getDeviceControllerNumber(int32_t deviceId) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device == NULL) return 0;
+    return device->controllerNumber;
+}
+
+void EventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device && device->configuration) {
+        *outConfiguration = *device->configuration;
+    } else {
+        outConfiguration->clear();
+    }
+}
+
+status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
+        RawAbsoluteAxisInfo* outAxisInfo) const {
+    outAxisInfo->clear();
+
+    if (axis >= 0 && axis <= ABS_MAX) {
+        AutoMutex _l(mLock);
+
+        Device* device = getDeviceLocked(deviceId);
+        if (device && !device->isVirtual() && test_bit(axis, device->absBitmask)) {
+            struct input_absinfo info;
+            if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
+                ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
+                     axis, device->identifier.name.string(), device->fd, errno);
+                return -errno;
+            }
+
+            if (info.minimum != info.maximum) {
+                outAxisInfo->valid = true;
+                outAxisInfo->minValue = info.minimum;
+                outAxisInfo->maxValue = info.maximum;
+                outAxisInfo->flat = info.flat;
+                outAxisInfo->fuzz = info.fuzz;
+                outAxisInfo->resolution = info.resolution;
+            }
+            return OK;
+        }
+    }
+    return -1;
+}
+
+bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const {
+    if (axis >= 0 && axis <= REL_MAX) {
+        AutoMutex _l(mLock);
+
+        Device* device = getDeviceLocked(deviceId);
+        if (device) {
+            return test_bit(axis, device->relBitmask);
+        }
+    }
+    return false;
+}
+
+bool EventHub::hasInputProperty(int32_t deviceId, int property) const {
+    if (property >= 0 && property <= INPUT_PROP_MAX) {
+        AutoMutex _l(mLock);
+
+        Device* device = getDeviceLocked(deviceId);
+        if (device) {
+            return test_bit(property, device->propBitmask);
+        }
+    }
+    return false;
+}
+
+int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
+    if (scanCode >= 0 && scanCode <= KEY_MAX) {
+        AutoMutex _l(mLock);
+
+        Device* device = getDeviceLocked(deviceId);
+        if (device && !device->isVirtual() && test_bit(scanCode, device->keyBitmask)) {
+            uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)];
+            memset(keyState, 0, sizeof(keyState));
+            if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
+                return test_bit(scanCode, keyState) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
+            }
+        }
+    }
+    return AKEY_STATE_UNKNOWN;
+}
+
+int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
+    AutoMutex _l(mLock);
+
+    Device* device = getDeviceLocked(deviceId);
+    if (device && !device->isVirtual() && device->keyMap.haveKeyLayout()) {
+        Vector<int32_t> scanCodes;
+        device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes);
+        if (scanCodes.size() != 0) {
+            uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)];
+            memset(keyState, 0, sizeof(keyState));
+            if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
+                for (size_t i = 0; i < scanCodes.size(); i++) {
+                    int32_t sc = scanCodes.itemAt(i);
+                    if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, keyState)) {
+                        return AKEY_STATE_DOWN;
+                    }
+                }
+                return AKEY_STATE_UP;
+            }
+        }
+    }
+    return AKEY_STATE_UNKNOWN;
+}
+
+int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
+    if (sw >= 0 && sw <= SW_MAX) {
+        AutoMutex _l(mLock);
+
+        Device* device = getDeviceLocked(deviceId);
+        if (device && !device->isVirtual() && test_bit(sw, device->swBitmask)) {
+            uint8_t swState[sizeof_bit_array(SW_MAX + 1)];
+            memset(swState, 0, sizeof(swState));
+            if (ioctl(device->fd, EVIOCGSW(sizeof(swState)), swState) >= 0) {
+                return test_bit(sw, swState) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
+            }
+        }
+    }
+    return AKEY_STATE_UNKNOWN;
+}
+
+status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const {
+    *outValue = 0;
+
+    if (axis >= 0 && axis <= ABS_MAX) {
+        AutoMutex _l(mLock);
+
+        Device* device = getDeviceLocked(deviceId);
+        if (device && !device->isVirtual() && test_bit(axis, device->absBitmask)) {
+            struct input_absinfo info;
+            if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
+                ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
+                     axis, device->identifier.name.string(), device->fd, errno);
+                return -errno;
+            }
+
+            *outValue = info.value;
+            return OK;
+        }
+    }
+    return -1;
+}
+
+bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
+        const int32_t* keyCodes, uint8_t* outFlags) const {
+    AutoMutex _l(mLock);
+
+    Device* device = getDeviceLocked(deviceId);
+    if (device && device->keyMap.haveKeyLayout()) {
+        Vector<int32_t> scanCodes;
+        for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
+            scanCodes.clear();
+
+            status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(
+                    keyCodes[codeIndex], &scanCodes);
+            if (! err) {
+                // check the possible scan codes identified by the layout map against the
+                // map of codes actually emitted by the driver
+                for (size_t sc = 0; sc < scanCodes.size(); sc++) {
+                    if (test_bit(scanCodes[sc], device->keyBitmask)) {
+                        outFlags[codeIndex] = 1;
+                        break;
+                    }
+                }
+            }
+        }
+        return true;
+    }
+    return false;
+}
+
+status_t EventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
+        int32_t* outKeycode, uint32_t* outFlags) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+
+    if (device) {
+        // Check the key character map first.
+        sp<KeyCharacterMap> kcm = device->getKeyCharacterMap();
+        if (kcm != NULL) {
+            if (!kcm->mapKey(scanCode, usageCode, outKeycode)) {
+                *outFlags = 0;
+                return NO_ERROR;
+            }
+        }
+
+        // Check the key layout next.
+        if (device->keyMap.haveKeyLayout()) {
+            if (!device->keyMap.keyLayoutMap->mapKey(
+                    scanCode, usageCode, outKeycode, outFlags)) {
+                return NO_ERROR;
+            }
+        }
+    }
+
+    *outKeycode = 0;
+    *outFlags = 0;
+    return NAME_NOT_FOUND;
+}
+
+status_t EventHub::mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+
+    if (device && device->keyMap.haveKeyLayout()) {
+        status_t err = device->keyMap.keyLayoutMap->mapAxis(scanCode, outAxisInfo);
+        if (err == NO_ERROR) {
+            return NO_ERROR;
+        }
+    }
+
+    return NAME_NOT_FOUND;
+}
+
+void EventHub::setExcludedDevices(const Vector<String8>& devices) {
+    AutoMutex _l(mLock);
+
+    mExcludedDevices = devices;
+}
+
+bool EventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device && scanCode >= 0 && scanCode <= KEY_MAX) {
+        if (test_bit(scanCode, device->keyBitmask)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    int32_t sc;
+    if (device && mapLed(device, led, &sc) == NO_ERROR) {
+        if (test_bit(sc, device->ledBitmask)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void EventHub::setLedState(int32_t deviceId, int32_t led, bool on) {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    setLedStateLocked(device, led, on);
+}
+
+void EventHub::setLedStateLocked(Device* device, int32_t led, bool on) {
+    int32_t sc;
+    if (device && !device->isVirtual() && mapLed(device, led, &sc) != NAME_NOT_FOUND) {
+        struct input_event ev;
+        ev.time.tv_sec = 0;
+        ev.time.tv_usec = 0;
+        ev.type = EV_LED;
+        ev.code = sc;
+        ev.value = on ? 1 : 0;
+
+        ssize_t nWrite;
+        do {
+            nWrite = write(device->fd, &ev, sizeof(struct input_event));
+        } while (nWrite == -1 && errno == EINTR);
+    }
+}
+
+void EventHub::getVirtualKeyDefinitions(int32_t deviceId,
+        Vector<VirtualKeyDefinition>& outVirtualKeys) const {
+    outVirtualKeys.clear();
+
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device && device->virtualKeyMap) {
+        outVirtualKeys.appendVector(device->virtualKeyMap->getVirtualKeys());
+    }
+}
+
+sp<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t deviceId) const {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device) {
+        return device->getKeyCharacterMap();
+    }
+    return NULL;
+}
+
+bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId,
+        const sp<KeyCharacterMap>& map) {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device) {
+        if (map != device->overlayKeyMap) {
+            device->overlayKeyMap = map;
+            device->combinedKeyMap = KeyCharacterMap::combine(
+                    device->keyMap.keyCharacterMap, map);
+            return true;
+        }
+    }
+    return false;
+}
+
+static String8 generateDescriptor(InputDeviceIdentifier& identifier) {
+    String8 rawDescriptor;
+    rawDescriptor.appendFormat(":%04x:%04x:", identifier.vendor,
+            identifier.product);
+    // TODO add handling for USB devices to not uniqueify kbs that show up twice
+    if (!identifier.uniqueId.isEmpty()) {
+        rawDescriptor.append("uniqueId:");
+        rawDescriptor.append(identifier.uniqueId);
+    } else if (identifier.nonce != 0) {
+        rawDescriptor.appendFormat("nonce:%04x", identifier.nonce);
+    }
+
+    if (identifier.vendor == 0 && identifier.product == 0) {
+        // If we don't know the vendor and product id, then the device is probably
+        // built-in so we need to rely on other information to uniquely identify
+        // the input device.  Usually we try to avoid relying on the device name or
+        // location but for built-in input device, they are unlikely to ever change.
+        if (!identifier.name.isEmpty()) {
+            rawDescriptor.append("name:");
+            rawDescriptor.append(identifier.name);
+        } else if (!identifier.location.isEmpty()) {
+            rawDescriptor.append("location:");
+            rawDescriptor.append(identifier.location);
+        }
+    }
+    identifier.descriptor = sha1(rawDescriptor);
+    return rawDescriptor;
+}
+
+void EventHub::assignDescriptorLocked(InputDeviceIdentifier& identifier) {
+    // Compute a device descriptor that uniquely identifies the device.
+    // The descriptor is assumed to be a stable identifier.  Its value should not
+    // change between reboots, reconnections, firmware updates or new releases
+    // of Android. In practice we sometimes get devices that cannot be uniquely
+    // identified. In this case we enforce uniqueness between connected devices.
+    // Ideally, we also want the descriptor to be short and relatively opaque.
+
+    identifier.nonce = 0;
+    String8 rawDescriptor = generateDescriptor(identifier);
+    if (identifier.uniqueId.isEmpty()) {
+        // If it didn't have a unique id check for conflicts and enforce
+        // uniqueness if necessary.
+        while(getDeviceByDescriptorLocked(identifier.descriptor) != NULL) {
+            identifier.nonce++;
+            rawDescriptor = generateDescriptor(identifier);
+        }
+    }
+    ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.string(),
+            identifier.descriptor.string());
+}
+
+void EventHub::vibrate(int32_t deviceId, nsecs_t duration) {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device && !device->isVirtual()) {
+        ff_effect effect;
+        memset(&effect, 0, sizeof(effect));
+        effect.type = FF_RUMBLE;
+        effect.id = device->ffEffectId;
+        effect.u.rumble.strong_magnitude = 0xc000;
+        effect.u.rumble.weak_magnitude = 0xc000;
+        effect.replay.length = (duration + 999999LL) / 1000000LL;
+        effect.replay.delay = 0;
+        if (ioctl(device->fd, EVIOCSFF, &effect)) {
+            ALOGW("Could not upload force feedback effect to device %s due to error %d.",
+                    device->identifier.name.string(), errno);
+            return;
+        }
+        device->ffEffectId = effect.id;
+
+        struct input_event ev;
+        ev.time.tv_sec = 0;
+        ev.time.tv_usec = 0;
+        ev.type = EV_FF;
+        ev.code = device->ffEffectId;
+        ev.value = 1;
+        if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) {
+            ALOGW("Could not start force feedback effect on device %s due to error %d.",
+                    device->identifier.name.string(), errno);
+            return;
+        }
+        device->ffEffectPlaying = true;
+    }
+}
+
+void EventHub::cancelVibrate(int32_t deviceId) {
+    AutoMutex _l(mLock);
+    Device* device = getDeviceLocked(deviceId);
+    if (device && !device->isVirtual()) {
+        if (device->ffEffectPlaying) {
+            device->ffEffectPlaying = false;
+
+            struct input_event ev;
+            ev.time.tv_sec = 0;
+            ev.time.tv_usec = 0;
+            ev.type = EV_FF;
+            ev.code = device->ffEffectId;
+            ev.value = 0;
+            if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) {
+                ALOGW("Could not stop force feedback effect on device %s due to error %d.",
+                        device->identifier.name.string(), errno);
+                return;
+            }
+        }
+    }
+}
+
+EventHub::Device* EventHub::getDeviceByDescriptorLocked(String8& descriptor) const {
+    size_t size = mDevices.size();
+    for (size_t i = 0; i < size; i++) {
+        Device* device = mDevices.valueAt(i);
+        if (descriptor.compare(device->identifier.descriptor) == 0) {
+            return device;
+        }
+    }
+    return NULL;
+}
+
+EventHub::Device* EventHub::getDeviceLocked(int32_t deviceId) const {
+    if (deviceId == BUILT_IN_KEYBOARD_ID) {
+        deviceId = mBuiltInKeyboardId;
+    }
+    ssize_t index = mDevices.indexOfKey(deviceId);
+    return index >= 0 ? mDevices.valueAt(index) : NULL;
+}
+
+EventHub::Device* EventHub::getDeviceByPathLocked(const char* devicePath) const {
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        Device* device = mDevices.valueAt(i);
+        if (device->path == devicePath) {
+            return device;
+        }
+    }
+    return NULL;
+}
+
+size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
+    ALOG_ASSERT(bufferSize >= 1);
+
+    AutoMutex _l(mLock);
+
+    struct input_event readBuffer[bufferSize];
+
+    RawEvent* event = buffer;
+    size_t capacity = bufferSize;
+    bool awoken = false;
+    for (;;) {
+        nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+
+        // Reopen input devices if needed.
+        if (mNeedToReopenDevices) {
+            mNeedToReopenDevices = false;
+
+            ALOGI("Reopening all input devices due to a configuration change.");
+
+            closeAllDevicesLocked();
+            mNeedToScanDevices = true;
+            break; // return to the caller before we actually rescan
+        }
+
+        // Report any devices that had last been added/removed.
+        while (mClosingDevices) {
+            Device* device = mClosingDevices;
+            ALOGV("Reporting device closed: id=%d, name=%s\n",
+                 device->id, device->path.string());
+            mClosingDevices = device->next;
+            event->when = now;
+            event->deviceId = device->id == mBuiltInKeyboardId ? BUILT_IN_KEYBOARD_ID : device->id;
+            event->type = DEVICE_REMOVED;
+            event += 1;
+            delete device;
+            mNeedToSendFinishedDeviceScan = true;
+            if (--capacity == 0) {
+                break;
+            }
+        }
+
+        if (mNeedToScanDevices) {
+            mNeedToScanDevices = false;
+            scanDevicesLocked();
+            mNeedToSendFinishedDeviceScan = true;
+        }
+
+        while (mOpeningDevices != NULL) {
+            Device* device = mOpeningDevices;
+            ALOGV("Reporting device opened: id=%d, name=%s\n",
+                 device->id, device->path.string());
+            mOpeningDevices = device->next;
+            event->when = now;
+            event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
+            event->type = DEVICE_ADDED;
+            event += 1;
+            mNeedToSendFinishedDeviceScan = true;
+            if (--capacity == 0) {
+                break;
+            }
+        }
+
+        if (mNeedToSendFinishedDeviceScan) {
+            mNeedToSendFinishedDeviceScan = false;
+            event->when = now;
+            event->type = FINISHED_DEVICE_SCAN;
+            event += 1;
+            if (--capacity == 0) {
+                break;
+            }
+        }
+
+        // Grab the next input event.
+        bool deviceChanged = false;
+        while (mPendingEventIndex < mPendingEventCount) {
+            const struct epoll_event& eventItem = mPendingEventItems[mPendingEventIndex++];
+            if (eventItem.data.u32 == EPOLL_ID_INOTIFY) {
+                if (eventItem.events & EPOLLIN) {
+                    mPendingINotify = true;
+                } else {
+                    ALOGW("Received unexpected epoll event 0x%08x for INotify.", eventItem.events);
+                }
+                continue;
+            }
+
+            if (eventItem.data.u32 == EPOLL_ID_WAKE) {
+                if (eventItem.events & EPOLLIN) {
+                    ALOGV("awoken after wake()");
+                    awoken = true;
+                    char buffer[16];
+                    ssize_t nRead;
+                    do {
+                        nRead = read(mWakeReadPipeFd, buffer, sizeof(buffer));
+                    } while ((nRead == -1 && errno == EINTR) || nRead == sizeof(buffer));
+                } else {
+                    ALOGW("Received unexpected epoll event 0x%08x for wake read pipe.",
+                            eventItem.events);
+                }
+                continue;
+            }
+
+            ssize_t deviceIndex = mDevices.indexOfKey(eventItem.data.u32);
+            if (deviceIndex < 0) {
+                ALOGW("Received unexpected epoll event 0x%08x for unknown device id %d.",
+                        eventItem.events, eventItem.data.u32);
+                continue;
+            }
+
+            Device* device = mDevices.valueAt(deviceIndex);
+            if (eventItem.events & EPOLLIN) {
+                int32_t readSize = read(device->fd, readBuffer,
+                        sizeof(struct input_event) * capacity);
+                if (readSize == 0 || (readSize < 0 && errno == ENODEV)) {
+                    // Device was removed before INotify noticed.
+                    ALOGW("could not get event, removed? (fd: %d size: %d bufferSize: %d "
+                            "capacity: %d errno: %d)\n",
+                            device->fd, readSize, bufferSize, capacity, errno);
+                    deviceChanged = true;
+                    closeDeviceLocked(device);
+                } else if (readSize < 0) {
+                    if (errno != EAGAIN && errno != EINTR) {
+                        ALOGW("could not get event (errno=%d)", errno);
+                    }
+                } else if ((readSize % sizeof(struct input_event)) != 0) {
+                    ALOGE("could not get event (wrong size: %d)", readSize);
+                } else {
+                    int32_t deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
+
+                    size_t count = size_t(readSize) / sizeof(struct input_event);
+                    for (size_t i = 0; i < count; i++) {
+                        struct input_event& iev = readBuffer[i];
+                        ALOGV("%s got: time=%d.%06d, type=%d, code=%d, value=%d",
+                                device->path.string(),
+                                (int) iev.time.tv_sec, (int) iev.time.tv_usec,
+                                iev.type, iev.code, iev.value);
+
+                        // Some input devices may have a better concept of the time
+                        // when an input event was actually generated than the kernel
+                        // which simply timestamps all events on entry to evdev.
+                        // This is a custom Android extension of the input protocol
+                        // mainly intended for use with uinput based device drivers.
+                        if (iev.type == EV_MSC) {
+                            if (iev.code == MSC_ANDROID_TIME_SEC) {
+                                device->timestampOverrideSec = iev.value;
+                                continue;
+                            } else if (iev.code == MSC_ANDROID_TIME_USEC) {
+                                device->timestampOverrideUsec = iev.value;
+                                continue;
+                            }
+                        }
+                        if (device->timestampOverrideSec || device->timestampOverrideUsec) {
+                            iev.time.tv_sec = device->timestampOverrideSec;
+                            iev.time.tv_usec = device->timestampOverrideUsec;
+                            if (iev.type == EV_SYN && iev.code == SYN_REPORT) {
+                                device->timestampOverrideSec = 0;
+                                device->timestampOverrideUsec = 0;
+                            }
+                            ALOGV("applied override time %d.%06d",
+                                    int(iev.time.tv_sec), int(iev.time.tv_usec));
+                        }
+
+#ifdef HAVE_POSIX_CLOCKS
+                        // Use the time specified in the event instead of the current time
+                        // so that downstream code can get more accurate estimates of
+                        // event dispatch latency from the time the event is enqueued onto
+                        // the evdev client buffer.
+                        //
+                        // The event's timestamp fortuitously uses the same monotonic clock
+                        // time base as the rest of Android.  The kernel event device driver
+                        // (drivers/input/evdev.c) obtains timestamps using ktime_get_ts().
+                        // The systemTime(SYSTEM_TIME_MONOTONIC) function we use everywhere
+                        // calls clock_gettime(CLOCK_MONOTONIC) which is implemented as a
+                        // system call that also queries ktime_get_ts().
+                        event->when = nsecs_t(iev.time.tv_sec) * 1000000000LL
+                                + nsecs_t(iev.time.tv_usec) * 1000LL;
+                        ALOGV("event time %lld, now %lld", event->when, now);
+
+                        // Bug 7291243: Add a guard in case the kernel generates timestamps
+                        // that appear to be far into the future because they were generated
+                        // using the wrong clock source.
+                        //
+                        // This can happen because when the input device is initially opened
+                        // it has a default clock source of CLOCK_REALTIME.  Any input events
+                        // enqueued right after the device is opened will have timestamps
+                        // generated using CLOCK_REALTIME.  We later set the clock source
+                        // to CLOCK_MONOTONIC but it is already too late.
+                        //
+                        // Invalid input event timestamps can result in ANRs, crashes and
+                        // and other issues that are hard to track down.  We must not let them
+                        // propagate through the system.
+                        //
+                        // Log a warning so that we notice the problem and recover gracefully.
+                        if (event->when >= now + 10 * 1000000000LL) {
+                            // Double-check.  Time may have moved on.
+                            nsecs_t time = systemTime(SYSTEM_TIME_MONOTONIC);
+                            if (event->when > time) {
+                                ALOGW("An input event from %s has a timestamp that appears to "
+                                        "have been generated using the wrong clock source "
+                                        "(expected CLOCK_MONOTONIC): "
+                                        "event time %lld, current time %lld, call time %lld.  "
+                                        "Using current time instead.",
+                                        device->path.string(), event->when, time, now);
+                                event->when = time;
+                            } else {
+                                ALOGV("Event time is ok but failed the fast path and required "
+                                        "an extra call to systemTime: "
+                                        "event time %lld, current time %lld, call time %lld.",
+                                        event->when, time, now);
+                            }
+                        }
+#else
+                        event->when = now;
+#endif
+                        event->deviceId = deviceId;
+                        event->type = iev.type;
+                        event->code = iev.code;
+                        event->value = iev.value;
+                        event += 1;
+                        capacity -= 1;
+                    }
+                    if (capacity == 0) {
+                        // The result buffer is full.  Reset the pending event index
+                        // so we will try to read the device again on the next iteration.
+                        mPendingEventIndex -= 1;
+                        break;
+                    }
+                }
+            } else if (eventItem.events & EPOLLHUP) {
+                ALOGI("Removing device %s due to epoll hang-up event.",
+                        device->identifier.name.string());
+                deviceChanged = true;
+                closeDeviceLocked(device);
+            } else {
+                ALOGW("Received unexpected epoll event 0x%08x for device %s.",
+                        eventItem.events, device->identifier.name.string());
+            }
+        }
+
+        // readNotify() will modify the list of devices so this must be done after
+        // processing all other events to ensure that we read all remaining events
+        // before closing the devices.
+        if (mPendingINotify && mPendingEventIndex >= mPendingEventCount) {
+            mPendingINotify = false;
+            readNotifyLocked();
+            deviceChanged = true;
+        }
+
+        // Report added or removed devices immediately.
+        if (deviceChanged) {
+            continue;
+        }
+
+        // Return now if we have collected any events or if we were explicitly awoken.
+        if (event != buffer || awoken) {
+            break;
+        }
+
+        // Poll for events.  Mind the wake lock dance!
+        // We hold a wake lock at all times except during epoll_wait().  This works due to some
+        // subtle choreography.  When a device driver has pending (unread) events, it acquires
+        // a kernel wake lock.  However, once the last pending event has been read, the device
+        // driver will release the kernel wake lock.  To prevent the system from going to sleep
+        // when this happens, the EventHub holds onto its own user wake lock while the client
+        // is processing events.  Thus the system can only sleep if there are no events
+        // pending or currently being processed.
+        //
+        // The timeout is advisory only.  If the device is asleep, it will not wake just to
+        // service the timeout.
+        mPendingEventIndex = 0;
+
+        mLock.unlock(); // release lock before poll, must be before release_wake_lock
+        release_wake_lock(WAKE_LOCK_ID);
+
+        int pollResult = epoll_wait(mEpollFd, mPendingEventItems, EPOLL_MAX_EVENTS, timeoutMillis);
+
+        acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
+        mLock.lock(); // reacquire lock after poll, must be after acquire_wake_lock
+
+        if (pollResult == 0) {
+            // Timed out.
+            mPendingEventCount = 0;
+            break;
+        }
+
+        if (pollResult < 0) {
+            // An error occurred.
+            mPendingEventCount = 0;
+
+            // Sleep after errors to avoid locking up the system.
+            // Hopefully the error is transient.
+            if (errno != EINTR) {
+                ALOGW("poll failed (errno=%d)\n", errno);
+                usleep(100000);
+            }
+        } else {
+            // Some events occurred.
+            mPendingEventCount = size_t(pollResult);
+        }
+    }
+
+    // All done, return the number of events we read.
+    return event - buffer;
+}
+
+void EventHub::wake() {
+    ALOGV("wake() called");
+
+    ssize_t nWrite;
+    do {
+        nWrite = write(mWakeWritePipeFd, "W", 1);
+    } while (nWrite == -1 && errno == EINTR);
+
+    if (nWrite != 1 && errno != EAGAIN) {
+        ALOGW("Could not write wake signal, errno=%d", errno);
+    }
+}
+
+void EventHub::scanDevicesLocked() {
+    status_t res = scanDirLocked(DEVICE_PATH);
+    if(res < 0) {
+        ALOGE("scan dir failed for %s\n", DEVICE_PATH);
+    }
+    if (mDevices.indexOfKey(VIRTUAL_KEYBOARD_ID) < 0) {
+        createVirtualKeyboardLocked();
+    }
+}
+
+// ----------------------------------------------------------------------------
+
+static bool containsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex) {
+    const uint8_t* end = array + endIndex;
+    array += startIndex;
+    while (array != end) {
+        if (*(array++) != 0) {
+            return true;
+        }
+    }
+    return false;
+}
+
+static const int32_t GAMEPAD_KEYCODES[] = {
+        AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C,
+        AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z,
+        AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1,
+        AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2,
+        AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR,
+        AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE,
+        AKEYCODE_BUTTON_1, AKEYCODE_BUTTON_2, AKEYCODE_BUTTON_3, AKEYCODE_BUTTON_4,
+        AKEYCODE_BUTTON_5, AKEYCODE_BUTTON_6, AKEYCODE_BUTTON_7, AKEYCODE_BUTTON_8,
+        AKEYCODE_BUTTON_9, AKEYCODE_BUTTON_10, AKEYCODE_BUTTON_11, AKEYCODE_BUTTON_12,
+        AKEYCODE_BUTTON_13, AKEYCODE_BUTTON_14, AKEYCODE_BUTTON_15, AKEYCODE_BUTTON_16,
+};
+
+status_t EventHub::openDeviceLocked(const char *devicePath) {
+    char buffer[80];
+
+    ALOGV("Opening device: %s", devicePath);
+
+    int fd = open(devicePath, O_RDWR | O_CLOEXEC);
+    if(fd < 0) {
+        ALOGE("could not open %s, %s\n", devicePath, strerror(errno));
+        return -1;
+    }
+
+    InputDeviceIdentifier identifier;
+
+    // Get device name.
+    if(ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) {
+        //fprintf(stderr, "could not get device name for %s, %s\n", devicePath, strerror(errno));
+    } else {
+        buffer[sizeof(buffer) - 1] = '\0';
+        identifier.name.setTo(buffer);
+    }
+
+    // Check to see if the device is on our excluded list
+    for (size_t i = 0; i < mExcludedDevices.size(); i++) {
+        const String8& item = mExcludedDevices.itemAt(i);
+        if (identifier.name == item) {
+            ALOGI("ignoring event id %s driver %s\n", devicePath, item.string());
+            close(fd);
+            return -1;
+        }
+    }
+
+    // Get device driver version.
+    int driverVersion;
+    if(ioctl(fd, EVIOCGVERSION, &driverVersion)) {
+        ALOGE("could not get driver version for %s, %s\n", devicePath, strerror(errno));
+        close(fd);
+        return -1;
+    }
+
+    // Get device identifier.
+    struct input_id inputId;
+    if(ioctl(fd, EVIOCGID, &inputId)) {
+        ALOGE("could not get device input id for %s, %s\n", devicePath, strerror(errno));
+        close(fd);
+        return -1;
+    }
+    identifier.bus = inputId.bustype;
+    identifier.product = inputId.product;
+    identifier.vendor = inputId.vendor;
+    identifier.version = inputId.version;
+
+    // Get device physical location.
+    if(ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) {
+        //fprintf(stderr, "could not get location for %s, %s\n", devicePath, strerror(errno));
+    } else {
+        buffer[sizeof(buffer) - 1] = '\0';
+        identifier.location.setTo(buffer);
+    }
+
+    // Get device unique id.
+    if(ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) {
+        //fprintf(stderr, "could not get idstring for %s, %s\n", devicePath, strerror(errno));
+    } else {
+        buffer[sizeof(buffer) - 1] = '\0';
+        identifier.uniqueId.setTo(buffer);
+    }
+
+    // Fill in the descriptor.
+    assignDescriptorLocked(identifier);
+
+    // Make file descriptor non-blocking for use with poll().
+    if (fcntl(fd, F_SETFL, O_NONBLOCK)) {
+        ALOGE("Error %d making device file descriptor non-blocking.", errno);
+        close(fd);
+        return -1;
+    }
+
+    // Allocate device.  (The device object takes ownership of the fd at this point.)
+    int32_t deviceId = mNextDeviceId++;
+    Device* device = new Device(fd, deviceId, String8(devicePath), identifier);
+
+    ALOGV("add device %d: %s\n", deviceId, devicePath);
+    ALOGV("  bus:        %04x\n"
+         "  vendor      %04x\n"
+         "  product     %04x\n"
+         "  version     %04x\n",
+        identifier.bus, identifier.vendor, identifier.product, identifier.version);
+    ALOGV("  name:       \"%s\"\n", identifier.name.string());
+    ALOGV("  location:   \"%s\"\n", identifier.location.string());
+    ALOGV("  unique id:  \"%s\"\n", identifier.uniqueId.string());
+    ALOGV("  descriptor: \"%s\"\n", identifier.descriptor.string());
+    ALOGV("  driver:     v%d.%d.%d\n",
+        driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff);
+
+    // Load the configuration file for the device.
+    loadConfigurationLocked(device);
+
+    // Figure out the kinds of events the device reports.
+    ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask);
+    ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(device->absBitmask)), device->absBitmask);
+    ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask);
+    ioctl(fd, EVIOCGBIT(EV_SW, sizeof(device->swBitmask)), device->swBitmask);
+    ioctl(fd, EVIOCGBIT(EV_LED, sizeof(device->ledBitmask)), device->ledBitmask);
+    ioctl(fd, EVIOCGBIT(EV_FF, sizeof(device->ffBitmask)), device->ffBitmask);
+    ioctl(fd, EVIOCGPROP(sizeof(device->propBitmask)), device->propBitmask);
+
+    // See if this is a keyboard.  Ignore everything in the button range except for
+    // joystick and gamepad buttons which are handled like keyboards for the most part.
+    bool haveKeyboardKeys = containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC))
+            || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK),
+                    sizeof_bit_array(KEY_MAX + 1));
+    bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
+                    sizeof_bit_array(BTN_MOUSE))
+            || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK),
+                    sizeof_bit_array(BTN_DIGI));
+    if (haveKeyboardKeys || haveGamepadButtons) {
+        device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
+    }
+
+    // See if this is a cursor device such as a trackball or mouse.
+    if (test_bit(BTN_MOUSE, device->keyBitmask)
+            && test_bit(REL_X, device->relBitmask)
+            && test_bit(REL_Y, device->relBitmask)) {
+        device->classes |= INPUT_DEVICE_CLASS_CURSOR;
+    }
+
+    // See if this is a touch pad.
+    // Is this a new modern multi-touch driver?
+    if (test_bit(ABS_MT_POSITION_X, device->absBitmask)
+            && test_bit(ABS_MT_POSITION_Y, device->absBitmask)) {
+        // Some joysticks such as the PS3 controller report axes that conflict
+        // with the ABS_MT range.  Try to confirm that the device really is
+        // a touch screen.
+        if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) {
+            device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
+        }
+    // Is this an old style single-touch driver?
+    } else if (test_bit(BTN_TOUCH, device->keyBitmask)
+            && test_bit(ABS_X, device->absBitmask)
+            && test_bit(ABS_Y, device->absBitmask)) {
+        device->classes |= INPUT_DEVICE_CLASS_TOUCH;
+    }
+
+    // See if this device is a joystick.
+    // Assumes that joysticks always have gamepad buttons in order to distinguish them
+    // from other devices such as accelerometers that also have absolute axes.
+    if (haveGamepadButtons) {
+        uint32_t assumedClasses = device->classes | INPUT_DEVICE_CLASS_JOYSTICK;
+        for (int i = 0; i <= ABS_MAX; i++) {
+            if (test_bit(i, device->absBitmask)
+                    && (getAbsAxisUsage(i, assumedClasses) & INPUT_DEVICE_CLASS_JOYSTICK)) {
+                device->classes = assumedClasses;
+                break;
+            }
+        }
+    }
+
+    // Check whether this device has switches.
+    for (int i = 0; i <= SW_MAX; i++) {
+        if (test_bit(i, device->swBitmask)) {
+            device->classes |= INPUT_DEVICE_CLASS_SWITCH;
+            break;
+        }
+    }
+
+    // Check whether this device supports the vibrator.
+    if (test_bit(FF_RUMBLE, device->ffBitmask)) {
+        device->classes |= INPUT_DEVICE_CLASS_VIBRATOR;
+    }
+
+    // Configure virtual keys.
+    if ((device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
+        // Load the virtual keys for the touch screen, if any.
+        // We do this now so that we can make sure to load the keymap if necessary.
+        status_t status = loadVirtualKeyMapLocked(device);
+        if (!status) {
+            device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
+        }
+    }
+
+    // Load the key map.
+    // We need to do this for joysticks too because the key layout may specify axes.
+    status_t keyMapStatus = NAME_NOT_FOUND;
+    if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
+        // Load the keymap for the device.
+        keyMapStatus = loadKeyMapLocked(device);
+    }
+
+    // Configure the keyboard, gamepad or virtual keyboard.
+    if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) {
+        // Register the keyboard as a built-in keyboard if it is eligible.
+        if (!keyMapStatus
+                && mBuiltInKeyboardId == NO_BUILT_IN_KEYBOARD
+                && isEligibleBuiltInKeyboard(device->identifier,
+                        device->configuration, &device->keyMap)) {
+            mBuiltInKeyboardId = device->id;
+        }
+
+        // 'Q' key support = cheap test of whether this is an alpha-capable kbd
+        if (hasKeycodeLocked(device, AKEYCODE_Q)) {
+            device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
+        }
+
+        // See if this device has a DPAD.
+        if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) &&
+                hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) &&
+                hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) &&
+                hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) &&
+                hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) {
+            device->classes |= INPUT_DEVICE_CLASS_DPAD;
+        }
+
+        // See if this device has a gamepad.
+        for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES)/sizeof(GAMEPAD_KEYCODES[0]); i++) {
+            if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) {
+                device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
+                break;
+            }
+        }
+
+        // Disable kernel key repeat since we handle it ourselves
+        unsigned int repeatRate[] = {0,0};
+        if (ioctl(fd, EVIOCSREP, repeatRate)) {
+            ALOGW("Unable to disable kernel key repeat for %s: %s", devicePath, strerror(errno));
+        }
+    }
+
+    // If the device isn't recognized as something we handle, don't monitor it.
+    if (device->classes == 0) {
+        ALOGV("Dropping device: id=%d, path='%s', name='%s'",
+                deviceId, devicePath, device->identifier.name.string());
+        delete device;
+        return -1;
+    }
+
+    // Determine whether the device is external or internal.
+    if (isExternalDeviceLocked(device)) {
+        device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
+    }
+
+    if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_DPAD)
+            && device->classes & INPUT_DEVICE_CLASS_GAMEPAD) {
+        device->controllerNumber = getNextControllerNumberLocked(device);
+        setLedForController(device);
+    }
+
+    // Register with epoll.
+    struct epoll_event eventItem;
+    memset(&eventItem, 0, sizeof(eventItem));
+    eventItem.events = EPOLLIN;
+    eventItem.data.u32 = deviceId;
+    if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)) {
+        ALOGE("Could not add device fd to epoll instance.  errno=%d", errno);
+        delete device;
+        return -1;
+    }
+
+    // Enable wake-lock behavior on kernels that support it.
+    // TODO: Only need this for devices that can really wake the system.
+#ifndef EVIOCSSUSPENDBLOCK
+    // uapi headers don't include EVIOCSSUSPENDBLOCK, and future kernels
+    // will use an epoll flag instead, so as long as we want to support
+    // this feature, we need to be prepared to define the ioctl ourselves.
+#define EVIOCSSUSPENDBLOCK _IOW('E', 0x91, int)
+#endif
+    bool usingSuspendBlockIoctl = !ioctl(fd, EVIOCSSUSPENDBLOCK, 1);
+
+    // Tell the kernel that we want to use the monotonic clock for reporting timestamps
+    // associated with input events.  This is important because the input system
+    // uses the timestamps extensively and assumes they were recorded using the monotonic
+    // clock.
+    //
+    // In older kernel, before Linux 3.4, there was no way to tell the kernel which
+    // clock to use to input event timestamps.  The standard kernel behavior was to
+    // record a real time timestamp, which isn't what we want.  Android kernels therefore
+    // contained a patch to the evdev_event() function in drivers/input/evdev.c to
+    // replace the call to do_gettimeofday() with ktime_get_ts() to cause the monotonic
+    // clock to be used instead of the real time clock.
+    //
+    // As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock.
+    // Therefore, we no longer require the Android-specific kernel patch described above
+    // as long as we make sure to set select the monotonic clock.  We do that here.
+    int clockId = CLOCK_MONOTONIC;
+    bool usingClockIoctl = !ioctl(fd, EVIOCSCLOCKID, &clockId);
+
+    ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
+            "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, "
+            "usingSuspendBlockIoctl=%s, usingClockIoctl=%s",
+         deviceId, fd, devicePath, device->identifier.name.string(),
+         device->classes,
+         device->configurationFile.string(),
+         device->keyMap.keyLayoutFile.string(),
+         device->keyMap.keyCharacterMapFile.string(),
+         toString(mBuiltInKeyboardId == deviceId),
+         toString(usingSuspendBlockIoctl), toString(usingClockIoctl));
+
+    addDeviceLocked(device);
+    return 0;
+}
+
+void EventHub::createVirtualKeyboardLocked() {
+    InputDeviceIdentifier identifier;
+    identifier.name = "Virtual";
+    identifier.uniqueId = "<virtual>";
+    assignDescriptorLocked(identifier);
+
+    Device* device = new Device(-1, VIRTUAL_KEYBOARD_ID, String8("<virtual>"), identifier);
+    device->classes = INPUT_DEVICE_CLASS_KEYBOARD
+            | INPUT_DEVICE_CLASS_ALPHAKEY
+            | INPUT_DEVICE_CLASS_DPAD
+            | INPUT_DEVICE_CLASS_VIRTUAL;
+    loadKeyMapLocked(device);
+    addDeviceLocked(device);
+}
+
+void EventHub::addDeviceLocked(Device* device) {
+    mDevices.add(device->id, device);
+    device->next = mOpeningDevices;
+    mOpeningDevices = device;
+}
+
+void EventHub::loadConfigurationLocked(Device* device) {
+    device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(
+            device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);
+    if (device->configurationFile.isEmpty()) {
+        ALOGD("No input device configuration file found for device '%s'.",
+                device->identifier.name.string());
+    } else {
+        status_t status = PropertyMap::load(device->configurationFile,
+                &device->configuration);
+        if (status) {
+            ALOGE("Error loading input device configuration file for device '%s'.  "
+                    "Using default configuration.",
+                    device->identifier.name.string());
+        }
+    }
+}
+
+status_t EventHub::loadVirtualKeyMapLocked(Device* device) {
+    // The virtual key map is supplied by the kernel as a system board property file.
+    String8 path;
+    path.append("/sys/board_properties/virtualkeys.");
+    path.append(device->identifier.name);
+    if (access(path.string(), R_OK)) {
+        return NAME_NOT_FOUND;
+    }
+    return VirtualKeyMap::load(path, &device->virtualKeyMap);
+}
+
+status_t EventHub::loadKeyMapLocked(Device* device) {
+    return device->keyMap.load(device->identifier, device->configuration);
+}
+
+bool EventHub::isExternalDeviceLocked(Device* device) {
+    if (device->configuration) {
+        bool value;
+        if (device->configuration->tryGetProperty(String8("device.internal"), value)) {
+            return !value;
+        }
+    }
+    return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH;
+}
+
+int32_t EventHub::getNextControllerNumberLocked(Device* device) {
+    if (mControllerNumbers.isFull()) {
+        ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s",
+                device->identifier.name.string());
+        return 0;
+    }
+    // Since the controller number 0 is reserved for non-controllers, translate all numbers up by
+    // one
+    return static_cast<int32_t>(mControllerNumbers.markFirstUnmarkedBit() + 1);
+}
+
+void EventHub::releaseControllerNumberLocked(Device* device) {
+    int32_t num = device->controllerNumber;
+    device->controllerNumber= 0;
+    if (num == 0) {
+        return;
+    }
+    mControllerNumbers.clearBit(static_cast<uint32_t>(num - 1));
+}
+
+void EventHub::setLedForController(Device* device) {
+    for (int i = 0; i < MAX_CONTROLLER_LEDS; i++) {
+        setLedStateLocked(device, ALED_CONTROLLER_1 + i, device->controllerNumber == i + 1);
+    }
+}
+
+bool EventHub::hasKeycodeLocked(Device* device, int keycode) const {
+    if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) {
+        return false;
+    }
+    
+    Vector<int32_t> scanCodes;
+    device->keyMap.keyLayoutMap->findScanCodesForKey(keycode, &scanCodes);
+    const size_t N = scanCodes.size();
+    for (size_t i=0; i<N && i<=KEY_MAX; i++) {
+        int32_t sc = scanCodes.itemAt(i);
+        if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) {
+            return true;
+        }
+    }
+    
+    return false;
+}
+
+status_t EventHub::mapLed(Device* device, int32_t led, int32_t* outScanCode) const {
+    if (!device->keyMap.haveKeyLayout() || !device->ledBitmask) {
+        return NAME_NOT_FOUND;
+    }
+
+    int32_t scanCode;
+    if(device->keyMap.keyLayoutMap->findScanCodeForLed(led, &scanCode) != NAME_NOT_FOUND) {
+        if(scanCode >= 0 && scanCode <= LED_MAX && test_bit(scanCode, device->ledBitmask)) {
+            *outScanCode = scanCode;
+            return NO_ERROR;
+        }
+    }
+    return NAME_NOT_FOUND;
+}
+
+status_t EventHub::closeDeviceByPathLocked(const char *devicePath) {
+    Device* device = getDeviceByPathLocked(devicePath);
+    if (device) {
+        closeDeviceLocked(device);
+        return 0;
+    }
+    ALOGV("Remove device: %s not found, device may already have been removed.", devicePath);
+    return -1;
+}
+
+void EventHub::closeAllDevicesLocked() {
+    while (mDevices.size() > 0) {
+        closeDeviceLocked(mDevices.valueAt(mDevices.size() - 1));
+    }
+}
+
+void EventHub::closeDeviceLocked(Device* device) {
+    ALOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n",
+         device->path.string(), device->identifier.name.string(), device->id,
+         device->fd, device->classes);
+
+    if (device->id == mBuiltInKeyboardId) {
+        ALOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
+                device->path.string(), mBuiltInKeyboardId);
+        mBuiltInKeyboardId = NO_BUILT_IN_KEYBOARD;
+    }
+
+    if (!device->isVirtual()) {
+        if (epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)) {
+            ALOGW("Could not remove device fd from epoll instance.  errno=%d", errno);
+        }
+    }
+
+    releaseControllerNumberLocked(device);
+
+    mDevices.removeItem(device->id);
+    device->close();
+
+    // Unlink for opening devices list if it is present.
+    Device* pred = NULL;
+    bool found = false;
+    for (Device* entry = mOpeningDevices; entry != NULL; ) {
+        if (entry == device) {
+            found = true;
+            break;
+        }
+        pred = entry;
+        entry = entry->next;
+    }
+    if (found) {
+        // Unlink the device from the opening devices list then delete it.
+        // We don't need to tell the client that the device was closed because
+        // it does not even know it was opened in the first place.
+        ALOGI("Device %s was immediately closed after opening.", device->path.string());
+        if (pred) {
+            pred->next = device->next;
+        } else {
+            mOpeningDevices = device->next;
+        }
+        delete device;
+    } else {
+        // Link into closing devices list.
+        // The device will be deleted later after we have informed the client.
+        device->next = mClosingDevices;
+        mClosingDevices = device;
+    }
+}
+
+status_t EventHub::readNotifyLocked() {
+    int res;
+    char devname[PATH_MAX];
+    char *filename;
+    char event_buf[512];
+    int event_size;
+    int event_pos = 0;
+    struct inotify_event *event;
+
+    ALOGV("EventHub::readNotify nfd: %d\n", mINotifyFd);
+    res = read(mINotifyFd, event_buf, sizeof(event_buf));
+    if(res < (int)sizeof(*event)) {
+        if(errno == EINTR)
+            return 0;
+        ALOGW("could not get event, %s\n", strerror(errno));
+        return -1;
+    }
+    //printf("got %d bytes of event information\n", res);
+
+    strcpy(devname, DEVICE_PATH);
+    filename = devname + strlen(devname);
+    *filename++ = '/';
+
+    while(res >= (int)sizeof(*event)) {
+        event = (struct inotify_event *)(event_buf + event_pos);
+        //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
+        if(event->len) {
+            strcpy(filename, event->name);
+            if(event->mask & IN_CREATE) {
+                openDeviceLocked(devname);
+            } else {
+                ALOGI("Removing device '%s' due to inotify event\n", devname);
+                closeDeviceByPathLocked(devname);
+            }
+        }
+        event_size = sizeof(*event) + event->len;
+        res -= event_size;
+        event_pos += event_size;
+    }
+    return 0;
+}
+
+status_t EventHub::scanDirLocked(const char *dirname)
+{
+    char devname[PATH_MAX];
+    char *filename;
+    DIR *dir;
+    struct dirent *de;
+    dir = opendir(dirname);
+    if(dir == NULL)
+        return -1;
+    strcpy(devname, dirname);
+    filename = devname + strlen(devname);
+    *filename++ = '/';
+    while((de = readdir(dir))) {
+        if(de->d_name[0] == '.' &&
+           (de->d_name[1] == '\0' ||
+            (de->d_name[1] == '.' && de->d_name[2] == '\0')))
+            continue;
+        strcpy(filename, de->d_name);
+        openDeviceLocked(devname);
+    }
+    closedir(dir);
+    return 0;
+}
+
+void EventHub::requestReopenDevices() {
+    ALOGV("requestReopenDevices() called");
+
+    AutoMutex _l(mLock);
+    mNeedToReopenDevices = true;
+}
+
+void EventHub::dump(String8& dump) {
+    dump.append("Event Hub State:\n");
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        dump.appendFormat(INDENT "BuiltInKeyboardId: %d\n", mBuiltInKeyboardId);
+
+        dump.append(INDENT "Devices:\n");
+
+        for (size_t i = 0; i < mDevices.size(); i++) {
+            const Device* device = mDevices.valueAt(i);
+            if (mBuiltInKeyboardId == device->id) {
+                dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n",
+                        device->id, device->identifier.name.string());
+            } else {
+                dump.appendFormat(INDENT2 "%d: %s\n", device->id,
+                        device->identifier.name.string());
+            }
+            dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
+            dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
+            dump.appendFormat(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.string());
+            dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string());
+            dump.appendFormat(INDENT3 "ControllerNumber: %d\n", device->controllerNumber);
+            dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string());
+            dump.appendFormat(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, "
+                    "product=0x%04x, version=0x%04x\n",
+                    device->identifier.bus, device->identifier.vendor,
+                    device->identifier.product, device->identifier.version);
+            dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n",
+                    device->keyMap.keyLayoutFile.string());
+            dump.appendFormat(INDENT3 "KeyCharacterMapFile: %s\n",
+                    device->keyMap.keyCharacterMapFile.string());
+            dump.appendFormat(INDENT3 "ConfigurationFile: %s\n",
+                    device->configurationFile.string());
+            dump.appendFormat(INDENT3 "HaveKeyboardLayoutOverlay: %s\n",
+                    toString(device->overlayKeyMap != NULL));
+        }
+    } // release lock
+}
+
+void EventHub::monitor() {
+    // Acquire and release the lock to ensure that the event hub has not deadlocked.
+    mLock.lock();
+    mLock.unlock();
+}
+
+
+}; // namespace android
diff --git a/libs/input/EventHub.h b/libs/input/EventHub.h
new file mode 100644
index 0000000..86c05af
--- /dev/null
+++ b/libs/input/EventHub.h
@@ -0,0 +1,455 @@
+/*
+ * Copyright (C) 2005 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 _RUNTIME_EVENT_HUB_H
+#define _RUNTIME_EVENT_HUB_H
+
+#include <input/Input.h>
+#include <input/InputDevice.h>
+#include <input/Keyboard.h>
+#include <input/KeyLayoutMap.h>
+#include <input/KeyCharacterMap.h>
+#include <input/VirtualKeyMap.h>
+#include <utils/String8.h>
+#include <utils/threads.h>
+#include <utils/Log.h>
+#include <utils/threads.h>
+#include <utils/List.h>
+#include <utils/Errors.h>
+#include <utils/PropertyMap.h>
+#include <utils/Vector.h>
+#include <utils/KeyedVector.h>
+#include <utils/BitSet.h>
+
+#include <linux/input.h>
+#include <sys/epoll.h>
+
+/* Convenience constants. */
+
+#define BTN_FIRST 0x100  // first button code
+#define BTN_LAST 0x15f   // last button code
+
+/*
+ * These constants are used privately in Android to pass raw timestamps
+ * through evdev from uinput device drivers because there is currently no
+ * other way to transfer this information.  The evdev driver automatically
+ * timestamps all input events with the time they were posted and clobbers
+ * whatever information was passed in.
+ *
+ * For the purposes of this hack, the timestamp is specified in the
+ * CLOCK_MONOTONIC timebase and is split into two EV_MSC events specifying
+ * seconds and microseconds.
+ */
+#define MSC_ANDROID_TIME_SEC 0x6
+#define MSC_ANDROID_TIME_USEC 0x7
+
+namespace android {
+
+enum {
+    // Device id of a special "virtual" keyboard that is always present.
+    VIRTUAL_KEYBOARD_ID = -1,
+    // Device id of the "built-in" keyboard if there is one.
+    BUILT_IN_KEYBOARD_ID = 0,
+};
+
+/*
+ * A raw event as retrieved from the EventHub.
+ */
+struct RawEvent {
+    nsecs_t when;
+    int32_t deviceId;
+    int32_t type;
+    int32_t code;
+    int32_t value;
+};
+
+/* Describes an absolute axis. */
+struct RawAbsoluteAxisInfo {
+    bool valid; // true if the information is valid, false otherwise
+
+    int32_t minValue;  // minimum value
+    int32_t maxValue;  // maximum value
+    int32_t flat;      // center flat position, eg. flat == 8 means center is between -8 and 8
+    int32_t fuzz;      // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
+    int32_t resolution; // resolution in units per mm or radians per mm
+
+    inline void clear() {
+        valid = false;
+        minValue = 0;
+        maxValue = 0;
+        flat = 0;
+        fuzz = 0;
+        resolution = 0;
+    }
+};
+
+/*
+ * Input device classes.
+ */
+enum {
+    /* The input device is a keyboard or has buttons. */
+    INPUT_DEVICE_CLASS_KEYBOARD      = 0x00000001,
+
+    /* The input device is an alpha-numeric keyboard (not just a dial pad). */
+    INPUT_DEVICE_CLASS_ALPHAKEY      = 0x00000002,
+
+    /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
+    INPUT_DEVICE_CLASS_TOUCH         = 0x00000004,
+
+    /* The input device is a cursor device such as a trackball or mouse. */
+    INPUT_DEVICE_CLASS_CURSOR        = 0x00000008,
+
+    /* The input device is a multi-touch touchscreen. */
+    INPUT_DEVICE_CLASS_TOUCH_MT      = 0x00000010,
+
+    /* The input device is a directional pad (implies keyboard, has DPAD keys). */
+    INPUT_DEVICE_CLASS_DPAD          = 0x00000020,
+
+    /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
+    INPUT_DEVICE_CLASS_GAMEPAD       = 0x00000040,
+
+    /* The input device has switches. */
+    INPUT_DEVICE_CLASS_SWITCH        = 0x00000080,
+
+    /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
+    INPUT_DEVICE_CLASS_JOYSTICK      = 0x00000100,
+
+    /* The input device has a vibrator (supports FF_RUMBLE). */
+    INPUT_DEVICE_CLASS_VIBRATOR      = 0x00000200,
+
+    /* The input device is virtual (not a real device, not part of UI configuration). */
+    INPUT_DEVICE_CLASS_VIRTUAL       = 0x40000000,
+
+    /* The input device is external (not built-in). */
+    INPUT_DEVICE_CLASS_EXTERNAL      = 0x80000000,
+};
+
+/*
+ * Gets the class that owns an axis, in cases where multiple classes might claim
+ * the same axis for different purposes.
+ */
+extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses);
+
+/*
+ * Grand Central Station for events.
+ *
+ * The event hub aggregates input events received across all known input
+ * devices on the system, including devices that may be emulated by the simulator
+ * environment.  In addition, the event hub generates fake input events to indicate
+ * when devices are added or removed.
+ *
+ * The event hub provides a stream of input events (via the getEvent function).
+ * It also supports querying the current actual state of input devices such as identifying
+ * which keys are currently down.  Finally, the event hub keeps track of the capabilities of
+ * individual input devices, such as their class and the set of key codes that they support.
+ */
+class EventHubInterface : public virtual RefBase {
+protected:
+    EventHubInterface() { }
+    virtual ~EventHubInterface() { }
+
+public:
+    // Synthetic raw event type codes produced when devices are added or removed.
+    enum {
+        // Sent when a device is added.
+        DEVICE_ADDED = 0x10000000,
+        // Sent when a device is removed.
+        DEVICE_REMOVED = 0x20000000,
+        // Sent when all added/removed devices from the most recent scan have been reported.
+        // This event is always sent at least once.
+        FINISHED_DEVICE_SCAN = 0x30000000,
+
+        FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
+    };
+
+    virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
+
+    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
+
+    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0;
+
+    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
+
+    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
+            RawAbsoluteAxisInfo* outAxisInfo) const = 0;
+
+    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
+
+    virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
+
+    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
+            int32_t* outKeycode, uint32_t* outFlags) const = 0;
+
+    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
+            AxisInfo* outAxisInfo) const = 0;
+
+    // Sets devices that are excluded from opening.
+    // This can be used to ignore input devices for sensors.
+    virtual void setExcludedDevices(const Vector<String8>& devices) = 0;
+
+    /*
+     * Wait for events to become available and returns them.
+     * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
+     * This ensures that the device will not go to sleep while the event is being processed.
+     * If the device needs to remain awake longer than that, then the caller is responsible
+     * for taking care of it (say, by poking the power manager user activity timer).
+     *
+     * The timeout is advisory only.  If the device is asleep, it will not wake just to
+     * service the timeout.
+     *
+     * Returns the number of events obtained, or 0 if the timeout expired.
+     */
+    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
+
+    /*
+     * Query current input state.
+     */
+    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
+    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
+    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
+    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
+            int32_t* outValue) const = 0;
+
+    /*
+     * Examine key input devices for specific framework keycode support
+     */
+    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
+            uint8_t* outFlags) const = 0;
+
+    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
+
+    /* LED related functions expect Android LED constants, not scan codes or HID usages */
+    virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
+    virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
+
+    virtual void getVirtualKeyDefinitions(int32_t deviceId,
+            Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
+
+    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
+    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0;
+
+    /* Control the vibrator. */
+    virtual void vibrate(int32_t deviceId, nsecs_t duration) = 0;
+    virtual void cancelVibrate(int32_t deviceId) = 0;
+
+    /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
+    virtual void requestReopenDevices() = 0;
+
+    /* Wakes up getEvents() if it is blocked on a read. */
+    virtual void wake() = 0;
+
+    /* Dump EventHub state to a string. */
+    virtual void dump(String8& dump) = 0;
+
+    /* Called by the heatbeat to ensures that the reader has not deadlocked. */
+    virtual void monitor() = 0;
+};
+
+class EventHub : public EventHubInterface
+{
+public:
+    EventHub();
+
+    virtual uint32_t getDeviceClasses(int32_t deviceId) const;
+
+    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const;
+
+    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const;
+
+    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const;
+
+    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
+            RawAbsoluteAxisInfo* outAxisInfo) const;
+
+    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const;
+
+    virtual bool hasInputProperty(int32_t deviceId, int property) const;
+
+    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
+            int32_t* outKeycode, uint32_t* outFlags) const;
+
+    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
+            AxisInfo* outAxisInfo) const;
+
+    virtual void setExcludedDevices(const Vector<String8>& devices);
+
+    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const;
+    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const;
+    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const;
+    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const;
+
+    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags) const;
+
+    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize);
+
+    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const;
+    virtual bool hasLed(int32_t deviceId, int32_t led) const;
+    virtual void setLedState(int32_t deviceId, int32_t led, bool on);
+
+    virtual void getVirtualKeyDefinitions(int32_t deviceId,
+            Vector<VirtualKeyDefinition>& outVirtualKeys) const;
+
+    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const;
+    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map);
+
+    virtual void vibrate(int32_t deviceId, nsecs_t duration);
+    virtual void cancelVibrate(int32_t deviceId);
+
+    virtual void requestReopenDevices();
+
+    virtual void wake();
+
+    virtual void dump(String8& dump);
+    virtual void monitor();
+
+protected:
+    virtual ~EventHub();
+
+private:
+    struct Device {
+        Device* next;
+
+        int fd; // may be -1 if device is virtual
+        const int32_t id;
+        const String8 path;
+        const InputDeviceIdentifier identifier;
+
+        uint32_t classes;
+
+        uint8_t keyBitmask[(KEY_MAX + 1) / 8];
+        uint8_t absBitmask[(ABS_MAX + 1) / 8];
+        uint8_t relBitmask[(REL_MAX + 1) / 8];
+        uint8_t swBitmask[(SW_MAX + 1) / 8];
+        uint8_t ledBitmask[(LED_MAX + 1) / 8];
+        uint8_t ffBitmask[(FF_MAX + 1) / 8];
+        uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8];
+
+        String8 configurationFile;
+        PropertyMap* configuration;
+        VirtualKeyMap* virtualKeyMap;
+        KeyMap keyMap;
+
+        sp<KeyCharacterMap> overlayKeyMap;
+        sp<KeyCharacterMap> combinedKeyMap;
+
+        bool ffEffectPlaying;
+        int16_t ffEffectId; // initially -1
+
+        int32_t controllerNumber;
+
+        int32_t timestampOverrideSec;
+        int32_t timestampOverrideUsec;
+
+        Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier);
+        ~Device();
+
+        void close();
+
+        inline bool isVirtual() const { return fd < 0; }
+
+        const sp<KeyCharacterMap>& getKeyCharacterMap() const {
+            if (combinedKeyMap != NULL) {
+                return combinedKeyMap;
+            }
+            return keyMap.keyCharacterMap;
+        }
+    };
+
+    status_t openDeviceLocked(const char *devicePath);
+    void createVirtualKeyboardLocked();
+    void addDeviceLocked(Device* device);
+    void assignDescriptorLocked(InputDeviceIdentifier& identifier);
+
+    status_t closeDeviceByPathLocked(const char *devicePath);
+    void closeDeviceLocked(Device* device);
+    void closeAllDevicesLocked();
+
+    status_t scanDirLocked(const char *dirname);
+    void scanDevicesLocked();
+    status_t readNotifyLocked();
+
+    Device* getDeviceByDescriptorLocked(String8& descriptor) const;
+    Device* getDeviceLocked(int32_t deviceId) const;
+    Device* getDeviceByPathLocked(const char* devicePath) const;
+
+    bool hasKeycodeLocked(Device* device, int keycode) const;
+
+    void loadConfigurationLocked(Device* device);
+    status_t loadVirtualKeyMapLocked(Device* device);
+    status_t loadKeyMapLocked(Device* device);
+
+    bool isExternalDeviceLocked(Device* device);
+
+    int32_t getNextControllerNumberLocked(Device* device);
+    void releaseControllerNumberLocked(Device* device);
+    void setLedForController(Device* device);
+
+    status_t mapLed(Device* device, int32_t led, int32_t* outScanCode) const;
+    void setLedStateLocked(Device* device, int32_t led, bool on);
+
+    // Protect all internal state.
+    mutable Mutex mLock;
+
+    // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
+    // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
+    enum {
+        // Must not conflict with any other assigned device ids, including
+        // the virtual keyboard id (-1).
+        NO_BUILT_IN_KEYBOARD = -2,
+    };
+    int32_t mBuiltInKeyboardId;
+
+    int32_t mNextDeviceId;
+
+    BitSet32 mControllerNumbers;
+
+    KeyedVector<int32_t, Device*> mDevices;
+
+    Device *mOpeningDevices;
+    Device *mClosingDevices;
+
+    bool mNeedToSendFinishedDeviceScan;
+    bool mNeedToReopenDevices;
+    bool mNeedToScanDevices;
+    Vector<String8> mExcludedDevices;
+
+    int mEpollFd;
+    int mINotifyFd;
+    int mWakeReadPipeFd;
+    int mWakeWritePipeFd;
+
+    // Ids used for epoll notifications not associated with devices.
+    static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
+    static const uint32_t EPOLL_ID_WAKE = 0x80000002;
+
+    // Epoll FD list size hint.
+    static const int EPOLL_SIZE_HINT = 8;
+
+    // Maximum number of signalled FDs to handle at a time.
+    static const int EPOLL_MAX_EVENTS = 16;
+
+    // The array of pending epoll events and the index of the next event to be handled.
+    struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
+    size_t mPendingEventCount;
+    size_t mPendingEventIndex;
+    bool mPendingINotify;
+};
+
+}; // namespace android
+
+#endif // _RUNTIME_EVENT_HUB_H
diff --git a/services/input/InputApplication.cpp b/libs/input/InputApplication.cpp
similarity index 100%
rename from services/input/InputApplication.cpp
rename to libs/input/InputApplication.cpp
diff --git a/services/input/InputApplication.h b/libs/input/InputApplication.h
similarity index 100%
rename from services/input/InputApplication.h
rename to libs/input/InputApplication.h
diff --git a/libs/input/InputDispatcher.cpp b/libs/input/InputDispatcher.cpp
new file mode 100644
index 0000000..4d44787
--- /dev/null
+++ b/libs/input/InputDispatcher.cpp
@@ -0,0 +1,4510 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#define LOG_TAG "InputDispatcher"
+#define ATRACE_TAG ATRACE_TAG_INPUT
+
+//#define LOG_NDEBUG 0
+
+// Log detailed debug messages about each inbound event notification to the dispatcher.
+#define DEBUG_INBOUND_EVENT_DETAILS 0
+
+// Log detailed debug messages about each outbound event processed by the dispatcher.
+#define DEBUG_OUTBOUND_EVENT_DETAILS 0
+
+// Log debug messages about the dispatch cycle.
+#define DEBUG_DISPATCH_CYCLE 0
+
+// Log debug messages about registrations.
+#define DEBUG_REGISTRATION 0
+
+// Log debug messages about input event injection.
+#define DEBUG_INJECTION 0
+
+// Log debug messages about input focus tracking.
+#define DEBUG_FOCUS 0
+
+// Log debug messages about the app switch latency optimization.
+#define DEBUG_APP_SWITCH 0
+
+// Log debug messages about hover events.
+#define DEBUG_HOVER 0
+
+#include "InputDispatcher.h"
+
+#include <utils/Trace.h>
+#include <cutils/log.h>
+#include <androidfw/PowerManager.h>
+
+#include <stddef.h>
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <time.h>
+
+#define INDENT "  "
+#define INDENT2 "    "
+#define INDENT3 "      "
+#define INDENT4 "        "
+
+namespace android {
+
+// Default input dispatching timeout if there is no focused application or paused window
+// from which to determine an appropriate dispatching timeout.
+const nsecs_t DEFAULT_INPUT_DISPATCHING_TIMEOUT = 5000 * 1000000LL; // 5 sec
+
+// Amount of time to allow for all pending events to be processed when an app switch
+// key is on the way.  This is used to preempt input dispatch and drop input events
+// when an application takes too long to respond and the user has pressed an app switch key.
+const nsecs_t APP_SWITCH_TIMEOUT = 500 * 1000000LL; // 0.5sec
+
+// Amount of time to allow for an event to be dispatched (measured since its eventTime)
+// before considering it stale and dropping it.
+const nsecs_t STALE_EVENT_TIMEOUT = 10000 * 1000000LL; // 10sec
+
+// Amount of time to allow touch events to be streamed out to a connection before requiring
+// that the first event be finished.  This value extends the ANR timeout by the specified
+// amount.  For example, if streaming is allowed to get ahead by one second relative to the
+// queue of waiting unfinished events, then ANRs will similarly be delayed by one second.
+const nsecs_t STREAM_AHEAD_EVENT_TIMEOUT = 500 * 1000000LL; // 0.5sec
+
+// Log a warning when an event takes longer than this to process, even if an ANR does not occur.
+const nsecs_t SLOW_EVENT_PROCESSING_WARNING_TIMEOUT = 2000 * 1000000LL; // 2sec
+
+// Number of recent events to keep for debugging purposes.
+const size_t RECENT_QUEUE_MAX_SIZE = 10;
+
+static inline nsecs_t now() {
+    return systemTime(SYSTEM_TIME_MONOTONIC);
+}
+
+static inline const char* toString(bool value) {
+    return value ? "true" : "false";
+}
+
+static inline int32_t getMotionEventActionPointerIndex(int32_t action) {
+    return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
+            >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+}
+
+static bool isValidKeyAction(int32_t action) {
+    switch (action) {
+    case AKEY_EVENT_ACTION_DOWN:
+    case AKEY_EVENT_ACTION_UP:
+        return true;
+    default:
+        return false;
+    }
+}
+
+static bool validateKeyEvent(int32_t action) {
+    if (! isValidKeyAction(action)) {
+        ALOGE("Key event has invalid action code 0x%x", action);
+        return false;
+    }
+    return true;
+}
+
+static bool isValidMotionAction(int32_t action, size_t pointerCount) {
+    switch (action & AMOTION_EVENT_ACTION_MASK) {
+    case AMOTION_EVENT_ACTION_DOWN:
+    case AMOTION_EVENT_ACTION_UP:
+    case AMOTION_EVENT_ACTION_CANCEL:
+    case AMOTION_EVENT_ACTION_MOVE:
+    case AMOTION_EVENT_ACTION_OUTSIDE:
+    case AMOTION_EVENT_ACTION_HOVER_ENTER:
+    case AMOTION_EVENT_ACTION_HOVER_MOVE:
+    case AMOTION_EVENT_ACTION_HOVER_EXIT:
+    case AMOTION_EVENT_ACTION_SCROLL:
+        return true;
+    case AMOTION_EVENT_ACTION_POINTER_DOWN:
+    case AMOTION_EVENT_ACTION_POINTER_UP: {
+        int32_t index = getMotionEventActionPointerIndex(action);
+        return index >= 0 && size_t(index) < pointerCount;
+    }
+    default:
+        return false;
+    }
+}
+
+static bool validateMotionEvent(int32_t action, size_t pointerCount,
+        const PointerProperties* pointerProperties) {
+    if (! isValidMotionAction(action, pointerCount)) {
+        ALOGE("Motion event has invalid action code 0x%x", action);
+        return false;
+    }
+    if (pointerCount < 1 || pointerCount > MAX_POINTERS) {
+        ALOGE("Motion event has invalid pointer count %d; value must be between 1 and %d.",
+                pointerCount, MAX_POINTERS);
+        return false;
+    }
+    BitSet32 pointerIdBits;
+    for (size_t i = 0; i < pointerCount; i++) {
+        int32_t id = pointerProperties[i].id;
+        if (id < 0 || id > MAX_POINTER_ID) {
+            ALOGE("Motion event has invalid pointer id %d; value must be between 0 and %d",
+                    id, MAX_POINTER_ID);
+            return false;
+        }
+        if (pointerIdBits.hasBit(id)) {
+            ALOGE("Motion event has duplicate pointer id %d", id);
+            return false;
+        }
+        pointerIdBits.markBit(id);
+    }
+    return true;
+}
+
+static bool isMainDisplay(int32_t displayId) {
+    return displayId == ADISPLAY_ID_DEFAULT || displayId == ADISPLAY_ID_NONE;
+}
+
+static void dumpRegion(String8& dump, const SkRegion& region) {
+    if (region.isEmpty()) {
+        dump.append("<empty>");
+        return;
+    }
+
+    bool first = true;
+    for (SkRegion::Iterator it(region); !it.done(); it.next()) {
+        if (first) {
+            first = false;
+        } else {
+            dump.append("|");
+        }
+        const SkIRect& rect = it.rect();
+        dump.appendFormat("[%d,%d][%d,%d]", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
+    }
+}
+
+
+// --- InputDispatcher ---
+
+InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy) :
+    mPolicy(policy),
+    mPendingEvent(NULL), mAppSwitchSawKeyDown(false), mAppSwitchDueTime(LONG_LONG_MAX),
+    mNextUnblockedEvent(NULL),
+    mDispatchEnabled(false), mDispatchFrozen(false), mInputFilterEnabled(false),
+    mInputTargetWaitCause(INPUT_TARGET_WAIT_CAUSE_NONE) {
+    mLooper = new Looper(false);
+
+    mKeyRepeatState.lastKeyEntry = NULL;
+
+    policy->getDispatcherConfiguration(&mConfig);
+}
+
+InputDispatcher::~InputDispatcher() {
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        resetKeyRepeatLocked();
+        releasePendingEventLocked();
+        drainInboundQueueLocked();
+    }
+
+    while (mConnectionsByFd.size() != 0) {
+        unregisterInputChannel(mConnectionsByFd.valueAt(0)->inputChannel);
+    }
+}
+
+void InputDispatcher::dispatchOnce() {
+    nsecs_t nextWakeupTime = LONG_LONG_MAX;
+    { // acquire lock
+        AutoMutex _l(mLock);
+        mDispatcherIsAliveCondition.broadcast();
+
+        // Run a dispatch loop if there are no pending commands.
+        // The dispatch loop might enqueue commands to run afterwards.
+        if (!haveCommandsLocked()) {
+            dispatchOnceInnerLocked(&nextWakeupTime);
+        }
+
+        // Run all pending commands if there are any.
+        // If any commands were run then force the next poll to wake up immediately.
+        if (runCommandsLockedInterruptible()) {
+            nextWakeupTime = LONG_LONG_MIN;
+        }
+    } // release lock
+
+    // Wait for callback or timeout or wake.  (make sure we round up, not down)
+    nsecs_t currentTime = now();
+    int timeoutMillis = toMillisecondTimeoutDelay(currentTime, nextWakeupTime);
+    mLooper->pollOnce(timeoutMillis);
+}
+
+void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
+    nsecs_t currentTime = now();
+
+    // Reset the key repeat timer whenever we disallow key events, even if the next event
+    // is not a key.  This is to ensure that we abort a key repeat if the device is just coming
+    // out of sleep.
+    if (!mPolicy->isKeyRepeatEnabled()) {
+        resetKeyRepeatLocked();
+    }
+
+    // If dispatching is frozen, do not process timeouts or try to deliver any new events.
+    if (mDispatchFrozen) {
+#if DEBUG_FOCUS
+        ALOGD("Dispatch frozen.  Waiting some more.");
+#endif
+        return;
+    }
+
+    // Optimize latency of app switches.
+    // Essentially we start a short timeout when an app switch key (HOME / ENDCALL) has
+    // been pressed.  When it expires, we preempt dispatch and drop all other pending events.
+    bool isAppSwitchDue = mAppSwitchDueTime <= currentTime;
+    if (mAppSwitchDueTime < *nextWakeupTime) {
+        *nextWakeupTime = mAppSwitchDueTime;
+    }
+
+    // Ready to start a new event.
+    // If we don't already have a pending event, go grab one.
+    if (! mPendingEvent) {
+        if (mInboundQueue.isEmpty()) {
+            if (isAppSwitchDue) {
+                // The inbound queue is empty so the app switch key we were waiting
+                // for will never arrive.  Stop waiting for it.
+                resetPendingAppSwitchLocked(false);
+                isAppSwitchDue = false;
+            }
+
+            // Synthesize a key repeat if appropriate.
+            if (mKeyRepeatState.lastKeyEntry) {
+                if (currentTime >= mKeyRepeatState.nextRepeatTime) {
+                    mPendingEvent = synthesizeKeyRepeatLocked(currentTime);
+                } else {
+                    if (mKeyRepeatState.nextRepeatTime < *nextWakeupTime) {
+                        *nextWakeupTime = mKeyRepeatState.nextRepeatTime;
+                    }
+                }
+            }
+
+            // Nothing to do if there is no pending event.
+            if (!mPendingEvent) {
+                return;
+            }
+        } else {
+            // Inbound queue has at least one entry.
+            mPendingEvent = mInboundQueue.dequeueAtHead();
+            traceInboundQueueLengthLocked();
+        }
+
+        // Poke user activity for this event.
+        if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) {
+            pokeUserActivityLocked(mPendingEvent);
+        }
+
+        // Get ready to dispatch the event.
+        resetANRTimeoutsLocked();
+    }
+
+    // Now we have an event to dispatch.
+    // All events are eventually dequeued and processed this way, even if we intend to drop them.
+    ALOG_ASSERT(mPendingEvent != NULL);
+    bool done = false;
+    DropReason dropReason = DROP_REASON_NOT_DROPPED;
+    if (!(mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER)) {
+        dropReason = DROP_REASON_POLICY;
+    } else if (!mDispatchEnabled) {
+        dropReason = DROP_REASON_DISABLED;
+    }
+
+    if (mNextUnblockedEvent == mPendingEvent) {
+        mNextUnblockedEvent = NULL;
+    }
+
+    switch (mPendingEvent->type) {
+    case EventEntry::TYPE_CONFIGURATION_CHANGED: {
+        ConfigurationChangedEntry* typedEntry =
+                static_cast<ConfigurationChangedEntry*>(mPendingEvent);
+        done = dispatchConfigurationChangedLocked(currentTime, typedEntry);
+        dropReason = DROP_REASON_NOT_DROPPED; // configuration changes are never dropped
+        break;
+    }
+
+    case EventEntry::TYPE_DEVICE_RESET: {
+        DeviceResetEntry* typedEntry =
+                static_cast<DeviceResetEntry*>(mPendingEvent);
+        done = dispatchDeviceResetLocked(currentTime, typedEntry);
+        dropReason = DROP_REASON_NOT_DROPPED; // device resets are never dropped
+        break;
+    }
+
+    case EventEntry::TYPE_KEY: {
+        KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent);
+        if (isAppSwitchDue) {
+            if (isAppSwitchKeyEventLocked(typedEntry)) {
+                resetPendingAppSwitchLocked(true);
+                isAppSwitchDue = false;
+            } else if (dropReason == DROP_REASON_NOT_DROPPED) {
+                dropReason = DROP_REASON_APP_SWITCH;
+            }
+        }
+        if (dropReason == DROP_REASON_NOT_DROPPED
+                && isStaleEventLocked(currentTime, typedEntry)) {
+            dropReason = DROP_REASON_STALE;
+        }
+        if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {
+            dropReason = DROP_REASON_BLOCKED;
+        }
+        done = dispatchKeyLocked(currentTime, typedEntry, &dropReason, nextWakeupTime);
+        break;
+    }
+
+    case EventEntry::TYPE_MOTION: {
+        MotionEntry* typedEntry = static_cast<MotionEntry*>(mPendingEvent);
+        if (dropReason == DROP_REASON_NOT_DROPPED && isAppSwitchDue) {
+            dropReason = DROP_REASON_APP_SWITCH;
+        }
+        if (dropReason == DROP_REASON_NOT_DROPPED
+                && isStaleEventLocked(currentTime, typedEntry)) {
+            dropReason = DROP_REASON_STALE;
+        }
+        if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {
+            dropReason = DROP_REASON_BLOCKED;
+        }
+        done = dispatchMotionLocked(currentTime, typedEntry,
+                &dropReason, nextWakeupTime);
+        break;
+    }
+
+    default:
+        ALOG_ASSERT(false);
+        break;
+    }
+
+    if (done) {
+        if (dropReason != DROP_REASON_NOT_DROPPED) {
+            dropInboundEventLocked(mPendingEvent, dropReason);
+        }
+
+        releasePendingEventLocked();
+        *nextWakeupTime = LONG_LONG_MIN;  // force next poll to wake up immediately
+    }
+}
+
+bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) {
+    bool needWake = mInboundQueue.isEmpty();
+    mInboundQueue.enqueueAtTail(entry);
+    traceInboundQueueLengthLocked();
+
+    switch (entry->type) {
+    case EventEntry::TYPE_KEY: {
+        // Optimize app switch latency.
+        // If the application takes too long to catch up then we drop all events preceding
+        // the app switch key.
+        KeyEntry* keyEntry = static_cast<KeyEntry*>(entry);
+        if (isAppSwitchKeyEventLocked(keyEntry)) {
+            if (keyEntry->action == AKEY_EVENT_ACTION_DOWN) {
+                mAppSwitchSawKeyDown = true;
+            } else if (keyEntry->action == AKEY_EVENT_ACTION_UP) {
+                if (mAppSwitchSawKeyDown) {
+#if DEBUG_APP_SWITCH
+                    ALOGD("App switch is pending!");
+#endif
+                    mAppSwitchDueTime = keyEntry->eventTime + APP_SWITCH_TIMEOUT;
+                    mAppSwitchSawKeyDown = false;
+                    needWake = true;
+                }
+            }
+        }
+        break;
+    }
+
+    case EventEntry::TYPE_MOTION: {
+        // Optimize case where the current application is unresponsive and the user
+        // decides to touch a window in a different application.
+        // If the application takes too long to catch up then we drop all events preceding
+        // the touch into the other window.
+        MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
+        if (motionEntry->action == AMOTION_EVENT_ACTION_DOWN
+                && (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER)
+                && mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY
+                && mInputTargetWaitApplicationHandle != NULL) {
+            int32_t displayId = motionEntry->displayId;
+            int32_t x = int32_t(motionEntry->pointerCoords[0].
+                    getAxisValue(AMOTION_EVENT_AXIS_X));
+            int32_t y = int32_t(motionEntry->pointerCoords[0].
+                    getAxisValue(AMOTION_EVENT_AXIS_Y));
+            sp<InputWindowHandle> touchedWindowHandle = findTouchedWindowAtLocked(displayId, x, y);
+            if (touchedWindowHandle != NULL
+                    && touchedWindowHandle->inputApplicationHandle
+                            != mInputTargetWaitApplicationHandle) {
+                // User touched a different application than the one we are waiting on.
+                // Flag the event, and start pruning the input queue.
+                mNextUnblockedEvent = motionEntry;
+                needWake = true;
+            }
+        }
+        break;
+    }
+    }
+
+    return needWake;
+}
+
+void InputDispatcher::addRecentEventLocked(EventEntry* entry) {
+    entry->refCount += 1;
+    mRecentQueue.enqueueAtTail(entry);
+    if (mRecentQueue.count() > RECENT_QUEUE_MAX_SIZE) {
+        mRecentQueue.dequeueAtHead()->release();
+    }
+}
+
+sp<InputWindowHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayId,
+        int32_t x, int32_t y) {
+    // Traverse windows from front to back to find touched window.
+    size_t numWindows = mWindowHandles.size();
+    for (size_t i = 0; i < numWindows; i++) {
+        sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i);
+        const InputWindowInfo* windowInfo = windowHandle->getInfo();
+        if (windowInfo->displayId == displayId) {
+            int32_t flags = windowInfo->layoutParamsFlags;
+            int32_t privateFlags = windowInfo->layoutParamsPrivateFlags;
+
+            if (windowInfo->visible) {
+                if (!(flags & InputWindowInfo::FLAG_NOT_TOUCHABLE)) {
+                    bool isTouchModal = (flags & (InputWindowInfo::FLAG_NOT_FOCUSABLE
+                            | InputWindowInfo::FLAG_NOT_TOUCH_MODAL)) == 0;
+                    if (isTouchModal || windowInfo->touchableRegionContainsPoint(x, y)) {
+                        // Found window.
+                        return windowHandle;
+                    }
+                }
+            }
+
+            if (privateFlags & InputWindowInfo::PRIVATE_FLAG_SYSTEM_ERROR) {
+                // Error window is on top but not visible, so touch is dropped.
+                return NULL;
+            }
+        }
+    }
+    return NULL;
+}
+
+void InputDispatcher::dropInboundEventLocked(EventEntry* entry, DropReason dropReason) {
+    const char* reason;
+    switch (dropReason) {
+    case DROP_REASON_POLICY:
+#if DEBUG_INBOUND_EVENT_DETAILS
+        ALOGD("Dropped event because policy consumed it.");
+#endif
+        reason = "inbound event was dropped because the policy consumed it";
+        break;
+    case DROP_REASON_DISABLED:
+        ALOGI("Dropped event because input dispatch is disabled.");
+        reason = "inbound event was dropped because input dispatch is disabled";
+        break;
+    case DROP_REASON_APP_SWITCH:
+        ALOGI("Dropped event because of pending overdue app switch.");
+        reason = "inbound event was dropped because of pending overdue app switch";
+        break;
+    case DROP_REASON_BLOCKED:
+        ALOGI("Dropped event because the current application is not responding and the user "
+                "has started interacting with a different application.");
+        reason = "inbound event was dropped because the current application is not responding "
+                "and the user has started interacting with a different application";
+        break;
+    case DROP_REASON_STALE:
+        ALOGI("Dropped event because it is stale.");
+        reason = "inbound event was dropped because it is stale";
+        break;
+    default:
+        ALOG_ASSERT(false);
+        return;
+    }
+
+    switch (entry->type) {
+    case EventEntry::TYPE_KEY: {
+        CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason);
+        synthesizeCancelationEventsForAllConnectionsLocked(options);
+        break;
+    }
+    case EventEntry::TYPE_MOTION: {
+        MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
+        if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
+            CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, reason);
+            synthesizeCancelationEventsForAllConnectionsLocked(options);
+        } else {
+            CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason);
+            synthesizeCancelationEventsForAllConnectionsLocked(options);
+        }
+        break;
+    }
+    }
+}
+
+bool InputDispatcher::isAppSwitchKeyCode(int32_t keyCode) {
+    return keyCode == AKEYCODE_HOME
+            || keyCode == AKEYCODE_ENDCALL
+            || keyCode == AKEYCODE_APP_SWITCH;
+}
+
+bool InputDispatcher::isAppSwitchKeyEventLocked(KeyEntry* keyEntry) {
+    return ! (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED)
+            && isAppSwitchKeyCode(keyEntry->keyCode)
+            && (keyEntry->policyFlags & POLICY_FLAG_TRUSTED)
+            && (keyEntry->policyFlags & POLICY_FLAG_PASS_TO_USER);
+}
+
+bool InputDispatcher::isAppSwitchPendingLocked() {
+    return mAppSwitchDueTime != LONG_LONG_MAX;
+}
+
+void InputDispatcher::resetPendingAppSwitchLocked(bool handled) {
+    mAppSwitchDueTime = LONG_LONG_MAX;
+
+#if DEBUG_APP_SWITCH
+    if (handled) {
+        ALOGD("App switch has arrived.");
+    } else {
+        ALOGD("App switch was abandoned.");
+    }
+#endif
+}
+
+bool InputDispatcher::isStaleEventLocked(nsecs_t currentTime, EventEntry* entry) {
+    return currentTime - entry->eventTime >= STALE_EVENT_TIMEOUT;
+}
+
+bool InputDispatcher::haveCommandsLocked() const {
+    return !mCommandQueue.isEmpty();
+}
+
+bool InputDispatcher::runCommandsLockedInterruptible() {
+    if (mCommandQueue.isEmpty()) {
+        return false;
+    }
+
+    do {
+        CommandEntry* commandEntry = mCommandQueue.dequeueAtHead();
+
+        Command command = commandEntry->command;
+        (this->*command)(commandEntry); // commands are implicitly 'LockedInterruptible'
+
+        commandEntry->connection.clear();
+        delete commandEntry;
+    } while (! mCommandQueue.isEmpty());
+    return true;
+}
+
+InputDispatcher::CommandEntry* InputDispatcher::postCommandLocked(Command command) {
+    CommandEntry* commandEntry = new CommandEntry(command);
+    mCommandQueue.enqueueAtTail(commandEntry);
+    return commandEntry;
+}
+
+void InputDispatcher::drainInboundQueueLocked() {
+    while (! mInboundQueue.isEmpty()) {
+        EventEntry* entry = mInboundQueue.dequeueAtHead();
+        releaseInboundEventLocked(entry);
+    }
+    traceInboundQueueLengthLocked();
+}
+
+void InputDispatcher::releasePendingEventLocked() {
+    if (mPendingEvent) {
+        resetANRTimeoutsLocked();
+        releaseInboundEventLocked(mPendingEvent);
+        mPendingEvent = NULL;
+    }
+}
+
+void InputDispatcher::releaseInboundEventLocked(EventEntry* entry) {
+    InjectionState* injectionState = entry->injectionState;
+    if (injectionState && injectionState->injectionResult == INPUT_EVENT_INJECTION_PENDING) {
+#if DEBUG_DISPATCH_CYCLE
+        ALOGD("Injected inbound event was dropped.");
+#endif
+        setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED);
+    }
+    if (entry == mNextUnblockedEvent) {
+        mNextUnblockedEvent = NULL;
+    }
+    addRecentEventLocked(entry);
+    entry->release();
+}
+
+void InputDispatcher::resetKeyRepeatLocked() {
+    if (mKeyRepeatState.lastKeyEntry) {
+        mKeyRepeatState.lastKeyEntry->release();
+        mKeyRepeatState.lastKeyEntry = NULL;
+    }
+}
+
+InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(nsecs_t currentTime) {
+    KeyEntry* entry = mKeyRepeatState.lastKeyEntry;
+
+    // Reuse the repeated key entry if it is otherwise unreferenced.
+    uint32_t policyFlags = (entry->policyFlags & POLICY_FLAG_RAW_MASK)
+            | POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_TRUSTED;
+    if (entry->refCount == 1) {
+        entry->recycle();
+        entry->eventTime = currentTime;
+        entry->policyFlags = policyFlags;
+        entry->repeatCount += 1;
+    } else {
+        KeyEntry* newEntry = new KeyEntry(currentTime,
+                entry->deviceId, entry->source, policyFlags,
+                entry->action, entry->flags, entry->keyCode, entry->scanCode,
+                entry->metaState, entry->repeatCount + 1, entry->downTime);
+
+        mKeyRepeatState.lastKeyEntry = newEntry;
+        entry->release();
+
+        entry = newEntry;
+    }
+    entry->syntheticRepeat = true;
+
+    // Increment reference count since we keep a reference to the event in
+    // mKeyRepeatState.lastKeyEntry in addition to the one we return.
+    entry->refCount += 1;
+
+    mKeyRepeatState.nextRepeatTime = currentTime + mConfig.keyRepeatDelay;
+    return entry;
+}
+
+bool InputDispatcher::dispatchConfigurationChangedLocked(
+        nsecs_t currentTime, ConfigurationChangedEntry* entry) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+    ALOGD("dispatchConfigurationChanged - eventTime=%lld", entry->eventTime);
+#endif
+
+    // Reset key repeating in case a keyboard device was added or removed or something.
+    resetKeyRepeatLocked();
+
+    // Enqueue a command to run outside the lock to tell the policy that the configuration changed.
+    CommandEntry* commandEntry = postCommandLocked(
+            & InputDispatcher::doNotifyConfigurationChangedInterruptible);
+    commandEntry->eventTime = entry->eventTime;
+    return true;
+}
+
+bool InputDispatcher::dispatchDeviceResetLocked(
+        nsecs_t currentTime, DeviceResetEntry* entry) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+    ALOGD("dispatchDeviceReset - eventTime=%lld, deviceId=%d", entry->eventTime, entry->deviceId);
+#endif
+
+    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
+            "device was reset");
+    options.deviceId = entry->deviceId;
+    synthesizeCancelationEventsForAllConnectionsLocked(options);
+    return true;
+}
+
+bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry,
+        DropReason* dropReason, nsecs_t* nextWakeupTime) {
+    // Preprocessing.
+    if (! entry->dispatchInProgress) {
+        if (entry->repeatCount == 0
+                && entry->action == AKEY_EVENT_ACTION_DOWN
+                && (entry->policyFlags & POLICY_FLAG_TRUSTED)
+                && (!(entry->policyFlags & POLICY_FLAG_DISABLE_KEY_REPEAT))) {
+            if (mKeyRepeatState.lastKeyEntry
+                    && mKeyRepeatState.lastKeyEntry->keyCode == entry->keyCode) {
+                // We have seen two identical key downs in a row which indicates that the device
+                // driver is automatically generating key repeats itself.  We take note of the
+                // repeat here, but we disable our own next key repeat timer since it is clear that
+                // we will not need to synthesize key repeats ourselves.
+                entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1;
+                resetKeyRepeatLocked();
+                mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves
+            } else {
+                // Not a repeat.  Save key down state in case we do see a repeat later.
+                resetKeyRepeatLocked();
+                mKeyRepeatState.nextRepeatTime = entry->eventTime + mConfig.keyRepeatTimeout;
+            }
+            mKeyRepeatState.lastKeyEntry = entry;
+            entry->refCount += 1;
+        } else if (! entry->syntheticRepeat) {
+            resetKeyRepeatLocked();
+        }
+
+        if (entry->repeatCount == 1) {
+            entry->flags |= AKEY_EVENT_FLAG_LONG_PRESS;
+        } else {
+            entry->flags &= ~AKEY_EVENT_FLAG_LONG_PRESS;
+        }
+
+        entry->dispatchInProgress = true;
+
+        logOutboundKeyDetailsLocked("dispatchKey - ", entry);
+    }
+
+    // Handle case where the policy asked us to try again later last time.
+    if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER) {
+        if (currentTime < entry->interceptKeyWakeupTime) {
+            if (entry->interceptKeyWakeupTime < *nextWakeupTime) {
+                *nextWakeupTime = entry->interceptKeyWakeupTime;
+            }
+            return false; // wait until next wakeup
+        }
+        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN;
+        entry->interceptKeyWakeupTime = 0;
+    }
+
+    // Give the policy a chance to intercept the key.
+    if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN) {
+        if (entry->policyFlags & POLICY_FLAG_PASS_TO_USER) {
+            CommandEntry* commandEntry = postCommandLocked(
+                    & InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible);
+            if (mFocusedWindowHandle != NULL) {
+                commandEntry->inputWindowHandle = mFocusedWindowHandle;
+            }
+            commandEntry->keyEntry = entry;
+            entry->refCount += 1;
+            return false; // wait for the command to run
+        } else {
+            entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE;
+        }
+    } else if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_SKIP) {
+        if (*dropReason == DROP_REASON_NOT_DROPPED) {
+            *dropReason = DROP_REASON_POLICY;
+        }
+    }
+
+    // Clean up if dropping the event.
+    if (*dropReason != DROP_REASON_NOT_DROPPED) {
+        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
+                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
+        return true;
+    }
+
+    // Identify targets.
+    Vector<InputTarget> inputTargets;
+    int32_t injectionResult = findFocusedWindowTargetsLocked(currentTime,
+            entry, inputTargets, nextWakeupTime);
+    if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
+        return false;
+    }
+
+    setInjectionResultLocked(entry, injectionResult);
+    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
+        return true;
+    }
+
+    addMonitoringTargetsLocked(inputTargets);
+
+    // Dispatch the key.
+    dispatchEventLocked(currentTime, entry, inputTargets);
+    return true;
+}
+
+void InputDispatcher::logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+    ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
+            "action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, "
+            "repeatCount=%d, downTime=%lld",
+            prefix,
+            entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
+            entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState,
+            entry->repeatCount, entry->downTime);
+#endif
+}
+
+bool InputDispatcher::dispatchMotionLocked(
+        nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) {
+    // Preprocessing.
+    if (! entry->dispatchInProgress) {
+        entry->dispatchInProgress = true;
+
+        logOutboundMotionDetailsLocked("dispatchMotion - ", entry);
+    }
+
+    // Clean up if dropping the event.
+    if (*dropReason != DROP_REASON_NOT_DROPPED) {
+        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
+                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
+        return true;
+    }
+
+    bool isPointerEvent = entry->source & AINPUT_SOURCE_CLASS_POINTER;
+
+    // Identify targets.
+    Vector<InputTarget> inputTargets;
+
+    bool conflictingPointerActions = false;
+    int32_t injectionResult;
+    if (isPointerEvent) {
+        // Pointer event.  (eg. touchscreen)
+        injectionResult = findTouchedWindowTargetsLocked(currentTime,
+                entry, inputTargets, nextWakeupTime, &conflictingPointerActions);
+    } else {
+        // Non touch event.  (eg. trackball)
+        injectionResult = findFocusedWindowTargetsLocked(currentTime,
+                entry, inputTargets, nextWakeupTime);
+    }
+    if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
+        return false;
+    }
+
+    setInjectionResultLocked(entry, injectionResult);
+    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
+        return true;
+    }
+
+    // TODO: support sending secondary display events to input monitors
+    if (isMainDisplay(entry->displayId)) {
+        addMonitoringTargetsLocked(inputTargets);
+    }
+
+    // Dispatch the motion.
+    if (conflictingPointerActions) {
+        CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
+                "conflicting pointer actions");
+        synthesizeCancelationEventsForAllConnectionsLocked(options);
+    }
+    dispatchEventLocked(currentTime, entry, inputTargets);
+    return true;
+}
+
+
+void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+    ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
+            "action=0x%x, flags=0x%x, "
+            "metaState=0x%x, buttonState=0x%x, "
+            "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld",
+            prefix,
+            entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
+            entry->action, entry->flags,
+            entry->metaState, entry->buttonState,
+            entry->edgeFlags, entry->xPrecision, entry->yPrecision,
+            entry->downTime);
+
+    for (uint32_t i = 0; i < entry->pointerCount; i++) {
+        ALOGD("  Pointer %d: id=%d, toolType=%d, "
+                "x=%f, y=%f, pressure=%f, size=%f, "
+                "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
+                "orientation=%f",
+                i, entry->pointerProperties[i].id,
+                entry->pointerProperties[i].toolType,
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
+                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
+    }
+#endif
+}
+
+void InputDispatcher::dispatchEventLocked(nsecs_t currentTime,
+        EventEntry* eventEntry, const Vector<InputTarget>& inputTargets) {
+#if DEBUG_DISPATCH_CYCLE
+    ALOGD("dispatchEventToCurrentInputTargets");
+#endif
+
+    ALOG_ASSERT(eventEntry->dispatchInProgress); // should already have been set to true
+
+    pokeUserActivityLocked(eventEntry);
+
+    for (size_t i = 0; i < inputTargets.size(); i++) {
+        const InputTarget& inputTarget = inputTargets.itemAt(i);
+
+        ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel);
+        if (connectionIndex >= 0) {
+            sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
+            prepareDispatchCycleLocked(currentTime, connection, eventEntry, &inputTarget);
+        } else {
+#if DEBUG_FOCUS
+            ALOGD("Dropping event delivery to target with channel '%s' because it "
+                    "is no longer registered with the input dispatcher.",
+                    inputTarget.inputChannel->getName().string());
+#endif
+        }
+    }
+}
+
+int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime,
+        const EventEntry* entry,
+        const sp<InputApplicationHandle>& applicationHandle,
+        const sp<InputWindowHandle>& windowHandle,
+        nsecs_t* nextWakeupTime, const char* reason) {
+    if (applicationHandle == NULL && windowHandle == NULL) {
+        if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY) {
+#if DEBUG_FOCUS
+            ALOGD("Waiting for system to become ready for input.  Reason: %s", reason);
+#endif
+            mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY;
+            mInputTargetWaitStartTime = currentTime;
+            mInputTargetWaitTimeoutTime = LONG_LONG_MAX;
+            mInputTargetWaitTimeoutExpired = false;
+            mInputTargetWaitApplicationHandle.clear();
+        }
+    } else {
+        if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) {
+#if DEBUG_FOCUS
+            ALOGD("Waiting for application to become ready for input: %s.  Reason: %s",
+                    getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(),
+                    reason);
+#endif
+            nsecs_t timeout;
+            if (windowHandle != NULL) {
+                timeout = windowHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT);
+            } else if (applicationHandle != NULL) {
+                timeout = applicationHandle->getDispatchingTimeout(
+                        DEFAULT_INPUT_DISPATCHING_TIMEOUT);
+            } else {
+                timeout = DEFAULT_INPUT_DISPATCHING_TIMEOUT;
+            }
+
+            mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY;
+            mInputTargetWaitStartTime = currentTime;
+            mInputTargetWaitTimeoutTime = currentTime + timeout;
+            mInputTargetWaitTimeoutExpired = false;
+            mInputTargetWaitApplicationHandle.clear();
+
+            if (windowHandle != NULL) {
+                mInputTargetWaitApplicationHandle = windowHandle->inputApplicationHandle;
+            }
+            if (mInputTargetWaitApplicationHandle == NULL && applicationHandle != NULL) {
+                mInputTargetWaitApplicationHandle = applicationHandle;
+            }
+        }
+    }
+
+    if (mInputTargetWaitTimeoutExpired) {
+        return INPUT_EVENT_INJECTION_TIMED_OUT;
+    }
+
+    if (currentTime >= mInputTargetWaitTimeoutTime) {
+        onANRLocked(currentTime, applicationHandle, windowHandle,
+                entry->eventTime, mInputTargetWaitStartTime, reason);
+
+        // Force poll loop to wake up immediately on next iteration once we get the
+        // ANR response back from the policy.
+        *nextWakeupTime = LONG_LONG_MIN;
+        return INPUT_EVENT_INJECTION_PENDING;
+    } else {
+        // Force poll loop to wake up when timeout is due.
+        if (mInputTargetWaitTimeoutTime < *nextWakeupTime) {
+            *nextWakeupTime = mInputTargetWaitTimeoutTime;
+        }
+        return INPUT_EVENT_INJECTION_PENDING;
+    }
+}
+
+void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
+        const sp<InputChannel>& inputChannel) {
+    if (newTimeout > 0) {
+        // Extend the timeout.
+        mInputTargetWaitTimeoutTime = now() + newTimeout;
+    } else {
+        // Give up.
+        mInputTargetWaitTimeoutExpired = true;
+
+        // Input state will not be realistic.  Mark it out of sync.
+        if (inputChannel.get()) {
+            ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
+            if (connectionIndex >= 0) {
+                sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
+                sp<InputWindowHandle> windowHandle = connection->inputWindowHandle;
+
+                if (windowHandle != NULL) {
+                    const InputWindowInfo* info = windowHandle->getInfo();
+                    if (info) {
+                        ssize_t stateIndex = mTouchStatesByDisplay.indexOfKey(info->displayId);
+                        if (stateIndex >= 0) {
+                            mTouchStatesByDisplay.editValueAt(stateIndex).removeWindow(
+                                    windowHandle);
+                        }
+                    }
+                }
+
+                if (connection->status == Connection::STATUS_NORMAL) {
+                    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
+                            "application not responding");
+                    synthesizeCancelationEventsForConnectionLocked(connection, options);
+                }
+            }
+        }
+    }
+}
+
+nsecs_t InputDispatcher::getTimeSpentWaitingForApplicationLocked(
+        nsecs_t currentTime) {
+    if (mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) {
+        return currentTime - mInputTargetWaitStartTime;
+    }
+    return 0;
+}
+
+void InputDispatcher::resetANRTimeoutsLocked() {
+#if DEBUG_FOCUS
+        ALOGD("Resetting ANR timeouts.");
+#endif
+
+    // Reset input target wait timeout.
+    mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_NONE;
+    mInputTargetWaitApplicationHandle.clear();
+}
+
+int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime,
+        const EventEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime) {
+    int32_t injectionResult;
+
+    // If there is no currently focused window and no focused application
+    // then drop the event.
+    if (mFocusedWindowHandle == NULL) {
+        if (mFocusedApplicationHandle != NULL) {
+            injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
+                    mFocusedApplicationHandle, NULL, nextWakeupTime,
+                    "Waiting because no window has focus but there is a "
+                    "focused application that may eventually add a window "
+                    "when it finishes starting up.");
+            goto Unresponsive;
+        }
+
+        ALOGI("Dropping event because there is no focused window or focused application.");
+        injectionResult = INPUT_EVENT_INJECTION_FAILED;
+        goto Failed;
+    }
+
+    // Check permissions.
+    if (! checkInjectionPermission(mFocusedWindowHandle, entry->injectionState)) {
+        injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
+        goto Failed;
+    }
+
+    // If the currently focused window is paused then keep waiting.
+    if (mFocusedWindowHandle->getInfo()->paused) {
+        injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
+                mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime,
+                "Waiting because the focused window is paused.");
+        goto Unresponsive;
+    }
+
+    // If the currently focused window is still working on previous events then keep waiting.
+    if (!isWindowReadyForMoreInputLocked(currentTime, mFocusedWindowHandle, entry)) {
+        injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
+                mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime,
+                "Waiting because the focused window has not finished "
+                "processing the input events that were previously delivered to it.");
+        goto Unresponsive;
+    }
+
+    // Success!  Output targets.
+    injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
+    addWindowTargetLocked(mFocusedWindowHandle,
+            InputTarget::FLAG_FOREGROUND | InputTarget::FLAG_DISPATCH_AS_IS, BitSet32(0),
+            inputTargets);
+
+    // Done.
+Failed:
+Unresponsive:
+    nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime);
+    updateDispatchStatisticsLocked(currentTime, entry,
+            injectionResult, timeSpentWaitingForApplication);
+#if DEBUG_FOCUS
+    ALOGD("findFocusedWindow finished: injectionResult=%d, "
+            "timeSpentWaitingForApplication=%0.1fms",
+            injectionResult, timeSpentWaitingForApplication / 1000000.0);
+#endif
+    return injectionResult;
+}
+
+int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
+        const MotionEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
+        bool* outConflictingPointerActions) {
+    enum InjectionPermission {
+        INJECTION_PERMISSION_UNKNOWN,
+        INJECTION_PERMISSION_GRANTED,
+        INJECTION_PERMISSION_DENIED
+    };
+
+    nsecs_t startTime = now();
+
+    // For security reasons, we defer updating the touch state until we are sure that
+    // event injection will be allowed.
+    //
+    // FIXME In the original code, screenWasOff could never be set to true.
+    //       The reason is that the POLICY_FLAG_WOKE_HERE
+    //       and POLICY_FLAG_BRIGHT_HERE flags were set only when preprocessing raw
+    //       EV_KEY, EV_REL and EV_ABS events.  As it happens, the touch event was
+    //       actually enqueued using the policyFlags that appeared in the final EV_SYN
+    //       events upon which no preprocessing took place.  So policyFlags was always 0.
+    //       In the new native input dispatcher we're a bit more careful about event
+    //       preprocessing so the touches we receive can actually have non-zero policyFlags.
+    //       Unfortunately we obtain undesirable behavior.
+    //
+    //       Here's what happens:
+    //
+    //       When the device dims in anticipation of going to sleep, touches
+    //       in windows which have FLAG_TOUCHABLE_WHEN_WAKING cause
+    //       the device to brighten and reset the user activity timer.
+    //       Touches on other windows (such as the launcher window)
+    //       are dropped.  Then after a moment, the device goes to sleep.  Oops.
+    //
+    //       Also notice how screenWasOff was being initialized using POLICY_FLAG_BRIGHT_HERE
+    //       instead of POLICY_FLAG_WOKE_HERE...
+    //
+    bool screenWasOff = false; // original policy: policyFlags & POLICY_FLAG_BRIGHT_HERE;
+
+    int32_t displayId = entry->displayId;
+    int32_t action = entry->action;
+    int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
+
+    // Update the touch state as needed based on the properties of the touch event.
+    int32_t injectionResult = INPUT_EVENT_INJECTION_PENDING;
+    InjectionPermission injectionPermission = INJECTION_PERMISSION_UNKNOWN;
+    sp<InputWindowHandle> newHoverWindowHandle;
+
+    // Copy current touch state into mTempTouchState.
+    // This state is always reset at the end of this function, so if we don't find state
+    // for the specified display then our initial state will be empty.
+    const TouchState* oldState = NULL;
+    ssize_t oldStateIndex = mTouchStatesByDisplay.indexOfKey(displayId);
+    if (oldStateIndex >= 0) {
+        oldState = &mTouchStatesByDisplay.valueAt(oldStateIndex);
+        mTempTouchState.copyFrom(*oldState);
+    }
+
+    bool isSplit = mTempTouchState.split;
+    bool switchedDevice = mTempTouchState.deviceId >= 0 && mTempTouchState.displayId >= 0
+            && (mTempTouchState.deviceId != entry->deviceId
+                    || mTempTouchState.source != entry->source
+                    || mTempTouchState.displayId != displayId);
+    bool isHoverAction = (maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE
+            || maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER
+            || maskedAction == AMOTION_EVENT_ACTION_HOVER_EXIT);
+    bool newGesture = (maskedAction == AMOTION_EVENT_ACTION_DOWN
+            || maskedAction == AMOTION_EVENT_ACTION_SCROLL
+            || isHoverAction);
+    bool wrongDevice = false;
+    if (newGesture) {
+        bool down = maskedAction == AMOTION_EVENT_ACTION_DOWN;
+        if (switchedDevice && mTempTouchState.down && !down) {
+#if DEBUG_FOCUS
+            ALOGD("Dropping event because a pointer for a different device is already down.");
+#endif
+            injectionResult = INPUT_EVENT_INJECTION_FAILED;
+            switchedDevice = false;
+            wrongDevice = true;
+            goto Failed;
+        }
+        mTempTouchState.reset();
+        mTempTouchState.down = down;
+        mTempTouchState.deviceId = entry->deviceId;
+        mTempTouchState.source = entry->source;
+        mTempTouchState.displayId = displayId;
+        isSplit = false;
+    }
+
+    if (newGesture || (isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN)) {
+        /* Case 1: New splittable pointer going down, or need target for hover or scroll. */
+
+        int32_t pointerIndex = getMotionEventActionPointerIndex(action);
+        int32_t x = int32_t(entry->pointerCoords[pointerIndex].
+                getAxisValue(AMOTION_EVENT_AXIS_X));
+        int32_t y = int32_t(entry->pointerCoords[pointerIndex].
+                getAxisValue(AMOTION_EVENT_AXIS_Y));
+        sp<InputWindowHandle> newTouchedWindowHandle;
+        sp<InputWindowHandle> topErrorWindowHandle;
+        bool isTouchModal = false;
+
+        // Traverse windows from front to back to find touched window and outside targets.
+        size_t numWindows = mWindowHandles.size();
+        for (size_t i = 0; i < numWindows; i++) {
+            sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i);
+            const InputWindowInfo* windowInfo = windowHandle->getInfo();
+            if (windowInfo->displayId != displayId) {
+                continue; // wrong display
+            }
+
+            int32_t privateFlags = windowInfo->layoutParamsPrivateFlags;
+            if (privateFlags & InputWindowInfo::PRIVATE_FLAG_SYSTEM_ERROR) {
+                if (topErrorWindowHandle == NULL) {
+                    topErrorWindowHandle = windowHandle;
+                }
+            }
+
+            int32_t flags = windowInfo->layoutParamsFlags;
+            if (windowInfo->visible) {
+                if (! (flags & InputWindowInfo::FLAG_NOT_TOUCHABLE)) {
+                    isTouchModal = (flags & (InputWindowInfo::FLAG_NOT_FOCUSABLE
+                            | InputWindowInfo::FLAG_NOT_TOUCH_MODAL)) == 0;
+                    if (isTouchModal || windowInfo->touchableRegionContainsPoint(x, y)) {
+                        if (! screenWasOff
+                                || (flags & InputWindowInfo::FLAG_TOUCHABLE_WHEN_WAKING)) {
+                            newTouchedWindowHandle = windowHandle;
+                        }
+                        break; // found touched window, exit window loop
+                    }
+                }
+
+                if (maskedAction == AMOTION_EVENT_ACTION_DOWN
+                        && (flags & InputWindowInfo::FLAG_WATCH_OUTSIDE_TOUCH)) {
+                    int32_t outsideTargetFlags = InputTarget::FLAG_DISPATCH_AS_OUTSIDE;
+                    if (isWindowObscuredAtPointLocked(windowHandle, x, y)) {
+                        outsideTargetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
+                    }
+
+                    mTempTouchState.addOrUpdateWindow(
+                            windowHandle, outsideTargetFlags, BitSet32(0));
+                }
+            }
+        }
+
+        // If there is an error window but it is not taking focus (typically because
+        // it is invisible) then wait for it.  Any other focused window may in
+        // fact be in ANR state.
+        if (topErrorWindowHandle != NULL && newTouchedWindowHandle != topErrorWindowHandle) {
+            injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
+                    NULL, NULL, nextWakeupTime,
+                    "Waiting because a system error window is about to be displayed.");
+            injectionPermission = INJECTION_PERMISSION_UNKNOWN;
+            goto Unresponsive;
+        }
+
+        // Figure out whether splitting will be allowed for this window.
+        if (newTouchedWindowHandle != NULL
+                && newTouchedWindowHandle->getInfo()->supportsSplitTouch()) {
+            // New window supports splitting.
+            isSplit = true;
+        } else if (isSplit) {
+            // New window does not support splitting but we have already split events.
+            // Ignore the new window.
+            newTouchedWindowHandle = NULL;
+        }
+
+        // Handle the case where we did not find a window.
+        if (newTouchedWindowHandle == NULL) {
+            // Try to assign the pointer to the first foreground window we find, if there is one.
+            newTouchedWindowHandle = mTempTouchState.getFirstForegroundWindowHandle();
+            if (newTouchedWindowHandle == NULL) {
+                ALOGI("Dropping event because there is no touchable window at (%d, %d).", x, y);
+                injectionResult = INPUT_EVENT_INJECTION_FAILED;
+                goto Failed;
+            }
+        }
+
+        // Set target flags.
+        int32_t targetFlags = InputTarget::FLAG_FOREGROUND | InputTarget::FLAG_DISPATCH_AS_IS;
+        if (isSplit) {
+            targetFlags |= InputTarget::FLAG_SPLIT;
+        }
+        if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) {
+            targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
+        }
+
+        // Update hover state.
+        if (isHoverAction) {
+            newHoverWindowHandle = newTouchedWindowHandle;
+        } else if (maskedAction == AMOTION_EVENT_ACTION_SCROLL) {
+            newHoverWindowHandle = mLastHoverWindowHandle;
+        }
+
+        // Update the temporary touch state.
+        BitSet32 pointerIds;
+        if (isSplit) {
+            uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
+            pointerIds.markBit(pointerId);
+        }
+        mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds);
+    } else {
+        /* Case 2: Pointer move, up, cancel or non-splittable pointer down. */
+
+        // If the pointer is not currently down, then ignore the event.
+        if (! mTempTouchState.down) {
+#if DEBUG_FOCUS
+            ALOGD("Dropping event because the pointer is not down or we previously "
+                    "dropped the pointer down event.");
+#endif
+            injectionResult = INPUT_EVENT_INJECTION_FAILED;
+            goto Failed;
+        }
+
+        // Check whether touches should slip outside of the current foreground window.
+        if (maskedAction == AMOTION_EVENT_ACTION_MOVE
+                && entry->pointerCount == 1
+                && mTempTouchState.isSlippery()) {
+            int32_t x = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X));
+            int32_t y = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));
+
+            sp<InputWindowHandle> oldTouchedWindowHandle =
+                    mTempTouchState.getFirstForegroundWindowHandle();
+            sp<InputWindowHandle> newTouchedWindowHandle =
+                    findTouchedWindowAtLocked(displayId, x, y);
+            if (oldTouchedWindowHandle != newTouchedWindowHandle
+                    && newTouchedWindowHandle != NULL) {
+#if DEBUG_FOCUS
+                ALOGD("Touch is slipping out of window %s into window %s.",
+                        oldTouchedWindowHandle->getName().string(),
+                        newTouchedWindowHandle->getName().string());
+#endif
+                // Make a slippery exit from the old window.
+                mTempTouchState.addOrUpdateWindow(oldTouchedWindowHandle,
+                        InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT, BitSet32(0));
+
+                // Make a slippery entrance into the new window.
+                if (newTouchedWindowHandle->getInfo()->supportsSplitTouch()) {
+                    isSplit = true;
+                }
+
+                int32_t targetFlags = InputTarget::FLAG_FOREGROUND
+                        | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER;
+                if (isSplit) {
+                    targetFlags |= InputTarget::FLAG_SPLIT;
+                }
+                if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) {
+                    targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
+                }
+
+                BitSet32 pointerIds;
+                if (isSplit) {
+                    pointerIds.markBit(entry->pointerProperties[0].id);
+                }
+                mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds);
+            }
+        }
+    }
+
+    if (newHoverWindowHandle != mLastHoverWindowHandle) {
+        // Let the previous window know that the hover sequence is over.
+        if (mLastHoverWindowHandle != NULL) {
+#if DEBUG_HOVER
+            ALOGD("Sending hover exit event to window %s.",
+                    mLastHoverWindowHandle->getName().string());
+#endif
+            mTempTouchState.addOrUpdateWindow(mLastHoverWindowHandle,
+                    InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT, BitSet32(0));
+        }
+
+        // Let the new window know that the hover sequence is starting.
+        if (newHoverWindowHandle != NULL) {
+#if DEBUG_HOVER
+            ALOGD("Sending hover enter event to window %s.",
+                    newHoverWindowHandle->getName().string());
+#endif
+            mTempTouchState.addOrUpdateWindow(newHoverWindowHandle,
+                    InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER, BitSet32(0));
+        }
+    }
+
+    // Check permission to inject into all touched foreground windows and ensure there
+    // is at least one touched foreground window.
+    {
+        bool haveForegroundWindow = false;
+        for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
+            const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+            if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
+                haveForegroundWindow = true;
+                if (! checkInjectionPermission(touchedWindow.windowHandle,
+                        entry->injectionState)) {
+                    injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
+                    injectionPermission = INJECTION_PERMISSION_DENIED;
+                    goto Failed;
+                }
+            }
+        }
+        if (! haveForegroundWindow) {
+#if DEBUG_FOCUS
+            ALOGD("Dropping event because there is no touched foreground window to receive it.");
+#endif
+            injectionResult = INPUT_EVENT_INJECTION_FAILED;
+            goto Failed;
+        }
+
+        // Permission granted to injection into all touched foreground windows.
+        injectionPermission = INJECTION_PERMISSION_GRANTED;
+    }
+
+    // Check whether windows listening for outside touches are owned by the same UID. If it is
+    // set the policy flag that we will not reveal coordinate information to this window.
+    if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
+        sp<InputWindowHandle> foregroundWindowHandle =
+                mTempTouchState.getFirstForegroundWindowHandle();
+        const int32_t foregroundWindowUid = foregroundWindowHandle->getInfo()->ownerUid;
+        for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
+            const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+            if (touchedWindow.targetFlags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
+                sp<InputWindowHandle> inputWindowHandle = touchedWindow.windowHandle;
+                if (inputWindowHandle->getInfo()->ownerUid != foregroundWindowUid) {
+                    mTempTouchState.addOrUpdateWindow(inputWindowHandle,
+                            InputTarget::FLAG_ZERO_COORDS, BitSet32(0));
+                }
+            }
+        }
+    }
+
+    // Ensure all touched foreground windows are ready for new input.
+    for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
+        const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
+        if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
+            // If the touched window is paused then keep waiting.
+            if (touchedWindow.windowHandle->getInfo()->paused) {
+                injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
+                        NULL, touchedWindow.windowHandle, nextWakeupTime,
+                        "Waiting because the touched window is paused.");
+                goto Unresponsive;
+            }
+
+            // If the touched window is still working on previous events then keep waiting.
+            if (!isWindowReadyForMoreInputLocked(currentTime, touchedWindow.windowHandle, entry)) {
+                injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
+                        NULL, touchedWindow.windowHandle, nextWakeupTime,
+                        "Waiting because the touched window has not finished "
+                        "processing the input events that were previously delivered to it.");
+                goto Unresponsive;
+            }
+        }
+    }
+
+    // If this is the first pointer going down and the touched window has a wallpaper
+    // then also add the touched wallpaper windows so they are locked in for the duration
+    // of the touch gesture.
+    // We do not collect wallpapers during HOVER_MOVE or SCROLL because the wallpaper
+    // engine only supports touch events.  We would need to add a mechanism similar
+    // to View.onGenericMotionEvent to enable wallpapers to handle these events.
+    if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
+        sp<InputWindowHandle> foregroundWindowHandle =
+                mTempTouchState.getFirstForegroundWindowHandle();
+        if (foregroundWindowHandle->getInfo()->hasWallpaper) {
+            for (size_t i = 0; i < mWindowHandles.size(); i++) {
+                sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i);
+                const InputWindowInfo* info = windowHandle->getInfo();
+                if (info->displayId == displayId
+                        && windowHandle->getInfo()->layoutParamsType
+                                == InputWindowInfo::TYPE_WALLPAPER) {
+                    mTempTouchState.addOrUpdateWindow(windowHandle,
+                            InputTarget::FLAG_WINDOW_IS_OBSCURED
+                                    | InputTarget::FLAG_DISPATCH_AS_IS,
+                            BitSet32(0));
+                }
+            }
+        }
+    }
+
+    // Success!  Output targets.
+    injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
+
+    for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
+        const TouchedWindow& touchedWindow = mTempTouchState.windows.itemAt(i);
+        addWindowTargetLocked(touchedWindow.windowHandle, touchedWindow.targetFlags,
+                touchedWindow.pointerIds, inputTargets);
+    }
+
+    // Drop the outside or hover touch windows since we will not care about them
+    // in the next iteration.
+    mTempTouchState.filterNonAsIsTouchWindows();
+
+Failed:
+    // Check injection permission once and for all.
+    if (injectionPermission == INJECTION_PERMISSION_UNKNOWN) {
+        if (checkInjectionPermission(NULL, entry->injectionState)) {
+            injectionPermission = INJECTION_PERMISSION_GRANTED;
+        } else {
+            injectionPermission = INJECTION_PERMISSION_DENIED;
+        }
+    }
+
+    // Update final pieces of touch state if the injector had permission.
+    if (injectionPermission == INJECTION_PERMISSION_GRANTED) {
+        if (!wrongDevice) {
+            if (switchedDevice) {
+#if DEBUG_FOCUS
+                ALOGD("Conflicting pointer actions: Switched to a different device.");
+#endif
+                *outConflictingPointerActions = true;
+            }
+
+            if (isHoverAction) {
+                // Started hovering, therefore no longer down.
+                if (oldState && oldState->down) {
+#if DEBUG_FOCUS
+                    ALOGD("Conflicting pointer actions: Hover received while pointer was down.");
+#endif
+                    *outConflictingPointerActions = true;
+                }
+                mTempTouchState.reset();
+                if (maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER
+                        || maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE) {
+                    mTempTouchState.deviceId = entry->deviceId;
+                    mTempTouchState.source = entry->source;
+                    mTempTouchState.displayId = displayId;
+                }
+            } else if (maskedAction == AMOTION_EVENT_ACTION_UP
+                    || maskedAction == AMOTION_EVENT_ACTION_CANCEL) {
+                // All pointers up or canceled.
+                mTempTouchState.reset();
+            } else if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
+                // First pointer went down.
+                if (oldState && oldState->down) {
+#if DEBUG_FOCUS
+                    ALOGD("Conflicting pointer actions: Down received while already down.");
+#endif
+                    *outConflictingPointerActions = true;
+                }
+            } else if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
+                // One pointer went up.
+                if (isSplit) {
+                    int32_t pointerIndex = getMotionEventActionPointerIndex(action);
+                    uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
+
+                    for (size_t i = 0; i < mTempTouchState.windows.size(); ) {
+                        TouchedWindow& touchedWindow = mTempTouchState.windows.editItemAt(i);
+                        if (touchedWindow.targetFlags & InputTarget::FLAG_SPLIT) {
+                            touchedWindow.pointerIds.clearBit(pointerId);
+                            if (touchedWindow.pointerIds.isEmpty()) {
+                                mTempTouchState.windows.removeAt(i);
+                                continue;
+                            }
+                        }
+                        i += 1;
+                    }
+                }
+            }
+
+            // Save changes unless the action was scroll in which case the temporary touch
+            // state was only valid for this one action.
+            if (maskedAction != AMOTION_EVENT_ACTION_SCROLL) {
+                if (mTempTouchState.displayId >= 0) {
+                    if (oldStateIndex >= 0) {
+                        mTouchStatesByDisplay.editValueAt(oldStateIndex).copyFrom(mTempTouchState);
+                    } else {
+                        mTouchStatesByDisplay.add(displayId, mTempTouchState);
+                    }
+                } else if (oldStateIndex >= 0) {
+                    mTouchStatesByDisplay.removeItemsAt(oldStateIndex);
+                }
+            }
+
+            // Update hover state.
+            mLastHoverWindowHandle = newHoverWindowHandle;
+        }
+    } else {
+#if DEBUG_FOCUS
+        ALOGD("Not updating touch focus because injection was denied.");
+#endif
+    }
+
+Unresponsive:
+    // Reset temporary touch state to ensure we release unnecessary references to input channels.
+    mTempTouchState.reset();
+
+    nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime);
+    updateDispatchStatisticsLocked(currentTime, entry,
+            injectionResult, timeSpentWaitingForApplication);
+#if DEBUG_FOCUS
+    ALOGD("findTouchedWindow finished: injectionResult=%d, injectionPermission=%d, "
+            "timeSpentWaitingForApplication=%0.1fms",
+            injectionResult, injectionPermission, timeSpentWaitingForApplication / 1000000.0);
+#endif
+    return injectionResult;
+}
+
+void InputDispatcher::addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
+        int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets) {
+    inputTargets.push();
+
+    const InputWindowInfo* windowInfo = windowHandle->getInfo();
+    InputTarget& target = inputTargets.editTop();
+    target.inputChannel = windowInfo->inputChannel;
+    target.flags = targetFlags;
+    target.xOffset = - windowInfo->frameLeft;
+    target.yOffset = - windowInfo->frameTop;
+    target.scaleFactor = windowInfo->scaleFactor;
+    target.pointerIds = pointerIds;
+}
+
+void InputDispatcher::addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets) {
+    for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
+        inputTargets.push();
+
+        InputTarget& target = inputTargets.editTop();
+        target.inputChannel = mMonitoringChannels[i];
+        target.flags = InputTarget::FLAG_DISPATCH_AS_IS;
+        target.xOffset = 0;
+        target.yOffset = 0;
+        target.pointerIds.clear();
+        target.scaleFactor = 1.0f;
+    }
+}
+
+bool InputDispatcher::checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
+        const InjectionState* injectionState) {
+    if (injectionState
+            && (windowHandle == NULL
+                    || windowHandle->getInfo()->ownerUid != injectionState->injectorUid)
+            && !hasInjectionPermission(injectionState->injectorPid, injectionState->injectorUid)) {
+        if (windowHandle != NULL) {
+            ALOGW("Permission denied: injecting event from pid %d uid %d to window %s "
+                    "owned by uid %d",
+                    injectionState->injectorPid, injectionState->injectorUid,
+                    windowHandle->getName().string(),
+                    windowHandle->getInfo()->ownerUid);
+        } else {
+            ALOGW("Permission denied: injecting event from pid %d uid %d",
+                    injectionState->injectorPid, injectionState->injectorUid);
+        }
+        return false;
+    }
+    return true;
+}
+
+bool InputDispatcher::isWindowObscuredAtPointLocked(
+        const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const {
+    int32_t displayId = windowHandle->getInfo()->displayId;
+    size_t numWindows = mWindowHandles.size();
+    for (size_t i = 0; i < numWindows; i++) {
+        sp<InputWindowHandle> otherHandle = mWindowHandles.itemAt(i);
+        if (otherHandle == windowHandle) {
+            break;
+        }
+
+        const InputWindowInfo* otherInfo = otherHandle->getInfo();
+        if (otherInfo->displayId == displayId
+                && otherInfo->visible && !otherInfo->isTrustedOverlay()
+                && otherInfo->frameContainsPoint(x, y)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool InputDispatcher::isWindowReadyForMoreInputLocked(nsecs_t currentTime,
+        const sp<InputWindowHandle>& windowHandle, const EventEntry* eventEntry) {
+    ssize_t connectionIndex = getConnectionIndexLocked(windowHandle->getInputChannel());
+    if (connectionIndex >= 0) {
+        sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
+        if (connection->inputPublisherBlocked) {
+            return false;
+        }
+        if (eventEntry->type == EventEntry::TYPE_KEY) {
+            // If the event is a key event, then we must wait for all previous events to
+            // complete before delivering it because previous events may have the
+            // side-effect of transferring focus to a different window and we want to
+            // ensure that the following keys are sent to the new window.
+            //
+            // Suppose the user touches a button in a window then immediately presses "A".
+            // If the button causes a pop-up window to appear then we want to ensure that
+            // the "A" key is delivered to the new pop-up window.  This is because users
+            // often anticipate pending UI changes when typing on a keyboard.
+            // To obtain this behavior, we must serialize key events with respect to all
+            // prior input events.
+            return connection->outboundQueue.isEmpty()
+                    && connection->waitQueue.isEmpty();
+        }
+        // Touch events can always be sent to a window immediately because the user intended
+        // to touch whatever was visible at the time.  Even if focus changes or a new
+        // window appears moments later, the touch event was meant to be delivered to
+        // whatever window happened to be on screen at the time.
+        //
+        // Generic motion events, such as trackball or joystick events are a little trickier.
+        // Like key events, generic motion events are delivered to the focused window.
+        // Unlike key events, generic motion events don't tend to transfer focus to other
+        // windows and it is not important for them to be serialized.  So we prefer to deliver
+        // generic motion events as soon as possible to improve efficiency and reduce lag
+        // through batching.
+        //
+        // The one case where we pause input event delivery is when the wait queue is piling
+        // up with lots of events because the application is not responding.
+        // This condition ensures that ANRs are detected reliably.
+        if (!connection->waitQueue.isEmpty()
+                && currentTime >= connection->waitQueue.head->deliveryTime
+                        + STREAM_AHEAD_EVENT_TIMEOUT) {
+            return false;
+        }
+    }
+    return true;
+}
+
+String8 InputDispatcher::getApplicationWindowLabelLocked(
+        const sp<InputApplicationHandle>& applicationHandle,
+        const sp<InputWindowHandle>& windowHandle) {
+    if (applicationHandle != NULL) {
+        if (windowHandle != NULL) {
+            String8 label(applicationHandle->getName());
+            label.append(" - ");
+            label.append(windowHandle->getName());
+            return label;
+        } else {
+            return applicationHandle->getName();
+        }
+    } else if (windowHandle != NULL) {
+        return windowHandle->getName();
+    } else {
+        return String8("<unknown application or window>");
+    }
+}
+
+void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
+    if (mFocusedWindowHandle != NULL) {
+        const InputWindowInfo* info = mFocusedWindowHandle->getInfo();
+        if (info->inputFeatures & InputWindowInfo::INPUT_FEATURE_DISABLE_USER_ACTIVITY) {
+#if DEBUG_DISPATCH_CYCLE
+            ALOGD("Not poking user activity: disabled by window '%s'.", info->name.string());
+#endif
+            return;
+        }
+    }
+
+    int32_t eventType = USER_ACTIVITY_EVENT_OTHER;
+    switch (eventEntry->type) {
+    case EventEntry::TYPE_MOTION: {
+        const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry);
+        if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) {
+            return;
+        }
+
+        if (MotionEvent::isTouchEvent(motionEntry->source, motionEntry->action)) {
+            eventType = USER_ACTIVITY_EVENT_TOUCH;
+        }
+        break;
+    }
+    case EventEntry::TYPE_KEY: {
+        const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry);
+        if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) {
+            return;
+        }
+        eventType = USER_ACTIVITY_EVENT_BUTTON;
+        break;
+    }
+    }
+
+    CommandEntry* commandEntry = postCommandLocked(
+            & InputDispatcher::doPokeUserActivityLockedInterruptible);
+    commandEntry->eventTime = eventEntry->eventTime;
+    commandEntry->userActivityEventType = eventType;
+}
+
+void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime,
+        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) {
+#if DEBUG_DISPATCH_CYCLE
+    ALOGD("channel '%s' ~ prepareDispatchCycle - flags=0x%08x, "
+            "xOffset=%f, yOffset=%f, scaleFactor=%f, "
+            "pointerIds=0x%x",
+            connection->getInputChannelName(), inputTarget->flags,
+            inputTarget->xOffset, inputTarget->yOffset,
+            inputTarget->scaleFactor, inputTarget->pointerIds.value);
+#endif
+
+    // Skip this event if the connection status is not normal.
+    // We don't want to enqueue additional outbound events if the connection is broken.
+    if (connection->status != Connection::STATUS_NORMAL) {
+#if DEBUG_DISPATCH_CYCLE
+        ALOGD("channel '%s' ~ Dropping event because the channel status is %s",
+                connection->getInputChannelName(), connection->getStatusLabel());
+#endif
+        return;
+    }
+
+    // Split a motion event if needed.
+    if (inputTarget->flags & InputTarget::FLAG_SPLIT) {
+        ALOG_ASSERT(eventEntry->type == EventEntry::TYPE_MOTION);
+
+        MotionEntry* originalMotionEntry = static_cast<MotionEntry*>(eventEntry);
+        if (inputTarget->pointerIds.count() != originalMotionEntry->pointerCount) {
+            MotionEntry* splitMotionEntry = splitMotionEvent(
+                    originalMotionEntry, inputTarget->pointerIds);
+            if (!splitMotionEntry) {
+                return; // split event was dropped
+            }
+#if DEBUG_FOCUS
+            ALOGD("channel '%s' ~ Split motion event.",
+                    connection->getInputChannelName());
+            logOutboundMotionDetailsLocked("  ", splitMotionEntry);
+#endif
+            enqueueDispatchEntriesLocked(currentTime, connection,
+                    splitMotionEntry, inputTarget);
+            splitMotionEntry->release();
+            return;
+        }
+    }
+
+    // Not splitting.  Enqueue dispatch entries for the event as is.
+    enqueueDispatchEntriesLocked(currentTime, connection, eventEntry, inputTarget);
+}
+
+void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,
+        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) {
+    bool wasEmpty = connection->outboundQueue.isEmpty();
+
+    // Enqueue dispatch entries for the requested modes.
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            InputTarget::FLAG_DISPATCH_AS_OUTSIDE);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            InputTarget::FLAG_DISPATCH_AS_IS);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT);
+    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
+            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER);
+
+    // If the outbound queue was previously empty, start the dispatch cycle going.
+    if (wasEmpty && !connection->outboundQueue.isEmpty()) {
+        startDispatchCycleLocked(currentTime, connection);
+    }
+}
+
+void InputDispatcher::enqueueDispatchEntryLocked(
+        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
+        int32_t dispatchMode) {
+    int32_t inputTargetFlags = inputTarget->flags;
+    if (!(inputTargetFlags & dispatchMode)) {
+        return;
+    }
+    inputTargetFlags = (inputTargetFlags & ~InputTarget::FLAG_DISPATCH_MASK) | dispatchMode;
+
+    // This is a new event.
+    // Enqueue a new dispatch entry onto the outbound queue for this connection.
+    DispatchEntry* dispatchEntry = new DispatchEntry(eventEntry, // increments ref
+            inputTargetFlags, inputTarget->xOffset, inputTarget->yOffset,
+            inputTarget->scaleFactor);
+
+    // Apply target flags and update the connection's input state.
+    switch (eventEntry->type) {
+    case EventEntry::TYPE_KEY: {
+        KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry);
+        dispatchEntry->resolvedAction = keyEntry->action;
+        dispatchEntry->resolvedFlags = keyEntry->flags;
+
+        if (!connection->inputState.trackKey(keyEntry,
+                dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags)) {
+#if DEBUG_DISPATCH_CYCLE
+            ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent key event",
+                    connection->getInputChannelName());
+#endif
+            delete dispatchEntry;
+            return; // skip the inconsistent event
+        }
+        break;
+    }
+
+    case EventEntry::TYPE_MOTION: {
+        MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
+        if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
+            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_OUTSIDE;
+        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT) {
+            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_EXIT;
+        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER) {
+            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER;
+        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
+            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_CANCEL;
+        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER) {
+            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_DOWN;
+        } else {
+            dispatchEntry->resolvedAction = motionEntry->action;
+        }
+        if (dispatchEntry->resolvedAction == AMOTION_EVENT_ACTION_HOVER_MOVE
+                && !connection->inputState.isHovering(
+                        motionEntry->deviceId, motionEntry->source, motionEntry->displayId)) {
+#if DEBUG_DISPATCH_CYCLE
+        ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: filling in missing hover enter event",
+                connection->getInputChannelName());
+#endif
+            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER;
+        }
+
+        dispatchEntry->resolvedFlags = motionEntry->flags;
+        if (dispatchEntry->targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) {
+            dispatchEntry->resolvedFlags |= AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
+        }
+
+        if (!connection->inputState.trackMotion(motionEntry,
+                dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags)) {
+#if DEBUG_DISPATCH_CYCLE
+            ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent motion event",
+                    connection->getInputChannelName());
+#endif
+            delete dispatchEntry;
+            return; // skip the inconsistent event
+        }
+        break;
+    }
+    }
+
+    // Remember that we are waiting for this dispatch to complete.
+    if (dispatchEntry->hasForegroundTarget()) {
+        incrementPendingForegroundDispatchesLocked(eventEntry);
+    }
+
+    // Enqueue the dispatch entry.
+    connection->outboundQueue.enqueueAtTail(dispatchEntry);
+    traceOutboundQueueLengthLocked(connection);
+}
+
+void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
+        const sp<Connection>& connection) {
+#if DEBUG_DISPATCH_CYCLE
+    ALOGD("channel '%s' ~ startDispatchCycle",
+            connection->getInputChannelName());
+#endif
+
+    while (connection->status == Connection::STATUS_NORMAL
+            && !connection->outboundQueue.isEmpty()) {
+        DispatchEntry* dispatchEntry = connection->outboundQueue.head;
+        dispatchEntry->deliveryTime = currentTime;
+
+        // Publish the event.
+        status_t status;
+        EventEntry* eventEntry = dispatchEntry->eventEntry;
+        switch (eventEntry->type) {
+        case EventEntry::TYPE_KEY: {
+            KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry);
+
+            // Publish the key event.
+            status = connection->inputPublisher.publishKeyEvent(dispatchEntry->seq,
+                    keyEntry->deviceId, keyEntry->source,
+                    dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags,
+                    keyEntry->keyCode, keyEntry->scanCode,
+                    keyEntry->metaState, keyEntry->repeatCount, keyEntry->downTime,
+                    keyEntry->eventTime);
+            break;
+        }
+
+        case EventEntry::TYPE_MOTION: {
+            MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
+
+            PointerCoords scaledCoords[MAX_POINTERS];
+            const PointerCoords* usingCoords = motionEntry->pointerCoords;
+
+            // Set the X and Y offset depending on the input source.
+            float xOffset, yOffset, scaleFactor;
+            if ((motionEntry->source & AINPUT_SOURCE_CLASS_POINTER)
+                    && !(dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS)) {
+                scaleFactor = dispatchEntry->scaleFactor;
+                xOffset = dispatchEntry->xOffset * scaleFactor;
+                yOffset = dispatchEntry->yOffset * scaleFactor;
+                if (scaleFactor != 1.0f) {
+                    for (size_t i = 0; i < motionEntry->pointerCount; i++) {
+                        scaledCoords[i] = motionEntry->pointerCoords[i];
+                        scaledCoords[i].scale(scaleFactor);
+                    }
+                    usingCoords = scaledCoords;
+                }
+            } else {
+                xOffset = 0.0f;
+                yOffset = 0.0f;
+                scaleFactor = 1.0f;
+
+                // We don't want the dispatch target to know.
+                if (dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS) {
+                    for (size_t i = 0; i < motionEntry->pointerCount; i++) {
+                        scaledCoords[i].clear();
+                    }
+                    usingCoords = scaledCoords;
+                }
+            }
+
+            // Publish the motion event.
+            status = connection->inputPublisher.publishMotionEvent(dispatchEntry->seq,
+                    motionEntry->deviceId, motionEntry->source,
+                    dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags,
+                    motionEntry->edgeFlags, motionEntry->metaState, motionEntry->buttonState,
+                    xOffset, yOffset,
+                    motionEntry->xPrecision, motionEntry->yPrecision,
+                    motionEntry->downTime, motionEntry->eventTime,
+                    motionEntry->pointerCount, motionEntry->pointerProperties,
+                    usingCoords);
+            break;
+        }
+
+        default:
+            ALOG_ASSERT(false);
+            return;
+        }
+
+        // Check the result.
+        if (status) {
+            if (status == WOULD_BLOCK) {
+                if (connection->waitQueue.isEmpty()) {
+                    ALOGE("channel '%s' ~ Could not publish event because the pipe is full. "
+                            "This is unexpected because the wait queue is empty, so the pipe "
+                            "should be empty and we shouldn't have any problems writing an "
+                            "event to it, status=%d", connection->getInputChannelName(), status);
+                    abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);
+                } else {
+                    // Pipe is full and we are waiting for the app to finish process some events
+                    // before sending more events to it.
+#if DEBUG_DISPATCH_CYCLE
+                    ALOGD("channel '%s' ~ Could not publish event because the pipe is full, "
+                            "waiting for the application to catch up",
+                            connection->getInputChannelName());
+#endif
+                    connection->inputPublisherBlocked = true;
+                }
+            } else {
+                ALOGE("channel '%s' ~ Could not publish event due to an unexpected error, "
+                        "status=%d", connection->getInputChannelName(), status);
+                abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);
+            }
+            return;
+        }
+
+        // Re-enqueue the event on the wait queue.
+        connection->outboundQueue.dequeue(dispatchEntry);
+        traceOutboundQueueLengthLocked(connection);
+        connection->waitQueue.enqueueAtTail(dispatchEntry);
+        traceWaitQueueLengthLocked(connection);
+    }
+}
+
+void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime,
+        const sp<Connection>& connection, uint32_t seq, bool handled) {
+#if DEBUG_DISPATCH_CYCLE
+    ALOGD("channel '%s' ~ finishDispatchCycle - seq=%u, handled=%s",
+            connection->getInputChannelName(), seq, toString(handled));
+#endif
+
+    connection->inputPublisherBlocked = false;
+
+    if (connection->status == Connection::STATUS_BROKEN
+            || connection->status == Connection::STATUS_ZOMBIE) {
+        return;
+    }
+
+    // Notify other system components and prepare to start the next dispatch cycle.
+    onDispatchCycleFinishedLocked(currentTime, connection, seq, handled);
+}
+
+void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
+        const sp<Connection>& connection, bool notify) {
+#if DEBUG_DISPATCH_CYCLE
+    ALOGD("channel '%s' ~ abortBrokenDispatchCycle - notify=%s",
+            connection->getInputChannelName(), toString(notify));
+#endif
+
+    // Clear the dispatch queues.
+    drainDispatchQueueLocked(&connection->outboundQueue);
+    traceOutboundQueueLengthLocked(connection);
+    drainDispatchQueueLocked(&connection->waitQueue);
+    traceWaitQueueLengthLocked(connection);
+
+    // The connection appears to be unrecoverably broken.
+    // Ignore already broken or zombie connections.
+    if (connection->status == Connection::STATUS_NORMAL) {
+        connection->status = Connection::STATUS_BROKEN;
+
+        if (notify) {
+            // Notify other system components.
+            onDispatchCycleBrokenLocked(currentTime, connection);
+        }
+    }
+}
+
+void InputDispatcher::drainDispatchQueueLocked(Queue<DispatchEntry>* queue) {
+    while (!queue->isEmpty()) {
+        DispatchEntry* dispatchEntry = queue->dequeueAtHead();
+        releaseDispatchEntryLocked(dispatchEntry);
+    }
+}
+
+void InputDispatcher::releaseDispatchEntryLocked(DispatchEntry* dispatchEntry) {
+    if (dispatchEntry->hasForegroundTarget()) {
+        decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry);
+    }
+    delete dispatchEntry;
+}
+
+int InputDispatcher::handleReceiveCallback(int fd, int events, void* data) {
+    InputDispatcher* d = static_cast<InputDispatcher*>(data);
+
+    { // acquire lock
+        AutoMutex _l(d->mLock);
+
+        ssize_t connectionIndex = d->mConnectionsByFd.indexOfKey(fd);
+        if (connectionIndex < 0) {
+            ALOGE("Received spurious receive callback for unknown input channel.  "
+                    "fd=%d, events=0x%x", fd, events);
+            return 0; // remove the callback
+        }
+
+        bool notify;
+        sp<Connection> connection = d->mConnectionsByFd.valueAt(connectionIndex);
+        if (!(events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP))) {
+            if (!(events & ALOOPER_EVENT_INPUT)) {
+                ALOGW("channel '%s' ~ Received spurious callback for unhandled poll event.  "
+                        "events=0x%x", connection->getInputChannelName(), events);
+                return 1;
+            }
+
+            nsecs_t currentTime = now();
+            bool gotOne = false;
+            status_t status;
+            for (;;) {
+                uint32_t seq;
+                bool handled;
+                status = connection->inputPublisher.receiveFinishedSignal(&seq, &handled);
+                if (status) {
+                    break;
+                }
+                d->finishDispatchCycleLocked(currentTime, connection, seq, handled);
+                gotOne = true;
+            }
+            if (gotOne) {
+                d->runCommandsLockedInterruptible();
+                if (status == WOULD_BLOCK) {
+                    return 1;
+                }
+            }
+
+            notify = status != DEAD_OBJECT || !connection->monitor;
+            if (notify) {
+                ALOGE("channel '%s' ~ Failed to receive finished signal.  status=%d",
+                        connection->getInputChannelName(), status);
+            }
+        } else {
+            // Monitor channels are never explicitly unregistered.
+            // We do it automatically when the remote endpoint is closed so don't warn
+            // about them.
+            notify = !connection->monitor;
+            if (notify) {
+                ALOGW("channel '%s' ~ Consumer closed input channel or an error occurred.  "
+                        "events=0x%x", connection->getInputChannelName(), events);
+            }
+        }
+
+        // Unregister the channel.
+        d->unregisterInputChannelLocked(connection->inputChannel, notify);
+        return 0; // remove the callback
+    } // release lock
+}
+
+void InputDispatcher::synthesizeCancelationEventsForAllConnectionsLocked(
+        const CancelationOptions& options) {
+    for (size_t i = 0; i < mConnectionsByFd.size(); i++) {
+        synthesizeCancelationEventsForConnectionLocked(
+                mConnectionsByFd.valueAt(i), options);
+    }
+}
+
+void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked(
+        const sp<InputChannel>& channel, const CancelationOptions& options) {
+    ssize_t index = getConnectionIndexLocked(channel);
+    if (index >= 0) {
+        synthesizeCancelationEventsForConnectionLocked(
+                mConnectionsByFd.valueAt(index), options);
+    }
+}
+
+void InputDispatcher::synthesizeCancelationEventsForConnectionLocked(
+        const sp<Connection>& connection, const CancelationOptions& options) {
+    if (connection->status == Connection::STATUS_BROKEN) {
+        return;
+    }
+
+    nsecs_t currentTime = now();
+
+    Vector<EventEntry*> cancelationEvents;
+    connection->inputState.synthesizeCancelationEvents(currentTime,
+            cancelationEvents, options);
+
+    if (!cancelationEvents.isEmpty()) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+        ALOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync "
+                "with reality: %s, mode=%d.",
+                connection->getInputChannelName(), cancelationEvents.size(),
+                options.reason, options.mode);
+#endif
+        for (size_t i = 0; i < cancelationEvents.size(); i++) {
+            EventEntry* cancelationEventEntry = cancelationEvents.itemAt(i);
+            switch (cancelationEventEntry->type) {
+            case EventEntry::TYPE_KEY:
+                logOutboundKeyDetailsLocked("cancel - ",
+                        static_cast<KeyEntry*>(cancelationEventEntry));
+                break;
+            case EventEntry::TYPE_MOTION:
+                logOutboundMotionDetailsLocked("cancel - ",
+                        static_cast<MotionEntry*>(cancelationEventEntry));
+                break;
+            }
+
+            InputTarget target;
+            sp<InputWindowHandle> windowHandle = getWindowHandleLocked(connection->inputChannel);
+            if (windowHandle != NULL) {
+                const InputWindowInfo* windowInfo = windowHandle->getInfo();
+                target.xOffset = -windowInfo->frameLeft;
+                target.yOffset = -windowInfo->frameTop;
+                target.scaleFactor = windowInfo->scaleFactor;
+            } else {
+                target.xOffset = 0;
+                target.yOffset = 0;
+                target.scaleFactor = 1.0f;
+            }
+            target.inputChannel = connection->inputChannel;
+            target.flags = InputTarget::FLAG_DISPATCH_AS_IS;
+
+            enqueueDispatchEntryLocked(connection, cancelationEventEntry, // increments ref
+                    &target, InputTarget::FLAG_DISPATCH_AS_IS);
+
+            cancelationEventEntry->release();
+        }
+
+        startDispatchCycleLocked(currentTime, connection);
+    }
+}
+
+InputDispatcher::MotionEntry*
+InputDispatcher::splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds) {
+    ALOG_ASSERT(pointerIds.value != 0);
+
+    uint32_t splitPointerIndexMap[MAX_POINTERS];
+    PointerProperties splitPointerProperties[MAX_POINTERS];
+    PointerCoords splitPointerCoords[MAX_POINTERS];
+
+    uint32_t originalPointerCount = originalMotionEntry->pointerCount;
+    uint32_t splitPointerCount = 0;
+
+    for (uint32_t originalPointerIndex = 0; originalPointerIndex < originalPointerCount;
+            originalPointerIndex++) {
+        const PointerProperties& pointerProperties =
+                originalMotionEntry->pointerProperties[originalPointerIndex];
+        uint32_t pointerId = uint32_t(pointerProperties.id);
+        if (pointerIds.hasBit(pointerId)) {
+            splitPointerIndexMap[splitPointerCount] = originalPointerIndex;
+            splitPointerProperties[splitPointerCount].copyFrom(pointerProperties);
+            splitPointerCoords[splitPointerCount].copyFrom(
+                    originalMotionEntry->pointerCoords[originalPointerIndex]);
+            splitPointerCount += 1;
+        }
+    }
+
+    if (splitPointerCount != pointerIds.count()) {
+        // This is bad.  We are missing some of the pointers that we expected to deliver.
+        // Most likely this indicates that we received an ACTION_MOVE events that has
+        // different pointer ids than we expected based on the previous ACTION_DOWN
+        // or ACTION_POINTER_DOWN events that caused us to decide to split the pointers
+        // in this way.
+        ALOGW("Dropping split motion event because the pointer count is %d but "
+                "we expected there to be %d pointers.  This probably means we received "
+                "a broken sequence of pointer ids from the input device.",
+                splitPointerCount, pointerIds.count());
+        return NULL;
+    }
+
+    int32_t action = originalMotionEntry->action;
+    int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
+    if (maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN
+            || maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
+        int32_t originalPointerIndex = getMotionEventActionPointerIndex(action);
+        const PointerProperties& pointerProperties =
+                originalMotionEntry->pointerProperties[originalPointerIndex];
+        uint32_t pointerId = uint32_t(pointerProperties.id);
+        if (pointerIds.hasBit(pointerId)) {
+            if (pointerIds.count() == 1) {
+                // The first/last pointer went down/up.
+                action = maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN
+                        ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
+            } else {
+                // A secondary pointer went down/up.
+                uint32_t splitPointerIndex = 0;
+                while (pointerId != uint32_t(splitPointerProperties[splitPointerIndex].id)) {
+                    splitPointerIndex += 1;
+                }
+                action = maskedAction | (splitPointerIndex
+                        << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
+            }
+        } else {
+            // An unrelated pointer changed.
+            action = AMOTION_EVENT_ACTION_MOVE;
+        }
+    }
+
+    MotionEntry* splitMotionEntry = new MotionEntry(
+            originalMotionEntry->eventTime,
+            originalMotionEntry->deviceId,
+            originalMotionEntry->source,
+            originalMotionEntry->policyFlags,
+            action,
+            originalMotionEntry->flags,
+            originalMotionEntry->metaState,
+            originalMotionEntry->buttonState,
+            originalMotionEntry->edgeFlags,
+            originalMotionEntry->xPrecision,
+            originalMotionEntry->yPrecision,
+            originalMotionEntry->downTime,
+            originalMotionEntry->displayId,
+            splitPointerCount, splitPointerProperties, splitPointerCoords, 0, 0);
+
+    if (originalMotionEntry->injectionState) {
+        splitMotionEntry->injectionState = originalMotionEntry->injectionState;
+        splitMotionEntry->injectionState->refCount += 1;
+    }
+
+    return splitMotionEntry;
+}
+
+void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
+#if DEBUG_INBOUND_EVENT_DETAILS
+    ALOGD("notifyConfigurationChanged - eventTime=%lld", args->eventTime);
+#endif
+
+    bool needWake;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        ConfigurationChangedEntry* newEntry = new ConfigurationChangedEntry(args->eventTime);
+        needWake = enqueueInboundEventLocked(newEntry);
+    } // release lock
+
+    if (needWake) {
+        mLooper->wake();
+    }
+}
+
+void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
+#if DEBUG_INBOUND_EVENT_DETAILS
+    ALOGD("notifyKey - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, "
+            "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld",
+            args->eventTime, args->deviceId, args->source, args->policyFlags,
+            args->action, args->flags, args->keyCode, args->scanCode,
+            args->metaState, args->downTime);
+#endif
+    if (!validateKeyEvent(args->action)) {
+        return;
+    }
+
+    uint32_t policyFlags = args->policyFlags;
+    int32_t flags = args->flags;
+    int32_t metaState = args->metaState;
+    if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) {
+        policyFlags |= POLICY_FLAG_VIRTUAL;
+        flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
+    }
+    if (policyFlags & POLICY_FLAG_ALT) {
+        metaState |= AMETA_ALT_ON | AMETA_ALT_LEFT_ON;
+    }
+    if (policyFlags & POLICY_FLAG_ALT_GR) {
+        metaState |= AMETA_ALT_ON | AMETA_ALT_RIGHT_ON;
+    }
+    if (policyFlags & POLICY_FLAG_SHIFT) {
+        metaState |= AMETA_SHIFT_ON | AMETA_SHIFT_LEFT_ON;
+    }
+    if (policyFlags & POLICY_FLAG_CAPS_LOCK) {
+        metaState |= AMETA_CAPS_LOCK_ON;
+    }
+    if (policyFlags & POLICY_FLAG_FUNCTION) {
+        metaState |= AMETA_FUNCTION_ON;
+    }
+
+    policyFlags |= POLICY_FLAG_TRUSTED;
+
+    KeyEvent event;
+    event.initialize(args->deviceId, args->source, args->action,
+            flags, args->keyCode, args->scanCode, metaState, 0,
+            args->downTime, args->eventTime);
+
+    mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags);
+
+    if (policyFlags & POLICY_FLAG_WOKE_HERE) {
+        flags |= AKEY_EVENT_FLAG_WOKE_HERE;
+    }
+
+    bool needWake;
+    { // acquire lock
+        mLock.lock();
+
+        if (shouldSendKeyToInputFilterLocked(args)) {
+            mLock.unlock();
+
+            policyFlags |= POLICY_FLAG_FILTERED;
+            if (!mPolicy->filterInputEvent(&event, policyFlags)) {
+                return; // event was consumed by the filter
+            }
+
+            mLock.lock();
+        }
+
+        int32_t repeatCount = 0;
+        KeyEntry* newEntry = new KeyEntry(args->eventTime,
+                args->deviceId, args->source, policyFlags,
+                args->action, flags, args->keyCode, args->scanCode,
+                metaState, repeatCount, args->downTime);
+
+        needWake = enqueueInboundEventLocked(newEntry);
+        mLock.unlock();
+    } // release lock
+
+    if (needWake) {
+        mLooper->wake();
+    }
+}
+
+bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) {
+    return mInputFilterEnabled;
+}
+
+void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {
+#if DEBUG_INBOUND_EVENT_DETAILS
+    ALOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
+            "action=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, edgeFlags=0x%x, "
+            "xPrecision=%f, yPrecision=%f, downTime=%lld",
+            args->eventTime, args->deviceId, args->source, args->policyFlags,
+            args->action, args->flags, args->metaState, args->buttonState,
+            args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime);
+    for (uint32_t i = 0; i < args->pointerCount; i++) {
+        ALOGD("  Pointer %d: id=%d, toolType=%d, "
+                "x=%f, y=%f, pressure=%f, size=%f, "
+                "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
+                "orientation=%f",
+                i, args->pointerProperties[i].id,
+                args->pointerProperties[i].toolType,
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
+                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
+    }
+#endif
+    if (!validateMotionEvent(args->action, args->pointerCount, args->pointerProperties)) {
+        return;
+    }
+
+    uint32_t policyFlags = args->policyFlags;
+    policyFlags |= POLICY_FLAG_TRUSTED;
+    mPolicy->interceptMotionBeforeQueueing(args->eventTime, /*byref*/ policyFlags);
+
+    bool needWake;
+    { // acquire lock
+        mLock.lock();
+
+        if (shouldSendMotionToInputFilterLocked(args)) {
+            mLock.unlock();
+
+            MotionEvent event;
+            event.initialize(args->deviceId, args->source, args->action, args->flags,
+                    args->edgeFlags, args->metaState, args->buttonState, 0, 0,
+                    args->xPrecision, args->yPrecision,
+                    args->downTime, args->eventTime,
+                    args->pointerCount, args->pointerProperties, args->pointerCoords);
+
+            policyFlags |= POLICY_FLAG_FILTERED;
+            if (!mPolicy->filterInputEvent(&event, policyFlags)) {
+                return; // event was consumed by the filter
+            }
+
+            mLock.lock();
+        }
+
+        // Just enqueue a new motion event.
+        MotionEntry* newEntry = new MotionEntry(args->eventTime,
+                args->deviceId, args->source, policyFlags,
+                args->action, args->flags, args->metaState, args->buttonState,
+                args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime,
+                args->displayId,
+                args->pointerCount, args->pointerProperties, args->pointerCoords, 0, 0);
+
+        needWake = enqueueInboundEventLocked(newEntry);
+        mLock.unlock();
+    } // release lock
+
+    if (needWake) {
+        mLooper->wake();
+    }
+}
+
+bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) {
+    // TODO: support sending secondary display events to input filter
+    return mInputFilterEnabled && isMainDisplay(args->displayId);
+}
+
+void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
+#if DEBUG_INBOUND_EVENT_DETAILS
+    ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchValues=0x%08x, switchMask=0x%08x",
+            args->eventTime, args->policyFlags,
+            args->switchValues, args->switchMask);
+#endif
+
+    uint32_t policyFlags = args->policyFlags;
+    policyFlags |= POLICY_FLAG_TRUSTED;
+    mPolicy->notifySwitch(args->eventTime,
+            args->switchValues, args->switchMask, policyFlags);
+}
+
+void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+#if DEBUG_INBOUND_EVENT_DETAILS
+    ALOGD("notifyDeviceReset - eventTime=%lld, deviceId=%d",
+            args->eventTime, args->deviceId);
+#endif
+
+    bool needWake;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        DeviceResetEntry* newEntry = new DeviceResetEntry(args->eventTime, args->deviceId);
+        needWake = enqueueInboundEventLocked(newEntry);
+    } // release lock
+
+    if (needWake) {
+        mLooper->wake();
+    }
+}
+
+int32_t InputDispatcher::injectInputEvent(const InputEvent* event, int32_t displayId,
+        int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
+        uint32_t policyFlags) {
+#if DEBUG_INBOUND_EVENT_DETAILS
+    ALOGD("injectInputEvent - eventType=%d, injectorPid=%d, injectorUid=%d, "
+            "syncMode=%d, timeoutMillis=%d, policyFlags=0x%08x",
+            event->getType(), injectorPid, injectorUid, syncMode, timeoutMillis, policyFlags);
+#endif
+
+    nsecs_t endTime = now() + milliseconds_to_nanoseconds(timeoutMillis);
+
+    policyFlags |= POLICY_FLAG_INJECTED;
+    if (hasInjectionPermission(injectorPid, injectorUid)) {
+        policyFlags |= POLICY_FLAG_TRUSTED;
+    }
+
+    EventEntry* firstInjectedEntry;
+    EventEntry* lastInjectedEntry;
+    switch (event->getType()) {
+    case AINPUT_EVENT_TYPE_KEY: {
+        const KeyEvent* keyEvent = static_cast<const KeyEvent*>(event);
+        int32_t action = keyEvent->getAction();
+        if (! validateKeyEvent(action)) {
+            return INPUT_EVENT_INJECTION_FAILED;
+        }
+
+        int32_t flags = keyEvent->getFlags();
+        if (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY) {
+            policyFlags |= POLICY_FLAG_VIRTUAL;
+        }
+
+        if (!(policyFlags & POLICY_FLAG_FILTERED)) {
+            mPolicy->interceptKeyBeforeQueueing(keyEvent, /*byref*/ policyFlags);
+        }
+
+        if (policyFlags & POLICY_FLAG_WOKE_HERE) {
+            flags |= AKEY_EVENT_FLAG_WOKE_HERE;
+        }
+
+        mLock.lock();
+        firstInjectedEntry = new KeyEntry(keyEvent->getEventTime(),
+                keyEvent->getDeviceId(), keyEvent->getSource(),
+                policyFlags, action, flags,
+                keyEvent->getKeyCode(), keyEvent->getScanCode(), keyEvent->getMetaState(),
+                keyEvent->getRepeatCount(), keyEvent->getDownTime());
+        lastInjectedEntry = firstInjectedEntry;
+        break;
+    }
+
+    case AINPUT_EVENT_TYPE_MOTION: {
+        const MotionEvent* motionEvent = static_cast<const MotionEvent*>(event);
+        int32_t action = motionEvent->getAction();
+        size_t pointerCount = motionEvent->getPointerCount();
+        const PointerProperties* pointerProperties = motionEvent->getPointerProperties();
+        if (! validateMotionEvent(action, pointerCount, pointerProperties)) {
+            return INPUT_EVENT_INJECTION_FAILED;
+        }
+
+        if (!(policyFlags & POLICY_FLAG_FILTERED)) {
+            nsecs_t eventTime = motionEvent->getEventTime();
+            mPolicy->interceptMotionBeforeQueueing(eventTime, /*byref*/ policyFlags);
+        }
+
+        mLock.lock();
+        const nsecs_t* sampleEventTimes = motionEvent->getSampleEventTimes();
+        const PointerCoords* samplePointerCoords = motionEvent->getSamplePointerCoords();
+        firstInjectedEntry = new MotionEntry(*sampleEventTimes,
+                motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags,
+                action, motionEvent->getFlags(),
+                motionEvent->getMetaState(), motionEvent->getButtonState(),
+                motionEvent->getEdgeFlags(),
+                motionEvent->getXPrecision(), motionEvent->getYPrecision(),
+                motionEvent->getDownTime(), displayId,
+                uint32_t(pointerCount), pointerProperties, samplePointerCoords,
+                motionEvent->getXOffset(), motionEvent->getYOffset());
+        lastInjectedEntry = firstInjectedEntry;
+        for (size_t i = motionEvent->getHistorySize(); i > 0; i--) {
+            sampleEventTimes += 1;
+            samplePointerCoords += pointerCount;
+            MotionEntry* nextInjectedEntry = new MotionEntry(*sampleEventTimes,
+                    motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags,
+                    action, motionEvent->getFlags(),
+                    motionEvent->getMetaState(), motionEvent->getButtonState(),
+                    motionEvent->getEdgeFlags(),
+                    motionEvent->getXPrecision(), motionEvent->getYPrecision(),
+                    motionEvent->getDownTime(), displayId,
+                    uint32_t(pointerCount), pointerProperties, samplePointerCoords,
+                    motionEvent->getXOffset(), motionEvent->getYOffset());
+            lastInjectedEntry->next = nextInjectedEntry;
+            lastInjectedEntry = nextInjectedEntry;
+        }
+        break;
+    }
+
+    default:
+        ALOGW("Cannot inject event of type %d", event->getType());
+        return INPUT_EVENT_INJECTION_FAILED;
+    }
+
+    InjectionState* injectionState = new InjectionState(injectorPid, injectorUid);
+    if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) {
+        injectionState->injectionIsAsync = true;
+    }
+
+    injectionState->refCount += 1;
+    lastInjectedEntry->injectionState = injectionState;
+
+    bool needWake = false;
+    for (EventEntry* entry = firstInjectedEntry; entry != NULL; ) {
+        EventEntry* nextEntry = entry->next;
+        needWake |= enqueueInboundEventLocked(entry);
+        entry = nextEntry;
+    }
+
+    mLock.unlock();
+
+    if (needWake) {
+        mLooper->wake();
+    }
+
+    int32_t injectionResult;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) {
+            injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
+        } else {
+            for (;;) {
+                injectionResult = injectionState->injectionResult;
+                if (injectionResult != INPUT_EVENT_INJECTION_PENDING) {
+                    break;
+                }
+
+                nsecs_t remainingTimeout = endTime - now();
+                if (remainingTimeout <= 0) {
+#if DEBUG_INJECTION
+                    ALOGD("injectInputEvent - Timed out waiting for injection result "
+                            "to become available.");
+#endif
+                    injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT;
+                    break;
+                }
+
+                mInjectionResultAvailableCondition.waitRelative(mLock, remainingTimeout);
+            }
+
+            if (injectionResult == INPUT_EVENT_INJECTION_SUCCEEDED
+                    && syncMode == INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED) {
+                while (injectionState->pendingForegroundDispatches != 0) {
+#if DEBUG_INJECTION
+                    ALOGD("injectInputEvent - Waiting for %d pending foreground dispatches.",
+                            injectionState->pendingForegroundDispatches);
+#endif
+                    nsecs_t remainingTimeout = endTime - now();
+                    if (remainingTimeout <= 0) {
+#if DEBUG_INJECTION
+                    ALOGD("injectInputEvent - Timed out waiting for pending foreground "
+                            "dispatches to finish.");
+#endif
+                        injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT;
+                        break;
+                    }
+
+                    mInjectionSyncFinishedCondition.waitRelative(mLock, remainingTimeout);
+                }
+            }
+        }
+
+        injectionState->release();
+    } // release lock
+
+#if DEBUG_INJECTION
+    ALOGD("injectInputEvent - Finished with result %d.  "
+            "injectorPid=%d, injectorUid=%d",
+            injectionResult, injectorPid, injectorUid);
+#endif
+
+    return injectionResult;
+}
+
+bool InputDispatcher::hasInjectionPermission(int32_t injectorPid, int32_t injectorUid) {
+    return injectorUid == 0
+            || mPolicy->checkInjectEventsPermissionNonReentrant(injectorPid, injectorUid);
+}
+
+void InputDispatcher::setInjectionResultLocked(EventEntry* entry, int32_t injectionResult) {
+    InjectionState* injectionState = entry->injectionState;
+    if (injectionState) {
+#if DEBUG_INJECTION
+        ALOGD("Setting input event injection result to %d.  "
+                "injectorPid=%d, injectorUid=%d",
+                 injectionResult, injectionState->injectorPid, injectionState->injectorUid);
+#endif
+
+        if (injectionState->injectionIsAsync
+                && !(entry->policyFlags & POLICY_FLAG_FILTERED)) {
+            // Log the outcome since the injector did not wait for the injection result.
+            switch (injectionResult) {
+            case INPUT_EVENT_INJECTION_SUCCEEDED:
+                ALOGV("Asynchronous input event injection succeeded.");
+                break;
+            case INPUT_EVENT_INJECTION_FAILED:
+                ALOGW("Asynchronous input event injection failed.");
+                break;
+            case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
+                ALOGW("Asynchronous input event injection permission denied.");
+                break;
+            case INPUT_EVENT_INJECTION_TIMED_OUT:
+                ALOGW("Asynchronous input event injection timed out.");
+                break;
+            }
+        }
+
+        injectionState->injectionResult = injectionResult;
+        mInjectionResultAvailableCondition.broadcast();
+    }
+}
+
+void InputDispatcher::incrementPendingForegroundDispatchesLocked(EventEntry* entry) {
+    InjectionState* injectionState = entry->injectionState;
+    if (injectionState) {
+        injectionState->pendingForegroundDispatches += 1;
+    }
+}
+
+void InputDispatcher::decrementPendingForegroundDispatchesLocked(EventEntry* entry) {
+    InjectionState* injectionState = entry->injectionState;
+    if (injectionState) {
+        injectionState->pendingForegroundDispatches -= 1;
+
+        if (injectionState->pendingForegroundDispatches == 0) {
+            mInjectionSyncFinishedCondition.broadcast();
+        }
+    }
+}
+
+sp<InputWindowHandle> InputDispatcher::getWindowHandleLocked(
+        const sp<InputChannel>& inputChannel) const {
+    size_t numWindows = mWindowHandles.size();
+    for (size_t i = 0; i < numWindows; i++) {
+        const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i);
+        if (windowHandle->getInputChannel() == inputChannel) {
+            return windowHandle;
+        }
+    }
+    return NULL;
+}
+
+bool InputDispatcher::hasWindowHandleLocked(
+        const sp<InputWindowHandle>& windowHandle) const {
+    size_t numWindows = mWindowHandles.size();
+    for (size_t i = 0; i < numWindows; i++) {
+        if (mWindowHandles.itemAt(i) == windowHandle) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void InputDispatcher::setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles) {
+#if DEBUG_FOCUS
+    ALOGD("setInputWindows");
+#endif
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        Vector<sp<InputWindowHandle> > oldWindowHandles = mWindowHandles;
+        mWindowHandles = inputWindowHandles;
+
+        sp<InputWindowHandle> newFocusedWindowHandle;
+        bool foundHoveredWindow = false;
+        for (size_t i = 0; i < mWindowHandles.size(); i++) {
+            const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i);
+            if (!windowHandle->updateInfo() || windowHandle->getInputChannel() == NULL) {
+                mWindowHandles.removeAt(i--);
+                continue;
+            }
+            if (windowHandle->getInfo()->hasFocus) {
+                newFocusedWindowHandle = windowHandle;
+            }
+            if (windowHandle == mLastHoverWindowHandle) {
+                foundHoveredWindow = true;
+            }
+        }
+
+        if (!foundHoveredWindow) {
+            mLastHoverWindowHandle = NULL;
+        }
+
+        if (mFocusedWindowHandle != newFocusedWindowHandle) {
+            if (mFocusedWindowHandle != NULL) {
+#if DEBUG_FOCUS
+                ALOGD("Focus left window: %s",
+                        mFocusedWindowHandle->getName().string());
+#endif
+                sp<InputChannel> focusedInputChannel = mFocusedWindowHandle->getInputChannel();
+                if (focusedInputChannel != NULL) {
+                    CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS,
+                            "focus left window");
+                    synthesizeCancelationEventsForInputChannelLocked(
+                            focusedInputChannel, options);
+                }
+            }
+            if (newFocusedWindowHandle != NULL) {
+#if DEBUG_FOCUS
+                ALOGD("Focus entered window: %s",
+                        newFocusedWindowHandle->getName().string());
+#endif
+            }
+            mFocusedWindowHandle = newFocusedWindowHandle;
+        }
+
+        for (size_t d = 0; d < mTouchStatesByDisplay.size(); d++) {
+            TouchState& state = mTouchStatesByDisplay.editValueAt(d);
+            for (size_t i = 0; i < state.windows.size(); i++) {
+                TouchedWindow& touchedWindow = state.windows.editItemAt(i);
+                if (!hasWindowHandleLocked(touchedWindow.windowHandle)) {
+#if DEBUG_FOCUS
+                    ALOGD("Touched window was removed: %s",
+                            touchedWindow.windowHandle->getName().string());
+#endif
+                    sp<InputChannel> touchedInputChannel =
+                            touchedWindow.windowHandle->getInputChannel();
+                    if (touchedInputChannel != NULL) {
+                        CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
+                                "touched window was removed");
+                        synthesizeCancelationEventsForInputChannelLocked(
+                                touchedInputChannel, options);
+                    }
+                    state.windows.removeAt(i--);
+                }
+            }
+        }
+
+        // Release information for windows that are no longer present.
+        // This ensures that unused input channels are released promptly.
+        // Otherwise, they might stick around until the window handle is destroyed
+        // which might not happen until the next GC.
+        for (size_t i = 0; i < oldWindowHandles.size(); i++) {
+            const sp<InputWindowHandle>& oldWindowHandle = oldWindowHandles.itemAt(i);
+            if (!hasWindowHandleLocked(oldWindowHandle)) {
+#if DEBUG_FOCUS
+                ALOGD("Window went away: %s", oldWindowHandle->getName().string());
+#endif
+                oldWindowHandle->releaseInfo();
+            }
+        }
+    } // release lock
+
+    // Wake up poll loop since it may need to make new input dispatching choices.
+    mLooper->wake();
+}
+
+void InputDispatcher::setFocusedApplication(
+        const sp<InputApplicationHandle>& inputApplicationHandle) {
+#if DEBUG_FOCUS
+    ALOGD("setFocusedApplication");
+#endif
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (inputApplicationHandle != NULL && inputApplicationHandle->updateInfo()) {
+            if (mFocusedApplicationHandle != inputApplicationHandle) {
+                if (mFocusedApplicationHandle != NULL) {
+                    resetANRTimeoutsLocked();
+                    mFocusedApplicationHandle->releaseInfo();
+                }
+                mFocusedApplicationHandle = inputApplicationHandle;
+            }
+        } else if (mFocusedApplicationHandle != NULL) {
+            resetANRTimeoutsLocked();
+            mFocusedApplicationHandle->releaseInfo();
+            mFocusedApplicationHandle.clear();
+        }
+
+#if DEBUG_FOCUS
+        //logDispatchStateLocked();
+#endif
+    } // release lock
+
+    // Wake up poll loop since it may need to make new input dispatching choices.
+    mLooper->wake();
+}
+
+void InputDispatcher::setInputDispatchMode(bool enabled, bool frozen) {
+#if DEBUG_FOCUS
+    ALOGD("setInputDispatchMode: enabled=%d, frozen=%d", enabled, frozen);
+#endif
+
+    bool changed;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mDispatchEnabled != enabled || mDispatchFrozen != frozen) {
+            if (mDispatchFrozen && !frozen) {
+                resetANRTimeoutsLocked();
+            }
+
+            if (mDispatchEnabled && !enabled) {
+                resetAndDropEverythingLocked("dispatcher is being disabled");
+            }
+
+            mDispatchEnabled = enabled;
+            mDispatchFrozen = frozen;
+            changed = true;
+        } else {
+            changed = false;
+        }
+
+#if DEBUG_FOCUS
+        //logDispatchStateLocked();
+#endif
+    } // release lock
+
+    if (changed) {
+        // Wake up poll loop since it may need to make new input dispatching choices.
+        mLooper->wake();
+    }
+}
+
+void InputDispatcher::setInputFilterEnabled(bool enabled) {
+#if DEBUG_FOCUS
+    ALOGD("setInputFilterEnabled: enabled=%d", enabled);
+#endif
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mInputFilterEnabled == enabled) {
+            return;
+        }
+
+        mInputFilterEnabled = enabled;
+        resetAndDropEverythingLocked("input filter is being enabled or disabled");
+    } // release lock
+
+    // Wake up poll loop since there might be work to do to drop everything.
+    mLooper->wake();
+}
+
+bool InputDispatcher::transferTouchFocus(const sp<InputChannel>& fromChannel,
+        const sp<InputChannel>& toChannel) {
+#if DEBUG_FOCUS
+    ALOGD("transferTouchFocus: fromChannel=%s, toChannel=%s",
+            fromChannel->getName().string(), toChannel->getName().string());
+#endif
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        sp<InputWindowHandle> fromWindowHandle = getWindowHandleLocked(fromChannel);
+        sp<InputWindowHandle> toWindowHandle = getWindowHandleLocked(toChannel);
+        if (fromWindowHandle == NULL || toWindowHandle == NULL) {
+#if DEBUG_FOCUS
+            ALOGD("Cannot transfer focus because from or to window not found.");
+#endif
+            return false;
+        }
+        if (fromWindowHandle == toWindowHandle) {
+#if DEBUG_FOCUS
+            ALOGD("Trivial transfer to same window.");
+#endif
+            return true;
+        }
+        if (fromWindowHandle->getInfo()->displayId != toWindowHandle->getInfo()->displayId) {
+#if DEBUG_FOCUS
+            ALOGD("Cannot transfer focus because windows are on different displays.");
+#endif
+            return false;
+        }
+
+        bool found = false;
+        for (size_t d = 0; d < mTouchStatesByDisplay.size(); d++) {
+            TouchState& state = mTouchStatesByDisplay.editValueAt(d);
+            for (size_t i = 0; i < state.windows.size(); i++) {
+                const TouchedWindow& touchedWindow = state.windows[i];
+                if (touchedWindow.windowHandle == fromWindowHandle) {
+                    int32_t oldTargetFlags = touchedWindow.targetFlags;
+                    BitSet32 pointerIds = touchedWindow.pointerIds;
+
+                    state.windows.removeAt(i);
+
+                    int32_t newTargetFlags = oldTargetFlags
+                            & (InputTarget::FLAG_FOREGROUND
+                                    | InputTarget::FLAG_SPLIT | InputTarget::FLAG_DISPATCH_AS_IS);
+                    state.addOrUpdateWindow(toWindowHandle, newTargetFlags, pointerIds);
+
+                    found = true;
+                    goto Found;
+                }
+            }
+        }
+Found:
+
+        if (! found) {
+#if DEBUG_FOCUS
+            ALOGD("Focus transfer failed because from window did not have focus.");
+#endif
+            return false;
+        }
+
+        ssize_t fromConnectionIndex = getConnectionIndexLocked(fromChannel);
+        ssize_t toConnectionIndex = getConnectionIndexLocked(toChannel);
+        if (fromConnectionIndex >= 0 && toConnectionIndex >= 0) {
+            sp<Connection> fromConnection = mConnectionsByFd.valueAt(fromConnectionIndex);
+            sp<Connection> toConnection = mConnectionsByFd.valueAt(toConnectionIndex);
+
+            fromConnection->inputState.copyPointerStateTo(toConnection->inputState);
+            CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
+                    "transferring touch focus from this window to another window");
+            synthesizeCancelationEventsForConnectionLocked(fromConnection, options);
+        }
+
+#if DEBUG_FOCUS
+        logDispatchStateLocked();
+#endif
+    } // release lock
+
+    // Wake up poll loop since it may need to make new input dispatching choices.
+    mLooper->wake();
+    return true;
+}
+
+void InputDispatcher::resetAndDropEverythingLocked(const char* reason) {
+#if DEBUG_FOCUS
+    ALOGD("Resetting and dropping all events (%s).", reason);
+#endif
+
+    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, reason);
+    synthesizeCancelationEventsForAllConnectionsLocked(options);
+
+    resetKeyRepeatLocked();
+    releasePendingEventLocked();
+    drainInboundQueueLocked();
+    resetANRTimeoutsLocked();
+
+    mTouchStatesByDisplay.clear();
+    mLastHoverWindowHandle.clear();
+}
+
+void InputDispatcher::logDispatchStateLocked() {
+    String8 dump;
+    dumpDispatchStateLocked(dump);
+
+    char* text = dump.lockBuffer(dump.size());
+    char* start = text;
+    while (*start != '\0') {
+        char* end = strchr(start, '\n');
+        if (*end == '\n') {
+            *(end++) = '\0';
+        }
+        ALOGD("%s", start);
+        start = end;
+    }
+}
+
+void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
+    dump.appendFormat(INDENT "DispatchEnabled: %d\n", mDispatchEnabled);
+    dump.appendFormat(INDENT "DispatchFrozen: %d\n", mDispatchFrozen);
+
+    if (mFocusedApplicationHandle != NULL) {
+        dump.appendFormat(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n",
+                mFocusedApplicationHandle->getName().string(),
+                mFocusedApplicationHandle->getDispatchingTimeout(
+                        DEFAULT_INPUT_DISPATCHING_TIMEOUT) / 1000000.0);
+    } else {
+        dump.append(INDENT "FocusedApplication: <null>\n");
+    }
+    dump.appendFormat(INDENT "FocusedWindow: name='%s'\n",
+            mFocusedWindowHandle != NULL ? mFocusedWindowHandle->getName().string() : "<null>");
+
+    if (!mTouchStatesByDisplay.isEmpty()) {
+        dump.appendFormat(INDENT "TouchStatesByDisplay:\n");
+        for (size_t i = 0; i < mTouchStatesByDisplay.size(); i++) {
+            const TouchState& state = mTouchStatesByDisplay.valueAt(i);
+            dump.appendFormat(INDENT2 "%d: down=%s, split=%s, deviceId=%d, source=0x%08x\n",
+                    state.displayId, toString(state.down), toString(state.split),
+                    state.deviceId, state.source);
+            if (!state.windows.isEmpty()) {
+                dump.append(INDENT3 "Windows:\n");
+                for (size_t i = 0; i < state.windows.size(); i++) {
+                    const TouchedWindow& touchedWindow = state.windows[i];
+                    dump.appendFormat(INDENT4 "%d: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n",
+                            i, touchedWindow.windowHandle->getName().string(),
+                            touchedWindow.pointerIds.value,
+                            touchedWindow.targetFlags);
+                }
+            } else {
+                dump.append(INDENT3 "Windows: <none>\n");
+            }
+        }
+    } else {
+        dump.append(INDENT "TouchStates: <no displays touched>\n");
+    }
+
+    if (!mWindowHandles.isEmpty()) {
+        dump.append(INDENT "Windows:\n");
+        for (size_t i = 0; i < mWindowHandles.size(); i++) {
+            const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i);
+            const InputWindowInfo* windowInfo = windowHandle->getInfo();
+
+            dump.appendFormat(INDENT2 "%d: name='%s', displayId=%d, "
+                    "paused=%s, hasFocus=%s, hasWallpaper=%s, "
+                    "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
+                    "frame=[%d,%d][%d,%d], scale=%f, "
+                    "touchableRegion=",
+                    i, windowInfo->name.string(), windowInfo->displayId,
+                    toString(windowInfo->paused),
+                    toString(windowInfo->hasFocus),
+                    toString(windowInfo->hasWallpaper),
+                    toString(windowInfo->visible),
+                    toString(windowInfo->canReceiveKeys),
+                    windowInfo->layoutParamsFlags, windowInfo->layoutParamsType,
+                    windowInfo->layer,
+                    windowInfo->frameLeft, windowInfo->frameTop,
+                    windowInfo->frameRight, windowInfo->frameBottom,
+                    windowInfo->scaleFactor);
+            dumpRegion(dump, windowInfo->touchableRegion);
+            dump.appendFormat(", inputFeatures=0x%08x", windowInfo->inputFeatures);
+            dump.appendFormat(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
+                    windowInfo->ownerPid, windowInfo->ownerUid,
+                    windowInfo->dispatchingTimeout / 1000000.0);
+        }
+    } else {
+        dump.append(INDENT "Windows: <none>\n");
+    }
+
+    if (!mMonitoringChannels.isEmpty()) {
+        dump.append(INDENT "MonitoringChannels:\n");
+        for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
+            const sp<InputChannel>& channel = mMonitoringChannels[i];
+            dump.appendFormat(INDENT2 "%d: '%s'\n", i, channel->getName().string());
+        }
+    } else {
+        dump.append(INDENT "MonitoringChannels: <none>\n");
+    }
+
+    nsecs_t currentTime = now();
+
+    // Dump recently dispatched or dropped events from oldest to newest.
+    if (!mRecentQueue.isEmpty()) {
+        dump.appendFormat(INDENT "RecentQueue: length=%u\n", mRecentQueue.count());
+        for (EventEntry* entry = mRecentQueue.head; entry; entry = entry->next) {
+            dump.append(INDENT2);
+            entry->appendDescription(dump);
+            dump.appendFormat(", age=%0.1fms\n",
+                    (currentTime - entry->eventTime) * 0.000001f);
+        }
+    } else {
+        dump.append(INDENT "RecentQueue: <empty>\n");
+    }
+
+    // Dump event currently being dispatched.
+    if (mPendingEvent) {
+        dump.append(INDENT "PendingEvent:\n");
+        dump.append(INDENT2);
+        mPendingEvent->appendDescription(dump);
+        dump.appendFormat(", age=%0.1fms\n",
+                (currentTime - mPendingEvent->eventTime) * 0.000001f);
+    } else {
+        dump.append(INDENT "PendingEvent: <none>\n");
+    }
+
+    // Dump inbound events from oldest to newest.
+    if (!mInboundQueue.isEmpty()) {
+        dump.appendFormat(INDENT "InboundQueue: length=%u\n", mInboundQueue.count());
+        for (EventEntry* entry = mInboundQueue.head; entry; entry = entry->next) {
+            dump.append(INDENT2);
+            entry->appendDescription(dump);
+            dump.appendFormat(", age=%0.1fms\n",
+                    (currentTime - entry->eventTime) * 0.000001f);
+        }
+    } else {
+        dump.append(INDENT "InboundQueue: <empty>\n");
+    }
+
+    if (!mConnectionsByFd.isEmpty()) {
+        dump.append(INDENT "Connections:\n");
+        for (size_t i = 0; i < mConnectionsByFd.size(); i++) {
+            const sp<Connection>& connection = mConnectionsByFd.valueAt(i);
+            dump.appendFormat(INDENT2 "%d: channelName='%s', windowName='%s', "
+                    "status=%s, monitor=%s, inputPublisherBlocked=%s\n",
+                    i, connection->getInputChannelName(), connection->getWindowName(),
+                    connection->getStatusLabel(), toString(connection->monitor),
+                    toString(connection->inputPublisherBlocked));
+
+            if (!connection->outboundQueue.isEmpty()) {
+                dump.appendFormat(INDENT3 "OutboundQueue: length=%u\n",
+                        connection->outboundQueue.count());
+                for (DispatchEntry* entry = connection->outboundQueue.head; entry;
+                        entry = entry->next) {
+                    dump.append(INDENT4);
+                    entry->eventEntry->appendDescription(dump);
+                    dump.appendFormat(", targetFlags=0x%08x, resolvedAction=%d, age=%0.1fms\n",
+                            entry->targetFlags, entry->resolvedAction,
+                            (currentTime - entry->eventEntry->eventTime) * 0.000001f);
+                }
+            } else {
+                dump.append(INDENT3 "OutboundQueue: <empty>\n");
+            }
+
+            if (!connection->waitQueue.isEmpty()) {
+                dump.appendFormat(INDENT3 "WaitQueue: length=%u\n",
+                        connection->waitQueue.count());
+                for (DispatchEntry* entry = connection->waitQueue.head; entry;
+                        entry = entry->next) {
+                    dump.append(INDENT4);
+                    entry->eventEntry->appendDescription(dump);
+                    dump.appendFormat(", targetFlags=0x%08x, resolvedAction=%d, "
+                            "age=%0.1fms, wait=%0.1fms\n",
+                            entry->targetFlags, entry->resolvedAction,
+                            (currentTime - entry->eventEntry->eventTime) * 0.000001f,
+                            (currentTime - entry->deliveryTime) * 0.000001f);
+                }
+            } else {
+                dump.append(INDENT3 "WaitQueue: <empty>\n");
+            }
+        }
+    } else {
+        dump.append(INDENT "Connections: <none>\n");
+    }
+
+    if (isAppSwitchPendingLocked()) {
+        dump.appendFormat(INDENT "AppSwitch: pending, due in %0.1fms\n",
+                (mAppSwitchDueTime - now()) / 1000000.0);
+    } else {
+        dump.append(INDENT "AppSwitch: not pending\n");
+    }
+
+    dump.append(INDENT "Configuration:\n");
+    dump.appendFormat(INDENT2 "KeyRepeatDelay: %0.1fms\n",
+            mConfig.keyRepeatDelay * 0.000001f);
+    dump.appendFormat(INDENT2 "KeyRepeatTimeout: %0.1fms\n",
+            mConfig.keyRepeatTimeout * 0.000001f);
+}
+
+status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel,
+        const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
+#if DEBUG_REGISTRATION
+    ALOGD("channel '%s' ~ registerInputChannel - monitor=%s", inputChannel->getName().string(),
+            toString(monitor));
+#endif
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (getConnectionIndexLocked(inputChannel) >= 0) {
+            ALOGW("Attempted to register already registered input channel '%s'",
+                    inputChannel->getName().string());
+            return BAD_VALUE;
+        }
+
+        sp<Connection> connection = new Connection(inputChannel, inputWindowHandle, monitor);
+
+        int fd = inputChannel->getFd();
+        mConnectionsByFd.add(fd, connection);
+
+        if (monitor) {
+            mMonitoringChannels.push(inputChannel);
+        }
+
+        mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, handleReceiveCallback, this);
+    } // release lock
+
+    // Wake the looper because some connections have changed.
+    mLooper->wake();
+    return OK;
+}
+
+status_t InputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChannel) {
+#if DEBUG_REGISTRATION
+    ALOGD("channel '%s' ~ unregisterInputChannel", inputChannel->getName().string());
+#endif
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        status_t status = unregisterInputChannelLocked(inputChannel, false /*notify*/);
+        if (status) {
+            return status;
+        }
+    } // release lock
+
+    // Wake the poll loop because removing the connection may have changed the current
+    // synchronization state.
+    mLooper->wake();
+    return OK;
+}
+
+status_t InputDispatcher::unregisterInputChannelLocked(const sp<InputChannel>& inputChannel,
+        bool notify) {
+    ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
+    if (connectionIndex < 0) {
+        ALOGW("Attempted to unregister already unregistered input channel '%s'",
+                inputChannel->getName().string());
+        return BAD_VALUE;
+    }
+
+    sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
+    mConnectionsByFd.removeItemsAt(connectionIndex);
+
+    if (connection->monitor) {
+        removeMonitorChannelLocked(inputChannel);
+    }
+
+    mLooper->removeFd(inputChannel->getFd());
+
+    nsecs_t currentTime = now();
+    abortBrokenDispatchCycleLocked(currentTime, connection, notify);
+
+    connection->status = Connection::STATUS_ZOMBIE;
+    return OK;
+}
+
+void InputDispatcher::removeMonitorChannelLocked(const sp<InputChannel>& inputChannel) {
+    for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
+         if (mMonitoringChannels[i] == inputChannel) {
+             mMonitoringChannels.removeAt(i);
+             break;
+         }
+    }
+}
+
+ssize_t InputDispatcher::getConnectionIndexLocked(const sp<InputChannel>& inputChannel) {
+    ssize_t connectionIndex = mConnectionsByFd.indexOfKey(inputChannel->getFd());
+    if (connectionIndex >= 0) {
+        sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
+        if (connection->inputChannel.get() == inputChannel.get()) {
+            return connectionIndex;
+        }
+    }
+
+    return -1;
+}
+
+void InputDispatcher::onDispatchCycleFinishedLocked(
+        nsecs_t currentTime, const sp<Connection>& connection, uint32_t seq, bool handled) {
+    CommandEntry* commandEntry = postCommandLocked(
+            & InputDispatcher::doDispatchCycleFinishedLockedInterruptible);
+    commandEntry->connection = connection;
+    commandEntry->eventTime = currentTime;
+    commandEntry->seq = seq;
+    commandEntry->handled = handled;
+}
+
+void InputDispatcher::onDispatchCycleBrokenLocked(
+        nsecs_t currentTime, const sp<Connection>& connection) {
+    ALOGE("channel '%s' ~ Channel is unrecoverably broken and will be disposed!",
+            connection->getInputChannelName());
+
+    CommandEntry* commandEntry = postCommandLocked(
+            & InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible);
+    commandEntry->connection = connection;
+}
+
+void InputDispatcher::onANRLocked(
+        nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle,
+        const sp<InputWindowHandle>& windowHandle,
+        nsecs_t eventTime, nsecs_t waitStartTime, const char* reason) {
+    float dispatchLatency = (currentTime - eventTime) * 0.000001f;
+    float waitDuration = (currentTime - waitStartTime) * 0.000001f;
+    ALOGI("Application is not responding: %s.  "
+            "It has been %0.1fms since event, %0.1fms since wait started.  Reason: %s",
+            getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(),
+            dispatchLatency, waitDuration, reason);
+
+    // Capture a record of the InputDispatcher state at the time of the ANR.
+    time_t t = time(NULL);
+    struct tm tm;
+    localtime_r(&t, &tm);
+    char timestr[64];
+    strftime(timestr, sizeof(timestr), "%F %T", &tm);
+    mLastANRState.clear();
+    mLastANRState.append(INDENT "ANR:\n");
+    mLastANRState.appendFormat(INDENT2 "Time: %s\n", timestr);
+    mLastANRState.appendFormat(INDENT2 "Window: %s\n",
+            getApplicationWindowLabelLocked(applicationHandle, windowHandle).string());
+    mLastANRState.appendFormat(INDENT2 "DispatchLatency: %0.1fms\n", dispatchLatency);
+    mLastANRState.appendFormat(INDENT2 "WaitDuration: %0.1fms\n", waitDuration);
+    mLastANRState.appendFormat(INDENT2 "Reason: %s\n", reason);
+    dumpDispatchStateLocked(mLastANRState);
+
+    CommandEntry* commandEntry = postCommandLocked(
+            & InputDispatcher::doNotifyANRLockedInterruptible);
+    commandEntry->inputApplicationHandle = applicationHandle;
+    commandEntry->inputWindowHandle = windowHandle;
+    commandEntry->reason = reason;
+}
+
+void InputDispatcher::doNotifyConfigurationChangedInterruptible(
+        CommandEntry* commandEntry) {
+    mLock.unlock();
+
+    mPolicy->notifyConfigurationChanged(commandEntry->eventTime);
+
+    mLock.lock();
+}
+
+void InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible(
+        CommandEntry* commandEntry) {
+    sp<Connection> connection = commandEntry->connection;
+
+    if (connection->status != Connection::STATUS_ZOMBIE) {
+        mLock.unlock();
+
+        mPolicy->notifyInputChannelBroken(connection->inputWindowHandle);
+
+        mLock.lock();
+    }
+}
+
+void InputDispatcher::doNotifyANRLockedInterruptible(
+        CommandEntry* commandEntry) {
+    mLock.unlock();
+
+    nsecs_t newTimeout = mPolicy->notifyANR(
+            commandEntry->inputApplicationHandle, commandEntry->inputWindowHandle,
+            commandEntry->reason);
+
+    mLock.lock();
+
+    resumeAfterTargetsNotReadyTimeoutLocked(newTimeout,
+            commandEntry->inputWindowHandle != NULL
+                    ? commandEntry->inputWindowHandle->getInputChannel() : NULL);
+}
+
+void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible(
+        CommandEntry* commandEntry) {
+    KeyEntry* entry = commandEntry->keyEntry;
+
+    KeyEvent event;
+    initializeKeyEvent(&event, entry);
+
+    mLock.unlock();
+
+    nsecs_t delay = mPolicy->interceptKeyBeforeDispatching(commandEntry->inputWindowHandle,
+            &event, entry->policyFlags);
+
+    mLock.lock();
+
+    if (delay < 0) {
+        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_SKIP;
+    } else if (!delay) {
+        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE;
+    } else {
+        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER;
+        entry->interceptKeyWakeupTime = now() + delay;
+    }
+    entry->release();
+}
+
+void InputDispatcher::doDispatchCycleFinishedLockedInterruptible(
+        CommandEntry* commandEntry) {
+    sp<Connection> connection = commandEntry->connection;
+    nsecs_t finishTime = commandEntry->eventTime;
+    uint32_t seq = commandEntry->seq;
+    bool handled = commandEntry->handled;
+
+    // Handle post-event policy actions.
+    DispatchEntry* dispatchEntry = connection->findWaitQueueEntry(seq);
+    if (dispatchEntry) {
+        nsecs_t eventDuration = finishTime - dispatchEntry->deliveryTime;
+        if (eventDuration > SLOW_EVENT_PROCESSING_WARNING_TIMEOUT) {
+            String8 msg;
+            msg.appendFormat("Window '%s' spent %0.1fms processing the last input event: ",
+                    connection->getWindowName(), eventDuration * 0.000001f);
+            dispatchEntry->eventEntry->appendDescription(msg);
+            ALOGI("%s", msg.string());
+        }
+
+        bool restartEvent;
+        if (dispatchEntry->eventEntry->type == EventEntry::TYPE_KEY) {
+            KeyEntry* keyEntry = static_cast<KeyEntry*>(dispatchEntry->eventEntry);
+            restartEvent = afterKeyEventLockedInterruptible(connection,
+                    dispatchEntry, keyEntry, handled);
+        } else if (dispatchEntry->eventEntry->type == EventEntry::TYPE_MOTION) {
+            MotionEntry* motionEntry = static_cast<MotionEntry*>(dispatchEntry->eventEntry);
+            restartEvent = afterMotionEventLockedInterruptible(connection,
+                    dispatchEntry, motionEntry, handled);
+        } else {
+            restartEvent = false;
+        }
+
+        // Dequeue the event and start the next cycle.
+        // Note that because the lock might have been released, it is possible that the
+        // contents of the wait queue to have been drained, so we need to double-check
+        // a few things.
+        if (dispatchEntry == connection->findWaitQueueEntry(seq)) {
+            connection->waitQueue.dequeue(dispatchEntry);
+            traceWaitQueueLengthLocked(connection);
+            if (restartEvent && connection->status == Connection::STATUS_NORMAL) {
+                connection->outboundQueue.enqueueAtHead(dispatchEntry);
+                traceOutboundQueueLengthLocked(connection);
+            } else {
+                releaseDispatchEntryLocked(dispatchEntry);
+            }
+        }
+
+        // Start the next dispatch cycle for this connection.
+        startDispatchCycleLocked(now(), connection);
+    }
+}
+
+bool InputDispatcher::afterKeyEventLockedInterruptible(const sp<Connection>& connection,
+        DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled) {
+    if (!(keyEntry->flags & AKEY_EVENT_FLAG_FALLBACK)) {
+        // Get the fallback key state.
+        // Clear it out after dispatching the UP.
+        int32_t originalKeyCode = keyEntry->keyCode;
+        int32_t fallbackKeyCode = connection->inputState.getFallbackKey(originalKeyCode);
+        if (keyEntry->action == AKEY_EVENT_ACTION_UP) {
+            connection->inputState.removeFallbackKey(originalKeyCode);
+        }
+
+        if (handled || !dispatchEntry->hasForegroundTarget()) {
+            // If the application handles the original key for which we previously
+            // generated a fallback or if the window is not a foreground window,
+            // then cancel the associated fallback key, if any.
+            if (fallbackKeyCode != -1) {
+                // Dispatch the unhandled key to the policy with the cancel flag.
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+                ALOGD("Unhandled key event: Asking policy to cancel fallback action.  "
+                        "keyCode=%d, action=%d, repeatCount=%d, policyFlags=0x%08x",
+                        keyEntry->keyCode, keyEntry->action, keyEntry->repeatCount,
+                        keyEntry->policyFlags);
+#endif
+                KeyEvent event;
+                initializeKeyEvent(&event, keyEntry);
+                event.setFlags(event.getFlags() | AKEY_EVENT_FLAG_CANCELED);
+
+                mLock.unlock();
+
+                mPolicy->dispatchUnhandledKey(connection->inputWindowHandle,
+                        &event, keyEntry->policyFlags, &event);
+
+                mLock.lock();
+
+                // Cancel the fallback key.
+                if (fallbackKeyCode != AKEYCODE_UNKNOWN) {
+                    CancelationOptions options(CancelationOptions::CANCEL_FALLBACK_EVENTS,
+                            "application handled the original non-fallback key "
+                            "or is no longer a foreground target, "
+                            "canceling previously dispatched fallback key");
+                    options.keyCode = fallbackKeyCode;
+                    synthesizeCancelationEventsForConnectionLocked(connection, options);
+                }
+                connection->inputState.removeFallbackKey(originalKeyCode);
+            }
+        } else {
+            // If the application did not handle a non-fallback key, first check
+            // that we are in a good state to perform unhandled key event processing
+            // Then ask the policy what to do with it.
+            bool initialDown = keyEntry->action == AKEY_EVENT_ACTION_DOWN
+                    && keyEntry->repeatCount == 0;
+            if (fallbackKeyCode == -1 && !initialDown) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+                ALOGD("Unhandled key event: Skipping unhandled key event processing "
+                        "since this is not an initial down.  "
+                        "keyCode=%d, action=%d, repeatCount=%d, policyFlags=0x%08x",
+                        originalKeyCode, keyEntry->action, keyEntry->repeatCount,
+                        keyEntry->policyFlags);
+#endif
+                return false;
+            }
+
+            // Dispatch the unhandled key to the policy.
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+            ALOGD("Unhandled key event: Asking policy to perform fallback action.  "
+                    "keyCode=%d, action=%d, repeatCount=%d, policyFlags=0x%08x",
+                    keyEntry->keyCode, keyEntry->action, keyEntry->repeatCount,
+                    keyEntry->policyFlags);
+#endif
+            KeyEvent event;
+            initializeKeyEvent(&event, keyEntry);
+
+            mLock.unlock();
+
+            bool fallback = mPolicy->dispatchUnhandledKey(connection->inputWindowHandle,
+                    &event, keyEntry->policyFlags, &event);
+
+            mLock.lock();
+
+            if (connection->status != Connection::STATUS_NORMAL) {
+                connection->inputState.removeFallbackKey(originalKeyCode);
+                return false;
+            }
+
+            // Latch the fallback keycode for this key on an initial down.
+            // The fallback keycode cannot change at any other point in the lifecycle.
+            if (initialDown) {
+                if (fallback) {
+                    fallbackKeyCode = event.getKeyCode();
+                } else {
+                    fallbackKeyCode = AKEYCODE_UNKNOWN;
+                }
+                connection->inputState.setFallbackKey(originalKeyCode, fallbackKeyCode);
+            }
+
+            ALOG_ASSERT(fallbackKeyCode != -1);
+
+            // Cancel the fallback key if the policy decides not to send it anymore.
+            // We will continue to dispatch the key to the policy but we will no
+            // longer dispatch a fallback key to the application.
+            if (fallbackKeyCode != AKEYCODE_UNKNOWN
+                    && (!fallback || fallbackKeyCode != event.getKeyCode())) {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+                if (fallback) {
+                    ALOGD("Unhandled key event: Policy requested to send key %d"
+                            "as a fallback for %d, but on the DOWN it had requested "
+                            "to send %d instead.  Fallback canceled.",
+                            event.getKeyCode(), originalKeyCode, fallbackKeyCode);
+                } else {
+                    ALOGD("Unhandled key event: Policy did not request fallback for %d, "
+                            "but on the DOWN it had requested to send %d.  "
+                            "Fallback canceled.",
+                            originalKeyCode, fallbackKeyCode);
+                }
+#endif
+
+                CancelationOptions options(CancelationOptions::CANCEL_FALLBACK_EVENTS,
+                        "canceling fallback, policy no longer desires it");
+                options.keyCode = fallbackKeyCode;
+                synthesizeCancelationEventsForConnectionLocked(connection, options);
+
+                fallback = false;
+                fallbackKeyCode = AKEYCODE_UNKNOWN;
+                if (keyEntry->action != AKEY_EVENT_ACTION_UP) {
+                    connection->inputState.setFallbackKey(originalKeyCode,
+                            fallbackKeyCode);
+                }
+            }
+
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+            {
+                String8 msg;
+                const KeyedVector<int32_t, int32_t>& fallbackKeys =
+                        connection->inputState.getFallbackKeys();
+                for (size_t i = 0; i < fallbackKeys.size(); i++) {
+                    msg.appendFormat(", %d->%d", fallbackKeys.keyAt(i),
+                            fallbackKeys.valueAt(i));
+                }
+                ALOGD("Unhandled key event: %d currently tracked fallback keys%s.",
+                        fallbackKeys.size(), msg.string());
+            }
+#endif
+
+            if (fallback) {
+                // Restart the dispatch cycle using the fallback key.
+                keyEntry->eventTime = event.getEventTime();
+                keyEntry->deviceId = event.getDeviceId();
+                keyEntry->source = event.getSource();
+                keyEntry->flags = event.getFlags() | AKEY_EVENT_FLAG_FALLBACK;
+                keyEntry->keyCode = fallbackKeyCode;
+                keyEntry->scanCode = event.getScanCode();
+                keyEntry->metaState = event.getMetaState();
+                keyEntry->repeatCount = event.getRepeatCount();
+                keyEntry->downTime = event.getDownTime();
+                keyEntry->syntheticRepeat = false;
+
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+                ALOGD("Unhandled key event: Dispatching fallback key.  "
+                        "originalKeyCode=%d, fallbackKeyCode=%d, fallbackMetaState=%08x",
+                        originalKeyCode, fallbackKeyCode, keyEntry->metaState);
+#endif
+                return true; // restart the event
+            } else {
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+                ALOGD("Unhandled key event: No fallback key.");
+#endif
+            }
+        }
+    }
+    return false;
+}
+
+bool InputDispatcher::afterMotionEventLockedInterruptible(const sp<Connection>& connection,
+        DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled) {
+    return false;
+}
+
+void InputDispatcher::doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) {
+    mLock.unlock();
+
+    mPolicy->pokeUserActivity(commandEntry->eventTime, commandEntry->userActivityEventType);
+
+    mLock.lock();
+}
+
+void InputDispatcher::initializeKeyEvent(KeyEvent* event, const KeyEntry* entry) {
+    event->initialize(entry->deviceId, entry->source, entry->action, entry->flags,
+            entry->keyCode, entry->scanCode, entry->metaState, entry->repeatCount,
+            entry->downTime, entry->eventTime);
+}
+
+void InputDispatcher::updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry,
+        int32_t injectionResult, nsecs_t timeSpentWaitingForApplication) {
+    // TODO Write some statistics about how long we spend waiting.
+}
+
+void InputDispatcher::traceInboundQueueLengthLocked() {
+    if (ATRACE_ENABLED()) {
+        ATRACE_INT("iq", mInboundQueue.count());
+    }
+}
+
+void InputDispatcher::traceOutboundQueueLengthLocked(const sp<Connection>& connection) {
+    if (ATRACE_ENABLED()) {
+        char counterName[40];
+        snprintf(counterName, sizeof(counterName), "oq:%s", connection->getWindowName());
+        ATRACE_INT(counterName, connection->outboundQueue.count());
+    }
+}
+
+void InputDispatcher::traceWaitQueueLengthLocked(const sp<Connection>& connection) {
+    if (ATRACE_ENABLED()) {
+        char counterName[40];
+        snprintf(counterName, sizeof(counterName), "wq:%s", connection->getWindowName());
+        ATRACE_INT(counterName, connection->waitQueue.count());
+    }
+}
+
+void InputDispatcher::dump(String8& dump) {
+    AutoMutex _l(mLock);
+
+    dump.append("Input Dispatcher State:\n");
+    dumpDispatchStateLocked(dump);
+
+    if (!mLastANRState.isEmpty()) {
+        dump.append("\nInput Dispatcher State at time of last ANR:\n");
+        dump.append(mLastANRState);
+    }
+}
+
+void InputDispatcher::monitor() {
+    // Acquire and release the lock to ensure that the dispatcher has not deadlocked.
+    mLock.lock();
+    mLooper->wake();
+    mDispatcherIsAliveCondition.wait(mLock);
+    mLock.unlock();
+}
+
+
+// --- InputDispatcher::Queue ---
+
+template <typename T>
+uint32_t InputDispatcher::Queue<T>::count() const {
+    uint32_t result = 0;
+    for (const T* entry = head; entry; entry = entry->next) {
+        result += 1;
+    }
+    return result;
+}
+
+
+// --- InputDispatcher::InjectionState ---
+
+InputDispatcher::InjectionState::InjectionState(int32_t injectorPid, int32_t injectorUid) :
+        refCount(1),
+        injectorPid(injectorPid), injectorUid(injectorUid),
+        injectionResult(INPUT_EVENT_INJECTION_PENDING), injectionIsAsync(false),
+        pendingForegroundDispatches(0) {
+}
+
+InputDispatcher::InjectionState::~InjectionState() {
+}
+
+void InputDispatcher::InjectionState::release() {
+    refCount -= 1;
+    if (refCount == 0) {
+        delete this;
+    } else {
+        ALOG_ASSERT(refCount > 0);
+    }
+}
+
+
+// --- InputDispatcher::EventEntry ---
+
+InputDispatcher::EventEntry::EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags) :
+        refCount(1), type(type), eventTime(eventTime), policyFlags(policyFlags),
+        injectionState(NULL), dispatchInProgress(false) {
+}
+
+InputDispatcher::EventEntry::~EventEntry() {
+    releaseInjectionState();
+}
+
+void InputDispatcher::EventEntry::release() {
+    refCount -= 1;
+    if (refCount == 0) {
+        delete this;
+    } else {
+        ALOG_ASSERT(refCount > 0);
+    }
+}
+
+void InputDispatcher::EventEntry::releaseInjectionState() {
+    if (injectionState) {
+        injectionState->release();
+        injectionState = NULL;
+    }
+}
+
+
+// --- InputDispatcher::ConfigurationChangedEntry ---
+
+InputDispatcher::ConfigurationChangedEntry::ConfigurationChangedEntry(nsecs_t eventTime) :
+        EventEntry(TYPE_CONFIGURATION_CHANGED, eventTime, 0) {
+}
+
+InputDispatcher::ConfigurationChangedEntry::~ConfigurationChangedEntry() {
+}
+
+void InputDispatcher::ConfigurationChangedEntry::appendDescription(String8& msg) const {
+    msg.append("ConfigurationChangedEvent(), policyFlags=0x%08x",
+            policyFlags);
+}
+
+
+// --- InputDispatcher::DeviceResetEntry ---
+
+InputDispatcher::DeviceResetEntry::DeviceResetEntry(nsecs_t eventTime, int32_t deviceId) :
+        EventEntry(TYPE_DEVICE_RESET, eventTime, 0),
+        deviceId(deviceId) {
+}
+
+InputDispatcher::DeviceResetEntry::~DeviceResetEntry() {
+}
+
+void InputDispatcher::DeviceResetEntry::appendDescription(String8& msg) const {
+    msg.appendFormat("DeviceResetEvent(deviceId=%d), policyFlags=0x%08x",
+            deviceId, policyFlags);
+}
+
+
+// --- InputDispatcher::KeyEntry ---
+
+InputDispatcher::KeyEntry::KeyEntry(nsecs_t eventTime,
+        int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action,
+        int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
+        int32_t repeatCount, nsecs_t downTime) :
+        EventEntry(TYPE_KEY, eventTime, policyFlags),
+        deviceId(deviceId), source(source), action(action), flags(flags),
+        keyCode(keyCode), scanCode(scanCode), metaState(metaState),
+        repeatCount(repeatCount), downTime(downTime),
+        syntheticRepeat(false), interceptKeyResult(KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN),
+        interceptKeyWakeupTime(0) {
+}
+
+InputDispatcher::KeyEntry::~KeyEntry() {
+}
+
+void InputDispatcher::KeyEntry::appendDescription(String8& msg) const {
+    msg.appendFormat("KeyEvent(deviceId=%d, source=0x%08x, action=%d, "
+            "flags=0x%08x, keyCode=%d, scanCode=%d, metaState=0x%08x, "
+            "repeatCount=%d), policyFlags=0x%08x",
+            deviceId, source, action, flags, keyCode, scanCode, metaState,
+            repeatCount, policyFlags);
+}
+
+void InputDispatcher::KeyEntry::recycle() {
+    releaseInjectionState();
+
+    dispatchInProgress = false;
+    syntheticRepeat = false;
+    interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN;
+    interceptKeyWakeupTime = 0;
+}
+
+
+// --- InputDispatcher::MotionEntry ---
+
+InputDispatcher::MotionEntry::MotionEntry(nsecs_t eventTime,
+        int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, int32_t flags,
+        int32_t metaState, int32_t buttonState,
+        int32_t edgeFlags, float xPrecision, float yPrecision,
+        nsecs_t downTime, int32_t displayId, uint32_t pointerCount,
+        const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
+        float xOffset, float yOffset) :
+        EventEntry(TYPE_MOTION, eventTime, policyFlags),
+        eventTime(eventTime),
+        deviceId(deviceId), source(source), action(action), flags(flags),
+        metaState(metaState), buttonState(buttonState), edgeFlags(edgeFlags),
+        xPrecision(xPrecision), yPrecision(yPrecision),
+        downTime(downTime), displayId(displayId), pointerCount(pointerCount) {
+    for (uint32_t i = 0; i < pointerCount; i++) {
+        this->pointerProperties[i].copyFrom(pointerProperties[i]);
+        this->pointerCoords[i].copyFrom(pointerCoords[i]);
+        if (xOffset || yOffset) {
+            this->pointerCoords[i].applyOffset(xOffset, yOffset);
+        }
+    }
+}
+
+InputDispatcher::MotionEntry::~MotionEntry() {
+}
+
+void InputDispatcher::MotionEntry::appendDescription(String8& msg) const {
+    msg.appendFormat("MotionEvent(deviceId=%d, source=0x%08x, action=%d, "
+            "flags=0x%08x, metaState=0x%08x, buttonState=0x%08x, edgeFlags=0x%08x, "
+            "xPrecision=%.1f, yPrecision=%.1f, displayId=%d, pointers=[",
+            deviceId, source, action, flags, metaState, buttonState, edgeFlags,
+            xPrecision, yPrecision, displayId);
+    for (uint32_t i = 0; i < pointerCount; i++) {
+        if (i) {
+            msg.append(", ");
+        }
+        msg.appendFormat("%d: (%.1f, %.1f)", pointerProperties[i].id,
+                pointerCoords[i].getX(), pointerCoords[i].getY());
+    }
+    msg.appendFormat("]), policyFlags=0x%08x", policyFlags);
+}
+
+
+// --- InputDispatcher::DispatchEntry ---
+
+volatile int32_t InputDispatcher::DispatchEntry::sNextSeqAtomic;
+
+InputDispatcher::DispatchEntry::DispatchEntry(EventEntry* eventEntry,
+        int32_t targetFlags, float xOffset, float yOffset, float scaleFactor) :
+        seq(nextSeq()),
+        eventEntry(eventEntry), targetFlags(targetFlags),
+        xOffset(xOffset), yOffset(yOffset), scaleFactor(scaleFactor),
+        deliveryTime(0), resolvedAction(0), resolvedFlags(0) {
+    eventEntry->refCount += 1;
+}
+
+InputDispatcher::DispatchEntry::~DispatchEntry() {
+    eventEntry->release();
+}
+
+uint32_t InputDispatcher::DispatchEntry::nextSeq() {
+    // Sequence number 0 is reserved and will never be returned.
+    uint32_t seq;
+    do {
+        seq = android_atomic_inc(&sNextSeqAtomic);
+    } while (!seq);
+    return seq;
+}
+
+
+// --- InputDispatcher::InputState ---
+
+InputDispatcher::InputState::InputState() {
+}
+
+InputDispatcher::InputState::~InputState() {
+}
+
+bool InputDispatcher::InputState::isNeutral() const {
+    return mKeyMementos.isEmpty() && mMotionMementos.isEmpty();
+}
+
+bool InputDispatcher::InputState::isHovering(int32_t deviceId, uint32_t source,
+        int32_t displayId) const {
+    for (size_t i = 0; i < mMotionMementos.size(); i++) {
+        const MotionMemento& memento = mMotionMementos.itemAt(i);
+        if (memento.deviceId == deviceId
+                && memento.source == source
+                && memento.displayId == displayId
+                && memento.hovering) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool InputDispatcher::InputState::trackKey(const KeyEntry* entry,
+        int32_t action, int32_t flags) {
+    switch (action) {
+    case AKEY_EVENT_ACTION_UP: {
+        if (entry->flags & AKEY_EVENT_FLAG_FALLBACK) {
+            for (size_t i = 0; i < mFallbackKeys.size(); ) {
+                if (mFallbackKeys.valueAt(i) == entry->keyCode) {
+                    mFallbackKeys.removeItemsAt(i);
+                } else {
+                    i += 1;
+                }
+            }
+        }
+        ssize_t index = findKeyMemento(entry);
+        if (index >= 0) {
+            mKeyMementos.removeAt(index);
+            return true;
+        }
+        /* FIXME: We can't just drop the key up event because that prevents creating
+         * popup windows that are automatically shown when a key is held and then
+         * dismissed when the key is released.  The problem is that the popup will
+         * not have received the original key down, so the key up will be considered
+         * to be inconsistent with its observed state.  We could perhaps handle this
+         * by synthesizing a key down but that will cause other problems.
+         *
+         * So for now, allow inconsistent key up events to be dispatched.
+         *
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+        ALOGD("Dropping inconsistent key up event: deviceId=%d, source=%08x, "
+                "keyCode=%d, scanCode=%d",
+                entry->deviceId, entry->source, entry->keyCode, entry->scanCode);
+#endif
+        return false;
+        */
+        return true;
+    }
+
+    case AKEY_EVENT_ACTION_DOWN: {
+        ssize_t index = findKeyMemento(entry);
+        if (index >= 0) {
+            mKeyMementos.removeAt(index);
+        }
+        addKeyMemento(entry, flags);
+        return true;
+    }
+
+    default:
+        return true;
+    }
+}
+
+bool InputDispatcher::InputState::trackMotion(const MotionEntry* entry,
+        int32_t action, int32_t flags) {
+    int32_t actionMasked = action & AMOTION_EVENT_ACTION_MASK;
+    switch (actionMasked) {
+    case AMOTION_EVENT_ACTION_UP:
+    case AMOTION_EVENT_ACTION_CANCEL: {
+        ssize_t index = findMotionMemento(entry, false /*hovering*/);
+        if (index >= 0) {
+            mMotionMementos.removeAt(index);
+            return true;
+        }
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+        ALOGD("Dropping inconsistent motion up or cancel event: deviceId=%d, source=%08x, "
+                "actionMasked=%d",
+                entry->deviceId, entry->source, actionMasked);
+#endif
+        return false;
+    }
+
+    case AMOTION_EVENT_ACTION_DOWN: {
+        ssize_t index = findMotionMemento(entry, false /*hovering*/);
+        if (index >= 0) {
+            mMotionMementos.removeAt(index);
+        }
+        addMotionMemento(entry, flags, false /*hovering*/);
+        return true;
+    }
+
+    case AMOTION_EVENT_ACTION_POINTER_UP:
+    case AMOTION_EVENT_ACTION_POINTER_DOWN:
+    case AMOTION_EVENT_ACTION_MOVE: {
+        ssize_t index = findMotionMemento(entry, false /*hovering*/);
+        if (index >= 0) {
+            MotionMemento& memento = mMotionMementos.editItemAt(index);
+            memento.setPointers(entry);
+            return true;
+        }
+        if (actionMasked == AMOTION_EVENT_ACTION_MOVE
+                && (entry->source & (AINPUT_SOURCE_CLASS_JOYSTICK
+                        | AINPUT_SOURCE_CLASS_NAVIGATION))) {
+            // Joysticks and trackballs can send MOVE events without corresponding DOWN or UP.
+            return true;
+        }
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+        ALOGD("Dropping inconsistent motion pointer up/down or move event: "
+                "deviceId=%d, source=%08x, actionMasked=%d",
+                entry->deviceId, entry->source, actionMasked);
+#endif
+        return false;
+    }
+
+    case AMOTION_EVENT_ACTION_HOVER_EXIT: {
+        ssize_t index = findMotionMemento(entry, true /*hovering*/);
+        if (index >= 0) {
+            mMotionMementos.removeAt(index);
+            return true;
+        }
+#if DEBUG_OUTBOUND_EVENT_DETAILS
+        ALOGD("Dropping inconsistent motion hover exit event: deviceId=%d, source=%08x",
+                entry->deviceId, entry->source);
+#endif
+        return false;
+    }
+
+    case AMOTION_EVENT_ACTION_HOVER_ENTER:
+    case AMOTION_EVENT_ACTION_HOVER_MOVE: {
+        ssize_t index = findMotionMemento(entry, true /*hovering*/);
+        if (index >= 0) {
+            mMotionMementos.removeAt(index);
+        }
+        addMotionMemento(entry, flags, true /*hovering*/);
+        return true;
+    }
+
+    default:
+        return true;
+    }
+}
+
+ssize_t InputDispatcher::InputState::findKeyMemento(const KeyEntry* entry) const {
+    for (size_t i = 0; i < mKeyMementos.size(); i++) {
+        const KeyMemento& memento = mKeyMementos.itemAt(i);
+        if (memento.deviceId == entry->deviceId
+                && memento.source == entry->source
+                && memento.keyCode == entry->keyCode
+                && memento.scanCode == entry->scanCode) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+ssize_t InputDispatcher::InputState::findMotionMemento(const MotionEntry* entry,
+        bool hovering) const {
+    for (size_t i = 0; i < mMotionMementos.size(); i++) {
+        const MotionMemento& memento = mMotionMementos.itemAt(i);
+        if (memento.deviceId == entry->deviceId
+                && memento.source == entry->source
+                && memento.displayId == entry->displayId
+                && memento.hovering == hovering) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+void InputDispatcher::InputState::addKeyMemento(const KeyEntry* entry, int32_t flags) {
+    mKeyMementos.push();
+    KeyMemento& memento = mKeyMementos.editTop();
+    memento.deviceId = entry->deviceId;
+    memento.source = entry->source;
+    memento.keyCode = entry->keyCode;
+    memento.scanCode = entry->scanCode;
+    memento.metaState = entry->metaState;
+    memento.flags = flags;
+    memento.downTime = entry->downTime;
+    memento.policyFlags = entry->policyFlags;
+}
+
+void InputDispatcher::InputState::addMotionMemento(const MotionEntry* entry,
+        int32_t flags, bool hovering) {
+    mMotionMementos.push();
+    MotionMemento& memento = mMotionMementos.editTop();
+    memento.deviceId = entry->deviceId;
+    memento.source = entry->source;
+    memento.flags = flags;
+    memento.xPrecision = entry->xPrecision;
+    memento.yPrecision = entry->yPrecision;
+    memento.downTime = entry->downTime;
+    memento.displayId = entry->displayId;
+    memento.setPointers(entry);
+    memento.hovering = hovering;
+    memento.policyFlags = entry->policyFlags;
+}
+
+void InputDispatcher::InputState::MotionMemento::setPointers(const MotionEntry* entry) {
+    pointerCount = entry->pointerCount;
+    for (uint32_t i = 0; i < entry->pointerCount; i++) {
+        pointerProperties[i].copyFrom(entry->pointerProperties[i]);
+        pointerCoords[i].copyFrom(entry->pointerCoords[i]);
+    }
+}
+
+void InputDispatcher::InputState::synthesizeCancelationEvents(nsecs_t currentTime,
+        Vector<EventEntry*>& outEvents, const CancelationOptions& options) {
+    for (size_t i = 0; i < mKeyMementos.size(); i++) {
+        const KeyMemento& memento = mKeyMementos.itemAt(i);
+        if (shouldCancelKey(memento, options)) {
+            outEvents.push(new KeyEntry(currentTime,
+                    memento.deviceId, memento.source, memento.policyFlags,
+                    AKEY_EVENT_ACTION_UP, memento.flags | AKEY_EVENT_FLAG_CANCELED,
+                    memento.keyCode, memento.scanCode, memento.metaState, 0, memento.downTime));
+        }
+    }
+
+    for (size_t i = 0; i < mMotionMementos.size(); i++) {
+        const MotionMemento& memento = mMotionMementos.itemAt(i);
+        if (shouldCancelMotion(memento, options)) {
+            outEvents.push(new MotionEntry(currentTime,
+                    memento.deviceId, memento.source, memento.policyFlags,
+                    memento.hovering
+                            ? AMOTION_EVENT_ACTION_HOVER_EXIT
+                            : AMOTION_EVENT_ACTION_CANCEL,
+                    memento.flags, 0, 0, 0,
+                    memento.xPrecision, memento.yPrecision, memento.downTime,
+                    memento.displayId,
+                    memento.pointerCount, memento.pointerProperties, memento.pointerCoords,
+                    0, 0));
+        }
+    }
+}
+
+void InputDispatcher::InputState::clear() {
+    mKeyMementos.clear();
+    mMotionMementos.clear();
+    mFallbackKeys.clear();
+}
+
+void InputDispatcher::InputState::copyPointerStateTo(InputState& other) const {
+    for (size_t i = 0; i < mMotionMementos.size(); i++) {
+        const MotionMemento& memento = mMotionMementos.itemAt(i);
+        if (memento.source & AINPUT_SOURCE_CLASS_POINTER) {
+            for (size_t j = 0; j < other.mMotionMementos.size(); ) {
+                const MotionMemento& otherMemento = other.mMotionMementos.itemAt(j);
+                if (memento.deviceId == otherMemento.deviceId
+                        && memento.source == otherMemento.source
+                        && memento.displayId == otherMemento.displayId) {
+                    other.mMotionMementos.removeAt(j);
+                } else {
+                    j += 1;
+                }
+            }
+            other.mMotionMementos.push(memento);
+        }
+    }
+}
+
+int32_t InputDispatcher::InputState::getFallbackKey(int32_t originalKeyCode) {
+    ssize_t index = mFallbackKeys.indexOfKey(originalKeyCode);
+    return index >= 0 ? mFallbackKeys.valueAt(index) : -1;
+}
+
+void InputDispatcher::InputState::setFallbackKey(int32_t originalKeyCode,
+        int32_t fallbackKeyCode) {
+    ssize_t index = mFallbackKeys.indexOfKey(originalKeyCode);
+    if (index >= 0) {
+        mFallbackKeys.replaceValueAt(index, fallbackKeyCode);
+    } else {
+        mFallbackKeys.add(originalKeyCode, fallbackKeyCode);
+    }
+}
+
+void InputDispatcher::InputState::removeFallbackKey(int32_t originalKeyCode) {
+    mFallbackKeys.removeItem(originalKeyCode);
+}
+
+bool InputDispatcher::InputState::shouldCancelKey(const KeyMemento& memento,
+        const CancelationOptions& options) {
+    if (options.keyCode != -1 && memento.keyCode != options.keyCode) {
+        return false;
+    }
+
+    if (options.deviceId != -1 && memento.deviceId != options.deviceId) {
+        return false;
+    }
+
+    switch (options.mode) {
+    case CancelationOptions::CANCEL_ALL_EVENTS:
+    case CancelationOptions::CANCEL_NON_POINTER_EVENTS:
+        return true;
+    case CancelationOptions::CANCEL_FALLBACK_EVENTS:
+        return memento.flags & AKEY_EVENT_FLAG_FALLBACK;
+    default:
+        return false;
+    }
+}
+
+bool InputDispatcher::InputState::shouldCancelMotion(const MotionMemento& memento,
+        const CancelationOptions& options) {
+    if (options.deviceId != -1 && memento.deviceId != options.deviceId) {
+        return false;
+    }
+
+    switch (options.mode) {
+    case CancelationOptions::CANCEL_ALL_EVENTS:
+        return true;
+    case CancelationOptions::CANCEL_POINTER_EVENTS:
+        return memento.source & AINPUT_SOURCE_CLASS_POINTER;
+    case CancelationOptions::CANCEL_NON_POINTER_EVENTS:
+        return !(memento.source & AINPUT_SOURCE_CLASS_POINTER);
+    default:
+        return false;
+    }
+}
+
+
+// --- InputDispatcher::Connection ---
+
+InputDispatcher::Connection::Connection(const sp<InputChannel>& inputChannel,
+        const sp<InputWindowHandle>& inputWindowHandle, bool monitor) :
+        status(STATUS_NORMAL), inputChannel(inputChannel), inputWindowHandle(inputWindowHandle),
+        monitor(monitor),
+        inputPublisher(inputChannel), inputPublisherBlocked(false) {
+}
+
+InputDispatcher::Connection::~Connection() {
+}
+
+const char* InputDispatcher::Connection::getWindowName() const {
+    if (inputWindowHandle != NULL) {
+        return inputWindowHandle->getName().string();
+    }
+    if (monitor) {
+        return "monitor";
+    }
+    return "?";
+}
+
+const char* InputDispatcher::Connection::getStatusLabel() const {
+    switch (status) {
+    case STATUS_NORMAL:
+        return "NORMAL";
+
+    case STATUS_BROKEN:
+        return "BROKEN";
+
+    case STATUS_ZOMBIE:
+        return "ZOMBIE";
+
+    default:
+        return "UNKNOWN";
+    }
+}
+
+InputDispatcher::DispatchEntry* InputDispatcher::Connection::findWaitQueueEntry(uint32_t seq) {
+    for (DispatchEntry* entry = waitQueue.head; entry != NULL; entry = entry->next) {
+        if (entry->seq == seq) {
+            return entry;
+        }
+    }
+    return NULL;
+}
+
+
+// --- InputDispatcher::CommandEntry ---
+
+InputDispatcher::CommandEntry::CommandEntry(Command command) :
+    command(command), eventTime(0), keyEntry(NULL), userActivityEventType(0),
+    seq(0), handled(false) {
+}
+
+InputDispatcher::CommandEntry::~CommandEntry() {
+}
+
+
+// --- InputDispatcher::TouchState ---
+
+InputDispatcher::TouchState::TouchState() :
+    down(false), split(false), deviceId(-1), source(0), displayId(-1) {
+}
+
+InputDispatcher::TouchState::~TouchState() {
+}
+
+void InputDispatcher::TouchState::reset() {
+    down = false;
+    split = false;
+    deviceId = -1;
+    source = 0;
+    displayId = -1;
+    windows.clear();
+}
+
+void InputDispatcher::TouchState::copyFrom(const TouchState& other) {
+    down = other.down;
+    split = other.split;
+    deviceId = other.deviceId;
+    source = other.source;
+    displayId = other.displayId;
+    windows = other.windows;
+}
+
+void InputDispatcher::TouchState::addOrUpdateWindow(const sp<InputWindowHandle>& windowHandle,
+        int32_t targetFlags, BitSet32 pointerIds) {
+    if (targetFlags & InputTarget::FLAG_SPLIT) {
+        split = true;
+    }
+
+    for (size_t i = 0; i < windows.size(); i++) {
+        TouchedWindow& touchedWindow = windows.editItemAt(i);
+        if (touchedWindow.windowHandle == windowHandle) {
+            touchedWindow.targetFlags |= targetFlags;
+            if (targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
+                touchedWindow.targetFlags &= ~InputTarget::FLAG_DISPATCH_AS_IS;
+            }
+            touchedWindow.pointerIds.value |= pointerIds.value;
+            return;
+        }
+    }
+
+    windows.push();
+
+    TouchedWindow& touchedWindow = windows.editTop();
+    touchedWindow.windowHandle = windowHandle;
+    touchedWindow.targetFlags = targetFlags;
+    touchedWindow.pointerIds = pointerIds;
+}
+
+void InputDispatcher::TouchState::removeWindow(const sp<InputWindowHandle>& windowHandle) {
+    for (size_t i = 0; i < windows.size(); i++) {
+        if (windows.itemAt(i).windowHandle == windowHandle) {
+            windows.removeAt(i);
+            return;
+        }
+    }
+}
+
+void InputDispatcher::TouchState::filterNonAsIsTouchWindows() {
+    for (size_t i = 0 ; i < windows.size(); ) {
+        TouchedWindow& window = windows.editItemAt(i);
+        if (window.targetFlags & (InputTarget::FLAG_DISPATCH_AS_IS
+                | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER)) {
+            window.targetFlags &= ~InputTarget::FLAG_DISPATCH_MASK;
+            window.targetFlags |= InputTarget::FLAG_DISPATCH_AS_IS;
+            i += 1;
+        } else {
+            windows.removeAt(i);
+        }
+    }
+}
+
+sp<InputWindowHandle> InputDispatcher::TouchState::getFirstForegroundWindowHandle() const {
+    for (size_t i = 0; i < windows.size(); i++) {
+        const TouchedWindow& window = windows.itemAt(i);
+        if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
+            return window.windowHandle;
+        }
+    }
+    return NULL;
+}
+
+bool InputDispatcher::TouchState::isSlippery() const {
+    // Must have exactly one foreground window.
+    bool haveSlipperyForegroundWindow = false;
+    for (size_t i = 0; i < windows.size(); i++) {
+        const TouchedWindow& window = windows.itemAt(i);
+        if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
+            if (haveSlipperyForegroundWindow
+                    || !(window.windowHandle->getInfo()->layoutParamsFlags
+                            & InputWindowInfo::FLAG_SLIPPERY)) {
+                return false;
+            }
+            haveSlipperyForegroundWindow = true;
+        }
+    }
+    return haveSlipperyForegroundWindow;
+}
+
+
+// --- InputDispatcherThread ---
+
+InputDispatcherThread::InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher) :
+        Thread(/*canCallJava*/ true), mDispatcher(dispatcher) {
+}
+
+InputDispatcherThread::~InputDispatcherThread() {
+}
+
+bool InputDispatcherThread::threadLoop() {
+    mDispatcher->dispatchOnce();
+    return true;
+}
+
+} // namespace android
diff --git a/libs/input/InputDispatcher.h b/libs/input/InputDispatcher.h
new file mode 100644
index 0000000..29854b2
--- /dev/null
+++ b/libs/input/InputDispatcher.h
@@ -0,0 +1,1124 @@
+/*
+ * Copyright (C) 2010 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 _UI_INPUT_DISPATCHER_H
+#define _UI_INPUT_DISPATCHER_H
+
+#include <input/Input.h>
+#include <input/InputTransport.h>
+#include <utils/KeyedVector.h>
+#include <utils/Vector.h>
+#include <utils/threads.h>
+#include <utils/Timers.h>
+#include <utils/RefBase.h>
+#include <utils/String8.h>
+#include <utils/Looper.h>
+#include <utils/BitSet.h>
+#include <cutils/atomic.h>
+
+#include <stddef.h>
+#include <unistd.h>
+#include <limits.h>
+
+#include "InputWindow.h"
+#include "InputApplication.h"
+#include "InputListener.h"
+
+
+namespace android {
+
+/*
+ * Constants used to report the outcome of input event injection.
+ */
+enum {
+    /* (INTERNAL USE ONLY) Specifies that injection is pending and its outcome is unknown. */
+    INPUT_EVENT_INJECTION_PENDING = -1,
+
+    /* Injection succeeded. */
+    INPUT_EVENT_INJECTION_SUCCEEDED = 0,
+
+    /* Injection failed because the injector did not have permission to inject
+     * into the application with input focus. */
+    INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1,
+
+    /* Injection failed because there were no available input targets. */
+    INPUT_EVENT_INJECTION_FAILED = 2,
+
+    /* Injection failed due to a timeout. */
+    INPUT_EVENT_INJECTION_TIMED_OUT = 3
+};
+
+/*
+ * Constants used to determine the input event injection synchronization mode.
+ */
+enum {
+    /* Injection is asynchronous and is assumed always to be successful. */
+    INPUT_EVENT_INJECTION_SYNC_NONE = 0,
+
+    /* Waits for previous events to be dispatched so that the input dispatcher can determine
+     * whether input event injection willbe permitted based on the current input focus.
+     * Does not wait for the input event to finish processing. */
+    INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1,
+
+    /* Waits for the input event to be completely processed. */
+    INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED = 2,
+};
+
+
+/*
+ * An input target specifies how an input event is to be dispatched to a particular window
+ * including the window's input channel, control flags, a timeout, and an X / Y offset to
+ * be added to input event coordinates to compensate for the absolute position of the
+ * window area.
+ */
+struct InputTarget {
+    enum {
+        /* This flag indicates that the event is being delivered to a foreground application. */
+        FLAG_FOREGROUND = 1 << 0,
+
+        /* This flag indicates that the target of a MotionEvent is partly or wholly
+         * obscured by another visible window above it.  The motion event should be
+         * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */
+        FLAG_WINDOW_IS_OBSCURED = 1 << 1,
+
+        /* This flag indicates that a motion event is being split across multiple windows. */
+        FLAG_SPLIT = 1 << 2,
+
+        /* This flag indicates that the pointer coordinates dispatched to the application
+         * will be zeroed out to avoid revealing information to an application. This is
+         * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
+         * the same UID from watching all touches. */
+        FLAG_ZERO_COORDS = 1 << 3,
+
+        /* This flag indicates that the event should be sent as is.
+         * Should always be set unless the event is to be transmuted. */
+        FLAG_DISPATCH_AS_IS = 1 << 8,
+
+        /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside
+         * of the area of this target and so should instead be delivered as an
+         * AMOTION_EVENT_ACTION_OUTSIDE to this target. */
+        FLAG_DISPATCH_AS_OUTSIDE = 1 << 9,
+
+        /* This flag indicates that a hover sequence is starting in the given window.
+         * The event is transmuted into ACTION_HOVER_ENTER. */
+        FLAG_DISPATCH_AS_HOVER_ENTER = 1 << 10,
+
+        /* This flag indicates that a hover event happened outside of a window which handled
+         * previous hover events, signifying the end of the current hover sequence for that
+         * window.
+         * The event is transmuted into ACTION_HOVER_ENTER. */
+        FLAG_DISPATCH_AS_HOVER_EXIT = 1 << 11,
+
+        /* This flag indicates that the event should be canceled.
+         * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips
+         * outside of a window. */
+        FLAG_DISPATCH_AS_SLIPPERY_EXIT = 1 << 12,
+
+        /* This flag indicates that the event should be dispatched as an initial down.
+         * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips
+         * into a new window. */
+        FLAG_DISPATCH_AS_SLIPPERY_ENTER = 1 << 13,
+
+        /* Mask for all dispatch modes. */
+        FLAG_DISPATCH_MASK = FLAG_DISPATCH_AS_IS
+                | FLAG_DISPATCH_AS_OUTSIDE
+                | FLAG_DISPATCH_AS_HOVER_ENTER
+                | FLAG_DISPATCH_AS_HOVER_EXIT
+                | FLAG_DISPATCH_AS_SLIPPERY_EXIT
+                | FLAG_DISPATCH_AS_SLIPPERY_ENTER,
+    };
+
+    // The input channel to be targeted.
+    sp<InputChannel> inputChannel;
+
+    // Flags for the input target.
+    int32_t flags;
+
+    // The x and y offset to add to a MotionEvent as it is delivered.
+    // (ignored for KeyEvents)
+    float xOffset, yOffset;
+
+    // Scaling factor to apply to MotionEvent as it is delivered.
+    // (ignored for KeyEvents)
+    float scaleFactor;
+
+    // The subset of pointer ids to include in motion events dispatched to this input target
+    // if FLAG_SPLIT is set.
+    BitSet32 pointerIds;
+};
+
+
+/*
+ * Input dispatcher configuration.
+ *
+ * Specifies various options that modify the behavior of the input dispatcher.
+ * The values provided here are merely defaults. The actual values will come from ViewConfiguration
+ * and are passed into the dispatcher during initialization.
+ */
+struct InputDispatcherConfiguration {
+    // The key repeat initial timeout.
+    nsecs_t keyRepeatTimeout;
+
+    // The key repeat inter-key delay.
+    nsecs_t keyRepeatDelay;
+
+    InputDispatcherConfiguration() :
+            keyRepeatTimeout(500 * 1000000LL),
+            keyRepeatDelay(50 * 1000000LL) { }
+};
+
+
+/*
+ * Input dispatcher policy interface.
+ *
+ * The input reader policy is used by the input reader to interact with the Window Manager
+ * and other system components.
+ *
+ * The actual implementation is partially supported by callbacks into the DVM
+ * via JNI.  This interface is also mocked in the unit tests.
+ */
+class InputDispatcherPolicyInterface : public virtual RefBase {
+protected:
+    InputDispatcherPolicyInterface() { }
+    virtual ~InputDispatcherPolicyInterface() { }
+
+public:
+    /* Notifies the system that a configuration change has occurred. */
+    virtual void notifyConfigurationChanged(nsecs_t when) = 0;
+
+    /* Notifies the system that an application is not responding.
+     * Returns a new timeout to continue waiting, or 0 to abort dispatch. */
+    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
+            const sp<InputWindowHandle>& inputWindowHandle,
+            const String8& reason) = 0;
+
+    /* Notifies the system that an input channel is unrecoverably broken. */
+    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) = 0;
+
+    /* Gets the input dispatcher configuration. */
+    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0;
+
+    /* Returns true if automatic key repeating is enabled. */
+    virtual bool isKeyRepeatEnabled() = 0;
+
+    /* Filters an input event.
+     * Return true to dispatch the event unmodified, false to consume the event.
+     * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED
+     * to injectInputEvent.
+     */
+    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) = 0;
+
+    /* Intercepts a key event immediately before queueing it.
+     * The policy can use this method as an opportunity to perform power management functions
+     * and early event preprocessing such as updating policy flags.
+     *
+     * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
+     * should be dispatched to applications.
+     */
+    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0;
+
+    /* Intercepts a touch, trackball or other motion event before queueing it.
+     * The policy can use this method as an opportunity to perform power management functions
+     * and early event preprocessing such as updating policy flags.
+     *
+     * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
+     * should be dispatched to applications.
+     */
+    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) = 0;
+
+    /* Allows the policy a chance to intercept a key before dispatching. */
+    virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
+            const KeyEvent* keyEvent, uint32_t policyFlags) = 0;
+
+    /* Allows the policy a chance to perform default processing for an unhandled key.
+     * Returns an alternate keycode to redispatch as a fallback, or 0 to give up. */
+    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
+            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) = 0;
+
+    /* Notifies the policy about switch events.
+     */
+    virtual void notifySwitch(nsecs_t when,
+            uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) = 0;
+
+    /* Poke user activity for an event dispatched to a window. */
+    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;
+
+    /* Checks whether a given application pid/uid has permission to inject input events
+     * into other applications.
+     *
+     * This method is special in that its implementation promises to be non-reentrant and
+     * is safe to call while holding other locks.  (Most other methods make no such guarantees!)
+     */
+    virtual bool checkInjectEventsPermissionNonReentrant(
+            int32_t injectorPid, int32_t injectorUid) = 0;
+};
+
+
+/* Notifies the system about input events generated by the input reader.
+ * The dispatcher is expected to be mostly asynchronous. */
+class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface {
+protected:
+    InputDispatcherInterface() { }
+    virtual ~InputDispatcherInterface() { }
+
+public:
+    /* Dumps the state of the input dispatcher.
+     *
+     * This method may be called on any thread (usually by the input manager). */
+    virtual void dump(String8& dump) = 0;
+
+    /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
+    virtual void monitor() = 0;
+
+    /* Runs a single iteration of the dispatch loop.
+     * Nominally processes one queued event, a timeout, or a response from an input consumer.
+     *
+     * This method should only be called on the input dispatcher thread.
+     */
+    virtual void dispatchOnce() = 0;
+
+    /* Injects an input event and optionally waits for sync.
+     * The synchronization mode determines whether the method blocks while waiting for
+     * input injection to proceed.
+     * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
+     *
+     * This method may be called on any thread (usually by the input manager).
+     */
+    virtual int32_t injectInputEvent(const InputEvent* event, int32_t displayId,
+            int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
+            uint32_t policyFlags) = 0;
+
+    /* Sets the list of input windows.
+     *
+     * This method may be called on any thread (usually by the input manager).
+     */
+    virtual void setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles) = 0;
+
+    /* Sets the focused application.
+     *
+     * This method may be called on any thread (usually by the input manager).
+     */
+    virtual void setFocusedApplication(
+            const sp<InputApplicationHandle>& inputApplicationHandle) = 0;
+
+    /* Sets the input dispatching mode.
+     *
+     * This method may be called on any thread (usually by the input manager).
+     */
+    virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
+
+    /* Sets whether input event filtering is enabled.
+     * When enabled, incoming input events are sent to the policy's filterInputEvent
+     * method instead of being dispatched.  The filter is expected to use
+     * injectInputEvent to inject the events it would like to have dispatched.
+     * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
+     */
+    virtual void setInputFilterEnabled(bool enabled) = 0;
+
+    /* Transfers touch focus from the window associated with one channel to the
+     * window associated with the other channel.
+     *
+     * Returns true on success.  False if the window did not actually have touch focus.
+     */
+    virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
+            const sp<InputChannel>& toChannel) = 0;
+
+    /* Registers or unregister input channels that may be used as targets for input events.
+     * If monitor is true, the channel will receive a copy of all input events.
+     *
+     * These methods may be called on any thread (usually by the input manager).
+     */
+    virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
+            const sp<InputWindowHandle>& inputWindowHandle, bool monitor) = 0;
+    virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0;
+};
+
+/* Dispatches events to input targets.  Some functions of the input dispatcher, such as
+ * identifying input targets, are controlled by a separate policy object.
+ *
+ * IMPORTANT INVARIANT:
+ *     Because the policy can potentially block or cause re-entrance into the input dispatcher,
+ *     the input dispatcher never calls into the policy while holding its internal locks.
+ *     The implementation is also carefully designed to recover from scenarios such as an
+ *     input channel becoming unregistered while identifying input targets or processing timeouts.
+ *
+ *     Methods marked 'Locked' must be called with the lock acquired.
+ *
+ *     Methods marked 'LockedInterruptible' must be called with the lock acquired but
+ *     may during the course of their execution release the lock, call into the policy, and
+ *     then reacquire the lock.  The caller is responsible for recovering gracefully.
+ *
+ *     A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa.
+ */
+class InputDispatcher : public InputDispatcherInterface {
+protected:
+    virtual ~InputDispatcher();
+
+public:
+    explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy);
+
+    virtual void dump(String8& dump);
+    virtual void monitor();
+
+    virtual void dispatchOnce();
+
+    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
+    virtual void notifyKey(const NotifyKeyArgs* args);
+    virtual void notifyMotion(const NotifyMotionArgs* args);
+    virtual void notifySwitch(const NotifySwitchArgs* args);
+    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
+
+    virtual int32_t injectInputEvent(const InputEvent* event, int32_t displayId,
+            int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
+            uint32_t policyFlags);
+
+    virtual void setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles);
+    virtual void setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle);
+    virtual void setInputDispatchMode(bool enabled, bool frozen);
+    virtual void setInputFilterEnabled(bool enabled);
+
+    virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
+            const sp<InputChannel>& toChannel);
+
+    virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
+            const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
+    virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel);
+
+private:
+    template <typename T>
+    struct Link {
+        T* next;
+        T* prev;
+
+    protected:
+        inline Link() : next(NULL), prev(NULL) { }
+    };
+
+    struct InjectionState {
+        mutable int32_t refCount;
+
+        int32_t injectorPid;
+        int32_t injectorUid;
+        int32_t injectionResult;  // initially INPUT_EVENT_INJECTION_PENDING
+        bool injectionIsAsync; // set to true if injection is not waiting for the result
+        int32_t pendingForegroundDispatches; // the number of foreground dispatches in progress
+
+        InjectionState(int32_t injectorPid, int32_t injectorUid);
+        void release();
+
+    private:
+        ~InjectionState();
+    };
+
+    struct EventEntry : Link<EventEntry> {
+        enum {
+            TYPE_CONFIGURATION_CHANGED,
+            TYPE_DEVICE_RESET,
+            TYPE_KEY,
+            TYPE_MOTION
+        };
+
+        mutable int32_t refCount;
+        int32_t type;
+        nsecs_t eventTime;
+        uint32_t policyFlags;
+        InjectionState* injectionState;
+
+        bool dispatchInProgress; // initially false, set to true while dispatching
+
+        inline bool isInjected() const { return injectionState != NULL; }
+
+        void release();
+
+        virtual void appendDescription(String8& msg) const = 0;
+
+    protected:
+        EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags);
+        virtual ~EventEntry();
+        void releaseInjectionState();
+    };
+
+    struct ConfigurationChangedEntry : EventEntry {
+        ConfigurationChangedEntry(nsecs_t eventTime);
+        virtual void appendDescription(String8& msg) const;
+
+    protected:
+        virtual ~ConfigurationChangedEntry();
+    };
+
+    struct DeviceResetEntry : EventEntry {
+        int32_t deviceId;
+
+        DeviceResetEntry(nsecs_t eventTime, int32_t deviceId);
+        virtual void appendDescription(String8& msg) const;
+
+    protected:
+        virtual ~DeviceResetEntry();
+    };
+
+    struct KeyEntry : EventEntry {
+        int32_t deviceId;
+        uint32_t source;
+        int32_t action;
+        int32_t flags;
+        int32_t keyCode;
+        int32_t scanCode;
+        int32_t metaState;
+        int32_t repeatCount;
+        nsecs_t downTime;
+
+        bool syntheticRepeat; // set to true for synthetic key repeats
+
+        enum InterceptKeyResult {
+            INTERCEPT_KEY_RESULT_UNKNOWN,
+            INTERCEPT_KEY_RESULT_SKIP,
+            INTERCEPT_KEY_RESULT_CONTINUE,
+            INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER,
+        };
+        InterceptKeyResult interceptKeyResult; // set based on the interception result
+        nsecs_t interceptKeyWakeupTime; // used with INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER
+
+        KeyEntry(nsecs_t eventTime,
+                int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action,
+                int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
+                int32_t repeatCount, nsecs_t downTime);
+        virtual void appendDescription(String8& msg) const;
+        void recycle();
+
+    protected:
+        virtual ~KeyEntry();
+    };
+
+    struct MotionEntry : EventEntry {
+        nsecs_t eventTime;
+        int32_t deviceId;
+        uint32_t source;
+        int32_t action;
+        int32_t flags;
+        int32_t metaState;
+        int32_t buttonState;
+        int32_t edgeFlags;
+        float xPrecision;
+        float yPrecision;
+        nsecs_t downTime;
+        int32_t displayId;
+        uint32_t pointerCount;
+        PointerProperties pointerProperties[MAX_POINTERS];
+        PointerCoords pointerCoords[MAX_POINTERS];
+
+        MotionEntry(nsecs_t eventTime,
+                int32_t deviceId, uint32_t source, uint32_t policyFlags,
+                int32_t action, int32_t flags,
+                int32_t metaState, int32_t buttonState, int32_t edgeFlags,
+                float xPrecision, float yPrecision,
+                nsecs_t downTime, int32_t displayId, uint32_t pointerCount,
+                const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
+                float xOffset, float yOffset);
+        virtual void appendDescription(String8& msg) const;
+
+    protected:
+        virtual ~MotionEntry();
+    };
+
+    // Tracks the progress of dispatching a particular event to a particular connection.
+    struct DispatchEntry : Link<DispatchEntry> {
+        const uint32_t seq; // unique sequence number, never 0
+
+        EventEntry* eventEntry; // the event to dispatch
+        int32_t targetFlags;
+        float xOffset;
+        float yOffset;
+        float scaleFactor;
+        nsecs_t deliveryTime; // time when the event was actually delivered
+
+        // Set to the resolved action and flags when the event is enqueued.
+        int32_t resolvedAction;
+        int32_t resolvedFlags;
+
+        DispatchEntry(EventEntry* eventEntry,
+                int32_t targetFlags, float xOffset, float yOffset, float scaleFactor);
+        ~DispatchEntry();
+
+        inline bool hasForegroundTarget() const {
+            return targetFlags & InputTarget::FLAG_FOREGROUND;
+        }
+
+        inline bool isSplit() const {
+            return targetFlags & InputTarget::FLAG_SPLIT;
+        }
+
+    private:
+        static volatile int32_t sNextSeqAtomic;
+
+        static uint32_t nextSeq();
+    };
+
+    // A command entry captures state and behavior for an action to be performed in the
+    // dispatch loop after the initial processing has taken place.  It is essentially
+    // a kind of continuation used to postpone sensitive policy interactions to a point
+    // in the dispatch loop where it is safe to release the lock (generally after finishing
+    // the critical parts of the dispatch cycle).
+    //
+    // The special thing about commands is that they can voluntarily release and reacquire
+    // the dispatcher lock at will.  Initially when the command starts running, the
+    // dispatcher lock is held.  However, if the command needs to call into the policy to
+    // do some work, it can release the lock, do the work, then reacquire the lock again
+    // before returning.
+    //
+    // This mechanism is a bit clunky but it helps to preserve the invariant that the dispatch
+    // never calls into the policy while holding its lock.
+    //
+    // Commands are implicitly 'LockedInterruptible'.
+    struct CommandEntry;
+    typedef void (InputDispatcher::*Command)(CommandEntry* commandEntry);
+
+    class Connection;
+    struct CommandEntry : Link<CommandEntry> {
+        CommandEntry(Command command);
+        ~CommandEntry();
+
+        Command command;
+
+        // parameters for the command (usage varies by command)
+        sp<Connection> connection;
+        nsecs_t eventTime;
+        KeyEntry* keyEntry;
+        sp<InputApplicationHandle> inputApplicationHandle;
+        sp<InputWindowHandle> inputWindowHandle;
+        String8 reason;
+        int32_t userActivityEventType;
+        uint32_t seq;
+        bool handled;
+    };
+
+    // Generic queue implementation.
+    template <typename T>
+    struct Queue {
+        T* head;
+        T* tail;
+
+        inline Queue() : head(NULL), tail(NULL) {
+        }
+
+        inline bool isEmpty() const {
+            return !head;
+        }
+
+        inline void enqueueAtTail(T* entry) {
+            entry->prev = tail;
+            if (tail) {
+                tail->next = entry;
+            } else {
+                head = entry;
+            }
+            entry->next = NULL;
+            tail = entry;
+        }
+
+        inline void enqueueAtHead(T* entry) {
+            entry->next = head;
+            if (head) {
+                head->prev = entry;
+            } else {
+                tail = entry;
+            }
+            entry->prev = NULL;
+            head = entry;
+        }
+
+        inline void dequeue(T* entry) {
+            if (entry->prev) {
+                entry->prev->next = entry->next;
+            } else {
+                head = entry->next;
+            }
+            if (entry->next) {
+                entry->next->prev = entry->prev;
+            } else {
+                tail = entry->prev;
+            }
+        }
+
+        inline T* dequeueAtHead() {
+            T* entry = head;
+            head = entry->next;
+            if (head) {
+                head->prev = NULL;
+            } else {
+                tail = NULL;
+            }
+            return entry;
+        }
+
+        uint32_t count() const;
+    };
+
+    /* Specifies which events are to be canceled and why. */
+    struct CancelationOptions {
+        enum Mode {
+            CANCEL_ALL_EVENTS = 0,
+            CANCEL_POINTER_EVENTS = 1,
+            CANCEL_NON_POINTER_EVENTS = 2,
+            CANCEL_FALLBACK_EVENTS = 3,
+        };
+
+        // The criterion to use to determine which events should be canceled.
+        Mode mode;
+
+        // Descriptive reason for the cancelation.
+        const char* reason;
+
+        // The specific keycode of the key event to cancel, or -1 to cancel any key event.
+        int32_t keyCode;
+
+        // The specific device id of events to cancel, or -1 to cancel events from any device.
+        int32_t deviceId;
+
+        CancelationOptions(Mode mode, const char* reason) :
+                mode(mode), reason(reason), keyCode(-1), deviceId(-1) { }
+    };
+
+    /* Tracks dispatched key and motion event state so that cancelation events can be
+     * synthesized when events are dropped. */
+    class InputState {
+    public:
+        InputState();
+        ~InputState();
+
+        // Returns true if there is no state to be canceled.
+        bool isNeutral() const;
+
+        // Returns true if the specified source is known to have received a hover enter
+        // motion event.
+        bool isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const;
+
+        // Records tracking information for a key event that has just been published.
+        // Returns true if the event should be delivered, false if it is inconsistent
+        // and should be skipped.
+        bool trackKey(const KeyEntry* entry, int32_t action, int32_t flags);
+
+        // Records tracking information for a motion event that has just been published.
+        // Returns true if the event should be delivered, false if it is inconsistent
+        // and should be skipped.
+        bool trackMotion(const MotionEntry* entry, int32_t action, int32_t flags);
+
+        // Synthesizes cancelation events for the current state and resets the tracked state.
+        void synthesizeCancelationEvents(nsecs_t currentTime,
+                Vector<EventEntry*>& outEvents, const CancelationOptions& options);
+
+        // Clears the current state.
+        void clear();
+
+        // Copies pointer-related parts of the input state to another instance.
+        void copyPointerStateTo(InputState& other) const;
+
+        // Gets the fallback key associated with a keycode.
+        // Returns -1 if none.
+        // Returns AKEYCODE_UNKNOWN if we are only dispatching the unhandled key to the policy.
+        int32_t getFallbackKey(int32_t originalKeyCode);
+
+        // Sets the fallback key for a particular keycode.
+        void setFallbackKey(int32_t originalKeyCode, int32_t fallbackKeyCode);
+
+        // Removes the fallback key for a particular keycode.
+        void removeFallbackKey(int32_t originalKeyCode);
+
+        inline const KeyedVector<int32_t, int32_t>& getFallbackKeys() const {
+            return mFallbackKeys;
+        }
+
+    private:
+        struct KeyMemento {
+            int32_t deviceId;
+            uint32_t source;
+            int32_t keyCode;
+            int32_t scanCode;
+            int32_t metaState;
+            int32_t flags;
+            nsecs_t downTime;
+            uint32_t policyFlags;
+        };
+
+        struct MotionMemento {
+            int32_t deviceId;
+            uint32_t source;
+            int32_t flags;
+            float xPrecision;
+            float yPrecision;
+            nsecs_t downTime;
+            int32_t displayId;
+            uint32_t pointerCount;
+            PointerProperties pointerProperties[MAX_POINTERS];
+            PointerCoords pointerCoords[MAX_POINTERS];
+            bool hovering;
+            uint32_t policyFlags;
+
+            void setPointers(const MotionEntry* entry);
+        };
+
+        Vector<KeyMemento> mKeyMementos;
+        Vector<MotionMemento> mMotionMementos;
+        KeyedVector<int32_t, int32_t> mFallbackKeys;
+
+        ssize_t findKeyMemento(const KeyEntry* entry) const;
+        ssize_t findMotionMemento(const MotionEntry* entry, bool hovering) const;
+
+        void addKeyMemento(const KeyEntry* entry, int32_t flags);
+        void addMotionMemento(const MotionEntry* entry, int32_t flags, bool hovering);
+
+        static bool shouldCancelKey(const KeyMemento& memento,
+                const CancelationOptions& options);
+        static bool shouldCancelMotion(const MotionMemento& memento,
+                const CancelationOptions& options);
+    };
+
+    /* Manages the dispatch state associated with a single input channel. */
+    class Connection : public RefBase {
+    protected:
+        virtual ~Connection();
+
+    public:
+        enum Status {
+            // Everything is peachy.
+            STATUS_NORMAL,
+            // An unrecoverable communication error has occurred.
+            STATUS_BROKEN,
+            // The input channel has been unregistered.
+            STATUS_ZOMBIE
+        };
+
+        Status status;
+        sp<InputChannel> inputChannel; // never null
+        sp<InputWindowHandle> inputWindowHandle; // may be null
+        bool monitor;
+        InputPublisher inputPublisher;
+        InputState inputState;
+
+        // True if the socket is full and no further events can be published until
+        // the application consumes some of the input.
+        bool inputPublisherBlocked;
+
+        // Queue of events that need to be published to the connection.
+        Queue<DispatchEntry> outboundQueue;
+
+        // Queue of events that have been published to the connection but that have not
+        // yet received a "finished" response from the application.
+        Queue<DispatchEntry> waitQueue;
+
+        explicit Connection(const sp<InputChannel>& inputChannel,
+                const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
+
+        inline const char* getInputChannelName() const { return inputChannel->getName().string(); }
+
+        const char* getWindowName() const;
+        const char* getStatusLabel() const;
+
+        DispatchEntry* findWaitQueueEntry(uint32_t seq);
+    };
+
+    enum DropReason {
+        DROP_REASON_NOT_DROPPED = 0,
+        DROP_REASON_POLICY = 1,
+        DROP_REASON_APP_SWITCH = 2,
+        DROP_REASON_DISABLED = 3,
+        DROP_REASON_BLOCKED = 4,
+        DROP_REASON_STALE = 5,
+    };
+
+    sp<InputDispatcherPolicyInterface> mPolicy;
+    InputDispatcherConfiguration mConfig;
+
+    Mutex mLock;
+
+    Condition mDispatcherIsAliveCondition;
+
+    sp<Looper> mLooper;
+
+    EventEntry* mPendingEvent;
+    Queue<EventEntry> mInboundQueue;
+    Queue<EventEntry> mRecentQueue;
+    Queue<CommandEntry> mCommandQueue;
+
+    void dispatchOnceInnerLocked(nsecs_t* nextWakeupTime);
+
+    // Enqueues an inbound event.  Returns true if mLooper->wake() should be called.
+    bool enqueueInboundEventLocked(EventEntry* entry);
+
+    // Cleans up input state when dropping an inbound event.
+    void dropInboundEventLocked(EventEntry* entry, DropReason dropReason);
+
+    // Adds an event to a queue of recent events for debugging purposes.
+    void addRecentEventLocked(EventEntry* entry);
+
+    // App switch latency optimization.
+    bool mAppSwitchSawKeyDown;
+    nsecs_t mAppSwitchDueTime;
+
+    static bool isAppSwitchKeyCode(int32_t keyCode);
+    bool isAppSwitchKeyEventLocked(KeyEntry* keyEntry);
+    bool isAppSwitchPendingLocked();
+    void resetPendingAppSwitchLocked(bool handled);
+
+    // Stale event latency optimization.
+    static bool isStaleEventLocked(nsecs_t currentTime, EventEntry* entry);
+
+    // Blocked event latency optimization.  Drops old events when the user intends
+    // to transfer focus to a new application.
+    EventEntry* mNextUnblockedEvent;
+
+    sp<InputWindowHandle> findTouchedWindowAtLocked(int32_t displayId, int32_t x, int32_t y);
+
+    // All registered connections mapped by channel file descriptor.
+    KeyedVector<int, sp<Connection> > mConnectionsByFd;
+
+    ssize_t getConnectionIndexLocked(const sp<InputChannel>& inputChannel);
+
+    // Input channels that will receive a copy of all input events.
+    Vector<sp<InputChannel> > mMonitoringChannels;
+
+    // Event injection and synchronization.
+    Condition mInjectionResultAvailableCondition;
+    bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid);
+    void setInjectionResultLocked(EventEntry* entry, int32_t injectionResult);
+
+    Condition mInjectionSyncFinishedCondition;
+    void incrementPendingForegroundDispatchesLocked(EventEntry* entry);
+    void decrementPendingForegroundDispatchesLocked(EventEntry* entry);
+
+    // Key repeat tracking.
+    struct KeyRepeatState {
+        KeyEntry* lastKeyEntry; // or null if no repeat
+        nsecs_t nextRepeatTime;
+    } mKeyRepeatState;
+
+    void resetKeyRepeatLocked();
+    KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime);
+
+    // Deferred command processing.
+    bool haveCommandsLocked() const;
+    bool runCommandsLockedInterruptible();
+    CommandEntry* postCommandLocked(Command command);
+
+    // Input filter processing.
+    bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args);
+    bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args);
+
+    // Inbound event processing.
+    void drainInboundQueueLocked();
+    void releasePendingEventLocked();
+    void releaseInboundEventLocked(EventEntry* entry);
+
+    // Dispatch state.
+    bool mDispatchEnabled;
+    bool mDispatchFrozen;
+    bool mInputFilterEnabled;
+
+    Vector<sp<InputWindowHandle> > mWindowHandles;
+
+    sp<InputWindowHandle> getWindowHandleLocked(const sp<InputChannel>& inputChannel) const;
+    bool hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const;
+
+    // Focus tracking for keys, trackball, etc.
+    sp<InputWindowHandle> mFocusedWindowHandle;
+
+    // Focus tracking for touch.
+    struct TouchedWindow {
+        sp<InputWindowHandle> windowHandle;
+        int32_t targetFlags;
+        BitSet32 pointerIds;        // zero unless target flag FLAG_SPLIT is set
+    };
+    struct TouchState {
+        bool down;
+        bool split;
+        int32_t deviceId; // id of the device that is currently down, others are rejected
+        uint32_t source;  // source of the device that is current down, others are rejected
+        int32_t displayId; // id to the display that currently has a touch, others are rejected
+        Vector<TouchedWindow> windows;
+
+        TouchState();
+        ~TouchState();
+        void reset();
+        void copyFrom(const TouchState& other);
+        void addOrUpdateWindow(const sp<InputWindowHandle>& windowHandle,
+                int32_t targetFlags, BitSet32 pointerIds);
+        void removeWindow(const sp<InputWindowHandle>& windowHandle);
+        void filterNonAsIsTouchWindows();
+        sp<InputWindowHandle> getFirstForegroundWindowHandle() const;
+        bool isSlippery() const;
+    };
+
+    KeyedVector<int32_t, TouchState> mTouchStatesByDisplay;
+    TouchState mTempTouchState;
+
+    // Focused application.
+    sp<InputApplicationHandle> mFocusedApplicationHandle;
+
+    // Dispatcher state at time of last ANR.
+    String8 mLastANRState;
+
+    // Dispatch inbound events.
+    bool dispatchConfigurationChangedLocked(
+            nsecs_t currentTime, ConfigurationChangedEntry* entry);
+    bool dispatchDeviceResetLocked(
+            nsecs_t currentTime, DeviceResetEntry* entry);
+    bool dispatchKeyLocked(
+            nsecs_t currentTime, KeyEntry* entry,
+            DropReason* dropReason, nsecs_t* nextWakeupTime);
+    bool dispatchMotionLocked(
+            nsecs_t currentTime, MotionEntry* entry,
+            DropReason* dropReason, nsecs_t* nextWakeupTime);
+    void dispatchEventLocked(nsecs_t currentTime, EventEntry* entry,
+            const Vector<InputTarget>& inputTargets);
+
+    void logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry);
+    void logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry);
+
+    // Keeping track of ANR timeouts.
+    enum InputTargetWaitCause {
+        INPUT_TARGET_WAIT_CAUSE_NONE,
+        INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY,
+        INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY,
+    };
+
+    InputTargetWaitCause mInputTargetWaitCause;
+    nsecs_t mInputTargetWaitStartTime;
+    nsecs_t mInputTargetWaitTimeoutTime;
+    bool mInputTargetWaitTimeoutExpired;
+    sp<InputApplicationHandle> mInputTargetWaitApplicationHandle;
+
+    // Contains the last window which received a hover event.
+    sp<InputWindowHandle> mLastHoverWindowHandle;
+
+    // Finding targets for input events.
+    int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry* entry,
+            const sp<InputApplicationHandle>& applicationHandle,
+            const sp<InputWindowHandle>& windowHandle,
+            nsecs_t* nextWakeupTime, const char* reason);
+    void resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
+            const sp<InputChannel>& inputChannel);
+    nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime);
+    void resetANRTimeoutsLocked();
+
+    int32_t findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry* entry,
+            Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime);
+    int32_t findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry* entry,
+            Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
+            bool* outConflictingPointerActions);
+
+    void addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
+            int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets);
+    void addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets);
+
+    void pokeUserActivityLocked(const EventEntry* eventEntry);
+    bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
+            const InjectionState* injectionState);
+    bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle,
+            int32_t x, int32_t y) const;
+    bool isWindowReadyForMoreInputLocked(nsecs_t currentTime,
+            const sp<InputWindowHandle>& windowHandle, const EventEntry* eventEntry);
+    String8 getApplicationWindowLabelLocked(const sp<InputApplicationHandle>& applicationHandle,
+            const sp<InputWindowHandle>& windowHandle);
+
+    // Manage the dispatch cycle for a single connection.
+    // These methods are deliberately not Interruptible because doing all of the work
+    // with the mutex held makes it easier to ensure that connection invariants are maintained.
+    // If needed, the methods post commands to run later once the critical bits are done.
+    void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
+            EventEntry* eventEntry, const InputTarget* inputTarget);
+    void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
+            EventEntry* eventEntry, const InputTarget* inputTarget);
+    void enqueueDispatchEntryLocked(const sp<Connection>& connection,
+            EventEntry* eventEntry, const InputTarget* inputTarget, int32_t dispatchMode);
+    void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection);
+    void finishDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
+            uint32_t seq, bool handled);
+    void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
+            bool notify);
+    void drainDispatchQueueLocked(Queue<DispatchEntry>* queue);
+    void releaseDispatchEntryLocked(DispatchEntry* dispatchEntry);
+    static int handleReceiveCallback(int fd, int events, void* data);
+
+    void synthesizeCancelationEventsForAllConnectionsLocked(
+            const CancelationOptions& options);
+    void synthesizeCancelationEventsForInputChannelLocked(const sp<InputChannel>& channel,
+            const CancelationOptions& options);
+    void synthesizeCancelationEventsForConnectionLocked(const sp<Connection>& connection,
+            const CancelationOptions& options);
+
+    // Splitting motion events across windows.
+    MotionEntry* splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds);
+
+    // Reset and drop everything the dispatcher is doing.
+    void resetAndDropEverythingLocked(const char* reason);
+
+    // Dump state.
+    void dumpDispatchStateLocked(String8& dump);
+    void logDispatchStateLocked();
+
+    // Registration.
+    void removeMonitorChannelLocked(const sp<InputChannel>& inputChannel);
+    status_t unregisterInputChannelLocked(const sp<InputChannel>& inputChannel, bool notify);
+
+    // Add or remove a connection to the mActiveConnections vector.
+    void activateConnectionLocked(Connection* connection);
+    void deactivateConnectionLocked(Connection* connection);
+
+    // Interesting events that we might like to log or tell the framework about.
+    void onDispatchCycleFinishedLocked(
+            nsecs_t currentTime, const sp<Connection>& connection, uint32_t seq, bool handled);
+    void onDispatchCycleBrokenLocked(
+            nsecs_t currentTime, const sp<Connection>& connection);
+    void onANRLocked(
+            nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle,
+            const sp<InputWindowHandle>& windowHandle,
+            nsecs_t eventTime, nsecs_t waitStartTime, const char* reason);
+
+    // Outbound policy interactions.
+    void doNotifyConfigurationChangedInterruptible(CommandEntry* commandEntry);
+    void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry);
+    void doNotifyANRLockedInterruptible(CommandEntry* commandEntry);
+    void doInterceptKeyBeforeDispatchingLockedInterruptible(CommandEntry* commandEntry);
+    void doDispatchCycleFinishedLockedInterruptible(CommandEntry* commandEntry);
+    bool afterKeyEventLockedInterruptible(const sp<Connection>& connection,
+            DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled);
+    bool afterMotionEventLockedInterruptible(const sp<Connection>& connection,
+            DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled);
+    void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry);
+    void initializeKeyEvent(KeyEvent* event, const KeyEntry* entry);
+
+    // Statistics gathering.
+    void updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry,
+            int32_t injectionResult, nsecs_t timeSpentWaitingForApplication);
+    void traceInboundQueueLengthLocked();
+    void traceOutboundQueueLengthLocked(const sp<Connection>& connection);
+    void traceWaitQueueLengthLocked(const sp<Connection>& connection);
+};
+
+/* Enqueues and dispatches input events, endlessly. */
+class InputDispatcherThread : public Thread {
+public:
+    explicit InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher);
+    ~InputDispatcherThread();
+
+private:
+    virtual bool threadLoop();
+
+    sp<InputDispatcherInterface> mDispatcher;
+};
+
+} // namespace android
+
+#endif // _UI_INPUT_DISPATCHER_H
diff --git a/services/input/InputListener.cpp b/libs/input/InputListener.cpp
similarity index 100%
rename from services/input/InputListener.cpp
rename to libs/input/InputListener.cpp
diff --git a/services/input/InputListener.h b/libs/input/InputListener.h
similarity index 100%
rename from services/input/InputListener.h
rename to libs/input/InputListener.h
diff --git a/services/input/InputManager.cpp b/libs/input/InputManager.cpp
similarity index 100%
rename from services/input/InputManager.cpp
rename to libs/input/InputManager.cpp
diff --git a/services/input/InputManager.h b/libs/input/InputManager.h
similarity index 100%
rename from services/input/InputManager.h
rename to libs/input/InputManager.h
diff --git a/libs/input/InputReader.cpp b/libs/input/InputReader.cpp
new file mode 100644
index 0000000..3c037fb8
--- /dev/null
+++ b/libs/input/InputReader.cpp
@@ -0,0 +1,6533 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#define LOG_TAG "InputReader"
+
+//#define LOG_NDEBUG 0
+
+// Log debug messages for each raw event received from the EventHub.
+#define DEBUG_RAW_EVENTS 0
+
+// Log debug messages about touch screen filtering hacks.
+#define DEBUG_HACKS 0
+
+// Log debug messages about virtual key processing.
+#define DEBUG_VIRTUAL_KEYS 0
+
+// Log debug messages about pointers.
+#define DEBUG_POINTERS 0
+
+// Log debug messages about pointer assignment calculations.
+#define DEBUG_POINTER_ASSIGNMENT 0
+
+// Log debug messages about gesture detection.
+#define DEBUG_GESTURES 0
+
+// Log debug messages about the vibrator.
+#define DEBUG_VIBRATOR 0
+
+#include "InputReader.h"
+
+#include <cutils/log.h>
+#include <input/Keyboard.h>
+#include <input/VirtualKeyMap.h>
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+#include <math.h>
+
+#define INDENT "  "
+#define INDENT2 "    "
+#define INDENT3 "      "
+#define INDENT4 "        "
+#define INDENT5 "          "
+
+namespace android {
+
+// --- Constants ---
+
+// Maximum number of slots supported when using the slot-based Multitouch Protocol B.
+static const size_t MAX_SLOTS = 32;
+
+// --- Static Functions ---
+
+template<typename T>
+inline static T abs(const T& value) {
+    return value < 0 ? - value : value;
+}
+
+template<typename T>
+inline static T min(const T& a, const T& b) {
+    return a < b ? a : b;
+}
+
+template<typename T>
+inline static void swap(T& a, T& b) {
+    T temp = a;
+    a = b;
+    b = temp;
+}
+
+inline static float avg(float x, float y) {
+    return (x + y) / 2;
+}
+
+inline static float distance(float x1, float y1, float x2, float y2) {
+    return hypotf(x1 - x2, y1 - y2);
+}
+
+inline static int32_t signExtendNybble(int32_t value) {
+    return value >= 8 ? value - 16 : value;
+}
+
+static inline const char* toString(bool value) {
+    return value ? "true" : "false";
+}
+
+static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation,
+        const int32_t map[][4], size_t mapSize) {
+    if (orientation != DISPLAY_ORIENTATION_0) {
+        for (size_t i = 0; i < mapSize; i++) {
+            if (value == map[i][0]) {
+                return map[i][orientation];
+            }
+        }
+    }
+    return value;
+}
+
+static const int32_t keyCodeRotationMap[][4] = {
+        // key codes enumerated counter-clockwise with the original (unrotated) key first
+        // no rotation,        90 degree rotation,  180 degree rotation, 270 degree rotation
+        { AKEYCODE_DPAD_DOWN,   AKEYCODE_DPAD_RIGHT,  AKEYCODE_DPAD_UP,     AKEYCODE_DPAD_LEFT },
+        { AKEYCODE_DPAD_RIGHT,  AKEYCODE_DPAD_UP,     AKEYCODE_DPAD_LEFT,   AKEYCODE_DPAD_DOWN },
+        { AKEYCODE_DPAD_UP,     AKEYCODE_DPAD_LEFT,   AKEYCODE_DPAD_DOWN,   AKEYCODE_DPAD_RIGHT },
+        { AKEYCODE_DPAD_LEFT,   AKEYCODE_DPAD_DOWN,   AKEYCODE_DPAD_RIGHT,  AKEYCODE_DPAD_UP },
+};
+static const size_t keyCodeRotationMapSize =
+        sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]);
+
+static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) {
+    return rotateValueUsingRotationMap(keyCode, orientation,
+            keyCodeRotationMap, keyCodeRotationMapSize);
+}
+
+static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) {
+    float temp;
+    switch (orientation) {
+    case DISPLAY_ORIENTATION_90:
+        temp = *deltaX;
+        *deltaX = *deltaY;
+        *deltaY = -temp;
+        break;
+
+    case DISPLAY_ORIENTATION_180:
+        *deltaX = -*deltaX;
+        *deltaY = -*deltaY;
+        break;
+
+    case DISPLAY_ORIENTATION_270:
+        temp = *deltaX;
+        *deltaX = -*deltaY;
+        *deltaY = temp;
+        break;
+    }
+}
+
+static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
+    return (sources & sourceMask & ~ AINPUT_SOURCE_CLASS_MASK) != 0;
+}
+
+// Returns true if the pointer should be reported as being down given the specified
+// button states.  This determines whether the event is reported as a touch event.
+static bool isPointerDown(int32_t buttonState) {
+    return buttonState &
+            (AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY
+                    | AMOTION_EVENT_BUTTON_TERTIARY);
+}
+
+static float calculateCommonVector(float a, float b) {
+    if (a > 0 && b > 0) {
+        return a < b ? a : b;
+    } else if (a < 0 && b < 0) {
+        return a > b ? a : b;
+    } else {
+        return 0;
+    }
+}
+
+static void synthesizeButtonKey(InputReaderContext* context, int32_t action,
+        nsecs_t when, int32_t deviceId, uint32_t source,
+        uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState,
+        int32_t buttonState, int32_t keyCode) {
+    if (
+            (action == AKEY_EVENT_ACTION_DOWN
+                    && !(lastButtonState & buttonState)
+                    && (currentButtonState & buttonState))
+            || (action == AKEY_EVENT_ACTION_UP
+                    && (lastButtonState & buttonState)
+                    && !(currentButtonState & buttonState))) {
+        NotifyKeyArgs args(when, deviceId, source, policyFlags,
+                action, 0, keyCode, 0, context->getGlobalMetaState(), when);
+        context->getListener()->notifyKey(&args);
+    }
+}
+
+static void synthesizeButtonKeys(InputReaderContext* context, int32_t action,
+        nsecs_t when, int32_t deviceId, uint32_t source,
+        uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState) {
+    synthesizeButtonKey(context, action, when, deviceId, source, policyFlags,
+            lastButtonState, currentButtonState,
+            AMOTION_EVENT_BUTTON_BACK, AKEYCODE_BACK);
+    synthesizeButtonKey(context, action, when, deviceId, source, policyFlags,
+            lastButtonState, currentButtonState,
+            AMOTION_EVENT_BUTTON_FORWARD, AKEYCODE_FORWARD);
+}
+
+
+// --- InputReaderConfiguration ---
+
+bool InputReaderConfiguration::getDisplayInfo(bool external, DisplayViewport* outViewport) const {
+    const DisplayViewport& viewport = external ? mExternalDisplay : mInternalDisplay;
+    if (viewport.displayId >= 0) {
+        *outViewport = viewport;
+        return true;
+    }
+    return false;
+}
+
+void InputReaderConfiguration::setDisplayInfo(bool external, const DisplayViewport& viewport) {
+    DisplayViewport& v = external ? mExternalDisplay : mInternalDisplay;
+    v = viewport;
+}
+
+
+// --- InputReader ---
+
+InputReader::InputReader(const sp<EventHubInterface>& eventHub,
+        const sp<InputReaderPolicyInterface>& policy,
+        const sp<InputListenerInterface>& listener) :
+        mContext(this), mEventHub(eventHub), mPolicy(policy),
+        mGlobalMetaState(0), mGeneration(1),
+        mDisableVirtualKeysTimeout(LLONG_MIN), mNextTimeout(LLONG_MAX),
+        mConfigurationChangesToRefresh(0) {
+    mQueuedListener = new QueuedInputListener(listener);
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        refreshConfigurationLocked(0);
+        updateGlobalMetaStateLocked();
+    } // release lock
+}
+
+InputReader::~InputReader() {
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        delete mDevices.valueAt(i);
+    }
+}
+
+void InputReader::loopOnce() {
+    int32_t oldGeneration;
+    int32_t timeoutMillis;
+    bool inputDevicesChanged = false;
+    Vector<InputDeviceInfo> inputDevices;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        oldGeneration = mGeneration;
+        timeoutMillis = -1;
+
+        uint32_t changes = mConfigurationChangesToRefresh;
+        if (changes) {
+            mConfigurationChangesToRefresh = 0;
+            timeoutMillis = 0;
+            refreshConfigurationLocked(changes);
+        } else if (mNextTimeout != LLONG_MAX) {
+            nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+            timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout);
+        }
+    } // release lock
+
+    size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+        mReaderIsAliveCondition.broadcast();
+
+        if (count) {
+            processEventsLocked(mEventBuffer, count);
+        }
+
+        if (mNextTimeout != LLONG_MAX) {
+            nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+            if (now >= mNextTimeout) {
+#if DEBUG_RAW_EVENTS
+                ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
+#endif
+                mNextTimeout = LLONG_MAX;
+                timeoutExpiredLocked(now);
+            }
+        }
+
+        if (oldGeneration != mGeneration) {
+            inputDevicesChanged = true;
+            getInputDevicesLocked(inputDevices);
+        }
+    } // release lock
+
+    // Send out a message that the describes the changed input devices.
+    if (inputDevicesChanged) {
+        mPolicy->notifyInputDevicesChanged(inputDevices);
+    }
+
+    // Flush queued events out to the listener.
+    // This must happen outside of the lock because the listener could potentially call
+    // back into the InputReader's methods, such as getScanCodeState, or become blocked
+    // on another thread similarly waiting to acquire the InputReader lock thereby
+    // resulting in a deadlock.  This situation is actually quite plausible because the
+    // listener is actually the input dispatcher, which calls into the window manager,
+    // which occasionally calls into the input reader.
+    mQueuedListener->flush();
+}
+
+void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
+    for (const RawEvent* rawEvent = rawEvents; count;) {
+        int32_t type = rawEvent->type;
+        size_t batchSize = 1;
+        if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
+            int32_t deviceId = rawEvent->deviceId;
+            while (batchSize < count) {
+                if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT
+                        || rawEvent[batchSize].deviceId != deviceId) {
+                    break;
+                }
+                batchSize += 1;
+            }
+#if DEBUG_RAW_EVENTS
+            ALOGD("BatchSize: %d Count: %d", batchSize, count);
+#endif
+            processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
+        } else {
+            switch (rawEvent->type) {
+            case EventHubInterface::DEVICE_ADDED:
+                addDeviceLocked(rawEvent->when, rawEvent->deviceId);
+                break;
+            case EventHubInterface::DEVICE_REMOVED:
+                removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
+                break;
+            case EventHubInterface::FINISHED_DEVICE_SCAN:
+                handleConfigurationChangedLocked(rawEvent->when);
+                break;
+            default:
+                ALOG_ASSERT(false); // can't happen
+                break;
+            }
+        }
+        count -= batchSize;
+        rawEvent += batchSize;
+    }
+}
+
+void InputReader::addDeviceLocked(nsecs_t when, int32_t deviceId) {
+    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+    if (deviceIndex >= 0) {
+        ALOGW("Ignoring spurious device added event for deviceId %d.", deviceId);
+        return;
+    }
+
+    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(deviceId);
+    uint32_t classes = mEventHub->getDeviceClasses(deviceId);
+    int32_t controllerNumber = mEventHub->getDeviceControllerNumber(deviceId);
+
+    InputDevice* device = createDeviceLocked(deviceId, controllerNumber, identifier, classes);
+    device->configure(when, &mConfig, 0);
+    device->reset(when);
+
+    if (device->isIgnored()) {
+        ALOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId,
+                identifier.name.string());
+    } else {
+        ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId,
+                identifier.name.string(), device->getSources());
+    }
+
+    mDevices.add(deviceId, device);
+    bumpGenerationLocked();
+}
+
+void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) {
+    InputDevice* device = NULL;
+    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+    if (deviceIndex < 0) {
+        ALOGW("Ignoring spurious device removed event for deviceId %d.", deviceId);
+        return;
+    }
+
+    device = mDevices.valueAt(deviceIndex);
+    mDevices.removeItemsAt(deviceIndex, 1);
+    bumpGenerationLocked();
+
+    if (device->isIgnored()) {
+        ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)",
+                device->getId(), device->getName().string());
+    } else {
+        ALOGI("Device removed: id=%d, name='%s', sources=0x%08x",
+                device->getId(), device->getName().string(), device->getSources());
+    }
+
+    device->reset(when);
+    delete device;
+}
+
+InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
+        const InputDeviceIdentifier& identifier, uint32_t classes) {
+    InputDevice* device = new InputDevice(&mContext, deviceId, bumpGenerationLocked(),
+            controllerNumber, identifier, classes);
+
+    // External devices.
+    if (classes & INPUT_DEVICE_CLASS_EXTERNAL) {
+        device->setExternal(true);
+    }
+
+    // Switch-like devices.
+    if (classes & INPUT_DEVICE_CLASS_SWITCH) {
+        device->addMapper(new SwitchInputMapper(device));
+    }
+
+    // Vibrator-like devices.
+    if (classes & INPUT_DEVICE_CLASS_VIBRATOR) {
+        device->addMapper(new VibratorInputMapper(device));
+    }
+
+    // Keyboard-like devices.
+    uint32_t keyboardSource = 0;
+    int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC;
+    if (classes & INPUT_DEVICE_CLASS_KEYBOARD) {
+        keyboardSource |= AINPUT_SOURCE_KEYBOARD;
+    }
+    if (classes & INPUT_DEVICE_CLASS_ALPHAKEY) {
+        keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC;
+    }
+    if (classes & INPUT_DEVICE_CLASS_DPAD) {
+        keyboardSource |= AINPUT_SOURCE_DPAD;
+    }
+    if (classes & INPUT_DEVICE_CLASS_GAMEPAD) {
+        keyboardSource |= AINPUT_SOURCE_GAMEPAD;
+    }
+
+    if (keyboardSource != 0) {
+        device->addMapper(new KeyboardInputMapper(device, keyboardSource, keyboardType));
+    }
+
+    // Cursor-like devices.
+    if (classes & INPUT_DEVICE_CLASS_CURSOR) {
+        device->addMapper(new CursorInputMapper(device));
+    }
+
+    // Touchscreens and touchpad devices.
+    if (classes & INPUT_DEVICE_CLASS_TOUCH_MT) {
+        device->addMapper(new MultiTouchInputMapper(device));
+    } else if (classes & INPUT_DEVICE_CLASS_TOUCH) {
+        device->addMapper(new SingleTouchInputMapper(device));
+    }
+
+    // Joystick-like devices.
+    if (classes & INPUT_DEVICE_CLASS_JOYSTICK) {
+        device->addMapper(new JoystickInputMapper(device));
+    }
+
+    return device;
+}
+
+void InputReader::processEventsForDeviceLocked(int32_t deviceId,
+        const RawEvent* rawEvents, size_t count) {
+    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+    if (deviceIndex < 0) {
+        ALOGW("Discarding event for unknown deviceId %d.", deviceId);
+        return;
+    }
+
+    InputDevice* device = mDevices.valueAt(deviceIndex);
+    if (device->isIgnored()) {
+        //ALOGD("Discarding event for ignored deviceId %d.", deviceId);
+        return;
+    }
+
+    device->process(rawEvents, count);
+}
+
+void InputReader::timeoutExpiredLocked(nsecs_t when) {
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        InputDevice* device = mDevices.valueAt(i);
+        if (!device->isIgnored()) {
+            device->timeoutExpired(when);
+        }
+    }
+}
+
+void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
+    // Reset global meta state because it depends on the list of all configured devices.
+    updateGlobalMetaStateLocked();
+
+    // Enqueue configuration changed.
+    NotifyConfigurationChangedArgs args(when);
+    mQueuedListener->notifyConfigurationChanged(&args);
+}
+
+void InputReader::refreshConfigurationLocked(uint32_t changes) {
+    mPolicy->getReaderConfiguration(&mConfig);
+    mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
+
+    if (changes) {
+        ALOGI("Reconfiguring input devices.  changes=0x%08x", changes);
+        nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+
+        if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
+            mEventHub->requestReopenDevices();
+        } else {
+            for (size_t i = 0; i < mDevices.size(); i++) {
+                InputDevice* device = mDevices.valueAt(i);
+                device->configure(now, &mConfig, changes);
+            }
+        }
+    }
+}
+
+void InputReader::updateGlobalMetaStateLocked() {
+    mGlobalMetaState = 0;
+
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        InputDevice* device = mDevices.valueAt(i);
+        mGlobalMetaState |= device->getMetaState();
+    }
+}
+
+int32_t InputReader::getGlobalMetaStateLocked() {
+    return mGlobalMetaState;
+}
+
+void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
+    mDisableVirtualKeysTimeout = time;
+}
+
+bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now,
+        InputDevice* device, int32_t keyCode, int32_t scanCode) {
+    if (now < mDisableVirtualKeysTimeout) {
+        ALOGI("Dropping virtual key from device %s because virtual keys are "
+                "temporarily disabled for the next %0.3fms.  keyCode=%d, scanCode=%d",
+                device->getName().string(),
+                (mDisableVirtualKeysTimeout - now) * 0.000001,
+                keyCode, scanCode);
+        return true;
+    } else {
+        return false;
+    }
+}
+
+void InputReader::fadePointerLocked() {
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        InputDevice* device = mDevices.valueAt(i);
+        device->fadePointer();
+    }
+}
+
+void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) {
+    if (when < mNextTimeout) {
+        mNextTimeout = when;
+        mEventHub->wake();
+    }
+}
+
+int32_t InputReader::bumpGenerationLocked() {
+    return ++mGeneration;
+}
+
+void InputReader::getInputDevices(Vector<InputDeviceInfo>& outInputDevices) {
+    AutoMutex _l(mLock);
+    getInputDevicesLocked(outInputDevices);
+}
+
+void InputReader::getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices) {
+    outInputDevices.clear();
+
+    size_t numDevices = mDevices.size();
+    for (size_t i = 0; i < numDevices; i++) {
+        InputDevice* device = mDevices.valueAt(i);
+        if (!device->isIgnored()) {
+            outInputDevices.push();
+            device->getDeviceInfo(&outInputDevices.editTop());
+        }
+    }
+}
+
+int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
+        int32_t keyCode) {
+    AutoMutex _l(mLock);
+
+    return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState);
+}
+
+int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask,
+        int32_t scanCode) {
+    AutoMutex _l(mLock);
+
+    return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState);
+}
+
+int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) {
+    AutoMutex _l(mLock);
+
+    return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState);
+}
+
+int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
+        GetStateFunc getStateFunc) {
+    int32_t result = AKEY_STATE_UNKNOWN;
+    if (deviceId >= 0) {
+        ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+        if (deviceIndex >= 0) {
+            InputDevice* device = mDevices.valueAt(deviceIndex);
+            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
+                result = (device->*getStateFunc)(sourceMask, code);
+            }
+        }
+    } else {
+        size_t numDevices = mDevices.size();
+        for (size_t i = 0; i < numDevices; i++) {
+            InputDevice* device = mDevices.valueAt(i);
+            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
+                // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
+                // value.  Otherwise, return AKEY_STATE_UP as long as one device reports it.
+                int32_t currentResult = (device->*getStateFunc)(sourceMask, code);
+                if (currentResult >= AKEY_STATE_DOWN) {
+                    return currentResult;
+                } else if (currentResult == AKEY_STATE_UP) {
+                    result = currentResult;
+                }
+            }
+        }
+    }
+    return result;
+}
+
+bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask,
+        size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) {
+    AutoMutex _l(mLock);
+
+    memset(outFlags, 0, numCodes);
+    return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags);
+}
+
+bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
+        size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) {
+    bool result = false;
+    if (deviceId >= 0) {
+        ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+        if (deviceIndex >= 0) {
+            InputDevice* device = mDevices.valueAt(deviceIndex);
+            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
+                result = device->markSupportedKeyCodes(sourceMask,
+                        numCodes, keyCodes, outFlags);
+            }
+        }
+    } else {
+        size_t numDevices = mDevices.size();
+        for (size_t i = 0; i < numDevices; i++) {
+            InputDevice* device = mDevices.valueAt(i);
+            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
+                result |= device->markSupportedKeyCodes(sourceMask,
+                        numCodes, keyCodes, outFlags);
+            }
+        }
+    }
+    return result;
+}
+
+void InputReader::requestRefreshConfiguration(uint32_t changes) {
+    AutoMutex _l(mLock);
+
+    if (changes) {
+        bool needWake = !mConfigurationChangesToRefresh;
+        mConfigurationChangesToRefresh |= changes;
+
+        if (needWake) {
+            mEventHub->wake();
+        }
+    }
+}
+
+void InputReader::vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
+        ssize_t repeat, int32_t token) {
+    AutoMutex _l(mLock);
+
+    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+    if (deviceIndex >= 0) {
+        InputDevice* device = mDevices.valueAt(deviceIndex);
+        device->vibrate(pattern, patternSize, repeat, token);
+    }
+}
+
+void InputReader::cancelVibrate(int32_t deviceId, int32_t token) {
+    AutoMutex _l(mLock);
+
+    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+    if (deviceIndex >= 0) {
+        InputDevice* device = mDevices.valueAt(deviceIndex);
+        device->cancelVibrate(token);
+    }
+}
+
+void InputReader::dump(String8& dump) {
+    AutoMutex _l(mLock);
+
+    mEventHub->dump(dump);
+    dump.append("\n");
+
+    dump.append("Input Reader State:\n");
+
+    for (size_t i = 0; i < mDevices.size(); i++) {
+        mDevices.valueAt(i)->dump(dump);
+    }
+
+    dump.append(INDENT "Configuration:\n");
+    dump.append(INDENT2 "ExcludedDeviceNames: [");
+    for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
+        if (i != 0) {
+            dump.append(", ");
+        }
+        dump.append(mConfig.excludedDeviceNames.itemAt(i).string());
+    }
+    dump.append("]\n");
+    dump.appendFormat(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
+            mConfig.virtualKeyQuietTime * 0.000001f);
+
+    dump.appendFormat(INDENT2 "PointerVelocityControlParameters: "
+            "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n",
+            mConfig.pointerVelocityControlParameters.scale,
+            mConfig.pointerVelocityControlParameters.lowThreshold,
+            mConfig.pointerVelocityControlParameters.highThreshold,
+            mConfig.pointerVelocityControlParameters.acceleration);
+
+    dump.appendFormat(INDENT2 "WheelVelocityControlParameters: "
+            "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n",
+            mConfig.wheelVelocityControlParameters.scale,
+            mConfig.wheelVelocityControlParameters.lowThreshold,
+            mConfig.wheelVelocityControlParameters.highThreshold,
+            mConfig.wheelVelocityControlParameters.acceleration);
+
+    dump.appendFormat(INDENT2 "PointerGesture:\n");
+    dump.appendFormat(INDENT3 "Enabled: %s\n",
+            toString(mConfig.pointerGesturesEnabled));
+    dump.appendFormat(INDENT3 "QuietInterval: %0.1fms\n",
+            mConfig.pointerGestureQuietInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
+            mConfig.pointerGestureDragMinSwitchSpeed);
+    dump.appendFormat(INDENT3 "TapInterval: %0.1fms\n",
+            mConfig.pointerGestureTapInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "TapDragInterval: %0.1fms\n",
+            mConfig.pointerGestureTapDragInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "TapSlop: %0.1fpx\n",
+            mConfig.pointerGestureTapSlop);
+    dump.appendFormat(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
+            mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
+    dump.appendFormat(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
+            mConfig.pointerGestureMultitouchMinDistance);
+    dump.appendFormat(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
+            mConfig.pointerGestureSwipeTransitionAngleCosine);
+    dump.appendFormat(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
+            mConfig.pointerGestureSwipeMaxWidthRatio);
+    dump.appendFormat(INDENT3 "MovementSpeedRatio: %0.1f\n",
+            mConfig.pointerGestureMovementSpeedRatio);
+    dump.appendFormat(INDENT3 "ZoomSpeedRatio: %0.1f\n",
+            mConfig.pointerGestureZoomSpeedRatio);
+}
+
+void InputReader::monitor() {
+    // Acquire and release the lock to ensure that the reader has not deadlocked.
+    mLock.lock();
+    mEventHub->wake();
+    mReaderIsAliveCondition.wait(mLock);
+    mLock.unlock();
+
+    // Check the EventHub
+    mEventHub->monitor();
+}
+
+
+// --- InputReader::ContextImpl ---
+
+InputReader::ContextImpl::ContextImpl(InputReader* reader) :
+        mReader(reader) {
+}
+
+void InputReader::ContextImpl::updateGlobalMetaState() {
+    // lock is already held by the input loop
+    mReader->updateGlobalMetaStateLocked();
+}
+
+int32_t InputReader::ContextImpl::getGlobalMetaState() {
+    // lock is already held by the input loop
+    return mReader->getGlobalMetaStateLocked();
+}
+
+void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
+    // lock is already held by the input loop
+    mReader->disableVirtualKeysUntilLocked(time);
+}
+
+bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now,
+        InputDevice* device, int32_t keyCode, int32_t scanCode) {
+    // lock is already held by the input loop
+    return mReader->shouldDropVirtualKeyLocked(now, device, keyCode, scanCode);
+}
+
+void InputReader::ContextImpl::fadePointer() {
+    // lock is already held by the input loop
+    mReader->fadePointerLocked();
+}
+
+void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
+    // lock is already held by the input loop
+    mReader->requestTimeoutAtTimeLocked(when);
+}
+
+int32_t InputReader::ContextImpl::bumpGeneration() {
+    // lock is already held by the input loop
+    return mReader->bumpGenerationLocked();
+}
+
+InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
+    return mReader->mPolicy.get();
+}
+
+InputListenerInterface* InputReader::ContextImpl::getListener() {
+    return mReader->mQueuedListener.get();
+}
+
+EventHubInterface* InputReader::ContextImpl::getEventHub() {
+    return mReader->mEventHub.get();
+}
+
+
+// --- InputReaderThread ---
+
+InputReaderThread::InputReaderThread(const sp<InputReaderInterface>& reader) :
+        Thread(/*canCallJava*/ true), mReader(reader) {
+}
+
+InputReaderThread::~InputReaderThread() {
+}
+
+bool InputReaderThread::threadLoop() {
+    mReader->loopOnce();
+    return true;
+}
+
+
+// --- InputDevice ---
+
+InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
+        int32_t controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes) :
+        mContext(context), mId(id), mGeneration(generation), mControllerNumber(controllerNumber),
+        mIdentifier(identifier), mClasses(classes),
+        mSources(0), mIsExternal(false), mDropUntilNextSync(false) {
+}
+
+InputDevice::~InputDevice() {
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        delete mMappers[i];
+    }
+    mMappers.clear();
+}
+
+void InputDevice::dump(String8& dump) {
+    InputDeviceInfo deviceInfo;
+    getDeviceInfo(& deviceInfo);
+
+    dump.appendFormat(INDENT "Device %d: %s\n", deviceInfo.getId(),
+            deviceInfo.getDisplayName().string());
+    dump.appendFormat(INDENT2 "Generation: %d\n", mGeneration);
+    dump.appendFormat(INDENT2 "IsExternal: %s\n", toString(mIsExternal));
+    dump.appendFormat(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources());
+    dump.appendFormat(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType());
+
+    const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
+    if (!ranges.isEmpty()) {
+        dump.append(INDENT2 "Motion Ranges:\n");
+        for (size_t i = 0; i < ranges.size(); i++) {
+            const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
+            const char* label = getAxisLabel(range.axis);
+            char name[32];
+            if (label) {
+                strncpy(name, label, sizeof(name));
+                name[sizeof(name) - 1] = '\0';
+            } else {
+                snprintf(name, sizeof(name), "%d", range.axis);
+            }
+            dump.appendFormat(INDENT3 "%s: source=0x%08x, "
+                    "min=%0.3f, max=%0.3f, flat=%0.3f, fuzz=%0.3f, resolution=%0.3f\n",
+                    name, range.source, range.min, range.max, range.flat, range.fuzz,
+                    range.resolution);
+        }
+    }
+
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->dump(dump);
+    }
+}
+
+void InputDevice::addMapper(InputMapper* mapper) {
+    mMappers.add(mapper);
+}
+
+void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) {
+    mSources = 0;
+
+    if (!isIgnored()) {
+        if (!changes) { // first time only
+            mContext->getEventHub()->getConfiguration(mId, &mConfiguration);
+        }
+
+        if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) {
+            if (!(mClasses & INPUT_DEVICE_CLASS_VIRTUAL)) {
+                sp<KeyCharacterMap> keyboardLayout =
+                        mContext->getPolicy()->getKeyboardLayoutOverlay(mIdentifier);
+                if (mContext->getEventHub()->setKeyboardLayoutOverlay(mId, keyboardLayout)) {
+                    bumpGeneration();
+                }
+            }
+        }
+
+        if (!changes || (changes & InputReaderConfiguration::CHANGE_DEVICE_ALIAS)) {
+            if (!(mClasses & INPUT_DEVICE_CLASS_VIRTUAL)) {
+                String8 alias = mContext->getPolicy()->getDeviceAlias(mIdentifier);
+                if (mAlias != alias) {
+                    mAlias = alias;
+                    bumpGeneration();
+                }
+            }
+        }
+
+        size_t numMappers = mMappers.size();
+        for (size_t i = 0; i < numMappers; i++) {
+            InputMapper* mapper = mMappers[i];
+            mapper->configure(when, config, changes);
+            mSources |= mapper->getSources();
+        }
+    }
+}
+
+void InputDevice::reset(nsecs_t when) {
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->reset(when);
+    }
+
+    mContext->updateGlobalMetaState();
+
+    notifyReset(when);
+}
+
+void InputDevice::process(const RawEvent* rawEvents, size_t count) {
+    // Process all of the events in order for each mapper.
+    // We cannot simply ask each mapper to process them in bulk because mappers may
+    // have side-effects that must be interleaved.  For example, joystick movement events and
+    // gamepad button presses are handled by different mappers but they should be dispatched
+    // in the order received.
+    size_t numMappers = mMappers.size();
+    for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) {
+#if DEBUG_RAW_EVENTS
+        ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%lld",
+                rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
+                rawEvent->when);
+#endif
+
+        if (mDropUntilNextSync) {
+            if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
+                mDropUntilNextSync = false;
+#if DEBUG_RAW_EVENTS
+                ALOGD("Recovered from input event buffer overrun.");
+#endif
+            } else {
+#if DEBUG_RAW_EVENTS
+                ALOGD("Dropped input event while waiting for next input sync.");
+#endif
+            }
+        } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_DROPPED) {
+            ALOGI("Detected input event buffer overrun for device %s.", getName().string());
+            mDropUntilNextSync = true;
+            reset(rawEvent->when);
+        } else {
+            for (size_t i = 0; i < numMappers; i++) {
+                InputMapper* mapper = mMappers[i];
+                mapper->process(rawEvent);
+            }
+        }
+    }
+}
+
+void InputDevice::timeoutExpired(nsecs_t when) {
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->timeoutExpired(when);
+    }
+}
+
+void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) {
+    outDeviceInfo->initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias,
+            mIsExternal);
+
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->populateDeviceInfo(outDeviceInfo);
+    }
+}
+
+int32_t InputDevice::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
+    return getState(sourceMask, keyCode, & InputMapper::getKeyCodeState);
+}
+
+int32_t InputDevice::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+    return getState(sourceMask, scanCode, & InputMapper::getScanCodeState);
+}
+
+int32_t InputDevice::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
+    return getState(sourceMask, switchCode, & InputMapper::getSwitchState);
+}
+
+int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc) {
+    int32_t result = AKEY_STATE_UNKNOWN;
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        if (sourcesMatchMask(mapper->getSources(), sourceMask)) {
+            // If any mapper reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
+            // value.  Otherwise, return AKEY_STATE_UP as long as one mapper reports it.
+            int32_t currentResult = (mapper->*getStateFunc)(sourceMask, code);
+            if (currentResult >= AKEY_STATE_DOWN) {
+                return currentResult;
+            } else if (currentResult == AKEY_STATE_UP) {
+                result = currentResult;
+            }
+        }
+    }
+    return result;
+}
+
+bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+        const int32_t* keyCodes, uint8_t* outFlags) {
+    bool result = false;
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        if (sourcesMatchMask(mapper->getSources(), sourceMask)) {
+            result |= mapper->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags);
+        }
+    }
+    return result;
+}
+
+void InputDevice::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
+        int32_t token) {
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->vibrate(pattern, patternSize, repeat, token);
+    }
+}
+
+void InputDevice::cancelVibrate(int32_t token) {
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->cancelVibrate(token);
+    }
+}
+
+int32_t InputDevice::getMetaState() {
+    int32_t result = 0;
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        result |= mapper->getMetaState();
+    }
+    return result;
+}
+
+void InputDevice::fadePointer() {
+    size_t numMappers = mMappers.size();
+    for (size_t i = 0; i < numMappers; i++) {
+        InputMapper* mapper = mMappers[i];
+        mapper->fadePointer();
+    }
+}
+
+void InputDevice::bumpGeneration() {
+    mGeneration = mContext->bumpGeneration();
+}
+
+void InputDevice::notifyReset(nsecs_t when) {
+    NotifyDeviceResetArgs args(when, mId);
+    mContext->getListener()->notifyDeviceReset(&args);
+}
+
+
+// --- CursorButtonAccumulator ---
+
+CursorButtonAccumulator::CursorButtonAccumulator() {
+    clearButtons();
+}
+
+void CursorButtonAccumulator::reset(InputDevice* device) {
+    mBtnLeft = device->isKeyPressed(BTN_LEFT);
+    mBtnRight = device->isKeyPressed(BTN_RIGHT);
+    mBtnMiddle = device->isKeyPressed(BTN_MIDDLE);
+    mBtnBack = device->isKeyPressed(BTN_BACK);
+    mBtnSide = device->isKeyPressed(BTN_SIDE);
+    mBtnForward = device->isKeyPressed(BTN_FORWARD);
+    mBtnExtra = device->isKeyPressed(BTN_EXTRA);
+    mBtnTask = device->isKeyPressed(BTN_TASK);
+}
+
+void CursorButtonAccumulator::clearButtons() {
+    mBtnLeft = 0;
+    mBtnRight = 0;
+    mBtnMiddle = 0;
+    mBtnBack = 0;
+    mBtnSide = 0;
+    mBtnForward = 0;
+    mBtnExtra = 0;
+    mBtnTask = 0;
+}
+
+void CursorButtonAccumulator::process(const RawEvent* rawEvent) {
+    if (rawEvent->type == EV_KEY) {
+        switch (rawEvent->code) {
+        case BTN_LEFT:
+            mBtnLeft = rawEvent->value;
+            break;
+        case BTN_RIGHT:
+            mBtnRight = rawEvent->value;
+            break;
+        case BTN_MIDDLE:
+            mBtnMiddle = rawEvent->value;
+            break;
+        case BTN_BACK:
+            mBtnBack = rawEvent->value;
+            break;
+        case BTN_SIDE:
+            mBtnSide = rawEvent->value;
+            break;
+        case BTN_FORWARD:
+            mBtnForward = rawEvent->value;
+            break;
+        case BTN_EXTRA:
+            mBtnExtra = rawEvent->value;
+            break;
+        case BTN_TASK:
+            mBtnTask = rawEvent->value;
+            break;
+        }
+    }
+}
+
+uint32_t CursorButtonAccumulator::getButtonState() const {
+    uint32_t result = 0;
+    if (mBtnLeft) {
+        result |= AMOTION_EVENT_BUTTON_PRIMARY;
+    }
+    if (mBtnRight) {
+        result |= AMOTION_EVENT_BUTTON_SECONDARY;
+    }
+    if (mBtnMiddle) {
+        result |= AMOTION_EVENT_BUTTON_TERTIARY;
+    }
+    if (mBtnBack || mBtnSide) {
+        result |= AMOTION_EVENT_BUTTON_BACK;
+    }
+    if (mBtnForward || mBtnExtra) {
+        result |= AMOTION_EVENT_BUTTON_FORWARD;
+    }
+    return result;
+}
+
+
+// --- CursorMotionAccumulator ---
+
+CursorMotionAccumulator::CursorMotionAccumulator() {
+    clearRelativeAxes();
+}
+
+void CursorMotionAccumulator::reset(InputDevice* device) {
+    clearRelativeAxes();
+}
+
+void CursorMotionAccumulator::clearRelativeAxes() {
+    mRelX = 0;
+    mRelY = 0;
+}
+
+void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
+    if (rawEvent->type == EV_REL) {
+        switch (rawEvent->code) {
+        case REL_X:
+            mRelX = rawEvent->value;
+            break;
+        case REL_Y:
+            mRelY = rawEvent->value;
+            break;
+        }
+    }
+}
+
+void CursorMotionAccumulator::finishSync() {
+    clearRelativeAxes();
+}
+
+
+// --- CursorScrollAccumulator ---
+
+CursorScrollAccumulator::CursorScrollAccumulator() :
+        mHaveRelWheel(false), mHaveRelHWheel(false) {
+    clearRelativeAxes();
+}
+
+void CursorScrollAccumulator::configure(InputDevice* device) {
+    mHaveRelWheel = device->getEventHub()->hasRelativeAxis(device->getId(), REL_WHEEL);
+    mHaveRelHWheel = device->getEventHub()->hasRelativeAxis(device->getId(), REL_HWHEEL);
+}
+
+void CursorScrollAccumulator::reset(InputDevice* device) {
+    clearRelativeAxes();
+}
+
+void CursorScrollAccumulator::clearRelativeAxes() {
+    mRelWheel = 0;
+    mRelHWheel = 0;
+}
+
+void CursorScrollAccumulator::process(const RawEvent* rawEvent) {
+    if (rawEvent->type == EV_REL) {
+        switch (rawEvent->code) {
+        case REL_WHEEL:
+            mRelWheel = rawEvent->value;
+            break;
+        case REL_HWHEEL:
+            mRelHWheel = rawEvent->value;
+            break;
+        }
+    }
+}
+
+void CursorScrollAccumulator::finishSync() {
+    clearRelativeAxes();
+}
+
+
+// --- TouchButtonAccumulator ---
+
+TouchButtonAccumulator::TouchButtonAccumulator() :
+        mHaveBtnTouch(false), mHaveStylus(false) {
+    clearButtons();
+}
+
+void TouchButtonAccumulator::configure(InputDevice* device) {
+    mHaveBtnTouch = device->hasKey(BTN_TOUCH);
+    mHaveStylus = device->hasKey(BTN_TOOL_PEN)
+            || device->hasKey(BTN_TOOL_RUBBER)
+            || device->hasKey(BTN_TOOL_BRUSH)
+            || device->hasKey(BTN_TOOL_PENCIL)
+            || device->hasKey(BTN_TOOL_AIRBRUSH);
+}
+
+void TouchButtonAccumulator::reset(InputDevice* device) {
+    mBtnTouch = device->isKeyPressed(BTN_TOUCH);
+    mBtnStylus = device->isKeyPressed(BTN_STYLUS);
+    mBtnStylus2 = device->isKeyPressed(BTN_STYLUS);
+    mBtnToolFinger = device->isKeyPressed(BTN_TOOL_FINGER);
+    mBtnToolPen = device->isKeyPressed(BTN_TOOL_PEN);
+    mBtnToolRubber = device->isKeyPressed(BTN_TOOL_RUBBER);
+    mBtnToolBrush = device->isKeyPressed(BTN_TOOL_BRUSH);
+    mBtnToolPencil = device->isKeyPressed(BTN_TOOL_PENCIL);
+    mBtnToolAirbrush = device->isKeyPressed(BTN_TOOL_AIRBRUSH);
+    mBtnToolMouse = device->isKeyPressed(BTN_TOOL_MOUSE);
+    mBtnToolLens = device->isKeyPressed(BTN_TOOL_LENS);
+    mBtnToolDoubleTap = device->isKeyPressed(BTN_TOOL_DOUBLETAP);
+    mBtnToolTripleTap = device->isKeyPressed(BTN_TOOL_TRIPLETAP);
+    mBtnToolQuadTap = device->isKeyPressed(BTN_TOOL_QUADTAP);
+}
+
+void TouchButtonAccumulator::clearButtons() {
+    mBtnTouch = 0;
+    mBtnStylus = 0;
+    mBtnStylus2 = 0;
+    mBtnToolFinger = 0;
+    mBtnToolPen = 0;
+    mBtnToolRubber = 0;
+    mBtnToolBrush = 0;
+    mBtnToolPencil = 0;
+    mBtnToolAirbrush = 0;
+    mBtnToolMouse = 0;
+    mBtnToolLens = 0;
+    mBtnToolDoubleTap = 0;
+    mBtnToolTripleTap = 0;
+    mBtnToolQuadTap = 0;
+}
+
+void TouchButtonAccumulator::process(const RawEvent* rawEvent) {
+    if (rawEvent->type == EV_KEY) {
+        switch (rawEvent->code) {
+        case BTN_TOUCH:
+            mBtnTouch = rawEvent->value;
+            break;
+        case BTN_STYLUS:
+            mBtnStylus = rawEvent->value;
+            break;
+        case BTN_STYLUS2:
+            mBtnStylus2 = rawEvent->value;
+            break;
+        case BTN_TOOL_FINGER:
+            mBtnToolFinger = rawEvent->value;
+            break;
+        case BTN_TOOL_PEN:
+            mBtnToolPen = rawEvent->value;
+            break;
+        case BTN_TOOL_RUBBER:
+            mBtnToolRubber = rawEvent->value;
+            break;
+        case BTN_TOOL_BRUSH:
+            mBtnToolBrush = rawEvent->value;
+            break;
+        case BTN_TOOL_PENCIL:
+            mBtnToolPencil = rawEvent->value;
+            break;
+        case BTN_TOOL_AIRBRUSH:
+            mBtnToolAirbrush = rawEvent->value;
+            break;
+        case BTN_TOOL_MOUSE:
+            mBtnToolMouse = rawEvent->value;
+            break;
+        case BTN_TOOL_LENS:
+            mBtnToolLens = rawEvent->value;
+            break;
+        case BTN_TOOL_DOUBLETAP:
+            mBtnToolDoubleTap = rawEvent->value;
+            break;
+        case BTN_TOOL_TRIPLETAP:
+            mBtnToolTripleTap = rawEvent->value;
+            break;
+        case BTN_TOOL_QUADTAP:
+            mBtnToolQuadTap = rawEvent->value;
+            break;
+        }
+    }
+}
+
+uint32_t TouchButtonAccumulator::getButtonState() const {
+    uint32_t result = 0;
+    if (mBtnStylus) {
+        result |= AMOTION_EVENT_BUTTON_SECONDARY;
+    }
+    if (mBtnStylus2) {
+        result |= AMOTION_EVENT_BUTTON_TERTIARY;
+    }
+    return result;
+}
+
+int32_t TouchButtonAccumulator::getToolType() const {
+    if (mBtnToolMouse || mBtnToolLens) {
+        return AMOTION_EVENT_TOOL_TYPE_MOUSE;
+    }
+    if (mBtnToolRubber) {
+        return AMOTION_EVENT_TOOL_TYPE_ERASER;
+    }
+    if (mBtnToolPen || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush) {
+        return AMOTION_EVENT_TOOL_TYPE_STYLUS;
+    }
+    if (mBtnToolFinger || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap) {
+        return AMOTION_EVENT_TOOL_TYPE_FINGER;
+    }
+    return AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
+}
+
+bool TouchButtonAccumulator::isToolActive() const {
+    return mBtnTouch || mBtnToolFinger || mBtnToolPen || mBtnToolRubber
+            || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush
+            || mBtnToolMouse || mBtnToolLens
+            || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap;
+}
+
+bool TouchButtonAccumulator::isHovering() const {
+    return mHaveBtnTouch && !mBtnTouch;
+}
+
+bool TouchButtonAccumulator::hasStylus() const {
+    return mHaveStylus;
+}
+
+
+// --- RawPointerAxes ---
+
+RawPointerAxes::RawPointerAxes() {
+    clear();
+}
+
+void RawPointerAxes::clear() {
+    x.clear();
+    y.clear();
+    pressure.clear();
+    touchMajor.clear();
+    touchMinor.clear();
+    toolMajor.clear();
+    toolMinor.clear();
+    orientation.clear();
+    distance.clear();
+    tiltX.clear();
+    tiltY.clear();
+    trackingId.clear();
+    slot.clear();
+}
+
+
+// --- RawPointerData ---
+
+RawPointerData::RawPointerData() {
+    clear();
+}
+
+void RawPointerData::clear() {
+    pointerCount = 0;
+    clearIdBits();
+}
+
+void RawPointerData::copyFrom(const RawPointerData& other) {
+    pointerCount = other.pointerCount;
+    hoveringIdBits = other.hoveringIdBits;
+    touchingIdBits = other.touchingIdBits;
+
+    for (uint32_t i = 0; i < pointerCount; i++) {
+        pointers[i] = other.pointers[i];
+
+        int id = pointers[i].id;
+        idToIndex[id] = other.idToIndex[id];
+    }
+}
+
+void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) const {
+    float x = 0, y = 0;
+    uint32_t count = touchingIdBits.count();
+    if (count) {
+        for (BitSet32 idBits(touchingIdBits); !idBits.isEmpty(); ) {
+            uint32_t id = idBits.clearFirstMarkedBit();
+            const Pointer& pointer = pointerForId(id);
+            x += pointer.x;
+            y += pointer.y;
+        }
+        x /= count;
+        y /= count;
+    }
+    *outX = x;
+    *outY = y;
+}
+
+
+// --- CookedPointerData ---
+
+CookedPointerData::CookedPointerData() {
+    clear();
+}
+
+void CookedPointerData::clear() {
+    pointerCount = 0;
+    hoveringIdBits.clear();
+    touchingIdBits.clear();
+}
+
+void CookedPointerData::copyFrom(const CookedPointerData& other) {
+    pointerCount = other.pointerCount;
+    hoveringIdBits = other.hoveringIdBits;
+    touchingIdBits = other.touchingIdBits;
+
+    for (uint32_t i = 0; i < pointerCount; i++) {
+        pointerProperties[i].copyFrom(other.pointerProperties[i]);
+        pointerCoords[i].copyFrom(other.pointerCoords[i]);
+
+        int id = pointerProperties[i].id;
+        idToIndex[id] = other.idToIndex[id];
+    }
+}
+
+
+// --- SingleTouchMotionAccumulator ---
+
+SingleTouchMotionAccumulator::SingleTouchMotionAccumulator() {
+    clearAbsoluteAxes();
+}
+
+void SingleTouchMotionAccumulator::reset(InputDevice* device) {
+    mAbsX = device->getAbsoluteAxisValue(ABS_X);
+    mAbsY = device->getAbsoluteAxisValue(ABS_Y);
+    mAbsPressure = device->getAbsoluteAxisValue(ABS_PRESSURE);
+    mAbsToolWidth = device->getAbsoluteAxisValue(ABS_TOOL_WIDTH);
+    mAbsDistance = device->getAbsoluteAxisValue(ABS_DISTANCE);
+    mAbsTiltX = device->getAbsoluteAxisValue(ABS_TILT_X);
+    mAbsTiltY = device->getAbsoluteAxisValue(ABS_TILT_Y);
+}
+
+void SingleTouchMotionAccumulator::clearAbsoluteAxes() {
+    mAbsX = 0;
+    mAbsY = 0;
+    mAbsPressure = 0;
+    mAbsToolWidth = 0;
+    mAbsDistance = 0;
+    mAbsTiltX = 0;
+    mAbsTiltY = 0;
+}
+
+void SingleTouchMotionAccumulator::process(const RawEvent* rawEvent) {
+    if (rawEvent->type == EV_ABS) {
+        switch (rawEvent->code) {
+        case ABS_X:
+            mAbsX = rawEvent->value;
+            break;
+        case ABS_Y:
+            mAbsY = rawEvent->value;
+            break;
+        case ABS_PRESSURE:
+            mAbsPressure = rawEvent->value;
+            break;
+        case ABS_TOOL_WIDTH:
+            mAbsToolWidth = rawEvent->value;
+            break;
+        case ABS_DISTANCE:
+            mAbsDistance = rawEvent->value;
+            break;
+        case ABS_TILT_X:
+            mAbsTiltX = rawEvent->value;
+            break;
+        case ABS_TILT_Y:
+            mAbsTiltY = rawEvent->value;
+            break;
+        }
+    }
+}
+
+
+// --- MultiTouchMotionAccumulator ---
+
+MultiTouchMotionAccumulator::MultiTouchMotionAccumulator() :
+        mCurrentSlot(-1), mSlots(NULL), mSlotCount(0), mUsingSlotsProtocol(false),
+        mHaveStylus(false) {
+}
+
+MultiTouchMotionAccumulator::~MultiTouchMotionAccumulator() {
+    delete[] mSlots;
+}
+
+void MultiTouchMotionAccumulator::configure(InputDevice* device,
+        size_t slotCount, bool usingSlotsProtocol) {
+    mSlotCount = slotCount;
+    mUsingSlotsProtocol = usingSlotsProtocol;
+    mHaveStylus = device->hasAbsoluteAxis(ABS_MT_TOOL_TYPE);
+
+    delete[] mSlots;
+    mSlots = new Slot[slotCount];
+}
+
+void MultiTouchMotionAccumulator::reset(InputDevice* device) {
+    // Unfortunately there is no way to read the initial contents of the slots.
+    // So when we reset the accumulator, we must assume they are all zeroes.
+    if (mUsingSlotsProtocol) {
+        // Query the driver for the current slot index and use it as the initial slot
+        // before we start reading events from the device.  It is possible that the
+        // current slot index will not be the same as it was when the first event was
+        // written into the evdev buffer, which means the input mapper could start
+        // out of sync with the initial state of the events in the evdev buffer.
+        // In the extremely unlikely case that this happens, the data from
+        // two slots will be confused until the next ABS_MT_SLOT event is received.
+        // This can cause the touch point to "jump", but at least there will be
+        // no stuck touches.
+        int32_t initialSlot;
+        status_t status = device->getEventHub()->getAbsoluteAxisValue(device->getId(),
+                ABS_MT_SLOT, &initialSlot);
+        if (status) {
+            ALOGD("Could not retrieve current multitouch slot index.  status=%d", status);
+            initialSlot = -1;
+        }
+        clearSlots(initialSlot);
+    } else {
+        clearSlots(-1);
+    }
+}
+
+void MultiTouchMotionAccumulator::clearSlots(int32_t initialSlot) {
+    if (mSlots) {
+        for (size_t i = 0; i < mSlotCount; i++) {
+            mSlots[i].clear();
+        }
+    }
+    mCurrentSlot = initialSlot;
+}
+
+void MultiTouchMotionAccumulator::process(const RawEvent* rawEvent) {
+    if (rawEvent->type == EV_ABS) {
+        bool newSlot = false;
+        if (mUsingSlotsProtocol) {
+            if (rawEvent->code == ABS_MT_SLOT) {
+                mCurrentSlot = rawEvent->value;
+                newSlot = true;
+            }
+        } else if (mCurrentSlot < 0) {
+            mCurrentSlot = 0;
+        }
+
+        if (mCurrentSlot < 0 || size_t(mCurrentSlot) >= mSlotCount) {
+#if DEBUG_POINTERS
+            if (newSlot) {
+                ALOGW("MultiTouch device emitted invalid slot index %d but it "
+                        "should be between 0 and %d; ignoring this slot.",
+                        mCurrentSlot, mSlotCount - 1);
+            }
+#endif
+        } else {
+            Slot* slot = &mSlots[mCurrentSlot];
+
+            switch (rawEvent->code) {
+            case ABS_MT_POSITION_X:
+                slot->mInUse = true;
+                slot->mAbsMTPositionX = rawEvent->value;
+                break;
+            case ABS_MT_POSITION_Y:
+                slot->mInUse = true;
+                slot->mAbsMTPositionY = rawEvent->value;
+                break;
+            case ABS_MT_TOUCH_MAJOR:
+                slot->mInUse = true;
+                slot->mAbsMTTouchMajor = rawEvent->value;
+                break;
+            case ABS_MT_TOUCH_MINOR:
+                slot->mInUse = true;
+                slot->mAbsMTTouchMinor = rawEvent->value;
+                slot->mHaveAbsMTTouchMinor = true;
+                break;
+            case ABS_MT_WIDTH_MAJOR:
+                slot->mInUse = true;
+                slot->mAbsMTWidthMajor = rawEvent->value;
+                break;
+            case ABS_MT_WIDTH_MINOR:
+                slot->mInUse = true;
+                slot->mAbsMTWidthMinor = rawEvent->value;
+                slot->mHaveAbsMTWidthMinor = true;
+                break;
+            case ABS_MT_ORIENTATION:
+                slot->mInUse = true;
+                slot->mAbsMTOrientation = rawEvent->value;
+                break;
+            case ABS_MT_TRACKING_ID:
+                if (mUsingSlotsProtocol && rawEvent->value < 0) {
+                    // The slot is no longer in use but it retains its previous contents,
+                    // which may be reused for subsequent touches.
+                    slot->mInUse = false;
+                } else {
+                    slot->mInUse = true;
+                    slot->mAbsMTTrackingId = rawEvent->value;
+                }
+                break;
+            case ABS_MT_PRESSURE:
+                slot->mInUse = true;
+                slot->mAbsMTPressure = rawEvent->value;
+                break;
+            case ABS_MT_DISTANCE:
+                slot->mInUse = true;
+                slot->mAbsMTDistance = rawEvent->value;
+                break;
+            case ABS_MT_TOOL_TYPE:
+                slot->mInUse = true;
+                slot->mAbsMTToolType = rawEvent->value;
+                slot->mHaveAbsMTToolType = true;
+                break;
+            }
+        }
+    } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_MT_REPORT) {
+        // MultiTouch Sync: The driver has returned all data for *one* of the pointers.
+        mCurrentSlot += 1;
+    }
+}
+
+void MultiTouchMotionAccumulator::finishSync() {
+    if (!mUsingSlotsProtocol) {
+        clearSlots(-1);
+    }
+}
+
+bool MultiTouchMotionAccumulator::hasStylus() const {
+    return mHaveStylus;
+}
+
+
+// --- MultiTouchMotionAccumulator::Slot ---
+
+MultiTouchMotionAccumulator::Slot::Slot() {
+    clear();
+}
+
+void MultiTouchMotionAccumulator::Slot::clear() {
+    mInUse = false;
+    mHaveAbsMTTouchMinor = false;
+    mHaveAbsMTWidthMinor = false;
+    mHaveAbsMTToolType = false;
+    mAbsMTPositionX = 0;
+    mAbsMTPositionY = 0;
+    mAbsMTTouchMajor = 0;
+    mAbsMTTouchMinor = 0;
+    mAbsMTWidthMajor = 0;
+    mAbsMTWidthMinor = 0;
+    mAbsMTOrientation = 0;
+    mAbsMTTrackingId = -1;
+    mAbsMTPressure = 0;
+    mAbsMTDistance = 0;
+    mAbsMTToolType = 0;
+}
+
+int32_t MultiTouchMotionAccumulator::Slot::getToolType() const {
+    if (mHaveAbsMTToolType) {
+        switch (mAbsMTToolType) {
+        case MT_TOOL_FINGER:
+            return AMOTION_EVENT_TOOL_TYPE_FINGER;
+        case MT_TOOL_PEN:
+            return AMOTION_EVENT_TOOL_TYPE_STYLUS;
+        }
+    }
+    return AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
+}
+
+
+// --- InputMapper ---
+
+InputMapper::InputMapper(InputDevice* device) :
+        mDevice(device), mContext(device->getContext()) {
+}
+
+InputMapper::~InputMapper() {
+}
+
+void InputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+    info->addSource(getSources());
+}
+
+void InputMapper::dump(String8& dump) {
+}
+
+void InputMapper::configure(nsecs_t when,
+        const InputReaderConfiguration* config, uint32_t changes) {
+}
+
+void InputMapper::reset(nsecs_t when) {
+}
+
+void InputMapper::timeoutExpired(nsecs_t when) {
+}
+
+int32_t InputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
+    return AKEY_STATE_UNKNOWN;
+}
+
+int32_t InputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+    return AKEY_STATE_UNKNOWN;
+}
+
+int32_t InputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
+    return AKEY_STATE_UNKNOWN;
+}
+
+bool InputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+        const int32_t* keyCodes, uint8_t* outFlags) {
+    return false;
+}
+
+void InputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
+        int32_t token) {
+}
+
+void InputMapper::cancelVibrate(int32_t token) {
+}
+
+int32_t InputMapper::getMetaState() {
+    return 0;
+}
+
+void InputMapper::fadePointer() {
+}
+
+status_t InputMapper::getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo) {
+    return getEventHub()->getAbsoluteAxisInfo(getDeviceId(), axis, axisInfo);
+}
+
+void InputMapper::bumpGeneration() {
+    mDevice->bumpGeneration();
+}
+
+void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump,
+        const RawAbsoluteAxisInfo& axis, const char* name) {
+    if (axis.valid) {
+        dump.appendFormat(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n",
+                name, axis.minValue, axis.maxValue, axis.flat, axis.fuzz, axis.resolution);
+    } else {
+        dump.appendFormat(INDENT4 "%s: unknown range\n", name);
+    }
+}
+
+
+// --- SwitchInputMapper ---
+
+SwitchInputMapper::SwitchInputMapper(InputDevice* device) :
+        InputMapper(device), mUpdatedSwitchValues(0), mUpdatedSwitchMask(0) {
+}
+
+SwitchInputMapper::~SwitchInputMapper() {
+}
+
+uint32_t SwitchInputMapper::getSources() {
+    return AINPUT_SOURCE_SWITCH;
+}
+
+void SwitchInputMapper::process(const RawEvent* rawEvent) {
+    switch (rawEvent->type) {
+    case EV_SW:
+        processSwitch(rawEvent->code, rawEvent->value);
+        break;
+
+    case EV_SYN:
+        if (rawEvent->code == SYN_REPORT) {
+            sync(rawEvent->when);
+        }
+    }
+}
+
+void SwitchInputMapper::processSwitch(int32_t switchCode, int32_t switchValue) {
+    if (switchCode >= 0 && switchCode < 32) {
+        if (switchValue) {
+            mUpdatedSwitchValues |= 1 << switchCode;
+        }
+        mUpdatedSwitchMask |= 1 << switchCode;
+    }
+}
+
+void SwitchInputMapper::sync(nsecs_t when) {
+    if (mUpdatedSwitchMask) {
+        NotifySwitchArgs args(when, 0, mUpdatedSwitchValues, mUpdatedSwitchMask);
+        getListener()->notifySwitch(&args);
+
+        mUpdatedSwitchValues = 0;
+        mUpdatedSwitchMask = 0;
+    }
+}
+
+int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
+    return getEventHub()->getSwitchState(getDeviceId(), switchCode);
+}
+
+
+// --- VibratorInputMapper ---
+
+VibratorInputMapper::VibratorInputMapper(InputDevice* device) :
+        InputMapper(device), mVibrating(false) {
+}
+
+VibratorInputMapper::~VibratorInputMapper() {
+}
+
+uint32_t VibratorInputMapper::getSources() {
+    return 0;
+}
+
+void VibratorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+    InputMapper::populateDeviceInfo(info);
+
+    info->setVibrator(true);
+}
+
+void VibratorInputMapper::process(const RawEvent* rawEvent) {
+    // TODO: Handle FF_STATUS, although it does not seem to be widely supported.
+}
+
+void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
+        int32_t token) {
+#if DEBUG_VIBRATOR
+    String8 patternStr;
+    for (size_t i = 0; i < patternSize; i++) {
+        if (i != 0) {
+            patternStr.append(", ");
+        }
+        patternStr.appendFormat("%lld", pattern[i]);
+    }
+    ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%ld, token=%d",
+            getDeviceId(), patternStr.string(), repeat, token);
+#endif
+
+    mVibrating = true;
+    memcpy(mPattern, pattern, patternSize * sizeof(nsecs_t));
+    mPatternSize = patternSize;
+    mRepeat = repeat;
+    mToken = token;
+    mIndex = -1;
+
+    nextStep();
+}
+
+void VibratorInputMapper::cancelVibrate(int32_t token) {
+#if DEBUG_VIBRATOR
+    ALOGD("cancelVibrate: deviceId=%d, token=%d", getDeviceId(), token);
+#endif
+
+    if (mVibrating && mToken == token) {
+        stopVibrating();
+    }
+}
+
+void VibratorInputMapper::timeoutExpired(nsecs_t when) {
+    if (mVibrating) {
+        if (when >= mNextStepTime) {
+            nextStep();
+        } else {
+            getContext()->requestTimeoutAtTime(mNextStepTime);
+        }
+    }
+}
+
+void VibratorInputMapper::nextStep() {
+    mIndex += 1;
+    if (size_t(mIndex) >= mPatternSize) {
+        if (mRepeat < 0) {
+            // We are done.
+            stopVibrating();
+            return;
+        }
+        mIndex = mRepeat;
+    }
+
+    bool vibratorOn = mIndex & 1;
+    nsecs_t duration = mPattern[mIndex];
+    if (vibratorOn) {
+#if DEBUG_VIBRATOR
+        ALOGD("nextStep: sending vibrate deviceId=%d, duration=%lld",
+                getDeviceId(), duration);
+#endif
+        getEventHub()->vibrate(getDeviceId(), duration);
+    } else {
+#if DEBUG_VIBRATOR
+        ALOGD("nextStep: sending cancel vibrate deviceId=%d", getDeviceId());
+#endif
+        getEventHub()->cancelVibrate(getDeviceId());
+    }
+    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
+    mNextStepTime = now + duration;
+    getContext()->requestTimeoutAtTime(mNextStepTime);
+#if DEBUG_VIBRATOR
+    ALOGD("nextStep: scheduled timeout in %0.3fms", duration * 0.000001f);
+#endif
+}
+
+void VibratorInputMapper::stopVibrating() {
+    mVibrating = false;
+#if DEBUG_VIBRATOR
+    ALOGD("stopVibrating: sending cancel vibrate deviceId=%d", getDeviceId());
+#endif
+    getEventHub()->cancelVibrate(getDeviceId());
+}
+
+void VibratorInputMapper::dump(String8& dump) {
+    dump.append(INDENT2 "Vibrator Input Mapper:\n");
+    dump.appendFormat(INDENT3 "Vibrating: %s\n", toString(mVibrating));
+}
+
+
+// --- KeyboardInputMapper ---
+
+KeyboardInputMapper::KeyboardInputMapper(InputDevice* device,
+        uint32_t source, int32_t keyboardType) :
+        InputMapper(device), mSource(source),
+        mKeyboardType(keyboardType) {
+}
+
+KeyboardInputMapper::~KeyboardInputMapper() {
+}
+
+uint32_t KeyboardInputMapper::getSources() {
+    return mSource;
+}
+
+void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+    InputMapper::populateDeviceInfo(info);
+
+    info->setKeyboardType(mKeyboardType);
+    info->setKeyCharacterMap(getEventHub()->getKeyCharacterMap(getDeviceId()));
+}
+
+void KeyboardInputMapper::dump(String8& dump) {
+    dump.append(INDENT2 "Keyboard Input Mapper:\n");
+    dumpParameters(dump);
+    dump.appendFormat(INDENT3 "KeyboardType: %d\n", mKeyboardType);
+    dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation);
+    dump.appendFormat(INDENT3 "KeyDowns: %d keys currently down\n", mKeyDowns.size());
+    dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mMetaState);
+    dump.appendFormat(INDENT3 "DownTime: %lld\n", mDownTime);
+}
+
+
+void KeyboardInputMapper::configure(nsecs_t when,
+        const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(when, config, changes);
+
+    if (!changes) { // first time only
+        // Configure basic parameters.
+        configureParameters();
+    }
+
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
+        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
+            DisplayViewport v;
+            if (config->getDisplayInfo(false /*external*/, &v)) {
+                mOrientation = v.orientation;
+            } else {
+                mOrientation = DISPLAY_ORIENTATION_0;
+            }
+        } else {
+            mOrientation = DISPLAY_ORIENTATION_0;
+        }
+    }
+}
+
+void KeyboardInputMapper::configureParameters() {
+    mParameters.orientationAware = false;
+    getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"),
+            mParameters.orientationAware);
+
+    mParameters.hasAssociatedDisplay = false;
+    if (mParameters.orientationAware) {
+        mParameters.hasAssociatedDisplay = true;
+    }
+}
+
+void KeyboardInputMapper::dumpParameters(String8& dump) {
+    dump.append(INDENT3 "Parameters:\n");
+    dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
+            toString(mParameters.hasAssociatedDisplay));
+    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
+            toString(mParameters.orientationAware));
+}
+
+void KeyboardInputMapper::reset(nsecs_t when) {
+    mMetaState = AMETA_NONE;
+    mDownTime = 0;
+    mKeyDowns.clear();
+    mCurrentHidUsage = 0;
+
+    resetLedState();
+
+    InputMapper::reset(when);
+}
+
+void KeyboardInputMapper::process(const RawEvent* rawEvent) {
+    switch (rawEvent->type) {
+    case EV_KEY: {
+        int32_t scanCode = rawEvent->code;
+        int32_t usageCode = mCurrentHidUsage;
+        mCurrentHidUsage = 0;
+
+        if (isKeyboardOrGamepadKey(scanCode)) {
+            int32_t keyCode;
+            uint32_t flags;
+            if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, &keyCode, &flags)) {
+                keyCode = AKEYCODE_UNKNOWN;
+                flags = 0;
+            }
+            processKey(rawEvent->when, rawEvent->value != 0, keyCode, scanCode, flags);
+        }
+        break;
+    }
+    case EV_MSC: {
+        if (rawEvent->code == MSC_SCAN) {
+            mCurrentHidUsage = rawEvent->value;
+        }
+        break;
+    }
+    case EV_SYN: {
+        if (rawEvent->code == SYN_REPORT) {
+            mCurrentHidUsage = 0;
+        }
+    }
+    }
+}
+
+bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) {
+    return scanCode < BTN_MOUSE
+        || scanCode >= KEY_OK
+        || (scanCode >= BTN_MISC && scanCode < BTN_MOUSE)
+        || (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI);
+}
+
+void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
+        int32_t scanCode, uint32_t policyFlags) {
+
+    if (down) {
+        // Rotate key codes according to orientation if needed.
+        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
+            keyCode = rotateKeyCode(keyCode, mOrientation);
+        }
+
+        // Add key down.
+        ssize_t keyDownIndex = findKeyDown(scanCode);
+        if (keyDownIndex >= 0) {
+            // key repeat, be sure to use same keycode as before in case of rotation
+            keyCode = mKeyDowns.itemAt(keyDownIndex).keyCode;
+        } else {
+            // key down
+            if ((policyFlags & POLICY_FLAG_VIRTUAL)
+                    && mContext->shouldDropVirtualKey(when,
+                            getDevice(), keyCode, scanCode)) {
+                return;
+            }
+
+            mKeyDowns.push();
+            KeyDown& keyDown = mKeyDowns.editTop();
+            keyDown.keyCode = keyCode;
+            keyDown.scanCode = scanCode;
+        }
+
+        mDownTime = when;
+    } else {
+        // Remove key down.
+        ssize_t keyDownIndex = findKeyDown(scanCode);
+        if (keyDownIndex >= 0) {
+            // key up, be sure to use same keycode as before in case of rotation
+            keyCode = mKeyDowns.itemAt(keyDownIndex).keyCode;
+            mKeyDowns.removeAt(size_t(keyDownIndex));
+        } else {
+            // key was not actually down
+            ALOGI("Dropping key up from device %s because the key was not down.  "
+                    "keyCode=%d, scanCode=%d",
+                    getDeviceName().string(), keyCode, scanCode);
+            return;
+        }
+    }
+
+    int32_t oldMetaState = mMetaState;
+    int32_t newMetaState = updateMetaState(keyCode, down, oldMetaState);
+    bool metaStateChanged = oldMetaState != newMetaState;
+    if (metaStateChanged) {
+        mMetaState = newMetaState;
+        updateLedState(false);
+    }
+
+    nsecs_t downTime = mDownTime;
+
+    // Key down on external an keyboard should wake the device.
+    // We don't do this for internal keyboards to prevent them from waking up in your pocket.
+    // For internal keyboards, the key layout file should specify the policy flags for
+    // each wake key individually.
+    // TODO: Use the input device configuration to control this behavior more finely.
+    if (down && getDevice()->isExternal()
+            && !(policyFlags & (POLICY_FLAG_WAKE | POLICY_FLAG_WAKE_DROPPED))) {
+        policyFlags |= POLICY_FLAG_WAKE_DROPPED;
+    }
+
+    if (metaStateChanged) {
+        getContext()->updateGlobalMetaState();
+    }
+
+    if (down && !isMetaKey(keyCode)) {
+        getContext()->fadePointer();
+    }
+
+    NotifyKeyArgs args(when, getDeviceId(), mSource, policyFlags,
+            down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
+            AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime);
+    getListener()->notifyKey(&args);
+}
+
+ssize_t KeyboardInputMapper::findKeyDown(int32_t scanCode) {
+    size_t n = mKeyDowns.size();
+    for (size_t i = 0; i < n; i++) {
+        if (mKeyDowns[i].scanCode == scanCode) {
+            return i;
+        }
+    }
+    return -1;
+}
+
+int32_t KeyboardInputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
+    return getEventHub()->getKeyCodeState(getDeviceId(), keyCode);
+}
+
+int32_t KeyboardInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+    return getEventHub()->getScanCodeState(getDeviceId(), scanCode);
+}
+
+bool KeyboardInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+        const int32_t* keyCodes, uint8_t* outFlags) {
+    return getEventHub()->markSupportedKeyCodes(getDeviceId(), numCodes, keyCodes, outFlags);
+}
+
+int32_t KeyboardInputMapper::getMetaState() {
+    return mMetaState;
+}
+
+void KeyboardInputMapper::resetLedState() {
+    initializeLedState(mCapsLockLedState, ALED_CAPS_LOCK);
+    initializeLedState(mNumLockLedState, ALED_NUM_LOCK);
+    initializeLedState(mScrollLockLedState, ALED_SCROLL_LOCK);
+
+    updateLedState(true);
+}
+
+void KeyboardInputMapper::initializeLedState(LedState& ledState, int32_t led) {
+    ledState.avail = getEventHub()->hasLed(getDeviceId(), led);
+    ledState.on = false;
+}
+
+void KeyboardInputMapper::updateLedState(bool reset) {
+    updateLedStateForModifier(mCapsLockLedState, ALED_CAPS_LOCK,
+            AMETA_CAPS_LOCK_ON, reset);
+    updateLedStateForModifier(mNumLockLedState, ALED_NUM_LOCK,
+            AMETA_NUM_LOCK_ON, reset);
+    updateLedStateForModifier(mScrollLockLedState, ALED_SCROLL_LOCK,
+            AMETA_SCROLL_LOCK_ON, reset);
+}
+
+void KeyboardInputMapper::updateLedStateForModifier(LedState& ledState,
+        int32_t led, int32_t modifier, bool reset) {
+    if (ledState.avail) {
+        bool desiredState = (mMetaState & modifier) != 0;
+        if (reset || ledState.on != desiredState) {
+            getEventHub()->setLedState(getDeviceId(), led, desiredState);
+            ledState.on = desiredState;
+        }
+    }
+}
+
+
+// --- CursorInputMapper ---
+
+CursorInputMapper::CursorInputMapper(InputDevice* device) :
+        InputMapper(device) {
+}
+
+CursorInputMapper::~CursorInputMapper() {
+}
+
+uint32_t CursorInputMapper::getSources() {
+    return mSource;
+}
+
+void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+    InputMapper::populateDeviceInfo(info);
+
+    if (mParameters.mode == Parameters::MODE_POINTER) {
+        float minX, minY, maxX, maxY;
+        if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
+            info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, minX, maxX, 0.0f, 0.0f, 0.0f);
+            info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, minY, maxY, 0.0f, 0.0f, 0.0f);
+        }
+    } else {
+        info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, -1.0f, 1.0f, 0.0f, mXScale, 0.0f);
+        info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, -1.0f, 1.0f, 0.0f, mYScale, 0.0f);
+    }
+    info->addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, mSource, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
+
+    if (mCursorScrollAccumulator.haveRelativeVWheel()) {
+        info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
+    }
+    if (mCursorScrollAccumulator.haveRelativeHWheel()) {
+        info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
+    }
+}
+
+void CursorInputMapper::dump(String8& dump) {
+    dump.append(INDENT2 "Cursor Input Mapper:\n");
+    dumpParameters(dump);
+    dump.appendFormat(INDENT3 "XScale: %0.3f\n", mXScale);
+    dump.appendFormat(INDENT3 "YScale: %0.3f\n", mYScale);
+    dump.appendFormat(INDENT3 "XPrecision: %0.3f\n", mXPrecision);
+    dump.appendFormat(INDENT3 "YPrecision: %0.3f\n", mYPrecision);
+    dump.appendFormat(INDENT3 "HaveVWheel: %s\n",
+            toString(mCursorScrollAccumulator.haveRelativeVWheel()));
+    dump.appendFormat(INDENT3 "HaveHWheel: %s\n",
+            toString(mCursorScrollAccumulator.haveRelativeHWheel()));
+    dump.appendFormat(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale);
+    dump.appendFormat(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale);
+    dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation);
+    dump.appendFormat(INDENT3 "ButtonState: 0x%08x\n", mButtonState);
+    dump.appendFormat(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState)));
+    dump.appendFormat(INDENT3 "DownTime: %lld\n", mDownTime);
+}
+
+void CursorInputMapper::configure(nsecs_t when,
+        const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(when, config, changes);
+
+    if (!changes) { // first time only
+        mCursorScrollAccumulator.configure(getDevice());
+
+        // Configure basic parameters.
+        configureParameters();
+
+        // Configure device mode.
+        switch (mParameters.mode) {
+        case Parameters::MODE_POINTER:
+            mSource = AINPUT_SOURCE_MOUSE;
+            mXPrecision = 1.0f;
+            mYPrecision = 1.0f;
+            mXScale = 1.0f;
+            mYScale = 1.0f;
+            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
+            break;
+        case Parameters::MODE_NAVIGATION:
+            mSource = AINPUT_SOURCE_TRACKBALL;
+            mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
+            mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
+            mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
+            mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
+            break;
+        }
+
+        mVWheelScale = 1.0f;
+        mHWheelScale = 1.0f;
+    }
+
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
+        mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters);
+        mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters);
+        mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters);
+    }
+
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
+        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
+            DisplayViewport v;
+            if (config->getDisplayInfo(false /*external*/, &v)) {
+                mOrientation = v.orientation;
+            } else {
+                mOrientation = DISPLAY_ORIENTATION_0;
+            }
+        } else {
+            mOrientation = DISPLAY_ORIENTATION_0;
+        }
+        bumpGeneration();
+    }
+}
+
+void CursorInputMapper::configureParameters() {
+    mParameters.mode = Parameters::MODE_POINTER;
+    String8 cursorModeString;
+    if (getDevice()->getConfiguration().tryGetProperty(String8("cursor.mode"), cursorModeString)) {
+        if (cursorModeString == "navigation") {
+            mParameters.mode = Parameters::MODE_NAVIGATION;
+        } else if (cursorModeString != "pointer" && cursorModeString != "default") {
+            ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string());
+        }
+    }
+
+    mParameters.orientationAware = false;
+    getDevice()->getConfiguration().tryGetProperty(String8("cursor.orientationAware"),
+            mParameters.orientationAware);
+
+    mParameters.hasAssociatedDisplay = false;
+    if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
+        mParameters.hasAssociatedDisplay = true;
+    }
+}
+
+void CursorInputMapper::dumpParameters(String8& dump) {
+    dump.append(INDENT3 "Parameters:\n");
+    dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
+            toString(mParameters.hasAssociatedDisplay));
+
+    switch (mParameters.mode) {
+    case Parameters::MODE_POINTER:
+        dump.append(INDENT4 "Mode: pointer\n");
+        break;
+    case Parameters::MODE_NAVIGATION:
+        dump.append(INDENT4 "Mode: navigation\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+
+    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
+            toString(mParameters.orientationAware));
+}
+
+void CursorInputMapper::reset(nsecs_t when) {
+    mButtonState = 0;
+    mDownTime = 0;
+
+    mPointerVelocityControl.reset();
+    mWheelXVelocityControl.reset();
+    mWheelYVelocityControl.reset();
+
+    mCursorButtonAccumulator.reset(getDevice());
+    mCursorMotionAccumulator.reset(getDevice());
+    mCursorScrollAccumulator.reset(getDevice());
+
+    InputMapper::reset(when);
+}
+
+void CursorInputMapper::process(const RawEvent* rawEvent) {
+    mCursorButtonAccumulator.process(rawEvent);
+    mCursorMotionAccumulator.process(rawEvent);
+    mCursorScrollAccumulator.process(rawEvent);
+
+    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
+        sync(rawEvent->when);
+    }
+}
+
+void CursorInputMapper::sync(nsecs_t when) {
+    int32_t lastButtonState = mButtonState;
+    int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
+    mButtonState = currentButtonState;
+
+    bool wasDown = isPointerDown(lastButtonState);
+    bool down = isPointerDown(currentButtonState);
+    bool downChanged;
+    if (!wasDown && down) {
+        mDownTime = when;
+        downChanged = true;
+    } else if (wasDown && !down) {
+        downChanged = true;
+    } else {
+        downChanged = false;
+    }
+    nsecs_t downTime = mDownTime;
+    bool buttonsChanged = currentButtonState != lastButtonState;
+    bool buttonsPressed = currentButtonState & ~lastButtonState;
+
+    float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
+    float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
+    bool moved = deltaX != 0 || deltaY != 0;
+
+    // Rotate delta according to orientation if needed.
+    if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
+            && (deltaX != 0.0f || deltaY != 0.0f)) {
+        rotateDelta(mOrientation, &deltaX, &deltaY);
+    }
+
+    // Move the pointer.
+    PointerProperties pointerProperties;
+    pointerProperties.clear();
+    pointerProperties.id = 0;
+    pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE;
+
+    PointerCoords pointerCoords;
+    pointerCoords.clear();
+
+    float vscroll = mCursorScrollAccumulator.getRelativeVWheel();
+    float hscroll = mCursorScrollAccumulator.getRelativeHWheel();
+    bool scrolled = vscroll != 0 || hscroll != 0;
+
+    mWheelYVelocityControl.move(when, NULL, &vscroll);
+    mWheelXVelocityControl.move(when, &hscroll, NULL);
+
+    mPointerVelocityControl.move(when, &deltaX, &deltaY);
+
+    int32_t displayId;
+    if (mPointerController != NULL) {
+        if (moved || scrolled || buttonsChanged) {
+            mPointerController->setPresentation(
+                    PointerControllerInterface::PRESENTATION_POINTER);
+
+            if (moved) {
+                mPointerController->move(deltaX, deltaY);
+            }
+
+            if (buttonsChanged) {
+                mPointerController->setButtonState(currentButtonState);
+            }
+
+            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
+        }
+
+        float x, y;
+        mPointerController->getPosition(&x, &y);
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+        displayId = ADISPLAY_ID_DEFAULT;
+    } else {
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
+        displayId = ADISPLAY_ID_NONE;
+    }
+
+    pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f);
+
+    // Moving an external trackball or mouse should wake the device.
+    // We don't do this for internal cursor devices to prevent them from waking up
+    // the device in your pocket.
+    // TODO: Use the input device configuration to control this behavior more finely.
+    uint32_t policyFlags = 0;
+    if ((buttonsPressed || moved || scrolled) && getDevice()->isExternal()) {
+        policyFlags |= POLICY_FLAG_WAKE_DROPPED;
+    }
+
+    // Synthesize key down from buttons if needed.
+    synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
+            policyFlags, lastButtonState, currentButtonState);
+
+    // Send motion event.
+    if (downChanged || moved || scrolled || buttonsChanged) {
+        int32_t metaState = mContext->getGlobalMetaState();
+        int32_t motionEventAction;
+        if (downChanged) {
+            motionEventAction = down ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
+        } else if (down || mPointerController == NULL) {
+            motionEventAction = AMOTION_EVENT_ACTION_MOVE;
+        } else {
+            motionEventAction = AMOTION_EVENT_ACTION_HOVER_MOVE;
+        }
+
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                motionEventAction, 0, metaState, currentButtonState, 0,
+                displayId, 1, &pointerProperties, &pointerCoords,
+                mXPrecision, mYPrecision, downTime);
+        getListener()->notifyMotion(&args);
+
+        // Send hover move after UP to tell the application that the mouse is hovering now.
+        if (motionEventAction == AMOTION_EVENT_ACTION_UP
+                && mPointerController != NULL) {
+            NotifyMotionArgs hoverArgs(when, getDeviceId(), mSource, policyFlags,
+                    AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
+                    metaState, currentButtonState, AMOTION_EVENT_EDGE_FLAG_NONE,
+                    displayId, 1, &pointerProperties, &pointerCoords,
+                    mXPrecision, mYPrecision, downTime);
+            getListener()->notifyMotion(&hoverArgs);
+        }
+
+        // Send scroll events.
+        if (scrolled) {
+            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
+            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);
+
+            NotifyMotionArgs scrollArgs(when, getDeviceId(), mSource, policyFlags,
+                    AMOTION_EVENT_ACTION_SCROLL, 0, metaState, currentButtonState,
+                    AMOTION_EVENT_EDGE_FLAG_NONE,
+                    displayId, 1, &pointerProperties, &pointerCoords,
+                    mXPrecision, mYPrecision, downTime);
+            getListener()->notifyMotion(&scrollArgs);
+        }
+    }
+
+    // Synthesize key up from buttons if needed.
+    synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource,
+            policyFlags, lastButtonState, currentButtonState);
+
+    mCursorMotionAccumulator.finishSync();
+    mCursorScrollAccumulator.finishSync();
+}
+
+int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+    if (scanCode >= BTN_MOUSE && scanCode < BTN_JOYSTICK) {
+        return getEventHub()->getScanCodeState(getDeviceId(), scanCode);
+    } else {
+        return AKEY_STATE_UNKNOWN;
+    }
+}
+
+void CursorInputMapper::fadePointer() {
+    if (mPointerController != NULL) {
+        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+    }
+}
+
+
+// --- TouchInputMapper ---
+
+TouchInputMapper::TouchInputMapper(InputDevice* device) :
+        InputMapper(device),
+        mSource(0), mDeviceMode(DEVICE_MODE_DISABLED),
+        mSurfaceWidth(-1), mSurfaceHeight(-1), mSurfaceLeft(0), mSurfaceTop(0),
+        mSurfaceOrientation(DISPLAY_ORIENTATION_0) {
+}
+
+TouchInputMapper::~TouchInputMapper() {
+}
+
+uint32_t TouchInputMapper::getSources() {
+    return mSource;
+}
+
+void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+    InputMapper::populateDeviceInfo(info);
+
+    if (mDeviceMode != DEVICE_MODE_DISABLED) {
+        info->addMotionRange(mOrientedRanges.x);
+        info->addMotionRange(mOrientedRanges.y);
+        info->addMotionRange(mOrientedRanges.pressure);
+
+        if (mOrientedRanges.haveSize) {
+            info->addMotionRange(mOrientedRanges.size);
+        }
+
+        if (mOrientedRanges.haveTouchSize) {
+            info->addMotionRange(mOrientedRanges.touchMajor);
+            info->addMotionRange(mOrientedRanges.touchMinor);
+        }
+
+        if (mOrientedRanges.haveToolSize) {
+            info->addMotionRange(mOrientedRanges.toolMajor);
+            info->addMotionRange(mOrientedRanges.toolMinor);
+        }
+
+        if (mOrientedRanges.haveOrientation) {
+            info->addMotionRange(mOrientedRanges.orientation);
+        }
+
+        if (mOrientedRanges.haveDistance) {
+            info->addMotionRange(mOrientedRanges.distance);
+        }
+
+        if (mOrientedRanges.haveTilt) {
+            info->addMotionRange(mOrientedRanges.tilt);
+        }
+
+        if (mCursorScrollAccumulator.haveRelativeVWheel()) {
+            info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f,
+                    0.0f);
+        }
+        if (mCursorScrollAccumulator.haveRelativeHWheel()) {
+            info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f,
+                    0.0f);
+        }
+        if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_BOX) {
+            const InputDeviceInfo::MotionRange& x = mOrientedRanges.x;
+            const InputDeviceInfo::MotionRange& y = mOrientedRanges.y;
+            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_1, mSource, x.min, x.max, x.flat,
+                    x.fuzz, x.resolution);
+            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_2, mSource, y.min, y.max, y.flat,
+                    y.fuzz, y.resolution);
+            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_3, mSource, x.min, x.max, x.flat,
+                    x.fuzz, x.resolution);
+            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_4, mSource, y.min, y.max, y.flat,
+                    y.fuzz, y.resolution);
+        }
+        info->setButtonUnderPad(mParameters.hasButtonUnderPad);
+    }
+}
+
+void TouchInputMapper::dump(String8& dump) {
+    dump.append(INDENT2 "Touch Input Mapper:\n");
+    dumpParameters(dump);
+    dumpVirtualKeys(dump);
+    dumpRawPointerAxes(dump);
+    dumpCalibration(dump);
+    dumpSurface(dump);
+
+    dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n");
+    dump.appendFormat(INDENT4 "XTranslate: %0.3f\n", mXTranslate);
+    dump.appendFormat(INDENT4 "YTranslate: %0.3f\n", mYTranslate);
+    dump.appendFormat(INDENT4 "XScale: %0.3f\n", mXScale);
+    dump.appendFormat(INDENT4 "YScale: %0.3f\n", mYScale);
+    dump.appendFormat(INDENT4 "XPrecision: %0.3f\n", mXPrecision);
+    dump.appendFormat(INDENT4 "YPrecision: %0.3f\n", mYPrecision);
+    dump.appendFormat(INDENT4 "GeometricScale: %0.3f\n", mGeometricScale);
+    dump.appendFormat(INDENT4 "PressureScale: %0.3f\n", mPressureScale);
+    dump.appendFormat(INDENT4 "SizeScale: %0.3f\n", mSizeScale);
+    dump.appendFormat(INDENT4 "OrientationScale: %0.3f\n", mOrientationScale);
+    dump.appendFormat(INDENT4 "DistanceScale: %0.3f\n", mDistanceScale);
+    dump.appendFormat(INDENT4 "HaveTilt: %s\n", toString(mHaveTilt));
+    dump.appendFormat(INDENT4 "TiltXCenter: %0.3f\n", mTiltXCenter);
+    dump.appendFormat(INDENT4 "TiltXScale: %0.3f\n", mTiltXScale);
+    dump.appendFormat(INDENT4 "TiltYCenter: %0.3f\n", mTiltYCenter);
+    dump.appendFormat(INDENT4 "TiltYScale: %0.3f\n", mTiltYScale);
+
+    dump.appendFormat(INDENT3 "Last Button State: 0x%08x\n", mLastButtonState);
+
+    dump.appendFormat(INDENT3 "Last Raw Touch: pointerCount=%d\n",
+            mLastRawPointerData.pointerCount);
+    for (uint32_t i = 0; i < mLastRawPointerData.pointerCount; i++) {
+        const RawPointerData::Pointer& pointer = mLastRawPointerData.pointers[i];
+        dump.appendFormat(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, "
+                "touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, "
+                "orientation=%d, tiltX=%d, tiltY=%d, distance=%d, "
+                "toolType=%d, isHovering=%s\n", i,
+                pointer.id, pointer.x, pointer.y, pointer.pressure,
+                pointer.touchMajor, pointer.touchMinor,
+                pointer.toolMajor, pointer.toolMinor,
+                pointer.orientation, pointer.tiltX, pointer.tiltY, pointer.distance,
+                pointer.toolType, toString(pointer.isHovering));
+    }
+
+    dump.appendFormat(INDENT3 "Last Cooked Touch: pointerCount=%d\n",
+            mLastCookedPointerData.pointerCount);
+    for (uint32_t i = 0; i < mLastCookedPointerData.pointerCount; i++) {
+        const PointerProperties& pointerProperties = mLastCookedPointerData.pointerProperties[i];
+        const PointerCoords& pointerCoords = mLastCookedPointerData.pointerCoords[i];
+        dump.appendFormat(INDENT4 "[%d]: id=%d, x=%0.3f, y=%0.3f, pressure=%0.3f, "
+                "touchMajor=%0.3f, touchMinor=%0.3f, toolMajor=%0.3f, toolMinor=%0.3f, "
+                "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, "
+                "toolType=%d, isHovering=%s\n", i,
+                pointerProperties.id,
+                pointerCoords.getX(),
+                pointerCoords.getY(),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TILT),
+                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE),
+                pointerProperties.toolType,
+                toString(mLastCookedPointerData.isHovering(i)));
+    }
+
+    if (mDeviceMode == DEVICE_MODE_POINTER) {
+        dump.appendFormat(INDENT3 "Pointer Gesture Detector:\n");
+        dump.appendFormat(INDENT4 "XMovementScale: %0.3f\n",
+                mPointerXMovementScale);
+        dump.appendFormat(INDENT4 "YMovementScale: %0.3f\n",
+                mPointerYMovementScale);
+        dump.appendFormat(INDENT4 "XZoomScale: %0.3f\n",
+                mPointerXZoomScale);
+        dump.appendFormat(INDENT4 "YZoomScale: %0.3f\n",
+                mPointerYZoomScale);
+        dump.appendFormat(INDENT4 "MaxSwipeWidth: %f\n",
+                mPointerGestureMaxSwipeWidth);
+    }
+}
+
+void TouchInputMapper::configure(nsecs_t when,
+        const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(when, config, changes);
+
+    mConfig = *config;
+
+    if (!changes) { // first time only
+        // Configure basic parameters.
+        configureParameters();
+
+        // Configure common accumulators.
+        mCursorScrollAccumulator.configure(getDevice());
+        mTouchButtonAccumulator.configure(getDevice());
+
+        // Configure absolute axis information.
+        configureRawPointerAxes();
+
+        // Prepare input device calibration.
+        parseCalibration();
+        resolveCalibration();
+    }
+
+    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
+        // Update pointer speed.
+        mPointerVelocityControl.setParameters(mConfig.pointerVelocityControlParameters);
+        mWheelXVelocityControl.setParameters(mConfig.wheelVelocityControlParameters);
+        mWheelYVelocityControl.setParameters(mConfig.wheelVelocityControlParameters);
+    }
+
+    bool resetNeeded = false;
+    if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO
+            | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT
+            | InputReaderConfiguration::CHANGE_SHOW_TOUCHES))) {
+        // Configure device sources, surface dimensions, orientation and
+        // scaling factors.
+        configureSurface(when, &resetNeeded);
+    }
+
+    if (changes && resetNeeded) {
+        // Send reset, unless this is the first time the device has been configured,
+        // in which case the reader will call reset itself after all mappers are ready.
+        getDevice()->notifyReset(when);
+    }
+}
+
+void TouchInputMapper::configureParameters() {
+    // Use the pointer presentation mode for devices that do not support distinct
+    // multitouch.  The spot-based presentation relies on being able to accurately
+    // locate two or more fingers on the touch pad.
+    mParameters.gestureMode = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_SEMI_MT)
+            ? Parameters::GESTURE_MODE_POINTER : Parameters::GESTURE_MODE_SPOTS;
+
+    String8 gestureModeString;
+    if (getDevice()->getConfiguration().tryGetProperty(String8("touch.gestureMode"),
+            gestureModeString)) {
+        if (gestureModeString == "pointer") {
+            mParameters.gestureMode = Parameters::GESTURE_MODE_POINTER;
+        } else if (gestureModeString == "spots") {
+            mParameters.gestureMode = Parameters::GESTURE_MODE_SPOTS;
+        } else if (gestureModeString != "default") {
+            ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.string());
+        }
+    }
+
+    if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_DIRECT)) {
+        // The device is a touch screen.
+        mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;
+    } else if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_POINTER)) {
+        // The device is a pointing device like a track pad.
+        mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
+    } else if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X)
+            || getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) {
+        // The device is a cursor device with a touch pad attached.
+        // By default don't use the touch pad to move the pointer.
+        mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;
+    } else {
+        // The device is a touch pad of unknown purpose.
+        mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
+    }
+
+    mParameters.hasButtonUnderPad=
+            getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_BUTTONPAD);
+
+    String8 deviceTypeString;
+    if (getDevice()->getConfiguration().tryGetProperty(String8("touch.deviceType"),
+            deviceTypeString)) {
+        if (deviceTypeString == "touchScreen") {
+            mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;
+        } else if (deviceTypeString == "touchPad") {
+            mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;
+        } else if (deviceTypeString == "touchNavigation") {
+            mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_NAVIGATION;
+        } else if (deviceTypeString == "pointer") {
+            mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
+        } else if (deviceTypeString != "default") {
+            ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string());
+        }
+    }
+
+    mParameters.orientationAware = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN;
+    getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"),
+            mParameters.orientationAware);
+
+    mParameters.hasAssociatedDisplay = false;
+    mParameters.associatedDisplayIsExternal = false;
+    if (mParameters.orientationAware
+            || mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
+            || mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {
+        mParameters.hasAssociatedDisplay = true;
+        mParameters.associatedDisplayIsExternal =
+                mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
+                        && getDevice()->isExternal();
+    }
+
+    // Initial downs on external touch devices should wake the device.
+    // Normally we don't do this for internal touch screens to prevent them from waking
+    // up in your pocket but you can enable it using the input device configuration.
+    mParameters.wake = getDevice()->isExternal();
+    getDevice()->getConfiguration().tryGetProperty(String8("touch.wake"),
+            mParameters.wake);
+}
+
+void TouchInputMapper::dumpParameters(String8& dump) {
+    dump.append(INDENT3 "Parameters:\n");
+
+    switch (mParameters.gestureMode) {
+    case Parameters::GESTURE_MODE_POINTER:
+        dump.append(INDENT4 "GestureMode: pointer\n");
+        break;
+    case Parameters::GESTURE_MODE_SPOTS:
+        dump.append(INDENT4 "GestureMode: spots\n");
+        break;
+    default:
+        assert(false);
+    }
+
+    switch (mParameters.deviceType) {
+    case Parameters::DEVICE_TYPE_TOUCH_SCREEN:
+        dump.append(INDENT4 "DeviceType: touchScreen\n");
+        break;
+    case Parameters::DEVICE_TYPE_TOUCH_PAD:
+        dump.append(INDENT4 "DeviceType: touchPad\n");
+        break;
+    case Parameters::DEVICE_TYPE_TOUCH_NAVIGATION:
+        dump.append(INDENT4 "DeviceType: touchNavigation\n");
+        break;
+    case Parameters::DEVICE_TYPE_POINTER:
+        dump.append(INDENT4 "DeviceType: pointer\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+
+    dump.appendFormat(INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s\n",
+            toString(mParameters.hasAssociatedDisplay),
+            toString(mParameters.associatedDisplayIsExternal));
+    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
+            toString(mParameters.orientationAware));
+}
+
+void TouchInputMapper::configureRawPointerAxes() {
+    mRawPointerAxes.clear();
+}
+
+void TouchInputMapper::dumpRawPointerAxes(String8& dump) {
+    dump.append(INDENT3 "Raw Touch Axes:\n");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.x, "X");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.y, "Y");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.pressure, "Pressure");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.touchMajor, "TouchMajor");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.touchMinor, "TouchMinor");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.toolMajor, "ToolMajor");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.toolMinor, "ToolMinor");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.orientation, "Orientation");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.distance, "Distance");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.tiltX, "TiltX");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.tiltY, "TiltY");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.trackingId, "TrackingId");
+    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.slot, "Slot");
+}
+
+void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
+    int32_t oldDeviceMode = mDeviceMode;
+
+    // Determine device mode.
+    if (mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER
+            && mConfig.pointerGesturesEnabled) {
+        mSource = AINPUT_SOURCE_MOUSE;
+        mDeviceMode = DEVICE_MODE_POINTER;
+        if (hasStylus()) {
+            mSource |= AINPUT_SOURCE_STYLUS;
+        }
+    } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
+            && mParameters.hasAssociatedDisplay) {
+        mSource = AINPUT_SOURCE_TOUCHSCREEN;
+        mDeviceMode = DEVICE_MODE_DIRECT;
+        if (hasStylus()) {
+            mSource |= AINPUT_SOURCE_STYLUS;
+        }
+    } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_NAVIGATION) {
+        mSource = AINPUT_SOURCE_TOUCH_NAVIGATION;
+        mDeviceMode = DEVICE_MODE_NAVIGATION;
+    } else {
+        mSource = AINPUT_SOURCE_TOUCHPAD;
+        mDeviceMode = DEVICE_MODE_UNSCALED;
+    }
+
+    // Ensure we have valid X and Y axes.
+    if (!mRawPointerAxes.x.valid || !mRawPointerAxes.y.valid) {
+        ALOGW(INDENT "Touch device '%s' did not report support for X or Y axis!  "
+                "The device will be inoperable.", getDeviceName().string());
+        mDeviceMode = DEVICE_MODE_DISABLED;
+        return;
+    }
+
+    // Raw width and height in the natural orientation.
+    int32_t rawWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
+    int32_t rawHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
+
+    // Get associated display dimensions.
+    DisplayViewport newViewport;
+    if (mParameters.hasAssociatedDisplay) {
+        if (!mConfig.getDisplayInfo(mParameters.associatedDisplayIsExternal, &newViewport)) {
+            ALOGI(INDENT "Touch device '%s' could not query the properties of its associated "
+                    "display.  The device will be inoperable until the display size "
+                    "becomes available.",
+                    getDeviceName().string());
+            mDeviceMode = DEVICE_MODE_DISABLED;
+            return;
+        }
+    } else {
+        newViewport.setNonDisplayViewport(rawWidth, rawHeight);
+    }
+    bool viewportChanged = mViewport != newViewport;
+    if (viewportChanged) {
+        mViewport = newViewport;
+
+        if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
+            // Convert rotated viewport to natural surface coordinates.
+            int32_t naturalLogicalWidth, naturalLogicalHeight;
+            int32_t naturalPhysicalWidth, naturalPhysicalHeight;
+            int32_t naturalPhysicalLeft, naturalPhysicalTop;
+            int32_t naturalDeviceWidth, naturalDeviceHeight;
+            switch (mViewport.orientation) {
+            case DISPLAY_ORIENTATION_90:
+                naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
+                naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
+                naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
+                naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
+                naturalPhysicalLeft = mViewport.deviceHeight - mViewport.physicalBottom;
+                naturalPhysicalTop = mViewport.physicalLeft;
+                naturalDeviceWidth = mViewport.deviceHeight;
+                naturalDeviceHeight = mViewport.deviceWidth;
+                break;
+            case DISPLAY_ORIENTATION_180:
+                naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
+                naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
+                naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
+                naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
+                naturalPhysicalLeft = mViewport.deviceWidth - mViewport.physicalRight;
+                naturalPhysicalTop = mViewport.deviceHeight - mViewport.physicalBottom;
+                naturalDeviceWidth = mViewport.deviceWidth;
+                naturalDeviceHeight = mViewport.deviceHeight;
+                break;
+            case DISPLAY_ORIENTATION_270:
+                naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
+                naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
+                naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
+                naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
+                naturalPhysicalLeft = mViewport.physicalTop;
+                naturalPhysicalTop = mViewport.deviceWidth - mViewport.physicalRight;
+                naturalDeviceWidth = mViewport.deviceHeight;
+                naturalDeviceHeight = mViewport.deviceWidth;
+                break;
+            case DISPLAY_ORIENTATION_0:
+            default:
+                naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
+                naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
+                naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
+                naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
+                naturalPhysicalLeft = mViewport.physicalLeft;
+                naturalPhysicalTop = mViewport.physicalTop;
+                naturalDeviceWidth = mViewport.deviceWidth;
+                naturalDeviceHeight = mViewport.deviceHeight;
+                break;
+            }
+
+            mSurfaceWidth = naturalLogicalWidth * naturalDeviceWidth / naturalPhysicalWidth;
+            mSurfaceHeight = naturalLogicalHeight * naturalDeviceHeight / naturalPhysicalHeight;
+            mSurfaceLeft = naturalPhysicalLeft * naturalLogicalWidth / naturalPhysicalWidth;
+            mSurfaceTop = naturalPhysicalTop * naturalLogicalHeight / naturalPhysicalHeight;
+
+            mSurfaceOrientation = mParameters.orientationAware ?
+                    mViewport.orientation : DISPLAY_ORIENTATION_0;
+        } else {
+            mSurfaceWidth = rawWidth;
+            mSurfaceHeight = rawHeight;
+            mSurfaceLeft = 0;
+            mSurfaceTop = 0;
+            mSurfaceOrientation = DISPLAY_ORIENTATION_0;
+        }
+    }
+
+    // If moving between pointer modes, need to reset some state.
+    bool deviceModeChanged = mDeviceMode != oldDeviceMode;
+    if (deviceModeChanged) {
+        mOrientedRanges.clear();
+    }
+
+    // Create pointer controller if needed.
+    if (mDeviceMode == DEVICE_MODE_POINTER ||
+            (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
+        if (mPointerController == NULL) {
+            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
+        }
+    } else {
+        mPointerController.clear();
+    }
+
+    if (viewportChanged || deviceModeChanged) {
+        ALOGI("Device reconfigured: id=%d, name='%s', size %dx%d, orientation %d, mode %d, "
+                "display id %d",
+                getDeviceId(), getDeviceName().string(), mSurfaceWidth, mSurfaceHeight,
+                mSurfaceOrientation, mDeviceMode, mViewport.displayId);
+
+        // Configure X and Y factors.
+        mXScale = float(mSurfaceWidth) / rawWidth;
+        mYScale = float(mSurfaceHeight) / rawHeight;
+        mXTranslate = -mSurfaceLeft;
+        mYTranslate = -mSurfaceTop;
+        mXPrecision = 1.0f / mXScale;
+        mYPrecision = 1.0f / mYScale;
+
+        mOrientedRanges.x.axis = AMOTION_EVENT_AXIS_X;
+        mOrientedRanges.x.source = mSource;
+        mOrientedRanges.y.axis = AMOTION_EVENT_AXIS_Y;
+        mOrientedRanges.y.source = mSource;
+
+        configureVirtualKeys();
+
+        // Scale factor for terms that are not oriented in a particular axis.
+        // If the pixels are square then xScale == yScale otherwise we fake it
+        // by choosing an average.
+        mGeometricScale = avg(mXScale, mYScale);
+
+        // Size of diagonal axis.
+        float diagonalSize = hypotf(mSurfaceWidth, mSurfaceHeight);
+
+        // Size factors.
+        if (mCalibration.sizeCalibration != Calibration::SIZE_CALIBRATION_NONE) {
+            if (mRawPointerAxes.touchMajor.valid
+                    && mRawPointerAxes.touchMajor.maxValue != 0) {
+                mSizeScale = 1.0f / mRawPointerAxes.touchMajor.maxValue;
+            } else if (mRawPointerAxes.toolMajor.valid
+                    && mRawPointerAxes.toolMajor.maxValue != 0) {
+                mSizeScale = 1.0f / mRawPointerAxes.toolMajor.maxValue;
+            } else {
+                mSizeScale = 0.0f;
+            }
+
+            mOrientedRanges.haveTouchSize = true;
+            mOrientedRanges.haveToolSize = true;
+            mOrientedRanges.haveSize = true;
+
+            mOrientedRanges.touchMajor.axis = AMOTION_EVENT_AXIS_TOUCH_MAJOR;
+            mOrientedRanges.touchMajor.source = mSource;
+            mOrientedRanges.touchMajor.min = 0;
+            mOrientedRanges.touchMajor.max = diagonalSize;
+            mOrientedRanges.touchMajor.flat = 0;
+            mOrientedRanges.touchMajor.fuzz = 0;
+            mOrientedRanges.touchMajor.resolution = 0;
+
+            mOrientedRanges.touchMinor = mOrientedRanges.touchMajor;
+            mOrientedRanges.touchMinor.axis = AMOTION_EVENT_AXIS_TOUCH_MINOR;
+
+            mOrientedRanges.toolMajor.axis = AMOTION_EVENT_AXIS_TOOL_MAJOR;
+            mOrientedRanges.toolMajor.source = mSource;
+            mOrientedRanges.toolMajor.min = 0;
+            mOrientedRanges.toolMajor.max = diagonalSize;
+            mOrientedRanges.toolMajor.flat = 0;
+            mOrientedRanges.toolMajor.fuzz = 0;
+            mOrientedRanges.toolMajor.resolution = 0;
+
+            mOrientedRanges.toolMinor = mOrientedRanges.toolMajor;
+            mOrientedRanges.toolMinor.axis = AMOTION_EVENT_AXIS_TOOL_MINOR;
+
+            mOrientedRanges.size.axis = AMOTION_EVENT_AXIS_SIZE;
+            mOrientedRanges.size.source = mSource;
+            mOrientedRanges.size.min = 0;
+            mOrientedRanges.size.max = 1.0;
+            mOrientedRanges.size.flat = 0;
+            mOrientedRanges.size.fuzz = 0;
+            mOrientedRanges.size.resolution = 0;
+        } else {
+            mSizeScale = 0.0f;
+        }
+
+        // Pressure factors.
+        mPressureScale = 0;
+        if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL
+                || mCalibration.pressureCalibration
+                        == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) {
+            if (mCalibration.havePressureScale) {
+                mPressureScale = mCalibration.pressureScale;
+            } else if (mRawPointerAxes.pressure.valid
+                    && mRawPointerAxes.pressure.maxValue != 0) {
+                mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue;
+            }
+        }
+
+        mOrientedRanges.pressure.axis = AMOTION_EVENT_AXIS_PRESSURE;
+        mOrientedRanges.pressure.source = mSource;
+        mOrientedRanges.pressure.min = 0;
+        mOrientedRanges.pressure.max = 1.0;
+        mOrientedRanges.pressure.flat = 0;
+        mOrientedRanges.pressure.fuzz = 0;
+        mOrientedRanges.pressure.resolution = 0;
+
+        // Tilt
+        mTiltXCenter = 0;
+        mTiltXScale = 0;
+        mTiltYCenter = 0;
+        mTiltYScale = 0;
+        mHaveTilt = mRawPointerAxes.tiltX.valid && mRawPointerAxes.tiltY.valid;
+        if (mHaveTilt) {
+            mTiltXCenter = avg(mRawPointerAxes.tiltX.minValue,
+                    mRawPointerAxes.tiltX.maxValue);
+            mTiltYCenter = avg(mRawPointerAxes.tiltY.minValue,
+                    mRawPointerAxes.tiltY.maxValue);
+            mTiltXScale = M_PI / 180;
+            mTiltYScale = M_PI / 180;
+
+            mOrientedRanges.haveTilt = true;
+
+            mOrientedRanges.tilt.axis = AMOTION_EVENT_AXIS_TILT;
+            mOrientedRanges.tilt.source = mSource;
+            mOrientedRanges.tilt.min = 0;
+            mOrientedRanges.tilt.max = M_PI_2;
+            mOrientedRanges.tilt.flat = 0;
+            mOrientedRanges.tilt.fuzz = 0;
+            mOrientedRanges.tilt.resolution = 0;
+        }
+
+        // Orientation
+        mOrientationScale = 0;
+        if (mHaveTilt) {
+            mOrientedRanges.haveOrientation = true;
+
+            mOrientedRanges.orientation.axis = AMOTION_EVENT_AXIS_ORIENTATION;
+            mOrientedRanges.orientation.source = mSource;
+            mOrientedRanges.orientation.min = -M_PI;
+            mOrientedRanges.orientation.max = M_PI;
+            mOrientedRanges.orientation.flat = 0;
+            mOrientedRanges.orientation.fuzz = 0;
+            mOrientedRanges.orientation.resolution = 0;
+        } else if (mCalibration.orientationCalibration !=
+                Calibration::ORIENTATION_CALIBRATION_NONE) {
+            if (mCalibration.orientationCalibration
+                    == Calibration::ORIENTATION_CALIBRATION_INTERPOLATED) {
+                if (mRawPointerAxes.orientation.valid) {
+                    if (mRawPointerAxes.orientation.maxValue > 0) {
+                        mOrientationScale = M_PI_2 / mRawPointerAxes.orientation.maxValue;
+                    } else if (mRawPointerAxes.orientation.minValue < 0) {
+                        mOrientationScale = -M_PI_2 / mRawPointerAxes.orientation.minValue;
+                    } else {
+                        mOrientationScale = 0;
+                    }
+                }
+            }
+
+            mOrientedRanges.haveOrientation = true;
+
+            mOrientedRanges.orientation.axis = AMOTION_EVENT_AXIS_ORIENTATION;
+            mOrientedRanges.orientation.source = mSource;
+            mOrientedRanges.orientation.min = -M_PI_2;
+            mOrientedRanges.orientation.max = M_PI_2;
+            mOrientedRanges.orientation.flat = 0;
+            mOrientedRanges.orientation.fuzz = 0;
+            mOrientedRanges.orientation.resolution = 0;
+        }
+
+        // Distance
+        mDistanceScale = 0;
+        if (mCalibration.distanceCalibration != Calibration::DISTANCE_CALIBRATION_NONE) {
+            if (mCalibration.distanceCalibration
+                    == Calibration::DISTANCE_CALIBRATION_SCALED) {
+                if (mCalibration.haveDistanceScale) {
+                    mDistanceScale = mCalibration.distanceScale;
+                } else {
+                    mDistanceScale = 1.0f;
+                }
+            }
+
+            mOrientedRanges.haveDistance = true;
+
+            mOrientedRanges.distance.axis = AMOTION_EVENT_AXIS_DISTANCE;
+            mOrientedRanges.distance.source = mSource;
+            mOrientedRanges.distance.min =
+                    mRawPointerAxes.distance.minValue * mDistanceScale;
+            mOrientedRanges.distance.max =
+                    mRawPointerAxes.distance.maxValue * mDistanceScale;
+            mOrientedRanges.distance.flat = 0;
+            mOrientedRanges.distance.fuzz =
+                    mRawPointerAxes.distance.fuzz * mDistanceScale;
+            mOrientedRanges.distance.resolution = 0;
+        }
+
+        // Compute oriented precision, scales and ranges.
+        // Note that the maximum value reported is an inclusive maximum value so it is one
+        // unit less than the total width or height of surface.
+        switch (mSurfaceOrientation) {
+        case DISPLAY_ORIENTATION_90:
+        case DISPLAY_ORIENTATION_270:
+            mOrientedXPrecision = mYPrecision;
+            mOrientedYPrecision = mXPrecision;
+
+            mOrientedRanges.x.min = mYTranslate;
+            mOrientedRanges.x.max = mSurfaceHeight + mYTranslate - 1;
+            mOrientedRanges.x.flat = 0;
+            mOrientedRanges.x.fuzz = 0;
+            mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mYScale;
+
+            mOrientedRanges.y.min = mXTranslate;
+            mOrientedRanges.y.max = mSurfaceWidth + mXTranslate - 1;
+            mOrientedRanges.y.flat = 0;
+            mOrientedRanges.y.fuzz = 0;
+            mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mXScale;
+            break;
+
+        default:
+            mOrientedXPrecision = mXPrecision;
+            mOrientedYPrecision = mYPrecision;
+
+            mOrientedRanges.x.min = mXTranslate;
+            mOrientedRanges.x.max = mSurfaceWidth + mXTranslate - 1;
+            mOrientedRanges.x.flat = 0;
+            mOrientedRanges.x.fuzz = 0;
+            mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mXScale;
+
+            mOrientedRanges.y.min = mYTranslate;
+            mOrientedRanges.y.max = mSurfaceHeight + mYTranslate - 1;
+            mOrientedRanges.y.flat = 0;
+            mOrientedRanges.y.fuzz = 0;
+            mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mYScale;
+            break;
+        }
+
+        if (mDeviceMode == DEVICE_MODE_POINTER) {
+            // Compute pointer gesture detection parameters.
+            float rawDiagonal = hypotf(rawWidth, rawHeight);
+            float displayDiagonal = hypotf(mSurfaceWidth, mSurfaceHeight);
+
+            // Scale movements such that one whole swipe of the touch pad covers a
+            // given area relative to the diagonal size of the display when no acceleration
+            // is applied.
+            // Assume that the touch pad has a square aspect ratio such that movements in
+            // X and Y of the same number of raw units cover the same physical distance.
+            mPointerXMovementScale = mConfig.pointerGestureMovementSpeedRatio
+                    * displayDiagonal / rawDiagonal;
+            mPointerYMovementScale = mPointerXMovementScale;
+
+            // Scale zooms to cover a smaller range of the display than movements do.
+            // This value determines the area around the pointer that is affected by freeform
+            // pointer gestures.
+            mPointerXZoomScale = mConfig.pointerGestureZoomSpeedRatio
+                    * displayDiagonal / rawDiagonal;
+            mPointerYZoomScale = mPointerXZoomScale;
+
+            // Max width between pointers to detect a swipe gesture is more than some fraction
+            // of the diagonal axis of the touch pad.  Touches that are wider than this are
+            // translated into freeform gestures.
+            mPointerGestureMaxSwipeWidth =
+                    mConfig.pointerGestureSwipeMaxWidthRatio * rawDiagonal;
+
+            // Abort current pointer usages because the state has changed.
+            abortPointerUsage(when, 0 /*policyFlags*/);
+        }
+
+        // Inform the dispatcher about the changes.
+        *outResetNeeded = true;
+        bumpGeneration();
+    }
+}
+
+void TouchInputMapper::dumpSurface(String8& dump) {
+    dump.appendFormat(INDENT3 "Viewport: displayId=%d, orientation=%d, "
+            "logicalFrame=[%d, %d, %d, %d], "
+            "physicalFrame=[%d, %d, %d, %d], "
+            "deviceSize=[%d, %d]\n",
+            mViewport.displayId, mViewport.orientation,
+            mViewport.logicalLeft, mViewport.logicalTop,
+            mViewport.logicalRight, mViewport.logicalBottom,
+            mViewport.physicalLeft, mViewport.physicalTop,
+            mViewport.physicalRight, mViewport.physicalBottom,
+            mViewport.deviceWidth, mViewport.deviceHeight);
+
+    dump.appendFormat(INDENT3 "SurfaceWidth: %dpx\n", mSurfaceWidth);
+    dump.appendFormat(INDENT3 "SurfaceHeight: %dpx\n", mSurfaceHeight);
+    dump.appendFormat(INDENT3 "SurfaceLeft: %d\n", mSurfaceLeft);
+    dump.appendFormat(INDENT3 "SurfaceTop: %d\n", mSurfaceTop);
+    dump.appendFormat(INDENT3 "SurfaceOrientation: %d\n", mSurfaceOrientation);
+}
+
+void TouchInputMapper::configureVirtualKeys() {
+    Vector<VirtualKeyDefinition> virtualKeyDefinitions;
+    getEventHub()->getVirtualKeyDefinitions(getDeviceId(), virtualKeyDefinitions);
+
+    mVirtualKeys.clear();
+
+    if (virtualKeyDefinitions.size() == 0) {
+        return;
+    }
+
+    mVirtualKeys.setCapacity(virtualKeyDefinitions.size());
+
+    int32_t touchScreenLeft = mRawPointerAxes.x.minValue;
+    int32_t touchScreenTop = mRawPointerAxes.y.minValue;
+    int32_t touchScreenWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
+    int32_t touchScreenHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
+
+    for (size_t i = 0; i < virtualKeyDefinitions.size(); i++) {
+        const VirtualKeyDefinition& virtualKeyDefinition =
+                virtualKeyDefinitions[i];
+
+        mVirtualKeys.add();
+        VirtualKey& virtualKey = mVirtualKeys.editTop();
+
+        virtualKey.scanCode = virtualKeyDefinition.scanCode;
+        int32_t keyCode;
+        uint32_t flags;
+        if (getEventHub()->mapKey(getDeviceId(), virtualKey.scanCode, 0, &keyCode, &flags)) {
+            ALOGW(INDENT "VirtualKey %d: could not obtain key code, ignoring",
+                    virtualKey.scanCode);
+            mVirtualKeys.pop(); // drop the key
+            continue;
+        }
+
+        virtualKey.keyCode = keyCode;
+        virtualKey.flags = flags;
+
+        // convert the key definition's display coordinates into touch coordinates for a hit box
+        int32_t halfWidth = virtualKeyDefinition.width / 2;
+        int32_t halfHeight = virtualKeyDefinition.height / 2;
+
+        virtualKey.hitLeft = (virtualKeyDefinition.centerX - halfWidth)
+                * touchScreenWidth / mSurfaceWidth + touchScreenLeft;
+        virtualKey.hitRight= (virtualKeyDefinition.centerX + halfWidth)
+                * touchScreenWidth / mSurfaceWidth + touchScreenLeft;
+        virtualKey.hitTop = (virtualKeyDefinition.centerY - halfHeight)
+                * touchScreenHeight / mSurfaceHeight + touchScreenTop;
+        virtualKey.hitBottom = (virtualKeyDefinition.centerY + halfHeight)
+                * touchScreenHeight / mSurfaceHeight + touchScreenTop;
+    }
+}
+
+void TouchInputMapper::dumpVirtualKeys(String8& dump) {
+    if (!mVirtualKeys.isEmpty()) {
+        dump.append(INDENT3 "Virtual Keys:\n");
+
+        for (size_t i = 0; i < mVirtualKeys.size(); i++) {
+            const VirtualKey& virtualKey = mVirtualKeys.itemAt(i);
+            dump.appendFormat(INDENT4 "%d: scanCode=%d, keyCode=%d, "
+                    "hitLeft=%d, hitRight=%d, hitTop=%d, hitBottom=%d\n",
+                    i, virtualKey.scanCode, virtualKey.keyCode,
+                    virtualKey.hitLeft, virtualKey.hitRight,
+                    virtualKey.hitTop, virtualKey.hitBottom);
+        }
+    }
+}
+
+void TouchInputMapper::parseCalibration() {
+    const PropertyMap& in = getDevice()->getConfiguration();
+    Calibration& out = mCalibration;
+
+    // Size
+    out.sizeCalibration = Calibration::SIZE_CALIBRATION_DEFAULT;
+    String8 sizeCalibrationString;
+    if (in.tryGetProperty(String8("touch.size.calibration"), sizeCalibrationString)) {
+        if (sizeCalibrationString == "none") {
+            out.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE;
+        } else if (sizeCalibrationString == "geometric") {
+            out.sizeCalibration = Calibration::SIZE_CALIBRATION_GEOMETRIC;
+        } else if (sizeCalibrationString == "diameter") {
+            out.sizeCalibration = Calibration::SIZE_CALIBRATION_DIAMETER;
+        } else if (sizeCalibrationString == "box") {
+            out.sizeCalibration = Calibration::SIZE_CALIBRATION_BOX;
+        } else if (sizeCalibrationString == "area") {
+            out.sizeCalibration = Calibration::SIZE_CALIBRATION_AREA;
+        } else if (sizeCalibrationString != "default") {
+            ALOGW("Invalid value for touch.size.calibration: '%s'",
+                    sizeCalibrationString.string());
+        }
+    }
+
+    out.haveSizeScale = in.tryGetProperty(String8("touch.size.scale"),
+            out.sizeScale);
+    out.haveSizeBias = in.tryGetProperty(String8("touch.size.bias"),
+            out.sizeBias);
+    out.haveSizeIsSummed = in.tryGetProperty(String8("touch.size.isSummed"),
+            out.sizeIsSummed);
+
+    // Pressure
+    out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_DEFAULT;
+    String8 pressureCalibrationString;
+    if (in.tryGetProperty(String8("touch.pressure.calibration"), pressureCalibrationString)) {
+        if (pressureCalibrationString == "none") {
+            out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE;
+        } else if (pressureCalibrationString == "physical") {
+            out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_PHYSICAL;
+        } else if (pressureCalibrationString == "amplitude") {
+            out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_AMPLITUDE;
+        } else if (pressureCalibrationString != "default") {
+            ALOGW("Invalid value for touch.pressure.calibration: '%s'",
+                    pressureCalibrationString.string());
+        }
+    }
+
+    out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"),
+            out.pressureScale);
+
+    // Orientation
+    out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_DEFAULT;
+    String8 orientationCalibrationString;
+    if (in.tryGetProperty(String8("touch.orientation.calibration"), orientationCalibrationString)) {
+        if (orientationCalibrationString == "none") {
+            out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE;
+        } else if (orientationCalibrationString == "interpolated") {
+            out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED;
+        } else if (orientationCalibrationString == "vector") {
+            out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_VECTOR;
+        } else if (orientationCalibrationString != "default") {
+            ALOGW("Invalid value for touch.orientation.calibration: '%s'",
+                    orientationCalibrationString.string());
+        }
+    }
+
+    // Distance
+    out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_DEFAULT;
+    String8 distanceCalibrationString;
+    if (in.tryGetProperty(String8("touch.distance.calibration"), distanceCalibrationString)) {
+        if (distanceCalibrationString == "none") {
+            out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_NONE;
+        } else if (distanceCalibrationString == "scaled") {
+            out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_SCALED;
+        } else if (distanceCalibrationString != "default") {
+            ALOGW("Invalid value for touch.distance.calibration: '%s'",
+                    distanceCalibrationString.string());
+        }
+    }
+
+    out.haveDistanceScale = in.tryGetProperty(String8("touch.distance.scale"),
+            out.distanceScale);
+
+    out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_DEFAULT;
+    String8 coverageCalibrationString;
+    if (in.tryGetProperty(String8("touch.coverage.calibration"), coverageCalibrationString)) {
+        if (coverageCalibrationString == "none") {
+            out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_NONE;
+        } else if (coverageCalibrationString == "box") {
+            out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_BOX;
+        } else if (coverageCalibrationString != "default") {
+            ALOGW("Invalid value for touch.coverage.calibration: '%s'",
+                    coverageCalibrationString.string());
+        }
+    }
+}
+
+void TouchInputMapper::resolveCalibration() {
+    // Size
+    if (mRawPointerAxes.touchMajor.valid || mRawPointerAxes.toolMajor.valid) {
+        if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DEFAULT) {
+            mCalibration.sizeCalibration = Calibration::SIZE_CALIBRATION_GEOMETRIC;
+        }
+    } else {
+        mCalibration.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE;
+    }
+
+    // Pressure
+    if (mRawPointerAxes.pressure.valid) {
+        if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_DEFAULT) {
+            mCalibration.pressureCalibration = Calibration::PRESSURE_CALIBRATION_PHYSICAL;
+        }
+    } else {
+        mCalibration.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE;
+    }
+
+    // Orientation
+    if (mRawPointerAxes.orientation.valid) {
+        if (mCalibration.orientationCalibration == Calibration::ORIENTATION_CALIBRATION_DEFAULT) {
+            mCalibration.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED;
+        }
+    } else {
+        mCalibration.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE;
+    }
+
+    // Distance
+    if (mRawPointerAxes.distance.valid) {
+        if (mCalibration.distanceCalibration == Calibration::DISTANCE_CALIBRATION_DEFAULT) {
+            mCalibration.distanceCalibration = Calibration::DISTANCE_CALIBRATION_SCALED;
+        }
+    } else {
+        mCalibration.distanceCalibration = Calibration::DISTANCE_CALIBRATION_NONE;
+    }
+
+    // Coverage
+    if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_DEFAULT) {
+        mCalibration.coverageCalibration = Calibration::COVERAGE_CALIBRATION_NONE;
+    }
+}
+
+void TouchInputMapper::dumpCalibration(String8& dump) {
+    dump.append(INDENT3 "Calibration:\n");
+
+    // Size
+    switch (mCalibration.sizeCalibration) {
+    case Calibration::SIZE_CALIBRATION_NONE:
+        dump.append(INDENT4 "touch.size.calibration: none\n");
+        break;
+    case Calibration::SIZE_CALIBRATION_GEOMETRIC:
+        dump.append(INDENT4 "touch.size.calibration: geometric\n");
+        break;
+    case Calibration::SIZE_CALIBRATION_DIAMETER:
+        dump.append(INDENT4 "touch.size.calibration: diameter\n");
+        break;
+    case Calibration::SIZE_CALIBRATION_BOX:
+        dump.append(INDENT4 "touch.size.calibration: box\n");
+        break;
+    case Calibration::SIZE_CALIBRATION_AREA:
+        dump.append(INDENT4 "touch.size.calibration: area\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+
+    if (mCalibration.haveSizeScale) {
+        dump.appendFormat(INDENT4 "touch.size.scale: %0.3f\n",
+                mCalibration.sizeScale);
+    }
+
+    if (mCalibration.haveSizeBias) {
+        dump.appendFormat(INDENT4 "touch.size.bias: %0.3f\n",
+                mCalibration.sizeBias);
+    }
+
+    if (mCalibration.haveSizeIsSummed) {
+        dump.appendFormat(INDENT4 "touch.size.isSummed: %s\n",
+                toString(mCalibration.sizeIsSummed));
+    }
+
+    // Pressure
+    switch (mCalibration.pressureCalibration) {
+    case Calibration::PRESSURE_CALIBRATION_NONE:
+        dump.append(INDENT4 "touch.pressure.calibration: none\n");
+        break;
+    case Calibration::PRESSURE_CALIBRATION_PHYSICAL:
+        dump.append(INDENT4 "touch.pressure.calibration: physical\n");
+        break;
+    case Calibration::PRESSURE_CALIBRATION_AMPLITUDE:
+        dump.append(INDENT4 "touch.pressure.calibration: amplitude\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+
+    if (mCalibration.havePressureScale) {
+        dump.appendFormat(INDENT4 "touch.pressure.scale: %0.3f\n",
+                mCalibration.pressureScale);
+    }
+
+    // Orientation
+    switch (mCalibration.orientationCalibration) {
+    case Calibration::ORIENTATION_CALIBRATION_NONE:
+        dump.append(INDENT4 "touch.orientation.calibration: none\n");
+        break;
+    case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED:
+        dump.append(INDENT4 "touch.orientation.calibration: interpolated\n");
+        break;
+    case Calibration::ORIENTATION_CALIBRATION_VECTOR:
+        dump.append(INDENT4 "touch.orientation.calibration: vector\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+
+    // Distance
+    switch (mCalibration.distanceCalibration) {
+    case Calibration::DISTANCE_CALIBRATION_NONE:
+        dump.append(INDENT4 "touch.distance.calibration: none\n");
+        break;
+    case Calibration::DISTANCE_CALIBRATION_SCALED:
+        dump.append(INDENT4 "touch.distance.calibration: scaled\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+
+    if (mCalibration.haveDistanceScale) {
+        dump.appendFormat(INDENT4 "touch.distance.scale: %0.3f\n",
+                mCalibration.distanceScale);
+    }
+
+    switch (mCalibration.coverageCalibration) {
+    case Calibration::COVERAGE_CALIBRATION_NONE:
+        dump.append(INDENT4 "touch.coverage.calibration: none\n");
+        break;
+    case Calibration::COVERAGE_CALIBRATION_BOX:
+        dump.append(INDENT4 "touch.coverage.calibration: box\n");
+        break;
+    default:
+        ALOG_ASSERT(false);
+    }
+}
+
+void TouchInputMapper::reset(nsecs_t when) {
+    mCursorButtonAccumulator.reset(getDevice());
+    mCursorScrollAccumulator.reset(getDevice());
+    mTouchButtonAccumulator.reset(getDevice());
+
+    mPointerVelocityControl.reset();
+    mWheelXVelocityControl.reset();
+    mWheelYVelocityControl.reset();
+
+    mCurrentRawPointerData.clear();
+    mLastRawPointerData.clear();
+    mCurrentCookedPointerData.clear();
+    mLastCookedPointerData.clear();
+    mCurrentButtonState = 0;
+    mLastButtonState = 0;
+    mCurrentRawVScroll = 0;
+    mCurrentRawHScroll = 0;
+    mCurrentFingerIdBits.clear();
+    mLastFingerIdBits.clear();
+    mCurrentStylusIdBits.clear();
+    mLastStylusIdBits.clear();
+    mCurrentMouseIdBits.clear();
+    mLastMouseIdBits.clear();
+    mPointerUsage = POINTER_USAGE_NONE;
+    mSentHoverEnter = false;
+    mDownTime = 0;
+
+    mCurrentVirtualKey.down = false;
+
+    mPointerGesture.reset();
+    mPointerSimple.reset();
+
+    if (mPointerController != NULL) {
+        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+        mPointerController->clearSpots();
+    }
+
+    InputMapper::reset(when);
+}
+
+void TouchInputMapper::process(const RawEvent* rawEvent) {
+    mCursorButtonAccumulator.process(rawEvent);
+    mCursorScrollAccumulator.process(rawEvent);
+    mTouchButtonAccumulator.process(rawEvent);
+
+    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
+        sync(rawEvent->when);
+    }
+}
+
+void TouchInputMapper::sync(nsecs_t when) {
+    // Sync button state.
+    mCurrentButtonState = mTouchButtonAccumulator.getButtonState()
+            | mCursorButtonAccumulator.getButtonState();
+
+    // Sync scroll state.
+    mCurrentRawVScroll = mCursorScrollAccumulator.getRelativeVWheel();
+    mCurrentRawHScroll = mCursorScrollAccumulator.getRelativeHWheel();
+    mCursorScrollAccumulator.finishSync();
+
+    // Sync touch state.
+    bool havePointerIds = true;
+    mCurrentRawPointerData.clear();
+    syncTouch(when, &havePointerIds);
+
+#if DEBUG_RAW_EVENTS
+    if (!havePointerIds) {
+        ALOGD("syncTouch: pointerCount %d -> %d, no pointer ids",
+                mLastRawPointerData.pointerCount,
+                mCurrentRawPointerData.pointerCount);
+    } else {
+        ALOGD("syncTouch: pointerCount %d -> %d, touching ids 0x%08x -> 0x%08x, "
+                "hovering ids 0x%08x -> 0x%08x",
+                mLastRawPointerData.pointerCount,
+                mCurrentRawPointerData.pointerCount,
+                mLastRawPointerData.touchingIdBits.value,
+                mCurrentRawPointerData.touchingIdBits.value,
+                mLastRawPointerData.hoveringIdBits.value,
+                mCurrentRawPointerData.hoveringIdBits.value);
+    }
+#endif
+
+    // Reset state that we will compute below.
+    mCurrentFingerIdBits.clear();
+    mCurrentStylusIdBits.clear();
+    mCurrentMouseIdBits.clear();
+    mCurrentCookedPointerData.clear();
+
+    if (mDeviceMode == DEVICE_MODE_DISABLED) {
+        // Drop all input if the device is disabled.
+        mCurrentRawPointerData.clear();
+        mCurrentButtonState = 0;
+    } else {
+        // Preprocess pointer data.
+        if (!havePointerIds) {
+            assignPointerIds();
+        }
+
+        // Handle policy on initial down or hover events.
+        uint32_t policyFlags = 0;
+        bool initialDown = mLastRawPointerData.pointerCount == 0
+                && mCurrentRawPointerData.pointerCount != 0;
+        bool buttonsPressed = mCurrentButtonState & ~mLastButtonState;
+        if (initialDown || buttonsPressed) {
+            // If this is a touch screen, hide the pointer on an initial down.
+            if (mDeviceMode == DEVICE_MODE_DIRECT) {
+                getContext()->fadePointer();
+            }
+
+            if (mParameters.wake) {
+                policyFlags |= POLICY_FLAG_WAKE_DROPPED;
+            }
+        }
+
+        // Synthesize key down from raw buttons if needed.
+        synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
+                policyFlags, mLastButtonState, mCurrentButtonState);
+
+        // Consume raw off-screen touches before cooking pointer data.
+        // If touches are consumed, subsequent code will not receive any pointer data.
+        if (consumeRawTouches(when, policyFlags)) {
+            mCurrentRawPointerData.clear();
+        }
+
+        // Cook pointer data.  This call populates the mCurrentCookedPointerData structure
+        // with cooked pointer data that has the same ids and indices as the raw data.
+        // The following code can use either the raw or cooked data, as needed.
+        cookPointerData();
+
+        // Dispatch the touches either directly or by translation through a pointer on screen.
+        if (mDeviceMode == DEVICE_MODE_POINTER) {
+            for (BitSet32 idBits(mCurrentRawPointerData.touchingIdBits); !idBits.isEmpty(); ) {
+                uint32_t id = idBits.clearFirstMarkedBit();
+                const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
+                if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS
+                        || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) {
+                    mCurrentStylusIdBits.markBit(id);
+                } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER
+                        || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
+                    mCurrentFingerIdBits.markBit(id);
+                } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_MOUSE) {
+                    mCurrentMouseIdBits.markBit(id);
+                }
+            }
+            for (BitSet32 idBits(mCurrentRawPointerData.hoveringIdBits); !idBits.isEmpty(); ) {
+                uint32_t id = idBits.clearFirstMarkedBit();
+                const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
+                if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS
+                        || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) {
+                    mCurrentStylusIdBits.markBit(id);
+                }
+            }
+
+            // Stylus takes precedence over all tools, then mouse, then finger.
+            PointerUsage pointerUsage = mPointerUsage;
+            if (!mCurrentStylusIdBits.isEmpty()) {
+                mCurrentMouseIdBits.clear();
+                mCurrentFingerIdBits.clear();
+                pointerUsage = POINTER_USAGE_STYLUS;
+            } else if (!mCurrentMouseIdBits.isEmpty()) {
+                mCurrentFingerIdBits.clear();
+                pointerUsage = POINTER_USAGE_MOUSE;
+            } else if (!mCurrentFingerIdBits.isEmpty() || isPointerDown(mCurrentButtonState)) {
+                pointerUsage = POINTER_USAGE_GESTURES;
+            }
+
+            dispatchPointerUsage(when, policyFlags, pointerUsage);
+        } else {
+            if (mDeviceMode == DEVICE_MODE_DIRECT
+                    && mConfig.showTouches && mPointerController != NULL) {
+                mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT);
+                mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+
+                mPointerController->setButtonState(mCurrentButtonState);
+                mPointerController->setSpots(mCurrentCookedPointerData.pointerCoords,
+                        mCurrentCookedPointerData.idToIndex,
+                        mCurrentCookedPointerData.touchingIdBits);
+            }
+
+            dispatchHoverExit(when, policyFlags);
+            dispatchTouches(when, policyFlags);
+            dispatchHoverEnterAndMove(when, policyFlags);
+        }
+
+        // Synthesize key up from raw buttons if needed.
+        synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource,
+                policyFlags, mLastButtonState, mCurrentButtonState);
+    }
+
+    // Copy current touch to last touch in preparation for the next cycle.
+    mLastRawPointerData.copyFrom(mCurrentRawPointerData);
+    mLastCookedPointerData.copyFrom(mCurrentCookedPointerData);
+    mLastButtonState = mCurrentButtonState;
+    mLastFingerIdBits = mCurrentFingerIdBits;
+    mLastStylusIdBits = mCurrentStylusIdBits;
+    mLastMouseIdBits = mCurrentMouseIdBits;
+
+    // Clear some transient state.
+    mCurrentRawVScroll = 0;
+    mCurrentRawHScroll = 0;
+}
+
+void TouchInputMapper::timeoutExpired(nsecs_t when) {
+    if (mDeviceMode == DEVICE_MODE_POINTER) {
+        if (mPointerUsage == POINTER_USAGE_GESTURES) {
+            dispatchPointerGestures(when, 0 /*policyFlags*/, true /*isTimeout*/);
+        }
+    }
+}
+
+bool TouchInputMapper::consumeRawTouches(nsecs_t when, uint32_t policyFlags) {
+    // Check for release of a virtual key.
+    if (mCurrentVirtualKey.down) {
+        if (mCurrentRawPointerData.touchingIdBits.isEmpty()) {
+            // Pointer went up while virtual key was down.
+            mCurrentVirtualKey.down = false;
+            if (!mCurrentVirtualKey.ignored) {
+#if DEBUG_VIRTUAL_KEYS
+                ALOGD("VirtualKeys: Generating key up: keyCode=%d, scanCode=%d",
+                        mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
+#endif
+                dispatchVirtualKey(when, policyFlags,
+                        AKEY_EVENT_ACTION_UP,
+                        AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY);
+            }
+            return true;
+        }
+
+        if (mCurrentRawPointerData.touchingIdBits.count() == 1) {
+            uint32_t id = mCurrentRawPointerData.touchingIdBits.firstMarkedBit();
+            const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
+            const VirtualKey* virtualKey = findVirtualKeyHit(pointer.x, pointer.y);
+            if (virtualKey && virtualKey->keyCode == mCurrentVirtualKey.keyCode) {
+                // Pointer is still within the space of the virtual key.
+                return true;
+            }
+        }
+
+        // Pointer left virtual key area or another pointer also went down.
+        // Send key cancellation but do not consume the touch yet.
+        // This is useful when the user swipes through from the virtual key area
+        // into the main display surface.
+        mCurrentVirtualKey.down = false;
+        if (!mCurrentVirtualKey.ignored) {
+#if DEBUG_VIRTUAL_KEYS
+            ALOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d",
+                    mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
+#endif
+            dispatchVirtualKey(when, policyFlags,
+                    AKEY_EVENT_ACTION_UP,
+                    AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
+                            | AKEY_EVENT_FLAG_CANCELED);
+        }
+    }
+
+    if (mLastRawPointerData.touchingIdBits.isEmpty()
+            && !mCurrentRawPointerData.touchingIdBits.isEmpty()) {
+        // Pointer just went down.  Check for virtual key press or off-screen touches.
+        uint32_t id = mCurrentRawPointerData.touchingIdBits.firstMarkedBit();
+        const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
+        if (!isPointInsideSurface(pointer.x, pointer.y)) {
+            // If exactly one pointer went down, check for virtual key hit.
+            // Otherwise we will drop the entire stroke.
+            if (mCurrentRawPointerData.touchingIdBits.count() == 1) {
+                const VirtualKey* virtualKey = findVirtualKeyHit(pointer.x, pointer.y);
+                if (virtualKey) {
+                    mCurrentVirtualKey.down = true;
+                    mCurrentVirtualKey.downTime = when;
+                    mCurrentVirtualKey.keyCode = virtualKey->keyCode;
+                    mCurrentVirtualKey.scanCode = virtualKey->scanCode;
+                    mCurrentVirtualKey.ignored = mContext->shouldDropVirtualKey(
+                            when, getDevice(), virtualKey->keyCode, virtualKey->scanCode);
+
+                    if (!mCurrentVirtualKey.ignored) {
+#if DEBUG_VIRTUAL_KEYS
+                        ALOGD("VirtualKeys: Generating key down: keyCode=%d, scanCode=%d",
+                                mCurrentVirtualKey.keyCode,
+                                mCurrentVirtualKey.scanCode);
+#endif
+                        dispatchVirtualKey(when, policyFlags,
+                                AKEY_EVENT_ACTION_DOWN,
+                                AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY);
+                    }
+                }
+            }
+            return true;
+        }
+    }
+
+    // Disable all virtual key touches that happen within a short time interval of the
+    // most recent touch within the screen area.  The idea is to filter out stray
+    // virtual key presses when interacting with the touch screen.
+    //
+    // Problems we're trying to solve:
+    //
+    // 1. While scrolling a list or dragging the window shade, the user swipes down into a
+    //    virtual key area that is implemented by a separate touch panel and accidentally
+    //    triggers a virtual key.
+    //
+    // 2. While typing in the on screen keyboard, the user taps slightly outside the screen
+    //    area and accidentally triggers a virtual key.  This often happens when virtual keys
+    //    are layed out below the screen near to where the on screen keyboard's space bar
+    //    is displayed.
+    if (mConfig.virtualKeyQuietTime > 0 && !mCurrentRawPointerData.touchingIdBits.isEmpty()) {
+        mContext->disableVirtualKeysUntil(when + mConfig.virtualKeyQuietTime);
+    }
+    return false;
+}
+
+void TouchInputMapper::dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
+        int32_t keyEventAction, int32_t keyEventFlags) {
+    int32_t keyCode = mCurrentVirtualKey.keyCode;
+    int32_t scanCode = mCurrentVirtualKey.scanCode;
+    nsecs_t downTime = mCurrentVirtualKey.downTime;
+    int32_t metaState = mContext->getGlobalMetaState();
+    policyFlags |= POLICY_FLAG_VIRTUAL;
+
+    NotifyKeyArgs args(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
+            keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime);
+    getListener()->notifyKey(&args);
+}
+
+void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
+    BitSet32 currentIdBits = mCurrentCookedPointerData.touchingIdBits;
+    BitSet32 lastIdBits = mLastCookedPointerData.touchingIdBits;
+    int32_t metaState = getContext()->getGlobalMetaState();
+    int32_t buttonState = mCurrentButtonState;
+
+    if (currentIdBits == lastIdBits) {
+        if (!currentIdBits.isEmpty()) {
+            // No pointer id changes so this is a move event.
+            // The listener takes care of batching moves so we don't have to deal with that here.
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState,
+                    AMOTION_EVENT_EDGE_FLAG_NONE,
+                    mCurrentCookedPointerData.pointerProperties,
+                    mCurrentCookedPointerData.pointerCoords,
+                    mCurrentCookedPointerData.idToIndex,
+                    currentIdBits, -1,
+                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+        }
+    } else {
+        // There may be pointers going up and pointers going down and pointers moving
+        // all at the same time.
+        BitSet32 upIdBits(lastIdBits.value & ~currentIdBits.value);
+        BitSet32 downIdBits(currentIdBits.value & ~lastIdBits.value);
+        BitSet32 moveIdBits(lastIdBits.value & currentIdBits.value);
+        BitSet32 dispatchedIdBits(lastIdBits.value);
+
+        // Update last coordinates of pointers that have moved so that we observe the new
+        // pointer positions at the same time as other pointers that have just gone up.
+        bool moveNeeded = updateMovedPointers(
+                mCurrentCookedPointerData.pointerProperties,
+                mCurrentCookedPointerData.pointerCoords,
+                mCurrentCookedPointerData.idToIndex,
+                mLastCookedPointerData.pointerProperties,
+                mLastCookedPointerData.pointerCoords,
+                mLastCookedPointerData.idToIndex,
+                moveIdBits);
+        if (buttonState != mLastButtonState) {
+            moveNeeded = true;
+        }
+
+        // Dispatch pointer up events.
+        while (!upIdBits.isEmpty()) {
+            uint32_t upId = upIdBits.clearFirstMarkedBit();
+
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_POINTER_UP, 0, metaState, buttonState, 0,
+                    mLastCookedPointerData.pointerProperties,
+                    mLastCookedPointerData.pointerCoords,
+                    mLastCookedPointerData.idToIndex,
+                    dispatchedIdBits, upId,
+                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+            dispatchedIdBits.clearBit(upId);
+        }
+
+        // Dispatch move events if any of the remaining pointers moved from their old locations.
+        // Although applications receive new locations as part of individual pointer up
+        // events, they do not generally handle them except when presented in a move event.
+        if (moveNeeded) {
+            ALOG_ASSERT(moveIdBits.value == dispatchedIdBits.value);
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, 0,
+                    mCurrentCookedPointerData.pointerProperties,
+                    mCurrentCookedPointerData.pointerCoords,
+                    mCurrentCookedPointerData.idToIndex,
+                    dispatchedIdBits, -1,
+                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+        }
+
+        // Dispatch pointer down events using the new pointer locations.
+        while (!downIdBits.isEmpty()) {
+            uint32_t downId = downIdBits.clearFirstMarkedBit();
+            dispatchedIdBits.markBit(downId);
+
+            if (dispatchedIdBits.count() == 1) {
+                // First pointer is going down.  Set down time.
+                mDownTime = when;
+            }
+
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
+                    mCurrentCookedPointerData.pointerProperties,
+                    mCurrentCookedPointerData.pointerCoords,
+                    mCurrentCookedPointerData.idToIndex,
+                    dispatchedIdBits, downId,
+                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+        }
+    }
+}
+
+void TouchInputMapper::dispatchHoverExit(nsecs_t when, uint32_t policyFlags) {
+    if (mSentHoverEnter &&
+            (mCurrentCookedPointerData.hoveringIdBits.isEmpty()
+                    || !mCurrentCookedPointerData.touchingIdBits.isEmpty())) {
+        int32_t metaState = getContext()->getGlobalMetaState();
+        dispatchMotion(when, policyFlags, mSource,
+                AMOTION_EVENT_ACTION_HOVER_EXIT, 0, metaState, mLastButtonState, 0,
+                mLastCookedPointerData.pointerProperties,
+                mLastCookedPointerData.pointerCoords,
+                mLastCookedPointerData.idToIndex,
+                mLastCookedPointerData.hoveringIdBits, -1,
+                mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+        mSentHoverEnter = false;
+    }
+}
+
+void TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags) {
+    if (mCurrentCookedPointerData.touchingIdBits.isEmpty()
+            && !mCurrentCookedPointerData.hoveringIdBits.isEmpty()) {
+        int32_t metaState = getContext()->getGlobalMetaState();
+        if (!mSentHoverEnter) {
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_HOVER_ENTER, 0, metaState, mCurrentButtonState, 0,
+                    mCurrentCookedPointerData.pointerProperties,
+                    mCurrentCookedPointerData.pointerCoords,
+                    mCurrentCookedPointerData.idToIndex,
+                    mCurrentCookedPointerData.hoveringIdBits, -1,
+                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+            mSentHoverEnter = true;
+        }
+
+        dispatchMotion(when, policyFlags, mSource,
+                AMOTION_EVENT_ACTION_HOVER_MOVE, 0, metaState, mCurrentButtonState, 0,
+                mCurrentCookedPointerData.pointerProperties,
+                mCurrentCookedPointerData.pointerCoords,
+                mCurrentCookedPointerData.idToIndex,
+                mCurrentCookedPointerData.hoveringIdBits, -1,
+                mOrientedXPrecision, mOrientedYPrecision, mDownTime);
+    }
+}
+
+void TouchInputMapper::cookPointerData() {
+    uint32_t currentPointerCount = mCurrentRawPointerData.pointerCount;
+
+    mCurrentCookedPointerData.clear();
+    mCurrentCookedPointerData.pointerCount = currentPointerCount;
+    mCurrentCookedPointerData.hoveringIdBits = mCurrentRawPointerData.hoveringIdBits;
+    mCurrentCookedPointerData.touchingIdBits = mCurrentRawPointerData.touchingIdBits;
+
+    // Walk through the the active pointers and map device coordinates onto
+    // surface coordinates and adjust for display orientation.
+    for (uint32_t i = 0; i < currentPointerCount; i++) {
+        const RawPointerData::Pointer& in = mCurrentRawPointerData.pointers[i];
+
+        // Size
+        float touchMajor, touchMinor, toolMajor, toolMinor, size;
+        switch (mCalibration.sizeCalibration) {
+        case Calibration::SIZE_CALIBRATION_GEOMETRIC:
+        case Calibration::SIZE_CALIBRATION_DIAMETER:
+        case Calibration::SIZE_CALIBRATION_BOX:
+        case Calibration::SIZE_CALIBRATION_AREA:
+            if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) {
+                touchMajor = in.touchMajor;
+                touchMinor = mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor;
+                toolMajor = in.toolMajor;
+                toolMinor = mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor;
+                size = mRawPointerAxes.touchMinor.valid
+                        ? avg(in.touchMajor, in.touchMinor) : in.touchMajor;
+            } else if (mRawPointerAxes.touchMajor.valid) {
+                toolMajor = touchMajor = in.touchMajor;
+                toolMinor = touchMinor = mRawPointerAxes.touchMinor.valid
+                        ? in.touchMinor : in.touchMajor;
+                size = mRawPointerAxes.touchMinor.valid
+                        ? avg(in.touchMajor, in.touchMinor) : in.touchMajor;
+            } else if (mRawPointerAxes.toolMajor.valid) {
+                touchMajor = toolMajor = in.toolMajor;
+                touchMinor = toolMinor = mRawPointerAxes.toolMinor.valid
+                        ? in.toolMinor : in.toolMajor;
+                size = mRawPointerAxes.toolMinor.valid
+                        ? avg(in.toolMajor, in.toolMinor) : in.toolMajor;
+            } else {
+                ALOG_ASSERT(false, "No touch or tool axes.  "
+                        "Size calibration should have been resolved to NONE.");
+                touchMajor = 0;
+                touchMinor = 0;
+                toolMajor = 0;
+                toolMinor = 0;
+                size = 0;
+            }
+
+            if (mCalibration.haveSizeIsSummed && mCalibration.sizeIsSummed) {
+                uint32_t touchingCount = mCurrentRawPointerData.touchingIdBits.count();
+                if (touchingCount > 1) {
+                    touchMajor /= touchingCount;
+                    touchMinor /= touchingCount;
+                    toolMajor /= touchingCount;
+                    toolMinor /= touchingCount;
+                    size /= touchingCount;
+                }
+            }
+
+            if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_GEOMETRIC) {
+                touchMajor *= mGeometricScale;
+                touchMinor *= mGeometricScale;
+                toolMajor *= mGeometricScale;
+                toolMinor *= mGeometricScale;
+            } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_AREA) {
+                touchMajor = touchMajor > 0 ? sqrtf(touchMajor) : 0;
+                touchMinor = touchMajor;
+                toolMajor = toolMajor > 0 ? sqrtf(toolMajor) : 0;
+                toolMinor = toolMajor;
+            } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DIAMETER) {
+                touchMinor = touchMajor;
+                toolMinor = toolMajor;
+            }
+
+            mCalibration.applySizeScaleAndBias(&touchMajor);
+            mCalibration.applySizeScaleAndBias(&touchMinor);
+            mCalibration.applySizeScaleAndBias(&toolMajor);
+            mCalibration.applySizeScaleAndBias(&toolMinor);
+            size *= mSizeScale;
+            break;
+        default:
+            touchMajor = 0;
+            touchMinor = 0;
+            toolMajor = 0;
+            toolMinor = 0;
+            size = 0;
+            break;
+        }
+
+        // Pressure
+        float pressure;
+        switch (mCalibration.pressureCalibration) {
+        case Calibration::PRESSURE_CALIBRATION_PHYSICAL:
+        case Calibration::PRESSURE_CALIBRATION_AMPLITUDE:
+            pressure = in.pressure * mPressureScale;
+            break;
+        default:
+            pressure = in.isHovering ? 0 : 1;
+            break;
+        }
+
+        // Tilt and Orientation
+        float tilt;
+        float orientation;
+        if (mHaveTilt) {
+            float tiltXAngle = (in.tiltX - mTiltXCenter) * mTiltXScale;
+            float tiltYAngle = (in.tiltY - mTiltYCenter) * mTiltYScale;
+            orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle));
+            tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle));
+        } else {
+            tilt = 0;
+
+            switch (mCalibration.orientationCalibration) {
+            case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED:
+                orientation = in.orientation * mOrientationScale;
+                break;
+            case Calibration::ORIENTATION_CALIBRATION_VECTOR: {
+                int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4);
+                int32_t c2 = signExtendNybble(in.orientation & 0x0f);
+                if (c1 != 0 || c2 != 0) {
+                    orientation = atan2f(c1, c2) * 0.5f;
+                    float confidence = hypotf(c1, c2);
+                    float scale = 1.0f + confidence / 16.0f;
+                    touchMajor *= scale;
+                    touchMinor /= scale;
+                    toolMajor *= scale;
+                    toolMinor /= scale;
+                } else {
+                    orientation = 0;
+                }
+                break;
+            }
+            default:
+                orientation = 0;
+            }
+        }
+
+        // Distance
+        float distance;
+        switch (mCalibration.distanceCalibration) {
+        case Calibration::DISTANCE_CALIBRATION_SCALED:
+            distance = in.distance * mDistanceScale;
+            break;
+        default:
+            distance = 0;
+        }
+
+        // Coverage
+        int32_t rawLeft, rawTop, rawRight, rawBottom;
+        switch (mCalibration.coverageCalibration) {
+        case Calibration::COVERAGE_CALIBRATION_BOX:
+            rawLeft = (in.toolMinor & 0xffff0000) >> 16;
+            rawRight = in.toolMinor & 0x0000ffff;
+            rawBottom = in.toolMajor & 0x0000ffff;
+            rawTop = (in.toolMajor & 0xffff0000) >> 16;
+            break;
+        default:
+            rawLeft = rawTop = rawRight = rawBottom = 0;
+            break;
+        }
+
+        // X, Y, and the bounding box for coverage information
+        // Adjust coords for surface orientation.
+        float x, y, left, top, right, bottom;
+        switch (mSurfaceOrientation) {
+        case DISPLAY_ORIENTATION_90:
+            x = float(in.y - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+            y = float(mRawPointerAxes.x.maxValue - in.x) * mXScale + mXTranslate;
+            left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+            right = float(rawBottom- mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+            bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate;
+            top = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate;
+            orientation -= M_PI_2;
+            if (orientation < mOrientedRanges.orientation.min) {
+                orientation += (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min);
+            }
+            break;
+        case DISPLAY_ORIENTATION_180:
+            x = float(mRawPointerAxes.x.maxValue - in.x) * mXScale + mXTranslate;
+            y = float(mRawPointerAxes.y.maxValue - in.y) * mYScale + mYTranslate;
+            left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate;
+            right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate;
+            bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate;
+            top = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate;
+            orientation -= M_PI;
+            if (orientation < mOrientedRanges.orientation.min) {
+                orientation += (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min);
+            }
+            break;
+        case DISPLAY_ORIENTATION_270:
+            x = float(mRawPointerAxes.y.maxValue - in.y) * mYScale + mYTranslate;
+            y = float(in.x - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+            left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate;
+            right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate;
+            bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+            top = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+            orientation += M_PI_2;
+            if (orientation > mOrientedRanges.orientation.max) {
+                orientation -= (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min);
+            }
+            break;
+        default:
+            x = float(in.x - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+            y = float(in.y - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+            left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+            right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
+            bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+            top = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
+            break;
+        }
+
+        // Write output coords.
+        PointerCoords& out = mCurrentCookedPointerData.pointerCoords[i];
+        out.clear();
+        out.setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        out.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+        out.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
+        out.setAxisValue(AMOTION_EVENT_AXIS_SIZE, size);
+        out.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, touchMajor);
+        out.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, touchMinor);
+        out.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, orientation);
+        out.setAxisValue(AMOTION_EVENT_AXIS_TILT, tilt);
+        out.setAxisValue(AMOTION_EVENT_AXIS_DISTANCE, distance);
+        if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_BOX) {
+            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_1, left);
+            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_2, top);
+            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_3, right);
+            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_4, bottom);
+        } else {
+            out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, toolMajor);
+            out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, toolMinor);
+        }
+
+        // Write output properties.
+        PointerProperties& properties = mCurrentCookedPointerData.pointerProperties[i];
+        uint32_t id = in.id;
+        properties.clear();
+        properties.id = id;
+        properties.toolType = in.toolType;
+
+        // Write id index.
+        mCurrentCookedPointerData.idToIndex[id] = i;
+    }
+}
+
+void TouchInputMapper::dispatchPointerUsage(nsecs_t when, uint32_t policyFlags,
+        PointerUsage pointerUsage) {
+    if (pointerUsage != mPointerUsage) {
+        abortPointerUsage(when, policyFlags);
+        mPointerUsage = pointerUsage;
+    }
+
+    switch (mPointerUsage) {
+    case POINTER_USAGE_GESTURES:
+        dispatchPointerGestures(when, policyFlags, false /*isTimeout*/);
+        break;
+    case POINTER_USAGE_STYLUS:
+        dispatchPointerStylus(when, policyFlags);
+        break;
+    case POINTER_USAGE_MOUSE:
+        dispatchPointerMouse(when, policyFlags);
+        break;
+    default:
+        break;
+    }
+}
+
+void TouchInputMapper::abortPointerUsage(nsecs_t when, uint32_t policyFlags) {
+    switch (mPointerUsage) {
+    case POINTER_USAGE_GESTURES:
+        abortPointerGestures(when, policyFlags);
+        break;
+    case POINTER_USAGE_STYLUS:
+        abortPointerStylus(when, policyFlags);
+        break;
+    case POINTER_USAGE_MOUSE:
+        abortPointerMouse(when, policyFlags);
+        break;
+    default:
+        break;
+    }
+
+    mPointerUsage = POINTER_USAGE_NONE;
+}
+
+void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlags,
+        bool isTimeout) {
+    // Update current gesture coordinates.
+    bool cancelPreviousGesture, finishPreviousGesture;
+    bool sendEvents = preparePointerGestures(when,
+            &cancelPreviousGesture, &finishPreviousGesture, isTimeout);
+    if (!sendEvents) {
+        return;
+    }
+    if (finishPreviousGesture) {
+        cancelPreviousGesture = false;
+    }
+
+    // Update the pointer presentation and spots.
+    if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
+        mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT);
+        if (finishPreviousGesture || cancelPreviousGesture) {
+            mPointerController->clearSpots();
+        }
+        mPointerController->setSpots(mPointerGesture.currentGestureCoords,
+                mPointerGesture.currentGestureIdToIndex,
+                mPointerGesture.currentGestureIdBits);
+    } else {
+        mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
+    }
+
+    // Show or hide the pointer if needed.
+    switch (mPointerGesture.currentGestureMode) {
+    case PointerGesture::NEUTRAL:
+    case PointerGesture::QUIET:
+        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS
+                && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE
+                        || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) {
+            // Remind the user of where the pointer is after finishing a gesture with spots.
+            mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL);
+        }
+        break;
+    case PointerGesture::TAP:
+    case PointerGesture::TAP_DRAG:
+    case PointerGesture::BUTTON_CLICK_OR_DRAG:
+    case PointerGesture::HOVER:
+    case PointerGesture::PRESS:
+        // Unfade the pointer when the current gesture manipulates the
+        // area directly under the pointer.
+        mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
+        break;
+    case PointerGesture::SWIPE:
+    case PointerGesture::FREEFORM:
+        // Fade the pointer when the current gesture manipulates a different
+        // area and there are spots to guide the user experience.
+        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
+            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+        } else {
+            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
+        }
+        break;
+    }
+
+    // Send events!
+    int32_t metaState = getContext()->getGlobalMetaState();
+    int32_t buttonState = mCurrentButtonState;
+
+    // Update last coordinates of pointers that have moved so that we observe the new
+    // pointer positions at the same time as other pointers that have just gone up.
+    bool down = mPointerGesture.currentGestureMode == PointerGesture::TAP
+            || mPointerGesture.currentGestureMode == PointerGesture::TAP_DRAG
+            || mPointerGesture.currentGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG
+            || mPointerGesture.currentGestureMode == PointerGesture::PRESS
+            || mPointerGesture.currentGestureMode == PointerGesture::SWIPE
+            || mPointerGesture.currentGestureMode == PointerGesture::FREEFORM;
+    bool moveNeeded = false;
+    if (down && !cancelPreviousGesture && !finishPreviousGesture
+            && !mPointerGesture.lastGestureIdBits.isEmpty()
+            && !mPointerGesture.currentGestureIdBits.isEmpty()) {
+        BitSet32 movedGestureIdBits(mPointerGesture.currentGestureIdBits.value
+                & mPointerGesture.lastGestureIdBits.value);
+        moveNeeded = updateMovedPointers(mPointerGesture.currentGestureProperties,
+                mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
+                mPointerGesture.lastGestureProperties,
+                mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
+                movedGestureIdBits);
+        if (buttonState != mLastButtonState) {
+            moveNeeded = true;
+        }
+    }
+
+    // Send motion events for all pointers that went up or were canceled.
+    BitSet32 dispatchedGestureIdBits(mPointerGesture.lastGestureIdBits);
+    if (!dispatchedGestureIdBits.isEmpty()) {
+        if (cancelPreviousGesture) {
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_CANCEL, 0, metaState, buttonState,
+                    AMOTION_EVENT_EDGE_FLAG_NONE,
+                    mPointerGesture.lastGestureProperties,
+                    mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
+                    dispatchedGestureIdBits, -1,
+                    0, 0, mPointerGesture.downTime);
+
+            dispatchedGestureIdBits.clear();
+        } else {
+            BitSet32 upGestureIdBits;
+            if (finishPreviousGesture) {
+                upGestureIdBits = dispatchedGestureIdBits;
+            } else {
+                upGestureIdBits.value = dispatchedGestureIdBits.value
+                        & ~mPointerGesture.currentGestureIdBits.value;
+            }
+            while (!upGestureIdBits.isEmpty()) {
+                uint32_t id = upGestureIdBits.clearFirstMarkedBit();
+
+                dispatchMotion(when, policyFlags, mSource,
+                        AMOTION_EVENT_ACTION_POINTER_UP, 0,
+                        metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
+                        mPointerGesture.lastGestureProperties,
+                        mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
+                        dispatchedGestureIdBits, id,
+                        0, 0, mPointerGesture.downTime);
+
+                dispatchedGestureIdBits.clearBit(id);
+            }
+        }
+    }
+
+    // Send motion events for all pointers that moved.
+    if (moveNeeded) {
+        dispatchMotion(when, policyFlags, mSource,
+                AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
+                mPointerGesture.currentGestureProperties,
+                mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
+                dispatchedGestureIdBits, -1,
+                0, 0, mPointerGesture.downTime);
+    }
+
+    // Send motion events for all pointers that went down.
+    if (down) {
+        BitSet32 downGestureIdBits(mPointerGesture.currentGestureIdBits.value
+                & ~dispatchedGestureIdBits.value);
+        while (!downGestureIdBits.isEmpty()) {
+            uint32_t id = downGestureIdBits.clearFirstMarkedBit();
+            dispatchedGestureIdBits.markBit(id);
+
+            if (dispatchedGestureIdBits.count() == 1) {
+                mPointerGesture.downTime = when;
+            }
+
+            dispatchMotion(when, policyFlags, mSource,
+                    AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
+                    mPointerGesture.currentGestureProperties,
+                    mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
+                    dispatchedGestureIdBits, id,
+                    0, 0, mPointerGesture.downTime);
+        }
+    }
+
+    // Send motion events for hover.
+    if (mPointerGesture.currentGestureMode == PointerGesture::HOVER) {
+        dispatchMotion(when, policyFlags, mSource,
+                AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
+                metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
+                mPointerGesture.currentGestureProperties,
+                mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
+                mPointerGesture.currentGestureIdBits, -1,
+                0, 0, mPointerGesture.downTime);
+    } else if (dispatchedGestureIdBits.isEmpty()
+            && !mPointerGesture.lastGestureIdBits.isEmpty()) {
+        // Synthesize a hover move event after all pointers go up to indicate that
+        // the pointer is hovering again even if the user is not currently touching
+        // the touch pad.  This ensures that a view will receive a fresh hover enter
+        // event after a tap.
+        float x, y;
+        mPointerController->getPosition(&x, &y);
+
+        PointerProperties pointerProperties;
+        pointerProperties.clear();
+        pointerProperties.id = 0;
+        pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
+
+        PointerCoords pointerCoords;
+        pointerCoords.clear();
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
+                metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
+                mViewport.displayId, 1, &pointerProperties, &pointerCoords,
+                0, 0, mPointerGesture.downTime);
+        getListener()->notifyMotion(&args);
+    }
+
+    // Update state.
+    mPointerGesture.lastGestureMode = mPointerGesture.currentGestureMode;
+    if (!down) {
+        mPointerGesture.lastGestureIdBits.clear();
+    } else {
+        mPointerGesture.lastGestureIdBits = mPointerGesture.currentGestureIdBits;
+        for (BitSet32 idBits(mPointerGesture.currentGestureIdBits); !idBits.isEmpty(); ) {
+            uint32_t id = idBits.clearFirstMarkedBit();
+            uint32_t index = mPointerGesture.currentGestureIdToIndex[id];
+            mPointerGesture.lastGestureProperties[index].copyFrom(
+                    mPointerGesture.currentGestureProperties[index]);
+            mPointerGesture.lastGestureCoords[index].copyFrom(
+                    mPointerGesture.currentGestureCoords[index]);
+            mPointerGesture.lastGestureIdToIndex[id] = index;
+        }
+    }
+}
+
+void TouchInputMapper::abortPointerGestures(nsecs_t when, uint32_t policyFlags) {
+    // Cancel previously dispatches pointers.
+    if (!mPointerGesture.lastGestureIdBits.isEmpty()) {
+        int32_t metaState = getContext()->getGlobalMetaState();
+        int32_t buttonState = mCurrentButtonState;
+        dispatchMotion(when, policyFlags, mSource,
+                AMOTION_EVENT_ACTION_CANCEL, 0, metaState, buttonState,
+                AMOTION_EVENT_EDGE_FLAG_NONE,
+                mPointerGesture.lastGestureProperties,
+                mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
+                mPointerGesture.lastGestureIdBits, -1,
+                0, 0, mPointerGesture.downTime);
+    }
+
+    // Reset the current pointer gesture.
+    mPointerGesture.reset();
+    mPointerVelocityControl.reset();
+
+    // Remove any current spots.
+    if (mPointerController != NULL) {
+        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+        mPointerController->clearSpots();
+    }
+}
+
+bool TouchInputMapper::preparePointerGestures(nsecs_t when,
+        bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout) {
+    *outCancelPreviousGesture = false;
+    *outFinishPreviousGesture = false;
+
+    // Handle TAP timeout.
+    if (isTimeout) {
+#if DEBUG_GESTURES
+        ALOGD("Gestures: Processing timeout");
+#endif
+
+        if (mPointerGesture.lastGestureMode == PointerGesture::TAP) {
+            if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
+                // The tap/drag timeout has not yet expired.
+                getContext()->requestTimeoutAtTime(mPointerGesture.tapUpTime
+                        + mConfig.pointerGestureTapDragInterval);
+            } else {
+                // The tap is finished.
+#if DEBUG_GESTURES
+                ALOGD("Gestures: TAP finished");
+#endif
+                *outFinishPreviousGesture = true;
+
+                mPointerGesture.activeGestureId = -1;
+                mPointerGesture.currentGestureMode = PointerGesture::NEUTRAL;
+                mPointerGesture.currentGestureIdBits.clear();
+
+                mPointerVelocityControl.reset();
+                return true;
+            }
+        }
+
+        // We did not handle this timeout.
+        return false;
+    }
+
+    const uint32_t currentFingerCount = mCurrentFingerIdBits.count();
+    const uint32_t lastFingerCount = mLastFingerIdBits.count();
+
+    // Update the velocity tracker.
+    {
+        VelocityTracker::Position positions[MAX_POINTERS];
+        uint32_t count = 0;
+        for (BitSet32 idBits(mCurrentFingerIdBits); !idBits.isEmpty(); count++) {
+            uint32_t id = idBits.clearFirstMarkedBit();
+            const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
+            positions[count].x = pointer.x * mPointerXMovementScale;
+            positions[count].y = pointer.y * mPointerYMovementScale;
+        }
+        mPointerGesture.velocityTracker.addMovement(when,
+                mCurrentFingerIdBits, positions);
+    }
+
+    // If the gesture ever enters a mode other than TAP, HOVER or TAP_DRAG, without first returning
+    // to NEUTRAL, then we should not generate tap event.
+    if (mPointerGesture.lastGestureMode != PointerGesture::HOVER
+            && mPointerGesture.lastGestureMode != PointerGesture::TAP
+            && mPointerGesture.lastGestureMode != PointerGesture::TAP_DRAG) {
+        mPointerGesture.resetTap();
+    }
+
+    // Pick a new active touch id if needed.
+    // Choose an arbitrary pointer that just went down, if there is one.
+    // Otherwise choose an arbitrary remaining pointer.
+    // This guarantees we always have an active touch id when there is at least one pointer.
+    // We keep the same active touch id for as long as possible.
+    bool activeTouchChanged = false;
+    int32_t lastActiveTouchId = mPointerGesture.activeTouchId;
+    int32_t activeTouchId = lastActiveTouchId;
+    if (activeTouchId < 0) {
+        if (!mCurrentFingerIdBits.isEmpty()) {
+            activeTouchChanged = true;
+            activeTouchId = mPointerGesture.activeTouchId =
+                    mCurrentFingerIdBits.firstMarkedBit();
+            mPointerGesture.firstTouchTime = when;
+        }
+    } else if (!mCurrentFingerIdBits.hasBit(activeTouchId)) {
+        activeTouchChanged = true;
+        if (!mCurrentFingerIdBits.isEmpty()) {
+            activeTouchId = mPointerGesture.activeTouchId =
+                    mCurrentFingerIdBits.firstMarkedBit();
+        } else {
+            activeTouchId = mPointerGesture.activeTouchId = -1;
+        }
+    }
+
+    // Determine whether we are in quiet time.
+    bool isQuietTime = false;
+    if (activeTouchId < 0) {
+        mPointerGesture.resetQuietTime();
+    } else {
+        isQuietTime = when < mPointerGesture.quietTime + mConfig.pointerGestureQuietInterval;
+        if (!isQuietTime) {
+            if ((mPointerGesture.lastGestureMode == PointerGesture::PRESS
+                    || mPointerGesture.lastGestureMode == PointerGesture::SWIPE
+                    || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)
+                    && currentFingerCount < 2) {
+                // Enter quiet time when exiting swipe or freeform state.
+                // This is to prevent accidentally entering the hover state and flinging the
+                // pointer when finishing a swipe and there is still one pointer left onscreen.
+                isQuietTime = true;
+            } else if (mPointerGesture.lastGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG
+                    && currentFingerCount >= 2
+                    && !isPointerDown(mCurrentButtonState)) {
+                // Enter quiet time when releasing the button and there are still two or more
+                // fingers down.  This may indicate that one finger was used to press the button
+                // but it has not gone up yet.
+                isQuietTime = true;
+            }
+            if (isQuietTime) {
+                mPointerGesture.quietTime = when;
+            }
+        }
+    }
+
+    // Switch states based on button and pointer state.
+    if (isQuietTime) {
+        // Case 1: Quiet time. (QUIET)
+#if DEBUG_GESTURES
+        ALOGD("Gestures: QUIET for next %0.3fms", (mPointerGesture.quietTime
+                + mConfig.pointerGestureQuietInterval - when) * 0.000001f);
+#endif
+        if (mPointerGesture.lastGestureMode != PointerGesture::QUIET) {
+            *outFinishPreviousGesture = true;
+        }
+
+        mPointerGesture.activeGestureId = -1;
+        mPointerGesture.currentGestureMode = PointerGesture::QUIET;
+        mPointerGesture.currentGestureIdBits.clear();
+
+        mPointerVelocityControl.reset();
+    } else if (isPointerDown(mCurrentButtonState)) {
+        // Case 2: Button is pressed. (BUTTON_CLICK_OR_DRAG)
+        // The pointer follows the active touch point.
+        // Emit DOWN, MOVE, UP events at the pointer location.
+        //
+        // Only the active touch matters; other fingers are ignored.  This policy helps
+        // to handle the case where the user places a second finger on the touch pad
+        // to apply the necessary force to depress an integrated button below the surface.
+        // We don't want the second finger to be delivered to applications.
+        //
+        // For this to work well, we need to make sure to track the pointer that is really
+        // active.  If the user first puts one finger down to click then adds another
+        // finger to drag then the active pointer should switch to the finger that is
+        // being dragged.
+#if DEBUG_GESTURES
+        ALOGD("Gestures: BUTTON_CLICK_OR_DRAG activeTouchId=%d, "
+                "currentFingerCount=%d", activeTouchId, currentFingerCount);
+#endif
+        // Reset state when just starting.
+        if (mPointerGesture.lastGestureMode != PointerGesture::BUTTON_CLICK_OR_DRAG) {
+            *outFinishPreviousGesture = true;
+            mPointerGesture.activeGestureId = 0;
+        }
+
+        // Switch pointers if needed.
+        // Find the fastest pointer and follow it.
+        if (activeTouchId >= 0 && currentFingerCount > 1) {
+            int32_t bestId = -1;
+            float bestSpeed = mConfig.pointerGestureDragMinSwitchSpeed;
+            for (BitSet32 idBits(mCurrentFingerIdBits); !idBits.isEmpty(); ) {
+                uint32_t id = idBits.clearFirstMarkedBit();
+                float vx, vy;
+                if (mPointerGesture.velocityTracker.getVelocity(id, &vx, &vy)) {
+                    float speed = hypotf(vx, vy);
+                    if (speed > bestSpeed) {
+                        bestId = id;
+                        bestSpeed = speed;
+                    }
+                }
+            }
+            if (bestId >= 0 && bestId != activeTouchId) {
+                mPointerGesture.activeTouchId = activeTouchId = bestId;
+                activeTouchChanged = true;
+#if DEBUG_GESTURES
+                ALOGD("Gestures: BUTTON_CLICK_OR_DRAG switched pointers, "
+                        "bestId=%d, bestSpeed=%0.3f", bestId, bestSpeed);
+#endif
+            }
+        }
+
+        if (activeTouchId >= 0 && mLastFingerIdBits.hasBit(activeTouchId)) {
+            const RawPointerData::Pointer& currentPointer =
+                    mCurrentRawPointerData.pointerForId(activeTouchId);
+            const RawPointerData::Pointer& lastPointer =
+                    mLastRawPointerData.pointerForId(activeTouchId);
+            float deltaX = (currentPointer.x - lastPointer.x) * mPointerXMovementScale;
+            float deltaY = (currentPointer.y - lastPointer.y) * mPointerYMovementScale;
+
+            rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
+            mPointerVelocityControl.move(when, &deltaX, &deltaY);
+
+            // Move the pointer using a relative motion.
+            // When using spots, the click will occur at the position of the anchor
+            // spot and all other spots will move there.
+            mPointerController->move(deltaX, deltaY);
+        } else {
+            mPointerVelocityControl.reset();
+        }
+
+        float x, y;
+        mPointerController->getPosition(&x, &y);
+
+        mPointerGesture.currentGestureMode = PointerGesture::BUTTON_CLICK_OR_DRAG;
+        mPointerGesture.currentGestureIdBits.clear();
+        mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
+        mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
+        mPointerGesture.currentGestureProperties[0].clear();
+        mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
+        mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
+        mPointerGesture.currentGestureCoords[0].clear();
+        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
+    } else if (currentFingerCount == 0) {
+        // Case 3. No fingers down and button is not pressed. (NEUTRAL)
+        if (mPointerGesture.lastGestureMode != PointerGesture::NEUTRAL) {
+            *outFinishPreviousGesture = true;
+        }
+
+        // Watch for taps coming out of HOVER or TAP_DRAG mode.
+        // Checking for taps after TAP_DRAG allows us to detect double-taps.
+        bool tapped = false;
+        if ((mPointerGesture.lastGestureMode == PointerGesture::HOVER
+                || mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG)
+                && lastFingerCount == 1) {
+            if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) {
+                float x, y;
+                mPointerController->getPosition(&x, &y);
+                if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop
+                        && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
+#if DEBUG_GESTURES
+                    ALOGD("Gestures: TAP");
+#endif
+
+                    mPointerGesture.tapUpTime = when;
+                    getContext()->requestTimeoutAtTime(when
+                            + mConfig.pointerGestureTapDragInterval);
+
+                    mPointerGesture.activeGestureId = 0;
+                    mPointerGesture.currentGestureMode = PointerGesture::TAP;
+                    mPointerGesture.currentGestureIdBits.clear();
+                    mPointerGesture.currentGestureIdBits.markBit(
+                            mPointerGesture.activeGestureId);
+                    mPointerGesture.currentGestureIdToIndex[
+                            mPointerGesture.activeGestureId] = 0;
+                    mPointerGesture.currentGestureProperties[0].clear();
+                    mPointerGesture.currentGestureProperties[0].id =
+                            mPointerGesture.activeGestureId;
+                    mPointerGesture.currentGestureProperties[0].toolType =
+                            AMOTION_EVENT_TOOL_TYPE_FINGER;
+                    mPointerGesture.currentGestureCoords[0].clear();
+                    mPointerGesture.currentGestureCoords[0].setAxisValue(
+                            AMOTION_EVENT_AXIS_X, mPointerGesture.tapX);
+                    mPointerGesture.currentGestureCoords[0].setAxisValue(
+                            AMOTION_EVENT_AXIS_Y, mPointerGesture.tapY);
+                    mPointerGesture.currentGestureCoords[0].setAxisValue(
+                            AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
+
+                    tapped = true;
+                } else {
+#if DEBUG_GESTURES
+                    ALOGD("Gestures: Not a TAP, deltaX=%f, deltaY=%f",
+                            x - mPointerGesture.tapX,
+                            y - mPointerGesture.tapY);
+#endif
+                }
+            } else {
+#if DEBUG_GESTURES
+                if (mPointerGesture.tapDownTime != LLONG_MIN) {
+                    ALOGD("Gestures: Not a TAP, %0.3fms since down",
+                            (when - mPointerGesture.tapDownTime) * 0.000001f);
+                } else {
+                    ALOGD("Gestures: Not a TAP, incompatible mode transitions");
+                }
+#endif
+            }
+        }
+
+        mPointerVelocityControl.reset();
+
+        if (!tapped) {
+#if DEBUG_GESTURES
+            ALOGD("Gestures: NEUTRAL");
+#endif
+            mPointerGesture.activeGestureId = -1;
+            mPointerGesture.currentGestureMode = PointerGesture::NEUTRAL;
+            mPointerGesture.currentGestureIdBits.clear();
+        }
+    } else if (currentFingerCount == 1) {
+        // Case 4. Exactly one finger down, button is not pressed. (HOVER or TAP_DRAG)
+        // The pointer follows the active touch point.
+        // When in HOVER, emit HOVER_MOVE events at the pointer location.
+        // When in TAP_DRAG, emit MOVE events at the pointer location.
+        ALOG_ASSERT(activeTouchId >= 0);
+
+        mPointerGesture.currentGestureMode = PointerGesture::HOVER;
+        if (mPointerGesture.lastGestureMode == PointerGesture::TAP) {
+            if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
+                float x, y;
+                mPointerController->getPosition(&x, &y);
+                if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop
+                        && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
+                    mPointerGesture.currentGestureMode = PointerGesture::TAP_DRAG;
+                } else {
+#if DEBUG_GESTURES
+                    ALOGD("Gestures: Not a TAP_DRAG, deltaX=%f, deltaY=%f",
+                            x - mPointerGesture.tapX,
+                            y - mPointerGesture.tapY);
+#endif
+                }
+            } else {
+#if DEBUG_GESTURES
+                ALOGD("Gestures: Not a TAP_DRAG, %0.3fms time since up",
+                        (when - mPointerGesture.tapUpTime) * 0.000001f);
+#endif
+            }
+        } else if (mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG) {
+            mPointerGesture.currentGestureMode = PointerGesture::TAP_DRAG;
+        }
+
+        if (mLastFingerIdBits.hasBit(activeTouchId)) {
+            const RawPointerData::Pointer& currentPointer =
+                    mCurrentRawPointerData.pointerForId(activeTouchId);
+            const RawPointerData::Pointer& lastPointer =
+                    mLastRawPointerData.pointerForId(activeTouchId);
+            float deltaX = (currentPointer.x - lastPointer.x)
+                    * mPointerXMovementScale;
+            float deltaY = (currentPointer.y - lastPointer.y)
+                    * mPointerYMovementScale;
+
+            rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
+            mPointerVelocityControl.move(when, &deltaX, &deltaY);
+
+            // Move the pointer using a relative motion.
+            // When using spots, the hover or drag will occur at the position of the anchor spot.
+            mPointerController->move(deltaX, deltaY);
+        } else {
+            mPointerVelocityControl.reset();
+        }
+
+        bool down;
+        if (mPointerGesture.currentGestureMode == PointerGesture::TAP_DRAG) {
+#if DEBUG_GESTURES
+            ALOGD("Gestures: TAP_DRAG");
+#endif
+            down = true;
+        } else {
+#if DEBUG_GESTURES
+            ALOGD("Gestures: HOVER");
+#endif
+            if (mPointerGesture.lastGestureMode != PointerGesture::HOVER) {
+                *outFinishPreviousGesture = true;
+            }
+            mPointerGesture.activeGestureId = 0;
+            down = false;
+        }
+
+        float x, y;
+        mPointerController->getPosition(&x, &y);
+
+        mPointerGesture.currentGestureIdBits.clear();
+        mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
+        mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
+        mPointerGesture.currentGestureProperties[0].clear();
+        mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
+        mPointerGesture.currentGestureProperties[0].toolType =
+                AMOTION_EVENT_TOOL_TYPE_FINGER;
+        mPointerGesture.currentGestureCoords[0].clear();
+        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE,
+                down ? 1.0f : 0.0f);
+
+        if (lastFingerCount == 0 && currentFingerCount != 0) {
+            mPointerGesture.resetTap();
+            mPointerGesture.tapDownTime = when;
+            mPointerGesture.tapX = x;
+            mPointerGesture.tapY = y;
+        }
+    } else {
+        // Case 5. At least two fingers down, button is not pressed. (PRESS, SWIPE or FREEFORM)
+        // We need to provide feedback for each finger that goes down so we cannot wait
+        // for the fingers to move before deciding what to do.
+        //
+        // The ambiguous case is deciding what to do when there are two fingers down but they
+        // have not moved enough to determine whether they are part of a drag or part of a
+        // freeform gesture, or just a press or long-press at the pointer location.
+        //
+        // When there are two fingers we start with the PRESS hypothesis and we generate a
+        // down at the pointer location.
+        //
+        // When the two fingers move enough or when additional fingers are added, we make
+        // a decision to transition into SWIPE or FREEFORM mode accordingly.
+        ALOG_ASSERT(activeTouchId >= 0);
+
+        bool settled = when >= mPointerGesture.firstTouchTime
+                + mConfig.pointerGestureMultitouchSettleInterval;
+        if (mPointerGesture.lastGestureMode != PointerGesture::PRESS
+                && mPointerGesture.lastGestureMode != PointerGesture::SWIPE
+                && mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) {
+            *outFinishPreviousGesture = true;
+        } else if (!settled && currentFingerCount > lastFingerCount) {
+            // Additional pointers have gone down but not yet settled.
+            // Reset the gesture.
+#if DEBUG_GESTURES
+            ALOGD("Gestures: Resetting gesture since additional pointers went down for MULTITOUCH, "
+                    "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime
+                            + mConfig.pointerGestureMultitouchSettleInterval - when)
+                            * 0.000001f);
+#endif
+            *outCancelPreviousGesture = true;
+        } else {
+            // Continue previous gesture.
+            mPointerGesture.currentGestureMode = mPointerGesture.lastGestureMode;
+        }
+
+        if (*outFinishPreviousGesture || *outCancelPreviousGesture) {
+            mPointerGesture.currentGestureMode = PointerGesture::PRESS;
+            mPointerGesture.activeGestureId = 0;
+            mPointerGesture.referenceIdBits.clear();
+            mPointerVelocityControl.reset();
+
+            // Use the centroid and pointer location as the reference points for the gesture.
+#if DEBUG_GESTURES
+            ALOGD("Gestures: Using centroid as reference for MULTITOUCH, "
+                    "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime
+                            + mConfig.pointerGestureMultitouchSettleInterval - when)
+                            * 0.000001f);
+#endif
+            mCurrentRawPointerData.getCentroidOfTouchingPointers(
+                    &mPointerGesture.referenceTouchX,
+                    &mPointerGesture.referenceTouchY);
+            mPointerController->getPosition(&mPointerGesture.referenceGestureX,
+                    &mPointerGesture.referenceGestureY);
+        }
+
+        // Clear the reference deltas for fingers not yet included in the reference calculation.
+        for (BitSet32 idBits(mCurrentFingerIdBits.value
+                & ~mPointerGesture.referenceIdBits.value); !idBits.isEmpty(); ) {
+            uint32_t id = idBits.clearFirstMarkedBit();
+            mPointerGesture.referenceDeltas[id].dx = 0;
+            mPointerGesture.referenceDeltas[id].dy = 0;
+        }
+        mPointerGesture.referenceIdBits = mCurrentFingerIdBits;
+
+        // Add delta for all fingers and calculate a common movement delta.
+        float commonDeltaX = 0, commonDeltaY = 0;
+        BitSet32 commonIdBits(mLastFingerIdBits.value
+                & mCurrentFingerIdBits.value);
+        for (BitSet32 idBits(commonIdBits); !idBits.isEmpty(); ) {
+            bool first = (idBits == commonIdBits);
+            uint32_t id = idBits.clearFirstMarkedBit();
+            const RawPointerData::Pointer& cpd = mCurrentRawPointerData.pointerForId(id);
+            const RawPointerData::Pointer& lpd = mLastRawPointerData.pointerForId(id);
+            PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
+            delta.dx += cpd.x - lpd.x;
+            delta.dy += cpd.y - lpd.y;
+
+            if (first) {
+                commonDeltaX = delta.dx;
+                commonDeltaY = delta.dy;
+            } else {
+                commonDeltaX = calculateCommonVector(commonDeltaX, delta.dx);
+                commonDeltaY = calculateCommonVector(commonDeltaY, delta.dy);
+            }
+        }
+
+        // Consider transitions from PRESS to SWIPE or MULTITOUCH.
+        if (mPointerGesture.currentGestureMode == PointerGesture::PRESS) {
+            float dist[MAX_POINTER_ID + 1];
+            int32_t distOverThreshold = 0;
+            for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) {
+                uint32_t id = idBits.clearFirstMarkedBit();
+                PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
+                dist[id] = hypotf(delta.dx * mPointerXZoomScale,
+                        delta.dy * mPointerYZoomScale);
+                if (dist[id] > mConfig.pointerGestureMultitouchMinDistance) {
+                    distOverThreshold += 1;
+                }
+            }
+
+            // Only transition when at least two pointers have moved further than
+            // the minimum distance threshold.
+            if (distOverThreshold >= 2) {
+                if (currentFingerCount > 2) {
+                    // There are more than two pointers, switch to FREEFORM.
+#if DEBUG_GESTURES
+                    ALOGD("Gestures: PRESS transitioned to FREEFORM, number of pointers %d > 2",
+                            currentFingerCount);
+#endif
+                    *outCancelPreviousGesture = true;
+                    mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                } else {
+                    // There are exactly two pointers.
+                    BitSet32 idBits(mCurrentFingerIdBits);
+                    uint32_t id1 = idBits.clearFirstMarkedBit();
+                    uint32_t id2 = idBits.firstMarkedBit();
+                    const RawPointerData::Pointer& p1 = mCurrentRawPointerData.pointerForId(id1);
+                    const RawPointerData::Pointer& p2 = mCurrentRawPointerData.pointerForId(id2);
+                    float mutualDistance = distance(p1.x, p1.y, p2.x, p2.y);
+                    if (mutualDistance > mPointerGestureMaxSwipeWidth) {
+                        // There are two pointers but they are too far apart for a SWIPE,
+                        // switch to FREEFORM.
+#if DEBUG_GESTURES
+                        ALOGD("Gestures: PRESS transitioned to FREEFORM, distance %0.3f > %0.3f",
+                                mutualDistance, mPointerGestureMaxSwipeWidth);
+#endif
+                        *outCancelPreviousGesture = true;
+                        mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                    } else {
+                        // There are two pointers.  Wait for both pointers to start moving
+                        // before deciding whether this is a SWIPE or FREEFORM gesture.
+                        float dist1 = dist[id1];
+                        float dist2 = dist[id2];
+                        if (dist1 >= mConfig.pointerGestureMultitouchMinDistance
+                                && dist2 >= mConfig.pointerGestureMultitouchMinDistance) {
+                            // Calculate the dot product of the displacement vectors.
+                            // When the vectors are oriented in approximately the same direction,
+                            // the angle betweeen them is near zero and the cosine of the angle
+                            // approches 1.0.  Recall that dot(v1, v2) = cos(angle) * mag(v1) * mag(v2).
+                            PointerGesture::Delta& delta1 = mPointerGesture.referenceDeltas[id1];
+                            PointerGesture::Delta& delta2 = mPointerGesture.referenceDeltas[id2];
+                            float dx1 = delta1.dx * mPointerXZoomScale;
+                            float dy1 = delta1.dy * mPointerYZoomScale;
+                            float dx2 = delta2.dx * mPointerXZoomScale;
+                            float dy2 = delta2.dy * mPointerYZoomScale;
+                            float dot = dx1 * dx2 + dy1 * dy2;
+                            float cosine = dot / (dist1 * dist2); // denominator always > 0
+                            if (cosine >= mConfig.pointerGestureSwipeTransitionAngleCosine) {
+                                // Pointers are moving in the same direction.  Switch to SWIPE.
+#if DEBUG_GESTURES
+                                ALOGD("Gestures: PRESS transitioned to SWIPE, "
+                                        "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, "
+                                        "cosine %0.3f >= %0.3f",
+                                        dist1, mConfig.pointerGestureMultitouchMinDistance,
+                                        dist2, mConfig.pointerGestureMultitouchMinDistance,
+                                        cosine, mConfig.pointerGestureSwipeTransitionAngleCosine);
+#endif
+                                mPointerGesture.currentGestureMode = PointerGesture::SWIPE;
+                            } else {
+                                // Pointers are moving in different directions.  Switch to FREEFORM.
+#if DEBUG_GESTURES
+                                ALOGD("Gestures: PRESS transitioned to FREEFORM, "
+                                        "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, "
+                                        "cosine %0.3f < %0.3f",
+                                        dist1, mConfig.pointerGestureMultitouchMinDistance,
+                                        dist2, mConfig.pointerGestureMultitouchMinDistance,
+                                        cosine, mConfig.pointerGestureSwipeTransitionAngleCosine);
+#endif
+                                *outCancelPreviousGesture = true;
+                                mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+                            }
+                        }
+                    }
+                }
+            }
+        } else if (mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
+            // Switch from SWIPE to FREEFORM if additional pointers go down.
+            // Cancel previous gesture.
+            if (currentFingerCount > 2) {
+#if DEBUG_GESTURES
+                ALOGD("Gestures: SWIPE transitioned to FREEFORM, number of pointers %d > 2",
+                        currentFingerCount);
+#endif
+                *outCancelPreviousGesture = true;
+                mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
+            }
+        }
+
+        // Move the reference points based on the overall group motion of the fingers
+        // except in PRESS mode while waiting for a transition to occur.
+        if (mPointerGesture.currentGestureMode != PointerGesture::PRESS
+                && (commonDeltaX || commonDeltaY)) {
+            for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) {
+                uint32_t id = idBits.clearFirstMarkedBit();
+                PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
+                delta.dx = 0;
+                delta.dy = 0;
+            }
+
+            mPointerGesture.referenceTouchX += commonDeltaX;
+            mPointerGesture.referenceTouchY += commonDeltaY;
+
+            commonDeltaX *= mPointerXMovementScale;
+            commonDeltaY *= mPointerYMovementScale;
+
+            rotateDelta(mSurfaceOrientation, &commonDeltaX, &commonDeltaY);
+            mPointerVelocityControl.move(when, &commonDeltaX, &commonDeltaY);
+
+            mPointerGesture.referenceGestureX += commonDeltaX;
+            mPointerGesture.referenceGestureY += commonDeltaY;
+        }
+
+        // Report gestures.
+        if (mPointerGesture.currentGestureMode == PointerGesture::PRESS
+                || mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
+            // PRESS or SWIPE mode.
+#if DEBUG_GESTURES
+            ALOGD("Gestures: PRESS or SWIPE activeTouchId=%d,"
+                    "activeGestureId=%d, currentTouchPointerCount=%d",
+                    activeTouchId, mPointerGesture.activeGestureId, currentFingerCount);
+#endif
+            ALOG_ASSERT(mPointerGesture.activeGestureId >= 0);
+
+            mPointerGesture.currentGestureIdBits.clear();
+            mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
+            mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
+            mPointerGesture.currentGestureProperties[0].clear();
+            mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
+            mPointerGesture.currentGestureProperties[0].toolType =
+                    AMOTION_EVENT_TOOL_TYPE_FINGER;
+            mPointerGesture.currentGestureCoords[0].clear();
+            mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X,
+                    mPointerGesture.referenceGestureX);
+            mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y,
+                    mPointerGesture.referenceGestureY);
+            mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
+        } else if (mPointerGesture.currentGestureMode == PointerGesture::FREEFORM) {
+            // FREEFORM mode.
+#if DEBUG_GESTURES
+            ALOGD("Gestures: FREEFORM activeTouchId=%d,"
+                    "activeGestureId=%d, currentTouchPointerCount=%d",
+                    activeTouchId, mPointerGesture.activeGestureId, currentFingerCount);
+#endif
+            ALOG_ASSERT(mPointerGesture.activeGestureId >= 0);
+
+            mPointerGesture.currentGestureIdBits.clear();
+
+            BitSet32 mappedTouchIdBits;
+            BitSet32 usedGestureIdBits;
+            if (mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) {
+                // Initially, assign the active gesture id to the active touch point
+                // if there is one.  No other touch id bits are mapped yet.
+                if (!*outCancelPreviousGesture) {
+                    mappedTouchIdBits.markBit(activeTouchId);
+                    usedGestureIdBits.markBit(mPointerGesture.activeGestureId);
+                    mPointerGesture.freeformTouchToGestureIdMap[activeTouchId] =
+                            mPointerGesture.activeGestureId;
+                } else {
+                    mPointerGesture.activeGestureId = -1;
+                }
+            } else {
+                // Otherwise, assume we mapped all touches from the previous frame.
+                // Reuse all mappings that are still applicable.
+                mappedTouchIdBits.value = mLastFingerIdBits.value
+                        & mCurrentFingerIdBits.value;
+                usedGestureIdBits = mPointerGesture.lastGestureIdBits;
+
+                // Check whether we need to choose a new active gesture id because the
+                // current went went up.
+                for (BitSet32 upTouchIdBits(mLastFingerIdBits.value
+                        & ~mCurrentFingerIdBits.value);
+                        !upTouchIdBits.isEmpty(); ) {
+                    uint32_t upTouchId = upTouchIdBits.clearFirstMarkedBit();
+                    uint32_t upGestureId = mPointerGesture.freeformTouchToGestureIdMap[upTouchId];
+                    if (upGestureId == uint32_t(mPointerGesture.activeGestureId)) {
+                        mPointerGesture.activeGestureId = -1;
+                        break;
+                    }
+                }
+            }
+
+#if DEBUG_GESTURES
+            ALOGD("Gestures: FREEFORM follow up "
+                    "mappedTouchIdBits=0x%08x, usedGestureIdBits=0x%08x, "
+                    "activeGestureId=%d",
+                    mappedTouchIdBits.value, usedGestureIdBits.value,
+                    mPointerGesture.activeGestureId);
+#endif
+
+            BitSet32 idBits(mCurrentFingerIdBits);
+            for (uint32_t i = 0; i < currentFingerCount; i++) {
+                uint32_t touchId = idBits.clearFirstMarkedBit();
+                uint32_t gestureId;
+                if (!mappedTouchIdBits.hasBit(touchId)) {
+                    gestureId = usedGestureIdBits.markFirstUnmarkedBit();
+                    mPointerGesture.freeformTouchToGestureIdMap[touchId] = gestureId;
+#if DEBUG_GESTURES
+                    ALOGD("Gestures: FREEFORM "
+                            "new mapping for touch id %d -> gesture id %d",
+                            touchId, gestureId);
+#endif
+                } else {
+                    gestureId = mPointerGesture.freeformTouchToGestureIdMap[touchId];
+#if DEBUG_GESTURES
+                    ALOGD("Gestures: FREEFORM "
+                            "existing mapping for touch id %d -> gesture id %d",
+                            touchId, gestureId);
+#endif
+                }
+                mPointerGesture.currentGestureIdBits.markBit(gestureId);
+                mPointerGesture.currentGestureIdToIndex[gestureId] = i;
+
+                const RawPointerData::Pointer& pointer =
+                        mCurrentRawPointerData.pointerForId(touchId);
+                float deltaX = (pointer.x - mPointerGesture.referenceTouchX)
+                        * mPointerXZoomScale;
+                float deltaY = (pointer.y - mPointerGesture.referenceTouchY)
+                        * mPointerYZoomScale;
+                rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
+
+                mPointerGesture.currentGestureProperties[i].clear();
+                mPointerGesture.currentGestureProperties[i].id = gestureId;
+                mPointerGesture.currentGestureProperties[i].toolType =
+                        AMOTION_EVENT_TOOL_TYPE_FINGER;
+                mPointerGesture.currentGestureCoords[i].clear();
+                mPointerGesture.currentGestureCoords[i].setAxisValue(
+                        AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX + deltaX);
+                mPointerGesture.currentGestureCoords[i].setAxisValue(
+                        AMOTION_EVENT_AXIS_Y, mPointerGesture.referenceGestureY + deltaY);
+                mPointerGesture.currentGestureCoords[i].setAxisValue(
+                        AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
+            }
+
+            if (mPointerGesture.activeGestureId < 0) {
+                mPointerGesture.activeGestureId =
+                        mPointerGesture.currentGestureIdBits.firstMarkedBit();
+#if DEBUG_GESTURES
+                ALOGD("Gestures: FREEFORM new "
+                        "activeGestureId=%d", mPointerGesture.activeGestureId);
+#endif
+            }
+        }
+    }
+
+    mPointerController->setButtonState(mCurrentButtonState);
+
+#if DEBUG_GESTURES
+    ALOGD("Gestures: finishPreviousGesture=%s, cancelPreviousGesture=%s, "
+            "currentGestureMode=%d, currentGestureIdBits=0x%08x, "
+            "lastGestureMode=%d, lastGestureIdBits=0x%08x",
+            toString(*outFinishPreviousGesture), toString(*outCancelPreviousGesture),
+            mPointerGesture.currentGestureMode, mPointerGesture.currentGestureIdBits.value,
+            mPointerGesture.lastGestureMode, mPointerGesture.lastGestureIdBits.value);
+    for (BitSet32 idBits = mPointerGesture.currentGestureIdBits; !idBits.isEmpty(); ) {
+        uint32_t id = idBits.clearFirstMarkedBit();
+        uint32_t index = mPointerGesture.currentGestureIdToIndex[id];
+        const PointerProperties& properties = mPointerGesture.currentGestureProperties[index];
+        const PointerCoords& coords = mPointerGesture.currentGestureCoords[index];
+        ALOGD("  currentGesture[%d]: index=%d, toolType=%d, "
+                "x=%0.3f, y=%0.3f, pressure=%0.3f",
+                id, index, properties.toolType,
+                coords.getAxisValue(AMOTION_EVENT_AXIS_X),
+                coords.getAxisValue(AMOTION_EVENT_AXIS_Y),
+                coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
+    }
+    for (BitSet32 idBits = mPointerGesture.lastGestureIdBits; !idBits.isEmpty(); ) {
+        uint32_t id = idBits.clearFirstMarkedBit();
+        uint32_t index = mPointerGesture.lastGestureIdToIndex[id];
+        const PointerProperties& properties = mPointerGesture.lastGestureProperties[index];
+        const PointerCoords& coords = mPointerGesture.lastGestureCoords[index];
+        ALOGD("  lastGesture[%d]: index=%d, toolType=%d, "
+                "x=%0.3f, y=%0.3f, pressure=%0.3f",
+                id, index, properties.toolType,
+                coords.getAxisValue(AMOTION_EVENT_AXIS_X),
+                coords.getAxisValue(AMOTION_EVENT_AXIS_Y),
+                coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
+    }
+#endif
+    return true;
+}
+
+void TouchInputMapper::dispatchPointerStylus(nsecs_t when, uint32_t policyFlags) {
+    mPointerSimple.currentCoords.clear();
+    mPointerSimple.currentProperties.clear();
+
+    bool down, hovering;
+    if (!mCurrentStylusIdBits.isEmpty()) {
+        uint32_t id = mCurrentStylusIdBits.firstMarkedBit();
+        uint32_t index = mCurrentCookedPointerData.idToIndex[id];
+        float x = mCurrentCookedPointerData.pointerCoords[index].getX();
+        float y = mCurrentCookedPointerData.pointerCoords[index].getY();
+        mPointerController->setPosition(x, y);
+
+        hovering = mCurrentCookedPointerData.hoveringIdBits.hasBit(id);
+        down = !hovering;
+
+        mPointerController->getPosition(&x, &y);
+        mPointerSimple.currentCoords.copyFrom(mCurrentCookedPointerData.pointerCoords[index]);
+        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+        mPointerSimple.currentProperties.id = 0;
+        mPointerSimple.currentProperties.toolType =
+                mCurrentCookedPointerData.pointerProperties[index].toolType;
+    } else {
+        down = false;
+        hovering = false;
+    }
+
+    dispatchPointerSimple(when, policyFlags, down, hovering);
+}
+
+void TouchInputMapper::abortPointerStylus(nsecs_t when, uint32_t policyFlags) {
+    abortPointerSimple(when, policyFlags);
+}
+
+void TouchInputMapper::dispatchPointerMouse(nsecs_t when, uint32_t policyFlags) {
+    mPointerSimple.currentCoords.clear();
+    mPointerSimple.currentProperties.clear();
+
+    bool down, hovering;
+    if (!mCurrentMouseIdBits.isEmpty()) {
+        uint32_t id = mCurrentMouseIdBits.firstMarkedBit();
+        uint32_t currentIndex = mCurrentRawPointerData.idToIndex[id];
+        if (mLastMouseIdBits.hasBit(id)) {
+            uint32_t lastIndex = mCurrentRawPointerData.idToIndex[id];
+            float deltaX = (mCurrentRawPointerData.pointers[currentIndex].x
+                    - mLastRawPointerData.pointers[lastIndex].x)
+                    * mPointerXMovementScale;
+            float deltaY = (mCurrentRawPointerData.pointers[currentIndex].y
+                    - mLastRawPointerData.pointers[lastIndex].y)
+                    * mPointerYMovementScale;
+
+            rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
+            mPointerVelocityControl.move(when, &deltaX, &deltaY);
+
+            mPointerController->move(deltaX, deltaY);
+        } else {
+            mPointerVelocityControl.reset();
+        }
+
+        down = isPointerDown(mCurrentButtonState);
+        hovering = !down;
+
+        float x, y;
+        mPointerController->getPosition(&x, &y);
+        mPointerSimple.currentCoords.copyFrom(
+                mCurrentCookedPointerData.pointerCoords[currentIndex]);
+        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
+        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE,
+                hovering ? 0.0f : 1.0f);
+        mPointerSimple.currentProperties.id = 0;
+        mPointerSimple.currentProperties.toolType =
+                mCurrentCookedPointerData.pointerProperties[currentIndex].toolType;
+    } else {
+        mPointerVelocityControl.reset();
+
+        down = false;
+        hovering = false;
+    }
+
+    dispatchPointerSimple(when, policyFlags, down, hovering);
+}
+
+void TouchInputMapper::abortPointerMouse(nsecs_t when, uint32_t policyFlags) {
+    abortPointerSimple(when, policyFlags);
+
+    mPointerVelocityControl.reset();
+}
+
+void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
+        bool down, bool hovering) {
+    int32_t metaState = getContext()->getGlobalMetaState();
+
+    if (mPointerController != NULL) {
+        if (down || hovering) {
+            mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
+            mPointerController->clearSpots();
+            mPointerController->setButtonState(mCurrentButtonState);
+            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
+        } else if (!down && !hovering && (mPointerSimple.down || mPointerSimple.hovering)) {
+            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+        }
+    }
+
+    if (mPointerSimple.down && !down) {
+        mPointerSimple.down = false;
+
+        // Send up.
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                 AMOTION_EVENT_ACTION_UP, 0, metaState, mLastButtonState, 0,
+                 mViewport.displayId,
+                 1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
+                 mOrientedXPrecision, mOrientedYPrecision,
+                 mPointerSimple.downTime);
+        getListener()->notifyMotion(&args);
+    }
+
+    if (mPointerSimple.hovering && !hovering) {
+        mPointerSimple.hovering = false;
+
+        // Send hover exit.
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                AMOTION_EVENT_ACTION_HOVER_EXIT, 0, metaState, mLastButtonState, 0,
+                mViewport.displayId,
+                1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
+                mOrientedXPrecision, mOrientedYPrecision,
+                mPointerSimple.downTime);
+        getListener()->notifyMotion(&args);
+    }
+
+    if (down) {
+        if (!mPointerSimple.down) {
+            mPointerSimple.down = true;
+            mPointerSimple.downTime = when;
+
+            // Send down.
+            NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                    AMOTION_EVENT_ACTION_DOWN, 0, metaState, mCurrentButtonState, 0,
+                    mViewport.displayId,
+                    1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
+                    mOrientedXPrecision, mOrientedYPrecision,
+                    mPointerSimple.downTime);
+            getListener()->notifyMotion(&args);
+        }
+
+        // Send move.
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                AMOTION_EVENT_ACTION_MOVE, 0, metaState, mCurrentButtonState, 0,
+                mViewport.displayId,
+                1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
+                mOrientedXPrecision, mOrientedYPrecision,
+                mPointerSimple.downTime);
+        getListener()->notifyMotion(&args);
+    }
+
+    if (hovering) {
+        if (!mPointerSimple.hovering) {
+            mPointerSimple.hovering = true;
+
+            // Send hover enter.
+            NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                    AMOTION_EVENT_ACTION_HOVER_ENTER, 0, metaState, mCurrentButtonState, 0,
+                    mViewport.displayId,
+                    1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
+                    mOrientedXPrecision, mOrientedYPrecision,
+                    mPointerSimple.downTime);
+            getListener()->notifyMotion(&args);
+        }
+
+        // Send hover move.
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                AMOTION_EVENT_ACTION_HOVER_MOVE, 0, metaState, mCurrentButtonState, 0,
+                mViewport.displayId,
+                1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
+                mOrientedXPrecision, mOrientedYPrecision,
+                mPointerSimple.downTime);
+        getListener()->notifyMotion(&args);
+    }
+
+    if (mCurrentRawVScroll || mCurrentRawHScroll) {
+        float vscroll = mCurrentRawVScroll;
+        float hscroll = mCurrentRawHScroll;
+        mWheelYVelocityControl.move(when, NULL, &vscroll);
+        mWheelXVelocityControl.move(when, &hscroll, NULL);
+
+        // Send scroll.
+        PointerCoords pointerCoords;
+        pointerCoords.copyFrom(mPointerSimple.currentCoords);
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
+        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);
+
+        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
+                AMOTION_EVENT_ACTION_SCROLL, 0, metaState, mCurrentButtonState, 0,
+                mViewport.displayId,
+                1, &mPointerSimple.currentProperties, &pointerCoords,
+                mOrientedXPrecision, mOrientedYPrecision,
+                mPointerSimple.downTime);
+        getListener()->notifyMotion(&args);
+    }
+
+    // Save state.
+    if (down || hovering) {
+        mPointerSimple.lastCoords.copyFrom(mPointerSimple.currentCoords);
+        mPointerSimple.lastProperties.copyFrom(mPointerSimple.currentProperties);
+    } else {
+        mPointerSimple.reset();
+    }
+}
+
+void TouchInputMapper::abortPointerSimple(nsecs_t when, uint32_t policyFlags) {
+    mPointerSimple.currentCoords.clear();
+    mPointerSimple.currentProperties.clear();
+
+    dispatchPointerSimple(when, policyFlags, false, false);
+}
+
+void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
+        int32_t action, int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags,
+        const PointerProperties* properties, const PointerCoords* coords,
+        const uint32_t* idToIndex, BitSet32 idBits,
+        int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime) {
+    PointerCoords pointerCoords[MAX_POINTERS];
+    PointerProperties pointerProperties[MAX_POINTERS];
+    uint32_t pointerCount = 0;
+    while (!idBits.isEmpty()) {
+        uint32_t id = idBits.clearFirstMarkedBit();
+        uint32_t index = idToIndex[id];
+        pointerProperties[pointerCount].copyFrom(properties[index]);
+        pointerCoords[pointerCount].copyFrom(coords[index]);
+
+        if (changedId >= 0 && id == uint32_t(changedId)) {
+            action |= pointerCount << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
+        }
+
+        pointerCount += 1;
+    }
+
+    ALOG_ASSERT(pointerCount != 0);
+
+    if (changedId >= 0 && pointerCount == 1) {
+        // Replace initial down and final up action.
+        // We can compare the action without masking off the changed pointer index
+        // because we know the index is 0.
+        if (action == AMOTION_EVENT_ACTION_POINTER_DOWN) {
+            action = AMOTION_EVENT_ACTION_DOWN;
+        } else if (action == AMOTION_EVENT_ACTION_POINTER_UP) {
+            action = AMOTION_EVENT_ACTION_UP;
+        } else {
+            // Can't happen.
+            ALOG_ASSERT(false);
+        }
+    }
+
+    NotifyMotionArgs args(when, getDeviceId(), source, policyFlags,
+            action, flags, metaState, buttonState, edgeFlags,
+            mViewport.displayId, pointerCount, pointerProperties, pointerCoords,
+            xPrecision, yPrecision, downTime);
+    getListener()->notifyMotion(&args);
+}
+
+bool TouchInputMapper::updateMovedPointers(const PointerProperties* inProperties,
+        const PointerCoords* inCoords, const uint32_t* inIdToIndex,
+        PointerProperties* outProperties, PointerCoords* outCoords, const uint32_t* outIdToIndex,
+        BitSet32 idBits) const {
+    bool changed = false;
+    while (!idBits.isEmpty()) {
+        uint32_t id = idBits.clearFirstMarkedBit();
+        uint32_t inIndex = inIdToIndex[id];
+        uint32_t outIndex = outIdToIndex[id];
+
+        const PointerProperties& curInProperties = inProperties[inIndex];
+        const PointerCoords& curInCoords = inCoords[inIndex];
+        PointerProperties& curOutProperties = outProperties[outIndex];
+        PointerCoords& curOutCoords = outCoords[outIndex];
+
+        if (curInProperties != curOutProperties) {
+            curOutProperties.copyFrom(curInProperties);
+            changed = true;
+        }
+
+        if (curInCoords != curOutCoords) {
+            curOutCoords.copyFrom(curInCoords);
+            changed = true;
+        }
+    }
+    return changed;
+}
+
+void TouchInputMapper::fadePointer() {
+    if (mPointerController != NULL) {
+        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
+    }
+}
+
+bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) {
+    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue
+            && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue;
+}
+
+const TouchInputMapper::VirtualKey* TouchInputMapper::findVirtualKeyHit(
+        int32_t x, int32_t y) {
+    size_t numVirtualKeys = mVirtualKeys.size();
+    for (size_t i = 0; i < numVirtualKeys; i++) {
+        const VirtualKey& virtualKey = mVirtualKeys[i];
+
+#if DEBUG_VIRTUAL_KEYS
+        ALOGD("VirtualKeys: Hit test (%d, %d): keyCode=%d, scanCode=%d, "
+                "left=%d, top=%d, right=%d, bottom=%d",
+                x, y,
+                virtualKey.keyCode, virtualKey.scanCode,
+                virtualKey.hitLeft, virtualKey.hitTop,
+                virtualKey.hitRight, virtualKey.hitBottom);
+#endif
+
+        if (virtualKey.isHit(x, y)) {
+            return & virtualKey;
+        }
+    }
+
+    return NULL;
+}
+
+void TouchInputMapper::assignPointerIds() {
+    uint32_t currentPointerCount = mCurrentRawPointerData.pointerCount;
+    uint32_t lastPointerCount = mLastRawPointerData.pointerCount;
+
+    mCurrentRawPointerData.clearIdBits();
+
+    if (currentPointerCount == 0) {
+        // No pointers to assign.
+        return;
+    }
+
+    if (lastPointerCount == 0) {
+        // All pointers are new.
+        for (uint32_t i = 0; i < currentPointerCount; i++) {
+            uint32_t id = i;
+            mCurrentRawPointerData.pointers[i].id = id;
+            mCurrentRawPointerData.idToIndex[id] = i;
+            mCurrentRawPointerData.markIdBit(id, mCurrentRawPointerData.isHovering(i));
+        }
+        return;
+    }
+
+    if (currentPointerCount == 1 && lastPointerCount == 1
+            && mCurrentRawPointerData.pointers[0].toolType
+                    == mLastRawPointerData.pointers[0].toolType) {
+        // Only one pointer and no change in count so it must have the same id as before.
+        uint32_t id = mLastRawPointerData.pointers[0].id;
+        mCurrentRawPointerData.pointers[0].id = id;
+        mCurrentRawPointerData.idToIndex[id] = 0;
+        mCurrentRawPointerData.markIdBit(id, mCurrentRawPointerData.isHovering(0));
+        return;
+    }
+
+    // General case.
+    // We build a heap of squared euclidean distances between current and last pointers
+    // associated with the current and last pointer indices.  Then, we find the best
+    // match (by distance) for each current pointer.
+    // The pointers must have the same tool type but it is possible for them to
+    // transition from hovering to touching or vice-versa while retaining the same id.
+    PointerDistanceHeapElement heap[MAX_POINTERS * MAX_POINTERS];
+
+    uint32_t heapSize = 0;
+    for (uint32_t currentPointerIndex = 0; currentPointerIndex < currentPointerCount;
+            currentPointerIndex++) {
+        for (uint32_t lastPointerIndex = 0; lastPointerIndex < lastPointerCount;
+                lastPointerIndex++) {
+            const RawPointerData::Pointer& currentPointer =
+                    mCurrentRawPointerData.pointers[currentPointerIndex];
+            const RawPointerData::Pointer& lastPointer =
+                    mLastRawPointerData.pointers[lastPointerIndex];
+            if (currentPointer.toolType == lastPointer.toolType) {
+                int64_t deltaX = currentPointer.x - lastPointer.x;
+                int64_t deltaY = currentPointer.y - lastPointer.y;
+
+                uint64_t distance = uint64_t(deltaX * deltaX + deltaY * deltaY);
+
+                // Insert new element into the heap (sift up).
+                heap[heapSize].currentPointerIndex = currentPointerIndex;
+                heap[heapSize].lastPointerIndex = lastPointerIndex;
+                heap[heapSize].distance = distance;
+                heapSize += 1;
+            }
+        }
+    }
+
+    // Heapify
+    for (uint32_t startIndex = heapSize / 2; startIndex != 0; ) {
+        startIndex -= 1;
+        for (uint32_t parentIndex = startIndex; ;) {
+            uint32_t childIndex = parentIndex * 2 + 1;
+            if (childIndex >= heapSize) {
+                break;
+            }
+
+            if (childIndex + 1 < heapSize
+                    && heap[childIndex + 1].distance < heap[childIndex].distance) {
+                childIndex += 1;
+            }
+
+            if (heap[parentIndex].distance <= heap[childIndex].distance) {
+                break;
+            }
+
+            swap(heap[parentIndex], heap[childIndex]);
+            parentIndex = childIndex;
+        }
+    }
+
+#if DEBUG_POINTER_ASSIGNMENT
+    ALOGD("assignPointerIds - initial distance min-heap: size=%d", heapSize);
+    for (size_t i = 0; i < heapSize; i++) {
+        ALOGD("  heap[%d]: cur=%d, last=%d, distance=%lld",
+                i, heap[i].currentPointerIndex, heap[i].lastPointerIndex,
+                heap[i].distance);
+    }
+#endif
+
+    // Pull matches out by increasing order of distance.
+    // To avoid reassigning pointers that have already been matched, the loop keeps track
+    // of which last and current pointers have been matched using the matchedXXXBits variables.
+    // It also tracks the used pointer id bits.
+    BitSet32 matchedLastBits(0);
+    BitSet32 matchedCurrentBits(0);
+    BitSet32 usedIdBits(0);
+    bool first = true;
+    for (uint32_t i = min(currentPointerCount, lastPointerCount); heapSize > 0 && i > 0; i--) {
+        while (heapSize > 0) {
+            if (first) {
+                // The first time through the loop, we just consume the root element of
+                // the heap (the one with smallest distance).
+                first = false;
+            } else {
+                // Previous iterations consumed the root element of the heap.
+                // Pop root element off of the heap (sift down).
+                heap[0] = heap[heapSize];
+                for (uint32_t parentIndex = 0; ;) {
+                    uint32_t childIndex = parentIndex * 2 + 1;
+                    if (childIndex >= heapSize) {
+                        break;
+                    }
+
+                    if (childIndex + 1 < heapSize
+                            && heap[childIndex + 1].distance < heap[childIndex].distance) {
+                        childIndex += 1;
+                    }
+
+                    if (heap[parentIndex].distance <= heap[childIndex].distance) {
+                        break;
+                    }
+
+                    swap(heap[parentIndex], heap[childIndex]);
+                    parentIndex = childIndex;
+                }
+
+#if DEBUG_POINTER_ASSIGNMENT
+                ALOGD("assignPointerIds - reduced distance min-heap: size=%d", heapSize);
+                for (size_t i = 0; i < heapSize; i++) {
+                    ALOGD("  heap[%d]: cur=%d, last=%d, distance=%lld",
+                            i, heap[i].currentPointerIndex, heap[i].lastPointerIndex,
+                            heap[i].distance);
+                }
+#endif
+            }
+
+            heapSize -= 1;
+
+            uint32_t currentPointerIndex = heap[0].currentPointerIndex;
+            if (matchedCurrentBits.hasBit(currentPointerIndex)) continue; // already matched
+
+            uint32_t lastPointerIndex = heap[0].lastPointerIndex;
+            if (matchedLastBits.hasBit(lastPointerIndex)) continue; // already matched
+
+            matchedCurrentBits.markBit(currentPointerIndex);
+            matchedLastBits.markBit(lastPointerIndex);
+
+            uint32_t id = mLastRawPointerData.pointers[lastPointerIndex].id;
+            mCurrentRawPointerData.pointers[currentPointerIndex].id = id;
+            mCurrentRawPointerData.idToIndex[id] = currentPointerIndex;
+            mCurrentRawPointerData.markIdBit(id,
+                    mCurrentRawPointerData.isHovering(currentPointerIndex));
+            usedIdBits.markBit(id);
+
+#if DEBUG_POINTER_ASSIGNMENT
+            ALOGD("assignPointerIds - matched: cur=%d, last=%d, id=%d, distance=%lld",
+                    lastPointerIndex, currentPointerIndex, id, heap[0].distance);
+#endif
+            break;
+        }
+    }
+
+    // Assign fresh ids to pointers that were not matched in the process.
+    for (uint32_t i = currentPointerCount - matchedCurrentBits.count(); i != 0; i--) {
+        uint32_t currentPointerIndex = matchedCurrentBits.markFirstUnmarkedBit();
+        uint32_t id = usedIdBits.markFirstUnmarkedBit();
+
+        mCurrentRawPointerData.pointers[currentPointerIndex].id = id;
+        mCurrentRawPointerData.idToIndex[id] = currentPointerIndex;
+        mCurrentRawPointerData.markIdBit(id,
+                mCurrentRawPointerData.isHovering(currentPointerIndex));
+
+#if DEBUG_POINTER_ASSIGNMENT
+        ALOGD("assignPointerIds - assigned: cur=%d, id=%d",
+                currentPointerIndex, id);
+#endif
+    }
+}
+
+int32_t TouchInputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
+    if (mCurrentVirtualKey.down && mCurrentVirtualKey.keyCode == keyCode) {
+        return AKEY_STATE_VIRTUAL;
+    }
+
+    size_t numVirtualKeys = mVirtualKeys.size();
+    for (size_t i = 0; i < numVirtualKeys; i++) {
+        const VirtualKey& virtualKey = mVirtualKeys[i];
+        if (virtualKey.keyCode == keyCode) {
+            return AKEY_STATE_UP;
+        }
+    }
+
+    return AKEY_STATE_UNKNOWN;
+}
+
+int32_t TouchInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+    if (mCurrentVirtualKey.down && mCurrentVirtualKey.scanCode == scanCode) {
+        return AKEY_STATE_VIRTUAL;
+    }
+
+    size_t numVirtualKeys = mVirtualKeys.size();
+    for (size_t i = 0; i < numVirtualKeys; i++) {
+        const VirtualKey& virtualKey = mVirtualKeys[i];
+        if (virtualKey.scanCode == scanCode) {
+            return AKEY_STATE_UP;
+        }
+    }
+
+    return AKEY_STATE_UNKNOWN;
+}
+
+bool TouchInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+        const int32_t* keyCodes, uint8_t* outFlags) {
+    size_t numVirtualKeys = mVirtualKeys.size();
+    for (size_t i = 0; i < numVirtualKeys; i++) {
+        const VirtualKey& virtualKey = mVirtualKeys[i];
+
+        for (size_t i = 0; i < numCodes; i++) {
+            if (virtualKey.keyCode == keyCodes[i]) {
+                outFlags[i] = 1;
+            }
+        }
+    }
+
+    return true;
+}
+
+
+// --- SingleTouchInputMapper ---
+
+SingleTouchInputMapper::SingleTouchInputMapper(InputDevice* device) :
+        TouchInputMapper(device) {
+}
+
+SingleTouchInputMapper::~SingleTouchInputMapper() {
+}
+
+void SingleTouchInputMapper::reset(nsecs_t when) {
+    mSingleTouchMotionAccumulator.reset(getDevice());
+
+    TouchInputMapper::reset(when);
+}
+
+void SingleTouchInputMapper::process(const RawEvent* rawEvent) {
+    TouchInputMapper::process(rawEvent);
+
+    mSingleTouchMotionAccumulator.process(rawEvent);
+}
+
+void SingleTouchInputMapper::syncTouch(nsecs_t when, bool* outHavePointerIds) {
+    if (mTouchButtonAccumulator.isToolActive()) {
+        mCurrentRawPointerData.pointerCount = 1;
+        mCurrentRawPointerData.idToIndex[0] = 0;
+
+        bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE
+                && (mTouchButtonAccumulator.isHovering()
+                        || (mRawPointerAxes.pressure.valid
+                                && mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0));
+        mCurrentRawPointerData.markIdBit(0, isHovering);
+
+        RawPointerData::Pointer& outPointer = mCurrentRawPointerData.pointers[0];
+        outPointer.id = 0;
+        outPointer.x = mSingleTouchMotionAccumulator.getAbsoluteX();
+        outPointer.y = mSingleTouchMotionAccumulator.getAbsoluteY();
+        outPointer.pressure = mSingleTouchMotionAccumulator.getAbsolutePressure();
+        outPointer.touchMajor = 0;
+        outPointer.touchMinor = 0;
+        outPointer.toolMajor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth();
+        outPointer.toolMinor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth();
+        outPointer.orientation = 0;
+        outPointer.distance = mSingleTouchMotionAccumulator.getAbsoluteDistance();
+        outPointer.tiltX = mSingleTouchMotionAccumulator.getAbsoluteTiltX();
+        outPointer.tiltY = mSingleTouchMotionAccumulator.getAbsoluteTiltY();
+        outPointer.toolType = mTouchButtonAccumulator.getToolType();
+        if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
+            outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
+        }
+        outPointer.isHovering = isHovering;
+    }
+}
+
+void SingleTouchInputMapper::configureRawPointerAxes() {
+    TouchInputMapper::configureRawPointerAxes();
+
+    getAbsoluteAxisInfo(ABS_X, &mRawPointerAxes.x);
+    getAbsoluteAxisInfo(ABS_Y, &mRawPointerAxes.y);
+    getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPointerAxes.pressure);
+    getAbsoluteAxisInfo(ABS_TOOL_WIDTH, &mRawPointerAxes.toolMajor);
+    getAbsoluteAxisInfo(ABS_DISTANCE, &mRawPointerAxes.distance);
+    getAbsoluteAxisInfo(ABS_TILT_X, &mRawPointerAxes.tiltX);
+    getAbsoluteAxisInfo(ABS_TILT_Y, &mRawPointerAxes.tiltY);
+}
+
+bool SingleTouchInputMapper::hasStylus() const {
+    return mTouchButtonAccumulator.hasStylus();
+}
+
+
+// --- MultiTouchInputMapper ---
+
+MultiTouchInputMapper::MultiTouchInputMapper(InputDevice* device) :
+        TouchInputMapper(device) {
+}
+
+MultiTouchInputMapper::~MultiTouchInputMapper() {
+}
+
+void MultiTouchInputMapper::reset(nsecs_t when) {
+    mMultiTouchMotionAccumulator.reset(getDevice());
+
+    mPointerIdBits.clear();
+
+    TouchInputMapper::reset(when);
+}
+
+void MultiTouchInputMapper::process(const RawEvent* rawEvent) {
+    TouchInputMapper::process(rawEvent);
+
+    mMultiTouchMotionAccumulator.process(rawEvent);
+}
+
+void MultiTouchInputMapper::syncTouch(nsecs_t when, bool* outHavePointerIds) {
+    size_t inCount = mMultiTouchMotionAccumulator.getSlotCount();
+    size_t outCount = 0;
+    BitSet32 newPointerIdBits;
+
+    for (size_t inIndex = 0; inIndex < inCount; inIndex++) {
+        const MultiTouchMotionAccumulator::Slot* inSlot =
+                mMultiTouchMotionAccumulator.getSlot(inIndex);
+        if (!inSlot->isInUse()) {
+            continue;
+        }
+
+        if (outCount >= MAX_POINTERS) {
+#if DEBUG_POINTERS
+            ALOGD("MultiTouch device %s emitted more than maximum of %d pointers; "
+                    "ignoring the rest.",
+                    getDeviceName().string(), MAX_POINTERS);
+#endif
+            break; // too many fingers!
+        }
+
+        RawPointerData::Pointer& outPointer = mCurrentRawPointerData.pointers[outCount];
+        outPointer.x = inSlot->getX();
+        outPointer.y = inSlot->getY();
+        outPointer.pressure = inSlot->getPressure();
+        outPointer.touchMajor = inSlot->getTouchMajor();
+        outPointer.touchMinor = inSlot->getTouchMinor();
+        outPointer.toolMajor = inSlot->getToolMajor();
+        outPointer.toolMinor = inSlot->getToolMinor();
+        outPointer.orientation = inSlot->getOrientation();
+        outPointer.distance = inSlot->getDistance();
+        outPointer.tiltX = 0;
+        outPointer.tiltY = 0;
+
+        outPointer.toolType = inSlot->getToolType();
+        if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
+            outPointer.toolType = mTouchButtonAccumulator.getToolType();
+            if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
+                outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
+            }
+        }
+
+        bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE
+                && (mTouchButtonAccumulator.isHovering()
+                        || (mRawPointerAxes.pressure.valid && inSlot->getPressure() <= 0));
+        outPointer.isHovering = isHovering;
+
+        // Assign pointer id using tracking id if available.
+        if (*outHavePointerIds) {
+            int32_t trackingId = inSlot->getTrackingId();
+            int32_t id = -1;
+            if (trackingId >= 0) {
+                for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty(); ) {
+                    uint32_t n = idBits.clearFirstMarkedBit();
+                    if (mPointerTrackingIdMap[n] == trackingId) {
+                        id = n;
+                    }
+                }
+
+                if (id < 0 && !mPointerIdBits.isFull()) {
+                    id = mPointerIdBits.markFirstUnmarkedBit();
+                    mPointerTrackingIdMap[id] = trackingId;
+                }
+            }
+            if (id < 0) {
+                *outHavePointerIds = false;
+                mCurrentRawPointerData.clearIdBits();
+                newPointerIdBits.clear();
+            } else {
+                outPointer.id = id;
+                mCurrentRawPointerData.idToIndex[id] = outCount;
+                mCurrentRawPointerData.markIdBit(id, isHovering);
+                newPointerIdBits.markBit(id);
+            }
+        }
+
+        outCount += 1;
+    }
+
+    mCurrentRawPointerData.pointerCount = outCount;
+    mPointerIdBits = newPointerIdBits;
+
+    mMultiTouchMotionAccumulator.finishSync();
+}
+
+void MultiTouchInputMapper::configureRawPointerAxes() {
+    TouchInputMapper::configureRawPointerAxes();
+
+    getAbsoluteAxisInfo(ABS_MT_POSITION_X, &mRawPointerAxes.x);
+    getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mRawPointerAxes.y);
+    getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR, &mRawPointerAxes.touchMajor);
+    getAbsoluteAxisInfo(ABS_MT_TOUCH_MINOR, &mRawPointerAxes.touchMinor);
+    getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR, &mRawPointerAxes.toolMajor);
+    getAbsoluteAxisInfo(ABS_MT_WIDTH_MINOR, &mRawPointerAxes.toolMinor);
+    getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &mRawPointerAxes.orientation);
+    getAbsoluteAxisInfo(ABS_MT_PRESSURE, &mRawPointerAxes.pressure);
+    getAbsoluteAxisInfo(ABS_MT_DISTANCE, &mRawPointerAxes.distance);
+    getAbsoluteAxisInfo(ABS_MT_TRACKING_ID, &mRawPointerAxes.trackingId);
+    getAbsoluteAxisInfo(ABS_MT_SLOT, &mRawPointerAxes.slot);
+
+    if (mRawPointerAxes.trackingId.valid
+            && mRawPointerAxes.slot.valid
+            && mRawPointerAxes.slot.minValue == 0 && mRawPointerAxes.slot.maxValue > 0) {
+        size_t slotCount = mRawPointerAxes.slot.maxValue + 1;
+        if (slotCount > MAX_SLOTS) {
+            ALOGW("MultiTouch Device %s reported %d slots but the framework "
+                    "only supports a maximum of %d slots at this time.",
+                    getDeviceName().string(), slotCount, MAX_SLOTS);
+            slotCount = MAX_SLOTS;
+        }
+        mMultiTouchMotionAccumulator.configure(getDevice(),
+                slotCount, true /*usingSlotsProtocol*/);
+    } else {
+        mMultiTouchMotionAccumulator.configure(getDevice(),
+                MAX_POINTERS, false /*usingSlotsProtocol*/);
+    }
+}
+
+bool MultiTouchInputMapper::hasStylus() const {
+    return mMultiTouchMotionAccumulator.hasStylus()
+            || mTouchButtonAccumulator.hasStylus();
+}
+
+
+// --- JoystickInputMapper ---
+
+JoystickInputMapper::JoystickInputMapper(InputDevice* device) :
+        InputMapper(device) {
+}
+
+JoystickInputMapper::~JoystickInputMapper() {
+}
+
+uint32_t JoystickInputMapper::getSources() {
+    return AINPUT_SOURCE_JOYSTICK;
+}
+
+void JoystickInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
+    InputMapper::populateDeviceInfo(info);
+
+    for (size_t i = 0; i < mAxes.size(); i++) {
+        const Axis& axis = mAxes.valueAt(i);
+        addMotionRange(axis.axisInfo.axis, axis, info);
+
+        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
+            addMotionRange(axis.axisInfo.highAxis, axis, info);
+
+        }
+    }
+}
+
+void JoystickInputMapper::addMotionRange(int32_t axisId, const Axis& axis,
+        InputDeviceInfo* info) {
+    info->addMotionRange(axisId, AINPUT_SOURCE_JOYSTICK,
+            axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution);
+    /* In order to ease the transition for developers from using the old axes
+     * to the newer, more semantically correct axes, we'll continue to register
+     * the old axes as duplicates of their corresponding new ones.  */
+    int32_t compatAxis = getCompatAxis(axisId);
+    if (compatAxis >= 0) {
+        info->addMotionRange(compatAxis, AINPUT_SOURCE_JOYSTICK,
+                axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution);
+    }
+}
+
+/* A mapping from axes the joystick actually has to the axes that should be
+ * artificially created for compatibility purposes.
+ * Returns -1 if no compatibility axis is needed. */
+int32_t JoystickInputMapper::getCompatAxis(int32_t axis) {
+    switch(axis) {
+    case AMOTION_EVENT_AXIS_LTRIGGER:
+        return AMOTION_EVENT_AXIS_BRAKE;
+    case AMOTION_EVENT_AXIS_RTRIGGER:
+        return AMOTION_EVENT_AXIS_GAS;
+    }
+    return -1;
+}
+
+void JoystickInputMapper::dump(String8& dump) {
+    dump.append(INDENT2 "Joystick Input Mapper:\n");
+
+    dump.append(INDENT3 "Axes:\n");
+    size_t numAxes = mAxes.size();
+    for (size_t i = 0; i < numAxes; i++) {
+        const Axis& axis = mAxes.valueAt(i);
+        const char* label = getAxisLabel(axis.axisInfo.axis);
+        if (label) {
+            dump.appendFormat(INDENT4 "%s", label);
+        } else {
+            dump.appendFormat(INDENT4 "%d", axis.axisInfo.axis);
+        }
+        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
+            label = getAxisLabel(axis.axisInfo.highAxis);
+            if (label) {
+                dump.appendFormat(" / %s (split at %d)", label, axis.axisInfo.splitValue);
+            } else {
+                dump.appendFormat(" / %d (split at %d)", axis.axisInfo.highAxis,
+                        axis.axisInfo.splitValue);
+            }
+        } else if (axis.axisInfo.mode == AxisInfo::MODE_INVERT) {
+            dump.append(" (invert)");
+        }
+
+        dump.appendFormat(": min=%0.5f, max=%0.5f, flat=%0.5f, fuzz=%0.5f, resolution=%0.5f\n",
+                axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution);
+        dump.appendFormat(INDENT4 "  scale=%0.5f, offset=%0.5f, "
+                "highScale=%0.5f, highOffset=%0.5f\n",
+                axis.scale, axis.offset, axis.highScale, axis.highOffset);
+        dump.appendFormat(INDENT4 "  rawAxis=%d, rawMin=%d, rawMax=%d, "
+                "rawFlat=%d, rawFuzz=%d, rawResolution=%d\n",
+                mAxes.keyAt(i), axis.rawAxisInfo.minValue, axis.rawAxisInfo.maxValue,
+                axis.rawAxisInfo.flat, axis.rawAxisInfo.fuzz, axis.rawAxisInfo.resolution);
+    }
+}
+
+void JoystickInputMapper::configure(nsecs_t when,
+        const InputReaderConfiguration* config, uint32_t changes) {
+    InputMapper::configure(when, config, changes);
+
+    if (!changes) { // first time only
+        // Collect all axes.
+        for (int32_t abs = 0; abs <= ABS_MAX; abs++) {
+            if (!(getAbsAxisUsage(abs, getDevice()->getClasses())
+                    & INPUT_DEVICE_CLASS_JOYSTICK)) {
+                continue; // axis must be claimed by a different device
+            }
+
+            RawAbsoluteAxisInfo rawAxisInfo;
+            getAbsoluteAxisInfo(abs, &rawAxisInfo);
+            if (rawAxisInfo.valid) {
+                // Map axis.
+                AxisInfo axisInfo;
+                bool explicitlyMapped = !getEventHub()->mapAxis(getDeviceId(), abs, &axisInfo);
+                if (!explicitlyMapped) {
+                    // Axis is not explicitly mapped, will choose a generic axis later.
+                    axisInfo.mode = AxisInfo::MODE_NORMAL;
+                    axisInfo.axis = -1;
+                }
+
+                // Apply flat override.
+                int32_t rawFlat = axisInfo.flatOverride < 0
+                        ? rawAxisInfo.flat : axisInfo.flatOverride;
+
+                // Calculate scaling factors and limits.
+                Axis axis;
+                if (axisInfo.mode == AxisInfo::MODE_SPLIT) {
+                    float scale = 1.0f / (axisInfo.splitValue - rawAxisInfo.minValue);
+                    float highScale = 1.0f / (rawAxisInfo.maxValue - axisInfo.splitValue);
+                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
+                            scale, 0.0f, highScale, 0.0f,
+                            0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale,
+                            rawAxisInfo.resolution * scale);
+                } else if (isCenteredAxis(axisInfo.axis)) {
+                    float scale = 2.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
+                    float offset = avg(rawAxisInfo.minValue, rawAxisInfo.maxValue) * -scale;
+                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
+                            scale, offset, scale, offset,
+                            -1.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale,
+                            rawAxisInfo.resolution * scale);
+                } else {
+                    float scale = 1.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
+                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
+                            scale, 0.0f, scale, 0.0f,
+                            0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale,
+                            rawAxisInfo.resolution * scale);
+                }
+
+                // To eliminate noise while the joystick is at rest, filter out small variations
+                // in axis values up front.
+                axis.filter = axis.flat * 0.25f;
+
+                mAxes.add(abs, axis);
+            }
+        }
+
+        // If there are too many axes, start dropping them.
+        // Prefer to keep explicitly mapped axes.
+        if (mAxes.size() > PointerCoords::MAX_AXES) {
+            ALOGI("Joystick '%s' has %d axes but the framework only supports a maximum of %d.",
+                    getDeviceName().string(), mAxes.size(), PointerCoords::MAX_AXES);
+            pruneAxes(true);
+            pruneAxes(false);
+        }
+
+        // Assign generic axis ids to remaining axes.
+        int32_t nextGenericAxisId = AMOTION_EVENT_AXIS_GENERIC_1;
+        size_t numAxes = mAxes.size();
+        for (size_t i = 0; i < numAxes; i++) {
+            Axis& axis = mAxes.editValueAt(i);
+            if (axis.axisInfo.axis < 0) {
+                while (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16
+                        && haveAxis(nextGenericAxisId)) {
+                    nextGenericAxisId += 1;
+                }
+
+                if (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16) {
+                    axis.axisInfo.axis = nextGenericAxisId;
+                    nextGenericAxisId += 1;
+                } else {
+                    ALOGI("Ignoring joystick '%s' axis %d because all of the generic axis ids "
+                            "have already been assigned to other axes.",
+                            getDeviceName().string(), mAxes.keyAt(i));
+                    mAxes.removeItemsAt(i--);
+                    numAxes -= 1;
+                }
+            }
+        }
+    }
+}
+
+bool JoystickInputMapper::haveAxis(int32_t axisId) {
+    size_t numAxes = mAxes.size();
+    for (size_t i = 0; i < numAxes; i++) {
+        const Axis& axis = mAxes.valueAt(i);
+        if (axis.axisInfo.axis == axisId
+                || (axis.axisInfo.mode == AxisInfo::MODE_SPLIT
+                        && axis.axisInfo.highAxis == axisId)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void JoystickInputMapper::pruneAxes(bool ignoreExplicitlyMappedAxes) {
+    size_t i = mAxes.size();
+    while (mAxes.size() > PointerCoords::MAX_AXES && i-- > 0) {
+        if (ignoreExplicitlyMappedAxes && mAxes.valueAt(i).explicitlyMapped) {
+            continue;
+        }
+        ALOGI("Discarding joystick '%s' axis %d because there are too many axes.",
+                getDeviceName().string(), mAxes.keyAt(i));
+        mAxes.removeItemsAt(i);
+    }
+}
+
+bool JoystickInputMapper::isCenteredAxis(int32_t axis) {
+    switch (axis) {
+    case AMOTION_EVENT_AXIS_X:
+    case AMOTION_EVENT_AXIS_Y:
+    case AMOTION_EVENT_AXIS_Z:
+    case AMOTION_EVENT_AXIS_RX:
+    case AMOTION_EVENT_AXIS_RY:
+    case AMOTION_EVENT_AXIS_RZ:
+    case AMOTION_EVENT_AXIS_HAT_X:
+    case AMOTION_EVENT_AXIS_HAT_Y:
+    case AMOTION_EVENT_AXIS_ORIENTATION:
+    case AMOTION_EVENT_AXIS_RUDDER:
+    case AMOTION_EVENT_AXIS_WHEEL:
+        return true;
+    default:
+        return false;
+    }
+}
+
+void JoystickInputMapper::reset(nsecs_t when) {
+    // Recenter all axes.
+    size_t numAxes = mAxes.size();
+    for (size_t i = 0; i < numAxes; i++) {
+        Axis& axis = mAxes.editValueAt(i);
+        axis.resetValue();
+    }
+
+    InputMapper::reset(when);
+}
+
+void JoystickInputMapper::process(const RawEvent* rawEvent) {
+    switch (rawEvent->type) {
+    case EV_ABS: {
+        ssize_t index = mAxes.indexOfKey(rawEvent->code);
+        if (index >= 0) {
+            Axis& axis = mAxes.editValueAt(index);
+            float newValue, highNewValue;
+            switch (axis.axisInfo.mode) {
+            case AxisInfo::MODE_INVERT:
+                newValue = (axis.rawAxisInfo.maxValue - rawEvent->value)
+                        * axis.scale + axis.offset;
+                highNewValue = 0.0f;
+                break;
+            case AxisInfo::MODE_SPLIT:
+                if (rawEvent->value < axis.axisInfo.splitValue) {
+                    newValue = (axis.axisInfo.splitValue - rawEvent->value)
+                            * axis.scale + axis.offset;
+                    highNewValue = 0.0f;
+                } else if (rawEvent->value > axis.axisInfo.splitValue) {
+                    newValue = 0.0f;
+                    highNewValue = (rawEvent->value - axis.axisInfo.splitValue)
+                            * axis.highScale + axis.highOffset;
+                } else {
+                    newValue = 0.0f;
+                    highNewValue = 0.0f;
+                }
+                break;
+            default:
+                newValue = rawEvent->value * axis.scale + axis.offset;
+                highNewValue = 0.0f;
+                break;
+            }
+            axis.newValue = newValue;
+            axis.highNewValue = highNewValue;
+        }
+        break;
+    }
+
+    case EV_SYN:
+        switch (rawEvent->code) {
+        case SYN_REPORT:
+            sync(rawEvent->when, false /*force*/);
+            break;
+        }
+        break;
+    }
+}
+
+void JoystickInputMapper::sync(nsecs_t when, bool force) {
+    if (!filterAxes(force)) {
+        return;
+    }
+
+    int32_t metaState = mContext->getGlobalMetaState();
+    int32_t buttonState = 0;
+
+    PointerProperties pointerProperties;
+    pointerProperties.clear();
+    pointerProperties.id = 0;
+    pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
+
+    PointerCoords pointerCoords;
+    pointerCoords.clear();
+
+    size_t numAxes = mAxes.size();
+    for (size_t i = 0; i < numAxes; i++) {
+        const Axis& axis = mAxes.valueAt(i);
+        setPointerCoordsAxisValue(&pointerCoords, axis.axisInfo.axis, axis.currentValue);
+        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
+            setPointerCoordsAxisValue(&pointerCoords, axis.axisInfo.highAxis,
+                    axis.highCurrentValue);
+        }
+    }
+
+    // Moving a joystick axis should not wake the device because joysticks can
+    // be fairly noisy even when not in use.  On the other hand, pushing a gamepad
+    // button will likely wake the device.
+    // TODO: Use the input device configuration to control this behavior more finely.
+    uint32_t policyFlags = 0;
+
+    NotifyMotionArgs args(when, getDeviceId(), AINPUT_SOURCE_JOYSTICK, policyFlags,
+            AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
+            ADISPLAY_ID_NONE, 1, &pointerProperties, &pointerCoords, 0, 0, 0);
+    getListener()->notifyMotion(&args);
+}
+
+void JoystickInputMapper::setPointerCoordsAxisValue(PointerCoords* pointerCoords,
+        int32_t axis, float value) {
+    pointerCoords->setAxisValue(axis, value);
+    /* In order to ease the transition for developers from using the old axes
+     * to the newer, more semantically correct axes, we'll continue to produce
+     * values for the old axes as mirrors of the value of their corresponding
+     * new axes. */
+    int32_t compatAxis = getCompatAxis(axis);
+    if (compatAxis >= 0) {
+        pointerCoords->setAxisValue(compatAxis, value);
+    }
+}
+
+bool JoystickInputMapper::filterAxes(bool force) {
+    bool atLeastOneSignificantChange = force;
+    size_t numAxes = mAxes.size();
+    for (size_t i = 0; i < numAxes; i++) {
+        Axis& axis = mAxes.editValueAt(i);
+        if (force || hasValueChangedSignificantly(axis.filter,
+                axis.newValue, axis.currentValue, axis.min, axis.max)) {
+            axis.currentValue = axis.newValue;
+            atLeastOneSignificantChange = true;
+        }
+        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
+            if (force || hasValueChangedSignificantly(axis.filter,
+                    axis.highNewValue, axis.highCurrentValue, axis.min, axis.max)) {
+                axis.highCurrentValue = axis.highNewValue;
+                atLeastOneSignificantChange = true;
+            }
+        }
+    }
+    return atLeastOneSignificantChange;
+}
+
+bool JoystickInputMapper::hasValueChangedSignificantly(
+        float filter, float newValue, float currentValue, float min, float max) {
+    if (newValue != currentValue) {
+        // Filter out small changes in value unless the value is converging on the axis
+        // bounds or center point.  This is intended to reduce the amount of information
+        // sent to applications by particularly noisy joysticks (such as PS3).
+        if (fabs(newValue - currentValue) > filter
+                || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, min)
+                || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, max)
+                || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, 0)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool JoystickInputMapper::hasMovedNearerToValueWithinFilteredRange(
+        float filter, float newValue, float currentValue, float thresholdValue) {
+    float newDistance = fabs(newValue - thresholdValue);
+    if (newDistance < filter) {
+        float oldDistance = fabs(currentValue - thresholdValue);
+        if (newDistance < oldDistance) {
+            return true;
+        }
+    }
+    return false;
+}
+
+} // namespace android
diff --git a/libs/input/InputReader.h b/libs/input/InputReader.h
new file mode 100644
index 0000000..6b5ce34
--- /dev/null
+++ b/libs/input/InputReader.h
@@ -0,0 +1,1819 @@
+/*
+ * Copyright (C) 2010 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 _UI_INPUT_READER_H
+#define _UI_INPUT_READER_H
+
+#include "EventHub.h"
+#include "PointerController.h"
+#include "InputListener.h"
+
+#include <input/Input.h>
+#include <input/VelocityControl.h>
+#include <input/VelocityTracker.h>
+#include <utils/KeyedVector.h>
+#include <utils/threads.h>
+#include <utils/Timers.h>
+#include <utils/RefBase.h>
+#include <utils/String8.h>
+#include <utils/BitSet.h>
+
+#include <stddef.h>
+#include <unistd.h>
+
+// Maximum supported size of a vibration pattern.
+// Must be at least 2.
+#define MAX_VIBRATE_PATTERN_SIZE 100
+
+// Maximum allowable delay value in a vibration pattern before
+// which the delay will be truncated.
+#define MAX_VIBRATE_PATTERN_DELAY_NSECS (1000000 * 1000000000LL)
+
+namespace android {
+
+class InputDevice;
+class InputMapper;
+
+/*
+ * Describes how coordinates are mapped on a physical display.
+ * See com.android.server.display.DisplayViewport.
+ */
+struct DisplayViewport {
+    int32_t displayId; // -1 if invalid
+    int32_t orientation;
+    int32_t logicalLeft;
+    int32_t logicalTop;
+    int32_t logicalRight;
+    int32_t logicalBottom;
+    int32_t physicalLeft;
+    int32_t physicalTop;
+    int32_t physicalRight;
+    int32_t physicalBottom;
+    int32_t deviceWidth;
+    int32_t deviceHeight;
+
+    DisplayViewport() :
+            displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
+            logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
+            physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
+            deviceWidth(0), deviceHeight(0) {
+    }
+
+    bool operator==(const DisplayViewport& other) const {
+        return displayId == other.displayId
+                && orientation == other.orientation
+                && logicalLeft == other.logicalLeft
+                && logicalTop == other.logicalTop
+                && logicalRight == other.logicalRight
+                && logicalBottom == other.logicalBottom
+                && physicalLeft == other.physicalLeft
+                && physicalTop == other.physicalTop
+                && physicalRight == other.physicalRight
+                && physicalBottom == other.physicalBottom
+                && deviceWidth == other.deviceWidth
+                && deviceHeight == other.deviceHeight;
+    }
+
+    bool operator!=(const DisplayViewport& other) const {
+        return !(*this == other);
+    }
+
+    inline bool isValid() const {
+        return displayId >= 0;
+    }
+
+    void setNonDisplayViewport(int32_t width, int32_t height) {
+        displayId = ADISPLAY_ID_NONE;
+        orientation = DISPLAY_ORIENTATION_0;
+        logicalLeft = 0;
+        logicalTop = 0;
+        logicalRight = width;
+        logicalBottom = height;
+        physicalLeft = 0;
+        physicalTop = 0;
+        physicalRight = width;
+        physicalBottom = height;
+        deviceWidth = width;
+        deviceHeight = height;
+    }
+};
+
+/*
+ * Input reader configuration.
+ *
+ * Specifies various options that modify the behavior of the input reader.
+ */
+struct InputReaderConfiguration {
+    // Describes changes that have occurred.
+    enum {
+        // The pointer speed changed.
+        CHANGE_POINTER_SPEED = 1 << 0,
+
+        // The pointer gesture control changed.
+        CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
+
+        // The display size or orientation changed.
+        CHANGE_DISPLAY_INFO = 1 << 2,
+
+        // The visible touches option changed.
+        CHANGE_SHOW_TOUCHES = 1 << 3,
+
+        // The keyboard layouts must be reloaded.
+        CHANGE_KEYBOARD_LAYOUTS = 1 << 4,
+
+        // The device name alias supplied by the may have changed for some devices.
+        CHANGE_DEVICE_ALIAS = 1 << 5,
+
+        // All devices must be reopened.
+        CHANGE_MUST_REOPEN = 1 << 31,
+    };
+
+    // Gets the amount of time to disable virtual keys after the screen is touched
+    // in order to filter out accidental virtual key presses due to swiping gestures
+    // or taps near the edge of the display.  May be 0 to disable the feature.
+    nsecs_t virtualKeyQuietTime;
+
+    // The excluded device names for the platform.
+    // Devices with these names will be ignored.
+    Vector<String8> excludedDeviceNames;
+
+    // Velocity control parameters for mouse pointer movements.
+    VelocityControlParameters pointerVelocityControlParameters;
+
+    // Velocity control parameters for mouse wheel movements.
+    VelocityControlParameters wheelVelocityControlParameters;
+
+    // True if pointer gestures are enabled.
+    bool pointerGesturesEnabled;
+
+    // Quiet time between certain pointer gesture transitions.
+    // Time to allow for all fingers or buttons to settle into a stable state before
+    // starting a new gesture.
+    nsecs_t pointerGestureQuietInterval;
+
+    // The minimum speed that a pointer must travel for us to consider switching the active
+    // touch pointer to it during a drag.  This threshold is set to avoid switching due
+    // to noise from a finger resting on the touch pad (perhaps just pressing it down).
+    float pointerGestureDragMinSwitchSpeed; // in pixels per second
+
+    // Tap gesture delay time.
+    // The time between down and up must be less than this to be considered a tap.
+    nsecs_t pointerGestureTapInterval;
+
+    // Tap drag gesture delay time.
+    // The time between the previous tap's up and the next down must be less than
+    // this to be considered a drag.  Otherwise, the previous tap is finished and a
+    // new tap begins.
+    //
+    // Note that the previous tap will be held down for this entire duration so this
+    // interval must be shorter than the long press timeout.
+    nsecs_t pointerGestureTapDragInterval;
+
+    // The distance in pixels that the pointer is allowed to move from initial down
+    // to up and still be called a tap.
+    float pointerGestureTapSlop; // in pixels
+
+    // Time after the first touch points go down to settle on an initial centroid.
+    // This is intended to be enough time to handle cases where the user puts down two
+    // fingers at almost but not quite exactly the same time.
+    nsecs_t pointerGestureMultitouchSettleInterval;
+
+    // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
+    // at least two pointers have moved at least this far from their starting place.
+    float pointerGestureMultitouchMinDistance; // in pixels
+
+    // The transition from PRESS to SWIPE gesture mode can only occur when the
+    // cosine of the angle between the two vectors is greater than or equal to than this value
+    // which indicates that the vectors are oriented in the same direction.
+    // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
+    // (In exactly opposite directions, the cosine is -1.0.)
+    float pointerGestureSwipeTransitionAngleCosine;
+
+    // The transition from PRESS to SWIPE gesture mode can only occur when the
+    // fingers are no more than this far apart relative to the diagonal size of
+    // the touch pad.  For example, a ratio of 0.5 means that the fingers must be
+    // no more than half the diagonal size of the touch pad apart.
+    float pointerGestureSwipeMaxWidthRatio;
+
+    // The gesture movement speed factor relative to the size of the display.
+    // Movement speed applies when the fingers are moving in the same direction.
+    // Without acceleration, a full swipe of the touch pad diagonal in movement mode
+    // will cover this portion of the display diagonal.
+    float pointerGestureMovementSpeedRatio;
+
+    // The gesture zoom speed factor relative to the size of the display.
+    // Zoom speed applies when the fingers are mostly moving relative to each other
+    // to execute a scale gesture or similar.
+    // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
+    // will cover this portion of the display diagonal.
+    float pointerGestureZoomSpeedRatio;
+
+    // True to show the location of touches on the touch screen as spots.
+    bool showTouches;
+
+    InputReaderConfiguration() :
+            virtualKeyQuietTime(0),
+            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
+            wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
+            pointerGesturesEnabled(true),
+            pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
+            pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
+            pointerGestureTapInterval(150 * 1000000LL), // 150 ms
+            pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
+            pointerGestureTapSlop(10.0f), // 10 pixels
+            pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
+            pointerGestureMultitouchMinDistance(15), // 15 pixels
+            pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
+            pointerGestureSwipeMaxWidthRatio(0.25f),
+            pointerGestureMovementSpeedRatio(0.8f),
+            pointerGestureZoomSpeedRatio(0.3f),
+            showTouches(false) { }
+
+    bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
+    void setDisplayInfo(bool external, const DisplayViewport& viewport);
+
+private:
+    DisplayViewport mInternalDisplay;
+    DisplayViewport mExternalDisplay;
+};
+
+
+/*
+ * Input reader policy interface.
+ *
+ * The input reader policy is used by the input reader to interact with the Window Manager
+ * and other system components.
+ *
+ * The actual implementation is partially supported by callbacks into the DVM
+ * via JNI.  This interface is also mocked in the unit tests.
+ *
+ * These methods must NOT re-enter the input reader since they may be called while
+ * holding the input reader lock.
+ */
+class InputReaderPolicyInterface : public virtual RefBase {
+protected:
+    InputReaderPolicyInterface() { }
+    virtual ~InputReaderPolicyInterface() { }
+
+public:
+    /* Gets the input reader configuration. */
+    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
+
+    /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
+    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
+
+    /* Notifies the input reader policy that some input devices have changed
+     * and provides information about all current input devices.
+     */
+    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) = 0;
+
+    /* Gets the keyboard layout for a particular input device. */
+    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(
+            const InputDeviceIdentifier& identifier) = 0;
+
+    /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
+    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
+};
+
+
+/* Processes raw input events and sends cooked event data to an input listener. */
+class InputReaderInterface : public virtual RefBase {
+protected:
+    InputReaderInterface() { }
+    virtual ~InputReaderInterface() { }
+
+public:
+    /* Dumps the state of the input reader.
+     *
+     * This method may be called on any thread (usually by the input manager). */
+    virtual void dump(String8& dump) = 0;
+
+    /* Called by the heatbeat to ensures that the reader has not deadlocked. */
+    virtual void monitor() = 0;
+
+    /* Runs a single iteration of the processing loop.
+     * Nominally reads and processes one incoming message from the EventHub.
+     *
+     * This method should be called on the input reader thread.
+     */
+    virtual void loopOnce() = 0;
+
+    /* Gets information about all input devices.
+     *
+     * This method may be called on any thread (usually by the input manager).
+     */
+    virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0;
+
+    /* Query current input state. */
+    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
+            int32_t scanCode) = 0;
+    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
+            int32_t keyCode) = 0;
+    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
+            int32_t sw) = 0;
+
+    /* Determine whether physical keys exist for the given framework-domain key codes. */
+    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
+            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
+
+    /* Requests that a reconfiguration of all input devices.
+     * The changes flag is a bitfield that indicates what has changed and whether
+     * the input devices must all be reopened. */
+    virtual void requestRefreshConfiguration(uint32_t changes) = 0;
+
+    /* Controls the vibrator of a particular input device. */
+    virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
+            ssize_t repeat, int32_t token) = 0;
+    virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
+};
+
+
+/* Internal interface used by individual input devices to access global input device state
+ * and parameters maintained by the input reader.
+ */
+class InputReaderContext {
+public:
+    InputReaderContext() { }
+    virtual ~InputReaderContext() { }
+
+    virtual void updateGlobalMetaState() = 0;
+    virtual int32_t getGlobalMetaState() = 0;
+
+    virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
+    virtual bool shouldDropVirtualKey(nsecs_t now,
+            InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
+
+    virtual void fadePointer() = 0;
+
+    virtual void requestTimeoutAtTime(nsecs_t when) = 0;
+    virtual int32_t bumpGeneration() = 0;
+
+    virtual InputReaderPolicyInterface* getPolicy() = 0;
+    virtual InputListenerInterface* getListener() = 0;
+    virtual EventHubInterface* getEventHub() = 0;
+};
+
+
+/* The input reader reads raw event data from the event hub and processes it into input events
+ * that it sends to the input listener.  Some functions of the input reader, such as early
+ * event filtering in low power states, are controlled by a separate policy object.
+ *
+ * The InputReader owns a collection of InputMappers.  Most of the work it does happens
+ * on the input reader thread but the InputReader can receive queries from other system
+ * components running on arbitrary threads.  To keep things manageable, the InputReader
+ * uses a single Mutex to guard its state.  The Mutex may be held while calling into the
+ * EventHub or the InputReaderPolicy but it is never held while calling into the
+ * InputListener.
+ */
+class InputReader : public InputReaderInterface {
+public:
+    InputReader(const sp<EventHubInterface>& eventHub,
+            const sp<InputReaderPolicyInterface>& policy,
+            const sp<InputListenerInterface>& listener);
+    virtual ~InputReader();
+
+    virtual void dump(String8& dump);
+    virtual void monitor();
+
+    virtual void loopOnce();
+
+    virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices);
+
+    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
+            int32_t scanCode);
+    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
+            int32_t keyCode);
+    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
+            int32_t sw);
+
+    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
+            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
+
+    virtual void requestRefreshConfiguration(uint32_t changes);
+
+    virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
+            ssize_t repeat, int32_t token);
+    virtual void cancelVibrate(int32_t deviceId, int32_t token);
+
+protected:
+    // These members are protected so they can be instrumented by test cases.
+    virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
+            const InputDeviceIdentifier& identifier, uint32_t classes);
+
+    class ContextImpl : public InputReaderContext {
+        InputReader* mReader;
+
+    public:
+        ContextImpl(InputReader* reader);
+
+        virtual void updateGlobalMetaState();
+        virtual int32_t getGlobalMetaState();
+        virtual void disableVirtualKeysUntil(nsecs_t time);
+        virtual bool shouldDropVirtualKey(nsecs_t now,
+                InputDevice* device, int32_t keyCode, int32_t scanCode);
+        virtual void fadePointer();
+        virtual void requestTimeoutAtTime(nsecs_t when);
+        virtual int32_t bumpGeneration();
+        virtual InputReaderPolicyInterface* getPolicy();
+        virtual InputListenerInterface* getListener();
+        virtual EventHubInterface* getEventHub();
+    } mContext;
+
+    friend class ContextImpl;
+
+private:
+    Mutex mLock;
+
+    Condition mReaderIsAliveCondition;
+
+    sp<EventHubInterface> mEventHub;
+    sp<InputReaderPolicyInterface> mPolicy;
+    sp<QueuedInputListener> mQueuedListener;
+
+    InputReaderConfiguration mConfig;
+
+    // The event queue.
+    static const int EVENT_BUFFER_SIZE = 256;
+    RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
+
+    KeyedVector<int32_t, InputDevice*> mDevices;
+
+    // low-level input event decoding and device management
+    void processEventsLocked(const RawEvent* rawEvents, size_t count);
+
+    void addDeviceLocked(nsecs_t when, int32_t deviceId);
+    void removeDeviceLocked(nsecs_t when, int32_t deviceId);
+    void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
+    void timeoutExpiredLocked(nsecs_t when);
+
+    void handleConfigurationChangedLocked(nsecs_t when);
+
+    int32_t mGlobalMetaState;
+    void updateGlobalMetaStateLocked();
+    int32_t getGlobalMetaStateLocked();
+
+    void fadePointerLocked();
+
+    int32_t mGeneration;
+    int32_t bumpGenerationLocked();
+
+    void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices);
+
+    nsecs_t mDisableVirtualKeysTimeout;
+    void disableVirtualKeysUntilLocked(nsecs_t time);
+    bool shouldDropVirtualKeyLocked(nsecs_t now,
+            InputDevice* device, int32_t keyCode, int32_t scanCode);
+
+    nsecs_t mNextTimeout;
+    void requestTimeoutAtTimeLocked(nsecs_t when);
+
+    uint32_t mConfigurationChangesToRefresh;
+    void refreshConfigurationLocked(uint32_t changes);
+
+    // state queries
+    typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
+    int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
+            GetStateFunc getStateFunc);
+    bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags);
+};
+
+
+/* Reads raw events from the event hub and processes them, endlessly. */
+class InputReaderThread : public Thread {
+public:
+    InputReaderThread(const sp<InputReaderInterface>& reader);
+    virtual ~InputReaderThread();
+
+private:
+    sp<InputReaderInterface> mReader;
+
+    virtual bool threadLoop();
+};
+
+
+/* Represents the state of a single input device. */
+class InputDevice {
+public:
+    InputDevice(InputReaderContext* context, int32_t id, int32_t generation, int32_t
+            controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes);
+    ~InputDevice();
+
+    inline InputReaderContext* getContext() { return mContext; }
+    inline int32_t getId() const { return mId; }
+    inline int32_t getControllerNumber() const { return mControllerNumber; }
+    inline int32_t getGeneration() const { return mGeneration; }
+    inline const String8& getName() const { return mIdentifier.name; }
+    inline uint32_t getClasses() const { return mClasses; }
+    inline uint32_t getSources() const { return mSources; }
+
+    inline bool isExternal() { return mIsExternal; }
+    inline void setExternal(bool external) { mIsExternal = external; }
+
+    inline bool isIgnored() { return mMappers.isEmpty(); }
+
+    void dump(String8& dump);
+    void addMapper(InputMapper* mapper);
+    void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
+    void reset(nsecs_t when);
+    void process(const RawEvent* rawEvents, size_t count);
+    void timeoutExpired(nsecs_t when);
+
+    void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
+    int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
+    int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
+    int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
+    bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags);
+    void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
+    void cancelVibrate(int32_t token);
+
+    int32_t getMetaState();
+
+    void fadePointer();
+
+    void bumpGeneration();
+
+    void notifyReset(nsecs_t when);
+
+    inline const PropertyMap& getConfiguration() { return mConfiguration; }
+    inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
+
+    bool hasKey(int32_t code) {
+        return getEventHub()->hasScanCode(mId, code);
+    }
+
+    bool hasAbsoluteAxis(int32_t code) {
+        RawAbsoluteAxisInfo info;
+        getEventHub()->getAbsoluteAxisInfo(mId, code, &info);
+        return info.valid;
+    }
+
+    bool isKeyPressed(int32_t code) {
+        return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
+    }
+
+    int32_t getAbsoluteAxisValue(int32_t code) {
+        int32_t value;
+        getEventHub()->getAbsoluteAxisValue(mId, code, &value);
+        return value;
+    }
+
+private:
+    InputReaderContext* mContext;
+    int32_t mId;
+    int32_t mControllerNumber;
+    int32_t mGeneration;
+    InputDeviceIdentifier mIdentifier;
+    String8 mAlias;
+    uint32_t mClasses;
+
+    Vector<InputMapper*> mMappers;
+
+    uint32_t mSources;
+    bool mIsExternal;
+    bool mDropUntilNextSync;
+
+    typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
+    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
+
+    PropertyMap mConfiguration;
+};
+
+
+/* Keeps track of the state of mouse or touch pad buttons. */
+class CursorButtonAccumulator {
+public:
+    CursorButtonAccumulator();
+    void reset(InputDevice* device);
+
+    void process(const RawEvent* rawEvent);
+
+    uint32_t getButtonState() const;
+
+private:
+    bool mBtnLeft;
+    bool mBtnRight;
+    bool mBtnMiddle;
+    bool mBtnBack;
+    bool mBtnSide;
+    bool mBtnForward;
+    bool mBtnExtra;
+    bool mBtnTask;
+
+    void clearButtons();
+};
+
+
+/* Keeps track of cursor movements. */
+
+class CursorMotionAccumulator {
+public:
+    CursorMotionAccumulator();
+    void reset(InputDevice* device);
+
+    void process(const RawEvent* rawEvent);
+    void finishSync();
+
+    inline int32_t getRelativeX() const { return mRelX; }
+    inline int32_t getRelativeY() const { return mRelY; }
+
+private:
+    int32_t mRelX;
+    int32_t mRelY;
+
+    void clearRelativeAxes();
+};
+
+
+/* Keeps track of cursor scrolling motions. */
+
+class CursorScrollAccumulator {
+public:
+    CursorScrollAccumulator();
+    void configure(InputDevice* device);
+    void reset(InputDevice* device);
+
+    void process(const RawEvent* rawEvent);
+    void finishSync();
+
+    inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
+    inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
+
+    inline int32_t getRelativeX() const { return mRelX; }
+    inline int32_t getRelativeY() const { return mRelY; }
+    inline int32_t getRelativeVWheel() const { return mRelWheel; }
+    inline int32_t getRelativeHWheel() const { return mRelHWheel; }
+
+private:
+    bool mHaveRelWheel;
+    bool mHaveRelHWheel;
+
+    int32_t mRelX;
+    int32_t mRelY;
+    int32_t mRelWheel;
+    int32_t mRelHWheel;
+
+    void clearRelativeAxes();
+};
+
+
+/* Keeps track of the state of touch, stylus and tool buttons. */
+class TouchButtonAccumulator {
+public:
+    TouchButtonAccumulator();
+    void configure(InputDevice* device);
+    void reset(InputDevice* device);
+
+    void process(const RawEvent* rawEvent);
+
+    uint32_t getButtonState() const;
+    int32_t getToolType() const;
+    bool isToolActive() const;
+    bool isHovering() const;
+    bool hasStylus() const;
+
+private:
+    bool mHaveBtnTouch;
+    bool mHaveStylus;
+
+    bool mBtnTouch;
+    bool mBtnStylus;
+    bool mBtnStylus2;
+    bool mBtnToolFinger;
+    bool mBtnToolPen;
+    bool mBtnToolRubber;
+    bool mBtnToolBrush;
+    bool mBtnToolPencil;
+    bool mBtnToolAirbrush;
+    bool mBtnToolMouse;
+    bool mBtnToolLens;
+    bool mBtnToolDoubleTap;
+    bool mBtnToolTripleTap;
+    bool mBtnToolQuadTap;
+
+    void clearButtons();
+};
+
+
+/* Raw axis information from the driver. */
+struct RawPointerAxes {
+    RawAbsoluteAxisInfo x;
+    RawAbsoluteAxisInfo y;
+    RawAbsoluteAxisInfo pressure;
+    RawAbsoluteAxisInfo touchMajor;
+    RawAbsoluteAxisInfo touchMinor;
+    RawAbsoluteAxisInfo toolMajor;
+    RawAbsoluteAxisInfo toolMinor;
+    RawAbsoluteAxisInfo orientation;
+    RawAbsoluteAxisInfo distance;
+    RawAbsoluteAxisInfo tiltX;
+    RawAbsoluteAxisInfo tiltY;
+    RawAbsoluteAxisInfo trackingId;
+    RawAbsoluteAxisInfo slot;
+
+    RawPointerAxes();
+    void clear();
+};
+
+
+/* Raw data for a collection of pointers including a pointer id mapping table. */
+struct RawPointerData {
+    struct Pointer {
+        uint32_t id;
+        int32_t x;
+        int32_t y;
+        int32_t pressure;
+        int32_t touchMajor;
+        int32_t touchMinor;
+        int32_t toolMajor;
+        int32_t toolMinor;
+        int32_t orientation;
+        int32_t distance;
+        int32_t tiltX;
+        int32_t tiltY;
+        int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
+        bool isHovering;
+    };
+
+    uint32_t pointerCount;
+    Pointer pointers[MAX_POINTERS];
+    BitSet32 hoveringIdBits, touchingIdBits;
+    uint32_t idToIndex[MAX_POINTER_ID + 1];
+
+    RawPointerData();
+    void clear();
+    void copyFrom(const RawPointerData& other);
+    void getCentroidOfTouchingPointers(float* outX, float* outY) const;
+
+    inline void markIdBit(uint32_t id, bool isHovering) {
+        if (isHovering) {
+            hoveringIdBits.markBit(id);
+        } else {
+            touchingIdBits.markBit(id);
+        }
+    }
+
+    inline void clearIdBits() {
+        hoveringIdBits.clear();
+        touchingIdBits.clear();
+    }
+
+    inline const Pointer& pointerForId(uint32_t id) const {
+        return pointers[idToIndex[id]];
+    }
+
+    inline bool isHovering(uint32_t pointerIndex) {
+        return pointers[pointerIndex].isHovering;
+    }
+};
+
+
+/* Cooked data for a collection of pointers including a pointer id mapping table. */
+struct CookedPointerData {
+    uint32_t pointerCount;
+    PointerProperties pointerProperties[MAX_POINTERS];
+    PointerCoords pointerCoords[MAX_POINTERS];
+    BitSet32 hoveringIdBits, touchingIdBits;
+    uint32_t idToIndex[MAX_POINTER_ID + 1];
+
+    CookedPointerData();
+    void clear();
+    void copyFrom(const CookedPointerData& other);
+
+    inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
+        return pointerCoords[idToIndex[id]];
+    }
+
+    inline bool isHovering(uint32_t pointerIndex) {
+        return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
+    }
+};
+
+
+/* Keeps track of the state of single-touch protocol. */
+class SingleTouchMotionAccumulator {
+public:
+    SingleTouchMotionAccumulator();
+
+    void process(const RawEvent* rawEvent);
+    void reset(InputDevice* device);
+
+    inline int32_t getAbsoluteX() const { return mAbsX; }
+    inline int32_t getAbsoluteY() const { return mAbsY; }
+    inline int32_t getAbsolutePressure() const { return mAbsPressure; }
+    inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
+    inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
+    inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
+    inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
+
+private:
+    int32_t mAbsX;
+    int32_t mAbsY;
+    int32_t mAbsPressure;
+    int32_t mAbsToolWidth;
+    int32_t mAbsDistance;
+    int32_t mAbsTiltX;
+    int32_t mAbsTiltY;
+
+    void clearAbsoluteAxes();
+};
+
+
+/* Keeps track of the state of multi-touch protocol. */
+class MultiTouchMotionAccumulator {
+public:
+    class Slot {
+    public:
+        inline bool isInUse() const { return mInUse; }
+        inline int32_t getX() const { return mAbsMTPositionX; }
+        inline int32_t getY() const { return mAbsMTPositionY; }
+        inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
+        inline int32_t getTouchMinor() const {
+            return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; }
+        inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
+        inline int32_t getToolMinor() const {
+            return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; }
+        inline int32_t getOrientation() const { return mAbsMTOrientation; }
+        inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
+        inline int32_t getPressure() const { return mAbsMTPressure; }
+        inline int32_t getDistance() const { return mAbsMTDistance; }
+        inline int32_t getToolType() const;
+
+    private:
+        friend class MultiTouchMotionAccumulator;
+
+        bool mInUse;
+        bool mHaveAbsMTTouchMinor;
+        bool mHaveAbsMTWidthMinor;
+        bool mHaveAbsMTToolType;
+
+        int32_t mAbsMTPositionX;
+        int32_t mAbsMTPositionY;
+        int32_t mAbsMTTouchMajor;
+        int32_t mAbsMTTouchMinor;
+        int32_t mAbsMTWidthMajor;
+        int32_t mAbsMTWidthMinor;
+        int32_t mAbsMTOrientation;
+        int32_t mAbsMTTrackingId;
+        int32_t mAbsMTPressure;
+        int32_t mAbsMTDistance;
+        int32_t mAbsMTToolType;
+
+        Slot();
+        void clear();
+    };
+
+    MultiTouchMotionAccumulator();
+    ~MultiTouchMotionAccumulator();
+
+    void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol);
+    void reset(InputDevice* device);
+    void process(const RawEvent* rawEvent);
+    void finishSync();
+    bool hasStylus() const;
+
+    inline size_t getSlotCount() const { return mSlotCount; }
+    inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
+
+private:
+    int32_t mCurrentSlot;
+    Slot* mSlots;
+    size_t mSlotCount;
+    bool mUsingSlotsProtocol;
+    bool mHaveStylus;
+
+    void clearSlots(int32_t initialSlot);
+};
+
+
+/* An input mapper transforms raw input events into cooked event data.
+ * A single input device can have multiple associated input mappers in order to interpret
+ * different classes of events.
+ *
+ * InputMapper lifecycle:
+ * - create
+ * - configure with 0 changes
+ * - reset
+ * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
+ * - reset
+ * - destroy
+ */
+class InputMapper {
+public:
+    InputMapper(InputDevice* device);
+    virtual ~InputMapper();
+
+    inline InputDevice* getDevice() { return mDevice; }
+    inline int32_t getDeviceId() { return mDevice->getId(); }
+    inline const String8 getDeviceName() { return mDevice->getName(); }
+    inline InputReaderContext* getContext() { return mContext; }
+    inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
+    inline InputListenerInterface* getListener() { return mContext->getListener(); }
+    inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
+
+    virtual uint32_t getSources() = 0;
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
+    virtual void dump(String8& dump);
+    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent) = 0;
+    virtual void timeoutExpired(nsecs_t when);
+
+    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
+    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
+    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
+    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags);
+    virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
+            int32_t token);
+    virtual void cancelVibrate(int32_t token);
+
+    virtual int32_t getMetaState();
+
+    virtual void fadePointer();
+
+protected:
+    InputDevice* mDevice;
+    InputReaderContext* mContext;
+
+    status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
+    void bumpGeneration();
+
+    static void dumpRawAbsoluteAxisInfo(String8& dump,
+            const RawAbsoluteAxisInfo& axis, const char* name);
+};
+
+
+class SwitchInputMapper : public InputMapper {
+public:
+    SwitchInputMapper(InputDevice* device);
+    virtual ~SwitchInputMapper();
+
+    virtual uint32_t getSources();
+    virtual void process(const RawEvent* rawEvent);
+
+    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
+
+private:
+    uint32_t mUpdatedSwitchValues;
+    uint32_t mUpdatedSwitchMask;
+
+    void processSwitch(int32_t switchCode, int32_t switchValue);
+    void sync(nsecs_t when);
+};
+
+
+class VibratorInputMapper : public InputMapper {
+public:
+    VibratorInputMapper(InputDevice* device);
+    virtual ~VibratorInputMapper();
+
+    virtual uint32_t getSources();
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
+    virtual void process(const RawEvent* rawEvent);
+
+    virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
+            int32_t token);
+    virtual void cancelVibrate(int32_t token);
+    virtual void timeoutExpired(nsecs_t when);
+    virtual void dump(String8& dump);
+
+private:
+    bool mVibrating;
+    nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE];
+    size_t mPatternSize;
+    ssize_t mRepeat;
+    int32_t mToken;
+    ssize_t mIndex;
+    nsecs_t mNextStepTime;
+
+    void nextStep();
+    void stopVibrating();
+};
+
+
+class KeyboardInputMapper : public InputMapper {
+public:
+    KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
+    virtual ~KeyboardInputMapper();
+
+    virtual uint32_t getSources();
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
+    virtual void dump(String8& dump);
+    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent);
+
+    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
+    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
+    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags);
+
+    virtual int32_t getMetaState();
+
+private:
+    struct KeyDown {
+        int32_t keyCode;
+        int32_t scanCode;
+    };
+
+    uint32_t mSource;
+    int32_t mKeyboardType;
+
+    int32_t mOrientation; // orientation for dpad keys
+
+    Vector<KeyDown> mKeyDowns; // keys that are down
+    int32_t mMetaState;
+    nsecs_t mDownTime; // time of most recent key down
+
+    int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
+
+    struct LedState {
+        bool avail; // led is available
+        bool on;    // we think the led is currently on
+    };
+    LedState mCapsLockLedState;
+    LedState mNumLockLedState;
+    LedState mScrollLockLedState;
+
+    // Immutable configuration parameters.
+    struct Parameters {
+        bool hasAssociatedDisplay;
+        bool orientationAware;
+    } mParameters;
+
+    void configureParameters();
+    void dumpParameters(String8& dump);
+
+    bool isKeyboardOrGamepadKey(int32_t scanCode);
+
+    void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
+            uint32_t policyFlags);
+
+    ssize_t findKeyDown(int32_t scanCode);
+
+    void resetLedState();
+    void initializeLedState(LedState& ledState, int32_t led);
+    void updateLedState(bool reset);
+    void updateLedStateForModifier(LedState& ledState, int32_t led,
+            int32_t modifier, bool reset);
+};
+
+
+class CursorInputMapper : public InputMapper {
+public:
+    CursorInputMapper(InputDevice* device);
+    virtual ~CursorInputMapper();
+
+    virtual uint32_t getSources();
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
+    virtual void dump(String8& dump);
+    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent);
+
+    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
+
+    virtual void fadePointer();
+
+private:
+    // Amount that trackball needs to move in order to generate a key event.
+    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
+
+    // Immutable configuration parameters.
+    struct Parameters {
+        enum Mode {
+            MODE_POINTER,
+            MODE_NAVIGATION,
+        };
+
+        Mode mode;
+        bool hasAssociatedDisplay;
+        bool orientationAware;
+    } mParameters;
+
+    CursorButtonAccumulator mCursorButtonAccumulator;
+    CursorMotionAccumulator mCursorMotionAccumulator;
+    CursorScrollAccumulator mCursorScrollAccumulator;
+
+    int32_t mSource;
+    float mXScale;
+    float mYScale;
+    float mXPrecision;
+    float mYPrecision;
+
+    float mVWheelScale;
+    float mHWheelScale;
+
+    // Velocity controls for mouse pointer and wheel movements.
+    // The controls for X and Y wheel movements are separate to keep them decoupled.
+    VelocityControl mPointerVelocityControl;
+    VelocityControl mWheelXVelocityControl;
+    VelocityControl mWheelYVelocityControl;
+
+    int32_t mOrientation;
+
+    sp<PointerControllerInterface> mPointerController;
+
+    int32_t mButtonState;
+    nsecs_t mDownTime;
+
+    void configureParameters();
+    void dumpParameters(String8& dump);
+
+    void sync(nsecs_t when);
+};
+
+
+class TouchInputMapper : public InputMapper {
+public:
+    TouchInputMapper(InputDevice* device);
+    virtual ~TouchInputMapper();
+
+    virtual uint32_t getSources();
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
+    virtual void dump(String8& dump);
+    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent);
+
+    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
+    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
+    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags);
+
+    virtual void fadePointer();
+    virtual void timeoutExpired(nsecs_t when);
+
+protected:
+    CursorButtonAccumulator mCursorButtonAccumulator;
+    CursorScrollAccumulator mCursorScrollAccumulator;
+    TouchButtonAccumulator mTouchButtonAccumulator;
+
+    struct VirtualKey {
+        int32_t keyCode;
+        int32_t scanCode;
+        uint32_t flags;
+
+        // computed hit box, specified in touch screen coords based on known display size
+        int32_t hitLeft;
+        int32_t hitTop;
+        int32_t hitRight;
+        int32_t hitBottom;
+
+        inline bool isHit(int32_t x, int32_t y) const {
+            return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
+        }
+    };
+
+    // Input sources and device mode.
+    uint32_t mSource;
+
+    enum DeviceMode {
+        DEVICE_MODE_DISABLED, // input is disabled
+        DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
+        DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
+        DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
+        DEVICE_MODE_POINTER, // pointer mapping (pointer)
+    };
+    DeviceMode mDeviceMode;
+
+    // The reader's configuration.
+    InputReaderConfiguration mConfig;
+
+    // Immutable configuration parameters.
+    struct Parameters {
+        enum DeviceType {
+            DEVICE_TYPE_TOUCH_SCREEN,
+            DEVICE_TYPE_TOUCH_PAD,
+            DEVICE_TYPE_TOUCH_NAVIGATION,
+            DEVICE_TYPE_POINTER,
+        };
+
+        DeviceType deviceType;
+        bool hasAssociatedDisplay;
+        bool associatedDisplayIsExternal;
+        bool orientationAware;
+        bool hasButtonUnderPad;
+
+        enum GestureMode {
+            GESTURE_MODE_POINTER,
+            GESTURE_MODE_SPOTS,
+        };
+        GestureMode gestureMode;
+
+        bool wake;
+    } mParameters;
+
+    // Immutable calibration parameters in parsed form.
+    struct Calibration {
+        // Size
+        enum SizeCalibration {
+            SIZE_CALIBRATION_DEFAULT,
+            SIZE_CALIBRATION_NONE,
+            SIZE_CALIBRATION_GEOMETRIC,
+            SIZE_CALIBRATION_DIAMETER,
+            SIZE_CALIBRATION_BOX,
+            SIZE_CALIBRATION_AREA,
+        };
+
+        SizeCalibration sizeCalibration;
+
+        bool haveSizeScale;
+        float sizeScale;
+        bool haveSizeBias;
+        float sizeBias;
+        bool haveSizeIsSummed;
+        bool sizeIsSummed;
+
+        // Pressure
+        enum PressureCalibration {
+            PRESSURE_CALIBRATION_DEFAULT,
+            PRESSURE_CALIBRATION_NONE,
+            PRESSURE_CALIBRATION_PHYSICAL,
+            PRESSURE_CALIBRATION_AMPLITUDE,
+        };
+
+        PressureCalibration pressureCalibration;
+        bool havePressureScale;
+        float pressureScale;
+
+        // Orientation
+        enum OrientationCalibration {
+            ORIENTATION_CALIBRATION_DEFAULT,
+            ORIENTATION_CALIBRATION_NONE,
+            ORIENTATION_CALIBRATION_INTERPOLATED,
+            ORIENTATION_CALIBRATION_VECTOR,
+        };
+
+        OrientationCalibration orientationCalibration;
+
+        // Distance
+        enum DistanceCalibration {
+            DISTANCE_CALIBRATION_DEFAULT,
+            DISTANCE_CALIBRATION_NONE,
+            DISTANCE_CALIBRATION_SCALED,
+        };
+
+        DistanceCalibration distanceCalibration;
+        bool haveDistanceScale;
+        float distanceScale;
+
+        enum CoverageCalibration {
+            COVERAGE_CALIBRATION_DEFAULT,
+            COVERAGE_CALIBRATION_NONE,
+            COVERAGE_CALIBRATION_BOX,
+        };
+
+        CoverageCalibration coverageCalibration;
+
+        inline void applySizeScaleAndBias(float* outSize) const {
+            if (haveSizeScale) {
+                *outSize *= sizeScale;
+            }
+            if (haveSizeBias) {
+                *outSize += sizeBias;
+            }
+            if (*outSize < 0) {
+                *outSize = 0;
+            }
+        }
+    } mCalibration;
+
+    // Raw pointer axis information from the driver.
+    RawPointerAxes mRawPointerAxes;
+
+    // Raw pointer sample data.
+    RawPointerData mCurrentRawPointerData;
+    RawPointerData mLastRawPointerData;
+
+    // Cooked pointer sample data.
+    CookedPointerData mCurrentCookedPointerData;
+    CookedPointerData mLastCookedPointerData;
+
+    // Button state.
+    int32_t mCurrentButtonState;
+    int32_t mLastButtonState;
+
+    // Scroll state.
+    int32_t mCurrentRawVScroll;
+    int32_t mCurrentRawHScroll;
+
+    // Id bits used to differentiate fingers, stylus and mouse tools.
+    BitSet32 mCurrentFingerIdBits; // finger or unknown
+    BitSet32 mLastFingerIdBits;
+    BitSet32 mCurrentStylusIdBits; // stylus or eraser
+    BitSet32 mLastStylusIdBits;
+    BitSet32 mCurrentMouseIdBits; // mouse or lens
+    BitSet32 mLastMouseIdBits;
+
+    // True if we sent a HOVER_ENTER event.
+    bool mSentHoverEnter;
+
+    // The time the primary pointer last went down.
+    nsecs_t mDownTime;
+
+    // The pointer controller, or null if the device is not a pointer.
+    sp<PointerControllerInterface> mPointerController;
+
+    Vector<VirtualKey> mVirtualKeys;
+
+    virtual void configureParameters();
+    virtual void dumpParameters(String8& dump);
+    virtual void configureRawPointerAxes();
+    virtual void dumpRawPointerAxes(String8& dump);
+    virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
+    virtual void dumpSurface(String8& dump);
+    virtual void configureVirtualKeys();
+    virtual void dumpVirtualKeys(String8& dump);
+    virtual void parseCalibration();
+    virtual void resolveCalibration();
+    virtual void dumpCalibration(String8& dump);
+    virtual bool hasStylus() const = 0;
+
+    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
+
+private:
+    // The current viewport.
+    // The components of the viewport are specified in the display's rotated orientation.
+    DisplayViewport mViewport;
+
+    // The surface orientation, width and height set by configureSurface().
+    // The width and height are derived from the viewport but are specified
+    // in the natural orientation.
+    // The surface origin specifies how the surface coordinates should be translated
+    // to align with the logical display coordinate space.
+    // The orientation may be different from the viewport orientation as it specifies
+    // the rotation of the surface coordinates required to produce the viewport's
+    // requested orientation, so it will depend on whether the device is orientation aware.
+    int32_t mSurfaceWidth;
+    int32_t mSurfaceHeight;
+    int32_t mSurfaceLeft;
+    int32_t mSurfaceTop;
+    int32_t mSurfaceOrientation;
+
+    // Translation and scaling factors, orientation-independent.
+    float mXTranslate;
+    float mXScale;
+    float mXPrecision;
+
+    float mYTranslate;
+    float mYScale;
+    float mYPrecision;
+
+    float mGeometricScale;
+
+    float mPressureScale;
+
+    float mSizeScale;
+
+    float mOrientationScale;
+
+    float mDistanceScale;
+
+    bool mHaveTilt;
+    float mTiltXCenter;
+    float mTiltXScale;
+    float mTiltYCenter;
+    float mTiltYScale;
+
+    // Oriented motion ranges for input device info.
+    struct OrientedRanges {
+        InputDeviceInfo::MotionRange x;
+        InputDeviceInfo::MotionRange y;
+        InputDeviceInfo::MotionRange pressure;
+
+        bool haveSize;
+        InputDeviceInfo::MotionRange size;
+
+        bool haveTouchSize;
+        InputDeviceInfo::MotionRange touchMajor;
+        InputDeviceInfo::MotionRange touchMinor;
+
+        bool haveToolSize;
+        InputDeviceInfo::MotionRange toolMajor;
+        InputDeviceInfo::MotionRange toolMinor;
+
+        bool haveOrientation;
+        InputDeviceInfo::MotionRange orientation;
+
+        bool haveDistance;
+        InputDeviceInfo::MotionRange distance;
+
+        bool haveTilt;
+        InputDeviceInfo::MotionRange tilt;
+
+        OrientedRanges() {
+            clear();
+        }
+
+        void clear() {
+            haveSize = false;
+            haveTouchSize = false;
+            haveToolSize = false;
+            haveOrientation = false;
+            haveDistance = false;
+            haveTilt = false;
+        }
+    } mOrientedRanges;
+
+    // Oriented dimensions and precision.
+    float mOrientedXPrecision;
+    float mOrientedYPrecision;
+
+    struct CurrentVirtualKeyState {
+        bool down;
+        bool ignored;
+        nsecs_t downTime;
+        int32_t keyCode;
+        int32_t scanCode;
+    } mCurrentVirtualKey;
+
+    // Scale factor for gesture or mouse based pointer movements.
+    float mPointerXMovementScale;
+    float mPointerYMovementScale;
+
+    // Scale factor for gesture based zooming and other freeform motions.
+    float mPointerXZoomScale;
+    float mPointerYZoomScale;
+
+    // The maximum swipe width.
+    float mPointerGestureMaxSwipeWidth;
+
+    struct PointerDistanceHeapElement {
+        uint32_t currentPointerIndex : 8;
+        uint32_t lastPointerIndex : 8;
+        uint64_t distance : 48; // squared distance
+    };
+
+    enum PointerUsage {
+        POINTER_USAGE_NONE,
+        POINTER_USAGE_GESTURES,
+        POINTER_USAGE_STYLUS,
+        POINTER_USAGE_MOUSE,
+    };
+    PointerUsage mPointerUsage;
+
+    struct PointerGesture {
+        enum Mode {
+            // No fingers, button is not pressed.
+            // Nothing happening.
+            NEUTRAL,
+
+            // No fingers, button is not pressed.
+            // Tap detected.
+            // Emits DOWN and UP events at the pointer location.
+            TAP,
+
+            // Exactly one finger dragging following a tap.
+            // Pointer follows the active finger.
+            // Emits DOWN, MOVE and UP events at the pointer location.
+            //
+            // Detect double-taps when the finger goes up while in TAP_DRAG mode.
+            TAP_DRAG,
+
+            // Button is pressed.
+            // Pointer follows the active finger if there is one.  Other fingers are ignored.
+            // Emits DOWN, MOVE and UP events at the pointer location.
+            BUTTON_CLICK_OR_DRAG,
+
+            // Exactly one finger, button is not pressed.
+            // Pointer follows the active finger.
+            // Emits HOVER_MOVE events at the pointer location.
+            //
+            // Detect taps when the finger goes up while in HOVER mode.
+            HOVER,
+
+            // Exactly two fingers but neither have moved enough to clearly indicate
+            // whether a swipe or freeform gesture was intended.  We consider the
+            // pointer to be pressed so this enables clicking or long-pressing on buttons.
+            // Pointer does not move.
+            // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
+            PRESS,
+
+            // Exactly two fingers moving in the same direction, button is not pressed.
+            // Pointer does not move.
+            // Emits DOWN, MOVE and UP events with a single pointer coordinate that
+            // follows the midpoint between both fingers.
+            SWIPE,
+
+            // Two or more fingers moving in arbitrary directions, button is not pressed.
+            // Pointer does not move.
+            // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
+            // each finger individually relative to the initial centroid of the finger.
+            FREEFORM,
+
+            // Waiting for quiet time to end before starting the next gesture.
+            QUIET,
+        };
+
+        // Time the first finger went down.
+        nsecs_t firstTouchTime;
+
+        // The active pointer id from the raw touch data.
+        int32_t activeTouchId; // -1 if none
+
+        // The active pointer id from the gesture last delivered to the application.
+        int32_t activeGestureId; // -1 if none
+
+        // Pointer coords and ids for the current and previous pointer gesture.
+        Mode currentGestureMode;
+        BitSet32 currentGestureIdBits;
+        uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
+        PointerProperties currentGestureProperties[MAX_POINTERS];
+        PointerCoords currentGestureCoords[MAX_POINTERS];
+
+        Mode lastGestureMode;
+        BitSet32 lastGestureIdBits;
+        uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
+        PointerProperties lastGestureProperties[MAX_POINTERS];
+        PointerCoords lastGestureCoords[MAX_POINTERS];
+
+        // Time the pointer gesture last went down.
+        nsecs_t downTime;
+
+        // Time when the pointer went down for a TAP.
+        nsecs_t tapDownTime;
+
+        // Time when the pointer went up for a TAP.
+        nsecs_t tapUpTime;
+
+        // Location of initial tap.
+        float tapX, tapY;
+
+        // Time we started waiting for quiescence.
+        nsecs_t quietTime;
+
+        // Reference points for multitouch gestures.
+        float referenceTouchX;    // reference touch X/Y coordinates in surface units
+        float referenceTouchY;
+        float referenceGestureX;  // reference gesture X/Y coordinates in pixels
+        float referenceGestureY;
+
+        // Distance that each pointer has traveled which has not yet been
+        // subsumed into the reference gesture position.
+        BitSet32 referenceIdBits;
+        struct Delta {
+            float dx, dy;
+        };
+        Delta referenceDeltas[MAX_POINTER_ID + 1];
+
+        // Describes how touch ids are mapped to gesture ids for freeform gestures.
+        uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
+
+        // A velocity tracker for determining whether to switch active pointers during drags.
+        VelocityTracker velocityTracker;
+
+        void reset() {
+            firstTouchTime = LLONG_MIN;
+            activeTouchId = -1;
+            activeGestureId = -1;
+            currentGestureMode = NEUTRAL;
+            currentGestureIdBits.clear();
+            lastGestureMode = NEUTRAL;
+            lastGestureIdBits.clear();
+            downTime = 0;
+            velocityTracker.clear();
+            resetTap();
+            resetQuietTime();
+        }
+
+        void resetTap() {
+            tapDownTime = LLONG_MIN;
+            tapUpTime = LLONG_MIN;
+        }
+
+        void resetQuietTime() {
+            quietTime = LLONG_MIN;
+        }
+    } mPointerGesture;
+
+    struct PointerSimple {
+        PointerCoords currentCoords;
+        PointerProperties currentProperties;
+        PointerCoords lastCoords;
+        PointerProperties lastProperties;
+
+        // True if the pointer is down.
+        bool down;
+
+        // True if the pointer is hovering.
+        bool hovering;
+
+        // Time the pointer last went down.
+        nsecs_t downTime;
+
+        void reset() {
+            currentCoords.clear();
+            currentProperties.clear();
+            lastCoords.clear();
+            lastProperties.clear();
+            down = false;
+            hovering = false;
+            downTime = 0;
+        }
+    } mPointerSimple;
+
+    // The pointer and scroll velocity controls.
+    VelocityControl mPointerVelocityControl;
+    VelocityControl mWheelXVelocityControl;
+    VelocityControl mWheelYVelocityControl;
+
+    void sync(nsecs_t when);
+
+    bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
+    void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
+            int32_t keyEventAction, int32_t keyEventFlags);
+
+    void dispatchTouches(nsecs_t when, uint32_t policyFlags);
+    void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
+    void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
+    void cookPointerData();
+
+    void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
+    void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
+
+    void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
+    void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
+    bool preparePointerGestures(nsecs_t when,
+            bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
+            bool isTimeout);
+
+    void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
+    void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
+
+    void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
+    void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
+
+    void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
+            bool down, bool hovering);
+    void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
+
+    // Dispatches a motion event.
+    // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
+    // method will take care of setting the index and transmuting the action to DOWN or UP
+    // it is the first / last pointer to go down / up.
+    void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
+            int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
+            int32_t edgeFlags,
+            const PointerProperties* properties, const PointerCoords* coords,
+            const uint32_t* idToIndex, BitSet32 idBits,
+            int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
+
+    // Updates pointer coords and properties for pointers with specified ids that have moved.
+    // Returns true if any of them changed.
+    bool updateMovedPointers(const PointerProperties* inProperties,
+            const PointerCoords* inCoords, const uint32_t* inIdToIndex,
+            PointerProperties* outProperties, PointerCoords* outCoords,
+            const uint32_t* outIdToIndex, BitSet32 idBits) const;
+
+    bool isPointInsideSurface(int32_t x, int32_t y);
+    const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
+
+    void assignPointerIds();
+};
+
+
+class SingleTouchInputMapper : public TouchInputMapper {
+public:
+    SingleTouchInputMapper(InputDevice* device);
+    virtual ~SingleTouchInputMapper();
+
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent);
+
+protected:
+    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
+    virtual void configureRawPointerAxes();
+    virtual bool hasStylus() const;
+
+private:
+    SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
+};
+
+
+class MultiTouchInputMapper : public TouchInputMapper {
+public:
+    MultiTouchInputMapper(InputDevice* device);
+    virtual ~MultiTouchInputMapper();
+
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent);
+
+protected:
+    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
+    virtual void configureRawPointerAxes();
+    virtual bool hasStylus() const;
+
+private:
+    MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
+
+    // Specifies the pointer id bits that are in use, and their associated tracking id.
+    BitSet32 mPointerIdBits;
+    int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
+};
+
+
+class JoystickInputMapper : public InputMapper {
+public:
+    JoystickInputMapper(InputDevice* device);
+    virtual ~JoystickInputMapper();
+
+    virtual uint32_t getSources();
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
+    virtual void dump(String8& dump);
+    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
+    virtual void reset(nsecs_t when);
+    virtual void process(const RawEvent* rawEvent);
+
+private:
+    struct Axis {
+        RawAbsoluteAxisInfo rawAxisInfo;
+        AxisInfo axisInfo;
+
+        bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
+
+        float scale;   // scale factor from raw to normalized values
+        float offset;  // offset to add after scaling for normalization
+        float highScale;  // scale factor from raw to normalized values of high split
+        float highOffset; // offset to add after scaling for normalization of high split
+
+        float min;        // normalized inclusive minimum
+        float max;        // normalized inclusive maximum
+        float flat;       // normalized flat region size
+        float fuzz;       // normalized error tolerance
+        float resolution; // normalized resolution in units/mm
+
+        float filter;  // filter out small variations of this size
+        float currentValue; // current value
+        float newValue; // most recent value
+        float highCurrentValue; // current value of high split
+        float highNewValue; // most recent value of high split
+
+        void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
+                bool explicitlyMapped, float scale, float offset,
+                float highScale, float highOffset,
+                float min, float max, float flat, float fuzz, float resolution) {
+            this->rawAxisInfo = rawAxisInfo;
+            this->axisInfo = axisInfo;
+            this->explicitlyMapped = explicitlyMapped;
+            this->scale = scale;
+            this->offset = offset;
+            this->highScale = highScale;
+            this->highOffset = highOffset;
+            this->min = min;
+            this->max = max;
+            this->flat = flat;
+            this->fuzz = fuzz;
+            this->resolution = resolution;
+            this->filter = 0;
+            resetValue();
+        }
+
+        void resetValue() {
+            this->currentValue = 0;
+            this->newValue = 0;
+            this->highCurrentValue = 0;
+            this->highNewValue = 0;
+        }
+    };
+
+    // Axes indexed by raw ABS_* axis index.
+    KeyedVector<int32_t, Axis> mAxes;
+
+    void sync(nsecs_t when, bool force);
+
+    bool haveAxis(int32_t axisId);
+    void pruneAxes(bool ignoreExplicitlyMappedAxes);
+    bool filterAxes(bool force);
+
+    static bool hasValueChangedSignificantly(float filter,
+            float newValue, float currentValue, float min, float max);
+    static bool hasMovedNearerToValueWithinFilteredRange(float filter,
+            float newValue, float currentValue, float thresholdValue);
+
+    static bool isCenteredAxis(int32_t axis);
+    static int32_t getCompatAxis(int32_t axis);
+
+    static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info);
+    static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis,
+            float value);
+};
+
+} // namespace android
+
+#endif // _UI_INPUT_READER_H
diff --git a/services/input/InputWindow.cpp b/libs/input/InputWindow.cpp
similarity index 100%
rename from services/input/InputWindow.cpp
rename to libs/input/InputWindow.cpp
diff --git a/services/input/InputWindow.h b/libs/input/InputWindow.h
similarity index 100%
rename from services/input/InputWindow.h
rename to libs/input/InputWindow.h
diff --git a/services/input/PointerController.cpp b/libs/input/PointerController.cpp
similarity index 100%
rename from services/input/PointerController.cpp
rename to libs/input/PointerController.cpp
diff --git a/services/input/PointerController.h b/libs/input/PointerController.h
similarity index 100%
rename from services/input/PointerController.h
rename to libs/input/PointerController.h
diff --git a/services/input/SpriteController.cpp b/libs/input/SpriteController.cpp
similarity index 100%
rename from services/input/SpriteController.cpp
rename to libs/input/SpriteController.cpp
diff --git a/services/input/SpriteController.h b/libs/input/SpriteController.h
similarity index 100%
rename from services/input/SpriteController.h
rename to libs/input/SpriteController.h
diff --git a/services/input/tests/Android.mk b/libs/input/tests/Android.mk
similarity index 100%
rename from services/input/tests/Android.mk
rename to libs/input/tests/Android.mk
diff --git a/libs/input/tests/InputDispatcher_test.cpp b/libs/input/tests/InputDispatcher_test.cpp
new file mode 100644
index 0000000..fc89a9b
--- /dev/null
+++ b/libs/input/tests/InputDispatcher_test.cpp
@@ -0,0 +1,262 @@
+/*
+ * Copyright (C) 2010 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 "../InputDispatcher.h"
+
+#include <gtest/gtest.h>
+#include <linux/input.h>
+
+namespace android {
+
+// An arbitrary time value.
+static const nsecs_t ARBITRARY_TIME = 1234;
+
+// An arbitrary device id.
+static const int32_t DEVICE_ID = 1;
+
+// An arbitrary display id.
+static const int32_t DISPLAY_ID = 0;
+
+// An arbitrary injector pid / uid pair that has permission to inject events.
+static const int32_t INJECTOR_PID = 999;
+static const int32_t INJECTOR_UID = 1001;
+
+
+// --- FakeInputDispatcherPolicy ---
+
+class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
+    InputDispatcherConfiguration mConfig;
+
+protected:
+    virtual ~FakeInputDispatcherPolicy() {
+    }
+
+public:
+    FakeInputDispatcherPolicy() {
+    }
+
+private:
+    virtual void notifyConfigurationChanged(nsecs_t when) {
+    }
+
+    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
+            const sp<InputWindowHandle>& inputWindowHandle,
+            const String8& reason) {
+        return 0;
+    }
+
+    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
+    }
+
+    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
+        *outConfig = mConfig;
+    }
+
+    virtual bool isKeyRepeatEnabled() {
+        return true;
+    }
+
+    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
+        return true;
+    }
+
+    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) {
+    }
+
+    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
+    }
+
+    virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
+            const KeyEvent* keyEvent, uint32_t policyFlags) {
+        return 0;
+    }
+
+    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
+            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
+        return false;
+    }
+
+    virtual void notifySwitch(nsecs_t when,
+            uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
+    }
+
+    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
+    }
+
+    virtual bool checkInjectEventsPermissionNonReentrant(
+            int32_t injectorPid, int32_t injectorUid) {
+        return false;
+    }
+};
+
+
+// --- InputDispatcherTest ---
+
+class InputDispatcherTest : public testing::Test {
+protected:
+    sp<FakeInputDispatcherPolicy> mFakePolicy;
+    sp<InputDispatcher> mDispatcher;
+
+    virtual void SetUp() {
+        mFakePolicy = new FakeInputDispatcherPolicy();
+        mDispatcher = new InputDispatcher(mFakePolicy);
+    }
+
+    virtual void TearDown() {
+        mFakePolicy.clear();
+        mDispatcher.clear();
+    }
+};
+
+
+TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) {
+    KeyEvent event;
+
+    // Rejects undefined key actions.
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
+            /*action*/ -1, 0,
+            AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject key events with undefined action.";
+
+    // Rejects ACTION_MULTIPLE since it is not supported despite being defined in the API.
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
+            AKEY_EVENT_ACTION_MULTIPLE, 0,
+            AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject key events with ACTION_MULTIPLE.";
+}
+
+TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) {
+    MotionEvent event;
+    PointerProperties pointerProperties[MAX_POINTERS + 1];
+    PointerCoords pointerCoords[MAX_POINTERS + 1];
+    for (int i = 0; i <= MAX_POINTERS; i++) {
+        pointerProperties[i].clear();
+        pointerProperties[i].id = i;
+        pointerCoords[i].clear();
+    }
+
+    // Rejects undefined motion actions.
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            /*action*/ -1, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with undefined action.";
+
+    // Rejects pointer down with invalid index.
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with pointer down index too large.";
+
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_POINTER_DOWN | (-1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with pointer down index too small.";
+
+    // Rejects pointer up with invalid index.
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with pointer up index too large.";
+
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_POINTER_UP | (-1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with pointer up index too small.";
+
+    // Rejects motion events with invalid number of pointers.
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 0, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with 0 pointers.";
+
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ MAX_POINTERS + 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with more than MAX_POINTERS pointers.";
+
+    // Rejects motion events with invalid pointer ids.
+    pointerProperties[0].id = -1;
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with pointer ids less than 0.";
+
+    pointerProperties[0].id = MAX_POINTER_ID + 1;
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 1, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with pointer ids greater than MAX_POINTER_ID.";
+
+    // Rejects motion events with duplicate pointer ids.
+    pointerProperties[0].id = 1;
+    pointerProperties[1].id = 1;
+    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
+            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
+            ARBITRARY_TIME, ARBITRARY_TIME,
+            /*pointerCount*/ 2, pointerProperties, pointerCoords);
+    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(
+            &event, DISPLAY_ID,
+            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
+            << "Should reject motion events with duplicate pointer ids.";
+}
+
+} // namespace android
diff --git a/libs/input/tests/InputReader_test.cpp b/libs/input/tests/InputReader_test.cpp
new file mode 100644
index 0000000..aaa973d
--- /dev/null
+++ b/libs/input/tests/InputReader_test.cpp
@@ -0,0 +1,5099 @@
+/*
+ * Copyright (C) 2010 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 "../InputReader.h"
+
+#include <utils/List.h>
+#include <gtest/gtest.h>
+#include <math.h>
+
+namespace android {
+
+// An arbitrary time value.
+static const nsecs_t ARBITRARY_TIME = 1234;
+
+// Arbitrary display properties.
+static const int32_t DISPLAY_ID = 0;
+static const int32_t DISPLAY_WIDTH = 480;
+static const int32_t DISPLAY_HEIGHT = 800;
+
+// Error tolerance for floating point assertions.
+static const float EPSILON = 0.001f;
+
+template<typename T>
+static inline T min(T a, T b) {
+    return a < b ? a : b;
+}
+
+static inline float avg(float x, float y) {
+    return (x + y) / 2;
+}
+
+
+// --- FakePointerController ---
+
+class FakePointerController : public PointerControllerInterface {
+    bool mHaveBounds;
+    float mMinX, mMinY, mMaxX, mMaxY;
+    float mX, mY;
+    int32_t mButtonState;
+
+protected:
+    virtual ~FakePointerController() { }
+
+public:
+    FakePointerController() :
+        mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0), mX(0), mY(0),
+        mButtonState(0) {
+    }
+
+    void setBounds(float minX, float minY, float maxX, float maxY) {
+        mHaveBounds = true;
+        mMinX = minX;
+        mMinY = minY;
+        mMaxX = maxX;
+        mMaxY = maxY;
+    }
+
+    virtual void setPosition(float x, float y) {
+        mX = x;
+        mY = y;
+    }
+
+    virtual void setButtonState(int32_t buttonState) {
+        mButtonState = buttonState;
+    }
+
+    virtual int32_t getButtonState() const {
+        return mButtonState;
+    }
+
+    virtual void getPosition(float* outX, float* outY) const {
+        *outX = mX;
+        *outY = mY;
+    }
+
+private:
+    virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const {
+        *outMinX = mMinX;
+        *outMinY = mMinY;
+        *outMaxX = mMaxX;
+        *outMaxY = mMaxY;
+        return mHaveBounds;
+    }
+
+    virtual void move(float deltaX, float deltaY) {
+        mX += deltaX;
+        if (mX < mMinX) mX = mMinX;
+        if (mX > mMaxX) mX = mMaxX;
+        mY += deltaY;
+        if (mY < mMinY) mY = mMinY;
+        if (mY > mMaxY) mY = mMaxY;
+    }
+
+    virtual void fade(Transition transition) {
+    }
+
+    virtual void unfade(Transition transition) {
+    }
+
+    virtual void setPresentation(Presentation presentation) {
+    }
+
+    virtual void setSpots(const PointerCoords* spotCoords,
+            const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
+    }
+
+    virtual void clearSpots() {
+    }
+};
+
+
+// --- FakeInputReaderPolicy ---
+
+class FakeInputReaderPolicy : public InputReaderPolicyInterface {
+    InputReaderConfiguration mConfig;
+    KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers;
+    Vector<InputDeviceInfo> mInputDevices;
+
+protected:
+    virtual ~FakeInputReaderPolicy() { }
+
+public:
+    FakeInputReaderPolicy() {
+    }
+
+    void setDisplayInfo(int32_t displayId, int32_t width, int32_t height, int32_t orientation) {
+        // Set the size of both the internal and external display at the same time.
+        bool isRotated = (orientation == DISPLAY_ORIENTATION_90
+                || orientation == DISPLAY_ORIENTATION_270);
+        DisplayViewport v;
+        v.displayId = displayId;
+        v.orientation = orientation;
+        v.logicalLeft = 0;
+        v.logicalTop = 0;
+        v.logicalRight = isRotated ? height : width;
+        v.logicalBottom = isRotated ? width : height;
+        v.physicalLeft = 0;
+        v.physicalTop = 0;
+        v.physicalRight = isRotated ? height : width;
+        v.physicalBottom = isRotated ? width : height;
+        v.deviceWidth = isRotated ? height : width;
+        v.deviceHeight = isRotated ? width : height;
+        mConfig.setDisplayInfo(false /*external*/, v);
+        mConfig.setDisplayInfo(true /*external*/, v);
+    }
+
+    void addExcludedDeviceName(const String8& deviceName) {
+        mConfig.excludedDeviceNames.push(deviceName);
+    }
+
+    void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) {
+        mPointerControllers.add(deviceId, controller);
+    }
+
+    const InputReaderConfiguration* getReaderConfiguration() const {
+        return &mConfig;
+    }
+
+    const Vector<InputDeviceInfo>& getInputDevices() const {
+        return mInputDevices;
+    }
+
+private:
+    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) {
+        *outConfig = mConfig;
+    }
+
+    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) {
+        return mPointerControllers.valueFor(deviceId);
+    }
+
+    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
+        mInputDevices = inputDevices;
+    }
+
+    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier) {
+        return NULL;
+    }
+
+    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) {
+        return String8::empty();
+    }
+};
+
+
+// --- FakeInputListener ---
+
+class FakeInputListener : public InputListenerInterface {
+private:
+    List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgsQueue;
+    List<NotifyDeviceResetArgs> mNotifyDeviceResetArgsQueue;
+    List<NotifyKeyArgs> mNotifyKeyArgsQueue;
+    List<NotifyMotionArgs> mNotifyMotionArgsQueue;
+    List<NotifySwitchArgs> mNotifySwitchArgsQueue;
+
+protected:
+    virtual ~FakeInputListener() { }
+
+public:
+    FakeInputListener() {
+    }
+
+    void assertNotifyConfigurationChangedWasCalled(
+            NotifyConfigurationChangedArgs* outEventArgs = NULL) {
+        ASSERT_FALSE(mNotifyConfigurationChangedArgsQueue.empty())
+                << "Expected notifyConfigurationChanged() to have been called.";
+        if (outEventArgs) {
+            *outEventArgs = *mNotifyConfigurationChangedArgsQueue.begin();
+        }
+        mNotifyConfigurationChangedArgsQueue.erase(mNotifyConfigurationChangedArgsQueue.begin());
+    }
+
+    void assertNotifyDeviceResetWasCalled(
+            NotifyDeviceResetArgs* outEventArgs = NULL) {
+        ASSERT_FALSE(mNotifyDeviceResetArgsQueue.empty())
+                << "Expected notifyDeviceReset() to have been called.";
+        if (outEventArgs) {
+            *outEventArgs = *mNotifyDeviceResetArgsQueue.begin();
+        }
+        mNotifyDeviceResetArgsQueue.erase(mNotifyDeviceResetArgsQueue.begin());
+    }
+
+    void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = NULL) {
+        ASSERT_FALSE(mNotifyKeyArgsQueue.empty())
+                << "Expected notifyKey() to have been called.";
+        if (outEventArgs) {
+            *outEventArgs = *mNotifyKeyArgsQueue.begin();
+        }
+        mNotifyKeyArgsQueue.erase(mNotifyKeyArgsQueue.begin());
+    }
+
+    void assertNotifyKeyWasNotCalled() {
+        ASSERT_TRUE(mNotifyKeyArgsQueue.empty())
+                << "Expected notifyKey() to not have been called.";
+    }
+
+    void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = NULL) {
+        ASSERT_FALSE(mNotifyMotionArgsQueue.empty())
+                << "Expected notifyMotion() to have been called.";
+        if (outEventArgs) {
+            *outEventArgs = *mNotifyMotionArgsQueue.begin();
+        }
+        mNotifyMotionArgsQueue.erase(mNotifyMotionArgsQueue.begin());
+    }
+
+    void assertNotifyMotionWasNotCalled() {
+        ASSERT_TRUE(mNotifyMotionArgsQueue.empty())
+                << "Expected notifyMotion() to not have been called.";
+    }
+
+    void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = NULL) {
+        ASSERT_FALSE(mNotifySwitchArgsQueue.empty())
+                << "Expected notifySwitch() to have been called.";
+        if (outEventArgs) {
+            *outEventArgs = *mNotifySwitchArgsQueue.begin();
+        }
+        mNotifySwitchArgsQueue.erase(mNotifySwitchArgsQueue.begin());
+    }
+
+private:
+    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
+        mNotifyConfigurationChangedArgsQueue.push_back(*args);
+    }
+
+    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+        mNotifyDeviceResetArgsQueue.push_back(*args);
+    }
+
+    virtual void notifyKey(const NotifyKeyArgs* args) {
+        mNotifyKeyArgsQueue.push_back(*args);
+    }
+
+    virtual void notifyMotion(const NotifyMotionArgs* args) {
+        mNotifyMotionArgsQueue.push_back(*args);
+    }
+
+    virtual void notifySwitch(const NotifySwitchArgs* args) {
+        mNotifySwitchArgsQueue.push_back(*args);
+    }
+};
+
+
+// --- FakeEventHub ---
+
+class FakeEventHub : public EventHubInterface {
+    struct KeyInfo {
+        int32_t keyCode;
+        uint32_t flags;
+    };
+
+    struct Device {
+        InputDeviceIdentifier identifier;
+        uint32_t classes;
+        PropertyMap configuration;
+        KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes;
+        KeyedVector<int, bool> relativeAxes;
+        KeyedVector<int32_t, int32_t> keyCodeStates;
+        KeyedVector<int32_t, int32_t> scanCodeStates;
+        KeyedVector<int32_t, int32_t> switchStates;
+        KeyedVector<int32_t, int32_t> absoluteAxisValue;
+        KeyedVector<int32_t, KeyInfo> keysByScanCode;
+        KeyedVector<int32_t, KeyInfo> keysByUsageCode;
+        KeyedVector<int32_t, bool> leds;
+        Vector<VirtualKeyDefinition> virtualKeys;
+
+        Device(uint32_t classes) :
+                classes(classes) {
+        }
+    };
+
+    KeyedVector<int32_t, Device*> mDevices;
+    Vector<String8> mExcludedDevices;
+    List<RawEvent> mEvents;
+
+protected:
+    virtual ~FakeEventHub() {
+        for (size_t i = 0; i < mDevices.size(); i++) {
+            delete mDevices.valueAt(i);
+        }
+    }
+
+public:
+    FakeEventHub() { }
+
+    void addDevice(int32_t deviceId, const String8& name, uint32_t classes) {
+        Device* device = new Device(classes);
+        device->identifier.name = name;
+        mDevices.add(deviceId, device);
+
+        enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0);
+    }
+
+    void removeDevice(int32_t deviceId) {
+        delete mDevices.valueFor(deviceId);
+        mDevices.removeItem(deviceId);
+
+        enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0);
+    }
+
+    void finishDeviceScan() {
+        enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0);
+    }
+
+    void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) {
+        Device* device = getDevice(deviceId);
+        device->configuration.addProperty(key, value);
+    }
+
+    void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) {
+        Device* device = getDevice(deviceId);
+        device->configuration.addAll(configuration);
+    }
+
+    void addAbsoluteAxis(int32_t deviceId, int axis,
+            int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) {
+        Device* device = getDevice(deviceId);
+
+        RawAbsoluteAxisInfo info;
+        info.valid = true;
+        info.minValue = minValue;
+        info.maxValue = maxValue;
+        info.flat = flat;
+        info.fuzz = fuzz;
+        info.resolution = resolution;
+        device->absoluteAxes.add(axis, info);
+    }
+
+    void addRelativeAxis(int32_t deviceId, int32_t axis) {
+        Device* device = getDevice(deviceId);
+        device->relativeAxes.add(axis, true);
+    }
+
+    void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) {
+        Device* device = getDevice(deviceId);
+        device->keyCodeStates.replaceValueFor(keyCode, state);
+    }
+
+    void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) {
+        Device* device = getDevice(deviceId);
+        device->scanCodeStates.replaceValueFor(scanCode, state);
+    }
+
+    void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) {
+        Device* device = getDevice(deviceId);
+        device->switchStates.replaceValueFor(switchCode, state);
+    }
+
+    void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) {
+        Device* device = getDevice(deviceId);
+        device->absoluteAxisValue.replaceValueFor(axis, value);
+    }
+
+    void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
+            int32_t keyCode, uint32_t flags) {
+        Device* device = getDevice(deviceId);
+        KeyInfo info;
+        info.keyCode = keyCode;
+        info.flags = flags;
+        if (scanCode) {
+            device->keysByScanCode.add(scanCode, info);
+        }
+        if (usageCode) {
+            device->keysByUsageCode.add(usageCode, info);
+        }
+    }
+
+    void addLed(int32_t deviceId, int32_t led, bool initialState) {
+        Device* device = getDevice(deviceId);
+        device->leds.add(led, initialState);
+    }
+
+    bool getLedState(int32_t deviceId, int32_t led) {
+        Device* device = getDevice(deviceId);
+        return device->leds.valueFor(led);
+    }
+
+    Vector<String8>& getExcludedDevices() {
+        return mExcludedDevices;
+    }
+
+    void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) {
+        Device* device = getDevice(deviceId);
+        device->virtualKeys.push(definition);
+    }
+
+    void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type,
+            int32_t code, int32_t value) {
+        RawEvent event;
+        event.when = when;
+        event.deviceId = deviceId;
+        event.type = type;
+        event.code = code;
+        event.value = value;
+        mEvents.push_back(event);
+
+        if (type == EV_ABS) {
+            setAbsoluteAxisValue(deviceId, code, value);
+        }
+    }
+
+    void assertQueueIsEmpty() {
+        ASSERT_EQ(size_t(0), mEvents.size())
+                << "Expected the event queue to be empty (fully consumed).";
+    }
+
+private:
+    Device* getDevice(int32_t deviceId) const {
+        ssize_t index = mDevices.indexOfKey(deviceId);
+        return index >= 0 ? mDevices.valueAt(index) : NULL;
+    }
+
+    virtual uint32_t getDeviceClasses(int32_t deviceId) const {
+        Device* device = getDevice(deviceId);
+        return device ? device->classes : 0;
+    }
+
+    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const {
+        Device* device = getDevice(deviceId);
+        return device ? device->identifier : InputDeviceIdentifier();
+    }
+
+    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const {
+        return 0;
+    }
+
+    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            *outConfiguration = device->configuration;
+        }
+    }
+
+    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
+            RawAbsoluteAxisInfo* outAxisInfo) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->absoluteAxes.indexOfKey(axis);
+            if (index >= 0) {
+                *outAxisInfo = device->absoluteAxes.valueAt(index);
+                return OK;
+            }
+        }
+        outAxisInfo->clear();
+        return -1;
+    }
+
+    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            return device->relativeAxes.indexOfKey(axis) >= 0;
+        }
+        return false;
+    }
+
+    virtual bool hasInputProperty(int32_t deviceId, int property) const {
+        return false;
+    }
+
+    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
+            int32_t* outKeycode, uint32_t* outFlags) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            const KeyInfo* key = getKey(device, scanCode, usageCode);
+            if (key) {
+                if (outKeycode) {
+                    *outKeycode = key->keyCode;
+                }
+                if (outFlags) {
+                    *outFlags = key->flags;
+                }
+                return OK;
+            }
+        }
+        return NAME_NOT_FOUND;
+    }
+
+    const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const {
+        if (usageCode) {
+            ssize_t index = device->keysByUsageCode.indexOfKey(usageCode);
+            if (index >= 0) {
+                return &device->keysByUsageCode.valueAt(index);
+            }
+        }
+        if (scanCode) {
+            ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
+            if (index >= 0) {
+                return &device->keysByScanCode.valueAt(index);
+            }
+        }
+        return NULL;
+    }
+
+    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
+            AxisInfo* outAxisInfo) const {
+        return NAME_NOT_FOUND;
+    }
+
+    virtual void setExcludedDevices(const Vector<String8>& devices) {
+        mExcludedDevices = devices;
+    }
+
+    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
+        if (mEvents.empty()) {
+            return 0;
+        }
+
+        *buffer = *mEvents.begin();
+        mEvents.erase(mEvents.begin());
+        return 1;
+    }
+
+    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->scanCodeStates.indexOfKey(scanCode);
+            if (index >= 0) {
+                return device->scanCodeStates.valueAt(index);
+            }
+        }
+        return AKEY_STATE_UNKNOWN;
+    }
+
+    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->keyCodeStates.indexOfKey(keyCode);
+            if (index >= 0) {
+                return device->keyCodeStates.valueAt(index);
+            }
+        }
+        return AKEY_STATE_UNKNOWN;
+    }
+
+    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->switchStates.indexOfKey(sw);
+            if (index >= 0) {
+                return device->switchStates.valueAt(index);
+            }
+        }
+        return AKEY_STATE_UNKNOWN;
+    }
+
+    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
+            int32_t* outValue) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->absoluteAxisValue.indexOfKey(axis);
+            if (index >= 0) {
+                *outValue = device->absoluteAxisValue.valueAt(index);
+                return OK;
+            }
+        }
+        *outValue = 0;
+        return -1;
+    }
+
+    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
+            uint8_t* outFlags) const {
+        bool result = false;
+        Device* device = getDevice(deviceId);
+        if (device) {
+            for (size_t i = 0; i < numCodes; i++) {
+                for (size_t j = 0; j < device->keysByScanCode.size(); j++) {
+                    if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) {
+                        outFlags[i] = 1;
+                        result = true;
+                    }
+                }
+                for (size_t j = 0; j < device->keysByUsageCode.size(); j++) {
+                    if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) {
+                        outFlags[i] = 1;
+                        result = true;
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
+            return index >= 0;
+        }
+        return false;
+    }
+
+    virtual bool hasLed(int32_t deviceId, int32_t led) const {
+        Device* device = getDevice(deviceId);
+        return device && device->leds.indexOfKey(led) >= 0;
+    }
+
+    virtual void setLedState(int32_t deviceId, int32_t led, bool on) {
+        Device* device = getDevice(deviceId);
+        if (device) {
+            ssize_t index = device->leds.indexOfKey(led);
+            if (index >= 0) {
+                device->leds.replaceValueAt(led, on);
+            } else {
+                ADD_FAILURE()
+                        << "Attempted to set the state of an LED that the EventHub declared "
+                        "was not present.  led=" << led;
+            }
+        }
+    }
+
+    virtual void getVirtualKeyDefinitions(int32_t deviceId,
+            Vector<VirtualKeyDefinition>& outVirtualKeys) const {
+        outVirtualKeys.clear();
+
+        Device* device = getDevice(deviceId);
+        if (device) {
+            outVirtualKeys.appendVector(device->virtualKeys);
+        }
+    }
+
+    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const {
+        return NULL;
+    }
+
+    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) {
+        return false;
+    }
+
+    virtual void vibrate(int32_t deviceId, nsecs_t duration) {
+    }
+
+    virtual void cancelVibrate(int32_t deviceId) {
+    }
+
+    virtual bool isExternal(int32_t deviceId) const {
+        return false;
+    }
+
+    virtual void dump(String8& dump) {
+    }
+
+    virtual void monitor() {
+    }
+
+    virtual void requestReopenDevices() {
+    }
+
+    virtual void wake() {
+    }
+};
+
+
+// --- FakeInputReaderContext ---
+
+class FakeInputReaderContext : public InputReaderContext {
+    sp<EventHubInterface> mEventHub;
+    sp<InputReaderPolicyInterface> mPolicy;
+    sp<InputListenerInterface> mListener;
+    int32_t mGlobalMetaState;
+    bool mUpdateGlobalMetaStateWasCalled;
+    int32_t mGeneration;
+
+public:
+    FakeInputReaderContext(const sp<EventHubInterface>& eventHub,
+            const sp<InputReaderPolicyInterface>& policy,
+            const sp<InputListenerInterface>& listener) :
+            mEventHub(eventHub), mPolicy(policy), mListener(listener),
+            mGlobalMetaState(0) {
+    }
+
+    virtual ~FakeInputReaderContext() { }
+
+    void assertUpdateGlobalMetaStateWasCalled() {
+        ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled)
+                << "Expected updateGlobalMetaState() to have been called.";
+        mUpdateGlobalMetaStateWasCalled = false;
+    }
+
+    void setGlobalMetaState(int32_t state) {
+        mGlobalMetaState = state;
+    }
+
+private:
+    virtual void updateGlobalMetaState() {
+        mUpdateGlobalMetaStateWasCalled = true;
+    }
+
+    virtual int32_t getGlobalMetaState() {
+        return mGlobalMetaState;
+    }
+
+    virtual EventHubInterface* getEventHub() {
+        return mEventHub.get();
+    }
+
+    virtual InputReaderPolicyInterface* getPolicy() {
+        return mPolicy.get();
+    }
+
+    virtual InputListenerInterface* getListener() {
+        return mListener.get();
+    }
+
+    virtual void disableVirtualKeysUntil(nsecs_t time) {
+    }
+
+    virtual bool shouldDropVirtualKey(nsecs_t now,
+            InputDevice* device, int32_t keyCode, int32_t scanCode) {
+        return false;
+    }
+
+    virtual void fadePointer() {
+    }
+
+    virtual void requestTimeoutAtTime(nsecs_t when) {
+    }
+
+    virtual int32_t bumpGeneration() {
+        return ++mGeneration;
+    }
+};
+
+
+// --- FakeInputMapper ---
+
+class FakeInputMapper : public InputMapper {
+    uint32_t mSources;
+    int32_t mKeyboardType;
+    int32_t mMetaState;
+    KeyedVector<int32_t, int32_t> mKeyCodeStates;
+    KeyedVector<int32_t, int32_t> mScanCodeStates;
+    KeyedVector<int32_t, int32_t> mSwitchStates;
+    Vector<int32_t> mSupportedKeyCodes;
+    RawEvent mLastEvent;
+
+    bool mConfigureWasCalled;
+    bool mResetWasCalled;
+    bool mProcessWasCalled;
+
+public:
+    FakeInputMapper(InputDevice* device, uint32_t sources) :
+            InputMapper(device),
+            mSources(sources), mKeyboardType(AINPUT_KEYBOARD_TYPE_NONE),
+            mMetaState(0),
+            mConfigureWasCalled(false), mResetWasCalled(false), mProcessWasCalled(false) {
+    }
+
+    virtual ~FakeInputMapper() { }
+
+    void setKeyboardType(int32_t keyboardType) {
+        mKeyboardType = keyboardType;
+    }
+
+    void setMetaState(int32_t metaState) {
+        mMetaState = metaState;
+    }
+
+    void assertConfigureWasCalled() {
+        ASSERT_TRUE(mConfigureWasCalled)
+                << "Expected configure() to have been called.";
+        mConfigureWasCalled = false;
+    }
+
+    void assertResetWasCalled() {
+        ASSERT_TRUE(mResetWasCalled)
+                << "Expected reset() to have been called.";
+        mResetWasCalled = false;
+    }
+
+    void assertProcessWasCalled(RawEvent* outLastEvent = NULL) {
+        ASSERT_TRUE(mProcessWasCalled)
+                << "Expected process() to have been called.";
+        if (outLastEvent) {
+            *outLastEvent = mLastEvent;
+        }
+        mProcessWasCalled = false;
+    }
+
+    void setKeyCodeState(int32_t keyCode, int32_t state) {
+        mKeyCodeStates.replaceValueFor(keyCode, state);
+    }
+
+    void setScanCodeState(int32_t scanCode, int32_t state) {
+        mScanCodeStates.replaceValueFor(scanCode, state);
+    }
+
+    void setSwitchState(int32_t switchCode, int32_t state) {
+        mSwitchStates.replaceValueFor(switchCode, state);
+    }
+
+    void addSupportedKeyCode(int32_t keyCode) {
+        mSupportedKeyCodes.add(keyCode);
+    }
+
+private:
+    virtual uint32_t getSources() {
+        return mSources;
+    }
+
+    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) {
+        InputMapper::populateDeviceInfo(deviceInfo);
+
+        if (mKeyboardType != AINPUT_KEYBOARD_TYPE_NONE) {
+            deviceInfo->setKeyboardType(mKeyboardType);
+        }
+    }
+
+    virtual void configure(nsecs_t when,
+            const InputReaderConfiguration* config, uint32_t changes) {
+        mConfigureWasCalled = true;
+    }
+
+    virtual void reset(nsecs_t when) {
+        mResetWasCalled = true;
+    }
+
+    virtual void process(const RawEvent* rawEvent) {
+        mLastEvent = *rawEvent;
+        mProcessWasCalled = true;
+    }
+
+    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
+        ssize_t index = mKeyCodeStates.indexOfKey(keyCode);
+        return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
+    }
+
+    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
+        ssize_t index = mScanCodeStates.indexOfKey(scanCode);
+        return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
+    }
+
+    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode) {
+        ssize_t index = mSwitchStates.indexOfKey(switchCode);
+        return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN;
+    }
+
+    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
+            const int32_t* keyCodes, uint8_t* outFlags) {
+        bool result = false;
+        for (size_t i = 0; i < numCodes; i++) {
+            for (size_t j = 0; j < mSupportedKeyCodes.size(); j++) {
+                if (keyCodes[i] == mSupportedKeyCodes[j]) {
+                    outFlags[i] = 1;
+                    result = true;
+                }
+            }
+        }
+        return result;
+    }
+
+    virtual int32_t getMetaState() {
+        return mMetaState;
+    }
+
+    virtual void fadePointer() {
+    }
+};
+
+
+// --- InstrumentedInputReader ---
+
+class InstrumentedInputReader : public InputReader {
+    InputDevice* mNextDevice;
+
+public:
+    InstrumentedInputReader(const sp<EventHubInterface>& eventHub,
+            const sp<InputReaderPolicyInterface>& policy,
+            const sp<InputListenerInterface>& listener) :
+            InputReader(eventHub, policy, listener),
+            mNextDevice(NULL) {
+    }
+
+    virtual ~InstrumentedInputReader() {
+        if (mNextDevice) {
+            delete mNextDevice;
+        }
+    }
+
+    void setNextDevice(InputDevice* device) {
+        mNextDevice = device;
+    }
+
+    InputDevice* newDevice(int32_t deviceId, int32_t controllerNumber, const String8& name,
+            uint32_t classes) {
+        InputDeviceIdentifier identifier;
+        identifier.name = name;
+        int32_t generation = deviceId + 1;
+        return new InputDevice(&mContext, deviceId, generation, controllerNumber, identifier,
+                classes);
+    }
+
+protected:
+    virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
+            const InputDeviceIdentifier& identifier, uint32_t classes) {
+        if (mNextDevice) {
+            InputDevice* device = mNextDevice;
+            mNextDevice = NULL;
+            return device;
+        }
+        return InputReader::createDeviceLocked(deviceId, controllerNumber, identifier, classes);
+    }
+
+    friend class InputReaderTest;
+};
+
+
+// --- InputReaderTest ---
+
+class InputReaderTest : public testing::Test {
+protected:
+    sp<FakeInputListener> mFakeListener;
+    sp<FakeInputReaderPolicy> mFakePolicy;
+    sp<FakeEventHub> mFakeEventHub;
+    sp<InstrumentedInputReader> mReader;
+
+    virtual void SetUp() {
+        mFakeEventHub = new FakeEventHub();
+        mFakePolicy = new FakeInputReaderPolicy();
+        mFakeListener = new FakeInputListener();
+
+        mReader = new InstrumentedInputReader(mFakeEventHub, mFakePolicy, mFakeListener);
+    }
+
+    virtual void TearDown() {
+        mReader.clear();
+
+        mFakeListener.clear();
+        mFakePolicy.clear();
+        mFakeEventHub.clear();
+    }
+
+    void addDevice(int32_t deviceId, const String8& name, uint32_t classes,
+            const PropertyMap* configuration) {
+        mFakeEventHub->addDevice(deviceId, name, classes);
+
+        if (configuration) {
+            mFakeEventHub->addConfigurationMap(deviceId, configuration);
+        }
+        mFakeEventHub->finishDeviceScan();
+        mReader->loopOnce();
+        mReader->loopOnce();
+        mFakeEventHub->assertQueueIsEmpty();
+    }
+
+    FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, int32_t controllerNumber,
+            const String8& name, uint32_t classes, uint32_t sources,
+            const PropertyMap* configuration) {
+        InputDevice* device = mReader->newDevice(deviceId, controllerNumber, name, classes);
+        FakeInputMapper* mapper = new FakeInputMapper(device, sources);
+        device->addMapper(mapper);
+        mReader->setNextDevice(device);
+        addDevice(deviceId, name, classes, configuration);
+        return mapper;
+    }
+};
+
+TEST_F(InputReaderTest, GetInputDevices) {
+    ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"),
+            INPUT_DEVICE_CLASS_KEYBOARD, NULL));
+    ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("ignored"),
+            0, NULL)); // no classes so device will be ignored
+
+    Vector<InputDeviceInfo> inputDevices;
+    mReader->getInputDevices(inputDevices);
+
+    ASSERT_EQ(1U, inputDevices.size());
+    ASSERT_EQ(1, inputDevices[0].getId());
+    ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string());
+    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType());
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources());
+    ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size());
+
+    // Should also have received a notification describing the new input devices.
+    inputDevices = mFakePolicy->getInputDevices();
+    ASSERT_EQ(1U, inputDevices.size());
+    ASSERT_EQ(1, inputDevices[0].getId());
+    ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string());
+    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType());
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources());
+    ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size());
+}
+
+TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) {
+    FakeInputMapper* mapper = NULL;
+    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
+            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
+    mapper->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN);
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(0,
+            AINPUT_SOURCE_ANY, AKEYCODE_A))
+            << "Should return unknown when the device id is >= 0 but unknown.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(1,
+            AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return unknown when the device id is valid but the sources are not supported by the device.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(1,
+            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(-1,
+            AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return unknown when the device id is < 0 but the sources are not supported by any device.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(-1,
+            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
+}
+
+TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) {
+    FakeInputMapper* mapper = NULL;
+    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
+            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
+    mapper->setScanCodeState(KEY_A, AKEY_STATE_DOWN);
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(0,
+            AINPUT_SOURCE_ANY, KEY_A))
+            << "Should return unknown when the device id is >= 0 but unknown.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(1,
+            AINPUT_SOURCE_TRACKBALL, KEY_A))
+            << "Should return unknown when the device id is valid but the sources are not supported by the device.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(1,
+            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A))
+            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(-1,
+            AINPUT_SOURCE_TRACKBALL, KEY_A))
+            << "Should return unknown when the device id is < 0 but the sources are not supported by any device.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(-1,
+            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A))
+            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
+}
+
+TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) {
+    FakeInputMapper* mapper = NULL;
+    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
+            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
+    mapper->setSwitchState(SW_LID, AKEY_STATE_DOWN);
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(0,
+            AINPUT_SOURCE_ANY, SW_LID))
+            << "Should return unknown when the device id is >= 0 but unknown.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(1,
+            AINPUT_SOURCE_TRACKBALL, SW_LID))
+            << "Should return unknown when the device id is valid but the sources are not supported by the device.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(1,
+            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID))
+            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(-1,
+            AINPUT_SOURCE_TRACKBALL, SW_LID))
+            << "Should return unknown when the device id is < 0 but the sources are not supported by any device.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(-1,
+            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID))
+            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
+}
+
+TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) {
+    FakeInputMapper* mapper = NULL;
+    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
+            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
+    mapper->addSupportedKeyCode(AKEYCODE_A);
+    mapper->addSupportedKeyCode(AKEYCODE_B);
+
+    const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 };
+    uint8_t flags[4] = { 0, 0, 0, 1 };
+
+    ASSERT_FALSE(mReader->hasKeys(0, AINPUT_SOURCE_ANY, 4, keyCodes, flags))
+            << "Should return false when device id is >= 0 but unknown.";
+    ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]);
+
+    flags[3] = 1;
+    ASSERT_FALSE(mReader->hasKeys(1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
+            << "Should return false when device id is valid but the sources are not supported by the device.";
+    ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]);
+
+    flags[3] = 1;
+    ASSERT_TRUE(mReader->hasKeys(1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
+            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
+    ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]);
+
+    flags[3] = 1;
+    ASSERT_FALSE(mReader->hasKeys(-1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
+            << "Should return false when the device id is < 0 but the sources are not supported by any device.";
+    ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]);
+
+    flags[3] = 1;
+    ASSERT_TRUE(mReader->hasKeys(-1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
+            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
+    ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]);
+}
+
+TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) {
+    addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, NULL);
+
+    NotifyConfigurationChangedArgs args;
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(&args));
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+}
+
+TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) {
+    FakeInputMapper* mapper = NULL;
+    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
+            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
+
+    mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, 1);
+    mReader->loopOnce();
+    ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty());
+
+    RawEvent event;
+    ASSERT_NO_FATAL_FAILURE(mapper->assertProcessWasCalled(&event));
+    ASSERT_EQ(0, event.when);
+    ASSERT_EQ(1, event.deviceId);
+    ASSERT_EQ(EV_KEY, event.type);
+    ASSERT_EQ(KEY_A, event.code);
+    ASSERT_EQ(1, event.value);
+}
+
+
+// --- InputDeviceTest ---
+
+class InputDeviceTest : public testing::Test {
+protected:
+    static const char* DEVICE_NAME;
+    static const int32_t DEVICE_ID;
+    static const int32_t DEVICE_GENERATION;
+    static const int32_t DEVICE_CONTROLLER_NUMBER;
+    static const uint32_t DEVICE_CLASSES;
+
+    sp<FakeEventHub> mFakeEventHub;
+    sp<FakeInputReaderPolicy> mFakePolicy;
+    sp<FakeInputListener> mFakeListener;
+    FakeInputReaderContext* mFakeContext;
+
+    InputDevice* mDevice;
+
+    virtual void SetUp() {
+        mFakeEventHub = new FakeEventHub();
+        mFakePolicy = new FakeInputReaderPolicy();
+        mFakeListener = new FakeInputListener();
+        mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener);
+
+        mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0);
+        InputDeviceIdentifier identifier;
+        identifier.name = DEVICE_NAME;
+        mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION,
+                DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
+    }
+
+    virtual void TearDown() {
+        delete mDevice;
+
+        delete mFakeContext;
+        mFakeListener.clear();
+        mFakePolicy.clear();
+        mFakeEventHub.clear();
+    }
+};
+
+const char* InputDeviceTest::DEVICE_NAME = "device";
+const int32_t InputDeviceTest::DEVICE_ID = 1;
+const int32_t InputDeviceTest::DEVICE_GENERATION = 2;
+const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0;
+const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD
+        | INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_JOYSTICK;
+
+TEST_F(InputDeviceTest, ImmutableProperties) {
+    ASSERT_EQ(DEVICE_ID, mDevice->getId());
+    ASSERT_STREQ(DEVICE_NAME, mDevice->getName());
+    ASSERT_EQ(DEVICE_CLASSES, mDevice->getClasses());
+}
+
+TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) {
+    // Configuration.
+    InputReaderConfiguration config;
+    mDevice->configure(ARBITRARY_TIME, &config, 0);
+
+    // Reset.
+    mDevice->reset(ARBITRARY_TIME);
+
+    NotifyDeviceResetArgs resetArgs;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
+    ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
+
+    // Metadata.
+    ASSERT_TRUE(mDevice->isIgnored());
+    ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mDevice->getSources());
+
+    InputDeviceInfo info;
+    mDevice->getDeviceInfo(&info);
+    ASSERT_EQ(DEVICE_ID, info.getId());
+    ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string());
+    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType());
+    ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, info.getSources());
+
+    // State queries.
+    ASSERT_EQ(0, mDevice->getMetaState());
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, 0))
+            << "Ignored device should return unknown key code state.";
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 0))
+            << "Ignored device should return unknown scan code state.";
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 0))
+            << "Ignored device should return unknown switch state.";
+
+    const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B };
+    uint8_t flags[2] = { 0, 1 };
+    ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 2, keyCodes, flags))
+            << "Ignored device should never mark any key codes.";
+    ASSERT_EQ(0, flags[0]) << "Flag for unsupported key should be unchanged.";
+    ASSERT_EQ(1, flags[1]) << "Flag for unsupported key should be unchanged.";
+}
+
+TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) {
+    // Configuration.
+    mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8("key"), String8("value"));
+
+    FakeInputMapper* mapper1 = new FakeInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD);
+    mapper1->setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    mapper1->setMetaState(AMETA_ALT_ON);
+    mapper1->addSupportedKeyCode(AKEYCODE_A);
+    mapper1->addSupportedKeyCode(AKEYCODE_B);
+    mapper1->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN);
+    mapper1->setKeyCodeState(AKEYCODE_B, AKEY_STATE_UP);
+    mapper1->setScanCodeState(2, AKEY_STATE_DOWN);
+    mapper1->setScanCodeState(3, AKEY_STATE_UP);
+    mapper1->setSwitchState(4, AKEY_STATE_DOWN);
+    mDevice->addMapper(mapper1);
+
+    FakeInputMapper* mapper2 = new FakeInputMapper(mDevice, AINPUT_SOURCE_TOUCHSCREEN);
+    mapper2->setMetaState(AMETA_SHIFT_ON);
+    mDevice->addMapper(mapper2);
+
+    InputReaderConfiguration config;
+    mDevice->configure(ARBITRARY_TIME, &config, 0);
+
+    String8 propertyValue;
+    ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue))
+            << "Device should have read configuration during configuration phase.";
+    ASSERT_STREQ("value", propertyValue.string());
+
+    ASSERT_NO_FATAL_FAILURE(mapper1->assertConfigureWasCalled());
+    ASSERT_NO_FATAL_FAILURE(mapper2->assertConfigureWasCalled());
+
+    // Reset
+    mDevice->reset(ARBITRARY_TIME);
+    ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled());
+    ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled());
+
+    NotifyDeviceResetArgs resetArgs;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
+    ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
+
+    // Metadata.
+    ASSERT_FALSE(mDevice->isIgnored());
+    ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources());
+
+    InputDeviceInfo info;
+    mDevice->getDeviceInfo(&info);
+    ASSERT_EQ(DEVICE_ID, info.getId());
+    ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string());
+    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType());
+    ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), info.getSources());
+
+    // State queries.
+    ASSERT_EQ(AMETA_ALT_ON | AMETA_SHIFT_ON, mDevice->getMetaState())
+            << "Should query mappers and combine meta states.";
+
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return unknown key code state when source not supported.";
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return unknown scan code state when source not supported.";
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
+            << "Should return unknown switch state when source not supported.";
+
+    ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, AKEYCODE_A))
+            << "Should query mapper when source is supported.";
+    ASSERT_EQ(AKEY_STATE_UP, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 3))
+            << "Should query mapper when source is supported.";
+    ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 4))
+            << "Should query mapper when source is supported.";
+
+    const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 };
+    uint8_t flags[4] = { 0, 0, 0, 1 };
+    ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
+            << "Should do nothing when source is unsupported.";
+    ASSERT_EQ(0, flags[0]) << "Flag should be unchanged when source is unsupported.";
+    ASSERT_EQ(0, flags[1]) << "Flag should be unchanged when source is unsupported.";
+    ASSERT_EQ(0, flags[2]) << "Flag should be unchanged when source is unsupported.";
+    ASSERT_EQ(1, flags[3]) << "Flag should be unchanged when source is unsupported.";
+
+    ASSERT_TRUE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 4, keyCodes, flags))
+            << "Should query mapper when source is supported.";
+    ASSERT_EQ(1, flags[0]) << "Flag for supported key should be set.";
+    ASSERT_EQ(1, flags[1]) << "Flag for supported key should be set.";
+    ASSERT_EQ(0, flags[2]) << "Flag for unsupported key should be unchanged.";
+    ASSERT_EQ(1, flags[3]) << "Flag for unsupported key should be unchanged.";
+
+    // Event handling.
+    RawEvent event;
+    mDevice->process(&event, 1);
+
+    ASSERT_NO_FATAL_FAILURE(mapper1->assertProcessWasCalled());
+    ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled());
+}
+
+
+// --- InputMapperTest ---
+
+class InputMapperTest : public testing::Test {
+protected:
+    static const char* DEVICE_NAME;
+    static const int32_t DEVICE_ID;
+    static const int32_t DEVICE_GENERATION;
+    static const int32_t DEVICE_CONTROLLER_NUMBER;
+    static const uint32_t DEVICE_CLASSES;
+
+    sp<FakeEventHub> mFakeEventHub;
+    sp<FakeInputReaderPolicy> mFakePolicy;
+    sp<FakeInputListener> mFakeListener;
+    FakeInputReaderContext* mFakeContext;
+    InputDevice* mDevice;
+
+    virtual void SetUp() {
+        mFakeEventHub = new FakeEventHub();
+        mFakePolicy = new FakeInputReaderPolicy();
+        mFakeListener = new FakeInputListener();
+        mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener);
+        InputDeviceIdentifier identifier;
+        identifier.name = DEVICE_NAME;
+        mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION,
+                DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
+
+        mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0);
+    }
+
+    virtual void TearDown() {
+        delete mDevice;
+        delete mFakeContext;
+        mFakeListener.clear();
+        mFakePolicy.clear();
+        mFakeEventHub.clear();
+    }
+
+    void addConfigurationProperty(const char* key, const char* value) {
+        mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8(key), String8(value));
+    }
+
+    void addMapperAndConfigure(InputMapper* mapper) {
+        mDevice->addMapper(mapper);
+        mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
+        mDevice->reset(ARBITRARY_TIME);
+    }
+
+    void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height,
+            int32_t orientation) {
+        mFakePolicy->setDisplayInfo(displayId, width, height, orientation);
+        mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+                InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+    }
+
+    static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type,
+            int32_t code, int32_t value) {
+        RawEvent event;
+        event.when = when;
+        event.deviceId = deviceId;
+        event.type = type;
+        event.code = code;
+        event.value = value;
+        mapper->process(&event);
+    }
+
+    static void assertMotionRange(const InputDeviceInfo& info,
+            int32_t axis, uint32_t source, float min, float max, float flat, float fuzz) {
+        const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source);
+        ASSERT_TRUE(range != NULL) << "Axis: " << axis << " Source: " << source;
+        ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source;
+        ASSERT_EQ(source, range->source) << "Axis: " << axis << " Source: " << source;
+        ASSERT_NEAR(min, range->min, EPSILON) << "Axis: " << axis << " Source: " << source;
+        ASSERT_NEAR(max, range->max, EPSILON) << "Axis: " << axis << " Source: " << source;
+        ASSERT_NEAR(flat, range->flat, EPSILON) << "Axis: " << axis << " Source: " << source;
+        ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source;
+    }
+
+    static void assertPointerCoords(const PointerCoords& coords,
+            float x, float y, float pressure, float size,
+            float touchMajor, float touchMinor, float toolMajor, float toolMinor,
+            float orientation, float distance) {
+        ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+        ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
+        ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON);
+        ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON);
+        ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), 1);
+        ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), 1);
+        ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), 1);
+        ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), 1);
+        ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON);
+        ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON);
+    }
+
+    static void assertPosition(const sp<FakePointerController>& controller, float x, float y) {
+        float actualX, actualY;
+        controller->getPosition(&actualX, &actualY);
+        ASSERT_NEAR(x, actualX, 1);
+        ASSERT_NEAR(y, actualY, 1);
+    }
+};
+
+const char* InputMapperTest::DEVICE_NAME = "device";
+const int32_t InputMapperTest::DEVICE_ID = 1;
+const int32_t InputMapperTest::DEVICE_GENERATION = 2;
+const int32_t InputMapperTest::DEVICE_CONTROLLER_NUMBER = 0;
+const uint32_t InputMapperTest::DEVICE_CLASSES = 0; // not needed for current tests
+
+
+// --- SwitchInputMapperTest ---
+
+class SwitchInputMapperTest : public InputMapperTest {
+protected:
+};
+
+TEST_F(SwitchInputMapperTest, GetSources) {
+    SwitchInputMapper* mapper = new SwitchInputMapper(mDevice);
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper->getSources());
+}
+
+TEST_F(SwitchInputMapperTest, GetSwitchState) {
+    SwitchInputMapper* mapper = new SwitchInputMapper(mDevice);
+    addMapperAndConfigure(mapper);
+
+    mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 1);
+    ASSERT_EQ(1, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
+
+    mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 0);
+    ASSERT_EQ(0, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
+}
+
+TEST_F(SwitchInputMapperTest, Process) {
+    SwitchInputMapper* mapper = new SwitchInputMapper(mDevice);
+    addMapperAndConfigure(mapper);
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_HEADPHONE_INSERT, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+
+    NotifySwitchArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args));
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT), args.switchValues);
+    ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT),
+            args.switchMask);
+    ASSERT_EQ(uint32_t(0), args.policyFlags);
+}
+
+
+// --- KeyboardInputMapperTest ---
+
+class KeyboardInputMapperTest : public InputMapperTest {
+protected:
+    void testDPadKeyRotation(KeyboardInputMapper* mapper,
+            int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode);
+};
+
+void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper,
+        int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode) {
+    NotifyKeyArgs args;
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 1);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(originalScanCode, args.scanCode);
+    ASSERT_EQ(rotatedKeyCode, args.keyCode);
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(originalScanCode, args.scanCode);
+    ASSERT_EQ(rotatedKeyCode, args.keyCode);
+}
+
+
+TEST_F(KeyboardInputMapperTest, GetSources) {
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, mapper->getSources());
+}
+
+TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
+    const int32_t USAGE_A = 0x070004;
+    const int32_t USAGE_UNKNOWN = 0x07ffff;
+    mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE);
+    mFakeEventHub->addKey(DEVICE_ID, 0, USAGE_A, AKEYCODE_A, POLICY_FLAG_WAKE);
+
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    // Key down by scan code.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_HOME, 1);
+    NotifyKeyArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
+    ASSERT_EQ(KEY_HOME, args.scanCode);
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
+    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Key up by scan code.
+    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
+            EV_KEY, KEY_HOME, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
+    ASSERT_EQ(KEY_HOME, args.scanCode);
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
+    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Key down by usage code.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_MSC, MSC_SCAN, USAGE_A);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, 0, 1);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(AKEYCODE_A, args.keyCode);
+    ASSERT_EQ(0, args.scanCode);
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
+    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Key up by usage code.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_MSC, MSC_SCAN, USAGE_A);
+    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
+            EV_KEY, 0, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(AKEYCODE_A, args.keyCode);
+    ASSERT_EQ(0, args.scanCode);
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
+    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Key down with unknown scan code or usage code.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_UNKNOWN, 1);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(0, args.keyCode);
+    ASSERT_EQ(KEY_UNKNOWN, args.scanCode);
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
+    ASSERT_EQ(0U, args.policyFlags);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Key up with unknown scan code or usage code.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
+    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
+            EV_KEY, KEY_UNKNOWN, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(0, args.keyCode);
+    ASSERT_EQ(KEY_UNKNOWN, args.scanCode);
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
+    ASSERT_EQ(0U, args.policyFlags);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+}
+
+TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) {
+    mFakeEventHub->addKey(DEVICE_ID, KEY_LEFTSHIFT, 0, AKEYCODE_SHIFT_LEFT, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0);
+
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    // Initial metastate.
+    ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
+
+    // Metakey down.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_LEFTSHIFT, 1);
+    NotifyKeyArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState());
+    ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled());
+
+    // Key down.
+    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
+            EV_KEY, KEY_A, 1);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState());
+
+    // Key up.
+    process(mapper, ARBITRARY_TIME + 2, DEVICE_ID,
+            EV_KEY, KEY_A, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState());
+
+    // Metakey up.
+    process(mapper, ARBITRARY_TIME + 3, DEVICE_ID,
+            EV_KEY, KEY_LEFTSHIFT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AMETA_NONE, args.metaState);
+    ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
+    ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled());
+}
+
+TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateDPad) {
+    mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0);
+
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_90);
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT));
+}
+
+TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
+    mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0);
+
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addConfigurationProperty("keyboard.orientationAware", "1");
+    addMapperAndConfigure(mapper);
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_0);
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT));
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_90);
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN));
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_180);
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_LEFT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_UP));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT));
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_270);
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_DOWN));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_LEFT));
+    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
+            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_UP));
+
+    // Special case: if orientation changes while key is down, we still emit the same keycode
+    // in the key up as we did in the key down.
+    NotifyKeyArgs args;
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_270);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(KEY_UP, args.scanCode);
+    ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode);
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_180);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(KEY_UP, args.scanCode);
+    ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode);
+}
+
+TEST_F(KeyboardInputMapperTest, GetKeyCodeState) {
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 1);
+    ASSERT_EQ(1, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A));
+
+    mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 0);
+    ASSERT_EQ(0, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A));
+}
+
+TEST_F(KeyboardInputMapperTest, GetScanCodeState) {
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 1);
+    ASSERT_EQ(1, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A));
+
+    mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 0);
+    ASSERT_EQ(0, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A));
+}
+
+TEST_F(KeyboardInputMapperTest, MarkSupportedKeyCodes) {
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0);
+
+    const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B };
+    uint8_t flags[2] = { 0, 0 };
+    ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 1, keyCodes, flags));
+    ASSERT_TRUE(flags[0]);
+    ASSERT_FALSE(flags[1]);
+}
+
+TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds) {
+    mFakeEventHub->addLed(DEVICE_ID, LED_CAPSL, true /*initially on*/);
+    mFakeEventHub->addLed(DEVICE_ID, LED_NUML, false /*initially off*/);
+    mFakeEventHub->addLed(DEVICE_ID, LED_SCROLLL, false /*initially off*/);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_CAPSLOCK, 0, AKEYCODE_CAPS_LOCK, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_NUMLOCK, 0, AKEYCODE_NUM_LOCK, 0);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0);
+
+    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
+            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
+    addMapperAndConfigure(mapper);
+
+    // Initialization should have turned all of the lights off.
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+
+    // Toggle caps lock on.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_CAPSLOCK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_CAPSLOCK, 0);
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+    ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper->getMetaState());
+
+    // Toggle num lock on.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_NUMLOCK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_NUMLOCK, 0);
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+    ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper->getMetaState());
+
+    // Toggle caps lock off.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_CAPSLOCK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_CAPSLOCK, 0);
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+    ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper->getMetaState());
+
+    // Toggle scroll lock on.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_SCROLLLOCK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_SCROLLLOCK, 0);
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+    ASSERT_EQ(AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper->getMetaState());
+
+    // Toggle num lock off.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_NUMLOCK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_NUMLOCK, 0);
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+    ASSERT_EQ(AMETA_SCROLL_LOCK_ON, mapper->getMetaState());
+
+    // Toggle scroll lock off.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_SCROLLLOCK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID,
+            EV_KEY, KEY_SCROLLLOCK, 0);
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
+    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
+    ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
+}
+
+
+// --- CursorInputMapperTest ---
+
+class CursorInputMapperTest : public InputMapperTest {
+protected:
+    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD;
+
+    sp<FakePointerController> mFakePointerController;
+
+    virtual void SetUp() {
+        InputMapperTest::SetUp();
+
+        mFakePointerController = new FakePointerController();
+        mFakePolicy->setPointerController(DEVICE_ID, mFakePointerController);
+    }
+
+    void testMotionRotation(CursorInputMapper* mapper,
+            int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY);
+};
+
+const int32_t CursorInputMapperTest::TRACKBALL_MOVEMENT_THRESHOLD = 6;
+
+void CursorInputMapperTest::testMotionRotation(CursorInputMapper* mapper,
+        int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY) {
+    NotifyMotionArgs args;
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, originalX);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, originalY);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD,
+            float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD,
+            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+}
+
+TEST_F(CursorInputMapperTest, WhenModeIsPointer_GetSources_ReturnsMouse) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "pointer");
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources());
+}
+
+TEST_F(CursorInputMapperTest, WhenModeIsNavigation_GetSources_ReturnsTrackball) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, mapper->getSources());
+}
+
+TEST_F(CursorInputMapperTest, WhenModeIsPointer_PopulateDeviceInfo_ReturnsRangeFromPointerController) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "pointer");
+    addMapperAndConfigure(mapper);
+
+    InputDeviceInfo info;
+    mapper->populateDeviceInfo(&info);
+
+    // Initially there may not be a valid motion range.
+    ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE));
+    ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE));
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
+            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, 0.0f, 1.0f, 0.0f, 0.0f));
+
+    // When the bounds are set, then there should be a valid motion range.
+    mFakePointerController->setBounds(1, 2, 800 - 1, 480 - 1);
+
+    InputDeviceInfo info2;
+    mapper->populateDeviceInfo(&info2);
+
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2,
+            AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE,
+            1, 800 - 1, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2,
+            AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE,
+            2, 480 - 1, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2,
+            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE,
+            0.0f, 1.0f, 0.0f, 0.0f));
+}
+
+TEST_F(CursorInputMapperTest, WhenModeIsNavigation_PopulateDeviceInfo_ReturnsScaledRange) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    InputDeviceInfo info;
+    mapper->populateDeviceInfo(&info);
+
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
+            AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_TRACKBALL,
+            -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD));
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
+            AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_TRACKBALL,
+            -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD));
+    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
+            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TRACKBALL,
+            0.0f, 1.0f, 0.0f, 0.0f));
+}
+
+TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaState) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyMotionArgs args;
+
+    // Button press.
+    // Mostly testing non x/y behavior here so we don't need to check again elsewhere.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source);
+    ASSERT_EQ(uint32_t(0), args.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(0, args.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, args.buttonState);
+    ASSERT_EQ(0, args.edgeFlags);
+    ASSERT_EQ(uint32_t(1), args.pointerCount);
+    ASSERT_EQ(0, args.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
+    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Button release.  Should have same down time.
+    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_KEY, BTN_MOUSE, 0);
+    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source);
+    ASSERT_EQ(uint32_t(0), args.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(0, args.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(0, args.buttonState);
+    ASSERT_EQ(0, args.edgeFlags);
+    ASSERT_EQ(uint32_t(1), args.pointerCount);
+    ASSERT_EQ(0, args.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
+    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+}
+
+TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs args;
+
+    // Motion in X but not Y.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    // Motion in Y but not X.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+}
+
+TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs args;
+
+    // Button press.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    // Button release.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+}
+
+TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs args;
+
+    // Combined X, Y and Button.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD,
+            1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    // Move X, Y a bit while pressed.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 2);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD,
+            1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    // Release Button.
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+}
+
+TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addMapperAndConfigure(mapper);
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT,
+            DISPLAY_ORIENTATION_90);
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0, -1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1,  1));
+}
+
+TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "navigation");
+    addConfigurationProperty("cursor.orientationAware", "1");
+    addMapperAndConfigure(mapper);
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0);
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0, -1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1,  1));
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_90);
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  0, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1, -1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1, -1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  0,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1,  1,  1));
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_180);
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1, -1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0, -1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1, -1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1,  1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1,  1, -1));
+
+    setDisplayInfoAndReconfigure(DISPLAY_ID,
+            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_270);
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1, -1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1, -1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  0,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1,  1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  1,  0));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1,  1, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  0, -1));
+    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1, -1));
+}
+
+TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "pointer");
+    addMapperAndConfigure(mapper);
+
+    mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
+    mFakePointerController->setPosition(100, 200);
+    mFakePointerController->setButtonState(0);
+
+    NotifyMotionArgs motionArgs;
+    NotifyKeyArgs keyArgs;
+
+    // press BTN_LEFT, release BTN_LEFT
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState());
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
+            motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
+            mFakePointerController->getButtonState());
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    // press BTN_BACK, release BTN_BACK
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+
+    // press BTN_SIDE, release BTN_SIDE
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+
+    // press BTN_FORWARD, release BTN_FORWARD
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+
+    // press BTN_EXTRA, release BTN_EXTRA
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 0);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, mFakePointerController->getButtonState());
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+}
+
+TEST_F(CursorInputMapperTest, Process_WhenModeIsPointer_ShouldMoveThePointerAround) {
+    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
+    addConfigurationProperty("cursor.mode", "pointer");
+    addMapperAndConfigure(mapper);
+
+    mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
+    mFakePointerController->setPosition(100, 200);
+    mFakePointerController->setButtonState(0);
+
+    NotifyMotionArgs args;
+
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 10);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 20);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
+    ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f));
+}
+
+
+// --- TouchInputMapperTest ---
+
+class TouchInputMapperTest : public InputMapperTest {
+protected:
+    static const int32_t RAW_X_MIN;
+    static const int32_t RAW_X_MAX;
+    static const int32_t RAW_Y_MIN;
+    static const int32_t RAW_Y_MAX;
+    static const int32_t RAW_TOUCH_MIN;
+    static const int32_t RAW_TOUCH_MAX;
+    static const int32_t RAW_TOOL_MIN;
+    static const int32_t RAW_TOOL_MAX;
+    static const int32_t RAW_PRESSURE_MIN;
+    static const int32_t RAW_PRESSURE_MAX;
+    static const int32_t RAW_ORIENTATION_MIN;
+    static const int32_t RAW_ORIENTATION_MAX;
+    static const int32_t RAW_DISTANCE_MIN;
+    static const int32_t RAW_DISTANCE_MAX;
+    static const int32_t RAW_TILT_MIN;
+    static const int32_t RAW_TILT_MAX;
+    static const int32_t RAW_ID_MIN;
+    static const int32_t RAW_ID_MAX;
+    static const int32_t RAW_SLOT_MIN;
+    static const int32_t RAW_SLOT_MAX;
+    static const float X_PRECISION;
+    static const float Y_PRECISION;
+
+    static const float GEOMETRIC_SCALE;
+
+    static const VirtualKeyDefinition VIRTUAL_KEYS[2];
+
+    enum Axes {
+        POSITION = 1 << 0,
+        TOUCH = 1 << 1,
+        TOOL = 1 << 2,
+        PRESSURE = 1 << 3,
+        ORIENTATION = 1 << 4,
+        MINOR = 1 << 5,
+        ID = 1 << 6,
+        DISTANCE = 1 << 7,
+        TILT = 1 << 8,
+        SLOT = 1 << 9,
+        TOOL_TYPE = 1 << 10,
+    };
+
+    void prepareDisplay(int32_t orientation);
+    void prepareVirtualKeys();
+    int32_t toRawX(float displayX);
+    int32_t toRawY(float displayY);
+    float toDisplayX(int32_t rawX);
+    float toDisplayY(int32_t rawY);
+};
+
+const int32_t TouchInputMapperTest::RAW_X_MIN = 25;
+const int32_t TouchInputMapperTest::RAW_X_MAX = 1019;
+const int32_t TouchInputMapperTest::RAW_Y_MIN = 30;
+const int32_t TouchInputMapperTest::RAW_Y_MAX = 1009;
+const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0;
+const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31;
+const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0;
+const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15;
+const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = RAW_TOUCH_MIN;
+const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = RAW_TOUCH_MAX;
+const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7;
+const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7;
+const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0;
+const int32_t TouchInputMapperTest::RAW_DISTANCE_MAX = 7;
+const int32_t TouchInputMapperTest::RAW_TILT_MIN = 0;
+const int32_t TouchInputMapperTest::RAW_TILT_MAX = 150;
+const int32_t TouchInputMapperTest::RAW_ID_MIN = 0;
+const int32_t TouchInputMapperTest::RAW_ID_MAX = 9;
+const int32_t TouchInputMapperTest::RAW_SLOT_MIN = 0;
+const int32_t TouchInputMapperTest::RAW_SLOT_MAX = 9;
+const float TouchInputMapperTest::X_PRECISION = float(RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH;
+const float TouchInputMapperTest::Y_PRECISION = float(RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT;
+
+const float TouchInputMapperTest::GEOMETRIC_SCALE =
+        avg(float(DISPLAY_WIDTH) / (RAW_X_MAX - RAW_X_MIN + 1),
+                float(DISPLAY_HEIGHT) / (RAW_Y_MAX - RAW_Y_MIN + 1));
+
+const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = {
+        { KEY_HOME, 60, DISPLAY_HEIGHT + 15, 20, 20 },
+        { KEY_MENU, DISPLAY_HEIGHT - 60, DISPLAY_WIDTH + 15, 20, 20 },
+};
+
+void TouchInputMapperTest::prepareDisplay(int32_t orientation) {
+    setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation);
+}
+
+void TouchInputMapperTest::prepareVirtualKeys() {
+    mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[0]);
+    mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[1]);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE);
+    mFakeEventHub->addKey(DEVICE_ID, KEY_MENU, 0, AKEYCODE_MENU, POLICY_FLAG_WAKE);
+}
+
+int32_t TouchInputMapperTest::toRawX(float displayX) {
+    return int32_t(displayX * (RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH + RAW_X_MIN);
+}
+
+int32_t TouchInputMapperTest::toRawY(float displayY) {
+    return int32_t(displayY * (RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT + RAW_Y_MIN);
+}
+
+float TouchInputMapperTest::toDisplayX(int32_t rawX) {
+    return float(rawX - RAW_X_MIN) * DISPLAY_WIDTH / (RAW_X_MAX - RAW_X_MIN + 1);
+}
+
+float TouchInputMapperTest::toDisplayY(int32_t rawY) {
+    return float(rawY - RAW_Y_MIN) * DISPLAY_HEIGHT / (RAW_Y_MAX - RAW_Y_MIN + 1);
+}
+
+
+// --- SingleTouchInputMapperTest ---
+
+class SingleTouchInputMapperTest : public TouchInputMapperTest {
+protected:
+    void prepareButtons();
+    void prepareAxes(int axes);
+
+    void processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y);
+    void processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y);
+    void processUp(SingleTouchInputMapper* mappery);
+    void processPressure(SingleTouchInputMapper* mapper, int32_t pressure);
+    void processToolMajor(SingleTouchInputMapper* mapper, int32_t toolMajor);
+    void processDistance(SingleTouchInputMapper* mapper, int32_t distance);
+    void processTilt(SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY);
+    void processKey(SingleTouchInputMapper* mapper, int32_t code, int32_t value);
+    void processSync(SingleTouchInputMapper* mapper);
+};
+
+void SingleTouchInputMapperTest::prepareButtons() {
+    mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0);
+}
+
+void SingleTouchInputMapperTest::prepareAxes(int axes) {
+    if (axes & POSITION) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_X,
+                RAW_X_MIN, RAW_X_MAX, 0, 0);
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_Y,
+                RAW_Y_MIN, RAW_Y_MAX, 0, 0);
+    }
+    if (axes & PRESSURE) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_PRESSURE,
+                RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0);
+    }
+    if (axes & TOOL) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TOOL_WIDTH,
+                RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0);
+    }
+    if (axes & DISTANCE) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_DISTANCE,
+                RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0);
+    }
+    if (axes & TILT) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_X,
+                RAW_TILT_MIN, RAW_TILT_MAX, 0, 0);
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_Y,
+                RAW_TILT_MIN, RAW_TILT_MAX, 0, 0);
+    }
+}
+
+void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 1);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y);
+}
+
+void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y);
+}
+
+void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper* mapper) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 0);
+}
+
+void SingleTouchInputMapperTest::processPressure(
+        SingleTouchInputMapper* mapper, int32_t pressure) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_PRESSURE, pressure);
+}
+
+void SingleTouchInputMapperTest::processToolMajor(
+        SingleTouchInputMapper* mapper, int32_t toolMajor) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
+}
+
+void SingleTouchInputMapperTest::processDistance(
+        SingleTouchInputMapper* mapper, int32_t distance) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_DISTANCE, distance);
+}
+
+void SingleTouchInputMapperTest::processTilt(
+        SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_X, tiltX);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_Y, tiltY);
+}
+
+void SingleTouchInputMapperTest::processKey(
+        SingleTouchInputMapper* mapper, int32_t code, int32_t value) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value);
+}
+
+void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper* mapper) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+}
+
+
+TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    prepareButtons();
+    prepareAxes(POSITION);
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources());
+}
+
+TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndIsACursor_ReturnsTouchPad) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_X);
+    mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_Y);
+    prepareButtons();
+    prepareAxes(POSITION);
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources());
+}
+
+TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchPad_ReturnsTouchPad) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    prepareButtons();
+    prepareAxes(POSITION);
+    addConfigurationProperty("touch.deviceType", "touchPad");
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources());
+}
+
+TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchScreen_ReturnsTouchScreen) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    prepareButtons();
+    prepareAxes(POSITION);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    addMapperAndConfigure(mapper);
+
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources());
+}
+
+TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    // Unknown key.
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A));
+
+    // Virtual key is down.
+    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
+    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
+    processDown(mapper, x, y);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
+
+    ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME));
+
+    // Virtual key is up.
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
+
+    ASSERT_EQ(AKEY_STATE_UP, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME));
+}
+
+TEST_F(SingleTouchInputMapperTest, GetScanCodeState) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    // Unknown key.
+    ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A));
+
+    // Virtual key is down.
+    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
+    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
+    processDown(mapper, x, y);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
+
+    ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME));
+
+    // Virtual key is up.
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
+
+    ASSERT_EQ(AKEY_STATE_UP, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME));
+}
+
+TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    const int32_t keys[2] = { AKEYCODE_HOME, AKEYCODE_A };
+    uint8_t flags[2] = { 0, 0 };
+    ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 2, keys, flags));
+    ASSERT_TRUE(flags[0]);
+    ASSERT_FALSE(flags[1]);
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyKeyArgs args;
+
+    // Press virtual key.
+    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
+    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
+    processDown(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags);
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags);
+    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
+    ASSERT_EQ(KEY_HOME, args.scanCode);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Release virtual key.
+    processUp(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
+    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
+    ASSERT_EQ(DEVICE_ID, args.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
+    ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags);
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags);
+    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
+    ASSERT_EQ(KEY_HOME, args.scanCode);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
+    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
+
+    // Should not have sent any motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfBounds_SendsKeyDownAndKeyCancel) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyKeyArgs keyArgs;
+
+    // Press virtual key.
+    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
+    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
+    processDown(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, keyArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source);
+    ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags);
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, keyArgs.flags);
+    ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode);
+    ASSERT_EQ(KEY_HOME, keyArgs.scanCode);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState);
+    ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime);
+
+    // Move out of bounds.  This should generate a cancel and a pointer down since we moved
+    // into the display area.
+    y -= 100;
+    processMove(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, keyArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source);
+    ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags);
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
+            | AKEY_EVENT_FLAG_CANCELED, keyArgs.flags);
+    ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode);
+    ASSERT_EQ(KEY_HOME, keyArgs.scanCode);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState);
+    ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime);
+
+    NotifyMotionArgs motionArgs;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Keep moving out of bounds.  Should generate a pointer move.
+    y -= 50;
+    processMove(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Release out of bounds.  Should generate a pointer up.
+    processUp(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Should not have sent any more keys or motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMovesIn_SendsDownAsTouchEntersDisplay) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyMotionArgs motionArgs;
+
+    // Initially go down out of bounds.
+    int32_t x = -10;
+    int32_t y = -10;
+    processDown(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+
+    // Move into the display area.  Should generate a pointer down.
+    x = 50;
+    y = 75;
+    processMove(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Release.  Should generate a pointer up.
+    processUp(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Should not have sent any more keys or motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyMotionArgs motionArgs;
+
+    // Down.
+    int32_t x = 100;
+    int32_t y = 125;
+    processDown(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Move.
+    x += 50;
+    y += 75;
+    processMove(mapper, x, y);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Up.
+    processUp(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Should not have sent any more keys or motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotateMotions) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareButtons();
+    prepareAxes(POSITION);
+    addConfigurationProperty("touch.orientationAware", "0");
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs args;
+
+    // Rotation 90.
+    prepareDisplay(DISPLAY_ORIENTATION_90);
+    processDown(mapper, toRawX(50), toRawY(75));
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
+
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareButtons();
+    prepareAxes(POSITION);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs args;
+
+    // Rotation 0.
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    processDown(mapper, toRawX(50), toRawY(75));
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
+
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
+
+    // Rotation 90.
+    prepareDisplay(DISPLAY_ORIENTATION_90);
+    processDown(mapper, RAW_X_MAX - toRawX(75) + RAW_X_MIN, toRawY(50));
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
+
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
+
+    // Rotation 180.
+    prepareDisplay(DISPLAY_ORIENTATION_180);
+    processDown(mapper, RAW_X_MAX - toRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRawY(75) + RAW_Y_MIN);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
+
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
+
+    // Rotation 270.
+    prepareDisplay(DISPLAY_ORIENTATION_270);
+    processDown(mapper, toRawX(75), RAW_Y_MAX - toRawY(50) + RAW_Y_MIN);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
+    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
+
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE | TILT);
+    addMapperAndConfigure(mapper);
+
+    // These calculations are based on the input device calibration documentation.
+    int32_t rawX = 100;
+    int32_t rawY = 200;
+    int32_t rawPressure = 10;
+    int32_t rawToolMajor = 12;
+    int32_t rawDistance = 2;
+    int32_t rawTiltX = 30;
+    int32_t rawTiltY = 110;
+
+    float x = toDisplayX(rawX);
+    float y = toDisplayY(rawY);
+    float pressure = float(rawPressure) / RAW_PRESSURE_MAX;
+    float size = float(rawToolMajor) / RAW_TOOL_MAX;
+    float tool = float(rawToolMajor) * GEOMETRIC_SCALE;
+    float distance = float(rawDistance);
+
+    float tiltCenter = (RAW_TILT_MAX + RAW_TILT_MIN) * 0.5f;
+    float tiltScale = M_PI / 180;
+    float tiltXAngle = (rawTiltX - tiltCenter) * tiltScale;
+    float tiltYAngle = (rawTiltY - tiltCenter) * tiltScale;
+    float orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle));
+    float tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle));
+
+    processDown(mapper, rawX, rawY);
+    processPressure(mapper, rawPressure);
+    processToolMajor(mapper, rawToolMajor);
+    processDistance(mapper, rawDistance);
+    processTilt(mapper, rawTiltX, rawTiltY);
+    processSync(mapper);
+
+    NotifyMotionArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            x, y, pressure, size, tool, tool, tool, tool, orientation, distance));
+    ASSERT_EQ(tilt, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TILT));
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+    NotifyKeyArgs keyArgs;
+
+    processDown(mapper, 100, 200);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.buttonState);
+
+    // press BTN_LEFT, release BTN_LEFT
+    processKey(mapper, BTN_LEFT, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
+
+    processKey(mapper, BTN_LEFT, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
+    processKey(mapper, BTN_RIGHT, 1);
+    processKey(mapper, BTN_MIDDLE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
+            motionArgs.buttonState);
+
+    processKey(mapper, BTN_RIGHT, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_MIDDLE, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // press BTN_BACK, release BTN_BACK
+    processKey(mapper, BTN_BACK, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_BACK, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+
+    // press BTN_SIDE, release BTN_SIDE
+    processKey(mapper, BTN_SIDE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_SIDE, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+
+    // press BTN_FORWARD, release BTN_FORWARD
+    processKey(mapper, BTN_FORWARD, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_FORWARD, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+
+    // press BTN_EXTRA, release BTN_EXTRA
+    processKey(mapper, BTN_EXTRA, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_EXTRA, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+
+    // press BTN_STYLUS, release BTN_STYLUS
+    processKey(mapper, BTN_STYLUS, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY, motionArgs.buttonState);
+
+    processKey(mapper, BTN_STYLUS, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // press BTN_STYLUS2, release BTN_STYLUS2
+    processKey(mapper, BTN_STYLUS2, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
+
+    processKey(mapper, BTN_STYLUS2, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // release touch
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.buttonState);
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+
+    // default tool type is finger
+    processDown(mapper, 100, 200);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // eraser
+    processKey(mapper, BTN_TOOL_RUBBER, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
+
+    // stylus
+    processKey(mapper, BTN_TOOL_RUBBER, 0);
+    processKey(mapper, BTN_TOOL_PEN, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // brush
+    processKey(mapper, BTN_TOOL_PEN, 0);
+    processKey(mapper, BTN_TOOL_BRUSH, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // pencil
+    processKey(mapper, BTN_TOOL_BRUSH, 0);
+    processKey(mapper, BTN_TOOL_PENCIL, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // airbrush
+    processKey(mapper, BTN_TOOL_PENCIL, 0);
+    processKey(mapper, BTN_TOOL_AIRBRUSH, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // mouse
+    processKey(mapper, BTN_TOOL_AIRBRUSH, 0);
+    processKey(mapper, BTN_TOOL_MOUSE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
+
+    // lens
+    processKey(mapper, BTN_TOOL_MOUSE, 0);
+    processKey(mapper, BTN_TOOL_LENS, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
+
+    // double-tap
+    processKey(mapper, BTN_TOOL_LENS, 0);
+    processKey(mapper, BTN_TOOL_DOUBLETAP, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // triple-tap
+    processKey(mapper, BTN_TOOL_DOUBLETAP, 0);
+    processKey(mapper, BTN_TOOL_TRIPLETAP, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // quad-tap
+    processKey(mapper, BTN_TOOL_TRIPLETAP, 0);
+    processKey(mapper, BTN_TOOL_QUADTAP, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // finger
+    processKey(mapper, BTN_TOOL_QUADTAP, 0);
+    processKey(mapper, BTN_TOOL_FINGER, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // stylus trumps finger
+    processKey(mapper, BTN_TOOL_PEN, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // eraser trumps stylus
+    processKey(mapper, BTN_TOOL_RUBBER, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
+
+    // mouse trumps eraser
+    processKey(mapper, BTN_TOOL_MOUSE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
+
+    // back to default tool type
+    processKey(mapper, BTN_TOOL_MOUSE, 0);
+    processKey(mapper, BTN_TOOL_RUBBER, 0);
+    processKey(mapper, BTN_TOOL_PEN, 0);
+    processKey(mapper, BTN_TOOL_FINGER, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION);
+    mFakeEventHub->addKey(DEVICE_ID, BTN_TOOL_FINGER, 0, AKEYCODE_UNKNOWN, 0);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+
+    // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0
+    processKey(mapper, BTN_TOOL_FINGER, 1);
+    processMove(mapper, 100, 200);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // move a little
+    processMove(mapper, 150, 250);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // down when BTN_TOUCH is pressed, pressure defaults to 1
+    processKey(mapper, BTN_TOUCH, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // up when BTN_TOUCH is released, hover restored
+    processKey(mapper, BTN_TOUCH, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // exit hover when pointer goes away
+    processKey(mapper, BTN_TOOL_FINGER, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+}
+
+TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsValueIsZero) {
+    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareButtons();
+    prepareAxes(POSITION | PRESSURE);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+
+    // initially hovering because pressure is 0
+    processDown(mapper, 100, 200);
+    processPressure(mapper, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // move a little
+    processMove(mapper, 150, 250);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // down when pressure is non-zero
+    processPressure(mapper, RAW_PRESSURE_MAX);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // up when pressure becomes 0, hover restored
+    processPressure(mapper, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // exit hover when pointer goes away
+    processUp(mapper);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+}
+
+
+// --- MultiTouchInputMapperTest ---
+
+class MultiTouchInputMapperTest : public TouchInputMapperTest {
+protected:
+    void prepareAxes(int axes);
+
+    void processPosition(MultiTouchInputMapper* mapper, int32_t x, int32_t y);
+    void processTouchMajor(MultiTouchInputMapper* mapper, int32_t touchMajor);
+    void processTouchMinor(MultiTouchInputMapper* mapper, int32_t touchMinor);
+    void processToolMajor(MultiTouchInputMapper* mapper, int32_t toolMajor);
+    void processToolMinor(MultiTouchInputMapper* mapper, int32_t toolMinor);
+    void processOrientation(MultiTouchInputMapper* mapper, int32_t orientation);
+    void processPressure(MultiTouchInputMapper* mapper, int32_t pressure);
+    void processDistance(MultiTouchInputMapper* mapper, int32_t distance);
+    void processId(MultiTouchInputMapper* mapper, int32_t id);
+    void processSlot(MultiTouchInputMapper* mapper, int32_t slot);
+    void processToolType(MultiTouchInputMapper* mapper, int32_t toolType);
+    void processKey(MultiTouchInputMapper* mapper, int32_t code, int32_t value);
+    void processMTSync(MultiTouchInputMapper* mapper);
+    void processSync(MultiTouchInputMapper* mapper);
+};
+
+void MultiTouchInputMapperTest::prepareAxes(int axes) {
+    if (axes & POSITION) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_X,
+                RAW_X_MIN, RAW_X_MAX, 0, 0);
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_Y,
+                RAW_Y_MIN, RAW_Y_MAX, 0, 0);
+    }
+    if (axes & TOUCH) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MAJOR,
+                RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0);
+        if (axes & MINOR) {
+            mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MINOR,
+                    RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0);
+        }
+    }
+    if (axes & TOOL) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MAJOR,
+                RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0);
+        if (axes & MINOR) {
+            mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MINOR,
+                    RAW_TOOL_MAX, RAW_TOOL_MAX, 0, 0);
+        }
+    }
+    if (axes & ORIENTATION) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_ORIENTATION,
+                RAW_ORIENTATION_MIN, RAW_ORIENTATION_MAX, 0, 0);
+    }
+    if (axes & PRESSURE) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_PRESSURE,
+                RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0);
+    }
+    if (axes & DISTANCE) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_DISTANCE,
+                RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0);
+    }
+    if (axes & ID) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TRACKING_ID,
+                RAW_ID_MIN, RAW_ID_MAX, 0, 0);
+    }
+    if (axes & SLOT) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_SLOT,
+                RAW_SLOT_MIN, RAW_SLOT_MAX, 0, 0);
+        mFakeEventHub->setAbsoluteAxisValue(DEVICE_ID, ABS_MT_SLOT, 0);
+    }
+    if (axes & TOOL_TYPE) {
+        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOOL_TYPE,
+                0, MT_TOOL_MAX, 0, 0);
+    }
+}
+
+void MultiTouchInputMapperTest::processPosition(
+        MultiTouchInputMapper* mapper, int32_t x, int32_t y) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_X, x);
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_Y, y);
+}
+
+void MultiTouchInputMapperTest::processTouchMajor(
+        MultiTouchInputMapper* mapper, int32_t touchMajor) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MAJOR, touchMajor);
+}
+
+void MultiTouchInputMapperTest::processTouchMinor(
+        MultiTouchInputMapper* mapper, int32_t touchMinor) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MINOR, touchMinor);
+}
+
+void MultiTouchInputMapperTest::processToolMajor(
+        MultiTouchInputMapper* mapper, int32_t toolMajor) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MAJOR, toolMajor);
+}
+
+void MultiTouchInputMapperTest::processToolMinor(
+        MultiTouchInputMapper* mapper, int32_t toolMinor) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MINOR, toolMinor);
+}
+
+void MultiTouchInputMapperTest::processOrientation(
+        MultiTouchInputMapper* mapper, int32_t orientation) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_ORIENTATION, orientation);
+}
+
+void MultiTouchInputMapperTest::processPressure(
+        MultiTouchInputMapper* mapper, int32_t pressure) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_PRESSURE, pressure);
+}
+
+void MultiTouchInputMapperTest::processDistance(
+        MultiTouchInputMapper* mapper, int32_t distance) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_DISTANCE, distance);
+}
+
+void MultiTouchInputMapperTest::processId(
+        MultiTouchInputMapper* mapper, int32_t id) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TRACKING_ID, id);
+}
+
+void MultiTouchInputMapperTest::processSlot(
+        MultiTouchInputMapper* mapper, int32_t slot) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_SLOT, slot);
+}
+
+void MultiTouchInputMapperTest::processToolType(
+        MultiTouchInputMapper* mapper, int32_t toolType) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOOL_TYPE, toolType);
+}
+
+void MultiTouchInputMapperTest::processKey(
+        MultiTouchInputMapper* mapper, int32_t code, int32_t value) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value);
+}
+
+void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0);
+}
+
+void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper* mapper) {
+    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
+}
+
+
+TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyMotionArgs motionArgs;
+
+    // Two fingers down at once.
+    int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
+    processPosition(mapper, x1, y1);
+    processMTSync(mapper);
+    processPosition(mapper, x2, y2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Move.
+    x1 += 10; y1 += 15; x2 += 5; y2 -= 10;
+    processPosition(mapper, x1, y1);
+    processMTSync(mapper);
+    processPosition(mapper, x2, y2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // First finger up.
+    x2 += 15; y2 -= 20;
+    processPosition(mapper, x2, y2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Move.
+    x2 += 20; y2 -= 25;
+    processPosition(mapper, x2, y2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // New finger down.
+    int32_t x3 = 700, y3 = 300;
+    processPosition(mapper, x2, y2);
+    processMTSync(mapper);
+    processPosition(mapper, x3, y3);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Second finger up.
+    x3 += 30; y3 -= 20;
+    processPosition(mapper, x3, y3);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Last finger up.
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
+    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
+    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
+    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.flags);
+    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(0, motionArgs.edgeFlags);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
+    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
+    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
+
+    // Should not have sent any more keys or motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingIds) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | ID);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyMotionArgs motionArgs;
+
+    // Two fingers down at once.
+    int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
+    processPosition(mapper, x1, y1);
+    processId(mapper, 1);
+    processMTSync(mapper);
+    processPosition(mapper, x2, y2);
+    processId(mapper, 2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Move.
+    x1 += 10; y1 += 15; x2 += 5; y2 -= 10;
+    processPosition(mapper, x1, y1);
+    processId(mapper, 1);
+    processMTSync(mapper);
+    processPosition(mapper, x2, y2);
+    processId(mapper, 2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // First finger up.
+    x2 += 15; y2 -= 20;
+    processPosition(mapper, x2, y2);
+    processId(mapper, 2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Move.
+    x2 += 20; y2 -= 25;
+    processPosition(mapper, x2, y2);
+    processId(mapper, 2);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // New finger down.
+    int32_t x3 = 700, y3 = 300;
+    processPosition(mapper, x2, y2);
+    processId(mapper, 2);
+    processMTSync(mapper);
+    processPosition(mapper, x3, y3);
+    processId(mapper, 3);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Second finger up.
+    x3 += 30; y3 -= 20;
+    processPosition(mapper, x3, y3);
+    processId(mapper, 3);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Last finger up.
+    processMTSync(mapper);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Should not have sent any more keys or motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | ID | SLOT);
+    prepareVirtualKeys();
+    addMapperAndConfigure(mapper);
+
+    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
+
+    NotifyMotionArgs motionArgs;
+
+    // Two fingers down at once.
+    int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
+    processPosition(mapper, x1, y1);
+    processId(mapper, 1);
+    processSlot(mapper, 1);
+    processPosition(mapper, x2, y2);
+    processId(mapper, 2);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Move.
+    x1 += 10; y1 += 15; x2 += 5; y2 -= 10;
+    processSlot(mapper, 0);
+    processPosition(mapper, x1, y1);
+    processSlot(mapper, 1);
+    processPosition(mapper, x2, y2);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // First finger up.
+    x2 += 15; y2 -= 20;
+    processSlot(mapper, 0);
+    processId(mapper, -1);
+    processSlot(mapper, 1);
+    processPosition(mapper, x2, y2);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Move.
+    x2 += 20; y2 -= 25;
+    processPosition(mapper, x2, y2);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // New finger down.
+    int32_t x3 = 700, y3 = 300;
+    processPosition(mapper, x2, y2);
+    processSlot(mapper, 0);
+    processId(mapper, 3);
+    processPosition(mapper, x3, y3);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Second finger up.
+    x3 += 30; y3 -= 20;
+    processSlot(mapper, 1);
+    processId(mapper, -1);
+    processSlot(mapper, 0);
+    processPosition(mapper, x3, y3);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            motionArgs.action);
+    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
+            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Last finger up.
+    processId(mapper, -1);
+    processSync(mapper);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
+    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // Should not have sent any more keys or motions.
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | TOUCH | TOOL | PRESSURE | ORIENTATION | ID | MINOR | DISTANCE);
+    addMapperAndConfigure(mapper);
+
+    // These calculations are based on the input device calibration documentation.
+    int32_t rawX = 100;
+    int32_t rawY = 200;
+    int32_t rawTouchMajor = 7;
+    int32_t rawTouchMinor = 6;
+    int32_t rawToolMajor = 9;
+    int32_t rawToolMinor = 8;
+    int32_t rawPressure = 11;
+    int32_t rawDistance = 0;
+    int32_t rawOrientation = 3;
+    int32_t id = 5;
+
+    float x = toDisplayX(rawX);
+    float y = toDisplayY(rawY);
+    float pressure = float(rawPressure) / RAW_PRESSURE_MAX;
+    float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX;
+    float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE;
+    float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE;
+    float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE;
+    float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE;
+    float orientation = float(rawOrientation) / RAW_ORIENTATION_MAX * M_PI_2;
+    float distance = float(rawDistance);
+
+    processPosition(mapper, rawX, rawY);
+    processTouchMajor(mapper, rawTouchMajor);
+    processTouchMinor(mapper, rawTouchMinor);
+    processToolMajor(mapper, rawToolMajor);
+    processToolMinor(mapper, rawToolMinor);
+    processPressure(mapper, rawPressure);
+    processOrientation(mapper, rawOrientation);
+    processDistance(mapper, rawDistance);
+    processId(mapper, id);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    NotifyMotionArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(0, args.pointerProperties[0].id);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            x, y, pressure, size, touchMajor, touchMinor, toolMajor, toolMinor,
+            orientation, distance));
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | TOUCH | TOOL | MINOR);
+    addConfigurationProperty("touch.size.calibration", "geometric");
+    addMapperAndConfigure(mapper);
+
+    // These calculations are based on the input device calibration documentation.
+    int32_t rawX = 100;
+    int32_t rawY = 200;
+    int32_t rawTouchMajor = 140;
+    int32_t rawTouchMinor = 120;
+    int32_t rawToolMajor = 180;
+    int32_t rawToolMinor = 160;
+
+    float x = toDisplayX(rawX);
+    float y = toDisplayY(rawY);
+    float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX;
+    float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE;
+    float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE;
+    float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE;
+    float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE;
+
+    processPosition(mapper, rawX, rawY);
+    processTouchMajor(mapper, rawTouchMajor);
+    processTouchMinor(mapper, rawTouchMinor);
+    processToolMajor(mapper, rawToolMajor);
+    processToolMinor(mapper, rawToolMinor);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    NotifyMotionArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            x, y, 1.0f, size, touchMajor, touchMinor, toolMajor, toolMinor, 0, 0));
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_SummedLinearCalibration) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | TOUCH | TOOL);
+    addConfigurationProperty("touch.size.calibration", "diameter");
+    addConfigurationProperty("touch.size.scale", "10");
+    addConfigurationProperty("touch.size.bias", "160");
+    addConfigurationProperty("touch.size.isSummed", "1");
+    addMapperAndConfigure(mapper);
+
+    // These calculations are based on the input device calibration documentation.
+    // Note: We only provide a single common touch/tool value because the device is assumed
+    //       not to emit separate values for each pointer (isSummed = 1).
+    int32_t rawX = 100;
+    int32_t rawY = 200;
+    int32_t rawX2 = 150;
+    int32_t rawY2 = 250;
+    int32_t rawTouchMajor = 5;
+    int32_t rawToolMajor = 8;
+
+    float x = toDisplayX(rawX);
+    float y = toDisplayY(rawY);
+    float x2 = toDisplayX(rawX2);
+    float y2 = toDisplayY(rawY2);
+    float size = float(rawTouchMajor) / 2 / RAW_TOUCH_MAX;
+    float touch = float(rawTouchMajor) / 2 * 10.0f + 160.0f;
+    float tool = float(rawToolMajor) / 2 * 10.0f + 160.0f;
+
+    processPosition(mapper, rawX, rawY);
+    processTouchMajor(mapper, rawTouchMajor);
+    processToolMajor(mapper, rawToolMajor);
+    processMTSync(mapper);
+    processPosition(mapper, rawX2, rawY2);
+    processTouchMajor(mapper, rawTouchMajor);
+    processToolMajor(mapper, rawToolMajor);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    NotifyMotionArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
+            args.action);
+    ASSERT_EQ(size_t(2), args.pointerCount);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            x, y, 1.0f, size, touch, touch, tool, tool, 0, 0));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[1],
+            x2, y2, 1.0f, size, touch, touch, tool, tool, 0, 0));
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_AreaCalibration) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | TOUCH | TOOL);
+    addConfigurationProperty("touch.size.calibration", "area");
+    addConfigurationProperty("touch.size.scale", "43");
+    addConfigurationProperty("touch.size.bias", "3");
+    addMapperAndConfigure(mapper);
+
+    // These calculations are based on the input device calibration documentation.
+    int32_t rawX = 100;
+    int32_t rawY = 200;
+    int32_t rawTouchMajor = 5;
+    int32_t rawToolMajor = 8;
+
+    float x = toDisplayX(rawX);
+    float y = toDisplayY(rawY);
+    float size = float(rawTouchMajor) / RAW_TOUCH_MAX;
+    float touch = sqrtf(rawTouchMajor) * 43.0f + 3.0f;
+    float tool = sqrtf(rawToolMajor) * 43.0f + 3.0f;
+
+    processPosition(mapper, rawX, rawY);
+    processTouchMajor(mapper, rawTouchMajor);
+    processToolMajor(mapper, rawToolMajor);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    NotifyMotionArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            x, y, 1.0f, size, touch, touch, tool, tool, 0, 0));
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | PRESSURE);
+    addConfigurationProperty("touch.pressure.calibration", "amplitude");
+    addConfigurationProperty("touch.pressure.scale", "0.01");
+    addMapperAndConfigure(mapper);
+
+    // These calculations are based on the input device calibration documentation.
+    int32_t rawX = 100;
+    int32_t rawY = 200;
+    int32_t rawPressure = 60;
+
+    float x = toDisplayX(rawX);
+    float y = toDisplayY(rawY);
+    float pressure = float(rawPressure) * 0.01f;
+
+    processPosition(mapper, rawX, rawY);
+    processPressure(mapper, rawPressure);
+    processMTSync(mapper);
+    processSync(mapper);
+
+    NotifyMotionArgs args;
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
+            x, y, pressure, 0, 0, 0, 0, 0, 0, 0));
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllButtons) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | ID | SLOT);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+    NotifyKeyArgs keyArgs;
+
+    processId(mapper, 1);
+    processPosition(mapper, 100, 200);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.buttonState);
+
+    // press BTN_LEFT, release BTN_LEFT
+    processKey(mapper, BTN_LEFT, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
+
+    processKey(mapper, BTN_LEFT, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
+    processKey(mapper, BTN_RIGHT, 1);
+    processKey(mapper, BTN_MIDDLE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
+            motionArgs.buttonState);
+
+    processKey(mapper, BTN_RIGHT, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_MIDDLE, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // press BTN_BACK, release BTN_BACK
+    processKey(mapper, BTN_BACK, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_BACK, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+
+    // press BTN_SIDE, release BTN_SIDE
+    processKey(mapper, BTN_SIDE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_SIDE, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
+
+    // press BTN_FORWARD, release BTN_FORWARD
+    processKey(mapper, BTN_FORWARD, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_FORWARD, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+
+    // press BTN_EXTRA, release BTN_EXTRA
+    processKey(mapper, BTN_EXTRA, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    processKey(mapper, BTN_EXTRA, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
+    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
+    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
+
+    // press BTN_STYLUS, release BTN_STYLUS
+    processKey(mapper, BTN_STYLUS, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY, motionArgs.buttonState);
+
+    processKey(mapper, BTN_STYLUS, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // press BTN_STYLUS2, release BTN_STYLUS2
+    processKey(mapper, BTN_STYLUS2, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
+
+    processKey(mapper, BTN_STYLUS2, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(0, motionArgs.buttonState);
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+
+    // release touch
+    processId(mapper, -1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_EQ(0, motionArgs.buttonState);
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | ID | SLOT | TOOL_TYPE);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+
+    // default tool type is finger
+    processId(mapper, 1);
+    processPosition(mapper, 100, 200);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // eraser
+    processKey(mapper, BTN_TOOL_RUBBER, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
+
+    // stylus
+    processKey(mapper, BTN_TOOL_RUBBER, 0);
+    processKey(mapper, BTN_TOOL_PEN, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // brush
+    processKey(mapper, BTN_TOOL_PEN, 0);
+    processKey(mapper, BTN_TOOL_BRUSH, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // pencil
+    processKey(mapper, BTN_TOOL_BRUSH, 0);
+    processKey(mapper, BTN_TOOL_PENCIL, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // airbrush
+    processKey(mapper, BTN_TOOL_PENCIL, 0);
+    processKey(mapper, BTN_TOOL_AIRBRUSH, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // mouse
+    processKey(mapper, BTN_TOOL_AIRBRUSH, 0);
+    processKey(mapper, BTN_TOOL_MOUSE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
+
+    // lens
+    processKey(mapper, BTN_TOOL_MOUSE, 0);
+    processKey(mapper, BTN_TOOL_LENS, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
+
+    // double-tap
+    processKey(mapper, BTN_TOOL_LENS, 0);
+    processKey(mapper, BTN_TOOL_DOUBLETAP, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // triple-tap
+    processKey(mapper, BTN_TOOL_DOUBLETAP, 0);
+    processKey(mapper, BTN_TOOL_TRIPLETAP, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // quad-tap
+    processKey(mapper, BTN_TOOL_TRIPLETAP, 0);
+    processKey(mapper, BTN_TOOL_QUADTAP, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // finger
+    processKey(mapper, BTN_TOOL_QUADTAP, 0);
+    processKey(mapper, BTN_TOOL_FINGER, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // stylus trumps finger
+    processKey(mapper, BTN_TOOL_PEN, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // eraser trumps stylus
+    processKey(mapper, BTN_TOOL_RUBBER, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
+
+    // mouse trumps eraser
+    processKey(mapper, BTN_TOOL_MOUSE, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
+
+    // MT tool type trumps BTN tool types: MT_TOOL_FINGER
+    processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+
+    // MT tool type trumps BTN tool types: MT_TOOL_PEN
+    processToolType(mapper, MT_TOOL_PEN);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
+
+    // back to default tool type
+    processToolType(mapper, -1); // use a deliberately undefined tool type, for testing
+    processKey(mapper, BTN_TOOL_MOUSE, 0);
+    processKey(mapper, BTN_TOOL_RUBBER, 0);
+    processKey(mapper, BTN_TOOL_PEN, 0);
+    processKey(mapper, BTN_TOOL_FINGER, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
+    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | ID | SLOT);
+    mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+
+    // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0
+    processId(mapper, 1);
+    processPosition(mapper, 100, 200);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // move a little
+    processPosition(mapper, 150, 250);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // down when BTN_TOUCH is pressed, pressure defaults to 1
+    processKey(mapper, BTN_TOUCH, 1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // up when BTN_TOUCH is released, hover restored
+    processKey(mapper, BTN_TOUCH, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // exit hover when pointer goes away
+    processId(mapper, -1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+}
+
+TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfItsValueIsZero) {
+    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
+    addConfigurationProperty("touch.deviceType", "touchScreen");
+    prepareDisplay(DISPLAY_ORIENTATION_0);
+    prepareAxes(POSITION | ID | SLOT | PRESSURE);
+    addMapperAndConfigure(mapper);
+
+    NotifyMotionArgs motionArgs;
+
+    // initially hovering because pressure is 0
+    processId(mapper, 1);
+    processPosition(mapper, 100, 200);
+    processPressure(mapper, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // move a little
+    processPosition(mapper, 150, 250);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // down when pressure becomes non-zero
+    processPressure(mapper, RAW_PRESSURE_MAX);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    // up when pressure becomes 0, hover restored
+    processPressure(mapper, 0);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+
+    // exit hover when pointer goes away
+    processId(mapper, -1);
+    processSync(mapper);
+    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
+    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
+    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
+            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
+}
+
+
+} // namespace android
diff --git a/media/java/android/media/AmrInputStream.java b/media/java/android/media/AmrInputStream.java
index 8b7eee2..e2115e4 100644
--- a/media/java/android/media/AmrInputStream.java
+++ b/media/java/android/media/AmrInputStream.java
@@ -41,7 +41,7 @@
     private InputStream mInputStream;
     
     // native handle
-    private int mGae;
+    private long mGae;
     
     // result amr stream
     private final byte[] mBuf = new byte[SAMPLES_PER_FRAME * 2];
@@ -130,11 +130,11 @@
     //
     // AudioRecord JNI interface
     //
-    private static native int GsmAmrEncoderNew();
-    private static native void GsmAmrEncoderInitialize(int gae);
-    private static native int GsmAmrEncoderEncode(int gae,
+    private static native long GsmAmrEncoderNew();
+    private static native void GsmAmrEncoderInitialize(long gae);
+    private static native int GsmAmrEncoderEncode(long gae,
             byte[] pcm, int pcmOffset, byte[] amr, int amrOffset) throws IOException;
-    private static native void GsmAmrEncoderCleanup(int gae);
-    private static native void GsmAmrEncoderDelete(int gae);
+    private static native void GsmAmrEncoderCleanup(long gae);
+    private static native void GsmAmrEncoderDelete(long gae);
 
 }
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index f49ef2e..461b52f 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -107,13 +107,13 @@
      * Accessed by native methods: provides access to C++ AudioRecord object
      */
     @SuppressWarnings("unused")
-    private int mNativeRecorderInJavaObj;
+    private long mNativeRecorderInJavaObj;
 
     /**
      * Accessed by native methods: provides access to the callback data.
      */
     @SuppressWarnings("unused")
-    private int mNativeCallbackCookie;
+    private long mNativeCallbackCookie;
 
 
     //---------------------------------------------------------
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 78a37c5..01a6fc2 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -221,13 +221,13 @@
      * Accessed by native methods: provides access to C++ AudioTrack object.
      */
     @SuppressWarnings("unused")
-    private int mNativeTrackInJavaObj;
+    private long mNativeTrackInJavaObj;
     /**
      * Accessed by native methods: provides access to the JNI data (i.e. resources used by
      * the native AudioTrack object, but not stored in it).
      */
     @SuppressWarnings("unused")
-    private int mJniData;
+    private long mJniData;
 
 
     //--------------------------------------------------------------------------
diff --git a/media/java/android/media/FaceDetector.java b/media/java/android/media/FaceDetector.java
index cf900ce..61991e3 100644
--- a/media/java/android/media/FaceDetector.java
+++ b/media/java/android/media/FaceDetector.java
@@ -191,9 +191,9 @@
     native private void fft_get_face(Face face, int i);
     native private void fft_destroy();
 
-    private int     mFD;
-    private int     mSDK;
-    private int     mDCR;
+    private long    mFD;
+    private long    mSDK;
+    private long    mDCR;
     private int     mWidth;
     private int     mHeight;
     private int     mMaxFaces;    
diff --git a/media/java/android/media/JetPlayer.java b/media/java/android/media/JetPlayer.java
index 06cda34..bd91fc5 100644
--- a/media/java/android/media/JetPlayer.java
+++ b/media/java/android/media/JetPlayer.java
@@ -127,7 +127,7 @@
      * Accessed by native methods: provides access to C++ JetPlayer object 
      */
     @SuppressWarnings("unused")
-    private int mNativePlayerInJavaObj;
+    private long mNativePlayerInJavaObj;
 
     
     //--------------------------------------------
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java
index 5175830..ddf88df 100644
--- a/media/java/android/media/MediaCodec.java
+++ b/media/java/android/media/MediaCodec.java
@@ -644,5 +644,5 @@
         native_init();
     }
 
-    private int mNativeContext;
+    private long mNativeContext;
 }
diff --git a/media/java/android/media/MediaCrypto.java b/media/java/android/media/MediaCrypto.java
index 40a1326..c7c3fc2 100644
--- a/media/java/android/media/MediaCrypto.java
+++ b/media/java/android/media/MediaCrypto.java
@@ -88,5 +88,5 @@
         native_init();
     }
 
-    private int mNativeContext;
+    private long mNativeContext;
 }
diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java
index 6b278d4..f5a703b 100644
--- a/media/java/android/media/MediaDrm.java
+++ b/media/java/android/media/MediaDrm.java
@@ -100,7 +100,7 @@
     private EventHandler mEventHandler;
     private OnEventListener mOnEventListener;
 
-    private int mNativeContext;
+    private long mNativeContext;
 
     /**
      * Query if the given scheme identified by its UUID is supported on
diff --git a/media/java/android/media/MediaExtractor.java b/media/java/android/media/MediaExtractor.java
index e558c07..c3e5035 100644
--- a/media/java/android/media/MediaExtractor.java
+++ b/media/java/android/media/MediaExtractor.java
@@ -352,5 +352,5 @@
         native_init();
     }
 
-    private int mNativeContext;
+    private long mNativeContext;
 }
diff --git a/media/java/android/media/MediaMetadataRetriever.java b/media/java/android/media/MediaMetadataRetriever.java
index 9014453..db27d09 100644
--- a/media/java/android/media/MediaMetadataRetriever.java
+++ b/media/java/android/media/MediaMetadataRetriever.java
@@ -42,7 +42,7 @@
 
     // The field below is accessed by native methods
     @SuppressWarnings("unused")
-    private int mNativeContext;
+    private long mNativeContext;
  
     private static final int EMBEDDED_PICTURE_TYPE_ANY = 0xFFFF;
 
diff --git a/media/java/android/media/MediaMuxer.java b/media/java/android/media/MediaMuxer.java
index 65a9308..e5c97e7 100644
--- a/media/java/android/media/MediaMuxer.java
+++ b/media/java/android/media/MediaMuxer.java
@@ -65,8 +65,6 @@
 
 final public class MediaMuxer {
 
-    private int mNativeContext;
-
     static {
         System.loadLibrary("media_jni");
     }
@@ -84,16 +82,16 @@
     };
 
     // All the native functions are listed here.
-    private static native int nativeSetup(FileDescriptor fd, int format);
-    private static native void nativeRelease(int nativeObject);
-    private static native void nativeStart(int nativeObject);
-    private static native void nativeStop(int nativeObject);
-    private static native int nativeAddTrack(int nativeObject, String[] keys,
+    private static native long nativeSetup(FileDescriptor fd, int format);
+    private static native void nativeRelease(long nativeObject);
+    private static native void nativeStart(long nativeObject);
+    private static native void nativeStop(long nativeObject);
+    private static native int nativeAddTrack(long nativeObject, String[] keys,
             Object[] values);
-    private static native void nativeSetOrientationHint(int nativeObject,
+    private static native void nativeSetOrientationHint(long nativeObject,
             int degrees);
-    private static native void nativeSetLocation(int nativeObject, int latitude, int longitude);
-    private static native void nativeWriteSampleData(int nativeObject,
+    private static native void nativeSetLocation(long nativeObject, int latitude, int longitude);
+    private static native void nativeWriteSampleData(long nativeObject,
             int trackIndex, ByteBuffer byteBuf,
             int offset, int size, long presentationTimeUs, int flags);
 
@@ -108,7 +106,7 @@
     private final CloseGuard mCloseGuard = CloseGuard.get();
     private int mLastTrackIndex = -1;
 
-    private int mNativeObject;
+    private long mNativeObject;
 
     /**
      * Constructor.
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 706258a..b34cea8f 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -572,8 +572,8 @@
     // macro invocation in IMediaPlayer.cpp
     private final static String IMEDIA_PLAYER = "android.media.IMediaPlayer";
 
-    private int mNativeContext; // accessed by native methods
-    private int mNativeSurfaceTexture;  // accessed by native methods
+    private long mNativeContext; // accessed by native methods
+    private long mNativeSurfaceTexture;  // accessed by native methods
     private int mListenerContext; // accessed by native methods
     private SurfaceHolder mSurfaceHolder;
     private EventHandler mEventHandler;
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 8dcbd6b..5a9d577 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -81,7 +81,7 @@
 
     // The two fields below are accessed by native methods
     @SuppressWarnings("unused")
-    private int mNativeContext;
+    private long mNativeContext;
 
     @SuppressWarnings("unused")
     private Surface mSurface;
diff --git a/media/java/android/media/MediaRouter.java b/media/java/android/media/MediaRouter.java
index de20227..a4d491d8 100644
--- a/media/java/android/media/MediaRouter.java
+++ b/media/java/android/media/MediaRouter.java
@@ -16,8 +16,6 @@
 
 package android.media;
 
-import com.android.internal.util.Objects;
-
 import android.Manifest;
 import android.app.ActivityThread;
 import android.content.BroadcastReceiver;
@@ -43,6 +41,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
@@ -493,11 +492,11 @@
             boolean volumeChanged = false;
             boolean presentationDisplayChanged = false;
 
-            if (!Objects.equal(route.mName, globalRoute.name)) {
+            if (!Objects.equals(route.mName, globalRoute.name)) {
                 route.mName = globalRoute.name;
                 changed = true;
             }
-            if (!Objects.equal(route.mDescription, globalRoute.description)) {
+            if (!Objects.equals(route.mDescription, globalRoute.description)) {
                 route.mDescription = globalRoute.description;
                 changed = true;
             }
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index de3041e..53835e2 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -301,7 +301,7 @@
         // 148 and up don't seem to have been defined yet.
     };
 
-    private int mNativeContext;
+    private long mNativeContext;
     private Context mContext;
     private String mPackageName;
     private IContentProvider mMediaProvider;
diff --git a/media/java/android/media/RemoteDisplay.java b/media/java/android/media/RemoteDisplay.java
index 7afce1a..4e937a5 100644
--- a/media/java/android/media/RemoteDisplay.java
+++ b/media/java/android/media/RemoteDisplay.java
@@ -38,12 +38,12 @@
     private final Listener mListener;
     private final Handler mHandler;
 
-    private int mPtr;
+    private long mPtr;
 
-    private native int nativeListen(String iface);
-    private native void nativeDispose(int ptr);
-    private native void nativePause(int ptr);
-    private native void nativeResume(int ptr);
+    private native long nativeListen(String iface);
+    private native void nativeDispose(long ptr);
+    private native void nativePause(long ptr);
+    private native void nativeResume(long ptr);
 
     private RemoteDisplay(Listener listener, Handler handler) {
         mListener = listener;
diff --git a/media/java/android/media/SoundPool.java b/media/java/android/media/SoundPool.java
index 06af5de..fbfc574 100644
--- a/media/java/android/media/SoundPool.java
+++ b/media/java/android/media/SoundPool.java
@@ -443,7 +443,7 @@
         private final static String TAG = "SoundPool";
         private final static boolean DEBUG = false;
 
-        private int mNativeContext; // accessed by native methods
+        private long mNativeContext; // accessed by native methods
 
         private EventHandler mEventHandler;
         private SoundPool.OnLoadCompleteListener mOnLoadCompleteListener;
diff --git a/media/java/android/media/ToneGenerator.java b/media/java/android/media/ToneGenerator.java
index 5592105..713f147 100644
--- a/media/java/android/media/ToneGenerator.java
+++ b/media/java/android/media/ToneGenerator.java
@@ -887,5 +887,5 @@
     protected void finalize() { native_finalize(); }
 
     @SuppressWarnings("unused")
-    private int mNativeContext; // accessed by native methods
+    private long mNativeContext; // accessed by native methods
 }
diff --git a/media/java/android/media/audiofx/AudioEffect.java b/media/java/android/media/audiofx/AudioEffect.java
index 1e1ef8c..cc121a3 100644
--- a/media/java/android/media/audiofx/AudioEffect.java
+++ b/media/java/android/media/audiofx/AudioEffect.java
@@ -315,8 +315,8 @@
     private int mId;
 
     // accessed by native methods
-    private int mNativeAudioEffect;
-    private int mJniData;
+    private long mNativeAudioEffect;
+    private long mJniData;
 
     /**
      * Effect descriptor
diff --git a/media/java/android/media/audiofx/Visualizer.java b/media/java/android/media/audiofx/Visualizer.java
index fb7f718..ff04201 100644
--- a/media/java/android/media/audiofx/Visualizer.java
+++ b/media/java/android/media/audiofx/Visualizer.java
@@ -184,8 +184,8 @@
     private OnServerDiedListener mServerDiedListener = null;
 
     // accessed by native methods
-    private int mNativeVisualizer;
-    private int mJniData;
+    private long mNativeVisualizer;
+    private long mJniData;
 
     //--------------------------------------------------------------------------
     // Constructor, Finalize
diff --git a/media/java/android/media/videoeditor/MediaArtistNativeHelper.java b/media/java/android/media/videoeditor/MediaArtistNativeHelper.java
index f4fccbe..2b0b3e2 100644
--- a/media/java/android/media/videoeditor/MediaArtistNativeHelper.java
+++ b/media/java/android/media/videoeditor/MediaArtistNativeHelper.java
@@ -118,7 +118,7 @@
     private boolean mErrorFlagSet = false;
 
     @SuppressWarnings("unused")
-    private int mManualEditContext;
+    private long mManualEditContext;
 
     /* Listeners */
 
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index cf1238a..9ceefc3 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -1036,7 +1036,7 @@
     }
 
     // used by the JNI code
-    private int mNativeContext;
+    private long mNativeContext;
 
     private native final void native_setup();
     private native final void native_finalize();
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index 3272fed..8310579 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -237,7 +237,7 @@
     }
 
     // used by the JNI code
-    private int mNativeContext;
+    private long mNativeContext;
 
     private native boolean native_open(String deviceName, int fd);
     private native void native_close();
diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java
index f561cc0..266f78e 100644
--- a/media/java/android/mtp/MtpServer.java
+++ b/media/java/android/mtp/MtpServer.java
@@ -22,7 +22,7 @@
  */
 public class MtpServer implements Runnable {
 
-    private int mNativeContext; // accessed by native methods
+    private long mNativeContext; // accessed by native methods
 
     static {
         System.loadLibrary("media_jni");
diff --git a/media/jni/android_media_AmrInputStream.cpp b/media/jni/android_media_AmrInputStream.cpp
index b5220fe..3df6530 100644
--- a/media/jni/android_media_AmrInputStream.cpp
+++ b/media/jni/android_media_AmrInputStream.cpp
@@ -49,17 +49,17 @@
     int32_t mLastModeUsed;
 };
 
-static jint android_media_AmrInputStream_GsmAmrEncoderNew
+static jlong android_media_AmrInputStream_GsmAmrEncoderNew
         (JNIEnv *env, jclass clazz) {
     GsmAmrEncoderState* gae = new GsmAmrEncoderState();
     if (gae == NULL) {
         jniThrowRuntimeException(env, "Out of memory");
     }
-    return (jint)gae;
+    return (jlong)gae;
 }
 
 static void android_media_AmrInputStream_GsmAmrEncoderInitialize
-        (JNIEnv *env, jclass clazz, jint gae) {
+        (JNIEnv *env, jclass clazz, jlong gae) {
     GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
     int32_t nResult = AMREncodeInit(&state->mEncState, &state->mSidState, false);
     if (nResult != OK) {
@@ -70,7 +70,7 @@
 
 static jint android_media_AmrInputStream_GsmAmrEncoderEncode
         (JNIEnv *env, jclass clazz,
-         jint gae, jbyteArray pcm, jint pcmOffset, jbyteArray amr, jint amrOffset) {
+         jlong gae, jbyteArray pcm, jint pcmOffset, jbyteArray amr, jint amrOffset) {
 
     jbyte inBuf[BYTES_PER_FRAME];
     jbyte outBuf[MAX_OUTPUT_BUFFER_SIZE];
@@ -86,7 +86,7 @@
     if (length < 0) {
         jniThrowExceptionFmt(env, "java/io/IOException",
                 "Failed to encode a frame with error code: %d", length);
-        return -1;
+        return (jint)-1;
     }
 
     // The 1st byte of PV AMR frames are WMF (Wireless Multimedia Forum)
@@ -101,30 +101,30 @@
 
     env->SetByteArrayRegion(amr, amrOffset, length, outBuf);
 
-    return length;
+    return (jint)length;
 }
 
 static void android_media_AmrInputStream_GsmAmrEncoderCleanup
-        (JNIEnv *env, jclass clazz, jint gae) {
-    GsmAmrEncoderState *state = (GsmAmrEncoderState *)gae;
+        (JNIEnv *env, jclass clazz, jlong gae) {
+    GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
     AMREncodeExit(&state->mEncState, &state->mSidState);
     state->mEncState = NULL;
     state->mSidState = NULL;
 }
 
 static void android_media_AmrInputStream_GsmAmrEncoderDelete
-        (JNIEnv *env, jclass clazz, jint gae) {
+        (JNIEnv *env, jclass clazz, jlong gae) {
     delete (GsmAmrEncoderState*)gae;
 }
 
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gMethods[] = {
-    {"GsmAmrEncoderNew",        "()I",        (void*)android_media_AmrInputStream_GsmAmrEncoderNew},
-    {"GsmAmrEncoderInitialize", "(I)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderInitialize},
-    {"GsmAmrEncoderEncode",     "(I[BI[BI)I", (void*)android_media_AmrInputStream_GsmAmrEncoderEncode},
-    {"GsmAmrEncoderCleanup",    "(I)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderCleanup},
-    {"GsmAmrEncoderDelete",     "(I)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderDelete},
+    {"GsmAmrEncoderNew",        "()J",        (void*)android_media_AmrInputStream_GsmAmrEncoderNew},
+    {"GsmAmrEncoderInitialize", "(J)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderInitialize},
+    {"GsmAmrEncoderEncode",     "(J[BI[BI)I", (void*)android_media_AmrInputStream_GsmAmrEncoderEncode},
+    {"GsmAmrEncoderCleanup",    "(J)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderCleanup},
+    {"GsmAmrEncoderDelete",     "(J)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderDelete},
 };
 
 
diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp
index b8d437c..221ea57 100644
--- a/media/jni/android_media_MediaCodec.cpp
+++ b/media/jni/android_media_MediaCodec.cpp
@@ -328,20 +328,20 @@
 
 static sp<JMediaCodec> setMediaCodec(
         JNIEnv *env, jobject thiz, const sp<JMediaCodec> &codec) {
-    sp<JMediaCodec> old = (JMediaCodec *)env->GetIntField(thiz, gFields.context);
+    sp<JMediaCodec> old = (JMediaCodec *)env->GetLongField(thiz, gFields.context);
     if (codec != NULL) {
         codec->incStrong(thiz);
     }
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)codec.get());
+    env->SetLongField(thiz, gFields.context, (jlong)codec.get());
 
     return old;
 }
 
 static sp<JMediaCodec> getMediaCodec(JNIEnv *env, jobject thiz) {
-    return (JMediaCodec *)env->GetIntField(thiz, gFields.context);
+    return (JMediaCodec *)env->GetLongField(thiz, gFields.context);
 }
 
 static void android_media_MediaCodec_release(JNIEnv *env, jobject thiz) {
@@ -710,7 +710,7 @@
     status_t err = codec->dequeueInputBuffer(&index, timeoutUs);
 
     if (err == OK) {
-        return index;
+        return (jint) index;
     }
 
     return throwExceptionAsNecessary(env, err);
@@ -732,7 +732,7 @@
             env, bufferInfo, &index, timeoutUs);
 
     if (err == OK) {
-        return index;
+        return (jint) index;
     }
 
     return throwExceptionAsNecessary(env, err);
@@ -885,7 +885,7 @@
             env, env->FindClass("android/media/MediaCodec"));
     CHECK(clazz.get() != NULL);
 
-    gFields.context = env->GetFieldID(clazz.get(), "mNativeContext", "I");
+    gFields.context = env->GetFieldID(clazz.get(), "mNativeContext", "J");
     CHECK(gFields.context != NULL);
 
     clazz.reset(env->FindClass("android/media/MediaCodec$CryptoInfo"));
diff --git a/media/jni/android_media_MediaCrypto.cpp b/media/jni/android_media_MediaCrypto.cpp
index d0f56ea..a6f8dcd 100644
--- a/media/jni/android_media_MediaCrypto.cpp
+++ b/media/jni/android_media_MediaCrypto.cpp
@@ -38,7 +38,7 @@
 static fields_t gFields;
 
 static sp<JCrypto> getCrypto(JNIEnv *env, jobject thiz) {
-    return (JCrypto *)env->GetIntField(thiz, gFields.context);
+    return (JCrypto *)env->GetLongField(thiz, gFields.context);
 }
 
 JCrypto::JCrypto(
@@ -146,14 +146,14 @@
 
 static sp<JCrypto> setCrypto(
         JNIEnv *env, jobject thiz, const sp<JCrypto> &crypto) {
-    sp<JCrypto> old = (JCrypto *)env->GetIntField(thiz, gFields.context);
+    sp<JCrypto> old = (JCrypto *)env->GetLongField(thiz, gFields.context);
     if (crypto != NULL) {
         crypto->incStrong(thiz);
     }
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)crypto.get());
+    env->SetLongField(thiz, gFields.context, (jlong)crypto.get());
 
     return old;
 }
@@ -166,7 +166,7 @@
     jclass clazz = env->FindClass("android/media/MediaCrypto");
     CHECK(clazz != NULL);
 
-    gFields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    gFields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     CHECK(gFields.context != NULL);
 }
 
@@ -232,7 +232,7 @@
                 env,
                 "java/lang/IllegalArgumentException",
                 NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     jboolean isCopy;
@@ -243,27 +243,27 @@
     env->ReleaseByteArrayElements(uuidObj, uuid, 0);
     uuid = NULL;
 
-    return result;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static jboolean android_media_MediaCrypto_requiresSecureDecoderComponent(
         JNIEnv *env, jobject thiz, jstring mimeObj) {
     if (mimeObj == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     sp<JCrypto> crypto = getCrypto(env, thiz);
 
     if (crypto == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     const char *mime = env->GetStringUTFChars(mimeObj, NULL);
 
     if (mime == NULL) {
-        return false;
+        return JNI_FALSE;
     }
 
     bool result = crypto->requiresSecureDecoderComponent(mime);
@@ -271,7 +271,7 @@
     env->ReleaseStringUTFChars(mimeObj, mime);
     mime = NULL;
 
-    return result;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static JNINativeMethod gMethods[] = {
diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp
index bbb74d25b..052d97d 100644
--- a/media/jni/android_media_MediaDrm.cpp
+++ b/media/jni/android_media_MediaDrm.cpp
@@ -186,6 +186,7 @@
             nativeParcel->setData(obj->data(), obj->dataSize());
             env->CallStaticVoidMethod(mClass, gFields.post_event, mObject,
                     jeventType, extra, jParcel);
+            env->DeleteLocalRef(jParcel);
         }
     }
 
@@ -267,7 +268,7 @@
 }
 
 static sp<IDrm> GetDrm(JNIEnv *env, jobject thiz) {
-    JDrm *jdrm = (JDrm *)env->GetIntField(thiz, gFields.context);
+    JDrm *jdrm = (JDrm *)env->GetLongField(thiz, gFields.context);
     return jdrm ? jdrm->getDrm() : NULL;
 }
 
@@ -484,14 +485,14 @@
 
 static sp<JDrm> setDrm(
         JNIEnv *env, jobject thiz, const sp<JDrm> &drm) {
-    sp<JDrm> old = (JDrm *)env->GetIntField(thiz, gFields.context);
+    sp<JDrm> old = (JDrm *)env->GetLongField(thiz, gFields.context);
     if (drm != NULL) {
         drm->incStrong(thiz);
     }
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)drm.get());
+    env->SetLongField(thiz, gFields.context, reinterpret_cast<jlong>(drm.get()));
 
     return old;
 }
@@ -520,7 +521,7 @@
 static void android_media_MediaDrm_native_init(JNIEnv *env) {
     jclass clazz;
     FIND_CLASS(clazz, "android/media/MediaDrm");
-    GET_FIELD_ID(gFields.context, clazz, "mNativeContext", "I");
+    GET_FIELD_ID(gFields.context, clazz, "mNativeContext", "J");
     GET_STATIC_METHOD_ID(gFields.post_event, clazz, "postEventFromNative",
                          "(Ljava/lang/Object;IILjava/lang/Object;)V");
 
diff --git a/media/jni/android_media_MediaExtractor.cpp b/media/jni/android_media_MediaExtractor.cpp
index 1ac45d4..705de88 100644
--- a/media/jni/android_media_MediaExtractor.cpp
+++ b/media/jni/android_media_MediaExtractor.cpp
@@ -88,7 +88,7 @@
         env->GetByteArrayRegion(byteArrayObj, 0, size, (jbyte*) buffer);
         env->DeleteLocalRef(byteArrayObj);
         if (env->ExceptionCheck()) {
-            ALOGW("Exception occurred while reading %d at %lld", size, offset);
+            ALOGW("Exception occurred while reading %zu at %lld", size, offset);
             LOGW_EX(env);
             env->ExceptionClear();
             return -1;
@@ -198,7 +198,7 @@
 
     void *dst = env->GetDirectBufferAddress(byteBuf);
 
-    jlong dstSize;
+    size_t dstSize;
     jbyteArray byteArray = NULL;
 
     if (dst == NULL) {
@@ -219,9 +219,9 @@
         jboolean isCopy;
         dst = env->GetByteArrayElements(byteArray, &isCopy);
 
-        dstSize = env->GetArrayLength(byteArray);
+        dstSize = (size_t) env->GetArrayLength(byteArray);
     } else {
-        dstSize = env->GetDirectBufferCapacity(byteBuf);
+        dstSize = (size_t) env->GetDirectBufferCapacity(byteBuf);
     }
 
     if (dstSize < offset) {
@@ -299,7 +299,7 @@
 static sp<JMediaExtractor> setMediaExtractor(
         JNIEnv *env, jobject thiz, const sp<JMediaExtractor> &extractor) {
     sp<JMediaExtractor> old =
-        (JMediaExtractor *)env->GetIntField(thiz, gFields.context);
+        (JMediaExtractor *)env->GetLongField(thiz, gFields.context);
 
     if (extractor != NULL) {
         extractor->incStrong(thiz);
@@ -307,13 +307,13 @@
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)extractor.get());
+    env->SetLongField(thiz, gFields.context, (jlong)extractor.get());
 
     return old;
 }
 
 static sp<JMediaExtractor> getMediaExtractor(JNIEnv *env, jobject thiz) {
-    return (JMediaExtractor *)env->GetIntField(thiz, gFields.context);
+    return (JMediaExtractor *)env->GetLongField(thiz, gFields.context);
 }
 
 static void android_media_MediaExtractor_release(JNIEnv *env, jobject thiz) {
@@ -329,7 +329,7 @@
         return -1;
     }
 
-    return extractor->countTracks();
+    return (jint) extractor->countTracks();
 }
 
 static jobject android_media_MediaExtractor_getTrackFormatNative(
@@ -430,19 +430,19 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     status_t err = extractor->advance();
 
     if (err == ERROR_END_OF_STREAM) {
-        return false;
+        return JNI_FALSE;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
-    return true;
+    return JNI_TRUE;
 }
 
 static jint android_media_MediaExtractor_readSampleData(
@@ -461,10 +461,10 @@
         return -1;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1;
     }
 
-    return sampleSize;
+    return (jint) sampleSize;
 }
 
 static jint android_media_MediaExtractor_getSampleTrackIndex(
@@ -483,10 +483,10 @@
         return -1;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1;
     }
 
-    return trackIndex;
+    return (jint) trackIndex;
 }
 
 static jlong android_media_MediaExtractor_getSampleTime(
@@ -505,10 +505,10 @@
         return -1ll;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1ll;
     }
 
-    return sampleTimeUs;
+    return (jlong) sampleTimeUs;
 }
 
 static jint android_media_MediaExtractor_getSampleFlags(
@@ -517,20 +517,20 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return -1ll;
+        return -1;
     }
 
     uint32_t sampleFlags;
     status_t err = extractor->getSampleFlags(&sampleFlags);
 
     if (err == ERROR_END_OF_STREAM) {
-        return -1ll;
+        return -1;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1;
     }
 
-    return sampleFlags;
+    return (jint) sampleFlags;
 }
 
 static jboolean android_media_MediaExtractor_getSampleCryptoInfo(
@@ -539,27 +539,27 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return -1ll;
+        return JNI_FALSE;
     }
 
     sp<MetaData> meta;
     status_t err = extractor->getSampleMeta(&meta);
 
     if (err != OK) {
-        return false;
+        return JNI_FALSE;
     }
 
     uint32_t type;
     const void *data;
     size_t size;
     if (!meta->findData(kKeyEncryptedSizes, &type, &data, &size)) {
-        return false;
+        return JNI_FALSE;
     }
 
     size_t numSubSamples = size / sizeof(size_t);
 
     if (numSubSamples == 0) {
-        return false;
+        return JNI_FALSE;
     }
 
     jintArray numBytesOfEncryptedDataObj = env->NewIntArray(numSubSamples);
@@ -576,7 +576,7 @@
     if (meta->findData(kKeyPlainSizes, &type, &data, &size)) {
         if (size != encSize) {
             // The two must be of the same length.
-            return false;
+            return JNI_FALSE;
         }
 
         numBytesOfPlainDataObj = env->NewIntArray(numSubSamples);
@@ -593,7 +593,7 @@
     if (meta->findData(kKeyCryptoKey, &type, &data, &size)) {
         if (size != 16) {
             // Keys must be 16 bytes in length.
-            return false;
+            return JNI_FALSE;
         }
 
         keyObj = env->NewByteArray(size);
@@ -608,7 +608,7 @@
     if (meta->findData(kKeyCryptoIV, &type, &data, &size)) {
         if (size != 16) {
             // IVs must be 16 bytes in length.
-            return false;
+            return JNI_FALSE;
         }
 
         ivObj = env->NewByteArray(size);
@@ -634,14 +634,14 @@
             ivObj,
             mode);
 
-    return true;
+    return JNI_TRUE;
 }
 
 static void android_media_MediaExtractor_native_init(JNIEnv *env) {
     jclass clazz = env->FindClass("android/media/MediaExtractor");
     CHECK(clazz != NULL);
 
-    gFields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    gFields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     CHECK(gFields.context != NULL);
 
     clazz = env->FindClass("android/media/MediaCodec$CryptoInfo");
@@ -770,7 +770,7 @@
         return -1ll;
     }
 
-    return cachedDurationUs;
+    return (jlong) cachedDurationUs;
 }
 
 static jboolean android_media_MediaExtractor_hasCacheReachedEOS(
@@ -779,16 +779,16 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return true;
+        return JNI_TRUE;
     }
 
     int64_t cachedDurationUs;
     bool eos;
     if (!extractor->getCachedDuration(&cachedDurationUs, &eos)) {
-        return true;
+        return JNI_TRUE;
     }
 
-    return eos;
+    return eos ? JNI_TRUE : JNI_FALSE;
 }
 
 static void android_media_MediaExtractor_native_finalize(
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 297dadf..a52b24d 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -67,15 +67,15 @@
 static MediaMetadataRetriever* getRetriever(JNIEnv* env, jobject thiz)
 {
     // No lock is needed, since it is called internally by other methods that are protected
-    MediaMetadataRetriever* retriever = (MediaMetadataRetriever*) env->GetIntField(thiz, fields.context);
+    MediaMetadataRetriever* retriever = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
     return retriever;
 }
 
-static void setRetriever(JNIEnv* env, jobject thiz, int retriever)
+static void setRetriever(JNIEnv* env, jobject thiz, MediaMetadataRetriever* retriever)
 {
     // No lock is needed, since it is called internally by other methods that are protected
-    MediaMetadataRetriever *old = (MediaMetadataRetriever*) env->GetIntField(thiz, fields.context);
-    env->SetIntField(thiz, fields.context, retriever);
+    MediaMetadataRetriever *old = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
+    env->SetLongField(thiz, fields.context, (jlong) retriever);
 }
 
 static void
@@ -146,10 +146,10 @@
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
     if (offset < 0 || length < 0 || fd < 0) {
         if (offset < 0) {
-            ALOGE("negative offset (%lld)", offset);
+            ALOGE("negative offset (%lld)", (long long)offset);
         }
         if (length < 0) {
-            ALOGE("negative length (%lld)", length);
+            ALOGE("negative length (%lld)", (long long)length);
         }
         if (fd < 0) {
             ALOGE("invalid file descriptor");
@@ -264,7 +264,7 @@
                             config);
 
     SkBitmap *bitmap =
-            (SkBitmap *) env->GetIntField(jBitmap, fields.nativeBitmap);
+            (SkBitmap *) env->GetLongField(jBitmap, fields.nativeBitmap);
 
     bitmap->lockPixels();
     rotate((uint16_t*)bitmap->getPixels(),
@@ -359,7 +359,7 @@
     Mutex::Autolock lock(sLock);
     MediaMetadataRetriever* retriever = getRetriever(env, thiz);
     delete retriever;
-    setRetriever(env, thiz, 0);
+    setRetriever(env, thiz, (MediaMetadataRetriever*) 0);
 }
 
 static void android_media_MediaMetadataRetriever_native_finalize(JNIEnv *env, jobject thiz)
@@ -379,7 +379,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
@@ -406,7 +406,7 @@
     if (fields.createScaledBitmapMethod == NULL) {
         return;
     }
-    fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "I");
+    fields.nativeBitmap = env->GetFieldID(fields.bitmapClazz, "mNativeBitmap", "J");
     if (fields.nativeBitmap == NULL) {
         return;
     }
@@ -435,7 +435,7 @@
         jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
         return;
     }
-    setRetriever(env, thiz, (int)retriever);
+    setRetriever(env, thiz, retriever);
 }
 
 // JNI mapping between Java methods and native methods
diff --git a/media/jni/android_media_MediaMuxer.cpp b/media/jni/android_media_MediaMuxer.cpp
index 457b956..2c16a05 100644
--- a/media/jni/android_media_MediaMuxer.cpp
+++ b/media/jni/android_media_MediaMuxer.cpp
@@ -31,7 +31,6 @@
 namespace android {
 
 struct fields_t {
-    jfieldID context;
     jmethodID arrayID;
 };
 
@@ -42,7 +41,7 @@
 using namespace android;
 
 static jint android_media_MediaMuxer_addTrack(
-        JNIEnv *env, jclass clazz, jint nativeObject, jobjectArray keys,
+        JNIEnv *env, jclass clazz, jlong nativeObject, jobjectArray keys,
         jobjectArray values) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
@@ -72,7 +71,7 @@
 }
 
 static void android_media_MediaMuxer_writeSampleData(
-        JNIEnv *env, jclass clazz, jint nativeObject, jint trackIndex,
+        JNIEnv *env, jclass clazz, jlong nativeObject, jint trackIndex,
         jobject byteBuf, jint offset, jint size, jlong timeUs, jint flags) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
@@ -147,7 +146,7 @@
 }
 
 static void android_media_MediaMuxer_setOrientationHint(
-        JNIEnv *env, jclass clazz, jint nativeObject, jint degrees) {
+        JNIEnv *env, jclass clazz, jlong nativeObject, jint degrees) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -177,7 +176,7 @@
 }
 
 static void android_media_MediaMuxer_start(JNIEnv *env, jclass clazz,
-                                           jint nativeObject) {
+                                           jlong nativeObject) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -195,7 +194,7 @@
 }
 
 static void android_media_MediaMuxer_stop(JNIEnv *env, jclass clazz,
-                                          jint nativeObject) {
+                                          jlong nativeObject) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -213,7 +212,7 @@
 }
 
 static void android_media_MediaMuxer_native_release(
-        JNIEnv *env, jclass clazz, jint nativeObject) {
+        JNIEnv *env, jclass clazz, jlong nativeObject) {
     sp<MediaMuxer> muxer(reinterpret_cast<MediaMuxer *>(nativeObject));
     if (muxer != NULL) {
         muxer->decStrong(clazz);
@@ -222,26 +221,26 @@
 
 static JNINativeMethod gMethods[] = {
 
-    { "nativeAddTrack", "(I[Ljava/lang/String;[Ljava/lang/Object;)I",
+    { "nativeAddTrack", "(J[Ljava/lang/String;[Ljava/lang/Object;)I",
         (void *)android_media_MediaMuxer_addTrack },
 
-    { "nativeSetOrientationHint", "(II)V",
+    { "nativeSetOrientationHint", "(JI)V",
         (void *)android_media_MediaMuxer_setOrientationHint},
 
-    { "nativeSetLocation", "(III)V",
+    { "nativeSetLocation", "(JII)V",
         (void *)android_media_MediaMuxer_setLocation},
 
-    { "nativeStart", "(I)V", (void *)android_media_MediaMuxer_start},
+    { "nativeStart", "(J)V", (void *)android_media_MediaMuxer_start},
 
-    { "nativeWriteSampleData", "(IILjava/nio/ByteBuffer;IIJI)V",
+    { "nativeWriteSampleData", "(JILjava/nio/ByteBuffer;IIJI)V",
         (void *)android_media_MediaMuxer_writeSampleData },
 
-    { "nativeStop", "(I)V", (void *)android_media_MediaMuxer_stop},
+    { "nativeStop", "(J)V", (void *)android_media_MediaMuxer_stop},
 
-    { "nativeSetup", "(Ljava/io/FileDescriptor;I)I",
+    { "nativeSetup", "(Ljava/io/FileDescriptor;I)J",
         (void *)android_media_MediaMuxer_native_setup },
 
-    { "nativeRelease", "(I)V",
+    { "nativeRelease", "(J)V",
         (void *)android_media_MediaMuxer_native_release },
 
 };
@@ -252,12 +251,6 @@
     int err = AndroidRuntime::registerNativeMethods(env,
                 "android/media/MediaMuxer", gMethods, NELEM(gMethods));
 
-    jclass clazz = env->FindClass("android/media/MediaMuxer");
-    CHECK(clazz != NULL);
-
-    gFields.context = env->GetFieldID(clazz, "mNativeContext", "I");
-    CHECK(gFields.context != NULL);
-
     jclass byteBufClass = env->FindClass("java/nio/ByteBuffer");
     CHECK(byteBufClass != NULL);
 
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 4be9cd6..9d0d5a6 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -133,21 +133,21 @@
 static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz)
 {
     Mutex::Autolock l(sLock);
-    MediaPlayer* const p = (MediaPlayer*)env->GetIntField(thiz, fields.context);
+    MediaPlayer* const p = (MediaPlayer*)env->GetLongField(thiz, fields.context);
     return sp<MediaPlayer>(p);
 }
 
 static sp<MediaPlayer> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer>& player)
 {
     Mutex::Autolock l(sLock);
-    sp<MediaPlayer> old = (MediaPlayer*)env->GetIntField(thiz, fields.context);
+    sp<MediaPlayer> old = (MediaPlayer*)env->GetLongField(thiz, fields.context);
     if (player.get()) {
         player->incStrong((void*)setMediaPlayer);
     }
     if (old != 0) {
         old->decStrong((void*)setMediaPlayer);
     }
-    env->SetIntField(thiz, fields.context, (int)player.get());
+    env->SetLongField(thiz, fields.context, (jlong)player.get());
     return old;
 }
 
@@ -244,7 +244,7 @@
 
 static sp<IGraphicBufferProducer>
 getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
-    IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetIntField(thiz, fields.surface_texture);
+    IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture);
     return sp<IGraphicBufferProducer>(p);
 }
 
@@ -293,7 +293,7 @@
         }
     }
 
-    env->SetIntField(thiz, fields.surface_texture, (int)new_st.get());
+    env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get());
 
     // This will fail if the media player has not been initialized yet. This
     // can be the case if setDisplay() on MediaPlayer.java has been called
@@ -384,7 +384,7 @@
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
     const jboolean is_playing = mp->isPlaying();
 
@@ -393,7 +393,7 @@
 }
 
 static void
-android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, int msec)
+android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, jint msec)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
@@ -404,7 +404,7 @@
     process_media_player_call( env, thiz, mp->seekTo(msec), NULL, NULL );
 }
 
-static int
+static jint
 android_media_MediaPlayer_getVideoWidth(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -418,10 +418,10 @@
         w = 0;
     }
     ALOGV("getVideoWidth: %d", w);
-    return w;
+    return (jint) w;
 }
 
-static int
+static jint
 android_media_MediaPlayer_getVideoHeight(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -435,11 +435,11 @@
         h = 0;
     }
     ALOGV("getVideoHeight: %d", h);
-    return h;
+    return (jint) h;
 }
 
 
-static int
+static jint
 android_media_MediaPlayer_getCurrentPosition(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -450,10 +450,10 @@
     int msec;
     process_media_player_call( env, thiz, mp->getCurrentPosition(&msec), NULL, NULL );
     ALOGV("getCurrentPosition: %d (msec)", msec);
-    return msec;
+    return (jint) msec;
 }
 
-static int
+static jint
 android_media_MediaPlayer_getDuration(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -464,7 +464,7 @@
     int msec;
     process_media_player_call( env, thiz, mp->getDuration(&msec), NULL, NULL );
     ALOGV("getDuration: %d (msec)", msec);
-    return msec;
+    return (jint) msec;
 }
 
 static void
@@ -480,7 +480,7 @@
 }
 
 static void
-android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, int streamtype)
+android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, jint streamtype)
 {
     ALOGV("setAudioStreamType: %d", streamtype);
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -510,21 +510,21 @@
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
-    return mp->isLooping();
+    return mp->isLooping() ? JNI_TRUE : JNI_FALSE;
 }
 
 static void
-android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, float leftVolume, float rightVolume)
+android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, jfloat leftVolume, jfloat rightVolume)
 {
-    ALOGV("setVolume: left %f  right %f", leftVolume, rightVolume);
+    ALOGV("setVolume: left %f  right %f", (float) leftVolume, (float) rightVolume);
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
         return;
     }
-    process_media_player_call( env, thiz, mp->setVolume(leftVolume, rightVolume), NULL, NULL );
+    process_media_player_call( env, thiz, mp->setVolume((float) leftVolume, (float) rightVolume), NULL, NULL );
 }
 
 // Sends the request and reply parcels to the media player via the
@@ -544,7 +544,7 @@
 
     // Don't use process_media_player_call which use the async loop to
     // report errors, instead returns the status.
-    return media_player->invoke(*request, reply);
+    return (jint) media_player->invoke(*request, reply);
 }
 
 // Sends the new filter to the client.
@@ -564,7 +564,7 @@
         return UNKNOWN_ERROR;
     }
 
-    return media_player->setMetadataFilter(*filter);
+    return (jint) media_player->setMetadataFilter(*filter);
 }
 
 static jboolean
@@ -574,14 +574,14 @@
     sp<MediaPlayer> media_player = getMediaPlayer(env, thiz);
     if (media_player == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     Parcel *metadata = parcelForJavaObject(env, reply);
 
     if (metadata == NULL ) {
         jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null");
-        return false;
+        return JNI_FALSE;
     }
 
     metadata->freeData();
@@ -589,7 +589,11 @@
     // metadata. Note however that the parcel actually starts with the
     // return code so you should not rewind the parcel using
     // setDataPosition(0).
-    return media_player->getMetadata(update_only, apply_filter, metadata) == OK;
+    if (media_player->getMetadata(update_only, apply_filter, metadata) == OK) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
 }
 
 // This function gets some field IDs, which in turn causes class initialization.
@@ -605,7 +609,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
@@ -616,7 +620,7 @@
         return;
     }
 
-    fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "I");
+    fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "J");
     if (fields.surface_texture == NULL) {
         return;
     }
@@ -696,7 +700,7 @@
         return 0;
     }
 
-    return mp->getAudioSessionId();
+    return (jint) mp->getAudioSessionId();
 }
 
 static void
@@ -733,7 +737,7 @@
 
     Parcel *reply = parcelForJavaObject(env, java_reply);
 
-    return service->pullBatteryData(reply);
+    return (jint) service->pullBatteryData(reply);
 }
 
 static jint
@@ -772,7 +776,7 @@
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
     }
 
-    return ret;
+    return (jint) ret;
 }
 
 static void
@@ -826,16 +830,19 @@
         jstring exclusionListObj = (jstring)env->CallObjectMethod(
                 proxyProps, fields.proxyConfigGetExclusionList);
 
-        const char *exclusionList =
-            env->GetStringUTFChars(exclusionListObj, NULL);
-
         if (host != NULL && exclusionListObj != NULL) {
-            thisplayer->updateProxyConfig(host, port, exclusionList);
-        }
+            const char *exclusionList = env->GetStringUTFChars(exclusionListObj, NULL);
 
-        if (exclusionList != NULL) {
-            env->ReleaseStringUTFChars(exclusionListObj, exclusionList);
-            exclusionList = NULL;
+            if (exclusionList != NULL) {
+                thisplayer->updateProxyConfig(host, port, exclusionList);
+
+                env->ReleaseStringUTFChars(exclusionListObj, exclusionList);
+                exclusionList = NULL;
+            } else {
+                thisplayer->updateProxyConfig(host, port, "");
+            }
+        } else if (host != NULL) {
+            thisplayer->updateProxyConfig(host, port, "");
         }
 
         if (host != NULL) {
diff --git a/media/jni/android_media_MediaProfiles.cpp b/media/jni/android_media_MediaProfiles.cpp
index 3fbb8ba..48a9132 100644
--- a/media/jni/android_media_MediaProfiles.cpp
+++ b/media/jni/android_media_MediaProfiles.cpp
@@ -48,7 +48,7 @@
 android_media_MediaProfiles_native_get_num_file_formats(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_file_formats");
-    return sProfiles->getOutputFileFormats().size();
+    return (jint) sProfiles->getOutputFileFormats().size();
 }
 
 static jint
@@ -119,7 +119,7 @@
 android_media_MediaProfiles_native_get_num_audio_encoders(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_audio_encoders");
-    return sProfiles->getAudioEncoders().size();
+    return (jint) sProfiles->getAudioEncoders().size();
 }
 
 static jobject
@@ -223,18 +223,18 @@
 {
     ALOGV("native_has_camcorder_profile: %d %d", id, quality);
     if (!isCamcorderQualityKnown(quality)) {
-        return false;
+        return JNI_FALSE;
     }
 
     camcorder_quality q = static_cast<camcorder_quality>(quality);
-    return sProfiles->hasCamcorderProfile(id, q);
+    return sProfiles->hasCamcorderProfile(id, q) ? JNI_TRUE : JNI_FALSE;
 }
 
 static jint
 android_media_MediaProfiles_native_get_num_video_decoders(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_video_decoders");
-    return sProfiles->getVideoDecoders().size();
+    return (jint) sProfiles->getVideoDecoders().size();
 }
 
 static jint
@@ -255,7 +255,7 @@
 android_media_MediaProfiles_native_get_num_audio_decoders(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_audio_decoders");
-    return sProfiles->getAudioDecoders().size();
+    return (jint) sProfiles->getAudioDecoders().size();
 }
 
 static jint
@@ -276,7 +276,7 @@
 android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv *env, jobject thiz, jint cameraId)
 {
     ALOGV("native_get_num_image_encoding_quality_levels");
-    return sProfiles->getImageEncodingQualityLevels(cameraId).size();
+    return (jint) sProfiles->getImageEncodingQualityLevels(cameraId).size();
 }
 
 static jint
@@ -284,7 +284,7 @@
 {
     ALOGV("native_get_image_encoding_quality_level");
     Vector<int> levels = sProfiles->getImageEncodingQualityLevels(cameraId);
-    if (index < 0 || index >= levels.size()) {
+    if (index < 0 || index >= (jint) levels.size()) {
         jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary");
         return -1;
     }
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 9888591..0cfd2ff 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -128,21 +128,21 @@
 static sp<MediaRecorder> getMediaRecorder(JNIEnv* env, jobject thiz)
 {
     Mutex::Autolock l(sLock);
-    MediaRecorder* const p = (MediaRecorder*)env->GetIntField(thiz, fields.context);
+    MediaRecorder* const p = (MediaRecorder*)env->GetLongField(thiz, fields.context);
     return sp<MediaRecorder>(p);
 }
 
 static sp<MediaRecorder> setMediaRecorder(JNIEnv* env, jobject thiz, const sp<MediaRecorder>& recorder)
 {
     Mutex::Autolock l(sLock);
-    sp<MediaRecorder> old = (MediaRecorder*)env->GetIntField(thiz, fields.context);
+    sp<MediaRecorder> old = (MediaRecorder*)env->GetLongField(thiz, fields.context);
     if (recorder.get()) {
         recorder->incStrong(thiz);
     }
     if (old != 0) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, fields.context, (int)recorder.get());
+    env->SetLongField(thiz, fields.context, (jlong)recorder.get());
     return old;
 }
 
@@ -334,14 +334,14 @@
     process_media_recorder_call(env, mr->prepare(), "java/io/IOException", "prepare failed.");
 }
 
-static int
+static jint
 android_media_MediaRecorder_native_getMaxAmplitude(JNIEnv *env, jobject thiz)
 {
     ALOGV("getMaxAmplitude");
     sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
     int result = 0;
     process_media_recorder_call(env, mr->getMaxAmplitude(&result), "java/lang/RuntimeException", "getMaxAmplitude failed.");
-    return result;
+    return (jint) result;
 }
 
 static void
@@ -392,7 +392,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp
index 4e3d14e..84028b7 100644
--- a/media/jni/android_media_MediaScanner.cpp
+++ b/media/jni/android_media_MediaScanner.cpp
@@ -226,12 +226,12 @@
 
 static MediaScanner *getNativeScanner_l(JNIEnv* env, jobject thiz)
 {
-    return (MediaScanner *) env->GetIntField(thiz, fields.context);
+    return (MediaScanner *) env->GetLongField(thiz, fields.context);
 }
 
 static void setNativeScanner_l(JNIEnv* env, jobject thiz, MediaScanner *s)
 {
-    env->SetIntField(thiz, fields.context, (int)s);
+    env->SetLongField(thiz, fields.context, (jlong)s);
 }
 
 static void
@@ -381,7 +381,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
@@ -398,7 +398,7 @@
         return;
     }
 
-    env->SetIntField(thiz, fields.context, (int)mp);
+    env->SetLongField(thiz, fields.context, (jlong)mp);
 }
 
 static void
diff --git a/media/jni/android_mtp_MtpDatabase.cpp b/media/jni/android_mtp_MtpDatabase.cpp
index 067e7a6..6b0bd0d 100644
--- a/media/jni/android_mtp_MtpDatabase.cpp
+++ b/media/jni/android_mtp_MtpDatabase.cpp
@@ -80,7 +80,7 @@
 
 
 MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database) {
-    return (MtpDatabase *)env->GetIntField(database, field_context);
+    return (MtpDatabase *)env->GetLongField(database, field_context);
 }
 
 // ----------------------------------------------------------------------------
@@ -1087,17 +1087,17 @@
 android_mtp_MtpDatabase_setup(JNIEnv *env, jobject thiz)
 {
     MyMtpDatabase* database = new MyMtpDatabase(env, thiz);
-    env->SetIntField(thiz, field_context, (int)database);
+    env->SetLongField(thiz, field_context, (jlong)database);
     checkAndClearExceptionFromCallback(env, __FUNCTION__);
 }
 
 static void
 android_mtp_MtpDatabase_finalize(JNIEnv *env, jobject thiz)
 {
-    MyMtpDatabase* database = (MyMtpDatabase *)env->GetIntField(thiz, field_context);
+    MyMtpDatabase* database = (MyMtpDatabase *)env->GetLongField(thiz, field_context);
     database->cleanup(env);
     delete database;
-    env->SetIntField(thiz, field_context, 0);
+    env->SetLongField(thiz, field_context, 0);
     checkAndClearExceptionFromCallback(env, __FUNCTION__);
 }
 
@@ -1229,7 +1229,7 @@
         return -1;
     }
 
-    field_context = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_context == NULL) {
         ALOGE("Can't find MtpDatabase.mNativeContext");
         return -1;
diff --git a/media/jni/android_mtp_MtpDevice.cpp b/media/jni/android_mtp_MtpDevice.cpp
index b61b66c..8e013a0 100644
--- a/media/jni/android_mtp_MtpDevice.cpp
+++ b/media/jni/android_mtp_MtpDevice.cpp
@@ -88,7 +88,7 @@
 
 MtpDevice* get_device_from_object(JNIEnv* env, jobject javaDevice)
 {
-    return (MtpDevice*)env->GetIntField(javaDevice, field_context);
+    return (MtpDevice*)env->GetLongField(javaDevice, field_context);
 }
 
 static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
@@ -106,15 +106,15 @@
 {
     const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
     if (deviceNameStr == NULL) {
-        return false;
+        return JNI_FALSE;
     }
 
     MtpDevice* device = MtpDevice::open(deviceNameStr, fd);
     env->ReleaseStringUTFChars(deviceName, deviceNameStr);
 
     if (device)
-        env->SetIntField(thiz, field_context, (int)device);
-    return (device != NULL);
+        env->SetLongField(thiz, field_context,  (jlong)device);
+    return (jboolean)(device != NULL);
 }
 
 static void
@@ -124,7 +124,7 @@
     if (device) {
         device->close();
         delete device;
-        env->SetIntField(thiz, field_context, 0);
+        env->SetLongField(thiz, field_context, 0);
     }
 }
 
@@ -356,10 +356,11 @@
 android_mtp_MtpDevice_delete_object(JNIEnv *env, jobject thiz, jint object_id)
 {
     MtpDevice* device = get_device_from_object(env, thiz);
-    if (device)
-        return device->deleteObject(object_id);
-    else
-        return NULL;
+    if (device && device->deleteObject(object_id)) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
 }
 
 static jlong
@@ -367,7 +368,7 @@
 {
     MtpDevice* device = get_device_from_object(env, thiz);
     if (device)
-        return device->getParent(object_id);
+        return (jlong)device->getParent(object_id);
     else
         return -1;
 }
@@ -377,7 +378,7 @@
 {
     MtpDevice* device = get_device_from_object(env, thiz);
     if (device)
-        return device->getStorageID(object_id);
+        return (jlong)device->getStorageID(object_id);
     else
         return -1;
 }
@@ -389,15 +390,15 @@
     if (device) {
         const char *destPathStr = env->GetStringUTFChars(dest_path, NULL);
         if (destPathStr == NULL) {
-            return false;
+            return JNI_FALSE;
         }
 
-        bool result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
+        jboolean result = device->readObject(object_id, destPathStr, AID_SDCARD_RW, 0664);
         env->ReleaseStringUTFChars(dest_path, destPathStr);
         return result;
     }
 
-    return false;
+    return JNI_FALSE;
 }
 
 // ----------------------------------------------------------------------------
@@ -618,7 +619,7 @@
         ALOGE("Can't find android/mtp/MtpDevice");
         return -1;
     }
-    field_context = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_context == NULL) {
         ALOGE("Can't find MtpDevice.mNativeContext");
         return -1;
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index 5252a3a..9d7f1c2 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -53,7 +53,7 @@
 extern MtpDatabase* getMtpDatabase(JNIEnv *env, jobject database);
 
 static inline MtpServer* getMtpServer(JNIEnv *env, jobject thiz) {
-    return (MtpServer*)env->GetIntField(thiz, field_MtpServer_nativeContext);
+    return (MtpServer*)env->GetLongField(thiz, field_MtpServer_nativeContext);
 }
 
 static void
@@ -63,7 +63,7 @@
     if (fd >= 0) {
         MtpServer* server = new MtpServer(fd, getMtpDatabase(env, javaDatabase),
                 usePtp, AID_MEDIA_RW, 0664, 0775);
-        env->SetIntField(thiz, field_MtpServer_nativeContext, (int)server);
+        env->SetLongField(thiz, field_MtpServer_nativeContext, (jlong)server);
     } else {
         ALOGE("could not open MTP driver, errno: %d", errno);
     }
@@ -87,7 +87,7 @@
     MtpServer* server = getMtpServer(env, thiz);
     if (server) {
         delete server;
-        env->SetIntField(thiz, field_MtpServer_nativeContext, 0);
+        env->SetLongField(thiz, field_MtpServer_nativeContext, 0);
     } else {
         ALOGE("server is null in cleanup");
     }
@@ -226,7 +226,7 @@
         ALOGE("Can't find android/mtp/MtpServer");
         return -1;
     }
-    field_MtpServer_nativeContext = env->GetFieldID(clazz, "mNativeContext", "I");
+    field_MtpServer_nativeContext = env->GetFieldID(clazz, "mNativeContext", "J");
     if (field_MtpServer_nativeContext == NULL) {
         ALOGE("Can't find MtpServer.mNativeContext");
         return -1;
diff --git a/media/jni/audioeffect/android_media_AudioEffect.cpp b/media/jni/audioeffect/android_media_AudioEffect.cpp
index bcab4f3..be37aa8 100644
--- a/media/jni/audioeffect/android_media_AudioEffect.cpp
+++ b/media/jni/audioeffect/android_media_AudioEffect.cpp
@@ -214,7 +214,7 @@
     //      nativeTrackInJavaObj
     fields.fidNativeAudioEffect = env->GetFieldID(
             fields.clazzEffect,
-            "mNativeAudioEffect", "I");
+            "mNativeAudioEffect", "J");
     if (fields.fidNativeAudioEffect == NULL) {
         ALOGE("Can't find AudioEffect.%s", "mNativeAudioEffect");
         return;
@@ -222,7 +222,7 @@
     //      fidJniData;
     fields.fidJniData = env->GetFieldID(
             fields.clazzEffect,
-            "mJniData", "I");
+            "mJniData", "J");
     if (fields.fidJniData == NULL) {
         ALOGE("Can't find AudioEffect.%s", "mJniData");
         return;
@@ -388,11 +388,11 @@
 
     env->SetObjectArrayElement(javadesc, 0, jdesc);
 
-    env->SetIntField(thiz, fields.fidNativeAudioEffect, (int)lpAudioEffect);
+    env->SetLongField(thiz, fields.fidNativeAudioEffect, (jlong)lpAudioEffect);
 
-    env->SetIntField(thiz, fields.fidJniData, (int)lpJniStorage);
+    env->SetLongField(thiz, fields.fidJniData, (jlong)lpJniStorage);
 
-    return AUDIOEFFECT_SUCCESS;
+    return (jint) AUDIOEFFECT_SUCCESS;
 
     // failures:
 setup_failure:
@@ -404,12 +404,12 @@
     if (lpAudioEffect) {
         delete lpAudioEffect;
     }
-    env->SetIntField(thiz, fields.fidNativeAudioEffect, 0);
+    env->SetLongField(thiz, fields.fidNativeAudioEffect, 0);
 
     if (lpJniStorage) {
         delete lpJniStorage;
     }
-    env->SetIntField(thiz, fields.fidJniData, 0);
+    env->SetLongField(thiz, fields.fidJniData, 0);
 
     if (uuidStr != NULL) {
         env->ReleaseStringUTFChars(uuid, uuidStr);
@@ -419,27 +419,27 @@
         env->ReleaseStringUTFChars(type, typeStr);
     }
 
-    return lStatus;
+    return (jint)lStatus;
 }
 
 
 // ----------------------------------------------------------------------------
 static void android_media_AudioEffect_native_finalize(JNIEnv *env,  jobject thiz) {
-    ALOGV("android_media_AudioEffect_native_finalize jobject: %x\n", (int)thiz);
+    ALOGV("android_media_AudioEffect_native_finalize jobject: %p\n", thiz);
 
     // delete the AudioEffect object
-    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField(
+    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField(
         thiz, fields.fidNativeAudioEffect);
     if (lpAudioEffect) {
-        ALOGV("deleting AudioEffect: %x\n", (int)lpAudioEffect);
+        ALOGV("deleting AudioEffect: %p\n", lpAudioEffect);
         delete lpAudioEffect;
     }
 
     // delete the JNI data
-    AudioEffectJniStorage* lpJniStorage = (AudioEffectJniStorage *)env->GetIntField(
+    AudioEffectJniStorage* lpJniStorage = (AudioEffectJniStorage *)env->GetLongField(
         thiz, fields.fidJniData);
     if (lpJniStorage) {
-        ALOGV("deleting pJniStorage: %x\n", (int)lpJniStorage);
+        ALOGV("deleting pJniStorage: %p\n", lpJniStorage);
         delete lpJniStorage;
     }
 }
@@ -451,15 +451,15 @@
     android_media_AudioEffect_native_finalize(env, thiz);
     // + reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, fields.fidNativeAudioEffect, 0);
-    env->SetIntField(thiz, fields.fidJniData, 0);
+    env->SetLongField(thiz, fields.fidNativeAudioEffect, 0);
+    env->SetLongField(thiz, fields.fidJniData, 0);
 }
 
 static jint
 android_media_AudioEffect_native_setEnabled(JNIEnv *env, jobject thiz, jboolean enabled)
 {
     // retrieve the AudioEffect object
-    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField(
+    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField(
         thiz, fields.fidNativeAudioEffect);
 
     if (lpAudioEffect == NULL) {
@@ -468,23 +468,27 @@
         return AUDIOEFFECT_ERROR_NO_INIT;
     }
 
-    return translateError(lpAudioEffect->setEnabled(enabled));
+    return (jint) translateError(lpAudioEffect->setEnabled(enabled));
 }
 
 static jboolean
 android_media_AudioEffect_native_getEnabled(JNIEnv *env, jobject thiz)
 {
     // retrieve the AudioEffect object
-    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField(
+    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField(
         thiz, fields.fidNativeAudioEffect);
 
     if (lpAudioEffect == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
             "Unable to retrieve AudioEffect pointer for getEnabled()");
-        return false;
+        return JNI_FALSE;
     }
 
-    return (jboolean)lpAudioEffect->getEnabled();
+    if (lpAudioEffect->getEnabled()) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
 }
 
 
@@ -492,24 +496,24 @@
 android_media_AudioEffect_native_hasControl(JNIEnv *env, jobject thiz)
 {
     // retrieve the AudioEffect object
-    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetIntField(
+    AudioEffect* lpAudioEffect = (AudioEffect *)env->GetLongField(
         thiz, fields.fidNativeAudioEffect);
 
     if (lpAudioEffect == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
             "Unable to retrieve AudioEffect pointer for hasControl()");
-        return false;
+        return JNI_FALSE;
     }
 
     if (lpAudioEffect->initCheck() == NO_ERROR) {
-        return true;
+        return JNI_TRUE;
     } else {
-        return false;
+        return JNI_FALSE;
     }
 }
 
 static jint android_media_AudioEffect_native_setParameter(JNIEnv *env,
-        jobject thiz, int psize, jbyteArray pJavaParam, int vsize,
+        jobject thiz, jint psize, jbyteArray pJavaParam, jint vsize,
         jbyteArray pJavaValue) {
     // retrieve the AudioEffect object
     jbyte* lpValue = NULL;
@@ -518,7 +522,7 @@
     effect_param_t *p;
     int voffset;
 
-    AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz,
+    AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz,
             fields.fidNativeAudioEffect);
 
     if (lpAudioEffect == NULL) {
@@ -567,7 +571,7 @@
     if (lpValue != NULL) {
         env->ReleasePrimitiveArrayCritical(pJavaValue, lpValue, 0);
     }
-    return translateError(lStatus);
+    return (jint) translateError(lStatus);
 }
 
 static jint
@@ -581,7 +585,7 @@
     effect_param_t *p;
     int voffset;
 
-    AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz,
+    AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz,
             fields.fidNativeAudioEffect);
 
     if (lpAudioEffect == NULL) {
@@ -637,7 +641,7 @@
     if (lStatus == NO_ERROR) {
         return vsize;
     }
-    return translateError(lStatus);
+    return (jint) translateError(lStatus);
 }
 
 static jint android_media_AudioEffect_native_command(JNIEnv *env, jobject thiz,
@@ -648,7 +652,7 @@
     jint lStatus = AUDIOEFFECT_ERROR_BAD_VALUE;
 
     // retrieve the AudioEffect object
-    AudioEffect* lpAudioEffect = (AudioEffect *) env->GetIntField(thiz,
+    AudioEffect* lpAudioEffect = (AudioEffect *) env->GetLongField(thiz,
             fields.fidNativeAudioEffect);
 
     if (lpAudioEffect == NULL) {
diff --git a/media/jni/audioeffect/android_media_Visualizer.cpp b/media/jni/audioeffect/android_media_Visualizer.cpp
index 40cd06b..8463d94 100644
--- a/media/jni/audioeffect/android_media_Visualizer.cpp
+++ b/media/jni/audioeffect/android_media_Visualizer.cpp
@@ -231,7 +231,7 @@
 
 static Visualizer *getVisualizer(JNIEnv* env, jobject thiz)
 {
-    Visualizer *v = (Visualizer *)env->GetIntField(
+    Visualizer *v = (Visualizer *)env->GetLongField(
         thiz, fields.fidNativeVisualizer);
     if (v == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -282,7 +282,7 @@
     //      nativeTrackInJavaObj
     fields.fidNativeVisualizer = env->GetFieldID(
             fields.clazzEffect,
-            "mNativeVisualizer", "I");
+            "mNativeVisualizer", "J");
     if (fields.fidNativeVisualizer == NULL) {
         ALOGE("Can't find Visualizer.%s", "mNativeVisualizer");
         return;
@@ -290,7 +290,7 @@
     //      fidJniData;
     fields.fidJniData = env->GetFieldID(
             fields.clazzEffect,
-            "mJniData", "I");
+            "mJniData", "J");
     if (fields.fidJniData == NULL) {
         ALOGE("Can't find Visualizer.%s", "mJniData");
         return;
@@ -391,9 +391,9 @@
     env->ReleasePrimitiveArrayCritical(jId, nId, 0);
     nId = NULL;
 
-    env->SetIntField(thiz, fields.fidNativeVisualizer, (int)lpVisualizer);
+    env->SetLongField(thiz, fields.fidNativeVisualizer, (jlong)lpVisualizer);
 
-    env->SetIntField(thiz, fields.fidJniData, (int)lpJniStorage);
+    env->SetLongField(thiz, fields.fidJniData, (jlong)lpJniStorage);
 
     return VISUALIZER_SUCCESS;
 
@@ -407,33 +407,33 @@
     if (lpVisualizer) {
         delete lpVisualizer;
     }
-    env->SetIntField(thiz, fields.fidNativeVisualizer, 0);
+    env->SetLongField(thiz, fields.fidNativeVisualizer, 0);
 
     if (lpJniStorage) {
         delete lpJniStorage;
     }
-    env->SetIntField(thiz, fields.fidJniData, 0);
+    env->SetLongField(thiz, fields.fidJniData, 0);
 
-    return lStatus;
+    return (jint) lStatus;
 }
 
 // ----------------------------------------------------------------------------
 static void android_media_visualizer_native_finalize(JNIEnv *env,  jobject thiz) {
-    ALOGV("android_media_visualizer_native_finalize jobject: %x\n", (int)thiz);
+    ALOGV("android_media_visualizer_native_finalize jobject: %p\n", thiz);
 
     // delete the Visualizer object
-    Visualizer* lpVisualizer = (Visualizer *)env->GetIntField(
+    Visualizer* lpVisualizer = (Visualizer *)env->GetLongField(
         thiz, fields.fidNativeVisualizer);
     if (lpVisualizer) {
-        ALOGV("deleting Visualizer: %x\n", (int)lpVisualizer);
+        ALOGV("deleting Visualizer: %p\n", lpVisualizer);
         delete lpVisualizer;
     }
 
     // delete the JNI data
-    visualizerJniStorage* lpJniStorage = (visualizerJniStorage *)env->GetIntField(
+    visualizerJniStorage* lpJniStorage = (visualizerJniStorage *)env->GetLongField(
         thiz, fields.fidJniData);
     if (lpJniStorage) {
-        ALOGV("deleting pJniStorage: %x\n", (int)lpJniStorage);
+        ALOGV("deleting pJniStorage: %p\n", lpJniStorage);
         delete lpJniStorage;
     }
 }
@@ -445,8 +445,8 @@
     android_media_visualizer_native_finalize(env, thiz);
     // + reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, fields.fidNativeVisualizer, 0);
-    env->SetIntField(thiz, fields.fidJniData, 0);
+    env->SetLongField(thiz, fields.fidNativeVisualizer, 0);
+    env->SetLongField(thiz, fields.fidJniData, 0);
 }
 
 static jint
@@ -460,7 +460,7 @@
     jint retVal = translateError(lpVisualizer->setEnabled(enabled));
 
     if (!enabled) {
-        visualizerJniStorage* lpJniStorage = (visualizerJniStorage *)env->GetIntField(
+        visualizerJniStorage* lpJniStorage = (visualizerJniStorage *)env->GetLongField(
             thiz, fields.fidJniData);
 
         if (NULL != lpJniStorage)
@@ -475,10 +475,14 @@
 {
     Visualizer* lpVisualizer = getVisualizer(env, thiz);
     if (lpVisualizer == NULL) {
-        return false;
+        return JNI_FALSE;
     }
 
-    return (jboolean)lpVisualizer->getEnabled();
+    if (lpVisualizer->getEnabled()) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
 }
 
 static jintArray
@@ -496,7 +500,7 @@
 static jint
 android_media_visualizer_native_getMaxCaptureRate(JNIEnv *env, jobject thiz)
 {
-    return Visualizer::getMaxCaptureRate();
+    return (jint) Visualizer::getMaxCaptureRate();
 }
 
 static jint
@@ -517,7 +521,7 @@
     if (lpVisualizer == NULL) {
         return -1;
     }
-    return lpVisualizer->getCaptureSize();
+    return (jint) lpVisualizer->getCaptureSize();
 }
 
 static jint
@@ -538,7 +542,7 @@
     if (lpVisualizer == NULL) {
         return -1;
     }
-    return lpVisualizer->getScalingMode();
+    return (jint)lpVisualizer->getScalingMode();
 }
 
 static jint
@@ -568,7 +572,7 @@
     if (lpVisualizer == NULL) {
         return -1;
     }
-    return lpVisualizer->getSamplingRate();
+    return (jint) lpVisualizer->getSamplingRate();
 }
 
 static jint
@@ -634,7 +638,7 @@
     if (lpVisualizer == NULL) {
         return VISUALIZER_ERROR_NO_INIT;
     }
-    visualizerJniStorage* lpJniStorage = (visualizerJniStorage *)env->GetIntField(thiz,
+    visualizerJniStorage* lpJniStorage = (visualizerJniStorage *)env->GetLongField(thiz,
             fields.fidJniData);
     if (lpJniStorage == NULL) {
         return VISUALIZER_ERROR_NO_INIT;
diff --git a/media/jni/mediaeditor/VideoEditorClasses.cpp b/media/jni/mediaeditor/VideoEditorClasses.cpp
index d8099dd..d29fad3 100644
--- a/media/jni/mediaeditor/VideoEditorClasses.cpp
+++ b/media/jni/mediaeditor/VideoEditorClasses.cpp
@@ -609,7 +609,7 @@
 
 VIDEOEDIT_JAVA_DEFINE_FIELDS(Engine)
 {
-    VIDEOEDIT_JAVA_FIELD_INIT("mManualEditContext", "I")
+    VIDEOEDIT_JAVA_FIELD_INIT("mManualEditContext", "J")
 };
 
 VIDEOEDIT_JAVA_DEFINE_FIELD_CLASS(Engine, MANUAL_EDIT_ENGINE_CLASS_NAME)
@@ -3096,7 +3096,7 @@
     if (*pResult)
     {
         // Retrieve the context pointer.
-        pContext = (void *)pEnv->GetIntField(object, fieldIds.context);
+        pContext = (void *)pEnv->GetLongField(object, fieldIds.context);
     }
 
     // Return the context pointer.
@@ -3132,15 +3132,15 @@
     {
         // Set the context field.
         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_CLASSES",
-                        "The context value from JAVA before setting is = 0x%x",
-                        pEnv->GetIntField(object, fieldIds.context));
+                        "The context value from JAVA before setting is = %p",
+                        (void *)pEnv->GetLongField(object, fieldIds.context));
 
-        pEnv->SetIntField(object, fieldIds.context, (int)pContext);
-        M4OSA_TRACE1_1("The context value in JNI is = 0x%x",pContext);
+        pEnv->SetLongField(object, fieldIds.context, (jlong)pContext);
+        M4OSA_TRACE1_1("The context value in JNI is = %p",pContext);
 
         VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR_CLASSES",
-                         "The context value from JAVA after setting is = 0x%x",
-                         pEnv->GetIntField(object, fieldIds.context));
+                         "The context value from JAVA after setting is = %p",
+                         (void *)pEnv->GetLongField(object, fieldIds.context));
     }
 }
 
diff --git a/media/jni/mediaeditor/VideoEditorMain.cpp b/media/jni/mediaeditor/VideoEditorMain.cpp
index c1ad516..058012b 100644
--- a/media/jni/mediaeditor/VideoEditorMain.cpp
+++ b/media/jni/mediaeditor/VideoEditorMain.cpp
@@ -170,7 +170,7 @@
 static void videoEditor_release(
                 JNIEnv*                             pEnv,
                 jobject                             thiz);
-static int videoEditor_getPixels(
+static jint videoEditor_getPixels(
                                  JNIEnv*                  env,
                                  jobject                  thiz,
                                  jstring                  path,
@@ -178,7 +178,7 @@
                                  M4OSA_UInt32             width,
                                  M4OSA_UInt32             height,
                                  M4OSA_UInt32             timeMS);
-static int videoEditor_getPixelsList(
+static jint videoEditor_getPixelsList(
                                      JNIEnv*                  env,
                                      jobject                  thiz,
                                      jstring                  path,
@@ -209,7 +209,7 @@
                 jobject                 object,
                 jobject                 audioSettingObject);
 
-static int videoEditor_stopPreview(JNIEnv*  pEnv,
+static jint videoEditor_stopPreview(JNIEnv*  pEnv,
                               jobject  thiz);
 
 static jobject
@@ -218,7 +218,7 @@
                 jobject                             thiz,
                 jstring                             file);
 
-static int videoEditor_renderPreviewFrame(JNIEnv* pEnv,
+static jint videoEditor_renderPreviewFrame(JNIEnv* pEnv,
                                     jobject thiz,
                                     jobject    mSurface,
                                     jlong fromMs,
@@ -231,7 +231,7 @@
 static void jniPreviewProgressCallback(void* cookie, M4OSA_UInt32 msgType,
                                         void *argc);
 
-static int videoEditor_renderMediaItemPreviewFrame(JNIEnv* pEnv,
+static jint videoEditor_renderMediaItemPreviewFrame(JNIEnv* pEnv,
                                                     jobject thiz,
                                                     jobject mSurface,
                                                     jstring filePath,
@@ -241,7 +241,7 @@
                                                     jint surfaceHeight,
                                                     jlong fromMs);
 
-static int videoEditor_generateAudioWaveFormSync ( JNIEnv*     pEnv,
+static jint videoEditor_generateAudioWaveFormSync ( JNIEnv*     pEnv,
                                                   jobject     thiz,
                                                   jstring     pcmfilePath,
                                                   jstring     outGraphfilePath,
@@ -258,7 +258,7 @@
                                     M4OSA_Char* infilePath,
                                     M4OSA_Char* pcmfilePath );
 
-static int
+static jint
 videoEditor_generateClip(
                 JNIEnv*                             pEnv,
                 jobject                             thiz,
@@ -572,7 +572,7 @@
 
     return result;
 }
-static int videoEditor_stopPreview(JNIEnv*  pEnv,
+static jint videoEditor_stopPreview(JNIEnv*  pEnv,
                               jobject  thiz)
 {
     ManualEditContext* pContext = M4OSA_NULL;
@@ -594,7 +594,7 @@
         pContext->mOverlayFileName = NULL;
     }
 
-    return lastProgressTimeMs;
+    return (jint)lastProgressTimeMs;
 }
 
 static void videoEditor_clearSurface(JNIEnv* pEnv,
@@ -654,7 +654,7 @@
 
   }
 
-static int videoEditor_renderPreviewFrame(JNIEnv* pEnv,
+static jint videoEditor_renderPreviewFrame(JNIEnv* pEnv,
                                     jobject thiz,
                                     jobject    mSurface,
                                     jlong fromMs,
@@ -976,10 +976,10 @@
         free(yuvPlane);
     }
 
-    return tnTimeMs;
+    return (jint)tnTimeMs;
 }
 
-static int videoEditor_renderMediaItemPreviewFrame(JNIEnv* pEnv,
+static jint videoEditor_renderMediaItemPreviewFrame(JNIEnv* pEnv,
                                                     jobject thiz,
                                                     jobject mSurface,
                                                     jstring filePath,
@@ -1033,7 +1033,7 @@
     /* get thumbnail*/
     result = ThumbnailOpen(&tnContext,(const M4OSA_Char*)pString, M4OSA_TRUE);
     if (result != M4NO_ERROR || tnContext  == M4OSA_NULL) {
-        return timeMs;
+        return (jint)timeMs;
     }
 
     framesizeYuv = ((frameWidth)*(frameHeight)*1.5);
@@ -1046,7 +1046,7 @@
         ThumbnailClose(tnContext);
         pMessage = videoEditJava_getErrorName(M4ERR_ALLOC);
         jniThrowException(pEnv, "java/lang/RuntimeException", pMessage);
-        return timeMs;
+        return (jint)timeMs;
     }
 
     result = ThumbnailGetPixels16(tnContext, (M4OSA_Int16 *)pixelArray,
@@ -1055,7 +1055,7 @@
     if (result != M4NO_ERROR) {
         free(pixelArray);
         ThumbnailClose(tnContext);
-        return fromMs;
+        return (jint)fromMs;
     }
 
 #ifdef DUMPTOFILESYSTEM
@@ -1131,10 +1131,10 @@
         pEnv->ReleaseStringUTFChars(filePath, pString);
     }
 
-    return timeMs;
+    return (jint)timeMs;
 }
 
-int videoEditor_generateAudioRawFile(   JNIEnv*     pEnv,
+jint videoEditor_generateAudioRawFile(  JNIEnv*     pEnv,
                                         jobject     thiz,
                                         jstring     infilePath,
                                         jstring     pcmfilePath)
@@ -1178,7 +1178,7 @@
         pEnv->ReleaseStringUTFChars(pcmfilePath, pStringOutPCMFilePath);
     }
 
-    return result;
+    return (jint)result;
 }
 
 M4OSA_ERR videoEditor_generateAudio(JNIEnv* pEnv,ManualEditContext* pContext,
@@ -2182,7 +2182,7 @@
     return object;
 
 }
-static int videoEditor_getPixels(
+static jint videoEditor_getPixels(
                     JNIEnv*                     env,
                     jobject                     thiz,
                     jstring                     path,
@@ -2234,10 +2234,10 @@
         env->ReleaseStringUTFChars(path, pString);
     }
 
-    return timeMS;
+    return (jint)timeMS;
 }
 
-static int videoEditor_getPixelsList(
+static jint videoEditor_getPixelsList(
                 JNIEnv*                 env,
                 jobject                 thiz,
                 jstring                 path,
@@ -2257,7 +2257,7 @@
     const char *pString = env->GetStringUTFChars(path, NULL);
     if (pString == M4OSA_NULL) {
         jniThrowException(env, "java/lang/RuntimeException", "Input string null");
-        return M4ERR_ALLOC;
+        return (jint)M4ERR_ALLOC;
     }
 
     err = ThumbnailOpen(&mContext,(const M4OSA_Char*)pString, M4OSA_FALSE);
@@ -2266,7 +2266,7 @@
         if (pString != NULL) {
             env->ReleaseStringUTFChars(path, pString);
         }
-        return err;
+        return (jint)err;
     }
 
     jlong duration = (endTime - startTime);
@@ -2307,7 +2307,7 @@
                 "ThumbnailGetPixels32 failed");
     }
 
-    return err;
+    return (jint)err;
 }
 
 static M4OSA_ERR
@@ -2892,7 +2892,7 @@
 }
 /*+ PROGRESS CB */
 
-static int
+static jint
 videoEditor_generateClip(
                 JNIEnv*                             pEnv,
                 jobject                             thiz,
@@ -2934,7 +2934,7 @@
     }
 
     ALOGV("videoEditor_generateClip END 0x%x", (unsigned int) result);
-    return result;
+    return (jint)result;
 }
 
 static void
@@ -3556,7 +3556,7 @@
     return err;
 }
 
-static int videoEditor_generateAudioWaveFormSync (JNIEnv*  pEnv, jobject thiz,
+static jint videoEditor_generateAudioWaveFormSync (JNIEnv*  pEnv, jobject thiz,
                                                   jstring pcmfilePath,
                                                   jstring outGraphfilePath,
                                                   jint frameDuration, jint channels,
@@ -3619,7 +3619,7 @@
     VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR",
         "videoEditor_generateAudioWaveFormSync pContext->bSkipState ");
 
-    return result;
+    return (jint)result;
 }
 
 /******** End Audio Graph *******/
diff --git a/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp b/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
index 2604850..9cc55ab 100644
--- a/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
+++ b/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
@@ -34,11 +34,11 @@
 } fields;
 
 static inline SoundPool* MusterSoundPool(JNIEnv *env, jobject thiz) {
-    return (SoundPool*)env->GetIntField(thiz, fields.mNativeContext);
+    return (SoundPool*)env->GetLongField(thiz, fields.mNativeContext);
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_SoundPool_SoundPoolImpl_load_URL(JNIEnv *env, jobject thiz, jstring path, jint priority)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_load_URL");
@@ -50,29 +50,29 @@
     const char* s = env->GetStringUTFChars(path, NULL);
     int id = ap->load(s, priority);
     env->ReleaseStringUTFChars(path, s);
-    return id;
+    return (jint) id;
 }
 
-static int
+static jint
 android_media_SoundPool_SoundPoolImpl_load_FD(JNIEnv *env, jobject thiz, jobject fileDescriptor,
         jlong offset, jlong length, jint priority)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_load_FD");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return 0;
-    return ap->load(jniGetFDFromFileDescriptor(env, fileDescriptor),
+    return (jint) ap->load(jniGetFDFromFileDescriptor(env, fileDescriptor),
             int64_t(offset), int64_t(length), int(priority));
 }
 
-static bool
+static jboolean
 android_media_SoundPool_SoundPoolImpl_unload(JNIEnv *env, jobject thiz, jint sampleID) {
     ALOGV("android_media_SoundPool_SoundPoolImpl_unload\n");
     SoundPool *ap = MusterSoundPool(env, thiz);
-    if (ap == NULL) return 0;
-    return ap->unload(sampleID);
+    if (ap == NULL) return JNI_FALSE;
+    return ap->unload(sampleID) ? JNI_TRUE : JNI_FALSE;
 }
 
-static int
+static jint
 android_media_SoundPool_SoundPoolImpl_play(JNIEnv *env, jobject thiz, jint sampleID,
         jfloat leftVolume, jfloat rightVolume, jint priority, jint loop,
         jfloat rate)
@@ -80,7 +80,7 @@
     ALOGV("android_media_SoundPool_SoundPoolImpl_play\n");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return 0;
-    return ap->play(sampleID, leftVolume, rightVolume, priority, loop, rate);
+    return (jint) ap->play(sampleID, leftVolume, rightVolume, priority, loop, rate);
 }
 
 static void
@@ -130,22 +130,22 @@
 
 static void
 android_media_SoundPool_SoundPoolImpl_setVolume(JNIEnv *env, jobject thiz, jint channelID,
-        float leftVolume, float rightVolume)
+        jfloat leftVolume, jfloat rightVolume)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_setVolume");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return;
-    ap->setVolume(channelID, leftVolume, rightVolume);
+    ap->setVolume(channelID, (float) leftVolume, (float) rightVolume);
 }
 
 static void
 android_media_SoundPool_SoundPoolImpl_setPriority(JNIEnv *env, jobject thiz, jint channelID,
-        int priority)
+        jint priority)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_setPriority");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return;
-    ap->setPriority(channelID, priority);
+    ap->setPriority(channelID, (int) priority);
 }
 
 static void
@@ -160,12 +160,12 @@
 
 static void
 android_media_SoundPool_SoundPoolImpl_setRate(JNIEnv *env, jobject thiz, jint channelID,
-        float rate)
+       jfloat rate)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_setRate");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return;
-    ap->setRate(channelID, rate);
+    ap->setRate(channelID, (float) rate);
 }
 
 static void android_media_callback(SoundPoolEvent event, SoundPool* soundPool, void* user)
@@ -185,7 +185,7 @@
     }
 
     // save pointer to SoundPool C++ object in opaque field in Java object
-    env->SetIntField(thiz, fields.mNativeContext, (int)ap);
+    env->SetLongField(thiz, fields.mNativeContext, (jlong) ap);
 
     // set callback with weak reference
     jobject globalWeakRef = env->NewGlobalRef(weakRef);
@@ -208,7 +208,7 @@
 
         // clear callback and native context
         ap->setCallback(NULL, NULL);
-        env->SetIntField(thiz, fields.mNativeContext, 0);
+        env->SetLongField(thiz, fields.mNativeContext, 0);
         delete ap;
     }
 }
@@ -299,7 +299,7 @@
         goto bail;
     }
 
-    fields.mNativeContext = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.mNativeContext = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.mNativeContext == NULL) {
         ALOGE("Can't find SoundPoolImpl.mNativeContext");
         goto bail;
diff --git a/media/lib/java/com/android/media/remotedisplay/RemoteDisplay.java b/media/lib/java/com/android/media/remotedisplay/RemoteDisplay.java
index 5e15702..6cfc0e8 100644
--- a/media/lib/java/com/android/media/remotedisplay/RemoteDisplay.java
+++ b/media/lib/java/com/android/media/remotedisplay/RemoteDisplay.java
@@ -16,12 +16,12 @@
 
 package com.android.media.remotedisplay;
 
-import com.android.internal.util.Objects;
-
 import android.media.MediaRouter;
 import android.media.RemoteDisplayState.RemoteDisplayInfo;
 import android.text.TextUtils;
 
+import java.util.Objects;
+
 /**
  * Represents a remote display that has been discovered.
  */
@@ -87,7 +87,7 @@
     }
 
     public void setName(String name) {
-        if (!Objects.equal(mMutableInfo.name, name)) {
+        if (!Objects.equals(mMutableInfo.name, name)) {
             mMutableInfo.name = name;
             mImmutableInfo = null;
         }
@@ -98,7 +98,7 @@
     }
 
     public void setDescription(String description) {
-        if (!Objects.equal(mMutableInfo.description, description)) {
+        if (!Objects.equals(mMutableInfo.description, description)) {
             mMutableInfo.description = description;
             mImmutableInfo = null;
         }
diff --git a/media/mca/filterfw/jni/jni_gl_environment.cpp b/media/mca/filterfw/jni/jni_gl_environment.cpp
index 9abf191..6da7b7c 100644
--- a/media/mca/filterfw/jni/jni_gl_environment.cpp
+++ b/media/mca/filterfw/jni/jni_gl_environment.cpp
@@ -119,12 +119,12 @@
         return NULL;
     }
 
-    jfieldID context = env->GetFieldID(clazz, "mNativeContext", "I");
+    jfieldID context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (context == NULL) {
         return NULL;
     }
 
-    MediaRecorder* const p = (MediaRecorder*)env->GetIntField(jmediarecorder, context);
+    MediaRecorder* const p = (MediaRecorder*)env->GetLongField(jmediarecorder, context);
     env->DeleteLocalRef(clazz);
     return sp<MediaRecorder>(p);
 }
diff --git a/media/tests/omxjpegdecoder/omx_jpeg_decoder.cpp b/media/tests/omxjpegdecoder/omx_jpeg_decoder.cpp
index 53f04bc..6424744 100644
--- a/media/tests/omxjpegdecoder/omx_jpeg_decoder.cpp
+++ b/media/tests/omxjpegdecoder/omx_jpeg_decoder.cpp
@@ -30,7 +30,6 @@
 #include <media/stagefright/MetaData.h>
 #include <media/stagefright/OMXClient.h>
 #include <media/stagefright/OMXCodec.h>
-#include <SkImage.h>
 #include <SkMallocPixelRef.h>
 
 #include "omx_jpeg_decoder.h"
@@ -185,7 +184,8 @@
 
 void OmxJpegImageDecoder::configBitmapSize(SkBitmap* bm, SkBitmap::Config pref,
         int width, int height) {
-    bm->setConfig(getColorSpaceConfig(pref), width, height, 0, kOpaque_SkAlphaType);
+    bm->setConfig(getColorSpaceConfig(pref), width, height);
+    bm->setIsOpaque(true);
 }
 
 SkBitmap::Config OmxJpegImageDecoder::getColorSpaceConfig(
diff --git a/native/android/input.cpp b/native/android/input.cpp
index e9d08b4..fc52138 100644
--- a/native/android/input.cpp
+++ b/native/android/input.cpp
@@ -273,7 +273,7 @@
 void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
         int ident, ALooper_callbackFunc callback, void* data) {
     InputQueue* iq = static_cast<InputQueue*>(queue);
-    Looper* l = static_cast<Looper*>(looper);
+    Looper* l = reinterpret_cast<Looper*>(looper);
     iq->attachLooper(l, ident, callback, data);
 }
 
diff --git a/native/android/looper.cpp b/native/android/looper.cpp
index 455e950..24cb234 100644
--- a/native/android/looper.cpp
+++ b/native/android/looper.cpp
@@ -25,20 +25,28 @@
 using android::sp;
 using android::IPCThreadState;
 
+static inline Looper* ALooper_to_Looper(ALooper* alooper) {
+    return reinterpret_cast<Looper*>(alooper);
+}
+
+static inline ALooper* Looper_to_ALooper(Looper* looper) {
+    return reinterpret_cast<ALooper*>(looper);
+}
+
 ALooper* ALooper_forThread() {
-    return Looper::getForThread().get();
+    return Looper_to_ALooper(Looper::getForThread().get());
 }
 
 ALooper* ALooper_prepare(int opts) {
-    return Looper::prepare(opts).get();
+    return Looper_to_ALooper(Looper::prepare(opts).get());
 }
 
 void ALooper_acquire(ALooper* looper) {
-    static_cast<Looper*>(looper)->incStrong((void*)ALooper_acquire);
+    ALooper_to_Looper(looper)->incStrong((void*)ALooper_acquire);
 }
 
 void ALooper_release(ALooper* looper) {
-    static_cast<Looper*>(looper)->decStrong((void*)ALooper_acquire);
+    ALooper_to_Looper(looper)->decStrong((void*)ALooper_acquire);
 }
 
 int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData) {
@@ -64,14 +72,14 @@
 }
 
 void ALooper_wake(ALooper* looper) {
-    static_cast<Looper*>(looper)->wake();
+    ALooper_to_Looper(looper)->wake();
 }
 
 int ALooper_addFd(ALooper* looper, int fd, int ident, int events,
         ALooper_callbackFunc callback, void* data) {
-    return static_cast<Looper*>(looper)->addFd(fd, ident, events, callback, data);
+    return ALooper_to_Looper(looper)->addFd(fd, ident, events, callback, data);
 }
 
 int ALooper_removeFd(ALooper* looper, int fd) {
-    return static_cast<Looper*>(looper)->removeFd(fd);
+    return ALooper_to_Looper(looper)->removeFd(fd);
 }
diff --git a/opengl/java/android/opengl/EGLLogWrapper.java b/opengl/java/android/opengl/EGLLogWrapper.java
index 36e88a2..c677957 100644
--- a/opengl/java/android/opengl/EGLLogWrapper.java
+++ b/opengl/java/android/opengl/EGLLogWrapper.java
@@ -326,7 +326,7 @@
     }
 
     public boolean eglSwapBuffers(EGLDisplay display, EGLSurface surface) {
-        begin("eglInitialize");
+        begin("eglSwapBuffers");
         arg("display", display);
         arg("surface", surface);
         end();
diff --git a/packages/BackupRestoreConfirmation/res/values-en-rIN/strings.xml b/packages/BackupRestoreConfirmation/res/values-en-rIN/strings.xml
deleted file mode 100644
index d096d98..0000000
--- a/packages/BackupRestoreConfirmation/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"Full backup"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"Full restoration"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"A full backup of all data to a connected desktop computer has been requested. Do you want to allow this to happen?\n\nIf you did not request the backup yourself, do not allow the operation to proceed."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"Back up my data"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"Do not back up"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"A full restore of all data from a connected desktop computer has been requested. Do you want to allow this to happen?\n\nIf you did not request the restore yourself, do not allow the operation to proceed. This will replace any data currently on the device!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"Restore my data"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"Do not restore"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"Please enter your current backup password below:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"Please enter your device encryption password below."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"Please enter your device encryption password below. This will also be used to encrypt the backup archive."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"Please enter a password to use for encrypting the full backup data. If this is left blank, your current backup password will be used:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"If you wish to encrypt the full backup data, enter a password below:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"If the restore data is encrypted, please enter the password below:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"Backup starting..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"Backup finished"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"Restoration starting..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"Restoration ended"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"Operation timed out"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-et-rEE/strings.xml b/packages/BackupRestoreConfirmation/res/values-et-rEE/strings.xml
deleted file mode 100644
index 0f5fde2..0000000
--- a/packages/BackupRestoreConfirmation/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"Täielik varundus"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"Täielik taastamine"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"Taotleti kõikide andmete varundamist ühendatud lauaarvutist. Kas soovite seda lubada?\n\nKui te ei taotlenud varundust, siis ärge lubage toimingut jätkata."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"Varunda mu andmed"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"Ära varunda"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"Taotletud on kõikide andmete taastamist ühendatud lauaarvutist. Kas soovite seda lubada?\n\nKui te ei taotlenud taastamist, siis ärge lubage toimingut jätkata. See asendab kõik praegu seadmes olevad andmed."</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"Taasta mu andmed"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"Ära taasta"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"Sisestage allpool praegune varunduse parool:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"Sisestage allpool oma seadme krüpteerimise parool."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"Sisestage allpool oma seadme krüpteerimise parool. Seda kasutatakse ka varukoopiate arhiivi krüpteerimiseks."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"Sisestage parool kõikide varundatud andmete krüpteerimise jaoks. Kui jätate selle tühjaks, siis kasutatakse teie praegust varunduse parooli:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"Kui soovite kõik varundusandmed krüpteerida, siis sisestage allpool parool:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"Kui taasteandmed on krüpteeritud, siis sisestage allpool parool."</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"Algab varundamine ..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"Varundamine jõudis lõpule"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"Algab taastamine ..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"Taastamine jõudis lõpule"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"Toiming aegus"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-fr-rCA/strings.xml b/packages/BackupRestoreConfirmation/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 8a70fb5..0000000
--- a/packages/BackupRestoreConfirmation/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"Sauvegarde complète"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"Restauration complète"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"Vous avez demandé une sauvegarde complète de l\'ensemble des données vers un ordinateur de bureau connecté. Voulez-vous l\'autoriser?\n\nSi vous n\'avez pas demandé la sauvegarde vous-même, n\'autorisez pas la poursuite de l\'opération."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"Sauvegarder mes données"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"Ne pas sauvegarder"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"Vous avez demandé une restauration complète de l\'ensemble des données à partir d\'un ordinateur de bureau connecté. Voulez-vous l\'autoriser?\n\nSi vous n\'avez pas demandé vous-même la restauration, n\'autorisez pas sa poursuite. Cette opération remplacera toutes les données actuellement sur l\'appareil!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"Restaurer mes données"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"Ne pas restaurer"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"Veuillez saisir votre mot de passe de sauvegarde actuel ci-dessous :"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"Veuillez saisir le mot de passe de chiffrement de l\'appareil ci-dessous."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"Veuillez saisir le mot de passe de chiffrement de l\'appareil ci-dessous. Il permettra également de chiffrer les archives de sauvegarde."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"Veuillez saisir un mot de passe à utiliser pour chiffrer les données de sauvegarde complète. Si ce champ n\'est pas renseigné, votre mot de passe de sauvegarde actuel sera utilisé :"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"Si vous souhaitez chiffrer l\'ensemble des données de sauvegarde, veuillez saisir un mot de passe ci-dessous :"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"Si les données de restauration sont chiffrées, veuillez saisir le mot de passe ci-dessous :"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"Démarrage de la sauvegarde…"</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"Sauvegarde terminée."</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"Démarrage de la restauration…"</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"Restauration terminée."</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"L\'opération a expiré."</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-hi/strings.xml b/packages/BackupRestoreConfirmation/res/values-hi/strings.xml
index 0b29804..dd0c645 100644
--- a/packages/BackupRestoreConfirmation/res/values-hi/strings.xml
+++ b/packages/BackupRestoreConfirmation/res/values-hi/strings.xml
@@ -16,22 +16,22 @@
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"पूर्ण सुरक्षा"</string>
+    <string name="backup_confirm_title" msgid="827563724209303345">"पूर्ण बैकअप"</string>
     <string name="restore_confirm_title" msgid="5469365809567486602">"पूर्ण पुनर्स्‍थापना"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"कनेक्‍ट कि‍ए गए डेस्‍कटॉप कंप्‍यूटर से सभी डेटा के संपूर्ण सुरक्षा का अनुरोध कि‍या गया है. क्‍या आप इसकी अनुमति‍ देना चाहते हैं?\n\nयदि‍ आपने स्‍वयं बैकअप का अनुरोध नहीं कि‍या है, तो प्रक्रि‍या जारी रखने की अनुमति‍ न दें."</string>
+    <string name="backup_confirm_text" msgid="1878021282758896593">"कनेक्‍ट कि‍ए गए डेस्‍कटॉप कंप्‍यूटर से सभी डेटा के संपूर्ण बैकअप का अनुरोध कि‍या गया है. क्‍या आप इसकी अनुमति‍ देना चाहते हैं?\n\nयदि‍ आपने स्‍वयं बैकअप का अनुरोध नहीं कि‍या है, तो प्रक्रि‍या जारी रखने की अनुमति‍ न दें."</string>
     <string name="allow_backup_button_label" msgid="4217228747769644068">"मेरे डेटा का बैकअप लें"</string>
     <string name="deny_backup_button_label" msgid="6009119115581097708">"बैकअप न लें"</string>
     <string name="restore_confirm_text" msgid="7499866728030461776">"कनेक्‍ट कि‍ए गए डेस्‍कटॉप कंप्‍यूटर से सभी डेटा की पूर्ण पुनर्स्थापना का अनुरोध कि‍या गया है. क्‍या आप इसकी अनुमति‍ देना चाहते हैं?\n\nयदि‍ आपने स्‍वयं पुनर्प्राप्ति‍ का अनुरोध नहीं कि‍या है, तो प्रक्रि‍या जारी रखने की अनुमति‍ न दें. इससे वर्तमान में आपके उपकरण पर मौजूद डेटा बदल जाएगा!"</string>
     <string name="allow_restore_button_label" msgid="3081286752277127827">"मेरा डेटा पुनर्स्थापित करें"</string>
     <string name="deny_restore_button_label" msgid="1724367334453104378">"पुनर्स्‍थापित न करें"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"कृपया नीचे अपना वर्तमान सुरक्षित करने का पासवर्ड डालें:"</string>
+    <string name="current_password_text" msgid="8268189555578298067">"कृपया नीचे अपना वर्तमान बैकअप पासवर्ड डालें:"</string>
     <string name="device_encryption_restore_text" msgid="1570864916855208992">"कृपया नीचे अपना उपकरण एन्‍क्रिप्शन पासवर्ड डालें."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"कृपया अपना उपकरण सुरक्षित तरीका पासवर्ड नीचे दर्ज करें. बैकअप संग्रहण को एन्‍क्रिप्‍ट करने के लिए भी इसका उपयोग किया जाएगा."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"कृपया संपूर्ण सुरक्षित डेटा को एन्‍क्रि‍प्‍ट करने में उपयोग के लि‍ए पासवर्ड डालें. यदि‍ यह खाली छोड़ दि‍या जाता है, तो आपके वर्तमान बैकअप पासवर्ड का उपयोग कि‍या जाएगा:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"यदि‍ आप संपूर्ण सुरक्षित डेटा को एन्‍क्रि‍प्‍ट करना चाहते हैं, तो नीचे पासवर्ड डालें:"</string>
+    <string name="device_encryption_backup_text" msgid="5866590762672844664">"कृपया अपना उपकरण एन्क्रिप्शन पासवर्ड नीचे दर्ज करें. बैकअप संग्रहण को एन्‍क्रिप्‍ट करने के लिए भी इसका उपयोग किया जाएगा."</string>
+    <string name="backup_enc_password_text" msgid="4981585714795233099">"कृपया संपूर्ण बैकअप डेटा को एन्‍क्रि‍प्‍ट करने में उपयोग के लि‍ए पासवर्ड डालें. यदि‍ यह खाली छोड़ दि‍या जाता है, तो आपके वर्तमान बैकअप पासवर्ड का उपयोग कि‍या जाएगा:"</string>
+    <string name="backup_enc_password_optional" msgid="1350137345907579306">"यदि‍ आप संपूर्ण बैकअप डेटा एन्‍क्रि‍प्‍ट करना चाहते हैं, तो नीचे पासवर्ड डालें:"</string>
     <string name="restore_enc_password_text" msgid="6140898525580710823">"यदि‍ पुनर्स्थापित डेटा को एन्‍क्रि‍प्‍ट कि‍या गया है, तो कृपया नीचे पासवर्ड डालें:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"सुरक्षित करना शुरु हो रहा है..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"सुरक्षित करना पूर्ण"</string>
+    <string name="toast_backup_started" msgid="550354281452756121">"बैकअप प्रारंभ हो रहा है..."</string>
+    <string name="toast_backup_ended" msgid="3818080769548726424">"बैकअप पूर्ण"</string>
     <string name="toast_restore_started" msgid="7881679218971277385">"पुनर्स्‍थापना प्रारंभ हो रही है..."</string>
     <string name="toast_restore_ended" msgid="1764041639199696132">"पुनर्स्‍थापना समाप्त"</string>
     <string name="toast_timeout" msgid="5276598587087626877">"कार्यवाही समयबाह्य हो गई"</string>
diff --git a/packages/BackupRestoreConfirmation/res/values-hy-rAM/strings.xml b/packages/BackupRestoreConfirmation/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 4db9080..0000000
--- a/packages/BackupRestoreConfirmation/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"Ամբողջական պահուստավորում"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"Ամբողջական վերականգնում"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"Կապակցված աշխատասեղանով համակարգչի վրա բոլոր տվյալների լրիվ պահուստավորման հարցում է արվել: Ցանկանու՞մ եք թույլատրել հարցման կատարումը:\n\nԵթե դուք ինքներդ պահուստավորման հարցում չեք արել, թույլ մի տվեք, որպեսզի գործողությունը շարունակվի:"</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"Պահուստավորել իմ տվյալները"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"Չպահուստավորել"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"Հայցվել է բոլոր տվյալների ամբողջական վերականգնում միացված աշխատանքային համակարգչից: Ցանկանու՞մ եք թույլատրել, որ դա տեղի ունենա:\n\nԵթե վերականգնումը ինքներդ չեք հայցել, թուjլ մի տվեք, որ գործողությունը շարունակվի: Դա կփոխարինի ներկայում հեռախոսի մեջ գտնվող ցանկացած տվյալ:"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"Վերականգնել իմ տվյալները"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"Չվերականգնել"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"Խնդրում ենք մուտքագրել ձեր ընթացիկ պահուստային գաղտնաբառը ներքևում`"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"Խնդրում ենք մուտքագրել ձեր սարքի կոդավորված գաղտնաբառը ներքևում:"</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"Խնդրում ենք մուտքագրել ձեր սարքի կոդավորված գաղտնաբառը ներքևում: Այն նաև կօգտագործվի պահուստային արխիվի կոդավորման համար:"</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"Խնդրում ենք մուտքագրել գաղտնաբառը` ամբողջական պահուստավորվող տվյալները կոդավորելու համար: Եթե ​​այն դատարկ թողնեք, ապա կօգտագործվի ձեր առկա պահուստավորման գաղտնաբառը`"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"Եթե ​​ցանկանում եք կոդավորել ամբողջական պահուստավորված տվյալները, մուտքագրեք գաղտնաբառ ստորև`"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"Եթե ​​վերականգնվող տվյալները կոդավորված են, խնդրում ենք մուտքագրել գաղտնաբառը ստորև`"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"Պահուստավորումը սկսվում է..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"Պահուստավորումն ավարտվեց"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"Վերականգնումը մեկնարկեց..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"Վերականգնումն ավարտվեց"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"Գործողության ժամանակը սպառվեց"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-ka-rGE/strings.xml b/packages/BackupRestoreConfirmation/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 9c6f67e..0000000
--- a/packages/BackupRestoreConfirmation/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"სრული სარეზერვო კოპირება"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"სრულად აღდგენა"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"მოთხოვნილ იქნა სამაგიდო კომპიუტერთან დაკავშირებული ყველა მონაცემის სრულყოფილი სარეზერვო ასლები. \n\nთუ სარეზერვო ასლები თქვენ არ მოგითხოვიათ, არ დაუშვათ ამ ოპერაციის გაგრძელება."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"ჩემი მონაცემების სარეზერვო კოპირება"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"სარეზერვო ასლები არ გააკეთო"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"დაკავშირებული დესკტოპ კომპიუტერიდან მოხდა ყველა მონაცემის სრული აღდგენის მოთხოვნა. გსურთ, დაუშვათ ეს?\n\nთუ თქვენ თვითონ არ მოითხოვეთ აღდგენა, არ დაუშვათ ამ ოპერაციის გაგრძელება. ის ჩაანაცვლებს მოწყობილობაზე ამჟამად არსებულ ნებისმიერ მონაცემს!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"ჩემი მონაცემების აღდგენა"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"არ აღადგინო"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"გთხოვთ, ქვემოთ მიუთითოთ თქვენი ამჟამინდელი სათადარიგო პაროლი:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"გთხოვთ, ქვემოთ მიუთითოთ თქვენი მოწყობილობის დაშიფვრის პაროლი."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"გთხოვთ, ქვემოთ მიუთითოთ თქვენი მოწყობილობის დაშიფვრის პაროლი. ეს ასევე გამოყენებული იქნება სათადარიგო არქივის დაშიფრვისათვის."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"გთხოვთ შეიყვანოთ ყველა სამარქაფო ასლის დაშიფრვის პაროლი. თუ ამ ველს ცარიელს დატოვებთ, გამოყენებული იქნება მიმდინარე პაროლი:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"თუ გსურთ სრული ლოკალური სარეზერვო კოპიის დაშიფრვა, შეიყვანეთ პაროლი ქვემოთ:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"თუ აღსადგენი მონაცემები დაშიფრულია, გთხოვთ, შეიყვანოთ პაროლი ქვემოთ:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"ასლების მომზადება იწყება..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"სარეზერვო კოპირება დასრულებულია"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"აღდგენა იწყება..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"აღდგენა დასრულდა"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"ოპერაციის დროის ლიმიტი ამოიწურა"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-km-rKH/strings.xml b/packages/BackupRestoreConfirmation/res/values-km-rKH/strings.xml
deleted file mode 100644
index 956fdd7..0000000
--- a/packages/BackupRestoreConfirmation/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"ការ​បម្រុង​ទុក​ពេញលេញ"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"ស្ដារ​ឡើងវិញ​ពេញលេញ"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"ការ​បម្រុងទុក​ទិន្នន័យ​ទាំងអស់​ពេញលេញ​​ទៅ​កុំព្យូទ័រ​ដែល​បាន​ភ្ជាប់​ត្រូវ​បាន​ស្នើ។ តើ​អ្នក​ចង់ឲ្យ​វា​កើត​ឡើង​ដែរ​ឬទេ??\n\nបើ​អ្នក​មិន​បាន​ស្នើ​ការ​បម្រុងទុក​ដោយ​ខ្លួន​អ្នក​ផ្ទាល់​ទេ កុំ​អនុញ្ញាត​ប្រតិបត្តិការ​នេះ។"</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"បម្រុង​ទុក​ទិន្នន័យ​របស់​ខ្ញុំ"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"កុំ​បម្រុង​ទុក"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"ការ​ស្ដារ​ទិន្នន័យ​ទាំងអស់​ពេញលេញ​ពី​កុំព្យូទ័រ​ដែល​បាន​តភ្ជាប់​ត្រូវ​បាន​ស្នើ។ តើ​អ្នក​ចង់​អនុញ្ញាត​ដែរ​ឬទេ?\n\n បើ​អ្នក​មិន​បាន​ស្នើ​ការ​ស្ដារ​ខ្លួន​ឯង​ទេ កុំ​អនុញ្ញាត។ វា​នឹង​ជំនួស​ទិន្នន័យ​ណាមួយ​ដែល​មាន​លើ​ឧបករណ៍!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"ស្ដារ​ទិន្នន័យ​របស់​ខ្ញុំ"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"កុំ​ស្ដារ​ឡើងវិញ"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"សូម​បញ្ចូល​ពាក្យ​សម្ងាត់​បម្រុង​ទុក​បច្ចុប្បន្ន​របស់​អ្នក​ខាង​ក្រោម៖"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"សូម​បញ្ចូល​ពាក្យ​សម្ងាត់​ដាក់​លេខ​កូដ​​ឧបករណ៍​របស់​​អ្នក​ខាង​ក្រោម។"</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"សូម​បញ្ចូល​ពាក្យ​សម្ងាត់​ដាក់​លេខ​កូដ​ឧបករណ៍​របស់​អ្នក​ខាង​ក្រោម។ វា​នឹង​ត្រូវ​បាន​ប្រើ ដើម្បី​ដាក់​លេខ​កូដ​ប័ណ្ណសារ​បម្រុងទុក​ផង​ដែរ។"</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"សូម​បញ្ចូល​ពាក្យ​សម្ងាត់​ដើម្បី​ប្រើ​សម្រាប់​ដាក់លេខ​កូដ​ទិន្នន័យ​បម្រុងទុក​ពេញលេញ។ បើ​ទុក​វា​ទទេ ពាក្យ​សម្ងាត់​បម្រុងទុក​បច្ចុប្បន្ន​របស់​អ្នក​នឹង​ត្រូវ​បាន​ប្រើ៖"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"បើ​អ្នក​ចង់​ដាក់​លេខ​កូដ​ទិន្នន័យ​បម្រុងទុក​ពេញលេញ បញ្ចូល​ពាក្យ​សម្ងាត់​ខាង​ក្រោម៖"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"បើ​​ទិន្នន័យ​ស្ដារ​ត្រូវ​បាន​ដាក់​លេខ​កូដ សូម​បញ្ចូល​ពាក្យ​សម្ងាត់​ខាង​ក្រោម៖"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"កំពុង​ចាប់ផ្ដើម​បម្រុងទុក..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"ការ​​បម្រុង​ទុក​បាន​បញ្ចប់"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"ការ​ស្ដារ​កំពុង​ចាប់ផ្ដើម..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"ការ​ស្តា​រ​បាន​បញ្ចប់"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"ប្រតិបត្តិការ​អស់​ពេល"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-lo-rLA/strings.xml b/packages/BackupRestoreConfirmation/res/values-lo-rLA/strings.xml
deleted file mode 100644
index fb28502..0000000
--- a/packages/BackupRestoreConfirmation/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"ສຳຮອງຂໍ້ມູນເຕັມຮູບແບບ"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"ກູ້ຂໍ້ມູນເຕັມຮູບແບບ"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"ມີການຮ້ອງຂໍໃຫ້ສຳຮອງຂໍ້ມູນທັງໝົດ ໄປໃສ່ຄອມພິວເຕີຕັ້ງໂຕະທີ່ເຊື່ອມຕໍ່ຢູ່. ທ່ານຈະອະນຸມັດໃຫ້ດຳເນີນການຫຼືບໍ່?\n\nຫາກທ່ານບໍ່ໄດ້ຮ້ອງຂໍໃຫ້ສຳຮອງຂໍ້ມູນດ້ວຍຕົນເອງ, ກະລຸນາຢ່າອະນຸຍາດໃຫ້ດຳເນີນການຕໍ່ໄປ."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"ສຳຮອງຂໍ້ມູນຂອງຂ້ອຍ"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"ບໍ່ໃຫ້ສຳຮອງຂໍ້ມູນ"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"ການກູ້ຂໍ້ມູນທັງໝົດຈາກຄອມພິວເຕີທີ່ເຊື່ອມຕໍ່ຢູ່ນັ້ນຖືກຮ້ອງຂໍແລ້ວ. ທ່ານຕ້ອງການອະນຸຍາດໃຫ້ການກະທຳນີ້ເກີດຂຶ້ນບໍ່?\n\nຫາກທ່ານບໍ່ໄດ້ເຮັດການຮ້ອງຂໍ້ການກູ້ຂໍ້ມູນດ້ວຍໂຕທ່ານເອງ, ທ່ານບໍ່ຄວນອະນຸຍາດໃຫ້ມີການດຳເນີນການໃດໆ ເນື່ອງຈາກມັນຈະໄປຂຽນທັບຂໍ້ມູນທັງໝົດທີ່ຢູ່ໃນອຸປະກອນ!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"ກູ້ຄືນຂໍ້ມູນຂອງຂ້ອຍ"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"ບໍ່ໃຫ້ກູ້ຄືນ"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"ກະລຸນາປ້ອນລະຫັດຜ່ານການສຳຮອງຂໍ້ມູນທີ່ທ່ານໃຊ້ຢູ່ໃສ່ດ້ານລຸ່ມ:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"ກະລຸນາປ້ອນລະຫັດຜ່ານການເຂົ້າລະຫັດອຸປະກອນຂອງທ່ານໃສ່ດ້ານລຸ່ມ."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"ກະລຸນາປ້ອນລະຫັດຜ່ານການເຂົ້າລະຫັດອຸປະກອນຂອງທ່ານໃສ່ດ້ານລຸ່ມ. ລະຫັດນີ້ຍັງຈະໃຊ້ເພື່ອເຂົ້າລະຫັດຂໍ້ມູນທີ່ສຳຮອງໄວ້."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"ກະລຸນາປ້ອນລະຫັດຜ່ານ ເພື່ອໃຊ້ໃນການເຂົ້າລະຫັດການສຳຮອງຂໍ້ມູນເຕັມຮູບແບບ. ຖ້າປ່ອຍໃຫ້ເປົ່າຫວ່າງໄວ້, ລະຫັດຜ່ານສຳຮອງຂໍ້ມູນທີ່ທ່ານໃຊ້ຢູ່ຈະຖືກນຳໃຊ້ແທນ:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"ຫາກທ່ານຕ້ອງການທີ່ຈະເຂົ້າລະຫັດໃຫ້ກັບການສຳຮອງຂໍ້ມູນທັງໝົດ, ກະລຸນາໃສ່ລະຫັດທາງລຸ່ມນີ້:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"ຫາກຂໍ້ມູນສຳຮອງຖືກເຂົ້າລະຫັດໄວ້, ກະລຸນາໃສ່ລະຫັດຜ່ານທາງດ້ານລຸ່ມນີ້:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"ກຳລັງເລີ່ມການສຳຮອງຂໍ້ມູນ..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"ສຳຮອງຂໍ້ມູນສຳເລັດແລ້ວ"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"ການກູ້ຂໍ້ມູນກຳລັງຈະເລີ່ມ..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"ການກູ້ຂໍ້ມູນສິ້ນສຸດແລ້ວ"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"ໝົດເວລາປະຕິບັດການ"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-mn-rMN/strings.xml b/packages/BackupRestoreConfirmation/res/values-mn-rMN/strings.xml
deleted file mode 100644
index b2738c0..0000000
--- a/packages/BackupRestoreConfirmation/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"Бүрэн нөөшлөх"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"Бүрэн сэргээх"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"Холбогдсон байгаа десктоп компьютерлүү бүх датаг бүрэн нөөшлөх хүсэлт тавигдав. Та энийг зөвшөөрөх үү?\n\nХэрэв та нөөшлөлт хийх хүсэлт хийгээгүй бол энийг зөвшөөрч болохгүй."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"Миний датаг нөөшлөх"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"Нөөшлөхгүй"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"Холбогдсон байгаа десктоп компьютерээс бүх датаг бүрэн сэргээх хүсэлт тавигдав. Та энийг зөвшөөрөх үү?\n\nХэрэв та сэргээх хүсэлт хийгээгүй бол энийг зөвшөөрч болохгүй. Энэ нь төхөөрөмж дээр одоо байгаа дурын датаг орлуулах болно!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"Миний датаг сэргээх"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"Сэргээхгүй"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"Одоогийн нөөшлөх нууц үгийг доор оруулна уу:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"Төхөөрөмж шифрлэх нууц үгийг доор оруулна уу."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"Төхөөрөмж шифрлэх нууц үгийг доор оруулна уу. Энэ нууц үгийг нөөшлөх архивийг шифрлэхэд бас ашиглана."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"Бүрэн дата нөөшлөлтийг шифрлэхэд ашиглах нууц үгийг оруулна уу. Хэрэв та хоосон үлдээвэл таны одоогийн нөөшлөлтийн нууц үг ашиглагдах болно:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"Хэрэв та бүрэн нөөшлөх датаг шифрлэх бол доор нууц үгийг оруулна уу:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"Хэрэв сэргээх дата шифрлэгдсэн бол доор нууц үгийг оруулна уу:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"Нөөшлөж эхлэх..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"Нөөшлөлт дуусав"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"Сэргээлт эхлэж байна..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"Сэргээлт дуусав"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"Ажиллагааны хугацаа хэтрэв"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-ms-rMY/strings.xml b/packages/BackupRestoreConfirmation/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 65a9ede..0000000
--- a/packages/BackupRestoreConfirmation/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"Sandaran penuh"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"Pemulihan penuh"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"Sandaran lengkap bagi semua data ke komputer meja yang bersambung telah diminta. Adakah anda mahu membenarkan ini berlaku?\n\nJika anda tidak meminta sandaran ini sendiri, jangan benarkan operasi diteruskan."</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"Sandarkan data saya"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"Jangan buat sandaran"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"Pemulihan penuh semua data dari komputer meja yang bersambung telah diminta. Adakah anda mahu membenarkan ini berlaku?\n\nJika anda tidak meminta pemulihan ini sendiri, jangan benarkan operasi ini diteruskan. Ini akan menggantikan sebarang data semasa pada peranti!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"Pulihkan data saya"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"Jangan kembalikan"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"Sila masukkan kata laluan sandaran semasa anda di bawah:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"Sila masukkan kata laluan penyulitan peranti anda di bawah."</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"Sila masukkan kata laluan penyulitan peranti anda di bawah. Ini juga akan digunakan untuk menyulitkan arkib sandaran."</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"Sila masukkan kata laluan yang hendak digunakan untuk menyulitkan data sandaran lengkap. Jika dibiarkan kosong, kata laluan sandaran semasa anda akan digunakan:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"Jika anda ingin menyulitkan data sandaran lengkap, masukkan kata laluan di bawah:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"Jika pemulihan data disulitkan, sila masukkan kata laluan di bawah:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"Sandaran bermula..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"Sandaran selesai"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"Pemulihan bermula..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"Pemulihan berakhir"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"Operasi tamat masa"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-zh-rHK/strings.xml b/packages/BackupRestoreConfirmation/res/values-zh-rHK/strings.xml
deleted file mode 100644
index d3bcd6e..0000000
--- a/packages/BackupRestoreConfirmation/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,38 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="backup_confirm_title" msgid="827563724209303345">"完整備份"</string>
-    <string name="restore_confirm_title" msgid="5469365809567486602">"完整還原"</string>
-    <string name="backup_confirm_text" msgid="1878021282758896593">"系統收到將所有資料完整備份到連線桌上電腦的要求,請問您允許進行備份嗎?\n\n如果您本人並未提出備份要求,請勿允許繼續進行這項作業。"</string>
-    <string name="allow_backup_button_label" msgid="4217228747769644068">"備份我的資料"</string>
-    <string name="deny_backup_button_label" msgid="6009119115581097708">"不要備份"</string>
-    <string name="restore_confirm_text" msgid="7499866728030461776">"系統收到從連線的桌上電腦完整還原所有資料的要求,請問您允許進行還原嗎?\n\n如果您本人並未提出還原要求,請勿允許繼續進行這項作業。這項作業將取代裝置上現有的全部資料!"</string>
-    <string name="allow_restore_button_label" msgid="3081286752277127827">"還原我的資料"</string>
-    <string name="deny_restore_button_label" msgid="1724367334453104378">"不要還原"</string>
-    <string name="current_password_text" msgid="8268189555578298067">"在下面輸入您目前的備份密碼:"</string>
-    <string name="device_encryption_restore_text" msgid="1570864916855208992">"請在下面輸入您的裝置加密密碼。"</string>
-    <string name="device_encryption_backup_text" msgid="5866590762672844664">"請在下面輸入您的裝置加密密碼,這也會用來將封存備份加密。"</string>
-    <string name="backup_enc_password_text" msgid="4981585714795233099">"請輸入為完整備份資料加密的專用密碼。如果留空,系統將使用您目前的備份密碼:"</string>
-    <string name="backup_enc_password_optional" msgid="1350137345907579306">"如果您想將完整的備份資料加密,請在下面輸入一組密碼:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"如果還原的資料經過加密處理,請在下面輸入密碼:"</string>
-    <string name="toast_backup_started" msgid="550354281452756121">"正在開始備份..."</string>
-    <string name="toast_backup_ended" msgid="3818080769548726424">"備份完畢"</string>
-    <string name="toast_restore_started" msgid="7881679218971277385">"正在開始還原..."</string>
-    <string name="toast_restore_ended" msgid="1764041639199696132">"還原完畢"</string>
-    <string name="toast_timeout" msgid="5276598587087626877">"操作逾時"</string>
-</resources>
diff --git a/packages/BackupRestoreConfirmation/res/values-zu/strings.xml b/packages/BackupRestoreConfirmation/res/values-zu/strings.xml
index 955b26f..b62b7af 100644
--- a/packages/BackupRestoreConfirmation/res/values-zu/strings.xml
+++ b/packages/BackupRestoreConfirmation/res/values-zu/strings.xml
@@ -29,7 +29,7 @@
     <string name="device_encryption_backup_text" msgid="5866590762672844664">"Uyacelwa ukuba ufake iphasiwedi efakwe kudivayisi yakho ngezansi. lokhu kuzosetshenziswa ukufaka kusilondoloza sokusiza lapho kudingeka."</string>
     <string name="backup_enc_password_text" msgid="4981585714795233099">"Sicela ufake iphasiwedi ezosetshenziselwa ukubhala ngokufihlekileyo imininingo eyesekwe ngokulondoloza. Uma lokhu kushiywe kungabhalwe lutho, kuzosetshenziswa iphasiwedi yokweseka ngokulondoloza yamanje:"</string>
     <string name="backup_enc_password_optional" msgid="1350137345907579306">"Uma ufuna ukufaka ikhowudi kwimininingo yonke eyesekelwe ngokulondoloza faka i-passowrd engezansi:"</string>
-    <string name="restore_enc_password_text" msgid="6140898525580710823">"Uma uhlelo lokusebenza yokubuyiselwa esimweni kwmininingo ibhalwe ngokufihlekileyo, sicela ufake iphasiwedi engezansi:"</string>
+    <string name="restore_enc_password_text" msgid="6140898525580710823">"Uma insiza yokubuyiselwa esimweni kwmininingo ibhalwe ngokufihlekileyo, sicela ufake iphasiwedi engezansi:"</string>
     <string name="toast_backup_started" msgid="550354281452756121">"Ukulondoloza kuyaqala..."</string>
     <string name="toast_backup_ended" msgid="3818080769548726424">"Ukulondoloza kuphelile"</string>
     <string name="toast_restore_started" msgid="7881679218971277385">"Ukubuyisa kuyaqala..."</string>
diff --git a/packages/DefaultContainerService/res/values-en-rIN/strings.xml b/packages/DefaultContainerService/res/values-en-rIN/strings.xml
deleted file mode 100644
index 216d715..0000000
--- a/packages/DefaultContainerService/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Package Access Helper"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-et-rEE/strings.xml b/packages/DefaultContainerService/res/values-et-rEE/strings.xml
deleted file mode 100644
index 216d715..0000000
--- a/packages/DefaultContainerService/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Package Access Helper"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-fr-rCA/strings.xml b/packages/DefaultContainerService/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 69c4e99..0000000
--- a/packages/DefaultContainerService/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Aide accès au paquet"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-hy-rAM/strings.xml b/packages/DefaultContainerService/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 1e2f587..0000000
--- a/packages/DefaultContainerService/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Փաթեթի մուտքի օժանդակող"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-ka-rGE/strings.xml b/packages/DefaultContainerService/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 216d715..0000000
--- a/packages/DefaultContainerService/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Package Access Helper"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-km-rKH/strings.xml b/packages/DefaultContainerService/res/values-km-rKH/strings.xml
deleted file mode 100644
index 1006d56..0000000
--- a/packages/DefaultContainerService/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"កម្មវិធី​ជំនួយ​ចូល​ដំណើរការ​កញ្ចប់"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-lo-rLA/strings.xml b/packages/DefaultContainerService/res/values-lo-rLA/strings.xml
deleted file mode 100644
index 216d715..0000000
--- a/packages/DefaultContainerService/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Package Access Helper"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-mn-rMN/strings.xml b/packages/DefaultContainerService/res/values-mn-rMN/strings.xml
deleted file mode 100644
index d9fe647..0000000
--- a/packages/DefaultContainerService/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Багц хандалтын тусламж"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-ms-rMY/strings.xml b/packages/DefaultContainerService/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 77d7927..0000000
--- a/packages/DefaultContainerService/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"Pembantu Akses Pakej"</string>
-</resources>
diff --git a/packages/DefaultContainerService/res/values-zh-rHK/strings.xml b/packages/DefaultContainerService/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 9a43509..0000000
--- a/packages/DefaultContainerService/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/*
-**
-** Copyright 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.
-*/
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="service_name" msgid="4841491635055379553">"套件存取輔助程式"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-af/strings.xml b/packages/DocumentsUI/res/values-af/strings.xml
deleted file mode 100644
index 41fd63a..0000000
--- a/packages/DocumentsUI/res/values-af/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumente"</string>
-    <string name="title_open" msgid="4353228937663917801">"Maak oop vanaf"</string>
-    <string name="title_save" msgid="2433679664882857999">"Stoor na"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Skep vouer"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Roosteraansig"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Lysaansig"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sorteer volgens"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Soek"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Instellings"</string>
-    <string name="menu_open" msgid="432922957274920903">"Maak oop"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Stoor"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Deel"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Vee uit"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> gekies"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Volgens naam"</string>
-    <string name="sort_date" msgid="586080032956151448">"Volgens datum gewysig"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Volgens grootte"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Wys wortels"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Versteek wortels"</string>
-    <string name="save_error" msgid="6167009778003223664">"Kon nie dokument stoor nie"</string>
-    <string name="create_error" msgid="3735649141335444215">"Kon nie vouer skep nie"</string>
-    <string name="query_error" msgid="1222448261663503501">"Kon nie navraag doen oor dokumente nie"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Onlangs"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> gratis"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Bergingdienste"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Kortpaaie"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Toestelle"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Nog programme"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Wys gevorderde toestelle"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Wys lêergrootte"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Wys toestelgrootte"</string>
-    <string name="empty" msgid="7858882803708117596">"Geen items nie"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Kan lêer nie oopmaak nie"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Kan sommige dokumente nie uitvee nie"</string>
-    <string name="share_via" msgid="8966594246261344259">"Deel via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-am/strings.xml b/packages/DocumentsUI/res/values-am/strings.xml
deleted file mode 100644
index c77a8ee..0000000
--- a/packages/DocumentsUI/res/values-am/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"ሰነዶች"</string>
-    <string name="title_open" msgid="4353228937663917801">"ክፈት ከ"</string>
-    <string name="title_save" msgid="2433679664882857999">"አስቀምጥ ወደ"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"አቃፊ ፍጠር"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"የፍርግርግ እይታ"</string>
-    <string name="menu_list" msgid="7279285939892417279">"የዝርዝር እይታ"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"ደርድር በ"</string>
-    <string name="menu_search" msgid="3816712084502856974">"ፈልግ"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"ቅንብሮች"</string>
-    <string name="menu_open" msgid="432922957274920903">"ክፈት"</string>
-    <string name="menu_save" msgid="2394743337684426338">"አስቀምጥ"</string>
-    <string name="menu_share" msgid="3075149983979628146">"አጋራ"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"ሰርዝ"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> ተመርጠዋል"</string>
-    <string name="sort_name" msgid="9183560467917256779">"በስም"</string>
-    <string name="sort_date" msgid="586080032956151448">"በተለወጠበት ቀን"</string>
-    <string name="sort_size" msgid="3350681319735474741">"በመጠን"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"ስሮችን አሳይ"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"ስሮችን ደብቅ"</string>
-    <string name="save_error" msgid="6167009778003223664">"ሰነድ ማስቀመጥ አልተሳካም"</string>
-    <string name="create_error" msgid="3735649141335444215">"አቃፊ መፍጠር አልተሳካም"</string>
-    <string name="query_error" msgid="1222448261663503501">"ለሰነዶች መጠይቅ መስራት አልተሳካም"</string>
-    <string name="root_recent" msgid="4470053704320518133">"የቅርብ ጊዜ"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ነፃ"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"የማከማቻ አገልግሎቶች"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"አቋራጮች"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"መሣሪያዎች"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"ተጨማሪ መተግበሪያዎች"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"የላቁ መሳሪያዎችን አሳይ"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"የፋይል መጠን አሳይ"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"የመሳሪያ መጠን አሳይ"</string>
-    <string name="empty" msgid="7858882803708117596">"ምንም ንጥሎች የሉም"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"ፋይል መክፈት አይቻልም"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"አንዳንድ ሰነዶችን መሰረዝ አልተቻለም"</string>
-    <string name="share_via" msgid="8966594246261344259">"በሚከተለው በኩል ያጋሩ"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ar/strings.xml b/packages/DocumentsUI/res/values-ar/strings.xml
deleted file mode 100644
index c59c0ee..0000000
--- a/packages/DocumentsUI/res/values-ar/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"مستندات"</string>
-    <string name="title_open" msgid="4353228937663917801">"فتح من"</string>
-    <string name="title_save" msgid="2433679664882857999">"حفظ في"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"إنشاء مجلد"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"عرض الشبكة"</string>
-    <string name="menu_list" msgid="7279285939892417279">"عرض القائمة"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"ترتيب بحسب"</string>
-    <string name="menu_search" msgid="3816712084502856974">"بحث"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"الإعدادات"</string>
-    <string name="menu_open" msgid="432922957274920903">"فتح"</string>
-    <string name="menu_save" msgid="2394743337684426338">"حفظ"</string>
-    <string name="menu_share" msgid="3075149983979628146">"مشاركة"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"حذف"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"تم تحديد <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"بحسب الاسم"</string>
-    <string name="sort_date" msgid="586080032956151448">"بحسب تاريخ التعديل"</string>
-    <string name="sort_size" msgid="3350681319735474741">"بحسب الحجم"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"عرض الجذور"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"إخفاء الجذور"</string>
-    <string name="save_error" msgid="6167009778003223664">"أخفق حفظ المستند"</string>
-    <string name="create_error" msgid="3735649141335444215">"أخفق إنشاء المجلد"</string>
-    <string name="query_error" msgid="1222448261663503501">"أخفق إرسال طلب بحث عن المستندات"</string>
-    <string name="root_recent" msgid="4470053704320518133">"الأخيرة"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> خالية"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"خدمات التخزين"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"اختصارات"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"أجهزة"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"المزيد من التطبيقات"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"عرض الأجهزة المتقدمة"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"عرض حجم الملف"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"عرض حجم الجهاز"</string>
-    <string name="empty" msgid="7858882803708117596">"ليس هناك أي عناصر"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"لا يمكن فتح الملف"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"تعذر حذف بعض المستندات"</string>
-    <string name="share_via" msgid="8966594246261344259">"مشاركة عبر"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-az-rAZ/strings.xml b/packages/DocumentsUI/res/values-az-rAZ/strings.xml
deleted file mode 100644
index 1374982..0000000
--- a/packages/DocumentsUI/res/values-az-rAZ/strings.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Sənədlər"</string>
-    <string name="title_open" msgid="4353228937663917801">"Vasitəsilə açın"</string>
-    <string name="title_save" msgid="2433679664882857999">"buraya saxlayın"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Qovluq yaradın"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Torlu görünüş"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Siyahı görünüşü"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Bunlardan biri üzrə sırala"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Axtarış"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Ayarlar"</string>
-    <string name="menu_open" msgid="432922957274920903">"Açın"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Yadda saxlayın"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Paylaşın"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Sil"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> seçilmiş"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Ad üzrə"</string>
-    <string name="sort_date" msgid="586080032956151448">"Tarix üzrə dəyişmiş"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Ölçü üzrə"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Kökləri göstərin"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Kökləri gizlədin"</string>
-    <string name="save_error" msgid="6167009778003223664">"Sənədi yadda saxlaya bilmədi"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Son"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ödənişsiz"</string>
-    <!-- no translation found for root_type_service (2178854894416775409) -->
-    <skip />
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Qısa yollar"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Cihazlar"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Daha çox tətbiq"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Qabaqcıl cihazları görüntüləyin"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Fayl ölçüsünü görüntüləyin"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Cihaz ölçüsünü görüntüləyin"</string>
-    <string name="empty" msgid="7858882803708117596">"Element yoxdur"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Faylı aça bilmir"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Bəzi sənədləri silə bilmir"</string>
-    <string name="share_via" msgid="8966594246261344259">"Bunun vasitəsilə paylaş:"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-az/strings.xml b/packages/DocumentsUI/res/values-az/strings.xml
deleted file mode 100644
index 806118b..0000000
--- a/packages/DocumentsUI/res/values-az/strings.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Sənədlər"</string>
-    <string name="title_open" msgid="4353228937663917801">"Vasitəsilə açın"</string>
-    <string name="title_save" msgid="2433679664882857999">"buraya saxlayın"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Qovluq yaradın"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Torlu görünüş"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Siyahı görünüşü"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Bunlardan biri üzrə sırala"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Axtarış"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Ayarlar"</string>
-    <string name="menu_open" msgid="432922957274920903">"Açın"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Yadda saxlayın"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Paylaşın"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Sil"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> seçilmiş"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Ad üzrə"</string>
-    <string name="sort_date" msgid="586080032956151448">"Tarix üzrə dəyişmiş"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Ölçü üzrə"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Kökləri göstərin"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Kökləri gizlədin"</string>
-    <string name="save_error" msgid="6167009778003223664">"Sənədi yadda saxlaya bilmədi"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Son"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ödənişsiz"</string>
-    <string name="root_type_service" msgid="2857362700576006694">"Xidmətlər"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Qısa yollar"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Cihazlar"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Daha çox tətbiq"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Qabaqcıl cihazları görüntüləyin"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Fayl ölçüsünü görüntüləyin"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Cihaz ölçüsünü görüntüləyin"</string>
-    <string name="empty" msgid="7858882803708117596">"Element yoxdur"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Faylı aça bilmir"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Bəzi sənədləri silə bilmir"</string>
-    <string name="more" msgid="7117420986529297171">"Daha çox"</string>
-    <string name="loading" msgid="7933681260296021180">"Yüklənir…"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-bg/strings.xml b/packages/DocumentsUI/res/values-bg/strings.xml
deleted file mode 100644
index c3242b2..0000000
--- a/packages/DocumentsUI/res/values-bg/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Документи"</string>
-    <string name="title_open" msgid="4353228937663917801">"Отваряне от"</string>
-    <string name="title_save" msgid="2433679664882857999">"Запазване в/ъв"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Създаване на папка"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Изглед в мрежа"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Списъчен изглед"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Сортиране по"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Търсене"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Настройки"</string>
-    <string name="menu_open" msgid="432922957274920903">"Отваряне"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Запазване"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Споделяне"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Изтриване"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Избрахте <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"По име"</string>
-    <string name="sort_date" msgid="586080032956151448">"По дата на промяната"</string>
-    <string name="sort_size" msgid="3350681319735474741">"По размер"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Показване на основните елементи"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Скриване на основните елементи"</string>
-    <string name="save_error" msgid="6167009778003223664">"Запазването на документа не бе успешно"</string>
-    <string name="create_error" msgid="3735649141335444215">"Създаването на папката не бе успешно"</string>
-    <string name="query_error" msgid="1222448261663503501">"Заявката за документи не бе успешна"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Скорошно"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Свободно: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Услуги за съхранение"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Преки пътища"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Устройства"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Още приложения"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Устройства с разширени ф-ии"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Показване на файловия размер"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Показване на размера на устройството"</string>
-    <string name="empty" msgid="7858882803708117596">"Няма елементи"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Файлът не може да се отвори"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Някои документи не могат да бъдат изтрити"</string>
-    <string name="share_via" msgid="8966594246261344259">"Споделяне чрез"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ca/strings.xml b/packages/DocumentsUI/res/values-ca/strings.xml
deleted file mode 100644
index 68c7b0e..0000000
--- a/packages/DocumentsUI/res/values-ca/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documents"</string>
-    <string name="title_open" msgid="4353228937663917801">"Obre des de"</string>
-    <string name="title_save" msgid="2433679664882857999">"Desa a"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Crea una carpeta"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Visualització de quadrícula"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Visualització de llista"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Ordena per"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Cerca"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Configuració"</string>
-    <string name="menu_open" msgid="432922957274920903">"Obre"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Desa"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Comparteix"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Suprimeix"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Seleccionats: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Per nom"</string>
-    <string name="sort_date" msgid="586080032956151448">"Per data de modificació"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Per mida"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Mostra les arrels"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Amaga les arrels"</string>
-    <string name="save_error" msgid="6167009778003223664">"No s\'ha pogut desar el document."</string>
-    <string name="create_error" msgid="3735649141335444215">"No s\'ha pogut crear la carpeta"</string>
-    <string name="query_error" msgid="1222448261663503501">"No s\'han pogut consultar els documents"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recent"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> lliures"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Serveis d\'emmagatzematge"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Dreceres"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispositius"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Més aplicacions"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Mostra els dispositius avançats"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Mostra la mida del fitxer"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Mostra la mida del dispositiu"</string>
-    <string name="empty" msgid="7858882803708117596">"Sense elements"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"No es pot obrir el fitxer."</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"No es poden suprimir alguns documents."</string>
-    <string name="share_via" msgid="8966594246261344259">"Comparteix mitjançant"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-cs/strings.xml b/packages/DocumentsUI/res/values-cs/strings.xml
deleted file mode 100644
index f089c8b..0000000
--- a/packages/DocumentsUI/res/values-cs/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenty"</string>
-    <string name="title_open" msgid="4353228937663917801">"Otevřít z"</string>
-    <string name="title_save" msgid="2433679664882857999">"Uložit do"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Vytvořit složku"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Mřížka"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Seznam"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Řadit podle"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Hledat"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Nastavení"</string>
-    <string name="menu_open" msgid="432922957274920903">"Otevřít"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Uložit"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Sdílet"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Smazat"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Vybráno: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Podle názvu"</string>
-    <string name="sort_date" msgid="586080032956151448">"Podle data úpravy"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Podle velikosti"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Zobrazit kořeny"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Skrýt kořeny"</string>
-    <string name="save_error" msgid="6167009778003223664">"Uložení dokumentu se nezdařilo"</string>
-    <string name="create_error" msgid="3735649141335444215">"Složku se nepodařilo vytvořit"</string>
-    <string name="query_error" msgid="1222448261663503501">"Seznam dokumentů se nepodařilo načíst"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Poslední"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Volný prostor: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Služby úložiště"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Klávesové zkratky"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Zařízení"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Další aplikace"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Zobrazit pokročilá zařízení"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Zobrazit velikost souboru"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Zobrazit velikost zařízení"</string>
-    <string name="empty" msgid="7858882803708117596">"Žádné položky"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Soubor nelze otevřít"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Některé dokumenty nelze smazat"</string>
-    <string name="share_via" msgid="8966594246261344259">"Sdílet pomocí"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-da/strings.xml b/packages/DocumentsUI/res/values-da/strings.xml
deleted file mode 100644
index 816f9a7..0000000
--- a/packages/DocumentsUI/res/values-da/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenter"</string>
-    <string name="title_open" msgid="4353228937663917801">"Åbn fra"</string>
-    <string name="title_save" msgid="2433679664882857999">"Gem på"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Opret mappe"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Gittervisning"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Listevisning"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortér efter"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Søg"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Indstillinger"</string>
-    <string name="menu_open" msgid="432922957274920903">"Åbn"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Gem"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Del"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Slet"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> er valgt"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Efter navn"</string>
-    <string name="sort_date" msgid="586080032956151448">"Efter ændringsdato"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Efter størrelse"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Vis rødder"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Skjul rødder"</string>
-    <string name="save_error" msgid="6167009778003223664">"Dokumentet kunne ikke gemmes"</string>
-    <string name="create_error" msgid="3735649141335444215">"Mappen kunne ikke oprettes"</string>
-    <string name="query_error" msgid="1222448261663503501">"Dokumenterne kunne ikke forespørges."</string>
-    <string name="root_recent" msgid="4470053704320518133">"Seneste"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ledig plads"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Lagringstjenester"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Genveje"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Enheder"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Flere apps"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Vis avancerede enheder"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Vis filstørrelse"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Vis enhedens størrelse"</string>
-    <string name="empty" msgid="7858882803708117596">"Ingen elementer"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Filen kan ikke åbnes"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Nogle dokumenter kan ikke slettes"</string>
-    <string name="share_via" msgid="8966594246261344259">"Del via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-de/strings.xml b/packages/DocumentsUI/res/values-de/strings.xml
deleted file mode 100644
index 3b448d9..0000000
--- a/packages/DocumentsUI/res/values-de/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumente"</string>
-    <string name="title_open" msgid="4353228937663917801">"Öffnen von"</string>
-    <string name="title_save" msgid="2433679664882857999">"Speichern unter"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Ordner erstellen"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Rasteransicht"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Listenansicht"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortieren nach"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Suchen"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Einstellungen"</string>
-    <string name="menu_open" msgid="432922957274920903">"Öffnen"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Speichern"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Teilen"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Löschen"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> ausgewählt"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Nach Name"</string>
-    <string name="sort_date" msgid="586080032956151448">"Nach Änderungsdatum"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Nach Größe"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Root-Verzeichnis anzeigen"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Root-Verzeichnis ausblenden"</string>
-    <string name="save_error" msgid="6167009778003223664">"Dokument konnte nicht gespeichert werden."</string>
-    <string name="create_error" msgid="3735649141335444215">"Ordner konnte nicht erstellt werden."</string>
-    <string name="query_error" msgid="1222448261663503501">"Fehler bei der Anforderung von Dokumenten"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Letzte"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> verfügbar"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Speicherdienste"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Verknüpfungen"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Geräte"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Weitere Apps"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Erweiterte Geräte anzeigen"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Dateigröße anzeigen"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Geräteabmessungen anzeigen"</string>
-    <string name="empty" msgid="7858882803708117596">"Keine Elemente"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Datei kann nicht geöffnet werden."</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Einige Dokumente konnten nicht gelöscht werden."</string>
-    <string name="share_via" msgid="8966594246261344259">"Teilen über"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-el/strings.xml b/packages/DocumentsUI/res/values-el/strings.xml
deleted file mode 100644
index aec3318..0000000
--- a/packages/DocumentsUI/res/values-el/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Έγγραφα"</string>
-    <string name="title_open" msgid="4353228937663917801">"Άνοιγμα από"</string>
-    <string name="title_save" msgid="2433679664882857999">"Αποθήκευση σε"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Δημιουργία φακέλου"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Προβολή πλέγματος"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Προβολή λίστας"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Ταξινόμηση κατά"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Αναζήτηση"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Ρυθμίσεις"</string>
-    <string name="menu_open" msgid="432922957274920903">"Άνοιγμα"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Αποθήκευση"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Κοινή χρήση"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Διαγραφή"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Επιλέχθηκαν <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Κατά όνομα"</string>
-    <string name="sort_date" msgid="586080032956151448">"Κατά ημερομηνία τροποποίησης"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Κατά μέγεθος"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Εμφάνιση ρίζας"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Απόκρυψη ρίζας"</string>
-    <string name="save_error" msgid="6167009778003223664">"Αποτυχία αποθήκευσης του εγγράφου"</string>
-    <string name="create_error" msgid="3735649141335444215">"Αποτυχία δημιουργίας φακέλου"</string>
-    <string name="query_error" msgid="1222448261663503501">"Αποτυχία υποβολής  ερωτήματος για έγγραφα"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Πρόσφατα"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ελεύθερα"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Υπηρεσίες αποθήκευσης"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Συντομεύσεις"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Συσκευές"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Περισσότερες εφαρμογές"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Εμφάνιση προηγμένων συσκευών"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Εμφάνιση μεγέθους αρχείου"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Εμφάνιση μεγέθους συσκευής"</string>
-    <string name="empty" msgid="7858882803708117596">"Δεν υπάρχουν στοιχεία"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Δεν είναι δυνατό το άνοιγμα του αρχείου"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Δεν είναι δυνατή η διαγραφή ορισμένων εγγράφων"</string>
-    <string name="share_via" msgid="8966594246261344259">"Κοινή χρήση μέσω"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-en-rGB/strings.xml b/packages/DocumentsUI/res/values-en-rGB/strings.xml
deleted file mode 100644
index a95e7f1..0000000
--- a/packages/DocumentsUI/res/values-en-rGB/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documents"</string>
-    <string name="title_open" msgid="4353228937663917801">"Open from"</string>
-    <string name="title_save" msgid="2433679664882857999">"Save to"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Create folder"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Grid view"</string>
-    <string name="menu_list" msgid="7279285939892417279">"List view"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sort by"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Search"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Settings"</string>
-    <string name="menu_open" msgid="432922957274920903">"Open"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Save"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Share"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Delete"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> selected"</string>
-    <string name="sort_name" msgid="9183560467917256779">"By name"</string>
-    <string name="sort_date" msgid="586080032956151448">"By date modified"</string>
-    <string name="sort_size" msgid="3350681319735474741">"By size"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Show roots"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Hide roots"</string>
-    <string name="save_error" msgid="6167009778003223664">"Failed to save document"</string>
-    <string name="create_error" msgid="3735649141335444215">"Failed to create folder"</string>
-    <string name="query_error" msgid="1222448261663503501">"Failed to query documents"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recent"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> free"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Storage services"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Shortcuts"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Devices"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"More apps"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Display advanced devices"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Display file size"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Display device size"</string>
-    <string name="empty" msgid="7858882803708117596">"No items"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Cannot open file"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Unable to delete some documents"</string>
-    <string name="share_via" msgid="8966594246261344259">"Share via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-en-rIN/strings.xml b/packages/DocumentsUI/res/values-en-rIN/strings.xml
deleted file mode 100644
index a95e7f1..0000000
--- a/packages/DocumentsUI/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documents"</string>
-    <string name="title_open" msgid="4353228937663917801">"Open from"</string>
-    <string name="title_save" msgid="2433679664882857999">"Save to"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Create folder"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Grid view"</string>
-    <string name="menu_list" msgid="7279285939892417279">"List view"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sort by"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Search"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Settings"</string>
-    <string name="menu_open" msgid="432922957274920903">"Open"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Save"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Share"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Delete"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> selected"</string>
-    <string name="sort_name" msgid="9183560467917256779">"By name"</string>
-    <string name="sort_date" msgid="586080032956151448">"By date modified"</string>
-    <string name="sort_size" msgid="3350681319735474741">"By size"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Show roots"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Hide roots"</string>
-    <string name="save_error" msgid="6167009778003223664">"Failed to save document"</string>
-    <string name="create_error" msgid="3735649141335444215">"Failed to create folder"</string>
-    <string name="query_error" msgid="1222448261663503501">"Failed to query documents"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recent"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> free"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Storage services"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Shortcuts"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Devices"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"More apps"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Display advanced devices"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Display file size"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Display device size"</string>
-    <string name="empty" msgid="7858882803708117596">"No items"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Cannot open file"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Unable to delete some documents"</string>
-    <string name="share_via" msgid="8966594246261344259">"Share via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-es-rUS/strings.xml b/packages/DocumentsUI/res/values-es-rUS/strings.xml
deleted file mode 100644
index 4a3ff33..0000000
--- a/packages/DocumentsUI/res/values-es-rUS/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documentos"</string>
-    <string name="title_open" msgid="4353228937663917801">"Abrir desde"</string>
-    <string name="title_save" msgid="2433679664882857999">"Guardar en"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Crear carpeta"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Vista de cuadrícula"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Vista de lista"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Ordenar por"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Buscar"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Configuración"</string>
-    <string name="menu_open" msgid="432922957274920903">"Abrir"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Guardar"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Compartir"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Eliminar"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> seleccionado(s)"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Por nombre"</string>
-    <string name="sort_date" msgid="586080032956151448">"Por fecha de modificación"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Por tamaño"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Mostrar raíces"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ocultar raíces"</string>
-    <string name="save_error" msgid="6167009778003223664">"Error al guardar el documento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Error al crear la carpeta"</string>
-    <string name="query_error" msgid="1222448261663503501">"Error al consultar documentos"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recientes"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> de espacio libre"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Almacenamiento"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Accesos directos"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispositivos"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Más aplicaciones"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Mostrar dispositivos avanzados"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Mostrar tamaño del archivo"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Mostrar tamaño del dispositivo"</string>
-    <string name="empty" msgid="7858882803708117596">"Sin elementos"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"No se puede abrir el archivo."</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"No es posible eliminar algunos documentos."</string>
-    <string name="share_via" msgid="8966594246261344259">"Compartir mediante"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-es/strings.xml b/packages/DocumentsUI/res/values-es/strings.xml
deleted file mode 100644
index 1682542..0000000
--- a/packages/DocumentsUI/res/values-es/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documentos"</string>
-    <string name="title_open" msgid="4353228937663917801">"Abrir desde"</string>
-    <string name="title_save" msgid="2433679664882857999">"Guardar en"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Crear carpeta"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Vista de cuadrícula"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Vista de lista"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Ordenar por"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Buscar"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Ajustes"</string>
-    <string name="menu_open" msgid="432922957274920903">"Abrir"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Guardar"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Compartir"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Eliminar"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Seleccionado: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Por nombre"</string>
-    <string name="sort_date" msgid="586080032956151448">"Por fecha de modificación"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Por tamaño"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Mostrar raíces"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ocultar raíces"</string>
-    <string name="save_error" msgid="6167009778003223664">"Error al guardar documento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Error al crear la carpeta"</string>
-    <string name="query_error" msgid="1222448261663503501">"Error al consultar lista de documentos"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Reciente"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> de espacio libre"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Servicios almacenamiento"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Accesos directos"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispositivos"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Más aplicaciones"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Mostrar dispositivos avanzados"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Mostrar tamaño del archivo"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Mostrar tamaño del dispositivo"</string>
-    <string name="empty" msgid="7858882803708117596">"Sin elementos"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Error al abrir el archivo"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"No es posible eliminar algunos documentos"</string>
-    <string name="share_via" msgid="8966594246261344259">"Compartir a través de"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-et-rEE/strings.xml b/packages/DocumentsUI/res/values-et-rEE/strings.xml
deleted file mode 100644
index 5412956..0000000
--- a/packages/DocumentsUI/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumendid"</string>
-    <string name="title_open" msgid="4353228937663917801">"Ava:"</string>
-    <string name="title_save" msgid="2433679664882857999">"Salvesta:"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Loo kaust"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Ruudustikkuva"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Loendikuva"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortimisalus:"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Otsing"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Seaded"</string>
-    <string name="menu_open" msgid="432922957274920903">"Ava"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Salvesta"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Jaga"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Kustuta"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> on valitud"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Nime järgi"</string>
-    <string name="sort_date" msgid="586080032956151448">"Muutmiskuupäeva järgi"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Suuruse järgi"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Kuva juured"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Peida juured"</string>
-    <string name="save_error" msgid="6167009778003223664">"Dokumendi salvestamine ebaõnnestus"</string>
-    <string name="create_error" msgid="3735649141335444215">"Kausta loomine ebaõnnestus"</string>
-    <string name="query_error" msgid="1222448261663503501">"Dokumentide päring ebaõnnestus"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Hiljutised"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> on vaba"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Mäluruumi teenused"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Otseteed"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Seadmed"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Rohkem rakendusi"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Kuva tippseadmed"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Kuva faili suurus"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Kuva seadme suurus"</string>
-    <string name="empty" msgid="7858882803708117596">"Üksusi ei ole"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Faili ei saa avada"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Mõnda dokumenti ei õnnestu kustutada"</string>
-    <string name="share_via" msgid="8966594246261344259">"Jagage teenusega"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-fa/strings.xml b/packages/DocumentsUI/res/values-fa/strings.xml
deleted file mode 100644
index c922b37..0000000
--- a/packages/DocumentsUI/res/values-fa/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"اسناد"</string>
-    <string name="title_open" msgid="4353228937663917801">"باز کردن از"</string>
-    <string name="title_save" msgid="2433679664882857999">"ذخیره در"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"ایجاد پوشه"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"نمای جدولی"</string>
-    <string name="menu_list" msgid="7279285939892417279">"نمای فهرست‌وار"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"مرتب‌سازی بر اساس"</string>
-    <string name="menu_search" msgid="3816712084502856974">"جستجو"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"تنظیمات"</string>
-    <string name="menu_open" msgid="432922957274920903">"باز کردن"</string>
-    <string name="menu_save" msgid="2394743337684426338">"ذخیره"</string>
-    <string name="menu_share" msgid="3075149983979628146">"اشتراک‌گذاری"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"حذف"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> انتخاب شد"</string>
-    <string name="sort_name" msgid="9183560467917256779">"بر اساس نام"</string>
-    <string name="sort_date" msgid="586080032956151448">"بر اساس تاریخ اصلاح"</string>
-    <string name="sort_size" msgid="3350681319735474741">"بر اساس اندازه"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"نمایش ریشه‌ها"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"پنهان کردن ریشه‌ها"</string>
-    <string name="save_error" msgid="6167009778003223664">"ذخیره سند انجام نشد"</string>
-    <string name="create_error" msgid="3735649141335444215">"ایجاد پوشه انجام نشد"</string>
-    <string name="query_error" msgid="1222448261663503501">"جستجوی اسناد ناموفق بود"</string>
-    <string name="root_recent" msgid="4470053704320518133">"اخیر"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> آزاد"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"خدمات ذخیره‌سازی"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"میانبرها"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"دستگاه‌ها"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"برنامه‌های بیشتر"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"نمایش دستگاه‌های پیشرفته"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"نمایش اندازه فایل"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"نمایش اندازه صفحه نمایش"</string>
-    <string name="empty" msgid="7858882803708117596">"موردی موجود نیست"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"فایل باز نمی‌شود"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"برخی از اسناد حذف نمی‌شوند"</string>
-    <string name="share_via" msgid="8966594246261344259">"اشتراک‌گذاری از طریق"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-fi/strings.xml b/packages/DocumentsUI/res/values-fi/strings.xml
deleted file mode 100644
index 5e40ecd..0000000
--- a/packages/DocumentsUI/res/values-fi/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Asiakirjat"</string>
-    <string name="title_open" msgid="4353228937663917801">"Avoinna alkaen"</string>
-    <string name="title_save" msgid="2433679664882857999">"Tallenna kohteeseen"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Luo kansio"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Ruudukkonäkymä"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Luettelonäkymä"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Lajitteluperuste"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Haku"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Asetukset"</string>
-    <string name="menu_open" msgid="432922957274920903">"Avaa"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Tallenna"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Jaa"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Poista"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> valittua"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Nimen mukaan"</string>
-    <string name="sort_date" msgid="586080032956151448">"Muokkauspäivän mukaan"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Koon mukaan"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Näytä juuret"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Piilota juuret"</string>
-    <string name="save_error" msgid="6167009778003223664">"Asiakirjan tallennus epäonnistui"</string>
-    <string name="create_error" msgid="3735649141335444215">"Kansion luominen epäonnistui"</string>
-    <string name="query_error" msgid="1222448261663503501">"Dokumenttikysely epäonnistui"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Viimeisimmät"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> vapaana"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Tallennuspalvelut"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Pikakuvakkeet"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Laitteet"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Lisää sovelluksia"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Näytä kehittyneet laitteet"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Näytä tiedoston koko"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Näytä laitteen koko"</string>
-    <string name="empty" msgid="7858882803708117596">"Ei kohteita"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Tiedostoa ei voi avata"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Joitakin asiakirjoja ei voi poistaa"</string>
-    <string name="share_via" msgid="8966594246261344259">"Jaa sovelluksessa"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-fr-rCA/strings.xml b/packages/DocumentsUI/res/values-fr-rCA/strings.xml
deleted file mode 100644
index a837379..0000000
--- a/packages/DocumentsUI/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documents"</string>
-    <string name="title_open" msgid="4353228937663917801">"Ouvert à partir de"</string>
-    <string name="title_save" msgid="2433679664882857999">"Enregistrer dans"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Créer un dossier"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Grille"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Liste"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Trier par"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Rechercher"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Paramètres"</string>
-    <string name="menu_open" msgid="432922957274920903">"Ouvrir"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Enregistrer"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Partager"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Supprimer"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> sélectionné(s)"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Par nom"</string>
-    <string name="sort_date" msgid="586080032956151448">"Par date de modification"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Par taille"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Afficher les racines"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Masquer les racines"</string>
-    <string name="save_error" msgid="6167009778003223664">"Échec de l\'enregistrement du document"</string>
-    <string name="create_error" msgid="3735649141335444215">"Échec de la création du dossier"</string>
-    <string name="query_error" msgid="1222448261663503501">"Échec de la demande de document"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Récents"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> disponible"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Services de stockage"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Raccourcis"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Appareils"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Plus d\'applications"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Afficher les appareils avancés"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Afficher la taille du fichier"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Taille de l\'écran de l\'appareil"</string>
-    <string name="empty" msgid="7858882803708117596">"Aucun élément"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Impossible d\'ouvrir le fichier"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Impossible de supprimer certains documents"</string>
-    <string name="share_via" msgid="8966594246261344259">"Partager par"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-fr/strings.xml b/packages/DocumentsUI/res/values-fr/strings.xml
deleted file mode 100644
index ff9aeda..0000000
--- a/packages/DocumentsUI/res/values-fr/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documents"</string>
-    <string name="title_open" msgid="4353228937663917801">"Ouvrir à partir de"</string>
-    <string name="title_save" msgid="2433679664882857999">"Enregistrer sous"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Créer un dossier"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Grille"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Liste"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Trier par"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Rechercher"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Paramètres"</string>
-    <string name="menu_open" msgid="432922957274920903">"Ouvrir"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Enregistrer"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Partager"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Supprimer"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> élément(s) sélectionné(s)"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Par nom"</string>
-    <string name="sort_date" msgid="586080032956151448">"Par date de modification"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Par taille"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Afficher les répertoires racines"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Masquer les répertoires racines"</string>
-    <string name="save_error" msgid="6167009778003223664">"Échec de l\'enregistrement du document."</string>
-    <string name="create_error" msgid="3735649141335444215">"Échec de la création du dossier."</string>
-    <string name="query_error" msgid="1222448261663503501">"Échec de la demande de documents."</string>
-    <string name="root_recent" msgid="4470053704320518133">"Récents"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Espace disponible : <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Services de stockage"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Raccourcis"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Appareils"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Autres applications"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Afficher les appareils avancés"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Afficher la taille des fichiers"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Afficher la capacité de stockage des appareils"</string>
-    <string name="empty" msgid="7858882803708117596">"Aucun élément"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Impossible d\'ouvrir le fichier."</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Impossible de supprimer certains documents."</string>
-    <string name="share_via" msgid="8966594246261344259">"Partager via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-hi/strings.xml b/packages/DocumentsUI/res/values-hi/strings.xml
deleted file mode 100644
index 4ce02db..0000000
--- a/packages/DocumentsUI/res/values-hi/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"दस्तावेज़"</string>
-    <string name="title_open" msgid="4353228937663917801">"यहां से खोलें"</string>
-    <string name="title_save" msgid="2433679664882857999">"यहां सहेजें"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"फ़ोल्डर बनाएं"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"ग्रिड दृश्य"</string>
-    <string name="menu_list" msgid="7279285939892417279">"सूची दृश्य"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"इससे क्रमित करें"</string>
-    <string name="menu_search" msgid="3816712084502856974">"खोजें"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"सेटिंग"</string>
-    <string name="menu_open" msgid="432922957274920903">"खोलें"</string>
-    <string name="menu_save" msgid="2394743337684426338">"सहेजें"</string>
-    <string name="menu_share" msgid="3075149983979628146">"साझा करें"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"हटाएं"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> चयनित"</string>
-    <string name="sort_name" msgid="9183560467917256779">"नाम के अनुसार"</string>
-    <string name="sort_date" msgid="586080032956151448">"बदलाव के दिनांक के अनुसार"</string>
-    <string name="sort_size" msgid="3350681319735474741">"आकार के अनुसार"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"रूट दिखाएं"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"रूट छिपाएं"</string>
-    <string name="save_error" msgid="6167009778003223664">"दस्तावेज़ सहेजने में विफल रहा"</string>
-    <string name="create_error" msgid="3735649141335444215">"फ़ोल्डर बनाने में विफल"</string>
-    <string name="query_error" msgid="1222448261663503501">"दस्तावेजों के लिए क्वेरी करने में विफल रहा"</string>
-    <string name="root_recent" msgid="4470053704320518133">"हाल ही के"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> रिक्त"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"संग्रहण सेवाएं"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"शॉर्टकट"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"उपकरण"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"अधिक एप्स"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"उन्नत उपकरणों को दिखाएं"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"फ़ाइल का आकार दिखाएं"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"उपकरण का आकार दिखाएं"</string>
-    <string name="empty" msgid="7858882803708117596">"कोई आइटम नहीं"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"फ़ाइल नहीं खोली जा सकती"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"कुछ दस्तावेज़ों को हटाने में अक्षम"</string>
-    <string name="share_via" msgid="8966594246261344259">"इसके द्वारा साझा करें"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-hr/strings.xml b/packages/DocumentsUI/res/values-hr/strings.xml
deleted file mode 100644
index 73c2f04..0000000
--- a/packages/DocumentsUI/res/values-hr/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenti"</string>
-    <string name="title_open" msgid="4353228937663917801">"Otvori iz"</string>
-    <string name="title_save" msgid="2433679664882857999">"Spremi u"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Izradi mapu"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Prikaz rešetke"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Prikaz popisa"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Poredano po"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Pretraživanje"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Postavke"</string>
-    <string name="menu_open" msgid="432922957274920903">"Otvaranje"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Spremi"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Dijeli"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Izbriši"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Odabrano: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Po korisniku"</string>
-    <string name="sort_date" msgid="586080032956151448">"Po datumu izmjene"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Po veličini"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Prikaži korijene"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Sakrij korijene"</string>
-    <string name="save_error" msgid="6167009778003223664">"Nije uspjelo spremanje dokumenta"</string>
-    <string name="create_error" msgid="3735649141335444215">"Izrada mape nije uspjela"</string>
-    <string name="query_error" msgid="1222448261663503501">"Traženje dokumenata nije uspjelo"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Nedavno"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> besplatno"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Usluge pohrane"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Prečaci"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Uređaji"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Više aplikacija"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Prikaži napredne uređaje"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Prikaži veličinu datoteke"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Prikaži veličinu uređaja"</string>
-    <string name="empty" msgid="7858882803708117596">"Nema stavki"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Datoteku nije moguće otvoriti"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Nije moguće izbrisati neke dokumente"</string>
-    <string name="share_via" msgid="8966594246261344259">"Dijeli putem"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-hu/strings.xml b/packages/DocumentsUI/res/values-hu/strings.xml
deleted file mode 100644
index db7854b..0000000
--- a/packages/DocumentsUI/res/values-hu/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumentumok"</string>
-    <string name="title_open" msgid="4353228937663917801">"Megnyitás innen"</string>
-    <string name="title_save" msgid="2433679664882857999">"Mentés ide"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Mappa létrehozása"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Rács"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Lista"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Rendezés"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Keresés"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Beállítások"</string>
-    <string name="menu_open" msgid="432922957274920903">"Megnyitás"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Mentés"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Megosztás"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Törlés"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> kiválasztva"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Név szerint"</string>
-    <string name="sort_date" msgid="586080032956151448">"Módosítás dátuma szerint"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Méret szerint"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Gyökérszint megjelenítése"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Gyökérszint elrejtése"</string>
-    <string name="save_error" msgid="6167009778003223664">"Nem sikerült menteni a dokumentumot"</string>
-    <string name="create_error" msgid="3735649141335444215">"Nem sikerült létrehozni a mappát"</string>
-    <string name="query_error" msgid="1222448261663503501">"A dokumentumok lekérése nem sikerült"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Legutóbbiak"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> szabad"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Tárhelyszolgáltatások"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Parancsikonok"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Eszközök"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"További alkalmazások"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Speciális eszközök megjelenítése"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Fájlméret megjelenítése"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Eszközméret megjelenítése"</string>
-    <string name="empty" msgid="7858882803708117596">"Nincsenek elemek"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"A fájlt nem lehet megnyitni"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Néhány dokumentumot nem lehet törölni"</string>
-    <string name="share_via" msgid="8966594246261344259">"Megosztás itt:"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-hy-rAM/strings.xml b/packages/DocumentsUI/res/values-hy-rAM/strings.xml
deleted file mode 100644
index c683f3e..0000000
--- a/packages/DocumentsUI/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Փաստաթղթեր"</string>
-    <string name="title_open" msgid="4353228937663917801">"Բացել այստեղից"</string>
-    <string name="title_save" msgid="2433679664882857999">"Պահել այստեղ"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Ստեղծել թղթապանակ"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Ցանցային տեսք"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Ցուցակի տեսք"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Դասավորել ըստ"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Որոնել"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Կարգավորումներ"</string>
-    <string name="menu_open" msgid="432922957274920903">"Բացել"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Պահել"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Համօգտագործել"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Ջնջել"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> ընտրված"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Ըստ անվան"</string>
-    <string name="sort_date" msgid="586080032956151448">"Ըստ փոփոխման ամսաթվի"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Ըստ չափի"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Ցույց տալ արմատները"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Թաքցնել արմատները"</string>
-    <string name="save_error" msgid="6167009778003223664">"Չհաջողվեց պահել փաստաթուղթը"</string>
-    <string name="create_error" msgid="3735649141335444215">"Չհաջողվեց ստեղծել թղթապանակը"</string>
-    <string name="query_error" msgid="1222448261663503501">"Փաստաթղթերին հարցում կատարելիս սխալ տեղի ունեցավ"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Վերջին"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ազատ է"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Պահուստի ծառայություններ"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Դյուրանցումներ"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Սարքեր"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Հավելյալ ծրագրեր"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Ցուցադրել ընդլայնված սարքերը"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Ցուցադրել ֆայլի չափը"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Ցուցադրել սարքի չափը"</string>
-    <string name="empty" msgid="7858882803708117596">"Տարրեր չկան"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Հնարավոր չէ բացել ֆայլը"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Անհնար է ջնջել որոշ փաստաթղթեր"</string>
-    <string name="share_via" msgid="8966594246261344259">"Տարածել"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-in/strings.xml b/packages/DocumentsUI/res/values-in/strings.xml
deleted file mode 100644
index 519b936..0000000
--- a/packages/DocumentsUI/res/values-in/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumen"</string>
-    <string name="title_open" msgid="4353228937663917801">"Buka dari"</string>
-    <string name="title_save" msgid="2433679664882857999">"Simpan ke"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Buat folder"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Tampilan kisi"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Tampilan daftar"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortir menurut"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Telusuri"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Setelan"</string>
-    <string name="menu_open" msgid="432922957274920903">"Buka"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Simpan"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Bagikan"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Hapus"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> dipilih"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Menurut nama"</string>
-    <string name="sort_date" msgid="586080032956151448">"Menurut tanggal diubah"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Menurut ukuran"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Tampilkan akar"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Sembunyikan akar"</string>
-    <string name="save_error" msgid="6167009778003223664">"Gagal menyimpan dokumen"</string>
-    <string name="create_error" msgid="3735649141335444215">"Gagal membuat folder"</string>
-    <string name="query_error" msgid="1222448261663503501">"Gagal mengirim kueri untuk dokumen"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Terkini"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> bebas"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Layanan penyimpanan"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Pintasan"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Perangkat"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Aplikasi lain"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Tampilkan perangkat lanjutan"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Tampilkan ukuran file"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Tampilkan ukuran perangkat"</string>
-    <string name="empty" msgid="7858882803708117596">"Tidak ada item"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Tidak dapat membuka file"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Tidak dapat menghapus beberapa dokumen"</string>
-    <string name="share_via" msgid="8966594246261344259">"Bagikan melalui"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-it/strings.xml b/packages/DocumentsUI/res/values-it/strings.xml
deleted file mode 100644
index 28323b6..0000000
--- a/packages/DocumentsUI/res/values-it/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documenti"</string>
-    <string name="title_open" msgid="4353228937663917801">"Apri da"</string>
-    <string name="title_save" msgid="2433679664882857999">"Salva in"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Crea cartella"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Visualizzazione griglia"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Visualizzazione elenco"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Ordina per"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Cerca"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Impostazioni"</string>
-    <string name="menu_open" msgid="432922957274920903">"Apri"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Salva"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Condividi"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Elimina"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> selezionati"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Per nome"</string>
-    <string name="sort_date" msgid="586080032956151448">"Per data di modifica"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Per dimensioni"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Mostra nodi principali"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Nascondi nodi principali"</string>
-    <string name="save_error" msgid="6167009778003223664">"Impossibile salvare il documento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Impossibile creare la cartella"</string>
-    <string name="query_error" msgid="1222448261663503501">"Impossibile chiedere documenti"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recente"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> liberi"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Servizi di archiviazione"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Scorciatoie"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispositivi"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Altre app"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Visualizza dispositivi avanzati"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Visualizza dimensioni file"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Visualizza dimensioni dispositivi"</string>
-    <string name="empty" msgid="7858882803708117596">"Nessun articolo"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Impossibile aprire il file"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Impossibile eliminare alcuni documenti"</string>
-    <string name="share_via" msgid="8966594246261344259">"Condividi via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-iw/strings.xml b/packages/DocumentsUI/res/values-iw/strings.xml
deleted file mode 100644
index 712c060..0000000
--- a/packages/DocumentsUI/res/values-iw/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"מסמכים"</string>
-    <string name="title_open" msgid="4353228937663917801">"פתח מ-"</string>
-    <string name="title_save" msgid="2433679664882857999">"שמור ב-"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"צור תיקיה"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"תצוגת רשת"</string>
-    <string name="menu_list" msgid="7279285939892417279">"תצוגת רשימה"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"מיין לפי"</string>
-    <string name="menu_search" msgid="3816712084502856974">"חפש"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"הגדרות"</string>
-    <string name="menu_open" msgid="432922957274920903">"פתח"</string>
-    <string name="menu_save" msgid="2394743337684426338">"שמור"</string>
-    <string name="menu_share" msgid="3075149983979628146">"שתף"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"מחק"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> נבחרו"</string>
-    <string name="sort_name" msgid="9183560467917256779">"לפי שם"</string>
-    <string name="sort_date" msgid="586080032956151448">"לפי תאריך שינוי"</string>
-    <string name="sort_size" msgid="3350681319735474741">"לפי גודל"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"הצג שורשים"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"הסתר שורשים"</string>
-    <string name="save_error" msgid="6167009778003223664">"שמירת המסמך נכשלה"</string>
-    <string name="create_error" msgid="3735649141335444215">"יצירת התיקיה נכשלה"</string>
-    <string name="query_error" msgid="1222448261663503501">"שאילתת המסמכים נכשלה"</string>
-    <string name="root_recent" msgid="4470053704320518133">"מהזמן האחרון"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> של שטח פנוי"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"שירותי אחסון"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"קיצורי דרך"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"מכשירים"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"עוד אפליקציות"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"הצג מכשירים מתקדמים"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"הצג את גודל הקובץ"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"הצג את גודל המכשיר"</string>
-    <string name="empty" msgid="7858882803708117596">"אין פריטים"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"לא ניתן לפתוח את הקובץ"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"לא ניתן למחוק חלק מהמסמכים"</string>
-    <string name="share_via" msgid="8966594246261344259">"שתף באמצעות"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ja/strings.xml b/packages/DocumentsUI/res/values-ja/strings.xml
deleted file mode 100644
index 996496d..0000000
--- a/packages/DocumentsUI/res/values-ja/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"ドキュメント"</string>
-    <string name="title_open" msgid="4353228937663917801">"次から開く:"</string>
-    <string name="title_save" msgid="2433679664882857999">"次に保存:"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"フォルダを作成"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"グリッド表示"</string>
-    <string name="menu_list" msgid="7279285939892417279">"リスト表示"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"並べ替え"</string>
-    <string name="menu_search" msgid="3816712084502856974">"検索"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"設定"</string>
-    <string name="menu_open" msgid="432922957274920903">"開く"</string>
-    <string name="menu_save" msgid="2394743337684426338">"保存"</string>
-    <string name="menu_share" msgid="3075149983979628146">"共有"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"削除"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g>件選択済み"</string>
-    <string name="sort_name" msgid="9183560467917256779">"名前順"</string>
-    <string name="sort_date" msgid="586080032956151448">"更新日順"</string>
-    <string name="sort_size" msgid="3350681319735474741">"サイズ順"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"ルートを表示する"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"ルートを非表示にする"</string>
-    <string name="save_error" msgid="6167009778003223664">"ドキュメントを保存できませんでした"</string>
-    <string name="create_error" msgid="3735649141335444215">"フォルダを作成できませんでした"</string>
-    <string name="query_error" msgid="1222448261663503501">"ドキュメントのクエリに失敗しました"</string>
-    <string name="root_recent" msgid="4470053704320518133">"最近"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"空き容量: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"ストレージサービス"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"ショートカット"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"端末"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"その他のアプリ"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"端末の詳細設定を表示"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"ファイルのサイズを表示"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"端末のサイズを表示"</string>
-    <string name="empty" msgid="7858882803708117596">"アイテムがありません"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"ファイルを開けません"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"一部のドキュメントを削除できません"</string>
-    <string name="share_via" msgid="8966594246261344259">"共有ツール"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ka-rGE/strings.xml b/packages/DocumentsUI/res/values-ka-rGE/strings.xml
deleted file mode 100644
index f3e1274..0000000
--- a/packages/DocumentsUI/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"დოკუმენტები"</string>
-    <string name="title_open" msgid="4353228937663917801">"გახსნა აქედან:"</string>
-    <string name="title_save" msgid="2433679664882857999">"შენახვა აქ:"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"საქაღალდის შექმნა"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"ბადის ხედი"</string>
-    <string name="menu_list" msgid="7279285939892417279">"სიის ხედი"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"სორტირება:"</string>
-    <string name="menu_search" msgid="3816712084502856974">"ძიება"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"პარამეტრები"</string>
-    <string name="menu_open" msgid="432922957274920903">"გახსნა"</string>
-    <string name="menu_save" msgid="2394743337684426338">"შენახვა"</string>
-    <string name="menu_share" msgid="3075149983979628146">"გაზიარება"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"წაშლა"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> მონიშნული"</string>
-    <string name="sort_name" msgid="9183560467917256779">"სახელით"</string>
-    <string name="sort_date" msgid="586080032956151448">"ცვლილების თარიღით"</string>
-    <string name="sort_size" msgid="3350681319735474741">"ზომით"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"ფესვების ჩვენება"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"ფესვების დამალვა"</string>
-    <string name="save_error" msgid="6167009778003223664">"დოკუმენტის შენახვა ვერ მოხერხდა"</string>
-    <string name="create_error" msgid="3735649141335444215">"საქაღალდის შექმნა ვერ მოხერხდა"</string>
-    <string name="query_error" msgid="1222448261663503501">"დოკუმენტებზე მოთხოვნა ვერ გაიგზავნა"</string>
-    <string name="root_recent" msgid="4470053704320518133">"ბოლო"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> თავისუფალია"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"მეხსიერების სერვისები"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"მალსახმობები"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"მოწყობილობები"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"მეტი აპები"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"კომპლექსური მოწყობილობების ჩვენება"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"ფაილის ზომის ჩვენება"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"მოწყობილობის ზომის ჩვენება"</string>
-    <string name="empty" msgid="7858882803708117596">"ერთეულები არ არის"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"ფაილის გახსნა ვერ ხერხდება"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"ზოგიერთი დოკუმენტის წაშლა ვერ ხერხდება"</string>
-    <string name="share_via" msgid="8966594246261344259">"გაზიარება:"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-km-rKH/strings.xml b/packages/DocumentsUI/res/values-km-rKH/strings.xml
deleted file mode 100644
index 80f3698..0000000
--- a/packages/DocumentsUI/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"ឯកសារ"</string>
-    <string name="title_open" msgid="4353228937663917801">"បើក​ពី"</string>
-    <string name="title_save" msgid="2433679664882857999">"រក្សា​ទុក​ទៅ"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"បង្កើត​ថត"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"ទិដ្ឋភាព​ក្រឡា"</string>
-    <string name="menu_list" msgid="7279285939892417279">"ទិដ្ឋភាព​បញ្ជី"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"តម្រៀប​តាម"</string>
-    <string name="menu_search" msgid="3816712084502856974">"ស្វែងរក"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"ការ​កំណត់"</string>
-    <string name="menu_open" msgid="432922957274920903">"បើក"</string>
-    <string name="menu_save" msgid="2394743337684426338">"រក្សាទុក"</string>
-    <string name="menu_share" msgid="3075149983979628146">"ចែករំលែក"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"លុប"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"បាន​ជ្រើស <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"តាម​ឈ្មោះ"</string>
-    <string name="sort_date" msgid="586080032956151448">"តាម​កាលបរិច្ឆេទ​បាន​កែប្រែ"</string>
-    <string name="sort_size" msgid="3350681319735474741">"តាម​​ទំហំ"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"បង្ហាញ roots"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"លាក់ roots"</string>
-    <string name="save_error" msgid="6167009778003223664">"បាន​បរាជ័យ​ក្នុង​ការ​រក្សា​ទុក​ឯកសារ"</string>
-    <string name="create_error" msgid="3735649141335444215">"បាន​បរាជ័យ​ក្នុង​ការ​បង្កើត​ថត"</string>
-    <string name="query_error" msgid="1222448261663503501">"បាន​បរាជ័យ​ក្នុង​ការ​​ច្រោះ​ឯកសារ"</string>
-    <string name="root_recent" msgid="4470053704320518133">"ថ្មីៗ"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"ទំនេរ <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"សេវាកម្ម​ផ្ដល់​ឧបករណ៍​ផ្ទុក"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"ផ្លូវកាត់"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"ឧបករណ៍"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"កម្ម​វិធី​​ច្រើន​ទៀត"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"បង្ហាញ​ឧបករណ៍​កម្រិត​ខ្ពស់"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"បង្ហាញ​ទំហំ​ឯកសារ"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"បង្ហាញ​ទំហំ​ឧបករណ៍"</string>
-    <string name="empty" msgid="7858882803708117596">"គ្មានធាតុ"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"មិន​អាច​បើក​ឯកសារ"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"មិន​អាច​លុប​ឯកសារ​មួយ​ចំនួន"</string>
-    <string name="share_via" msgid="8966594246261344259">"ចែករំលែក​តាម"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ko/strings.xml b/packages/DocumentsUI/res/values-ko/strings.xml
deleted file mode 100644
index 2cd0d44..0000000
--- a/packages/DocumentsUI/res/values-ko/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"문서"</string>
-    <string name="title_open" msgid="4353228937663917801">"열기:"</string>
-    <string name="title_save" msgid="2433679664882857999">"저장 위치:"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"폴더 만들기"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"바둑판식 보기"</string>
-    <string name="menu_list" msgid="7279285939892417279">"목록 보기"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"정렬 기준"</string>
-    <string name="menu_search" msgid="3816712084502856974">"검색"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"설정"</string>
-    <string name="menu_open" msgid="432922957274920903">"열기"</string>
-    <string name="menu_save" msgid="2394743337684426338">"저장"</string>
-    <string name="menu_share" msgid="3075149983979628146">"공유"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"삭제"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g>개 선택됨"</string>
-    <string name="sort_name" msgid="9183560467917256779">"이름순"</string>
-    <string name="sort_date" msgid="586080032956151448">"수정된 날짜순"</string>
-    <string name="sort_size" msgid="3350681319735474741">"크기순"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"루트 표시"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"루트 숨기기"</string>
-    <string name="save_error" msgid="6167009778003223664">"문서 저장 실패"</string>
-    <string name="create_error" msgid="3735649141335444215">"폴더를 만들지 못함"</string>
-    <string name="query_error" msgid="1222448261663503501">"문서를 검색하지 못했습니다."</string>
-    <string name="root_recent" msgid="4470053704320518133">"최근"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> 남음"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"저장용량 서비스"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"바로가기"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"기기"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"앱 더보기"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"고급 기기 표시"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"파일 크기 표시"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"기기 크기 표시"</string>
-    <string name="empty" msgid="7858882803708117596">"항목 없음"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"파일을 열 수 없음"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"일부 문서를 삭제할 수 없음"</string>
-    <string name="share_via" msgid="8966594246261344259">"공유 방법"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-lo-rLA/strings.xml b/packages/DocumentsUI/res/values-lo-rLA/strings.xml
deleted file mode 100644
index 9a6f32f..0000000
--- a/packages/DocumentsUI/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"ເອ​ກະ​ສານ"</string>
-    <string name="title_open" msgid="4353228937663917801">"ເປີດ​ຈາກ"</string>
-    <string name="title_save" msgid="2433679664882857999">"ບັນທຶກໄປທີ່"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"ສ້າງໂຟນເດີ"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"ມຸມມອງແບບຊ່ອງ"</string>
-    <string name="menu_list" msgid="7279285939892417279">"ມຸມມອງແບບລາຍຊື່"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"ຮຽງລຳດັບຕາມ"</string>
-    <string name="menu_search" msgid="3816712084502856974">"ຊອກຫາ"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"ການຕັ້ງຄ່າ"</string>
-    <string name="menu_open" msgid="432922957274920903">"ເປີດ"</string>
-    <string name="menu_save" msgid="2394743337684426338">"ບັນທຶກ"</string>
-    <string name="menu_share" msgid="3075149983979628146">"ແບ່ງປັນ"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"ລຶບ"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"ເລືອກແລ້ວ <xliff:g id="COUNT">%1$d</xliff:g> ລາຍການ"</string>
-    <string name="sort_name" msgid="9183560467917256779">"ຕາມຊື່"</string>
-    <string name="sort_date" msgid="586080032956151448">"ຕາມວັນທີທີ່ແກ້ໄຂ"</string>
-    <string name="sort_size" msgid="3350681319735474741">"ຕາມຂະໜາດ"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"ສະແດງ roots"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"ເຊື່ອງ roots"</string>
-    <string name="save_error" msgid="6167009778003223664">"ການບັນທຶກເອກະສານລົ້ມເຫລວ"</string>
-    <string name="create_error" msgid="3735649141335444215">"ການ​ສ້າງ​ໂຟນ​ເດີລົ້ມເຫຼວ"</string>
-    <string name="query_error" msgid="1222448261663503501">"ການຊອກຫາເອກະສານລົ້ມເຫຼວ"</string>
-    <string name="root_recent" msgid="4470053704320518133">"ຫາກໍໃຊ້"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"ຟຣີ <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"ບໍລິການບ່ອນຈັດເກັບຂໍ້ມູນ"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"ທາງລັດ"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"ອຸປະກອນ"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"ແອັບຯອື່ນໆ"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"ສະແດງອຸປະກອນຂັ້ນສູງ"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"ສະແດງຂະໜາດໄຟລ໌"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"ສະແດງຂະໜາດອຸປະກອນ"</string>
-    <string name="empty" msgid="7858882803708117596">"ບໍ່ມີລາຍການ"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"ບໍ່ສາມດາເປີດໄຟລ໌ໄດ້"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"ບໍ່ສາມາດລຶບບາງເອກະສານໄດ້"</string>
-    <string name="share_via" msgid="8966594246261344259">"ແບ່ງປັນຜ່ານ"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-lt/strings.xml b/packages/DocumentsUI/res/values-lt/strings.xml
deleted file mode 100644
index f861b99..0000000
--- a/packages/DocumentsUI/res/values-lt/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumentai"</string>
-    <string name="title_open" msgid="4353228937663917801">"Atidaryti iš"</string>
-    <string name="title_save" msgid="2433679664882857999">"Išsaugoti į"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Kurti aplanką"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Tinklelio rodinys"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Sąrašo rodinys"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Rūšiuoti pagal"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Ieškoti"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Nustatymai"</string>
-    <string name="menu_open" msgid="432922957274920903">"Atidaryti"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Išsaugoti"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Bendrinti"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Ištrinti"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Pasirinkta: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Pagal pavadinimą"</string>
-    <string name="sort_date" msgid="586080032956151448">"Pagal keitimo datą"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Pagal dydį"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Rodyti šaknis"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Slėpti šaknis"</string>
-    <string name="save_error" msgid="6167009778003223664">"Nepavyko išsaugoti dokumento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Nepavyko sukurti aplanko"</string>
-    <string name="query_error" msgid="1222448261663503501">"Nepavyko pateikti dokumentų užklausų"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Naujausi"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Laisvos vietos: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Saugyklos paslaugos"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Spartieji klavišai"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Įrenginiai"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Daugiau programų"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Rodyti išplėstinius įrenginius"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Rodyti failo dydį"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Rodyti įrenginio dydį"</string>
-    <string name="empty" msgid="7858882803708117596">"Nėra elementų"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Nepavyksta atidaryti failo"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Nepavyko ištrinti kai kurių dokumentų"</string>
-    <string name="share_via" msgid="8966594246261344259">"Bendrinti naudojant"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-lv/strings.xml b/packages/DocumentsUI/res/values-lv/strings.xml
deleted file mode 100644
index 651a59fe0d..0000000
--- a/packages/DocumentsUI/res/values-lv/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenti"</string>
-    <string name="title_open" msgid="4353228937663917801">"Atvēršana no:"</string>
-    <string name="title_save" msgid="2433679664882857999">"Saglabāšana:"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Izveidot mapi"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Režģis"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Saraksts"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Kārtot pēc"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Meklēt"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Iestatījumi"</string>
-    <string name="menu_open" msgid="432922957274920903">"Atvērt"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Saglabāt"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Kopīgot"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Dzēst"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Atlasīts: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Pēc nosaukuma"</string>
-    <string name="sort_date" msgid="586080032956151448">"Pēc pārveidošanas datuma"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Pēc lieluma"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Rādīt saknes"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Slēpt saknes"</string>
-    <string name="save_error" msgid="6167009778003223664">"Neizdevās saglabāt dokumentu."</string>
-    <string name="create_error" msgid="3735649141335444215">"Neizdevās izveidot mapi."</string>
-    <string name="query_error" msgid="1222448261663503501">"Neizdevās atrast vaicājumā norādītos dokumentus."</string>
-    <string name="root_recent" msgid="4470053704320518133">"Pēdējie"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Brīva vieta: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Glabāšanas pakalpojumi"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Saīsnes"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Ierīces"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Vairāk lietotņu"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Attēlot papildu ierīces"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Attēlot faila lielumu"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Attēlot ierīces izmēru"</string>
-    <string name="empty" msgid="7858882803708117596">"Nav vienumu"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Nevar atvērt failu."</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Nevar dzēst dažus dokumentus."</string>
-    <string name="share_via" msgid="8966594246261344259">"Kopīgot, izmantojot"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-mn-rMN/strings.xml b/packages/DocumentsUI/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 22c9fcd..0000000
--- a/packages/DocumentsUI/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Документүүд"</string>
-    <string name="title_open" msgid="4353228937663917801">"Нээх"</string>
-    <string name="title_save" msgid="2433679664882857999">"Хадгалах"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Фолдер үүсгэх"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Эгнүүлж харах"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Жагсааж харах"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Эрэмбэлэх"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Хайх"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Тохиргоо"</string>
-    <string name="menu_open" msgid="432922957274920903">"Нээх"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Хадгалах"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Хуваалцах"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Устгах"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> сонгогдсон"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Нэрээр"</string>
-    <string name="sort_date" msgid="586080032956151448">"Өөрчлөгдсөн огноогоор"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Хэмжээгээр"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Язгуурыг харуулах"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Язгуурыг нууцлах"</string>
-    <string name="save_error" msgid="6167009778003223664">"Документыг хадгалж чадсангүй"</string>
-    <string name="create_error" msgid="3735649141335444215">"Фолдер үүсгэж чадсангүй"</string>
-    <string name="query_error" msgid="1222448261663503501">"Документын хүсэлт гаргаж чадсангүй"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Саяхны"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> чөлөөтэй"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Сангийн үйлчилгээ"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Товчлол"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Төхөөрөмжүүд"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Өөр апп-ууд"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Дэвшилтэт төхөөрөмжүүдийг харуулах"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Файлын хэмжээг харуулах"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Төхөөрөмжийн хэмжээг харуулах"</string>
-    <string name="empty" msgid="7858882803708117596">"Хоосон"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Файлыг нээх боломжгүй"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Зарим документуудыг устгах боломжгүй"</string>
-    <string name="share_via" msgid="8966594246261344259">"Дараахаар дамжуулан хуваалцах"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-mn/strings.xml b/packages/DocumentsUI/res/values-mn/strings.xml
deleted file mode 100644
index 66637b8..0000000
--- a/packages/DocumentsUI/res/values-mn/strings.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Документүүд"</string>
-    <string name="title_open" msgid="4353228937663917801">"Нээх"</string>
-    <string name="title_save" msgid="2433679664882857999">"Хадгалах"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Фолдер үүсгэх"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Эгнүүлж харах"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Жагсааж харах"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Эрэмбэлэх"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Хайх"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Тохиргоо"</string>
-    <string name="menu_open" msgid="432922957274920903">"Нээх"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Хадгалах"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Хуваалцах"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Устгах"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> сонгогдсон"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Нэрээр"</string>
-    <string name="sort_date" msgid="586080032956151448">"Өөрчлөгдсөн огноогоор"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Хэмжээгээр"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Язгуурыг харуулах"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Язгуурыг нууцлах"</string>
-    <string name="save_error" msgid="6167009778003223664">"Документыг хадгалж чадсангүй"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Саяхны"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> чөлөөтэй"</string>
-    <string name="root_type_service" msgid="2857362700576006694">"Үйлчилгээнүүд"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Товчлол"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Төхөөрөмжүүд"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Өөр апп-ууд"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Дэвшилтэт төхөөрөмжүүдийг харуулах"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Файлын хэмжээг харуулах"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Төхөөрөмжийн хэмжээг харуулах"</string>
-    <string name="empty" msgid="7858882803708117596">"Хоосон"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Файлыг нээх боломжгүй"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Зарим документуудыг устгах боломжгүй"</string>
-    <string name="more" msgid="7117420986529297171">"Цааш"</string>
-    <string name="loading" msgid="7933681260296021180">"Ачааллаж байна..."</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ms-rMY/strings.xml b/packages/DocumentsUI/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 7e09c57..0000000
--- a/packages/DocumentsUI/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumen"</string>
-    <string name="title_open" msgid="4353228937663917801">"Buka dari"</string>
-    <string name="title_save" msgid="2433679664882857999">"Simpan ke"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Buat folder"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Paparan grid"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Paparan senarai"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Isih mengikut"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Cari"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Tetapan"</string>
-    <string name="menu_open" msgid="432922957274920903">"Buka"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Simpan"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Kongsi"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Padam"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> dipilih"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Mengikut nama"</string>
-    <string name="sort_date" msgid="586080032956151448">"Diubah suai mengikut tarikh"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Mengikut saiz"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Tunjukkan akar"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Sembunyikan akar"</string>
-    <string name="save_error" msgid="6167009778003223664">"Gagal menyimpan dokumen"</string>
-    <string name="create_error" msgid="3735649141335444215">"Gagal membuat folder"</string>
-    <string name="query_error" msgid="1222448261663503501">"Gagal menanyakan dokumen"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Terbaharu"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> kosong"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Perkhidmatan storan"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Pintasan"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Peranti"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Lebih banyak apl"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Paparkan peranti terperinci"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Paparkan saiz fail"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Paparkan saiz peranti"</string>
-    <string name="empty" msgid="7858882803708117596">"Tiada item"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Tidak dapat membuka fail"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Tidak dapat memadam beberapa dokumen"</string>
-    <string name="share_via" msgid="8966594246261344259">"Kongsi melalui"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-nb/strings.xml b/packages/DocumentsUI/res/values-nb/strings.xml
deleted file mode 100644
index 8831bd8..0000000
--- a/packages/DocumentsUI/res/values-nb/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenter"</string>
-    <string name="title_open" msgid="4353228937663917801">"Åpne fra"</string>
-    <string name="title_save" msgid="2433679664882857999">"Lagre i"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Opprett en mappe"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Rutenettvisning"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Listevisning"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortér etter"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Søk"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Innstillinger"</string>
-    <string name="menu_open" msgid="432922957274920903">"Åpne"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Lagre"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Del"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Slett"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> valgt"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Etter navn"</string>
-    <string name="sort_date" msgid="586080032956151448">"«Etter dato» endret"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Etter størrelse"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Vis røtter"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Skjul røtter"</string>
-    <string name="save_error" msgid="6167009778003223664">"Kunne ikke lagre dokumentet"</string>
-    <string name="create_error" msgid="3735649141335444215">"Kunne ikke opprette mappen"</string>
-    <string name="query_error" msgid="1222448261663503501">"Kunne ikke undersøke dokumenter"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Siste"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> gratis"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Lagringstjenester"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Snarveier"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Enheter"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Flere apper"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Vis avanserte enheter"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Vis filstørrelse"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Vis enhetsstørrelse"</string>
-    <string name="empty" msgid="7858882803708117596">"Ingen elementer"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Kan ikke åpne filen"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Enkelte dokumenter kunne ikke slettes"</string>
-    <string name="share_via" msgid="8966594246261344259">"Del via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ne-rNP/strings.xml b/packages/DocumentsUI/res/values-ne-rNP/strings.xml
deleted file mode 100644
index d2606df..0000000
--- a/packages/DocumentsUI/res/values-ne-rNP/strings.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"कागजातहरू"</string>
-    <string name="title_open" msgid="4353228937663917801">"यसबाट खोल्नुहोस्"</string>
-    <string name="title_save" msgid="2433679664882857999">"यसमा सुरक्षित गर्नुहोस्"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"फोल्डर सिर्जना गर्नुहोस्"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"ग्रिड दृश्य"</string>
-    <string name="menu_list" msgid="7279285939892417279">"सूची दृश्य"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"यसद्वारा क्रमवद्घ गर्नुहोस्"</string>
-    <string name="menu_search" msgid="3816712084502856974">"खोज्नुहोस्"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"सेटिङहरू"</string>
-    <string name="menu_open" msgid="432922957274920903">"खोल्नुहोस्"</string>
-    <string name="menu_save" msgid="2394743337684426338">"सुरक्षित गर्नुहोस्"</string>
-    <string name="menu_share" msgid="3075149983979628146">"साझेदारी गर्नुहोस्"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"मेटाउनुहोस्"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> चयन गरियो"</string>
-    <string name="sort_name" msgid="9183560467917256779">"नाम अनुसार"</string>
-    <string name="sort_date" msgid="586080032956151448">"परिमार्जित मिति अनुसार"</string>
-    <string name="sort_size" msgid="3350681319735474741">"आकार अनुसार"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"मूलहरू देखाउनुहोस्"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"मूलहरू लुकाउनुहोस्"</string>
-    <string name="save_error" msgid="6167009778003223664">"कागजात सुरक्षित गर्न विफल भयो"</string>
-    <string name="root_recent" msgid="4470053704320518133">"हालैको"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> खाली"</string>
-    <!-- no translation found for root_type_service (2178854894416775409) -->
-    <skip />
-    <string name="root_type_shortcut" msgid="3318760609471618093">"सर्टकटहरू"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"उपकरणहरू"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"थप अनुप्रयोगहरू"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"उन्नत उपकरणहरू प्रदर्शन गर्नुहोस्"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"फाइल आकार प्रदर्शन गर्नुहोस्"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"उपकरण आकार प्रदर्शन गर्नुहोस्"</string>
-    <string name="empty" msgid="7858882803708117596">"कुनै वस्तु छैन।"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"फाइल खोल्न सक्दैन"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"केही कागजातहरू मेट्न असमर्थ छ"</string>
-    <string name="share_via" msgid="8966594246261344259">"माध्यमबाट साझेदारी गर्नुहोस्"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-nl/strings.xml b/packages/DocumentsUI/res/values-nl/strings.xml
deleted file mode 100644
index 08862e8..0000000
--- a/packages/DocumentsUI/res/values-nl/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documenten"</string>
-    <string name="title_open" msgid="4353228937663917801">"Openen vanuit"</string>
-    <string name="title_save" msgid="2433679664882857999">"Opslaan in"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Map maken"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Rasterweergave"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Lijstweergave"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sorteren op"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Zoeken"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Instellingen"</string>
-    <string name="menu_open" msgid="432922957274920903">"Openen"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Opslaan"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Delen"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Verwijderen"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> geselecteerd"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Op naam"</string>
-    <string name="sort_date" msgid="586080032956151448">"Op aanpassingsdatum"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Op grootte"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Roots weergeven"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Roots verbergen"</string>
-    <string name="save_error" msgid="6167009778003223664">"Kan document niet opslaan"</string>
-    <string name="create_error" msgid="3735649141335444215">"Kan map niet maken"</string>
-    <string name="query_error" msgid="1222448261663503501">"Kan geen query\'s voor documenten verzenden"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recent"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> vrij"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Opslagservices"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Sneltoetsen"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Apparaten"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Meer apps"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Geavanceerde apparaten weergeven"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Bestandsgrootte weergeven"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Apparaatgrootte weergeven"</string>
-    <string name="empty" msgid="7858882803708117596">"Geen items"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Kan bestand niet openen"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Kan bepaalde documenten niet verwijderen"</string>
-    <string name="share_via" msgid="8966594246261344259">"Delen via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-pl/strings.xml b/packages/DocumentsUI/res/values-pl/strings.xml
deleted file mode 100644
index f4e5582..0000000
--- a/packages/DocumentsUI/res/values-pl/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenty"</string>
-    <string name="title_open" msgid="4353228937663917801">"Otwórz z"</string>
-    <string name="title_save" msgid="2433679664882857999">"Zapisz w"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Utwórz folder"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Widok siatki"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Widok listy"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortuj według"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Szukaj"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Ustawienia"</string>
-    <string name="menu_open" msgid="432922957274920903">"Otwórz"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Zapisz"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Udostępnij"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Usuń"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Wybrano: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Według nazwy"</string>
-    <string name="sort_date" msgid="586080032956151448">"Według daty edycji"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Według rozmiaru"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Pokaż elementy główne"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ukryj elementy główne"</string>
-    <string name="save_error" msgid="6167009778003223664">"Nie udało się zapisać dokumentu"</string>
-    <string name="create_error" msgid="3735649141335444215">"Nie udało się utworzyć folderu"</string>
-    <string name="query_error" msgid="1222448261663503501">"Nie udało się pobrać listy dokumentów"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Ostatnie"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> wolne"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Usługi pamięci masowej"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Skróty"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Urządzenia"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Więcej aplikacji"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Wyświetl urządzenia zaawansowane"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Wyświetl rozmiar pliku"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Wyświetl rozmiar urządzenia"</string>
-    <string name="empty" msgid="7858882803708117596">"Brak elementów"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Nie można otworzyć pliku"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Nie można usunąć niektórych dokumentów"</string>
-    <string name="share_via" msgid="8966594246261344259">"Udostępnij przez"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-pt-rPT/strings.xml b/packages/DocumentsUI/res/values-pt-rPT/strings.xml
deleted file mode 100644
index 1c1ba8b..0000000
--- a/packages/DocumentsUI/res/values-pt-rPT/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documentos"</string>
-    <string name="title_open" msgid="4353228937663917801">"Abrir de"</string>
-    <string name="title_save" msgid="2433679664882857999">"Guardar em"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Criar pasta"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Vista de grelha"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Vista de lista"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Ordenar por"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Pesquisar"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Definições"</string>
-    <string name="menu_open" msgid="432922957274920903">"Abrir"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Guardar"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Partilhar"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Eliminar"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> selecionado(s)"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Por nome"</string>
-    <string name="sort_date" msgid="586080032956151448">"Por data de modificação"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Por tamanho"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Mostrar raízes"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ocultar raízes"</string>
-    <string name="save_error" msgid="6167009778003223664">"Falha ao guardar o documento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Falha ao criar a pasta"</string>
-    <string name="query_error" msgid="1222448261663503501">"Falha ao consultar os documentos"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recentes"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> espaço livre"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Serv. de armazenamento"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Atalhos"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispositivos"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Mais aplicações"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Apresentar dispositivos avançados"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Apresentar tamanho do ficheiro"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Apresentar tamanho do dispositivo"</string>
-    <string name="empty" msgid="7858882803708117596">"Sem itens"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Não é possível abrir o ficheiro"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Não é possível eliminar alguns documentos"</string>
-    <string name="share_via" msgid="8966594246261344259">"Partilhar através de"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-pt/strings.xml b/packages/DocumentsUI/res/values-pt/strings.xml
deleted file mode 100644
index 78fcaf8..0000000
--- a/packages/DocumentsUI/res/values-pt/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documentos"</string>
-    <string name="title_open" msgid="4353228937663917801">"Abrir de"</string>
-    <string name="title_save" msgid="2433679664882857999">"Salvar em"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Criar pasta"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Visualização em grade"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Visualização em lista"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Classificar por"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Pesquisar"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Configurações"</string>
-    <string name="menu_open" msgid="432922957274920903">"Abrir"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Salvar"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Compartilhar"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Excluir"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> selecionados"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Por nome"</string>
-    <string name="sort_date" msgid="586080032956151448">"Por data de modificação"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Por tamanho"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Mostrar raízes"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ocultar raízes"</string>
-    <string name="save_error" msgid="6167009778003223664">"Falha ao salvar o documento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Falha ao criar a pasta"</string>
-    <string name="query_error" msgid="1222448261663503501">"Falha ao consultar documentos"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recentes"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> livres"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Serviços de armazenamento"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Atalhos"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispositivos"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Mais aplicativos"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Mostrar dispositivos avançados"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Mostrar tamanho do arquivo"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Mostrar tamanho do dispositivo"</string>
-    <string name="empty" msgid="7858882803708117596">"Nenhum item"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Não é possível abrir o arquivo"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Não foi possível excluir alguns documentos"</string>
-    <string name="share_via" msgid="8966594246261344259">"Compartilhar via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ro/strings.xml b/packages/DocumentsUI/res/values-ro/strings.xml
deleted file mode 100644
index 5fd44c8..0000000
--- a/packages/DocumentsUI/res/values-ro/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Documente"</string>
-    <string name="title_open" msgid="4353228937663917801">"Deschideți din"</string>
-    <string name="title_save" msgid="2433679664882857999">"Salvați în"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Creați un dosar"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Afișare tip grilă"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Afișare tip listă"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortați după"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Căutați"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Setări"</string>
-    <string name="menu_open" msgid="432922957274920903">"Deschideți"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Salvați"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Distribuiți"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Ștergeți"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> selectate"</string>
-    <string name="sort_name" msgid="9183560467917256779">"După nume"</string>
-    <string name="sort_date" msgid="586080032956151448">"După data modificării"</string>
-    <string name="sort_size" msgid="3350681319735474741">"După dimensiune"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Afișați directoarele rădăcină"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ascundeți directoarele rădăcină"</string>
-    <string name="save_error" msgid="6167009778003223664">"Salvarea documentului nu a reușit"</string>
-    <string name="create_error" msgid="3735649141335444215">"Eroare la crearea dosarului"</string>
-    <string name="query_error" msgid="1222448261663503501">"Interogarea referitoare la documente nu a reușit"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Recente"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> spațiu liber"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Servicii de stocare"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Comenzi rapide"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Dispozitive"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Alte aplicații"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Afișați dispozitive avansate"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Afișați dimensiunile fișierelor"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Afișați capacitatea de stocare a dispozitivelor"</string>
-    <string name="empty" msgid="7858882803708117596">"Nu există elemente"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Fișierul nu poate fi deschis"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Unele documente nu au putut fi șterse"</string>
-    <string name="share_via" msgid="8966594246261344259">"Distribuiți prin"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-ru/strings.xml b/packages/DocumentsUI/res/values-ru/strings.xml
deleted file mode 100644
index 85fd70e0..0000000
--- a/packages/DocumentsUI/res/values-ru/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Документы"</string>
-    <string name="title_open" msgid="4353228937663917801">"Открыть"</string>
-    <string name="title_save" msgid="2433679664882857999">"Сохранить"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Новая папка"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Таблица"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Список"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Сортировать"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Поиск"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Настройки"</string>
-    <string name="menu_open" msgid="432922957274920903">"Открыть"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Сохранить"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Поделиться"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Удалить"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Выбрано: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"По названию"</string>
-    <string name="sort_date" msgid="586080032956151448">"По дате изменения"</string>
-    <string name="sort_size" msgid="3350681319735474741">"По размеру"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Показать"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Скрыть"</string>
-    <string name="save_error" msgid="6167009778003223664">"Не удалось сохранить документ"</string>
-    <string name="create_error" msgid="3735649141335444215">"Не удалось создать папку"</string>
-    <string name="query_error" msgid="1222448261663503501">"Не удалось отправить запрос"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Недавние"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Свободно <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Службы хранения"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Ярлыки"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Устройства"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Другие приложения"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Показать другие устройства"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Показать размер файла"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Показать размер устройства"</string>
-    <string name="empty" msgid="7858882803708117596">"Ничего нет"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Не удалось открыть файл"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Не удалось удалить некоторые документы"</string>
-    <string name="share_via" msgid="8966594246261344259">"Поделиться"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-si-rLK/strings.xml b/packages/DocumentsUI/res/values-si-rLK/strings.xml
deleted file mode 100644
index 6263b82..0000000
--- a/packages/DocumentsUI/res/values-si-rLK/strings.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"ලේඛන"</string>
-    <string name="title_open" msgid="4353228937663917801">"විවෘත වන්නේ"</string>
-    <string name="title_save" msgid="2433679664882857999">"සුරකින්නේ"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"ෆෝල්ඩරයක් සාදන්න"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"ජාල පෙනුම"</string>
-    <string name="menu_list" msgid="7279285939892417279">"ලැයිස්තු පෙනුම"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"අනුපිළිවෙලට සකසා ඇත්තේ"</string>
-    <string name="menu_search" msgid="3816712084502856974">"සෙවීම"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"සැකසීම්"</string>
-    <string name="menu_open" msgid="432922957274920903">"විවෘත කරන්න"</string>
-    <string name="menu_save" msgid="2394743337684426338">"සුරකින්න"</string>
-    <string name="menu_share" msgid="3075149983979628146">"බෙදාගන්න"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"මකන්න"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> ක් තෝරාගන්නා ලදි"</string>
-    <string name="sort_name" msgid="9183560467917256779">"නමින්"</string>
-    <string name="sort_date" msgid="586080032956151448">"වෙනස් කරන ලද දිනයෙන්"</string>
-    <string name="sort_size" msgid="3350681319735474741">"ප්‍රමාණය මගින්"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"මුල් පෙන්වන්න"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"මුල් සඟවන්න"</string>
-    <string name="save_error" msgid="6167009778003223664">"ලේඛනය සුරැකීමට අපොහොසත් විය"</string>
-    <string name="root_recent" msgid="4470053704320518133">"මෑත"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ඉතිරියි"</string>
-    <!-- no translation found for root_type_service (2178854894416775409) -->
-    <skip />
-    <string name="root_type_shortcut" msgid="3318760609471618093">"කෙටිමං"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"උපාංග"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"තවත් යෙදුම්"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"උසස් උපාංග දර්ශනය කරන්න"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"ගොනු ප්‍රමාණය දර්ශනය කරන්න"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"උපාංග ප්‍රමාණය දර්ශනය කරන්න"</string>
-    <string name="empty" msgid="7858882803708117596">"අයිතම නැත"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"ගොනුව විවෘත කළ නොහැක"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"සමහර ලේඛන මැකීමට නොහැකි විය"</string>
-    <string name="share_via" msgid="8966594246261344259">"හරහා බෙදාගන්න"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-sk/strings.xml b/packages/DocumentsUI/res/values-sk/strings.xml
deleted file mode 100644
index 2a96b1a..0000000
--- a/packages/DocumentsUI/res/values-sk/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenty"</string>
-    <string name="title_open" msgid="4353228937663917801">"Otvoriť z"</string>
-    <string name="title_save" msgid="2433679664882857999">"Uložiť do"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Vytvoriť priečinok"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Zobrazenie mriežky"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Zobrazenie zoznamu"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Zoradiť podľa"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Hľadať"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Nastavenia"</string>
-    <string name="menu_open" msgid="432922957274920903">"Otvoriť"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Uložiť"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Zdieľať"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Odstrániť"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Vybraté: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Podľa názvu"</string>
-    <string name="sort_date" msgid="586080032956151448">"Podľa dátumu zmeny"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Podľa veľkosti"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Zobraziť korene"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Skryť korene"</string>
-    <string name="save_error" msgid="6167009778003223664">"Dokument sa nepodarilo uložiť"</string>
-    <string name="create_error" msgid="3735649141335444215">"Priečinok sa nepodarilo vytvoriť"</string>
-    <string name="query_error" msgid="1222448261663503501">"Zoznam dokumentov sa nepodarilo načítať"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Nedávne"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Voľné: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Služby úložiska"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Skratky"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Zariadenia"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Ďalšie aplikácie"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Zobraziť rozšírené zariadenia"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Zobraziť veľkosť súboru"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Zobraziť veľkosť zariadenia"</string>
-    <string name="empty" msgid="7858882803708117596">"Žiadne položky"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Súbor sa nepodarilo otvoriť"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Niektoré dokumenty sa nepodarilo odstrániť"</string>
-    <string name="share_via" msgid="8966594246261344259">"Zdieľať pomocou"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-sl/strings.xml b/packages/DocumentsUI/res/values-sl/strings.xml
deleted file mode 100644
index f984a0a..0000000
--- a/packages/DocumentsUI/res/values-sl/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokumenti"</string>
-    <string name="title_open" msgid="4353228937663917801">"Odpiranje iz"</string>
-    <string name="title_save" msgid="2433679664882857999">"Shranjevanje v"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Ustvarjanje mape"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Mrežni pogled"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Pogled seznama"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Razvrsti glede na"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Iskanje"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Nastavitve"</string>
-    <string name="menu_open" msgid="432922957274920903">"Odpri"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Shrani"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Skupna raba"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Izbriši"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Št. izbranih: <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Po imenu"</string>
-    <string name="sort_date" msgid="586080032956151448">"Po datumu spremembe"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Po velikosti"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Pokaži korene"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Skrij korene"</string>
-    <string name="save_error" msgid="6167009778003223664">"Dokumenta ni bilo mogoče shraniti"</string>
-    <string name="create_error" msgid="3735649141335444215">"Mape ni bilo mogoče ustvariti"</string>
-    <string name="query_error" msgid="1222448261663503501">"Poizvedba za dokumente ni uspela"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Nedavno"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Prosto: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Storitve shrambe"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Bližnjice"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Naprave"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Več aplikacij"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Prikaz naprednih naprav"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Prikaz velikosti datoteke"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Prikaz velikosti naprave"</string>
-    <string name="empty" msgid="7858882803708117596">"Ni elementov"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Datoteke ni mogoče odpreti"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Nekaterih dokumentov ni mogoče izbrisati"</string>
-    <string name="share_via" msgid="8966594246261344259">"Deli z drugimi prek"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-sr/strings.xml b/packages/DocumentsUI/res/values-sr/strings.xml
deleted file mode 100644
index eb0b197..0000000
--- a/packages/DocumentsUI/res/values-sr/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Документи"</string>
-    <string name="title_open" msgid="4353228937663917801">"Отвори са"</string>
-    <string name="title_save" msgid="2433679664882857999">"Сачувај у"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Направи директоријум"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Приказ мреже"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Приказ листе"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Сортирај према"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Претражи"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Подешавања"</string>
-    <string name="menu_open" msgid="432922957274920903">"Отвори"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Сачувај"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Дели"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Избриши"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Изабрано је <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Према имену"</string>
-    <string name="sort_date" msgid="586080032956151448">"Према датуму измене"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Према величини"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Прикажи основне елементе"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Сакриј основне елементе"</string>
-    <string name="save_error" msgid="6167009778003223664">"Чување документа није успело"</string>
-    <string name="create_error" msgid="3735649141335444215">"Директоријум није направљен"</string>
-    <string name="query_error" msgid="1222448261663503501">"Слање упита за документе није успело"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Недавно"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"Слободно је <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Услуге складиштења"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Пречице"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Уређаји"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Још апликација"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Прикажи напредне уређаје"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Прикажи величину датотеке"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Прикажи величину уређаја"</string>
-    <string name="empty" msgid="7858882803708117596">"Нема ставки"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Није могуће отворити датотеку"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Није могуће избрисати неке документе"</string>
-    <string name="share_via" msgid="8966594246261344259">"Делите преко"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-sv/strings.xml b/packages/DocumentsUI/res/values-sv/strings.xml
deleted file mode 100644
index 7aa5c50..0000000
--- a/packages/DocumentsUI/res/values-sv/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokument"</string>
-    <string name="title_open" msgid="4353228937663917801">"Öppna från"</string>
-    <string name="title_save" msgid="2433679664882857999">"Spara till"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Skapa mapp"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Rutnätsvy"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Listvy"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sortera efter"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Sök"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Inställningar"</string>
-    <string name="menu_open" msgid="432922957274920903">"Öppna"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Spara"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Dela"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Ta bort"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Har valt <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Efter namn"</string>
-    <string name="sort_date" msgid="586080032956151448">"Efter ändringsdatum"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Efter storlek"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Visa rötter"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Dölj rötter"</string>
-    <string name="save_error" msgid="6167009778003223664">"Det gick inte att spara dokumentet"</string>
-    <string name="create_error" msgid="3735649141335444215">"Det gick inte att skapa mappen"</string>
-    <string name="query_error" msgid="1222448261663503501">"Det gick inte att söka efter dokument"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Senaste"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ledigt"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Lagringstjänster"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Genvägar"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Enheter"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Fler appar"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Visa avancerade enheter"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Visa filstorlek"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Bildskärmsstorlek"</string>
-    <string name="empty" msgid="7858882803708117596">"Inga objekt"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Det går inte att öppna filen"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Det gick inte att ta bort vissa dokument"</string>
-    <string name="share_via" msgid="8966594246261344259">"Dela via"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-sw/strings.xml b/packages/DocumentsUI/res/values-sw/strings.xml
deleted file mode 100644
index 299fda7..0000000
--- a/packages/DocumentsUI/res/values-sw/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Hati"</string>
-    <string name="title_open" msgid="4353228937663917801">"Fungua kutoka"</string>
-    <string name="title_save" msgid="2433679664882857999">"Hifadhi kwenye"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Unda folda"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Mwonekano gridi"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Mwonekano orodha"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Panga kwa"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Utafutaji"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Mipangilio"</string>
-    <string name="menu_open" msgid="432922957274920903">"Fungua"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Hifadhi"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Shiriki"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Futa"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> zimechaguliwa"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Kwa jina"</string>
-    <string name="sort_date" msgid="586080032956151448">"Kwa tarehe viliporekebishwa"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Kwa ukubwa"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Onyesha usuli"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ficha usuli"</string>
-    <string name="save_error" msgid="6167009778003223664">"Imeshindwa kuhifadhi hati"</string>
-    <string name="create_error" msgid="3735649141335444215">"Ilishindwa kuunda folda"</string>
-    <string name="query_error" msgid="1222448261663503501">"Ilishindwa kuhoji hati"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Hivi karibuni"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> bila malipo"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Huduma za hifadhi"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Njia za mkato"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Vifaa"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Programu zaidi"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Onyesha vifaa mahiri"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Onyesha ukubwa wa faili"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Onyesha ukubwa wa kifaa"</string>
-    <string name="empty" msgid="7858882803708117596">"Hakuna vipengee"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Haiwezi kufungua faili"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Imeshindwa kufuta baadhi ya hati"</string>
-    <string name="share_via" msgid="8966594246261344259">"Shiriki kupitia"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-th/strings.xml b/packages/DocumentsUI/res/values-th/strings.xml
deleted file mode 100644
index 6ac8810..0000000
--- a/packages/DocumentsUI/res/values-th/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"เอกสาร"</string>
-    <string name="title_open" msgid="4353228937663917801">"เปิดจาก"</string>
-    <string name="title_save" msgid="2433679664882857999">"บันทึกไปยัง"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"สร้างโฟลเดอร์"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"มุมมองตาราง"</string>
-    <string name="menu_list" msgid="7279285939892417279">"มุมมองรายการ"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"จัดเรียงตาม"</string>
-    <string name="menu_search" msgid="3816712084502856974">"ค้นหา"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"การตั้งค่า"</string>
-    <string name="menu_open" msgid="432922957274920903">"เปิด"</string>
-    <string name="menu_save" msgid="2394743337684426338">"บันทึก"</string>
-    <string name="menu_share" msgid="3075149983979628146">"แชร์"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"ลบ"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"เลือกไว้ <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"ตามชื่อ"</string>
-    <string name="sort_date" msgid="586080032956151448">"ตามวันที่ที่ปรับเปลี่ยน"</string>
-    <string name="sort_size" msgid="3350681319735474741">"ตามขนาด"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"แสดงราก"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"ซ่อนราก"</string>
-    <string name="save_error" msgid="6167009778003223664">"การบันทึกเอกสารล้มเหลว"</string>
-    <string name="create_error" msgid="3735649141335444215">"การสร้างโฟลเดอร์ล้มเหลว"</string>
-    <string name="query_error" msgid="1222448261663503501">"การค้นหาเอกสารล้มเหลว"</string>
-    <string name="root_recent" msgid="4470053704320518133">"ล่าสุด"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"ว่าง <xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"บริการที่เก็บข้อมูล"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"ทางลัด"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"อุปกรณ์"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"แอปเพิ่มเติม"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"แสดงอุปกรณ์ขั้นสูง"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"แสดงขนาดของไฟล์"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"แสดงขนาดของอุปกรณ์"</string>
-    <string name="empty" msgid="7858882803708117596">"ไม่มีรายการ"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"ไม่สามารถเปิดไฟล์ได้"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"ไม่สามารถลบเอกสารบางรายการ"</string>
-    <string name="share_via" msgid="8966594246261344259">"แชร์ผ่าน"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-tl/strings.xml b/packages/DocumentsUI/res/values-tl/strings.xml
deleted file mode 100644
index e0fd8c8..0000000
--- a/packages/DocumentsUI/res/values-tl/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Mga Dokumento"</string>
-    <string name="title_open" msgid="4353228937663917801">"Buksan mula sa"</string>
-    <string name="title_save" msgid="2433679664882857999">"I-save sa"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Gumawa ng folder"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"View ng grid"</string>
-    <string name="menu_list" msgid="7279285939892417279">"View ng listahan"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Pag-uri-uriin ayon sa"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Maghanap"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Mga Setting"</string>
-    <string name="menu_open" msgid="432922957274920903">"Buksan"</string>
-    <string name="menu_save" msgid="2394743337684426338">"I-save"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Ibahagi"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Tanggalin"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> ang pinili"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Ayon sa pangalan"</string>
-    <string name="sort_date" msgid="586080032956151448">"Ayon sa petsa ng pagbago"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Ayon sa laki"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Ipakita ang mga root"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Itago ang mga root"</string>
-    <string name="save_error" msgid="6167009778003223664">"Hindi na-save ang dokumento"</string>
-    <string name="create_error" msgid="3735649141335444215">"Hindi nagawa ang folder"</string>
-    <string name="query_error" msgid="1222448261663503501">"Hindi na-query ang mga dokumento"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Kamakailan"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> ang libre"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Mga serbisyo ng storage"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Mga Shortcut"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Mga Device"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Higit pang apps"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Ipakita ang mga advanced na device"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Ipakita ang laki ng file"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Ipakita ang laki ng device"</string>
-    <string name="empty" msgid="7858882803708117596">"Walang mga item"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Hindi mabuksan ang file"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Hindi matanggal ang ilang dokumento"</string>
-    <string name="share_via" msgid="8966594246261344259">"Ibahagi sa pamamagitan ng"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-tr/strings.xml b/packages/DocumentsUI/res/values-tr/strings.xml
deleted file mode 100644
index 699a5cd..0000000
--- a/packages/DocumentsUI/res/values-tr/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Dokümanlar"</string>
-    <string name="title_open" msgid="4353228937663917801">"Şuradan aç:"</string>
-    <string name="title_save" msgid="2433679664882857999">"Şuraya kaydet:"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Klasör oluştur"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Tablo görünümü"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Liste görünümü"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sıralama ölçütü"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Ara"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Ayarlar"</string>
-    <string name="menu_open" msgid="432922957274920903">"Aç"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Kaydet"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Paylaş"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Sil"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> tane seçildi"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Ada göre"</string>
-    <string name="sort_date" msgid="586080032956151448">"Değişiklik tarihine göre"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Boyuta göre"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Kökleri göster"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Kökleri sakla"</string>
-    <string name="save_error" msgid="6167009778003223664">"Doküman kaydedilemedi"</string>
-    <string name="create_error" msgid="3735649141335444215">"Klasör oluşturulamadı"</string>
-    <string name="query_error" msgid="1222448261663503501">"Dokümanlar sorgulanamadı"</string>
-    <string name="root_recent" msgid="4470053704320518133">"En son"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> boş"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Depolama hizmetleri"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Kısayollar"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Cihazlar"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Diğer uygulamalar"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Gelişmiş cihazları göster"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Dosya boyutunu göster"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Cihaz boyutunu göster"</string>
-    <string name="empty" msgid="7858882803708117596">"Öğe yok"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Dosya açılamıyor"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Bazı dokümanlar silinemiyor"</string>
-    <string name="share_via" msgid="8966594246261344259">"Şunu kullanarak paylaş:"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-uk/strings.xml b/packages/DocumentsUI/res/values-uk/strings.xml
deleted file mode 100644
index f87b6a2..0000000
--- a/packages/DocumentsUI/res/values-uk/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Документи"</string>
-    <string name="title_open" msgid="4353228937663917801">"Відкрити в"</string>
-    <string name="title_save" msgid="2433679664882857999">"Зберегти в"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Створити папку"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Режим таблиці"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Режим списку"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Параметри сортування"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Пошук"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Налаштування"</string>
-    <string name="menu_open" msgid="432922957274920903">"Відкрити"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Зберегти"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Поділитися"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Видалити"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Вибрано <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"За назвою"</string>
-    <string name="sort_date" msgid="586080032956151448">"За датою змінення"</string>
-    <string name="sort_size" msgid="3350681319735474741">"За розміром"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Показати кореневі каталоги"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Сховати кореневі каталоги"</string>
-    <string name="save_error" msgid="6167009778003223664">"Не вдалося зберегти документ"</string>
-    <string name="create_error" msgid="3735649141335444215">"Помилка створення папки"</string>
-    <string name="query_error" msgid="1222448261663503501">"Помилка надсилання запиту на документи"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Останні"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> вільного місця"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Онлайн-сховища"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Ярлики"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Пристрої"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Інші програми"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Показати покращені пристрої"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Показати розмір файлу"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Показати розмір пристрою"</string>
-    <string name="empty" msgid="7858882803708117596">"Немає елементів"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Не вдалося відкрити файл"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Не вдалося видалити деякі документи"</string>
-    <string name="share_via" msgid="8966594246261344259">"Надіслати через"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-vi/strings.xml b/packages/DocumentsUI/res/values-vi/strings.xml
deleted file mode 100644
index 41e29fa..0000000
--- a/packages/DocumentsUI/res/values-vi/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Tài liệu"</string>
-    <string name="title_open" msgid="4353228937663917801">"Mở từ"</string>
-    <string name="title_save" msgid="2433679664882857999">"Lưu vào"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Tạo thư mục"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Chế độ xem lưới"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Chế độ xem danh sách"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Sắp xếp theo"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Tìm kiếm"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Cài đặt"</string>
-    <string name="menu_open" msgid="432922957274920903">"Mở"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Lưu"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Chia sẻ"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Xóa"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"Đã chọn <xliff:g id="COUNT">%1$d</xliff:g>"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Theo tên"</string>
-    <string name="sort_date" msgid="586080032956151448">"Theo ngày sửa đổi"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Theo kích thước"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Hiển thị gốc"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Ẩn gốc"</string>
-    <string name="save_error" msgid="6167009778003223664">"Không lưu tài liệu được"</string>
-    <string name="create_error" msgid="3735649141335444215">"Không thể tạo thư mục"</string>
-    <string name="query_error" msgid="1222448261663503501">"Không truy vấn được tài liệu"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Gần đây"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> còn trống"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Dịch vụ lưu trữ"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Lối tắt"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Thiết bị"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Các ứng dụng khác"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Hiển thị các thiết bị nâng cao"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Hiển thị kích thước tệp"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Hiển thị kích thước thiết bị"</string>
-    <string name="empty" msgid="7858882803708117596">"Không có mục nào"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Không thể mở tệp"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Không thể xóa một số tài liệu"</string>
-    <string name="share_via" msgid="8966594246261344259">"Chia sẻ qua"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-zh-rCN/strings.xml b/packages/DocumentsUI/res/values-zh-rCN/strings.xml
deleted file mode 100644
index 742cda7..0000000
--- a/packages/DocumentsUI/res/values-zh-rCN/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"文档"</string>
-    <string name="title_open" msgid="4353228937663917801">"打开文件"</string>
-    <string name="title_save" msgid="2433679664882857999">"保存文件"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"新建文件夹"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"网格视图"</string>
-    <string name="menu_list" msgid="7279285939892417279">"列表视图"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"排序依据"</string>
-    <string name="menu_search" msgid="3816712084502856974">"搜索"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"设置"</string>
-    <string name="menu_open" msgid="432922957274920903">"打开"</string>
-    <string name="menu_save" msgid="2394743337684426338">"保存"</string>
-    <string name="menu_share" msgid="3075149983979628146">"分享"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"删除"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"已选择<xliff:g id="COUNT">%1$d</xliff:g>项"</string>
-    <string name="sort_name" msgid="9183560467917256779">"按名称"</string>
-    <string name="sort_date" msgid="586080032956151448">"按修改日期"</string>
-    <string name="sort_size" msgid="3350681319735474741">"按大小"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"显示根目录"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"隐藏根目录"</string>
-    <string name="save_error" msgid="6167009778003223664">"无法保存文档"</string>
-    <string name="create_error" msgid="3735649141335444215">"无法创建文件夹"</string>
-    <string name="query_error" msgid="1222448261663503501">"无法查询文档"</string>
-    <string name="root_recent" msgid="4470053704320518133">"最近"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"可用空间:<xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"存储服务"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"捷径"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"设备"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"更多应用"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"显示高级设备"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"显示文件大小"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"显示设备大小"</string>
-    <string name="empty" msgid="7858882803708117596">"无任何文件"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"无法打开文件"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"无法删除部分文档"</string>
-    <string name="share_via" msgid="8966594246261344259">"分享方式"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-zh-rHK/strings.xml b/packages/DocumentsUI/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 67ed587..0000000
--- a/packages/DocumentsUI/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"文件"</string>
-    <string name="title_open" msgid="4353228937663917801">"開啟自"</string>
-    <string name="title_save" msgid="2433679664882857999">"儲存至"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"建立資料夾"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"格狀檢視"</string>
-    <string name="menu_list" msgid="7279285939892417279">"清單檢視"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"排序方式"</string>
-    <string name="menu_search" msgid="3816712084502856974">"搜尋"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"設定"</string>
-    <string name="menu_open" msgid="432922957274920903">"開啟"</string>
-    <string name="menu_save" msgid="2394743337684426338">"儲存"</string>
-    <string name="menu_share" msgid="3075149983979628146">"分享"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"刪除"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"已選取 <xliff:g id="COUNT">%1$d</xliff:g> 個"</string>
-    <string name="sort_name" msgid="9183560467917256779">"按名稱"</string>
-    <string name="sort_date" msgid="586080032956151448">"按修改日期"</string>
-    <string name="sort_size" msgid="3350681319735474741">"按大小"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"顯示根目錄"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"隱藏根目錄"</string>
-    <string name="save_error" msgid="6167009778003223664">"無法儲存文件"</string>
-    <string name="create_error" msgid="3735649141335444215">"無法建立資料夾"</string>
-    <string name="query_error" msgid="1222448261663503501">"無法查詢文件"</string>
-    <string name="root_recent" msgid="4470053704320518133">"近期用過"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"可用空間:<xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"儲存空間服務"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"捷徑"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"裝置"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"更多應用程式"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"顯示進階裝置"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"顯示檔案大小"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"顯示裝置大小"</string>
-    <string name="empty" msgid="7858882803708117596">"沒有項目"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"無法開啟檔案"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"無法刪除部分文件"</string>
-    <string name="share_via" msgid="8966594246261344259">"分享方式:"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-zh-rTW/strings.xml b/packages/DocumentsUI/res/values-zh-rTW/strings.xml
deleted file mode 100644
index 269583a..0000000
--- a/packages/DocumentsUI/res/values-zh-rTW/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"文件"</string>
-    <string name="title_open" msgid="4353228937663917801">"開啟工具"</string>
-    <string name="title_save" msgid="2433679664882857999">"儲存至"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"建立資料夾"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"格狀檢視"</string>
-    <string name="menu_list" msgid="7279285939892417279">"清單檢視"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"排序依據"</string>
-    <string name="menu_search" msgid="3816712084502856974">"搜尋"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"設定"</string>
-    <string name="menu_open" msgid="432922957274920903">"開啟"</string>
-    <string name="menu_save" msgid="2394743337684426338">"儲存"</string>
-    <string name="menu_share" msgid="3075149983979628146">"共用"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"刪除"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"已選取 <xliff:g id="COUNT">%1$d</xliff:g> 個項目"</string>
-    <string name="sort_name" msgid="9183560467917256779">"依名稱"</string>
-    <string name="sort_date" msgid="586080032956151448">"依修改日期"</string>
-    <string name="sort_size" msgid="3350681319735474741">"依大小"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"顯示根目錄"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"隱藏根目錄"</string>
-    <string name="save_error" msgid="6167009778003223664">"無法儲存文件"</string>
-    <string name="create_error" msgid="3735649141335444215">"無法建立資料夾"</string>
-    <string name="query_error" msgid="1222448261663503501">"無法查詢文件"</string>
-    <string name="root_recent" msgid="4470053704320518133">"最近使用過的項目"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"可用空間:<xliff:g id="SIZE">%1$s</xliff:g>"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"儲存空間服務"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"捷徑"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"裝置"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"更多應用程式"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"顯示進階裝置"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"顯示檔案大小"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"顯示裝置大小"</string>
-    <string name="empty" msgid="7858882803708117596">"沒有項目"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"無法開啟檔案"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"無法刪除部分文件"</string>
-    <string name="share_via" msgid="8966594246261344259">"分享方式:"</string>
-</resources>
diff --git a/packages/DocumentsUI/res/values-zu/strings.xml b/packages/DocumentsUI/res/values-zu/strings.xml
deleted file mode 100644
index bedd2cdf..0000000
--- a/packages/DocumentsUI/res/values-zu/strings.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="2783841764617238354">"Amadokhumenti"</string>
-    <string name="title_open" msgid="4353228937663917801">"Vula kusuka ku-"</string>
-    <string name="title_save" msgid="2433679664882857999">"Londoloza ku-"</string>
-    <string name="menu_create_dir" msgid="5947289605844398389">"Dala ifolda"</string>
-    <string name="menu_grid" msgid="6878021334497835259">"Ukubuka kwegridi"</string>
-    <string name="menu_list" msgid="7279285939892417279">"Ukubuka uhlu"</string>
-    <string name="menu_sort" msgid="7677740407158414452">"Hlunga nge-"</string>
-    <string name="menu_search" msgid="3816712084502856974">"Sesha"</string>
-    <string name="menu_settings" msgid="6008033148948428823">"Izilungiselelo"</string>
-    <string name="menu_open" msgid="432922957274920903">"Vula"</string>
-    <string name="menu_save" msgid="2394743337684426338">"Londoloza"</string>
-    <string name="menu_share" msgid="3075149983979628146">"Yabelana"</string>
-    <string name="menu_delete" msgid="8138799623850614177">"Susa"</string>
-    <string name="mode_selected_count" msgid="459111894725594625">"<xliff:g id="COUNT">%1$d</xliff:g> okukhethiwe"</string>
-    <string name="sort_name" msgid="9183560467917256779">"Ngegama"</string>
-    <string name="sort_date" msgid="586080032956151448">"Ngedethi yokuguqula"</string>
-    <string name="sort_size" msgid="3350681319735474741">"Ngosayizi"</string>
-    <string name="drawer_open" msgid="4545466532430226949">"Bonisa izimpande"</string>
-    <string name="drawer_close" msgid="7602734368552123318">"Fihla izimpande"</string>
-    <string name="save_error" msgid="6167009778003223664">"Yehlulekile ukulondoloza idokhumenti"</string>
-    <string name="create_error" msgid="3735649141335444215">"Yehlulekile ukudala ifolda"</string>
-    <string name="query_error" msgid="1222448261663503501">"Ihlulekile ukubuza amadokhumenti"</string>
-    <string name="root_recent" msgid="4470053704320518133">"Okwakamuva"</string>
-    <string name="root_available_bytes" msgid="8568452858617033281">"<xliff:g id="SIZE">%1$s</xliff:g> okhululekile"</string>
-    <string name="root_type_service" msgid="2178854894416775409">"Amasevisi wesitoreji"</string>
-    <string name="root_type_shortcut" msgid="3318760609471618093">"Izinqamuleli"</string>
-    <string name="root_type_device" msgid="7121342474653483538">"Amadivayisi"</string>
-    <string name="root_type_apps" msgid="8838065367985945189">"Izinhlelo zokusebenza eziningi"</string>
-    <string name="pref_advanced_devices" msgid="903257239609301276">"Bonisa amadivayisi aphakeme"</string>
-    <string name="pref_file_size" msgid="2826879315743961459">"Bonisa usayizi wefayela"</string>
-    <string name="pref_device_size" msgid="3542106883278997222">"Bonisa usayizi wedivayisi"</string>
-    <string name="empty" msgid="7858882803708117596">"Azikho izinto"</string>
-    <string name="toast_no_application" msgid="1339885974067891667">"Ayikwazi ukuvula ifayela"</string>
-    <string name="toast_failed_delete" msgid="2180678019407244069">"Ayikwazi ukususa amanye amadokhumenti"</string>
-    <string name="share_via" msgid="8966594246261344259">"Yabelana nge-"</string>
-</resources>
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
index f6b43c7..f1dca1d 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java
@@ -40,7 +40,6 @@
 import com.android.documentsui.model.RootInfo;
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.Objects;
 import com.google.android.collect.Lists;
 import com.google.android.collect.Sets;
 import com.google.common.collect.ArrayListMultimap;
@@ -51,6 +50,7 @@
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -295,7 +295,7 @@
 
     private RootInfo getRootLocked(String authority, String rootId) {
         for (RootInfo root : mRoots.get(authority)) {
-            if (Objects.equal(root.rootId, rootId)) {
+            if (Objects.equals(root.rootId, rootId)) {
                 return root;
             }
         }
@@ -308,7 +308,7 @@
         synchronized (mLock) {
             final int rootIcon = root.derivedIcon != 0 ? root.derivedIcon : root.icon;
             for (RootInfo test : mRoots.get(root.authority)) {
-                if (Objects.equal(test.rootId, root.rootId)) {
+                if (Objects.equals(test.rootId, root.rootId)) {
                     continue;
                 }
                 final int testIcon = test.derivedIcon != 0 ? test.derivedIcon : test.icon;
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java b/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java
index 931dac9..923c79c 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RootsFragment.java
@@ -46,13 +46,13 @@
 import com.android.documentsui.DocumentsActivity.State;
 import com.android.documentsui.model.DocumentInfo;
 import com.android.documentsui.model.RootInfo;
-import com.android.internal.util.Objects;
 import com.google.common.collect.Lists;
 
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * Display list of known storage backend roots.
@@ -157,7 +157,7 @@
             final Object item = mAdapter.getItem(i);
             if (item instanceof RootItem) {
                 final RootInfo testRoot = ((RootItem) item).root;
-                if (Objects.equal(testRoot, root)) {
+                if (Objects.equals(testRoot, root)) {
                     mList.setItemChecked(i, true);
                     return;
                 }
diff --git a/packages/ExternalStorageProvider/res/values-af/strings.xml b/packages/ExternalStorageProvider/res/values-af/strings.xml
deleted file mode 100644
index 1de881d..0000000
--- a/packages/ExternalStorageProvider/res/values-af/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Eksterne berging"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Interne berging"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumente"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-am/strings.xml b/packages/ExternalStorageProvider/res/values-am/strings.xml
deleted file mode 100644
index 230fb06..0000000
--- a/packages/ExternalStorageProvider/res/values-am/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"ውጫዊ ማከማቻ"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"ውስጣዊ ማከማቻ"</string>
-    <string name="root_documents" msgid="4051252304075469250">"ሰነዶች"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ar/strings.xml b/packages/ExternalStorageProvider/res/values-ar/strings.xml
deleted file mode 100644
index b20a056..0000000
--- a/packages/ExternalStorageProvider/res/values-ar/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"وحدة تخزين خارجية"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"وحدة تخزين داخلية"</string>
-    <string name="root_documents" msgid="4051252304075469250">"مستندات"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-az/strings.xml b/packages/ExternalStorageProvider/res/values-az/strings.xml
deleted file mode 100644
index a6a79ca8..0000000
--- a/packages/ExternalStorageProvider/res/values-az/strings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Xarici Yaddaş"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Daxili yaddaş"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-bg/strings.xml b/packages/ExternalStorageProvider/res/values-bg/strings.xml
deleted file mode 100644
index f5dce31..0000000
--- a/packages/ExternalStorageProvider/res/values-bg/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Външно хранилище"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Вътрешно хранилище"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Документи"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ca/strings.xml b/packages/ExternalStorageProvider/res/values-ca/strings.xml
deleted file mode 100644
index 15e9d46..0000000
--- a/packages/ExternalStorageProvider/res/values-ca/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Emmagatzematge extern"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Emmagatzematge intern"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documents"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-cs/strings.xml b/packages/ExternalStorageProvider/res/values-cs/strings.xml
deleted file mode 100644
index b68a928..0000000
--- a/packages/ExternalStorageProvider/res/values-cs/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Externí úložiště"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Interní úložiště"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenty"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-da/strings.xml b/packages/ExternalStorageProvider/res/values-da/strings.xml
deleted file mode 100644
index a9ecb69..0000000
--- a/packages/ExternalStorageProvider/res/values-da/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Ekstern lagring"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Intern lagring"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenter"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-de/strings.xml b/packages/ExternalStorageProvider/res/values-de/strings.xml
deleted file mode 100644
index 318634a..0000000
--- a/packages/ExternalStorageProvider/res/values-de/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Externer Speicher"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Interner Speicher"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumente"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-el/strings.xml b/packages/ExternalStorageProvider/res/values-el/strings.xml
deleted file mode 100644
index b3aa792..0000000
--- a/packages/ExternalStorageProvider/res/values-el/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Εξωτερικός αποθηκευτικός χώρος"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Εσωτερικός αποθηκευτικός χώρος"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Έγγραφα"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-en-rGB/strings.xml b/packages/ExternalStorageProvider/res/values-en-rGB/strings.xml
deleted file mode 100644
index f88eb9e..0000000
--- a/packages/ExternalStorageProvider/res/values-en-rGB/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"External Storage"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Internal storage"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documents"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-en-rIN/strings.xml b/packages/ExternalStorageProvider/res/values-en-rIN/strings.xml
deleted file mode 100644
index f88eb9e..0000000
--- a/packages/ExternalStorageProvider/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"External Storage"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Internal storage"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documents"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-es-rUS/strings.xml b/packages/ExternalStorageProvider/res/values-es-rUS/strings.xml
deleted file mode 100644
index e7e38b5..0000000
--- a/packages/ExternalStorageProvider/res/values-es-rUS/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Almacenamiento externo"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Almacenamiento interno"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documentos"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-es/strings.xml b/packages/ExternalStorageProvider/res/values-es/strings.xml
deleted file mode 100644
index e7e38b5..0000000
--- a/packages/ExternalStorageProvider/res/values-es/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Almacenamiento externo"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Almacenamiento interno"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documentos"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-et-rEE/strings.xml b/packages/ExternalStorageProvider/res/values-et-rEE/strings.xml
deleted file mode 100644
index 6824e9d..0000000
--- a/packages/ExternalStorageProvider/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Väline talletusruum"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Sisemine salvestusruum"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumendid"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-fa/strings.xml b/packages/ExternalStorageProvider/res/values-fa/strings.xml
deleted file mode 100644
index 8471fc7..0000000
--- a/packages/ExternalStorageProvider/res/values-fa/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"فضای ذخیره خارجی"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"حافظهٔ داخلی"</string>
-    <string name="root_documents" msgid="4051252304075469250">"اسناد"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-fi/strings.xml b/packages/ExternalStorageProvider/res/values-fi/strings.xml
deleted file mode 100644
index 9d1fbaa..0000000
--- a/packages/ExternalStorageProvider/res/values-fi/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Ulkoinen tallennustila"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Sisäinen tallennustila"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumentit"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-fr-rCA/strings.xml b/packages/ExternalStorageProvider/res/values-fr-rCA/strings.xml
deleted file mode 100644
index b3fdd48..0000000
--- a/packages/ExternalStorageProvider/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Stockage externe"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Mémoire de stockage interne"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documents"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-fr/strings.xml b/packages/ExternalStorageProvider/res/values-fr/strings.xml
deleted file mode 100644
index b3fdd48..0000000
--- a/packages/ExternalStorageProvider/res/values-fr/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Stockage externe"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Mémoire de stockage interne"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documents"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-hi/strings.xml b/packages/ExternalStorageProvider/res/values-hi/strings.xml
deleted file mode 100644
index 1227bd4..0000000
--- a/packages/ExternalStorageProvider/res/values-hi/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"बाहरी संग्रहण"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"मोबाइल संग्रहण"</string>
-    <string name="root_documents" msgid="4051252304075469250">"दस्तावेज़"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-hr/strings.xml b/packages/ExternalStorageProvider/res/values-hr/strings.xml
deleted file mode 100644
index a74f8e8..0000000
--- a/packages/ExternalStorageProvider/res/values-hr/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Vanjska pohrana"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Unutarnja pohrana"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenti"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-hu/strings.xml b/packages/ExternalStorageProvider/res/values-hu/strings.xml
deleted file mode 100644
index 3f72b41..0000000
--- a/packages/ExternalStorageProvider/res/values-hu/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Külső tárhely"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Belső tárhely"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumentumok"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-hy-rAM/strings.xml b/packages/ExternalStorageProvider/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 5360124..0000000
--- a/packages/ExternalStorageProvider/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Արտաքին պահոց"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Ներքին պահոց"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Փաստաթղթեր"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-in/strings.xml b/packages/ExternalStorageProvider/res/values-in/strings.xml
deleted file mode 100644
index 42acde7..0000000
--- a/packages/ExternalStorageProvider/res/values-in/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Penyimpanan Eksternal"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Penyimpanan internal"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumen"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-it/strings.xml b/packages/ExternalStorageProvider/res/values-it/strings.xml
deleted file mode 100644
index 957b5ff..0000000
--- a/packages/ExternalStorageProvider/res/values-it/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Archivio esterno"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Memoria interna"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documenti"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-iw/strings.xml b/packages/ExternalStorageProvider/res/values-iw/strings.xml
deleted file mode 100644
index 775506a..0000000
--- a/packages/ExternalStorageProvider/res/values-iw/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"אחסון חיצוני"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"אחסון פנימי"</string>
-    <string name="root_documents" msgid="4051252304075469250">"מסמכים"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ja/strings.xml b/packages/ExternalStorageProvider/res/values-ja/strings.xml
deleted file mode 100644
index 188fca2..0000000
--- a/packages/ExternalStorageProvider/res/values-ja/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"外部ストレージ"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"内部ストレージ"</string>
-    <string name="root_documents" msgid="4051252304075469250">"ドキュメント"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ka-rGE/strings.xml b/packages/ExternalStorageProvider/res/values-ka-rGE/strings.xml
deleted file mode 100644
index cc04860..0000000
--- a/packages/ExternalStorageProvider/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"გარე მეხსიერება"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"შიდა მეხსიერება"</string>
-    <string name="root_documents" msgid="4051252304075469250">"დოკუმენტები"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-km-rKH/strings.xml b/packages/ExternalStorageProvider/res/values-km-rKH/strings.xml
deleted file mode 100644
index 9cf76d4..0000000
--- a/packages/ExternalStorageProvider/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"ឧបករណ៍​​ផ្ទុក​ខាងក្រៅ"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"ឧបករណ៍​ផ្ទុក​ខាង​ក្នុង"</string>
-    <string name="root_documents" msgid="4051252304075469250">"ឯកសារ"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ko/strings.xml b/packages/ExternalStorageProvider/res/values-ko/strings.xml
deleted file mode 100644
index 849d37e..0000000
--- a/packages/ExternalStorageProvider/res/values-ko/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"외부 저장소"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"내부 저장소"</string>
-    <string name="root_documents" msgid="4051252304075469250">"문서"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-lo-rLA/strings.xml b/packages/ExternalStorageProvider/res/values-lo-rLA/strings.xml
deleted file mode 100644
index cecd9f5..0000000
--- a/packages/ExternalStorageProvider/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"ບ່ອນຈັດເກັບຂໍ້ມູນພາຍນອກ"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"ບ່ອນຈັດເກັບຂໍ້ມູນພາຍໃນ"</string>
-    <string name="root_documents" msgid="4051252304075469250">"ເອ​ກະ​ສານ"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-lt/strings.xml b/packages/ExternalStorageProvider/res/values-lt/strings.xml
deleted file mode 100644
index 240ea89..0000000
--- a/packages/ExternalStorageProvider/res/values-lt/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Išorinė atmintinė"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Vidinė atmintinė"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumentai"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-lv/strings.xml b/packages/ExternalStorageProvider/res/values-lv/strings.xml
deleted file mode 100644
index d308fe8..0000000
--- a/packages/ExternalStorageProvider/res/values-lv/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Ārējā krātuve"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Iekšējā atmiņa"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenti"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-mn-rMN/strings.xml b/packages/ExternalStorageProvider/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 3d7b7f7..0000000
--- a/packages/ExternalStorageProvider/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Гадаад сан"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Дотоод сан"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Документүүд"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-mn/strings.xml b/packages/ExternalStorageProvider/res/values-mn/strings.xml
deleted file mode 100644
index 0193cdb..0000000
--- a/packages/ExternalStorageProvider/res/values-mn/strings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Гадаад сан"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Дотоод сан"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ms-rMY/strings.xml b/packages/ExternalStorageProvider/res/values-ms-rMY/strings.xml
deleted file mode 100644
index cb4d736..0000000
--- a/packages/ExternalStorageProvider/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Storan Luaran"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Storan dalaman"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumen"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-nb/strings.xml b/packages/ExternalStorageProvider/res/values-nb/strings.xml
deleted file mode 100644
index a9ecb69..0000000
--- a/packages/ExternalStorageProvider/res/values-nb/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Ekstern lagring"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Intern lagring"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenter"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ne-rNP/strings.xml b/packages/ExternalStorageProvider/res/values-ne-rNP/strings.xml
deleted file mode 100644
index 8a9454e..0000000
--- a/packages/ExternalStorageProvider/res/values-ne-rNP/strings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"बाह्य भण्डारण"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"आन्तरिक भण्डारण"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-nl/strings.xml b/packages/ExternalStorageProvider/res/values-nl/strings.xml
deleted file mode 100644
index bde6166..0000000
--- a/packages/ExternalStorageProvider/res/values-nl/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Externe opslag"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Interne opslag"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documenten"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-pl/strings.xml b/packages/ExternalStorageProvider/res/values-pl/strings.xml
deleted file mode 100644
index 6c5e7d7..0000000
--- a/packages/ExternalStorageProvider/res/values-pl/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Pamięć zewnętrzna"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Pamięć wewnętrzna"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenty"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-pt-rPT/strings.xml b/packages/ExternalStorageProvider/res/values-pt-rPT/strings.xml
deleted file mode 100644
index 77c89b8..0000000
--- a/packages/ExternalStorageProvider/res/values-pt-rPT/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Armazenamento externo"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Armazenamento interno"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documentos"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-pt/strings.xml b/packages/ExternalStorageProvider/res/values-pt/strings.xml
deleted file mode 100644
index 77c89b8..0000000
--- a/packages/ExternalStorageProvider/res/values-pt/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Armazenamento externo"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Armazenamento interno"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documentos"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ro/strings.xml b/packages/ExternalStorageProvider/res/values-ro/strings.xml
deleted file mode 100644
index abd0b98..0000000
--- a/packages/ExternalStorageProvider/res/values-ro/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Stocare externă"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Stocare internă"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Documente"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-ru/strings.xml b/packages/ExternalStorageProvider/res/values-ru/strings.xml
deleted file mode 100644
index b6c10951..0000000
--- a/packages/ExternalStorageProvider/res/values-ru/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Внешний накопитель"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Внутренняя память"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Документы"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-si-rLK/strings.xml b/packages/ExternalStorageProvider/res/values-si-rLK/strings.xml
deleted file mode 100644
index de3f3e8..0000000
--- a/packages/ExternalStorageProvider/res/values-si-rLK/strings.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"බාහිර ආචයනය"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"අභ්‍යන්තර ආචයනය"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-sk/strings.xml b/packages/ExternalStorageProvider/res/values-sk/strings.xml
deleted file mode 100644
index fd424c8..0000000
--- a/packages/ExternalStorageProvider/res/values-sk/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Externý ukladací priestor"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Interný ukladací priestor"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenty"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-sl/strings.xml b/packages/ExternalStorageProvider/res/values-sl/strings.xml
deleted file mode 100644
index 6ffa698..0000000
--- a/packages/ExternalStorageProvider/res/values-sl/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Zunanja shramba"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Notranja shramba"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokumenti"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-sr/strings.xml b/packages/ExternalStorageProvider/res/values-sr/strings.xml
deleted file mode 100644
index 54238a4..0000000
--- a/packages/ExternalStorageProvider/res/values-sr/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Спољна меморија"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Интерна меморија"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Документи"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-sv/strings.xml b/packages/ExternalStorageProvider/res/values-sv/strings.xml
deleted file mode 100644
index 6eac11e..0000000
--- a/packages/ExternalStorageProvider/res/values-sv/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Extern lagring"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Intern lagring"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokument"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-sw/strings.xml b/packages/ExternalStorageProvider/res/values-sw/strings.xml
deleted file mode 100644
index 0d0e483..0000000
--- a/packages/ExternalStorageProvider/res/values-sw/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Hifadhi ya Nje"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Hifadhi ya ndani"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Hati"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-th/strings.xml b/packages/ExternalStorageProvider/res/values-th/strings.xml
deleted file mode 100644
index 796635e..0000000
--- a/packages/ExternalStorageProvider/res/values-th/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"ที่จัดเก็บข้อมูลภายนอก"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"ที่จัดเก็บข้อมูลภายใน"</string>
-    <string name="root_documents" msgid="4051252304075469250">"เอกสาร"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-tl/strings.xml b/packages/ExternalStorageProvider/res/values-tl/strings.xml
deleted file mode 100644
index 529cdc2..0000000
--- a/packages/ExternalStorageProvider/res/values-tl/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"External Storage"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Internal storage"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Mga Dokumento"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-tr/strings.xml b/packages/ExternalStorageProvider/res/values-tr/strings.xml
deleted file mode 100644
index d6bd52a..0000000
--- a/packages/ExternalStorageProvider/res/values-tr/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Harici Depolama"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Dahili depolama"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Dokümanlar"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-uk/strings.xml b/packages/ExternalStorageProvider/res/values-uk/strings.xml
deleted file mode 100644
index b8206e0..0000000
--- a/packages/ExternalStorageProvider/res/values-uk/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Зовнішня пам’ять"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Внутрішня пам’ять"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Документи"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-vi/strings.xml b/packages/ExternalStorageProvider/res/values-vi/strings.xml
deleted file mode 100644
index b171c93..0000000
--- a/packages/ExternalStorageProvider/res/values-vi/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Bộ nhớ ngoài"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Bộ nhớ trong"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Tài liệu"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-zh-rCN/strings.xml b/packages/ExternalStorageProvider/res/values-zh-rCN/strings.xml
deleted file mode 100644
index 7df77dd..0000000
--- a/packages/ExternalStorageProvider/res/values-zh-rCN/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"外部存储设备"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"内部存储空间"</string>
-    <string name="root_documents" msgid="4051252304075469250">"文档"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-zh-rHK/strings.xml b/packages/ExternalStorageProvider/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 62d8afb..0000000
--- a/packages/ExternalStorageProvider/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"外部儲存空間"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"內部儲存空間"</string>
-    <string name="root_documents" msgid="4051252304075469250">"文件"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-zh-rTW/strings.xml b/packages/ExternalStorageProvider/res/values-zh-rTW/strings.xml
deleted file mode 100644
index 62d8afb..0000000
--- a/packages/ExternalStorageProvider/res/values-zh-rTW/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"外部儲存空間"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"內部儲存空間"</string>
-    <string name="root_documents" msgid="4051252304075469250">"文件"</string>
-</resources>
diff --git a/packages/ExternalStorageProvider/res/values-zu/strings.xml b/packages/ExternalStorageProvider/res/values-zu/strings.xml
deleted file mode 100644
index 4a0a845..0000000
--- a/packages/ExternalStorageProvider/res/values-zu/strings.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7123375275748530234">"Isitoreji sangaphandle"</string>
-    <string name="root_internal_storage" msgid="827844243068584127">"Isitoreji sangaphakathi"</string>
-    <string name="root_documents" msgid="4051252304075469250">"Amadokhumenti"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-af/strings.xml b/packages/FusedLocation/res/values-af/strings.xml
deleted file mode 100644
index a321abe..0000000
--- a/packages/FusedLocation/res/values-af/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Saamgesmelte ligging"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-am/strings.xml b/packages/FusedLocation/res/values-am/strings.xml
deleted file mode 100644
index 9c4d9d5..0000000
--- a/packages/FusedLocation/res/values-am/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"ፍዩዥን አካባቢ"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ar/strings.xml b/packages/FusedLocation/res/values-ar/strings.xml
deleted file mode 100644
index dfbcf7a..0000000
--- a/packages/FusedLocation/res/values-ar/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"الموقع المدمج"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-bg/strings.xml b/packages/FusedLocation/res/values-bg/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-bg/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ca/strings.xml b/packages/FusedLocation/res/values-ca/strings.xml
deleted file mode 100644
index bdd55dd..0000000
--- a/packages/FusedLocation/res/values-ca/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Ubicació unificada"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-cs/strings.xml b/packages/FusedLocation/res/values-cs/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-cs/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-da/strings.xml b/packages/FusedLocation/res/values-da/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-da/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-de/strings.xml b/packages/FusedLocation/res/values-de/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-de/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-el/strings.xml b/packages/FusedLocation/res/values-el/strings.xml
deleted file mode 100644
index 1243b21..0000000
--- a/packages/FusedLocation/res/values-el/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Ενοποιημένη τοποθεσία"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-en-rGB/strings.xml b/packages/FusedLocation/res/values-en-rGB/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-en-rGB/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-en-rIN/strings.xml b/packages/FusedLocation/res/values-en-rIN/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-es-rUS/strings.xml b/packages/FusedLocation/res/values-es-rUS/strings.xml
deleted file mode 100644
index ec95314..0000000
--- a/packages/FusedLocation/res/values-es-rUS/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Ubicación combinada"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-es/strings.xml b/packages/FusedLocation/res/values-es/strings.xml
deleted file mode 100644
index ec95314..0000000
--- a/packages/FusedLocation/res/values-es/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Ubicación combinada"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-et-rEE/strings.xml b/packages/FusedLocation/res/values-et-rEE/strings.xml
deleted file mode 100644
index fcf4ef7..0000000
--- a/packages/FusedLocation/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Liidetud asukoht"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-fa/strings.xml b/packages/FusedLocation/res/values-fa/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-fa/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-fi/strings.xml b/packages/FusedLocation/res/values-fi/strings.xml
deleted file mode 100644
index 2d308b3..0000000
--- a/packages/FusedLocation/res/values-fi/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Yhdistetty sijainti"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-fr-rCA/strings.xml b/packages/FusedLocation/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-fr/strings.xml b/packages/FusedLocation/res/values-fr/strings.xml
deleted file mode 100644
index 8604c39..0000000
--- a/packages/FusedLocation/res/values-fr/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Localisation via les tables de fusion"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-hi/strings.xml b/packages/FusedLocation/res/values-hi/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-hi/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-hr/strings.xml b/packages/FusedLocation/res/values-hr/strings.xml
deleted file mode 100644
index b2a2cc9..0000000
--- a/packages/FusedLocation/res/values-hr/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Lokacija iz kombiniranih izvora"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-hu/strings.xml b/packages/FusedLocation/res/values-hu/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-hu/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-hy-rAM/strings.xml b/packages/FusedLocation/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-in/strings.xml b/packages/FusedLocation/res/values-in/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-in/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-it/strings.xml b/packages/FusedLocation/res/values-it/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-it/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-iw/strings.xml b/packages/FusedLocation/res/values-iw/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-iw/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ja/strings.xml b/packages/FusedLocation/res/values-ja/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-ja/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ka-rGE/strings.xml b/packages/FusedLocation/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-km-rKH/strings.xml b/packages/FusedLocation/res/values-km-rKH/strings.xml
deleted file mode 100644
index 649e4f7..0000000
--- a/packages/FusedLocation/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"ភ្ជាប់​ទីតាំង"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ko/strings.xml b/packages/FusedLocation/res/values-ko/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-ko/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-lo-rLA/strings.xml b/packages/FusedLocation/res/values-lo-rLA/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-lt/strings.xml b/packages/FusedLocation/res/values-lt/strings.xml
deleted file mode 100644
index 245c0b0..0000000
--- a/packages/FusedLocation/res/values-lt/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Suderinta vietovė"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-lv/strings.xml b/packages/FusedLocation/res/values-lv/strings.xml
deleted file mode 100644
index 8c40cb2..0000000
--- a/packages/FusedLocation/res/values-lv/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Apvienota atrašanās vieta"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-mn-rMN/strings.xml b/packages/FusedLocation/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 8055ca8..0000000
--- a/packages/FusedLocation/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Нэгдмэл байршил"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ms-rMY/strings.xml b/packages/FusedLocation/res/values-ms-rMY/strings.xml
deleted file mode 100644
index d345cb8..0000000
--- a/packages/FusedLocation/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Lokasi Terlakur"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-nb/strings.xml b/packages/FusedLocation/res/values-nb/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-nb/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-nl/strings.xml b/packages/FusedLocation/res/values-nl/strings.xml
deleted file mode 100644
index b3003c8..0000000
--- a/packages/FusedLocation/res/values-nl/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Samengestelde locatie"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-pl/strings.xml b/packages/FusedLocation/res/values-pl/strings.xml
deleted file mode 100644
index b3a9e2a..0000000
--- a/packages/FusedLocation/res/values-pl/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Przybliżona lokalizacja"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-pt-rPT/strings.xml b/packages/FusedLocation/res/values-pt-rPT/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-pt-rPT/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-pt/strings.xml b/packages/FusedLocation/res/values-pt/strings.xml
deleted file mode 100644
index cf5f5bf..0000000
--- a/packages/FusedLocation/res/values-pt/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Localização fundida"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ro/strings.xml b/packages/FusedLocation/res/values-ro/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-ro/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-ru/strings.xml b/packages/FusedLocation/res/values-ru/strings.xml
deleted file mode 100644
index 40d9e6f..0000000
--- a/packages/FusedLocation/res/values-ru/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Геоданные из нескольких источников"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-sk/strings.xml b/packages/FusedLocation/res/values-sk/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-sk/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-sl/strings.xml b/packages/FusedLocation/res/values-sl/strings.xml
deleted file mode 100644
index 928c50b..0000000
--- a/packages/FusedLocation/res/values-sl/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Kombinirana lokacija"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-sr/strings.xml b/packages/FusedLocation/res/values-sr/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-sr/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-sv/strings.xml b/packages/FusedLocation/res/values-sv/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-sv/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-sw/strings.xml b/packages/FusedLocation/res/values-sw/strings.xml
deleted file mode 100644
index 60c235e..0000000
--- a/packages/FusedLocation/res/values-sw/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Eneo Hakika"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-th/strings.xml b/packages/FusedLocation/res/values-th/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-th/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-tl/strings.xml b/packages/FusedLocation/res/values-tl/strings.xml
deleted file mode 100644
index 94a2507..0000000
--- a/packages/FusedLocation/res/values-tl/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Naka-fuse na Lokasyon"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-tr/strings.xml b/packages/FusedLocation/res/values-tr/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-tr/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-uk/strings.xml b/packages/FusedLocation/res/values-uk/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-uk/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-vi/strings.xml b/packages/FusedLocation/res/values-vi/strings.xml
deleted file mode 100644
index e0e83a8..0000000
--- a/packages/FusedLocation/res/values-vi/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Vị trí được hợp nhất"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-zh-rCN/strings.xml b/packages/FusedLocation/res/values-zh-rCN/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-zh-rCN/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-zh-rHK/strings.xml b/packages/FusedLocation/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-zh-rTW/strings.xml b/packages/FusedLocation/res/values-zh-rTW/strings.xml
deleted file mode 100644
index 0d2cccc..0000000
--- a/packages/FusedLocation/res/values-zh-rTW/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Fused Location"</string>
-</resources>
diff --git a/packages/FusedLocation/res/values-zu/strings.xml b/packages/FusedLocation/res/values-zu/strings.xml
deleted file mode 100644
index 62d4359..0000000
--- a/packages/FusedLocation/res/values-zu/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="5379477904423203699">"Indawo ehlanganisiwe"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-af/strings.xml b/packages/InputDevices/res/values-af/strings.xml
deleted file mode 100644
index 748bae0..0000000
--- a/packages/InputDevices/res/values-af/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Invoertoestelle"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-sleutelbord"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Engels (VK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Engels (VS)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Engels (VS), internasionale styl"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Engels (VS), Colemak-styl"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Engels (VS), Dvorak-styl"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Duits"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Frans"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Frans (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russies"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russies, Mac-styl"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spaans"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Switserse Frans"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Switserse Duits"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgies"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgaars"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiaans"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Deens"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Noors"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Sweeds"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Fins"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroasies"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tsjeggies"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estnies"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hongaars"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Yslands"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasiliaans"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugees"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slowaaks"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Sloweens"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turks"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Oekraïens"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-am/strings.xml b/packages/InputDevices/res/values-am/strings.xml
deleted file mode 100644
index d4097f4..0000000
--- a/packages/InputDevices/res/values-am/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"የግቤት መሣሪያዎች"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"የAndroid የቁልፍ ሰሌዳ"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"እንግሊዝኛ (ዩኬ)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"እንግሊዘኛ (ዩ.ኤስ.)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"እንግሊዘኛ (ዩ. ኤስ.)፣ አለም አቀፍ ቅጥ"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"እንግሊዘኛ (ዩ. ኤስ.)፣ የኮልማርክ ቅጥ"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"እንግሊዘኛ (ዩ. ኤስ.)፣ የድቮራክ ቅጥ"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"ጀርመን"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"ፈረንሳይኛ"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"ፈረንሳይኛ (ካናዳ)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ሩስያኛ"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ሩስያኛ፣ Mac ቅጥ"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"ስፓኒሽ"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"የስዊዝ ፈረንሳይኛ"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"የስዊዝ ጀርመን"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"ቤልጂየምኛ"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"ቡልጋሪኛ"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"ጣሊያንኛ"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"ዴኒሽ"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"ኖርዌጂያን"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"ስዊድንኛ"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"ፊኒሽ"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"ክሮሽያንኛ"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"ቼክ"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"ኤስቶኒያኛ"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"ሀንጋሪያኛ"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"አይስላንድኛ"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"የብራዚል"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"ፖርቹጋልኛ"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"ስሎቫክኛ"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"ስሎቪኛ"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"ቱርክኛ"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ዩክረኒኛ"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ar/strings.xml b/packages/InputDevices/res/values-ar/strings.xml
deleted file mode 100644
index abf0967..0000000
--- a/packages/InputDevices/res/values-ar/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"أجهزة إدخال بيانات"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"لوحة مفاتيح Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"الإنجليزية (المملكة المتحدة)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"الإنجليزية (الولايات المتحدة)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"الإنجليزية (الولايات المتحدة)، النمط الدولي"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"الإنجليزية (الولايات المتحدة)، نمط Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"الإنجليزية (الولايات المتحدة)، نمط Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"الألمانية"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"الفرنسية"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"الفرنسية (كندا)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"الروسية"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"الروسية، نمط Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"الإسبانية"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"الفرنسية السويسرية"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"الألمانية السويسرية"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"البلجيكية"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"البلغارية"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"الإيطالية"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"الدانماركية"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"النرويجية"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"السويدية"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"الفنلندية"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"الكرواتية"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"التشيكية"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"الإستونية"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"المجرية"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"الأيسلندية"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"البرازيلية"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"البرتغالية"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"السلوفاكية"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"السلوفينية"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"التركية"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"الأوكرانية"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-bg/strings.xml b/packages/InputDevices/res/values-bg/strings.xml
deleted file mode 100644
index 0c413a4..0000000
--- a/packages/InputDevices/res/values-bg/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Входни устройства"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Клавиатура на Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"английски (Великобритания)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"английски (САЩ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"англ. (САЩ) – стил „Mеждународна“"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"английски (САЩ) – стил „Коулмак“"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"английски (САЩ) – стил „Дворак“"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"немски"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"френски"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"френски (Канада)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"руски"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"руски – стил „Mac“"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"испански"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"швейцарски френски"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"швейцарски немски"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"белгийски"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"български"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"италиански"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"датски"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"норвежки"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"шведски"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"финландски"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"хърватски"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"чешки"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"естонски"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"унгарски"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"исландски"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"португалски (Бразилия)"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"португалски"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"словашки"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"словенски"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"турски"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"украински"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ca/strings.xml b/packages/InputDevices/res/values-ca/strings.xml
deleted file mode 100644
index 2021b8f..0000000
--- a/packages/InputDevices/res/values-ca/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispositius d’entrada"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Teclat Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Anglès (RU)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Anglès (EUA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Anglès (EUA), estil internacional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Anglès (EUA), estil Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Anglès (EUA), estil Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Alemany"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francès"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francès (Canadà)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Rus"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Rus, estil Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Espanyol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francès suís"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Alemany suís"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Búlgar"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italià"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danès"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Noruec"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Suec"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finès"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croat"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Txec"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonià"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hongarès"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandès"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasiler"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portuguès"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Eslovac"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Eslovè"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turc"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucraïnès"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-cs/strings.xml b/packages/InputDevices/res/values-cs/strings.xml
deleted file mode 100644
index 33b420e..0000000
--- a/packages/InputDevices/res/values-cs/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Vstupní zařízení"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Klávesnice Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"anglické (Spojené království)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"anglické (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"anglické (USA), mezinárodní"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"anglické (USA), styl Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"anglické (USA), styl Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"německé"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"francouzské"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"francouzské (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ruské"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ruské, styl Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"španělské"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"švýcarské (francouzština)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"švýcarské (němčina)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"belgické"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"bulharské"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"italské"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"dánské"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"norské"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"švédské"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"finské"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"chorvatské"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"české"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"estonské"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"maďarské"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"islandské"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"brazilské"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"portugalské"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"slovenské"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"slovinské"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"turecké"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukrajinské"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-da/strings.xml b/packages/InputDevices/res/values-da/strings.xml
deleted file mode 100644
index 5eb30b17..0000000
--- a/packages/InputDevices/res/values-da/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Inputenheder"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-tastatur"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Engelsk (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Engelsk (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Engelsk (USA), international stil"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Engelsk (USA), Colemak-stil"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Engelsk (USA), Dvorak-stil"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Tysk"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Fransk"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Fransk (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russisk"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russisk, Mac-stil"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spansk"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"schweizisk fransk"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"schweizertysk"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgisk"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarsk"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiensk"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Dansk"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norsk"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Svensk"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finsk"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroatisk"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tjekkisk"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estisk"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungarsk"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandsk"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasiliansk"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugisisk"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovakisk"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovensk"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Tyrkisk"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukrainsk"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-de/strings.xml b/packages/InputDevices/res/values-de/strings.xml
deleted file mode 100644
index b5c3b50..0000000
--- a/packages/InputDevices/res/values-de/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Eingabegeräte"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-Tastatur"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Englisch (Großbritannien)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Englisch (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Englisch (USA), international"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Englisch (USA), Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Englisch (USA), Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Deutsch"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Französisch"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Französisch (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russisch"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russisch, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spanisch"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Schweizer Französisch"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Schweizerdeutsch"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgisch"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarisch"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italienisch"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Dänisch"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norwegisch"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Schwedisch"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finnisch"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroatisch"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tschechisch"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estnisch"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungarisch"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Isländisch"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasilianisch"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugiesisch"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slowakisch"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slowenisch"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Türkisch"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainisch"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-el/strings.xml b/packages/InputDevices/res/values-el/strings.xml
deleted file mode 100644
index bcf7b86..0000000
--- a/packages/InputDevices/res/values-el/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Συσκευές εισόδου"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Πληκτρολόγιο Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Αγγλικά (Η.Β.)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Αγγλικά (Η.Π.Α.)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Αγγλικά (Η.Π.Α.), τύπου International"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Αγγλικά (Η.Π.Α.), τύπου Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Αγγλικά (Η.Π.Α.), τύπου Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Γερμανικά"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Γαλλικά"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Γαλλικά (Καναδά)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Ρωσικά"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russian, τύπου Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Ισπανικά"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Γαλλικά Ελβετίας"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Γερμανικά Ελβετίας"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Βελγίου"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Βουλγαρικά"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Ιταλικά"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Δανικά"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Νορβηγικά"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Σουηδικά"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Φινλανδικά"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Κροατικά"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Τσεχικά"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Εσθονικά"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ουγγρικά"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Ισλανδικά"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Βραζιλίας"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Πορτογαλικά"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Σλοβακικά"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Σλοβενικά"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Τουρκικά"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ουκρανικά"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-en-rGB/strings.xml b/packages/InputDevices/res/values-en-rGB/strings.xml
deleted file mode 100644
index 2d794a6..0000000
--- a/packages/InputDevices/res/values-en-rGB/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Input Devices"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android keyboard"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"English (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"English (US)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"English (US), International style"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"English (US), Colemak style"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"English (US), Dvorak style"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"German"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"French"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"French (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russian"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russian, Mac style"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spanish"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Swiss French"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Swiss German"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgian"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarian"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italian"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danish"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norwegian"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Swedish"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finnish"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croatian"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Czech"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonian"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hungarian"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Icelandic"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazilian"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portuguese"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovak"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovenian"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turkish"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainian"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-en-rIN/strings.xml b/packages/InputDevices/res/values-en-rIN/strings.xml
deleted file mode 100644
index 2d794a6..0000000
--- a/packages/InputDevices/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Input Devices"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android keyboard"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"English (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"English (US)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"English (US), International style"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"English (US), Colemak style"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"English (US), Dvorak style"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"German"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"French"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"French (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russian"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russian, Mac style"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spanish"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Swiss French"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Swiss German"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgian"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarian"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italian"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danish"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norwegian"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Swedish"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finnish"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croatian"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Czech"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonian"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hungarian"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Icelandic"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazilian"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portuguese"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovak"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovenian"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turkish"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainian"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-es-rUS/strings.xml b/packages/InputDevices/res/values-es-rUS/strings.xml
deleted file mode 100644
index 2d61b80..0000000
--- a/packages/InputDevices/res/values-es-rUS/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispositivos de entrada"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Teclado de Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inglés (Reino Unido)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inglés (EE. UU.)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inglés (EE. UU.), internacional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inglés (EE. UU.), Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inglés (EE. UU.), Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Alemán"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francés"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francés (Canadá)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Ruso"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Ruso, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Español"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francés de Suiza"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Alemán de Suiza"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Búlgaro"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiano"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danés"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Noruego"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Sueco"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandés"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croata"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Checo"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonio"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Húngaro"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandés"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasileño"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugués"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Eslovaco"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Esloveno"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turco"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucraniano"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-es/strings.xml b/packages/InputDevices/res/values-es/strings.xml
deleted file mode 100644
index 82ea4d6..0000000
--- a/packages/InputDevices/res/values-es/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispositivos de entrada"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Teclado de Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inglés (Reino Unido)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inglés (EE.UU.)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inglés (EE.UU.), estilo internacional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inglés (EE.UU.), estilo Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inglés (EE.UU.), estilo Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Alemán"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francés"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francés (Canadá)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Ruso"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Ruso, estilo Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Español"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francés de Suiza"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Alemán suizo"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Búlgaro"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiano"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danés"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Noruego"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Sueco"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandés"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croata"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Checo"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonio"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Húngaro"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandés"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasileño"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugués"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Eslovaco"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Esloveno"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turco"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucraniano"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-et-rEE/strings.xml b/packages/InputDevices/res/values-et-rEE/strings.xml
deleted file mode 100644
index 5b4fa3b..0000000
--- a/packages/InputDevices/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Sisendseadmed"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Androidi klaviatuur"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inglise (Ühendkuningriik)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inglise (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inglise (USA), rahvusvaheline stiil"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inglise (USA), Colemaki stiil"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inglise (USA), Dvoraki stiil"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Saksa"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Prantsuse"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Prantsuse (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Vene"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Vene, Maci stiil"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Hispaania"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Šveitsi prantsuse"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Šveitsisaksa"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgia"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgaaria"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Itaalia"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Taani"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norra"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Rootsi"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Soome"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Horvaatia"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tšehhi"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Eesti"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungari"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandi"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasiilia"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugali"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovaki"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Sloveenia"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Türgi"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukraina"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-fa/strings.xml b/packages/InputDevices/res/values-fa/strings.xml
deleted file mode 100644
index d6a842e..0000000
--- a/packages/InputDevices/res/values-fa/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Input Devices"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"صفحه‌کلید Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"انگلیسی (بریتانیا)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"انگلیسی (امریکا)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"انگلیسی (ایالات متحده)، سبک بین‌المللی"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"انگلیسی (ایالات متحده)، سبک Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"انگلیسی (ایالات متحده)، سبک Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"آلمانی"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"فرانسوی"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"فرانسوی (کانادا)‏"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"روسی"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"روسی، سبک Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"اسپانیایی"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"فرانسوی سوئیس"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"آلمانی سوئیسی"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"بلژیکی"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"بلغاری"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"ایتالیایی"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"دانمارکی"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"نروژی"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"سوئدی"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"فنلاندی"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"کرواسی"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"چک"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"استونیایی"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"مجارستانی"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"ایسلندی"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"برزیلی"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"پرتغالی"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"اسلوواکی"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"اسلوونیایی"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"ترکی"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"اوکراینی"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-fi/strings.xml b/packages/InputDevices/res/values-fi/strings.xml
deleted file mode 100644
index 428eb30..0000000
--- a/packages/InputDevices/res/values-fi/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Syöttölaitteet"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-näppäimistö"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"englanti (Iso-Britannia)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"englanti (Yhdysvallat)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"englanti (Yhdysvallat), kansainvälinen"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"englanti (Yhdysvallat), Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"englanti (Yhdysvallat), Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"saksa"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"ranska"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"ranska (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"venäjä"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"venäjä, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"espanja"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"sveitsinranska"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"sveitsinsaksa"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"belgialainen"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"bulgaria"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"italia"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"tanska"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"norja"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"ruotsi"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"suomi"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"kroaatti"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"tšekki"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"viro"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"unkari"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"islanti"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"brasilialainen"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"portugali"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"slovakki"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"sloveeni"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"turkki"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukraina"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-fr-rCA/strings.xml b/packages/InputDevices/res/values-fr-rCA/strings.xml
deleted file mode 100644
index c947634..0000000
--- a/packages/InputDevices/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Périphériques d\'entrée"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Clavier Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Anglais (britannique)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Anglais (États-Unis)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Anglais (États-Unis), international"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Anglais (États-Unis), type Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Anglais (États-Unis), type Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Allemand"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Français"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Français (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russe"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russe, type Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Espagnol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Français (Suisse)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Allemand (Suisse)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belge"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgare"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italien"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danois"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norvégien"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Suédois"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finnois"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croate"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tchèque"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonien"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hongrois"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandais"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brésilien"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugais"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovaque"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovène"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turc"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainien"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-fr/strings.xml b/packages/InputDevices/res/values-fr/strings.xml
deleted file mode 100644
index fa02e5f..0000000
--- a/packages/InputDevices/res/values-fr/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Périphériques d\'entrée"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Clavier Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Anglais (Royaume-Uni)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Anglais (États-Unis)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Anglais (États-Unis), international"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Anglais (États-Unis), type Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Anglais (États-Unis), type Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Allemand"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Français"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Français (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russe"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russe, type Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Espagnol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Français (Suisse)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Allemand (Suisse)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belge"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgare"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italien"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danois"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norvégien"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Suédois"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finnois"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croate"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tchèque"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonien"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hongrois"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandais"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brésilien"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugais"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovaque"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovène"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turc"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainien"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-hi/strings.xml b/packages/InputDevices/res/values-hi/strings.xml
deleted file mode 100644
index 8e1864e..0000000
--- a/packages/InputDevices/res/values-hi/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"इनपुट उपकरण"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android कीबोर्ड"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"अंग्रेज़ी (यूके)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"अंग्रेज़ी (यूएस)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"अंग्रेज़ी (यूएस), अंतर्राष्ट्रीय शैली"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"अंग्रेज़ी (यूएस), कोलमैक शैली"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"अंग्रेज़ी (यूएस), ड्वोरक शैली"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"जर्मन"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"फ़्रांसीसी"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"फ़्रांसीसी (कनाडा)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"रूसी"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"रूसी, मैक शैली"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"स्पैनिश"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"स्विस फ़्रांसीसी"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"स्विस जर्मन"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"बेल्जियाई"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"बुल्‍गारियाई"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"इतालवी"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"डैनिश"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"नार्वेजियाई"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"स्वीडिश"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"फ़िनिश"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"क्रोएशियाई"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"चेक"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"एस्टोनियाई"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"हंगेरियाई"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"आइसलैंडिक"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"ब्राज़ीलियाई"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"पुर्तगाली"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"स्लोवाक"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"स्लोवेनियाई"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"तुर्की"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"यूक्रेनियाई"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-hr/strings.xml b/packages/InputDevices/res/values-hr/strings.xml
deleted file mode 100644
index fd3d594..0000000
--- a/packages/InputDevices/res/values-hr/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Uređaji za unos"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Androidova tipkovnica"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"engleska (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"engleska (SAD)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"engleska (SAD), međunarodna"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"engleska (SAD), Colemakov raspored"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"engleska (SAD), Dvorakov raspored"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"njemačka"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"francuska"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"francuska (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ruska"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ruska, raspored Maca"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"španjolska"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"švicarsko-francuska"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"švicarsko-njemačka"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"belgijska"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"bugarska"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"talijanska"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"danska"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"norveška"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"švedska"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"finska"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"hrvatska"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"češka"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"estonska"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"mađarska"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"islandska"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"brazilska"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"portugalska"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"slovačka"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"slovenska"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"turska"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukrajinska"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-hu/strings.xml b/packages/InputDevices/res/values-hu/strings.xml
deleted file mode 100644
index 0cdbfb2..0000000
--- a/packages/InputDevices/res/values-hu/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Beviteli eszközök"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-billentyűzet"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"angol (Egyesült Királyság)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"angol (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"angol (USA), nemzetközi stílus"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"angol (USA), Colemak-stílus"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"angol (USA), Dvorak-stílus"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"német"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"francia"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"francia (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"orosz"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"orosz, Mac-stílus"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"spanyol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"svájci francia"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"svájci német"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"bolgár"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"olasz"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"dán"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"norvég"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"svéd"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"finn"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"horvát"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"cseh"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"észt"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"magyar"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"izlandi"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"brazil"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"portugál"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"szlovák"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"szlovén"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"török"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukrán"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-hy-rAM/strings.xml b/packages/InputDevices/res/values-hy-rAM/strings.xml
deleted file mode 100644
index a73fb89..0000000
--- a/packages/InputDevices/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Մուտքագրման ​​սարքեր"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android ստեղնաշար"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Անգլերեն (ՄԲ)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Անգլերեն (ԱՄՆ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Անգլերեն (ԱՄՆ), միջազգային տեսակ"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Անգլերեն (ԱՄՆ), Colemak տեսակ"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Անգլերեն (ԱՄՆ), Dvorak տեսակ"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Գերմաներեն"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"ֆրանսերեն"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Ֆրանսերեն (Կանադա)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Ռուսերեն"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Ռուսերեն, Mac տեսակ"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Իսպաներեն"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Շվեյցարական ֆրանսերեն"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Շվեյցարական գերմաներեն"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Բելգիական"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Բուլղարերեն"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Իտալերեն"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Դանիերեն"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Նորվեգերեն"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Շվեդերեն"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Ֆիններեն"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Խորվաթերեն"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Չեխերեն"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Էստոներեն"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Հունգարերեն"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Իսլանդերեն"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Բրազիլերեն"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Պորտուգալերեն"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Սլովակերեն"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Սլովեներեն"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Թուրքերեն"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ուկրաիներեն"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-in/strings.xml b/packages/InputDevices/res/values-in/strings.xml
deleted file mode 100644
index 11e2dd0a..0000000
--- a/packages/InputDevices/res/values-in/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Perangkat Masukan"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Keyboard Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inggris (Britania)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inggris (Amerika)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inggris (AS), gaya Internasional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inggris (AS), gaya Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inggris (AS), gaya Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Jerman"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Prancis"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Prancis (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Rusia"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Rusia, gaya Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spanyol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Prancis Swiss"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Jerman Swiss"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgia"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgaria"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italia"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Denmark"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norwegia"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Swedia"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandia"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroasia"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Cheska"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonia"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hungaria"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandia"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasil"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugis"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slowakia"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovenia"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turki"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukraina"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-it/strings.xml b/packages/InputDevices/res/values-it/strings.xml
deleted file mode 100644
index dbb7301..0000000
--- a/packages/InputDevices/res/values-it/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispositivi di input"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Tastiera Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inglese (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inglese (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inglese (USA), stile internazionale"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inglese (USA), stile Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inglese (USA), stile Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Tedesco"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francese"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francese (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russo"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russo, stile Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spagnolo"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francese svizzero"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Tedesco svizzero"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgaro"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiano"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danese"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norvegese"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Svedese"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandese"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croato"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Ceco"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estone"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungherese"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandese"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasiliano"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portoghese"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovacco"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Sloveno"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turco"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucraino"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-iw/strings.xml b/packages/InputDevices/res/values-iw/strings.xml
deleted file mode 100644
index 5fab322..0000000
--- a/packages/InputDevices/res/values-iw/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"התקני קלט"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"מקלדת Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"אנגלית (בריטניה)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"אנגלית (ארה\"ב)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"אנגלית (ארה\"ב), סגנון בינ\"ל"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"אנגלית (ארה\"ב), סגנון Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"אנגלית (ארה\"ב), סגנון Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"גרמנית"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"צרפתית"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"צרפתית (קנדה)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"רוסית"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"רוסית, סגנון Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"ספרדית"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"צרפתית שוויצרית"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"גרמנית שוויצרית"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"בלגית"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"בולגרית"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"איטלקית"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"דנית"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"נורווגית"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"שוודית"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"פינית"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"קרואטית"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"צ\'כית"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"אסטונית"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"הונגרית"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"איסלנדית"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"ברזילאית"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"פורטוגזית"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"סלובקית"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"סלובנית"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"טורקית"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"אוקראינית"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ja/strings.xml b/packages/InputDevices/res/values-ja/strings.xml
deleted file mode 100644
index 950b727..0000000
--- a/packages/InputDevices/res/values-ja/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Input Devices"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Androidキーボード"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"英語(イギリス)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"英語(アメリカ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"英語(アメリカ)、インターナショナル配列"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"英語(アメリカ)、Colemak配列"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"英語(アメリカ)、Dvorak配列"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"ドイツ語"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"フランス語"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"フランス語(カナダ)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ロシア語"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ロシア語(Mac配列)"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"スペイン語"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"フランス語(スイス)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"ドイツ語(スイス)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"ベルギー語"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"ブルガリア語"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"イタリア語"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"デンマーク語"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"ノルウェー語"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"スウェーデン語"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"フィンランド語"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"クロアチア語"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"チェコ語"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"エストニア語"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"ハンガリー語"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"アイスランド語"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"ブラジル配列"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"ポルトガル語"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"スロバキア語"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"スロベニア語"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"トルコ語"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ウクライナ語"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ka-rGE/strings.xml b/packages/InputDevices/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 17ca302..0000000
--- a/packages/InputDevices/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Input Devices"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-ის კლავიატურა"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"ინგლისური (ბრიტ.)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"ინგლისური (აშშ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"ინგლისური (აშშ), საერთაშორისო სტილი"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"ანგლისური (აშშ), Colemak სტილი"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"ინგლისური (აშშ), Dvorak სტილი"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"გერმანული"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"ფრანგული"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"ფრანგული (კანადა)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"რუსული"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"რუსული, Mac სტილი"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"ესპანური"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"შვეიცარიული ფრანგული"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"შვეიცარიული გერმანული"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"ბელგიური"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"ბულგარული"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"იტალიური"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"დანიური"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"ნორვეგიული"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"შვედური"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"ფინური"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"ხორვატიული"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"ჩეხური"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"ესტონური"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"უნგრული"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"ისლანდიური"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"ბრაზილიური"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"პორტუგალიური"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"სლოვაკური"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"სლოვენური"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"თურქული"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"უკრაინული"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-km-rKH/strings.xml b/packages/InputDevices/res/values-km-rKH/strings.xml
deleted file mode 100644
index 9a8c99b..0000000
--- a/packages/InputDevices/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"ឧបករណ៍​បញ្ចូល"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"ក្ដារចុច​ Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"អង់គ្លេស (​ចក្រភព​អង់គ្លេស)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"អង់គ្លេស (​សហរដ្ឋ​អាមេរិក)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"អង់គ្លេស (សហរដ្ឋ​អាមេរិក​)​, ​​រចនាប័ទ្ម​​អន្តរជាតិ"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"អង់គ្លេស (សហរដ្ឋ​អាមេរិក​)​, ​​រចនាប័ទ្ម Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"អង់គ្លេស (សហរដ្ឋ​អាមេរិក​)​, ​​រចនាប័ទ្ម Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"អាល្លឺម៉ង់"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"បារាំង"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"បារាំង (កាណាដា​)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"រុស្សី"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"រុស្សី ​រចនាប័ទ្ម Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"អេស្ប៉ាញ"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"​​បារាំង​ ស្វីស"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"អាល្លឺម៉ង់ ស្វីស"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"បែលហ្ស៊ិក"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"ប៊ុលហ្ការី"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"អ៊ីតាលី"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"ដាណឺម៉ាក"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"ន័រវែស"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"ស៊ុយអែដ"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"ហ្វាំងឡង់"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"ក្រូអាត"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"ឆេក"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"អេស្តូនី"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"ហុងគ្រី"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"អ៊ីស្លង់"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"ប្រេស៊ីល"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"ព័រទុយហ្គាល់"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"ស្លូវ៉ាគី"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"ស្លូវ៉ានី"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"ទួរគី"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"អ៊ុយក្រែន"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ko/strings.xml b/packages/InputDevices/res/values-ko/strings.xml
deleted file mode 100644
index 8071586..0000000
--- a/packages/InputDevices/res/values-ko/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"입력 기기"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android 키보드"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"영어(영국)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"영어(미국)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"영어(미국), 글로벌 스타일"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"영어(미국), 콜맥 스타일"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"영어(미국), 드보락 스타일"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"독일어"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"프랑스어"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"프랑스어(캐나다)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"러시아어"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"러시아어, Mac 스타일"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"스페인어"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"프랑스어(스위스)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"독일어(스위스)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"벨기에어"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"불가리아어"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"이탈리아어"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"덴마크어"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"노르웨이어"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"스웨덴어"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"핀란드어"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"크로아티아어"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"체코어"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"에스토니아어"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"헝가리어"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"아이슬란드어"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"브라질어"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"포르투갈어"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"슬로바키아어"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"슬로베니아어"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"터키어"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"우크라이나어"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-lo-rLA/strings.xml b/packages/InputDevices/res/values-lo-rLA/strings.xml
deleted file mode 100644
index 2c97e11..0000000
--- a/packages/InputDevices/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"ອຸປະກອນປ້ອນຂໍ້ມູນ"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"ແປ້ນພິມ Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"ອັງກິດ (ສະຫະລັດຊະອານາຈັກ)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"ອັງກິດ (ສະຫະລັດຯ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"ອັງກິດ (ສະຫະລັດຯ), ແບບສາກົນ"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"ອັງກິດ (ສະຫະລັດຯ), ແບບ Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"ອັງກິດ (ສະຫະລັດຯ), ແບບ Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"ເຢຍລະມັນ"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"ຝຣັ່ງ"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"ຝຣັ່ງ (ຄານາດາ)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ຣັດເຊຍ"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ຣັດຊຽຍ, ແບບ Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"ສະແປນນິດ"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"ສະວິສ ຝຣັ່ງ"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"ສະວິສ ເຢຍລະມັນ"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"ເບວຢ້ຽນ"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"ຮັງກາຣຽນ"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"ອິຕາລຽນ"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"ເດັນນິຊ"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"ນໍເວກຽນ"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"ສະວີດິຊ"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"ຟິນນິຊ"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"ໂຄຣເອທຽນ"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"ເຊກ"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"ເອສໂຕນຽນ"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"ຮັງກາຣຽນ"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"ໄອສແລນດິກ"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"ບຣາຊິລຽນ"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"ປໍຕູກີສ"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"ສະໂລແວັກ"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"ສະໂລເວນຽນ"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"ເຕີກິສ"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ຢູເຄຣນຽນ"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-lt/strings.xml b/packages/InputDevices/res/values-lt/strings.xml
deleted file mode 100644
index 177d418..0000000
--- a/packages/InputDevices/res/values-lt/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Įvesties įrenginiai"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"„Android“ klaviatūra"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Anglų k. (JK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Anglų k. (JAV)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Anglų k. (JAV), tarptautinis stilius"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Anglų k. (JAV), „Colemak“ stilius"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Anglų k. (JAV), „Dvorak“ stilius"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Vokiečių k."</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Prancūzų k."</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Prancūzų k. (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Rusų k."</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Rusų k., „Mac“ stilius"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Ispanų k."</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Šveicarijos prancūzų k."</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Šveicarijos vokiečių k."</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgų k."</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarų k."</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italų k."</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danų k."</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norvegų k."</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Švedų k."</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Suomių k."</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroatų k."</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Čekų k."</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estų k."</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Vengrų k."</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandų k."</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazilų k."</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugalų k."</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovakų k."</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovėnų k."</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turkų k."</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainiečių k."</string>
-</resources>
diff --git a/packages/InputDevices/res/values-lv/strings.xml b/packages/InputDevices/res/values-lv/strings.xml
deleted file mode 100644
index 07a8654..0000000
--- a/packages/InputDevices/res/values-lv/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Ievadierīces"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android tastatūra"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Angļu (Lielbritānija)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Angļu (ASV)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Angļu (ASV), starptautiska"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Angļu (ASV), Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Angļu (ASV), Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Vācu"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Franču"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Franču (Kanāda)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Krievu"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Krievu, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spāņu"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Franču (Šveice)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Vācu (Šveice)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Beļģu"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgāru"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Itāļu"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Dāņu"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norvēģu"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Zviedru"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Somu"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Horvātu"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Čehu"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Igauņu"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungāru"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Īslandiešu"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazīļu"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugāļu"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovāku"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovēņu"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turku"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukraiņu"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-mn-rMN/strings.xml b/packages/InputDevices/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 0cfb085..0000000
--- a/packages/InputDevices/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Оруулах Төхөөрөмж"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Андройд гар"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Англи (ИБ)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Англи (АНУ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Англи (АНУ), Олон улсын стиль"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Англи (АНУ), Колемак стиль"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Англи (АНУ), Дворак стиль"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Герман"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Франц"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Франц (Канад)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Орос"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Орос, Maк стиль"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Испани"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Швейцарийн Франц"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Швейцарийн Герман"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Бельги"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Болгар"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Итали"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Дани"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Норвеги"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Швед"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Финлянд"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Хорват"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Чех"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Эстони"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Унгар"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Исланд"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Бразил"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Португал"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Словак"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Словени"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Турк"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Украйн"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ms-rMY/strings.xml b/packages/InputDevices/res/values-ms-rMY/strings.xml
deleted file mode 100644
index e08c39c..0000000
--- a/packages/InputDevices/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Peranti Input"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Papan kekunci Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Bahasa Inggeris (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Bahasa Inggeris (Australia)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Bahasa Inggeris (AS), gaya A/bangsa"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Bahasa Inggeris (AS), gaya Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Bahasa Inggeris (AS), gaya Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Bahasa Jerman"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Bahasa Perancis"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Bahasa Perancis (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Bahasa Rusia"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Bahasa Rusia, gaya Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Bahasa Sepanyol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Perancis Switzerland"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Jerman Switzerland"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Bahasa Belgium"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bahasa Bulgaria"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Bahasa Itali"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Bahasa Denmark"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Bahasa Norway"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Bahasa Sweden"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Bahasa Finland"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Bahasa Croatia"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Bahasa Czech"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Bahasa Estonia"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Bahasa Hungary"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Bahasa Iceland"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Bahasa Brazil"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Bahasa Portugis"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Bahasa Slovakia"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Bahasa Slovenia"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Bahasa Turki"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Bahasa Ukraine"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-nb/strings.xml b/packages/InputDevices/res/values-nb/strings.xml
deleted file mode 100644
index b646061..0000000
--- a/packages/InputDevices/res/values-nb/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Inndataenheter"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-tastatur"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Engelsk (Storbritannia)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Engelsk (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Engelsk (USA), internasjonal stil"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Engelsk (USA), Colemak-stil"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Engelsk (USA), Dvorak-stil"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Tysk"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Fransk"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Fransk (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russisk"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russisk, Mac-stil"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spansk"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Sveitsisk fransk"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Sveitsisk standardtysk"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgisk"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarsk"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiensk"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Dansk"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norsk"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Svensk"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finsk"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroatisk"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tsjekkisk"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estisk"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungarsk"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandsk"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasiliansk"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugisisk"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovakisk"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovensk"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Tyrkisk"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainsk"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-nl/strings.xml b/packages/InputDevices/res/values-nl/strings.xml
deleted file mode 100644
index 56d84c9..0000000
--- a/packages/InputDevices/res/values-nl/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Invoerapparaten"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android-toetsenbord"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Engels (Verenigd Koninkrijk)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Engels (Verenigde Staten)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Engels (VS), internationaal"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Engels (VS), Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Engels (VS), Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Duits"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Frans"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Frans (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russisch"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russisch, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spaans"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Zwitsers Frans"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Zwitsers Duits"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgisch"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgaars"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiaans"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Deens"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Noors"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Zweeds"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Fins"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroatisch"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tsjechisch"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estlands"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hongaars"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"IJslands"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Braziliaans"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugees"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slowaaks"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Sloveens"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turks"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Oekraïens"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-pl/strings.xml b/packages/InputDevices/res/values-pl/strings.xml
deleted file mode 100644
index 4522215..0000000
--- a/packages/InputDevices/res/values-pl/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Urządzenia wejściowe"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Klawiatura Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Angielski (Wielka Brytania)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Angielski (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Angielski (USA), międzynarodowy"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Angielski (USA), Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Angielski (USA), Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Niemiecki"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francuski"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francuski (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Rosyjski"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Rosyjski, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Hiszpański"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francuski (Szwajcaria)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Niemiecki (Szwajcaria)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgijski"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bułgarski"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Włoski"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Duński"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norweski"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Szwedzki"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Fiński"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Chorwacki"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Czeski"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estoński"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Węgierski"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandzki"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazylijski"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugalski"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Słowacki"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Słoweński"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turecki"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukraiński"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-pt-rPT/strings.xml b/packages/InputDevices/res/values-pt-rPT/strings.xml
deleted file mode 100644
index 9a639cd..0000000
--- a/packages/InputDevices/res/values-pt-rPT/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispositivos de entrada"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Teclado do Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inglês (RU)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inglês (EUA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inglês (EUA), est. Internacional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inglês (EUA), estilo Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inglês (EUA), estilo Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Alemão"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francês"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francês (Canadá)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russo"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russo, estilo Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Espanhol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francês (Suíça)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Alemão (Suíça)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Búlgaro"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiano"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Dinamarquês"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norueguês"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Sueco"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandês"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croata"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Checo"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estónio"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Húngaro"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandês"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasileiro"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Português"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Eslovaco"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Esloveno"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turco"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucraniano"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-pt/strings.xml b/packages/InputDevices/res/values-pt/strings.xml
deleted file mode 100644
index 05a0cd0..0000000
--- a/packages/InputDevices/res/values-pt/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispositivos de entrada"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Teclado do Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Inglês (Reino Unido)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Inglês (EUA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Inglês (EUA), estilo internacional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Inglês (EUA), estilo Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Inglês (EUA), estilo Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Alemão"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francês"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francês (Canadá)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russo"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russo, estilo Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Espanhol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francês suíço"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Alemão suíço"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belga"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Búlgaro"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italiano"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Dinamarquês"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norueguês"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Sueco"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandês"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croata"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tcheco"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estoniano"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Húngaro"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandês"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brasileiro"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Português"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Eslovaco"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Esloveno"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turco"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucraniano"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ro/strings.xml b/packages/InputDevices/res/values-ro/strings.xml
deleted file mode 100644
index 6ec5b25..0000000
--- a/packages/InputDevices/res/values-ro/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Dispozitive de introducere de date"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Tastatură Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Englez (Regatul Unit)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Englez (S.U.A.)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Englez (S.U.A.), stil internațional"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Englez (S.U.A.), stil Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Englez (S.U.A.), stil Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"German"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Francez"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Francez (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Rus"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Rus, stil Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spaniol"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Francez (Elveția)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"German (Elveția)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgian"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgar"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italian"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danez"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norvegian"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Suedez"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finlandez"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croat"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Ceh"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonian"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Maghiar"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Islandez"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazilian"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portughez"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovac"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Sloven"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turc"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ucrainean"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-ru/strings.xml b/packages/InputDevices/res/values-ru/strings.xml
deleted file mode 100644
index 5a80358..0000000
--- a/packages/InputDevices/res/values-ru/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Устройства ввода"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Клавиатура Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"английский (Великобритания)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"английский (США)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"English (US), International style"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"English (US), Colemak style"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"English (US), Dvorak style"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"немецкий"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"французский"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Французский (Канада)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"русский"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russian, Mac style"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"испанский"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"швейцарский французский"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"швейцарский немецкий"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Нидерландский (Бельгия)"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Болгарский"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"итальянский"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"датский"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"норвежский"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"шведский"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"финский"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"хорватский"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"чешский"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"эстонский"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"венгерский"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"исландский"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Португальский (Бразилия)"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"португальский"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"словацкий"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"словенский"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"турецкий"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"украинский"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-sk/strings.xml b/packages/InputDevices/res/values-sk/strings.xml
deleted file mode 100644
index 01ab042..0000000
--- a/packages/InputDevices/res/values-sk/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Vstupné zariadenia"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Klávesnica Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"anglické (Spojené kráľovstvo)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"anglické (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"anglické (USA), medzinárodné"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"anglické (USA), štýl Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"anglické (USA), štýl Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"nemecké"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"francúzske"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"francúzske (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ruské"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ruské, štýl Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"španielske"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"švajčiarske (francúzština)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"švajčiarske (nemčina)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"belgické"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"bulharské"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"talianske"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"dánske"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"nórske"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"švédske"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"fínske"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"chorvátske"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"české"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"estónske"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"maďarské"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"islandské"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"brazílske"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"portugalské"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"slovenské"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"slovinské"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"turecké"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukrajinské"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-sl/strings.xml b/packages/InputDevices/res/values-sl/strings.xml
deleted file mode 100644
index 30ff3c4..0000000
--- a/packages/InputDevices/res/values-sl/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Vhodne naprave"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Tipkovnica Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"angleška (Združeno kraljestvo)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"angleška (ZDA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"angleška (ZDA), mednarodni slog"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"angleška (ZDA), slog Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"angleška (ZDA), slog Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"nemška"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"francoska"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"francoska (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"ruska"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"ruska, slog Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"španska"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"švicarska francoska"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"švicarska nemška"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"belgijska"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"bolgarska"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"italijanska"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"danska"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"norveška"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"švedska"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"finska"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"hrvaška"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"češka"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"estonska"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"madžarska"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"islandska"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"brazilska"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"portugalska"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"slovaška"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"slovenska"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"turška"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ukrajinska"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-sr/strings.xml b/packages/InputDevices/res/values-sr/strings.xml
deleted file mode 100644
index 4b7910c..0000000
--- a/packages/InputDevices/res/values-sr/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Улазни уређаји"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android тастатура"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"енглески (Уједињено Краљевство)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"енглески (САД)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"енглески (САД), међународни стил"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"енглески (САД), Colemak стил"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"енглески (САД), Dvorak стил"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"немачки"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"француски"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"француски (Канада)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"руски"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"руски, Mac стил"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"шпански"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"швајцарски француски"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"швајцарски немачки"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"белгијски"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"бугарски"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"италијански"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"дански"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"норвешки"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"шведски"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"фински"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"хрватски"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"чешки"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"естонски"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"мађарски"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"исландски"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"бразилски"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"португалски"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"словачки"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"словеначки"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"турски"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"украјински"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-sv/strings.xml b/packages/InputDevices/res/values-sv/strings.xml
deleted file mode 100644
index 25a5ae8..0000000
--- a/packages/InputDevices/res/values-sv/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Indataenheter"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Androids tangentbord"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Engelskt (Storbritannien)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Engelskt (USA)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Engelskt (USA), internationellt"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Engelskt (USA), colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Engelskt (USA), dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Tyskt"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Franskt"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Franskt (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Ryskt"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Ryskt, Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spanskt"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Franskt (Schweiz)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Tyskt (Schweiz)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgiskt"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgariskt"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italienskt"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danskt"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norskt"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Svenskt"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finskt"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kroatiskt"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tjeckiskt"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estniskt"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Ungerskt"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Isländskt"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Portugisiskt (Brasilien)"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portugisiskt"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovakiskt"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovenskt"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turkiskt"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainskt"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-sw/strings.xml b/packages/InputDevices/res/values-sw/strings.xml
deleted file mode 100644
index 65c9f59..0000000
--- a/packages/InputDevices/res/values-sw/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Vifaa Ingizi"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Kibodi ya Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Kiingereza (Uingereza)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Kingereza (Marekani)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Kiingereza (Marekani), Muundo wa Kimataifa"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Kiingereza (Marekani), Muundo wa Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Kiingereza (Marekani), Muundo wa Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Kijerumani"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Kifaransa"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Kifaransa (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Kirusi"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Kirusi, Muundo wa Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Kihispania"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Kifaransa cha Uswisi"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Kijerumani cha Uswisi"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Kibelgiji"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Kibulgaria"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Kiitaliano"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Kidenmarki"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Kinorwei"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Kiswidi"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Kifinlandi"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Kikroeshia"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Kicheki"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Kiestonia"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Kihungari"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Kiaislandi"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Kibrazili"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Kireno"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Kislovakia"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Kislovenia"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Kituruki"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Kiukrania"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-th/strings.xml b/packages/InputDevices/res/values-th/strings.xml
deleted file mode 100644
index 0cc7d47..0000000
--- a/packages/InputDevices/res/values-th/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"อุปกรณ์อินพุต"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"แป้นพิมพ์แอนดรอยด์"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"อังกฤษ (สหราชอาณาจักร)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"อังกฤษ (อเมริกัน)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"อังกฤษ (อเมริกัน), รูปแบบนานาชาติ"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"อังกฤษ (อเมริกัน), รูปแบบ Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"อังกฤษ (อเมริกัน), รูปแบบ Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"เยอรมัน"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"ฝรั่งเศส"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"ฝรั่งเศส (แคนาดา)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"รัสเซีย"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"รัสเซีย, รูปแบบ Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"สเปน"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"ฝรั่งเศส (สวิส)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"เยอรมันสวิส"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"เบลเยียม"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"บัลแกเรีย"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"อิตาลี"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"เดนมาร์ก"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"นอร์เวย์"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"สวีเดน"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"ฟินแลนด์"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"โครเอเชีย"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"เช็ก"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"เอสโตเนีย"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"ฮังการี"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"ไอซ์แลนดิก"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"บราซิล"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"โปรตุเกส"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"สโลวัก"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"สโลวีเนีย"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"ตุรกี"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"ยูเครน"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-tl/strings.xml b/packages/InputDevices/res/values-tl/strings.xml
deleted file mode 100644
index 08f34d2..0000000
--- a/packages/InputDevices/res/values-tl/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Mga Input Device"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android keyboard"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Ingles (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Ingles (US)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Ingles (US), istilong International"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Ingles (US), istilong Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Ingles (US), istilong Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"German"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"French"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"French (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Russian"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Russian, istilong Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Spanish"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Swiss French"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Swiss German"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belgian"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarian"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Italian"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danish"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norwegian"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Swedish"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Finnish"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Croatian"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Czech"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonian"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Hungarian"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Icelandic"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brazilian"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portuguese"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovak"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovenian"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Turkish"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukrainian"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-tr/strings.xml b/packages/InputDevices/res/values-tr/strings.xml
deleted file mode 100644
index d146b35..0000000
--- a/packages/InputDevices/res/values-tr/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Giriş Cihazları"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android klavyesi"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"İngilizce (İngiltere)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"İngilizce (ABD)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"İngilizce (ABD) Uluslararası stil"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"İngilizce (ABD) Colemak stili"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"İngilizce (ABD) Dvorak stili"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Almanca"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Fransızca"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Fransızca (Kanada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Rusça"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Rusça, Mac stili"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"İspanyolca"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"İsviçre Fransızcası"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"İsviçre Almancası"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Belçika dili"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Bulgarca"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"İtalyanca"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Danca"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Norveççe"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"İsveççe"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Fince"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Hırvatça"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Çekçe"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Estonca"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Macarca"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"İzlandaca"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Brezilya dili"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Portekizce"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Slovakça"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Slovence"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Türkçe"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Ukraynaca"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-uk/strings.xml b/packages/InputDevices/res/values-uk/strings.xml
deleted file mode 100644
index ee6ffc7..0000000
--- a/packages/InputDevices/res/values-uk/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Пристрої вводу"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Клавіатура Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"англійська (Великобританія)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"англійська (США)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"англійська (США), міжнародна"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"англійська (США), розкладка Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"англійська (США), розкладка Дворака"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"німецька"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"французька"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"французька (Канада)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"російська"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"російська, розкладка Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"іспанська"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"французька (Швейцарія)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"німецька (Швейцарія)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"бельгійська"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"болгарська"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"італійська"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"данська"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"норвезька"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"шведська"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"фінська"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"хорватська"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"чеська"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"естонська"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"угорська"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"ісландська"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"бразильська"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"португальська"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"словацька"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"словенська"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"турецька"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"українська"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-vi/strings.xml b/packages/InputDevices/res/values-vi/strings.xml
deleted file mode 100644
index 7a65e45..0000000
--- a/packages/InputDevices/res/values-vi/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Thiết bị đầu vào"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Bàn phím Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"Tiếng Anh (Anh)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"Tiếng Anh (Mỹ)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"Tiếng Anh (Mỹ), kiểu Quốc tế"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"Tiếng Anh (Mỹ), kiểu Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"Tiếng Anh (Mỹ), kiểu Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Tiếng Đức"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Tiếng Pháp"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Tiếng Pháp (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Tiếng Nga"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Tiếng Nga, kiểu Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Tiếng Tây Ban Nha"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Tiếng Pháp ở Thụy Sĩ"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Tiếng Đức Thụy Sĩ"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Tiếng Bỉ"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Tiếng Bungary"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Tiếng Ý"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Tiếng Đan Mạch"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Tiếng Na Uy"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Tiếng Thụy Điển"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Tiếng Phần Lan"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Tiếng Croatia"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Tiếng Séc"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Tiếng Estonia"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Tiếng Hungary"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Tiếng Ai-xơ-len"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Tiếng Brazil"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Tiếng Bồ Đào Nha"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Tiếng Slovak"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Tiếng Sloven"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Tiếng Thổ Nhĩ Kỳ"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Tiếng Ukraina"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-zh-rCN/strings.xml b/packages/InputDevices/res/values-zh-rCN/strings.xml
deleted file mode 100644
index 2e18180..0000000
--- a/packages/InputDevices/res/values-zh-rCN/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"输入设备"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android 键盘"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"英语(英式)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"英语(美式)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"英语(美式),国际风格"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"英语(美式),Colemak 风格"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"英语(美式),Dvorak 风格"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"德语"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"法语"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"法语(加拿大)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"俄语"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"俄语,Mac 风格"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"西班牙语"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"瑞士法语"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"瑞士德语"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"比利时语"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"保加利亚语"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"意大利语"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"丹麦语"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"挪威语"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"瑞典语"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"芬兰语"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"克罗地亚语"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"捷克语"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"爱沙尼亚语"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"匈牙利语"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"冰岛语"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"巴西语"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"葡萄牙语"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"斯洛伐克语"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"斯洛文尼亚语"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"土耳其语"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"乌克兰语"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-zh-rHK/strings.xml b/packages/InputDevices/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 839c546..0000000
--- a/packages/InputDevices/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"輸入裝置"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android 鍵盤"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"英文 (英國)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"英文 (美國)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"英文 (美國),國際樣式"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"英文 (美國),Colemak 樣式"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"英文 (美國),Dvorak 樣式"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"德文"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"法文"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"法文 (加拿大)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"俄文"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"俄文,Mac 樣式"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"西班牙文"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"法文 (瑞士)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"德文(瑞士)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"比利時文"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"保加利亞文"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"意大利文"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"丹麥文"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"挪威文"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"瑞典文"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"芬蘭文"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"克羅地亞文"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"捷克文"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"愛沙尼亞文"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"匈牙利文"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"冰島文"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"巴西文"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"葡萄牙文"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"斯洛伐克文"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"斯洛文尼亞文"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"土耳其文"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"烏克蘭文"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-zh-rTW/strings.xml b/packages/InputDevices/res/values-zh-rTW/strings.xml
deleted file mode 100644
index ba9f132..0000000
--- a/packages/InputDevices/res/values-zh-rTW/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"輸入裝置"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Android 鍵盤"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"英文 (英國)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"英文 (美國)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"英文 (美國),國際樣式"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"英文 (美國),Colemak 樣式"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"英文 (美國),Dvorak 樣式"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"德文"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"法文"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"法文 (加拿大)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"俄文"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"俄文,Mac 樣式"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"西班牙文"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"法文 (瑞士)"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"德文 (瑞士)"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"比利時式"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"保加利亞文"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"義大利文"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"丹麥文"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"挪威文"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"瑞典文"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"芬蘭文"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"克羅埃西亞文"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"捷克文"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"愛沙尼亞文"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"匈牙利文"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"冰島文"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"巴西式"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"葡萄牙文"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"斯洛伐克文"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"斯洛維尼亞文"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"土耳其文"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"烏克蘭文"</string>
-</resources>
diff --git a/packages/InputDevices/res/values-zu/strings.xml b/packages/InputDevices/res/values-zu/strings.xml
deleted file mode 100644
index fbf1074..0000000
--- a/packages/InputDevices/res/values-zu/strings.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="8016145283189546017">"Amadivayisi wokufaka"</string>
-    <string name="keyboard_layouts_label" msgid="6688773268302087545">"Ikhibhodi ye-Android"</string>
-    <string name="keyboard_layout_english_uk_label" msgid="6664258463319999632">"I-English (UK)"</string>
-    <string name="keyboard_layout_english_us_label" msgid="8994890249649106291">"I-English (US)"</string>
-    <string name="keyboard_layout_english_us_intl" msgid="3705168594034233583">"I-English (US), isitayela sakwamanye amazwe"</string>
-    <string name="keyboard_layout_english_us_colemak_label" msgid="4194969610343455380">"I-English (US), isitayela se-Colemak"</string>
-    <string name="keyboard_layout_english_us_dvorak_label" msgid="793528923171145202">"I-English (US), isitayela se-Dvorak"</string>
-    <string name="keyboard_layout_german_label" msgid="8451565865467909999">"Isi-German"</string>
-    <string name="keyboard_layout_french_label" msgid="813450119589383723">"Isi-French"</string>
-    <string name="keyboard_layout_french_ca_label" msgid="365352601060604832">"Isi-French (Canada)"</string>
-    <string name="keyboard_layout_russian_label" msgid="8724879775815042968">"Isi-Russian"</string>
-    <string name="keyboard_layout_russian_mac_label" msgid="3795866869038264796">"Isi-Russian, isitayela se-Mac"</string>
-    <string name="keyboard_layout_spanish_label" msgid="7091555148131908240">"Isi-Spanish"</string>
-    <string name="keyboard_layout_swiss_french_label" msgid="4659191025396371684">"Isi-Swiss French"</string>
-    <string name="keyboard_layout_swiss_german_label" msgid="2305520941993314258">"Isi-Swiss German"</string>
-    <string name="keyboard_layout_belgian" msgid="2011984572838651558">"Isi-Belgian"</string>
-    <string name="keyboard_layout_bulgarian" msgid="8951224309972028398">"Isi-Bulgarian"</string>
-    <string name="keyboard_layout_italian" msgid="6497079660449781213">"Isi-Italian"</string>
-    <string name="keyboard_layout_danish" msgid="8036432066627127851">"Isi-Danish"</string>
-    <string name="keyboard_layout_norwegian" msgid="9090097917011040937">"Isi-Norwegian"</string>
-    <string name="keyboard_layout_swedish" msgid="732959109088479351">"Isi-Swedish"</string>
-    <string name="keyboard_layout_finnish" msgid="5585659438924315466">"Isi-Finnish"</string>
-    <string name="keyboard_layout_croatian" msgid="4172229471079281138">"Isi-Croatian"</string>
-    <string name="keyboard_layout_czech" msgid="1349256901452975343">"Isi-Czech"</string>
-    <string name="keyboard_layout_estonian" msgid="8775830985185665274">"Isi-Estonian"</string>
-    <string name="keyboard_layout_hungarian" msgid="4154963661406035109">"Isi-Hungarian"</string>
-    <string name="keyboard_layout_icelandic" msgid="5836645650912489642">"Isi-Icelandic"</string>
-    <string name="keyboard_layout_brazilian" msgid="5117896443147781939">"Isi-Brazilian"</string>
-    <string name="keyboard_layout_portuguese" msgid="2888198587329660305">"Isi-Portuguese"</string>
-    <string name="keyboard_layout_slovak" msgid="2469379934672837296">"Isi-Slovak"</string>
-    <string name="keyboard_layout_slovenian" msgid="1735933028924982368">"Isi-Slovenian"</string>
-    <string name="keyboard_layout_turkish" msgid="7736163250907964898">"Isi-Turkish"</string>
-    <string name="keyboard_layout_ukrainian" msgid="8176637744389480417">"Isi-Ukrainian"</string>
-</resources>
diff --git a/packages/Keyguard/Android.mk b/packages/Keyguard/Android.mk
index f6f441d..1f2b5fb 100644
--- a/packages/Keyguard/Android.mk
+++ b/packages/Keyguard/Android.mk
@@ -18,8 +18,6 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-subdir-Iaidl-files)
 
-LOCAL_JAVA_LIBRARIES := services
-
 LOCAL_PACKAGE_NAME := Keyguard
 
 LOCAL_CERTIFICATE := platform
diff --git a/packages/Keyguard/res/values-af/strings.xml b/packages/Keyguard/res/values-af/strings.xml
index 834f2f6..7e1f0bf 100644
--- a/packages/Keyguard/res/values-af/strings.xml
+++ b/packages/Keyguard/res/values-af/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Laatwag-knoppie"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Speel-knoppie"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stop-knoppie"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Laaik baie"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Laaik niks"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Hart"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Ontsluit om voort te gaan"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Begin gekanselleer"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Laat los <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> om uit te vee."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> sal nie uitgevee word nie."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-am/strings.xml b/packages/Keyguard/res/values-am/strings.xml
index 6b4980d..2f6dab0 100644
--- a/packages/Keyguard/res/values-am/strings.xml
+++ b/packages/Keyguard/res/values-am/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"ለአፍታ አቁም አዝራር"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"የአጫውት አዝራር"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"አቁም አዝራር"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"አሪፍ"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"ደባሪ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"ልብ"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"ለመቀጠል ይክፈቱ"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"ማስጀመር ተሰርዟል"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"ለመሰረዝ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>ን ጣል ያድርጉ።"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> አይሰርዝም።"</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-ar/strings.xml b/packages/Keyguard/res/values-ar/strings.xml
index fa778b3..bcfe7db 100644
--- a/packages/Keyguard/res/values-ar/strings.xml
+++ b/packages/Keyguard/res/values-ar/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"زر الإيقاف المؤقت"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"زر التشغيل"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"زر الإيقاف"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"رائعة"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"معارضة"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"قلب"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"إلغاء القفل للمتابعة"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"تم إلغاء التشغيل"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"أسقط <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> للحذف."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"لن يتم حذف <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ب ت ث"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-be/strings.xml b/packages/Keyguard/res/values-be/strings.xml
index b34d441..81020a0 100644
--- a/packages/Keyguard/res/values-be/strings.xml
+++ b/packages/Keyguard/res/values-be/strings.xml
@@ -71,20 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Кнопка паўзы"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Кнопка прайгравання"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Кнопка спынення"</string>
-    <!-- no translation found for keyguard_accessibility_transport_thumbs_up_description (4535938129663903194) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_transport_thumbs_down_description (8101433677192177861) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_transport_heart_description (2336943232474689887) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_show_bouncer (5425837272418176176) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_hide_bouncer (7896992171878309358) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_delete_widget_start (4096550552634391451) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_delete_widget_end (508833506780909393) -->
-    <skip />
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"Alt"</string>
diff --git a/packages/Keyguard/res/values-bg/strings.xml b/packages/Keyguard/res/values-bg/strings.xml
index 468570f..869ab7b 100644
--- a/packages/Keyguard/res/values-bg/strings.xml
+++ b/packages/Keyguard/res/values-bg/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Бутон за пауза"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Бутон за пускане"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Бутон за спиране"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Харесва ми"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Не ми харесва"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Сърце"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Отключете, за да продължите"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Стартирането е анулирано"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Пуснете <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>, за да изтриете."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> няма да се изтрие."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"АБВ"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-ca/strings.xml b/packages/Keyguard/res/values-ca/strings.xml
index 1b76723..4f97c6b 100644
--- a/packages/Keyguard/res/values-ca/strings.xml
+++ b/packages/Keyguard/res/values-ca/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Botó de pausa"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Botó de reproducció"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Botó de parada"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"M\'agrada"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"No m\'agrada"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Cor"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Desbloqueja per continuar"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"S\'ha cancel·lat l\'inici"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Deixa anar <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> per suprimir-lo."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"No se suprimirà <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-cs/strings.xml b/packages/Keyguard/res/values-cs/strings.xml
index b4598cb..ec2833c 100644
--- a/packages/Keyguard/res/values-cs/strings.xml
+++ b/packages/Keyguard/res/values-cs/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Tlačítko Pozastavit"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Tlačítko Přehrát"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Tlačítko Zastavit"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Líbí se mi"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Nelíbí se mi"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Srdíčko"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Pokračujte odemknutím"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Spuštění zrušeno"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Uvolněním dotyku widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> vymažete."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> nebude vymazán."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"Alt"</string>
diff --git a/packages/Keyguard/res/values-da/strings.xml b/packages/Keyguard/res/values-da/strings.xml
index 0cff37c..cfc7464 100644
--- a/packages/Keyguard/res/values-da/strings.xml
+++ b/packages/Keyguard/res/values-da/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pause-knap"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Afspil-knap"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stop-knap"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Synes om"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Synes ikke om"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Hjerte"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Lås op for at gå videre"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Starten blev annulleret"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Slip <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> for at slette."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> slettes ikke."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-de/strings.xml b/packages/Keyguard/res/values-de/strings.xml
index d42e1b9..85d1a4f9 100644
--- a/packages/Keyguard/res/values-de/strings.xml
+++ b/packages/Keyguard/res/values-de/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Schaltfläche für Pause"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Schaltfläche für Wiedergabe"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Schaltfläche für Stopp"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Mag ich"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Mag ich nicht"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Herz"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Zum Fortfahren entsperren"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Start abgebrochen"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Legen Sie <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> zum Löschen ab."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> wird nicht gelöscht."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-el/strings.xml b/packages/Keyguard/res/values-el/strings.xml
index 2d67df0..e86f24d 100644
--- a/packages/Keyguard/res/values-el/strings.xml
+++ b/packages/Keyguard/res/values-el/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Κουμπί παύσης"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Κουμπί αναπαραγωγής"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Κουμπί διακοπής"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Επιδοκιμασία"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Αποδοκιμασία"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Καρδιά"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Ξεκλειδώστε για να συνεχίσετε"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Η εκκίνηση ακυρώθηκε"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Αποθέστε <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> για διαγραφή."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> δεν θα διαγραφεί."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ΑΒΓ"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-en-rGB/strings.xml b/packages/Keyguard/res/values-en-rGB/strings.xml
index 892bab7..967c3fa 100644
--- a/packages/Keyguard/res/values-en-rGB/strings.xml
+++ b/packages/Keyguard/res/values-en-rGB/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pause button"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Play button"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stop button"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Thumbs up"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Thumbs down"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Heart"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Unlock to continue"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Launch cancelled"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Drop <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> to delete."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> will not be deleted."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-en-rIN/strings.xml b/packages/Keyguard/res/values-en-rIN/strings.xml
deleted file mode 100644
index 892bab7..0000000
--- a/packages/Keyguard/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"Type PIN code"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"Type PUK and new PIN code"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK code"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"New PIN Code"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Touch to type password"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Type password to unlock"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Type PIN to unlock"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Incorrect PIN code."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"To unlock, press Menu, then 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Maximum Face Unlock attempts exceeded"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Charged"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"Charging, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"Connect your charger."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Press Menu to unlock."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"Network locked"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"No SIM card"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"No SIM card in tablet."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"No SIM card in phone."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"Insert a SIM card."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"The SIM card is missing or not readable. Insert a SIM card."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"Unusable SIM card."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"Your SIM card has been permanently disabled.\n Contact your wireless service provider for another SIM card."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"SIM card is locked."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"SIM card is PUK-locked."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"Unlocking SIM card…"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Widget %2$d of %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Add widget"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Empty"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Unlock area expanded."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Unlock area collapsed."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> widget."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"User selector"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Status"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Camera"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Media controls"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Widget reordering started."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Widget reordering ended."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> deleted."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Expand unlock area."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Slide unlock."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Pattern unlock."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Face unlock."</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin unlock."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Password unlock."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Pattern area."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Slide area."</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"Previous track button"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"Next track button"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pause button"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Play button"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stop button"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Thumbs up"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Thumbs down"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Heart"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Unlock to continue"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Launch cancelled"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Drop <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> to delete."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> will not be deleted."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Cancel"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Delete"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Done"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Mode change"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Enter"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Unlock"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Camera"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Silent"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Sound on"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Search"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"Slide up for <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"Slide down for <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"Slide left for <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"Slide right for <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Current user <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Emergency call"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Forgot Pattern"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Wrong Pattern"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Wrong Password"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"Wrong PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Try again in <xliff:g id="NUMBER">%d</xliff:g> seconds."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Draw your pattern"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Enter SIM PIN"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"Enter PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Enter Password"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM is now disabled. Enter PUK code to continue. Contact carrier for details."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Enter desired PIN code"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Confirm desired PIN code"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"Unlocking SIM card…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Incorrect PIN code."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"Type a PIN that is 4 to 8 numbers."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK code should be 8 numbers or more."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Re-enter the correct PUK code. Repeated attempts will permanently disable the SIM."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN codes do not match"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Too many pattern attempts"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"To unlock, sign in with your Google account."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Username (email)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Password"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Sign in"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Invalid username or password."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Forgot your username or password?\nVisit "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Checking account…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"You have incorrectly typed your PIN <xliff:g id="NUMBER_0">%d</xliff:g> times. \n\nTry again in <xliff:g id="NUMBER_1">%d</xliff:g> seconds."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"You have incorrectly typed your password <xliff:g id="NUMBER_0">%d</xliff:g> times. \n\nTry again in <xliff:g id="NUMBER_1">%d</xliff:g> seconds."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"You have incorrectly drawn your unlock pattern <xliff:g id="NUMBER_0">%d</xliff:g> times. \n\nTry again in <xliff:g id="NUMBER_1">%d</xliff:g> seconds."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"You have incorrectly attempted to unlock the tablet <xliff:g id="NUMBER_0">%d</xliff:g> times. After <xliff:g id="NUMBER_1">%d</xliff:g> more unsuccessful attempts, the tablet will be reset to factory default and all user data will be lost."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"You have incorrectly attempted to unlock the phone <xliff:g id="NUMBER_0">%d</xliff:g> times. After <xliff:g id="NUMBER_1">%d</xliff:g> more unsuccessful attempts, the phone will be reset to factory default and all user data will be lost."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"You have incorrectly attempted to unlock the tablet <xliff:g id="NUMBER">%d</xliff:g> times. The tablet will now be reset to factory default."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"You have incorrectly attempted to unlock the phone <xliff:g id="NUMBER">%d</xliff:g> times. The phone will now be reset to factory default."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"You have incorrectly drawn your unlock pattern <xliff:g id="NUMBER_0">%d</xliff:g> times. After <xliff:g id="NUMBER_1">%d</xliff:g> more unsuccessful attempts, you will be asked to unlock your tablet using an email account.\n\n Try again in <xliff:g id="NUMBER_2">%d</xliff:g> seconds."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"You have incorrectly drawn your unlock pattern <xliff:g id="NUMBER_0">%d</xliff:g> times. After <xliff:g id="NUMBER_1">%d</xliff:g> more unsuccessful attempts, you will be asked to unlock your phone using an email account.\n\n Try again in <xliff:g id="NUMBER_2">%d</xliff:g> seconds."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Remove"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"Previous track button"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"Next track button"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Pause button"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Play button"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Stop button"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"No service."</string>
-</resources>
diff --git a/packages/Keyguard/res/values-es-rUS/strings.xml b/packages/Keyguard/res/values-es-rUS/strings.xml
index 2278efd..787581a 100644
--- a/packages/Keyguard/res/values-es-rUS/strings.xml
+++ b/packages/Keyguard/res/values-es-rUS/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Botón de pausa"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Botón de reproducción"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Botón de detención"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Votos a favor"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Votos en contra"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Corazón"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Desbloquea para continuar."</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Se canceló el inicio."</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Suelta <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> para eliminarlo."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"No se eliminará <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-es/strings.xml b/packages/Keyguard/res/values-es/strings.xml
index 330926b..d0c79eb 100644
--- a/packages/Keyguard/res/values-es/strings.xml
+++ b/packages/Keyguard/res/values-es/strings.xml
@@ -30,7 +30,7 @@
     <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Código PIN incorrecto"</string>
     <string name="keyguard_label_text" msgid="861796461028298424">"Para desbloquear el teléfono, pulsa la tecla de menú y, a continuación, pulsa 0."</string>
     <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Se ha superado el número máximo de intentos de desbloqueo facial."</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Cargada"</string>
+    <string name="keyguard_charged" msgid="3272223906073492454">"Cargado"</string>
     <string name="keyguard_plugged_in" msgid="8117572000639998388">"Cargando (<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>)"</string>
     <string name="keyguard_low_battery" msgid="8143808018719173859">"Conecta el cargador."</string>
     <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Ve al menú para desbloquear la pantalla."</string>
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Botón de pausa"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Botón de reproducción"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Botón para detener la reproducción"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Me gusta"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"No me gusta"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Corazón"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Desbloquear para continuar"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Inicio cancelado"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Suelta <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> para eliminarlo."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> no se eliminará."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-et-rEE/strings.xml b/packages/Keyguard/res/values-et-rEE/strings.xml
deleted file mode 100644
index a2a4091..0000000
--- a/packages/Keyguard/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"Sisestage PIN-kood"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"Sisestage PUK-kood ja uus PIN-kood"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK-kood"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Uus PIN-kood"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Puudutage parooli sisestamiseks"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Avamiseks sisestage parool"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Avamiseks sisestage PIN-kood"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Vale PIN-kood."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Avamiseks vajutage menüüklahvi, seejärel klahvi 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Maksimaalne teenusega Face Unlock avamise katsete arv on ületatud"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Laetud"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"Laadimine, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"Ühendage laadija."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Avamiseks vajutage menüüklahvi."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"Võrk on suletud"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"SIM-kaarti pole"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"Tahvelarvutis pole SIM-kaarti."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"Telefonis pole SIM-kaarti."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"Sisestage SIM-kaart."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"SIM-kaart puudub või on loetamatu. Sisestage SIM-kaart."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"Kasutamiskõlbmatu SIM-kaart."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"SIM-kaart on jäädavalt keelatud.\n Uue SIM-kaardi saamiseks võtke ühendust oma mobiilsideoperaatoriga."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"SIM-kaart on lukus."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"SIM-kaart on PUK-lukus."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"SIM-kaardi avamine ..."</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Vidin %2$d/%3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Vidina lisamine."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Tühi"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Avamisala on laiendatud."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Avamisala on ahendatud."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"Vidin <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Kasutaja valija"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Olek"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Kaamera"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Meedia juhtnupud"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Vidina ümberkorraldamine algas."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Vidina ümberkorraldamine lõppes."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Vidin <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> on kustutatud."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Avamisala laiendamine."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Lohistamisega avamine."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Mustriga avamine."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Näoga avamine."</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"PIN-koodiga avamine."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Parooliga avamine."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Mustri ala."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Lohistamisala."</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"Nupp Eelmine lugu"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"Nupp Järgmine lugu"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Nupp Peata"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Nupp Esita"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Nupp Peata"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Meeldib"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Ei meeldi"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Süda"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Jätkamiseks tühistage lukustus"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Käivitamine on tühistatud"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Kustutamiseks laske vidin <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> lahti."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Vidinat <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ei kustutata."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Tühista"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Kustuta"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Valmis"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Režiimi muutmine"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Tõstuklahv"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Sisestusklahv"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Luku avamine"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Kaamera"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Hääletu"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Heli on sees"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Otsing"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"Lohistage üles: <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"Lohistage alla: <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"Lohistage vasakule: <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"Lohistage paremale: <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Praegune kasutaja <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Hädaabikõne"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Unustasin mustri"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Vale muster"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Vale parool"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"Vale PIN-kood"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Proovige uuesti <xliff:g id="NUMBER">%d</xliff:g> sekundi pärast."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Joonistage oma muster"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Sisestage SIM-i PIN-kood"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"Sisestage PIN-kood"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Sisestage parool"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM on nüüd keelatud. Jätkamiseks sisestage PUK-kood. Üksikasju küsige operaatorilt."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Sisestage soovitud PIN-kood"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Kinnitage soovitud PIN-kood"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM-kaardi avamine ..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Vale PIN-kood."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"Sisestage 4–8-numbriline PIN-kood."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK-koodi pikkus peab olema vähemalt 8 numbrit."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Sisestage uuesti õige PUK-kood. Korduvkatsete korral keelatakse SIM jäädavalt."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN-koodid ei ole vastavuses"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Liiga palju mustrikatseid"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Avamiseks logige sisse oma Google\'i kontoga."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Kasutajanimi (e-post)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Parool"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Logi sisse"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Vale kasutajanimi või parool."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Kas unustasite kasutajanime või parooli?\nKülastage aadressi "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Konto kontrollimine ..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Olete PIN-koodi <xliff:g id="NUMBER_0">%d</xliff:g> korda valesti sisestanud.\n\nProovige <xliff:g id="NUMBER_1">%d</xliff:g> sekundi pärast uuesti."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Olete parooli <xliff:g id="NUMBER_0">%d</xliff:g> korda valesti sisestanud. \n\nProovige uuesti <xliff:g id="NUMBER_1">%d</xliff:g> sekundi pärast."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Joonistasite oma avamismustri <xliff:g id="NUMBER_0">%d</xliff:g> korda valesti.\n\nProovige <xliff:g id="NUMBER_1">%d</xliff:g> sekundi pärast uuesti."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Olete üritanud <xliff:g id="NUMBER_0">%d</xliff:g> korda tahvelarvutit valesti avada. Pärast veel <xliff:g id="NUMBER_1">%d</xliff:g> ebaõnnestunud katset lähtestatakse tahvelarvuti tehase vaikeseadetele ja kõik kasutajaandmed lähevad kaotsi."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Olete üritanud <xliff:g id="NUMBER_0">%d</xliff:g> korda telefoni valesti avada. Pärast veel <xliff:g id="NUMBER_1">%d</xliff:g> ebaõnnestunud katset lähtestatakse telefon tehase vaikeseadetele ja kõik kasutajaandmed lähevad kaotsi."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Olete püüdnud tahvelarvutit <xliff:g id="NUMBER">%d</xliff:g> korda valesti avada. Tahvelarvuti lähtestatakse nüüd tehase vaikeseadetele."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Olete püüdnud telefoni <xliff:g id="NUMBER">%d</xliff:g> korda valesti avada. Telefon lähtestatakse nüüd tehase vaikeseadetele."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Joonistasite oma avamismustri <xliff:g id="NUMBER_0">%d</xliff:g> korda valesti. Pärast veel <xliff:g id="NUMBER_1">%d</xliff:g> ebaõnnestunud katset palutakse teil tahvelarvuti avada meilikontoga.\n\n Proovige uuesti <xliff:g id="NUMBER_2">%d</xliff:g> sekundi pärast."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Joonistasite oma avamismustri <xliff:g id="NUMBER_0">%d</xliff:g> korda valesti. Pärast veel <xliff:g id="NUMBER_1">%d</xliff:g> ebaõnnestunud katset palutakse teil telefon avada meilikontoga.\n\n Proovige uuesti <xliff:g id="NUMBER_2">%d</xliff:g> sekundi pärast."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Eemalda"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"Nupp Eelmine lugu"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"Nupp Järgmine lugu"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Nupp Peata"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Nupp Esita"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Nupp Peata"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Teenus puudub."</string>
-</resources>
diff --git a/packages/Keyguard/res/values-fa/strings.xml b/packages/Keyguard/res/values-fa/strings.xml
index 4b0bce5..83c5a34 100644
--- a/packages/Keyguard/res/values-fa/strings.xml
+++ b/packages/Keyguard/res/values-fa/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"دکمه توقف موقت"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"دکمه پخش"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"دکمه توقف"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"رأی موافق"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"رأی مخالف"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"قلب"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"برای ادامه قفل را باز کنید"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"راه‌اندازی لغو شد"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"جهت حذف، <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> را بکشید."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> پاک نخواهد شد."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-fi/strings.xml b/packages/Keyguard/res/values-fi/strings.xml
index 68d8227..dbca50d 100644
--- a/packages/Keyguard/res/values-fi/strings.xml
+++ b/packages/Keyguard/res/values-fi/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Tauko-painike"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Toista-painike"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Keskeytä-painike"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Tykkään"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"En tykkää"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Sydän"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Jatka poistamalla lukitus"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Käynnistys peruutettu"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Poista <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> pudottamalla."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Kohdetta <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ei poisteta."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-fr-rCA/strings.xml b/packages/Keyguard/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 8d07cfd..0000000
--- a/packages/Keyguard/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"Saisissez le NIP."</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"Saisissez la clé PUK et le nouveau NIP."</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"Clé PUK"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Nouveau NIP"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Appuyer pour saisir mot passe"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Saisissez le mot de passe pour déverrouiller le clavier."</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Saisissez le NIP pour déverrouiller le clavier."</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"NIP erroné."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Pour déverrouiller le téléphone, appuyez sur \"Menu\", puis sur 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Nombre maximal autorisé de tentatives Face Unlock atteint."</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Chargé"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"En charge (<xliff:g id="NUMBER">%d</xliff:g> <xliff:g id="PERCENT">%%</xliff:g>)"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"Branchez votre chargeur."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Appuyez sur \"Menu\" pour déverrouiller l\'appareil."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"Réseau verrouillé"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"Aucune carte SIM"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"Aucune carte SIM n\'est insérée dans la tablette."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"Aucune carte SIM n\'est insérée dans le téléphone."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"Insérez une carte SIM."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"Carte SIM absente ou illisible. Veuillez insérer une carte SIM."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"Carte SIM inutilisable."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"Votre carte SIM a été définitivement désactivée.\n Veuillez contacter votre opérateur de téléphonie mobile pour en obtenir une autre."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"La carte SIM est verrouillée."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"La carte SIM est verrouillée par clé PUK."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"Déverrouillage de la carte SIM en cours…"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Widget %2$d sur %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Ajouter un widget"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Vide"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Développement de la zone de déverrouillage"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Réduction de la zone de déverrouillage"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"Widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Sélecteur d\'utilisateur"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"État"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Caméra"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Commandes multimédias"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Début de la réorganisation des widgets"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Fin de la réorganisation des widgets"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Le widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> a été supprimé."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Développer la zone de déverrouillage"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Déverrouillage en faisant glisser votre doigt sur l\'écran"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Déverrouillage par schéma"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Déverrouillage par reconnaissance faciale"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Déverrouillage par NIP"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Déverrouillage par mot de passe"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Zone du schéma"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Zone où faire glisser votre doigt sur l\'écran"</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"Bouton pour revenir au titre précédent"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"Bouton pour atteindre le titre suivant"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Bouton de pause"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Bouton de lecture"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Bouton d\'arrêt"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"J\'aime"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Je n\'aime pas"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Cœur"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Déverrouiller pour continuer"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Lancement annulé"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Déposez <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> pour supprimer."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ne sera pas supprimé."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Annuler"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Supprimer"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Terminé"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Changement de mode"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Maj"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Entrée"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Déverrouiller"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Appareil photo"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Mode silencieux"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Son activé"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Recherche"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"Faire glisser le doigt vers le haut : <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"Faire glisser le doigt vers le bas : <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"Faites glisser votre doigt vers la gauche pour <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"Faites glisser votre doigt vers la droite pour <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Utilisateur actuel : <xliff:g id="NAME">%1$s</xliff:g>"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Appel d\'urgence"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"J\'ai oublié le schéma"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Schéma incorrect."</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Mot de passe incorrect."</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"NIP incorrect."</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Réessayez dans <xliff:g id="NUMBER">%d</xliff:g> secondes."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Dessinez votre schéma."</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Saisissez le NIP de la carte SIM"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"Saisissez le NIP."</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Saisissez votre mot de passe."</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"La carte SIM est maintenant désactivée. Saisissez le code PUK pour continuer. Contactez votre opérateur pour en savoir plus."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Saisir le NIP souhaité"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Confirmer le NIP souhaité"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"Déblocage de la carte SIM en cours…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"NIP erroné."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"Saisissez un NIP comprenant entre quatre et huit chiffres"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"Le code PUK doit contenir au moins 8 chiffres."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Veuillez saisir de nouveau le code PUK correct. Des tentatives répétées désactivent définitivement la carte SIM."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"Les codes PIN ne correspondent pas."</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Trop de tentatives."</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Pour déverrouiller l\'appareil, connectez-vous avec votre compte Google."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Nom d\'utilisateur (courriel)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Mot de passe"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Connexion"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Nom d\'utilisateur ou mot de passe non valide."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Vous avez oublié votre nom d\'utilisateur ou votre mot de passe?\nRendez-vous sur la page "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Vérification du compte en cours…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Vous avez saisi un NIP incorrect à <xliff:g id="NUMBER_0">%d</xliff:g> reprises. \n\nVeuillez réessayer dans <xliff:g id="NUMBER_1">%d</xliff:g> secondes."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Vous avez saisi un mot de passe incorrect à <xliff:g id="NUMBER_0">%d</xliff:g> reprises. \n\nVeuillez réessayer dans <xliff:g id="NUMBER_1">%d</xliff:g> secondes."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Vous avez dessiné un schéma de déverrouillage incorrect à <xliff:g id="NUMBER_0">%d</xliff:g> reprises.\n\nVeuillez réessayer dans <xliff:g id="NUMBER_1">%d</xliff:g> secondes."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Vous avez tenté de déverrouiller la tablette de façon incorrecte à <xliff:g id="NUMBER_0">%d</xliff:g> reprises. Si vous échouez encore <xliff:g id="NUMBER_1">%d</xliff:g> fois, sa configuration d\'usine sera rétablie, et toutes les données utilisateur seront perdues."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Vous avez tenté de déverrouiller le téléphone de façon incorrecte à <xliff:g id="NUMBER_0">%d</xliff:g> reprises. Si vous échouez encore <xliff:g id="NUMBER_1">%d</xliff:g> fois, sa configuration d\'usine sera rétablie, et toutes les données utilisateur seront perdues."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Vous avez tenté de déverrouiller la tablette de façon incorrecte à <xliff:g id="NUMBER">%d</xliff:g> reprises. Sa configuration d\'usine va être rétablie."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Vous avez tenté de déverrouiller le téléphone de façon incorrecte à <xliff:g id="NUMBER">%d</xliff:g> reprises. Sa configuration d\'usine va être rétablie."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Vous avez dessiné un schéma de déverrouillage incorrect à <xliff:g id="NUMBER_0">%d</xliff:g> reprises. Si vous échouez encore <xliff:g id="NUMBER_1">%d</xliff:g> fois, vous devrez déverrouiller votre tablette à l\'aide d\'un compte de messagerie électronique.\n\n Veuillez réessayer dans <xliff:g id="NUMBER_2">%d</xliff:g> secondes."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Vous avez dessiné un schéma de déverrouillage incorrect à <xliff:g id="NUMBER_0">%d</xliff:g> reprises. Si vous échouez encore <xliff:g id="NUMBER_1">%d</xliff:g> fois, vous devrez déverrouiller votre téléphone à l\'aide d\'un compte de messagerie électronique.\n\n Veuillez réessayer dans <xliff:g id="NUMBER_2">%d</xliff:g> secondes."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Supprimer"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"Bouton pour revenir au titre précédent"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"Bouton pour atteindre le titre suivant"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Bouton de pause"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Bouton de lecture"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Bouton d\'arrêt"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Aucun service"</string>
-</resources>
diff --git a/packages/Keyguard/res/values-fr/strings.xml b/packages/Keyguard/res/values-fr/strings.xml
index 37fb8fb..250a136 100644
--- a/packages/Keyguard/res/values-fr/strings.xml
+++ b/packages/Keyguard/res/values-fr/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Bouton de pause"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Bouton de lecture"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Bouton d\'arrêt"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"J\'aime"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Je n\'aime pas"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Cœur"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Déverrouillez l\'appareil pour continuer."</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Lancement annulé."</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Relâchez le widget \"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>\" pour le supprimer."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Le widget \"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>\" ne va pas être supprimé."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-hi/strings.xml b/packages/Keyguard/res/values-hi/strings.xml
index 058a2f7..714d9fb 100644
--- a/packages/Keyguard/res/values-hi/strings.xml
+++ b/packages/Keyguard/res/values-hi/strings.xml
@@ -60,24 +60,17 @@
     <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"विजेट <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> को हटा दिया गया."</string>
     <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"अनलॉक क्षेत्र विस्तृत करें."</string>
     <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"स्लाइड अनलॉक."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"आकार अनलॉक."</string>
+    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"प्रतिमान अनलॉक."</string>
     <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"फेस अनलॉक."</string>
     <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"पिन अनलॉक."</string>
     <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"पासवर्ड अनलॉक."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"आकार क्षेत्र."</string>
+    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"प्रतिमान क्षेत्र."</string>
     <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"स्लाइड क्षेत्र."</string>
     <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"पिछला ट्रैक बटन"</string>
     <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"अगला ट्रैक बटन"</string>
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"पॉज़ करें बटन"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"चलाएं बटन"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"रोकें बटन"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"पसंद"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"नापसंद"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"दिल"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"जारी रखने के लिए अनलॉक करें"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"लॉन्‍च रद्द कर दिया गया"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"हटाने के लिए <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> खींचें."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> को नहीं हटाया जाएगा."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
@@ -99,12 +92,12 @@
     <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> के लिए दाएं स्‍लाइड करें."</string>
     <string name="user_switched" msgid="3768006783166984410">"वर्तमान उपयोगकर्ता <xliff:g id="NAME">%1$s</xliff:g>."</string>
     <string name="kg_emergency_call_label" msgid="684946192523830531">"आपातकालीन कॉल"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"आकार भूल गए"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"गलत आकार"</string>
+    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"प्रतिमान भूल गए"</string>
+    <string name="kg_wrong_pattern" msgid="1850806070801358830">"गलत प्रतिमान"</string>
     <string name="kg_wrong_password" msgid="2333281762128113157">"गलत पासवर्ड"</string>
     <string name="kg_wrong_pin" msgid="1131306510833563801">"गलत PIN"</string>
     <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"अपना आकार आरेखित करें"</string>
+    <string name="kg_pattern_instructions" msgid="398978611683075868">"अपना प्रतिमान आरेखित करें"</string>
     <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"सिम PIN डालें"</string>
     <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN डालें"</string>
     <string name="kg_password_instructions" msgid="5753646556186936819">"पासवर्ड डालें"</string>
@@ -117,23 +110,23 @@
     <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK कोड 8 या अधिक संख्या वाला होना चाहिए."</string>
     <string name="kg_invalid_puk" msgid="3638289409676051243">"सही PUK कोड पुन: डालें. बार-बार प्रयास करने से सिम स्थायी रूप से अक्षम हो जाएगी."</string>
     <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"पिन कोड का मिलान नहीं होता"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"बहुत अधिक आकार प्रयास"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"अनलॉक करने के लिए, अपने Google खाते से प्रवेश करें."</string>
+    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"बहुत अधिक प्रतिमान प्रयास"</string>
+    <string name="kg_login_instructions" msgid="1100551261265506448">"अनलॉक करने के लिए, अपने Google खाते से साइन इन करें."</string>
     <string name="kg_login_username_hint" msgid="5718534272070920364">"उपयोगकर्ता नाम (ईमेल)"</string>
     <string name="kg_login_password_hint" msgid="9057289103827298549">"पासवर्ड"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"प्रवेश करें"</string>
+    <string name="kg_login_submit_button" msgid="5355904582674054702">"साइन इन करें"</string>
     <string name="kg_login_invalid_input" msgid="5754664119319872197">"अमान्य उपयोगकर्ता नाम या पासवर्ड."</string>
     <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"अपना उपयोगकर्ता नाम या पासवर्ड भूल गए?\n "<b>"google.com/accounts/recovery"</b>" पर जाएं."</string>
     <string name="kg_login_checking_password" msgid="1052685197710252395">"खाते की जांच की जा रही है…"</string>
     <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"आप अपना PIN <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से लिख चुके हैं. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
     <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"आप अपना पासवर्ड <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से लिख चुके हैं. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"आपने अपना अनलॉक आकार <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से आरेखित किया है. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
+    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"आपने अपना अनलॉक प्रतिमान <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से आरेखित किया है. \n\n <xliff:g id="NUMBER_1">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"आप टेबलेट को अनलॉक करने के लिए <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से प्रयास कर चुके हैं. <xliff:g id="NUMBER_1">%d</xliff:g> और असफल प्रयासों के बाद, टेबलेट फ़ैक्टरी डिफ़ॉल्ट पर रीसेट हो जाएगा और सभी उपयोगकर्ता डेटा खो जाएगा."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"आप फ़ोन को अनलॉक करने के लिए <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से प्रयास कर चुके हैं. <xliff:g id="NUMBER_1">%d</xliff:g> और असफल प्रयासों के बाद, फ़ोन फ़ैक्टरी डिफ़ॉल्ट पर रीसेट हो जाएगा और सभी उपयोगकर्ता डेटा खो जाएगा."</string>
     <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"आप टेबलेट को अनलॉक करने के लिए <xliff:g id="NUMBER">%d</xliff:g> बार गलत तरीके से प्रयास कर चुके हैं. टेबलेट अब फ़ैक्‍टरी डिफ़ॉल्‍ट पर रीसेट हो जाएगा."</string>
     <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"आप फ़ोन को अनलॉक करने के लिए <xliff:g id="NUMBER">%d</xliff:g> बार गलत तरीके से प्रयास कर चुके हैं. फ़ोन अब फ़ैक्टरी डिफ़ॉल्ट पर रीसेट हो जाएगा."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"आपने अपने अनलॉक आकार को <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से आरेखित किया है. <xliff:g id="NUMBER_1">%d</xliff:g> और असफल प्रयासों के बाद, आपसे अपने टेबलेट को किसी ईमेल खाते के उपयोग से अनलॉक करने के लिए कहा जाएगा.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"आपने अपने अनलॉक आकार को <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से आरेखित किया है. <xliff:g id="NUMBER_1">%d</xliff:g> और असफल प्रयासों के बाद, आपसे अपने फ़ोन को किसी ईमेल खाते का उपयोग करके अनलॉक करने के लिए कहा जाएगा.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"आपने अपने अनलॉक प्रतिमान को <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से आरेखित किया है. <xliff:g id="NUMBER_1">%d</xliff:g> और असफल प्रयासों के बाद, आपसे अपने टेबलेट को किसी ईमेल खाते के उपयोग से अनलॉक करने के लिए कहा जाएगा.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"आपने अपने अनलॉक प्रतिमान को <xliff:g id="NUMBER_0">%d</xliff:g> बार गलत तरीके से आरेखित किया है. <xliff:g id="NUMBER_1">%d</xliff:g> और असफल प्रयासों के बाद, आपसे अपने फ़ोन को किसी ईमेल खाते का उपयोग करके अनलॉक करने के लिए कहा जाएगा.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> सेकंड में पुन: प्रयास करें."</string>
     <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
     <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"निकालें"</string>
     <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"पिछला ट्रैक बटन"</string>
diff --git a/packages/Keyguard/res/values-hr/strings.xml b/packages/Keyguard/res/values-hr/strings.xml
index 99270a9..70e6305 100644
--- a/packages/Keyguard/res/values-hr/strings.xml
+++ b/packages/Keyguard/res/values-hr/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Gumb Pauza"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Gumb Reprodukcija"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Gumb Zaustavi"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Palac gore"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Palac dolje"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Srce"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Otključajte za nastavak"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Pokretanje je otkazano"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Ispustite widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> da biste ga izbrisali."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> neće se izbrisati."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-hu/strings.xml b/packages/Keyguard/res/values-hu/strings.xml
index 81a56c5..611602e 100644
--- a/packages/Keyguard/res/values-hu/strings.xml
+++ b/packages/Keyguard/res/values-hu/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Szünet gomb"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Lejátszás gomb"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Leállítás gomb"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Tetszik"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Nem tetszik"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Szív"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"A folytatáshoz oldja fel a billentyűzárat"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Indítás törölve"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Engedje el a(z) <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> törléséhez."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"A(z) <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> nem lesz törölve."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-hy-rAM/strings.xml b/packages/Keyguard/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 2c10d39..0000000
--- a/packages/Keyguard/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"Մուտքագրեք PIN կոդը"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"Մուտքագրեք PUK-ը և նոր PIN կոդը"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK կոդ"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Նոր PIN ծածկագիր"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Հպեք` գաղտնաբառը մուտքագրելու համար"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Մուտքագրեք գաղտնաբառը ապակողպման համար"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Մուտքագրեք PIN-ը ապակողպման համար"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Սխալ PIN ծածկագիր:"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Ապակողպման համար սեղմեք Ցանկ, ապա 0:"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Առավելագույն Դեմքով ապակողպման փորձերը գերազանցված են"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Լիցքավորված է"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"Լիցքավորում, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"Միացրեք ձեր լիցքավորիչը:"</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Ապակողպելու համար սեղմեք Ցանկը:"</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"Ցանցը կողպված է"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"SIM քարտ չկա"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"Գրասալիկում SIM քարտ չկա:"</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"Հեռախոսի մեջ SIM քարտ չկա:"</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"Զետեղեք SIM քարտը:"</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"SIM քարտը բացակայում է կամ չի կարող կարդացվել: Մտցրեք SIM քարտ:"</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"Անպիտան SIM քարտ:"</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"Ձեր SIM քարտը ընդմիշտ կասեցվել է:\nԿապվեք ձեր բջջային ծառայության մատակարարի հետ նոր SIM քարտ ձեռք բերելու համար:"</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"SIM քարտը կողպված է:"</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"SIM քարտը PUK-ով կողպված է:"</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"SIM քարտը ապակողպվում է..."</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Վիջեթ %2$d of %3$d:"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Ավելացնել վիջեթ:"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Դատարկ"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Ապակողպման տարածքն ընդլայնված է:"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Ապակողպման տարածքը ետ է ծալված:"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> վիջեթ:"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Օգտվողի ընտրիչ"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Կարգավիճակ"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Ֆոտոխցիկ"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Մեդիա կարգավորումներ"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Վիջեթների վերադասավորումը մեկնարկել է:"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Վիջեթի վերադասավորումն ավարտվեց:"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Վիջեթ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>-ը ջնջված է:"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Ընդլայնել ապակողպման տարածությունը:"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Էջի ապակողպում:"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Սխեմայով ապակողպում:"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Դեմքով ապակողպում:"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Pin-ն ապակողպված է:"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Գաղտնաբառի ապակողպում:"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Սխեմայի տարածք:"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Սահեցման տարածք:"</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"Նախորդ հետագծի կոճակը"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"Հաջորդ հետագծի կոճակը"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Դադարի կոճակ"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Նվագարկման կոճակ"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Կանգի կոճակ"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Լավն է"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Լավը չէ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Սիրտ"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Շարունակելու համար ապակողպեք"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Գործարկումը չեղարկվեց"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> վիջեթը ջնջելու համար բաց թողեք այն այստեղ:"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> վիջեթը չի ջնջվի:"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Չեղարկել"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Ջնջել"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Կատարված է"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Ռեժիմի փոփոխում"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Մուտք"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Ապակողպել"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Ֆոտոխցիկ"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Լուռ"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Ձայնը միացնել"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Որոնել"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"Սահեցրեք վերև <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"Սահեցրեք ցած <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"Սահեցրեք ձախ` <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"Սահեցրեք աջ` <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-ի համար:"</string>
-    <string name="user_switched" msgid="3768006783166984410">"Ներկայիս օգտվողը <xliff:g id="NAME">%1$s</xliff:g>:"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Արտակարգ իրավիճակի հեռախոսազանգ"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Մոռացել եմ սխեման"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Սխալ սխեմա"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Սխալ գաղտնաբառ"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"Սխալ PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Փորձեք կրկին <xliff:g id="NUMBER">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Հավաքեք ձեր սխեման"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Մուտքագրեք SIM-ի PIN-ը"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"Մուտքագրեք PIN-ը"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Մուտքագրեք գաղտնաբառը"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM-ը այս պահին անջատված է: Մուտքագրեք PUK կոդը շարունակելու համար: Մանրամասների համար կապվեք օպերատորի հետ:"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Մուտքագրեք ցանկալի PIN ծածկագիրը"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Հաստատեք ցանկալի PIN ծածկագիրը"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"Ապակողպում է SIM քարտը ..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Սխալ PIN ծածկագիր:"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"Մուտքագրեք PIN, որը 4-ից 8 թիվ է:"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK կոդը պետք է լինի 8 կամ ավելի թիվ:"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Վերամուտքագրեք ճիշտ PUK ծածկագիրը: Կրկնվող փորձերը ընդմիշտ կկասեցնեն SIM քարտը:"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN ծածկագրերը չեն համընկնում"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Չափից շատ սխեմայի փորձեր"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Ապակողպելու համար` մուտք գործեք ձեր Google հաշվով:"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Օգտանուն (էլփոստ)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Գաղտնաբառը"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Մուտք գործել"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Սխալ օգտանուն կամ գաղտնաբառ:"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Մոռացե՞լ եք ձեր օգտանունը կամ գաղտնաբառը:\nԱյցելեք "<b>"google.com /accounts/recovery"</b>":"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Հաշիվը ստուգվում է..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք մուտքագրել ձեր PIN-ը: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Դուք սխալ եք մուտքագրել ձեր գաղտնաբառը <xliff:g id="NUMBER_0">%d</xliff:g> անգամ: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման սխեման: \n\nՓորձեք կրկին <xliff:g id="NUMBER_1">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ փորձ եք արել գրասալիկն ապակողպելու համար: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո գրասալիկը կվերակարգավորվի գործարանային լռելյայնի, և օգտվողի բոլոր տվյալները կկորեն:"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ փորձ եք արել հեռախոսն ապակողպելու համար: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո հեռախոսը կվերակարգավորվի գործարանային լռելյայնի, և օգտվողի բոլոր տվյալները կկորեն:"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Դուք <xliff:g id="NUMBER">%d</xliff:g> անգամ սխալ փորձ եք արել գրասալիկն ապակողպելու համար: Գրասալիկն այժմ կվերակարգավորվի գործարանային լռելյայնի:"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Դուք <xliff:g id="NUMBER">%d</xliff:g> անգամ սխալ փորձ եք արել հեռախոսն ապակողպելու համար: Հեռախոսն այժմ կվերակարգավորվի գործարանային լռելյայնի:"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Դուք սխալ եք հավաքել ձեր ապակողպման սխեման <xliff:g id="NUMBER_0">%d</xliff:g> անգամ: Եվս <xliff:g id="NUMBER_1">%d</xliff:g> անհաջող փորձից հետո ձեզանից կպահանջվի ապակողպել ձեր գրասալիկը` օգտագործելով էլփոստի հաշիվ:\n\n Փորձեք կրկին <xliff:g id="NUMBER_2">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Դուք <xliff:g id="NUMBER_0">%d</xliff:g> անգամ սխալ եք հավաքել ձեր ապակողպման նմուշը: <xliff:g id="NUMBER_1">%d</xliff:g> անգամից ավել անհաջող փորձերից հետո ձեզ կառաջարկվի ապակողպել ձեր հեռախոսը` օգտագործելով էլփոստի հաշիվ:\n\n Փորձեք կրկին <xliff:g id="NUMBER_2">%d</xliff:g> վայրկյանից:"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Հեռացնել"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"Նախորդ հետագծի կոճակ"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"Հաջորդ հետագծի կոճակ"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Դադարի կոճակ"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Նվագարկման կոճակ"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Դադարի կոճակ"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Ծառայություն չկա:"</string>
-</resources>
diff --git a/packages/Keyguard/res/values-in/strings.xml b/packages/Keyguard/res/values-in/strings.xml
index 3b2de3d..9f731ab 100644
--- a/packages/Keyguard/res/values-in/strings.xml
+++ b/packages/Keyguard/res/values-in/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Tombol jeda"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Tombol putar"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Tombol hentikan"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Bagus"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Jelek"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Hati"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Buka kunci untuk melanjutkan"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Peluncuran dibatalkan"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Jatuhkan <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> untuk menghapus."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> tidak akan dihapus."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-it/strings.xml b/packages/Keyguard/res/values-it/strings.xml
index 360f0b5..4eda348 100644
--- a/packages/Keyguard/res/values-it/strings.xml
+++ b/packages/Keyguard/res/values-it/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pulsante Pausa"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Pulsante Riproduci"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Pulsante di arresto"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Mi piace"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Pollice giù"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Cuore"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Sblocca per continuare"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Avvio annullato"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Rilascia <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> per eliminarlo."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> non sarà eliminato."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-iw/strings.xml b/packages/Keyguard/res/values-iw/strings.xml
index e6218b1..8d36309 100644
--- a/packages/Keyguard/res/values-iw/strings.xml
+++ b/packages/Keyguard/res/values-iw/strings.xml
@@ -29,7 +29,7 @@
     <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"הקלד קוד PIN לביטול הנעילה"</string>
     <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"קוד PIN שגוי"</string>
     <string name="keyguard_label_text" msgid="861796461028298424">"כדי לבטל את הנעילה, לחץ על \'תפריט\' ולאחר מכן על 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"חרגת ממספר הניסיונות המרבי של זיהוי פנים"</string>
+    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"חרגת ממספר הניסיונות המרבי של זיהוי פרצוף"</string>
     <string name="keyguard_charged" msgid="3272223906073492454">"טעון"</string>
     <string name="keyguard_plugged_in" msgid="8117572000639998388">"טוען, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
     <string name="keyguard_low_battery" msgid="8143808018719173859">"חבר את המטען."</string>
@@ -61,7 +61,7 @@
     <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"הרחב את אזור ביטול הנעילה."</string>
     <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"ביטול נעילה באמצעות הסטה."</string>
     <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"ביטול נעילה באמצעות ציור קו."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"ביטול נעילה באמצעות זיהוי פנים."</string>
+    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"ביטול נעילה באמצעות זיהוי פרצוף."</string>
     <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"ביטול נעילה באמצעות מספר PIN."</string>
     <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"ביטול נעילה באמצעות סיסמה."</string>
     <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"אזור ציור קו."</string>
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"לחצן \'השהה\'"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"לחצן \'הפעל\'"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"לחצן \'הפסק\'"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"אהבתי"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"לא אהבתי"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"לב"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"בטל נעילה כדי להמשיך"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"ההפעלה בוטלה"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"שחרר את <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> למחיקה."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> לא יימחק."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"אבג"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-ja/strings.xml b/packages/Keyguard/res/values-ja/strings.xml
index c7e0447..92e308b 100644
--- a/packages/Keyguard/res/values-ja/strings.xml
+++ b/packages/Keyguard/res/values-ja/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"一時停止ボタン"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"再生ボタン"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"停止ボタン"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"グッド"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"イマイチ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"ハート"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"続行するにはロックを解除してください"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"起動をキャンセルしました"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"削除するには<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>をドロップしてください。"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>は削除されません。"</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-ka-rGE/strings.xml b/packages/Keyguard/res/values-ka-rGE/strings.xml
deleted file mode 100644
index f643178..0000000
--- a/packages/Keyguard/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"აკრიფეთ PIN კოდი"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"დაბეჭდეთ PUK კოდი და ახალი PIN კოდი."</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK კოდი"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"ახალი PIN კოდი"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384">"შეეხეთ "<font size="17">"-ს პაროლის"</font>" დასაბეჭდად."</string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"განსაბლოკად აკრიფეთ პაროლი"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"განსაბლოკად აკრიფეთ PIN კოდი"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"არასწორი PIN კოდი."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"განბლოკვისათვის დააჭირეთ მენიუს და შემდეგ 0-ს."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"სახის ამოცნობით განბლოკვის მცდელობამ დაშვებულ რაოდენობას გადააჭარბა"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"დამუხტულია"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"მიმდინარეობს დამუხტვა (<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>)"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"შეაერთეთ დამტენი."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"განბლოკვისთვის დააჭირეთ მენიუს."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"ქსელი ჩაკეტილია"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"SIM ბარათი არ არის"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"ტაბლეტში არ დევს SIM ბარათი."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"არ არის SIM ბარათი ტელეფონში."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"ჩადეთ SIM ბარათი."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"SIM ბარათი არ არის ან არ იკითხება. ჩადეთ SIM ბარათი."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"არამოხმარებადი SIM ბარათი."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"თქვენი SIM ბარათი გამუდმებით გამორთული იყო.\n დაუკავშირდით თქვენი უკაბელო სერვისის პროვაიდერს სხვა SIM ბარათისთვის."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"SIM ბარათი დაბლოკილია."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"SIM ბარათი დაბლოკილია PUK კოდით."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"მიმდინარეობს SIM ბარათის განბლოკვა…"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. ვიჯეტი %2$d of %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"ვიჯეტის დამატება"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"ცარიელი"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"განბლოკვის სივრცე გაშლილია."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"განბლოკვის სივრცე ჩაკეცილია."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ვიჯეტი."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"მომხმარებლის ამომრჩეველი"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"სტატუსი"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"კამერა"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"მედიის მართვის ელემენტები"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"დაიწყო ვიჯეტის ხელახლა განლაგება."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"ვიჯეტების გადახარისხება დასრულებულია."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"ვიჯეტი <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> წაიშალა."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"განბლოკვის სივრცის გაშლა."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"გასრიალებით განბლოკვა"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"განბლოკვა ნიმუშით."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"განბლოკვა სახით"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"განბლოკვა Pin-ით."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"პაროლის განბლოკვა"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ნიმუშების სივრცე."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"გადასრიალების სივრცე."</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"წინა ჩანაწერის ღილაკი"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"შემდეგი ჩანაწერის ღილაკი"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"პაუზის ღილაკი"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"დაკვრის ღილაკი"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stop ღილაკი"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"ზევით აწეული ცერი"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"ქვევით დახრილი ცერი"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"გული"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"განბლოკეთ გასაგრძელებლად"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"გამოძახება გაუქმდა"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"ჩააგდეთ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> წასაშლელად."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> არ წაიშლება."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"გაუქმება"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"წაშლა"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"დასრულდა"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"რეჟიმის შეცვლა"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift-"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"შეყვანა"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"განბლოკვა"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"კამერა"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"უხმო"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"ხმის ჩართვა"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"ძიება"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"გაასრიალეთ ზემოთ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"გაასრიალეთ ქვემოთ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"გაასრიალეთ მარცხნივ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"გაასრიალეთ მარჯვნივ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-თვის."</string>
-    <string name="user_switched" msgid="3768006783166984410">"ამჟამინდელი მომხმარებელი <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"გადაუდებელი დახმარების ზარი"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"დაგავიწყდათ ნიმუში"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"არასწორი ნიმუში"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"არასწორი პაროლი"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"არასწორი PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"კიდევ სცადეთ <xliff:g id="NUMBER">%d</xliff:g> წამში."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"დახატეთ თქვენი ნიმუში."</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN-ის შეყვანა"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"შეიყვანეთ PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"პაროლის შეყვანა"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM ამჟამად დეაქტივირებულია. გასაგრძელებლად შეიყვანეთ PUK კოდი. დეტალებისთვის მიმართეთ მობილურ ოპერატორს."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"სასურველი PIN კოდის შეყვანა"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"სასურველი PIN კოდის დადასტურება"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM ბარათის განბლოკვა…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"არასწორი PIN კოდი."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"აკრიფეთ PIN, რომელიც შედგება 4-დან 8 ციფრამდე."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK კოდი უნდა იყოს რვა ან მეტი ციფრისგან შემდგარი."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"ხელახლა შეიყვანეთ სწორი PUK კოდი. რამდენიმე წარუმატებელი მცდელობა გამოიწვევს SIM ბარათის დაბლოკვას."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN კოდები არ ემთხვევა"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"ნახატი ნიმუშის ძალიან ბევრი მცდელობა"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"განბლოკვისთვის გაიარეთ ავტორიზაცია თქვენი Google  ანგარიშით."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"მომხმარებლის სახელი (ელფოსტა)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"პაროლი"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"შესვლა"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"არასწორი სახელი, ან პაროლი."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"დაგავიწყდათ მომხმარებლის სახელი და პაროლი?\nეწვიეთ "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"მიმდინარეობს ანგარიშის შემოწმება…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ არასწორად შეიყვანეთ PIN კოდი. \n\nსცადეთ ხელახლა <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ არასწორად დაბეჭდეთ თქვენი პაროლი. \n\nხელახლა სცადეთ <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"თქვენ <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ დახატეთ განბლოკვის ნიმუში. \n\nსცადეთ ხელახლა <xliff:g id="NUMBER_1">%d</xliff:g> წამში."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"თქვენ არასწორად სცადეთ ტაბლეტის განბლოკვა <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ ტაბლეტზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"თქვენ არასწორად სცადეთ ტელეფონის განბლოკვა <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ ტელეფონზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"თქვენ არასწორად სცადეთ ტაბლეტის განბლოკვა <xliff:g id="NUMBER">%d</xliff:g>-ჯერ. ტაბლეტზე დაყენდება საწყისი, ქარხნული პარამეტრები და მომხმარებლის ყველა მონაცემი დაიკარგება."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"თქვენ <xliff:g id="NUMBER">%d</xliff:g>-ჯერ არასწორად სცადეთ ტელეფონის განბლოკვა. ამიტომ ტელეფონზე დადგება საწყისი, ქარხნული პარამეტრები."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"თქვენ არასწორად დახატეთ თქვენი განბლოკვის ნიმუში <xliff:g id="NUMBER_0">%d</xliff:g> ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ მოგთხოვთ ტაბლეტის განბლოკვას ელფოსტის ანგარიშის გამოყენებით.\n\n ხელახლა სცადეთ <xliff:g id="NUMBER_2">%d</xliff:g> წამში."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"თქვენ არასწორად დახატეთ თქვენი განბლოკვის ნიმუში <xliff:g id="NUMBER_0">%d</xliff:g>-ჯერ. კიდევ <xliff:g id="NUMBER_1">%d</xliff:g> წარუმატებელი ცდის შემდეგ, დაგჭირდებათ თქვენი ტელეფონის განბლოკვა ელფოსტის ანგარიშის გამოყენებით.\n\n ხელახლა სცადეთ <xliff:g id="NUMBER_2">%d</xliff:g> წამში."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"ამოშლა"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"წინა ჩანაწერზე გადასვლის ღილაკი"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"შემდეგი ჩანაწერის ღილაკი"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"პაუზის ღილაკი"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"დაკვრის ღილაკი"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"შეჩერების ღილაკი"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"არ არის სერვისი."</string>
-</resources>
diff --git a/packages/Keyguard/res/values-km-rKH/strings.xml b/packages/Keyguard/res/values-km-rKH/strings.xml
deleted file mode 100644
index 08af5dd..0000000
--- a/packages/Keyguard/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"បញ្ចូល​កូដ PIN"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"បញ្ចូល​កូដ PUK និង​ PIN ថ្មី"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"កូដ PUK"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"កូដ PIN ថ្មី"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"ប៉ះ ដើម្បី​បញ្ចូល​ពាក្យ​សម្ងាត់"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"បញ្ចូល​ពាក្យ​សម្ងាត់​ ​ដើម្បី​ដោះ​សោ"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"បញ្ចូល​កូដ PIN ដើម្បី​ដោះ​សោ"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"កូដ PIN មិន​ត្រឹមត្រូវ។"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"ដើម្បី​ដោះ​សោ​​ ចុច​ម៉ឺនុយ​ បន្ទាប់មក 0 ។"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"បាន​លើស​ការ​ព្យាយាម​ដោះ​សោ​តាម​ទម្រង់​មុខ"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"បាន​បញ្ចូល​​ពេញ"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"បញ្ចូល​ថ្ម <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"ភ្ជាប់​ឧបករណ៍​បញ្ចូល​ថ្ម​។"</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"ចុច​ម៉ឺនុយ ដើម្បី​ដោះ​សោ។"</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"បណ្ដាញ​ជាប់​សោ"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"គ្មាន​ស៊ី​ម​កាត"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"គ្មាន​ស៊ី​ម​កាត​នៅ​ក្នុង​កុំព្យូទ័រ​បន្ទះ​។"</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"គ្មាន​ស៊ីមកាត​ក្នុង​ទូរស័ព្ទ។"</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"បញ្ចូល​​​ស៊ី​ម​កាត​។"</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"បាត់​ស៊ីមកាត ឬ​មិន​អាច​អាន។ បញ្ចូល​ស៊ីម​កាត។"</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"ស៊ីម​កាត​មិន​អាច​ប្រើ​បាន។"</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"បាន​បិទ​ស៊ីម​កាត​របស់​អ្នក​ជា​អចិន្ត្រៃយ៍។\n ទាក់ទង​​ក្រុមហ៊ុន​ផ្ដល់​សេវាកម្ម​ឥត​ខ្សែ​សម្រាប់​ស៊ីម​កាត​ផ្សេង។"</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"ស៊ីម​កាត​​ជាប់​សោ។"</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"ស៊ីម​កាត​ជាប់​កូដ​​ PUK ។"</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"កំពុង​ដោះ​សោ​ស៊ីម​កាត..."</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. ធាតុ​ក្រាហ្វិក %2$d នៃ %3$d ។"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"បន្ថែម​ធាតុ​ក្រាហ្វិក​។"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"ទទេ"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"បាន​ពង្រីក​ផ្ទៃ​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"បាន​បង្រួម​ផ្ទៃ​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ធាតុ​ក្រាហ្វិក។"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"ឧបករណ៍​ជ្រើស​អ្នក​ប្រើ"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"ស្ថានភាព"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"ម៉ាស៊ីន​ថត"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"ពិនិត្យ​មេឌៀ"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"បាន​ចាប់ផ្ដើម​តម្រៀប​ធាតុ​ក្រាហ្វិក​ឡើងវិញ។"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"បាន​បញ្ចប់​ការ​បង្ហាញ​ធាតុ​ក្រាហ្វិក។"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"បាន​លុប​ធាតុ​ក្រាហ្វិក <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ។"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"ពង្រីក​តំបន់​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"រុញ​ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"លំនាំ​ដោះ​សោ​។"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"ដោះ​សោ​តាម​​ទម្រង់​មុខ។"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"កូដ PIN ដោះ​សោ។"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"ពាក្យ​សម្ងាត់​ដោះ​សោ​។"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ផ្ទៃ​លំនាំ។"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"ផ្ទៃ​រុញ។"</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"ប៊ូតុង​បទ​មុន"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"ប៊ូតុង​បទ​បន្ទាប់"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"ប៊ូតុង​ផ្អាក"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"ប៊ូតុង​ចាក់"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"ប៊ូតុង​បញ្ឈប់"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"មេដៃ​ឡើង"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"មេដៃ​ចុះ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"បេះដូង"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"ដោះ​សោ ​ដើម្បី​បន្ត"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"បាន​បោះបង់​ការ​ចាប់ផ្ដើម"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"ទម្លាក់ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ដើម្បី​លុប។"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> នឹង​មិន​ត្រូវ​បាន​លុប​។"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"បោះ​បង់"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"លុប"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"រួចរាល់"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"ប្ដូរ​របៀប"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Enter"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"ដោះ​​សោ"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"ម៉ាស៊ីន​ថត"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"ស្ងាត់"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"បើក​សំឡេង"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"ស្វែងរក"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"រុញ​ឡើង​លើ​ដើម្បី <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"រុញ​ចុះក្រោម​សម្រាប់ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"រុញ​ទៅ​ឆ្វេង​ដើម្បី <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"រុញ​​ទៅ​ស្ដាំ​ដើម្បី <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> ។"</string>
-    <string name="user_switched" msgid="3768006783166984410">"អ្នក​ប្រើ​បច្ចុប្បន្ន <xliff:g id="NAME">%1$s</xliff:g> ។"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"ការ​ហៅ​ពេល​អាសន្ន"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"ភ្លេច​​លំនាំ"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"លំនាំ​មិន​ត្រឹមត្រូវ"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"កូដ PIN មិន​ត្រឹមត្រូវ"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"គូរ​លំនាំ​របស់​អ្នក"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"បញ្ចូល​កូដ PIN ស៊ីម​កាត"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"បញ្ចូល​​កូដ PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"បញ្ចូល​ពាក្យ​សម្ងាត់"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"ឥឡូវ​ស៊ីមកាត​ត្រូវ​បាន​បិទ។ បញ្ចូល​កូដ PUK ដើម្បី​បន្ត។ ចំពោះ​ព័ត៌មាន​លម្អិត​ទាក់ទង​ក្រុមហ៊ុន​បញ្ជូន​របស់​អ្នក។"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"បញ្ចូល​កូដ PIN ដែល​ចង់​បាន"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"បញ្ជាក់​កូដ PIN ដែល​ចង់​បាន"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"កំពុង​ដោះ​សោ​​ស៊ីម​កាត..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"កូដ PIN មិន​ត្រឹមត្រូវ។"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"បញ្ចូល​កូដ PIN ដែល​មាន​ពី ៤ ដល់ ៨ លេខ។"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"កូដ PUK គួរ​តែ​មាន​​ ៨ លេខ ឬ​​ច្រើន​ជាង​នេះ។"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"បញ្ចូល​កូដ PUK ម្ដង​ទៀត។ ការ​ព្យាយាម​ដដែល​ច្រើន​ដឹង​នឹង​បិទ​ស៊ីម​កាត​ជា​អចិន្ត្រៃយ៍។"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"កូដ PIN មិន​ដូច​គ្នា"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"ព្យាយាម​លំនាំ​ច្រើន​ពេក"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"ដើម្បី​ដោះ​សោ ចូល​ក្នុង​គណនី Google ។"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"ឈ្មោះ​អ្នក​ប្រើ (អ៊ី​ម៉ែ​ល​)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"ពាក្យសម្ងាត់"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"ចូល"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"ឈ្មោះ​អ្នកប្រើ ឬ​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ។"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"ភ្លេច​ឈ្មោះ​អ្នកប្រើ ឬ​ពាក្យ​សម្ងាត់​របស់​អ្នក?\nមើល "<b>"google.com/accounts/recovery"</b>" ។"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"កំពុង​ពិនិត្យ​មើល​គណនី..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"អ្នក​បាន​បញ្ចូល​កូដ PIN របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"អ្នក​បាន​បញ្ចូល​ពាក្យ​សម្ងាត់​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។\n\nព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"អ្នក​បាន​​គូរ​លំនាំ​ដោះ​សោ​របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។\n\nព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_1">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​​កុំព្យូទ័រ​បន្ទះ​​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើន​ជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង កុំព្យូទ័រ​បន្ទះ​​នឹង​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោងចក្រ ហើយ​ទិន្នន័យ​អ្នកប្រើ​នឹង​បាត់បង់។"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​ទូរស័ព្ទ​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើន​ជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង ទូរស័ព្ទ​នឹង​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោងចក្រ ហើយ​ទិន្នន័យ​អ្នកប្រើ​នឹង​បាត់បង់។"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​កុំព្យូទ័រ​បន្ទះ​មិន​ត្រឹមត្រូវ​ចំនួន​ <xliff:g id="NUMBER">%d</xliff:g> ដង។ កុំព្យូទ័រ​បន្ទះ​នឹង​ត្រូវ​បាន​កំណត់​ទៅ​លំនាំដើម​ដូច​ចេញ​ពី​រោងចក្រ"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"អ្នក​បាន​ព្យាយាម​ដោះ​សោ​ទូរស័ព្ទ​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER">%d</xliff:g> ដង។ ឥឡូវ​ទូរស័ព្ទ​នឹង​កំណត់​ទៅ​លំនាំ​ដើម​ដូច​ចេញ​ពី​រោងចក្រ។"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​សោ​មិន​ត្រឹមត្រូវ <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម <xliff:g id="NUMBER_1">%d</xliff:g> ដង​មិន​ជោគជ័យ អ្នក​នឹង​ត្រូវ​បាន​ស្នើ​ឲ្យ​ដោះ​សោ​កុំព្យូទ័រ​បន្ទះ​របស់​អ្នក ដោយ​ប្រើ​គណនី​អ៊ីមែល។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_2">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"អ្នក​បាន​គូរ​លំនាំ​ដោះ​​សោ​របស់​អ្នក​មិន​ត្រឹមត្រូវ​ចំនួន <xliff:g id="NUMBER_0">%d</xliff:g> ដង។ បន្ទាប់​ពី​ការ​ព្យាយាម​មិន​ជោគជ័យ​​ច្រើនជាង <xliff:g id="NUMBER_1">%d</xliff:g> ដង អ្នក​នឹង​ត្រូវ​បាន​​ស្នើ​ឲ្យ​ដោះ​សោ​ទូរស័ព្ទ​របស់​អ្នក​ដោយ​ប្រើ​គណនី​អ៊ីមែល។\n\n ព្យាយាម​ម្ដង​ទៀត​ក្នុង​រយៈ​ពេល <xliff:g id="NUMBER_2">%d</xliff:g> វិនាទី។"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"លុប​ចេញ"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"ប៊ូតុង​បទ​មុន"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"ប៊ូតុង​បទ​បន្ទាប់"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"ប៊ូតុង​ផ្អាក"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"ប៊ូតុង​ចាក់"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"ប៊ូតុង​បញ្ឈប់"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"គ្មាន​សេវា​។"</string>
-</resources>
diff --git a/packages/Keyguard/res/values-ko/strings.xml b/packages/Keyguard/res/values-ko/strings.xml
index a1b5096..dfac106 100644
--- a/packages/Keyguard/res/values-ko/strings.xml
+++ b/packages/Keyguard/res/values-ko/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"일시중지 버튼"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"재생 버튼"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"중지 버튼"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"좋아요"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"싫어요"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"하트"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"계속하려면 잠금해제합니다."</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"실행 취소됨"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"삭제하려면 <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>을(를) 드롭합니다."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>은(는) 삭제되지 않습니다."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-lo-rLA/strings.xml b/packages/Keyguard/res/values-lo-rLA/strings.xml
deleted file mode 100644
index a9ba8ba..0000000
--- a/packages/Keyguard/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"ພິມລະຫັດ PIN"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"ພິມລະຫັດ PUK ແລະ​ລະ​ຫັດ PIN ອັນໃໝ່"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"ລະ​ຫັດ PUK"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"ລະຫັດ PIN ໃໝ່"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"ແຕະເພື່ອພິມລະຫັດຜ່ານ"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"ພິມລະຫັດເພື່ອປົດລັອກ"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"ພິມລະຫັດ PIN ເພື່ອປົດລັອກ"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"ລະຫັດ PIN ບໍ່ຖືກຕ້ອງ."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"ເພື່ອປົດລັອກ, ໃຫ້ກົດເມນູ ແລ້ວກົດ 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"ຄວາມພະຍາຍາມປົດລັອກດ້ວຍໜ້ານັ້ນ ເກີນຈຳນວນທີ່ກຳນົດແລ້ວ"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"ສາກເຕັມແລ້ວ"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"ກຳລັງສາກ, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"ເຊື່ອມຕໍ່ອຸປະກອນສາກຂອງທ່ານ."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"ກົດເມນູເພື່ອປົດລັອກ."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"ເຄືອຂ່າຍຖືກລັອກ"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"ບໍ່ມີຊິມກາດ"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"ບໍ່ມີຊິມກາດໃນແທັບເລັດ."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"ບໍ່ມີຊິມກາດຢູ່ໃນໂທລະສັບ."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"ໃສ່ SIM card."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"ບໍ່ພົບເຫັນຊິມກາດ ຫຼືບໍ່ສາມາດອ່ານຊິມກາດໄດ້. ກະລຸນາໃສ່ຊິມກາດໃໝ່."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"SIM card ບໍ່ສາມາດໃຊ້ໄດ້."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"SIM card ຂອງທ່ານຖືກປິດການນຳໃຊ້ຢ່າງຖາວອນແລ້ວ.\n ຕິດຕໍ່ຜູ່ໃຫ້ບໍລິການລະບົບຂອງທ່ານເພື່ອຂໍ SIM card ໃໝ່."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"ຊິມກາດຖືກລັອກ."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"ຊິມກາດຖືກລັອກດ້ວຍລະຫັດ PUK."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"ກຳລັງປົດລັອກຊິມກາດ..."</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. ວິດເຈັດ %2$d ຈາກທັງໝົດ %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"ເພີ່ມວິດເຈັດ"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"ຫວ່າງເປົ່າ"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"ຂະຫຍາຍພື້ນທີ່ປົດລັອກແລ້ວ."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"ຫຍໍ້ພື້ນທີ່ປົດລັອກແລ້ວ."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ວິດເຈັດ."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"ໂຕເລືອກຂອງຜູ່ໃຊ້"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"ສະຖານະ"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"ກ້ອງ"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"ການຄວບຄຸມສື່"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"ການຈັດຮຽງວິເຈັດໃໝ່ເລີ່ມຕົ້ນແລ້ວ."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"ການຈັດຮຽງວິດເຈັດຄືນໃໝ່ສຳເລັດແລ້ວ."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"ລຶບວິດເຈັດ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ແລ້ວ."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"ຂະຫຍາຍຂອບເຂດປົດລັອກ."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"ການປົດລັອກດ້ວຍການເລື່ອນ."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"ປົດລັອກດ້ວຍຮູບແບບ."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"ປົດລັອກດ້ວຍໜ້າ."</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"ປົດລັອກດ້ວຍ PIN."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"ການປົດລັອກດ້ວຍລະຫັດຜ່ານ."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"ພື້ນທີ່ຮູບແບບ."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"ເລື່ອນພື້ນທີ່."</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"ປຸ່ມເພງກ່ອນໜ້າ"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"ປຸ່ມເພງຕໍ່ໄປ"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"ປຸ່ມຢຸດຊົ່ວຄາວ"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"ປຸ່ມຫຼິ້ນ"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"ປຸ່ມຢຸດ"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"ເລື່ອນນິ້ວໂປ້ຂຶ້ນ"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"ເລື່ອນນິ້ວໂປ້ລົງ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"ຫົວໃຈ"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"ປົດລັອກເພື່ອດຳເນີນການຕໍ່"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"ການເປີດໃຊ້ຖືກຍົກເລີກ"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"ວາງ <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ເພື່ອລຶບ."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ຈະບໍ່ຖືກລຶບອອກ"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"ຍົກເລີກ"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"ລຶບ"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"ແລ້ວໆ"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"ປ່ຽນຮູບແບບ"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Enter"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"ປົດລັອກ"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"ກ້ອງ"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"ປິດສຽງ"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"ເປີດສຽງ"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"ຊອກຫາ"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"ເລື່ອນຂຶ້ນເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"ເລື່ອນລົງເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"ເລື່ອນໄປທາງຊ້າຍເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"ເລື່ອນໄປທາງຂວາເພື່ອ <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="user_switched" msgid="3768006783166984410">"ຜູ່ໃຊ້ປັດຈຸບັນ <xliff:g id="NAME">%1$s</xliff:g> ."</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"ການໂທສຸກເສີນ"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"ລືມຮູບແບບປົດລັອກ?"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"ຮູບແບບຜິດ"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"ລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"ລະຫັດ PIN ຜິດ"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"ລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"ແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານ"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"ໃສ່ລະຫັດ PIN ຂອງຊິມ"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"ໃສ່ລະຫັດ PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"ໃສ່ລະຫັດຜ່ານ"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"ຊິມຖືກປິດການນຳໃຊ້ແລ້ວ. ປ້ອນລະຫັດ PUK ເພື່ອດຳເນີນການຕໍ່. ຕິດຕໍ່ຜູ່ໃຫ້ບໍລິການສຳລັບລາຍລະອຽດ."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"ໃສ່ລະຫັດ PIN ທີ່ຕ້ອງການ."</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"ຢືນຢັນລະຫັດ PIN ທີ່ຕ້ອງການ"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"ປົດລັອກ SIM card..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"ລະຫັດ PIN ບໍ່ຖືກຕ້ອງ."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"ພິມລະຫັດ PIN ຄວາມຍາວ 4 ເຖິງ 8 ໂຕເລກ."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"ລະຫັດ PUK ຄວນມີຢ່າງໜ້ອຍ 8 ໂຕເລກ."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"ປ້ອນລະຫັດ PUK ທີ່ຖືກຕ້ອງຄືນໃໝ່. ການພະຍາຍາມໃສ່ຫຼາຍເທື່ອຈະເຮັດໃຫ້ຊິມກາດໃຊ້ບໍ່ໄດ້ຖາວອນ."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"ລະຫັດ PIN ບໍ່ກົງກັນ"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"ແຕ້ມຮູບແບບປົດລັອກຫຼາຍເກີນໄປ"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"ເພື່ອປົດລັອກ, ເຂົ້າສູ່ລະບົບດ້ວຍບັນຊີ Google ຂອງທ່ານ."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"ຊື່ຜູ່ໃຊ້ (ອີເມວ)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"ລະຫັດຜ່ານ"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"ເຂົ້າສູ່ລະບົບ"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"ຊື່ຜູ່ໃຊ້ ຫຼືລະຫັດຜ່ານບໍ່ຖືກຕ້ອງ."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"ລືມຊື່ຜູ່ໃຊ້ ຫຼືລະຫັດຜ່ານຂອງທ່ານບໍ່?\nໄປທີ່ "<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"ກຳລັງກວດສອບບັນຊີ..."</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"ທ່ານພິມລະຫັດ PIN​ ຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nກະລຸນາລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"ທ່ານພິມລະຫັດຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. \n\nກະລຸນາລອງໃໝ່ໃນອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກແທັບເລັດບໍ່ສຳເລັດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ແທັບເລັດຂອງທ່ານຈະຖືກຕັ້ງ ໃຫ້ກັບໄປໃຊ້ຄ່າເລີ່ມຕົ້ນຈາກໂຮງງານຄືນໃໝ່ ແລະຂໍ້ມູນຜູ່ໃຊ້ທັງໝົດຈະສູນຫາຍໄປ."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກໂທລະສັບບໍ່ສຳເລັດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ໂທລະສັບຂອງທ່ານຈະຖືກຕັ້ງ ໃຫ້ກັບໄປໃຊ້ຄ່າເລີ່ມຕົ້ນຈາກໂຮງງານຄືນໃໝ່ ແລະຂໍ້ມູນຜູ່ໃຊ້ທັງໝົດຈະສູນຫາຍໄປ."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກແທັບເລັດບໍ່ສຳເລັດ <xliff:g id="NUMBER">%d</xliff:g> ເທື່ອແລ້ວ. ຕອນນີ້ແທັບເລັດຈະຖືກຕັ້ງໃຫ້ກັບໄປໃຊ້ຄ່າເລີ່ມຕົ້ນຈາກໂຮງງານ."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"ທ່ານໄດ້ພະຍາຍາມປົດລັອກໂທລະສັບບໍ່ຖືກ <xliff:g id="NUMBER">%d</xliff:g> ເທື່ອແລ້ວ. ຕອນນີ້ໂທລະສັບຈະຖືກຣີເຊັດເປັນຄ່າຈາກໂຮງງານ."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກແຕ້ມຜິດອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ, ທ່ານຈະຖືກຖາມໃຫ້ປົດລັອກແທັບເລັດຂອງທ່ານ ດ້ວຍການເຂົ້າສູ່ລະບົບໂດຍໃຊ້ອີເມວຂອງທ່ານ.\n\n ກະລຸນາລອງໃໝ່ອີກຄັ້ງໃນອີກ <xliff:g id="NUMBER_2">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"ທ່ານແຕ້ມຮູບແບບປົດລັອກຂອງທ່ານຜິດ <xliff:g id="NUMBER_0">%d</xliff:g> ເທື່ອແລ້ວ. ຫຼັງຈາກຄວາມພະຍາຍາມອີກ <xliff:g id="NUMBER_1">%d</xliff:g> ເທື່ອ ທ່ານຈະຖືກຖາມໃຫ້ປົດລັອກໂທລະສັບຂອງທ່ານດ້ວຍບັນຊີອີເມວ.\n\n ລອງໃໝ່ອີກຄັ້ງໃນ <xliff:g id="NUMBER_2">%d</xliff:g> ວິນາທີ."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"ລຶບອອກ"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"ປຸ່ມເພງກ່ອນໜ້າ"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"ປຸ່ມເພງຕໍ່ໄປ"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"ປຸ່ມຢຸດຊົ່ວຄາວ"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"ປຸ່ມຫຼິ້ນ"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"ປຸ່ມຢຸດ"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"ບໍ່ມີບໍລິການ"</string>
-</resources>
diff --git a/packages/Keyguard/res/values-lt/strings.xml b/packages/Keyguard/res/values-lt/strings.xml
index 48167e8..29f62a7 100644
--- a/packages/Keyguard/res/values-lt/strings.xml
+++ b/packages/Keyguard/res/values-lt/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pristabdymo mygtukas"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Paleidimo mygtukas"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Sustabdymo mygtukas"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Patinka"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Nepatinka"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Širdis"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Jei norite tęsti, atrakinkite"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Paleidimas atšauktas"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Paleiskite „<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>“, kad jį ištrintumėte."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"„<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>“ nebus ištrintas."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-lv/strings.xml b/packages/Keyguard/res/values-lv/strings.xml
index 332e613..aa13934 100644
--- a/packages/Keyguard/res/values-lv/strings.xml
+++ b/packages/Keyguard/res/values-lv/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pārtraukšanas poga"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Atskaņošanas poga"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Apturēšanas poga"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Patīk"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Nepatīk"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Sirds"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Atbloķējiet, lai turpinātu."</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Palaišana atcelta"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Velciet logrīku <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>, lai to izdzēstu."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Logrīks <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> netiks izdzēsts."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-mn-rMN/strings.xml b/packages/Keyguard/res/values-mn-rMN/strings.xml
deleted file mode 100644
index e4c07eb..0000000
--- a/packages/Keyguard/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"PIN кодыг бичнэ үү"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"PUK-г бичээд шинэ PIN код оруулна уу"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK код"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Шинэ PIN код"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Нууц үг бичих бол хүрнэ үү"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Тайлах нууц үгийг бичнэ үү"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Тайлах PIN-г оруулна уу"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Буруу PIN код."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Тайлах бол Цэсийг дараад 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Нүүрээр түгжээ тайлах оролдлогын тоо дээд хэмжээнээс хэтэрсэн"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Цэнэглэгдэв"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"Цэнэглэж байна, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"Цэнэглэгчээ холбоно уу."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Тайлх бол цэсийг дарна уу."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"Сүлжээ түгжигдсэн"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"SIM карт байхгүй"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"Таблет SIM картгүй."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"Утсанд SIM карт байхгүй."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"SIM картыг оруулна уу."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"SIM карт байхгүй эсвэл унших боломжгүй. SIM карт оруулна уу."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"Ашиглаж болохгүй SIM карт."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"Таны SIM карт бүрмөсөн идэвхгүй болов.\n Өөр SIM карт авах бол өөрийн утасгүй үйлчилгээний нийлүүлэгчтэй холбогдоно уу."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"SIM карт түгжигдсэн."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"SIM картны PUK-түгжигдсэн."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"SIM картны түгжээг гаргаж байна…"</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. %3$d. -н %2$d виджет"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Виджет нэмэх."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Хоосон"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Тайлах хэсэг нээгдсэн."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Тайлах хэсэг хаагдсан."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> виджет."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Хэрэглэгч сонгоч"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Статус"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Камер"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Медиа контрол"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Виджет дахин эрэмбэлж эхлэв."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Виджетийг дахин эрэмбэлж дуусав."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> виджет устсан."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Түгжээгүй хэсгийг өргөсгөх."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Тайлах гулсуулалт."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Тайлах хээ."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Нүүрээр тайлах"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Тайлах пин."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Тайлах нууц үг."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Хээний хэсэг."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Гулсуулах хэсэг."</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"Өмнөх бичлэг товч"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"Дараагийн бичлэг товч"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Түр зогсоох товч"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Тоглуулах товч"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Зогсоох товч"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Сайн"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Онцгүй"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Зүрх"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Үргэлжлүүлэхийн тулд түгжээг тайлна уу"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Эхлүүлэхийг цуцалсан"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Устгахын тулд <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>-г тавина уу."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> устахгүй."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"АБВ"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Цуцлах"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Устгах"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Дуусгах"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Горим өөрчлөх"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Шифт"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Оруулах"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Тайлах"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Камер"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Чимээгүй"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Дуунууд идэвхтэй"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Хайх"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>-г гулсуулах."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> хийх бол доош гулсуулах."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> хийх зүүнлүү гулсуулах."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g> хийх бол баруунлуу гулсуулах."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Одоогийн хэрэглэгч <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Яаралтай дуудлага"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Хээг мартсан"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Буруу хээ"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Нууц үг буруу"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN буруу"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"<xliff:g id="NUMBER">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Хээг зурах"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"SIM PIN оруулна уу"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"PIN оруулна уу"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Нууц үгээ оруулна уу"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM идэвхгүй байна. Үргэлжлүүлэх бол PUK кодыг оруулна уу. Дэлгэрэнгүй мэдээллийг оператороос асууна ууу"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Хүссэн PIN кодоо оруулна уу"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Хүссэн PIN кодоо дахин оруулна уу"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"SIM картны түгжээг гаргаж байна…"</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Буруу PIN код."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"4-8 тооноос бүтэх PIN-г бичнэ үү."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK код 8-с цөөнгүй тооноос бүтнэ."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Зөв PUK кодыг дахин оруулна уу. Давтан оролдвол SIM нь бүрмөсөн идэвхгүй болгоно."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN кодууд таарахгүй байна"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Хээ оруулах оролдлого хэт олон"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Түгжээг тайлах бол Google акаунтаараа нэвтэрнэ үү."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Хэрэглэгчийн нэр (имэйл)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Нууц үг"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Нэвтрэх"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Хэрэглэгчийн нэр эсвэл нууц үг буруу."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Хэрэглэгчийн нэр нууц үгээ мартсан уу?\n"<b>"google.com/accounts/recovery"</b>"-д зочилно уу."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Акаунт шалгаж байна…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Та PIN кодоо <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу бичив. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Та PIN кодоо <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу бичив. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. \n\n<xliff:g id="NUMBER_1">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Та таблетыг тайлах гэж <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу оролдлоо. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол таблет үйлдвэрийн үндсэн утгаараа тохируулагдах ба хэрэглэгчийн дата бүхэлдээ устана."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Та утсыг тайлах гэж <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу оролдлоо. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оролдвол утас үйлдвэрийн үндсэн утгаараа тохируулагдах ба хэрэглэгчийн дата бүхэлдээ устана."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Та таблетыг тайлах гэж <xliff:g id="NUMBER">%d</xliff:g> удаа буруу оролдлоо. Таблет одоо үйлдвэрийн үндсэн утгаараа тохируулагдах болно."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Та утсыг тайлах гэж <xliff:g id="NUMBER">%d</xliff:g> удаа буруу оролдлоо. Утас одоо үйлдвэрийн үндсэн утгаараа тохируулагдах болно."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оруулбал, та таблетаа тайлахын тулд имэйл акаунт шаардлагатай болно.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Та тайлах хээг <xliff:g id="NUMBER_0">%d</xliff:g> удаа буруу зурлаа. <xliff:g id="NUMBER_1">%d</xliff:g> удаа дахин буруу оруулбал, та утсаа тайлахын тулд имэйл акаунтаа ашиглах шаардлагатай болно.\n\n <xliff:g id="NUMBER_2">%d</xliff:g> секундын дараа дахин оролдоно уу."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Устгах"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"Өмнөх дуу товч"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"Дараагийн дуу товч"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Түр зогсох товч"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Тоглуулах товч"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Зогсоох товч"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Үйлчилгээ байхгүй."</string>
-</resources>
diff --git a/packages/Keyguard/res/values-ms-rMY/strings.xml b/packages/Keyguard/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 17ec2e6..0000000
--- a/packages/Keyguard/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"Taip kod PIN"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"Taip PUK dan kod PIN baharu"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"Kod PUK"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"Kod PIN Baharu"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"Sentuh untuk menaip kata laluan"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"Taip kata laluan untuk membuka kunci"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"Taip PIN untuk membuka kunci"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"Kod PIN salah."</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"Untuk membuka kunci, tekan Menu, kemudian 0."</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Telah melepasi had cubaan Buka Kunci Wajah"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"Sudah dicas"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"Mengecas, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"Sambungkan pengecas anda."</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"Tekan Menu untuk membuka kunci."</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"Rangkaian dikunci"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"Tiada kad SIM"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"Tiada kad SIM dalam tablet."</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"Tiada kad SIM dalam telefon."</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"Masukkan kad SIM."</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"Kad SIM tiada atau tidak boleh dibaca. Sila masukkan kad SIM."</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"Kad SIM tidak boleh digunakan."</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"Kad SIM anda telah dilumpuhkan secara kekal.\n Hubungi pembekal perkhidmatan wayarles anda untuk mendapatkan kad SIM lain."</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"Kad SIM dikunci."</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"Kad SIM dikunci dengan PUK."</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"Membuka kunci kad SIM..."</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s. Widget %2$d dari %3$d."</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"Tambah widget."</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"Kosong"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"Bahagian buka kunci dikembangkan."</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"Bahagian buka kunci diruntuhkan."</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"Widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>."</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"Pemilih pengguna"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"Status"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"Kamera"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"Kawalan media"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"Penyusunan semula widget dimulakan."</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"Penyusunan semula widget tamat."</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"Widget <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> dipadamkan."</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"Kembangkan bahagian buka kunci."</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"Buka kunci luncur."</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"Buka kunci corak."</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"Wajah Buka Kunci"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"Buka kunci pin."</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"Buka kunci kata laluan."</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"Kawasan corak."</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"Kawasan luncur."</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"Butang lagu sebelumnya"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"Butang lagu seterusnya"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Butang jeda"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Butang main"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Butang berhenti"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Menyukai"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Tidak diterima"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Jantung"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Buka kunci untuk meneruskan"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Pelancaran dibatalkan"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Jatuhkan <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> untuk memadam."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> tidak akan dipadamkan."</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"Batal"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"Padam"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"Selesai"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"Perubahan mod"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Masuk"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"Buka kunci"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"Kamera"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"Senyap"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"Bunyi dihidupkan"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"Carian"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"Luncurkan ke atas untuk <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"Luncurkan ke bawah untuk <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"Luncurkan ke kiri untuk <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"Luncurkan ke kanan untuk <xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>."</string>
-    <string name="user_switched" msgid="3768006783166984410">"Pengguna semasa <xliff:g id="NAME">%1$s</xliff:g>."</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"Panggilan kecemasan"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"Lupa Corak"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"Corak Salah"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"Kata Laluan Salah"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN salah"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Cuba lagi dalam <xliff:g id="NUMBER">%d</xliff:g> saat."</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"Lukiskan corak anda"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Masukkan PIN SIM"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"Masukkan PIN"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"Masukkan Kata Laluan"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"Kini SIM dilumpuhkan. Masukkan kod PUK untuk meneruskan. Hubungi pembawa untuk butiran."</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"Masukkan kod PIN yang diingini"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"Sahkan kod PIN yang diingini"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"Membuka kunci kad SIM..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"Kod PIN salah."</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"Taipkan PIN yang mengandungi 4 hingga 8 nombor."</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"Kod PUK mestilah 8 nombor atau lebih."</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"Masukkan semula kod PIN yang betul. Percubaan berulang akan melumpuhkan SIM secara kekal."</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"Kod PIN tidak sepadan"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Terlalu banyak percubaan melukis corak"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"Untuk membuka kunci, log masuk dengan akaun Google anda."</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"Nama Pengguna (E-mel)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"Kata laluan"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"Log masuk"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"Nama pengguna atau kata laluan tidak sah."</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Lupa nama pengguna atau kata laluan anda?\nLawati"<b>"google.com/accounts/recovery"</b>"."</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"Menyemak akaun…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Anda telah menaip PIN anda secara salah sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. \n\nCuba lagi dalam <xliff:g id="NUMBER_1">%d</xliff:g> saat."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Anda telah menaip kata laluan anda secara salah sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. \n\nCuba lagi dalam <xliff:g id="NUMBER_1">%d</xliff:g> saat."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Anda telah tersilap melukis corak buka kunci anda sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. \n\nCuba lagi dalam <xliff:g id="NUMBER_1">%d</xliff:g> saat."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Anda telah mencuba untuk membuka kunci tablet dengan salah sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. Selepas <xliff:g id="NUMBER_1">%d</xliff:g> lagi percubaan yang tidak berjaya, tablet akan ditetapkan semula kepada tetapan lalai kilang dan semua data pengguna akan hilang."</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Anda telah mencuba untuk membuka kunci telefon dengan salah sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. Selepas <xliff:g id="NUMBER_1">%d</xliff:g> lagi percubaan yang tidak berjaya, telefon akan ditetapkan semula kepada tetapan lalai kilang dan semua data pengguna akan hilang."</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Anda telah mencuba untuk membuka kunci tablet secara salah sebanyak <xliff:g id="NUMBER">%d</xliff:g> kali. Tablet kini akan ditetapkan semula ke tetapan lalai kilang."</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Anda telah mencuba untuk membuka kunci telefon secara salah sebanyak <xliff:g id="NUMBER">%d</xliff:g> kali. Telefon kini akan ditetapkan semula ke tetapan lalai kilang."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Anda telah tersilap melukis corak buka kunci sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. Selepas <xliff:g id="NUMBER_1">%d</xliff:g> lagi percubaan yang tidak berjaya, anda akan diminta membuka kunci tablet anda menggunakan log masuk Google anda.\n\n Cuba lagi dalam <xliff:g id="NUMBER_2">%d</xliff:g> saat."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Anda telah tersilap lukis corak buka kunci sebanyak <xliff:g id="NUMBER_0">%d</xliff:g> kali. Selepas <xliff:g id="NUMBER_1">%d</xliff:g> lagi percubaan yang tidak berjaya, anda akan diminta membuka kunci telefon anda menggunakan log masuk Google anda.\n\n Cuba lagi dalam <xliff:g id="NUMBER_2">%d</xliff:g> saat."</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Alih keluar"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"Butang lagu sebelumnya"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"Butang lagu seterusnya"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Butang jeda"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Butang main"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Butang berhenti"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Tiada perkhidmatan."</string>
-</resources>
diff --git a/packages/Keyguard/res/values-nb/strings.xml b/packages/Keyguard/res/values-nb/strings.xml
index dff741c..6a5bfa9 100644
--- a/packages/Keyguard/res/values-nb/strings.xml
+++ b/packages/Keyguard/res/values-nb/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pause-knapp"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Avspillingsknapp"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stopp-knapp"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Likt av meg"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Sanger du ikke liker"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Hjerte"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Lås opp for å fortsette"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Starten ble kansellert"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Slipp <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> for å slette den."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> blir ikke slettet."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-nl/strings.xml b/packages/Keyguard/res/values-nl/strings.xml
index 799c801..b94cb70 100644
--- a/packages/Keyguard/res/values-nl/strings.xml
+++ b/packages/Keyguard/res/values-nl/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Knop voor onderbreken"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Knop voor afspelen"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Knop voor stoppen"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Leuk"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Niet leuk"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Hart"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Ontgrendel om door te gaan"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Start geannuleerd"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Zet <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> neer om te verwijderen."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> wordt niet verwijderd."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"Alt"</string>
diff --git a/packages/Keyguard/res/values-pl/strings.xml b/packages/Keyguard/res/values-pl/strings.xml
index 30910f5..15a4a7c 100644
--- a/packages/Keyguard/res/values-pl/strings.xml
+++ b/packages/Keyguard/res/values-pl/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Przycisk wstrzymania"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Przycisk odtwarzania"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Przycisk zatrzymania"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Podoba mi się"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Nie podoba mi się"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Serce"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Odblokuj, by kontynuować"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Uruchomienie anulowane"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Upuść <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>, by usunąć."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> nie zostanie usunięty."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-pt-rPT/strings.xml b/packages/Keyguard/res/values-pt-rPT/strings.xml
index 2aba3b4..222051c 100644
--- a/packages/Keyguard/res/values-pt-rPT/strings.xml
+++ b/packages/Keyguard/res/values-pt-rPT/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Botão Pausa"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Botão Reproduzir"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Botão Parar"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Gosto"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Não gosto"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Coração"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Desbloquear para continuar"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Lançamento cancelado"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Largue <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> para eliminar."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> não será eliminado."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-pt/strings.xml b/packages/Keyguard/res/values-pt/strings.xml
index 3c668a0..a563372 100644
--- a/packages/Keyguard/res/values-pt/strings.xml
+++ b/packages/Keyguard/res/values-pt/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Botão \"Pausar\""</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Botão \"Reproduzir\""</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Botão \"Parar\""</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Gostei"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Não gostei"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Coração"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Desbloqueie para continuar"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Inicialização cancelada"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Solte <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> para excluir."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> não será excluído."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-rm/strings.xml b/packages/Keyguard/res/values-rm/strings.xml
index f7ba4e3..8dda055 100644
--- a/packages/Keyguard/res/values-rm/strings.xml
+++ b/packages/Keyguard/res/values-rm/strings.xml
@@ -121,20 +121,6 @@
     <skip />
     <!-- no translation found for keyguard_accessibility_transport_stop_description (7656358482980912216) -->
     <skip />
-    <!-- no translation found for keyguard_accessibility_transport_thumbs_up_description (4535938129663903194) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_transport_thumbs_down_description (8101433677192177861) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_transport_heart_description (2336943232474689887) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_show_bouncer (5425837272418176176) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_hide_bouncer (7896992171878309358) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_delete_widget_start (4096550552634391451) -->
-    <skip />
-    <!-- no translation found for keyguard_accessibility_delete_widget_end (508833506780909393) -->
-    <skip />
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-ro/strings.xml b/packages/Keyguard/res/values-ro/strings.xml
index cebf0df..01d79f8 100644
--- a/packages/Keyguard/res/values-ro/strings.xml
+++ b/packages/Keyguard/res/values-ro/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Butonul Întrerupeți"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Butonul Redați"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Butonul Opriți"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Vot pozitiv"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Vot negativ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Inimă"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Deblocați pentru a continua"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Lansare anulată"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Eliberați <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> pentru a șterge."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Widgetul <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> nu va fi șters."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-ru/strings.xml b/packages/Keyguard/res/values-ru/strings.xml
index d8a457d..136982a 100644
--- a/packages/Keyguard/res/values-ru/strings.xml
+++ b/packages/Keyguard/res/values-ru/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Кнопка паузы"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Кнопка воспроизведения"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Кнопка выключения"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Нравится"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Не нравится"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Рейтинг"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Разблокируйте экран, чтобы продолжить."</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Запуск отменен."</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Отпустите виджет \"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>\", чтобы удалить его."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Виджет \"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>\" не будет удален."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"АБВ"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-sk/strings.xml b/packages/Keyguard/res/values-sk/strings.xml
index bd3f058..4b2e1e3 100644
--- a/packages/Keyguard/res/values-sk/strings.xml
+++ b/packages/Keyguard/res/values-sk/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Tlačidlo Pozastaviť"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Tlačidlo Prehrať"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Tlačidlo Zastaviť"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Páči sa mi"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Nepáči sa mi"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Srdce"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Odomknite zariadenie a pokračujte"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Spustenie bolo zrušené"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Uvoľnením dotyku miniaplikáciu <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> odstránite."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Miniaplikácia <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> nebude odstránená."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-sl/strings.xml b/packages/Keyguard/res/values-sl/strings.xml
index 7e7d893..b6cfc1c 100644
--- a/packages/Keyguard/res/values-sl/strings.xml
+++ b/packages/Keyguard/res/values-sl/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Gumb za začasno ustavitev"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Gumb za predvajanje"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Gumb za ustavitev"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Všeč mi je"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Ni mi všeč"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Srce"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Za nadaljevanje odklenite"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Zagon je preklican"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Izpustite pripomoček <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>, da ga izbrišete."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Pripomoček <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ne bo izbrisan."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-sr/strings.xml b/packages/Keyguard/res/values-sr/strings.xml
index c5cc39c..664b85e 100644
--- a/packages/Keyguard/res/values-sr/strings.xml
+++ b/packages/Keyguard/res/values-sr/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Дугме за паузу"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Дугме за репродукцију"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Дугме за заустављање"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Свиђа ми се"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Не свиђа ми се"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Срце"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Откључајте да бисте наставили"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Покретање је отказано"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Отпустите виџет <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> да бисте га избрисали."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Виџет <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> неће бити избрисан."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
@@ -141,5 +134,5 @@
     <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"Дугме за паузу"</string>
     <string name="keyguard_transport_play_description" msgid="2924628863741150956">"Дугме за репродукцију"</string>
     <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"Дугме за заустављање"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Офлајн сте."</string>
+    <string name="keyguard_carrier_default" msgid="8700650403054042153">"Ван мреже сте."</string>
 </resources>
diff --git a/packages/Keyguard/res/values-sv/strings.xml b/packages/Keyguard/res/values-sv/strings.xml
index dd82711..fb0f912 100644
--- a/packages/Keyguard/res/values-sv/strings.xml
+++ b/packages/Keyguard/res/values-sv/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Pausknappen"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Uppspelningsknappen"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Stoppknappen"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Gillar"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Tummen ned"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Hjärta"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Lås upp om du vill fortsätta"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Lanseringen har avbrutits"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Ta bort genom att släppa <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> här."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> kommer inte att tas bort."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-sw/strings.xml b/packages/Keyguard/res/values-sw/strings.xml
index 5e2b163..27f1f30 100644
--- a/packages/Keyguard/res/values-sw/strings.xml
+++ b/packages/Keyguard/res/values-sw/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Kitufe cha kusitisha"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Kitufe cha kucheza"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Kitufe cha kusitisha"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Bomba"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Si bomba"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Moyo"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Fungua ili uendelee"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Uzinduzi umeghairiwa"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Dondosha <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ili ufute."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> haitafutwa."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-th/strings.xml b/packages/Keyguard/res/values-th/strings.xml
index 3f2c747..d6308b6 100644
--- a/packages/Keyguard/res/values-th/strings.xml
+++ b/packages/Keyguard/res/values-th/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"ปุ่มหยุดชั่วคราว"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"ปุ่มเล่น"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"ปุ่มหยุด"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"สุดยอด"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"ไม่ชอบ"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"หัวใจ"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"ปลดล็อกเพื่อดำเนินการต่อ"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"ยกเลิกการเปิดใช้งานแล้ว"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"ลาก <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> เพื่อลบ"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> จะไม่ถูกลบ"</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-tl/strings.xml b/packages/Keyguard/res/values-tl/strings.xml
index 3a33c9f..a41d268 100644
--- a/packages/Keyguard/res/values-tl/strings.xml
+++ b/packages/Keyguard/res/values-tl/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Button na I-pause"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Button na I-play"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Button na Ihinto"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Thumbs up"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Thumbs down"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Heart"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"I-unlock upang magpatuloy"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Nakansela ang paglunsad"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"I-drop ang <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> upang tanggalin."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"Hindi tatanggalin ang <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-tr/strings.xml b/packages/Keyguard/res/values-tr/strings.xml
index d9c950f..0af7740 100644
--- a/packages/Keyguard/res/values-tr/strings.xml
+++ b/packages/Keyguard/res/values-tr/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Duraklat düğmesi"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Oynat düğmesi"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Durdur düğmesi"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Beğen"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Beğenme"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Kalp"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Devam etmek için kilidini açın"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Başlatma iptal edildi"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Silmek için <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> widget\'ını bırakın."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> silinmeyecek."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-uk/strings.xml b/packages/Keyguard/res/values-uk/strings.xml
index 01bf687..2879e87 100644
--- a/packages/Keyguard/res/values-uk/strings.xml
+++ b/packages/Keyguard/res/values-uk/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Кнопка \"Призупинити\""</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Кнопка \"Відтворити\""</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Кнопка \"Зупинити\""</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Подобається"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Не подобається"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Рейтинг"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Розблокуйте, щоб продовжити"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Запуск скасовано"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Відпустіть <xliff:g id="WIDGET_INDEX">%1$s</xliff:g>, щоб видалити."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> не буде видалено."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-vi/strings.xml b/packages/Keyguard/res/values-vi/strings.xml
index 6ae8312..70d3c73 100644
--- a/packages/Keyguard/res/values-vi/strings.xml
+++ b/packages/Keyguard/res/values-vi/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Nút tạm dừng"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Nút phát"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Nút dừng"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Bài hát được đánh dấu thích"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Bài hát được đánh dấu không thích"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Trái tim"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Mở khóa để tiếp tục"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Quá trình khởi chạy bị hủy"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Thả <xliff:g id="WIDGET_INDEX">%1$s</xliff:g> để xóa."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> sẽ không bị xóa."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-zh-rCN/strings.xml b/packages/Keyguard/res/values-zh-rCN/strings.xml
index 06d71ff..cdb1944e 100644
--- a/packages/Keyguard/res/values-zh-rCN/strings.xml
+++ b/packages/Keyguard/res/values-zh-rCN/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"暂停按钮"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"播放按钮"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"停止按钮"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"我喜欢"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"不喜欢"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"爱心"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"解锁即可继续"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"启动已取消"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"放下<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>即可将其删除。"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>将不会被删除。"</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-zh-rHK/strings.xml b/packages/Keyguard/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 724357f..0000000
--- a/packages/Keyguard/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,145 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/* //device/apps/common/assets/res/any/strings.xml
-**
-** Copyright 2006, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="keyguard_password_enter_pin_code" msgid="3037685796058495017">"輸入 PIN 碼"</string>
-    <string name="keyguard_password_enter_puk_code" msgid="4800725266925845333">"輸入 PUK 碼和新 PIN 碼"</string>
-    <string name="keyguard_password_enter_puk_prompt" msgid="1341112146710087048">"PUK 碼"</string>
-    <string name="keyguard_password_enter_pin_prompt" msgid="8027680321614196258">"新 PIN 碼"</string>
-    <string name="keyguard_password_entry_touch_hint" msgid="7858547464982981384"><font size="17">"輕觸即可輸入密碼"</font></string>
-    <string name="keyguard_password_enter_password_code" msgid="1054721668279049780">"輸入密碼即可解鎖"</string>
-    <string name="keyguard_password_enter_pin_password_code" msgid="6391755146112503443">"輸入 PIN 碼即可解鎖"</string>
-    <string name="keyguard_password_wrong_pin_code" msgid="2422225591006134936">"PIN 碼不正確。"</string>
-    <string name="keyguard_label_text" msgid="861796461028298424">"如要解鎖,請按選單鍵,然後按 0。"</string>
-    <string name="faceunlock_multiple_failures" msgid="754137583022792429">"已超過臉容解鎖嘗試次數上限"</string>
-    <string name="keyguard_charged" msgid="3272223906073492454">"充電完成"</string>
-    <string name="keyguard_plugged_in" msgid="8117572000639998388">"充電中 (<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>)"</string>
-    <string name="keyguard_low_battery" msgid="8143808018719173859">"請連接充電器。"</string>
-    <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"按選單鍵解鎖。"</string>
-    <string name="keyguard_network_locked_message" msgid="9169717779058037168">"網絡已鎖定"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"找不到 SIM 卡"</string>
-    <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"平板電腦中沒有 SIM 卡。"</string>
-    <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"手機中沒有 SIM 卡。"</string>
-    <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"請插入 SIM 卡。"</string>
-    <string name="keyguard_missing_sim_instructions_long" msgid="5968985489463870358">"找不到 SIM 卡或無法讀取 SIM 卡,請插入 SIM 卡。"</string>
-    <string name="keyguard_permanent_disabled_sim_message_short" msgid="8340813989586622356">"SIM 卡無法使用。"</string>
-    <string name="keyguard_permanent_disabled_sim_instructions" msgid="5892940909699723544">"您的 SIM 卡已被永久停用。\n請與您的無線服務供應商聯絡,以取得另一張 SIM 卡。"</string>
-    <string name="keyguard_sim_locked_message" msgid="6875773413306380902">"SIM 卡處於鎖定狀態。"</string>
-    <string name="keyguard_sim_puk_locked_message" msgid="3747232467471801633">"SIM 卡處於 PUK 鎖定狀態。"</string>
-    <string name="keyguard_sim_unlock_progress_dialog_message" msgid="7975221805033614426">"正在解開上鎖的 SIM 卡..."</string>
-    <string name="keyguard_accessibility_widget_changed" msgid="5678624624681400191">"%1$s。第 %2$d 個小工具,共 %3$d 個。"</string>
-    <string name="keyguard_accessibility_add_widget" msgid="8273277058724924654">"新增小工具。"</string>
-    <string name="keyguard_accessibility_widget_empty_slot" msgid="1281505703307930757">"空白"</string>
-    <string name="keyguard_accessibility_unlock_area_expanded" msgid="2278106022311170299">"解鎖區域已展開。"</string>
-    <string name="keyguard_accessibility_unlock_area_collapsed" msgid="6366992066936076396">"解鎖區域已收合。"</string>
-    <string name="keyguard_accessibility_widget" msgid="6527131039741808240">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>小工具。"</string>
-    <string name="keyguard_accessibility_user_selector" msgid="1226798370913698896">"用戶選取工具"</string>
-    <string name="keyguard_accessibility_status" msgid="8008264603935930611">"狀態"</string>
-    <string name="keyguard_accessibility_camera" msgid="8904231194181114603">"相機"</string>
-    <string name="keygaurd_accessibility_media_controls" msgid="262209654292161806">"媒體控制"</string>
-    <string name="keyguard_accessibility_widget_reorder_start" msgid="8736853615588828197">"已開始為小工具重新排列次序。"</string>
-    <string name="keyguard_accessibility_widget_reorder_end" msgid="7170190950870468320">"已完成為小工具重新排列次序。"</string>
-    <string name="keyguard_accessibility_widget_deleted" msgid="4426204263929224434">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>小工具已刪除。"</string>
-    <string name="keyguard_accessibility_expand_lock_area" msgid="519859720934178024">"展開解鎖區域。"</string>
-    <string name="keyguard_accessibility_slide_unlock" msgid="2959928478764697254">"滑動解鎖。"</string>
-    <string name="keyguard_accessibility_pattern_unlock" msgid="1490840706075246612">"圖案解鎖。"</string>
-    <string name="keyguard_accessibility_face_unlock" msgid="4817282543351718535">"臉容解鎖。"</string>
-    <string name="keyguard_accessibility_pin_unlock" msgid="2469687111784035046">"PIN 解鎖。"</string>
-    <string name="keyguard_accessibility_password_unlock" msgid="7675777623912155089">"密碼解鎖。"</string>
-    <string name="keyguard_accessibility_pattern_area" msgid="7679891324509597904">"圖案區域。"</string>
-    <string name="keyguard_accessibility_slide_area" msgid="6736064494019979544">"滑動區域。"</string>
-    <string name="keyguard_accessibility_transport_prev_description" msgid="1337286538318543555">"[上一首曲目] 按鈕"</string>
-    <string name="keyguard_accessibility_transport_next_description" msgid="7073928300444909320">"[下一首曲目] 按鈕"</string>
-    <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"[暫停] 按鈕"</string>
-    <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"[播放] 按鈕"</string>
-    <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"[停止] 按鈕"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"喜歡"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"不喜歡"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"心形"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"請解鎖以繼續"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"已取消啟動"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"拖放「<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>」即可刪除。"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"「<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>」將不會被刪除。"</string>
-    <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
-    <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
-    <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
-    <string name="keyboardview_keycode_alt" msgid="4856868820040051939">"Alt"</string>
-    <string name="keyboardview_keycode_cancel" msgid="1203984017245783244">"取消"</string>
-    <string name="keyboardview_keycode_delete" msgid="3337914833206635744">"刪除"</string>
-    <string name="keyboardview_keycode_done" msgid="1992571118466679775">"完成"</string>
-    <string name="keyboardview_keycode_mode_change" msgid="4547387741906537519">"模式更改"</string>
-    <string name="keyboardview_keycode_shift" msgid="2270748814315147690">"Shift 鍵"</string>
-    <string name="keyboardview_keycode_enter" msgid="2985864015076059467">"Enter 鍵"</string>
-    <string name="description_target_unlock" msgid="2228524900439801453">"解鎖"</string>
-    <string name="description_target_camera" msgid="969071997552486814">"相機"</string>
-    <string name="description_target_silent" msgid="893551287746522182">"靜音"</string>
-    <string name="description_target_soundon" msgid="30052466675500172">"音效已開啟"</string>
-    <string name="description_target_search" msgid="3091587249776033139">"搜尋"</string>
-    <string name="description_direction_up" msgid="7169032478259485180">"向上滑動即可<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>。"</string>
-    <string name="description_direction_down" msgid="5087739728639014595">"向下滑動即可<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>。"</string>
-    <string name="description_direction_left" msgid="7207478719805562165">"向左滑動即可<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>。"</string>
-    <string name="description_direction_right" msgid="8034433242579600980">"向右滑動即可<xliff:g id="TARGET_DESCRIPTION">%s</xliff:g>。"</string>
-    <string name="user_switched" msgid="3768006783166984410">"目前的用戶是<xliff:g id="NAME">%1$s</xliff:g>。"</string>
-    <string name="kg_emergency_call_label" msgid="684946192523830531">"緊急電話"</string>
-    <string name="kg_forgot_pattern_button_text" msgid="8852021467868220608">"忘記圖案"</string>
-    <string name="kg_wrong_pattern" msgid="1850806070801358830">"圖案錯誤"</string>
-    <string name="kg_wrong_password" msgid="2333281762128113157">"密碼錯誤"</string>
-    <string name="kg_wrong_pin" msgid="1131306510833563801">"PIN 錯誤"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"請在 <xliff:g id="NUMBER">%d</xliff:g> 秒後再試一次。"</string>
-    <string name="kg_pattern_instructions" msgid="398978611683075868">"畫出圖案"</string>
-    <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"輸入 SIM 卡 PIN 碼"</string>
-    <string name="kg_pin_instructions" msgid="2377242233495111557">"輸入 PIN 碼"</string>
-    <string name="kg_password_instructions" msgid="5753646556186936819">"輸入密碼"</string>
-    <string name="kg_puk_enter_puk_hint" msgid="453227143861735537">"SIM 卡現已停用,請輸入 PUK 碼以繼續。詳情請與流動網絡供應商聯絡。"</string>
-    <string name="kg_puk_enter_pin_hint" msgid="7871604527429602024">"輸入所需的 PIN 碼"</string>
-    <string name="kg_enter_confirm_pin_hint" msgid="325676184762529976">"確認所需的 PIN 碼"</string>
-    <string name="kg_sim_unlock_progress_dialog_message" msgid="8950398016976865762">"正在解開上鎖的 SIM 卡..."</string>
-    <string name="kg_password_wrong_pin_code" msgid="1139324887413846912">"PIN 碼不正確。"</string>
-    <string name="kg_invalid_sim_pin_hint" msgid="8795159358110620001">"請輸入一個 4 至 8 位數的 PIN 碼。"</string>
-    <string name="kg_invalid_sim_puk_hint" msgid="7553388325654369575">"PUK 碼應由 8 個或以上數字組成。"</string>
-    <string name="kg_invalid_puk" msgid="3638289409676051243">"請重新輸入正確的 PUK 碼。如果嘗試輸入的次數過多,SIM 卡將永久停用。"</string>
-    <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN 碼不符"</string>
-    <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"圖案嘗試次數過多"</string>
-    <string name="kg_login_instructions" msgid="1100551261265506448">"如要解鎖,請以 Google 帳戶登入。"</string>
-    <string name="kg_login_username_hint" msgid="5718534272070920364">"用戶名稱 (電子郵件)"</string>
-    <string name="kg_login_password_hint" msgid="9057289103827298549">"密碼"</string>
-    <string name="kg_login_submit_button" msgid="5355904582674054702">"登入"</string>
-    <string name="kg_login_invalid_input" msgid="5754664119319872197">"無效的用戶名稱或密碼。"</string>
-    <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"忘記用戶名稱或密碼?\n請瀏覽 "<b>"google.com/accounts/recovery"</b>"。"</string>
-    <string name="kg_login_checking_password" msgid="1052685197710252395">"正在檢查帳戶…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"您已輸入錯誤的 PIN 碼 <xliff:g id="NUMBER_0">%d</xliff:g> 次。\n\n請在 <xliff:g id="NUMBER_1">%d</xliff:g> 秒後再試一次。"</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"您已輸入錯誤的密碼 <xliff:g id="NUMBER_0">%d</xliff:g> 次。\n\n請在 <xliff:g id="NUMBER_1">%d</xliff:g> 秒後再試一次。"</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"您已畫錯解鎖圖案 <xliff:g id="NUMBER_0">%d</xliff:g> 次。\n\n請在 <xliff:g id="NUMBER_1">%d</xliff:g> 秒後再試一次。"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"您嘗試了 <xliff:g id="NUMBER_0">%d</xliff:g> 次仍未能成功解開這部上鎖的平板電腦。如果再嘗試 <xliff:g id="NUMBER_1">%d</xliff:g> 次仍未成功,平板電腦將回復原廠設定,所有用戶資料均會失去。"</string>
-    <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"您嘗試了 <xliff:g id="NUMBER_0">%d</xliff:g> 次仍未能成功解開這部上鎖的手機。如果再嘗試 <xliff:g id="NUMBER_1">%d</xliff:g> 次仍未成功,手機將回復原廠設定,所有用戶資料均會失去。"</string>
-    <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"您嘗試了 <xliff:g id="NUMBER">%d</xliff:g> 次仍未能成功解開這部上鎖的平板電腦。平板電腦現在將回復原廠設定。"</string>
-    <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"您嘗試了 <xliff:g id="NUMBER">%d</xliff:g> 次仍未能成功解開這部上鎖的手機。手機現在將回復原廠設定。"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"您已畫錯解鎖圖案 <xliff:g id="NUMBER_0">%d</xliff:g> 次,如果再嘗試 <xliff:g id="NUMBER_1">%d</xliff:g> 次仍未成功,系統會要求您透過電郵帳戶解開上鎖的平板電腦。\n\n請在 <xliff:g id="NUMBER_2">%d</xliff:g> 秒後再試一次。"</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"您已畫錯解鎖圖案 <xliff:g id="NUMBER_0">%d</xliff:g> 次,如果再嘗試 <xliff:g id="NUMBER_1">%d</xliff:g> 次仍未成功,系統會要求您透過電郵帳戶解開上鎖的手機。\n\n請在 <xliff:g id="NUMBER_2">%d</xliff:g> 秒後再試一次。"</string>
-    <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" — "</string>
-    <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"移除"</string>
-    <string name="keyguard_transport_prev_description" msgid="8229108430245669854">"[上一首曲目] 按鈕"</string>
-    <string name="keyguard_transport_next_description" msgid="4299258300283778305">"[下一首曲目] 按鈕"</string>
-    <string name="keyguard_transport_pause_description" msgid="5093073338238310224">"[暫停] 按鈕"</string>
-    <string name="keyguard_transport_play_description" msgid="2924628863741150956">"[播放] 按鈕"</string>
-    <string name="keyguard_transport_stop_description" msgid="3084179324810575787">"[停止] 按鈕"</string>
-    <string name="keyguard_carrier_default" msgid="8700650403054042153">"沒有服務。"</string>
-</resources>
diff --git a/packages/Keyguard/res/values-zh-rTW/strings.xml b/packages/Keyguard/res/values-zh-rTW/strings.xml
index f3f1724..72a1c0f 100644
--- a/packages/Keyguard/res/values-zh-rTW/strings.xml
+++ b/packages/Keyguard/res/values-zh-rTW/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"[暫停] 按鈕"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"[播放] 按鈕"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"[停止] 按鈕"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"喜歡"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"不喜歡"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"愛心"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"先解鎖才能繼續操作"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"已取消啟動"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"拖放「<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>」即可將其刪除。"</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"「<xliff:g id="WIDGET_INDEX">%1$s</xliff:g>」將不會遭到刪除。"</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/res/values-zu/strings.xml b/packages/Keyguard/res/values-zu/strings.xml
index b8d884e..185ea03 100644
--- a/packages/Keyguard/res/values-zu/strings.xml
+++ b/packages/Keyguard/res/values-zu/strings.xml
@@ -71,13 +71,6 @@
     <string name="keyguard_accessibility_transport_pause_description" msgid="8455979545295224302">"Inkinobho yokumiswa isikhashana"</string>
     <string name="keyguard_accessibility_transport_play_description" msgid="8146417789511154044">"Inkinobho yokudlala"</string>
     <string name="keyguard_accessibility_transport_stop_description" msgid="7656358482980912216">"Inkinobho yokumisa"</string>
-    <string name="keyguard_accessibility_transport_thumbs_up_description" msgid="4535938129663903194">"Okushaphu"</string>
-    <string name="keyguard_accessibility_transport_thumbs_down_description" msgid="8101433677192177861">"Akulungile"</string>
-    <string name="keyguard_accessibility_transport_heart_description" msgid="2336943232474689887">"Inhliziyo"</string>
-    <string name="keyguard_accessibility_show_bouncer" msgid="5425837272418176176">"Vula ukuze uqhubeke"</string>
-    <string name="keyguard_accessibility_hide_bouncer" msgid="7896992171878309358">"Ukuqalisa kukhanseliwe"</string>
-    <string name="keyguard_accessibility_delete_widget_start" msgid="4096550552634391451">"Lahla i-<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ukuze uyisuse."</string>
-    <string name="keyguard_accessibility_delete_widget_end" msgid="508833506780909393">"<xliff:g id="WIDGET_INDEX">%1$s</xliff:g> ngeke isuswe."</string>
     <string name="password_keyboard_label_symbol_key" msgid="992280756256536042">"?123"</string>
     <string name="password_keyboard_label_alpha_key" msgid="8001096175167485649">"ABC"</string>
     <string name="password_keyboard_label_alt_key" msgid="1284820942620288678">"ALT"</string>
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java
index 6e9e83e..d882eca 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java
@@ -274,7 +274,7 @@
 
     private boolean checkPuk() {
         // make sure the puk is at least 8 digits long.
-        if (mPasswordEntry.getText().length() >= 8) {
+        if (mPasswordEntry.getText().length() == 8) {
             mPukText = mPasswordEntry.getText().toString();
             return true;
         }
diff --git a/packages/PrintSpooler/res/values-af/strings.xml b/packages/PrintSpooler/res/values-af/strings.xml
deleted file mode 100644
index 4090893..0000000
--- a/packages/PrintSpooler/res/values-af/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Drukwaglys"</string>
-    <string name="print_button" msgid="645164566271246268">"Druk"</string>
-    <string name="save_button" msgid="1921310454071758999">"Stoor"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Bestemming"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Afskrifte"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papiergrootte"</string>
-    <string name="label_color" msgid="1108690305218188969">"Kleur"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Oriëntasie"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Bladsye (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Drukvoorskou"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installeer PDF-bekyker vir voorskou"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Drukkerprogram het omgeval"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Bladsye"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Genereer uitdruktaak"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Stoor as PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Alle drukkers…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Drukdialoog"</string>
-    <string name="search" msgid="5421724265322228497">"Deursoek"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Alle drukkers"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Voeg diens by"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Soekkassie vertoon"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Soekkassie weggesteek"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Voeg drukker by"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> drukker gekry"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> drukkers gekry"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Kies drukdiens"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Soek tans vir drukkers"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Geen drukkers gekry nie"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Druk tans <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Kanselleer tans <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Drukkerfout by <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Drukker het <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> geblokkeer"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>-druktaak"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>-druktake"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Kanselleer"</string>
-    <string name="restart" msgid="2472034227037808749">"Herbegin"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Geen verbinding met drukker nie"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"onbekend"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – nie beskikbaar nie"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Swart en wit"</item>
-    <item msgid="2762241247228983754">"Kleur"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portret"</item>
-    <item msgid="3199660090246166812">"Landskap"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Alles"</item>
-    <item msgid="6812869625222503603">"Reikwydte"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-am/strings.xml b/packages/PrintSpooler/res/values-am/strings.xml
deleted file mode 100644
index 6569cf4..0000000
--- a/packages/PrintSpooler/res/values-am/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"የህትመት አስተላላፊ"</string>
-    <string name="print_button" msgid="645164566271246268">"አትም"</string>
-    <string name="save_button" msgid="1921310454071758999">"አስቀምጥ"</string>
-    <string name="label_destination" msgid="9132510997381599275">"መድረሻ"</string>
-    <string name="label_copies" msgid="3634531042822968308">"ቅጂዎች"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"የወረቀት መጠን"</string>
-    <string name="label_color" msgid="1108690305218188969">"ቀለም"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"አቀማመጠ ገፅ"</string>
-    <string name="label_pages" msgid="6300874667546617333">"ገጾች (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"የህትመት ቅድመ እይታ"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"ለቅድመ-እይታ የፒ ዲ ኤፍ መመልከቻ ይጫኑ"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"የአታሚ መተግበሪያ ተበላሽቷል"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"ገፆች"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"የህትመት ስራን በማመንጨት ላይ"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"እንደ ፒ ዲ ኤፍ አስቀምጥ"</string>
-    <string name="all_printers" msgid="5018829726861876202">"ሁሉም አታሚዎች…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"የህትመት መገናኛ"</string>
-    <string name="search" msgid="5421724265322228497">"ፍለጋ"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"ሁሉም አታሚዎች"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"አገልግሎት አክል"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"የፍለጋ ሳጥን ይታያል"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"የፍለጋ ሳጥን ተደብቋል"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"አታሚ አክል"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> አታሚ ተገኝቷል"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> አታሚዎች ተገኝተዋል"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"የህትመት አገልግሎት ይምረጡ"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"አታሚዎችን በመፈለግ ላይ"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"ምንም አታሚዎች አልተገኙም"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>ን በማተም ላይ"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>ን በመተው ላይ"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"የአታሚ ስህተት <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"አታሚ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>ን አግዷል"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> የህትመት ስራ"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> የህትመት ስራዎች"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"ሰርዝ"</string>
-    <string name="restart" msgid="2472034227037808749">"እንደገና ጀምር"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"ከአታሚ ጋር ምንም ግንኙነት የለም"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"አይታወቅም"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – አይገኝም"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"ጥቁር እና ነጭ"</item>
-    <item msgid="2762241247228983754">"ቀለም"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"የቁም"</item>
-    <item msgid="3199660090246166812">"የወርድ"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"ሁሉም"</item>
-    <item msgid="6812869625222503603">"ምጥጥነ ገጽታ"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ar/strings.xml b/packages/PrintSpooler/res/values-ar/strings.xml
deleted file mode 100644
index 76d5dad8..0000000
--- a/packages/PrintSpooler/res/values-ar/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"طباعة"</string>
-    <string name="save_button" msgid="1921310454071758999">"حفظ"</string>
-    <string name="label_destination" msgid="9132510997381599275">"الوجهة"</string>
-    <string name="label_copies" msgid="3634531042822968308">"عدد النسخ"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"حجم الورق"</string>
-    <string name="label_color" msgid="1108690305218188969">"اللون"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"الاتجاه"</string>
-    <string name="label_pages" msgid="6300874667546617333">"الصفحات (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"معاينة قبل الطباعة"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"تثبيت برنامج عرض PDF للمعاينة"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"تعطّل تطبيق الطباعة"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"الصفحات"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"جارٍ إنشاء مهمة الطباعة"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"حفظ بتنسيق PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"جميع الطابعات…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"مربع حوار الطباعة"</string>
-    <string name="search" msgid="5421724265322228497">"بحث"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"جميع الطابعات"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"إضافة خدمة"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"تم إظهار مربع البحث"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"تم إخفاء مربع البحث"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"إضافة طابعة"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"تم العثور على <xliff:g id="COUNT">%1$s</xliff:g> طابعة"</item>
-    <item quantity="other" msgid="6533817036607128241">"تم العثور على <xliff:g id="COUNT">%1$s</xliff:g> من الطابعات"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"اختر خدمة طباعة"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"البحث عن طابعات"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"لم يتم العثور على طابعات"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"جارٍ طباعة <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"جارٍ إلغاء <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"خطا في الطابعة <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"رفضت الطابعة <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> مهمة طباعة"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> من مهام الطباعة"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"إلغاء"</string>
-    <string name="restart" msgid="2472034227037808749">"إعادة تشغيل"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"لا يوجد اتصال بالطابعة"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"غير معروف"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – غير متاحة"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"أبيض وأسود"</item>
-    <item msgid="2762241247228983754">"اللون"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"صورة أشخاص"</item>
-    <item msgid="3199660090246166812">"معالم"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"الكل"</item>
-    <item msgid="6812869625222503603">"النطاق"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-bg/strings.xml b/packages/PrintSpooler/res/values-bg/strings.xml
deleted file mode 100644
index 7f8c3aa..0000000
--- a/packages/PrintSpooler/res/values-bg/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Спулер за печат"</string>
-    <string name="print_button" msgid="645164566271246268">"Печат"</string>
-    <string name="save_button" msgid="1921310454071758999">"Запазване"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Местоназначение"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Копия"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Размер на хартията"</string>
-    <string name="label_color" msgid="1108690305218188969">"Цвят"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Ориентация"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Страници (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Визуализация за печат"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Инсталиране на визуализатор на PDF"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Получи се срив в приложението за отпечатване"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Страници"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Заданието за печат се генерира"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Запазване като PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Всички принтери…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Диалогов прозорец за отпечатване"</string>
-    <string name="search" msgid="5421724265322228497">"Търсене"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Всички принтери"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Добавяне на услуга"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Полето за търсене е показано"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Полето за търсене е скрито"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Добавяне на принтер"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Намерен е <xliff:g id="COUNT">%1$s</xliff:g> принтер"</item>
-    <item quantity="other" msgid="6533817036607128241">"Намерени са <xliff:g id="COUNT">%1$s</xliff:g> принтера"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Избиране на услуга за отпечатване"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Търсят се принтери"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Няма намерени принтери"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"„<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>“ се отпечатва"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"„<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>“ се анулира"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Грешка в принтера при „<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>“"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Принтерът блокира при „<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>“"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Отказ"</string>
-    <string name="restart" msgid="2472034227037808749">"Рестартиране"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Няма връзка с принтера"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"няма данни"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – не е налице"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Черно-бяло"</item>
-    <item msgid="2762241247228983754">"Цветно"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Вертикално"</item>
-    <item msgid="3199660090246166812">"Хоризонтално"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Всички"</item>
-    <item msgid="6812869625222503603">"Поредица"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ca/strings.xml b/packages/PrintSpooler/res/values-ca/strings.xml
deleted file mode 100644
index 330c79b..0000000
--- a/packages/PrintSpooler/res/values-ca/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Gest. cues impr."</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimeix"</string>
-    <string name="save_button" msgid="1921310454071758999">"Desa"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destinació"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Còpies"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Mida del paper"</string>
-    <string name="label_color" msgid="1108690305218188969">"Color"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientació"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pàgines (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Visualització prèvia impressió"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instal·la un lector de PDF per a visualitz. prèvia"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"L\'aplicació d\'impressió ha fallat"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pàgines"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generant tasca impressió"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Desa com a PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Totes les impressores…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Diàleg d\'impressió"</string>
-    <string name="search" msgid="5421724265322228497">"Cerca"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Totes les impressores"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Afegeix un servei"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Es mostra el quadre de cerca"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"S\'ha amagat el quadre de cerca"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Afegeix una impressora"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"S\'ha trobat <xliff:g id="COUNT">%1$s</xliff:g> impressora"</item>
-    <item quantity="other" msgid="6533817036607128241">"S\'han trobat <xliff:g id="COUNT">%1$s</xliff:g> impressores"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Selecció del servei d\'impressió"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Cerca d\'impressores"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"No s\'ha trobat cap impressora"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"S\'està imprimint <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"S\'està cancel·lant <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Error d\'impressora <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Impressora bloquejada <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Tasca d\'impressió per a <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Tasques d\'impressió de <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Cancel·la"</string>
-    <string name="restart" msgid="2472034227037808749">"Reinicia"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"No hi ha connexió amb la impressora"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"desconegut"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>: no disponible"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Blanc i negre"</item>
-    <item msgid="2762241247228983754">"Color"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Vertical"</item>
-    <item msgid="3199660090246166812">"Horitzontal"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Tots"</item>
-    <item msgid="6812869625222503603">"Interval"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-cs/strings.xml b/packages/PrintSpooler/res/values-cs/strings.xml
deleted file mode 100644
index c45a965..0000000
--- a/packages/PrintSpooler/res/values-cs/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Tisk"</string>
-    <string name="save_button" msgid="1921310454071758999">"Uložit"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Cíl"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopie"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Velikost papíru"</string>
-    <string name="label_color" msgid="1108690305218188969">"Barva"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientace"</string>
-    <string name="label_pages" msgid="6300874667546617333">"STRÁNKY (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Náhled tisku"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Nainstalovat prohlížeč PDF (umožní náhled)"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Aplikace tisku selhala"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Stránky"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generování úlohy tisku"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Uložit ve formátu PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Všechny tiskárny…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Dialog tisku"</string>
-    <string name="search" msgid="5421724265322228497">"Hledat"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Všechny tiskárny"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Přidat službu"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Vyhledávací pole se zobrazuje"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Vyhledávací pole je skryto"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Přidat tiskárnu"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Počet nalezených tiskáren: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-    <item quantity="other" msgid="6533817036607128241">"Počet nalezených tiskáren: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Zvolte službu tisku"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Vyhledávání tiskáren"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nebyly nalezeny žádné tiskárny"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Tisk úlohy <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Rušení úlohy <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Chyba tiskárny u úlohy <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Tiskárna blokuje úlohu <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Zrušit"</string>
-    <string name="restart" msgid="2472034227037808749">"Restartovat"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nelze se připojit k tiskárně"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"neznámé"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – není k dispozici"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Černobíle"</item>
-    <item msgid="2762241247228983754">"Barevně"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Na výšku"</item>
-    <item msgid="3199660090246166812">"Na šířku"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Vše"</item>
-    <item msgid="6812869625222503603">"Rozsah"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-da/strings.xml b/packages/PrintSpooler/res/values-da/strings.xml
deleted file mode 100644
index c711d67..0000000
--- a/packages/PrintSpooler/res/values-da/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Udskriv"</string>
-    <string name="save_button" msgid="1921310454071758999">"Gem"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destination"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopier"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papirstørrelse"</string>
-    <string name="label_color" msgid="1108690305218188969">"Farve"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Retning"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Sider (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Vis udskrift"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installer et PDF-visningsprog. for at se eksempel"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Udskrivningsapp gik ned"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Sider"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Udskriften generes"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Gem som PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Alle printere..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Udskriftsdialog"</string>
-    <string name="search" msgid="5421724265322228497">"Søg"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Alle printere"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Tilføj tjeneste"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Søgefeltet vises"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Søgefeltet er skjult"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Tilføj printer"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Der blev fundet <xliff:g id="COUNT">%1$s</xliff:g> printer"</item>
-    <item quantity="other" msgid="6533817036607128241">"Der blev fundet <xliff:g id="COUNT">%1$s</xliff:g> printere"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Vælg udskriftstjeneste"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Søger efter printere"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Der blev ikke fundet nogen printere"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> udskrives"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> annulleres"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Udskriften <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> mislykkedes"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printeren har blokeret <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>-udskriftsjob"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>-udskriftsjobs"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Annuller"</string>
-    <string name="restart" msgid="2472034227037808749">"Genstart"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Ingen forbindelse til printer"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"ukendt"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – ikke tilgængelig"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Sort/hvid"</item>
-    <item msgid="2762241247228983754">"Farve"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portræt"</item>
-    <item msgid="3199660090246166812">"Landskab"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Alle"</item>
-    <item msgid="6812869625222503603">"Interval"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-de/strings.xml b/packages/PrintSpooler/res/values-de/strings.xml
deleted file mode 100644
index f4aef65..0000000
--- a/packages/PrintSpooler/res/values-de/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Druck-Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Drucken"</string>
-    <string name="save_button" msgid="1921310454071758999">"Speichern"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Ziel"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Exemplare"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papiergröße"</string>
-    <string name="label_color" msgid="1108690305218188969">"Farbe"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Ausrichtung"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Seiten (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Vorschau drucken"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"PDF-Viewer für Vorschau installieren"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Druck-App abgestürzt"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Seiten"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Druckauftrag wird generiert..."</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Als PDF speichern"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Alle Drucker…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Druckdialogfeld"</string>
-    <string name="search" msgid="5421724265322228497">"Suchen"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Alle Drucker"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Dienst hinzufügen"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Suchfeld angezeigt"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Suchfeld ausgeblendet"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Drucker hinzufügen"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> Drucker gefunden"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> Drucker gefunden"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Druckdienst auswählen"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Suche nach Druckern"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Keine Drucker gefunden"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> wird gedruckt..."</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> wird abgebrochen..."</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Druckerfehler <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Drucker hat <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> blockiert."</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Druckauftrag \"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>\""</item>
-    <item quantity="other" msgid="8746611264734222865">"Druckaufträge \"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>\""</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Abbrechen"</string>
-    <string name="restart" msgid="2472034227037808749">"Neu starten"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Keine Verbindung zum Drucker"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"unbekannt"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – nicht verfügbar"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Schwarz-weiß"</item>
-    <item msgid="2762241247228983754">"Farbe"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Hochformat"</item>
-    <item msgid="3199660090246166812">"Querformat"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Alle"</item>
-    <item msgid="6812869625222503603">"Bereich"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-el/strings.xml b/packages/PrintSpooler/res/values-el/strings.xml
deleted file mode 100644
index dc3ac8d..0000000
--- a/packages/PrintSpooler/res/values-el/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Λογισμικό ουράς εκτύπωσης"</string>
-    <string name="print_button" msgid="645164566271246268">"Εκτύπωση"</string>
-    <string name="save_button" msgid="1921310454071758999">"Αποθήκευση"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Προορισμός"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Αντίγραφα"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Μέγεθος χαρτιού"</string>
-    <string name="label_color" msgid="1108690305218188969">"Χρώμα"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Προσανατολισμός"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Σελίδες (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Προεπισκόπηση εκτύπωσης"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Εγκαταστήστε το PDF viewer για προεπισκόπηση"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Διακοπή λειτουργίας εφαρμογής εκτύπωσης"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Σελίδες"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Δημιουργία εργασίας εκτύπωσης"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Αποθήκευση ως PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Όλοι οι εκτυπωτές…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Πλαίσιο διαλόγου εκτύπωσης"</string>
-    <string name="search" msgid="5421724265322228497">"Αναζήτηση"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Όλοι οι εκτυπωτές"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Προσθήκη υπηρεσίας"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Εμφάνιση πλαισίου αναζήτησης"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Απόκρυψη πλαισίου αναζήτησης"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Προσθήκη εκτυπωτή"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Βρέθηκε <xliff:g id="COUNT">%1$s</xliff:g> εκτυπωτής"</item>
-    <item quantity="other" msgid="6533817036607128241">"Βρέθηκαν <xliff:g id="COUNT">%1$s</xliff:g> εκτυπωτές"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Επιλέξτε υπηρεσία εκτύπωσης"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Αναζήτηση για εκτυπωτές"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Δεν βρέθηκαν εκτυπωτές"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Εκτύπωση <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Ακύρωση <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Σφάλμα εκτυπωτή <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Ο εκτυπωτής απέκλεισε <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Ακύρωση"</string>
-    <string name="restart" msgid="2472034227037808749">"Επανεκκίνηση"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Δεν υπάρχει σύνδεση με εκτυπωτή"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"άγνωστο"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – μη διαθέσιμο"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Ασπρόμαυρο"</item>
-    <item msgid="2762241247228983754">"Χρώμα"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Πορτραίτο"</item>
-    <item msgid="3199660090246166812">"Οριζόντια"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Όλα"</item>
-    <item msgid="6812869625222503603">"Εύρος"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-en-rGB/strings.xml b/packages/PrintSpooler/res/values-en-rGB/strings.xml
deleted file mode 100644
index d94cbfb..0000000
--- a/packages/PrintSpooler/res/values-en-rGB/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Print"</string>
-    <string name="save_button" msgid="1921310454071758999">"Save"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destination"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copies"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Paper Size"</string>
-    <string name="label_color" msgid="1108690305218188969">"Colour"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientation"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pages (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Print preview"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Install PDF viewer for preview"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Printing app crashed"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pages"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generating print job"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Save as PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"All printers…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Print dialogue"</string>
-    <string name="search" msgid="5421724265322228497">"Search"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"All printers"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Add service"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Search box shown"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Search box hidden"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Add printer"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> printer found"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> printers found"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Choose print service"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Searching for printers"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"No printers found"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Printing <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Cancelling <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Printer error <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printer blocked <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> print job"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> print jobs"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Cancel"</string>
-    <string name="restart" msgid="2472034227037808749">"Restart"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"No connection to printer"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"unknown"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – unavailable"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Black &amp; White"</item>
-    <item msgid="2762241247228983754">"Colour"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portrait"</item>
-    <item msgid="3199660090246166812">"Landscape"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"All"</item>
-    <item msgid="6812869625222503603">"Range"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-en-rIN/strings.xml b/packages/PrintSpooler/res/values-en-rIN/strings.xml
deleted file mode 100644
index d94cbfb..0000000
--- a/packages/PrintSpooler/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Print"</string>
-    <string name="save_button" msgid="1921310454071758999">"Save"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destination"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copies"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Paper Size"</string>
-    <string name="label_color" msgid="1108690305218188969">"Colour"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientation"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pages (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Print preview"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Install PDF viewer for preview"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Printing app crashed"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pages"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generating print job"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Save as PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"All printers…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Print dialogue"</string>
-    <string name="search" msgid="5421724265322228497">"Search"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"All printers"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Add service"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Search box shown"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Search box hidden"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Add printer"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> printer found"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> printers found"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Choose print service"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Searching for printers"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"No printers found"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Printing <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Cancelling <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Printer error <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printer blocked <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> print job"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> print jobs"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Cancel"</string>
-    <string name="restart" msgid="2472034227037808749">"Restart"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"No connection to printer"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"unknown"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – unavailable"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Black &amp; White"</item>
-    <item msgid="2762241247228983754">"Colour"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portrait"</item>
-    <item msgid="3199660090246166812">"Landscape"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"All"</item>
-    <item msgid="6812869625222503603">"Range"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-es-rUS/strings.xml b/packages/PrintSpooler/res/values-es-rUS/strings.xml
deleted file mode 100644
index 13ca561..0000000
--- a/packages/PrintSpooler/res/values-es-rUS/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Cola de impresión"</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimir"</string>
-    <string name="save_button" msgid="1921310454071758999">"Guardar"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destino"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copias"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Tamaño del papel"</string>
-    <string name="label_color" msgid="1108690305218188969">"Color"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientación"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Páginas (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Vista previa de impresión"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instalar visualizador de PDF para vista previa"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"La aplicación de impresión falló"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Páginas"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generando trabajo de impresión"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Guardar como PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Todas las impresoras…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Cuadro de diálogo de impresión"</string>
-    <string name="search" msgid="5421724265322228497">"Buscar"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Todas las impresoras"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Agregar servicio"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Cuadro de búsqueda visible"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Cuadro de búsqueda oculto"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Agregar impresora"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Se encontró <xliff:g id="COUNT">%1$s</xliff:g> impresora."</item>
-    <item quantity="other" msgid="6533817036607128241">"Se encontraron <xliff:g id="COUNT">%1$s</xliff:g> impresoras."</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Elegir servicio de impresión"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Buscando impresoras"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"No se encontraron impresoras"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Imprimiendo <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Cancelando <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Error de impresora <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"La impresora bloqueó <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>."</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Trabajo de impresión <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Trabajos de impresión <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Cancelar"</string>
-    <string name="restart" msgid="2472034227037808749">"Reiniciar"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"No hay conexión con la impresora."</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"desconocido"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>: no disponible"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Blanco y negro"</item>
-    <item msgid="2762241247228983754">"Color"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Vertical"</item>
-    <item msgid="3199660090246166812">"Horizontal"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Todas"</item>
-    <item msgid="6812869625222503603">"Intervalo"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-es/strings.xml b/packages/PrintSpooler/res/values-es/strings.xml
deleted file mode 100644
index e0fd096..0000000
--- a/packages/PrintSpooler/res/values-es/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Cola de impresión"</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimir"</string>
-    <string name="save_button" msgid="1921310454071758999">"Guardar"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destino"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copias"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Tamaño del papel"</string>
-    <string name="label_color" msgid="1108690305218188969">"Color"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientación"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Páginas (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Vista previa de impresión"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instalar visor PDF para obtener vista previa"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Error de aplicación de impresión"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Páginas"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generando trabajo de impresión"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Guardar como PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Todas las impresoras…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Cuadro de diálogo de impresión"</string>
-    <string name="search" msgid="5421724265322228497">"Buscar"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Todas las impresoras"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Añadir servicio"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Cuadro de búsqueda visible"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Cuadro de búsqueda oculto"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Añadir impresora"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Se ha encontrado <xliff:g id="COUNT">%1$s</xliff:g> impresora"</item>
-    <item quantity="other" msgid="6533817036607128241">"Se han encontrado <xliff:g id="COUNT">%1$s</xliff:g> impresoras"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Seleccionar servicio de impresión"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Buscando impresoras"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"No se encontraron impresoras"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Imprimiendo <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Cancelando <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Error de impresora <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"La impresora ha bloqueado <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Cancelar"</string>
-    <string name="restart" msgid="2472034227037808749">"Volver a empezar"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"No hay conexión con la impresora"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"desconocido"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – no disponible"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Blanco y negro"</item>
-    <item msgid="2762241247228983754">"Color"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Vertical"</item>
-    <item msgid="3199660090246166812">"Horizontal"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Todo"</item>
-    <item msgid="6812869625222503603">"Intervalo"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-et-rEE/strings.xml b/packages/PrintSpooler/res/values-et-rEE/strings.xml
deleted file mode 100644
index 8f7fc58..0000000
--- a/packages/PrintSpooler/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Prindispuuler"</string>
-    <string name="print_button" msgid="645164566271246268">"Prindi"</string>
-    <string name="save_button" msgid="1921310454071758999">"Salvesta"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Sihtkoht"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Koopiaid"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Paberiformaat"</string>
-    <string name="label_color" msgid="1108690305218188969">"Värv"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Suund"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Lehti (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Prindi eelvaade"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"PDF-vaaturi installimine eelvaate kuvamiseks"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Printimisrakendus jooksis kokku"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Lehed"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Prinditöö loomine"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Salvesta PDF-ina"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Kõik printerid …"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Printimisdialoog"</string>
-    <string name="search" msgid="5421724265322228497">"Otsing"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Kõik printerid"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Lisa teenus"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Otsingukast on kuvatud"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Otsingukast on peidetud"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Lisa printer"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Leiti <xliff:g id="COUNT">%1$s</xliff:g> printer"</item>
-    <item quantity="other" msgid="6533817036607128241">"Leiti <xliff:g id="COUNT">%1$s</xliff:g> printerit"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Prinditeenuse valimine"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Printerite otsimine"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Printereid ei leitud"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Prinditöö <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> printimine"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Prinditöö <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> tühistamine"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Printeri viga: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printer blokeeris töö <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Tühista"</string>
-    <string name="restart" msgid="2472034227037808749">"Taaskäivita"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Printeriühendus puudub"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"teadmata"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – pole saadaval"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Mustvalge"</item>
-    <item msgid="2762241247228983754">"Värv"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Vertikaalpaigutus"</item>
-    <item msgid="3199660090246166812">"Horisontaalpaigutus"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Kõik"</item>
-    <item msgid="6812869625222503603">"Vahemik"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-fa/strings.xml b/packages/PrintSpooler/res/values-fa/strings.xml
deleted file mode 100644
index 1f8324b..0000000
--- a/packages/PrintSpooler/res/values-fa/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"هماهنگ‌کننده چاپ"</string>
-    <string name="print_button" msgid="645164566271246268">"چاپ"</string>
-    <string name="save_button" msgid="1921310454071758999">"ذخیره"</string>
-    <string name="label_destination" msgid="9132510997381599275">"مقصد"</string>
-    <string name="label_copies" msgid="3634531042822968308">"کپی‌ها"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"اندازه کاغذ"</string>
-    <string name="label_color" msgid="1108690305218188969">"رنگی"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"جهت"</string>
-    <string name="label_pages" msgid="6300874667546617333">"صفحات (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"پیش‌نمایش چاپ"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"نصب نمایشگر PDF برای پیش‌نمایش"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"برنامه چاپ خراب شد"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"صفحات"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"در حال ایجاد کار چاپ"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"ذخیره به‌عنوان PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"همه چاپگرها..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"چاپ گفتگو"</string>
-    <string name="search" msgid="5421724265322228497">"جستجو"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"همه چاپگرها"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"افزودن سرویس"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"کادر جستجو نمایان شد"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"کادر جستجو پنهان شد"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"افزودن چاپگر"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> چاپگر یافت شد"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> چاپگر یافت شد"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"انتخاب سرویس چاپ"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"در حال جستجو برای چاپگرها"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"هیچ چاپگری یافت نشد"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"در حال چاپ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"در حال لغو <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"خطای چاپگر <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"چاپگر، کار <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> را مسدود کرد"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"کار چاپ <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"کارهای چاپ <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"لغو"</string>
-    <string name="restart" msgid="2472034227037808749">"راه‌اندازی مجدد"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"اتصال با چاپگر برقرار نیست"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"نامعلوم"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> - در دسترس نیست"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"سیاه و سفید"</item>
-    <item msgid="2762241247228983754">"رنگی"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"عمودی"</item>
-    <item msgid="3199660090246166812">"افقی"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"همه"</item>
-    <item msgid="6812869625222503603">"محدوده"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-fi/strings.xml b/packages/PrintSpooler/res/values-fi/strings.xml
deleted file mode 100644
index 28ab391..0000000
--- a/packages/PrintSpooler/res/values-fi/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Taustatulostus"</string>
-    <string name="print_button" msgid="645164566271246268">"Tulosta"</string>
-    <string name="save_button" msgid="1921310454071758999">"Tallenna"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Kohde"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopiot"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Paperikoko"</string>
-    <string name="label_color" msgid="1108690305218188969">"Väri"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Suunta"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Sivut (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Tulostuksen esikatselu"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Asenna PDF-katseluohjelma esikatselua varten"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Tulostussovellus kaatui"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Sivut"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Luodaan tulostustyö"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Tallenna PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Kaikki tulostimet…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Tulostusikkuna"</string>
-    <string name="search" msgid="5421724265322228497">"Haku"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Kaikki tulostimet"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Lisää palvelu"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Hakukenttä näkyvissä"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Hakukenttä piilotettu"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Lisää tulostin"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Löytyi <xliff:g id="COUNT">%1$s</xliff:g> tulostin"</item>
-    <item quantity="other" msgid="6533817036607128241">"Löytyi <xliff:g id="COUNT">%1$s</xliff:g> tulostinta"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Valitse tulostuspalvelu"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Etsitään tulostimia"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Tulostimia ei löydy"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Tulostetaan <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Peruutetaan työ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Tulostinvirhe työlle <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Tulostin esti työn <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Peruuta"</string>
-    <string name="restart" msgid="2472034227037808749">"Käynnistä uudelleen"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Ei yhteyttä tulostimeen"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"tuntematon"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – ei käytettävissä"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Mustavalkoinen"</item>
-    <item msgid="2762241247228983754">"Väri"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Pysty"</item>
-    <item msgid="3199660090246166812">"Vaaka"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Kaikki"</item>
-    <item msgid="6812869625222503603">"Väli"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-fr-rCA/strings.xml b/packages/PrintSpooler/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 7991dca..0000000
--- a/packages/PrintSpooler/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"File d\'att. impr."</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimer"</string>
-    <string name="save_button" msgid="1921310454071758999">"Enregistrer"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destination"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copies"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Format du papier"</string>
-    <string name="label_color" msgid="1108690305218188969">"Couleur"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientation"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pages (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Aperçu avant impression"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installer un lecteur PDF pour voir l\'aperçu"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"L\'application à l\'origine de l\'impression a planté"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pages"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Génération tâche impression…"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Enregistrer en format PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Toutes les imprimantes…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Boîte de dialogue d\'impression"</string>
-    <string name="search" msgid="5421724265322228497">"Rechercher"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Toutes les imprimantes"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Ajouter le service"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Champ de recherche affiché"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Champ de recherche masqué"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Ajouter une imprimante"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> imprimante trouvée"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> imprimantes trouvées"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Sélectionner le service d\'impression"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Recherche d\'imprimantes en cours..."</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Aucune imprimante trouvée"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Impression de <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> en cours…"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Annulation de « <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> »…"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Erreur impression : « <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> »"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Impression de « <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> » bloquée"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Tâche d\'impression <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Tâches d\'impression <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Annuler"</string>
-    <string name="restart" msgid="2472034227037808749">"Recommencer"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Aucune connexion à l\'imprimante"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"inconnu"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> — indisponible"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Noir et blanc"</item>
-    <item msgid="2762241247228983754">"Couleur"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portrait"</item>
-    <item msgid="3199660090246166812">"Paysage"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Tous"</item>
-    <item msgid="6812869625222503603">"Plage"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-fr/strings.xml b/packages/PrintSpooler/res/values-fr/strings.xml
deleted file mode 100644
index 9f2eda7..0000000
--- a/packages/PrintSpooler/res/values-fr/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Spouler impress."</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimer"</string>
-    <string name="save_button" msgid="1921310454071758999">"Enregistrer"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destination"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copies"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Format du papier"</string>
-    <string name="label_color" msgid="1108690305218188969">"Couleur"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientation"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pages (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Aperçu avant impression"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installer un lecteur PDF pour afficher l\'aperçu"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"L\'application à l\'origine de l\'impression a planté"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pages"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Génération tâche impression…"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Enregistrer au format .PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Toutes les imprimantes…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Boîte de dialogue d\'impression"</string>
-    <string name="search" msgid="5421724265322228497">"Rechercher"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Toutes les imprimantes"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Ajouter un service"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Champ de recherche affiché."</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Champ de recherche masqué."</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Ajouter une imprimante"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> imprimante trouvée."</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> imprimantes trouvées."</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Sélectionner le service d\'impression"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Recherche d\'imprimantes en cours"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Aucune imprimante trouvée"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Impression de \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" en cours…"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Annulation de \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" en cours…"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Erreur impression pour \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\""</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Impression de \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" bloquée"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Tâche d\'impression <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Tâches d\'impression <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Annuler"</string>
-    <string name="restart" msgid="2472034227037808749">"Redémarrer"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Aucune connexion à l\'imprimante."</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"inconnue"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – indisponible"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Noir et blanc"</item>
-    <item msgid="2762241247228983754">"Couleur"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portrait"</item>
-    <item msgid="3199660090246166812">"Paysage"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Tout"</item>
-    <item msgid="6812869625222503603">"Plage"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-hi/strings.xml b/packages/PrintSpooler/res/values-hi/strings.xml
deleted file mode 100644
index e34d2d4..0000000
--- a/packages/PrintSpooler/res/values-hi/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"प्रिंट स्पूलर"</string>
-    <string name="print_button" msgid="645164566271246268">"प्रिंट करें"</string>
-    <string name="save_button" msgid="1921310454071758999">"सहेजें"</string>
-    <string name="label_destination" msgid="9132510997381599275">"गंतव्य"</string>
-    <string name="label_copies" msgid="3634531042822968308">"प्रतियां"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"कागज़ का आकार"</string>
-    <string name="label_color" msgid="1108690305218188969">"रंग"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"अभिविन्‍यास"</string>
-    <string name="label_pages" msgid="6300874667546617333">"पृष्‍ठ (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"प्रिंट पूर्वावलोकन"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"पूर्वावलोकन के लिए PDF व्यूअर इंस्टॉल करें"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"प्रिंटिंग एप्लिकेशन क्रैश हो गया"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"पृष्ठ"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"प्रिंट कार्य जनरेट हो रहा है"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"PDF के रूप में सहेजें"</string>
-    <string name="all_printers" msgid="5018829726861876202">"सभी प्रिंटर..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"प्रिंट संवाद"</string>
-    <string name="search" msgid="5421724265322228497">"खोजें"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"सभी प्रिंटर"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"सेवा जोड़ें"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"खोज बॉक्स प्रदर्शित है"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"खोज बॉक्स छिपा हुआ है"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"प्रिंटर जोड़ें"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> प्रिंटर मिला"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> प्रिंटर मिले"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"प्रिंट सेवा चुनें"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"प्रिंटर खोज रहा है"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"कोई प्रिंटर नहीं मिले"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> प्रिंट हो रहा है"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> रद्द हो रहा है"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"प्रिंटर त्रुटि <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"प्रिंटर अवरोधित <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"रद्द करें"</string>
-    <string name="restart" msgid="2472034227037808749">"पुन: आरंभ करें"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"प्रिंटर के लिए कोई कनेक्शन नहीं"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"अज्ञात"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – अनुपलब्ध"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"श्याम और श्वेत"</item>
-    <item msgid="2762241247228983754">"रंग"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"पोर्ट्रेट"</item>
-    <item msgid="3199660090246166812">"लैंडस्केप"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"सभी"</item>
-    <item msgid="6812869625222503603">"सीमा"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-hr/strings.xml b/packages/PrintSpooler/res/values-hr/strings.xml
deleted file mode 100644
index 0f225c8..0000000
--- a/packages/PrintSpooler/res/values-hr/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Ispis"</string>
-    <string name="save_button" msgid="1921310454071758999">"Spremi"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Odredište"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopije"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Veličina papira"</string>
-    <string name="label_color" msgid="1108690305218188969">"U boji"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orijentacija"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Stranice (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Pregled ispisa"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instaliraj PDF preglednik za pregled"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Srušila se aplikacija za ispis"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Stranice"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generiranje zadatka ispisa"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Spremi kao PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Svi pisači…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Dijaloški okvir za ispis"</string>
-    <string name="search" msgid="5421724265322228497">"Pretraživanje"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Svi pisači"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Dodaj uslugu"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Okvir za pretraživanje prikazan je"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Okvir za pretraživanje skriven je"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Dodaj pisač"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Pronađen je <xliff:g id="COUNT">%1$s</xliff:g> pisač"</item>
-    <item quantity="other" msgid="6533817036607128241">"Pronađen je sljedeći broj pisača: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Odaberite uslugu ispisa"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Traženje pisača"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nije pronađen nijedan pisač"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Ispisivanje <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Otkazivanje zadatka <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Pogreška pisača <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Pisač je blokirao <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Odustani"</string>
-    <string name="restart" msgid="2472034227037808749">"Ponovo pokreni"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nema veze s pisačem"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"nepoznato"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – zadatak nije dostupan"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Crno-bijelo"</item>
-    <item msgid="2762241247228983754">"U boji"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portret"</item>
-    <item msgid="3199660090246166812">"Pejzaž"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Sve"</item>
-    <item msgid="6812869625222503603">"Raspon"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-hu/strings.xml b/packages/PrintSpooler/res/values-hu/strings.xml
deleted file mode 100644
index 3c3402d..0000000
--- a/packages/PrintSpooler/res/values-hu/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Nyomtatásisor-kezelő"</string>
-    <string name="print_button" msgid="645164566271246268">"Nyomtatás"</string>
-    <string name="save_button" msgid="1921310454071758999">"Mentés"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Cél"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Példányszám"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papírméret"</string>
-    <string name="label_color" msgid="1108690305218188969">"Szín"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Tájolás"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Oldalszám (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Előnézet nyomtatása"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Az előnézethez telepítse a PDF-megtekintőt."</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"A nyomtatási alkalmazás összeomlott."</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Oldalak"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Nyomtatási feladat létrehozása"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Mentés PDF-ként"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Az összes nyomtató…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Nyomtatási párbeszédablak"</string>
-    <string name="search" msgid="5421724265322228497">"Keresés"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Az összes nyomtató"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Szolgáltatás hozzáadása"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Keresőmező megjelenítve"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Keresőmező elrejtve"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Nyomtató hozzáadása"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> nyomtató észlelve"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> nyomtató észlelve"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Nyomtatási szolgáltatás kiválasztása"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Nyomtatók keresése"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nem található nyomtató"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"A(z) <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> nyomtatása"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"A(z) <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> törlése"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Nyomtatási hiba: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"A(z) <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> letiltva."</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> – nyomtatási feladat"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> – nyomtatási feladatok"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Mégse"</string>
-    <string name="restart" msgid="2472034227037808749">"Újraindítás"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nincs kapcsolat a nyomtatóval"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"ismeretlen"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – nem érhető el"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Fekete-fehér"</item>
-    <item msgid="2762241247228983754">"Szín"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Álló"</item>
-    <item msgid="3199660090246166812">"Fekvő"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Összes"</item>
-    <item msgid="6812869625222503603">"Tartomány"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-hy-rAM/strings.xml b/packages/PrintSpooler/res/values-hy-rAM/strings.xml
deleted file mode 100644
index a524654..0000000
--- a/packages/PrintSpooler/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Տպման կարգավար"</string>
-    <string name="print_button" msgid="645164566271246268">"Տպել"</string>
-    <string name="save_button" msgid="1921310454071758999">"Պահել"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Նպատակակետ"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Պատճեններ"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Թղթի չափը"</string>
-    <string name="label_color" msgid="1108690305218188969">"Գույնը"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Դիրքավորում"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Էջեր (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Տպելու նախադիտում"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Նախադիտման համար տեղադրեք PDF դիտարկիչ"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Տպելու ծրագիրը վթարի է ենթարկվել"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Էջեր"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Ձևավորվում է տպելու աշխատանքը"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Պահել որպես PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Բոլոր տպիչները..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Տպելու երկխոսության պատուհան"</string>
-    <string name="search" msgid="5421724265322228497">"Որոնել"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Բոլոր տպիչները"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Ավելացնել ծառայություն"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Որոնման վանդակը ցուցադրված է"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Որոնման վանդակը թաքցվել է"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Ավելացնել տպիչ"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> տպիչ է գտնվել"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> տպիչ է գտնվել"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Ընտրեք տպելու ծառայությունը"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Տպիչների որոնում"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Տպիչներ չեն գտնվել"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Տպվում է՝ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>-ը չեղարկվում է"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Տպիչի սխալ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Տպիչն արգելափակել է <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>-ը"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Չեղարկել"</string>
-    <string name="restart" msgid="2472034227037808749">"Վերագործարկել"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Տպիչի հետ կապ չկա"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"անհայտ"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> տպիչն անհասանելի է"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Սև ու սպիտակ"</item>
-    <item msgid="2762241247228983754">"Գույնը"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Դիմանկար"</item>
-    <item msgid="3199660090246166812">"Լանդշաֆտ"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Բոլորը"</item>
-    <item msgid="6812869625222503603">"Միջակայք"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-in/strings.xml b/packages/PrintSpooler/res/values-in/strings.xml
deleted file mode 100644
index 5f7a56e..0000000
--- a/packages/PrintSpooler/res/values-in/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Cetak"</string>
-    <string name="save_button" msgid="1921310454071758999">"Simpan"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Tujuan"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Salinan"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Ukuran Kertas"</string>
-    <string name="label_color" msgid="1108690305218188969">"Warna"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientasi"</string>
-    <string name="label_pages" msgid="6300874667546617333">"(<xliff:g id="PAGE_COUNT">%1$s</xliff:g>) halaman"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Pratinjau cetak"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Pasang penampil PDF untuk pratinjau"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Aplikasi pencetakan mogok"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Halaman"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Membuat tugas pencetakan"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Simpan sebagai PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Semua printer…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Cetak dialog"</string>
-    <string name="search" msgid="5421724265322228497">"Cari"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Semua printer"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Tambahkan layanan"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Kotak telusur ditampilkan"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Kotak telusur disembunyikan"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Tambahkan printer"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> printer ditemukan"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> printer ditemukan"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Pilih layanan cetak"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Mencari printer"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Tidak ditemukan printer"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Mencetak <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Membatalkan <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Ada kesalahan printer <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printer memblokir <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Batal"</string>
-    <string name="restart" msgid="2472034227037808749">"Mulai Ulang"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Tidak ada sambungan ke printer"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"tak diketahui"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – tidak tersedia"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Hitam &amp; Putih"</item>
-    <item msgid="2762241247228983754">"Warna"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Potret"</item>
-    <item msgid="3199660090246166812">"Lanskap"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Semua"</item>
-    <item msgid="6812869625222503603">"Rentang"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-it/strings.xml b/packages/PrintSpooler/res/values-it/strings.xml
deleted file mode 100644
index 5de5094..0000000
--- a/packages/PrintSpooler/res/values-it/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Stampa"</string>
-    <string name="save_button" msgid="1921310454071758999">"Salva"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destinazione"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copie"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Formato carta"</string>
-    <string name="label_color" msgid="1108690305218188969">"A colori"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientamento"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pagine (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Anteprima di stampa"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installa visualizzatore PDF per anteprima"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Arresto anomalo dell\'app di stampa"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pagine"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generazione processo di stampa"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Salva in PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Tutte le stampanti…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Finestra di dialogo Stampa"</string>
-    <string name="search" msgid="5421724265322228497">"Cerca"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Tutte le stampanti"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Aggiungi servizio"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Casella di ricerca visualizzata"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Casella di ricerca nascosta"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Aggiungi stampante"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> stampante trovata"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> stampanti trovate"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Scegli servizio di stampa"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Ricerca di stampanti"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nessuna stampante trovata"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Stampa di <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Annullamento di <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Errore della stampante: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"La stampante ha bloccato <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Processo di stampa <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Processi di stampa <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Annulla"</string>
-    <string name="restart" msgid="2472034227037808749">"Riavvia"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nessun collegamento alla stampante"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"sconosciuto"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> - non disponibile"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Bianco e nero"</item>
-    <item msgid="2762241247228983754">"A colori"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Verticale"</item>
-    <item msgid="3199660090246166812">"Orizzontale"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Tutte"</item>
-    <item msgid="6812869625222503603">"Intervallo"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-iw/strings.xml b/packages/PrintSpooler/res/values-iw/strings.xml
deleted file mode 100644
index dae65ca..0000000
--- a/packages/PrintSpooler/res/values-iw/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"הדפס"</string>
-    <string name="save_button" msgid="1921310454071758999">"שמור"</string>
-    <string name="label_destination" msgid="9132510997381599275">"יעד"</string>
-    <string name="label_copies" msgid="3634531042822968308">"עותקים"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"גודל נייר"</string>
-    <string name="label_color" msgid="1108690305218188969">"צבע"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"כיוון"</string>
-    <string name="label_pages" msgid="6300874667546617333">"עמודים (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"תצוגה מקדימה של הדפסה"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"התקן מציג PDF ליצירת תצוגה מקדימה"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"אפליקציית ההדפסה קרסה"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"עמודים"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"יוצר עבודת הדפסה"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"שמור כ-PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"כל המדפסות…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"תיבת דו שיח של מדפסת"</string>
-    <string name="search" msgid="5421724265322228497">"חפש"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"כל המדפסות"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"הוסף שירות"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"תיבת החיפוש מוצגת"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"תיבת החיפוש מוסתרת"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"הוסף מדפסת"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"נמצאה מדפסת <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-    <item quantity="other" msgid="6533817036607128241">"נמצאו <xliff:g id="COUNT">%1$s</xliff:g> מדפסות"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"בחר שירות הדפסה"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"מחפש מדפסות"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"לא נמצאו מדפסות"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"מדפיס את <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"מבטל את <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"שגיאת מדפסת ב-<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"המדפסת חסמה את <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"בטל"</string>
-    <string name="restart" msgid="2472034227037808749">"הפעל מחדש"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"אין חיבור למדפסת"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"לא ידוע"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – לא זמינה"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"שחור ולבן"</item>
-    <item msgid="2762241247228983754">"צבע"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"לאורך"</item>
-    <item msgid="3199660090246166812">"לרוחב"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"הכל"</item>
-    <item msgid="6812869625222503603">"טווח"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ja/arrays.xml b/packages/PrintSpooler/res/values-ja/arrays.xml
index 460bdb2..3187cbe 100644
--- a/packages/PrintSpooler/res/values-ja/arrays.xml
+++ b/packages/PrintSpooler/res/values-ja/arrays.xml
@@ -36,7 +36,6 @@
         <item>JPN_KAHU</item>
         <item>JPN_KAKU2</item>
         <item>JPN_YOU4</item>
-
     </string-array>
 
 </resources>
diff --git a/packages/PrintSpooler/res/values-ja/strings.xml b/packages/PrintSpooler/res/values-ja/strings.xml
deleted file mode 100644
index 187698b..0000000
--- a/packages/PrintSpooler/res/values-ja/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"印刷スプーラ"</string>
-    <string name="print_button" msgid="645164566271246268">"印刷"</string>
-    <string name="save_button" msgid="1921310454071758999">"保存"</string>
-    <string name="label_destination" msgid="9132510997381599275">"印刷先"</string>
-    <string name="label_copies" msgid="3634531042822968308">"部数"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"用紙サイズ"</string>
-    <string name="label_color" msgid="1108690305218188969">"色"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"方向"</string>
-    <string name="label_pages" msgid="6300874667546617333">"ページ(<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"印刷プレビュー"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"プレビュー用PDFビューアをインストール"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"印刷アプリでの障害発生"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"ページ数"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"印刷ジョブを生成しています"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"PDF形式で保存"</string>
-    <string name="all_printers" msgid="5018829726861876202">"すべてのプリンタ…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"印刷ダイアログ"</string>
-    <string name="search" msgid="5421724265322228497">"検索"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"すべてのプリンタ"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"サービスを追加"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"検索ボックスは表示されています"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"検索ボックスは表示されていません"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"プリンタを追加"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g>台のプリンタが見つかりました"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g>台のプリンタが見つかりました"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"印刷サービスの選択"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"プリンタの検索中"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"プリンタが見つかりません"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>を印刷しています"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>をキャンセルしています"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"プリンタエラー: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>をブロックしました"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"キャンセル"</string>
-    <string name="restart" msgid="2472034227037808749">"再起動"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"プリンタに接続されていません"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"不明"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>–使用不可"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"モノクロ"</item>
-    <item msgid="2762241247228983754">"色"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"縦向き"</item>
-    <item msgid="3199660090246166812">"横向き"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"すべて"</item>
-    <item msgid="6812869625222503603">"範囲"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ka-rGE/strings.xml b/packages/PrintSpooler/res/values-ka-rGE/strings.xml
deleted file mode 100644
index d519755..0000000
--- a/packages/PrintSpooler/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"ბეჭდვის Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"ბეჭდვა"</string>
-    <string name="save_button" msgid="1921310454071758999">"შენახვა"</string>
-    <string name="label_destination" msgid="9132510997381599275">"დანიშნულება"</string>
-    <string name="label_copies" msgid="3634531042822968308">"ასლები"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"ფურცლის ზომა"</string>
-    <string name="label_color" msgid="1108690305218188969">"ფერი"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"ორიენტაცია"</string>
-    <string name="label_pages" msgid="6300874667546617333">"გვერდები (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"ნახვა ამობეჭდვამდე"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"გადახედვისთვის დააყენეთ PDF მნახველი"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"ბეჭდვის აპი ავარიულად გაითიშა"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"გვერდები"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"მიმდინარეობის ბეჭდვის დავალების შექმნა"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"PDF-ად შენახვა"</string>
-    <string name="all_printers" msgid="5018829726861876202">"ყველა პრინტერი…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"ბეჭდვის სარკმელი"</string>
-    <string name="search" msgid="5421724265322228497">"ძიება"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"ყველა პრინტერი"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"სერვისის დამატება"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"საძიებო ველი ნაჩვენებია"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"საძიებო ველი დამალულია"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"პრინტერის დამატება"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"ნაპოვნია <xliff:g id="COUNT">%1$s</xliff:g> პრინტერი"</item>
-    <item quantity="other" msgid="6533817036607128241">"ნაპოვნია <xliff:g id="COUNT">%1$s</xliff:g> პრინტერი"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"აირჩიეთ ბეჭდვის სერვისი"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"მიმდინარეობს პრინტერების ძიება"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"პრინტერები ვერ მოიძებნა"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"იბეჭდება <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"მიმდინარეობს <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>-ის გაუქმება"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"ბეჭდვის შეცდომა <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"პრინტერმა დაბლოკა <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"გაუქმება"</string>
-    <string name="restart" msgid="2472034227037808749">"გადატვირთვა"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"პრინტერთან კავშირი არ არის"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"უცნობი"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – მიუწვდომელია"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"შავ-თეთრი"</item>
-    <item msgid="2762241247228983754">"ფერი"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"პორტრეტი"</item>
-    <item msgid="3199660090246166812">"პეიზაჟის რეჟიმი"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"ყველა"</item>
-    <item msgid="6812869625222503603">"დიაპაზონი"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-km-rKH/strings.xml b/packages/PrintSpooler/res/values-km-rKH/strings.xml
deleted file mode 100644
index b766a19..0000000
--- a/packages/PrintSpooler/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"បោះពុម្ព​ស្ពូល័រ"</string>
-    <string name="print_button" msgid="645164566271246268">"បោះពុម្ព"</string>
-    <string name="save_button" msgid="1921310454071758999">"រក្សាទុក"</string>
-    <string name="label_destination" msgid="9132510997381599275">"ទិសដៅ"</string>
-    <string name="label_copies" msgid="3634531042822968308">"ច្បាប់​ចម្លង"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"ទំហំ​ក្រដាស"</string>
-    <string name="label_color" msgid="1108690305218188969">"ពណ៌"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"ទិស"</string>
-    <string name="label_pages" msgid="6300874667546617333">"ទំព័រ (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"មើល​មុន​បោះពុម្ព"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"ដំឡើង​កម្មវិធី​មើល PDF សម្រាប់​ការ​មើល​ជា​មុន"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"កម្មវិធី​បោះពុម្ព​គាំង"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"ទំព័រ"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"​បង្កើត​ការ​ងារ​បោះពុម្ព"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"រក្សា​ទុក​ជា PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"ម៉ាស៊ីន​បោះពុម្ព​ទាំងអស់ ..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"ប្រអប់​បោះពុម្ព"</string>
-    <string name="search" msgid="5421724265322228497">"ស្វែងរក"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"ម៉ាស៊ីន​បោះពុម្ព​ទាំងអស់"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"បន្ថែម​សេវាកម្ម"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"បាន​បង្ហាញ​ប្រ​អប់​ស្វែងរក"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"បាន​លាក់​ប្រអប់​ស្វែងរក"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"បន្ថែម​ម៉ាស៊ីន​បោះពុម្ព"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"រក​ឃើញ​ម៉ាស៊ីន​បោះពុម្ព <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-    <item quantity="other" msgid="6533817036607128241">"រក​ឃើញ​ម៉ាស៊ីន​បោះពុម្ព <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"ជ្រើស​សេវា​បោះពុម្ព"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"ស្វែងរក​ម៉ាស៊ីន​បោះពុម្ព"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"រក​មិន​ឃើញ​ម៉ាស៊ីន​បោះពុម្ព"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"កំពុង​​បោះពុម្ព <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"ការ​បោះបង់ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"កំហុស​ម៉ាស៊ីន​បោះពុម្ព <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"ម៉ាស៊ីន​បោះពុម្ព​បាន​ទប់ស្កាត់ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"ការងារ​បោះពុម្ព <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"ការងារ​បោះពុម្ព <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"បោះបង់"</string>
-    <string name="restart" msgid="2472034227037808749">"ចាប់ផ្ដើម​ឡើងវិញ"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"គ្មាន​​​ការ​ភ្ជាប់​ទៅ​ម៉ាស៊ីន​បោះពុម្ព"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"មិន​ស្គាល់"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – មិន​អាច​ប្រើ​បាន"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"ស &amp; ខ្មៅ"</item>
-    <item msgid="2762241247228983754">"ពណ៌"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"បញ្ឈរ"</item>
-    <item msgid="3199660090246166812">"ផ្ដេក"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"ទាំង​អស់"</item>
-    <item msgid="6812869625222503603">"ជួរ"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ko/strings.xml b/packages/PrintSpooler/res/values-ko/strings.xml
deleted file mode 100644
index 01642c9..0000000
--- a/packages/PrintSpooler/res/values-ko/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"인쇄 스풀러"</string>
-    <string name="print_button" msgid="645164566271246268">"인쇄"</string>
-    <string name="save_button" msgid="1921310454071758999">"저장"</string>
-    <string name="label_destination" msgid="9132510997381599275">"대상"</string>
-    <string name="label_copies" msgid="3634531042822968308">"매수"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"용지 크기"</string>
-    <string name="label_color" msgid="1108690305218188969">"색상"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"방향"</string>
-    <string name="label_pages" msgid="6300874667546617333">"페이지 수(<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"인쇄 미리보기"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"미리보기용 PDF 뷰어 설치"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"인쇄 앱에 오류 발생"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"페이지"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"인쇄 작업 생성 중"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"PDF로 저장"</string>
-    <string name="all_printers" msgid="5018829726861876202">"모든 프린터…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"인쇄 대화상자"</string>
-    <string name="search" msgid="5421724265322228497">"검색"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"모든 프린터"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"서비스 추가"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"검색창 표시됨"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"검색창 숨겨짐"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"프린터 추가"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"프린터 <xliff:g id="COUNT">%1$s</xliff:g>대 검색됨"</item>
-    <item quantity="other" msgid="6533817036607128241">"프린터 <xliff:g id="COUNT">%1$s</xliff:g>대 검색됨"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"인쇄 서비스 선택"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"프린터 검색 중"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"프린터 없음"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> 인쇄 중"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> 취소 중"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"프린터 오류: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"차단된 프린터: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"취소"</string>
-    <string name="restart" msgid="2472034227037808749">"다시 시작"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"프린터와 연결되지 않음"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"알 수 없음"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – 사용할 수 없음"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"흑백"</item>
-    <item msgid="2762241247228983754">"컬러"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"세로"</item>
-    <item msgid="3199660090246166812">"가로"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"모두"</item>
-    <item msgid="6812869625222503603">"범위"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-lo-rLA/strings.xml b/packages/PrintSpooler/res/values-lo-rLA/strings.xml
deleted file mode 100644
index cf3a5f7..0000000
--- a/packages/PrintSpooler/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"ຕົວຈັດຄິວການພິມ"</string>
-    <string name="print_button" msgid="645164566271246268">"ພິມ"</string>
-    <string name="save_button" msgid="1921310454071758999">"ບັນທຶກ"</string>
-    <string name="label_destination" msgid="9132510997381599275">"ປາຍທາງ"</string>
-    <string name="label_copies" msgid="3634531042822968308">"ສຳເນົາ"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"ຂະໜາດຂອງໜ້າເຈ້ຍ"</string>
-    <string name="label_color" msgid="1108690305218188969">"ສີ"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"ລວງ"</string>
-    <string name="label_pages" msgid="6300874667546617333">"(<xliff:g id="PAGE_COUNT">%1$s</xliff:g>) ໜ້າ"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"ເບິ່ງກ່ອນພິມ"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"ຕິດຕັ້ງໂປຼແກຼມເບິ່ງ PDF ເພື່ອເບິ່ງຕົວຢ່າງ"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"ແອັບຯພິມລົ້ມເຫລວ"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"ໜ້າ"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"ກຳລັງສ້າງວຽກພິມ"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"ບັນທຶກເປັ​​ນ PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"ທຸກເຄື່ອງພິມ..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"ໜ້າຕ່າງການພິມ"</string>
-    <string name="search" msgid="5421724265322228497">"ຊອກຫາ"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"ທຸກເຄື່ອງພິມ"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"ເພີ່ມບໍລິການ"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"ກ່ອງຊອກຫາຖືກສະແດງ"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"ກ່ອງຊອກຫາຖືກເຊື່ອງ"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"ເພີ່ມເຄື່ອງພິມ"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"ພົບ <xliff:g id="COUNT">%1$s</xliff:g> ເຄື່ອງພິມ"</item>
-    <item quantity="other" msgid="6533817036607128241">"ພົບ <xliff:g id="COUNT">%1$s</xliff:g> ເຄື່ອງພິມ"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"ເລືອກບໍລິການການພິມ"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"ກຳລັງຊອກຫາເຄື່ອງພິມ"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"ບໍ່ພົບເຄື່ອງພິມ"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"ກຳລັງພິມ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"ກຳລັງຍົກເລີກ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"ເຄື່ອງພິມເກີດຂໍ້ຜິດພາດ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"ເຄື່ອງພິມຖືກບລອກ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"ງານພິມ <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"ງານພິມ <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"ຍົກເລີກ"</string>
-    <string name="restart" msgid="2472034227037808749">"ປິດເປີດໃໝ່"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"ບໍ່ມີການເຊື່ອມຕໍ່ຫາເຄື່ອງພິມ"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"ບໍ່ຮູ້ຈັກ"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> - ບໍ່ມີຢູ່"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"ຂາວດຳ"</item>
-    <item msgid="2762241247228983754">"ສີ"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"ລວງຕັ້ງ"</item>
-    <item msgid="3199660090246166812">"ລວງນອນ"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"ທັງໝົດ"</item>
-    <item msgid="6812869625222503603">"ໄລຍະ"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-lt/strings.xml b/packages/PrintSpooler/res/values-lt/strings.xml
deleted file mode 100644
index c8475fe..0000000
--- a/packages/PrintSpooler/res/values-lt/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Spausdinti"</string>
-    <string name="save_button" msgid="1921310454071758999">"Išsaugoti"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Paskirties vieta"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopijos"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Popieriaus dydis"</string>
-    <string name="label_color" msgid="1108690305218188969">"Spalva"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientacija"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Puslapiai (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Spaudinio peržiūra"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Įdiegti PDF peržiūros priemonę"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Spausdinimo programa užstrigo"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Puslapiai"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generuojama spausd. užduotis"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Išsaugoti kaip PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Visi spausdintuvai…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Spausdinimo dialogo langas"</string>
-    <string name="search" msgid="5421724265322228497">"Ieškoti"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Visi spausdintuvai"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Pridėti paslaugą"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Paieškos laukelis rodomas"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Paieškos laukelis paslėptas"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Pridėti spausdintuvą"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Rasta spausdintuvų: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-    <item quantity="other" msgid="6533817036607128241">"Rasta spausdintuvų: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Pasirinkite spausdinimo paslaugą"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Ieškoma spausdintuvų"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nerasta spausdintuvų"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Spausdinama: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Atšaukiama: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Spausdintuvo klaida: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Spausdintuvas užblokavo: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Spausdinimo užduotis: <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Spausdinimo užduotys: <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Atšaukti"</string>
-    <string name="restart" msgid="2472034227037808749">"Paleisti iš naujo"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nėra ryšio su spausdintuvu"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"nežinoma"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"„<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>“ – nepasiekiama"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Nespalvotas"</item>
-    <item msgid="2762241247228983754">"Spalva"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Stačias"</item>
-    <item msgid="3199660090246166812">"Gulsčias"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Visi"</item>
-    <item msgid="6812869625222503603">"Diapazonas"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-lv/strings.xml b/packages/PrintSpooler/res/values-lv/strings.xml
deleted file mode 100644
index 3e277dd..0000000
--- a/packages/PrintSpooler/res/values-lv/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Drukāt"</string>
-    <string name="save_button" msgid="1921310454071758999">"Saglabāt"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Galamērķis"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Eksemplāri"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papīra izmērs"</string>
-    <string name="label_color" msgid="1108690305218188969">"Krāsa"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Virziens"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Lapas (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Drukas priekšskatījums"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instalēt PDF skatītāju priekšskatīšanai"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Drukas lietotne avarēja"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Lapas"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Ģenerē drukas darbu…"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Saglabāt kā PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Visi printeri…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Drukāšanas dialoglodziņš"</string>
-    <string name="search" msgid="5421724265322228497">"Meklēt"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Visi printeri"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Pievienot pakalpojumu"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Meklēšanas lodziņš ir redzams."</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Meklēšanas lodziņš ir paslēpts."</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Pievienot printeri"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Atrasts <xliff:g id="COUNT">%1$s</xliff:g> printeris"</item>
-    <item quantity="other" msgid="6533817036607128241">"Atrasti <xliff:g id="COUNT">%1$s</xliff:g> printeri"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Izvēlieties drukāšanas pakalpojumu"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Printeru meklēšana"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Netika atrasts neviens printeris."</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Notiek darba <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> drukāšana…"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Pārtrauc drukas darbu <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>…"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Printera kļūda ar darbu <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printeris bloķēja darbu <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Atcelt"</string>
-    <string name="restart" msgid="2472034227037808749">"Restartēt"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nav savienojuma ar printeri"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"nezināms"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> — nav pieejams"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Melnbalts"</item>
-    <item msgid="2762241247228983754">"Krāsa"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portrets"</item>
-    <item msgid="3199660090246166812">"Ainava"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Visi"</item>
-    <item msgid="6812869625222503603">"Diapazons"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-mn-rMN/strings.xml b/packages/PrintSpooler/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 7487308..0000000
--- a/packages/PrintSpooler/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Хэвлэгчийн буфер"</string>
-    <string name="print_button" msgid="645164566271246268">"Хэвлэх"</string>
-    <string name="save_button" msgid="1921310454071758999">"Хадгалах"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Хүлээн авагч"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Хуулбарууд"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Цаасны хэмжээ"</string>
-    <string name="label_color" msgid="1108690305218188969">"Өнгө"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Чиглэл"</string>
-    <string name="label_pages" msgid="6300874667546617333">"(<xliff:g id="PAGE_COUNT">%1$s</xliff:g>) хуудас"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Хэвлэхээр урьдчилан харах"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Урьдчилан харахын тулд PDF харагчийг суулгах"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Хэвлэгч апп гацсан"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Хуудас"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Хэвлэх ажил үүсгэж байна"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"PDF болгож хадгалах"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Бүх принтерүүд…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Хэвлэх диалоги"</string>
-    <string name="search" msgid="5421724265322228497">"Хайх"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Бүх принтерүүд"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Үйлчилгээ нэмэх"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Хайлтын нүдийг гаргах"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Хайлтын нүдийг далдлах"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Принтер нэмэх"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> принтер олдсон"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> принтер олдсон"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Хэвлэх үйлчилгээг сонгох"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Принтер хайж байна"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Принтер олдсонгүй"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Хэвлэж байна <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Цуцлаж байна <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Принтерийн алдаа <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Принтер хориглогдсон <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> хэвлэх ажил"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> хэвлэх ажлууд"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Цуцлах"</string>
-    <string name="restart" msgid="2472034227037808749">"Дахин эхлүүлэх"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Принтер холбогдоогүй байна"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"тодорхойгүй"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – ашиглах боломжгүй"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Хар &amp; Цагаан"</item>
-    <item msgid="2762241247228983754">"Өнгө"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Босоо"</item>
-    <item msgid="3199660090246166812">"Хэвтээ"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Бүгд"</item>
-    <item msgid="6812869625222503603">"Хүрээ"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ms-rMY/strings.xml b/packages/PrintSpooler/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 9a2dca3..0000000
--- a/packages/PrintSpooler/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Penspul Cetakan"</string>
-    <string name="print_button" msgid="645164566271246268">"Cetak"</string>
-    <string name="save_button" msgid="1921310454071758999">"Simpan"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destinasi"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Salinan"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Saiz Kertas"</string>
-    <string name="label_color" msgid="1108690305218188969">"Warna"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientasi"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Halaman (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Pratonton cetak"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Pasang pemapar PDF untuk pratonton"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Apl percetakan ranap"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Halaman"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Menjana kerja cetak"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Simpan sebagai PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Semua pencetak..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Dialog cetakan"</string>
-    <string name="search" msgid="5421724265322228497">"Cari"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Semua pencetak"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Tambahkan perkhidmatan"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Kotak carian ditunjukkan"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Kotak carian tersembunyi"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Tambah pencetak"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> pencetak ditemui"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> pencetak ditemui"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Pilih perkhidmatan cetak"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Mencari pencetak"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Tiada pencetak ditemui"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Mencetak <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Membatalkan <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Ralat pencetak <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Pencetak disekat <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Batal"</string>
-    <string name="restart" msgid="2472034227037808749">"Mulakan semula"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Tiada sambungan ke pencetak"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"tidak diketahui"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – tidak tersedia"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Hitam &amp; Putih"</item>
-    <item msgid="2762241247228983754">"Warna"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Potret"</item>
-    <item msgid="3199660090246166812">"Landskap"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Semua"</item>
-    <item msgid="6812869625222503603">"Julat"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-nb/strings.xml b/packages/PrintSpooler/res/values-nb/strings.xml
deleted file mode 100644
index 77798ea..0000000
--- a/packages/PrintSpooler/res/values-nb/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Utskriftskø"</string>
-    <string name="print_button" msgid="645164566271246268">"Skriv ut"</string>
-    <string name="save_button" msgid="1921310454071758999">"Lagre"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destinasjon"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopier"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papirstørrelse"</string>
-    <string name="label_color" msgid="1108690305218188969">"Farge"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Retning"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Sider (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Utskriftsforhåndsvisning"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installer PDF-leser for forhåndsvisning"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Utskriftsappen krasjet"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Sider"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Genererer utskriftsjobb"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Lagre som PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Alle skrivere"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Skriv ut dialog"</string>
-    <string name="search" msgid="5421724265322228497">"Søk"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Alle skrivere"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Legg til tjeneste"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Søkefeltet vises"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Søkefeltet er skjult"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Legg til skriver"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> skriver ble funnet"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> skrivere ble funnet"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Velg utskriftstjeneste"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Søker etter skrivere"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Fant ingen skrivere"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Skriver ut <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Avbryter <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Skriverfeil <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Skriveren blokkerte <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Utskriftsjobb for <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Utskriftsjobber for <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Avbryt"</string>
-    <string name="restart" msgid="2472034227037808749">"Start på nytt"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Ingen forbindelse med skriveren"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"ukjent"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – utilgjengelig"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Svart og hvitt"</item>
-    <item msgid="2762241247228983754">"Farge"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Stående"</item>
-    <item msgid="3199660090246166812">"Liggende"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Alle"</item>
-    <item msgid="6812869625222503603">"Område"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-nl/strings.xml b/packages/PrintSpooler/res/values-nl/strings.xml
deleted file mode 100644
index e576e0c..0000000
--- a/packages/PrintSpooler/res/values-nl/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Afdrukspooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Afdrukken"</string>
-    <string name="save_button" msgid="1921310454071758999">"Opslaan"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Bestemming"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Aantal exemplaren"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Papierformaat"</string>
-    <string name="label_color" msgid="1108690305218188969">"Kleur"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Stand"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pagina\'s (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Afdrukvoorbeeld"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Pdf-viewer installeren voor voorbeeld"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Afdruk-app gecrasht"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pagina\'s"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Afdruktaak genereren"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Opslaan als pdf"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Alle printers…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Afdrukdialoogvenster"</string>
-    <string name="search" msgid="5421724265322228497">"Zoeken"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Alle printers"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Service toevoegen"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Zoekvak weergegeven"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Zoekvak verborgen"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Printer toevoegen"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> printer gevonden"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> printers gevonden"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Afdrukservice kiezen"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Printers zoeken"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Geen printers gevonden"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> afdrukken"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> annuleren"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Printerfout <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> geblokkeerd door printer"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> afdruktaak"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> afdruktaken"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Annuleren"</string>
-    <string name="restart" msgid="2472034227037808749">"Opnieuw starten"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Geen verbinding met printer"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"onbekend"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – niet beschikbaar"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Zwart-wit"</item>
-    <item msgid="2762241247228983754">"Kleur"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portret"</item>
-    <item msgid="3199660090246166812">"Landschap"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Alle"</item>
-    <item msgid="6812869625222503603">"Bereik"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-pl/strings.xml b/packages/PrintSpooler/res/values-pl/strings.xml
deleted file mode 100644
index 252c582..0000000
--- a/packages/PrintSpooler/res/values-pl/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Bufor wydruku"</string>
-    <string name="print_button" msgid="645164566271246268">"Drukuj"</string>
-    <string name="save_button" msgid="1921310454071758999">"Zapisz"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Miejsce docelowe"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopie"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Rozmiar papieru"</string>
-    <string name="label_color" msgid="1108690305218188969">"Kolor"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientacja"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Strony (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Podgląd wydruku"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Zainstaluj przeglądarkę PDF, by zobaczyć podgląd"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Aplikacja drukująca uległa awarii"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Strony"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generowanie zadania wydruku"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Zapisz jako PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Wszystkie drukarki…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Okno drukowania"</string>
-    <string name="search" msgid="5421724265322228497">"Szukaj"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Wszystkie drukarki"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Dodaj usługę"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Pole wyszukiwania jest widoczne"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Pole wyszukiwania jest ukryte"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Dodaj drukarkę"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Znaleziono <xliff:g id="COUNT">%1$s</xliff:g> drukarkę"</item>
-    <item quantity="other" msgid="6533817036607128241">"Znalezione drukarki: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Wybierz usługę drukowania"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Szukanie drukarek"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nie znaleziono drukarek"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Drukowanie: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Anulowanie: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Błąd drukarki: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Drukarka zablokowała <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> zadanie drukowania"</item>
-    <item quantity="other" msgid="8746611264734222865">"Zadania drukowania: <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Anuluj"</string>
-    <string name="restart" msgid="2472034227037808749">"Od nowa"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Brak połączenia z drukarką"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"brak informacji"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – niedostępne"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Czarno-białe"</item>
-    <item msgid="2762241247228983754">"Kolor"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Pionowa"</item>
-    <item msgid="3199660090246166812">"Pozioma"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Wszystkie"</item>
-    <item msgid="6812869625222503603">"Zakres"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-pt-rPT/strings.xml b/packages/PrintSpooler/res/values-pt-rPT/strings.xml
deleted file mode 100644
index 4c3dc76..0000000
--- a/packages/PrintSpooler/res/values-pt-rPT/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimir"</string>
-    <string name="save_button" msgid="1921310454071758999">"Guardar"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destino"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Cópias"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Tamanho do papel"</string>
-    <string name="label_color" msgid="1108690305218188969">"Cor"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientação"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Páginas (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Pré-visualização de impressão"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instalar o leitor de PDF para pré-visualização"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"A aplicação de impressão bloqueou"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Páginas"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"A gerar tarefa de impressão"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Guardar como PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Todas as impressoras..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Caixa de diálogo de impressão"</string>
-    <string name="search" msgid="5421724265322228497">"Pesquisar"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Todas as impressoras"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Adicionar serviço"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Caixa de pesquisa apresentada"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Caixa de pesquisa ocultada"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Adicionar impressora"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> impressora encontrada"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> impressoras encontradas"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Escolher o serviço de impressão"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"A procurar impressoras"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nenhuma impressora encontrada"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"A imprimir <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"A cancelar <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Erro da impressora <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"A impressora bloqueou <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> tarefa de impressão"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> tarefas de impressão"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Cancelar"</string>
-    <string name="restart" msgid="2472034227037808749">"Reiniciar"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Sem ligação à impressora"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"desconhecido"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – indisponível"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Preto e branco"</item>
-    <item msgid="2762241247228983754">"Cor"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Vertical"</item>
-    <item msgid="3199660090246166812">"Horizontal"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Todas"</item>
-    <item msgid="6812869625222503603">"Intervalo"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-pt/strings.xml b/packages/PrintSpooler/res/values-pt/strings.xml
deleted file mode 100644
index 5e13b9f..0000000
--- a/packages/PrintSpooler/res/values-pt/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Sp. de impressão"</string>
-    <string name="print_button" msgid="645164566271246268">"Imprimir"</string>
-    <string name="save_button" msgid="1921310454071758999">"Salvar"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destino"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Cópias"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Tamanho do papel"</string>
-    <string name="label_color" msgid="1108690305218188969">"Cor"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientação"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Páginas (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Visualização de impressão"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instalar o visualizador de PDF"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"O aplicativo de impressão falhou"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Páginas"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Gerando trabalho de impressão"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Salvar como PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Todas as impressoras…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Diálogo de impressão"</string>
-    <string name="search" msgid="5421724265322228497">"Pesquisar"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Todas as impressoras"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Adicionar serviço"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Caixa de pesquisa exibida"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Caixa de pesquisa oculta"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Adicionar impressora"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> impressora encontrada"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> impressoras encontradas"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Selecione o serviço de impressão"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Procurando impressoras"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nenhuma impressora encontrada"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Imprimindo <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Cancelando <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Erro ao imprimir <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"A impressora bloqueou <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Cancelar"</string>
-    <string name="restart" msgid="2472034227037808749">"Reiniciar"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Sem conexão com a impressora"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"desconhecido"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – não disponível"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Preto e branco"</item>
-    <item msgid="2762241247228983754">"Cor"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Retrato"</item>
-    <item msgid="3199660090246166812">"Paisagem"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Todas"</item>
-    <item msgid="6812869625222503603">"Intervalo"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ro/strings.xml b/packages/PrintSpooler/res/values-ro/strings.xml
deleted file mode 100644
index 34571df..0000000
--- a/packages/PrintSpooler/res/values-ro/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Derulator print."</string>
-    <string name="print_button" msgid="645164566271246268">"Printați"</string>
-    <string name="save_button" msgid="1921310454071758999">"Salvați"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destinație"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Copii"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Formatul hârtiei"</string>
-    <string name="label_color" msgid="1108690305218188969">"Color"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientare"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Pagini (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Previzualizați printarea"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Instalați PDF viewer pentru previzualizare"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Aplicația de printare s-a blocat"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Pagini"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Se generează sarcină printare"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Salvați ca PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Toate imprimantele..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Caseta de dialog de printare"</string>
-    <string name="search" msgid="5421724265322228497">"Căutați"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Toate imprimantele"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Adăugați un serviciu"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Caseta de căutare este afișată"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Caseta de căutare este ascunsă"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Adăugați o imprimantă"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> imprimantă găsită"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> (de) imprimante găsite"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Alegeți serviciul de printare"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Se caută imprimante"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nu au fost găsite imprimante"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Se printează <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Se anulează <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Eroare de printare: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printare blocată: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Sarcină de printare <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Sarcini de printare <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Anulați"</string>
-    <string name="restart" msgid="2472034227037808749">"Reporniți"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Nu există conexiune la o imprimantă"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"necunoscut"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> - indisponibil"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Alb-negru"</item>
-    <item msgid="2762241247228983754">"Color"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portret"</item>
-    <item msgid="3199660090246166812">"Peisaj"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Toate"</item>
-    <item msgid="6812869625222503603">"Interval"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-ru/strings.xml b/packages/PrintSpooler/res/values-ru/strings.xml
deleted file mode 100644
index 35695e6..0000000
--- a/packages/PrintSpooler/res/values-ru/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Спулер печати"</string>
-    <string name="print_button" msgid="645164566271246268">"Печать"</string>
-    <string name="save_button" msgid="1921310454071758999">"Сохранить"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Принтер"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Копии"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Размер бумаги"</string>
-    <string name="label_color" msgid="1108690305218188969">"Цветной"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Ориентация"</string>
-    <string name="label_pages" msgid="6300874667546617333">"СТРАНИЦЫ (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Предварительный просмотр"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Установить средство просмотра PDF"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Сбой приложения печати"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Количество страниц"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Создание задания печати…"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Сохранить как PDF-файл"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Все принтеры"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Диалоговое окно печати"</string>
-    <string name="search" msgid="5421724265322228497">"Поиск"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Все принтеры"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Добавить службу печати"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Открыто окно поиска"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Окно поиска скрыто"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Добавить принтер"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Найден <xliff:g id="COUNT">%1$s</xliff:g> принтер"</item>
-    <item quantity="other" msgid="6533817036607128241">"Найдено несколько принтеров (<xliff:g id="COUNT">%1$s</xliff:g>)"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Выберите службу печати"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Поиск принтеров…"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Ничего не найдено"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Печать задания \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\"…"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Отмена задания <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>…"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Ошибка задания \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\""</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Задание \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" заблокировано"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Отмена"</string>
-    <string name="restart" msgid="2472034227037808749">"Повторить"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Нет связи с принтером"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"неизвестно"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – недоступен"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Черно-белое"</item>
-    <item msgid="2762241247228983754">"Цветное"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Книжная"</item>
-    <item msgid="3199660090246166812">"Альбомная"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Все"</item>
-    <item msgid="6812869625222503603">"Диапазон"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-sk/strings.xml b/packages/PrintSpooler/res/values-sk/strings.xml
deleted file mode 100644
index 008481f..0000000
--- a/packages/PrintSpooler/res/values-sk/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Zaraďovač tlače"</string>
-    <string name="print_button" msgid="645164566271246268">"Tlačiť"</string>
-    <string name="save_button" msgid="1921310454071758999">"Uložiť"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Cieľ"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kópie"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Veľkosť papiera"</string>
-    <string name="label_color" msgid="1108690305218188969">"Farba"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientácia"</string>
-    <string name="label_pages" msgid="6300874667546617333">"STRÁNKY (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Ukážka pred tlačou"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Inštalovať zobrazovač PDF na zobrazenie ukážky"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Aplikácia pre tlač zlyhala"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Strany"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Generuje sa tlačová úloha"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Uložiť ako PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Všetky tlačiarne..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Dialógové okno tlače"</string>
-    <string name="search" msgid="5421724265322228497">"VYHĽADÁVANIE"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Všetky tlačiarne"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Pridať službu"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Vyhľadávacie pole sa zobrazuje"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Vyhľadávacie pole je skryté"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Pridať tlačiareň"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Našla sa <xliff:g id="COUNT">%1$s</xliff:g> tlačiareň"</item>
-    <item quantity="other" msgid="6533817036607128241">"Počet nájdených tlačiarní: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Výber tlačovej služby"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Vyhľadávanie tlačiarní"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Nenašli sa žiadne tlačiarne"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Prebieha tlač úlohy <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Prebieha zrušenie úlohy <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Chyba tlačiarne – úloha <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Tlačiareň zablok. úlohu <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Zrušiť"</string>
-    <string name="restart" msgid="2472034227037808749">"Spustiť znova"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Žiadne pripojenie k tlačiarni"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"neznáme"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – nie je k dispozícii"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Čiernobiele"</item>
-    <item msgid="2762241247228983754">"Farba"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Na výšku"</item>
-    <item msgid="3199660090246166812">"Na šírku"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Všetky"</item>
-    <item msgid="6812869625222503603">"Rozsah"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-sl/strings.xml b/packages/PrintSpooler/res/values-sl/strings.xml
deleted file mode 100644
index 40a69c2..0000000
--- a/packages/PrintSpooler/res/values-sl/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Tisk. v ozadju"</string>
-    <string name="print_button" msgid="645164566271246268">"Natisni"</string>
-    <string name="save_button" msgid="1921310454071758999">"Shrani"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Cilj"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Št. kopij"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Velikost papirja"</string>
-    <string name="label_color" msgid="1108690305218188969">"Barvno"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Postavitev"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Št. strani (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Predogled tiskanja"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Za predogled namestite pregledovalnik za PDF-je"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Aplikacija za tiskanje se je zrušila"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Št. strani:"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Ustvarjanje zahteve za tisk"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Shrani kot PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Vsi tiskalniki …"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Pogovorno okno za tiskanje"</string>
-    <string name="search" msgid="5421724265322228497">"Iskanje"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Vsi tiskalniki"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Dodaj storitev"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Iskalno polje je prikazano"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Iskalno polje je skrito"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Dodajanje tiskalnika"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Najden <xliff:g id="COUNT">%1$s</xliff:g> tiskalnik"</item>
-    <item quantity="other" msgid="6533817036607128241">"Število najdenih tiskalnikov: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Izberite tiskalno storitev"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Iskanje tiskalnikov"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Tiskalnikov ni mogoče najti"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Tiskanje: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Preklic: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Napaka tiskalnika: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Tiskalnik je blokiral <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Tiskalno opravilo: <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Tiskalna opravila: <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Prekliči"</string>
-    <string name="restart" msgid="2472034227037808749">"Začni znova"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Ni povezave s tiskalnikom"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"neznano"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – ni na voljo"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Črno-belo"</item>
-    <item msgid="2762241247228983754">"Barvno"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Navpično"</item>
-    <item msgid="3199660090246166812">"Ležeče"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Vse"</item>
-    <item msgid="6812869625222503603">"Obseg"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-sr/strings.xml b/packages/PrintSpooler/res/values-sr/strings.xml
deleted file mode 100644
index 7cc5ec5..0000000
--- a/packages/PrintSpooler/res/values-sr/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Штамп. из мемор."</string>
-    <string name="print_button" msgid="645164566271246268">"Штампај"</string>
-    <string name="save_button" msgid="1921310454071758999">"Сачувај"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Одредиште"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Копије"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Величина папира"</string>
-    <string name="label_color" msgid="1108690305218188969">"Боја"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Положај"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Странице (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Преглед пре штампања"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Инсталирај PDF приказивач за преглед"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Апликација за штампање је отказала"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Странице"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Генерисање задатка за штампање"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Сачувај као PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Сви штампачи…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Дијалог за штампање"</string>
-    <string name="search" msgid="5421724265322228497">"Претражи"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Сви штампачи"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Додај услугу"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Оквир за претрагу се приказује"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Оквир за претрагу је сакривен"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Додај штампач"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Пронађен је <xliff:g id="COUNT">%1$s</xliff:g> штампач"</item>
-    <item quantity="other" msgid="6533817036607128241">"Пронађено је <xliff:g id="COUNT">%1$s</xliff:g> штампача"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Изаберите услугу штампања"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Претрага штампача"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Није пронађен ниједан штампач"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Штампа се <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Отказује се <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Грешка штампача <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Штампач је блокирао <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Откажи"</string>
-    <string name="restart" msgid="2472034227037808749">"Поново покрени"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Нема везе са штампачем"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"непознато"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – недоступан"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Црно-бело"</item>
-    <item msgid="2762241247228983754">"Боја"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Усправно"</item>
-    <item msgid="3199660090246166812">"Водоравно"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Све"</item>
-    <item msgid="6812869625222503603">"Опсег"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-sv/strings.xml b/packages/PrintSpooler/res/values-sv/strings.xml
deleted file mode 100644
index 8f75bf5..0000000
--- a/packages/PrintSpooler/res/values-sv/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Utskriftskö"</string>
-    <string name="print_button" msgid="645164566271246268">"Skriv ut"</string>
-    <string name="save_button" msgid="1921310454071758999">"Spara"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Destination"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopior"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Pappersstorlek"</string>
-    <string name="label_color" msgid="1108690305218188969">"Färg"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Orientering"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Sidor (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Förhandsgranskning"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Installera PDF-läsare för förhandsgranskning"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Utskriftsappen kraschade"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Sidor"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Genererar utskriftsjobb"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Spara som PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Alla skrivare ..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Dialogrutan Skriv ut"</string>
-    <string name="search" msgid="5421724265322228497">"Sök"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Alla skrivare"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Lägg till tjänst"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Sökrutan visas"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Sökrutan är dold"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Lägg till skrivare"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> skrivare hittades"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> skrivare hittades"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Välj utskriftstjänst"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Söker efter skrivare"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Det gick inte att hitta några skrivare"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Skriver ut <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Avbryter <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Skrivarfel för <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Skrivaren har blockerat <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Utskriftsjobb – <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Utskriftsjobb – <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Avbryt"</string>
-    <string name="restart" msgid="2472034227037808749">"Starta om"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Ingen anslutning till skrivaren"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"okänt"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – inte tillgänglig"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Svartvit"</item>
-    <item msgid="2762241247228983754">"Färg"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Stående"</item>
-    <item msgid="3199660090246166812">"Liggande"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Alla"</item>
-    <item msgid="6812869625222503603">"Intervall"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-sw/strings.xml b/packages/PrintSpooler/res/values-sw/strings.xml
deleted file mode 100644
index 1991832..0000000
--- a/packages/PrintSpooler/res/values-sw/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Programu ya kuandaa Printa kwa ajili ya Kuchapisha"</string>
-    <string name="print_button" msgid="645164566271246268">"Chapisha"</string>
-    <string name="save_button" msgid="1921310454071758999">"Hifadhi"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Itakapofika"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Nakala"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Ukubwa wa Karatasi"</string>
-    <string name="label_color" msgid="1108690305218188969">"Rangi"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Mkao"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Kurasa (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Chungulia kwanza kabla ya kuchapisha"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Sakinisha kitazamaji cha PDF kwa onyesho la kuchungulia"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Programu ya kuchapisha imeacha kufanya kazi"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Kurasa"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Inazanzisha kazi ya kuchapisha"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Hifadhi kama PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Printa zote..."</string>
-    <string name="print_dialog" msgid="32628687461331979">"Chapisha mazungumzo"</string>
-    <string name="search" msgid="5421724265322228497">"Tafuta"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Printa zote"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Ongeza huduma"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Kisanduku cha kutafutia kimeonyeshwa"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Kisanduku cha kutafutia kimefichwa"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Ongeza printa"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Printa <xliff:g id="COUNT">%1$s</xliff:g> imepatikana"</item>
-    <item quantity="other" msgid="6533817036607128241">"Printa <xliff:g id="COUNT">%1$s</xliff:g> zimepatikana"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Chagua huduma ya printa"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Inatafuta printa"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Hakuna printa zilizopatikana"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Inachapisha <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Inaghairi <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Hitilafu ya kuchapisha <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Printa imefungwa <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Ghairi"</string>
-    <string name="restart" msgid="2472034227037808749">"Anzisha upya"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Hakuna muunganisho kwa printa"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"haijulikani"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> - haipatikani"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Nyeusi na Nyeupe"</item>
-    <item msgid="2762241247228983754">"Rangi"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Wima"</item>
-    <item msgid="3199660090246166812">"Mlalo"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Zote"</item>
-    <item msgid="6812869625222503603">"Masafa"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-th/strings.xml b/packages/PrintSpooler/res/values-th/strings.xml
deleted file mode 100644
index 0d247a5..0000000
--- a/packages/PrintSpooler/res/values-th/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"พิมพ์"</string>
-    <string name="save_button" msgid="1921310454071758999">"บันทึก"</string>
-    <string name="label_destination" msgid="9132510997381599275">"ปลายทาง"</string>
-    <string name="label_copies" msgid="3634531042822968308">"สำเนา"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"ขนาดของกระดาษ"</string>
-    <string name="label_color" msgid="1108690305218188969">"สี"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"การวางแนว"</string>
-    <string name="label_pages" msgid="6300874667546617333">"หน้า (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"ตัวอย่างก่อนพิมพ์"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"ติดตั้งโปรแกรมดู PDF เพื่อดูหน้าตัวอย่าง"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"แอปการพิมพ์ขัดข้อง"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"หน้า"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"กำลังสร้างงานพิมพ์"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"บันทึกเป็น PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"เครื่องพิมพ์ทั้งหมด…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"ช่องโต้ตอบการพิมพ์"</string>
-    <string name="search" msgid="5421724265322228497">"ค้นหา"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"เครื่องพิมพ์ทั้งหมด"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"เพิ่มบริการ"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"แสดงช่องค้นหาอยู่"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"ซ่อนช่องค้นหาอยู่"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"เพิ่มเครื่องพิมพ์"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"พบเครื่องพิมพ์ <xliff:g id="COUNT">%1$s</xliff:g> เครื่อง"</item>
-    <item quantity="other" msgid="6533817036607128241">"พบเครื่องพิมพ์ <xliff:g id="COUNT">%1$s</xliff:g> เครื่อง"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"เลือกบริการพิมพ์"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"กำลังค้นหาเครื่องพิมพ์"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"ไม่พบเครื่องพิมพ์"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"กำลังพิมพ์ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"กำลังยกเลิก <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"ข้อผิดพลาดเครื่องพิมพ์ <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"เครื่องพิมพ์ได้บล็อก <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"ยกเลิก"</string>
-    <string name="restart" msgid="2472034227037808749">"เริ่มต้นใหม่"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"ไม่มีการเชื่อมต่อไปยังเครื่องพิมพ์"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"ไม่ทราบ"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> ไม่พร้อมใช้งาน"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"ขาวดำ"</item>
-    <item msgid="2762241247228983754">"สี"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"แนวตั้ง"</item>
-    <item msgid="3199660090246166812">"แนวนอน"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"ทั้งหมด"</item>
-    <item msgid="6812869625222503603">"ช่วง"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-tl/strings.xml b/packages/PrintSpooler/res/values-tl/strings.xml
deleted file mode 100644
index 087cf49..0000000
--- a/packages/PrintSpooler/res/values-tl/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"I-print"</string>
-    <string name="save_button" msgid="1921310454071758999">"I-save"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Patutunguhan"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Mga Kopya"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Laki ng Papel"</string>
-    <string name="label_color" msgid="1108690305218188969">"Kulay"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Oryentasyon"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Mga Pahina (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Preview sa pag-print"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Mag-install ng PDF viewer para sa pag-preview"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Nag-crash ang app sa pag-print"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Mga Pahina"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Gumagawa ng pag-print"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"I-save bilang PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Lahat ng printer…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Dialog ng pag-print"</string>
-    <string name="search" msgid="5421724265322228497">"Hanapin"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Lahat ng printer"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Magdagdag ng serbisyo"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Ipinapakita ang box para sa paghahanap"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Nakatago ang box para sa paghahanap"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Magdagdag ng printer"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> printer ang nakita"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> (na) printer ang nakita"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Pumili ng serbisyo ng pag-print"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Naghahanap ng mga printer"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Walang mga printer na nakita"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Pini-print ang <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Kinakansela ang <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Error sa printer <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Naka-block ang Printer <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Kanselahin"</string>
-    <string name="restart" msgid="2472034227037808749">"I-restart"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Hindi nakakonekta sa printer"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"hindi alam"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – hindi available"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Black &amp; White"</item>
-    <item msgid="2762241247228983754">"Kulay"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Portrait"</item>
-    <item msgid="3199660090246166812">"Landscape"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Lahat"</item>
-    <item msgid="6812869625222503603">"Sakop"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-tr/strings.xml b/packages/PrintSpooler/res/values-tr/strings.xml
deleted file mode 100644
index 8127c4b..0000000
--- a/packages/PrintSpooler/res/values-tr/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Yazdır"</string>
-    <string name="save_button" msgid="1921310454071758999">"Kaydet"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Hedef"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Kopya sayısı"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Kağıt Boyutu"</string>
-    <string name="label_color" msgid="1108690305218188969">"Renkli"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Sayfa yönü"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Sayfa (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Yazdırmayı önizle"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Önizlemek için PDF görüntüleyici yükleyin"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Yazdırma uygulaması kilitlendi"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Sayfa"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Yazdırma işi oluşturuluyor"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"PDF olarak kaydet"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Tüm yazıcılar…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Yazdırma iletişim kutusu"</string>
-    <string name="search" msgid="5421724265322228497">"Ara"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Tüm yazıcılar"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Hizmet ekle"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Arama kutusu gösteriliyor"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Arama kutusu gizli"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Yazıcı ekle"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> yazıcı bulundu"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> yazıcı bulundu"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Yazdırma hizmetini seçin"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Yazıcılar aranıyor"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Yazıcı bulunamadı"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> yazdırılıyor"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> iptal ediliyor"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Yazıcı hatası: <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Yazıcı <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> işini engelledi"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"İptal"</string>
-    <string name="restart" msgid="2472034227037808749">"Yeniden başlat"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Yazıcı bağlantısı yok"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"bilinmiyor"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – kullanılamıyor"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Siyah Beyaz"</item>
-    <item msgid="2762241247228983754">"Renkli"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Dikey"</item>
-    <item msgid="3199660090246166812">"Yatay"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Tümü"</item>
-    <item msgid="6812869625222503603">"Aralık"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-uk/strings.xml b/packages/PrintSpooler/res/values-uk/strings.xml
deleted file mode 100644
index cd28f3c..0000000
--- a/packages/PrintSpooler/res/values-uk/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"Друк"</string>
-    <string name="save_button" msgid="1921310454071758999">"Зберегти"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Місце признач-ня"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Копії"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Розмір паперу"</string>
-    <string name="label_color" msgid="1108690305218188969">"Колір"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Орієнтація"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Сторінки (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Версія для друку"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Установити засіб перегляду PDF"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Програма друку аварійно завершила роботу"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Сторінки"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Створюється завдання друку"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Зберегти як PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Усі принтери…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Діалогове вікно друку"</string>
-    <string name="search" msgid="5421724265322228497">"Пошук"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Усі принтери"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Додати службу"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Вікно пошуку показано"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Вікно пошуку сховано"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Додати принтер"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Знайдено принтерів: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-    <item quantity="other" msgid="6533817036607128241">"Знайдено принтерів: <xliff:g id="COUNT">%1$s</xliff:g>"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Вибрати службу друку"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Пошук принтерів"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Принтери не знайдено"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Завдання \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" друкується"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Завдання \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" скасовується"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Помилка завдання \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\""</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Завдання \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" заблоковано"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"Завдання друку <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-    <item quantity="other" msgid="8746611264734222865">"Завдання друку <xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g>"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Скасувати"</string>
-    <string name="restart" msgid="2472034227037808749">"Перезапустити"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Немає з’єднання з принтером"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"невідомо"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"Завдання \"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>\" не доступне"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Чорно-білий"</item>
-    <item msgid="2762241247228983754">"Колір"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Книжкова"</item>
-    <item msgid="3199660090246166812">"Альбомна"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Усі"</item>
-    <item msgid="6812869625222503603">"Діапазон"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-vi/strings.xml b/packages/PrintSpooler/res/values-vi/strings.xml
deleted file mode 100644
index 3c44e7d..0000000
--- a/packages/PrintSpooler/res/values-vi/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Print Spooler"</string>
-    <string name="print_button" msgid="645164566271246268">"In"</string>
-    <string name="save_button" msgid="1921310454071758999">"Lưu"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Đích"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Bản sao"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Kích thước trang"</string>
-    <string name="label_color" msgid="1108690305218188969">"Màu"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Hướng"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Trang (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Xem trước bản in"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Cài đặt trình xem PDF để xem trước"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Ứng dụng in gặp lỗi"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Trang"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Đang tạo lệnh in"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Lưu dưới dạng PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Tất cả máy in…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Hộp thoại in"</string>
-    <string name="search" msgid="5421724265322228497">"Tìm kiếm"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Tất cả máy in"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Thêm dịch vụ"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Hiển thị hộp tìm kiếm"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Ẩn hộp tìm kiếm"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Thêm máy in"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"Đã tìm thấy <xliff:g id="COUNT">%1$s</xliff:g> máy in"</item>
-    <item quantity="other" msgid="6533817036607128241">"Đã tìm thấy <xliff:g id="COUNT">%1$s</xliff:g> máy in"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Chọn dịch vụ in"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Đang tìm kiếm máy in"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Không tìm thấy máy in"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"In <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Hủy <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Lỗi máy in <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Máy in đã chặn <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"Hủy"</string>
-    <string name="restart" msgid="2472034227037808749">"Bắt đầu lại"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Không có kết nối nào với máy in"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"không xác định"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – không khả dụng"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Đen trắng"</item>
-    <item msgid="2762241247228983754">"Màu"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Dọc"</item>
-    <item msgid="3199660090246166812">"Ngang"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Tất cả"</item>
-    <item msgid="6812869625222503603">"Dãy"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-zh-rCN/strings.xml b/packages/PrintSpooler/res/values-zh-rCN/strings.xml
deleted file mode 100644
index a968d26..0000000
--- a/packages/PrintSpooler/res/values-zh-rCN/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"打印处理服务"</string>
-    <string name="print_button" msgid="645164566271246268">"打印"</string>
-    <string name="save_button" msgid="1921310454071758999">"保存"</string>
-    <string name="label_destination" msgid="9132510997381599275">"目的地"</string>
-    <string name="label_copies" msgid="3634531042822968308">"份数"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"纸张尺寸"</string>
-    <string name="label_color" msgid="1108690305218188969">"颜色"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"方向"</string>
-    <string name="label_pages" msgid="6300874667546617333">"页数 (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"打印预览"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"安装 PDF 查看器以便预览"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"打印应用崩溃了"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"页数"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"正在生成打印作业"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"保存为 PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"所有打印机…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"打印对话框"</string>
-    <string name="search" msgid="5421724265322228497">"搜索"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"所有打印机"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"添加服务"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"搜索框已显示"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"搜索框已隐藏"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"添加打印机"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"找到<xliff:g id="COUNT">%1$s</xliff:g>台打印机"</item>
-    <item quantity="other" msgid="6533817036607128241">"找到<xliff:g id="COUNT">%1$s</xliff:g>台打印机"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"选择打印服务"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"正在搜索打印机"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"找不到打印机"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"正在打印“<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>”"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"正在取消打印“<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>”"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"打印机在打印“<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>”时出错"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"打印机拒绝打印“<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>”"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"取消"</string>
-    <string name="restart" msgid="2472034227037808749">"重新开始"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"未与打印机建立连接"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"未知"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> - 无法使用"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"黑白"</item>
-    <item msgid="2762241247228983754">"彩色"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"纵向"</item>
-    <item msgid="3199660090246166812">"横向"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"全部"</item>
-    <item msgid="6812869625222503603">"范围"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-zh-rHK/strings.xml b/packages/PrintSpooler/res/values-zh-rHK/strings.xml
deleted file mode 100644
index c089a22..0000000
--- a/packages/PrintSpooler/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"列印多工緩衝處理器"</string>
-    <string name="print_button" msgid="645164566271246268">"列印"</string>
-    <string name="save_button" msgid="1921310454071758999">"儲存"</string>
-    <string name="label_destination" msgid="9132510997381599275">"目的地"</string>
-    <string name="label_copies" msgid="3634531042822968308">"份數"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"紙張大小"</string>
-    <string name="label_color" msgid="1108690305218188969">"顏色"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"方向"</string>
-    <string name="label_pages" msgid="6300874667546617333">"頁數 (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"預覽列印"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"安裝預覽所需的 PDF 檢視器"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"列印應用程式當機了"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"頁數"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"正在產生列印工作"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"儲存為 PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"所有打印機…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"列印對話方塊"</string>
-    <string name="search" msgid="5421724265322228497">"搜尋"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"所有打印機"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"新增服務"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"搜尋框已顯示"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"搜尋框已隱藏"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"新增打印機"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"找到 <xliff:g id="COUNT">%1$s</xliff:g> 部打印機"</item>
-    <item quantity="other" msgid="6533817036607128241">"找到 <xliff:g id="COUNT">%1$s</xliff:g> 部打印機"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"選擇列印服務"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"正在搜尋打印機"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"找不到打印機"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"正在列印 <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"正在取消 <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"打印機錯誤:<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"打印機已封鎖 <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"取消"</string>
-    <string name="restart" msgid="2472034227037808749">"重新開始"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"尚未與打印機連線"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"不明"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – 無法使用"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"黑白"</item>
-    <item msgid="2762241247228983754">"彩色"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"直向"</item>
-    <item msgid="3199660090246166812">"橫向"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"全部"</item>
-    <item msgid="6812869625222503603">"範圍"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-zh-rTW/strings.xml b/packages/PrintSpooler/res/values-zh-rTW/strings.xml
deleted file mode 100644
index 1d84ac5..0000000
--- a/packages/PrintSpooler/res/values-zh-rTW/strings.xml
+++ /dev/null
@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"列印多工緩衝處理器"</string>
-    <string name="print_button" msgid="645164566271246268">"列印"</string>
-    <string name="save_button" msgid="1921310454071758999">"儲存"</string>
-    <string name="label_destination" msgid="9132510997381599275">"目的地"</string>
-    <string name="label_copies" msgid="3634531042822968308">"份數"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"紙張大小"</string>
-    <string name="label_color" msgid="1108690305218188969">"色彩"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"方向"</string>
-    <string name="label_pages" msgid="6300874667546617333">"頁數 (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"列印預覽"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"安裝預覽所需的 PDF 檢視器"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"列印應用程式當機了"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"頁數"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"正在產生列印工作"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"儲存為 PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"所有印表機…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"列印對話方塊"</string>
-    <string name="search" msgid="5421724265322228497">"搜尋"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"所有印表機"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"新增服務"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"搜尋框已顯示"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"搜尋框已隱藏"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"新增印表機"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"找到 <xliff:g id="COUNT">%1$s</xliff:g> 台印表機"</item>
-    <item quantity="other" msgid="6533817036607128241">"找到 <xliff:g id="COUNT">%1$s</xliff:g> 台印表機"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"選擇列印服務"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"正在搜尋印表機"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"找不到印表機"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"正在列印 <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"正在取消 <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"印表機發生錯誤:<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"印表機封鎖了 <xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <!-- no translation found for composite_notification_title_template:one (5866624638054847057) -->
-    <!-- no translation found for composite_notification_title_template:other (8746611264734222865) -->
-    <string name="cancel" msgid="4373674107267141885">"取消"</string>
-    <string name="restart" msgid="2472034227037808749">"重新開始"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"尚未與印表機建立連線"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"不明"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – 無法使用"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"黑白"</item>
-    <item msgid="2762241247228983754">"彩色"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"縱向"</item>
-    <item msgid="3199660090246166812">"橫向"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"全部"</item>
-    <item msgid="6812869625222503603">"範圍"</item>
-  </string-array>
-</resources>
diff --git a/packages/PrintSpooler/res/values-zu/strings.xml b/packages/PrintSpooler/res/values-zu/strings.xml
deleted file mode 100644
index 1bf72a6..0000000
--- a/packages/PrintSpooler/res/values-zu/strings.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4469836075319831821">"Ispuli sephrinta"</string>
-    <string name="print_button" msgid="645164566271246268">"Phrinta"</string>
-    <string name="save_button" msgid="1921310454071758999">"Londoloza"</string>
-    <string name="label_destination" msgid="9132510997381599275">"Indawo"</string>
-    <string name="label_copies" msgid="3634531042822968308">"Amakhophi"</string>
-    <string name="label_paper_size" msgid="8681895607876809323">"Usayizi wephepha"</string>
-    <string name="label_color" msgid="1108690305218188969">"Umbala"</string>
-    <string name="label_orientation" msgid="2853142581990496477">"Umumo"</string>
-    <string name="label_pages" msgid="6300874667546617333">"Amakhasi (<xliff:g id="PAGE_COUNT">%1$s</xliff:g>)"</string>
-    <!-- no translation found for pages_range_example (8558694453556945172) -->
-    <skip />
-    <string name="print_preview" msgid="8010217796057763343">"Ukubuka kuqala kokuphrinta"</string>
-    <string name="install_for_print_preview" msgid="6366303997385509332">"Faka isibukeli se-PDF ukuze uhlole kuqala"</string>
-    <string name="printing_app_crashed" msgid="854477616686566398">"Ukuphrinta uhlelo lokusebenza kukhubazekile"</string>
-    <string name="page_count_unknown" msgid="6058852665954511124">"Amakhasi"</string>
-    <string name="generating_print_job" msgid="3119608742651698916">"Ikhiqiza umsebenzi wokuphrinta"</string>
-    <string name="save_as_pdf" msgid="5718454119847596853">"Londoloza njenge-PDF"</string>
-    <string name="all_printers" msgid="5018829726861876202">"Wonke amaphrinta…"</string>
-    <string name="print_dialog" msgid="32628687461331979">"Ingxoxo yokuphrinta"</string>
-    <string name="search" msgid="5421724265322228497">"Sesha"</string>
-    <string name="all_printers_label" msgid="3178848870161526399">"Wonke amaphrinta"</string>
-    <string name="add_print_service_label" msgid="5356702546188981940">"Engeza isevisi"</string>
-    <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"Ibhokisi lokuhlola libonisiwe"</string>
-    <string name="print_search_box_hidden_utterance" msgid="5727755169343113351">"Ibhokisi lokusesha lifihliwe"</string>
-    <string name="print_add_printer" msgid="1088656468360653455">"Engeza iphrinta"</string>
-  <plurals name="print_search_result_count_utterance">
-    <item quantity="one" msgid="4484953260685964252">"<xliff:g id="COUNT">%1$s</xliff:g> iphrinta itholiwe"</item>
-    <item quantity="other" msgid="6533817036607128241">"<xliff:g id="COUNT">%1$s</xliff:g> amaphrinta atholiwe"</item>
-  </plurals>
-    <string name="choose_print_service" msgid="3740309762324459694">"Khetha isevisi yephrinta"</string>
-    <string name="print_searching_for_printers" msgid="6550424555079932867">"Isesha amaphrinta"</string>
-    <string name="print_no_printers" msgid="4869403323900054866">"Awekho amaphrinta atholiwe"</string>
-    <string name="printing_notification_title_template" msgid="295903957762447362">"Iphrinta i-<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="cancelling_notification_title_template" msgid="1821759594704703197">"Ikhansela i-<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="failed_notification_title_template" msgid="2256217208186530973">"Iphutha lephrinta ye-<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g>"</string>
-    <string name="blocked_notification_title_template" msgid="1175435827331588646">"Iphrinta engu-<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> ivinjelwe"</string>
-  <plurals name="composite_notification_title_template">
-    <item quantity="one" msgid="5866624638054847057">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> umsebenzi wokuphrinta"</item>
-    <item quantity="other" msgid="8746611264734222865">"<xliff:g id="PRINT_JOB_NAME">%1$d</xliff:g> imisebenzi yokuphrinta"</item>
-  </plurals>
-    <string name="cancel" msgid="4373674107267141885">"Khansela"</string>
-    <string name="restart" msgid="2472034227037808749">"Qala kabusha"</string>
-    <string name="no_connection_to_printer" msgid="2159246915977282728">"Akukho ukuxhumana kuphrinta"</string>
-    <string name="reason_unknown" msgid="5507940196503246139">"akwaziwa"</string>
-    <string name="printer_unavailable" msgid="2434170617003315690">"I-<xliff:g id="PRINT_JOB_NAME">%1$s</xliff:g> – ayitholakali"</string>
-    <!-- no translation found for print_error_default_message (8568506918983980567) -->
-    <skip />
-  <string-array name="color_mode_labels">
-    <item msgid="7602948745415174937">"Okumnyama nokumhlophe"</item>
-    <item msgid="2762241247228983754">"Umbala"</item>
-  </string-array>
-  <string-array name="orientation_labels">
-    <item msgid="4061931020926489228">"Ukuma ngobude"</item>
-    <item msgid="3199660090246166812">"Ukwakheka kwezwe"</item>
-  </string-array>
-  <string-array name="page_options_labels">
-    <item msgid="7421377442011699994">"Konke"</item>
-    <item msgid="6812869625222503603">"Ibanga"</item>
-  </string-array>
-</resources>
diff --git a/packages/SettingsProvider/res/values-en-rIN/strings.xml b/packages/SettingsProvider/res/values-en-rIN/strings.xml
deleted file mode 100644
index c19fdd7..0000000
--- a/packages/SettingsProvider/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"Settings Storage"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-et-rEE/strings.xml b/packages/SettingsProvider/res/values-et-rEE/strings.xml
deleted file mode 100644
index 30b7293..0000000
--- a/packages/SettingsProvider/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"Seadete talletusruum"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-fr-rCA/strings.xml b/packages/SettingsProvider/res/values-fr-rCA/strings.xml
deleted file mode 100644
index c90eb09..0000000
--- a/packages/SettingsProvider/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"Stockage des paramètres"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-hy-rAM/strings.xml b/packages/SettingsProvider/res/values-hy-rAM/strings.xml
deleted file mode 100644
index b1f1afb..0000000
--- a/packages/SettingsProvider/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"Կարգավորումների պահուստ"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-ka-rGE/strings.xml b/packages/SettingsProvider/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 691a2e9..0000000
--- a/packages/SettingsProvider/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"პარამეტრების საცავი"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-km-rKH/strings.xml b/packages/SettingsProvider/res/values-km-rKH/strings.xml
deleted file mode 100644
index 7be6242..0000000
--- a/packages/SettingsProvider/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"កំណត់​ការ​ផ្ទុក"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-lo-rLA/strings.xml b/packages/SettingsProvider/res/values-lo-rLA/strings.xml
deleted file mode 100644
index 4e57936..0000000
--- a/packages/SettingsProvider/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"ບ່ອນເກັບຂໍ້ມູນການຕັ້ງຄ່າ"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-mn-rMN/strings.xml b/packages/SettingsProvider/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 9452145..0000000
--- a/packages/SettingsProvider/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"Тохиргооны Сан"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-ms-rMY/strings.xml b/packages/SettingsProvider/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 9108b07..0000000
--- a/packages/SettingsProvider/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"Storan Tetapan"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values-zh-rHK/strings.xml b/packages/SettingsProvider/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 977c9b9..0000000
--- a/packages/SettingsProvider/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2007, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="4567566098528588863">"設定儲存空間"</string>
-</resources>
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index a1d8f22..da3ca0f 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -173,4 +173,8 @@
          0 means no timeout; battery sounds will always play
          >0 is milliseconds of screen-off time after which battery sounds will not play -->
     <integer name="def_low_battery_sound_timeout">0</integer>
+
+    <!-- Default for Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE -->
+    <integer name="def_wifi_scan_always_available">0</integer>
+
 </resources>
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index 09c21f3..ed86f42 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2274,6 +2274,9 @@
             loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
                     R.integer.def_low_battery_sound_timeout);
 
+            loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
+                    R.integer.def_wifi_scan_always_available);
+
             // --- New global settings start here
         } finally {
             if (stmt != null) stmt.close();
diff --git a/packages/Shell/res/values-cs/strings.xml b/packages/Shell/res/values-cs/strings.xml
index 3f1c921..effdcb9 100644
--- a/packages/Shell/res/values-cs/strings.xml
+++ b/packages/Shell/res/values-cs/strings.xml
@@ -17,8 +17,8 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="app_label" msgid="3701846017049540910">"Prostředí"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Bylo vytvořeno chybové hlášení"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Chybové hlášení můžete sdílet klepnutím."</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Chybová hlášení obsahují data z různých souborů protokolů systému včetně osobních a soukromých informací. Chybová hlášení sdílejte pouze s aplikacemi a uživateli, kterým důvěřujete."</string>
+    <string name="bugreport_finished_title" msgid="2293711546892863898">"Byla vytvořena zpráva o chybě"</string>
+    <string name="bugreport_finished_text" msgid="3559904746859400732">"Zprávu o chybě můžete sdílet klepnutím."</string>
+    <string name="bugreport_confirm" msgid="5130698467795669780">"Zprávy o chybách obsahují data z různých souborů protokolů systému včetně osobních a soukromých informací. Zprávy o chybách sdílejte pouze s aplikacemi a uživateli, kterým důvěřujete."</string>
     <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Zobrazit tuto zprávu příště"</string>
 </resources>
diff --git a/packages/Shell/res/values-da/strings.xml b/packages/Shell/res/values-da/strings.xml
index a8a3605..01ea42b 100644
--- a/packages/Shell/res/values-da/strings.xml
+++ b/packages/Shell/res/values-da/strings.xml
@@ -19,6 +19,6 @@
     <string name="app_label" msgid="3701846017049540910">"Shell"</string>
     <string name="bugreport_finished_title" msgid="2293711546892863898">"Fejlrapporten er registreret"</string>
     <string name="bugreport_finished_text" msgid="3559904746859400732">"Tryk for at dele din fejlrapport"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Fejlrapporter indeholder data fra systemets forskellige logfiler, f.eks. personlige og private oplysninger. Del kun fejlrapporter med apps og personer, du har tillid til."</string>
+    <string name="bugreport_confirm" msgid="5130698467795669780">"Fejlrapporter indeholder data fra systemets forskellige logfiler, herunder personlige og private oplysninger. Del kun fejlrapporter med apps og personer, du har tillid til."</string>
     <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Vis denne meddelelse næste gang"</string>
 </resources>
diff --git a/packages/Shell/res/values-en-rIN/strings.xml b/packages/Shell/res/values-en-rIN/strings.xml
deleted file mode 100644
index 68708e0..0000000
--- a/packages/Shell/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Shell"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Bug report captured"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Touch to share your bug report"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Bug reports contain data from the system\'s various log files, including personal and private information. Only share bug reports with apps and people that you trust."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Show this message next time"</string>
-</resources>
diff --git a/packages/Shell/res/values-et-rEE/strings.xml b/packages/Shell/res/values-et-rEE/strings.xml
deleted file mode 100644
index 7788158..0000000
--- a/packages/Shell/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Kest"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Veaaruanne jäädvustati"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Veaaruande jagamiseks puudutage"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Veaaruanded sisaldavad andmeid erinevatest süsteemi logifailidest, sh isiklikku ja privaatset teavet. Jagage veaaruandeid ainult usaldusväärsete rakenduste ja inimestega."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Kuva see sõnum järgmisel korral"</string>
-</resources>
diff --git a/packages/Shell/res/values-fr-rCA/strings.xml b/packages/Shell/res/values-fr-rCA/strings.xml
deleted file mode 100644
index c672f23..0000000
--- a/packages/Shell/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Shell"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Rapport de bogue enregistré"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Appuyer ici pour partager votre rapport de bogue"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Les rapports de bogue contiennent des données des fichiers journaux du système, y compris des informations personnelles et privées. Ne partagez les rapports de bogue qu\'avec les applications et les personnes que vous estimez fiables."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Afficher ce message la prochaine fois"</string>
-</resources>
diff --git a/packages/Shell/res/values-hi/strings.xml b/packages/Shell/res/values-hi/strings.xml
index 7e73c79..4ea0664 100644
--- a/packages/Shell/res/values-hi/strings.xml
+++ b/packages/Shell/res/values-hi/strings.xml
@@ -19,6 +19,6 @@
     <string name="app_label" msgid="3701846017049540910">"शेल"</string>
     <string name="bugreport_finished_title" msgid="2293711546892863898">"बग रिपोर्ट कैप्चर कर ली गई"</string>
     <string name="bugreport_finished_text" msgid="3559904746859400732">"अपनी बग रिपोर्ट साझा करने के लिए स्पर्श करें"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"बग रिपोर्ट में व्यक्तिगत और निजी जानकारी सहित, सिस्टम की विभिन्न लॉग फ़ाइलों का डेटा होता है. बग रिपोर्ट केवल विश्वसनीय एप्स और व्यक्तियों से ही साझा करें."</string>
+    <string name="bugreport_confirm" msgid="5130698467795669780">"बग रिपोर्ट में व्यक्तिगत और निजी जानकारी सहित, सिस्टम की विभिन्न लॉग फ़ाइलों का डेटा होता है. बग रिपोर्ट केवल विश्वसनीय एप्लिकेशन और व्यक्तियों से ही साझा करें."</string>
     <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"यह संदेश अगली बार दिखाएं"</string>
 </resources>
diff --git a/packages/Shell/res/values-hy-rAM/strings.xml b/packages/Shell/res/values-hy-rAM/strings.xml
deleted file mode 100644
index ea7fa9f..0000000
--- a/packages/Shell/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Խեցի"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Վրիպակի զեկույց ստացվեց"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Հպեք` ձեր վրիպակի մասին զեկույցը տարածելու համար"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Վրիպակի զեկույցները պարունակում են տվյալներ համակարգի տարբեր մուտքի ֆայլերից, այդ թվում նաև անհատական ​​և գաղտնի տեղեկություններ: Վրիպակի զեկույցները կիսեք միայն այն հավելվածների և մարդկանց հետ, որոնց վստահում եք:"</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Այս հաղորդագրությունը ցույց տալ հաջորդ անգամ"</string>
-</resources>
diff --git a/packages/Shell/res/values-iw/strings.xml b/packages/Shell/res/values-iw/strings.xml
index ded860c..e7715e9 100644
--- a/packages/Shell/res/values-iw/strings.xml
+++ b/packages/Shell/res/values-iw/strings.xml
@@ -19,6 +19,6 @@
     <string name="app_label" msgid="3701846017049540910">"מעטפת"</string>
     <string name="bugreport_finished_title" msgid="2293711546892863898">"דוח הבאגים צולם"</string>
     <string name="bugreport_finished_text" msgid="3559904746859400732">"גע כדי לשתף את דוח הבאגים שלך"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"דוחות על באגים כוללים נתונים מקובצי היומן השונים במערכת, כולל מידע אישי ופרטי. שתף דוחות באגים רק עם אפליקציות ואנשים שאתה סומך עליהם."</string>
+    <string name="bugreport_confirm" msgid="5130698467795669780">"דוחות על באגים כוללים נתונים מקובצי היומן השונים במערכת, כולל מידע אישי ופרטי. שתף דוחות באגים רק עם יישומים ואנשים שאתה סומך עליהם."</string>
     <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"הצג את ההודעה הזו בפעם הבאה"</string>
 </resources>
diff --git a/packages/Shell/res/values-ka-rGE/strings.xml b/packages/Shell/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 7d9c72a..0000000
--- a/packages/Shell/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"გარეკანი"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"ანგარიში ხარვეზების შესახებ შექმნილია"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"შეეხეთ თქვენი ხარვეზების ანგარიშის გასაზიარებლად"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"ხარვეზის ანგარიშები მოიცავს მონაცემებს სხვადასხვა სისტემური ჟურნალის ფაილებიდან, მათ შორის პირად და კონფიდენციალურ ინფორმაციას."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"შემდგომში აჩვენე ეს შეტყობინება"</string>
-</resources>
diff --git a/packages/Shell/res/values-km-rKH/strings.xml b/packages/Shell/res/values-km-rKH/strings.xml
deleted file mode 100644
index efb345c..0000000
--- a/packages/Shell/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"សែល"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"បាន​ចាប់​យក​របាយការណ៍​កំហុស"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"ប៉ះ​ ដើម្បី​ចែក​រំលែក​របាយការណ៍​កំហុស​របស់​អ្នក"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"របាយការណ៍​កំហុស​រួមមាន​ឯកសារ​កំណត់​ហេតុ​ផ្សេងៗ​របស់​ប្រព័ន្ធ រួមមាន​ព័ត៌មាន​ផ្ទាល់ខ្លួន និង​ឯកជន។ ចែករំលែក​របាយការណ៍​កំហុស​ជា​មួយ​កម្មវិធី និង​មនុស្ស​ដែល​អ្នក​ទុក​ចិត្ត។"</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"បង្ហាញ​សារ​នេះ​ពេល​ក្រោយ"</string>
-</resources>
diff --git a/packages/Shell/res/values-lo-rLA/strings.xml b/packages/Shell/res/values-lo-rLA/strings.xml
deleted file mode 100644
index a237d48..0000000
--- a/packages/Shell/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Shell"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"ລາຍງານຈຸດບົກພ່ອງຖືກເກັບກຳແລ້ວ"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"ແຕະເພື່ອສົ່ງການລາຍງານປັນຫາຂອງທ່ານ"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"ການລາຍງານຂໍ້ຜິດພາດປະກອບມີ ຂໍ້ມູນຈາກໄຟລ໌ບັນທຶກຂອງລະບົບຫຼາຍໄຟລ໌, ຮວມທັງຂໍ້ມູນສ່ວນໂຕນຳ. ທ່ານຕ້ອງແບ່ງປັນລາຍງານຂໍ້ຜິດພາດໃຫ້ແອັບຯ ແລະຄົນທີ່ທ່ານເຊື່ອຖືໄດ້ເທົ່ານັ້ນ."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"ສະແດງຂໍ້ຄວາມນີ້ອີກໃນເທື່ອຕໍ່ໄປ"</string>
-</resources>
diff --git a/packages/Shell/res/values-mn-rMN/strings.xml b/packages/Shell/res/values-mn-rMN/strings.xml
deleted file mode 100644
index f74298d..0000000
--- a/packages/Shell/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Шел"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Алдааны мэдээлэл хүлээн авав"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Та алдааны мэдэгдлийг хуваалцах бол хүрнэ үү"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Алдааны репорт нь хувийн болон нууц мэдээлэл зэргийг агуулсан системийн төрөл бүрийн лог файлын датаг агуулна. Алдааны репортыг зөвхөн итгэлтэй апп болон хүмүүст хуваалцана уу."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Энэ мессежийг дараагийн удаа харуулах"</string>
-</resources>
diff --git a/packages/Shell/res/values-ms-rMY/strings.xml b/packages/Shell/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 8d1e4a2..0000000
--- a/packages/Shell/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"Shell"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"Laporan pepijat telah ditangkap"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"Sentuh untuk berkongsi laporan pepijat anda"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"Laporan pepijat mengandungi data dari pelbagai fail log sistem, termasuk maklumat peribadi dan sulit. Kongsikan laporan pepijat hanya dengan apl dan orang yang anda percayai."</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"Tunjukkan mesej ini pada masa akan datang"</string>
-</resources>
diff --git a/packages/Shell/res/values-zh-rHK/strings.xml b/packages/Shell/res/values-zh-rHK/strings.xml
deleted file mode 100644
index b5f1935..0000000
--- a/packages/Shell/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--  Copyright (C) 2013 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="3701846017049540910">"命令介面"</string>
-    <string name="bugreport_finished_title" msgid="2293711546892863898">"已擷取錯誤報告"</string>
-    <string name="bugreport_finished_text" msgid="3559904746859400732">"輕觸即可分享您的錯誤報告"</string>
-    <string name="bugreport_confirm" msgid="5130698467795669780">"錯誤報告中有來自系統各個記錄檔案的資料,包括個人和私人資料。請只與您信任的應用程式和用戶分享錯誤報告。"</string>
-    <string name="bugreport_confirm_repeat" msgid="4926842460688645058">"下次再顯示這則訊息"</string>
-</resources>
diff --git a/packages/SystemUI/proguard.flags b/packages/SystemUI/proguard.flags
index ab45d99..1ff93d2 100644
--- a/packages/SystemUI/proguard.flags
+++ b/packages/SystemUI/proguard.flags
@@ -7,4 +7,5 @@
   public void setGlowScale(float);
 }
 
+-keep class com.android.systemui.statusbar.phone.PhoneStatusBar
 -keep class com.android.systemui.statusbar.tv.TvStatusBar
diff --git a/packages/SystemUI/res/values-af/strings.xml b/packages/SystemUI/res/values-af/strings.xml
index 3374d37..9ddf42a 100644
--- a/packages/SystemUI/res/values-af/strings.xml
+++ b/packages/SystemUI/res/values-af/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Laat altyd toe van hierdie rekenaar af"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoem om skerm te vul"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Strek om skerm te vul"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Versoenbaarheidszoem"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"As \'n program vir \'n kleiner skerm ontwerp is, sal \'n zoemkontrole naby die horlosie verskyn"</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Stoor tans skermkiekie..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Stoor tans skermkiekie..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Skermkiekie word tans gestoor."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Tuis"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Kieslys"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Onlangse programme"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Deursoek"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Knoppie vir wissel van invoermetode."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Versoenbaarheid-zoem se knoppie."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoem kleiner na groter skerm."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi gekoppel"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Soek vir GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Ligging deur GPS gestel"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Liggingversoeke aktief"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Verwyder alle kennisgewings."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Programinligting"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Die skerm sal outomaties draai."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Skerm is in landskapsoriëntasie gesluit."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Skerm is in portretoriëntasie gesluit."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Nageregkas"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Sluimer"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Vliegtuigmodus"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Outoroteer"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotasie gesluit"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Invoermetode"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Ligging"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Ligging af"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Mediatoestel"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Net noodoproepe"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Draadlose aansig"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Helderheid"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"OUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Netwerk word\ndalk gemonitor"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Kennisgewings verskyn hier"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Verkry enige tyd toegang tot hulle deur af te sleep.\nSleep weer af vir stelselkontroles."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Sleep rand van skerm om balk te wys"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Sleep van rand van skerm af om stelselbalk te wys"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-am/strings.xml b/packages/SystemUI/res/values-am/strings.xml
index 164ec7d..1d81ea7 100644
--- a/packages/SystemUI/res/values-am/strings.xml
+++ b/packages/SystemUI/res/values-am/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"ሁልጊዜ ከዚህ ኮምፒውተር ፍቀድ"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"ማያ እንዲሞላ አጉላ"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"ማያ ለመሙለት ሳብ"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"የተኳኋኝነት አጉላ"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"ትግበራ ለትንሽ ማያ ሲነደፍ፣ የአጉላ መቆመጣጠሪያ በሰዓት በኩል ብቅ ይላል።"</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"ቅጽበታዊ ገጽ እይታ በማስቀመጥ ላይ..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"ቅጽበታዊ ገጽ እይታ በማስቀመጥ ላይ..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"ቅጽበታዊ ገጽ እይታ እየተቀመጠ ነው::"</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"መነሻ"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"ምናሌ"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"የቅርብ ጊዜ  መተግበሪያዎች"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"ፈልግ"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"ካሜራ"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"የግቤት ስልት አዝራር ቀይር"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"የተኳኋኝአጉላ አዝራር።"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"አነስተኛውን ማያ ወደ ትልቅ አጉላ።"</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi ተያይዟል"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"ለGPS በመፈለግ ላይ"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"በ GPS የተዘጋጀ ሥፍራ"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"የአካባቢ ጥያቄዎች ነቅተዋል"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"ሁሉንም ማሳወቂያዎች አጽዳ"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"የመተግበሪያ መረጃ"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"ማያ ገጽ በራስ ሰር ይዞራል።"</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"ማያ ገጽ በወርድ ገፅ አቀማመጥ ተቆልፏል።"</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"ማያ ገጽ በቁም ገፅ አቀማመጥ ተቆልፏል።"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"የማወራረጃ ምግቦች መያዣ"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"የቀን ህልም"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"ኤተርኔት"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"የአውሮፕላን ሁነታ"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"ገመድ አልባ ማሳያ"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"ብሩህነት"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ራስ-ሰር"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"አውታረ መረብ\nክትትል ሊደረግበት ይችላል"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"ማሳወቂያዎች እዚህ ላይ ይታያሉ"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"ወደ ታች በማንሸራተት በማንኛውም ጊዜ ይድረሱባቸው።\nSwipe የስርዓት መቆጣጠሪያዎችን ለማምጣት እንደገና ወደ ታች ያንሸራትቱ።"</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"አሞሌውን ለማሳየት የማያ ገጹን ጠርዝ ላይ ያንሸራትቱ"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"አሞሌውን ለማሳየት ከማያ ገጹ ጠርዝ ጀምረው ያንሸራትቱ"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ar/strings.xml b/packages/SystemUI/res/values-ar/strings.xml
index 2ab8cbe..c31d6d9 100644
--- a/packages/SystemUI/res/values-ar/strings.xml
+++ b/packages/SystemUI/res/values-ar/strings.xml
@@ -29,9 +29,9 @@
     <item quantity="one" msgid="5854176083865845541">"تطبيق حديث واحد"</item>
     <item quantity="other" msgid="1040784359794890744">"%d من التطبيقات الحديثة"</item>
   </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"ليس هناك أي اشعارات"</string>
+    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"ليس هناك أي تنبيهات"</string>
     <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"مستمر"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"الإشعارات"</string>
+    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"التنبيهات"</string>
     <string name="battery_low_title" msgid="2783104807551211639">"توصيل الشاحن"</string>
     <string name="battery_low_subtitle" msgid="1752040062087829196">"انخفضت طاقة البطارية."</string>
     <string name="battery_low_percent_format" msgid="1077244949318261761">"المتبقي: <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
@@ -43,7 +43,7 @@
     <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"التدوير التلقائي للشاشة"</string>
     <string name="status_bar_settings_mute_label" msgid="554682549917429396">"كتم"</string>
     <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"تلقائي"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"الإشعارات"</string>
+    <string name="status_bar_settings_notifications" msgid="397146176280905137">"التنبيهات"</string>
     <string name="bluetooth_tethered" msgid="7094101612161133267">"تم إنشاء الاتصال بالإنترنت عن طريق البلوتوث."</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"إعداد أسلوب الإدخال"</string>
     <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"لوحة مفاتيح فعلية"</string>
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"السماح دائمًا من هذا الكمبيوتر"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"تكبير/تصغير لملء الشاشة"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"توسيع بملء الشاشة"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"تكبير/تصغير التوافق"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"عند تصميم تطبيق لشاشة أصغر، سيظهر عنصر تحكم في التكبير/التصغير بجوار الساعة."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"جارٍ حفظ لقطة الشاشة..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"جارٍ حفظ لقطة الشاشة..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"يتم حفظ لقطة."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"الرئيسية"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"القائمة"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"التطبيقات الحديثة"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"بحث"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"الكاميرا"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"زر تبديل طريقة الإدخال."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"زر تكبير/تصغير للتوافق."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"استخدام التكبير/التصغير لتحويل شاشة صغيرة إلى شاشة أكبر"</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi متصل"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"جارٍ البحث عن GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"تم تعيين الموقع بواسطة GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"طلبات الموقع نشطة"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"محو جميع الإشعارات."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"معلومات التطبيق"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"سيتم تدوير الشاشة تلقائيًا."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"تم تأمين الشاشة في الاتجاه الأفقي."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"تم تأمين الشاشة في الاتجاه العمودي."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"حالة الحلويات"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"حلم اليقظة"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"وضع الطائرة"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"عرض شاشة لاسلكي"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"السطوع"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"تلقائي"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"قد تكون الشبكة\nخاضعة للرقابة"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"تظهر الإشعارات هنا"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"يمكنك الدخول إليها في أي وقت بالتمرير السريع إلى أسفل.\nيمكنك التمرير السريع إلى أسفل مرة أخرى للوصول إلى عناصر تحكم النظام."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"مرر سريعًا لحافة الشاشة لإظهار الشريط"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"مرر سريعًا من حافة الشاشة لإظهار شريط النظام"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-az-rAZ-land/strings.xml b/packages/SystemUI/res/values-az-rAZ-land/strings.xml
deleted file mode 100644
index 8eb6978..0000000
--- a/packages/SystemUI/res/values-az-rAZ-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"Hazırda ekran landşaft orientasiyasında kilidlənib."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-az-rAZ/strings.xml b/packages/SystemUI/res/values-az-rAZ/strings.xml
deleted file mode 100644
index 9565eee..0000000
--- a/packages/SystemUI/res/values-az-rAZ/strings.xml
+++ /dev/null
@@ -1,206 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Sistemin İstifadə İnterfeysi"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Təmizlə"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Siyahıdan sil"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Tətbiq infosu"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Yeni tətbiq yoxdur"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Son tətbiqləri kənarlaşdır"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 son tətbiq"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d son tətbiq"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Bildiriş yoxdu"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Davam edir"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Bildirişlər"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Adapteri qoşun"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Batareya azalır."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> qalıb"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB ilə elektrik doldurma dəstəklənmir.\nYalnız adapter istifadə edin."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Batareya istifadəsi"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Ayarlar"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Təyyarə rejimi"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Ekranın avto-dönüşü"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"SUSDUR"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AVTO"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Bildirişlər"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth tezerinq"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Daxiletmə metodlarını ayarlayın"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Fiziki klaviatura"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"<xliff:g id="APPLICATION">%1$s</xliff:g> tətbiqinə USB cihazına daxil olmağa icazə verilsin?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"<xliff:g id="APPLICATION">%1$s</xliff:g> tətbiqinə USB aksesuarına qoşulmağa icazə verirsiniz?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"USB cihaz qoşulu olan zaman <xliff:g id="ACTIVITY">%1$s</xliff:g> açılsın mı?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"USB aksesuar qoşulu olan zaman <xliff:g id="ACTIVITY">%1$s</xliff:g> açılsın mı?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Heç bir quraşdırılmış tətbiq bu USB aksesuar ilə işləmir. Bu aksesuar haqqında daha ətraflı məlumatı <xliff:g id="URL">%1$s</xliff:g> adresindən öyrənin"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB aksesuar"</string>
-    <string name="label_view" msgid="6304565553218192990">"Göstər"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Bu USB cihaz üçün defolt olaraq istifadə edin."</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Bu USB aksesuar üçün defolt istifadə edin"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB sazlamaya icazə verilsin?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Kompüterin RSA barmaq izi: \n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Bu kompüterdən həmişə icazə verilsin"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Ekranı doldurmaq üçün yaxınlaşdır"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Ekranı doldurmaq üçün uzat"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Skrinşot yadda saxlanılır..."</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Skrinşot yadda saxlanır..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Skrinşot yadda saxlanır."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Skrinşot çəkildi."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Skrinşotunuza baxmaq üçün toxunun"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Skrinşot götürülə bilinmədi."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Skrinşotu yadda saxlamaq alınmadı, yəqin yaddaş istifadə olunur."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB fayl transferi seçimləri"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Media pleyer (MTP) kimi montaj edin"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Kamera kimi birləşdir (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Mac üçün Android File Transfer tətbiqini quraşdırın"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Geri"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Ana səhifə"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Menyu"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Son tətbiqlər"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Daxiletmə metodu düyməsinə keç"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Uyğunluq zoom düyməsi."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Daha böyük ekranda uzaqlaşdır."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth qoşulub."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth əlaqəsi kəsildi."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Batareya yoxdur."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Batareya bir xətdir."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Batareya iki xətdir."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Batareya üç xətdir."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Batareya doludur"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Telefon yoxdur."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Şəbəkə bir xətdir."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Şəbəkə iki xətdir."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Şəbəkə üç xətdir."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Tam şəbəkə."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Məlumat yoxdur."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Data bir xətdir."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Data iki xətdir."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Data üç xətdir."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Data siqnalı tamdır."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi sönülüdür."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi bağlantı kəsildi."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi bir xətdir."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi iki xətdir."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi üç xətdir."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi siqnalı tamdır."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX yoxdur."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX bir xətt."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX iki xətdir."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX üç xətdir."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX siqnalı tamdır."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Siqnal yoxdur."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Qoşulu deyil."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Sıfır xətt."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Bir xətt."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"İki xətt."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Üç xətdir."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Siqnal tamdır."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Aktiv."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Deaktiv"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Qoşuludur."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Rouminq"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM yoxdur"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth tezering."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Uçuş rejimi"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Batareya <xliff:g id="NUMBER">%d</xliff:g> faizdir."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Sistem parametrləri"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Bildirişlər."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Bildirişi təmizlə."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS aktivdir."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS əldə edilir."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter aktivləşdirilib."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Zəng vibrasiyası"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Zəngvuran səssiz."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> çıxarıldı."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Bildiriş uzaqlaşdırıldı."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Bildiriş kölgəsi."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Tez ayarlar."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Axırıncı tətbiqlər."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"İstifadəçi <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Mobil <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Batareya <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Təyyarə Rejimi <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Alarm <xliff:g id="TIME">%s</xliff:g> üçün qurulub."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G data qeyri-aktivdir"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G data deaktiv edildi"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Mobil data qeyri-aktivdir"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Data qeyri-aktivdir"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Göstərilmiş data istifadə limitinə çatdınız.\n\nƏgər datanı yenidən aktivləşdirsəniz, operator tərəfindən əlavə tariflər tətbiq oluna bilər."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Datanı yenidən aktiv et"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"İnternet bağlantısı yoxdur"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi qoşulub"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS Axtarışı"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Yer GPS tərəfindən müəyyən edildi"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Məkan sorğuları arxivi"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Bütün bildirişləri sil."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Tətbiq infosu"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekran avtomatik döndəriləcək."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ekran landşaft orientasiyasında kilidlənib."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ekran portret orientasiyasında kilidlənib."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Xəyal"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Uçuş rejimi"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Dolur, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Dolub"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> Cihaz)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth bağlıdır"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Parlaqlıq"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Avtofırlanma"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Fırlatma kilidlidir"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Daxiletmə metodu"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Yer"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Yer Deaktiv"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Media cihazı"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Yalnız fövqəladə zənglər"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Nizamlar"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Vaxt"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Mən"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Bağlantı yoxdur"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Şəbəkə yoxdur"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi sönülüdür"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi Ekran"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Simsiz Ekran"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Parlaqlıq"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AVTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="5848402127455021714">"Şəbəkə monitor edilə bilər"</string>
-    <string name="done_button" msgid="1759387181766603361">"Hazırdır"</string>
-    <string name="ssl_ca_cert_dialog_title" msgid="1273796967092027291">"Şəbəkə Monitorinqi"</string>
-    <string name="ssl_ca_cert_info_message" msgid="5430320539555358452">"Bu cihaz <xliff:g id="MANAGING_DOMAIN">%s</xliff:g> tərəfindən idarə edilir . \n \n Sizin administrator şəbəkə fəaliyyətinizin, həmçinin e-poçt, tətbiqlər və təhlükəsiz veb saytlarınızın monitorinqini etməyə qadirdir. \n \n Ətraflı məlumat üçün administrator ilə əlaqə saxlayın."</string>
-    <string name="ssl_ca_cert_warning_message" msgid="2033091656129963669">"Üçüncü tərəf \n şəbəkə fəaliyyətinizin, həmçinin e-poçt, tətbiqlər və təhlükəsiz veb saytlarınızın monitorinqini etməyə qadirdir. . \n \nCihanzınıza yüklənmiş etibarlı etimad bunu mümkün edir."</string>
-    <string name="ssl_ca_cert_settings_button" msgid="7946956977377166709">"Etibarlı etimadları yoxlayın"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-az/strings.xml b/packages/SystemUI/res/values-az/strings.xml
deleted file mode 100644
index cb48aa0..0000000
--- a/packages/SystemUI/res/values-az/strings.xml
+++ /dev/null
@@ -1,208 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Sistemin İstifadə İnterfeysi"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Təmizlə"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Siyahıdan sil"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Tətbiq infosu"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Yeni tətbiq yoxdur"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Son tətbiqləri kənarlaşdır"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 son tətbiq"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d son tətbiq"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Bildiriş yoxdu"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Davam edir"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Bildirişlər"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Adapteri qoşun"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Batareya azalır."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> qalıb"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB ilə elektrik doldurma dəstəklənmir.\nYalnız adapter istifadə edin."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Batareya istifadəsi"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Ayarlar"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Təyyarə rejimi"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Ekranın avto-dönüşü"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"SUSDUR"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AVTO"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Bildirişlər"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth tezerinq"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Daxiletmə metodlarını ayarlayın"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Fiziki klaviatura"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"<xliff:g id="APPLICATION">%1$s</xliff:g> tətbiqinə USB cihazına daxil olmağa icazə verilsin?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"<xliff:g id="APPLICATION">%1$s</xliff:g> tətbiqinə USB aksesuarına qoşulmağa icazə verirsiniz?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"USB cihaz qoşulu olan zaman <xliff:g id="ACTIVITY">%1$s</xliff:g> açılsın mı?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"USB aksesuar qoşulu olan zaman <xliff:g id="ACTIVITY">%1$s</xliff:g> açılsın mı?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Heç bir quraşdırılmış tətbiq bu USB aksesuar ilə işləmir. Bu aksesuar haqqında daha ətraflı məlumatı <xliff:g id="URL">%1$s</xliff:g> adresindən öyrənin"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB aksesuar"</string>
-    <string name="label_view" msgid="6304565553218192990">"Göstər"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Bu USB cihaz üçün defolt olaraq istifadə edin."</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Bu USB aksesuar üçün defolt istifadə edin"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB sazlamaya icazə verilsin?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Kompüterin RSA barmaq izi: \n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Bu kompüterdən həmişə icazə verilsin"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Ekranı doldurmaq üçün yaxınlaşdır"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Ekranı doldurmaq üçün uzat"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Skrinşot yadda saxlanılır..."</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Skrinşot yadda saxlanır..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Skrinşot yadda saxlanır."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Skrinşot çəkildi."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Skrinşotunuza baxmaq üçün toxunun"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Skrinşot götürülə bilinmədi."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Skrinşotu yadda saxlamaq alınmadı, yəqin yaddaş istifadə olunur."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB fayl transferi seçimləri"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Media pleyer (MTP) kimi montaj edin"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Kamera kimi birləşdir (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Mac üçün Android File Transfer tətbiqini quraşdırın"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Geri"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Ana səhifə"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Menyu"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Son tətbiqlər"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Daxiletmə metodu düyməsinə keç"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Uyğunluq zoom düyməsi."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Daha böyük ekranda uzaqlaşdır."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth qoşulub."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth əlaqəsi kəsildi."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Batareya yoxdur."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Batareya bir xətdir."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Batareya iki xətdir."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Batareya üç xətdir."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Batareya doludur"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Telefon yoxdur."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Şəbəkə bir xətdir."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Şəbəkə iki xətdir."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Şəbəkə üç xətdir."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Tam şəbəkə."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Məlumat yoxdur."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Data bir xətdir."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Data iki xətdir."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Data üç xətdir."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Data siqnalı tamdır."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi sönülüdür."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi bağlantı kəsildi."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi bir xətdir."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi iki xətdir."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi üç xətdir."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi siqnalı tamdır."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX yoxdur."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX bir xətt."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX iki xətdir."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX üç xətdir."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX siqnalı tamdır."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Siqnal yoxdur."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Qoşulu deyil."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Sıfır xətt."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Bir xətt."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"İki xətt."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Üç xətdir."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Siqnal tamdır."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Aktiv."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Deaktiv"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Qoşuludur."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Rouminq"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM yoxdur"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth tezering."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Uçuş rejimi"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Batareya <xliff:g id="NUMBER">%d</xliff:g> faizdir."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Sistem parametrləri"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Bildirişlər."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Bildirişi təmizlə."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS aktivdir."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS əldə edilir."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter aktivləşdirilib."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Zəng vibrasiyası"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Zəngvuran səssiz."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> çıxarıldı."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Bildiriş uzaqlaşdırıldı."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Bildiriş kölgəsi."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Tez ayarlar."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Axırıncı tətbiqlər."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"İstifadəçi <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Mobil <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Batareya <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Təyyarə Rejimi <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Alarm <xliff:g id="TIME">%s</xliff:g> üçün qurulub."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G data qeyri-aktivdir"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G data deaktiv edildi"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Mobil data qeyri-aktivdir"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Data qeyri-aktivdir"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Göstərilmiş data istifadə limitinə çatdınız.\n\nƏgər datanı yenidən aktivləşdirsəniz, operator tərəfindən əlavə tariflər tətbiq oluna bilər."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Datanı yenidən aktiv et"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"İnternet bağlantısı yoxdur"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi qoşulub"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS Axtarışı"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Yer GPS tərəfindən müəyyən edildi"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Məkan sorğuları arxivi"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Bütün bildirişləri sil."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Tətbiq infosu"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekran avtomatik döndəriləcək."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ekran landşaft orientasiyasında kilidlənib."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ekran portret orientasiyasında kilidlənib."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Xəyal"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Uçuş rejimi"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Dolur, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Dolub"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> Cihaz)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth bağlıdır"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Parlaqlıq"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Avtofırlanma"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Fırlatma kilidlidir"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Daxiletmə metodu"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Yer"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Yer Deaktiv"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Media cihazı"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Yalnız fövqəladə zənglər"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Nizamlar"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Vaxt"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Mən"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Bağlantı yoxdur"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Şəbəkə yoxdur"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi sönülüdür"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi Ekran"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Simsiz Ekran"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Parlaqlıq"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AVTO"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"Bildirişlər burada görünür"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"Aşağı sürüşdürməklə istənilən vaxt onları əldə edin.\nSistemi nəzarəti üçün yenə də aşağı sürüşdürün."</string>
-    <string name="ssl_ca_cert_warning" msgid="5848402127455021714">"Şəbəkə monitor edilə bilər"</string>
-    <string name="done_button" msgid="1759387181766603361">"Hazırdır"</string>
-    <string name="ssl_ca_cert_dialog_title" msgid="1273796967092027291">"Şəbəkə Monitorinqi"</string>
-    <string name="ssl_ca_cert_info_message" msgid="5430320539555358452">"Bu cihaz <xliff:g id="MANAGING_DOMAIN">%s</xliff:g> tərəfindən idarə edilir . \n \n Sizin administrator şəbəkə fəaliyyətinizin, həmçinin e-poçt, tətbiqlər və təhlükəsiz veb saytlarınızın monitorinqini etməyə qadirdir. \n \n Ətraflı məlumat üçün administrator ilə əlaqə saxlayın."</string>
-    <string name="ssl_ca_cert_warning_message" msgid="2033091656129963669">"Üçüncü tərəf \n şəbəkə fəaliyyətinizin, həmçinin e-poçt, tətbiqlər və təhlükəsiz veb saytlarınızın monitorinqini etməyə qadirdir. . \n \nCihanzınıza yüklənmiş etibarlı etimad bunu mümkün edir."</string>
-    <string name="ssl_ca_cert_settings_button" msgid="7946956977377166709">"Etibarlı etimadları yoxlayın"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-be/strings.xml b/packages/SystemUI/res/values-be/strings.xml
index bb8e1d2..6608b79 100644
--- a/packages/SystemUI/res/values-be/strings.xml
+++ b/packages/SystemUI/res/values-be/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Заўсёды дазваляць з гэтага камп\'ютара"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Павял. на ўвесь экран"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Расцягн. на ўвесь экран"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Маштабаванне для сумяшчальнасцi"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Калі прыкладанне распрацаванае для невялікіх экранаў, каля гадзінніка з\'явіцца кіраванне маштабаваннем."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Захаванне скрыншота..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Захаванне скрыншота..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Скрыншот захаваны."</string>
@@ -76,10 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"На Галоўную старонку"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Меню"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Нядаўнія прыкладанні"</string>
-    <!-- no translation found for accessibility_search_light (1103867596330271848) -->
-    <skip />
-    <!-- no translation found for accessibility_camera_button (8064671582820358152) -->
-    <skip />
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Кнопка пераключэння метаду ўводу."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Кнопка сумяшчальнасці маштаба."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Маштабаванне малых элементаў для большага экрана."</string>
@@ -168,15 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi падключаны"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Пошук GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Месца задана праз GPS"</string>
-    <!-- no translation found for accessibility_location_active (2427290146138169014) -->
-    <skip />
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Выдалiць усе апавяшчэннi."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Інфармацыя пра прыкладанне"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Экран паварочваецца аўтаматычна."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Экран заблакiраваны ў альбомнай арыентацыі."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Экран заблакiраваны ў партрэтнай арыентацыі."</string>
-    <!-- no translation found for dessert_case (1295161776223959221) -->
-    <skip />
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Мроi"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Рэжым палёту"</string>
@@ -207,6 +202,10 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Бесправадны дысплей"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Яркасць"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АЎТА"</string>
-    <!-- no translation found for ssl_ca_cert_warning (9005954106902053641) -->
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Апавяшчэнні з\'яўляюцца тут"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Атрымлівайце доступ да іх у любы час, праводзячы пальцам уніз.\nПравядзіце пальцам уніз яшчэ раз, каб атрымаць доступ да сродкаў кіравання сістэмай."</string>
+    <!-- no translation found for hideybar_confirmation_message (9050869548951044371) -->
+    <skip />
+    <!-- no translation found for hideybar_confirmation_message_long (7117692795163620626) -->
     <skip />
 </resources>
diff --git a/packages/SystemUI/res/values-bg/strings.xml b/packages/SystemUI/res/values-bg/strings.xml
index b951aa8..6194fd8 100644
--- a/packages/SystemUI/res/values-bg/strings.xml
+++ b/packages/SystemUI/res/values-bg/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Винаги да се разрешава от този компютър"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Мащаб – запълва екрана"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Разпъване – запълва екрана"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Промяна на мащаба за съвместимост"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Когато дадено приложение е създадено за по-малък екран, до часовника ще се покаже управление за промяна на мащаба."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Екранната снимка се запазва..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Екранната снимка се запазва..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Екранната снимка се запазва."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Начало"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Меню"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Скорошни приложения"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Търсене"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Камера"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Бутон за превключване на метода на въвеждане."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Бутон за промяна на мащаба с цел съвместимост."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Промяна на мащаба на екрана от по-малък до по-голям."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi: Има връзка"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Търси се GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Местоположението е зададено от GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Активни заявки за местоположение"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Изчистване на всички известия."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Информация за приложението"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Екранът ще се завърта автоматично."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Екранът е заключен в хоризонтална ориентация."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Екранът е заключен във вертикална ориентация."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Витрина с десерти"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Мечта"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Самолетен режим"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Автоматична ориентация"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Ориентацията е заключена"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Метод на въвеждане"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Местоположение"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Местоположението е изключено"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Мултимедийно устройство"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"Индикатор за силата на получения сигнал (RSSI)"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Само спешни обаждания"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Безжичен дисплей"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Яркост"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АВТ."</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Мрежата може\nда се наблюдава"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Известията се показват тук"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Осъществявайте достъп до тях по всяко време, като прекарате пръст надолу.\nНаправете го отново за системните контроли."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Прекарайте пръст по ръба на екрана, за да се покаже лентата"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Прекарайте пръст от ръба на екрана, за да се покаже системната лента"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ca/strings.xml b/packages/SystemUI/res/values-ca/strings.xml
index 9bf8de8..eddeda3 100644
--- a/packages/SystemUI/res/values-ca/strings.xml
+++ b/packages/SystemUI/res/values-ca/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Dóna sempre permís des d\'aquest equip"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom per omplir pantalla"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Estira per omplir pant."</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom de compatibilitat"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Quan una aplicació s\'hagi dissenyat per a una pantalla més petita, apareixerà un control de zoom al costat del rellotge."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Desant captura de pantalla..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"S\'està desant la captura de pantalla..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"La captura de pantalla s\'ha desat."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Pàgina d\'inici"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menú"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Aplicacions recents"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Cerca"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Càmera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Botó de canvi del mètode d\'entrada."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Botó de zoom de compatibilitat."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Amplia menys com més gran sigui la pantalla."</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi: connectada"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"S\'està cercant un GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"S\'ha establert la ubicació per GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Sol·licituds d\'ubicació actives"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Esborra totes les notificacions."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informació de l\'aplicació"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"La pantalla girarà automàticament."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"La pantalla està bloquejada en orientació horitzontal."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"La pantalla està bloquejada en orientació vertical."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Capsa de postres"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Estalvi de pantalla"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Mode d\'avió"</string>
@@ -201,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Pantalla sense fil"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brillantor"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMÀTICA"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"És possible que la xarxa\nestigui controlada"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Les notificacions apareixen aquí"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Accedeix-hi en qualsevol moment: només has de fer lliscar el dit cap avall.\nTorna a fer lliscar el dit cap avall per fer que es mostrin els controls del sistema."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Fes lliscar el dit per la vora de la pantalla perquè es mostri la barra"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Fes lliscar el dit des de la vora de la pantalla perquè es mostri la barra del sistema"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-cs/strings.xml b/packages/SystemUI/res/values-cs/strings.xml
index e975979..87ba67a 100644
--- a/packages/SystemUI/res/values-cs/strings.xml
+++ b/packages/SystemUI/res/values-cs/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Vždy povolit z tohoto počítače"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Přiblížit na celou obrazovku"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Na celou obrazovku"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Úprava velikosti z důvodu kompatibility"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Pokud je aplikace navržena pro menší obrazovku, zobrazí se vedle hodin ovládací prvek přiblížení."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Ukládání snímku obrazovky..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Ukládání snímku obrazovky..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Probíhá ukládání snímku obrazovky."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Domů"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Nové aplikace"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Hledat"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Fotoaparát"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Tlačítko přepnutí metody zadávání"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Tlačítko úpravy velikosti z důvodu kompatibility"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zvětšit menší obrázek na větší obrazovku."</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi: připojeno"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Vyhledávání satelitů GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Poloha nastavena pomocí systému GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktivní žádosti o polohu"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Vymazat všechna oznámení."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informace o aplikaci"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Obrazovka se automaticky otočí."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Obrazovka je uzamčena v orientaci na šířku."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Obrazovka je uzamčena v orientaci na výšku."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Pult se sladkostmi"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Spořič obrazovky"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Režim V letadle"</string>
@@ -185,8 +184,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Automatické otáčení"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Otáčení je uzamčeno"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Metoda zadávání dat"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Poloha"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Poloha vypnuta"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Mediální zařízení"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Pouze tísňová volání"</string>
@@ -201,5 +202,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Bezdrátový displej"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Jas"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATICKY"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Síť může být\nmonitorována"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Zde se zobrazují oznámení"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Můžete je kdykoli zobrazit tím, že přejedete prstem dolů.\nPřejedete-li prstem dolů ještě jednou, zobrazí se ovládací prvky systému."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Panel zobrazíte přejetím přes okraj obrazovky"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Systémový panel zobrazíte přejetím přes okraj obrazovky"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-da/strings.xml b/packages/SystemUI/res/values-da/strings.xml
index 25c5baa..af4bb33 100644
--- a/packages/SystemUI/res/values-da/strings.xml
+++ b/packages/SystemUI/res/values-da/strings.xml
@@ -44,7 +44,7 @@
     <string name="status_bar_settings_mute_label" msgid="554682549917429396">"LYDLØS"</string>
     <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AUTO"</string>
     <string name="status_bar_settings_notifications" msgid="397146176280905137">"Underretninger"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Netdeling via Bluetooth anvendt"</string>
+    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth-tethering anvendt"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Konfigurer inputmetoder"</string>
     <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Fysisk tastatur"</string>
     <string name="usb_device_permission_prompt" msgid="834698001271562057">"Tillad, at appen <xliff:g id="APPLICATION">%1$s</xliff:g> kan få adgang til USB-enheden?"</string>
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Tillad altid fra denne computer"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom til fuld skærm"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Stræk til fuld skærm"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Kompatibilitetszoom"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Når en app er udviklet til en mindre skærm, vises der en zoomfunktion ved uret."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Gemmer skærmbillede..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Gemmer skærmbillede..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Skærmbilledet gemmes."</string>
@@ -73,11 +75,9 @@
     <string name="use_ptp_button_title" msgid="7517127540301625751">"Isæt som et kamera (PTP)"</string>
     <string name="installer_cd_button_title" msgid="2312667578562201583">"Installer appen Android Filoverførsel til Mac"</string>
     <string name="accessibility_back" msgid="567011538994429120">"Tilbage"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Startskærm"</string>
+    <string name="accessibility_home" msgid="8217216074895377641">"Startside"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Seneste apps"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Søg"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Skift indtastningsmetode-knappen."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Knap for kompatibilitetszoom."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom mindre til større skærm."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi er forbundet"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Søger efter GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Placeringen er angivet ved hjælp af GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktive placeringsanmodninger"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Ryd alle meddelelser."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Oplysninger om appen"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Skærmen roterer automatisk."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Skærmen er nu låst i liggende retning."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Skærmen er nu låst i stående retning."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessertcase"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Dagdrøm"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Flytilstand"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Trådløs skærm"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Lysstyrke"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Netværket kan\nvære overvåget"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Underretninger vises her"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Få adgang til dem når som helst ved at stryge ned.\nStryg ned igen for at komme til systemindstillingerne."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Stryg kanten af skærmen for at se bjælken"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Stryg fra skærmens kant for at se systembjælken"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-de/strings.xml b/packages/SystemUI/res/values-de/strings.xml
index cc31df4..ec52ede 100644
--- a/packages/SystemUI/res/values-de/strings.xml
+++ b/packages/SystemUI/res/values-de/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Von diesem Computer immer zulassen"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom auf Bildschirmgröße"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Auf Bildschirmgröße anpassen"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Kompatibilitätszoom"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Wenn eine App für einen kleineren Bildschirm ausgelegt ist, wird ein Zoom-Steuerelement neben der Uhr angezeigt."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Screenshot wird gespeichert..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Screenshot wird gespeichert..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Screenshot wird gespeichert..."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Startbildschirm"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menü"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Kürzlich geöffnete Apps"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Suchen"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Schaltfläche zum Ändern der Eingabemethode"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Schaltfläche für Kompatibilitätszoom"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom auf einen größeren Bildschirm"</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"WLAN verbunden"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS wird gesucht"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Standort durch GPS festgelegt"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Standortanfragen aktiv"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Alle Benachrichtigungen löschen"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"App-Details"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Bildschirm wird automatisch gedreht."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Bildschirm bleibt im Querformat."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Bildschirm bleibt im Hochformat."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessertbehälter"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Flugmodus"</string>
@@ -185,8 +184,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Autom. drehen"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Drehung gesperrt"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Eingabemethode"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Standort"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Standort aus"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Mediengerät"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Nur Notrufe"</string>
@@ -201,5 +202,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Kabellose Übertragung (WiDi)"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Helligkeit"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Netzwerk wird\neventuell überwacht."</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Benachrichtigungen erscheinen hier"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Greifen Sie jederzeit auf sie zu, indem Sie nach unten wischen.\nWischen Sie für Systemeinstellungen erneut nach unten."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Zum Einblenden der Leiste vom Rand wischen"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Zum Einblenden der Systemleiste vom Display-Rand weg wischen"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-el/strings.xml b/packages/SystemUI/res/values-el/strings.xml
index 37fa359..ab43081 100644
--- a/packages/SystemUI/res/values-el/strings.xml
+++ b/packages/SystemUI/res/values-el/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Να επιτρέπεται πάντα από αυτόν τον υπολογιστή"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Ζουμ σε πλήρη οθόνη"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Προβoλή σε πλήρη οθ."</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Ζουμ για συμβατότητα"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Όταν μια εφαρμογή έχει σχεδιαστεί για προβολή σε μικρότερη οθόνη, δίπλα από το ρολόι θα εμφανιστεί ένα στοιχείο ελέγχου ζουμ."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Αποθήκ. στιγμιότυπου οθόνης..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Αποθήκευση στιγμιότυπου οθόνης..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Γίνεται αποθήκευση του στιγμιότυπου οθόνης."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Αρχική σελίδα"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Μενού"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Πρόσφατες εφαρμογές"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Αναζήτηση"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Φωτογραφική μηχανή"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Κουμπί εναλλαγής μεθόδου εισόδου"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Κουμπί εστίασης συμβατότητας."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Ζουμ από μικρότερη σε μεγαλύτερη οθόνη."</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi συνδεδεμένο"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Αναζήτηση για GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Ρύθμιση τοποθεσίας με GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Τα αιτήματα τοποθεσίας έχουν ενεργοποιηθεί"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Εκκαθάριση όλων των ειδοποιήσεων."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Πληροφορίες εφαρμογής"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Θα γίνεται αυτόματη περιστροφή της οθόνης."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Η οθόνη έχει κλειδωθεί σε οριζόντιο προσανατολισμό."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Η οθόνη έχει κλειδωθεί σε κατακόρυφο προσανατολισμό."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Επιδόρπιο"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Λειτουργία πτήσης"</string>
@@ -201,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Ασύρματη οθόνη"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Φωτεινότητα"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ΑΥΤΟΜΑΤΗ"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Το δίκτυο μπορεί\nνα παρακολουθείται"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Οι ειδοποιήσεις εμφανίζονται εδώ"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Μεταβείτε σε αυτές ανά πάσα στιγμή σύροντας προς τα κάτω.\nΣύρετε ξανά προς τα κάτω για τα στοιχεία ελέγχου συστήματος."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Σύρετε από την άκρη της οθόνης για να εμφανίσετε τη γραμμή"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Σύρετε από την άκρη της οθόνης για να εμφανίσετε τη γραμμή συστήματος"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-en-rGB/strings.xml b/packages/SystemUI/res/values-en-rGB/strings.xml
index fb32af1..6027553f 100644
--- a/packages/SystemUI/res/values-en-rGB/strings.xml
+++ b/packages/SystemUI/res/values-en-rGB/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Always allow from this computer"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom to fill screen"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Stretch to fill screen"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Compatibility zoom"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"When an app was designed for a smaller screen, a zoom control will appear by the clock."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Saving screenshot…"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Saving screenshot…"</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Screenshot is being saved."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Home"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Recent apps"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Search"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Camera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Switch input method button."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Compatibility zoom button."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom smaller to larger screen."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi connected"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Searching for GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Location set by GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Location requests active"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Clear all notifications."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"App info"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Screen will rotate automatically."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Screen is locked in landscape orientation."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Screen is locked in portrait orientation."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Aeroplane mode"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Wireless Display"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brightness"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Network may\nbe monitored"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Notifications appear here"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Access them any time by swiping down.\nSwipe down again for system controls."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Swipe edge of screen to reveal bar"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Swipe from edge of screen to reveal system bar"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-en-rIN-land/strings.xml b/packages/SystemUI/res/values-en-rIN-land/strings.xml
deleted file mode 100644
index ba773b8..0000000
--- a/packages/SystemUI/res/values-en-rIN-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"Screen is now locked in landscape orientation."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-en-rIN/strings.xml b/packages/SystemUI/res/values-en-rIN/strings.xml
deleted file mode 100644
index fb32af1..0000000
--- a/packages/SystemUI/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"System UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Clear"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Remove from list"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"App info"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"No recent apps"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Dismiss recent apps"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 recent app"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d recent apps"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"No notifications"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Ongoing"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Notifications"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Connect charger"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"The battery is getting low."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> remaining"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB charging not supported.\nUse only the supplied charger."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Battery use"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Settings"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Aeroplane mode"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Auto-rotate screen"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"MUTE"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AUTO"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Notifications"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth tethered"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Set up input methods"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Physical keyboard"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Allow the app <xliff:g id="APPLICATION">%1$s</xliff:g> to access the USB device?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Allow the app <xliff:g id="APPLICATION">%1$s</xliff:g> to access the USB accessory?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Open <xliff:g id="ACTIVITY">%1$s</xliff:g> when this USB device is connected?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Open <xliff:g id="ACTIVITY">%1$s</xliff:g> when this USB accessory is connected?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"No installed apps work with this USB accessory. Learn more about this accessory at <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB accessory"</string>
-    <string name="label_view" msgid="6304565553218192990">"View"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Use by default for this USB device"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Use by default for this USB accessory"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"Allow USB debugging?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"The computer\'s RSA key fingerprint is:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Always allow from this computer"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Zoom to fill screen"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Stretch to fill screen"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Saving screenshot…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Saving screenshot…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Screenshot is being saved."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Screenshot captured."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Touch to view your screenshot."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Couldn\'t capture screenshot."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Couldn\'t save screenshot. Storage may be in use."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB file transfer options"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Mount as a media player (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Mount as a camera (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Install Android File Transfer application for Mac"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Back"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Home"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Recent apps"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Search"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Camera"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Switch input method button."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Compatibility zoom button."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom smaller to larger screen."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth connected."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth disconnected."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"No battery."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Battery one bar."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Battery two bars."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Battery three bars."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Battery full."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"No phone."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Phone one bar."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Phone two bars."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Phone three bars."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Phone signal full."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"No data."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Data one bar."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Data two bars."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Data three bars."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Data signal full."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wi-Fi off."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wi-Fi disconnected."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wi-Fi one bar."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wi-Fi two bars."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wi-Fi three bars."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wi-Fi signal full."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"No WiMAX."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX one bar."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX two bars."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX three bars."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX signal full."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"No signal."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Not connected."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Zero bars."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"One bar."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Two bars."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Three bars."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Signal full."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"On."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Off."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Connected."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Roaming"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"No SIM."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth tethering"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Aeroplane mode"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Battery <xliff:g id="NUMBER">%d</xliff:g> per cent."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"System settings"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Notifications."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Clear notification."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS enabled."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS acquiring."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter enabled."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Ringer vibrate."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Ringer silent."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> dismissed."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Notification dismissed."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Notification shade."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Quick settings."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Recent apps"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"User <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Mobile <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Battery <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Aeroplane Mode <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Alarm set for <xliff:g id="TIME">%s</xliff:g>."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G data disabled"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G data disabled"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Mobile data disabled"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Data disabled"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"You\'ve reached the specified data usage limit.\n\nIf you re-enable data, you may be charged by the operator."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Reenable data"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"No Internet connection"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi connected"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"Searching for GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Location set by GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Location requests active"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Clear all notifications."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"App info"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Screen will rotate automatically."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Screen is locked in landscape orientation."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Screen is locked in portrait orientation."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Aeroplane mode"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Charging, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Charged"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> Devices)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth Off"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Brightness"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Auto Rotate"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotation Locked"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Input Method"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Location"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Location Off"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Media device"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Emergency Calls Only"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Settings"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Time"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Me"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Not Connected"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"No Network"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi Off"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi Display"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Wireless Display"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brightness"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Network may\nbe monitored"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-es-rUS/strings.xml b/packages/SystemUI/res/values-es-rUS/strings.xml
index 54ad455..62f6c20 100644
--- a/packages/SystemUI/res/values-es-rUS/strings.xml
+++ b/packages/SystemUI/res/values-es-rUS/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Permitir siempre desde esta computadora"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom para ocupar la pantalla"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Estirar p/ ocupar la pantalla"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom de compatibilidad"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Cuando una aplicación fue diseñada para una pantalla más pequeña, aparece un control de zoom junto al reloj."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Guardando captura de pantalla"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Guardando la captura de pantalla..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"La captura de pantalla se está guardando."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Página principal"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menú"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Aplicaciones recientes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Buscar"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Cámara"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Botón Cambiar método de entrada"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Botón de zoom de compatibilidad"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom de pantalla más pequeña a más grande"</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi conectado"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Buscando GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"La ubicación se estableció por GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Solicitudes de ubicación activas"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Eliminar todas las notificaciones"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Información de la aplicación"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"La pantalla girará automáticamente."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"La pantalla está bloqueada en modo horizontal."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"La pantalla está bloqueada en modo vertical."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Caja para postres"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Activar protector"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Modo avión"</string>
@@ -185,8 +184,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Girar automáticamente"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotación bloqueada"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Método de introducción"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Ubicación"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Ubicación desactivada"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Dispositivo multimedia"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Solo emergencia"</string>
@@ -201,5 +202,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Pantalla inalámbrica"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brillo"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMÁTICO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Es posible que la red\nesté supervisada."</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Las notificaciones aparecen aquí."</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Desliza el dedo hacia abajo para acceder al contenido.\nVuelve a deslizar el dedo hacia abajo para acceder a los controles del sistema."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Desliza el dedo desde el borde de la pantalla para mostrar la barra."</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Desliza el dedo desde el borde de la pantalla para mostrar la barra del sistema."</string>
 </resources>
diff --git a/packages/SystemUI/res/values-es/strings.xml b/packages/SystemUI/res/values-es/strings.xml
index 7dcb079..64c3cab 100644
--- a/packages/SystemUI/res/values-es/strings.xml
+++ b/packages/SystemUI/res/values-es/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Permitir siempre desde este ordenador"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom para ajustar"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Expandir para ajustar"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom de compatibilidad"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Si la aplicación se ha diseñado para una pantalla más pequeña, aparecerá un control de zoom junto al reloj."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Guardando captura..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Guardando captura..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"La captura de pantalla se está guardando."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Inicio"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menú"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Aplicaciones recientes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Buscar"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Cámara"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Botón Cambiar método de entrada"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Botón de zoom de compatibilidad"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom de pantalla más pequeña a más grande"</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Con conexión Wi-Fi"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Buscando GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Ubicación definida por GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Solicitudes de ubicación activas"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Borrar todas las notificaciones"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Información de la aplicación"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"La pantalla girará automáticamente."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"La pantalla está bloqueada en modo horizontal."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"La pantalla está bloqueada en modo vertical."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Caja para postres"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Salvapantallas"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Modo avión"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Pantalla inalámbrica"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brillo"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"La red se\npuede supervisar"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Las notificaciones aparecen aquí"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Desliza el dedo hacia abajo para acceder al contenido.\nVuelve a deslizar el dedo hacia abajo para acceder a los controles del sistema."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Desliza el borde de la pantalla para mostrar la barra"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Desliza el borde de la pantalla para mostrar la barra del sistema"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-et-rEE-land/strings.xml b/packages/SystemUI/res/values-et-rEE-land/strings.xml
deleted file mode 100644
index 77b0ce1..0000000
--- a/packages/SystemUI/res/values-et-rEE-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"Ekraan on nüüd lukustatud horisontaalasendisse."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-et-rEE/strings.xml b/packages/SystemUI/res/values-et-rEE/strings.xml
deleted file mode 100644
index d485a55..0000000
--- a/packages/SystemUI/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Süsteemi UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Kustuta"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Loendist eemaldamine"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Rakenduse teave"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Uusi rakendusi pole"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Loobu hiljutistest rakendustest"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 hiljutine rakendus"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d hiljutist rakendust"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Teatisi pole"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Jätkuv"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Teadistused"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Ühendage laadija"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Aku hakkab tühjenema."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> on alles"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB laadimist ei toetata.\nKasutage ainult tootja laadija."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Akukasutus"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Seaded"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"WiFi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Lennurežiim"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Pööra ekraani automaatselt"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"SUMMUTA"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AUTO"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Teatised"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth on jagatud"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Seadista sisestusmeetodeid"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Füüsiline klaviatuur"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Kas lubate rakendusel <xliff:g id="APPLICATION">%1$s</xliff:g> USB-seadmele juurde pääseda?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Kas lubate rakendusel <xliff:g id="APPLICATION">%1$s</xliff:g> USB-seadmele juurde pääseda?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Kas avada <xliff:g id="ACTIVITY">%1$s</xliff:g>, kui see USB-seade on ühendatud?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Kas avada <xliff:g id="ACTIVITY">%1$s</xliff:g>, kui USB-lisaseade on ühendatud?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Inst. rak. ei tööta selle USB-seadmega. Lisateavet lisaseadme kohta vt siit: <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB-lisaseade"</string>
-    <string name="label_view" msgid="6304565553218192990">"Kuva"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Kasuta vaikimisi selle USB-seadme jaoks"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Vaikimisi kasuta seda USB-lisaseadet"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"Kas luban USB silumise?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Arvuti RSA-võtme sõrmejälg:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Luba alati sellest arvutist"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Suumi ekraani täitmiseks"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Venita ekraani täitmiseks"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Kuvatõmmise salvestamine ..."</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Kuvatõmmise salvestamine ..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Kuvatõmmist salvestatakse."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Ekraanipilt on jäädvustatud."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Puudutage kuvatõmmise vaatamiseks."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Kuvatõmmist ei saanud jäädvustada."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Kuvatõmmist ei saa salvestada. Mäluseade võib olla kasutuses."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB-failiedastuse valikud"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Paigalda meediumimängijana (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Paigalda kaamerana (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Android File Transferi installimine Macile"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Tagasi"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Kodu"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Menüü"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Hiljutised rakendused"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Otsing"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kaamera"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Sisestusmeetodi vahetamise nupp."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Sobivussuumi nupp."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Suumi suuremale ekraanile vähem."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth on ühendatud."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetoothi ühendus katkestatud."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Aku puudub."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Aku: üks pulk."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Aku: kaks pulka."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Aku: kolm pulka."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Aku täis."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Telefonisignaal puudub"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Telefonisignaal: üks pulk."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Telefonisignaal: kaks pulka."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Telefonisignaal: kolm pulka."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Telefonisignaal on tugev."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Andmed puuduvad."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Andmesignaal: üks pulk."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Andmeside: kaks pulka."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Andmeside: kolm pulka."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Andmesignaal on tugev."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi on väljas."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi-ühendus on katkestatud."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"WiFi: üks pulk."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"WiFi: kaks pulka."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi: kolm pulka."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"WiFi-signaal on tugev."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX-i pole."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX-i on üks riba."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX-i on kaks riba."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX-i on kolm riba."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX-i signaal on tugev."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Signaal puudub."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Ühendus puudub."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Null pulka."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Üks pulk."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Kaks pulka."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Kolm pulka."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Signaal on tugev."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Sees."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Väljas."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Ühendatud."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3,5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Rändlus"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Serv"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"WiFi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM-kaarti pole."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetoothi jagamine."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Lennurežiim."</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Aku: <xliff:g id="NUMBER">%d</xliff:g> protsenti."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Süsteemiseaded"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Teatised"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Teatise kustutamine"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS on lubatud."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS-signaali otsimine."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter lubatud."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Vibreeriv kõlisti."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Vaikne kõlisti."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"Loobusite rakendusest <xliff:g id="APP">%s</xliff:g>."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Märguandest on loobutud."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Märguande vari."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Kiirseaded."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Hiljutised rakendused"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Kasutaja <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Mobiili <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Aku: <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Lennukirežiim: <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth: <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Määratud äratus: <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G–3G andmeside keelatud"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G andmeside keelatud"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Mobiilne andmeside keelatud"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Andmekasutus keelatud."</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Olete jõudnud määratud andmekasutuse piirini.\n\nKui lülitate andmeside uuesti sisse, siis võib operaator teilt tasu võtta."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Luba andmeside uuesti"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Interneti-ühendus puudub"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"WiFi on ühendatud"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS-i otsimine"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS-i määratud asukoht"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Asukoha taotlused on aktiivsed"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Kustuta kõik teatised."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Rakenduse teave"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekraani pööramine toimub automaatselt."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ekraan on lukustatud horisontaalsuunas."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ekraan on lukustatud vertikaalsuunas."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Maiustusekorv"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Unistus"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Lennurežiim"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Laadimine, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Laetud"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> seadet)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth on väljas"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Heledus"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Automaatne pööramine"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Pööramine lukus"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Sisestusmeetod"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Asukoht"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Asukoht on väljas"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Meediaseade"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Ainult hädaabikõned"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Seaded"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Aeg"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Mina"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"WiFi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Ühendus puudub"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Võrku pole"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"WiFi-ühendus on väljas"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"WiFi-ekraan"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Juhtmeta ekraaniühendus"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Heledus"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMAATNE"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Võrku võidakse\njälgida"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-et/strings.xml b/packages/SystemUI/res/values-et/strings.xml
index 28ece65..6d9c838 100644
--- a/packages/SystemUI/res/values-et/strings.xml
+++ b/packages/SystemUI/res/values-et/strings.xml
@@ -164,7 +164,6 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"WiFi on ühendatud"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS-i otsimine"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS-i määratud asukoht"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Asukoha taotlused on aktiivsed"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Kustuta kõik teatised."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Rakenduse teave"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekraani pööramine toimub automaatselt."</string>
@@ -201,4 +200,6 @@
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMAATNE"</string>
     <string name="status_bar_help_title" msgid="1199237744086469217">"Märguanded ilmuvad siia"</string>
     <string name="status_bar_help_text" msgid="7874607155052076323">"Juurdepääs igal ajal sõrmega alla pühkides.\nSüsteemi juhtnuppude jaoks pühkige uuesti alla."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Riba kuvamiseks pühkige ekraani serva"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Süsteemiriba kuvamiseks pühkige ekraani servast"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-fa/strings.xml b/packages/SystemUI/res/values-fa/strings.xml
index d9f193f..b095519 100644
--- a/packages/SystemUI/res/values-fa/strings.xml
+++ b/packages/SystemUI/res/values-fa/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"همیشه از این رایانه انجام شود"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"بزرگنمایی برای پر کردن صفحه"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"گسترده کردن برای پر کردن صفحه"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"بزرگنمایی سازگاری"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"اگر یک برنامه برای صفحه کوچک تری طراحی شده باشد، یک کنترل بزرگنمایی توسط ساعت نشان داده می‌شود."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"در حال ذخیره تصویر صفحه..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"در حال ذخیره تصویر صفحه..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"تصویر صفحه ذخیره شد."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"صفحهٔ اصلی"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"منو"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"برنامه‌های اخیر"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"جستجو"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"دوربین"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"کلید تغییر روش ورود متن."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"دکمه بزرگنمایی سازگار."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"بزرگنمایی از صفحه‌های کوچک تا بزرگ."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi متصل شد"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"جستجو برای GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"مکان تنظیم شده توسط GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"درخواست‌های موقعیت مکانی فعال است"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"پاک کردن تمام اعلان‌ها"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"اطلاعات برنامه"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"صفحه به صورت خودکار می‌چرخد."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"صفحه اکنون در جهت افقی قفل است."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"صفحه اکنون در جهت عمودی قفل است."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"ویترین دسر"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"رویاپردازی"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"اترنت"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"حالت هواپیما"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"چرخش خودکار"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"چرخش قفل شد"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"روش ورودی"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"مکان"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"مکان خاموش"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"دستگاه رسانه"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"فقط تماس‌های اضطراری"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"نمایش بدون سیم"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"روشنایی"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"خودکار"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"ممکن است شبکه\nتحت نظارت باشد"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"اعلان‌ها در اینجا نمایش داده می‌شوند"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"با کشیدن انگشت به طرف پایین به آنها دسترسی پیدا کنید.\nبرای کنترل‌های سیستم دوباره انگشت خود را به سمت پایین بکشید."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"برای نمایش نوار، انگشت خود را از لبه‌ صفحه به داخل بکشید"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"برای نمایش نوار سیستم، انگشت خود را از لبه‌ صفحه به داخل بکشید"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-fi/strings.xml b/packages/SystemUI/res/values-fi/strings.xml
index 4607365..06e1926 100644
--- a/packages/SystemUI/res/values-fi/strings.xml
+++ b/packages/SystemUI/res/values-fi/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Salli aina tällä tietokoneella"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoomaa koko näyttöön"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Venytä koko näyttöön"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Yhteensopivuuszoomaus"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Jos sovellus on suunniteltu pienemmälle näytölle, kellon viereen tulee näkyviin zoomaussäädin."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Tallennetaan kuvakaappausta..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Tallennetaan kuvakaappausta..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Kuvakaappausta tallennetaan."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Aloituspainike"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Valikko"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Viimeaikaiset sovellukset"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Haku"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Syöttötavan vaihtopainike."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Yhteensopivuuszoomaus-painike."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoomaa pienemmältä suuremmalle ruudulle."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wifi yhdistetty"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Haetaan GPS-yhteyttä"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Sijainti määritetty GPS:n avulla"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Sijaintipyynnöt aktiiviset"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Tyhjennä kaikki ilmoitukset."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Sovelluksen tiedot"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ruutu kääntyy automaattisesti."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ruutu on lukittu vaakasuuntaan."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ruutu on lukittu pystysuuntaan."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Jälkiruokavitriini"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Unelmat"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Lentokonetila"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Langaton näyttö"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Kirkkaus"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Verkkoa saatetaan\nvalvoa"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Ilmoitukset näkyvät tässä"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Näet ilmoitukset liu\'uttamalla sormea alas ruudulla.\nVoit palauttaa järjestelmän ohjaimet näkyviin liu\'uttamalla sormea alas uudelleen."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Tuo palkki näkyviin liu\'uttamalla ruudun reunasta"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Tuo järjestelmäpalkki näkyviin liu\'uttamalla ruudun reunasta"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-fr-rCA-land/strings.xml b/packages/SystemUI/res/values-fr-rCA-land/strings.xml
deleted file mode 100644
index 4775fc6..0000000
--- a/packages/SystemUI/res/values-fr-rCA-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"L\'écran est désormais verrouillé au format paysage."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-fr-rCA/strings.xml b/packages/SystemUI/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 8b49129..0000000
--- a/packages/SystemUI/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,205 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"IU système"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Effacer"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Supprimer de la liste"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Informations sur l\'application"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Aucune application récente"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Masquer les applications récentes"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 application récente"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d applications récentes"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Aucune notification"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"En cours"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Notifications"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Brancher le chargeur"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Le niveau de la batterie est faible."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> restant(s)"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"Chargement USB non compatible.\nVous devez utiliser le chargeur fourni."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Utilisation de la batterie"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Paramètres"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Mode Avion"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Rotation auto de l\'écran"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"MUET"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AUTOMATIQUE"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Notifications"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Connexion Bluetooth partagée"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Configurer les modes de saisie"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Clavier physique"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Autoriser l\'application <xliff:g id="APPLICATION">%1$s</xliff:g> à accéder au périphérique USB?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Autoriser l\'application <xliff:g id="APPLICATION">%1$s</xliff:g> à accéder à l\'accessoire USB?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Ouvrir <xliff:g id="ACTIVITY">%1$s</xliff:g> lors de la connexion de ce périphérique USB?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Ouvrir <xliff:g id="ACTIVITY">%1$s</xliff:g> lors de la connexion de cet accessoire USB?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Aucune application installée compatible avec accessoire USB. En savoir plus sur <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"Accessoire USB"</string>
-    <string name="label_view" msgid="6304565553218192990">"Afficher"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Utiliser par défaut pour ce périphérique USB"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Utiliser par défaut pour cet accessoire USB"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"Autoriser le débogage USB?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Empreinte numérique de la clé RSA de l\'ordinateur : \n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Toujours autoriser sur cet ordinateur"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Zoomer pour remplir l\'écran"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Étirer pour remplir l\'écran"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Enregistrement capture écran…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Enregistrement capture écran…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Enregistrement de la capture d\'écran en cours…"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Capture d\'écran réussie"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Appuyez pour afficher votre capture d\'écran."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Impossible de réaliser une capture d\'écran"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Impossible enregistrer capture d\'écran. Périphérique de stockage peut-être en cours d\'utilisation."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"Options transfert fichiers USB"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Installer comme un lecteur multimédia (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Installer comme un appareil photo (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Installer application Android File Transfer (Mac)"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Précédent"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Domicile"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Applications récentes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Rechercher"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Appareil photo"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Bouton \"Changer le mode de saisie\""</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Bouton \"Zoom de compatibilité\""</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom de compatibilité avec la taille de l\'écran"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth connecté"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth déconnecté"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Batterie vide"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Niveau de batterie : faible"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Niveau de batterie : moyen"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Niveau de batterie : bon"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Batterie pleine"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Aucun signal"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Signal : faible"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Signal : moyen"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Signal : bon"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Signal excellent"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Aucun signal"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Signal faible"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Signal moyen"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Signal bon"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Signal excellent"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wi-Fi désactivé"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wi-Fi déconnecté"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Signal Wi-Fi faible"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Signal Wi-Fi moyen"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Signal Wi-Fi bon"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Signal Wi-Fi excellent"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"Aucun signal WiMAX"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"Signal WiMAX : faible"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"Signal WiMAX : moyen"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"Signal WiMAX : bon"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"Signal WiMAX : excellent"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Aucun signal"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Non connecté"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Aucun signal"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Signal faible"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Moyen"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Bon"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Signal excellent"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Activé"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Désactivé"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Connecté"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1x"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"3G+"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3G+"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Itinérance"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"EDGE"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"Aucune carte SIM"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Partage de connexion Bluetooth"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Mode Avion"</string>
-    <!-- String.format failed for translation -->
-    <!-- no translation found for accessibility_battery_level (7451474187113371965) -->
-    <skip />
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Paramètres système"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Notifications"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Supprimer la notification"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS activé"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"Acquisition de données GPS"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"Téléscripteur activé"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Sonnerie en mode vibreur"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Sonnerie en mode silencieux"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"Application \"<xliff:g id="APP">%s</xliff:g>\" ignorée."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Notification masquée"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Volet des notifications"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Paramètres rapides"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Applications récentes"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Utilisateur : <xliff:g id="USER">%s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>, <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Signal mobile : <xliff:g id="SIGNAL">%1$s</xliff:g>, <xliff:g id="TYPE">%2$s</xliff:g>, <xliff:g id="NETWORK">%3$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Batterie : <xliff:g id="STATE">%s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Mode Avion : <xliff:g id="STATE">%s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth : <xliff:g id="STATE">%s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Alarme réglée sur <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"Données 2G-3G  désactivées"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"Données 4G désactivées"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Données mobiles désactivées"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Données désactivées"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Vous avez atteint le plafond de consommation de données spécifié.\n\nSi vous utilisez des données supplémentaires, celles-ci pourront être facturées par l\'opérateur."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Réactiver connexion données"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Aucune connexion Internet"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Connecté au Wi-Fi"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"Recherche de GPS..."</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Position définie par GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Demandes de localisation actives"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Supprimer toutes les notifications"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informations sur l\'application"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"L\'écran pivote automatiquement."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"L\'écran est verrouillé en mode paysage."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"L\'écran est verrouillé en mode portrait."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Vitrine des desserts"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Écran de veille"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Mode Avion"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"En charge (<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>)"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Chargée"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> appareils)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"BLUETOOTH DÉSACTIVÉ"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Luminosité"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Rotation automatique"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotation verrouillée"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Mode de saisie"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Position"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Localisation désactivée"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Appareil multimédia"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Appels d\'urgence uniquement"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Paramètres"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Heures"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Moi"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Non connecté"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Aucun réseau"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi désactivé"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Affichage Wi-Fi"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Affichage sans fil"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Luminosité"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATIQUE"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Le réseau peut\nêtre surveillé."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-fr/strings.xml b/packages/SystemUI/res/values-fr/strings.xml
index 45e407d2..7db07e2 100644
--- a/packages/SystemUI/res/values-fr/strings.xml
+++ b/packages/SystemUI/res/values-fr/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Toujours autoriser sur cet ordinateur"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoomer pour remplir l\'écran"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Étirer pour remplir l\'écran"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom de compatibilité"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Si une application a été conçue pour un écran plus petit, une commande de zoom s\'affiche à côté de l\'horloge."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Enregistrement capture écran…"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Enregistrement de la capture d\'écran…"</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Enregistrement de la capture d\'écran en cours…"</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Accueil"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Applications récentes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Rechercher"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Appareil photo"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Bouton \"Changer le mode de saisie\""</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Bouton \"Zoom de compatibilité\""</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom de compatibilité avec la taille de l\'écran"</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Connecté au Wi-Fi"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Recherche de GPS..."</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Position définie par GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Demandes de localisation actives"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Supprimer toutes les notifications"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informations sur l\'application"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"L\'écran pivote automatiquement."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"L\'écran est verrouillé en mode paysage."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"L\'écran est verrouillé en mode portrait."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Vitrine des desserts"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Écran de veille interactif"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Mode avion"</string>
@@ -185,8 +184,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Rotation auto"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotation bloquée"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Mode de saisie"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Localisation"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Localisation désactivée"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Appareil multimédia"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Appels d\'urgence uniquement"</string>
@@ -201,5 +202,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Affichage sans fil"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Luminosité"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATIQUE"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Le réseau peut\nêtre surveillé."</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Les notifications s’affichent ici"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Accédez-y à tout moment en faisant glisser le doigt vers le bas.\nRépétez l\'opération pour accéder aux commandes du système."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Faites glisser votre doigt sur le côté de l\'écran pour afficher la barre."</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Faites glisser votre doigt à partir d\'un côté de l\'écran pour afficher la barre système."</string>
 </resources>
diff --git a/packages/SystemUI/res/values-hi/strings.xml b/packages/SystemUI/res/values-hi/strings.xml
index da958bf..862e2ef 100644
--- a/packages/SystemUI/res/values-hi/strings.xml
+++ b/packages/SystemUI/res/values-hi/strings.xml
@@ -22,12 +22,12 @@
     <string name="app_label" msgid="7164937344850004466">"सिस्‍टम UI"</string>
     <string name="status_bar_clear_all_button" msgid="7774721344716731603">"साफ़ करें"</string>
     <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"सूची से निकालें"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"एप्‍स जानकारी"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"कोई हाल ही के एप्स नहीं"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"हाल ही के एप्स खारिज करें"</string>
+    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"एप्‍लिकेशन जानकारी"</string>
+    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"कोई हाल ही के एप्लिकेशन नहीं"</string>
+    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"हाल ही के एप्लिकेशन खारिज करें"</string>
   <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 हाल ही का एप्स"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d हाल ही के एप्स"</item>
+    <item quantity="one" msgid="5854176083865845541">"1 हाल ही का एप्लिकेशन"</item>
+    <item quantity="other" msgid="1040784359794890744">"%d हाल ही के एप्लिकेशन"</item>
   </plurals>
     <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"कोई सूचना नहीं"</string>
     <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"ऑनगोइंग"</string>
@@ -40,18 +40,18 @@
     <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"सेटिंग"</string>
     <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
     <string name="status_bar_settings_airplane" msgid="4879879698500955300">"हवाई जहाज मोड"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"स्‍क्रीन अपनेआप घुमाएं"</string>
+    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"स्‍क्रीन स्‍वत: घुमाएं"</string>
     <string name="status_bar_settings_mute_label" msgid="554682549917429396">"म्यूट करें"</string>
     <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"स्वत:"</string>
     <string name="status_bar_settings_notifications" msgid="397146176280905137">"सूचनाएं"</string>
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth टीदर किया गया"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"इनपुट पद्धति सेट करें"</string>
     <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"भौतिक कीबोर्ड"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"एप्स <xliff:g id="APPLICATION">%1$s</xliff:g> को USB उपकरण तक पहुंचने दें?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"एप्स <xliff:g id="APPLICATION">%1$s</xliff:g> को USB सहायक उपकरण तक पहुंचने दें?"</string>
+    <string name="usb_device_permission_prompt" msgid="834698001271562057">"एप्लिकेशन <xliff:g id="APPLICATION">%1$s</xliff:g> को USB उपकरण तक पहुंचने दें?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"एप्लिकेशन <xliff:g id="APPLICATION">%1$s</xliff:g> को USB सहायक उपकरण तक पहुंचने दें?"</string>
     <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"जब यह USB उपकरण कनेक्ट किया जाए, तब <xliff:g id="ACTIVITY">%1$s</xliff:g> को खोलें?"</string>
     <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"जब यह USB एसेसरी कनेक्ट की जाए, तब <xliff:g id="ACTIVITY">%1$s</xliff:g> को खोलें?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"इस USB सहायक उपकरण के साथ कोई भी इंस्टॉल एप्स काम नहीं करता. इस सहायक उपकरण के बारे में यहां अधिक जानें: <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"इस USB सहायक उपकरण के साथ कोई भी इंस्टॉल एप्लिकेशन काम नहीं करता. इस सहायक उपकरण के बारे में यहां अधिक जानें: <xliff:g id="URL">%1$s</xliff:g>"</string>
     <string name="title_usb_accessory" msgid="4966265263465181372">"USB सहायक साधन"</string>
     <string name="label_view" msgid="6304565553218192990">"देखें"</string>
     <string name="always_use_device" msgid="1450287437017315906">"इस USB उपकरण के लिए डिफ़ॉल्‍ट रूप से उपयोग करें"</string>
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"इस कंप्यूटर से हमेशा अनुमति दें"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"स्‍क्रीन भरने हेतु ज़ूम करें"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"स्‍क्रीन को भरने के लिए खींचें"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"संगतता ज़ूम"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"जब किसी छोटी स्‍क्रीन के लिए एप्‍लिकेशन को डिज़ाइन किया जाता है, तो ज़ूम नियंत्रण क्लॉक के पास दिखाई देगा."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"स्क्रीनशॉट सहेजा जा रहा है..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"स्क्रीनशॉट सहेजा जा रहा है..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"स्क्रीनशॉट सहेजा जा रहा है."</string>
@@ -75,9 +77,7 @@
     <string name="accessibility_back" msgid="567011538994429120">"वापस जाएं"</string>
     <string name="accessibility_home" msgid="8217216074895377641">"होम"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"मेनू"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"हाल ही के एप्‍स"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"खोजें"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"कैमरा"</string>
+    <string name="accessibility_recent" msgid="8571350598987952883">"हाल ही के एप्‍लिकेशन"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"इनपुट पद्धति‍ बटन स्विच करें."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"संगतता ज़ूम बटन."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"छोटी से बड़ी स्‍क्रीन पर ज़ूम करें."</string>
@@ -146,7 +146,7 @@
     <string name="accessibility_notification_dismissed" msgid="854211387186306927">"सूचना खारिज की गई."</string>
     <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"सूचना शेड."</string>
     <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"त्वरित सेटिंग."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"हाल ही के एप्‍स."</string>
+    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"हाल ही के एप्‍लिकेशन."</string>
     <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"उपयोगकर्ता <xliff:g id="USER">%s</xliff:g>."</string>
     <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
     <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"मोबाइल <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
@@ -164,14 +164,13 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi कनेक्‍ट किया गया"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS को खोजा जा रहा है"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS द्वारा सेट किया गया स्‍थान"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"स्थान अनुरोध सक्रिय"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"सभी सूचनाएं साफ़ करें."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"एप्‍स जानकारी"</string>
+    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"एप्‍लिकेशन जानकारी"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"स्‍क्रीन स्‍वचालित रूप से घूमेगी."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"स्‍क्रीन लैंडस्केप अभिविन्यास में लॉक है."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"स्‍क्रीन पोर्ट्रेट अभिविन्‍यास में लॉक है."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"मिठाई का डिब्बा"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"दिवास्वप्न"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
+    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"ईथरनेट"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"हवाई जहाज़ मोड"</string>
     <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"चार्ज हो रही है, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
@@ -179,7 +178,7 @@
     <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
     <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> उपकरण)"</string>
     <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth बंद"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"स्क्रीन की रोशनी"</string>
+    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"चमक"</string>
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"स्वत: रोटेट"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"रोटेशन लॉक किया गया"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"इनपुट विधि"</string>
@@ -197,7 +196,10 @@
     <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi बंद"</string>
     <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi प्रदर्शन"</string>
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"वायरलेस डिस्प्ले"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"स्क्रीन की रोशनी"</string>
+    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"चमक"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"स्वत:"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"नेटवर्क को\nमॉनीटर किया जा सकता है"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"सूचनाएं यहां दिखाई देती हैं"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"नीचे स्वाइप करके उन तक कभी भी पहुंचें.\nसिस्टम नियंत्रणों के लिए पुन: नीचे स्वाइप करें."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"बार दिखाने के लिए स्क्रीन के किनारे को स्वाइप करें"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"सिस्टम बार दिखाने के लिए स्क्रीन के किनारे से स्वाइप करें"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-hr/strings.xml b/packages/SystemUI/res/values-hr/strings.xml
index 305ebcf..631d549 100644
--- a/packages/SystemUI/res/values-hr/strings.xml
+++ b/packages/SystemUI/res/values-hr/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Uvijek dopusti s ovog računala"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zumiraj i ispuni zaslon"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Rastegni i ispuni zaslon"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Kompatibilno zumiranje"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Kada je aplikacija dizajnirana za manji zaslon, kontrole zumiranja prikazuju se pored sata."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Spremanje snimke zaslona..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Spremanje snimke zaslona..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Spremanje snimke zaslona."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Početna"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Izbornik"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Nedavne aplikacije"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Pretraži"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Fotoaparat"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Gumb za promjenu načina unosa."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Gumb za kompatibilnost zumiranja."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zumiranje manjeg zaslona na veći."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi povezan"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Traženje GPS-a"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokaciju utvrdio GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Zahtjevi za lokaciju aktivni su"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Brisanje svih obavijesti."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informacije o aplikaciji"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Zaslon će se automatski zakrenuti."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Zaslon je zaključan u pejzažnoj orijentaciji."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Zaslon je zaključan u portretnoj orijentaciji."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Izlog za slastice"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Sanjarenje"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Način rada u zrakoplovu"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Bežični prikaz"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Svjetlina"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATSKI"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Mreža se\nmožda prati"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Obavijesti se prikazuju ovdje"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Pristupite im u bilo kojem trenutku tako da prstom trznete prema dolje. \nPonovo prstom trznite prema dolje za kontrole sustava."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Prijeđite prstom po rubu zaslona da bi se prikazala traka"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Prijeđite prstom od ruba zaslona da bi se prikazala traka sustava"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-hu/strings.xml b/packages/SystemUI/res/values-hu/strings.xml
index 2127b7e..c1c9136 100644
--- a/packages/SystemUI/res/values-hu/strings.xml
+++ b/packages/SystemUI/res/values-hu/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Mindig engedélyezze erről a számítógépről"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Nagyítás a kitöltéshez"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Nyújtás kitöltéshez"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Kompatibilitás -- nagyítás/kicsinyítés"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Ha egy alkalmazást kisebb képernyőre terveztek, akkor a nagyítás/kicsinyítés vezérlője az óra mellett jelenik meg."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Képernyőkép mentése..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Képernyőkép mentése..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Képernyőkép mentése."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Főoldal"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menü"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Legújabb alkalmazás"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Keresés"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Beviteli mód váltása gomb."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Kompatibilitási zoom gomb."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Kicsinyítsen a nagyobb képernyőhöz."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi csatlakoztatva"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS keresése"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"A GPS beállította a helyet"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktív helylekérések"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Minden értesítés törlése"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Alkalmazásinformáció"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"A képernyő automatikusan forogni fog."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"A képernyő zárolva van fekvő tájolásban."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"A képernyő zárolva van álló tájolásban."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Álmodozás"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Repülőgép üzemmód"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Vezeték nélküli kijelző"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Fényerő"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"automatikus"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Lehet, hogy a\nhálózat felügyelt"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Az értesítések itt jelennek meg."</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Bármikor elérheti őket, ha lefelé húzza az ujját.\nHúzza le az ujját még egyszer a rendszerbeállítások eléréséhez."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Csúsztassa ujját a képernyő szélén a sáv megjelenítéséhez"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Csúsztassa ujját a képernyő szélétől a rendszersáv megjelenítéséhez"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-hy-rAM-land/strings.xml b/packages/SystemUI/res/values-hy-rAM-land/strings.xml
deleted file mode 100644
index 7c0535c..0000000
--- a/packages/SystemUI/res/values-hy-rAM-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"Էկրանն այժմ կողպված է հորիզոնական դիրքավորման մեջ:"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-hy-rAM/strings.xml b/packages/SystemUI/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 7b38bf4..0000000
--- a/packages/SystemUI/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Համակարգային UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Մաքրել"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Հեռացնել ցանկից"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Տեղեկություններ ծրագրի մասին"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Թարմ հավելվածներ չկան"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Անտեսել վերջին ծրագրերը"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 նոր ծրագիր"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d նոր ծրագիր"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Ծանուցումներ չկան"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Ընթացիկ"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Ծանուցումներ"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Միացրեք լիցքավորիչը"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Մարտկոցը լիցքաթափվում է:"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"մնում է <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB լիցքավորումը չի աջակցվում:\nՕգտվեք միայն գործող լիցքավորիչից:"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Մարտկոցի օգտագործումը"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Կարգավորումներ"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Ինքնապտտվող էկրան"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"Համրեցնել"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"Ինքնաշխատ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Ծանուցումներ"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth-ը կապված է"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Կարգավորել մուտքագրման եղանակները"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Ֆիզիկական ստեղնաշար"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Թույլատրե՞լ <xliff:g id="APPLICATION">%1$s</xliff:g> հավելվածի մուտքը USB սարք:"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Թույլատրե՞լ, որ <xliff:g id="APPLICATION">%1$s</xliff:g> հավելվածը մուտք գործի USB լրասարք:"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Բացե՞լ <xliff:g id="ACTIVITY">%1$s</xliff:g>-ը, երբ այս USB կրիչը կապակցված է:"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Բացե՞լ <xliff:g id="ACTIVITY">%1$s</xliff:g>-ը, երբ այս USB լրասարքը կապակցված է:"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Այս USB լրասարքի հետ ոչ մի հավելված չի աշխատում: Իմացեք ավելին այս լրասարքի մասին <xliff:g id="URL">%1$s</xliff:g>-ում"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB լրասարք"</string>
-    <string name="label_view" msgid="6304565553218192990">"Դիտել"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Օգտագործել լռելյայն այս USB սարքի համար"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Օգտագործել լռելյայն այս USB լրասարքի համար"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"Թույլատրե՞լ USB-ի կարգաբերումը:"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Համակարգչի RSA-ի բանալի մատնահետքն է`\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Միշտ թույլատրել այս համակարգչից"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Խոշորացնել` էկրանը լցնելու համար"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Ձգել` էկրանը լցնելու համար"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Պահում է էկրանի հանույթը…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Պահում է էկրանի հանույթը..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Էկրանի հանույթը պահվում է:"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Էկրանի հանույթը լուսանկարվել է:"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Հպեք ձեր էկրանի հանույթը տեսնելու համար:"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Չհաջողվեց լուսանկարել էկրանի հանույթը:"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Չհաջողվեց պահել էկրանի հանույթը: Հնարավոր է` պահոցն օգտագործման մեջ է:"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ֆայլերի փոխանցման ընտրանքներ"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Միացնել որպես մեդիա նվագարկիչ (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Միացնել որպես ֆոտոխցիկ (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Տեղադրել Android ֆայլերի փոխանցման հավելվածը Mac-ի համար"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Հետ"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Տուն"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Ցանկ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Վերջին ծրագրերը"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Որոնել"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Ֆոտոխցիկ"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Միացնել մուտքագրման եղանակի կոճակը:"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Համատեղելիության խոշորացման կոճակը:"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Դիտափոխել փոքրից ավելի մեծ էկրան:"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth-ը միացված է:"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth-ն անջատված է:"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Մարտկոց չկա:"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Մարտկոցի մեկ գիծ:"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Մարտկոցի երկու գիծ:"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Մարտկոցի երեք գիծ:"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Մարտկոցը լիքն է:"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Հեռախոս չկա:"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Հեռախոսի մեկ գիծ:"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Հեռախոսի երկու գիծ:"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Հեռախոսի երեք գիծ:"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Հեռախոսի ազդանշանը լիքն է:"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Տվյալներ չկան:"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Տվյալների մեկ գիծ:"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Տվյալների երկու գիծ:"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Տվյալների երեք գիծ:"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Տվյալների ազդանշանը լրիվ է:"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi-ը անջատված է:"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"WiFi-ը անջատված է:"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi-ի մեկ գիծ:"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi-ի երկու գիծ:"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi-ի երեք գիծ:"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi-ի ազդանշանը լիքն է:"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX չկա:"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX-ի մեկ գիծ:"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX-ի երկու գիծ:"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX-ի երեք գիծ:"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX-ի ազդանշանը լիքն է:"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Ազդանշան չկա:"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Միացված չէ:"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Զրո գիծ:"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Մեկ գիծ:"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Երկու գիծ:"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Երեք գիծ:"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Ազդանշանը լրիվ է:"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Միացված է:"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Անջատված է:"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Միացված է:"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Ռոումինգ"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM չկա:"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth-ը կապվում է:"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Մարտկոցը <xliff:g id="NUMBER">%d</xliff:g> տոկոս է:"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Համակարգի կարգավորումներ:"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Ծանուցումներ:"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Մաքրել ծանուցումը:"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS-ը միացված է:"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS-ի ստացում:"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"Հեռամուտքագրիչը միացված է:"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Զանգի թրթռոց:"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Զանգակը լռեցված է:"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g>-ը անտեսված է:"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Ծանուցումը անտեսվեց:"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Ծանուցումների վահանակ:"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Արագ կարգավորումներ:"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Վերջին հավելվածները:"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Օգտվող <xliff:g id="USER">%s</xliff:g>:"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>: <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Շարժական <xliff:g id="SIGNAL">%1$s</xliff:g>: <xliff:g id="TYPE">%2$s</xliff:g>: <xliff:g id="NETWORK">%3$s</xliff:g>:"</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Մարտկոցը <xliff:g id="STATE">%s</xliff:g> է:"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Ինքնաթիռային ռեժիմը <xliff:g id="STATE">%s</xliff:g> է:"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth-ը <xliff:g id="STATE">%s</xliff:g> է:"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Զարթուցիչը դրված է <xliff:g id="TIME">%s</xliff:g>-ին:"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Շարժական տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Դուք հասել եք նշված տվյալների օգտագործման սահմանին:\n\n Եթե դուք կրկին ակտիվացնեք տվյալները, այն կարող է գանձվել օպերատորի կողմից:"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Վերամիացնել տվյալները"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Ինտերնետ կապ չկա"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi-ը միացված է"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"Որոնում է GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Տեղադրությունը կարգավորվել է GPS-ի կողմից"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Տեղադրության հարցումներն ակտիվ են"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Մաքրել բոլոր ծանուցումները:"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Տեղեկություններ ծրագրի մասին"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Էկրանը ինքնուրույն կպտտվի:"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Էկրանը կողպված է հորիզոնական դիրքավորման մեջ:"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Էկրանը կողպված է ուղղաձիգ դիրքավորմամբ:"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Ցերեկային ռեժիմ"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Լիցքավորում` <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Լիցքավորված է"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> սարք)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth-ն անջատված է"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Պայծառություն"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Ինքնապտտում"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Պտտումը կողպված է"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Մուտքագրման եղանակը"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Տեղադրություն"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Անջատել տեղադրությունը"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Մեդիա սարք"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Միայն արտակարգ իրավիճակների զանգեր"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Կարգավորումներ"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Ժամանակը"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Ես"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Միացված չէ"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Ցանց չկա"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi-ը անջատված է"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi ցուցադրիչ"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Անլար էկրան"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Պայծառություն"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"Ինքնաշխատ"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Ցանցը կարող է\nվերահսկվել"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-hy/strings.xml b/packages/SystemUI/res/values-hy/strings.xml
deleted file mode 100644
index 4241898..0000000
--- a/packages/SystemUI/res/values-hy/strings.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Համակարգային UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Մաքրել"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Հեռացնել ցանկից"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Տեղեկություններ ծրագրի մասին"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Թարմ հավելվածներ չկան"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Անտեսել վերջին ծրագրերը"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 նոր ծրագիր"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d նոր ծրագիր"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Ծանուցումներ չկան"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Ընթացիկ"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Ծանուցումներ"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Միացրեք լիցքավորիչը"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Մարտկոցը լիցքաթափվում է:"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"մնում է <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB լիցքավորումը չի աջակցվում:\nՕգտվեք միայն գործող լիցքավորիչից:"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Մարտկոցի օգտագործումը"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Կարգավորումներ"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Ինքնապտտվող էկրան"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"Համրեցնել"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"Ինքնաշխատ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Ծանուցումներ"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth-ը կապված է"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Կարգավորել մուտքագրման եղանակները"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Ֆիզիկական ստեղնաշար"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Թույլատրե՞լ <xliff:g id="APPLICATION">%1$s</xliff:g> հավելվածի մուտքը USB սարք:"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Թույլատրե՞լ, որ <xliff:g id="APPLICATION">%1$s</xliff:g> հավելվածը մուտք գործի USB լրասարք:"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Բացե՞լ <xliff:g id="ACTIVITY">%1$s</xliff:g>-ը, երբ այս USB կրիչը կապակցված է:"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Բացե՞լ <xliff:g id="ACTIVITY">%1$s</xliff:g>-ը, երբ այս USB լրասարքը կապակցված է:"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Այս USB լրասարքի հետ ոչ մի հավելված չի աշխատում: Իմացեք ավելին այս լրասարքի մասին <xliff:g id="URL">%1$s</xliff:g>-ում"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB լրասարք"</string>
-    <string name="label_view" msgid="6304565553218192990">"Դիտել"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Օգտագործել լռելյայն այս USB սարքի համար"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Օգտագործել լռելյայն այս USB լրասարքի համար"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"Թույլատրե՞լ USB-ի կարգաբերումը:"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Համակարգչի RSA-ի բանալի մատնահետքն է`\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Միշտ թույլատրել այս համակարգչից"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Խոշորացնել` էկրանը լցնելու համար"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Ձգել` էկրանը լցնելու համար"</string>
-    <string name="compat_mode_help_header" msgid="7969493989397529910">"Համատեղելիության խոշորացում"</string>
-    <string name="compat_mode_help_body" msgid="4946726776359270040">"Երբ հավելվածը նախագծված է ավելի փոքր էկրանի համար, խոշորացման կարգավորիչը կհայտնվի ժամացույցի կողքին:"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Պահում է էկրանի հանույթը…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Պահում է էկրանի հանույթը..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Էկրանի հանույթը պահվում է:"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Էկրանի հանույթը լուսանկարվել է:"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Հպեք ձեր էկրանի հանույթը տեսնելու համար:"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Չհաջողվեց լուսանկարել էկրանի հանույթը:"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Չհաջողվեց պահել էկրանի հանույթը: Հնարավոր է` պահոցն օգտագործման մեջ է:"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ֆայլերի փոխանցման ընտրանքներ"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Միացնել որպես մեդիա նվագարկիչ (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Միացնել որպես ֆոտոխցիկ (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Տեղադրել Android ֆայլերի փոխանցման հավելվածը Mac-ի համար"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Հետ"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Տուն"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Ցանկ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Վերջին ծրագրերը"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Միացնել մուտքագրման եղանակի կոճակը:"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Համատեղելիության խոշորացման կոճակը:"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Դիտափոխել փոքրից ավելի մեծ էկրան:"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth-ը միացված է:"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth-ն անջատված է:"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Մարտկոց չկա:"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Մարտկոցի մեկ գիծ:"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Մարտկոցի երկու գիծ:"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Մարտկոցի երեք գիծ:"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Մարտկոցը լիքն է:"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Հեռախոս չկա:"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Հեռախոսի մեկ գիծ:"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Հեռախոսի երկու գիծ:"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Հեռախոսի երեք գիծ:"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Հեռախոսի ազդանշանը լիքն է:"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Տվյալներ չկան:"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Տվյալների մեկ գիծ:"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Տվյալների երկու գիծ:"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Տվյալների երեք գիծ:"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Տվյալների ազդանշանը լրիվ է:"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi-ը անջատված է:"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"WiFi-ը անջատված է:"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi-ի մեկ գիծ:"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi-ի երկու գիծ:"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi-ի երեք գիծ:"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi-ի ազդանշանը լիքն է:"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX չկա:"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX-ի մեկ գիծ:"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX-ի երկու գիծ:"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX-ի երեք գիծ:"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX-ի ազդանշանը լիքն է:"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Ազդանշան չկա:"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Միացված չէ:"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Զրո գիծ:"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Մեկ գիծ:"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Երկու գիծ:"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Երեք գիծ:"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Ազդանշանը լրիվ է:"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Միացված է:"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Անջատված է:"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Միացված է:"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Ռոումինգ"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM չկա:"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth-ը կապվում է:"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Մարտկոցը <xliff:g id="NUMBER">%d</xliff:g> տոկոս է:"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Համակարգի կարգավորումներ:"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Ծանուցումներ:"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Մաքրել ծանուցումը:"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS-ը միացված է:"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS-ի ստացում:"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"Հեռամուտքագրիչը միացված է:"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Զանգի թրթռոց:"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Զանգակը լռեցված է:"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g>-ը անտեսված է:"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Ծանուցումը անտեսվեց:"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Ծանուցումների վահանակ:"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Արագ կարգավորումներ:"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Վերջին հավելվածները:"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Օգտվող <xliff:g id="USER">%s</xliff:g>:"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>: <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Շարժական <xliff:g id="SIGNAL">%1$s</xliff:g>: <xliff:g id="TYPE">%2$s</xliff:g>: <xliff:g id="NETWORK">%3$s</xliff:g>:"</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Մարտկոցը <xliff:g id="STATE">%s</xliff:g> է:"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Ինքնաթիռային ռեժիմը <xliff:g id="STATE">%s</xliff:g> է:"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth-ը <xliff:g id="STATE">%s</xliff:g> է:"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Զարթուցիչը դրված է <xliff:g id="TIME">%s</xliff:g>-ին:"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Շարժական տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Տվյալները անջատված են"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Դուք հասել եք նշված տվյալների օգտագործման սահմանին:\n\n Եթե դուք կրկին ակտիվացնեք տվյալները, այն կարող է գանձվել օպերատորի կողմից:"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Վերամիացնել տվյալները"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Ինտերնետ կապ չկա"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi-ը միացված է"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"Որոնում է GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Տեղադրությունը կարգավորվել է GPS-ի կողմից"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Տեղադրության հարցումներն ակտիվ են"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Մաքրել բոլոր ծանուցումները:"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Տեղեկություններ ծրագրի մասին"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Էկրանը ինքնուրույն կպտտվի:"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Էկրանը կողպված է հորիզոնական դիրքավորման մեջ:"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Էկրանը կողպված է ուղղաձիգ դիրքավորմամբ:"</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Ցերեկային ռեժիմ"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Ինքնաթիռային ռեժիմ"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Լիցքավորում` <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Լիցքավորված է"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> սարք)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth-ն անջատված է"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Պայծառություն"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Ինքնապտտում"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Պտտումը կողպված է"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Մուտքագրման եղանակը"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Տեղադրություն"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Անջատել տեղադրությունը"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Մեդիա սարք"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Միայն արտակարգ իրավիճակների զանգեր"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Կարգավորումներ"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Ժամանակը"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Ես"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Միացված չէ"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Ցանց չկա"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi-ը անջատված է"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi ցուցադրիչ"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Անլար էկրան"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Պայծառություն"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"Ինքնաշխատ"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"Ծանուցումները հայտնվում են այստեղ"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"Դրանք մատչեք ցանկացած պահի` սահահարվածելով:\nԿրկին սահահարվածեք ներքև` համակարգային կառավարման համար:"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-in/strings.xml b/packages/SystemUI/res/values-in/strings.xml
index 2b23405..6a702b9 100644
--- a/packages/SystemUI/res/values-in/strings.xml
+++ b/packages/SystemUI/res/values-in/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Selalu izinkan dari komputer ini"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Perbesar utk mengisi layar"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Rentangkn utk mngisi layar"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Perbesar/perkecil untuk kompatibilitas"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Saat apl dirancang untuk layar yang lebih kecil, kontrol zoom akan tampil di dekat jam."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Menyimpan tangkapan layar..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Menyimpan tangkapan layar..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Tangkapan layar sedang disimpan."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Utama"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Apl terbaru"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Telusuri"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Tombol beralih metode masukan."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Tombol perbesar/perkecil kompatibilitas."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Perbesar dari layar kecil ke besar."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi tersambung"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Menelusuri GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokasi yang disetel oleh GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Permintaan lokasi aktif"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Menghapus semua pemberitahuan."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Info aplikasi"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Layar akan diputar secara otomatis."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Layar dikunci dalam orientasi lanskap."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Layar dikunci dalam orientasi potret."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Etalase Hidangan Penutup"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Lamunan"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Mode pesawat"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Rotasi Otomatis"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotasi Dikunci"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Metode Masukan"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Lokasi"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Lokasi Mati"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Perangkat media"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Panggilan Darurat Saja"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Layar Nirkabel"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Kecerahan"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"OTOMATIS"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Jaringan bisa\ndiawasi"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Pemberitahuan muncul di sini"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Akses kapan saja dengan menggesek ke bawah.\nGesek ke bawah sekali lagi untuk kontrol sistem."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Gesek tepi layar untuk membuka bilah"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Gesek dari bagian tepi layar untuk membuka bilah sistem"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-it/strings.xml b/packages/SystemUI/res/values-it/strings.xml
index d833ec1..a350d38 100644
--- a/packages/SystemUI/res/values-it/strings.xml
+++ b/packages/SystemUI/res/values-it/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Consenti sempre da questo computer"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom per riempire schermo"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Estendi per riemp. schermo"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom compatibilità"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Se un\'applicazione è stata progettata per uno schermo più piccolo, accanto all\'orologio viene visualizzato un controllo dello zoom."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Salvataggio screenshot..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Salvataggio screenshot..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Screenshot in corso di salvataggio."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Home"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Applicazioni recenti"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Cerca"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Fotocamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Pulsante per cambiare metodo di immissione."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Pulsante zoom compatibilità."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom inferiore per schermo più grande."</string>
@@ -116,8 +116,8 @@
     <string name="accessibility_two_bars" msgid="6437363648385206679">"Due barre."</string>
     <string name="accessibility_three_bars" msgid="2648241415119396648">"Tre barre."</string>
     <string name="accessibility_signal_full" msgid="9122922886519676839">"Massimo segnale."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"ON"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"OFF"</string>
+    <string name="accessibility_desc_on" msgid="2385254693624345265">"Attivo."</string>
+    <string name="accessibility_desc_off" msgid="6475508157786853157">"Non attivo."</string>
     <string name="accessibility_desc_connected" msgid="8366256693719499665">"Connesso."</string>
     <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
     <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi connesso"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Ricerca del GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Posizione stabilita dal GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Richieste di accesso alla posizione attive"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Cancella tutte le notifiche."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informazioni applicazione"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Lo schermo ruoterà automaticamente."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Lo schermo è bloccato in orientamento orizzontale."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Lo schermo è bloccato in orientamento verticale."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Vetrina di dolci"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Modalità aereo"</string>
@@ -185,7 +184,7 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Rotazione autom."</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotazione bloccata"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Metodo di immissione"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Geolocalizzazione"</string>
+    <string name="quick_settings_location_label" msgid="5011327048748762257">"Posizione"</string>
     <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Posizione non attiva"</string>
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Dispositivo multimediale"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
@@ -201,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Visualizzazione wireless"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Luminosità"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"La rete potrebbe\nessere monitorata"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Le notifiche vengono visualizzate qui"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Puoi accedervi in qualsiasi momento scorrendo verso il basso.\nFai scorrere di nuovo verso il basso per visualizzare i controlli del sistema."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Fai scorrere il bordo dello schermo per visualizzare la barra"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Fai scorrere il dito dal bordo dello schermo per visualizzare la barra di sistema"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-iw/strings.xml b/packages/SystemUI/res/values-iw/strings.xml
index 7dd99b6..b274dcc 100644
--- a/packages/SystemUI/res/values-iw/strings.xml
+++ b/packages/SystemUI/res/values-iw/strings.xml
@@ -22,12 +22,12 @@
     <string name="app_label" msgid="7164937344850004466">"ממשק משתמש של המערכת"</string>
     <string name="status_bar_clear_all_button" msgid="7774721344716731603">"נקה"</string>
     <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"הסר מהרשימה"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"פרטי אפליקציה"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"אין אפליקציות אחרונות"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"סגור אפליקציות אחרונות"</string>
+    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"פרטי יישום"</string>
+    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"אין יישומים אחרונים"</string>
+    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"סגור יישומים אחרונים"</string>
   <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"אפליקציה אחרונה אחת"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d האפליקציות האחרונות"</item>
+    <item quantity="one" msgid="5854176083865845541">"יישום אחרון אחד"</item>
+    <item quantity="other" msgid="1040784359794890744">"%d היישומים האחרונים"</item>
   </plurals>
     <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"אין התראות"</string>
     <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"מתמשך"</string>
@@ -47,11 +47,11 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth קשור"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"הגדר שיטות קלט"</string>
     <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"מקלדת פיזית"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"לאפשר לאפליקציה <xliff:g id="APPLICATION">%1$s</xliff:g> גישה להתקן ה-USB?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"לאפשר לאפליקציה <xliff:g id="APPLICATION">%1$s</xliff:g> גישה לאביזר ה-USB?"</string>
+    <string name="usb_device_permission_prompt" msgid="834698001271562057">"לאפשר ליישום <xliff:g id="APPLICATION">%1$s</xliff:g> גישה להתקן ה-USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"לאפשר ליישום <xliff:g id="APPLICATION">%1$s</xliff:g> גישה לאביזר ה-USB?"</string>
     <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"האם לפתוח את <xliff:g id="ACTIVITY">%1$s</xliff:g> כאשר מכשיר USB זה מחובר?"</string>
     <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"האם לפתוח את <xliff:g id="ACTIVITY">%1$s</xliff:g> כאשר אביזר USB זה מחובר?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"אין אפליקציות מותקנות הפועלות עם אביזר ה-USB. למידע נוסף על אביזר זה בקר בכתובת <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"אין יישומים מותקנים הפועלים עם אביזר ה-USB. למידע נוסף על אביזר זה בקר בכתובת <xliff:g id="URL">%1$s</xliff:g>"</string>
     <string name="title_usb_accessory" msgid="4966265263465181372">"אביזר USB"</string>
     <string name="label_view" msgid="6304565553218192990">"הצג"</string>
     <string name="always_use_device" msgid="1450287437017315906">"השתמש כברירת מחדל עבור מכשיר USB זה"</string>
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"אפשר תמיד ממחשב זה"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"הגדל תצוגה כדי למלא את המסך"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"מתח כדי למלא את המסך"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"שינוי מרחק מתצוגה לצורך תאימות"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"כאשר יישום מיועד למסך קטן יותר, פקד של מרחק מתצוגה יופיע ליד השעון."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"שומר צילום מסך..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"שומר צילום מסך..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"מתבצעת שמירה של צילום המסך."</string>
@@ -71,13 +73,11 @@
     <string name="usb_preference_title" msgid="6551050377388882787">"אפשרויות העברת קבצים ב-USB"</string>
     <string name="use_mtp_button_title" msgid="4333504413563023626">"טען כנגן מדיה (MTP)"</string>
     <string name="use_ptp_button_title" msgid="7517127540301625751">"טען כמצלמה (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"התקן את אפליקציית העברת הקבצים של Android עבור Mac"</string>
+    <string name="installer_cd_button_title" msgid="2312667578562201583">"התקן את יישום העברת הקבצים של Android עבור Mac"</string>
     <string name="accessibility_back" msgid="567011538994429120">"הקודם"</string>
     <string name="accessibility_home" msgid="8217216074895377641">"בית"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"תפריט"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"אפליקציות אחרונות"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"חפש"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"מצלמה"</string>
+    <string name="accessibility_recent" msgid="8571350598987952883">"יישומים אחרונים"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"לחצן החלפת שיטת קלט."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"לחצן מרחק מתצוגה של תאימות."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"שנה מרחק מתצוגה של מסך קטן לגדול יותר."</string>
@@ -146,7 +146,7 @@
     <string name="accessibility_notification_dismissed" msgid="854211387186306927">"הודעה נדחתה."</string>
     <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"תריס התראות."</string>
     <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"הגדרות מהירות."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"אפליקציות אחרונות"</string>
+    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"יישומים אחרונים"</string>
     <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"משתמש <xliff:g id="USER">%s</xliff:g>."</string>
     <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>‏. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
     <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"נייד <xliff:g id="SIGNAL">%1$s</xliff:g>.‏ <xliff:g id="TYPE">%2$s</xliff:g>.‏ <xliff:g id="NETWORK">%3$s</xliff:g>.‏"</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi מחובר"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"מחפש GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"מיקום מוגדר על ידי GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"בקשות מיקום פעילות"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"נקה את כל ההתראות."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"פרטי אפליקציה"</string>
+    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"פרטי יישום"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"המסך יסתובב באופן אוטומטי."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"המסך נעול כעת לרוחב."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"המסך נעול כעת לאורך."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"מזנון קינוחים"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"חלום בהקיץ"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"מצב טיסה"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"תצוגת Wi-Fi"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"בהירות"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"אוטומטי"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"ייתכן שהרשת\nמנוטרת"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"הודעות מופיעות כאן"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"גש אליהם בכל עת על ידי החלקה למטה.\nהחלק למטה שוב למעבר למרכז הבקרה של המערכת."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"החלק מקצה המסך כדי להציג את הסרגל"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"החלק מקצה המסך כדי להציג את סרגל המערכת"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ja/strings.xml b/packages/SystemUI/res/values-ja/strings.xml
index 725d599..7392ae9 100644
--- a/packages/SystemUI/res/values-ja/strings.xml
+++ b/packages/SystemUI/res/values-ja/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"このパソコンからのUSBデバッグを常に許可する"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"画面サイズに合わせて拡大"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"画面サイズに合わせて拡大"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"互換ズーム"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"より小型の画面向けのアプリの場合は、ズームコントロールが時計のそばに表示されます。"</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"スクリーンショットを保存中..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"スクリーンショットを保存しています..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"スクリーンショットを保存しています。"</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"ホーム"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"メニュー"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"最近使ったアプリ"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"検索"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"カメラ"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"入力方法の切り替えボタン。"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"互換ズームボタン。"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"小さい画面から大きい画面に拡大。"</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi接続済み"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPSで検索中"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPSにより現在地が設定されました"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"現在地リクエストがアクティブ"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"通知をすべて消去。"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"アプリ情報"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"画面は自動的に回転します。"</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"画面は横向きにロックされています。"</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"画面は縦向きにロックされています。"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"デザートケース"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"スクリーンセーバー"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"イーサネット"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"機内モード"</string>
@@ -201,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"ワイヤレスディスプレイ"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"画面の明るさ"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"自動"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"ネットワークが監視される\n場合があります"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"ここに通知が表示されます"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"下にスワイプすると、いつでも通知を表示できます。\nシステムを管理するにはもう一度下にスワイプしてください。"</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"バーを表示するには、画面の端からスワイプします"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"システムバーを表示するには、画面の端からスワイプします"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ka-rGE-land/strings.xml b/packages/SystemUI/res/values-ka-rGE-land/strings.xml
deleted file mode 100644
index 3f20938..0000000
--- a/packages/SystemUI/res/values-ka-rGE-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"ეკრანი ამჟამად დაბლოკილია თარაზულ ორიენტაციაში"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ka-rGE/strings.xml b/packages/SystemUI/res/values-ka-rGE/strings.xml
deleted file mode 100644
index a3d98b7..0000000
--- a/packages/SystemUI/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"სისტემის UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"გასუფთავება"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"სიიდან ამოშლა"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"აპის შესახებ"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"ბოლოს გამოყენებული აპების სია ცარიელია"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"ბოლო აპების გაუქმება"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 ბოლო აპი"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d ბოლო აპი"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"შეტყობინებები არ არის."</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"მიმდინარე"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"შეტყობინებები"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"შეაერთეთ დამტენი."</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ბატარეა ჯდება."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"დარჩენილია <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB-ით დატენვა არ არის მხარდაჭერილი.\nგამოიყენეთ მხოლოდ ელექტრო-დამტენი."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ელემენტის გამოყენება"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"პარამეტრები"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"თვითმფრინავის რეჟიმი"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"ავტოროტაციის ეკრანი"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"დადუმება"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ავტო."</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"შეტყობინებები"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth მიერთებულია."</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"შეყვანის მეთოდების დაყენება"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"ფიზიკური კლავიატურა"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"გსურთ, მისცეთ აპლიკაციას „<xliff:g id="APPLICATION">%1$s</xliff:g>“ USB მეხსიერებასთან წვდომის უფლება?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"გსურთ, მისცეთ აპლიკაციას „<xliff:g id="APPLICATION">%1$s</xliff:g>“ USB აქსესუართან წვდომის უფლება?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"გსურთ <xliff:g id="ACTIVITY">%1$s</xliff:g> , როდესაც ეს USB მოწყობილობა შეერთებულია?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"გსურთ <xliff:g id="ACTIVITY">%1$s</xliff:g> , როდესაც ეს USB მოწყობილობა შეერთებულია?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"არცერთი დაყენებული აპი არ მუშაობს ამ USB აქსესუართან. შეიტყვეთ მეტი ამ აქსესუარის შესახებ <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB აქსესუარი"</string>
-    <string name="label_view" msgid="6304565553218192990">"ნახვა"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"ამ USB მოწყობილობის ნაგულისხმევად გამოყენება"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"ავტომატურად გამოიყენე ამ USB აქსესუარისთვის."</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"გააქტიურდეს USB გამართვა?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"კომპიუტერის RSA გასაღების თითის ანაბეჭდია:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"ყოველთვის დართე ნება ამ კომპიუტერიდან."</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"მასშტაბი შეცვალეთ ეკრანის შესავსებად."</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"გაწიეთ ეკრანის შესავსებად."</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"სკრინშოტის შენახვა…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"ეკრანის სურათის შენახვა…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"ეკრანის სურათი შენახულია."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"სკრინშოტი გადაღებულია."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"შეეხეთ ეკრანის სურათის სანახავად."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"ვერ მოხერხდა ეკრანის ანაბეჭდის გადაღება."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"ეკრანის სურათი ვერ შეინახა. შესაძლოა, მეხსიერება უკვე დაკავებულია."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ფაილის ტრანსფერის პარამეტრები"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"მედია-საკრავად (MTP) ჩართვა"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"მიუერთეთ როგორც კამერა (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Android File Transfer აპის დაყენება Mac-თვის"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"უკან"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"საწყისი"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"მენიუ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"ბოლოს გამოყენებული აპები"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"ძიება"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"კამერა"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"შეყვანის მეთოდის გადართვის ღილაკი."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"თავსებადი მასშტაბირების ღილაკი."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"შეცვალეთ პატარა ეკრანი უფრო დიდით."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth დაკავშირებულია."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth კავშირი გაწყვეტილია."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"ბატარეა დამჯდარია."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ბატარეია ერთ ზოლზეა."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ელემენტი ორ ზოლზე."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ელემენტი სამ ზოლზე."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ელემენტი სავსეა."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"ტელეფონი არ არის."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"ტელეფონის სიგნალი ერთ ზოლზეა."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"ტელეფონის სიგნალი ორ ზოლზეა."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"ტელეფონის სიგნალი სამ ზოლზეა."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"ტელეფონის სიგნალი სრულია."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"მონაცემები არ არის."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"თარიღი ზოლზე."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"მონაცემების გადაცემა: ორი ზოლი"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"მონაცემების გადაცემა: სამი ზოლი"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"მონაცემთა გადაცემის საიმედო სიგნალი."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi გამორთულია."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi არ არის დაკავშირებული."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi სიგნალი ერთ ზოლზეა."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi სიგნალი ორ ზოლზეა."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi სამი ზოლი."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi სიგნალი სრულია."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX არ არის."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX ერთი სვეტი."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX-ის ორი ზოლი."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX-ის სამი ზოლი."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX სიგნალი სრულია."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"სიგნალი არ არის."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"არ არის დაკავშირებული."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"სიგნალი ნულ ზოლზეა."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"ერთი ზოლი."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"ორი სვეტი."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"სამი ზოლი."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"სრული სიგნალი."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"ჩართული"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"გამორთულია."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"დაკავშირებულია."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5გბ"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"როუმინგი"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM არ არის."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth-ის ჩართვა"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"თვითმფრინავის რეჟიმი"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ბატარეა: <xliff:g id="NUMBER">%d</xliff:g> პროცენტი."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"სისტემის პარამეტრები."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"შეტყობინებები"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"შეტყობინებების გასუფთავება."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS გააქტიურდა."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS-ის დადგენა."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"ტელეტაიპი ჩართულია."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"ვიბრაციის რეჟიმი."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"უხმო რეჟიმი."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> ამოშლილია სიიდან."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"შეტყობინება წაიშალა."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"შეტყობინებების ფარდა"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"სწრაფი პარამეტრები"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"ბოლო აპები."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"მომხმარებელი: <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"მობილურის <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ელემენტი: <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"თვითმფრინავის რეჟიმი <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"მაღვიძარა დაყენებულია: <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G მონაცემები გათიშულია"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"მობილური ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"თქვენ მიაღწიეთ ინტერნეტის გამოყენების განსაზღვრულ ლიმიტს.\n\nთუ გააქტიურებთ ინტერნეტს, შესაძლოა მობილური ოპერატორისთვის დამატებითი თანხის გადახდა მოგიწიოთ."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"მონაცემების ხელახლა ჩართვა"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"ინტერნეტ კავშირი არ არის"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi დაკავშირებულია"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS-ის ძებნა"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS-ით დადგენილი მდებარეობა"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"მდებარეობის მოთხოვნები აქტიურია"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"ყველა შეტყობინების წაშლა"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"აპის შესახებ"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"ეკრანი შეტრიალდება ავტომატურად."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"ეკრანი დაბლოკილია თარაზულ ორიენტაციაში"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"ეკრანი დაბლოკილია პორტრეტის ორიენტაციაში."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"სადესერტო ყუთი"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"ეთერნეტი"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"თვითმფრინავის რეჟიმი"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"დამუხტვა, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"დამუხტულია"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> მოწყობილობა)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth გამორთულია"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"სიკაშკაშე"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"ავტო მობრუნება"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"როტაციის ჩაკეტვა"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"შეყვანის მეთოდი"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"მდებარეობა"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"მდებარეობა გამორთულია"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"მედია მოწყობილობა"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"მხოლოდ გადაუდებელი დახმარების ზარებისთვის"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"პარამეტრები"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"დრო"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"მე"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"არ არის დაკავშირებული."</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"ქსელი არ არის"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi გამორთულია"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi ეკრანი"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"უსადენო ეკრანი"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"განათება"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ავტომატურად"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"შესაძლოა ქსელზე\nმონიტორინგი ხორციელდებოდეს"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ka/strings.xml b/packages/SystemUI/res/values-ka/strings.xml
deleted file mode 100644
index bcbe4de..0000000
--- a/packages/SystemUI/res/values-ka/strings.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"სისტემის UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"გასუფთავება"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"სიიდან ამოშლა"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"აპის შესახებ"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"ბოლოს გამოყენებული აპების სია ცარიელია"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"ბოლო აპების გაუქმება"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 ბოლო აპი"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d ბოლო აპი"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"შეტყობინებები არ არის."</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"მიმდინარე"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"შეტყობინებები"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"შეაერთეთ დამტენი."</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ბატარეა ჯდება."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"დარჩენილია <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB-ით დატენვა არ არის მხარდაჭერილი.\nგამოიყენეთ მხოლოდ ელექტრო-დამტენი."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ელემენტის გამოყენება"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"პარამეტრები"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"თვითმფრინავის რეჟიმი"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"ავტოროტაციის ეკრანი"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"დადუმება"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ავტომატური"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"შეტყობინებები"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth მიერთებულია."</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"შეყვანის მეთოდების დაყენება"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"ფიზიკური კლავიატურა"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"გსურთ, მისცეთ აპლიკაციას „<xliff:g id="APPLICATION">%1$s</xliff:g>“ USB მეხსიერებასთან წვდომის უფლება?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"გსურთ, მისცეთ აპლიკაციას „<xliff:g id="APPLICATION">%1$s</xliff:g>“ USB აქსესუართან წვდომის უფლება?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"გსურთ <xliff:g id="ACTIVITY">%1$s</xliff:g> , როდესაც ეს USB მოწყობილობა შეერთებულია?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"გსურთ <xliff:g id="ACTIVITY">%1$s</xliff:g> , როდესაც ეს USB მოწყობილობა შეერთებულია?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"არცერთი დაყენებული აპი არ მუშაობს ამ USB აქსესუართან. შეიტყვეთ მეტი ამ აქსესუარის შესახებ <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB აქსესუარი"</string>
-    <string name="label_view" msgid="6304565553218192990">"ნახვა"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"ამ USB მოწყობილობის ნაგულისხმევად გამოყენება"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"ავტომატურად გამოიყენე ამ USB აქსესუარისთვის."</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"გააქტიურდეს USB გამართვა?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"კომპიუტერის RSA გასაღების თითის ანაბეჭდია:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"ყოველთვის დართე ნება ამ კომპიუტერიდან."</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"მასშტაბი შეცვალეთ ეკრანის შესავსებად."</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"გაწიეთ ეკრანის შესავსებად."</string>
-    <string name="compat_mode_help_header" msgid="7969493989397529910">"თავსებადობის მასშტაბი"</string>
-    <string name="compat_mode_help_body" msgid="4946726776359270040">"თუ აპი გათვლილია მცირე ეკრანისთვის, საათის გვერდით გაჩნდება მასშტაბის მართვის ელემენტი."</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"სკრინშოტის შენახვა…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"ეკრანის სურათის შენახვა…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"ეკრანის სურათი შენახულია."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"სკრინშოტი გადაღებულია."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"შეეხეთ ეკრანის სურათის სანახავად."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"ვერ მოხერხდა ეკრანის ანაბეჭდის გადაღება."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"ეკრანის სურათი ვერ შეინახა. შესაძლოა, მეხსიერება უკვე დაკავებულია."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ფაილის ტრანსფერის პარამეტრები"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"მედია-საკრავად (MTP) ჩართვა"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"მიუერთეთ როგორც კამერა (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Android File Transfer აპის დაყენება Mac-თვის"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"უკან"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"საწყისი"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"მენიუ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"ბოლოს გამოყენებული აპები"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"შეყვანის მეთოდის გადართვის ღილაკი."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"თავსებადი მასშტაბირების ღილაკი."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"შეცვალეთ პატარა ეკრანი უფრო დიდით."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth დაკავშირებულია."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth კავშირი გაწყვეტილია."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"ბატარეა დამჯდარია."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ბატარეია ერთ ზოლზეა."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ელემენტი ორ ზოლზე."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ელემენტი სამ ზოლზე."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ელემენტი სავსეა."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"ტელეფონი არ არის."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"ტელეფონის სიგნალი ერთ ზოლზეა."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"ტელეფონის სიგნალი ორ ზოლზეა."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"ტელეფონის სიგნალი სამ ზოლზეა."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"ტელეფონის სიგნალი სრულია."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"მონაცემები არ არის."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"თარიღი ზოლზე."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"მონაცემების გადაცემა: ორი ზოლი"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"მონაცემების გადაცემა: სამი ზოლი"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"მონაცემთა გადაცემის საიმედო სიგნალი."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi გამორთულია."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi არ არის დაკავშირებული."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi სიგნალი ერთ ზოლზეა."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi სიგნალი ორ ზოლზეა."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi სამი ზოლი."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi სიგნალი სრულია."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX არ არის."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX ერთი სვეტი."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX-ის ორი ზოლი."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX-ის სამი ზოლი."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX სიგნალი სრულია."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"სიგნალი არ არის."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"არ არის დაკავშირებული."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"სიგნალი ნულ ზოლზეა."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"ერთი ზოლი."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"ორი სვეტი."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"სამი ზოლი."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"სრული სიგნალი."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"ჩართული"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"გამორთულია."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"დაკავშირებულია."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5გბ"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"როუმინგი"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM არ არის."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Bluetooth-ის ჩართვა"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"თვითმფრინავის რეჟიმი"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ბატარეა: <xliff:g id="NUMBER">%d</xliff:g> პროცენტი."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"სისტემის პარამეტრები."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"შეტყობინებები"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"შეტყობინებების გასუფთავება."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS გააქტიურდა."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS-ის დადგენა."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"ტელეტაიპი ჩართულია."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"ვიბრაციის რეჟიმი."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"უხმო რეჟიმი."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> ამოშლილია სიიდან."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"შეტყობინება წაიშალა."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"შეტყობინებების ფარდა"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"სწრაფი პარამეტრები"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"ბოლო აპები."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"მომხმარებელი: <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"მობილურის <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ელემენტი: <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"თვითმფრინავის რეჟიმი <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"მაღვიძარა დაყენებულია: <xliff:g id="TIME">%s</xliff:g>"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G მონაცემები გათიშულია"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"მობილური ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"ინტერნეტი გაითიშა."</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"თქვენ მიაღწიეთ ინტერნეტის გამოყენების განსაზღვრულ ლიმიტს.\n\nთუ გააქტიურებთ ინტერნეტს, შესაძლოა მობილური ოპერატორისთვის დამატებითი თანხის გადახდა მოგიწიოთ."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"მონაცემების ხელახლა ჩართვა"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"ინტერნეტ კავშირი არ არის"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi დაკავშირებულია"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS-ის ძებნა"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS-ით დადგენილი მდებარეობა"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"მდებარეობის მოთხოვნები აქტიურია"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"ყველა შეტყობინების წაშლა"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"აპის შესახებ"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"ეკრანი შეტრიალდება ავტომატურად."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"ეკრანი დაბლოკილია თარაზულ ორიენტაციაში"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"ეკრანი დაბლოკილია პორტრეტის ორიენტაციაში."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"ეთერნეტი"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"თვითმფრინავის რეჟიმი"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"დამუხტვა, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"დამუხტულია"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> მოწყობილობა)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth გამორთულია"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"სიკაშკაშე"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"ავტოროტაცია"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"როტაციის ჩაკეტვა"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"შეყვანის მეთოდი"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"მდებარეობა"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"მდებარეობა გამორთულია"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"მედია მოწყობილობა"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"მხოლოდ გადაუდებელი დახმარების ზარებისთვის"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"პარამეტრები"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"დრო"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"მე"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"არ არის დაკავშირებული."</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"ქსელი არ არის"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi გამორთულია"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi ეკრანი"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"უსადენო ეკრანი"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"განათება"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ავტომატურად"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"შეტყობინებები აქ გამოჩნდება"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"მათზე წვდომისათვის, ნებისმიერ დროს გადაფურცლეთ ქვემოთ.\nსისტემის კონტროლისთვისაც გადაფურცლეთ ქვემოთ."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-km-rKH-land/strings.xml b/packages/SystemUI/res/values-km-rKH-land/strings.xml
deleted file mode 100644
index f148cc3..0000000
--- a/packages/SystemUI/res/values-km-rKH-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"ឥឡូវ​អេក្រង់​​ជាប់​សោ​ក្នុង​ទិស​ផ្ដេក។"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-km-rKH/strings.xml b/packages/SystemUI/res/values-km-rKH/strings.xml
deleted file mode 100644
index 02e641c..0000000
--- a/packages/SystemUI/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"ចំណុច​ប្រទាក់​ប្រព័ន្ធ"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"សម្អាត"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"យក​ចេញ​ពី​បញ្ជី"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"ព័ត៌មាន​កម្មវិធី"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"គ្មាន​កម្មវិធី​ថ្មីៗ"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"បដិសេធ​កម្មវិធី​ថ្មីៗ"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"កម្មវិធី​ថ្មី ១"</item>
-    <item quantity="other" msgid="1040784359794890744">"កម្មវិធី​ថ្មីៗ %d"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"គ្មាន​ការ​ជូន​ដំណឹង"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"បន្ត"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"ការ​ជូន​ដំណឹង"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"ភ្ជាប់​ឧបករណ៍​បញ្ចូល​ថ្ម"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ជិត​អស់​ថ្ម​ហើយ។"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"នៅ​សល់ <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"មិន​គាំទ្រ​ការ​បញ្ចូល​តាម​យូអេសប៊ី។\nប្រើ​តែ​ឧបករណ៍​បញ្ចូល​ថ្ម​ដែល​បាន​ផ្ដល់។"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ការ​ប្រើ​ថ្ម"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"ការ​កំណត់"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"វ៉ាយហ្វាយ"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"ពេល​ជិះ​យន្តហោះ"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"បង្វិល​អេក្រង់​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"ស្ងាត់"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ស្វ័យប្រវត្តិ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"ការ​ជូន​ដំណឹង"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"បាន​ភ្ជាប់​ប៊្លូធូស"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"រៀបចំ​វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"ក្ដារ​ចុច​ពិតប្រាកដ"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"ឲ្យ​កម្មវិធី <xliff:g id="APPLICATION">%1$s</xliff:g> ចូល​ដំណើរការ​ឧបករណ៍​យូអេសប៊ី?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"ឲ្យ​កម្មវិធី <xliff:g id="APPLICATION">%1$s</xliff:g> ចូល​ដំណើរការ​ឧបករណ៍​យូអេសប៊ី?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"បើក <xliff:g id="ACTIVITY">%1$s</xliff:g> ពេល​បាន​ភ្ជាប់​ឧបករណ៍​យូអេសប៊ី​នេះ?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"បើក <xliff:g id="ACTIVITY">%1$s</xliff:g> ពេល​បាន​ភ្ជាប់​ឧបករណ៍​យូអេសប៊ី?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"គ្មាន​កម្មវិធី​បាន​ដំឡើង​ដំណើរការ​ជា​មួយ​ឧបករណ៍​យូអេសប៊ី។ ស្វែងយល់​បន្ថែម​អំពី​ឧបករណ៍​នេះ​នៅ <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"ឧបករណ៍​យូអេសប៊ី"</string>
-    <string name="label_view" msgid="6304565553218192990">"មើល"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"ប្រើ​តាម​លំនាំដើម​សម្រាប់​ឧបករណ៍​យូអេសប៊ី​នេះ"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"ប្រើ​តាម​លំនាំដើម​សម្រាប់​ខ្សែ​យូអេសប៊ី​នេះ"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"អនុញ្ញាត​ការ​កែ​កំហុស​យូអេសប៊ី?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"ស្នាម​ម្រាម​ដៃ​ RSA របស់​កុំព្យូទ័រ​គឺ៖ \n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"អនុញ្ញាត​ជា​និច្ច​សម្រាប់​កុំព្យូទ័រ​នេះ"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"ពង្រីក​​ដើម្បី​ឲ្យ​ពេញ​អេក្រង់"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"ទាញ​ដើម្បី​ឲ្យ​ពេញ​អេក្រង់"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"កំពុង​រក្សាទុក​រូបថត​អេក្រង់…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"កំពុង​រក្សាទុក​រូបថត​អេក្រង់..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"រូបថត​អេក្រង់​កំពុង​ត្រូវ​បាន​រក្សាទុក។"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"បាន​ចាប់​យក​រូបថត​អេក្រង់។"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"ប៉ះ ​ដើម្បី​មើល​រូបថត​អេក្រង់​របស់​អ្នក​។"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"មិន​អាច​ចាប់​យក​រូប​ថត​អេក្រង់​។"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"មិន​អាច​រក្សាទុក​រូបថត​អេក្រង់​។ ឧបករណ៍​ផ្ទុក​អាច​កំពុង​ប្រើ​​។"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"ជម្រើស​ផ្ទេរ​ឯកសារ​តាម​យូអេសប៊ី"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"ភ្ជាប់​ជា​កម្មវិធី​ចាក់​មេឌៀ (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"ភ្ជាប់​ជា​ម៉ាស៊ីន​ថត (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"ដំឡើង​កម្មវិធី​ផ្ទេរ​ឯកសារ Android សម្រាប់ Mac"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"ថយក្រោយ"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"គេហ​ទំព័រ"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"ម៉ឺនុយ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"កម្មវិធី​ថ្មីៗ"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"ស្វែងរក"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"ម៉ាស៊ីន​ថត"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ប្ដូរ​ប៊ូតុង​វិធីសាស្ត្រ​បញ្ចូល។"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ប៊ូតុង​ពង្រីក​ត្រូវ​គ្នា។"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"ពង្រីក/បង្រួម​​អេក្រង់​ពី​​ទៅធំ"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"បាន​តភ្ជាប់​ប៊្លូធូស។"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"បាន​ផ្ដាច់​​ប៊្លូធូស។"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"គ្មាន​ថ្ម។"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ថ្ម​មួយ​កាំ។"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ថ្ម​ពីរ​កាំ។"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ថ្ម​ទាំង​បី​​កាំ​។"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ថ្ម​ពេញ​ហើយ។"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"គ្មាន​ទូរស័ព្ទ។"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"សេវា​ទូរស័ព្ទ​មួយ​កាំ។"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"សេវា​ទូរស័ព្ទ​ពីរ​កាំ។"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"សេវា​ទូរស័ព្ទ​បី​កាំ​។"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"សេវា​ទូរស័ព្ទ​ពេញ។"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"គ្មាន​ទិន្នន័យ​។"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"ទិន្នន័យ​មួយ​​កាំ។"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"ទិន្នន័យ​ពីរ​​កាំ។"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"ទិន្នន័យ​បី​កាំ។"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"សញ្ញា​ទិន្នន័យ​ពេញ។"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"បិទ​វ៉ាយហ្វាយ។"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"បាន​ផ្ដាច់​វ៉ាយហ្វាយ។"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"សញ្ញា​វ៉ាយហ្វាយ​មួយ​កាំ។"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"សេវា​វ៉ាយហ្វាយ​ពីរ​កាំ។"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"វ៉ាយហ្វាយ​បី​កាំ។"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"សញ្ញា​វ៉ាយហ្វាយ​ពេញ។"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"គ្មាន WiMAX ។"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX មួយ​កាំ។"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX ពីរ​កាំ។"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX បី​កាំ។"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"សញ្ញា WiMAX ពេញ។"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"គ្មាន​សញ្ញា។"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"មិន​បាន​តភ្ជាប់​។"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"សូន្យ​កាំ។"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"មួយ​កាំ។"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"ពីរ​កាំ។"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"បី​កាំ។"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"សញ្ញា​ពេញ​​។"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"បើក។"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"បិទ"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"បាន​តភ្ជាប់។"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"រ៉ូ​មីង"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"វ៉ាយហ្វាយ"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"គ្មាន​ស៊ីម​កាត។"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"ការ​ភ្ជាប់​ប៊្លូធូស។"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"របៀប​​ពេលជិះ​យន្តហោះ"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ថ្ម <xliff:g id="NUMBER">%d</xliff:g> ភាគរយ។"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"ការ​កំណត់​ប្រព័ន្ធ​។"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"ការ​ជូន​ដំណឹង។"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"សម្អាត​ការ​ជូន​ដំណឹង។"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"បាន​បើក GPS ។"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"ទទួល​​ GPS ។"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"បាន​បើក​ម៉ាស៊ីន​អង្គុលីលេខ"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"កម្មវិធី​រោទ៍​ញ័រ។"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"កម្មវិធី​រោទ៍​ស្ងាត់។"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> បដិសេធ។"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"បាន​បដិសេធ​ការ​ជូនដំណឹង"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"ពណ៌​ការ​ជូន​ដំណឹង"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"ការ​កំណត់​រហ័ស។"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"កម្មវិធី​ថ្មី​ៗ។"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"អ្នក​ប្រើ <xliff:g id="USER">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"ចល័ត <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ថ្ម <xliff:g id="STATE">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"របៀបពេល​ជិះ​យន្ត​ហោះ <xliff:g id="STATE">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"ប៊្លូធូស <xliff:g id="STATE">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"កំណត់​សំឡេង​រោទ៍​សម្រាប់ <xliff:g id="TIME">%s</xliff:g> ។"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"បាន​បិទ​ទិន្នន័យ 2G-3G"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"បាន​បិទ​ទិន្នន័យ 4G"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"បាន​បិទ​ទិន្នន័យ​ចល័ត"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"បាន​បិទ​ទិន្នន័យ"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"អ្នក​បាន​ដល់​ដែន​កំណត់​ប្រើ​ទិន្នន័យ​បាន​បញ្ជាក់។\n\nបើ​អ្នក​បើក​ទិន្នន័យ​ឡើងវិញ អ្នក​អាច​ត្រូវ​បាន​ប្ដូរ​ដោយ​ប្រតិបត្តិ​ករ។"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"បើក​​ទិន្នន័យ​ឡើងវិញ"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"គ្មាន​ការ​តភ្ជាប់​អ៊ីនធឺណិត"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"បាន​ភ្ជាប់​វ៉ាយហ្វាយ"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"ស្វែងរក GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"ទីតាំង​​​​​កំណត់​ដោយ GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"សំណើ​ទីតាំង​សកម្ម"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"សម្អាត​ការ​ជូន​ដំណឹង​ទាំងអស់។"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"ព័ត៌មាន​កម្មវិធី"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"នឹង​បង្វិល​អេក្រង់​ស្វ័យ​ប្រវត្តិ។"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"អេក្រង់​ជាប់​សោ​ក្នុង​ទិស​ផ្ដេក។"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"បា​ន​ចាក់​សោ​អេក្រង់​​ក្នុង​ទិស​បញ្ឈរ។"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"ករណី Dessert"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"ស្រមើ​ស្រមៃ"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"អ៊ីសឺរណិត"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"របៀបពេល​​ជិះ​យន្តហោះ"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"បញ្ចូល​ថ្ម <xliff:g id="NUMBER">%d</xliff:g> <xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"បាន​បញ្ចូល​ពេញ"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"ប៊្លូធូស"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"ប៊្លូធូស (ឧបករណ៍ <xliff:g id="NUMBER">%d</xliff:g>)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"បិទ​ប៊្លូធូស"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"ពន្លឺ"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"បង្វិល​​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"បាន​ចាក់​សោ​ការ​បង្វិល"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"ទី​តាំង"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"ទីតាំង​បិទ"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"ឧបករណ៍​មេឌៀ"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"សម្រាប់​តែ​ការ​ហៅ​ពេល​អាសន្ន"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"ការ​កំណត់"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"ពេលវេលា"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"ខ្ញុំ"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"វ៉ាយហ្វាយ"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"មិន​បាន​តភ្ជាប់"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"គ្មាន​បណ្ដាញ"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"បិទ​វ៉ាយហ្វាយ"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"បង្ហា​ញ​វ៉ាយហ្វាយ"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"​បង្ហាញ​បណ្ដាញ​ឥត​ខ្សែ"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"ពន្លឺ"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ស្វ័យប្រវត្តិ"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"បណ្ដាញ​អាច​\nត្រូវ​បាន​ត្រួតពិនិត្យ"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-km/strings.xml b/packages/SystemUI/res/values-km/strings.xml
deleted file mode 100644
index f972925..0000000
--- a/packages/SystemUI/res/values-km/strings.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"ចំណុច​ប្រទាក់​ប្រព័ន្ធ"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"សម្អាត"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"យក​ចេញ​ពី​បញ្ជី"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"ព័ត៌មាន​កម្មវិធី"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"គ្មាន​កម្មវិធី​ថ្មីៗ"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"បដិសេធ​កម្មវិធី​ថ្មីៗ"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"កម្មវិធី​ថ្មី ១"</item>
-    <item quantity="other" msgid="1040784359794890744">"កម្មវិធី​ថ្មីៗ %d"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"គ្មាន​ការ​ជូន​ដំណឹង"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"បន្ត"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"ការ​ជូន​ដំណឹង"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"ភ្ជាប់​ឧបករណ៍​បញ្ចូល​ថ្ម"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ជិត​អស់​ថ្ម​ហើយ។"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"នៅ​សល់ <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"មិន​គាំទ្រ​ការ​បញ្ចូល​តាម​យូអេសប៊ី។\nប្រើ​តែ​ឧបករណ៍​បញ្ចូល​ថ្ម​ដែល​បាន​ផ្ដល់។"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ការ​ប្រើ​ថ្ម"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"ការ​កំណត់"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"វ៉ាយហ្វាយ"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"ពេល​ជិះ​យន្តហោះ"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"បង្វិល​អេក្រង់​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"ស្ងាត់"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ស្វ័យប្រវត្តិ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"ការ​ជូន​ដំណឹង"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"បាន​ភ្ជាប់​ប៊្លូធូស"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"រៀបចំ​វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"ក្ដារ​ចុច​ពិតប្រាកដ"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"ឲ្យ​កម្មវិធី <xliff:g id="APPLICATION">%1$s</xliff:g> ចូល​ដំណើរការ​ឧបករណ៍​យូអេសប៊ី?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"ឲ្យ​កម្មវិធី <xliff:g id="APPLICATION">%1$s</xliff:g> ចូល​ដំណើរការ​ឧបករណ៍​យូអេសប៊ី?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"បើក <xliff:g id="ACTIVITY">%1$s</xliff:g> ពេល​បាន​ភ្ជាប់​ឧបករណ៍​យូអេសប៊ី​នេះ?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"បើក <xliff:g id="ACTIVITY">%1$s</xliff:g> ពេល​បាន​ភ្ជាប់​ឧបករណ៍​យូអេសប៊ី?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"គ្មាន​កម្មវិធី​បាន​ដំឡើង​ដំណើរការ​ជា​មួយ​ឧបករណ៍​យូអេសប៊ី។ ស្វែងយល់​បន្ថែម​អំពី​ឧបករណ៍​នេះ​នៅ <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"ឧបករណ៍​យូអេសប៊ី"</string>
-    <string name="label_view" msgid="6304565553218192990">"មើល"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"ប្រើ​តាម​លំនាំដើម​សម្រាប់​ឧបករណ៍​យូអេសប៊ី​នេះ"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"ប្រើ​តាម​លំនាំដើម​សម្រាប់​ខ្សែ​យូអេសប៊ី​នេះ"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"អនុញ្ញាត​ការ​កែ​កំហុស​យូអេសប៊ី?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"ស្នាម​ម្រាម​ដៃ​ RSA របស់​កុំព្យូទ័រ​គឺ៖ \n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"អនុញ្ញាត​ជា​និច្ច​សម្រាប់​កុំព្យូទ័រ​នេះ"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"ពង្រីក​​ដើម្បី​ឲ្យ​ពេញ​អេក្រង់"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"ទាញ​ដើម្បី​ឲ្យ​ពេញ​អេក្រង់"</string>
-    <string name="compat_mode_help_header" msgid="7969493989397529910">"ការ​ពង្រីក​ត្រូវ​គ្នា"</string>
-    <string name="compat_mode_help_body" msgid="4946726776359270040">"ពេល​កម្មវិធី​ត្រូវ​បាន​រៀបចំ​សម្រាប់​អេក្រង់​តូច ការ​គ្រប់គ្រង​ការ​ពង្រីក​នឹង​បង្ហាញ​តាម​នាឡិកា។"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"កំពុង​រក្សាទុក​រូបថត​អេក្រង់…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"កំពុង​រក្សាទុក​រូបថត​អេក្រង់..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"រូបថត​អេក្រង់​កំពុង​ត្រូវ​បាន​រក្សាទុក។"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"បាន​ចាប់​យក​រូបថត​អេក្រង់។"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"ប៉ះ ​ដើម្បី​មើល​រូបថត​អេក្រង់​របស់​អ្នក​។"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"មិន​អាច​ចាប់​យក​រូប​ថត​អេក្រង់​។"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"មិន​អាច​រក្សាទុក​រូបថត​អេក្រង់​។ ឧបករណ៍​ផ្ទុក​អាច​កំពុង​ប្រើ​​។"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"ជម្រើស​ផ្ទេរ​ឯកសារ​តាម​យូអេសប៊ី"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"ភ្ជាប់​ជា​កម្មវិធី​ចាក់​មេឌៀ (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"ភ្ជាប់​ជា​ម៉ាស៊ីន​ថត (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"ដំឡើង​កម្មវិធី​ផ្ទេរ​ឯកសារ Android សម្រាប់ Mac"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"ថយក្រោយ"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"គេហ​ទំព័រ"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"ម៉ឺនុយ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"កម្មវិធី​ថ្មីៗ"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ប្ដូរ​ប៊ូតុង​វិធីសាស្ត្រ​បញ្ចូល។"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ប៊ូតុង​ពង្រីក​ត្រូវ​គ្នា។"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"ពង្រីក/បង្រួម​​អេក្រង់​ពី​​ទៅធំ"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"បាន​តភ្ជាប់​ប៊្លូធូស។"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"បាន​ផ្ដាច់​​ប៊្លូធូស។"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"គ្មាន​ថ្ម។"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ថ្ម​មួយ​កាំ។"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ថ្ម​ពីរ​កាំ។"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ថ្ម​ទាំង​បី​​កាំ​។"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ថ្ម​ពេញ​ហើយ។"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"គ្មាន​ទូរស័ព្ទ។"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"សេវា​ទូរស័ព្ទ​មួយ​កាំ។"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"សេវា​ទូរស័ព្ទ​ពីរ​កាំ។"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"សេវា​ទូរស័ព្ទ​បី​កាំ​។"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"សេវា​ទូរស័ព្ទ​ពេញ។"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"គ្មាន​ទិន្នន័យ​។"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"ទិន្នន័យ​មួយ​​កាំ។"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"ទិន្នន័យ​ពីរ​​កាំ។"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"ទិន្នន័យ​បី​កាំ។"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"សញ្ញា​ទិន្នន័យ​ពេញ។"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"បិទ​វ៉ាយហ្វាយ។"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"បាន​ផ្ដាច់​វ៉ាយហ្វាយ។"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"សញ្ញា​វ៉ាយហ្វាយ​មួយ​កាំ។"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"សេវា​វ៉ាយហ្វាយ​ពីរ​កាំ។"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"វ៉ាយហ្វាយ​បី​កាំ។"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"សញ្ញា​វ៉ាយហ្វាយ​ពេញ។"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"គ្មាន WiMAX ។"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX មួយ​កាំ។"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX ពីរ​កាំ។"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX បី​កាំ។"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"សញ្ញា WiMAX ពេញ។"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"គ្មាន​សញ្ញា។"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"មិន​បាន​តភ្ជាប់​។"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"សូន្យ​កាំ។"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"មួយ​កាំ។"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"ពីរ​កាំ។"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"បី​កាំ។"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"សញ្ញា​ពេញ​​។"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"បើក។"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"បិទ"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"បាន​តភ្ជាប់។"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"រ៉ូ​មីង"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"វ៉ាយហ្វាយ"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"គ្មាន​ស៊ីម​កាត។"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"ការ​ភ្ជាប់​ប៊្លូធូស។"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"របៀប​​ជិះ​យន្តហោះ"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ថ្ម <xliff:g id="NUMBER">%d</xliff:g> ភាគរយ។"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"ការ​កំណត់​ប្រព័ន្ធ​។"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"ការ​ជូន​ដំណឹង។"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"សម្អាត​ការ​ជូន​ដំណឹង។"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"បាន​បើក GPS ។"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"ទទួល​​ GPS ។"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"បាន​បើក​ម៉ាស៊ីន​អង្គុលីលេខ"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"កម្មវិធី​រោទ៍​ញ័រ។"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"កម្មវិធី​រោទ៍​ស្ងាត់។"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> បដិសេធ។"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"បាន​បដិសេធ​ការ​ជូនដំណឹង"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"ពណ៌​ការ​ជូន​ដំណឹង"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"ការ​កំណត់​រហ័ស។"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"កម្មវិធី​ថ្មី​ៗ។"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"អ្នក​ប្រើ <xliff:g id="USER">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"ចល័ត <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ថ្ម <xliff:g id="STATE">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"របៀប​ជិះ​យន្ត​ហោះ <xliff:g id="STATE">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"ប៊្លូធូស <xliff:g id="STATE">%s</xliff:g> ។"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"កំណត់​សំឡេង​រោទ៍​សម្រាប់ <xliff:g id="TIME">%s</xliff:g> ។"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"បាន​បិទ​ទិន្នន័យ 2G-3G"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"បាន​បិទ​ទិន្នន័យ 4G"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"បាន​បិទ​ទិន្នន័យ​ចល័ត"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"បាន​បិទ​ទិន្នន័យ"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"អ្នក​បាន​ដល់​ដែន​កំណត់​ប្រើ​ទិន្នន័យ​បាន​បញ្ជាក់។\n\nបើ​អ្នក​បើក​ទិន្នន័យ​ឡើងវិញ អ្នក​អាច​ត្រូវ​បាន​ប្ដូរ​ដោយ​ប្រតិបត្តិ​ករ។"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"បើក​​ទិន្នន័យ​ឡើងវិញ"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"គ្មាន​ការ​តភ្ជាប់​អ៊ីនធឺណិត"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"បាន​ភ្ជាប់​វ៉ាយហ្វាយ"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"ស្វែងរក GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"ទីតាំង​​​​​កំណត់​ដោយ GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"សំណើ​ទីតាំង​សកម្ម"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"សម្អាត​ការ​ជូន​ដំណឹង​ទាំងអស់។"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"ព័ត៌មាន​កម្មវិធី"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"នឹង​បង្វិល​អេក្រង់​ស្វ័យ​ប្រវត្តិ។"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"អេក្រង់​ជាប់​សោ​ក្នុង​ទិស​ផ្ដេក។"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"បា​ន​ចាក់​សោ​អេក្រង់​​ក្នុង​ទិស​បញ្ឈរ។"</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"ស្រមើ​ស្រមៃ"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"អ៊ីសឺរណិត"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"របៀប​​ជិះ​យន្តហោះ"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"បញ្ចូល​ថ្ម <xliff:g id="NUMBER">%d</xliff:g> <xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"បាន​បញ្ចូល​ពេញ"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"ប៊្លូធូស"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"ប៊្លូធូស (ឧបករណ៍ <xliff:g id="NUMBER">%d</xliff:g>)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"បិទ​ប៊្លូធូស"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"ពន្លឺ"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"បង្វិល​​ស្វ័យ​ប្រវត្តិ"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"បាន​ចាក់​សោ​ការ​បង្វិល"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"វិធីសាស្ត្រ​បញ្ចូល"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"ទី​តាំង"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"ទីតាំង​បិទ"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"ឧបករណ៍​មេឌៀ"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"សម្រាប់​តែ​ការ​ហៅ​ពេល​អាសន្ន"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"ការ​កំណត់"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"ពេលវេលា"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"ខ្ញុំ"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"វ៉ាយហ្វាយ"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"មិន​បាន​តភ្ជាប់"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"គ្មាន​បណ្ដាញ"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"បិទ​វ៉ាយហ្វាយ"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"បង្ហា​ញ​វ៉ាយហ្វាយ"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"​បង្ហាញ​បណ្ដាញ​ឥត​ខ្សែ"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"ពន្លឺ"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ស្វ័យប្រវត្តិ"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"ការ​ជូន​ដំណឹង​​បង្ហាញ​​នៅ​ទីនេះ"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"ចូល​ដំណើរការ​ពួក​វា​ពេល​ណា​មួយ​ដោយ​អូស​ចុះក្រោម។\nអូស​ចុះក្រោម​ម្ដង​ទៀត​ ដើម្បី​ពិនិត្យ​ប្រព័ន្ធ។"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ko/strings.xml b/packages/SystemUI/res/values-ko/strings.xml
index 82f9b89..1437601 100644
--- a/packages/SystemUI/res/values-ko/strings.xml
+++ b/packages/SystemUI/res/values-ko/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"이 컴퓨터에서 항상 허용"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"전체화면 모드로 확대"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"전체화면 모드로 확대"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"호환성 확대/축소"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"앱이 작은 화면에 맞도록 설계된 경우 시계 옆에 확대/축소 컨트롤이 표시됩니다."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"캡쳐화면 저장 중..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"캡쳐화면 저장 중..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"캡쳐화면을 저장하는 중입니다."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"홈"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"메뉴"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"최근에 사용한 앱"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"검색"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"카메라"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"입력 방법 버튼을 전환합니다."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"호환성 확대/축소 버튼입니다."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"작은 화면을 큰 화면으로 확대합니다."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi 연결됨"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS 검색 중"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS에서 위치 설정"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"위치 요청 있음"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"모든 알림 지우기"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"앱 정보"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"화면이 자동으로 회전됩니다."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"화면이 가로 방향으로 잠겨 있습니다."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"화면이 세로 방향으로 잠겨 있습니다."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"디저트 케이스"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"화면 보호기"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"이더넷"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"비행기 모드"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"자동 회전"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"회전 잠금"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"입력 방법"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"위치"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"위치 사용 중지"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"미디어 기기"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"긴급 통화만 허용"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"무선 디스플레이"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"밝기"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"자동"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"네트워크가\n모니터링될 수 있음"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"알림이 여기에 표시됨"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"아래로 스와이프하여 언제든 액세스하세요.\n한 번 더 아래로 스와이프하면 시스템 관리로 이동합니다."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"화면 가장자리에서 스와이프하여 표시줄 표시"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"화면 가장자리에서 스와이프하여 시스템 표시줄 표시"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-lo-rLA-land/strings.xml b/packages/SystemUI/res/values-lo-rLA-land/strings.xml
deleted file mode 100644
index a838a15..0000000
--- a/packages/SystemUI/res/values-lo-rLA-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"ໜ້າຈໍຕອນນີ້ຖືກລັອກໄວ້ໃນແບບລວງນອນ."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-lo-rLA/strings.xml b/packages/SystemUI/res/values-lo-rLA/strings.xml
deleted file mode 100644
index ec14830..0000000
--- a/packages/SystemUI/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"ສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ຂອງລະບົບ"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"ລຶບ"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"ເອົາອອກຈາກລາຍການ"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"ຂໍ້ມູນແອັບຯ"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"ບໍ່ມີແອັບຯທີ່ຫາກໍໃຊ້"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"ປິດແອັບຯຫຼ້າສຸດທີ່ໃຊ້"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 ແອັບຯຫຼ້າສຸດ"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d ແອັບຯຫຼ້າສຸດ"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"ບໍ່ມີການແຈ້ງເຕືອນ"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"ດຳເນີນຢູ່"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"ການແຈ້ງເຕືອນ"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"ເຊື່ອມຕໍ່ສາຍສາກ"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ແບັດເຕີຣີເຫຼືອໜ້ອຍແລ້ວ."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"ຍັງເຫຼືອອີກ <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"ບໍ່ຮອງຮັບການສາກໄຟດ້ວຍ USB.\nຕ້ອງໃຊ້ສະເພາະເຄື່ອງສາກທີ່ແຖມມານຳເທົ່ານັ້ນ."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ການນຳໃຊ້ແບັດເຕີຣີ"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"ການຕັ້ງຄ່າ"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"ໂໝດເທິງຍົນ"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"ໝຸນໜ້າຈໍອັດຕະໂນມັດ"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"ປິດສຽງ"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ອັດຕະໂນມັດ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"ການແຈ້ງເຕືອນ"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"ປ່ອຍສັນຍານຜ່ານ Bluetooth ແລ້ວ"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"ຕັ້ງຄ່າວິທີການປ້ອນຂໍ້ມູນ"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"ແປ້ນພິມແທ້"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"ອະນຸຍາດໃຫ້ແອັບຯ <xliff:g id="APPLICATION">%1$s</xliff:g> ເຂົ້າເຖິງອຸປະກອນ USB?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"ອະນຸຍາດໃຫ້ແອັບຯ <xliff:g id="APPLICATION">%1$s</xliff:g> ເຂົ້າເຖິງອຸປະກອນພ່ວງ USB?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"ເປີດ <xliff:g id="ACTIVITY">%1$s</xliff:g> ເມື່ອເຊື່ອມຕໍ່ກັບອຸປະກອນ USB ນີ້ຫຼືບໍ່?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"ເປີດ <xliff:g id="ACTIVITY">%1$s</xliff:g> ເມື່ອມີການເຊື່ອມຕໍ່ກັບອຸປະກອນເສີມ USB ນີ້ຫຼືບໍ່?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"ບໍ່ມີແອັບຯໃດທີ່ຕິດຕັ້ງໄປແລ້ວ ສາມາດເຮັດວຽກຮ່ວມກັບອຸປະກອນເສີມ USB ນີ້ໄດ້. ສຶກສາເພີ່ມເຕີມກ່ຽວກັບອຸປະກອນເສີມນີ້ທີ່ <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"ອຸປະກອນເສີມ USB"</string>
-    <string name="label_view" msgid="6304565553218192990">"ເບິ່ງ"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"ໃຊ້ເປັນຄ່າເລີ່ມຕົ້ນສຳລັບອຸປະກອນ USB ນີ້"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"ໃຊ້ຄ່າເລີ່ມຕົ້ນສຳລັບອຸປະກອນເສີມ USB ນີ້."</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"ອະນຸຍາດການດີບັ໊ກຜ່ານ USB?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"ລາຍນິ້ມື RSA ຂອງຄອມພິວເຕີແມ່ນ:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"ອະນຸຍາດຈາກຄອມພິວເຕີນີ້ຕະຫຼອດ"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"ຊູມໃຫ້ເຕັມໜ້າຈໍ"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"ປັບໃຫ້ເຕັມໜ້າຈໍ"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"ກຳລັງບັນທຶກຮູບໜ້າຈໍ"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"ກຳລັງບັນທຶກພາບໜ້າຈໍ..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"ກຳລັງບັນທຶກພາບໜ້າຈໍ."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"ຖ່າຍຮູບໜ້າຈໍແລ້ວ"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"ແຕະເພື່ອເບິ່ງພາບໜ້າຈໍຂອງທ່ານ."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"ບໍ່ສາມາດຖ່າຍຮູບໜ້າຈໍໄດ້"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"ບໍ່ສາມາດບັນທຶກພາບໜ້າຈໍໄດ້. ບ່ອນຈັດເກັບອາດກຳລັງຖືກນຳໃຊ້ຢູ່."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ໂຕເລືອກການຍ້າຍໄຟລ໌"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"ເຊື່ອມຕໍ່ເປັນ media player (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"ເຊື່ອມຕໍ່ເປັນກ້ອງຖ່າຍຮູບ (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"ຕິດຕັ້ງແອັບຯ Android File Transfer ສຳລັບ Mac"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"ກັບຄືນ"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"ໜ້າທຳອິດ"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"ເມນູ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"ແອັບຯຫຼ້າສຸດ"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"ຊອກຫາ"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"ກ້ອງ"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ປຸ່ມສະລັບຮູບແບບການປ້ອນຂໍ້ມູນ."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ປຸ່ມຊູມທີ່ໃຊ້ຮ່ວມກັນໄດ້."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"ຊູມຈໍນ້ອຍໄປເປັນຈໍຂະຫນາດໃຫຍ່."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"ເຊື່ອມຕໍ່ Bluetooth ແລ້ວ."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth ຖືກຕັດການເຊື່ອມຕໍ່ແລ້ວ."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"ແບັດເຕີຣີໝົດ."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ແບັດເຕີຣີນຶ່ງຂີດ."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ແບັດເຕີຣີສອງຂີດ."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ແບັດເຕີຣີສາມຂີດ."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ແບັດເຕີຣີເຕັມ."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"ບໍ່ມີໂທລະສັບ."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"ສັນຍານນຶ່ງຂີດ."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"ສັນຍານສອງຂີດ."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"ສັນຍານສາມຂີດ."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"ສັນຍານເຕັມ."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"ບໍ່ມີຂໍ້ມູນ."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"ຂໍ້ມູນນຶ່ງຂີດ."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"ຂໍ້ມູນສອງຂີດ."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"ຂໍ້ມູນສາມຂີດ."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"ສັນ​ຍານຂໍ້ມູນ​ເຕັມ."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"WiFi ປິດຢູ່."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"ຕັດການເຊື່ອມຕໍ່ Wi-Fi ແລ້ວ."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"ສັນຍານ Wi-Fi ນຶ່ງຂີດ."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"ສັນຍານ Wi-Fi ສອງຂີດ."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi ສາມຂີດ."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"ສັນຍານ Wi-Fi ເຕັມ"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"ບໍ່ມີ WiMAX."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX ນຶ່ງຂີດ."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX ສອງຂີດ."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX ສາມຂີດ."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"ສັນ​ຍານ WiMAX ເຕັມ."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"ບໍ່ມີສັນຍານ."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"ບໍ່ໄດ້ເຊື່ອມຕໍ່."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"ບໍ່ມີຈັກຂີດ."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"ນຶ່ງຂີດ."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"ສອງຂີດ."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"ສາມຂີດ."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"ສັນຍານເຕັມ."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"ເປີດ."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"ປິດ."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"ເຊື່ອມ​ຕໍ່ແລ້ວ."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"ໂຣມມິງ"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"ບໍ່ມີຊິມ."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"ການປ່ອຍສັນຍານ Bluetooth."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"ໂໝດໃນຍົນ."</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ແບັດເຕີຣີ <xliff:g id="NUMBER">%d</xliff:g> ເປີເຊັນ."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"ການຕັ້ງຄ່າລະບົບ."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"ການແຈ້ງເຕືອນ."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"ລຶບລ້າງການແຈ້ງເຕືອນ."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS ເປີດແລ້ວ."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"ກຳລັງຊອກຫາ GPS."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter ຖືກເປີດຢູ່."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"ສັ່ນເຕືອນພ້ອມສຽງເອີ້ນເຂົ້າ."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"ປິດສຽງ."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"ປິດ <xliff:g id="APP">%s</xliff:g> ແລ້ວ."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"ປິດການແຈ້ງເຕືອນແລ້ວ."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"ໜ້າຈໍແຈ້ງເຕືອນ."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"ການຕັ້ງຄ່າດ່ວນ."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"ແອັບຯທີ່ຫາກໍໃຊ້."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"ຜູ່ໃຊ້ <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"ມືຖື <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ແບັດເຕີຣີ <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"ໂໝດໃນຍົນ <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"ຕັ້ງໂມງປຸກ <xliff:g id="TIME">%s</xliff:g> ແລ້ວ."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"ອິນເຕີເນັດ 2G​, 3G ຖືກປິດແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"ການນຳໃຊ້ຂໍ້ມູນ 4G ຖືກປິດແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"ອິນເຕີເນັດໃນມືຖືຖືກປິດການນຳໃຊ້ແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"ອິນເຕີເນັດຖືກປິດການນຳໃຊ້ແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"ທ່ານໄດ້ໃຊ້ຂໍ້ມູນຈົນຮອດຈຳນວນທີ່ຈຳກັດໄວ້ແລ້ວ.\n\nຫາກທ່ານເປີດນຳໃຊ້ຂໍ້ມູນຄືນອີກຄັ້ງ, ທ່ານອາດຖືກຮຽກເກັບເງິນໂດຍຜູ່ໃຫ້ບໍລິການໄດ້."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"ເປີດນຳໃຊ້ຂໍ້ມູນຄືນໃໝ່"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"ບໍ່ມີການເຊື່ອມຕໍ່ອິນເຕີເນັດ"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"ເຊື່ອມ​ຕໍ່ Wi-​-Fi ແລ້ວ"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"ກຳລັງຊອກຫາ GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"ສະຖານທີ່ກຳນົດໂດຍ GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"ການຮ້ອງຂໍສະຖານທີ່ທີ່ເຮັດວຽກຢູ່"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"ລຶບການແຈ້ງເຕືອນທັງໝົດ."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"ຂໍ້ມູນແອັບຯ"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"ໜ້າຈໍຈະໝຸນໂດຍອັດຕະໂນມັດ."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"ໜ້າຈໍຖືກລັອກໃນລວງນອນ."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"ໜ້າຈໍຖືກລັອກຢູ່ໃນໂໝດແນວຕັ້ງ."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"ກ່ອງຂອງຫວານ"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"ໂໝດຢູ່ໃນຍົນ"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"ກຳລັງສາກ, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"ສາກເຕັມແລ້ວ"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> ອຸປະກອນ)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth ປິດ"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"ຄວາມສະຫວ່າງ"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"ໝຸນໜ້າຈໍອັດຕະໂນມັດ"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"ລັອກການປ່ຽນລວງ"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"ວິທີການປ້ອນຂໍ້ມູນ"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"ສະຖານທີ່"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"ຂໍ້ມູນສະຖານທີ່ປິດຢູ່"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"ອຸປະກອນສື່"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"ໂທສຸກເສີນເທົ່ານັ້ນ"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"ການຕັ້ງຄ່າ"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"ເວລາ"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"ຂ້ອຍ"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi​-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"ບໍ່ໄດ້ເຊື່ອມຕໍ່"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"ບໍ່ມີເຄືອຂ່າຍ"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi​-Fi ປິດ"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"ຈໍສະແດງຜົນ Wi-Fi"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"ການສະແດງຜົນໄຮ້ສາຍ"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"ຄວາມແຈ້ງ"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ອັດຕະໂນມັດ"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"ເຄືອຄ່າຍອາດ\nຖືກຕິດຕາມ"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-lo/strings.xml b/packages/SystemUI/res/values-lo/strings.xml
deleted file mode 100644
index 85b10f7..0000000
--- a/packages/SystemUI/res/values-lo/strings.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"ສ່ວນຕິດຕໍ່ຜູ່ໃຊ້ຂອງລະບົບ"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"ລຶບ"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"ເອົາອອກຈາກລາຍການ"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"ຂໍ້ມູນແອັບຯ"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"ບໍ່ມີແອັບຯທີ່ຫາກໍໃຊ້"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"ປິດແອັບຯຫຼ້າສຸດທີ່ໃຊ້"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 ແອັບຯຫຼ້າສຸດ"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d ແອັບຯຫຼ້າສຸດ"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"ບໍ່ມີການແຈ້ງເຕືອນ"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"ດຳເນີນຢູ່"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"ການແຈ້ງເຕືອນ"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"ເຊື່ອມຕໍ່ສາຍສາກ"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ແບັດເຕີຣີເຫຼືອໜ້ອຍແລ້ວ."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"ຍັງເຫຼືອອີກ <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"ບໍ່ຮອງຮັບການສາກໄຟດ້ວຍ USB.\nຕ້ອງໃຊ້ສະເພາະເຄື່ອງສາກທີ່ແຖມມານຳເທົ່ານັ້ນ."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ການນຳໃຊ້ແບັດເຕີຣີ"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"ການຕັ້ງຄ່າ"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"ໂໝດເທິງຍົນ"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"ໝຸນໜ້າຈໍອັດຕະໂນມັດ"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"ປິດສຽງ"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ອັດຕະໂນມັດ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"ການແຈ້ງເຕືອນ"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"ປ່ອຍສັນຍານຜ່ານ Bluetooth ແລ້ວ"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"ຕັ້ງຄ່າວິທີການປ້ອນຂໍ້ມູນ"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"ແປ້ນພິມແທ້"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"ອະນຸຍາດໃຫ້ແອັບຯ <xliff:g id="APPLICATION">%1$s</xliff:g> ເຂົ້າເຖິງອຸປະກອນ USB?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"ອະນຸຍາດໃຫ້ແອັບຯ <xliff:g id="APPLICATION">%1$s</xliff:g> ເຂົ້າເຖິງອຸປະກອນພ່ວງ USB?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"ເປີດ <xliff:g id="ACTIVITY">%1$s</xliff:g> ເມື່ອເຊື່ອມຕໍ່ກັບອຸປະກອນ USB ນີ້ຫຼືບໍ່?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"ເປີດ <xliff:g id="ACTIVITY">%1$s</xliff:g> ເມື່ອມີການເຊື່ອມຕໍ່ກັບອຸປະກອນເສີມ USB ນີ້ຫຼືບໍ່?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"ບໍ່ມີແອັບຯໃດທີ່ຕິດຕັ້ງໄປແລ້ວ ສາມາດເຮັດວຽກຮ່ວມກັບອຸປະກອນເສີມ USB ນີ້ໄດ້. ສຶກສາເພີ່ມເຕີມກ່ຽວກັບອຸປະກອນເສີມນີ້ທີ່ <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"ອຸປະກອນເສີມ USB"</string>
-    <string name="label_view" msgid="6304565553218192990">"ເບິ່ງ"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"ໃຊ້ເປັນຄ່າເລີ່ມຕົ້ນສຳລັບອຸປະກອນ USB ນີ້"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"ໃຊ້ຄ່າເລີ່ມຕົ້ນສຳລັບອຸປະກອນເສີມ USB ນີ້."</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"ອະນຸຍາດການດີບັ໊ກຜ່ານ USB?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"ລາຍນິ້ມື RSA ຂອງຄອມພິວເຕີແມ່ນ:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"ອະນຸຍາດຈາກຄອມພິວເຕີນີ້ຕະຫຼອດ"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"ຊູມໃຫ້ເຕັມໜ້າຈໍ"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"ປັບໃຫ້ເຕັມໜ້າຈໍ"</string>
-    <string name="compat_mode_help_header" msgid="7969493989397529910">"ຄວາມເຂົ້າກັນໄດ້ຂອງການຊູມ"</string>
-    <string name="compat_mode_help_body" msgid="4946726776359270040">"ເມື່ອແອັບຯຖືກອອກແບບມາສຳລັບໜ້າຈໍນ້ອຍກວ່າ​, ຕົວຄວບຄຸມການຊູມຈະປາກົດຢູ່ໃກ້ກັບໂມງ."</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"ກຳລັງບັນທຶກຮູບໜ້າຈໍ"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"ກຳລັງບັນທຶກພາບໜ້າຈໍ..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"ກຳລັງບັນທຶກພາບໜ້າຈໍ."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"ຖ່າຍຮູບໜ້າຈໍແລ້ວ"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"ແຕະເພື່ອເບິ່ງພາບໜ້າຈໍຂອງທ່ານ."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"ບໍ່ສາມາດຖ່າຍຮູບໜ້າຈໍໄດ້"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"ບໍ່ສາມາດບັນທຶກພາບໜ້າຈໍໄດ້. ບ່ອນຈັດເກັບອາດກຳລັງຖືກນຳໃຊ້ຢູ່."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ໂຕເລືອກການຍ້າຍໄຟລ໌"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"ເຊື່ອມຕໍ່ເປັນ media player (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"ເຊື່ອມຕໍ່ເປັນກ້ອງຖ່າຍຮູບ (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"ຕິດຕັ້ງແອັບຯ Android File Transfer ສຳລັບ Mac"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"ກັບຄືນ"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"ໜ້າທຳອິດ"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"ເມນູ"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"ແອັບຯຫຼ້າສຸດ"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ປຸ່ມສະລັບຮູບແບບການປ້ອນຂໍ້ມູນ."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ປຸ່ມຊູມທີ່ໃຊ້ຮ່ວມກັນໄດ້."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"ຊູມຈໍນ້ອຍໄປເປັນຈໍຂະຫນາດໃຫຍ່."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"ເຊື່ອມຕໍ່ Bluetooth ແລ້ວ."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth ຖືກຕັດການເຊື່ອມຕໍ່ແລ້ວ."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"ແບັດເຕີຣີໝົດ."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ແບັດເຕີຣີນຶ່ງຂີດ."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ແບັດເຕີຣີສອງຂີດ."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ແບັດເຕີຣີສາມຂີດ."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ແບັດເຕີຣີເຕັມ."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"ບໍ່ມີໂທລະສັບ."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"ສັນຍານນຶ່ງຂີດ."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"ສັນຍານສອງຂີດ."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"ສັນຍານສາມຂີດ."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"ສັນຍານເຕັມ."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"ບໍ່ມີຂໍ້ມູນ."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"ຂໍ້ມູນນຶ່ງຂີດ."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"ຂໍ້ມູນສອງຂີດ."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"ຂໍ້ມູນສາມຂີດ."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"ສັນ​ຍານຂໍ້ມູນ​ເຕັມ."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"WiFi ປິດຢູ່."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"ຕັດການເຊື່ອມຕໍ່ Wi-Fi ແລ້ວ."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"ສັນຍານ Wi-Fi ນຶ່ງຂີດ."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"ສັນຍານ Wi-Fi ສອງຂີດ."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi ສາມຂີດ."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"ສັນຍານ Wi-Fi ເຕັມ"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"ບໍ່ມີ WiMAX."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX ນຶ່ງຂີດ."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX ສອງຂີດ."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX ສາມຂີດ."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"ສັນ​ຍານ WiMAX ເຕັມ."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"ບໍ່ມີສັນຍານ."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"ບໍ່ໄດ້ເຊື່ອມຕໍ່."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"ບໍ່ມີຈັກຂີດ."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"ນຶ່ງຂີດ."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"ສອງຂີດ."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"ສາມຂີດ."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"ສັນຍານເຕັມ."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"ເປີດ."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"ປິດ."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"ເຊື່ອມ​ຕໍ່ແລ້ວ."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"ໂຣມມິງ"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"ບໍ່ມີຊິມ."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"ການປ່ອຍສັນຍານ Bluetooth."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"ໂໝດໃນຍົນ."</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ແບັດເຕີຣີ <xliff:g id="NUMBER">%d</xliff:g> ເປີເຊັນ."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"ການຕັ້ງຄ່າລະບົບ."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"ການແຈ້ງເຕືອນ."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"ລຶບລ້າງການແຈ້ງເຕືອນ."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS ເປີດແລ້ວ."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"ກຳລັງຊອກຫາ GPS."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter ຖືກເປີດຢູ່."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"ສັ່ນເຕືອນພ້ອມສຽງເອີ້ນເຂົ້າ."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"ປິດສຽງ."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"ປິດ <xliff:g id="APP">%s</xliff:g> ແລ້ວ."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"ປິດການແຈ້ງເຕືອນແລ້ວ."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"ໜ້າຈໍແຈ້ງເຕືອນ."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"ການຕັ້ງຄ່າດ່ວນ."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"ແອັບຯທີ່ຫາກໍໃຊ້."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"ຜູ່ໃຊ້ <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"ມືຖື <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ແບັດເຕີຣີ <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"ໂໝດໃນຍົນ <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"ຕັ້ງໂມງປຸກ <xliff:g id="TIME">%s</xliff:g> ແລ້ວ."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"ອິນເຕີເນັດ 2G​, 3G ຖືກປິດແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"ການນຳໃຊ້ຂໍ້ມູນ 4G ຖືກປິດແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"ອິນເຕີເນັດໃນມືຖືຖືກປິດການນຳໃຊ້ແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"ອິນເຕີເນັດຖືກປິດການນຳໃຊ້ແລ້ວ"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"ທ່ານໄດ້ໃຊ້ຂໍ້ມູນຈົນຮອດຈຳນວນທີ່ຈຳກັດໄວ້ແລ້ວ.\n\nຫາກທ່ານເປີດນຳໃຊ້ຂໍ້ມູນຄືນອີກຄັ້ງ, ທ່ານອາດຖືກຮຽກເກັບເງິນໂດຍຜູ່ໃຫ້ບໍລິການໄດ້."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"ເປີດນຳໃຊ້ຂໍ້ມູນຄືນໃໝ່"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"ບໍ່ມີການເຊື່ອມຕໍ່ອິນເຕີເນັດ"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"ເຊື່ອມ​ຕໍ່ Wi-​-Fi ແລ້ວ"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"ກຳລັງຊອກຫາ GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"ສະຖານທີ່ກຳນົດໂດຍ GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"ການຮ້ອງຂໍສະຖານທີ່ທີ່ເຮັດວຽກຢູ່"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"ລຶບການແຈ້ງເຕືອນທັງໝົດ."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"ຂໍ້ມູນແອັບຯ"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"ໜ້າຈໍຈະໝຸນໂດຍອັດຕະໂນມັດ."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"ໜ້າຈໍຖືກລັອກໃນລວງນອນ."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"ໜ້າຈໍຖືກລັອກຢູ່ໃນໂໝດແນວຕັ້ງ."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"ໂໝດຢູ່ໃນຍົນ"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"ກຳລັງສາກ, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"ສາກເຕັມແລ້ວ"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> ອຸປະກອນ)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth ປິດ"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"ຄວາມສະຫວ່າງ"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"ໝຸນໜ້າຈໍອັດຕະໂນມັດ"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"ລັອກການປ່ຽນລວງ"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"ວິທີການປ້ອນຂໍ້ມູນ"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"ສະຖານທີ່"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"ຂໍ້ມູນສະຖານທີ່ປິດຢູ່"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"ອຸປະກອນສື່"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"ໂທສຸກເສີນເທົ່ານັ້ນ"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"ການຕັ້ງຄ່າ"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"ເວລາ"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"ຂ້ອຍ"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi​-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"ບໍ່ໄດ້ເຊື່ອມຕໍ່"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"ບໍ່ມີເຄືອຂ່າຍ"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi​-Fi ປິດ"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"ຈໍສະແດງຜົນ Wi-Fi"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"ການສະແດງຜົນໄຮ້ສາຍ"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"ຄວາມແຈ້ງ"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ອັດຕະໂນມັດ"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"ການແຈ້ງເຕືອນຈະປາກົດບ່ອນນີ້"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"ເຂົ້າເຖິງໄດ້ທຸກເມື່ອໂດຍການປັດນິ້ວລົງ.\nປັດລົງອີກເທື່ອນຶ່ງສຳລັບການຄວບຄຸມລະບົບ."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-lt/strings.xml b/packages/SystemUI/res/values-lt/strings.xml
index abb2240..bf8662a 100644
--- a/packages/SystemUI/res/values-lt/strings.xml
+++ b/packages/SystemUI/res/values-lt/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Visada leisti iš šio kompiuterio"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Keisti mast., kad atit. ekr."</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Ištempti, kad atit. ekr."</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Suderinamumo mastelio keitimas"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Kai programa bus pritaikyta mažesniam ekranui, mastelio keitimo valdiklis bus parodytas šalia laikrodžio."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Išsaugoma ekrano kopija..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Išsaugoma ekrano kopija..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Išsaugoma ekrano kopija."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Pagrindinis"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Meniu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Naujausios programos"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Ieškoti"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Fotoaparatas"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Perjungti įvesties metodo mygtuką."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Suderinamumo priartinimo mygtukas."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Padidinti ekraną."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Prisij. prie „Wi-Fi“"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Ieškoma GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS nustatyta vieta"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Vietovės užklausos aktyvios"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Išvalyti visus pranešimus."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Programos informacija"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekranas bus sukamas automatiškai."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Užrakintas ekranas yra horizontalios orientacijos."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Užrakintas ekranas yra vertikalios orientacijos."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Desertų dėklas"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Svajonė"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Eternetas"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Lėktuvo režimas"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Belaidis rodymas"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Skaistis"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATINIS"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Tinklas gali\nbūti stebimas"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Pranešimai rodomi čia"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Perbraukę žemyn bet kuriuo metu pasieksite pranešimus.\nJei norite naudoti sistemos valdiklius, perbraukite žemyn dar kartą."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Jei norite, kad būtų rodoma juosta, perbraukite ekrano krašte"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Jei norite, kad būtų rodoma sistemos juosta, perbraukite iš ekrano krašto"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-lv/strings.xml b/packages/SystemUI/res/values-lv/strings.xml
index 0d01924..b96a786 100644
--- a/packages/SystemUI/res/values-lv/strings.xml
+++ b/packages/SystemUI/res/values-lv/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Vienmēr atļaut no šī datora"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Tālumm., lai aizp. ekr."</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Stiepiet, lai aizp. ekr."</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Saderības tālummaiņa"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Ja lietotne ir paredzēta mazākam ekrānam, blakus pulkstenim tiks parādīta tālummaiņas vadīkla."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Saglabā ekrānuzņēmumu…"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Notiek ekrānuzņēmuma saglabāšana..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Notiek ekrānuzņēmuma saglabāšana."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Sākums"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Izvēlne"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Nesen izmantotās lietotnes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Meklēt"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Ievades metodes maiņas poga."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Saderības tālummaiņas poga."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Veikt tālummaiņu no mazāka ekrāna uz lielāku."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Izv. sav. ar Wi-Fi"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Notiek GPS meklēšana..."</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS iestatītā atrašanās vieta"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktīvi atrašanās vietu pieprasījumi"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Notīrīt visus paziņojumus"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informācija par lietotni"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekrāns tiks pagriezts automātiski."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ekrāns tagad ir bloķēts ainavas orientācijā."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ekrāns tagad ir bloķēts portreta orientācijā."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Saldo ēdienu stends"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Ekrānsaudzētājs"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Tīkls Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Lidojuma režīms"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Bezvadu attēlošana"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Spilgtums"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMĀTISKI"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Tīkls var\ntikt uzraudzīts"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Šeit tiek rādīti paziņojumi"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Piekļūstiet tiem jebkurā laikā, velkot uz leju.\nVēlreiz velciet, lai tiktu parādītas sistēmas vadīklas."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Velciet no ekrāna malas, lai piekļūtu joslai."</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Velciet no ekrāna malas, lai piekļūtu sistēmas joslai."</string>
 </resources>
diff --git a/packages/SystemUI/res/values-mn-rMN-land/strings.xml b/packages/SystemUI/res/values-mn-rMN-land/strings.xml
deleted file mode 100644
index ec4616f..0000000
--- a/packages/SystemUI/res/values-mn-rMN-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"Дэлгэц хэвтээ чиглэлд түгжигдсэн."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-mn-rMN/strings.xml b/packages/SystemUI/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 0e6c032..0000000
--- a/packages/SystemUI/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Систем UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Цэвэрлэх"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Жагсаалтаас устгах"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Апп мэдээлэл"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Сүүлийн апп хоосон"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Сүүлийн апп-уудыг хаах"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 сүүлийн апп"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d сүүлийн апп"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Мэдэгдэл байхгүй"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Гарсан"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Мэдэгдэл"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Цэнэглэгчийг холбоно уу"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Батерей дуусаж байна."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> үлдсэн"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB цэнэглэлт дэмжигдэхгүй байна.\nЗөвхөн нийлүүлэгдсэн цэнэглэгчийг ашиглана уу."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Батерей ашиглах"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Тохиргоо"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Нислэгийн горим"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Дэлгэцийг автоматаар эргүүлэх"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"ХААХ"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"АВТОМАТ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Мэдэгдэл"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Блютүүтыг модем болгож байна"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Оруулах аргыг тохируулах"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Бодит гар"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"<xliff:g id="APPLICATION">%1$s</xliff:g> апп-г USB төхөөрөмжид хандахыг зөвшөөрөх үү?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"<xliff:g id="APPLICATION">%1$s</xliff:g> апп-г USB төхөөрөмжид хандахыг зөвшөөрөх үү?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Энэ USB төхөөрөмж холбогдох үед <xliff:g id="ACTIVITY">%1$s</xliff:g>-г нээх үү?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Энэ USB төхөөрөмж холбогдох үед <xliff:g id="ACTIVITY">%1$s</xliff:g>-г нээх үү?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Энэ USB хэрэгсэл дээр суулгасан апп ажиллаагүй байна. Энэ хэрэгслийн талаар <xliff:g id="URL">%1$s</xliff:g>-с дэлгэрэнгүй үзнэ үү."</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB төхөөрөмж"</string>
-    <string name="label_view" msgid="6304565553218192990">"Үзэх"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Энэ USB төхөөрөмжийг үндсэн болгон ашиглах"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Энэ USB төхөөрөмжийг үндсэн болгон ашиглах"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB дебаг хийхийг зөвшөөрөх үү?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Компьютерийн RSA түлхүүрийн хурууны хээ :\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Энэ компьютерээс орохыг байнга зөвшөөрөх"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Дэлгэц дүүргэх бол өсгөнө үү"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Дэлгэц дүүргэх бол татна уу"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Дэлгэцийн агшинг хадгалж байна…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Дэлгэцийн агшинг хадгалж байна…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Дэлгэцийн агшин хадгалагдав."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Дэлгэцийн агшинг авсан."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Дэлгэцийн агшныг харах бол хүрнэ үү."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Дэлгэцийн агшинг авч чадсангүй."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Дэлгэцийн агшинг хадгалж чадсангүй. Сан ашиглагдаж байгаа бололтой."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB файл шилжүүлэх сонголт"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Медиа тоглуулагч(MTP) болгон залгах"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Камер болгон(PTP) залгах"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Мас-д зориулсан  Андройд Файл Шилжүүлэх апп-г суулгана уу"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Буцах"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Гэрийн"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Цэс"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Сүүлийн апп"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Хайх"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Камер"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Оруулах аргыг сэлгэх товч."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Тохиромжтой өсгөх товч."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Жижгээс том дэлгэцрүү өсгөх."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Блютүүт холбогдсон."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Блютүүт тасрав."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Батерей байхгүй."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Батерей нэг баганатай."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Батерей хоёр баганатай."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Батерей гурван баганатай."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Батерей дүүрэн."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Утас байхгүй."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Утас нэг баганатай."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Утас хоёр баганатай."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Утас гурван баганатай."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Утасны дохио дүүрэн."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Дата байхгүй."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Дата нэг баганатай."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Дата хоёр баганатай."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Дата гурван баганатай."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Дата дохио дүүрэн."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi унтарсан."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi салав."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi нэг баганатай."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi хоёр баганатай."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi гурван баганатай."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi дохио дүүрэн."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX байхгүй."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX нэг багана."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX хоёр баганатай."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX гурван баганатай."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX дохио дүүрэн."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Дохио байхгүй."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Холбогдоогүй."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Тэг баганатай."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Нэг баганатай."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Хоёр багана."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Гурван баганатай."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Дохио дүүрэн."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Идэвхижсэн."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Унтраах"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Холбогдсон."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Рүүминг"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM байхгүй."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Блютүүт модем болж байна."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Нислэгийн горим"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Батерей <xliff:g id="NUMBER">%d</xliff:g> хувьтай."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Системийн тохиргоо."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Мэдэгдэл."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Мэдэгдлийг цэвэрлэх."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS идэвхтэй."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS хайж байна."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter идэвхтэй болов."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Хонхны чичиргээ."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Хонхыг хаах."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> байхгүй."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Мэдэгдэл хаагдсан."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Мэдэгдлийн хураангуй самбар"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Шуурхай тохиргоо."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Сүүлийн апп"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Хэрэглэгч <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Мобайл <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Батерей <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Нислэгийн горим <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Блютүүт <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Сэрүүлгийг <xliff:g id="TIME">%s</xliff:g>-д тохируулсан."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G дата идэвхгүй болов"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G дата идэвхгүй байна"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Мобайл дата идэвхгүй болов"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Дата идэвхгүй болов"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Та заасан дата ашиглалтын хязгаарт хүрэв.\n\nХэрэв та датаг дахин идэвхжүүлбэл операторт төлбөр төлөх хэрэгтэй."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Дата дахин идэвхжүүлэх"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Интернет холболт байхгүй"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi холбогдсон"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS хайж байна"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS байршил"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Байршлын хүсэлтүүд идэвхтэй"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Бүх мэдэгдлийг цэвэрлэх."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Апп мэдээлэл"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Дэлгэц автоматаар эргэнэ."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Дэлгэц хэвтээ чиглэлд түгжигдсэн."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Дэлгэц босоо чиглэлээр түгжигдсэн."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Амттаны хайрцаг"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Этернет"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Нислэгийн горим"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Цэнэглэж байна, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Цэнэглэгдсэн"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Блютүүт"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Блютүүт (<xliff:g id="NUMBER">%d</xliff:g> төхөөрөмж)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Блютүүт унтраалттай"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Тодрол"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Автомат эргэх"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Эргүүлэлт түгжигдсэн"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Оруулах арга"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Байршил"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Байршил идэвхгүй"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Медиа төхөөрөмж"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Зөвхөн яаралтай дуудлага"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Тохиргоо"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Цаг"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Би"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Холбогдоогүй"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Сүлжээгүй"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi унтарсан"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi Дэлгэц"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Утасгүй дэлгэц"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Тодрол"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АВТОМАТ"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Сүлжээ хянагдаж\nбайж болзошгүй"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-mn/strings.xml b/packages/SystemUI/res/values-mn/strings.xml
deleted file mode 100644
index aea7be1..0000000
--- a/packages/SystemUI/res/values-mn/strings.xml
+++ /dev/null
@@ -1,208 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Систем UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Цэвэрлэх"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Жагсаалтаас устгах"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Апп мэдээлэл"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Сүүлийн апп хоосон"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Сүүлийн апп-уудыг хаах"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 сүүлийн апп"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d сүүлийн апп"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Мэдэгдэл байхгүй"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Гарсан"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Мэдэгдэл"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Цэнэглэгчийг холбоно уу"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Батерей дуусаж байна."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> үлдсэн"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB цэнэглэлт дэмжигдэхгүй байна.\nЗөвхөн нийлүүлэгдсэн цэнэглэгчийг ашиглана уу."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Батерей ашиглах"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Тохиргоо"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Нислэгийн горим"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Дэлгэцийг автоматаар эргүүлэх"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"ХААХ"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"АВТОМАТ"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Мэдэгдэл"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Блютүүтыг модем болгож байна"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Оруулах аргыг тохируулах"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Бодит гар"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"<xliff:g id="APPLICATION">%1$s</xliff:g> апп-г USB төхөөрөмжид хандахыг зөвшөөрөх үү?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"<xliff:g id="APPLICATION">%1$s</xliff:g> апп-г USB төхөөрөмжид хандахыг зөвшөөрөх үү?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Энэ USB төхөөрөмж холбогдох үед <xliff:g id="ACTIVITY">%1$s</xliff:g>-г нээх үү?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Энэ USB төхөөрөмж холбогдох үед <xliff:g id="ACTIVITY">%1$s</xliff:g>-г нээх үү?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Энэ USB хэрэгсэл дээр суулгасан апп ажиллаагүй байна. Энэ хэрэгслийн талаар <xliff:g id="URL">%1$s</xliff:g>-с дэлгэрэнгүй үзнэ үү."</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB төхөөрөмж"</string>
-    <string name="label_view" msgid="6304565553218192990">"Үзэх"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Энэ USB төхөөрөмжийг үндсэн болгон ашиглах"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Энэ USB төхөөрөмжийг үндсэн болгон ашиглах"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB дебаг хийхийг зөвшөөрөх үү?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Компьютерийн RSA түлхүүрийн хурууны хээ :\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Энэ компьютерээс орохыг байнга зөвшөөрөх"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Дэлгэц дүүргэх бол өсгөнө үү"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Дэлгэц дүүргэх бол татна уу"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Дэлгэцийн агшинг хадгалж байна…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Дэлгэцийн агшинг хадгалж байна…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Дэлгэцийн агшин хадгалагдав."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Дэлгэцийн агшинг авсан."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Дэлгэцийн агшныг харах бол хүрнэ үү."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Дэлгэцийн агшинг авч чадсангүй."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Дэлгэцийн агшинг хадгалж чадсангүй. Сан ашиглагдаж байгаа бололтой."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB файл шилжүүлэх сонголт"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Медиа тоглуулагч(MTP) болгон залгах"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Камер болгон(PTP) залгах"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Мас-д зориулсан  Андройд Файл Шилжүүлэх апп-г суулгана уу"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Буцах"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Гэрийн"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Цэс"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Сүүлийн апп"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Оруулах аргыг сэлгэх товч."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Тохиромжтой өсгөх товч."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Жижгээс том дэлгэцрүү өсгөх."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Блютүүт холбогдсон."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Блютүүт тасрав."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Батерей байхгүй."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Батерей нэг баганатай."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Батерей хоёр баганатай."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Батерей гурван баганатай."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Батерей дүүрэн."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Утас байхгүй."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Утас нэг баганатай."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Утас хоёр баганатай."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Утас гурван баганатай."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Утасны дохио дүүрэн."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Дата байхгүй."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Дата нэг баганатай."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Дата хоёр баганатай."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Дата гурван баганатай."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Дата дохио дүүрэн."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi унтарсан."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi салав."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi нэг баганатай."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi хоёр баганатай."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"Wifi гурван баганатай."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi дохио дүүрэн."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX байхгүй."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX нэг багана."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX хоёр баганатай."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX гурван баганатай."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX дохио дүүрэн."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Дохио байхгүй."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Холбогдоогүй."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Тэг баганатай."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Нэг баганатай."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Хоёр багана."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Гурван баганатай."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Дохио дүүрэн."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Идэвхижсэн."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Унтраах"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Холбогдсон."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Рүүминг"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM байхгүй."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Блютүүт модем болж байна."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Нислэгийн горим"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Батерей <xliff:g id="NUMBER">%d</xliff:g> хувьтай."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Системийн тохиргоо."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Мэдэгдэл."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Мэдэгдлийг цэвэрлэх."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS идэвхтэй."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS хайж байна."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter идэвхтэй болов."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Хонхны чичиргээ."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Хонхыг хаах."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> байхгүй."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Мэдэгдэл хаагдсан."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Мэдэгдлийн хураангуй самбар"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Шуурхай тохиргоо."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Сүүлийн апп"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Хэрэглэгч <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Мобайл <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Батерей <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Нислэгийн горим <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Блютүүт <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Сэрүүлгийг <xliff:g id="TIME">%s</xliff:g>-д тохируулсан."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G дата идэвхгүй болов"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G дата идэвхгүй байна"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Мобайл дата идэвхгүй болов"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Дата идэвхгүй болов"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Та заасан дата ашиглалтын хязгаарт хүрэв.\n\nХэрэв та датаг дахин идэвхжүүлбэл операторт төлбөр төлөх хэрэгтэй."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Дата дахин идэвхжүүлэх"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Интернет холболт байхгүй"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi холбогдсон"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS хайж байна"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS байршил"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Байршлын хүсэлтүүд идэвхтэй"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Бүх мэдэгдлийг цэвэрлэх."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Апп мэдээлэл"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Дэлгэц автоматаар эргэнэ."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Дэлгэц хэвтээ чиглэлд түгжигдсэн."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Дэлгэц босоо чиглэлээр түгжигдсэн."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Этернет"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Нислэгийн горим"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Цэнэглэж байна, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Цэнэглэгдсэн"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Блютүүт"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Блютүүт (<xliff:g id="NUMBER">%d</xliff:g> төхөөрөмж)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Блютүүт унтраалттай"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Тодрол"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Автомат эргэх"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Эргүүлэлт түгжигдсэн"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Оруулах арга"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Байршил"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Байршил идэвхгүй"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Медиа төхөөрөмж"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Зөвхөн яаралтай дуудлага"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Тохиргоо"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Цаг"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Би"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Холбогдоогүй"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Сүлжээгүй"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi унтарсан"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi Дэлгэц"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Утасгүй дэлгэц"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Тодрол"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АВТОМАТ"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"Мэдэгдэл энд харагдана"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"Доош татаад тэдгээрт хандана уу.\nДахин доош татаад систем контролд хандана уу."</string>
-    <string name="ssl_ca_cert_warning" msgid="5848402127455021714">"Сүлжээ хянагдаж байж болзошгүй"</string>
-    <string name="done_button" msgid="1759387181766603361">"Дууссан"</string>
-    <string name="ssl_ca_cert_dialog_title" msgid="1273796967092027291">"Сүлжээний Хяналт"</string>
-    <string name="ssl_ca_cert_info_message" msgid="5430320539555358452">"Энэ төхөөрөмжийг удирдагч: <xliff:g id="MANAGING_DOMAIN">%s</xliff:g>.\n\nТаны админ имэйл, апп-ууд болон аюулгүй вебсайтуудыг оруулан таны сүлжээний үйл ажиллагааг хянах боломжтой.\n\nДэлгэрэнгүй мэдээллийг өөрийн админтай холбогдож авна уу."</string>
-    <string name="ssl_ca_cert_warning_message" msgid="2033091656129963669">"Гуравдагч талын этгээд таны сүлжээг хянаж байж болзошгүй\nүүнд имэйл, апп-ууд болон аюулгүй вебсайтууд багтана.\n\nТаны төхөөрөмж дээр суулгасан итгэмжлэгдсэн жуух энэ боломжоор хангаж байна."</string>
-    <string name="ssl_ca_cert_settings_button" msgid="7946956977377166709">"Итгэмжлэгдсэн жуухуудыг шалгах"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ms-rMY-land/strings.xml b/packages/SystemUI/res/values-ms-rMY-land/strings.xml
deleted file mode 100644
index 175b0fa..0000000
--- a/packages/SystemUI/res/values-ms-rMY-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"Skrin kini dikunci dalam orientasi landskap."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ms-rMY/strings.xml b/packages/SystemUI/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 7aa20fc..0000000
--- a/packages/SystemUI/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"Sistem UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"Pdm bersih"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Alih keluar dari senarai"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Maklumat aplikasi"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Tiada aplikasi terbaharu"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Buang aplikasi terbaharu"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 aplikasi terbaharu"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d aplikasi terbaharu"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Tiada pemberitahuan"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Sedang berlangsung"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"Pemberitahuan"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"Sambungkan pengecas"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"Bateri semakin lemah."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"Berbaki <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"Pengecasan USB tidak disokong.\nGunakan hanya pengecas yang dibekalkan."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"Penggunaan bateri"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"Tetapan"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"Mod pesawat"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"Autoputar skrin"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"REDAM"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"AUTO"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"Pemberitahuan"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"Bluetooth ditambatkan"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Sediakan kaedah input"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Papan kekunci fizikal"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Benarkan aplikasi <xliff:g id="APPLICATION">%1$s</xliff:g> mengakses peranti USB?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Benarkan aplikasi <xliff:g id="APPLICATION">%1$s</xliff:g> mengakses aksesori USB?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Buka <xliff:g id="ACTIVITY">%1$s</xliff:g> apabila peranti USB ini disambungkan?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Buka <xliff:g id="ACTIVITY">%1$s</xliff:g> apabila aksesori USB ini disambungkan?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Tiada apl yg dipsg bfungsi dgn aksesori USB ini. Ketahui lg ttg aksesori ini di <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"Aksesori USB"</string>
-    <string name="label_view" msgid="6304565553218192990">"Lihat"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"Gunakan secara lalai untuk peranti USB ini"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"Gunakan secara lalai untuk aksesori USB ini"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"Benarkan penyahpepijatan USB?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"Cap jari kekunci RSA komputer ialah:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"Sentiasa benarkan komputer ini"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"Zum untuk memenuhi skrin"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"Regang utk memenuhi skrin"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Menyimpan tangkapan skrin..."</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"Menyimpan tangkapan skrin..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"Tangkapan skrin sedang disimpan."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"Tangkapan skrin ditangkap."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"Sentuh untuk melihat tangkapan skrin anda."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"Tidak dapat menangkap tangkapan skrin."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"Tidak boleh menyimpan tangkapan skrin. Storan mungkin sedang digunakan."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"Pilihan pemindahan fail USB"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"Lekapkan sebagai pemain media (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"Lekapkan sebagai kamera (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Pasang aplikasi Pindahan Fail Android untuk Mac"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"Kembali"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"Rumah"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"Aplikasi terbaharu"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Cari"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Butang tukar kaedah input."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Butang zum keserasian."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Skrin zum lebih kecil kepada lebih besar."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"Bluetooth disambungkan."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"Bluetooth diputuskan sambungan."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"Tiada bateri."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"Bateri satu bar."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"Bateri dua bar."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"Bateri tiga bar."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"Bateri penuh."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"Tiada telefon."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"Telefon satu bar."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"Telefon dua bar."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"Telefon tiga bar."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"Isyarat telefon penuh."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"Tiada data."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"Data satu bar."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"Data dua bar."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"Data tiga bar."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"Isyarat data penuh."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi dimatikan."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi diputuskan sambungannya."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"WiFi satu bar."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"WiFi dua bar."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi tiga bar."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Isyarat WiFi penuh."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"Tiada WiMAX"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX satu bar."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX dua bar."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX tiga bar."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"Isyarat WiMAX penuh."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"Tiada isyarat."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"Tidak disambungkan."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"Tiada bar."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"Satu bar."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"Dua bar."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"Tiga bar."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"Isyarat penuh."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"Dihidupkan."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"Dimatikan."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"Disambungkan."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"Perayauan"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"Tiada SIM."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Penambatan Bluetooth."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Mod pesawat"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"Bateri <xliff:g id="NUMBER">%d</xliff:g> peratus."</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"Tetapan sistem."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"Pemberitahuan."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"Padamkan pemberitahuan."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS didayakan."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS sedang mendapatkan."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"Mesin Teletaip didayakan."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"Pendering bergetar."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"Pendering senyap."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> ditolak."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"Pemberitahuan diketepikan."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"Bidai pemberitahuan."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"Tetapan pantas."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"Apl terbaru."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"Pengguna <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"Mudah Alih <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"Bateri <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"Mod Pesawat <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"Bluetooth <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"Penggera ditetapkan pada <xliff:g id="TIME">%s</xliff:g>."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"Data 2G-3G dilumpuhkan"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"Data 4G dilumpuhkan"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"Data mudah alih dilumpuhkan"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"Data dilumpuhkan"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"Anda telah mencapai had penggunaan data yang dinyatakan.\n\nJika anda mendayakan semula data, anda mungkin dikenakan caj oleh operator."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"Dayakan semula data"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"Tiada smbg Internet"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi disambungkan"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"Mencari GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokasi ditetapkan oleh GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Permintaan lokasi aktif"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"Padamkan semua pemberitahuan."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Maklumat apl"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Skrin akan berputar secara automatik."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Skrin dikunci dalam orientasi landskap."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Skrin dikunci dalam orientasi potret."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Bekas Pencuci Mulut"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Lamun"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Mod kapal terbang"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Mengecas, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Sudah dicas"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> Peranti)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth Dimatikan"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Kecerahan"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Auto Putar"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Putaran Dikunci"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"Kaedah Input"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Lokasi"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Lokasi Dimatikan"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Peranti media"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Panggilan Kecemasan Sahaja"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"Tetapan"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"Masa"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"Saya"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"Tidak Disambungkan"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"Tiada Rangkaian"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi Dimatikan"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Paparan Wi-Fi"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Paparan Wayarles"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Kecerahan"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Rangkaian mungkin\nboleh dipantau"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ms/strings.xml b/packages/SystemUI/res/values-ms/strings.xml
index 9c76eae..5312ccb 100644
--- a/packages/SystemUI/res/values-ms/strings.xml
+++ b/packages/SystemUI/res/values-ms/strings.xml
@@ -164,7 +164,6 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi disambungkan"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Mencari GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokasi ditetapkan oleh GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Permintaan lokasi aktif"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Padamkan semua pemberitahuan."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Maklumat apl"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Skrin akan berputar secara automatik."</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Auto Putar"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Putaran Dikunci"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Kaedah Input"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Lokasi"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Lokasi Dimatikan"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Peranti media"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Panggilan Kecemasan Sahaja"</string>
@@ -201,4 +202,6 @@
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
     <string name="status_bar_help_title" msgid="1199237744086469217">"Pemberitahuan dipaparkan di sini"</string>
     <string name="status_bar_help_text" msgid="7874607155052076323">"Akses panel pada bila-bila masa dengan meleret ke bawah.\nLeret ke bawah sekali lagi untuk mendapatkan kawalan sistem."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Leret ke bahagian tepi skrin untuk menampakkan bar"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Leret dari tepi skrin untuk menampakkan bar sistem"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-nb/strings.xml b/packages/SystemUI/res/values-nb/strings.xml
index 56db18f..778be83 100644
--- a/packages/SystemUI/res/values-nb/strings.xml
+++ b/packages/SystemUI/res/values-nb/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Tillat alltid fra denne datamaskinen"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom for å fylle skjermen"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Strekk for å fylle skjerm"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Kompatibilitets-zooming"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Når en app er utformet for en mindre skjerm, vises det en zoomkontroll ved klokken."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Lagrer skjermdumpen …"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Lagrer skjermdumpen …"</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Skjermdumpen lagres."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Startside"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Meny"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Nylige apper"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Søk"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Bytt knapp for inndatametode."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Zoomknapp for kompatibilitet."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom fra mindre til større skjerm."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi tilkoblet"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Søker etter GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Posisjon angitt av GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktive stedsforespørsler"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Fjern alle varslinger."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Info om app"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Skjermen roterer automatisk."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Skjermen er låst i liggende retning."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Skjermen er låst i stående retning."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessertmonter"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Dagdrøm"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Flymodus"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Trådløs skjerm"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Lysstyrke"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Nettverket kan\nvære overvåket"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Varslene vises her"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Bruk dem når som helst ved å sveipe nedover.\nSveip nedover igjen for å gå til systemkontrollene."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Sveip på kanten av skjermen for å få frem feltet"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Sveip fra kanten på skjermen for å få frem systemfeltet"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ne-rNP-land/strings.xml b/packages/SystemUI/res/values-ne-rNP-land/strings.xml
deleted file mode 100644
index 8d5286e..0000000
--- a/packages/SystemUI/res/values-ne-rNP-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"स्क्रिन अहिले ल्यान्डस्केप अवस्थामा बन्द छ।"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ne-rNP/strings.xml b/packages/SystemUI/res/values-ne-rNP/strings.xml
deleted file mode 100644
index 9e6605e..0000000
--- a/packages/SystemUI/res/values-ne-rNP/strings.xml
+++ /dev/null
@@ -1,206 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"प्रणाली UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"हटाउनुहोस्"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"सूचीबाट हटाउनुहोस्"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"अनुप्रयोगको जानकारी"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"कुनै नयाँ अनुप्रयोगहरू छैनन्"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"नयाँ अनुप्रयोगहरू खारेज गर्नुहोस्"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"१ भरखरै अनुप्रयोग"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d भरखरैका अनुप्रयोगहरू"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"कुनै सूचनाहरू छैन"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"चलिरहेको"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"सूचनाहरू"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"चार्जर जडान गर्नुहोस्"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ब्याट्रि न्यून हुँदै छ।"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> बाँकी"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB चार्ज गर्न समर्थित छैन।\n आपूर्ति गरिएको चार्जर मात्र प्रयोग गर्नुहोस्।"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ब्याट्रि प्रयोग"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"सेटिङहरू"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"वाइफाइ"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"हवाइजहाज मोड"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"स्वत:घुम्ने स्क्रिन"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"म्युट गर्नुहोस्"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"स्वतः"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"सूचनाहरू"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"ब्लुटुथ टेथर भयो"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"इनपुट विधिहरू सेटअप गर्नुहोस्"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"फिजिकल किबोर्ड"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"<xliff:g id="APPLICATION">%1$s</xliff:g> USB उपकरणलाई पहुँच दिनको लागि अनुप्रयोगलाई अनुमति दिने हो?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"<xliff:g id="APPLICATION">%1$s</xliff:g> USB पाटपुर्जालाई पहुँच दिनको लागि अनुप्रयोगलाई अनुमति दिने हो?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"यो USB उपकरण जोडिएको बेला <xliff:g id="ACTIVITY">%1$s</xliff:g> खोल्ने हो?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"यो USB सहायक जडान हुँदा <xliff:g id="ACTIVITY">%1$s</xliff:g> खोल्ने हो?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"यस USB उपकरणसँग स्थापित अनुप्रयोग काम गर्दैन। यस उपकरणको बारेमा <xliff:g id="URL">%1$s</xliff:g> मा धेरै जान्नुहोस्"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB सहयोगी"</string>
-    <string name="label_view" msgid="6304565553218192990">"दृश्य"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"यो USB उपकरणको लागि पूर्वनिर्धारितबाट प्रयोग गर्नुहोस्"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"यस USB सहायक सामानको लागि पूर्वनिर्धारितद्वारा प्रयोग गर्नुहोस्"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB डिबग गर्नको लागि अनुमति दिने हो?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"कम्प्युटरको RSA कुञ्जी औंलाछाप:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"यो कम्प्युटरबाट सधैँ अनुमति दिनुहोस्"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"स्क्रिन भर्न जुम गर्नुहोस्"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"स्क्रिन भर्न तन्काउनुहोस्"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"स्क्रिनसट बचत गर्दै…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"स्क्रिनसट बचत गर्दै…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"स्क्रिनसट बचत हुँदै छ।"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"स्क्रिनसट क्याप्चर गरियो।"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"तपाईँको स्क्रिनसट हेर्न छुनुहोस्।"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"स्क्रिनसट क्याप्चर गर्न सकिएन।"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"स्क्रिनसटलाई बचत गर्न सकेन। भण्डारण उपयोगमा हुन सक्छ।"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB फाइल सार्ने विकल्पहरू"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"मिडिया प्लेयर(MTP)को रूपमा माउन्ट गर्नुहोस्"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"क्यामेराको रूपमा माउन्ट गर्नुहोस् (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"म्याकको लागि एन्ड्रोइड फाइल ट्रान्सफर अनुप्रयोग स्थापना गर्नुहोस्"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"पछाडि"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"गृह"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"मेनु"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"भर्खरका अनुप्रयोगहरू"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"इनपुट विधि बटन स्विच गर्नुहोस्।"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"मिलाउने जुम बटन।"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"स्क्रिनलाई सानोबाट ठूलो पार्नुहोस्।"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"ब्लुटुथ जडान भयो।"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"ब्लुटुथसँग विच्छेद गरियो।"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"कुनै ब्याट्रि छैन।"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ब्याट्रि एउटा पट्टि।"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ब्याट्रिका दुईवटा पट्टिहरू"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ब्याट्रिका तिनवटा पट्टिहरू"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ब्याट्रि पूर्ण छ।"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"फोन छैन्।"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"फोन एउटा पट्टि।"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"फोन दुई पट्टि।"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"फोन तिन पट्टिहरू।"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"फोन सङ्केत भरिएको।"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"डेटा छैन।"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"डेटाको एउटा पट्टि।"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"डेटा दुई बाधाहरू।"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"डेटा तिन बाधाहरू।"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"डेटा संकेत पूर्ण।"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"वाइफाइ बन्द।"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"वाइफाइ विच्छेद भयो।"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"वाइफाइ एक पट्टि।"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"वाइफाइ दुई पट्टि।"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"वाइफाइ तिन बारहरू।"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"वाइफाइ सङ्केत भरिएको।"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"वाइम्यास छैन।"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX एउटा पट्टि।"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"वाइम्याक्स दुईवटा बारहरू।"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"वाइम्याक्स तिनवटा बारहरू।"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"वाइम्याक्स सङ्केत भरिएका।"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"सङ्केत छैन।"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"जडान नगरिएको।"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"शून्य पट्टि।"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"एउटा बार।"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"दुई पट्टिहरू।"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"तिनवटा पट्टिहरू"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"सङ्केत पूर्ण छ।"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"चालु।"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"बन्द गर्नुहोस्।"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"जडान गरिएको।"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"रोमिङ"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"वाइफाइ"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM छैन।"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"ब्लुटुथ टेदर गर्दै।"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"हवाइजहाज मोड।"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ब्याट्रि <xliff:g id="NUMBER">%d</xliff:g> प्रतिशत"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"प्रणाली सेटिङहरू"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"सूचनाहरू।"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"सूचना खाली गर्नुहोस्।"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS सक्षम गरिएको"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS प्राप्त हुँदैछ।"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"टेलि टाइपराइटर सक्षम गरियो।"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"बज्ने कम्पन हुन्छ।"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"घन्टी मौन।"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> खारेज गरिएको छ।"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"सूचना खारेज।"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"सूचना कक्ष।"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"द्रुत सेटिङहरू"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"वर्तमान अनुप्रयोगहरू"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"प्रयोगकर्ता <xliff:g id="USER">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>। <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"मोवाइल <xliff:g id="SIGNAL">%1$s</xliff:g>। <xliff:g id="TYPE">%2$s</xliff:g>। <xliff:g id="NETWORK">%3$s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ब्याट्रि <xliff:g id="STATE">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"हवाजहाज मोड <xliff:g id="STATE">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"ब्लुटुथ <xliff:g id="STATE">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"<xliff:g id="TIME">%s</xliff:g>को लागि सङ्केत घन्टी सेट गरिएको"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G डेटा अक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G डेटा असक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"मोबाइल डेटा अक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"डेटा अक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"तपाईँ निर्दिष्ट डेटा उपयोग सीमामा पुग्नु भएको छ।\n\nयदि तपाईँले डेटालाई पुनःसक्षम पार्नु भयो भने तपाईँलाई अर्को संचालकबाट शुल्क लगाउन सक्छ।"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"डेटा पुनः सक्षम गर्नुहोस्"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"इन्टरनेट जडान छैन"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"वाइफाइ जडित"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPSको लागि खोजी गर्दै"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS द्वारा स्थान सेट गरिएको"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"स्थान अनुरोधहरू सक्रिय"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"सबै सूचनाहरू हटाउनुहोस्।"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"अनुप्रयोगको जानकारी"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"स्क्रिन स्वतः घुम्ने छ।"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"स्क्रिनलाई ल्यान्डस्केप अवस्थामा बन्द गरिएको छ।"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"स्क्रिन पोर्टेट अभिमूखमा लक गरिएको छ।"</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"दिवासपना"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"हवाइजहाज मोड"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"चार्ज हुँदै, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"चार्ज भयो"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"ब्लुटुथ"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"ब्लुटुथ (<xliff:g id="NUMBER">%d</xliff:g> उपकरणहरू)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"ब्लुटुथ बन्द"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"चमक"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"स्वतः घुमाइ"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"घुम्ने लक गरेको"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"आगत विधि"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"स्थान"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"स्थान बन्द छ"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"मिडिया उपकरण"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"आकस्मिक कल मात्र"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"सेटिङहरू"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"समय"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"मलाई"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"वाइफाइ"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"जोडिएको छैन"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"नेटवर्क छैन"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"वाइफाइ बन्द"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"वाइफाइ प्रदर्शन"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"ताररहित प्रदर्शन"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"उज्यालपन"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"स्वतः"</string>
-    <string name="ssl_ca_cert_warning" msgid="5848402127455021714">"सञ्जाल अनुगमित हुन सक्छ"</string>
-    <string name="done_button" msgid="1759387181766603361">"भयो"</string>
-    <string name="ssl_ca_cert_dialog_title" msgid="1273796967092027291">"सञ्जाल निगरानी"</string>
-    <string name="ssl_ca_cert_info_message" msgid="5430320539555358452">"यो उपकरण <xliff:g id="MANAGING_DOMAIN">%s</xliff:g>द्वारा प्रबन्धित छ। \n \n तपाईँको प्रशासक तपाईँको अनुप्रयोग र सुरक्षित वेब साइट लगायत सञ्जाल गतिविधि अनुगमन गर्न सक्षम छ। \n \n थप जानकारीको लागि तपाईँको प्रशासकसँग सम्पर्क राख्नुहोस्।"</string>
-    <string name="ssl_ca_cert_warning_message" msgid="2033091656129963669">"एक तेस्रो पक्ष तपाईँको सञ्जाल\n गतिविधि, इमेल, अनुप्रयोग र सुरक्षित वेबसाइट अनुगमन गर्न सक्षम छ। \n \n तपाईँको उपकरणमा स्थापित एक विश्वसनीय प्रामाणिक डेटाले सम्भव तुल्याइरहेको छ।"</string>
-    <string name="ssl_ca_cert_settings_button" msgid="7946956977377166709">"विश्वसनीय प्रामाणिक डेटा जाँच गर्नुहोस्"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-ne/strings.xml b/packages/SystemUI/res/values-ne/strings.xml
deleted file mode 100644
index c3eee01..0000000
--- a/packages/SystemUI/res/values-ne/strings.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"प्रणाली UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"हटाउनुहोस्"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"सूचीबाट हटाउनुहोस्"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"अनुप्रयोगको जानकारी"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"कुनै नयाँ अनुप्रयोगहरू छैनन्"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"नयाँ अनुप्रयोगहरू खारेज गर्नुहोस्"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"१ भरखरै अनुप्रयोग"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d भरखरैका अनुप्रयोगहरू"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"कुनै सूचनाहरू छैन"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"चलिरहेको"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"सूचनाहरू"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"चार्जर जडान गर्नुहोस्"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"ब्याट्रि न्यून हुँदै छ।"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> बाँकी"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB चार्ज गर्न समर्थित छैन।\n आपूर्ति गरिएको चार्जर मात्र प्रयोग गर्नुहोस्।"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"ब्याट्रि प्रयोग"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"सेटिङहरू"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"वाइ-फाइ"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"हवाइजहाज मोड"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"स्वत:घुम्ने स्क्रिन"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"म्युट गर्नुहोस्"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"स्वतः"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"सूचनाहरू"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"ब्लुटुथ टेथर भयो"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"इनपुट विधिहरू सेटअप गर्नुहोस्"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"फिजिकल किबोर्ड"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"<xliff:g id="APPLICATION">%1$s</xliff:g> USB उपकरणलाई पहुँच दिनको लागि अनुप्रयोगलाई अनुमति दिने हो?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"<xliff:g id="APPLICATION">%1$s</xliff:g> USB पाटपुर्जालाई पहुँच दिनको लागि अनुप्रयोगलाई अनुमति दिने हो?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"यो USB उपकरण जोडिएको बेला <xliff:g id="ACTIVITY">%1$s</xliff:g> खोल्ने हो?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"यो USB सहायक जडान हुँदा <xliff:g id="ACTIVITY">%1$s</xliff:g> खोल्ने हो?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"यस USB उपकरणसँग स्थापित अनुप्रयोग काम गर्दैन। यस उपकरणको बारेमा <xliff:g id="URL">%1$s</xliff:g> मा धेरै जान्नुहोस्"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB सहयोगी"</string>
-    <string name="label_view" msgid="6304565553218192990">"दृश्य"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"यो USB उपकरणको लागि पूर्वनिर्धारितबाट प्रयोग गर्नुहोस्"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"यस USB सहायक सामानको लागि पूर्वनिर्धारितद्वारा प्रयोग गर्नुहोस्"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB डिबग गर्नको लागि अनुमति दिने हो?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"कम्प्युटरको RSA कुञ्जी औंलाछाप:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"यो कम्प्युटरबाट सधैँ अनुमति दिनुहोस्"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"स्क्रिन भर्न जुम गर्नुहोस्"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"स्क्रिन भर्न तन्काउनुहोस्"</string>
-    <string name="compat_mode_help_header" msgid="7969493989397529910">"अनुकूलता जुम"</string>
-    <string name="compat_mode_help_body" msgid="4946726776359270040">"जब कुनै अनुप्रयोग सानो स्क्रिनको लागि बनाइएको हुन्छ, तब जुम नियन्त्रण घडीको नजिक देखिन्छ।"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"स्क्रिनसट बचत गर्दै…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"स्क्रिनसट बचत गर्दै…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"स्क्रिनसट बचत हुँदै छ।"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"स्क्रिनसट क्याप्चर गरियो।"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"तपाईँको स्क्रिनसट हेर्न छुनुहोस्।"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"स्क्रिनसट क्याप्चर गर्न सकिएन।"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"स्क्रिनसटलाई बचत गर्न सकेन। भण्डारण उपयोगमा हुन सक्छ।"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB फाइल सार्ने विकल्पहरू"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"मिडिया प्लेयर(MTP)को रूपमा माउन्ट गर्नुहोस्"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"क्यामेराको रूपमा माउन्ट गर्नुहोस् (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"म्याकको लागि एन्ड्रोइड फाइल ट्रान्सफर अनुप्रयोग स्थापना गर्नुहोस्"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"पछाडि"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"गृह"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"मेनु"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"भर्खरका अनुप्रयोगहरू"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"इनपुट विधि बटन स्विच गर्नुहोस्।"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"मिलाउने जुम बटन।"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"स्क्रिनलाई सानोबाट ठूलो पार्नुहोस्।"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"ब्लुटुथ जडान भयो।"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"ब्लुटुथसँग विच्छेद गरियो।"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"कुनै ब्याट्रि छैन।"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"ब्याट्रि एउटा पट्टि।"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"ब्याट्रिका दुईवटा पट्टिहरू"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"ब्याट्रिका तिनवटा पट्टिहरू"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"ब्याट्रि पूर्ण छ।"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"फोन छैन्।"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"फोन एउटा पट्टि।"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"फोन दुई पट्टि।"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"फोन तिन पट्टिहरू।"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"फोन सङ्केत भरिएको।"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"डेटा छैन।"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"डेटाको एउटा पट्टि।"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"डेटा दुई बाधाहरू।"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"डेटा तिन बाधाहरू।"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"डेटा संकेत पूर्ण।"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"वाइफाइ बन्द।"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"वाइफाइ विच्छेद भयो।"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"वाइफाइ एक पट्टि।"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"वाइफाइ दुई पट्टि।"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"वाइफाइ तिन बारहरू।"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"वाइफाइ सङ्केत भरिएको।"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"वाइम्यास छैन।"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX एउटा पट्टि।"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"वाइम्याक्स दुईवटा बारहरू।"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"वाइम्याक्स तिनवटा बारहरू।"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"वाइम्याक्स सङ्केत भरिएका।"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"सङ्केत छैन।"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"जडान नगरिएको।"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"शून्य पट्टि।"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"एउटा बार।"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"दुई पट्टिहरू।"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"तिनवटा पट्टिहरू"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"सङ्केत पूर्ण छ।"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"चालु।"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"बन्द गर्नुहोस्।"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"जडान गरिएको।"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"रोमिङ"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"वाइ-फाइ"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM छैन।"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"ब्लुटुथ टिथर गर्दै।"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"हवाइजहाज मोड।"</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"ब्याट्रि <xliff:g id="NUMBER">%d</xliff:g> प्रतिशत"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"प्रणाली सेटिङहरू"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"सूचनाहरू।"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"सूचना खाली गर्नुहोस्।"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS सक्षम गरिएको"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS प्राप्त हुँदैछ।"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"टेलि टाइपराइटर सक्षम गरियो।"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"बज्ने कम्पन हुन्छ।"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"घन्टी मौन।"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> खारेज गरिएको छ।"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"सूचना खारेज।"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"सूचना कक्ष।"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"द्रुत सेटिङहरू"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"वर्तमान अनुप्रयोगहरू"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"प्रयोगकर्ता <xliff:g id="USER">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>। <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"मोवाइल <xliff:g id="SIGNAL">%1$s</xliff:g>। <xliff:g id="TYPE">%2$s</xliff:g>। <xliff:g id="NETWORK">%3$s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"ब्याट्रि <xliff:g id="STATE">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"हवाजहाज मोड <xliff:g id="STATE">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"ब्लुटुथ <xliff:g id="STATE">%s</xliff:g>।"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"<xliff:g id="TIME">%s</xliff:g>को लागि सङ्केत घन्टी सेट गरिएको"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G डेटा अक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G डेटा असक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"मोबाइल डेटा अक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"डेटा अक्षम गरियो"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"तपाईँ निर्दिष्ट डेटा उपयोग सीमामा पुग्नु भएको छ।\n\nयदि तपाईँले डेटालाई पुनःसक्षम पार्नु भयो भने तपाईँलाई अर्को संचालकबाट शुल्क लगाउन सक्छ।"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"डेटा पुनः सक्षम गर्नुहोस्"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"इन्टरनेट जडान छैन"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"वाइ-फाइ जडित"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPSको लागि खोजी गर्दै"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS द्वारा स्थान सेट गरिएको"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"स्थान अनुरोधहरू सक्रिय"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"सबै सूचनाहरू हटाउनुहोस्।"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"अनुप्रयोगको जानकारी"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"स्क्रिन स्वतः घुम्ने छ।"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"स्क्रिनलाई ल्यान्डस्केप अवस्थामा बन्द गरिएको छ।"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"स्क्रिन पोर्टेट अभिमूखमा लक गरिएको छ।"</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"दिवासपना"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"उडान मोड"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"चार्ज हुँदै, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"चार्ज भयो"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"ब्लुटुथ"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"ब्लुटुथ (<xliff:g id="NUMBER">%d</xliff:g> उपकरणहरू)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"ब्लुटुथ बन्द"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"चमक"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"स्वतः घुमाइ"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"घुम्ने लक गरेको"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"आगत विधि"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"स्थान"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"स्थान बन्द छ"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"मिडिया उपकरण"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"आकस्मिक कल मात्र"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"सेटिङहरू"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"समय"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"मलाई"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"वाइ-फाइ"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"जोडिएको छैन"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"नेटवर्क छैन"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"वाइ-फाइ बन्द"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"वाइ-फाइ प्रदर्शन"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"ताररहित प्रदर्शन"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"उज्यालपन"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"स्वतः"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"यहाँ जानकारीहरू देखा पर्छन्"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"तल हुत्त्याएर तिनीहरूलाई सधैं पहुँच गर्नुहोस्\nप्रणाली नियन्त्रणको लागि पुनः तल हुत्त्याउनुहोस्"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-nl/strings.xml b/packages/SystemUI/res/values-nl/strings.xml
index deda030..ab77839 100644
--- a/packages/SystemUI/res/values-nl/strings.xml
+++ b/packages/SystemUI/res/values-nl/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Altijd toestaan vanaf deze computer"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom om scherm te vullen"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Rek uit v. schermvulling"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Compatibiliteitszoom"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Wanneer een app is ontworpen voor een kleiner scherm, wordt naast de klok een zoomknop weergegeven."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Screenshot opslaan..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Screenshot opslaan..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Screenshot wordt opgeslagen."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Startpagina"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Recente apps"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Zoeken"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Camera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Knop voor wijzigen invoermethode."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Knop voor compatibiliteitszoom."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Kleiner scherm uitzoomen naar groter scherm."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Verbonden via wifi"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Zoeken naar GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Locatie bepaald met GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Locatieverzoeken actief"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Alle meldingen wissen."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"App-info"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Scherm wordt automatisch geroteerd."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Het scherm is nu vergrendeld in liggende stand."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Het scherm is nu vergrendeld in staande stand."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessertshowcase"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Dagdroom"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Vliegmodus"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Draadloze display"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Helderheid"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATISCH"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Netwerk kan\nworden gecontroleerd"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Meldingen worden hier weergegeven"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"U kunt de meldingen op elk gewenst moment openen door met uw vinger omlaag te vegen.\nVeeg nogmaals met uw vinger omlaag om de systeembesturingselementen weer te geven."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Veeg vanaf de rand om balk weer te geven"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Veeg vanaf de rand van het scherm om de systeembalk weer te geven"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-pl/strings.xml b/packages/SystemUI/res/values-pl/strings.xml
index 41dfd42..c94cfc8 100644
--- a/packages/SystemUI/res/values-pl/strings.xml
+++ b/packages/SystemUI/res/values-pl/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Zawsze zezwalaj z tego komputera"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Powiększ, aby wypełnić ekran"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Rozciągnij, aby wypełnić ekran"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Powiększenie w trybie zgodności"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Jeśli aplikacja została przystosowana do mniejszego ekranu, obok zegara zostanie wyświetlony element sterujący powiększeniem."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Zapisywanie zrzutu ekranu..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Zapisywanie zrzutu ekranu..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Zapisywanie zrzutu ekranu."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Ekran główny"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Ostatnie aplikacje"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Szukaj"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Aparat"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Przycisk przełączania metody wprowadzania."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Przycisk powiększenia na potrzeby zgodności."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Powiększa mniejszy ekran do większego."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi: połączono"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Wyszukiwanie sygnału GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokalizacja z GPSa"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Prośby o lokalizację są aktywne"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Usuń wszystkie powiadomienia."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"O aplikacji"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekran zostanie obrócony automatycznie."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ekran jest zablokowany w orientacji poziomej."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ekran jest zablokowany w orientacji pionowej."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Półka ze słodkościami"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Wygaszacz ekranu"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Tryb samolotowy"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Wyświetlacz bezprzewodowy"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Jasność"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATYCZNA"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Sieć może być\nmonitorowana"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Tutaj pokazują się powiadomienia"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Możesz je otworzyć w dowolnej chwili, przesuwając w dół.\nPrzesuń jeszcze raz w dół, by otworzyć ustawienia systemowe."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Przesuń palcem od krawędzi ekranu, by odkryć pasek"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Przesuń palcem od krawędzi ekranu, by odkryć pasek systemu"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-pt-rPT/strings.xml b/packages/SystemUI/res/values-pt-rPT/strings.xml
index b1f599b..c106329 100644
--- a/packages/SystemUI/res/values-pt-rPT/strings.xml
+++ b/packages/SystemUI/res/values-pt-rPT/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Permitir sempre a partir deste computador"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom para preencher o ecrã"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Esticar p. caber em ec. int."</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom de compatibilidade"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Sempre que uma aplicação tiver sido concebida para ecrãs mais pequenos, aparecerá um controlo de zoom junto ao relógio."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"A guardar captura de ecrã..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"A guardar captura de ecrã..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"A guardar captura de ecrã."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Página inicial"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Aplicações recentes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Pesquisar"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Câmara"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Alternar botão de método de introdução."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Botão zoom de compatibilidade."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zoom menor para ecrã maior."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi ligado"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"A procurar GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Localização definida por GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Pedidos de localização ativos"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Limpar todas as notificações."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informações da aplicação"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"O ecrã será rodado automaticamente."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"O ecrã está bloqueado na orientação horizontal."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"O ecrã está bloqueado na orientação vertical."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Vitrina de sobremesas"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Modo de avião"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Display Sem Fios"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brilho"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMÁTICO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"A rede pode ser\nmonitorizada"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"As notificações são apresentadas aqui"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Pode aceder em qualquer altura, deslizando rapidamente para baixo com o dedo.\nDeslize novamente para baixo para aceder aos controlos do sistema."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Deslize da extremidade do ecrã para revelar a barra"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Deslize da extremidade do ecrã para revelar a barra do sistema"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-pt/strings.xml b/packages/SystemUI/res/values-pt/strings.xml
index ae9ea1e..91e7f02 100644
--- a/packages/SystemUI/res/values-pt/strings.xml
+++ b/packages/SystemUI/res/values-pt/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Sempre permitir a partir deste computador"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom p/ preencher a tela"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Ampliar p/ preencher tela"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom em modo de compatibilidade"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Quando um aplicativo é desenvolvido para uma tela menor, um controle de zoom é exibido perto do relógio."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Salvando captura de tela..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Salvando captura de tela..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"A captura de tela está sendo salva."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Página inicial"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Aplicativos recentes"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Pesquisar"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Câmera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Alterar botão do método de entrada."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Botão de zoom da compatibilidade."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Aumentar a tela com zoom."</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi conectado"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Buscando GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Local definido por GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Solicitações de localização ativas"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Limpar todas as notificações."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informações do aplicativo"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"A tela girará automaticamente."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"A tela está bloqueada na orientação paisagem."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"A tela está bloqueada na orientação retrato."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Mostruário de sobremesas"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Modo avião"</string>
@@ -185,8 +184,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Girar automat."</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotação bloqueada"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Método de entrada"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Localização"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Localização desativada"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Dispositivo de mídia"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Somente chamadas de emergência"</string>
@@ -201,5 +202,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Display sem fio"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brilho"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"A rede pode estar\nsob monitoração"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"As notificações aparecem aqui"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Acesse a qualquer momento deslizando para baixo.\nDeslize para baixo novamente para acessar os controles do sistema."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Deslize a borda da tela para ver a barra"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Deslize a partir da borda da tela ver a barra do sistema"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-rm/strings.xml b/packages/SystemUI/res/values-rm/strings.xml
index 287b382..d7772ed 100644
--- a/packages/SystemUI/res/values-rm/strings.xml
+++ b/packages/SystemUI/res/values-rm/strings.xml
@@ -92,6 +92,10 @@
     <skip />
     <!-- no translation found for compat_mode_off (4434467572461327898) -->
     <skip />
+    <!-- no translation found for compat_mode_help_header (7969493989397529910) -->
+    <skip />
+    <!-- no translation found for compat_mode_help_body (4946726776359270040) -->
+    <skip />
     <!-- no translation found for screenshot_saving_ticker (7403652894056693515) -->
     <skip />
     <!-- no translation found for screenshot_saving_title (8242282144535555697) -->
@@ -122,10 +126,6 @@
     <skip />
     <!-- no translation found for accessibility_recent (8571350598987952883) -->
     <skip />
-    <!-- no translation found for accessibility_search_light (1103867596330271848) -->
-    <skip />
-    <!-- no translation found for accessibility_camera_button (8064671582820358152) -->
-    <skip />
     <!-- no translation found for accessibility_ime_switch_button (5032926134740456424) -->
     <skip />
     <!-- no translation found for accessibility_compatibility_zoom_button (8461115318742350699) -->
@@ -298,8 +298,6 @@
     <skip />
     <!-- no translation found for gps_notification_found_text (4619274244146446464) -->
     <skip />
-    <!-- no translation found for accessibility_location_active (2427290146138169014) -->
-    <skip />
     <!-- no translation found for accessibility_clear_all (5235938559247164925) -->
     <skip />
     <!-- no translation found for status_bar_notification_inspect_item_title (1163547729015390250) -->
@@ -310,7 +308,7 @@
     <skip />
     <!-- no translation found for accessibility_rotation_lock_on_portrait (5809367521644012115) -->
     <skip />
-    <!-- no translation found for dessert_case (1295161776223959221) -->
+    <!-- no translation found for jelly_bean_dream_name (5992026543636816792) -->
     <skip />
     <!-- no translation found for start_dreams (7219575858348719790) -->
     <skip />
@@ -368,6 +366,12 @@
     <skip />
     <!-- no translation found for quick_settings_brightness_dialog_auto_brightness_label (5064982743784071218) -->
     <skip />
-    <!-- no translation found for ssl_ca_cert_warning (9005954106902053641) -->
+    <!-- no translation found for status_bar_help_title (1199237744086469217) -->
+    <skip />
+    <!-- no translation found for status_bar_help_text (7874607155052076323) -->
+    <skip />
+    <!-- no translation found for hideybar_confirmation_message (9050869548951044371) -->
+    <skip />
+    <!-- no translation found for hideybar_confirmation_message_long (7117692795163620626) -->
     <skip />
 </resources>
diff --git a/packages/SystemUI/res/values-ro/strings.xml b/packages/SystemUI/res/values-ro/strings.xml
index f57c3b5..42e2d48 100644
--- a/packages/SystemUI/res/values-ro/strings.xml
+++ b/packages/SystemUI/res/values-ro/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Permiteţi întotdeauna de pe acest computer"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zoom pt. a umple ecranul"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Înt. pt. a umple ecranul"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom de compatibilitate"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Atunci când o aplicaţie a fost concepută pentru un ecran mai mic, o comandă pentru mărire/micşorare va apărea alături de ceas."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Se salv. captura de ecran..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Se salvează captura de ecran..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Captura de ecran este salvată."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Ecranul de pornire"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Meniu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Aplicaţii recente"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Căutați"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Cameră foto"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Buton pentru comutarea metodei de introducere."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Buton zoom pentru compatibilitate."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Faceţi zoom de la o imagine mai mică la una mai mare."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi conectat"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Se caută GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Locaţie setată prin GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Solicitări locație active"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Ștergeţi toate notificările."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informaţii despre aplicaţie"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ecranul se va roti în mod automat."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ecranul este blocat în orientarea de tip peisaj."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ecranul este blocat în orientarea de tip portret."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Vitrina cu dulciuri"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Mod Avion"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Rotire automată"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Rotire blocată"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Metodă de introducere"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Locație"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Localizarea este dezactivată"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Dispozitiv media"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Numai apeluri de urgenţă"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Ecran wireless"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Luminozitate"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMAT"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Rețeaua poate\nfi monitorizată"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Notificările se afişează aici"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Accesaţi-le oricând glisând în jos.\nGlisaţi în jos din nou pentru comenzile sistemului."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Glisați dinspre marginea ecranului pentru a afișa bara"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Glisați dinspre marginea ecranului pentru a afișa bara de sistem"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-ru/strings.xml b/packages/SystemUI/res/values-ru/strings.xml
index f7bb4d3..233fee8a8 100644
--- a/packages/SystemUI/res/values-ru/strings.xml
+++ b/packages/SystemUI/res/values-ru/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Всегда разрешать отладку с этого компьютера"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Подогнать по размерам экрана"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Растянуть на весь экран"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Масштаб и совместимость"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Если приложение рассчитано на экран меньших размеров, рядом с часами появятся средства масштабирования."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Сохранение..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Сохранение..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Сохранение..."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Домой"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Меню"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Недавние приложения"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Поиск"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Камера"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Кнопка переключения способа ввода."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Кнопка масштабирования (режим совместимости)"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Уменьшение изображения для увеличения свободного места на экране."</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi подключено"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Поиск GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Координаты по GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Есть активные запросы на определение местоположения"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Удалить все уведомления"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"О приложении"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Экран будет поворачиваться автоматически."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Выбрана только альбомная ориентация экрана."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Выбрана только книжная ориентация экрана."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Коробка со сладостями"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Заставка"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Режим полета"</string>
@@ -187,8 +186,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Автоповорот"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Автоповорот выкл."</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Способ ввода"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Передача геоданных"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Местоположение выкл."</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Режим медиа"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Экстр. вызов"</string>
@@ -203,5 +204,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Wi-Fi-монитор"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Яркость"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АВТОНАСТРОЙКА"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Действия в сети\nмогут отслеживаться"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Это панель уведомлений"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Ее можно открыть, пролистнув экран вниз.\nЧтобы открыть настройки, проведите пальцем вниз ещё раз."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Чтобы открыть панель, проведите пальцем от края к центру экрана"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Чтобы открыть панель навигации, проведите пальцем от края к центру экрана"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-si-rLK-land/strings.xml b/packages/SystemUI/res/values-si-rLK-land/strings.xml
deleted file mode 100644
index b5aba2a..0000000
--- a/packages/SystemUI/res/values-si-rLK-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"තිරය දැන් තිරස් දිශානතිය අගුළු දමා ඇත."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-si-rLK/strings.xml b/packages/SystemUI/res/values-si-rLK/strings.xml
deleted file mode 100644
index 24accd1..0000000
--- a/packages/SystemUI/res/values-si-rLK/strings.xml
+++ /dev/null
@@ -1,206 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"පද්ධති UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"හිස් කරන්න"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"ලැයිස්තුවෙන් ඉවත් කරන්න"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"යෙදුම් තොරතුරු"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"මෑත උපාංග නැත"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"මෑත යෙදුම් ඉවතලන්න"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"මෑත යෙදුම් 1 ක්"</item>
-    <item quantity="other" msgid="1040784359794890744">"මෑත යෙදුම් %d ක්"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"දැනුම්දීම් නැත"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"දැනට පවතින"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"දැනුම්දීම්"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"අරෝපකයට සම්බන්ධ කරන්න"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"බැටරිය අඩු වෙමින් පවතී."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> ක් ඉතිරියි"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB ආරෝපණය සහය නොදක්වයි.\nසපයන ලද ආරෝපකය පමණක් භාවිතා කරන්න."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"බැටරි භාවිතය"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"සැකසීම්"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"අහස්යානා ආකාරය"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"ස්වයංක්‍රීයව-භ්‍රමණය වන තිරය"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"නිශ්ශබ්ද කරන්න"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ස්වයංක්‍රීය"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"දැනුම්දීම්"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"බ්ලූටූත් ටෙදර් කරා"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"ආදාන ක්‍රම සකසන්න"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"භෞතික යතුරු පුවරුව"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"USB උපාංගය ප්‍රවේශ කිරීමට <xliff:g id="APPLICATION">%1$s</xliff:g> යෙදුමට අවසර දෙනවාද?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"USB මෙවලම ප්‍රවේශ කිරීමට <xliff:g id="APPLICATION">%1$s</xliff:g> යෙදුමට අවසර දෙනවාද?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"මෙම USB උපාංගය සම්බන්ධ විට <xliff:g id="ACTIVITY">%1$s</xliff:g> විවෘත කරන්නද?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"මෙම USB මෙවලමට සම්බන්ධ වී ඇති විට <xliff:g id="ACTIVITY">%1$s</xliff:g> විවෘත කරන්නද?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"මෙම USB මෙවලම සමග ක්‍රියා කරන ස්ථාපිත යෙදුම් නොමැත. <xliff:g id="URL">%1$s</xliff:g> වලින් මෙම මෙවලම ගැන තව දැනගන්න"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB මෙවලම"</string>
-    <string name="label_view" msgid="6304565553218192990">"පෙනුම"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"මෙම USB උපාංගය සඳහා සුපුරුද්දෙන් භාවිතා කරන්න"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"මේ USB මෙවලම සඳහා සුපුරුද්දෙන් භාවිතා කරන්න."</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB නිදොස්කරණයට අවසර දෙනවද?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"මෙම පරිගණකයේ RSA යතුරු ඇඟිලි සටහන වන්නේ:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"සැම විටම මෙම පරිගණකයෙන් ඉඩ ලබා දෙන්න"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"තිරය පිරවීමට විශාලනය කරන්න"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"තිරය පිරවීමට අදින්න"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"තිර රුව සුරකිමින්…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"තිර රුව සුරැකෙමින් පවතී…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"තිර රුව සුරැකෙමින් පවතී."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"තිර රුව ග්‍රහණය කරන ලදි."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"ඔබගේ තිර රුව බැලීමට ස්පර්ශ කරන්න."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"තිර රුව ග්‍රහණය කිරීමට නොහැකි විය."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"තිර රුව සුරැකීමට නොහැකි විය. ආචයනය භාවිතාවේ තිබෙනවා විය හැක."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ගොනු හුවමාරු විකල්ප"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"මධ්‍ය ධාවකයක් (MTP) ලෙස සවි කරන්න"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"කැමරාවක් (PTP) ලෙස සවි කරන්න"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Mac සඳහා Android ගොනු හුවමාරු යෙදුම ස්ථාපනය කරන්න"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"ආපසු"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"මුල් පිටුව"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"මෙනුව"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"මෑත යෙදුම්"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ආදාන ක්‍රමය මාරු කිරීමේ බොත්තම."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ගැළපෙන විශාලන බොත්තම."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"විශාල තිරය වෙත කුඩාව විශාලනය කරන්න."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"බ්ලූටූත් සම්බන්ධිතයි."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"බ්ලූටූත් විසන්ධි කර ඇත."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"බැටරිය නැත."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"බැටරිය තීරු එකයි."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"බැටරිය තීරු දෙකයි."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"බැටරිය තීරු තුනයි."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"බැටරිය පිරී ඇත."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"දුරකථනයක් නැත."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"දුරකථනය තීරු එකයි."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"දුරකථනය තීරු දෙකයි."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"දුරකථනය තීරු තුනයි."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"දුරකථනයේ සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"දත්ත නැත."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"දත්ත තීරු එකයි."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"දත්ත තීරු 2."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"දත්ත තීරු 3."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"දත්ත සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi අක්‍රියයි."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi සම්බන්ධ කර නොමැත."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi තීරු එකයි."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi තීරු දෙකයි."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi තීරු තුනයි."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX නැත."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX තීරු එකයි."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX තීරු දෙකයි."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX තීරු තුනයි."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"සංඥා නැත."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"සම්බන්ධ වී නැත."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"තීරු ශුන්‍යයි."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"තීරු එක."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"තීරු දෙකයි."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"තීරු තුනයි."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"සක්‍රීයයි."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"අක්‍රිය කරන්න."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"සම්බන්ධිතයි."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"රෝමිං"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM නැත."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"බ්ලූටූත් ටෙදරින්."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"අහස්යානා ආකාරය."</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"බැටරි ප්‍රතිශතය <xliff:g id="NUMBER">%d</xliff:g>"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"පද්ධති සැකසීම්."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"දැනුම්දීම්."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"දැනුම්දීම හිස් කරන්න."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS සබල කර ඇත."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS ලබා ගනිමින්."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter ක්‍රියාත්මකයි."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"හඬ නඟනය කම්පනය වේ."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"හඬ නඟනය නිශ්ශබ්දයි."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> අස් කර ඇත."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"දැනුම්දීම නිෂ්ප්‍රභා කරඇත."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"දැනුම්දීම් ආවරණය."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"ක්ෂණික සැකසීම්."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"මෑත කාලීන යෙදුම්."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"පරිශීලකයා <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"ජංගම <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"බැටරිය <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"අහස්යානා ආකාරය <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"බ්ලූටූත් <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"<xliff:g id="TIME">%s</xliff:g> සඳහා සීනුව සකස් කර ඇත."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G දත්ත අබල කරන ලදි"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"ජංගම දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"ඔබ නියමිත දත්ත භාවිත සීමාවට ළඟා වී ඇත.\n\nඔබ දත්ත නැවත සබල කළහොත් වාහකයා ඔබගෙන් ඇතැම් විට අය කරගත හැක."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"නැවත දත්ත සබල කරන්න"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"අන්තර්ජාල සම්බන්ධතාවයක් නැත"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi සම්බන්ධිතයි"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS සඳහා සොයමින්"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS මඟින් ස්ථානය සකසා ඇත"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"පිහිටීම් ඉල්ලීම් සක්‍රියයි"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"සියලු දැනුම්දීම් හිස් කරන්න."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"යෙදුම් තොරතුරු"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"තිරය ස්වයංක්‍රීයව කරකැවේ."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"තිරය තිරස් දිශානතියෙහි අගුළු දමා ඇත."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"තිරය සිරස් දිශානතිය තුළ අගුළු වැටී ඇත."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"දවල් හීනය"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"ඊතර නෙට්"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"අහස්යානා ආකාරය"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"ආරෝපණය වෙමින්, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"අරෝපිතයි"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"බ්ලූටූත්"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"බ්ලූටූත් (උපාංග <xliff:g id="NUMBER">%d</xliff:g>)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"බ්ලූටූත් අක්‍රියයි"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"දීප්තිය"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"ස්වයංක්‍රීය කරකැවීම"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"භ්‍රමණය අගුළු දමා ඇත"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"ආදාන ක්‍රමය"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"ස්ථානය"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"ස්ථානය අක්‍රියයි"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"මාධ්‍ය උපාංගය"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"හදිසි ඇමතුම් පමණි"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"සැකසීම්"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"වේලාව"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"මම"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"සම්බන්ධ වී නොමැත"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"ජාලයක් නැත"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi අක්‍රියයි"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi සංදර්ශකය"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"නොරැහැන් සංදර්ශකය"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"දීප්තිමත් බව"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ස්වයංක්‍රීය"</string>
-    <string name="ssl_ca_cert_warning" msgid="5848402127455021714">"ඇතැම් විට ජාලය නිරීක්ෂණය විය හැක"</string>
-    <string name="done_button" msgid="1759387181766603361">"හරි"</string>
-    <string name="ssl_ca_cert_dialog_title" msgid="1273796967092027291">"ජාල නිරීක්ෂණය කිරීම"</string>
-    <string name="ssl_ca_cert_info_message" msgid="5430320539555358452">"මෙම උපාංගය කළමනාකරණය කරනුයේ: <xliff:g id="MANAGING_DOMAIN">%s</xliff:g>.\n\nඔබගේ පරිපාලකයා ඊ-තැපැල්, යෙදුම්, සහ ආරක්‍ෂිත වෙබ් අඩවි ඇතුළුව ඔබගේ ජාල ක්‍රියාකාරකම් නිරීක්ෂණය කිරීමට හැකියාව ඇත.\n\nවැඩි විස්තර සඳහා, ඔබේ පරිපාලකයා සම්බන්ධ කරගන්න."</string>
-    <string name="ssl_ca_cert_warning_message" msgid="2033091656129963669">"තුන්වන පාර්ශවයකට ඔබගේ ජාලය නිරීක්ෂණය කිරීමට හැකියාව ඇත\nක්‍රියාකාරකම්, ඊ-තැපැල්, යෙදුම් සහ ආරක්‍ෂිත වෙබ් අඩවි ඇතුළුව.\n\nඔබගේ උපාංගය මත ස්ථාපිත විශ්වාසදයී අක්තපත්‍ර මෙය සිදුවීමේ හැකියාව ඇතිකරයි."</string>
-    <string name="ssl_ca_cert_settings_button" msgid="7946956977377166709">"විශ්වාසදායී අක්තපත්‍ර පරික්ෂා කරන්න"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-si/strings.xml b/packages/SystemUI/res/values-si/strings.xml
deleted file mode 100644
index f28cd16..0000000
--- a/packages/SystemUI/res/values-si/strings.xml
+++ /dev/null
@@ -1,204 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"පද්ධති UI"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"හිස් කරන්න"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"ලැයිස්තුවෙන් ඉවත් කරන්න"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"යෙදුම් තොරතුරු"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"මෑත උපාංග නැත"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"මෑත යෙදුම් ඉවතලන්න"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"මෑත යෙදුම් 1 ක්"</item>
-    <item quantity="other" msgid="1040784359794890744">"මෑත යෙදුම් %d ක්"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"දැනුම්දීම් නැත"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"දැනට පවතින"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"දැනුම්දීම්"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"අරෝපකයට සම්බන්ධ කරන්න"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"බැටරිය අඩු වෙමින් පවතී."</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"<xliff:g id="NUMBER">%d%%</xliff:g> ක් ඉතිරියි"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"USB ආරෝපණය සහය නොදක්වයි.\nසපයන ලද ආරෝපකය පමණක් භාවිතා කරන්න."</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"බැටරි භාවිතය"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"සැකසීම්"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"අහස්යානා ආකාරය"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"ස්වයංක්‍රීයව-භ්‍රමණය වන තිරය"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"නිශ්ශබ්ද කරන්න"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"ස්වයංක්‍රීය"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"දැනුම්දීම්"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"බ්ලූටූත් ටෙදර් කරා"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"ආදාන ක්‍රම සකසන්න"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"භෞතික යතුරු පුවරුව"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"USB උපාංගය ප්‍රවේශ කිරීමට <xliff:g id="APPLICATION">%1$s</xliff:g> යෙදුමට අවසර දෙනවාද?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"USB මෙවලම ප්‍රවේශ කිරීමට <xliff:g id="APPLICATION">%1$s</xliff:g> යෙදුමට අවසර දෙනවාද?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"මෙම USB උපාංගය සම්බන්ධ විට <xliff:g id="ACTIVITY">%1$s</xliff:g> විවෘත කරන්නද?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"මෙම USB මෙවලමට සම්බන්ධ වී ඇති විට <xliff:g id="ACTIVITY">%1$s</xliff:g> විවෘත කරන්නද?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"මෙම USB මෙවලම සමග ක්‍රියා කරන ස්ථාපිත යෙදුම් නොමැත. <xliff:g id="URL">%1$s</xliff:g> වලින් මෙම මෙවලම ගැන තව දැනගන්න"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB මෙවලම"</string>
-    <string name="label_view" msgid="6304565553218192990">"පෙනුම"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"මෙම USB උපාංගය සඳහා සුපුරුද්දෙන් භාවිතා කරන්න"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"මේ USB මෙවලම සඳහා සුපුරුද්දෙන් භාවිතා කරන්න."</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"USB නිදොස්කරණයට අවසර දෙනවද?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"මෙම පරිගණකයේ RSA යතුරු ඇඟිලි සටහන වන්නේ:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"සැම විටම මෙම පරිගණකයෙන් ඉඩ ලබා දෙන්න"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"තිරය පිරවීමට විශාලනය කරන්න"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"තිරය පිරවීමට අදින්න"</string>
-    <string name="compat_mode_help_header" msgid="7969493989397529910">"ගැළපෙන විශාලනය"</string>
-    <string name="compat_mode_help_body" msgid="4946726776359270040">"කුඩා තිරයක් සඳහා යෙදුමක් නිර්මාණය කළ විට, විශාලනය පාලකය ඔරලෝසුව ළඟින් පෙන්වයි."</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"තිර රුව සුරකිමින්…"</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"තිර රුව සුරැකෙමින් පවතී…"</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"තිර රුව සුරැකෙමින් පවතී."</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"තිර රුව ග්‍රහණය කරන ලදි."</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"ඔබගේ තිර රුව බැලීමට ස්පර්ශ කරන්න."</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"තිර රුව ග්‍රහණය කිරීමට නොහැකි විය."</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"තිර රුව සුරැකීමට නොහැකි විය. ආචයනය භාවිතාවේ තිබෙනවා විය හැක."</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB ගොනු හුවමාරු විකල්ප"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"මධ්‍ය ධාවකයක් (MTP) ලෙස සවි කරන්න"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"කැමරාවක් (PTP) ලෙස සවි කරන්න"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Mac සඳහා Android ගොනු හුවමාරු යෙදුම ස්ථාපනය කරන්න"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"ආපසු"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"මුල් පිටුව"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"මෙනුව"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"මෑත යෙදුම්"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ආදාන ක්‍රමය මාරු කිරීමේ බොත්තම."</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ගැළපෙන විශාලන බොත්තම."</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"විශාල තිරය වෙත කුඩාව විශාලනය කරන්න."</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"බ්ලූටූත් සම්බන්ධිතයි."</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"බ්ලූටූත් විසන්ධි කර ඇත."</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"බැටරිය නැත."</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"බැටරිය තීරු එකයි."</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"බැටරිය තීරු දෙකයි."</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"බැටරිය තීරු තුනයි."</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"බැටරිය පිරී ඇත."</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"දුරකථනයක් නැත."</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"දුරකථනය තීරු එකයි."</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"දුරකථනය තීරු දෙකයි."</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"දුරකථනය තීරු තුනයි."</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"දුරකථනයේ සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"දත්ත නැත."</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"දත්ත තීරු එකයි."</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"දත්ත තීරු 2."</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"දත්ත තීරු 3."</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"දත්ත සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"Wifi අක්‍රියයි."</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"Wifi සම්බන්ධ කර නොමැත."</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"Wifi තීරු එකයි."</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"Wifi තීරු දෙකයි."</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi තීරු තුනයි."</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"Wifi සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"WiMAX නැත."</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX තීරු එකයි."</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX තීරු දෙකයි."</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX තීරු තුනයි."</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"සංඥා නැත."</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"සම්බන්ධ වී නැත."</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"තීරු ශුන්‍යයි."</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"තීරු එක."</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"තීරු දෙකයි."</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"තීරු තුනයි."</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"සංඥාව පිරී ඇත."</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"සක්‍රීයයි."</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"අක්‍රිය කරන්න."</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"සම්බන්ධිතයි."</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"රෝමිං"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"SIM නැත."</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"බ්ලූටූත් ටෙදරින්."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"අහස්යානා ආකාරය."</string>
-    <string name="accessibility_battery_level" msgid="7451474187113371965">"බැටරි ප්‍රතිශතය <xliff:g id="NUMBER">%d</xliff:g>"</string>
-    <string name="accessibility_settings_button" msgid="799583911231893380">"පද්ධති සැකසීම්."</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"දැනුම්දීම්."</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"දැනුම්දීම හිස් කරන්න."</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS සබල කර ඇත."</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"GPS ලබා ගනිමින්."</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter ක්‍රියාත්මකයි."</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"හඬ නඟනය කම්පනය වේ."</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"හඬ නඟනය නිශ්ශබ්දයි."</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"<xliff:g id="APP">%s</xliff:g> අස් කර ඇත."</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"දැනුම්දීම නිෂ්ප්‍රභා කරඇත."</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"දැනුම්දීම් ආවරණය."</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"ක්ෂණික සැකසීම්."</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"මෑත කාලීන යෙදුම්."</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"පරිශීලකයා <xliff:g id="USER">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"ජංගම <xliff:g id="SIGNAL">%1$s</xliff:g>. <xliff:g id="TYPE">%2$s</xliff:g>. <xliff:g id="NETWORK">%3$s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"බැටරිය <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"අහස්යානා ආකාරය <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"බ්ලූටූත් <xliff:g id="STATE">%s</xliff:g>."</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"<xliff:g id="TIME">%s</xliff:g> සඳහා සීනුව සකස් කර ඇත."</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G දත්ත අබල කරන ලදි"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"ජංගම දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"දත්ත අබල කර ඇත"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"ඔබ නියමිත දත්ත භාවිත සීමාවට ළඟා වී ඇත.\n\nඔබ දත්ත නැවත සබල කළහොත් වාහකයා ඔබගෙන් ඇතැම් විට අය කරගත හැක."</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"නැවත දත්ත සබල කරන්න"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"අන්තර්ජාල සම්බන්ධතාවයක් නැත"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi සම්බන්ධිතයි"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS සඳහා සොයමින්"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS මඟින් ස්ථානය සකසා ඇත"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"පිහිටීම් ඉල්ලීම් සක්‍රියයි"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"සියලු දැනුම්දීම් හිස් කරන්න."</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"යෙදුම් තොරතුරු"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"තිරය ස්වයංක්‍රීයව කරකැවේ."</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"තිරය තිරස් දිශානතියෙහි අගුළු දමා ඇත."</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"තිරය සිරස් දිශානතිය තුළ අගුළු වැටී ඇත."</string>
-    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"දවල් හීනය"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"ඊතර නෙට්"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"අහස්යානා ආකාරය"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"ආරෝපණය වෙමින්, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"අරෝපිතයි"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"බ්ලූටූත්"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"බ්ලූටූත් (උපාංග <xliff:g id="NUMBER">%d</xliff:g>)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"බ්ලූටූත් අක්‍රියයි"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"දීප්තිය"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"ස්වයංක්‍රීය කරකැවීම"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"භ්‍රමණය අගුළු දමා ඇත"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"ආදාන ක්‍රමය"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"ස්ථානය"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"ස්ථානය අක්‍රියයි"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"මාධ්‍ය උපාංගය"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"හදිසි ඇමතුම් පමණි"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"සැකසීම්"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"වේලාව"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"මම"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"සම්බන්ධ වී නොමැත"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"ජාලයක් නැත"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi අක්‍රියයි"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi සංදර්ශකය"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"නොරැහැන් සංදර්ශකය"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"දීප්තිමත් බව"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"ස්වයංක්‍රීය"</string>
-    <string name="status_bar_help_title" msgid="1199237744086469217">"දැනුම්දීම් මෙතන පෙන්නුම් කරයි"</string>
-    <string name="status_bar_help_text" msgid="7874607155052076323">"පහලට සර්පණය කිරීමෙන් ඕනෑම වෙලාවක ඒවා වෙත පිවිසෙන්න.\nපද්ධති පාලක සඳහා නැවත පහළට සර්පණය කරන්න."</string>
-</resources>
diff --git a/packages/SystemUI/res/values-sk/strings.xml b/packages/SystemUI/res/values-sk/strings.xml
index 4fdb8078..c54540c 100644
--- a/packages/SystemUI/res/values-sk/strings.xml
+++ b/packages/SystemUI/res/values-sk/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Vždy povoliť z tohto počítača"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Priblížiť na celú obrazovku"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Na celú obrazovku"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Úprava veľkosti z dôvodu kompatibility"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Ak je aplikácia navrhnutá pre menšiu obrazovku, zobrazí sa vedľa hodín ovládací prvok priblíženia."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Prebieha ukladanie snímky obrazovky..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Prebieha ukladanie snímky obrazovky..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Snímka obrazovky sa ukladá."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Plocha"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Nové aplikácie"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Hľadať"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Fotoaparát"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Tlačidlo prepnutia metódy vstupu."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Tlačidlo úpravy veľkosti z dôvodu kompatibility."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zväčšiť menší obrázok na väčšiu obrazovku."</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi: pripojené"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Vyhľadávanie satelitov GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Poloha nastavená pomocou GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Žiadosti o polohu sú aktívne"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Vymazať všetky upozornenia."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Informácie o aplikácii"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Obrazovka sa automaticky otočí."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Obrazovka je uzamknutá v orientácii na šírku."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Obrazovka je uzamknutá v orientácii na výšku."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Pult s dezertami"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Šetrič obrazovky"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Režim V lietadle"</string>
@@ -201,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Bezdrôtový displej"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Jas"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTOMATICKY"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Sieť môže byť\nmonitorovaná"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Tu sa zobrazujú upozornenia"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Môžete ich kedykoľvek zobraziť tak, že posuniete prstom nadol.\nAk posuniete prstom nadol ešte raz, zobrazia sa ovládacie prvky systému."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Panel zobrazíte posunutím cez okraj obrazovky"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Systémový panel zobrazíte posunutím cez okraj obrazovky"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sl/strings.xml b/packages/SystemUI/res/values-sl/strings.xml
index 27369ea..3fc4882 100644
--- a/packages/SystemUI/res/values-sl/strings.xml
+++ b/packages/SystemUI/res/values-sl/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Vedno dovoli iz tega računalnika"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Povečava čez cel zaslon"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Raztegnitev čez zaslon"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Razširitev združljivosti"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Če je program izdelan za manjše zaslone, se ob uri pokaže kontrolnik za povečavo."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Shranjev. posnetka zaslona ..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Shranjevanje posnetka zaslona ..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Shranjevanje posnetka zaslona."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Začetni zaslon"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Meni"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Nedavni programi"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Iskanje"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Fotoaparat"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Gumb za preklop načina vnosa."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Gumb povečave za združljivost."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Povečava manjšega na večji zaslon."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi povezan"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Iskanje GPS-a"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokacija nastavljena z GPS-om"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktivne zahteve za lokacijo"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Izbriši vsa obvestila."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Podatki o aplikaciji"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Zaslon se bo samodejno zasukal."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Zaslon je zaklenjen v ležeči usmerjenosti."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Zaslon je zaklenjen v pokončni usmerjenosti."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Vitrina za sladice"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Sanjarjenje"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Način za letalo"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Prikaz brezžičnih naprav"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Svetlost"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"SAMODEJNO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Omrežje je\nlahko spremljano"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Obvestila so prikazana tukaj"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Do njih lahko kadar koli dostopate tako, da povlečete navzdol.\nZa prikaz sistemskih kontrolnikov znova povlecite navzdol."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Vrstico prikažete tako, da povlečete z roba zaslona"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Sistemsko vrstico prikažete tako, da povlečete z roba zaslona"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sr/strings.xml b/packages/SystemUI/res/values-sr/strings.xml
index 7c182a20..7ba2da5 100644
--- a/packages/SystemUI/res/values-sr/strings.xml
+++ b/packages/SystemUI/res/values-sr/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Увек дозволи са овог рачунара"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Зумирај на целом екрану"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Развуци на цео екран"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Компатибилно зумирање"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Када је апликација намењена мањем екрану, контрола зумирања приказује се поред сата."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Чување снимка екрана..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Чување снимка екрана..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Снимак екрана се чува."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Почетна"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Мени"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Недавне апликације"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Претражите"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Камера"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Дугме Промени метод уноса."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Дугме Зум компатибилности."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Зумирање са мањег на већи екран."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi је повезан"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Тражи се GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Локацију је подесио GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Има активних захтева за локацију"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Обриши сва обавештења."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Информације о апликацији"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Екран ће се аутоматски ротирати."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Екран је закључан у хоризонталном положају."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Екран је закључан у вертикалном положају."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Витрина са посластицама"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Сањарење"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Етернет"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Режим рада у авиону"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Бежични екран"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Осветљеност"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АУТОМАТСКА"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Мрежа се можда\nнадгледа"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Обавештења се појављују овде"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Приступите им у било ком тренутку листањем надоле.\nПоново листајте надоле да би се приказале системске контроле."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Превуците по ивици екрана да би се приказала трака"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Превуците од ивице екрана да би се приказала системска трака"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sv/strings.xml b/packages/SystemUI/res/values-sv/strings.xml
index 99d19f0..022e2f2 100644
--- a/packages/SystemUI/res/values-sv/strings.xml
+++ b/packages/SystemUI/res/values-sv/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Tillåt alltid på den här datorn"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Zooma för att fylla skärm"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Dra för att fylla skärmen"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom i kompatibilitetsläge"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"När en app är anpassad för en mindre skärm visas ett zoomreglage vid klockan."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Skärmdumpen sparas ..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Skärmdumpen sparas ..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Skärmdumpen sparas."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Startsida"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Meny"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Senaste apparna"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Sök"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Knapp för byte av inmatningsmetod."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Knapp för kompatibilitetszoom."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Zooma mindre skärm till större."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi-ansluten"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Sökning efter GPS pågår"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Platsen har identifierats av GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Det finns aktiva platsbegäranden"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Ta bort alla meddelanden."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Info om appen"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Skärmen roteras automatiskt."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Bildskärmens riktning är nu låst i liggande format."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Bildskärmens riktning är nu låst i stående format."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessertdisken"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Dagdröm"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Flygplansläge"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Trådlös skärm"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Ljusstyrka"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Nätverket kan\nvara övervakat"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Meddelanden visas här"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Du kommer åt dem när som helst genom att dra nedåt.\nDra nedåt igen om du vill visa systemkontroller."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Dra från kanten av skärmen om du vill visa fältet"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Dra från kanten av skärmen om du vill visa systemfältet"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-sw/strings.xml b/packages/SystemUI/res/values-sw/strings.xml
index 7c7f661..27f556c 100644
--- a/packages/SystemUI/res/values-sw/strings.xml
+++ b/packages/SystemUI/res/values-sw/strings.xml
@@ -59,6 +59,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Ruhusu kutoka kwenye kompyuta hii kila wakati"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Kuza ili kujaza skrini"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Tanua ili kujaza skrini"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Kukuza kwa Utangamanifu"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Wakati programu ilibuniwa kwa skrini ndogo, kidhibiti cha kukuza kitaonekana kwa saa."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Inahifadhi picha ya skrini..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Inahifadhi picha ya skrini..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Picha ya skrini inahifadhiwa"</string>
@@ -74,8 +76,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Nyumbani"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menyu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Programu za hivi karibuni"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Tafuta"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Swichi kitufe cha mbinu ingizi."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Kichupo cha kukuza kwa utangamanifu"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Kuza kidogo kwa skrini kubwa."</string>
@@ -130,7 +130,7 @@
     <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
     <string name="accessibility_no_sim" msgid="8274017118472455155">"Hakuna SIM."</string>
     <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"Shiriki intaneti kwa Bluetooth."</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Hali ya ndege."</string>
+    <string name="accessibility_airplane_mode" msgid="834748999790763092">"Modi ya ndege."</string>
     <string name="accessibility_battery_level" msgid="7451474187113371965">"Asilimia <xliff:g id="NUMBER">%d</xliff:g> ya betri"</string>
     <string name="accessibility_settings_button" msgid="799583911231893380">"Mipangilio ya mfumo."</string>
     <string name="accessibility_notifications_button" msgid="4498000369779421892">"Arifa."</string>
@@ -162,16 +162,15 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Mtandao-hewa umeunganishwa"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Inatafuta GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Mahali pamewekwa na GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Maombi ya eneo yanatumika"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Futa arifa zote."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Taarifa ya programu"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Skrini itazunguka kiotomatiki."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Skrini imefungwa sasa katika uelekezo wa mandhari."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Skrini imefungwa katika uelekeo wa picha."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Sanduku la Vitindamlo"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Hali Tulivu"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Hali ya ndege"</string>
+    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Modi ya ndege"</string>
     <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"Inachaji, <xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>"</string>
     <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"Imechajiwa"</string>
     <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
@@ -181,8 +180,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Zungusha Otomatiki"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Mzunguko Umefungwa"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Mbinu ya uingizaji"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Kutambua Eneo"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Kitambua eneo kimezimwa"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Kifaa cha midia"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Simu za Dharura Pekee"</string>
@@ -197,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Uonyeshaji Pasiwaya"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Ung\'avu"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"KIOTOMATIKI"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Huenda mtandao\nunafuatiliwa"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Arifa zitaonekana hapa"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Zifikie wakati wowote kwa kutelezesha chini.\nTelezesha chini tena kupata vidhibiti vya mfumo."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Papasa kwa kasi kutoka ukingo wa skrini ili kuonyesha upau"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Papasa kwa kasi kutoka ukingo wa skrini ili kuonyesha upau wa mfumo"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-th/strings.xml b/packages/SystemUI/res/values-th/strings.xml
index 07bca1a..dc643c4 100644
--- a/packages/SystemUI/res/values-th/strings.xml
+++ b/packages/SystemUI/res/values-th/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"อนุญาตจากคอมพิวเตอร์เครื่องนี้เสมอ"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"ขยายจนเต็มหน้าจอ"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"ยืดจนเต็มหน้าจอ"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"ความเข้ากันได้ของการย่อ/ขยาย"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"สำหรับแอปพลิเคชันที่ออกแบบมาสำหรับหน้าจอขนาดเล็ก ตัวควบคุมการย่อ/ขยายจะปรากฏขึ้นข้างนาฬิกา"</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"กำลังบันทึกภาพหน้าจอ..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"กำลังบันทึกภาพหน้าจอ..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"กำลังบันทึกภาพหน้าจอ"</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"หน้าแรก"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"เมนู"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"แอปพลิเคชันล่าสุด"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"ค้นหา"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"กล้องถ่ายรูป"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"ปุ่มสลับวิธีการป้อนข้อมูล"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"ปุ่มซูมที่ใช้งานร่วมกันได้"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"ซูมหน้าจอให้มีขนาดใหญ่ขึ้น"</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"เชื่อมต่อ WiFi แล้ว"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"กำลังค้นหา GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"ตำแหน่งที่กำหนดโดย GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"คำขอตำแหน่งที่มีการใช้งาน"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"ล้างการแจ้งเตือนทั้งหมด"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"ข้อมูลแอป"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"หน้าจอจะหมุนโดยอัตโนมัติ"</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"ขณะนี้หน้าจอถูกล็อกให้วางในแนวนอน"</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"ขณะนี้หน้าจอถูกล็อกให้วางในแนวตั้ง"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"ชั้นแสดงของหวาน"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"อีเทอร์เน็ต"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"โหมดใช้งานบนเครื่องบิน"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"จอแสดงผลไร้สาย"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"ความสว่าง"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"อัตโนมัติ"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"เครือข่ายอาจ\nถูกตรวจสอบ"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"การแจ้งเตือนจะแสดงขึ้นที่นี่"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"เข้าถึงได้ทุกเมื่อด้วยการกวาดนิ้วลง\nกวาดนิ้วลงอีกครั้งสำหรับการควบคุมระบบ"</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"กวาดขอบของหน้าจอเพื่อแสดงแถบ"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"กวาดจากขอบของหน้าจอเพื่อแสดงแถบระบบ"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-tl/strings.xml b/packages/SystemUI/res/values-tl/strings.xml
index e163333..0053be4 100644
--- a/packages/SystemUI/res/values-tl/strings.xml
+++ b/packages/SystemUI/res/values-tl/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Palaging payagan mula sa computer na ito"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"I-zoom upang punan screen"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"I-stretch upang mapuno screen"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Zoom sa pagiging Tugma"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Kapag nakadisenyo ang isang app para sa mas maliit na screen, isang kontrol ng zoom ang lalabas sa may orasan."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Sine-save ang screenshot…"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Sine-save ang screenshot…"</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Sine-save ang screenshot."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Home"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Kamakailang apps"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Hanapin"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Camera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Ilipat ang button na pamamaraan ng pag-input."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Button ng zoom ng pagiging tugma."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Mag-zoom nang mas maliit sa mas malaking screen."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"nakakonekta ang Wi-Fi"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Naghahanap ng GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Lokasyong itinatakda ng GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Aktibo ang mga kahilingan ng lokasyon"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"I-clear ang lahat ng notification."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Impormasyon ng app"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Awtomatikong iikot ang screen."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Naka-lock ang screen sa pahigang oryentasyon."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Naka-lock ang screen sa patayong oryentasyon."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Airplane mode"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Wireless Display"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Brightness"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"AUTO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Maaaring\nsinusubaybayan ang network"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Dito lumalabas ang mga notification"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"I-access ang mga ito anumang oras sa pamamagitan ng pag-swipe pababa.\nMuling mag-swipe pababa para sa mga kontrol ng system."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Mag-swipe sa gilid ng screen upang ipakita ang bar"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Mag-swipe mula sa gilid ng screen upang ipakita ang system bar"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-tr/strings.xml b/packages/SystemUI/res/values-tr/strings.xml
index 6fcde0c..f39f8bc 100644
--- a/packages/SystemUI/res/values-tr/strings.xml
+++ b/packages/SystemUI/res/values-tr/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Bu bilgisayardan her zaman izin ver"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Yakınlaştır (ekranı kaplasın)"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Genişlet (ekran kapansın)"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Uyumluluk yakınlaştırması"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Uygulama küçük bir ekran için tasarlanmışsa saatin yanında bir yakınlaştırma denetimi görünür."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Ekran görüntüsü kaydediliyor..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Ekran görüntüsü kaydediliyor..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Ekran görüntüsü kaydediliyor."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Ana sayfa"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Menü"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Son uygulamalar"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Ara"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Kamera"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Giriş yöntemini değiştirme düğmesi."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Uyumluluk zum düğmesi."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Daha büyük ekrana daha küçük yakınlaştır."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Kablosuz bağlandı"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"GPS aranıyor"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Konum GPS ile belirlendi"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Konum bilgisi istekleri etkin"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Tüm bildirimleri temizle"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Uygulama bilgileri"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Ekran otomatik olarak dönecektir."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Ekran yatay yönde kilitlendi."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Ekran dikey yönde kilitlendi."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Tatlı Kutusu"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Hafif uyku"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Uçak modu"</string>
@@ -183,8 +182,10 @@
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"Otomatik Döndür"</string>
     <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"Dönme Kilitlendi"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"Giriş Yöntemi"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"Konum"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"Konum Bilgisi Kapalı"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"Medya cihazı"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"Yalnızca Acil Çağrılar İçin"</string>
@@ -199,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Kablosuz Ekran"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Parlaklık"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"OTOMATİK"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Ağ izleniyor\nolabilir"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Bildirimler burada görünür"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Aşağıya hızlıca kaydırarak bunlara istediğiniz zaman erişebilirsiniz.\nSistem denetimleri için tekrar hızlıca aşağı kaydırın."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Çubuğu görüntülemek için ekranın kenarından hızlıca kaydırın"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Sistem çubuğunu görüntülemek için ekranın kenarından hızlıca kaydırın"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-uk/strings.xml b/packages/SystemUI/res/values-uk/strings.xml
index 9567c03..18f67a2 100644
--- a/packages/SystemUI/res/values-uk/strings.xml
+++ b/packages/SystemUI/res/values-uk/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Завжди дозволяти з цього комп’ютера"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Масштабув. на весь екран"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Розтягнути на весь екран"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Масштабування для сумісності"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Якщо програму призначено для менших екранів, елемент керування масштабом буде відображатися біля годинника."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Збереження знімка екрана..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Збереження знімка екрана..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Зберігається знімок екрана."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Головна"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Меню"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Останні програми"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Пошук"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Камера"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Кнопка перемикання методу введення."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Кнопка масштабування сумісності."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Збільшення екрана."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi під’єднано"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Виконується пошук GPS-сигналу"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Місцезнаходження встановлено за допомогою GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Запити про місцезнаходження активні"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Очистити всі сповіщення."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Інформація про програму"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Екран обертатиметься автоматично."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Екран заблоковано в альбомній орієнтації."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Екран заблоковано в книжковій орієнтації."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Вітрина десертів"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Заставка"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Режим польоту"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Бездротове відображення"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Яскравість"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"АВТО"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Мережа може\nвідстежуватися"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Сповіщення з’являються тут"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Отримуйте до них доступ будь-коли, провівши пальцем униз.\nЗнову проведіть униз, щоб відкрити елементи керування системи."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Гортайте від краю екрана, щоб з’явилась панель"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Проведіть пальцем від краю екрана, щоб з’явилась навігаційна панель"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-vi/strings.xml b/packages/SystemUI/res/values-vi/strings.xml
index 6e68c63..acc7e0e 100644
--- a/packages/SystemUI/res/values-vi/strings.xml
+++ b/packages/SystemUI/res/values-vi/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Luôn cho phép từ máy tính này"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"T.phóng để lấp đầy m.hình"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Giãn ra để lấp đầy m.hình"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Thu phóng tương thích"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Khi ứng dụng được thiết kế cho một màn hình nhỏ hơn, điều khiển thu phóng sẽ xuất hiện bên cạnh đồng hồ."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Đang lưu ảnh chụp màn hình..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Đang lưu ảnh chụp màn hình..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Ảnh chụp màn hình đang được lưu."</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"Trang chủ"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Trình đơn"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Ứng dụng gần đây"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Tìm kiếm"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Máy ảnh"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Nút chuyển phương thức nhập."</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Nút thu phóng khả năng tương thích."</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Thu phóng màn hình lớn hơn hoặc nhỏ hơn."</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Đã kết nối Wi-Fi"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Đang tìm kiếm GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Vị trí đặt bởi GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Yêu cầu về thông tin vị trí đang hoạt động"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Xóa tất cả thông báo."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Thông tin về ứng dụng"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Màn hình sẽ xoay tự động."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Màn hình hiện bị khóa theo hướng ngang."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Màn hình hiện bị khóa theo hướng dọc."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Tủ trưng bày bánh ngọt"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Chế độ ngủ"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Chế độ trên máy bay"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Hiển thị không dây"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Độ sáng"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"TỰ ĐỘNG"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Mạng có thể\nđược giám sát"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Thông báo xuất hiện tại đây"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Truy cập vào chúng bất kỳ lúc nào bằng cách vuốt xuống.\nVuốt lại xuống để hiển thị các điều khiển hệ thống."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Vuốt cạnh màn hình để hiển thị thanh"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Vuốt từ cạnh màn hình để hiển thị thanh hệ thống"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index 39d73c3..0a62ee3 100644
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"一律允许使用这台计算机进行调试"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"缩放以填满屏幕"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"拉伸以填满屏幕"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"兼容性缩放"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"如果应用是针对较小屏幕设计的,则时钟旁会显示缩放控件。"</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"正在保存屏幕截图..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"正在保存屏幕截图..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"正在保存屏幕截图。"</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"主屏幕"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"菜单"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"最近运行的应用"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"搜索"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"相机"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"输入法切换按钮。"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"兼容性缩放按钮。"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"将小屏幕的图片放大在较大屏幕上显示。"</string>
@@ -147,7 +147,7 @@
     <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"已删除<xliff:g id="APP">%s</xliff:g>"</string>
     <string name="accessibility_notification_dismissed" msgid="854211387186306927">"已关闭通知。"</string>
     <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"通知栏。"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"快捷设置。"</string>
+    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"快速设置。"</string>
     <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"最近使用的应用。"</string>
     <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"用户:<xliff:g id="USER">%s</xliff:g>。"</string>
     <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>,<xliff:g id="NETWORK">%2$s</xliff:g>"</string>
@@ -158,21 +158,20 @@
     <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"闹钟已设置为:<xliff:g id="TIME">%s</xliff:g>。"</string>
     <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"2G-3G 数据网络已停用"</string>
     <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"4G 数据网络已停用"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"移动数据网络已停用"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"数据网络已停用"</string>
+    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"移动数据已停用"</string>
+    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"数据已停用"</string>
     <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"您已达到指定的数据流量上限。\n\n如果您重新启用数据,运营商可能会收取相应的费用。"</string>
     <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"重新启用数据连接"</string>
     <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"未连接互联网"</string>
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"WLAN 已连接"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"正在搜索 GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"已通过 GPS 确定位置"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"应用发出了有效位置信息请求"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"清除所有通知。"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"应用信息"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"屏幕会自动旋转。"</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"屏幕锁定为横向模式。"</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"屏幕锁定为纵向模式。"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"甜品盒"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"果冻豆大乱舞"</string>
     <string name="start_dreams" msgid="7219575858348719790">"互动屏保"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"以太网"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"飞行模式"</string>
@@ -180,13 +179,15 @@
     <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"充电完成"</string>
     <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"蓝牙"</string>
     <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"蓝牙(<xliff:g id="NUMBER">%d</xliff:g> 台设备)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"蓝牙:关闭"</string>
+    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"蓝牙已关闭"</string>
     <string name="quick_settings_brightness_label" msgid="6968372297018755815">"亮度"</string>
     <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"自动旋转"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"屏幕方向:锁定"</string>
+    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"屏幕方向已锁定"</string>
     <string name="quick_settings_ime_label" msgid="7073463064369468429">"输入法"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"位置信息"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"位置信息服务已关闭"</string>
+    <!-- no translation found for quick_settings_location_label (5011327048748762257) -->
+    <skip />
+    <!-- no translation found for quick_settings_location_off_label (7464544086507331459) -->
+    <skip />
     <string name="quick_settings_media_device_label" msgid="1302906836372603762">"媒体设备"</string>
     <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
     <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"只能拨打紧急呼救电话"</string>
@@ -201,5 +202,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"无线显示"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"亮度"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"自动"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"网络可能会\n受到监控"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"通知会显示在这里"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"向下滑动可随时查看通知。\n再次向下滑动可使用系统控制功能。"</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"从边缘向里滑可显示系统栏"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"从屏幕边缘向里滑动即可显示系统栏"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-zh-rHK-land/strings.xml b/packages/SystemUI/res/values-zh-rHK-land/strings.xml
deleted file mode 100644
index 8d55df4..0000000
--- a/packages/SystemUI/res/values-zh-rHK-land/strings.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * Copyright (c) 2010, 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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="toast_rotation_locked" msgid="7609673011431556092">"屏幕現已鎖定為橫向模式"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-zh-rHK/strings.xml b/packages/SystemUI/res/values-zh-rHK/strings.xml
deleted file mode 100644
index d83455c..0000000
--- a/packages/SystemUI/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,205 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-/**
- * 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.
- */
- -->
-
-<resources xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="app_label" msgid="7164937344850004466">"系統用戶介面"</string>
-    <string name="status_bar_clear_all_button" msgid="7774721344716731603">"清除"</string>
-    <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"從清單中移除"</string>
-    <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"應用程式資訊"</string>
-    <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"沒有最近的應用程式"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"關閉最近使用的應用程式"</string>
-  <plurals name="status_bar_accessibility_recent_apps">
-    <item quantity="one" msgid="5854176083865845541">"1 個最近使用的應用程式"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d 個最近使用的應用程式"</item>
-  </plurals>
-    <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"無通知"</string>
-    <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"持續進行"</string>
-    <string name="status_bar_latest_events_title" msgid="6594767438577593172">"通知"</string>
-    <string name="battery_low_title" msgid="2783104807551211639">"連接充電器"</string>
-    <string name="battery_low_subtitle" msgid="1752040062087829196">"電池即將用盡。"</string>
-    <string name="battery_low_percent_format" msgid="1077244949318261761">"剩餘 <xliff:g id="NUMBER">%d%%</xliff:g>"</string>
-    <string name="invalid_charger" msgid="4549105996740522523">"不支援 USB 充電。\n僅能使用隨附的充電器。"</string>
-    <string name="battery_low_why" msgid="7279169609518386372">"電池使用情況"</string>
-    <string name="status_bar_settings_settings_button" msgid="3023889916699270224">"設定"</string>
-    <string name="status_bar_settings_wifi_button" msgid="1733928151698311923">"Wi-Fi"</string>
-    <string name="status_bar_settings_airplane" msgid="4879879698500955300">"飛行模式"</string>
-    <string name="status_bar_settings_auto_rotation" msgid="3790482541357798421">"自動旋轉螢幕"</string>
-    <string name="status_bar_settings_mute_label" msgid="554682549917429396">"關閉"</string>
-    <string name="status_bar_settings_auto_brightness_label" msgid="511453614962324674">"自動"</string>
-    <string name="status_bar_settings_notifications" msgid="397146176280905137">"通知"</string>
-    <string name="bluetooth_tethered" msgid="7094101612161133267">"已經由藍牙進行網絡共享"</string>
-    <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"設定輸入方式"</string>
-    <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"實體鍵盤"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"允許「<xliff:g id="APPLICATION">%1$s</xliff:g>」應用程式存取 USB 裝置嗎?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"允許「<xliff:g id="APPLICATION">%1$s</xliff:g>」應用程式存取 USB 配件嗎?"</string>
-    <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"連接這個 USB 裝置時啟用 <xliff:g id="ACTIVITY">%1$s</xliff:g> 嗎?"</string>
-    <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"連接這個 USB 配件時啟用 <xliff:g id="ACTIVITY">%1$s</xliff:g> 嗎?"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"已安裝的應用程式均無法存取這個 USB 配件,如要進一步瞭解這個配件,請瀏覽 <xliff:g id="URL">%1$s</xliff:g>"</string>
-    <string name="title_usb_accessory" msgid="4966265263465181372">"USB 配件"</string>
-    <string name="label_view" msgid="6304565553218192990">"觀看"</string>
-    <string name="always_use_device" msgid="1450287437017315906">"預設用於這個 USB 裝置"</string>
-    <string name="always_use_accessory" msgid="1210954576979621596">"預設用於這個 USB 配件"</string>
-    <string name="usb_debugging_title" msgid="4513918393387141949">"允許 USB 除錯嗎?"</string>
-    <string name="usb_debugging_message" msgid="2220143855912376496">"這部電腦的 RSA 密鑰指紋如下:\n<xliff:g id="FINGERPRINT">%1$s</xliff:g>"</string>
-    <string name="usb_debugging_always" msgid="303335496705863070">"一律允許透過這部電腦進行"</string>
-    <string name="compat_mode_on" msgid="6623839244840638213">"放大為全螢幕"</string>
-    <string name="compat_mode_off" msgid="4434467572461327898">"放大為全螢幕"</string>
-    <string name="screenshot_saving_ticker" msgid="7403652894056693515">"正在儲存屏幕擷取畫面..."</string>
-    <string name="screenshot_saving_title" msgid="8242282144535555697">"正在儲存屏幕擷取畫面..."</string>
-    <string name="screenshot_saving_text" msgid="2419718443411738818">"正在儲存屏幕擷取畫面。"</string>
-    <string name="screenshot_saved_title" msgid="6461865960961414961">"已擷取屏幕畫面。"</string>
-    <string name="screenshot_saved_text" msgid="1152839647677558815">"輕觸即可查看屏幕擷取畫面。"</string>
-    <string name="screenshot_failed_title" msgid="705781116746922771">"無法擷取屏幕畫面。"</string>
-    <string name="screenshot_failed_text" msgid="8134011269572415402">"無法儲存屏幕擷取畫面,儲存裝置可能正在使用。"</string>
-    <string name="usb_preference_title" msgid="6551050377388882787">"USB 檔案傳輸選項"</string>
-    <string name="use_mtp_button_title" msgid="4333504413563023626">"掛接為媒體播放器 (MTP)"</string>
-    <string name="use_ptp_button_title" msgid="7517127540301625751">"掛接為相機 (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"安裝 Mac 專用的「Android 檔案傳輸」應用程式"</string>
-    <string name="accessibility_back" msgid="567011538994429120">"返回"</string>
-    <string name="accessibility_home" msgid="8217216074895377641">"首頁"</string>
-    <string name="accessibility_menu" msgid="316839303324695949">"選單"</string>
-    <string name="accessibility_recent" msgid="8571350598987952883">"最近使用的應用程式"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"搜尋"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"相機"</string>
-    <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"切換輸入法按鈕。"</string>
-    <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"相容性縮放按鈕。"</string>
-    <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"將較小螢幕的畫面放大在較大螢幕上顯示。"</string>
-    <string name="accessibility_bluetooth_connected" msgid="2707027633242983370">"藍牙連線已建立。"</string>
-    <string name="accessibility_bluetooth_disconnected" msgid="7416648669976870175">"藍牙連線已中斷。"</string>
-    <string name="accessibility_no_battery" msgid="358343022352820946">"未安裝電池。"</string>
-    <string name="accessibility_battery_one_bar" msgid="7774887721891057523">"電池電量為一格。"</string>
-    <string name="accessibility_battery_two_bars" msgid="8500650438735009973">"電池電量為兩格。"</string>
-    <string name="accessibility_battery_three_bars" msgid="2302983330865040446">"電池電量為三格。"</string>
-    <string name="accessibility_battery_full" msgid="8909122401720158582">"電池已滿。"</string>
-    <string name="accessibility_no_phone" msgid="4894708937052611281">"沒有電話訊號。"</string>
-    <string name="accessibility_phone_one_bar" msgid="687699278132664115">"電話訊號強度為一格。"</string>
-    <string name="accessibility_phone_two_bars" msgid="8384905382804815201">"電話訊號強度為兩格。"</string>
-    <string name="accessibility_phone_three_bars" msgid="8521904843919971885">"電話訊號強度為三格。"</string>
-    <string name="accessibility_phone_signal_full" msgid="6471834868580757898">"電話訊號滿格。"</string>
-    <string name="accessibility_no_data" msgid="4791966295096867555">"沒有數據網絡。"</string>
-    <string name="accessibility_data_one_bar" msgid="1415625833238273628">"數據網絡訊號強度為一格。"</string>
-    <string name="accessibility_data_two_bars" msgid="6166018492360432091">"數據網絡訊號強度為兩格。"</string>
-    <string name="accessibility_data_three_bars" msgid="9167670452395038520">"數據網絡訊號強度為三格。"</string>
-    <string name="accessibility_data_signal_full" msgid="2708384608124519369">"數據網絡訊號滿格。"</string>
-    <string name="accessibility_wifi_off" msgid="3177380296697933627">"WiFi 已關閉。"</string>
-    <string name="accessibility_no_wifi" msgid="1425476551827924474">"WiFi 連線已中斷。"</string>
-    <string name="accessibility_wifi_one_bar" msgid="7735893178010724377">"WiFi 訊號強度為一格。"</string>
-    <string name="accessibility_wifi_two_bars" msgid="4994274250497262434">"WiFi 訊號強度為兩格。"</string>
-    <string name="accessibility_wifi_three_bars" msgid="3495755044276588384">"WiFi 訊號強度為三格。"</string>
-    <string name="accessibility_wifi_signal_full" msgid="6853561303586480376">"WiFi 訊號已滿。"</string>
-    <string name="accessibility_no_wimax" msgid="4329180129727630368">"沒有 WiMAX 訊號。"</string>
-    <string name="accessibility_wimax_one_bar" msgid="4170994299011863648">"WiMAX 訊號強度一格。"</string>
-    <string name="accessibility_wimax_two_bars" msgid="9176236858336502288">"WiMAX 訊號強度兩格。"</string>
-    <string name="accessibility_wimax_three_bars" msgid="6116551636752103927">"WiMAX 訊號強度三格。"</string>
-    <string name="accessibility_wimax_signal_full" msgid="2768089986795579558">"WiMAX 訊號滿格。"</string>
-    <string name="accessibility_no_signal" msgid="7064645320782585167">"沒有訊號。"</string>
-    <string name="accessibility_not_connected" msgid="6395326276213402883">"未連線。"</string>
-    <string name="accessibility_zero_bars" msgid="3806060224467027887">"訊號強度為零格。"</string>
-    <string name="accessibility_one_bar" msgid="1685730113192081895">"訊號強度為一格。"</string>
-    <string name="accessibility_two_bars" msgid="6437363648385206679">"訊號強度為兩格。"</string>
-    <string name="accessibility_three_bars" msgid="2648241415119396648">"訊號強度為三格。"</string>
-    <string name="accessibility_signal_full" msgid="9122922886519676839">"訊號已滿。"</string>
-    <string name="accessibility_desc_on" msgid="2385254693624345265">"開啟。"</string>
-    <string name="accessibility_desc_off" msgid="6475508157786853157">"關閉。"</string>
-    <string name="accessibility_desc_connected" msgid="8366256693719499665">"已連線。"</string>
-    <string name="accessibility_data_connection_gprs" msgid="1606477224486747751">"GPRS"</string>
-    <string name="accessibility_data_connection_1x" msgid="994133468120244018">"1 X"</string>
-    <string name="accessibility_data_connection_hspa" msgid="2032328855462645198">"HSPA"</string>
-    <string name="accessibility_data_connection_3g" msgid="8628562305003568260">"3G"</string>
-    <string name="accessibility_data_connection_3.5g" msgid="8664845609981692001">"3.5G"</string>
-    <string name="accessibility_data_connection_4g" msgid="7741000750630089612">"4G"</string>
-    <string name="accessibility_data_connection_lte" msgid="5413468808637540658">"LTE"</string>
-    <string name="accessibility_data_connection_cdma" msgid="6132648193978823023">"CDMA"</string>
-    <string name="accessibility_data_connection_roaming" msgid="5977362333466556094">"漫遊"</string>
-    <string name="accessibility_data_connection_edge" msgid="4477457051631979278">"Edge"</string>
-    <string name="accessibility_data_connection_wifi" msgid="2324496756590645221">"Wi-Fi"</string>
-    <string name="accessibility_no_sim" msgid="8274017118472455155">"無 SIM 卡。"</string>
-    <string name="accessibility_bluetooth_tether" msgid="4102784498140271969">"藍牙數據連線。"</string>
-    <string name="accessibility_airplane_mode" msgid="834748999790763092">"飛航模式。"</string>
-    <!-- String.format failed for translation -->
-    <!-- no translation found for accessibility_battery_level (7451474187113371965) -->
-    <skip />
-    <string name="accessibility_settings_button" msgid="799583911231893380">"系統設定"</string>
-    <string name="accessibility_notifications_button" msgid="4498000369779421892">"通知。"</string>
-    <string name="accessibility_remove_notification" msgid="3603099514902182350">"清除通知。"</string>
-    <string name="accessibility_gps_enabled" msgid="3511469499240123019">"GPS 已啟用。"</string>
-    <string name="accessibility_gps_acquiring" msgid="8959333351058967158">"正在取得 GPS 訊號。"</string>
-    <string name="accessibility_tty_enabled" msgid="4613200365379426561">"TeleTypewriter (TTY) 已啟用。"</string>
-    <string name="accessibility_ringer_vibrate" msgid="666585363364155055">"鈴聲震動。"</string>
-    <string name="accessibility_ringer_silent" msgid="9061243307939135383">"鈴聲靜音。"</string>
-    <string name="accessibility_recents_item_dismissed" msgid="6803574935084867070">"「<xliff:g id="APP">%s</xliff:g>」已關閉。"</string>
-    <string name="accessibility_notification_dismissed" msgid="854211387186306927">"通知已關閉。"</string>
-    <string name="accessibility_desc_notification_shade" msgid="4690274844447504208">"通知欄。"</string>
-    <string name="accessibility_desc_quick_settings" msgid="6186378411582437046">"快速設定。"</string>
-    <string name="accessibility_desc_recent_apps" msgid="9014032916410590027">"最近使用的應用程式"</string>
-    <string name="accessibility_quick_settings_user" msgid="1104846699869476855">"用戶:<xliff:g id="USER">%s</xliff:g>。"</string>
-    <string name="accessibility_quick_settings_wifi" msgid="6099781031669728709">"<xliff:g id="SIGNAL">%1$s</xliff:g>、<xliff:g id="NETWORK">%2$s</xliff:g>"</string>
-    <string name="accessibility_quick_settings_mobile" msgid="4876806564086241341">"流動數據連線:<xliff:g id="SIGNAL">%1$s</xliff:g>、<xliff:g id="TYPE">%2$s</xliff:g>、<xliff:g id="NETWORK">%3$s</xliff:g>。"</string>
-    <string name="accessibility_quick_settings_battery" msgid="1480931583381408972">"電池電量:<xliff:g id="STATE">%s</xliff:g>。"</string>
-    <string name="accessibility_quick_settings_airplane" msgid="4196876722090224753">"飛航模式:<xliff:g id="STATE">%s</xliff:g>。"</string>
-    <string name="accessibility_quick_settings_bluetooth" msgid="5749054971341882340">"藍牙:<xliff:g id="STATE">%s</xliff:g>。"</string>
-    <string name="accessibility_quick_settings_alarm" msgid="3959908972897295660">"鬧鐘已設定為:<xliff:g id="TIME">%s</xliff:g>。"</string>
-    <string name="data_usage_disabled_dialog_3g_title" msgid="5257833881698644687">"已停用 2G-3G 數據"</string>
-    <string name="data_usage_disabled_dialog_4g_title" msgid="4789143363492682629">"已停用 4G 數據"</string>
-    <string name="data_usage_disabled_dialog_mobile_title" msgid="1046047248844821202">"已停用流動數據"</string>
-    <string name="data_usage_disabled_dialog_title" msgid="2086815304858964954">"數據停用"</string>
-    <string name="data_usage_disabled_dialog" msgid="3853117269051806280">"您已到達指定的數據用量上限。\n\n如果您重新啟用數據傳輸,流動網絡供應商可能會向您收費。"</string>
-    <string name="data_usage_disabled_dialog_enable" msgid="7729772039208664606">"重新啟用數據"</string>
-    <string name="status_bar_settings_signal_meter_disconnected" msgid="1940231521274147771">"沒有互聯網連線"</string>
-    <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi 已連線"</string>
-    <string name="gps_notification_searching_text" msgid="8574247005642736060">"正在搜尋 GPS"</string>
-    <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS 已定位"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"位置要求啟動中"</string>
-    <string name="accessibility_clear_all" msgid="5235938559247164925">"清除所有通知。"</string>
-    <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"應用程式資訊"</string>
-    <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"屏幕會自動旋轉。"</string>
-    <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"屏幕已鎖定為橫向模式。"</string>
-    <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"屏幕已鎖定為垂直模式。"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
-    <string name="start_dreams" msgid="7219575858348719790">"Daydream"</string>
-    <string name="ethernet_label" msgid="7967563676324087464">"以太網"</string>
-    <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"飛行模式"</string>
-    <string name="quick_settings_battery_charging_label" msgid="490074774465309209">"充電中 (<xliff:g id="NUMBER">%d</xliff:g><xliff:g id="PERCENT">%%</xliff:g>)"</string>
-    <string name="quick_settings_battery_charged_label" msgid="8865413079414246081">"充電完成"</string>
-    <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"藍牙"</string>
-    <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"藍牙 (<xliff:g id="NUMBER">%d</xliff:g> 部裝置)"</string>
-    <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"藍牙關閉"</string>
-    <string name="quick_settings_brightness_label" msgid="6968372297018755815">"亮度"</string>
-    <string name="quick_settings_rotation_unlocked_label" msgid="336054930362580584">"自動旋轉"</string>
-    <string name="quick_settings_rotation_locked_label" msgid="8058646447242565486">"已鎖定屏幕旋轉功能"</string>
-    <string name="quick_settings_ime_label" msgid="7073463064369468429">"輸入法"</string>
-    <string name="quick_settings_location_label" msgid="5011327048748762257">"位置"</string>
-    <string name="quick_settings_location_off_label" msgid="7464544086507331459">"位置關閉"</string>
-    <string name="quick_settings_media_device_label" msgid="1302906836372603762">"媒體裝置"</string>
-    <string name="quick_settings_rssi_label" msgid="7725671335550695589">"RSSI"</string>
-    <string name="quick_settings_rssi_emergency_only" msgid="2713774041672886750">"只可撥打緊急電話"</string>
-    <string name="quick_settings_settings_label" msgid="5326556592578065401">"設定"</string>
-    <string name="quick_settings_time_label" msgid="4635969182239736408">"時間"</string>
-    <string name="quick_settings_user_label" msgid="5238995632130897840">"我"</string>
-    <string name="quick_settings_wifi_label" msgid="9135344704899546041">"Wi-Fi"</string>
-    <string name="quick_settings_wifi_not_connected" msgid="7171904845345573431">"未連線"</string>
-    <string name="quick_settings_wifi_no_network" msgid="2221993077220856376">"沒有網絡"</string>
-    <string name="quick_settings_wifi_off_label" msgid="7558778100843885864">"Wi-Fi 關閉"</string>
-    <string name="quick_settings_wifi_display_label" msgid="6893592964463624333">"Wi-Fi Display"</string>
-    <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"無線顯示"</string>
-    <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"亮度"</string>
-    <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"自動"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"網絡可能會\n受到監控"</string>
-</resources>
diff --git a/packages/SystemUI/res/values-zh-rTW/strings.xml b/packages/SystemUI/res/values-zh-rTW/strings.xml
index 6085c34..2cfdb59 100644
--- a/packages/SystemUI/res/values-zh-rTW/strings.xml
+++ b/packages/SystemUI/res/values-zh-rTW/strings.xml
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"一律允許透過這台電腦進行"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"放大為全螢幕"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"放大為全螢幕"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"相容性縮放"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"執行專為較小螢幕設計的應用程式時,系統會在時鐘旁顯示縮放控制項。"</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"正在儲存螢幕擷取畫面…"</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"正在儲存螢幕擷取畫面…"</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"正在儲存螢幕擷取畫面。"</string>
@@ -76,8 +78,6 @@
     <string name="accessibility_home" msgid="8217216074895377641">"主螢幕"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"選單"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"最近使用的應用程式"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"搜尋"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"相機"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"切換輸入法按鈕。"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"相容性縮放按鈕。"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"將較小螢幕的畫面放大在較大螢幕上顯示。"</string>
@@ -166,13 +166,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"Wi-Fi 已連線"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"正在搜尋 GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"GPS 已定位"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"有位置資訊要求"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"清除所有通知。"</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"應用程式資訊"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"螢幕會自動旋轉。"</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"螢幕已鎖定為橫向模式。"</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"螢幕已鎖定為垂直模式。"</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Dessert Case"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"休眠模式"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"乙太網路"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"飛航模式"</string>
@@ -201,5 +200,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"無線螢幕分享"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"亮度"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"自動"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"網路可能\n受到監控"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"系統會在這裡顯示通知"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"向下滑動即可隨時存取通知。\n再次向下滑動即可使用系統控制項。"</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"滑動螢幕邊緣即可顯示導覽列"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"從螢幕邊緣向內滑動即可顯示導覽列"</string>
 </resources>
diff --git a/packages/SystemUI/res/values-zu/strings.xml b/packages/SystemUI/res/values-zu/strings.xml
index 14d3091..007d338 100644
--- a/packages/SystemUI/res/values-zu/strings.xml
+++ b/packages/SystemUI/res/values-zu/strings.xml
@@ -24,10 +24,10 @@
     <string name="status_bar_recent_remove_item_title" msgid="6026395868129852968">"Susa ohlwini"</string>
     <string name="status_bar_recent_inspect_item_title" msgid="7793624864528818569">"Ulwazi lwensiza"</string>
     <string name="status_bar_no_recent_apps" msgid="6576392951053994640">"Azikho izinhlelo zokusebenza zakamuva"</string>
-    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Susa izinhlelo zokusebenza zakamumva"</string>
+    <string name="status_bar_accessibility_dismiss_recents" msgid="4576076075226540105">"Susa izinsiza zakamumva"</string>
   <plurals name="status_bar_accessibility_recent_apps">
     <item quantity="one" msgid="5854176083865845541">"Insiza eyi-1 yakamumva"</item>
-    <item quantity="other" msgid="1040784359794890744">"%d izinhlelo zokusebenza zakamumva"</item>
+    <item quantity="other" msgid="1040784359794890744">"%d izinsiza zakamumva"</item>
   </plurals>
     <string name="status_bar_no_notifications_title" msgid="4755261167193833213">"Azikho izaziso"</string>
     <string name="status_bar_ongoing_events_title" msgid="1682504513316879202">"Okuqhubekayo"</string>
@@ -47,11 +47,11 @@
     <string name="bluetooth_tethered" msgid="7094101612161133267">"Ukusebenzisa i-Bluetooth njengemodemu"</string>
     <string name="status_bar_input_method_settings_configure_input_methods" msgid="3504292471512317827">"Izilungiselelo zezindlela zokufakwayo"</string>
     <string name="status_bar_use_physical_keyboard" msgid="7551903084416057810">"Ukwakheka kwekhibhodi"</string>
-    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Vumela uhlelo lokusebenza <xliff:g id="APPLICATION">%1$s</xliff:g> ukuthi ufinyelele ezintweni eziphuma ne-USB?"</string>
-    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Vumela uhlelo lokusebenza <xliff:g id="APPLICATION">%1$s</xliff:g> ukuthi ufinyelele ezintweni eziphuma ne-USB?"</string>
+    <string name="usb_device_permission_prompt" msgid="834698001271562057">"Vumela insiza <xliff:g id="APPLICATION">%1$s</xliff:g> ukuthi ufinyelele ezintweni eziphuma ne-USB?"</string>
+    <string name="usb_accessory_permission_prompt" msgid="5171775411178865750">"Vumela insiza <xliff:g id="APPLICATION">%1$s</xliff:g> ukuthi ufinyelele ezintweni eziphuma ne-USB?"</string>
     <string name="usb_device_confirm_prompt" msgid="5161205258635253206">"Vula <xliff:g id="ACTIVITY">%1$s</xliff:g> uma ledivayisi ye-USB ixhunyiwe?"</string>
     <string name="usb_accessory_confirm_prompt" msgid="3808984931830229888">"Vula <xliff:g id="ACTIVITY">%1$s</xliff:g> uma le-accessory ye-USB ixhunyiwe"</string>
-    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Azikho izinhlelo zokusebenza ezisebenze ngezinto ze-USB. Funda okwengeziwe ngale into kwi <xliff:g id="URL">%1$s</xliff:g>"</string>
+    <string name="usb_accessory_uri_prompt" msgid="513450621413733343">"Azikho izinsiza ezisebenze ngezinto ze-USB. Funda okwengeziwe ngale into kwi <xliff:g id="URL">%1$s</xliff:g>"</string>
     <string name="title_usb_accessory" msgid="4966265263465181372">"ama-accessory e-USB"</string>
     <string name="label_view" msgid="6304565553218192990">"Buka"</string>
     <string name="always_use_device" msgid="1450287437017315906">"Sebenzisa ngokuzenzakalelayo yale divayisi ye-USB"</string>
@@ -61,6 +61,8 @@
     <string name="usb_debugging_always" msgid="303335496705863070">"Hlala uvumela njalo kusuka kule khompyutha"</string>
     <string name="compat_mode_on" msgid="6623839244840638213">"Sondeza ukugcwalisa isikrini"</string>
     <string name="compat_mode_off" msgid="4434467572461327898">"Nweba ukugcwalisa isikrini"</string>
+    <string name="compat_mode_help_header" msgid="7969493989397529910">"Ukuhambelana Kokusondeza"</string>
+    <string name="compat_mode_help_body" msgid="4946726776359270040">"Uma uhlelo lokusebenza lwenzelwe isikrini ezincane, isilawuli sokusondeza sizovela ngakuyiwashi."</string>
     <string name="screenshot_saving_ticker" msgid="7403652894056693515">"Ilondoloz umfanekiso weskrini..."</string>
     <string name="screenshot_saving_title" msgid="8242282144535555697">"Ilondoloz umfanekiso weskrini..."</string>
     <string name="screenshot_saving_text" msgid="2419718443411738818">"Umfanekiso weskrini uyalondolozwa."</string>
@@ -71,13 +73,11 @@
     <string name="usb_preference_title" msgid="6551050377388882787">"Okukhethwa kokudluliswa kwefayela ye-USB"</string>
     <string name="use_mtp_button_title" msgid="4333504413563023626">"Lengisa njengesidlali semediya (MTP)"</string>
     <string name="use_ptp_button_title" msgid="7517127540301625751">"Lengisa ikhamera (PTP)"</string>
-    <string name="installer_cd_button_title" msgid="2312667578562201583">"Faka uhlelo lokusebenza yokudluliswa Kwefayela ye-Android kwi-Mac"</string>
+    <string name="installer_cd_button_title" msgid="2312667578562201583">"Faka insiza yokudluliswa Kwefayela ye-Android kwi-Mac"</string>
     <string name="accessibility_back" msgid="567011538994429120">"Emuva"</string>
     <string name="accessibility_home" msgid="8217216074895377641">"Ekhaya"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"Imenyu"</string>
     <string name="accessibility_recent" msgid="8571350598987952883">"Izinhlelo zokusebenza zakamuva"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"Sesha"</string>
-    <string name="accessibility_camera_button" msgid="8064671582820358152">"Ikhamela"</string>
     <string name="accessibility_ime_switch_button" msgid="5032926134740456424">"Vula indlela yokungena yenkinobho"</string>
     <string name="accessibility_compatibility_zoom_button" msgid="8461115318742350699">"Inkinobho evumelekile yokusondeza"</string>
     <string name="accessibility_compatibility_zoom_example" msgid="4220687294564945780">"Sondeza kancane esikrinini esikhudlwana"</string>
@@ -164,13 +164,12 @@
     <string name="status_bar_settings_signal_meter_wifi_nossid" msgid="6557486452774597820">"I-Wi-Fi ixhunyiwe"</string>
     <string name="gps_notification_searching_text" msgid="8574247005642736060">"Isesha i-GPS"</string>
     <string name="gps_notification_found_text" msgid="4619274244146446464">"Indawo ihlelwe i-GPS"</string>
-    <string name="accessibility_location_active" msgid="2427290146138169014">"Izicelo zendawo ziyasebenza"</string>
     <string name="accessibility_clear_all" msgid="5235938559247164925">"Susa zonke izaziso."</string>
     <string name="status_bar_notification_inspect_item_title" msgid="1163547729015390250">"Ulwazi lohlelo lokusebenza"</string>
     <string name="accessibility_rotation_lock_off" msgid="4062780228931590069">"Isikrini sizophenduka ngokuzenzakalela."</string>
     <string name="accessibility_rotation_lock_on_landscape" msgid="6731197337665366273">"Isikrini sikhiyelwe ngomumo we-landscape."</string>
     <string name="accessibility_rotation_lock_on_portrait" msgid="5809367521644012115">"Isikrini sikhiyelwe ngomumo we-portrait."</string>
-    <string name="dessert_case" msgid="1295161776223959221">"Isikhwama soswidi"</string>
+    <string name="jelly_bean_dream_name" msgid="5992026543636816792">"I-BeanFlinger"</string>
     <string name="start_dreams" msgid="7219575858348719790">"Ukuphupha emini"</string>
     <string name="ethernet_label" msgid="7967563676324087464">"I-Ethernet"</string>
     <string name="quick_settings_airplane_mode_label" msgid="5510520633448831350">"Isimo sendiza"</string>
@@ -199,5 +198,8 @@
     <string name="quick_settings_wifi_display_no_connection_label" msgid="2355298740765736918">"Ukubonisa okungenazintambo"</string>
     <string name="quick_settings_brightness_dialog_title" msgid="8599674057673605368">"Ukugqama"</string>
     <string name="quick_settings_brightness_dialog_auto_brightness_label" msgid="5064982743784071218">"OKUZENZAKALELAYO"</string>
-    <string name="ssl_ca_cert_warning" msgid="9005954106902053641">"Kungenzeka inethiwekhi\niqashiwe"</string>
+    <string name="status_bar_help_title" msgid="1199237744086469217">"Izaziso zivela lapha"</string>
+    <string name="status_bar_help_text" msgid="7874607155052076323">"Kufinyelele noma kunini ngokuswayiphela phansi.\nSwayiphela phansi futhi ngezilawuli zesistimu."</string>
+    <string name="hideybar_confirmation_message" msgid="9050869548951044371">"Swayipha unqenqema wesikrini ukuze uveze ibha"</string>
+    <string name="hideybar_confirmation_message_long" msgid="7117692795163620626">"Swayipha kusukela kunqenqema ukuze uveze ibha yesistimu"</string>
 </resources>
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
index 2063563..74d982a 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -60,6 +60,7 @@
 
 import java.io.File;
 import java.io.OutputStream;
+import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -214,8 +215,7 @@
             values.put(MediaStore.Images.ImageColumns.HEIGHT, mImageHeight);
             Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
 
-            String subjectDate = new SimpleDateFormat("hh:mma, MMM dd, yyyy")
-                .format(new Date(mImageTime));
+            String subjectDate = DateFormat.getDateTimeInstance().format(new Date(mImageTime));
             String subject = String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
             Intent sharingIntent = new Intent(Intent.ACTION_SEND);
             sharingIntent.setType("image/png");
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 839016d..9589e8b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -521,6 +521,11 @@
             Log.d(TAG, "reorient(): rot=" + mDisplay.getRotation());
         }
 
+        // swap to x coordinate if orientation is not in vertical
+        if (mDelegateHelper != null) {
+            mDelegateHelper.setSwapXY(!mVertical);
+        }
+
         setNavigationIconHints(mNavigationIconHints, true);
     }
 
diff --git a/packages/VpnDialogs/res/values-en-rIN/strings.xml b/packages/VpnDialogs/res/values-en-rIN/strings.xml
deleted file mode 100644
index afc46d8..0000000
--- a/packages/VpnDialogs/res/values-en-rIN/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> attempts to create a VPN connection."</string>
-    <string name="warning" msgid="5470743576660160079">"By proceeding, you are giving the application permission to intercept all network traffic. "<b>"Do NOT accept unless you trust the application."</b>" Otherwise, you run the risk of having your data compromised by malicious software."</string>
-    <string name="accept" msgid="2889226408765810173">"I trust this application."</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN is connected"</string>
-    <string name="configure" msgid="4905518375574791375">"Configure"</string>
-    <string name="disconnect" msgid="971412338304200056">"Disconnect"</string>
-    <string name="session" msgid="6470628549473641030">"Session:"</string>
-    <string name="duration" msgid="3584782459928719435">"Duration:"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"Sent:"</string>
-    <string name="data_received" msgid="4062776929376067820">"Received:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> bytes / <xliff:g id="NUMBER_1">%2$s</xliff:g> packets"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-et-rEE/strings.xml b/packages/VpnDialogs/res/values-et-rEE/strings.xml
deleted file mode 100644
index c016eb0..0000000
--- a/packages/VpnDialogs/res/values-et-rEE/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"Rakenduse <xliff:g id="APP">%s</xliff:g> katsed luua VPN-ühendust."</string>
-    <string name="warning" msgid="5470743576660160079">"Jätkates annate rakendusele loa jälgida kogu võrguliiklust. "<b>"ÄRGE nõustuge, kui te seda rakendust ei usalda."</b>" Vastasel juhul on oht, et pahavara võib kahjustada teie andmeid."</string>
-    <string name="accept" msgid="2889226408765810173">"Usaldan seda rakendust."</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN on ühendatud"</string>
-    <string name="configure" msgid="4905518375574791375">"Seadistamine"</string>
-    <string name="disconnect" msgid="971412338304200056">"Katkesta ühendus"</string>
-    <string name="session" msgid="6470628549473641030">"Seansid"</string>
-    <string name="duration" msgid="3584782459928719435">"Kestus:"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"Saadetud:"</string>
-    <string name="data_received" msgid="4062776929376067820">"Vastu on võetud:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> baiti / <xliff:g id="NUMBER_1">%2$s</xliff:g> paketti"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-fr-rCA/strings.xml b/packages/VpnDialogs/res/values-fr-rCA/strings.xml
deleted file mode 100644
index 1028f83..0000000
--- a/packages/VpnDialogs/res/values-fr-rCA/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> tente de créer une connexion VPN."</string>
-    <string name="warning" msgid="5470743576660160079">"En continuant, vous autorisez l\'application à intercepter l\'ensemble du trafic réseau. "<b>"N\'acceptez PAS, sauf si vous avez confiance en l\'application."</b>"Sinon, vos données risquent d\'être piratées par un logiciel malveillant."</string>
-    <string name="accept" msgid="2889226408765810173">"J\'ai confiance en cette application."</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN connecté"</string>
-    <string name="configure" msgid="4905518375574791375">"Configurer"</string>
-    <string name="disconnect" msgid="971412338304200056">"Déconnecter"</string>
-    <string name="session" msgid="6470628549473641030">"Session :"</string>
-    <string name="duration" msgid="3584782459928719435">"Durée :"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"Date d\'envoi :"</string>
-    <string name="data_received" msgid="4062776929376067820">"Reçu le :"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> octets / <xliff:g id="NUMBER_1">%2$s</xliff:g> paquets"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-hi/strings.xml b/packages/VpnDialogs/res/values-hi/strings.xml
index 50be98c..e2cb51a 100644
--- a/packages/VpnDialogs/res/values-hi/strings.xml
+++ b/packages/VpnDialogs/res/values-hi/strings.xml
@@ -17,8 +17,8 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> एक VPN कनेक्‍शन बनाने का प्रयास करता है."</string>
-    <string name="warning" msgid="5470743576660160079">"जारी रखकर, आप एप्स को सभी नेटवर्क ट्रैफ़िक अवरोधित करने की अनुमति देते हैं. "<b>"जब तक आपको एप्स पर विश्वास न हो स्‍वीकार न करें."</b>" अन्‍यथा, आपको अपने डेटा के साथ किसी दुर्भावनापूर्ण सॉफ़्टवेयर द्वारा छेड़छाड़ किए जाने का जोखिम हो सकता है."</string>
-    <string name="accept" msgid="2889226408765810173">"मुझे इस एप्स पर विश्वास है."</string>
+    <string name="warning" msgid="5470743576660160079">"जारी रखकर, आप एप्लिकेशन को सभी नेटवर्क ट्रैफ़िक अवरोधित करने की अनुमति देते हैं. "<b>"जब तक आपको एप्लिकेशन पर विश्वास न हो स्‍वीकार न करें."</b>" अन्‍यथा, आपको अपने डेटा के साथ किसी दुर्भावनापूर्ण सॉफ़्टवेयर द्वारा छेड़छाड़ किए जाने का जोखिम हो सकता है."</string>
+    <string name="accept" msgid="2889226408765810173">"मुझे इस एप्लिकेशन पर विश्वास है."</string>
     <string name="legacy_title" msgid="192936250066580964">"VPN कनेक्‍ट है"</string>
     <string name="configure" msgid="4905518375574791375">"कॉन्फ़िगर करें"</string>
     <string name="disconnect" msgid="971412338304200056">"डिस्‍कनेक्‍ट करें"</string>
diff --git a/packages/VpnDialogs/res/values-hy-rAM/strings.xml b/packages/VpnDialogs/res/values-hy-rAM/strings.xml
deleted file mode 100644
index 85db579..0000000
--- a/packages/VpnDialogs/res/values-hy-rAM/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g>-ը փորձում է ստեղծել VPN կապ:"</string>
-    <string name="warning" msgid="5470743576660160079">"Շարունակելով` դուք հավելվածին թույլատրում եք կանգնեցնել ամբողջ ցանցային շարժը: "<b>"Մի ընդունեք, եթե չեք վստահում հավելվածին:"</b>" Այլապես ռիսկ կա ձեր տվյալները վտանգելու վնասարար հավելվածների կողմից:"</string>
-    <string name="accept" msgid="2889226408765810173">"Ես վստահում եմ այս ծրագրին:"</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN-ը կապակցված է"</string>
-    <string name="configure" msgid="4905518375574791375">"Կարգավորել"</string>
-    <string name="disconnect" msgid="971412338304200056">"Անջատել"</string>
-    <string name="session" msgid="6470628549473641030">"Աշխատաշրջան`"</string>
-    <string name="duration" msgid="3584782459928719435">"Տևողությունը՝"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"Ուղարկվել է՝"</string>
-    <string name="data_received" msgid="4062776929376067820">"Ստացվել է՝"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> բայթ / <xliff:g id="NUMBER_1">%2$s</xliff:g> փաթեթ"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-iw/strings.xml b/packages/VpnDialogs/res/values-iw/strings.xml
index 9082180..bb845ee 100644
--- a/packages/VpnDialogs/res/values-iw/strings.xml
+++ b/packages/VpnDialogs/res/values-iw/strings.xml
@@ -17,8 +17,8 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> מנסה ליצור חיבור VPN."</string>
-    <string name="warning" msgid="5470743576660160079">"אם תמשיך, אתה מעניק לאפליקציה הרשאה לעכב את כל התנועה ברשת. "<b>" אל תקבל אלא אם כן אתה סומך על האפליקציה. "</b>" אחרת, אתה חושף את הנתונים שלך לסכנה של פגיעה על-ידי תוכנה זדונית."</string>
-    <string name="accept" msgid="2889226408765810173">"אני סומך על אפליקציה זו."</string>
+    <string name="warning" msgid="5470743576660160079">"אם תמשיך, אתה מעניק ליישום הרשאה לעכב את כל התנועה ברשת. "<b>" אל תקבל אלא אם כן אתה סומך על היישום. "</b>" אחרת, אתה חושף את הנתונים שלך לסכנה של פגיעה על-ידי תוכנה זדונית."</string>
+    <string name="accept" msgid="2889226408765810173">"אני סומך על יישום זה."</string>
     <string name="legacy_title" msgid="192936250066580964">"VPN מחובר"</string>
     <string name="configure" msgid="4905518375574791375">"הגדר"</string>
     <string name="disconnect" msgid="971412338304200056">"נתק"</string>
diff --git a/packages/VpnDialogs/res/values-ka-rGE/strings.xml b/packages/VpnDialogs/res/values-ka-rGE/strings.xml
deleted file mode 100644
index 960d3f6..0000000
--- a/packages/VpnDialogs/res/values-ka-rGE/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> ცდილობს VPN კავშირის შექმნას."</string>
-    <string name="warning" msgid="5470743576660160079">"გაგრძელების შემთხვევაში, აპლიკაციას ექნება ქსელში გადაცემული მონაცემების მოპოვების საშუალება. "<b>"არ განაგრძოთ, თუ არ ენდობით აპლიკაციას."</b>" წინააღმდეგ შემთვევაში შესაძლოა მავნე პროგრამას თქვენ მონაცემებთან წვდომის საშუალება მიეცეს."</string>
-    <string name="accept" msgid="2889226408765810173">"ვენდობი ამ აპლიკაციას."</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN დაკავშირებულია"</string>
-    <string name="configure" msgid="4905518375574791375">"კონფიგურაცია"</string>
-    <string name="disconnect" msgid="971412338304200056">"კავშირის გაწყვეტა"</string>
-    <string name="session" msgid="6470628549473641030">"სესია:"</string>
-    <string name="duration" msgid="3584782459928719435">"ხანგრძლივობა:"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"გაგზავნილი:"</string>
-    <string name="data_received" msgid="4062776929376067820">"მიღებული:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> ბაიტი / <xliff:g id="NUMBER_1">%2$s</xliff:g> პაკეტი"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-km-rKH/strings.xml b/packages/VpnDialogs/res/values-km-rKH/strings.xml
deleted file mode 100644
index 2c79e26..0000000
--- a/packages/VpnDialogs/res/values-km-rKH/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> ព្យាយាម​បង្កើត​ការ​តភ្ជាប់ VPN ។"</string>
-    <string name="warning" msgid="5470743576660160079">"ដោយ​បន្ត អ្នក​កំពុង​ផ្ដល់​សិទ្ធិ​ឲ្យ​កម្មវិធី​ទប់ស្កាត់​ចរាចរណ៍​បណ្ដាញ។ "<b>"កុំ​ទទួល​ លុះ​ត្រា​តែ​អ្នក​ទុក​ចិត្ត​កម្មវិធី។"</b>" បើ​មិន​ដូច្នេះ​ទេ អ្នក​ដំណើរការ​ប្រឈម​នឹង​គ្រោះថ្នាក់ ដោយ​ទិន្នន័យ​របស់​អ្នក​បាន​សម្របសម្រួល​ដោយ​កម្មវិធី​ព្យាបាទ។"</string>
-    <string name="accept" msgid="2889226408765810173">"ខ្ញុំ​ទុកចិត្ត​​​កម្មវិធី​នេះ​។"</string>
-    <string name="legacy_title" msgid="192936250066580964">"បា​ន​ភ្ជាប់ VPN"</string>
-    <string name="configure" msgid="4905518375574791375">"កំណត់​រចនាសម្ព័ន្ធ"</string>
-    <string name="disconnect" msgid="971412338304200056">"ផ្ដាច់"</string>
-    <string name="session" msgid="6470628549473641030">"សម័យ៖"</string>
-    <string name="duration" msgid="3584782459928719435">"ថិរវេលា៖"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"បាន​ផ្ញើ៖"</string>
-    <string name="data_received" msgid="4062776929376067820">"បាន​ទទួល៖"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> បៃ / <xliff:g id="NUMBER_1">%2$s</xliff:g> កញ្ចប់​ព័ត៌មាន"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-lo-rLA/strings.xml b/packages/VpnDialogs/res/values-lo-rLA/strings.xml
deleted file mode 100644
index 9f5216b..0000000
--- a/packages/VpnDialogs/res/values-lo-rLA/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> ພະຍາຍາມສ້າງການເຊື່ອມຕໍ່ VPN."</string>
-    <string name="warning" msgid="5470743576660160079">"ຖ້າດຳເນີນຕໍ່, ແມ່ນທ່ານກຳລັງຈະໃຫ້ສິດແກ່ແອັບພລິເຄຊັນ ໃນການດັກຂໍ້ມູນຈະລາຈອນໃນເຄືອຂ່າຍທັງໝົດ. "<b>"ຢ່າຍອມຮັບ ນອກຈາກວ່າທ່ານຈະເຊື່ອໃຈແອັບພລິເຄຊັນດັ່ງກ່າວ."</b>" ຖ້າບໍ່ດັ່ງນັ້ນ, ທ່ານຈະຕົກຢູ່ໃນຄວາມສ່ຽງ ທີ່ຂໍ້ມູນຂອງທ່ານຈະຖືກຄຸກຄາມໂດຍຊອບແວທີ່ເປັນອັນຕະລາຍ."</string>
-    <string name="accept" msgid="2889226408765810173">"ຂ້ອຍເຊື່ອແອັບພລິເຄຊັນນີ້."</string>
-    <string name="legacy_title" msgid="192936250066580964">"ເຊື່ອມຕໍ່ VPN ແລ້ວ"</string>
-    <string name="configure" msgid="4905518375574791375">"ປັບຄ່າ"</string>
-    <string name="disconnect" msgid="971412338304200056">"ຕັດການເຊື່ອມຕໍ່"</string>
-    <string name="session" msgid="6470628549473641030">"ເຊສຊັນ:"</string>
-    <string name="duration" msgid="3584782459928719435">"ໄລຍະເວລາ:"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"ສົ່ງ:"</string>
-    <string name="data_received" msgid="4062776929376067820">"ຮັບ:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> ໄບ / <xliff:g id="NUMBER_1">%2$s</xliff:g> ແພັກເກັດ"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-mn-rMN/strings.xml b/packages/VpnDialogs/res/values-mn-rMN/strings.xml
deleted file mode 100644
index 887bb73..0000000
--- a/packages/VpnDialogs/res/values-mn-rMN/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> VPN холболтыг үүсгэх гэж байна."</string>
-    <string name="warning" msgid="5470743576660160079">"Үргэлжлүүлсэнээр та аппликешнд бүх сүлжээний урсгалыг таслах зөвшөөрлийг өгөх болно. "<b>"Аппикешн баталгаагүй гэж үзсэн тохиолдолд л зөвшөөрч болорхгүй."</b>" Бусад тохиолдолд та өөрийн датаг хортой софтверийн аюулд өртөх эрсдэлийг үүсгэж байна."</string>
-    <string name="accept" msgid="2889226408765810173">"Би энэ аппликешнд итгэж байна."</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN холбогдов"</string>
-    <string name="configure" msgid="4905518375574791375">"Тохируулах"</string>
-    <string name="disconnect" msgid="971412338304200056">"Салгах"</string>
-    <string name="session" msgid="6470628549473641030">"Сешн:"</string>
-    <string name="duration" msgid="3584782459928719435">"Үргэлжлэх хугацаа:"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"Илгээсэн:"</string>
-    <string name="data_received" msgid="4062776929376067820">"Хүлээн авсан:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> байт/ <xliff:g id="NUMBER_1">%2$s</xliff:g> пакет"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-ms-rMY/strings.xml b/packages/VpnDialogs/res/values-ms-rMY/strings.xml
deleted file mode 100644
index 417fbae..0000000
--- a/packages/VpnDialogs/res/values-ms-rMY/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> percubaan untuk membuat sambungan VPN."</string>
-    <string name="warning" msgid="5470743576660160079">"Dengan meneruskan, anda memberi keizinan kepada aplikasi untuk memintas semua trafik rangkaian. "<b>"JANGAN terima melainkan anda mempercayai aplikasi itu."</b>" Jika tidak, anda akan mengalami risiko data terjejas oleh perisian berniat jahat."</string>
-    <string name="accept" msgid="2889226408765810173">"Saya percayai aplikasi ini."</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN telah disambungkan"</string>
-    <string name="configure" msgid="4905518375574791375">"Konfigurasikan"</string>
-    <string name="disconnect" msgid="971412338304200056">"Putuskan sambungan"</string>
-    <string name="session" msgid="6470628549473641030">"Sesi:"</string>
-    <string name="duration" msgid="3584782459928719435">"Tempoh:"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"Dihantar:"</string>
-    <string name="data_received" msgid="4062776929376067820">"Diterima:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> bait / <xliff:g id="NUMBER_1">%2$s</xliff:g> bingkisan"</string>
-</resources>
diff --git a/packages/VpnDialogs/res/values-nb/strings.xml b/packages/VpnDialogs/res/values-nb/strings.xml
index 6bffc98..f716422 100644
--- a/packages/VpnDialogs/res/values-nb/strings.xml
+++ b/packages/VpnDialogs/res/values-nb/strings.xml
@@ -17,8 +17,8 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> forsøker å etablere en VPN-tilkobling."</string>
-    <string name="warning" msgid="5470743576660160079">"Ved å fortsette gir du appen tillatelse til å fange opp all nettverkstrafikk. "<b>"IKKE godta med mindre du stoler på appen."</b>" Ellers risikerer du at dataene dine kompromitteres av en ondsinnet programvare."</string>
-    <string name="accept" msgid="2889226408765810173">"Jeg stoler på denne appen."</string>
+    <string name="warning" msgid="5470743576660160079">"Ved å fortsette gir du applikasjonen tillatelse til å fange opp all nettverkstrafikk. "<b>"IKKE godta med mindre du stoler på applikasjonen."</b>" Ellers risikerer du at dataene dine kompromitteres av en ondsinnet programvare."</string>
+    <string name="accept" msgid="2889226408765810173">"Jeg stoler på denne applikasjonen."</string>
     <string name="legacy_title" msgid="192936250066580964">"VPN er tilkoblet"</string>
     <string name="configure" msgid="4905518375574791375">"Konfigurer"</string>
     <string name="disconnect" msgid="971412338304200056">"Koble fra"</string>
diff --git a/packages/VpnDialogs/res/values-zh-rHK/strings.xml b/packages/VpnDialogs/res/values-zh-rHK/strings.xml
deleted file mode 100644
index 8b25d41..0000000
--- a/packages/VpnDialogs/res/values-zh-rHK/strings.xml
+++ /dev/null
@@ -1,30 +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:android="http://schemas.android.com/apk/res/android"
-    xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
-    <string name="prompt" msgid="8359175999006833462">"<xliff:g id="APP">%s</xliff:g> 嘗試建立 VPN 連線。"</string>
-    <string name="warning" msgid="5470743576660160079">"如果繼續進行,即表示您允許該應用程式攔截所有網絡流量。"<b>"除非您信任該應用程式,否則不應接受。"</b>"不然就會讓您的資料陷於遭惡意程式入侵的風險。"</string>
-    <string name="accept" msgid="2889226408765810173">"我信任這個應用程式。"</string>
-    <string name="legacy_title" msgid="192936250066580964">"VPN 已連線"</string>
-    <string name="configure" msgid="4905518375574791375">"設定"</string>
-    <string name="disconnect" msgid="971412338304200056">"中斷連線"</string>
-    <string name="session" msgid="6470628549473641030">"時段:"</string>
-    <string name="duration" msgid="3584782459928719435">"持續時間︰"</string>
-    <string name="data_transmitted" msgid="7988167672982199061">"已傳送:"</string>
-    <string name="data_received" msgid="4062776929376067820">"已接收:"</string>
-    <string name="data_value_format" msgid="2192466557826897580">"<xliff:g id="NUMBER_0">%1$s</xliff:g> 位元組 / <xliff:g id="NUMBER_1">%2$s</xliff:g> 封包"</string>
-</resources>
diff --git a/policy/src/com/android/internal/policy/impl/GlobalActions.java b/policy/src/com/android/internal/policy/impl/GlobalActions.java
index 884f57e..7c0735b 100644
--- a/policy/src/com/android/internal/policy/impl/GlobalActions.java
+++ b/policy/src/com/android/internal/policy/impl/GlobalActions.java
@@ -887,6 +887,7 @@
             case MESSAGE_DISMISS:
                 if (mDialog != null) {
                     mDialog.dismiss();
+                    mDialog = null;
                 }
                 break;
             case MESSAGE_REFRESH:
diff --git a/policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java b/policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java
index 6bf4beb..968976b 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneLayoutInflater.java
@@ -26,7 +26,8 @@
 public class PhoneLayoutInflater extends LayoutInflater {
     private static final String[] sClassPrefixList = {
         "android.widget.",
-        "android.webkit."
+        "android.webkit.",
+        "android.app."
     };
     
     /**
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index 44fc1f8..7c047c3 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -38,6 +38,7 @@
 import com.android.internal.widget.ActionBarContextView;
 import com.android.internal.widget.ActionBarOverlayLayout;
 import com.android.internal.widget.ActionBarView;
+import com.android.internal.widget.SwipeDismissLayout;
 
 import android.app.KeyguardManager;
 import android.content.Context;
@@ -267,6 +268,15 @@
             // Remove the action bar feature if we have no title. No title dominates.
             removeFeature(FEATURE_ACTION_BAR);
         }
+
+        if ((features & (1 << FEATURE_ACTION_BAR)) != 0 && featureId == FEATURE_SWIPE_TO_DISMISS) {
+            throw new AndroidRuntimeException(
+                    "You cannot combine swipe dismissal and the action bar.");
+        }
+        if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0 && featureId == FEATURE_ACTION_BAR) {
+            throw new AndroidRuntimeException(
+                    "You cannot combine swipe dismissal and the action bar.");
+        }
         return super.requestFeature(featureId);
     }
 
@@ -2838,6 +2848,10 @@
             requestFeature(FEATURE_ACTION_MODE_OVERLAY);
         }
 
+        if (a.getBoolean(com.android.internal.R.styleable.Window_windowSwipeToDismiss, false)) {
+            requestFeature(FEATURE_SWIPE_TO_DISMISS);
+        }
+
         if (a.getBoolean(com.android.internal.R.styleable.Window_windowFullscreen, false)) {
             setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN & (~getForcedWindowFlags()));
         }
@@ -2964,7 +2978,9 @@
         int layoutResource;
         int features = getLocalFeatures();
         // System.out.println("Features: 0x" + Integer.toHexString(features));
-        if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) {
+        if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) {
+            layoutResource = com.android.internal.R.layout.screen_swipe_dismiss;
+        } else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) {
             if (mIsFloating) {
                 TypedValue res = new TypedValue();
                 getContext().getTheme().resolveAttribute(
@@ -3034,6 +3050,10 @@
             }
         }
 
+        if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) {
+            registerSwipeCallbacks();
+        }
+
         // Remaining setup -- of background and title -- that only applies
         // to top-level windows.
         if (getContainer() == null) {
@@ -3390,6 +3410,53 @@
         return (mRightIconView = (ImageView)findViewById(com.android.internal.R.id.right_icon));
     }
 
+    private void registerSwipeCallbacks() {
+        SwipeDismissLayout swipeDismiss =
+                (SwipeDismissLayout) findViewById(com.android.internal.R.id.content);
+        swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() {
+            @Override
+            public void onDismissed(SwipeDismissLayout layout) {
+                Callback cb = getCallback();
+                if (cb != null) {
+                    try {
+                        cb.onWindowDismissed();
+                    } catch (AbstractMethodError e) {
+                        Log.e(TAG, "onWindowDismissed not implemented in " +
+                                cb.getClass().getSimpleName(), e);
+                    }
+                }
+            }
+        });
+        swipeDismiss.setOnSwipeProgressChangedListener(
+                new SwipeDismissLayout.OnSwipeProgressChangedListener() {
+                    private boolean mIsTranslucent = false;
+
+                    @Override
+                    public void onSwipeProgressChanged(
+                            SwipeDismissLayout layout, float progress, float translate) {
+                        WindowManager.LayoutParams newParams = getAttributes();
+                        newParams.x = (int) translate;
+                        setAttributes(newParams);
+
+                        int flags = 0;
+                        if (newParams.x == 0) {
+                            flags = FLAG_FULLSCREEN;
+                        } else {
+                            flags = FLAG_LAYOUT_NO_LIMITS;
+                        }
+                        setFlags(flags, FLAG_FULLSCREEN | FLAG_LAYOUT_NO_LIMITS);
+                    }
+
+                    @Override
+                    public void onSwipeCancelled(SwipeDismissLayout layout) {
+                        WindowManager.LayoutParams newParams = getAttributes();
+                        newParams.x = 0;
+                        setAttributes(newParams);
+                        setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN | FLAG_LAYOUT_NO_LIMITS);
+                    }
+                });
+    }
+
     /**
      * Helper method for calling the {@link Callback#onPanelClosed(int, Menu)}
      * callback. This method will grab whatever extra state is needed for the
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index a7e0114..f53868b 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -231,7 +231,6 @@
     /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
     boolean mEnableShiftMenuBugReports = false;
 
-    boolean mHeadless;
     boolean mSafeMode;
     WindowState mStatusBar = null;
     int mStatusBarHeight;
@@ -284,6 +283,7 @@
     int mUserRotation = Surface.ROTATION_0;
     boolean mAccelerometerDefault;
 
+    boolean mSupportAutoRotation;
     int mAllowAllRotations = -1;
     boolean mCarDockEnablesAccelerometer;
     boolean mDeskDockEnablesAccelerometer;
@@ -592,13 +592,15 @@
      * screen is switched off.
      */
     boolean needSensorRunningLp() {
-        if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
-                || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
-                || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
-                || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
-            // If the application has explicitly requested to follow the
-            // orientation, then we need to turn the sensor or.
-            return true;
+        if (mSupportAutoRotation) {
+            if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
+                    || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
+                    || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
+                    || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
+                // If the application has explicitly requested to follow the
+                // orientation, then we need to turn the sensor on.
+                return true;
+            }
         }
         if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
                 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
@@ -619,7 +621,7 @@
             // still be turned off when the screen is off.)
             return false;
         }
-        return true;
+        return mSupportAutoRotation;
     }
 
     /*
@@ -856,7 +858,6 @@
         mContext = context;
         mWindowManager = windowManager;
         mWindowManagerFuncs = windowManagerFuncs;
-        mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
         mHandler = new PolicyHandler();
         mOrientationListener = new MyOrientationListener(mContext, mHandler);
         try {
@@ -885,6 +886,8 @@
         mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                 "PhoneWindowManager.mBroadcastWakeLock");
         mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
+        mSupportAutoRotation = mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_supportAutoRotation);
         mLidOpenRotation = readRotation(
                 com.android.internal.R.integer.config_lidOpenRotation);
         mCarDockRotation = readRotation(
@@ -1675,7 +1678,8 @@
             return view.getParent() != null ? view : null;
         } catch (WindowManager.BadTokenException e) {
             // ignore
-            Log.w(TAG, appToken + " already running, starting window not displayed");
+            Log.w(TAG, appToken + " already running, starting window not displayed. " +
+                    e.getMessage());
         } catch (RuntimeException e) {
             // don't crash if something else bad happens, for example a
             // failure loading resources because we are loading from an app
@@ -3607,9 +3611,6 @@
 
     /** {@inheritDoc} */
     public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
-        // do nothing if headless
-        if (mHeadless) return;
-
         // lid changed state
         final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
         if (newLidState == mLidState) {
@@ -3815,17 +3816,16 @@
                                                 mKeyguardDelegate.isShowingAndNotHidden() :
                                                 mKeyguardDelegate.isShowing()));
 
-        if (keyCode == KeyEvent.KEYCODE_POWER) {
+        if (keyCode == KeyEvent.KEYCODE_POWER
+                || keyCode == KeyEvent.KEYCODE_SLEEP
+                || keyCode == KeyEvent.KEYCODE_WAKEUP) {
             policyFlags |= WindowManagerPolicy.FLAG_WAKE;
         }
-        final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
-                | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
 
         if (DEBUG_INPUT) {
             Log.d(TAG, "interceptKeyTq keycode=" + keyCode
                     + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
-                    + " policyFlags=" + Integer.toHexString(policyFlags)
-                    + " isWakeKey=" + isWakeKey);
+                    + " policyFlags=" + Integer.toHexString(policyFlags));
         }
 
         if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
@@ -3842,15 +3842,17 @@
         //        the device some other way (which is why we have an exemption here for injected
         //        events).
         int result;
-        if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
+        boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
+                | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
+        if (isScreenOn || (isInjected && !isWakeKey)) {
             // When the screen is on or if the key is injected pass the key to the application.
             result = ACTION_PASS_TO_USER;
         } else {
             // When the screen is off and the key is not injected, determine whether
             // to wake the device but don't pass the key to the application.
             result = 0;
-            if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
-                result |= ACTION_WAKE_UP;
+            if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
+                isWakeKey = false;
             }
         }
 
@@ -3960,7 +3962,8 @@
                         }
                         if ((mEndcallBehavior
                                 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
-                            result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
+                            mPowerManager.goToSleep(event.getEventTime());
+                            isWakeKey = false;
                         }
                     }
                 }
@@ -4004,13 +4007,26 @@
                     mPowerKeyTriggered = false;
                     cancelPendingScreenshotChordAction();
                     if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
-                        result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
+                        mPowerManager.goToSleep(event.getEventTime());
+                        isWakeKey = false;
                     }
                     mPendingPowerKeyUpCanceled = false;
                 }
                 break;
             }
 
+            case KeyEvent.KEYCODE_SLEEP: {
+                result &= ~ACTION_PASS_TO_USER;
+                mPowerManager.goToSleep(event.getEventTime());
+                isWakeKey = false;
+                break;
+            }
+
+            case KeyEvent.KEYCODE_WAKEUP: {
+                result &= ~ACTION_PASS_TO_USER;
+                break;
+            }
+
             case KeyEvent.KEYCODE_MEDIA_PLAY:
             case KeyEvent.KEYCODE_MEDIA_PAUSE:
             case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
@@ -4074,6 +4090,10 @@
                 break;
             }
         }
+
+        if (isWakeKey) {
+            mPowerManager.wakeUp(event.getEventTime());
+        }
         return result;
     }
 
@@ -4114,13 +4134,13 @@
 
     /** {@inheritDoc} */
     @Override
-    public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
+    public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags) {
         int result = 0;
 
         final boolean isWakeMotion = (policyFlags
                 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
         if (isWakeMotion) {
-            result |= ACTION_WAKE_UP;
+            mPowerManager.wakeUp(whenNanos / 1000000);
         }
         return result;
     }
@@ -4484,6 +4504,10 @@
             } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
                 // Application just wants to remain locked in the last rotation.
                 preferredRotation = lastRotation;
+            } else if (!mSupportAutoRotation) {
+                // If we don't support auto-rotation then bail out here and ignore
+                // the sensor and any rotation lock settings.
+                preferredRotation = -1;
             } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
                             && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
                                     || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
@@ -4668,10 +4692,9 @@
     /** {@inheritDoc} */
     @Override
     public void systemReady() {
-        if (!mHeadless) {
-            mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
-            mKeyguardDelegate.onSystemReady();
-        }
+        mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
+        mKeyguardDelegate.onSystemReady();
+
         synchronized (mLock) {
             updateOrientationListenerLp();
             mSystemReady = true;
@@ -4698,7 +4721,6 @@
 
     /** {@inheritDoc} */
     public void showBootMessage(final CharSequence msg, final boolean always) {
-        if (mHeadless) return;
         mHandler.post(new Runnable() {
             @Override public void run() {
                 if (mBootMsgDialog == null) {
@@ -5295,6 +5317,7 @@
             pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
                     pw.println(mLastFocusNeedsMenu);
         }
+        pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
         pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
                 pw.print(" mDockMode="); pw.print(mDockMode);
                 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardServiceDelegate.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardServiceDelegate.java
index 1357462..e5af716 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardServiceDelegate.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardServiceDelegate.java
@@ -109,6 +109,9 @@
         if (!context.bindServiceAsUser(intent, mKeyguardConnection,
                 Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
             if (DEBUG) Log.v(TAG, "*** Keyguard: can't bind to " + KEYGUARD_CLASS);
+            mKeyguardState.showing = false;
+            mKeyguardState.showingAndNotHidden = false;
+            mKeyguardState.secure = false;
         } else {
             if (DEBUG) Log.v(TAG, "*** Keyguard started");
         }
diff --git a/preloaded-classes b/preloaded-classes
index 467da25..342126d 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -1428,7 +1428,6 @@
 com.android.internal.util.AsyncChannel$DeathMonitor
 com.android.internal.util.FastXmlSerializer
 com.android.internal.util.MemInfoReader
-com.android.internal.util.Objects
 com.android.internal.util.Preconditions
 com.android.internal.util.XmlUtils
 com.android.internal.view.ActionBarPolicy
@@ -1633,31 +1632,21 @@
 com.android.org.conscrypt.OpenSSLCipher$AES$CBC$NoPadding
 com.android.org.conscrypt.OpenSSLCipher$AES$CBC$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$AES$CFB
-com.android.org.conscrypt.OpenSSLCipher$AES$CFB$NoPadding
-com.android.org.conscrypt.OpenSSLCipher$AES$CFB$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$AES$CTR
-com.android.org.conscrypt.OpenSSLCipher$AES$CTR$NoPadding
-com.android.org.conscrypt.OpenSSLCipher$AES$CTR$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$AES$ECB
 com.android.org.conscrypt.OpenSSLCipher$AES$ECB$NoPadding
 com.android.org.conscrypt.OpenSSLCipher$AES$ECB$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$AES$OFB
-com.android.org.conscrypt.OpenSSLCipher$AES$OFB$NoPadding
-com.android.org.conscrypt.OpenSSLCipher$AES$OFB$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$ARC4
 com.android.org.conscrypt.OpenSSLCipher$DESEDE
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$CBC
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$CBC$NoPadding
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$CBC$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$CFB
-com.android.org.conscrypt.OpenSSLCipher$DESEDE$CFB$NoPadding
-com.android.org.conscrypt.OpenSSLCipher$DESEDE$CFB$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$ECB
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$ECB$NoPadding
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$ECB$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipher$DESEDE$OFB
-com.android.org.conscrypt.OpenSSLCipher$DESEDE$OFB$NoPadding
-com.android.org.conscrypt.OpenSSLCipher$DESEDE$OFB$PKCS5Padding
 com.android.org.conscrypt.OpenSSLCipherRSA
 com.android.org.conscrypt.OpenSSLCipherRSA$PKCS1
 com.android.org.conscrypt.OpenSSLCipherRSA$Raw
@@ -2034,6 +2023,7 @@
 java.security.cert.Certificate
 java.security.cert.CertificateFactory
 java.security.cert.CertificateFactorySpi
+java.security.cert.CertStoreParameters
 java.security.cert.PKIXCertPathChecker
 java.security.cert.PKIXCertPathValidatorResult
 java.security.cert.PKIXParameters
@@ -2308,6 +2298,7 @@
 javax.crypto.KeyAgreementSpi
 javax.crypto.MacSpi
 javax.crypto.SecretKey
+javax.crypto.spec.GCMParameterSpec
 javax.crypto.spec.IvParameterSpec
 javax.crypto.spec.SecretKeySpec
 javax.microedition.khronos.egl.EGL
diff --git a/services/Android.mk b/services/Android.mk
new file mode 100644
index 0000000..5260540
--- /dev/null
+++ b/services/Android.mk
@@ -0,0 +1,64 @@
+LOCAL_PATH:= $(call my-dir)
+
+# merge all required services into one jar
+# ============================================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services
+
+LOCAL_SRC_FILES := $(call all-java-files-under,java)
+
+# Uncomment to enable output of certain warnings (deprecated, unchecked)
+# LOCAL_JAVACFLAGS := -Xlint
+
+# Services that will be built as part of services.jar
+# These should map to directory names relative to this
+# Android.mk.
+services := \
+    core \
+    accessibility \
+    appwidget \
+    backup \
+    devicepolicy \
+    print \
+    usb
+
+# The convention is to name each service module 'services.$(module_name)'
+LOCAL_STATIC_JAVA_LIBRARIES := $(addprefix services.,$(services))
+
+include $(BUILD_JAVA_LIBRARY)
+
+# native library
+# =============================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES :=
+LOCAL_SHARED_LIBRARIES :=
+
+# include all the jni subdirs to collect their sources
+include $(wildcard $(LOCAL_PATH)/*/jni/Android.mk)
+
+LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES -DGL_GLEXT_PROTOTYPES
+
+ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
+    LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
+endif
+
+LOCAL_MODULE:= libandroid_servers
+
+include $(BUILD_SHARED_LIBRARY)
+
+# =============================================================
+
+ifeq (,$(ONE_SHOT_MAKEFILE))
+# A full make is happening, so make everything.
+include $(call all-makefiles-under,$(LOCAL_PATH))
+else
+# If we ran an mm[m] command, we still want to build the individual
+# services that we depend on. This differs from the above condition
+# by only including service makefiles and not any tests or other
+# modules.
+include $(patsubst %,$(LOCAL_PATH)/%/Android.mk,$(services))
+endif
+
diff --git a/services/accessibility/Android.mk b/services/accessibility/Android.mk
new file mode 100644
index 0000000..d98fc28
--- /dev/null
+++ b/services/accessibility/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.accessibility
+
+LOCAL_SRC_FILES += \
+      $(call all-java-files-under,java)
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/java/com/android/server/accessibility/AccessibilityInputFilter.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java
similarity index 100%
rename from services/java/com/android/server/accessibility/AccessibilityInputFilter.java
rename to services/accessibility/java/com/android/server/accessibility/AccessibilityInputFilter.java
diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
similarity index 100%
rename from services/java/com/android/server/accessibility/AccessibilityManagerService.java
rename to services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
diff --git a/services/java/com/android/server/accessibility/EventStreamTransformation.java b/services/accessibility/java/com/android/server/accessibility/EventStreamTransformation.java
similarity index 100%
rename from services/java/com/android/server/accessibility/EventStreamTransformation.java
rename to services/accessibility/java/com/android/server/accessibility/EventStreamTransformation.java
diff --git a/services/java/com/android/server/accessibility/GestureUtils.java b/services/accessibility/java/com/android/server/accessibility/GestureUtils.java
similarity index 100%
rename from services/java/com/android/server/accessibility/GestureUtils.java
rename to services/accessibility/java/com/android/server/accessibility/GestureUtils.java
diff --git a/services/java/com/android/server/accessibility/ScreenMagnifier.java b/services/accessibility/java/com/android/server/accessibility/ScreenMagnifier.java
similarity index 100%
rename from services/java/com/android/server/accessibility/ScreenMagnifier.java
rename to services/accessibility/java/com/android/server/accessibility/ScreenMagnifier.java
diff --git a/services/java/com/android/server/accessibility/TouchExplorer.java b/services/accessibility/java/com/android/server/accessibility/TouchExplorer.java
similarity index 100%
rename from services/java/com/android/server/accessibility/TouchExplorer.java
rename to services/accessibility/java/com/android/server/accessibility/TouchExplorer.java
diff --git a/services/appwidget/Android.mk b/services/appwidget/Android.mk
new file mode 100644
index 0000000..ca38f2f
--- /dev/null
+++ b/services/appwidget/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.appwidget
+
+LOCAL_SRC_FILES += \
+      $(call all-java-files-under,java)
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java
new file mode 100644
index 0000000..e208677
--- /dev/null
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetService.java
@@ -0,0 +1,384 @@
+/*
+ * Copyright (C) 2007 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.appwidget;
+
+import android.app.ActivityManager;
+import android.appwidget.AppWidgetProviderInfo;
+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.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.widget.RemoteViews;
+
+import com.android.internal.appwidget.IAppWidgetHost;
+import com.android.internal.appwidget.IAppWidgetService;
+import com.android.internal.os.BackgroundThread;
+import com.android.internal.util.IndentingPrintWriter;
+import com.android.server.SystemService;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Locale;
+
+
+/**
+ * SystemService that publishes an IAppWidgetService.
+ */
+public class AppWidgetService extends SystemService {
+
+    static final String TAG = "AppWidgetService";
+
+    final Context mContext;
+    final Handler mSaveStateHandler;
+
+    final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
+
+    public AppWidgetService(Context context) {
+        super(context);
+        mContext = context;
+
+        mSaveStateHandler = BackgroundThread.getHandler();
+
+        mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5);
+        AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0, mSaveStateHandler);
+        mAppWidgetServices.append(0, primary);
+    }
+
+    @Override
+    public void onStart() {
+        publishBinderService(Context.APPWIDGET_SERVICE, mServiceImpl);
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
+            mServiceImpl.systemRunning(isSafeMode());
+        }
+    }
+
+    private final AppWidgetServiceStub mServiceImpl = new AppWidgetServiceStub();
+
+    private class AppWidgetServiceStub extends IAppWidgetService.Stub {
+
+        private boolean mSafeMode;
+        private Locale mLocale;
+        private PackageManager mPackageManager;
+
+        public void systemRunning(boolean safeMode) {
+            mSafeMode = safeMode;
+
+            mAppWidgetServices.get(0).systemReady(safeMode);
+
+            // Register for the boot completed broadcast, so we can send the
+            // ENABLE broacasts. If we try to send them now, they time out,
+            // because the system isn't ready to handle them yet.
+            mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
+                    new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
+
+            // Register for configuration changes so we can update the names
+            // of the widgets when the locale changes.
+            mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
+                    new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null);
+
+            // Register for broadcasts about package install, etc., so we can
+            // update the provider list.
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_PACKAGE_ADDED);
+            filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+            filter.addDataScheme("package");
+            mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
+                    filter, null, null);
+            // Register for events related to sdcard installation.
+            IntentFilter sdFilter = new IntentFilter();
+            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
+            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+            mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
+                    sdFilter, null, null);
+
+            IntentFilter userFilter = new IntentFilter();
+            userFilter.addAction(Intent.ACTION_USER_REMOVED);
+            userFilter.addAction(Intent.ACTION_USER_STOPPING);
+            mContext.registerReceiver(new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) {
+                        onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+                                UserHandle.USER_NULL));
+                    } else if (Intent.ACTION_USER_STOPPING.equals(intent.getAction())) {
+                        onUserStopping(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+                                UserHandle.USER_NULL));
+                    }
+                }
+            }, userFilter);
+        }
+
+        @Override
+        public int allocateAppWidgetId(String packageName, int hostId, int userId)
+                throws RemoteException {
+            return getImplForUser(userId).allocateAppWidgetId(packageName, hostId);
+        }
+
+        @Override
+        public int[] getAppWidgetIdsForHost(int hostId, int userId) throws RemoteException {
+            return getImplForUser(userId).getAppWidgetIdsForHost(hostId);
+        }
+
+        @Override
+        public void deleteAppWidgetId(int appWidgetId, int userId) throws RemoteException {
+            getImplForUser(userId).deleteAppWidgetId(appWidgetId);
+        }
+
+        @Override
+        public void deleteHost(int hostId, int userId) throws RemoteException {
+            getImplForUser(userId).deleteHost(hostId);
+        }
+
+        @Override
+        public void deleteAllHosts(int userId) throws RemoteException {
+            getImplForUser(userId).deleteAllHosts();
+        }
+
+        @Override
+        public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options,
+                int userId) throws RemoteException {
+            getImplForUser(userId).bindAppWidgetId(appWidgetId, provider, options);
+        }
+
+        @Override
+        public boolean bindAppWidgetIdIfAllowed(
+                String packageName, int appWidgetId, ComponentName provider, Bundle options,
+                int userId) throws RemoteException {
+            return getImplForUser(userId).bindAppWidgetIdIfAllowed(
+                    packageName, appWidgetId, provider, options);
+        }
+
+        @Override
+        public boolean hasBindAppWidgetPermission(String packageName, int userId)
+                throws RemoteException {
+            return getImplForUser(userId).hasBindAppWidgetPermission(packageName);
+        }
+
+        @Override
+        public void setBindAppWidgetPermission(String packageName, boolean permission, int userId)
+                throws RemoteException {
+            getImplForUser(userId).setBindAppWidgetPermission(packageName, permission);
+        }
+
+        @Override
+        public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection,
+                int userId) throws RemoteException {
+            getImplForUser(userId).bindRemoteViewsService(appWidgetId, intent, connection);
+        }
+
+        @Override
+        public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
+                List<RemoteViews> updatedViews, int userId) throws RemoteException {
+            return getImplForUser(userId).startListening(host, packageName, hostId, updatedViews);
+        }
+
+        public void onUserRemoved(int userId) {
+            if (userId < 1) return;
+            synchronized (mAppWidgetServices) {
+                AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
+                mAppWidgetServices.remove(userId);
+
+                if (impl == null) {
+                    AppWidgetServiceImpl.getSettingsFile(userId).delete();
+                } else {
+                    impl.onUserRemoved();
+                }
+            }
+        }
+
+        public void onUserStopping(int userId) {
+            if (userId < 1) return;
+            synchronized (mAppWidgetServices) {
+                AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
+                if (impl != null) {
+                    mAppWidgetServices.remove(userId);
+                    impl.onUserStopping();
+                }
+            }
+        }
+
+        private void checkPermission(int userId) {
+            int realUserId = ActivityManager.handleIncomingUser(
+                    Binder.getCallingPid(),
+                    Binder.getCallingUid(),
+                    userId,
+                    false, /* allowAll */
+                    true, /* requireFull */
+                    this.getClass().getSimpleName(),
+                    this.getClass().getPackage().getName());
+        }
+
+        private AppWidgetServiceImpl getImplForUser(int userId) {
+            checkPermission(userId);
+            boolean sendInitial = false;
+            AppWidgetServiceImpl service;
+            synchronized (mAppWidgetServices) {
+                service = mAppWidgetServices.get(userId);
+                if (service == null) {
+                    Slog.i(TAG, "Unable to find AppWidgetServiceImpl for user " + userId
+                            + ", adding");
+                    // TODO: Verify that it's a valid user
+                    service = new AppWidgetServiceImpl(mContext, userId, mSaveStateHandler);
+                    service.systemReady(mSafeMode);
+                    // Assume that BOOT_COMPLETED was received, as this is a non-primary user.
+                    mAppWidgetServices.append(userId, service);
+                    sendInitial = true;
+                }
+            }
+            if (sendInitial) {
+                service.sendInitialBroadcasts();
+            }
+            return service;
+        }
+
+        @Override
+        public int[] getAppWidgetIds(ComponentName provider, int userId) throws RemoteException {
+            return getImplForUser(userId).getAppWidgetIds(provider);
+        }
+
+        @Override
+        public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId, int userId)
+                throws RemoteException {
+            return getImplForUser(userId).getAppWidgetInfo(appWidgetId);
+        }
+
+        @Override
+        public RemoteViews getAppWidgetViews(int appWidgetId, int userId) throws RemoteException {
+            return getImplForUser(userId).getAppWidgetViews(appWidgetId);
+        }
+
+        @Override
+        public void updateAppWidgetOptions(int appWidgetId, Bundle options, int userId) {
+            getImplForUser(userId).updateAppWidgetOptions(appWidgetId, options);
+        }
+
+        @Override
+        public Bundle getAppWidgetOptions(int appWidgetId, int userId) {
+            return getImplForUser(userId).getAppWidgetOptions(appWidgetId);
+        }
+
+        @Override
+        public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter, int userId)
+                throws RemoteException {
+            return getImplForUser(userId).getInstalledProviders(categoryFilter);
+        }
+
+        @Override
+        public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId, int userId)
+                throws RemoteException {
+            getImplForUser(userId).notifyAppWidgetViewDataChanged(
+                    appWidgetIds, viewId);
+        }
+
+        @Override
+        public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views, int userId)
+                throws RemoteException {
+            getImplForUser(userId).partiallyUpdateAppWidgetIds(
+                    appWidgetIds, views);
+        }
+
+        @Override
+        public void stopListening(int hostId, int userId) throws RemoteException {
+            getImplForUser(userId).stopListening(hostId);
+        }
+
+        @Override
+        public void unbindRemoteViewsService(int appWidgetId, Intent intent, int userId)
+                throws RemoteException {
+            getImplForUser(userId).unbindRemoteViewsService(
+                    appWidgetId, intent);
+        }
+
+        @Override
+        public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views, int userId)
+                throws RemoteException {
+            getImplForUser(userId).updateAppWidgetIds(appWidgetIds, views);
+        }
+
+        @Override
+        public void updateAppWidgetProvider(ComponentName provider, RemoteViews views, int userId)
+                throws RemoteException {
+            getImplForUser(userId).updateAppWidgetProvider(provider, views);
+        }
+
+        @Override
+        public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
+
+            // Dump the state of all the app widget providers
+            synchronized (mAppWidgetServices) {
+                IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
+                for (int i = 0; i < mAppWidgetServices.size(); i++) {
+                    pw.println("User: " + mAppWidgetServices.keyAt(i));
+                    ipw.increaseIndent();
+                    AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
+                    service.dump(fd, ipw, args);
+                    ipw.decreaseIndent();
+                }
+            }
+        }
+
+        BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+            public void onReceive(Context context, Intent intent) {
+                String action = intent.getAction();
+                // Slog.d(TAG, "received " + action);
+                if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
+                    int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
+                    if (userId >= 0) {
+                        getImplForUser(userId).sendInitialBroadcasts();
+                    } else {
+                        Slog.w(TAG, "Incorrect user handle supplied in " + intent);
+                    }
+                } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
+                    for (int i = 0; i < mAppWidgetServices.size(); i++) {
+                        AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
+                        service.onConfigurationChanged();
+                    }
+                } else {
+                    int sendingUser = getSendingUserId();
+                    if (sendingUser == UserHandle.USER_ALL) {
+                        for (int i = 0; i < mAppWidgetServices.size(); i++) {
+                            AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
+                            service.onBroadcastReceived(intent);
+                        }
+                    } else {
+                        AppWidgetServiceImpl service = mAppWidgetServices.get(sendingUser);
+                        if (service != null) {
+                            service.onBroadcastReceived(intent);
+                        }
+                    }
+                }
+            }
+        };
+    }
+}
diff --git a/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
new file mode 100644
index 0000000..98dead3
--- /dev/null
+++ b/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java
@@ -0,0 +1,2126 @@
+/*
+ * 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.server.appwidget;
+
+import android.app.AlarmManager;
+import android.app.AppGlobals;
+import android.app.PendingIntent;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProviderInfo;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.Intent.FilterComparison;
+import android.content.ServiceConnection;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.graphics.Point;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.util.AtomicFile;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.util.Pair;
+import android.util.Slog;
+import android.util.TypedValue;
+import android.util.Xml;
+import android.view.Display;
+import android.view.WindowManager;
+import android.widget.RemoteViews;
+
+import com.android.internal.appwidget.IAppWidgetHost;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.widget.IRemoteViewsAdapterConnection;
+import com.android.internal.widget.IRemoteViewsFactory;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+class AppWidgetServiceImpl {
+
+    private static final String KEYGUARD_HOST_PACKAGE = "com.android.keyguard";
+    private static final int KEYGUARD_HOST_ID = 0x4b455947;
+    private static final String TAG = "AppWidgetServiceImpl";
+    private static final String SETTINGS_FILENAME = "appwidgets.xml";
+    private static final int MIN_UPDATE_PERIOD = 30 * 60 * 1000; // 30 minutes
+    private static final int CURRENT_VERSION = 1; // Bump if the stored widgets need to be upgraded.
+
+    private static boolean DBG = false;
+
+    /*
+     * When identifying a Host or Provider based on the calling process, use the uid field. When
+     * identifying a Host or Provider based on a package manager broadcast, use the package given.
+     */
+
+    static class Provider {
+        int uid;
+        AppWidgetProviderInfo info;
+        ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
+        PendingIntent broadcast;
+        boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
+
+        int tag; // for use while saving state (the index)
+    }
+
+    static class Host {
+        int uid;
+        int hostId;
+        String packageName;
+        ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
+        IAppWidgetHost callbacks;
+        boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
+
+        int tag; // for use while saving state (the index)
+
+        boolean uidMatches(int callingUid) {
+            if (UserHandle.getAppId(callingUid) == Process.myUid()) {
+                // For a host that's in the system process, ignore the user id
+                return UserHandle.isSameApp(this.uid, callingUid);
+            } else {
+                return this.uid == callingUid;
+            }
+        }
+    }
+
+    static class AppWidgetId {
+        int appWidgetId;
+        Provider provider;
+        RemoteViews views;
+        Bundle options;
+        Host host;
+    }
+
+    /**
+     * Acts as a proxy between the ServiceConnection and the RemoteViewsAdapterConnection. This
+     * needs to be a static inner class since a reference to the ServiceConnection is held globally
+     * and may lead us to leak AppWidgetService instances (if there were more than one).
+     */
+    static class ServiceConnectionProxy implements ServiceConnection {
+        private final IBinder mConnectionCb;
+
+        ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) {
+            mConnectionCb = connectionCb;
+        }
+
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            final IRemoteViewsAdapterConnection cb = IRemoteViewsAdapterConnection.Stub
+                    .asInterface(mConnectionCb);
+            try {
+                cb.onServiceConnected(service);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+
+        public void onServiceDisconnected(ComponentName name) {
+            disconnect();
+        }
+
+        public void disconnect() {
+            final IRemoteViewsAdapterConnection cb = IRemoteViewsAdapterConnection.Stub
+                    .asInterface(mConnectionCb);
+            try {
+                cb.onServiceDisconnected();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    // Manages active connections to RemoteViewsServices
+    private final HashMap<Pair<Integer, FilterComparison>, ServiceConnection> mBoundRemoteViewsServices = new HashMap<Pair<Integer, FilterComparison>, ServiceConnection>();
+    // Manages persistent references to RemoteViewsServices from different App Widgets
+    private final HashMap<FilterComparison, HashSet<Integer>> mRemoteViewsServicesAppWidgets = new HashMap<FilterComparison, HashSet<Integer>>();
+
+    final Context mContext;
+    final IPackageManager mPm;
+    final AlarmManager mAlarmManager;
+    final ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
+    final int mUserId;
+    final boolean mHasFeature;
+
+    Locale mLocale;
+    int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
+    final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
+    final ArrayList<Host> mHosts = new ArrayList<Host>();
+    // set of package names
+    final HashSet<String> mPackagesWithBindWidgetPermission = new HashSet<String>();
+    boolean mSafeMode;
+    boolean mStateLoaded;
+    int mMaxWidgetBitmapMemory;
+
+    private final Handler mSaveStateHandler;
+
+    // These are for debugging only -- widgets are going missing in some rare instances
+    ArrayList<Provider> mDeletedProviders = new ArrayList<Provider>();
+    ArrayList<Host> mDeletedHosts = new ArrayList<Host>();
+
+    AppWidgetServiceImpl(Context context, int userId, Handler saveStateHandler) {
+        mContext = context;
+        mPm = AppGlobals.getPackageManager();
+        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
+        mUserId = userId;
+        mSaveStateHandler = saveStateHandler;
+        mHasFeature = context.getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_APP_WIDGETS);
+        computeMaximumWidgetBitmapMemory();
+    }
+
+    void computeMaximumWidgetBitmapMemory() {
+        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
+        Display display = wm.getDefaultDisplay();
+        Point size = new Point();
+        display.getRealSize(size);
+        // Cap memory usage at 1.5 times the size of the display
+        // 1.5 * 4 bytes/pixel * w * h ==> 6 * w * h
+        mMaxWidgetBitmapMemory = 6 * size.x * size.y;
+    }
+
+    public void systemReady(boolean safeMode) {
+        mSafeMode = safeMode;
+
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+        }
+    }
+
+    private void log(String msg) {
+        Slog.i(TAG, "u=" + mUserId + ": " + msg);
+    }
+
+    void onConfigurationChanged() {
+        if (DBG) log("Got onConfigurationChanged()");
+        Locale revised = Locale.getDefault();
+        if (revised == null || mLocale == null || !(revised.equals(mLocale))) {
+            mLocale = revised;
+
+            synchronized (mAppWidgetIds) {
+                ensureStateLoadedLocked();
+                // Note: updateProvidersForPackageLocked() may remove providers, so we must copy the
+                // list of installed providers and skip providers that we don't need to update.
+                // Also note that remove the provider does not clear the Provider component data.
+                ArrayList<Provider> installedProviders =
+                        new ArrayList<Provider>(mInstalledProviders);
+                HashSet<ComponentName> removedProviders = new HashSet<ComponentName>();
+                int N = installedProviders.size();
+                for (int i = N - 1; i >= 0; i--) {
+                    Provider p = installedProviders.get(i);
+                    ComponentName cn = p.info.provider;
+                    if (!removedProviders.contains(cn)) {
+                        updateProvidersForPackageLocked(cn.getPackageName(), removedProviders);
+                    }
+                }
+                saveStateAsync();
+            }
+        }
+    }
+
+    void onBroadcastReceived(Intent intent) {
+        if (DBG) log("onBroadcast " + intent);
+        final String action = intent.getAction();
+        boolean added = false;
+        boolean changed = false;
+        boolean providersModified = false;
+        String pkgList[] = null;
+        if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
+            pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+            added = true;
+        } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
+            pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+            added = false;
+        } else {
+            Uri uri = intent.getData();
+            if (uri == null) {
+                return;
+            }
+            String pkgName = uri.getSchemeSpecificPart();
+            if (pkgName == null) {
+                return;
+            }
+            pkgList = new String[] { pkgName };
+            added = Intent.ACTION_PACKAGE_ADDED.equals(action);
+            changed = Intent.ACTION_PACKAGE_CHANGED.equals(action);
+        }
+        if (pkgList == null || pkgList.length == 0) {
+            return;
+        }
+        if (added || changed) {
+            synchronized (mAppWidgetIds) {
+                ensureStateLoadedLocked();
+                Bundle extras = intent.getExtras();
+                if (changed
+                        || (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false))) {
+                    for (String pkgName : pkgList) {
+                        // The package was just upgraded
+                        providersModified |= updateProvidersForPackageLocked(pkgName, null);
+                    }
+                } else {
+                    // The package was just added
+                    for (String pkgName : pkgList) {
+                        providersModified |= addProvidersForPackageLocked(pkgName);
+                    }
+                }
+                saveStateAsync();
+            }
+        } else {
+            Bundle extras = intent.getExtras();
+            if (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false)) {
+                // The package is being updated. We'll receive a PACKAGE_ADDED shortly.
+            } else {
+                synchronized (mAppWidgetIds) {
+                    ensureStateLoadedLocked();
+                    for (String pkgName : pkgList) {
+                        providersModified |= removeProvidersForPackageLocked(pkgName);
+                        saveStateAsync();
+                    }
+                }
+            }
+        }
+
+        if (providersModified) {
+            // If the set of providers has been modified, notify each active AppWidgetHost
+            synchronized (mAppWidgetIds) {
+                ensureStateLoadedLocked();
+                notifyHostsForProvidersChangedLocked();
+            }
+        }
+    }
+
+    private void dumpProvider(Provider p, int index, PrintWriter pw) {
+        AppWidgetProviderInfo info = p.info;
+        pw.print("  ["); pw.print(index); pw.print("] provider ");
+                pw.print(info.provider.flattenToShortString());
+                pw.println(':');
+        pw.print("    min=("); pw.print(info.minWidth);
+                pw.print("x"); pw.print(info.minHeight);
+        pw.print(")   minResize=("); pw.print(info.minResizeWidth);
+                pw.print("x"); pw.print(info.minResizeHeight);
+                pw.print(") updatePeriodMillis=");
+                pw.print(info.updatePeriodMillis);
+                pw.print(" resizeMode=");
+                pw.print(info.resizeMode);
+                pw.print(info.widgetCategory);
+                pw.print(" autoAdvanceViewId=");
+                pw.print(info.autoAdvanceViewId);
+                pw.print(" initialLayout=#");
+                pw.print(Integer.toHexString(info.initialLayout));
+                pw.print(" uid="); pw.print(p.uid);
+                pw.print(" zombie="); pw.println(p.zombie);
+    }
+
+    private void dumpHost(Host host, int index, PrintWriter pw) {
+        pw.print("  ["); pw.print(index); pw.print("] hostId=");
+                pw.print(host.hostId); pw.print(' ');
+                pw.print(host.packageName); pw.print('/');
+        pw.print(host.uid); pw.println(':');
+        pw.print("    callbacks="); pw.println(host.callbacks);
+        pw.print("    instances.size="); pw.print(host.instances.size());
+                pw.print(" zombie="); pw.println(host.zombie);
+    }
+
+    private void dumpAppWidgetId(AppWidgetId id, int index, PrintWriter pw) {
+        pw.print("  ["); pw.print(index); pw.print("] id=");
+                pw.println(id.appWidgetId);
+        pw.print("    hostId=");
+                pw.print(id.host.hostId); pw.print(' ');
+                pw.print(id.host.packageName); pw.print('/');
+                pw.println(id.host.uid);
+        if (id.provider != null) {
+            pw.print("    provider=");
+                    pw.println(id.provider.info.provider.flattenToShortString());
+        }
+        if (id.host != null) {
+            pw.print("    host.callbacks="); pw.println(id.host.callbacks);
+        }
+        if (id.views != null) {
+            pw.print("    views="); pw.println(id.views);
+        }
+    }
+
+    void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        synchronized (mAppWidgetIds) {
+            int N = mInstalledProviders.size();
+            pw.println("Providers:");
+            for (int i=0; i<N; i++) {
+                dumpProvider(mInstalledProviders.get(i), i, pw);
+            }
+
+            N = mAppWidgetIds.size();
+            pw.println(" ");
+            pw.println("AppWidgetIds:");
+            for (int i=0; i<N; i++) {
+                dumpAppWidgetId(mAppWidgetIds.get(i), i, pw);
+            }
+
+            N = mHosts.size();
+            pw.println(" ");
+            pw.println("Hosts:");
+            for (int i=0; i<N; i++) {
+                dumpHost(mHosts.get(i), i, pw);
+            }
+
+            N = mDeletedProviders.size();
+            pw.println(" ");
+            pw.println("Deleted Providers:");
+            for (int i=0; i<N; i++) {
+                dumpProvider(mDeletedProviders.get(i), i, pw);
+            }
+
+            N = mDeletedHosts.size();
+            pw.println(" ");
+            pw.println("Deleted Hosts:");
+            for (int i=0; i<N; i++) {
+                dumpHost(mDeletedHosts.get(i), i, pw);
+            }
+        }
+    }
+
+    private void ensureStateLoadedLocked() {
+        if (!mStateLoaded) {
+            if (!mHasFeature) {
+                return;
+            }
+            loadAppWidgetListLocked();
+            loadStateLocked();
+            mStateLoaded = true;
+        }
+    }
+
+    public int allocateAppWidgetId(String packageName, int hostId) {
+        int callingUid = enforceSystemOrCallingUid(packageName);
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return -1;
+            }
+            ensureStateLoadedLocked();
+            int appWidgetId = mNextAppWidgetId++;
+
+            Host host = lookupOrAddHostLocked(callingUid, packageName, hostId);
+
+            AppWidgetId id = new AppWidgetId();
+            id.appWidgetId = appWidgetId;
+            id.host = host;
+
+            host.instances.add(id);
+            mAppWidgetIds.add(id);
+
+            saveStateAsync();
+            if (DBG) log("Allocating AppWidgetId for " + packageName + " host=" + hostId
+                    + " id=" + appWidgetId);
+            return appWidgetId;
+        }
+    }
+
+    public void deleteAppWidgetId(int appWidgetId) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            ensureStateLoadedLocked();
+            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+            if (id != null) {
+                deleteAppWidgetLocked(id);
+                saveStateAsync();
+            }
+        }
+    }
+
+    public void deleteHost(int hostId) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            ensureStateLoadedLocked();
+            int callingUid = Binder.getCallingUid();
+            Host host = lookupHostLocked(callingUid, hostId);
+            if (host != null) {
+                deleteHostLocked(host);
+                saveStateAsync();
+            }
+        }
+    }
+
+    public void deleteAllHosts() {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            ensureStateLoadedLocked();
+            int callingUid = Binder.getCallingUid();
+            final int N = mHosts.size();
+            boolean changed = false;
+            for (int i = N - 1; i >= 0; i--) {
+                Host host = mHosts.get(i);
+                if (host.uidMatches(callingUid)) {
+                    deleteHostLocked(host);
+                    changed = true;
+                }
+            }
+            if (changed) {
+                saveStateAsync();
+            }
+        }
+    }
+
+    void deleteHostLocked(Host host) {
+        final int N = host.instances.size();
+        for (int i = N - 1; i >= 0; i--) {
+            AppWidgetId id = host.instances.get(i);
+            deleteAppWidgetLocked(id);
+        }
+        host.instances.clear();
+        mHosts.remove(host);
+        mDeletedHosts.add(host);
+        // it's gone or going away, abruptly drop the callback connection
+        host.callbacks = null;
+    }
+
+    void deleteAppWidgetLocked(AppWidgetId id) {
+        // We first unbind all services that are bound to this id
+        unbindAppWidgetRemoteViewsServicesLocked(id);
+
+        Host host = id.host;
+        host.instances.remove(id);
+        pruneHostLocked(host);
+
+        mAppWidgetIds.remove(id);
+
+        Provider p = id.provider;
+        if (p != null) {
+            p.instances.remove(id);
+            if (!p.zombie) {
+                // send the broacast saying that this appWidgetId has been deleted
+                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
+                intent.setComponent(p.info.provider);
+                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
+                mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
+                if (p.instances.size() == 0) {
+                    // cancel the future updates
+                    cancelBroadcasts(p);
+
+                    // send the broacast saying that the provider is not in use any more
+                    intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DISABLED);
+                    intent.setComponent(p.info.provider);
+                    mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
+                }
+            }
+        }
+    }
+
+    void cancelBroadcasts(Provider p) {
+        if (DBG) log("cancelBroadcasts for " + p);
+        if (p.broadcast != null) {
+            mAlarmManager.cancel(p.broadcast);
+            long token = Binder.clearCallingIdentity();
+            try {
+                p.broadcast.cancel();
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+            p.broadcast = null;
+        }
+    }
+
+    private void bindAppWidgetIdImpl(int appWidgetId, ComponentName provider, Bundle options) {
+        if (DBG) log("bindAppWidgetIdImpl appwid=" + appWidgetId
+                + " provider=" + provider);
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (mAppWidgetIds) {
+                if (!mHasFeature) {
+                    return;
+                }
+                options = cloneIfLocalBinder(options);
+                ensureStateLoadedLocked();
+                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+                if (id == null) {
+                    throw new IllegalArgumentException("bad appWidgetId");
+                }
+                if (id.provider != null) {
+                    throw new IllegalArgumentException("appWidgetId " + appWidgetId
+                            + " already bound to " + id.provider.info.provider);
+                }
+                Provider p = lookupProviderLocked(provider);
+                if (p == null) {
+                    throw new IllegalArgumentException("not a appwidget provider: " + provider);
+                }
+                if (p.zombie) {
+                    throw new IllegalArgumentException("can't bind to a 3rd party provider in"
+                            + " safe mode: " + provider);
+                }
+
+                id.provider = p;
+                if (options == null) {
+                    options = new Bundle();
+                }
+                id.options = options;
+
+                // We need to provide a default value for the widget category if it is not specified
+                if (!options.containsKey(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)) {
+                    options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
+                            AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
+                }
+
+                p.instances.add(id);
+                int instancesSize = p.instances.size();
+                if (instancesSize == 1) {
+                    // tell the provider that it's ready
+                    sendEnableIntentLocked(p);
+                }
+
+                // send an update now -- We need this update now, and just for this appWidgetId.
+                // It's less critical when the next one happens, so when we schedule the next one,
+                // we add updatePeriodMillis to its start time. That time will have some slop,
+                // but that's okay.
+                sendUpdateIntentLocked(p, new int[] { appWidgetId });
+
+                // schedule the future updates
+                registerForBroadcastsLocked(p, getAppWidgetIds(p));
+                saveStateAsync();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET,
+            "bindAppWidgetId appWidgetId=" + appWidgetId + " provider=" + provider);
+        bindAppWidgetIdImpl(appWidgetId, provider, options);
+    }
+
+    public boolean bindAppWidgetIdIfAllowed(
+            String packageName, int appWidgetId, ComponentName provider, Bundle options) {
+        if (!mHasFeature) {
+            return false;
+        }
+        try {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET, null);
+        } catch (SecurityException se) {
+            if (!callerHasBindAppWidgetPermission(packageName)) {
+                return false;
+            }
+        }
+        bindAppWidgetIdImpl(appWidgetId, provider, options);
+        return true;
+    }
+
+    private boolean callerHasBindAppWidgetPermission(String packageName) {
+        int callingUid = Binder.getCallingUid();
+        try {
+            if (!UserHandle.isSameApp(callingUid, getUidForPackage(packageName))) {
+                return false;
+            }
+        } catch (Exception e) {
+            return false;
+        }
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            return mPackagesWithBindWidgetPermission.contains(packageName);
+        }
+    }
+
+    public boolean hasBindAppWidgetPermission(String packageName) {
+        if (!mHasFeature) {
+            return false;
+        }
+        mContext.enforceCallingPermission(
+                android.Manifest.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS,
+                "hasBindAppWidgetPermission packageName=" + packageName);
+
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            return mPackagesWithBindWidgetPermission.contains(packageName);
+        }
+    }
+
+    public void setBindAppWidgetPermission(String packageName, boolean permission) {
+        if (!mHasFeature) {
+            return;
+        }
+        mContext.enforceCallingPermission(
+                android.Manifest.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS,
+                "setBindAppWidgetPermission packageName=" + packageName);
+
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            if (permission) {
+                mPackagesWithBindWidgetPermission.add(packageName);
+            } else {
+                mPackagesWithBindWidgetPermission.remove(packageName);
+            }
+            saveStateAsync();
+        }
+    }
+
+    // Binds to a specific RemoteViewsService
+    public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            ensureStateLoadedLocked();
+            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+            if (id == null) {
+                throw new IllegalArgumentException("bad appWidgetId");
+            }
+            final ComponentName componentName = intent.getComponent();
+            try {
+                final ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(componentName,
+                        PackageManager.GET_PERMISSIONS, mUserId);
+                if (!android.Manifest.permission.BIND_REMOTEVIEWS.equals(si.permission)) {
+                    throw new SecurityException("Selected service does not require "
+                            + android.Manifest.permission.BIND_REMOTEVIEWS + ": " + componentName);
+                }
+            } catch (RemoteException e) {
+                throw new IllegalArgumentException("Unknown component " + componentName);
+            }
+
+            // If there is already a connection made for this service intent, then disconnect from
+            // that first. (This does not allow multiple connections to the same service under
+            // the same key)
+            ServiceConnectionProxy conn = null;
+            FilterComparison fc = new FilterComparison(intent);
+            Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, fc);
+            if (mBoundRemoteViewsServices.containsKey(key)) {
+                conn = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
+                conn.disconnect();
+                mContext.unbindService(conn);
+                mBoundRemoteViewsServices.remove(key);
+            }
+
+            int userId = UserHandle.getUserId(id.provider.uid);
+            if (userId != mUserId) {
+                Slog.w(TAG, "AppWidgetServiceImpl of user " + mUserId
+                        + " binding to provider on user " + userId);
+            }
+            // Bind to the RemoteViewsService (which will trigger a callback to the
+            // RemoteViewsAdapter.onServiceConnected())
+            final long token = Binder.clearCallingIdentity();
+            try {
+                conn = new ServiceConnectionProxy(key, connection);
+                mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
+                        new UserHandle(userId));
+                mBoundRemoteViewsServices.put(key, conn);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+
+            // Add it to the mapping of RemoteViewsService to appWidgetIds so that we can determine
+            // when we can call back to the RemoteViewsService later to destroy associated
+            // factories.
+            incrementAppWidgetServiceRefCount(appWidgetId, fc);
+        }
+    }
+
+    // Unbinds from a specific RemoteViewsService
+    public void unbindRemoteViewsService(int appWidgetId, Intent intent) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            ensureStateLoadedLocked();
+            // Unbind from the RemoteViewsService (which will trigger a callback to the bound
+            // RemoteViewsAdapter)
+            Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, new FilterComparison(
+                    intent));
+            if (mBoundRemoteViewsServices.containsKey(key)) {
+                // We don't need to use the appWidgetId until after we are sure there is something
+                // to unbind. Note that this may mask certain issues with apps calling unbind()
+                // more than necessary.
+                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+                if (id == null) {
+                    throw new IllegalArgumentException("bad appWidgetId");
+                }
+
+                ServiceConnectionProxy conn = (ServiceConnectionProxy) mBoundRemoteViewsServices
+                        .get(key);
+                conn.disconnect();
+                mContext.unbindService(conn);
+                mBoundRemoteViewsServices.remove(key);
+            }
+        }
+    }
+
+    // Unbinds from a RemoteViewsService when we delete an app widget
+    private void unbindAppWidgetRemoteViewsServicesLocked(AppWidgetId id) {
+        int appWidgetId = id.appWidgetId;
+        // Unbind all connections to Services bound to this AppWidgetId
+        Iterator<Pair<Integer, Intent.FilterComparison>> it = mBoundRemoteViewsServices.keySet()
+                .iterator();
+        while (it.hasNext()) {
+            final Pair<Integer, Intent.FilterComparison> key = it.next();
+            if (key.first.intValue() == appWidgetId) {
+                final ServiceConnectionProxy conn = (ServiceConnectionProxy) mBoundRemoteViewsServices
+                        .get(key);
+                conn.disconnect();
+                mContext.unbindService(conn);
+                it.remove();
+            }
+        }
+
+        // Check if we need to destroy any services (if no other app widgets are
+        // referencing the same service)
+        decrementAppWidgetServiceRefCount(id);
+    }
+
+    // Destroys the cached factory on the RemoteViewsService's side related to the specified intent
+    private void destroyRemoteViewsService(final Intent intent, AppWidgetId id) {
+        final ServiceConnection conn = new ServiceConnection() {
+            @Override
+            public void onServiceConnected(ComponentName name, IBinder service) {
+                final IRemoteViewsFactory cb = IRemoteViewsFactory.Stub.asInterface(service);
+                try {
+                    cb.onDestroy(intent);
+                } catch (RemoteException e) {
+                    e.printStackTrace();
+                } catch (RuntimeException e) {
+                    e.printStackTrace();
+                }
+                mContext.unbindService(this);
+            }
+
+            @Override
+            public void onServiceDisconnected(android.content.ComponentName name) {
+                // Do nothing
+            }
+        };
+
+        int userId = UserHandle.getUserId(id.provider.uid);
+        // Bind to the service and remove the static intent->factory mapping in the
+        // RemoteViewsService.
+        final long token = Binder.clearCallingIdentity();
+        try {
+            mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
+                    new UserHandle(userId));
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Adds to the ref-count for a given RemoteViewsService intent
+    private void incrementAppWidgetServiceRefCount(int appWidgetId, FilterComparison fc) {
+        HashSet<Integer> appWidgetIds = null;
+        if (mRemoteViewsServicesAppWidgets.containsKey(fc)) {
+            appWidgetIds = mRemoteViewsServicesAppWidgets.get(fc);
+        } else {
+            appWidgetIds = new HashSet<Integer>();
+            mRemoteViewsServicesAppWidgets.put(fc, appWidgetIds);
+        }
+        appWidgetIds.add(appWidgetId);
+    }
+
+    // Subtracts from the ref-count for a given RemoteViewsService intent, prompting a delete if
+    // the ref-count reaches zero.
+    private void decrementAppWidgetServiceRefCount(AppWidgetId id) {
+        Iterator<FilterComparison> it = mRemoteViewsServicesAppWidgets.keySet().iterator();
+        while (it.hasNext()) {
+            final FilterComparison key = it.next();
+            final HashSet<Integer> ids = mRemoteViewsServicesAppWidgets.get(key);
+            if (ids.remove(id.appWidgetId)) {
+                // If we have removed the last app widget referencing this service, then we
+                // should destroy it and remove it from this set
+                if (ids.isEmpty()) {
+                    destroyRemoteViewsService(key.getIntent(), id);
+                    it.remove();
+                }
+            }
+        }
+    }
+
+    public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return null;
+            }
+            ensureStateLoadedLocked();
+            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+            if (id != null && id.provider != null && !id.provider.zombie) {
+                return cloneIfLocalBinder(id.provider.info);
+            }
+            return null;
+        }
+    }
+
+    public RemoteViews getAppWidgetViews(int appWidgetId) {
+        if (DBG) log("getAppWidgetViews id=" + appWidgetId);
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return null;
+            }
+            ensureStateLoadedLocked();
+            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+            if (id != null) {
+                return cloneIfLocalBinder(id.views);
+            }
+            if (DBG) log("   couldn't find appwidgetid");
+            return null;
+        }
+    }
+
+    public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return new ArrayList<AppWidgetProviderInfo>(0);
+            }
+            ensureStateLoadedLocked();
+            final int N = mInstalledProviders.size();
+            ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>(N);
+            for (int i = 0; i < N; i++) {
+                Provider p = mInstalledProviders.get(i);
+                if (!p.zombie && (p.info.widgetCategory & categoryFilter) != 0) {
+                    result.add(cloneIfLocalBinder(p.info));
+                }
+            }
+            return result;
+        }
+    }
+
+    public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
+        if (!mHasFeature) {
+            return;
+        }
+        if (appWidgetIds == null) {
+            return;
+        }
+        if (DBG) log("updateAppWidgetIds views: " + views);
+        int bitmapMemoryUsage = 0;
+        if (views != null) {
+            bitmapMemoryUsage = views.estimateMemoryUsage();
+        }
+        if (bitmapMemoryUsage > mMaxWidgetBitmapMemory) {
+            throw new IllegalArgumentException("RemoteViews for widget update exceeds maximum" +
+                    " bitmap memory usage (used: " + bitmapMemoryUsage + ", max: " +
+                    mMaxWidgetBitmapMemory + ") The total memory cannot exceed that required to" +
+                    " fill the device's screen once.");
+        }
+
+        if (appWidgetIds.length == 0) {
+            return;
+        }
+        final int N = appWidgetIds.length;
+
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            for (int i = 0; i < N; i++) {
+                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
+                updateAppWidgetInstanceLocked(id, views);
+            }
+        }
+    }
+
+    private void saveStateAsync() {
+        mSaveStateHandler.post(mSaveStateRunnable);
+    }
+
+    private final Runnable mSaveStateRunnable = new Runnable() {
+        @Override
+        public void run() {
+            synchronized (mAppWidgetIds) {
+                ensureStateLoadedLocked();
+                saveStateLocked();
+            }
+        }
+    };
+
+    public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            options = cloneIfLocalBinder(options);
+            ensureStateLoadedLocked();
+            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+
+            if (id == null) {
+                return;
+            }
+
+            Provider p = id.provider;
+            // Merge the options
+            id.options.putAll(options);
+
+            // send the broacast saying that this appWidgetId has been deleted
+            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED);
+            intent.setComponent(p.info.provider);
+            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
+            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, id.options);
+            mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
+            saveStateAsync();
+        }
+    }
+
+    public Bundle getAppWidgetOptions(int appWidgetId) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return Bundle.EMPTY;
+            }
+            ensureStateLoadedLocked();
+            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
+            if (id != null && id.options != null) {
+                return cloneIfLocalBinder(id.options);
+            } else {
+                return Bundle.EMPTY;
+            }
+        }
+    }
+
+    public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
+        if (!mHasFeature) {
+            return;
+        }
+        if (appWidgetIds == null) {
+            return;
+        }
+        if (appWidgetIds.length == 0) {
+            return;
+        }
+        final int N = appWidgetIds.length;
+
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            for (int i = 0; i < N; i++) {
+                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
+                if (id == null) {
+                    Slog.w(TAG, "widget id " + appWidgetIds[i] + " not found!");
+                } else if (id.views != null) {
+                    // Only trigger a partial update for a widget if it has received a full update
+                    updateAppWidgetInstanceLocked(id, views, true);
+                }
+            }
+        }
+    }
+
+    public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId) {
+        if (!mHasFeature) {
+            return;
+        }
+        if (appWidgetIds == null) {
+            return;
+        }
+        if (appWidgetIds.length == 0) {
+            return;
+        }
+        final int N = appWidgetIds.length;
+
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            for (int i = 0; i < N; i++) {
+                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
+                notifyAppWidgetViewDataChangedInstanceLocked(id, viewId);
+            }
+        }
+    }
+
+    public void updateAppWidgetProvider(ComponentName provider, RemoteViews views) {
+        if (!mHasFeature) {
+            return;
+        }
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            Provider p = lookupProviderLocked(provider);
+            if (p == null) {
+                Slog.w(TAG, "updateAppWidgetProvider: provider doesn't exist: " + provider);
+                return;
+            }
+            ArrayList<AppWidgetId> instances = p.instances;
+            final int callingUid = Binder.getCallingUid();
+            final int N = instances.size();
+            for (int i = 0; i < N; i++) {
+                AppWidgetId id = instances.get(i);
+                if (canAccessAppWidgetId(id, callingUid)) {
+                    updateAppWidgetInstanceLocked(id, views);
+                }
+            }
+        }
+    }
+
+    void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views) {
+        updateAppWidgetInstanceLocked(id, views, false);
+    }
+
+    void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views, boolean isPartialUpdate) {
+        // allow for stale appWidgetIds and other badness
+        // lookup also checks that the calling process can access the appWidgetId
+        // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
+        if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
+
+            if (!isPartialUpdate) {
+                // For a full update we replace the RemoteViews completely.
+                id.views = views;
+            } else {
+                // For a partial update, we merge the new RemoteViews with the old.
+                id.views.mergeRemoteViews(views);
+            }
+
+            // is anyone listening?
+            if (id.host.callbacks != null) {
+                try {
+                    // the lock is held, but this is a oneway call
+                    id.host.callbacks.updateAppWidget(id.appWidgetId, views, mUserId);
+                } catch (RemoteException e) {
+                    // It failed; remove the callback. No need to prune because
+                    // we know that this host is still referenced by this instance.
+                    id.host.callbacks = null;
+                }
+            }
+        }
+    }
+
+    void notifyAppWidgetViewDataChangedInstanceLocked(AppWidgetId id, int viewId) {
+        // allow for stale appWidgetIds and other badness
+        // lookup also checks that the calling process can access the appWidgetId
+        // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
+        if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
+            // is anyone listening?
+            if (id.host.callbacks != null) {
+                try {
+                    // the lock is held, but this is a oneway call
+                    id.host.callbacks.viewDataChanged(id.appWidgetId, viewId, mUserId);
+                } catch (RemoteException e) {
+                    // It failed; remove the callback. No need to prune because
+                    // we know that this host is still referenced by this instance.
+                    id.host.callbacks = null;
+                }
+            }
+
+            // If the host is unavailable, then we call the associated
+            // RemoteViewsFactory.onDataSetChanged() directly
+            if (id.host.callbacks == null) {
+                Set<FilterComparison> keys = mRemoteViewsServicesAppWidgets.keySet();
+                for (FilterComparison key : keys) {
+                    if (mRemoteViewsServicesAppWidgets.get(key).contains(id.appWidgetId)) {
+                        Intent intent = key.getIntent();
+
+                        final ServiceConnection conn = new ServiceConnection() {
+                            @Override
+                            public void onServiceConnected(ComponentName name, IBinder service) {
+                                IRemoteViewsFactory cb = IRemoteViewsFactory.Stub
+                                        .asInterface(service);
+                                try {
+                                    cb.onDataSetChangedAsync();
+                                } catch (RemoteException e) {
+                                    e.printStackTrace();
+                                } catch (RuntimeException e) {
+                                    e.printStackTrace();
+                                }
+                                mContext.unbindService(this);
+                            }
+
+                            @Override
+                            public void onServiceDisconnected(android.content.ComponentName name) {
+                                // Do nothing
+                            }
+                        };
+
+                        int userId = UserHandle.getUserId(id.provider.uid);
+                        // Bind to the service and call onDataSetChanged()
+                        final long token = Binder.clearCallingIdentity();
+                        try {
+                            mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
+                                    new UserHandle(userId));
+                        } finally {
+                            Binder.restoreCallingIdentity(token);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private boolean isLocalBinder() {
+        return Process.myPid() == Binder.getCallingPid();
+    }
+
+    private RemoteViews cloneIfLocalBinder(RemoteViews rv) {
+        if (isLocalBinder() && rv != null) {
+            return rv.clone();
+        }
+        return rv;
+    }
+
+    private AppWidgetProviderInfo cloneIfLocalBinder(AppWidgetProviderInfo info) {
+        if (isLocalBinder() && info != null) {
+            return info.clone();
+        }
+        return info;
+    }
+
+    private Bundle cloneIfLocalBinder(Bundle bundle) {
+        // Note: this is only a shallow copy. For now this will be fine, but it could be problematic
+        // if we start adding objects to the options. Further, it would only be an issue if keyguard
+        // used such options.
+        if (isLocalBinder() && bundle != null) {
+            return (Bundle) bundle.clone();
+        }
+        return bundle;
+    }
+
+    public int[] startListening(IAppWidgetHost callbacks, String packageName, int hostId,
+            List<RemoteViews> updatedViews) {
+        if (!mHasFeature) {
+            return new int[0];
+        }
+        int callingUid = enforceCallingUid(packageName);
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            Host host = lookupOrAddHostLocked(callingUid, packageName, hostId);
+            host.callbacks = callbacks;
+
+            updatedViews.clear();
+
+            ArrayList<AppWidgetId> instances = host.instances;
+            int N = instances.size();
+            int[] updatedIds = new int[N];
+            for (int i = 0; i < N; i++) {
+                AppWidgetId id = instances.get(i);
+                updatedIds[i] = id.appWidgetId;
+                updatedViews.add(cloneIfLocalBinder(id.views));
+            }
+            return updatedIds;
+        }
+    }
+
+    public void stopListening(int hostId) {
+        synchronized (mAppWidgetIds) {
+            if (!mHasFeature) {
+                return;
+            }
+            ensureStateLoadedLocked();
+            Host host = lookupHostLocked(Binder.getCallingUid(), hostId);
+            if (host != null) {
+                host.callbacks = null;
+                pruneHostLocked(host);
+            }
+        }
+    }
+
+    boolean canAccessAppWidgetId(AppWidgetId id, int callingUid) {
+        if (id.host.uidMatches(callingUid)) {
+            // Apps hosting the AppWidget have access to it.
+            return true;
+        }
+        if (id.provider != null && id.provider.uid == callingUid) {
+            // Apps providing the AppWidget have access to it (if the appWidgetId has been bound)
+            return true;
+        }
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET) == PackageManager.PERMISSION_GRANTED) {
+            // Apps that can bind have access to all appWidgetIds.
+            return true;
+        }
+        // Nobody else can access it.
+        return false;
+    }
+
+    AppWidgetId lookupAppWidgetIdLocked(int appWidgetId) {
+        int callingUid = Binder.getCallingUid();
+        final int N = mAppWidgetIds.size();
+        for (int i = 0; i < N; i++) {
+            AppWidgetId id = mAppWidgetIds.get(i);
+            if (id.appWidgetId == appWidgetId && canAccessAppWidgetId(id, callingUid)) {
+                return id;
+            }
+        }
+        return null;
+    }
+
+    Provider lookupProviderLocked(ComponentName provider) {
+        final int N = mInstalledProviders.size();
+        for (int i = 0; i < N; i++) {
+            Provider p = mInstalledProviders.get(i);
+            if (p.info.provider.equals(provider)) {
+                return p;
+            }
+        }
+        return null;
+    }
+
+    Host lookupHostLocked(int uid, int hostId) {
+        final int N = mHosts.size();
+        for (int i = 0; i < N; i++) {
+            Host h = mHosts.get(i);
+            if (h.uidMatches(uid) && h.hostId == hostId) {
+                return h;
+            }
+        }
+        return null;
+    }
+
+    Host lookupOrAddHostLocked(int uid, String packageName, int hostId) {
+        final int N = mHosts.size();
+        for (int i = 0; i < N; i++) {
+            Host h = mHosts.get(i);
+            if (h.hostId == hostId && h.packageName.equals(packageName)) {
+                return h;
+            }
+        }
+        Host host = new Host();
+        host.packageName = packageName;
+        host.uid = uid;
+        host.hostId = hostId;
+        mHosts.add(host);
+        return host;
+    }
+
+    void pruneHostLocked(Host host) {
+        if (host.instances.size() == 0 && host.callbacks == null) {
+            mHosts.remove(host);
+        }
+    }
+
+    void loadAppWidgetListLocked() {
+        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+        try {
+            List<ResolveInfo> broadcastReceivers = mPm.queryIntentReceivers(intent,
+                    intent.resolveTypeIfNeeded(mContext.getContentResolver()),
+                    PackageManager.GET_META_DATA, mUserId);
+
+            final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
+            for (int i = 0; i < N; i++) {
+                ResolveInfo ri = broadcastReceivers.get(i);
+                addProviderLocked(ri);
+            }
+        } catch (RemoteException re) {
+            // Shouldn't happen, local call
+        }
+    }
+
+    boolean addProviderLocked(ResolveInfo ri) {
+        if ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
+            return false;
+        }
+        if (!ri.activityInfo.isEnabled()) {
+            return false;
+        }
+        Provider p = parseProviderInfoXml(new ComponentName(ri.activityInfo.packageName,
+                ri.activityInfo.name), ri);
+        if (p != null) {
+            mInstalledProviders.add(p);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    void removeProviderLocked(int index, Provider p) {
+        int N = p.instances.size();
+        for (int i = 0; i < N; i++) {
+            AppWidgetId id = p.instances.get(i);
+            // Call back with empty RemoteViews
+            updateAppWidgetInstanceLocked(id, null);
+            // Stop telling the host about updates for this from now on
+            cancelBroadcasts(p);
+            // clear out references to this appWidgetId
+            id.host.instances.remove(id);
+            mAppWidgetIds.remove(id);
+            id.provider = null;
+            pruneHostLocked(id.host);
+            id.host = null;
+        }
+        p.instances.clear();
+        mInstalledProviders.remove(index);
+        mDeletedProviders.add(p);
+        // no need to send the DISABLE broadcast, since the receiver is gone anyway
+        cancelBroadcasts(p);
+    }
+
+    void sendEnableIntentLocked(Provider p) {
+        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_ENABLED);
+        intent.setComponent(p.info.provider);
+        mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
+    }
+
+    void sendUpdateIntentLocked(Provider p, int[] appWidgetIds) {
+        if (appWidgetIds != null && appWidgetIds.length > 0) {
+            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
+            intent.setComponent(p.info.provider);
+            mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
+        }
+    }
+
+    void registerForBroadcastsLocked(Provider p, int[] appWidgetIds) {
+        if (p.info.updatePeriodMillis > 0) {
+            // if this is the first instance, set the alarm. otherwise,
+            // rely on the fact that we've already set it and that
+            // PendingIntent.getBroadcast will update the extras.
+            boolean alreadyRegistered = p.broadcast != null;
+            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
+            intent.setComponent(p.info.provider);
+            long token = Binder.clearCallingIdentity();
+            try {
+                p.broadcast = PendingIntent.getBroadcastAsUser(mContext, 1, intent,
+                        PendingIntent.FLAG_UPDATE_CURRENT, new UserHandle(mUserId));
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+            if (!alreadyRegistered) {
+                long period = p.info.updatePeriodMillis;
+                if (period < MIN_UPDATE_PERIOD) {
+                    period = MIN_UPDATE_PERIOD;
+                }
+                mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock
+                        .elapsedRealtime()
+                        + period, period, p.broadcast);
+            }
+        }
+    }
+
+    static int[] getAppWidgetIds(Provider p) {
+        int instancesSize = p.instances.size();
+        int appWidgetIds[] = new int[instancesSize];
+        for (int i = 0; i < instancesSize; i++) {
+            appWidgetIds[i] = p.instances.get(i).appWidgetId;
+        }
+        return appWidgetIds;
+    }
+
+    public int[] getAppWidgetIds(ComponentName provider) {
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            Provider p = lookupProviderLocked(provider);
+            if (p != null && Binder.getCallingUid() == p.uid) {
+                return getAppWidgetIds(p);
+            } else {
+                return new int[0];
+            }
+        }
+    }
+
+    static int[] getAppWidgetIds(Host h) {
+        int instancesSize = h.instances.size();
+        int appWidgetIds[] = new int[instancesSize];
+        for (int i = 0; i < instancesSize; i++) {
+            appWidgetIds[i] = h.instances.get(i).appWidgetId;
+        }
+        return appWidgetIds;
+    }
+
+    public int[] getAppWidgetIdsForHost(int hostId) {
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            int callingUid = Binder.getCallingUid();
+            Host host = lookupHostLocked(callingUid, hostId);
+            if (host != null) {
+                return getAppWidgetIds(host);
+            } else {
+                return new int[0];
+            }
+        }
+    }
+
+    private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) {
+        Provider p = null;
+
+        ActivityInfo activityInfo = ri.activityInfo;
+        XmlResourceParser parser = null;
+        try {
+            parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(),
+                    AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
+            if (parser == null) {
+                Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER
+                        + " meta-data for " + "AppWidget provider '" + component + '\'');
+                return null;
+            }
+
+            AttributeSet attrs = Xml.asAttributeSet(parser);
+
+            int type;
+            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                    && type != XmlPullParser.START_TAG) {
+                // drain whitespace, comments, etc.
+            }
+
+            String nodeName = parser.getName();
+            if (!"appwidget-provider".equals(nodeName)) {
+                Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for"
+                        + " AppWidget provider '" + component + '\'');
+                return null;
+            }
+
+            p = new Provider();
+            AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo();
+            info.provider = component;
+            p.uid = activityInfo.applicationInfo.uid;
+
+            Resources res = mContext.getPackageManager()
+                    .getResourcesForApplicationAsUser(activityInfo.packageName, mUserId);
+
+            TypedArray sa = res.obtainAttributes(attrs,
+                    com.android.internal.R.styleable.AppWidgetProviderInfo);
+
+            // These dimensions has to be resolved in the application's context.
+            // We simply send back the raw complex data, which will be
+            // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
+            TypedValue value = sa
+                    .peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
+            info.minWidth = value != null ? value.data : 0;
+            value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
+            info.minHeight = value != null ? value.data : 0;
+            value = sa.peekValue(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
+            info.minResizeWidth = value != null ? value.data : info.minWidth;
+            value = sa.peekValue(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
+            info.minResizeHeight = value != null ? value.data : info.minHeight;
+            info.updatePeriodMillis = sa.getInt(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
+            info.initialLayout = sa.getResourceId(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
+            info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.
+                    AppWidgetProviderInfo_initialKeyguardLayout, 0);
+            String className = sa
+                    .getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
+            if (className != null) {
+                info.configure = new ComponentName(component.getPackageName(), className);
+            }
+            info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
+            info.icon = ri.getIconResource();
+            info.previewImage = sa.getResourceId(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
+            info.autoAdvanceViewId = sa.getResourceId(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
+            info.resizeMode = sa.getInt(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode,
+                    AppWidgetProviderInfo.RESIZE_NONE);
+            info.widgetCategory = sa.getInt(
+                    com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory,
+                    AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
+
+            sa.recycle();
+        } catch (Exception e) {
+            // Ok to catch Exception here, because anything going wrong because
+            // of what a client process passes to us should not be fatal for the
+            // system process.
+            Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e);
+            return null;
+        } finally {
+            if (parser != null)
+                parser.close();
+        }
+        return p;
+    }
+
+    int getUidForPackage(String packageName) throws PackageManager.NameNotFoundException {
+        PackageInfo pkgInfo = null;
+        try {
+            pkgInfo = mPm.getPackageInfo(packageName, 0, mUserId);
+        } catch (RemoteException re) {
+            // Shouldn't happen, local call
+        }
+        if (pkgInfo == null || pkgInfo.applicationInfo == null) {
+            throw new PackageManager.NameNotFoundException();
+        }
+        return pkgInfo.applicationInfo.uid;
+    }
+
+    int enforceSystemOrCallingUid(String packageName) throws IllegalArgumentException {
+        int callingUid = Binder.getCallingUid();
+        if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID || callingUid == 0) {
+            return callingUid;
+        }
+        return enforceCallingUid(packageName);
+    }
+
+    int enforceCallingUid(String packageName) throws IllegalArgumentException {
+        int callingUid = Binder.getCallingUid();
+        int packageUid;
+        try {
+            packageUid = getUidForPackage(packageName);
+        } catch (PackageManager.NameNotFoundException ex) {
+            throw new IllegalArgumentException("packageName and uid don't match packageName="
+                    + packageName);
+        }
+        if (!UserHandle.isSameApp(callingUid, packageUid)) {
+            throw new IllegalArgumentException("packageName and uid don't match packageName="
+                    + packageName);
+        }
+        return callingUid;
+    }
+
+    void sendInitialBroadcasts() {
+        synchronized (mAppWidgetIds) {
+            ensureStateLoadedLocked();
+            final int N = mInstalledProviders.size();
+            for (int i = 0; i < N; i++) {
+                Provider p = mInstalledProviders.get(i);
+                if (p.instances.size() > 0) {
+                    sendEnableIntentLocked(p);
+                    int[] appWidgetIds = getAppWidgetIds(p);
+                    sendUpdateIntentLocked(p, appWidgetIds);
+                    registerForBroadcastsLocked(p, appWidgetIds);
+                }
+            }
+        }
+    }
+
+    // only call from initialization -- it assumes that the data structures are all empty
+    void loadStateLocked() {
+        AtomicFile file = savedStateFile();
+        try {
+            FileInputStream stream = file.openRead();
+            readStateFromFileLocked(stream);
+
+            if (stream != null) {
+                try {
+                    stream.close();
+                } catch (IOException e) {
+                    Slog.w(TAG, "Failed to close state FileInputStream " + e);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            Slog.w(TAG, "Failed to read state: " + e);
+        }
+    }
+
+    void saveStateLocked() {
+        if (!mHasFeature) {
+            return;
+        }
+        AtomicFile file = savedStateFile();
+        FileOutputStream stream;
+        try {
+            stream = file.startWrite();
+            if (writeStateToFileLocked(stream)) {
+                file.finishWrite(stream);
+            } else {
+                file.failWrite(stream);
+                Slog.w(TAG, "Failed to save state, restoring backup.");
+            }
+        } catch (IOException e) {
+            Slog.w(TAG, "Failed open state file for write: " + e);
+        }
+    }
+
+    boolean writeStateToFileLocked(FileOutputStream stream) {
+        int N;
+
+        try {
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(stream, "utf-8");
+            out.startDocument(null, true);
+            out.startTag(null, "gs");
+            out.attribute(null, "version", String.valueOf(CURRENT_VERSION));
+            int providerIndex = 0;
+            N = mInstalledProviders.size();
+            for (int i = 0; i < N; i++) {
+                Provider p = mInstalledProviders.get(i);
+                if (p.instances.size() > 0) {
+                    out.startTag(null, "p");
+                    out.attribute(null, "pkg", p.info.provider.getPackageName());
+                    out.attribute(null, "cl", p.info.provider.getClassName());
+                    out.endTag(null, "p");
+                    p.tag = providerIndex;
+                    providerIndex++;
+                }
+            }
+
+            N = mHosts.size();
+            for (int i = 0; i < N; i++) {
+                Host host = mHosts.get(i);
+                out.startTag(null, "h");
+                out.attribute(null, "pkg", host.packageName);
+                out.attribute(null, "id", Integer.toHexString(host.hostId));
+                out.endTag(null, "h");
+                host.tag = i;
+            }
+
+            N = mAppWidgetIds.size();
+            for (int i = 0; i < N; i++) {
+                AppWidgetId id = mAppWidgetIds.get(i);
+                out.startTag(null, "g");
+                out.attribute(null, "id", Integer.toHexString(id.appWidgetId));
+                out.attribute(null, "h", Integer.toHexString(id.host.tag));
+                if (id.provider != null) {
+                    out.attribute(null, "p", Integer.toHexString(id.provider.tag));
+                }
+                if (id.options != null) {
+                    out.attribute(null, "min_width", Integer.toHexString(id.options.getInt(
+                            AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)));
+                    out.attribute(null, "min_height", Integer.toHexString(id.options.getInt(
+                            AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)));
+                    out.attribute(null, "max_width", Integer.toHexString(id.options.getInt(
+                            AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)));
+                    out.attribute(null, "max_height", Integer.toHexString(id.options.getInt(
+                            AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)));
+                    out.attribute(null, "host_category", Integer.toHexString(id.options.getInt(
+                            AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)));
+                }
+                out.endTag(null, "g");
+            }
+
+            Iterator<String> it = mPackagesWithBindWidgetPermission.iterator();
+            while (it.hasNext()) {
+                out.startTag(null, "b");
+                out.attribute(null, "packageName", it.next());
+                out.endTag(null, "b");
+            }
+
+            out.endTag(null, "gs");
+
+            out.endDocument();
+            return true;
+        } catch (IOException e) {
+            Slog.w(TAG, "Failed to write state: " + e);
+            return false;
+        }
+    }
+
+    @SuppressWarnings("unused")
+    void readStateFromFileLocked(FileInputStream stream) {
+        boolean success = false;
+        int version = 0;
+        try {
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(stream, null);
+
+            int type;
+            int providerIndex = 0;
+            HashMap<Integer, Provider> loadedProviders = new HashMap<Integer, Provider>();
+            do {
+                type = parser.next();
+                if (type == XmlPullParser.START_TAG) {
+                    String tag = parser.getName();
+                    if ("gs".equals(tag)) {
+                        String attributeValue = parser.getAttributeValue(null, "version");
+                        try {
+                            version = Integer.parseInt(attributeValue);
+                        } catch (NumberFormatException e) {
+                            version = 0;
+                        }
+                    } else if ("p".equals(tag)) {
+                        // TODO: do we need to check that this package has the same signature
+                        // as before?
+                        String pkg = parser.getAttributeValue(null, "pkg");
+                        String cl = parser.getAttributeValue(null, "cl");
+
+                        final IPackageManager packageManager = AppGlobals.getPackageManager();
+                        try {
+                            packageManager.getReceiverInfo(new ComponentName(pkg, cl), 0, mUserId);
+                        } catch (RemoteException e) {
+                            String[] pkgs = mContext.getPackageManager()
+                                    .currentToCanonicalPackageNames(new String[] { pkg });
+                            pkg = pkgs[0];
+                        }
+
+                        Provider p = lookupProviderLocked(new ComponentName(pkg, cl));
+                        if (p == null && mSafeMode) {
+                            // if we're in safe mode, make a temporary one
+                            p = new Provider();
+                            p.info = new AppWidgetProviderInfo();
+                            p.info.provider = new ComponentName(pkg, cl);
+                            p.zombie = true;
+                            mInstalledProviders.add(p);
+                        }
+                        if (p != null) {
+                            // if it wasn't uninstalled or something
+                            loadedProviders.put(providerIndex, p);
+                        }
+                        providerIndex++;
+                    } else if ("h".equals(tag)) {
+                        Host host = new Host();
+
+                        // TODO: do we need to check that this package has the same signature
+                        // as before?
+                        host.packageName = parser.getAttributeValue(null, "pkg");
+                        try {
+                            host.uid = getUidForPackage(host.packageName);
+                        } catch (PackageManager.NameNotFoundException ex) {
+                            host.zombie = true;
+                        }
+                        if (!host.zombie || mSafeMode) {
+                            // In safe mode, we don't discard the hosts we don't recognize
+                            // so that they're not pruned from our list. Otherwise, we do.
+                            host.hostId = Integer
+                                    .parseInt(parser.getAttributeValue(null, "id"), 16);
+                            mHosts.add(host);
+                        }
+                    } else if ("b".equals(tag)) {
+                        String packageName = parser.getAttributeValue(null, "packageName");
+                        if (packageName != null) {
+                            mPackagesWithBindWidgetPermission.add(packageName);
+                        }
+                    } else if ("g".equals(tag)) {
+                        AppWidgetId id = new AppWidgetId();
+                        id.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
+                        if (id.appWidgetId >= mNextAppWidgetId) {
+                            mNextAppWidgetId = id.appWidgetId + 1;
+                        }
+
+                        Bundle options = new Bundle();
+                        String minWidthString = parser.getAttributeValue(null, "min_width");
+                        if (minWidthString != null) {
+                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
+                                    Integer.parseInt(minWidthString, 16));
+                        }
+                        String minHeightString = parser.getAttributeValue(null, "min_height");
+                        if (minHeightString != null) {
+                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
+                                    Integer.parseInt(minHeightString, 16));
+                        }
+                        String maxWidthString = parser.getAttributeValue(null, "max_width");
+                        if (maxWidthString != null) {
+                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
+                                    Integer.parseInt(maxWidthString, 16));
+                        }
+                        String maxHeightString = parser.getAttributeValue(null, "max_height");
+                        if (maxHeightString != null) {
+                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
+                                    Integer.parseInt(maxHeightString, 16));
+                        }
+                        String categoryString = parser.getAttributeValue(null, "host_category");
+                        if (categoryString != null) {
+                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
+                                    Integer.parseInt(categoryString, 16));
+                        }
+                        id.options = options;
+
+                        String providerString = parser.getAttributeValue(null, "p");
+                        if (providerString != null) {
+                            // there's no provider if it hasn't been bound yet.
+                            // maybe we don't have to save this, but it brings the system
+                            // to the state it was in.
+                            int pIndex = Integer.parseInt(providerString, 16);
+                            id.provider = loadedProviders.get(pIndex);
+                            if (false) {
+                                Slog.d(TAG, "bound appWidgetId=" + id.appWidgetId + " to provider "
+                                        + pIndex + " which is " + id.provider);
+                            }
+                            if (id.provider == null) {
+                                // This provider is gone. We just let the host figure out
+                                // that this happened when it fails to load it.
+                                continue;
+                            }
+                        }
+
+                        int hIndex = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
+                        id.host = mHosts.get(hIndex);
+                        if (id.host == null) {
+                            // This host is gone.
+                            continue;
+                        }
+
+                        if (id.provider != null) {
+                            id.provider.instances.add(id);
+                        }
+                        id.host.instances.add(id);
+                        mAppWidgetIds.add(id);
+                    }
+                }
+            } while (type != XmlPullParser.END_DOCUMENT);
+            success = true;
+        } catch (NullPointerException e) {
+            Slog.w(TAG, "failed parsing " + e);
+        } catch (NumberFormatException e) {
+            Slog.w(TAG, "failed parsing " + e);
+        } catch (XmlPullParserException e) {
+            Slog.w(TAG, "failed parsing " + e);
+        } catch (IOException e) {
+            Slog.w(TAG, "failed parsing " + e);
+        } catch (IndexOutOfBoundsException e) {
+            Slog.w(TAG, "failed parsing " + e);
+        }
+
+        if (success) {
+            // delete any hosts that didn't manage to get connected (should happen)
+            // if it matters, they'll be reconnected.
+            for (int i = mHosts.size() - 1; i >= 0; i--) {
+                pruneHostLocked(mHosts.get(i));
+            }
+            // upgrade the database if needed
+            performUpgrade(version);
+        } else {
+            // failed reading, clean up
+            Slog.w(TAG, "Failed to read state, clearing widgets and hosts.");
+
+            mAppWidgetIds.clear();
+            mHosts.clear();
+            final int N = mInstalledProviders.size();
+            for (int i = 0; i < N; i++) {
+                mInstalledProviders.get(i).instances.clear();
+            }
+        }
+    }
+
+    private void performUpgrade(int fromVersion) {
+        if (fromVersion < CURRENT_VERSION) {
+            Slog.v(TAG, "Upgrading widget database from " + fromVersion + " to " + CURRENT_VERSION
+                    + " for user " + mUserId);
+        }
+
+        int version = fromVersion;
+
+        // Update 1: keyguard moved from package "android" to "com.android.keyguard"
+        if (version == 0) {
+            for (int i = 0; i < mHosts.size(); i++) {
+                Host host = mHosts.get(i);
+                if (host != null && "android".equals(host.packageName)
+                        && host.hostId == KEYGUARD_HOST_ID) {
+                    host.packageName = KEYGUARD_HOST_PACKAGE;
+                }
+            }
+            version = 1;
+        }
+
+        if (version != CURRENT_VERSION) {
+            throw new IllegalStateException("Failed to upgrade widget database");
+        }
+    }
+
+    static File getSettingsFile(int userId) {
+        return new File(Environment.getUserSystemDirectory(userId), SETTINGS_FILENAME);
+    }
+
+    AtomicFile savedStateFile() {
+        File dir = Environment.getUserSystemDirectory(mUserId);
+        File settingsFile = getSettingsFile(mUserId);
+        if (!settingsFile.exists() && mUserId == 0) {
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+            // Migrate old data
+            File oldFile = new File("/data/system/" + SETTINGS_FILENAME);
+            // Method doesn't throw an exception on failure. Ignore any errors
+            // in moving the file (like non-existence)
+            oldFile.renameTo(settingsFile);
+        }
+        return new AtomicFile(settingsFile);
+    }
+
+    void onUserStopping() {
+        // prune the ones we don't want to keep
+        int N = mInstalledProviders.size();
+        for (int i = N - 1; i >= 0; i--) {
+            Provider p = mInstalledProviders.get(i);
+            cancelBroadcasts(p);
+        }
+    }
+
+    void onUserRemoved() {
+        getSettingsFile(mUserId).delete();
+    }
+
+    boolean addProvidersForPackageLocked(String pkgName) {
+        boolean providersAdded = false;
+        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+        intent.setPackage(pkgName);
+        List<ResolveInfo> broadcastReceivers;
+        try {
+            broadcastReceivers = mPm.queryIntentReceivers(intent,
+                    intent.resolveTypeIfNeeded(mContext.getContentResolver()),
+                    PackageManager.GET_META_DATA, mUserId);
+        } catch (RemoteException re) {
+            // Shouldn't happen, local call
+            return false;
+        }
+        final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
+        for (int i = 0; i < N; i++) {
+            ResolveInfo ri = broadcastReceivers.get(i);
+            ActivityInfo ai = ri.activityInfo;
+            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
+                continue;
+            }
+            if (pkgName.equals(ai.packageName)) {
+                addProviderLocked(ri);
+                providersAdded = true;
+            }
+        }
+
+        return providersAdded;
+    }
+
+    /**
+     * Updates all providers with the specified package names, and records any providers that were
+     * pruned.
+     *
+     * @return whether any providers were updated
+     */
+    boolean updateProvidersForPackageLocked(String pkgName, Set<ComponentName> removedProviders) {
+        boolean providersUpdated = false;
+        HashSet<String> keep = new HashSet<String>();
+        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
+        intent.setPackage(pkgName);
+        List<ResolveInfo> broadcastReceivers;
+        try {
+            broadcastReceivers = mPm.queryIntentReceivers(intent,
+                intent.resolveTypeIfNeeded(mContext.getContentResolver()),
+                PackageManager.GET_META_DATA, mUserId);
+        } catch (RemoteException re) {
+            // Shouldn't happen, local call
+            return false;
+        }
+
+        // add the missing ones and collect which ones to keep
+        int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
+        for (int i = 0; i < N; i++) {
+            ResolveInfo ri = broadcastReceivers.get(i);
+            ActivityInfo ai = ri.activityInfo;
+            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
+                continue;
+            }
+            if (pkgName.equals(ai.packageName)) {
+                ComponentName component = new ComponentName(ai.packageName, ai.name);
+                Provider p = lookupProviderLocked(component);
+                if (p == null) {
+                    if (addProviderLocked(ri)) {
+                        keep.add(ai.name);
+                        providersUpdated = true;
+                    }
+                } else {
+                    Provider parsed = parseProviderInfoXml(component, ri);
+                    if (parsed != null) {
+                        keep.add(ai.name);
+                        // Use the new AppWidgetProviderInfo.
+                        p.info = parsed.info;
+                        // If it's enabled
+                        final int M = p.instances.size();
+                        if (M > 0) {
+                            int[] appWidgetIds = getAppWidgetIds(p);
+                            // Reschedule for the new updatePeriodMillis (don't worry about handling
+                            // it specially if updatePeriodMillis didn't change because we just sent
+                            // an update, and the next one will be updatePeriodMillis from now).
+                            cancelBroadcasts(p);
+                            registerForBroadcastsLocked(p, appWidgetIds);
+                            // If it's currently showing, call back with the new
+                            // AppWidgetProviderInfo.
+                            for (int j = 0; j < M; j++) {
+                                AppWidgetId id = p.instances.get(j);
+                                id.views = null;
+                                if (id.host != null && id.host.callbacks != null) {
+                                    try {
+                                        id.host.callbacks.providerChanged(id.appWidgetId, p.info,
+                                                mUserId);
+                                    } catch (RemoteException ex) {
+                                        // It failed; remove the callback. No need to prune because
+                                        // we know that this host is still referenced by this
+                                        // instance.
+                                        id.host.callbacks = null;
+                                    }
+                                }
+                            }
+                            // Now that we've told the host, push out an update.
+                            sendUpdateIntentLocked(p, appWidgetIds);
+                            providersUpdated = true;
+                        }
+                    }
+                }
+            }
+        }
+
+        // prune the ones we don't want to keep
+        N = mInstalledProviders.size();
+        for (int i = N - 1; i >= 0; i--) {
+            Provider p = mInstalledProviders.get(i);
+            if (pkgName.equals(p.info.provider.getPackageName())
+                    && !keep.contains(p.info.provider.getClassName())) {
+                if (removedProviders != null) {
+                    removedProviders.add(p.info.provider);
+                }
+                removeProviderLocked(i, p);
+                providersUpdated = true;
+            }
+        }
+
+        return providersUpdated;
+    }
+
+    boolean removeProvidersForPackageLocked(String pkgName) {
+        boolean providersRemoved = false;
+        int N = mInstalledProviders.size();
+        for (int i = N - 1; i >= 0; i--) {
+            Provider p = mInstalledProviders.get(i);
+            if (pkgName.equals(p.info.provider.getPackageName())) {
+                removeProviderLocked(i, p);
+                providersRemoved = true;
+            }
+        }
+
+        // Delete the hosts for this package too
+        //
+        // By now, we have removed any AppWidgets that were in any hosts here,
+        // so we don't need to worry about sending DISABLE broadcasts to them.
+        N = mHosts.size();
+        for (int i = N - 1; i >= 0; i--) {
+            Host host = mHosts.get(i);
+            if (pkgName.equals(host.packageName)) {
+                deleteHostLocked(host);
+            }
+        }
+
+        return providersRemoved;
+    }
+
+    void notifyHostsForProvidersChangedLocked() {
+        final int N = mHosts.size();
+        for (int i = N - 1; i >= 0; i--) {
+            Host host = mHosts.get(i);
+            try {
+                if (host.callbacks != null) {
+                    host.callbacks.providersChanged(mUserId);
+                }
+            } catch (RemoteException ex) {
+                // It failed; remove the callback. No need to prune because
+                // we know that this host is still referenced by this
+                // instance.
+                host.callbacks = null;
+            }
+        }
+    }
+}
diff --git a/services/backup/Android.mk b/services/backup/Android.mk
new file mode 100644
index 0000000..3e686d1
--- /dev/null
+++ b/services/backup/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.backup
+
+LOCAL_SRC_FILES += \
+      $(call all-java-files-under,java)
+
+LOCAL_JAVA_LIBRARIES := services.core
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
new file mode 100644
index 0000000..b3571d7
--- /dev/null
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -0,0 +1,6306 @@
+/*
+ * 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.
+ */
+
+package com.android.server.backup;
+
+import android.app.ActivityManagerNative;
+import android.app.AlarmManager;
+import android.app.AppGlobals;
+import android.app.IActivityManager;
+import android.app.IApplicationThread;
+import android.app.IBackupAgent;
+import android.app.PendingIntent;
+import android.app.backup.BackupAgent;
+import android.app.backup.BackupDataOutput;
+import android.app.backup.FullBackup;
+import android.app.backup.RestoreSet;
+import android.app.backup.IBackupManager;
+import android.app.backup.IFullBackupRestoreObserver;
+import android.app.backup.IRestoreObserver;
+import android.app.backup.IRestoreSession;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageDataObserver;
+import android.content.pm.IPackageDeleteObserver;
+import android.content.pm.IPackageInstallObserver;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.pm.Signature;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.ParcelFileDescriptor;
+import android.os.PowerManager;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SELinux;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.os.WorkSource;
+import android.os.Environment.UserEnvironment;
+import android.os.storage.IMountService;
+import android.provider.Settings;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.StringBuilderPrinter;
+
+import com.android.internal.backup.BackupConstants;
+import com.android.internal.backup.IBackupTransport;
+import com.android.internal.backup.IObbBackupService;
+import com.android.server.EventLogTags;
+import com.android.server.SystemService;
+import com.android.server.backup.PackageManagerBackupAgent.Metadata;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.RandomAccessFile;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.zip.Deflater;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.InflaterInputStream;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.CipherOutputStream;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.SecretKeySpec;
+
+public class BackupManagerService extends IBackupManager.Stub {
+
+    private static final String TAG = "BackupManagerService";
+    private static final boolean DEBUG = true;
+    private static final boolean MORE_DEBUG = false;
+
+    // Historical and current algorithm names
+    static final String PBKDF_CURRENT = "PBKDF2WithHmacSHA1";
+    static final String PBKDF_FALLBACK = "PBKDF2WithHmacSHA1And8bit";
+
+    // Name and current contents version of the full-backup manifest file
+    static final String BACKUP_MANIFEST_FILENAME = "_manifest";
+    static final int BACKUP_MANIFEST_VERSION = 1;
+    static final String BACKUP_FILE_HEADER_MAGIC = "ANDROID BACKUP\n";
+    static final int BACKUP_FILE_VERSION = 2;
+    static final int BACKUP_PW_FILE_VERSION = 2;
+    static final boolean COMPRESS_FULL_BACKUPS = true; // should be true in production
+
+    static final String SHARED_BACKUP_AGENT_PACKAGE = "com.android.sharedstoragebackup";
+    static final String SERVICE_ACTION_TRANSPORT_HOST = "android.backup.TRANSPORT_HOST";
+
+    // How often we perform a backup pass.  Privileged external callers can
+    // trigger an immediate pass.
+    private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR;
+
+    // Random variation in backup scheduling time to avoid server load spikes
+    private static final int FUZZ_MILLIS = 5 * 60 * 1000;
+
+    // The amount of time between the initial provisioning of the device and
+    // the first backup pass.
+    private static final long FIRST_BACKUP_INTERVAL = 12 * AlarmManager.INTERVAL_HOUR;
+
+    // Retry interval for clear/init when the transport is unavailable
+    private static final long TRANSPORT_RETRY_INTERVAL = 1 * AlarmManager.INTERVAL_HOUR;
+
+    private static final String RUN_BACKUP_ACTION = "android.app.backup.intent.RUN";
+    private static final String RUN_INITIALIZE_ACTION = "android.app.backup.intent.INIT";
+    private static final String RUN_CLEAR_ACTION = "android.app.backup.intent.CLEAR";
+    private static final int MSG_RUN_BACKUP = 1;
+    private static final int MSG_RUN_FULL_BACKUP = 2;
+    private static final int MSG_RUN_RESTORE = 3;
+    private static final int MSG_RUN_CLEAR = 4;
+    private static final int MSG_RUN_INITIALIZE = 5;
+    private static final int MSG_RUN_GET_RESTORE_SETS = 6;
+    private static final int MSG_TIMEOUT = 7;
+    private static final int MSG_RESTORE_TIMEOUT = 8;
+    private static final int MSG_FULL_CONFIRMATION_TIMEOUT = 9;
+    private static final int MSG_RUN_FULL_RESTORE = 10;
+    private static final int MSG_RETRY_INIT = 11;
+    private static final int MSG_RETRY_CLEAR = 12;
+
+    // backup task state machine tick
+    static final int MSG_BACKUP_RESTORE_STEP = 20;
+    static final int MSG_OP_COMPLETE = 21;
+
+    // Timeout interval for deciding that a bind or clear-data has taken too long
+    static final long TIMEOUT_INTERVAL = 10 * 1000;
+
+    // Timeout intervals for agent backup & restore operations
+    static final long TIMEOUT_BACKUP_INTERVAL = 30 * 1000;
+    static final long TIMEOUT_FULL_BACKUP_INTERVAL = 5 * 60 * 1000;
+    static final long TIMEOUT_SHARED_BACKUP_INTERVAL = 30 * 60 * 1000;
+    static final long TIMEOUT_RESTORE_INTERVAL = 60 * 1000;
+
+    // User confirmation timeout for a full backup/restore operation.  It's this long in
+    // order to give them time to enter the backup password.
+    static final long TIMEOUT_FULL_CONFIRMATION = 60 * 1000;
+
+    private Context mContext;
+    private PackageManager mPackageManager;
+    IPackageManager mPackageManagerBinder;
+    private IActivityManager mActivityManager;
+    private PowerManager mPowerManager;
+    private AlarmManager mAlarmManager;
+    private IMountService mMountService;
+    IBackupManager mBackupManagerBinder;
+
+    boolean mEnabled;   // access to this is synchronized on 'this'
+    boolean mProvisioned;
+    boolean mAutoRestore;
+    PowerManager.WakeLock mWakelock;
+    HandlerThread mHandlerThread;
+    BackupHandler mBackupHandler;
+    PendingIntent mRunBackupIntent, mRunInitIntent;
+    BroadcastReceiver mRunBackupReceiver, mRunInitReceiver;
+    // map UIDs to the set of participating packages under that UID
+    final SparseArray<HashSet<String>> mBackupParticipants
+            = new SparseArray<HashSet<String>>();
+    // set of backup services that have pending changes
+    class BackupRequest {
+        public String packageName;
+
+        BackupRequest(String pkgName) {
+            packageName = pkgName;
+        }
+
+        public String toString() {
+            return "BackupRequest{pkg=" + packageName + "}";
+        }
+    }
+    // Backups that we haven't started yet.  Keys are package names.
+    HashMap<String,BackupRequest> mPendingBackups
+            = new HashMap<String,BackupRequest>();
+
+    // Pseudoname that we use for the Package Manager metadata "package"
+    static final String PACKAGE_MANAGER_SENTINEL = "@pm@";
+
+    // locking around the pending-backup management
+    final Object mQueueLock = new Object();
+
+    // The thread performing the sequence of queued backups binds to each app's agent
+    // in succession.  Bind notifications are asynchronously delivered through the
+    // Activity Manager; use this lock object to signal when a requested binding has
+    // completed.
+    final Object mAgentConnectLock = new Object();
+    IBackupAgent mConnectedAgent;
+    volatile boolean mBackupRunning;
+    volatile boolean mConnecting;
+    volatile long mLastBackupPass;
+    volatile long mNextBackupPass;
+
+    // For debugging, we maintain a progress trace of operations during backup
+    static final boolean DEBUG_BACKUP_TRACE = true;
+    final List<String> mBackupTrace = new ArrayList<String>();
+
+    // A similar synchronization mechanism around clearing apps' data for restore
+    final Object mClearDataLock = new Object();
+    volatile boolean mClearingData;
+
+    // Transport bookkeeping
+    final HashMap<String,String> mTransportNames
+            = new HashMap<String,String>();             // component name -> registration name
+    final HashMap<String,IBackupTransport> mTransports
+            = new HashMap<String,IBackupTransport>();   // registration name -> binder
+    final ArrayList<TransportConnection> mTransportConnections
+            = new ArrayList<TransportConnection>();
+    String mCurrentTransport;
+    ActiveRestoreSession mActiveRestoreSession;
+
+    // Watch the device provisioning operation during setup
+    ContentObserver mProvisionedObserver;
+
+    public static final class Lifecycle extends SystemService {
+        private final BackupManagerService mService;
+
+        public Lifecycle(Context context) {
+            super(context);
+            mService = new BackupManagerService(context);
+        }
+
+        @Override
+        public void onStart() {
+            publishBinderService(Context.BACKUP_SERVICE, mService);
+        }
+    }
+
+    class ProvisionedObserver extends ContentObserver {
+        public ProvisionedObserver(Handler handler) {
+            super(handler);
+        }
+
+        public void onChange(boolean selfChange) {
+            final boolean wasProvisioned = mProvisioned;
+            final boolean isProvisioned = deviceIsProvisioned();
+            // latch: never unprovision
+            mProvisioned = wasProvisioned || isProvisioned;
+            if (MORE_DEBUG) {
+                Slog.d(TAG, "Provisioning change: was=" + wasProvisioned
+                        + " is=" + isProvisioned + " now=" + mProvisioned);
+            }
+
+            synchronized (mQueueLock) {
+                if (mProvisioned && !wasProvisioned && mEnabled) {
+                    // we're now good to go, so start the backup alarms
+                    if (MORE_DEBUG) Slog.d(TAG, "Now provisioned, so starting backups");
+                    startBackupAlarmsLocked(FIRST_BACKUP_INTERVAL);
+                }
+            }
+        }
+    }
+
+    class RestoreGetSetsParams {
+        public IBackupTransport transport;
+        public ActiveRestoreSession session;
+        public IRestoreObserver observer;
+
+        RestoreGetSetsParams(IBackupTransport _transport, ActiveRestoreSession _session,
+                IRestoreObserver _observer) {
+            transport = _transport;
+            session = _session;
+            observer = _observer;
+        }
+    }
+
+    class RestoreParams {
+        public IBackupTransport transport;
+        public String dirName;
+        public IRestoreObserver observer;
+        public long token;
+        public PackageInfo pkgInfo;
+        public int pmToken; // in post-install restore, the PM's token for this transaction
+        public boolean needFullBackup;
+        public String[] filterSet;
+
+        RestoreParams(IBackupTransport _transport, String _dirName, IRestoreObserver _obs,
+                long _token, PackageInfo _pkg, int _pmToken, boolean _needFullBackup) {
+            transport = _transport;
+            dirName = _dirName;
+            observer = _obs;
+            token = _token;
+            pkgInfo = _pkg;
+            pmToken = _pmToken;
+            needFullBackup = _needFullBackup;
+            filterSet = null;
+        }
+
+        RestoreParams(IBackupTransport _transport, String _dirName, IRestoreObserver _obs,
+                long _token, boolean _needFullBackup) {
+            transport = _transport;
+            dirName = _dirName;
+            observer = _obs;
+            token = _token;
+            pkgInfo = null;
+            pmToken = 0;
+            needFullBackup = _needFullBackup;
+            filterSet = null;
+        }
+
+        RestoreParams(IBackupTransport _transport, String _dirName, IRestoreObserver _obs,
+                long _token, String[] _filterSet, boolean _needFullBackup) {
+            transport = _transport;
+            dirName = _dirName;
+            observer = _obs;
+            token = _token;
+            pkgInfo = null;
+            pmToken = 0;
+            needFullBackup = _needFullBackup;
+            filterSet = _filterSet;
+        }
+    }
+
+    class ClearParams {
+        public IBackupTransport transport;
+        public PackageInfo packageInfo;
+
+        ClearParams(IBackupTransport _transport, PackageInfo _info) {
+            transport = _transport;
+            packageInfo = _info;
+        }
+    }
+
+    class ClearRetryParams {
+        public String transportName;
+        public String packageName;
+
+        ClearRetryParams(String transport, String pkg) {
+            transportName = transport;
+            packageName = pkg;
+        }
+    }
+
+    class FullParams {
+        public ParcelFileDescriptor fd;
+        public final AtomicBoolean latch;
+        public IFullBackupRestoreObserver observer;
+        public String curPassword;     // filled in by the confirmation step
+        public String encryptPassword;
+
+        FullParams() {
+            latch = new AtomicBoolean(false);
+        }
+    }
+
+    class FullBackupParams extends FullParams {
+        public boolean includeApks;
+        public boolean includeObbs;
+        public boolean includeShared;
+        public boolean allApps;
+        public boolean includeSystem;
+        public String[] packages;
+
+        FullBackupParams(ParcelFileDescriptor output, boolean saveApks, boolean saveObbs,
+                boolean saveShared, boolean doAllApps, boolean doSystem, String[] pkgList) {
+            fd = output;
+            includeApks = saveApks;
+            includeObbs = saveObbs;
+            includeShared = saveShared;
+            allApps = doAllApps;
+            includeSystem = doSystem;
+            packages = pkgList;
+        }
+    }
+
+    class FullRestoreParams extends FullParams {
+        FullRestoreParams(ParcelFileDescriptor input) {
+            fd = input;
+        }
+    }
+
+    // Bookkeeping of in-flight operations for timeout etc. purposes.  The operation
+    // token is the index of the entry in the pending-operations list.
+    static final int OP_PENDING = 0;
+    static final int OP_ACKNOWLEDGED = 1;
+    static final int OP_TIMEOUT = -1;
+
+    class Operation {
+        public int state;
+        public BackupRestoreTask callback;
+
+        Operation(int initialState, BackupRestoreTask callbackObj) {
+            state = initialState;
+            callback = callbackObj;
+        }
+    }
+    final SparseArray<Operation> mCurrentOperations = new SparseArray<Operation>();
+    final Object mCurrentOpLock = new Object();
+    final Random mTokenGenerator = new Random();
+
+    final SparseArray<FullParams> mFullConfirmations = new SparseArray<FullParams>();
+
+    // Where we keep our journal files and other bookkeeping
+    File mBaseStateDir;
+    File mDataDir;
+    File mJournalDir;
+    File mJournal;
+
+    // Backup password, if any, and the file where it's saved.  What is stored is not the
+    // password text itself; it's the result of a PBKDF2 hash with a randomly chosen (but
+    // persisted) salt.  Validation is performed by running the challenge text through the
+    // same PBKDF2 cycle with the persisted salt; if the resulting derived key string matches
+    // the saved hash string, then the challenge text matches the originally supplied
+    // password text.
+    private final SecureRandom mRng = new SecureRandom();
+    private String mPasswordHash;
+    private File mPasswordHashFile;
+    private int mPasswordVersion;
+    private File mPasswordVersionFile;
+    private byte[] mPasswordSalt;
+
+    // Configuration of PBKDF2 that we use for generating pw hashes and intermediate keys
+    static final int PBKDF2_HASH_ROUNDS = 10000;
+    static final int PBKDF2_KEY_SIZE = 256;     // bits
+    static final int PBKDF2_SALT_SIZE = 512;    // bits
+    static final String ENCRYPTION_ALGORITHM_NAME = "AES-256";
+
+    // Keep a log of all the apps we've ever backed up, and what the
+    // dataset tokens are for both the current backup dataset and
+    // the ancestral dataset.
+    private File mEverStored;
+    HashSet<String> mEverStoredApps = new HashSet<String>();
+
+    static final int CURRENT_ANCESTRAL_RECORD_VERSION = 1;  // increment when the schema changes
+    File mTokenFile;
+    Set<String> mAncestralPackages = null;
+    long mAncestralToken = 0;
+    long mCurrentToken = 0;
+
+    // Persistently track the need to do a full init
+    static final String INIT_SENTINEL_FILE_NAME = "_need_init_";
+    HashSet<String> mPendingInits = new HashSet<String>();  // transport names
+
+    // Utility: build a new random integer token
+    int generateToken() {
+        int token;
+        do {
+            synchronized (mTokenGenerator) {
+                token = mTokenGenerator.nextInt();
+            }
+        } while (token < 0);
+        return token;
+    }
+
+    // ----- Asynchronous backup/restore handler thread -----
+
+    private class BackupHandler extends Handler {
+        public BackupHandler(Looper looper) {
+            super(looper);
+        }
+
+        public void handleMessage(Message msg) {
+
+            switch (msg.what) {
+            case MSG_RUN_BACKUP:
+            {
+                mLastBackupPass = System.currentTimeMillis();
+                mNextBackupPass = mLastBackupPass + BACKUP_INTERVAL;
+
+                IBackupTransport transport = getTransport(mCurrentTransport);
+                if (transport == null) {
+                    Slog.v(TAG, "Backup requested but no transport available");
+                    synchronized (mQueueLock) {
+                        mBackupRunning = false;
+                    }
+                    mWakelock.release();
+                    break;
+                }
+
+                // snapshot the pending-backup set and work on that
+                ArrayList<BackupRequest> queue = new ArrayList<BackupRequest>();
+                File oldJournal = mJournal;
+                synchronized (mQueueLock) {
+                    // Do we have any work to do?  Construct the work queue
+                    // then release the synchronization lock to actually run
+                    // the backup.
+                    if (mPendingBackups.size() > 0) {
+                        for (BackupRequest b: mPendingBackups.values()) {
+                            queue.add(b);
+                        }
+                        if (DEBUG) Slog.v(TAG, "clearing pending backups");
+                        mPendingBackups.clear();
+
+                        // Start a new backup-queue journal file too
+                        mJournal = null;
+
+                    }
+                }
+
+                // At this point, we have started a new journal file, and the old
+                // file identity is being passed to the backup processing task.
+                // When it completes successfully, that old journal file will be
+                // deleted.  If we crash prior to that, the old journal is parsed
+                // at next boot and the journaled requests fulfilled.
+                boolean staged = true;
+                if (queue.size() > 0) {
+                    // Spin up a backup state sequence and set it running
+                    try {
+                        String dirName = transport.transportDirName();
+                        PerformBackupTask pbt = new PerformBackupTask(transport, dirName,
+                                queue, oldJournal);
+                        Message pbtMessage = obtainMessage(MSG_BACKUP_RESTORE_STEP, pbt);
+                        sendMessage(pbtMessage);
+                    } catch (RemoteException e) {
+                        // unable to ask the transport its dir name -- transient failure, since
+                        // the above check succeeded.  Try again next time.
+                        Slog.e(TAG, "Transport became unavailable attempting backup");
+                        staged = false;
+                    }
+                } else {
+                    Slog.v(TAG, "Backup requested but nothing pending");
+                    staged = false;
+                }
+
+                if (!staged) {
+                    // if we didn't actually hand off the wakelock, rewind until next time
+                    synchronized (mQueueLock) {
+                        mBackupRunning = false;
+                    }
+                    mWakelock.release();
+                }
+                break;
+            }
+
+            case MSG_BACKUP_RESTORE_STEP:
+            {
+                try {
+                    BackupRestoreTask task = (BackupRestoreTask) msg.obj;
+                    if (MORE_DEBUG) Slog.v(TAG, "Got next step for " + task + ", executing");
+                    task.execute();
+                } catch (ClassCastException e) {
+                    Slog.e(TAG, "Invalid backup task in flight, obj=" + msg.obj);
+                }
+                break;
+            }
+
+            case MSG_OP_COMPLETE:
+            {
+                try {
+                    BackupRestoreTask task = (BackupRestoreTask) msg.obj;
+                    task.operationComplete();
+                } catch (ClassCastException e) {
+                    Slog.e(TAG, "Invalid completion in flight, obj=" + msg.obj);
+                }
+                break;
+            }
+
+            case MSG_RUN_FULL_BACKUP:
+            {
+                // TODO: refactor full backup to be a looper-based state machine
+                // similar to normal backup/restore.
+                FullBackupParams params = (FullBackupParams)msg.obj;
+                PerformFullBackupTask task = new PerformFullBackupTask(params.fd,
+                        params.observer, params.includeApks, params.includeObbs,
+                        params.includeShared, params.curPassword, params.encryptPassword,
+                        params.allApps, params.includeSystem, params.packages, params.latch);
+                (new Thread(task)).start();
+                break;
+            }
+
+            case MSG_RUN_RESTORE:
+            {
+                RestoreParams params = (RestoreParams)msg.obj;
+                Slog.d(TAG, "MSG_RUN_RESTORE observer=" + params.observer);
+                PerformRestoreTask task = new PerformRestoreTask(
+                        params.transport, params.dirName, params.observer,
+                        params.token, params.pkgInfo, params.pmToken,
+                        params.needFullBackup, params.filterSet);
+                Message restoreMsg = obtainMessage(MSG_BACKUP_RESTORE_STEP, task);
+                sendMessage(restoreMsg);
+                break;
+            }
+
+            case MSG_RUN_FULL_RESTORE:
+            {
+                // TODO: refactor full restore to be a looper-based state machine
+                // similar to normal backup/restore.
+                FullRestoreParams params = (FullRestoreParams)msg.obj;
+                PerformFullRestoreTask task = new PerformFullRestoreTask(params.fd,
+                        params.curPassword, params.encryptPassword,
+                        params.observer, params.latch);
+                (new Thread(task)).start();
+                break;
+            }
+
+            case MSG_RUN_CLEAR:
+            {
+                ClearParams params = (ClearParams)msg.obj;
+                (new PerformClearTask(params.transport, params.packageInfo)).run();
+                break;
+            }
+
+            case MSG_RETRY_CLEAR:
+            {
+                // reenqueues if the transport remains unavailable
+                ClearRetryParams params = (ClearRetryParams)msg.obj;
+                clearBackupData(params.transportName, params.packageName);
+                break;
+            }
+
+            case MSG_RUN_INITIALIZE:
+            {
+                HashSet<String> queue;
+
+                // Snapshot the pending-init queue and work on that
+                synchronized (mQueueLock) {
+                    queue = new HashSet<String>(mPendingInits);
+                    mPendingInits.clear();
+                }
+
+                (new PerformInitializeTask(queue)).run();
+                break;
+            }
+
+            case MSG_RETRY_INIT:
+            {
+                synchronized (mQueueLock) {
+                    recordInitPendingLocked(msg.arg1 != 0, (String)msg.obj);
+                    mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
+                            mRunInitIntent);
+                }
+                break;
+            }
+
+            case MSG_RUN_GET_RESTORE_SETS:
+            {
+                // Like other async operations, this is entered with the wakelock held
+                RestoreSet[] sets = null;
+                RestoreGetSetsParams params = (RestoreGetSetsParams)msg.obj;
+                try {
+                    sets = params.transport.getAvailableRestoreSets();
+                    // cache the result in the active session
+                    synchronized (params.session) {
+                        params.session.mRestoreSets = sets;
+                    }
+                    if (sets == null) EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                } catch (Exception e) {
+                    Slog.e(TAG, "Error from transport getting set list");
+                } finally {
+                    if (params.observer != null) {
+                        try {
+                            params.observer.restoreSetsAvailable(sets);
+                        } catch (RemoteException re) {
+                            Slog.e(TAG, "Unable to report listing to observer");
+                        } catch (Exception e) {
+                            Slog.e(TAG, "Restore observer threw", e);
+                        }
+                    }
+
+                    // Done: reset the session timeout clock
+                    removeMessages(MSG_RESTORE_TIMEOUT);
+                    sendEmptyMessageDelayed(MSG_RESTORE_TIMEOUT, TIMEOUT_RESTORE_INTERVAL);
+
+                    mWakelock.release();
+                }
+                break;
+            }
+
+            case MSG_TIMEOUT:
+            {
+                handleTimeout(msg.arg1, msg.obj);
+                break;
+            }
+
+            case MSG_RESTORE_TIMEOUT:
+            {
+                synchronized (BackupManagerService.this) {
+                    if (mActiveRestoreSession != null) {
+                        // Client app left the restore session dangling.  We know that it
+                        // can't be in the middle of an actual restore operation because
+                        // the timeout is suspended while a restore is in progress.  Clean
+                        // up now.
+                        Slog.w(TAG, "Restore session timed out; aborting");
+                        post(mActiveRestoreSession.new EndRestoreRunnable(
+                                BackupManagerService.this, mActiveRestoreSession));
+                    }
+                }
+            }
+
+            case MSG_FULL_CONFIRMATION_TIMEOUT:
+            {
+                synchronized (mFullConfirmations) {
+                    FullParams params = mFullConfirmations.get(msg.arg1);
+                    if (params != null) {
+                        Slog.i(TAG, "Full backup/restore timed out waiting for user confirmation");
+
+                        // Release the waiter; timeout == completion
+                        signalFullBackupRestoreCompletion(params);
+
+                        // Remove the token from the set
+                        mFullConfirmations.delete(msg.arg1);
+
+                        // Report a timeout to the observer, if any
+                        if (params.observer != null) {
+                            try {
+                                params.observer.onTimeout();
+                            } catch (RemoteException e) {
+                                /* don't care if the app has gone away */
+                            }
+                        }
+                    } else {
+                        Slog.d(TAG, "couldn't find params for token " + msg.arg1);
+                    }
+                }
+                break;
+            }
+            }
+        }
+    }
+
+    // ----- Debug-only backup operation trace -----
+    void addBackupTrace(String s) {
+        if (DEBUG_BACKUP_TRACE) {
+            synchronized (mBackupTrace) {
+                mBackupTrace.add(s);
+            }
+        }
+    }
+
+    void clearBackupTrace() {
+        if (DEBUG_BACKUP_TRACE) {
+            synchronized (mBackupTrace) {
+                mBackupTrace.clear();
+            }
+        }
+    }
+
+    // ----- Main service implementation -----
+
+    public BackupManagerService(Context context) {
+        mContext = context;
+        mPackageManager = context.getPackageManager();
+        mPackageManagerBinder = AppGlobals.getPackageManager();
+        mActivityManager = ActivityManagerNative.getDefault();
+
+        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+        mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
+
+        mBackupManagerBinder = asInterface(asBinder());
+
+        // spin up the backup/restore handler thread
+        mHandlerThread = new HandlerThread("backup", Process.THREAD_PRIORITY_BACKGROUND);
+        mHandlerThread.start();
+        mBackupHandler = new BackupHandler(mHandlerThread.getLooper());
+
+        // Set up our bookkeeping
+        final ContentResolver resolver = context.getContentResolver();
+        boolean areEnabled = Settings.Secure.getInt(resolver,
+                Settings.Secure.BACKUP_ENABLED, 0) != 0;
+        mProvisioned = Settings.Global.getInt(resolver,
+                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
+        mAutoRestore = Settings.Secure.getInt(resolver,
+                Settings.Secure.BACKUP_AUTO_RESTORE, 1) != 0;
+
+        mProvisionedObserver = new ProvisionedObserver(mBackupHandler);
+        resolver.registerContentObserver(
+                Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
+                false, mProvisionedObserver);
+
+        // If Encrypted file systems is enabled or disabled, this call will return the
+        // correct directory.
+        mBaseStateDir = new File(Environment.getSecureDataDirectory(), "backup");
+        mBaseStateDir.mkdirs();
+        if (!SELinux.restorecon(mBaseStateDir)) {
+            Slog.e(TAG, "SELinux restorecon failed on " + mBaseStateDir);
+        }
+        mDataDir = Environment.getDownloadCacheDirectory();
+
+        mPasswordVersion = 1;       // unless we hear otherwise
+        mPasswordVersionFile = new File(mBaseStateDir, "pwversion");
+        if (mPasswordVersionFile.exists()) {
+            FileInputStream fin = null;
+            DataInputStream in = null;
+            try {
+                fin = new FileInputStream(mPasswordVersionFile);
+                in = new DataInputStream(fin);
+                mPasswordVersion = in.readInt();
+            } catch (IOException e) {
+                Slog.e(TAG, "Unable to read backup pw version");
+            } finally {
+                try {
+                    if (in != null) in.close();
+                    if (fin != null) fin.close();
+                } catch (IOException e) {
+                    Slog.w(TAG, "Error closing pw version files");
+                }
+            }
+        }
+
+        mPasswordHashFile = new File(mBaseStateDir, "pwhash");
+        if (mPasswordHashFile.exists()) {
+            FileInputStream fin = null;
+            DataInputStream in = null;
+            try {
+                fin = new FileInputStream(mPasswordHashFile);
+                in = new DataInputStream(new BufferedInputStream(fin));
+                // integer length of the salt array, followed by the salt,
+                // then the hex pw hash string
+                int saltLen = in.readInt();
+                byte[] salt = new byte[saltLen];
+                in.readFully(salt);
+                mPasswordHash = in.readUTF();
+                mPasswordSalt = salt;
+            } catch (IOException e) {
+                Slog.e(TAG, "Unable to read saved backup pw hash");
+            } finally {
+                try {
+                    if (in != null) in.close();
+                    if (fin != null) fin.close();
+                } catch (IOException e) {
+                    Slog.w(TAG, "Unable to close streams");
+                }
+            }
+        }
+
+        // Alarm receivers for scheduled backups & initialization operations
+        mRunBackupReceiver = new RunBackupReceiver();
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(RUN_BACKUP_ACTION);
+        context.registerReceiver(mRunBackupReceiver, filter,
+                android.Manifest.permission.BACKUP, null);
+
+        mRunInitReceiver = new RunInitializeReceiver();
+        filter = new IntentFilter();
+        filter.addAction(RUN_INITIALIZE_ACTION);
+        context.registerReceiver(mRunInitReceiver, filter,
+                android.Manifest.permission.BACKUP, null);
+
+        Intent backupIntent = new Intent(RUN_BACKUP_ACTION);
+        backupIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+        mRunBackupIntent = PendingIntent.getBroadcast(context, MSG_RUN_BACKUP, backupIntent, 0);
+
+        Intent initIntent = new Intent(RUN_INITIALIZE_ACTION);
+        backupIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+        mRunInitIntent = PendingIntent.getBroadcast(context, MSG_RUN_INITIALIZE, initIntent, 0);
+
+        // Set up the backup-request journaling
+        mJournalDir = new File(mBaseStateDir, "pending");
+        mJournalDir.mkdirs();   // creates mBaseStateDir along the way
+        mJournal = null;        // will be created on first use
+
+        // Set up the various sorts of package tracking we do
+        initPackageTracking();
+
+        // Build our mapping of uid to backup client services.  This implicitly
+        // schedules a backup pass on the Package Manager metadata the first
+        // time anything needs to be backed up.
+        synchronized (mBackupParticipants) {
+            addPackageParticipantsLocked(null);
+        }
+
+        // Set up our transport options and initialize the default transport
+        // TODO: Don't create transports that we don't need to?
+        mCurrentTransport = Settings.Secure.getString(context.getContentResolver(),
+                Settings.Secure.BACKUP_TRANSPORT);
+        if ("".equals(mCurrentTransport)) {
+            mCurrentTransport = null;
+        }
+        if (DEBUG) Slog.v(TAG, "Starting with transport " + mCurrentTransport);
+
+        // Find transport hosts and bind to their services
+        Intent transportServiceIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST);
+        List<ResolveInfo> hosts = mPackageManager.queryIntentServicesAsUser(
+                transportServiceIntent, 0, UserHandle.USER_OWNER);
+        if (DEBUG) {
+            Slog.v(TAG, "Found transports: " + ((hosts == null) ? "null" : hosts.size()));
+        }
+        if (hosts != null) {
+            if (MORE_DEBUG) {
+                for (int i = 0; i < hosts.size(); i++) {
+                    ServiceInfo info = hosts.get(i).serviceInfo;
+                    Slog.v(TAG, "   " + info.packageName + "/" + info.name);
+                }
+            }
+            for (int i = 0; i < hosts.size(); i++) {
+                try {
+                    ServiceInfo info = hosts.get(i).serviceInfo;
+                    PackageInfo packInfo = mPackageManager.getPackageInfo(info.packageName, 0);
+                    if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_PRIVILEGED) != 0) {
+                        ComponentName svcName = new ComponentName(info.packageName, info.name);
+                        if (DEBUG) {
+                            Slog.i(TAG, "Binding to transport host " + svcName);
+                        }
+                        Intent intent = new Intent(transportServiceIntent);
+                        intent.setComponent(svcName);
+                        TransportConnection connection = new TransportConnection();
+                        mTransportConnections.add(connection);
+                        context.bindServiceAsUser(intent,
+                                connection, Context.BIND_AUTO_CREATE,
+                                UserHandle.OWNER);
+                    } else {
+                        Slog.w(TAG, "Transport package not privileged: " + info.packageName);
+                    }
+                } catch (Exception e) {
+                    Slog.e(TAG, "Problem resolving transport service: " + e.getMessage());
+                }
+            }
+        }
+
+        // Now that we know about valid backup participants, parse any
+        // leftover journal files into the pending backup set
+        parseLeftoverJournals();
+
+        // Power management
+        mWakelock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*");
+
+        // Start the backup passes going
+        setBackupEnabled(areEnabled);
+    }
+
+    private class RunBackupReceiver extends BroadcastReceiver {
+        public void onReceive(Context context, Intent intent) {
+            if (RUN_BACKUP_ACTION.equals(intent.getAction())) {
+                synchronized (mQueueLock) {
+                    if (mPendingInits.size() > 0) {
+                        // If there are pending init operations, we process those
+                        // and then settle into the usual periodic backup schedule.
+                        if (DEBUG) Slog.v(TAG, "Init pending at scheduled backup");
+                        try {
+                            mAlarmManager.cancel(mRunInitIntent);
+                            mRunInitIntent.send();
+                        } catch (PendingIntent.CanceledException ce) {
+                            Slog.e(TAG, "Run init intent cancelled");
+                            // can't really do more than bail here
+                        }
+                    } else {
+                        // Don't run backups now if we're disabled or not yet
+                        // fully set up.
+                        if (mEnabled && mProvisioned) {
+                            if (!mBackupRunning) {
+                                if (DEBUG) Slog.v(TAG, "Running a backup pass");
+
+                                // Acquire the wakelock and pass it to the backup thread.  it will
+                                // be released once backup concludes.
+                                mBackupRunning = true;
+                                mWakelock.acquire();
+
+                                Message msg = mBackupHandler.obtainMessage(MSG_RUN_BACKUP);
+                                mBackupHandler.sendMessage(msg);
+                            } else {
+                                Slog.i(TAG, "Backup time but one already running");
+                            }
+                        } else {
+                            Slog.w(TAG, "Backup pass but e=" + mEnabled + " p=" + mProvisioned);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private class RunInitializeReceiver extends BroadcastReceiver {
+        public void onReceive(Context context, Intent intent) {
+            if (RUN_INITIALIZE_ACTION.equals(intent.getAction())) {
+                synchronized (mQueueLock) {
+                    if (DEBUG) Slog.v(TAG, "Running a device init");
+
+                    // Acquire the wakelock and pass it to the init thread.  it will
+                    // be released once init concludes.
+                    mWakelock.acquire();
+
+                    Message msg = mBackupHandler.obtainMessage(MSG_RUN_INITIALIZE);
+                    mBackupHandler.sendMessage(msg);
+                }
+            }
+        }
+    }
+
+    private void initPackageTracking() {
+        if (DEBUG) Slog.v(TAG, "Initializing package tracking");
+
+        // Remember our ancestral dataset
+        mTokenFile = new File(mBaseStateDir, "ancestral");
+        try {
+            RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r");
+            int version = tf.readInt();
+            if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
+                mAncestralToken = tf.readLong();
+                mCurrentToken = tf.readLong();
+
+                int numPackages = tf.readInt();
+                if (numPackages >= 0) {
+                    mAncestralPackages = new HashSet<String>();
+                    for (int i = 0; i < numPackages; i++) {
+                        String pkgName = tf.readUTF();
+                        mAncestralPackages.add(pkgName);
+                    }
+                }
+            }
+            tf.close();
+        } catch (FileNotFoundException fnf) {
+            // Probably innocuous
+            Slog.v(TAG, "No ancestral data");
+        } catch (IOException e) {
+            Slog.w(TAG, "Unable to read token file", e);
+        }
+
+        // Keep a log of what apps we've ever backed up.  Because we might have
+        // rebooted in the middle of an operation that was removing something from
+        // this log, we sanity-check its contents here and reconstruct it.
+        mEverStored = new File(mBaseStateDir, "processed");
+        File tempProcessedFile = new File(mBaseStateDir, "processed.new");
+
+        // If we were in the middle of removing something from the ever-backed-up
+        // file, there might be a transient "processed.new" file still present.
+        // Ignore it -- we'll validate "processed" against the current package set.
+        if (tempProcessedFile.exists()) {
+            tempProcessedFile.delete();
+        }
+
+        // If there are previous contents, parse them out then start a new
+        // file to continue the recordkeeping.
+        if (mEverStored.exists()) {
+            RandomAccessFile temp = null;
+            RandomAccessFile in = null;
+
+            try {
+                temp = new RandomAccessFile(tempProcessedFile, "rws");
+                in = new RandomAccessFile(mEverStored, "r");
+
+                while (true) {
+                    PackageInfo info;
+                    String pkg = in.readUTF();
+                    try {
+                        info = mPackageManager.getPackageInfo(pkg, 0);
+                        mEverStoredApps.add(pkg);
+                        temp.writeUTF(pkg);
+                        if (MORE_DEBUG) Slog.v(TAG, "   + " + pkg);
+                    } catch (NameNotFoundException e) {
+                        // nope, this package was uninstalled; don't include it
+                        if (MORE_DEBUG) Slog.v(TAG, "   - " + pkg);
+                    }
+                }
+            } catch (EOFException e) {
+                // Once we've rewritten the backup history log, atomically replace the
+                // old one with the new one then reopen the file for continuing use.
+                if (!tempProcessedFile.renameTo(mEverStored)) {
+                    Slog.e(TAG, "Error renaming " + tempProcessedFile + " to " + mEverStored);
+                }
+            } catch (IOException e) {
+                Slog.e(TAG, "Error in processed file", e);
+            } finally {
+                try { if (temp != null) temp.close(); } catch (IOException e) {}
+                try { if (in != null) in.close(); } catch (IOException e) {}
+            }
+        }
+
+        // Register for broadcasts about package install, etc., so we can
+        // update the provider list.
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
+        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+        filter.addDataScheme("package");
+        mContext.registerReceiver(mBroadcastReceiver, filter);
+        // Register for events related to sdcard installation.
+        IntentFilter sdFilter = new IntentFilter();
+        sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
+        sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+        mContext.registerReceiver(mBroadcastReceiver, sdFilter);
+    }
+
+    private void parseLeftoverJournals() {
+        for (File f : mJournalDir.listFiles()) {
+            if (mJournal == null || f.compareTo(mJournal) != 0) {
+                // This isn't the current journal, so it must be a leftover.  Read
+                // out the package names mentioned there and schedule them for
+                // backup.
+                RandomAccessFile in = null;
+                try {
+                    Slog.i(TAG, "Found stale backup journal, scheduling");
+                    in = new RandomAccessFile(f, "r");
+                    while (true) {
+                        String packageName = in.readUTF();
+                        Slog.i(TAG, "  " + packageName);
+                        dataChangedImpl(packageName);
+                    }
+                } catch (EOFException e) {
+                    // no more data; we're done
+                } catch (Exception e) {
+                    Slog.e(TAG, "Can't read " + f, e);
+                } finally {
+                    // close/delete the file
+                    try { if (in != null) in.close(); } catch (IOException e) {}
+                    f.delete();
+                }
+            }
+        }
+    }
+
+    private SecretKey buildPasswordKey(String algorithm, String pw, byte[] salt, int rounds) {
+        return buildCharArrayKey(algorithm, pw.toCharArray(), salt, rounds);
+    }
+
+    private SecretKey buildCharArrayKey(String algorithm, char[] pwArray, byte[] salt, int rounds) {
+        try {
+            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
+            KeySpec ks = new PBEKeySpec(pwArray, salt, rounds, PBKDF2_KEY_SIZE);
+            return keyFactory.generateSecret(ks);
+        } catch (InvalidKeySpecException e) {
+            Slog.e(TAG, "Invalid key spec for PBKDF2!");
+        } catch (NoSuchAlgorithmException e) {
+            Slog.e(TAG, "PBKDF2 unavailable!");
+        }
+        return null;
+    }
+
+    private String buildPasswordHash(String algorithm, String pw, byte[] salt, int rounds) {
+        SecretKey key = buildPasswordKey(algorithm, pw, salt, rounds);
+        if (key != null) {
+            return byteArrayToHex(key.getEncoded());
+        }
+        return null;
+    }
+
+    private String byteArrayToHex(byte[] data) {
+        StringBuilder buf = new StringBuilder(data.length * 2);
+        for (int i = 0; i < data.length; i++) {
+            buf.append(Byte.toHexString(data[i], true));
+        }
+        return buf.toString();
+    }
+
+    private byte[] hexToByteArray(String digits) {
+        final int bytes = digits.length() / 2;
+        if (2*bytes != digits.length()) {
+            throw new IllegalArgumentException("Hex string must have an even number of digits");
+        }
+
+        byte[] result = new byte[bytes];
+        for (int i = 0; i < digits.length(); i += 2) {
+            result[i/2] = (byte) Integer.parseInt(digits.substring(i, i+2), 16);
+        }
+        return result;
+    }
+
+    private byte[] makeKeyChecksum(String algorithm, byte[] pwBytes, byte[] salt, int rounds) {
+        char[] mkAsChar = new char[pwBytes.length];
+        for (int i = 0; i < pwBytes.length; i++) {
+            mkAsChar[i] = (char) pwBytes[i];
+        }
+
+        Key checksum = buildCharArrayKey(algorithm, mkAsChar, salt, rounds);
+        return checksum.getEncoded();
+    }
+
+    // Used for generating random salts or passwords
+    private byte[] randomBytes(int bits) {
+        byte[] array = new byte[bits / 8];
+        mRng.nextBytes(array);
+        return array;
+    }
+
+    // Backup password management
+    boolean passwordMatchesSaved(String algorithm, String candidatePw, int rounds) {
+        // First, on an encrypted device we require matching the device pw
+        final boolean isEncrypted;
+        try {
+            isEncrypted = (mMountService.getEncryptionState() !=
+                    IMountService.ENCRYPTION_STATE_NONE);
+            if (isEncrypted) {
+                if (DEBUG) {
+                    Slog.i(TAG, "Device encrypted; verifying against device data pw");
+                }
+                // 0 means the password validated
+                // -2 means device not encrypted
+                // Any other result is either password failure or an error condition,
+                // so we refuse the match
+                final int result = mMountService.verifyEncryptionPassword(candidatePw);
+                if (result == 0) {
+                    if (MORE_DEBUG) Slog.d(TAG, "Pw verifies");
+                    return true;
+                } else if (result != -2) {
+                    if (MORE_DEBUG) Slog.d(TAG, "Pw mismatch");
+                    return false;
+                } else {
+                    // ...else the device is supposedly not encrypted.  HOWEVER, the
+                    // query about the encryption state said that the device *is*
+                    // encrypted, so ... we may have a problem.  Log it and refuse
+                    // the backup.
+                    Slog.e(TAG, "verified encryption state mismatch against query; no match allowed");
+                    return false;
+                }
+            }
+        } catch (Exception e) {
+            // Something went wrong talking to the mount service.  This is very bad;
+            // assume that we fail password validation.
+            return false;
+        }
+
+        if (mPasswordHash == null) {
+            // no current password case -- require that 'currentPw' be null or empty
+            if (candidatePw == null || "".equals(candidatePw)) {
+                return true;
+            } // else the non-empty candidate does not match the empty stored pw
+        } else {
+            // hash the stated current pw and compare to the stored one
+            if (candidatePw != null && candidatePw.length() > 0) {
+                String currentPwHash = buildPasswordHash(algorithm, candidatePw, mPasswordSalt, rounds);
+                if (mPasswordHash.equalsIgnoreCase(currentPwHash)) {
+                    // candidate hash matches the stored hash -- the password matches
+                    return true;
+                }
+            } // else the stored pw is nonempty but the candidate is empty; no match
+        }
+        return false;
+    }
+
+    @Override
+    public boolean setBackupPassword(String currentPw, String newPw) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "setBackupPassword");
+
+        // When processing v1 passwords we may need to try two different PBKDF2 checksum regimes
+        final boolean pbkdf2Fallback = (mPasswordVersion < BACKUP_PW_FILE_VERSION);
+
+        // If the supplied pw doesn't hash to the the saved one, fail.  The password
+        // might be caught in the legacy crypto mismatch; verify that too.
+        if (!passwordMatchesSaved(PBKDF_CURRENT, currentPw, PBKDF2_HASH_ROUNDS)
+                && !(pbkdf2Fallback && passwordMatchesSaved(PBKDF_FALLBACK,
+                        currentPw, PBKDF2_HASH_ROUNDS))) {
+            return false;
+        }
+
+        // Snap up to current on the pw file version
+        mPasswordVersion = BACKUP_PW_FILE_VERSION;
+        FileOutputStream pwFout = null;
+        DataOutputStream pwOut = null;
+        try {
+            pwFout = new FileOutputStream(mPasswordVersionFile);
+            pwOut = new DataOutputStream(pwFout);
+            pwOut.writeInt(mPasswordVersion);
+        } catch (IOException e) {
+            Slog.e(TAG, "Unable to write backup pw version; password not changed");
+            return false;
+        } finally {
+            try {
+                if (pwOut != null) pwOut.close();
+                if (pwFout != null) pwFout.close();
+            } catch (IOException e) {
+                Slog.w(TAG, "Unable to close pw version record");
+            }
+        }
+
+        // Clearing the password is okay
+        if (newPw == null || newPw.isEmpty()) {
+            if (mPasswordHashFile.exists()) {
+                if (!mPasswordHashFile.delete()) {
+                    // Unable to delete the old pw file, so fail
+                    Slog.e(TAG, "Unable to clear backup password");
+                    return false;
+                }
+            }
+            mPasswordHash = null;
+            mPasswordSalt = null;
+            return true;
+        }
+
+        try {
+            // Okay, build the hash of the new backup password
+            byte[] salt = randomBytes(PBKDF2_SALT_SIZE);
+            String newPwHash = buildPasswordHash(PBKDF_CURRENT, newPw, salt, PBKDF2_HASH_ROUNDS);
+
+            OutputStream pwf = null, buffer = null;
+            DataOutputStream out = null;
+            try {
+                pwf = new FileOutputStream(mPasswordHashFile);
+                buffer = new BufferedOutputStream(pwf);
+                out = new DataOutputStream(buffer);
+                // integer length of the salt array, followed by the salt,
+                // then the hex pw hash string
+                out.writeInt(salt.length);
+                out.write(salt);
+                out.writeUTF(newPwHash);
+                out.flush();
+                mPasswordHash = newPwHash;
+                mPasswordSalt = salt;
+                return true;
+            } finally {
+                if (out != null) out.close();
+                if (buffer != null) buffer.close();
+                if (pwf != null) pwf.close();
+            }
+        } catch (IOException e) {
+            Slog.e(TAG, "Unable to set backup password");
+        }
+        return false;
+    }
+
+    @Override
+    public boolean hasBackupPassword() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "hasBackupPassword");
+
+        try {
+            return (mMountService.getEncryptionState() != IMountService.ENCRYPTION_STATE_NONE)
+                || (mPasswordHash != null && mPasswordHash.length() > 0);
+        } catch (Exception e) {
+            // If we can't talk to the mount service we have a serious problem; fail
+            // "secure" i.e. assuming that we require a password
+            return true;
+        }
+    }
+
+    private boolean backupPasswordMatches(String currentPw) {
+        if (hasBackupPassword()) {
+            final boolean pbkdf2Fallback = (mPasswordVersion < BACKUP_PW_FILE_VERSION);
+            if (!passwordMatchesSaved(PBKDF_CURRENT, currentPw, PBKDF2_HASH_ROUNDS)
+                    && !(pbkdf2Fallback && passwordMatchesSaved(PBKDF_FALLBACK,
+                            currentPw, PBKDF2_HASH_ROUNDS))) {
+                if (DEBUG) Slog.w(TAG, "Backup password mismatch; aborting");
+                return false;
+            }
+        }
+        return true;
+    }
+
+    // Maintain persistent state around whether need to do an initialize operation.
+    // Must be called with the queue lock held.
+    void recordInitPendingLocked(boolean isPending, String transportName) {
+        if (DEBUG) Slog.i(TAG, "recordInitPendingLocked: " + isPending
+                + " on transport " + transportName);
+        mBackupHandler.removeMessages(MSG_RETRY_INIT);
+
+        try {
+            IBackupTransport transport = getTransport(transportName);
+            if (transport != null) {
+                String transportDirName = transport.transportDirName();
+                File stateDir = new File(mBaseStateDir, transportDirName);
+                File initPendingFile = new File(stateDir, INIT_SENTINEL_FILE_NAME);
+
+                if (isPending) {
+                    // We need an init before we can proceed with sending backup data.
+                    // Record that with an entry in our set of pending inits, as well as
+                    // journaling it via creation of a sentinel file.
+                    mPendingInits.add(transportName);
+                    try {
+                        (new FileOutputStream(initPendingFile)).close();
+                    } catch (IOException ioe) {
+                        // Something is badly wrong with our permissions; just try to move on
+                    }
+                } else {
+                    // No more initialization needed; wipe the journal and reset our state.
+                    initPendingFile.delete();
+                    mPendingInits.remove(transportName);
+                }
+                return; // done; don't fall through to the error case
+            }
+        } catch (RemoteException e) {
+            // transport threw when asked its name; fall through to the lookup-failed case
+        }
+
+        // The named transport doesn't exist or threw.  This operation is
+        // important, so we record the need for a an init and post a message
+        // to retry the init later.
+        if (isPending) {
+            mPendingInits.add(transportName);
+            mBackupHandler.sendMessageDelayed(
+                    mBackupHandler.obtainMessage(MSG_RETRY_INIT,
+                            (isPending ? 1 : 0),
+                            0,
+                            transportName),
+                    TRANSPORT_RETRY_INTERVAL);
+        }
+    }
+
+    // Reset all of our bookkeeping, in response to having been told that
+    // the backend data has been wiped [due to idle expiry, for example],
+    // so we must re-upload all saved settings.
+    void resetBackupState(File stateFileDir) {
+        synchronized (mQueueLock) {
+            // Wipe the "what we've ever backed up" tracking
+            mEverStoredApps.clear();
+            mEverStored.delete();
+
+            mCurrentToken = 0;
+            writeRestoreTokens();
+
+            // Remove all the state files
+            for (File sf : stateFileDir.listFiles()) {
+                // ... but don't touch the needs-init sentinel
+                if (!sf.getName().equals(INIT_SENTINEL_FILE_NAME)) {
+                    sf.delete();
+                }
+            }
+        }
+
+        // Enqueue a new backup of every participant
+        synchronized (mBackupParticipants) {
+            final int N = mBackupParticipants.size();
+            for (int i=0; i<N; i++) {
+                HashSet<String> participants = mBackupParticipants.valueAt(i);
+                if (participants != null) {
+                    for (String packageName : participants) {
+                        dataChangedImpl(packageName);
+                    }
+                }
+            }
+        }
+    }
+
+    // Add a transport to our set of available backends.  If 'transport' is null, this
+    // is an unregistration, and the transport's entry is removed from our bookkeeping.
+    private void registerTransport(String name, String component, IBackupTransport transport) {
+        synchronized (mTransports) {
+            if (DEBUG) Slog.v(TAG, "Registering transport "
+                    + component + "::" + name + " = " + transport);
+            if (transport != null) {
+                mTransports.put(name, transport);
+                mTransportNames.put(component, name);
+            } else {
+                mTransports.remove(mTransportNames.get(component));
+                mTransportNames.remove(component);
+                // Nothing further to do in the unregistration case
+                return;
+            }
+        }
+
+        // If the init sentinel file exists, we need to be sure to perform the init
+        // as soon as practical.  We also create the state directory at registration
+        // time to ensure it's present from the outset.
+        try {
+            String transportName = transport.transportDirName();
+            File stateDir = new File(mBaseStateDir, transportName);
+            stateDir.mkdirs();
+
+            File initSentinel = new File(stateDir, INIT_SENTINEL_FILE_NAME);
+            if (initSentinel.exists()) {
+                synchronized (mQueueLock) {
+                    mPendingInits.add(transportName);
+
+                    // TODO: pick a better starting time than now + 1 minute
+                    long delay = 1000 * 60; // one minute, in milliseconds
+                    mAlarmManager.set(AlarmManager.RTC_WAKEUP,
+                            System.currentTimeMillis() + delay, mRunInitIntent);
+                }
+            }
+        } catch (RemoteException e) {
+            // the transport threw when asked its file naming prefs; declare it invalid
+            Slog.e(TAG, "Unable to register transport as " + name);
+            mTransportNames.remove(component);
+            mTransports.remove(name);
+        }
+    }
+
+    // ----- Track installation/removal of packages -----
+    BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            if (DEBUG) Slog.d(TAG, "Received broadcast " + intent);
+
+            String action = intent.getAction();
+            boolean replacing = false;
+            boolean added = false;
+            Bundle extras = intent.getExtras();
+            String pkgList[] = null;
+            if (Intent.ACTION_PACKAGE_ADDED.equals(action) ||
+                    Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
+                Uri uri = intent.getData();
+                if (uri == null) {
+                    return;
+                }
+                String pkgName = uri.getSchemeSpecificPart();
+                if (pkgName != null) {
+                    pkgList = new String[] { pkgName };
+                }
+                added = Intent.ACTION_PACKAGE_ADDED.equals(action);
+                replacing = extras.getBoolean(Intent.EXTRA_REPLACING, false);
+            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
+                added = true;
+                pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
+                added = false;
+                pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+            }
+
+            if (pkgList == null || pkgList.length == 0) {
+                return;
+            }
+
+            final int uid = extras.getInt(Intent.EXTRA_UID);
+            if (added) {
+                synchronized (mBackupParticipants) {
+                    if (replacing) {
+                        // This is the package-replaced case; we just remove the entry
+                        // under the old uid and fall through to re-add.
+                        removePackageParticipantsLocked(pkgList, uid);
+                    }
+                    addPackageParticipantsLocked(pkgList);
+                }
+            } else {
+                if (replacing) {
+                    // The package is being updated.  We'll receive a PACKAGE_ADDED shortly.
+                } else {
+                    synchronized (mBackupParticipants) {
+                        removePackageParticipantsLocked(pkgList, uid);
+                    }
+                }
+            }
+        }
+    };
+
+    // ----- Track connection to transports service -----
+    class TransportConnection implements ServiceConnection {
+        @Override
+        public void onServiceConnected(ComponentName component, IBinder service) {
+            if (DEBUG) Slog.v(TAG, "Connected to transport " + component);
+            try {
+                IBackupTransport transport = IBackupTransport.Stub.asInterface(service);
+                registerTransport(transport.name(), component.flattenToShortString(), transport);
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Unable to register transport " + component);
+            }
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName component) {
+            if (DEBUG) Slog.v(TAG, "Disconnected from transport " + component);
+            registerTransport(null, component.flattenToShortString(), null);
+        }
+    };
+
+    // Add the backup agents in the given packages to our set of known backup participants.
+    // If 'packageNames' is null, adds all backup agents in the whole system.
+    void addPackageParticipantsLocked(String[] packageNames) {
+        // Look for apps that define the android:backupAgent attribute
+        List<PackageInfo> targetApps = allAgentPackages();
+        if (packageNames != null) {
+            if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: #" + packageNames.length);
+            for (String packageName : packageNames) {
+                addPackageParticipantsLockedInner(packageName, targetApps);
+            }
+        } else {
+            if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: all");
+            addPackageParticipantsLockedInner(null, targetApps);
+        }
+    }
+
+    private void addPackageParticipantsLockedInner(String packageName,
+            List<PackageInfo> targetPkgs) {
+        if (MORE_DEBUG) {
+            Slog.v(TAG, "Examining " + packageName + " for backup agent");
+        }
+
+        for (PackageInfo pkg : targetPkgs) {
+            if (packageName == null || pkg.packageName.equals(packageName)) {
+                int uid = pkg.applicationInfo.uid;
+                HashSet<String> set = mBackupParticipants.get(uid);
+                if (set == null) {
+                    set = new HashSet<String>();
+                    mBackupParticipants.put(uid, set);
+                }
+                set.add(pkg.packageName);
+                if (MORE_DEBUG) Slog.v(TAG, "Agent found; added");
+
+                // Schedule a backup for it on general principles
+                if (DEBUG) Slog.i(TAG, "Scheduling backup for new app " + pkg.packageName);
+                dataChangedImpl(pkg.packageName);
+            }
+        }
+    }
+
+    // Remove the given packages' entries from our known active set.
+    void removePackageParticipantsLocked(String[] packageNames, int oldUid) {
+        if (packageNames == null) {
+            Slog.w(TAG, "removePackageParticipants with null list");
+            return;
+        }
+
+        if (DEBUG) Slog.v(TAG, "removePackageParticipantsLocked: uid=" + oldUid
+                + " #" + packageNames.length);
+        for (String pkg : packageNames) {
+            // Known previous UID, so we know which package set to check
+            HashSet<String> set = mBackupParticipants.get(oldUid);
+            if (set != null && set.contains(pkg)) {
+                removePackageFromSetLocked(set, pkg);
+                if (set.isEmpty()) {
+                    if (MORE_DEBUG) Slog.v(TAG, "  last one of this uid; purging set");
+                    mBackupParticipants.remove(oldUid);
+                }
+            }
+        }
+    }
+
+    private void removePackageFromSetLocked(final HashSet<String> set,
+            final String packageName) {
+        if (set.contains(packageName)) {
+            // Found it.  Remove this one package from the bookkeeping, and
+            // if it's the last participating app under this uid we drop the
+            // (now-empty) set as well.
+            // Note that we deliberately leave it 'known' in the "ever backed up"
+            // bookkeeping so that its current-dataset data will be retrieved
+            // if the app is subsequently reinstalled
+            if (MORE_DEBUG) Slog.v(TAG, "  removing participant " + packageName);
+            set.remove(packageName);
+            mPendingBackups.remove(packageName);
+        }
+    }
+
+    // Returns the set of all applications that define an android:backupAgent attribute
+    List<PackageInfo> allAgentPackages() {
+        // !!! TODO: cache this and regenerate only when necessary
+        int flags = PackageManager.GET_SIGNATURES;
+        List<PackageInfo> packages = mPackageManager.getInstalledPackages(flags);
+        int N = packages.size();
+        for (int a = N-1; a >= 0; a--) {
+            PackageInfo pkg = packages.get(a);
+            try {
+                ApplicationInfo app = pkg.applicationInfo;
+                if (((app.flags&ApplicationInfo.FLAG_ALLOW_BACKUP) == 0)
+                        || app.backupAgentName == null) {
+                    packages.remove(a);
+                }
+                else {
+                    // we will need the shared library path, so look that up and store it here
+                    app = mPackageManager.getApplicationInfo(pkg.packageName,
+                            PackageManager.GET_SHARED_LIBRARY_FILES);
+                    pkg.applicationInfo.sharedLibraryFiles = app.sharedLibraryFiles;
+                }
+            } catch (NameNotFoundException e) {
+                packages.remove(a);
+            }
+        }
+        return packages;
+    }
+
+    // Called from the backup task: record that the given app has been successfully
+    // backed up at least once
+    void logBackupComplete(String packageName) {
+        if (packageName.equals(PACKAGE_MANAGER_SENTINEL)) return;
+
+        synchronized (mEverStoredApps) {
+            if (!mEverStoredApps.add(packageName)) return;
+
+            RandomAccessFile out = null;
+            try {
+                out = new RandomAccessFile(mEverStored, "rws");
+                out.seek(out.length());
+                out.writeUTF(packageName);
+            } catch (IOException e) {
+                Slog.e(TAG, "Can't log backup of " + packageName + " to " + mEverStored);
+            } finally {
+                try { if (out != null) out.close(); } catch (IOException e) {}
+            }
+        }
+    }
+
+    // Remove our awareness of having ever backed up the given package
+    void removeEverBackedUp(String packageName) {
+        if (DEBUG) Slog.v(TAG, "Removing backed-up knowledge of " + packageName);
+        if (MORE_DEBUG) Slog.v(TAG, "New set:");
+
+        synchronized (mEverStoredApps) {
+            // Rewrite the file and rename to overwrite.  If we reboot in the middle,
+            // we'll recognize on initialization time that the package no longer
+            // exists and fix it up then.
+            File tempKnownFile = new File(mBaseStateDir, "processed.new");
+            RandomAccessFile known = null;
+            try {
+                known = new RandomAccessFile(tempKnownFile, "rws");
+                mEverStoredApps.remove(packageName);
+                for (String s : mEverStoredApps) {
+                    known.writeUTF(s);
+                    if (MORE_DEBUG) Slog.v(TAG, "    " + s);
+                }
+                known.close();
+                known = null;
+                if (!tempKnownFile.renameTo(mEverStored)) {
+                    throw new IOException("Can't rename " + tempKnownFile + " to " + mEverStored);
+                }
+            } catch (IOException e) {
+                // Bad: we couldn't create the new copy.  For safety's sake we
+                // abandon the whole process and remove all what's-backed-up
+                // state entirely, meaning we'll force a backup pass for every
+                // participant on the next boot or [re]install.
+                Slog.w(TAG, "Error rewriting " + mEverStored, e);
+                mEverStoredApps.clear();
+                tempKnownFile.delete();
+                mEverStored.delete();
+            } finally {
+                try { if (known != null) known.close(); } catch (IOException e) {}
+            }
+        }
+    }
+
+    // Persistently record the current and ancestral backup tokens as well
+    // as the set of packages with data [supposedly] available in the
+    // ancestral dataset.
+    void writeRestoreTokens() {
+        try {
+            RandomAccessFile af = new RandomAccessFile(mTokenFile, "rwd");
+
+            // First, the version number of this record, for futureproofing
+            af.writeInt(CURRENT_ANCESTRAL_RECORD_VERSION);
+
+            // Write the ancestral and current tokens
+            af.writeLong(mAncestralToken);
+            af.writeLong(mCurrentToken);
+
+            // Now write the set of ancestral packages
+            if (mAncestralPackages == null) {
+                af.writeInt(-1);
+            } else {
+                af.writeInt(mAncestralPackages.size());
+                if (DEBUG) Slog.v(TAG, "Ancestral packages:  " + mAncestralPackages.size());
+                for (String pkgName : mAncestralPackages) {
+                    af.writeUTF(pkgName);
+                    if (MORE_DEBUG) Slog.v(TAG, "   " + pkgName);
+                }
+            }
+            af.close();
+        } catch (IOException e) {
+            Slog.w(TAG, "Unable to write token file:", e);
+        }
+    }
+
+    // Return the given transport
+    private IBackupTransport getTransport(String transportName) {
+        synchronized (mTransports) {
+            IBackupTransport transport = mTransports.get(transportName);
+            if (transport == null) {
+                Slog.w(TAG, "Requested unavailable transport: " + transportName);
+            }
+            return transport;
+        }
+    }
+
+    // fire off a backup agent, blocking until it attaches or times out
+    IBackupAgent bindToAgentSynchronous(ApplicationInfo app, int mode) {
+        IBackupAgent agent = null;
+        synchronized(mAgentConnectLock) {
+            mConnecting = true;
+            mConnectedAgent = null;
+            try {
+                if (mActivityManager.bindBackupAgent(app, mode)) {
+                    Slog.d(TAG, "awaiting agent for " + app);
+
+                    // success; wait for the agent to arrive
+                    // only wait 10 seconds for the bind to happen
+                    long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
+                    while (mConnecting && mConnectedAgent == null
+                            && (System.currentTimeMillis() < timeoutMark)) {
+                        try {
+                            mAgentConnectLock.wait(5000);
+                        } catch (InterruptedException e) {
+                            // just bail
+                            if (DEBUG) Slog.w(TAG, "Interrupted: " + e);
+                            mActivityManager.clearPendingBackup();
+                            return null;
+                        }
+                    }
+
+                    // if we timed out with no connect, abort and move on
+                    if (mConnecting == true) {
+                        Slog.w(TAG, "Timeout waiting for agent " + app);
+                        mActivityManager.clearPendingBackup();
+                        return null;
+                    }
+                    if (DEBUG) Slog.i(TAG, "got agent " + mConnectedAgent);
+                    agent = mConnectedAgent;
+                }
+            } catch (RemoteException e) {
+                // can't happen - ActivityManager is local
+            }
+        }
+        return agent;
+    }
+
+    // clear an application's data, blocking until the operation completes or times out
+    void clearApplicationDataSynchronous(String packageName) {
+        // Don't wipe packages marked allowClearUserData=false
+        try {
+            PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
+            if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) == 0) {
+                if (MORE_DEBUG) Slog.i(TAG, "allowClearUserData=false so not wiping "
+                        + packageName);
+                return;
+            }
+        } catch (NameNotFoundException e) {
+            Slog.w(TAG, "Tried to clear data for " + packageName + " but not found");
+            return;
+        }
+
+        ClearDataObserver observer = new ClearDataObserver();
+
+        synchronized(mClearDataLock) {
+            mClearingData = true;
+            try {
+                mActivityManager.clearApplicationUserData(packageName, observer, 0);
+            } catch (RemoteException e) {
+                // can't happen because the activity manager is in this process
+            }
+
+            // only wait 10 seconds for the clear data to happen
+            long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
+            while (mClearingData && (System.currentTimeMillis() < timeoutMark)) {
+                try {
+                    mClearDataLock.wait(5000);
+                } catch (InterruptedException e) {
+                    // won't happen, but still.
+                    mClearingData = false;
+                }
+            }
+        }
+    }
+
+    class ClearDataObserver extends IPackageDataObserver.Stub {
+        public void onRemoveCompleted(String packageName, boolean succeeded) {
+            synchronized(mClearDataLock) {
+                mClearingData = false;
+                mClearDataLock.notifyAll();
+            }
+        }
+    }
+
+    // Get the restore-set token for the best-available restore set for this package:
+    // the active set if possible, else the ancestral one.  Returns zero if none available.
+    long getAvailableRestoreToken(String packageName) {
+        long token = mAncestralToken;
+        synchronized (mQueueLock) {
+            if (mEverStoredApps.contains(packageName)) {
+                token = mCurrentToken;
+            }
+        }
+        return token;
+    }
+
+    // -----
+    // Interface and methods used by the asynchronous-with-timeout backup/restore operations
+
+    interface BackupRestoreTask {
+        // Execute one tick of whatever state machine the task implements
+        void execute();
+
+        // An operation that wanted a callback has completed
+        void operationComplete();
+
+        // An operation that wanted a callback has timed out
+        void handleTimeout();
+    }
+
+    void prepareOperationTimeout(int token, long interval, BackupRestoreTask callback) {
+        if (MORE_DEBUG) Slog.v(TAG, "starting timeout: token=" + Integer.toHexString(token)
+                + " interval=" + interval);
+        synchronized (mCurrentOpLock) {
+            mCurrentOperations.put(token, new Operation(OP_PENDING, callback));
+
+            Message msg = mBackupHandler.obtainMessage(MSG_TIMEOUT, token, 0, callback);
+            mBackupHandler.sendMessageDelayed(msg, interval);
+        }
+    }
+
+    // synchronous waiter case
+    boolean waitUntilOperationComplete(int token) {
+        if (MORE_DEBUG) Slog.i(TAG, "Blocking until operation complete for "
+                + Integer.toHexString(token));
+        int finalState = OP_PENDING;
+        Operation op = null;
+        synchronized (mCurrentOpLock) {
+            while (true) {
+                op = mCurrentOperations.get(token);
+                if (op == null) {
+                    // mysterious disappearance: treat as success with no callback
+                    break;
+                } else {
+                    if (op.state == OP_PENDING) {
+                        try {
+                            mCurrentOpLock.wait();
+                        } catch (InterruptedException e) {}
+                        // When the wait is notified we loop around and recheck the current state
+                    } else {
+                        // No longer pending; we're done
+                        finalState = op.state;
+                        break;
+                    }
+                }
+            }
+        }
+
+        mBackupHandler.removeMessages(MSG_TIMEOUT);
+        if (MORE_DEBUG) Slog.v(TAG, "operation " + Integer.toHexString(token)
+                + " complete: finalState=" + finalState);
+        return finalState == OP_ACKNOWLEDGED;
+    }
+
+    void handleTimeout(int token, Object obj) {
+        // Notify any synchronous waiters
+        Operation op = null;
+        synchronized (mCurrentOpLock) {
+            op = mCurrentOperations.get(token);
+            if (MORE_DEBUG) {
+                if (op == null) Slog.w(TAG, "Timeout of token " + Integer.toHexString(token)
+                        + " but no op found");
+            }
+            int state = (op != null) ? op.state : OP_TIMEOUT;
+            if (state == OP_PENDING) {
+                if (DEBUG) Slog.v(TAG, "TIMEOUT: token=" + Integer.toHexString(token));
+                op.state = OP_TIMEOUT;
+                mCurrentOperations.put(token, op);
+            }
+            mCurrentOpLock.notifyAll();
+        }
+
+        // If there's a TimeoutHandler for this event, call it
+        if (op != null && op.callback != null) {
+            op.callback.handleTimeout();
+        }
+    }
+
+    // ----- Back up a set of applications via a worker thread -----
+
+    enum BackupState {
+        INITIAL,
+        RUNNING_QUEUE,
+        FINAL
+    }
+
+    class PerformBackupTask implements BackupRestoreTask {
+        private static final String TAG = "PerformBackupTask";
+
+        IBackupTransport mTransport;
+        ArrayList<BackupRequest> mQueue;
+        ArrayList<BackupRequest> mOriginalQueue;
+        File mStateDir;
+        File mJournal;
+        BackupState mCurrentState;
+
+        // carried information about the current in-flight operation
+        PackageInfo mCurrentPackage;
+        File mSavedStateName;
+        File mBackupDataName;
+        File mNewStateName;
+        ParcelFileDescriptor mSavedState;
+        ParcelFileDescriptor mBackupData;
+        ParcelFileDescriptor mNewState;
+        int mStatus;
+        boolean mFinished;
+
+        public PerformBackupTask(IBackupTransport transport, String dirName,
+                ArrayList<BackupRequest> queue, File journal) {
+            mTransport = transport;
+            mOriginalQueue = queue;
+            mJournal = journal;
+
+            mStateDir = new File(mBaseStateDir, dirName);
+
+            mCurrentState = BackupState.INITIAL;
+            mFinished = false;
+
+            addBackupTrace("STATE => INITIAL");
+        }
+
+        // Main entry point: perform one chunk of work, updating the state as appropriate
+        // and reposting the next chunk to the primary backup handler thread.
+        @Override
+        public void execute() {
+            switch (mCurrentState) {
+                case INITIAL:
+                    beginBackup();
+                    break;
+
+                case RUNNING_QUEUE:
+                    invokeNextAgent();
+                    break;
+
+                case FINAL:
+                    if (!mFinished) finalizeBackup();
+                    else {
+                        Slog.e(TAG, "Duplicate finish");
+                    }
+                    mFinished = true;
+                    break;
+            }
+        }
+
+        // We're starting a backup pass.  Initialize the transport and send
+        // the PM metadata blob if we haven't already.
+        void beginBackup() {
+            if (DEBUG_BACKUP_TRACE) {
+                clearBackupTrace();
+                StringBuilder b = new StringBuilder(256);
+                b.append("beginBackup: [");
+                for (BackupRequest req : mOriginalQueue) {
+                    b.append(' ');
+                    b.append(req.packageName);
+                }
+                b.append(" ]");
+                addBackupTrace(b.toString());
+            }
+
+            mStatus = BackupConstants.TRANSPORT_OK;
+
+            // Sanity check: if the queue is empty we have no work to do.
+            if (mOriginalQueue.isEmpty()) {
+                Slog.w(TAG, "Backup begun with an empty queue - nothing to do.");
+                addBackupTrace("queue empty at begin");
+                executeNextState(BackupState.FINAL);
+                return;
+            }
+
+            // We need to retain the original queue contents in case of transport
+            // failure, but we want a working copy that we can manipulate along
+            // the way.
+            mQueue = (ArrayList<BackupRequest>) mOriginalQueue.clone();
+
+            if (DEBUG) Slog.v(TAG, "Beginning backup of " + mQueue.size() + " targets");
+
+            File pmState = new File(mStateDir, PACKAGE_MANAGER_SENTINEL);
+            try {
+                final String transportName = mTransport.transportDirName();
+                EventLog.writeEvent(EventLogTags.BACKUP_START, transportName);
+
+                // If we haven't stored package manager metadata yet, we must init the transport.
+                if (mStatus == BackupConstants.TRANSPORT_OK && pmState.length() <= 0) {
+                    Slog.i(TAG, "Initializing (wiping) backup state and transport storage");
+                    addBackupTrace("initializing transport " + transportName);
+                    resetBackupState(mStateDir);  // Just to make sure.
+                    mStatus = mTransport.initializeDevice();
+
+                    addBackupTrace("transport.initializeDevice() == " + mStatus);
+                    if (mStatus == BackupConstants.TRANSPORT_OK) {
+                        EventLog.writeEvent(EventLogTags.BACKUP_INITIALIZE);
+                    } else {
+                        EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE, "(initialize)");
+                        Slog.e(TAG, "Transport error in initializeDevice()");
+                    }
+                }
+
+                // The package manager doesn't have a proper <application> etc, but since
+                // it's running here in the system process we can just set up its agent
+                // directly and use a synthetic BackupRequest.  We always run this pass
+                // because it's cheap and this way we guarantee that we don't get out of
+                // step even if we're selecting among various transports at run time.
+                if (mStatus == BackupConstants.TRANSPORT_OK) {
+                    PackageManagerBackupAgent pmAgent = new PackageManagerBackupAgent(
+                            mPackageManager, allAgentPackages());
+                    mStatus = invokeAgentForBackup(PACKAGE_MANAGER_SENTINEL,
+                            IBackupAgent.Stub.asInterface(pmAgent.onBind()), mTransport);
+                    addBackupTrace("PMBA invoke: " + mStatus);
+                }
+
+                if (mStatus == BackupConstants.TRANSPORT_NOT_INITIALIZED) {
+                    // The backend reports that our dataset has been wiped.  Note this in
+                    // the event log; the no-success code below will reset the backup
+                    // state as well.
+                    EventLog.writeEvent(EventLogTags.BACKUP_RESET, mTransport.transportDirName());
+                }
+            } catch (Exception e) {
+                Slog.e(TAG, "Error in backup thread", e);
+                addBackupTrace("Exception in backup thread: " + e);
+                mStatus = BackupConstants.TRANSPORT_ERROR;
+            } finally {
+                // If we've succeeded so far, invokeAgentForBackup() will have run the PM
+                // metadata and its completion/timeout callback will continue the state
+                // machine chain.  If it failed that won't happen; we handle that now.
+                addBackupTrace("exiting prelim: " + mStatus);
+                if (mStatus != BackupConstants.TRANSPORT_OK) {
+                    // if things went wrong at this point, we need to
+                    // restage everything and try again later.
+                    resetBackupState(mStateDir);  // Just to make sure.
+                    executeNextState(BackupState.FINAL);
+                }
+            }
+        }
+
+        // Transport has been initialized and the PM metadata submitted successfully
+        // if that was warranted.  Now we process the single next thing in the queue.
+        void invokeNextAgent() {
+            mStatus = BackupConstants.TRANSPORT_OK;
+            addBackupTrace("invoke q=" + mQueue.size());
+
+            // Sanity check that we have work to do.  If not, skip to the end where
+            // we reestablish the wakelock invariants etc.
+            if (mQueue.isEmpty()) {
+                if (DEBUG) Slog.i(TAG, "queue now empty");
+                executeNextState(BackupState.FINAL);
+                return;
+            }
+
+            // pop the entry we're going to process on this step
+            BackupRequest request = mQueue.get(0);
+            mQueue.remove(0);
+
+            Slog.d(TAG, "starting agent for backup of " + request);
+            addBackupTrace("launch agent for " + request.packageName);
+
+            // Verify that the requested app exists; it might be something that
+            // requested a backup but was then uninstalled.  The request was
+            // journalled and rather than tamper with the journal it's safer
+            // to sanity-check here.  This also gives us the classname of the
+            // package's backup agent.
+            try {
+                mCurrentPackage = mPackageManager.getPackageInfo(request.packageName,
+                        PackageManager.GET_SIGNATURES);
+                if (mCurrentPackage.applicationInfo.backupAgentName == null) {
+                    // The manifest has changed but we had a stale backup request pending.
+                    // This won't happen again because the app won't be requesting further
+                    // backups.
+                    Slog.i(TAG, "Package " + request.packageName
+                            + " no longer supports backup; skipping");
+                    addBackupTrace("skipping - no agent, completion is noop");
+                    executeNextState(BackupState.RUNNING_QUEUE);
+                    return;
+                }
+
+                if ((mCurrentPackage.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
+                    // The app has been force-stopped or cleared or just installed,
+                    // and not yet launched out of that state, so just as it won't
+                    // receive broadcasts, we won't run it for backup.
+                    addBackupTrace("skipping - stopped");
+                    executeNextState(BackupState.RUNNING_QUEUE);
+                    return;
+                }
+
+                IBackupAgent agent = null;
+                try {
+                    mWakelock.setWorkSource(new WorkSource(mCurrentPackage.applicationInfo.uid));
+                    agent = bindToAgentSynchronous(mCurrentPackage.applicationInfo,
+                            IApplicationThread.BACKUP_MODE_INCREMENTAL);
+                    addBackupTrace("agent bound; a? = " + (agent != null));
+                    if (agent != null) {
+                        mStatus = invokeAgentForBackup(request.packageName, agent, mTransport);
+                        // at this point we'll either get a completion callback from the
+                        // agent, or a timeout message on the main handler.  either way, we're
+                        // done here as long as we're successful so far.
+                    } else {
+                        // Timeout waiting for the agent
+                        mStatus = BackupConstants.AGENT_ERROR;
+                    }
+                } catch (SecurityException ex) {
+                    // Try for the next one.
+                    Slog.d(TAG, "error in bind/backup", ex);
+                    mStatus = BackupConstants.AGENT_ERROR;
+                            addBackupTrace("agent SE");
+                }
+            } catch (NameNotFoundException e) {
+                Slog.d(TAG, "Package does not exist; skipping");
+                addBackupTrace("no such package");
+                mStatus = BackupConstants.AGENT_UNKNOWN;
+            } finally {
+                mWakelock.setWorkSource(null);
+
+                // If there was an agent error, no timeout/completion handling will occur.
+                // That means we need to direct to the next state ourselves.
+                if (mStatus != BackupConstants.TRANSPORT_OK) {
+                    BackupState nextState = BackupState.RUNNING_QUEUE;
+
+                    // An agent-level failure means we reenqueue this one agent for
+                    // a later retry, but otherwise proceed normally.
+                    if (mStatus == BackupConstants.AGENT_ERROR) {
+                        if (MORE_DEBUG) Slog.i(TAG, "Agent failure for " + request.packageName
+                                + " - restaging");
+                        dataChangedImpl(request.packageName);
+                        mStatus = BackupConstants.TRANSPORT_OK;
+                        if (mQueue.isEmpty()) nextState = BackupState.FINAL;
+                    } else if (mStatus == BackupConstants.AGENT_UNKNOWN) {
+                        // Failed lookup of the app, so we couldn't bring up an agent, but
+                        // we're otherwise fine.  Just drop it and go on to the next as usual.
+                        mStatus = BackupConstants.TRANSPORT_OK;
+                    } else {
+                        // Transport-level failure means we reenqueue everything
+                        revertAndEndBackup();
+                        nextState = BackupState.FINAL;
+                    }
+
+                    executeNextState(nextState);
+                } else {
+                    addBackupTrace("expecting completion/timeout callback");
+                }
+            }
+        }
+
+        void finalizeBackup() {
+            addBackupTrace("finishing");
+
+            // Either backup was successful, in which case we of course do not need
+            // this pass's journal any more; or it failed, in which case we just
+            // re-enqueued all of these packages in the current active journal.
+            // Either way, we no longer need this pass's journal.
+            if (mJournal != null && !mJournal.delete()) {
+                Slog.e(TAG, "Unable to remove backup journal file " + mJournal);
+            }
+
+            // If everything actually went through and this is the first time we've
+            // done a backup, we can now record what the current backup dataset token
+            // is.
+            if ((mCurrentToken == 0) && (mStatus == BackupConstants.TRANSPORT_OK)) {
+                addBackupTrace("success; recording token");
+                try {
+                    mCurrentToken = mTransport.getCurrentRestoreSet();
+                    writeRestoreTokens();
+                } catch (RemoteException e) {
+                    // nothing for it at this point, unfortunately, but this will be
+                    // recorded the next time we fully succeed.
+                    addBackupTrace("transport threw returning token");
+                }
+            }
+
+            // Set up the next backup pass - at this point we can set mBackupRunning
+            // to false to allow another pass to fire, because we're done with the
+            // state machine sequence and the wakelock is refcounted.
+            synchronized (mQueueLock) {
+                mBackupRunning = false;
+                if (mStatus == BackupConstants.TRANSPORT_NOT_INITIALIZED) {
+                    // Make sure we back up everything and perform the one-time init
+                    clearMetadata();
+                    if (DEBUG) Slog.d(TAG, "Server requires init; rerunning");
+                    addBackupTrace("init required; rerunning");
+                    backupNow();
+                }
+            }
+
+            // Only once we're entirely finished do we release the wakelock
+            clearBackupTrace();
+            Slog.i(TAG, "Backup pass finished.");
+            mWakelock.release();
+        }
+
+        // Remove the PM metadata state. This will generate an init on the next pass.
+        void clearMetadata() {
+            final File pmState = new File(mStateDir, PACKAGE_MANAGER_SENTINEL);
+            if (pmState.exists()) pmState.delete();
+        }
+
+        // Invoke an agent's doBackup() and start a timeout message spinning on the main
+        // handler in case it doesn't get back to us.
+        int invokeAgentForBackup(String packageName, IBackupAgent agent,
+                IBackupTransport transport) {
+            if (DEBUG) Slog.d(TAG, "invokeAgentForBackup on " + packageName);
+            addBackupTrace("invoking " + packageName);
+
+            mSavedStateName = new File(mStateDir, packageName);
+            mBackupDataName = new File(mDataDir, packageName + ".data");
+            mNewStateName = new File(mStateDir, packageName + ".new");
+
+            mSavedState = null;
+            mBackupData = null;
+            mNewState = null;
+
+            final int token = generateToken();
+            try {
+                // Look up the package info & signatures.  This is first so that if it
+                // throws an exception, there's no file setup yet that would need to
+                // be unraveled.
+                if (packageName.equals(PACKAGE_MANAGER_SENTINEL)) {
+                    // The metadata 'package' is synthetic; construct one and make
+                    // sure our global state is pointed at it
+                    mCurrentPackage = new PackageInfo();
+                    mCurrentPackage.packageName = packageName;
+                }
+
+                // In a full backup, we pass a null ParcelFileDescriptor as
+                // the saved-state "file". This is by definition an incremental,
+                // so we build a saved state file to pass.
+                mSavedState = ParcelFileDescriptor.open(mSavedStateName,
+                        ParcelFileDescriptor.MODE_READ_ONLY |
+                        ParcelFileDescriptor.MODE_CREATE);  // Make an empty file if necessary
+
+                mBackupData = ParcelFileDescriptor.open(mBackupDataName,
+                        ParcelFileDescriptor.MODE_READ_WRITE |
+                        ParcelFileDescriptor.MODE_CREATE |
+                        ParcelFileDescriptor.MODE_TRUNCATE);
+
+                if (!SELinux.restorecon(mBackupDataName)) {
+                    Slog.e(TAG, "SELinux restorecon failed on " + mBackupDataName);
+                }
+
+                mNewState = ParcelFileDescriptor.open(mNewStateName,
+                        ParcelFileDescriptor.MODE_READ_WRITE |
+                        ParcelFileDescriptor.MODE_CREATE |
+                        ParcelFileDescriptor.MODE_TRUNCATE);
+
+                // Initiate the target's backup pass
+                addBackupTrace("setting timeout");
+                prepareOperationTimeout(token, TIMEOUT_BACKUP_INTERVAL, this);
+                addBackupTrace("calling agent doBackup()");
+                agent.doBackup(mSavedState, mBackupData, mNewState, token, mBackupManagerBinder);
+            } catch (Exception e) {
+                Slog.e(TAG, "Error invoking for backup on " + packageName);
+                addBackupTrace("exception: " + e);
+                EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, packageName,
+                        e.toString());
+                agentErrorCleanup();
+                return BackupConstants.AGENT_ERROR;
+            }
+
+            // At this point the agent is off and running.  The next thing to happen will
+            // either be a callback from the agent, at which point we'll process its data
+            // for transport, or a timeout.  Either way the next phase will happen in
+            // response to the TimeoutHandler interface callbacks.
+            addBackupTrace("invoke success");
+            return BackupConstants.TRANSPORT_OK;
+        }
+
+        @Override
+        public void operationComplete() {
+            // Okay, the agent successfully reported back to us.  Spin the data off to the
+            // transport and proceed with the next stage.
+            if (MORE_DEBUG) Slog.v(TAG, "operationComplete(): sending data to transport for "
+                    + mCurrentPackage.packageName);
+            mBackupHandler.removeMessages(MSG_TIMEOUT);
+            clearAgentState();
+            addBackupTrace("operation complete");
+
+            ParcelFileDescriptor backupData = null;
+            mStatus = BackupConstants.TRANSPORT_OK;
+            try {
+                int size = (int) mBackupDataName.length();
+                if (size > 0) {
+                    if (mStatus == BackupConstants.TRANSPORT_OK) {
+                        backupData = ParcelFileDescriptor.open(mBackupDataName,
+                                ParcelFileDescriptor.MODE_READ_ONLY);
+                        addBackupTrace("sending data to transport");
+                        mStatus = mTransport.performBackup(mCurrentPackage, backupData);
+                    }
+
+                    // TODO - We call finishBackup() for each application backed up, because
+                    // we need to know now whether it succeeded or failed.  Instead, we should
+                    // hold off on finishBackup() until the end, which implies holding off on
+                    // renaming *all* the output state files (see below) until that happens.
+
+                    addBackupTrace("data delivered: " + mStatus);
+                    if (mStatus == BackupConstants.TRANSPORT_OK) {
+                        addBackupTrace("finishing op on transport");
+                        mStatus = mTransport.finishBackup();
+                        addBackupTrace("finished: " + mStatus);
+                    }
+                } else {
+                    if (DEBUG) Slog.i(TAG, "no backup data written; not calling transport");
+                    addBackupTrace("no data to send");
+                }
+
+                // After successful transport, delete the now-stale data
+                // and juggle the files so that next time we supply the agent
+                // with the new state file it just created.
+                if (mStatus == BackupConstants.TRANSPORT_OK) {
+                    mBackupDataName.delete();
+                    mNewStateName.renameTo(mSavedStateName);
+                    EventLog.writeEvent(EventLogTags.BACKUP_PACKAGE,
+                            mCurrentPackage.packageName, size);
+                    logBackupComplete(mCurrentPackage.packageName);
+                } else {
+                    EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE,
+                            mCurrentPackage.packageName);
+                }
+            } catch (Exception e) {
+                Slog.e(TAG, "Transport error backing up " + mCurrentPackage.packageName, e);
+                EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE,
+                        mCurrentPackage.packageName);
+                mStatus = BackupConstants.TRANSPORT_ERROR;
+            } finally {
+                try { if (backupData != null) backupData.close(); } catch (IOException e) {}
+            }
+
+            // If we encountered an error here it's a transport-level failure.  That
+            // means we need to halt everything and reschedule everything for next time.
+            final BackupState nextState;
+            if (mStatus != BackupConstants.TRANSPORT_OK) {
+                revertAndEndBackup();
+                nextState = BackupState.FINAL;
+            } else {
+                // Success!  Proceed with the next app if any, otherwise we're done.
+                nextState = (mQueue.isEmpty()) ? BackupState.FINAL : BackupState.RUNNING_QUEUE;
+            }
+
+            executeNextState(nextState);
+        }
+
+        @Override
+        public void handleTimeout() {
+            // Whoops, the current agent timed out running doBackup().  Tidy up and restage
+            // it for the next time we run a backup pass.
+            // !!! TODO: keep track of failure counts per agent, and blacklist those which
+            // fail repeatedly (i.e. have proved themselves to be buggy).
+            Slog.e(TAG, "Timeout backing up " + mCurrentPackage.packageName);
+            EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, mCurrentPackage.packageName,
+                    "timeout");
+            addBackupTrace("timeout of " + mCurrentPackage.packageName);
+            agentErrorCleanup();
+            dataChangedImpl(mCurrentPackage.packageName);
+        }
+
+        void revertAndEndBackup() {
+            if (MORE_DEBUG) Slog.i(TAG, "Reverting backup queue - restaging everything");
+            addBackupTrace("transport error; reverting");
+            for (BackupRequest request : mOriginalQueue) {
+                dataChangedImpl(request.packageName);
+            }
+            // We also want to reset the backup schedule based on whatever
+            // the transport suggests by way of retry/backoff time.
+            restartBackupAlarm();
+        }
+
+        void agentErrorCleanup() {
+            mBackupDataName.delete();
+            mNewStateName.delete();
+            clearAgentState();
+
+            executeNextState(mQueue.isEmpty() ? BackupState.FINAL : BackupState.RUNNING_QUEUE);
+        }
+
+        // Cleanup common to both success and failure cases
+        void clearAgentState() {
+            try { if (mSavedState != null) mSavedState.close(); } catch (IOException e) {}
+            try { if (mBackupData != null) mBackupData.close(); } catch (IOException e) {}
+            try { if (mNewState != null) mNewState.close(); } catch (IOException e) {}
+            mSavedState = mBackupData = mNewState = null;
+            synchronized (mCurrentOpLock) {
+                mCurrentOperations.clear();
+            }
+
+            // If this was a pseudopackage there's no associated Activity Manager state
+            if (mCurrentPackage.applicationInfo != null) {
+                addBackupTrace("unbinding " + mCurrentPackage.packageName);
+                try {  // unbind even on timeout, just in case
+                    mActivityManager.unbindBackupAgent(mCurrentPackage.applicationInfo);
+                } catch (RemoteException e) { /* can't happen; activity manager is local */ }
+            }
+        }
+
+        void restartBackupAlarm() {
+            addBackupTrace("setting backup trigger");
+            synchronized (mQueueLock) {
+                try {
+                    startBackupAlarmsLocked(mTransport.requestBackupTime());
+                } catch (RemoteException e) { /* cannot happen */ }
+            }
+        }
+
+        void executeNextState(BackupState nextState) {
+            if (MORE_DEBUG) Slog.i(TAG, " => executing next step on "
+                    + this + " nextState=" + nextState);
+            addBackupTrace("executeNextState => " + nextState);
+            mCurrentState = nextState;
+            Message msg = mBackupHandler.obtainMessage(MSG_BACKUP_RESTORE_STEP, this);
+            mBackupHandler.sendMessage(msg);
+        }
+    }
+
+
+    // ----- Full backup/restore to a file/socket -----
+
+    abstract class ObbServiceClient {
+        public IObbBackupService mObbService;
+        public void setObbBinder(IObbBackupService binder) {
+            mObbService = binder;
+        }
+    }
+
+    class FullBackupObbConnection implements ServiceConnection {
+        volatile IObbBackupService mService;
+
+        FullBackupObbConnection() {
+            mService = null;
+        }
+
+        public void establish() {
+            if (DEBUG) Slog.i(TAG, "Initiating bind of OBB service on " + this);
+            Intent obbIntent = new Intent().setComponent(new ComponentName(
+                    "com.android.sharedstoragebackup",
+                    "com.android.sharedstoragebackup.ObbBackupService"));
+            BackupManagerService.this.mContext.bindService(
+                    obbIntent, this, Context.BIND_AUTO_CREATE);
+        }
+
+        public void tearDown() {
+            BackupManagerService.this.mContext.unbindService(this);
+        }
+
+        public boolean backupObbs(PackageInfo pkg, OutputStream out) {
+            boolean success = false;
+            waitForConnection();
+
+            ParcelFileDescriptor[] pipes = null;
+            try {
+                pipes = ParcelFileDescriptor.createPipe();
+                int token = generateToken();
+                prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL, null);
+                mService.backupObbs(pkg.packageName, pipes[1], token, mBackupManagerBinder);
+                routeSocketDataToOutput(pipes[0], out);
+                success = waitUntilOperationComplete(token);
+            } catch (Exception e) {
+                Slog.w(TAG, "Unable to back up OBBs for " + pkg, e);
+            } finally {
+                try {
+                    out.flush();
+                    if (pipes != null) {
+                        if (pipes[0] != null) pipes[0].close();
+                        if (pipes[1] != null) pipes[1].close();
+                    }
+                } catch (IOException e) {
+                    Slog.w(TAG, "I/O error closing down OBB backup", e);
+                }
+            }
+            return success;
+        }
+
+        public void restoreObbFile(String pkgName, ParcelFileDescriptor data,
+                long fileSize, int type, String path, long mode, long mtime,
+                int token, IBackupManager callbackBinder) {
+            waitForConnection();
+
+            try {
+                mService.restoreObbFile(pkgName, data, fileSize, type, path, mode, mtime,
+                        token, callbackBinder);
+            } catch (Exception e) {
+                Slog.w(TAG, "Unable to restore OBBs for " + pkgName, e);
+            }
+        }
+
+        private void waitForConnection() {
+            synchronized (this) {
+                while (mService == null) {
+                    if (DEBUG) Slog.i(TAG, "...waiting for OBB service binding...");
+                    try {
+                        this.wait();
+                    } catch (InterruptedException e) { /* never interrupted */ }
+                }
+                if (DEBUG) Slog.i(TAG, "Connected to OBB service; continuing");
+            }
+        }
+
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            synchronized (this) {
+                mService = IObbBackupService.Stub.asInterface(service);
+                if (DEBUG) Slog.i(TAG, "OBB service connection " + mService
+                        + " connected on " + this);
+                this.notifyAll();
+            }
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+            synchronized (this) {
+                mService = null;
+                if (DEBUG) Slog.i(TAG, "OBB service connection disconnected on " + this);
+                this.notifyAll();
+            }
+        }
+        
+    }
+
+    private void routeSocketDataToOutput(ParcelFileDescriptor inPipe, OutputStream out)
+            throws IOException {
+        FileInputStream raw = new FileInputStream(inPipe.getFileDescriptor());
+        DataInputStream in = new DataInputStream(raw);
+
+        byte[] buffer = new byte[32 * 1024];
+        int chunkTotal;
+        while ((chunkTotal = in.readInt()) > 0) {
+            while (chunkTotal > 0) {
+                int toRead = (chunkTotal > buffer.length) ? buffer.length : chunkTotal;
+                int nRead = in.read(buffer, 0, toRead);
+                out.write(buffer, 0, nRead);
+                chunkTotal -= nRead;
+            }
+        }
+    }
+
+    class PerformFullBackupTask extends ObbServiceClient implements Runnable {
+        ParcelFileDescriptor mOutputFile;
+        DeflaterOutputStream mDeflater;
+        IFullBackupRestoreObserver mObserver;
+        boolean mIncludeApks;
+        boolean mIncludeObbs;
+        boolean mIncludeShared;
+        boolean mAllApps;
+        final boolean mIncludeSystem;
+        String[] mPackages;
+        String mCurrentPassword;
+        String mEncryptPassword;
+        AtomicBoolean mLatchObject;
+        File mFilesDir;
+        File mManifestFile;
+        
+
+        class FullBackupRunner implements Runnable {
+            PackageInfo mPackage;
+            IBackupAgent mAgent;
+            ParcelFileDescriptor mPipe;
+            int mToken;
+            boolean mSendApk;
+            boolean mWriteManifest;
+
+            FullBackupRunner(PackageInfo pack, IBackupAgent agent, ParcelFileDescriptor pipe,
+                    int token, boolean sendApk, boolean writeManifest)  throws IOException {
+                mPackage = pack;
+                mAgent = agent;
+                mPipe = ParcelFileDescriptor.dup(pipe.getFileDescriptor());
+                mToken = token;
+                mSendApk = sendApk;
+                mWriteManifest = writeManifest;
+            }
+
+            @Override
+            public void run() {
+                try {
+                    BackupDataOutput output = new BackupDataOutput(
+                            mPipe.getFileDescriptor());
+
+                    if (mWriteManifest) {
+                        if (MORE_DEBUG) Slog.d(TAG, "Writing manifest for " + mPackage.packageName);
+                        writeAppManifest(mPackage, mManifestFile, mSendApk);
+                        FullBackup.backupToTar(mPackage.packageName, null, null,
+                                mFilesDir.getAbsolutePath(),
+                                mManifestFile.getAbsolutePath(),
+                                output);
+                    }
+
+                    if (mSendApk) {
+                        writeApkToBackup(mPackage, output);
+                    }
+
+                    if (DEBUG) Slog.d(TAG, "Calling doFullBackup() on " + mPackage.packageName);
+                    prepareOperationTimeout(mToken, TIMEOUT_FULL_BACKUP_INTERVAL, null);
+                    mAgent.doFullBackup(mPipe, mToken, mBackupManagerBinder);
+                } catch (IOException e) {
+                    Slog.e(TAG, "Error running full backup for " + mPackage.packageName);
+                } catch (RemoteException e) {
+                    Slog.e(TAG, "Remote agent vanished during full backup of "
+                            + mPackage.packageName);
+                } finally {
+                    try {
+                        mPipe.close();
+                    } catch (IOException e) {}
+                }
+            }
+        }
+
+        PerformFullBackupTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer, 
+                boolean includeApks, boolean includeObbs, boolean includeShared,
+                String curPassword, String encryptPassword, boolean doAllApps,
+                boolean doSystem, String[] packages, AtomicBoolean latch) {
+            mOutputFile = fd;
+            mObserver = observer;
+            mIncludeApks = includeApks;
+            mIncludeObbs = includeObbs;
+            mIncludeShared = includeShared;
+            mAllApps = doAllApps;
+            mIncludeSystem = doSystem;
+            mPackages = packages;
+            mCurrentPassword = curPassword;
+            // when backing up, if there is a current backup password, we require that
+            // the user use a nonempty encryption password as well.  if one is supplied
+            // in the UI we use that, but if the UI was left empty we fall back to the
+            // current backup password (which was supplied by the user as well).
+            if (encryptPassword == null || "".equals(encryptPassword)) {
+                mEncryptPassword = curPassword;
+            } else {
+                mEncryptPassword = encryptPassword;
+            }
+            mLatchObject = latch;
+
+            mFilesDir = new File("/data/system");
+            mManifestFile = new File(mFilesDir, BACKUP_MANIFEST_FILENAME);
+        }
+
+        @Override
+        public void run() {
+            Slog.i(TAG, "--- Performing full-dataset backup ---");
+
+            List<PackageInfo> packagesToBackup = new ArrayList<PackageInfo>();
+            FullBackupObbConnection obbConnection = new FullBackupObbConnection();
+            obbConnection.establish();  // we'll want this later
+
+            sendStartBackup();
+
+            // doAllApps supersedes the package set if any
+            if (mAllApps) {
+                packagesToBackup = mPackageManager.getInstalledPackages(
+                        PackageManager.GET_SIGNATURES);
+                // Exclude system apps if we've been asked to do so
+                if (mIncludeSystem == false) {
+                    for (int i = 0; i < packagesToBackup.size(); ) {
+                        PackageInfo pkg = packagesToBackup.get(i);
+                        if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                            packagesToBackup.remove(i);
+                        } else {
+                            i++;
+                        }
+                    }
+                }
+            }
+
+            // Now process the command line argument packages, if any. Note that explicitly-
+            // named system-partition packages will be included even if includeSystem was
+            // set to false.
+            if (mPackages != null) {
+                for (String pkgName : mPackages) {
+                    try {
+                        packagesToBackup.add(mPackageManager.getPackageInfo(pkgName,
+                                PackageManager.GET_SIGNATURES));
+                    } catch (NameNotFoundException e) {
+                        Slog.w(TAG, "Unknown package " + pkgName + ", skipping");
+                    }
+                }
+            }
+
+            // Cull any packages that have indicated that backups are not permitted, as well
+            // as any explicit mention of the 'special' shared-storage agent package (we
+            // handle that one at the end).
+            for (int i = 0; i < packagesToBackup.size(); ) {
+                PackageInfo pkg = packagesToBackup.get(i);
+                if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0
+                        || pkg.packageName.equals(SHARED_BACKUP_AGENT_PACKAGE)) {
+                    packagesToBackup.remove(i);
+                } else {
+                    i++;
+                }
+            }
+
+            // Cull any packages that run as system-domain uids but do not define their
+            // own backup agents
+            for (int i = 0; i < packagesToBackup.size(); ) {
+                PackageInfo pkg = packagesToBackup.get(i);
+                if ((pkg.applicationInfo.uid < Process.FIRST_APPLICATION_UID)
+                        && (pkg.applicationInfo.backupAgentName == null)) {
+                    if (MORE_DEBUG) {
+                        Slog.i(TAG, "... ignoring non-agent system package " + pkg.packageName);
+                    }
+                    packagesToBackup.remove(i);
+                } else {
+                    i++;
+                }
+            }
+
+            FileOutputStream ofstream = new FileOutputStream(mOutputFile.getFileDescriptor());
+            OutputStream out = null;
+
+            PackageInfo pkg = null;
+            try {
+                boolean encrypting = (mEncryptPassword != null && mEncryptPassword.length() > 0);
+                boolean compressing = COMPRESS_FULL_BACKUPS;
+                OutputStream finalOutput = ofstream;
+
+                // Verify that the given password matches the currently-active
+                // backup password, if any
+                if (!backupPasswordMatches(mCurrentPassword)) {
+                    if (DEBUG) Slog.w(TAG, "Backup password mismatch; aborting");
+                    return;
+                }
+
+                // Write the global file header.  All strings are UTF-8 encoded; lines end
+                // with a '\n' byte.  Actual backup data begins immediately following the
+                // final '\n'.
+                //
+                // line 1: "ANDROID BACKUP"
+                // line 2: backup file format version, currently "2"
+                // line 3: compressed?  "0" if not compressed, "1" if compressed.
+                // line 4: name of encryption algorithm [currently only "none" or "AES-256"]
+                //
+                // When line 4 is not "none", then additional header data follows:
+                //
+                // line 5: user password salt [hex]
+                // line 6: master key checksum salt [hex]
+                // line 7: number of PBKDF2 rounds to use (same for user & master) [decimal]
+                // line 8: IV of the user key [hex]
+                // line 9: master key blob [hex]
+                //     IV of the master key, master key itself, master key checksum hash
+                //
+                // The master key checksum is the master key plus its checksum salt, run through
+                // 10k rounds of PBKDF2.  This is used to verify that the user has supplied the
+                // correct password for decrypting the archive:  the master key decrypted from
+                // the archive using the user-supplied password is also run through PBKDF2 in
+                // this way, and if the result does not match the checksum as stored in the
+                // archive, then we know that the user-supplied password does not match the
+                // archive's.
+                StringBuilder headerbuf = new StringBuilder(1024);
+
+                headerbuf.append(BACKUP_FILE_HEADER_MAGIC);
+                headerbuf.append(BACKUP_FILE_VERSION); // integer, no trailing \n
+                headerbuf.append(compressing ? "\n1\n" : "\n0\n");
+
+                try {
+                    // Set up the encryption stage if appropriate, and emit the correct header
+                    if (encrypting) {
+                        finalOutput = emitAesBackupHeader(headerbuf, finalOutput);
+                    } else {
+                        headerbuf.append("none\n");
+                    }
+
+                    byte[] header = headerbuf.toString().getBytes("UTF-8");
+                    ofstream.write(header);
+
+                    // Set up the compression stage feeding into the encryption stage (if any)
+                    if (compressing) {
+                        Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
+                        finalOutput = new DeflaterOutputStream(finalOutput, deflater, true);
+                    }
+
+                    out = finalOutput;
+                } catch (Exception e) {
+                    // Should never happen!
+                    Slog.e(TAG, "Unable to emit archive header", e);
+                    return;
+                }
+
+                // Shared storage if requested
+                if (mIncludeShared) {
+                    try {
+                        pkg = mPackageManager.getPackageInfo(SHARED_BACKUP_AGENT_PACKAGE, 0);
+                        packagesToBackup.add(pkg);
+                    } catch (NameNotFoundException e) {
+                        Slog.e(TAG, "Unable to find shared-storage backup handler");
+                    }
+                }
+
+                // Now back up the app data via the agent mechanism
+                int N = packagesToBackup.size();
+                for (int i = 0; i < N; i++) {
+                    pkg = packagesToBackup.get(i);
+                    backupOnePackage(pkg, out);
+
+                    // after the app's agent runs to handle its private filesystem
+                    // contents, back up any OBB content it has on its behalf.
+                    if (mIncludeObbs) {
+                        boolean obbOkay = obbConnection.backupObbs(pkg, out);
+                        if (!obbOkay) {
+                            throw new RuntimeException("Failure writing OBB stack for " + pkg);
+                        }
+                    }
+                }
+
+                // Done!
+                finalizeBackup(out);
+            } catch (RemoteException e) {
+                Slog.e(TAG, "App died during full backup");
+            } catch (Exception e) {
+                Slog.e(TAG, "Internal exception during full backup", e);
+            } finally {
+                tearDown(pkg);
+                try {
+                    if (out != null) out.close();
+                    mOutputFile.close();
+                } catch (IOException e) {
+                    /* nothing we can do about this */
+                }
+                synchronized (mCurrentOpLock) {
+                    mCurrentOperations.clear();
+                }
+                synchronized (mLatchObject) {
+                    mLatchObject.set(true);
+                    mLatchObject.notifyAll();
+                }
+                sendEndBackup();
+                obbConnection.tearDown();
+                if (DEBUG) Slog.d(TAG, "Full backup pass complete.");
+                mWakelock.release();
+            }
+        }
+
+        private OutputStream emitAesBackupHeader(StringBuilder headerbuf,
+                OutputStream ofstream) throws Exception {
+            // User key will be used to encrypt the master key.
+            byte[] newUserSalt = randomBytes(PBKDF2_SALT_SIZE);
+            SecretKey userKey = buildPasswordKey(PBKDF_CURRENT, mEncryptPassword, newUserSalt,
+                    PBKDF2_HASH_ROUNDS);
+
+            // the master key is random for each backup
+            byte[] masterPw = new byte[256 / 8];
+            mRng.nextBytes(masterPw);
+            byte[] checksumSalt = randomBytes(PBKDF2_SALT_SIZE);
+
+            // primary encryption of the datastream with the random key
+            Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            SecretKeySpec masterKeySpec = new SecretKeySpec(masterPw, "AES");
+            c.init(Cipher.ENCRYPT_MODE, masterKeySpec);
+            OutputStream finalOutput = new CipherOutputStream(ofstream, c);
+
+            // line 4: name of encryption algorithm
+            headerbuf.append(ENCRYPTION_ALGORITHM_NAME);
+            headerbuf.append('\n');
+            // line 5: user password salt [hex]
+            headerbuf.append(byteArrayToHex(newUserSalt));
+            headerbuf.append('\n');
+            // line 6: master key checksum salt [hex]
+            headerbuf.append(byteArrayToHex(checksumSalt));
+            headerbuf.append('\n');
+            // line 7: number of PBKDF2 rounds used [decimal]
+            headerbuf.append(PBKDF2_HASH_ROUNDS);
+            headerbuf.append('\n');
+
+            // line 8: IV of the user key [hex]
+            Cipher mkC = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            mkC.init(Cipher.ENCRYPT_MODE, userKey);
+
+            byte[] IV = mkC.getIV();
+            headerbuf.append(byteArrayToHex(IV));
+            headerbuf.append('\n');
+
+            // line 9: master IV + key blob, encrypted by the user key [hex].  Blob format:
+            //    [byte] IV length = Niv
+            //    [array of Niv bytes] IV itself
+            //    [byte] master key length = Nmk
+            //    [array of Nmk bytes] master key itself
+            //    [byte] MK checksum hash length = Nck
+            //    [array of Nck bytes] master key checksum hash
+            //
+            // The checksum is the (master key + checksum salt), run through the
+            // stated number of PBKDF2 rounds
+            IV = c.getIV();
+            byte[] mk = masterKeySpec.getEncoded();
+            byte[] checksum = makeKeyChecksum(PBKDF_CURRENT, masterKeySpec.getEncoded(),
+                    checksumSalt, PBKDF2_HASH_ROUNDS);
+
+            ByteArrayOutputStream blob = new ByteArrayOutputStream(IV.length + mk.length
+                    + checksum.length + 3);
+            DataOutputStream mkOut = new DataOutputStream(blob);
+            mkOut.writeByte(IV.length);
+            mkOut.write(IV);
+            mkOut.writeByte(mk.length);
+            mkOut.write(mk);
+            mkOut.writeByte(checksum.length);
+            mkOut.write(checksum);
+            mkOut.flush();
+            byte[] encryptedMk = mkC.doFinal(blob.toByteArray());
+            headerbuf.append(byteArrayToHex(encryptedMk));
+            headerbuf.append('\n');
+
+            return finalOutput;
+        }
+
+        private void backupOnePackage(PackageInfo pkg, OutputStream out)
+                throws RemoteException {
+            Slog.d(TAG, "Binding to full backup agent : " + pkg.packageName);
+
+            IBackupAgent agent = bindToAgentSynchronous(pkg.applicationInfo,
+                    IApplicationThread.BACKUP_MODE_FULL);
+            if (agent != null) {
+                ParcelFileDescriptor[] pipes = null;
+                try {
+                    pipes = ParcelFileDescriptor.createPipe();
+
+                    ApplicationInfo app = pkg.applicationInfo;
+                    final boolean isSharedStorage = pkg.packageName.equals(SHARED_BACKUP_AGENT_PACKAGE);
+                    final boolean sendApk = mIncludeApks
+                            && !isSharedStorage
+                            && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0)
+                            && ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ||
+                                (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
+
+                    sendOnBackupPackage(isSharedStorage ? "Shared storage" : pkg.packageName);
+
+                    final int token = generateToken();
+                    FullBackupRunner runner = new FullBackupRunner(pkg, agent, pipes[1],
+                            token, sendApk, !isSharedStorage);
+                    pipes[1].close();   // the runner has dup'd it
+                    pipes[1] = null;
+                    Thread t = new Thread(runner);
+                    t.start();
+
+                    // Now pull data from the app and stuff it into the compressor
+                    try {
+                        routeSocketDataToOutput(pipes[0], out);
+                    } catch (IOException e) {
+                        Slog.i(TAG, "Caught exception reading from agent", e);
+                    }
+
+                    if (!waitUntilOperationComplete(token)) {
+                        Slog.e(TAG, "Full backup failed on package " + pkg.packageName);
+                    } else {
+                        if (DEBUG) Slog.d(TAG, "Full package backup success: " + pkg.packageName);
+                    }
+
+                } catch (IOException e) {
+                    Slog.e(TAG, "Error backing up " + pkg.packageName, e);
+                } finally {
+                    try {
+                        // flush after every package
+                        out.flush();
+                        if (pipes != null) {
+                            if (pipes[0] != null) pipes[0].close();
+                            if (pipes[1] != null) pipes[1].close();
+                        }
+                    } catch (IOException e) {
+                        Slog.w(TAG, "Error bringing down backup stack");
+                    }
+                }
+            } else {
+                Slog.w(TAG, "Unable to bind to full agent for " + pkg.packageName);
+            }
+            tearDown(pkg);
+        }
+
+        private void writeApkToBackup(PackageInfo pkg, BackupDataOutput output) {
+            // Forward-locked apps, system-bundled .apks, etc are filtered out before we get here
+            final String appSourceDir = pkg.applicationInfo.sourceDir;
+            final String apkDir = new File(appSourceDir).getParent();
+            FullBackup.backupToTar(pkg.packageName, FullBackup.APK_TREE_TOKEN, null,
+                    apkDir, appSourceDir, output);
+
+            // TODO: migrate this to SharedStorageBackup, since AID_SYSTEM
+            // doesn't have access to external storage.
+
+            // Save associated .obb content if it exists and we did save the apk
+            // check for .obb and save those too
+            final UserEnvironment userEnv = new UserEnvironment(UserHandle.USER_OWNER);
+            final File obbDir = userEnv.buildExternalStorageAppObbDirs(pkg.packageName)[0];
+            if (obbDir != null) {
+                if (MORE_DEBUG) Log.i(TAG, "obb dir: " + obbDir.getAbsolutePath());
+                File[] obbFiles = obbDir.listFiles();
+                if (obbFiles != null) {
+                    final String obbDirName = obbDir.getAbsolutePath();
+                    for (File obb : obbFiles) {
+                        FullBackup.backupToTar(pkg.packageName, FullBackup.OBB_TREE_TOKEN, null,
+                                obbDirName, obb.getAbsolutePath(), output);
+                    }
+                }
+            }
+        }
+
+        private void finalizeBackup(OutputStream out) {
+            try {
+                // A standard 'tar' EOF sequence: two 512-byte blocks of all zeroes.
+                byte[] eof = new byte[512 * 2]; // newly allocated == zero filled
+                out.write(eof);
+            } catch (IOException e) {
+                Slog.w(TAG, "Error attempting to finalize backup stream");
+            }
+        }
+
+        private void writeAppManifest(PackageInfo pkg, File manifestFile, boolean withApk)
+                throws IOException {
+            // Manifest format. All data are strings ending in LF:
+            //     BACKUP_MANIFEST_VERSION, currently 1
+            //
+            // Version 1:
+            //     package name
+            //     package's versionCode
+            //     platform versionCode
+            //     getInstallerPackageName() for this package (maybe empty)
+            //     boolean: "1" if archive includes .apk; any other string means not
+            //     number of signatures == N
+            // N*:    signature byte array in ascii format per Signature.toCharsString()
+            StringBuilder builder = new StringBuilder(4096);
+            StringBuilderPrinter printer = new StringBuilderPrinter(builder);
+
+            printer.println(Integer.toString(BACKUP_MANIFEST_VERSION));
+            printer.println(pkg.packageName);
+            printer.println(Integer.toString(pkg.versionCode));
+            printer.println(Integer.toString(Build.VERSION.SDK_INT));
+
+            String installerName = mPackageManager.getInstallerPackageName(pkg.packageName);
+            printer.println((installerName != null) ? installerName : "");
+
+            printer.println(withApk ? "1" : "0");
+            if (pkg.signatures == null) {
+                printer.println("0");
+            } else {
+                printer.println(Integer.toString(pkg.signatures.length));
+                for (Signature sig : pkg.signatures) {
+                    printer.println(sig.toCharsString());
+                }
+            }
+
+            FileOutputStream outstream = new FileOutputStream(manifestFile);
+            outstream.write(builder.toString().getBytes());
+            outstream.close();
+        }
+
+        private void tearDown(PackageInfo pkg) {
+            if (pkg != null) {
+                final ApplicationInfo app = pkg.applicationInfo;
+                if (app != null) {
+                    try {
+                        // unbind and tidy up even on timeout or failure, just in case
+                        mActivityManager.unbindBackupAgent(app);
+
+                        // The agent was running with a stub Application object, so shut it down.
+                        if (app.uid != Process.SYSTEM_UID
+                                && app.uid != Process.PHONE_UID) {
+                            if (MORE_DEBUG) Slog.d(TAG, "Backup complete, killing host process");
+                            mActivityManager.killApplicationProcess(app.processName, app.uid);
+                        } else {
+                            if (MORE_DEBUG) Slog.d(TAG, "Not killing after restore: " + app.processName);
+                        }
+                    } catch (RemoteException e) {
+                        Slog.d(TAG, "Lost app trying to shut down");
+                    }
+                }
+            }
+        }
+
+        // wrappers for observer use
+        void sendStartBackup() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onStartBackup();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full backup observer went away: startBackup");
+                    mObserver = null;
+                }
+            }
+        }
+
+        void sendOnBackupPackage(String name) {
+            if (mObserver != null) {
+                try {
+                    // TODO: use a more user-friendly name string
+                    mObserver.onBackupPackage(name);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full backup observer went away: backupPackage");
+                    mObserver = null;
+                }
+            }
+        }
+
+        void sendEndBackup() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onEndBackup();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full backup observer went away: endBackup");
+                    mObserver = null;
+                }
+            }
+        }
+    }
+
+
+    // ----- Full restore from a file/socket -----
+
+    // Description of a file in the restore datastream
+    static class FileMetadata {
+        String packageName;             // name of the owning app
+        String installerPackageName;    // name of the market-type app that installed the owner
+        int type;                       // e.g. BackupAgent.TYPE_DIRECTORY
+        String domain;                  // e.g. FullBackup.DATABASE_TREE_TOKEN
+        String path;                    // subpath within the semantic domain
+        long mode;                      // e.g. 0666 (actually int)
+        long mtime;                     // last mod time, UTC time_t (actually int)
+        long size;                      // bytes of content
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("FileMetadata{");
+            sb.append(packageName); sb.append(',');
+            sb.append(type); sb.append(',');
+            sb.append(domain); sb.append(':'); sb.append(path); sb.append(',');
+            sb.append(size);
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+    enum RestorePolicy {
+        IGNORE,
+        ACCEPT,
+        ACCEPT_IF_APK
+    }
+
+    class PerformFullRestoreTask extends ObbServiceClient implements Runnable {
+        ParcelFileDescriptor mInputFile;
+        String mCurrentPassword;
+        String mDecryptPassword;
+        IFullBackupRestoreObserver mObserver;
+        AtomicBoolean mLatchObject;
+        IBackupAgent mAgent;
+        String mAgentPackage;
+        ApplicationInfo mTargetApp;
+        FullBackupObbConnection mObbConnection = null;
+        ParcelFileDescriptor[] mPipes = null;
+
+        long mBytes;
+
+        // possible handling states for a given package in the restore dataset
+        final HashMap<String, RestorePolicy> mPackagePolicies
+                = new HashMap<String, RestorePolicy>();
+
+        // installer package names for each encountered app, derived from the manifests
+        final HashMap<String, String> mPackageInstallers = new HashMap<String, String>();
+
+        // Signatures for a given package found in its manifest file
+        final HashMap<String, Signature[]> mManifestSignatures
+                = new HashMap<String, Signature[]>();
+
+        // Packages we've already wiped data on when restoring their first file
+        final HashSet<String> mClearedPackages = new HashSet<String>();
+
+        PerformFullRestoreTask(ParcelFileDescriptor fd, String curPassword, String decryptPassword,
+                IFullBackupRestoreObserver observer, AtomicBoolean latch) {
+            mInputFile = fd;
+            mCurrentPassword = curPassword;
+            mDecryptPassword = decryptPassword;
+            mObserver = observer;
+            mLatchObject = latch;
+            mAgent = null;
+            mAgentPackage = null;
+            mTargetApp = null;
+            mObbConnection = new FullBackupObbConnection();
+
+            // Which packages we've already wiped data on.  We prepopulate this
+            // with a whitelist of packages known to be unclearable.
+            mClearedPackages.add("android");
+            mClearedPackages.add("com.android.providers.settings");
+
+        }
+
+        class RestoreFileRunnable implements Runnable {
+            IBackupAgent mAgent;
+            FileMetadata mInfo;
+            ParcelFileDescriptor mSocket;
+            int mToken;
+
+            RestoreFileRunnable(IBackupAgent agent, FileMetadata info,
+                    ParcelFileDescriptor socket, int token) throws IOException {
+                mAgent = agent;
+                mInfo = info;
+                mToken = token;
+
+                // This class is used strictly for process-local binder invocations.  The
+                // semantics of ParcelFileDescriptor differ in this case; in particular, we
+                // do not automatically get a 'dup'ed descriptor that we can can continue
+                // to use asynchronously from the caller.  So, we make sure to dup it ourselves
+                // before proceeding to do the restore.
+                mSocket = ParcelFileDescriptor.dup(socket.getFileDescriptor());
+            }
+
+            @Override
+            public void run() {
+                try {
+                    mAgent.doRestoreFile(mSocket, mInfo.size, mInfo.type,
+                            mInfo.domain, mInfo.path, mInfo.mode, mInfo.mtime,
+                            mToken, mBackupManagerBinder);
+                } catch (RemoteException e) {
+                    // never happens; this is used strictly for local binder calls
+                }
+            }
+        }
+
+        @Override
+        public void run() {
+            Slog.i(TAG, "--- Performing full-dataset restore ---");
+            mObbConnection.establish();
+            sendStartRestore();
+
+            // Are we able to restore shared-storage data?
+            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+                mPackagePolicies.put(SHARED_BACKUP_AGENT_PACKAGE, RestorePolicy.ACCEPT);
+            }
+
+            FileInputStream rawInStream = null;
+            DataInputStream rawDataIn = null;
+            try {
+                if (!backupPasswordMatches(mCurrentPassword)) {
+                    if (DEBUG) Slog.w(TAG, "Backup password mismatch; aborting");
+                    return;
+                }
+
+                mBytes = 0;
+                byte[] buffer = new byte[32 * 1024];
+                rawInStream = new FileInputStream(mInputFile.getFileDescriptor());
+                rawDataIn = new DataInputStream(rawInStream);
+
+                // First, parse out the unencrypted/uncompressed header
+                boolean compressed = false;
+                InputStream preCompressStream = rawInStream;
+                final InputStream in;
+
+                boolean okay = false;
+                final int headerLen = BACKUP_FILE_HEADER_MAGIC.length();
+                byte[] streamHeader = new byte[headerLen];
+                rawDataIn.readFully(streamHeader);
+                byte[] magicBytes = BACKUP_FILE_HEADER_MAGIC.getBytes("UTF-8");
+                if (Arrays.equals(magicBytes, streamHeader)) {
+                    // okay, header looks good.  now parse out the rest of the fields.
+                    String s = readHeaderLine(rawInStream);
+                    final int archiveVersion = Integer.parseInt(s);
+                    if (archiveVersion <= BACKUP_FILE_VERSION) {
+                        // okay, it's a version we recognize.  if it's version 1, we may need
+                        // to try two different PBKDF2 regimes to compare checksums.
+                        final boolean pbkdf2Fallback = (archiveVersion == 1);
+
+                        s = readHeaderLine(rawInStream);
+                        compressed = (Integer.parseInt(s) != 0);
+                        s = readHeaderLine(rawInStream);
+                        if (s.equals("none")) {
+                            // no more header to parse; we're good to go
+                            okay = true;
+                        } else if (mDecryptPassword != null && mDecryptPassword.length() > 0) {
+                            preCompressStream = decodeAesHeaderAndInitialize(s, pbkdf2Fallback,
+                                    rawInStream);
+                            if (preCompressStream != null) {
+                                okay = true;
+                            }
+                        } else Slog.w(TAG, "Archive is encrypted but no password given");
+                    } else Slog.w(TAG, "Wrong header version: " + s);
+                } else Slog.w(TAG, "Didn't read the right header magic");
+
+                if (!okay) {
+                    Slog.w(TAG, "Invalid restore data; aborting.");
+                    return;
+                }
+
+                // okay, use the right stream layer based on compression
+                in = (compressed) ? new InflaterInputStream(preCompressStream) : preCompressStream;
+
+                boolean didRestore;
+                do {
+                    didRestore = restoreOneFile(in, buffer);
+                } while (didRestore);
+
+                if (MORE_DEBUG) Slog.v(TAG, "Done consuming input tarfile, total bytes=" + mBytes);
+            } catch (IOException e) {
+                Slog.e(TAG, "Unable to read restore input");
+            } finally {
+                tearDownPipes();
+                tearDownAgent(mTargetApp);
+
+                try {
+                    if (rawDataIn != null) rawDataIn.close();
+                    if (rawInStream != null) rawInStream.close();
+                    mInputFile.close();
+                } catch (IOException e) {
+                    Slog.w(TAG, "Close of restore data pipe threw", e);
+                    /* nothing we can do about this */
+                }
+                synchronized (mCurrentOpLock) {
+                    mCurrentOperations.clear();
+                }
+                synchronized (mLatchObject) {
+                    mLatchObject.set(true);
+                    mLatchObject.notifyAll();
+                }
+                mObbConnection.tearDown();
+                sendEndRestore();
+                Slog.d(TAG, "Full restore pass complete.");
+                mWakelock.release();
+            }
+        }
+
+        String readHeaderLine(InputStream in) throws IOException {
+            int c;
+            StringBuilder buffer = new StringBuilder(80);
+            while ((c = in.read()) >= 0) {
+                if (c == '\n') break;   // consume and discard the newlines
+                buffer.append((char)c);
+            }
+            return buffer.toString();
+        }
+
+        InputStream attemptMasterKeyDecryption(String algorithm, byte[] userSalt, byte[] ckSalt,
+                int rounds, String userIvHex, String masterKeyBlobHex, InputStream rawInStream,
+                boolean doLog) {
+            InputStream result = null;
+
+            try {
+                Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
+                SecretKey userKey = buildPasswordKey(algorithm, mDecryptPassword, userSalt,
+                        rounds);
+                byte[] IV = hexToByteArray(userIvHex);
+                IvParameterSpec ivSpec = new IvParameterSpec(IV);
+                c.init(Cipher.DECRYPT_MODE,
+                        new SecretKeySpec(userKey.getEncoded(), "AES"),
+                        ivSpec);
+                byte[] mkCipher = hexToByteArray(masterKeyBlobHex);
+                byte[] mkBlob = c.doFinal(mkCipher);
+
+                // first, the master key IV
+                int offset = 0;
+                int len = mkBlob[offset++];
+                IV = Arrays.copyOfRange(mkBlob, offset, offset + len);
+                offset += len;
+                // then the master key itself
+                len = mkBlob[offset++];
+                byte[] mk = Arrays.copyOfRange(mkBlob,
+                        offset, offset + len);
+                offset += len;
+                // and finally the master key checksum hash
+                len = mkBlob[offset++];
+                byte[] mkChecksum = Arrays.copyOfRange(mkBlob,
+                        offset, offset + len);
+
+                // now validate the decrypted master key against the checksum
+                byte[] calculatedCk = makeKeyChecksum(algorithm, mk, ckSalt, rounds);
+                if (Arrays.equals(calculatedCk, mkChecksum)) {
+                    ivSpec = new IvParameterSpec(IV);
+                    c.init(Cipher.DECRYPT_MODE,
+                            new SecretKeySpec(mk, "AES"),
+                            ivSpec);
+                    // Only if all of the above worked properly will 'result' be assigned
+                    result = new CipherInputStream(rawInStream, c);
+                } else if (doLog) Slog.w(TAG, "Incorrect password");
+            } catch (InvalidAlgorithmParameterException e) {
+                if (doLog) Slog.e(TAG, "Needed parameter spec unavailable!", e);
+            } catch (BadPaddingException e) {
+                // This case frequently occurs when the wrong password is used to decrypt
+                // the master key.  Use the identical "incorrect password" log text as is
+                // used in the checksum failure log in order to avoid providing additional
+                // information to an attacker.
+                if (doLog) Slog.w(TAG, "Incorrect password");
+            } catch (IllegalBlockSizeException e) {
+                if (doLog) Slog.w(TAG, "Invalid block size in master key");
+            } catch (NoSuchAlgorithmException e) {
+                if (doLog) Slog.e(TAG, "Needed decryption algorithm unavailable!");
+            } catch (NoSuchPaddingException e) {
+                if (doLog) Slog.e(TAG, "Needed padding mechanism unavailable!");
+            } catch (InvalidKeyException e) {
+                if (doLog) Slog.w(TAG, "Illegal password; aborting");
+            }
+
+            return result;
+        }
+
+        InputStream decodeAesHeaderAndInitialize(String encryptionName, boolean pbkdf2Fallback,
+                InputStream rawInStream) {
+            InputStream result = null;
+            try {
+                if (encryptionName.equals(ENCRYPTION_ALGORITHM_NAME)) {
+
+                    String userSaltHex = readHeaderLine(rawInStream); // 5
+                    byte[] userSalt = hexToByteArray(userSaltHex);
+
+                    String ckSaltHex = readHeaderLine(rawInStream); // 6
+                    byte[] ckSalt = hexToByteArray(ckSaltHex);
+
+                    int rounds = Integer.parseInt(readHeaderLine(rawInStream)); // 7
+                    String userIvHex = readHeaderLine(rawInStream); // 8
+
+                    String masterKeyBlobHex = readHeaderLine(rawInStream); // 9
+
+                    // decrypt the master key blob
+                    result = attemptMasterKeyDecryption(PBKDF_CURRENT, userSalt, ckSalt,
+                            rounds, userIvHex, masterKeyBlobHex, rawInStream, false);
+                    if (result == null && pbkdf2Fallback) {
+                        result = attemptMasterKeyDecryption(PBKDF_FALLBACK, userSalt, ckSalt,
+                                rounds, userIvHex, masterKeyBlobHex, rawInStream, true);
+                    }
+                } else Slog.w(TAG, "Unsupported encryption method: " + encryptionName);
+            } catch (NumberFormatException e) {
+                Slog.w(TAG, "Can't parse restore data header");
+            } catch (IOException e) {
+                Slog.w(TAG, "Can't read input header");
+            }
+
+            return result;
+        }
+
+        boolean restoreOneFile(InputStream instream, byte[] buffer) {
+            FileMetadata info;
+            try {
+                info = readTarHeaders(instream);
+                if (info != null) {
+                    if (MORE_DEBUG) {
+                        dumpFileMetadata(info);
+                    }
+
+                    final String pkg = info.packageName;
+                    if (!pkg.equals(mAgentPackage)) {
+                        // okay, change in package; set up our various
+                        // bookkeeping if we haven't seen it yet
+                        if (!mPackagePolicies.containsKey(pkg)) {
+                            mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                        }
+
+                        // Clean up the previous agent relationship if necessary,
+                        // and let the observer know we're considering a new app.
+                        if (mAgent != null) {
+                            if (DEBUG) Slog.d(TAG, "Saw new package; tearing down old one");
+                            tearDownPipes();
+                            tearDownAgent(mTargetApp);
+                            mTargetApp = null;
+                            mAgentPackage = null;
+                        }
+                    }
+
+                    if (info.path.equals(BACKUP_MANIFEST_FILENAME)) {
+                        mPackagePolicies.put(pkg, readAppManifest(info, instream));
+                        mPackageInstallers.put(pkg, info.installerPackageName);
+                        // We've read only the manifest content itself at this point,
+                        // so consume the footer before looping around to the next
+                        // input file
+                        skipTarPadding(info.size, instream);
+                        sendOnRestorePackage(pkg);
+                    } else {
+                        // Non-manifest, so it's actual file data.  Is this a package
+                        // we're ignoring?
+                        boolean okay = true;
+                        RestorePolicy policy = mPackagePolicies.get(pkg);
+                        switch (policy) {
+                            case IGNORE:
+                                okay = false;
+                                break;
+
+                            case ACCEPT_IF_APK:
+                                // If we're in accept-if-apk state, then the first file we
+                                // see MUST be the apk.
+                                if (info.domain.equals(FullBackup.APK_TREE_TOKEN)) {
+                                    if (DEBUG) Slog.d(TAG, "APK file; installing");
+                                    // Try to install the app.
+                                    String installerName = mPackageInstallers.get(pkg);
+                                    okay = installApk(info, installerName, instream);
+                                    // good to go; promote to ACCEPT
+                                    mPackagePolicies.put(pkg, (okay)
+                                            ? RestorePolicy.ACCEPT
+                                            : RestorePolicy.IGNORE);
+                                    // At this point we've consumed this file entry
+                                    // ourselves, so just strip the tar footer and
+                                    // go on to the next file in the input stream
+                                    skipTarPadding(info.size, instream);
+                                    return true;
+                                } else {
+                                    // File data before (or without) the apk.  We can't
+                                    // handle it coherently in this case so ignore it.
+                                    mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                                    okay = false;
+                                }
+                                break;
+
+                            case ACCEPT:
+                                if (info.domain.equals(FullBackup.APK_TREE_TOKEN)) {
+                                    if (DEBUG) Slog.d(TAG, "apk present but ACCEPT");
+                                    // we can take the data without the apk, so we
+                                    // *want* to do so.  skip the apk by declaring this
+                                    // one file not-okay without changing the restore
+                                    // policy for the package.
+                                    okay = false;
+                                }
+                                break;
+
+                            default:
+                                // Something has gone dreadfully wrong when determining
+                                // the restore policy from the manifest.  Ignore the
+                                // rest of this package's data.
+                                Slog.e(TAG, "Invalid policy from manifest");
+                                okay = false;
+                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                                break;
+                        }
+
+                        // If the policy is satisfied, go ahead and set up to pipe the
+                        // data to the agent.
+                        if (DEBUG && okay && mAgent != null) {
+                            Slog.i(TAG, "Reusing existing agent instance");
+                        }
+                        if (okay && mAgent == null) {
+                            if (DEBUG) Slog.d(TAG, "Need to launch agent for " + pkg);
+
+                            try {
+                                mTargetApp = mPackageManager.getApplicationInfo(pkg, 0);
+
+                                // If we haven't sent any data to this app yet, we probably
+                                // need to clear it first.  Check that.
+                                if (!mClearedPackages.contains(pkg)) {
+                                    // apps with their own backup agents are
+                                    // responsible for coherently managing a full
+                                    // restore.
+                                    if (mTargetApp.backupAgentName == null) {
+                                        if (DEBUG) Slog.d(TAG, "Clearing app data preparatory to full restore");
+                                        clearApplicationDataSynchronous(pkg);
+                                    } else {
+                                        if (DEBUG) Slog.d(TAG, "backup agent ("
+                                                + mTargetApp.backupAgentName + ") => no clear");
+                                    }
+                                    mClearedPackages.add(pkg);
+                                } else {
+                                    if (DEBUG) Slog.d(TAG, "We've initialized this app already; no clear required");
+                                }
+
+                                // All set; now set up the IPC and launch the agent
+                                setUpPipes();
+                                mAgent = bindToAgentSynchronous(mTargetApp,
+                                        IApplicationThread.BACKUP_MODE_RESTORE_FULL);
+                                mAgentPackage = pkg;
+                            } catch (IOException e) {
+                                // fall through to error handling
+                            } catch (NameNotFoundException e) {
+                                // fall through to error handling
+                            }
+
+                            if (mAgent == null) {
+                                if (DEBUG) Slog.d(TAG, "Unable to create agent for " + pkg);
+                                okay = false;
+                                tearDownPipes();
+                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                            }
+                        }
+
+                        // Sanity check: make sure we never give data to the wrong app.  This
+                        // should never happen but a little paranoia here won't go amiss.
+                        if (okay && !pkg.equals(mAgentPackage)) {
+                            Slog.e(TAG, "Restoring data for " + pkg
+                                    + " but agent is for " + mAgentPackage);
+                            okay = false;
+                        }
+
+                        // At this point we have an agent ready to handle the full
+                        // restore data as well as a pipe for sending data to
+                        // that agent.  Tell the agent to start reading from the
+                        // pipe.
+                        if (okay) {
+                            boolean agentSuccess = true;
+                            long toCopy = info.size;
+                            final int token = generateToken();
+                            try {
+                                prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL, null);
+                                if (info.domain.equals(FullBackup.OBB_TREE_TOKEN)) {
+                                    if (DEBUG) Slog.d(TAG, "Restoring OBB file for " + pkg
+                                            + " : " + info.path);
+                                    mObbConnection.restoreObbFile(pkg, mPipes[0],
+                                            info.size, info.type, info.path, info.mode,
+                                            info.mtime, token, mBackupManagerBinder);
+                                } else {
+                                    if (DEBUG) Slog.d(TAG, "Invoking agent to restore file "
+                                            + info.path);
+                                    // fire up the app's agent listening on the socket.  If
+                                    // the agent is running in the system process we can't
+                                    // just invoke it asynchronously, so we provide a thread
+                                    // for it here.
+                                    if (mTargetApp.processName.equals("system")) {
+                                        Slog.d(TAG, "system process agent - spinning a thread");
+                                        RestoreFileRunnable runner = new RestoreFileRunnable(
+                                                mAgent, info, mPipes[0], token);
+                                        new Thread(runner).start();
+                                    } else {
+                                        mAgent.doRestoreFile(mPipes[0], info.size, info.type,
+                                                info.domain, info.path, info.mode, info.mtime,
+                                                token, mBackupManagerBinder);
+                                    }
+                                }
+                            } catch (IOException e) {
+                                // couldn't dup the socket for a process-local restore
+                                Slog.d(TAG, "Couldn't establish restore");
+                                agentSuccess = false;
+                                okay = false;
+                            } catch (RemoteException e) {
+                                // whoops, remote entity went away.  We'll eat the content
+                                // ourselves, then, and not copy it over.
+                                Slog.e(TAG, "Agent crashed during full restore");
+                                agentSuccess = false;
+                                okay = false;
+                            }
+
+                            // Copy over the data if the agent is still good
+                            if (okay) {
+                                boolean pipeOkay = true;
+                                FileOutputStream pipe = new FileOutputStream(
+                                        mPipes[1].getFileDescriptor());
+                                while (toCopy > 0) {
+                                    int toRead = (toCopy > buffer.length)
+                                    ? buffer.length : (int)toCopy;
+                                    int nRead = instream.read(buffer, 0, toRead);
+                                    if (nRead >= 0) mBytes += nRead;
+                                    if (nRead <= 0) break;
+                                    toCopy -= nRead;
+
+                                    // send it to the output pipe as long as things
+                                    // are still good
+                                    if (pipeOkay) {
+                                        try {
+                                            pipe.write(buffer, 0, nRead);
+                                        } catch (IOException e) {
+                                            Slog.e(TAG, "Failed to write to restore pipe", e);
+                                            pipeOkay = false;
+                                        }
+                                    }
+                                }
+
+                                // done sending that file!  Now we just need to consume
+                                // the delta from info.size to the end of block.
+                                skipTarPadding(info.size, instream);
+
+                                // and now that we've sent it all, wait for the remote
+                                // side to acknowledge receipt
+                                agentSuccess = waitUntilOperationComplete(token);
+                            }
+
+                            // okay, if the remote end failed at any point, deal with
+                            // it by ignoring the rest of the restore on it
+                            if (!agentSuccess) {
+                                mBackupHandler.removeMessages(MSG_TIMEOUT);
+                                tearDownPipes();
+                                tearDownAgent(mTargetApp);
+                                mAgent = null;
+                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
+                            }
+                        }
+
+                        // Problems setting up the agent communication, or an already-
+                        // ignored package: skip to the next tar stream entry by
+                        // reading and discarding this file.
+                        if (!okay) {
+                            if (DEBUG) Slog.d(TAG, "[discarding file content]");
+                            long bytesToConsume = (info.size + 511) & ~511;
+                            while (bytesToConsume > 0) {
+                                int toRead = (bytesToConsume > buffer.length)
+                                ? buffer.length : (int)bytesToConsume;
+                                long nRead = instream.read(buffer, 0, toRead);
+                                if (nRead >= 0) mBytes += nRead;
+                                if (nRead <= 0) break;
+                                bytesToConsume -= nRead;
+                            }
+                        }
+                    }
+                }
+            } catch (IOException e) {
+                if (DEBUG) Slog.w(TAG, "io exception on restore socket read", e);
+                // treat as EOF
+                info = null;
+            }
+
+            return (info != null);
+        }
+
+        void setUpPipes() throws IOException {
+            mPipes = ParcelFileDescriptor.createPipe();
+        }
+
+        void tearDownPipes() {
+            if (mPipes != null) {
+                try {
+                    mPipes[0].close();
+                    mPipes[0] = null;
+                    mPipes[1].close();
+                    mPipes[1] = null;
+                } catch (IOException e) {
+                    Slog.w(TAG, "Couldn't close agent pipes", e);
+                }
+                mPipes = null;
+            }
+        }
+
+        void tearDownAgent(ApplicationInfo app) {
+            if (mAgent != null) {
+                try {
+                    // unbind and tidy up even on timeout or failure, just in case
+                    mActivityManager.unbindBackupAgent(app);
+
+                    // The agent was running with a stub Application object, so shut it down.
+                    // !!! We hardcode the confirmation UI's package name here rather than use a
+                    //     manifest flag!  TODO something less direct.
+                    if (app.uid != Process.SYSTEM_UID
+                            && !app.packageName.equals("com.android.backupconfirm")) {
+                        if (DEBUG) Slog.d(TAG, "Killing host process");
+                        mActivityManager.killApplicationProcess(app.processName, app.uid);
+                    } else {
+                        if (DEBUG) Slog.d(TAG, "Not killing after full restore");
+                    }
+                } catch (RemoteException e) {
+                    Slog.d(TAG, "Lost app trying to shut down");
+                }
+                mAgent = null;
+            }
+        }
+
+        class RestoreInstallObserver extends IPackageInstallObserver.Stub {
+            final AtomicBoolean mDone = new AtomicBoolean();
+            String mPackageName;
+            int mResult;
+
+            public void reset() {
+                synchronized (mDone) {
+                    mDone.set(false);
+                }
+            }
+
+            public void waitForCompletion() {
+                synchronized (mDone) {
+                    while (mDone.get() == false) {
+                        try {
+                            mDone.wait();
+                        } catch (InterruptedException e) { }
+                    }
+                }
+            }
+
+            int getResult() {
+                return mResult;
+            }
+
+            @Override
+            public void packageInstalled(String packageName, int returnCode)
+                    throws RemoteException {
+                synchronized (mDone) {
+                    mResult = returnCode;
+                    mPackageName = packageName;
+                    mDone.set(true);
+                    mDone.notifyAll();
+                }
+            }
+        }
+
+        class RestoreDeleteObserver extends IPackageDeleteObserver.Stub {
+            final AtomicBoolean mDone = new AtomicBoolean();
+            int mResult;
+
+            public void reset() {
+                synchronized (mDone) {
+                    mDone.set(false);
+                }
+            }
+
+            public void waitForCompletion() {
+                synchronized (mDone) {
+                    while (mDone.get() == false) {
+                        try {
+                            mDone.wait();
+                        } catch (InterruptedException e) { }
+                    }
+                }
+            }
+
+            @Override
+            public void packageDeleted(String packageName, int returnCode) throws RemoteException {
+                synchronized (mDone) {
+                    mResult = returnCode;
+                    mDone.set(true);
+                    mDone.notifyAll();
+                }
+            }
+        }
+
+        final RestoreInstallObserver mInstallObserver = new RestoreInstallObserver();
+        final RestoreDeleteObserver mDeleteObserver = new RestoreDeleteObserver();
+
+        boolean installApk(FileMetadata info, String installerPackage, InputStream instream) {
+            boolean okay = true;
+
+            if (DEBUG) Slog.d(TAG, "Installing from backup: " + info.packageName);
+
+            // The file content is an .apk file.  Copy it out to a staging location and
+            // attempt to install it.
+            File apkFile = new File(mDataDir, info.packageName);
+            try {
+                FileOutputStream apkStream = new FileOutputStream(apkFile);
+                byte[] buffer = new byte[32 * 1024];
+                long size = info.size;
+                while (size > 0) {
+                    long toRead = (buffer.length < size) ? buffer.length : size;
+                    int didRead = instream.read(buffer, 0, (int)toRead);
+                    if (didRead >= 0) mBytes += didRead;
+                    apkStream.write(buffer, 0, didRead);
+                    size -= didRead;
+                }
+                apkStream.close();
+
+                // make sure the installer can read it
+                apkFile.setReadable(true, false);
+
+                // Now install it
+                Uri packageUri = Uri.fromFile(apkFile);
+                mInstallObserver.reset();
+                mPackageManager.installPackage(packageUri, mInstallObserver,
+                        PackageManager.INSTALL_REPLACE_EXISTING | PackageManager.INSTALL_FROM_ADB,
+                        installerPackage);
+                mInstallObserver.waitForCompletion();
+
+                if (mInstallObserver.getResult() != PackageManager.INSTALL_SUCCEEDED) {
+                    // The only time we continue to accept install of data even if the
+                    // apk install failed is if we had already determined that we could
+                    // accept the data regardless.
+                    if (mPackagePolicies.get(info.packageName) != RestorePolicy.ACCEPT) {
+                        okay = false;
+                    }
+                } else {
+                    // Okay, the install succeeded.  Make sure it was the right app.
+                    boolean uninstall = false;
+                    if (!mInstallObserver.mPackageName.equals(info.packageName)) {
+                        Slog.w(TAG, "Restore stream claimed to include apk for "
+                                + info.packageName + " but apk was really "
+                                + mInstallObserver.mPackageName);
+                        // delete the package we just put in place; it might be fraudulent
+                        okay = false;
+                        uninstall = true;
+                    } else {
+                        try {
+                            PackageInfo pkg = mPackageManager.getPackageInfo(info.packageName,
+                                    PackageManager.GET_SIGNATURES);
+                            if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
+                                Slog.w(TAG, "Restore stream contains apk of package "
+                                        + info.packageName + " but it disallows backup/restore");
+                                okay = false;
+                            } else {
+                                // So far so good -- do the signatures match the manifest?
+                                Signature[] sigs = mManifestSignatures.get(info.packageName);
+                                if (signaturesMatch(sigs, pkg)) {
+                                    // If this is a system-uid app without a declared backup agent,
+                                    // don't restore any of the file data.
+                                    if ((pkg.applicationInfo.uid < Process.FIRST_APPLICATION_UID)
+                                            && (pkg.applicationInfo.backupAgentName == null)) {
+                                        Slog.w(TAG, "Installed app " + info.packageName
+                                                + " has restricted uid and no agent");
+                                        okay = false;
+                                    }
+                                } else {
+                                    Slog.w(TAG, "Installed app " + info.packageName
+                                            + " signatures do not match restore manifest");
+                                    okay = false;
+                                    uninstall = true;
+                                }
+                            }
+                        } catch (NameNotFoundException e) {
+                            Slog.w(TAG, "Install of package " + info.packageName
+                                    + " succeeded but now not found");
+                            okay = false;
+                        }
+                    }
+
+                    // If we're not okay at this point, we need to delete the package
+                    // that we just installed.
+                    if (uninstall) {
+                        mDeleteObserver.reset();
+                        mPackageManager.deletePackage(mInstallObserver.mPackageName,
+                                mDeleteObserver, 0);
+                        mDeleteObserver.waitForCompletion();
+                    }
+                }
+            } catch (IOException e) {
+                Slog.e(TAG, "Unable to transcribe restored apk for install");
+                okay = false;
+            } finally {
+                apkFile.delete();
+            }
+
+            return okay;
+        }
+
+        // Given an actual file content size, consume the post-content padding mandated
+        // by the tar format.
+        void skipTarPadding(long size, InputStream instream) throws IOException {
+            long partial = (size + 512) % 512;
+            if (partial > 0) {
+                final int needed = 512 - (int)partial;
+                byte[] buffer = new byte[needed];
+                if (readExactly(instream, buffer, 0, needed) == needed) {
+                    mBytes += needed;
+                } else throw new IOException("Unexpected EOF in padding");
+            }
+        }
+
+        // Returns a policy constant; takes a buffer arg to reduce memory churn
+        RestorePolicy readAppManifest(FileMetadata info, InputStream instream)
+                throws IOException {
+            // Fail on suspiciously large manifest files
+            if (info.size > 64 * 1024) {
+                throw new IOException("Restore manifest too big; corrupt? size=" + info.size);
+            }
+
+            byte[] buffer = new byte[(int) info.size];
+            if (readExactly(instream, buffer, 0, (int)info.size) == info.size) {
+                mBytes += info.size;
+            } else throw new IOException("Unexpected EOF in manifest");
+
+            RestorePolicy policy = RestorePolicy.IGNORE;
+            String[] str = new String[1];
+            int offset = 0;
+
+            try {
+                offset = extractLine(buffer, offset, str);
+                int version = Integer.parseInt(str[0]);
+                if (version == BACKUP_MANIFEST_VERSION) {
+                    offset = extractLine(buffer, offset, str);
+                    String manifestPackage = str[0];
+                    // TODO: handle <original-package>
+                    if (manifestPackage.equals(info.packageName)) {
+                        offset = extractLine(buffer, offset, str);
+                        version = Integer.parseInt(str[0]);  // app version
+                        offset = extractLine(buffer, offset, str);
+                        int platformVersion = Integer.parseInt(str[0]);
+                        offset = extractLine(buffer, offset, str);
+                        info.installerPackageName = (str[0].length() > 0) ? str[0] : null;
+                        offset = extractLine(buffer, offset, str);
+                        boolean hasApk = str[0].equals("1");
+                        offset = extractLine(buffer, offset, str);
+                        int numSigs = Integer.parseInt(str[0]);
+                        if (numSigs > 0) {
+                            Signature[] sigs = new Signature[numSigs];
+                            for (int i = 0; i < numSigs; i++) {
+                                offset = extractLine(buffer, offset, str);
+                                sigs[i] = new Signature(str[0]);
+                            }
+                            mManifestSignatures.put(info.packageName, sigs);
+
+                            // Okay, got the manifest info we need...
+                            try {
+                                PackageInfo pkgInfo = mPackageManager.getPackageInfo(
+                                        info.packageName, PackageManager.GET_SIGNATURES);
+                                // Fall through to IGNORE if the app explicitly disallows backup
+                                final int flags = pkgInfo.applicationInfo.flags;
+                                if ((flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) {
+                                    // Restore system-uid-space packages only if they have
+                                    // defined a custom backup agent
+                                    if ((pkgInfo.applicationInfo.uid >= Process.FIRST_APPLICATION_UID)
+                                            || (pkgInfo.applicationInfo.backupAgentName != null)) {
+                                        // Verify signatures against any installed version; if they
+                                        // don't match, then we fall though and ignore the data.  The
+                                        // signatureMatch() method explicitly ignores the signature
+                                        // check for packages installed on the system partition, because
+                                        // such packages are signed with the platform cert instead of
+                                        // the app developer's cert, so they're different on every
+                                        // device.
+                                        if (signaturesMatch(sigs, pkgInfo)) {
+                                            if (pkgInfo.versionCode >= version) {
+                                                Slog.i(TAG, "Sig + version match; taking data");
+                                                policy = RestorePolicy.ACCEPT;
+                                            } else {
+                                                // The data is from a newer version of the app than
+                                                // is presently installed.  That means we can only
+                                                // use it if the matching apk is also supplied.
+                                                Slog.d(TAG, "Data version " + version
+                                                        + " is newer than installed version "
+                                                        + pkgInfo.versionCode + " - requiring apk");
+                                                policy = RestorePolicy.ACCEPT_IF_APK;
+                                            }
+                                        } else {
+                                            Slog.w(TAG, "Restore manifest signatures do not match "
+                                                    + "installed application for " + info.packageName);
+                                        }
+                                    } else {
+                                        Slog.w(TAG, "Package " + info.packageName
+                                                + " is system level with no agent");
+                                    }
+                                } else {
+                                    if (DEBUG) Slog.i(TAG, "Restore manifest from "
+                                            + info.packageName + " but allowBackup=false");
+                                }
+                            } catch (NameNotFoundException e) {
+                                // Okay, the target app isn't installed.  We can process
+                                // the restore properly only if the dataset provides the
+                                // apk file and we can successfully install it.
+                                if (DEBUG) Slog.i(TAG, "Package " + info.packageName
+                                        + " not installed; requiring apk in dataset");
+                                policy = RestorePolicy.ACCEPT_IF_APK;
+                            }
+
+                            if (policy == RestorePolicy.ACCEPT_IF_APK && !hasApk) {
+                                Slog.i(TAG, "Cannot restore package " + info.packageName
+                                        + " without the matching .apk");
+                            }
+                        } else {
+                            Slog.i(TAG, "Missing signature on backed-up package "
+                                    + info.packageName);
+                        }
+                    } else {
+                        Slog.i(TAG, "Expected package " + info.packageName
+                                + " but restore manifest claims " + manifestPackage);
+                    }
+                } else {
+                    Slog.i(TAG, "Unknown restore manifest version " + version
+                            + " for package " + info.packageName);
+                }
+            } catch (NumberFormatException e) {
+                Slog.w(TAG, "Corrupt restore manifest for package " + info.packageName);
+            } catch (IllegalArgumentException e) {
+                Slog.w(TAG, e.getMessage());
+            }
+
+            return policy;
+        }
+
+        // Builds a line from a byte buffer starting at 'offset', and returns
+        // the index of the next unconsumed data in the buffer.
+        int extractLine(byte[] buffer, int offset, String[] outStr) throws IOException {
+            final int end = buffer.length;
+            if (offset >= end) throw new IOException("Incomplete data");
+
+            int pos;
+            for (pos = offset; pos < end; pos++) {
+                byte c = buffer[pos];
+                // at LF we declare end of line, and return the next char as the
+                // starting point for the next time through
+                if (c == '\n') {
+                    break;
+                }
+            }
+            outStr[0] = new String(buffer, offset, pos - offset);
+            pos++;  // may be pointing an extra byte past the end but that's okay
+            return pos;
+        }
+
+        void dumpFileMetadata(FileMetadata info) {
+            if (DEBUG) {
+                StringBuilder b = new StringBuilder(128);
+
+                // mode string
+                b.append((info.type == BackupAgent.TYPE_DIRECTORY) ? 'd' : '-');
+                b.append(((info.mode & 0400) != 0) ? 'r' : '-');
+                b.append(((info.mode & 0200) != 0) ? 'w' : '-');
+                b.append(((info.mode & 0100) != 0) ? 'x' : '-');
+                b.append(((info.mode & 0040) != 0) ? 'r' : '-');
+                b.append(((info.mode & 0020) != 0) ? 'w' : '-');
+                b.append(((info.mode & 0010) != 0) ? 'x' : '-');
+                b.append(((info.mode & 0004) != 0) ? 'r' : '-');
+                b.append(((info.mode & 0002) != 0) ? 'w' : '-');
+                b.append(((info.mode & 0001) != 0) ? 'x' : '-');
+                b.append(String.format(" %9d ", info.size));
+
+                Date stamp = new Date(info.mtime);
+                b.append(new SimpleDateFormat("MMM dd HH:mm:ss ").format(stamp));
+
+                b.append(info.packageName);
+                b.append(" :: ");
+                b.append(info.domain);
+                b.append(" :: ");
+                b.append(info.path);
+
+                Slog.i(TAG, b.toString());
+            }
+        }
+        // Consume a tar file header block [sequence] and accumulate the relevant metadata
+        FileMetadata readTarHeaders(InputStream instream) throws IOException {
+            byte[] block = new byte[512];
+            FileMetadata info = null;
+
+            boolean gotHeader = readTarHeader(instream, block);
+            if (gotHeader) {
+                try {
+                    // okay, presume we're okay, and extract the various metadata
+                    info = new FileMetadata();
+                    info.size = extractRadix(block, 124, 12, 8);
+                    info.mtime = extractRadix(block, 136, 12, 8);
+                    info.mode = extractRadix(block, 100, 8, 8);
+
+                    info.path = extractString(block, 345, 155); // prefix
+                    String path = extractString(block, 0, 100);
+                    if (path.length() > 0) {
+                        if (info.path.length() > 0) info.path += '/';
+                        info.path += path;
+                    }
+
+                    // tar link indicator field: 1 byte at offset 156 in the header.
+                    int typeChar = block[156];
+                    if (typeChar == 'x') {
+                        // pax extended header, so we need to read that
+                        gotHeader = readPaxExtendedHeader(instream, info);
+                        if (gotHeader) {
+                            // and after a pax extended header comes another real header -- read
+                            // that to find the real file type
+                            gotHeader = readTarHeader(instream, block);
+                        }
+                        if (!gotHeader) throw new IOException("Bad or missing pax header");
+
+                        typeChar = block[156];
+                    }
+
+                    switch (typeChar) {
+                        case '0': info.type = BackupAgent.TYPE_FILE; break;
+                        case '5': {
+                            info.type = BackupAgent.TYPE_DIRECTORY;
+                            if (info.size != 0) {
+                                Slog.w(TAG, "Directory entry with nonzero size in header");
+                                info.size = 0;
+                            }
+                            break;
+                        }
+                        case 0: {
+                            // presume EOF
+                            if (DEBUG) Slog.w(TAG, "Saw type=0 in tar header block, info=" + info);
+                            return null;
+                        }
+                        default: {
+                            Slog.e(TAG, "Unknown tar entity type: " + typeChar);
+                            throw new IOException("Unknown entity type " + typeChar);
+                        }
+                    }
+
+                    // Parse out the path
+                    //
+                    // first: apps/shared/unrecognized
+                    if (FullBackup.SHARED_PREFIX.regionMatches(0,
+                            info.path, 0, FullBackup.SHARED_PREFIX.length())) {
+                        // File in shared storage.  !!! TODO: implement this.
+                        info.path = info.path.substring(FullBackup.SHARED_PREFIX.length());
+                        info.packageName = SHARED_BACKUP_AGENT_PACKAGE;
+                        info.domain = FullBackup.SHARED_STORAGE_TOKEN;
+                        if (DEBUG) Slog.i(TAG, "File in shared storage: " + info.path);
+                    } else if (FullBackup.APPS_PREFIX.regionMatches(0,
+                            info.path, 0, FullBackup.APPS_PREFIX.length())) {
+                        // App content!  Parse out the package name and domain
+
+                        // strip the apps/ prefix
+                        info.path = info.path.substring(FullBackup.APPS_PREFIX.length());
+
+                        // extract the package name
+                        int slash = info.path.indexOf('/');
+                        if (slash < 0) throw new IOException("Illegal semantic path in " + info.path);
+                        info.packageName = info.path.substring(0, slash);
+                        info.path = info.path.substring(slash+1);
+
+                        // if it's a manifest we're done, otherwise parse out the domains
+                        if (!info.path.equals(BACKUP_MANIFEST_FILENAME)) {
+                            slash = info.path.indexOf('/');
+                            if (slash < 0) throw new IOException("Illegal semantic path in non-manifest " + info.path);
+                            info.domain = info.path.substring(0, slash);
+                            info.path = info.path.substring(slash + 1);
+                        }
+                    }
+                } catch (IOException e) {
+                    if (DEBUG) {
+                        Slog.e(TAG, "Parse error in header: " + e.getMessage());
+                        HEXLOG(block);
+                    }
+                    throw e;
+                }
+            }
+            return info;
+        }
+
+        private void HEXLOG(byte[] block) {
+            int offset = 0;
+            int todo = block.length;
+            StringBuilder buf = new StringBuilder(64);
+            while (todo > 0) {
+                buf.append(String.format("%04x   ", offset));
+                int numThisLine = (todo > 16) ? 16 : todo;
+                for (int i = 0; i < numThisLine; i++) {
+                    buf.append(String.format("%02x ", block[offset+i]));
+                }
+                Slog.i("hexdump", buf.toString());
+                buf.setLength(0);
+                todo -= numThisLine;
+                offset += numThisLine;
+            }
+        }
+
+        // Read exactly the given number of bytes into a buffer at the stated offset.
+        // Returns false if EOF is encountered before the requested number of bytes
+        // could be read.
+        int readExactly(InputStream in, byte[] buffer, int offset, int size)
+                throws IOException {
+            if (size <= 0) throw new IllegalArgumentException("size must be > 0");
+
+            int soFar = 0;
+            while (soFar < size) {
+                int nRead = in.read(buffer, offset + soFar, size - soFar);
+                if (nRead <= 0) {
+                    if (MORE_DEBUG) Slog.w(TAG, "- wanted exactly " + size + " but got only " + soFar);
+                    break;
+                }
+                soFar += nRead;
+            }
+            return soFar;
+        }
+
+        boolean readTarHeader(InputStream instream, byte[] block) throws IOException {
+            final int got = readExactly(instream, block, 0, 512);
+            if (got == 0) return false;     // Clean EOF
+            if (got < 512) throw new IOException("Unable to read full block header");
+            mBytes += 512;
+            return true;
+        }
+
+        // overwrites 'info' fields based on the pax extended header
+        boolean readPaxExtendedHeader(InputStream instream, FileMetadata info)
+                throws IOException {
+            // We should never see a pax extended header larger than this
+            if (info.size > 32*1024) {
+                Slog.w(TAG, "Suspiciously large pax header size " + info.size
+                        + " - aborting");
+                throw new IOException("Sanity failure: pax header size " + info.size);
+            }
+
+            // read whole blocks, not just the content size
+            int numBlocks = (int)((info.size + 511) >> 9);
+            byte[] data = new byte[numBlocks * 512];
+            if (readExactly(instream, data, 0, data.length) < data.length) {
+                throw new IOException("Unable to read full pax header");
+            }
+            mBytes += data.length;
+
+            final int contentSize = (int) info.size;
+            int offset = 0;
+            do {
+                // extract the line at 'offset'
+                int eol = offset+1;
+                while (eol < contentSize && data[eol] != ' ') eol++;
+                if (eol >= contentSize) {
+                    // error: we just hit EOD looking for the end of the size field
+                    throw new IOException("Invalid pax data");
+                }
+                // eol points to the space between the count and the key
+                int linelen = (int) extractRadix(data, offset, eol - offset, 10);
+                int key = eol + 1;  // start of key=value
+                eol = offset + linelen - 1; // trailing LF
+                int value;
+                for (value = key+1; data[value] != '=' && value <= eol; value++);
+                if (value > eol) {
+                    throw new IOException("Invalid pax declaration");
+                }
+
+                // pax requires that key/value strings be in UTF-8
+                String keyStr = new String(data, key, value-key, "UTF-8");
+                // -1 to strip the trailing LF
+                String valStr = new String(data, value+1, eol-value-1, "UTF-8");
+
+                if ("path".equals(keyStr)) {
+                    info.path = valStr;
+                } else if ("size".equals(keyStr)) {
+                    info.size = Long.parseLong(valStr);
+                } else {
+                    if (DEBUG) Slog.i(TAG, "Unhandled pax key: " + key);
+                }
+
+                offset += linelen;
+            } while (offset < contentSize);
+
+            return true;
+        }
+
+        long extractRadix(byte[] data, int offset, int maxChars, int radix)
+                throws IOException {
+            long value = 0;
+            final int end = offset + maxChars;
+            for (int i = offset; i < end; i++) {
+                final byte b = data[i];
+                // Numeric fields in tar can terminate with either NUL or SPC
+                if (b == 0 || b == ' ') break;
+                if (b < '0' || b > ('0' + radix - 1)) {
+                    throw new IOException("Invalid number in header: '" + (char)b + "' for radix " + radix);
+                }
+                value = radix * value + (b - '0');
+            }
+            return value;
+        }
+
+        String extractString(byte[] data, int offset, int maxChars) throws IOException {
+            final int end = offset + maxChars;
+            int eos = offset;
+            // tar string fields terminate early with a NUL
+            while (eos < end && data[eos] != 0) eos++;
+            return new String(data, offset, eos-offset, "US-ASCII");
+        }
+
+        void sendStartRestore() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onStartRestore();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full restore observer went away: startRestore");
+                    mObserver = null;
+                }
+            }
+        }
+
+        void sendOnRestorePackage(String name) {
+            if (mObserver != null) {
+                try {
+                    // TODO: use a more user-friendly name string
+                    mObserver.onRestorePackage(name);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full restore observer went away: restorePackage");
+                    mObserver = null;
+                }
+            }
+        }
+
+        void sendEndRestore() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onEndRestore();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "full restore observer went away: endRestore");
+                    mObserver = null;
+                }
+            }
+        }
+    }
+
+    // ----- Restore handling -----
+
+    private boolean signaturesMatch(Signature[] storedSigs, PackageInfo target) {
+        // If the target resides on the system partition, we allow it to restore
+        // data from the like-named package in a restore set even if the signatures
+        // do not match.  (Unlike general applications, those flashed to the system
+        // partition will be signed with the device's platform certificate, so on
+        // different phones the same system app will have different signatures.)
+        if ((target.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+            if (DEBUG) Slog.v(TAG, "System app " + target.packageName + " - skipping sig check");
+            return true;
+        }
+
+        // Allow unsigned apps, but not signed on one device and unsigned on the other
+        // !!! TODO: is this the right policy?
+        Signature[] deviceSigs = target.signatures;
+        if (MORE_DEBUG) Slog.v(TAG, "signaturesMatch(): stored=" + storedSigs
+                + " device=" + deviceSigs);
+        if ((storedSigs == null || storedSigs.length == 0)
+                && (deviceSigs == null || deviceSigs.length == 0)) {
+            return true;
+        }
+        if (storedSigs == null || deviceSigs == null) {
+            return false;
+        }
+
+        // !!! TODO: this demands that every stored signature match one
+        // that is present on device, and does not demand the converse.
+        // Is this this right policy?
+        int nStored = storedSigs.length;
+        int nDevice = deviceSigs.length;
+
+        for (int i=0; i < nStored; i++) {
+            boolean match = false;
+            for (int j=0; j < nDevice; j++) {
+                if (storedSigs[i].equals(deviceSigs[j])) {
+                    match = true;
+                    break;
+                }
+            }
+            if (!match) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    enum RestoreState {
+        INITIAL,
+        DOWNLOAD_DATA,
+        PM_METADATA,
+        RUNNING_QUEUE,
+        FINAL
+    }
+
+    class PerformRestoreTask implements BackupRestoreTask {
+        private IBackupTransport mTransport;
+        private IRestoreObserver mObserver;
+        private long mToken;
+        private PackageInfo mTargetPackage;
+        private File mStateDir;
+        private int mPmToken;
+        private boolean mNeedFullBackup;
+        private HashSet<String> mFilterSet;
+        private long mStartRealtime;
+        private PackageManagerBackupAgent mPmAgent;
+        private List<PackageInfo> mAgentPackages;
+        private ArrayList<PackageInfo> mRestorePackages;
+        private RestoreState mCurrentState;
+        private int mCount;
+        private boolean mFinished;
+        private int mStatus;
+        private File mBackupDataName;
+        private File mNewStateName;
+        private File mSavedStateName;
+        private ParcelFileDescriptor mBackupData;
+        private ParcelFileDescriptor mNewState;
+        private PackageInfo mCurrentPackage;
+
+
+        class RestoreRequest {
+            public PackageInfo app;
+            public int storedAppVersion;
+
+            RestoreRequest(PackageInfo _app, int _version) {
+                app = _app;
+                storedAppVersion = _version;
+            }
+        }
+
+        PerformRestoreTask(IBackupTransport transport, String dirName, IRestoreObserver observer,
+                long restoreSetToken, PackageInfo targetPackage, int pmToken,
+                boolean needFullBackup, String[] filterSet) {
+            mCurrentState = RestoreState.INITIAL;
+            mFinished = false;
+            mPmAgent = null;
+
+            mTransport = transport;
+            mObserver = observer;
+            mToken = restoreSetToken;
+            mTargetPackage = targetPackage;
+            mPmToken = pmToken;
+            mNeedFullBackup = needFullBackup;
+
+            if (filterSet != null) {
+                mFilterSet = new HashSet<String>();
+                for (String pkg : filterSet) {
+                    mFilterSet.add(pkg);
+                }
+            } else {
+                mFilterSet = null;
+            }
+
+            mStateDir = new File(mBaseStateDir, dirName);
+        }
+
+        // Execute one tick of whatever state machine the task implements
+        @Override
+        public void execute() {
+            if (MORE_DEBUG) Slog.v(TAG, "*** Executing restore step: " + mCurrentState);
+            switch (mCurrentState) {
+                case INITIAL:
+                    beginRestore();
+                    break;
+
+                case DOWNLOAD_DATA:
+                    downloadRestoreData();
+                    break;
+
+                case PM_METADATA:
+                    restorePmMetadata();
+                    break;
+
+                case RUNNING_QUEUE:
+                    restoreNextAgent();
+                    break;
+
+                case FINAL:
+                    if (!mFinished) finalizeRestore();
+                    else {
+                        Slog.e(TAG, "Duplicate finish");
+                    }
+                    mFinished = true;
+                    break;
+            }
+        }
+
+        // Initialize and set up for the PM metadata restore, which comes first
+        void beginRestore() {
+            // Don't account time doing the restore as inactivity of the app
+            // that has opened a restore session.
+            mBackupHandler.removeMessages(MSG_RESTORE_TIMEOUT);
+
+            // Assume error until we successfully init everything
+            mStatus = BackupConstants.TRANSPORT_ERROR;
+
+            try {
+                // TODO: Log this before getAvailableRestoreSets, somehow
+                EventLog.writeEvent(EventLogTags.RESTORE_START, mTransport.transportDirName(), mToken);
+
+                // Get the list of all packages which have backup enabled.
+                // (Include the Package Manager metadata pseudo-package first.)
+                mRestorePackages = new ArrayList<PackageInfo>();
+                PackageInfo omPackage = new PackageInfo();
+                omPackage.packageName = PACKAGE_MANAGER_SENTINEL;
+                mRestorePackages.add(omPackage);
+
+                mAgentPackages = allAgentPackages();
+                if (mTargetPackage == null) {
+                    // if there's a filter set, strip out anything that isn't
+                    // present before proceeding
+                    if (mFilterSet != null) {
+                        for (int i = mAgentPackages.size() - 1; i >= 0; i--) {
+                            final PackageInfo pkg = mAgentPackages.get(i);
+                            if (! mFilterSet.contains(pkg.packageName)) {
+                                mAgentPackages.remove(i);
+                            }
+                        }
+                        if (MORE_DEBUG) {
+                            Slog.i(TAG, "Post-filter package set for restore:");
+                            for (PackageInfo p : mAgentPackages) {
+                                Slog.i(TAG, "    " + p);
+                            }
+                        }
+                    }
+                    mRestorePackages.addAll(mAgentPackages);
+                } else {
+                    // Just one package to attempt restore of
+                    mRestorePackages.add(mTargetPackage);
+                }
+
+                // let the observer know that we're running
+                if (mObserver != null) {
+                    try {
+                        // !!! TODO: get an actual count from the transport after
+                        // its startRestore() runs?
+                        mObserver.restoreStarting(mRestorePackages.size());
+                    } catch (RemoteException e) {
+                        Slog.d(TAG, "Restore observer died at restoreStarting");
+                        mObserver = null;
+                    }
+                }
+            } catch (RemoteException e) {
+                // Something has gone catastrophically wrong with the transport
+                Slog.e(TAG, "Error communicating with transport for restore");
+                executeNextState(RestoreState.FINAL);
+                return;
+            }
+
+            mStatus = BackupConstants.TRANSPORT_OK;
+            executeNextState(RestoreState.DOWNLOAD_DATA);
+        }
+
+        void downloadRestoreData() {
+            // Note that the download phase can be very time consuming, but we're executing
+            // it inline here on the looper.  This is "okay" because it is not calling out to
+            // third party code; the transport is "trusted," and so we assume it is being a
+            // good citizen and timing out etc when appropriate.
+            //
+            // TODO: when appropriate, move the download off the looper and rearrange the
+            //       error handling around that.
+            try {
+                mStatus = mTransport.startRestore(mToken,
+                        mRestorePackages.toArray(new PackageInfo[0]));
+                if (mStatus != BackupConstants.TRANSPORT_OK) {
+                    Slog.e(TAG, "Error starting restore operation");
+                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                }
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Error communicating with transport for restore");
+                EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                mStatus = BackupConstants.TRANSPORT_ERROR;
+                executeNextState(RestoreState.FINAL);
+                return;
+            }
+
+            // Successful download of the data to be parceled out to the apps, so off we go.
+            executeNextState(RestoreState.PM_METADATA);
+        }
+
+        void restorePmMetadata() {
+            try {
+                String packageName = mTransport.nextRestorePackage();
+                if (packageName == null) {
+                    Slog.e(TAG, "Error getting first restore package");
+                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                    mStatus = BackupConstants.TRANSPORT_ERROR;
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                } else if (packageName.equals("")) {
+                    Slog.i(TAG, "No restore data available");
+                    int millis = (int) (SystemClock.elapsedRealtime() - mStartRealtime);
+                    EventLog.writeEvent(EventLogTags.RESTORE_SUCCESS, 0, millis);
+                    mStatus = BackupConstants.TRANSPORT_OK;
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                } else if (!packageName.equals(PACKAGE_MANAGER_SENTINEL)) {
+                    Slog.e(TAG, "Expected restore data for \"" + PACKAGE_MANAGER_SENTINEL
+                            + "\", found only \"" + packageName + "\"");
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, PACKAGE_MANAGER_SENTINEL,
+                            "Package manager data missing");
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                }
+
+                // Pull the Package Manager metadata from the restore set first
+                PackageInfo omPackage = new PackageInfo();
+                omPackage.packageName = PACKAGE_MANAGER_SENTINEL;
+                mPmAgent = new PackageManagerBackupAgent(
+                        mPackageManager, mAgentPackages);
+                initiateOneRestore(omPackage, 0, IBackupAgent.Stub.asInterface(mPmAgent.onBind()),
+                        mNeedFullBackup);
+                // The PM agent called operationComplete() already, because our invocation
+                // of it is process-local and therefore synchronous.  That means that a
+                // RUNNING_QUEUE message is already enqueued.  Only if we're unable to
+                // proceed with running the queue do we remove that pending message and
+                // jump straight to the FINAL state.
+
+                // Verify that the backup set includes metadata.  If not, we can't do
+                // signature/version verification etc, so we simply do not proceed with
+                // the restore operation.
+                if (!mPmAgent.hasMetadata()) {
+                    Slog.e(TAG, "No restore metadata available, so not restoring settings");
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, PACKAGE_MANAGER_SENTINEL,
+                    "Package manager restore metadata missing");
+                    mStatus = BackupConstants.TRANSPORT_ERROR;
+                    mBackupHandler.removeMessages(MSG_BACKUP_RESTORE_STEP, this);
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                }
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Error communicating with transport for restore");
+                EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                mStatus = BackupConstants.TRANSPORT_ERROR;
+                mBackupHandler.removeMessages(MSG_BACKUP_RESTORE_STEP, this);
+                executeNextState(RestoreState.FINAL);
+                return;
+            }
+
+            // Metadata is intact, so we can now run the restore queue.  If we get here,
+            // we have already enqueued the necessary next-step message on the looper.
+        }
+
+        void restoreNextAgent() {
+            try {
+                String packageName = mTransport.nextRestorePackage();
+
+                if (packageName == null) {
+                    Slog.e(TAG, "Error getting next restore package");
+                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                } else if (packageName.equals("")) {
+                    if (DEBUG) Slog.v(TAG, "No next package, finishing restore");
+                    int millis = (int) (SystemClock.elapsedRealtime() - mStartRealtime);
+                    EventLog.writeEvent(EventLogTags.RESTORE_SUCCESS, mCount, millis);
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                }
+
+                if (mObserver != null) {
+                    try {
+                        mObserver.onUpdate(mCount, packageName);
+                    } catch (RemoteException e) {
+                        Slog.d(TAG, "Restore observer died in onUpdate");
+                        mObserver = null;
+                    }
+                }
+
+                Metadata metaInfo = mPmAgent.getRestoredMetadata(packageName);
+                if (metaInfo == null) {
+                    Slog.e(TAG, "Missing metadata for " + packageName);
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
+                            "Package metadata missing");
+                    executeNextState(RestoreState.RUNNING_QUEUE);
+                    return;
+                }
+
+                PackageInfo packageInfo;
+                try {
+                    int flags = PackageManager.GET_SIGNATURES;
+                    packageInfo = mPackageManager.getPackageInfo(packageName, flags);
+                } catch (NameNotFoundException e) {
+                    Slog.e(TAG, "Invalid package restoring data", e);
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
+                            "Package missing on device");
+                    executeNextState(RestoreState.RUNNING_QUEUE);
+                    return;
+                }
+
+                if (packageInfo.applicationInfo.backupAgentName == null
+                        || "".equals(packageInfo.applicationInfo.backupAgentName)) {
+                    if (DEBUG) {
+                        Slog.i(TAG, "Data exists for package " + packageName
+                                + " but app has no agent; skipping");
+                    }
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
+                            "Package has no agent");
+                    executeNextState(RestoreState.RUNNING_QUEUE);
+                    return;
+                }
+
+                if (metaInfo.versionCode > packageInfo.versionCode) {
+                    // Data is from a "newer" version of the app than we have currently
+                    // installed.  If the app has not declared that it is prepared to
+                    // handle this case, we do not attempt the restore.
+                    if ((packageInfo.applicationInfo.flags
+                            & ApplicationInfo.FLAG_RESTORE_ANY_VERSION) == 0) {
+                        String message = "Version " + metaInfo.versionCode
+                        + " > installed version " + packageInfo.versionCode;
+                        Slog.w(TAG, "Package " + packageName + ": " + message);
+                        EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE,
+                                packageName, message);
+                        executeNextState(RestoreState.RUNNING_QUEUE);
+                        return;
+                    } else {
+                        if (DEBUG) Slog.v(TAG, "Version " + metaInfo.versionCode
+                                + " > installed " + packageInfo.versionCode
+                                + " but restoreAnyVersion");
+                    }
+                }
+
+                if (!signaturesMatch(metaInfo.signatures, packageInfo)) {
+                    Slog.w(TAG, "Signature mismatch restoring " + packageName);
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
+                            "Signature mismatch");
+                    executeNextState(RestoreState.RUNNING_QUEUE);
+                    return;
+                }
+
+                if (DEBUG) Slog.v(TAG, "Package " + packageName
+                        + " restore version [" + metaInfo.versionCode
+                        + "] is compatible with installed version ["
+                        + packageInfo.versionCode + "]");
+
+                // Then set up and bind the agent
+                IBackupAgent agent = bindToAgentSynchronous(
+                        packageInfo.applicationInfo,
+                        IApplicationThread.BACKUP_MODE_INCREMENTAL);
+                if (agent == null) {
+                    Slog.w(TAG, "Can't find backup agent for " + packageName);
+                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
+                            "Restore agent missing");
+                    executeNextState(RestoreState.RUNNING_QUEUE);
+                    return;
+                }
+
+                // And then finally start the restore on this agent
+                try {
+                    initiateOneRestore(packageInfo, metaInfo.versionCode, agent, mNeedFullBackup);
+                    ++mCount;
+                } catch (Exception e) {
+                    Slog.e(TAG, "Error when attempting restore: " + e.toString());
+                    agentErrorCleanup();
+                    executeNextState(RestoreState.RUNNING_QUEUE);
+                }
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Unable to fetch restore data from transport");
+                mStatus = BackupConstants.TRANSPORT_ERROR;
+                executeNextState(RestoreState.FINAL);
+            }
+        }
+
+        void finalizeRestore() {
+            if (MORE_DEBUG) Slog.d(TAG, "finishing restore mObserver=" + mObserver);
+
+            try {
+                mTransport.finishRestore();
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Error finishing restore", e);
+            }
+
+            if (mObserver != null) {
+                try {
+                    mObserver.restoreFinished(mStatus);
+                } catch (RemoteException e) {
+                    Slog.d(TAG, "Restore observer died at restoreFinished");
+                }
+            }
+
+            // If this was a restoreAll operation, record that this was our
+            // ancestral dataset, as well as the set of apps that are possibly
+            // restoreable from the dataset
+            if (mTargetPackage == null && mPmAgent != null) {
+                mAncestralPackages = mPmAgent.getRestoredPackages();
+                mAncestralToken = mToken;
+                writeRestoreTokens();
+            }
+
+            // We must under all circumstances tell the Package Manager to
+            // proceed with install notifications if it's waiting for us.
+            if (mPmToken > 0) {
+                if (MORE_DEBUG) Slog.v(TAG, "finishing PM token " + mPmToken);
+                try {
+                    mPackageManagerBinder.finishPackageInstall(mPmToken);
+                } catch (RemoteException e) { /* can't happen */ }
+            }
+
+            // Furthermore we need to reset the session timeout clock
+            mBackupHandler.removeMessages(MSG_RESTORE_TIMEOUT);
+            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_TIMEOUT,
+                    TIMEOUT_RESTORE_INTERVAL);
+
+            // done; we can finally release the wakelock
+            Slog.i(TAG, "Restore complete.");
+            mWakelock.release();
+        }
+
+        // Call asynchronously into the app, passing it the restore data.  The next step
+        // after this is always a callback, either operationComplete() or handleTimeout().
+        void initiateOneRestore(PackageInfo app, int appVersionCode, IBackupAgent agent,
+                boolean needFullBackup) {
+            mCurrentPackage = app;
+            final String packageName = app.packageName;
+
+            if (DEBUG) Slog.d(TAG, "initiateOneRestore packageName=" + packageName);
+
+            // !!! TODO: get the dirs from the transport
+            mBackupDataName = new File(mDataDir, packageName + ".restore");
+            mNewStateName = new File(mStateDir, packageName + ".new");
+            mSavedStateName = new File(mStateDir, packageName);
+
+            final int token = generateToken();
+            try {
+                // Run the transport's restore pass
+                mBackupData = ParcelFileDescriptor.open(mBackupDataName,
+                            ParcelFileDescriptor.MODE_READ_WRITE |
+                            ParcelFileDescriptor.MODE_CREATE |
+                            ParcelFileDescriptor.MODE_TRUNCATE);
+
+                if (!SELinux.restorecon(mBackupDataName)) {
+                    Slog.e(TAG, "SElinux restorecon failed for " + mBackupDataName);
+                }
+
+                if (mTransport.getRestoreData(mBackupData) != BackupConstants.TRANSPORT_OK) {
+                    // Transport-level failure, so we wind everything up and
+                    // terminate the restore operation.
+                    Slog.e(TAG, "Error getting restore data for " + packageName);
+                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
+                    mBackupData.close();
+                    mBackupDataName.delete();
+                    executeNextState(RestoreState.FINAL);
+                    return;
+                }
+
+                // Okay, we have the data.  Now have the agent do the restore.
+                mBackupData.close();
+                mBackupData = ParcelFileDescriptor.open(mBackupDataName,
+                            ParcelFileDescriptor.MODE_READ_ONLY);
+
+                mNewState = ParcelFileDescriptor.open(mNewStateName,
+                            ParcelFileDescriptor.MODE_READ_WRITE |
+                            ParcelFileDescriptor.MODE_CREATE |
+                            ParcelFileDescriptor.MODE_TRUNCATE);
+
+                // Kick off the restore, checking for hung agents
+                prepareOperationTimeout(token, TIMEOUT_RESTORE_INTERVAL, this);
+                agent.doRestore(mBackupData, appVersionCode, mNewState, token, mBackupManagerBinder);
+            } catch (Exception e) {
+                Slog.e(TAG, "Unable to call app for restore: " + packageName, e);
+                EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName, e.toString());
+                agentErrorCleanup();    // clears any pending timeout messages as well
+
+                // After a restore failure we go back to running the queue.  If there
+                // are no more packages to be restored that will be handled by the
+                // next step.
+                executeNextState(RestoreState.RUNNING_QUEUE);
+            }
+        }
+
+        void agentErrorCleanup() {
+            // If the agent fails restore, it might have put the app's data
+            // into an incoherent state.  For consistency we wipe its data
+            // again in this case before continuing with normal teardown
+            clearApplicationDataSynchronous(mCurrentPackage.packageName);
+            agentCleanup();
+        }
+
+        void agentCleanup() {
+            mBackupDataName.delete();
+            try { if (mBackupData != null) mBackupData.close(); } catch (IOException e) {}
+            try { if (mNewState != null) mNewState.close(); } catch (IOException e) {}
+            mBackupData = mNewState = null;
+
+            // if everything went okay, remember the recorded state now
+            //
+            // !!! TODO: the restored data should be migrated on the server
+            // side into the current dataset.  In that case the new state file
+            // we just created would reflect the data already extant in the
+            // backend, so there'd be nothing more to do.  Until that happens,
+            // however, we need to make sure that we record the data to the
+            // current backend dataset.  (Yes, this means shipping the data over
+            // the wire in both directions.  That's bad, but consistency comes
+            // first, then efficiency.)  Once we introduce server-side data
+            // migration to the newly-restored device's dataset, we will change
+            // the following from a discard of the newly-written state to the
+            // "correct" operation of renaming into the canonical state blob.
+            mNewStateName.delete();                      // TODO: remove; see above comment
+            //mNewStateName.renameTo(mSavedStateName);   // TODO: replace with this
+
+            // If this wasn't the PM pseudopackage, tear down the agent side
+            if (mCurrentPackage.applicationInfo != null) {
+                // unbind and tidy up even on timeout or failure
+                try {
+                    mActivityManager.unbindBackupAgent(mCurrentPackage.applicationInfo);
+
+                    // The agent was probably running with a stub Application object,
+                    // which isn't a valid run mode for the main app logic.  Shut
+                    // down the app so that next time it's launched, it gets the
+                    // usual full initialization.  Note that this is only done for
+                    // full-system restores: when a single app has requested a restore,
+                    // it is explicitly not killed following that operation.
+                    if (mTargetPackage == null && (mCurrentPackage.applicationInfo.flags
+                            & ApplicationInfo.FLAG_KILL_AFTER_RESTORE) != 0) {
+                        if (DEBUG) Slog.d(TAG, "Restore complete, killing host process of "
+                                + mCurrentPackage.applicationInfo.processName);
+                        mActivityManager.killApplicationProcess(
+                                mCurrentPackage.applicationInfo.processName,
+                                mCurrentPackage.applicationInfo.uid);
+                    }
+                } catch (RemoteException e) {
+                    // can't happen; we run in the same process as the activity manager
+                }
+            }
+
+            // The caller is responsible for reestablishing the state machine; our
+            // responsibility here is to clear the decks for whatever comes next.
+            mBackupHandler.removeMessages(MSG_TIMEOUT, this);
+            synchronized (mCurrentOpLock) {
+                mCurrentOperations.clear();
+            }
+        }
+
+        // A call to agent.doRestore() has been positively acknowledged as complete
+        @Override
+        public void operationComplete() {
+            int size = (int) mBackupDataName.length();
+            EventLog.writeEvent(EventLogTags.RESTORE_PACKAGE, mCurrentPackage.packageName, size);
+            // Just go back to running the restore queue
+            agentCleanup();
+
+            executeNextState(RestoreState.RUNNING_QUEUE);
+        }
+
+        // A call to agent.doRestore() has timed out
+        @Override
+        public void handleTimeout() {
+            Slog.e(TAG, "Timeout restoring application " + mCurrentPackage.packageName);
+            EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE,
+                    mCurrentPackage.packageName, "restore timeout");
+            // Handle like an agent that threw on invocation: wipe it and go on to the next
+            agentErrorCleanup();
+            executeNextState(RestoreState.RUNNING_QUEUE);
+        }
+
+        void executeNextState(RestoreState nextState) {
+            if (MORE_DEBUG) Slog.i(TAG, " => executing next step on "
+                    + this + " nextState=" + nextState);
+            mCurrentState = nextState;
+            Message msg = mBackupHandler.obtainMessage(MSG_BACKUP_RESTORE_STEP, this);
+            mBackupHandler.sendMessage(msg);
+        }
+    }
+
+    class PerformClearTask implements Runnable {
+        IBackupTransport mTransport;
+        PackageInfo mPackage;
+
+        PerformClearTask(IBackupTransport transport, PackageInfo packageInfo) {
+            mTransport = transport;
+            mPackage = packageInfo;
+        }
+
+        public void run() {
+            try {
+                // Clear the on-device backup state to ensure a full backup next time
+                File stateDir = new File(mBaseStateDir, mTransport.transportDirName());
+                File stateFile = new File(stateDir, mPackage.packageName);
+                stateFile.delete();
+
+                // Tell the transport to remove all the persistent storage for the app
+                // TODO - need to handle failures
+                mTransport.clearBackupData(mPackage);
+            } catch (RemoteException e) {
+                // can't happen; the transport is local
+            } catch (Exception e) {
+                Slog.e(TAG, "Transport threw attempting to clear data for " + mPackage);
+            } finally {
+                try {
+                    // TODO - need to handle failures
+                    mTransport.finishBackup();
+                } catch (RemoteException e) {
+                    // can't happen; the transport is local
+                }
+
+                // Last but not least, release the cpu
+                mWakelock.release();
+            }
+        }
+    }
+
+    class PerformInitializeTask implements Runnable {
+        HashSet<String> mQueue;
+
+        PerformInitializeTask(HashSet<String> transportNames) {
+            mQueue = transportNames;
+        }
+
+        public void run() {
+            try {
+                for (String transportName : mQueue) {
+                    IBackupTransport transport = getTransport(transportName);
+                    if (transport == null) {
+                        Slog.e(TAG, "Requested init for " + transportName + " but not found");
+                        continue;
+                    }
+
+                    Slog.i(TAG, "Initializing (wiping) backup transport storage: " + transportName);
+                    EventLog.writeEvent(EventLogTags.BACKUP_START, transport.transportDirName());
+                    long startRealtime = SystemClock.elapsedRealtime();
+                    int status = transport.initializeDevice();
+
+                    if (status == BackupConstants.TRANSPORT_OK) {
+                        status = transport.finishBackup();
+                    }
+
+                    // Okay, the wipe really happened.  Clean up our local bookkeeping.
+                    if (status == BackupConstants.TRANSPORT_OK) {
+                        Slog.i(TAG, "Device init successful");
+                        int millis = (int) (SystemClock.elapsedRealtime() - startRealtime);
+                        EventLog.writeEvent(EventLogTags.BACKUP_INITIALIZE);
+                        resetBackupState(new File(mBaseStateDir, transport.transportDirName()));
+                        EventLog.writeEvent(EventLogTags.BACKUP_SUCCESS, 0, millis);
+                        synchronized (mQueueLock) {
+                            recordInitPendingLocked(false, transportName);
+                        }
+                    } else {
+                        // If this didn't work, requeue this one and try again
+                        // after a suitable interval
+                        Slog.e(TAG, "Transport error in initializeDevice()");
+                        EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE, "(initialize)");
+                        synchronized (mQueueLock) {
+                            recordInitPendingLocked(true, transportName);
+                        }
+                        // do this via another alarm to make sure of the wakelock states
+                        long delay = transport.requestBackupTime();
+                        if (DEBUG) Slog.w(TAG, "init failed on "
+                                + transportName + " resched in " + delay);
+                        mAlarmManager.set(AlarmManager.RTC_WAKEUP,
+                                System.currentTimeMillis() + delay, mRunInitIntent);
+                    }
+                }
+            } catch (RemoteException e) {
+                // can't happen; the transports are local
+            } catch (Exception e) {
+                Slog.e(TAG, "Unexpected error performing init", e);
+            } finally {
+                // Done; release the wakelock
+                mWakelock.release();
+            }
+        }
+    }
+
+    private void dataChangedImpl(String packageName) {
+        HashSet<String> targets = dataChangedTargets(packageName);
+        dataChangedImpl(packageName, targets);
+    }
+
+    private void dataChangedImpl(String packageName, HashSet<String> targets) {
+        // Record that we need a backup pass for the caller.  Since multiple callers
+        // may share a uid, we need to note all candidates within that uid and schedule
+        // a backup pass for each of them.
+        EventLog.writeEvent(EventLogTags.BACKUP_DATA_CHANGED, packageName);
+
+        if (targets == null) {
+            Slog.w(TAG, "dataChanged but no participant pkg='" + packageName + "'"
+                   + " uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        synchronized (mQueueLock) {
+            // Note that this client has made data changes that need to be backed up
+            if (targets.contains(packageName)) {
+                // Add the caller to the set of pending backups.  If there is
+                // one already there, then overwrite it, but no harm done.
+                BackupRequest req = new BackupRequest(packageName);
+                if (mPendingBackups.put(packageName, req) == null) {
+                    if (DEBUG) Slog.d(TAG, "Now staging backup of " + packageName);
+
+                    // Journal this request in case of crash.  The put()
+                    // operation returned null when this package was not already
+                    // in the set; we want to avoid touching the disk redundantly.
+                    writeToJournalLocked(packageName);
+
+                    if (MORE_DEBUG) {
+                        int numKeys = mPendingBackups.size();
+                        Slog.d(TAG, "Now awaiting backup for " + numKeys + " participants:");
+                        for (BackupRequest b : mPendingBackups.values()) {
+                            Slog.d(TAG, "    + " + b);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // Note: packageName is currently unused, but may be in the future
+    private HashSet<String> dataChangedTargets(String packageName) {
+        // If the caller does not hold the BACKUP permission, it can only request a
+        // backup of its own data.
+        if ((mContext.checkPermission(android.Manifest.permission.BACKUP, Binder.getCallingPid(),
+                Binder.getCallingUid())) == PackageManager.PERMISSION_DENIED) {
+            synchronized (mBackupParticipants) {
+                return mBackupParticipants.get(Binder.getCallingUid());
+            }
+        }
+
+        // a caller with full permission can ask to back up any participating app
+        // !!! TODO: allow backup of ANY app?
+        HashSet<String> targets = new HashSet<String>();
+        synchronized (mBackupParticipants) {
+            int N = mBackupParticipants.size();
+            for (int i = 0; i < N; i++) {
+                HashSet<String> s = mBackupParticipants.valueAt(i);
+                if (s != null) {
+                    targets.addAll(s);
+                }
+            }
+        }
+        return targets;
+    }
+
+    private void writeToJournalLocked(String str) {
+        RandomAccessFile out = null;
+        try {
+            if (mJournal == null) mJournal = File.createTempFile("journal", null, mJournalDir);
+            out = new RandomAccessFile(mJournal, "rws");
+            out.seek(out.length());
+            out.writeUTF(str);
+        } catch (IOException e) {
+            Slog.e(TAG, "Can't write " + str + " to backup journal", e);
+            mJournal = null;
+        } finally {
+            try { if (out != null) out.close(); } catch (IOException e) {}
+        }
+    }
+
+    // ----- IBackupManager binder interface -----
+
+    public void dataChanged(final String packageName) {
+        final int callingUserHandle = UserHandle.getCallingUserId();
+        if (callingUserHandle != UserHandle.USER_OWNER) {
+            // App is running under a non-owner user profile.  For now, we do not back
+            // up data from secondary user profiles.
+            // TODO: backups for all user profiles.
+            if (MORE_DEBUG) {
+                Slog.v(TAG, "dataChanged(" + packageName + ") ignored because it's user "
+                        + callingUserHandle);
+            }
+            return;
+        }
+
+        final HashSet<String> targets = dataChangedTargets(packageName);
+        if (targets == null) {
+            Slog.w(TAG, "dataChanged but no participant pkg='" + packageName + "'"
+                   + " uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        mBackupHandler.post(new Runnable() {
+                public void run() {
+                    dataChangedImpl(packageName, targets);
+                }
+            });
+    }
+
+    // Clear the given package's backup data from the current transport
+    public void clearBackupData(String transportName, String packageName) {
+        if (DEBUG) Slog.v(TAG, "clearBackupData() of " + packageName + " on " + transportName);
+        PackageInfo info;
+        try {
+            info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
+        } catch (NameNotFoundException e) {
+            Slog.d(TAG, "No such package '" + packageName + "' - not clearing backup data");
+            return;
+        }
+
+        // If the caller does not hold the BACKUP permission, it can only request a
+        // wipe of its own backed-up data.
+        HashSet<String> apps;
+        if ((mContext.checkPermission(android.Manifest.permission.BACKUP, Binder.getCallingPid(),
+                Binder.getCallingUid())) == PackageManager.PERMISSION_DENIED) {
+            apps = mBackupParticipants.get(Binder.getCallingUid());
+        } else {
+            // a caller with full permission can ask to back up any participating app
+            // !!! TODO: allow data-clear of ANY app?
+            if (DEBUG) Slog.v(TAG, "Privileged caller, allowing clear of other apps");
+            apps = new HashSet<String>();
+            int N = mBackupParticipants.size();
+            for (int i = 0; i < N; i++) {
+                HashSet<String> s = mBackupParticipants.valueAt(i);
+                if (s != null) {
+                    apps.addAll(s);
+                }
+            }
+        }
+
+        // Is the given app an available participant?
+        if (apps.contains(packageName)) {
+            // found it; fire off the clear request
+            if (DEBUG) Slog.v(TAG, "Found the app - running clear process");
+            mBackupHandler.removeMessages(MSG_RETRY_CLEAR);
+            synchronized (mQueueLock) {
+                final IBackupTransport transport = getTransport(transportName);
+                if (transport == null) {
+                    // transport is currently unavailable -- make sure to retry
+                    Message msg = mBackupHandler.obtainMessage(MSG_RETRY_CLEAR,
+                            new ClearRetryParams(transportName, packageName));
+                    mBackupHandler.sendMessageDelayed(msg, TRANSPORT_RETRY_INTERVAL);
+                    return;
+                }
+                long oldId = Binder.clearCallingIdentity();
+                mWakelock.acquire();
+                Message msg = mBackupHandler.obtainMessage(MSG_RUN_CLEAR,
+                        new ClearParams(transport, info));
+                mBackupHandler.sendMessage(msg);
+                Binder.restoreCallingIdentity(oldId);
+            }
+        }
+    }
+
+    // Run a backup pass immediately for any applications that have declared
+    // that they have pending updates.
+    public void backupNow() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "backupNow");
+
+        if (DEBUG) Slog.v(TAG, "Scheduling immediate backup pass");
+        synchronized (mQueueLock) {
+            // Because the alarms we are using can jitter, and we want an *immediate*
+            // backup pass to happen, we restart the timer beginning with "next time,"
+            // then manually fire the backup trigger intent ourselves.
+            startBackupAlarmsLocked(BACKUP_INTERVAL);
+            try {
+                mRunBackupIntent.send();
+            } catch (PendingIntent.CanceledException e) {
+                // should never happen
+                Slog.e(TAG, "run-backup intent cancelled!");
+            }
+        }
+    }
+
+    boolean deviceIsProvisioned() {
+        final ContentResolver resolver = mContext.getContentResolver();
+        return (Settings.Global.getInt(resolver, Settings.Global.DEVICE_PROVISIONED, 0) != 0);
+    }
+
+    // Run a *full* backup pass for the given package, writing the resulting data stream
+    // to the supplied file descriptor.  This method is synchronous and does not return
+    // to the caller until the backup has been completed.
+    public void fullBackup(ParcelFileDescriptor fd, boolean includeApks,
+            boolean includeObbs, boolean includeShared,
+            boolean doAllApps, boolean includeSystem, String[] pkgList) {
+        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
+
+        final int callingUserHandle = UserHandle.getCallingUserId();
+        if (callingUserHandle != UserHandle.USER_OWNER) {
+            throw new IllegalStateException("Backup supported only for the device owner");
+        }
+
+        // Validate
+        if (!doAllApps) {
+            if (!includeShared) {
+                // If we're backing up shared data (sdcard or equivalent), then we can run
+                // without any supplied app names.  Otherwise, we'd be doing no work, so
+                // report the error.
+                if (pkgList == null || pkgList.length == 0) {
+                    throw new IllegalArgumentException(
+                            "Backup requested but neither shared nor any apps named");
+                }
+            }
+        }
+
+        long oldId = Binder.clearCallingIdentity();
+        try {
+            // Doesn't make sense to do a full backup prior to setup
+            if (!deviceIsProvisioned()) {
+                Slog.i(TAG, "Full backup not supported before setup");
+                return;
+            }
+
+            if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks
+                    + " obb=" + includeObbs + " shared=" + includeShared + " all=" + doAllApps
+                    + " pkgs=" + pkgList);
+            Slog.i(TAG, "Beginning full backup...");
+
+            FullBackupParams params = new FullBackupParams(fd, includeApks, includeObbs,
+                    includeShared, doAllApps, includeSystem, pkgList);
+            final int token = generateToken();
+            synchronized (mFullConfirmations) {
+                mFullConfirmations.put(token, params);
+            }
+
+            // start up the confirmation UI
+            if (DEBUG) Slog.d(TAG, "Starting backup confirmation UI, token=" + token);
+            if (!startConfirmationUi(token, FullBackup.FULL_BACKUP_INTENT_ACTION)) {
+                Slog.e(TAG, "Unable to launch full backup confirmation");
+                mFullConfirmations.delete(token);
+                return;
+            }
+
+            // make sure the screen is lit for the user interaction
+            mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
+
+            // start the confirmation countdown
+            startConfirmationTimeout(token, params);
+
+            // wait for the backup to be performed
+            if (DEBUG) Slog.d(TAG, "Waiting for full backup completion...");
+            waitForCompletion(params);
+        } finally {
+            try {
+                fd.close();
+            } catch (IOException e) {
+                // just eat it
+            }
+            Binder.restoreCallingIdentity(oldId);
+            Slog.d(TAG, "Full backup processing complete.");
+        }
+    }
+
+    public void fullRestore(ParcelFileDescriptor fd) {
+        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullRestore");
+
+        final int callingUserHandle = UserHandle.getCallingUserId();
+        if (callingUserHandle != UserHandle.USER_OWNER) {
+            throw new IllegalStateException("Restore supported only for the device owner");
+        }
+
+        long oldId = Binder.clearCallingIdentity();
+
+        try {
+            // Check whether the device has been provisioned -- we don't handle
+            // full restores prior to completing the setup process.
+            if (!deviceIsProvisioned()) {
+                Slog.i(TAG, "Full restore not permitted before setup");
+                return;
+            }
+
+            Slog.i(TAG, "Beginning full restore...");
+
+            FullRestoreParams params = new FullRestoreParams(fd);
+            final int token = generateToken();
+            synchronized (mFullConfirmations) {
+                mFullConfirmations.put(token, params);
+            }
+
+            // start up the confirmation UI
+            if (DEBUG) Slog.d(TAG, "Starting restore confirmation UI, token=" + token);
+            if (!startConfirmationUi(token, FullBackup.FULL_RESTORE_INTENT_ACTION)) {
+                Slog.e(TAG, "Unable to launch full restore confirmation");
+                mFullConfirmations.delete(token);
+                return;
+            }
+
+            // make sure the screen is lit for the user interaction
+            mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
+
+            // start the confirmation countdown
+            startConfirmationTimeout(token, params);
+
+            // wait for the restore to be performed
+            if (DEBUG) Slog.d(TAG, "Waiting for full restore completion...");
+            waitForCompletion(params);
+        } finally {
+            try {
+                fd.close();
+            } catch (IOException e) {
+                Slog.w(TAG, "Error trying to close fd after full restore: " + e);
+            }
+            Binder.restoreCallingIdentity(oldId);
+            Slog.i(TAG, "Full restore processing complete.");
+        }
+    }
+
+    boolean startConfirmationUi(int token, String action) {
+        try {
+            Intent confIntent = new Intent(action);
+            confIntent.setClassName("com.android.backupconfirm",
+                    "com.android.backupconfirm.BackupRestoreConfirmation");
+            confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token);
+            confIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mContext.startActivity(confIntent);
+        } catch (ActivityNotFoundException e) {
+            return false;
+        }
+        return true;
+    }
+
+    void startConfirmationTimeout(int token, FullParams params) {
+        if (MORE_DEBUG) Slog.d(TAG, "Posting conf timeout msg after "
+                + TIMEOUT_FULL_CONFIRMATION + " millis");
+        Message msg = mBackupHandler.obtainMessage(MSG_FULL_CONFIRMATION_TIMEOUT,
+                token, 0, params);
+        mBackupHandler.sendMessageDelayed(msg, TIMEOUT_FULL_CONFIRMATION);
+    }
+
+    void waitForCompletion(FullParams params) {
+        synchronized (params.latch) {
+            while (params.latch.get() == false) {
+                try {
+                    params.latch.wait();
+                } catch (InterruptedException e) { /* never interrupted */ }
+            }
+        }
+    }
+
+    void signalFullBackupRestoreCompletion(FullParams params) {
+        synchronized (params.latch) {
+            params.latch.set(true);
+            params.latch.notifyAll();
+        }
+    }
+
+    // Confirm that the previously-requested full backup/restore operation can proceed.  This
+    // is used to require a user-facing disclosure about the operation.
+    @Override
+    public void acknowledgeFullBackupOrRestore(int token, boolean allow,
+            String curPassword, String encPpassword, IFullBackupRestoreObserver observer) {
+        if (DEBUG) Slog.d(TAG, "acknowledgeFullBackupOrRestore : token=" + token
+                + " allow=" + allow);
+
+        // TODO: possibly require not just this signature-only permission, but even
+        // require that the specific designated confirmation-UI app uid is the caller?
+        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "acknowledgeFullBackupOrRestore");
+
+        long oldId = Binder.clearCallingIdentity();
+        try {
+
+            FullParams params;
+            synchronized (mFullConfirmations) {
+                params = mFullConfirmations.get(token);
+                if (params != null) {
+                    mBackupHandler.removeMessages(MSG_FULL_CONFIRMATION_TIMEOUT, params);
+                    mFullConfirmations.delete(token);
+
+                    if (allow) {
+                        final int verb = params instanceof FullBackupParams
+                                ? MSG_RUN_FULL_BACKUP
+                                : MSG_RUN_FULL_RESTORE;
+
+                        params.observer = observer;
+                        params.curPassword = curPassword;
+
+                        boolean isEncrypted;
+                        try {
+                            isEncrypted = (mMountService.getEncryptionState() !=
+                                    IMountService.ENCRYPTION_STATE_NONE);
+                            if (isEncrypted) Slog.w(TAG, "Device is encrypted; forcing enc password");
+                        } catch (RemoteException e) {
+                            // couldn't contact the mount service; fail "safe" and assume encryption
+                            Slog.e(TAG, "Unable to contact mount service!");
+                            isEncrypted = true;
+                        }
+                        params.encryptPassword = (isEncrypted) ? curPassword : encPpassword;
+
+                        if (DEBUG) Slog.d(TAG, "Sending conf message with verb " + verb);
+                        mWakelock.acquire();
+                        Message msg = mBackupHandler.obtainMessage(verb, params);
+                        mBackupHandler.sendMessage(msg);
+                    } else {
+                        Slog.w(TAG, "User rejected full backup/restore operation");
+                        // indicate completion without having actually transferred any data
+                        signalFullBackupRestoreCompletion(params);
+                    }
+                } else {
+                    Slog.w(TAG, "Attempted to ack full backup/restore with invalid token");
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(oldId);
+        }
+    }
+
+    // Enable/disable the backup service
+    @Override
+    public void setBackupEnabled(boolean enable) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "setBackupEnabled");
+
+        Slog.i(TAG, "Backup enabled => " + enable);
+
+        long oldId = Binder.clearCallingIdentity();
+        try {
+            boolean wasEnabled = mEnabled;
+            synchronized (this) {
+                Settings.Secure.putInt(mContext.getContentResolver(),
+                        Settings.Secure.BACKUP_ENABLED, enable ? 1 : 0);
+                mEnabled = enable;
+            }
+
+            synchronized (mQueueLock) {
+                if (enable && !wasEnabled && mProvisioned) {
+                    // if we've just been enabled, start scheduling backup passes
+                    startBackupAlarmsLocked(BACKUP_INTERVAL);
+                } else if (!enable) {
+                    // No longer enabled, so stop running backups
+                    if (DEBUG) Slog.i(TAG, "Opting out of backup");
+
+                    mAlarmManager.cancel(mRunBackupIntent);
+
+                    // This also constitutes an opt-out, so we wipe any data for
+                    // this device from the backend.  We start that process with
+                    // an alarm in order to guarantee wakelock states.
+                    if (wasEnabled && mProvisioned) {
+                        // NOTE: we currently flush every registered transport, not just
+                        // the currently-active one.
+                        HashSet<String> allTransports;
+                        synchronized (mTransports) {
+                            allTransports = new HashSet<String>(mTransports.keySet());
+                        }
+                        // build the set of transports for which we are posting an init
+                        for (String transport : allTransports) {
+                            recordInitPendingLocked(true, transport);
+                        }
+                        mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
+                                mRunInitIntent);
+                    }
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(oldId);
+        }
+    }
+
+    // Enable/disable automatic restore of app data at install time
+    public void setAutoRestore(boolean doAutoRestore) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "setAutoRestore");
+
+        Slog.i(TAG, "Auto restore => " + doAutoRestore);
+
+        synchronized (this) {
+            Settings.Secure.putInt(mContext.getContentResolver(),
+                    Settings.Secure.BACKUP_AUTO_RESTORE, doAutoRestore ? 1 : 0);
+            mAutoRestore = doAutoRestore;
+        }
+    }
+
+    // Mark the backup service as having been provisioned
+    public void setBackupProvisioned(boolean available) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "setBackupProvisioned");
+        /*
+         * This is now a no-op; provisioning is simply the device's own setup state.
+         */
+    }
+
+    private void startBackupAlarmsLocked(long delayBeforeFirstBackup) {
+        // We used to use setInexactRepeating(), but that may be linked to
+        // backups running at :00 more often than not, creating load spikes.
+        // Schedule at an exact time for now, and also add a bit of "fuzz".
+
+        Random random = new Random();
+        long when = System.currentTimeMillis() + delayBeforeFirstBackup +
+                random.nextInt(FUZZ_MILLIS);
+        mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when,
+                BACKUP_INTERVAL + random.nextInt(FUZZ_MILLIS), mRunBackupIntent);
+        mNextBackupPass = when;
+    }
+
+    // Report whether the backup mechanism is currently enabled
+    public boolean isBackupEnabled() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "isBackupEnabled");
+        return mEnabled;    // no need to synchronize just to read it
+    }
+
+    // Report the name of the currently active transport
+    public String getCurrentTransport() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "getCurrentTransport");
+        if (MORE_DEBUG) Slog.v(TAG, "... getCurrentTransport() returning " + mCurrentTransport);
+        return mCurrentTransport;
+    }
+
+    // Report all known, available backup transports
+    public String[] listAllTransports() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "listAllTransports");
+
+        String[] list = null;
+        ArrayList<String> known = new ArrayList<String>();
+        for (Map.Entry<String, IBackupTransport> entry : mTransports.entrySet()) {
+            if (entry.getValue() != null) {
+                known.add(entry.getKey());
+            }
+        }
+
+        if (known.size() > 0) {
+            list = new String[known.size()];
+            known.toArray(list);
+        }
+        return list;
+    }
+
+    // Select which transport to use for the next backup operation.  If the given
+    // name is not one of the available transports, no action is taken and the method
+    // returns null.
+    public String selectBackupTransport(String transport) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "selectBackupTransport");
+
+        synchronized (mTransports) {
+            String prevTransport = null;
+            if (mTransports.get(transport) != null) {
+                prevTransport = mCurrentTransport;
+                mCurrentTransport = transport;
+                Settings.Secure.putString(mContext.getContentResolver(),
+                        Settings.Secure.BACKUP_TRANSPORT, transport);
+                Slog.v(TAG, "selectBackupTransport() set " + mCurrentTransport
+                        + " returning " + prevTransport);
+            } else {
+                Slog.w(TAG, "Attempt to select unavailable transport " + transport);
+            }
+            return prevTransport;
+        }
+    }
+
+    // Supply the configuration Intent for the given transport.  If the name is not one
+    // of the available transports, or if the transport does not supply any configuration
+    // UI, the method returns null.
+    public Intent getConfigurationIntent(String transportName) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "getConfigurationIntent");
+
+        synchronized (mTransports) {
+            final IBackupTransport transport = mTransports.get(transportName);
+            if (transport != null) {
+                try {
+                    final Intent intent = transport.configurationIntent();
+                    if (MORE_DEBUG) Slog.d(TAG, "getConfigurationIntent() returning config intent "
+                            + intent);
+                    return intent;
+                } catch (RemoteException e) {
+                    /* fall through to return null */
+                }
+            }
+        }
+
+        return null;
+    }
+
+    // Supply the configuration summary string for the given transport.  If the name is
+    // not one of the available transports, or if the transport does not supply any
+    // summary / destination string, the method can return null.
+    //
+    // This string is used VERBATIM as the summary text of the relevant Settings item!
+    public String getDestinationString(String transportName) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                "getDestinationString");
+
+        synchronized (mTransports) {
+            final IBackupTransport transport = mTransports.get(transportName);
+            if (transport != null) {
+                try {
+                    final String text = transport.currentDestinationString();
+                    if (MORE_DEBUG) Slog.d(TAG, "getDestinationString() returning " + text);
+                    return text;
+                } catch (RemoteException e) {
+                    /* fall through to return null */
+                }
+            }
+        }
+
+        return null;
+    }
+
+    // Callback: a requested backup agent has been instantiated.  This should only
+    // be called from the Activity Manager.
+    public void agentConnected(String packageName, IBinder agentBinder) {
+        synchronized(mAgentConnectLock) {
+            if (Binder.getCallingUid() == Process.SYSTEM_UID) {
+                Slog.d(TAG, "agentConnected pkg=" + packageName + " agent=" + agentBinder);
+                IBackupAgent agent = IBackupAgent.Stub.asInterface(agentBinder);
+                mConnectedAgent = agent;
+                mConnecting = false;
+            } else {
+                Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid()
+                        + " claiming agent connected");
+            }
+            mAgentConnectLock.notifyAll();
+        }
+    }
+
+    // Callback: a backup agent has failed to come up, or has unexpectedly quit.
+    // If the agent failed to come up in the first place, the agentBinder argument
+    // will be null.  This should only be called from the Activity Manager.
+    public void agentDisconnected(String packageName) {
+        // TODO: handle backup being interrupted
+        synchronized(mAgentConnectLock) {
+            if (Binder.getCallingUid() == Process.SYSTEM_UID) {
+                mConnectedAgent = null;
+                mConnecting = false;
+            } else {
+                Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid()
+                        + " claiming agent disconnected");
+            }
+            mAgentConnectLock.notifyAll();
+        }
+    }
+
+    // An application being installed will need a restore pass, then the Package Manager
+    // will need to be told when the restore is finished.
+    public void restoreAtInstall(String packageName, int token) {
+        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+            Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid()
+                    + " attemping install-time restore");
+            return;
+        }
+
+        boolean skip = false;
+
+        long restoreSet = getAvailableRestoreToken(packageName);
+        if (DEBUG) Slog.v(TAG, "restoreAtInstall pkg=" + packageName
+                + " token=" + Integer.toHexString(token)
+                + " restoreSet=" + Long.toHexString(restoreSet));
+        if (restoreSet == 0) {
+            if (MORE_DEBUG) Slog.i(TAG, "No restore set");
+            skip = true;
+        }
+
+        // Do we have a transport to fetch data for us?
+        IBackupTransport transport = getTransport(mCurrentTransport);
+        if (transport == null) {
+            if (DEBUG) Slog.w(TAG, "No transport");
+            skip = true;
+        }
+
+        if (!skip && mAutoRestore && mProvisioned) {
+            try {
+                // okay, we're going to attempt a restore of this package from this restore set.
+                // The eventual message back into the Package Manager to run the post-install
+                // steps for 'token' will be issued from the restore handling code.
+
+                // This can throw and so *must* happen before the wakelock is acquired
+                String dirName = transport.transportDirName();
+
+                // We can use a synthetic PackageInfo here because:
+                //   1. We know it's valid, since the Package Manager supplied the name
+                //   2. Only the packageName field will be used by the restore code
+                PackageInfo pkg = new PackageInfo();
+                pkg.packageName = packageName;
+
+                mWakelock.acquire();
+                Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
+                msg.obj = new RestoreParams(transport, dirName, null,
+                        restoreSet, pkg, token, true);
+                mBackupHandler.sendMessage(msg);
+            } catch (RemoteException e) {
+                // Binding to the transport broke; back off and proceed with the installation.
+                Slog.e(TAG, "Unable to contact transport");
+                skip = true;
+            }
+        }
+
+        if (skip) {
+            // Auto-restore disabled or no way to attempt a restore; just tell the Package
+            // Manager to proceed with the post-install handling for this package.
+            if (DEBUG) Slog.v(TAG, "Skipping");
+            try {
+                mPackageManagerBinder.finishPackageInstall(token);
+            } catch (RemoteException e) { /* can't happen */ }
+        }
+    }
+
+    // Hand off a restore session
+    public IRestoreSession beginRestoreSession(String packageName, String transport) {
+        if (DEBUG) Slog.v(TAG, "beginRestoreSession: pkg=" + packageName
+                + " transport=" + transport);
+
+        boolean needPermission = true;
+        if (transport == null) {
+            transport = mCurrentTransport;
+
+            if (packageName != null) {
+                PackageInfo app = null;
+                try {
+                    app = mPackageManager.getPackageInfo(packageName, 0);
+                } catch (NameNotFoundException nnf) {
+                    Slog.w(TAG, "Asked to restore nonexistent pkg " + packageName);
+                    throw new IllegalArgumentException("Package " + packageName + " not found");
+                }
+
+                if (app.applicationInfo.uid == Binder.getCallingUid()) {
+                    // So: using the current active transport, and the caller has asked
+                    // that its own package will be restored.  In this narrow use case
+                    // we do not require the caller to hold the permission.
+                    needPermission = false;
+                }
+            }
+        }
+
+        if (needPermission) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                    "beginRestoreSession");
+        } else {
+            if (DEBUG) Slog.d(TAG, "restoring self on current transport; no permission needed");
+        }
+
+        synchronized(this) {
+            if (mActiveRestoreSession != null) {
+                Slog.d(TAG, "Restore session requested but one already active");
+                return null;
+            }
+            mActiveRestoreSession = new ActiveRestoreSession(packageName, transport);
+            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_TIMEOUT, TIMEOUT_RESTORE_INTERVAL);
+        }
+        return mActiveRestoreSession;
+    }
+
+    void clearRestoreSession(ActiveRestoreSession currentSession) {
+        synchronized(this) {
+            if (currentSession != mActiveRestoreSession) {
+                Slog.e(TAG, "ending non-current restore session");
+            } else {
+                if (DEBUG) Slog.v(TAG, "Clearing restore session and halting timeout");
+                mActiveRestoreSession = null;
+                mBackupHandler.removeMessages(MSG_RESTORE_TIMEOUT);
+            }
+        }
+    }
+
+    // Note that a currently-active backup agent has notified us that it has
+    // completed the given outstanding asynchronous backup/restore operation.
+    @Override
+    public void opComplete(int token) {
+        if (MORE_DEBUG) Slog.v(TAG, "opComplete: " + Integer.toHexString(token));
+        Operation op = null;
+        synchronized (mCurrentOpLock) {
+            op = mCurrentOperations.get(token);
+            if (op != null) {
+                op.state = OP_ACKNOWLEDGED;
+            }
+            mCurrentOpLock.notifyAll();
+        }
+
+        // The completion callback, if any, is invoked on the handler
+        if (op != null && op.callback != null) {
+            Message msg = mBackupHandler.obtainMessage(MSG_OP_COMPLETE, op.callback);
+            mBackupHandler.sendMessage(msg);
+        }
+    }
+
+    // ----- Restore session -----
+
+    class ActiveRestoreSession extends IRestoreSession.Stub {
+        private static final String TAG = "RestoreSession";
+
+        private String mPackageName;
+        private IBackupTransport mRestoreTransport = null;
+        RestoreSet[] mRestoreSets = null;
+        boolean mEnded = false;
+
+        ActiveRestoreSession(String packageName, String transport) {
+            mPackageName = packageName;
+            mRestoreTransport = getTransport(transport);
+        }
+
+        // --- Binder interface ---
+        public synchronized int getAvailableRestoreSets(IRestoreObserver observer) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                    "getAvailableRestoreSets");
+            if (observer == null) {
+                throw new IllegalArgumentException("Observer must not be null");
+            }
+
+            if (mEnded) {
+                throw new IllegalStateException("Restore session already ended");
+            }
+
+            long oldId = Binder.clearCallingIdentity();
+            try {
+                if (mRestoreTransport == null) {
+                    Slog.w(TAG, "Null transport getting restore sets");
+                    return -1;
+                }
+                // spin off the transport request to our service thread
+                mWakelock.acquire();
+                Message msg = mBackupHandler.obtainMessage(MSG_RUN_GET_RESTORE_SETS,
+                        new RestoreGetSetsParams(mRestoreTransport, this, observer));
+                mBackupHandler.sendMessage(msg);
+                return 0;
+            } catch (Exception e) {
+                Slog.e(TAG, "Error in getAvailableRestoreSets", e);
+                return -1;
+            } finally {
+                Binder.restoreCallingIdentity(oldId);
+            }
+        }
+
+        public synchronized int restoreAll(long token, IRestoreObserver observer) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                    "performRestore");
+
+            if (DEBUG) Slog.d(TAG, "restoreAll token=" + Long.toHexString(token)
+                    + " observer=" + observer);
+
+            if (mEnded) {
+                throw new IllegalStateException("Restore session already ended");
+            }
+
+            if (mRestoreTransport == null || mRestoreSets == null) {
+                Slog.e(TAG, "Ignoring restoreAll() with no restore set");
+                return -1;
+            }
+
+            if (mPackageName != null) {
+                Slog.e(TAG, "Ignoring restoreAll() on single-package session");
+                return -1;
+            }
+
+            String dirName;
+            try {
+                dirName = mRestoreTransport.transportDirName();
+            } catch (RemoteException e) {
+                // Transport went AWOL; fail.
+                Slog.e(TAG, "Unable to contact transport for restore");
+                return -1;
+            }
+
+            synchronized (mQueueLock) {
+                for (int i = 0; i < mRestoreSets.length; i++) {
+                    if (token == mRestoreSets[i].token) {
+                        long oldId = Binder.clearCallingIdentity();
+                        mWakelock.acquire();
+                        Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
+                        msg.obj = new RestoreParams(mRestoreTransport, dirName,
+                                observer, token, true);
+                        mBackupHandler.sendMessage(msg);
+                        Binder.restoreCallingIdentity(oldId);
+                        return 0;
+                    }
+                }
+            }
+
+            Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found");
+            return -1;
+        }
+
+        public synchronized int restoreSome(long token, IRestoreObserver observer,
+                String[] packages) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
+                    "performRestore");
+
+            if (DEBUG) {
+                StringBuilder b = new StringBuilder(128);
+                b.append("restoreSome token=");
+                b.append(Long.toHexString(token));
+                b.append(" observer=");
+                b.append(observer.toString());
+                b.append(" packages=");
+                if (packages == null) {
+                    b.append("null");
+                } else {
+                    b.append('{');
+                    boolean first = true;
+                    for (String s : packages) {
+                        if (!first) {
+                            b.append(", ");
+                        } else first = false;
+                        b.append(s);
+                    }
+                    b.append('}');
+                }
+                Slog.d(TAG, b.toString());
+            }
+
+            if (mEnded) {
+                throw new IllegalStateException("Restore session already ended");
+            }
+
+            if (mRestoreTransport == null || mRestoreSets == null) {
+                Slog.e(TAG, "Ignoring restoreAll() with no restore set");
+                return -1;
+            }
+
+            if (mPackageName != null) {
+                Slog.e(TAG, "Ignoring restoreAll() on single-package session");
+                return -1;
+            }
+
+            String dirName;
+            try {
+                dirName = mRestoreTransport.transportDirName();
+            } catch (RemoteException e) {
+                // Transport went AWOL; fail.
+                Slog.e(TAG, "Unable to contact transport for restore");
+                return -1;
+            }
+
+            synchronized (mQueueLock) {
+                for (int i = 0; i < mRestoreSets.length; i++) {
+                    if (token == mRestoreSets[i].token) {
+                        long oldId = Binder.clearCallingIdentity();
+                        mWakelock.acquire();
+                        Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
+                        msg.obj = new RestoreParams(mRestoreTransport, dirName, observer, token,
+                                packages, true);
+                        mBackupHandler.sendMessage(msg);
+                        Binder.restoreCallingIdentity(oldId);
+                        return 0;
+                    }
+                }
+            }
+
+            Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found");
+            return -1;
+        }
+
+        public synchronized int restorePackage(String packageName, IRestoreObserver observer) {
+            if (DEBUG) Slog.v(TAG, "restorePackage pkg=" + packageName + " obs=" + observer);
+
+            if (mEnded) {
+                throw new IllegalStateException("Restore session already ended");
+            }
+
+            if (mPackageName != null) {
+                if (! mPackageName.equals(packageName)) {
+                    Slog.e(TAG, "Ignoring attempt to restore pkg=" + packageName
+                            + " on session for package " + mPackageName);
+                    return -1;
+                }
+            }
+
+            PackageInfo app = null;
+            try {
+                app = mPackageManager.getPackageInfo(packageName, 0);
+            } catch (NameNotFoundException nnf) {
+                Slog.w(TAG, "Asked to restore nonexistent pkg " + packageName);
+                return -1;
+            }
+
+            // If the caller is not privileged and is not coming from the target
+            // app's uid, throw a permission exception back to the caller.
+            int perm = mContext.checkPermission(android.Manifest.permission.BACKUP,
+                    Binder.getCallingPid(), Binder.getCallingUid());
+            if ((perm == PackageManager.PERMISSION_DENIED) &&
+                    (app.applicationInfo.uid != Binder.getCallingUid())) {
+                Slog.w(TAG, "restorePackage: bad packageName=" + packageName
+                        + " or calling uid=" + Binder.getCallingUid());
+                throw new SecurityException("No permission to restore other packages");
+            }
+
+            // If the package has no backup agent, we obviously cannot proceed
+            if (app.applicationInfo.backupAgentName == null) {
+                Slog.w(TAG, "Asked to restore package " + packageName + " with no agent");
+                return -1;
+            }
+
+            // So far so good; we're allowed to try to restore this package.  Now
+            // check whether there is data for it in the current dataset, falling back
+            // to the ancestral dataset if not.
+            long token = getAvailableRestoreToken(packageName);
+
+            // If we didn't come up with a place to look -- no ancestral dataset and
+            // the app has never been backed up from this device -- there's nothing
+            // to do but return failure.
+            if (token == 0) {
+                if (DEBUG) Slog.w(TAG, "No data available for this package; not restoring");
+                return -1;
+            }
+
+            String dirName;
+            try {
+                dirName = mRestoreTransport.transportDirName();
+            } catch (RemoteException e) {
+                // Transport went AWOL; fail.
+                Slog.e(TAG, "Unable to contact transport for restore");
+                return -1;
+            }
+
+            // Ready to go:  enqueue the restore request and claim success
+            long oldId = Binder.clearCallingIdentity();
+            mWakelock.acquire();
+            Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
+            msg.obj = new RestoreParams(mRestoreTransport, dirName,
+                    observer, token, app, 0, false);
+            mBackupHandler.sendMessage(msg);
+            Binder.restoreCallingIdentity(oldId);
+            return 0;
+        }
+
+        // Posted to the handler to tear down a restore session in a cleanly synchronized way
+        class EndRestoreRunnable implements Runnable {
+            BackupManagerService mBackupManager;
+            ActiveRestoreSession mSession;
+
+            EndRestoreRunnable(BackupManagerService manager, ActiveRestoreSession session) {
+                mBackupManager = manager;
+                mSession = session;
+            }
+
+            public void run() {
+                // clean up the session's bookkeeping
+                synchronized (mSession) {
+                    try {
+                        if (mSession.mRestoreTransport != null) {
+                            mSession.mRestoreTransport.finishRestore();
+                        }
+                    } catch (Exception e) {
+                        Slog.e(TAG, "Error in finishRestore", e);
+                    } finally {
+                        mSession.mRestoreTransport = null;
+                        mSession.mEnded = true;
+                    }
+                }
+
+                // clean up the BackupManagerImpl side of the bookkeeping
+                // and cancel any pending timeout message
+                mBackupManager.clearRestoreSession(mSession);
+            }
+        }
+
+        public synchronized void endRestoreSession() {
+            if (DEBUG) Slog.d(TAG, "endRestoreSession");
+
+            if (mEnded) {
+                throw new IllegalStateException("Restore session already ended");
+            }
+
+            mBackupHandler.post(new EndRestoreRunnable(BackupManagerService.this, this));
+        }
+    }
+
+    @Override
+    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
+
+        long identityToken = Binder.clearCallingIdentity();
+        try {
+            dumpInternal(pw);
+        } finally {
+            Binder.restoreCallingIdentity(identityToken);
+        }
+    }
+
+    private void dumpInternal(PrintWriter pw) {
+        synchronized (mQueueLock) {
+            pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled")
+                    + " / " + (!mProvisioned ? "not " : "") + "provisioned / "
+                    + (this.mPendingInits.size() == 0 ? "not " : "") + "pending init");
+            pw.println("Auto-restore is " + (mAutoRestore ? "enabled" : "disabled"));
+            if (mBackupRunning) pw.println("Backup currently running");
+            pw.println("Last backup pass started: " + mLastBackupPass
+                    + " (now = " + System.currentTimeMillis() + ')');
+            pw.println("  next scheduled: " + mNextBackupPass);
+
+            pw.println("Available transports:");
+            for (String t : listAllTransports()) {
+                pw.println((t.equals(mCurrentTransport) ? "  * " : "    ") + t);
+                try {
+                    IBackupTransport transport = getTransport(t);
+                    File dir = new File(mBaseStateDir, transport.transportDirName());
+                    pw.println("       destination: " + transport.currentDestinationString());
+                    pw.println("       intent: " + transport.configurationIntent());
+                    for (File f : dir.listFiles()) {
+                        pw.println("       " + f.getName() + " - " + f.length() + " state bytes");
+                    }
+                } catch (Exception e) {
+                    Slog.e(TAG, "Error in transport", e);
+                    pw.println("        Error: " + e);
+                }
+            }
+
+            pw.println("Pending init: " + mPendingInits.size());
+            for (String s : mPendingInits) {
+                pw.println("    " + s);
+            }
+
+            if (DEBUG_BACKUP_TRACE) {
+                synchronized (mBackupTrace) {
+                    if (!mBackupTrace.isEmpty()) {
+                        pw.println("Most recent backup trace:");
+                        for (String s : mBackupTrace) {
+                            pw.println("   " + s);
+                        }
+                    }
+                }
+            }
+
+            int N = mBackupParticipants.size();
+            pw.println("Participants:");
+            for (int i=0; i<N; i++) {
+                int uid = mBackupParticipants.keyAt(i);
+                pw.print("  uid: ");
+                pw.println(uid);
+                HashSet<String> participants = mBackupParticipants.valueAt(i);
+                for (String app: participants) {
+                    pw.println("    " + app);
+                }
+            }
+
+            pw.println("Ancestral packages: "
+                    + (mAncestralPackages == null ? "none" : mAncestralPackages.size()));
+            if (mAncestralPackages != null) {
+                for (String pkg : mAncestralPackages) {
+                    pw.println("    " + pkg);
+                }
+            }
+
+            pw.println("Ever backed up: " + mEverStoredApps.size());
+            for (String pkg : mEverStoredApps) {
+                pw.println("    " + pkg);
+            }
+
+            pw.println("Pending backup: " + mPendingBackups.size());
+            for (BackupRequest req : mPendingBackups.values()) {
+                pw.println("    " + req);
+            }
+        }
+    }
+}
diff --git a/services/backup/java/com/android/server/backup/PackageManagerBackupAgent.java b/services/backup/java/com/android/server/backup/PackageManagerBackupAgent.java
new file mode 100644
index 0000000..495da88
--- /dev/null
+++ b/services/backup/java/com/android/server/backup/PackageManagerBackupAgent.java
@@ -0,0 +1,425 @@
+/*
+ * 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.
+ */
+
+package com.android.server.backup;
+
+import android.app.backup.BackupAgent;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.Signature;
+import android.os.Build;
+import android.os.ParcelFileDescriptor;
+import android.util.Slog;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * We back up the signatures of each package so that during a system restore,
+ * we can verify that the app whose data we think we have matches the app
+ * actually resident on the device.
+ *
+ * Since the Package Manager isn't a proper "application" we just provide a
+ * direct IBackupAgent implementation and hand-construct it at need.
+ */
+public class PackageManagerBackupAgent extends BackupAgent {
+    private static final String TAG = "PMBA";
+    private static final boolean DEBUG = false;
+
+    // key under which we store global metadata (individual app metadata
+    // is stored using the package name as a key)
+    private static final String GLOBAL_METADATA_KEY = "@meta@";
+
+    private List<PackageInfo> mAllPackages;
+    private PackageManager mPackageManager;
+    // version & signature info of each app in a restore set
+    private HashMap<String, Metadata> mRestoredSignatures;
+    // The version info of each backed-up app as read from the state file
+    private HashMap<String, Metadata> mStateVersions = new HashMap<String, Metadata>();
+
+    private final HashSet<String> mExisting = new HashSet<String>();
+    private int mStoredSdkVersion;
+    private String mStoredIncrementalVersion;
+    private boolean mHasMetadata;
+
+    public class Metadata {
+        public int versionCode;
+        public Signature[] signatures;
+
+        Metadata(int version, Signature[] sigs) {
+            versionCode = version;
+            signatures = sigs;
+        }
+    }
+
+    // We're constructed with the set of applications that are participating
+    // in backup.  This set changes as apps are installed & removed.
+    PackageManagerBackupAgent(PackageManager packageMgr, List<PackageInfo> packages) {
+        mPackageManager = packageMgr;
+        mAllPackages = packages;
+        mRestoredSignatures = null;
+        mHasMetadata = false;
+    }
+
+    public boolean hasMetadata() {
+        return mHasMetadata;
+    }
+
+    public Metadata getRestoredMetadata(String packageName) {
+        if (mRestoredSignatures == null) {
+            Slog.w(TAG, "getRestoredMetadata() before metadata read!");
+            return null;
+        }
+
+        return mRestoredSignatures.get(packageName);
+    }
+
+    public Set<String> getRestoredPackages() {
+        if (mRestoredSignatures == null) {
+            Slog.w(TAG, "getRestoredPackages() before metadata read!");
+            return null;
+        }
+
+        // This is technically the set of packages on the originating handset
+        // that had backup agents at all, not limited to the set of packages
+        // that had actually contributed a restore dataset, but it's a
+        // close enough approximation for our purposes and does not require any
+        // additional involvement by the transport to obtain.
+        return mRestoredSignatures.keySet();
+    }
+    
+    // The backed up data is the signature block for each app, keyed by
+    // the package name.
+    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
+            ParcelFileDescriptor newState) {
+        if (DEBUG) Slog.v(TAG, "onBackup()");
+
+        ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();  // we'll reuse these
+        DataOutputStream outputBufferStream = new DataOutputStream(outputBuffer);
+        parseStateFile(oldState);
+
+        // If the stored version string differs, we need to re-backup all
+        // of the metadata.  We force this by removing everything from the
+        // "already backed up" map built by parseStateFile().
+        if (mStoredIncrementalVersion == null
+                || !mStoredIncrementalVersion.equals(Build.VERSION.INCREMENTAL)) {
+            Slog.i(TAG, "Previous metadata " + mStoredIncrementalVersion + " mismatch vs "
+                    + Build.VERSION.INCREMENTAL + " - rewriting");
+            mExisting.clear();
+        }
+
+        try {
+            /*
+             * Global metadata:
+             *
+             * int SDKversion -- the SDK version of the OS itself on the device
+             *                   that produced this backup set.  Used to reject
+             *                   backups from later OSes onto earlier ones.
+             * String incremental -- the incremental release name of the OS stored in
+             *                       the backup set.
+             */
+            if (!mExisting.contains(GLOBAL_METADATA_KEY)) {
+                if (DEBUG) Slog.v(TAG, "Storing global metadata key");
+                outputBufferStream.writeInt(Build.VERSION.SDK_INT);
+                outputBufferStream.writeUTF(Build.VERSION.INCREMENTAL);
+                writeEntity(data, GLOBAL_METADATA_KEY, outputBuffer.toByteArray());
+            } else {
+                if (DEBUG) Slog.v(TAG, "Global metadata key already stored");
+                // don't consider it to have been skipped/deleted
+                mExisting.remove(GLOBAL_METADATA_KEY);
+            }
+
+            // For each app we have on device, see if we've backed it up yet.  If not,
+            // write its signature block to the output, keyed on the package name.
+            for (PackageInfo pkg : mAllPackages) {
+                String packName = pkg.packageName;
+                if (packName.equals(GLOBAL_METADATA_KEY)) {
+                    // We've already handled the metadata key; skip it here
+                    continue;
+                } else {
+                    PackageInfo info = null;
+                    try {
+                        info = mPackageManager.getPackageInfo(packName,
+                                PackageManager.GET_SIGNATURES);
+                    } catch (NameNotFoundException e) {
+                        // Weird; we just found it, and now are told it doesn't exist.
+                        // Treat it as having been removed from the device.
+                        mExisting.add(packName);
+                        continue;
+                    }
+
+                    if (mExisting.contains(packName)) {
+                        // We have backed up this app before.  Check whether the version
+                        // of the backup matches the version of the current app; if they
+                        // don't match, the app has been updated and we need to store its
+                        // metadata again.  In either case, take it out of mExisting so that
+                        // we don't consider it deleted later.
+                        mExisting.remove(packName);
+                        if (info.versionCode == mStateVersions.get(packName).versionCode) {
+                            continue;
+                        }
+                    }
+                    
+                    if (info.signatures == null || info.signatures.length == 0)
+                    {
+                        Slog.w(TAG, "Not backing up package " + packName
+                                + " since it appears to have no signatures.");
+                        continue;
+                    }
+
+                    // We need to store this app's metadata
+                    /*
+                     * Metadata for each package:
+                     *
+                     * int version       -- [4] the package's versionCode
+                     * byte[] signatures -- [len] flattened Signature[] of the package
+                     */
+
+                    // marshal the version code in a canonical form
+                    outputBuffer.reset();
+                    outputBufferStream.writeInt(info.versionCode);
+                    writeSignatureArray(outputBufferStream, info.signatures);
+
+                    if (DEBUG) {
+                        Slog.v(TAG, "+ writing metadata for " + packName
+                                + " version=" + info.versionCode
+                                + " entityLen=" + outputBuffer.size());
+                    }
+                    
+                    // Now we can write the backup entity for this package
+                    writeEntity(data, packName, outputBuffer.toByteArray());
+                }
+            }
+
+            // At this point, the only entries in 'existing' are apps that were
+            // mentioned in the saved state file, but appear to no longer be present
+            // on the device.  Write a deletion entity for them.
+            for (String app : mExisting) {
+                if (DEBUG) Slog.v(TAG, "- removing metadata for deleted pkg " + app);
+                try {
+                    data.writeEntityHeader(app, -1);
+                } catch (IOException e) {
+                    Slog.e(TAG, "Unable to write package deletions!");
+                    return;
+                }
+            }
+        } catch (IOException e) {
+            // Real error writing data
+            Slog.e(TAG, "Unable to write package backup data file!");
+            return;
+        }
+
+        // Finally, write the new state blob -- just the list of all apps we handled
+        writeStateFile(mAllPackages, newState);
+    }
+    
+    private static void writeEntity(BackupDataOutput data, String key, byte[] bytes)
+            throws IOException {
+        data.writeEntityHeader(key, bytes.length);
+        data.writeEntityData(bytes, bytes.length);
+    }
+
+    // "Restore" here is a misnomer.  What we're really doing is reading back the
+    // set of app signatures associated with each backed-up app in this restore
+    // image.  We'll use those later to determine what we can legitimately restore.
+    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+            throws IOException {
+        List<ApplicationInfo> restoredApps = new ArrayList<ApplicationInfo>();
+        HashMap<String, Metadata> sigMap = new HashMap<String, Metadata>();
+        if (DEBUG) Slog.v(TAG, "onRestore()");
+        int storedSystemVersion = -1;
+
+        while (data.readNextHeader()) {
+            String key = data.getKey();
+            int dataSize = data.getDataSize();
+
+            if (DEBUG) Slog.v(TAG, "   got key=" + key + " dataSize=" + dataSize);
+
+            // generic setup to parse any entity data
+            byte[] inputBytes = new byte[dataSize];
+            data.readEntityData(inputBytes, 0, dataSize);
+            ByteArrayInputStream inputBuffer = new ByteArrayInputStream(inputBytes);
+            DataInputStream inputBufferStream = new DataInputStream(inputBuffer);
+
+            if (key.equals(GLOBAL_METADATA_KEY)) {
+                int storedSdkVersion = inputBufferStream.readInt();
+                if (DEBUG) Slog.v(TAG, "   storedSystemVersion = " + storedSystemVersion);
+                if (storedSystemVersion > Build.VERSION.SDK_INT) {
+                    // returning before setting the sig map means we rejected the restore set
+                    Slog.w(TAG, "Restore set was from a later version of Android; not restoring");
+                    return;
+                }
+                mStoredSdkVersion = storedSdkVersion;
+                mStoredIncrementalVersion = inputBufferStream.readUTF();
+                mHasMetadata = true;
+                if (DEBUG) {
+                    Slog.i(TAG, "Restore set version " + storedSystemVersion
+                            + " is compatible with OS version " + Build.VERSION.SDK_INT
+                            + " (" + mStoredIncrementalVersion + " vs "
+                            + Build.VERSION.INCREMENTAL + ")");
+                }
+            } else {
+                // it's a file metadata record
+                int versionCode = inputBufferStream.readInt();
+                Signature[] sigs = readSignatureArray(inputBufferStream);
+                if (DEBUG) {
+                    Slog.i(TAG, "   read metadata for " + key
+                            + " dataSize=" + dataSize
+                            + " versionCode=" + versionCode + " sigs=" + sigs);
+                }
+                
+                if (sigs == null || sigs.length == 0) {
+                    Slog.w(TAG, "Not restoring package " + key
+                            + " since it appears to have no signatures.");
+                    continue;
+                }
+
+                ApplicationInfo app = new ApplicationInfo();
+                app.packageName = key;
+                restoredApps.add(app);
+                sigMap.put(key, new Metadata(versionCode, sigs));
+            }
+        }
+
+        // On successful completion, cache the signature map for the Backup Manager to use
+        mRestoredSignatures = sigMap;
+    }
+
+    private static void writeSignatureArray(DataOutputStream out, Signature[] sigs)
+            throws IOException {
+        // write the number of signatures in the array
+        out.writeInt(sigs.length);
+
+        // write the signatures themselves, length + flattened buffer
+        for (Signature sig : sigs) {
+            byte[] flat = sig.toByteArray();
+            out.writeInt(flat.length);
+            out.write(flat);
+        }
+    }
+
+    private static Signature[] readSignatureArray(DataInputStream in) {
+        try {
+            int num;
+            try {
+                num = in.readInt();
+            } catch (EOFException e) {
+                // clean termination
+                Slog.w(TAG, "Read empty signature block");
+                return null;
+            }
+            
+            if (DEBUG) Slog.v(TAG, " ... unflatten read " + num);
+            
+            // Sensical?
+            if (num > 20) {
+                Slog.e(TAG, "Suspiciously large sig count in restore data; aborting");
+                throw new IllegalStateException("Bad restore state");
+            }
+            
+            Signature[] sigs = new Signature[num];
+            for (int i = 0; i < num; i++) {
+                int len = in.readInt();
+                byte[] flatSig = new byte[len];
+                in.read(flatSig);
+                sigs[i] = new Signature(flatSig);
+            }
+            return sigs;
+        } catch (IOException e) {
+            Slog.e(TAG, "Unable to read signatures");
+            return null;
+        }
+    }
+
+    // Util: parse out an existing state file into a usable structure
+    private void parseStateFile(ParcelFileDescriptor stateFile) {
+        mExisting.clear();
+        mStateVersions.clear();
+        mStoredSdkVersion = 0;
+        mStoredIncrementalVersion = null;
+
+        // The state file is just the list of app names we have stored signatures for
+        // with the exception of the metadata block, to which is also appended the
+        // version numbers corresponding with the last time we wrote this PM block.
+        // If they mismatch the current system, we'll re-store the metadata key.
+        FileInputStream instream = new FileInputStream(stateFile.getFileDescriptor());
+        DataInputStream in = new DataInputStream(instream);
+
+        int bufSize = 256;
+        byte[] buf = new byte[bufSize];
+        try {
+            String pkg = in.readUTF();
+            if (pkg.equals(GLOBAL_METADATA_KEY)) {
+                mStoredSdkVersion = in.readInt();
+                mStoredIncrementalVersion = in.readUTF();
+                mExisting.add(GLOBAL_METADATA_KEY);
+            } else {
+                Slog.e(TAG, "No global metadata in state file!");
+                return;
+            }
+
+            // The global metadata was first; now read all the apps
+            while (true) {
+                pkg = in.readUTF();
+                int versionCode = in.readInt();
+                mExisting.add(pkg);
+                mStateVersions.put(pkg, new Metadata(versionCode, null));
+            }
+        } catch (EOFException eof) {
+            // safe; we're done
+        } catch (IOException e) {
+            // whoops, bad state file.  abort.
+            Slog.e(TAG, "Unable to read Package Manager state file: " + e);
+        }
+    }
+
+    // Util: write out our new backup state file
+    private void writeStateFile(List<PackageInfo> pkgs, ParcelFileDescriptor stateFile) {
+        FileOutputStream outstream = new FileOutputStream(stateFile.getFileDescriptor());
+        DataOutputStream out = new DataOutputStream(outstream);
+
+        try {
+            // by the time we get here we know we've stored the global metadata record
+            out.writeUTF(GLOBAL_METADATA_KEY);
+            out.writeInt(Build.VERSION.SDK_INT);
+            out.writeUTF(Build.VERSION.INCREMENTAL);
+
+            // now write all the app names too
+            for (PackageInfo pkg : pkgs) {
+                out.writeUTF(pkg.packageName);
+                out.writeInt(pkg.versionCode);
+            }
+        } catch (IOException e) {
+            Slog.e(TAG, "Unable to write package manager state file!");
+            return;
+        }
+    }
+}
diff --git a/services/backup/java/com/android/server/backup/SystemBackupAgent.java b/services/backup/java/com/android/server/backup/SystemBackupAgent.java
new file mode 100644
index 0000000..26e2e2a
--- /dev/null
+++ b/services/backup/java/com/android/server/backup/SystemBackupAgent.java
@@ -0,0 +1,185 @@
+/*
+ * 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.
+ */
+
+package com.android.server.backup;
+
+
+import android.app.IWallpaperManager;
+import android.app.backup.BackupDataInput;
+import android.app.backup.BackupDataOutput;
+import android.app.backup.BackupAgentHelper;
+import android.app.backup.FullBackup;
+import android.app.backup.FullBackupDataOutput;
+import android.app.backup.WallpaperBackupHelper;
+import android.content.Context;
+import android.os.Environment;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Backup agent for various system-managed data, currently just the system wallpaper
+ */
+public class SystemBackupAgent extends BackupAgentHelper {
+    private static final String TAG = "SystemBackupAgent";
+
+    // These paths must match what the WallpaperManagerService uses.  The leaf *_FILENAME
+    // are also used in the full-backup file format, so must not change unless steps are
+    // taken to support the legacy backed-up datasets.
+    private static final String WALLPAPER_IMAGE_FILENAME = "wallpaper";
+    private static final String WALLPAPER_INFO_FILENAME = "wallpaper_info.xml";
+
+    // TODO: Will need to change if backing up non-primary user's wallpaper
+    private static final String WALLPAPER_IMAGE_DIR =
+            Environment.getUserSystemDirectory(UserHandle.USER_OWNER).getAbsolutePath();
+    private static final String WALLPAPER_IMAGE = WallpaperBackupHelper.WALLPAPER_IMAGE;
+
+    // TODO: Will need to change if backing up non-primary user's wallpaper
+    private static final String WALLPAPER_INFO_DIR =
+            Environment.getUserSystemDirectory(UserHandle.USER_OWNER).getAbsolutePath();
+    private static final String WALLPAPER_INFO = WallpaperBackupHelper.WALLPAPER_INFO;
+    // Use old keys to keep legacy data compatibility and avoid writing two wallpapers
+    private static final String WALLPAPER_IMAGE_KEY = WallpaperBackupHelper.WALLPAPER_IMAGE_KEY;
+    private static final String WALLPAPER_INFO_KEY = WallpaperBackupHelper.WALLPAPER_INFO_KEY;
+
+    @Override
+    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
+            ParcelFileDescriptor newState) throws IOException {
+        // We only back up the data under the current "wallpaper" schema with metadata
+        IWallpaperManager wallpaper = (IWallpaperManager)ServiceManager.getService(
+                Context.WALLPAPER_SERVICE);
+        String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
+        String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY };
+        if (wallpaper != null) {
+            try {
+                final String wallpaperName = wallpaper.getName();
+                if (wallpaperName != null && wallpaperName.length() > 0) {
+                    // When the wallpaper has a name, back up the info by itself.
+                    // TODO: Don't rely on the innards of the service object like this!
+                    // TODO: Send a delete for any stored wallpaper image in this case?
+                    files = new String[] { WALLPAPER_INFO };
+                    keys = new String[] { WALLPAPER_INFO_KEY };
+                }
+            } catch (RemoteException re) {
+                Slog.e(TAG, "Couldn't get wallpaper name\n" + re);
+            }
+        }
+        addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys));
+        super.onBackup(oldState, data, newState);
+    }
+
+    @Override
+    public void onFullBackup(FullBackupDataOutput data) throws IOException {
+        // At present we back up only the wallpaper
+        fullWallpaperBackup(data);
+    }
+
+    private void fullWallpaperBackup(FullBackupDataOutput output) {
+        // Back up the data files directly.  We do them in this specific order --
+        // info file followed by image -- because then we need take no special
+        // steps during restore; the restore will happen properly when the individual
+        // files are restored piecemeal.
+        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
+                WALLPAPER_INFO_DIR, WALLPAPER_INFO, output.getData());
+        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
+                WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output.getData());
+    }
+
+    @Override
+    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
+            throws IOException {
+        // On restore, we also support a previous data schema "system_files"
+        addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this,
+                new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO },
+                new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY} ));
+        addHelper("system_files", new WallpaperBackupHelper(SystemBackupAgent.this,
+                new String[] { WALLPAPER_IMAGE },
+                new String[] { WALLPAPER_IMAGE_KEY} ));
+
+        try {
+            super.onRestore(data, appVersionCode, newState);
+
+            IWallpaperManager wallpaper = (IWallpaperManager) ServiceManager.getService(
+                    Context.WALLPAPER_SERVICE);
+            if (wallpaper != null) {
+                try {
+                    wallpaper.settingsRestored();
+                } catch (RemoteException re) {
+                    Slog.e(TAG, "Couldn't restore settings\n" + re);
+                }
+            }
+        } catch (IOException ex) {
+            // If there was a failure, delete everything for the wallpaper, this is too aggressive,
+            // but this is hopefully a rare failure.
+            Slog.d(TAG, "restore failed", ex);
+            (new File(WALLPAPER_IMAGE)).delete();
+            (new File(WALLPAPER_INFO)).delete();
+        }
+    }
+
+    @Override
+    public void onRestoreFile(ParcelFileDescriptor data, long size,
+            int type, String domain, String path, long mode, long mtime)
+            throws IOException {
+        Slog.i(TAG, "Restoring file domain=" + domain + " path=" + path);
+
+        // Bits to indicate postprocessing we may need to perform
+        boolean restoredWallpaper = false;
+
+        File outFile = null;
+        // Various domain+files we understand a priori
+        if (domain.equals(FullBackup.ROOT_TREE_TOKEN)) {
+            if (path.equals(WALLPAPER_INFO_FILENAME)) {
+                outFile = new File(WALLPAPER_INFO);
+                restoredWallpaper = true;
+            } else if (path.equals(WALLPAPER_IMAGE_FILENAME)) {
+                outFile = new File(WALLPAPER_IMAGE);
+                restoredWallpaper = true;
+            }
+        }
+
+        try {
+            if (outFile == null) {
+                Slog.w(TAG, "Skipping unrecognized system file: [ " + domain + " : " + path + " ]");
+            }
+            FullBackup.restoreFile(data, size, type, mode, mtime, outFile);
+
+            if (restoredWallpaper) {
+                IWallpaperManager wallpaper =
+                        (IWallpaperManager)ServiceManager.getService(
+                        Context.WALLPAPER_SERVICE);
+                if (wallpaper != null) {
+                    try {
+                        wallpaper.settingsRestored();
+                    } catch (RemoteException re) {
+                        Slog.e(TAG, "Couldn't restore settings\n" + re);
+                    }
+                }
+            }
+        } catch (IOException e) {
+            if (restoredWallpaper) {
+                // Make sure we wind up in a good state
+                (new File(WALLPAPER_IMAGE)).delete();
+                (new File(WALLPAPER_INFO)).delete();
+            }
+        }
+    }
+}
diff --git a/services/core/Android.mk b/services/core/Android.mk
new file mode 100644
index 0000000..5c45201
--- /dev/null
+++ b/services/core/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.core
+
+LOCAL_SRC_FILES += \
+    $(call all-java-files-under,java) \
+    java/com/android/server/EventLogTags.logtags \
+    java/com/android/server/am/EventLogTags.logtags
+
+LOCAL_JAVA_LIBRARIES := android.policy telephony-common
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/core/java/com/android/server/AlarmManagerService.java b/services/core/java/com/android/server/AlarmManagerService.java
new file mode 100644
index 0000000..96063d5
--- /dev/null
+++ b/services/core/java/com/android/server/AlarmManagerService.java
@@ -0,0 +1,1519 @@
+/*
+ * Copyright (C) 2006 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;
+
+import android.app.Activity;
+import android.app.ActivityManagerNative;
+import android.app.AlarmManager;
+import android.app.IAlarmManager;
+import android.app.PendingIntent;
+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.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.WorkSource;
+import android.text.TextUtils;
+import android.util.Pair;
+import android.util.Slog;
+import android.util.TimeUtils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.TimeZone;
+
+import static android.app.AlarmManager.RTC_WAKEUP;
+import static android.app.AlarmManager.RTC;
+import static android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP;
+import static android.app.AlarmManager.ELAPSED_REALTIME;
+
+import com.android.internal.util.LocalLog;
+
+class AlarmManagerService extends SystemService {
+    // The threshold for how long an alarm can be late before we print a
+    // warning message.  The time duration is in milliseconds.
+    private static final long LATE_ALARM_THRESHOLD = 10 * 1000;
+
+    private static final int RTC_WAKEUP_MASK = 1 << RTC_WAKEUP;
+    private static final int RTC_MASK = 1 << RTC;
+    private static final int ELAPSED_REALTIME_WAKEUP_MASK = 1 << ELAPSED_REALTIME_WAKEUP;
+    private static final int ELAPSED_REALTIME_MASK = 1 << ELAPSED_REALTIME;
+    static final int TIME_CHANGED_MASK = 1 << 16;
+    static final int IS_WAKEUP_MASK = RTC_WAKEUP_MASK|ELAPSED_REALTIME_WAKEUP_MASK;
+
+    // Mask for testing whether a given alarm type is wakeup vs non-wakeup
+    static final int TYPE_NONWAKEUP_MASK = 0x1; // low bit => non-wakeup
+
+    static final String TAG = "AlarmManager";
+    static final String ClockReceiver_TAG = "ClockReceiver";
+    static final boolean localLOGV = false;
+    static final boolean DEBUG_BATCH = localLOGV || false;
+    static final boolean DEBUG_VALIDATE = localLOGV || false;
+    static final int ALARM_EVENT = 1;
+    static final String TIMEZONE_PROPERTY = "persist.sys.timezone";
+    
+    static final Intent mBackgroundIntent
+            = new Intent().addFlags(Intent.FLAG_FROM_BACKGROUND);
+    static final IncreasingTimeOrder sIncreasingTimeOrder = new IncreasingTimeOrder();
+    
+    static final boolean WAKEUP_STATS = false;
+
+    final LocalLog mLog = new LocalLog(TAG);
+
+    final Object mLock = new Object();
+
+    long mNativeData;
+    private long mNextWakeup;
+    private long mNextNonWakeup;
+    int mBroadcastRefCount = 0;
+    PowerManager.WakeLock mWakeLock;
+    ArrayList<InFlight> mInFlight = new ArrayList<InFlight>();
+    final AlarmHandler mHandler = new AlarmHandler();
+    ClockReceiver mClockReceiver;
+    private UninstallReceiver mUninstallReceiver;
+    final ResultReceiver mResultReceiver = new ResultReceiver();
+    PendingIntent mTimeTickSender;
+    PendingIntent mDateChangeSender;
+
+    class WakeupEvent {
+        public long when;
+        public int uid;
+        public String action;
+
+        public WakeupEvent(long theTime, int theUid, String theAction) {
+            when = theTime;
+            uid = theUid;
+            action = theAction;
+        }
+    }
+
+    final LinkedList<WakeupEvent> mRecentWakeups = new LinkedList<WakeupEvent>();
+    final long RECENT_WAKEUP_PERIOD = 1000L * 60 * 60 * 24; // one day
+
+    static final class Batch {
+        long start;     // These endpoints are always in ELAPSED
+        long end;
+        boolean standalone; // certain "batches" don't participate in coalescing
+
+        final ArrayList<Alarm> alarms = new ArrayList<Alarm>();
+
+        Batch() {
+            start = 0;
+            end = Long.MAX_VALUE;
+        }
+
+        Batch(Alarm seed) {
+            start = seed.whenElapsed;
+            end = seed.maxWhen;
+            alarms.add(seed);
+        }
+
+        int size() {
+            return alarms.size();
+        }
+
+        Alarm get(int index) {
+            return alarms.get(index);
+        }
+
+        boolean canHold(long whenElapsed, long maxWhen) {
+            return (end >= whenElapsed) && (start <= maxWhen);
+        }
+
+        boolean add(Alarm alarm) {
+            boolean newStart = false;
+            // narrows the batch if necessary; presumes that canHold(alarm) is true
+            int index = Collections.binarySearch(alarms, alarm, sIncreasingTimeOrder);
+            if (index < 0) {
+                index = 0 - index - 1;
+            }
+            alarms.add(index, alarm);
+            if (DEBUG_BATCH) {
+                Slog.v(TAG, "Adding " + alarm + " to " + this);
+            }
+            if (alarm.whenElapsed > start) {
+                start = alarm.whenElapsed;
+                newStart = true;
+            }
+            if (alarm.maxWhen < end) {
+                end = alarm.maxWhen;
+            }
+
+            if (DEBUG_BATCH) {
+                Slog.v(TAG, "    => now " + this);
+            }
+            return newStart;
+        }
+
+        boolean remove(final PendingIntent operation) {
+            boolean didRemove = false;
+            long newStart = 0;  // recalculate endpoints as we go
+            long newEnd = Long.MAX_VALUE;
+            for (int i = 0; i < alarms.size(); ) {
+                Alarm alarm = alarms.get(i);
+                if (alarm.operation.equals(operation)) {
+                    alarms.remove(i);
+                    didRemove = true;
+                } else {
+                    if (alarm.whenElapsed > newStart) {
+                        newStart = alarm.whenElapsed;
+                    }
+                    if (alarm.maxWhen < newEnd) {
+                        newEnd = alarm.maxWhen;
+                    }
+                    i++;
+                }
+            }
+            if (didRemove) {
+                // commit the new batch bounds
+                start = newStart;
+                end = newEnd;
+            }
+            return didRemove;
+        }
+
+        boolean remove(final String packageName) {
+            boolean didRemove = false;
+            long newStart = 0;  // recalculate endpoints as we go
+            long newEnd = Long.MAX_VALUE;
+            for (int i = 0; i < alarms.size(); ) {
+                Alarm alarm = alarms.get(i);
+                if (alarm.operation.getTargetPackage().equals(packageName)) {
+                    alarms.remove(i);
+                    didRemove = true;
+                } else {
+                    if (alarm.whenElapsed > newStart) {
+                        newStart = alarm.whenElapsed;
+                    }
+                    if (alarm.maxWhen < newEnd) {
+                        newEnd = alarm.maxWhen;
+                    }
+                    i++;
+                }
+            }
+            if (didRemove) {
+                // commit the new batch bounds
+                start = newStart;
+                end = newEnd;
+            }
+            return didRemove;
+        }
+
+        boolean remove(final int userHandle) {
+            boolean didRemove = false;
+            long newStart = 0;  // recalculate endpoints as we go
+            long newEnd = Long.MAX_VALUE;
+            for (int i = 0; i < alarms.size(); ) {
+                Alarm alarm = alarms.get(i);
+                if (UserHandle.getUserId(alarm.operation.getCreatorUid()) == userHandle) {
+                    alarms.remove(i);
+                    didRemove = true;
+                } else {
+                    if (alarm.whenElapsed > newStart) {
+                        newStart = alarm.whenElapsed;
+                    }
+                    if (alarm.maxWhen < newEnd) {
+                        newEnd = alarm.maxWhen;
+                    }
+                    i++;
+                }
+            }
+            if (didRemove) {
+                // commit the new batch bounds
+                start = newStart;
+                end = newEnd;
+            }
+            return didRemove;
+        }
+
+        boolean hasPackage(final String packageName) {
+            final int N = alarms.size();
+            for (int i = 0; i < N; i++) {
+                Alarm a = alarms.get(i);
+                if (a.operation.getTargetPackage().equals(packageName)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        boolean hasWakeups() {
+            final int N = alarms.size();
+            for (int i = 0; i < N; i++) {
+                Alarm a = alarms.get(i);
+                // non-wakeup alarms are types 1 and 3, i.e. have the low bit set
+                if ((a.type & TYPE_NONWAKEUP_MASK) == 0) {
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder b = new StringBuilder(40);
+            b.append("Batch{"); b.append(Integer.toHexString(this.hashCode()));
+            b.append(" num="); b.append(size());
+            b.append(" start="); b.append(start);
+            b.append(" end="); b.append(end);
+            if (standalone) {
+                b.append(" STANDALONE");
+            }
+            b.append('}');
+            return b.toString();
+        }
+    }
+
+    static class BatchTimeOrder implements Comparator<Batch> {
+        public int compare(Batch b1, Batch b2) {
+            long when1 = b1.start;
+            long when2 = b2.start;
+            if (when1 - when2 > 0) {
+                return 1;
+            }
+            if (when1 - when2 < 0) {
+                return -1;
+            }
+            return 0;
+        }
+    }
+    
+    // minimum recurrence period or alarm futurity for us to be able to fuzz it
+    static final long MIN_FUZZABLE_INTERVAL = 10000;
+    static final BatchTimeOrder sBatchOrder = new BatchTimeOrder();
+    final ArrayList<Batch> mAlarmBatches = new ArrayList<Batch>();
+
+    public AlarmManagerService(Context context) {
+        super(context);
+    }
+
+    static long convertToElapsed(long when, int type) {
+        final boolean isRtc = (type == RTC || type == RTC_WAKEUP);
+        if (isRtc) {
+            when -= System.currentTimeMillis() - SystemClock.elapsedRealtime();
+        }
+        return when;
+    }
+
+    // Apply a heuristic to { recurrence interval, futurity of the trigger time } to
+    // calculate the end of our nominal delivery window for the alarm.
+    static long maxTriggerTime(long now, long triggerAtTime, long interval) {
+        // Current heuristic: batchable window is 75% of either the recurrence interval
+        // [for a periodic alarm] or of the time from now to the desired delivery time,
+        // with a minimum delay/interval of 10 seconds, under which we will simply not
+        // defer the alarm.
+        long futurity = (interval == 0)
+                ? (triggerAtTime - now)
+                : interval;
+        if (futurity < MIN_FUZZABLE_INTERVAL) {
+            futurity = 0;
+        }
+        return triggerAtTime + (long)(.75 * futurity);
+    }
+
+    // returns true if the batch was added at the head
+    static boolean addBatchLocked(ArrayList<Batch> list, Batch newBatch) {
+        int index = Collections.binarySearch(list, newBatch, sBatchOrder);
+        if (index < 0) {
+            index = 0 - index - 1;
+        }
+        list.add(index, newBatch);
+        return (index == 0);
+    }
+
+    // Return the index of the matching batch, or -1 if none found.
+    int attemptCoalesceLocked(long whenElapsed, long maxWhen) {
+        final int N = mAlarmBatches.size();
+        for (int i = 0; i < N; i++) {
+            Batch b = mAlarmBatches.get(i);
+            if (!b.standalone && b.canHold(whenElapsed, maxWhen)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    // The RTC clock has moved arbitrarily, so we need to recalculate all the batching
+    void rebatchAllAlarms() {
+        synchronized (mLock) {
+            rebatchAllAlarmsLocked(true);
+        }
+    }
+
+    void rebatchAllAlarmsLocked(boolean doValidate) {
+        ArrayList<Batch> oldSet = (ArrayList<Batch>) mAlarmBatches.clone();
+        mAlarmBatches.clear();
+        final long nowElapsed = SystemClock.elapsedRealtime();
+        final int oldBatches = oldSet.size();
+        for (int batchNum = 0; batchNum < oldBatches; batchNum++) {
+            Batch batch = oldSet.get(batchNum);
+            final int N = batch.size();
+            for (int i = 0; i < N; i++) {
+                Alarm a = batch.get(i);
+                long whenElapsed = convertToElapsed(a.when, a.type);
+                final long maxElapsed;
+                if (a.whenElapsed == a.maxWhen) {
+                    // Exact
+                    maxElapsed = whenElapsed;
+                } else {
+                    // Not exact.  Preserve any explicit window, otherwise recalculate
+                    // the window based on the alarm's new futurity.  Note that this
+                    // reflects a policy of preferring timely to deferred delivery.
+                    maxElapsed = (a.windowLength > 0)
+                            ? (whenElapsed + a.windowLength)
+                            : maxTriggerTime(nowElapsed, whenElapsed, a.repeatInterval);
+                }
+                setImplLocked(a.type, a.when, whenElapsed, a.windowLength, maxElapsed,
+                        a.repeatInterval, a.operation, batch.standalone, doValidate, a.workSource);
+            }
+        }
+    }
+
+    static final class InFlight extends Intent {
+        final PendingIntent mPendingIntent;
+        final WorkSource mWorkSource;
+        final Pair<String, ComponentName> mTarget;
+        final BroadcastStats mBroadcastStats;
+        final FilterStats mFilterStats;
+
+        InFlight(AlarmManagerService service, PendingIntent pendingIntent, WorkSource workSource) {
+            mPendingIntent = pendingIntent;
+            mWorkSource = workSource;
+            Intent intent = pendingIntent.getIntent();
+            mTarget = intent != null
+                    ? new Pair<String, ComponentName>(intent.getAction(), intent.getComponent())
+                    : null;
+            mBroadcastStats = service.getStatsLocked(pendingIntent);
+            FilterStats fs = mBroadcastStats.filterStats.get(mTarget);
+            if (fs == null) {
+                fs = new FilterStats(mBroadcastStats, mTarget);
+                mBroadcastStats.filterStats.put(mTarget, fs);
+            }
+            mFilterStats = fs;
+        }
+    }
+
+    static final class FilterStats {
+        final BroadcastStats mBroadcastStats;
+        final Pair<String, ComponentName> mTarget;
+
+        long aggregateTime;
+        int count;
+        int numWakeup;
+        long startTime;
+        int nesting;
+
+        FilterStats(BroadcastStats broadcastStats, Pair<String, ComponentName> target) {
+            mBroadcastStats = broadcastStats;
+            mTarget = target;
+        }
+    }
+    
+    static final class BroadcastStats {
+        final String mPackageName;
+
+        long aggregateTime;
+        int count;
+        int numWakeup;
+        long startTime;
+        int nesting;
+        final HashMap<Pair<String, ComponentName>, FilterStats> filterStats
+                = new HashMap<Pair<String, ComponentName>, FilterStats>();
+
+        BroadcastStats(String packageName) {
+            mPackageName = packageName;
+        }
+    }
+    
+    final HashMap<String, BroadcastStats> mBroadcastStats
+            = new HashMap<String, BroadcastStats>();
+    
+    @Override
+    public void onStart() {
+        mNativeData = init();
+        mNextWakeup = mNextNonWakeup = 0;
+
+        // We have to set current TimeZone info to kernel
+        // because kernel doesn't keep this after reboot
+        setTimeZoneImpl(SystemProperties.get(TIMEZONE_PROPERTY));
+
+        PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
+        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+        
+        mTimeTickSender = PendingIntent.getBroadcastAsUser(getContext(), 0,
+                new Intent(Intent.ACTION_TIME_TICK).addFlags(
+                        Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                        | Intent.FLAG_RECEIVER_FOREGROUND), 0,
+                        UserHandle.ALL);
+        Intent intent = new Intent(Intent.ACTION_DATE_CHANGED);
+        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+        mDateChangeSender = PendingIntent.getBroadcastAsUser(getContext(), 0, intent,
+                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, UserHandle.ALL);
+        
+        // now that we have initied the driver schedule the alarm
+        mClockReceiver = new ClockReceiver();
+        mClockReceiver.scheduleTimeTickEvent();
+        mClockReceiver.scheduleDateChangedEvent();
+        mUninstallReceiver = new UninstallReceiver();
+        
+        if (mNativeData != 0) {
+            AlarmThread waitThread = new AlarmThread();
+            waitThread.start();
+        } else {
+            Slog.w(TAG, "Failed to open alarm driver. Falling back to a handler.");
+        }
+
+        publishBinderService(Context.ALARM_SERVICE, mService);
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            close(mNativeData);
+        } finally {
+            super.finalize();
+        }
+    }
+
+    void setTimeZoneImpl(String tz) {
+        if (TextUtils.isEmpty(tz)) {
+            return;
+        }
+
+        TimeZone zone = TimeZone.getTimeZone(tz);
+        // Prevent reentrant calls from stepping on each other when writing
+        // the time zone property
+        boolean timeZoneWasChanged = false;
+        synchronized (this) {
+            String current = SystemProperties.get(TIMEZONE_PROPERTY);
+            if (current == null || !current.equals(zone.getID())) {
+                if (localLOGV) {
+                    Slog.v(TAG, "timezone changed: " + current + ", new=" + zone.getID());
+                }
+                timeZoneWasChanged = true;
+                SystemProperties.set(TIMEZONE_PROPERTY, zone.getID());
+            }
+
+            // Update the kernel timezone information
+            // Kernel tracks time offsets as 'minutes west of GMT'
+            int gmtOffset = zone.getOffset(System.currentTimeMillis());
+            setKernelTimezone(mNativeData, -(gmtOffset / 60000));
+        }
+
+        TimeZone.setDefault(null);
+
+        if (timeZoneWasChanged) {
+            Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
+            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+            intent.putExtra("time-zone", zone.getID());
+            getContext().sendBroadcastAsUser(intent, UserHandle.ALL);
+        }
+    }
+
+    void removeImpl(PendingIntent operation) {
+        if (operation == null) {
+            return;
+        }
+        synchronized (mLock) {
+            removeLocked(operation);
+        }
+    }
+
+    void setImpl(int type, long triggerAtTime, long windowLength, long interval,
+            PendingIntent operation, boolean isStandalone, WorkSource workSource) {
+        if (operation == null) {
+            Slog.w(TAG, "set/setRepeating ignored because there is no intent");
+            return;
+        }
+
+        // Sanity check the window length.  This will catch people mistakenly
+        // trying to pass an end-of-window timestamp rather than a duration.
+        if (windowLength > AlarmManager.INTERVAL_HALF_DAY) {
+            Slog.w(TAG, "Window length " + windowLength
+                    + "ms suspiciously long; limiting to 1 hour");
+            windowLength = AlarmManager.INTERVAL_HOUR;
+        }
+
+        if (type < RTC_WAKEUP || type > ELAPSED_REALTIME) {
+            throw new IllegalArgumentException("Invalid alarm type " + type);
+        }
+
+        if (triggerAtTime < 0) {
+            final long who = Binder.getCallingUid();
+            final long what = Binder.getCallingPid();
+            Slog.w(TAG, "Invalid alarm trigger time! " + triggerAtTime + " from uid=" + who
+                    + " pid=" + what);
+            triggerAtTime = 0;
+        }
+
+        final long nowElapsed = SystemClock.elapsedRealtime();
+        final long triggerElapsed = convertToElapsed(triggerAtTime, type);
+        final long maxElapsed;
+        if (windowLength == AlarmManager.WINDOW_EXACT) {
+            maxElapsed = triggerElapsed;
+        } else if (windowLength < 0) {
+            maxElapsed = maxTriggerTime(nowElapsed, triggerElapsed, interval);
+        } else {
+            maxElapsed = triggerElapsed + windowLength;
+        }
+
+        synchronized (mLock) {
+            if (DEBUG_BATCH) {
+                Slog.v(TAG, "set(" + operation + ") : type=" + type
+                        + " triggerAtTime=" + triggerAtTime + " win=" + windowLength
+                        + " tElapsed=" + triggerElapsed + " maxElapsed=" + maxElapsed
+                        + " interval=" + interval + " standalone=" + isStandalone);
+            }
+            setImplLocked(type, triggerAtTime, triggerElapsed, windowLength, maxElapsed,
+                    interval, operation, isStandalone, true, workSource);
+        }
+    }
+
+    private void setImplLocked(int type, long when, long whenElapsed, long windowLength,
+            long maxWhen, long interval, PendingIntent operation, boolean isStandalone,
+            boolean doValidate, WorkSource workSource) {
+        Alarm a = new Alarm(type, when, whenElapsed, windowLength, maxWhen, interval,
+                operation, workSource);
+        removeLocked(operation);
+
+        int whichBatch = (isStandalone) ? -1 : attemptCoalesceLocked(whenElapsed, maxWhen);
+        if (whichBatch < 0) {
+            Batch batch = new Batch(a);
+            batch.standalone = isStandalone;
+            addBatchLocked(mAlarmBatches, batch);
+        } else {
+            Batch batch = mAlarmBatches.get(whichBatch);
+            if (batch.add(a)) {
+                // The start time of this batch advanced, so batch ordering may
+                // have just been broken.  Move it to where it now belongs.
+                mAlarmBatches.remove(whichBatch);
+                addBatchLocked(mAlarmBatches, batch);
+            }
+        }
+
+        if (DEBUG_VALIDATE) {
+            if (doValidate && !validateConsistencyLocked()) {
+                Slog.v(TAG, "Tipping-point operation: type=" + type + " when=" + when
+                        + " when(hex)=" + Long.toHexString(when)
+                        + " whenElapsed=" + whenElapsed + " maxWhen=" + maxWhen
+                        + " interval=" + interval + " op=" + operation
+                        + " standalone=" + isStandalone);
+                rebatchAllAlarmsLocked(false);
+            }
+        }
+
+        rescheduleKernelAlarmsLocked();
+    }
+
+    private final IBinder mService = new IAlarmManager.Stub() {
+        @Override
+        public void set(int type, long triggerAtTime, long windowLength, long interval,
+                PendingIntent operation, WorkSource workSource) {
+            if (workSource != null) {
+                getContext().enforceCallingPermission(
+                        android.Manifest.permission.UPDATE_DEVICE_STATS,
+                        "AlarmManager.set");
+            }
+
+            setImpl(type, triggerAtTime, windowLength, interval, operation,
+                    false, workSource);
+        }
+
+        @Override
+        public void setTime(long millis) {
+            getContext().enforceCallingOrSelfPermission(
+                    "android.permission.SET_TIME",
+                    "setTime");
+
+            SystemClock.setCurrentTimeMillis(millis);
+        }
+
+        @Override
+        public void setTimeZone(String tz) {
+            getContext().enforceCallingOrSelfPermission(
+                    "android.permission.SET_TIME_ZONE",
+                    "setTimeZone");
+
+            final long oldId = Binder.clearCallingIdentity();
+            try {
+                setTimeZoneImpl(tz);
+            } finally {
+                Binder.restoreCallingIdentity(oldId);
+            }
+        }
+
+        @Override
+        public void remove(PendingIntent operation) {
+            removeImpl(operation);
+
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump AlarmManager from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            dumpImpl(pw);
+        }
+    };
+
+    void dumpImpl(PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println("Current Alarm Manager state:");
+            final long nowRTC = System.currentTimeMillis();
+            final long nowELAPSED = SystemClock.elapsedRealtime();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+            pw.print("nowRTC="); pw.print(nowRTC);
+            pw.print("="); pw.print(sdf.format(new Date(nowRTC)));
+            pw.print(" nowELAPSED="); pw.println(nowELAPSED);
+
+            long nextWakeupRTC = mNextWakeup + (nowRTC - nowELAPSED);
+            long nextNonWakeupRTC = mNextNonWakeup + (nowRTC - nowELAPSED);
+            pw.print("Next alarm: "); pw.print(mNextNonWakeup);
+                    pw.print(" = "); pw.println(sdf.format(new Date(nextNonWakeupRTC)));
+            pw.print("Next wakeup: "); pw.print(mNextWakeup);
+                    pw.print(" = "); pw.println(sdf.format(new Date(nextWakeupRTC)));
+
+            if (mAlarmBatches.size() > 0) {
+                pw.println();
+                pw.print("Pending alarm batches: ");
+                pw.println(mAlarmBatches.size());
+                for (Batch b : mAlarmBatches) {
+                    pw.print(b); pw.println(':');
+                    dumpAlarmList(pw, b.alarms, "  ", nowELAPSED, nowRTC);
+                }
+            }
+
+            pw.println();
+            pw.print("  Broadcast ref count: "); pw.println(mBroadcastRefCount);
+            pw.println();
+
+            if (mLog.dump(pw, "  Recent problems", "    ")) {
+                pw.println();
+            }
+
+            final FilterStats[] topFilters = new FilterStats[10];
+            final Comparator<FilterStats> comparator = new Comparator<FilterStats>() {
+                @Override
+                public int compare(FilterStats lhs, FilterStats rhs) {
+                    if (lhs.aggregateTime < rhs.aggregateTime) {
+                        return 1;
+                    } else if (lhs.aggregateTime > rhs.aggregateTime) {
+                        return -1;
+                    }
+                    return 0;
+                }
+            };
+            int len = 0;
+            for (Map.Entry<String, BroadcastStats> be : mBroadcastStats.entrySet()) {
+                BroadcastStats bs = be.getValue();
+                for (Map.Entry<Pair<String, ComponentName>, FilterStats> fe
+                        : bs.filterStats.entrySet()) {
+                    FilterStats fs = fe.getValue();
+                    int pos = len > 0
+                            ? Arrays.binarySearch(topFilters, 0, len, fs, comparator) : 0;
+                    if (pos < 0) {
+                        pos = -pos - 1;
+                    }
+                    if (pos < topFilters.length) {
+                        int copylen = topFilters.length - pos - 1;
+                        if (copylen > 0) {
+                            System.arraycopy(topFilters, pos, topFilters, pos+1, copylen);
+                        }
+                        topFilters[pos] = fs;
+                        if (len < topFilters.length) {
+                            len++;
+                        }
+                    }
+                }
+            }
+            if (len > 0) {
+                pw.println("  Top Alarms:");
+                for (int i=0; i<len; i++) {
+                    FilterStats fs = topFilters[i];
+                    pw.print("    ");
+                    if (fs.nesting > 0) pw.print("*ACTIVE* ");
+                    TimeUtils.formatDuration(fs.aggregateTime, pw);
+                    pw.print(" running, "); pw.print(fs.numWakeup);
+                    pw.print(" wakeups, "); pw.print(fs.count);
+                    pw.print(" alarms: "); pw.print(fs.mBroadcastStats.mPackageName);
+                    pw.println();
+                    pw.print("      ");
+                    if (fs.mTarget.first != null) {
+                        pw.print(" act="); pw.print(fs.mTarget.first);
+                    }
+                    if (fs.mTarget.second != null) {
+                        pw.print(" cmp="); pw.print(fs.mTarget.second.toShortString());
+                    }
+                    pw.println();
+                }
+            }
+
+            pw.println(" ");
+            pw.println("  Alarm Stats:");
+            final ArrayList<FilterStats> tmpFilters = new ArrayList<FilterStats>();
+            for (Map.Entry<String, BroadcastStats> be : mBroadcastStats.entrySet()) {
+                BroadcastStats bs = be.getValue();
+                pw.print("  ");
+                if (bs.nesting > 0) pw.print("*ACTIVE* ");
+                pw.print(be.getKey());
+                pw.print(" "); TimeUtils.formatDuration(bs.aggregateTime, pw);
+                        pw.print(" running, "); pw.print(bs.numWakeup);
+                        pw.println(" wakeups:");
+                tmpFilters.clear();
+                for (Map.Entry<Pair<String, ComponentName>, FilterStats> fe
+                        : bs.filterStats.entrySet()) {
+                    tmpFilters.add(fe.getValue());
+                }
+                Collections.sort(tmpFilters, comparator);
+                for (int i=0; i<tmpFilters.size(); i++) {
+                    FilterStats fs = tmpFilters.get(i);
+                    pw.print("    ");
+                            if (fs.nesting > 0) pw.print("*ACTIVE* ");
+                            TimeUtils.formatDuration(fs.aggregateTime, pw);
+                            pw.print(" "); pw.print(fs.numWakeup);
+                            pw.print(" wakes " ); pw.print(fs.count);
+                            pw.print(" alarms:");
+                            if (fs.mTarget.first != null) {
+                                pw.print(" act="); pw.print(fs.mTarget.first);
+                            }
+                            if (fs.mTarget.second != null) {
+                                pw.print(" cmp="); pw.print(fs.mTarget.second.toShortString());
+                            }
+                            pw.println();
+                }
+            }
+
+            if (WAKEUP_STATS) {
+                pw.println();
+                pw.println("  Recent Wakeup History:");
+                long last = -1;
+                for (WakeupEvent event : mRecentWakeups) {
+                    pw.print("    "); pw.print(sdf.format(new Date(event.when)));
+                    pw.print('|');
+                    if (last < 0) {
+                        pw.print('0');
+                    } else {
+                        pw.print(event.when - last);
+                    }
+                    last = event.when;
+                    pw.print('|'); pw.print(event.uid);
+                    pw.print('|'); pw.print(event.action);
+                    pw.println();
+                }
+                pw.println();
+            }
+        }
+    }
+
+    private void logBatchesLocked() {
+        ByteArrayOutputStream bs = new ByteArrayOutputStream(2048);
+        PrintWriter pw = new PrintWriter(bs);
+        final long nowRTC = System.currentTimeMillis();
+        final long nowELAPSED = SystemClock.elapsedRealtime();
+        final int NZ = mAlarmBatches.size();
+        for (int iz = 0; iz < NZ; iz++) {
+            Batch bz = mAlarmBatches.get(iz);
+            pw.append("Batch "); pw.print(iz); pw.append(": "); pw.println(bz);
+            dumpAlarmList(pw, bz.alarms, "  ", nowELAPSED, nowRTC);
+            pw.flush();
+            Slog.v(TAG, bs.toString());
+            bs.reset();
+        }
+    }
+
+    private boolean validateConsistencyLocked() {
+        if (DEBUG_VALIDATE) {
+            long lastTime = Long.MIN_VALUE;
+            final int N = mAlarmBatches.size();
+            for (int i = 0; i < N; i++) {
+                Batch b = mAlarmBatches.get(i);
+                if (b.start >= lastTime) {
+                    // duplicate start times are okay because of standalone batches
+                    lastTime = b.start;
+                } else {
+                    Slog.e(TAG, "CONSISTENCY FAILURE: Batch " + i + " is out of order");
+                    logBatchesLocked();
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    private Batch findFirstWakeupBatchLocked() {
+        final int N = mAlarmBatches.size();
+        for (int i = 0; i < N; i++) {
+            Batch b = mAlarmBatches.get(i);
+            if (b.hasWakeups()) {
+                return b;
+            }
+        }
+        return null;
+    }
+
+    void rescheduleKernelAlarmsLocked() {
+        // Schedule the next upcoming wakeup alarm.  If there is a deliverable batch
+        // prior to that which contains no wakeups, we schedule that as well.
+        if (mAlarmBatches.size() > 0) {
+            final Batch firstWakeup = findFirstWakeupBatchLocked();
+            final Batch firstBatch = mAlarmBatches.get(0);
+            if (firstWakeup != null && mNextWakeup != firstWakeup.start) {
+                mNextWakeup = firstWakeup.start;
+                setLocked(ELAPSED_REALTIME_WAKEUP, firstWakeup.start);
+            }
+            if (firstBatch != firstWakeup && mNextNonWakeup != firstBatch.start) {
+                mNextNonWakeup = firstBatch.start;
+                setLocked(ELAPSED_REALTIME, firstBatch.start);
+            }
+        }
+    }
+
+    private void removeLocked(PendingIntent operation) {
+        boolean didRemove = false;
+        for (int i = mAlarmBatches.size() - 1; i >= 0; i--) {
+            Batch b = mAlarmBatches.get(i);
+            didRemove |= b.remove(operation);
+            if (b.size() == 0) {
+                mAlarmBatches.remove(i);
+            }
+        }
+
+        if (didRemove) {
+            if (DEBUG_BATCH) {
+                Slog.v(TAG, "remove(operation) changed bounds; rebatching");
+            }
+            rebatchAllAlarmsLocked(true);
+            rescheduleKernelAlarmsLocked();
+        }
+    }
+
+    void removeLocked(String packageName) {
+        boolean didRemove = false;
+        for (int i = mAlarmBatches.size() - 1; i >= 0; i--) {
+            Batch b = mAlarmBatches.get(i);
+            didRemove |= b.remove(packageName);
+            if (b.size() == 0) {
+                mAlarmBatches.remove(i);
+            }
+        }
+
+        if (didRemove) {
+            if (DEBUG_BATCH) {
+                Slog.v(TAG, "remove(package) changed bounds; rebatching");
+            }
+            rebatchAllAlarmsLocked(true);
+            rescheduleKernelAlarmsLocked();
+        }
+    }
+
+    void removeUserLocked(int userHandle) {
+        boolean didRemove = false;
+        for (int i = mAlarmBatches.size() - 1; i >= 0; i--) {
+            Batch b = mAlarmBatches.get(i);
+            didRemove |= b.remove(userHandle);
+            if (b.size() == 0) {
+                mAlarmBatches.remove(i);
+            }
+        }
+
+        if (didRemove) {
+            if (DEBUG_BATCH) {
+                Slog.v(TAG, "remove(user) changed bounds; rebatching");
+            }
+            rebatchAllAlarmsLocked(true);
+            rescheduleKernelAlarmsLocked();
+        }
+    }
+
+    boolean lookForPackageLocked(String packageName) {
+        for (int i = 0; i < mAlarmBatches.size(); i++) {
+            Batch b = mAlarmBatches.get(i);
+            if (b.hasPackage(packageName)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private void setLocked(int type, long when) {
+        if (mNativeData != 0) {
+            // The kernel never triggers alarms with negative wakeup times
+            // so we ensure they are positive.
+            long alarmSeconds, alarmNanoseconds;
+            if (when < 0) {
+                alarmSeconds = 0;
+                alarmNanoseconds = 0;
+            } else {
+                alarmSeconds = when / 1000;
+                alarmNanoseconds = (when % 1000) * 1000 * 1000;
+            }
+            
+            set(mNativeData, type, alarmSeconds, alarmNanoseconds);
+        } else {
+            Message msg = Message.obtain();
+            msg.what = ALARM_EVENT;
+            
+            mHandler.removeMessages(ALARM_EVENT);
+            mHandler.sendMessageAtTime(msg, when);
+        }
+    }
+
+    private static final void dumpAlarmList(PrintWriter pw, ArrayList<Alarm> list,
+            String prefix, String label, long now) {
+        for (int i=list.size()-1; i>=0; i--) {
+            Alarm a = list.get(i);
+            pw.print(prefix); pw.print(label); pw.print(" #"); pw.print(i);
+                    pw.print(": "); pw.println(a);
+            a.dump(pw, prefix + "  ", now);
+        }
+    }
+
+    private static final String labelForType(int type) {
+        switch (type) {
+        case RTC: return "RTC";
+        case RTC_WAKEUP : return "RTC_WAKEUP";
+        case ELAPSED_REALTIME : return "ELAPSED";
+        case ELAPSED_REALTIME_WAKEUP: return "ELAPSED_WAKEUP";
+        default:
+            break;
+        }
+        return "--unknown--";
+    }
+
+    private static final void dumpAlarmList(PrintWriter pw, ArrayList<Alarm> list,
+            String prefix, long nowELAPSED, long nowRTC) {
+        for (int i=list.size()-1; i>=0; i--) {
+            Alarm a = list.get(i);
+            final String label = labelForType(a.type);
+            long now = (a.type <= RTC) ? nowRTC : nowELAPSED;
+            pw.print(prefix); pw.print(label); pw.print(" #"); pw.print(i);
+                    pw.print(": "); pw.println(a);
+            a.dump(pw, prefix + "  ", now);
+        }
+    }
+
+    private native long init();
+    private native void close(long nativeData);
+    private native void set(long nativeData, int type, long seconds, long nanoseconds);
+    private native int waitForAlarm(long nativeData);
+    private native int setKernelTimezone(long nativeData, int minuteswest);
+
+    void triggerAlarmsLocked(ArrayList<Alarm> triggerList, long nowELAPSED, long nowRTC) {
+        // batches are temporally sorted, so we need only pull from the
+        // start of the list until we either empty it or hit a batch
+        // that is not yet deliverable
+        while (mAlarmBatches.size() > 0) {
+            Batch batch = mAlarmBatches.get(0);
+            if (batch.start > nowELAPSED) {
+                // Everything else is scheduled for the future
+                break;
+            }
+
+            // We will (re)schedule some alarms now; don't let that interfere
+            // with delivery of this current batch
+            mAlarmBatches.remove(0);
+
+            final int N = batch.size();
+            for (int i = 0; i < N; i++) {
+                Alarm alarm = batch.get(i);
+                alarm.count = 1;
+                triggerList.add(alarm);
+
+                // Recurring alarms may have passed several alarm intervals while the
+                // phone was asleep or off, so pass a trigger count when sending them.
+                if (alarm.repeatInterval > 0) {
+                    // this adjustment will be zero if we're late by
+                    // less than one full repeat interval
+                    alarm.count += (nowELAPSED - alarm.whenElapsed) / alarm.repeatInterval;
+
+                    // Also schedule its next recurrence
+                    final long delta = alarm.count * alarm.repeatInterval;
+                    final long nextElapsed = alarm.whenElapsed + delta;
+                    setImplLocked(alarm.type, alarm.when + delta, nextElapsed, alarm.windowLength,
+                            maxTriggerTime(nowELAPSED, nextElapsed, alarm.repeatInterval),
+                            alarm.repeatInterval, alarm.operation, batch.standalone, true,
+                            alarm.workSource);
+                }
+
+            }
+        }
+    }
+
+    /**
+     * This Comparator sorts Alarms into increasing time order.
+     */
+    public static class IncreasingTimeOrder implements Comparator<Alarm> {
+        public int compare(Alarm a1, Alarm a2) {
+            long when1 = a1.when;
+            long when2 = a2.when;
+            if (when1 - when2 > 0) {
+                return 1;
+            }
+            if (when1 - when2 < 0) {
+                return -1;
+            }
+            return 0;
+        }
+    }
+    
+    private static class Alarm {
+        public int type;
+        public int count;
+        public long when;
+        public long windowLength;
+        public long whenElapsed;    // 'when' in the elapsed time base
+        public long maxWhen;        // also in the elapsed time base
+        public long repeatInterval;
+        public PendingIntent operation;
+        public WorkSource workSource;
+        
+        public Alarm(int _type, long _when, long _whenElapsed, long _windowLength, long _maxWhen,
+                long _interval, PendingIntent _op, WorkSource _ws) {
+            type = _type;
+            when = _when;
+            whenElapsed = _whenElapsed;
+            windowLength = _windowLength;
+            maxWhen = _maxWhen;
+            repeatInterval = _interval;
+            operation = _op;
+            workSource = _ws;
+        }
+
+        @Override
+        public String toString()
+        {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("Alarm{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(" type ");
+            sb.append(type);
+            sb.append(" ");
+            sb.append(operation.getTargetPackage());
+            sb.append('}');
+            return sb.toString();
+        }
+
+        public void dump(PrintWriter pw, String prefix, long now) {
+            pw.print(prefix); pw.print("type="); pw.print(type);
+                    pw.print(" whenElapsed="); pw.print(whenElapsed);
+                    pw.print(" when="); TimeUtils.formatDuration(when, now, pw);
+                    pw.print(" window="); pw.print(windowLength);
+                    pw.print(" repeatInterval="); pw.print(repeatInterval);
+                    pw.print(" count="); pw.println(count);
+            pw.print(prefix); pw.print("operation="); pw.println(operation);
+        }
+    }
+
+    void recordWakeupAlarms(ArrayList<Batch> batches, long nowELAPSED, long nowRTC) {
+        final int numBatches = batches.size();
+        for (int nextBatch = 0; nextBatch < numBatches; nextBatch++) {
+            Batch b = batches.get(nextBatch);
+            if (b.start > nowELAPSED) {
+                break;
+            }
+
+            final int numAlarms = b.alarms.size();
+            for (int nextAlarm = 0; nextAlarm < numAlarms; nextAlarm++) {
+                Alarm a = b.alarms.get(nextAlarm);
+                WakeupEvent e = new WakeupEvent(nowRTC,
+                        a.operation.getCreatorUid(),
+                        a.operation.getIntent().getAction());
+                mRecentWakeups.add(e);
+            }
+        }
+    }
+
+    private class AlarmThread extends Thread
+    {
+        public AlarmThread()
+        {
+            super("AlarmManager");
+        }
+        
+        public void run()
+        {
+            ArrayList<Alarm> triggerList = new ArrayList<Alarm>();
+
+            while (true)
+            {
+                int result = waitForAlarm(mNativeData);
+
+                triggerList.clear();
+
+                if ((result & TIME_CHANGED_MASK) != 0) {
+                    if (DEBUG_BATCH) {
+                        Slog.v(TAG, "Time changed notification from kernel; rebatching");
+                    }
+                    removeImpl(mTimeTickSender);
+                    rebatchAllAlarms();
+                    mClockReceiver.scheduleTimeTickEvent();
+                    Intent intent = new Intent(Intent.ACTION_TIME_CHANGED);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
+                            | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+                    getContext().sendBroadcastAsUser(intent, UserHandle.ALL);
+                }
+                
+                synchronized (mLock) {
+                    final long nowRTC = System.currentTimeMillis();
+                    final long nowELAPSED = SystemClock.elapsedRealtime();
+                    if (localLOGV) Slog.v(
+                        TAG, "Checking for alarms... rtc=" + nowRTC
+                        + ", elapsed=" + nowELAPSED);
+
+                    if (WAKEUP_STATS) {
+                        if ((result & IS_WAKEUP_MASK) != 0) {
+                            long newEarliest = nowRTC - RECENT_WAKEUP_PERIOD;
+                            int n = 0;
+                            for (WakeupEvent event : mRecentWakeups) {
+                                if (event.when > newEarliest) break;
+                                n++; // number of now-stale entries at the list head
+                            }
+                            for (int i = 0; i < n; i++) {
+                                mRecentWakeups.remove();
+                            }
+
+                            recordWakeupAlarms(mAlarmBatches, nowELAPSED, nowRTC);
+                        }
+                    }
+
+                    triggerAlarmsLocked(triggerList, nowELAPSED, nowRTC);
+                    rescheduleKernelAlarmsLocked();
+
+                    // now deliver the alarm intents
+                    for (int i=0; i<triggerList.size(); i++) {
+                        Alarm alarm = triggerList.get(i);
+                        try {
+                            if (localLOGV) Slog.v(TAG, "sending alarm " + alarm);
+                            alarm.operation.send(getContext(), 0,
+                                    mBackgroundIntent.putExtra(
+                                            Intent.EXTRA_ALARM_COUNT, alarm.count),
+                                    mResultReceiver, mHandler);
+                            
+                            // we have an active broadcast so stay awake.
+                            if (mBroadcastRefCount == 0) {
+                                setWakelockWorkSource(alarm.operation, alarm.workSource);
+                                mWakeLock.acquire();
+                            }
+                            final InFlight inflight = new InFlight(AlarmManagerService.this,
+                                    alarm.operation, alarm.workSource);
+                            mInFlight.add(inflight);
+                            mBroadcastRefCount++;
+
+                            final BroadcastStats bs = inflight.mBroadcastStats;
+                            bs.count++;
+                            if (bs.nesting == 0) {
+                                bs.nesting = 1;
+                                bs.startTime = nowELAPSED;
+                            } else {
+                                bs.nesting++;
+                            }
+                            final FilterStats fs = inflight.mFilterStats;
+                            fs.count++;
+                            if (fs.nesting == 0) {
+                                fs.nesting = 1;
+                                fs.startTime = nowELAPSED;
+                            } else {
+                                fs.nesting++;
+                            }
+                            if (alarm.type == ELAPSED_REALTIME_WAKEUP
+                                    || alarm.type == RTC_WAKEUP) {
+                                bs.numWakeup++;
+                                fs.numWakeup++;
+                                ActivityManagerNative.noteWakeupAlarm(
+                                        alarm.operation);
+                            }
+                        } catch (PendingIntent.CanceledException e) {
+                            if (alarm.repeatInterval > 0) {
+                                // This IntentSender is no longer valid, but this
+                                // is a repeating alarm, so toss the hoser.
+                                removeImpl(alarm.operation);
+                            }
+                        } catch (RuntimeException e) {
+                            Slog.w(TAG, "Failure sending alarm.", e);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Attribute blame for a WakeLock.
+     * @param pi PendingIntent to attribute blame to if ws is null.
+     * @param ws WorkSource to attribute blame.
+     */
+    void setWakelockWorkSource(PendingIntent pi, WorkSource ws) {
+        try {
+            if (ws != null) {
+                mWakeLock.setWorkSource(ws);
+                return;
+            }
+
+            final int uid = ActivityManagerNative.getDefault()
+                    .getUidForIntentSender(pi.getTarget());
+            if (uid >= 0) {
+                mWakeLock.setWorkSource(new WorkSource(uid));
+                return;
+            }
+        } catch (Exception e) {
+        }
+
+        // Something went wrong; fall back to attributing the lock to the OS
+        mWakeLock.setWorkSource(null);
+    }
+
+    private class AlarmHandler extends Handler {
+        public static final int ALARM_EVENT = 1;
+        public static final int MINUTE_CHANGE_EVENT = 2;
+        public static final int DATE_CHANGE_EVENT = 3;
+        
+        public AlarmHandler() {
+        }
+        
+        public void handleMessage(Message msg) {
+            if (msg.what == ALARM_EVENT) {
+                ArrayList<Alarm> triggerList = new ArrayList<Alarm>();
+                synchronized (mLock) {
+                    final long nowRTC = System.currentTimeMillis();
+                    final long nowELAPSED = SystemClock.elapsedRealtime();
+                    triggerAlarmsLocked(triggerList, nowELAPSED, nowRTC);
+                }
+                
+                // now trigger the alarms without the lock held
+                for (int i=0; i<triggerList.size(); i++) {
+                    Alarm alarm = triggerList.get(i);
+                    try {
+                        alarm.operation.send();
+                    } catch (PendingIntent.CanceledException e) {
+                        if (alarm.repeatInterval > 0) {
+                            // This IntentSender is no longer valid, but this
+                            // is a repeating alarm, so toss the hoser.
+                            removeImpl(alarm.operation);
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    class ClockReceiver extends BroadcastReceiver {
+        public ClockReceiver() {
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_TIME_TICK);
+            filter.addAction(Intent.ACTION_DATE_CHANGED);
+            getContext().registerReceiver(this, filter);
+        }
+        
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
+                if (DEBUG_BATCH) {
+                    Slog.v(TAG, "Received TIME_TICK alarm; rescheduling");
+                }
+                scheduleTimeTickEvent();
+            } else if (intent.getAction().equals(Intent.ACTION_DATE_CHANGED)) {
+                // Since the kernel does not keep track of DST, we need to
+                // reset the TZ information at the beginning of each day
+                // based off of the current Zone gmt offset + userspace tracked
+                // daylight savings information.
+                TimeZone zone = TimeZone.getTimeZone(SystemProperties.get(TIMEZONE_PROPERTY));
+                int gmtOffset = zone.getOffset(System.currentTimeMillis());
+                setKernelTimezone(mNativeData, -(gmtOffset / 60000));
+                scheduleDateChangedEvent();
+            }
+        }
+        
+        public void scheduleTimeTickEvent() {
+            final long currentTime = System.currentTimeMillis();
+            final long nextTime = 60000 * ((currentTime / 60000) + 1);
+
+            // Schedule this event for the amount of time that it would take to get to
+            // the top of the next minute.
+            final long tickEventDelay = nextTime - currentTime;
+
+            final WorkSource workSource = null; // Let system take blame for time tick events.
+            setImpl(ELAPSED_REALTIME, SystemClock.elapsedRealtime() + tickEventDelay, 0,
+                    0, mTimeTickSender, true, workSource);
+        }
+
+        public void scheduleDateChangedEvent() {
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTimeInMillis(System.currentTimeMillis());
+            calendar.set(Calendar.HOUR, 0);
+            calendar.set(Calendar.MINUTE, 0);
+            calendar.set(Calendar.SECOND, 0);
+            calendar.set(Calendar.MILLISECOND, 0);
+            calendar.add(Calendar.DAY_OF_MONTH, 1);
+
+            final WorkSource workSource = null; // Let system take blame for date change events.
+            setImpl(RTC, calendar.getTimeInMillis(), 0, 0, mDateChangeSender, true, workSource);
+        }
+    }
+    
+    class UninstallReceiver extends BroadcastReceiver {
+        public UninstallReceiver() {
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+            filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
+            filter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
+            filter.addDataScheme("package");
+            getContext().registerReceiver(this, filter);
+             // Register for events related to sdcard installation.
+            IntentFilter sdFilter = new IntentFilter();
+            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+            sdFilter.addAction(Intent.ACTION_USER_STOPPED);
+            getContext().registerReceiver(this, sdFilter);
+        }
+        
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (mLock) {
+                String action = intent.getAction();
+                String pkgList[] = null;
+                if (Intent.ACTION_QUERY_PACKAGE_RESTART.equals(action)) {
+                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
+                    for (String packageName : pkgList) {
+                        if (lookForPackageLocked(packageName)) {
+                            setResultCode(Activity.RESULT_OK);
+                            return;
+                        }
+                    }
+                    return;
+                } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
+                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+                } else if (Intent.ACTION_USER_STOPPED.equals(action)) {
+                    int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+                    if (userHandle >= 0) {
+                        removeUserLocked(userHandle);
+                    }
+                } else {
+                    if (Intent.ACTION_PACKAGE_REMOVED.equals(action)
+                            && intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
+                        // This package is being updated; don't kill its alarms.
+                        return;
+                    }
+                    Uri data = intent.getData();
+                    if (data != null) {
+                        String pkg = data.getSchemeSpecificPart();
+                        if (pkg != null) {
+                            pkgList = new String[]{pkg};
+                        }
+                    }
+                }
+                if (pkgList != null && (pkgList.length > 0)) {
+                    for (String pkg : pkgList) {
+                        removeLocked(pkg);
+                        mBroadcastStats.remove(pkg);
+                    }
+                }
+            }
+        }
+    }
+    
+    private final BroadcastStats getStatsLocked(PendingIntent pi) {
+        String pkg = pi.getTargetPackage();
+        BroadcastStats bs = mBroadcastStats.get(pkg);
+        if (bs == null) {
+            bs = new BroadcastStats(pkg);
+            mBroadcastStats.put(pkg, bs);
+        }
+        return bs;
+    }
+
+    class ResultReceiver implements PendingIntent.OnFinished {
+        public void onSendFinished(PendingIntent pi, Intent intent, int resultCode,
+                String resultData, Bundle resultExtras) {
+            synchronized (mLock) {
+                InFlight inflight = null;
+                for (int i=0; i<mInFlight.size(); i++) {
+                    if (mInFlight.get(i).mPendingIntent == pi) {
+                        inflight = mInFlight.remove(i);
+                        break;
+                    }
+                }
+                if (inflight != null) {
+                    final long nowELAPSED = SystemClock.elapsedRealtime();
+                    BroadcastStats bs = inflight.mBroadcastStats;
+                    bs.nesting--;
+                    if (bs.nesting <= 0) {
+                        bs.nesting = 0;
+                        bs.aggregateTime += nowELAPSED - bs.startTime;
+                    }
+                    FilterStats fs = inflight.mFilterStats;
+                    fs.nesting--;
+                    if (fs.nesting <= 0) {
+                        fs.nesting = 0;
+                        fs.aggregateTime += nowELAPSED - fs.startTime;
+                    }
+                } else {
+                    mLog.w("No in-flight alarm for " + pi + " " + intent);
+                }
+                mBroadcastRefCount--;
+                if (mBroadcastRefCount == 0) {
+                    mWakeLock.release();
+                    if (mInFlight.size() > 0) {
+                        mLog.w("Finished all broadcasts with " + mInFlight.size()
+                                + " remaining inflights");
+                        for (int i=0; i<mInFlight.size(); i++) {
+                            mLog.w("  Remaining #" + i + ": " + mInFlight.get(i));
+                        }
+                        mInFlight.clear();
+                    }
+                } else {
+                    // the next of our alarms is now in flight.  reattribute the wakelock.
+                    if (mInFlight.size() > 0) {
+                        InFlight inFlight = mInFlight.get(0);
+                        setWakelockWorkSource(inFlight.mPendingIntent, inFlight.mWorkSource);
+                    } else {
+                        // should never happen
+                        mLog.w("Alarm wakelock still held but sent queue empty");
+                        mWakeLock.setWorkSource(null);
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/AppOpsService.java b/services/core/java/com/android/server/AppOpsService.java
new file mode 100644
index 0000000..e5615c0
--- /dev/null
+++ b/services/core/java/com/android/server/AppOpsService.java
@@ -0,0 +1,1083 @@
+/*
+ * 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.server;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.AsyncTask;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.ArrayMap;
+import android.util.AtomicFile;
+import android.util.Log;
+import android.util.Pair;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.TimeUtils;
+import android.util.Xml;
+
+import com.android.internal.app.IAppOpsService;
+import com.android.internal.app.IAppOpsCallback;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.XmlUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+public class AppOpsService extends IAppOpsService.Stub {
+    static final String TAG = "AppOps";
+    static final boolean DEBUG = false;
+
+    // Write at most every 30 minutes.
+    static final long WRITE_DELAY = DEBUG ? 1000 : 30*60*1000;
+
+    Context mContext;
+    final AtomicFile mFile;
+    final Handler mHandler;
+
+    boolean mWriteScheduled;
+    final Runnable mWriteRunner = new Runnable() {
+        public void run() {
+            synchronized (AppOpsService.this) {
+                mWriteScheduled = false;
+                AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
+                    @Override protected Void doInBackground(Void... params) {
+                        writeState();
+                        return null;
+                    }
+                };
+                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);
+            }
+        }
+    };
+
+    final SparseArray<HashMap<String, Ops>> mUidOps
+            = new SparseArray<HashMap<String, Ops>>();
+
+    public final static class Ops extends SparseArray<Op> {
+        public final String packageName;
+        public final int uid;
+
+        public Ops(String _packageName, int _uid) {
+            packageName = _packageName;
+            uid = _uid;
+        }
+    }
+
+    public final static class Op {
+        public final int uid;
+        public final String packageName;
+        public final int op;
+        public int mode;
+        public int duration;
+        public long time;
+        public long rejectTime;
+        public int nesting;
+
+        public Op(int _uid, String _packageName, int _op) {
+            uid = _uid;
+            packageName = _packageName;
+            op = _op;
+            mode = AppOpsManager.opToDefaultMode(op);
+        }
+    }
+
+    final SparseArray<ArrayList<Callback>> mOpModeWatchers
+            = new SparseArray<ArrayList<Callback>>();
+    final ArrayMap<String, ArrayList<Callback>> mPackageModeWatchers
+            = new ArrayMap<String, ArrayList<Callback>>();
+    final ArrayMap<IBinder, Callback> mModeWatchers
+            = new ArrayMap<IBinder, Callback>();
+
+    public final class Callback implements DeathRecipient {
+        final IAppOpsCallback mCallback;
+
+        public Callback(IAppOpsCallback callback) {
+            mCallback = callback;
+            try {
+                mCallback.asBinder().linkToDeath(this, 0);
+            } catch (RemoteException e) {
+            }
+        }
+
+        public void unlinkToDeath() {
+            mCallback.asBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public void binderDied() {
+            stopWatchingMode(mCallback);
+        }
+    }
+
+    final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<IBinder, ClientState>();
+
+    public final class ClientState extends Binder implements DeathRecipient {
+        final IBinder mAppToken;
+        final int mPid;
+        final ArrayList<Op> mStartedOps;
+
+        public ClientState(IBinder appToken) {
+            mAppToken = appToken;
+            mPid = Binder.getCallingPid();
+            if (appToken instanceof Binder) {
+                // For local clients, there is no reason to track them.
+                mStartedOps = null;
+            } else {
+                mStartedOps = new ArrayList<Op>();
+                try {
+                    mAppToken.linkToDeath(this, 0);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "ClientState{" +
+                    "mAppToken=" + mAppToken +
+                    ", " + (mStartedOps != null ? ("pid=" + mPid) : "local") +
+                    '}';
+        }
+
+        @Override
+        public void binderDied() {
+            synchronized (AppOpsService.this) {
+                for (int i=mStartedOps.size()-1; i>=0; i--) {
+                    finishOperationLocked(mStartedOps.get(i));
+                }
+                mClients.remove(mAppToken);
+            }
+        }
+    }
+
+    public AppOpsService(File storagePath, Handler handler) {
+        mFile = new AtomicFile(storagePath);
+        mHandler = handler;
+        readState();
+    }
+
+    public void publish(Context context) {
+        mContext = context;
+        ServiceManager.addService(Context.APP_OPS_SERVICE, asBinder());
+    }
+
+    public void systemReady() {
+        synchronized (this) {
+            boolean changed = false;
+            for (int i=0; i<mUidOps.size(); i++) {
+                HashMap<String, Ops> pkgs = mUidOps.valueAt(i);
+                Iterator<Ops> it = pkgs.values().iterator();
+                while (it.hasNext()) {
+                    Ops ops = it.next();
+                    int curUid;
+                    try {
+                        curUid = mContext.getPackageManager().getPackageUid(ops.packageName,
+                                UserHandle.getUserId(ops.uid));
+                    } catch (NameNotFoundException e) {
+                        curUid = -1;
+                    }
+                    if (curUid != ops.uid) {
+                        Slog.i(TAG, "Pruning old package " + ops.packageName
+                                + "/" + ops.uid + ": new uid=" + curUid);
+                        it.remove();
+                        changed = true;
+                    }
+                }
+                if (pkgs.size() <= 0) {
+                    mUidOps.removeAt(i);
+                }
+            }
+            if (changed) {
+                scheduleWriteLocked();
+            }
+        }
+    }
+
+    public void packageRemoved(int uid, String packageName) {
+        synchronized (this) {
+            HashMap<String, Ops> pkgs = mUidOps.get(uid);
+            if (pkgs != null) {
+                if (pkgs.remove(packageName) != null) {
+                    if (pkgs.size() <= 0) {
+                        mUidOps.remove(uid);
+                    }
+                    scheduleWriteLocked();
+                }
+            }
+        }
+    }
+
+    public void uidRemoved(int uid) {
+        synchronized (this) {
+            if (mUidOps.indexOfKey(uid) >= 0) {
+                mUidOps.remove(uid);
+                scheduleWriteLocked();
+            }
+        }
+    }
+
+    public void shutdown() {
+        Slog.w(TAG, "Writing app ops before shutdown...");
+        boolean doWrite = false;
+        synchronized (this) {
+            if (mWriteScheduled) {
+                mWriteScheduled = false;
+                doWrite = true;
+            }
+        }
+        if (doWrite) {
+            writeState();
+        }
+    }
+
+    private ArrayList<AppOpsManager.OpEntry> collectOps(Ops pkgOps, int[] ops) {
+        ArrayList<AppOpsManager.OpEntry> resOps = null;
+        if (ops == null) {
+            resOps = new ArrayList<AppOpsManager.OpEntry>();
+            for (int j=0; j<pkgOps.size(); j++) {
+                Op curOp = pkgOps.valueAt(j);
+                resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.mode, curOp.time,
+                        curOp.rejectTime, curOp.duration));
+            }
+        } else {
+            for (int j=0; j<ops.length; j++) {
+                Op curOp = pkgOps.get(ops[j]);
+                if (curOp != null) {
+                    if (resOps == null) {
+                        resOps = new ArrayList<AppOpsManager.OpEntry>();
+                    }
+                    resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.mode, curOp.time,
+                            curOp.rejectTime, curOp.duration));
+                }
+            }
+        }
+        return resOps;
+    }
+
+    @Override
+    public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
+        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+        ArrayList<AppOpsManager.PackageOps> res = null;
+        synchronized (this) {
+            for (int i=0; i<mUidOps.size(); i++) {
+                HashMap<String, Ops> packages = mUidOps.valueAt(i);
+                for (Ops pkgOps : packages.values()) {
+                    ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
+                    if (resOps != null) {
+                        if (res == null) {
+                            res = new ArrayList<AppOpsManager.PackageOps>();
+                        }
+                        AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
+                                pkgOps.packageName, pkgOps.uid, resOps);
+                        res.add(resPackage);
+                    }
+                }
+            }
+        }
+        return res;
+    }
+
+    @Override
+    public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
+            int[] ops) {
+        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+        synchronized (this) {
+            Ops pkgOps = getOpsLocked(uid, packageName, false);
+            if (pkgOps == null) {
+                return null;
+            }
+            ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
+            if (resOps == null) {
+                return null;
+            }
+            ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
+            AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
+                    pkgOps.packageName, pkgOps.uid, resOps);
+            res.add(resPackage);
+            return res;
+        }
+    }
+
+    private void pruneOp(Op op, int uid, String packageName) {
+        if (op.time == 0 && op.rejectTime == 0) {
+            Ops ops = getOpsLocked(uid, packageName, false);
+            if (ops != null) {
+                ops.remove(op.op);
+                if (ops.size() <= 0) {
+                    HashMap<String, Ops> pkgOps = mUidOps.get(uid);
+                    if (pkgOps != null) {
+                        pkgOps.remove(ops.packageName);
+                        if (pkgOps.size() <= 0) {
+                            mUidOps.remove(uid);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public void setMode(int code, int uid, String packageName, int mode) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
+        ArrayList<Callback> repCbs = null;
+        code = AppOpsManager.opToSwitch(code);
+        synchronized (this) {
+            Op op = getOpLocked(code, uid, packageName, true);
+            if (op != null) {
+                if (op.mode != mode) {
+                    op.mode = mode;
+                    ArrayList<Callback> cbs = mOpModeWatchers.get(code);
+                    if (cbs != null) {
+                        if (repCbs == null) {
+                            repCbs = new ArrayList<Callback>();
+                        }
+                        repCbs.addAll(cbs);
+                    }
+                    cbs = mPackageModeWatchers.get(packageName);
+                    if (cbs != null) {
+                        if (repCbs == null) {
+                            repCbs = new ArrayList<Callback>();
+                        }
+                        repCbs.addAll(cbs);
+                    }
+                    if (mode == AppOpsManager.opToDefaultMode(op.op)) {
+                        // If going into the default mode, prune this op
+                        // if there is nothing else interesting in it.
+                        pruneOp(op, uid, packageName);
+                    }
+                    scheduleWriteNowLocked();
+                }
+            }
+        }
+        if (repCbs != null) {
+            for (int i=0; i<repCbs.size(); i++) {
+                try {
+                    repCbs.get(i).mCallback.opChanged(code, packageName);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+    }
+
+    private static HashMap<Callback, ArrayList<Pair<String, Integer>>> addCallbacks(
+            HashMap<Callback, ArrayList<Pair<String, Integer>>> callbacks,
+            String packageName, int op, ArrayList<Callback> cbs) {
+        if (cbs == null) {
+            return callbacks;
+        }
+        if (callbacks == null) {
+            callbacks = new HashMap<Callback, ArrayList<Pair<String, Integer>>>();
+        }
+        for (int i=0; i<cbs.size(); i++) {
+            Callback cb = cbs.get(i);
+            ArrayList<Pair<String, Integer>> reports = callbacks.get(cb);
+            if (reports == null) {
+                reports = new ArrayList<Pair<String, Integer>>();
+                callbacks.put(cb, reports);
+            }
+            reports.add(new Pair<String, Integer>(packageName, op));
+        }
+        return callbacks;
+    }
+
+    @Override
+    public void resetAllModes() {
+        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+        HashMap<Callback, ArrayList<Pair<String, Integer>>> callbacks = null;
+        synchronized (this) {
+            boolean changed = false;
+            for (int i=mUidOps.size()-1; i>=0; i--) {
+                HashMap<String, Ops> packages = mUidOps.valueAt(i);
+                Iterator<Map.Entry<String, Ops>> it = packages.entrySet().iterator();
+                while (it.hasNext()) {
+                    Map.Entry<String, Ops> ent = it.next();
+                    String packageName = ent.getKey();
+                    Ops pkgOps = ent.getValue();
+                    for (int j=pkgOps.size()-1; j>=0; j--) {
+                        Op curOp = pkgOps.valueAt(j);
+                        if (AppOpsManager.opAllowsReset(curOp.op)
+                                && curOp.mode != AppOpsManager.opToDefaultMode(curOp.op)) {
+                            curOp.mode = AppOpsManager.opToDefaultMode(curOp.op);
+                            changed = true;
+                            callbacks = addCallbacks(callbacks, packageName, curOp.op,
+                                    mOpModeWatchers.get(curOp.op));
+                            callbacks = addCallbacks(callbacks, packageName, curOp.op,
+                                    mPackageModeWatchers.get(packageName));
+                            if (curOp.time == 0 && curOp.rejectTime == 0) {
+                                pkgOps.removeAt(j);
+                            }
+                        }
+                    }
+                    if (pkgOps.size() == 0) {
+                        it.remove();
+                    }
+                }
+                if (packages.size() == 0) {
+                    mUidOps.removeAt(i);
+                }
+            }
+            if (changed) {
+                scheduleWriteNowLocked();
+            }
+        }
+        if (callbacks != null) {
+            for (Map.Entry<Callback, ArrayList<Pair<String, Integer>>> ent : callbacks.entrySet()) {
+                Callback cb = ent.getKey();
+                ArrayList<Pair<String, Integer>> reports = ent.getValue();
+                for (int i=0; i<reports.size(); i++) {
+                    Pair<String, Integer> rep = reports.get(i);
+                    try {
+                        cb.mCallback.opChanged(rep.second, rep.first);
+                    } catch (RemoteException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public void startWatchingMode(int op, String packageName, IAppOpsCallback callback) {
+        synchronized (this) {
+            op = AppOpsManager.opToSwitch(op);
+            Callback cb = mModeWatchers.get(callback.asBinder());
+            if (cb == null) {
+                cb = new Callback(callback);
+                mModeWatchers.put(callback.asBinder(), cb);
+            }
+            if (op != AppOpsManager.OP_NONE) {
+                ArrayList<Callback> cbs = mOpModeWatchers.get(op);
+                if (cbs == null) {
+                    cbs = new ArrayList<Callback>();
+                    mOpModeWatchers.put(op, cbs);
+                }
+                cbs.add(cb);
+            }
+            if (packageName != null) {
+                ArrayList<Callback> cbs = mPackageModeWatchers.get(packageName);
+                if (cbs == null) {
+                    cbs = new ArrayList<Callback>();
+                    mPackageModeWatchers.put(packageName, cbs);
+                }
+                cbs.add(cb);
+            }
+        }
+    }
+
+    @Override
+    public void stopWatchingMode(IAppOpsCallback callback) {
+        synchronized (this) {
+            Callback cb = mModeWatchers.remove(callback.asBinder());
+            if (cb != null) {
+                cb.unlinkToDeath();
+                for (int i=mOpModeWatchers.size()-1; i>=0; i--) {
+                    ArrayList<Callback> cbs = mOpModeWatchers.valueAt(i);
+                    cbs.remove(cb);
+                    if (cbs.size() <= 0) {
+                        mOpModeWatchers.removeAt(i);
+                    }
+                }
+                for (int i=mPackageModeWatchers.size()-1; i>=0; i--) {
+                    ArrayList<Callback> cbs = mPackageModeWatchers.valueAt(i);
+                    cbs.remove(cb);
+                    if (cbs.size() <= 0) {
+                        mPackageModeWatchers.removeAt(i);
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public IBinder getToken(IBinder clientToken) {
+        synchronized (this) {
+            ClientState cs = mClients.get(clientToken);
+            if (cs == null) {
+                cs = new ClientState(clientToken);
+                mClients.put(clientToken, cs);
+            }
+            return cs;
+        }
+    }
+
+    @Override
+    public int checkOperation(int code, int uid, String packageName) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
+        synchronized (this) {
+            Op op = getOpLocked(AppOpsManager.opToSwitch(code), uid, packageName, false);
+            if (op == null) {
+                return AppOpsManager.opToDefaultMode(code);
+            }
+            return op.mode;
+        }
+    }
+
+    @Override
+    public int checkPackage(int uid, String packageName) {
+        synchronized (this) {
+            if (getOpsLocked(uid, packageName, true) != null) {
+                return AppOpsManager.MODE_ALLOWED;
+            } else {
+                return AppOpsManager.MODE_ERRORED;
+            }
+        }
+    }
+
+    @Override
+    public int noteOperation(int code, int uid, String packageName) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
+        synchronized (this) {
+            Ops ops = getOpsLocked(uid, packageName, true);
+            if (ops == null) {
+                if (DEBUG) Log.d(TAG, "noteOperation: no op for code " + code + " uid " + uid
+                        + " package " + packageName);
+                return AppOpsManager.MODE_ERRORED;
+            }
+            Op op = getOpLocked(ops, code, true);
+            if (op.duration == -1) {
+                Slog.w(TAG, "Noting op not finished: uid " + uid + " pkg " + packageName
+                        + " code " + code + " time=" + op.time + " duration=" + op.duration);
+            }
+            op.duration = 0;
+            final int switchCode = AppOpsManager.opToSwitch(code);
+            final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op;
+            if (switchOp.mode != AppOpsManager.MODE_ALLOWED) {
+                if (DEBUG) Log.d(TAG, "noteOperation: reject #" + op.mode + " for code "
+                        + switchCode + " (" + code + ") uid " + uid + " package " + packageName);
+                op.rejectTime = System.currentTimeMillis();
+                return switchOp.mode;
+            }
+            if (DEBUG) Log.d(TAG, "noteOperation: allowing code " + code + " uid " + uid
+                    + " package " + packageName);
+            op.time = System.currentTimeMillis();
+            op.rejectTime = 0;
+            return AppOpsManager.MODE_ALLOWED;
+        }
+    }
+
+    @Override
+    public int startOperation(IBinder token, int code, int uid, String packageName) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
+        ClientState client = (ClientState)token;
+        synchronized (this) {
+            Ops ops = getOpsLocked(uid, packageName, true);
+            if (ops == null) {
+                if (DEBUG) Log.d(TAG, "startOperation: no op for code " + code + " uid " + uid
+                        + " package " + packageName);
+                return AppOpsManager.MODE_ERRORED;
+            }
+            Op op = getOpLocked(ops, code, true);
+            final int switchCode = AppOpsManager.opToSwitch(code);
+            final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op;
+            if (switchOp.mode != AppOpsManager.MODE_ALLOWED) {
+                if (DEBUG) Log.d(TAG, "startOperation: reject #" + op.mode + " for code "
+                        + switchCode + " (" + code + ") uid " + uid + " package " + packageName);
+                op.rejectTime = System.currentTimeMillis();
+                return switchOp.mode;
+            }
+            if (DEBUG) Log.d(TAG, "startOperation: allowing code " + code + " uid " + uid
+                    + " package " + packageName);
+            if (op.nesting == 0) {
+                op.time = System.currentTimeMillis();
+                op.rejectTime = 0;
+                op.duration = -1;
+            }
+            op.nesting++;
+            if (client.mStartedOps != null) {
+                client.mStartedOps.add(op);
+            }
+            return AppOpsManager.MODE_ALLOWED;
+        }
+    }
+
+    @Override
+    public void finishOperation(IBinder token, int code, int uid, String packageName) {
+        verifyIncomingUid(uid);
+        verifyIncomingOp(code);
+        ClientState client = (ClientState)token;
+        synchronized (this) {
+            Op op = getOpLocked(code, uid, packageName, true);
+            if (op == null) {
+                return;
+            }
+            if (client.mStartedOps != null) {
+                if (!client.mStartedOps.remove(op)) {
+                    throw new IllegalStateException("Operation not started: uid" + op.uid
+                            + " pkg=" + op.packageName + " op=" + op.op);
+                }
+            }
+            finishOperationLocked(op);
+        }
+    }
+
+    void finishOperationLocked(Op op) {
+        if (op.nesting <= 1) {
+            if (op.nesting == 1) {
+                op.duration = (int)(System.currentTimeMillis() - op.time);
+                op.time += op.duration;
+            } else {
+                Slog.w(TAG, "Finishing op nesting under-run: uid " + op.uid + " pkg "
+                        + op.packageName + " code " + op.op + " time=" + op.time
+                        + " duration=" + op.duration + " nesting=" + op.nesting);
+            }
+            op.nesting = 0;
+        } else {
+            op.nesting--;
+        }
+    }
+
+    private void verifyIncomingUid(int uid) {
+        if (uid == Binder.getCallingUid()) {
+            return;
+        }
+        if (Binder.getCallingPid() == Process.myPid()) {
+            return;
+        }
+        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+    }
+
+    private void verifyIncomingOp(int op) {
+        if (op >= 0 && op < AppOpsManager._NUM_OP) {
+            return;
+        }
+        throw new IllegalArgumentException("Bad operation #" + op);
+    }
+
+    private Ops getOpsLocked(int uid, String packageName, boolean edit) {
+        HashMap<String, Ops> pkgOps = mUidOps.get(uid);
+        if (pkgOps == null) {
+            if (!edit) {
+                return null;
+            }
+            pkgOps = new HashMap<String, Ops>();
+            mUidOps.put(uid, pkgOps);
+        }
+        if (uid == 0) {
+            packageName = "root";
+        } else if (uid == Process.SHELL_UID) {
+            packageName = "com.android.shell";
+        }
+        Ops ops = pkgOps.get(packageName);
+        if (ops == null) {
+            if (!edit) {
+                return null;
+            }
+            // This is the first time we have seen this package name under this uid,
+            // so let's make sure it is valid.
+            if (uid != 0) {
+                final long ident = Binder.clearCallingIdentity();
+                try {
+                    int pkgUid = -1;
+                    try {
+                        pkgUid = mContext.getPackageManager().getPackageUid(packageName,
+                                UserHandle.getUserId(uid));
+                    } catch (NameNotFoundException e) {
+                        if ("media".equals(packageName)) {
+                            pkgUid = Process.MEDIA_UID;
+                        }
+                    }
+                    if (pkgUid != uid) {
+                        // Oops!  The package name is not valid for the uid they are calling
+                        // under.  Abort.
+                        Slog.w(TAG, "Bad call: specified package " + packageName
+                                + " under uid " + uid + " but it is really " + pkgUid);
+                        return null;
+                    }
+                } finally {
+                    Binder.restoreCallingIdentity(ident);
+                }
+            }
+            ops = new Ops(packageName, uid);
+            pkgOps.put(packageName, ops);
+        }
+        return ops;
+    }
+
+    private void scheduleWriteLocked() {
+        if (!mWriteScheduled) {
+            mWriteScheduled = true;
+            mHandler.postDelayed(mWriteRunner, WRITE_DELAY);
+        }
+    }
+
+    private void scheduleWriteNowLocked() {
+        if (!mWriteScheduled) {
+            mWriteScheduled = true;
+        }
+        mHandler.removeCallbacks(mWriteRunner);
+        mHandler.post(mWriteRunner);
+    }
+
+    private Op getOpLocked(int code, int uid, String packageName, boolean edit) {
+        Ops ops = getOpsLocked(uid, packageName, edit);
+        if (ops == null) {
+            return null;
+        }
+        return getOpLocked(ops, code, edit);
+    }
+
+    private Op getOpLocked(Ops ops, int code, boolean edit) {
+        Op op = ops.get(code);
+        if (op == null) {
+            if (!edit) {
+                return null;
+            }
+            op = new Op(ops.uid, ops.packageName, code);
+            ops.put(code, op);
+        }
+        if (edit) {
+            scheduleWriteLocked();
+        }
+        return op;
+    }
+
+    void readState() {
+        synchronized (mFile) {
+            synchronized (this) {
+                FileInputStream stream;
+                try {
+                    stream = mFile.openRead();
+                } catch (FileNotFoundException e) {
+                    Slog.i(TAG, "No existing app ops " + mFile.getBaseFile() + "; starting empty");
+                    return;
+                }
+                boolean success = false;
+                try {
+                    XmlPullParser parser = Xml.newPullParser();
+                    parser.setInput(stream, null);
+                    int type;
+                    while ((type = parser.next()) != XmlPullParser.START_TAG
+                            && type != XmlPullParser.END_DOCUMENT) {
+                        ;
+                    }
+
+                    if (type != XmlPullParser.START_TAG) {
+                        throw new IllegalStateException("no start tag found");
+                    }
+
+                    int outerDepth = parser.getDepth();
+                    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                            continue;
+                        }
+
+                        String tagName = parser.getName();
+                        if (tagName.equals("pkg")) {
+                            readPackage(parser);
+                        } else {
+                            Slog.w(TAG, "Unknown element under <app-ops>: "
+                                    + parser.getName());
+                            XmlUtils.skipCurrentTag(parser);
+                        }
+                    }
+                    success = true;
+                } catch (IllegalStateException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (NullPointerException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (NumberFormatException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (XmlPullParserException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (IOException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } catch (IndexOutOfBoundsException e) {
+                    Slog.w(TAG, "Failed parsing " + e);
+                } finally {
+                    if (!success) {
+                        mUidOps.clear();
+                    }
+                    try {
+                        stream.close();
+                    } catch (IOException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    void readPackage(XmlPullParser parser) throws NumberFormatException,
+            XmlPullParserException, IOException {
+        String pkgName = parser.getAttributeValue(null, "n");
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals("uid")) {
+                readUid(parser, pkgName);
+            } else {
+                Slog.w(TAG, "Unknown element under <pkg>: "
+                        + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+    }
+
+    void readUid(XmlPullParser parser, String pkgName) throws NumberFormatException,
+            XmlPullParserException, IOException {
+        int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals("op")) {
+                Op op = new Op(uid, pkgName, Integer.parseInt(parser.getAttributeValue(null, "n")));
+                String mode = parser.getAttributeValue(null, "m");
+                if (mode != null) {
+                    op.mode = Integer.parseInt(mode);
+                }
+                String time = parser.getAttributeValue(null, "t");
+                if (time != null) {
+                    op.time = Long.parseLong(time);
+                }
+                time = parser.getAttributeValue(null, "r");
+                if (time != null) {
+                    op.rejectTime = Long.parseLong(time);
+                }
+                String dur = parser.getAttributeValue(null, "d");
+                if (dur != null) {
+                    op.duration = Integer.parseInt(dur);
+                }
+                HashMap<String, Ops> pkgOps = mUidOps.get(uid);
+                if (pkgOps == null) {
+                    pkgOps = new HashMap<String, Ops>();
+                    mUidOps.put(uid, pkgOps);
+                }
+                Ops ops = pkgOps.get(pkgName);
+                if (ops == null) {
+                    ops = new Ops(pkgName, uid);
+                    pkgOps.put(pkgName, ops);
+                }
+                ops.put(op.op, op);
+            } else {
+                Slog.w(TAG, "Unknown element under <pkg>: "
+                        + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+    }
+
+    void writeState() {
+        synchronized (mFile) {
+            List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
+
+            FileOutputStream stream;
+            try {
+                stream = mFile.startWrite();
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed to write state: " + e);
+                return;
+            }
+
+            try {
+                XmlSerializer out = new FastXmlSerializer();
+                out.setOutput(stream, "utf-8");
+                out.startDocument(null, true);
+                out.startTag(null, "app-ops");
+
+                if (allOps != null) {
+                    String lastPkg = null;
+                    for (int i=0; i<allOps.size(); i++) {
+                        AppOpsManager.PackageOps pkg = allOps.get(i);
+                        if (!pkg.getPackageName().equals(lastPkg)) {
+                            if (lastPkg != null) {
+                                out.endTag(null, "pkg");
+                            }
+                            lastPkg = pkg.getPackageName();
+                            out.startTag(null, "pkg");
+                            out.attribute(null, "n", lastPkg);
+                        }
+                        out.startTag(null, "uid");
+                        out.attribute(null, "n", Integer.toString(pkg.getUid()));
+                        List<AppOpsManager.OpEntry> ops = pkg.getOps();
+                        for (int j=0; j<ops.size(); j++) {
+                            AppOpsManager.OpEntry op = ops.get(j);
+                            out.startTag(null, "op");
+                            out.attribute(null, "n", Integer.toString(op.getOp()));
+                            if (op.getMode() != AppOpsManager.opToDefaultMode(op.getOp())) {
+                                out.attribute(null, "m", Integer.toString(op.getMode()));
+                            }
+                            long time = op.getTime();
+                            if (time != 0) {
+                                out.attribute(null, "t", Long.toString(time));
+                            }
+                            time = op.getRejectTime();
+                            if (time != 0) {
+                                out.attribute(null, "r", Long.toString(time));
+                            }
+                            int dur = op.getDuration();
+                            if (dur != 0) {
+                                out.attribute(null, "d", Integer.toString(dur));
+                            }
+                            out.endTag(null, "op");
+                        }
+                        out.endTag(null, "uid");
+                    }
+                    if (lastPkg != null) {
+                        out.endTag(null, "pkg");
+                    }
+                }
+
+                out.endTag(null, "app-ops");
+                out.endDocument();
+                mFile.finishWrite(stream);
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed to write state, restoring backup.", e);
+                mFile.failWrite(stream);
+            }
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump ApOps service from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        synchronized (this) {
+            pw.println("Current AppOps Service state:");
+            final long now = System.currentTimeMillis();
+            boolean needSep = false;
+            if (mOpModeWatchers.size() > 0) {
+                needSep = true;
+                pw.println("  Op mode watchers:");
+                for (int i=0; i<mOpModeWatchers.size(); i++) {
+                    pw.print("    Op "); pw.print(AppOpsManager.opToName(mOpModeWatchers.keyAt(i)));
+                    pw.println(":");
+                    ArrayList<Callback> callbacks = mOpModeWatchers.valueAt(i);
+                    for (int j=0; j<callbacks.size(); j++) {
+                        pw.print("      #"); pw.print(j); pw.print(": ");
+                        pw.println(callbacks.get(j));
+                    }
+                }
+            }
+            if (mPackageModeWatchers.size() > 0) {
+                needSep = true;
+                pw.println("  Package mode watchers:");
+                for (int i=0; i<mPackageModeWatchers.size(); i++) {
+                    pw.print("    Pkg "); pw.print(mPackageModeWatchers.keyAt(i));
+                    pw.println(":");
+                    ArrayList<Callback> callbacks = mPackageModeWatchers.valueAt(i);
+                    for (int j=0; j<callbacks.size(); j++) {
+                        pw.print("      #"); pw.print(j); pw.print(": ");
+                        pw.println(callbacks.get(j));
+                    }
+                }
+            }
+            if (mModeWatchers.size() > 0) {
+                needSep = true;
+                pw.println("  All mode watchers:");
+                for (int i=0; i<mModeWatchers.size(); i++) {
+                    pw.print("    "); pw.print(mModeWatchers.keyAt(i));
+                    pw.print(" -> "); pw.println(mModeWatchers.valueAt(i));
+                }
+            }
+            if (mClients.size() > 0) {
+                needSep = true;
+                pw.println("  Clients:");
+                for (int i=0; i<mClients.size(); i++) {
+                    pw.print("    "); pw.print(mClients.keyAt(i)); pw.println(":");
+                    ClientState cs = mClients.valueAt(i);
+                    pw.print("      "); pw.println(cs);
+                    if (cs.mStartedOps != null && cs.mStartedOps.size() > 0) {
+                        pw.println("      Started ops:");
+                        for (int j=0; j<cs.mStartedOps.size(); j++) {
+                            Op op = cs.mStartedOps.get(j);
+                            pw.print("        "); pw.print("uid="); pw.print(op.uid);
+                            pw.print(" pkg="); pw.print(op.packageName);
+                            pw.print(" op="); pw.println(AppOpsManager.opToName(op.op));
+                        }
+                    }
+                }
+            }
+            if (needSep) {
+                pw.println();
+            }
+            for (int i=0; i<mUidOps.size(); i++) {
+                pw.print("  Uid "); UserHandle.formatUid(pw, mUidOps.keyAt(i)); pw.println(":");
+                HashMap<String, Ops> pkgOps = mUidOps.valueAt(i);
+                for (Ops ops : pkgOps.values()) {
+                    pw.print("    Package "); pw.print(ops.packageName); pw.println(":");
+                    for (int j=0; j<ops.size(); j++) {
+                        Op op = ops.valueAt(j);
+                        pw.print("      "); pw.print(AppOpsManager.opToName(op.op));
+                        pw.print(": mode="); pw.print(op.mode);
+                        if (op.time != 0) {
+                            pw.print("; time="); TimeUtils.formatDuration(now-op.time, pw);
+                            pw.print(" ago");
+                        }
+                        if (op.rejectTime != 0) {
+                            pw.print("; rejectTime="); TimeUtils.formatDuration(now-op.rejectTime, pw);
+                            pw.print(" ago");
+                        }
+                        if (op.duration == -1) {
+                            pw.println(" (running)");
+                        } else {
+                            pw.print("; duration=");
+                                    TimeUtils.formatDuration(op.duration, pw);
+                                    pw.println();
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java
new file mode 100644
index 0000000..3fb006b
--- /dev/null
+++ b/services/core/java/com/android/server/AssetAtlasService.java
@@ -0,0 +1,735 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.graphics.Atlas;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.drawable.Drawable;
+import android.os.Environment;
+import android.os.RemoteException;
+import android.os.SystemProperties;
+import android.util.Log;
+import android.util.LongSparseArray;
+import android.view.GraphicBuffer;
+import android.view.IAssetAtlas;
+
+import java.io.BufferedReader;
+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.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * This service is responsible for packing preloaded bitmaps into a single
+ * atlas texture. The resulting texture can be shared across processes to
+ * reduce overall memory usage.
+ *
+ * @hide
+ */
+public class AssetAtlasService extends IAssetAtlas.Stub {
+    /**
+     * Name of the <code>AssetAtlasService</code>.
+     */
+    public static final String ASSET_ATLAS_SERVICE = "assetatlas";
+
+    private static final String LOG_TAG = "Atlas";
+
+    // Turns debug logs on/off. Debug logs are kept to a minimum and should
+    // remain on to diagnose issues
+    private static final boolean DEBUG_ATLAS = true;
+
+    // When set to true the content of the atlas will be saved to disk
+    // in /data/system/atlas.png. The shared GraphicBuffer may be empty
+    private static final boolean DEBUG_ATLAS_TEXTURE = false;
+
+    // Minimum size in pixels to consider for the resulting texture
+    private static final int MIN_SIZE = 768;
+    // Maximum size in pixels to consider for the resulting texture
+    private static final int MAX_SIZE = 2048;
+    // Increment in number of pixels between size variants when looking
+    // for the best texture dimensions
+    private static final int STEP = 64;
+
+    // This percentage of the total number of pixels represents the minimum
+    // number of pixels we want to be able to pack in the atlas
+    private static final float PACKING_THRESHOLD = 0.8f;
+
+    // Defines the number of int fields used to represent a single entry
+    // in the atlas map. This number defines the size of the array returned
+    // by the getMap(). See the mAtlasMap field for more information
+    private static final int ATLAS_MAP_ENTRY_FIELD_COUNT = 4;
+
+    // Specifies how our GraphicBuffer will be used. To get proper swizzling
+    // the buffer will be written to using OpenGL (from JNI) so we can leave
+    // the software flag set to "never"
+    private static final int GRAPHIC_BUFFER_USAGE = GraphicBuffer.USAGE_SW_READ_NEVER |
+            GraphicBuffer.USAGE_SW_WRITE_NEVER | GraphicBuffer.USAGE_HW_TEXTURE;
+
+    // This boolean is set to true if an atlas was successfully
+    // computed and rendered
+    private final AtomicBoolean mAtlasReady = new AtomicBoolean(false);
+
+    private final Context mContext;
+
+    // Version name of the current build, used to identify changes to assets list
+    private final String mVersionName;
+
+    // Holds the atlas' data. This buffer can be mapped to
+    // OpenGL using an EGLImage
+    private GraphicBuffer mBuffer;
+
+    // Describes how bitmaps are placed in the atlas. Each bitmap is
+    // represented by several entries in the array:
+    // int0: SkBitmap*, the native bitmap object
+    // int1: x position
+    // int2: y position
+    // int3: rotated, 1 if the bitmap must be rotated, 0 otherwise
+    // NOTE: This will need to be handled differently to support 64 bit pointers
+    private int[] mAtlasMap;
+
+    /**
+     * Creates a new service. Upon creating, the service will gather the list of
+     * assets to consider for packing into the atlas and spawn a new thread to
+     * start the packing work.
+     *
+     * @param context The context giving access to preloaded resources
+     */
+    public AssetAtlasService(Context context) {
+        mContext = context;
+        mVersionName = queryVersionName(context);
+
+        ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(300);
+        int totalPixelCount = 0;
+
+        // We only care about drawables that hold bitmaps
+        final Resources resources = context.getResources();
+        final LongSparseArray<Drawable.ConstantState> drawables = resources.getPreloadedDrawables();
+
+        final int count = drawables.size();
+        for (int i = 0; i < count; i++) {
+            final Bitmap bitmap = drawables.valueAt(i).getBitmap();
+            if (bitmap != null && bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
+                bitmaps.add(bitmap);
+                totalPixelCount += bitmap.getWidth() * bitmap.getHeight();
+            }
+        }
+
+        // Our algorithms perform better when the bitmaps are first sorted
+        // The comparator will sort the bitmap by width first, then by height
+        Collections.sort(bitmaps, new Comparator<Bitmap>() {
+            @Override
+            public int compare(Bitmap b1, Bitmap b2) {
+                if (b1.getWidth() == b2.getWidth()) {
+                    return b2.getHeight() - b1.getHeight();
+                }
+                return b2.getWidth() - b1.getWidth();
+            }
+        });
+
+        // Kick off the packing work on a worker thread
+        new Thread(new Renderer(bitmaps, totalPixelCount)).start();
+    }
+
+    /**
+     * Queries the version name stored in framework's AndroidManifest.
+     * The version name can be used to identify possible changes to
+     * framework resources.
+     *
+     * @see #getBuildIdentifier(String)
+     */
+    private static String queryVersionName(Context context) {
+        try {
+            String packageName = context.getPackageName();
+            PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
+            return info.versionName;
+        } catch (PackageManager.NameNotFoundException e) {
+            Log.w(LOG_TAG, "Could not get package info", e);
+        }
+        return null;
+    }
+
+    /**
+     * Callback invoked by the server thread to indicate we can now run
+     * 3rd party code.
+     */
+    public void systemRunning() {
+    }
+
+    /**
+     * The renderer does all the work:
+     */
+    private class Renderer implements Runnable {
+        private final ArrayList<Bitmap> mBitmaps;
+        private final int mPixelCount;
+
+        private int mNativeBitmap;
+
+        // Used for debugging only
+        private Bitmap mAtlasBitmap;
+
+        Renderer(ArrayList<Bitmap> bitmaps, int pixelCount) {
+            mBitmaps = bitmaps;
+            mPixelCount = pixelCount;
+        }
+
+        /**
+         * 1. On first boot or after every update, brute-force through all the
+         *    possible atlas configurations and look for the best one (maximimize
+         *    number of packed assets and minimize texture size)
+         *    a. If a best configuration was computed, write it out to disk for
+         *       future use
+         * 2. Read best configuration from disk
+         * 3. Compute the packing using the best configuration
+         * 4. Allocate a GraphicBuffer
+         * 5. Render assets in the buffer
+         */
+        @Override
+        public void run() {
+            Configuration config = chooseConfiguration(mBitmaps, mPixelCount, mVersionName);
+            if (DEBUG_ATLAS) Log.d(LOG_TAG, "Loaded configuration: " + config);
+
+            if (config != null) {
+                mBuffer = GraphicBuffer.create(config.width, config.height,
+                        PixelFormat.RGBA_8888, GRAPHIC_BUFFER_USAGE);
+
+                if (mBuffer != null) {
+                    Atlas atlas = new Atlas(config.type, config.width, config.height, config.flags);
+                    if (renderAtlas(mBuffer, atlas, config.count)) {
+                        mAtlasReady.set(true);
+                    }
+                }
+            }
+        }
+
+        /**
+         * Renders a list of bitmaps into the atlas. The position of each bitmap
+         * was decided by the packing algorithm and will be honored by this
+         * method. If need be this method will also rotate bitmaps.
+         *
+         * @param buffer The buffer to render the atlas entries into
+         * @param atlas The atlas to pack the bitmaps into
+         * @param packCount The number of bitmaps that will be packed in the atlas
+         *
+         * @return true if the atlas was rendered, false otherwise
+         */
+        @SuppressWarnings("MismatchedReadAndWriteOfArray")
+        private boolean renderAtlas(GraphicBuffer buffer, Atlas atlas, int packCount) {
+            // Use a Source blend mode to improve performance, the target bitmap
+            // will be zero'd out so there's no need to waste time applying blending
+            final Paint paint = new Paint();
+            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+
+            // We always render the atlas into a bitmap. This bitmap is then
+            // uploaded into the GraphicBuffer using OpenGL to swizzle the content
+            final Canvas canvas = acquireCanvas(buffer.getWidth(), buffer.getHeight());
+            if (canvas == null) return false;
+
+            final Atlas.Entry entry = new Atlas.Entry();
+
+            mAtlasMap = new int[packCount * ATLAS_MAP_ENTRY_FIELD_COUNT];
+            int[] atlasMap = mAtlasMap;
+            int mapIndex = 0;
+
+            boolean result = false;
+            try {
+                final long startRender = System.nanoTime();
+                final int count = mBitmaps.size();
+
+                for (int i = 0; i < count; i++) {
+                    final Bitmap bitmap = mBitmaps.get(i);
+                    if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) {
+                        // We have more bitmaps to pack than the current configuration
+                        // says, we were most likely not able to detect a change in the
+                        // list of preloaded drawables, abort and delete the configuration
+                        if (mapIndex >= mAtlasMap.length) {
+                            deleteDataFile();
+                            break;
+                        }
+
+                        canvas.save();
+                        canvas.translate(entry.x, entry.y);
+                        if (entry.rotated) {
+                            canvas.translate(bitmap.getHeight(), 0.0f);
+                            canvas.rotate(90.0f);
+                        }
+                        canvas.drawBitmap(bitmap, 0.0f, 0.0f, null);
+                        canvas.restore();
+                        // TODO: Change mAtlasMap to long[] to support 64-bit systems
+                        atlasMap[mapIndex++] = (int) bitmap.mNativeBitmap;
+                        atlasMap[mapIndex++] = entry.x;
+                        atlasMap[mapIndex++] = entry.y;
+                        atlasMap[mapIndex++] = entry.rotated ? 1 : 0;
+                    }
+                }
+
+                final long endRender = System.nanoTime();
+                if (mNativeBitmap != 0) {
+                    result = nUploadAtlas(buffer, mNativeBitmap);
+                }
+
+                final long endUpload = System.nanoTime();
+                if (DEBUG_ATLAS) {
+                    float renderDuration = (endRender - startRender) / 1000.0f / 1000.0f;
+                    float uploadDuration = (endUpload - endRender) / 1000.0f / 1000.0f;
+                    Log.d(LOG_TAG, String.format("Rendered atlas in %.2fms (%.2f+%.2fms)",
+                            renderDuration + uploadDuration, renderDuration, uploadDuration));
+                }
+
+            } finally {
+                releaseCanvas(canvas);
+            }
+
+            return result;
+        }
+
+        /**
+         * Returns a Canvas for the specified buffer. If {@link #DEBUG_ATLAS_TEXTURE}
+         * is turned on, the returned Canvas will render into a local bitmap that
+         * will then be saved out to disk for debugging purposes.
+         * @param width
+         * @param height
+         */
+        private Canvas acquireCanvas(int width, int height) {
+            if (DEBUG_ATLAS_TEXTURE) {
+                mAtlasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+                return new Canvas(mAtlasBitmap);
+            } else {
+                Canvas canvas = new Canvas();
+                mNativeBitmap = nAcquireAtlasCanvas(canvas, width, height);
+                return canvas;
+            }
+        }
+
+        /**
+         * Releases the canvas used to render into the buffer. Calling this method
+         * will release any resource previously acquired. If {@link #DEBUG_ATLAS_TEXTURE}
+         * is turend on, calling this method will write the content of the atlas
+         * to disk in /data/system/atlas.png for debugging.
+         */
+        private void releaseCanvas(Canvas canvas) {
+            if (DEBUG_ATLAS_TEXTURE) {
+                canvas.setBitmap(null);
+
+                File systemDirectory = new File(Environment.getDataDirectory(), "system");
+                File dataFile = new File(systemDirectory, "atlas.png");
+
+                try {
+                    FileOutputStream out = new FileOutputStream(dataFile);
+                    mAtlasBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
+                    out.close();
+                } catch (FileNotFoundException e) {
+                    // Ignore
+                } catch (IOException e) {
+                    // Ignore
+                }
+
+                mAtlasBitmap.recycle();
+                mAtlasBitmap = null;
+            } else {
+                nReleaseAtlasCanvas(canvas, mNativeBitmap);
+            }
+        }
+    }
+
+    private static native int nAcquireAtlasCanvas(Canvas canvas, int width, int height);
+    private static native void nReleaseAtlasCanvas(Canvas canvas, int bitmap);
+    private static native boolean nUploadAtlas(GraphicBuffer buffer, int bitmap);
+
+    @Override
+    public boolean isCompatible(int ppid) {
+        return ppid == android.os.Process.myPpid();
+    }
+
+    @Override
+    public GraphicBuffer getBuffer() throws RemoteException {
+        return mAtlasReady.get() ? mBuffer : null;
+    }
+
+    @Override
+    public int[] getMap() throws RemoteException {
+        return mAtlasReady.get() ? mAtlasMap : null;
+    }
+
+    /**
+     * Finds the best atlas configuration to pack the list of supplied bitmaps.
+     * This method takes advantage of multi-core systems by spawning a number
+     * of threads equal to the number of available cores.
+     */
+    private static Configuration computeBestConfiguration(
+            ArrayList<Bitmap> bitmaps, int pixelCount) {
+        if (DEBUG_ATLAS) Log.d(LOG_TAG, "Computing best atlas configuration...");
+
+        long begin = System.nanoTime();
+        List<WorkerResult> results = Collections.synchronizedList(new ArrayList<WorkerResult>());
+
+        // Don't bother with an extra thread if there's only one processor
+        int cpuCount = Runtime.getRuntime().availableProcessors();
+        if (cpuCount == 1) {
+            new ComputeWorker(MIN_SIZE, MAX_SIZE, STEP, bitmaps, pixelCount, results, null).run();
+        } else {
+            int start = MIN_SIZE;
+            int end = MAX_SIZE - (cpuCount - 1) * STEP;
+            int step = STEP * cpuCount;
+
+            final CountDownLatch signal = new CountDownLatch(cpuCount);
+
+            for (int i = 0; i < cpuCount; i++, start += STEP, end += STEP) {
+                ComputeWorker worker = new ComputeWorker(start, end, step,
+                        bitmaps, pixelCount, results, signal);
+                new Thread(worker, "Atlas Worker #" + (i + 1)).start();
+            }
+
+            try {
+                signal.await(10, TimeUnit.SECONDS);
+            } catch (InterruptedException e) {
+                Log.w(LOG_TAG, "Could not complete configuration computation");
+                return null;
+            }
+        }
+
+        // Maximize the number of packed bitmaps, minimize the texture size
+        Collections.sort(results, new Comparator<WorkerResult>() {
+            @Override
+            public int compare(WorkerResult r1, WorkerResult r2) {
+                int delta = r2.count - r1.count;
+                if (delta != 0) return delta;
+                return r1.width * r1.height - r2.width * r2.height;
+            }
+        });
+
+        if (DEBUG_ATLAS) {
+            float delay = (System.nanoTime() - begin) / 1000.0f / 1000.0f / 1000.0f;
+            Log.d(LOG_TAG, String.format("Found best atlas configuration in %.2fs", delay));
+        }
+
+        WorkerResult result = results.get(0);
+        return new Configuration(result.type, result.width, result.height, result.count);
+    }
+
+    /**
+     * Returns the path to the file containing the best computed
+     * atlas configuration.
+     */
+    private static File getDataFile() {
+        File systemDirectory = new File(Environment.getDataDirectory(), "system");
+        return new File(systemDirectory, "framework_atlas.config");
+    }
+
+    private static void deleteDataFile() {
+        Log.w(LOG_TAG, "Current configuration inconsistent with assets list");
+        if (!getDataFile().delete()) {
+            Log.w(LOG_TAG, "Could not delete the current configuration");
+        }
+    }
+
+    private File getFrameworkResourcesFile() {
+        return new File(mContext.getApplicationInfo().sourceDir);
+    }
+
+    /**
+     * Returns the best known atlas configuration. This method will either
+     * read the configuration from disk or start a brute-force search
+     * and save the result out to disk.
+     */
+    private Configuration chooseConfiguration(ArrayList<Bitmap> bitmaps, int pixelCount,
+            String versionName) {
+        Configuration config = null;
+
+        final File dataFile = getDataFile();
+        if (dataFile.exists()) {
+            config = readConfiguration(dataFile, versionName);
+        }
+
+        if (config == null) {
+            config = computeBestConfiguration(bitmaps, pixelCount);
+            if (config != null) writeConfiguration(config, dataFile, versionName);
+        }
+
+        return config;
+    }
+
+    /**
+     * Writes the specified atlas configuration to the specified file.
+     */
+    private void writeConfiguration(Configuration config, File file, String versionName) {
+        BufferedWriter writer = null;
+        try {
+            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
+            writer.write(getBuildIdentifier(versionName));
+            writer.newLine();
+            writer.write(config.type.toString());
+            writer.newLine();
+            writer.write(String.valueOf(config.width));
+            writer.newLine();
+            writer.write(String.valueOf(config.height));
+            writer.newLine();
+            writer.write(String.valueOf(config.count));
+            writer.newLine();
+            writer.write(String.valueOf(config.flags));
+            writer.newLine();
+        } catch (FileNotFoundException e) {
+            Log.w(LOG_TAG, "Could not write " + file, e);
+        } catch (IOException e) {
+            Log.w(LOG_TAG, "Could not write " + file, e);
+        } finally {
+            if (writer != null) {
+                try {
+                    writer.close();
+                } catch (IOException e) {
+                    // Ignore
+                }
+            }
+        }
+    }
+
+    /**
+     * Reads an atlas configuration from the specified file. This method
+     * returns null if an error occurs or if the configuration is invalid.
+     */
+    private Configuration readConfiguration(File file, String versionName) {
+        BufferedReader reader = null;
+        Configuration config = null;
+        try {
+            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+
+            if (checkBuildIdentifier(reader, versionName)) {
+                Atlas.Type type = Atlas.Type.valueOf(reader.readLine());
+                int width = readInt(reader, MIN_SIZE, MAX_SIZE);
+                int height = readInt(reader, MIN_SIZE, MAX_SIZE);
+                int count = readInt(reader, 0, Integer.MAX_VALUE);
+                int flags = readInt(reader, Integer.MIN_VALUE, Integer.MAX_VALUE);
+
+                config = new Configuration(type, width, height, count, flags);
+            }
+        } catch (IllegalArgumentException e) {
+            Log.w(LOG_TAG, "Invalid parameter value in " + file, e);
+        } catch (FileNotFoundException e) {
+            Log.w(LOG_TAG, "Could not read " + file, e);
+        } catch (IOException e) {
+            Log.w(LOG_TAG, "Could not read " + file, e);
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    // Ignore
+                }
+            }
+        }
+        return config;
+    }
+
+    private static int readInt(BufferedReader reader, int min, int max) throws IOException {
+        return Math.max(min, Math.min(max, Integer.parseInt(reader.readLine())));
+    }
+
+    /**
+     * Compares the next line in the specified buffered reader to the current
+     * build identifier. Returns whether the two values are equal.
+     *
+     * @see #getBuildIdentifier(String)
+     */
+    private boolean checkBuildIdentifier(BufferedReader reader, String versionName)
+            throws IOException {
+        String deviceBuildId = getBuildIdentifier(versionName);
+        String buildId = reader.readLine();
+        return deviceBuildId.equals(buildId);
+    }
+
+    /**
+     * Returns an identifier for the current build that can be used to detect
+     * likely changes to framework resources. The build identifier is made of
+     * several distinct values:
+     *
+     * build fingerprint/framework version name/file size of framework resources apk
+     *
+     * Only the build fingerprint should be necessary on user builds but
+     * the other values are useful to detect changes on eng builds during
+     * development.
+     *
+     * This identifier does not attempt to be exact: a new identifier does not
+     * necessarily mean the preloaded drawables have changed. It is important
+     * however that whenever the list of preloaded drawables changes, this
+     * identifier changes as well.
+     *
+     * @see #checkBuildIdentifier(java.io.BufferedReader, String)
+     */
+    private String getBuildIdentifier(String versionName) {
+        return SystemProperties.get("ro.build.fingerprint", "") + '/' + versionName + '/' +
+                String.valueOf(getFrameworkResourcesFile().length());
+    }
+
+    /**
+     * Atlas configuration. Specifies the algorithm, dimensions and flags to use.
+     */
+    private static class Configuration {
+        final Atlas.Type type;
+        final int width;
+        final int height;
+        final int count;
+        final int flags;
+
+        Configuration(Atlas.Type type, int width, int height, int count) {
+            this(type, width, height, count, Atlas.FLAG_DEFAULTS);
+        }
+
+        Configuration(Atlas.Type type, int width, int height, int count, int flags) {
+            this.type = type;
+            this.width = width;
+            this.height = height;
+            this.count = count;
+            this.flags = flags;
+        }
+
+        @Override
+        public String toString() {
+            return type.toString() + " (" + width + "x" + height + ") flags=0x" +
+                    Integer.toHexString(flags) + " count=" + count;
+        }
+    }
+
+    /**
+     * Used during the brute-force search to gather information about each
+     * variant of the packing algorithm.
+     */
+    private static class WorkerResult {
+        Atlas.Type type;
+        int width;
+        int height;
+        int count;
+
+        WorkerResult(Atlas.Type type, int width, int height, int count) {
+            this.type = type;
+            this.width = width;
+            this.height = height;
+            this.count = count;
+        }
+
+        @Override
+        public String toString() {
+            return String.format("%s %dx%d", type.toString(), width, height);
+        }
+    }
+
+    /**
+     * A compute worker will try a finite number of variations of the packing
+     * algorithms and save the results in a supplied list.
+     */
+    private static class ComputeWorker implements Runnable {
+        private final int mStart;
+        private final int mEnd;
+        private final int mStep;
+        private final List<Bitmap> mBitmaps;
+        private final List<WorkerResult> mResults;
+        private final CountDownLatch mSignal;
+        private final int mThreshold;
+
+        /**
+         * Creates a new compute worker to brute-force through a range of
+         * packing algorithms variants.
+         *
+         * @param start The minimum texture width to try
+         * @param end The maximum texture width to try
+         * @param step The number of pixels to increment the texture width by at each step
+         * @param bitmaps The list of bitmaps to pack in the atlas
+         * @param pixelCount The total number of pixels occupied by the list of bitmaps
+         * @param results The list of results in which to save the brute-force search results
+         * @param signal Latch to decrement when this worker is done, may be null
+         */
+        ComputeWorker(int start, int end, int step, List<Bitmap> bitmaps, int pixelCount,
+                List<WorkerResult> results, CountDownLatch signal) {
+            mStart = start;
+            mEnd = end;
+            mStep = step;
+            mBitmaps = bitmaps;
+            mResults = results;
+            mSignal = signal;
+
+            // Minimum number of pixels we want to be able to pack
+            int threshold = (int) (pixelCount * PACKING_THRESHOLD);
+            // Make sure we can find at least one configuration
+            while (threshold > MAX_SIZE * MAX_SIZE) {
+                threshold >>= 1;
+            }
+            mThreshold = threshold;
+        }
+
+        @Override
+        public void run() {
+            if (DEBUG_ATLAS) Log.d(LOG_TAG, "Running " + Thread.currentThread().getName());
+
+            Atlas.Entry entry = new Atlas.Entry();
+            for (Atlas.Type type : Atlas.Type.values()) {
+                for (int width = mStart; width < mEnd; width += mStep) {
+                    for (int height = MIN_SIZE; height < MAX_SIZE; height += STEP) {
+                        // If the atlas is not big enough, skip it
+                        if (width * height <= mThreshold) continue;
+
+                        final int count = packBitmaps(type, width, height, entry);
+                        if (count > 0) {
+                            mResults.add(new WorkerResult(type, width, height, count));
+                            // If we were able to pack everything let's stop here
+                            // Increasing the height further won't make things better
+                            if (count == mBitmaps.size()) {
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (mSignal != null) {
+                mSignal.countDown();
+            }
+        }
+
+        private int packBitmaps(Atlas.Type type, int width, int height, Atlas.Entry entry) {
+            int total = 0;
+            Atlas atlas = new Atlas(type, width, height);
+
+            final int count = mBitmaps.size();
+            for (int i = 0; i < count; i++) {
+                final Bitmap bitmap = mBitmaps.get(i);
+                if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) {
+                    total++;
+                }
+            }
+
+            return total;
+        }
+    }
+}
diff --git a/services/java/com/android/server/AttributeCache.java b/services/core/java/com/android/server/AttributeCache.java
similarity index 100%
rename from services/java/com/android/server/AttributeCache.java
rename to services/core/java/com/android/server/AttributeCache.java
diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java
new file mode 100644
index 0000000..cc9055d
--- /dev/null
+++ b/services/core/java/com/android/server/BatteryService.java
@@ -0,0 +1,753 @@
+/*
+ * Copyright (C) 2006 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;
+
+import android.os.BatteryStats;
+import com.android.internal.app.IBatteryStats;
+import com.android.server.am.BatteryStatsService;
+import com.android.server.lights.Light;
+import com.android.server.lights.LightsManager;
+
+import android.app.ActivityManagerNative;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.BatteryManager;
+import android.os.BatteryProperties;
+import android.os.Binder;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.IBatteryPropertiesListener;
+import android.os.IBatteryPropertiesRegistrar;
+import android.os.IBinder;
+import android.os.DropBoxManager;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.UEventObserver;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.EventLog;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+
+/**
+ * <p>BatteryService monitors the charging status, and charge level of the device
+ * battery.  When these values change this service broadcasts the new values
+ * to all {@link android.content.BroadcastReceiver IntentReceivers} that are
+ * watching the {@link android.content.Intent#ACTION_BATTERY_CHANGED
+ * BATTERY_CHANGED} action.</p>
+ * <p>The new values are stored in the Intent data and can be retrieved by
+ * calling {@link android.content.Intent#getExtra Intent.getExtra} with the
+ * following keys:</p>
+ * <p>&quot;scale&quot; - int, the maximum value for the charge level</p>
+ * <p>&quot;level&quot; - int, charge level, from 0 through &quot;scale&quot; inclusive</p>
+ * <p>&quot;status&quot; - String, the current charging status.<br />
+ * <p>&quot;health&quot; - String, the current battery health.<br />
+ * <p>&quot;present&quot; - boolean, true if the battery is present<br />
+ * <p>&quot;icon-small&quot; - int, suggested small icon to use for this state</p>
+ * <p>&quot;plugged&quot; - int, 0 if the device is not plugged in; 1 if plugged
+ * into an AC power adapter; 2 if plugged in via USB.</p>
+ * <p>&quot;voltage&quot; - int, current battery voltage in millivolts</p>
+ * <p>&quot;temperature&quot; - int, current battery temperature in tenths of
+ * a degree Centigrade</p>
+ * <p>&quot;technology&quot; - String, the type of battery installed, e.g. "Li-ion"</p>
+ *
+ * <p>
+ * The battery service may be called by the power manager while holding its locks so
+ * we take care to post all outcalls into the activity manager to a handler.
+ *
+ * FIXME: Ideally the power manager would perform all of its calls into the battery
+ * service asynchronously itself.
+ * </p>
+ */
+public final class BatteryService extends Binder {
+    private static final String TAG = BatteryService.class.getSimpleName();
+
+    private static final boolean DEBUG = false;
+
+    private static final int BATTERY_SCALE = 100;    // battery capacity is a percentage
+
+    // Used locally for determining when to make a last ditch effort to log
+    // discharge stats before the device dies.
+    private int mCriticalBatteryLevel;
+
+    private static final int DUMP_MAX_LENGTH = 24 * 1024;
+    private static final String[] DUMPSYS_ARGS = new String[] { "--checkin", "--unplugged" };
+
+    private static final String DUMPSYS_DATA_PATH = "/data/system/";
+
+    // This should probably be exposed in the API, though it's not critical
+    private static final int BATTERY_PLUGGED_NONE = 0;
+
+    private final Context mContext;
+    private final IBatteryStats mBatteryStats;
+    private final Handler mHandler;
+
+    private final Object mLock = new Object();
+
+    private BatteryProperties mBatteryProps;
+    private boolean mBatteryLevelCritical;
+    private int mLastBatteryStatus;
+    private int mLastBatteryHealth;
+    private boolean mLastBatteryPresent;
+    private int mLastBatteryLevel;
+    private int mLastBatteryVoltage;
+    private int mLastBatteryTemperature;
+    private boolean mLastBatteryLevelCritical;
+
+    private int mInvalidCharger;
+    private int mLastInvalidCharger;
+
+    private int mLowBatteryWarningLevel;
+    private int mLowBatteryCloseWarningLevel;
+    private int mShutdownBatteryTemperature;
+
+    private int mPlugType;
+    private int mLastPlugType = -1; // Extra state so we can detect first run
+
+    private long mDischargeStartTime;
+    private int mDischargeStartLevel;
+
+    private boolean mUpdatesStopped;
+
+    private Led mLed;
+
+    private boolean mSentLowBatteryBroadcast = false;
+
+    public BatteryService(Context context, LightsManager lightsManager) {
+        mContext = context;
+        mHandler = new Handler(true /*async*/);
+        mLed = new Led(context, lightsManager);
+        mBatteryStats = BatteryStatsService.getService();
+
+        mCriticalBatteryLevel = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_criticalBatteryWarningLevel);
+        mLowBatteryWarningLevel = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_lowBatteryWarningLevel);
+        mLowBatteryCloseWarningLevel = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_lowBatteryCloseWarningLevel);
+        mShutdownBatteryTemperature = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_shutdownBatteryTemperature);
+
+        // watch for invalid charger messages if the invalid_charger switch exists
+        if (new File("/sys/devices/virtual/switch/invalid_charger/state").exists()) {
+            mInvalidChargerObserver.startObserving(
+                    "DEVPATH=/devices/virtual/switch/invalid_charger");
+        }
+
+        IBinder b = ServiceManager.getService("batterypropreg");
+        final IBatteryPropertiesRegistrar batteryPropertiesRegistrar =
+                IBatteryPropertiesRegistrar.Stub.asInterface(b);
+        try {
+            batteryPropertiesRegistrar.registerListener(new BatteryListener());
+        } catch (RemoteException e) {
+            // Should never happen.
+        }
+    }
+
+    void systemReady() {
+        // check our power situation now that it is safe to display the shutdown dialog.
+        synchronized (mLock) {
+            shutdownIfNoPowerLocked();
+            shutdownIfOverTempLocked();
+        }
+    }
+
+    /**
+     * Returns true if the device is plugged into any of the specified plug types.
+     */
+    public boolean isPowered(int plugTypeSet) {
+        synchronized (mLock) {
+            return isPoweredLocked(plugTypeSet);
+        }
+    }
+
+    private boolean isPoweredLocked(int plugTypeSet) {
+        // assume we are powered if battery state is unknown so
+        // the "stay on while plugged in" option will work.
+        if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
+            return true;
+        }
+        if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_AC) != 0 && mBatteryProps.chargerAcOnline) {
+            return true;
+        }
+        if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_USB) != 0 && mBatteryProps.chargerUsbOnline) {
+            return true;
+        }
+        if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0 && mBatteryProps.chargerWirelessOnline) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Returns the current plug type.
+     */
+    public int getPlugType() {
+        synchronized (mLock) {
+            return mPlugType;
+        }
+    }
+
+    /**
+     * Returns battery level as a percentage.
+     */
+    public int getBatteryLevel() {
+        synchronized (mLock) {
+            return mBatteryProps.batteryLevel;
+        }
+    }
+
+    /**
+     * Returns true if battery level is below the first warning threshold.
+     */
+    public boolean isBatteryLow() {
+        synchronized (mLock) {
+            return mBatteryProps.batteryPresent && mBatteryProps.batteryLevel <= mLowBatteryWarningLevel;
+        }
+    }
+
+    /**
+     * Returns a non-zero value if an  unsupported charger is attached.
+     */
+    public int getInvalidCharger() {
+        synchronized (mLock) {
+            return mInvalidCharger;
+        }
+    }
+
+    private void shutdownIfNoPowerLocked() {
+        // shut down gracefully if our battery is critically low and we are not powered.
+        // wait until the system has booted before attempting to display the shutdown dialog.
+        if (mBatteryProps.batteryLevel == 0 && !isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    if (ActivityManagerNative.isSystemReady()) {
+                        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
+                        intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
+                    }
+                }
+            });
+        }
+    }
+
+    private void shutdownIfOverTempLocked() {
+        // shut down gracefully if temperature is too high (> 68.0C by default)
+        // wait until the system has booted before attempting to display the
+        // shutdown dialog.
+        if (mBatteryProps.batteryTemperature > mShutdownBatteryTemperature) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    if (ActivityManagerNative.isSystemReady()) {
+                        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
+                        intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
+                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
+                    }
+                }
+            });
+        }
+    }
+
+    private void update(BatteryProperties props) {
+        synchronized (mLock) {
+            if (!mUpdatesStopped) {
+                mBatteryProps = props;
+                // Process the new values.
+                processValuesLocked();
+            }
+        }
+    }
+
+    private void processValuesLocked() {
+        boolean logOutlier = false;
+        long dischargeDuration = 0;
+
+        mBatteryLevelCritical = (mBatteryProps.batteryLevel <= mCriticalBatteryLevel);
+        if (mBatteryProps.chargerAcOnline) {
+            mPlugType = BatteryManager.BATTERY_PLUGGED_AC;
+        } else if (mBatteryProps.chargerUsbOnline) {
+            mPlugType = BatteryManager.BATTERY_PLUGGED_USB;
+        } else if (mBatteryProps.chargerWirelessOnline) {
+            mPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS;
+        } else {
+            mPlugType = BATTERY_PLUGGED_NONE;
+        }
+
+        if (DEBUG) {
+            Slog.d(TAG, "Processing new values: "
+                    + "chargerAcOnline=" + mBatteryProps.chargerAcOnline
+                    + ", chargerUsbOnline=" + mBatteryProps.chargerUsbOnline
+                    + ", chargerWirelessOnline=" + mBatteryProps.chargerWirelessOnline
+                    + ", batteryStatus=" + mBatteryProps.batteryStatus
+                    + ", batteryHealth=" + mBatteryProps.batteryHealth
+                    + ", batteryPresent=" + mBatteryProps.batteryPresent
+                    + ", batteryLevel=" + mBatteryProps.batteryLevel
+                    + ", batteryTechnology=" + mBatteryProps.batteryTechnology
+                    + ", batteryVoltage=" + mBatteryProps.batteryVoltage
+                    + ", batteryCurrentNow=" + mBatteryProps.batteryCurrentNow
+                    + ", batteryChargeCounter=" + mBatteryProps.batteryChargeCounter
+                    + ", batteryTemperature=" + mBatteryProps.batteryTemperature
+                    + ", mBatteryLevelCritical=" + mBatteryLevelCritical
+                    + ", mPlugType=" + mPlugType);
+        }
+
+        // Let the battery stats keep track of the current level.
+        try {
+            mBatteryStats.setBatteryState(mBatteryProps.batteryStatus, mBatteryProps.batteryHealth,
+                    mPlugType, mBatteryProps.batteryLevel, mBatteryProps.batteryTemperature,
+                    mBatteryProps.batteryVoltage);
+        } catch (RemoteException e) {
+            // Should never happen.
+        }
+
+        shutdownIfNoPowerLocked();
+        shutdownIfOverTempLocked();
+
+        if (mBatteryProps.batteryStatus != mLastBatteryStatus ||
+                mBatteryProps.batteryHealth != mLastBatteryHealth ||
+                mBatteryProps.batteryPresent != mLastBatteryPresent ||
+                mBatteryProps.batteryLevel != mLastBatteryLevel ||
+                mPlugType != mLastPlugType ||
+                mBatteryProps.batteryVoltage != mLastBatteryVoltage ||
+                mBatteryProps.batteryTemperature != mLastBatteryTemperature ||
+                mInvalidCharger != mLastInvalidCharger) {
+
+            if (mPlugType != mLastPlugType) {
+                if (mLastPlugType == BATTERY_PLUGGED_NONE) {
+                    // discharging -> charging
+
+                    // There's no value in this data unless we've discharged at least once and the
+                    // battery level has changed; so don't log until it does.
+                    if (mDischargeStartTime != 0 && mDischargeStartLevel != mBatteryProps.batteryLevel) {
+                        dischargeDuration = SystemClock.elapsedRealtime() - mDischargeStartTime;
+                        logOutlier = true;
+                        EventLog.writeEvent(EventLogTags.BATTERY_DISCHARGE, dischargeDuration,
+                                mDischargeStartLevel, mBatteryProps.batteryLevel);
+                        // make sure we see a discharge event before logging again
+                        mDischargeStartTime = 0;
+                    }
+                } else if (mPlugType == BATTERY_PLUGGED_NONE) {
+                    // charging -> discharging or we just powered up
+                    mDischargeStartTime = SystemClock.elapsedRealtime();
+                    mDischargeStartLevel = mBatteryProps.batteryLevel;
+                }
+            }
+            if (mBatteryProps.batteryStatus != mLastBatteryStatus ||
+                    mBatteryProps.batteryHealth != mLastBatteryHealth ||
+                    mBatteryProps.batteryPresent != mLastBatteryPresent ||
+                    mPlugType != mLastPlugType) {
+                EventLog.writeEvent(EventLogTags.BATTERY_STATUS,
+                        mBatteryProps.batteryStatus, mBatteryProps.batteryHealth, mBatteryProps.batteryPresent ? 1 : 0,
+                        mPlugType, mBatteryProps.batteryTechnology);
+            }
+            if (mBatteryProps.batteryLevel != mLastBatteryLevel) {
+                // Don't do this just from voltage or temperature changes, that is
+                // too noisy.
+                EventLog.writeEvent(EventLogTags.BATTERY_LEVEL,
+                        mBatteryProps.batteryLevel, mBatteryProps.batteryVoltage, mBatteryProps.batteryTemperature);
+            }
+            if (mBatteryLevelCritical && !mLastBatteryLevelCritical &&
+                    mPlugType == BATTERY_PLUGGED_NONE) {
+                // We want to make sure we log discharge cycle outliers
+                // if the battery is about to die.
+                dischargeDuration = SystemClock.elapsedRealtime() - mDischargeStartTime;
+                logOutlier = true;
+            }
+
+            final boolean plugged = mPlugType != BATTERY_PLUGGED_NONE;
+            final boolean oldPlugged = mLastPlugType != BATTERY_PLUGGED_NONE;
+
+            /* The ACTION_BATTERY_LOW broadcast is sent in these situations:
+             * - is just un-plugged (previously was plugged) and battery level is
+             *   less than or equal to WARNING, or
+             * - is not plugged and battery level falls to WARNING boundary
+             *   (becomes <= mLowBatteryWarningLevel).
+             */
+            final boolean sendBatteryLow = !plugged
+                    && mBatteryProps.batteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
+                    && mBatteryProps.batteryLevel <= mLowBatteryWarningLevel
+                    && (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel);
+
+            sendIntentLocked();
+
+            // Separate broadcast is sent for power connected / not connected
+            // since the standard intent will not wake any applications and some
+            // applications may want to have smart behavior based on this.
+            if (mPlugType != 0 && mLastPlugType == 0) {
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        Intent statusIntent = new Intent(Intent.ACTION_POWER_CONNECTED);
+                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
+                    }
+                });
+            }
+            else if (mPlugType == 0 && mLastPlugType != 0) {
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        Intent statusIntent = new Intent(Intent.ACTION_POWER_DISCONNECTED);
+                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
+                    }
+                });
+            }
+
+            if (sendBatteryLow) {
+                mSentLowBatteryBroadcast = true;
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        Intent statusIntent = new Intent(Intent.ACTION_BATTERY_LOW);
+                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
+                    }
+                });
+            } else if (mSentLowBatteryBroadcast && mLastBatteryLevel >= mLowBatteryCloseWarningLevel) {
+                mSentLowBatteryBroadcast = false;
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        Intent statusIntent = new Intent(Intent.ACTION_BATTERY_OKAY);
+                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
+                    }
+                });
+            }
+
+            // Update the battery LED
+            mLed.updateLightsLocked();
+
+            // This needs to be done after sendIntent() so that we get the lastest battery stats.
+            if (logOutlier && dischargeDuration != 0) {
+                logOutlierLocked(dischargeDuration);
+            }
+
+            mLastBatteryStatus = mBatteryProps.batteryStatus;
+            mLastBatteryHealth = mBatteryProps.batteryHealth;
+            mLastBatteryPresent = mBatteryProps.batteryPresent;
+            mLastBatteryLevel = mBatteryProps.batteryLevel;
+            mLastPlugType = mPlugType;
+            mLastBatteryVoltage = mBatteryProps.batteryVoltage;
+            mLastBatteryTemperature = mBatteryProps.batteryTemperature;
+            mLastBatteryLevelCritical = mBatteryLevelCritical;
+            mLastInvalidCharger = mInvalidCharger;
+        }
+    }
+
+    private void sendIntentLocked() {
+        //  Pack up the values and broadcast them to everyone
+        final Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
+        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                | Intent.FLAG_RECEIVER_REPLACE_PENDING);
+
+        int icon = getIconLocked(mBatteryProps.batteryLevel);
+
+        intent.putExtra(BatteryManager.EXTRA_STATUS, mBatteryProps.batteryStatus);
+        intent.putExtra(BatteryManager.EXTRA_HEALTH, mBatteryProps.batteryHealth);
+        intent.putExtra(BatteryManager.EXTRA_PRESENT, mBatteryProps.batteryPresent);
+        intent.putExtra(BatteryManager.EXTRA_LEVEL, mBatteryProps.batteryLevel);
+        intent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_SCALE);
+        intent.putExtra(BatteryManager.EXTRA_ICON_SMALL, icon);
+        intent.putExtra(BatteryManager.EXTRA_PLUGGED, mPlugType);
+        intent.putExtra(BatteryManager.EXTRA_VOLTAGE, mBatteryProps.batteryVoltage);
+        intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mBatteryProps.batteryTemperature);
+        intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryProps.batteryTechnology);
+        intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
+
+        if (DEBUG) {
+            Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED.  level:" + mBatteryProps.batteryLevel +
+                    ", scale:" + BATTERY_SCALE + ", status:" + mBatteryProps.batteryStatus +
+                    ", health:" + mBatteryProps.batteryHealth +  ", present:" + mBatteryProps.batteryPresent +
+                    ", voltage: " + mBatteryProps.batteryVoltage +
+                    ", temperature: " + mBatteryProps.batteryTemperature +
+                    ", technology: " + mBatteryProps.batteryTechnology +
+                    ", AC powered:" + mBatteryProps.chargerAcOnline + ", USB powered:" + mBatteryProps.chargerUsbOnline +
+                    ", Wireless powered:" + mBatteryProps.chargerWirelessOnline +
+                    ", icon:" + icon  + ", invalid charger:" + mInvalidCharger);
+        }
+
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                ActivityManagerNative.broadcastStickyIntent(intent, null, UserHandle.USER_ALL);
+            }
+        });
+    }
+
+    private void logBatteryStatsLocked() {
+        IBinder batteryInfoService = ServiceManager.getService(BatteryStats.SERVICE_NAME);
+        if (batteryInfoService == null) return;
+
+        DropBoxManager db = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
+        if (db == null || !db.isTagEnabled("BATTERY_DISCHARGE_INFO")) return;
+
+        File dumpFile = null;
+        FileOutputStream dumpStream = null;
+        try {
+            // dump the service to a file
+            dumpFile = new File(DUMPSYS_DATA_PATH + BatteryStats.SERVICE_NAME + ".dump");
+            dumpStream = new FileOutputStream(dumpFile);
+            batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
+            FileUtils.sync(dumpStream);
+
+            // add dump file to drop box
+            db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
+        } catch (RemoteException e) {
+            Slog.e(TAG, "failed to dump battery service", e);
+        } catch (IOException e) {
+            Slog.e(TAG, "failed to write dumpsys file", e);
+        } finally {
+            // make sure we clean up
+            if (dumpStream != null) {
+                try {
+                    dumpStream.close();
+                } catch (IOException e) {
+                    Slog.e(TAG, "failed to close dumpsys output stream");
+                }
+            }
+            if (dumpFile != null && !dumpFile.delete()) {
+                Slog.e(TAG, "failed to delete temporary dumpsys file: "
+                        + dumpFile.getAbsolutePath());
+            }
+        }
+    }
+
+    private void logOutlierLocked(long duration) {
+        ContentResolver cr = mContext.getContentResolver();
+        String dischargeThresholdString = Settings.Global.getString(cr,
+                Settings.Global.BATTERY_DISCHARGE_THRESHOLD);
+        String durationThresholdString = Settings.Global.getString(cr,
+                Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD);
+
+        if (dischargeThresholdString != null && durationThresholdString != null) {
+            try {
+                long durationThreshold = Long.parseLong(durationThresholdString);
+                int dischargeThreshold = Integer.parseInt(dischargeThresholdString);
+                if (duration <= durationThreshold &&
+                        mDischargeStartLevel - mBatteryProps.batteryLevel >= dischargeThreshold) {
+                    // If the discharge cycle is bad enough we want to know about it.
+                    logBatteryStatsLocked();
+                }
+                if (DEBUG) Slog.v(TAG, "duration threshold: " + durationThreshold +
+                        " discharge threshold: " + dischargeThreshold);
+                if (DEBUG) Slog.v(TAG, "duration: " + duration + " discharge: " +
+                        (mDischargeStartLevel - mBatteryProps.batteryLevel));
+            } catch (NumberFormatException e) {
+                Slog.e(TAG, "Invalid DischargeThresholds GService string: " +
+                        durationThresholdString + " or " + dischargeThresholdString);
+                return;
+            }
+        }
+    }
+
+    private int getIconLocked(int level) {
+        if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_CHARGING) {
+            return com.android.internal.R.drawable.stat_sys_battery_charge;
+        } else if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_DISCHARGING) {
+            return com.android.internal.R.drawable.stat_sys_battery;
+        } else if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING
+                || mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_FULL) {
+            if (isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)
+                    && mBatteryProps.batteryLevel >= 100) {
+                return com.android.internal.R.drawable.stat_sys_battery_charge;
+            } else {
+                return com.android.internal.R.drawable.stat_sys_battery;
+            }
+        } else {
+            return com.android.internal.R.drawable.stat_sys_battery_unknown;
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+
+            pw.println("Permission Denial: can't dump Battery service from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        synchronized (mLock) {
+            if (args == null || args.length == 0 || "-a".equals(args[0])) {
+                pw.println("Current Battery Service state:");
+                if (mUpdatesStopped) {
+                    pw.println("  (UPDATES STOPPED -- use 'reset' to restart)");
+                }
+                pw.println("  AC powered: " + mBatteryProps.chargerAcOnline);
+                pw.println("  USB powered: " + mBatteryProps.chargerUsbOnline);
+                pw.println("  Wireless powered: " + mBatteryProps.chargerWirelessOnline);
+                pw.println("  status: " + mBatteryProps.batteryStatus);
+                pw.println("  health: " + mBatteryProps.batteryHealth);
+                pw.println("  present: " + mBatteryProps.batteryPresent);
+                pw.println("  level: " + mBatteryProps.batteryLevel);
+                pw.println("  scale: " + BATTERY_SCALE);
+                pw.println("  voltage: " + mBatteryProps.batteryVoltage);
+
+                if (mBatteryProps.batteryCurrentNow != Integer.MIN_VALUE) {
+                    pw.println("  current now: " + mBatteryProps.batteryCurrentNow);
+                }
+
+                if (mBatteryProps.batteryChargeCounter != Integer.MIN_VALUE) {
+                    pw.println("  charge counter: " + mBatteryProps.batteryChargeCounter);
+                }
+
+                pw.println("  temperature: " + mBatteryProps.batteryTemperature);
+                pw.println("  technology: " + mBatteryProps.batteryTechnology);
+            } else if (args.length == 3 && "set".equals(args[0])) {
+                String key = args[1];
+                String value = args[2];
+                try {
+                    boolean update = true;
+                    if ("ac".equals(key)) {
+                        mBatteryProps.chargerAcOnline = Integer.parseInt(value) != 0;
+                    } else if ("usb".equals(key)) {
+                        mBatteryProps.chargerUsbOnline = Integer.parseInt(value) != 0;
+                    } else if ("wireless".equals(key)) {
+                        mBatteryProps.chargerWirelessOnline = Integer.parseInt(value) != 0;
+                    } else if ("status".equals(key)) {
+                        mBatteryProps.batteryStatus = Integer.parseInt(value);
+                    } else if ("level".equals(key)) {
+                        mBatteryProps.batteryLevel = Integer.parseInt(value);
+                    } else if ("invalid".equals(key)) {
+                        mInvalidCharger = Integer.parseInt(value);
+                    } else {
+                        pw.println("Unknown set option: " + key);
+                        update = false;
+                    }
+                    if (update) {
+                        long ident = Binder.clearCallingIdentity();
+                        try {
+                            mUpdatesStopped = true;
+                            processValuesLocked();
+                        } finally {
+                            Binder.restoreCallingIdentity(ident);
+                        }
+                    }
+                } catch (NumberFormatException ex) {
+                    pw.println("Bad value: " + value);
+                }
+            } else if (args.length == 1 && "reset".equals(args[0])) {
+                long ident = Binder.clearCallingIdentity();
+                try {
+                    mUpdatesStopped = false;
+                } finally {
+                    Binder.restoreCallingIdentity(ident);
+                }
+            } else {
+                pw.println("Dump current battery state, or:");
+                pw.println("  set ac|usb|wireless|status|level|invalid <value>");
+                pw.println("  reset");
+            }
+        }
+    }
+
+    private final UEventObserver mInvalidChargerObserver = new UEventObserver() {
+        @Override
+        public void onUEvent(UEventObserver.UEvent event) {
+            final int invalidCharger = "1".equals(event.get("SWITCH_STATE")) ? 1 : 0;
+            synchronized (mLock) {
+                if (mInvalidCharger != invalidCharger) {
+                    mInvalidCharger = invalidCharger;
+                }
+            }
+        }
+    };
+
+    private final class Led {
+        private final Light mBatteryLight;
+
+        private final int mBatteryLowARGB;
+        private final int mBatteryMediumARGB;
+        private final int mBatteryFullARGB;
+        private final int mBatteryLedOn;
+        private final int mBatteryLedOff;
+
+        public Led(Context context, LightsManager lights) {
+            mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);
+
+            mBatteryLowARGB = context.getResources().getInteger(
+                    com.android.internal.R.integer.config_notificationsBatteryLowARGB);
+            mBatteryMediumARGB = context.getResources().getInteger(
+                    com.android.internal.R.integer.config_notificationsBatteryMediumARGB);
+            mBatteryFullARGB = context.getResources().getInteger(
+                    com.android.internal.R.integer.config_notificationsBatteryFullARGB);
+            mBatteryLedOn = context.getResources().getInteger(
+                    com.android.internal.R.integer.config_notificationsBatteryLedOn);
+            mBatteryLedOff = context.getResources().getInteger(
+                    com.android.internal.R.integer.config_notificationsBatteryLedOff);
+        }
+
+        /**
+         * Synchronize on BatteryService.
+         */
+        public void updateLightsLocked() {
+            final int level = mBatteryProps.batteryLevel;
+            final int status = mBatteryProps.batteryStatus;
+            if (level < mLowBatteryWarningLevel) {
+                if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
+                    // Solid red when battery is charging
+                    mBatteryLight.setColor(mBatteryLowARGB);
+                } else {
+                    // Flash red when battery is low and not charging
+                    mBatteryLight.setFlashing(mBatteryLowARGB, Light.LIGHT_FLASH_TIMED,
+                            mBatteryLedOn, mBatteryLedOff);
+                }
+            } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
+                    || status == BatteryManager.BATTERY_STATUS_FULL) {
+                if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) {
+                    // Solid green when full or charging and nearly full
+                    mBatteryLight.setColor(mBatteryFullARGB);
+                } else {
+                    // Solid orange when charging and halfway full
+                    mBatteryLight.setColor(mBatteryMediumARGB);
+                }
+            } else {
+                // No lights if not charging and not low
+                mBatteryLight.turnOff();
+            }
+        }
+    }
+
+    private final class BatteryListener extends IBatteryPropertiesListener.Stub {
+        @Override
+        public void batteryPropertiesChanged(BatteryProperties props) {
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                BatteryService.this.update(props);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+       }
+    }
+}
diff --git a/services/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
similarity index 100%
rename from services/java/com/android/server/BluetoothManagerService.java
rename to services/core/java/com/android/server/BluetoothManagerService.java
diff --git a/services/core/java/com/android/server/BootReceiver.java b/services/core/java/com/android/server/BootReceiver.java
new file mode 100644
index 0000000..bce85ce
--- /dev/null
+++ b/services/core/java/com/android/server/BootReceiver.java
@@ -0,0 +1,241 @@
+/*
+ * 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.
+ */
+
+package com.android.server;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.IPackageManager;
+import android.os.Build;
+import android.os.DropBoxManager;
+import android.os.FileObserver;
+import android.os.FileUtils;
+import android.os.RecoverySystem;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+import android.provider.Downloads;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Performs a number of miscellaneous, non-system-critical actions
+ * after the system has finished booting.
+ */
+public class BootReceiver extends BroadcastReceiver {
+    private static final String TAG = "BootReceiver";
+
+    // Maximum size of a logged event (files get truncated if they're longer).
+    // Give userdebug builds a larger max to capture extra debug, esp. for last_kmsg.
+    private static final int LOG_SIZE =
+        SystemProperties.getInt("ro.debuggable", 0) == 1 ? 98304 : 65536;
+
+    private static final File TOMBSTONE_DIR = new File("/data/tombstones");
+
+    // The pre-froyo package and class of the system updater, which
+    // ran in the system process.  We need to remove its packages here
+    // in order to clean up after a pre-froyo-to-froyo update.
+    private static final String OLD_UPDATER_PACKAGE =
+        "com.google.android.systemupdater";
+    private static final String OLD_UPDATER_CLASS =
+        "com.google.android.systemupdater.SystemUpdateReceiver";
+
+    // Keep a reference to the observer so the finalizer doesn't disable it.
+    private static FileObserver sTombstoneObserver = null;
+
+    @Override
+    public void onReceive(final Context context, Intent intent) {
+        // Log boot events in the background to avoid blocking the main thread with I/O
+        new Thread() {
+            @Override
+            public void run() {
+                try {
+                    logBootEvents(context);
+                } catch (Exception e) {
+                    Slog.e(TAG, "Can't log boot events", e);
+                }
+                try {
+                    boolean onlyCore = false;
+                    try {
+                        onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
+                                "package")).isOnlyCoreApps();
+                    } catch (RemoteException e) {
+                    }
+                    if (!onlyCore) {
+                        removeOldUpdatePackages(context);
+                    }
+                } catch (Exception e) {
+                    Slog.e(TAG, "Can't remove old update packages", e);
+                }
+
+            }
+        }.start();
+    }
+
+    private void removeOldUpdatePackages(Context context) {
+        Downloads.removeAllDownloadsByPackage(context, OLD_UPDATER_PACKAGE, OLD_UPDATER_CLASS);
+    }
+
+    private void logBootEvents(Context ctx) throws IOException {
+        final DropBoxManager db = (DropBoxManager) ctx.getSystemService(Context.DROPBOX_SERVICE);
+        final SharedPreferences prefs = ctx.getSharedPreferences("log_files", Context.MODE_PRIVATE);
+        final String headers = new StringBuilder(512)
+            .append("Build: ").append(Build.FINGERPRINT).append("\n")
+            .append("Hardware: ").append(Build.BOARD).append("\n")
+            .append("Revision: ")
+            .append(SystemProperties.get("ro.revision", "")).append("\n")
+            .append("Bootloader: ").append(Build.BOOTLOADER).append("\n")
+            .append("Radio: ").append(Build.RADIO).append("\n")
+            .append("Kernel: ")
+            .append(FileUtils.readTextFile(new File("/proc/version"), 1024, "...\n"))
+            .append("\n").toString();
+
+        String recovery = RecoverySystem.handleAftermath();
+        if (recovery != null && db != null) {
+            db.addText("SYSTEM_RECOVERY_LOG", headers + recovery);
+        }
+
+        if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
+            String now = Long.toString(System.currentTimeMillis());
+            SystemProperties.set("ro.runtime.firstboot", now);
+            if (db != null) db.addText("SYSTEM_BOOT", headers);
+
+            // Negative sizes mean to take the *tail* of the file (see FileUtils.readTextFile())
+            addFileToDropBox(db, prefs, headers, "/proc/last_kmsg",
+                    -LOG_SIZE, "SYSTEM_LAST_KMSG");
+            addFileToDropBox(db, prefs, headers, "/sys/fs/pstore/console-ramoops",
+                    -LOG_SIZE, "SYSTEM_LAST_KMSG");
+            addFileToDropBox(db, prefs, headers, "/cache/recovery/log",
+                    -LOG_SIZE, "SYSTEM_RECOVERY_LOG");
+            addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_console",
+                    -LOG_SIZE, "APANIC_CONSOLE");
+            addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_threads",
+                    -LOG_SIZE, "APANIC_THREADS");
+            addAuditErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_AUDIT");
+            addFsckErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_FSCK");
+        } else {
+            if (db != null) db.addText("SYSTEM_RESTART", headers);
+        }
+
+        // Scan existing tombstones (in case any new ones appeared)
+        File[] tombstoneFiles = TOMBSTONE_DIR.listFiles();
+        for (int i = 0; tombstoneFiles != null && i < tombstoneFiles.length; i++) {
+            addFileToDropBox(db, prefs, headers, tombstoneFiles[i].getPath(),
+                    LOG_SIZE, "SYSTEM_TOMBSTONE");
+        }
+
+        // Start watching for new tombstone files; will record them as they occur.
+        // This gets registered with the singleton file observer thread.
+        sTombstoneObserver = new FileObserver(TOMBSTONE_DIR.getPath(), FileObserver.CLOSE_WRITE) {
+            @Override
+            public void onEvent(int event, String path) {
+                try {
+                    String filename = new File(TOMBSTONE_DIR, path).getPath();
+                    addFileToDropBox(db, prefs, headers, filename, LOG_SIZE, "SYSTEM_TOMBSTONE");
+                } catch (IOException e) {
+                    Slog.e(TAG, "Can't log tombstone", e);
+                }
+            }
+        };
+
+        sTombstoneObserver.startWatching();
+    }
+
+    private static void addFileToDropBox(
+            DropBoxManager db, SharedPreferences prefs,
+            String headers, String filename, int maxSize, String tag) throws IOException {
+        if (db == null || !db.isTagEnabled(tag)) return;  // Logging disabled
+
+        File file = new File(filename);
+        long fileTime = file.lastModified();
+        if (fileTime <= 0) return;  // File does not exist
+
+        if (prefs != null) {
+            long lastTime = prefs.getLong(filename, 0);
+            if (lastTime == fileTime) return;  // Already logged this particular file
+            // TODO: move all these SharedPreferences Editor commits
+            // outside this function to the end of logBootEvents
+            prefs.edit().putLong(filename, fileTime).apply();
+        }
+
+        Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")");
+        db.addText(tag, headers + FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n"));
+    }
+
+    private static void addAuditErrorsToDropBox(DropBoxManager db,  SharedPreferences prefs,
+            String headers, int maxSize, String tag) throws IOException {
+        if (db == null || !db.isTagEnabled(tag)) return;  // Logging disabled
+        Slog.i(TAG, "Copying audit failures to DropBox");
+
+        File file = new File("/proc/last_kmsg");
+        long fileTime = file.lastModified();
+        if (fileTime <= 0) {
+            file = new File("/sys/fs/pstore/console-ramoops");
+            fileTime = file.lastModified();
+        }
+
+        if (fileTime <= 0) return;  // File does not exist
+
+        if (prefs != null) {
+            long lastTime = prefs.getLong(tag, 0);
+            if (lastTime == fileTime) return;  // Already logged this particular file
+            // TODO: move all these SharedPreferences Editor commits
+            // outside this function to the end of logBootEvents
+            prefs.edit().putLong(tag, fileTime).apply();
+        }
+
+        String log = FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n");
+        StringBuilder sb = new StringBuilder();
+        for (String line : log.split("\n")) {
+            if (line.contains("audit")) {
+                sb.append(line + "\n");
+            }
+        }
+        Slog.i(TAG, "Copied " + sb.toString().length() + " worth of audits to DropBox");
+        db.addText(tag, headers + sb.toString());
+    }
+
+    private static void addFsckErrorsToDropBox(DropBoxManager db,  SharedPreferences prefs,
+            String headers, int maxSize, String tag) throws IOException {
+        boolean upload_needed = false;
+        if (db == null || !db.isTagEnabled(tag)) return;  // Logging disabled
+        Slog.i(TAG, "Checking for fsck errors");
+
+        File file = new File("/dev/fscklogs/log");
+        long fileTime = file.lastModified();
+        if (fileTime <= 0) return;  // File does not exist
+
+        String log = FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n");
+        StringBuilder sb = new StringBuilder();
+        for (String line : log.split("\n")) {
+            if (line.contains("FILE SYSTEM WAS MODIFIED")) {
+                upload_needed = true;
+                break;
+            }
+        }
+
+        if (upload_needed) {
+            addFileToDropBox(db, prefs, headers, "/dev/fscklogs/log", maxSize, tag);
+        }
+
+        // Remove the file so we don't re-upload if the runtime restarts.
+        file.delete();
+    }
+}
diff --git a/services/java/com/android/server/BrickReceiver.java b/services/core/java/com/android/server/BrickReceiver.java
similarity index 100%
rename from services/java/com/android/server/BrickReceiver.java
rename to services/core/java/com/android/server/BrickReceiver.java
diff --git a/services/java/com/android/server/CertBlacklister.java b/services/core/java/com/android/server/CertBlacklister.java
similarity index 100%
rename from services/java/com/android/server/CertBlacklister.java
rename to services/core/java/com/android/server/CertBlacklister.java
diff --git a/services/java/com/android/server/CommonTimeManagementService.java b/services/core/java/com/android/server/CommonTimeManagementService.java
similarity index 100%
rename from services/java/com/android/server/CommonTimeManagementService.java
rename to services/core/java/com/android/server/CommonTimeManagementService.java
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
new file mode 100644
index 0000000..0862f8a
--- /dev/null
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -0,0 +1,5007 @@
+/*
+ * 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.server;
+
+import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
+import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
+import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
+import static android.net.ConnectivityManager.TYPE_DUMMY;
+import static android.net.ConnectivityManager.TYPE_ETHERNET;
+import static android.net.ConnectivityManager.TYPE_MOBILE;
+import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.ConnectivityManager.TYPE_WIMAX;
+import static android.net.ConnectivityManager.TYPE_PROXY;
+import static android.net.ConnectivityManager.getNetworkTypeName;
+import static android.net.ConnectivityManager.isNetworkTypeValid;
+import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
+import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
+
+import android.app.AlarmManager;
+import android.app.AppOpsManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.bluetooth.BluetoothTetheringDataTracker;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.net.CaptivePortalTracker;
+import android.net.ConnectivityManager;
+import android.net.DummyDataStateTracker;
+import android.net.EthernetDataTracker;
+import android.net.IConnectivityManager;
+import android.net.INetworkManagementEventObserver;
+import android.net.INetworkPolicyListener;
+import android.net.INetworkPolicyManager;
+import android.net.INetworkStatsService;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.net.LinkProperties.CompareResult;
+import android.net.LinkQualityInfo;
+import android.net.MobileDataStateTracker;
+import android.net.NetworkConfig;
+import android.net.NetworkInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkQuotaInfo;
+import android.net.NetworkState;
+import android.net.NetworkStateTracker;
+import android.net.NetworkUtils;
+import android.net.Proxy;
+import android.net.ProxyDataTracker;
+import android.net.ProxyProperties;
+import android.net.RouteInfo;
+import android.net.SamplingDataTracker;
+import android.net.Uri;
+import android.net.wifi.WifiStateTracker;
+import android.net.wimax.WimaxManagerConstants;
+import android.os.AsyncTask;
+import android.os.Binder;
+import android.os.Build;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.INetworkManagementService;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.ParcelFileDescriptor;
+import android.os.PowerManager;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.security.Credentials;
+import android.security.KeyStore;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.SparseIntArray;
+import android.util.Xml;
+
+import com.android.internal.R;
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.net.LegacyVpnInfo;
+import com.android.internal.net.VpnConfig;
+import com.android.internal.net.VpnProfile;
+import com.android.internal.telephony.DctConstants;
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.util.IndentingPrintWriter;
+import com.android.internal.util.XmlUtils;
+import com.android.server.am.BatteryStatsService;
+import com.android.server.connectivity.DataConnectionStats;
+import com.android.server.connectivity.Nat464Xlat;
+import com.android.server.connectivity.PacManager;
+import com.android.server.connectivity.Tethering;
+import com.android.server.connectivity.Vpn;
+import com.android.server.net.BaseNetworkObserver;
+import com.android.server.net.LockdownVpnTracker;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Sets;
+
+import dalvik.system.DexClassLoader;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Constructor;
+import java.net.HttpURLConnection;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+
+/**
+ * @hide
+ */
+public class ConnectivityService extends IConnectivityManager.Stub {
+    private static final String TAG = "ConnectivityService";
+
+    private static final boolean DBG = true;
+    private static final boolean VDBG = false;
+
+    private static final boolean LOGD_RULES = false;
+
+    // TODO: create better separation between radio types and network types
+
+    // how long to wait before switching back to a radio's default network
+    private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
+    // system property that can override the above value
+    private static final String NETWORK_RESTORE_DELAY_PROP_NAME =
+            "android.telephony.apn-restore";
+
+    // Default value if FAIL_FAST_TIME_MS is not set
+    private static final int DEFAULT_FAIL_FAST_TIME_MS = 1 * 60 * 1000;
+    // system property that can override DEFAULT_FAIL_FAST_TIME_MS
+    private static final String FAIL_FAST_TIME_MS =
+            "persist.radio.fail_fast_time_ms";
+
+    private static final String ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED =
+            "android.net.ConnectivityService.action.PKT_CNT_SAMPLE_INTERVAL_ELAPSED";
+
+    private static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0;
+
+    private PendingIntent mSampleIntervalElapsedIntent;
+
+    // Set network sampling interval at 12 minutes, this way, even if the timers get
+    // aggregated, it will fire at around 15 minutes, which should allow us to
+    // aggregate this timer with other timers (specially the socket keep alive timers)
+    private static final int DEFAULT_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 12 * 60);
+
+    // start network sampling a minute after booting ...
+    private static final int DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 60);
+
+    AlarmManager mAlarmManager;
+
+    // used in recursive route setting to add gateways for the host for which
+    // a host route was requested.
+    private static final int MAX_HOSTROUTE_CYCLE_COUNT = 10;
+
+    private Tethering mTethering;
+
+    private KeyStore mKeyStore;
+
+    @GuardedBy("mVpns")
+    private final SparseArray<Vpn> mVpns = new SparseArray<Vpn>();
+    private VpnCallback mVpnCallback = new VpnCallback();
+
+    private boolean mLockdownEnabled;
+    private LockdownVpnTracker mLockdownTracker;
+
+    private Nat464Xlat mClat;
+
+    /** Lock around {@link #mUidRules} and {@link #mMeteredIfaces}. */
+    private Object mRulesLock = new Object();
+    /** Currently active network rules by UID. */
+    private SparseIntArray mUidRules = new SparseIntArray();
+    /** Set of ifaces that are costly. */
+    private HashSet<String> mMeteredIfaces = Sets.newHashSet();
+
+    /**
+     * Sometimes we want to refer to the individual network state
+     * trackers separately, and sometimes we just want to treat them
+     * abstractly.
+     */
+    private NetworkStateTracker mNetTrackers[];
+
+    /* Handles captive portal check on a network */
+    private CaptivePortalTracker mCaptivePortalTracker;
+
+    /**
+     * The link properties that define the current links
+     */
+    private LinkProperties mCurrentLinkProperties[];
+
+    /**
+     * A per Net list of the PID's that requested access to the net
+     * used both as a refcount and for per-PID DNS selection
+     */
+    private List<Integer> mNetRequestersPids[];
+
+    // priority order of the nettrackers
+    // (excluding dynamically set mNetworkPreference)
+    // TODO - move mNetworkTypePreference into this
+    private int[] mPriorityList;
+
+    private Context mContext;
+    private int mNetworkPreference;
+    private int mActiveDefaultNetwork = -1;
+    // 0 is full bad, 100 is full good
+    private int mDefaultInetCondition = 0;
+    private int mDefaultInetConditionPublished = 0;
+    private boolean mInetConditionChangeInFlight = false;
+    private int mDefaultConnectionSequence = 0;
+
+    private Object mDnsLock = new Object();
+    private int mNumDnsEntries;
+
+    private boolean mTestMode;
+    private static ConnectivityService sServiceInstance;
+
+    private INetworkManagementService mNetd;
+    private INetworkPolicyManager mPolicyManager;
+
+    private static final int ENABLED  = 1;
+    private static final int DISABLED = 0;
+
+    private static final boolean ADD = true;
+    private static final boolean REMOVE = false;
+
+    private static final boolean TO_DEFAULT_TABLE = true;
+    private static final boolean TO_SECONDARY_TABLE = false;
+
+    private static final boolean EXEMPT = true;
+    private static final boolean UNEXEMPT = false;
+
+    /**
+     * used internally as a delayed event to make us switch back to the
+     * default network
+     */
+    private static final int EVENT_RESTORE_DEFAULT_NETWORK = 1;
+
+    /**
+     * used internally to change our mobile data enabled flag
+     */
+    private static final int EVENT_CHANGE_MOBILE_DATA_ENABLED = 2;
+
+    /**
+     * used internally to change our network preference setting
+     * arg1 = networkType to prefer
+     */
+    private static final int EVENT_SET_NETWORK_PREFERENCE = 3;
+
+    /**
+     * used internally to synchronize inet condition reports
+     * arg1 = networkType
+     * arg2 = condition (0 bad, 100 good)
+     */
+    private static final int EVENT_INET_CONDITION_CHANGE = 4;
+
+    /**
+     * used internally to mark the end of inet condition hold periods
+     * arg1 = networkType
+     */
+    private static final int EVENT_INET_CONDITION_HOLD_END = 5;
+
+    /**
+     * used internally to set enable/disable cellular data
+     * arg1 = ENBALED or DISABLED
+     */
+    private static final int EVENT_SET_MOBILE_DATA = 7;
+
+    /**
+     * used internally to clear a wakelock when transitioning
+     * from one net to another
+     */
+    private static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 8;
+
+    /**
+     * used internally to reload global proxy settings
+     */
+    private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY = 9;
+
+    /**
+     * used internally to set external dependency met/unmet
+     * arg1 = ENABLED (met) or DISABLED (unmet)
+     * arg2 = NetworkType
+     */
+    private static final int EVENT_SET_DEPENDENCY_MET = 10;
+
+    /**
+     * used internally to send a sticky broadcast delayed.
+     */
+    private static final int EVENT_SEND_STICKY_BROADCAST_INTENT = 11;
+
+    /**
+     * Used internally to
+     * {@link NetworkStateTracker#setPolicyDataEnable(boolean)}.
+     */
+    private static final int EVENT_SET_POLICY_DATA_ENABLE = 12;
+
+    private static final int EVENT_VPN_STATE_CHANGED = 13;
+
+    /**
+     * Used internally to disable fail fast of mobile data
+     */
+    private static final int EVENT_ENABLE_FAIL_FAST_MOBILE_DATA = 14;
+
+    /**
+     * user internally to indicate that data sampling interval is up
+     */
+    private static final int EVENT_SAMPLE_INTERVAL_ELAPSED = 15;
+
+    /**
+     * PAC manager has received new port.
+     */
+    private static final int EVENT_PROXY_HAS_CHANGED = 16;
+
+    /** Handler used for internal events. */
+    private InternalHandler mHandler;
+    /** Handler used for incoming {@link NetworkStateTracker} events. */
+    private NetworkStateTrackerHandler mTrackerHandler;
+
+    // list of DeathRecipients used to make sure features are turned off when
+    // a process dies
+    private List<FeatureUser> mFeatureUsers;
+
+    private boolean mSystemReady;
+    private Intent mInitialBroadcast;
+
+    private PowerManager.WakeLock mNetTransitionWakeLock;
+    private String mNetTransitionWakeLockCausedBy = "";
+    private int mNetTransitionWakeLockSerialNumber;
+    private int mNetTransitionWakeLockTimeout;
+
+    private InetAddress mDefaultDns;
+
+    // Lock for protecting access to mAddedRoutes and mExemptAddresses
+    private final Object mRoutesLock = new Object();
+
+    // this collection is used to refcount the added routes - if there are none left
+    // it's time to remove the route from the route table
+    @GuardedBy("mRoutesLock")
+    private Collection<RouteInfo> mAddedRoutes = new ArrayList<RouteInfo>();
+
+    // this collection corresponds to the entries of mAddedRoutes that have routing exemptions
+    // used to handle cleanup of exempt rules
+    @GuardedBy("mRoutesLock")
+    private Collection<LinkAddress> mExemptAddresses = new ArrayList<LinkAddress>();
+
+    // used in DBG mode to track inet condition reports
+    private static final int INET_CONDITION_LOG_MAX_SIZE = 15;
+    private ArrayList mInetLog;
+
+    // track the current default http proxy - tell the world if we get a new one (real change)
+    private ProxyProperties mDefaultProxy = null;
+    private Object mProxyLock = new Object();
+    private boolean mDefaultProxyDisabled = false;
+
+    // track the global proxy.
+    private ProxyProperties mGlobalProxy = null;
+
+    private PacManager mPacManager = null;
+
+    private SettingsObserver mSettingsObserver;
+
+    private AppOpsManager mAppOpsManager;
+
+    NetworkConfig[] mNetConfigs;
+    int mNetworksDefined;
+
+    private static class RadioAttributes {
+        public int mSimultaneity;
+        public int mType;
+        public RadioAttributes(String init) {
+            String fragments[] = init.split(",");
+            mType = Integer.parseInt(fragments[0]);
+            mSimultaneity = Integer.parseInt(fragments[1]);
+        }
+    }
+    RadioAttributes[] mRadioAttributes;
+
+    // the set of network types that can only be enabled by system/sig apps
+    List mProtectedNetworks;
+
+    private DataConnectionStats mDataConnectionStats;
+
+    private AtomicInteger mEnableFailFastMobileDataTag = new AtomicInteger(0);
+
+    TelephonyManager mTelephonyManager;
+
+    public ConnectivityService(Context context, INetworkManagementService netd,
+            INetworkStatsService statsService, INetworkPolicyManager policyManager) {
+        // Currently, omitting a NetworkFactory will create one internally
+        // TODO: create here when we have cleaner WiMAX support
+        this(context, netd, statsService, policyManager, null);
+    }
+
+    public ConnectivityService(Context context, INetworkManagementService netManager,
+            INetworkStatsService statsService, INetworkPolicyManager policyManager,
+            NetworkFactory netFactory) {
+        if (DBG) log("ConnectivityService starting up");
+
+        HandlerThread handlerThread = new HandlerThread("ConnectivityServiceThread");
+        handlerThread.start();
+        mHandler = new InternalHandler(handlerThread.getLooper());
+        mTrackerHandler = new NetworkStateTrackerHandler(handlerThread.getLooper());
+
+        if (netFactory == null) {
+            netFactory = new DefaultNetworkFactory(context, mTrackerHandler);
+        }
+
+        // setup our unique device name
+        if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
+            String id = Settings.Secure.getString(context.getContentResolver(),
+                    Settings.Secure.ANDROID_ID);
+            if (id != null && id.length() > 0) {
+                String name = new String("android-").concat(id);
+                SystemProperties.set("net.hostname", name);
+            }
+        }
+
+        // read our default dns server ip
+        String dns = Settings.Global.getString(context.getContentResolver(),
+                Settings.Global.DEFAULT_DNS_SERVER);
+        if (dns == null || dns.length() == 0) {
+            dns = context.getResources().getString(
+                    com.android.internal.R.string.config_default_dns_server);
+        }
+        try {
+            mDefaultDns = NetworkUtils.numericToInetAddress(dns);
+        } catch (IllegalArgumentException e) {
+            loge("Error setting defaultDns using " + dns);
+        }
+
+        mContext = checkNotNull(context, "missing Context");
+        mNetd = checkNotNull(netManager, "missing INetworkManagementService");
+        mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
+        mKeyStore = KeyStore.getInstance();
+        mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+
+        try {
+            mPolicyManager.registerListener(mPolicyListener);
+        } catch (RemoteException e) {
+            // ouch, no rules updates means some processes may never get network
+            loge("unable to register INetworkPolicyListener" + e.toString());
+        }
+
+        final PowerManager powerManager = (PowerManager) context.getSystemService(
+                Context.POWER_SERVICE);
+        mNetTransitionWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+        mNetTransitionWakeLockTimeout = mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_networkTransitionTimeout);
+
+        mNetTrackers = new NetworkStateTracker[
+                ConnectivityManager.MAX_NETWORK_TYPE+1];
+        mCurrentLinkProperties = new LinkProperties[ConnectivityManager.MAX_NETWORK_TYPE+1];
+
+        mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
+        mNetConfigs = new NetworkConfig[ConnectivityManager.MAX_NETWORK_TYPE+1];
+
+        // Load device network attributes from resources
+        String[] raStrings = context.getResources().getStringArray(
+                com.android.internal.R.array.radioAttributes);
+        for (String raString : raStrings) {
+            RadioAttributes r = new RadioAttributes(raString);
+            if (VDBG) log("raString=" + raString + " r=" + r);
+            if (r.mType > ConnectivityManager.MAX_RADIO_TYPE) {
+                loge("Error in radioAttributes - ignoring attempt to define type " + r.mType);
+                continue;
+            }
+            if (mRadioAttributes[r.mType] != null) {
+                loge("Error in radioAttributes - ignoring attempt to redefine type " +
+                        r.mType);
+                continue;
+            }
+            mRadioAttributes[r.mType] = r;
+        }
+
+        // TODO: What is the "correct" way to do determine if this is a wifi only device?
+        boolean wifiOnly = SystemProperties.getBoolean("ro.radio.noril", false);
+        log("wifiOnly=" + wifiOnly);
+        String[] naStrings = context.getResources().getStringArray(
+                com.android.internal.R.array.networkAttributes);
+        for (String naString : naStrings) {
+            try {
+                NetworkConfig n = new NetworkConfig(naString);
+                if (VDBG) log("naString=" + naString + " config=" + n);
+                if (n.type > ConnectivityManager.MAX_NETWORK_TYPE) {
+                    loge("Error in networkAttributes - ignoring attempt to define type " +
+                            n.type);
+                    continue;
+                }
+                if (wifiOnly && ConnectivityManager.isNetworkTypeMobile(n.type)) {
+                    log("networkAttributes - ignoring mobile as this dev is wifiOnly " +
+                            n.type);
+                    continue;
+                }
+                if (mNetConfigs[n.type] != null) {
+                    loge("Error in networkAttributes - ignoring attempt to redefine type " +
+                            n.type);
+                    continue;
+                }
+                if (mRadioAttributes[n.radio] == null) {
+                    loge("Error in networkAttributes - ignoring attempt to use undefined " +
+                            "radio " + n.radio + " in network type " + n.type);
+                    continue;
+                }
+                mNetConfigs[n.type] = n;
+                mNetworksDefined++;
+            } catch(Exception e) {
+                // ignore it - leave the entry null
+            }
+        }
+        if (VDBG) log("mNetworksDefined=" + mNetworksDefined);
+
+        mProtectedNetworks = new ArrayList<Integer>();
+        int[] protectedNetworks = context.getResources().getIntArray(
+                com.android.internal.R.array.config_protectedNetworks);
+        for (int p : protectedNetworks) {
+            if ((mNetConfigs[p] != null) && (mProtectedNetworks.contains(p) == false)) {
+                mProtectedNetworks.add(p);
+            } else {
+                if (DBG) loge("Ignoring protectedNetwork " + p);
+            }
+        }
+
+        // high priority first
+        mPriorityList = new int[mNetworksDefined];
+        {
+            int insertionPoint = mNetworksDefined-1;
+            int currentLowest = 0;
+            int nextLowest = 0;
+            while (insertionPoint > -1) {
+                for (NetworkConfig na : mNetConfigs) {
+                    if (na == null) continue;
+                    if (na.priority < currentLowest) continue;
+                    if (na.priority > currentLowest) {
+                        if (na.priority < nextLowest || nextLowest == 0) {
+                            nextLowest = na.priority;
+                        }
+                        continue;
+                    }
+                    mPriorityList[insertionPoint--] = na.type;
+                }
+                currentLowest = nextLowest;
+                nextLowest = 0;
+            }
+        }
+
+        // Update mNetworkPreference according to user mannually first then overlay config.xml
+        mNetworkPreference = getPersistedNetworkPreference();
+        if (mNetworkPreference == -1) {
+            for (int n : mPriorityList) {
+                if (mNetConfigs[n].isDefault() && ConnectivityManager.isNetworkTypeValid(n)) {
+                    mNetworkPreference = n;
+                    break;
+                }
+            }
+            if (mNetworkPreference == -1) {
+                throw new IllegalStateException(
+                        "You should set at least one default Network in config.xml!");
+            }
+        }
+
+        mNetRequestersPids =
+                (List<Integer> [])new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
+        for (int i : mPriorityList) {
+            mNetRequestersPids[i] = new ArrayList<Integer>();
+        }
+
+        mFeatureUsers = new ArrayList<FeatureUser>();
+
+        mTestMode = SystemProperties.get("cm.test.mode").equals("true")
+                && SystemProperties.get("ro.build.type").equals("eng");
+
+        // Create and start trackers for hard-coded networks
+        for (int targetNetworkType : mPriorityList) {
+            final NetworkConfig config = mNetConfigs[targetNetworkType];
+            final NetworkStateTracker tracker;
+            try {
+                tracker = netFactory.createTracker(targetNetworkType, config);
+                mNetTrackers[targetNetworkType] = tracker;
+            } catch (IllegalArgumentException e) {
+                Slog.e(TAG, "Problem creating " + getNetworkTypeName(targetNetworkType)
+                        + " tracker: " + e);
+                continue;
+            }
+
+            tracker.startMonitoring(context, mTrackerHandler);
+            if (config.isDefault()) {
+                tracker.reconnect();
+            }
+        }
+
+        mTethering = new Tethering(mContext, mNetd, statsService, this, mHandler.getLooper());
+
+        //set up the listener for user state for creating user VPNs
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction(Intent.ACTION_USER_STARTING);
+        intentFilter.addAction(Intent.ACTION_USER_STOPPING);
+        mContext.registerReceiverAsUser(
+                mUserIntentReceiver, UserHandle.ALL, intentFilter, null, null);
+        mClat = new Nat464Xlat(mContext, mNetd, this, mTrackerHandler);
+
+        try {
+            mNetd.registerObserver(mTethering);
+            mNetd.registerObserver(mDataActivityObserver);
+            mNetd.registerObserver(mClat);
+        } catch (RemoteException e) {
+            loge("Error registering observer :" + e);
+        }
+
+        if (DBG) {
+            mInetLog = new ArrayList();
+        }
+
+        mSettingsObserver = new SettingsObserver(mHandler, EVENT_APPLY_GLOBAL_HTTP_PROXY);
+        mSettingsObserver.observe(mContext);
+
+        mDataConnectionStats = new DataConnectionStats(mContext);
+        mDataConnectionStats.startMonitoring();
+
+        // start network sampling ..
+        Intent intent = new Intent(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED, null);
+        mSampleIntervalElapsedIntent = PendingIntent.getBroadcast(mContext,
+                SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE, intent, 0);
+
+        mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
+        setAlarm(DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS * 1000, mSampleIntervalElapsedIntent);
+
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED);
+        mContext.registerReceiver(
+                new BroadcastReceiver() {
+                    @Override
+                    public void onReceive(Context context, Intent intent) {
+                        String action = intent.getAction();
+                        if (action.equals(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED)) {
+                            mHandler.sendMessage(mHandler.obtainMessage
+                                    (EVENT_SAMPLE_INTERVAL_ELAPSED));
+                        }
+                    }
+                },
+                new IntentFilter(filter));
+
+        mPacManager = new PacManager(mContext, mHandler, EVENT_PROXY_HAS_CHANGED);
+
+        filter = new IntentFilter();
+        filter.addAction(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
+        mContext.registerReceiver(mProvisioningReceiver, filter);
+
+        mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
+    }
+
+    /**
+     * Factory that creates {@link NetworkStateTracker} instances using given
+     * {@link NetworkConfig}.
+     */
+    public interface NetworkFactory {
+        public NetworkStateTracker createTracker(int targetNetworkType, NetworkConfig config);
+    }
+
+    private static class DefaultNetworkFactory implements NetworkFactory {
+        private final Context mContext;
+        private final Handler mTrackerHandler;
+
+        public DefaultNetworkFactory(Context context, Handler trackerHandler) {
+            mContext = context;
+            mTrackerHandler = trackerHandler;
+        }
+
+        @Override
+        public NetworkStateTracker createTracker(int targetNetworkType, NetworkConfig config) {
+            switch (config.radio) {
+                case TYPE_WIFI:
+                    return new WifiStateTracker(targetNetworkType, config.name);
+                case TYPE_MOBILE:
+                    return new MobileDataStateTracker(targetNetworkType, config.name);
+                case TYPE_DUMMY:
+                    return new DummyDataStateTracker(targetNetworkType, config.name);
+                case TYPE_BLUETOOTH:
+                    return BluetoothTetheringDataTracker.getInstance();
+                case TYPE_WIMAX:
+                    return makeWimaxStateTracker(mContext, mTrackerHandler);
+                case TYPE_ETHERNET:
+                    return EthernetDataTracker.getInstance();
+                case TYPE_PROXY:
+                    return new ProxyDataTracker();
+                default:
+                    throw new IllegalArgumentException(
+                            "Trying to create a NetworkStateTracker for an unknown radio type: "
+                            + config.radio);
+            }
+        }
+    }
+
+    /**
+     * Loads external WiMAX library and registers as system service, returning a
+     * {@link NetworkStateTracker} for WiMAX. Caller is still responsible for
+     * invoking {@link NetworkStateTracker#startMonitoring(Context, Handler)}.
+     */
+    private static NetworkStateTracker makeWimaxStateTracker(
+            Context context, Handler trackerHandler) {
+        // Initialize Wimax
+        DexClassLoader wimaxClassLoader;
+        Class wimaxStateTrackerClass = null;
+        Class wimaxServiceClass = null;
+        Class wimaxManagerClass;
+        String wimaxJarLocation;
+        String wimaxLibLocation;
+        String wimaxManagerClassName;
+        String wimaxServiceClassName;
+        String wimaxStateTrackerClassName;
+
+        NetworkStateTracker wimaxStateTracker = null;
+
+        boolean isWimaxEnabled = context.getResources().getBoolean(
+                com.android.internal.R.bool.config_wimaxEnabled);
+
+        if (isWimaxEnabled) {
+            try {
+                wimaxJarLocation = context.getResources().getString(
+                        com.android.internal.R.string.config_wimaxServiceJarLocation);
+                wimaxLibLocation = context.getResources().getString(
+                        com.android.internal.R.string.config_wimaxNativeLibLocation);
+                wimaxManagerClassName = context.getResources().getString(
+                        com.android.internal.R.string.config_wimaxManagerClassname);
+                wimaxServiceClassName = context.getResources().getString(
+                        com.android.internal.R.string.config_wimaxServiceClassname);
+                wimaxStateTrackerClassName = context.getResources().getString(
+                        com.android.internal.R.string.config_wimaxStateTrackerClassname);
+
+                if (DBG) log("wimaxJarLocation: " + wimaxJarLocation);
+                wimaxClassLoader =  new DexClassLoader(wimaxJarLocation,
+                        new ContextWrapper(context).getCacheDir().getAbsolutePath(),
+                        wimaxLibLocation, ClassLoader.getSystemClassLoader());
+
+                try {
+                    wimaxManagerClass = wimaxClassLoader.loadClass(wimaxManagerClassName);
+                    wimaxStateTrackerClass = wimaxClassLoader.loadClass(wimaxStateTrackerClassName);
+                    wimaxServiceClass = wimaxClassLoader.loadClass(wimaxServiceClassName);
+                } catch (ClassNotFoundException ex) {
+                    loge("Exception finding Wimax classes: " + ex.toString());
+                    return null;
+                }
+            } catch(Resources.NotFoundException ex) {
+                loge("Wimax Resources does not exist!!! ");
+                return null;
+            }
+
+            try {
+                if (DBG) log("Starting Wimax Service... ");
+
+                Constructor wmxStTrkrConst = wimaxStateTrackerClass.getConstructor
+                        (new Class[] {Context.class, Handler.class});
+                wimaxStateTracker = (NetworkStateTracker) wmxStTrkrConst.newInstance(
+                        context, trackerHandler);
+
+                Constructor wmxSrvConst = wimaxServiceClass.getDeclaredConstructor
+                        (new Class[] {Context.class, wimaxStateTrackerClass});
+                wmxSrvConst.setAccessible(true);
+                IBinder svcInvoker = (IBinder)wmxSrvConst.newInstance(context, wimaxStateTracker);
+                wmxSrvConst.setAccessible(false);
+
+                ServiceManager.addService(WimaxManagerConstants.WIMAX_SERVICE, svcInvoker);
+
+            } catch(Exception ex) {
+                loge("Exception creating Wimax classes: " + ex.toString());
+                return null;
+            }
+        } else {
+            loge("Wimax is not enabled or not added to the network attributes!!! ");
+            return null;
+        }
+
+        return wimaxStateTracker;
+    }
+
+    /**
+     * Sets the preferred network.
+     * @param preference the new preference
+     */
+    public void setNetworkPreference(int preference) {
+        enforceChangePermission();
+
+        mHandler.sendMessage(
+                mHandler.obtainMessage(EVENT_SET_NETWORK_PREFERENCE, preference, 0));
+    }
+
+    public int getNetworkPreference() {
+        enforceAccessPermission();
+        int preference;
+        synchronized(this) {
+            preference = mNetworkPreference;
+        }
+        return preference;
+    }
+
+    private void handleSetNetworkPreference(int preference) {
+        if (ConnectivityManager.isNetworkTypeValid(preference) &&
+                mNetConfigs[preference] != null &&
+                mNetConfigs[preference].isDefault()) {
+            if (mNetworkPreference != preference) {
+                final ContentResolver cr = mContext.getContentResolver();
+                Settings.Global.putInt(cr, Settings.Global.NETWORK_PREFERENCE, preference);
+                synchronized(this) {
+                    mNetworkPreference = preference;
+                }
+                enforcePreference();
+            }
+        }
+    }
+
+    private int getConnectivityChangeDelay() {
+        final ContentResolver cr = mContext.getContentResolver();
+
+        /** Check system properties for the default value then use secure settings value, if any. */
+        int defaultDelay = SystemProperties.getInt(
+                "conn." + Settings.Global.CONNECTIVITY_CHANGE_DELAY,
+                ConnectivityManager.CONNECTIVITY_CHANGE_DELAY_DEFAULT);
+        return Settings.Global.getInt(cr, Settings.Global.CONNECTIVITY_CHANGE_DELAY,
+                defaultDelay);
+    }
+
+    private int getPersistedNetworkPreference() {
+        final ContentResolver cr = mContext.getContentResolver();
+
+        final int networkPrefSetting = Settings.Global
+                .getInt(cr, Settings.Global.NETWORK_PREFERENCE, -1);
+
+        return networkPrefSetting;
+    }
+
+    /**
+     * Make the state of network connectivity conform to the preference settings
+     * In this method, we only tear down a non-preferred network. Establishing
+     * a connection to the preferred network is taken care of when we handle
+     * the disconnect event from the non-preferred network
+     * (see {@link #handleDisconnect(NetworkInfo)}).
+     */
+    private void enforcePreference() {
+        if (mNetTrackers[mNetworkPreference].getNetworkInfo().isConnected())
+            return;
+
+        if (!mNetTrackers[mNetworkPreference].isAvailable())
+            return;
+
+        for (int t=0; t <= ConnectivityManager.MAX_RADIO_TYPE; t++) {
+            if (t != mNetworkPreference && mNetTrackers[t] != null &&
+                    mNetTrackers[t].getNetworkInfo().isConnected()) {
+                if (DBG) {
+                    log("tearing down " + mNetTrackers[t].getNetworkInfo() +
+                            " in enforcePreference");
+                }
+                teardown(mNetTrackers[t]);
+            }
+        }
+    }
+
+    private boolean teardown(NetworkStateTracker netTracker) {
+        if (netTracker.teardown()) {
+            netTracker.setTeardownRequested(true);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Check if UID should be blocked from using the network represented by the
+     * given {@link NetworkStateTracker}.
+     */
+    private boolean isNetworkBlocked(NetworkStateTracker tracker, int uid) {
+        final String iface = tracker.getLinkProperties().getInterfaceName();
+
+        final boolean networkCostly;
+        final int uidRules;
+        synchronized (mRulesLock) {
+            networkCostly = mMeteredIfaces.contains(iface);
+            uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
+        }
+
+        if (networkCostly && (uidRules & RULE_REJECT_METERED) != 0) {
+            return true;
+        }
+
+        // no restrictive rules; network is visible
+        return false;
+    }
+
+    /**
+     * Return a filtered {@link NetworkInfo}, potentially marked
+     * {@link DetailedState#BLOCKED} based on
+     * {@link #isNetworkBlocked(NetworkStateTracker, int)}.
+     */
+    private NetworkInfo getFilteredNetworkInfo(NetworkStateTracker tracker, int uid) {
+        NetworkInfo info = tracker.getNetworkInfo();
+        if (isNetworkBlocked(tracker, uid)) {
+            // network is blocked; clone and override state
+            info = new NetworkInfo(info);
+            info.setDetailedState(DetailedState.BLOCKED, null, null);
+        }
+        if (mLockdownTracker != null) {
+            info = mLockdownTracker.augmentNetworkInfo(info);
+        }
+        return info;
+    }
+
+    /**
+     * Return NetworkInfo for the active (i.e., connected) network interface.
+     * It is assumed that at most one network is active at a time. If more
+     * than one is active, it is indeterminate which will be returned.
+     * @return the info for the active network, or {@code null} if none is
+     * active
+     */
+    @Override
+    public NetworkInfo getActiveNetworkInfo() {
+        enforceAccessPermission();
+        final int uid = Binder.getCallingUid();
+        return getNetworkInfo(mActiveDefaultNetwork, uid);
+    }
+
+    /**
+     * Find the first Provisioning network.
+     *
+     * @return NetworkInfo or null if none.
+     */
+    private NetworkInfo getProvisioningNetworkInfo() {
+        enforceAccessPermission();
+
+        // Find the first Provisioning Network
+        NetworkInfo provNi = null;
+        for (NetworkInfo ni : getAllNetworkInfo()) {
+            if (ni.isConnectedToProvisioningNetwork()) {
+                provNi = ni;
+                break;
+            }
+        }
+        if (DBG) log("getProvisioningNetworkInfo: X provNi=" + provNi);
+        return provNi;
+    }
+
+    /**
+     * Find the first Provisioning network or the ActiveDefaultNetwork
+     * if there is no Provisioning network
+     *
+     * @return NetworkInfo or null if none.
+     */
+    @Override
+    public NetworkInfo getProvisioningOrActiveNetworkInfo() {
+        enforceAccessPermission();
+
+        NetworkInfo provNi = getProvisioningNetworkInfo();
+        if (provNi == null) {
+            final int uid = Binder.getCallingUid();
+            provNi = getNetworkInfo(mActiveDefaultNetwork, uid);
+        }
+        if (DBG) log("getProvisioningOrActiveNetworkInfo: X provNi=" + provNi);
+        return provNi;
+    }
+
+    public NetworkInfo getActiveNetworkInfoUnfiltered() {
+        enforceAccessPermission();
+        if (isNetworkTypeValid(mActiveDefaultNetwork)) {
+            final NetworkStateTracker tracker = mNetTrackers[mActiveDefaultNetwork];
+            if (tracker != null) {
+                return tracker.getNetworkInfo();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public NetworkInfo getActiveNetworkInfoForUid(int uid) {
+        enforceConnectivityInternalPermission();
+        return getNetworkInfo(mActiveDefaultNetwork, uid);
+    }
+
+    @Override
+    public NetworkInfo getNetworkInfo(int networkType) {
+        enforceAccessPermission();
+        final int uid = Binder.getCallingUid();
+        return getNetworkInfo(networkType, uid);
+    }
+
+    private NetworkInfo getNetworkInfo(int networkType, int uid) {
+        NetworkInfo info = null;
+        if (isNetworkTypeValid(networkType)) {
+            final NetworkStateTracker tracker = mNetTrackers[networkType];
+            if (tracker != null) {
+                info = getFilteredNetworkInfo(tracker, uid);
+            }
+        }
+        return info;
+    }
+
+    @Override
+    public NetworkInfo[] getAllNetworkInfo() {
+        enforceAccessPermission();
+        final int uid = Binder.getCallingUid();
+        final ArrayList<NetworkInfo> result = Lists.newArrayList();
+        synchronized (mRulesLock) {
+            for (NetworkStateTracker tracker : mNetTrackers) {
+                if (tracker != null) {
+                    result.add(getFilteredNetworkInfo(tracker, uid));
+                }
+            }
+        }
+        return result.toArray(new NetworkInfo[result.size()]);
+    }
+
+    @Override
+    public boolean isNetworkSupported(int networkType) {
+        enforceAccessPermission();
+        return (isNetworkTypeValid(networkType) && (mNetTrackers[networkType] != null));
+    }
+
+    /**
+     * Return LinkProperties for the active (i.e., connected) default
+     * network interface.  It is assumed that at most one default network
+     * is active at a time. If more than one is active, it is indeterminate
+     * which will be returned.
+     * @return the ip properties for the active network, or {@code null} if
+     * none is active
+     */
+    @Override
+    public LinkProperties getActiveLinkProperties() {
+        return getLinkProperties(mActiveDefaultNetwork);
+    }
+
+    @Override
+    public LinkProperties getLinkProperties(int networkType) {
+        enforceAccessPermission();
+        if (isNetworkTypeValid(networkType)) {
+            final NetworkStateTracker tracker = mNetTrackers[networkType];
+            if (tracker != null) {
+                return tracker.getLinkProperties();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public NetworkState[] getAllNetworkState() {
+        enforceAccessPermission();
+        final int uid = Binder.getCallingUid();
+        final ArrayList<NetworkState> result = Lists.newArrayList();
+        synchronized (mRulesLock) {
+            for (NetworkStateTracker tracker : mNetTrackers) {
+                if (tracker != null) {
+                    final NetworkInfo info = getFilteredNetworkInfo(tracker, uid);
+                    result.add(new NetworkState(
+                            info, tracker.getLinkProperties(), tracker.getLinkCapabilities()));
+                }
+            }
+        }
+        return result.toArray(new NetworkState[result.size()]);
+    }
+
+    private NetworkState getNetworkStateUnchecked(int networkType) {
+        if (isNetworkTypeValid(networkType)) {
+            final NetworkStateTracker tracker = mNetTrackers[networkType];
+            if (tracker != null) {
+                return new NetworkState(tracker.getNetworkInfo(), tracker.getLinkProperties(),
+                        tracker.getLinkCapabilities());
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
+        enforceAccessPermission();
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            final NetworkState state = getNetworkStateUnchecked(mActiveDefaultNetwork);
+            if (state != null) {
+                try {
+                    return mPolicyManager.getNetworkQuotaInfo(state);
+                } catch (RemoteException e) {
+                }
+            }
+            return null;
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    @Override
+    public boolean isActiveNetworkMetered() {
+        enforceAccessPermission();
+        final long token = Binder.clearCallingIdentity();
+        try {
+            return isNetworkMeteredUnchecked(mActiveDefaultNetwork);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    private boolean isNetworkMeteredUnchecked(int networkType) {
+        final NetworkState state = getNetworkStateUnchecked(networkType);
+        if (state != null) {
+            try {
+                return mPolicyManager.isNetworkMetered(state);
+            } catch (RemoteException e) {
+            }
+        }
+        return false;
+    }
+
+    public boolean setRadios(boolean turnOn) {
+        boolean result = true;
+        enforceChangePermission();
+        for (NetworkStateTracker t : mNetTrackers) {
+            if (t != null) result = t.setRadio(turnOn) && result;
+        }
+        return result;
+    }
+
+    public boolean setRadio(int netType, boolean turnOn) {
+        enforceChangePermission();
+        if (!ConnectivityManager.isNetworkTypeValid(netType)) {
+            return false;
+        }
+        NetworkStateTracker tracker = mNetTrackers[netType];
+        return tracker != null && tracker.setRadio(turnOn);
+    }
+
+    private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() {
+        @Override
+        public void interfaceClassDataActivityChanged(String label, boolean active) {
+            int deviceType = Integer.parseInt(label);
+            sendDataActivityBroadcast(deviceType, active);
+        }
+    };
+
+    /**
+     * Used to notice when the calling process dies so we can self-expire
+     *
+     * Also used to know if the process has cleaned up after itself when
+     * our auto-expire timer goes off.  The timer has a link to an object.
+     *
+     */
+    private class FeatureUser implements IBinder.DeathRecipient {
+        int mNetworkType;
+        String mFeature;
+        IBinder mBinder;
+        int mPid;
+        int mUid;
+        long mCreateTime;
+
+        FeatureUser(int type, String feature, IBinder binder) {
+            super();
+            mNetworkType = type;
+            mFeature = feature;
+            mBinder = binder;
+            mPid = getCallingPid();
+            mUid = getCallingUid();
+            mCreateTime = System.currentTimeMillis();
+
+            try {
+                mBinder.linkToDeath(this, 0);
+            } catch (RemoteException e) {
+                binderDied();
+            }
+        }
+
+        void unlinkDeathRecipient() {
+            mBinder.unlinkToDeath(this, 0);
+        }
+
+        public void binderDied() {
+            log("ConnectivityService FeatureUser binderDied(" +
+                    mNetworkType + ", " + mFeature + ", " + mBinder + "), created " +
+                    (System.currentTimeMillis() - mCreateTime) + " mSec ago");
+            stopUsingNetworkFeature(this, false);
+        }
+
+        public void expire() {
+            if (VDBG) {
+                log("ConnectivityService FeatureUser expire(" +
+                        mNetworkType + ", " + mFeature + ", " + mBinder +"), created " +
+                        (System.currentTimeMillis() - mCreateTime) + " mSec ago");
+            }
+            stopUsingNetworkFeature(this, false);
+        }
+
+        public boolean isSameUser(FeatureUser u) {
+            if (u == null) return false;
+
+            return isSameUser(u.mPid, u.mUid, u.mNetworkType, u.mFeature);
+        }
+
+        public boolean isSameUser(int pid, int uid, int networkType, String feature) {
+            if ((mPid == pid) && (mUid == uid) && (mNetworkType == networkType) &&
+                TextUtils.equals(mFeature, feature)) {
+                return true;
+            }
+            return false;
+        }
+
+        public String toString() {
+            return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
+                    (System.currentTimeMillis() - mCreateTime) + " mSec ago";
+        }
+    }
+
+    // javadoc from interface
+    public int startUsingNetworkFeature(int networkType, String feature,
+            IBinder binder) {
+        long startTime = 0;
+        if (DBG) {
+            startTime = SystemClock.elapsedRealtime();
+        }
+        if (VDBG) {
+            log("startUsingNetworkFeature for net " + networkType + ": " + feature + ", uid="
+                    + Binder.getCallingUid());
+        }
+        enforceChangePermission();
+        try {
+            if (!ConnectivityManager.isNetworkTypeValid(networkType) ||
+                    mNetConfigs[networkType] == null) {
+                return PhoneConstants.APN_REQUEST_FAILED;
+            }
+
+            FeatureUser f = new FeatureUser(networkType, feature, binder);
+
+            // TODO - move this into individual networktrackers
+            int usedNetworkType = convertFeatureToNetworkType(networkType, feature);
+
+            if (mLockdownEnabled) {
+                // Since carrier APNs usually aren't available from VPN
+                // endpoint, mark them as unavailable.
+                return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
+            }
+
+            if (mProtectedNetworks.contains(usedNetworkType)) {
+                enforceConnectivityInternalPermission();
+            }
+
+            // if UID is restricted, don't allow them to bring up metered APNs
+            final boolean networkMetered = isNetworkMeteredUnchecked(usedNetworkType);
+            final int uidRules;
+            synchronized (mRulesLock) {
+                uidRules = mUidRules.get(Binder.getCallingUid(), RULE_ALLOW_ALL);
+            }
+            if (networkMetered && (uidRules & RULE_REJECT_METERED) != 0) {
+                return PhoneConstants.APN_REQUEST_FAILED;
+            }
+
+            NetworkStateTracker network = mNetTrackers[usedNetworkType];
+            if (network != null) {
+                Integer currentPid = new Integer(getCallingPid());
+                if (usedNetworkType != networkType) {
+                    NetworkInfo ni = network.getNetworkInfo();
+
+                    if (ni.isAvailable() == false) {
+                        if (!TextUtils.equals(feature,Phone.FEATURE_ENABLE_DUN_ALWAYS)) {
+                            if (DBG) log("special network not available ni=" + ni.getTypeName());
+                            return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
+                        } else {
+                            // else make the attempt anyway - probably giving REQUEST_STARTED below
+                            if (DBG) {
+                                log("special network not available, but try anyway ni=" +
+                                        ni.getTypeName());
+                            }
+                        }
+                    }
+
+                    int restoreTimer = getRestoreDefaultNetworkDelay(usedNetworkType);
+
+                    synchronized(this) {
+                        boolean addToList = true;
+                        if (restoreTimer < 0) {
+                            // In case there is no timer is specified for the feature,
+                            // make sure we don't add duplicate entry with the same request.
+                            for (FeatureUser u : mFeatureUsers) {
+                                if (u.isSameUser(f)) {
+                                    // Duplicate user is found. Do not add.
+                                    addToList = false;
+                                    break;
+                                }
+                            }
+                        }
+
+                        if (addToList) mFeatureUsers.add(f);
+                        if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
+                            // this gets used for per-pid dns when connected
+                            mNetRequestersPids[usedNetworkType].add(currentPid);
+                        }
+                    }
+
+                    if (restoreTimer >= 0) {
+                        mHandler.sendMessageDelayed(mHandler.obtainMessage(
+                                EVENT_RESTORE_DEFAULT_NETWORK, f), restoreTimer);
+                    }
+
+                    if ((ni.isConnectedOrConnecting() == true) &&
+                            !network.isTeardownRequested()) {
+                        if (ni.isConnected() == true) {
+                            final long token = Binder.clearCallingIdentity();
+                            try {
+                                // add the pid-specific dns
+                                handleDnsConfigurationChange(usedNetworkType);
+                                if (VDBG) log("special network already active");
+                            } finally {
+                                Binder.restoreCallingIdentity(token);
+                            }
+                            return PhoneConstants.APN_ALREADY_ACTIVE;
+                        }
+                        if (VDBG) log("special network already connecting");
+                        return PhoneConstants.APN_REQUEST_STARTED;
+                    }
+
+                    // check if the radio in play can make another contact
+                    // assume if cannot for now
+
+                    if (DBG) {
+                        log("startUsingNetworkFeature reconnecting to " + networkType + ": " +
+                                feature);
+                    }
+                    if (network.reconnect()) {
+                        if (DBG) log("startUsingNetworkFeature X: return APN_REQUEST_STARTED");
+                        return PhoneConstants.APN_REQUEST_STARTED;
+                    } else {
+                        if (DBG) log("startUsingNetworkFeature X: return APN_REQUEST_FAILED");
+                        return PhoneConstants.APN_REQUEST_FAILED;
+                    }
+                } else {
+                    // need to remember this unsupported request so we respond appropriately on stop
+                    synchronized(this) {
+                        mFeatureUsers.add(f);
+                        if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
+                            // this gets used for per-pid dns when connected
+                            mNetRequestersPids[usedNetworkType].add(currentPid);
+                        }
+                    }
+                    if (DBG) log("startUsingNetworkFeature X: return -1 unsupported feature.");
+                    return -1;
+                }
+            }
+            if (DBG) log("startUsingNetworkFeature X: return APN_TYPE_NOT_AVAILABLE");
+            return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
+         } finally {
+            if (DBG) {
+                final long execTime = SystemClock.elapsedRealtime() - startTime;
+                if (execTime > 250) {
+                    loge("startUsingNetworkFeature took too long: " + execTime + "ms");
+                } else {
+                    if (VDBG) log("startUsingNetworkFeature took " + execTime + "ms");
+                }
+            }
+         }
+    }
+
+    // javadoc from interface
+    public int stopUsingNetworkFeature(int networkType, String feature) {
+        enforceChangePermission();
+
+        int pid = getCallingPid();
+        int uid = getCallingUid();
+
+        FeatureUser u = null;
+        boolean found = false;
+
+        synchronized(this) {
+            for (FeatureUser x : mFeatureUsers) {
+                if (x.isSameUser(pid, uid, networkType, feature)) {
+                    u = x;
+                    found = true;
+                    break;
+                }
+            }
+        }
+        if (found && u != null) {
+            if (VDBG) log("stopUsingNetworkFeature: X");
+            // stop regardless of how many other time this proc had called start
+            return stopUsingNetworkFeature(u, true);
+        } else {
+            // none found!
+            if (VDBG) log("stopUsingNetworkFeature: X not a live request, ignoring");
+            return 1;
+        }
+    }
+
+    private int stopUsingNetworkFeature(FeatureUser u, boolean ignoreDups) {
+        int networkType = u.mNetworkType;
+        String feature = u.mFeature;
+        int pid = u.mPid;
+        int uid = u.mUid;
+
+        NetworkStateTracker tracker = null;
+        boolean callTeardown = false;  // used to carry our decision outside of sync block
+
+        if (VDBG) {
+            log("stopUsingNetworkFeature: net " + networkType + ": " + feature);
+        }
+
+        if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
+            if (DBG) {
+                log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
+                        ", net is invalid");
+            }
+            return -1;
+        }
+
+        // need to link the mFeatureUsers list with the mNetRequestersPids state in this
+        // sync block
+        synchronized(this) {
+            // check if this process still has an outstanding start request
+            if (!mFeatureUsers.contains(u)) {
+                if (VDBG) {
+                    log("stopUsingNetworkFeature: this process has no outstanding requests" +
+                        ", ignoring");
+                }
+                return 1;
+            }
+            u.unlinkDeathRecipient();
+            mFeatureUsers.remove(mFeatureUsers.indexOf(u));
+            // If we care about duplicate requests, check for that here.
+            //
+            // This is done to support the extension of a request - the app
+            // can request we start the network feature again and renew the
+            // auto-shutoff delay.  Normal "stop" calls from the app though
+            // do not pay attention to duplicate requests - in effect the
+            // API does not refcount and a single stop will counter multiple starts.
+            if (ignoreDups == false) {
+                for (FeatureUser x : mFeatureUsers) {
+                    if (x.isSameUser(u)) {
+                        if (VDBG) log("stopUsingNetworkFeature: dup is found, ignoring");
+                        return 1;
+                    }
+                }
+            }
+
+            // TODO - move to individual network trackers
+            int usedNetworkType = convertFeatureToNetworkType(networkType, feature);
+
+            tracker =  mNetTrackers[usedNetworkType];
+            if (tracker == null) {
+                if (DBG) {
+                    log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
+                            " no known tracker for used net type " + usedNetworkType);
+                }
+                return -1;
+            }
+            if (usedNetworkType != networkType) {
+                Integer currentPid = new Integer(pid);
+                mNetRequestersPids[usedNetworkType].remove(currentPid);
+
+                final long token = Binder.clearCallingIdentity();
+                try {
+                    reassessPidDns(pid, true);
+                } finally {
+                    Binder.restoreCallingIdentity(token);
+                }
+                flushVmDnsCache();
+                if (mNetRequestersPids[usedNetworkType].size() != 0) {
+                    if (VDBG) {
+                        log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
+                                " others still using it");
+                    }
+                    return 1;
+                }
+                callTeardown = true;
+            } else {
+                if (DBG) {
+                    log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
+                            " not a known feature - dropping");
+                }
+            }
+        }
+
+        if (callTeardown) {
+            if (DBG) {
+                log("stopUsingNetworkFeature: teardown net " + networkType + ": " + feature);
+            }
+            tracker.teardown();
+            return 1;
+        } else {
+            return -1;
+        }
+    }
+
+    /**
+     * Check if the address falls into any of currently running VPN's route's.
+     */
+    private boolean isAddressUnderVpn(InetAddress address) {
+        synchronized (mVpns) {
+            synchronized (mRoutesLock) {
+                int uid = UserHandle.getCallingUserId();
+                Vpn vpn = mVpns.get(uid);
+                if (vpn == null) {
+                    return false;
+                }
+
+                // Check if an exemption exists for this address.
+                for (LinkAddress destination : mExemptAddresses) {
+                    if (!NetworkUtils.addressTypeMatches(address, destination.getAddress())) {
+                        continue;
+                    }
+
+                    int prefix = destination.getNetworkPrefixLength();
+                    InetAddress addrMasked = NetworkUtils.getNetworkPart(address, prefix);
+                    InetAddress destMasked = NetworkUtils.getNetworkPart(destination.getAddress(),
+                            prefix);
+
+                    if (addrMasked.equals(destMasked)) {
+                        return false;
+                    }
+                }
+
+                // Finally check if the address is covered by the VPN.
+                return vpn.isAddressCovered(address);
+            }
+        }
+    }
+
+    /**
+     * @deprecated use requestRouteToHostAddress instead
+     *
+     * Ensure that a network route exists to deliver traffic to the specified
+     * host via the specified network interface.
+     * @param networkType the type of the network over which traffic to the
+     * specified host is to be routed
+     * @param hostAddress the IP address of the host to which the route is
+     * desired
+     * @return {@code true} on success, {@code false} on failure
+     */
+    public boolean requestRouteToHost(int networkType, int hostAddress, String packageName) {
+        InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
+
+        if (inetAddress == null) {
+            return false;
+        }
+
+        return requestRouteToHostAddress(networkType, inetAddress.getAddress(), packageName);
+    }
+
+    /**
+     * Ensure that a network route exists to deliver traffic to the specified
+     * host via the specified network interface.
+     * @param networkType the type of the network over which traffic to the
+     * specified host is to be routed
+     * @param hostAddress the IP address of the host to which the route is
+     * desired
+     * @return {@code true} on success, {@code false} on failure
+     */
+    public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress,
+            String packageName) {
+        enforceChangePermission();
+        if (mProtectedNetworks.contains(networkType)) {
+            enforceConnectivityInternalPermission();
+        }
+        boolean exempt;
+        InetAddress addr;
+        try {
+            addr = InetAddress.getByAddress(hostAddress);
+        } catch (UnknownHostException e) {
+            if (DBG) log("requestRouteToHostAddress got " + e.toString());
+            return false;
+        }
+        // System apps may request routes bypassing the VPN to keep other networks working.
+        if (Binder.getCallingUid() == Process.SYSTEM_UID) {
+            exempt = true;
+        } else {
+            mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName);
+            try {
+                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(packageName,
+                        0);
+                exempt = (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+            } catch (NameNotFoundException e) {
+                throw new IllegalArgumentException("Failed to find calling package details", e);
+            }
+        }
+
+        // Non-exempt routeToHost's can only be added if the host is not covered by the VPN.
+        // This can be either because the VPN's routes do not cover the destination or a
+        // system application added an exemption that covers this destination.
+        if (!exempt && isAddressUnderVpn(addr)) {
+            return false;
+        }
+
+        if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
+            if (DBG) log("requestRouteToHostAddress on invalid network: " + networkType);
+            return false;
+        }
+        NetworkStateTracker tracker = mNetTrackers[networkType];
+        DetailedState netState = DetailedState.DISCONNECTED;
+        if (tracker != null) {
+            netState = tracker.getNetworkInfo().getDetailedState();
+        }
+
+        if ((netState != DetailedState.CONNECTED &&
+                netState != DetailedState.CAPTIVE_PORTAL_CHECK) ||
+                tracker.isTeardownRequested()) {
+            if (VDBG) {
+                log("requestRouteToHostAddress on down network "
+                        + "(" + networkType + ") - dropped"
+                        + " tracker=" + tracker
+                        + " netState=" + netState
+                        + " isTeardownRequested="
+                            + ((tracker != null) ? tracker.isTeardownRequested() : "tracker:null"));
+            }
+            return false;
+        }
+        final long token = Binder.clearCallingIdentity();
+        try {
+            LinkProperties lp = tracker.getLinkProperties();
+            boolean ok = addRouteToAddress(lp, addr, exempt);
+            if (DBG) log("requestRouteToHostAddress ok=" + ok);
+            return ok;
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    private boolean addRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable,
+            boolean exempt) {
+        return modifyRoute(p, r, 0, ADD, toDefaultTable, exempt);
+    }
+
+    private boolean removeRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable) {
+        return modifyRoute(p, r, 0, REMOVE, toDefaultTable, UNEXEMPT);
+    }
+
+    private boolean addRouteToAddress(LinkProperties lp, InetAddress addr, boolean exempt) {
+        return modifyRouteToAddress(lp, addr, ADD, TO_DEFAULT_TABLE, exempt);
+    }
+
+    private boolean removeRouteToAddress(LinkProperties lp, InetAddress addr) {
+        return modifyRouteToAddress(lp, addr, REMOVE, TO_DEFAULT_TABLE, UNEXEMPT);
+    }
+
+    private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd,
+            boolean toDefaultTable, boolean exempt) {
+        RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getAllRoutes(), addr);
+        if (bestRoute == null) {
+            bestRoute = RouteInfo.makeHostRoute(addr, lp.getInterfaceName());
+        } else {
+            String iface = bestRoute.getInterface();
+            if (bestRoute.getGateway().equals(addr)) {
+                // if there is no better route, add the implied hostroute for our gateway
+                bestRoute = RouteInfo.makeHostRoute(addr, iface);
+            } else {
+                // if we will connect to this through another route, add a direct route
+                // to it's gateway
+                bestRoute = RouteInfo.makeHostRoute(addr, bestRoute.getGateway(), iface);
+            }
+        }
+        return modifyRoute(lp, bestRoute, 0, doAdd, toDefaultTable, exempt);
+    }
+
+    private boolean modifyRoute(LinkProperties lp, RouteInfo r, int cycleCount, boolean doAdd,
+            boolean toDefaultTable, boolean exempt) {
+        if ((lp == null) || (r == null)) {
+            if (DBG) log("modifyRoute got unexpected null: " + lp + ", " + r);
+            return false;
+        }
+
+        if (cycleCount > MAX_HOSTROUTE_CYCLE_COUNT) {
+            loge("Error modifying route - too much recursion");
+            return false;
+        }
+
+        String ifaceName = r.getInterface();
+        if(ifaceName == null) {
+            loge("Error modifying route - no interface name");
+            return false;
+        }
+        if (r.hasGateway()) {
+            RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getAllRoutes(), r.getGateway());
+            if (bestRoute != null) {
+                if (bestRoute.getGateway().equals(r.getGateway())) {
+                    // if there is no better route, add the implied hostroute for our gateway
+                    bestRoute = RouteInfo.makeHostRoute(r.getGateway(), ifaceName);
+                } else {
+                    // if we will connect to our gateway through another route, add a direct
+                    // route to it's gateway
+                    bestRoute = RouteInfo.makeHostRoute(r.getGateway(),
+                                                        bestRoute.getGateway(),
+                                                        ifaceName);
+                }
+                modifyRoute(lp, bestRoute, cycleCount+1, doAdd, toDefaultTable, exempt);
+            }
+        }
+        if (doAdd) {
+            if (VDBG) log("Adding " + r + " for interface " + ifaceName);
+            try {
+                if (toDefaultTable) {
+                    synchronized (mRoutesLock) {
+                        // only track default table - only one apps can effect
+                        mAddedRoutes.add(r);
+                        mNetd.addRoute(ifaceName, r);
+                        if (exempt) {
+                            LinkAddress dest = r.getDestination();
+                            if (!mExemptAddresses.contains(dest)) {
+                                mNetd.setHostExemption(dest);
+                                mExemptAddresses.add(dest);
+                            }
+                        }
+                    }
+                } else {
+                    mNetd.addSecondaryRoute(ifaceName, r);
+                }
+            } catch (Exception e) {
+                // never crash - catch them all
+                if (DBG) loge("Exception trying to add a route: " + e);
+                return false;
+            }
+        } else {
+            // if we remove this one and there are no more like it, then refcount==0 and
+            // we can remove it from the table
+            if (toDefaultTable) {
+                synchronized (mRoutesLock) {
+                    mAddedRoutes.remove(r);
+                    if (mAddedRoutes.contains(r) == false) {
+                        if (VDBG) log("Removing " + r + " for interface " + ifaceName);
+                        try {
+                            mNetd.removeRoute(ifaceName, r);
+                            LinkAddress dest = r.getDestination();
+                            if (mExemptAddresses.contains(dest)) {
+                                mNetd.clearHostExemption(dest);
+                                mExemptAddresses.remove(dest);
+                            }
+                        } catch (Exception e) {
+                            // never crash - catch them all
+                            if (VDBG) loge("Exception trying to remove a route: " + e);
+                            return false;
+                        }
+                    } else {
+                        if (VDBG) log("not removing " + r + " as it's still in use");
+                    }
+                }
+            } else {
+                if (VDBG) log("Removing " + r + " for interface " + ifaceName);
+                try {
+                    mNetd.removeSecondaryRoute(ifaceName, r);
+                } catch (Exception e) {
+                    // never crash - catch them all
+                    if (VDBG) loge("Exception trying to remove a route: " + e);
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * @see ConnectivityManager#getMobileDataEnabled()
+     */
+    public boolean getMobileDataEnabled() {
+        // TODO: This detail should probably be in DataConnectionTracker's
+        //       which is where we store the value and maybe make this
+        //       asynchronous.
+        enforceAccessPermission();
+        boolean retVal = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.MOBILE_DATA, 1) == 1;
+        if (VDBG) log("getMobileDataEnabled returning " + retVal);
+        return retVal;
+    }
+
+    public void setDataDependency(int networkType, boolean met) {
+        enforceConnectivityInternalPermission();
+
+        mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_DEPENDENCY_MET,
+                (met ? ENABLED : DISABLED), networkType));
+    }
+
+    private void handleSetDependencyMet(int networkType, boolean met) {
+        if (mNetTrackers[networkType] != null) {
+            if (DBG) {
+                log("handleSetDependencyMet(" + networkType + ", " + met + ")");
+            }
+            mNetTrackers[networkType].setDependencyMet(met);
+        }
+    }
+
+    private INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
+        @Override
+        public void onUidRulesChanged(int uid, int uidRules) {
+            // caller is NPMS, since we only register with them
+            if (LOGD_RULES) {
+                log("onUidRulesChanged(uid=" + uid + ", uidRules=" + uidRules + ")");
+            }
+
+            synchronized (mRulesLock) {
+                // skip update when we've already applied rules
+                final int oldRules = mUidRules.get(uid, RULE_ALLOW_ALL);
+                if (oldRules == uidRules) return;
+
+                mUidRules.put(uid, uidRules);
+            }
+
+            // TODO: notify UID when it has requested targeted updates
+        }
+
+        @Override
+        public void onMeteredIfacesChanged(String[] meteredIfaces) {
+            // caller is NPMS, since we only register with them
+            if (LOGD_RULES) {
+                log("onMeteredIfacesChanged(ifaces=" + Arrays.toString(meteredIfaces) + ")");
+            }
+
+            synchronized (mRulesLock) {
+                mMeteredIfaces.clear();
+                for (String iface : meteredIfaces) {
+                    mMeteredIfaces.add(iface);
+                }
+            }
+        }
+
+        @Override
+        public void onRestrictBackgroundChanged(boolean restrictBackground) {
+            // caller is NPMS, since we only register with them
+            if (LOGD_RULES) {
+                log("onRestrictBackgroundChanged(restrictBackground=" + restrictBackground + ")");
+            }
+
+            // kick off connectivity change broadcast for active network, since
+            // global background policy change is radical.
+            final int networkType = mActiveDefaultNetwork;
+            if (isNetworkTypeValid(networkType)) {
+                final NetworkStateTracker tracker = mNetTrackers[networkType];
+                if (tracker != null) {
+                    final NetworkInfo info = tracker.getNetworkInfo();
+                    if (info != null && info.isConnected()) {
+                        sendConnectedBroadcast(info);
+                    }
+                }
+            }
+        }
+    };
+
+    /**
+     * @see ConnectivityManager#setMobileDataEnabled(boolean)
+     */
+    public void setMobileDataEnabled(boolean enabled) {
+        enforceChangePermission();
+        if (DBG) log("setMobileDataEnabled(" + enabled + ")");
+
+        mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_MOBILE_DATA,
+                (enabled ? ENABLED : DISABLED), 0));
+    }
+
+    private void handleSetMobileData(boolean enabled) {
+        if (mNetTrackers[ConnectivityManager.TYPE_MOBILE] != null) {
+            if (VDBG) {
+                log(mNetTrackers[ConnectivityManager.TYPE_MOBILE].toString() + enabled);
+            }
+            mNetTrackers[ConnectivityManager.TYPE_MOBILE].setUserDataEnable(enabled);
+        }
+        if (mNetTrackers[ConnectivityManager.TYPE_WIMAX] != null) {
+            if (VDBG) {
+                log(mNetTrackers[ConnectivityManager.TYPE_WIMAX].toString() + enabled);
+            }
+            mNetTrackers[ConnectivityManager.TYPE_WIMAX].setUserDataEnable(enabled);
+        }
+    }
+
+    @Override
+    public void setPolicyDataEnable(int networkType, boolean enabled) {
+        // only someone like NPMS should only be calling us
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        mHandler.sendMessage(mHandler.obtainMessage(
+                EVENT_SET_POLICY_DATA_ENABLE, networkType, (enabled ? ENABLED : DISABLED)));
+    }
+
+    private void handleSetPolicyDataEnable(int networkType, boolean enabled) {
+        if (isNetworkTypeValid(networkType)) {
+            final NetworkStateTracker tracker = mNetTrackers[networkType];
+            if (tracker != null) {
+                tracker.setPolicyDataEnable(enabled);
+            }
+        }
+    }
+
+    private void enforceAccessPermission() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.ACCESS_NETWORK_STATE,
+                "ConnectivityService");
+    }
+
+    private void enforceChangePermission() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CHANGE_NETWORK_STATE,
+                "ConnectivityService");
+    }
+
+    // TODO Make this a special check when it goes public
+    private void enforceTetherChangePermission() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CHANGE_NETWORK_STATE,
+                "ConnectivityService");
+    }
+
+    private void enforceTetherAccessPermission() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.ACCESS_NETWORK_STATE,
+                "ConnectivityService");
+    }
+
+    private void enforceConnectivityInternalPermission() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CONNECTIVITY_INTERNAL,
+                "ConnectivityService");
+    }
+
+    private void enforceMarkNetworkSocketPermission() {
+        //Media server special case
+        if (Binder.getCallingUid() == Process.MEDIA_UID) {
+            return;
+        }
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.MARK_NETWORK_SOCKET,
+                "ConnectivityService");
+    }
+
+    /**
+     * Handle a {@code DISCONNECTED} event. If this pertains to the non-active
+     * network, we ignore it. If it is for the active network, we send out a
+     * broadcast. But first, we check whether it might be possible to connect
+     * to a different network.
+     * @param info the {@code NetworkInfo} for the network
+     */
+    private void handleDisconnect(NetworkInfo info) {
+
+        int prevNetType = info.getType();
+
+        mNetTrackers[prevNetType].setTeardownRequested(false);
+
+        // Remove idletimer previously setup in {@code handleConnect}
+        removeDataActivityTracking(prevNetType);
+
+        /*
+         * If the disconnected network is not the active one, then don't report
+         * this as a loss of connectivity. What probably happened is that we're
+         * getting the disconnect for a network that we explicitly disabled
+         * in accordance with network preference policies.
+         */
+        if (!mNetConfigs[prevNetType].isDefault()) {
+            List<Integer> pids = mNetRequestersPids[prevNetType];
+            for (Integer pid : pids) {
+                // will remove them because the net's no longer connected
+                // need to do this now as only now do we know the pids and
+                // can properly null things that are no longer referenced.
+                reassessPidDns(pid.intValue(), false);
+            }
+        }
+
+        Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
+        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
+        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
+        if (info.isFailover()) {
+            intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
+            info.setFailover(false);
+        }
+        if (info.getReason() != null) {
+            intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
+        }
+        if (info.getExtraInfo() != null) {
+            intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
+                    info.getExtraInfo());
+        }
+
+        if (mNetConfigs[prevNetType].isDefault()) {
+            tryFailover(prevNetType);
+            if (mActiveDefaultNetwork != -1) {
+                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
+                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
+            } else {
+                mDefaultInetConditionPublished = 0; // we're not connected anymore
+                intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
+            }
+        }
+        intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
+
+        // Reset interface if no other connections are using the same interface
+        boolean doReset = true;
+        LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties();
+        if (linkProperties != null) {
+            String oldIface = linkProperties.getInterfaceName();
+            if (TextUtils.isEmpty(oldIface) == false) {
+                for (NetworkStateTracker networkStateTracker : mNetTrackers) {
+                    if (networkStateTracker == null) continue;
+                    NetworkInfo networkInfo = networkStateTracker.getNetworkInfo();
+                    if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) {
+                        LinkProperties l = networkStateTracker.getLinkProperties();
+                        if (l == null) continue;
+                        if (oldIface.equals(l.getInterfaceName())) {
+                            doReset = false;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        // do this before we broadcast the change
+        handleConnectivityChange(prevNetType, doReset);
+
+        final Intent immediateIntent = new Intent(intent);
+        immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
+        sendStickyBroadcast(immediateIntent);
+        sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
+        /*
+         * If the failover network is already connected, then immediately send
+         * out a followup broadcast indicating successful failover
+         */
+        if (mActiveDefaultNetwork != -1) {
+            sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(),
+                    getConnectivityChangeDelay());
+        }
+    }
+
+    private void tryFailover(int prevNetType) {
+        /*
+         * If this is a default network, check if other defaults are available.
+         * Try to reconnect on all available and let them hash it out when
+         * more than one connects.
+         */
+        if (mNetConfigs[prevNetType].isDefault()) {
+            if (mActiveDefaultNetwork == prevNetType) {
+                if (DBG) {
+                    log("tryFailover: set mActiveDefaultNetwork=-1, prevNetType=" + prevNetType);
+                }
+                mActiveDefaultNetwork = -1;
+            }
+
+            // don't signal a reconnect for anything lower or equal priority than our
+            // current connected default
+            // TODO - don't filter by priority now - nice optimization but risky
+//            int currentPriority = -1;
+//            if (mActiveDefaultNetwork != -1) {
+//                currentPriority = mNetConfigs[mActiveDefaultNetwork].mPriority;
+//            }
+
+            for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
+                if (checkType == prevNetType) continue;
+                if (mNetConfigs[checkType] == null) continue;
+                if (!mNetConfigs[checkType].isDefault()) continue;
+                if (mNetTrackers[checkType] == null) continue;
+
+// Enabling the isAvailable() optimization caused mobile to not get
+// selected if it was in the middle of error handling. Specifically
+// a moble connection that took 30 seconds to complete the DEACTIVATE_DATA_CALL
+// would not be available and we wouldn't get connected to anything.
+// So removing the isAvailable() optimization below for now. TODO: This
+// optimization should work and we need to investigate why it doesn't work.
+// This could be related to how DEACTIVATE_DATA_CALL is reporting its
+// complete before it is really complete.
+
+//                if (!mNetTrackers[checkType].isAvailable()) continue;
+
+//                if (currentPriority >= mNetConfigs[checkType].mPriority) continue;
+
+                NetworkStateTracker checkTracker = mNetTrackers[checkType];
+                NetworkInfo checkInfo = checkTracker.getNetworkInfo();
+                if (!checkInfo.isConnectedOrConnecting() || checkTracker.isTeardownRequested()) {
+                    checkInfo.setFailover(true);
+                    checkTracker.reconnect();
+                }
+                if (DBG) log("Attempting to switch to " + checkInfo.getTypeName());
+            }
+        }
+    }
+
+    public void sendConnectedBroadcast(NetworkInfo info) {
+        enforceConnectivityInternalPermission();
+        sendGeneralBroadcast(info, CONNECTIVITY_ACTION_IMMEDIATE);
+        sendGeneralBroadcast(info, CONNECTIVITY_ACTION);
+    }
+
+    private void sendConnectedBroadcastDelayed(NetworkInfo info, int delayMs) {
+        sendGeneralBroadcast(info, CONNECTIVITY_ACTION_IMMEDIATE);
+        sendGeneralBroadcastDelayed(info, CONNECTIVITY_ACTION, delayMs);
+    }
+
+    private void sendInetConditionBroadcast(NetworkInfo info) {
+        sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
+    }
+
+    private Intent makeGeneralIntent(NetworkInfo info, String bcastType) {
+        if (mLockdownTracker != null) {
+            info = mLockdownTracker.augmentNetworkInfo(info);
+        }
+
+        Intent intent = new Intent(bcastType);
+        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
+        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
+        if (info.isFailover()) {
+            intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
+            info.setFailover(false);
+        }
+        if (info.getReason() != null) {
+            intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
+        }
+        if (info.getExtraInfo() != null) {
+            intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
+                    info.getExtraInfo());
+        }
+        intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
+        return intent;
+    }
+
+    private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
+        sendStickyBroadcast(makeGeneralIntent(info, bcastType));
+    }
+
+    private void sendGeneralBroadcastDelayed(NetworkInfo info, String bcastType, int delayMs) {
+        sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
+    }
+
+    private void sendDataActivityBroadcast(int deviceType, boolean active) {
+        Intent intent = new Intent(ConnectivityManager.ACTION_DATA_ACTIVITY_CHANGE);
+        intent.putExtra(ConnectivityManager.EXTRA_DEVICE_TYPE, deviceType);
+        intent.putExtra(ConnectivityManager.EXTRA_IS_ACTIVE, active);
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL,
+                    RECEIVE_DATA_ACTIVITY_CHANGE, null, null, 0, null, null);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    /**
+     * Called when an attempt to fail over to another network has failed.
+     * @param info the {@link NetworkInfo} for the failed network
+     */
+    private void handleConnectionFailure(NetworkInfo info) {
+        mNetTrackers[info.getType()].setTeardownRequested(false);
+
+        String reason = info.getReason();
+        String extraInfo = info.getExtraInfo();
+
+        String reasonText;
+        if (reason == null) {
+            reasonText = ".";
+        } else {
+            reasonText = " (" + reason + ").";
+        }
+        loge("Attempt to connect to " + info.getTypeName() + " failed" + reasonText);
+
+        Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
+        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
+        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
+        if (getActiveNetworkInfo() == null) {
+            intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
+        }
+        if (reason != null) {
+            intent.putExtra(ConnectivityManager.EXTRA_REASON, reason);
+        }
+        if (extraInfo != null) {
+            intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, extraInfo);
+        }
+        if (info.isFailover()) {
+            intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
+            info.setFailover(false);
+        }
+
+        if (mNetConfigs[info.getType()].isDefault()) {
+            tryFailover(info.getType());
+            if (mActiveDefaultNetwork != -1) {
+                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
+                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
+            } else {
+                mDefaultInetConditionPublished = 0;
+                intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
+            }
+        }
+
+        intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
+
+        final Intent immediateIntent = new Intent(intent);
+        immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
+        sendStickyBroadcast(immediateIntent);
+        sendStickyBroadcast(intent);
+        /*
+         * If the failover network is already connected, then immediately send
+         * out a followup broadcast indicating successful failover
+         */
+        if (mActiveDefaultNetwork != -1) {
+            sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
+        }
+    }
+
+    private void sendStickyBroadcast(Intent intent) {
+        synchronized(this) {
+            if (!mSystemReady) {
+                mInitialBroadcast = new Intent(intent);
+            }
+            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+            if (VDBG) {
+                log("sendStickyBroadcast: action=" + intent.getAction());
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    private void sendStickyBroadcastDelayed(Intent intent, int delayMs) {
+        if (delayMs <= 0) {
+            sendStickyBroadcast(intent);
+        } else {
+            if (VDBG) {
+                log("sendStickyBroadcastDelayed: delayMs=" + delayMs + ", action="
+                        + intent.getAction());
+            }
+            mHandler.sendMessageDelayed(mHandler.obtainMessage(
+                    EVENT_SEND_STICKY_BROADCAST_INTENT, intent), delayMs);
+        }
+    }
+
+    void systemReady() {
+        mCaptivePortalTracker = CaptivePortalTracker.makeCaptivePortalTracker(mContext, this);
+        loadGlobalProxy();
+
+        synchronized(this) {
+            mSystemReady = true;
+            if (mInitialBroadcast != null) {
+                mContext.sendStickyBroadcastAsUser(mInitialBroadcast, UserHandle.ALL);
+                mInitialBroadcast = null;
+            }
+        }
+        // load the global proxy at startup
+        mHandler.sendMessage(mHandler.obtainMessage(EVENT_APPLY_GLOBAL_HTTP_PROXY));
+
+        // Try bringing up tracker, but if KeyStore isn't ready yet, wait
+        // for user to unlock device.
+        if (!updateLockdownVpn()) {
+            final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
+            mContext.registerReceiver(mUserPresentReceiver, filter);
+        }
+    }
+
+    private BroadcastReceiver mUserPresentReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // Try creating lockdown tracker, since user present usually means
+            // unlocked keystore.
+            if (updateLockdownVpn()) {
+                mContext.unregisterReceiver(this);
+            }
+        }
+    };
+
+    private boolean isNewNetTypePreferredOverCurrentNetType(int type) {
+        if (((type != mNetworkPreference)
+                      && (mNetConfigs[mActiveDefaultNetwork].priority > mNetConfigs[type].priority))
+                   || (mNetworkPreference == mActiveDefaultNetwork)) {
+            return false;
+        }
+        return true;
+    }
+
+    private void handleConnect(NetworkInfo info) {
+        final int newNetType = info.getType();
+
+        setupDataActivityTracking(newNetType);
+
+        // snapshot isFailover, because sendConnectedBroadcast() resets it
+        boolean isFailover = info.isFailover();
+        final NetworkStateTracker thisNet = mNetTrackers[newNetType];
+        final String thisIface = thisNet.getLinkProperties().getInterfaceName();
+
+        if (VDBG) {
+            log("handleConnect: E newNetType=" + newNetType + " thisIface=" + thisIface
+                    + " isFailover" + isFailover);
+        }
+
+        // if this is a default net and other default is running
+        // kill the one not preferred
+        if (mNetConfigs[newNetType].isDefault()) {
+            if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != newNetType) {
+                if (isNewNetTypePreferredOverCurrentNetType(newNetType)) {
+                    // tear down the other
+                    NetworkStateTracker otherNet =
+                            mNetTrackers[mActiveDefaultNetwork];
+                    if (DBG) {
+                        log("Policy requires " + otherNet.getNetworkInfo().getTypeName() +
+                            " teardown");
+                    }
+                    if (!teardown(otherNet)) {
+                        loge("Network declined teardown request");
+                        teardown(thisNet);
+                        return;
+                    }
+                } else {
+                       // don't accept this one
+                        if (VDBG) {
+                            log("Not broadcasting CONNECT_ACTION " +
+                                "to torn down network " + info.getTypeName());
+                        }
+                        teardown(thisNet);
+                        return;
+                }
+            }
+            synchronized (ConnectivityService.this) {
+                // have a new default network, release the transition wakelock in a second
+                // if it's held.  The second pause is to allow apps to reconnect over the
+                // new network
+                if (mNetTransitionWakeLock.isHeld()) {
+                    mHandler.sendMessageDelayed(mHandler.obtainMessage(
+                            EVENT_CLEAR_NET_TRANSITION_WAKELOCK,
+                            mNetTransitionWakeLockSerialNumber, 0),
+                            1000);
+                }
+            }
+            mActiveDefaultNetwork = newNetType;
+            // this will cause us to come up initially as unconnected and switching
+            // to connected after our normal pause unless somebody reports us as reall
+            // disconnected
+            mDefaultInetConditionPublished = 0;
+            mDefaultConnectionSequence++;
+            mInetConditionChangeInFlight = false;
+            // Don't do this - if we never sign in stay, grey
+            //reportNetworkCondition(mActiveDefaultNetwork, 100);
+            updateNetworkSettings(thisNet);
+        }
+        thisNet.setTeardownRequested(false);
+        updateMtuSizeSettings(thisNet);
+        handleConnectivityChange(newNetType, false);
+        sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
+
+        // notify battery stats service about this network
+        if (thisIface != null) {
+            try {
+                BatteryStatsService.getService().noteNetworkInterfaceType(thisIface, newNetType);
+            } catch (RemoteException e) {
+                // ignored; service lives in system_server
+            }
+        }
+    }
+
+    private void handleCaptivePortalTrackerCheck(NetworkInfo info) {
+        if (DBG) log("Captive portal check " + info);
+        int type = info.getType();
+        final NetworkStateTracker thisNet = mNetTrackers[type];
+        if (mNetConfigs[type].isDefault()) {
+            if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
+                if (isNewNetTypePreferredOverCurrentNetType(type)) {
+                    if (DBG) log("Captive check on " + info.getTypeName());
+                    mCaptivePortalTracker.detectCaptivePortal(new NetworkInfo(info));
+                    return;
+                } else {
+                    if (DBG) log("Tear down low priority net " + info.getTypeName());
+                    teardown(thisNet);
+                    return;
+                }
+            }
+        }
+
+        if (DBG) log("handleCaptivePortalTrackerCheck: call captivePortalCheckComplete ni=" + info);
+        thisNet.captivePortalCheckComplete();
+    }
+
+    /** @hide */
+    @Override
+    public void captivePortalCheckComplete(NetworkInfo info) {
+        enforceConnectivityInternalPermission();
+        if (DBG) log("captivePortalCheckComplete: ni=" + info);
+        mNetTrackers[info.getType()].captivePortalCheckComplete();
+    }
+
+    /** @hide */
+    @Override
+    public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
+        enforceConnectivityInternalPermission();
+        if (DBG) log("captivePortalCheckCompleted: ni=" + info + " captive=" + isCaptivePortal);
+        mNetTrackers[info.getType()].captivePortalCheckCompleted(isCaptivePortal);
+    }
+
+    /**
+     * Setup data activity tracking for the given network interface.
+     *
+     * Every {@code setupDataActivityTracking} should be paired with a
+     * {@link removeDataActivityTracking} for cleanup.
+     */
+    private void setupDataActivityTracking(int type) {
+        final NetworkStateTracker thisNet = mNetTrackers[type];
+        final String iface = thisNet.getLinkProperties().getInterfaceName();
+
+        final int timeout;
+
+        if (ConnectivityManager.isNetworkTypeMobile(type)) {
+            timeout = Settings.Global.getInt(mContext.getContentResolver(),
+                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE,
+                                             0);
+            // Canonicalize mobile network type
+            type = ConnectivityManager.TYPE_MOBILE;
+        } else if (ConnectivityManager.TYPE_WIFI == type) {
+            timeout = Settings.Global.getInt(mContext.getContentResolver(),
+                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI,
+                                             0);
+        } else {
+            // do not track any other networks
+            timeout = 0;
+        }
+
+        if (timeout > 0 && iface != null) {
+            try {
+                mNetd.addIdleTimer(iface, timeout, Integer.toString(type));
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    /**
+     * Remove data activity tracking when network disconnects.
+     */
+    private void removeDataActivityTracking(int type) {
+        final NetworkStateTracker net = mNetTrackers[type];
+        final String iface = net.getLinkProperties().getInterfaceName();
+
+        if (iface != null && (ConnectivityManager.isNetworkTypeMobile(type) ||
+                              ConnectivityManager.TYPE_WIFI == type)) {
+            try {
+                // the call fails silently if no idletimer setup for this interface
+                mNetd.removeIdleTimer(iface);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    /**
+     * After a change in the connectivity state of a network. We're mainly
+     * concerned with making sure that the list of DNS servers is set up
+     * according to which networks are connected, and ensuring that the
+     * right routing table entries exist.
+     */
+    private void handleConnectivityChange(int netType, boolean doReset) {
+        int resetMask = doReset ? NetworkUtils.RESET_ALL_ADDRESSES : 0;
+        boolean exempt = ConnectivityManager.isNetworkTypeExempt(netType);
+        if (VDBG) {
+            log("handleConnectivityChange: netType=" + netType + " doReset=" + doReset
+                    + " resetMask=" + resetMask);
+        }
+
+        /*
+         * If a non-default network is enabled, add the host routes that
+         * will allow it's DNS servers to be accessed.
+         */
+        handleDnsConfigurationChange(netType);
+
+        LinkProperties curLp = mCurrentLinkProperties[netType];
+        LinkProperties newLp = null;
+
+        if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
+            newLp = mNetTrackers[netType].getLinkProperties();
+            if (VDBG) {
+                log("handleConnectivityChange: changed linkProperty[" + netType + "]:" +
+                        " doReset=" + doReset + " resetMask=" + resetMask +
+                        "\n   curLp=" + curLp +
+                        "\n   newLp=" + newLp);
+            }
+
+            if (curLp != null) {
+                if (curLp.isIdenticalInterfaceName(newLp)) {
+                    CompareResult<LinkAddress> car = curLp.compareAddresses(newLp);
+                    if ((car.removed.size() != 0) || (car.added.size() != 0)) {
+                        for (LinkAddress linkAddr : car.removed) {
+                            if (linkAddr.getAddress() instanceof Inet4Address) {
+                                resetMask |= NetworkUtils.RESET_IPV4_ADDRESSES;
+                            }
+                            if (linkAddr.getAddress() instanceof Inet6Address) {
+                                resetMask |= NetworkUtils.RESET_IPV6_ADDRESSES;
+                            }
+                        }
+                        if (DBG) {
+                            log("handleConnectivityChange: addresses changed" +
+                                    " linkProperty[" + netType + "]:" + " resetMask=" + resetMask +
+                                    "\n   car=" + car);
+                        }
+                    } else {
+                        if (DBG) {
+                            log("handleConnectivityChange: address are the same reset per doReset" +
+                                   " linkProperty[" + netType + "]:" +
+                                   " resetMask=" + resetMask);
+                        }
+                    }
+                } else {
+                    resetMask = NetworkUtils.RESET_ALL_ADDRESSES;
+                    if (DBG) {
+                        log("handleConnectivityChange: interface not not equivalent reset both" +
+                                " linkProperty[" + netType + "]:" +
+                                " resetMask=" + resetMask);
+                    }
+                }
+            }
+            if (mNetConfigs[netType].isDefault()) {
+                handleApplyDefaultProxy(newLp.getHttpProxy());
+            }
+        } else {
+            if (VDBG) {
+                log("handleConnectivityChange: changed linkProperty[" + netType + "]:" +
+                        " doReset=" + doReset + " resetMask=" + resetMask +
+                        "\n  curLp=" + curLp +
+                        "\n  newLp= null");
+            }
+        }
+        mCurrentLinkProperties[netType] = newLp;
+        boolean resetDns = updateRoutes(newLp, curLp, mNetConfigs[netType].isDefault(), exempt);
+
+        if (resetMask != 0 || resetDns) {
+            if (VDBG) log("handleConnectivityChange: resetting");
+            if (curLp != null) {
+                if (VDBG) log("handleConnectivityChange: resetting curLp=" + curLp);
+                for (String iface : curLp.getAllInterfaceNames()) {
+                    if (TextUtils.isEmpty(iface) == false) {
+                        if (resetMask != 0) {
+                            if (DBG) log("resetConnections(" + iface + ", " + resetMask + ")");
+                            NetworkUtils.resetConnections(iface, resetMask);
+
+                            // Tell VPN the interface is down. It is a temporary
+                            // but effective fix to make VPN aware of the change.
+                            if ((resetMask & NetworkUtils.RESET_IPV4_ADDRESSES) != 0) {
+                                synchronized(mVpns) {
+                                    for (int i = 0; i < mVpns.size(); i++) {
+                                        mVpns.valueAt(i).interfaceStatusChanged(iface, false);
+                                    }
+                                }
+                            }
+                        }
+                        if (resetDns) {
+                            flushVmDnsCache();
+                            if (VDBG) log("resetting DNS cache for " + iface);
+                            try {
+                                mNetd.flushInterfaceDnsCache(iface);
+                            } catch (Exception e) {
+                                // never crash - catch them all
+                                if (DBG) loge("Exception resetting dns cache: " + e);
+                            }
+                        }
+                    } else {
+                        loge("Can't reset connection for type "+netType);
+                    }
+                }
+            }
+        }
+
+        // Update 464xlat state.
+        NetworkStateTracker tracker = mNetTrackers[netType];
+        if (mClat.requiresClat(netType, tracker)) {
+
+            // If the connection was previously using clat, but is not using it now, stop the clat
+            // daemon. Normally, this happens automatically when the connection disconnects, but if
+            // the disconnect is not reported, or if the connection's LinkProperties changed for
+            // some other reason (e.g., handoff changes the IP addresses on the link), it would
+            // still be running. If it's not running, then stopping it is a no-op.
+            if (Nat464Xlat.isRunningClat(curLp) && !Nat464Xlat.isRunningClat(newLp)) {
+                mClat.stopClat();
+            }
+            // If the link requires clat to be running, then start the daemon now.
+            if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
+                mClat.startClat(tracker);
+            } else {
+                mClat.stopClat();
+            }
+        }
+
+        // TODO: Temporary notifying upstread change to Tethering.
+        //       @see bug/4455071
+        /** Notify TetheringService if interface name has been changed. */
+        if (TextUtils.equals(mNetTrackers[netType].getNetworkInfo().getReason(),
+                             PhoneConstants.REASON_LINK_PROPERTIES_CHANGED)) {
+            if (isTetheringSupported()) {
+                mTethering.handleTetherIfaceChange();
+            }
+        }
+    }
+
+    /**
+     * Add and remove routes using the old properties (null if not previously connected),
+     * new properties (null if becoming disconnected).  May even be double null, which
+     * is a noop.
+     * Uses isLinkDefault to determine if default routes should be set or conversely if
+     * host routes should be set to the dns servers
+     * returns a boolean indicating the routes changed
+     */
+    private boolean updateRoutes(LinkProperties newLp, LinkProperties curLp,
+            boolean isLinkDefault, boolean exempt) {
+        Collection<RouteInfo> routesToAdd = null;
+        CompareResult<InetAddress> dnsDiff = new CompareResult<InetAddress>();
+        CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>();
+        if (curLp != null) {
+            // check for the delta between the current set and the new
+            routeDiff = curLp.compareAllRoutes(newLp);
+            dnsDiff = curLp.compareDnses(newLp);
+        } else if (newLp != null) {
+            routeDiff.added = newLp.getAllRoutes();
+            dnsDiff.added = newLp.getDnses();
+        }
+
+        boolean routesChanged = (routeDiff.removed.size() != 0 || routeDiff.added.size() != 0);
+
+        for (RouteInfo r : routeDiff.removed) {
+            if (isLinkDefault || ! r.isDefaultRoute()) {
+                if (VDBG) log("updateRoutes: default remove route r=" + r);
+                removeRoute(curLp, r, TO_DEFAULT_TABLE);
+            }
+            if (isLinkDefault == false) {
+                // remove from a secondary route table
+                removeRoute(curLp, r, TO_SECONDARY_TABLE);
+            }
+        }
+
+        if (!isLinkDefault) {
+            // handle DNS routes
+            if (routesChanged) {
+                // routes changed - remove all old dns entries and add new
+                if (curLp != null) {
+                    for (InetAddress oldDns : curLp.getDnses()) {
+                        removeRouteToAddress(curLp, oldDns);
+                    }
+                }
+                if (newLp != null) {
+                    for (InetAddress newDns : newLp.getDnses()) {
+                        addRouteToAddress(newLp, newDns, exempt);
+                    }
+                }
+            } else {
+                // no change in routes, check for change in dns themselves
+                for (InetAddress oldDns : dnsDiff.removed) {
+                    removeRouteToAddress(curLp, oldDns);
+                }
+                for (InetAddress newDns : dnsDiff.added) {
+                    addRouteToAddress(newLp, newDns, exempt);
+                }
+            }
+        }
+
+        for (RouteInfo r :  routeDiff.added) {
+            if (isLinkDefault || ! r.isDefaultRoute()) {
+                addRoute(newLp, r, TO_DEFAULT_TABLE, exempt);
+            } else {
+                // add to a secondary route table
+                addRoute(newLp, r, TO_SECONDARY_TABLE, UNEXEMPT);
+
+                // many radios add a default route even when we don't want one.
+                // remove the default route unless somebody else has asked for it
+                String ifaceName = newLp.getInterfaceName();
+                synchronized (mRoutesLock) {
+                    if (!TextUtils.isEmpty(ifaceName) && !mAddedRoutes.contains(r)) {
+                        if (VDBG) log("Removing " + r + " for interface " + ifaceName);
+                        try {
+                            mNetd.removeRoute(ifaceName, r);
+                        } catch (Exception e) {
+                            // never crash - catch them all
+                            if (DBG) loge("Exception trying to remove a route: " + e);
+                        }
+                    }
+                }
+            }
+        }
+
+        return routesChanged;
+    }
+
+   /**
+     * Reads the network specific MTU size from reources.
+     * and set it on it's iface.
+     */
+   private void updateMtuSizeSettings(NetworkStateTracker nt) {
+       final String iface = nt.getLinkProperties().getInterfaceName();
+       final int mtu = nt.getLinkProperties().getMtu();
+
+       if (mtu < 68 || mtu > 10000) {
+           loge("Unexpected mtu value: " + nt);
+           return;
+       }
+
+       try {
+           if (VDBG) log("Setting MTU size: " + iface + ", " + mtu);
+           mNetd.setMtu(iface, mtu);
+       } catch (Exception e) {
+           Slog.e(TAG, "exception in setMtu()" + e);
+       }
+   }
+
+    /**
+     * Reads the network specific TCP buffer sizes from SystemProperties
+     * net.tcp.buffersize.[default|wifi|umts|edge|gprs] and set them for system
+     * wide use
+     */
+    private void updateNetworkSettings(NetworkStateTracker nt) {
+        String key = nt.getTcpBufferSizesPropName();
+        String bufferSizes = key == null ? null : SystemProperties.get(key);
+
+        if (TextUtils.isEmpty(bufferSizes)) {
+            if (VDBG) log(key + " not found in system properties. Using defaults");
+
+            // Setting to default values so we won't be stuck to previous values
+            key = "net.tcp.buffersize.default";
+            bufferSizes = SystemProperties.get(key);
+        }
+
+        // Set values in kernel
+        if (bufferSizes.length() != 0) {
+            if (VDBG) {
+                log("Setting TCP values: [" + bufferSizes
+                        + "] which comes from [" + key + "]");
+            }
+            setBufferSize(bufferSizes);
+        }
+
+        final String defaultRwndKey = "net.tcp.default_init_rwnd";
+        int defaultRwndValue = SystemProperties.getInt(defaultRwndKey, 0);
+        Integer rwndValue = Settings.Global.getInt(mContext.getContentResolver(),
+            Settings.Global.TCP_DEFAULT_INIT_RWND, defaultRwndValue);
+        final String sysctlKey = "sys.sysctl.tcp_def_init_rwnd";
+        if (rwndValue != 0) {
+            SystemProperties.set(sysctlKey, rwndValue.toString());
+        }
+    }
+
+    /**
+     * Writes TCP buffer sizes to /sys/kernel/ipv4/tcp_[r/w]mem_[min/def/max]
+     * which maps to /proc/sys/net/ipv4/tcp_rmem and tcpwmem
+     *
+     * @param bufferSizes in the format of "readMin, readInitial, readMax,
+     *        writeMin, writeInitial, writeMax"
+     */
+    private void setBufferSize(String bufferSizes) {
+        try {
+            String[] values = bufferSizes.split(",");
+
+            if (values.length == 6) {
+              final String prefix = "/sys/kernel/ipv4/tcp_";
+                FileUtils.stringToFile(prefix + "rmem_min", values[0]);
+                FileUtils.stringToFile(prefix + "rmem_def", values[1]);
+                FileUtils.stringToFile(prefix + "rmem_max", values[2]);
+                FileUtils.stringToFile(prefix + "wmem_min", values[3]);
+                FileUtils.stringToFile(prefix + "wmem_def", values[4]);
+                FileUtils.stringToFile(prefix + "wmem_max", values[5]);
+            } else {
+                loge("Invalid buffersize string: " + bufferSizes);
+            }
+        } catch (IOException e) {
+            loge("Can't set tcp buffer sizes:" + e);
+        }
+    }
+
+    /**
+     * Adjust the per-process dns entries (net.dns<x>.<pid>) based
+     * on the highest priority active net which this process requested.
+     * If there aren't any, clear it out
+     */
+    private void reassessPidDns(int pid, boolean doBump)
+    {
+        if (VDBG) log("reassessPidDns for pid " + pid);
+        Integer myPid = new Integer(pid);
+        for(int i : mPriorityList) {
+            if (mNetConfigs[i].isDefault()) {
+                continue;
+            }
+            NetworkStateTracker nt = mNetTrackers[i];
+            if (nt.getNetworkInfo().isConnected() &&
+                    !nt.isTeardownRequested()) {
+                LinkProperties p = nt.getLinkProperties();
+                if (p == null) continue;
+                if (mNetRequestersPids[i].contains(myPid)) {
+                    try {
+                        mNetd.setDnsInterfaceForPid(p.getInterfaceName(), pid);
+                    } catch (Exception e) {
+                        Slog.e(TAG, "exception reasseses pid dns: " + e);
+                    }
+                    return;
+                }
+           }
+        }
+        // nothing found - delete
+        try {
+            mNetd.clearDnsInterfaceForPid(pid);
+        } catch (Exception e) {
+            Slog.e(TAG, "exception clear interface from pid: " + e);
+        }
+    }
+
+    private void flushVmDnsCache() {
+        /*
+         * Tell the VMs to toss their DNS caches
+         */
+        Intent intent = new Intent(Intent.ACTION_CLEAR_DNS_CACHE);
+        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+        /*
+         * Connectivity events can happen before boot has completed ...
+         */
+        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    // Caller must grab mDnsLock.
+    private void updateDnsLocked(String network, String iface,
+            Collection<InetAddress> dnses, String domains, boolean defaultDns) {
+        int last = 0;
+        if (dnses.size() == 0 && mDefaultDns != null) {
+            dnses = new ArrayList();
+            dnses.add(mDefaultDns);
+            if (DBG) {
+                loge("no dns provided for " + network + " - using " + mDefaultDns.getHostAddress());
+            }
+        }
+
+        try {
+            mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses), domains);
+            if (defaultDns) {
+                mNetd.setDefaultInterfaceForDns(iface);
+            }
+
+            for (InetAddress dns : dnses) {
+                ++last;
+                String key = "net.dns" + last;
+                String value = dns.getHostAddress();
+                SystemProperties.set(key, value);
+            }
+            for (int i = last + 1; i <= mNumDnsEntries; ++i) {
+                String key = "net.dns" + i;
+                SystemProperties.set(key, "");
+            }
+            mNumDnsEntries = last;
+        } catch (Exception e) {
+            loge("exception setting default dns interface: " + e);
+        }
+    }
+
+    private void handleDnsConfigurationChange(int netType) {
+        // add default net's dns entries
+        NetworkStateTracker nt = mNetTrackers[netType];
+        if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
+            LinkProperties p = nt.getLinkProperties();
+            if (p == null) return;
+            Collection<InetAddress> dnses = p.getDnses();
+            if (mNetConfigs[netType].isDefault()) {
+                String network = nt.getNetworkInfo().getTypeName();
+                synchronized (mDnsLock) {
+                    updateDnsLocked(network, p.getInterfaceName(), dnses, p.getDomains(), true);
+                }
+            } else {
+                try {
+                    mNetd.setDnsServersForInterface(p.getInterfaceName(),
+                            NetworkUtils.makeStrings(dnses), p.getDomains());
+                } catch (Exception e) {
+                    if (DBG) loge("exception setting dns servers: " + e);
+                }
+                // set per-pid dns for attached secondary nets
+                List<Integer> pids = mNetRequestersPids[netType];
+                for (Integer pid : pids) {
+                    try {
+                        mNetd.setDnsInterfaceForPid(p.getInterfaceName(), pid);
+                    } catch (Exception e) {
+                        Slog.e(TAG, "exception setting interface for pid: " + e);
+                    }
+                }
+            }
+            flushVmDnsCache();
+        }
+    }
+
+    private int getRestoreDefaultNetworkDelay(int networkType) {
+        String restoreDefaultNetworkDelayStr = SystemProperties.get(
+                NETWORK_RESTORE_DELAY_PROP_NAME);
+        if(restoreDefaultNetworkDelayStr != null &&
+                restoreDefaultNetworkDelayStr.length() != 0) {
+            try {
+                return Integer.valueOf(restoreDefaultNetworkDelayStr);
+            } catch (NumberFormatException e) {
+            }
+        }
+        // if the system property isn't set, use the value for the apn type
+        int ret = RESTORE_DEFAULT_NETWORK_DELAY;
+
+        if ((networkType <= ConnectivityManager.MAX_NETWORK_TYPE) &&
+                (mNetConfigs[networkType] != null)) {
+            ret = mNetConfigs[networkType].restoreTime;
+        }
+        return ret;
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump ConnectivityService " +
+                    "from from pid=" + Binder.getCallingPid() + ", uid=" +
+                    Binder.getCallingUid());
+            return;
+        }
+
+        // TODO: add locking to get atomic snapshot
+        pw.println();
+        for (int i = 0; i < mNetTrackers.length; i++) {
+            final NetworkStateTracker nst = mNetTrackers[i];
+            if (nst != null) {
+                pw.println("NetworkStateTracker for " + getNetworkTypeName(i) + ":");
+                pw.increaseIndent();
+                if (nst.getNetworkInfo().isConnected()) {
+                    pw.println("Active network: " + nst.getNetworkInfo().
+                            getTypeName());
+                }
+                pw.println(nst.getNetworkInfo());
+                pw.println(nst.getLinkProperties());
+                pw.println(nst);
+                pw.println();
+                pw.decreaseIndent();
+            }
+        }
+
+        pw.println("Network Requester Pids:");
+        pw.increaseIndent();
+        for (int net : mPriorityList) {
+            String pidString = net + ": ";
+            for (Integer pid : mNetRequestersPids[net]) {
+                pidString = pidString + pid.toString() + ", ";
+            }
+            pw.println(pidString);
+        }
+        pw.println();
+        pw.decreaseIndent();
+
+        pw.println("FeatureUsers:");
+        pw.increaseIndent();
+        for (Object requester : mFeatureUsers) {
+            pw.println(requester.toString());
+        }
+        pw.println();
+        pw.decreaseIndent();
+
+        synchronized (this) {
+            pw.println("NetworkTranstionWakeLock is currently " +
+                    (mNetTransitionWakeLock.isHeld() ? "" : "not ") + "held.");
+            pw.println("It was last requested for "+mNetTransitionWakeLockCausedBy);
+        }
+        pw.println();
+
+        mTethering.dump(fd, pw, args);
+
+        if (mInetLog != null) {
+            pw.println();
+            pw.println("Inet condition reports:");
+            pw.increaseIndent();
+            for(int i = 0; i < mInetLog.size(); i++) {
+                pw.println(mInetLog.get(i));
+            }
+            pw.decreaseIndent();
+        }
+    }
+
+    // must be stateless - things change under us.
+    private class NetworkStateTrackerHandler extends Handler {
+        public NetworkStateTrackerHandler(Looper looper) {
+            super(looper);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            NetworkInfo info;
+            switch (msg.what) {
+                case NetworkStateTracker.EVENT_STATE_CHANGED: {
+                    info = (NetworkInfo) msg.obj;
+                    NetworkInfo.State state = info.getState();
+
+                    if (VDBG || (state == NetworkInfo.State.CONNECTED) ||
+                            (state == NetworkInfo.State.DISCONNECTED) ||
+                            (state == NetworkInfo.State.SUSPENDED)) {
+                        log("ConnectivityChange for " +
+                            info.getTypeName() + ": " +
+                            state + "/" + info.getDetailedState());
+                    }
+
+                    // Since mobile has the notion of a network/apn that can be used for
+                    // provisioning we need to check every time we're connected as
+                    // CaptiveProtalTracker won't detected it because DCT doesn't report it
+                    // as connected as ACTION_ANY_DATA_CONNECTION_STATE_CHANGED instead its
+                    // reported as ACTION_DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN. Which
+                    // is received by MDST and sent here as EVENT_STATE_CHANGED.
+                    if (ConnectivityManager.isNetworkTypeMobile(info.getType())
+                            && (0 != Settings.Global.getInt(mContext.getContentResolver(),
+                                        Settings.Global.DEVICE_PROVISIONED, 0))
+                            && (((state == NetworkInfo.State.CONNECTED)
+                                    && (info.getType() == ConnectivityManager.TYPE_MOBILE))
+                                || info.isConnectedToProvisioningNetwork())) {
+                        log("ConnectivityChange checkMobileProvisioning for"
+                                + " TYPE_MOBILE or ProvisioningNetwork");
+                        checkMobileProvisioning(CheckMp.MAX_TIMEOUT_MS);
+                    }
+
+                    EventLogTags.writeConnectivityStateChanged(
+                            info.getType(), info.getSubtype(), info.getDetailedState().ordinal());
+
+                    if (info.getDetailedState() ==
+                            NetworkInfo.DetailedState.FAILED) {
+                        handleConnectionFailure(info);
+                    } else if (info.getDetailedState() ==
+                            DetailedState.CAPTIVE_PORTAL_CHECK) {
+                        handleCaptivePortalTrackerCheck(info);
+                    } else if (info.isConnectedToProvisioningNetwork()) {
+                        /**
+                         * TODO: Create ConnectivityManager.TYPE_MOBILE_PROVISIONING
+                         * for now its an in between network, its a network that
+                         * is actually a default network but we don't want it to be
+                         * announced as such to keep background applications from
+                         * trying to use it. It turns out that some still try so we
+                         * take the additional step of clearing any default routes
+                         * to the link that may have incorrectly setup by the lower
+                         * levels.
+                         */
+                        LinkProperties lp = getLinkProperties(info.getType());
+                        if (DBG) {
+                            log("EVENT_STATE_CHANGED: connected to provisioning network, lp=" + lp);
+                        }
+
+                        // Clear any default routes setup by the radio so
+                        // any activity by applications trying to use this
+                        // connection will fail until the provisioning network
+                        // is enabled.
+                        for (RouteInfo r : lp.getRoutes()) {
+                            removeRoute(lp, r, TO_DEFAULT_TABLE);
+                        }
+                    } else if (state == NetworkInfo.State.DISCONNECTED) {
+                        handleDisconnect(info);
+                    } else if (state == NetworkInfo.State.SUSPENDED) {
+                        // TODO: need to think this over.
+                        // the logic here is, handle SUSPENDED the same as
+                        // DISCONNECTED. The only difference being we are
+                        // broadcasting an intent with NetworkInfo that's
+                        // suspended. This allows the applications an
+                        // opportunity to handle DISCONNECTED and SUSPENDED
+                        // differently, or not.
+                        handleDisconnect(info);
+                    } else if (state == NetworkInfo.State.CONNECTED) {
+                        handleConnect(info);
+                    }
+                    if (mLockdownTracker != null) {
+                        mLockdownTracker.onNetworkInfoChanged(info);
+                    }
+                    break;
+                }
+                case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED: {
+                    info = (NetworkInfo) msg.obj;
+                    // TODO: Temporary allowing network configuration
+                    //       change not resetting sockets.
+                    //       @see bug/4455071
+                    handleConnectivityChange(info.getType(), false);
+                    break;
+                }
+                case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED: {
+                    info = (NetworkInfo) msg.obj;
+                    int type = info.getType();
+                    if (mNetConfigs[type].isDefault()) updateNetworkSettings(mNetTrackers[type]);
+                    break;
+                }
+            }
+        }
+    }
+
+    private class InternalHandler extends Handler {
+        public InternalHandler(Looper looper) {
+            super(looper);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            NetworkInfo info;
+            switch (msg.what) {
+                case EVENT_CLEAR_NET_TRANSITION_WAKELOCK: {
+                    String causedBy = null;
+                    synchronized (ConnectivityService.this) {
+                        if (msg.arg1 == mNetTransitionWakeLockSerialNumber &&
+                                mNetTransitionWakeLock.isHeld()) {
+                            mNetTransitionWakeLock.release();
+                            causedBy = mNetTransitionWakeLockCausedBy;
+                        }
+                    }
+                    if (causedBy != null) {
+                        log("NetTransition Wakelock for " + causedBy + " released by timeout");
+                    }
+                    break;
+                }
+                case EVENT_RESTORE_DEFAULT_NETWORK: {
+                    FeatureUser u = (FeatureUser)msg.obj;
+                    u.expire();
+                    break;
+                }
+                case EVENT_INET_CONDITION_CHANGE: {
+                    int netType = msg.arg1;
+                    int condition = msg.arg2;
+                    handleInetConditionChange(netType, condition);
+                    break;
+                }
+                case EVENT_INET_CONDITION_HOLD_END: {
+                    int netType = msg.arg1;
+                    int sequence = msg.arg2;
+                    handleInetConditionHoldEnd(netType, sequence);
+                    break;
+                }
+                case EVENT_SET_NETWORK_PREFERENCE: {
+                    int preference = msg.arg1;
+                    handleSetNetworkPreference(preference);
+                    break;
+                }
+                case EVENT_SET_MOBILE_DATA: {
+                    boolean enabled = (msg.arg1 == ENABLED);
+                    handleSetMobileData(enabled);
+                    break;
+                }
+                case EVENT_APPLY_GLOBAL_HTTP_PROXY: {
+                    handleDeprecatedGlobalHttpProxy();
+                    break;
+                }
+                case EVENT_SET_DEPENDENCY_MET: {
+                    boolean met = (msg.arg1 == ENABLED);
+                    handleSetDependencyMet(msg.arg2, met);
+                    break;
+                }
+                case EVENT_SEND_STICKY_BROADCAST_INTENT: {
+                    Intent intent = (Intent)msg.obj;
+                    sendStickyBroadcast(intent);
+                    break;
+                }
+                case EVENT_SET_POLICY_DATA_ENABLE: {
+                    final int networkType = msg.arg1;
+                    final boolean enabled = msg.arg2 == ENABLED;
+                    handleSetPolicyDataEnable(networkType, enabled);
+                    break;
+                }
+                case EVENT_VPN_STATE_CHANGED: {
+                    if (mLockdownTracker != null) {
+                        mLockdownTracker.onVpnStateChanged((NetworkInfo) msg.obj);
+                    }
+                    break;
+                }
+                case EVENT_ENABLE_FAIL_FAST_MOBILE_DATA: {
+                    int tag = mEnableFailFastMobileDataTag.get();
+                    if (msg.arg1 == tag) {
+                        MobileDataStateTracker mobileDst =
+                            (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE];
+                        if (mobileDst != null) {
+                            mobileDst.setEnableFailFastMobileData(msg.arg2);
+                        }
+                    } else {
+                        log("EVENT_ENABLE_FAIL_FAST_MOBILE_DATA: stale arg1:" + msg.arg1
+                                + " != tag:" + tag);
+                    }
+                    break;
+                }
+                case EVENT_SAMPLE_INTERVAL_ELAPSED: {
+                    handleNetworkSamplingTimeout();
+                    break;
+                }
+                case EVENT_PROXY_HAS_CHANGED: {
+                    handleApplyDefaultProxy((ProxyProperties)msg.obj);
+                    break;
+                }
+            }
+        }
+    }
+
+    // javadoc from interface
+    public int tether(String iface) {
+        enforceTetherChangePermission();
+
+        if (isTetheringSupported()) {
+            return mTethering.tether(iface);
+        } else {
+            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
+        }
+    }
+
+    // javadoc from interface
+    public int untether(String iface) {
+        enforceTetherChangePermission();
+
+        if (isTetheringSupported()) {
+            return mTethering.untether(iface);
+        } else {
+            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
+        }
+    }
+
+    // javadoc from interface
+    public int getLastTetherError(String iface) {
+        enforceTetherAccessPermission();
+
+        if (isTetheringSupported()) {
+            return mTethering.getLastTetherError(iface);
+        } else {
+            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
+        }
+    }
+
+    // TODO - proper iface API for selection by property, inspection, etc
+    public String[] getTetherableUsbRegexs() {
+        enforceTetherAccessPermission();
+        if (isTetheringSupported()) {
+            return mTethering.getTetherableUsbRegexs();
+        } else {
+            return new String[0];
+        }
+    }
+
+    public String[] getTetherableWifiRegexs() {
+        enforceTetherAccessPermission();
+        if (isTetheringSupported()) {
+            return mTethering.getTetherableWifiRegexs();
+        } else {
+            return new String[0];
+        }
+    }
+
+    public String[] getTetherableBluetoothRegexs() {
+        enforceTetherAccessPermission();
+        if (isTetheringSupported()) {
+            return mTethering.getTetherableBluetoothRegexs();
+        } else {
+            return new String[0];
+        }
+    }
+
+    public int setUsbTethering(boolean enable) {
+        enforceTetherChangePermission();
+        if (isTetheringSupported()) {
+            return mTethering.setUsbTethering(enable);
+        } else {
+            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
+        }
+    }
+
+    // TODO - move iface listing, queries, etc to new module
+    // javadoc from interface
+    public String[] getTetherableIfaces() {
+        enforceTetherAccessPermission();
+        return mTethering.getTetherableIfaces();
+    }
+
+    public String[] getTetheredIfaces() {
+        enforceTetherAccessPermission();
+        return mTethering.getTetheredIfaces();
+    }
+
+    public String[] getTetheringErroredIfaces() {
+        enforceTetherAccessPermission();
+        return mTethering.getErroredIfaces();
+    }
+
+    // if ro.tether.denied = true we default to no tethering
+    // gservices could set the secure setting to 1 though to enable it on a build where it
+    // had previously been turned off.
+    public boolean isTetheringSupported() {
+        enforceTetherAccessPermission();
+        int defaultVal = (SystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1);
+        boolean tetherEnabledInSettings = (Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.TETHER_SUPPORTED, defaultVal) != 0);
+        return tetherEnabledInSettings && ((mTethering.getTetherableUsbRegexs().length != 0 ||
+                mTethering.getTetherableWifiRegexs().length != 0 ||
+                mTethering.getTetherableBluetoothRegexs().length != 0) &&
+                mTethering.getUpstreamIfaceTypes().length != 0);
+    }
+
+    // An API NetworkStateTrackers can call when they lose their network.
+    // This will automatically be cleared after X seconds or a network becomes CONNECTED,
+    // whichever happens first.  The timer is started by the first caller and not
+    // restarted by subsequent callers.
+    public void requestNetworkTransitionWakelock(String forWhom) {
+        enforceConnectivityInternalPermission();
+        synchronized (this) {
+            if (mNetTransitionWakeLock.isHeld()) return;
+            mNetTransitionWakeLockSerialNumber++;
+            mNetTransitionWakeLock.acquire();
+            mNetTransitionWakeLockCausedBy = forWhom;
+        }
+        mHandler.sendMessageDelayed(mHandler.obtainMessage(
+                EVENT_CLEAR_NET_TRANSITION_WAKELOCK,
+                mNetTransitionWakeLockSerialNumber, 0),
+                mNetTransitionWakeLockTimeout);
+        return;
+    }
+
+    // 100 percent is full good, 0 is full bad.
+    public void reportInetCondition(int networkType, int percentage) {
+        if (VDBG) log("reportNetworkCondition(" + networkType + ", " + percentage + ")");
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.STATUS_BAR,
+                "ConnectivityService");
+
+        if (DBG) {
+            int pid = getCallingPid();
+            int uid = getCallingUid();
+            String s = pid + "(" + uid + ") reports inet is " +
+                (percentage > 50 ? "connected" : "disconnected") + " (" + percentage + ") on " +
+                "network Type " + networkType + " at " + GregorianCalendar.getInstance().getTime();
+            mInetLog.add(s);
+            while(mInetLog.size() > INET_CONDITION_LOG_MAX_SIZE) {
+                mInetLog.remove(0);
+            }
+        }
+        mHandler.sendMessage(mHandler.obtainMessage(
+            EVENT_INET_CONDITION_CHANGE, networkType, percentage));
+    }
+
+    private void handleInetConditionChange(int netType, int condition) {
+        if (mActiveDefaultNetwork == -1) {
+            if (DBG) log("handleInetConditionChange: no active default network - ignore");
+            return;
+        }
+        if (mActiveDefaultNetwork != netType) {
+            if (DBG) log("handleInetConditionChange: net=" + netType +
+                            " != default=" + mActiveDefaultNetwork + " - ignore");
+            return;
+        }
+        if (VDBG) {
+            log("handleInetConditionChange: net=" +
+                    netType + ", condition=" + condition +
+                    ",mActiveDefaultNetwork=" + mActiveDefaultNetwork);
+        }
+        mDefaultInetCondition = condition;
+        int delay;
+        if (mInetConditionChangeInFlight == false) {
+            if (VDBG) log("handleInetConditionChange: starting a change hold");
+            // setup a new hold to debounce this
+            if (mDefaultInetCondition > 50) {
+                delay = Settings.Global.getInt(mContext.getContentResolver(),
+                        Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, 500);
+            } else {
+                delay = Settings.Global.getInt(mContext.getContentResolver(),
+                        Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, 3000);
+            }
+            mInetConditionChangeInFlight = true;
+            mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_INET_CONDITION_HOLD_END,
+                    mActiveDefaultNetwork, mDefaultConnectionSequence), delay);
+        } else {
+            // we've set the new condition, when this hold ends that will get picked up
+            if (VDBG) log("handleInetConditionChange: currently in hold - not setting new end evt");
+        }
+    }
+
+    private void handleInetConditionHoldEnd(int netType, int sequence) {
+        if (DBG) {
+            log("handleInetConditionHoldEnd: net=" + netType +
+                    ", condition=" + mDefaultInetCondition +
+                    ", published condition=" + mDefaultInetConditionPublished);
+        }
+        mInetConditionChangeInFlight = false;
+
+        if (mActiveDefaultNetwork == -1) {
+            if (DBG) log("handleInetConditionHoldEnd: no active default network - ignoring");
+            return;
+        }
+        if (mDefaultConnectionSequence != sequence) {
+            if (DBG) log("handleInetConditionHoldEnd: event hold for obsolete network - ignoring");
+            return;
+        }
+        // TODO: Figure out why this optimization sometimes causes a
+        //       change in mDefaultInetCondition to be missed and the
+        //       UI to not be updated.
+        //if (mDefaultInetConditionPublished == mDefaultInetCondition) {
+        //    if (DBG) log("no change in condition - aborting");
+        //    return;
+        //}
+        NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
+        if (networkInfo.isConnected() == false) {
+            if (DBG) log("handleInetConditionHoldEnd: default network not connected - ignoring");
+            return;
+        }
+        mDefaultInetConditionPublished = mDefaultInetCondition;
+        sendInetConditionBroadcast(networkInfo);
+        return;
+    }
+
+    public ProxyProperties getProxy() {
+        // this information is already available as a world read/writable jvm property
+        // so this API change wouldn't have a benifit.  It also breaks the passing
+        // of proxy info to all the JVMs.
+        // enforceAccessPermission();
+        synchronized (mProxyLock) {
+            ProxyProperties ret = mGlobalProxy;
+            if ((ret == null) && !mDefaultProxyDisabled) ret = mDefaultProxy;
+            return ret;
+        }
+    }
+
+    public void setGlobalProxy(ProxyProperties proxyProperties) {
+        enforceConnectivityInternalPermission();
+
+        synchronized (mProxyLock) {
+            if (proxyProperties == mGlobalProxy) return;
+            if (proxyProperties != null && proxyProperties.equals(mGlobalProxy)) return;
+            if (mGlobalProxy != null && mGlobalProxy.equals(proxyProperties)) return;
+
+            String host = "";
+            int port = 0;
+            String exclList = "";
+            String pacFileUrl = "";
+            if (proxyProperties != null && (!TextUtils.isEmpty(proxyProperties.getHost()) ||
+                    !TextUtils.isEmpty(proxyProperties.getPacFileUrl()))) {
+                if (!proxyProperties.isValid()) {
+                    if (DBG)
+                        log("Invalid proxy properties, ignoring: " + proxyProperties.toString());
+                    return;
+                }
+                mGlobalProxy = new ProxyProperties(proxyProperties);
+                host = mGlobalProxy.getHost();
+                port = mGlobalProxy.getPort();
+                exclList = mGlobalProxy.getExclusionList();
+                if (proxyProperties.getPacFileUrl() != null) {
+                    pacFileUrl = proxyProperties.getPacFileUrl();
+                }
+            } else {
+                mGlobalProxy = null;
+            }
+            ContentResolver res = mContext.getContentResolver();
+            final long token = Binder.clearCallingIdentity();
+            try {
+                Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host);
+                Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port);
+                Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
+                        exclList);
+                Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        if (mGlobalProxy == null) {
+            proxyProperties = mDefaultProxy;
+        }
+        sendProxyBroadcast(proxyProperties);
+    }
+
+    private void loadGlobalProxy() {
+        ContentResolver res = mContext.getContentResolver();
+        String host = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST);
+        int port = Settings.Global.getInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, 0);
+        String exclList = Settings.Global.getString(res,
+                Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST);
+        String pacFileUrl = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC);
+        if (!TextUtils.isEmpty(host) || !TextUtils.isEmpty(pacFileUrl)) {
+            ProxyProperties proxyProperties;
+            if (!TextUtils.isEmpty(pacFileUrl)) {
+                proxyProperties = new ProxyProperties(pacFileUrl);
+            } else {
+                proxyProperties = new ProxyProperties(host, port, exclList);
+            }
+            if (!proxyProperties.isValid()) {
+                if (DBG) log("Invalid proxy properties, ignoring: " + proxyProperties.toString());
+                return;
+            }
+
+            synchronized (mProxyLock) {
+                mGlobalProxy = proxyProperties;
+            }
+        }
+    }
+
+    public ProxyProperties getGlobalProxy() {
+        // this information is already available as a world read/writable jvm property
+        // so this API change wouldn't have a benifit.  It also breaks the passing
+        // of proxy info to all the JVMs.
+        // enforceAccessPermission();
+        synchronized (mProxyLock) {
+            return mGlobalProxy;
+        }
+    }
+
+    private void handleApplyDefaultProxy(ProxyProperties proxy) {
+        if (proxy != null && TextUtils.isEmpty(proxy.getHost())
+                && TextUtils.isEmpty(proxy.getPacFileUrl())) {
+            proxy = null;
+        }
+        synchronized (mProxyLock) {
+            if (mDefaultProxy != null && mDefaultProxy.equals(proxy)) return;
+            if (mDefaultProxy == proxy) return; // catches repeated nulls
+            if (proxy != null &&  !proxy.isValid()) {
+                if (DBG) log("Invalid proxy properties, ignoring: " + proxy.toString());
+                return;
+            }
+            mDefaultProxy = proxy;
+
+            if (mGlobalProxy != null) return;
+            if (!mDefaultProxyDisabled) {
+                sendProxyBroadcast(proxy);
+            }
+        }
+    }
+
+    private void handleDeprecatedGlobalHttpProxy() {
+        String proxy = Settings.Global.getString(mContext.getContentResolver(),
+                Settings.Global.HTTP_PROXY);
+        if (!TextUtils.isEmpty(proxy)) {
+            String data[] = proxy.split(":");
+            if (data.length == 0) {
+                return;
+            }
+
+            String proxyHost =  data[0];
+            int proxyPort = 8080;
+            if (data.length > 1) {
+                try {
+                    proxyPort = Integer.parseInt(data[1]);
+                } catch (NumberFormatException e) {
+                    return;
+                }
+            }
+            ProxyProperties p = new ProxyProperties(data[0], proxyPort, "");
+            setGlobalProxy(p);
+        }
+    }
+
+    private void sendProxyBroadcast(ProxyProperties proxy) {
+        if (proxy == null) proxy = new ProxyProperties("", 0, "");
+        if (mPacManager.setCurrentProxyScriptUrl(proxy)) return;
+        if (DBG) log("sending Proxy Broadcast for " + proxy);
+        Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
+        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
+            Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        intent.putExtra(Proxy.EXTRA_PROXY_INFO, proxy);
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private static class SettingsObserver extends ContentObserver {
+        private int mWhat;
+        private Handler mHandler;
+        SettingsObserver(Handler handler, int what) {
+            super(handler);
+            mHandler = handler;
+            mWhat = what;
+        }
+
+        void observe(Context context) {
+            ContentResolver resolver = context.getContentResolver();
+            resolver.registerContentObserver(Settings.Global.getUriFor(
+                    Settings.Global.HTTP_PROXY), false, this);
+        }
+
+        @Override
+        public void onChange(boolean selfChange) {
+            mHandler.obtainMessage(mWhat).sendToTarget();
+        }
+    }
+
+    private static void log(String s) {
+        Slog.d(TAG, s);
+    }
+
+    private static void loge(String s) {
+        Slog.e(TAG, s);
+    }
+
+    int convertFeatureToNetworkType(int networkType, String feature) {
+        int usedNetworkType = networkType;
+
+        if(networkType == ConnectivityManager.TYPE_MOBILE) {
+            if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
+            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
+            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN) ||
+                    TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN_ALWAYS)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
+            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
+            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_FOTA)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_FOTA;
+            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_IMS)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_IMS;
+            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_CBS)) {
+                usedNetworkType = ConnectivityManager.TYPE_MOBILE_CBS;
+            } else {
+                Slog.e(TAG, "Can't match any mobile netTracker!");
+            }
+        } else if (networkType == ConnectivityManager.TYPE_WIFI) {
+            if (TextUtils.equals(feature, "p2p")) {
+                usedNetworkType = ConnectivityManager.TYPE_WIFI_P2P;
+            } else {
+                Slog.e(TAG, "Can't match any wifi netTracker!");
+            }
+        } else {
+            Slog.e(TAG, "Unexpected network type");
+        }
+        return usedNetworkType;
+    }
+
+    private static <T> T checkNotNull(T value, String message) {
+        if (value == null) {
+            throw new NullPointerException(message);
+        }
+        return value;
+    }
+
+    /**
+     * Protect a socket from VPN routing rules. This method is used by
+     * VpnBuilder and not available in ConnectivityManager. Permissions
+     * are checked in Vpn class.
+     * @hide
+     */
+    @Override
+    public boolean protectVpn(ParcelFileDescriptor socket) {
+        throwIfLockdownEnabled();
+        try {
+            int type = mActiveDefaultNetwork;
+            int user = UserHandle.getUserId(Binder.getCallingUid());
+            if (ConnectivityManager.isNetworkTypeValid(type) && mNetTrackers[type] != null) {
+                synchronized(mVpns) {
+                    mVpns.get(user).protect(socket);
+                }
+                return true;
+            }
+        } catch (Exception e) {
+            // ignore
+        } finally {
+            try {
+                socket.close();
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Prepare for a VPN application. This method is used by VpnDialogs
+     * and not available in ConnectivityManager. Permissions are checked
+     * in Vpn class.
+     * @hide
+     */
+    @Override
+    public boolean prepareVpn(String oldPackage, String newPackage) {
+        throwIfLockdownEnabled();
+        int user = UserHandle.getUserId(Binder.getCallingUid());
+        synchronized(mVpns) {
+            return mVpns.get(user).prepare(oldPackage, newPackage);
+        }
+    }
+
+    @Override
+    public void markSocketAsUser(ParcelFileDescriptor socket, int uid) {
+        enforceMarkNetworkSocketPermission();
+        final long token = Binder.clearCallingIdentity();
+        try {
+            int mark = mNetd.getMarkForUid(uid);
+            // Clear the mark on the socket if no mark is needed to prevent socket reuse issues
+            if (mark == -1) {
+                mark = 0;
+            }
+            NetworkUtils.markSocket(socket.getFd(), mark);
+        } catch (RemoteException e) {
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    /**
+     * Configure a TUN interface and return its file descriptor. Parameters
+     * are encoded and opaque to this class. This method is used by VpnBuilder
+     * and not available in ConnectivityManager. Permissions are checked in
+     * Vpn class.
+     * @hide
+     */
+    @Override
+    public ParcelFileDescriptor establishVpn(VpnConfig config) {
+        throwIfLockdownEnabled();
+        int user = UserHandle.getUserId(Binder.getCallingUid());
+        synchronized(mVpns) {
+            return mVpns.get(user).establish(config);
+        }
+    }
+
+    /**
+     * Start legacy VPN, controlling native daemons as needed. Creates a
+     * secondary thread to perform connection work, returning quickly.
+     */
+    @Override
+    public void startLegacyVpn(VpnProfile profile) {
+        throwIfLockdownEnabled();
+        final LinkProperties egress = getActiveLinkProperties();
+        if (egress == null) {
+            throw new IllegalStateException("Missing active network connection");
+        }
+        int user = UserHandle.getUserId(Binder.getCallingUid());
+        synchronized(mVpns) {
+            mVpns.get(user).startLegacyVpn(profile, mKeyStore, egress);
+        }
+    }
+
+    /**
+     * Return the information of the ongoing legacy VPN. This method is used
+     * by VpnSettings and not available in ConnectivityManager. Permissions
+     * are checked in Vpn class.
+     * @hide
+     */
+    @Override
+    public LegacyVpnInfo getLegacyVpnInfo() {
+        throwIfLockdownEnabled();
+        int user = UserHandle.getUserId(Binder.getCallingUid());
+        synchronized(mVpns) {
+            return mVpns.get(user).getLegacyVpnInfo();
+        }
+    }
+
+    /**
+     * Returns the information of the ongoing VPN. This method is used by VpnDialogs and
+     * not available in ConnectivityManager.
+     * Permissions are checked in Vpn class.
+     * @hide
+     */
+    @Override
+    public VpnConfig getVpnConfig() {
+        int user = UserHandle.getUserId(Binder.getCallingUid());
+        synchronized(mVpns) {
+            return mVpns.get(user).getVpnConfig();
+        }
+    }
+
+    /**
+     * Callback for VPN subsystem. Currently VPN is not adapted to the service
+     * through NetworkStateTracker since it works differently. For example, it
+     * needs to override DNS servers but never takes the default routes. It
+     * relies on another data network, and it could keep existing connections
+     * alive after reconnecting, switching between networks, or even resuming
+     * from deep sleep. Calls from applications should be done synchronously
+     * to avoid race conditions. As these are all hidden APIs, refactoring can
+     * be done whenever a better abstraction is developed.
+     */
+    public class VpnCallback {
+        private VpnCallback() {
+        }
+
+        public void onStateChanged(NetworkInfo info) {
+            mHandler.obtainMessage(EVENT_VPN_STATE_CHANGED, info).sendToTarget();
+        }
+
+        public void override(String iface, List<String> dnsServers, List<String> searchDomains) {
+            if (dnsServers == null) {
+                restore();
+                return;
+            }
+
+            // Convert DNS servers into addresses.
+            List<InetAddress> addresses = new ArrayList<InetAddress>();
+            for (String address : dnsServers) {
+                // Double check the addresses and remove invalid ones.
+                try {
+                    addresses.add(InetAddress.parseNumericAddress(address));
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
+            if (addresses.isEmpty()) {
+                restore();
+                return;
+            }
+
+            // Concatenate search domains into a string.
+            StringBuilder buffer = new StringBuilder();
+            if (searchDomains != null) {
+                for (String domain : searchDomains) {
+                    buffer.append(domain).append(' ');
+                }
+            }
+            String domains = buffer.toString().trim();
+
+            // Apply DNS changes.
+            synchronized (mDnsLock) {
+                updateDnsLocked("VPN", iface, addresses, domains, false);
+            }
+
+            // Temporarily disable the default proxy (not global).
+            synchronized (mProxyLock) {
+                mDefaultProxyDisabled = true;
+                if (mGlobalProxy == null && mDefaultProxy != null) {
+                    sendProxyBroadcast(null);
+                }
+            }
+
+            // TODO: support proxy per network.
+        }
+
+        public void restore() {
+            synchronized (mProxyLock) {
+                mDefaultProxyDisabled = false;
+                if (mGlobalProxy == null && mDefaultProxy != null) {
+                    sendProxyBroadcast(mDefaultProxy);
+                }
+            }
+        }
+
+        public void protect(ParcelFileDescriptor socket) {
+            try {
+                final int mark = mNetd.getMarkForProtect();
+                NetworkUtils.markSocket(socket.getFd(), mark);
+            } catch (RemoteException e) {
+            }
+        }
+
+        public void setRoutes(String interfaze, List<RouteInfo> routes) {
+            for (RouteInfo route : routes) {
+                try {
+                    mNetd.setMarkedForwardingRoute(interfaze, route);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+
+        public void setMarkedForwarding(String interfaze) {
+            try {
+                mNetd.setMarkedForwarding(interfaze);
+            } catch (RemoteException e) {
+            }
+        }
+
+        public void clearMarkedForwarding(String interfaze) {
+            try {
+                mNetd.clearMarkedForwarding(interfaze);
+            } catch (RemoteException e) {
+            }
+        }
+
+        public void addUserForwarding(String interfaze, int uid, boolean forwardDns) {
+            int uidStart = uid * UserHandle.PER_USER_RANGE;
+            int uidEnd = uidStart + UserHandle.PER_USER_RANGE - 1;
+            addUidForwarding(interfaze, uidStart, uidEnd, forwardDns);
+        }
+
+        public void clearUserForwarding(String interfaze, int uid, boolean forwardDns) {
+            int uidStart = uid * UserHandle.PER_USER_RANGE;
+            int uidEnd = uidStart + UserHandle.PER_USER_RANGE - 1;
+            clearUidForwarding(interfaze, uidStart, uidEnd, forwardDns);
+        }
+
+        public void addUidForwarding(String interfaze, int uidStart, int uidEnd,
+                boolean forwardDns) {
+            try {
+                mNetd.setUidRangeRoute(interfaze,uidStart, uidEnd);
+                if (forwardDns) mNetd.setDnsInterfaceForUidRange(interfaze, uidStart, uidEnd);
+            } catch (RemoteException e) {
+            }
+
+        }
+
+        public void clearUidForwarding(String interfaze, int uidStart, int uidEnd,
+                boolean forwardDns) {
+            try {
+                mNetd.clearUidRangeRoute(interfaze, uidStart, uidEnd);
+                if (forwardDns) mNetd.clearDnsInterfaceForUidRange(uidStart, uidEnd);
+            } catch (RemoteException e) {
+            }
+
+        }
+    }
+
+    @Override
+    public boolean updateLockdownVpn() {
+        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+            Slog.w(TAG, "Lockdown VPN only available to AID_SYSTEM");
+            return false;
+        }
+
+        // Tear down existing lockdown if profile was removed
+        mLockdownEnabled = LockdownVpnTracker.isEnabled();
+        if (mLockdownEnabled) {
+            if (!mKeyStore.isUnlocked()) {
+                Slog.w(TAG, "KeyStore locked; unable to create LockdownTracker");
+                return false;
+            }
+
+            final String profileName = new String(mKeyStore.get(Credentials.LOCKDOWN_VPN));
+            final VpnProfile profile = VpnProfile.decode(
+                    profileName, mKeyStore.get(Credentials.VPN + profileName));
+            int user = UserHandle.getUserId(Binder.getCallingUid());
+            synchronized(mVpns) {
+                setLockdownTracker(new LockdownVpnTracker(mContext, mNetd, this, mVpns.get(user),
+                            profile));
+            }
+        } else {
+            setLockdownTracker(null);
+        }
+
+        return true;
+    }
+
+    /**
+     * Internally set new {@link LockdownVpnTracker}, shutting down any existing
+     * {@link LockdownVpnTracker}. Can be {@code null} to disable lockdown.
+     */
+    private void setLockdownTracker(LockdownVpnTracker tracker) {
+        // Shutdown any existing tracker
+        final LockdownVpnTracker existing = mLockdownTracker;
+        mLockdownTracker = null;
+        if (existing != null) {
+            existing.shutdown();
+        }
+
+        try {
+            if (tracker != null) {
+                mNetd.setFirewallEnabled(true);
+                mNetd.setFirewallInterfaceRule("lo", true);
+                mLockdownTracker = tracker;
+                mLockdownTracker.init();
+            } else {
+                mNetd.setFirewallEnabled(false);
+            }
+        } catch (RemoteException e) {
+            // ignored; NMS lives inside system_server
+        }
+    }
+
+    private void throwIfLockdownEnabled() {
+        if (mLockdownEnabled) {
+            throw new IllegalStateException("Unavailable in lockdown mode");
+        }
+    }
+
+    public void supplyMessenger(int networkType, Messenger messenger) {
+        enforceConnectivityInternalPermission();
+
+        if (isNetworkTypeValid(networkType) && mNetTrackers[networkType] != null) {
+            mNetTrackers[networkType].supplyMessenger(messenger);
+        }
+    }
+
+    public int findConnectionTypeForIface(String iface) {
+        enforceConnectivityInternalPermission();
+
+        if (TextUtils.isEmpty(iface)) return ConnectivityManager.TYPE_NONE;
+        for (NetworkStateTracker tracker : mNetTrackers) {
+            if (tracker != null) {
+                LinkProperties lp = tracker.getLinkProperties();
+                if (lp != null && iface.equals(lp.getInterfaceName())) {
+                    return tracker.getNetworkInfo().getType();
+                }
+            }
+        }
+        return ConnectivityManager.TYPE_NONE;
+    }
+
+    /**
+     * Have mobile data fail fast if enabled.
+     *
+     * @param enabled DctConstants.ENABLED/DISABLED
+     */
+    private void setEnableFailFastMobileData(int enabled) {
+        int tag;
+
+        if (enabled == DctConstants.ENABLED) {
+            tag = mEnableFailFastMobileDataTag.incrementAndGet();
+        } else {
+            tag = mEnableFailFastMobileDataTag.get();
+        }
+        mHandler.sendMessage(mHandler.obtainMessage(EVENT_ENABLE_FAIL_FAST_MOBILE_DATA, tag,
+                         enabled));
+    }
+
+    private boolean isMobileDataStateTrackerReady() {
+        MobileDataStateTracker mdst =
+                (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
+        return (mdst != null) && (mdst.isReady());
+    }
+
+    /**
+     * The ResultReceiver resultCode for checkMobileProvisioning (CMP_RESULT_CODE)
+     */
+
+    /**
+     * No connection was possible to the network.
+     * This is NOT a warm sim.
+     */
+    private static final int CMP_RESULT_CODE_NO_CONNECTION = 0;
+
+    /**
+     * A connection was made to the internet, all is well.
+     * This is NOT a warm sim.
+     */
+    private static final int CMP_RESULT_CODE_CONNECTABLE = 1;
+
+    /**
+     * A connection was made but no dns server was available to resolve a name to address.
+     * This is NOT a warm sim since provisioning network is supported.
+     */
+    private static final int CMP_RESULT_CODE_NO_DNS = 2;
+
+    /**
+     * A connection was made but could not open a TCP connection.
+     * This is NOT a warm sim since provisioning network is supported.
+     */
+    private static final int CMP_RESULT_CODE_NO_TCP_CONNECTION = 3;
+
+    /**
+     * A connection was made but there was a redirection, we appear to be in walled garden.
+     * This is an indication of a warm sim on a mobile network such as T-Mobile.
+     */
+    private static final int CMP_RESULT_CODE_REDIRECTED = 4;
+
+    /**
+     * The mobile network is a provisioning network.
+     * This is an indication of a warm sim on a mobile network such as AT&T.
+     */
+    private static final int CMP_RESULT_CODE_PROVISIONING_NETWORK = 5;
+
+    private AtomicBoolean mIsCheckingMobileProvisioning = new AtomicBoolean(false);
+
+    @Override
+    public int checkMobileProvisioning(int suggestedTimeOutMs) {
+        int timeOutMs = -1;
+        if (DBG) log("checkMobileProvisioning: E suggestedTimeOutMs=" + suggestedTimeOutMs);
+        enforceConnectivityInternalPermission();
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            timeOutMs = suggestedTimeOutMs;
+            if (suggestedTimeOutMs > CheckMp.MAX_TIMEOUT_MS) {
+                timeOutMs = CheckMp.MAX_TIMEOUT_MS;
+            }
+
+            // Check that mobile networks are supported
+            if (!isNetworkSupported(ConnectivityManager.TYPE_MOBILE)
+                    || !isNetworkSupported(ConnectivityManager.TYPE_MOBILE_HIPRI)) {
+                if (DBG) log("checkMobileProvisioning: X no mobile network");
+                return timeOutMs;
+            }
+
+            // If we're already checking don't do it again
+            // TODO: Add a queue of results...
+            if (mIsCheckingMobileProvisioning.getAndSet(true)) {
+                if (DBG) log("checkMobileProvisioning: X already checking ignore for the moment");
+                return timeOutMs;
+            }
+
+            // Start off with mobile notification off
+            setProvNotificationVisible(false, ConnectivityManager.TYPE_MOBILE_HIPRI, null, null);
+
+            CheckMp checkMp = new CheckMp(mContext, this);
+            CheckMp.CallBack cb = new CheckMp.CallBack() {
+                @Override
+                void onComplete(Integer result) {
+                    if (DBG) log("CheckMp.onComplete: result=" + result);
+                    NetworkInfo ni =
+                            mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI].getNetworkInfo();
+                    switch(result) {
+                        case CMP_RESULT_CODE_CONNECTABLE:
+                        case CMP_RESULT_CODE_NO_CONNECTION:
+                        case CMP_RESULT_CODE_NO_DNS:
+                        case CMP_RESULT_CODE_NO_TCP_CONNECTION: {
+                            if (DBG) log("CheckMp.onComplete: ignore, connected or no connection");
+                            break;
+                        }
+                        case CMP_RESULT_CODE_REDIRECTED: {
+                            if (DBG) log("CheckMp.onComplete: warm sim");
+                            String url = getMobileProvisioningUrl();
+                            if (TextUtils.isEmpty(url)) {
+                                url = getMobileRedirectedProvisioningUrl();
+                            }
+                            if (TextUtils.isEmpty(url) == false) {
+                                if (DBG) log("CheckMp.onComplete: warm (redirected), url=" + url);
+                                setProvNotificationVisible(true,
+                                        ConnectivityManager.TYPE_MOBILE_HIPRI, ni.getExtraInfo(),
+                                        url);
+                            } else {
+                                if (DBG) log("CheckMp.onComplete: warm (redirected), no url");
+                            }
+                            break;
+                        }
+                        case CMP_RESULT_CODE_PROVISIONING_NETWORK: {
+                            String url = getMobileProvisioningUrl();
+                            if (TextUtils.isEmpty(url) == false) {
+                                if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), url=" + url);
+                                setProvNotificationVisible(true,
+                                        ConnectivityManager.TYPE_MOBILE_HIPRI, ni.getExtraInfo(),
+                                        url);
+                            } else {
+                                if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), no url");
+                            }
+                            break;
+                        }
+                        default: {
+                            loge("CheckMp.onComplete: ignore unexpected result=" + result);
+                            break;
+                        }
+                    }
+                    mIsCheckingMobileProvisioning.set(false);
+                }
+            };
+            CheckMp.Params params =
+                    new CheckMp.Params(checkMp.getDefaultUrl(), timeOutMs, cb);
+            if (DBG) log("checkMobileProvisioning: params=" + params);
+            checkMp.execute(params);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+            if (DBG) log("checkMobileProvisioning: X");
+        }
+        return timeOutMs;
+    }
+
+    static class CheckMp extends
+            AsyncTask<CheckMp.Params, Void, Integer> {
+        private static final String CHECKMP_TAG = "CheckMp";
+
+        // adb shell setprop persist.checkmp.testfailures 1 to enable testing failures
+        private static boolean mTestingFailures;
+
+        // Choosing 4 loops as half of them will use HTTPS and the other half HTTP
+        private static final int MAX_LOOPS = 4;
+
+        // Number of milli-seconds to complete all of the retires
+        public static final int MAX_TIMEOUT_MS =  60000;
+
+        // The socket should retry only 5 seconds, the default is longer
+        private static final int SOCKET_TIMEOUT_MS = 5000;
+
+        // Sleep time for network errors
+        private static final int NET_ERROR_SLEEP_SEC = 3;
+
+        // Sleep time for network route establishment
+        private static final int NET_ROUTE_ESTABLISHMENT_SLEEP_SEC = 3;
+
+        // Short sleep time for polling :(
+        private static final int POLLING_SLEEP_SEC = 1;
+
+        private Context mContext;
+        private ConnectivityService mCs;
+        private TelephonyManager mTm;
+        private Params mParams;
+
+        /**
+         * Parameters for AsyncTask.execute
+         */
+        static class Params {
+            private String mUrl;
+            private long mTimeOutMs;
+            private CallBack mCb;
+
+            Params(String url, long timeOutMs, CallBack cb) {
+                mUrl = url;
+                mTimeOutMs = timeOutMs;
+                mCb = cb;
+            }
+
+            @Override
+            public String toString() {
+                return "{" + " url=" + mUrl + " mTimeOutMs=" + mTimeOutMs + " mCb=" + mCb + "}";
+            }
+        }
+
+        // As explained to me by Brian Carlstrom and Kenny Root, Certificates can be
+        // issued by name or ip address, for Google its by name so when we construct
+        // this HostnameVerifier we'll pass the original Uri and use it to verify
+        // the host. If the host name in the original uril fails we'll test the
+        // hostname parameter just incase things change.
+        static class CheckMpHostnameVerifier implements HostnameVerifier {
+            Uri mOrgUri;
+
+            CheckMpHostnameVerifier(Uri orgUri) {
+                mOrgUri = orgUri;
+            }
+
+            @Override
+            public boolean verify(String hostname, SSLSession session) {
+                HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
+                String orgUriHost = mOrgUri.getHost();
+                boolean retVal = hv.verify(orgUriHost, session) || hv.verify(hostname, session);
+                if (DBG) {
+                    log("isMobileOk: hostnameVerify retVal=" + retVal + " hostname=" + hostname
+                        + " orgUriHost=" + orgUriHost);
+                }
+                return retVal;
+            }
+        }
+
+        /**
+         * The call back object passed in Params. onComplete will be called
+         * on the main thread.
+         */
+        abstract static class CallBack {
+            // Called on the main thread.
+            abstract void onComplete(Integer result);
+        }
+
+        public CheckMp(Context context, ConnectivityService cs) {
+            if (Build.IS_DEBUGGABLE) {
+                mTestingFailures =
+                        SystemProperties.getInt("persist.checkmp.testfailures", 0) == 1;
+            } else {
+                mTestingFailures = false;
+            }
+
+            mContext = context;
+            mCs = cs;
+
+            // Setup access to TelephonyService we'll be using.
+            mTm = (TelephonyManager) mContext.getSystemService(
+                    Context.TELEPHONY_SERVICE);
+        }
+
+        /**
+         * Get the default url to use for the test.
+         */
+        public String getDefaultUrl() {
+            // See http://go/clientsdns for usage approval
+            String server = Settings.Global.getString(mContext.getContentResolver(),
+                    Settings.Global.CAPTIVE_PORTAL_SERVER);
+            if (server == null) {
+                server = "clients3.google.com";
+            }
+            return "http://" + server + "/generate_204";
+        }
+
+        /**
+         * Detect if its possible to connect to the http url. DNS based detection techniques
+         * do not work at all hotspots. The best way to check is to perform a request to
+         * a known address that fetches the data we expect.
+         */
+        private synchronized Integer isMobileOk(Params params) {
+            Integer result = CMP_RESULT_CODE_NO_CONNECTION;
+            Uri orgUri = Uri.parse(params.mUrl);
+            Random rand = new Random();
+            mParams = params;
+
+            if (mCs.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
+                result = CMP_RESULT_CODE_NO_CONNECTION;
+                log("isMobileOk: X not mobile capable result=" + result);
+                return result;
+            }
+
+            // See if we've already determined we've got a provisioning connection,
+            // if so we don't need to do anything active.
+            MobileDataStateTracker mdstDefault = (MobileDataStateTracker)
+                    mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE];
+            boolean isDefaultProvisioning = mdstDefault.isProvisioningNetwork();
+            log("isMobileOk: isDefaultProvisioning=" + isDefaultProvisioning);
+
+            MobileDataStateTracker mdstHipri = (MobileDataStateTracker)
+                    mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
+            boolean isHipriProvisioning = mdstHipri.isProvisioningNetwork();
+            log("isMobileOk: isHipriProvisioning=" + isHipriProvisioning);
+
+            if (isDefaultProvisioning || isHipriProvisioning) {
+                result = CMP_RESULT_CODE_PROVISIONING_NETWORK;
+                log("isMobileOk: X default || hipri is provisioning result=" + result);
+                return result;
+            }
+
+            try {
+                // Continue trying to connect until time has run out
+                long endTime = SystemClock.elapsedRealtime() + params.mTimeOutMs;
+
+                if (!mCs.isMobileDataStateTrackerReady()) {
+                    // Wait for MobileDataStateTracker to be ready.
+                    if (DBG) log("isMobileOk: mdst is not ready");
+                    while(SystemClock.elapsedRealtime() < endTime) {
+                        if (mCs.isMobileDataStateTrackerReady()) {
+                            // Enable fail fast as we'll do retries here and use a
+                            // hipri connection so the default connection stays active.
+                            if (DBG) log("isMobileOk: mdst ready, enable fail fast of mobile data");
+                            mCs.setEnableFailFastMobileData(DctConstants.ENABLED);
+                            break;
+                        }
+                        sleep(POLLING_SLEEP_SEC);
+                    }
+                }
+
+                log("isMobileOk: start hipri url=" + params.mUrl);
+
+                // First wait until we can start using hipri
+                Binder binder = new Binder();
+                while(SystemClock.elapsedRealtime() < endTime) {
+                    int ret = mCs.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+                            Phone.FEATURE_ENABLE_HIPRI, binder);
+                    if ((ret == PhoneConstants.APN_ALREADY_ACTIVE)
+                        || (ret == PhoneConstants.APN_REQUEST_STARTED)) {
+                            log("isMobileOk: hipri started");
+                            break;
+                    }
+                    if (VDBG) log("isMobileOk: hipri not started yet");
+                    result = CMP_RESULT_CODE_NO_CONNECTION;
+                    sleep(POLLING_SLEEP_SEC);
+                }
+
+                // Continue trying to connect until time has run out
+                while(SystemClock.elapsedRealtime() < endTime) {
+                    try {
+                        // Wait for hipri to connect.
+                        // TODO: Don't poll and handle situation where hipri fails
+                        // because default is retrying. See b/9569540
+                        NetworkInfo.State state = mCs
+                                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI).getState();
+                        if (state != NetworkInfo.State.CONNECTED) {
+                            if (true/*VDBG*/) {
+                                log("isMobileOk: not connected ni=" +
+                                    mCs.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI));
+                            }
+                            sleep(POLLING_SLEEP_SEC);
+                            result = CMP_RESULT_CODE_NO_CONNECTION;
+                            continue;
+                        }
+
+                        // Hipri has started check if this is a provisioning url
+                        MobileDataStateTracker mdst = (MobileDataStateTracker)
+                                mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
+                        if (mdst.isProvisioningNetwork()) {
+                            result = CMP_RESULT_CODE_PROVISIONING_NETWORK;
+                            if (DBG) log("isMobileOk: X isProvisioningNetwork result=" + result);
+                            return result;
+                        } else {
+                            if (DBG) log("isMobileOk: isProvisioningNetwork is false, continue");
+                        }
+
+                        // Get of the addresses associated with the url host. We need to use the
+                        // address otherwise HttpURLConnection object will use the name to get
+                        // the addresses and will try every address but that will bypass the
+                        // route to host we setup and the connection could succeed as the default
+                        // interface might be connected to the internet via wifi or other interface.
+                        InetAddress[] addresses;
+                        try {
+                            addresses = InetAddress.getAllByName(orgUri.getHost());
+                        } catch (UnknownHostException e) {
+                            result = CMP_RESULT_CODE_NO_DNS;
+                            log("isMobileOk: X UnknownHostException result=" + result);
+                            return result;
+                        }
+                        log("isMobileOk: addresses=" + inetAddressesToString(addresses));
+
+                        // Get the type of addresses supported by this link
+                        LinkProperties lp = mCs.getLinkProperties(
+                                ConnectivityManager.TYPE_MOBILE_HIPRI);
+                        boolean linkHasIpv4 = lp.hasIPv4Address();
+                        boolean linkHasIpv6 = lp.hasIPv6Address();
+                        log("isMobileOk: linkHasIpv4=" + linkHasIpv4
+                                + " linkHasIpv6=" + linkHasIpv6);
+
+                        final ArrayList<InetAddress> validAddresses =
+                                new ArrayList<InetAddress>(addresses.length);
+
+                        for (InetAddress addr : addresses) {
+                            if (((addr instanceof Inet4Address) && linkHasIpv4) ||
+                                    ((addr instanceof Inet6Address) && linkHasIpv6)) {
+                                validAddresses.add(addr);
+                            }
+                        }
+
+                        if (validAddresses.size() == 0) {
+                            return CMP_RESULT_CODE_NO_CONNECTION;
+                        }
+
+                        int addrTried = 0;
+                        while (true) {
+                            // Loop through at most MAX_LOOPS valid addresses or until
+                            // we run out of time
+                            if (addrTried++ >= MAX_LOOPS) {
+                                log("isMobileOk: too many loops tried - giving up");
+                                break;
+                            }
+                            if (SystemClock.elapsedRealtime() >= endTime) {
+                                log("isMobileOk: spend too much time - giving up");
+                                break;
+                            }
+
+                            InetAddress hostAddr = validAddresses.get(rand.nextInt(
+                                    validAddresses.size()));
+
+                            // Make a route to host so we check the specific interface.
+                            if (mCs.requestRouteToHostAddress(ConnectivityManager.TYPE_MOBILE_HIPRI,
+                                    hostAddr.getAddress(), null)) {
+                                // Wait a short time to be sure the route is established ??
+                                log("isMobileOk:"
+                                        + " wait to establish route to hostAddr=" + hostAddr);
+                                sleep(NET_ROUTE_ESTABLISHMENT_SLEEP_SEC);
+                            } else {
+                                log("isMobileOk:"
+                                        + " could not establish route to hostAddr=" + hostAddr);
+                                // Wait a short time before the next attempt
+                                sleep(NET_ERROR_SLEEP_SEC);
+                                continue;
+                            }
+
+                            // Rewrite the url to have numeric address to use the specific route
+                            // using http for half the attempts and https for the other half.
+                            // Doing https first and http second as on a redirected walled garden
+                            // such as t-mobile uses we get a SocketTimeoutException: "SSL
+                            // handshake timed out" which we declare as
+                            // CMP_RESULT_CODE_NO_TCP_CONNECTION. We could change this, but by
+                            // having http second we will be using logic used for some time.
+                            URL newUrl;
+                            String scheme = (addrTried <= (MAX_LOOPS/2)) ? "https" : "http";
+                            newUrl = new URL(scheme, hostAddr.getHostAddress(),
+                                        orgUri.getPath());
+                            log("isMobileOk: newUrl=" + newUrl);
+
+                            HttpURLConnection urlConn = null;
+                            try {
+                                // Open the connection set the request headers and get the response
+                                urlConn = (HttpURLConnection)newUrl.openConnection(
+                                        java.net.Proxy.NO_PROXY);
+                                if (scheme.equals("https")) {
+                                    ((HttpsURLConnection)urlConn).setHostnameVerifier(
+                                            new CheckMpHostnameVerifier(orgUri));
+                                }
+                                urlConn.setInstanceFollowRedirects(false);
+                                urlConn.setConnectTimeout(SOCKET_TIMEOUT_MS);
+                                urlConn.setReadTimeout(SOCKET_TIMEOUT_MS);
+                                urlConn.setUseCaches(false);
+                                urlConn.setAllowUserInteraction(false);
+                                // Set the "Connection" to "Close" as by default "Keep-Alive"
+                                // is used which is useless in this case.
+                                urlConn.setRequestProperty("Connection", "close");
+                                int responseCode = urlConn.getResponseCode();
+
+                                // For debug display the headers
+                                Map<String, List<String>> headers = urlConn.getHeaderFields();
+                                log("isMobileOk: headers=" + headers);
+
+                                // Close the connection
+                                urlConn.disconnect();
+                                urlConn = null;
+
+                                if (mTestingFailures) {
+                                    // Pretend no connection, this tests using http and https
+                                    result = CMP_RESULT_CODE_NO_CONNECTION;
+                                    log("isMobileOk: TESTING_FAILURES, pretend no connction");
+                                    continue;
+                                }
+
+                                if (responseCode == 204) {
+                                    // Return
+                                    result = CMP_RESULT_CODE_CONNECTABLE;
+                                    log("isMobileOk: X got expected responseCode=" + responseCode
+                                            + " result=" + result);
+                                    return result;
+                                } else {
+                                    // Retry to be sure this was redirected, we've gotten
+                                    // occasions where a server returned 200 even though
+                                    // the device didn't have a "warm" sim.
+                                    log("isMobileOk: not expected responseCode=" + responseCode);
+                                    // TODO - it would be nice in the single-address case to do
+                                    // another DNS resolve here, but flushing the cache is a bit
+                                    // heavy-handed.
+                                    result = CMP_RESULT_CODE_REDIRECTED;
+                                }
+                            } catch (Exception e) {
+                                log("isMobileOk: HttpURLConnection Exception" + e);
+                                result = CMP_RESULT_CODE_NO_TCP_CONNECTION;
+                                if (urlConn != null) {
+                                    urlConn.disconnect();
+                                    urlConn = null;
+                                }
+                                sleep(NET_ERROR_SLEEP_SEC);
+                                continue;
+                            }
+                        }
+                        log("isMobileOk: X loops|timed out result=" + result);
+                        return result;
+                    } catch (Exception e) {
+                        log("isMobileOk: Exception e=" + e);
+                        continue;
+                    }
+                }
+                log("isMobileOk: timed out");
+            } finally {
+                log("isMobileOk: F stop hipri");
+                mCs.setEnableFailFastMobileData(DctConstants.DISABLED);
+                mCs.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+                        Phone.FEATURE_ENABLE_HIPRI);
+
+                // Wait for hipri to disconnect.
+                long endTime = SystemClock.elapsedRealtime() + 5000;
+
+                while(SystemClock.elapsedRealtime() < endTime) {
+                    NetworkInfo.State state = mCs
+                            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI).getState();
+                    if (state != NetworkInfo.State.DISCONNECTED) {
+                        if (VDBG) {
+                            log("isMobileOk: connected ni=" +
+                                mCs.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI));
+                        }
+                        sleep(POLLING_SLEEP_SEC);
+                        continue;
+                    }
+                }
+
+                log("isMobileOk: X result=" + result);
+            }
+            return result;
+        }
+
+        @Override
+        protected Integer doInBackground(Params... params) {
+            return isMobileOk(params[0]);
+        }
+
+        @Override
+        protected void onPostExecute(Integer result) {
+            log("onPostExecute: result=" + result);
+            if ((mParams != null) && (mParams.mCb != null)) {
+                mParams.mCb.onComplete(result);
+            }
+        }
+
+        private String inetAddressesToString(InetAddress[] addresses) {
+            StringBuffer sb = new StringBuffer();
+            boolean firstTime = true;
+            for(InetAddress addr : addresses) {
+                if (firstTime) {
+                    firstTime = false;
+                } else {
+                    sb.append(",");
+                }
+                sb.append(addr);
+            }
+            return sb.toString();
+        }
+
+        private void printNetworkInfo() {
+            boolean hasIccCard = mTm.hasIccCard();
+            int simState = mTm.getSimState();
+            log("hasIccCard=" + hasIccCard
+                    + " simState=" + simState);
+            NetworkInfo[] ni = mCs.getAllNetworkInfo();
+            if (ni != null) {
+                log("ni.length=" + ni.length);
+                for (NetworkInfo netInfo: ni) {
+                    log("netInfo=" + netInfo.toString());
+                }
+            } else {
+                log("no network info ni=null");
+            }
+        }
+
+        /**
+         * Sleep for a few seconds then return.
+         * @param seconds
+         */
+        private static void sleep(int seconds) {
+            try {
+                Thread.sleep(seconds * 1000);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+
+        private static void log(String s) {
+            Slog.d(ConnectivityService.TAG, "[" + CHECKMP_TAG + "] " + s);
+        }
+    }
+
+    // TODO: Move to ConnectivityManager and make public?
+    private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION =
+            "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
+
+    private BroadcastReceiver mProvisioningReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(CONNECTED_TO_PROVISIONING_NETWORK_ACTION)) {
+                handleMobileProvisioningAction(intent.getStringExtra("EXTRA_URL"));
+            }
+        }
+    };
+
+    private void handleMobileProvisioningAction(String url) {
+        // Notication mark notification as not visible
+        setProvNotificationVisible(false, ConnectivityManager.TYPE_MOBILE_HIPRI, null, null);
+
+        // If provisioning network handle as a special case,
+        // otherwise launch browser with the intent directly.
+        NetworkInfo ni = getProvisioningNetworkInfo();
+        if ((ni != null) && ni.isConnectedToProvisioningNetwork()) {
+            if (DBG) log("handleMobileProvisioningAction: on provisioning network");
+            MobileDataStateTracker mdst = (MobileDataStateTracker)
+                    mNetTrackers[ConnectivityManager.TYPE_MOBILE];
+            mdst.enableMobileProvisioning(url);
+        } else {
+            if (DBG) log("handleMobileProvisioningAction: on default network");
+            Intent newIntent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
+                    Intent.CATEGORY_APP_BROWSER);
+            newIntent.setData(Uri.parse(url));
+            newIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
+                    Intent.FLAG_ACTIVITY_NEW_TASK);
+            try {
+                mContext.startActivity(newIntent);
+            } catch (ActivityNotFoundException e) {
+                loge("handleMobileProvisioningAction: startActivity failed" + e);
+            }
+        }
+    }
+
+    private static final String NOTIFICATION_ID = "CaptivePortal.Notification";
+    private volatile boolean mIsNotificationVisible = false;
+
+    private void setProvNotificationVisible(boolean visible, int networkType, String extraInfo,
+            String url) {
+        if (DBG) {
+            log("setProvNotificationVisible: E visible=" + visible + " networkType=" + networkType
+                + " extraInfo=" + extraInfo + " url=" + url);
+        }
+
+        Resources r = Resources.getSystem();
+        NotificationManager notificationManager = (NotificationManager) mContext
+            .getSystemService(Context.NOTIFICATION_SERVICE);
+
+        if (visible) {
+            CharSequence title;
+            CharSequence details;
+            int icon;
+            Intent intent;
+            Notification notification = new Notification();
+            switch (networkType) {
+                case ConnectivityManager.TYPE_WIFI:
+                    title = r.getString(R.string.wifi_available_sign_in, 0);
+                    details = r.getString(R.string.network_available_sign_in_detailed,
+                            extraInfo);
+                    icon = R.drawable.stat_notify_wifi_in_range;
+                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+                    intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
+                            Intent.FLAG_ACTIVITY_NEW_TASK);
+                    notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
+                    break;
+                case ConnectivityManager.TYPE_MOBILE:
+                case ConnectivityManager.TYPE_MOBILE_HIPRI:
+                    title = r.getString(R.string.network_available_sign_in, 0);
+                    // TODO: Change this to pull from NetworkInfo once a printable
+                    // name has been added to it
+                    details = mTelephonyManager.getNetworkOperatorName();
+                    icon = R.drawable.stat_notify_rssi_in_range;
+                    intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
+                    intent.putExtra("EXTRA_URL", url);
+                    intent.setFlags(0);
+                    notification.contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
+                    break;
+                default:
+                    title = r.getString(R.string.network_available_sign_in, 0);
+                    details = r.getString(R.string.network_available_sign_in_detailed,
+                            extraInfo);
+                    icon = R.drawable.stat_notify_rssi_in_range;
+                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+                    intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
+                            Intent.FLAG_ACTIVITY_NEW_TASK);
+                    notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
+                    break;
+            }
+
+            notification.when = 0;
+            notification.icon = icon;
+            notification.flags = Notification.FLAG_AUTO_CANCEL;
+            notification.tickerText = title;
+            notification.setLatestEventInfo(mContext, title, details, notification.contentIntent);
+
+            try {
+                notificationManager.notify(NOTIFICATION_ID, networkType, notification);
+            } catch (NullPointerException npe) {
+                loge("setNotificaitionVisible: visible notificationManager npe=" + npe);
+                npe.printStackTrace();
+            }
+        } else {
+            try {
+                notificationManager.cancel(NOTIFICATION_ID, networkType);
+            } catch (NullPointerException npe) {
+                loge("setNotificaitionVisible: cancel notificationManager npe=" + npe);
+                npe.printStackTrace();
+            }
+        }
+        mIsNotificationVisible = visible;
+    }
+
+    /** Location to an updatable file listing carrier provisioning urls.
+     *  An example:
+     *
+     * <?xml version="1.0" encoding="utf-8"?>
+     *  <provisioningUrls>
+     *   <provisioningUrl mcc="310" mnc="4">http://myserver.com/foo?mdn=%3$s&amp;iccid=%1$s&amp;imei=%2$s</provisioningUrl>
+     *   <redirectedUrl mcc="310" mnc="4">http://www.google.com</redirectedUrl>
+     *  </provisioningUrls>
+     */
+    private static final String PROVISIONING_URL_PATH =
+            "/data/misc/radio/provisioning_urls.xml";
+    private final File mProvisioningUrlFile = new File(PROVISIONING_URL_PATH);
+
+    /** XML tag for root element. */
+    private static final String TAG_PROVISIONING_URLS = "provisioningUrls";
+    /** XML tag for individual url */
+    private static final String TAG_PROVISIONING_URL = "provisioningUrl";
+    /** XML tag for redirected url */
+    private static final String TAG_REDIRECTED_URL = "redirectedUrl";
+    /** XML attribute for mcc */
+    private static final String ATTR_MCC = "mcc";
+    /** XML attribute for mnc */
+    private static final String ATTR_MNC = "mnc";
+
+    private static final int REDIRECTED_PROVISIONING = 1;
+    private static final int PROVISIONING = 2;
+
+    private String getProvisioningUrlBaseFromFile(int type) {
+        FileReader fileReader = null;
+        XmlPullParser parser = null;
+        Configuration config = mContext.getResources().getConfiguration();
+        String tagType;
+
+        switch (type) {
+            case PROVISIONING:
+                tagType = TAG_PROVISIONING_URL;
+                break;
+            case REDIRECTED_PROVISIONING:
+                tagType = TAG_REDIRECTED_URL;
+                break;
+            default:
+                throw new RuntimeException("getProvisioningUrlBaseFromFile: Unexpected parameter " +
+                        type);
+        }
+
+        try {
+            fileReader = new FileReader(mProvisioningUrlFile);
+            parser = Xml.newPullParser();
+            parser.setInput(fileReader);
+            XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
+
+            while (true) {
+                XmlUtils.nextElement(parser);
+
+                String element = parser.getName();
+                if (element == null) break;
+
+                if (element.equals(tagType)) {
+                    String mcc = parser.getAttributeValue(null, ATTR_MCC);
+                    try {
+                        if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
+                            String mnc = parser.getAttributeValue(null, ATTR_MNC);
+                            if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
+                                parser.next();
+                                if (parser.getEventType() == XmlPullParser.TEXT) {
+                                    return parser.getText();
+                                }
+                            }
+                        }
+                    } catch (NumberFormatException e) {
+                        loge("NumberFormatException in getProvisioningUrlBaseFromFile: " + e);
+                    }
+                }
+            }
+            return null;
+        } catch (FileNotFoundException e) {
+            loge("Carrier Provisioning Urls file not found");
+        } catch (XmlPullParserException e) {
+            loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
+        } catch (IOException e) {
+            loge("I/O exception reading Carrier Provisioning Urls file: " + e);
+        } finally {
+            if (fileReader != null) {
+                try {
+                    fileReader.close();
+                } catch (IOException e) {}
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public String getMobileRedirectedProvisioningUrl() {
+        enforceConnectivityInternalPermission();
+        String url = getProvisioningUrlBaseFromFile(REDIRECTED_PROVISIONING);
+        if (TextUtils.isEmpty(url)) {
+            url = mContext.getResources().getString(R.string.mobile_redirected_provisioning_url);
+        }
+        return url;
+    }
+
+    @Override
+    public String getMobileProvisioningUrl() {
+        enforceConnectivityInternalPermission();
+        String url = getProvisioningUrlBaseFromFile(PROVISIONING);
+        if (TextUtils.isEmpty(url)) {
+            url = mContext.getResources().getString(R.string.mobile_provisioning_url);
+            log("getMobileProvisioningUrl: mobile_provisioining_url from resource =" + url);
+        } else {
+            log("getMobileProvisioningUrl: mobile_provisioning_url from File =" + url);
+        }
+        // populate the iccid, imei and phone number in the provisioning url.
+        if (!TextUtils.isEmpty(url)) {
+            String phoneNumber = mTelephonyManager.getLine1Number();
+            if (TextUtils.isEmpty(phoneNumber)) {
+                phoneNumber = "0000000000";
+            }
+            url = String.format(url,
+                    mTelephonyManager.getSimSerialNumber() /* ICCID */,
+                    mTelephonyManager.getDeviceId() /* IMEI */,
+                    phoneNumber /* Phone numer */);
+        }
+
+        return url;
+    }
+
+    @Override
+    public void setProvisioningNotificationVisible(boolean visible, int networkType,
+            String extraInfo, String url) {
+        enforceConnectivityInternalPermission();
+        setProvNotificationVisible(visible, networkType, extraInfo, url);
+    }
+
+    @Override
+    public void setAirplaneMode(boolean enable) {
+        enforceConnectivityInternalPermission();
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            final ContentResolver cr = mContext.getContentResolver();
+            Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, enable ? 1 : 0);
+            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
+            intent.putExtra("state", enable);
+            mContext.sendBroadcast(intent);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private void onUserStart(int userId) {
+        synchronized(mVpns) {
+            Vpn userVpn = mVpns.get(userId);
+            if (userVpn != null) {
+                loge("Starting user already has a VPN");
+                return;
+            }
+            userVpn = new Vpn(mContext, mVpnCallback, mNetd, this, userId);
+            mVpns.put(userId, userVpn);
+            userVpn.startMonitoring(mContext, mTrackerHandler);
+        }
+    }
+
+    private void onUserStop(int userId) {
+        synchronized(mVpns) {
+            Vpn userVpn = mVpns.get(userId);
+            if (userVpn == null) {
+                loge("Stopping user has no VPN");
+                return;
+            }
+            mVpns.delete(userId);
+        }
+    }
+
+    private BroadcastReceiver mUserIntentReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
+            if (userId == UserHandle.USER_NULL) return;
+
+            if (Intent.ACTION_USER_STARTING.equals(action)) {
+                onUserStart(userId);
+            } else if (Intent.ACTION_USER_STOPPING.equals(action)) {
+                onUserStop(userId);
+            }
+        }
+    };
+
+    @Override
+    public LinkQualityInfo getLinkQualityInfo(int networkType) {
+        enforceAccessPermission();
+        if (isNetworkTypeValid(networkType)) {
+            return mNetTrackers[networkType].getLinkQualityInfo();
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public LinkQualityInfo getActiveLinkQualityInfo() {
+        enforceAccessPermission();
+        if (isNetworkTypeValid(mActiveDefaultNetwork)) {
+            return mNetTrackers[mActiveDefaultNetwork].getLinkQualityInfo();
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public LinkQualityInfo[] getAllLinkQualityInfo() {
+        enforceAccessPermission();
+        final ArrayList<LinkQualityInfo> result = Lists.newArrayList();
+        for (NetworkStateTracker tracker : mNetTrackers) {
+            if (tracker != null) {
+                LinkQualityInfo li = tracker.getLinkQualityInfo();
+                if (li != null) {
+                    result.add(li);
+                }
+            }
+        }
+
+        return result.toArray(new LinkQualityInfo[result.size()]);
+    }
+
+    /* Infrastructure for network sampling */
+
+    private void handleNetworkSamplingTimeout() {
+
+        log("Sampling interval elapsed, updating statistics ..");
+
+        // initialize list of interfaces ..
+        Map<String, SamplingDataTracker.SamplingSnapshot> mapIfaceToSample =
+                new HashMap<String, SamplingDataTracker.SamplingSnapshot>();
+        for (NetworkStateTracker tracker : mNetTrackers) {
+            if (tracker != null) {
+                String ifaceName = tracker.getNetworkInterfaceName();
+                if (ifaceName != null) {
+                    mapIfaceToSample.put(ifaceName, null);
+                }
+            }
+        }
+
+        // Read samples for all interfaces
+        SamplingDataTracker.getSamplingSnapshots(mapIfaceToSample);
+
+        // process samples for all networks
+        for (NetworkStateTracker tracker : mNetTrackers) {
+            if (tracker != null) {
+                String ifaceName = tracker.getNetworkInterfaceName();
+                SamplingDataTracker.SamplingSnapshot ss = mapIfaceToSample.get(ifaceName);
+                if (ss != null) {
+                    // end the previous sampling cycle
+                    tracker.stopSampling(ss);
+                    // start a new sampling cycle ..
+                    tracker.startSampling(ss);
+                }
+            }
+        }
+
+        log("Done.");
+
+        int samplingIntervalInSeconds = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.CONNECTIVITY_SAMPLING_INTERVAL_IN_SECONDS,
+                DEFAULT_SAMPLING_INTERVAL_IN_SECONDS);
+
+        if (DBG) log("Setting timer for " + String.valueOf(samplingIntervalInSeconds) + "seconds");
+
+        setAlarm(samplingIntervalInSeconds * 1000, mSampleIntervalElapsedIntent);
+    }
+
+    void setAlarm(int timeoutInMilliseconds, PendingIntent intent) {
+        long wakeupTime = SystemClock.elapsedRealtime() + timeoutInMilliseconds;
+        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime, intent);
+    }
+}
diff --git a/services/java/com/android/server/ConsumerIrService.java b/services/core/java/com/android/server/ConsumerIrService.java
similarity index 100%
rename from services/java/com/android/server/ConsumerIrService.java
rename to services/core/java/com/android/server/ConsumerIrService.java
diff --git a/services/java/com/android/server/CountryDetectorService.java b/services/core/java/com/android/server/CountryDetectorService.java
similarity index 100%
rename from services/java/com/android/server/CountryDetectorService.java
rename to services/core/java/com/android/server/CountryDetectorService.java
diff --git a/services/java/com/android/server/DiskStatsService.java b/services/core/java/com/android/server/DiskStatsService.java
similarity index 100%
rename from services/java/com/android/server/DiskStatsService.java
rename to services/core/java/com/android/server/DiskStatsService.java
diff --git a/services/core/java/com/android/server/DisplayThread.java b/services/core/java/com/android/server/DisplayThread.java
new file mode 100644
index 0000000..528ba0a
--- /dev/null
+++ b/services/core/java/com/android/server/DisplayThread.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.os.Handler;
+
+/**
+ * Shared singleton foreground thread for the system.  This is a thread for
+ * operations that affect what's on the display, which needs to have a minimum
+ * of latency.  This thread should pretty much only be used by the WindowManager,
+ * DisplayManager, and InputManager to perform quick operations in real time.
+ */
+public final class DisplayThread extends ServiceThread {
+    private static DisplayThread sInstance;
+    private static Handler sHandler;
+
+    private DisplayThread() {
+        super("android.display", android.os.Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
+    }
+
+    private static void ensureThreadLocked() {
+        if (sInstance == null) {
+            sInstance = new DisplayThread();
+            sInstance.start();
+            sHandler = new Handler(sInstance.getLooper());
+        }
+    }
+
+    public static DisplayThread get() {
+        synchronized (UiThread.class) {
+            ensureThreadLocked();
+            return sInstance;
+        }
+    }
+
+    public static Handler getHandler() {
+        synchronized (UiThread.class) {
+            ensureThreadLocked();
+            return sHandler;
+        }
+    }
+}
diff --git a/services/java/com/android/server/DockObserver.java b/services/core/java/com/android/server/DockObserver.java
similarity index 100%
rename from services/java/com/android/server/DockObserver.java
rename to services/core/java/com/android/server/DockObserver.java
diff --git a/services/java/com/android/server/DropBoxManagerService.java b/services/core/java/com/android/server/DropBoxManagerService.java
similarity index 100%
rename from services/java/com/android/server/DropBoxManagerService.java
rename to services/core/java/com/android/server/DropBoxManagerService.java
diff --git a/services/core/java/com/android/server/EntropyMixer.java b/services/core/java/com/android/server/EntropyMixer.java
new file mode 100644
index 0000000..cfdbf7d
--- /dev/null
+++ b/services/core/java/com/android/server/EntropyMixer.java
@@ -0,0 +1,208 @@
+/*
+ * 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.
+ */
+
+package com.android.server;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Message;
+import android.os.SystemProperties;
+import android.util.Slog;
+
+/**
+ * A service designed to load and periodically save &quot;randomness&quot;
+ * for the Linux kernel RNG and to mix in data from Hardware RNG (if present)
+ * into the Linux RNG.
+ *
+ * <p>When a Linux system starts up, the entropy pool associated with
+ * {@code /dev/random} may be in a fairly predictable state.  Applications which
+ * depend strongly on randomness may find {@code /dev/random} or
+ * {@code /dev/urandom} returning predictable data.  In order to counteract
+ * this effect, it's helpful to carry the entropy pool information across
+ * shutdowns and startups.
+ *
+ * <p>On systems with Hardware RNG (/dev/hw_random), a block of output from HW
+ * RNG is mixed into the Linux RNG on EntropyMixer's startup and whenever
+ * EntropyMixer periodically runs to save a block of output from Linux RNG on
+ * disk. This mixing is done in a way that does not increase the Linux RNG's
+ * entropy estimate is not increased. This is to avoid having to trust/verify
+ * the quality and authenticity of the &quot;randomness&quot; of the HW RNG.
+ *
+ * <p>This class was modeled after the script in
+ * <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/random.4.html">man
+ * 4 random</a>.
+ */
+public class EntropyMixer extends Binder {
+    private static final String TAG = "EntropyMixer";
+    private static final int ENTROPY_WHAT = 1;
+    private static final int ENTROPY_WRITE_PERIOD = 3 * 60 * 60 * 1000;  // 3 hrs
+    private static final long START_TIME = System.currentTimeMillis();
+    private static final long START_NANOTIME = System.nanoTime();
+
+    private final String randomDevice;
+    private final String hwRandomDevice;
+    private final String entropyFile;
+
+    /**
+     * Handler that periodically updates the entropy on disk.
+     */
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            if (msg.what != ENTROPY_WHAT) {
+                Slog.e(TAG, "Will not process invalid message");
+                return;
+            }
+            addHwRandomEntropy();
+            writeEntropy();
+            scheduleEntropyWriter();
+        }
+    };
+
+    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            writeEntropy();
+        }
+    };
+
+    public EntropyMixer(Context context) {
+        this(context, getSystemDir() + "/entropy.dat", "/dev/urandom", "/dev/hw_random");
+    }
+
+    /** Test only interface, not for public use */
+    public EntropyMixer(
+            Context context,
+            String entropyFile,
+            String randomDevice,
+            String hwRandomDevice) {
+        if (randomDevice == null) { throw new NullPointerException("randomDevice"); }
+        if (hwRandomDevice == null) { throw new NullPointerException("hwRandomDevice"); }
+        if (entropyFile == null) { throw new NullPointerException("entropyFile"); }
+
+        this.randomDevice = randomDevice;
+        this.hwRandomDevice = hwRandomDevice;
+        this.entropyFile = entropyFile;
+        loadInitialEntropy();
+        addDeviceSpecificEntropy();
+        addHwRandomEntropy();
+        writeEntropy();
+        scheduleEntropyWriter();
+        IntentFilter broadcastFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);
+        broadcastFilter.addAction(Intent.ACTION_POWER_CONNECTED);
+        broadcastFilter.addAction(Intent.ACTION_REBOOT);
+        context.registerReceiver(mBroadcastReceiver, broadcastFilter);
+    }
+
+    private void scheduleEntropyWriter() {
+        mHandler.removeMessages(ENTROPY_WHAT);
+        mHandler.sendEmptyMessageDelayed(ENTROPY_WHAT, ENTROPY_WRITE_PERIOD);
+    }
+
+    private void loadInitialEntropy() {
+        try {
+            RandomBlock.fromFile(entropyFile).toFile(randomDevice, false);
+        } catch (FileNotFoundException e) {
+            Slog.w(TAG, "No existing entropy file -- first boot?");
+        } catch (IOException e) {
+            Slog.w(TAG, "Failure loading existing entropy file", e);
+        }
+    }
+
+    private void writeEntropy() {
+        try {
+            Slog.i(TAG, "Writing entropy...");
+            RandomBlock.fromFile(randomDevice).toFile(entropyFile, true);
+        } catch (IOException e) {
+            Slog.w(TAG, "Unable to write entropy", e);
+        }
+    }
+
+    /**
+     * Add additional information to the kernel entropy pool.  The
+     * information isn't necessarily "random", but that's ok.  Even
+     * sending non-random information to {@code /dev/urandom} is useful
+     * because, while it doesn't increase the "quality" of the entropy pool,
+     * it mixes more bits into the pool, which gives us a higher degree
+     * of uncertainty in the generated randomness.  Like nature, writes to
+     * the random device can only cause the quality of the entropy in the
+     * kernel to stay the same or increase.
+     *
+     * <p>For maximum effect, we try to target information which varies
+     * on a per-device basis, and is not easily observable to an
+     * attacker.
+     */
+    private void addDeviceSpecificEntropy() {
+        PrintWriter out = null;
+        try {
+            out = new PrintWriter(new FileOutputStream(randomDevice));
+            out.println("Copyright (C) 2009 The Android Open Source Project");
+            out.println("All Your Randomness Are Belong To Us");
+            out.println(START_TIME);
+            out.println(START_NANOTIME);
+            out.println(SystemProperties.get("ro.serialno"));
+            out.println(SystemProperties.get("ro.bootmode"));
+            out.println(SystemProperties.get("ro.baseband"));
+            out.println(SystemProperties.get("ro.carrier"));
+            out.println(SystemProperties.get("ro.bootloader"));
+            out.println(SystemProperties.get("ro.hardware"));
+            out.println(SystemProperties.get("ro.revision"));
+            out.println(SystemProperties.get("ro.build.fingerprint"));
+            out.println(new Object().hashCode());
+            out.println(System.currentTimeMillis());
+            out.println(System.nanoTime());
+        } catch (IOException e) {
+            Slog.w(TAG, "Unable to add device specific data to the entropy pool", e);
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+        }
+    }
+
+    /**
+     * Mixes in the output from HW RNG (if present) into the Linux RNG.
+     */
+    private void addHwRandomEntropy() {
+        try {
+            RandomBlock.fromFile(hwRandomDevice).toFile(randomDevice, false);
+            Slog.i(TAG, "Added HW RNG output to entropy pool");
+        } catch (FileNotFoundException ignored) {
+            // HW RNG not present/exposed -- ignore
+        } catch (IOException e) {
+            Slog.w(TAG, "Failed to add HW RNG output to entropy pool", e);
+        }
+    }
+
+    private static String getSystemDir() {
+        File dataDir = Environment.getDataDirectory();
+        File systemDir = new File(dataDir, "system");
+        systemDir.mkdirs();
+        return systemDir.toString();
+    }
+}
diff --git a/services/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags
similarity index 100%
rename from services/java/com/android/server/EventLogTags.logtags
rename to services/core/java/com/android/server/EventLogTags.logtags
diff --git a/services/core/java/com/android/server/FgThread.java b/services/core/java/com/android/server/FgThread.java
new file mode 100644
index 0000000..03765db
--- /dev/null
+++ b/services/core/java/com/android/server/FgThread.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.os.Handler;
+
+/**
+ * Shared singleton foreground thread for the system.  This is a thread for regular
+ * foreground service operations, which shouldn't be blocked by anything running in
+ * the background.  In particular, the shared background thread could be doing
+ * relatively long-running operations like saving state to disk (in addition to
+ * simply being a background priority), which can cause operations scheduled on it
+ * to be delayed for a user-noticeable amount of time.
+ */
+public final class FgThread extends ServiceThread {
+    private static FgThread sInstance;
+    private static Handler sHandler;
+
+    private FgThread() {
+        super("android.fg", android.os.Process.THREAD_PRIORITY_DEFAULT, true /*allowIo*/);
+    }
+
+    private static void ensureThreadLocked() {
+        if (sInstance == null) {
+            sInstance = new FgThread();
+            sInstance.start();
+            sHandler = new Handler(sInstance.getLooper());
+        }
+    }
+
+    public static FgThread get() {
+        synchronized (UiThread.class) {
+            ensureThreadLocked();
+            return sInstance;
+        }
+    }
+
+    public static Handler getHandler() {
+        synchronized (UiThread.class) {
+            ensureThreadLocked();
+            return sHandler;
+        }
+    }
+}
diff --git a/services/java/com/android/server/INativeDaemonConnectorCallbacks.java b/services/core/java/com/android/server/INativeDaemonConnectorCallbacks.java
similarity index 100%
rename from services/java/com/android/server/INativeDaemonConnectorCallbacks.java
rename to services/core/java/com/android/server/INativeDaemonConnectorCallbacks.java
diff --git a/services/java/com/android/server/IdleMaintenanceService.java b/services/core/java/com/android/server/IdleMaintenanceService.java
similarity index 100%
rename from services/java/com/android/server/IdleMaintenanceService.java
rename to services/core/java/com/android/server/IdleMaintenanceService.java
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
new file mode 100644
index 0000000..26424a5
--- /dev/null
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -0,0 +1,3574 @@
+/*
+ *
+ * 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;
+
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.inputmethod.InputMethodUtils;
+import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
+import com.android.internal.os.HandlerCaller;
+import com.android.internal.os.SomeArgs;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.view.IInputContext;
+import com.android.internal.view.IInputMethod;
+import com.android.internal.view.IInputSessionCallback;
+import com.android.internal.view.IInputMethodClient;
+import com.android.internal.view.IInputMethodManager;
+import com.android.internal.view.IInputMethodSession;
+import com.android.internal.view.InputBindResult;
+import com.android.server.statusbar.StatusBarManagerService;
+import com.android.server.wm.WindowManagerService;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.app.ActivityManagerNative;
+import android.app.AppGlobals;
+import android.app.AlertDialog;
+import android.app.IUserSwitchObserver;
+import android.app.KeyguardManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnCancelListener;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.database.ContentObserver;
+import android.inputmethodservice.InputMethodService;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IInterface;
+import android.os.IRemoteCallback;
+import android.os.Message;
+import android.os.Process;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ResultReceiver;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.text.style.SuggestionSpan;
+import android.util.AtomicFile;
+import android.util.EventLog;
+import android.util.LruCache;
+import android.util.Pair;
+import android.util.PrintWriterPrinter;
+import android.util.Printer;
+import android.util.Slog;
+import android.util.Xml;
+import android.view.IWindowManager;
+import android.view.InputChannel;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputBinding;
+import android.view.inputmethod.InputMethod;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.view.inputmethod.InputMethodSubtype;
+import android.widget.ArrayAdapter;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.RadioButton;
+import android.widget.Switch;
+import android.widget.TextView;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.TreeMap;
+
+/**
+ * This class provides a system service that manages input methods.
+ */
+public class InputMethodManagerService extends IInputMethodManager.Stub
+        implements ServiceConnection, Handler.Callback {
+    static final boolean DEBUG = false;
+    static final String TAG = "InputMethodManagerService";
+
+    static final int MSG_SHOW_IM_PICKER = 1;
+    static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2;
+    static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3;
+    static final int MSG_SHOW_IM_CONFIG = 4;
+
+    static final int MSG_UNBIND_INPUT = 1000;
+    static final int MSG_BIND_INPUT = 1010;
+    static final int MSG_SHOW_SOFT_INPUT = 1020;
+    static final int MSG_HIDE_SOFT_INPUT = 1030;
+    static final int MSG_ATTACH_TOKEN = 1040;
+    static final int MSG_CREATE_SESSION = 1050;
+
+    static final int MSG_START_INPUT = 2000;
+    static final int MSG_RESTART_INPUT = 2010;
+
+    static final int MSG_UNBIND_METHOD = 3000;
+    static final int MSG_BIND_METHOD = 3010;
+    static final int MSG_SET_ACTIVE = 3020;
+
+    static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
+
+    static final long TIME_TO_RECONNECT = 10*1000;
+
+    static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20;
+
+    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
+    private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";
+
+
+    final Context mContext;
+    final Resources mRes;
+    final Handler mHandler;
+    final InputMethodSettings mSettings;
+    final SettingsObserver mSettingsObserver;
+    final IWindowManager mIWindowManager;
+    final HandlerCaller mCaller;
+    final boolean mHasFeature;
+    private InputMethodFileManager mFileManager;
+    private InputMethodAndSubtypeListManager mImListManager;
+    private final HardKeyboardListener mHardKeyboardListener;
+    private final WindowManagerService mWindowManagerService;
+
+    final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1);
+
+    // All known input methods.  mMethodMap also serves as the global
+    // lock for this class.
+    final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
+    final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>();
+    private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans =
+            new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE);
+
+    // Used to bring IME service up to visible adjustment while it is being shown.
+    final ServiceConnection mVisibleConnection = new ServiceConnection() {
+        @Override public void onServiceConnected(ComponentName name, IBinder service) {
+        }
+
+        @Override public void onServiceDisconnected(ComponentName name) {
+        }
+    };
+    boolean mVisibleBound = false;
+
+    // Ongoing notification
+    private NotificationManager mNotificationManager;
+    private KeyguardManager mKeyguardManager;
+    private StatusBarManagerService mStatusBar;
+    private Notification mImeSwitcherNotification;
+    private PendingIntent mImeSwitchPendingIntent;
+    private boolean mShowOngoingImeSwitcherForPhones;
+    private boolean mNotificationShown;
+    private final boolean mImeSelectedOnBoot;
+
+    class SessionState {
+        final ClientState client;
+        final IInputMethod method;
+
+        IInputMethodSession session;
+        InputChannel channel;
+
+        @Override
+        public String toString() {
+            return "SessionState{uid " + client.uid + " pid " + client.pid
+                    + " method " + Integer.toHexString(
+                            System.identityHashCode(method))
+                    + " session " + Integer.toHexString(
+                            System.identityHashCode(session))
+                    + " channel " + channel
+                    + "}";
+        }
+
+        SessionState(ClientState _client, IInputMethod _method,
+                IInputMethodSession _session, InputChannel _channel) {
+            client = _client;
+            method = _method;
+            session = _session;
+            channel = _channel;
+        }
+    }
+
+    static final class ClientState {
+        final IInputMethodClient client;
+        final IInputContext inputContext;
+        final int uid;
+        final int pid;
+        final InputBinding binding;
+
+        boolean sessionRequested;
+        SessionState curSession;
+
+        @Override
+        public String toString() {
+            return "ClientState{" + Integer.toHexString(
+                    System.identityHashCode(this)) + " uid " + uid
+                    + " pid " + pid + "}";
+        }
+
+        ClientState(IInputMethodClient _client, IInputContext _inputContext,
+                int _uid, int _pid) {
+            client = _client;
+            inputContext = _inputContext;
+            uid = _uid;
+            pid = _pid;
+            binding = new InputBinding(null, inputContext.asBinder(), uid, pid);
+        }
+    }
+
+    final HashMap<IBinder, ClientState> mClients
+            = new HashMap<IBinder, ClientState>();
+
+    /**
+     * Set once the system is ready to run third party code.
+     */
+    boolean mSystemReady;
+
+    /**
+     * Id of the currently selected input method.
+     */
+    String mCurMethodId;
+
+    /**
+     * The current binding sequence number, incremented every time there is
+     * a new bind performed.
+     */
+    int mCurSeq;
+
+    /**
+     * The client that is currently bound to an input method.
+     */
+    ClientState mCurClient;
+
+    /**
+     * The last window token that gained focus.
+     */
+    IBinder mCurFocusedWindow;
+
+    /**
+     * The input context last provided by the current client.
+     */
+    IInputContext mCurInputContext;
+
+    /**
+     * The attributes last provided by the current client.
+     */
+    EditorInfo mCurAttribute;
+
+    /**
+     * The input method ID of the input method service that we are currently
+     * connected to or in the process of connecting to.
+     */
+    String mCurId;
+
+    /**
+     * The current subtype of the current input method.
+     */
+    private InputMethodSubtype mCurrentSubtype;
+
+    // This list contains the pairs of InputMethodInfo and InputMethodSubtype.
+    private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>
+            mShortcutInputMethodsAndSubtypes =
+                new HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>();
+
+    // Was the keyguard locked when this client became current?
+    private boolean mCurClientInKeyguard;
+
+    /**
+     * Set to true if our ServiceConnection is currently actively bound to
+     * a service (whether or not we have gotten its IBinder back yet).
+     */
+    boolean mHaveConnection;
+
+    /**
+     * Set if the client has asked for the input method to be shown.
+     */
+    boolean mShowRequested;
+
+    /**
+     * Set if we were explicitly told to show the input method.
+     */
+    boolean mShowExplicitlyRequested;
+
+    /**
+     * Set if we were forced to be shown.
+     */
+    boolean mShowForced;
+
+    /**
+     * Set if we last told the input method to show itself.
+     */
+    boolean mInputShown;
+
+    /**
+     * The Intent used to connect to the current input method.
+     */
+    Intent mCurIntent;
+
+    /**
+     * The token we have made for the currently active input method, to
+     * identify it in the future.
+     */
+    IBinder mCurToken;
+
+    /**
+     * If non-null, this is the input method service we are currently connected
+     * to.
+     */
+    IInputMethod mCurMethod;
+
+    /**
+     * Time that we last initiated a bind to the input method, to determine
+     * if we should try to disconnect and reconnect to it.
+     */
+    long mLastBindTime;
+
+    /**
+     * Have we called mCurMethod.bindInput()?
+     */
+    boolean mBoundToMethod;
+
+    /**
+     * Currently enabled session.  Only touched by service thread, not
+     * protected by a lock.
+     */
+    SessionState mEnabledSession;
+
+    /**
+     * True if the screen is on.  The value is true initially.
+     */
+    boolean mScreenOn = true;
+
+    int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
+    int mImeWindowVis;
+
+    private AlertDialog.Builder mDialogBuilder;
+    private AlertDialog mSwitchingDialog;
+    private View mSwitchingDialogTitleView;
+    private InputMethodInfo[] mIms;
+    private int[] mSubtypeIds;
+    private Locale mLastSystemLocale;
+    private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
+    private final IPackageManager mIPackageManager;
+
+    class SettingsObserver extends ContentObserver {
+        String mLastEnabled = "";
+
+        SettingsObserver(Handler handler) {
+            super(handler);
+            ContentResolver resolver = mContext.getContentResolver();
+            resolver.registerContentObserver(Settings.Secure.getUriFor(
+                    Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
+            resolver.registerContentObserver(Settings.Secure.getUriFor(
+                    Settings.Secure.ENABLED_INPUT_METHODS), false, this);
+            resolver.registerContentObserver(Settings.Secure.getUriFor(
+                    Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
+        }
+
+        @Override public void onChange(boolean selfChange) {
+            synchronized (mMethodMap) {
+                boolean enabledChanged = false;
+                String newEnabled = mSettings.getEnabledInputMethodsStr();
+                if (!mLastEnabled.equals(newEnabled)) {
+                    mLastEnabled = newEnabled;
+                    enabledChanged = true;
+                }
+                updateFromSettingsLocked(enabledChanged);
+            }
+        }
+    }
+
+    class ImmsBroadcastReceiver extends android.content.BroadcastReceiver {
+        private void updateActive() {
+            // Inform the current client of the change in active status
+            if (mCurClient != null && mCurClient.client != null) {
+                executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
+                        MSG_SET_ACTIVE, mScreenOn ? 1 : 0, mCurClient));
+            }
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (Intent.ACTION_SCREEN_ON.equals(action)) {
+                mScreenOn = true;
+                refreshImeWindowVisibilityLocked();
+                updateActive();
+                return;
+            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
+                mScreenOn = false;
+                setImeWindowVisibilityStatusHiddenLocked();
+                updateActive();
+                return;
+            } else if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
+                hideInputMethodMenu();
+                // No need to updateActive
+                return;
+            } else {
+                Slog.w(TAG, "Unexpected intent " + intent);
+            }
+        }
+    }
+
+    class MyPackageMonitor extends PackageMonitor {
+        private boolean isChangingPackagesOfCurrentUser() {
+            final int userId = getChangingUserId();
+            final boolean retval = userId == mSettings.getCurrentUserId();
+            if (DEBUG) {
+                if (!retval) {
+                    Slog.d(TAG, "--- ignore this call back from a background user: " + userId);
+                }
+            }
+            return retval;
+        }
+
+        @Override
+        public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
+            if (!isChangingPackagesOfCurrentUser()) {
+                return false;
+            }
+            synchronized (mMethodMap) {
+                String curInputMethodId = mSettings.getSelectedInputMethod();
+                final int N = mMethodList.size();
+                if (curInputMethodId != null) {
+                    for (int i=0; i<N; i++) {
+                        InputMethodInfo imi = mMethodList.get(i);
+                        if (imi.getId().equals(curInputMethodId)) {
+                            for (String pkg : packages) {
+                                if (imi.getPackageName().equals(pkg)) {
+                                    if (!doit) {
+                                        return true;
+                                    }
+                                    resetSelectedInputMethodAndSubtypeLocked("");
+                                    chooseNewDefaultIMELocked();
+                                    return true;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            return false;
+        }
+
+        @Override
+        public void onSomePackagesChanged() {
+            if (!isChangingPackagesOfCurrentUser()) {
+                return;
+            }
+            synchronized (mMethodMap) {
+                InputMethodInfo curIm = null;
+                String curInputMethodId = mSettings.getSelectedInputMethod();
+                final int N = mMethodList.size();
+                if (curInputMethodId != null) {
+                    for (int i=0; i<N; i++) {
+                        InputMethodInfo imi = mMethodList.get(i);
+                        final String imiId = imi.getId();
+                        if (imiId.equals(curInputMethodId)) {
+                            curIm = imi;
+                        }
+
+                        int change = isPackageDisappearing(imi.getPackageName());
+                        if (isPackageModified(imi.getPackageName())) {
+                            mFileManager.deleteAllInputMethodSubtypes(imiId);
+                        }
+                        if (change == PACKAGE_TEMPORARY_CHANGE
+                                || change == PACKAGE_PERMANENT_CHANGE) {
+                            Slog.i(TAG, "Input method uninstalled, disabling: "
+                                    + imi.getComponent());
+                            setInputMethodEnabledLocked(imi.getId(), false);
+                        }
+                    }
+                }
+
+                buildInputMethodListLocked(
+                        mMethodList, mMethodMap, false /* resetDefaultEnabledIme */);
+
+                boolean changed = false;
+
+                if (curIm != null) {
+                    int change = isPackageDisappearing(curIm.getPackageName()); 
+                    if (change == PACKAGE_TEMPORARY_CHANGE
+                            || change == PACKAGE_PERMANENT_CHANGE) {
+                        ServiceInfo si = null;
+                        try {
+                            si = mIPackageManager.getServiceInfo(
+                                    curIm.getComponent(), 0, mSettings.getCurrentUserId());
+                        } catch (RemoteException ex) {
+                        }
+                        if (si == null) {
+                            // Uh oh, current input method is no longer around!
+                            // Pick another one...
+                            Slog.i(TAG, "Current input method removed: " + curInputMethodId);
+                            setImeWindowVisibilityStatusHiddenLocked();
+                            if (!chooseNewDefaultIMELocked()) {
+                                changed = true;
+                                curIm = null;
+                                Slog.i(TAG, "Unsetting current input method");
+                                resetSelectedInputMethodAndSubtypeLocked("");
+                            }
+                        }
+                    }
+                }
+
+                if (curIm == null) {
+                    // We currently don't have a default input method... is
+                    // one now available?
+                    changed = chooseNewDefaultIMELocked();
+                }
+
+                if (changed) {
+                    updateFromSettingsLocked(false);
+                }
+            }
+        }
+    }
+
+    private static final class MethodCallback extends IInputSessionCallback.Stub {
+        private final InputMethodManagerService mParentIMMS;
+        private final IInputMethod mMethod;
+        private final InputChannel mChannel;
+
+        MethodCallback(InputMethodManagerService imms, IInputMethod method,
+                InputChannel channel) {
+            mParentIMMS = imms;
+            mMethod = method;
+            mChannel = channel;
+        }
+
+        @Override
+        public void sessionCreated(IInputMethodSession session) {
+            mParentIMMS.onSessionCreated(mMethod, session, mChannel);
+        }
+    }
+
+    private class HardKeyboardListener
+            implements WindowManagerService.OnHardKeyboardStatusChangeListener {
+        @Override
+        public void onHardKeyboardStatusChange(boolean available, boolean enabled) {
+            mHandler.sendMessage(mHandler.obtainMessage(
+                    MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0, enabled ? 1 : 0));
+        }
+
+        public void handleHardKeyboardStatusChange(boolean available, boolean enabled) {
+            if (DEBUG) {
+                Slog.w(TAG, "HardKeyboardStatusChanged: available = " + available + ", enabled = "
+                        + enabled);
+            }
+            synchronized(mMethodMap) {
+                if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
+                        && mSwitchingDialog.isShowing()) {
+                    mSwitchingDialogTitleView.findViewById(
+                            com.android.internal.R.id.hard_keyboard_section).setVisibility(
+                                    available ? View.VISIBLE : View.GONE);
+                }
+            }
+        }
+    }
+
+    public InputMethodManagerService(Context context, WindowManagerService windowManager) {
+        mIPackageManager = AppGlobals.getPackageManager();
+        mContext = context;
+        mRes = context.getResources();
+        mHandler = new Handler(this);
+        mIWindowManager = IWindowManager.Stub.asInterface(
+                ServiceManager.getService(Context.WINDOW_SERVICE));
+        mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() {
+            @Override
+            public void executeMessage(Message msg) {
+                handleMessage(msg);
+            }
+        }, true /*asyncHandler*/);
+        mWindowManagerService = windowManager;
+        mHardKeyboardListener = new HardKeyboardListener();
+        mHasFeature = context.getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_INPUT_METHODS);
+
+        mImeSwitcherNotification = new Notification();
+        mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default;
+        mImeSwitcherNotification.when = 0;
+        mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT;
+        mImeSwitcherNotification.tickerText = null;
+        mImeSwitcherNotification.defaults = 0; // please be quiet
+        mImeSwitcherNotification.sound = null;
+        mImeSwitcherNotification.vibrate = null;
+
+        // Tag this notification specially so SystemUI knows it's important
+        mImeSwitcherNotification.kind = new String[] { "android.system.imeswitcher" };
+
+        Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
+        mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
+
+        mShowOngoingImeSwitcherForPhones = false;
+
+        final IntentFilter broadcastFilter = new IntentFilter();
+        broadcastFilter.addAction(Intent.ACTION_SCREEN_ON);
+        broadcastFilter.addAction(Intent.ACTION_SCREEN_OFF);
+        broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+        mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter);
+
+        mNotificationShown = false;
+        int userId = 0;
+        try {
+            ActivityManagerNative.getDefault().registerUserSwitchObserver(
+                    new IUserSwitchObserver.Stub() {
+                        @Override
+                        public void onUserSwitching(int newUserId, IRemoteCallback reply) {
+                            synchronized(mMethodMap) {
+                                switchUserLocked(newUserId);
+                            }
+                            if (reply != null) {
+                                try {
+                                    reply.sendResult(null);
+                                } catch (RemoteException e) {
+                                }
+                            }
+                        }
+
+                        @Override
+                        public void onUserSwitchComplete(int newUserId) throws RemoteException {
+                        }
+                    });
+            userId = ActivityManagerNative.getDefault().getCurrentUser().id;
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
+        }
+        mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true);
+
+        // mSettings should be created before buildInputMethodListLocked
+        mSettings = new InputMethodSettings(
+                mRes, context.getContentResolver(), mMethodMap, mMethodList, userId);
+        mFileManager = new InputMethodFileManager(mMethodMap, userId);
+        mImListManager = new InputMethodAndSubtypeListManager(context, this);
+
+        // Just checking if defaultImiId is empty or not
+        final String defaultImiId = mSettings.getSelectedInputMethod();
+        if (DEBUG) {
+            Slog.d(TAG, "Initial default ime = " + defaultImiId);
+        }
+        mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);
+
+        buildInputMethodListLocked(mMethodList, mMethodMap,
+                !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
+        mSettings.enableAllIMEsIfThereIsNoEnabledIME();
+
+        if (!mImeSelectedOnBoot) {
+            Slog.w(TAG, "No IME selected. Choose the most applicable IME.");
+            resetDefaultImeLocked(context);
+        }
+
+        mSettingsObserver = new SettingsObserver(mHandler);
+        updateFromSettingsLocked(true);
+
+        // IMMS wants to receive Intent.ACTION_LOCALE_CHANGED in order to update the current IME
+        // according to the new system locale.
+        final IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
+        mContext.registerReceiver(
+                new BroadcastReceiver() {
+                    @Override
+                    public void onReceive(Context context, Intent intent) {
+                        synchronized(mMethodMap) {
+                            resetStateIfCurrentLocaleChangedLocked();
+                        }
+                    }
+                }, filter);
+    }
+
+    private void resetDefaultImeLocked(Context context) {
+        // Do not reset the default (current) IME when it is a 3rd-party IME
+        if (mCurMethodId != null
+                && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
+            return;
+        }
+
+        InputMethodInfo defIm = null;
+        for (InputMethodInfo imi : mMethodList) {
+            if (defIm == null) {
+                if (InputMethodUtils.isValidSystemDefaultIme(
+                        mSystemReady, imi, context)) {
+                    defIm = imi;
+                    Slog.i(TAG, "Selected default: " + imi.getId());
+                }
+            }
+        }
+        if (defIm == null && mMethodList.size() > 0) {
+            defIm = InputMethodUtils.getMostApplicableDefaultIME(
+                    mSettings.getEnabledInputMethodListLocked());
+            Slog.i(TAG, "No default found, using " + defIm.getId());
+        }
+        if (defIm != null) {
+            setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
+        }
+    }
+
+    private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged,
+            final boolean resetDefaultEnabledIme) {
+        if (!mSystemReady) {
+            // not system ready
+            return;
+        }
+        final Locale newLocale = mRes.getConfiguration().locale;
+        if (!updateOnlyWhenLocaleChanged
+                || (newLocale != null && !newLocale.equals(mLastSystemLocale))) {
+            if (!updateOnlyWhenLocaleChanged) {
+                hideCurrentInputLocked(0, null);
+                mCurMethodId = null;
+                unbindCurrentMethodLocked(true, false);
+            }
+            if (DEBUG) {
+                Slog.i(TAG, "Locale has been changed to " + newLocale);
+            }
+            // InputMethodAndSubtypeListManager should be reset when the locale is changed.
+            mImListManager = new InputMethodAndSubtypeListManager(mContext, this);
+            buildInputMethodListLocked(mMethodList, mMethodMap, resetDefaultEnabledIme);
+            if (!updateOnlyWhenLocaleChanged) {
+                final String selectedImiId = mSettings.getSelectedInputMethod();
+                if (TextUtils.isEmpty(selectedImiId)) {
+                    // This is the first time of the user switch and
+                    // set the current ime to the proper one.
+                    resetDefaultImeLocked(mContext);
+                }
+            } else {
+                // If the locale is changed, needs to reset the default ime
+                resetDefaultImeLocked(mContext);
+            }
+            updateFromSettingsLocked(true);
+            mLastSystemLocale = newLocale;
+            if (!updateOnlyWhenLocaleChanged) {
+                try {
+                    startInputInnerLocked();
+                } catch (RuntimeException e) {
+                    Slog.w(TAG, "Unexpected exception", e);
+                }
+            }
+        }
+    }
+
+    private void resetStateIfCurrentLocaleChangedLocked() {
+        resetAllInternalStateLocked(true /* updateOnlyWhenLocaleChanged */,
+                true /* resetDefaultImeLocked */);
+    }
+
+    private void switchUserLocked(int newUserId) {
+        mSettings.setCurrentUserId(newUserId);
+        // InputMethodFileManager should be reset when the user is changed
+        mFileManager = new InputMethodFileManager(mMethodMap, newUserId);
+        final String defaultImiId = mSettings.getSelectedInputMethod();
+        // For secondary users, the list of enabled IMEs may not have been updated since the
+        // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may
+        // not be empty even if the IME has been uninstalled by the primary user.
+        // Even in such cases, IMMS works fine because it will find the most applicable
+        // IME for that user.
+        final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId);
+        if (DEBUG) {
+            Slog.d(TAG, "Switch user: " + newUserId + " current ime = " + defaultImiId);
+        }
+        resetAllInternalStateLocked(false  /* updateOnlyWhenLocaleChanged */,
+                initialUserSwitch /* needsToResetDefaultIme */);
+        if (initialUserSwitch) {
+            InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mContext.getPackageManager(),
+                    mSettings.getEnabledInputMethodListLocked());
+        }
+    }
+
+    @Override
+    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+            throws RemoteException {
+        try {
+            return super.onTransact(code, data, reply, flags);
+        } catch (RuntimeException e) {
+            // The input method manager only throws security exceptions, so let's
+            // log all others.
+            if (!(e instanceof SecurityException)) {
+                Slog.wtf(TAG, "Input Method Manager Crash", e);
+            }
+            throw e;
+        }
+    }
+
+    public void systemRunning(StatusBarManagerService statusBar) {
+        synchronized (mMethodMap) {
+            if (DEBUG) {
+                Slog.d(TAG, "--- systemReady");
+            }
+            if (!mSystemReady) {
+                mSystemReady = true;
+                mKeyguardManager =
+                        (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
+                mNotificationManager = (NotificationManager)
+                        mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+                mStatusBar = statusBar;
+                statusBar.setIconVisibility("ime", false);
+                updateImeWindowStatusLocked();
+                mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
+                        com.android.internal.R.bool.show_ongoing_ime_switcher);
+                if (mShowOngoingImeSwitcherForPhones) {
+                    mWindowManagerService.setOnHardKeyboardStatusChangeListener(
+                            mHardKeyboardListener);
+                }
+                buildInputMethodListLocked(mMethodList, mMethodMap,
+                        !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
+                if (!mImeSelectedOnBoot) {
+                    Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
+                    resetStateIfCurrentLocaleChangedLocked();
+                    InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(
+                            mContext.getPackageManager(),
+                            mSettings.getEnabledInputMethodListLocked());
+                }
+                mLastSystemLocale = mRes.getConfiguration().locale;
+                try {
+                    startInputInnerLocked();
+                } catch (RuntimeException e) {
+                    Slog.w(TAG, "Unexpected exception", e);
+                }
+            }
+        }
+    }
+
+    private void setImeWindowVisibilityStatusHiddenLocked() {
+        mImeWindowVis = 0;
+        updateImeWindowStatusLocked();
+    }
+
+    private void refreshImeWindowVisibilityLocked() {
+        final Configuration conf = mRes.getConfiguration();
+        final boolean haveHardKeyboard = conf.keyboard
+                != Configuration.KEYBOARD_NOKEYS;
+        final boolean hardKeyShown = haveHardKeyboard
+                && conf.hardKeyboardHidden
+                        != Configuration.HARDKEYBOARDHIDDEN_YES;
+
+        final boolean isScreenLocked = isKeyguardLocked();
+        final boolean inputActive = !isScreenLocked && (mInputShown || hardKeyShown);
+        // We assume the softkeyboard is shown when the input is active as long as the
+        // hard keyboard is not shown.
+        final boolean inputVisible = inputActive && !hardKeyShown;
+        mImeWindowVis = (inputActive ? InputMethodService.IME_ACTIVE : 0)
+                | (inputVisible ? InputMethodService.IME_VISIBLE : 0);
+        updateImeWindowStatusLocked();
+    }
+
+    private void updateImeWindowStatusLocked() {
+        setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition);
+    }
+
+    // ---------------------------------------------------------------------------------------
+    // Check whether or not this is a valid IPC. Assumes an IPC is valid when either
+    // 1) it comes from the system process
+    // 2) the calling process' user id is identical to the current user id IMMS thinks.
+    private boolean calledFromValidUser() {
+        final int uid = Binder.getCallingUid();
+        final int userId = UserHandle.getUserId(uid);
+        if (DEBUG) {
+            Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
+                    + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
+                    + " calling userId = " + userId + ", foreground user id = "
+                    + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid()
+                    + InputMethodUtils.getApiCallStack());
+        }
+        if (uid == Process.SYSTEM_UID || userId == mSettings.getCurrentUserId()) {
+            return true;
+        }
+
+        // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the
+        // foreground user, not for the user of that process. Accordingly InputMethodManagerService
+        // must not manage background users' states in any functions.
+        // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded
+        // by a token.
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+                        == PackageManager.PERMISSION_GRANTED) {
+            if (DEBUG) {
+                Slog.d(TAG, "--- Access granted because the calling process has "
+                        + "the INTERACT_ACROSS_USERS_FULL permission");
+            }
+            return true;
+        }
+        Slog.w(TAG, "--- IPC called from background users. Ignore. \n"
+                + InputMethodUtils.getStackTrace());
+        return false;
+    }
+
+    private boolean bindCurrentInputMethodService(
+            Intent service, ServiceConnection conn, int flags) {
+        if (service == null || conn == null) {
+            Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
+            return false;
+        }
+        return mContext.bindServiceAsUser(service, conn, flags,
+                new UserHandle(mSettings.getCurrentUserId()));
+    }
+
+    @Override
+    public List<InputMethodInfo> getInputMethodList() {
+        // TODO: Make this work even for non-current users?
+        if (!calledFromValidUser()) {
+            return Collections.emptyList();
+        }
+        synchronized (mMethodMap) {
+            return new ArrayList<InputMethodInfo>(mMethodList);
+        }
+    }
+
+    @Override
+    public List<InputMethodInfo> getEnabledInputMethodList() {
+        // TODO: Make this work even for non-current users?
+        if (!calledFromValidUser()) {
+            return Collections.emptyList();
+        }
+        synchronized (mMethodMap) {
+            return mSettings.getEnabledInputMethodListLocked();
+        }
+    }
+
+    private HashMap<InputMethodInfo, List<InputMethodSubtype>>
+            getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked() {
+        HashMap<InputMethodInfo, List<InputMethodSubtype>> enabledInputMethodAndSubtypes =
+                new HashMap<InputMethodInfo, List<InputMethodSubtype>>();
+        for (InputMethodInfo imi: mSettings.getEnabledInputMethodListLocked()) {
+            enabledInputMethodAndSubtypes.put(
+                    imi, mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true));
+        }
+        return enabledInputMethodAndSubtypes;
+    }
+
+    /**
+     * @param imiId if null, returns enabled subtypes for the current imi
+     * @return enabled subtypes of the specified imi
+     */
+    @Override
+    public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId,
+            boolean allowsImplicitlySelectedSubtypes) {
+        // TODO: Make this work even for non-current users?
+        if (!calledFromValidUser()) {
+            return Collections.<InputMethodSubtype>emptyList();
+        }
+        synchronized (mMethodMap) {
+            final InputMethodInfo imi;
+            if (imiId == null && mCurMethodId != null) {
+                imi = mMethodMap.get(mCurMethodId);
+            } else {
+                imi = mMethodMap.get(imiId);
+            }
+            if (imi == null) {
+                return Collections.<InputMethodSubtype>emptyList();
+            }
+            return mSettings.getEnabledInputMethodSubtypeListLocked(
+                    mContext, imi, allowsImplicitlySelectedSubtypes);
+        }
+    }
+
+    @Override
+    public void addClient(IInputMethodClient client,
+            IInputContext inputContext, int uid, int pid) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            mClients.put(client.asBinder(), new ClientState(client,
+                    inputContext, uid, pid));
+        }
+    }
+
+    @Override
+    public void removeClient(IInputMethodClient client) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            ClientState cs = mClients.remove(client.asBinder());
+            if (cs != null) {
+                clearClientSessionLocked(cs);
+            }
+        }
+    }
+
+    void executeOrSendMessage(IInterface target, Message msg) {
+         if (target.asBinder() instanceof Binder) {
+             mCaller.sendMessage(msg);
+         } else {
+             handleMessage(msg);
+             msg.recycle();
+         }
+    }
+
+    void unbindCurrentClientLocked() {
+        if (mCurClient != null) {
+            if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
+                    + mCurClient.client.asBinder());
+            if (mBoundToMethod) {
+                mBoundToMethod = false;
+                if (mCurMethod != null) {
+                    executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
+                            MSG_UNBIND_INPUT, mCurMethod));
+                }
+            }
+
+            executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
+                    MSG_SET_ACTIVE, 0, mCurClient));
+            executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
+                    MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
+            mCurClient.sessionRequested = false;
+            mCurClient = null;
+
+            hideInputMethodMenuLocked();
+        }
+    }
+
+    private int getImeShowFlags() {
+        int flags = 0;
+        if (mShowForced) {
+            flags |= InputMethod.SHOW_FORCED
+                    | InputMethod.SHOW_EXPLICIT;
+        } else if (mShowExplicitlyRequested) {
+            flags |= InputMethod.SHOW_EXPLICIT;
+        }
+        return flags;
+    }
+
+    private int getAppShowFlags() {
+        int flags = 0;
+        if (mShowForced) {
+            flags |= InputMethodManager.SHOW_FORCED;
+        } else if (!mShowExplicitlyRequested) {
+            flags |= InputMethodManager.SHOW_IMPLICIT;
+        }
+        return flags;
+    }
+
+    InputBindResult attachNewInputLocked(boolean initial) {
+        if (!mBoundToMethod) {
+            executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
+                    MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
+            mBoundToMethod = true;
+        }
+        final SessionState session = mCurClient.curSession;
+        if (initial) {
+            executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
+                    MSG_START_INPUT, session, mCurInputContext, mCurAttribute));
+        } else {
+            executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
+                    MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute));
+        }
+        if (mShowRequested) {
+            if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
+            showCurrentInputLocked(getAppShowFlags(), null);
+        }
+        return new InputBindResult(session.session,
+                session.channel != null ? session.channel.dup() : null, mCurId, mCurSeq);
+    }
+
+    InputBindResult startInputLocked(IInputMethodClient client,
+            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
+        // If no method is currently selected, do nothing.
+        if (mCurMethodId == null) {
+            return mNoBinding;
+        }
+
+        ClientState cs = mClients.get(client.asBinder());
+        if (cs == null) {
+            throw new IllegalArgumentException("unknown client "
+                    + client.asBinder());
+        }
+
+        try {
+            if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
+                // Check with the window manager to make sure this client actually
+                // has a window with focus.  If not, reject.  This is thread safe
+                // because if the focus changes some time before or after, the
+                // next client receiving focus that has any interest in input will
+                // be calling through here after that change happens.
+                Slog.w(TAG, "Starting input on non-focused client " + cs.client
+                        + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
+                return null;
+            }
+        } catch (RemoteException e) {
+        }
+
+        return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
+    }
+
+    InputBindResult startInputUncheckedLocked(ClientState cs,
+            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
+        // If no method is currently selected, do nothing.
+        if (mCurMethodId == null) {
+            return mNoBinding;
+        }
+
+        if (mCurClient != cs) {
+            // Was the keyguard locked when switching over to the new client?
+            mCurClientInKeyguard = isKeyguardLocked();
+            // If the client is changing, we need to switch over to the new
+            // one.
+            unbindCurrentClientLocked();
+            if (DEBUG) Slog.v(TAG, "switching to client: client = "
+                    + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard);
+
+            // If the screen is on, inform the new client it is active
+            if (mScreenOn) {
+                executeOrSendMessage(cs.client, mCaller.obtainMessageIO(
+                        MSG_SET_ACTIVE, mScreenOn ? 1 : 0, cs));
+            }
+        }
+
+        // Bump up the sequence for this client and attach it.
+        mCurSeq++;
+        if (mCurSeq <= 0) mCurSeq = 1;
+        mCurClient = cs;
+        mCurInputContext = inputContext;
+        mCurAttribute = attribute;
+
+        // Check if the input method is changing.
+        if (mCurId != null && mCurId.equals(mCurMethodId)) {
+            if (cs.curSession != null) {
+                // Fast case: if we are already connected to the input method,
+                // then just return it.
+                return attachNewInputLocked(
+                        (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0);
+            }
+            if (mHaveConnection) {
+                if (mCurMethod != null) {
+                    // Return to client, and we will get back with it when
+                    // we have had a session made for it.
+                    requestClientSessionLocked(cs);
+                    return new InputBindResult(null, null, mCurId, mCurSeq);
+                } else if (SystemClock.uptimeMillis()
+                        < (mLastBindTime+TIME_TO_RECONNECT)) {
+                    // In this case we have connected to the service, but
+                    // don't yet have its interface.  If it hasn't been too
+                    // long since we did the connection, we'll return to
+                    // the client and wait to get the service interface so
+                    // we can report back.  If it has been too long, we want
+                    // to fall through so we can try a disconnect/reconnect
+                    // to see if we can get back in touch with the service.
+                    return new InputBindResult(null, null, mCurId, mCurSeq);
+                } else {
+                    EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
+                            mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
+                }
+            }
+        }
+
+        return startInputInnerLocked();
+    }
+
+    InputBindResult startInputInnerLocked() {
+        if (mCurMethodId == null) {
+            return mNoBinding;
+        }
+
+        if (!mSystemReady) {
+            // If the system is not yet ready, we shouldn't be running third
+            // party code.
+            return new InputBindResult(null, null, mCurMethodId, mCurSeq);
+        }
+
+        InputMethodInfo info = mMethodMap.get(mCurMethodId);
+        if (info == null) {
+            throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
+        }
+
+        unbindCurrentMethodLocked(false, true);
+
+        mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
+        mCurIntent.setComponent(info.getComponent());
+        mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
+                com.android.internal.R.string.input_method_binding_label);
+        mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
+                mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
+        if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
+                | Context.BIND_NOT_VISIBLE | Context.BIND_SHOWING_UI)) {
+            mLastBindTime = SystemClock.uptimeMillis();
+            mHaveConnection = true;
+            mCurId = info.getId();
+            mCurToken = new Binder();
+            try {
+                if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
+                mIWindowManager.addWindowToken(mCurToken,
+                        WindowManager.LayoutParams.TYPE_INPUT_METHOD);
+            } catch (RemoteException e) {
+            }
+            return new InputBindResult(null, null, mCurId, mCurSeq);
+        } else {
+            mCurIntent = null;
+            Slog.w(TAG, "Failure connecting to input method service: "
+                    + mCurIntent);
+        }
+        return null;
+    }
+
+    @Override
+    public InputBindResult startInput(IInputMethodClient client,
+            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
+        if (!calledFromValidUser()) {
+            return null;
+        }
+        synchronized (mMethodMap) {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return startInputLocked(client, inputContext, attribute, controlFlags);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    @Override
+    public void finishInput(IInputMethodClient client) {
+    }
+
+    @Override
+    public void onServiceConnected(ComponentName name, IBinder service) {
+        synchronized (mMethodMap) {
+            if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
+                mCurMethod = IInputMethod.Stub.asInterface(service);
+                if (mCurToken == null) {
+                    Slog.w(TAG, "Service connected without a token!");
+                    unbindCurrentMethodLocked(false, false);
+                    return;
+                }
+                if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
+                executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
+                        MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
+                if (mCurClient != null) {
+                    clearClientSessionLocked(mCurClient);
+                    requestClientSessionLocked(mCurClient);
+                }
+            }
+        }
+    }
+
+    void onSessionCreated(IInputMethod method, IInputMethodSession session,
+            InputChannel channel) {
+        synchronized (mMethodMap) {
+            if (mCurMethod != null && method != null
+                    && mCurMethod.asBinder() == method.asBinder()) {
+                if (mCurClient != null) {
+                    clearClientSessionLocked(mCurClient);
+                    mCurClient.curSession = new SessionState(mCurClient,
+                            method, session, channel);
+                    InputBindResult res = attachNewInputLocked(true);
+                    if (res.method != null) {
+                        executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
+                                MSG_BIND_METHOD, mCurClient.client, res));
+                    }
+                    return;
+                }
+            }
+        }
+
+        // Session abandoned.  Close its associated input channel.
+        channel.dispose();
+    }
+
+    void unbindCurrentMethodLocked(boolean reportToClient, boolean savePosition) {
+        if (mVisibleBound) {
+            mContext.unbindService(mVisibleConnection);
+            mVisibleBound = false;
+        }
+
+        if (mHaveConnection) {
+            mContext.unbindService(this);
+            mHaveConnection = false;
+        }
+
+        if (mCurToken != null) {
+            try {
+                if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
+                if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) {
+                    // The current IME is shown. Hence an IME switch (transition) is happening.
+                    mWindowManagerService.saveLastInputMethodWindowForTransition();
+                }
+                mIWindowManager.removeWindowToken(mCurToken);
+            } catch (RemoteException e) {
+            }
+            mCurToken = null;
+        }
+
+        mCurId = null;
+        clearCurMethodLocked();
+
+        if (reportToClient && mCurClient != null) {
+            executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
+                    MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
+        }
+    }
+
+    void requestClientSessionLocked(ClientState cs) {
+        if (!cs.sessionRequested) {
+            if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
+            InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString());
+            cs.sessionRequested = true;
+            executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO(
+                    MSG_CREATE_SESSION, mCurMethod, channels[1],
+                    new MethodCallback(this, mCurMethod, channels[0])));
+        }
+    }
+
+    void clearClientSessionLocked(ClientState cs) {
+        finishSessionLocked(cs.curSession);
+        cs.curSession = null;
+        cs.sessionRequested = false;
+    }
+
+    private void finishSessionLocked(SessionState sessionState) {
+        if (sessionState != null) {
+            if (sessionState.session != null) {
+                try {
+                    sessionState.session.finishSession();
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Session failed to close due to remote exception", e);
+                    setImeWindowVisibilityStatusHiddenLocked();
+                }
+                sessionState.session = null;
+            }
+            if (sessionState.channel != null) {
+                sessionState.channel.dispose();
+                sessionState.channel = null;
+            }
+        }
+    }
+
+    void clearCurMethodLocked() {
+        if (mCurMethod != null) {
+            for (ClientState cs : mClients.values()) {
+                clearClientSessionLocked(cs);
+            }
+
+            finishSessionLocked(mEnabledSession);
+            mEnabledSession = null;
+            mCurMethod = null;
+        }
+        if (mStatusBar != null) {
+            mStatusBar.setIconVisibility("ime", false);
+        }
+    }
+
+    @Override
+    public void onServiceDisconnected(ComponentName name) {
+        synchronized (mMethodMap) {
+            if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
+                    + " mCurIntent=" + mCurIntent);
+            if (mCurMethod != null && mCurIntent != null
+                    && name.equals(mCurIntent.getComponent())) {
+                clearCurMethodLocked();
+                // We consider this to be a new bind attempt, since the system
+                // should now try to restart the service for us.
+                mLastBindTime = SystemClock.uptimeMillis();
+                mShowRequested = mInputShown;
+                mInputShown = false;
+                if (mCurClient != null) {
+                    executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
+                            MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
+                }
+            }
+        }
+    }
+
+    @Override
+    public void updateStatusIcon(IBinder token, String packageName, int iconId) {
+        int uid = Binder.getCallingUid();
+        long ident = Binder.clearCallingIdentity();
+        try {
+            if (token == null || mCurToken != token) {
+                Slog.w(TAG, "Ignoring setInputMethod of uid " + uid + " token: " + token);
+                return;
+            }
+
+            synchronized (mMethodMap) {
+                if (iconId == 0) {
+                    if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
+                    if (mStatusBar != null) {
+                        mStatusBar.setIconVisibility("ime", false);
+                    }
+                } else if (packageName != null) {
+                    if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
+                    CharSequence contentDescription = null;
+                    try {
+                        // Use PackageManager to load label
+                        final PackageManager packageManager = mContext.getPackageManager();
+                        contentDescription = packageManager.getApplicationLabel(
+                                mIPackageManager.getApplicationInfo(packageName, 0,
+                                        mSettings.getCurrentUserId()));
+                    } catch (RemoteException e) {
+                        /* ignore */
+                    }
+                    if (mStatusBar != null) {
+                        mStatusBar.setIcon("ime", packageName, iconId, 0,
+                                contentDescription  != null
+                                        ? contentDescription.toString() : null);
+                        mStatusBar.setIconVisibility("ime", true);
+                    }
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private boolean needsToShowImeSwitchOngoingNotification() {
+        if (!mShowOngoingImeSwitcherForPhones) return false;
+        if (isScreenLocked()) return false;
+        synchronized (mMethodMap) {
+            List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
+            final int N = imis.size();
+            if (N > 2) return true;
+            if (N < 1) return false;
+            int nonAuxCount = 0;
+            int auxCount = 0;
+            InputMethodSubtype nonAuxSubtype = null;
+            InputMethodSubtype auxSubtype = null;
+            for(int i = 0; i < N; ++i) {
+                final InputMethodInfo imi = imis.get(i);
+                final List<InputMethodSubtype> subtypes =
+                        mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
+                final int subtypeCount = subtypes.size();
+                if (subtypeCount == 0) {
+                    ++nonAuxCount;
+                } else {
+                    for (int j = 0; j < subtypeCount; ++j) {
+                        final InputMethodSubtype subtype = subtypes.get(j);
+                        if (!subtype.isAuxiliary()) {
+                            ++nonAuxCount;
+                            nonAuxSubtype = subtype;
+                        } else {
+                            ++auxCount;
+                            auxSubtype = subtype;
+                        }
+                    }
+                }
+            }
+            if (nonAuxCount > 1 || auxCount > 1) {
+                return true;
+            } else if (nonAuxCount == 1 && auxCount == 1) {
+                if (nonAuxSubtype != null && auxSubtype != null
+                        && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale())
+                                || auxSubtype.overridesImplicitlyEnabledSubtype()
+                                || nonAuxSubtype.overridesImplicitlyEnabledSubtype())
+                        && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
+                    return false;
+                }
+                return true;
+            }
+            return false;
+        }
+    }
+
+    private boolean isKeyguardLocked() {
+        return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
+    }
+
+    // Caution! This method is called in this class. Handle multi-user carefully
+    @SuppressWarnings("deprecation")
+    @Override
+    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            if (token == null || mCurToken != token) {
+                int uid = Binder.getCallingUid();
+                Slog.w(TAG, "Ignoring setImeWindowStatus of uid " + uid + " token: " + token);
+                return;
+            }
+            synchronized (mMethodMap) {
+                // apply policy for binder calls
+                if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
+                    vis = 0;
+                }
+                mImeWindowVis = vis;
+                mBackDisposition = backDisposition;
+                if (mStatusBar != null) {
+                    mStatusBar.setImeWindowStatus(token, vis, backDisposition);
+                }
+                final boolean iconVisibility = ((vis & (InputMethodService.IME_ACTIVE)) != 0)
+                        && (mWindowManagerService.isHardKeyboardAvailable()
+                                || (vis & (InputMethodService.IME_VISIBLE)) != 0);
+                final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
+                if (imi != null && iconVisibility && needsToShowImeSwitchOngoingNotification()) {
+                    // Used to load label
+                    final CharSequence title = mRes.getText(
+                            com.android.internal.R.string.select_input_method);
+                    final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(
+                            mContext, imi, mCurrentSubtype);
+
+                    mImeSwitcherNotification.setLatestEventInfo(
+                            mContext, title, summary, mImeSwitchPendingIntent);
+                    if (mNotificationManager != null) {
+                        if (DEBUG) {
+                            Slog.d(TAG, "--- show notification: label =  " + summary);
+                        }
+                        mNotificationManager.notifyAsUser(null,
+                                com.android.internal.R.string.select_input_method,
+                                mImeSwitcherNotification, UserHandle.ALL);
+                        mNotificationShown = true;
+                    }
+                } else {
+                    if (mNotificationShown && mNotificationManager != null) {
+                        if (DEBUG) {
+                            Slog.d(TAG, "--- hide notification");
+                        }
+                        mNotificationManager.cancelAsUser(null,
+                                com.android.internal.R.string.select_input_method, UserHandle.ALL);
+                        mNotificationShown = false;
+                    }
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
+            for (int i = 0; i < spans.length; ++i) {
+                SuggestionSpan ss = spans[i];
+                if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) {
+                    mSecureSuggestionSpans.put(ss, currentImi);
+                }
+            }
+        }
+    }
+
+    @Override
+    public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        synchronized (mMethodMap) {
+            final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
+            // TODO: Do not send the intent if the process of the targetImi is already dead.
+            if (targetImi != null) {
+                final String[] suggestions = span.getSuggestions();
+                if (index < 0 || index >= suggestions.length) return false;
+                final String className = span.getNotificationTargetClassName();
+                final Intent intent = new Intent();
+                // Ensures that only a class in the original IME package will receive the
+                // notification.
+                intent.setClassName(targetImi.getPackageName(), className);
+                intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
+                intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
+                intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
+                intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
+                final long ident = Binder.clearCallingIdentity();
+                try {
+                    mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
+                } finally {
+                    Binder.restoreCallingIdentity(ident);
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    void updateFromSettingsLocked(boolean enabledMayChange) {
+        if (enabledMayChange) {
+            List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
+            for (int i=0; i<enabled.size(); i++) {
+                // We allow the user to select "disabled until used" apps, so if they
+                // are enabling one of those here we now need to make it enabled.
+                InputMethodInfo imm = enabled.get(i);
+                try {
+                    ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(),
+                            PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
+                            mSettings.getCurrentUserId());
+                    if (ai != null && ai.enabledSetting
+                            == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
+                        if (DEBUG) {
+                            Slog.d(TAG, "Update state(" + imm.getId()
+                                    + "): DISABLED_UNTIL_USED -> DEFAULT");
+                        }
+                        mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(),
+                                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
+                                PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(),
+                                mContext.getBasePackageName());
+                    }
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
+        // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
+        // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
+        // enabled.
+        String id = mSettings.getSelectedInputMethod();
+        // There is no input method selected, try to choose new applicable input method.
+        if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
+            id = mSettings.getSelectedInputMethod();
+        }
+        if (!TextUtils.isEmpty(id)) {
+            try {
+                setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
+            } catch (IllegalArgumentException e) {
+                Slog.w(TAG, "Unknown input method from prefs: " + id, e);
+                mCurMethodId = null;
+                unbindCurrentMethodLocked(true, false);
+            }
+            mShortcutInputMethodsAndSubtypes.clear();
+        } else {
+            // There is no longer an input method set, so stop any current one.
+            mCurMethodId = null;
+            unbindCurrentMethodLocked(true, false);
+        }
+    }
+
+    /* package */ void setInputMethodLocked(String id, int subtypeId) {
+        InputMethodInfo info = mMethodMap.get(id);
+        if (info == null) {
+            throw new IllegalArgumentException("Unknown id: " + id);
+        }
+
+        // See if we need to notify a subtype change within the same IME.
+        if (id.equals(mCurMethodId)) {
+            final int subtypeCount = info.getSubtypeCount();
+            if (subtypeCount <= 0) {
+                return;
+            }
+            final InputMethodSubtype oldSubtype = mCurrentSubtype;
+            final InputMethodSubtype newSubtype;
+            if (subtypeId >= 0 && subtypeId < subtypeCount) {
+                newSubtype = info.getSubtypeAt(subtypeId);
+            } else {
+                // If subtype is null, try to find the most applicable one from
+                // getCurrentInputMethodSubtype.
+                newSubtype = getCurrentInputMethodSubtypeLocked();
+            }
+            if (newSubtype == null || oldSubtype == null) {
+                Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype
+                        + ", new subtype = " + newSubtype);
+                return;
+            }
+            if (newSubtype != oldSubtype) {
+                setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
+                if (mCurMethod != null) {
+                    try {
+                        refreshImeWindowVisibilityLocked();
+                        mCurMethod.changeInputMethodSubtype(newSubtype);
+                    } catch (RemoteException e) {
+                        Slog.w(TAG, "Failed to call changeInputMethodSubtype");
+                    }
+                }
+            }
+            return;
+        }
+
+        // Changing to a different IME.
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            // Set a subtype to this input method.
+            // subtypeId the name of a subtype which will be set.
+            setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false);
+            // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked()
+            // because mCurMethodId is stored as a history in
+            // setSelectedInputMethodAndSubtypeLocked().
+            mCurMethodId = id;
+
+            if (ActivityManagerNative.isSystemReady()) {
+                Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
+                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+                intent.putExtra("input_method_id", id);
+                mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
+            }
+            unbindCurrentClientLocked();
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public boolean showSoftInput(IInputMethodClient client, int flags,
+            ResultReceiver resultReceiver) {
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        int uid = Binder.getCallingUid();
+        long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (mMethodMap) {
+                if (mCurClient == null || client == null
+                        || mCurClient.client.asBinder() != client.asBinder()) {
+                    try {
+                        // We need to check if this is the current client with
+                        // focus in the window manager, to allow this call to
+                        // be made before input is started in it.
+                        if (!mIWindowManager.inputMethodClientHasFocus(client)) {
+                            Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
+                            return false;
+                        }
+                    } catch (RemoteException e) {
+                        return false;
+                    }
+                }
+
+                if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
+                return showCurrentInputLocked(flags, resultReceiver);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
+        mShowRequested = true;
+        if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
+            mShowExplicitlyRequested = true;
+        }
+        if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
+            mShowExplicitlyRequested = true;
+            mShowForced = true;
+        }
+
+        if (!mSystemReady) {
+            return false;
+        }
+
+        boolean res = false;
+        if (mCurMethod != null) {
+            if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken);
+            executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
+                    MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
+                    resultReceiver));
+            mInputShown = true;
+            if (mHaveConnection && !mVisibleBound) {
+                bindCurrentInputMethodService(
+                        mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE);
+                mVisibleBound = true;
+            }
+            res = true;
+        } else if (mHaveConnection && SystemClock.uptimeMillis()
+                >= (mLastBindTime+TIME_TO_RECONNECT)) {
+            // The client has asked to have the input method shown, but
+            // we have been sitting here too long with a connection to the
+            // service and no interface received, so let's disconnect/connect
+            // to try to prod things along.
+            EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
+                    SystemClock.uptimeMillis()-mLastBindTime,1);
+            Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()");
+            mContext.unbindService(this);
+            bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
+                    | Context.BIND_NOT_VISIBLE);
+        } else {
+            if (DEBUG) {
+                Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = "
+                        + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis()));
+            }
+        }
+
+        return res;
+    }
+
+    @Override
+    public boolean hideSoftInput(IInputMethodClient client, int flags,
+            ResultReceiver resultReceiver) {
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        int uid = Binder.getCallingUid();
+        long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (mMethodMap) {
+                if (mCurClient == null || client == null
+                        || mCurClient.client.asBinder() != client.asBinder()) {
+                    try {
+                        // We need to check if this is the current client with
+                        // focus in the window manager, to allow this call to
+                        // be made before input is started in it.
+                        if (!mIWindowManager.inputMethodClientHasFocus(client)) {
+                            if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
+                                    + uid + ": " + client);
+                            setImeWindowVisibilityStatusHiddenLocked();
+                            return false;
+                        }
+                    } catch (RemoteException e) {
+                        setImeWindowVisibilityStatusHiddenLocked();
+                        return false;
+                    }
+                }
+
+                if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
+                return hideCurrentInputLocked(flags, resultReceiver);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
+        if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
+                && (mShowExplicitlyRequested || mShowForced)) {
+            if (DEBUG) Slog.v(TAG, "Not hiding: explicit show not cancelled by non-explicit hide");
+            return false;
+        }
+        if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
+            if (DEBUG) Slog.v(TAG, "Not hiding: forced show not cancelled by not-always hide");
+            return false;
+        }
+        boolean res;
+        if (mInputShown && mCurMethod != null) {
+            executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
+                    MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
+            res = true;
+        } else {
+            res = false;
+        }
+        if (mHaveConnection && mVisibleBound) {
+            mContext.unbindService(mVisibleConnection);
+            mVisibleBound = false;
+        }
+        mInputShown = false;
+        mShowRequested = false;
+        mShowExplicitlyRequested = false;
+        mShowForced = false;
+        return res;
+    }
+
+    @Override
+    public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken,
+            int controlFlags, int softInputMode, int windowFlags,
+            EditorInfo attribute, IInputContext inputContext) {
+        // Needs to check the validity before clearing calling identity
+        final boolean calledFromValidUser = calledFromValidUser();
+
+        InputBindResult res = null;
+        long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (mMethodMap) {
+                if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
+                        + " controlFlags=#" + Integer.toHexString(controlFlags)
+                        + " softInputMode=#" + Integer.toHexString(softInputMode)
+                        + " windowFlags=#" + Integer.toHexString(windowFlags));
+
+                ClientState cs = mClients.get(client.asBinder());
+                if (cs == null) {
+                    throw new IllegalArgumentException("unknown client "
+                            + client.asBinder());
+                }
+
+                try {
+                    if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
+                        // Check with the window manager to make sure this client actually
+                        // has a window with focus.  If not, reject.  This is thread safe
+                        // because if the focus changes some time before or after, the
+                        // next client receiving focus that has any interest in input will
+                        // be calling through here after that change happens.
+                        Slog.w(TAG, "Focus gain on non-focused client " + cs.client
+                                + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
+                        return null;
+                    }
+                } catch (RemoteException e) {
+                }
+
+                if (!calledFromValidUser) {
+                    Slog.w(TAG, "A background user is requesting window. Hiding IME.");
+                    Slog.w(TAG, "If you want to interect with IME, you need "
+                            + "android.permission.INTERACT_ACROSS_USERS_FULL");
+                    hideCurrentInputLocked(0, null);
+                    return null;
+                }
+
+                if (mCurFocusedWindow == windowToken) {
+                    Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client
+                            + " attribute=" + attribute + ", token = " + windowToken);
+                    if (attribute != null) {
+                        return startInputUncheckedLocked(cs, inputContext, attribute,
+                                controlFlags);
+                    }
+                    return null;
+                }
+                mCurFocusedWindow = windowToken;
+
+                // Should we auto-show the IME even if the caller has not
+                // specified what should be done with it?
+                // We only do this automatically if the window can resize
+                // to accommodate the IME (so what the user sees will give
+                // them good context without input information being obscured
+                // by the IME) or if running on a large screen where there
+                // is more room for the target window + IME.
+                final boolean doAutoShow =
+                        (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
+                                == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
+                        || mRes.getConfiguration().isLayoutSizeAtLeast(
+                                Configuration.SCREENLAYOUT_SIZE_LARGE);
+                final boolean isTextEditor =
+                        (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
+
+                // We want to start input before showing the IME, but after closing
+                // it.  We want to do this after closing it to help the IME disappear
+                // more quickly (not get stuck behind it initializing itself for the
+                // new focused input, even if its window wants to hide the IME).
+                boolean didStart = false;
+                        
+                switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
+                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
+                        if (!isTextEditor || !doAutoShow) {
+                            if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
+                                // There is no focus view, and this window will
+                                // be behind any soft input window, so hide the
+                                // soft input window if it is shown.
+                                if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
+                                hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
+                            }
+                        } else if (isTextEditor && doAutoShow && (softInputMode &
+                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
+                            // There is a focus view, and we are navigating forward
+                            // into the window, so show the input window for the user.
+                            // We only do this automatically if the window can resize
+                            // to accommodate the IME (so what the user sees will give
+                            // them good context without input information being obscured
+                            // by the IME) or if running on a large screen where there
+                            // is more room for the target window + IME.
+                            if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
+                            if (attribute != null) {
+                                res = startInputUncheckedLocked(cs, inputContext, attribute,
+                                        controlFlags);
+                                didStart = true;
+                            }
+                            showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
+                        }
+                        break;
+                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
+                        // Do nothing.
+                        break;
+                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
+                        if ((softInputMode &
+                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
+                            if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
+                            hideCurrentInputLocked(0, null);
+                        }
+                        break;
+                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
+                        if (DEBUG) Slog.v(TAG, "Window asks to hide input");
+                        hideCurrentInputLocked(0, null);
+                        break;
+                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
+                        if ((softInputMode &
+                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
+                            if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
+                            if (attribute != null) {
+                                res = startInputUncheckedLocked(cs, inputContext, attribute,
+                                        controlFlags);
+                                didStart = true;
+                            }
+                            showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
+                        }
+                        break;
+                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
+                        if (DEBUG) Slog.v(TAG, "Window asks to always show input");
+                        if (attribute != null) {
+                            res = startInputUncheckedLocked(cs, inputContext, attribute,
+                                    controlFlags);
+                            didStart = true;
+                        }
+                        showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
+                        break;
+                }
+
+                if (!didStart && attribute != null) {
+                    res = startInputUncheckedLocked(cs, inputContext, attribute,
+                            controlFlags);
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+
+        return res;
+    }
+
+    @Override
+    public void showInputMethodPickerFromClient(IInputMethodClient client) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            if (mCurClient == null || client == null
+                    || mCurClient.client.asBinder() != client.asBinder()) {
+                Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
+                        + Binder.getCallingUid() + ": " + client);
+            }
+
+            // Always call subtype picker, because subtype picker is a superset of input method
+            // picker.
+            mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
+        }
+    }
+
+    @Override
+    public void setInputMethod(IBinder token, String id) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID);
+    }
+
+    @Override
+    public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            if (subtype != null) {
+                setInputMethodWithSubtypeId(token, id, InputMethodUtils.getSubtypeIdFromHashCode(
+                        mMethodMap.get(id), subtype.hashCode()));
+            } else {
+                setInputMethod(token, id);
+            }
+        }
+    }
+
+    @Override
+    public void showInputMethodAndSubtypeEnablerFromClient(
+            IInputMethodClient client, String inputMethodId) {
+        if (!calledFromValidUser()) {
+            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));
+        }
+    }
+
+    @Override
+    public boolean switchToLastInputMethod(IBinder token) {
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        synchronized (mMethodMap) {
+            final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
+            final InputMethodInfo lastImi;
+            if (lastIme != null) {
+                lastImi = mMethodMap.get(lastIme.first);
+            } else {
+                lastImi = null;
+            }
+            String targetLastImiId = null;
+            int subtypeId = NOT_A_SUBTYPE_ID;
+            if (lastIme != null && lastImi != null) {
+                final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
+                final int lastSubtypeHash = Integer.valueOf(lastIme.second);
+                final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
+                        : mCurrentSubtype.hashCode();
+                // If the last IME is the same as the current IME and the last subtype is not
+                // defined, there is no need to switch to the last IME.
+                if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
+                    targetLastImiId = lastIme.first;
+                    subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
+                }
+            }
+
+            if (TextUtils.isEmpty(targetLastImiId)
+                    && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
+                // This is a safety net. If the currentSubtype can't be added to the history
+                // and the framework couldn't find the last ime, we will make the last ime be
+                // the most applicable enabled keyboard subtype of the system imes.
+                final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
+                if (enabled != null) {
+                    final int N = enabled.size();
+                    final String locale = mCurrentSubtype == null
+                            ? mRes.getConfiguration().locale.toString()
+                            : mCurrentSubtype.getLocale();
+                    for (int i = 0; i < N; ++i) {
+                        final InputMethodInfo imi = enabled.get(i);
+                        if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
+                            InputMethodSubtype keyboardSubtype =
+                                    InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes,
+                                            InputMethodUtils.getSubtypes(imi),
+                                            InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
+                            if (keyboardSubtype != null) {
+                                targetLastImiId = imi.getId();
+                                subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
+                                        imi, keyboardSubtype.hashCode());
+                                if(keyboardSubtype.getLocale().equals(locale)) {
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (!TextUtils.isEmpty(targetLastImiId)) {
+                if (DEBUG) {
+                    Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second
+                            + ", from: " + mCurMethodId + ", " + subtypeId);
+                }
+                setInputMethodWithSubtypeId(token, targetLastImiId, subtypeId);
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
+
+    @Override
+    public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        synchronized (mMethodMap) {
+            final ImeSubtypeListItem nextSubtype = mImListManager.getNextInputMethod(
+                    onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype);
+            if (nextSubtype == null) {
+                return false;
+            }
+            setInputMethodWithSubtypeId(token, nextSubtype.mImi.getId(), nextSubtype.mSubtypeId);
+            return true;
+        }
+    }
+
+    @Override
+    public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) {
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        synchronized (mMethodMap) {
+            final ImeSubtypeListItem nextSubtype = mImListManager.getNextInputMethod(
+                    false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype);
+            if (nextSubtype == null) {
+                return false;
+            }
+            return true;
+        }
+    }
+
+    @Override
+    public InputMethodSubtype getLastInputMethodSubtype() {
+        if (!calledFromValidUser()) {
+            return null;
+        }
+        synchronized (mMethodMap) {
+            final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
+            // TODO: Handle the case of the last IME with no subtypes
+            if (lastIme == null || TextUtils.isEmpty(lastIme.first)
+                    || TextUtils.isEmpty(lastIme.second)) return null;
+            final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
+            if (lastImi == null) return null;
+            try {
+                final int lastSubtypeHash = Integer.valueOf(lastIme.second);
+                final int lastSubtypeId =
+                        InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
+                if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
+                    return null;
+                }
+                return lastImi.getSubtypeAt(lastSubtypeId);
+            } catch (NumberFormatException e) {
+                return null;
+            }
+        }
+    }
+
+    @Override
+    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        // By this IPC call, only a process which shares the same uid with the IME can add
+        // additional input method subtypes to the IME.
+        if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0) return;
+        synchronized (mMethodMap) {
+            final InputMethodInfo imi = mMethodMap.get(imiId);
+            if (imi == null) return;
+            final String[] packageInfos;
+            try {
+                packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid());
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Failed to get package infos");
+                return;
+            }
+            if (packageInfos != null) {
+                final int packageNum = packageInfos.length;
+                for (int i = 0; i < packageNum; ++i) {
+                    if (packageInfos[i].equals(imi.getPackageName())) {
+                        mFileManager.addInputMethodSubtypes(imi, subtypes);
+                        final long ident = Binder.clearCallingIdentity();
+                        try {
+                            buildInputMethodListLocked(mMethodList, mMethodMap,
+                                    false /* resetDefaultEnabledIme */);
+                        } finally {
+                            Binder.restoreCallingIdentity(ident);
+                        }
+                        return;
+                    }
+                }
+            }
+        }
+        return;
+    }
+
+    private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
+        synchronized (mMethodMap) {
+            if (token == null) {
+                if (mContext.checkCallingOrSelfPermission(
+                        android.Manifest.permission.WRITE_SECURE_SETTINGS)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    throw new SecurityException(
+                            "Using null token requires permission "
+                            + android.Manifest.permission.WRITE_SECURE_SETTINGS);
+                }
+            } else if (mCurToken != token) {
+                Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
+                        + " token: " + token);
+                return;
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setInputMethodLocked(id, subtypeId);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    @Override
+    public void hideMySoftInput(IBinder token, int flags) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            if (token == null || mCurToken != token) {
+                if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid "
+                        + Binder.getCallingUid() + " token: " + token);
+                return;
+            }
+            long ident = Binder.clearCallingIdentity();
+            try {
+                hideCurrentInputLocked(flags, null);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    @Override
+    public void showMySoftInput(IBinder token, int flags) {
+        if (!calledFromValidUser()) {
+            return;
+        }
+        synchronized (mMethodMap) {
+            if (token == null || mCurToken != token) {
+                Slog.w(TAG, "Ignoring showMySoftInput of uid "
+                        + Binder.getCallingUid() + " token: " + token);
+                return;
+            }
+            long ident = Binder.clearCallingIdentity();
+            try {
+                showCurrentInputLocked(flags, null);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    void setEnabledSessionInMainThread(SessionState session) {
+        if (mEnabledSession != session) {
+            if (mEnabledSession != null) {
+                try {
+                    if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
+                    mEnabledSession.method.setSessionEnabled(
+                            mEnabledSession.session, false);
+                } catch (RemoteException e) {
+                }
+            }
+            mEnabledSession = session;
+            try {
+                if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
+                session.method.setSessionEnabled(
+                        session.session, true);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    @Override
+    public boolean handleMessage(Message msg) {
+        SomeArgs args;
+        switch (msg.what) {
+            case MSG_SHOW_IM_PICKER:
+                showInputMethodMenu();
+                return true;
+
+            case MSG_SHOW_IM_SUBTYPE_PICKER:
+                showInputMethodSubtypeMenu();
+                return true;
+
+            case MSG_SHOW_IM_SUBTYPE_ENABLER:
+                args = (SomeArgs)msg.obj;
+                showInputMethodAndSubtypeEnabler((String)args.arg1);
+                args.recycle();
+                return true;
+
+            case MSG_SHOW_IM_CONFIG:
+                showConfigureInputMethods();
+                return true;
+
+            // ---------------------------------------------------------
+
+            case MSG_UNBIND_INPUT:
+                try {
+                    ((IInputMethod)msg.obj).unbindInput();
+                } catch (RemoteException e) {
+                    // There is nothing interesting about the method dying.
+                }
+                return true;
+            case MSG_BIND_INPUT:
+                args = (SomeArgs)msg.obj;
+                try {
+                    ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
+                } catch (RemoteException e) {
+                }
+                args.recycle();
+                return true;
+            case MSG_SHOW_SOFT_INPUT:
+                args = (SomeArgs)msg.obj;
+                try {
+                    if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput("
+                            + msg.arg1 + ", " + args.arg2 + ")");
+                    ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2);
+                } catch (RemoteException e) {
+                }
+                args.recycle();
+                return true;
+            case MSG_HIDE_SOFT_INPUT:
+                args = (SomeArgs)msg.obj;
+                try {
+                    if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, "
+                            + args.arg2 + ")");
+                    ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2);
+                } catch (RemoteException e) {
+                }
+                args.recycle();
+                return true;
+            case MSG_ATTACH_TOKEN:
+                args = (SomeArgs)msg.obj;
+                try {
+                    if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
+                    ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
+                } catch (RemoteException e) {
+                }
+                args.recycle();
+                return true;
+            case MSG_CREATE_SESSION: {
+                args = (SomeArgs)msg.obj;
+                IInputMethod method = (IInputMethod)args.arg1;
+                InputChannel channel = (InputChannel)args.arg2;
+                try {
+                    method.createSession(channel, (IInputSessionCallback)args.arg3);
+                } catch (RemoteException e) {
+                } finally {
+                    // Dispose the channel if the input method is not local to this process
+                    // because the remote proxy will get its own copy when unparceled.
+                    if (channel != null && Binder.isProxy(method)) {
+                        channel.dispose();
+                    }
+                }
+                args.recycle();
+                return true;
+            }
+            // ---------------------------------------------------------
+
+            case MSG_START_INPUT:
+                args = (SomeArgs)msg.obj;
+                try {
+                    SessionState session = (SessionState)args.arg1;
+                    setEnabledSessionInMainThread(session);
+                    session.method.startInput((IInputContext)args.arg2,
+                            (EditorInfo)args.arg3);
+                } catch (RemoteException e) {
+                }
+                args.recycle();
+                return true;
+            case MSG_RESTART_INPUT:
+                args = (SomeArgs)msg.obj;
+                try {
+                    SessionState session = (SessionState)args.arg1;
+                    setEnabledSessionInMainThread(session);
+                    session.method.restartInput((IInputContext)args.arg2,
+                            (EditorInfo)args.arg3);
+                } catch (RemoteException e) {
+                }
+                args.recycle();
+                return true;
+
+            // ---------------------------------------------------------
+
+            case MSG_UNBIND_METHOD:
+                try {
+                    ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1);
+                } catch (RemoteException e) {
+                    // There is nothing interesting about the last client dying.
+                }
+                return true;
+            case MSG_BIND_METHOD: {
+                args = (SomeArgs)msg.obj;
+                IInputMethodClient client = (IInputMethodClient)args.arg1;
+                InputBindResult res = (InputBindResult)args.arg2;
+                try {
+                    client.onBindMethod(res);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Client died receiving input method " + args.arg2);
+                } finally {
+                    // Dispose the channel if the input method is not local to this process
+                    // because the remote proxy will get its own copy when unparceled.
+                    if (res.channel != null && Binder.isProxy(client)) {
+                        res.channel.dispose();
+                    }
+                }
+                args.recycle();
+                return true;
+            }
+            case MSG_SET_ACTIVE:
+                try {
+                    ((ClientState)msg.obj).client.setActive(msg.arg1 != 0);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
+                            + ((ClientState)msg.obj).pid + " uid "
+                            + ((ClientState)msg.obj).uid);
+                }
+                return true;
+
+            // --------------------------------------------------------------
+            case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
+                mHardKeyboardListener.handleHardKeyboardStatusChange(
+                        msg.arg1 == 1, msg.arg2 == 1);
+                return true;
+        }
+        return false;
+    }
+
+    private boolean chooseNewDefaultIMELocked() {
+        final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
+                mSettings.getEnabledInputMethodListLocked());
+        if (imi != null) {
+            if (DEBUG) {
+                Slog.d(TAG, "New default IME was selected: " + imi.getId());
+            }
+            resetSelectedInputMethodAndSubtypeLocked(imi.getId());
+            return true;
+        }
+
+        return false;
+    }
+
+    void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
+            HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
+        if (DEBUG) {
+            Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
+                    + " \n ------ \n" + InputMethodUtils.getStackTrace());
+        }
+        list.clear();
+        map.clear();
+
+        // Use for queryIntentServicesAsUser
+        final PackageManager pm = mContext.getPackageManager();
+        String disabledSysImes = mSettings.getDisabledSystemInputMethods();
+        if (disabledSysImes == null) disabledSysImes = "";
+
+        final List<ResolveInfo> services = pm.queryIntentServicesAsUser(
+                new Intent(InputMethod.SERVICE_INTERFACE),
+                PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
+                mSettings.getCurrentUserId());
+
+        final HashMap<String, List<InputMethodSubtype>> additionalSubtypes =
+                mFileManager.getAllAdditionalInputMethodSubtypes();
+        for (int i = 0; i < services.size(); ++i) {
+            ResolveInfo ri = services.get(i);
+            ServiceInfo si = ri.serviceInfo;
+            ComponentName compName = new ComponentName(si.packageName, si.name);
+            if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
+                    si.permission)) {
+                Slog.w(TAG, "Skipping input method " + compName
+                        + ": it does not require the permission "
+                        + android.Manifest.permission.BIND_INPUT_METHOD);
+                continue;
+            }
+
+            if (DEBUG) Slog.d(TAG, "Checking " + compName);
+
+            try {
+                InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
+                list.add(p);
+                final String id = p.getId();
+                map.put(id, p);
+
+                if (DEBUG) {
+                    Slog.d(TAG, "Found an input method " + p);
+                }
+
+            } catch (XmlPullParserException e) {
+                Slog.w(TAG, "Unable to load input method " + compName, e);
+            } catch (IOException e) {
+                Slog.w(TAG, "Unable to load input method " + compName, e);
+            }
+        }
+
+        if (resetDefaultEnabledIme) {
+            final ArrayList<InputMethodInfo> defaultEnabledIme =
+                    InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
+            for (int i = 0; i < defaultEnabledIme.size(); ++i) {
+                final InputMethodInfo imi =  defaultEnabledIme.get(i);
+                if (DEBUG) {
+                    Slog.d(TAG, "--- enable ime = " + imi);
+                }
+                setInputMethodEnabledLocked(imi.getId(), true);
+            }
+        }
+
+        final String defaultImiId = mSettings.getSelectedInputMethod();
+        if (!TextUtils.isEmpty(defaultImiId)) {
+            if (!map.containsKey(defaultImiId)) {
+                Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
+                if (chooseNewDefaultIMELocked()) {
+                    updateFromSettingsLocked(true);
+                }
+            } else {
+                // Double check that the default IME is certainly enabled.
+                setInputMethodEnabledLocked(defaultImiId, true);
+            }
+        }
+    }
+
+    // ----------------------------------------------------------------------
+
+    private void showInputMethodMenu() {
+        showInputMethodMenuInternal(false);
+    }
+
+    private void showInputMethodSubtypeMenu() {
+        showInputMethodMenuInternal(true);
+    }
+
+    private void showInputMethodAndSubtypeEnabler(String inputMethodId) {
+        Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
+                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        if (!TextUtils.isEmpty(inputMethodId)) {
+            intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId);
+        }
+        mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
+    }
+
+    private void showConfigureInputMethods() {
+        Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
+                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
+    }
+
+    private boolean isScreenLocked() {
+        return mKeyguardManager != null
+                && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure();
+    }
+    private void showInputMethodMenuInternal(boolean showSubtypes) {
+        if (DEBUG) Slog.v(TAG, "Show switching menu");
+
+        final Context context = mContext;
+        final boolean isScreenLocked = isScreenLocked();
+
+        final String lastInputMethodId = mSettings.getSelectedInputMethod();
+        int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
+        if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
+
+        synchronized (mMethodMap) {
+            final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
+                    getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
+            if (immis == null || immis.size() == 0) {
+                return;
+            }
+
+            hideInputMethodMenuLocked();
+
+            final List<ImeSubtypeListItem> imList =
+                    mImListManager.getSortedInputMethodAndSubtypeList(
+                            showSubtypes, mInputShown, isScreenLocked);
+
+            if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
+                final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
+                if (currentSubtype != null) {
+                    final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
+                    lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
+                            currentImi, currentSubtype.hashCode());
+                }
+            }
+
+            final int N = imList.size();
+            mIms = new InputMethodInfo[N];
+            mSubtypeIds = new int[N];
+            int checkedItem = 0;
+            for (int i = 0; i < N; ++i) {
+                final ImeSubtypeListItem item = imList.get(i);
+                mIms[i] = item.mImi;
+                mSubtypeIds[i] = item.mSubtypeId;
+                if (mIms[i].getId().equals(lastInputMethodId)) {
+                    int subtypeId = mSubtypeIds[i];
+                    if ((subtypeId == NOT_A_SUBTYPE_ID)
+                            || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
+                            || (subtypeId == lastInputMethodSubtypeId)) {
+                        checkedItem = i;
+                    }
+                }
+            }
+            final TypedArray a = context.obtainStyledAttributes(null,
+                    com.android.internal.R.styleable.DialogPreference,
+                    com.android.internal.R.attr.alertDialogStyle, 0);
+            mDialogBuilder = new AlertDialog.Builder(context)
+                    .setOnCancelListener(new OnCancelListener() {
+                        @Override
+                        public void onCancel(DialogInterface dialog) {
+                            hideInputMethodMenu();
+                        }
+                    })
+                    .setIcon(a.getDrawable(
+                            com.android.internal.R.styleable.DialogPreference_dialogTitle));
+            a.recycle();
+            final LayoutInflater inflater =
+                    (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+            final View tv = inflater.inflate(
+                    com.android.internal.R.layout.input_method_switch_dialog_title, null);
+            mDialogBuilder.setCustomTitle(tv);
+
+            // Setup layout for a toggle switch of the hardware keyboard
+            mSwitchingDialogTitleView = tv;
+            mSwitchingDialogTitleView.findViewById(
+                    com.android.internal.R.id.hard_keyboard_section).setVisibility(
+                            mWindowManagerService.isHardKeyboardAvailable() ?
+                                    View.VISIBLE : View.GONE);
+            final Switch hardKeySwitch =  ((Switch)mSwitchingDialogTitleView.findViewById(
+                    com.android.internal.R.id.hard_keyboard_switch));
+            hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
+            hardKeySwitch.setOnCheckedChangeListener(
+                    new OnCheckedChangeListener() {
+                        @Override
+                        public void onCheckedChanged(
+                                CompoundButton buttonView, boolean isChecked) {
+                            mWindowManagerService.setHardKeyboardEnabled(isChecked);
+                            // Ensure that the input method dialog is dismissed when changing
+                            // the hardware keyboard state.
+                            hideInputMethodMenu();
+                        }
+                    });
+
+            final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context,
+                    com.android.internal.R.layout.simple_list_item_2_single_choice, imList,
+                    checkedItem);
+
+            mDialogBuilder.setSingleChoiceItems(adapter, checkedItem,
+                    new AlertDialog.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            synchronized (mMethodMap) {
+                                if (mIms == null || mIms.length <= which
+                                        || mSubtypeIds == null || mSubtypeIds.length <= which) {
+                                    return;
+                                }
+                                InputMethodInfo im = mIms[which];
+                                int subtypeId = mSubtypeIds[which];
+                                adapter.mCheckedItem = which;
+                                adapter.notifyDataSetChanged();
+                                hideInputMethodMenu();
+                                if (im != null) {
+                                    if ((subtypeId < 0)
+                                            || (subtypeId >= im.getSubtypeCount())) {
+                                        subtypeId = NOT_A_SUBTYPE_ID;
+                                    }
+                                    setInputMethodLocked(im.getId(), subtypeId);
+                                }
+                            }
+                        }
+                    });
+
+            if (showSubtypes && !isScreenLocked) {
+                mDialogBuilder.setPositiveButton(
+                        com.android.internal.R.string.configure_input_methods,
+                        new DialogInterface.OnClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialog, int whichButton) {
+                                showConfigureInputMethods();
+                            }
+                        });
+            }
+            mSwitchingDialog = mDialogBuilder.create();
+            mSwitchingDialog.setCanceledOnTouchOutside(true);
+            mSwitchingDialog.getWindow().setType(
+                    WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
+            mSwitchingDialog.getWindow().getAttributes().privateFlags |=
+                    WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
+            mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
+            mSwitchingDialog.show();
+        }
+    }
+
+    private static class ImeSubtypeListItem implements Comparable<ImeSubtypeListItem> {
+        public final CharSequence mImeName;
+        public final CharSequence mSubtypeName;
+        public final InputMethodInfo mImi;
+        public final int mSubtypeId;
+        private final boolean mIsSystemLocale;
+        private final boolean mIsSystemLanguage;
+
+        public ImeSubtypeListItem(CharSequence imeName, CharSequence subtypeName,
+                InputMethodInfo imi, int subtypeId, String subtypeLocale, String systemLocale) {
+            mImeName = imeName;
+            mSubtypeName = subtypeName;
+            mImi = imi;
+            mSubtypeId = subtypeId;
+            if (TextUtils.isEmpty(subtypeLocale)) {
+                mIsSystemLocale = false;
+                mIsSystemLanguage = false;
+            } else {
+                mIsSystemLocale = subtypeLocale.equals(systemLocale);
+                mIsSystemLanguage = mIsSystemLocale
+                        || subtypeLocale.startsWith(systemLocale.substring(0, 2));
+            }
+        }
+
+        @Override
+        public int compareTo(ImeSubtypeListItem other) {
+            if (TextUtils.isEmpty(mImeName)) {
+                return 1;
+            }
+            if (TextUtils.isEmpty(other.mImeName)) {
+                return -1;
+            }
+            if (!TextUtils.equals(mImeName, other.mImeName)) {
+                return mImeName.toString().compareTo(other.mImeName.toString());
+            }
+            if (TextUtils.equals(mSubtypeName, other.mSubtypeName)) {
+                return 0;
+            }
+            if (mIsSystemLocale) {
+                return -1;
+            }
+            if (other.mIsSystemLocale) {
+                return 1;
+            }
+            if (mIsSystemLanguage) {
+                return -1;
+            }
+            if (other.mIsSystemLanguage) {
+                return 1;
+            }
+            if (TextUtils.isEmpty(mSubtypeName)) {
+                return 1;
+            }
+            if (TextUtils.isEmpty(other.mSubtypeName)) {
+                return -1;
+            }
+            return mSubtypeName.toString().compareTo(other.mSubtypeName.toString());
+        }
+    }
+
+    private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> {
+        private final LayoutInflater mInflater;
+        private final int mTextViewResourceId;
+        private final List<ImeSubtypeListItem> mItemsList;
+        public int mCheckedItem;
+        public ImeSubtypeListAdapter(Context context, int textViewResourceId,
+                List<ImeSubtypeListItem> itemsList, int checkedItem) {
+            super(context, textViewResourceId, itemsList);
+            mTextViewResourceId = textViewResourceId;
+            mItemsList = itemsList;
+            mCheckedItem = checkedItem;
+            mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        }
+
+        @Override
+        public View getView(int position, View convertView, ViewGroup parent) {
+            final View view = convertView != null ? convertView
+                    : mInflater.inflate(mTextViewResourceId, null);
+            if (position < 0 || position >= mItemsList.size()) return view;
+            final ImeSubtypeListItem item = mItemsList.get(position);
+            final CharSequence imeName = item.mImeName;
+            final CharSequence subtypeName = item.mSubtypeName;
+            final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1);
+            final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2);
+            if (TextUtils.isEmpty(subtypeName)) {
+                firstTextView.setText(imeName);
+                secondTextView.setVisibility(View.GONE);
+            } else {
+                firstTextView.setText(subtypeName);
+                secondTextView.setText(imeName);
+                secondTextView.setVisibility(View.VISIBLE);
+            }
+            final RadioButton radioButton =
+                    (RadioButton)view.findViewById(com.android.internal.R.id.radio);
+            radioButton.setChecked(position == mCheckedItem);
+            return view;
+        }
+    }
+
+    void hideInputMethodMenu() {
+        synchronized (mMethodMap) {
+            hideInputMethodMenuLocked();
+        }
+    }
+
+    void hideInputMethodMenuLocked() {
+        if (DEBUG) Slog.v(TAG, "Hide switching menu");
+
+        if (mSwitchingDialog != null) {
+            mSwitchingDialog.dismiss();
+            mSwitchingDialog = null;
+        }
+
+        mDialogBuilder = null;
+        mIms = null;
+    }
+
+    // ----------------------------------------------------------------------
+
+    @Override
+    public boolean setInputMethodEnabled(String id, boolean enabled) {
+        // TODO: Make this work even for non-current users?
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        synchronized (mMethodMap) {
+            if (mContext.checkCallingOrSelfPermission(
+                    android.Manifest.permission.WRITE_SECURE_SETTINGS)
+                    != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException(
+                        "Requires permission "
+                        + android.Manifest.permission.WRITE_SECURE_SETTINGS);
+            }
+            
+            long ident = Binder.clearCallingIdentity();
+            try {
+                return setInputMethodEnabledLocked(id, enabled);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    boolean setInputMethodEnabledLocked(String id, boolean enabled) {
+        // Make sure this is a valid input method.
+        InputMethodInfo imm = mMethodMap.get(id);
+        if (imm == null) {
+            throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
+        }
+
+        List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
+                .getEnabledInputMethodsAndSubtypeListLocked();
+
+        if (enabled) {
+            for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
+                if (pair.first.equals(id)) {
+                    // We are enabling this input method, but it is already enabled.
+                    // Nothing to do. The previous state was enabled.
+                    return true;
+                }
+            }
+            mSettings.appendAndPutEnabledInputMethodLocked(id, false);
+            // Previous state was disabled.
+            return false;
+        } else {
+            StringBuilder builder = new StringBuilder();
+            if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
+                    builder, enabledInputMethodsList, id)) {
+                // Disabled input method is currently selected, switch to another one.
+                final String selId = mSettings.getSelectedInputMethod();
+                if (id.equals(selId) && !chooseNewDefaultIMELocked()) {
+                    Slog.i(TAG, "Can't find new IME, unsetting the current input method.");
+                    resetSelectedInputMethodAndSubtypeLocked("");
+                }
+                // Previous state was enabled.
+                return true;
+            } else {
+                // We are disabling the input method but it is already disabled.
+                // Nothing to do.  The previous state was disabled.
+                return false;
+            }
+        }
+    }
+
+    private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId,
+            boolean setSubtypeOnly) {
+        // Update the history of InputMethod and Subtype
+        mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype);
+
+        // Set Subtype here
+        if (imi == null || subtypeId < 0) {
+            mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
+            mCurrentSubtype = null;
+        } else {
+            if (subtypeId < imi.getSubtypeCount()) {
+                InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId);
+                mSettings.putSelectedSubtype(subtype.hashCode());
+                mCurrentSubtype = subtype;
+            } else {
+                mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
+                // If the subtype is not specified, choose the most applicable one
+                mCurrentSubtype = getCurrentInputMethodSubtypeLocked();
+            }
+        }
+
+        // Workaround.
+        // ASEC is not ready in the IMMS constructor. Accordingly, forward-locked
+        // IMEs are not recognized and considered uninstalled.
+        // Actually, we can't move everything after SystemReady because
+        // IMMS needs to run in the encryption lock screen. So, we just skip changing
+        // the default IME here and try cheking the default IME again in systemReady().
+        // TODO: Do nothing before system ready and implement a separated logic for
+        // the encryption lock screen.
+        // TODO: ASEC should be ready before IMMS is instantiated.
+        if (mSystemReady && !setSubtypeOnly) {
+            // Set InputMethod here
+            mSettings.putSelectedInputMethod(imi != null ? imi.getId() : "");
+        }
+    }
+
+    private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
+        InputMethodInfo imi = mMethodMap.get(newDefaultIme);
+        int lastSubtypeId = NOT_A_SUBTYPE_ID;
+        // newDefaultIme is empty when there is no candidate for the selected IME.
+        if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
+            String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
+            if (subtypeHashCode != null) {
+                try {
+                    lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
+                            imi, Integer.valueOf(subtypeHashCode));
+                } catch (NumberFormatException e) {
+                    Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
+                }
+            }
+        }
+        setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
+    }
+
+    // If there are no selected shortcuts, tries finding the most applicable ones.
+    private Pair<InputMethodInfo, InputMethodSubtype>
+            findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
+        List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
+        InputMethodInfo mostApplicableIMI = null;
+        InputMethodSubtype mostApplicableSubtype = null;
+        boolean foundInSystemIME = false;
+
+        // Search applicable subtype for each InputMethodInfo
+        for (InputMethodInfo imi: imis) {
+            final String imiId = imi.getId();
+            if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
+                continue;
+            }
+            InputMethodSubtype subtype = null;
+            final List<InputMethodSubtype> enabledSubtypes =
+                    mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
+            // 1. Search by the current subtype's locale from enabledSubtypes.
+            if (mCurrentSubtype != null) {
+                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
+                        mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
+            }
+            // 2. Search by the system locale from enabledSubtypes.
+            // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
+            if (subtype == null) {
+                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
+                        mRes, enabledSubtypes, mode, null, true);
+            }
+            final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
+                    InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
+            final ArrayList<InputMethodSubtype> subtypesForSearch =
+                    overridingImplicitlyEnabledSubtypes.isEmpty()
+                            ? InputMethodUtils.getSubtypes(imi)
+                            : overridingImplicitlyEnabledSubtypes;
+            // 4. Search by the current subtype's locale from all subtypes.
+            if (subtype == null && mCurrentSubtype != null) {
+                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
+                        mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
+            }
+            // 5. Search by the system locale from all subtypes.
+            // 6. Search the first enabled subtype matched with mode from all subtypes.
+            if (subtype == null) {
+                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
+                        mRes, subtypesForSearch, mode, null, true);
+            }
+            if (subtype != null) {
+                if (imiId.equals(mCurMethodId)) {
+                    // The current input method is the most applicable IME.
+                    mostApplicableIMI = imi;
+                    mostApplicableSubtype = subtype;
+                    break;
+                } else if (!foundInSystemIME) {
+                    // The system input method is 2nd applicable IME.
+                    mostApplicableIMI = imi;
+                    mostApplicableSubtype = subtype;
+                    if ((imi.getServiceInfo().applicationInfo.flags
+                            & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                        foundInSystemIME = true;
+                    }
+                }
+            }
+        }
+        if (DEBUG) {
+            if (mostApplicableIMI != null) {
+                Slog.w(TAG, "Most applicable shortcut input method was:"
+                        + mostApplicableIMI.getId());
+                if (mostApplicableSubtype != null) {
+                    Slog.w(TAG, "Most applicable shortcut input method subtype was:"
+                            + "," + mostApplicableSubtype.getMode() + ","
+                            + mostApplicableSubtype.getLocale());
+                }
+            }
+        }
+        if (mostApplicableIMI != null) {
+            return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI,
+                    mostApplicableSubtype);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * @return Return the current subtype of this input method.
+     */
+    @Override
+    public InputMethodSubtype getCurrentInputMethodSubtype() {
+        // TODO: Make this work even for non-current users?
+        if (!calledFromValidUser()) {
+            return null;
+        }
+        synchronized (mMethodMap) {
+            return getCurrentInputMethodSubtypeLocked();
+        }
+    }
+
+    private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
+        if (mCurMethodId == null) {
+            return null;
+        }
+        final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
+        final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
+        if (imi == null || imi.getSubtypeCount() == 0) {
+            return null;
+        }
+        if (!subtypeIsSelected || mCurrentSubtype == null
+                || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
+            int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
+            if (subtypeId == NOT_A_SUBTYPE_ID) {
+                // If there are no selected subtypes, the framework will try to find
+                // the most applicable subtype from explicitly or implicitly enabled
+                // subtypes.
+                List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes =
+                        mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
+                // If there is only one explicitly or implicitly enabled subtype,
+                // just returns it.
+                if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
+                    mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
+                } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
+                    mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
+                            mRes, explicitlyOrImplicitlyEnabledSubtypes,
+                            InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
+                    if (mCurrentSubtype == null) {
+                        mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
+                                mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null,
+                                true);
+                    }
+                }
+            } else {
+                mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
+            }
+        }
+        return mCurrentSubtype;
+    }
+
+    private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi,
+            InputMethodSubtype subtype) {
+        if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) {
+            mShortcutInputMethodsAndSubtypes.get(imi).add(subtype);
+        } else {
+            ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
+            subtypes.add(subtype);
+            mShortcutInputMethodsAndSubtypes.put(imi, subtypes);
+        }
+    }
+
+    // TODO: We should change the return type from List to List<Parcelable>
+    @SuppressWarnings("rawtypes")
+    @Override
+    public List getShortcutInputMethodsAndSubtypes() {
+        synchronized (mMethodMap) {
+            ArrayList<Object> ret = new ArrayList<Object>();
+            if (mShortcutInputMethodsAndSubtypes.size() == 0) {
+                // If there are no selected shortcut subtypes, the framework will try to find
+                // the most applicable subtype from all subtypes whose mode is
+                // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode.
+                Pair<InputMethodInfo, InputMethodSubtype> info =
+                    findLastResortApplicableShortcutInputMethodAndSubtypeLocked(
+                            InputMethodUtils.SUBTYPE_MODE_VOICE);
+                if (info != null) {
+                    ret.add(info.first);
+                    ret.add(info.second);
+                }
+                return ret;
+            }
+            for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) {
+                ret.add(imi);
+                for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) {
+                    ret.add(subtype);
+                }
+            }
+            return ret;
+        }
+    }
+
+    @Override
+    public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) {
+        // TODO: Make this work even for non-current users?
+        if (!calledFromValidUser()) {
+            return false;
+        }
+        synchronized (mMethodMap) {
+            if (subtype != null && mCurMethodId != null) {
+                InputMethodInfo imi = mMethodMap.get(mCurMethodId);
+                int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode());
+                if (subtypeId != NOT_A_SUBTYPE_ID) {
+                    setInputMethodLocked(mCurMethodId, subtypeId);
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    private static class InputMethodAndSubtypeListManager {
+        private final Context mContext;
+        // Used to load label
+        private final PackageManager mPm;
+        private final InputMethodManagerService mImms;
+        private final String mSystemLocaleStr;
+        public InputMethodAndSubtypeListManager(Context context, InputMethodManagerService imms) {
+            mContext = context;
+            mPm = context.getPackageManager();
+            mImms = imms;
+            final Locale locale = context.getResources().getConfiguration().locale;
+            mSystemLocaleStr = locale != null ? locale.toString() : "";
+        }
+
+        private final TreeMap<InputMethodInfo, List<InputMethodSubtype>> mSortedImmis =
+                new TreeMap<InputMethodInfo, List<InputMethodSubtype>>(
+                        new Comparator<InputMethodInfo>() {
+                            @Override
+                            public int compare(InputMethodInfo imi1, InputMethodInfo imi2) {
+                                if (imi2 == null) return 0;
+                                if (imi1 == null) return 1;
+                                if (mPm == null) {
+                                    return imi1.getId().compareTo(imi2.getId());
+                                }
+                                CharSequence imiId1 = imi1.loadLabel(mPm) + "/" + imi1.getId();
+                                CharSequence imiId2 = imi2.loadLabel(mPm) + "/" + imi2.getId();
+                                return imiId1.toString().compareTo(imiId2.toString());
+                            }
+                        });
+
+        public ImeSubtypeListItem getNextInputMethod(
+                boolean onlyCurrentIme, InputMethodInfo imi, InputMethodSubtype subtype) {
+            if (imi == null) {
+                return null;
+            }
+            final List<ImeSubtypeListItem> imList = getSortedInputMethodAndSubtypeList();
+            if (imList.size() <= 1) {
+                return null;
+            }
+            final int N = imList.size();
+            final int currentSubtypeId = subtype != null
+                    ? InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode())
+                    : NOT_A_SUBTYPE_ID;
+            for (int i = 0; i < N; ++i) {
+                final ImeSubtypeListItem isli = imList.get(i);
+                if (isli.mImi.equals(imi) && isli.mSubtypeId == currentSubtypeId) {
+                    if (!onlyCurrentIme) {
+                        return imList.get((i + 1) % N);
+                    }
+                    for (int j = 0; j < N - 1; ++j) {
+                        final ImeSubtypeListItem candidate = imList.get((i + j + 1) % N);
+                        if (candidate.mImi.equals(imi)) {
+                            return candidate;
+                        }
+                    }
+                    return null;
+                }
+            }
+            return null;
+        }
+
+        public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList() {
+            return getSortedInputMethodAndSubtypeList(true, false, false);
+        }
+
+        public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(boolean showSubtypes,
+                boolean inputShown, boolean isScreenLocked) {
+            final ArrayList<ImeSubtypeListItem> imList = new ArrayList<ImeSubtypeListItem>();
+            final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
+                    mImms.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
+            if (immis == null || immis.size() == 0) {
+                return Collections.emptyList();
+            }
+            mSortedImmis.clear();
+            mSortedImmis.putAll(immis);
+            for (InputMethodInfo imi : mSortedImmis.keySet()) {
+                if (imi == null) continue;
+                List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi);
+                HashSet<String> enabledSubtypeSet = new HashSet<String>();
+                for (InputMethodSubtype subtype: explicitlyOrImplicitlyEnabledSubtypeList) {
+                    enabledSubtypeSet.add(String.valueOf(subtype.hashCode()));
+                }
+                final CharSequence imeLabel = imi.loadLabel(mPm);
+                if (showSubtypes && enabledSubtypeSet.size() > 0) {
+                    final int subtypeCount = imi.getSubtypeCount();
+                    if (DEBUG) {
+                        Slog.v(TAG, "Add subtypes: " + subtypeCount + ", " + imi.getId());
+                    }
+                    for (int j = 0; j < subtypeCount; ++j) {
+                        final InputMethodSubtype subtype = imi.getSubtypeAt(j);
+                        final String subtypeHashCode = String.valueOf(subtype.hashCode());
+                        // We show all enabled IMEs and subtypes when an IME is shown.
+                        if (enabledSubtypeSet.contains(subtypeHashCode)
+                                && ((inputShown && !isScreenLocked) || !subtype.isAuxiliary())) {
+                            final CharSequence subtypeLabel =
+                                    subtype.overridesImplicitlyEnabledSubtype() ? null
+                                            : subtype.getDisplayName(mContext, imi.getPackageName(),
+                                                    imi.getServiceInfo().applicationInfo);
+                            imList.add(new ImeSubtypeListItem(imeLabel, subtypeLabel, imi, j,
+                                    subtype.getLocale(), mSystemLocaleStr));
+
+                            // Removing this subtype from enabledSubtypeSet because we no longer
+                            // need to add an entry of this subtype to imList to avoid duplicated
+                            // entries.
+                            enabledSubtypeSet.remove(subtypeHashCode);
+                        }
+                    }
+                } else {
+                    imList.add(new ImeSubtypeListItem(imeLabel, null, imi, NOT_A_SUBTYPE_ID,
+                            null, mSystemLocaleStr));
+                }
+            }
+            Collections.sort(imList);
+            return imList;
+        }
+    }
+
+    // TODO: Cache the state for each user and reset when the cached user is removed.
+    private static class InputMethodFileManager {
+        private static final String SYSTEM_PATH = "system";
+        private static final String INPUT_METHOD_PATH = "inputmethod";
+        private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml";
+        private static final String NODE_SUBTYPES = "subtypes";
+        private static final String NODE_SUBTYPE = "subtype";
+        private static final String NODE_IMI = "imi";
+        private static final String ATTR_ID = "id";
+        private static final String ATTR_LABEL = "label";
+        private static final String ATTR_ICON = "icon";
+        private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
+        private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode";
+        private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue";
+        private static final String ATTR_IS_AUXILIARY = "isAuxiliary";
+        private final AtomicFile mAdditionalInputMethodSubtypeFile;
+        private final HashMap<String, InputMethodInfo> mMethodMap;
+        private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap =
+                new HashMap<String, List<InputMethodSubtype>>();
+        public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) {
+            if (methodMap == null) {
+                throw new NullPointerException("methodMap is null");
+            }
+            mMethodMap = methodMap;
+            final File systemDir = userId == UserHandle.USER_OWNER
+                    ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
+                    : Environment.getUserSystemDirectory(userId);
+            final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
+            if (!inputMethodDir.mkdirs()) {
+                Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
+            }
+            final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
+            mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
+            if (!subtypeFile.exists()) {
+                // If "subtypes.xml" doesn't exist, create a blank file.
+                writeAdditionalInputMethodSubtypes(
+                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap);
+            } else {
+                readAdditionalInputMethodSubtypes(
+                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile);
+            }
+        }
+
+        private void deleteAllInputMethodSubtypes(String imiId) {
+            synchronized (mMethodMap) {
+                mAdditionalSubtypesMap.remove(imiId);
+                writeAdditionalInputMethodSubtypes(
+                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
+            }
+        }
+
+        public void addInputMethodSubtypes(
+                InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) {
+            synchronized (mMethodMap) {
+                final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
+                final int N = additionalSubtypes.length;
+                for (int i = 0; i < N; ++i) {
+                    final InputMethodSubtype subtype = additionalSubtypes[i];
+                    if (!subtypes.contains(subtype)) {
+                        subtypes.add(subtype);
+                    } else {
+                        Slog.w(TAG, "Duplicated subtype definition found: "
+                                + subtype.getLocale() + ", " + subtype.getMode());
+                    }
+                }
+                mAdditionalSubtypesMap.put(imi.getId(), subtypes);
+                writeAdditionalInputMethodSubtypes(
+                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
+            }
+        }
+
+        public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() {
+            synchronized (mMethodMap) {
+                return mAdditionalSubtypesMap;
+            }
+        }
+
+        private static void writeAdditionalInputMethodSubtypes(
+                HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile,
+                HashMap<String, InputMethodInfo> methodMap) {
+            // Safety net for the case that this function is called before methodMap is set.
+            final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
+            FileOutputStream fos = null;
+            try {
+                fos = subtypesFile.startWrite();
+                final XmlSerializer out = new FastXmlSerializer();
+                out.setOutput(fos, "utf-8");
+                out.startDocument(null, true);
+                out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+                out.startTag(null, NODE_SUBTYPES);
+                for (String imiId : allSubtypes.keySet()) {
+                    if (isSetMethodMap && !methodMap.containsKey(imiId)) {
+                        Slog.w(TAG, "IME uninstalled or not valid.: " + imiId);
+                        continue;
+                    }
+                    out.startTag(null, NODE_IMI);
+                    out.attribute(null, ATTR_ID, imiId);
+                    final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId);
+                    final int N = subtypesList.size();
+                    for (int i = 0; i < N; ++i) {
+                        final InputMethodSubtype subtype = subtypesList.get(i);
+                        out.startTag(null, NODE_SUBTYPE);
+                        out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId()));
+                        out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId()));
+                        out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
+                        out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode());
+                        out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue());
+                        out.attribute(null, ATTR_IS_AUXILIARY,
+                                String.valueOf(subtype.isAuxiliary() ? 1 : 0));
+                        out.endTag(null, NODE_SUBTYPE);
+                    }
+                    out.endTag(null, NODE_IMI);
+                }
+                out.endTag(null, NODE_SUBTYPES);
+                out.endDocument();
+                subtypesFile.finishWrite(fos);
+            } catch (java.io.IOException e) {
+                Slog.w(TAG, "Error writing subtypes", e);
+                if (fos != null) {
+                    subtypesFile.failWrite(fos);
+                }
+            }
+        }
+
+        private static void readAdditionalInputMethodSubtypes(
+                HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
+            if (allSubtypes == null || subtypesFile == null) return;
+            allSubtypes.clear();
+            FileInputStream fis = null;
+            try {
+                fis = subtypesFile.openRead();
+                final XmlPullParser parser = Xml.newPullParser();
+                parser.setInput(fis, null);
+                int type = parser.getEventType();
+                // Skip parsing until START_TAG
+                while ((type = parser.next()) != XmlPullParser.START_TAG
+                        && type != XmlPullParser.END_DOCUMENT) {}
+                String firstNodeName = parser.getName();
+                if (!NODE_SUBTYPES.equals(firstNodeName)) {
+                    throw new XmlPullParserException("Xml doesn't start with subtypes");
+                }
+                final int depth =parser.getDepth();
+                String currentImiId = null;
+                ArrayList<InputMethodSubtype> tempSubtypesArray = null;
+                while (((type = parser.next()) != XmlPullParser.END_TAG
+                        || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
+                    if (type != XmlPullParser.START_TAG)
+                        continue;
+                    final String nodeName = parser.getName();
+                    if (NODE_IMI.equals(nodeName)) {
+                        currentImiId = parser.getAttributeValue(null, ATTR_ID);
+                        if (TextUtils.isEmpty(currentImiId)) {
+                            Slog.w(TAG, "Invalid imi id found in subtypes.xml");
+                            continue;
+                        }
+                        tempSubtypesArray = new ArrayList<InputMethodSubtype>();
+                        allSubtypes.put(currentImiId, tempSubtypesArray);
+                    } else if (NODE_SUBTYPE.equals(nodeName)) {
+                        if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) {
+                            Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
+                            continue;
+                        }
+                        final int icon = Integer.valueOf(
+                                parser.getAttributeValue(null, ATTR_ICON));
+                        final int label = Integer.valueOf(
+                                parser.getAttributeValue(null, ATTR_LABEL));
+                        final String imeSubtypeLocale =
+                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
+                        final String imeSubtypeMode =
+                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE);
+                        final String imeSubtypeExtraValue =
+                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE);
+                        final boolean isAuxiliary = "1".equals(String.valueOf(
+                                parser.getAttributeValue(null, ATTR_IS_AUXILIARY)));
+                        final InputMethodSubtype subtype =
+                                new InputMethodSubtype(label, icon, imeSubtypeLocale,
+                                        imeSubtypeMode, imeSubtypeExtraValue, isAuxiliary);
+                        tempSubtypesArray.add(subtype);
+                    }
+                }
+            } catch (XmlPullParserException e) {
+                Slog.w(TAG, "Error reading subtypes: " + e);
+                return;
+            } catch (java.io.IOException e) {
+                Slog.w(TAG, "Error reading subtypes: " + e);
+                return;
+            } catch (NumberFormatException e) {
+                Slog.w(TAG, "Error reading subtypes: " + e);
+                return;
+            } finally {
+                if (fis != null) {
+                    try {
+                        fis.close();
+                    } catch (java.io.IOException e1) {
+                        Slog.w(TAG, "Failed to close.");
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+
+            pw.println("Permission Denial: can't dump InputMethodManager from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        IInputMethod method;
+        ClientState client;
+
+        final Printer p = new PrintWriterPrinter(pw);
+
+        synchronized (mMethodMap) {
+            p.println("Current Input Method Manager state:");
+            int N = mMethodList.size();
+            p.println("  Input Methods:");
+            for (int i=0; i<N; i++) {
+                InputMethodInfo info = mMethodList.get(i);
+                p.println("  InputMethod #" + i + ":");
+                info.dump(p, "    ");
+            }
+            p.println("  Clients:");
+            for (ClientState ci : mClients.values()) {
+                p.println("  Client " + ci + ":");
+                p.println("    client=" + ci.client);
+                p.println("    inputContext=" + ci.inputContext);
+                p.println("    sessionRequested=" + ci.sessionRequested);
+                p.println("    curSession=" + ci.curSession);
+            }
+            p.println("  mCurMethodId=" + mCurMethodId);
+            client = mCurClient;
+            p.println("  mCurClient=" + client + " mCurSeq=" + mCurSeq);
+            p.println("  mCurFocusedWindow=" + mCurFocusedWindow);
+            p.println("  mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
+                    + " mBoundToMethod=" + mBoundToMethod);
+            p.println("  mCurToken=" + mCurToken);
+            p.println("  mCurIntent=" + mCurIntent);
+            method = mCurMethod;
+            p.println("  mCurMethod=" + mCurMethod);
+            p.println("  mEnabledSession=" + mEnabledSession);
+            p.println("  mShowRequested=" + mShowRequested
+                    + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
+                    + " mShowForced=" + mShowForced
+                    + " mInputShown=" + mInputShown);
+            p.println("  mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn);
+        }
+
+        p.println(" ");
+        if (client != null) {
+            pw.flush();
+            try {
+                client.client.asBinder().dump(fd, args);
+            } catch (RemoteException e) {
+                p.println("Input method client dead: " + e);
+            }
+        } else {
+            p.println("No input method client.");
+        }
+
+        p.println(" ");
+        if (method != null) {
+            pw.flush();
+            try {
+                method.asBinder().dump(fd, args);
+            } catch (RemoteException e) {
+                p.println("Input method service dead: " + e);
+            }
+        } else {
+            p.println("No input method service.");
+        }
+    }
+}
diff --git a/services/java/com/android/server/IntentResolver.java b/services/core/java/com/android/server/IntentResolver.java
similarity index 100%
rename from services/java/com/android/server/IntentResolver.java
rename to services/core/java/com/android/server/IntentResolver.java
diff --git a/services/core/java/com/android/server/IoThread.java b/services/core/java/com/android/server/IoThread.java
new file mode 100644
index 0000000..0f29857
--- /dev/null
+++ b/services/core/java/com/android/server/IoThread.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.os.Handler;
+
+/**
+ * Shared singleton I/O thread for the system.  This is a thread for non-background
+ * service operations that can potential block briefly on network IO operations
+ * (not waiting for data itself, but communicating with network daemons).
+ */
+public final class IoThread extends ServiceThread {
+    private static IoThread sInstance;
+    private static Handler sHandler;
+
+    private IoThread() {
+        super("android.io", android.os.Process.THREAD_PRIORITY_DEFAULT, true /*allowIo*/);
+    }
+
+    private static void ensureThreadLocked() {
+        if (sInstance == null) {
+            sInstance = new IoThread();
+            sInstance.start();
+            sHandler = new Handler(sInstance.getLooper());
+        }
+    }
+
+    public static IoThread get() {
+        synchronized (IoThread.class) {
+            ensureThreadLocked();
+            return sInstance;
+        }
+    }
+
+    public static Handler getHandler() {
+        synchronized (IoThread.class) {
+            ensureThreadLocked();
+            return sHandler;
+        }
+    }
+}
diff --git a/services/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
similarity index 100%
rename from services/java/com/android/server/LocationManagerService.java
rename to services/core/java/com/android/server/LocationManagerService.java
diff --git a/services/java/com/android/server/LockSettingsService.java b/services/core/java/com/android/server/LockSettingsService.java
similarity index 100%
rename from services/java/com/android/server/LockSettingsService.java
rename to services/core/java/com/android/server/LockSettingsService.java
diff --git a/services/java/com/android/server/MasterClearReceiver.java b/services/core/java/com/android/server/MasterClearReceiver.java
similarity index 100%
rename from services/java/com/android/server/MasterClearReceiver.java
rename to services/core/java/com/android/server/MasterClearReceiver.java
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
new file mode 100644
index 0000000..816ae69
--- /dev/null
+++ b/services/core/java/com/android/server/MountService.java
@@ -0,0 +1,2834 @@
+/*
+ * Copyright (C) 2007 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;
+
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+
+import android.Manifest;
+import android.app.AppOpsManager;
+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.UserInfo;
+import android.content.res.ObbInfo;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.hardware.usb.UsbManager;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.Environment.UserEnvironment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.storage.IMountService;
+import android.os.storage.IMountServiceListener;
+import android.os.storage.IMountShutdownObserver;
+import android.os.storage.IObbActionListener;
+import android.os.storage.OnObbStateChangeListener;
+import android.os.storage.StorageResultCode;
+import android.os.storage.StorageVolume;
+import android.text.TextUtils;
+import android.util.AttributeSet;
+import android.util.Slog;
+import android.util.Xml;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.app.IMediaContainerService;
+import com.android.internal.util.IndentingPrintWriter;
+import com.android.internal.util.Preconditions;
+import com.android.internal.util.XmlUtils;
+import com.android.server.NativeDaemonConnector.Command;
+import com.android.server.NativeDaemonConnector.SensitiveArg;
+import com.android.server.am.ActivityManagerService;
+import com.android.server.pm.PackageManagerService;
+import com.android.server.pm.UserManagerService;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Maps;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.math.BigInteger;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+
+/**
+ * MountService implements back-end services for platform storage
+ * management.
+ * @hide - Applications should use android.os.storage.StorageManager
+ * to access the MountService.
+ */
+class MountService extends IMountService.Stub
+        implements INativeDaemonConnectorCallbacks, Watchdog.Monitor {
+
+    // TODO: listen for user creation/deletion
+
+    private static final boolean LOCAL_LOGD = false;
+    private static final boolean DEBUG_UNMOUNT = false;
+    private static final boolean DEBUG_EVENTS = false;
+    private static final boolean DEBUG_OBB = false;
+
+    // Disable this since it messes up long-running cryptfs operations.
+    private static final boolean WATCHDOG_ENABLE = false;
+
+    private static final String TAG = "MountService";
+
+    private static final String VOLD_TAG = "VoldConnector";
+
+    /** Maximum number of ASEC containers allowed to be mounted. */
+    private static final int MAX_CONTAINERS = 250;
+
+    /*
+     * Internal vold volume state constants
+     */
+    class VolumeState {
+        public static final int Init       = -1;
+        public static final int NoMedia    = 0;
+        public static final int Idle       = 1;
+        public static final int Pending    = 2;
+        public static final int Checking   = 3;
+        public static final int Mounted    = 4;
+        public static final int Unmounting = 5;
+        public static final int Formatting = 6;
+        public static final int Shared     = 7;
+        public static final int SharedMnt  = 8;
+    }
+
+    /*
+     * Internal vold response code constants
+     */
+    class VoldResponseCode {
+        /*
+         * 100 series - Requestion action was initiated; expect another reply
+         *              before proceeding with a new command.
+         */
+        public static final int VolumeListResult               = 110;
+        public static final int AsecListResult                 = 111;
+        public static final int StorageUsersListResult         = 112;
+
+        /*
+         * 200 series - Requestion action has been successfully completed.
+         */
+        public static final int ShareStatusResult              = 210;
+        public static final int AsecPathResult                 = 211;
+        public static final int ShareEnabledResult             = 212;
+
+        /*
+         * 400 series - Command was accepted, but the requested action
+         *              did not take place.
+         */
+        public static final int OpFailedNoMedia                = 401;
+        public static final int OpFailedMediaBlank             = 402;
+        public static final int OpFailedMediaCorrupt           = 403;
+        public static final int OpFailedVolNotMounted          = 404;
+        public static final int OpFailedStorageBusy            = 405;
+        public static final int OpFailedStorageNotFound        = 406;
+
+        /*
+         * 600 series - Unsolicited broadcasts.
+         */
+        public static final int VolumeStateChange              = 605;
+        public static final int VolumeUuidChange               = 613;
+        public static final int VolumeUserLabelChange          = 614;
+        public static final int VolumeDiskInserted             = 630;
+        public static final int VolumeDiskRemoved              = 631;
+        public static final int VolumeBadRemoval               = 632;
+
+        /*
+         * 700 series - fstrim
+         */
+        public static final int FstrimCompleted                = 700;
+    }
+
+    private Context mContext;
+    private NativeDaemonConnector mConnector;
+
+    private final Object mVolumesLock = new Object();
+
+    /** When defined, base template for user-specific {@link StorageVolume}. */
+    private StorageVolume mEmulatedTemplate;
+
+    // TODO: separate storage volumes on per-user basis
+
+    @GuardedBy("mVolumesLock")
+    private final ArrayList<StorageVolume> mVolumes = Lists.newArrayList();
+    /** Map from path to {@link StorageVolume} */
+    @GuardedBy("mVolumesLock")
+    private final HashMap<String, StorageVolume> mVolumesByPath = Maps.newHashMap();
+    /** Map from path to state */
+    @GuardedBy("mVolumesLock")
+    private final HashMap<String, String> mVolumeStates = Maps.newHashMap();
+
+    private volatile boolean mSystemReady = false;
+
+    private PackageManagerService                 mPms;
+    private boolean                               mUmsEnabling;
+    private boolean                               mUmsAvailable = false;
+    // Used as a lock for methods that register/unregister listeners.
+    final private ArrayList<MountServiceBinderListener> mListeners =
+            new ArrayList<MountServiceBinderListener>();
+    private final CountDownLatch mConnectedSignal = new CountDownLatch(1);
+    private final CountDownLatch mAsecsScanned = new CountDownLatch(1);
+    private boolean                               mSendUmsConnectedOnBoot = false;
+
+    /**
+     * Private hash of currently mounted secure containers.
+     * Used as a lock in methods to manipulate secure containers.
+     */
+    final private HashSet<String> mAsecMountSet = new HashSet<String>();
+
+    /**
+     * The size of the crypto algorithm key in bits for OBB files. Currently
+     * Twofish is used which takes 128-bit keys.
+     */
+    private static final int CRYPTO_ALGORITHM_KEY_SIZE = 128;
+
+    /**
+     * The number of times to run SHA1 in the PBKDF2 function for OBB files.
+     * 1024 is reasonably secure and not too slow.
+     */
+    private static final int PBKDF2_HASH_ROUNDS = 1024;
+
+    /**
+     * Mounted OBB tracking information. Used to track the current state of all
+     * OBBs.
+     */
+    final private Map<IBinder, List<ObbState>> mObbMounts = new HashMap<IBinder, List<ObbState>>();
+
+    /** Map from raw paths to {@link ObbState}. */
+    final private Map<String, ObbState> mObbPathToStateMap = new HashMap<String, ObbState>();
+
+    class ObbState implements IBinder.DeathRecipient {
+        public ObbState(String rawPath, String canonicalPath, int callingUid,
+                IObbActionListener token, int nonce) {
+            this.rawPath = rawPath;
+            this.canonicalPath = canonicalPath.toString();
+
+            final int userId = UserHandle.getUserId(callingUid);
+            this.ownerPath = buildObbPath(canonicalPath, userId, false);
+            this.voldPath = buildObbPath(canonicalPath, userId, true);
+
+            this.ownerGid = UserHandle.getSharedAppGid(callingUid);
+            this.token = token;
+            this.nonce = nonce;
+        }
+
+        final String rawPath;
+        final String canonicalPath;
+        final String ownerPath;
+        final String voldPath;
+
+        final int ownerGid;
+
+        // Token of remote Binder caller
+        final IObbActionListener token;
+
+        // Identifier to pass back to the token
+        final int nonce;
+
+        public IBinder getBinder() {
+            return token.asBinder();
+        }
+
+        @Override
+        public void binderDied() {
+            ObbAction action = new UnmountObbAction(this, true);
+            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));
+        }
+
+        public void link() throws RemoteException {
+            getBinder().linkToDeath(this, 0);
+        }
+
+        public void unlink() {
+            getBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder("ObbState{");
+            sb.append("rawPath=").append(rawPath);
+            sb.append(",canonicalPath=").append(canonicalPath);
+            sb.append(",ownerPath=").append(ownerPath);
+            sb.append(",voldPath=").append(voldPath);
+            sb.append(",ownerGid=").append(ownerGid);
+            sb.append(",token=").append(token);
+            sb.append(",binder=").append(getBinder());
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+    // OBB Action Handler
+    final private ObbActionHandler mObbActionHandler;
+
+    // OBB action handler messages
+    private static final int OBB_RUN_ACTION = 1;
+    private static final int OBB_MCS_BOUND = 2;
+    private static final int OBB_MCS_UNBIND = 3;
+    private static final int OBB_MCS_RECONNECT = 4;
+    private static final int OBB_FLUSH_MOUNT_STATE = 5;
+
+    /*
+     * Default Container Service information
+     */
+    static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
+            "com.android.defcontainer", "com.android.defcontainer.DefaultContainerService");
+
+    final private DefaultContainerConnection mDefContainerConn = new DefaultContainerConnection();
+
+    class DefaultContainerConnection implements ServiceConnection {
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            if (DEBUG_OBB)
+                Slog.i(TAG, "onServiceConnected");
+            IMediaContainerService imcs = IMediaContainerService.Stub.asInterface(service);
+            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_MCS_BOUND, imcs));
+        }
+
+        public void onServiceDisconnected(ComponentName name) {
+            if (DEBUG_OBB)
+                Slog.i(TAG, "onServiceDisconnected");
+        }
+    };
+
+    // Used in the ObbActionHandler
+    private IMediaContainerService mContainerService = null;
+
+    // Handler messages
+    private static final int H_UNMOUNT_PM_UPDATE = 1;
+    private static final int H_UNMOUNT_PM_DONE = 2;
+    private static final int H_UNMOUNT_MS = 3;
+    private static final int H_SYSTEM_READY = 4;
+
+    private static final int RETRY_UNMOUNT_DELAY = 30; // in ms
+    private static final int MAX_UNMOUNT_RETRIES = 4;
+
+    class UnmountCallBack {
+        final String path;
+        final boolean force;
+        final boolean removeEncryption;
+        int retries;
+
+        UnmountCallBack(String path, boolean force, boolean removeEncryption) {
+            retries = 0;
+            this.path = path;
+            this.force = force;
+            this.removeEncryption = removeEncryption;
+        }
+
+        void handleFinished() {
+            if (DEBUG_UNMOUNT) Slog.i(TAG, "Unmounting " + path);
+            doUnmountVolume(path, true, removeEncryption);
+        }
+    }
+
+    class UmsEnableCallBack extends UnmountCallBack {
+        final String method;
+
+        UmsEnableCallBack(String path, String method, boolean force) {
+            super(path, force, false);
+            this.method = method;
+        }
+
+        @Override
+        void handleFinished() {
+            super.handleFinished();
+            doShareUnshareVolume(path, method, true);
+        }
+    }
+
+    class ShutdownCallBack extends UnmountCallBack {
+        IMountShutdownObserver observer;
+        ShutdownCallBack(String path, IMountShutdownObserver observer) {
+            super(path, true, false);
+            this.observer = observer;
+        }
+
+        @Override
+        void handleFinished() {
+            int ret = doUnmountVolume(path, true, removeEncryption);
+            if (observer != null) {
+                try {
+                    observer.onShutDownComplete(ret);
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "RemoteException when shutting down");
+                }
+            }
+        }
+    }
+
+    class MountServiceHandler extends Handler {
+        ArrayList<UnmountCallBack> mForceUnmounts = new ArrayList<UnmountCallBack>();
+        boolean mUpdatingStatus = false;
+
+        MountServiceHandler(Looper l) {
+            super(l);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case H_UNMOUNT_PM_UPDATE: {
+                    if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_UPDATE");
+                    UnmountCallBack ucb = (UnmountCallBack) msg.obj;
+                    mForceUnmounts.add(ucb);
+                    if (DEBUG_UNMOUNT) Slog.i(TAG, " registered = " + mUpdatingStatus);
+                    // Register only if needed.
+                    if (!mUpdatingStatus) {
+                        if (DEBUG_UNMOUNT) Slog.i(TAG, "Updating external media status on PackageManager");
+                        mUpdatingStatus = true;
+                        mPms.updateExternalMediaStatus(false, true);
+                    }
+                    break;
+                }
+                case H_UNMOUNT_PM_DONE: {
+                    if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_DONE");
+                    if (DEBUG_UNMOUNT) Slog.i(TAG, "Updated status. Processing requests");
+                    mUpdatingStatus = false;
+                    int size = mForceUnmounts.size();
+                    int sizeArr[] = new int[size];
+                    int sizeArrN = 0;
+                    // Kill processes holding references first
+                    ActivityManagerService ams = (ActivityManagerService)
+                    ServiceManager.getService("activity");
+                    for (int i = 0; i < size; i++) {
+                        UnmountCallBack ucb = mForceUnmounts.get(i);
+                        String path = ucb.path;
+                        boolean done = false;
+                        if (!ucb.force) {
+                            done = true;
+                        } else {
+                            int pids[] = getStorageUsers(path);
+                            if (pids == null || pids.length == 0) {
+                                done = true;
+                            } else {
+                                // Eliminate system process here?
+                                ams.killPids(pids, "unmount media", true);
+                                // Confirm if file references have been freed.
+                                pids = getStorageUsers(path);
+                                if (pids == null || pids.length == 0) {
+                                    done = true;
+                                }
+                            }
+                        }
+                        if (!done && (ucb.retries < MAX_UNMOUNT_RETRIES)) {
+                            // Retry again
+                            Slog.i(TAG, "Retrying to kill storage users again");
+                            mHandler.sendMessageDelayed(
+                                    mHandler.obtainMessage(H_UNMOUNT_PM_DONE,
+                                            ucb.retries++),
+                                    RETRY_UNMOUNT_DELAY);
+                        } else {
+                            if (ucb.retries >= MAX_UNMOUNT_RETRIES) {
+                                Slog.i(TAG, "Failed to unmount media inspite of " +
+                                        MAX_UNMOUNT_RETRIES + " retries. Forcibly killing processes now");
+                            }
+                            sizeArr[sizeArrN++] = i;
+                            mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_MS,
+                                    ucb));
+                        }
+                    }
+                    // Remove already processed elements from list.
+                    for (int i = (sizeArrN-1); i >= 0; i--) {
+                        mForceUnmounts.remove(sizeArr[i]);
+                    }
+                    break;
+                }
+                case H_UNMOUNT_MS: {
+                    if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_MS");
+                    UnmountCallBack ucb = (UnmountCallBack) msg.obj;
+                    ucb.handleFinished();
+                    break;
+                }
+                case H_SYSTEM_READY: {
+                    try {
+                        handleSystemReady();
+                    } catch (Exception ex) {
+                        Slog.e(TAG, "Boot-time mount exception", ex);
+                    }
+                    break;
+                }
+            }
+        }
+    };
+
+    private final Handler mHandler;
+
+    void waitForAsecScan() {
+        waitForLatch(mAsecsScanned);
+    }
+
+    private void waitForReady() {
+        waitForLatch(mConnectedSignal);
+    }
+
+    private void waitForLatch(CountDownLatch latch) {
+        for (;;) {
+            try {
+                if (latch.await(5000, TimeUnit.MILLISECONDS)) {
+                    return;
+                } else {
+                    Slog.w(TAG, "Thread " + Thread.currentThread().getName()
+                            + " still waiting for MountService ready...");
+                }
+            } catch (InterruptedException e) {
+                Slog.w(TAG, "Interrupt while waiting for MountService to be ready.");
+            }
+        }
+    }
+
+    private void handleSystemReady() {
+        // Snapshot current volume states since it's not safe to call into vold
+        // while holding locks.
+        final HashMap<String, String> snapshot;
+        synchronized (mVolumesLock) {
+            snapshot = new HashMap<String, String>(mVolumeStates);
+        }
+
+        for (Map.Entry<String, String> entry : snapshot.entrySet()) {
+            final String path = entry.getKey();
+            final String state = entry.getValue();
+
+            if (state.equals(Environment.MEDIA_UNMOUNTED)) {
+                int rc = doMountVolume(path);
+                if (rc != StorageResultCode.OperationSucceeded) {
+                    Slog.e(TAG, String.format("Boot-time mount failed (%d)",
+                            rc));
+                }
+            } else if (state.equals(Environment.MEDIA_SHARED)) {
+                /*
+                 * Bootstrap UMS enabled state since vold indicates
+                 * the volume is shared (runtime restart while ums enabled)
+                 */
+                notifyVolumeStateChange(null, path, VolumeState.NoMedia,
+                        VolumeState.Shared);
+            }
+        }
+
+        // Push mounted state for all emulated storage
+        synchronized (mVolumesLock) {
+            for (StorageVolume volume : mVolumes) {
+                if (volume.isEmulated()) {
+                    updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
+                }
+            }
+        }
+
+        /*
+         * If UMS was connected on boot, send the connected event
+         * now that we're up.
+         */
+        if (mSendUmsConnectedOnBoot) {
+            sendUmsIntent(true);
+            mSendUmsConnectedOnBoot = false;
+        }
+    }
+
+    private final BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+            if (userId == -1) return;
+            final UserHandle user = new UserHandle(userId);
+
+            final String action = intent.getAction();
+            if (Intent.ACTION_USER_ADDED.equals(action)) {
+                synchronized (mVolumesLock) {
+                    createEmulatedVolumeForUserLocked(user);
+                }
+
+            } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
+                synchronized (mVolumesLock) {
+                    final List<StorageVolume> toRemove = Lists.newArrayList();
+                    for (StorageVolume volume : mVolumes) {
+                        if (user.equals(volume.getOwner())) {
+                            toRemove.add(volume);
+                        }
+                    }
+                    for (StorageVolume volume : toRemove) {
+                        removeVolumeLocked(volume);
+                    }
+                }
+            }
+        }
+    };
+
+    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            boolean available = (intent.getBooleanExtra(UsbManager.USB_CONNECTED, false) &&
+                    intent.getBooleanExtra(UsbManager.USB_FUNCTION_MASS_STORAGE, false));
+            notifyShareAvailabilityChange(available);
+        }
+    };
+
+    private final BroadcastReceiver mIdleMaintenanceReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            waitForReady();
+            String action = intent.getAction();
+            // Since fstrim will be run on a daily basis we do not expect
+            // fstrim to be too long, so it is not interruptible. We will
+            // implement interruption only in case we see issues.
+            if (Intent.ACTION_IDLE_MAINTENANCE_START.equals(action)) {
+                try {
+                    // This method runs on the handler thread,
+                    // so it is safe to directly call into vold.
+                    mConnector.execute("fstrim", "dotrim");
+                    EventLogTags.writeFstrimStart(SystemClock.elapsedRealtime());
+                } catch (NativeDaemonConnectorException ndce) {
+                    Slog.e(TAG, "Failed to run fstrim!");
+                }
+            }
+        }
+    };
+
+    private final class MountServiceBinderListener implements IBinder.DeathRecipient {
+        final IMountServiceListener mListener;
+
+        MountServiceBinderListener(IMountServiceListener listener) {
+            mListener = listener;
+
+        }
+
+        public void binderDied() {
+            if (LOCAL_LOGD) Slog.d(TAG, "An IMountServiceListener has died!");
+            synchronized (mListeners) {
+                mListeners.remove(this);
+                mListener.asBinder().unlinkToDeath(this, 0);
+            }
+        }
+    }
+
+    private void doShareUnshareVolume(String path, String method, boolean enable) {
+        // TODO: Add support for multiple share methods
+        if (!method.equals("ums")) {
+            throw new IllegalArgumentException(String.format("Method %s not supported", method));
+        }
+
+        try {
+            mConnector.execute("volume", enable ? "share" : "unshare", path, method);
+        } catch (NativeDaemonConnectorException e) {
+            Slog.e(TAG, "Failed to share/unshare", e);
+        }
+    }
+
+    private void updatePublicVolumeState(StorageVolume volume, String state) {
+        final String path = volume.getPath();
+        final String oldState;
+        synchronized (mVolumesLock) {
+            oldState = mVolumeStates.put(path, state);
+            volume.setState(state);
+        }
+
+        if (state.equals(oldState)) {
+            Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s",
+                    state, state, path));
+            return;
+        }
+
+        Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")");
+
+        // Tell PackageManager about changes to primary volume state, but only
+        // when not emulated.
+        if (volume.isPrimary() && !volume.isEmulated()) {
+            if (Environment.MEDIA_UNMOUNTED.equals(state)) {
+                mPms.updateExternalMediaStatus(false, false);
+
+                /*
+                 * Some OBBs might have been unmounted when this volume was
+                 * unmounted, so send a message to the handler to let it know to
+                 * remove those from the list of mounted OBBS.
+                 */
+                mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(
+                        OBB_FLUSH_MOUNT_STATE, path));
+            } else if (Environment.MEDIA_MOUNTED.equals(state)) {
+                mPms.updateExternalMediaStatus(true, false);
+            }
+        }
+
+        synchronized (mListeners) {
+            for (int i = mListeners.size() -1; i >= 0; i--) {
+                MountServiceBinderListener bl = mListeners.get(i);
+                try {
+                    bl.mListener.onStorageStateChanged(path, oldState, state);
+                } catch (RemoteException rex) {
+                    Slog.e(TAG, "Listener dead");
+                    mListeners.remove(i);
+                } catch (Exception ex) {
+                    Slog.e(TAG, "Listener failed", ex);
+                }
+            }
+        }
+    }
+
+    /**
+     * Callback from NativeDaemonConnector
+     */
+    public void onDaemonConnected() {
+        /*
+         * Since we'll be calling back into the NativeDaemonConnector,
+         * we need to do our work in a new thread.
+         */
+        new Thread("MountService#onDaemonConnected") {
+            @Override
+            public void run() {
+                /**
+                 * Determine media state and UMS detection status
+                 */
+                try {
+                    final String[] vols = NativeDaemonEvent.filterMessageList(
+                            mConnector.executeForList("volume", "list"),
+                            VoldResponseCode.VolumeListResult);
+                    for (String volstr : vols) {
+                        String[] tok = volstr.split(" ");
+                        // FMT: <label> <mountpoint> <state>
+                        String path = tok[1];
+                        String state = Environment.MEDIA_REMOVED;
+
+                        final StorageVolume volume;
+                        synchronized (mVolumesLock) {
+                            volume = mVolumesByPath.get(path);
+                        }
+
+                        int st = Integer.parseInt(tok[2]);
+                        if (st == VolumeState.NoMedia) {
+                            state = Environment.MEDIA_REMOVED;
+                        } else if (st == VolumeState.Idle) {
+                            state = Environment.MEDIA_UNMOUNTED;
+                        } else if (st == VolumeState.Mounted) {
+                            state = Environment.MEDIA_MOUNTED;
+                            Slog.i(TAG, "Media already mounted on daemon connection");
+                        } else if (st == VolumeState.Shared) {
+                            state = Environment.MEDIA_SHARED;
+                            Slog.i(TAG, "Media shared on daemon connection");
+                        } else {
+                            throw new Exception(String.format("Unexpected state %d", st));
+                        }
+
+                        if (state != null) {
+                            if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state);
+                            updatePublicVolumeState(volume, state);
+                        }
+                    }
+                } catch (Exception e) {
+                    Slog.e(TAG, "Error processing initial volume state", e);
+                    final StorageVolume primary = getPrimaryPhysicalVolume();
+                    if (primary != null) {
+                        updatePublicVolumeState(primary, Environment.MEDIA_REMOVED);
+                    }
+                }
+
+                /*
+                 * Now that we've done our initialization, release
+                 * the hounds!
+                 */
+                mConnectedSignal.countDown();
+
+                // Let package manager load internal ASECs.
+                mPms.scanAvailableAsecs();
+
+                // Notify people waiting for ASECs to be scanned that it's done.
+                mAsecsScanned.countDown();
+            }
+        }.start();
+    }
+
+    /**
+     * Callback from NativeDaemonConnector
+     */
+    public boolean onEvent(int code, String raw, String[] cooked) {
+        if (DEBUG_EVENTS) {
+            StringBuilder builder = new StringBuilder();
+            builder.append("onEvent::");
+            builder.append(" raw= " + raw);
+            if (cooked != null) {
+                builder.append(" cooked = " );
+                for (String str : cooked) {
+                    builder.append(" " + str);
+                }
+            }
+            Slog.i(TAG, builder.toString());
+        }
+        if (code == VoldResponseCode.VolumeStateChange) {
+            /*
+             * One of the volumes we're managing has changed state.
+             * Format: "NNN Volume <label> <path> state changed
+             * from <old_#> (<old_str>) to <new_#> (<new_str>)"
+             */
+            notifyVolumeStateChange(
+                    cooked[2], cooked[3], Integer.parseInt(cooked[7]),
+                            Integer.parseInt(cooked[10]));
+        } else if (code == VoldResponseCode.VolumeUuidChange) {
+            // Format: nnn <label> <path> <uuid>
+            final String path = cooked[2];
+            final String uuid = (cooked.length > 3) ? cooked[3] : null;
+
+            final StorageVolume vol = mVolumesByPath.get(path);
+            if (vol != null) {
+                vol.setUuid(uuid);
+            }
+
+        } else if (code == VoldResponseCode.VolumeUserLabelChange) {
+            // Format: nnn <label> <path> <label>
+            final String path = cooked[2];
+            final String userLabel = (cooked.length > 3) ? cooked[3] : null;
+
+            final StorageVolume vol = mVolumesByPath.get(path);
+            if (vol != null) {
+                vol.setUserLabel(userLabel);
+            }
+
+        } else if ((code == VoldResponseCode.VolumeDiskInserted) ||
+                   (code == VoldResponseCode.VolumeDiskRemoved) ||
+                   (code == VoldResponseCode.VolumeBadRemoval)) {
+            // FMT: NNN Volume <label> <mountpoint> disk inserted (<major>:<minor>)
+            // FMT: NNN Volume <label> <mountpoint> disk removed (<major>:<minor>)
+            // FMT: NNN Volume <label> <mountpoint> bad removal (<major>:<minor>)
+            String action = null;
+            final String label = cooked[2];
+            final String path = cooked[3];
+            int major = -1;
+            int minor = -1;
+
+            try {
+                String devComp = cooked[6].substring(1, cooked[6].length() -1);
+                String[] devTok = devComp.split(":");
+                major = Integer.parseInt(devTok[0]);
+                minor = Integer.parseInt(devTok[1]);
+            } catch (Exception ex) {
+                Slog.e(TAG, "Failed to parse major/minor", ex);
+            }
+
+            final StorageVolume volume;
+            final String state;
+            synchronized (mVolumesLock) {
+                volume = mVolumesByPath.get(path);
+                state = mVolumeStates.get(path);
+            }
+
+            if (code == VoldResponseCode.VolumeDiskInserted) {
+                new Thread("MountService#VolumeDiskInserted") {
+                    @Override
+                    public void run() {
+                        try {
+                            int rc;
+                            if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
+                                Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));
+                            }
+                        } catch (Exception ex) {
+                            Slog.w(TAG, "Failed to mount media on insertion", ex);
+                        }
+                    }
+                }.start();
+            } else if (code == VoldResponseCode.VolumeDiskRemoved) {
+                /*
+                 * This event gets trumped if we're already in BAD_REMOVAL state
+                 */
+                if (getVolumeState(path).equals(Environment.MEDIA_BAD_REMOVAL)) {
+                    return true;
+                }
+                /* Send the media unmounted event first */
+                if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first");
+                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
+                sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);
+
+                if (DEBUG_EVENTS) Slog.i(TAG, "Sending media removed");
+                updatePublicVolumeState(volume, Environment.MEDIA_REMOVED);
+                action = Intent.ACTION_MEDIA_REMOVED;
+            } else if (code == VoldResponseCode.VolumeBadRemoval) {
+                if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first");
+                /* Send the media unmounted event first */
+                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
+                sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);
+
+                if (DEBUG_EVENTS) Slog.i(TAG, "Sending media bad removal");
+                updatePublicVolumeState(volume, Environment.MEDIA_BAD_REMOVAL);
+                action = Intent.ACTION_MEDIA_BAD_REMOVAL;
+            } else if (code == VoldResponseCode.FstrimCompleted) {
+                EventLogTags.writeFstrimFinish(SystemClock.elapsedRealtime());
+            } else {
+                Slog.e(TAG, String.format("Unknown code {%d}", code));
+            }
+
+            if (action != null) {
+                sendStorageIntent(action, volume, UserHandle.ALL);
+            }
+        } else {
+            return false;
+        }
+
+        return true;
+    }
+
+    private void notifyVolumeStateChange(String label, String path, int oldState, int newState) {
+        final StorageVolume volume;
+        final String state;
+        synchronized (mVolumesLock) {
+            volume = mVolumesByPath.get(path);
+            state = getVolumeState(path);
+        }
+
+        if (DEBUG_EVENTS) Slog.i(TAG, "notifyVolumeStateChange::" + state);
+
+        String action = null;
+
+        if (oldState == VolumeState.Shared && newState != oldState) {
+            if (LOCAL_LOGD) Slog.d(TAG, "Sending ACTION_MEDIA_UNSHARED intent");
+            sendStorageIntent(Intent.ACTION_MEDIA_UNSHARED, volume, UserHandle.ALL);
+        }
+
+        if (newState == VolumeState.Init) {
+        } else if (newState == VolumeState.NoMedia) {
+            // NoMedia is handled via Disk Remove events
+        } else if (newState == VolumeState.Idle) {
+            /*
+             * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or
+             * if we're in the process of enabling UMS
+             */
+            if (!state.equals(
+                    Environment.MEDIA_BAD_REMOVAL) && !state.equals(
+                            Environment.MEDIA_NOFS) && !state.equals(
+                                    Environment.MEDIA_UNMOUNTABLE) && !getUmsEnabling()) {
+                if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state for media bad removal nofs and unmountable");
+                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
+                action = Intent.ACTION_MEDIA_UNMOUNTED;
+            }
+        } else if (newState == VolumeState.Pending) {
+        } else if (newState == VolumeState.Checking) {
+            if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state checking");
+            updatePublicVolumeState(volume, Environment.MEDIA_CHECKING);
+            action = Intent.ACTION_MEDIA_CHECKING;
+        } else if (newState == VolumeState.Mounted) {
+            if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state mounted");
+            updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
+            action = Intent.ACTION_MEDIA_MOUNTED;
+        } else if (newState == VolumeState.Unmounting) {
+            action = Intent.ACTION_MEDIA_EJECT;
+        } else if (newState == VolumeState.Formatting) {
+        } else if (newState == VolumeState.Shared) {
+            if (DEBUG_EVENTS) Slog.i(TAG, "Updating volume state media mounted");
+            /* Send the media unmounted event first */
+            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
+            sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);
+
+            if (DEBUG_EVENTS) Slog.i(TAG, "Updating media shared");
+            updatePublicVolumeState(volume, Environment.MEDIA_SHARED);
+            action = Intent.ACTION_MEDIA_SHARED;
+            if (LOCAL_LOGD) Slog.d(TAG, "Sending ACTION_MEDIA_SHARED intent");
+        } else if (newState == VolumeState.SharedMnt) {
+            Slog.e(TAG, "Live shared mounts not supported yet!");
+            return;
+        } else {
+            Slog.e(TAG, "Unhandled VolumeState {" + newState + "}");
+        }
+
+        if (action != null) {
+            sendStorageIntent(action, volume, UserHandle.ALL);
+        }
+    }
+
+    private int doMountVolume(String path) {
+        int rc = StorageResultCode.OperationSucceeded;
+
+        final StorageVolume volume;
+        synchronized (mVolumesLock) {
+            volume = mVolumesByPath.get(path);
+        }
+
+        if (DEBUG_EVENTS) Slog.i(TAG, "doMountVolume: Mouting " + path);
+        try {
+            mConnector.execute("volume", "mount", path);
+        } catch (NativeDaemonConnectorException e) {
+            /*
+             * Mount failed for some reason
+             */
+            String action = null;
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedNoMedia) {
+                /*
+                 * Attempt to mount but no media inserted
+                 */
+                rc = StorageResultCode.OperationFailedNoMedia;
+            } else if (code == VoldResponseCode.OpFailedMediaBlank) {
+                if (DEBUG_EVENTS) Slog.i(TAG, " updating volume state :: media nofs");
+                /*
+                 * Media is blank or does not contain a supported filesystem
+                 */
+                updatePublicVolumeState(volume, Environment.MEDIA_NOFS);
+                action = Intent.ACTION_MEDIA_NOFS;
+                rc = StorageResultCode.OperationFailedMediaBlank;
+            } else if (code == VoldResponseCode.OpFailedMediaCorrupt) {
+                if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state media corrupt");
+                /*
+                 * Volume consistency check failed
+                 */
+                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTABLE);
+                action = Intent.ACTION_MEDIA_UNMOUNTABLE;
+                rc = StorageResultCode.OperationFailedMediaCorrupt;
+            } else {
+                rc = StorageResultCode.OperationFailedInternalError;
+            }
+
+            /*
+             * Send broadcast intent (if required for the failure)
+             */
+            if (action != null) {
+                sendStorageIntent(action, volume, UserHandle.ALL);
+            }
+        }
+
+        return rc;
+    }
+
+    /*
+     * If force is not set, we do not unmount if there are
+     * processes holding references to the volume about to be unmounted.
+     * If force is set, all the processes holding references need to be
+     * killed via the ActivityManager before actually unmounting the volume.
+     * This might even take a while and might be retried after timed delays
+     * to make sure we dont end up in an instable state and kill some core
+     * processes.
+     * If removeEncryption is set, force is implied, and the system will remove any encryption
+     * mapping set on the volume when unmounting.
+     */
+    private int doUnmountVolume(String path, boolean force, boolean removeEncryption) {
+        if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) {
+            return VoldResponseCode.OpFailedVolNotMounted;
+        }
+
+        /*
+         * Force a GC to make sure AssetManagers in other threads of the
+         * system_server are cleaned up. We have to do this since AssetManager
+         * instances are kept as a WeakReference and it's possible we have files
+         * open on the external storage.
+         */
+        Runtime.getRuntime().gc();
+
+        // Redundant probably. But no harm in updating state again.
+        mPms.updateExternalMediaStatus(false, false);
+        try {
+            final Command cmd = new Command("volume", "unmount", path);
+            if (removeEncryption) {
+                cmd.appendArg("force_and_revert");
+            } else if (force) {
+                cmd.appendArg("force");
+            }
+            mConnector.execute(cmd);
+            // We unmounted the volume. None of the asec containers are available now.
+            synchronized (mAsecMountSet) {
+                mAsecMountSet.clear();
+            }
+            return StorageResultCode.OperationSucceeded;
+        } catch (NativeDaemonConnectorException e) {
+            // Don't worry about mismatch in PackageManager since the
+            // call back will handle the status changes any way.
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedVolNotMounted) {
+                return StorageResultCode.OperationFailedStorageNotMounted;
+            } else if (code == VoldResponseCode.OpFailedStorageBusy) {
+                return StorageResultCode.OperationFailedStorageBusy;
+            } else {
+                return StorageResultCode.OperationFailedInternalError;
+            }
+        }
+    }
+
+    private int doFormatVolume(String path) {
+        try {
+            mConnector.execute("volume", "format", path);
+            return StorageResultCode.OperationSucceeded;
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedNoMedia) {
+                return StorageResultCode.OperationFailedNoMedia;
+            } else if (code == VoldResponseCode.OpFailedMediaCorrupt) {
+                return StorageResultCode.OperationFailedMediaCorrupt;
+            } else {
+                return StorageResultCode.OperationFailedInternalError;
+            }
+        }
+    }
+
+    private boolean doGetVolumeShared(String path, String method) {
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("volume", "shared", path, method);
+        } catch (NativeDaemonConnectorException ex) {
+            Slog.e(TAG, "Failed to read response to volume shared " + path + " " + method);
+            return false;
+        }
+
+        if (event.getCode() == VoldResponseCode.ShareEnabledResult) {
+            return event.getMessage().endsWith("enabled");
+        } else {
+            return false;
+        }
+    }
+
+    private void notifyShareAvailabilityChange(final boolean avail) {
+        synchronized (mListeners) {
+            mUmsAvailable = avail;
+            for (int i = mListeners.size() -1; i >= 0; i--) {
+                MountServiceBinderListener bl = mListeners.get(i);
+                try {
+                    bl.mListener.onUsbMassStorageConnectionChanged(avail);
+                } catch (RemoteException rex) {
+                    Slog.e(TAG, "Listener dead");
+                    mListeners.remove(i);
+                } catch (Exception ex) {
+                    Slog.e(TAG, "Listener failed", ex);
+                }
+            }
+        }
+
+        if (mSystemReady == true) {
+            sendUmsIntent(avail);
+        } else {
+            mSendUmsConnectedOnBoot = avail;
+        }
+
+        final StorageVolume primary = getPrimaryPhysicalVolume();
+        if (avail == false && primary != null
+                && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) {
+            final String path = primary.getPath();
+            /*
+             * USB mass storage disconnected while enabled
+             */
+            new Thread("MountService#AvailabilityChange") {
+                @Override
+                public void run() {
+                    try {
+                        int rc;
+                        Slog.w(TAG, "Disabling UMS after cable disconnect");
+                        doShareUnshareVolume(path, "ums", false);
+                        if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
+                            Slog.e(TAG, String.format(
+                                    "Failed to remount {%s} on UMS enabled-disconnect (%d)",
+                                            path, rc));
+                        }
+                    } catch (Exception ex) {
+                        Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex);
+                    }
+                }
+            }.start();
+        }
+    }
+
+    private void sendStorageIntent(String action, StorageVolume volume, UserHandle user) {
+        final Intent intent = new Intent(action, Uri.parse("file://" + volume.getPath()));
+        intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, volume);
+        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        Slog.d(TAG, "sendStorageIntent " + intent + " to " + user);
+        mContext.sendBroadcastAsUser(intent, user);
+    }
+
+    private void sendUmsIntent(boolean c) {
+        mContext.sendBroadcastAsUser(
+                new Intent((c ? Intent.ACTION_UMS_CONNECTED : Intent.ACTION_UMS_DISCONNECTED)),
+                UserHandle.ALL);
+    }
+
+    private void validatePermission(String perm) {
+        if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException(String.format("Requires %s permission", perm));
+        }
+    }
+
+    // Storage list XML tags
+    private static final String TAG_STORAGE_LIST = "StorageList";
+    private static final String TAG_STORAGE = "storage";
+
+    private void readStorageListLocked() {
+        mVolumes.clear();
+        mVolumeStates.clear();
+
+        Resources resources = mContext.getResources();
+
+        int id = com.android.internal.R.xml.storage_list;
+        XmlResourceParser parser = resources.getXml(id);
+        AttributeSet attrs = Xml.asAttributeSet(parser);
+
+        try {
+            XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
+            while (true) {
+                XmlUtils.nextElement(parser);
+
+                String element = parser.getName();
+                if (element == null) break;
+
+                if (TAG_STORAGE.equals(element)) {
+                    TypedArray a = resources.obtainAttributes(attrs,
+                            com.android.internal.R.styleable.Storage);
+
+                    String path = a.getString(
+                            com.android.internal.R.styleable.Storage_mountPoint);
+                    int descriptionId = a.getResourceId(
+                            com.android.internal.R.styleable.Storage_storageDescription, -1);
+                    CharSequence description = a.getText(
+                            com.android.internal.R.styleable.Storage_storageDescription);
+                    boolean primary = a.getBoolean(
+                            com.android.internal.R.styleable.Storage_primary, false);
+                    boolean removable = a.getBoolean(
+                            com.android.internal.R.styleable.Storage_removable, false);
+                    boolean emulated = a.getBoolean(
+                            com.android.internal.R.styleable.Storage_emulated, false);
+                    int mtpReserve = a.getInt(
+                            com.android.internal.R.styleable.Storage_mtpReserve, 0);
+                    boolean allowMassStorage = a.getBoolean(
+                            com.android.internal.R.styleable.Storage_allowMassStorage, false);
+                    // resource parser does not support longs, so XML value is in megabytes
+                    long maxFileSize = a.getInt(
+                            com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L;
+
+                    Slog.d(TAG, "got storage path: " + path + " description: " + description +
+                            " primary: " + primary + " removable: " + removable +
+                            " emulated: " + emulated +  " mtpReserve: " + mtpReserve +
+                            " allowMassStorage: " + allowMassStorage +
+                            " maxFileSize: " + maxFileSize);
+
+                    if (emulated) {
+                        // For devices with emulated storage, we create separate
+                        // volumes for each known user.
+                        mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false,
+                                true, mtpReserve, false, maxFileSize, null);
+
+                        final UserManagerService userManager = UserManagerService.getInstance();
+                        for (UserInfo user : userManager.getUsers(false)) {
+                            createEmulatedVolumeForUserLocked(user.getUserHandle());
+                        }
+
+                    } else {
+                        if (path == null || description == null) {
+                            Slog.e(TAG, "Missing storage path or description in readStorageList");
+                        } else {
+                            final StorageVolume volume = new StorageVolume(new File(path),
+                                    descriptionId, primary, removable, emulated, mtpReserve,
+                                    allowMassStorage, maxFileSize, null);
+                            addVolumeLocked(volume);
+
+                            // Until we hear otherwise, treat as unmounted
+                            mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
+                            volume.setState(Environment.MEDIA_UNMOUNTED);
+                        }
+                    }
+
+                    a.recycle();
+                }
+            }
+        } catch (XmlPullParserException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            // Compute storage ID for each physical volume; emulated storage is
+            // always 0 when defined.
+            int index = isExternalStorageEmulated() ? 1 : 0;
+            for (StorageVolume volume : mVolumes) {
+                if (!volume.isEmulated()) {
+                    volume.setStorageId(index++);
+                }
+            }
+            parser.close();
+        }
+    }
+
+    /**
+     * Create and add new {@link StorageVolume} for given {@link UserHandle}
+     * using {@link #mEmulatedTemplate} as template.
+     */
+    private void createEmulatedVolumeForUserLocked(UserHandle user) {
+        if (mEmulatedTemplate == null) {
+            throw new IllegalStateException("Missing emulated volume multi-user template");
+        }
+
+        final UserEnvironment userEnv = new UserEnvironment(user.getIdentifier());
+        final File path = userEnv.getExternalStorageDirectory();
+        final StorageVolume volume = StorageVolume.fromTemplate(mEmulatedTemplate, path, user);
+        volume.setStorageId(0);
+        addVolumeLocked(volume);
+
+        if (mSystemReady) {
+            updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
+        } else {
+            // Place stub status for early callers to find
+            mVolumeStates.put(volume.getPath(), Environment.MEDIA_MOUNTED);
+            volume.setState(Environment.MEDIA_MOUNTED);
+        }
+    }
+
+    private void addVolumeLocked(StorageVolume volume) {
+        Slog.d(TAG, "addVolumeLocked() " + volume);
+        mVolumes.add(volume);
+        final StorageVolume existing = mVolumesByPath.put(volume.getPath(), volume);
+        if (existing != null) {
+            throw new IllegalStateException(
+                    "Volume at " + volume.getPath() + " already exists: " + existing);
+        }
+    }
+
+    private void removeVolumeLocked(StorageVolume volume) {
+        Slog.d(TAG, "removeVolumeLocked() " + volume);
+        mVolumes.remove(volume);
+        mVolumesByPath.remove(volume.getPath());
+        mVolumeStates.remove(volume.getPath());
+    }
+
+    private StorageVolume getPrimaryPhysicalVolume() {
+        synchronized (mVolumesLock) {
+            for (StorageVolume volume : mVolumes) {
+                if (volume.isPrimary() && !volume.isEmulated()) {
+                    return volume;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Constructs a new MountService instance
+     *
+     * @param context  Binder context for this service
+     */
+    public MountService(Context context) {
+        mContext = context;
+
+        synchronized (mVolumesLock) {
+            readStorageListLocked();
+        }
+
+        // XXX: This will go away soon in favor of IMountServiceObserver
+        mPms = (PackageManagerService) ServiceManager.getService("package");
+
+        HandlerThread hthread = new HandlerThread(TAG);
+        hthread.start();
+        mHandler = new MountServiceHandler(hthread.getLooper());
+
+        // Watch for user changes
+        final IntentFilter userFilter = new IntentFilter();
+        userFilter.addAction(Intent.ACTION_USER_ADDED);
+        userFilter.addAction(Intent.ACTION_USER_REMOVED);
+        mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);
+
+        // Watch for USB changes on primary volume
+        final StorageVolume primary = getPrimaryPhysicalVolume();
+        if (primary != null && primary.allowMassStorage()) {
+            mContext.registerReceiver(
+                    mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler);
+        }
+
+        // Watch for idle maintenance changes
+        IntentFilter idleMaintenanceFilter = new IntentFilter();
+        idleMaintenanceFilter.addAction(Intent.ACTION_IDLE_MAINTENANCE_START);
+        mContext.registerReceiverAsUser(mIdleMaintenanceReceiver, UserHandle.ALL,
+                idleMaintenanceFilter, null, mHandler);
+
+        // Add OBB Action Handler to MountService thread.
+        mObbActionHandler = new ObbActionHandler(IoThread.get().getLooper());
+
+        /*
+         * Create the connection to vold with a maximum queue of twice the
+         * amount of containers we'd ever expect to have. This keeps an
+         * "asec list" from blocking a thread repeatedly.
+         */
+        mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25);
+
+        Thread thread = new Thread(mConnector, VOLD_TAG);
+        thread.start();
+
+        // Add ourself to the Watchdog monitors if enabled.
+        if (WATCHDOG_ENABLE) {
+            Watchdog.getInstance().addMonitor(this);
+        }
+    }
+
+    public void systemReady() {
+        mSystemReady = true;
+        mHandler.obtainMessage(H_SYSTEM_READY).sendToTarget();
+    }
+
+    /**
+     * Exposed API calls below here
+     */
+
+    public void registerListener(IMountServiceListener listener) {
+        synchronized (mListeners) {
+            MountServiceBinderListener bl = new MountServiceBinderListener(listener);
+            try {
+                listener.asBinder().linkToDeath(bl, 0);
+                mListeners.add(bl);
+            } catch (RemoteException rex) {
+                Slog.e(TAG, "Failed to link to listener death");
+            }
+        }
+    }
+
+    public void unregisterListener(IMountServiceListener listener) {
+        synchronized (mListeners) {
+            for(MountServiceBinderListener bl : mListeners) {
+                if (bl.mListener.asBinder() == listener.asBinder()) {
+                    mListeners.remove(mListeners.indexOf(bl));
+                    listener.asBinder().unlinkToDeath(bl, 0);
+                    return;
+                }
+            }
+        }
+    }
+
+    public void shutdown(final IMountShutdownObserver observer) {
+        validatePermission(android.Manifest.permission.SHUTDOWN);
+
+        Slog.i(TAG, "Shutting down");
+        synchronized (mVolumesLock) {
+            for (String path : mVolumeStates.keySet()) {
+                String state = mVolumeStates.get(path);
+
+                if (state.equals(Environment.MEDIA_SHARED)) {
+                    /*
+                     * If the media is currently shared, unshare it.
+                     * XXX: This is still dangerous!. We should not
+                     * be rebooting at *all* if UMS is enabled, since
+                     * the UMS host could have dirty FAT cache entries
+                     * yet to flush.
+                     */
+                    setUsbMassStorageEnabled(false);
+                } else if (state.equals(Environment.MEDIA_CHECKING)) {
+                    /*
+                     * If the media is being checked, then we need to wait for
+                     * it to complete before being able to proceed.
+                     */
+                    // XXX: @hackbod - Should we disable the ANR timer here?
+                    int retries = 30;
+                    while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >=0)) {
+                        try {
+                            Thread.sleep(1000);
+                        } catch (InterruptedException iex) {
+                            Slog.e(TAG, "Interrupted while waiting for media", iex);
+                            break;
+                        }
+                        state = Environment.getExternalStorageState();
+                    }
+                    if (retries == 0) {
+                        Slog.e(TAG, "Timed out waiting for media to check");
+                    }
+                }
+
+                if (state.equals(Environment.MEDIA_MOUNTED)) {
+                    // Post a unmount message.
+                    ShutdownCallBack ucb = new ShutdownCallBack(path, observer);
+                    mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
+                } else if (observer != null) {
+                    /*
+                     * Observer is waiting for onShutDownComplete when we are done.
+                     * Since nothing will be done send notification directly so shutdown
+                     * sequence can continue.
+                     */
+                    try {
+                        observer.onShutDownComplete(StorageResultCode.OperationSucceeded);
+                    } catch (RemoteException e) {
+                        Slog.w(TAG, "RemoteException when shutting down");
+                    }
+                }
+            }
+        }
+    }
+
+    private boolean getUmsEnabling() {
+        synchronized (mListeners) {
+            return mUmsEnabling;
+        }
+    }
+
+    private void setUmsEnabling(boolean enable) {
+        synchronized (mListeners) {
+            mUmsEnabling = enable;
+        }
+    }
+
+    public boolean isUsbMassStorageConnected() {
+        waitForReady();
+
+        if (getUmsEnabling()) {
+            return true;
+        }
+        synchronized (mListeners) {
+            return mUmsAvailable;
+        }
+    }
+
+    public void setUsbMassStorageEnabled(boolean enable) {
+        waitForReady();
+        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
+
+        final StorageVolume primary = getPrimaryPhysicalVolume();
+        if (primary == null) return;
+
+        // TODO: Add support for multiple share methods
+
+        /*
+         * If the volume is mounted and we're enabling then unmount it
+         */
+        String path = primary.getPath();
+        String vs = getVolumeState(path);
+        String method = "ums";
+        if (enable && vs.equals(Environment.MEDIA_MOUNTED)) {
+            // Override for isUsbMassStorageEnabled()
+            setUmsEnabling(enable);
+            UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true);
+            mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb));
+            // Clear override
+            setUmsEnabling(false);
+        }
+        /*
+         * If we disabled UMS then mount the volume
+         */
+        if (!enable) {
+            doShareUnshareVolume(path, method, enable);
+            if (doMountVolume(path) != StorageResultCode.OperationSucceeded) {
+                Slog.e(TAG, "Failed to remount " + path +
+                        " after disabling share method " + method);
+                /*
+                 * Even though the mount failed, the unshare didn't so don't indicate an error.
+                 * The mountVolume() call will have set the storage state and sent the necessary
+                 * broadcasts.
+                 */
+            }
+        }
+    }
+
+    public boolean isUsbMassStorageEnabled() {
+        waitForReady();
+
+        final StorageVolume primary = getPrimaryPhysicalVolume();
+        if (primary != null) {
+            return doGetVolumeShared(primary.getPath(), "ums");
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * @return state of the volume at the specified mount point
+     */
+    public String getVolumeState(String mountPoint) {
+        synchronized (mVolumesLock) {
+            String state = mVolumeStates.get(mountPoint);
+            if (state == null) {
+                Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume");
+                if (SystemProperties.get("vold.encrypt_progress").length() != 0) {
+                    state = Environment.MEDIA_REMOVED;
+                } else {
+                    throw new IllegalArgumentException();
+                }
+            }
+
+            return state;
+        }
+    }
+
+    @Override
+    public boolean isExternalStorageEmulated() {
+        return mEmulatedTemplate != null;
+    }
+
+    public int mountVolume(String path) {
+        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
+
+        waitForReady();
+        return doMountVolume(path);
+    }
+
+    public void unmountVolume(String path, boolean force, boolean removeEncryption) {
+        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
+        waitForReady();
+
+        String volState = getVolumeState(path);
+        if (DEBUG_UNMOUNT) {
+            Slog.i(TAG, "Unmounting " + path
+                    + " force = " + force
+                    + " removeEncryption = " + removeEncryption);
+        }
+        if (Environment.MEDIA_UNMOUNTED.equals(volState) ||
+                Environment.MEDIA_REMOVED.equals(volState) ||
+                Environment.MEDIA_SHARED.equals(volState) ||
+                Environment.MEDIA_UNMOUNTABLE.equals(volState)) {
+            // Media already unmounted or cannot be unmounted.
+            // TODO return valid return code when adding observer call back.
+            return;
+        }
+        UnmountCallBack ucb = new UnmountCallBack(path, force, removeEncryption);
+        mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
+    }
+
+    public int formatVolume(String path) {
+        validatePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
+        waitForReady();
+
+        return doFormatVolume(path);
+    }
+
+    public int[] getStorageUsers(String path) {
+        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
+        waitForReady();
+        try {
+            final String[] r = NativeDaemonEvent.filterMessageList(
+                    mConnector.executeForList("storage", "users", path),
+                    VoldResponseCode.StorageUsersListResult);
+
+            // FMT: <pid> <process name>
+            int[] data = new int[r.length];
+            for (int i = 0; i < r.length; i++) {
+                String[] tok = r[i].split(" ");
+                try {
+                    data[i] = Integer.parseInt(tok[0]);
+                } catch (NumberFormatException nfe) {
+                    Slog.e(TAG, String.format("Error parsing pid %s", tok[0]));
+                    return new int[0];
+                }
+            }
+            return data;
+        } catch (NativeDaemonConnectorException e) {
+            Slog.e(TAG, "Failed to retrieve storage users list", e);
+            return new int[0];
+        }
+    }
+
+    private void warnOnNotMounted() {
+        final StorageVolume primary = getPrimaryPhysicalVolume();
+        if (primary != null) {
+            boolean mounted = false;
+            try {
+                mounted = Environment.MEDIA_MOUNTED.equals(getVolumeState(primary.getPath()));
+            } catch (IllegalArgumentException e) {
+            }
+
+            if (!mounted) {
+                Slog.w(TAG, "getSecureContainerList() called when storage not mounted");
+            }
+        }
+    }
+
+    public String[] getSecureContainerList() {
+        validatePermission(android.Manifest.permission.ASEC_ACCESS);
+        waitForReady();
+        warnOnNotMounted();
+
+        try {
+            return NativeDaemonEvent.filterMessageList(
+                    mConnector.executeForList("asec", "list"), VoldResponseCode.AsecListResult);
+        } catch (NativeDaemonConnectorException e) {
+            return new String[0];
+        }
+    }
+
+    public int createSecureContainer(String id, int sizeMb, String fstype, String key,
+            int ownerUid, boolean external) {
+        validatePermission(android.Manifest.permission.ASEC_CREATE);
+        waitForReady();
+        warnOnNotMounted();
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            mConnector.execute("asec", "create", id, sizeMb, fstype, new SensitiveArg(key),
+                    ownerUid, external ? "1" : "0");
+        } catch (NativeDaemonConnectorException e) {
+            rc = StorageResultCode.OperationFailedInternalError;
+        }
+
+        if (rc == StorageResultCode.OperationSucceeded) {
+            synchronized (mAsecMountSet) {
+                mAsecMountSet.add(id);
+            }
+        }
+        return rc;
+    }
+
+    public int finalizeSecureContainer(String id) {
+        validatePermission(android.Manifest.permission.ASEC_CREATE);
+        warnOnNotMounted();
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            mConnector.execute("asec", "finalize", id);
+            /*
+             * Finalization does a remount, so no need
+             * to update mAsecMountSet
+             */
+        } catch (NativeDaemonConnectorException e) {
+            rc = StorageResultCode.OperationFailedInternalError;
+        }
+        return rc;
+    }
+
+    public int fixPermissionsSecureContainer(String id, int gid, String filename) {
+        validatePermission(android.Manifest.permission.ASEC_CREATE);
+        warnOnNotMounted();
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            mConnector.execute("asec", "fixperms", id, gid, filename);
+            /*
+             * Fix permissions does a remount, so no need to update
+             * mAsecMountSet
+             */
+        } catch (NativeDaemonConnectorException e) {
+            rc = StorageResultCode.OperationFailedInternalError;
+        }
+        return rc;
+    }
+
+    public int destroySecureContainer(String id, boolean force) {
+        validatePermission(android.Manifest.permission.ASEC_DESTROY);
+        waitForReady();
+        warnOnNotMounted();
+
+        /*
+         * Force a GC to make sure AssetManagers in other threads of the
+         * system_server are cleaned up. We have to do this since AssetManager
+         * instances are kept as a WeakReference and it's possible we have files
+         * open on the external storage.
+         */
+        Runtime.getRuntime().gc();
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            final Command cmd = new Command("asec", "destroy", id);
+            if (force) {
+                cmd.appendArg("force");
+            }
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedStorageBusy) {
+                rc = StorageResultCode.OperationFailedStorageBusy;
+            } else {
+                rc = StorageResultCode.OperationFailedInternalError;
+            }
+        }
+
+        if (rc == StorageResultCode.OperationSucceeded) {
+            synchronized (mAsecMountSet) {
+                if (mAsecMountSet.contains(id)) {
+                    mAsecMountSet.remove(id);
+                }
+            }
+        }
+
+        return rc;
+    }
+
+    public int mountSecureContainer(String id, String key, int ownerUid) {
+        validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
+        waitForReady();
+        warnOnNotMounted();
+
+        synchronized (mAsecMountSet) {
+            if (mAsecMountSet.contains(id)) {
+                return StorageResultCode.OperationFailedStorageMounted;
+            }
+        }
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            mConnector.execute("asec", "mount", id, new SensitiveArg(key), ownerUid);
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code != VoldResponseCode.OpFailedStorageBusy) {
+                rc = StorageResultCode.OperationFailedInternalError;
+            }
+        }
+
+        if (rc == StorageResultCode.OperationSucceeded) {
+            synchronized (mAsecMountSet) {
+                mAsecMountSet.add(id);
+            }
+        }
+        return rc;
+    }
+
+    public int unmountSecureContainer(String id, boolean force) {
+        validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
+        waitForReady();
+        warnOnNotMounted();
+
+        synchronized (mAsecMountSet) {
+            if (!mAsecMountSet.contains(id)) {
+                return StorageResultCode.OperationFailedStorageNotMounted;
+            }
+         }
+
+        /*
+         * Force a GC to make sure AssetManagers in other threads of the
+         * system_server are cleaned up. We have to do this since AssetManager
+         * instances are kept as a WeakReference and it's possible we have files
+         * open on the external storage.
+         */
+        Runtime.getRuntime().gc();
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            final Command cmd = new Command("asec", "unmount", id);
+            if (force) {
+                cmd.appendArg("force");
+            }
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedStorageBusy) {
+                rc = StorageResultCode.OperationFailedStorageBusy;
+            } else {
+                rc = StorageResultCode.OperationFailedInternalError;
+            }
+        }
+
+        if (rc == StorageResultCode.OperationSucceeded) {
+            synchronized (mAsecMountSet) {
+                mAsecMountSet.remove(id);
+            }
+        }
+        return rc;
+    }
+
+    public boolean isSecureContainerMounted(String id) {
+        validatePermission(android.Manifest.permission.ASEC_ACCESS);
+        waitForReady();
+        warnOnNotMounted();
+
+        synchronized (mAsecMountSet) {
+            return mAsecMountSet.contains(id);
+        }
+    }
+
+    public int renameSecureContainer(String oldId, String newId) {
+        validatePermission(android.Manifest.permission.ASEC_RENAME);
+        waitForReady();
+        warnOnNotMounted();
+
+        synchronized (mAsecMountSet) {
+            /*
+             * Because a mounted container has active internal state which cannot be
+             * changed while active, we must ensure both ids are not currently mounted.
+             */
+            if (mAsecMountSet.contains(oldId) || mAsecMountSet.contains(newId)) {
+                return StorageResultCode.OperationFailedStorageMounted;
+            }
+        }
+
+        int rc = StorageResultCode.OperationSucceeded;
+        try {
+            mConnector.execute("asec", "rename", oldId, newId);
+        } catch (NativeDaemonConnectorException e) {
+            rc = StorageResultCode.OperationFailedInternalError;
+        }
+
+        return rc;
+    }
+
+    public String getSecureContainerPath(String id) {
+        validatePermission(android.Manifest.permission.ASEC_ACCESS);
+        waitForReady();
+        warnOnNotMounted();
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("asec", "path", id);
+            event.checkCode(VoldResponseCode.AsecPathResult);
+            return event.getMessage();
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedStorageNotFound) {
+                Slog.i(TAG, String.format("Container '%s' not found", id));
+                return null;
+            } else {
+                throw new IllegalStateException(String.format("Unexpected response code %d", code));
+            }
+        }
+    }
+
+    public String getSecureContainerFilesystemPath(String id) {
+        validatePermission(android.Manifest.permission.ASEC_ACCESS);
+        waitForReady();
+        warnOnNotMounted();
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("asec", "fspath", id);
+            event.checkCode(VoldResponseCode.AsecPathResult);
+            return event.getMessage();
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedStorageNotFound) {
+                Slog.i(TAG, String.format("Container '%s' not found", id));
+                return null;
+            } else {
+                throw new IllegalStateException(String.format("Unexpected response code %d", code));
+            }
+        }
+    }
+
+    public void finishMediaUpdate() {
+        mHandler.sendEmptyMessage(H_UNMOUNT_PM_DONE);
+    }
+
+    private boolean isUidOwnerOfPackageOrSystem(String packageName, int callerUid) {
+        if (callerUid == android.os.Process.SYSTEM_UID) {
+            return true;
+        }
+
+        if (packageName == null) {
+            return false;
+        }
+
+        final int packageUid = mPms.getPackageUid(packageName, UserHandle.getUserId(callerUid));
+
+        if (DEBUG_OBB) {
+            Slog.d(TAG, "packageName = " + packageName + ", packageUid = " +
+                    packageUid + ", callerUid = " + callerUid);
+        }
+
+        return callerUid == packageUid;
+    }
+
+    public String getMountedObbPath(String rawPath) {
+        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
+
+        waitForReady();
+        warnOnNotMounted();
+
+        final ObbState state;
+        synchronized (mObbPathToStateMap) {
+            state = mObbPathToStateMap.get(rawPath);
+        }
+        if (state == null) {
+            Slog.w(TAG, "Failed to find OBB mounted at " + rawPath);
+            return null;
+        }
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("obb", "path", state.voldPath);
+            event.checkCode(VoldResponseCode.AsecPathResult);
+            return event.getMessage();
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedStorageNotFound) {
+                return null;
+            } else {
+                throw new IllegalStateException(String.format("Unexpected response code %d", code));
+            }
+        }
+    }
+
+    @Override
+    public boolean isObbMounted(String rawPath) {
+        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
+        synchronized (mObbMounts) {
+            return mObbPathToStateMap.containsKey(rawPath);
+        }
+    }
+
+    @Override
+    public void mountObb(
+            String rawPath, String canonicalPath, String key, IObbActionListener token, int nonce) {
+        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
+        Preconditions.checkNotNull(canonicalPath, "canonicalPath cannot be null");
+        Preconditions.checkNotNull(token, "token cannot be null");
+
+        final int callingUid = Binder.getCallingUid();
+        final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce);
+        final ObbAction action = new MountObbAction(obbState, key, callingUid);
+        mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));
+
+        if (DEBUG_OBB)
+            Slog.i(TAG, "Send to OBB handler: " + action.toString());
+    }
+
+    @Override
+    public void unmountObb(String rawPath, boolean force, IObbActionListener token, int nonce) {
+        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
+
+        final ObbState existingState;
+        synchronized (mObbPathToStateMap) {
+            existingState = mObbPathToStateMap.get(rawPath);
+        }
+
+        if (existingState != null) {
+            // TODO: separate state object from request data
+            final int callingUid = Binder.getCallingUid();
+            final ObbState newState = new ObbState(
+                    rawPath, existingState.canonicalPath, callingUid, token, nonce);
+            final ObbAction action = new UnmountObbAction(newState, force);
+            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));
+
+            if (DEBUG_OBB)
+                Slog.i(TAG, "Send to OBB handler: " + action.toString());
+        } else {
+            Slog.w(TAG, "Unknown OBB mount at " + rawPath);
+        }
+    }
+
+    @Override
+    public int getEncryptionState() {
+        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
+                "no permission to access the crypt keeper");
+
+        waitForReady();
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("cryptfs", "cryptocomplete");
+            return Integer.parseInt(event.getMessage());
+        } catch (NumberFormatException e) {
+            // Bad result - unexpected.
+            Slog.w(TAG, "Unable to parse result from cryptfs cryptocomplete");
+            return ENCRYPTION_STATE_ERROR_UNKNOWN;
+        } catch (NativeDaemonConnectorException e) {
+            // Something bad happened.
+            Slog.w(TAG, "Error in communicating with cryptfs in validating");
+            return ENCRYPTION_STATE_ERROR_UNKNOWN;
+        }
+    }
+
+    @Override
+    public int decryptStorage(String password) {
+        if (TextUtils.isEmpty(password)) {
+            throw new IllegalArgumentException("password cannot be empty");
+        }
+
+        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
+                "no permission to access the crypt keeper");
+
+        waitForReady();
+
+        if (DEBUG_EVENTS) {
+            Slog.i(TAG, "decrypting storage...");
+        }
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("cryptfs", "checkpw", new SensitiveArg(password));
+
+            final int code = Integer.parseInt(event.getMessage());
+            if (code == 0) {
+                // Decrypt was successful. Post a delayed message before restarting in order
+                // to let the UI to clear itself
+                mHandler.postDelayed(new Runnable() {
+                    public void run() {
+                        try {
+                            mConnector.execute("cryptfs", "restart");
+                        } catch (NativeDaemonConnectorException e) {
+                            Slog.e(TAG, "problem executing in background", e);
+                        }
+                    }
+                }, 1000); // 1 second
+            }
+
+            return code;
+        } catch (NativeDaemonConnectorException e) {
+            // Decryption failed
+            return e.getCode();
+        }
+    }
+
+    public int encryptStorage(String password) {
+        if (TextUtils.isEmpty(password)) {
+            throw new IllegalArgumentException("password cannot be empty");
+        }
+
+        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
+            "no permission to access the crypt keeper");
+
+        waitForReady();
+
+        if (DEBUG_EVENTS) {
+            Slog.i(TAG, "encrypting storage...");
+        }
+
+        try {
+            mConnector.execute("cryptfs", "enablecrypto", "inplace", new SensitiveArg(password));
+        } catch (NativeDaemonConnectorException e) {
+            // Encryption failed
+            return e.getCode();
+        }
+
+        return 0;
+    }
+
+    public int changeEncryptionPassword(String password) {
+        if (TextUtils.isEmpty(password)) {
+            throw new IllegalArgumentException("password cannot be empty");
+        }
+
+        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
+            "no permission to access the crypt keeper");
+
+        waitForReady();
+
+        if (DEBUG_EVENTS) {
+            Slog.i(TAG, "changing encryption password...");
+        }
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("cryptfs", "changepw", new SensitiveArg(password));
+            return Integer.parseInt(event.getMessage());
+        } catch (NativeDaemonConnectorException e) {
+            // Encryption failed
+            return e.getCode();
+        }
+    }
+
+    /**
+     * Validate a user-supplied password string with cryptfs
+     */
+    @Override
+    public int verifyEncryptionPassword(String password) throws RemoteException {
+        // Only the system process is permitted to validate passwords
+        if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
+            throw new SecurityException("no permission to access the crypt keeper");
+        }
+
+        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
+            "no permission to access the crypt keeper");
+
+        if (TextUtils.isEmpty(password)) {
+            throw new IllegalArgumentException("password cannot be empty");
+        }
+
+        waitForReady();
+
+        if (DEBUG_EVENTS) {
+            Slog.i(TAG, "validating encryption password...");
+        }
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("cryptfs", "verifypw", new SensitiveArg(password));
+            Slog.i(TAG, "cryptfs verifypw => " + event.getMessage());
+            return Integer.parseInt(event.getMessage());
+        } catch (NativeDaemonConnectorException e) {
+            // Encryption failed
+            return e.getCode();
+        }
+    }
+
+    @Override
+    public int mkdirs(String callingPkg, String appPath) {
+        final int userId = UserHandle.getUserId(Binder.getCallingUid());
+        final UserEnvironment userEnv = new UserEnvironment(userId);
+
+        // Validate that reported package name belongs to caller
+        final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(
+                Context.APP_OPS_SERVICE);
+        appOps.checkPackage(Binder.getCallingUid(), callingPkg);
+
+        try {
+            appPath = new File(appPath).getCanonicalPath();
+        } catch (IOException e) {
+            Slog.e(TAG, "Failed to resolve " + appPath + ": " + e);
+            return -1;
+        }
+
+        if (!appPath.endsWith("/")) {
+            appPath = appPath + "/";
+        }
+
+        // Try translating the app path into a vold path, but require that it
+        // belong to the calling package.
+        String voldPath = maybeTranslatePathForVold(appPath,
+                userEnv.buildExternalStorageAppDataDirs(callingPkg),
+                userEnv.buildExternalStorageAppDataDirsForVold(callingPkg));
+        if (voldPath != null) {
+            try {
+                mConnector.execute("volume", "mkdirs", voldPath);
+                return 0;
+            } catch (NativeDaemonConnectorException e) {
+                return e.getCode();
+            }
+        }
+
+        voldPath = maybeTranslatePathForVold(appPath,
+                userEnv.buildExternalStorageAppObbDirs(callingPkg),
+                userEnv.buildExternalStorageAppObbDirsForVold(callingPkg));
+        if (voldPath != null) {
+            try {
+                mConnector.execute("volume", "mkdirs", voldPath);
+                return 0;
+            } catch (NativeDaemonConnectorException e) {
+                return e.getCode();
+            }
+        }
+
+        throw new SecurityException("Invalid mkdirs path: " + appPath);
+    }
+
+    /**
+     * Translate the given path from an app-visible path to a vold-visible path,
+     * but only if it's under the given whitelisted paths.
+     *
+     * @param path a canonicalized app-visible path.
+     * @param appPaths list of app-visible paths that are allowed.
+     * @param voldPaths list of vold-visible paths directly corresponding to the
+     *            allowed app-visible paths argument.
+     * @return a vold-visible path representing the original path, or
+     *         {@code null} if the given path didn't have an app-to-vold
+     *         mapping.
+     */
+    @VisibleForTesting
+    public static String maybeTranslatePathForVold(
+            String path, File[] appPaths, File[] voldPaths) {
+        if (appPaths.length != voldPaths.length) {
+            throw new IllegalStateException("Paths must be 1:1 mapping");
+        }
+
+        for (int i = 0; i < appPaths.length; i++) {
+            final String appPath = appPaths[i].getAbsolutePath() + "/";
+            if (path.startsWith(appPath)) {
+                path = new File(voldPaths[i], path.substring(appPath.length()))
+                        .getAbsolutePath();
+                if (!path.endsWith("/")) {
+                    path = path + "/";
+                }
+                return path;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public StorageVolume[] getVolumeList() {
+        final int callingUserId = UserHandle.getCallingUserId();
+        final boolean accessAll = (mContext.checkPermission(
+                android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
+                Binder.getCallingPid(), Binder.getCallingUid()) == PERMISSION_GRANTED);
+
+        synchronized (mVolumesLock) {
+            final ArrayList<StorageVolume> filtered = Lists.newArrayList();
+            for (StorageVolume volume : mVolumes) {
+                final UserHandle owner = volume.getOwner();
+                final boolean ownerMatch = owner == null || owner.getIdentifier() == callingUserId;
+                if (accessAll || ownerMatch) {
+                    filtered.add(volume);
+                }
+            }
+            return filtered.toArray(new StorageVolume[filtered.size()]);
+        }
+    }
+
+    private void addObbStateLocked(ObbState obbState) throws RemoteException {
+        final IBinder binder = obbState.getBinder();
+        List<ObbState> obbStates = mObbMounts.get(binder);
+
+        if (obbStates == null) {
+            obbStates = new ArrayList<ObbState>();
+            mObbMounts.put(binder, obbStates);
+        } else {
+            for (final ObbState o : obbStates) {
+                if (o.rawPath.equals(obbState.rawPath)) {
+                    throw new IllegalStateException("Attempt to add ObbState twice. "
+                            + "This indicates an error in the MountService logic.");
+                }
+            }
+        }
+
+        obbStates.add(obbState);
+        try {
+            obbState.link();
+        } catch (RemoteException e) {
+            /*
+             * The binder died before we could link it, so clean up our state
+             * and return failure.
+             */
+            obbStates.remove(obbState);
+            if (obbStates.isEmpty()) {
+                mObbMounts.remove(binder);
+            }
+
+            // Rethrow the error so mountObb can get it
+            throw e;
+        }
+
+        mObbPathToStateMap.put(obbState.rawPath, obbState);
+    }
+
+    private void removeObbStateLocked(ObbState obbState) {
+        final IBinder binder = obbState.getBinder();
+        final List<ObbState> obbStates = mObbMounts.get(binder);
+        if (obbStates != null) {
+            if (obbStates.remove(obbState)) {
+                obbState.unlink();
+            }
+            if (obbStates.isEmpty()) {
+                mObbMounts.remove(binder);
+            }
+        }
+
+        mObbPathToStateMap.remove(obbState.rawPath);
+    }
+
+    private class ObbActionHandler extends Handler {
+        private boolean mBound = false;
+        private final List<ObbAction> mActions = new LinkedList<ObbAction>();
+
+        ObbActionHandler(Looper l) {
+            super(l);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case OBB_RUN_ACTION: {
+                    final ObbAction action = (ObbAction) msg.obj;
+
+                    if (DEBUG_OBB)
+                        Slog.i(TAG, "OBB_RUN_ACTION: " + action.toString());
+
+                    // If a bind was already initiated we don't really
+                    // need to do anything. The pending install
+                    // will be processed later on.
+                    if (!mBound) {
+                        // If this is the only one pending we might
+                        // have to bind to the service again.
+                        if (!connectToService()) {
+                            Slog.e(TAG, "Failed to bind to media container service");
+                            action.handleError();
+                            return;
+                        }
+                    }
+
+                    mActions.add(action);
+                    break;
+                }
+                case OBB_MCS_BOUND: {
+                    if (DEBUG_OBB)
+                        Slog.i(TAG, "OBB_MCS_BOUND");
+                    if (msg.obj != null) {
+                        mContainerService = (IMediaContainerService) msg.obj;
+                    }
+                    if (mContainerService == null) {
+                        // Something seriously wrong. Bail out
+                        Slog.e(TAG, "Cannot bind to media container service");
+                        for (ObbAction action : mActions) {
+                            // Indicate service bind error
+                            action.handleError();
+                        }
+                        mActions.clear();
+                    } else if (mActions.size() > 0) {
+                        final ObbAction action = mActions.get(0);
+                        if (action != null) {
+                            action.execute(this);
+                        }
+                    } else {
+                        // Should never happen ideally.
+                        Slog.w(TAG, "Empty queue");
+                    }
+                    break;
+                }
+                case OBB_MCS_RECONNECT: {
+                    if (DEBUG_OBB)
+                        Slog.i(TAG, "OBB_MCS_RECONNECT");
+                    if (mActions.size() > 0) {
+                        if (mBound) {
+                            disconnectService();
+                        }
+                        if (!connectToService()) {
+                            Slog.e(TAG, "Failed to bind to media container service");
+                            for (ObbAction action : mActions) {
+                                // Indicate service bind error
+                                action.handleError();
+                            }
+                            mActions.clear();
+                        }
+                    }
+                    break;
+                }
+                case OBB_MCS_UNBIND: {
+                    if (DEBUG_OBB)
+                        Slog.i(TAG, "OBB_MCS_UNBIND");
+
+                    // Delete pending install
+                    if (mActions.size() > 0) {
+                        mActions.remove(0);
+                    }
+                    if (mActions.size() == 0) {
+                        if (mBound) {
+                            disconnectService();
+                        }
+                    } else {
+                        // There are more pending requests in queue.
+                        // Just post MCS_BOUND message to trigger processing
+                        // of next pending install.
+                        mObbActionHandler.sendEmptyMessage(OBB_MCS_BOUND);
+                    }
+                    break;
+                }
+                case OBB_FLUSH_MOUNT_STATE: {
+                    final String path = (String) msg.obj;
+
+                    if (DEBUG_OBB)
+                        Slog.i(TAG, "Flushing all OBB state for path " + path);
+
+                    synchronized (mObbMounts) {
+                        final List<ObbState> obbStatesToRemove = new LinkedList<ObbState>();
+
+                        final Iterator<ObbState> i = mObbPathToStateMap.values().iterator();
+                        while (i.hasNext()) {
+                            final ObbState state = i.next();
+
+                            /*
+                             * If this entry's source file is in the volume path
+                             * that got unmounted, remove it because it's no
+                             * longer valid.
+                             */
+                            if (state.canonicalPath.startsWith(path)) {
+                                obbStatesToRemove.add(state);
+                            }
+                        }
+
+                        for (final ObbState obbState : obbStatesToRemove) {
+                            if (DEBUG_OBB)
+                                Slog.i(TAG, "Removing state for " + obbState.rawPath);
+
+                            removeObbStateLocked(obbState);
+
+                            try {
+                                obbState.token.onObbResult(obbState.rawPath, obbState.nonce,
+                                        OnObbStateChangeListener.UNMOUNTED);
+                            } catch (RemoteException e) {
+                                Slog.i(TAG, "Couldn't send unmount notification for  OBB: "
+                                        + obbState.rawPath);
+                            }
+                        }
+                    }
+                    break;
+                }
+            }
+        }
+
+        private boolean connectToService() {
+            if (DEBUG_OBB)
+                Slog.i(TAG, "Trying to bind to DefaultContainerService");
+
+            Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
+            if (mContext.bindService(service, mDefContainerConn, Context.BIND_AUTO_CREATE)) {
+                mBound = true;
+                return true;
+            }
+            return false;
+        }
+
+        private void disconnectService() {
+            mContainerService = null;
+            mBound = false;
+            mContext.unbindService(mDefContainerConn);
+        }
+    }
+
+    abstract class ObbAction {
+        private static final int MAX_RETRIES = 3;
+        private int mRetries;
+
+        ObbState mObbState;
+
+        ObbAction(ObbState obbState) {
+            mObbState = obbState;
+        }
+
+        public void execute(ObbActionHandler handler) {
+            try {
+                if (DEBUG_OBB)
+                    Slog.i(TAG, "Starting to execute action: " + toString());
+                mRetries++;
+                if (mRetries > MAX_RETRIES) {
+                    Slog.w(TAG, "Failed to invoke remote methods on default container service. Giving up");
+                    mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND);
+                    handleError();
+                    return;
+                } else {
+                    handleExecute();
+                    if (DEBUG_OBB)
+                        Slog.i(TAG, "Posting install MCS_UNBIND");
+                    mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND);
+                }
+            } catch (RemoteException e) {
+                if (DEBUG_OBB)
+                    Slog.i(TAG, "Posting install MCS_RECONNECT");
+                mObbActionHandler.sendEmptyMessage(OBB_MCS_RECONNECT);
+            } catch (Exception e) {
+                if (DEBUG_OBB)
+                    Slog.d(TAG, "Error handling OBB action", e);
+                handleError();
+                mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND);
+            }
+        }
+
+        abstract void handleExecute() throws RemoteException, IOException;
+        abstract void handleError();
+
+        protected ObbInfo getObbInfo() throws IOException {
+            ObbInfo obbInfo;
+            try {
+                obbInfo = mContainerService.getObbInfo(mObbState.ownerPath);
+            } catch (RemoteException e) {
+                Slog.d(TAG, "Couldn't call DefaultContainerService to fetch OBB info for "
+                        + mObbState.ownerPath);
+                obbInfo = null;
+            }
+            if (obbInfo == null) {
+                throw new IOException("Couldn't read OBB file: " + mObbState.ownerPath);
+            }
+            return obbInfo;
+        }
+
+        protected void sendNewStatusOrIgnore(int status) {
+            if (mObbState == null || mObbState.token == null) {
+                return;
+            }
+
+            try {
+                mObbState.token.onObbResult(mObbState.rawPath, mObbState.nonce, status);
+            } catch (RemoteException e) {
+                Slog.w(TAG, "MountServiceListener went away while calling onObbStateChanged");
+            }
+        }
+    }
+
+    class MountObbAction extends ObbAction {
+        private final String mKey;
+        private final int mCallingUid;
+
+        MountObbAction(ObbState obbState, String key, int callingUid) {
+            super(obbState);
+            mKey = key;
+            mCallingUid = callingUid;
+        }
+
+        @Override
+        public void handleExecute() throws IOException, RemoteException {
+            waitForReady();
+            warnOnNotMounted();
+
+            final ObbInfo obbInfo = getObbInfo();
+
+            if (!isUidOwnerOfPackageOrSystem(obbInfo.packageName, mCallingUid)) {
+                Slog.w(TAG, "Denied attempt to mount OBB " + obbInfo.filename
+                        + " which is owned by " + obbInfo.packageName);
+                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
+                return;
+            }
+
+            final boolean isMounted;
+            synchronized (mObbMounts) {
+                isMounted = mObbPathToStateMap.containsKey(mObbState.rawPath);
+            }
+            if (isMounted) {
+                Slog.w(TAG, "Attempt to mount OBB which is already mounted: " + obbInfo.filename);
+                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_ALREADY_MOUNTED);
+                return;
+            }
+
+            final String hashedKey;
+            if (mKey == null) {
+                hashedKey = "none";
+            } else {
+                try {
+                    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
+
+                    KeySpec ks = new PBEKeySpec(mKey.toCharArray(), obbInfo.salt,
+                            PBKDF2_HASH_ROUNDS, CRYPTO_ALGORITHM_KEY_SIZE);
+                    SecretKey key = factory.generateSecret(ks);
+                    BigInteger bi = new BigInteger(key.getEncoded());
+                    hashedKey = bi.toString(16);
+                } catch (NoSuchAlgorithmException e) {
+                    Slog.e(TAG, "Could not load PBKDF2 algorithm", e);
+                    sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
+                    return;
+                } catch (InvalidKeySpecException e) {
+                    Slog.e(TAG, "Invalid key spec when loading PBKDF2 algorithm", e);
+                    sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
+                    return;
+                }
+            }
+
+            int rc = StorageResultCode.OperationSucceeded;
+            try {
+                mConnector.execute("obb", "mount", mObbState.voldPath, new SensitiveArg(hashedKey),
+                        mObbState.ownerGid);
+            } catch (NativeDaemonConnectorException e) {
+                int code = e.getCode();
+                if (code != VoldResponseCode.OpFailedStorageBusy) {
+                    rc = StorageResultCode.OperationFailedInternalError;
+                }
+            }
+
+            if (rc == StorageResultCode.OperationSucceeded) {
+                if (DEBUG_OBB)
+                    Slog.d(TAG, "Successfully mounted OBB " + mObbState.voldPath);
+
+                synchronized (mObbMounts) {
+                    addObbStateLocked(mObbState);
+                }
+
+                sendNewStatusOrIgnore(OnObbStateChangeListener.MOUNTED);
+            } else {
+                Slog.e(TAG, "Couldn't mount OBB file: " + rc);
+
+                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT);
+            }
+        }
+
+        @Override
+        public void handleError() {
+            sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            sb.append("MountObbAction{");
+            sb.append(mObbState);
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+    class UnmountObbAction extends ObbAction {
+        private final boolean mForceUnmount;
+
+        UnmountObbAction(ObbState obbState, boolean force) {
+            super(obbState);
+            mForceUnmount = force;
+        }
+
+        @Override
+        public void handleExecute() throws IOException {
+            waitForReady();
+            warnOnNotMounted();
+
+            final ObbInfo obbInfo = getObbInfo();
+
+            final ObbState existingState;
+            synchronized (mObbMounts) {
+                existingState = mObbPathToStateMap.get(mObbState.rawPath);
+            }
+
+            if (existingState == null) {
+                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_NOT_MOUNTED);
+                return;
+            }
+
+            if (existingState.ownerGid != mObbState.ownerGid) {
+                Slog.w(TAG, "Permission denied attempting to unmount OBB " + existingState.rawPath
+                        + " (owned by GID " + existingState.ownerGid + ")");
+                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
+                return;
+            }
+
+            int rc = StorageResultCode.OperationSucceeded;
+            try {
+                final Command cmd = new Command("obb", "unmount", mObbState.voldPath);
+                if (mForceUnmount) {
+                    cmd.appendArg("force");
+                }
+                mConnector.execute(cmd);
+            } catch (NativeDaemonConnectorException e) {
+                int code = e.getCode();
+                if (code == VoldResponseCode.OpFailedStorageBusy) {
+                    rc = StorageResultCode.OperationFailedStorageBusy;
+                } else if (code == VoldResponseCode.OpFailedStorageNotFound) {
+                    // If it's not mounted then we've already won.
+                    rc = StorageResultCode.OperationSucceeded;
+                } else {
+                    rc = StorageResultCode.OperationFailedInternalError;
+                }
+            }
+
+            if (rc == StorageResultCode.OperationSucceeded) {
+                synchronized (mObbMounts) {
+                    removeObbStateLocked(existingState);
+                }
+
+                sendNewStatusOrIgnore(OnObbStateChangeListener.UNMOUNTED);
+            } else {
+                Slog.w(TAG, "Could not unmount OBB: " + existingState);
+                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_COULD_NOT_UNMOUNT);
+            }
+        }
+
+        @Override
+        public void handleError() {
+            sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            sb.append("UnmountObbAction{");
+            sb.append(mObbState);
+            sb.append(",force=");
+            sb.append(mForceUnmount);
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+    @VisibleForTesting
+    public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) {
+        // TODO: allow caller to provide Environment for full testing
+        // TODO: extend to support OBB mounts on secondary external storage
+
+        // Only adjust paths when storage is emulated
+        if (!Environment.isExternalStorageEmulated()) {
+            return canonicalPath;
+        }
+
+        String path = canonicalPath.toString();
+
+        // First trim off any external storage prefix
+        final UserEnvironment userEnv = new UserEnvironment(userId);
+
+        // /storage/emulated/0
+        final String externalPath = userEnv.getExternalStorageDirectory().getAbsolutePath();
+        // /storage/emulated_legacy
+        final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory()
+                .getAbsolutePath();
+
+        if (path.startsWith(externalPath)) {
+            path = path.substring(externalPath.length() + 1);
+        } else if (path.startsWith(legacyExternalPath)) {
+            path = path.substring(legacyExternalPath.length() + 1);
+        } else {
+            return canonicalPath;
+        }
+
+        // Handle special OBB paths on emulated storage
+        final String obbPath = "Android/obb";
+        if (path.startsWith(obbPath)) {
+            path = path.substring(obbPath.length() + 1);
+
+            if (forVold) {
+                return new File(Environment.getEmulatedStorageObbSource(), path).getAbsolutePath();
+            } else {
+                final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER);
+                return new File(ownerEnv.buildExternalStorageAndroidObbDirs()[0], path)
+                        .getAbsolutePath();
+            }
+        }
+
+        // Handle normal external storage paths
+        if (forVold) {
+            return new File(Environment.getEmulatedStorageSource(userId), path).getAbsolutePath();
+        } else {
+            return new File(userEnv.getExternalDirsForApp()[0], path).getAbsolutePath();
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
+
+        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ", 160);
+
+        synchronized (mObbMounts) {
+            pw.println("mObbMounts:");
+            pw.increaseIndent();
+            final Iterator<Entry<IBinder, List<ObbState>>> binders = mObbMounts.entrySet()
+                    .iterator();
+            while (binders.hasNext()) {
+                Entry<IBinder, List<ObbState>> e = binders.next();
+                pw.println(e.getKey() + ":");
+                pw.increaseIndent();
+                final List<ObbState> obbStates = e.getValue();
+                for (final ObbState obbState : obbStates) {
+                    pw.println(obbState);
+                }
+                pw.decreaseIndent();
+            }
+            pw.decreaseIndent();
+
+            pw.println();
+            pw.println("mObbPathToStateMap:");
+            pw.increaseIndent();
+            final Iterator<Entry<String, ObbState>> maps = mObbPathToStateMap.entrySet().iterator();
+            while (maps.hasNext()) {
+                final Entry<String, ObbState> e = maps.next();
+                pw.print(e.getKey());
+                pw.print(" -> ");
+                pw.println(e.getValue());
+            }
+            pw.decreaseIndent();
+        }
+
+        synchronized (mVolumesLock) {
+            pw.println();
+            pw.println("mVolumes:");
+            pw.increaseIndent();
+            for (StorageVolume volume : mVolumes) {
+                pw.println(volume);
+                pw.increaseIndent();
+                pw.println("Current state: " + mVolumeStates.get(volume.getPath()));
+                pw.decreaseIndent();
+            }
+            pw.decreaseIndent();
+        }
+
+        pw.println();
+        pw.println("mConnection:");
+        pw.increaseIndent();
+        mConnector.dump(fd, pw, args);
+        pw.decreaseIndent();
+    }
+
+    /** {@inheritDoc} */
+    public void monitor() {
+        if (mConnector != null) {
+            mConnector.monitor();
+        }
+    }
+}
diff --git a/services/java/com/android/server/NativeDaemonConnector.java b/services/core/java/com/android/server/NativeDaemonConnector.java
similarity index 100%
rename from services/java/com/android/server/NativeDaemonConnector.java
rename to services/core/java/com/android/server/NativeDaemonConnector.java
diff --git a/services/java/com/android/server/NativeDaemonConnectorException.java b/services/core/java/com/android/server/NativeDaemonConnectorException.java
similarity index 100%
rename from services/java/com/android/server/NativeDaemonConnectorException.java
rename to services/core/java/com/android/server/NativeDaemonConnectorException.java
diff --git a/services/java/com/android/server/NativeDaemonEvent.java b/services/core/java/com/android/server/NativeDaemonEvent.java
similarity index 100%
rename from services/java/com/android/server/NativeDaemonEvent.java
rename to services/core/java/com/android/server/NativeDaemonEvent.java
diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
new file mode 100644
index 0000000..ad7ec99
--- /dev/null
+++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -0,0 +1,1810 @@
+/*
+ * Copyright (C) 2007 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;
+
+import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
+import static android.Manifest.permission.DUMP;
+import static android.Manifest.permission.SHUTDOWN;
+import static android.net.NetworkStats.SET_DEFAULT;
+import static android.net.NetworkStats.TAG_NONE;
+import static android.net.NetworkStats.UID_ALL;
+import static android.net.TrafficStats.UID_TETHERING;
+import static com.android.server.NetworkManagementService.NetdResponseCode.ClatdStatusResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.GetMarkResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceGetCfgResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceListResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.IpFwdStatusResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.TetherDnsFwdTgtListResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.TetherInterfaceListResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.TetherStatusResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsListResult;
+import static com.android.server.NetworkManagementService.NetdResponseCode.TtyListResult;
+import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED;
+
+import android.content.Context;
+import android.net.INetworkManagementEventObserver;
+import android.net.InterfaceConfiguration;
+import android.net.LinkAddress;
+import android.net.NetworkStats;
+import android.net.NetworkUtils;
+import android.net.RouteInfo;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiConfiguration.KeyMgmt;
+import android.os.BatteryStats;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.INetworkManagementService;
+import android.os.Process;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseBooleanArray;
+
+import com.android.internal.app.IBatteryStats;
+import com.android.internal.net.NetworkStatsFactory;
+import com.android.internal.util.Preconditions;
+import com.android.server.NativeDaemonConnector.Command;
+import com.android.server.NativeDaemonConnector.SensitiveArg;
+import com.android.server.net.LockdownVpnTracker;
+import com.google.android.collect.Maps;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.InterfaceAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.StringTokenizer;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @hide
+ */
+public class NetworkManagementService extends INetworkManagementService.Stub
+        implements Watchdog.Monitor {
+    private static final String TAG = "NetworkManagementService";
+    private static final boolean DBG = false;
+    private static final String NETD_TAG = "NetdConnector";
+    private static final String NETD_SOCKET_NAME = "netd";
+
+    private static final String ADD = "add";
+    private static final String REMOVE = "remove";
+
+    private static final String ALLOW = "allow";
+    private static final String DENY = "deny";
+
+    private static final String DEFAULT = "default";
+    private static final String SECONDARY = "secondary";
+
+    /**
+     * Name representing {@link #setGlobalAlert(long)} limit when delivered to
+     * {@link INetworkManagementEventObserver#limitReached(String, String)}.
+     */
+    public static final String LIMIT_GLOBAL_ALERT = "globalAlert";
+
+    class NetdResponseCode {
+        /* Keep in sync with system/netd/ResponseCode.h */
+        public static final int InterfaceListResult       = 110;
+        public static final int TetherInterfaceListResult = 111;
+        public static final int TetherDnsFwdTgtListResult = 112;
+        public static final int TtyListResult             = 113;
+        public static final int TetheringStatsListResult  = 114;
+
+        public static final int TetherStatusResult        = 210;
+        public static final int IpFwdStatusResult         = 211;
+        public static final int InterfaceGetCfgResult     = 213;
+        public static final int SoftapStatusResult        = 214;
+        public static final int InterfaceRxCounterResult  = 216;
+        public static final int InterfaceTxCounterResult  = 217;
+        public static final int QuotaCounterResult        = 220;
+        public static final int TetheringStatsResult      = 221;
+        public static final int DnsProxyQueryResult       = 222;
+        public static final int ClatdStatusResult         = 223;
+        public static final int GetMarkResult             = 225;
+
+        public static final int InterfaceChange           = 600;
+        public static final int BandwidthControl          = 601;
+        public static final int InterfaceClassActivity    = 613;
+        public static final int InterfaceAddressChange    = 614;
+        public static final int InterfaceDnsServerInfo    = 615;
+    }
+
+    /**
+     * Binder context for this service
+     */
+    private Context mContext;
+
+    /**
+     * connector object for communicating with netd
+     */
+    private NativeDaemonConnector mConnector;
+
+    private final Handler mMainHandler = new Handler();
+
+    private Thread mThread;
+    private CountDownLatch mConnectedSignal = new CountDownLatch(1);
+
+    private final RemoteCallbackList<INetworkManagementEventObserver> mObservers =
+            new RemoteCallbackList<INetworkManagementEventObserver>();
+
+    private final NetworkStatsFactory mStatsFactory = new NetworkStatsFactory();
+
+    private Object mQuotaLock = new Object();
+    /** Set of interfaces with active quotas. */
+    private HashMap<String, Long> mActiveQuotas = Maps.newHashMap();
+    /** Set of interfaces with active alerts. */
+    private HashMap<String, Long> mActiveAlerts = Maps.newHashMap();
+    /** Set of UIDs with active reject rules. */
+    private SparseBooleanArray mUidRejectOnQuota = new SparseBooleanArray();
+
+    private Object mIdleTimerLock = new Object();
+    /** Set of interfaces with active idle timers. */
+    private static class IdleTimerParams {
+        public final int timeout;
+        public final String label;
+        public int networkCount;
+
+        IdleTimerParams(int timeout, String label) {
+            this.timeout = timeout;
+            this.label = label;
+            this.networkCount = 1;
+        }
+    }
+    private HashMap<String, IdleTimerParams> mActiveIdleTimers = Maps.newHashMap();
+
+    private volatile boolean mBandwidthControlEnabled;
+    private volatile boolean mFirewallEnabled;
+
+    /**
+     * Constructs a new NetworkManagementService instance
+     *
+     * @param context  Binder context for this service
+     */
+    private NetworkManagementService(Context context, String socket) {
+        mContext = context;
+
+        if ("simulator".equals(SystemProperties.get("ro.product.device"))) {
+            return;
+        }
+
+        mConnector = new NativeDaemonConnector(
+                new NetdCallbackReceiver(), socket, 10, NETD_TAG, 160);
+        mThread = new Thread(mConnector, NETD_TAG);
+
+        // Add ourself to the Watchdog monitors.
+        Watchdog.getInstance().addMonitor(this);
+    }
+
+    static NetworkManagementService create(Context context,
+            String socket) throws InterruptedException {
+        final NetworkManagementService service = new NetworkManagementService(context, socket);
+        final CountDownLatch connectedSignal = service.mConnectedSignal;
+        if (DBG) Slog.d(TAG, "Creating NetworkManagementService");
+        service.mThread.start();
+        if (DBG) Slog.d(TAG, "Awaiting socket connection");
+        connectedSignal.await();
+        if (DBG) Slog.d(TAG, "Connected");
+        return service;
+    }
+
+    public static NetworkManagementService create(Context context) throws InterruptedException {
+        return create(context, NETD_SOCKET_NAME);
+    }
+
+    public void systemReady() {
+        prepareNativeDaemon();
+        if (DBG) Slog.d(TAG, "Prepared");
+    }
+
+    @Override
+    public void registerObserver(INetworkManagementEventObserver observer) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        mObservers.register(observer);
+    }
+
+    @Override
+    public void unregisterObserver(INetworkManagementEventObserver observer) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        mObservers.unregister(observer);
+    }
+
+    /**
+     * Notify our observers of an interface status change
+     */
+    private void notifyInterfaceStatusChanged(String iface, boolean up) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).interfaceStatusChanged(iface, up);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of an interface link state change
+     * (typically, an Ethernet cable has been plugged-in or unplugged).
+     */
+    private void notifyInterfaceLinkStateChanged(String iface, boolean up) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).interfaceLinkStateChanged(iface, up);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of an interface addition.
+     */
+    private void notifyInterfaceAdded(String iface) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).interfaceAdded(iface);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of an interface removal.
+     */
+    private void notifyInterfaceRemoved(String iface) {
+        // netd already clears out quota and alerts for removed ifaces; update
+        // our sanity-checking state.
+        mActiveAlerts.remove(iface);
+        mActiveQuotas.remove(iface);
+
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).interfaceRemoved(iface);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of a limit reached.
+     */
+    private void notifyLimitReached(String limitName, String iface) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).limitReached(limitName, iface);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of a change in the data activity state of the interface
+     */
+    private void notifyInterfaceClassActivity(String label, boolean active) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).interfaceClassDataActivityChanged(label, active);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Prepare native daemon once connected, enabling modules and pushing any
+     * existing in-memory rules.
+     */
+    private void prepareNativeDaemon() {
+        mBandwidthControlEnabled = false;
+
+        // only enable bandwidth control when support exists
+        final boolean hasKernelSupport = new File("/proc/net/xt_qtaguid/ctrl").exists();
+        if (hasKernelSupport) {
+            Slog.d(TAG, "enabling bandwidth control");
+            try {
+                mConnector.execute("bandwidth", "enable");
+                mBandwidthControlEnabled = true;
+            } catch (NativeDaemonConnectorException e) {
+                Log.wtf(TAG, "problem enabling bandwidth controls", e);
+            }
+        } else {
+            Slog.d(TAG, "not enabling bandwidth control");
+        }
+
+        SystemProperties.set(PROP_QTAGUID_ENABLED, mBandwidthControlEnabled ? "1" : "0");
+
+        if (mBandwidthControlEnabled) {
+            try {
+                IBatteryStats.Stub.asInterface(ServiceManager.getService(BatteryStats.SERVICE_NAME))
+                        .noteNetworkStatsEnabled();
+            } catch (RemoteException e) {
+            }
+        }
+
+        // push any existing quota or UID rules
+        synchronized (mQuotaLock) {
+            int size = mActiveQuotas.size();
+            if (size > 0) {
+                Slog.d(TAG, "pushing " + size + " active quota rules");
+                final HashMap<String, Long> activeQuotas = mActiveQuotas;
+                mActiveQuotas = Maps.newHashMap();
+                for (Map.Entry<String, Long> entry : activeQuotas.entrySet()) {
+                    setInterfaceQuota(entry.getKey(), entry.getValue());
+                }
+            }
+
+            size = mActiveAlerts.size();
+            if (size > 0) {
+                Slog.d(TAG, "pushing " + size + " active alert rules");
+                final HashMap<String, Long> activeAlerts = mActiveAlerts;
+                mActiveAlerts = Maps.newHashMap();
+                for (Map.Entry<String, Long> entry : activeAlerts.entrySet()) {
+                    setInterfaceAlert(entry.getKey(), entry.getValue());
+                }
+            }
+
+            size = mUidRejectOnQuota.size();
+            if (size > 0) {
+                Slog.d(TAG, "pushing " + size + " active uid rules");
+                final SparseBooleanArray uidRejectOnQuota = mUidRejectOnQuota;
+                mUidRejectOnQuota = new SparseBooleanArray();
+                for (int i = 0; i < uidRejectOnQuota.size(); i++) {
+                    setUidNetworkRules(uidRejectOnQuota.keyAt(i), uidRejectOnQuota.valueAt(i));
+                }
+            }
+        }
+
+        // TODO: Push any existing firewall state
+        setFirewallEnabled(mFirewallEnabled || LockdownVpnTracker.isEnabled());
+    }
+
+    /**
+     * Notify our observers of a new or updated interface address.
+     */
+    private void notifyAddressUpdated(String iface, LinkAddress address) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).addressUpdated(iface, address);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of a deleted interface address.
+     */
+    private void notifyAddressRemoved(String iface, LinkAddress address) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).addressRemoved(iface, address);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    /**
+     * Notify our observers of DNS server information received.
+     */
+    private void notifyInterfaceDnsServerInfo(String iface, long lifetime, String[] addresses) {
+        final int length = mObservers.beginBroadcast();
+        for (int i = 0; i < length; i++) {
+            try {
+                mObservers.getBroadcastItem(i).interfaceDnsServerInfo(iface, lifetime, addresses);
+            } catch (RemoteException e) {
+            } catch (RuntimeException e) {
+            }
+        }
+        mObservers.finishBroadcast();
+    }
+
+    //
+    // Netd Callback handling
+    //
+
+    private class NetdCallbackReceiver implements INativeDaemonConnectorCallbacks {
+        @Override
+        public void onDaemonConnected() {
+            // event is dispatched from internal NDC thread, so we prepare the
+            // daemon back on main thread.
+            if (mConnectedSignal != null) {
+                mConnectedSignal.countDown();
+                mConnectedSignal = null;
+            } else {
+                mMainHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        prepareNativeDaemon();
+                    }
+                });
+            }
+        }
+
+        @Override
+        public boolean onEvent(int code, String raw, String[] cooked) {
+            String errorMessage = String.format("Invalid event from daemon (%s)", raw);
+            switch (code) {
+            case NetdResponseCode.InterfaceChange:
+                    /*
+                     * a network interface change occured
+                     * Format: "NNN Iface added <name>"
+                     *         "NNN Iface removed <name>"
+                     *         "NNN Iface changed <name> <up/down>"
+                     *         "NNN Iface linkstatus <name> <up/down>"
+                     */
+                    if (cooked.length < 4 || !cooked[1].equals("Iface")) {
+                        throw new IllegalStateException(errorMessage);
+                    }
+                    if (cooked[2].equals("added")) {
+                        notifyInterfaceAdded(cooked[3]);
+                        return true;
+                    } else if (cooked[2].equals("removed")) {
+                        notifyInterfaceRemoved(cooked[3]);
+                        return true;
+                    } else if (cooked[2].equals("changed") && cooked.length == 5) {
+                        notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
+                        return true;
+                    } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
+                        notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
+                        return true;
+                    }
+                    throw new IllegalStateException(errorMessage);
+                    // break;
+            case NetdResponseCode.BandwidthControl:
+                    /*
+                     * Bandwidth control needs some attention
+                     * Format: "NNN limit alert <alertName> <ifaceName>"
+                     */
+                    if (cooked.length < 5 || !cooked[1].equals("limit")) {
+                        throw new IllegalStateException(errorMessage);
+                    }
+                    if (cooked[2].equals("alert")) {
+                        notifyLimitReached(cooked[3], cooked[4]);
+                        return true;
+                    }
+                    throw new IllegalStateException(errorMessage);
+                    // break;
+            case NetdResponseCode.InterfaceClassActivity:
+                    /*
+                     * An network interface class state changed (active/idle)
+                     * Format: "NNN IfaceClass <active/idle> <label>"
+                     */
+                    if (cooked.length < 4 || !cooked[1].equals("IfaceClass")) {
+                        throw new IllegalStateException(errorMessage);
+                    }
+                    boolean isActive = cooked[2].equals("active");
+                    notifyInterfaceClassActivity(cooked[3], isActive);
+                    return true;
+                    // break;
+            case NetdResponseCode.InterfaceAddressChange:
+                    /*
+                     * A network address change occurred
+                     * Format: "NNN Address updated <addr> <iface> <flags> <scope>"
+                     *         "NNN Address removed <addr> <iface> <flags> <scope>"
+                     */
+                    if (cooked.length < 7 || !cooked[1].equals("Address")) {
+                        throw new IllegalStateException(errorMessage);
+                    }
+
+                    String iface = cooked[4];
+                    LinkAddress address;
+                    try {
+                        int flags = Integer.parseInt(cooked[5]);
+                        int scope = Integer.parseInt(cooked[6]);
+                        address = new LinkAddress(cooked[3], flags, scope);
+                    } catch(NumberFormatException e) {     // Non-numeric lifetime or scope.
+                        throw new IllegalStateException(errorMessage, e);
+                    } catch(IllegalArgumentException e) {  // Malformed/invalid IP address.
+                        throw new IllegalStateException(errorMessage, e);
+                    }
+
+                    if (cooked[2].equals("updated")) {
+                        notifyAddressUpdated(iface, address);
+                    } else {
+                        notifyAddressRemoved(iface, address);
+                    }
+                    return true;
+                    // break;
+            case NetdResponseCode.InterfaceDnsServerInfo:
+                    /*
+                     * Information about available DNS servers has been received.
+                     * Format: "NNN DnsInfo servers <interface> <lifetime> <servers>"
+                     */
+                    long lifetime;  // Actually a 32-bit unsigned integer.
+
+                    if (cooked.length == 6 &&
+                        cooked[1].equals("DnsInfo") &&
+                        cooked[2].equals("servers")) {
+                        try {
+                            lifetime = Long.parseLong(cooked[4]);
+                        } catch (NumberFormatException e) {
+                            throw new IllegalStateException(errorMessage);
+                        }
+                        String[] servers = cooked[5].split(",");
+                        notifyInterfaceDnsServerInfo(cooked[3], lifetime, servers);
+                    }
+                    return true;
+                    // break;
+            default: break;
+            }
+            return false;
+        }
+    }
+
+
+    //
+    // INetworkManagementService members
+    //
+
+    @Override
+    public String[] listInterfaces() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return NativeDaemonEvent.filterMessageList(
+                    mConnector.executeForList("interface", "list"), InterfaceListResult);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public InterfaceConfiguration getInterfaceConfig(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("interface", "getcfg", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+
+        event.checkCode(InterfaceGetCfgResult);
+
+        // Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
+        final StringTokenizer st = new StringTokenizer(event.getMessage());
+
+        InterfaceConfiguration cfg;
+        try {
+            cfg = new InterfaceConfiguration();
+            cfg.setHardwareAddress(st.nextToken(" "));
+            InetAddress addr = null;
+            int prefixLength = 0;
+            try {
+                addr = NetworkUtils.numericToInetAddress(st.nextToken());
+            } catch (IllegalArgumentException iae) {
+                Slog.e(TAG, "Failed to parse ipaddr", iae);
+            }
+
+            try {
+                prefixLength = Integer.parseInt(st.nextToken());
+            } catch (NumberFormatException nfe) {
+                Slog.e(TAG, "Failed to parse prefixLength", nfe);
+            }
+
+            cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
+            while (st.hasMoreTokens()) {
+                cfg.setFlag(st.nextToken());
+            }
+        } catch (NoSuchElementException nsee) {
+            throw new IllegalStateException("Invalid response from daemon: " + event);
+        }
+        return cfg;
+    }
+
+    @Override
+    public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        LinkAddress linkAddr = cfg.getLinkAddress();
+        if (linkAddr == null || linkAddr.getAddress() == null) {
+            throw new IllegalStateException("Null LinkAddress given");
+        }
+
+        final Command cmd = new Command("interface", "setcfg", iface,
+                linkAddr.getAddress().getHostAddress(),
+                linkAddr.getNetworkPrefixLength());
+        for (String flag : cfg.getFlags()) {
+            cmd.appendArg(flag);
+        }
+
+        try {
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setInterfaceDown(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
+        ifcg.setInterfaceDown();
+        setInterfaceConfig(iface, ifcg);
+    }
+
+    @Override
+    public void setInterfaceUp(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
+        ifcg.setInterfaceUp();
+        setInterfaceConfig(iface, ifcg);
+    }
+
+    @Override
+    public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute(
+                    "interface", "ipv6privacyextensions", iface, enable ? "enable" : "disable");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
+       IPv6 addresses on interface down, but we need to do full clean up here */
+    @Override
+    public void clearInterfaceAddresses(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "clearaddrs", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void enableIpv6(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "ipv6", iface, "enable");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void disableIpv6(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "ipv6", iface, "disable");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void addRoute(String interfaceName, RouteInfo route) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        modifyRoute(interfaceName, ADD, route, DEFAULT);
+    }
+
+    @Override
+    public void removeRoute(String interfaceName, RouteInfo route) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        modifyRoute(interfaceName, REMOVE, route, DEFAULT);
+    }
+
+    @Override
+    public void addSecondaryRoute(String interfaceName, RouteInfo route) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        modifyRoute(interfaceName, ADD, route, SECONDARY);
+    }
+
+    @Override
+    public void removeSecondaryRoute(String interfaceName, RouteInfo route) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        modifyRoute(interfaceName, REMOVE, route, SECONDARY);
+    }
+
+    private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
+        final Command cmd = new Command("interface", "route", action, interfaceName, type);
+
+        // create triplet: dest-ip-addr prefixlength gateway-ip-addr
+        final LinkAddress la = route.getDestination();
+        cmd.appendArg(la.getAddress().getHostAddress());
+        cmd.appendArg(la.getNetworkPrefixLength());
+
+        if (route.getGateway() == null) {
+            if (la.getAddress() instanceof Inet4Address) {
+                cmd.appendArg("0.0.0.0");
+            } else {
+                cmd.appendArg("::0");
+            }
+        } else {
+            cmd.appendArg(route.getGateway().getHostAddress());
+        }
+
+        try {
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    private ArrayList<String> readRouteList(String filename) {
+        FileInputStream fstream = null;
+        ArrayList<String> list = new ArrayList<String>();
+
+        try {
+            fstream = new FileInputStream(filename);
+            DataInputStream in = new DataInputStream(fstream);
+            BufferedReader br = new BufferedReader(new InputStreamReader(in));
+            String s;
+
+            // throw away the title line
+
+            while (((s = br.readLine()) != null) && (s.length() != 0)) {
+                list.add(s);
+            }
+        } catch (IOException ex) {
+            // return current list, possibly empty
+        } finally {
+            if (fstream != null) {
+                try {
+                    fstream.close();
+                } catch (IOException ex) {}
+            }
+        }
+
+        return list;
+    }
+
+    @Override
+    public RouteInfo[] getRoutes(String interfaceName) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        ArrayList<RouteInfo> routes = new ArrayList<RouteInfo>();
+
+        // v4 routes listed as:
+        // iface dest-addr gateway-addr flags refcnt use metric netmask mtu window IRTT
+        for (String s : readRouteList("/proc/net/route")) {
+            String[] fields = s.split("\t");
+
+            if (fields.length > 7) {
+                String iface = fields[0];
+
+                if (interfaceName.equals(iface)) {
+                    String dest = fields[1];
+                    String gate = fields[2];
+                    String flags = fields[3]; // future use?
+                    String mask = fields[7];
+                    try {
+                        // address stored as a hex string, ex: 0014A8C0
+                        InetAddress destAddr =
+                                NetworkUtils.intToInetAddress((int)Long.parseLong(dest, 16));
+                        int prefixLength =
+                                NetworkUtils.netmaskIntToPrefixLength(
+                                (int)Long.parseLong(mask, 16));
+                        LinkAddress linkAddress = new LinkAddress(destAddr, prefixLength);
+
+                        // address stored as a hex string, ex 0014A8C0
+                        InetAddress gatewayAddr =
+                                NetworkUtils.intToInetAddress((int)Long.parseLong(gate, 16));
+
+                        RouteInfo route = new RouteInfo(linkAddress, gatewayAddr);
+                        routes.add(route);
+                    } catch (Exception e) {
+                        Log.e(TAG, "Error parsing route " + s + " : " + e);
+                        continue;
+                    }
+                }
+            }
+        }
+
+        // v6 routes listed as:
+        // dest-addr prefixlength ?? ?? gateway-addr ?? ?? ?? ?? iface
+        for (String s : readRouteList("/proc/net/ipv6_route")) {
+            String[]fields = s.split("\\s+");
+            if (fields.length > 9) {
+                String iface = fields[9].trim();
+                if (interfaceName.equals(iface)) {
+                    String dest = fields[0];
+                    String prefix = fields[1];
+                    String gate = fields[4];
+
+                    try {
+                        // prefix length stored as a hex string, ex 40
+                        int prefixLength = Integer.parseInt(prefix, 16);
+
+                        // address stored as a 32 char hex string
+                        // ex fe800000000000000000000000000000
+                        InetAddress destAddr = NetworkUtils.hexToInet6Address(dest);
+                        LinkAddress linkAddress = new LinkAddress(destAddr, prefixLength);
+
+                        InetAddress gateAddr = NetworkUtils.hexToInet6Address(gate);
+
+                        RouteInfo route = new RouteInfo(linkAddress, gateAddr);
+                        routes.add(route);
+                    } catch (Exception e) {
+                        Log.e(TAG, "Error parsing route " + s + " : " + e);
+                        continue;
+                    }
+                }
+            }
+        }
+        return routes.toArray(new RouteInfo[routes.size()]);
+    }
+
+    @Override
+    public void setMtu(String iface, int mtu) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("interface", "setmtu", iface, mtu);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void shutdown() {
+        // TODO: remove from aidl if nobody calls externally
+        mContext.enforceCallingOrSelfPermission(SHUTDOWN, TAG);
+
+        Slog.d(TAG, "Shutting down");
+    }
+
+    @Override
+    public boolean getIpForwardingEnabled() throws IllegalStateException{
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("ipfwd", "status");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+
+        // 211 Forwarding enabled
+        event.checkCode(IpFwdStatusResult);
+        return event.getMessage().endsWith("enabled");
+    }
+
+    @Override
+    public void setIpForwardingEnabled(boolean enable) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("ipfwd", enable ? "enable" : "disable");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void startTethering(String[] dhcpRange) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        // cmd is "tether start first_start first_stop second_start second_stop ..."
+        // an odd number of addrs will fail
+
+        final Command cmd = new Command("tether", "start");
+        for (String d : dhcpRange) {
+            cmd.appendArg(d);
+        }
+
+        try {
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void stopTethering() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("tether", "stop");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public boolean isTetheringStarted() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("tether", "status");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+
+        // 210 Tethering services started
+        event.checkCode(TetherStatusResult);
+        return event.getMessage().endsWith("started");
+    }
+
+    @Override
+    public void tetherInterface(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("tether", "interface", "add", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void untetherInterface(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("tether", "interface", "remove", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public String[] listTetheredInterfaces() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return NativeDaemonEvent.filterMessageList(
+                    mConnector.executeForList("tether", "interface", "list"),
+                    TetherInterfaceListResult);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setDnsForwarders(String[] dns) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final Command cmd = new Command("tether", "dns", "set");
+        for (String s : dns) {
+            cmd.appendArg(NetworkUtils.numericToInetAddress(s).getHostAddress());
+        }
+
+        try {
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public String[] getDnsForwarders() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return NativeDaemonEvent.filterMessageList(
+                    mConnector.executeForList("tether", "dns", "list"), TetherDnsFwdTgtListResult);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    private void modifyNat(String action, String internalInterface, String externalInterface)
+            throws SocketException {
+        final Command cmd = new Command("nat", action, internalInterface, externalInterface);
+
+        final NetworkInterface internalNetworkInterface = NetworkInterface.getByName(
+                internalInterface);
+        if (internalNetworkInterface == null) {
+            cmd.appendArg("0");
+        } else {
+            Collection<InterfaceAddress> interfaceAddresses = internalNetworkInterface
+                    .getInterfaceAddresses();
+            cmd.appendArg(interfaceAddresses.size());
+            for (InterfaceAddress ia : interfaceAddresses) {
+                InetAddress addr = NetworkUtils.getNetworkPart(
+                        ia.getAddress(), ia.getNetworkPrefixLength());
+                cmd.appendArg(addr.getHostAddress() + "/" + ia.getNetworkPrefixLength());
+            }
+        }
+
+        try {
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void enableNat(String internalInterface, String externalInterface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            modifyNat("enable", internalInterface, externalInterface);
+        } catch (SocketException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public void disableNat(String internalInterface, String externalInterface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            modifyNat("disable", internalInterface, externalInterface);
+        } catch (SocketException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public String[] listTtys() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return NativeDaemonEvent.filterMessageList(
+                    mConnector.executeForList("list_ttys"), TtyListResult);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void attachPppd(
+            String tty, String localAddr, String remoteAddr, String dns1Addr, String dns2Addr) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("pppd", "attach", tty,
+                    NetworkUtils.numericToInetAddress(localAddr).getHostAddress(),
+                    NetworkUtils.numericToInetAddress(remoteAddr).getHostAddress(),
+                    NetworkUtils.numericToInetAddress(dns1Addr).getHostAddress(),
+                    NetworkUtils.numericToInetAddress(dns2Addr).getHostAddress());
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void detachPppd(String tty) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("pppd", "detach", tty);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void startAccessPoint(
+            WifiConfiguration wifiConfig, String wlanIface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            wifiFirmwareReload(wlanIface, "AP");
+            if (wifiConfig == null) {
+                mConnector.execute("softap", "set", wlanIface);
+            } else {
+                mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
+                                   "broadcast", "6", getSecurityType(wifiConfig),
+                                   new SensitiveArg(wifiConfig.preSharedKey));
+            }
+            mConnector.execute("softap", "startap");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    private static String getSecurityType(WifiConfiguration wifiConfig) {
+        switch (wifiConfig.getAuthType()) {
+            case KeyMgmt.WPA_PSK:
+                return "wpa-psk";
+            case KeyMgmt.WPA2_PSK:
+                return "wpa2-psk";
+            default:
+                return "open";
+        }
+    }
+
+    /* @param mode can be "AP", "STA" or "P2P" */
+    @Override
+    public void wifiFirmwareReload(String wlanIface, String mode) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("softap", "fwreload", wlanIface, mode);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void stopAccessPoint(String wlanIface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("softap", "stopap");
+            wifiFirmwareReload(wlanIface, "STA");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setAccessPoint(WifiConfiguration wifiConfig, String wlanIface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            if (wifiConfig == null) {
+                mConnector.execute("softap", "set", wlanIface);
+            } else {
+                mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
+                                   "broadcast", "6", getSecurityType(wifiConfig),
+                                   new SensitiveArg(wifiConfig.preSharedKey));
+            }
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void addIdleTimer(String iface, int timeout, String label) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        if (DBG) Slog.d(TAG, "Adding idletimer");
+
+        synchronized (mIdleTimerLock) {
+            IdleTimerParams params = mActiveIdleTimers.get(iface);
+            if (params != null) {
+                // the interface already has idletimer, update network count
+                params.networkCount++;
+                return;
+            }
+
+            try {
+                mConnector.execute("idletimer", "add", iface, Integer.toString(timeout), label);
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+            mActiveIdleTimers.put(iface, new IdleTimerParams(timeout, label));
+        }
+    }
+
+    @Override
+    public void removeIdleTimer(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        if (DBG) Slog.d(TAG, "Removing idletimer");
+
+        synchronized (mIdleTimerLock) {
+            IdleTimerParams params = mActiveIdleTimers.get(iface);
+            if (params == null || --(params.networkCount) > 0) {
+                return;
+            }
+
+            try {
+                mConnector.execute("idletimer", "remove", iface,
+                        Integer.toString(params.timeout), params.label);
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+            mActiveIdleTimers.remove(iface);
+        }
+    }
+
+    @Override
+    public NetworkStats getNetworkStatsSummaryDev() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return mStatsFactory.readNetworkStatsSummaryDev();
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public NetworkStats getNetworkStatsSummaryXt() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return mStatsFactory.readNetworkStatsSummaryXt();
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public NetworkStats getNetworkStatsDetail() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return mStatsFactory.readNetworkStatsDetail(UID_ALL);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public void setInterfaceQuota(String iface, long quotaBytes) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        // silently discard when control disabled
+        // TODO: eventually migrate to be always enabled
+        if (!mBandwidthControlEnabled) return;
+
+        synchronized (mQuotaLock) {
+            if (mActiveQuotas.containsKey(iface)) {
+                throw new IllegalStateException("iface " + iface + " already has quota");
+            }
+
+            try {
+                // TODO: support quota shared across interfaces
+                mConnector.execute("bandwidth", "setiquota", iface, quotaBytes);
+                mActiveQuotas.put(iface, quotaBytes);
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+        }
+    }
+
+    @Override
+    public void removeInterfaceQuota(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        // silently discard when control disabled
+        // TODO: eventually migrate to be always enabled
+        if (!mBandwidthControlEnabled) return;
+
+        synchronized (mQuotaLock) {
+            if (!mActiveQuotas.containsKey(iface)) {
+                // TODO: eventually consider throwing
+                return;
+            }
+
+            mActiveQuotas.remove(iface);
+            mActiveAlerts.remove(iface);
+
+            try {
+                // TODO: support quota shared across interfaces
+                mConnector.execute("bandwidth", "removeiquota", iface);
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+        }
+    }
+
+    @Override
+    public void setInterfaceAlert(String iface, long alertBytes) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        // silently discard when control disabled
+        // TODO: eventually migrate to be always enabled
+        if (!mBandwidthControlEnabled) return;
+
+        // quick sanity check
+        if (!mActiveQuotas.containsKey(iface)) {
+            throw new IllegalStateException("setting alert requires existing quota on iface");
+        }
+
+        synchronized (mQuotaLock) {
+            if (mActiveAlerts.containsKey(iface)) {
+                throw new IllegalStateException("iface " + iface + " already has alert");
+            }
+
+            try {
+                // TODO: support alert shared across interfaces
+                mConnector.execute("bandwidth", "setinterfacealert", iface, alertBytes);
+                mActiveAlerts.put(iface, alertBytes);
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+        }
+    }
+
+    @Override
+    public void removeInterfaceAlert(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        // silently discard when control disabled
+        // TODO: eventually migrate to be always enabled
+        if (!mBandwidthControlEnabled) return;
+
+        synchronized (mQuotaLock) {
+            if (!mActiveAlerts.containsKey(iface)) {
+                // TODO: eventually consider throwing
+                return;
+            }
+
+            try {
+                // TODO: support alert shared across interfaces
+                mConnector.execute("bandwidth", "removeinterfacealert", iface);
+                mActiveAlerts.remove(iface);
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+        }
+    }
+
+    @Override
+    public void setGlobalAlert(long alertBytes) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        // silently discard when control disabled
+        // TODO: eventually migrate to be always enabled
+        if (!mBandwidthControlEnabled) return;
+
+        try {
+            mConnector.execute("bandwidth", "setglobalalert", alertBytes);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setUidNetworkRules(int uid, boolean rejectOnQuotaInterfaces) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        // silently discard when control disabled
+        // TODO: eventually migrate to be always enabled
+        if (!mBandwidthControlEnabled) return;
+
+        synchronized (mQuotaLock) {
+            final boolean oldRejectOnQuota = mUidRejectOnQuota.get(uid, false);
+            if (oldRejectOnQuota == rejectOnQuotaInterfaces) {
+                // TODO: eventually consider throwing
+                return;
+            }
+
+            try {
+                mConnector.execute("bandwidth",
+                        rejectOnQuotaInterfaces ? "addnaughtyapps" : "removenaughtyapps", uid);
+                if (rejectOnQuotaInterfaces) {
+                    mUidRejectOnQuota.put(uid, true);
+                } else {
+                    mUidRejectOnQuota.delete(uid);
+                }
+            } catch (NativeDaemonConnectorException e) {
+                throw e.rethrowAsParcelableException();
+            }
+        }
+    }
+
+    @Override
+    public boolean isBandwidthControlEnabled() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        return mBandwidthControlEnabled;
+    }
+
+    @Override
+    public NetworkStats getNetworkStatsUidDetail(int uid) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            return mStatsFactory.readNetworkStatsDetail(uid);
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    public NetworkStats getNetworkStatsTethering() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
+        try {
+            final NativeDaemonEvent[] events = mConnector.executeForList(
+                    "bandwidth", "gettetherstats");
+            for (NativeDaemonEvent event : events) {
+                if (event.getCode() != TetheringStatsListResult) continue;
+
+                // 114 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets
+                final StringTokenizer tok = new StringTokenizer(event.getMessage());
+                try {
+                    final String ifaceIn = tok.nextToken();
+                    final String ifaceOut = tok.nextToken();
+
+                    final NetworkStats.Entry entry = new NetworkStats.Entry();
+                    entry.iface = ifaceOut;
+                    entry.uid = UID_TETHERING;
+                    entry.set = SET_DEFAULT;
+                    entry.tag = TAG_NONE;
+                    entry.rxBytes = Long.parseLong(tok.nextToken());
+                    entry.rxPackets = Long.parseLong(tok.nextToken());
+                    entry.txBytes = Long.parseLong(tok.nextToken());
+                    entry.txPackets = Long.parseLong(tok.nextToken());
+                    stats.combineValues(entry);
+                } catch (NoSuchElementException e) {
+                    throw new IllegalStateException("problem parsing tethering stats: " + event);
+                } catch (NumberFormatException e) {
+                    throw new IllegalStateException("problem parsing tethering stats: " + event);
+                }
+            }
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+        return stats;
+    }
+
+    @Override
+    public void setDefaultInterfaceForDns(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "setdefaultif", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setDnsServersForInterface(String iface, String[] servers, String domains) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final Command cmd = new Command("resolver", "setifdns", iface,
+                (domains == null ? "" : domains));
+
+        for (String s : servers) {
+            InetAddress a = NetworkUtils.numericToInetAddress(s);
+            if (a.isAnyLocalAddress() == false) {
+                cmd.appendArg(a.getHostAddress());
+            }
+        }
+
+        try {
+            mConnector.execute(cmd);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setUidRangeRoute(String iface, int uid_start, int uid_end) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "fwmark",
+                    "uid", "add", iface, uid_start, uid_end);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void clearUidRangeRoute(String iface, int uid_start, int uid_end) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "fwmark",
+                    "uid", "remove", iface, uid_start, uid_end);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setMarkedForwarding(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "fwmark", "rule", "add", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void clearMarkedForwarding(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "fwmark", "rule", "remove", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public int getMarkForUid(int uid) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("interface", "fwmark", "get", "mark", uid);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+        event.checkCode(GetMarkResult);
+        return Integer.parseInt(event.getMessage());
+    }
+
+    @Override
+    public int getMarkForProtect() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("interface", "fwmark", "get", "protect");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+        event.checkCode(GetMarkResult);
+        return Integer.parseInt(event.getMessage());
+    }
+
+    @Override
+    public void setMarkedForwardingRoute(String iface, RouteInfo route) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            LinkAddress dest = route.getDestination();
+            mConnector.execute("interface", "fwmark", "route", "add", iface,
+                    dest.getAddress().getHostAddress(), dest.getNetworkPrefixLength());
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void clearMarkedForwardingRoute(String iface, RouteInfo route) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            LinkAddress dest = route.getDestination();
+            mConnector.execute("interface", "fwmark", "route", "remove", iface,
+                    dest.getAddress().getHostAddress(), dest.getNetworkPrefixLength());
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setHostExemption(LinkAddress host) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "fwmark", "exempt", "add", host);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void clearHostExemption(LinkAddress host) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("interface", "fwmark", "exempt", "remove", host);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setDnsInterfaceForUidRange(String iface, int uid_start, int uid_end) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "setifaceforuidrange", iface, uid_start, uid_end);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void clearDnsInterfaceForUidRange(int uid_start, int uid_end) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "clearifaceforuidrange", uid_start, uid_end);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void clearDnsInterfaceMaps() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "clearifacemapping");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+
+    @Override
+    public void flushDefaultDnsCache() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "flushdefaultif");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void flushInterfaceDnsCache(String iface) {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "flushif", iface);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setFirewallEnabled(boolean enabled) {
+        enforceSystemUid();
+        try {
+            mConnector.execute("firewall", enabled ? "enable" : "disable");
+            mFirewallEnabled = enabled;
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public boolean isFirewallEnabled() {
+        enforceSystemUid();
+        return mFirewallEnabled;
+    }
+
+    @Override
+    public void setFirewallInterfaceRule(String iface, boolean allow) {
+        enforceSystemUid();
+        Preconditions.checkState(mFirewallEnabled);
+        final String rule = allow ? ALLOW : DENY;
+        try {
+            mConnector.execute("firewall", "set_interface_rule", iface, rule);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setFirewallEgressSourceRule(String addr, boolean allow) {
+        enforceSystemUid();
+        Preconditions.checkState(mFirewallEnabled);
+        final String rule = allow ? ALLOW : DENY;
+        try {
+            mConnector.execute("firewall", "set_egress_source_rule", addr, rule);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setFirewallEgressDestRule(String addr, int port, boolean allow) {
+        enforceSystemUid();
+        Preconditions.checkState(mFirewallEnabled);
+        final String rule = allow ? ALLOW : DENY;
+        try {
+            mConnector.execute("firewall", "set_egress_dest_rule", addr, port, rule);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void setFirewallUidRule(int uid, boolean allow) {
+        enforceSystemUid();
+        Preconditions.checkState(mFirewallEnabled);
+        final String rule = allow ? ALLOW : DENY;
+        try {
+            mConnector.execute("firewall", "set_uid_rule", uid, rule);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    private static void enforceSystemUid() {
+        final int uid = Binder.getCallingUid();
+        if (uid != Process.SYSTEM_UID) {
+            throw new SecurityException("Only available to AID_SYSTEM");
+        }
+    }
+
+    @Override
+    public void setDnsInterfaceForPid(String iface, int pid) throws IllegalStateException {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "setifaceforpid", iface, pid);
+        } catch (NativeDaemonConnectorException e) {
+            throw new IllegalStateException(
+                    "Error communicating with native deamon to set interface for pid" + iface, e);
+        }
+    }
+
+    @Override
+    public void clearDnsInterfaceForPid(int pid) throws IllegalStateException {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+        try {
+            mConnector.execute("resolver", "clearifaceforpid", pid);
+        } catch (NativeDaemonConnectorException e) {
+            throw new IllegalStateException(
+                    "Error communicating with native deamon to clear interface for pid " + pid, e);
+        }
+    }
+
+    @Override
+    public void startClatd(String interfaceName) throws IllegalStateException {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        try {
+            mConnector.execute("clatd", "start", interfaceName);
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public void stopClatd() throws IllegalStateException {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        try {
+            mConnector.execute("clatd", "stop");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+    }
+
+    @Override
+    public boolean isClatdStarted() {
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        final NativeDaemonEvent event;
+        try {
+            event = mConnector.execute("clatd", "status");
+        } catch (NativeDaemonConnectorException e) {
+            throw e.rethrowAsParcelableException();
+        }
+
+        event.checkCode(ClatdStatusResult);
+        return event.getMessage().endsWith("started");
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void monitor() {
+        if (mConnector != null) {
+            mConnector.monitor();
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        mContext.enforceCallingOrSelfPermission(DUMP, TAG);
+
+        pw.println("NetworkManagementService NativeDaemonConnector Log:");
+        mConnector.dump(fd, pw, args);
+        pw.println();
+
+        pw.print("Bandwidth control enabled: "); pw.println(mBandwidthControlEnabled);
+
+        synchronized (mQuotaLock) {
+            pw.print("Active quota ifaces: "); pw.println(mActiveQuotas.toString());
+            pw.print("Active alert ifaces: "); pw.println(mActiveAlerts.toString());
+        }
+
+        synchronized (mUidRejectOnQuota) {
+            pw.print("UID reject on quota ifaces: [");
+            final int size = mUidRejectOnQuota.size();
+            for (int i = 0; i < size; i++) {
+                pw.print(mUidRejectOnQuota.keyAt(i));
+                if (i < size - 1) pw.print(",");
+            }
+            pw.println("]");
+        }
+
+        pw.print("Firewall enabled: "); pw.println(mFirewallEnabled);
+    }
+}
diff --git a/services/java/com/android/server/NetworkTimeUpdateService.java b/services/core/java/com/android/server/NetworkTimeUpdateService.java
similarity index 100%
rename from services/java/com/android/server/NetworkTimeUpdateService.java
rename to services/core/java/com/android/server/NetworkTimeUpdateService.java
diff --git a/services/java/com/android/server/NsdService.java b/services/core/java/com/android/server/NsdService.java
similarity index 100%
rename from services/java/com/android/server/NsdService.java
rename to services/core/java/com/android/server/NsdService.java
diff --git a/services/core/java/com/android/server/RandomBlock.java b/services/core/java/com/android/server/RandomBlock.java
new file mode 100644
index 0000000..6d6d901
--- /dev/null
+++ b/services/core/java/com/android/server/RandomBlock.java
@@ -0,0 +1,101 @@
+/*
+ * 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.
+ */
+
+package com.android.server;
+
+import android.util.Slog;
+
+import java.io.Closeable;
+import java.io.DataOutput;
+import java.io.EOFException;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+
+/**
+ * A block of 512 random {@code byte}s.
+ */
+class RandomBlock {
+
+    private static final String TAG = "RandomBlock";
+    private static final boolean DEBUG = false;
+    private static final int BLOCK_SIZE = 512;
+    private byte[] block = new byte[BLOCK_SIZE];
+
+    private RandomBlock() { }
+
+    static RandomBlock fromFile(String filename) throws IOException {
+        if (DEBUG) Slog.v(TAG, "reading from file " + filename);
+        InputStream stream = null;
+        try {
+            stream = new FileInputStream(filename);
+            return fromStream(stream);
+        } finally {
+            close(stream);
+        }
+    }
+
+    private static RandomBlock fromStream(InputStream in) throws IOException {
+        RandomBlock retval = new RandomBlock();
+        int total = 0;
+        while(total < BLOCK_SIZE) {
+            int result = in.read(retval.block, total, BLOCK_SIZE - total);
+            if (result == -1) {
+                throw new EOFException();
+            }
+            total += result;
+        }
+        return retval;
+    }
+
+    void toFile(String filename, boolean sync) throws IOException {
+        if (DEBUG) Slog.v(TAG, "writing to file " + filename);
+        RandomAccessFile out = null;
+        try {
+            out = new RandomAccessFile(filename, sync ? "rws" : "rw");
+            toDataOut(out);
+            truncateIfPossible(out);
+        } finally {
+            close(out);
+        }
+    }
+
+    private static void truncateIfPossible(RandomAccessFile f) {
+        try {
+            f.setLength(BLOCK_SIZE);
+        } catch (IOException e) {
+            // ignore this exception.  Sometimes, the file we're trying to
+            // write is a character device, such as /dev/urandom, and
+            // these character devices do not support setting the length.
+        }
+    }
+
+    private void toDataOut(DataOutput out) throws IOException {
+        out.write(block);
+    }
+
+    private static void close(Closeable c) {
+        try {
+            if (c == null) {
+                return;
+            }
+            c.close();
+        } catch (IOException e) {
+            Slog.w(TAG, "IOException thrown while closing Closeable", e);
+        }
+    }
+}
diff --git a/services/java/com/android/server/RecognitionManagerService.java b/services/core/java/com/android/server/RecognitionManagerService.java
similarity index 100%
rename from services/java/com/android/server/RecognitionManagerService.java
rename to services/core/java/com/android/server/RecognitionManagerService.java
diff --git a/services/java/com/android/server/SamplingProfilerService.java b/services/core/java/com/android/server/SamplingProfilerService.java
similarity index 100%
rename from services/java/com/android/server/SamplingProfilerService.java
rename to services/core/java/com/android/server/SamplingProfilerService.java
diff --git a/services/java/com/android/server/SerialService.java b/services/core/java/com/android/server/SerialService.java
similarity index 100%
rename from services/java/com/android/server/SerialService.java
rename to services/core/java/com/android/server/SerialService.java
diff --git a/services/core/java/com/android/server/ServiceThread.java b/services/core/java/com/android/server/ServiceThread.java
new file mode 100644
index 0000000..bce64af
--- /dev/null
+++ b/services/core/java/com/android/server/ServiceThread.java
@@ -0,0 +1,48 @@
+/*
+ * 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.server;
+
+import android.os.HandlerThread;
+import android.os.Process;
+import android.os.StrictMode;
+import android.util.Slog;
+
+/**
+ * Special handler thread that we create for system services that require their own loopers.
+ */
+public class ServiceThread extends HandlerThread {
+    private static final String TAG = "ServiceThread";
+
+    private final boolean mAllowIo;
+
+    public ServiceThread(String name, int priority, boolean allowIo) {
+        super(name, priority);
+        mAllowIo = allowIo;
+    }
+
+    @Override
+    public void run() {
+        Process.setCanSelfBackground(false);
+
+        // For debug builds, log event loop stalls to dropbox for analysis.
+        if (!mAllowIo && StrictMode.conditionallyEnableDebugLogging()) {
+            Slog.i(TAG, "Enabled StrictMode logging for " + getName() + " looper.");
+        }
+
+        super.run();
+    }
+}
\ No newline at end of file
diff --git a/services/java/com/android/server/ServiceWatcher.java b/services/core/java/com/android/server/ServiceWatcher.java
similarity index 100%
rename from services/java/com/android/server/ServiceWatcher.java
rename to services/core/java/com/android/server/ServiceWatcher.java
diff --git a/services/java/com/android/server/ShutdownActivity.java b/services/core/java/com/android/server/ShutdownActivity.java
similarity index 100%
rename from services/java/com/android/server/ShutdownActivity.java
rename to services/core/java/com/android/server/ShutdownActivity.java
diff --git a/services/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java
similarity index 100%
rename from services/java/com/android/server/TelephonyRegistry.java
rename to services/core/java/com/android/server/TelephonyRegistry.java
diff --git a/services/java/com/android/server/TextServicesManagerService.java b/services/core/java/com/android/server/TextServicesManagerService.java
similarity index 100%
rename from services/java/com/android/server/TextServicesManagerService.java
rename to services/core/java/com/android/server/TextServicesManagerService.java
diff --git a/services/java/com/android/server/TwilightCalculator.java b/services/core/java/com/android/server/TwilightCalculator.java
similarity index 100%
rename from services/java/com/android/server/TwilightCalculator.java
rename to services/core/java/com/android/server/TwilightCalculator.java
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java
new file mode 100644
index 0000000..ad693d0
--- /dev/null
+++ b/services/core/java/com/android/server/UiModeManagerService.java
@@ -0,0 +1,622 @@
+/*
+ * 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.server;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManagerNative;
+import android.app.IUiModeManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.StatusBarManager;
+import android.app.UiModeManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Configuration;
+import android.os.BatteryManager;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.PowerManager;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.service.dreams.Sandman;
+import android.util.Slog;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+import com.android.internal.R;
+import com.android.internal.app.DisableCarModeActivity;
+import com.android.server.twilight.TwilightListener;
+import com.android.server.twilight.TwilightManager;
+import com.android.server.twilight.TwilightState;
+
+final class UiModeManagerService extends SystemService {
+    private static final String TAG = UiModeManager.class.getSimpleName();
+    private static final boolean LOG = false;
+
+    // Enable launching of applications when entering the dock.
+    private static final boolean ENABLE_LAUNCH_CAR_DOCK_APP = true;
+    private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true;
+
+    final Object mLock = new Object();
+    private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
+
+    private int mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
+    int mNightMode = UiModeManager.MODE_NIGHT_NO;
+
+    private boolean mCarModeEnabled = false;
+    private boolean mCharging = false;
+    private int mDefaultUiModeType;
+    private boolean mCarModeKeepsScreenOn;
+    private boolean mDeskModeKeepsScreenOn;
+    private boolean mTelevision;
+    private boolean mComputedNightMode;
+
+    int mCurUiMode = 0;
+    private int mSetUiMode = 0;
+    private boolean mHoldingConfiguration = false;
+
+    private Configuration mConfiguration = new Configuration();
+    boolean mSystemReady;
+
+    private final Handler mHandler = new Handler();
+
+    private TwilightManager mTwilightManager;
+    private NotificationManager mNotificationManager;
+    private StatusBarManager mStatusBarManager;
+
+    private PowerManager.WakeLock mWakeLock;
+
+    public UiModeManagerService(Context context) {
+        super(context);
+    }
+
+    private static Intent buildHomeIntent(String category) {
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.addCategory(category);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+        return intent;
+    }
+
+    // The broadcast receiver which receives the result of the ordered broadcast sent when
+    // the dock state changes. The original ordered broadcast is sent with an initial result
+    // code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g.,
+    // to RESULT_CANCELED, then the intent to start a dock app will not be sent.
+    private final BroadcastReceiver mResultReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (getResultCode() != Activity.RESULT_OK) {
+                if (LOG) {
+                    Slog.v(TAG, "Handling broadcast result for action " + intent.getAction()
+                            + ": canceled: " + getResultCode());
+                }
+                return;
+            }
+
+            final int enableFlags = intent.getIntExtra("enableFlags", 0);
+            final int disableFlags = intent.getIntExtra("disableFlags", 0);
+            synchronized (mLock) {
+                updateAfterBroadcastLocked(intent.getAction(), enableFlags, disableFlags);
+            }
+        }
+    };
+
+    private final BroadcastReceiver mDockModeReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
+                    Intent.EXTRA_DOCK_STATE_UNDOCKED);
+            updateDockState(state);
+        }
+    };
+
+    private final BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            mCharging = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0);
+            synchronized (mLock) {
+                if (mSystemReady) {
+                    updateLocked(0, 0);
+                }
+            }
+        }
+    };
+
+    private final TwilightListener mTwilightListener = new TwilightListener() {
+        @Override
+        public void onTwilightStateChanged() {
+            updateTwilight();
+        }
+    };
+
+    @Override
+    public void onStart() {
+        final Context context = getContext();
+        mTwilightManager = getLocalService(TwilightManager.class);
+        final PowerManager powerManager =
+                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+        mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);
+
+        context.registerReceiver(mDockModeReceiver,
+                new IntentFilter(Intent.ACTION_DOCK_EVENT));
+        context.registerReceiver(mBatteryReceiver,
+                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
+
+        mConfiguration.setToDefaults();
+
+        mDefaultUiModeType = context.getResources().getInteger(
+                com.android.internal.R.integer.config_defaultUiModeType);
+        mCarModeKeepsScreenOn = (context.getResources().getInteger(
+                com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1);
+        mDeskModeKeepsScreenOn = (context.getResources().getInteger(
+                com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1);
+        mTelevision = context.getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_TELEVISION);
+
+        mNightMode = Settings.Secure.getInt(context.getContentResolver(),
+                Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO);
+
+        mTwilightManager.registerListener(mTwilightListener, mHandler);
+
+        publishBinderService(Context.UI_MODE_SERVICE, mService);
+    }
+
+    private final IBinder mService = new IUiModeManager.Stub() {
+        @Override
+        public void enableCarMode(int flags) {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                synchronized (mLock) {
+                    setCarModeLocked(true);
+                    if (mSystemReady) {
+                        updateLocked(flags, 0);
+                    }
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override
+        public void disableCarMode(int flags) {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                synchronized (mLock) {
+                    setCarModeLocked(false);
+                    if (mSystemReady) {
+                        updateLocked(0, flags);
+                    }
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override
+        public int getCurrentModeType() {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                synchronized (mLock) {
+                    return mCurUiMode & Configuration.UI_MODE_TYPE_MASK;
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override
+        public void setNightMode(int mode) {
+            switch (mode) {
+                case UiModeManager.MODE_NIGHT_NO:
+                case UiModeManager.MODE_NIGHT_YES:
+                case UiModeManager.MODE_NIGHT_AUTO:
+                    break;
+                default:
+                    throw new IllegalArgumentException("Unknown mode: " + mode);
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                synchronized (mLock) {
+                    if (isDoingNightModeLocked() && mNightMode != mode) {
+                        Settings.Secure.putInt(getContext().getContentResolver(),
+                                Settings.Secure.UI_NIGHT_MODE, mode);
+                        mNightMode = mode;
+                        updateLocked(0, 0);
+                    }
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override
+        public int getNightMode() {
+            synchronized (mLock) {
+                return mNightMode;
+            }
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+
+                pw.println("Permission Denial: can't dump uimode service from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            dumpImpl(pw);
+        }
+    };
+
+    void dumpImpl(PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println("Current UI Mode Service state:");
+            pw.print("  mDockState="); pw.print(mDockState);
+                    pw.print(" mLastBroadcastState="); pw.println(mLastBroadcastState);
+            pw.print("  mNightMode="); pw.print(mNightMode);
+                    pw.print(" mCarModeEnabled="); pw.print(mCarModeEnabled);
+                    pw.print(" mComputedNightMode="); pw.println(mComputedNightMode);
+            pw.print("  mCurUiMode=0x"); pw.print(Integer.toHexString(mCurUiMode));
+                    pw.print(" mSetUiMode=0x"); pw.println(Integer.toHexString(mSetUiMode));
+            pw.print("  mHoldingConfiguration="); pw.print(mHoldingConfiguration);
+                    pw.print(" mSystemReady="); pw.println(mSystemReady);
+            pw.print("  mTwilightService.getCurrentState()=");
+                    pw.println(mTwilightManager.getCurrentState());
+        }
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
+            synchronized (mLock) {
+                mSystemReady = true;
+                mCarModeEnabled = mDockState == Intent.EXTRA_DOCK_STATE_CAR;
+                updateComputedNightModeLocked();
+                updateLocked(0, 0);
+            }
+        }
+    }
+
+    boolean isDoingNightModeLocked() {
+        return mCarModeEnabled || mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
+    }
+
+    void setCarModeLocked(boolean enabled) {
+        if (mCarModeEnabled != enabled) {
+            mCarModeEnabled = enabled;
+        }
+    }
+
+    private void updateDockState(int newState) {
+        synchronized (mLock) {
+            if (newState != mDockState) {
+                mDockState = newState;
+                setCarModeLocked(mDockState == Intent.EXTRA_DOCK_STATE_CAR);
+                if (mSystemReady) {
+                    updateLocked(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME, 0);
+                }
+            }
+        }
+    }
+
+    private static boolean isDeskDockState(int state) {
+        switch (state) {
+            case Intent.EXTRA_DOCK_STATE_DESK:
+            case Intent.EXTRA_DOCK_STATE_LE_DESK:
+            case Intent.EXTRA_DOCK_STATE_HE_DESK:
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    private void updateConfigurationLocked() {
+        int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType;
+        if (mCarModeEnabled) {
+            uiMode = Configuration.UI_MODE_TYPE_CAR;
+        } else if (isDeskDockState(mDockState)) {
+            uiMode = Configuration.UI_MODE_TYPE_DESK;
+        }
+        if (mCarModeEnabled) {
+            if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
+                updateComputedNightModeLocked();
+                uiMode |= mComputedNightMode ? Configuration.UI_MODE_NIGHT_YES
+                        : Configuration.UI_MODE_NIGHT_NO;
+            } else {
+                uiMode |= mNightMode << 4;
+            }
+        } else {
+            // Disabling the car mode clears the night mode.
+            uiMode = (uiMode & ~Configuration.UI_MODE_NIGHT_MASK) | Configuration.UI_MODE_NIGHT_NO;
+        }
+
+        if (LOG) {
+            Slog.d(TAG,
+                "updateConfigurationLocked: mDockState=" + mDockState
+                + "; mCarMode=" + mCarModeEnabled
+                + "; mNightMode=" + mNightMode
+                + "; uiMode=" + uiMode);
+        }
+
+        mCurUiMode = uiMode;
+        if (!mHoldingConfiguration) {
+            mConfiguration.uiMode = uiMode;
+        }
+    }
+
+    private void sendConfigurationLocked() {
+        if (mSetUiMode != mConfiguration.uiMode) {
+            mSetUiMode = mConfiguration.uiMode;
+
+            try {
+                ActivityManagerNative.getDefault().updateConfiguration(mConfiguration);
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Failure communicating with activity manager", e);
+            }
+        }
+    }
+
+    void updateLocked(int enableFlags, int disableFlags) {
+        String action = null;
+        String oldAction = null;
+        if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
+            adjustStatusBarCarModeLocked();
+            oldAction = UiModeManager.ACTION_EXIT_CAR_MODE;
+        } else if (isDeskDockState(mLastBroadcastState)) {
+            oldAction = UiModeManager.ACTION_EXIT_DESK_MODE;
+        }
+
+        if (mCarModeEnabled) {
+            if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) {
+                adjustStatusBarCarModeLocked();
+
+                if (oldAction != null) {
+                    getContext().sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
+                }
+                mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR;
+                action = UiModeManager.ACTION_ENTER_CAR_MODE;
+            }
+        } else if (isDeskDockState(mDockState)) {
+            if (!isDeskDockState(mLastBroadcastState)) {
+                if (oldAction != null) {
+                    getContext().sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
+                }
+                mLastBroadcastState = mDockState;
+                action = UiModeManager.ACTION_ENTER_DESK_MODE;
+            }
+        } else {
+            mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
+            action = oldAction;
+        }
+
+        if (action != null) {
+            if (LOG) {
+                Slog.v(TAG, String.format(
+                    "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x",
+                    action, enableFlags, disableFlags));
+            }
+
+            // Send the ordered broadcast; the result receiver will receive after all
+            // broadcasts have been sent. If any broadcast receiver changes the result
+            // code from the initial value of RESULT_OK, then the result receiver will
+            // not launch the corresponding dock application. This gives apps a chance
+            // to override the behavior and stay in their app even when the device is
+            // placed into a dock.
+            Intent intent = new Intent(action);
+            intent.putExtra("enableFlags", enableFlags);
+            intent.putExtra("disableFlags", disableFlags);
+            getContext().sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
+                    mResultReceiver, null, Activity.RESULT_OK, null, null);
+
+            // Attempting to make this transition a little more clean, we are going
+            // to hold off on doing a configuration change until we have finished
+            // the broadcast and started the home activity.
+            mHoldingConfiguration = true;
+            updateConfigurationLocked();
+        } else {
+            String category = null;
+            if (mCarModeEnabled) {
+                if (ENABLE_LAUNCH_CAR_DOCK_APP
+                        && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+                    category = Intent.CATEGORY_CAR_DOCK;
+                }
+            } else if (isDeskDockState(mDockState)) {
+                if (ENABLE_LAUNCH_DESK_DOCK_APP
+                        && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+                    category = Intent.CATEGORY_DESK_DOCK;
+                }
+            } else {
+                if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
+                    category = Intent.CATEGORY_HOME;
+                }
+            }
+
+            if (LOG) {
+                Slog.v(TAG, "updateLocked: null action, mDockState="
+                        + mDockState +", category=" + category);
+            }
+
+            sendConfigurationAndStartDreamOrDockAppLocked(category);
+        }
+
+        // keep screen on when charging and in car mode
+        boolean keepScreenOn = mCharging &&
+                ((mCarModeEnabled && mCarModeKeepsScreenOn) ||
+                 (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
+        if (keepScreenOn != mWakeLock.isHeld()) {
+            if (keepScreenOn) {
+                mWakeLock.acquire();
+            } else {
+                mWakeLock.release();
+            }
+        }
+    }
+
+    private void updateAfterBroadcastLocked(String action, int enableFlags, int disableFlags) {
+        // Launch a dock activity
+        String category = null;
+        if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(action)) {
+            // Only launch car home when car mode is enabled and the caller
+            // has asked us to switch to it.
+            if (ENABLE_LAUNCH_CAR_DOCK_APP
+                    && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+                category = Intent.CATEGORY_CAR_DOCK;
+            }
+        } else if (UiModeManager.ACTION_ENTER_DESK_MODE.equals(action)) {
+            // Only launch car home when desk mode is enabled and the caller
+            // has asked us to switch to it.  Currently re-using the car
+            // mode flag since we don't have a formal API for "desk mode".
+            if (ENABLE_LAUNCH_DESK_DOCK_APP
+                    && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
+                category = Intent.CATEGORY_DESK_DOCK;
+            }
+        } else {
+            // Launch the standard home app if requested.
+            if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
+                category = Intent.CATEGORY_HOME;
+            }
+        }
+
+        if (LOG) {
+            Slog.v(TAG, String.format(
+                "Handling broadcast result for action %s: enable=0x%08x, disable=0x%08x, "
+                    + "category=%s",
+                action, enableFlags, disableFlags, category));
+        }
+
+        sendConfigurationAndStartDreamOrDockAppLocked(category);
+    }
+
+    private void sendConfigurationAndStartDreamOrDockAppLocked(String category) {
+        // Update the configuration but don't send it yet.
+        mHoldingConfiguration = false;
+        updateConfigurationLocked();
+
+        // Start the dock app, if there is one.
+        boolean dockAppStarted = false;
+        if (category != null) {
+            // Now we are going to be careful about switching the
+            // configuration and starting the activity -- we need to
+            // do this in a specific order under control of the
+            // activity manager, to do it cleanly.  So compute the
+            // new config, but don't set it yet, and let the
+            // activity manager take care of both the start and config
+            // change.
+            Intent homeIntent = buildHomeIntent(category);
+            if (Sandman.shouldStartDockApp(getContext(), homeIntent)) {
+                try {
+                    int result = ActivityManagerNative.getDefault().startActivityWithConfig(
+                            null, null, homeIntent, null, null, null, 0, 0,
+                            mConfiguration, null, UserHandle.USER_CURRENT);
+                    if (result >= ActivityManager.START_SUCCESS) {
+                        dockAppStarted = true;
+                    } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) {
+                        Slog.e(TAG, "Could not start dock app: " + homeIntent
+                                + ", startActivityWithConfig result " + result);
+                    }
+                } catch (RemoteException ex) {
+                    Slog.e(TAG, "Could not start dock app: " + homeIntent, ex);
+                }
+            }
+        }
+
+        // Send the new configuration.
+        sendConfigurationLocked();
+
+        // If we did not start a dock app, then start dreaming if supported.
+        if (category != null && !dockAppStarted) {
+            Sandman.startDreamWhenDockedIfAppropriate(getContext());
+        }
+    }
+
+    private void adjustStatusBarCarModeLocked() {
+        final Context context = getContext();
+        if (mStatusBarManager == null) {
+            mStatusBarManager = (StatusBarManager)
+                    context.getSystemService(Context.STATUS_BAR_SERVICE);
+        }
+
+        // Fear not: StatusBarManagerService manages a list of requests to disable
+        // features of the status bar; these are ORed together to form the
+        // active disabled list. So if (for example) the device is locked and
+        // the status bar should be totally disabled, the calls below will
+        // have no effect until the device is unlocked.
+        if (mStatusBarManager != null) {
+            mStatusBarManager.disable(mCarModeEnabled
+                ? StatusBarManager.DISABLE_NOTIFICATION_TICKER
+                : StatusBarManager.DISABLE_NONE);
+        }
+
+        if (mNotificationManager == null) {
+            mNotificationManager = (NotificationManager)
+                    context.getSystemService(Context.NOTIFICATION_SERVICE);
+        }
+
+        if (mNotificationManager != null) {
+            if (mCarModeEnabled) {
+                Intent carModeOffIntent = new Intent(context, DisableCarModeActivity.class);
+
+                Notification n = new Notification();
+                n.icon = R.drawable.stat_notify_car_mode;
+                n.defaults = Notification.DEFAULT_LIGHTS;
+                n.flags = Notification.FLAG_ONGOING_EVENT;
+                n.when = 0;
+                n.setLatestEventInfo(
+                        context,
+                        context.getString(R.string.car_mode_disable_notification_title),
+                        context.getString(R.string.car_mode_disable_notification_message),
+                        PendingIntent.getActivityAsUser(context, 0, carModeOffIntent, 0,
+                                null, UserHandle.CURRENT));
+                mNotificationManager.notifyAsUser(null,
+                        R.string.car_mode_disable_notification_title, n, UserHandle.ALL);
+            } else {
+                mNotificationManager.cancelAsUser(null,
+                        R.string.car_mode_disable_notification_title, UserHandle.ALL);
+            }
+        }
+    }
+
+    void updateTwilight() {
+        synchronized (mLock) {
+            if (isDoingNightModeLocked() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
+                updateComputedNightModeLocked();
+                updateLocked(0, 0);
+            }
+        }
+    }
+
+    private void updateComputedNightModeLocked() {
+        TwilightState state = mTwilightManager.getCurrentState();
+        if (state != null) {
+            mComputedNightMode = state.isNight();
+        }
+    }
+
+
+}
diff --git a/services/core/java/com/android/server/UiThread.java b/services/core/java/com/android/server/UiThread.java
new file mode 100644
index 0000000..0beb77f
--- /dev/null
+++ b/services/core/java/com/android/server/UiThread.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2013 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;
+
+import android.os.Handler;
+
+/**
+ * Shared singleton thread for showing UI.  This is a foreground thread, and in
+ * additional should not have operations that can take more than a few ms scheduled
+ * on it to avoid UI jank.
+ */
+public final class UiThread extends ServiceThread {
+    private static UiThread sInstance;
+    private static Handler sHandler;
+
+    private UiThread() {
+        super("android.ui", android.os.Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
+    }
+
+    private static void ensureThreadLocked() {
+        if (sInstance == null) {
+            sInstance = new UiThread();
+            sInstance.start();
+            sHandler = new Handler(sInstance.getLooper());
+        }
+    }
+
+    public static UiThread get() {
+        synchronized (UiThread.class) {
+            ensureThreadLocked();
+            return sInstance;
+        }
+    }
+
+    public static Handler getHandler() {
+        synchronized (UiThread.class) {
+            ensureThreadLocked();
+            return sHandler;
+        }
+    }
+}
diff --git a/services/java/com/android/server/UpdateLockService.java b/services/core/java/com/android/server/UpdateLockService.java
similarity index 100%
rename from services/java/com/android/server/UpdateLockService.java
rename to services/core/java/com/android/server/UpdateLockService.java
diff --git a/services/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java
similarity index 100%
rename from services/java/com/android/server/VibratorService.java
rename to services/core/java/com/android/server/VibratorService.java
diff --git a/services/core/java/com/android/server/Watchdog.java b/services/core/java/com/android/server/Watchdog.java
new file mode 100644
index 0000000..1ce073a
--- /dev/null
+++ b/services/core/java/com/android/server/Watchdog.java
@@ -0,0 +1,486 @@
+/*
+ * 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.server;
+
+import android.app.IActivityController;
+import android.os.Binder;
+import android.os.RemoteException;
+import com.android.server.am.ActivityManagerService;
+
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Debug;
+import android.os.Handler;
+import android.os.IPowerManager;
+import android.os.Looper;
+import android.os.Process;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Slog;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/** This class calls its monitor every minute. Killing this process if they don't return **/
+public class Watchdog extends Thread {
+    static final String TAG = "Watchdog";
+    static final boolean localLOGV = false || false;
+
+    // Set this to true to use debug default values.
+    static final boolean DB = false;
+
+    // Set this to true to have the watchdog record kernel thread stacks when it fires
+    static final boolean RECORD_KERNEL_THREADS = true;
+
+    static final long DEFAULT_TIMEOUT = DB ? 10*1000 : 60*1000;
+    static final long CHECK_INTERVAL = DEFAULT_TIMEOUT / 2;
+
+    // These are temporally ordered: larger values as lateness increases
+    static final int COMPLETED = 0;
+    static final int WAITING = 1;
+    static final int WAITED_HALF = 2;
+    static final int OVERDUE = 3;
+
+    // Which native processes to dump into dropbox's stack traces
+    public static final String[] NATIVE_STACKS_OF_INTEREST = new String[] {
+        "/system/bin/mediaserver",
+        "/system/bin/sdcard",
+        "/system/bin/surfaceflinger"
+    };
+
+    static Watchdog sWatchdog;
+
+    /* This handler will be used to post message back onto the main thread */
+    final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<HandlerChecker>();
+    final HandlerChecker mMonitorChecker;
+    ContentResolver mResolver;
+    ActivityManagerService mActivity;
+
+    int mPhonePid;
+    IActivityController mController;
+    boolean mAllowRestart = true;
+
+    /**
+     * Used for checking status of handle threads and scheduling monitor callbacks.
+     */
+    public final class HandlerChecker implements Runnable {
+        private final Handler mHandler;
+        private final String mName;
+        private final long mWaitMax;
+        private final ArrayList<Monitor> mMonitors = new ArrayList<Monitor>();
+        private boolean mCompleted;
+        private Monitor mCurrentMonitor;
+        private long mStartTime;
+
+        HandlerChecker(Handler handler, String name, long waitMaxMillis) {
+            mHandler = handler;
+            mName = name;
+            mWaitMax = waitMaxMillis;
+            mCompleted = true;
+        }
+
+        public void addMonitor(Monitor monitor) {
+            mMonitors.add(monitor);
+        }
+
+        public void scheduleCheckLocked() {
+            if (mMonitors.size() == 0 && mHandler.getLooper().isIdling()) {
+                // If the target looper is or just recently was idling, then
+                // there is no reason to enqueue our checker on it since that
+                // is as good as it not being deadlocked.  This avoid having
+                // to do a context switch to check the thread.  Note that we
+                // only do this if mCheckReboot is false and we have no
+                // monitors, since those would need to be executed at this point.
+                mCompleted = true;
+                return;
+            }
+
+            if (!mCompleted) {
+                // we already have a check in flight, so no need
+                return;
+            }
+
+            mCompleted = false;
+            mCurrentMonitor = null;
+            mStartTime = SystemClock.uptimeMillis();
+            mHandler.postAtFrontOfQueue(this);
+        }
+
+        public boolean isOverdueLocked() {
+            return (!mCompleted) && (SystemClock.uptimeMillis() > mStartTime + mWaitMax);
+        }
+
+        public int getCompletionStateLocked() {
+            if (mCompleted) {
+                return COMPLETED;
+            } else {
+                long latency = SystemClock.uptimeMillis() - mStartTime;
+                if (latency < mWaitMax/2) {
+                    return WAITING;
+                } else if (latency < mWaitMax) {
+                    return WAITED_HALF;
+                }
+            }
+            return OVERDUE;
+        }
+
+        public Thread getThread() {
+            return mHandler.getLooper().getThread();
+        }
+
+        public String getName() {
+            return mName;
+        }
+
+        public String describeBlockedStateLocked() {
+            if (mCurrentMonitor == null) {
+                return "Blocked in handler on " + mName + " (" + getThread().getName() + ")";
+            } else {
+                return "Blocked in monitor " + mCurrentMonitor.getClass().getName()
+                        + " on " + mName + " (" + getThread().getName() + ")";
+            }
+        }
+
+        @Override
+        public void run() {
+            final int size = mMonitors.size();
+            for (int i = 0 ; i < size ; i++) {
+                synchronized (Watchdog.this) {
+                    mCurrentMonitor = mMonitors.get(i);
+                }
+                mCurrentMonitor.monitor();
+            }
+
+            synchronized (Watchdog.this) {
+                mCompleted = true;
+                mCurrentMonitor = null;
+            }
+        }
+    }
+
+    final class RebootRequestReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context c, Intent intent) {
+            if (intent.getIntExtra("nowait", 0) != 0) {
+                rebootSystem("Received ACTION_REBOOT broadcast");
+                return;
+            }
+            Slog.w(TAG, "Unsupported ACTION_REBOOT broadcast: " + intent);
+        }
+    }
+
+    public interface Monitor {
+        void monitor();
+    }
+
+    public static Watchdog getInstance() {
+        if (sWatchdog == null) {
+            sWatchdog = new Watchdog();
+        }
+
+        return sWatchdog;
+    }
+
+    private Watchdog() {
+        super("watchdog");
+        // Initialize handler checkers for each common thread we want to check.  Note
+        // that we are not currently checking the background thread, since it can
+        // potentially hold longer running operations with no guarantees about the timeliness
+        // of operations there.
+
+        // The shared foreground thread is the main checker.  It is where we
+        // will also dispatch monitor checks and do other work.
+        mMonitorChecker = new HandlerChecker(FgThread.getHandler(),
+                "foreground thread", DEFAULT_TIMEOUT);
+        mHandlerCheckers.add(mMonitorChecker);
+        // Add checker for main thread.  We only do a quick check since there
+        // can be UI running on the thread.
+        mHandlerCheckers.add(new HandlerChecker(new Handler(Looper.getMainLooper()),
+                "main thread", DEFAULT_TIMEOUT));
+        // Add checker for shared UI thread.
+        mHandlerCheckers.add(new HandlerChecker(UiThread.getHandler(),
+                "ui thread", DEFAULT_TIMEOUT));
+        // And also check IO thread.
+        mHandlerCheckers.add(new HandlerChecker(IoThread.getHandler(),
+                "i/o thread", DEFAULT_TIMEOUT));
+        // And the display thread.
+        mHandlerCheckers.add(new HandlerChecker(DisplayThread.getHandler(),
+                "display thread", DEFAULT_TIMEOUT));
+    }
+
+    public void init(Context context, ActivityManagerService activity) {
+        mResolver = context.getContentResolver();
+        mActivity = activity;
+
+        context.registerReceiver(new RebootRequestReceiver(),
+                new IntentFilter(Intent.ACTION_REBOOT),
+                android.Manifest.permission.REBOOT, null);
+    }
+
+    public void processStarted(String name, int pid) {
+        synchronized (this) {
+            if ("com.android.phone".equals(name)) {
+                mPhonePid = pid;
+            }
+        }
+    }
+
+    public void setActivityController(IActivityController controller) {
+        synchronized (this) {
+            mController = controller;
+        }
+    }
+
+    public void setAllowRestart(boolean allowRestart) {
+        synchronized (this) {
+            mAllowRestart = allowRestart;
+        }
+    }
+
+    public void addMonitor(Monitor monitor) {
+        synchronized (this) {
+            if (isAlive()) {
+                throw new RuntimeException("Monitors can't be added once the Watchdog is running");
+            }
+            mMonitorChecker.addMonitor(monitor);
+        }
+    }
+
+    public void addThread(Handler thread) {
+        addThread(thread, DEFAULT_TIMEOUT);
+    }
+
+    public void addThread(Handler thread, long timeoutMillis) {
+        synchronized (this) {
+            if (isAlive()) {
+                throw new RuntimeException("Threads can't be added once the Watchdog is running");
+            }
+            final String name = thread.getLooper().getThread().getName();
+            mHandlerCheckers.add(new HandlerChecker(thread, name, timeoutMillis));
+        }
+    }
+
+    /**
+     * Perform a full reboot of the system.
+     */
+    void rebootSystem(String reason) {
+        Slog.i(TAG, "Rebooting system because: " + reason);
+        IPowerManager pms = (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE);
+        try {
+            pms.reboot(false, reason, false);
+        } catch (RemoteException ex) {
+        }
+    }
+
+    private int evaluateCheckerCompletionLocked() {
+        int state = COMPLETED;
+        for (int i=0; i<mHandlerCheckers.size(); i++) {
+            HandlerChecker hc = mHandlerCheckers.get(i);
+            state = Math.max(state, hc.getCompletionStateLocked());
+        }
+        return state;
+    }
+
+    private ArrayList<HandlerChecker> getBlockedCheckersLocked() {
+        ArrayList<HandlerChecker> checkers = new ArrayList<HandlerChecker>();
+        for (int i=0; i<mHandlerCheckers.size(); i++) {
+            HandlerChecker hc = mHandlerCheckers.get(i);
+            if (hc.isOverdueLocked()) {
+                checkers.add(hc);
+            }
+        }
+        return checkers;
+    }
+
+    private String describeCheckersLocked(ArrayList<HandlerChecker> checkers) {
+        StringBuilder builder = new StringBuilder(128);
+        for (int i=0; i<checkers.size(); i++) {
+            if (builder.length() > 0) {
+                builder.append(", ");
+            }
+            builder.append(checkers.get(i).describeBlockedStateLocked());
+        }
+        return builder.toString();
+    }
+
+    @Override
+    public void run() {
+        boolean waitedHalf = false;
+        while (true) {
+            final ArrayList<HandlerChecker> blockedCheckers;
+            final String subject;
+            final boolean allowRestart;
+            synchronized (this) {
+                long timeout = CHECK_INTERVAL;
+                // Make sure we (re)spin the checkers that have become idle within
+                // this wait-and-check interval
+                for (int i=0; i<mHandlerCheckers.size(); i++) {
+                    HandlerChecker hc = mHandlerCheckers.get(i);
+                    hc.scheduleCheckLocked();
+                }
+
+                // NOTE: We use uptimeMillis() here because we do not want to increment the time we
+                // wait while asleep. If the device is asleep then the thing that we are waiting
+                // to timeout on is asleep as well and won't have a chance to run, causing a false
+                // positive on when to kill things.
+                long start = SystemClock.uptimeMillis();
+                while (timeout > 0) {
+                    try {
+                        wait(timeout);
+                    } catch (InterruptedException e) {
+                        Log.wtf(TAG, e);
+                    }
+                    timeout = CHECK_INTERVAL - (SystemClock.uptimeMillis() - start);
+                }
+
+                final int waitState = evaluateCheckerCompletionLocked();
+                if (waitState == COMPLETED) {
+                    // The monitors have returned; reset
+                    waitedHalf = false;
+                    continue;
+                } else if (waitState == WAITING) {
+                    // still waiting but within their configured intervals; back off and recheck
+                    continue;
+                } else if (waitState == WAITED_HALF) {
+                    if (!waitedHalf) {
+                        // We've waited half the deadlock-detection interval.  Pull a stack
+                        // trace and wait another half.
+                        ArrayList<Integer> pids = new ArrayList<Integer>();
+                        pids.add(Process.myPid());
+                        ActivityManagerService.dumpStackTraces(true, pids, null, null,
+                                NATIVE_STACKS_OF_INTEREST);
+                        waitedHalf = true;
+                    }
+                    continue;
+                }
+
+                // something is overdue!
+                blockedCheckers = getBlockedCheckersLocked();
+                subject = describeCheckersLocked(blockedCheckers);
+                allowRestart = mAllowRestart;
+            }
+
+            // If we got here, that means that the system is most likely hung.
+            // First collect stack traces from all threads of the system process.
+            // Then kill this process so that the system will restart.
+            EventLog.writeEvent(EventLogTags.WATCHDOG, subject);
+
+            ArrayList<Integer> pids = new ArrayList<Integer>();
+            pids.add(Process.myPid());
+            if (mPhonePid > 0) pids.add(mPhonePid);
+            // Pass !waitedHalf so that just in case we somehow wind up here without having
+            // dumped the halfway stacks, we properly re-initialize the trace file.
+            final File stack = ActivityManagerService.dumpStackTraces(
+                    !waitedHalf, pids, null, null, NATIVE_STACKS_OF_INTEREST);
+
+            // Give some extra time to make sure the stack traces get written.
+            // The system's been hanging for a minute, another second or two won't hurt much.
+            SystemClock.sleep(2000);
+
+            // Pull our own kernel thread stacks as well if we're configured for that
+            if (RECORD_KERNEL_THREADS) {
+                dumpKernelStackTraces();
+            }
+
+            // Trigger the kernel to dump all blocked threads to the kernel log
+            try {
+                FileWriter sysrq_trigger = new FileWriter("/proc/sysrq-trigger");
+                sysrq_trigger.write("w");
+                sysrq_trigger.close();
+            } catch (IOException e) {
+                Slog.e(TAG, "Failed to write to /proc/sysrq-trigger");
+                Slog.e(TAG, e.getMessage());
+            }
+
+            // Try to add the error to the dropbox, but assuming that the ActivityManager
+            // itself may be deadlocked.  (which has happened, causing this statement to
+            // deadlock and the watchdog as a whole to be ineffective)
+            Thread dropboxThread = new Thread("watchdogWriteToDropbox") {
+                    public void run() {
+                        mActivity.addErrorToDropBox(
+                                "watchdog", null, "system_server", null, null,
+                                subject, null, stack, null);
+                    }
+                };
+            dropboxThread.start();
+            try {
+                dropboxThread.join(2000);  // wait up to 2 seconds for it to return.
+            } catch (InterruptedException ignored) {}
+
+            IActivityController controller;
+            synchronized (this) {
+                controller = mController;
+            }
+            if (controller != null) {
+                Slog.i(TAG, "Reporting stuck state to activity controller");
+                try {
+                    Binder.setDumpDisabled("Service dumps disabled due to hung system process.");
+                    // 1 = keep waiting, -1 = kill system
+                    int res = controller.systemNotResponding(subject);
+                    if (res >= 0) {
+                        Slog.i(TAG, "Activity controller requested to coninue to wait");
+                        waitedHalf = false;
+                        continue;
+                    }
+                } catch (RemoteException e) {
+                }
+            }
+
+            // Only kill the process if the debugger is not attached.
+            if (Debug.isDebuggerConnected()) {
+                Slog.w(TAG, "Debugger connected: Watchdog is *not* killing the system process");
+            } else if (!allowRestart) {
+                Slog.w(TAG, "Restart not allowed: Watchdog is *not* killing the system process");
+            } else {
+                Slog.w(TAG, "*** WATCHDOG KILLING SYSTEM PROCESS: " + subject);
+                for (int i=0; i<blockedCheckers.size(); i++) {
+                    Slog.w(TAG, blockedCheckers.get(i).getName() + " stack trace:");
+                    StackTraceElement[] stackTrace
+                            = blockedCheckers.get(i).getThread().getStackTrace();
+                    for (StackTraceElement element: stackTrace) {
+                        Slog.w(TAG, "    at " + element);
+                    }
+                }
+                Slog.w(TAG, "*** GOODBYE!");
+                Process.killProcess(Process.myPid());
+                System.exit(10);
+            }
+
+            waitedHalf = false;
+        }
+    }
+
+    private File dumpKernelStackTraces() {
+        String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
+        if (tracesPath == null || tracesPath.length() == 0) {
+            return null;
+        }
+
+        native_dumpKernelStacks(tracesPath);
+        return new File(tracesPath);
+    }
+
+    private native void native_dumpKernelStacks(String tracesPath);
+}
diff --git a/services/java/com/android/server/WiredAccessoryManager.java b/services/core/java/com/android/server/WiredAccessoryManager.java
similarity index 100%
rename from services/java/com/android/server/WiredAccessoryManager.java
rename to services/core/java/com/android/server/WiredAccessoryManager.java
diff --git a/services/java/com/android/server/accounts/AccountAuthenticatorCache.java b/services/core/java/com/android/server/accounts/AccountAuthenticatorCache.java
similarity index 100%
rename from services/java/com/android/server/accounts/AccountAuthenticatorCache.java
rename to services/core/java/com/android/server/accounts/AccountAuthenticatorCache.java
diff --git a/services/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
similarity index 100%
rename from services/java/com/android/server/accounts/AccountManagerService.java
rename to services/core/java/com/android/server/accounts/AccountManagerService.java
diff --git a/services/java/com/android/server/accounts/IAccountAuthenticatorCache.java b/services/core/java/com/android/server/accounts/IAccountAuthenticatorCache.java
similarity index 100%
rename from services/java/com/android/server/accounts/IAccountAuthenticatorCache.java
rename to services/core/java/com/android/server/accounts/IAccountAuthenticatorCache.java
diff --git a/services/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
similarity index 100%
rename from services/java/com/android/server/am/ActiveServices.java
rename to services/core/java/com/android/server/am/ActiveServices.java
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
new file mode 100644
index 0000000..6c3f528
--- /dev/null
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -0,0 +1,16532 @@
+/*
+ * Copyright (C) 2006-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.server.am;
+
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static com.android.internal.util.XmlUtils.readIntAttribute;
+import static com.android.internal.util.XmlUtils.readLongAttribute;
+import static com.android.internal.util.XmlUtils.writeIntAttribute;
+import static com.android.internal.util.XmlUtils.writeLongAttribute;
+import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
+import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
+import static org.xmlpull.v1.XmlPullParser.START_TAG;
+
+import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
+
+import android.app.AppOpsManager;
+import android.app.IActivityContainer;
+import android.app.IActivityContainerCallback;
+import android.appwidget.AppWidgetManager;
+import android.graphics.Rect;
+import android.util.ArrayMap;
+import com.android.internal.R;
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.app.IAppOpsService;
+import com.android.internal.app.ProcessMap;
+import com.android.internal.app.ProcessStats;
+import com.android.internal.os.BackgroundThread;
+import com.android.internal.os.BatteryStatsImpl;
+import com.android.internal.os.ProcessCpuTracker;
+import com.android.internal.os.TransferPipe;
+import com.android.internal.util.FastPrintWriter;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.MemInfoReader;
+import com.android.internal.util.Preconditions;
+import com.android.server.AppOpsService;
+import com.android.server.AttributeCache;
+import com.android.server.IntentResolver;
+import com.android.server.ServiceThread;
+import com.android.server.SystemService;
+import com.android.server.Watchdog;
+import com.android.server.am.ActivityStack.ActivityState;
+import com.android.server.firewall.IntentFirewall;
+import com.android.server.pm.UserManagerService;
+import com.android.server.wm.AppTransition;
+import com.android.server.wm.WindowManagerService;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Maps;
+
+import dalvik.system.Zygote;
+
+import libcore.io.IoUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.RunningTaskInfo;
+import android.app.ActivityManager.StackInfo;
+import android.app.ActivityManagerNative;
+import android.app.ActivityOptions;
+import android.app.ActivityThread;
+import android.app.AlertDialog;
+import android.app.AppGlobals;
+import android.app.ApplicationErrorReport;
+import android.app.Dialog;
+import android.app.IActivityController;
+import android.app.IApplicationThread;
+import android.app.IInstrumentationWatcher;
+import android.app.INotificationManager;
+import android.app.IProcessObserver;
+import android.app.IServiceConnection;
+import android.app.IStopUserCallback;
+import android.app.IThumbnailReceiver;
+import android.app.IUiAutomationConnection;
+import android.app.IUserSwitchObserver;
+import android.app.Instrumentation;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.backup.IBackupManager;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ClipData;
+import android.content.ComponentCallbacks2;
+import android.content.ComponentName;
+import android.content.ContentProvider;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.IContentProvider;
+import android.content.IIntentReceiver;
+import android.content.IIntentSender;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.IntentSender;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ConfigurationInfo;
+import android.content.pm.IPackageDataObserver;
+import android.content.pm.IPackageManager;
+import android.content.pm.InstrumentationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ParceledListSlice;
+import android.content.pm.UserInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.PathPermission;
+import android.content.pm.ProviderInfo;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.res.CompatibilityInfo;
+import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.net.Proxy;
+import android.net.ProxyProperties;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.DropBoxManager;
+import android.os.Environment;
+import android.os.FactoryTest;
+import android.os.FileObserver;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IPermissionController;
+import android.os.IRemoteCallback;
+import android.os.IUserManager;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Parcel;
+import android.os.ParcelFileDescriptor;
+import android.os.Process;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+import android.os.SELinux;
+import android.os.ServiceManager;
+import android.os.StrictMode;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UpdateLock;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.text.format.DateUtils;
+import android.text.format.Time;
+import android.util.AtomicFile;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Pair;
+import android.util.PrintWriterPrinter;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.TimeUtils;
+import android.util.Xml;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+
+public final class ActivityManagerService extends ActivityManagerNative
+        implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
+    private static final String USER_DATA_DIR = "/data/user/";
+    static final String TAG = "ActivityManager";
+    static final String TAG_MU = "ActivityManagerServiceMU";
+    static final boolean DEBUG = false;
+    static final boolean localLOGV = DEBUG;
+    static final boolean DEBUG_BACKUP = localLOGV || false;
+    static final boolean DEBUG_BROADCAST = localLOGV || false;
+    static final boolean DEBUG_BROADCAST_LIGHT = DEBUG_BROADCAST || false;
+    static final boolean DEBUG_BACKGROUND_BROADCAST = DEBUG_BROADCAST || false;
+    static final boolean DEBUG_CLEANUP = localLOGV || false;
+    static final boolean DEBUG_CONFIGURATION = localLOGV || false;
+    static final boolean DEBUG_FOCUS = false;
+    static final boolean DEBUG_IMMERSIVE = localLOGV || false;
+    static final boolean DEBUG_MU = localLOGV || false;
+    static final boolean DEBUG_OOM_ADJ = localLOGV || false;
+    static final boolean DEBUG_LRU = localLOGV || false;
+    static final boolean DEBUG_PAUSE = localLOGV || false;
+    static final boolean DEBUG_POWER = localLOGV || false;
+    static final boolean DEBUG_POWER_QUICK = DEBUG_POWER || false;
+    static final boolean DEBUG_PROCESS_OBSERVERS = localLOGV || false;
+    static final boolean DEBUG_PROCESSES = localLOGV || false;
+    static final boolean DEBUG_PROVIDER = localLOGV || false;
+    static final boolean DEBUG_RESULTS = localLOGV || false;
+    static final boolean DEBUG_SERVICE = localLOGV || false;
+    static final boolean DEBUG_SERVICE_EXECUTING = localLOGV || false;
+    static final boolean DEBUG_STACK = localLOGV || false;
+    static final boolean DEBUG_SWITCH = localLOGV || false;
+    static final boolean DEBUG_TASKS = localLOGV || false;
+    static final boolean DEBUG_THUMBNAILS = localLOGV || false;
+    static final boolean DEBUG_TRANSITION = localLOGV || false;
+    static final boolean DEBUG_URI_PERMISSION = localLOGV || false;
+    static final boolean DEBUG_USER_LEAVING = localLOGV || false;
+    static final boolean DEBUG_VISBILITY = localLOGV || false;
+    static final boolean DEBUG_PSS = localLOGV || false;
+    static final boolean DEBUG_LOCKSCREEN = localLOGV || false;
+    static final boolean VALIDATE_TOKENS = false;
+    static final boolean SHOW_ACTIVITY_START_TIME = true;
+
+    // Control over CPU and battery monitoring.
+    static final long BATTERY_STATS_TIME = 30*60*1000;      // write battery stats every 30 minutes.
+    static final boolean MONITOR_CPU_USAGE = true;
+    static final long MONITOR_CPU_MIN_TIME = 5*1000;        // don't sample cpu less than every 5 seconds.
+    static final long MONITOR_CPU_MAX_TIME = 0x0fffffff;    // wait possibly forever for next cpu sample.
+    static final boolean MONITOR_THREAD_CPU_USAGE = false;
+
+    // The flags that are set for all calls we make to the package manager.
+    static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES;
+
+    private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
+
+    static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
+
+    // Maximum number of recent tasks that we can remember.
+    static final int MAX_RECENT_TASKS = ActivityManager.isLowRamDeviceStatic() ? 10 : 20;
+
+    // Amount of time after a call to stopAppSwitches() during which we will
+    // prevent further untrusted switches from happening.
+    static final long APP_SWITCH_DELAY_TIME = 5*1000;
+
+    // How long we wait for a launched process to attach to the activity manager
+    // before we decide it's never going to come up for real.
+    static final int PROC_START_TIMEOUT = 10*1000;
+
+    // How long we wait for a launched process to attach to the activity manager
+    // before we decide it's never going to come up for real, when the process was
+    // started with a wrapper for instrumentation (such as Valgrind) because it
+    // could take much longer than usual.
+    static final int PROC_START_TIMEOUT_WITH_WRAPPER = 300*1000;
+
+    // How long to wait after going idle before forcing apps to GC.
+    static final int GC_TIMEOUT = 5*1000;
+
+    // The minimum amount of time between successive GC requests for a process.
+    static final int GC_MIN_INTERVAL = 60*1000;
+
+    // The minimum amount of time between successive PSS requests for a process.
+    static final int FULL_PSS_MIN_INTERVAL = 10*60*1000;
+
+    // The minimum amount of time between successive PSS requests for a process
+    // when the request is due to the memory state being lowered.
+    static final int FULL_PSS_LOWERED_INTERVAL = 2*60*1000;
+
+    // The rate at which we check for apps using excessive power -- 15 mins.
+    static final int POWER_CHECK_DELAY = (DEBUG_POWER_QUICK ? 2 : 15) * 60*1000;
+
+    // The minimum sample duration we will allow before deciding we have
+    // enough data on wake locks to start killing things.
+    static final int WAKE_LOCK_MIN_CHECK_DURATION = (DEBUG_POWER_QUICK ? 1 : 5) * 60*1000;
+
+    // The minimum sample duration we will allow before deciding we have
+    // enough data on CPU usage to start killing things.
+    static final int CPU_MIN_CHECK_DURATION = (DEBUG_POWER_QUICK ? 1 : 5) * 60*1000;
+
+    // How long we allow a receiver to run before giving up on it.
+    static final int BROADCAST_FG_TIMEOUT = 10*1000;
+    static final int BROADCAST_BG_TIMEOUT = 60*1000;
+
+    // How long we wait until we timeout on key dispatching.
+    static final int KEY_DISPATCHING_TIMEOUT = 5*1000;
+
+    // How long we wait until we timeout on key dispatching during instrumentation.
+    static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT = 60*1000;
+
+    // Amount of time we wait for observers to handle a user switch before
+    // giving up on them and unfreezing the screen.
+    static final int USER_SWITCH_TIMEOUT = 2*1000;
+
+    // Maximum number of users we allow to be running at a time.
+    static final int MAX_RUNNING_USERS = 3;
+
+    // How long to wait in getAssistContextExtras for the activity and foreground services
+    // to respond with the result.
+    static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500;
+
+    // Maximum number of persisted Uri grants a package is allowed
+    static final int MAX_PERSISTED_URI_GRANTS = 128;
+
+    static final int MY_PID = Process.myPid();
+
+    static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+    // How many bytes to write into the dropbox log before truncating
+    static final int DROPBOX_MAX_SIZE = 256 * 1024;
+
+    /** Run all ActivityStacks through this */
+    ActivityStackSupervisor mStackSupervisor;
+
+    public IntentFirewall mIntentFirewall;
+
+    // Whether we should show our dialogs (ANR, crash, etc) or just perform their
+    // default actuion automatically.  Important for devices without direct input
+    // devices.
+    private boolean mShowDialogs = true;
+
+    /**
+     * Description of a request to start a new activity, which has been held
+     * due to app switches being disabled.
+     */
+    static class PendingActivityLaunch {
+        final ActivityRecord r;
+        final ActivityRecord sourceRecord;
+        final int startFlags;
+        final ActivityStack stack;
+
+        PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord,
+                int _startFlags, ActivityStack _stack) {
+            r = _r;
+            sourceRecord = _sourceRecord;
+            startFlags = _startFlags;
+            stack = _stack;
+        }
+    }
+
+    final ArrayList<PendingActivityLaunch> mPendingActivityLaunches
+            = new ArrayList<PendingActivityLaunch>();
+
+    BroadcastQueue mFgBroadcastQueue;
+    BroadcastQueue mBgBroadcastQueue;
+    // Convenient for easy iteration over the queues. Foreground is first
+    // so that dispatch of foreground broadcasts gets precedence.
+    final BroadcastQueue[] mBroadcastQueues = new BroadcastQueue[2];
+
+    BroadcastQueue broadcastQueueForIntent(Intent intent) {
+        final boolean isFg = (intent.getFlags() & Intent.FLAG_RECEIVER_FOREGROUND) != 0;
+        if (DEBUG_BACKGROUND_BROADCAST) {
+            Slog.i(TAG, "Broadcast intent " + intent + " on "
+                    + (isFg ? "foreground" : "background")
+                    + " queue");
+        }
+        return (isFg) ? mFgBroadcastQueue : mBgBroadcastQueue;
+    }
+
+    BroadcastRecord broadcastRecordForReceiverLocked(IBinder receiver) {
+        for (BroadcastQueue queue : mBroadcastQueues) {
+            BroadcastRecord r = queue.getMatchingOrderedReceiver(receiver);
+            if (r != null) {
+                return r;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Activity we have told the window manager to have key focus.
+     */
+    ActivityRecord mFocusedActivity = null;
+
+    /**
+     * List of intents that were used to start the most recent tasks.
+     */
+    private final ArrayList<TaskRecord> mRecentTasks = new ArrayList<TaskRecord>();
+
+    public class PendingAssistExtras extends Binder implements Runnable {
+        public final ActivityRecord activity;
+        public boolean haveResult = false;
+        public Bundle result = null;
+        public PendingAssistExtras(ActivityRecord _activity) {
+            activity = _activity;
+        }
+        @Override
+        public void run() {
+            Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity);
+            synchronized (this) {
+                haveResult = true;
+                notifyAll();
+            }
+        }
+    }
+
+    final ArrayList<PendingAssistExtras> mPendingAssistExtras
+            = new ArrayList<PendingAssistExtras>();
+
+    /**
+     * Process management.
+     */
+    final ProcessList mProcessList = new ProcessList();
+
+    /**
+     * All of the applications we currently have running organized by name.
+     * The keys are strings of the application package name (as
+     * returned by the package manager), and the keys are ApplicationRecord
+     * objects.
+     */
+    final ProcessMap<ProcessRecord> mProcessNames = new ProcessMap<ProcessRecord>();
+
+    /**
+     * Tracking long-term execution of processes to look for abuse and other
+     * bad app behavior.
+     */
+    final ProcessStatsService mProcessStats;
+
+    /**
+     * The currently running isolated processes.
+     */
+    final SparseArray<ProcessRecord> mIsolatedProcesses = new SparseArray<ProcessRecord>();
+
+    /**
+     * Counter for assigning isolated process uids, to avoid frequently reusing the
+     * same ones.
+     */
+    int mNextIsolatedProcessUid = 0;
+
+    /**
+     * The currently running heavy-weight process, if any.
+     */
+    ProcessRecord mHeavyWeightProcess = null;
+
+    /**
+     * The last time that various processes have crashed.
+     */
+    final ProcessMap<Long> mProcessCrashTimes = new ProcessMap<Long>();
+
+    /**
+     * Information about a process that is currently marked as bad.
+     */
+    static final class BadProcessInfo {
+        BadProcessInfo(long time, String shortMsg, String longMsg, String stack) {
+            this.time = time;
+            this.shortMsg = shortMsg;
+            this.longMsg = longMsg;
+            this.stack = stack;
+        }
+
+        final long time;
+        final String shortMsg;
+        final String longMsg;
+        final String stack;
+    }
+
+    /**
+     * Set of applications that we consider to be bad, and will reject
+     * incoming broadcasts from (which the user has no control over).
+     * Processes are added to this set when they have crashed twice within
+     * a minimum amount of time; they are removed from it when they are
+     * later restarted (hopefully due to some user action).  The value is the
+     * time it was added to the list.
+     */
+    final ProcessMap<BadProcessInfo> mBadProcesses = new ProcessMap<BadProcessInfo>();
+
+    /**
+     * All of the processes we currently have running organized by pid.
+     * The keys are the pid running the application.
+     *
+     * <p>NOTE: This object is protected by its own lock, NOT the global
+     * activity manager lock!
+     */
+    final SparseArray<ProcessRecord> mPidsSelfLocked = new SparseArray<ProcessRecord>();
+
+    /**
+     * All of the processes that have been forced to be foreground.  The key
+     * is the pid of the caller who requested it (we hold a death
+     * link on it).
+     */
+    abstract class ForegroundToken implements IBinder.DeathRecipient {
+        int pid;
+        IBinder token;
+    }
+    final SparseArray<ForegroundToken> mForegroundProcesses = new SparseArray<ForegroundToken>();
+
+    /**
+     * List of records for processes that someone had tried to start before the
+     * system was ready.  We don't start them at that point, but ensure they
+     * are started by the time booting is complete.
+     */
+    final ArrayList<ProcessRecord> mProcessesOnHold = new ArrayList<ProcessRecord>();
+
+    /**
+     * List of persistent applications that are in the process
+     * of being started.
+     */
+    final ArrayList<ProcessRecord> mPersistentStartingProcesses = new ArrayList<ProcessRecord>();
+
+    /**
+     * Processes that are being forcibly torn down.
+     */
+    final ArrayList<ProcessRecord> mRemovedProcesses = new ArrayList<ProcessRecord>();
+
+    /**
+     * List of running applications, sorted by recent usage.
+     * The first entry in the list is the least recently used.
+     */
+    final ArrayList<ProcessRecord> mLruProcesses = new ArrayList<ProcessRecord>();
+
+    /**
+     * Where in mLruProcesses that the processes hosting activities start.
+     */
+    int mLruProcessActivityStart = 0;
+
+    /**
+     * Where in mLruProcesses that the processes hosting services start.
+     * This is after (lower index) than mLruProcessesActivityStart.
+     */
+    int mLruProcessServiceStart = 0;
+
+    /**
+     * List of processes that should gc as soon as things are idle.
+     */
+    final ArrayList<ProcessRecord> mProcessesToGc = new ArrayList<ProcessRecord>();
+
+    /**
+     * Processes we want to collect PSS data from.
+     */
+    final ArrayList<ProcessRecord> mPendingPssProcesses = new ArrayList<ProcessRecord>();
+
+    /**
+     * Last time we requested PSS data of all processes.
+     */
+    long mLastFullPssTime = SystemClock.uptimeMillis();
+
+    /**
+     * This is the process holding what we currently consider to be
+     * the "home" activity.
+     */
+    ProcessRecord mHomeProcess;
+
+    /**
+     * This is the process holding the activity the user last visited that
+     * is in a different process from the one they are currently in.
+     */
+    ProcessRecord mPreviousProcess;
+
+    /**
+     * The time at which the previous process was last visible.
+     */
+    long mPreviousProcessVisibleTime;
+
+    /**
+     * Which uses have been started, so are allowed to run code.
+     */
+    final SparseArray<UserStartedState> mStartedUsers = new SparseArray<UserStartedState>();
+
+    /**
+     * LRU list of history of current users.  Most recently current is at the end.
+     */
+    final ArrayList<Integer> mUserLru = new ArrayList<Integer>();
+
+    /**
+     * Constant array of the users that are currently started.
+     */
+    int[] mStartedUserArray = new int[] { 0 };
+
+    /**
+     * Registered observers of the user switching mechanics.
+     */
+    final RemoteCallbackList<IUserSwitchObserver> mUserSwitchObservers
+            = new RemoteCallbackList<IUserSwitchObserver>();
+
+    /**
+     * Currently active user switch.
+     */
+    Object mCurUserSwitchCallback;
+
+    /**
+     * Packages that the user has asked to have run in screen size
+     * compatibility mode instead of filling the screen.
+     */
+    final CompatModePackages mCompatModePackages;
+
+    /**
+     * Set of IntentSenderRecord objects that are currently active.
+     */
+    final HashMap<PendingIntentRecord.Key, WeakReference<PendingIntentRecord>> mIntentSenderRecords
+            = new HashMap<PendingIntentRecord.Key, WeakReference<PendingIntentRecord>>();
+
+    /**
+     * Fingerprints (hashCode()) of stack traces that we've
+     * already logged DropBox entries for.  Guarded by itself.  If
+     * something (rogue user app) forces this over
+     * MAX_DUP_SUPPRESSED_STACKS entries, the contents are cleared.
+     */
+    private final HashSet<Integer> mAlreadyLoggedViolatedStacks = new HashSet<Integer>();
+    private static final int MAX_DUP_SUPPRESSED_STACKS = 5000;
+
+    /**
+     * Strict Mode background batched logging state.
+     *
+     * The string buffer is guarded by itself, and its lock is also
+     * used to determine if another batched write is already
+     * in-flight.
+     */
+    private final StringBuilder mStrictModeBuffer = new StringBuilder();
+
+    /**
+     * Keeps track of all IIntentReceivers that have been registered for
+     * broadcasts.  Hash keys are the receiver IBinder, hash value is
+     * a ReceiverList.
+     */
+    final HashMap<IBinder, ReceiverList> mRegisteredReceivers =
+            new HashMap<IBinder, ReceiverList>();
+
+    /**
+     * Resolver for broadcast intents to registered receivers.
+     * Holds BroadcastFilter (subclass of IntentFilter).
+     */
+    final IntentResolver<BroadcastFilter, BroadcastFilter> mReceiverResolver
+            = new IntentResolver<BroadcastFilter, BroadcastFilter>() {
+        @Override
+        protected boolean allowFilterResult(
+                BroadcastFilter filter, List<BroadcastFilter> dest) {
+            IBinder target = filter.receiverList.receiver.asBinder();
+            for (int i=dest.size()-1; i>=0; i--) {
+                if (dest.get(i).receiverList.receiver.asBinder() == target) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        @Override
+        protected BroadcastFilter newResult(BroadcastFilter filter, int match, int userId) {
+            if (userId == UserHandle.USER_ALL || filter.owningUserId == UserHandle.USER_ALL
+                    || userId == filter.owningUserId) {
+                return super.newResult(filter, match, userId);
+            }
+            return null;
+        }
+
+        @Override
+        protected BroadcastFilter[] newArray(int size) {
+            return new BroadcastFilter[size];
+        }
+
+        @Override
+        protected boolean isPackageForFilter(String packageName, BroadcastFilter filter) {
+            return packageName.equals(filter.packageName);
+        }
+    };
+
+    /**
+     * State of all active sticky broadcasts per user.  Keys are the action of the
+     * sticky Intent, values are an ArrayList of all broadcasted intents with
+     * that action (which should usually be one).  The SparseArray is keyed
+     * by the user ID the sticky is for, and can include UserHandle.USER_ALL
+     * for stickies that are sent to all users.
+     */
+    final SparseArray<ArrayMap<String, ArrayList<Intent>>> mStickyBroadcasts =
+            new SparseArray<ArrayMap<String, ArrayList<Intent>>>();
+
+    final ActiveServices mServices;
+
+    /**
+     * Backup/restore process management
+     */
+    String mBackupAppName = null;
+    BackupRecord mBackupTarget = null;
+
+    /**
+     * List of PendingThumbnailsRecord objects of clients who are still
+     * waiting to receive all of the thumbnails for a task.
+     */
+    final ArrayList<PendingThumbnailsRecord> mPendingThumbnails =
+            new ArrayList<PendingThumbnailsRecord>();
+
+    final ProviderMap mProviderMap;
+
+    /**
+     * List of content providers who have clients waiting for them.  The
+     * application is currently being launched and the provider will be
+     * removed from this list once it is published.
+     */
+    final ArrayList<ContentProviderRecord> mLaunchingProviders
+            = new ArrayList<ContentProviderRecord>();
+
+    /**
+     * File storing persisted {@link #mGrantedUriPermissions}.
+     */
+    private final AtomicFile mGrantFile;
+
+    /** XML constants used in {@link #mGrantFile} */
+    private static final String TAG_URI_GRANTS = "uri-grants";
+    private static final String TAG_URI_GRANT = "uri-grant";
+    private static final String ATTR_USER_HANDLE = "userHandle";
+    private static final String ATTR_SOURCE_PKG = "sourcePkg";
+    private static final String ATTR_TARGET_PKG = "targetPkg";
+    private static final String ATTR_URI = "uri";
+    private static final String ATTR_MODE_FLAGS = "modeFlags";
+    private static final String ATTR_CREATED_TIME = "createdTime";
+
+    /**
+     * Global set of specific {@link Uri} permissions that have been granted.
+     * This optimized lookup structure maps from {@link UriPermission#targetUid}
+     * to {@link UriPermission#uri} to {@link UriPermission}.
+     */
+    @GuardedBy("this")
+    private final SparseArray<ArrayMap<Uri, UriPermission>>
+            mGrantedUriPermissions = new SparseArray<ArrayMap<Uri, UriPermission>>();
+
+    CoreSettingsObserver mCoreSettingsObserver;
+
+    /**
+     * Thread-local storage used to carry caller permissions over through
+     * indirect content-provider access.
+     */
+    private class Identity {
+        public int pid;
+        public int uid;
+
+        Identity(int _pid, int _uid) {
+            pid = _pid;
+            uid = _uid;
+        }
+    }
+
+    private static final ThreadLocal<Identity> sCallerIdentity = new ThreadLocal<Identity>();
+
+    /**
+     * All information we have collected about the runtime performance of
+     * any user id that can impact battery performance.
+     */
+    final BatteryStatsService mBatteryStatsService;
+
+    /**
+     * Information about component usage
+     */
+    final UsageStatsService mUsageStatsService;
+
+    /**
+     * Information about and control over application operations
+     */
+    final AppOpsService mAppOpsService;
+
+    /**
+     * Current configuration information.  HistoryRecord objects are given
+     * a reference to this object to indicate which configuration they are
+     * currently running in, so this object must be kept immutable.
+     */
+    Configuration mConfiguration = new Configuration();
+
+    /**
+     * Current sequencing integer of the configuration, for skipping old
+     * configurations.
+     */
+    int mConfigurationSeq = 0;
+
+    /**
+     * Hardware-reported OpenGLES version.
+     */
+    final int GL_ES_VERSION;
+
+    /**
+     * List of initialization arguments to pass to all processes when binding applications to them.
+     * For example, references to the commonly used services.
+     */
+    HashMap<String, IBinder> mAppBindArgs;
+
+    /**
+     * Temporary to avoid allocations.  Protected by main lock.
+     */
+    final StringBuilder mStringBuilder = new StringBuilder(256);
+
+    /**
+     * Used to control how we initialize the service.
+     */
+    boolean mStartRunning = false;
+    ComponentName mTopComponent;
+    String mTopAction;
+    String mTopData;
+    boolean mProcessesReady = false;
+    boolean mSystemReady = false;
+    boolean mBooting = false;
+    boolean mWaitingUpdate = false;
+    boolean mDidUpdate = false;
+    boolean mOnBattery = false;
+    boolean mLaunchWarningShown = false;
+
+    Context mContext;
+
+    int mFactoryTest;
+
+    boolean mCheckedForSetup;
+
+    /**
+     * The time at which we will allow normal application switches again,
+     * after a call to {@link #stopAppSwitches()}.
+     */
+    long mAppSwitchesAllowedTime;
+
+    /**
+     * This is set to true after the first switch after mAppSwitchesAllowedTime
+     * is set; any switches after that will clear the time.
+     */
+    boolean mDidAppSwitch;
+
+    /**
+     * Last time (in realtime) at which we checked for power usage.
+     */
+    long mLastPowerCheckRealtime;
+
+    /**
+     * Last time (in uptime) at which we checked for power usage.
+     */
+    long mLastPowerCheckUptime;
+
+    /**
+     * Set while we are wanting to sleep, to prevent any
+     * activities from being started/resumed.
+     */
+    boolean mSleeping = false;
+
+    /**
+     * State of external calls telling us if the device is asleep.
+     */
+    boolean mWentToSleep = false;
+
+    /**
+     * State of external call telling us if the lock screen is shown.
+     */
+    boolean mLockScreenShown = false;
+
+    /**
+     * Set if we are shutting down the system, similar to sleeping.
+     */
+    boolean mShuttingDown = false;
+
+    /**
+     * Current sequence id for oom_adj computation traversal.
+     */
+    int mAdjSeq = 0;
+
+    /**
+     * Current sequence id for process LRU updating.
+     */
+    int mLruSeq = 0;
+
+    /**
+     * Keep track of the non-cached/empty process we last found, to help
+     * determine how to distribute cached/empty processes next time.
+     */
+    int mNumNonCachedProcs = 0;
+
+    /**
+     * Keep track of the number of cached hidden procs, to balance oom adj
+     * distribution between those and empty procs.
+     */
+    int mNumCachedHiddenProcs = 0;
+
+    /**
+     * Keep track of the number of service processes we last found, to
+     * determine on the next iteration which should be B services.
+     */
+    int mNumServiceProcs = 0;
+    int mNewNumAServiceProcs = 0;
+    int mNewNumServiceProcs = 0;
+
+    /**
+     * Allow the current computed overall memory level of the system to go down?
+     * This is set to false when we are killing processes for reasons other than
+     * memory management, so that the now smaller process list will not be taken as
+     * an indication that memory is tighter.
+     */
+    boolean mAllowLowerMemLevel = false;
+
+    /**
+     * The last computed memory level, for holding when we are in a state that
+     * processes are going away for other reasons.
+     */
+    int mLastMemoryLevel = ProcessStats.ADJ_MEM_FACTOR_NORMAL;
+
+    /**
+     * The last total number of process we have, to determine if changes actually look
+     * like a shrinking number of process due to lower RAM.
+     */
+    int mLastNumProcesses;
+
+    /**
+     * The uptime of the last time we performed idle maintenance.
+     */
+    long mLastIdleTime = SystemClock.uptimeMillis();
+
+    /**
+     * Total time spent with RAM that has been added in the past since the last idle time.
+     */
+    long mLowRamTimeSinceLastIdle = 0;
+
+    /**
+     * If RAM is currently low, when that horrible situatin started.
+     */
+    long mLowRamStartTime = 0;
+
+    /**
+     * This is set if we had to do a delayed dexopt of an app before launching
+     * it, to increasing the ANR timeouts in that case.
+     */
+    boolean mDidDexOpt;
+
+    String mDebugApp = null;
+    boolean mWaitForDebugger = false;
+    boolean mDebugTransient = false;
+    String mOrigDebugApp = null;
+    boolean mOrigWaitForDebugger = false;
+    boolean mAlwaysFinishActivities = false;
+    IActivityController mController = null;
+    String mProfileApp = null;
+    ProcessRecord mProfileProc = null;
+    String mProfileFile;
+    ParcelFileDescriptor mProfileFd;
+    int mProfileType = 0;
+    boolean mAutoStopProfiler = false;
+    String mOpenGlTraceApp = null;
+
+    static class ProcessChangeItem {
+        static final int CHANGE_ACTIVITIES = 1<<0;
+        static final int CHANGE_IMPORTANCE= 1<<1;
+        int changes;
+        int uid;
+        int pid;
+        int importance;
+        boolean foregroundActivities;
+    }
+
+    final RemoteCallbackList<IProcessObserver> mProcessObservers
+            = new RemoteCallbackList<IProcessObserver>();
+    ProcessChangeItem[] mActiveProcessChanges = new ProcessChangeItem[5];
+
+    final ArrayList<ProcessChangeItem> mPendingProcessChanges
+            = new ArrayList<ProcessChangeItem>();
+    final ArrayList<ProcessChangeItem> mAvailProcessChanges
+            = new ArrayList<ProcessChangeItem>();
+
+    /**
+     * Runtime CPU use collection thread.  This object's lock is used to
+     * protect all related state.
+     */
+    final Thread mProcessCpuThread;
+
+    /**
+     * Used to collect process stats when showing not responding dialog.
+     * Protected by mProcessCpuThread.
+     */
+    final ProcessCpuTracker mProcessCpuTracker = new ProcessCpuTracker(
+            MONITOR_THREAD_CPU_USAGE);
+    final AtomicLong mLastCpuTime = new AtomicLong(0);
+    final AtomicBoolean mProcessCpuMutexFree = new AtomicBoolean(true);
+
+    long mLastWriteTime = 0;
+
+    /**
+     * Used to retain an update lock when the foreground activity is in
+     * immersive mode.
+     */
+    final UpdateLock mUpdateLock = new UpdateLock("immersive");
+
+    /**
+     * Set to true after the system has finished booting.
+     */
+    boolean mBooted = false;
+
+    int mProcessLimit = ProcessList.MAX_CACHED_APPS;
+    int mProcessLimitOverride = -1;
+
+    WindowManagerService mWindowManager;
+
+    final ActivityThread mSystemThread;
+
+    int mCurrentUserId = 0;
+    private UserManagerService mUserManager;
+
+    private final class AppDeathRecipient implements IBinder.DeathRecipient {
+        final ProcessRecord mApp;
+        final int mPid;
+        final IApplicationThread mAppThread;
+
+        AppDeathRecipient(ProcessRecord app, int pid,
+                IApplicationThread thread) {
+            if (localLOGV) Slog.v(
+                TAG, "New death recipient " + this
+                + " for thread " + thread.asBinder());
+            mApp = app;
+            mPid = pid;
+            mAppThread = thread;
+        }
+
+        @Override
+        public void binderDied() {
+            if (localLOGV) Slog.v(
+                TAG, "Death received in " + this
+                + " for thread " + mAppThread.asBinder());
+            synchronized(ActivityManagerService.this) {
+                appDiedLocked(mApp, mPid, mAppThread);
+            }
+        }
+    }
+
+    static final int SHOW_ERROR_MSG = 1;
+    static final int SHOW_NOT_RESPONDING_MSG = 2;
+    static final int SHOW_FACTORY_ERROR_MSG = 3;
+    static final int UPDATE_CONFIGURATION_MSG = 4;
+    static final int GC_BACKGROUND_PROCESSES_MSG = 5;
+    static final int WAIT_FOR_DEBUGGER_MSG = 6;
+    static final int SERVICE_TIMEOUT_MSG = 12;
+    static final int UPDATE_TIME_ZONE = 13;
+    static final int SHOW_UID_ERROR_MSG = 14;
+    static final int IM_FEELING_LUCKY_MSG = 15;
+    static final int PROC_START_TIMEOUT_MSG = 20;
+    static final int DO_PENDING_ACTIVITY_LAUNCHES_MSG = 21;
+    static final int KILL_APPLICATION_MSG = 22;
+    static final int FINALIZE_PENDING_INTENT_MSG = 23;
+    static final int POST_HEAVY_NOTIFICATION_MSG = 24;
+    static final int CANCEL_HEAVY_NOTIFICATION_MSG = 25;
+    static final int SHOW_STRICT_MODE_VIOLATION_MSG = 26;
+    static final int CHECK_EXCESSIVE_WAKE_LOCKS_MSG = 27;
+    static final int CLEAR_DNS_CACHE_MSG = 28;
+    static final int UPDATE_HTTP_PROXY_MSG = 29;
+    static final int SHOW_COMPAT_MODE_DIALOG_MSG = 30;
+    static final int DISPATCH_PROCESSES_CHANGED = 31;
+    static final int DISPATCH_PROCESS_DIED = 32;
+    static final int REPORT_MEM_USAGE_MSG = 33;
+    static final int REPORT_USER_SWITCH_MSG = 34;
+    static final int CONTINUE_USER_SWITCH_MSG = 35;
+    static final int USER_SWITCH_TIMEOUT_MSG = 36;
+    static final int IMMERSIVE_MODE_LOCK_MSG = 37;
+    static final int PERSIST_URI_GRANTS_MSG = 38;
+    static final int REQUEST_ALL_PSS_MSG = 39;
+
+    static final int FIRST_ACTIVITY_STACK_MSG = 100;
+    static final int FIRST_BROADCAST_QUEUE_MSG = 200;
+    static final int FIRST_COMPAT_MODE_MSG = 300;
+    static final int FIRST_SUPERVISOR_STACK_MSG = 100;
+
+    AlertDialog mUidAlert;
+    CompatModeDialog mCompatModeDialog;
+    long mLastMemUsageReportTime = 0;
+
+    /**
+     * Flag whether the current user is a "monkey", i.e. whether
+     * the UI is driven by a UI automation tool.
+     */
+    private boolean mUserIsMonkey;
+
+    final ServiceThread mHandlerThread;
+    final MainHandler mHandler;
+
+    final class MainHandler extends Handler {
+        public MainHandler(Looper looper) {
+            super(looper, null, true);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+            case SHOW_ERROR_MSG: {
+                HashMap<String, Object> data = (HashMap<String, Object>) msg.obj;
+                boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
+                        Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
+                synchronized (ActivityManagerService.this) {
+                    ProcessRecord proc = (ProcessRecord)data.get("app");
+                    AppErrorResult res = (AppErrorResult) data.get("result");
+                    if (proc != null && proc.crashDialog != null) {
+                        Slog.e(TAG, "App already has crash dialog: " + proc);
+                        if (res != null) {
+                            res.set(0);
+                        }
+                        return;
+                    }
+                    if (!showBackground && UserHandle.getAppId(proc.uid)
+                            >= Process.FIRST_APPLICATION_UID && proc.userId != mCurrentUserId
+                            && proc.pid != MY_PID) {
+                        Slog.w(TAG, "Skipping crash dialog of " + proc + ": background");
+                        if (res != null) {
+                            res.set(0);
+                        }
+                        return;
+                    }
+                    if (mShowDialogs && !mSleeping && !mShuttingDown) {
+                        Dialog d = new AppErrorDialog(mContext,
+                                ActivityManagerService.this, res, proc);
+                        d.show();
+                        proc.crashDialog = d;
+                    } else {
+                        // The device is asleep, so just pretend that the user
+                        // saw a crash dialog and hit "force quit".
+                        if (res != null) {
+                            res.set(0);
+                        }
+                    }
+                }
+
+                ensureBootCompleted();
+            } break;
+            case SHOW_NOT_RESPONDING_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    HashMap<String, Object> data = (HashMap<String, Object>) msg.obj;
+                    ProcessRecord proc = (ProcessRecord)data.get("app");
+                    if (proc != null && proc.anrDialog != null) {
+                        Slog.e(TAG, "App already has anr dialog: " + proc);
+                        return;
+                    }
+
+                    Intent intent = new Intent("android.intent.action.ANR");
+                    if (!mProcessesReady) {
+                        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                                | Intent.FLAG_RECEIVER_FOREGROUND);
+                    }
+                    broadcastIntentLocked(null, null, intent,
+                            null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                            false, false, MY_PID, Process.SYSTEM_UID, 0 /* TODO: Verify */);
+
+                    if (mShowDialogs) {
+                        Dialog d = new AppNotRespondingDialog(ActivityManagerService.this,
+                                mContext, proc, (ActivityRecord)data.get("activity"),
+                                msg.arg1 != 0);
+                        d.show();
+                        proc.anrDialog = d;
+                    } else {
+                        // Just kill the app if there is no dialog to be shown.
+                        killAppAtUsersRequest(proc, null);
+                    }
+                }
+
+                ensureBootCompleted();
+            } break;
+            case SHOW_STRICT_MODE_VIOLATION_MSG: {
+                HashMap<String, Object> data = (HashMap<String, Object>) msg.obj;
+                synchronized (ActivityManagerService.this) {
+                    ProcessRecord proc = (ProcessRecord) data.get("app");
+                    if (proc == null) {
+                        Slog.e(TAG, "App not found when showing strict mode dialog.");
+                        break;
+                    }
+                    if (proc.crashDialog != null) {
+                        Slog.e(TAG, "App already has strict mode dialog: " + proc);
+                        return;
+                    }
+                    AppErrorResult res = (AppErrorResult) data.get("result");
+                    if (mShowDialogs && !mSleeping && !mShuttingDown) {
+                        Dialog d = new StrictModeViolationDialog(mContext,
+                                ActivityManagerService.this, res, proc);
+                        d.show();
+                        proc.crashDialog = d;
+                    } else {
+                        // The device is asleep, so just pretend that the user
+                        // saw a crash dialog and hit "force quit".
+                        res.set(0);
+                    }
+                }
+                ensureBootCompleted();
+            } break;
+            case SHOW_FACTORY_ERROR_MSG: {
+                Dialog d = new FactoryErrorDialog(
+                    mContext, msg.getData().getCharSequence("msg"));
+                d.show();
+                ensureBootCompleted();
+            } break;
+            case UPDATE_CONFIGURATION_MSG: {
+                final ContentResolver resolver = mContext.getContentResolver();
+                Settings.System.putConfiguration(resolver, (Configuration)msg.obj);
+            } break;
+            case GC_BACKGROUND_PROCESSES_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    performAppGcsIfAppropriateLocked();
+                }
+            } break;
+            case WAIT_FOR_DEBUGGER_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    ProcessRecord app = (ProcessRecord)msg.obj;
+                    if (msg.arg1 != 0) {
+                        if (!app.waitedForDebugger) {
+                            Dialog d = new AppWaitingForDebuggerDialog(
+                                    ActivityManagerService.this,
+                                    mContext, app);
+                            app.waitDialog = d;
+                            app.waitedForDebugger = true;
+                            d.show();
+                        }
+                    } else {
+                        if (app.waitDialog != null) {
+                            app.waitDialog.dismiss();
+                            app.waitDialog = null;
+                        }
+                    }
+                }
+            } break;
+            case SERVICE_TIMEOUT_MSG: {
+                if (mDidDexOpt) {
+                    mDidDexOpt = false;
+                    Message nmsg = mHandler.obtainMessage(SERVICE_TIMEOUT_MSG);
+                    nmsg.obj = msg.obj;
+                    mHandler.sendMessageDelayed(nmsg, ActiveServices.SERVICE_TIMEOUT);
+                    return;
+                }
+                mServices.serviceTimeout((ProcessRecord)msg.obj);
+            } break;
+            case UPDATE_TIME_ZONE: {
+                synchronized (ActivityManagerService.this) {
+                    for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
+                        ProcessRecord r = mLruProcesses.get(i);
+                        if (r.thread != null) {
+                            try {
+                                r.thread.updateTimeZone();
+                            } catch (RemoteException ex) {
+                                Slog.w(TAG, "Failed to update time zone for: " + r.info.processName);
+                            }
+                        }
+                    }
+                }
+            } break;
+            case CLEAR_DNS_CACHE_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
+                        ProcessRecord r = mLruProcesses.get(i);
+                        if (r.thread != null) {
+                            try {
+                                r.thread.clearDnsCache();
+                            } catch (RemoteException ex) {
+                                Slog.w(TAG, "Failed to clear dns cache for: " + r.info.processName);
+                            }
+                        }
+                    }
+                }
+            } break;
+            case UPDATE_HTTP_PROXY_MSG: {
+                ProxyProperties proxy = (ProxyProperties)msg.obj;
+                String host = "";
+                String port = "";
+                String exclList = "";
+                String pacFileUrl = null;
+                if (proxy != null) {
+                    host = proxy.getHost();
+                    port = Integer.toString(proxy.getPort());
+                    exclList = proxy.getExclusionList();
+                    pacFileUrl = proxy.getPacFileUrl();
+                }
+                synchronized (ActivityManagerService.this) {
+                    for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
+                        ProcessRecord r = mLruProcesses.get(i);
+                        if (r.thread != null) {
+                            try {
+                                r.thread.setHttpProxy(host, port, exclList, pacFileUrl);
+                            } catch (RemoteException ex) {
+                                Slog.w(TAG, "Failed to update http proxy for: " +
+                                        r.info.processName);
+                            }
+                        }
+                    }
+                }
+            } break;
+            case SHOW_UID_ERROR_MSG: {
+                String title = "System UIDs Inconsistent";
+                String text = "UIDs on the system are inconsistent, you need to wipe your"
+                        + " data partition or your device will be unstable.";
+                Log.e(TAG, title + ": " + text);
+                if (mShowDialogs) {
+                    // XXX This is a temporary dialog, no need to localize.
+                    AlertDialog d = new BaseErrorDialog(mContext);
+                    d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
+                    d.setCancelable(false);
+                    d.setTitle(title);
+                    d.setMessage(text);
+                    d.setButton(DialogInterface.BUTTON_POSITIVE, "I'm Feeling Lucky",
+                            mHandler.obtainMessage(IM_FEELING_LUCKY_MSG));
+                    mUidAlert = d;
+                    d.show();
+                }
+            } break;
+            case IM_FEELING_LUCKY_MSG: {
+                if (mUidAlert != null) {
+                    mUidAlert.dismiss();
+                    mUidAlert = null;
+                }
+            } break;
+            case PROC_START_TIMEOUT_MSG: {
+                if (mDidDexOpt) {
+                    mDidDexOpt = false;
+                    Message nmsg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
+                    nmsg.obj = msg.obj;
+                    mHandler.sendMessageDelayed(nmsg, PROC_START_TIMEOUT);
+                    return;
+                }
+                ProcessRecord app = (ProcessRecord)msg.obj;
+                synchronized (ActivityManagerService.this) {
+                    processStartTimedOutLocked(app);
+                }
+            } break;
+            case DO_PENDING_ACTIVITY_LAUNCHES_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    doPendingActivityLaunchesLocked(true);
+                }
+            } break;
+            case KILL_APPLICATION_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    int appid = msg.arg1;
+                    boolean restart = (msg.arg2 == 1);
+                    Bundle bundle = (Bundle)msg.obj;
+                    String pkg = bundle.getString("pkg");
+                    String reason = bundle.getString("reason");
+                    forceStopPackageLocked(pkg, appid, restart, false, true, false,
+                            UserHandle.USER_ALL, reason);
+                }
+            } break;
+            case FINALIZE_PENDING_INTENT_MSG: {
+                ((PendingIntentRecord)msg.obj).completeFinalize();
+            } break;
+            case POST_HEAVY_NOTIFICATION_MSG: {
+                INotificationManager inm = NotificationManager.getService();
+                if (inm == null) {
+                    return;
+                }
+
+                ActivityRecord root = (ActivityRecord)msg.obj;
+                ProcessRecord process = root.app;
+                if (process == null) {
+                    return;
+                }
+
+                try {
+                    Context context = mContext.createPackageContext(process.info.packageName, 0);
+                    String text = mContext.getString(R.string.heavy_weight_notification,
+                            context.getApplicationInfo().loadLabel(context.getPackageManager()));
+                    Notification notification = new Notification();
+                    notification.icon = com.android.internal.R.drawable.stat_sys_adb; //context.getApplicationInfo().icon;
+                    notification.when = 0;
+                    notification.flags = Notification.FLAG_ONGOING_EVENT;
+                    notification.tickerText = text;
+                    notification.defaults = 0; // please be quiet
+                    notification.sound = null;
+                    notification.vibrate = null;
+                    notification.setLatestEventInfo(context, text,
+                            mContext.getText(R.string.heavy_weight_notification_detail),
+                            PendingIntent.getActivityAsUser(mContext, 0, root.intent,
+                                    PendingIntent.FLAG_CANCEL_CURRENT, null,
+                                    new UserHandle(root.userId)));
+
+                    try {
+                        int[] outId = new int[1];
+                        inm.enqueueNotificationWithTag("android", "android", null,
+                                R.string.heavy_weight_notification,
+                                notification, outId, root.userId);
+                    } catch (RuntimeException e) {
+                        Slog.w(ActivityManagerService.TAG,
+                                "Error showing notification for heavy-weight app", e);
+                    } catch (RemoteException e) {
+                    }
+                } catch (NameNotFoundException e) {
+                    Slog.w(TAG, "Unable to create context for heavy notification", e);
+                }
+            } break;
+            case CANCEL_HEAVY_NOTIFICATION_MSG: {
+                INotificationManager inm = NotificationManager.getService();
+                if (inm == null) {
+                    return;
+                }
+                try {
+                    inm.cancelNotificationWithTag("android", null,
+                            R.string.heavy_weight_notification,  msg.arg1);
+                } catch (RuntimeException e) {
+                    Slog.w(ActivityManagerService.TAG,
+                            "Error canceling notification for service", e);
+                } catch (RemoteException e) {
+                }
+            } break;
+            case CHECK_EXCESSIVE_WAKE_LOCKS_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    checkExcessivePowerUsageLocked(true);
+                    removeMessages(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
+                    Message nmsg = obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
+                    sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
+                }
+            } break;
+            case SHOW_COMPAT_MODE_DIALOG_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    ActivityRecord ar = (ActivityRecord)msg.obj;
+                    if (mCompatModeDialog != null) {
+                        if (mCompatModeDialog.mAppInfo.packageName.equals(
+                                ar.info.applicationInfo.packageName)) {
+                            return;
+                        }
+                        mCompatModeDialog.dismiss();
+                        mCompatModeDialog = null;
+                    }
+                    if (ar != null && false) {
+                        if (mCompatModePackages.getPackageAskCompatModeLocked(
+                                ar.packageName)) {
+                            int mode = mCompatModePackages.computeCompatModeLocked(
+                                    ar.info.applicationInfo);
+                            if (mode == ActivityManager.COMPAT_MODE_DISABLED
+                                    || mode == ActivityManager.COMPAT_MODE_ENABLED) {
+                                mCompatModeDialog = new CompatModeDialog(
+                                        ActivityManagerService.this, mContext,
+                                        ar.info.applicationInfo);
+                                mCompatModeDialog.show();
+                            }
+                        }
+                    }
+                }
+                break;
+            }
+            case DISPATCH_PROCESSES_CHANGED: {
+                dispatchProcessesChanged();
+                break;
+            }
+            case DISPATCH_PROCESS_DIED: {
+                final int pid = msg.arg1;
+                final int uid = msg.arg2;
+                dispatchProcessDied(pid, uid);
+                break;
+            }
+            case REPORT_MEM_USAGE_MSG: {
+                final ArrayList<ProcessMemInfo> memInfos = (ArrayList<ProcessMemInfo>)msg.obj;
+                Thread thread = new Thread() {
+                    @Override public void run() {
+                        final SparseArray<ProcessMemInfo> infoMap
+                                = new SparseArray<ProcessMemInfo>(memInfos.size());
+                        for (int i=0, N=memInfos.size(); i<N; i++) {
+                            ProcessMemInfo mi = memInfos.get(i);
+                            infoMap.put(mi.pid, mi);
+                        }
+                        updateCpuStatsNow();
+                        synchronized (mProcessCpuThread) {
+                            final int N = mProcessCpuTracker.countStats();
+                            for (int i=0; i<N; i++) {
+                                ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
+                                if (st.vsize > 0) {
+                                    long pss = Debug.getPss(st.pid, null);
+                                    if (pss > 0) {
+                                        if (infoMap.indexOfKey(st.pid) < 0) {
+                                            ProcessMemInfo mi = new ProcessMemInfo(st.name, st.pid,
+                                                    ProcessList.NATIVE_ADJ, -1, "native", null);
+                                            mi.pss = pss;
+                                            memInfos.add(mi);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+
+                        long totalPss = 0;
+                        for (int i=0, N=memInfos.size(); i<N; i++) {
+                            ProcessMemInfo mi = memInfos.get(i);
+                            if (mi.pss == 0) {
+                                mi.pss = Debug.getPss(mi.pid, null);
+                            }
+                            totalPss += mi.pss;
+                        }
+                        Collections.sort(memInfos, new Comparator<ProcessMemInfo>() {
+                            @Override public int compare(ProcessMemInfo lhs, ProcessMemInfo rhs) {
+                                if (lhs.oomAdj != rhs.oomAdj) {
+                                    return lhs.oomAdj < rhs.oomAdj ? -1 : 1;
+                                }
+                                if (lhs.pss != rhs.pss) {
+                                    return lhs.pss < rhs.pss ? 1 : -1;
+                                }
+                                return 0;
+                            }
+                        });
+
+                        StringBuilder tag = new StringBuilder(128);
+                        StringBuilder stack = new StringBuilder(128);
+                        tag.append("Low on memory -- ");
+                        appendMemBucket(tag, totalPss, "total", false);
+                        appendMemBucket(stack, totalPss, "total", true);
+
+                        StringBuilder logBuilder = new StringBuilder(1024);
+                        logBuilder.append("Low on memory:\n");
+
+                        boolean firstLine = true;
+                        int lastOomAdj = Integer.MIN_VALUE;
+                        for (int i=0, N=memInfos.size(); i<N; i++) {
+                            ProcessMemInfo mi = memInfos.get(i);
+
+                            if (mi.oomAdj != ProcessList.NATIVE_ADJ
+                                    && (mi.oomAdj < ProcessList.SERVICE_ADJ
+                                            || mi.oomAdj == ProcessList.HOME_APP_ADJ
+                                            || mi.oomAdj == ProcessList.PREVIOUS_APP_ADJ)) {
+                                if (lastOomAdj != mi.oomAdj) {
+                                    lastOomAdj = mi.oomAdj;
+                                    if (mi.oomAdj <= ProcessList.FOREGROUND_APP_ADJ) {
+                                        tag.append(" / ");
+                                    }
+                                    if (mi.oomAdj >= ProcessList.FOREGROUND_APP_ADJ) {
+                                        if (firstLine) {
+                                            stack.append(":");
+                                            firstLine = false;
+                                        }
+                                        stack.append("\n\t at ");
+                                    } else {
+                                        stack.append("$");
+                                    }
+                                } else {
+                                    tag.append(" ");
+                                    stack.append("$");
+                                }
+                                if (mi.oomAdj <= ProcessList.FOREGROUND_APP_ADJ) {
+                                    appendMemBucket(tag, mi.pss, mi.name, false);
+                                }
+                                appendMemBucket(stack, mi.pss, mi.name, true);
+                                if (mi.oomAdj >= ProcessList.FOREGROUND_APP_ADJ
+                                        && ((i+1) >= N || memInfos.get(i+1).oomAdj != lastOomAdj)) {
+                                    stack.append("(");
+                                    for (int k=0; k<DUMP_MEM_OOM_ADJ.length; k++) {
+                                        if (DUMP_MEM_OOM_ADJ[k] == mi.oomAdj) {
+                                            stack.append(DUMP_MEM_OOM_LABEL[k]);
+                                            stack.append(":");
+                                            stack.append(DUMP_MEM_OOM_ADJ[k]);
+                                        }
+                                    }
+                                    stack.append(")");
+                                }
+                            }
+
+                            logBuilder.append("  ");
+                            logBuilder.append(ProcessList.makeOomAdjString(mi.oomAdj));
+                            logBuilder.append(' ');
+                            logBuilder.append(ProcessList.makeProcStateString(mi.procState));
+                            logBuilder.append(' ');
+                            ProcessList.appendRamKb(logBuilder, mi.pss);
+                            logBuilder.append(" kB: ");
+                            logBuilder.append(mi.name);
+                            logBuilder.append(" (");
+                            logBuilder.append(mi.pid);
+                            logBuilder.append(") ");
+                            logBuilder.append(mi.adjType);
+                            logBuilder.append('\n');
+                            if (mi.adjReason != null) {
+                                logBuilder.append("                      ");
+                                logBuilder.append(mi.adjReason);
+                                logBuilder.append('\n');
+                            }
+                        }
+
+                        logBuilder.append("           ");
+                        ProcessList.appendRamKb(logBuilder, totalPss);
+                        logBuilder.append(" kB: TOTAL\n");
+
+                        long[] infos = new long[Debug.MEMINFO_COUNT];
+                        Debug.getMemInfo(infos);
+                        logBuilder.append("  MemInfo: ");
+                        logBuilder.append(infos[Debug.MEMINFO_SLAB]).append(" kB slab, ");
+                        logBuilder.append(infos[Debug.MEMINFO_SHMEM]).append(" kB shmem, ");
+                        logBuilder.append(infos[Debug.MEMINFO_BUFFERS]).append(" kB buffers, ");
+                        logBuilder.append(infos[Debug.MEMINFO_CACHED]).append(" kB cached, ");
+                        logBuilder.append(infos[Debug.MEMINFO_FREE]).append(" kB free\n");
+                        if (infos[Debug.MEMINFO_ZRAM_TOTAL] != 0) {
+                            logBuilder.append("  ZRAM: ");
+                            logBuilder.append(infos[Debug.MEMINFO_ZRAM_TOTAL]);
+                            logBuilder.append(" kB RAM, ");
+                            logBuilder.append(infos[Debug.MEMINFO_SWAP_TOTAL]);
+                            logBuilder.append(" kB swap total, ");
+                            logBuilder.append(infos[Debug.MEMINFO_SWAP_FREE]);
+                            logBuilder.append(" kB swap free\n");
+                        }
+                        Slog.i(TAG, logBuilder.toString());
+
+                        StringBuilder dropBuilder = new StringBuilder(1024);
+                        /*
+                        StringWriter oomSw = new StringWriter();
+                        PrintWriter oomPw = new FastPrintWriter(oomSw, false, 256);
+                        StringWriter catSw = new StringWriter();
+                        PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
+                        String[] emptyArgs = new String[] { };
+                        dumpApplicationMemoryUsage(null, oomPw, "  ", emptyArgs, true, catPw);
+                        oomPw.flush();
+                        String oomString = oomSw.toString();
+                        */
+                        dropBuilder.append(stack);
+                        dropBuilder.append('\n');
+                        dropBuilder.append('\n');
+                        dropBuilder.append(logBuilder);
+                        dropBuilder.append('\n');
+                        /*
+                        dropBuilder.append(oomString);
+                        dropBuilder.append('\n');
+                        */
+                        StringWriter catSw = new StringWriter();
+                        synchronized (ActivityManagerService.this) {
+                            PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
+                            String[] emptyArgs = new String[] { };
+                            catPw.println();
+                            dumpProcessesLocked(null, catPw, emptyArgs, 0, false, null);
+                            catPw.println();
+                            mServices.dumpServicesLocked(null, catPw, emptyArgs, 0,
+                                    false, false, null);
+                            catPw.println();
+                            dumpActivitiesLocked(null, catPw, emptyArgs, 0, false, false, null);
+                            catPw.flush();
+                        }
+                        dropBuilder.append(catSw.toString());
+                        addErrorToDropBox("lowmem", null, "system_server", null,
+                                null, tag.toString(), dropBuilder.toString(), null, null);
+                        //Slog.i(TAG, "Sent to dropbox:");
+                        //Slog.i(TAG, dropBuilder.toString());
+                        synchronized (ActivityManagerService.this) {
+                            long now = SystemClock.uptimeMillis();
+                            if (mLastMemUsageReportTime < now) {
+                                mLastMemUsageReportTime = now;
+                            }
+                        }
+                    }
+                };
+                thread.start();
+                break;
+            }
+            case REPORT_USER_SWITCH_MSG: {
+                dispatchUserSwitch((UserStartedState)msg.obj, msg.arg1, msg.arg2);
+                break;
+            }
+            case CONTINUE_USER_SWITCH_MSG: {
+                continueUserSwitch((UserStartedState)msg.obj, msg.arg1, msg.arg2);
+                break;
+            }
+            case USER_SWITCH_TIMEOUT_MSG: {
+                timeoutUserSwitch((UserStartedState)msg.obj, msg.arg1, msg.arg2);
+                break;
+            }
+            case IMMERSIVE_MODE_LOCK_MSG: {
+                final boolean nextState = (msg.arg1 != 0);
+                if (mUpdateLock.isHeld() != nextState) {
+                    if (DEBUG_IMMERSIVE) {
+                        final ActivityRecord r = (ActivityRecord) msg.obj;
+                        Slog.d(TAG, "Applying new update lock state '" + nextState + "' for " + r);
+                    }
+                    if (nextState) {
+                        mUpdateLock.acquire();
+                    } else {
+                        mUpdateLock.release();
+                    }
+                }
+                break;
+            }
+            case PERSIST_URI_GRANTS_MSG: {
+                writeGrantedUriPermissions();
+                break;
+            }
+            case REQUEST_ALL_PSS_MSG: {
+                requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
+                break;
+            }
+            }
+        }
+    };
+
+    static final int COLLECT_PSS_BG_MSG = 1;
+
+    final Handler mBgHandler = new Handler(BackgroundThread.getHandler().getLooper()) {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+            case COLLECT_PSS_BG_MSG: {
+                int i=0, num=0;
+                long start = SystemClock.uptimeMillis();
+                long[] tmp = new long[1];
+                do {
+                    ProcessRecord proc;
+                    int procState;
+                    int pid;
+                    synchronized (ActivityManagerService.this) {
+                        if (i >= mPendingPssProcesses.size()) {
+                            if (DEBUG_PSS) Slog.d(TAG, "Collected PSS of " + num + " of " + i
+                                    + " processes in " + (SystemClock.uptimeMillis()-start) + "ms");
+                            mPendingPssProcesses.clear();
+                            return;
+                        }
+                        proc = mPendingPssProcesses.get(i);
+                        procState = proc.pssProcState;
+                        if (proc.thread != null && procState == proc.setProcState) {
+                            pid = proc.pid;
+                        } else {
+                            proc = null;
+                            pid = 0;
+                        }
+                        i++;
+                    }
+                    if (proc != null) {
+                        long pss = Debug.getPss(pid, tmp);
+                        synchronized (ActivityManagerService.this) {
+                            if (proc.thread != null && proc.setProcState == procState
+                                    && proc.pid == pid) {
+                                num++;
+                                proc.lastPssTime = SystemClock.uptimeMillis();
+                                proc.baseProcessTracker.addPss(pss, tmp[0], true, proc.pkgList);
+                                if (DEBUG_PSS) Slog.d(TAG, "PSS of " + proc.toShortString()
+                                        + ": " + pss + " lastPss=" + proc.lastPss
+                                        + " state=" + ProcessList.makeProcStateString(procState));
+                                if (proc.initialIdlePss == 0) {
+                                    proc.initialIdlePss = pss;
+                                }
+                                proc.lastPss = pss;
+                                if (procState >= ActivityManager.PROCESS_STATE_HOME) {
+                                    proc.lastCachedPss = pss;
+                                }
+                            }
+                        }
+                    }
+                } while (true);
+            }
+            }
+        }
+    };
+
+    public void setSystemProcess() {
+        try {
+            ServiceManager.addService(Context.ACTIVITY_SERVICE, this, true);
+            ServiceManager.addService(ProcessStats.SERVICE_NAME, mProcessStats);
+            ServiceManager.addService("meminfo", new MemBinder(this));
+            ServiceManager.addService("gfxinfo", new GraphicsBinder(this));
+            ServiceManager.addService("dbinfo", new DbBinder(this));
+            if (MONITOR_CPU_USAGE) {
+                ServiceManager.addService("cpuinfo", new CpuBinder(this));
+            }
+            ServiceManager.addService("permission", new PermissionController(this));
+
+            ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(
+                    "android", STOCK_PM_FLAGS);
+            mSystemThread.installSystemApplicationInfo(info);
+
+            synchronized (this) {
+                ProcessRecord app = newProcessRecordLocked(info, info.processName, false);
+                app.persistent = true;
+                app.pid = MY_PID;
+                app.maxAdj = ProcessList.SYSTEM_ADJ;
+                app.makeActive(mSystemThread.getApplicationThread(), mProcessStats);
+                mProcessNames.put(app.processName, app.uid, app);
+                synchronized (mPidsSelfLocked) {
+                    mPidsSelfLocked.put(app.pid, app);
+                }
+                updateLruProcessLocked(app, false, null);
+                updateOomAdjLocked();
+            }
+        } catch (PackageManager.NameNotFoundException e) {
+            throw new RuntimeException(
+                    "Unable to find android system package", e);
+        }
+    }
+
+    public void setWindowManager(WindowManagerService wm) {
+        mWindowManager = wm;
+        mStackSupervisor.setWindowManager(wm);
+    }
+
+    public void startObservingNativeCrashes() {
+        final NativeCrashListener ncl = new NativeCrashListener(this);
+        ncl.start();
+    }
+
+    public IAppOpsService getAppOpsService() {
+        return mAppOpsService;
+    }
+
+    static class MemBinder extends Binder {
+        ActivityManagerService mActivityManagerService;
+        MemBinder(ActivityManagerService activityManagerService) {
+            mActivityManagerService = activityManagerService;
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump meminfo from from pid="
+                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                        + " without permission " + android.Manifest.permission.DUMP);
+                return;
+            }
+
+            mActivityManagerService.dumpApplicationMemoryUsage(fd, pw, "  ", args, false, null);
+        }
+    }
+
+    static class GraphicsBinder extends Binder {
+        ActivityManagerService mActivityManagerService;
+        GraphicsBinder(ActivityManagerService activityManagerService) {
+            mActivityManagerService = activityManagerService;
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump gfxinfo from from pid="
+                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                        + " without permission " + android.Manifest.permission.DUMP);
+                return;
+            }
+
+            mActivityManagerService.dumpGraphicsHardwareUsage(fd, pw, args);
+        }
+    }
+
+    static class DbBinder extends Binder {
+        ActivityManagerService mActivityManagerService;
+        DbBinder(ActivityManagerService activityManagerService) {
+            mActivityManagerService = activityManagerService;
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump dbinfo from from pid="
+                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                        + " without permission " + android.Manifest.permission.DUMP);
+                return;
+            }
+
+            mActivityManagerService.dumpDbInfo(fd, pw, args);
+        }
+    }
+
+    static class CpuBinder extends Binder {
+        ActivityManagerService mActivityManagerService;
+        CpuBinder(ActivityManagerService activityManagerService) {
+            mActivityManagerService = activityManagerService;
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump cpuinfo from from pid="
+                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                        + " without permission " + android.Manifest.permission.DUMP);
+                return;
+            }
+
+            synchronized (mActivityManagerService.mProcessCpuThread) {
+                pw.print(mActivityManagerService.mProcessCpuTracker.printCurrentLoad());
+                pw.print(mActivityManagerService.mProcessCpuTracker.printCurrentState(
+                        SystemClock.uptimeMillis()));
+            }
+        }
+    }
+
+    public static final class Lifecycle extends SystemService {
+        private final ActivityManagerService mService;
+
+        public Lifecycle(Context context) {
+            super(context);
+            mService = new ActivityManagerService(context);
+        }
+
+        @Override
+        public void onStart() {
+            mService.start();
+        }
+
+        public ActivityManagerService getService() {
+            return mService;
+        }
+    }
+
+    // Note: This method is invoked on the main thread but may need to attach various
+    // handlers to other threads.  So take care to be explicit about the looper.
+    public ActivityManagerService(Context systemContext) {
+        mContext = systemContext;
+        mFactoryTest = FactoryTest.getMode();
+        mSystemThread = ActivityThread.currentActivityThread();
+
+        Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());
+
+        mHandlerThread = new ServiceThread(TAG,
+                android.os.Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
+        mHandlerThread.start();
+        mHandler = new MainHandler(mHandlerThread.getLooper());
+
+        mFgBroadcastQueue = new BroadcastQueue(this, mHandler,
+                "foreground", BROADCAST_FG_TIMEOUT, false);
+        mBgBroadcastQueue = new BroadcastQueue(this, mHandler,
+                "background", BROADCAST_BG_TIMEOUT, true);
+        mBroadcastQueues[0] = mFgBroadcastQueue;
+        mBroadcastQueues[1] = mBgBroadcastQueue;
+
+        mServices = new ActiveServices(this);
+        mProviderMap = new ProviderMap(this);
+
+        // TODO: Move creation of battery stats service outside of activity manager service.
+        File dataDir = Environment.getDataDirectory();
+        File systemDir = new File(dataDir, "system");
+        systemDir.mkdirs();
+        mBatteryStatsService = new BatteryStatsService(new File(
+                systemDir, "batterystats.bin").toString(), mHandler);
+        mBatteryStatsService.getActiveStatistics().readLocked();
+        mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
+        mOnBattery = DEBUG_POWER ? true
+                : mBatteryStatsService.getActiveStatistics().getIsOnBattery();
+        mBatteryStatsService.getActiveStatistics().setCallback(this);
+
+        mProcessStats = new ProcessStatsService(this, new File(systemDir, "procstats"));
+
+        mUsageStatsService = new UsageStatsService(new File(systemDir, "usagestats").toString());
+        mAppOpsService = new AppOpsService(new File(systemDir, "appops.xml"), mHandler);
+
+        mGrantFile = new AtomicFile(new File(systemDir, "urigrants.xml"));
+
+        // User 0 is the first and only user that runs at boot.
+        mStartedUsers.put(0, new UserStartedState(new UserHandle(0), true));
+        mUserLru.add(Integer.valueOf(0));
+        updateStartedUserArrayLocked();
+
+        GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version",
+            ConfigurationInfo.GL_ES_VERSION_UNDEFINED);
+
+        mConfiguration.setToDefaults();
+        mConfiguration.setLocale(Locale.getDefault());
+
+        mConfigurationSeq = mConfiguration.seq = 1;
+        mProcessCpuTracker.init();
+
+        mCompatModePackages = new CompatModePackages(this, systemDir, mHandler);
+        mIntentFirewall = new IntentFirewall(new IntentFirewallInterface(), mHandler);
+        mStackSupervisor = new ActivityStackSupervisor(this);
+
+        mProcessCpuThread = new Thread("CpuTracker") {
+            @Override
+            public void run() {
+                while (true) {
+                    try {
+                        try {
+                            synchronized(this) {
+                                final long now = SystemClock.uptimeMillis();
+                                long nextCpuDelay = (mLastCpuTime.get()+MONITOR_CPU_MAX_TIME)-now;
+                                long nextWriteDelay = (mLastWriteTime+BATTERY_STATS_TIME)-now;
+                                //Slog.i(TAG, "Cpu delay=" + nextCpuDelay
+                                //        + ", write delay=" + nextWriteDelay);
+                                if (nextWriteDelay < nextCpuDelay) {
+                                    nextCpuDelay = nextWriteDelay;
+                                }
+                                if (nextCpuDelay > 0) {
+                                    mProcessCpuMutexFree.set(true);
+                                    this.wait(nextCpuDelay);
+                                }
+                            }
+                        } catch (InterruptedException e) {
+                        }
+                        updateCpuStatsNow();
+                    } catch (Exception e) {
+                        Slog.e(TAG, "Unexpected exception collecting process stats", e);
+                    }
+                }
+            }
+        };
+
+        Watchdog.getInstance().addMonitor(this);
+        Watchdog.getInstance().addThread(mHandler);
+    }
+
+    private void start() {
+        mProcessCpuThread.start();
+
+        mBatteryStatsService.publish(mContext);
+        mUsageStatsService.publish(mContext);
+        mAppOpsService.publish(mContext);
+        startRunning(null, null, null, null);
+    }
+
+    @Override
+    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+            throws RemoteException {
+        if (code == SYSPROPS_TRANSACTION) {
+            // We need to tell all apps about the system property change.
+            ArrayList<IBinder> procs = new ArrayList<IBinder>();
+            synchronized(this) {
+                final int NP = mProcessNames.getMap().size();
+                for (int ip=0; ip<NP; ip++) {
+                    SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
+                    final int NA = apps.size();
+                    for (int ia=0; ia<NA; ia++) {
+                        ProcessRecord app = apps.valueAt(ia);
+                        if (app.thread != null) {
+                            procs.add(app.thread.asBinder());
+                        }
+                    }
+                }
+            }
+
+            int N = procs.size();
+            for (int i=0; i<N; i++) {
+                Parcel data2 = Parcel.obtain();
+                try {
+                    procs.get(i).transact(IBinder.SYSPROPS_TRANSACTION, data2, null, 0);
+                } catch (RemoteException e) {
+                }
+                data2.recycle();
+            }
+        }
+        try {
+            return super.onTransact(code, data, reply, flags);
+        } catch (RuntimeException e) {
+            // The activity manager only throws security exceptions, so let's
+            // log all others.
+            if (!(e instanceof SecurityException)) {
+                Slog.wtf(TAG, "Activity Manager Crash", e);
+            }
+            throw e;
+        }
+    }
+
+    void updateCpuStats() {
+        final long now = SystemClock.uptimeMillis();
+        if (mLastCpuTime.get() >= now - MONITOR_CPU_MIN_TIME) {
+            return;
+        }
+        if (mProcessCpuMutexFree.compareAndSet(true, false)) {
+            synchronized (mProcessCpuThread) {
+                mProcessCpuThread.notify();
+            }
+        }
+    }
+
+    void updateCpuStatsNow() {
+        synchronized (mProcessCpuThread) {
+            mProcessCpuMutexFree.set(false);
+            final long now = SystemClock.uptimeMillis();
+            boolean haveNewCpuStats = false;
+
+            if (MONITOR_CPU_USAGE &&
+                    mLastCpuTime.get() < (now-MONITOR_CPU_MIN_TIME)) {
+                mLastCpuTime.set(now);
+                haveNewCpuStats = true;
+                mProcessCpuTracker.update();
+                //Slog.i(TAG, mProcessCpu.printCurrentState());
+                //Slog.i(TAG, "Total CPU usage: "
+                //        + mProcessCpu.getTotalCpuPercent() + "%");
+
+                // Slog the cpu usage if the property is set.
+                if ("true".equals(SystemProperties.get("events.cpu"))) {
+                    int user = mProcessCpuTracker.getLastUserTime();
+                    int system = mProcessCpuTracker.getLastSystemTime();
+                    int iowait = mProcessCpuTracker.getLastIoWaitTime();
+                    int irq = mProcessCpuTracker.getLastIrqTime();
+                    int softIrq = mProcessCpuTracker.getLastSoftIrqTime();
+                    int idle = mProcessCpuTracker.getLastIdleTime();
+
+                    int total = user + system + iowait + irq + softIrq + idle;
+                    if (total == 0) total = 1;
+
+                    EventLog.writeEvent(EventLogTags.CPU,
+                            ((user+system+iowait+irq+softIrq) * 100) / total,
+                            (user * 100) / total,
+                            (system * 100) / total,
+                            (iowait * 100) / total,
+                            (irq * 100) / total,
+                            (softIrq * 100) / total);
+                }
+            }
+
+            long[] cpuSpeedTimes = mProcessCpuTracker.getLastCpuSpeedTimes();
+            final BatteryStatsImpl bstats = mBatteryStatsService.getActiveStatistics();
+            synchronized(bstats) {
+                synchronized(mPidsSelfLocked) {
+                    if (haveNewCpuStats) {
+                        if (mOnBattery) {
+                            int perc = bstats.startAddingCpuLocked();
+                            int totalUTime = 0;
+                            int totalSTime = 0;
+                            final int N = mProcessCpuTracker.countStats();
+                            for (int i=0; i<N; i++) {
+                                ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
+                                if (!st.working) {
+                                    continue;
+                                }
+                                ProcessRecord pr = mPidsSelfLocked.get(st.pid);
+                                int otherUTime = (st.rel_utime*perc)/100;
+                                int otherSTime = (st.rel_stime*perc)/100;
+                                totalUTime += otherUTime;
+                                totalSTime += otherSTime;
+                                if (pr != null) {
+                                    BatteryStatsImpl.Uid.Proc ps = bstats.getProcessStatsLocked(
+                                            st.name, st.pid);
+                                    ps.addCpuTimeLocked(st.rel_utime-otherUTime,
+                                            st.rel_stime-otherSTime);
+                                    ps.addSpeedStepTimes(cpuSpeedTimes);
+                                    pr.curCpuTime += (st.rel_utime+st.rel_stime) * 10;
+                                } else if (st.uid >= Process.FIRST_APPLICATION_UID) {
+                                    BatteryStatsImpl.Uid.Proc ps = st.batteryStats;
+                                    if (ps == null) {
+                                        st.batteryStats = ps = bstats.getProcessStatsLocked(st.uid,
+                                                "(Unknown)");
+                                    }
+                                    ps.addCpuTimeLocked(st.rel_utime-otherUTime,
+                                            st.rel_stime-otherSTime);
+                                    ps.addSpeedStepTimes(cpuSpeedTimes);
+                                } else {
+                                    BatteryStatsImpl.Uid.Proc ps =
+                                            bstats.getProcessStatsLocked(st.name, st.pid);
+                                    if (ps != null) {
+                                        ps.addCpuTimeLocked(st.rel_utime-otherUTime,
+                                                st.rel_stime-otherSTime);
+                                        ps.addSpeedStepTimes(cpuSpeedTimes);
+                                    }
+                                }
+                            }
+                            bstats.finishAddingCpuLocked(perc, totalUTime,
+                                    totalSTime, cpuSpeedTimes);
+                        }
+                    }
+                }
+
+                if (mLastWriteTime < (now-BATTERY_STATS_TIME)) {
+                    mLastWriteTime = now;
+                    mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
+                }
+            }
+        }
+    }
+
+    @Override
+    public void batteryNeedsCpuUpdate() {
+        updateCpuStatsNow();
+    }
+
+    @Override
+    public void batteryPowerChanged(boolean onBattery) {
+        // When plugging in, update the CPU stats first before changing
+        // the plug state.
+        updateCpuStatsNow();
+        synchronized (this) {
+            synchronized(mPidsSelfLocked) {
+                mOnBattery = DEBUG_POWER ? true : onBattery;
+            }
+        }
+    }
+
+    /**
+     * Initialize the application bind args. These are passed to each
+     * process when the bindApplication() IPC is sent to the process. They're
+     * lazily setup to make sure the services are running when they're asked for.
+     */
+    private HashMap<String, IBinder> getCommonServicesLocked() {
+        if (mAppBindArgs == null) {
+            mAppBindArgs = new HashMap<String, IBinder>();
+
+            // Setup the application init args
+            mAppBindArgs.put("package", ServiceManager.getService("package"));
+            mAppBindArgs.put("window", ServiceManager.getService("window"));
+            mAppBindArgs.put(Context.ALARM_SERVICE,
+                    ServiceManager.getService(Context.ALARM_SERVICE));
+        }
+        return mAppBindArgs;
+    }
+
+    final void setFocusedActivityLocked(ActivityRecord r) {
+        if (mFocusedActivity != r) {
+            if (DEBUG_FOCUS) Slog.d(TAG, "setFocusedActivityLocked: r=" + r);
+            mFocusedActivity = r;
+            mStackSupervisor.setFocusedStack(r);
+            if (r != null) {
+                mWindowManager.setFocusedApp(r.appToken, true);
+            }
+            applyUpdateLockStateLocked(r);
+        }
+    }
+
+    @Override
+    public void setFocusedStack(int stackId) {
+        if (DEBUG_FOCUS) Slog.d(TAG, "setFocusedStack: stackId=" + stackId);
+        synchronized (ActivityManagerService.this) {
+            ActivityStack stack = mStackSupervisor.getStack(stackId);
+            if (stack != null) {
+                ActivityRecord r = stack.topRunningActivityLocked(null);
+                if (r != null) {
+                    setFocusedActivityLocked(r);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void notifyActivityDrawn(IBinder token) {
+        if (DEBUG_VISBILITY) Slog.d(TAG, "notifyActivityDrawn: token=" + token);
+        synchronized (this) {
+            ActivityRecord r= mStackSupervisor.isInAnyStackLocked(token);
+            if (r != null) {
+                r.task.stack.notifyActivityDrawnLocked(r);
+            }
+        }
+    }
+
+    final void applyUpdateLockStateLocked(ActivityRecord r) {
+        // Modifications to the UpdateLock state are done on our handler, outside
+        // the activity manager's locks.  The new state is determined based on the
+        // state *now* of the relevant activity record.  The object is passed to
+        // the handler solely for logging detail, not to be consulted/modified.
+        final boolean nextState = r != null && r.immersive;
+        mHandler.sendMessage(
+                mHandler.obtainMessage(IMMERSIVE_MODE_LOCK_MSG, (nextState) ? 1 : 0, 0, r));
+    }
+
+    final void showAskCompatModeDialogLocked(ActivityRecord r) {
+        Message msg = Message.obtain();
+        msg.what = SHOW_COMPAT_MODE_DIALOG_MSG;
+        msg.obj = r.task.askedCompatMode ? null : r;
+        mHandler.sendMessage(msg);
+    }
+
+    private final int updateLruProcessInternalLocked(ProcessRecord app, long now, int index,
+            String what, Object obj, ProcessRecord srcApp) {
+        app.lastActivityTime = now;
+
+        if (app.activities.size() > 0) {
+            // Don't want to touch dependent processes that are hosting activities.
+            return index;
+        }
+
+        int lrui = mLruProcesses.lastIndexOf(app);
+        if (lrui < 0) {
+            Slog.wtf(TAG, "Adding dependent process " + app + " not on LRU list: "
+                    + what + " " + obj + " from " + srcApp);
+            return index;
+        }
+
+        if (lrui >= index) {
+            // Don't want to cause this to move dependent processes *back* in the
+            // list as if they were less frequently used.
+            return index;
+        }
+
+        if (lrui >= mLruProcessActivityStart) {
+            // Don't want to touch dependent processes that are hosting activities.
+            return index;
+        }
+
+        mLruProcesses.remove(lrui);
+        if (index > 0) {
+            index--;
+        }
+        if (DEBUG_LRU) Slog.d(TAG, "Moving dep from " + lrui + " to " + index
+                + " in LRU list: " + app);
+        mLruProcesses.add(index, app);
+        return index;
+    }
+
+    final void removeLruProcessLocked(ProcessRecord app) {
+        int lrui = mLruProcesses.lastIndexOf(app);
+        if (lrui >= 0) {
+            if (lrui <= mLruProcessActivityStart) {
+                mLruProcessActivityStart--;
+            }
+            if (lrui <= mLruProcessServiceStart) {
+                mLruProcessServiceStart--;
+            }
+            mLruProcesses.remove(lrui);
+        }
+    }
+
+    final void updateLruProcessLocked(ProcessRecord app, boolean activityChange,
+            ProcessRecord client) {
+        final boolean hasActivity = app.activities.size() > 0 || app.hasClientActivities;
+        final boolean hasService = false; // not impl yet. app.services.size() > 0;
+        if (!activityChange && hasActivity) {
+            // The process has activties, so we are only going to allow activity-based
+            // adjustments move it.  It should be kept in the front of the list with other
+            // processes that have activities, and we don't want those to change their
+            // order except due to activity operations.
+            return;
+        }
+
+        mLruSeq++;
+        final long now = SystemClock.uptimeMillis();
+        app.lastActivityTime = now;
+
+        // First a quick reject: if the app is already at the position we will
+        // put it, then there is nothing to do.
+        if (hasActivity) {
+            final int N = mLruProcesses.size();
+            if (N > 0 && mLruProcesses.get(N-1) == app) {
+                if (DEBUG_LRU) Slog.d(TAG, "Not moving, already top activity: " + app);
+                return;
+            }
+        } else {
+            if (mLruProcessServiceStart > 0
+                    && mLruProcesses.get(mLruProcessServiceStart-1) == app) {
+                if (DEBUG_LRU) Slog.d(TAG, "Not moving, already top other: " + app);
+                return;
+            }
+        }
+
+        int lrui = mLruProcesses.lastIndexOf(app);
+
+        if (app.persistent && lrui >= 0) {
+            // We don't care about the position of persistent processes, as long as
+            // they are in the list.
+            if (DEBUG_LRU) Slog.d(TAG, "Not moving, persistent: " + app);
+            return;
+        }
+
+        /* In progress: compute new position first, so we can avoid doing work
+           if the process is not actually going to move.  Not yet working.
+        int addIndex;
+        int nextIndex;
+        boolean inActivity = false, inService = false;
+        if (hasActivity) {
+            // Process has activities, put it at the very tipsy-top.
+            addIndex = mLruProcesses.size();
+            nextIndex = mLruProcessServiceStart;
+            inActivity = true;
+        } else if (hasService) {
+            // Process has services, put it at the top of the service list.
+            addIndex = mLruProcessActivityStart;
+            nextIndex = mLruProcessServiceStart;
+            inActivity = true;
+            inService = true;
+        } else  {
+            // Process not otherwise of interest, it goes to the top of the non-service area.
+            addIndex = mLruProcessServiceStart;
+            if (client != null) {
+                int clientIndex = mLruProcesses.lastIndexOf(client);
+                if (clientIndex < 0) Slog.d(TAG, "Unknown client " + client + " when updating "
+                        + app);
+                if (clientIndex >= 0 && addIndex > clientIndex) {
+                    addIndex = clientIndex;
+                }
+            }
+            nextIndex = addIndex > 0 ? addIndex-1 : addIndex;
+        }
+
+        Slog.d(TAG, "Update LRU at " + lrui + " to " + addIndex + " (act="
+                + mLruProcessActivityStart + "): " + app);
+        */
+
+        if (lrui >= 0) {
+            if (lrui < mLruProcessActivityStart) {
+                mLruProcessActivityStart--;
+            }
+            if (lrui < mLruProcessServiceStart) {
+                mLruProcessServiceStart--;
+            }
+            /*
+            if (addIndex > lrui) {
+                addIndex--;
+            }
+            if (nextIndex > lrui) {
+                nextIndex--;
+            }
+            */
+            mLruProcesses.remove(lrui);
+        }
+
+        /*
+        mLruProcesses.add(addIndex, app);
+        if (inActivity) {
+            mLruProcessActivityStart++;
+        }
+        if (inService) {
+            mLruProcessActivityStart++;
+        }
+        */
+
+        int nextIndex;
+        if (hasActivity) {
+            final int N = mLruProcesses.size();
+            if (app.activities.size() == 0 && mLruProcessActivityStart < (N-1)) {
+                // Process doesn't have activities, but has clients with
+                // activities...  move it up, but one below the top (the top
+                // should always have a real activity).
+                if (DEBUG_LRU) Slog.d(TAG, "Adding to second-top of LRU activity list: " + app);
+                mLruProcesses.add(N-1, app);
+                // To keep it from spamming the LRU list (by making a bunch of clients),
+                // we will push down any other entries owned by the app.
+                final int uid = app.info.uid;
+                for (int i=N-2; i>mLruProcessActivityStart; i--) {
+                    ProcessRecord subProc = mLruProcesses.get(i);
+                    if (subProc.info.uid == uid) {
+                        // We want to push this one down the list.  If the process after
+                        // it is for the same uid, however, don't do so, because we don't
+                        // want them internally to be re-ordered.
+                        if (mLruProcesses.get(i-1).info.uid != uid) {
+                            if (DEBUG_LRU) Slog.d(TAG, "Pushing uid " + uid + " swapping at " + i
+                                    + ": " + mLruProcesses.get(i) + " : " + mLruProcesses.get(i-1));
+                            ProcessRecord tmp = mLruProcesses.get(i);
+                            mLruProcesses.set(i, mLruProcesses.get(i-1));
+                            mLruProcesses.set(i-1, tmp);
+                            i--;
+                        }
+                    } else {
+                        // A gap, we can stop here.
+                        break;
+                    }
+                }
+            } else {
+                // Process has activities, put it at the very tipsy-top.
+                if (DEBUG_LRU) Slog.d(TAG, "Adding to top of LRU activity list: " + app);
+                mLruProcesses.add(app);
+            }
+            nextIndex = mLruProcessServiceStart;
+        } else if (hasService) {
+            // Process has services, put it at the top of the service list.
+            if (DEBUG_LRU) Slog.d(TAG, "Adding to top of LRU service list: " + app);
+            mLruProcesses.add(mLruProcessActivityStart, app);
+            nextIndex = mLruProcessServiceStart;
+            mLruProcessActivityStart++;
+        } else  {
+            // Process not otherwise of interest, it goes to the top of the non-service area.
+            int index = mLruProcessServiceStart;
+            if (client != null) {
+                // If there is a client, don't allow the process to be moved up higher
+                // in the list than that client.
+                int clientIndex = mLruProcesses.lastIndexOf(client);
+                if (DEBUG_LRU && clientIndex < 0) Slog.d(TAG, "Unknown client " + client
+                        + " when updating " + app);
+                if (clientIndex <= lrui) {
+                    // Don't allow the client index restriction to push it down farther in the
+                    // list than it already is.
+                    clientIndex = lrui;
+                }
+                if (clientIndex >= 0 && index > clientIndex) {
+                    index = clientIndex;
+                }
+            }
+            if (DEBUG_LRU) Slog.d(TAG, "Adding at " + index + " of LRU list: " + app);
+            mLruProcesses.add(index, app);
+            nextIndex = index-1;
+            mLruProcessActivityStart++;
+            mLruProcessServiceStart++;
+        }
+
+        // If the app is currently using a content provider or service,
+        // bump those processes as well.
+        for (int j=app.connections.size()-1; j>=0; j--) {
+            ConnectionRecord cr = app.connections.valueAt(j);
+            if (cr.binding != null && !cr.serviceDead && cr.binding.service != null
+                    && cr.binding.service.app != null
+                    && cr.binding.service.app.lruSeq != mLruSeq
+                    && !cr.binding.service.app.persistent) {
+                nextIndex = updateLruProcessInternalLocked(cr.binding.service.app, now, nextIndex,
+                        "service connection", cr, app);
+            }
+        }
+        for (int j=app.conProviders.size()-1; j>=0; j--) {
+            ContentProviderRecord cpr = app.conProviders.get(j).provider;
+            if (cpr.proc != null && cpr.proc.lruSeq != mLruSeq && !cpr.proc.persistent) {
+                nextIndex = updateLruProcessInternalLocked(cpr.proc, now, nextIndex,
+                        "provider reference", cpr, app);
+            }
+        }
+    }
+
+    final ProcessRecord getProcessRecordLocked(String processName, int uid, boolean keepIfLarge) {
+        if (uid == Process.SYSTEM_UID) {
+            // The system gets to run in any process.  If there are multiple
+            // processes with the same uid, just pick the first (this
+            // should never happen).
+            SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(processName);
+            if (procs == null) return null;
+            final int N = procs.size();
+            for (int i = 0; i < N; i++) {
+                if (UserHandle.isSameUser(procs.keyAt(i), uid)) return procs.valueAt(i);
+            }
+        }
+        ProcessRecord proc = mProcessNames.get(processName, uid);
+        if (false && proc != null && !keepIfLarge
+                && proc.setProcState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY
+                && proc.lastCachedPss >= 4000) {
+            // Turn this condition on to cause killing to happen regularly, for testing.
+            if (proc.baseProcessTracker != null) {
+                proc.baseProcessTracker.reportCachedKill(proc.pkgList, proc.lastCachedPss);
+            }
+            killUnneededProcessLocked(proc, Long.toString(proc.lastCachedPss)
+                    + "k from cached");
+        } else if (proc != null && !keepIfLarge
+                && mLastMemoryLevel > ProcessStats.ADJ_MEM_FACTOR_NORMAL
+                && proc.setProcState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY) {
+            if (DEBUG_PSS) Slog.d(TAG, "May not keep " + proc + ": pss=" + proc.lastCachedPss);
+            if (proc.lastCachedPss >= mProcessList.getCachedRestoreThresholdKb()) {
+                if (proc.baseProcessTracker != null) {
+                    proc.baseProcessTracker.reportCachedKill(proc.pkgList, proc.lastCachedPss);
+                }
+                killUnneededProcessLocked(proc, Long.toString(proc.lastCachedPss)
+                        + "k from cached");
+            }
+        }
+        return proc;
+    }
+
+    void ensurePackageDexOpt(String packageName) {
+        IPackageManager pm = AppGlobals.getPackageManager();
+        try {
+            if (pm.performDexOpt(packageName)) {
+                mDidDexOpt = true;
+            }
+        } catch (RemoteException e) {
+        }
+    }
+
+    boolean isNextTransitionForward() {
+        int transit = mWindowManager.getPendingAppTransition();
+        return transit == AppTransition.TRANSIT_ACTIVITY_OPEN
+                || transit == AppTransition.TRANSIT_TASK_OPEN
+                || transit == AppTransition.TRANSIT_TASK_TO_FRONT;
+    }
+
+    final ProcessRecord startProcessLocked(String processName,
+            ApplicationInfo info, boolean knownToBeDead, int intentFlags,
+            String hostingType, ComponentName hostingName, boolean allowWhileBooting,
+            boolean isolated, boolean keepIfLarge) {
+        ProcessRecord app;
+        if (!isolated) {
+            app = getProcessRecordLocked(processName, info.uid, keepIfLarge);
+        } else {
+            // If this is an isolated process, it can't re-use an existing process.
+            app = null;
+        }
+        // We don't have to do anything more if:
+        // (1) There is an existing application record; and
+        // (2) The caller doesn't think it is dead, OR there is no thread
+        //     object attached to it so we know it couldn't have crashed; and
+        // (3) There is a pid assigned to it, so it is either starting or
+        //     already running.
+        if (DEBUG_PROCESSES) Slog.v(TAG, "startProcess: name=" + processName
+                + " app=" + app + " knownToBeDead=" + knownToBeDead
+                + " thread=" + (app != null ? app.thread : null)
+                + " pid=" + (app != null ? app.pid : -1));
+        if (app != null && app.pid > 0) {
+            if (!knownToBeDead || app.thread == null) {
+                // We already have the app running, or are waiting for it to
+                // come up (we have a pid but not yet its thread), so keep it.
+                if (DEBUG_PROCESSES) Slog.v(TAG, "App already running: " + app);
+                // If this is a new package in the process, add the package to the list
+                app.addPackage(info.packageName, mProcessStats);
+                return app;
+            }
+
+            // An application record is attached to a previous process,
+            // clean it up now.
+            if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG, "App died: " + app);
+            handleAppDiedLocked(app, true, true);
+        }
+
+        String hostingNameStr = hostingName != null
+                ? hostingName.flattenToShortString() : null;
+
+        if (!isolated) {
+            if ((intentFlags&Intent.FLAG_FROM_BACKGROUND) != 0) {
+                // If we are in the background, then check to see if this process
+                // is bad.  If so, we will just silently fail.
+                if (mBadProcesses.get(info.processName, info.uid) != null) {
+                    if (DEBUG_PROCESSES) Slog.v(TAG, "Bad process: " + info.uid
+                            + "/" + info.processName);
+                    return null;
+                }
+            } else {
+                // When the user is explicitly starting a process, then clear its
+                // crash count so that we won't make it bad until they see at
+                // least one crash dialog again, and make the process good again
+                // if it had been bad.
+                if (DEBUG_PROCESSES) Slog.v(TAG, "Clearing bad process: " + info.uid
+                        + "/" + info.processName);
+                mProcessCrashTimes.remove(info.processName, info.uid);
+                if (mBadProcesses.get(info.processName, info.uid) != null) {
+                    EventLog.writeEvent(EventLogTags.AM_PROC_GOOD,
+                            UserHandle.getUserId(info.uid), info.uid,
+                            info.processName);
+                    mBadProcesses.remove(info.processName, info.uid);
+                    if (app != null) {
+                        app.bad = false;
+                    }
+                }
+            }
+        }
+
+        if (app == null) {
+            app = newProcessRecordLocked(info, processName, isolated);
+            if (app == null) {
+                Slog.w(TAG, "Failed making new process record for "
+                        + processName + "/" + info.uid + " isolated=" + isolated);
+                return null;
+            }
+            mProcessNames.put(processName, app.uid, app);
+            if (isolated) {
+                mIsolatedProcesses.put(app.uid, app);
+            }
+        } else {
+            // If this is a new package in the process, add the package to the list
+            app.addPackage(info.packageName, mProcessStats);
+        }
+
+        // If the system is not ready yet, then hold off on starting this
+        // process until it is.
+        if (!mProcessesReady
+                && !isAllowedWhileBooting(info)
+                && !allowWhileBooting) {
+            if (!mProcessesOnHold.contains(app)) {
+                mProcessesOnHold.add(app);
+            }
+            if (DEBUG_PROCESSES) Slog.v(TAG, "System not ready, putting on hold: " + app);
+            return app;
+        }
+
+        startProcessLocked(app, hostingType, hostingNameStr);
+        return (app.pid != 0) ? app : null;
+    }
+
+    boolean isAllowedWhileBooting(ApplicationInfo ai) {
+        return (ai.flags&ApplicationInfo.FLAG_PERSISTENT) != 0;
+    }
+
+    private final void startProcessLocked(ProcessRecord app,
+            String hostingType, String hostingNameStr) {
+        if (app.pid > 0 && app.pid != MY_PID) {
+            synchronized (mPidsSelfLocked) {
+                mPidsSelfLocked.remove(app.pid);
+                mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
+            }
+            app.setPid(0);
+        }
+
+        if (DEBUG_PROCESSES && mProcessesOnHold.contains(app)) Slog.v(TAG,
+                "startProcessLocked removing on hold: " + app);
+        mProcessesOnHold.remove(app);
+
+        updateCpuStats();
+
+        try {
+            int uid = app.uid;
+
+            int[] gids = null;
+            int mountExternal = Zygote.MOUNT_EXTERNAL_NONE;
+            if (!app.isolated) {
+                int[] permGids = null;
+                try {
+                    final PackageManager pm = mContext.getPackageManager();
+                    permGids = pm.getPackageGids(app.info.packageName);
+
+                    if (Environment.isExternalStorageEmulated()) {
+                        if (pm.checkPermission(
+                                android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
+                                app.info.packageName) == PERMISSION_GRANTED) {
+                            mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER_ALL;
+                        } else {
+                            mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER;
+                        }
+                    }
+                } catch (PackageManager.NameNotFoundException e) {
+                    Slog.w(TAG, "Unable to retrieve gids", e);
+                }
+
+                /*
+                 * Add shared application GID so applications can share some
+                 * resources like shared libraries
+                 */
+                if (permGids == null) {
+                    gids = new int[1];
+                } else {
+                    gids = new int[permGids.length + 1];
+                    System.arraycopy(permGids, 0, gids, 1, permGids.length);
+                }
+                gids[0] = UserHandle.getSharedAppGid(UserHandle.getAppId(uid));
+            }
+            if (mFactoryTest != FactoryTest.FACTORY_TEST_OFF) {
+                if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
+                        && mTopComponent != null
+                        && app.processName.equals(mTopComponent.getPackageName())) {
+                    uid = 0;
+                }
+                if (mFactoryTest == FactoryTest.FACTORY_TEST_HIGH_LEVEL
+                        && (app.info.flags&ApplicationInfo.FLAG_FACTORY_TEST) != 0) {
+                    uid = 0;
+                }
+            }
+            int debugFlags = 0;
+            if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
+                debugFlags |= Zygote.DEBUG_ENABLE_DEBUGGER;
+                // Also turn on CheckJNI for debuggable apps. It's quite
+                // awkward to turn on otherwise.
+                debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
+            }
+            // Run the app in safe mode if its manifest requests so or the
+            // system is booted in safe mode.
+            if ((app.info.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0 ||
+                Zygote.systemInSafeMode == true) {
+                debugFlags |= Zygote.DEBUG_ENABLE_SAFEMODE;
+            }
+            if ("1".equals(SystemProperties.get("debug.checkjni"))) {
+                debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
+            }
+            if ("1".equals(SystemProperties.get("debug.jni.logging"))) {
+                debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING;
+            }
+            if ("1".equals(SystemProperties.get("debug.assert"))) {
+                debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
+            }
+
+            // Start the process.  It will either succeed and return a result containing
+            // the PID of the new process, or else throw a RuntimeException.
+            Process.ProcessStartResult startResult = Process.start("android.app.ActivityThread",
+                    app.processName, uid, uid, gids, debugFlags, mountExternal,
+                    app.info.targetSdkVersion, app.info.seinfo, null);
+
+            BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics();
+            synchronized (bs) {
+                if (bs.isOnBattery()) {
+                    bs.getProcessStatsLocked(app.uid, app.processName).incStartsLocked();
+                }
+            }
+
+            EventLog.writeEvent(EventLogTags.AM_PROC_START,
+                    UserHandle.getUserId(uid), startResult.pid, uid,
+                    app.processName, hostingType,
+                    hostingNameStr != null ? hostingNameStr : "");
+
+            if (app.persistent) {
+                Watchdog.getInstance().processStarted(app.processName, startResult.pid);
+            }
+
+            StringBuilder buf = mStringBuilder;
+            buf.setLength(0);
+            buf.append("Start proc ");
+            buf.append(app.processName);
+            buf.append(" for ");
+            buf.append(hostingType);
+            if (hostingNameStr != null) {
+                buf.append(" ");
+                buf.append(hostingNameStr);
+            }
+            buf.append(": pid=");
+            buf.append(startResult.pid);
+            buf.append(" uid=");
+            buf.append(uid);
+            buf.append(" gids={");
+            if (gids != null) {
+                for (int gi=0; gi<gids.length; gi++) {
+                    if (gi != 0) buf.append(", ");
+                    buf.append(gids[gi]);
+
+                }
+            }
+            buf.append("}");
+            Slog.i(TAG, buf.toString());
+            app.setPid(startResult.pid);
+            app.usingWrapper = startResult.usingWrapper;
+            app.removed = false;
+            synchronized (mPidsSelfLocked) {
+                this.mPidsSelfLocked.put(startResult.pid, app);
+                Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
+                msg.obj = app;
+                mHandler.sendMessageDelayed(msg, startResult.usingWrapper
+                        ? PROC_START_TIMEOUT_WITH_WRAPPER : PROC_START_TIMEOUT);
+            }
+        } catch (RuntimeException e) {
+            // XXX do better error recovery.
+            app.setPid(0);
+            Slog.e(TAG, "Failure starting process " + app.processName, e);
+        }
+    }
+
+    void updateUsageStats(ActivityRecord component, boolean resumed) {
+        if (DEBUG_SWITCH) Slog.d(TAG, "updateUsageStats: comp=" + component + "res=" + resumed);
+        final BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+        if (resumed) {
+            mUsageStatsService.noteResumeComponent(component.realActivity);
+            synchronized (stats) {
+                stats.noteActivityResumedLocked(component.app.uid);
+            }
+        } else {
+            mUsageStatsService.notePauseComponent(component.realActivity);
+            synchronized (stats) {
+                stats.noteActivityPausedLocked(component.app.uid);
+            }
+        }
+    }
+
+    Intent getHomeIntent() {
+        Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null);
+        intent.setComponent(mTopComponent);
+        if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
+            intent.addCategory(Intent.CATEGORY_HOME);
+        }
+        return intent;
+    }
+
+    boolean startHomeActivityLocked(int userId) {
+        if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
+                && mTopAction == null) {
+            // We are running in factory test mode, but unable to find
+            // the factory test app, so just sit around displaying the
+            // error message and don't try to start anything.
+            return false;
+        }
+        Intent intent = getHomeIntent();
+        ActivityInfo aInfo =
+            resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
+        if (aInfo != null) {
+            intent.setComponent(new ComponentName(
+                    aInfo.applicationInfo.packageName, aInfo.name));
+            // Don't do this if the home app is currently being
+            // instrumented.
+            aInfo = new ActivityInfo(aInfo);
+            aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);
+            ProcessRecord app = getProcessRecordLocked(aInfo.processName,
+                    aInfo.applicationInfo.uid, true);
+            if (app == null || app.instrumentationClass == null) {
+                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
+                mStackSupervisor.startHomeActivity(intent, aInfo);
+            }
+        }
+
+        return true;
+    }
+
+    private ActivityInfo resolveActivityInfo(Intent intent, int flags, int userId) {
+        ActivityInfo ai = null;
+        ComponentName comp = intent.getComponent();
+        try {
+            if (comp != null) {
+                ai = AppGlobals.getPackageManager().getActivityInfo(comp, flags, userId);
+            } else {
+                ResolveInfo info = AppGlobals.getPackageManager().resolveIntent(
+                        intent,
+                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),
+                            flags, userId);
+
+                if (info != null) {
+                    ai = info.activityInfo;
+                }
+            }
+        } catch (RemoteException e) {
+            // ignore
+        }
+
+        return ai;
+    }
+
+    /**
+     * Starts the "new version setup screen" if appropriate.
+     */
+    void startSetupActivityLocked() {
+        // Only do this once per boot.
+        if (mCheckedForSetup) {
+            return;
+        }
+
+        // We will show this screen if the current one is a different
+        // version than the last one shown, and we are not running in
+        // low-level factory test mode.
+        final ContentResolver resolver = mContext.getContentResolver();
+        if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL &&
+                Settings.Global.getInt(resolver,
+                        Settings.Global.DEVICE_PROVISIONED, 0) != 0) {
+            mCheckedForSetup = true;
+
+            // See if we should be showing the platform update setup UI.
+            Intent intent = new Intent(Intent.ACTION_UPGRADE_SETUP);
+            List<ResolveInfo> ris = mContext.getPackageManager()
+                    .queryIntentActivities(intent, PackageManager.GET_META_DATA);
+
+            // We don't allow third party apps to replace this.
+            ResolveInfo ri = null;
+            for (int i=0; ris != null && i<ris.size(); i++) {
+                if ((ris.get(i).activityInfo.applicationInfo.flags
+                        & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                    ri = ris.get(i);
+                    break;
+                }
+            }
+
+            if (ri != null) {
+                String vers = ri.activityInfo.metaData != null
+                        ? ri.activityInfo.metaData.getString(Intent.METADATA_SETUP_VERSION)
+                        : null;
+                if (vers == null && ri.activityInfo.applicationInfo.metaData != null) {
+                    vers = ri.activityInfo.applicationInfo.metaData.getString(
+                            Intent.METADATA_SETUP_VERSION);
+                }
+                String lastVers = Settings.Secure.getString(
+                        resolver, Settings.Secure.LAST_SETUP_SHOWN);
+                if (vers != null && !vers.equals(lastVers)) {
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    intent.setComponent(new ComponentName(
+                            ri.activityInfo.packageName, ri.activityInfo.name));
+                    mStackSupervisor.startActivityLocked(null, intent, null, ri.activityInfo,
+                            null, null, 0, 0, 0, null, 0, null, false, null, null);
+                }
+            }
+        }
+    }
+
+    CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
+        return mCompatModePackages.compatibilityInfoForPackageLocked(ai);
+    }
+
+    void enforceNotIsolatedCaller(String caller) {
+        if (UserHandle.isIsolated(Binder.getCallingUid())) {
+            throw new SecurityException("Isolated process not allowed to call " + caller);
+        }
+    }
+
+    @Override
+    public int getFrontActivityScreenCompatMode() {
+        enforceNotIsolatedCaller("getFrontActivityScreenCompatMode");
+        synchronized (this) {
+            return mCompatModePackages.getFrontActivityScreenCompatModeLocked();
+        }
+    }
+
+    @Override
+    public void setFrontActivityScreenCompatMode(int mode) {
+        enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY,
+                "setFrontActivityScreenCompatMode");
+        synchronized (this) {
+            mCompatModePackages.setFrontActivityScreenCompatModeLocked(mode);
+        }
+    }
+
+    @Override
+    public int getPackageScreenCompatMode(String packageName) {
+        enforceNotIsolatedCaller("getPackageScreenCompatMode");
+        synchronized (this) {
+            return mCompatModePackages.getPackageScreenCompatModeLocked(packageName);
+        }
+    }
+
+    @Override
+    public void setPackageScreenCompatMode(String packageName, int mode) {
+        enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY,
+                "setPackageScreenCompatMode");
+        synchronized (this) {
+            mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode);
+        }
+    }
+
+    @Override
+    public boolean getPackageAskScreenCompat(String packageName) {
+        enforceNotIsolatedCaller("getPackageAskScreenCompat");
+        synchronized (this) {
+            return mCompatModePackages.getPackageAskCompatModeLocked(packageName);
+        }
+    }
+
+    @Override
+    public void setPackageAskScreenCompat(String packageName, boolean ask) {
+        enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY,
+                "setPackageAskScreenCompat");
+        synchronized (this) {
+            mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask);
+        }
+    }
+
+    private void dispatchProcessesChanged() {
+        int N;
+        synchronized (this) {
+            N = mPendingProcessChanges.size();
+            if (mActiveProcessChanges.length < N) {
+                mActiveProcessChanges = new ProcessChangeItem[N];
+            }
+            mPendingProcessChanges.toArray(mActiveProcessChanges);
+            mAvailProcessChanges.addAll(mPendingProcessChanges);
+            mPendingProcessChanges.clear();
+            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "*** Delivering " + N + " process changes");
+        }
+
+        int i = mProcessObservers.beginBroadcast();
+        while (i > 0) {
+            i--;
+            final IProcessObserver observer = mProcessObservers.getBroadcastItem(i);
+            if (observer != null) {
+                try {
+                    for (int j=0; j<N; j++) {
+                        ProcessChangeItem item = mActiveProcessChanges[j];
+                        if ((item.changes&ProcessChangeItem.CHANGE_ACTIVITIES) != 0) {
+                            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "ACTIVITIES CHANGED pid="
+                                    + item.pid + " uid=" + item.uid + ": "
+                                    + item.foregroundActivities);
+                            observer.onForegroundActivitiesChanged(item.pid, item.uid,
+                                    item.foregroundActivities);
+                        }
+                        if ((item.changes&ProcessChangeItem.CHANGE_IMPORTANCE) != 0) {
+                            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "IMPORTANCE CHANGED pid="
+                                    + item.pid + " uid=" + item.uid + ": " + item.importance);
+                            observer.onImportanceChanged(item.pid, item.uid,
+                                    item.importance);
+                        }
+                    }
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        mProcessObservers.finishBroadcast();
+    }
+
+    private void dispatchProcessDied(int pid, int uid) {
+        int i = mProcessObservers.beginBroadcast();
+        while (i > 0) {
+            i--;
+            final IProcessObserver observer = mProcessObservers.getBroadcastItem(i);
+            if (observer != null) {
+                try {
+                    observer.onProcessDied(pid, uid);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        mProcessObservers.finishBroadcast();
+    }
+
+    final void doPendingActivityLaunchesLocked(boolean doResume) {
+        final int N = mPendingActivityLaunches.size();
+        if (N <= 0) {
+            return;
+        }
+        for (int i=0; i<N; i++) {
+            PendingActivityLaunch pal = mPendingActivityLaunches.get(i);
+            mStackSupervisor.startActivityUncheckedLocked(pal.r, pal.sourceRecord, pal.startFlags,
+                    doResume && i == (N-1), null);
+        }
+        mPendingActivityLaunches.clear();
+    }
+
+    @Override
+    public final int startActivity(IApplicationThread caller, String callingPackage,
+            Intent intent, String resolvedType, IBinder resultTo,
+            String resultWho, int requestCode, int startFlags,
+            String profileFile, ParcelFileDescriptor profileFd, Bundle options) {
+        return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo,
+                resultWho, requestCode,
+                startFlags, profileFile, profileFd, options, UserHandle.getCallingUserId());
+    }
+
+    @Override
+    public final int startActivityAsUser(IApplicationThread caller, String callingPackage,
+            Intent intent, String resolvedType, IBinder resultTo,
+            String resultWho, int requestCode, int startFlags,
+            String profileFile, ParcelFileDescriptor profileFd, Bundle options, int userId) {
+        enforceNotIsolatedCaller("startActivity");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "startActivity", null);
+        // TODO: Switch to user app stacks here.
+        return mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType,
+                resultTo, resultWho, requestCode, startFlags, profileFile, profileFd,
+                null, null, options, userId, null);
+    }
+
+    @Override
+    public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage,
+            Intent intent, String resolvedType, IBinder resultTo,
+            String resultWho, int requestCode, int startFlags, String profileFile,
+            ParcelFileDescriptor profileFd, Bundle options, int userId) {
+        enforceNotIsolatedCaller("startActivityAndWait");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "startActivityAndWait", null);
+        WaitResult res = new WaitResult();
+        // TODO: Switch to user app stacks here.
+        mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType,
+                resultTo, resultWho, requestCode, startFlags, profileFile, profileFd,
+                res, null, options, UserHandle.getCallingUserId(), null);
+        return res;
+    }
+
+    @Override
+    public final int startActivityWithConfig(IApplicationThread caller, String callingPackage,
+            Intent intent, String resolvedType, IBinder resultTo,
+            String resultWho, int requestCode, int startFlags, Configuration config,
+            Bundle options, int userId) {
+        enforceNotIsolatedCaller("startActivityWithConfig");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "startActivityWithConfig", null);
+        // TODO: Switch to user app stacks here.
+        int ret = mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent,
+                resolvedType, resultTo, resultWho, requestCode, startFlags,
+                null, null, null, config, options, userId, null);
+        return ret;
+    }
+
+    @Override
+    public int startActivityIntentSender(IApplicationThread caller,
+            IntentSender intent, Intent fillInIntent, String resolvedType,
+            IBinder resultTo, String resultWho, int requestCode,
+            int flagsMask, int flagsValues, Bundle options) {
+        enforceNotIsolatedCaller("startActivityIntentSender");
+        // Refuse possible leaked file descriptors
+        if (fillInIntent != null && fillInIntent.hasFileDescriptors()) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        IIntentSender sender = intent.getTarget();
+        if (!(sender instanceof PendingIntentRecord)) {
+            throw new IllegalArgumentException("Bad PendingIntent object");
+        }
+
+        PendingIntentRecord pir = (PendingIntentRecord)sender;
+
+        synchronized (this) {
+            // If this is coming from the currently resumed activity, it is
+            // effectively saying that app switches are allowed at this point.
+            final ActivityStack stack = getFocusedStack();
+            if (stack.mResumedActivity != null &&
+                    stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) {
+                mAppSwitchesAllowedTime = 0;
+            }
+        }
+        int ret = pir.sendInner(0, fillInIntent, resolvedType, null, null,
+                resultTo, resultWho, requestCode, flagsMask, flagsValues, options, null);
+        return ret;
+    }
+
+    @Override
+    public boolean startNextMatchingActivity(IBinder callingActivity,
+            Intent intent, Bundle options) {
+        // Refuse possible leaked file descriptors
+        if (intent != null && intent.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized (this) {
+            final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity);
+            if (r == null) {
+                ActivityOptions.abort(options);
+                return false;
+            }
+            if (r.app == null || r.app.thread == null) {
+                // The caller is not running...  d'oh!
+                ActivityOptions.abort(options);
+                return false;
+            }
+            intent = new Intent(intent);
+            // The caller is not allowed to change the data.
+            intent.setDataAndType(r.intent.getData(), r.intent.getType());
+            // And we are resetting to find the next component...
+            intent.setComponent(null);
+
+            final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);
+
+            ActivityInfo aInfo = null;
+            try {
+                List<ResolveInfo> resolves =
+                    AppGlobals.getPackageManager().queryIntentActivities(
+                            intent, r.resolvedType,
+                            PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS,
+                            UserHandle.getCallingUserId());
+
+                // Look for the original activity in the list...
+                final int N = resolves != null ? resolves.size() : 0;
+                for (int i=0; i<N; i++) {
+                    ResolveInfo rInfo = resolves.get(i);
+                    if (rInfo.activityInfo.packageName.equals(r.packageName)
+                            && rInfo.activityInfo.name.equals(r.info.name)) {
+                        // We found the current one...  the next matching is
+                        // after it.
+                        i++;
+                        if (i<N) {
+                            aInfo = resolves.get(i).activityInfo;
+                        }
+                        if (debug) {
+                            Slog.v(TAG, "Next matching activity: found current " + r.packageName
+                                    + "/" + r.info.name);
+                            Slog.v(TAG, "Next matching activity: next is " + aInfo.packageName
+                                    + "/" + aInfo.name);
+                        }
+                        break;
+                    }
+                }
+            } catch (RemoteException e) {
+            }
+
+            if (aInfo == null) {
+                // Nobody who is next!
+                ActivityOptions.abort(options);
+                if (debug) Slog.d(TAG, "Next matching activity: nothing found");
+                return false;
+            }
+
+            intent.setComponent(new ComponentName(
+                    aInfo.applicationInfo.packageName, aInfo.name));
+            intent.setFlags(intent.getFlags()&~(
+                    Intent.FLAG_ACTIVITY_FORWARD_RESULT|
+                    Intent.FLAG_ACTIVITY_CLEAR_TOP|
+                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK|
+                    Intent.FLAG_ACTIVITY_NEW_TASK));
+
+            // Okay now we need to start the new activity, replacing the
+            // currently running activity.  This is a little tricky because
+            // we want to start the new one as if the current one is finished,
+            // but not finish the current one first so that there is no flicker.
+            // And thus...
+            final boolean wasFinishing = r.finishing;
+            r.finishing = true;
+
+            // Propagate reply information over to the new activity.
+            final ActivityRecord resultTo = r.resultTo;
+            final String resultWho = r.resultWho;
+            final int requestCode = r.requestCode;
+            r.resultTo = null;
+            if (resultTo != null) {
+                resultTo.removeResultsLocked(r, resultWho, requestCode);
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+            int res = mStackSupervisor.startActivityLocked(r.app.thread, intent,
+                    r.resolvedType, aInfo, resultTo != null ? resultTo.appToken : null,
+                    resultWho, requestCode, -1, r.launchedFromUid, r.launchedFromPackage, 0,
+                    options, false, null, null);
+            Binder.restoreCallingIdentity(origId);
+
+            r.finishing = wasFinishing;
+            if (res != ActivityManager.START_SUCCESS) {
+                return false;
+            }
+            return true;
+        }
+    }
+
+    final int startActivityInPackage(int uid, String callingPackage,
+            Intent intent, String resolvedType, IBinder resultTo,
+            String resultWho, int requestCode, int startFlags, Bundle options, int userId,
+                    IActivityContainer container) {
+
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "startActivityInPackage", null);
+
+        // TODO: Switch to user app stacks here.
+        int ret = mStackSupervisor.startActivityMayWait(null, uid, callingPackage, intent, resolvedType,
+                resultTo, resultWho, requestCode, startFlags,
+                null, null, null, null, options, userId, container);
+        return ret;
+    }
+
+    @Override
+    public final int startActivities(IApplicationThread caller, String callingPackage,
+            Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options,
+            int userId) {
+        enforceNotIsolatedCaller("startActivities");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "startActivity", null);
+        // TODO: Switch to user app stacks here.
+        int ret = mStackSupervisor.startActivities(caller, -1, callingPackage, intents,
+                resolvedTypes, resultTo, options, userId);
+        return ret;
+    }
+
+    final int startActivitiesInPackage(int uid, String callingPackage,
+            Intent[] intents, String[] resolvedTypes, IBinder resultTo,
+            Bundle options, int userId) {
+
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "startActivityInPackage", null);
+        // TODO: Switch to user app stacks here.
+        int ret = mStackSupervisor.startActivities(null, uid, callingPackage, intents, resolvedTypes,
+                resultTo, options, userId);
+        return ret;
+    }
+
+    final void addRecentTaskLocked(TaskRecord task) {
+        int N = mRecentTasks.size();
+        // Quick case: check if the top-most recent task is the same.
+        if (N > 0 && mRecentTasks.get(0) == task) {
+            return;
+        }
+        // Remove any existing entries that are the same kind of task.
+        for (int i=0; i<N; i++) {
+            TaskRecord tr = mRecentTasks.get(i);
+            if (task.userId == tr.userId
+                    && ((task.affinity != null && task.affinity.equals(tr.affinity))
+                    || (task.intent != null && task.intent.filterEquals(tr.intent)))) {
+                tr.disposeThumbnail();
+                mRecentTasks.remove(i);
+                i--;
+                N--;
+                if (task.intent == null) {
+                    // If the new recent task we are adding is not fully
+                    // specified, then replace it with the existing recent task.
+                    task = tr;
+                }
+            }
+        }
+        if (N >= MAX_RECENT_TASKS) {
+            mRecentTasks.remove(N-1).disposeThumbnail();
+        }
+        mRecentTasks.add(0, task);
+    }
+
+    @Override
+    public void reportActivityFullyDrawn(IBinder token) {
+        synchronized (this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                return;
+            }
+            r.reportFullyDrawnLocked();
+        }
+    }
+
+    @Override
+    public void setRequestedOrientation(IBinder token, int requestedOrientation) {
+        synchronized (this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                return;
+            }
+            final long origId = Binder.clearCallingIdentity();
+            mWindowManager.setAppOrientation(r.appToken, requestedOrientation);
+            Configuration config = mWindowManager.updateOrientationFromAppTokens(
+                    mConfiguration, r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
+            if (config != null) {
+                r.frozenBeforeDestroy = true;
+                if (!updateConfigurationLocked(config, r, false, false)) {
+                    mStackSupervisor.resumeTopActivitiesLocked();
+                }
+            }
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public int getRequestedOrientation(IBinder token) {
+        synchronized (this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+            }
+            return mWindowManager.getAppOrientation(r.appToken);
+        }
+    }
+
+    /**
+     * This is the internal entry point for handling Activity.finish().
+     *
+     * @param token The Binder token referencing the Activity we want to finish.
+     * @param resultCode Result code, if any, from this Activity.
+     * @param resultData Result data (Intent), if any, from this Activity.
+     *
+     * @return Returns true if the activity successfully finished, or false if it is still running.
+     */
+    @Override
+    public final boolean finishActivity(IBinder token, int resultCode, Intent resultData) {
+        // Refuse possible leaked file descriptors
+        if (resultData != null && resultData.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized(this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                return true;
+            }
+            if (mController != null) {
+                // Find the first activity that is not finishing.
+                ActivityRecord next = r.task.stack.topRunningActivityLocked(token, 0);
+                if (next != null) {
+                    // ask watcher if this is allowed
+                    boolean resumeOK = true;
+                    try {
+                        resumeOK = mController.activityResuming(next.packageName);
+                    } catch (RemoteException e) {
+                        mController = null;
+                        Watchdog.getInstance().setActivityController(null);
+                    }
+
+                    if (!resumeOK) {
+                        return false;
+                    }
+                }
+            }
+            final long origId = Binder.clearCallingIdentity();
+            boolean res = r.task.stack.requestFinishActivityLocked(token, resultCode,
+                    resultData, "app-request", true);
+            Binder.restoreCallingIdentity(origId);
+            return res;
+        }
+    }
+
+    @Override
+    public final void finishHeavyWeightApp() {
+        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: finishHeavyWeightApp() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        synchronized(this) {
+            if (mHeavyWeightProcess == null) {
+                return;
+            }
+
+            ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(
+                    mHeavyWeightProcess.activities);
+            for (int i=0; i<activities.size(); i++) {
+                ActivityRecord r = activities.get(i);
+                if (!r.finishing) {
+                    r.task.stack.finishActivityLocked(r, Activity.RESULT_CANCELED,
+                            null, "finish-heavy", true);
+                }
+            }
+
+            mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
+                    mHeavyWeightProcess.userId, 0));
+            mHeavyWeightProcess = null;
+        }
+    }
+
+    @Override
+    public void crashApplication(int uid, int initialPid, String packageName,
+            String message) {
+        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: crashApplication() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        synchronized(this) {
+            ProcessRecord proc = null;
+
+            // Figure out which process to kill.  We don't trust that initialPid
+            // still has any relation to current pids, so must scan through the
+            // list.
+            synchronized (mPidsSelfLocked) {
+                for (int i=0; i<mPidsSelfLocked.size(); i++) {
+                    ProcessRecord p = mPidsSelfLocked.valueAt(i);
+                    if (p.uid != uid) {
+                        continue;
+                    }
+                    if (p.pid == initialPid) {
+                        proc = p;
+                        break;
+                    }
+                    if (p.pkgList.containsKey(packageName)) {
+                        proc = p;
+                    }
+                }
+            }
+
+            if (proc == null) {
+                Slog.w(TAG, "crashApplication: nothing for uid=" + uid
+                        + " initialPid=" + initialPid
+                        + " packageName=" + packageName);
+                return;
+            }
+
+            if (proc.thread != null) {
+                if (proc.pid == Process.myPid()) {
+                    Log.w(TAG, "crashApplication: trying to crash self!");
+                    return;
+                }
+                long ident = Binder.clearCallingIdentity();
+                try {
+                    proc.thread.scheduleCrash(message);
+                } catch (RemoteException e) {
+                }
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    @Override
+    public final void finishSubActivity(IBinder token, String resultWho,
+            int requestCode) {
+        synchronized(this) {
+            final long origId = Binder.clearCallingIdentity();
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r != null) {
+                r.task.stack.finishSubActivityLocked(r, resultWho, requestCode);
+            }
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public boolean finishActivityAffinity(IBinder token) {
+        synchronized(this) {
+            final long origId = Binder.clearCallingIdentity();
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            boolean res = false;
+            if (r != null) {
+                res = r.task.stack.finishActivityAffinityLocked(r);
+            }
+            Binder.restoreCallingIdentity(origId);
+            return res;
+        }
+    }
+
+    @Override
+    public boolean willActivityBeVisible(IBinder token) {
+        synchronized(this) {
+            ActivityStack stack = ActivityRecord.getStackLocked(token);
+            if (stack != null) {
+                return stack.willActivityBeVisibleLocked(token);
+            }
+            return false;
+        }
+    }
+
+    @Override
+    public void overridePendingTransition(IBinder token, String packageName,
+            int enterAnim, int exitAnim) {
+        synchronized(this) {
+            ActivityRecord self = ActivityRecord.isInStackLocked(token);
+            if (self == null) {
+                return;
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+
+            if (self.state == ActivityState.RESUMED
+                    || self.state == ActivityState.PAUSING) {
+                mWindowManager.overridePendingAppTransition(packageName,
+                        enterAnim, exitAnim, null);
+            }
+
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    /**
+     * Main function for removing an existing process from the activity manager
+     * as a result of that process going away.  Clears out all connections
+     * to the process.
+     */
+    private final void handleAppDiedLocked(ProcessRecord app,
+            boolean restarting, boolean allowRestart) {
+        int pid = app.pid;
+        cleanUpApplicationRecordLocked(app, restarting, allowRestart, -1);
+        if (!restarting) {
+            removeLruProcessLocked(app);
+            if (pid > 0) {
+                ProcessList.remove(pid);
+            }
+        }
+
+        if (mProfileProc == app) {
+            clearProfilerLocked();
+        }
+
+        // Remove this application's activities from active lists.
+        boolean hasVisibleActivities = mStackSupervisor.handleAppDiedLocked(app);
+
+        app.activities.clear();
+
+        if (app.instrumentationClass != null) {
+            Slog.w(TAG, "Crash of app " + app.processName
+                  + " running instrumentation " + app.instrumentationClass);
+            Bundle info = new Bundle();
+            info.putString("shortMsg", "Process crashed.");
+            finishInstrumentationLocked(app, Activity.RESULT_CANCELED, info);
+        }
+
+        if (!restarting) {
+            if (!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 (hasVisibleActivities) {
+                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
+                }
+            }
+        }
+    }
+
+    private final int getLRURecordIndexForAppLocked(IApplicationThread thread) {
+        IBinder threadBinder = thread.asBinder();
+        // Find the application record.
+        for (int i=mLruProcesses.size()-1; i>=0; i--) {
+            ProcessRecord rec = mLruProcesses.get(i);
+            if (rec.thread != null && rec.thread.asBinder() == threadBinder) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    final ProcessRecord getRecordForAppLocked(
+            IApplicationThread thread) {
+        if (thread == null) {
+            return null;
+        }
+
+        int appIndex = getLRURecordIndexForAppLocked(thread);
+        return appIndex >= 0 ? mLruProcesses.get(appIndex) : null;
+    }
+
+    final void doLowMemReportIfNeededLocked(ProcessRecord dyingProc) {
+        // If there are no longer any background processes running,
+        // and the app that died was not running instrumentation,
+        // then tell everyone we are now low on memory.
+        boolean haveBg = false;
+        for (int i=mLruProcesses.size()-1; i>=0; i--) {
+            ProcessRecord rec = mLruProcesses.get(i);
+            if (rec.thread != null
+                    && rec.setProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
+                haveBg = true;
+                break;
+            }
+        }
+
+        if (!haveBg) {
+            boolean doReport = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+            if (doReport) {
+                long now = SystemClock.uptimeMillis();
+                if (now < (mLastMemUsageReportTime+5*60*1000)) {
+                    doReport = false;
+                } else {
+                    mLastMemUsageReportTime = now;
+                }
+            }
+            final ArrayList<ProcessMemInfo> memInfos
+                    = doReport ? new ArrayList<ProcessMemInfo>(mLruProcesses.size()) : null;
+            EventLog.writeEvent(EventLogTags.AM_LOW_MEMORY, mLruProcesses.size());
+            long now = SystemClock.uptimeMillis();
+            for (int i=mLruProcesses.size()-1; i>=0; i--) {
+                ProcessRecord rec = mLruProcesses.get(i);
+                if (rec == dyingProc || rec.thread == null) {
+                    continue;
+                }
+                if (doReport) {
+                    memInfos.add(new ProcessMemInfo(rec.processName, rec.pid, rec.setAdj,
+                            rec.setProcState, rec.adjType, rec.makeAdjReason()));
+                }
+                if ((rec.lastLowMemory+GC_MIN_INTERVAL) <= now) {
+                    // The low memory report is overriding any current
+                    // state for a GC request.  Make sure to do
+                    // heavy/important/visible/foreground processes first.
+                    if (rec.setAdj <= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
+                        rec.lastRequestedGc = 0;
+                    } else {
+                        rec.lastRequestedGc = rec.lastLowMemory;
+                    }
+                    rec.reportLowMemory = true;
+                    rec.lastLowMemory = now;
+                    mProcessesToGc.remove(rec);
+                    addProcessToGcListLocked(rec);
+                }
+            }
+            if (doReport) {
+                Message msg = mHandler.obtainMessage(REPORT_MEM_USAGE_MSG, memInfos);
+                mHandler.sendMessage(msg);
+            }
+            scheduleAppGcsLocked();
+        }
+    }
+
+    final void appDiedLocked(ProcessRecord app, int pid,
+            IApplicationThread thread) {
+
+        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+        synchronized (stats) {
+            stats.noteProcessDiedLocked(app.info.uid, pid);
+        }
+
+        // Clean up already done if the process has been re-started.
+        if (app.pid == pid && app.thread != null &&
+                app.thread.asBinder() == thread.asBinder()) {
+            boolean doLowMem = app.instrumentationClass == null;
+            boolean doOomAdj = doLowMem;
+            if (!app.killedByAm) {
+                Slog.i(TAG, "Process " + app.processName + " (pid " + pid
+                        + ") has died.");
+                mAllowLowerMemLevel = true;
+            } else {
+                // Note that we always want to do oom adj to update our state with the
+                // new number of procs.
+                mAllowLowerMemLevel = false;
+                doLowMem = false;
+            }
+            EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.userId, app.pid, app.processName);
+            if (DEBUG_CLEANUP) Slog.v(
+                TAG, "Dying app: " + app + ", pid: " + pid
+                + ", thread: " + thread.asBinder());
+            handleAppDiedLocked(app, false, true);
+
+            if (doOomAdj) {
+                updateOomAdjLocked();
+            }
+            if (doLowMem) {
+                doLowMemReportIfNeededLocked(app);
+            }
+        } else if (app.pid != pid) {
+            // A new process has already been started.
+            Slog.i(TAG, "Process " + app.processName + " (pid " + pid
+                    + ") has died and restarted (pid " + app.pid + ").");
+            EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.userId, app.pid, app.processName);
+        } else if (DEBUG_PROCESSES) {
+            Slog.d(TAG, "Received spurious death notification for thread "
+                    + thread.asBinder());
+        }
+    }
+
+    /**
+     * If a stack trace dump file is configured, dump process stack traces.
+     * @param clearTraces causes the dump file to be erased prior to the new
+     *    traces being written, if true; when false, the new traces will be
+     *    appended to any existing file content.
+     * @param firstPids of dalvik VM processes to dump stack traces for first
+     * @param lastPids of dalvik VM processes to dump stack traces for last
+     * @param nativeProcs optional list of native process names to dump stack crawls
+     * @return file containing stack traces, or null if no dump file is configured
+     */
+    public static File dumpStackTraces(boolean clearTraces, ArrayList<Integer> firstPids,
+            ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids, String[] nativeProcs) {
+        String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
+        if (tracesPath == null || tracesPath.length() == 0) {
+            return null;
+        }
+
+        File tracesFile = new File(tracesPath);
+        try {
+            File tracesDir = tracesFile.getParentFile();
+            if (!tracesDir.exists()) {
+                tracesFile.mkdirs();
+                if (!SELinux.restorecon(tracesDir)) {
+                    return null;
+                }
+            }
+            FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);  // drwxrwxr-x
+
+            if (clearTraces && tracesFile.exists()) tracesFile.delete();
+            tracesFile.createNewFile();
+            FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw-
+        } catch (IOException e) {
+            Slog.w(TAG, "Unable to prepare ANR traces file: " + tracesPath, e);
+            return null;
+        }
+
+        dumpStackTraces(tracesPath, firstPids, processCpuTracker, lastPids, nativeProcs);
+        return tracesFile;
+    }
+
+    private static void dumpStackTraces(String tracesPath, ArrayList<Integer> firstPids,
+            ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids, String[] nativeProcs) {
+        // Use a FileObserver to detect when traces finish writing.
+        // The order of traces is considered important to maintain for legibility.
+        FileObserver observer = new FileObserver(tracesPath, FileObserver.CLOSE_WRITE) {
+            @Override
+            public synchronized void onEvent(int event, String path) { notify(); }
+        };
+
+        try {
+            observer.startWatching();
+
+            // First collect all of the stacks of the most important pids.
+            if (firstPids != null) {
+                try {
+                    int num = firstPids.size();
+                    for (int i = 0; i < num; i++) {
+                        synchronized (observer) {
+                            Process.sendSignal(firstPids.get(i), Process.SIGNAL_QUIT);
+                            observer.wait(200);  // Wait for write-close, give up after 200msec
+                        }
+                    }
+                } catch (InterruptedException e) {
+                    Log.wtf(TAG, e);
+                }
+            }
+
+            // Next collect the stacks of the native pids
+            if (nativeProcs != null) {
+                int[] pids = Process.getPidsForCommands(nativeProcs);
+                if (pids != null) {
+                    for (int pid : pids) {
+                        Debug.dumpNativeBacktraceToFile(pid, tracesPath);
+                    }
+                }
+            }
+
+            // Lastly, measure CPU usage.
+            if (processCpuTracker != null) {
+                processCpuTracker.init();
+                System.gc();
+                processCpuTracker.update();
+                try {
+                    synchronized (processCpuTracker) {
+                        processCpuTracker.wait(500); // measure over 1/2 second.
+                    }
+                } catch (InterruptedException e) {
+                }
+                processCpuTracker.update();
+
+                // We'll take the stack crawls of just the top apps using CPU.
+                final int N = processCpuTracker.countWorkingStats();
+                int numProcs = 0;
+                for (int i=0; i<N && numProcs<5; i++) {
+                    ProcessCpuTracker.Stats stats = processCpuTracker.getWorkingStats(i);
+                    if (lastPids.indexOfKey(stats.pid) >= 0) {
+                        numProcs++;
+                        try {
+                            synchronized (observer) {
+                                Process.sendSignal(stats.pid, Process.SIGNAL_QUIT);
+                                observer.wait(200);  // Wait for write-close, give up after 200msec
+                            }
+                        } catch (InterruptedException e) {
+                            Log.wtf(TAG, e);
+                        }
+
+                    }
+                }
+            }
+        } finally {
+            observer.stopWatching();
+        }
+    }
+
+    final void logAppTooSlow(ProcessRecord app, long startTime, String msg) {
+        if (true || IS_USER_BUILD) {
+            return;
+        }
+        String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
+        if (tracesPath == null || tracesPath.length() == 0) {
+            return;
+        }
+
+        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+        StrictMode.allowThreadDiskWrites();
+        try {
+            final File tracesFile = new File(tracesPath);
+            final File tracesDir = tracesFile.getParentFile();
+            final File tracesTmp = new File(tracesDir, "__tmp__");
+            try {
+                if (!tracesDir.exists()) {
+                    tracesFile.mkdirs();
+                    if (!SELinux.restorecon(tracesDir.getPath())) {
+                        return;
+                    }
+                }
+                FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);  // drwxrwxr-x
+
+                if (tracesFile.exists()) {
+                    tracesTmp.delete();
+                    tracesFile.renameTo(tracesTmp);
+                }
+                StringBuilder sb = new StringBuilder();
+                Time tobj = new Time();
+                tobj.set(System.currentTimeMillis());
+                sb.append(tobj.format("%Y-%m-%d %H:%M:%S"));
+                sb.append(": ");
+                TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb);
+                sb.append(" since ");
+                sb.append(msg);
+                FileOutputStream fos = new FileOutputStream(tracesFile);
+                fos.write(sb.toString().getBytes());
+                if (app == null) {
+                    fos.write("\n*** No application process!".getBytes());
+                }
+                fos.close();
+                FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw-
+            } catch (IOException e) {
+                Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesPath, e);
+                return;
+            }
+
+            if (app != null) {
+                ArrayList<Integer> firstPids = new ArrayList<Integer>();
+                firstPids.add(app.pid);
+                dumpStackTraces(tracesPath, firstPids, null, null, null);
+            }
+
+            File lastTracesFile = null;
+            File curTracesFile = null;
+            for (int i=9; i>=0; i--) {
+                String name = String.format(Locale.US, "slow%02d.txt", i);
+                curTracesFile = new File(tracesDir, name);
+                if (curTracesFile.exists()) {
+                    if (lastTracesFile != null) {
+                        curTracesFile.renameTo(lastTracesFile);
+                    } else {
+                        curTracesFile.delete();
+                    }
+                }
+                lastTracesFile = curTracesFile;
+            }
+            tracesFile.renameTo(curTracesFile);
+            if (tracesTmp.exists()) {
+                tracesTmp.renameTo(tracesFile);
+            }
+        } finally {
+            StrictMode.setThreadPolicy(oldPolicy);
+        }
+    }
+
+    final void appNotResponding(ProcessRecord app, ActivityRecord activity,
+            ActivityRecord parent, boolean aboveSystem, final String annotation) {
+        ArrayList<Integer> firstPids = new ArrayList<Integer>(5);
+        SparseArray<Boolean> lastPids = new SparseArray<Boolean>(20);
+
+        if (mController != null) {
+            try {
+                // 0 == continue, -1 = kill process immediately
+                int res = mController.appEarlyNotResponding(app.processName, app.pid, annotation);
+                if (res < 0 && app.pid != MY_PID) Process.killProcess(app.pid);
+            } catch (RemoteException e) {
+                mController = null;
+                Watchdog.getInstance().setActivityController(null);
+            }
+        }
+
+        long anrTime = SystemClock.uptimeMillis();
+        if (MONITOR_CPU_USAGE) {
+            updateCpuStatsNow();
+        }
+
+        synchronized (this) {
+            // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
+            if (mShuttingDown) {
+                Slog.i(TAG, "During shutdown skipping ANR: " + app + " " + annotation);
+                return;
+            } else if (app.notResponding) {
+                Slog.i(TAG, "Skipping duplicate ANR: " + app + " " + annotation);
+                return;
+            } else if (app.crashing) {
+                Slog.i(TAG, "Crashing app skipping ANR: " + app + " " + annotation);
+                return;
+            }
+
+            // In case we come through here for the same app before completing
+            // this one, mark as anring now so we will bail out.
+            app.notResponding = true;
+
+            // Log the ANR to the event log.
+            EventLog.writeEvent(EventLogTags.AM_ANR, app.userId, app.pid,
+                    app.processName, app.info.flags, annotation);
+
+            // Dump thread traces as quickly as we can, starting with "interesting" processes.
+            firstPids.add(app.pid);
+
+            int parentPid = app.pid;
+            if (parent != null && parent.app != null && parent.app.pid > 0) parentPid = parent.app.pid;
+            if (parentPid != app.pid) firstPids.add(parentPid);
+
+            if (MY_PID != app.pid && MY_PID != parentPid) firstPids.add(MY_PID);
+
+            for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
+                ProcessRecord r = mLruProcesses.get(i);
+                if (r != null && r.thread != null) {
+                    int pid = r.pid;
+                    if (pid > 0 && pid != app.pid && pid != parentPid && pid != MY_PID) {
+                        if (r.persistent) {
+                            firstPids.add(pid);
+                        } else {
+                            lastPids.put(pid, Boolean.TRUE);
+                        }
+                    }
+                }
+            }
+        }
+
+        // Log the ANR to the main log.
+        StringBuilder info = new StringBuilder();
+        info.setLength(0);
+        info.append("ANR in ").append(app.processName);
+        if (activity != null && activity.shortComponentName != null) {
+            info.append(" (").append(activity.shortComponentName).append(")");
+        }
+        info.append("\n");
+        info.append("PID: ").append(app.pid).append("\n");
+        if (annotation != null) {
+            info.append("Reason: ").append(annotation).append("\n");
+        }
+        if (parent != null && parent != activity) {
+            info.append("Parent: ").append(parent.shortComponentName).append("\n");
+        }
+
+        final ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
+
+        File tracesFile = dumpStackTraces(true, firstPids, processCpuTracker, lastPids,
+                NATIVE_STACKS_OF_INTEREST);
+
+        String cpuInfo = null;
+        if (MONITOR_CPU_USAGE) {
+            updateCpuStatsNow();
+            synchronized (mProcessCpuThread) {
+                cpuInfo = mProcessCpuTracker.printCurrentState(anrTime);
+            }
+            info.append(processCpuTracker.printCurrentLoad());
+            info.append(cpuInfo);
+        }
+
+        info.append(processCpuTracker.printCurrentState(anrTime));
+
+        Slog.e(TAG, info.toString());
+        if (tracesFile == null) {
+            // There is no trace file, so dump (only) the alleged culprit's threads to the log
+            Process.sendSignal(app.pid, Process.SIGNAL_QUIT);
+        }
+
+        addErrorToDropBox("anr", app, app.processName, activity, parent, annotation,
+                cpuInfo, tracesFile, null);
+
+        if (mController != null) {
+            try {
+                // 0 == show dialog, 1 = keep waiting, -1 = kill process immediately
+                int res = mController.appNotResponding(app.processName, app.pid, info.toString());
+                if (res != 0) {
+                    if (res < 0 && app.pid != MY_PID) {
+                        Process.killProcess(app.pid);
+                    } else {
+                        synchronized (this) {
+                            mServices.scheduleServiceTimeoutLocked(app);
+                        }
+                    }
+                    return;
+                }
+            } catch (RemoteException e) {
+                mController = null;
+                Watchdog.getInstance().setActivityController(null);
+            }
+        }
+
+        // Unless configured otherwise, swallow ANRs in background processes & kill the process.
+        boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
+                Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
+
+        synchronized (this) {
+            if (!showBackground && !app.isInterestingToUserLocked() && app.pid != MY_PID) {
+                killUnneededProcessLocked(app, "background ANR");
+                return;
+            }
+
+            // Set the app's notResponding state, and look up the errorReportReceiver
+            makeAppNotRespondingLocked(app,
+                    activity != null ? activity.shortComponentName : null,
+                    annotation != null ? "ANR " + annotation : "ANR",
+                    info.toString());
+
+            // Bring up the infamous App Not Responding dialog
+            Message msg = Message.obtain();
+            HashMap<String, Object> map = new HashMap<String, Object>();
+            msg.what = SHOW_NOT_RESPONDING_MSG;
+            msg.obj = map;
+            msg.arg1 = aboveSystem ? 1 : 0;
+            map.put("app", app);
+            if (activity != null) {
+                map.put("activity", activity);
+            }
+
+            mHandler.sendMessage(msg);
+        }
+    }
+
+    final void showLaunchWarningLocked(final ActivityRecord cur, final ActivityRecord next) {
+        if (!mLaunchWarningShown) {
+            mLaunchWarningShown = true;
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    synchronized (ActivityManagerService.this) {
+                        final Dialog d = new LaunchWarningWindow(mContext, cur, next);
+                        d.show();
+                        mHandler.postDelayed(new Runnable() {
+                            @Override
+                            public void run() {
+                                synchronized (ActivityManagerService.this) {
+                                    d.dismiss();
+                                    mLaunchWarningShown = false;
+                                }
+                            }
+                        }, 4000);
+                    }
+                }
+            });
+        }
+    }
+
+    @Override
+    public boolean clearApplicationUserData(final String packageName,
+            final IPackageDataObserver observer, int userId) {
+        enforceNotIsolatedCaller("clearApplicationUserData");
+        int uid = Binder.getCallingUid();
+        int pid = Binder.getCallingPid();
+        userId = handleIncomingUser(pid, uid,
+                userId, false, true, "clearApplicationUserData", null);
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            IPackageManager pm = AppGlobals.getPackageManager();
+            int pkgUid = -1;
+            synchronized(this) {
+                try {
+                    pkgUid = pm.getPackageUid(packageName, userId);
+                } catch (RemoteException e) {
+                }
+                if (pkgUid == -1) {
+                    Slog.w(TAG, "Invalid packageName: " + packageName);
+                    if (observer != null) {
+                        try {
+                            observer.onRemoveCompleted(packageName, false);
+                        } catch (RemoteException e) {
+                            Slog.i(TAG, "Observer no longer exists.");
+                        }
+                    }
+                    return false;
+                }
+                if (uid == pkgUid || checkComponentPermission(
+                        android.Manifest.permission.CLEAR_APP_USER_DATA,
+                        pid, uid, -1, true)
+                        == PackageManager.PERMISSION_GRANTED) {
+                    forceStopPackageLocked(packageName, pkgUid, "clear data");
+                } else {
+                    throw new SecurityException("PID " + pid + " does not have permission "
+                            + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data"
+                                    + " of package " + packageName);
+                }
+            }
+
+            try {
+                // Clear application user data
+                pm.clearApplicationUserData(packageName, observer, userId);
+
+                // Remove all permissions granted from/to this package
+                removeUriPermissionsForPackageLocked(packageName, userId, true);
+
+                Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED,
+                        Uri.fromParts("package", packageName, null));
+                intent.putExtra(Intent.EXTRA_UID, pkgUid);
+                broadcastIntentInPackage("android", Process.SYSTEM_UID, intent,
+                        null, null, 0, null, null, null, false, false, userId);
+            } catch (RemoteException e) {
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+        return true;
+    }
+
+    @Override
+    public void killBackgroundProcesses(final String packageName, int userId) {
+        if (checkCallingPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES)
+                != PackageManager.PERMISSION_GRANTED &&
+                checkCallingPermission(android.Manifest.permission.RESTART_PACKAGES)
+                        != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: killBackgroundProcesses() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.KILL_BACKGROUND_PROCESSES;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
+                userId, true, true, "killBackgroundProcesses", null);
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            IPackageManager pm = AppGlobals.getPackageManager();
+            synchronized(this) {
+                int appId = -1;
+                try {
+                    appId = UserHandle.getAppId(pm.getPackageUid(packageName, 0));
+                } catch (RemoteException e) {
+                }
+                if (appId == -1) {
+                    Slog.w(TAG, "Invalid packageName: " + packageName);
+                    return;
+                }
+                killPackageProcessesLocked(packageName, appId, userId,
+                        ProcessList.SERVICE_ADJ, false, true, true, false, "kill background");
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+    }
+
+    @Override
+    public void killAllBackgroundProcesses() {
+        if (checkCallingPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: killAllBackgroundProcesses() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.KILL_BACKGROUND_PROCESSES;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            synchronized(this) {
+                ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
+                final int NP = mProcessNames.getMap().size();
+                for (int ip=0; ip<NP; ip++) {
+                    SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
+                    final int NA = apps.size();
+                    for (int ia=0; ia<NA; ia++) {
+                        ProcessRecord app = apps.valueAt(ia);
+                        if (app.persistent) {
+                            // we don't kill persistent processes
+                            continue;
+                        }
+                        if (app.removed) {
+                            procs.add(app);
+                        } else if (app.setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
+                            app.removed = true;
+                            procs.add(app);
+                        }
+                    }
+                }
+
+                int N = procs.size();
+                for (int i=0; i<N; i++) {
+                    removeProcessLocked(procs.get(i), false, true, "kill all background");
+                }
+                mAllowLowerMemLevel = true;
+                updateOomAdjLocked();
+                doLowMemReportIfNeededLocked(null);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+    }
+
+    @Override
+    public void forceStopPackage(final String packageName, int userId) {
+        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: forceStopPackage() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+        final int callingPid = Binder.getCallingPid();
+        userId = handleIncomingUser(callingPid, Binder.getCallingUid(),
+                userId, true, true, "forceStopPackage", null);
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            IPackageManager pm = AppGlobals.getPackageManager();
+            synchronized(this) {
+                int[] users = userId == UserHandle.USER_ALL
+                        ? getUsersLocked() : new int[] { userId };
+                for (int user : users) {
+                    int pkgUid = -1;
+                    try {
+                        pkgUid = pm.getPackageUid(packageName, user);
+                    } catch (RemoteException e) {
+                    }
+                    if (pkgUid == -1) {
+                        Slog.w(TAG, "Invalid packageName: " + packageName);
+                        continue;
+                    }
+                    try {
+                        pm.setPackageStoppedState(packageName, true, user);
+                    } catch (RemoteException e) {
+                    } catch (IllegalArgumentException e) {
+                        Slog.w(TAG, "Failed trying to unstop package "
+                                + packageName + ": " + e);
+                    }
+                    if (isUserRunningLocked(user, false)) {
+                        forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid);
+                    }
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+    }
+
+    /*
+     * The pkg name and app id have to be specified.
+     */
+    @Override
+    public void killApplicationWithAppId(String pkg, int appid, String reason) {
+        if (pkg == null) {
+            return;
+        }
+        // Make sure the uid is valid.
+        if (appid < 0) {
+            Slog.w(TAG, "Invalid appid specified for pkg : " + pkg);
+            return;
+        }
+        int callerUid = Binder.getCallingUid();
+        // Only the system server can kill an application
+        if (callerUid == Process.SYSTEM_UID) {
+            // Post an aysnc message to kill the application
+            Message msg = mHandler.obtainMessage(KILL_APPLICATION_MSG);
+            msg.arg1 = appid;
+            msg.arg2 = 0;
+            Bundle bundle = new Bundle();
+            bundle.putString("pkg", pkg);
+            bundle.putString("reason", reason);
+            msg.obj = bundle;
+            mHandler.sendMessage(msg);
+        } else {
+            throw new SecurityException(callerUid + " cannot kill pkg: " +
+                    pkg);
+        }
+    }
+
+    @Override
+    public void closeSystemDialogs(String reason) {
+        enforceNotIsolatedCaller("closeSystemDialogs");
+
+        final int pid = Binder.getCallingPid();
+        final int uid = Binder.getCallingUid();
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                // Only allow this from foreground processes, so that background
+                // applications can't abuse it to prevent system UI from being shown.
+                if (uid >= Process.FIRST_APPLICATION_UID) {
+                    ProcessRecord proc;
+                    synchronized (mPidsSelfLocked) {
+                        proc = mPidsSelfLocked.get(pid);
+                    }
+                    if (proc.curRawAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+                        Slog.w(TAG, "Ignoring closeSystemDialogs " + reason
+                                + " from background process " + proc);
+                        return;
+                    }
+                }
+                closeSystemDialogsLocked(reason);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    void closeSystemDialogsLocked(String reason) {
+        Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                | Intent.FLAG_RECEIVER_FOREGROUND);
+        if (reason != null) {
+            intent.putExtra("reason", reason);
+        }
+        mWindowManager.closeSystemDialogs(reason);
+
+        mStackSupervisor.closeSystemDialogsLocked();
+
+        broadcastIntentLocked(null, null, intent, null,
+                null, 0, null, null, null, AppOpsManager.OP_NONE, false, false, -1,
+                Process.SYSTEM_UID, UserHandle.USER_ALL);
+    }
+
+    @Override
+    public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
+        enforceNotIsolatedCaller("getProcessMemoryInfo");
+        Debug.MemoryInfo[] infos = new Debug.MemoryInfo[pids.length];
+        for (int i=pids.length-1; i>=0; i--) {
+            ProcessRecord proc;
+            int oomAdj;
+            synchronized (this) {
+                synchronized (mPidsSelfLocked) {
+                    proc = mPidsSelfLocked.get(pids[i]);
+                    oomAdj = proc != null ? proc.setAdj : 0;
+                }
+            }
+            infos[i] = new Debug.MemoryInfo();
+            Debug.getMemoryInfo(pids[i], infos[i]);
+            if (proc != null) {
+                synchronized (this) {
+                    if (proc.thread != null && proc.setAdj == oomAdj) {
+                        // Record this for posterity if the process has been stable.
+                        proc.baseProcessTracker.addPss(infos[i].getTotalPss(),
+                                infos[i].getTotalUss(), false, proc.pkgList);
+                    }
+                }
+            }
+        }
+        return infos;
+    }
+
+    @Override
+    public long[] getProcessPss(int[] pids) {
+        enforceNotIsolatedCaller("getProcessPss");
+        long[] pss = new long[pids.length];
+        for (int i=pids.length-1; i>=0; i--) {
+            ProcessRecord proc;
+            int oomAdj;
+            synchronized (this) {
+                synchronized (mPidsSelfLocked) {
+                    proc = mPidsSelfLocked.get(pids[i]);
+                    oomAdj = proc != null ? proc.setAdj : 0;
+                }
+            }
+            long[] tmpUss = new long[1];
+            pss[i] = Debug.getPss(pids[i], tmpUss);
+            if (proc != null) {
+                synchronized (this) {
+                    if (proc.thread != null && proc.setAdj == oomAdj) {
+                        // Record this for posterity if the process has been stable.
+                        proc.baseProcessTracker.addPss(pss[i], tmpUss[0], false, proc.pkgList);
+                    }
+                }
+            }
+        }
+        return pss;
+    }
+
+    @Override
+    public void killApplicationProcess(String processName, int uid) {
+        if (processName == null) {
+            return;
+        }
+
+        int callerUid = Binder.getCallingUid();
+        // Only the system server can kill an application
+        if (callerUid == Process.SYSTEM_UID) {
+            synchronized (this) {
+                ProcessRecord app = getProcessRecordLocked(processName, uid, true);
+                if (app != null && app.thread != null) {
+                    try {
+                        app.thread.scheduleSuicide();
+                    } catch (RemoteException e) {
+                        // If the other end already died, then our work here is done.
+                    }
+                } else {
+                    Slog.w(TAG, "Process/uid not found attempting kill of "
+                            + processName + " / " + uid);
+                }
+            }
+        } else {
+            throw new SecurityException(callerUid + " cannot kill app process: " +
+                    processName);
+        }
+    }
+
+    private void forceStopPackageLocked(final String packageName, int uid, String reason) {
+        forceStopPackageLocked(packageName, UserHandle.getAppId(uid), false,
+                false, true, false, UserHandle.getUserId(uid), reason);
+        Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED,
+                Uri.fromParts("package", packageName, null));
+        if (!mProcessesReady) {
+            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                    | Intent.FLAG_RECEIVER_FOREGROUND);
+        }
+        intent.putExtra(Intent.EXTRA_UID, uid);
+        intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(uid));
+        broadcastIntentLocked(null, null, intent,
+                null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                false, false,
+                MY_PID, Process.SYSTEM_UID, UserHandle.getUserId(uid));
+    }
+
+    private void forceStopUserLocked(int userId, String reason) {
+        forceStopPackageLocked(null, -1, false, false, true, false, userId, reason);
+        Intent intent = new Intent(Intent.ACTION_USER_STOPPED);
+        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                | Intent.FLAG_RECEIVER_FOREGROUND);
+        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
+        broadcastIntentLocked(null, null, intent,
+                null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                false, false,
+                MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+    }
+
+    private final boolean killPackageProcessesLocked(String packageName, int appId,
+            int userId, int minOomAdj, boolean callerWillRestart, boolean allowRestart,
+            boolean doit, boolean evenPersistent, String reason) {
+        ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
+
+        // Remove all processes this package may have touched: all with the
+        // same UID (except for the system or root user), and all whose name
+        // matches the package name.
+        final String procNamePrefix = packageName != null ? (packageName + ":") : null;
+        final int NP = mProcessNames.getMap().size();
+        for (int ip=0; ip<NP; ip++) {
+            SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
+            final int NA = apps.size();
+            for (int ia=0; ia<NA; ia++) {
+                ProcessRecord app = apps.valueAt(ia);
+                if (app.persistent && !evenPersistent) {
+                    // we don't kill persistent processes
+                    continue;
+                }
+                if (app.removed) {
+                    if (doit) {
+                        procs.add(app);
+                    }
+                    continue;
+                }
+
+                // Skip process if it doesn't meet our oom adj requirement.
+                if (app.setAdj < minOomAdj) {
+                    continue;
+                }
+
+                // If no package is specified, we call all processes under the
+                // give user id.
+                if (packageName == null) {
+                    if (app.userId != userId) {
+                        continue;
+                    }
+                    if (appId >= 0 && UserHandle.getAppId(app.uid) != appId) {
+                        continue;
+                    }
+                // Package has been specified, we want to hit all processes
+                // that match it.  We need to qualify this by the processes
+                // that are running under the specified app and user ID.
+                } else {
+                    if (UserHandle.getAppId(app.uid) != appId) {
+                        continue;
+                    }
+                    if (userId != UserHandle.USER_ALL && app.userId != userId) {
+                        continue;
+                    }
+                    if (!app.pkgList.containsKey(packageName)) {
+                        continue;
+                    }
+                }
+
+                // Process has passed all conditions, kill it!
+                if (!doit) {
+                    return true;
+                }
+                app.removed = true;
+                procs.add(app);
+            }
+        }
+
+        int N = procs.size();
+        for (int i=0; i<N; i++) {
+            removeProcessLocked(procs.get(i), callerWillRestart, allowRestart, reason);
+        }
+        updateOomAdjLocked();
+        return N > 0;
+    }
+
+    private final boolean forceStopPackageLocked(String name, int appId,
+            boolean callerWillRestart, boolean purgeCache, boolean doit,
+            boolean evenPersistent, int userId, String reason) {
+        int i;
+        int N;
+
+        if (userId == UserHandle.USER_ALL && name == null) {
+            Slog.w(TAG, "Can't force stop all processes of all users, that is insane!");
+        }
+
+        if (appId < 0 && name != null) {
+            try {
+                appId = UserHandle.getAppId(
+                        AppGlobals.getPackageManager().getPackageUid(name, 0));
+            } catch (RemoteException e) {
+            }
+        }
+
+        if (doit) {
+            if (name != null) {
+                Slog.i(TAG, "Force stopping " + name + " appid=" + appId
+                        + " user=" + userId + ": " + reason);
+            } else {
+                Slog.i(TAG, "Force stopping u" + userId + ": " + reason);
+            }
+
+            final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
+            for (int ip=pmap.size()-1; ip>=0; ip--) {
+                SparseArray<Long> ba = pmap.valueAt(ip);
+                for (i=ba.size()-1; i>=0; i--) {
+                    boolean remove = false;
+                    final int entUid = ba.keyAt(i);
+                    if (name != null) {
+                        if (userId == UserHandle.USER_ALL) {
+                            if (UserHandle.getAppId(entUid) == appId) {
+                                remove = true;
+                            }
+                        } else {
+                            if (entUid == UserHandle.getUid(userId, appId)) {
+                                remove = true;
+                            }
+                        }
+                    } else if (UserHandle.getUserId(entUid) == userId) {
+                        remove = true;
+                    }
+                    if (remove) {
+                        ba.removeAt(i);
+                    }
+                }
+                if (ba.size() == 0) {
+                    pmap.removeAt(ip);
+                }
+            }
+        }
+
+        boolean didSomething = killPackageProcessesLocked(name, appId, userId,
+                -100, callerWillRestart, true, doit, evenPersistent,
+                name == null ? ("stop user " + userId) : ("stop " + name));
+
+        if (mStackSupervisor.forceStopPackageLocked(name, doit, evenPersistent, userId)) {
+            if (!doit) {
+                return true;
+            }
+            didSomething = true;
+        }
+
+        if (mServices.forceStopLocked(name, userId, evenPersistent, doit)) {
+            if (!doit) {
+                return true;
+            }
+            didSomething = true;
+        }
+
+        if (name == null) {
+            // Remove all sticky broadcasts from this user.
+            mStickyBroadcasts.remove(userId);
+        }
+
+        ArrayList<ContentProviderRecord> providers = new ArrayList<ContentProviderRecord>();
+        if (mProviderMap.collectForceStopProviders(name, appId, doit, evenPersistent,
+                userId, providers)) {
+            if (!doit) {
+                return true;
+            }
+            didSomething = true;
+        }
+        N = providers.size();
+        for (i=0; i<N; i++) {
+            removeDyingProviderLocked(null, providers.get(i), true);
+        }
+
+        // Remove transient permissions granted from/to this package/user
+        removeUriPermissionsForPackageLocked(name, userId, false);
+
+        if (name == null) {
+            // Remove pending intents.  For now we only do this when force
+            // stopping users, because we have some problems when doing this
+            // for packages -- app widgets are not currently cleaned up for
+            // such packages, so they can be left with bad pending intents.
+            if (mIntentSenderRecords.size() > 0) {
+                Iterator<WeakReference<PendingIntentRecord>> it
+                        = mIntentSenderRecords.values().iterator();
+                while (it.hasNext()) {
+                    WeakReference<PendingIntentRecord> wpir = it.next();
+                    if (wpir == null) {
+                        it.remove();
+                        continue;
+                    }
+                    PendingIntentRecord pir = wpir.get();
+                    if (pir == null) {
+                        it.remove();
+                        continue;
+                    }
+                    if (name == null) {
+                        // Stopping user, remove all objects for the user.
+                        if (pir.key.userId != userId) {
+                            // Not the same user, skip it.
+                            continue;
+                        }
+                    } else {
+                        if (UserHandle.getAppId(pir.uid) != appId) {
+                            // Different app id, skip it.
+                            continue;
+                        }
+                        if (userId != UserHandle.USER_ALL && pir.key.userId != userId) {
+                            // Different user, skip it.
+                            continue;
+                        }
+                        if (!pir.key.packageName.equals(name)) {
+                            // Different package, skip it.
+                            continue;
+                        }
+                    }
+                    if (!doit) {
+                        return true;
+                    }
+                    didSomething = true;
+                    it.remove();
+                    pir.canceled = true;
+                    if (pir.key.activity != null) {
+                        pir.key.activity.pendingResults.remove(pir.ref);
+                    }
+                }
+            }
+        }
+
+        if (doit) {
+            if (purgeCache && name != null) {
+                AttributeCache ac = AttributeCache.instance();
+                if (ac != null) {
+                    ac.removePackage(name);
+                }
+            }
+            if (mBooted) {
+                mStackSupervisor.resumeTopActivitiesLocked();
+                mStackSupervisor.scheduleIdleLocked();
+            }
+        }
+
+        return didSomething;
+    }
+
+    private final boolean removeProcessLocked(ProcessRecord app,
+            boolean callerWillRestart, boolean allowRestart, String reason) {
+        final String name = app.processName;
+        final int uid = app.uid;
+        if (DEBUG_PROCESSES) Slog.d(
+            TAG, "Force removing proc " + app.toShortString() + " (" + name
+            + "/" + uid + ")");
+
+        mProcessNames.remove(name, uid);
+        mIsolatedProcesses.remove(app.uid);
+        if (mHeavyWeightProcess == app) {
+            mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
+                    mHeavyWeightProcess.userId, 0));
+            mHeavyWeightProcess = null;
+        }
+        boolean needRestart = false;
+        if (app.pid > 0 && app.pid != MY_PID) {
+            int pid = app.pid;
+            synchronized (mPidsSelfLocked) {
+                mPidsSelfLocked.remove(pid);
+                mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
+            }
+            killUnneededProcessLocked(app, reason);
+            handleAppDiedLocked(app, true, allowRestart);
+            removeLruProcessLocked(app);
+
+            if (app.persistent && !app.isolated) {
+                if (!callerWillRestart) {
+                    addAppLocked(app.info, false);
+                } else {
+                    needRestart = true;
+                }
+            }
+        } else {
+            mRemovedProcesses.add(app);
+        }
+
+        return needRestart;
+    }
+
+    private final void processStartTimedOutLocked(ProcessRecord app) {
+        final int pid = app.pid;
+        boolean gone = false;
+        synchronized (mPidsSelfLocked) {
+            ProcessRecord knownApp = mPidsSelfLocked.get(pid);
+            if (knownApp != null && knownApp.thread == null) {
+                mPidsSelfLocked.remove(pid);
+                gone = true;
+            }
+        }
+
+        if (gone) {
+            Slog.w(TAG, "Process " + app + " failed to attach");
+            EventLog.writeEvent(EventLogTags.AM_PROCESS_START_TIMEOUT, app.userId,
+                    pid, app.uid, app.processName);
+            mProcessNames.remove(app.processName, app.uid);
+            mIsolatedProcesses.remove(app.uid);
+            if (mHeavyWeightProcess == app) {
+                mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
+                        mHeavyWeightProcess.userId, 0));
+                mHeavyWeightProcess = null;
+            }
+            // Take care of any launching providers waiting for this process.
+            checkAppInLaunchingProvidersLocked(app, true);
+            // Take care of any services that are waiting for the process.
+            mServices.processStartTimedOutLocked(app);
+            killUnneededProcessLocked(app, "start timeout");
+            if (mBackupTarget != null && mBackupTarget.app.pid == pid) {
+                Slog.w(TAG, "Unattached app died before backup, skipping");
+                try {
+                    IBackupManager bm = IBackupManager.Stub.asInterface(
+                            ServiceManager.getService(Context.BACKUP_SERVICE));
+                    bm.agentDisconnected(app.info.packageName);
+                } catch (RemoteException e) {
+                    // Can't happen; the backup manager is local
+                }
+            }
+            if (isPendingBroadcastProcessLocked(pid)) {
+                Slog.w(TAG, "Unattached app died before broadcast acknowledged, skipping");
+                skipPendingBroadcastLocked(pid);
+            }
+        } else {
+            Slog.w(TAG, "Spurious process start timeout - pid not known for " + app);
+        }
+    }
+
+    private final boolean attachApplicationLocked(IApplicationThread thread,
+            int pid) {
+
+        // Find the application record that is being attached...  either via
+        // the pid if we are running in multiple processes, or just pull the
+        // next app record if we are emulating process with anonymous threads.
+        ProcessRecord app;
+        if (pid != MY_PID && pid >= 0) {
+            synchronized (mPidsSelfLocked) {
+                app = mPidsSelfLocked.get(pid);
+            }
+        } else {
+            app = null;
+        }
+
+        if (app == null) {
+            Slog.w(TAG, "No pending application record for pid " + pid
+                    + " (IApplicationThread " + thread + "); dropping process");
+            EventLog.writeEvent(EventLogTags.AM_DROP_PROCESS, pid);
+            if (pid > 0 && pid != MY_PID) {
+                Process.killProcessQuiet(pid);
+            } else {
+                try {
+                    thread.scheduleExit();
+                } catch (Exception e) {
+                    // Ignore exceptions.
+                }
+            }
+            return false;
+        }
+
+        // If this application record is still attached to a previous
+        // process, clean it up now.
+        if (app.thread != null) {
+            handleAppDiedLocked(app, true, true);
+        }
+
+        // Tell the process all about itself.
+
+        if (localLOGV) Slog.v(
+                TAG, "Binding process pid " + pid + " to record " + app);
+
+        final String processName = app.processName;
+        try {
+            AppDeathRecipient adr = new AppDeathRecipient(
+                    app, pid, thread);
+            thread.asBinder().linkToDeath(adr, 0);
+            app.deathRecipient = adr;
+        } catch (RemoteException e) {
+            app.resetPackageList(mProcessStats);
+            startProcessLocked(app, "link fail", processName);
+            return false;
+        }
+
+        EventLog.writeEvent(EventLogTags.AM_PROC_BOUND, app.userId, app.pid, app.processName);
+
+        app.makeActive(thread, mProcessStats);
+        app.curAdj = app.setAdj = -100;
+        app.curSchedGroup = app.setSchedGroup = Process.THREAD_GROUP_DEFAULT;
+        app.forcingToForeground = null;
+        app.foregroundServices = false;
+        app.hasShownUi = false;
+        app.debugging = false;
+        app.cached = false;
+
+        mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
+
+        boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info);
+        List<ProviderInfo> providers = normalMode ? generateApplicationProvidersLocked(app) : null;
+
+        if (!normalMode) {
+            Slog.i(TAG, "Launching preboot mode app: " + app);
+        }
+
+        if (localLOGV) Slog.v(
+            TAG, "New app record " + app
+            + " thread=" + thread.asBinder() + " pid=" + pid);
+        try {
+            int testMode = IApplicationThread.DEBUG_OFF;
+            if (mDebugApp != null && mDebugApp.equals(processName)) {
+                testMode = mWaitForDebugger
+                    ? IApplicationThread.DEBUG_WAIT
+                    : IApplicationThread.DEBUG_ON;
+                app.debugging = true;
+                if (mDebugTransient) {
+                    mDebugApp = mOrigDebugApp;
+                    mWaitForDebugger = mOrigWaitForDebugger;
+                }
+            }
+            String profileFile = app.instrumentationProfileFile;
+            ParcelFileDescriptor profileFd = null;
+            boolean profileAutoStop = false;
+            if (mProfileApp != null && mProfileApp.equals(processName)) {
+                mProfileProc = app;
+                profileFile = mProfileFile;
+                profileFd = mProfileFd;
+                profileAutoStop = mAutoStopProfiler;
+            }
+            boolean enableOpenGlTrace = false;
+            if (mOpenGlTraceApp != null && mOpenGlTraceApp.equals(processName)) {
+                enableOpenGlTrace = true;
+                mOpenGlTraceApp = null;
+            }
+
+            // If the app is being launched for restore or full backup, set it up specially
+            boolean isRestrictedBackupMode = false;
+            if (mBackupTarget != null && mBackupAppName.equals(processName)) {
+                isRestrictedBackupMode = (mBackupTarget.backupMode == BackupRecord.RESTORE)
+                        || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL)
+                        || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL);
+            }
+
+            ensurePackageDexOpt(app.instrumentationInfo != null
+                    ? app.instrumentationInfo.packageName
+                    : app.info.packageName);
+            if (app.instrumentationClass != null) {
+                ensurePackageDexOpt(app.instrumentationClass.getPackageName());
+            }
+            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Binding proc "
+                    + processName + " with config " + mConfiguration);
+            ApplicationInfo appInfo = app.instrumentationInfo != null
+                    ? app.instrumentationInfo : app.info;
+            app.compat = compatibilityInfoForPackageLocked(appInfo);
+            if (profileFd != null) {
+                profileFd = profileFd.dup();
+            }
+            thread.bindApplication(processName, appInfo, providers,
+                    app.instrumentationClass, profileFile, profileFd, profileAutoStop,
+                    app.instrumentationArguments, app.instrumentationWatcher,
+                    app.instrumentationUiAutomationConnection, testMode, enableOpenGlTrace,
+                    isRestrictedBackupMode || !normalMode, app.persistent,
+                    new Configuration(mConfiguration), app.compat, getCommonServicesLocked(),
+                    mCoreSettingsObserver.getCoreSettingsLocked());
+            updateLruProcessLocked(app, false, null);
+            app.lastRequestedGc = app.lastLowMemory = SystemClock.uptimeMillis();
+        } catch (Exception e) {
+            // todo: Yikes!  What should we do?  For now we will try to
+            // start another process, but that could easily get us in
+            // an infinite loop of restarting processes...
+            Slog.w(TAG, "Exception thrown during bind!", e);
+
+            app.resetPackageList(mProcessStats);
+            app.unlinkDeathRecipient();
+            startProcessLocked(app, "bind fail", processName);
+            return false;
+        }
+
+        // Remove this record from the list of starting applications.
+        mPersistentStartingProcesses.remove(app);
+        if (DEBUG_PROCESSES && mProcessesOnHold.contains(app)) Slog.v(TAG,
+                "Attach application locked removing on hold: " + app);
+        mProcessesOnHold.remove(app);
+
+        boolean badApp = false;
+        boolean didSomething = false;
+
+        // See if the top visible activity is waiting to run in this process...
+        if (normalMode) {
+            try {
+                if (mStackSupervisor.attachApplicationLocked(app)) {
+                    didSomething = true;
+                }
+            } catch (Exception e) {
+                badApp = true;
+            }
+        }
+
+        // Find any services that should be running in this process...
+        if (!badApp) {
+            try {
+                didSomething |= mServices.attachApplicationLocked(app, processName);
+            } catch (Exception e) {
+                badApp = true;
+            }
+        }
+
+        // Check if a next-broadcast receiver is in this process...
+        if (!badApp && isPendingBroadcastProcessLocked(pid)) {
+            try {
+                didSomething |= sendPendingBroadcastsLocked(app);
+            } catch (Exception e) {
+                // If the app died trying to launch the receiver we declare it 'bad'
+                badApp = true;
+            }
+        }
+
+        // Check whether the next backup agent is in this process...
+        if (!badApp && mBackupTarget != null && mBackupTarget.appInfo.uid == app.uid) {
+            if (DEBUG_BACKUP) Slog.v(TAG, "New app is backup target, launching agent for " + app);
+            ensurePackageDexOpt(mBackupTarget.appInfo.packageName);
+            try {
+                thread.scheduleCreateBackupAgent(mBackupTarget.appInfo,
+                        compatibilityInfoForPackageLocked(mBackupTarget.appInfo),
+                        mBackupTarget.backupMode);
+            } catch (Exception e) {
+                Slog.w(TAG, "Exception scheduling backup agent creation: ");
+                e.printStackTrace();
+            }
+        }
+
+        if (badApp) {
+            // todo: Also need to kill application to deal with all
+            // kinds of exceptions.
+            handleAppDiedLocked(app, false, true);
+            return false;
+        }
+
+        if (!didSomething) {
+            updateOomAdjLocked();
+        }
+
+        return true;
+    }
+
+    @Override
+    public final void attachApplication(IApplicationThread thread) {
+        synchronized (this) {
+            int callingPid = Binder.getCallingPid();
+            final long origId = Binder.clearCallingIdentity();
+            attachApplicationLocked(thread, callingPid);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) {
+        final long origId = Binder.clearCallingIdentity();
+        synchronized (this) {
+            ActivityStack stack = ActivityRecord.getStackLocked(token);
+            if (stack != null) {
+                ActivityRecord r =
+                        mStackSupervisor.activityIdleInternalLocked(token, false, config);
+                if (stopProfiling) {
+                    if ((mProfileProc == r.app) && (mProfileFd != null)) {
+                        try {
+                            mProfileFd.close();
+                        } catch (IOException e) {
+                        }
+                        clearProfilerLocked();
+                    }
+                }
+            }
+        }
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    void enableScreenAfterBoot() {
+        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN,
+                SystemClock.uptimeMillis());
+        mWindowManager.enableScreenAfterBoot();
+
+        synchronized (this) {
+            updateEventDispatchingLocked();
+        }
+    }
+
+    @Override
+    public void showBootMessage(final CharSequence msg, final boolean always) {
+        enforceNotIsolatedCaller("showBootMessage");
+        mWindowManager.showBootMessage(msg, always);
+    }
+
+    @Override
+    public void dismissKeyguardOnNextActivity() {
+        enforceNotIsolatedCaller("dismissKeyguardOnNextActivity");
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                if (DEBUG_LOCKSCREEN) logLockScreen("");
+                if (mLockScreenShown) {
+                    mLockScreenShown = false;
+                    comeOutOfSleepIfNeededLocked();
+                }
+                mStackSupervisor.setDismissKeyguard(true);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    final void finishBooting() {
+        IntentFilter pkgFilter = new IntentFilter();
+        pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
+        pkgFilter.addDataScheme("package");
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                String[] pkgs = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
+                if (pkgs != null) {
+                    for (String pkg : pkgs) {
+                        synchronized (ActivityManagerService.this) {
+                            if (forceStopPackageLocked(pkg, -1, false, false, false, false, 0,
+                                    "finished booting")) {
+                                setResultCode(Activity.RESULT_OK);
+                                return;
+                            }
+                        }
+                    }
+                }
+            }
+        }, pkgFilter);
+
+        synchronized (this) {
+            // Ensure that any processes we had put on hold are now started
+            // up.
+            final int NP = mProcessesOnHold.size();
+            if (NP > 0) {
+                ArrayList<ProcessRecord> procs =
+                    new ArrayList<ProcessRecord>(mProcessesOnHold);
+                for (int ip=0; ip<NP; ip++) {
+                    if (DEBUG_PROCESSES) Slog.v(TAG, "Starting process on hold: "
+                            + procs.get(ip));
+                    startProcessLocked(procs.get(ip), "on-hold", null);
+                }
+            }
+            
+            if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
+                // Start looking for apps that are abusing wake locks.
+                Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
+                mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
+                // Tell anyone interested that we are done booting!
+                SystemProperties.set("sys.boot_completed", "1");
+                SystemProperties.set("dev.bootcomplete", "1");
+                for (int i=0; i<mStartedUsers.size(); i++) {
+                    UserStartedState uss = mStartedUsers.valueAt(i);
+                    if (uss.mState == UserStartedState.STATE_BOOTING) {
+                        uss.mState = UserStartedState.STATE_RUNNING;
+                        final int userId = mStartedUsers.keyAt(i);
+                        Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
+                        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
+                        intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT);
+                        broadcastIntentLocked(null, null, intent, null,
+                                new IIntentReceiver.Stub() {
+                                    @Override
+                                    public void performReceive(Intent intent, int resultCode,
+                                            String data, Bundle extras, boolean ordered,
+                                            boolean sticky, int sendingUser) {
+                                        synchronized (ActivityManagerService.this) {
+                                            requestPssAllProcsLocked(SystemClock.uptimeMillis(),
+                                                    true, false);
+                                        }
+                                    }
+                                },
+                                0, null, null,
+                                android.Manifest.permission.RECEIVE_BOOT_COMPLETED,
+                                AppOpsManager.OP_NONE, true, false, MY_PID, Process.SYSTEM_UID,
+                                userId);
+                    }
+                }
+            }
+        }
+    }
+    
+    final void ensureBootCompleted() {
+        boolean booting;
+        boolean enableScreen;
+        synchronized (this) {
+            booting = mBooting;
+            mBooting = false;
+            enableScreen = !mBooted;
+            mBooted = true;
+        }
+        
+        if (booting) {
+            finishBooting();
+        }
+
+        if (enableScreen) {
+            enableScreenAfterBoot();
+        }
+    }
+
+    @Override
+    public final void activityResumed(IBinder token) {
+        final long origId = Binder.clearCallingIdentity();
+        synchronized(this) {
+            ActivityStack stack = ActivityRecord.getStackLocked(token);
+            if (stack != null) {
+                ActivityRecord.activityResumedLocked(token);
+            }
+        }
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    @Override
+    public final void activityPaused(IBinder token) {
+        final long origId = Binder.clearCallingIdentity();
+        synchronized(this) {
+            ActivityStack stack = ActivityRecord.getStackLocked(token);
+            if (stack != null) {
+                stack.activityPausedLocked(token, false);
+            }
+        }
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    @Override
+    public final void activityStopped(IBinder token, Bundle icicle, Bitmap thumbnail,
+            CharSequence description) {
+        if (localLOGV) Slog.v(
+            TAG, "Activity stopped: token=" + token);
+
+        // Refuse possible leaked file descriptors
+        if (icicle != null && icicle.hasFileDescriptors()) {
+            throw new IllegalArgumentException("File descriptors passed in Bundle");
+        }
+
+        ActivityRecord r = null;
+
+        final long origId = Binder.clearCallingIdentity();
+
+        synchronized (this) {
+            r = ActivityRecord.isInStackLocked(token);
+            if (r != null) {
+                r.task.stack.activityStoppedLocked(r, icicle, thumbnail, description);
+            }
+        }
+
+        if (r != null) {
+            sendPendingThumbnail(r, null, null, null, false);
+        }
+
+        trimApplications();
+
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    @Override
+    public final void activityDestroyed(IBinder token) {
+        if (DEBUG_SWITCH) Slog.v(TAG, "ACTIVITY DESTROYED: " + token);
+        synchronized (this) {
+            ActivityStack stack = ActivityRecord.getStackLocked(token);
+            if (stack != null) {
+                stack.activityDestroyedLocked(token);
+            }
+        }
+    }
+    
+    @Override
+    public String getCallingPackage(IBinder token) {
+        synchronized (this) {
+            ActivityRecord r = getCallingRecordLocked(token);
+            return r != null ? r.info.packageName : null;
+        }
+    }
+
+    @Override
+    public ComponentName getCallingActivity(IBinder token) {
+        synchronized (this) {
+            ActivityRecord r = getCallingRecordLocked(token);
+            return r != null ? r.intent.getComponent() : null;
+        }
+    }
+
+    private ActivityRecord getCallingRecordLocked(IBinder token) {
+        ActivityRecord r = ActivityRecord.isInStackLocked(token);
+        if (r == null) {
+            return null;
+        }
+        return r.resultTo;
+    }
+
+    @Override
+    public ComponentName getActivityClassForToken(IBinder token) {
+        synchronized(this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                return null;
+            }
+            return r.intent.getComponent();
+        }
+    }
+
+    @Override
+    public String getPackageForToken(IBinder token) {
+        synchronized(this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                return null;
+            }
+            return r.packageName;
+        }
+    }
+
+    @Override
+    public IIntentSender getIntentSender(int type,
+            String packageName, IBinder token, String resultWho,
+            int requestCode, Intent[] intents, String[] resolvedTypes,
+            int flags, Bundle options, int userId) {
+        enforceNotIsolatedCaller("getIntentSender");
+        // Refuse possible leaked file descriptors
+        if (intents != null) {
+            if (intents.length < 1) {
+                throw new IllegalArgumentException("Intents array length must be >= 1");
+            }
+            for (int i=0; i<intents.length; i++) {
+                Intent intent = intents[i];
+                if (intent != null) {
+                    if (intent.hasFileDescriptors()) {
+                        throw new IllegalArgumentException("File descriptors passed in Intent");
+                    }
+                    if (type == ActivityManager.INTENT_SENDER_BROADCAST &&
+                            (intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
+                        throw new IllegalArgumentException(
+                                "Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
+                    }
+                    intents[i] = new Intent(intent);
+                }
+            }
+            if (resolvedTypes != null && resolvedTypes.length != intents.length) {
+                throw new IllegalArgumentException(
+                        "Intent array length does not match resolvedTypes length");
+            }
+        }
+        if (options != null) {
+            if (options.hasFileDescriptors()) {
+                throw new IllegalArgumentException("File descriptors passed in options");
+            }
+        }
+        
+        synchronized(this) {
+            int callingUid = Binder.getCallingUid();
+            int origUserId = userId;
+            userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId,
+                    type == ActivityManager.INTENT_SENDER_BROADCAST, false,
+                    "getIntentSender", null);
+            if (origUserId == UserHandle.USER_CURRENT) {
+                // We don't want to evaluate this until the pending intent is
+                // actually executed.  However, we do want to always do the
+                // security checking for it above.
+                userId = UserHandle.USER_CURRENT;
+            }
+            try {
+                if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
+                    int uid = AppGlobals.getPackageManager()
+                            .getPackageUid(packageName, UserHandle.getUserId(callingUid));
+                    if (!UserHandle.isSameApp(callingUid, uid)) {
+                        String msg = "Permission Denial: getIntentSender() from pid="
+                            + Binder.getCallingPid()
+                            + ", uid=" + Binder.getCallingUid()
+                            + ", (need uid=" + uid + ")"
+                            + " is not allowed to send as package " + packageName;
+                        Slog.w(TAG, msg);
+                        throw new SecurityException(msg);
+                    }
+                }
+
+                return getIntentSenderLocked(type, packageName, callingUid, userId,
+                        token, resultWho, requestCode, intents, resolvedTypes, flags, options);
+                
+            } catch (RemoteException e) {
+                throw new SecurityException(e);
+            }
+        }
+    }
+
+    IIntentSender getIntentSenderLocked(int type, String packageName,
+            int callingUid, int userId, IBinder token, String resultWho,
+            int requestCode, Intent[] intents, String[] resolvedTypes, int flags,
+            Bundle options) {
+        if (DEBUG_MU)
+            Slog.v(TAG_MU, "getIntentSenderLocked(): uid=" + callingUid);
+        ActivityRecord activity = null;
+        if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) {
+            activity = ActivityRecord.isInStackLocked(token);
+            if (activity == null) {
+                return null;
+            }
+            if (activity.finishing) {
+                return null;
+            }
+        }
+
+        final boolean noCreate = (flags&PendingIntent.FLAG_NO_CREATE) != 0;
+        final boolean cancelCurrent = (flags&PendingIntent.FLAG_CANCEL_CURRENT) != 0;
+        final boolean updateCurrent = (flags&PendingIntent.FLAG_UPDATE_CURRENT) != 0;
+        flags &= ~(PendingIntent.FLAG_NO_CREATE|PendingIntent.FLAG_CANCEL_CURRENT
+                |PendingIntent.FLAG_UPDATE_CURRENT);
+
+        PendingIntentRecord.Key key = new PendingIntentRecord.Key(
+                type, packageName, activity, resultWho,
+                requestCode, intents, resolvedTypes, flags, options, userId);
+        WeakReference<PendingIntentRecord> ref;
+        ref = mIntentSenderRecords.get(key);
+        PendingIntentRecord rec = ref != null ? ref.get() : null;
+        if (rec != null) {
+            if (!cancelCurrent) {
+                if (updateCurrent) {
+                    if (rec.key.requestIntent != null) {
+                        rec.key.requestIntent.replaceExtras(intents != null ?
+                                intents[intents.length - 1] : null);
+                    }
+                    if (intents != null) {
+                        intents[intents.length-1] = rec.key.requestIntent;
+                        rec.key.allIntents = intents;
+                        rec.key.allResolvedTypes = resolvedTypes;
+                    } else {
+                        rec.key.allIntents = null;
+                        rec.key.allResolvedTypes = null;
+                    }
+                }
+                return rec;
+            }
+            rec.canceled = true;
+            mIntentSenderRecords.remove(key);
+        }
+        if (noCreate) {
+            return rec;
+        }
+        rec = new PendingIntentRecord(this, key, callingUid);
+        mIntentSenderRecords.put(key, rec.ref);
+        if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) {
+            if (activity.pendingResults == null) {
+                activity.pendingResults
+                        = new HashSet<WeakReference<PendingIntentRecord>>();
+            }
+            activity.pendingResults.add(rec.ref);
+        }
+        return rec;
+    }
+
+    @Override
+    public void cancelIntentSender(IIntentSender sender) {
+        if (!(sender instanceof PendingIntentRecord)) {
+            return;
+        }
+        synchronized(this) {
+            PendingIntentRecord rec = (PendingIntentRecord)sender;
+            try {
+                int uid = AppGlobals.getPackageManager()
+                        .getPackageUid(rec.key.packageName, UserHandle.getCallingUserId());
+                if (!UserHandle.isSameApp(uid, Binder.getCallingUid())) {
+                    String msg = "Permission Denial: cancelIntentSender() from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid()
+                        + " is not allowed to cancel packges "
+                        + rec.key.packageName;
+                    Slog.w(TAG, msg);
+                    throw new SecurityException(msg);
+                }
+            } catch (RemoteException e) {
+                throw new SecurityException(e);
+            }
+            cancelIntentSenderLocked(rec, true);
+        }
+    }
+
+    void cancelIntentSenderLocked(PendingIntentRecord rec, boolean cleanActivity) {
+        rec.canceled = true;
+        mIntentSenderRecords.remove(rec.key);
+        if (cleanActivity && rec.key.activity != null) {
+            rec.key.activity.pendingResults.remove(rec.ref);
+        }
+    }
+
+    @Override
+    public String getPackageForIntentSender(IIntentSender pendingResult) {
+        if (!(pendingResult instanceof PendingIntentRecord)) {
+            return null;
+        }
+        try {
+            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
+            return res.key.packageName;
+        } catch (ClassCastException e) {
+        }
+        return null;
+    }
+
+    @Override
+    public int getUidForIntentSender(IIntentSender sender) {
+        if (sender instanceof PendingIntentRecord) {
+            try {
+                PendingIntentRecord res = (PendingIntentRecord)sender;
+                return res.uid;
+            } catch (ClassCastException e) {
+            }
+        }
+        return -1;
+    }
+
+    @Override
+    public boolean isIntentSenderTargetedToPackage(IIntentSender pendingResult) {
+        if (!(pendingResult instanceof PendingIntentRecord)) {
+            return false;
+        }
+        try {
+            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
+            if (res.key.allIntents == null) {
+                return false;
+            }
+            for (int i=0; i<res.key.allIntents.length; i++) {
+                Intent intent = res.key.allIntents[i];
+                if (intent.getPackage() != null && intent.getComponent() != null) {
+                    return false;
+                }
+            }
+            return true;
+        } catch (ClassCastException e) {
+        }
+        return false;
+    }
+
+    @Override
+    public boolean isIntentSenderAnActivity(IIntentSender pendingResult) {
+        if (!(pendingResult instanceof PendingIntentRecord)) {
+            return false;
+        }
+        try {
+            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
+            if (res.key.type == ActivityManager.INTENT_SENDER_ACTIVITY) {
+                return true;
+            }
+            return false;
+        } catch (ClassCastException e) {
+        }
+        return false;
+    }
+
+    @Override
+    public Intent getIntentForIntentSender(IIntentSender pendingResult) {
+        if (!(pendingResult instanceof PendingIntentRecord)) {
+            return null;
+        }
+        try {
+            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
+            return res.key.requestIntent != null ? new Intent(res.key.requestIntent) : null;
+        } catch (ClassCastException e) {
+        }
+        return null;
+    }
+
+    @Override
+    public void setProcessLimit(int max) {
+        enforceCallingPermission(android.Manifest.permission.SET_PROCESS_LIMIT,
+                "setProcessLimit()");
+        synchronized (this) {
+            mProcessLimit = max < 0 ? ProcessList.MAX_CACHED_APPS : max;
+            mProcessLimitOverride = max;
+        }
+        trimApplications();
+    }
+
+    @Override
+    public int getProcessLimit() {
+        synchronized (this) {
+            return mProcessLimitOverride;
+        }
+    }
+
+    void foregroundTokenDied(ForegroundToken token) {
+        synchronized (ActivityManagerService.this) {
+            synchronized (mPidsSelfLocked) {
+                ForegroundToken cur
+                    = mForegroundProcesses.get(token.pid);
+                if (cur != token) {
+                    return;
+                }
+                mForegroundProcesses.remove(token.pid);
+                ProcessRecord pr = mPidsSelfLocked.get(token.pid);
+                if (pr == null) {
+                    return;
+                }
+                pr.forcingToForeground = null;
+                pr.foregroundServices = false;
+            }
+            updateOomAdjLocked();
+        }
+    }
+
+    @Override
+    public void setProcessForeground(IBinder token, int pid, boolean isForeground) {
+        enforceCallingPermission(android.Manifest.permission.SET_PROCESS_LIMIT,
+                "setProcessForeground()");
+        synchronized(this) {
+            boolean changed = false;
+            
+            synchronized (mPidsSelfLocked) {
+                ProcessRecord pr = mPidsSelfLocked.get(pid);
+                if (pr == null && isForeground) {
+                    Slog.w(TAG, "setProcessForeground called on unknown pid: " + pid);
+                    return;
+                }
+                ForegroundToken oldToken = mForegroundProcesses.get(pid);
+                if (oldToken != null) {
+                    oldToken.token.unlinkToDeath(oldToken, 0);
+                    mForegroundProcesses.remove(pid);
+                    if (pr != null) {
+                        pr.forcingToForeground = null;
+                    }
+                    changed = true;
+                }
+                if (isForeground && token != null) {
+                    ForegroundToken newToken = new ForegroundToken() {
+                        @Override
+                        public void binderDied() {
+                            foregroundTokenDied(this);
+                        }
+                    };
+                    newToken.pid = pid;
+                    newToken.token = token;
+                    try {
+                        token.linkToDeath(newToken, 0);
+                        mForegroundProcesses.put(pid, newToken);
+                        pr.forcingToForeground = token;
+                        changed = true;
+                    } catch (RemoteException e) {
+                        // If the process died while doing this, we will later
+                        // do the cleanup with the process death link.
+                    }
+                }
+            }
+            
+            if (changed) {
+                updateOomAdjLocked();
+            }
+        }
+    }
+    
+    // =========================================================
+    // PERMISSIONS
+    // =========================================================
+
+    static class PermissionController extends IPermissionController.Stub {
+        ActivityManagerService mActivityManagerService;
+        PermissionController(ActivityManagerService activityManagerService) {
+            mActivityManagerService = activityManagerService;
+        }
+
+        @Override
+        public boolean checkPermission(String permission, int pid, int uid) {
+            return mActivityManagerService.checkPermission(permission, pid,
+                    uid) == PackageManager.PERMISSION_GRANTED;
+        }
+    }
+
+    class IntentFirewallInterface implements IntentFirewall.AMSInterface {
+        @Override
+        public int checkComponentPermission(String permission, int pid, int uid,
+                int owningUid, boolean exported) {
+            return ActivityManagerService.this.checkComponentPermission(permission, pid, uid,
+                    owningUid, exported);
+        }
+
+        @Override
+        public Object getAMSLock() {
+            return ActivityManagerService.this;
+        }
+    }
+
+    /**
+     * This can be called with or without the global lock held.
+     */
+    int checkComponentPermission(String permission, int pid, int uid,
+            int owningUid, boolean exported) {
+        // We might be performing an operation on behalf of an indirect binder
+        // invocation, e.g. via {@link #openContentUri}.  Check and adjust the
+        // client identity accordingly before proceeding.
+        Identity tlsIdentity = sCallerIdentity.get();
+        if (tlsIdentity != null) {
+            Slog.d(TAG, "checkComponentPermission() adjusting {pid,uid} to {"
+                    + tlsIdentity.pid + "," + tlsIdentity.uid + "}");
+            uid = tlsIdentity.uid;
+            pid = tlsIdentity.pid;
+        }
+
+        if (pid == MY_PID) {
+            return PackageManager.PERMISSION_GRANTED;
+        }
+
+        return ActivityManager.checkComponentPermission(permission, uid,
+                owningUid, exported);
+    }
+
+    /**
+     * As the only public entry point for permissions checking, this method
+     * can enforce the semantic that requesting a check on a null global
+     * permission is automatically denied.  (Internally a null permission
+     * string is used when calling {@link #checkComponentPermission} in cases
+     * when only uid-based security is needed.)
+     * 
+     * This can be called with or without the global lock held.
+     */
+    @Override
+    public int checkPermission(String permission, int pid, int uid) {
+        if (permission == null) {
+            return PackageManager.PERMISSION_DENIED;
+        }
+        return checkComponentPermission(permission, pid, UserHandle.getAppId(uid), -1, true);
+    }
+
+    /**
+     * Binder IPC calls go through the public entry point.
+     * This can be called with or without the global lock held.
+     */
+    int checkCallingPermission(String permission) {
+        return checkPermission(permission,
+                Binder.getCallingPid(),
+                UserHandle.getAppId(Binder.getCallingUid()));
+    }
+
+    /**
+     * This can be called with or without the global lock held.
+     */
+    void enforceCallingPermission(String permission, String func) {
+        if (checkCallingPermission(permission)
+                == PackageManager.PERMISSION_GRANTED) {
+            return;
+        }
+
+        String msg = "Permission Denial: " + func + " from pid="
+                + Binder.getCallingPid()
+                + ", uid=" + Binder.getCallingUid()
+                + " requires " + permission;
+        Slog.w(TAG, msg);
+        throw new SecurityException(msg);
+    }
+
+    /**
+     * Determine if UID is holding permissions required to access {@link Uri} in
+     * the given {@link ProviderInfo}. Final permission checking is always done
+     * in {@link ContentProvider}.
+     */
+    private final boolean checkHoldingPermissionsLocked(
+            IPackageManager pm, ProviderInfo pi, Uri uri, int uid, int modeFlags) {
+        if (DEBUG_URI_PERMISSION) Slog.v(TAG,
+                "checkHoldingPermissionsLocked: uri=" + uri + " uid=" + uid);
+
+        if (pi.applicationInfo.uid == uid) {
+            return true;
+        } else if (!pi.exported) {
+            return false;
+        }
+
+        boolean readMet = (modeFlags & Intent.FLAG_GRANT_READ_URI_PERMISSION) == 0;
+        boolean writeMet = (modeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0;
+        try {
+            // check if target holds top-level <provider> permissions
+            if (!readMet && pi.readPermission != null
+                    && (pm.checkUidPermission(pi.readPermission, uid) == PERMISSION_GRANTED)) {
+                readMet = true;
+            }
+            if (!writeMet && pi.writePermission != null
+                    && (pm.checkUidPermission(pi.writePermission, uid) == PERMISSION_GRANTED)) {
+                writeMet = true;
+            }
+
+            // track if unprotected read/write is allowed; any denied
+            // <path-permission> below removes this ability
+            boolean allowDefaultRead = pi.readPermission == null;
+            boolean allowDefaultWrite = pi.writePermission == null;
+
+            // check if target holds any <path-permission> that match uri
+            final PathPermission[] pps = pi.pathPermissions;
+            if (pps != null) {
+                final String path = uri.getPath();
+                int i = pps.length;
+                while (i > 0 && (!readMet || !writeMet)) {
+                    i--;
+                    PathPermission pp = pps[i];
+                    if (pp.match(path)) {
+                        if (!readMet) {
+                            final String pprperm = pp.getReadPermission();
+                            if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Checking read perm for "
+                                    + pprperm + " for " + pp.getPath()
+                                    + ": match=" + pp.match(path)
+                                    + " check=" + pm.checkUidPermission(pprperm, uid));
+                            if (pprperm != null) {
+                                if (pm.checkUidPermission(pprperm, uid) == PERMISSION_GRANTED) {
+                                    readMet = true;
+                                } else {
+                                    allowDefaultRead = false;
+                                }
+                            }
+                        }
+                        if (!writeMet) {
+                            final String ppwperm = pp.getWritePermission();
+                            if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Checking write perm "
+                                    + ppwperm + " for " + pp.getPath()
+                                    + ": match=" + pp.match(path)
+                                    + " check=" + pm.checkUidPermission(ppwperm, uid));
+                            if (ppwperm != null) {
+                                if (pm.checkUidPermission(ppwperm, uid) == PERMISSION_GRANTED) {
+                                    writeMet = true;
+                                } else {
+                                    allowDefaultWrite = false;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            // grant unprotected <provider> read/write, if not blocked by
+            // <path-permission> above
+            if (allowDefaultRead) readMet = true;
+            if (allowDefaultWrite) writeMet = true;
+
+        } catch (RemoteException e) {
+            return false;
+        }
+
+        return readMet && writeMet;
+    }
+
+    private ProviderInfo getProviderInfoLocked(String authority, int userHandle) {
+        ProviderInfo pi = null;
+        ContentProviderRecord cpr = mProviderMap.getProviderByName(authority, userHandle);
+        if (cpr != null) {
+            pi = cpr.info;
+        } else {
+            try {
+                pi = AppGlobals.getPackageManager().resolveContentProvider(
+                        authority, PackageManager.GET_URI_PERMISSION_PATTERNS, userHandle);
+            } catch (RemoteException ex) {
+            }
+        }
+        return pi;
+    }
+
+    private UriPermission findUriPermissionLocked(int targetUid, Uri uri) {
+        ArrayMap<Uri, UriPermission> targetUris = mGrantedUriPermissions.get(targetUid);
+        if (targetUris != null) {
+            return targetUris.get(uri);
+        } else {
+            return null;
+        }
+    }
+
+    private UriPermission findOrCreateUriPermissionLocked(
+            String sourcePkg, String targetPkg, int targetUid, Uri uri) {
+        ArrayMap<Uri, UriPermission> targetUris = mGrantedUriPermissions.get(targetUid);
+        if (targetUris == null) {
+            targetUris = Maps.newArrayMap();
+            mGrantedUriPermissions.put(targetUid, targetUris);
+        }
+
+        UriPermission perm = targetUris.get(uri);
+        if (perm == null) {
+            perm = new UriPermission(sourcePkg, targetPkg, targetUid, uri);
+            targetUris.put(uri, perm);
+        }
+
+        return perm;
+    }
+
+    private final boolean checkUriPermissionLocked(
+            Uri uri, int uid, int modeFlags, int minStrength) {
+        // Root gets to do everything.
+        if (uid == 0) {
+            return true;
+        }
+        ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(uid);
+        if (perms == null) return false;
+        UriPermission perm = perms.get(uri);
+        if (perm == null) return false;
+        return perm.getStrength(modeFlags) >= minStrength;
+    }
+
+    @Override
+    public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
+        enforceNotIsolatedCaller("checkUriPermission");
+
+        // Another redirected-binder-call permissions check as in
+        // {@link checkComponentPermission}.
+        Identity tlsIdentity = sCallerIdentity.get();
+        if (tlsIdentity != null) {
+            uid = tlsIdentity.uid;
+            pid = tlsIdentity.pid;
+        }
+
+        // Our own process gets to do everything.
+        if (pid == MY_PID) {
+            return PackageManager.PERMISSION_GRANTED;
+        }
+        synchronized(this) {
+            return checkUriPermissionLocked(uri, uid, modeFlags, UriPermission.STRENGTH_OWNED)
+                    ? PackageManager.PERMISSION_GRANTED
+                    : PackageManager.PERMISSION_DENIED;
+        }
+    }
+
+    /**
+     * Check if the targetPkg can be granted permission to access uri by
+     * the callingUid using the given modeFlags.  Throws a security exception
+     * if callingUid is not allowed to do this.  Returns the uid of the target
+     * if the URI permission grant should be performed; returns -1 if it is not
+     * needed (for example targetPkg already has permission to access the URI).
+     * If you already know the uid of the target, you can supply it in
+     * lastTargetUid else set that to -1.
+     */
+    int checkGrantUriPermissionLocked(int callingUid, String targetPkg,
+            Uri uri, int modeFlags, int lastTargetUid) {
+        final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
+        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
+                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+        if (modeFlags == 0) {
+            return -1;
+        }
+
+        if (targetPkg != null) {
+            if (DEBUG_URI_PERMISSION) Slog.v(TAG,
+                    "Checking grant " + targetPkg + " permission to " + uri);
+        }
+        
+        final IPackageManager pm = AppGlobals.getPackageManager();
+
+        // If this is not a content: uri, we can't do anything with it.
+        if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
+            if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
+                    "Can't grant URI permission for non-content URI: " + uri);
+            return -1;
+        }
+
+        final String authority = uri.getAuthority();
+        final ProviderInfo pi = getProviderInfoLocked(authority, UserHandle.getUserId(callingUid));
+        if (pi == null) {
+            Slog.w(TAG, "No content provider found for permission check: " + uri.toSafeString());
+            return -1;
+        }
+
+        int targetUid = lastTargetUid;
+        if (targetUid < 0 && targetPkg != null) {
+            try {
+                targetUid = pm.getPackageUid(targetPkg, UserHandle.getUserId(callingUid));
+                if (targetUid < 0) {
+                    if (DEBUG_URI_PERMISSION) Slog.v(TAG,
+                            "Can't grant URI permission no uid for: " + targetPkg);
+                    return -1;
+                }
+            } catch (RemoteException ex) {
+                return -1;
+            }
+        }
+
+        if (targetUid >= 0) {
+            // First...  does the target actually need this permission?
+            if (checkHoldingPermissionsLocked(pm, pi, uri, targetUid, modeFlags)) {
+                // No need to grant the target this permission.
+                if (DEBUG_URI_PERMISSION) Slog.v(TAG,
+                        "Target " + targetPkg + " already has full permission to " + uri);
+                return -1;
+            }
+        } else {
+            // First...  there is no target package, so can anyone access it?
+            boolean allowed = pi.exported;
+            if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) {
+                if (pi.readPermission != null) {
+                    allowed = false;
+                }
+            }
+            if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
+                if (pi.writePermission != null) {
+                    allowed = false;
+                }
+            }
+            if (allowed) {
+                return -1;
+            }
+        }
+
+        // Second...  is the provider allowing granting of URI permissions?
+        if (!pi.grantUriPermissions) {
+            throw new SecurityException("Provider " + pi.packageName
+                    + "/" + pi.name
+                    + " does not allow granting of Uri permissions (uri "
+                    + uri + ")");
+        }
+        if (pi.uriPermissionPatterns != null) {
+            final int N = pi.uriPermissionPatterns.length;
+            boolean allowed = false;
+            for (int i=0; i<N; i++) {
+                if (pi.uriPermissionPatterns[i] != null
+                        && pi.uriPermissionPatterns[i].match(uri.getPath())) {
+                    allowed = true;
+                    break;
+                }
+            }
+            if (!allowed) {
+                throw new SecurityException("Provider " + pi.packageName
+                        + "/" + pi.name
+                        + " does not allow granting of permission to path of Uri "
+                        + uri);
+            }
+        }
+
+        // Third...  does the caller itself have permission to access
+        // this uri?
+        if (callingUid != Process.myUid()) {
+            if (!checkHoldingPermissionsLocked(pm, pi, uri, callingUid, modeFlags)) {
+                // Require they hold a strong enough Uri permission
+                final int minStrength = persistable ? UriPermission.STRENGTH_PERSISTABLE
+                        : UriPermission.STRENGTH_OWNED;
+                if (!checkUriPermissionLocked(uri, callingUid, modeFlags, minStrength)) {
+                    throw new SecurityException("Uid " + callingUid
+                            + " does not have permission to uri " + uri);
+                }
+            }
+        }
+
+        return targetUid;
+    }
+
+    @Override
+    public int checkGrantUriPermission(int callingUid, String targetPkg,
+            Uri uri, int modeFlags) {
+        enforceNotIsolatedCaller("checkGrantUriPermission");
+        synchronized(this) {
+            return checkGrantUriPermissionLocked(callingUid, targetPkg, uri, modeFlags, -1);
+        }
+    }
+
+    void grantUriPermissionUncheckedLocked(
+            int targetUid, String targetPkg, Uri uri, int modeFlags, UriPermissionOwner owner) {
+        final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
+        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
+                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+        if (modeFlags == 0) {
+            return;
+        }
+
+        // So here we are: the caller has the assumed permission
+        // to the uri, and the target doesn't.  Let's now give this to
+        // the target.
+
+        if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
+                "Granting " + targetPkg + "/" + targetUid + " permission to " + uri);
+
+        final String authority = uri.getAuthority();
+        final ProviderInfo pi = getProviderInfoLocked(authority, UserHandle.getUserId(targetUid));
+        if (pi == null) {
+            Slog.w(TAG, "No content provider found for grant: " + uri.toSafeString());
+            return;
+        }
+
+        final UriPermission perm = findOrCreateUriPermissionLocked(
+                pi.packageName, targetPkg, targetUid, uri);
+        perm.grantModes(modeFlags, persistable, owner);
+    }
+
+    void grantUriPermissionLocked(int callingUid, String targetPkg, Uri uri,
+            int modeFlags, UriPermissionOwner owner) {
+        if (targetPkg == null) {
+            throw new NullPointerException("targetPkg");
+        }
+
+        int targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, uri, modeFlags, -1);
+        if (targetUid < 0) {
+            return;
+        }
+
+        grantUriPermissionUncheckedLocked(targetUid, targetPkg, uri, modeFlags, owner);
+    }
+
+    static class NeededUriGrants extends ArrayList<Uri> {
+        final String targetPkg;
+        final int targetUid;
+        final int flags;
+
+        NeededUriGrants(String targetPkg, int targetUid, int flags) {
+            this.targetPkg = targetPkg;
+            this.targetUid = targetUid;
+            this.flags = flags;
+        }
+    }
+
+    /**
+     * Like checkGrantUriPermissionLocked, but takes an Intent.
+     */
+    NeededUriGrants checkGrantUriPermissionFromIntentLocked(int callingUid,
+            String targetPkg, Intent intent, int mode, NeededUriGrants needed) {
+        if (DEBUG_URI_PERMISSION) Slog.v(TAG,
+                "Checking URI perm to data=" + (intent != null ? intent.getData() : null)
+                + " clip=" + (intent != null ? intent.getClipData() : null)
+                + " from " + intent + "; flags=0x"
+                + Integer.toHexString(intent != null ? intent.getFlags() : 0));
+
+        if (targetPkg == null) {
+            throw new NullPointerException("targetPkg");
+        }
+
+        if (intent == null) {
+            return null;
+        }
+        Uri data = intent.getData();
+        ClipData clip = intent.getClipData();
+        if (data == null && clip == null) {
+            return null;
+        }
+
+        if (data != null) {
+            int targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, data,
+                mode, needed != null ? needed.targetUid : -1);
+            if (targetUid > 0) {
+                if (needed == null) {
+                    needed = new NeededUriGrants(targetPkg, targetUid, mode);
+                }
+                needed.add(data);
+            }
+        }
+        if (clip != null) {
+            for (int i=0; i<clip.getItemCount(); i++) {
+                Uri uri = clip.getItemAt(i).getUri();
+                if (uri != null) {
+                    int targetUid = -1;
+                    targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, uri,
+                            mode, needed != null ? needed.targetUid : -1);
+                    if (targetUid > 0) {
+                        if (needed == null) {
+                            needed = new NeededUriGrants(targetPkg, targetUid, mode);
+                        }
+                        needed.add(uri);
+                    }
+                } else {
+                    Intent clipIntent = clip.getItemAt(i).getIntent();
+                    if (clipIntent != null) {
+                        NeededUriGrants newNeeded = checkGrantUriPermissionFromIntentLocked(
+                                callingUid, targetPkg, clipIntent, mode, needed);
+                        if (newNeeded != null) {
+                            needed = newNeeded;
+                        }
+                    }
+                }
+            }
+        }
+
+        return needed;
+    }
+
+    /**
+     * Like grantUriPermissionUncheckedLocked, but takes an Intent.
+     */
+    void grantUriPermissionUncheckedFromIntentLocked(NeededUriGrants needed,
+            UriPermissionOwner owner) {
+        if (needed != null) {
+            for (int i=0; i<needed.size(); i++) {
+                grantUriPermissionUncheckedLocked(needed.targetUid, needed.targetPkg,
+                        needed.get(i), needed.flags, owner);
+            }
+        }
+    }
+
+    void grantUriPermissionFromIntentLocked(int callingUid,
+            String targetPkg, Intent intent, UriPermissionOwner owner) {
+        NeededUriGrants needed = checkGrantUriPermissionFromIntentLocked(callingUid, targetPkg,
+                intent, intent != null ? intent.getFlags() : 0, null);
+        if (needed == null) {
+            return;
+        }
+
+        grantUriPermissionUncheckedFromIntentLocked(needed, owner);
+    }
+
+    @Override
+    public void grantUriPermission(IApplicationThread caller, String targetPkg,
+            Uri uri, int modeFlags) {
+        enforceNotIsolatedCaller("grantUriPermission");
+        synchronized(this) {
+            final ProcessRecord r = getRecordForAppLocked(caller);
+            if (r == null) {
+                throw new SecurityException("Unable to find app for caller "
+                        + caller
+                        + " when granting permission to uri " + uri);
+            }
+            if (targetPkg == null) {
+                throw new IllegalArgumentException("null target");
+            }
+            if (uri == null) {
+                throw new IllegalArgumentException("null uri");
+            }
+
+            // Persistable only supported through Intents
+            Preconditions.checkFlagsArgument(modeFlags,
+                    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
+            grantUriPermissionLocked(r.uid, targetPkg, uri, modeFlags,
+                    null);
+        }
+    }
+
+    void removeUriPermissionIfNeededLocked(UriPermission perm) {
+        if ((perm.modeFlags&(Intent.FLAG_GRANT_READ_URI_PERMISSION
+                |Intent.FLAG_GRANT_WRITE_URI_PERMISSION)) == 0) {
+            ArrayMap<Uri, UriPermission> perms
+                    = mGrantedUriPermissions.get(perm.targetUid);
+            if (perms != null) {
+                if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
+                        "Removing " + perm.targetUid + " permission to " + perm.uri);
+                perms.remove(perm.uri);
+                if (perms.size() == 0) {
+                    mGrantedUriPermissions.remove(perm.targetUid);
+                }
+            }
+        }
+    }
+
+    private void revokeUriPermissionLocked(int callingUid, Uri uri, int modeFlags) {
+        if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Revoking all granted permissions to " + uri);
+
+        final IPackageManager pm = AppGlobals.getPackageManager();
+        final String authority = uri.getAuthority();
+        final ProviderInfo pi = getProviderInfoLocked(authority, UserHandle.getUserId(callingUid));
+        if (pi == null) {
+            Slog.w(TAG, "No content provider found for permission revoke: " + uri.toSafeString());
+            return;
+        }
+
+        // Does the caller have this permission on the URI?
+        if (!checkHoldingPermissionsLocked(pm, pi, uri, callingUid, modeFlags)) {
+            // Right now, if you are not the original owner of the permission,
+            // you are not allowed to revoke it.
+            //if (!checkUriPermissionLocked(uri, callingUid, modeFlags)) {
+                throw new SecurityException("Uid " + callingUid
+                        + " does not have permission to uri " + uri);
+            //}
+        }
+
+        boolean persistChanged = false;
+
+        // Go through all of the permissions and remove any that match.
+        final List<String> SEGMENTS = uri.getPathSegments();
+        if (SEGMENTS != null) {
+            final int NS = SEGMENTS.size();
+            int N = mGrantedUriPermissions.size();
+            for (int i=0; i<N; i++) {
+                ArrayMap<Uri, UriPermission> perms
+                        = mGrantedUriPermissions.valueAt(i);
+                Iterator<UriPermission> it = perms.values().iterator();
+            toploop:
+                while (it.hasNext()) {
+                    UriPermission perm = it.next();
+                    Uri targetUri = perm.uri;
+                    if (!authority.equals(targetUri.getAuthority())) {
+                        continue;
+                    }
+                    List<String> targetSegments = targetUri.getPathSegments();
+                    if (targetSegments == null) {
+                        continue;
+                    }
+                    if (targetSegments.size() < NS) {
+                        continue;
+                    }
+                    for (int j=0; j<NS; j++) {
+                        if (!SEGMENTS.get(j).equals(targetSegments.get(j))) {
+                            continue toploop;
+                        }
+                    }
+                    if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
+                            "Revoking " + perm.targetUid + " permission to " + perm.uri);
+                    persistChanged |= perm.clearModes(modeFlags, true);
+                    if (perm.modeFlags == 0) {
+                        it.remove();
+                    }
+                }
+                if (perms.size() == 0) {
+                    mGrantedUriPermissions.remove(
+                            mGrantedUriPermissions.keyAt(i));
+                    N--;
+                    i--;
+                }
+            }
+        }
+
+        if (persistChanged) {
+            schedulePersistUriGrants();
+        }
+    }
+
+    @Override
+    public void revokeUriPermission(IApplicationThread caller, Uri uri,
+            int modeFlags) {
+        enforceNotIsolatedCaller("revokeUriPermission");
+        synchronized(this) {
+            final ProcessRecord r = getRecordForAppLocked(caller);
+            if (r == null) {
+                throw new SecurityException("Unable to find app for caller "
+                        + caller
+                        + " when revoking permission to uri " + uri);
+            }
+            if (uri == null) {
+                Slog.w(TAG, "revokeUriPermission: null uri");
+                return;
+            }
+
+            modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
+                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+            if (modeFlags == 0) {
+                return;
+            }
+
+            final IPackageManager pm = AppGlobals.getPackageManager();
+            final String authority = uri.getAuthority();
+            final ProviderInfo pi = getProviderInfoLocked(authority, r.userId);
+            if (pi == null) {
+                Slog.w(TAG, "No content provider found for permission revoke: "
+                        + uri.toSafeString());
+                return;
+            }
+
+            revokeUriPermissionLocked(r.uid, uri, modeFlags);
+        }
+    }
+
+    /**
+     * Remove any {@link UriPermission} granted <em>from</em> or <em>to</em> the
+     * given package.
+     *
+     * @param packageName Package name to match, or {@code null} to apply to all
+     *            packages.
+     * @param userHandle User to match, or {@link UserHandle#USER_ALL} to apply
+     *            to all users.
+     * @param persistable If persistable grants should be removed.
+     */
+    private void removeUriPermissionsForPackageLocked(
+            String packageName, int userHandle, boolean persistable) {
+        if (userHandle == UserHandle.USER_ALL && packageName == null) {
+            throw new IllegalArgumentException("Must narrow by either package or user");
+        }
+
+        boolean persistChanged = false;
+
+        final int size = mGrantedUriPermissions.size();
+        for (int i = 0; i < size; i++) {
+            // Only inspect grants matching user
+            if (userHandle == UserHandle.USER_ALL
+                    || userHandle == UserHandle.getUserId(mGrantedUriPermissions.keyAt(i))) {
+                final Iterator<UriPermission> it = mGrantedUriPermissions.valueAt(i)
+                        .values().iterator();
+                while (it.hasNext()) {
+                    final UriPermission perm = it.next();
+
+                    // Only inspect grants matching package
+                    if (packageName == null || perm.sourcePkg.equals(packageName)
+                            || perm.targetPkg.equals(packageName)) {
+                        persistChanged |= perm.clearModes(~0, persistable);
+
+                        // Only remove when no modes remain; any persisted grants
+                        // will keep this alive.
+                        if (perm.modeFlags == 0) {
+                            it.remove();
+                        }
+                    }
+                }
+            }
+        }
+
+        if (persistChanged) {
+            schedulePersistUriGrants();
+        }
+    }
+
+    @Override
+    public IBinder newUriPermissionOwner(String name) {
+        enforceNotIsolatedCaller("newUriPermissionOwner");
+        synchronized(this) {
+            UriPermissionOwner owner = new UriPermissionOwner(this, name);
+            return owner.getExternalTokenLocked();
+        }
+    }
+
+    @Override
+    public void grantUriPermissionFromOwner(IBinder token, int fromUid, String targetPkg,
+            Uri uri, int modeFlags) {
+        synchronized(this) {
+            UriPermissionOwner owner = UriPermissionOwner.fromExternalToken(token);
+            if (owner == null) {
+                throw new IllegalArgumentException("Unknown owner: " + token);
+            }
+            if (fromUid != Binder.getCallingUid()) {
+                if (Binder.getCallingUid() != Process.myUid()) {
+                    // Only system code can grant URI permissions on behalf
+                    // of other users.
+                    throw new SecurityException("nice try");
+                }
+            }
+            if (targetPkg == null) {
+                throw new IllegalArgumentException("null target");
+            }
+            if (uri == null) {
+                throw new IllegalArgumentException("null uri");
+            }
+
+            grantUriPermissionLocked(fromUid, targetPkg, uri, modeFlags, owner);
+        }
+    }
+
+    @Override
+    public void revokeUriPermissionFromOwner(IBinder token, Uri uri, int mode) {
+        synchronized(this) {
+            UriPermissionOwner owner = UriPermissionOwner.fromExternalToken(token);
+            if (owner == null) {
+                throw new IllegalArgumentException("Unknown owner: " + token);
+            }
+
+            if (uri == null) {
+                owner.removeUriPermissionsLocked(mode);
+            } else {
+                owner.removeUriPermissionLocked(uri, mode);
+            }
+        }
+    }
+
+    private void schedulePersistUriGrants() {
+        if (!mHandler.hasMessages(PERSIST_URI_GRANTS_MSG)) {
+            mHandler.sendMessageDelayed(mHandler.obtainMessage(PERSIST_URI_GRANTS_MSG),
+                    10 * DateUtils.SECOND_IN_MILLIS);
+        }
+    }
+
+    private void writeGrantedUriPermissions() {
+        if (DEBUG_URI_PERMISSION) Slog.v(TAG, "writeGrantedUriPermissions()");
+
+        // Snapshot permissions so we can persist without lock
+        ArrayList<UriPermission.Snapshot> persist = Lists.newArrayList();
+        synchronized (this) {
+            final int size = mGrantedUriPermissions.size();
+            for (int i = 0 ; i < size; i++) {
+                for (UriPermission perm : mGrantedUriPermissions.valueAt(i).values()) {
+                    if (perm.persistedModeFlags != 0) {
+                        persist.add(perm.snapshot());
+                    }
+                }
+            }
+        }
+
+        FileOutputStream fos = null;
+        try {
+            fos = mGrantFile.startWrite();
+
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            out.startDocument(null, true);
+            out.startTag(null, TAG_URI_GRANTS);
+            for (UriPermission.Snapshot perm : persist) {
+                out.startTag(null, TAG_URI_GRANT);
+                writeIntAttribute(out, ATTR_USER_HANDLE, perm.userHandle);
+                out.attribute(null, ATTR_SOURCE_PKG, perm.sourcePkg);
+                out.attribute(null, ATTR_TARGET_PKG, perm.targetPkg);
+                out.attribute(null, ATTR_URI, String.valueOf(perm.uri));
+                writeIntAttribute(out, ATTR_MODE_FLAGS, perm.persistedModeFlags);
+                writeLongAttribute(out, ATTR_CREATED_TIME, perm.persistedCreateTime);
+                out.endTag(null, TAG_URI_GRANT);
+            }
+            out.endTag(null, TAG_URI_GRANTS);
+            out.endDocument();
+
+            mGrantFile.finishWrite(fos);
+        } catch (IOException e) {
+            if (fos != null) {
+                mGrantFile.failWrite(fos);
+            }
+        }
+    }
+
+    private void readGrantedUriPermissionsLocked() {
+        if (DEBUG_URI_PERMISSION) Slog.v(TAG, "readGrantedUriPermissions()");
+
+        final long now = System.currentTimeMillis();
+
+        FileInputStream fis = null;
+        try {
+            fis = mGrantFile.openRead();
+            final XmlPullParser in = Xml.newPullParser();
+            in.setInput(fis, null);
+
+            int type;
+            while ((type = in.next()) != END_DOCUMENT) {
+                final String tag = in.getName();
+                if (type == START_TAG) {
+                    if (TAG_URI_GRANT.equals(tag)) {
+                        final int userHandle = readIntAttribute(in, ATTR_USER_HANDLE);
+                        final String sourcePkg = in.getAttributeValue(null, ATTR_SOURCE_PKG);
+                        final String targetPkg = in.getAttributeValue(null, ATTR_TARGET_PKG);
+                        final Uri uri = Uri.parse(in.getAttributeValue(null, ATTR_URI));
+                        final int modeFlags = readIntAttribute(in, ATTR_MODE_FLAGS);
+                        final long createdTime = readLongAttribute(in, ATTR_CREATED_TIME, now);
+
+                        // Sanity check that provider still belongs to source package
+                        final ProviderInfo pi = getProviderInfoLocked(
+                                uri.getAuthority(), userHandle);
+                        if (pi != null && sourcePkg.equals(pi.packageName)) {
+                            int targetUid = -1;
+                            try {
+                                targetUid = AppGlobals.getPackageManager()
+                                        .getPackageUid(targetPkg, userHandle);
+                            } catch (RemoteException e) {
+                            }
+                            if (targetUid != -1) {
+                                final UriPermission perm = findOrCreateUriPermissionLocked(
+                                        sourcePkg, targetPkg, targetUid, uri);
+                                perm.initPersistedModes(modeFlags, createdTime);
+                            }
+                        } else {
+                            Slog.w(TAG, "Persisted grant for " + uri + " had source " + sourcePkg
+                                    + " but instead found " + pi);
+                        }
+                    }
+                }
+            }
+        } catch (FileNotFoundException e) {
+            // Missing grants is okay
+        } catch (IOException e) {
+            Log.wtf(TAG, "Failed reading Uri grants", e);
+        } catch (XmlPullParserException e) {
+            Log.wtf(TAG, "Failed reading Uri grants", e);
+        } finally {
+            IoUtils.closeQuietly(fis);
+        }
+    }
+
+    @Override
+    public void takePersistableUriPermission(Uri uri, int modeFlags) {
+        enforceNotIsolatedCaller("takePersistableUriPermission");
+
+        Preconditions.checkFlagsArgument(modeFlags,
+                Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
+        synchronized (this) {
+            final int callingUid = Binder.getCallingUid();
+            final UriPermission perm = findUriPermissionLocked(callingUid, uri);
+            if (perm == null) {
+                throw new SecurityException("No permission grant found for UID " + callingUid
+                        + " and Uri " + uri.toSafeString());
+            }
+
+            boolean persistChanged = perm.takePersistableModes(modeFlags);
+            persistChanged |= maybePrunePersistedUriGrantsLocked(callingUid);
+
+            if (persistChanged) {
+                schedulePersistUriGrants();
+            }
+        }
+    }
+
+    @Override
+    public void releasePersistableUriPermission(Uri uri, int modeFlags) {
+        enforceNotIsolatedCaller("releasePersistableUriPermission");
+
+        Preconditions.checkFlagsArgument(modeFlags,
+                Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
+        synchronized (this) {
+            final int callingUid = Binder.getCallingUid();
+
+            final UriPermission perm = findUriPermissionLocked(callingUid, uri);
+            if (perm == null) {
+                Slog.w(TAG, "No permission grant found for UID " + callingUid + " and Uri "
+                        + uri.toSafeString());
+                return;
+            }
+
+            final boolean persistChanged = perm.releasePersistableModes(modeFlags);
+            removeUriPermissionIfNeededLocked(perm);
+            if (persistChanged) {
+                schedulePersistUriGrants();
+            }
+        }
+    }
+
+    /**
+     * Prune any older {@link UriPermission} for the given UID until outstanding
+     * persisted grants are below {@link #MAX_PERSISTED_URI_GRANTS}.
+     *
+     * @return if any mutations occured that require persisting.
+     */
+    private boolean maybePrunePersistedUriGrantsLocked(int uid) {
+        final ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(uid);
+        if (perms == null) return false;
+        if (perms.size() < MAX_PERSISTED_URI_GRANTS) return false;
+
+        final ArrayList<UriPermission> persisted = Lists.newArrayList();
+        for (UriPermission perm : perms.values()) {
+            if (perm.persistedModeFlags != 0) {
+                persisted.add(perm);
+            }
+        }
+
+        final int trimCount = persisted.size() - MAX_PERSISTED_URI_GRANTS;
+        if (trimCount <= 0) return false;
+
+        Collections.sort(persisted, new UriPermission.PersistedTimeComparator());
+        for (int i = 0; i < trimCount; i++) {
+            final UriPermission perm = persisted.get(i);
+
+            if (DEBUG_URI_PERMISSION) {
+                Slog.v(TAG, "Trimming grant created at " + perm.persistedCreateTime);
+            }
+
+            perm.releasePersistableModes(~0);
+            removeUriPermissionIfNeededLocked(perm);
+        }
+
+        return true;
+    }
+
+    @Override
+    public ParceledListSlice<android.content.UriPermission> getPersistedUriPermissions(
+            String packageName, boolean incoming) {
+        enforceNotIsolatedCaller("getPersistedUriPermissions");
+        Preconditions.checkNotNull(packageName, "packageName");
+
+        final int callingUid = Binder.getCallingUid();
+        final IPackageManager pm = AppGlobals.getPackageManager();
+        try {
+            final int packageUid = pm.getPackageUid(packageName, UserHandle.getUserId(callingUid));
+            if (packageUid != callingUid) {
+                throw new SecurityException(
+                        "Package " + packageName + " does not belong to calling UID " + callingUid);
+            }
+        } catch (RemoteException e) {
+            throw new SecurityException("Failed to verify package name ownership");
+        }
+
+        final ArrayList<android.content.UriPermission> result = Lists.newArrayList();
+        synchronized (this) {
+            if (incoming) {
+                final ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(callingUid);
+                if (perms == null) {
+                    Slog.w(TAG, "No permission grants found for " + packageName);
+                } else {
+                    final int size = perms.size();
+                    for (int i = 0; i < size; i++) {
+                        final UriPermission perm = perms.valueAt(i);
+                        if (packageName.equals(perm.targetPkg) && perm.persistedModeFlags != 0) {
+                            result.add(perm.buildPersistedPublicApiObject());
+                        }
+                    }
+                }
+            } else {
+                final int size = mGrantedUriPermissions.size();
+                for (int i = 0; i < size; i++) {
+                    final ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.valueAt(i);
+                    final int permsSize = perms.size();
+                    for (int j = 0; j < permsSize; j++) {
+                        final UriPermission perm = perms.valueAt(j);
+                        if (packageName.equals(perm.sourcePkg) && perm.persistedModeFlags != 0) {
+                            result.add(perm.buildPersistedPublicApiObject());
+                        }
+                    }
+                }
+            }
+        }
+        return new ParceledListSlice<android.content.UriPermission>(result);
+    }
+
+    @Override
+    public void showWaitingForDebugger(IApplicationThread who, boolean waiting) {
+        synchronized (this) {
+            ProcessRecord app =
+                who != null ? getRecordForAppLocked(who) : null;
+            if (app == null) return;
+
+            Message msg = Message.obtain();
+            msg.what = WAIT_FOR_DEBUGGER_MSG;
+            msg.obj = app;
+            msg.arg1 = waiting ? 1 : 0;
+            mHandler.sendMessage(msg);
+        }
+    }
+
+    @Override
+    public void getMemoryInfo(ActivityManager.MemoryInfo outInfo) {
+        final long homeAppMem = mProcessList.getMemLevel(ProcessList.HOME_APP_ADJ);
+        final long cachedAppMem = mProcessList.getMemLevel(ProcessList.CACHED_APP_MIN_ADJ);
+        outInfo.availMem = Process.getFreeMemory();
+        outInfo.totalMem = Process.getTotalMemory();
+        outInfo.threshold = homeAppMem;
+        outInfo.lowMemory = outInfo.availMem < (homeAppMem + ((cachedAppMem-homeAppMem)/2));
+        outInfo.hiddenAppThreshold = cachedAppMem;
+        outInfo.secondaryServerThreshold = mProcessList.getMemLevel(
+                ProcessList.SERVICE_ADJ);
+        outInfo.visibleAppThreshold = mProcessList.getMemLevel(
+                ProcessList.VISIBLE_APP_ADJ);
+        outInfo.foregroundAppThreshold = mProcessList.getMemLevel(
+                ProcessList.FOREGROUND_APP_ADJ);
+    }
+    
+    // =========================================================
+    // TASK MANAGEMENT
+    // =========================================================
+
+    @Override
+    public List<RunningTaskInfo> getTasks(int maxNum, int flags,
+                         IThumbnailReceiver receiver) {
+        ArrayList<RunningTaskInfo> list = new ArrayList<RunningTaskInfo>();
+
+        PendingThumbnailsRecord pending = new PendingThumbnailsRecord(receiver);
+        ActivityRecord topRecord = null;
+
+        synchronized(this) {
+            if (localLOGV) Slog.v(
+                TAG, "getTasks: max=" + maxNum + ", flags=" + flags
+                + ", receiver=" + receiver);
+
+            if (checkCallingPermission(android.Manifest.permission.GET_TASKS)
+                    != PackageManager.PERMISSION_GRANTED) {
+                if (receiver != null) {
+                    // If the caller wants to wait for pending thumbnails,
+                    // it ain't gonna get them.
+                    try {
+                        receiver.finished();
+                    } catch (RemoteException ex) {
+                    }
+                }
+                String msg = "Permission Denial: getTasks() from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid()
+                        + " requires " + android.Manifest.permission.GET_TASKS;
+                Slog.w(TAG, msg);
+                throw new SecurityException(msg);
+            }
+
+            // TODO: Improve with MRU list from all ActivityStacks.
+            topRecord = mStackSupervisor.getTasksLocked(maxNum, receiver, pending, list);
+
+            if (!pending.pendingRecords.isEmpty()) {
+                mPendingThumbnails.add(pending);
+            }
+        }
+
+        if (localLOGV) Slog.v(TAG, "We have pending thumbnails: " + pending);
+
+        if (topRecord != null) {
+            if (localLOGV) Slog.v(TAG, "Requesting top thumbnail");
+            try {
+                IApplicationThread topThumbnail = topRecord.app.thread;
+                topThumbnail.requestThumbnail(topRecord.appToken);
+            } catch (Exception e) {
+                Slog.w(TAG, "Exception thrown when requesting thumbnail", e);
+                sendPendingThumbnail(null, topRecord.appToken, null, null, true);
+            }
+        }
+
+        if (pending == null && receiver != null) {
+            // In this case all thumbnails were available and the client
+            // is being asked to be told when the remaining ones come in...
+            // which is unusually, since the top-most currently running
+            // activity should never have a canned thumbnail!  Oh well.
+            try {
+                receiver.finished();
+            } catch (RemoteException ex) {
+            }
+        }
+
+        return list;
+    }
+
+    TaskRecord getMostRecentTask() {
+        return mRecentTasks.get(0);
+    }
+
+    @Override
+    public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
+            int flags, int userId) {
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "getRecentTasks", null);
+
+        synchronized (this) {
+            enforceCallingPermission(android.Manifest.permission.GET_TASKS,
+                    "getRecentTasks()");
+            final boolean detailed = checkCallingPermission(
+                    android.Manifest.permission.GET_DETAILED_TASKS)
+                    == PackageManager.PERMISSION_GRANTED;
+
+            IPackageManager pm = AppGlobals.getPackageManager();
+
+            final int N = mRecentTasks.size();
+            ArrayList<ActivityManager.RecentTaskInfo> res
+                    = new ArrayList<ActivityManager.RecentTaskInfo>(
+                            maxNum < N ? maxNum : N);
+            for (int i=0; i<N && maxNum > 0; i++) {
+                TaskRecord tr = mRecentTasks.get(i);
+                // Only add calling user's recent tasks
+                if (tr.userId != userId) continue;
+                // Return the entry if desired by the caller.  We always return
+                // the first entry, because callers always expect this to be the
+                // foreground app.  We may filter others if the caller has
+                // not supplied RECENT_WITH_EXCLUDED and there is some reason
+                // we should exclude the entry.
+
+                if (i == 0
+                        || ((flags&ActivityManager.RECENT_WITH_EXCLUDED) != 0)
+                        || (tr.intent == null)
+                        || ((tr.intent.getFlags()
+                                &Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0)) {
+                    ActivityManager.RecentTaskInfo rti
+                            = new ActivityManager.RecentTaskInfo();
+                    rti.id = tr.numActivities > 0 ? tr.taskId : -1;
+                    rti.persistentId = tr.taskId;
+                    rti.baseIntent = new Intent(
+                            tr.intent != null ? tr.intent : tr.affinityIntent);
+                    if (!detailed) {
+                        rti.baseIntent.replaceExtras((Bundle)null);
+                    }
+                    rti.origActivity = tr.origActivity;
+                    rti.description = tr.lastDescription;
+                    rti.stackId = tr.stack.mStackId;
+
+                    if ((flags&ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) {
+                        // Check whether this activity is currently available.
+                        try {
+                            if (rti.origActivity != null) {
+                                if (pm.getActivityInfo(rti.origActivity, 0, userId)
+                                        == null) {
+                                    continue;
+                                }
+                            } else if (rti.baseIntent != null) {
+                                if (pm.queryIntentActivities(rti.baseIntent,
+                                        null, 0, userId) == null) {
+                                    continue;
+                                }
+                            }
+                        } catch (RemoteException e) {
+                            // Will never happen.
+                        }
+                    }
+                    
+                    res.add(rti);
+                    maxNum--;
+                }
+            }
+            return res;
+        }
+    }
+
+    private TaskRecord recentTaskForIdLocked(int id) {
+        final int N = mRecentTasks.size();
+            for (int i=0; i<N; i++) {
+                TaskRecord tr = mRecentTasks.get(i);
+                if (tr.taskId == id) {
+                    return tr;
+                }
+            }
+            return null;
+    }
+
+    @Override
+    public ActivityManager.TaskThumbnails getTaskThumbnails(int id) {
+        synchronized (this) {
+            enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
+                    "getTaskThumbnails()");
+            TaskRecord tr = recentTaskForIdLocked(id);
+            if (tr != null) {
+                return tr.getTaskThumbnailsLocked();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public Bitmap getTaskTopThumbnail(int id) {
+        synchronized (this) {
+            enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
+                    "getTaskTopThumbnail()");
+            TaskRecord tr = recentTaskForIdLocked(id);
+            if (tr != null) {
+                return tr.getTaskTopThumbnailLocked();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public boolean removeSubTask(int taskId, int subTaskIndex) {
+        synchronized (this) {
+            enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,
+                    "removeSubTask()");
+            long ident = Binder.clearCallingIdentity();
+            try {
+                TaskRecord tr = recentTaskForIdLocked(taskId);
+                if (tr != null) {
+                    return tr.removeTaskActivitiesLocked(subTaskIndex, true) != null;
+                }
+                return false;
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    private void killUnneededProcessLocked(ProcessRecord pr, String reason) {
+        if (!pr.killedByAm) {
+            Slog.i(TAG, "Killing " + pr.toShortString() + " (adj " + pr.setAdj + "): " + reason);
+            EventLog.writeEvent(EventLogTags.AM_KILL, pr.userId, pr.pid,
+                    pr.processName, pr.setAdj, reason);
+            pr.killedByAm = true;
+            Process.killProcessQuiet(pr.pid);
+        }
+    }
+
+    private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
+        tr.disposeThumbnail();
+        mRecentTasks.remove(tr);
+        final boolean killProcesses = (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
+        Intent baseIntent = new Intent(
+                tr.intent != null ? tr.intent : tr.affinityIntent);
+        ComponentName component = baseIntent.getComponent();
+        if (component == null) {
+            Slog.w(TAG, "Now component for base intent of task: " + tr);
+            return;
+        }
+
+        // Find any running services associated with this app.
+        mServices.cleanUpRemovedTaskLocked(tr, component, baseIntent);
+
+        if (killProcesses) {
+            // Find any running processes associated with this app.
+            final String pkg = component.getPackageName();
+            ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
+            ArrayMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
+            for (int i=0; i<pmap.size(); i++) {
+                SparseArray<ProcessRecord> uids = pmap.valueAt(i);
+                for (int j=0; j<uids.size(); j++) {
+                    ProcessRecord proc = uids.valueAt(j);
+                    if (proc.userId != tr.userId) {
+                        continue;
+                    }
+                    if (!proc.pkgList.containsKey(pkg)) {
+                        continue;
+                    }
+                    procs.add(proc);
+                }
+            }
+
+            // Kill the running processes.
+            for (int i=0; i<procs.size(); i++) {
+                ProcessRecord pr = procs.get(i);
+                if (pr == mHomeProcess) {
+                    // Don't kill the home process along with tasks from the same package.
+                    continue;
+                }
+                if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
+                    killUnneededProcessLocked(pr, "remove task");
+                } else {
+                    pr.waitingToKill = "remove task";
+                }
+            }
+        }
+    }
+
+    @Override
+    public boolean removeTask(int taskId, int flags) {
+        synchronized (this) {
+            enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,
+                    "removeTask()");
+            long ident = Binder.clearCallingIdentity();
+            try {
+                TaskRecord tr = recentTaskForIdLocked(taskId);
+                if (tr != null) {
+                    ActivityRecord r = tr.removeTaskActivitiesLocked(-1, false);
+                    if (r != null) {
+                        cleanUpRemovedTaskLocked(tr, flags);
+                        return true;
+                    }
+                    if (tr.mActivities.size() == 0) {
+                        // Caller is just removing a recent task that is
+                        // not actively running.  That is easy!
+                        cleanUpRemovedTaskLocked(tr, flags);
+                        return true;
+                    }
+                    Slog.w(TAG, "removeTask: task " + taskId
+                            + " does not have activities to remove, "
+                            + " but numActivities=" + tr.numActivities
+                            + ": " + tr);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+        return false;
+    }
+    
+    /**
+     * TODO: Add mController hook
+     */
+    @Override
+    public void moveTaskToFront(int task, int flags, Bundle options) {
+        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
+                "moveTaskToFront()");
+
+        if (DEBUG_STACK) Slog.d(TAG, "moveTaskToFront: moving task=" + task);
+        synchronized(this) {
+            if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
+                    Binder.getCallingUid(), "Task to front")) {
+                ActivityOptions.abort(options);
+                return;
+            }
+            final long origId = Binder.clearCallingIdentity();
+            try {
+                mStackSupervisor.findTaskToMoveToFrontLocked(task, flags, options);
+            } finally {
+                Binder.restoreCallingIdentity(origId);
+            }
+            ActivityOptions.abort(options);
+        }
+    }
+
+    @Override
+    public void moveTaskToBack(int taskId) {
+        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
+                "moveTaskToBack()");
+
+        synchronized(this) {
+            TaskRecord tr = recentTaskForIdLocked(taskId);
+            if (tr != null) {
+                if (DEBUG_STACK) Slog.d(TAG, "moveTaskToBack: moving task=" + tr);
+                ActivityStack stack = tr.stack;
+                if (stack.mResumedActivity != null && stack.mResumedActivity.task == tr) {
+                    if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
+                            Binder.getCallingUid(), "Task to back")) {
+                        return;
+                    }
+                }
+                final long origId = Binder.clearCallingIdentity();
+                try {
+                    stack.moveTaskToBackLocked(taskId, null);
+                } finally {
+                    Binder.restoreCallingIdentity(origId);
+                }
+            }
+        }
+    }
+
+    /**
+     * Moves an activity, and all of the other activities within the same task, to the bottom
+     * of the history stack.  The activity's order within the task is unchanged.
+     * 
+     * @param token A reference to the activity we wish to move
+     * @param nonRoot If false then this only works if the activity is the root
+     *                of a task; if true it will work for any activity in a task.
+     * @return Returns true if the move completed, false if not.
+     */
+    @Override
+    public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) {
+        enforceNotIsolatedCaller("moveActivityTaskToBack");
+        synchronized(this) {
+            final long origId = Binder.clearCallingIdentity();
+            int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot);
+            if (taskId >= 0) {
+                return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId, null);
+            }
+            Binder.restoreCallingIdentity(origId);
+        }
+        return false;
+    }
+
+    @Override
+    public void moveTaskBackwards(int task) {
+        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
+                "moveTaskBackwards()");
+
+        synchronized(this) {
+            if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
+                    Binder.getCallingUid(), "Task backwards")) {
+                return;
+            }
+            final long origId = Binder.clearCallingIdentity();
+            moveTaskBackwardsLocked(task);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    private final void moveTaskBackwardsLocked(int task) {
+        Slog.e(TAG, "moveTaskBackwards not yet implemented!");
+    }
+
+    @Override
+    public IBinder getHomeActivityToken() throws RemoteException {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "getHomeActivityToken()");
+        synchronized (this) {
+            return mStackSupervisor.getHomeActivityToken();
+        }
+    }
+
+    @Override
+    public IActivityContainer createActivityContainer(IBinder parentActivityToken,
+            IActivityContainerCallback callback) throws RemoteException {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "createActivityContainer()");
+        synchronized (this) {
+            if (parentActivityToken == null) {
+                throw new IllegalArgumentException("parent token must not be null");
+            }
+            ActivityRecord r = ActivityRecord.forToken(parentActivityToken);
+            if (r == null) {
+                return null;
+            }
+            return mStackSupervisor.createActivityContainer(r, callback);
+        }
+    }
+
+    @Override
+    public void deleteActivityContainer(IActivityContainer container) throws RemoteException {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "deleteActivityContainer()");
+        synchronized (this) {
+            mStackSupervisor.deleteActivityContainer(container);
+        }
+    }
+
+    @Override
+    public IActivityContainer getEnclosingActivityContainer(IBinder activityToken)
+            throws RemoteException {
+        synchronized (this) {
+            ActivityStack stack = ActivityRecord.getStackLocked(activityToken);
+            if (stack != null) {
+                return stack.mActivityContainer;
+            }
+            return null;
+        }
+    }
+
+    @Override
+    public void moveTaskToStack(int taskId, int stackId, boolean toTop) {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "moveTaskToStack()");
+        if (stackId == HOME_STACK_ID) {
+            Slog.e(TAG, "moveTaskToStack: Attempt to move task " + taskId + " to home stack",
+                    new RuntimeException("here").fillInStackTrace());
+        }
+        synchronized (this) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                if (DEBUG_STACK) Slog.d(TAG, "moveTaskToStack: moving task=" + taskId + " to stackId="
+                        + stackId + " toTop=" + toTop);
+                mStackSupervisor.moveTaskToStack(taskId, stackId, toTop);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    @Override
+    public void resizeStack(int stackBoxId, Rect bounds) {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "resizeStackBox()");
+        long ident = Binder.clearCallingIdentity();
+        try {
+            mWindowManager.resizeStack(stackBoxId, bounds);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public List<StackInfo> getAllStackInfos() {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "getAllStackInfos()");
+        long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                return mStackSupervisor.getAllStackInfosLocked();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public StackInfo getStackInfo(int stackId) {
+        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
+                "getStackInfo()");
+        long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                return mStackSupervisor.getStackInfoLocked(stackId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public int getTaskForActivity(IBinder token, boolean onlyRoot) {
+        synchronized(this) {
+            return ActivityRecord.getTaskForActivityLocked(token, onlyRoot);
+        }
+    }
+
+    // =========================================================
+    // THUMBNAILS
+    // =========================================================
+
+    public void reportThumbnail(IBinder token,
+            Bitmap thumbnail, CharSequence description) {
+        //System.out.println("Report thumbnail for " + token + ": " + thumbnail);
+        final long origId = Binder.clearCallingIdentity();
+        sendPendingThumbnail(null, token, thumbnail, description, true);
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    final void sendPendingThumbnail(ActivityRecord r, IBinder token,
+            Bitmap thumbnail, CharSequence description, boolean always) {
+        TaskRecord task;
+        ArrayList<PendingThumbnailsRecord> receivers = null;
+
+        //System.out.println("Send pending thumbnail: " + r);
+
+        synchronized(this) {
+            if (r == null) {
+                r = ActivityRecord.isInStackLocked(token);
+                if (r == null) {
+                    return;
+                }
+            }
+            if (thumbnail == null && r.thumbHolder != null) {
+                thumbnail = r.thumbHolder.lastThumbnail;
+                description = r.thumbHolder.lastDescription;
+            }
+            if (thumbnail == null && !always) {
+                // If there is no thumbnail, and this entry is not actually
+                // going away, then abort for now and pick up the next
+                // thumbnail we get.
+                return;
+            }
+            task = r.task;
+
+            int N = mPendingThumbnails.size();
+            int i=0;
+            while (i<N) {
+                PendingThumbnailsRecord pr = mPendingThumbnails.get(i);
+                //System.out.println("Looking in " + pr.pendingRecords);
+                if (pr.pendingRecords.remove(r)) {
+                    if (receivers == null) {
+                        receivers = new ArrayList<PendingThumbnailsRecord>();
+                    }
+                    receivers.add(pr);
+                    if (pr.pendingRecords.size() == 0) {
+                        pr.finished = true;
+                        mPendingThumbnails.remove(i);
+                        N--;
+                        continue;
+                    }
+                }
+                i++;
+            }
+        }
+
+        if (receivers != null) {
+            final int N = receivers.size();
+            for (int i=0; i<N; i++) {
+                try {
+                    PendingThumbnailsRecord pr = receivers.get(i);
+                    pr.receiver.newThumbnail(
+                        task != null ? task.taskId : -1, thumbnail, description);
+                    if (pr.finished) {
+                        pr.receiver.finished();
+                    }
+                } catch (Exception e) {
+                    Slog.w(TAG, "Exception thrown when sending thumbnail", e);
+                }
+            }
+        }
+    }
+
+    // =========================================================
+    // CONTENT PROVIDERS
+    // =========================================================
+
+    private final List<ProviderInfo> generateApplicationProvidersLocked(ProcessRecord app) {
+        List<ProviderInfo> providers = null;
+        try {
+            providers = AppGlobals.getPackageManager().
+                queryContentProviders(app.processName, app.uid,
+                        STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS);
+        } catch (RemoteException ex) {
+        }
+        if (DEBUG_MU)
+            Slog.v(TAG_MU, "generateApplicationProvidersLocked, app.info.uid = " + app.uid);
+        int userId = app.userId;
+        if (providers != null) {
+            int N = providers.size();
+            app.pubProviders.ensureCapacity(N + app.pubProviders.size());
+            for (int i=0; i<N; i++) {
+                ProviderInfo cpi =
+                    (ProviderInfo)providers.get(i);
+                boolean singleton = isSingleton(cpi.processName, cpi.applicationInfo,
+                        cpi.name, cpi.flags);
+                if (singleton && UserHandle.getUserId(app.uid) != 0) {
+                    // This is a singleton provider, but a user besides the
+                    // default user is asking to initialize a process it runs
+                    // in...  well, no, it doesn't actually run in this process,
+                    // it runs in the process of the default user.  Get rid of it.
+                    providers.remove(i);
+                    N--;
+                    i--;
+                    continue;
+                }
+
+                ComponentName comp = new ComponentName(cpi.packageName, cpi.name);
+                ContentProviderRecord cpr = mProviderMap.getProviderByClass(comp, userId);
+                if (cpr == null) {
+                    cpr = new ContentProviderRecord(this, cpi, app.info, comp, singleton);
+                    mProviderMap.putProviderByClass(comp, cpr);
+                }
+                if (DEBUG_MU)
+                    Slog.v(TAG_MU, "generateApplicationProvidersLocked, cpi.uid = " + cpr.uid);
+                app.pubProviders.put(cpi.name, cpr);
+                if (!cpi.multiprocess || !"android".equals(cpi.packageName)) {
+                    // Don't add this if it is a platform component that is marked
+                    // to run in multiple processes, because this is actually
+                    // part of the framework so doesn't make sense to track as a
+                    // separate apk in the process.
+                    app.addPackage(cpi.applicationInfo.packageName, mProcessStats);
+                }
+                ensurePackageDexOpt(cpi.applicationInfo.packageName);
+            }
+        }
+        return providers;
+    }
+
+    /**
+     * Check if {@link ProcessRecord} has a possible chance at accessing the
+     * given {@link ProviderInfo}. Final permission checking is always done
+     * in {@link ContentProvider}.
+     */
+    private final String checkContentProviderPermissionLocked(
+            ProviderInfo cpi, ProcessRecord r) {
+        final int callingPid = (r != null) ? r.pid : Binder.getCallingPid();
+        final int callingUid = (r != null) ? r.uid : Binder.getCallingUid();
+        if (checkComponentPermission(cpi.readPermission, callingPid, callingUid,
+                cpi.applicationInfo.uid, cpi.exported)
+                == PackageManager.PERMISSION_GRANTED) {
+            return null;
+        }
+        if (checkComponentPermission(cpi.writePermission, callingPid, callingUid,
+                cpi.applicationInfo.uid, cpi.exported)
+                == PackageManager.PERMISSION_GRANTED) {
+            return null;
+        }
+        
+        PathPermission[] pps = cpi.pathPermissions;
+        if (pps != null) {
+            int i = pps.length;
+            while (i > 0) {
+                i--;
+                PathPermission pp = pps[i];
+                if (checkComponentPermission(pp.getReadPermission(), callingPid, callingUid,
+                        cpi.applicationInfo.uid, cpi.exported)
+                        == PackageManager.PERMISSION_GRANTED) {
+                    return null;
+                }
+                if (checkComponentPermission(pp.getWritePermission(), callingPid, callingUid,
+                        cpi.applicationInfo.uid, cpi.exported)
+                        == PackageManager.PERMISSION_GRANTED) {
+                    return null;
+                }
+            }
+        }
+        
+        ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(callingUid);
+        if (perms != null) {
+            for (Map.Entry<Uri, UriPermission> uri : perms.entrySet()) {
+                if (uri.getKey().getAuthority().equals(cpi.authority)) {
+                    return null;
+                }
+            }
+        }
+
+        String msg;
+        if (!cpi.exported) {
+            msg = "Permission Denial: opening provider " + cpi.name
+                    + " from " + (r != null ? r : "(null)") + " (pid=" + callingPid
+                    + ", uid=" + callingUid + ") that is not exported from uid "
+                    + cpi.applicationInfo.uid;
+        } else {
+            msg = "Permission Denial: opening provider " + cpi.name
+                    + " from " + (r != null ? r : "(null)") + " (pid=" + callingPid
+                    + ", uid=" + callingUid + ") requires "
+                    + cpi.readPermission + " or " + cpi.writePermission;
+        }
+        Slog.w(TAG, msg);
+        return msg;
+    }
+
+    ContentProviderConnection incProviderCountLocked(ProcessRecord r,
+            final ContentProviderRecord cpr, IBinder externalProcessToken, boolean stable) {
+        if (r != null) {
+            for (int i=0; i<r.conProviders.size(); i++) {
+                ContentProviderConnection conn = r.conProviders.get(i);
+                if (conn.provider == cpr) {
+                    if (DEBUG_PROVIDER) Slog.v(TAG,
+                            "Adding provider requested by "
+                            + r.processName + " from process "
+                            + cpr.info.processName + ": " + cpr.name.flattenToShortString()
+                            + " scnt=" + conn.stableCount + " uscnt=" + conn.unstableCount);
+                    if (stable) {
+                        conn.stableCount++;
+                        conn.numStableIncs++;
+                    } else {
+                        conn.unstableCount++;
+                        conn.numUnstableIncs++;
+                    }
+                    return conn;
+                }
+            }
+            ContentProviderConnection conn = new ContentProviderConnection(cpr, r);
+            if (stable) {
+                conn.stableCount = 1;
+                conn.numStableIncs = 1;
+            } else {
+                conn.unstableCount = 1;
+                conn.numUnstableIncs = 1;
+            }
+            cpr.connections.add(conn);
+            r.conProviders.add(conn);
+            return conn;
+        }
+        cpr.addExternalProcessHandleLocked(externalProcessToken);
+        return null;
+    }
+
+    boolean decProviderCountLocked(ContentProviderConnection conn,
+            ContentProviderRecord cpr, IBinder externalProcessToken, boolean stable) {
+        if (conn != null) {
+            cpr = conn.provider;
+            if (DEBUG_PROVIDER) Slog.v(TAG,
+                    "Removing provider requested by "
+                    + conn.client.processName + " from process "
+                    + cpr.info.processName + ": " + cpr.name.flattenToShortString()
+                    + " scnt=" + conn.stableCount + " uscnt=" + conn.unstableCount);
+            if (stable) {
+                conn.stableCount--;
+            } else {
+                conn.unstableCount--;
+            }
+            if (conn.stableCount == 0 && conn.unstableCount == 0) {
+                cpr.connections.remove(conn);
+                conn.client.conProviders.remove(conn);
+                return true;
+            }
+            return false;
+        }
+        cpr.removeExternalProcessHandleLocked(externalProcessToken);
+        return false;
+    }
+
+    private final ContentProviderHolder getContentProviderImpl(IApplicationThread caller,
+            String name, IBinder token, boolean stable, int userId) {
+        ContentProviderRecord cpr;
+        ContentProviderConnection conn = null;
+        ProviderInfo cpi = null;
+
+        synchronized(this) {
+            ProcessRecord r = null;
+            if (caller != null) {
+                r = getRecordForAppLocked(caller);
+                if (r == null) {
+                    throw new SecurityException(
+                            "Unable to find app for caller " + caller
+                          + " (pid=" + Binder.getCallingPid()
+                          + ") when getting content provider " + name);
+                }
+            }
+
+            // First check if this content provider has been published...
+            cpr = mProviderMap.getProviderByName(name, userId);
+            boolean providerRunning = cpr != null;
+            if (providerRunning) {
+                cpi = cpr.info;
+                String msg;
+                if ((msg=checkContentProviderPermissionLocked(cpi, r)) != null) {
+                    throw new SecurityException(msg);
+                }
+
+                if (r != null && cpr.canRunHere(r)) {
+                    // This provider has been published or is in the process
+                    // of being published...  but it is also allowed to run
+                    // in the caller's process, so don't make a connection
+                    // and just let the caller instantiate its own instance.
+                    ContentProviderHolder holder = cpr.newHolder(null);
+                    // don't give caller the provider object, it needs
+                    // to make its own.
+                    holder.provider = null;
+                    return holder;
+                }
+
+                final long origId = Binder.clearCallingIdentity();
+
+                // In this case the provider instance already exists, so we can
+                // return it right away.
+                conn = incProviderCountLocked(r, cpr, token, stable);
+                if (conn != null && (conn.stableCount+conn.unstableCount) == 1) {
+                    if (cpr.proc != null && r.setAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
+                        // If this is a perceptible app accessing the provider,
+                        // make sure to count it as being accessed and thus
+                        // back up on the LRU list.  This is good because
+                        // content providers are often expensive to start.
+                        updateLruProcessLocked(cpr.proc, false, null);
+                    }
+                }
+
+                if (cpr.proc != null) {
+                    if (false) {
+                        if (cpr.name.flattenToShortString().equals(
+                                "com.android.providers.calendar/.CalendarProvider2")) {
+                            Slog.v(TAG, "****************** KILLING "
+                                + cpr.name.flattenToShortString());
+                            Process.killProcess(cpr.proc.pid);
+                        }
+                    }
+                    boolean success = updateOomAdjLocked(cpr.proc);
+                    if (DEBUG_PROVIDER) Slog.i(TAG, "Adjust success: " + success);
+                    // NOTE: there is still a race here where a signal could be
+                    // pending on the process even though we managed to update its
+                    // adj level.  Not sure what to do about this, but at least
+                    // the race is now smaller.
+                    if (!success) {
+                        // Uh oh...  it looks like the provider's process
+                        // has been killed on us.  We need to wait for a new
+                        // process to be started, and make sure its death
+                        // doesn't kill our process.
+                        Slog.i(TAG,
+                                "Existing provider " + cpr.name.flattenToShortString()
+                                + " is crashing; detaching " + r);
+                        boolean lastRef = decProviderCountLocked(conn, cpr, token, stable);
+                        appDiedLocked(cpr.proc, cpr.proc.pid, cpr.proc.thread);
+                        if (!lastRef) {
+                            // This wasn't the last ref our process had on
+                            // the provider...  we have now been killed, bail.
+                            return null;
+                        }
+                        providerRunning = false;
+                        conn = null;
+                    }
+                }
+
+                Binder.restoreCallingIdentity(origId);
+            }
+
+            boolean singleton;
+            if (!providerRunning) {
+                try {
+                    cpi = AppGlobals.getPackageManager().
+                        resolveContentProvider(name,
+                            STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS, userId);
+                } catch (RemoteException ex) {
+                }
+                if (cpi == null) {
+                    return null;
+                }
+                singleton = isSingleton(cpi.processName, cpi.applicationInfo,
+                        cpi.name, cpi.flags); 
+                if (singleton) {
+                    userId = 0;
+                }
+                cpi.applicationInfo = getAppInfoForUser(cpi.applicationInfo, userId);
+
+                String msg;
+                if ((msg=checkContentProviderPermissionLocked(cpi, r)) != null) {
+                    throw new SecurityException(msg);
+                }
+
+                if (!mProcessesReady && !mDidUpdate && !mWaitingUpdate
+                        && !cpi.processName.equals("system")) {
+                    // If this content provider does not run in the system
+                    // process, and the system is not yet ready to run other
+                    // processes, then fail fast instead of hanging.
+                    throw new IllegalArgumentException(
+                            "Attempt to launch content provider before system ready");
+                }
+
+                // Make sure that the user who owns this provider is started.  If not,
+                // we don't want to allow it to run.
+                if (mStartedUsers.get(userId) == null) {
+                    Slog.w(TAG, "Unable to launch app "
+                            + cpi.applicationInfo.packageName + "/"
+                            + cpi.applicationInfo.uid + " for provider "
+                            + name + ": user " + userId + " is stopped");
+                    return null;
+                }
+
+                ComponentName comp = new ComponentName(cpi.packageName, cpi.name);
+                cpr = mProviderMap.getProviderByClass(comp, userId);
+                final boolean firstClass = cpr == null;
+                if (firstClass) {
+                    try {
+                        ApplicationInfo ai =
+                            AppGlobals.getPackageManager().
+                                getApplicationInfo(
+                                        cpi.applicationInfo.packageName,
+                                        STOCK_PM_FLAGS, userId);
+                        if (ai == null) {
+                            Slog.w(TAG, "No package info for content provider "
+                                    + cpi.name);
+                            return null;
+                        }
+                        ai = getAppInfoForUser(ai, userId);
+                        cpr = new ContentProviderRecord(this, cpi, ai, comp, singleton);
+                    } catch (RemoteException ex) {
+                        // pm is in same process, this will never happen.
+                    }
+                }
+
+                if (r != null && cpr.canRunHere(r)) {
+                    // If this is a multiprocess provider, then just return its
+                    // info and allow the caller to instantiate it.  Only do
+                    // this if the provider is the same user as the caller's
+                    // process, or can run as root (so can be in any process).
+                    return cpr.newHolder(null);
+                }
+
+                if (DEBUG_PROVIDER) {
+                    RuntimeException e = new RuntimeException("here");
+                    Slog.w(TAG, "LAUNCHING REMOTE PROVIDER (myuid " + (r != null ? r.uid : null)
+                          + " pruid " + cpr.appInfo.uid + "): " + cpr.info.name, e);
+                }
+
+                // This is single process, and our app is now connecting to it.
+                // See if we are already in the process of launching this
+                // provider.
+                final int N = mLaunchingProviders.size();
+                int i;
+                for (i=0; i<N; i++) {
+                    if (mLaunchingProviders.get(i) == cpr) {
+                        break;
+                    }
+                }
+
+                // If the provider is not already being launched, then get it
+                // started.
+                if (i >= N) {
+                    final long origId = Binder.clearCallingIdentity();
+
+                    try {
+                        // Content provider is now in use, its package can't be stopped.
+                        try {
+                            AppGlobals.getPackageManager().setPackageStoppedState(
+                                    cpr.appInfo.packageName, false, userId);
+                        } catch (RemoteException e) {
+                        } catch (IllegalArgumentException e) {
+                            Slog.w(TAG, "Failed trying to unstop package "
+                                    + cpr.appInfo.packageName + ": " + e);
+                        }
+
+                        // Use existing process if already started
+                        ProcessRecord proc = getProcessRecordLocked(
+                                cpi.processName, cpr.appInfo.uid, false);
+                        if (proc != null && proc.thread != null) {
+                            if (DEBUG_PROVIDER) {
+                                Slog.d(TAG, "Installing in existing process " + proc);
+                            }
+                            proc.pubProviders.put(cpi.name, cpr);
+                            try {
+                                proc.thread.scheduleInstallProvider(cpi);
+                            } catch (RemoteException e) {
+                            }
+                        } else {
+                            proc = startProcessLocked(cpi.processName,
+                                    cpr.appInfo, false, 0, "content provider",
+                                    new ComponentName(cpi.applicationInfo.packageName,
+                                            cpi.name), false, false, false);
+                            if (proc == null) {
+                                Slog.w(TAG, "Unable to launch app "
+                                        + cpi.applicationInfo.packageName + "/"
+                                        + cpi.applicationInfo.uid + " for provider "
+                                        + name + ": process is bad");
+                                return null;
+                            }
+                        }
+                        cpr.launchingApp = proc;
+                        mLaunchingProviders.add(cpr);
+                    } finally {
+                        Binder.restoreCallingIdentity(origId);
+                    }
+                }
+
+                // Make sure the provider is published (the same provider class
+                // may be published under multiple names).
+                if (firstClass) {
+                    mProviderMap.putProviderByClass(comp, cpr);
+                }
+
+                mProviderMap.putProviderByName(name, cpr);
+                conn = incProviderCountLocked(r, cpr, token, stable);
+                if (conn != null) {
+                    conn.waiting = true;
+                }
+            }
+        }
+
+        // Wait for the provider to be published...
+        synchronized (cpr) {
+            while (cpr.provider == null) {
+                if (cpr.launchingApp == null) {
+                    Slog.w(TAG, "Unable to launch app "
+                            + cpi.applicationInfo.packageName + "/"
+                            + cpi.applicationInfo.uid + " for provider "
+                            + name + ": launching app became null");
+                    EventLog.writeEvent(EventLogTags.AM_PROVIDER_LOST_PROCESS,
+                            UserHandle.getUserId(cpi.applicationInfo.uid),
+                            cpi.applicationInfo.packageName,
+                            cpi.applicationInfo.uid, name);
+                    return null;
+                }
+                try {
+                    if (DEBUG_MU) {
+                        Slog.v(TAG_MU, "Waiting to start provider " + cpr + " launchingApp="
+                                + cpr.launchingApp);
+                    }
+                    if (conn != null) {
+                        conn.waiting = true;
+                    }
+                    cpr.wait();
+                } catch (InterruptedException ex) {
+                } finally {
+                    if (conn != null) {
+                        conn.waiting = false;
+                    }
+                }
+            }
+        }
+        return cpr != null ? cpr.newHolder(conn) : null;
+    }
+
+    public final ContentProviderHolder getContentProvider(
+            IApplicationThread caller, String name, int userId, boolean stable) {
+        enforceNotIsolatedCaller("getContentProvider");
+        if (caller == null) {
+            String msg = "null IApplicationThread when getting content provider "
+                    + name;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "getContentProvider", null);
+        return getContentProviderImpl(caller, name, null, stable, userId);
+    }
+
+    public ContentProviderHolder getContentProviderExternal(
+            String name, int userId, IBinder token) {
+        enforceCallingPermission(android.Manifest.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY,
+            "Do not have permission in call getContentProviderExternal()");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
+                false, true, "getContentProvider", null);
+        return getContentProviderExternalUnchecked(name, token, userId);
+    }
+
+    private ContentProviderHolder getContentProviderExternalUnchecked(String name,
+            IBinder token, int userId) {
+        return getContentProviderImpl(null, name, token, true, userId);
+    }
+
+    /**
+     * Drop a content provider from a ProcessRecord's bookkeeping
+     */
+    public void removeContentProvider(IBinder connection, boolean stable) {
+        enforceNotIsolatedCaller("removeContentProvider");
+        synchronized (this) {
+            ContentProviderConnection conn;
+            try {
+                conn = (ContentProviderConnection)connection;
+            } catch (ClassCastException e) {
+                String msg ="removeContentProvider: " + connection
+                        + " not a ContentProviderConnection";
+                Slog.w(TAG, msg);
+                throw new IllegalArgumentException(msg);
+            }
+            if (conn == null) {
+                throw new NullPointerException("connection is null");
+            }
+            if (decProviderCountLocked(conn, null, null, stable)) {
+                updateOomAdjLocked();
+            }
+        }
+    }
+
+    public void removeContentProviderExternal(String name, IBinder token) {
+        enforceCallingPermission(android.Manifest.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY,
+            "Do not have permission in call removeContentProviderExternal()");
+        removeContentProviderExternalUnchecked(name, token, UserHandle.getCallingUserId());
+    }
+
+    private void removeContentProviderExternalUnchecked(String name, IBinder token, int userId) {
+        synchronized (this) {
+            ContentProviderRecord cpr = mProviderMap.getProviderByName(name, userId);
+            if(cpr == null) {
+                //remove from mProvidersByClass
+                if(localLOGV) Slog.v(TAG, name+" content provider not found in providers list");
+                return;
+            }
+
+            //update content provider record entry info
+            ComponentName comp = new ComponentName(cpr.info.packageName, cpr.info.name);
+            ContentProviderRecord localCpr = mProviderMap.getProviderByClass(comp, userId);
+            if (localCpr.hasExternalProcessHandles()) {
+                if (localCpr.removeExternalProcessHandleLocked(token)) {
+                    updateOomAdjLocked();
+                } else {
+                    Slog.e(TAG, "Attmpt to remove content provider " + localCpr
+                            + " with no external reference for token: "
+                            + token + ".");
+                }
+            } else {
+                Slog.e(TAG, "Attmpt to remove content provider: " + localCpr
+                        + " with no external references.");
+            }
+        }
+    }
+    
+    public final void publishContentProviders(IApplicationThread caller,
+            List<ContentProviderHolder> providers) {
+        if (providers == null) {
+            return;
+        }
+
+        enforceNotIsolatedCaller("publishContentProviders");
+        synchronized (this) {
+            final ProcessRecord r = getRecordForAppLocked(caller);
+            if (DEBUG_MU)
+                Slog.v(TAG_MU, "ProcessRecord uid = " + r.uid);
+            if (r == null) {
+                throw new SecurityException(
+                        "Unable to find app for caller " + caller
+                      + " (pid=" + Binder.getCallingPid()
+                      + ") when publishing content providers");
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+
+            final int N = providers.size();
+            for (int i=0; i<N; i++) {
+                ContentProviderHolder src = providers.get(i);
+                if (src == null || src.info == null || src.provider == null) {
+                    continue;
+                }
+                ContentProviderRecord dst = r.pubProviders.get(src.info.name);
+                if (DEBUG_MU)
+                    Slog.v(TAG_MU, "ContentProviderRecord uid = " + dst.uid);
+                if (dst != null) {
+                    ComponentName comp = new ComponentName(dst.info.packageName, dst.info.name);
+                    mProviderMap.putProviderByClass(comp, dst);
+                    String names[] = dst.info.authority.split(";");
+                    for (int j = 0; j < names.length; j++) {
+                        mProviderMap.putProviderByName(names[j], dst);
+                    }
+
+                    int NL = mLaunchingProviders.size();
+                    int j;
+                    for (j=0; j<NL; j++) {
+                        if (mLaunchingProviders.get(j) == dst) {
+                            mLaunchingProviders.remove(j);
+                            j--;
+                            NL--;
+                        }
+                    }
+                    synchronized (dst) {
+                        dst.provider = src.provider;
+                        dst.proc = r;
+                        dst.notifyAll();
+                    }
+                    updateOomAdjLocked(r);
+                }
+            }
+
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    public boolean refContentProvider(IBinder connection, int stable, int unstable) {
+        ContentProviderConnection conn;
+        try {
+            conn = (ContentProviderConnection)connection;
+        } catch (ClassCastException e) {
+            String msg ="refContentProvider: " + connection
+                    + " not a ContentProviderConnection";
+            Slog.w(TAG, msg);
+            throw new IllegalArgumentException(msg);
+        }
+        if (conn == null) {
+            throw new NullPointerException("connection is null");
+        }
+
+        synchronized (this) {
+            if (stable > 0) {
+                conn.numStableIncs += stable;
+            }
+            stable = conn.stableCount + stable;
+            if (stable < 0) {
+                throw new IllegalStateException("stableCount < 0: " + stable);
+            }
+
+            if (unstable > 0) {
+                conn.numUnstableIncs += unstable;
+            }
+            unstable = conn.unstableCount + unstable;
+            if (unstable < 0) {
+                throw new IllegalStateException("unstableCount < 0: " + unstable);
+            }
+
+            if ((stable+unstable) <= 0) {
+                throw new IllegalStateException("ref counts can't go to zero here: stable="
+                        + stable + " unstable=" + unstable);
+            }
+            conn.stableCount = stable;
+            conn.unstableCount = unstable;
+            return !conn.dead;
+        }
+    }
+
+    public void unstableProviderDied(IBinder connection) {
+        ContentProviderConnection conn;
+        try {
+            conn = (ContentProviderConnection)connection;
+        } catch (ClassCastException e) {
+            String msg ="refContentProvider: " + connection
+                    + " not a ContentProviderConnection";
+            Slog.w(TAG, msg);
+            throw new IllegalArgumentException(msg);
+        }
+        if (conn == null) {
+            throw new NullPointerException("connection is null");
+        }
+
+        // Safely retrieve the content provider associated with the connection.
+        IContentProvider provider;
+        synchronized (this) {
+            provider = conn.provider.provider;
+        }
+
+        if (provider == null) {
+            // Um, yeah, we're way ahead of you.
+            return;
+        }
+
+        // Make sure the caller is being honest with us.
+        if (provider.asBinder().pingBinder()) {
+            // Er, no, still looks good to us.
+            synchronized (this) {
+                Slog.w(TAG, "unstableProviderDied: caller " + Binder.getCallingUid()
+                        + " says " + conn + " died, but we don't agree");
+                return;
+            }
+        }
+
+        // Well look at that!  It's dead!
+        synchronized (this) {
+            if (conn.provider.provider != provider) {
+                // But something changed...  good enough.
+                return;
+            }
+
+            ProcessRecord proc = conn.provider.proc;
+            if (proc == null || proc.thread == null) {
+                // Seems like the process is already cleaned up.
+                return;
+            }
+
+            // As far as we're concerned, this is just like receiving a
+            // death notification...  just a bit prematurely.
+            Slog.i(TAG, "Process " + proc.processName + " (pid " + proc.pid
+                    + ") early provider death");
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                appDiedLocked(proc, proc.pid, proc.thread);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    @Override
+    public void appNotRespondingViaProvider(IBinder connection) {
+        enforceCallingPermission(
+                android.Manifest.permission.REMOVE_TASKS, "appNotRespondingViaProvider()");
+
+        final ContentProviderConnection conn = (ContentProviderConnection) connection;
+        if (conn == null) {
+            Slog.w(TAG, "ContentProviderConnection is null");
+            return;
+        }
+
+        final ProcessRecord host = conn.provider.proc;
+        if (host == null) {
+            Slog.w(TAG, "Failed to find hosting ProcessRecord");
+            return;
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            appNotResponding(host, null, null, false, "ContentProvider not responding");
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    public final void installSystemProviders() {
+        List<ProviderInfo> providers;
+        synchronized (this) {
+            ProcessRecord app = mProcessNames.get("system", Process.SYSTEM_UID);
+            providers = generateApplicationProvidersLocked(app);
+            if (providers != null) {
+                for (int i=providers.size()-1; i>=0; i--) {
+                    ProviderInfo pi = (ProviderInfo)providers.get(i);
+                    if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+                        Slog.w(TAG, "Not installing system proc provider " + pi.name
+                                + ": not system .apk");
+                        providers.remove(i);
+                    }
+                }
+            }
+        }
+        if (providers != null) {
+            mSystemThread.installSystemProviders(providers);
+        }
+
+        mCoreSettingsObserver = new CoreSettingsObserver(this);
+
+        mUsageStatsService.monitorPackages();
+    }
+
+    /**
+     * Allows app to retrieve the MIME type of a URI without having permission
+     * to access its content provider.
+     *
+     * CTS tests for this functionality can be run with "runtest cts-appsecurity".
+     *
+     * Test cases are at cts/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/
+     *     src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
+     */
+    public String getProviderMimeType(Uri uri, int userId) {
+        enforceNotIsolatedCaller("getProviderMimeType");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
+                userId, false, true, "getProviderMimeType", null);
+        final String name = uri.getAuthority();
+        final long ident = Binder.clearCallingIdentity();
+        ContentProviderHolder holder = null;
+
+        try {
+            holder = getContentProviderExternalUnchecked(name, null, userId);
+            if (holder != null) {
+                return holder.provider.getType(uri);
+            }
+        } catch (RemoteException e) {
+            Log.w(TAG, "Content provider dead retrieving " + uri, e);
+            return null;
+        } finally {
+            if (holder != null) {
+                removeContentProviderExternalUnchecked(name, null, userId);
+            }
+            Binder.restoreCallingIdentity(ident);
+        }
+
+        return null;
+    }
+
+    // =========================================================
+    // GLOBAL MANAGEMENT
+    // =========================================================
+
+    final ProcessRecord newProcessRecordLocked(ApplicationInfo info, String customProcess,
+            boolean isolated) {
+        String proc = customProcess != null ? customProcess : info.processName;
+        BatteryStatsImpl.Uid.Proc ps = null;
+        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+        int uid = info.uid;
+        if (isolated) {
+            int userId = UserHandle.getUserId(uid);
+            int stepsLeft = Process.LAST_ISOLATED_UID - Process.FIRST_ISOLATED_UID + 1;
+            while (true) {
+                if (mNextIsolatedProcessUid < Process.FIRST_ISOLATED_UID
+                        || mNextIsolatedProcessUid > Process.LAST_ISOLATED_UID) {
+                    mNextIsolatedProcessUid = Process.FIRST_ISOLATED_UID;
+                }
+                uid = UserHandle.getUid(userId, mNextIsolatedProcessUid);
+                mNextIsolatedProcessUid++;
+                if (mIsolatedProcesses.indexOfKey(uid) < 0) {
+                    // No process for this uid, use it.
+                    break;
+                }
+                stepsLeft--;
+                if (stepsLeft <= 0) {
+                    return null;
+                }
+            }
+        }
+        return new ProcessRecord(stats, info, proc, uid);
+    }
+
+    final ProcessRecord addAppLocked(ApplicationInfo info, boolean isolated) {
+        ProcessRecord app;
+        if (!isolated) {
+            app = getProcessRecordLocked(info.processName, info.uid, true);
+        } else {
+            app = null;
+        }
+
+        if (app == null) {
+            app = newProcessRecordLocked(info, null, isolated);
+            mProcessNames.put(info.processName, app.uid, app);
+            if (isolated) {
+                mIsolatedProcesses.put(app.uid, app);
+            }
+            updateLruProcessLocked(app, false, null);
+            updateOomAdjLocked();
+        }
+
+        // This package really, really can not be stopped.
+        try {
+            AppGlobals.getPackageManager().setPackageStoppedState(
+                    info.packageName, false, UserHandle.getUserId(app.uid));
+        } catch (RemoteException e) {
+        } catch (IllegalArgumentException e) {
+            Slog.w(TAG, "Failed trying to unstop package "
+                    + info.packageName + ": " + e);
+        }
+
+        if ((info.flags&(ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT))
+                == (ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT)) {
+            app.persistent = true;
+            app.maxAdj = ProcessList.PERSISTENT_PROC_ADJ;
+        }
+        if (app.thread == null && mPersistentStartingProcesses.indexOf(app) < 0) {
+            mPersistentStartingProcesses.add(app);
+            startProcessLocked(app, "added application", app.processName);
+        }
+
+        return app;
+    }
+
+    public void unhandledBack() {
+        enforceCallingPermission(android.Manifest.permission.FORCE_BACK,
+                "unhandledBack()");
+
+        synchronized(this) {
+            final long origId = Binder.clearCallingIdentity();
+            try {
+                getFocusedStack().unhandledBackLocked();
+            } finally {
+                Binder.restoreCallingIdentity(origId);
+            }
+        }
+    }
+
+    public ParcelFileDescriptor openContentUri(Uri uri) throws RemoteException {
+        enforceNotIsolatedCaller("openContentUri");
+        final int userId = UserHandle.getCallingUserId();
+        String name = uri.getAuthority();
+        ContentProviderHolder cph = getContentProviderExternalUnchecked(name, null, userId);
+        ParcelFileDescriptor pfd = null;
+        if (cph != null) {
+            // We record the binder invoker's uid in thread-local storage before
+            // going to the content provider to open the file.  Later, in the code
+            // that handles all permissions checks, we look for this uid and use
+            // that rather than the Activity Manager's own uid.  The effect is that
+            // we do the check against the caller's permissions even though it looks
+            // to the content provider like the Activity Manager itself is making
+            // the request.
+            sCallerIdentity.set(new Identity(
+                    Binder.getCallingPid(), Binder.getCallingUid()));
+            try {
+                pfd = cph.provider.openFile(null, uri, "r", null);
+            } catch (FileNotFoundException e) {
+                // do nothing; pfd will be returned null
+            } finally {
+                // Ensure that whatever happens, we clean up the identity state
+                sCallerIdentity.remove();
+            }
+
+            // We've got the fd now, so we're done with the provider.
+            removeContentProviderExternalUnchecked(name, null, userId);
+        } else {
+            Slog.d(TAG, "Failed to get provider for authority '" + name + "'");
+        }
+        return pfd;
+    }
+
+    // Actually is sleeping or shutting down or whatever else in the future
+    // is an inactive state.
+    public boolean isSleepingOrShuttingDown() {
+        return mSleeping || mShuttingDown;
+    }
+
+    public void goingToSleep() {
+        if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.DEVICE_POWER);
+        }
+
+        synchronized(this) {
+            mWentToSleep = true;
+            updateEventDispatchingLocked();
+
+            if (!mSleeping) {
+                mSleeping = true;
+                mStackSupervisor.goingToSleepLocked();
+
+                // Initialize the wake times of all processes.
+                checkExcessivePowerUsageLocked(false);
+                mHandler.removeMessages(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
+                Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
+                mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
+            }
+        }
+    }
+
+    @Override
+    public boolean shutdown(int timeout) {
+        if (checkCallingPermission(android.Manifest.permission.SHUTDOWN)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.SHUTDOWN);
+        }
+
+        boolean timedout = false;
+
+        synchronized(this) {
+            mShuttingDown = true;
+            updateEventDispatchingLocked();
+            timedout = mStackSupervisor.shutdownLocked(timeout);
+        }
+
+        mAppOpsService.shutdown();
+        mUsageStatsService.shutdown();
+        mBatteryStatsService.shutdown();
+        synchronized (this) {
+            mProcessStats.shutdownLocked();
+        }
+
+        return timedout;
+    }
+    
+    public final void activitySlept(IBinder token) {
+        if (localLOGV) Slog.v(TAG, "Activity slept: token=" + token);
+
+        final long origId = Binder.clearCallingIdentity();
+
+        synchronized (this) {
+            final ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r != null) {
+                mStackSupervisor.activitySleptLocked(r);
+            }
+        }
+
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    void logLockScreen(String msg) {
+        if (DEBUG_LOCKSCREEN) Slog.d(TAG, Debug.getCallers(2) + ":" + msg +
+                " mLockScreenShown=" + mLockScreenShown + " mWentToSleep=" +
+                mWentToSleep + " mSleeping=" + mSleeping + " mDismissKeyguardOnNextActivity=" +
+                mStackSupervisor.mDismissKeyguardOnNextActivity);
+    }
+
+    private void comeOutOfSleepIfNeededLocked() {
+        if (!mWentToSleep && !mLockScreenShown) {
+            if (mSleeping) {
+                mSleeping = false;
+                mStackSupervisor.comeOutOfSleepIfNeededLocked();
+            }
+        }
+    }
+
+    public void wakingUp() {
+        if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.DEVICE_POWER);
+        }
+
+        synchronized(this) {
+            mWentToSleep = false;
+            updateEventDispatchingLocked();
+            comeOutOfSleepIfNeededLocked();
+        }
+    }
+
+    private void updateEventDispatchingLocked() {
+        mWindowManager.setEventDispatching(mBooted && !mWentToSleep && !mShuttingDown);
+    }
+
+    public void setLockScreenShown(boolean shown) {
+        if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.DEVICE_POWER);
+        }
+
+        synchronized(this) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                if (DEBUG_LOCKSCREEN) logLockScreen(" shown=" + shown);
+                mLockScreenShown = shown;
+                comeOutOfSleepIfNeededLocked();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void stopAppSwitches() {
+        if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.STOP_APP_SWITCHES);
+        }
+        
+        synchronized(this) {
+            mAppSwitchesAllowedTime = SystemClock.uptimeMillis()
+                    + APP_SWITCH_DELAY_TIME;
+            mDidAppSwitch = false;
+            mHandler.removeMessages(DO_PENDING_ACTIVITY_LAUNCHES_MSG);
+            Message msg = mHandler.obtainMessage(DO_PENDING_ACTIVITY_LAUNCHES_MSG);
+            mHandler.sendMessageDelayed(msg, APP_SWITCH_DELAY_TIME);
+        }
+    }
+    
+    public void resumeAppSwitches() {
+        if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.STOP_APP_SWITCHES);
+        }
+        
+        synchronized(this) {
+            // Note that we don't execute any pending app switches... we will
+            // let those wait until either the timeout, or the next start
+            // activity request.
+            mAppSwitchesAllowedTime = 0;
+        }
+    }
+    
+    boolean checkAppSwitchAllowedLocked(int callingPid, int callingUid,
+            String name) {
+        if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) {
+            return true;
+        }
+            
+        final int perm = checkComponentPermission(
+                android.Manifest.permission.STOP_APP_SWITCHES, callingPid,
+                callingUid, -1, true);
+        if (perm == PackageManager.PERMISSION_GRANTED) {
+            return true;
+        }
+        
+        Slog.w(TAG, name + " request from " + callingUid + " stopped");
+        return false;
+    }
+    
+    public void setDebugApp(String packageName, boolean waitForDebugger,
+            boolean persistent) {
+        enforceCallingPermission(android.Manifest.permission.SET_DEBUG_APP,
+                "setDebugApp()");
+
+        long ident = Binder.clearCallingIdentity();
+        try {
+            // Note that this is not really thread safe if there are multiple
+            // callers into it at the same time, but that's not a situation we
+            // care about.
+            if (persistent) {
+                final ContentResolver resolver = mContext.getContentResolver();
+                Settings.Global.putString(
+                    resolver, Settings.Global.DEBUG_APP,
+                    packageName);
+                Settings.Global.putInt(
+                    resolver, Settings.Global.WAIT_FOR_DEBUGGER,
+                    waitForDebugger ? 1 : 0);
+            }
+
+            synchronized (this) {
+                if (!persistent) {
+                    mOrigDebugApp = mDebugApp;
+                    mOrigWaitForDebugger = mWaitForDebugger;
+                }
+                mDebugApp = packageName;
+                mWaitForDebugger = waitForDebugger;
+                mDebugTransient = !persistent;
+                if (packageName != null) {
+                    forceStopPackageLocked(packageName, -1, false, false, true, true,
+                            UserHandle.USER_ALL, "set debug app");
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    void setOpenGlTraceApp(ApplicationInfo app, String processName) {
+        synchronized (this) {
+            boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+            if (!isDebuggable) {
+                if ((app.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
+                    throw new SecurityException("Process not debuggable: " + app.packageName);
+                }
+            }
+
+            mOpenGlTraceApp = processName;
+        }
+    }
+
+    void setProfileApp(ApplicationInfo app, String processName, String profileFile,
+            ParcelFileDescriptor profileFd, boolean autoStopProfiler) {
+        synchronized (this) {
+            boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+            if (!isDebuggable) {
+                if ((app.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
+                    throw new SecurityException("Process not debuggable: " + app.packageName);
+                }
+            }
+            mProfileApp = processName;
+            mProfileFile = profileFile;
+            if (mProfileFd != null) {
+                try {
+                    mProfileFd.close();
+                } catch (IOException e) {
+                }
+                mProfileFd = null;
+            }
+            mProfileFd = profileFd;
+            mProfileType = 0;
+            mAutoStopProfiler = autoStopProfiler;
+        }
+    }
+
+    @Override
+    public void setAlwaysFinish(boolean enabled) {
+        enforceCallingPermission(android.Manifest.permission.SET_ALWAYS_FINISH,
+                "setAlwaysFinish()");
+
+        Settings.Global.putInt(
+                mContext.getContentResolver(),
+                Settings.Global.ALWAYS_FINISH_ACTIVITIES, enabled ? 1 : 0);
+        
+        synchronized (this) {
+            mAlwaysFinishActivities = enabled;
+        }
+    }
+
+    @Override
+    public void setActivityController(IActivityController controller) {
+        enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
+                "setActivityController()");
+        synchronized (this) {
+            mController = controller;
+            Watchdog.getInstance().setActivityController(controller);
+        }
+    }
+
+    @Override
+    public void setUserIsMonkey(boolean userIsMonkey) {
+        synchronized (this) {
+            synchronized (mPidsSelfLocked) {
+                final int callingPid = Binder.getCallingPid();
+                ProcessRecord precessRecord = mPidsSelfLocked.get(callingPid);
+                if (precessRecord == null) {
+                    throw new SecurityException("Unknown process: " + callingPid);
+                }
+                if (precessRecord.instrumentationUiAutomationConnection  == null) {
+                    throw new SecurityException("Only an instrumentation process "
+                            + "with a UiAutomation can call setUserIsMonkey");
+                }
+            }
+            mUserIsMonkey = userIsMonkey;
+        }
+    }
+
+    @Override
+    public boolean isUserAMonkey() {
+        synchronized (this) {
+            // If there is a controller also implies the user is a monkey.
+            return (mUserIsMonkey || mController != null);
+        }
+    }
+
+    public void requestBugReport() {
+        enforceCallingPermission(android.Manifest.permission.DUMP, "requestBugReport");
+        SystemProperties.set("ctl.start", "bugreport");
+    }
+
+    public static long getInputDispatchingTimeoutLocked(ActivityRecord r) {
+        return r != null ? getInputDispatchingTimeoutLocked(r.app) : KEY_DISPATCHING_TIMEOUT;
+    }
+
+    public static long getInputDispatchingTimeoutLocked(ProcessRecord r) {
+        if (r != null && (r.instrumentationClass != null || r.usingWrapper)) {
+            return INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
+        }
+        return KEY_DISPATCHING_TIMEOUT;
+    }
+
+    @Override
+    public long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {
+        if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.FILTER_EVENTS);
+        }
+        ProcessRecord proc;
+        long timeout;
+        synchronized (this) {
+            synchronized (mPidsSelfLocked) {
+                proc = mPidsSelfLocked.get(pid);
+            }
+            timeout = getInputDispatchingTimeoutLocked(proc);
+        }
+
+        if (!inputDispatchingTimedOut(proc, null, null, aboveSystem, reason)) {
+            return -1;
+        }
+
+        return timeout;
+    }
+
+    /**
+     * Handle input dispatching timeouts.
+     * Returns whether input dispatching should be aborted or not.
+     */
+    public boolean inputDispatchingTimedOut(final ProcessRecord proc,
+            final ActivityRecord activity, final ActivityRecord parent,
+            final boolean aboveSystem, String reason) {
+        if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.FILTER_EVENTS);
+        }
+
+        final String annotation;
+        if (reason == null) {
+            annotation = "Input dispatching timed out";
+        } else {
+            annotation = "Input dispatching timed out (" + reason + ")";
+        }
+
+        if (proc != null) {
+            synchronized (this) {
+                if (proc.debugging) {
+                    return false;
+                }
+
+                if (mDidDexOpt) {
+                    // Give more time since we were dexopting.
+                    mDidDexOpt = false;
+                    return false;
+                }
+
+                if (proc.instrumentationClass != null) {
+                    Bundle info = new Bundle();
+                    info.putString("shortMsg", "keyDispatchingTimedOut");
+                    info.putString("longMsg", annotation);
+                    finishInstrumentationLocked(proc, Activity.RESULT_CANCELED, info);
+                    return true;
+                }
+            }
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    appNotResponding(proc, activity, parent, aboveSystem, annotation);
+                }
+            });
+        }
+
+        return true;
+    }
+
+    public Bundle getAssistContextExtras(int requestType) {
+        enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO,
+                "getAssistContextExtras()");
+        PendingAssistExtras pae;
+        Bundle extras = new Bundle();
+        synchronized (this) {
+            ActivityRecord activity = getFocusedStack().mResumedActivity;
+            if (activity == null) {
+                Slog.w(TAG, "getAssistContextExtras failed: no resumed activity");
+                return null;
+            }
+            extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName);
+            if (activity.app == null || activity.app.thread == null) {
+                Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity);
+                return extras;
+            }
+            if (activity.app.pid == Binder.getCallingPid()) {
+                Slog.w(TAG, "getAssistContextExtras failed: request process same as " + activity);
+                return extras;
+            }
+            pae = new PendingAssistExtras(activity);
+            try {
+                activity.app.thread.requestAssistContextExtras(activity.appToken, pae,
+                        requestType);
+                mPendingAssistExtras.add(pae);
+                mHandler.postDelayed(pae, PENDING_ASSIST_EXTRAS_TIMEOUT);
+            } catch (RemoteException e) {
+                Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity);
+                return extras;
+            }
+        }
+        synchronized (pae) {
+            while (!pae.haveResult) {
+                try {
+                    pae.wait();
+                } catch (InterruptedException e) {
+                }
+            }
+            if (pae.result != null) {
+                extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, pae.result);
+            }
+        }
+        synchronized (this) {
+            mPendingAssistExtras.remove(pae);
+            mHandler.removeCallbacks(pae);
+        }
+        return extras;
+    }
+
+    public void reportAssistContextExtras(IBinder token, Bundle extras) {
+        PendingAssistExtras pae = (PendingAssistExtras)token;
+        synchronized (pae) {
+            pae.result = extras;
+            pae.haveResult = true;
+            pae.notifyAll();
+        }
+    }
+
+    public void registerProcessObserver(IProcessObserver observer) {
+        enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
+                "registerProcessObserver()");
+        synchronized (this) {
+            mProcessObservers.register(observer);
+        }
+    }
+
+    @Override
+    public void unregisterProcessObserver(IProcessObserver observer) {
+        synchronized (this) {
+            mProcessObservers.unregister(observer);
+        }
+    }
+
+    @Override
+    public boolean convertFromTranslucent(IBinder token) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                final ActivityRecord r = ActivityRecord.isInStackLocked(token);
+                if (r == null) {
+                    return false;
+                }
+                if (r.changeWindowTranslucency(true)) {
+                    mWindowManager.setAppFullscreen(token, true);
+                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
+                    return true;
+                }
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public boolean convertToTranslucent(IBinder token) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                final ActivityRecord r = ActivityRecord.isInStackLocked(token);
+                if (r == null) {
+                    return false;
+                }
+                if (r.changeWindowTranslucency(false)) {
+                    r.task.stack.convertToTranslucent(r);
+                    mWindowManager.setAppFullscreen(token, false);
+                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
+                    return true;
+                }
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public void setImmersive(IBinder token, boolean immersive) {
+        synchronized(this) {
+            final ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                throw new IllegalArgumentException();
+            }
+            r.immersive = immersive;
+
+            // update associated state if we're frontmost
+            if (r == mFocusedActivity) {
+                if (DEBUG_IMMERSIVE) {
+                    Slog.d(TAG, "Frontmost changed immersion: "+ r);
+                }
+                applyUpdateLockStateLocked(r);
+            }
+        }
+    }
+
+    @Override
+    public boolean isImmersive(IBinder token) {
+        synchronized (this) {
+            ActivityRecord r = ActivityRecord.isInStackLocked(token);
+            if (r == null) {
+                throw new IllegalArgumentException();
+            }
+            return r.immersive;
+        }
+    }
+
+    public boolean isTopActivityImmersive() {
+        enforceNotIsolatedCaller("startActivity");
+        synchronized (this) {
+            ActivityRecord r = getFocusedStack().topRunningActivityLocked(null);
+            return (r != null) ? r.immersive : false;
+        }
+    }
+
+    public final void enterSafeMode() {
+        synchronized(this) {
+            // It only makes sense to do this before the system is ready
+            // and started launching other packages.
+            if (!mSystemReady) {
+                try {
+                    AppGlobals.getPackageManager().enterSafeMode();
+                } catch (RemoteException e) {
+                }
+            }
+        }
+    }
+
+    public final void showSafeModeOverlay() {
+        View v = LayoutInflater.from(mContext).inflate(
+                com.android.internal.R.layout.safe_mode, null);
+        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
+        lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
+        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
+        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
+        lp.gravity = Gravity.BOTTOM | Gravity.START;
+        lp.format = v.getBackground().getOpacity();
+        lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
+                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
+        lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
+        ((WindowManager)mContext.getSystemService(
+                Context.WINDOW_SERVICE)).addView(v, lp);
+    }
+
+    public void noteWakeupAlarm(IIntentSender sender) {
+        if (!(sender instanceof PendingIntentRecord)) {
+            return;
+        }
+        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+        synchronized (stats) {
+            if (mBatteryStatsService.isOnBattery()) {
+                mBatteryStatsService.enforceCallingPermission();
+                PendingIntentRecord rec = (PendingIntentRecord)sender;
+                int MY_UID = Binder.getCallingUid();
+                int uid = rec.uid == MY_UID ? Process.SYSTEM_UID : rec.uid;
+                BatteryStatsImpl.Uid.Pkg pkg =
+                    stats.getPackageStatsLocked(uid, rec.key.packageName);
+                pkg.incWakeupsLocked();
+            }
+        }
+    }
+
+    public boolean killPids(int[] pids, String pReason, boolean secure) {
+        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+            throw new SecurityException("killPids only available to the system");
+        }
+        String reason = (pReason == null) ? "Unknown" : pReason;
+        // XXX Note: don't acquire main activity lock here, because the window
+        // manager calls in with its locks held.
+
+        boolean killed = false;
+        synchronized (mPidsSelfLocked) {
+            int[] types = new int[pids.length];
+            int worstType = 0;
+            for (int i=0; i<pids.length; i++) {
+                ProcessRecord proc = mPidsSelfLocked.get(pids[i]);
+                if (proc != null) {
+                    int type = proc.setAdj;
+                    types[i] = type;
+                    if (type > worstType) {
+                        worstType = type;
+                    }
+                }
+            }
+
+            // If the worst oom_adj is somewhere in the cached proc LRU range,
+            // then constrain it so we will kill all cached procs.
+            if (worstType < ProcessList.CACHED_APP_MAX_ADJ
+                    && worstType > ProcessList.CACHED_APP_MIN_ADJ) {
+                worstType = ProcessList.CACHED_APP_MIN_ADJ;
+            }
+
+            // If this is not a secure call, don't let it kill processes that
+            // are important.
+            if (!secure && worstType < ProcessList.SERVICE_ADJ) {
+                worstType = ProcessList.SERVICE_ADJ;
+            }
+
+            Slog.w(TAG, "Killing processes " + reason + " at adjustment " + worstType);
+            for (int i=0; i<pids.length; i++) {
+                ProcessRecord proc = mPidsSelfLocked.get(pids[i]);
+                if (proc == null) {
+                    continue;
+                }
+                int adj = proc.setAdj;
+                if (adj >= worstType && !proc.killedByAm) {
+                    killUnneededProcessLocked(proc, reason);
+                    killed = true;
+                }
+            }
+        }
+        return killed;
+    }
+
+    @Override
+    public void killUid(int uid, String reason) {
+        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+            throw new SecurityException("killUid only available to the system");
+        }
+        synchronized (this) {
+            killPackageProcessesLocked(null, UserHandle.getAppId(uid), UserHandle.getUserId(uid),
+                    ProcessList.FOREGROUND_APP_ADJ-1, false, true, true, false,
+                    reason != null ? reason : "kill uid");
+        }
+    }
+
+    @Override
+    public boolean killProcessesBelowForeground(String reason) {
+        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+            throw new SecurityException("killProcessesBelowForeground() only available to system");
+        }
+
+        return killProcessesBelowAdj(ProcessList.FOREGROUND_APP_ADJ, reason);
+    }
+
+    private boolean killProcessesBelowAdj(int belowAdj, String reason) {
+        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+            throw new SecurityException("killProcessesBelowAdj() only available to system");
+        }
+
+        boolean killed = false;
+        synchronized (mPidsSelfLocked) {
+            final int size = mPidsSelfLocked.size();
+            for (int i = 0; i < size; i++) {
+                final int pid = mPidsSelfLocked.keyAt(i);
+                final ProcessRecord proc = mPidsSelfLocked.valueAt(i);
+                if (proc == null) continue;
+
+                final int adj = proc.setAdj;
+                if (adj > belowAdj && !proc.killedByAm) {
+                    killUnneededProcessLocked(proc, reason);
+                    killed = true;
+                }
+            }
+        }
+        return killed;
+    }
+
+    @Override
+    public void hang(final IBinder who, boolean allowRestart) {
+        if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.SET_ACTIVITY_WATCHER);
+        }
+
+        final IBinder.DeathRecipient death = new DeathRecipient() {
+            @Override
+            public void binderDied() {
+                synchronized (this) {
+                    notifyAll();
+                }
+            }
+        };
+
+        try {
+            who.linkToDeath(death, 0);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "hang: given caller IBinder is already dead.");
+            return;
+        }
+
+        synchronized (this) {
+            Watchdog.getInstance().setAllowRestart(allowRestart);
+            Slog.i(TAG, "Hanging system process at request of pid " + Binder.getCallingPid());
+            synchronized (death) {
+                while (who.isBinderAlive()) {
+                    try {
+                        death.wait();
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+            Watchdog.getInstance().setAllowRestart(true);
+        }
+    }
+
+    @Override
+    public void restart() {
+        if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.SET_ACTIVITY_WATCHER);
+        }
+
+        Log.i(TAG, "Sending shutdown broadcast...");
+
+        BroadcastReceiver br = new BroadcastReceiver() {
+            @Override public void onReceive(Context context, Intent intent) {
+                // Now the broadcast is done, finish up the low-level shutdown.
+                Log.i(TAG, "Shutting down activity manager...");
+                shutdown(10000);
+                Log.i(TAG, "Shutdown complete, restarting!");
+                Process.killProcess(Process.myPid());
+                System.exit(10);
+            }
+        };
+
+        // First send the high-level shut down broadcast.
+        Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
+        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+        intent.putExtra(Intent.EXTRA_SHUTDOWN_USERSPACE_ONLY, true);
+        /* For now we are not doing a clean shutdown, because things seem to get unhappy.
+        mContext.sendOrderedBroadcastAsUser(intent,
+                UserHandle.ALL, null, br, mHandler, 0, null, null);
+        */
+        br.onReceive(mContext, intent);
+    }
+
+    private long getLowRamTimeSinceIdle(long now) {
+        return mLowRamTimeSinceLastIdle + (mLowRamStartTime > 0 ? (now-mLowRamStartTime) : 0);
+    }
+
+    @Override
+    public void performIdleMaintenance() {
+        if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires permission "
+                    + android.Manifest.permission.SET_ACTIVITY_WATCHER);
+        }
+
+        synchronized (this) {
+            final long now = SystemClock.uptimeMillis();
+            final long timeSinceLastIdle = now - mLastIdleTime;
+            final long lowRamSinceLastIdle = getLowRamTimeSinceIdle(now);
+            mLastIdleTime = now;
+            mLowRamTimeSinceLastIdle = 0;
+            if (mLowRamStartTime != 0) {
+                mLowRamStartTime = now;
+            }
+
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("Idle maintenance over ");
+            TimeUtils.formatDuration(timeSinceLastIdle, sb);
+            sb.append(" low RAM for ");
+            TimeUtils.formatDuration(lowRamSinceLastIdle, sb);
+            Slog.i(TAG, sb.toString());
+
+            // If at least 1/3 of our time since the last idle period has been spent
+            // with RAM low, then we want to kill processes.
+            boolean doKilling = lowRamSinceLastIdle > (timeSinceLastIdle/3);
+
+            for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
+                ProcessRecord proc = mLruProcesses.get(i);
+                if (proc.notCachedSinceIdle) {
+                    if (proc.setProcState > ActivityManager.PROCESS_STATE_TOP
+                            && proc.setProcState <= ActivityManager.PROCESS_STATE_SERVICE) {
+                        if (doKilling && proc.initialIdlePss != 0
+                                && proc.lastPss > ((proc.initialIdlePss*3)/2)) {
+                            killUnneededProcessLocked(proc, "idle maint (pss " + proc.lastPss
+                                    + " from " + proc.initialIdlePss + ")");
+                        }
+                    }
+                } else if (proc.setProcState < ActivityManager.PROCESS_STATE_HOME) {
+                    proc.notCachedSinceIdle = true;
+                    proc.initialIdlePss = 0;
+                    proc.nextPssTime = ProcessList.computeNextPssTime(proc.curProcState, true,
+                            mSleeping, now);
+                }
+            }
+
+            mHandler.removeMessages(REQUEST_ALL_PSS_MSG);
+            mHandler.sendEmptyMessageDelayed(REQUEST_ALL_PSS_MSG, 2*60*1000);
+        }
+    }
+
+    public final void startRunning(String pkg, String cls, String action,
+            String data) {
+        synchronized(this) {
+            if (mStartRunning) {
+                return;
+            }
+            mStartRunning = true;
+            mTopComponent = pkg != null && cls != null
+                    ? new ComponentName(pkg, cls) : null;
+            mTopAction = action != null ? action : Intent.ACTION_MAIN;
+            mTopData = data;
+            if (!mSystemReady) {
+                return;
+            }
+        }
+
+        systemReady(null);
+    }
+
+    private void retrieveSettings() {
+        final ContentResolver resolver = mContext.getContentResolver();
+        String debugApp = Settings.Global.getString(
+            resolver, Settings.Global.DEBUG_APP);
+        boolean waitForDebugger = Settings.Global.getInt(
+            resolver, Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0;
+        boolean alwaysFinishActivities = Settings.Global.getInt(
+            resolver, Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0;
+        boolean forceRtl = Settings.Global.getInt(
+                resolver, Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0;
+        // Transfer any global setting for forcing RTL layout, into a System Property
+        SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0");
+
+        Configuration configuration = new Configuration();
+        Settings.System.getConfiguration(resolver, configuration);
+        if (forceRtl) {
+            // This will take care of setting the correct layout direction flags
+            configuration.setLayoutDirection(configuration.locale);
+        }
+
+        synchronized (this) {
+            mDebugApp = mOrigDebugApp = debugApp;
+            mWaitForDebugger = mOrigWaitForDebugger = waitForDebugger;
+            mAlwaysFinishActivities = alwaysFinishActivities;
+            // This happens before any activities are started, so we can
+            // change mConfiguration in-place.
+            updateConfigurationLocked(configuration, null, false, true);
+            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Initial config: " + mConfiguration);
+        }
+    }
+
+    public boolean testIsSystemReady() {
+        // no need to synchronize(this) just to read & return the value
+        return mSystemReady;
+    }
+
+    private static File getCalledPreBootReceiversFile() {
+        File dataDir = Environment.getDataDirectory();
+        File systemDir = new File(dataDir, "system");
+        File fname = new File(systemDir, "called_pre_boots.dat");
+        return fname;
+    }
+
+    static final int LAST_DONE_VERSION = 10000;
+
+    private static ArrayList<ComponentName> readLastDonePreBootReceivers() {
+        ArrayList<ComponentName> lastDoneReceivers = new ArrayList<ComponentName>();
+        File file = getCalledPreBootReceiversFile();
+        FileInputStream fis = null;
+        try {
+            fis = new FileInputStream(file);
+            DataInputStream dis = new DataInputStream(new BufferedInputStream(fis, 2048));
+            int fvers = dis.readInt();
+            if (fvers == LAST_DONE_VERSION) {
+                String vers = dis.readUTF();
+                String codename = dis.readUTF();
+                String build = dis.readUTF();
+                if (android.os.Build.VERSION.RELEASE.equals(vers)
+                        && android.os.Build.VERSION.CODENAME.equals(codename)
+                        && android.os.Build.VERSION.INCREMENTAL.equals(build)) {
+                    int num = dis.readInt();
+                    while (num > 0) {
+                        num--;
+                        String pkg = dis.readUTF();
+                        String cls = dis.readUTF();
+                        lastDoneReceivers.add(new ComponentName(pkg, cls));
+                    }
+                }
+            }
+        } catch (FileNotFoundException e) {
+        } catch (IOException e) {
+            Slog.w(TAG, "Failure reading last done pre-boot receivers", e);
+        } finally {
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+        return lastDoneReceivers;
+    }
+    
+    private static void writeLastDonePreBootReceivers(ArrayList<ComponentName> list) {
+        File file = getCalledPreBootReceiversFile();
+        FileOutputStream fos = null;
+        DataOutputStream dos = null;
+        try {
+            Slog.i(TAG, "Writing new set of last done pre-boot receivers...");
+            fos = new FileOutputStream(file);
+            dos = new DataOutputStream(new BufferedOutputStream(fos, 2048));
+            dos.writeInt(LAST_DONE_VERSION);
+            dos.writeUTF(android.os.Build.VERSION.RELEASE);
+            dos.writeUTF(android.os.Build.VERSION.CODENAME);
+            dos.writeUTF(android.os.Build.VERSION.INCREMENTAL);
+            dos.writeInt(list.size());
+            for (int i=0; i<list.size(); i++) {
+                dos.writeUTF(list.get(i).getPackageName());
+                dos.writeUTF(list.get(i).getClassName());
+            }
+        } catch (IOException e) {
+            Slog.w(TAG, "Failure writing last done pre-boot receivers", e);
+            file.delete();
+        } finally {
+            FileUtils.sync(fos);
+            if (dos != null) {
+                try {
+                    dos.close();
+                } catch (IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+    
+    public void systemReady(final Runnable goingCallback) {
+        synchronized(this) {
+            if (mSystemReady) {
+                if (goingCallback != null) goingCallback.run();
+                return;
+            }
+            
+            // Check to see if there are any update receivers to run.
+            if (!mDidUpdate) {
+                if (mWaitingUpdate) {
+                    return;
+                }
+                Intent intent = new Intent(Intent.ACTION_PRE_BOOT_COMPLETED);
+                List<ResolveInfo> ris = null;
+                try {
+                    ris = AppGlobals.getPackageManager().queryIntentReceivers(
+                            intent, null, 0, 0);
+                } catch (RemoteException e) {
+                }
+                if (ris != null) {
+                    for (int i=ris.size()-1; i>=0; i--) {
+                        if ((ris.get(i).activityInfo.applicationInfo.flags
+                                &ApplicationInfo.FLAG_SYSTEM) == 0) {
+                            ris.remove(i);
+                        }
+                    }
+                    intent.addFlags(Intent.FLAG_RECEIVER_BOOT_UPGRADE);
+
+                    ArrayList<ComponentName> lastDoneReceivers = readLastDonePreBootReceivers();
+
+                    final ArrayList<ComponentName> doneReceivers = new ArrayList<ComponentName>();
+                    for (int i=0; i<ris.size(); i++) {
+                        ActivityInfo ai = ris.get(i).activityInfo;
+                        ComponentName comp = new ComponentName(ai.packageName, ai.name);
+                        if (lastDoneReceivers.contains(comp)) {
+                            // We already did the pre boot receiver for this app with the current
+                            // platform version, so don't do it again...
+                            ris.remove(i);
+                            i--;
+                            // ...however, do keep it as one that has been done, so we don't
+                            // forget about it when rewriting the file of last done receivers.
+                            doneReceivers.add(comp);
+                        }
+                    }
+
+                    final int[] users = getUsersLocked();
+                    for (int i=0; i<ris.size(); i++) {
+                        ActivityInfo ai = ris.get(i).activityInfo;
+                        ComponentName comp = new ComponentName(ai.packageName, ai.name);
+                        doneReceivers.add(comp);
+                        intent.setComponent(comp);
+                        for (int j=0; j<users.length; j++) {
+                            IIntentReceiver finisher = null;
+                            if (i == ris.size()-1 && j == users.length-1) {
+                                finisher = new IIntentReceiver.Stub() {
+                                    public void performReceive(Intent intent, int resultCode,
+                                            String data, Bundle extras, boolean ordered,
+                                            boolean sticky, int sendingUser) {
+                                        // The raw IIntentReceiver interface is called
+                                        // with the AM lock held, so redispatch to
+                                        // execute our code without the lock.
+                                        mHandler.post(new Runnable() {
+                                            public void run() {
+                                                synchronized (ActivityManagerService.this) {
+                                                    mDidUpdate = true;
+                                                }
+                                                writeLastDonePreBootReceivers(doneReceivers);
+                                                showBootMessage(mContext.getText(
+                                                        R.string.android_upgrading_complete),
+                                                        false);
+                                                systemReady(goingCallback);
+                                            }
+                                        });
+                                    }
+                                };
+                            }
+                            Slog.i(TAG, "Sending system update to " + intent.getComponent()
+                                    + " for user " + users[j]);
+                            broadcastIntentLocked(null, null, intent, null, finisher,
+                                    0, null, null, null, AppOpsManager.OP_NONE,
+                                    true, false, MY_PID, Process.SYSTEM_UID,
+                                    users[j]);
+                            if (finisher != null) {
+                                mWaitingUpdate = true;
+                            }
+                        }
+                    }
+                }
+                if (mWaitingUpdate) {
+                    return;
+                }
+                mDidUpdate = true;
+            }
+
+            mAppOpsService.systemReady();
+            mSystemReady = true;
+            if (!mStartRunning) {
+                return;
+            }
+        }
+
+        ArrayList<ProcessRecord> procsToKill = null;
+        synchronized(mPidsSelfLocked) {
+            for (int i=mPidsSelfLocked.size()-1; i>=0; i--) {
+                ProcessRecord proc = mPidsSelfLocked.valueAt(i);
+                if (!isAllowedWhileBooting(proc.info)){
+                    if (procsToKill == null) {
+                        procsToKill = new ArrayList<ProcessRecord>();
+                    }
+                    procsToKill.add(proc);
+                }
+            }
+        }
+        
+        synchronized(this) {
+            if (procsToKill != null) {
+                for (int i=procsToKill.size()-1; i>=0; i--) {
+                    ProcessRecord proc = procsToKill.get(i);
+                    Slog.i(TAG, "Removing system update proc: " + proc);
+                    removeProcessLocked(proc, true, false, "system update done");
+                }
+            }
+            
+            // Now that we have cleaned up any update processes, we
+            // are ready to start launching real processes and know that
+            // we won't trample on them any more.
+            mProcessesReady = true;
+        }
+        
+        Slog.i(TAG, "System now ready");
+        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_AMS_READY,
+            SystemClock.uptimeMillis());
+
+        synchronized(this) {
+            // Make sure we have no pre-ready processes sitting around.
+            
+            if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
+                ResolveInfo ri = mContext.getPackageManager()
+                        .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST),
+                                STOCK_PM_FLAGS);
+                CharSequence errorMsg = null;
+                if (ri != null) {
+                    ActivityInfo ai = ri.activityInfo;
+                    ApplicationInfo app = ai.applicationInfo;
+                    if ((app.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
+                        mTopAction = Intent.ACTION_FACTORY_TEST;
+                        mTopData = null;
+                        mTopComponent = new ComponentName(app.packageName,
+                                ai.name);
+                    } else {
+                        errorMsg = mContext.getResources().getText(
+                                com.android.internal.R.string.factorytest_not_system);
+                    }
+                } else {
+                    errorMsg = mContext.getResources().getText(
+                            com.android.internal.R.string.factorytest_no_action);
+                }
+                if (errorMsg != null) {
+                    mTopAction = null;
+                    mTopData = null;
+                    mTopComponent = null;
+                    Message msg = Message.obtain();
+                    msg.what = SHOW_FACTORY_ERROR_MSG;
+                    msg.getData().putCharSequence("msg", errorMsg);
+                    mHandler.sendMessage(msg);
+                }
+            }
+        }
+
+        retrieveSettings();
+
+        synchronized (this) {
+            readGrantedUriPermissionsLocked();
+        }
+
+        if (goingCallback != null) goingCallback.run();
+        
+        synchronized (this) {
+            if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
+                try {
+                    List apps = AppGlobals.getPackageManager().
+                        getPersistentApplications(STOCK_PM_FLAGS);
+                    if (apps != null) {
+                        int N = apps.size();
+                        int i;
+                        for (i=0; i<N; i++) {
+                            ApplicationInfo info
+                                = (ApplicationInfo)apps.get(i);
+                            if (info != null &&
+                                    !info.packageName.equals("android")) {
+                                addAppLocked(info, false);
+                            }
+                        }
+                    }
+                } catch (RemoteException ex) {
+                    // pm is in same process, this will never happen.
+                }
+            }
+
+            // Start up initial activity.
+            mBooting = true;
+            
+            try {
+                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
+                    Message msg = Message.obtain();
+                    msg.what = SHOW_UID_ERROR_MSG;
+                    mHandler.sendMessage(msg);
+                }
+            } catch (RemoteException e) {
+            }
+
+            long ident = Binder.clearCallingIdentity();
+            try {
+                Intent intent = new Intent(Intent.ACTION_USER_STARTED);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                        | Intent.FLAG_RECEIVER_FOREGROUND);
+                intent.putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId);
+                broadcastIntentLocked(null, null, intent,
+                        null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                        false, false, MY_PID, Process.SYSTEM_UID, mCurrentUserId);
+                intent = new Intent(Intent.ACTION_USER_STARTING);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                intent.putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId);
+                broadcastIntentLocked(null, null, intent,
+                        null, new IIntentReceiver.Stub() {
+                            @Override
+                            public void performReceive(Intent intent, int resultCode, String data,
+                                    Bundle extras, boolean ordered, boolean sticky, int sendingUser)
+                                    throws RemoteException {
+                            }
+                        }, 0, null, null,
+                        android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
+                        true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+            mStackSupervisor.resumeTopActivitiesLocked();
+            sendUserSwitchBroadcastsLocked(-1, mCurrentUserId);
+        }
+    }
+
+    private boolean makeAppCrashingLocked(ProcessRecord app,
+            String shortMsg, String longMsg, String stackTrace) {
+        app.crashing = true;
+        app.crashingReport = generateProcessError(app,
+                ActivityManager.ProcessErrorStateInfo.CRASHED, null, shortMsg, longMsg, stackTrace);
+        startAppProblemLocked(app);
+        app.stopFreezingAllLocked();
+        return handleAppCrashLocked(app, shortMsg, longMsg, stackTrace);
+    }
+
+    private void makeAppNotRespondingLocked(ProcessRecord app,
+            String activity, String shortMsg, String longMsg) {
+        app.notResponding = true;
+        app.notRespondingReport = generateProcessError(app,
+                ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
+                activity, shortMsg, longMsg, null);
+        startAppProblemLocked(app);
+        app.stopFreezingAllLocked();
+    }
+    
+    /**
+     * Generate a process error record, suitable for attachment to a ProcessRecord.
+     * 
+     * @param app The ProcessRecord in which the error occurred.
+     * @param condition Crashing, Application Not Responding, etc.  Values are defined in 
+     *                      ActivityManager.AppErrorStateInfo
+     * @param activity The activity associated with the crash, if known.
+     * @param shortMsg Short message describing the crash.
+     * @param longMsg Long message describing the crash.
+     * @param stackTrace Full crash stack trace, may be null.
+     *
+     * @return Returns a fully-formed AppErrorStateInfo record.
+     */
+    private ActivityManager.ProcessErrorStateInfo generateProcessError(ProcessRecord app, 
+            int condition, String activity, String shortMsg, String longMsg, String stackTrace) {
+        ActivityManager.ProcessErrorStateInfo report = new ActivityManager.ProcessErrorStateInfo();
+
+        report.condition = condition;
+        report.processName = app.processName;
+        report.pid = app.pid;
+        report.uid = app.info.uid;
+        report.tag = activity;
+        report.shortMsg = shortMsg;
+        report.longMsg = longMsg;
+        report.stackTrace = stackTrace;
+
+        return report;
+    }
+
+    void killAppAtUsersRequest(ProcessRecord app, Dialog fromDialog) {
+        synchronized (this) {
+            app.crashing = false;
+            app.crashingReport = null;
+            app.notResponding = false;
+            app.notRespondingReport = null;
+            if (app.anrDialog == fromDialog) {
+                app.anrDialog = null;
+            }
+            if (app.waitDialog == fromDialog) {
+                app.waitDialog = null;
+            }
+            if (app.pid > 0 && app.pid != MY_PID) {
+                handleAppCrashLocked(app, null, null, null);
+                killUnneededProcessLocked(app, "user request after error");
+            }
+        }
+    }
+
+    private boolean handleAppCrashLocked(ProcessRecord app, String shortMsg, String longMsg,
+            String stackTrace) {
+        long now = SystemClock.uptimeMillis();
+
+        Long crashTime;
+        if (!app.isolated) {
+            crashTime = mProcessCrashTimes.get(app.info.processName, app.uid);
+        } else {
+            crashTime = null;
+        }
+        if (crashTime != null && now < crashTime+ProcessList.MIN_CRASH_INTERVAL) {
+            // This process loses!
+            Slog.w(TAG, "Process " + app.info.processName
+                    + " has crashed too many times: killing!");
+            EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
+                    app.userId, app.info.processName, app.uid);
+            mStackSupervisor.handleAppCrashLocked(app);
+            if (!app.persistent) {
+                // We don't want to start this process again until the user
+                // explicitly does so...  but for persistent process, we really
+                // need to keep it running.  If a persistent process is actually
+                // repeatedly crashing, then badness for everyone.
+                EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid,
+                        app.info.processName);
+                if (!app.isolated) {
+                    // XXX We don't have a way to mark isolated processes
+                    // as bad, since they don't have a peristent identity.
+                    mBadProcesses.put(app.info.processName, app.uid,
+                            new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
+                    mProcessCrashTimes.remove(app.info.processName, app.uid);
+                }
+                app.bad = true;
+                app.removed = true;
+                // Don't let services in this process be restarted and potentially
+                // annoy the user repeatedly.  Unless it is persistent, since those
+                // processes run critical code.
+                removeProcessLocked(app, false, false, "crash");
+                mStackSupervisor.resumeTopActivitiesLocked();
+                return false;
+            }
+            mStackSupervisor.resumeTopActivitiesLocked();
+        } else {
+            mStackSupervisor.finishTopRunningActivityLocked(app);
+        }
+
+        // Bump up the crash count of any services currently running in the proc.
+        for (int i=app.services.size()-1; i>=0; i--) {
+            // Any services running in the application need to be placed
+            // back in the pending list.
+            ServiceRecord sr = app.services.valueAt(i);
+            sr.crashCount++;
+        }
+
+        // If the crashing process is what we consider to be the "home process" and it has been
+        // replaced by a third-party app, clear the package preferred activities from packages
+        // with a home activity running in the process to prevent a repeatedly crashing app
+        // from blocking the user to manually clear the list.
+        final ArrayList<ActivityRecord> activities = app.activities;
+        if (app == mHomeProcess && activities.size() > 0
+                    && (mHomeProcess.info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.isHomeActivity()) {
+                    Log.i(TAG, "Clearing package preferred activities from " + r.packageName);
+                    try {
+                        ActivityThread.getPackageManager()
+                                .clearPackagePreferredActivities(r.packageName);
+                    } catch (RemoteException c) {
+                        // pm is in same process, this will never happen.
+                    }
+                }
+            }
+        }
+
+        if (!app.isolated) {
+            // XXX Can't keep track of crash times for isolated processes,
+            // because they don't have a perisistent identity.
+            mProcessCrashTimes.put(app.info.processName, app.uid, now);
+        }
+
+        return true;
+    }
+
+    void startAppProblemLocked(ProcessRecord app) {
+        if (app.userId == mCurrentUserId) {
+            app.errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
+                    mContext, app.info.packageName, app.info.flags);
+        } else {
+            // If this app is not running under the current user, then we
+            // can't give it a report button because that would require
+            // launching the report UI under a different user.
+            app.errorReportReceiver = null;
+        }
+        skipCurrentReceiverLocked(app);
+    }
+
+    void skipCurrentReceiverLocked(ProcessRecord app) {
+        for (BroadcastQueue queue : mBroadcastQueues) {
+            queue.skipCurrentReceiverLocked(app);
+        }
+    }
+
+    /**
+     * Used by {@link com.android.internal.os.RuntimeInit} to report when an application crashes.
+     * The application process will exit immediately after this call returns.
+     * @param app object of the crashing app, null for the system server
+     * @param crashInfo describing the exception
+     */
+    public void handleApplicationCrash(IBinder app, ApplicationErrorReport.CrashInfo crashInfo) {
+        ProcessRecord r = findAppProcess(app, "Crash");
+        final String processName = app == null ? "system_server"
+                : (r == null ? "unknown" : r.processName);
+
+        handleApplicationCrashInner("crash", r, processName, crashInfo);
+    }
+
+    /* Native crash reporting uses this inner version because it needs to be somewhat
+     * decoupled from the AM-managed cleanup lifecycle
+     */
+    void handleApplicationCrashInner(String eventType, ProcessRecord r, String processName,
+            ApplicationErrorReport.CrashInfo crashInfo) {
+        EventLog.writeEvent(EventLogTags.AM_CRASH, Binder.getCallingPid(),
+                UserHandle.getUserId(Binder.getCallingUid()), processName,
+                r == null ? -1 : r.info.flags,
+                crashInfo.exceptionClassName,
+                crashInfo.exceptionMessage,
+                crashInfo.throwFileName,
+                crashInfo.throwLineNumber);
+
+        addErrorToDropBox(eventType, r, processName, null, null, null, null, null, crashInfo);
+
+        crashApplication(r, crashInfo);
+    }
+
+    public void handleApplicationStrictModeViolation(
+            IBinder app,
+            int violationMask,
+            StrictMode.ViolationInfo info) {
+        ProcessRecord r = findAppProcess(app, "StrictMode");
+        if (r == null) {
+            return;
+        }
+
+        if ((violationMask & StrictMode.PENALTY_DROPBOX) != 0) {
+            Integer stackFingerprint = info.hashCode();
+            boolean logIt = true;
+            synchronized (mAlreadyLoggedViolatedStacks) {
+                if (mAlreadyLoggedViolatedStacks.contains(stackFingerprint)) {
+                    logIt = false;
+                    // TODO: sub-sample into EventLog for these, with
+                    // the info.durationMillis?  Then we'd get
+                    // the relative pain numbers, without logging all
+                    // the stack traces repeatedly.  We'd want to do
+                    // likewise in the client code, which also does
+                    // dup suppression, before the Binder call.
+                } else {
+                    if (mAlreadyLoggedViolatedStacks.size() >= MAX_DUP_SUPPRESSED_STACKS) {
+                        mAlreadyLoggedViolatedStacks.clear();
+                    }
+                    mAlreadyLoggedViolatedStacks.add(stackFingerprint);
+                }
+            }
+            if (logIt) {
+                logStrictModeViolationToDropBox(r, info);
+            }
+        }
+
+        if ((violationMask & StrictMode.PENALTY_DIALOG) != 0) {
+            AppErrorResult result = new AppErrorResult();
+            synchronized (this) {
+                final long origId = Binder.clearCallingIdentity();
+
+                Message msg = Message.obtain();
+                msg.what = SHOW_STRICT_MODE_VIOLATION_MSG;
+                HashMap<String, Object> data = new HashMap<String, Object>();
+                data.put("result", result);
+                data.put("app", r);
+                data.put("violationMask", violationMask);
+                data.put("info", info);
+                msg.obj = data;
+                mHandler.sendMessage(msg);
+
+                Binder.restoreCallingIdentity(origId);
+            }
+            int res = result.get();
+            Slog.w(TAG, "handleApplicationStrictModeViolation; res=" + res);
+        }
+    }
+
+    // Depending on the policy in effect, there could be a bunch of
+    // these in quick succession so we try to batch these together to
+    // minimize disk writes, number of dropbox entries, and maximize
+    // compression, by having more fewer, larger records.
+    private void logStrictModeViolationToDropBox(
+            ProcessRecord process,
+            StrictMode.ViolationInfo info) {
+        if (info == null) {
+            return;
+        }
+        final boolean isSystemApp = process == null ||
+                (process.info.flags & (ApplicationInfo.FLAG_SYSTEM |
+                                       ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
+        final String processName = process == null ? "unknown" : process.processName;
+        final String dropboxTag = isSystemApp ? "system_app_strictmode" : "data_app_strictmode";
+        final DropBoxManager dbox = (DropBoxManager)
+                mContext.getSystemService(Context.DROPBOX_SERVICE);
+
+        // Exit early if the dropbox isn't configured to accept this report type.
+        if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return;
+
+        boolean bufferWasEmpty;
+        boolean needsFlush;
+        final StringBuilder sb = isSystemApp ? mStrictModeBuffer : new StringBuilder(1024);
+        synchronized (sb) {
+            bufferWasEmpty = sb.length() == 0;
+            appendDropBoxProcessHeaders(process, processName, sb);
+            sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
+            sb.append("System-App: ").append(isSystemApp).append("\n");
+            sb.append("Uptime-Millis: ").append(info.violationUptimeMillis).append("\n");
+            if (info.violationNumThisLoop != 0) {
+                sb.append("Loop-Violation-Number: ").append(info.violationNumThisLoop).append("\n");
+            }
+            if (info.numAnimationsRunning != 0) {
+                sb.append("Animations-Running: ").append(info.numAnimationsRunning).append("\n");
+            }
+            if (info.broadcastIntentAction != null) {
+                sb.append("Broadcast-Intent-Action: ").append(info.broadcastIntentAction).append("\n");
+            }
+            if (info.durationMillis != -1) {
+                sb.append("Duration-Millis: ").append(info.durationMillis).append("\n");
+            }
+            if (info.numInstances != -1) {
+                sb.append("Instance-Count: ").append(info.numInstances).append("\n");
+            }
+            if (info.tags != null) {
+                for (String tag : info.tags) {
+                    sb.append("Span-Tag: ").append(tag).append("\n");
+                }
+            }
+            sb.append("\n");
+            if (info.crashInfo != null && info.crashInfo.stackTrace != null) {
+                sb.append(info.crashInfo.stackTrace);
+            }
+            sb.append("\n");
+
+            // Only buffer up to ~64k.  Various logging bits truncate
+            // things at 128k.
+            needsFlush = (sb.length() > 64 * 1024);
+        }
+
+        // Flush immediately if the buffer's grown too large, or this
+        // is a non-system app.  Non-system apps are isolated with a
+        // different tag & policy and not batched.
+        //
+        // Batching is useful during internal testing with
+        // StrictMode settings turned up high.  Without batching,
+        // thousands of separate files could be created on boot.
+        if (!isSystemApp || needsFlush) {
+            new Thread("Error dump: " + dropboxTag) {
+                @Override
+                public void run() {
+                    String report;
+                    synchronized (sb) {
+                        report = sb.toString();
+                        sb.delete(0, sb.length());
+                        sb.trimToSize();
+                    }
+                    if (report.length() != 0) {
+                        dbox.addText(dropboxTag, report);
+                    }
+                }
+            }.start();
+            return;
+        }
+
+        // System app batching:
+        if (!bufferWasEmpty) {
+            // An existing dropbox-writing thread is outstanding, so
+            // we don't need to start it up.  The existing thread will
+            // catch the buffer appends we just did.
+            return;
+        }
+
+        // Worker thread to both batch writes and to avoid blocking the caller on I/O.
+        // (After this point, we shouldn't access AMS internal data structures.)
+        new Thread("Error dump: " + dropboxTag) {
+            @Override
+            public void run() {
+                // 5 second sleep to let stacks arrive and be batched together
+                try {
+                    Thread.sleep(5000);  // 5 seconds
+                } catch (InterruptedException e) {}
+
+                String errorReport;
+                synchronized (mStrictModeBuffer) {
+                    errorReport = mStrictModeBuffer.toString();
+                    if (errorReport.length() == 0) {
+                        return;
+                    }
+                    mStrictModeBuffer.delete(0, mStrictModeBuffer.length());
+                    mStrictModeBuffer.trimToSize();
+                }
+                dbox.addText(dropboxTag, errorReport);
+            }
+        }.start();
+    }
+
+    /**
+     * Used by {@link Log} via {@link com.android.internal.os.RuntimeInit} to report serious errors.
+     * @param app object of the crashing app, null for the system server
+     * @param tag reported by the caller
+     * @param crashInfo describing the context of the error
+     * @return true if the process should exit immediately (WTF is fatal)
+     */
+    public boolean handleApplicationWtf(IBinder app, String tag,
+            ApplicationErrorReport.CrashInfo crashInfo) {
+        ProcessRecord r = findAppProcess(app, "WTF");
+        final String processName = app == null ? "system_server"
+                : (r == null ? "unknown" : r.processName);
+
+        EventLog.writeEvent(EventLogTags.AM_WTF,
+                UserHandle.getUserId(Binder.getCallingUid()), Binder.getCallingPid(),
+                processName,
+                r == null ? -1 : r.info.flags,
+                tag, crashInfo.exceptionMessage);
+
+        addErrorToDropBox("wtf", r, processName, null, null, tag, null, null, crashInfo);
+
+        if (r != null && r.pid != Process.myPid() &&
+                Settings.Global.getInt(mContext.getContentResolver(),
+                        Settings.Global.WTF_IS_FATAL, 0) != 0) {
+            crashApplication(r, crashInfo);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * @param app object of some object (as stored in {@link com.android.internal.os.RuntimeInit})
+     * @return the corresponding {@link ProcessRecord} object, or null if none could be found
+     */
+    private ProcessRecord findAppProcess(IBinder app, String reason) {
+        if (app == null) {
+            return null;
+        }
+
+        synchronized (this) {
+            final int NP = mProcessNames.getMap().size();
+            for (int ip=0; ip<NP; ip++) {
+                SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
+                final int NA = apps.size();
+                for (int ia=0; ia<NA; ia++) {
+                    ProcessRecord p = apps.valueAt(ia);
+                    if (p.thread != null && p.thread.asBinder() == app) {
+                        return p;
+                    }
+                }
+            }
+
+            Slog.w(TAG, "Can't find mystery application for " + reason
+                    + " from pid=" + Binder.getCallingPid()
+                    + " uid=" + Binder.getCallingUid() + ": " + app);
+            return null;
+        }
+    }
+
+    /**
+     * Utility function for addErrorToDropBox and handleStrictModeViolation's logging
+     * to append various headers to the dropbox log text.
+     */
+    private void appendDropBoxProcessHeaders(ProcessRecord process, String processName,
+            StringBuilder sb) {
+        // Watchdog thread ends up invoking this function (with
+        // a null ProcessRecord) to add the stack file to dropbox.
+        // Do not acquire a lock on this (am) in such cases, as it
+        // could cause a potential deadlock, if and when watchdog
+        // is invoked due to unavailability of lock on am and it
+        // would prevent watchdog from killing system_server.
+        if (process == null) {
+            sb.append("Process: ").append(processName).append("\n");
+            return;
+        }
+        // Note: ProcessRecord 'process' is guarded by the service
+        // instance.  (notably process.pkgList, which could otherwise change
+        // concurrently during execution of this method)
+        synchronized (this) {
+            sb.append("Process: ").append(processName).append("\n");
+            int flags = process.info.flags;
+            IPackageManager pm = AppGlobals.getPackageManager();
+            sb.append("Flags: 0x").append(Integer.toString(flags, 16)).append("\n");
+            for (int ip=0; ip<process.pkgList.size(); ip++) {
+                String pkg = process.pkgList.keyAt(ip);
+                sb.append("Package: ").append(pkg);
+                try {
+                    PackageInfo pi = pm.getPackageInfo(pkg, 0, UserHandle.getCallingUserId());
+                    if (pi != null) {
+                        sb.append(" v").append(pi.versionCode);
+                        if (pi.versionName != null) {
+                            sb.append(" (").append(pi.versionName).append(")");
+                        }
+                    }
+                } catch (RemoteException e) {
+                    Slog.e(TAG, "Error getting package info: " + pkg, e);
+                }
+                sb.append("\n");
+            }
+        }
+    }
+
+    private static String processClass(ProcessRecord process) {
+        if (process == null || process.pid == MY_PID) {
+            return "system_server";
+        } else if ((process.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+            return "system_app";
+        } else {
+            return "data_app";
+        }
+    }
+
+    /**
+     * Write a description of an error (crash, WTF, ANR) to the drop box.
+     * @param eventType to include in the drop box tag ("crash", "wtf", etc.)
+     * @param process which caused the error, null means the system server
+     * @param activity which triggered the error, null if unknown
+     * @param parent activity related to the error, null if unknown
+     * @param subject line related to the error, null if absent
+     * @param report in long form describing the error, null if absent
+     * @param logFile to include in the report, null if none
+     * @param crashInfo giving an application stack trace, null if absent
+     */
+    public void addErrorToDropBox(String eventType,
+            ProcessRecord process, String processName, ActivityRecord activity,
+            ActivityRecord parent, String subject,
+            final String report, final File logFile,
+            final ApplicationErrorReport.CrashInfo crashInfo) {
+        // NOTE -- this must never acquire the ActivityManagerService lock,
+        // otherwise the watchdog may be prevented from resetting the system.
+
+        final String dropboxTag = processClass(process) + "_" + eventType;
+        final DropBoxManager dbox = (DropBoxManager)
+                mContext.getSystemService(Context.DROPBOX_SERVICE);
+
+        // Exit early if the dropbox isn't configured to accept this report type.
+        if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return;
+
+        final StringBuilder sb = new StringBuilder(1024);
+        appendDropBoxProcessHeaders(process, processName, sb);
+        if (activity != null) {
+            sb.append("Activity: ").append(activity.shortComponentName).append("\n");
+        }
+        if (parent != null && parent.app != null && parent.app.pid != process.pid) {
+            sb.append("Parent-Process: ").append(parent.app.processName).append("\n");
+        }
+        if (parent != null && parent != activity) {
+            sb.append("Parent-Activity: ").append(parent.shortComponentName).append("\n");
+        }
+        if (subject != null) {
+            sb.append("Subject: ").append(subject).append("\n");
+        }
+        sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
+        if (Debug.isDebuggerConnected()) {
+            sb.append("Debugger: Connected\n");
+        }
+        sb.append("\n");
+
+        // Do the rest in a worker thread to avoid blocking the caller on I/O
+        // (After this point, we shouldn't access AMS internal data structures.)
+        Thread worker = new Thread("Error dump: " + dropboxTag) {
+            @Override
+            public void run() {
+                if (report != null) {
+                    sb.append(report);
+                }
+                if (logFile != null) {
+                    try {
+                        sb.append(FileUtils.readTextFile(logFile, DROPBOX_MAX_SIZE,
+                                    "\n\n[[TRUNCATED]]"));
+                    } catch (IOException e) {
+                        Slog.e(TAG, "Error reading " + logFile, e);
+                    }
+                }
+                if (crashInfo != null && crashInfo.stackTrace != null) {
+                    sb.append(crashInfo.stackTrace);
+                }
+
+                String setting = Settings.Global.ERROR_LOGCAT_PREFIX + dropboxTag;
+                int lines = Settings.Global.getInt(mContext.getContentResolver(), setting, 0);
+                if (lines > 0) {
+                    sb.append("\n");
+
+                    // Merge several logcat streams, and take the last N lines
+                    InputStreamReader input = null;
+                    try {
+                        java.lang.Process logcat = new ProcessBuilder("/system/bin/logcat",
+                                "-v", "time", "-b", "events", "-b", "system", "-b", "main",
+                                "-t", String.valueOf(lines)).redirectErrorStream(true).start();
+
+                        try { logcat.getOutputStream().close(); } catch (IOException e) {}
+                        try { logcat.getErrorStream().close(); } catch (IOException e) {}
+                        input = new InputStreamReader(logcat.getInputStream());
+
+                        int num;
+                        char[] buf = new char[8192];
+                        while ((num = input.read(buf)) > 0) sb.append(buf, 0, num);
+                    } catch (IOException e) {
+                        Slog.e(TAG, "Error running logcat", e);
+                    } finally {
+                        if (input != null) try { input.close(); } catch (IOException e) {}
+                    }
+                }
+
+                dbox.addText(dropboxTag, sb.toString());
+            }
+        };
+
+        if (process == null) {
+            // If process is null, we are being called from some internal code
+            // and may be about to die -- run this synchronously.
+            worker.run();
+        } else {
+            worker.start();
+        }
+    }
+
+    /**
+     * Bring up the "unexpected error" dialog box for a crashing app.
+     * Deal with edge cases (intercepts from instrumented applications,
+     * ActivityController, error intent receivers, that sort of thing).
+     * @param r the application crashing
+     * @param crashInfo describing the failure
+     */
+    private void crashApplication(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo) {
+        long timeMillis = System.currentTimeMillis();
+        String shortMsg = crashInfo.exceptionClassName;
+        String longMsg = crashInfo.exceptionMessage;
+        String stackTrace = crashInfo.stackTrace;
+        if (shortMsg != null && longMsg != null) {
+            longMsg = shortMsg + ": " + longMsg;
+        } else if (shortMsg != null) {
+            longMsg = shortMsg;
+        }
+
+        AppErrorResult result = new AppErrorResult();
+        synchronized (this) {
+            if (mController != null) {
+                try {
+                    String name = r != null ? r.processName : null;
+                    int pid = r != null ? r.pid : Binder.getCallingPid();
+                    if (!mController.appCrashed(name, pid,
+                            shortMsg, longMsg, timeMillis, crashInfo.stackTrace)) {
+                        Slog.w(TAG, "Force-killing crashed app " + name
+                                + " at watcher's request");
+                        Process.killProcess(pid);
+                        return;
+                    }
+                } catch (RemoteException e) {
+                    mController = null;
+                    Watchdog.getInstance().setActivityController(null);
+                }
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+
+            // If this process is running instrumentation, finish it.
+            if (r != null && r.instrumentationClass != null) {
+                Slog.w(TAG, "Error in app " + r.processName
+                      + " running instrumentation " + r.instrumentationClass + ":");
+                if (shortMsg != null) Slog.w(TAG, "  " + shortMsg);
+                if (longMsg != null) Slog.w(TAG, "  " + longMsg);
+                Bundle info = new Bundle();
+                info.putString("shortMsg", shortMsg);
+                info.putString("longMsg", longMsg);
+                finishInstrumentationLocked(r, Activity.RESULT_CANCELED, info);
+                Binder.restoreCallingIdentity(origId);
+                return;
+            }
+
+            // If we can't identify the process or it's already exceeded its crash quota,
+            // quit right away without showing a crash dialog.
+            if (r == null || !makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace)) {
+                Binder.restoreCallingIdentity(origId);
+                return;
+            }
+
+            Message msg = Message.obtain();
+            msg.what = SHOW_ERROR_MSG;
+            HashMap data = new HashMap();
+            data.put("result", result);
+            data.put("app", r);
+            msg.obj = data;
+            mHandler.sendMessage(msg);
+
+            Binder.restoreCallingIdentity(origId);
+        }
+
+        int res = result.get();
+
+        Intent appErrorIntent = null;
+        synchronized (this) {
+            if (r != null && !r.isolated) {
+                // XXX Can't keep track of crash time for isolated processes,
+                // since they don't have a persistent identity.
+                mProcessCrashTimes.put(r.info.processName, r.uid,
+                        SystemClock.uptimeMillis());
+            }
+            if (res == AppErrorDialog.FORCE_QUIT_AND_REPORT) {
+                appErrorIntent = createAppErrorIntentLocked(r, timeMillis, crashInfo);
+            }
+        }
+
+        if (appErrorIntent != null) {
+            try {
+                mContext.startActivityAsUser(appErrorIntent, new UserHandle(r.userId));
+            } catch (ActivityNotFoundException e) {
+                Slog.w(TAG, "bug report receiver dissappeared", e);
+            }
+        }
+    }
+
+    Intent createAppErrorIntentLocked(ProcessRecord r,
+            long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
+        ApplicationErrorReport report = createAppErrorReportLocked(r, timeMillis, crashInfo);
+        if (report == null) {
+            return null;
+        }
+        Intent result = new Intent(Intent.ACTION_APP_ERROR);
+        result.setComponent(r.errorReportReceiver);
+        result.putExtra(Intent.EXTRA_BUG_REPORT, report);
+        result.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        return result;
+    }
+
+    private ApplicationErrorReport createAppErrorReportLocked(ProcessRecord r,
+            long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
+        if (r.errorReportReceiver == null) {
+            return null;
+        }
+
+        if (!r.crashing && !r.notResponding && !r.forceCrashReport) {
+            return null;
+        }
+
+        ApplicationErrorReport report = new ApplicationErrorReport();
+        report.packageName = r.info.packageName;
+        report.installerPackageName = r.errorReportReceiver.getPackageName();
+        report.processName = r.processName;
+        report.time = timeMillis;
+        report.systemApp = (r.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+
+        if (r.crashing || r.forceCrashReport) {
+            report.type = ApplicationErrorReport.TYPE_CRASH;
+            report.crashInfo = crashInfo;
+        } else if (r.notResponding) {
+            report.type = ApplicationErrorReport.TYPE_ANR;
+            report.anrInfo = new ApplicationErrorReport.AnrInfo();
+
+            report.anrInfo.activity = r.notRespondingReport.tag;
+            report.anrInfo.cause = r.notRespondingReport.shortMsg;
+            report.anrInfo.info = r.notRespondingReport.longMsg;
+        }
+
+        return report;
+    }
+
+    public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState() {
+        enforceNotIsolatedCaller("getProcessesInErrorState");
+        // assume our apps are happy - lazy create the list
+        List<ActivityManager.ProcessErrorStateInfo> errList = null;
+
+        final boolean allUsers = ActivityManager.checkUidPermission(
+                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                Binder.getCallingUid()) == PackageManager.PERMISSION_GRANTED;
+        int userId = UserHandle.getUserId(Binder.getCallingUid());
+
+        synchronized (this) {
+
+            // iterate across all processes
+            for (int i=mLruProcesses.size()-1; i>=0; i--) {
+                ProcessRecord app = mLruProcesses.get(i);
+                if (!allUsers && app.userId != userId) {
+                    continue;
+                }
+                if ((app.thread != null) && (app.crashing || app.notResponding)) {
+                    // This one's in trouble, so we'll generate a report for it
+                    // crashes are higher priority (in case there's a crash *and* an anr)
+                    ActivityManager.ProcessErrorStateInfo report = null;
+                    if (app.crashing) {
+                        report = app.crashingReport;
+                    } else if (app.notResponding) {
+                        report = app.notRespondingReport;
+                    }
+                    
+                    if (report != null) {
+                        if (errList == null) {
+                            errList = new ArrayList<ActivityManager.ProcessErrorStateInfo>(1);
+                        }
+                        errList.add(report);
+                    } else {
+                        Slog.w(TAG, "Missing app error report, app = " + app.processName + 
+                                " crashing = " + app.crashing +
+                                " notResponding = " + app.notResponding);
+                    }
+                }
+            }
+        }
+
+        return errList;
+    }
+
+    static int oomAdjToImportance(int adj, ActivityManager.RunningAppProcessInfo currApp) {
+        if (adj >= ProcessList.CACHED_APP_MIN_ADJ) {
+            if (currApp != null) {
+                currApp.lru = adj - ProcessList.CACHED_APP_MIN_ADJ + 1;
+            }
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+        } else if (adj >= ProcessList.SERVICE_B_ADJ) {
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
+        } else if (adj >= ProcessList.HOME_APP_ADJ) {
+            if (currApp != null) {
+                currApp.lru = 0;
+            }
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+        } else if (adj >= ProcessList.SERVICE_ADJ) {
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
+        } else if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
+        } else if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
+        } else if (adj >= ProcessList.VISIBLE_APP_ADJ) {
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
+        } else {
+            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
+        }
+    }
+
+    private void fillInProcMemInfo(ProcessRecord app,
+            ActivityManager.RunningAppProcessInfo outInfo) {
+        outInfo.pid = app.pid;
+        outInfo.uid = app.info.uid;
+        if (mHeavyWeightProcess == app) {
+            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE;
+        }
+        if (app.persistent) {
+            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT;
+        }
+        if (app.activities.size() > 0) {
+            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES;
+        }
+        outInfo.lastTrimLevel = app.trimMemoryLevel;
+        int adj = app.curAdj;
+        outInfo.importance = oomAdjToImportance(adj, outInfo);
+        outInfo.importanceReasonCode = app.adjTypeCode;
+    }
+
+    public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() {
+        enforceNotIsolatedCaller("getRunningAppProcesses");
+        // Lazy instantiation of list
+        List<ActivityManager.RunningAppProcessInfo> runList = null;
+        final boolean allUsers = ActivityManager.checkUidPermission(
+                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                Binder.getCallingUid()) == PackageManager.PERMISSION_GRANTED;
+        int userId = UserHandle.getUserId(Binder.getCallingUid());
+        synchronized (this) {
+            // Iterate across all processes
+            for (int i=mLruProcesses.size()-1; i>=0; i--) {
+                ProcessRecord app = mLruProcesses.get(i);
+                if (!allUsers && app.userId != userId) {
+                    continue;
+                }
+                if ((app.thread != null) && (!app.crashing && !app.notResponding)) {
+                    // Generate process state info for running application
+                    ActivityManager.RunningAppProcessInfo currApp = 
+                        new ActivityManager.RunningAppProcessInfo(app.processName,
+                                app.pid, app.getPackageList());
+                    fillInProcMemInfo(app, currApp);
+                    if (app.adjSource instanceof ProcessRecord) {
+                        currApp.importanceReasonPid = ((ProcessRecord)app.adjSource).pid;
+                        currApp.importanceReasonImportance = oomAdjToImportance(
+                                app.adjSourceOom, null);
+                    } else if (app.adjSource instanceof ActivityRecord) {
+                        ActivityRecord r = (ActivityRecord)app.adjSource;
+                        if (r.app != null) currApp.importanceReasonPid = r.app.pid;
+                    }
+                    if (app.adjTarget instanceof ComponentName) {
+                        currApp.importanceReasonComponent = (ComponentName)app.adjTarget;
+                    }
+                    //Slog.v(TAG, "Proc " + app.processName + ": imp=" + currApp.importance
+                    //        + " lru=" + currApp.lru);
+                    if (runList == null) {
+                        runList = new ArrayList<ActivityManager.RunningAppProcessInfo>();
+                    }
+                    runList.add(currApp);
+                }
+            }
+        }
+        return runList;
+    }
+
+    public List<ApplicationInfo> getRunningExternalApplications() {
+        enforceNotIsolatedCaller("getRunningExternalApplications");
+        List<ActivityManager.RunningAppProcessInfo> runningApps = getRunningAppProcesses();
+        List<ApplicationInfo> retList = new ArrayList<ApplicationInfo>();
+        if (runningApps != null && runningApps.size() > 0) {
+            Set<String> extList = new HashSet<String>();
+            for (ActivityManager.RunningAppProcessInfo app : runningApps) {
+                if (app.pkgList != null) {
+                    for (String pkg : app.pkgList) {
+                        extList.add(pkg);
+                    }
+                }
+            }
+            IPackageManager pm = AppGlobals.getPackageManager();
+            for (String pkg : extList) {
+                try {
+                    ApplicationInfo info = pm.getApplicationInfo(pkg, 0, UserHandle.getCallingUserId());
+                    if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
+                        retList.add(info);
+                    }
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        return retList;
+    }
+
+    @Override
+    public void getMyMemoryState(ActivityManager.RunningAppProcessInfo outInfo) {
+        enforceNotIsolatedCaller("getMyMemoryState");
+        synchronized (this) {
+            ProcessRecord proc;
+            synchronized (mPidsSelfLocked) {
+                proc = mPidsSelfLocked.get(Binder.getCallingPid());
+            }
+            fillInProcMemInfo(proc, outInfo);
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (checkCallingPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump ActivityManager from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " without permission "
+                    + android.Manifest.permission.DUMP);
+            return;
+        }
+
+        boolean dumpAll = false;
+        boolean dumpClient = false;
+        String dumpPackage = null;
+        
+        int opti = 0;
+        while (opti < args.length) {
+            String opt = args[opti];
+            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
+                break;
+            }
+            opti++;
+            if ("-a".equals(opt)) {
+                dumpAll = true;
+            } else if ("-c".equals(opt)) {
+                dumpClient = true;
+            } else if ("-h".equals(opt)) {
+                pw.println("Activity manager dump options:");
+                pw.println("  [-a] [-c] [-h] [cmd] ...");
+                pw.println("  cmd may be one of:");
+                pw.println("    a[ctivities]: activity stack state");
+                pw.println("    b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state");
+                pw.println("    i[ntents] [PACKAGE_NAME]: pending intent state");
+                pw.println("    p[rocesses] [PACKAGE_NAME]: process state");
+                pw.println("    o[om]: out of memory management");
+                pw.println("    prov[iders] [COMP_SPEC ...]: content provider state");
+                pw.println("    provider [COMP_SPEC]: provider client-side state");
+                pw.println("    s[ervices] [COMP_SPEC ...]: service state");
+                pw.println("    service [COMP_SPEC]: service client-side state");
+                pw.println("    package [PACKAGE_NAME]: all state related to given package");
+                pw.println("    all: dump all activities");
+                pw.println("    top: dump the top activity");
+                pw.println("  cmd may also be a COMP_SPEC to dump activities.");
+                pw.println("  COMP_SPEC may be a component name (com.foo/.myApp),");
+                pw.println("    a partial substring in a component name, a");
+                pw.println("    hex object identifier.");
+                pw.println("  -a: include all available server state.");
+                pw.println("  -c: include client state.");
+                return;
+            } else {
+                pw.println("Unknown argument: " + opt + "; use -h for help");
+            }
+        }
+
+        long origId = Binder.clearCallingIdentity();
+        boolean more = false;
+        // Is the caller requesting to dump a particular piece of data?
+        if (opti < args.length) {
+            String cmd = args[opti];
+            opti++;
+            if ("activities".equals(cmd) || "a".equals(cmd)) {
+                synchronized (this) {
+                    dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, null);
+                }
+            } else if ("broadcasts".equals(cmd) || "b".equals(cmd)) {
+                String[] newArgs;
+                String name;
+                if (opti >= args.length) {
+                    name = null;
+                    newArgs = EMPTY_STRING_ARRAY;
+                } else {
+                    name = args[opti];
+                    opti++;
+                    newArgs = new String[args.length - opti];
+                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
+                            args.length - opti);
+                }
+                synchronized (this) {
+                    dumpBroadcastsLocked(fd, pw, args, opti, true, name);
+                }
+            } else if ("intents".equals(cmd) || "i".equals(cmd)) {
+                String[] newArgs;
+                String name;
+                if (opti >= args.length) {
+                    name = null;
+                    newArgs = EMPTY_STRING_ARRAY;
+                } else {
+                    name = args[opti];
+                    opti++;
+                    newArgs = new String[args.length - opti];
+                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
+                            args.length - opti);
+                }
+                synchronized (this) {
+                    dumpPendingIntentsLocked(fd, pw, args, opti, true, name);
+                }
+            } else if ("processes".equals(cmd) || "p".equals(cmd)) {
+                String[] newArgs;
+                String name;
+                if (opti >= args.length) {
+                    name = null;
+                    newArgs = EMPTY_STRING_ARRAY;
+                } else {
+                    name = args[opti];
+                    opti++;
+                    newArgs = new String[args.length - opti];
+                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
+                            args.length - opti);
+                }
+                synchronized (this) {
+                    dumpProcessesLocked(fd, pw, args, opti, true, name);
+                }
+            } else if ("oom".equals(cmd) || "o".equals(cmd)) {
+                synchronized (this) {
+                    dumpOomLocked(fd, pw, args, opti, true);
+                }
+            } else if ("provider".equals(cmd)) {
+                String[] newArgs;
+                String name;
+                if (opti >= args.length) {
+                    name = null;
+                    newArgs = EMPTY_STRING_ARRAY;
+                } else {
+                    name = args[opti];
+                    opti++;
+                    newArgs = new String[args.length - opti];
+                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0, args.length - opti);
+                }
+                if (!dumpProvider(fd, pw, name, newArgs, 0, dumpAll)) {
+                    pw.println("No providers match: " + name);
+                    pw.println("Use -h for help.");
+                }
+            } else if ("providers".equals(cmd) || "prov".equals(cmd)) {
+                synchronized (this) {
+                    dumpProvidersLocked(fd, pw, args, opti, true, null);
+                }
+            } else if ("service".equals(cmd)) {
+                String[] newArgs;
+                String name;
+                if (opti >= args.length) {
+                    name = null;
+                    newArgs = EMPTY_STRING_ARRAY;
+                } else {
+                    name = args[opti];
+                    opti++;
+                    newArgs = new String[args.length - opti];
+                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
+                            args.length - opti);
+                }
+                if (!mServices.dumpService(fd, pw, name, newArgs, 0, dumpAll)) {
+                    pw.println("No services match: " + name);
+                    pw.println("Use -h for help.");
+                }
+            } else if ("package".equals(cmd)) {
+                String[] newArgs;
+                if (opti >= args.length) {
+                    pw.println("package: no package name specified");
+                    pw.println("Use -h for help.");
+                } else {
+                    dumpPackage = args[opti];
+                    opti++;
+                    newArgs = new String[args.length - opti];
+                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
+                            args.length - opti);
+                    args = newArgs;
+                    opti = 0;
+                    more = true;
+                }
+            } else if ("services".equals(cmd) || "s".equals(cmd)) {
+                synchronized (this) {
+                    mServices.dumpServicesLocked(fd, pw, args, opti, true, dumpClient, null);
+                }
+            } else {
+                // Dumping a single activity?
+                if (!dumpActivity(fd, pw, cmd, args, opti, dumpAll)) {
+                    pw.println("Bad activity command, or no activities match: " + cmd);
+                    pw.println("Use -h for help.");
+                }
+            }
+            if (!more) {
+                Binder.restoreCallingIdentity(origId);
+                return;
+            }
+        }
+
+        // No piece of data specified, dump everything.
+        synchronized (this) {
+            dumpPendingIntentsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpBroadcastsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpProvidersLocked(fd, pw, args, opti, dumpAll, dumpPackage);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            mServices.dumpServicesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpProcessesLocked(fd, pw, args, opti, dumpAll, dumpPackage);
+        }
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) {
+        pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)");
+
+        boolean printedAnything = mStackSupervisor.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient,
+                dumpPackage);
+        boolean needSep = printedAnything;
+
+        boolean printed = ActivityStackSupervisor.printThisActivity(pw, mFocusedActivity,
+                dumpPackage, needSep, "  mFocusedActivity: ");
+        if (printed) {
+            printedAnything = true;
+            needSep = false;
+        }
+
+        if (dumpPackage == null) {
+            if (needSep) {
+                pw.println();
+            }
+            needSep = true;
+            printedAnything = true;
+            mStackSupervisor.dump(pw, "  ");
+        }
+
+        if (mRecentTasks.size() > 0) {
+            boolean printedHeader = false;
+
+            final int N = mRecentTasks.size();
+            for (int i=0; i<N; i++) {
+                TaskRecord tr = mRecentTasks.get(i);
+                if (dumpPackage != null) {
+                    if (tr.realActivity == null ||
+                            !dumpPackage.equals(tr.realActivity)) {
+                        continue;
+                    }
+                }
+                if (!printedHeader) {
+                    if (needSep) {
+                        pw.println();
+                    }
+                    pw.println("  Recent tasks:");
+                    printedHeader = true;
+                    printedAnything = true;
+                }
+                pw.print("  * Recent #"); pw.print(i); pw.print(": ");
+                        pw.println(tr);
+                if (dumpAll) {
+                    mRecentTasks.get(i).dump(pw, "    ");
+                }
+            }
+        }
+
+        if (!printedAnything) {
+            pw.println("  (nothing)");
+        }
+    }
+
+    void dumpProcessesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, String dumpPackage) {
+        boolean needSep = false;
+        boolean printedAnything = false;
+        int numPers = 0;
+
+        pw.println("ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)");
+
+        if (dumpAll) {
+            final int NP = mProcessNames.getMap().size();
+            for (int ip=0; ip<NP; ip++) {
+                SparseArray<ProcessRecord> procs = mProcessNames.getMap().valueAt(ip);
+                final int NA = procs.size();
+                for (int ia=0; ia<NA; ia++) {
+                    ProcessRecord r = procs.valueAt(ia);
+                    if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
+                        continue;
+                    }
+                    if (!needSep) {
+                        pw.println("  All known processes:");
+                        needSep = true;
+                        printedAnything = true;
+                    }
+                    pw.print(r.persistent ? "  *PERS*" : "  *APP*");
+                        pw.print(" UID "); pw.print(procs.keyAt(ia));
+                        pw.print(" "); pw.println(r);
+                    r.dump(pw, "    ");
+                    if (r.persistent) {
+                        numPers++;
+                    }
+                }
+            }
+        }
+
+        if (mIsolatedProcesses.size() > 0) {
+            boolean printed = false;
+            for (int i=0; i<mIsolatedProcesses.size(); i++) {
+                ProcessRecord r = mIsolatedProcesses.valueAt(i);
+                if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
+                    continue;
+                }
+                if (!printed) {
+                    if (needSep) {
+                        pw.println();
+                    }
+                    pw.println("  Isolated process list (sorted by uid):");
+                    printedAnything = true;
+                    printed = true;
+                    needSep = true;
+                }
+                pw.println(String.format("%sIsolated #%2d: %s",
+                        "    ", i, r.toString()));
+            }
+        }
+
+        if (mLruProcesses.size() > 0) {
+            if (needSep) {
+                pw.println();
+            }
+            pw.print("  Process LRU list (sorted by oom_adj, "); pw.print(mLruProcesses.size());
+                    pw.print(" total, non-act at ");
+                    pw.print(mLruProcesses.size()-mLruProcessActivityStart);
+                    pw.print(", non-svc at ");
+                    pw.print(mLruProcesses.size()-mLruProcessServiceStart);
+                    pw.println("):");
+            dumpProcessOomList(pw, this, mLruProcesses, "    ", "Proc", "PERS", false, dumpPackage);
+            needSep = true;
+            printedAnything = true;
+        }
+
+        if (dumpAll || dumpPackage != null) {
+            synchronized (mPidsSelfLocked) {
+                boolean printed = false;
+                for (int i=0; i<mPidsSelfLocked.size(); i++) {
+                    ProcessRecord r = mPidsSelfLocked.valueAt(i);
+                    if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
+                        continue;
+                    }
+                    if (!printed) {
+                        if (needSep) pw.println();
+                        needSep = true;
+                        pw.println("  PID mappings:");
+                        printed = true;
+                        printedAnything = true;
+                    }
+                    pw.print("    PID #"); pw.print(mPidsSelfLocked.keyAt(i));
+                        pw.print(": "); pw.println(mPidsSelfLocked.valueAt(i));
+                }
+            }
+        }
+        
+        if (mForegroundProcesses.size() > 0) {
+            synchronized (mPidsSelfLocked) {
+                boolean printed = false;
+                for (int i=0; i<mForegroundProcesses.size(); i++) {
+                    ProcessRecord r = mPidsSelfLocked.get( 
+                            mForegroundProcesses.valueAt(i).pid);
+                    if (dumpPackage != null && (r == null
+                            || !r.pkgList.containsKey(dumpPackage))) {
+                        continue;
+                    }
+                    if (!printed) {
+                        if (needSep) pw.println();
+                        needSep = true;
+                        pw.println("  Foreground Processes:");
+                        printed = true;
+                        printedAnything = true;
+                    }
+                    pw.print("    PID #"); pw.print(mForegroundProcesses.keyAt(i));
+                            pw.print(": "); pw.println(mForegroundProcesses.valueAt(i));
+                }
+            }
+        }
+        
+        if (mPersistentStartingProcesses.size() > 0) {
+            if (needSep) pw.println();
+            needSep = true;
+            printedAnything = true;
+            pw.println("  Persisent processes that are starting:");
+            dumpProcessList(pw, this, mPersistentStartingProcesses, "    ",
+                    "Starting Norm", "Restarting PERS", dumpPackage);
+        }
+
+        if (mRemovedProcesses.size() > 0) {
+            if (needSep) pw.println();
+            needSep = true;
+            printedAnything = true;
+            pw.println("  Processes that are being removed:");
+            dumpProcessList(pw, this, mRemovedProcesses, "    ",
+                    "Removed Norm", "Removed PERS", dumpPackage);
+        }
+        
+        if (mProcessesOnHold.size() > 0) {
+            if (needSep) pw.println();
+            needSep = true;
+            printedAnything = true;
+            pw.println("  Processes that are on old until the system is ready:");
+            dumpProcessList(pw, this, mProcessesOnHold, "    ",
+                    "OnHold Norm", "OnHold PERS", dumpPackage);
+        }
+
+        needSep = dumpProcessesToGc(fd, pw, args, opti, needSep, dumpAll, dumpPackage);
+        
+        if (mProcessCrashTimes.getMap().size() > 0) {
+            boolean printed = false;
+            long now = SystemClock.uptimeMillis();
+            final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
+            final int NP = pmap.size();
+            for (int ip=0; ip<NP; ip++) {
+                String pname = pmap.keyAt(ip);
+                SparseArray<Long> uids = pmap.valueAt(ip);
+                final int N = uids.size();
+                for (int i=0; i<N; i++) {
+                    int puid = uids.keyAt(i);
+                    ProcessRecord r = mProcessNames.get(pname, puid);
+                    if (dumpPackage != null && (r == null
+                            || !r.pkgList.containsKey(dumpPackage))) {
+                        continue;
+                    }
+                    if (!printed) {
+                        if (needSep) pw.println();
+                        needSep = true;
+                        pw.println("  Time since processes crashed:");
+                        printed = true;
+                        printedAnything = true;
+                    }
+                    pw.print("    Process "); pw.print(pname);
+                            pw.print(" uid "); pw.print(puid);
+                            pw.print(": last crashed ");
+                            TimeUtils.formatDuration(now-uids.valueAt(i), pw);
+                            pw.println(" ago");
+                }
+            }
+        }
+
+        if (mBadProcesses.getMap().size() > 0) {
+            boolean printed = false;
+            final ArrayMap<String, SparseArray<BadProcessInfo>> pmap = mBadProcesses.getMap();
+            final int NP = pmap.size();
+            for (int ip=0; ip<NP; ip++) {
+                String pname = pmap.keyAt(ip);
+                SparseArray<BadProcessInfo> uids = pmap.valueAt(ip);
+                final int N = uids.size();
+                for (int i=0; i<N; i++) {
+                    int puid = uids.keyAt(i);
+                    ProcessRecord r = mProcessNames.get(pname, puid);
+                    if (dumpPackage != null && (r == null
+                            || !r.pkgList.containsKey(dumpPackage))) {
+                        continue;
+                    }
+                    if (!printed) {
+                        if (needSep) pw.println();
+                        needSep = true;
+                        pw.println("  Bad processes:");
+                        printedAnything = true;
+                    }
+                    BadProcessInfo info = uids.valueAt(i);
+                    pw.print("    Bad process "); pw.print(pname);
+                            pw.print(" uid "); pw.print(puid);
+                            pw.print(": crashed at time "); pw.println(info.time);
+                    if (info.shortMsg != null) {
+                        pw.print("      Short msg: "); pw.println(info.shortMsg);
+                    }
+                    if (info.longMsg != null) {
+                        pw.print("      Long msg: "); pw.println(info.longMsg);
+                    }
+                    if (info.stack != null) {
+                        pw.println("      Stack:");
+                        int lastPos = 0;
+                        for (int pos=0; pos<info.stack.length(); pos++) {
+                            if (info.stack.charAt(pos) == '\n') {
+                                pw.print("        ");
+                                pw.write(info.stack, lastPos, pos-lastPos);
+                                pw.println();
+                                lastPos = pos+1;
+                            }
+                        }
+                        if (lastPos < info.stack.length()) {
+                            pw.print("        ");
+                            pw.write(info.stack, lastPos, info.stack.length()-lastPos);
+                            pw.println();
+                        }
+                    }
+                }
+            }
+        }
+
+        if (dumpPackage == null) {
+            pw.println();
+            needSep = false;
+            pw.println("  mStartedUsers:");
+            for (int i=0; i<mStartedUsers.size(); i++) {
+                UserStartedState uss = mStartedUsers.valueAt(i);
+                pw.print("    User #"); pw.print(uss.mHandle.getIdentifier());
+                        pw.print(": "); uss.dump("", pw);
+            }
+            pw.print("  mStartedUserArray: [");
+            for (int i=0; i<mStartedUserArray.length; i++) {
+                if (i > 0) pw.print(", ");
+                pw.print(mStartedUserArray[i]);
+            }
+            pw.println("]");
+            pw.print("  mUserLru: [");
+            for (int i=0; i<mUserLru.size(); i++) {
+                if (i > 0) pw.print(", ");
+                pw.print(mUserLru.get(i));
+            }
+            pw.println("]");
+            if (dumpAll) {
+                pw.print("  mStartedUserArray: "); pw.println(Arrays.toString(mStartedUserArray));
+            }
+        }
+        if (mHomeProcess != null && (dumpPackage == null
+                || mHomeProcess.pkgList.containsKey(dumpPackage))) {
+            if (needSep) {
+                pw.println();
+                needSep = false;
+            }
+            pw.println("  mHomeProcess: " + mHomeProcess);
+        }
+        if (mPreviousProcess != null && (dumpPackage == null
+                || mPreviousProcess.pkgList.containsKey(dumpPackage))) {
+            if (needSep) {
+                pw.println();
+                needSep = false;
+            }
+            pw.println("  mPreviousProcess: " + mPreviousProcess);
+        }
+        if (dumpAll) {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("  mPreviousProcessVisibleTime: ");
+            TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb);
+            pw.println(sb);
+        }
+        if (mHeavyWeightProcess != null && (dumpPackage == null
+                || mHeavyWeightProcess.pkgList.containsKey(dumpPackage))) {
+            if (needSep) {
+                pw.println();
+                needSep = false;
+            }
+            pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
+        }
+        if (dumpPackage == null) {
+            pw.println("  mConfiguration: " + mConfiguration);
+        }
+        if (dumpAll) {
+            pw.println("  mConfigWillChange: " + getFocusedStack().mConfigWillChange);
+            if (mCompatModePackages.getPackages().size() > 0) {
+                boolean printed = false;
+                for (Map.Entry<String, Integer> entry
+                        : mCompatModePackages.getPackages().entrySet()) {
+                    String pkg = entry.getKey();
+                    int mode = entry.getValue();
+                    if (dumpPackage != null && !dumpPackage.equals(pkg)) {
+                        continue;
+                    }
+                    if (!printed) {
+                        pw.println("  mScreenCompatPackages:");
+                        printed = true;
+                    }
+                    pw.print("    "); pw.print(pkg); pw.print(": ");
+                            pw.print(mode); pw.println();
+                }
+            }
+        }
+        if (dumpPackage == null) {
+            if (mSleeping || mWentToSleep || mLockScreenShown) {
+                pw.println("  mSleeping=" + mSleeping + " mWentToSleep=" + mWentToSleep
+                        + " mLockScreenShown " + mLockScreenShown);
+            }
+            if (mShuttingDown) {
+                pw.println("  mShuttingDown=" + mShuttingDown);
+            }
+        }
+        if (mDebugApp != null || mOrigDebugApp != null || mDebugTransient
+                || mOrigWaitForDebugger) {
+            if (dumpPackage == null || dumpPackage.equals(mDebugApp)
+                    || dumpPackage.equals(mOrigDebugApp)) {
+                if (needSep) {
+                    pw.println();
+                    needSep = false;
+                }
+                pw.println("  mDebugApp=" + mDebugApp + "/orig=" + mOrigDebugApp
+                        + " mDebugTransient=" + mDebugTransient
+                        + " mOrigWaitForDebugger=" + mOrigWaitForDebugger);
+            }
+        }
+        if (mOpenGlTraceApp != null) {
+            if (dumpPackage == null || dumpPackage.equals(mOpenGlTraceApp)) {
+                if (needSep) {
+                    pw.println();
+                    needSep = false;
+                }
+                pw.println("  mOpenGlTraceApp=" + mOpenGlTraceApp);
+            }
+        }
+        if (mProfileApp != null || mProfileProc != null || mProfileFile != null
+                || mProfileFd != null) {
+            if (dumpPackage == null || dumpPackage.equals(mProfileApp)) {
+                if (needSep) {
+                    pw.println();
+                    needSep = false;
+                }
+                pw.println("  mProfileApp=" + mProfileApp + " mProfileProc=" + mProfileProc);
+                pw.println("  mProfileFile=" + mProfileFile + " mProfileFd=" + mProfileFd);
+                pw.println("  mProfileType=" + mProfileType + " mAutoStopProfiler="
+                        + mAutoStopProfiler);
+            }
+        }
+        if (dumpPackage == null) {
+            if (mAlwaysFinishActivities || mController != null) {
+                pw.println("  mAlwaysFinishActivities=" + mAlwaysFinishActivities
+                        + " mController=" + mController);
+            }
+            if (dumpAll) {
+                pw.println("  Total persistent processes: " + numPers);
+                pw.println("  mStartRunning=" + mStartRunning
+                        + " mProcessesReady=" + mProcessesReady
+                        + " mSystemReady=" + mSystemReady);
+                pw.println("  mBooting=" + mBooting
+                        + " mBooted=" + mBooted
+                        + " mFactoryTest=" + mFactoryTest);
+                pw.print("  mLastPowerCheckRealtime=");
+                        TimeUtils.formatDuration(mLastPowerCheckRealtime, pw);
+                        pw.println("");
+                pw.print("  mLastPowerCheckUptime=");
+                        TimeUtils.formatDuration(mLastPowerCheckUptime, pw);
+                        pw.println("");
+                pw.println("  mGoingToSleep=" + mStackSupervisor.mGoingToSleep);
+                pw.println("  mLaunchingActivity=" + mStackSupervisor.mLaunchingActivity);
+                pw.println("  mAdjSeq=" + mAdjSeq + " mLruSeq=" + mLruSeq);
+                pw.println("  mNumNonCachedProcs=" + mNumNonCachedProcs
+                        + " (" + mLruProcesses.size() + " total)"
+                        + " mNumCachedHiddenProcs=" + mNumCachedHiddenProcs
+                        + " mNumServiceProcs=" + mNumServiceProcs
+                        + " mNewNumServiceProcs=" + mNewNumServiceProcs);
+                pw.println("  mAllowLowerMemLevel=" + mAllowLowerMemLevel
+                        + " mLastMemoryLevel" + mLastMemoryLevel
+                        + " mLastNumProcesses" + mLastNumProcesses);
+                long now = SystemClock.uptimeMillis();
+                pw.print("  mLastIdleTime=");
+                        TimeUtils.formatDuration(now, mLastIdleTime, pw);
+                        pw.print(" mLowRamSinceLastIdle=");
+                        TimeUtils.formatDuration(getLowRamTimeSinceIdle(now), pw);
+                        pw.println();
+            }
+        }
+
+        if (!printedAnything) {
+            pw.println("  (nothing)");
+        }
+    }
+
+    boolean dumpProcessesToGc(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean needSep, boolean dumpAll, String dumpPackage) {
+        if (mProcessesToGc.size() > 0) {
+            boolean printed = false;
+            long now = SystemClock.uptimeMillis();
+            for (int i=0; i<mProcessesToGc.size(); i++) {
+                ProcessRecord proc = mProcessesToGc.get(i);
+                if (dumpPackage != null && !dumpPackage.equals(proc.info.packageName)) {
+                    continue;
+                }
+                if (!printed) {
+                    if (needSep) pw.println();
+                    needSep = true;
+                    pw.println("  Processes that are waiting to GC:");
+                    printed = true;
+                }
+                pw.print("    Process "); pw.println(proc);
+                pw.print("      lowMem="); pw.print(proc.reportLowMemory);
+                        pw.print(", last gced=");
+                        pw.print(now-proc.lastRequestedGc);
+                        pw.print(" ms ago, last lowMem=");
+                        pw.print(now-proc.lastLowMemory);
+                        pw.println(" ms ago");
+
+            }
+        }
+        return needSep;
+    }
+
+    void printOomLevel(PrintWriter pw, String name, int adj) {
+        pw.print("    ");
+        if (adj >= 0) {
+            pw.print(' ');
+            if (adj < 10) pw.print(' ');
+        } else {
+            if (adj > -10) pw.print(' ');
+        }
+        pw.print(adj);
+        pw.print(": ");
+        pw.print(name);
+        pw.print(" (");
+        pw.print(mProcessList.getMemLevel(adj)/1024);
+        pw.println(" kB)");
+    }
+
+    boolean dumpOomLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll) {
+        boolean needSep = false;
+
+        if (mLruProcesses.size() > 0) {
+            if (needSep) pw.println();
+            needSep = true;
+            pw.println("  OOM levels:");
+            printOomLevel(pw, "SYSTEM_ADJ", ProcessList.SYSTEM_ADJ);
+            printOomLevel(pw, "PERSISTENT_PROC_ADJ", ProcessList.PERSISTENT_PROC_ADJ);
+            printOomLevel(pw, "FOREGROUND_APP_ADJ", ProcessList.FOREGROUND_APP_ADJ);
+            printOomLevel(pw, "VISIBLE_APP_ADJ", ProcessList.VISIBLE_APP_ADJ);
+            printOomLevel(pw, "PERCEPTIBLE_APP_ADJ", ProcessList.PERCEPTIBLE_APP_ADJ);
+            printOomLevel(pw, "BACKUP_APP_ADJ", ProcessList.BACKUP_APP_ADJ);
+            printOomLevel(pw, "HEAVY_WEIGHT_APP_ADJ", ProcessList.HEAVY_WEIGHT_APP_ADJ);
+            printOomLevel(pw, "SERVICE_ADJ", ProcessList.SERVICE_ADJ);
+            printOomLevel(pw, "HOME_APP_ADJ", ProcessList.HOME_APP_ADJ);
+            printOomLevel(pw, "PREVIOUS_APP_ADJ", ProcessList.PREVIOUS_APP_ADJ);
+            printOomLevel(pw, "SERVICE_B_ADJ", ProcessList.SERVICE_B_ADJ);
+            printOomLevel(pw, "CACHED_APP_MIN_ADJ", ProcessList.CACHED_APP_MIN_ADJ);
+            printOomLevel(pw, "CACHED_APP_MAX_ADJ", ProcessList.CACHED_APP_MAX_ADJ);
+
+            if (needSep) pw.println();
+            pw.print("  Process OOM control ("); pw.print(mLruProcesses.size());
+                    pw.print(" total, non-act at ");
+                    pw.print(mLruProcesses.size()-mLruProcessActivityStart);
+                    pw.print(", non-svc at ");
+                    pw.print(mLruProcesses.size()-mLruProcessServiceStart);
+                    pw.println("):");
+            dumpProcessOomList(pw, this, mLruProcesses, "    ", "Proc", "PERS", true, null);
+            needSep = true;
+        }
+
+        dumpProcessesToGc(fd, pw, args, opti, needSep, dumpAll, null);
+
+        pw.println();
+        pw.println("  mHomeProcess: " + mHomeProcess);
+        pw.println("  mPreviousProcess: " + mPreviousProcess);
+        if (mHeavyWeightProcess != null) {
+            pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
+        }
+
+        return true;
+    }
+
+    /**
+     * There are three ways to call this:
+     *  - no provider specified: dump all the providers
+     *  - a flattened component name that matched an existing provider was specified as the
+     *    first arg: dump that one provider
+     *  - the first arg isn't the flattened component name of an existing provider:
+     *    dump all providers whose component contains the first arg as a substring
+     */
+    protected boolean dumpProvider(FileDescriptor fd, PrintWriter pw, String name, String[] args,
+            int opti, boolean dumpAll) {
+        return mProviderMap.dumpProvider(fd, pw, name, args, opti, dumpAll);
+    }
+
+    static class ItemMatcher {
+        ArrayList<ComponentName> components;
+        ArrayList<String> strings;
+        ArrayList<Integer> objects;
+        boolean all;
+        
+        ItemMatcher() {
+            all = true;
+        }
+
+        void build(String name) {
+            ComponentName componentName = ComponentName.unflattenFromString(name);
+            if (componentName != null) {
+                if (components == null) {
+                    components = new ArrayList<ComponentName>();
+                }
+                components.add(componentName);
+                all = false;
+            } else {
+                int objectId = 0;
+                // Not a '/' separated full component name; maybe an object ID?
+                try {
+                    objectId = Integer.parseInt(name, 16);
+                    if (objects == null) {
+                        objects = new ArrayList<Integer>();
+                    }
+                    objects.add(objectId);
+                    all = false;
+                } catch (RuntimeException e) {
+                    // Not an integer; just do string match.
+                    if (strings == null) {
+                        strings = new ArrayList<String>();
+                    }
+                    strings.add(name);
+                    all = false;
+                }
+            }
+        }
+
+        int build(String[] args, int opti) {
+            for (; opti<args.length; opti++) {
+                String name = args[opti];
+                if ("--".equals(name)) {
+                    return opti+1;
+                }
+                build(name);
+            }
+            return opti;
+        }
+
+        boolean match(Object object, ComponentName comp) {
+            if (all) {
+                return true;
+            }
+            if (components != null) {
+                for (int i=0; i<components.size(); i++) {
+                    if (components.get(i).equals(comp)) {
+                        return true;
+                    }
+                }
+            }
+            if (objects != null) {
+                for (int i=0; i<objects.size(); i++) {
+                    if (System.identityHashCode(object) == objects.get(i)) {
+                        return true;
+                    }
+                }
+            }
+            if (strings != null) {
+                String flat = comp.flattenToString();
+                for (int i=0; i<strings.size(); i++) {
+                    if (flat.contains(strings.get(i))) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+    }
+
+    /**
+     * There are three things that cmd can be:
+     *  - a flattened component name that matches an existing activity
+     *  - the cmd arg isn't the flattened component name of an existing activity:
+     *    dump all activity whose component contains the cmd as a substring
+     *  - A hex number of the ActivityRecord object instance.
+     */
+    protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args,
+            int opti, boolean dumpAll) {
+        ArrayList<ActivityRecord> activities;
+        
+        synchronized (this) {
+            activities = mStackSupervisor.getDumpActivitiesLocked(name);
+        }
+
+        if (activities.size() <= 0) {
+            return false;
+        }
+
+        String[] newArgs = new String[args.length - opti];
+        System.arraycopy(args, opti, newArgs, 0, args.length - opti);
+
+        TaskRecord lastTask = null;
+        boolean needSep = false;
+        for (int i=activities.size()-1; i>=0; i--) {
+            ActivityRecord r = activities.get(i);
+            if (needSep) {
+                pw.println();
+            }
+            needSep = true;
+            synchronized (this) {
+                if (lastTask != r.task) {
+                    lastTask = r.task;
+                    pw.print("TASK "); pw.print(lastTask.affinity);
+                            pw.print(" id="); pw.println(lastTask.taskId);
+                    if (dumpAll) {
+                        lastTask.dump(pw, "  ");
+                    }
+                }
+            }
+            dumpActivity("  ", fd, pw, activities.get(i), newArgs, dumpAll);
+        }
+        return true;
+    }
+
+    /**
+     * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if
+     * there is a thread associated with the activity.
+     */
+    private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw,
+            final ActivityRecord r, String[] args, boolean dumpAll) {
+        String innerPrefix = prefix + "  ";
+        synchronized (this) {
+            pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName);
+                    pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r)));
+                    pw.print(" pid=");
+                    if (r.app != null) pw.println(r.app.pid);
+                    else pw.println("(not running)");
+            if (dumpAll) {
+                r.dump(pw, innerPrefix);
+            }
+        }
+        if (r.app != null && r.app.thread != null) {
+            // flush anything that is already in the PrintWriter since the thread is going
+            // to write to the file descriptor directly
+            pw.flush();
+            try {
+                TransferPipe tp = new TransferPipe();
+                try {
+                    r.app.thread.dumpActivity(tp.getWriteFd().getFileDescriptor(),
+                            r.appToken, innerPrefix, args);
+                    tp.go(fd);
+                } finally {
+                    tp.kill();
+                }
+            } catch (IOException e) {
+                pw.println(innerPrefix + "Failure while dumping the activity: " + e);
+            } catch (RemoteException e) {
+                pw.println(innerPrefix + "Got a RemoteException while dumping the activity");
+            }
+        }
+    }
+
+    void dumpBroadcastsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, String dumpPackage) {
+        boolean needSep = false;
+        boolean onlyHistory = false;
+        boolean printedAnything = false;
+
+        if ("history".equals(dumpPackage)) {
+            if (opti < args.length && "-s".equals(args[opti])) {
+                dumpAll = false;
+            }
+            onlyHistory = true;
+            dumpPackage = null;
+        }
+
+        pw.println("ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)");
+        if (!onlyHistory && dumpAll) {
+            if (mRegisteredReceivers.size() > 0) {
+                boolean printed = false;
+                Iterator it = mRegisteredReceivers.values().iterator();
+                while (it.hasNext()) {
+                    ReceiverList r = (ReceiverList)it.next();
+                    if (dumpPackage != null && (r.app == null ||
+                            !dumpPackage.equals(r.app.info.packageName))) {
+                        continue;
+                    }
+                    if (!printed) {
+                        pw.println("  Registered Receivers:");
+                        needSep = true;
+                        printed = true;
+                        printedAnything = true;
+                    }
+                    pw.print("  * "); pw.println(r);
+                    r.dump(pw, "    ");
+                }
+            }
+
+            if (mReceiverResolver.dump(pw, needSep ?
+                    "\n  Receiver Resolver Table:" : "  Receiver Resolver Table:",
+                    "    ", dumpPackage, false)) {
+                needSep = true;
+                printedAnything = true;
+            }
+        }
+
+        for (BroadcastQueue q : mBroadcastQueues) {
+            needSep = q.dumpLocked(fd, pw, args, opti, dumpAll, dumpPackage, needSep);
+            printedAnything |= needSep;
+        }
+
+        needSep = true;
+        
+        if (!onlyHistory && mStickyBroadcasts != null && dumpPackage == null) {
+            for (int user=0; user<mStickyBroadcasts.size(); user++) {
+                if (needSep) {
+                    pw.println();
+                }
+                needSep = true;
+                printedAnything = true;
+                pw.print("  Sticky broadcasts for user ");
+                        pw.print(mStickyBroadcasts.keyAt(user)); pw.println(":");
+                StringBuilder sb = new StringBuilder(128);
+                for (Map.Entry<String, ArrayList<Intent>> ent
+                        : mStickyBroadcasts.valueAt(user).entrySet()) {
+                    pw.print("  * Sticky action "); pw.print(ent.getKey());
+                    if (dumpAll) {
+                        pw.println(":");
+                        ArrayList<Intent> intents = ent.getValue();
+                        final int N = intents.size();
+                        for (int i=0; i<N; i++) {
+                            sb.setLength(0);
+                            sb.append("    Intent: ");
+                            intents.get(i).toShortString(sb, false, true, false, false);
+                            pw.println(sb.toString());
+                            Bundle bundle = intents.get(i).getExtras();
+                            if (bundle != null) {
+                                pw.print("      ");
+                                pw.println(bundle.toString());
+                            }
+                        }
+                    } else {
+                        pw.println("");
+                    }
+                }
+            }
+        }
+        
+        if (!onlyHistory && dumpAll) {
+            pw.println();
+            for (BroadcastQueue queue : mBroadcastQueues) {
+                pw.println("  mBroadcastsScheduled [" + queue.mQueueName + "]="
+                        + queue.mBroadcastsScheduled);
+            }
+            pw.println("  mHandler:");
+            mHandler.dump(new PrintWriterPrinter(pw), "    ");
+            needSep = true;
+            printedAnything = true;
+        }
+        
+        if (!printedAnything) {
+            pw.println("  (nothing)");
+        }
+    }
+
+    void dumpProvidersLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, String dumpPackage) {
+        boolean needSep;
+        boolean printedAnything = false;
+
+        ItemMatcher matcher = new ItemMatcher();
+        matcher.build(args, opti);
+
+        pw.println("ACTIVITY MANAGER CONTENT PROVIDERS (dumpsys activity providers)");
+
+        needSep = mProviderMap.dumpProvidersLocked(pw, dumpAll, dumpPackage);
+        printedAnything |= needSep;
+
+        if (mLaunchingProviders.size() > 0) {
+            boolean printed = false;
+            for (int i=mLaunchingProviders.size()-1; i>=0; i--) {
+                ContentProviderRecord r = mLaunchingProviders.get(i);
+                if (dumpPackage != null && !dumpPackage.equals(r.name.getPackageName())) {
+                    continue;
+                }
+                if (!printed) {
+                    if (needSep) pw.println();
+                    needSep = true;
+                    pw.println("  Launching content providers:");
+                    printed = true;
+                    printedAnything = true;
+                }
+                pw.print("  Launching #"); pw.print(i); pw.print(": ");
+                        pw.println(r);
+            }
+        }
+
+        if (mGrantedUriPermissions.size() > 0) {
+            boolean printed = false;
+            int dumpUid = -2;
+            if (dumpPackage != null) {
+                try {
+                    dumpUid = mContext.getPackageManager().getPackageUid(dumpPackage, 0);
+                } catch (NameNotFoundException e) {
+                    dumpUid = -1;
+                }
+            }
+            for (int i=0; i<mGrantedUriPermissions.size(); i++) {
+                int uid = mGrantedUriPermissions.keyAt(i);
+                if (dumpUid >= -1 && UserHandle.getAppId(uid) != dumpUid) {
+                    continue;
+                }
+                ArrayMap<Uri, UriPermission> perms
+                        = mGrantedUriPermissions.valueAt(i);
+                if (!printed) {
+                    if (needSep) pw.println();
+                    needSep = true;
+                    pw.println("  Granted Uri Permissions:");
+                    printed = true;
+                    printedAnything = true;
+                }
+                pw.print("  * UID "); pw.print(uid);
+                        pw.println(" holds:");
+                for (UriPermission perm : perms.values()) {
+                    pw.print("    "); pw.println(perm);
+                    if (dumpAll) {
+                        perm.dump(pw, "      ");
+                    }
+                }
+            }
+        }
+
+        if (!printedAnything) {
+            pw.println("  (nothing)");
+        }
+    }
+
+    void dumpPendingIntentsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, String dumpPackage) {
+        boolean printed = false;
+
+        pw.println("ACTIVITY MANAGER PENDING INTENTS (dumpsys activity intents)");
+
+        if (mIntentSenderRecords.size() > 0) {
+            Iterator<WeakReference<PendingIntentRecord>> it
+                    = mIntentSenderRecords.values().iterator();
+            while (it.hasNext()) {
+                WeakReference<PendingIntentRecord> ref = it.next();
+                PendingIntentRecord rec = ref != null ? ref.get(): null;
+                if (dumpPackage != null && (rec == null
+                        || !dumpPackage.equals(rec.key.packageName))) {
+                    continue;
+                }
+                printed = true;
+                if (rec != null) {
+                    pw.print("  * "); pw.println(rec);
+                    if (dumpAll) {
+                        rec.dump(pw, "    ");
+                    }
+                } else {
+                    pw.print("  * "); pw.println(ref);
+                }
+            }
+        }
+
+        if (!printed) {
+            pw.println("  (nothing)");
+        }
+    }
+
+    private static final int dumpProcessList(PrintWriter pw,
+            ActivityManagerService service, List list,
+            String prefix, String normalLabel, String persistentLabel,
+            String dumpPackage) {
+        int numPers = 0;
+        final int N = list.size()-1;
+        for (int i=N; i>=0; i--) {
+            ProcessRecord r = (ProcessRecord)list.get(i);
+            if (dumpPackage != null && !dumpPackage.equals(r.info.packageName)) {
+                continue;
+            }
+            pw.println(String.format("%s%s #%2d: %s",
+                    prefix, (r.persistent ? persistentLabel : normalLabel),
+                    i, r.toString()));
+            if (r.persistent) {
+                numPers++;
+            }
+        }
+        return numPers;
+    }
+
+    private static final boolean dumpProcessOomList(PrintWriter pw,
+            ActivityManagerService service, List<ProcessRecord> origList,
+            String prefix, String normalLabel, String persistentLabel,
+            boolean inclDetails, String dumpPackage) {
+
+        ArrayList<Pair<ProcessRecord, Integer>> list
+                = new ArrayList<Pair<ProcessRecord, Integer>>(origList.size());
+        for (int i=0; i<origList.size(); i++) {
+            ProcessRecord r = origList.get(i);
+            if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
+                continue;
+            }
+            list.add(new Pair<ProcessRecord, Integer>(origList.get(i), i));
+        }
+
+        if (list.size() <= 0) {
+            return false;
+        }
+
+        Comparator<Pair<ProcessRecord, Integer>> comparator
+                = new Comparator<Pair<ProcessRecord, Integer>>() {
+            @Override
+            public int compare(Pair<ProcessRecord, Integer> object1,
+                    Pair<ProcessRecord, Integer> object2) {
+                if (object1.first.setAdj != object2.first.setAdj) {
+                    return object1.first.setAdj > object2.first.setAdj ? -1 : 1;
+                }
+                if (object1.second.intValue() != object2.second.intValue()) {
+                    return object1.second.intValue() > object2.second.intValue() ? -1 : 1;
+                }
+                return 0;
+            }
+        };
+
+        Collections.sort(list, comparator);
+
+        final long curRealtime = SystemClock.elapsedRealtime();
+        final long realtimeSince = curRealtime - service.mLastPowerCheckRealtime;
+        final long curUptime = SystemClock.uptimeMillis();
+        final long uptimeSince = curUptime - service.mLastPowerCheckUptime;
+
+        for (int i=list.size()-1; i>=0; i--) {
+            ProcessRecord r = list.get(i).first;
+            String oomAdj = ProcessList.makeOomAdjString(r.setAdj);
+            char schedGroup;
+            switch (r.setSchedGroup) {
+                case Process.THREAD_GROUP_BG_NONINTERACTIVE:
+                    schedGroup = 'B';
+                    break;
+                case Process.THREAD_GROUP_DEFAULT:
+                    schedGroup = 'F';
+                    break;
+                default:
+                    schedGroup = '?';
+                    break;
+            }
+            char foreground;
+            if (r.foregroundActivities) {
+                foreground = 'A';
+            } else if (r.foregroundServices) {
+                foreground = 'S';
+            } else {
+                foreground = ' ';
+            }
+            String procState = ProcessList.makeProcStateString(r.curProcState);
+            pw.print(prefix);
+            pw.print(r.persistent ? persistentLabel : normalLabel);
+            pw.print(" #");
+            int num = (origList.size()-1)-list.get(i).second;
+            if (num < 10) pw.print(' ');
+            pw.print(num);
+            pw.print(": ");
+            pw.print(oomAdj);
+            pw.print(' ');
+            pw.print(schedGroup);
+            pw.print('/');
+            pw.print(foreground);
+            pw.print('/');
+            pw.print(procState);
+            pw.print(" trm:");
+            if (r.trimMemoryLevel < 10) pw.print(' ');
+            pw.print(r.trimMemoryLevel);
+            pw.print(' ');
+            pw.print(r.toShortString());
+            pw.print(" (");
+            pw.print(r.adjType);
+            pw.println(')');
+            if (r.adjSource != null || r.adjTarget != null) {
+                pw.print(prefix);
+                pw.print("    ");
+                if (r.adjTarget instanceof ComponentName) {
+                    pw.print(((ComponentName)r.adjTarget).flattenToShortString());
+                } else if (r.adjTarget != null) {
+                    pw.print(r.adjTarget.toString());
+                } else {
+                    pw.print("{null}");
+                }
+                pw.print("<=");
+                if (r.adjSource instanceof ProcessRecord) {
+                    pw.print("Proc{");
+                    pw.print(((ProcessRecord)r.adjSource).toShortString());
+                    pw.println("}");
+                } else if (r.adjSource != null) {
+                    pw.println(r.adjSource.toString());
+                } else {
+                    pw.println("{null}");
+                }
+            }
+            if (inclDetails) {
+                pw.print(prefix);
+                pw.print("    ");
+                pw.print("oom: max="); pw.print(r.maxAdj);
+                pw.print(" curRaw="); pw.print(r.curRawAdj);
+                pw.print(" setRaw="); pw.print(r.setRawAdj);
+                pw.print(" cur="); pw.print(r.curAdj);
+                pw.print(" set="); pw.println(r.setAdj);
+                pw.print(prefix);
+                pw.print("    ");
+                pw.print("state: cur="); pw.print(ProcessList.makeProcStateString(r.curProcState));
+                pw.print(" set="); pw.print(ProcessList.makeProcStateString(r.setProcState));
+                pw.print(" lastPss="); pw.print(r.lastPss);
+                pw.print(" lastCachedPss="); pw.println(r.lastCachedPss);
+                pw.print(prefix);
+                pw.print("    ");
+                pw.print("keeping="); pw.print(r.keeping);
+                pw.print(" cached="); pw.print(r.cached);
+                pw.print(" empty="); pw.print(r.empty);
+                pw.print(" hasAboveClient="); pw.println(r.hasAboveClient);
+
+                if (!r.keeping) {
+                    if (r.lastWakeTime != 0) {
+                        long wtime;
+                        BatteryStatsImpl stats = service.mBatteryStatsService.getActiveStatistics();
+                        synchronized (stats) {
+                            wtime = stats.getProcessWakeTime(r.info.uid,
+                                    r.pid, curRealtime);
+                        }
+                        long timeUsed = wtime - r.lastWakeTime;
+                        pw.print(prefix);
+                        pw.print("    ");
+                        pw.print("keep awake over ");
+                        TimeUtils.formatDuration(realtimeSince, pw);
+                        pw.print(" used ");
+                        TimeUtils.formatDuration(timeUsed, pw);
+                        pw.print(" (");
+                        pw.print((timeUsed*100)/realtimeSince);
+                        pw.println("%)");
+                    }
+                    if (r.lastCpuTime != 0) {
+                        long timeUsed = r.curCpuTime - r.lastCpuTime;
+                        pw.print(prefix);
+                        pw.print("    ");
+                        pw.print("run cpu over ");
+                        TimeUtils.formatDuration(uptimeSince, pw);
+                        pw.print(" used ");
+                        TimeUtils.formatDuration(timeUsed, pw);
+                        pw.print(" (");
+                        pw.print((timeUsed*100)/uptimeSince);
+                        pw.println("%)");
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+    ArrayList<ProcessRecord> collectProcesses(PrintWriter pw, int start, String[] args) {
+        ArrayList<ProcessRecord> procs;
+        synchronized (this) {
+            if (args != null && args.length > start
+                    && args[start].charAt(0) != '-') {
+                procs = new ArrayList<ProcessRecord>();
+                int pid = -1;
+                try {
+                    pid = Integer.parseInt(args[start]);
+                } catch (NumberFormatException e) {
+                }
+                for (int i=mLruProcesses.size()-1; i>=0; i--) {
+                    ProcessRecord proc = mLruProcesses.get(i);
+                    if (proc.pid == pid) {
+                        procs.add(proc);
+                    } else if (proc.processName.equals(args[start])) {
+                        procs.add(proc);
+                    }
+                }
+                if (procs.size() <= 0) {
+                    return null;
+                }
+            } else {
+                procs = new ArrayList<ProcessRecord>(mLruProcesses);
+            }
+        }
+        return procs;
+    }
+
+    final void dumpGraphicsHardwareUsage(FileDescriptor fd,
+            PrintWriter pw, String[] args) {
+        ArrayList<ProcessRecord> procs = collectProcesses(pw, 0, args);
+        if (procs == null) {
+            pw.println("No process found for: " + args[0]);
+            return;
+        }
+
+        long uptime = SystemClock.uptimeMillis();
+        long realtime = SystemClock.elapsedRealtime();
+        pw.println("Applications Graphics Acceleration Info:");
+        pw.println("Uptime: " + uptime + " Realtime: " + realtime);
+        
+        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
+            ProcessRecord r = procs.get(i);
+            if (r.thread != null) {
+                pw.println("\n** Graphics info for pid " + r.pid + " [" + r.processName + "] **");
+                pw.flush();
+                try {
+                    TransferPipe tp = new TransferPipe();
+                    try {
+                        r.thread.dumpGfxInfo(tp.getWriteFd().getFileDescriptor(), args);
+                        tp.go(fd);
+                    } finally {
+                        tp.kill();
+                    }
+                } catch (IOException e) {
+                    pw.println("Failure while dumping the app: " + r);
+                    pw.flush();
+                } catch (RemoteException e) {
+                    pw.println("Got a RemoteException while dumping the app " + r);
+                    pw.flush();
+                }
+            }
+        }
+    }
+
+    final void dumpDbInfo(FileDescriptor fd, PrintWriter pw, String[] args) {
+        ArrayList<ProcessRecord> procs = collectProcesses(pw, 0, args);
+        if (procs == null) {
+            pw.println("No process found for: " + args[0]);
+            return;
+        }
+
+        pw.println("Applications Database Info:");
+
+        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
+            ProcessRecord r = procs.get(i);
+            if (r.thread != null) {
+                pw.println("\n** Database info for pid " + r.pid + " [" + r.processName + "] **");
+                pw.flush();
+                try {
+                    TransferPipe tp = new TransferPipe();
+                    try {
+                        r.thread.dumpDbInfo(tp.getWriteFd().getFileDescriptor(), args);
+                        tp.go(fd);
+                    } finally {
+                        tp.kill();
+                    }
+                } catch (IOException e) {
+                    pw.println("Failure while dumping the app: " + r);
+                    pw.flush();
+                } catch (RemoteException e) {
+                    pw.println("Got a RemoteException while dumping the app " + r);
+                    pw.flush();
+                }
+            }
+        }
+    }
+
+    final static class MemItem {
+        final boolean isProc;
+        final String label;
+        final String shortLabel;
+        final long pss;
+        final int id;
+        final boolean hasActivities;
+        ArrayList<MemItem> subitems;
+
+        public MemItem(String _label, String _shortLabel, long _pss, int _id,
+                boolean _hasActivities) {
+            isProc = true;
+            label = _label;
+            shortLabel = _shortLabel;
+            pss = _pss;
+            id = _id;
+            hasActivities = _hasActivities;
+        }
+
+        public MemItem(String _label, String _shortLabel, long _pss, int _id) {
+            isProc = false;
+            label = _label;
+            shortLabel = _shortLabel;
+            pss = _pss;
+            id = _id;
+            hasActivities = false;
+        }
+    }
+
+    static final void dumpMemItems(PrintWriter pw, String prefix, String tag,
+            ArrayList<MemItem> items, boolean sort, boolean isCompact) {
+        if (sort && !isCompact) {
+            Collections.sort(items, new Comparator<MemItem>() {
+                @Override
+                public int compare(MemItem lhs, MemItem rhs) {
+                    if (lhs.pss < rhs.pss) {
+                        return 1;
+                    } else if (lhs.pss > rhs.pss) {
+                        return -1;
+                    }
+                    return 0;
+                }
+            });
+        }
+
+        for (int i=0; i<items.size(); i++) {
+            MemItem mi = items.get(i);
+            if (!isCompact) {
+                pw.print(prefix); pw.printf("%7d kB: ", mi.pss); pw.println(mi.label);
+            } else if (mi.isProc) {
+                pw.print("proc,"); pw.print(tag); pw.print(","); pw.print(mi.shortLabel);
+                pw.print(","); pw.print(mi.id); pw.print(","); pw.print(mi.pss);
+                pw.println(mi.hasActivities ? ",a" : ",e");
+            } else {
+                pw.print(tag); pw.print(","); pw.print(mi.shortLabel); pw.print(",");
+                pw.println(mi.pss);
+            }
+            if (mi.subitems != null) {
+                dumpMemItems(pw, prefix + "           ", mi.shortLabel, mi.subitems,
+                        true, isCompact);
+            }
+        }
+    }
+
+    // These are in KB.
+    static final long[] DUMP_MEM_BUCKETS = new long[] {
+        5*1024, 7*1024, 10*1024, 15*1024, 20*1024, 30*1024, 40*1024, 80*1024,
+        120*1024, 160*1024, 200*1024,
+        250*1024, 300*1024, 350*1024, 400*1024, 500*1024, 600*1024, 800*1024,
+        1*1024*1024, 2*1024*1024, 5*1024*1024, 10*1024*1024, 20*1024*1024
+    };
+
+    static final void appendMemBucket(StringBuilder out, long memKB, String label,
+            boolean stackLike) {
+        int start = label.lastIndexOf('.');
+        if (start >= 0) start++;
+        else start = 0;
+        int end = label.length();
+        for (int i=0; i<DUMP_MEM_BUCKETS.length; i++) {
+            if (DUMP_MEM_BUCKETS[i] >= memKB) {
+                long bucket = DUMP_MEM_BUCKETS[i]/1024;
+                out.append(bucket);
+                out.append(stackLike ? "MB." : "MB ");
+                out.append(label, start, end);
+                return;
+            }
+        }
+        out.append(memKB/1024);
+        out.append(stackLike ? "MB." : "MB ");
+        out.append(label, start, end);
+    }
+
+    static final int[] DUMP_MEM_OOM_ADJ = new int[] {
+            ProcessList.NATIVE_ADJ,
+            ProcessList.SYSTEM_ADJ, ProcessList.PERSISTENT_PROC_ADJ, ProcessList.FOREGROUND_APP_ADJ,
+            ProcessList.VISIBLE_APP_ADJ, ProcessList.PERCEPTIBLE_APP_ADJ,
+            ProcessList.BACKUP_APP_ADJ, ProcessList.HEAVY_WEIGHT_APP_ADJ,
+            ProcessList.SERVICE_ADJ, ProcessList.HOME_APP_ADJ,
+            ProcessList.PREVIOUS_APP_ADJ, ProcessList.SERVICE_B_ADJ, ProcessList.CACHED_APP_MAX_ADJ
+    };
+    static final String[] DUMP_MEM_OOM_LABEL = new String[] {
+            "Native",
+            "System", "Persistent", "Foreground",
+            "Visible", "Perceptible",
+            "Heavy Weight", "Backup",
+            "A Services", "Home",
+            "Previous", "B Services", "Cached"
+    };
+    static final String[] DUMP_MEM_OOM_COMPACT_LABEL = new String[] {
+            "native",
+            "sys", "pers", "fore",
+            "vis", "percept",
+            "heavy", "backup",
+            "servicea", "home",
+            "prev", "serviceb", "cached"
+    };
+
+    private final void dumpApplicationMemoryUsageHeader(PrintWriter pw, long uptime,
+            long realtime, boolean isCheckinRequest, boolean isCompact) {
+        if (isCheckinRequest || isCompact) {
+            // short checkin version
+            pw.print("time,"); pw.print(uptime); pw.print(","); pw.println(realtime);
+        } else {
+            pw.println("Applications Memory Usage (kB):");
+            pw.println("Uptime: " + uptime + " Realtime: " + realtime);
+        }
+    }
+
+    final void dumpApplicationMemoryUsage(FileDescriptor fd,
+            PrintWriter pw, String prefix, String[] args, boolean brief, PrintWriter categoryPw) {
+        boolean dumpDetails = false;
+        boolean dumpFullDetails = false;
+        boolean dumpDalvik = false;
+        boolean oomOnly = false;
+        boolean isCompact = false;
+        boolean localOnly = false;
+        
+        int opti = 0;
+        while (opti < args.length) {
+            String opt = args[opti];
+            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
+                break;
+            }
+            opti++;
+            if ("-a".equals(opt)) {
+                dumpDetails = true;
+                dumpFullDetails = true;
+                dumpDalvik = true;
+            } else if ("-d".equals(opt)) {
+                dumpDalvik = true;
+            } else if ("-c".equals(opt)) {
+                isCompact = true;
+            } else if ("--oom".equals(opt)) {
+                oomOnly = true;
+            } else if ("--local".equals(opt)) {
+                localOnly = true;
+            } else if ("-h".equals(opt)) {
+                pw.println("meminfo dump options: [-a] [-d] [-c] [--oom] [process]");
+                pw.println("  -a: include all available information for each process.");
+                pw.println("  -d: include dalvik details when dumping process details.");
+                pw.println("  -c: dump in a compact machine-parseable representation.");
+                pw.println("  --oom: only show processes organized by oom adj.");
+                pw.println("  --local: only collect details locally, don't call process.");
+                pw.println("If [process] is specified it can be the name or ");
+                pw.println("pid of a specific process to dump.");
+                return;
+            } else {
+                pw.println("Unknown argument: " + opt + "; use -h for help");
+            }
+        }
+        
+        final boolean isCheckinRequest = scanArgs(args, "--checkin");
+        long uptime = SystemClock.uptimeMillis();
+        long realtime = SystemClock.elapsedRealtime();
+        final long[] tmpLong = new long[1];
+
+        ArrayList<ProcessRecord> procs = collectProcesses(pw, opti, args);
+        if (procs == null) {
+            // No Java processes.  Maybe they want to print a native process.
+            if (args != null && args.length > opti
+                    && args[opti].charAt(0) != '-') {
+                ArrayList<ProcessCpuTracker.Stats> nativeProcs
+                        = new ArrayList<ProcessCpuTracker.Stats>();
+                updateCpuStatsNow();
+                int findPid = -1;
+                try {
+                    findPid = Integer.parseInt(args[opti]);
+                } catch (NumberFormatException e) {
+                }
+                synchronized (mProcessCpuThread) {
+                    final int N = mProcessCpuTracker.countStats();
+                    for (int i=0; i<N; i++) {
+                        ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
+                        if (st.pid == findPid || (st.baseName != null
+                                && st.baseName.equals(args[opti]))) {
+                            nativeProcs.add(st);
+                        }
+                    }
+                }
+                if (nativeProcs.size() > 0) {
+                    dumpApplicationMemoryUsageHeader(pw, uptime, realtime, isCheckinRequest,
+                            isCompact);
+                    Debug.MemoryInfo mi = null;
+                    for (int i = nativeProcs.size() - 1 ; i >= 0 ; i--) {
+                        final ProcessCpuTracker.Stats r = nativeProcs.get(i);
+                        final int pid = r.pid;
+                        if (!isCheckinRequest && dumpDetails) {
+                            pw.println("\n** MEMINFO in pid " + pid + " [" + r.baseName + "] **");
+                        }
+                        if (mi == null) {
+                            mi = new Debug.MemoryInfo();
+                        }
+                        if (dumpDetails || (!brief && !oomOnly)) {
+                            Debug.getMemoryInfo(pid, mi);
+                        } else {
+                            mi.dalvikPss = (int)Debug.getPss(pid, tmpLong);
+                            mi.dalvikPrivateDirty = (int)tmpLong[0];
+                        }
+                        ActivityThread.dumpMemInfoTable(pw, mi, isCheckinRequest, dumpFullDetails,
+                                dumpDalvik, pid, r.baseName, 0, 0, 0, 0, 0, 0);
+                        if (isCheckinRequest) {
+                            pw.println();
+                        }
+                    }
+                    return;
+                }
+            }
+            pw.println("No process found for: " + args[opti]);
+            return;
+        }
+
+        if (!brief && !oomOnly && (procs.size() == 1 || isCheckinRequest)) {
+            dumpDetails = true;
+        }
+
+        dumpApplicationMemoryUsageHeader(pw, uptime, realtime, isCheckinRequest, isCompact);
+
+        String[] innerArgs = new String[args.length-opti];
+        System.arraycopy(args, opti, innerArgs, 0, args.length-opti);
+
+        ArrayList<MemItem> procMems = new ArrayList<MemItem>();
+        final SparseArray<MemItem> procMemsMap = new SparseArray<MemItem>();
+        long nativePss=0, dalvikPss=0, otherPss=0;
+        long[] miscPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS];
+
+        long oomPss[] = new long[DUMP_MEM_OOM_LABEL.length];
+        ArrayList<MemItem>[] oomProcs = (ArrayList<MemItem>[])
+                new ArrayList[DUMP_MEM_OOM_LABEL.length];
+
+        long totalPss = 0;
+        long cachedPss = 0;
+
+        Debug.MemoryInfo mi = null;
+        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
+            final ProcessRecord r = procs.get(i);
+            final IApplicationThread thread;
+            final int pid;
+            final int oomAdj;
+            final boolean hasActivities;
+            synchronized (this) {
+                thread = r.thread;
+                pid = r.pid;
+                oomAdj = r.getSetAdjWithServices();
+                hasActivities = r.activities.size() > 0;
+            }
+            if (thread != null) {
+                if (!isCheckinRequest && dumpDetails) {
+                    pw.println("\n** MEMINFO in pid " + pid + " [" + r.processName + "] **");
+                }
+                if (mi == null) {
+                    mi = new Debug.MemoryInfo();
+                }
+                if (dumpDetails || (!brief && !oomOnly)) {
+                    Debug.getMemoryInfo(pid, mi);
+                } else {
+                    mi.dalvikPss = (int)Debug.getPss(pid, tmpLong);
+                    mi.dalvikPrivateDirty = (int)tmpLong[0];
+                }
+                if (dumpDetails) {
+                    if (localOnly) {
+                        ActivityThread.dumpMemInfoTable(pw, mi, isCheckinRequest, dumpFullDetails,
+                                dumpDalvik, pid, r.processName, 0, 0, 0, 0, 0, 0);
+                        if (isCheckinRequest) {
+                            pw.println();
+                        }
+                    } else {
+                        try {
+                            pw.flush();
+                            thread.dumpMemInfo(fd, mi, isCheckinRequest, dumpFullDetails,
+                                    dumpDalvik, innerArgs);
+                        } catch (RemoteException e) {
+                            if (!isCheckinRequest) {
+                                pw.println("Got RemoteException!");
+                                pw.flush();
+                            }
+                        }
+                    }
+                }
+
+                final long myTotalPss = mi.getTotalPss();
+                final long myTotalUss = mi.getTotalUss();
+
+                synchronized (this) {
+                    if (r.thread != null && oomAdj == r.getSetAdjWithServices()) {
+                        // Record this for posterity if the process has been stable.
+                        r.baseProcessTracker.addPss(myTotalPss, myTotalUss, true, r.pkgList);
+                    }
+                }
+
+                if (!isCheckinRequest && mi != null) {
+                    totalPss += myTotalPss;
+                    MemItem pssItem = new MemItem(r.processName + " (pid " + pid +
+                            (hasActivities ? " / activities)" : ")"),
+                            r.processName, myTotalPss, pid, hasActivities);
+                    procMems.add(pssItem);
+                    procMemsMap.put(pid, pssItem);
+
+                    nativePss += mi.nativePss;
+                    dalvikPss += mi.dalvikPss;
+                    otherPss += mi.otherPss;
+                    for (int j=0; j<Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
+                        long mem = mi.getOtherPss(j);
+                        miscPss[j] += mem;
+                        otherPss -= mem;
+                    }
+
+                    if (oomAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
+                        cachedPss += myTotalPss;
+                    }
+
+                    for (int oomIndex=0; oomIndex<oomPss.length; oomIndex++) {
+                        if (oomAdj <= DUMP_MEM_OOM_ADJ[oomIndex]
+                                || oomIndex == (oomPss.length-1)) {
+                            oomPss[oomIndex] += myTotalPss;
+                            if (oomProcs[oomIndex] == null) {
+                                oomProcs[oomIndex] = new ArrayList<MemItem>();
+                            }
+                            oomProcs[oomIndex].add(pssItem);
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        if (!isCheckinRequest && procs.size() > 1) {
+            // If we are showing aggregations, also look for native processes to
+            // include so that our aggregations are more accurate.
+            updateCpuStatsNow();
+            synchronized (mProcessCpuThread) {
+                final int N = mProcessCpuTracker.countStats();
+                for (int i=0; i<N; i++) {
+                    ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
+                    if (st.vsize > 0 && procMemsMap.indexOfKey(st.pid) < 0) {
+                        if (mi == null) {
+                            mi = new Debug.MemoryInfo();
+                        }
+                        if (!brief && !oomOnly) {
+                            Debug.getMemoryInfo(st.pid, mi);
+                        } else {
+                            mi.nativePss = (int)Debug.getPss(st.pid, tmpLong);
+                            mi.nativePrivateDirty = (int)tmpLong[0];
+                        }
+
+                        final long myTotalPss = mi.getTotalPss();
+                        totalPss += myTotalPss;
+
+                        MemItem pssItem = new MemItem(st.name + " (pid " + st.pid + ")",
+                                st.name, myTotalPss, st.pid, false);
+                        procMems.add(pssItem);
+
+                        nativePss += mi.nativePss;
+                        dalvikPss += mi.dalvikPss;
+                        otherPss += mi.otherPss;
+                        for (int j=0; j<Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
+                            long mem = mi.getOtherPss(j);
+                            miscPss[j] += mem;
+                            otherPss -= mem;
+                        }
+                        oomPss[0] += myTotalPss;
+                        if (oomProcs[0] == null) {
+                            oomProcs[0] = new ArrayList<MemItem>();
+                        }
+                        oomProcs[0].add(pssItem);
+                    }
+                }
+            }
+
+            ArrayList<MemItem> catMems = new ArrayList<MemItem>();
+
+            catMems.add(new MemItem("Native", "Native", nativePss, -1));
+            catMems.add(new MemItem("Dalvik", "Dalvik", dalvikPss, -2));
+            catMems.add(new MemItem("Unknown", "Unknown", otherPss, -3));
+            for (int j=0; j<Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
+                String label = Debug.MemoryInfo.getOtherLabel(j);
+                catMems.add(new MemItem(label, label, miscPss[j], j));
+            }
+
+            ArrayList<MemItem> oomMems = new ArrayList<MemItem>();
+            for (int j=0; j<oomPss.length; j++) {
+                if (oomPss[j] != 0) {
+                    String label = isCompact ? DUMP_MEM_OOM_COMPACT_LABEL[j]
+                            : DUMP_MEM_OOM_LABEL[j];
+                    MemItem item = new MemItem(label, label, oomPss[j],
+                            DUMP_MEM_OOM_ADJ[j]);
+                    item.subitems = oomProcs[j];
+                    oomMems.add(item);
+                }
+            }
+
+            if (!brief && !oomOnly && !isCompact) {
+                pw.println();
+                pw.println("Total PSS by process:");
+                dumpMemItems(pw, "  ", "proc", procMems, true, isCompact);
+                pw.println();
+            }
+            if (!isCompact) {
+                pw.println("Total PSS by OOM adjustment:");
+            }
+            dumpMemItems(pw, "  ", "oom", oomMems, false, isCompact);
+            if (!brief && !oomOnly) {
+                PrintWriter out = categoryPw != null ? categoryPw : pw;
+                if (!isCompact) {
+                    out.println();
+                    out.println("Total PSS by category:");
+                }
+                dumpMemItems(out, "  ", "cat", catMems, true, isCompact);
+            }
+            if (!isCompact) {
+                pw.println();
+            }
+            MemInfoReader memInfo = new MemInfoReader();
+            memInfo.readMemInfo();
+            if (!brief) {
+                if (!isCompact) {
+                    pw.print("Total RAM: "); pw.print(memInfo.getTotalSizeKb());
+                    pw.println(" kB");
+                    pw.print(" Free RAM: "); pw.print(cachedPss + memInfo.getCachedSizeKb()
+                            + memInfo.getFreeSizeKb()); pw.print(" kB (");
+                            pw.print(cachedPss); pw.print(" cached pss + ");
+                            pw.print(memInfo.getCachedSizeKb()); pw.print(" cached + ");
+                            pw.print(memInfo.getFreeSizeKb()); pw.println(" free)");
+                } else {
+                    pw.print("ram,"); pw.print(memInfo.getTotalSizeKb()); pw.print(",");
+                    pw.print(cachedPss + memInfo.getCachedSizeKb()
+                            + memInfo.getFreeSizeKb()); pw.print(",");
+                    pw.println(totalPss - cachedPss);
+                }
+            }
+            if (!isCompact) {
+                pw.print(" Used RAM: "); pw.print(totalPss - cachedPss
+                        + memInfo.getBuffersSizeKb() + memInfo.getShmemSizeKb()
+                        + memInfo.getSlabSizeKb()); pw.print(" kB (");
+                        pw.print(totalPss - cachedPss); pw.print(" used pss + ");
+                        pw.print(memInfo.getBuffersSizeKb()); pw.print(" buffers + ");
+                        pw.print(memInfo.getShmemSizeKb()); pw.print(" shmem + ");
+                        pw.print(memInfo.getSlabSizeKb()); pw.println(" slab)");
+                pw.print(" Lost RAM: "); pw.print(memInfo.getTotalSizeKb()
+                        - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
+                        - memInfo.getBuffersSizeKb() - memInfo.getShmemSizeKb()
+                        - memInfo.getSlabSizeKb()); pw.println(" kB");
+            }
+            if (!brief) {
+                if (memInfo.getZramTotalSizeKb() != 0) {
+                    if (!isCompact) {
+                        pw.print("     ZRAM: "); pw.print(memInfo.getZramTotalSizeKb());
+                                pw.print(" kB physical used for ");
+                                pw.print(memInfo.getSwapTotalSizeKb()
+                                        - memInfo.getSwapFreeSizeKb());
+                                pw.print(" kB in swap (");
+                                pw.print(memInfo.getSwapTotalSizeKb());
+                                pw.println(" kB total swap)");
+                    } else {
+                        pw.print("zram,"); pw.print(memInfo.getZramTotalSizeKb()); pw.print(",");
+                                pw.print(memInfo.getSwapTotalSizeKb()); pw.print(",");
+                                pw.println(memInfo.getSwapFreeSizeKb());
+                    }
+                }
+                final int[] SINGLE_LONG_FORMAT = new int[] {
+                    Process.PROC_SPACE_TERM|Process.PROC_OUT_LONG
+                };
+                long[] longOut = new long[1];
+                Process.readProcFile("/sys/kernel/mm/ksm/pages_shared",
+                        SINGLE_LONG_FORMAT, null, longOut, null);
+                long shared = longOut[0] * ProcessList.PAGE_SIZE / 1024;
+                longOut[0] = 0;
+                Process.readProcFile("/sys/kernel/mm/ksm/pages_sharing",
+                        SINGLE_LONG_FORMAT, null, longOut, null);
+                long sharing = longOut[0] * ProcessList.PAGE_SIZE / 1024;
+                longOut[0] = 0;
+                Process.readProcFile("/sys/kernel/mm/ksm/pages_unshared",
+                        SINGLE_LONG_FORMAT, null, longOut, null);
+                long unshared = longOut[0] * ProcessList.PAGE_SIZE / 1024;
+                longOut[0] = 0;
+                Process.readProcFile("/sys/kernel/mm/ksm/pages_volatile",
+                        SINGLE_LONG_FORMAT, null, longOut, null);
+                long voltile = longOut[0] * ProcessList.PAGE_SIZE / 1024;
+                if (!isCompact) {
+                    if (sharing != 0 || shared != 0 || unshared != 0 || voltile != 0) {
+                        pw.print("      KSM: "); pw.print(sharing);
+                                pw.print(" kB saved from shared ");
+                                pw.print(shared); pw.println(" kB");
+                        pw.print("           "); pw.print(unshared); pw.print(" kB unshared; ");
+                                pw.print(voltile); pw.println(" kB volatile");
+                    }
+                    pw.print("   Tuning: ");
+                    pw.print(ActivityManager.staticGetMemoryClass());
+                    pw.print(" (large ");
+                    pw.print(ActivityManager.staticGetLargeMemoryClass());
+                    pw.print("), oom ");
+                    pw.print(mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024);
+                    pw.print(" kB");
+                    pw.print(", restore limit ");
+                    pw.print(mProcessList.getCachedRestoreThresholdKb());
+                    pw.print(" kB");
+                    if (ActivityManager.isLowRamDeviceStatic()) {
+                        pw.print(" (low-ram)");
+                    }
+                    if (ActivityManager.isHighEndGfx()) {
+                        pw.print(" (high-end-gfx)");
+                    }
+                    pw.println();
+                } else {
+                    pw.print("ksm,"); pw.print(sharing); pw.print(",");
+                    pw.print(shared); pw.print(","); pw.print(unshared); pw.print(",");
+                    pw.println(voltile);
+                    pw.print("tuning,");
+                    pw.print(ActivityManager.staticGetMemoryClass());
+                    pw.print(',');
+                    pw.print(ActivityManager.staticGetLargeMemoryClass());
+                    pw.print(',');
+                    pw.print(mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024);
+                    if (ActivityManager.isLowRamDeviceStatic()) {
+                        pw.print(",low-ram");
+                    }
+                    if (ActivityManager.isHighEndGfx()) {
+                        pw.print(",high-end-gfx");
+                    }
+                    pw.println();
+                }
+            }
+        }
+    }
+
+    /**
+     * Searches array of arguments for the specified string
+     * @param args array of argument strings
+     * @param value value to search for
+     * @return true if the value is contained in the array
+     */
+    private static boolean scanArgs(String[] args, String value) {
+        if (args != null) {
+            for (String arg : args) {
+                if (value.equals(arg)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    private final boolean removeDyingProviderLocked(ProcessRecord proc,
+            ContentProviderRecord cpr, boolean always) {
+        final boolean inLaunching = mLaunchingProviders.contains(cpr);
+
+        if (!inLaunching || always) {
+            synchronized (cpr) {
+                cpr.launchingApp = null;
+                cpr.notifyAll();
+            }
+            mProviderMap.removeProviderByClass(cpr.name, UserHandle.getUserId(cpr.uid));
+            String names[] = cpr.info.authority.split(";");
+            for (int j = 0; j < names.length; j++) {
+                mProviderMap.removeProviderByName(names[j], UserHandle.getUserId(cpr.uid));
+            }
+        }
+
+        for (int i=0; i<cpr.connections.size(); i++) {
+            ContentProviderConnection conn = cpr.connections.get(i);
+            if (conn.waiting) {
+                // If this connection is waiting for the provider, then we don't
+                // need to mess with its process unless we are always removing
+                // or for some reason the provider is not currently launching.
+                if (inLaunching && !always) {
+                    continue;
+                }
+            }
+            ProcessRecord capp = conn.client;
+            conn.dead = true;
+            if (conn.stableCount > 0) {
+                if (!capp.persistent && capp.thread != null
+                        && capp.pid != 0
+                        && capp.pid != MY_PID) {
+                    killUnneededProcessLocked(capp, "depends on provider "
+                            + cpr.name.flattenToShortString()
+                            + " in dying proc " + (proc != null ? proc.processName : "??"));
+                }
+            } else if (capp.thread != null && conn.provider.provider != null) {
+                try {
+                    capp.thread.unstableProviderDied(conn.provider.provider.asBinder());
+                } catch (RemoteException e) {
+                }
+                // In the protocol here, we don't expect the client to correctly
+                // clean up this connection, we'll just remove it.
+                cpr.connections.remove(i);
+                conn.client.conProviders.remove(conn);
+            }
+        }
+
+        if (inLaunching && always) {
+            mLaunchingProviders.remove(cpr);
+        }
+        return inLaunching;
+    }
+
+    /**
+     * Main code for cleaning up a process when it has gone away.  This is
+     * called both as a result of the process dying, or directly when stopping
+     * a process when running in single process mode.
+     */
+    private final void cleanUpApplicationRecordLocked(ProcessRecord app,
+            boolean restarting, boolean allowRestart, int index) {
+        if (index >= 0) {
+            removeLruProcessLocked(app);
+            ProcessList.remove(app.pid);
+        }
+
+        mProcessesToGc.remove(app);
+        mPendingPssProcesses.remove(app);
+
+        // Dismiss any open dialogs.
+        if (app.crashDialog != null && !app.forceCrashReport) {
+            app.crashDialog.dismiss();
+            app.crashDialog = null;
+        }
+        if (app.anrDialog != null) {
+            app.anrDialog.dismiss();
+            app.anrDialog = null;
+        }
+        if (app.waitDialog != null) {
+            app.waitDialog.dismiss();
+            app.waitDialog = null;
+        }
+
+        app.crashing = false;
+        app.notResponding = false;
+
+        app.resetPackageList(mProcessStats);
+        app.unlinkDeathRecipient();
+        app.makeInactive(mProcessStats);
+        app.forcingToForeground = null;
+        app.foregroundServices = false;
+        app.foregroundActivities = false;
+        app.hasShownUi = false;
+        app.hasAboveClient = false;
+
+        mServices.killServicesLocked(app, allowRestart);
+
+        boolean restart = false;
+
+        // Remove published content providers.
+        for (int i=app.pubProviders.size()-1; i>=0; i--) {
+            ContentProviderRecord cpr = app.pubProviders.valueAt(i);
+            final boolean always = app.bad || !allowRestart;
+            if (removeDyingProviderLocked(app, cpr, always) || always) {
+                // We left the provider in the launching list, need to
+                // restart it.
+                restart = true;
+            }
+
+            cpr.provider = null;
+            cpr.proc = null;
+        }
+        app.pubProviders.clear();
+
+        // Take care of any launching providers waiting for this process.
+        if (checkAppInLaunchingProvidersLocked(app, false)) {
+            restart = true;
+        }
+
+        // Unregister from connected content providers.
+        if (!app.conProviders.isEmpty()) {
+            for (int i=0; i<app.conProviders.size(); i++) {
+                ContentProviderConnection conn = app.conProviders.get(i);
+                conn.provider.connections.remove(conn);
+            }
+            app.conProviders.clear();
+        }
+
+        // At this point there may be remaining entries in mLaunchingProviders
+        // where we were the only one waiting, so they are no longer of use.
+        // Look for these and clean up if found.
+        // XXX Commented out for now.  Trying to figure out a way to reproduce
+        // the actual situation to identify what is actually going on.
+        if (false) {
+            for (int i=0; i<mLaunchingProviders.size(); i++) {
+                ContentProviderRecord cpr = (ContentProviderRecord)
+                        mLaunchingProviders.get(i);
+                if (cpr.connections.size() <= 0 && !cpr.hasExternalProcessHandles()) {
+                    synchronized (cpr) {
+                        cpr.launchingApp = null;
+                        cpr.notifyAll();
+                    }
+                }
+            }
+        }
+
+        skipCurrentReceiverLocked(app);
+
+        // Unregister any receivers.
+        for (int i=app.receivers.size()-1; i>=0; i--) {
+            removeReceiverLocked(app.receivers.valueAt(i));
+        }
+        app.receivers.clear();
+
+        // If the app is undergoing backup, tell the backup manager about it
+        if (mBackupTarget != null && app.pid == mBackupTarget.app.pid) {
+            if (DEBUG_BACKUP || DEBUG_CLEANUP) Slog.d(TAG, "App "
+                    + mBackupTarget.appInfo + " died during backup");
+            try {
+                IBackupManager bm = IBackupManager.Stub.asInterface(
+                        ServiceManager.getService(Context.BACKUP_SERVICE));
+                bm.agentDisconnected(app.info.packageName);
+            } catch (RemoteException e) {
+                // can't happen; backup manager is local
+            }
+        }
+
+        for (int i = mPendingProcessChanges.size()-1; i>=0; i--) {
+            ProcessChangeItem item = mPendingProcessChanges.get(i);
+            if (item.pid == app.pid) {
+                mPendingProcessChanges.remove(i);
+                mAvailProcessChanges.add(item);
+            }
+        }
+        mHandler.obtainMessage(DISPATCH_PROCESS_DIED, app.pid, app.info.uid, null).sendToTarget();
+
+        // If the caller is restarting this app, then leave it in its
+        // current lists and let the caller take care of it.
+        if (restarting) {
+            return;
+        }
+
+        if (!app.persistent || app.isolated) {
+            if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG,
+                    "Removing non-persistent process during cleanup: " + app);
+            mProcessNames.remove(app.processName, app.uid);
+            mIsolatedProcesses.remove(app.uid);
+            if (mHeavyWeightProcess == app) {
+                mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
+                        mHeavyWeightProcess.userId, 0));
+                mHeavyWeightProcess = null;
+            }
+        } else if (!app.removed) {
+            // This app is persistent, so we need to keep its record around.
+            // If it is not already on the pending app list, add it there
+            // and start a new process for it.
+            if (mPersistentStartingProcesses.indexOf(app) < 0) {
+                mPersistentStartingProcesses.add(app);
+                restart = true;
+            }
+        }
+        if ((DEBUG_PROCESSES || DEBUG_CLEANUP) && mProcessesOnHold.contains(app)) Slog.v(TAG,
+                "Clean-up removing on hold: " + app);
+        mProcessesOnHold.remove(app);
+
+        if (app == mHomeProcess) {
+            mHomeProcess = null;
+        }
+        if (app == mPreviousProcess) {
+            mPreviousProcess = null;
+        }
+
+        if (restart && !app.isolated) {
+            // We have components that still need to be running in the
+            // process, so re-launch it.
+            mProcessNames.put(app.processName, app.uid, app);
+            startProcessLocked(app, "restart", app.processName);
+        } else if (app.pid > 0 && app.pid != MY_PID) {
+            // Goodbye!
+            synchronized (mPidsSelfLocked) {
+                mPidsSelfLocked.remove(app.pid);
+                mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
+            }
+            app.setPid(0);
+        }
+    }
+
+    boolean checkAppInLaunchingProvidersLocked(ProcessRecord app, boolean alwaysBad) {
+        // Look through the content providers we are waiting to have launched,
+        // and if any run in this process then either schedule a restart of
+        // the process or kill the client waiting for it if this process has
+        // gone bad.
+        int NL = mLaunchingProviders.size();
+        boolean restart = false;
+        for (int i=0; i<NL; i++) {
+            ContentProviderRecord cpr = mLaunchingProviders.get(i);
+            if (cpr.launchingApp == app) {
+                if (!alwaysBad && !app.bad) {
+                    restart = true;
+                } else {
+                    removeDyingProviderLocked(app, cpr, true);
+                    // cpr should have been removed from mLaunchingProviders
+                    NL = mLaunchingProviders.size();
+                    i--;
+                }
+            }
+        }
+        return restart;
+    }
+    
+    // =========================================================
+    // SERVICES
+    // =========================================================
+
+    public List<ActivityManager.RunningServiceInfo> getServices(int maxNum,
+            int flags) {
+        enforceNotIsolatedCaller("getServices");
+        synchronized (this) {
+            return mServices.getRunningServiceInfoLocked(maxNum, flags);
+        }
+    }
+
+    public PendingIntent getRunningServiceControlPanel(ComponentName name) {
+        enforceNotIsolatedCaller("getRunningServiceControlPanel");
+        synchronized (this) {
+            return mServices.getRunningServiceControlPanelLocked(name);
+        }
+    }
+    
+    public ComponentName startService(IApplicationThread caller, Intent service,
+            String resolvedType, int userId) {
+        enforceNotIsolatedCaller("startService");
+        // Refuse possible leaked file descriptors
+        if (service != null && service.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        if (DEBUG_SERVICE)
+            Slog.v(TAG, "startService: " + service + " type=" + resolvedType);
+        synchronized(this) {
+            final int callingPid = Binder.getCallingPid();
+            final int callingUid = Binder.getCallingUid();
+            final long origId = Binder.clearCallingIdentity();
+            ComponentName res = mServices.startServiceLocked(caller, service,
+                    resolvedType, callingPid, callingUid, userId);
+            Binder.restoreCallingIdentity(origId);
+            return res;
+        }
+    }
+
+    ComponentName startServiceInPackage(int uid,
+            Intent service, String resolvedType, int userId) {
+        synchronized(this) {
+            if (DEBUG_SERVICE)
+                Slog.v(TAG, "startServiceInPackage: " + service + " type=" + resolvedType);
+            final long origId = Binder.clearCallingIdentity();
+            ComponentName res = mServices.startServiceLocked(null, service,
+                    resolvedType, -1, uid, userId);
+            Binder.restoreCallingIdentity(origId);
+            return res;
+        }
+    }
+
+    public int stopService(IApplicationThread caller, Intent service,
+            String resolvedType, int userId) {
+        enforceNotIsolatedCaller("stopService");
+        // Refuse possible leaked file descriptors
+        if (service != null && service.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized(this) {
+            return mServices.stopServiceLocked(caller, service, resolvedType, userId);
+        }
+    }
+
+    public IBinder peekService(Intent service, String resolvedType) {
+        enforceNotIsolatedCaller("peekService");
+        // Refuse possible leaked file descriptors
+        if (service != null && service.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+        synchronized(this) {
+            return mServices.peekServiceLocked(service, resolvedType);
+        }
+    }
+    
+    public boolean stopServiceToken(ComponentName className, IBinder token,
+            int startId) {
+        synchronized(this) {
+            return mServices.stopServiceTokenLocked(className, token, startId);
+        }
+    }
+
+    public void setServiceForeground(ComponentName className, IBinder token,
+            int id, Notification notification, boolean removeNotification) {
+        synchronized(this) {
+            mServices.setServiceForegroundLocked(className, token, id, notification,
+                    removeNotification);
+        }
+    }
+
+    public int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll,
+            boolean requireFull, String name, String callerPackage) {
+        final int callingUserId = UserHandle.getUserId(callingUid);
+        if (callingUserId != userId) {
+            if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
+                if ((requireFull || checkComponentPermission(
+                        android.Manifest.permission.INTERACT_ACROSS_USERS,
+                        callingPid, callingUid, -1, true) != PackageManager.PERMISSION_GRANTED)
+                        && checkComponentPermission(
+                                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                                callingPid, callingUid, -1, true)
+                                != PackageManager.PERMISSION_GRANTED) {
+                    if (userId == UserHandle.USER_CURRENT_OR_SELF) {
+                        // In this case, they would like to just execute as their
+                        // owner user instead of failing.
+                        userId = callingUserId;
+                    } else {
+                        StringBuilder builder = new StringBuilder(128);
+                        builder.append("Permission Denial: ");
+                        builder.append(name);
+                        if (callerPackage != null) {
+                            builder.append(" from ");
+                            builder.append(callerPackage);
+                        }
+                        builder.append(" asks to run as user ");
+                        builder.append(userId);
+                        builder.append(" but is calling from user ");
+                        builder.append(UserHandle.getUserId(callingUid));
+                        builder.append("; this requires ");
+                        builder.append(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL);
+                        if (!requireFull) {
+                            builder.append(" or ");
+                            builder.append(android.Manifest.permission.INTERACT_ACROSS_USERS);
+                        }
+                        String msg = builder.toString();
+                        Slog.w(TAG, msg);
+                        throw new SecurityException(msg);
+                    }
+                }
+            }
+            if (userId == UserHandle.USER_CURRENT
+                    || userId == UserHandle.USER_CURRENT_OR_SELF) {
+                // Note that we may be accessing this outside of a lock...
+                // shouldn't be a big deal, if this is being called outside
+                // of a locked context there is intrinsically a race with
+                // the value the caller will receive and someone else changing it.
+                userId = mCurrentUserId;
+            }
+            if (!allowAll && userId < 0) {
+                throw new IllegalArgumentException(
+                        "Call does not support special user #" + userId);
+            }
+        }
+        return userId;
+    }
+
+    boolean isSingleton(String componentProcessName, ApplicationInfo aInfo,
+            String className, int flags) {
+        boolean result = false;
+        if (UserHandle.getAppId(aInfo.uid) >= Process.FIRST_APPLICATION_UID) {
+            if ((flags&ServiceInfo.FLAG_SINGLE_USER) != 0) {
+                if (ActivityManager.checkUidPermission(
+                        android.Manifest.permission.INTERACT_ACROSS_USERS,
+                        aInfo.uid) != PackageManager.PERMISSION_GRANTED) {
+                    ComponentName comp = new ComponentName(aInfo.packageName, className);
+                    String msg = "Permission Denial: Component " + comp.flattenToShortString()
+                            + " requests FLAG_SINGLE_USER, but app does not hold "
+                            + android.Manifest.permission.INTERACT_ACROSS_USERS;
+                    Slog.w(TAG, msg);
+                    throw new SecurityException(msg);
+                }
+                result = true;
+            }
+        } else if (componentProcessName == aInfo.packageName) {
+            result = (aInfo.flags & ApplicationInfo.FLAG_PERSISTENT) != 0;
+        } else if ("system".equals(componentProcessName)) {
+            result = true;
+        }
+        if (DEBUG_MU) {
+            Slog.v(TAG, "isSingleton(" + componentProcessName + ", " + aInfo
+                    + ", " + className + ", 0x" + Integer.toHexString(flags) + ") = " + result);
+        }
+        return result;
+    }
+
+    public int bindService(IApplicationThread caller, IBinder token,
+            Intent service, String resolvedType,
+            IServiceConnection connection, int flags, int userId) {
+        enforceNotIsolatedCaller("bindService");
+        // Refuse possible leaked file descriptors
+        if (service != null && service.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized(this) {
+            return mServices.bindServiceLocked(caller, token, service, resolvedType,
+                    connection, flags, userId);
+        }
+    }
+
+    public boolean unbindService(IServiceConnection connection) {
+        synchronized (this) {
+            return mServices.unbindServiceLocked(connection);
+        }
+    }
+
+    public void publishService(IBinder token, Intent intent, IBinder service) {
+        // Refuse possible leaked file descriptors
+        if (intent != null && intent.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized(this) {
+            if (!(token instanceof ServiceRecord)) {
+                throw new IllegalArgumentException("Invalid service token");
+            }
+            mServices.publishServiceLocked((ServiceRecord)token, intent, service);
+        }
+    }
+
+    public void unbindFinished(IBinder token, Intent intent, boolean doRebind) {
+        // Refuse possible leaked file descriptors
+        if (intent != null && intent.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized(this) {
+            mServices.unbindFinishedLocked((ServiceRecord)token, intent, doRebind);
+        }
+    }
+
+    public void serviceDoneExecuting(IBinder token, int type, int startId, int res) {
+        synchronized(this) {
+            if (!(token instanceof ServiceRecord)) {
+                throw new IllegalArgumentException("Invalid service token");
+            }
+            mServices.serviceDoneExecutingLocked((ServiceRecord)token, type, startId, res);
+        }
+    }
+    
+    // =========================================================
+    // BACKUP AND RESTORE
+    // =========================================================
+    
+    // Cause the target app to be launched if necessary and its backup agent
+    // instantiated.  The backup agent will invoke backupAgentCreated() on the
+    // activity manager to announce its creation.
+    public boolean bindBackupAgent(ApplicationInfo app, int backupMode) {
+        if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent: app=" + app + " mode=" + backupMode);
+        enforceCallingPermission("android.permission.BACKUP", "bindBackupAgent");
+
+        synchronized(this) {
+            // !!! TODO: currently no check here that we're already bound
+            BatteryStatsImpl.Uid.Pkg.Serv ss = null;
+            BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+            synchronized (stats) {
+                ss = stats.getServiceStatsLocked(app.uid, app.packageName, app.name);
+            }
+
+            // Backup agent is now in use, its package can't be stopped.
+            try {
+                AppGlobals.getPackageManager().setPackageStoppedState(
+                        app.packageName, false, UserHandle.getUserId(app.uid));
+            } catch (RemoteException e) {
+            } catch (IllegalArgumentException e) {
+                Slog.w(TAG, "Failed trying to unstop package "
+                        + app.packageName + ": " + e);
+            }
+
+            BackupRecord r = new BackupRecord(ss, app, backupMode);
+            ComponentName hostingName = (backupMode == IApplicationThread.BACKUP_MODE_INCREMENTAL)
+                    ? new ComponentName(app.packageName, app.backupAgentName)
+                    : new ComponentName("android", "FullBackupAgent");
+            // startProcessLocked() returns existing proc's record if it's already running
+            ProcessRecord proc = startProcessLocked(app.processName, app,
+                    false, 0, "backup", hostingName, false, false, false);
+            if (proc == null) {
+                Slog.e(TAG, "Unable to start backup agent process " + r);
+                return false;
+            }
+
+            r.app = proc;
+            mBackupTarget = r;
+            mBackupAppName = app.packageName;
+
+            // Try not to kill the process during backup
+            updateOomAdjLocked(proc);
+
+            // If the process is already attached, schedule the creation of the backup agent now.
+            // If it is not yet live, this will be done when it attaches to the framework.
+            if (proc.thread != null) {
+                if (DEBUG_BACKUP) Slog.v(TAG, "Agent proc already running: " + proc);
+                try {
+                    proc.thread.scheduleCreateBackupAgent(app,
+                            compatibilityInfoForPackageLocked(app), backupMode);
+                } catch (RemoteException e) {
+                    // Will time out on the backup manager side
+                }
+            } else {
+                if (DEBUG_BACKUP) Slog.v(TAG, "Agent proc not running, waiting for attach");
+            }
+            // Invariants: at this point, the target app process exists and the application
+            // is either already running or in the process of coming up.  mBackupTarget and
+            // mBackupAppName describe the app, so that when it binds back to the AM we
+            // know that it's scheduled for a backup-agent operation.
+        }
+        
+        return true;
+    }
+
+    @Override
+    public void clearPendingBackup() {
+        if (DEBUG_BACKUP) Slog.v(TAG, "clearPendingBackup");
+        enforceCallingPermission("android.permission.BACKUP", "clearPendingBackup");
+
+        synchronized (this) {
+            mBackupTarget = null;
+            mBackupAppName = null;
+        }
+    }
+
+    // A backup agent has just come up                    
+    public void backupAgentCreated(String agentPackageName, IBinder agent) {
+        if (DEBUG_BACKUP) Slog.v(TAG, "backupAgentCreated: " + agentPackageName
+                + " = " + agent);
+
+        synchronized(this) {
+            if (!agentPackageName.equals(mBackupAppName)) {
+                Slog.e(TAG, "Backup agent created for " + agentPackageName + " but not requested!");
+                return;
+            }
+        }
+
+        long oldIdent = Binder.clearCallingIdentity();
+        try {
+            IBackupManager bm = IBackupManager.Stub.asInterface(
+                    ServiceManager.getService(Context.BACKUP_SERVICE));
+            bm.agentConnected(agentPackageName, agent);
+        } catch (RemoteException e) {
+            // can't happen; the backup manager service is local
+        } catch (Exception e) {
+            Slog.w(TAG, "Exception trying to deliver BackupAgent binding: ");
+            e.printStackTrace();
+        } finally {
+            Binder.restoreCallingIdentity(oldIdent);
+        }
+    }
+
+    // done with this agent
+    public void unbindBackupAgent(ApplicationInfo appInfo) {
+        if (DEBUG_BACKUP) Slog.v(TAG, "unbindBackupAgent: " + appInfo);
+        if (appInfo == null) {
+            Slog.w(TAG, "unbind backup agent for null app");
+            return;
+        }
+
+        synchronized(this) {
+            try {
+                if (mBackupAppName == null) {
+                    Slog.w(TAG, "Unbinding backup agent with no active backup");
+                    return;
+                }
+
+                if (!mBackupAppName.equals(appInfo.packageName)) {
+                    Slog.e(TAG, "Unbind of " + appInfo + " but is not the current backup target");
+                    return;
+                }
+
+                // Not backing this app up any more; reset its OOM adjustment
+                final ProcessRecord proc = mBackupTarget.app;
+                updateOomAdjLocked(proc);
+
+                // If the app crashed during backup, 'thread' will be null here
+                if (proc.thread != null) {
+                    try {
+                        proc.thread.scheduleDestroyBackupAgent(appInfo,
+                                compatibilityInfoForPackageLocked(appInfo));
+                    } catch (Exception e) {
+                        Slog.e(TAG, "Exception when unbinding backup agent:");
+                        e.printStackTrace();
+                    }
+                }
+            } finally {
+                mBackupTarget = null;
+                mBackupAppName = null;
+            }
+        }
+    }
+    // =========================================================
+    // BROADCASTS
+    // =========================================================
+
+    private final List getStickiesLocked(String action, IntentFilter filter,
+            List cur, int userId) {
+        final ContentResolver resolver = mContext.getContentResolver();
+        ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
+        if (stickies == null) {
+            return cur;
+        }
+        final ArrayList<Intent> list = stickies.get(action);
+        if (list == null) {
+            return cur;
+        }
+        int N = list.size();
+        for (int i=0; i<N; i++) {
+            Intent intent = list.get(i);
+            if (filter.match(resolver, intent, true, TAG) >= 0) {
+                if (cur == null) {
+                    cur = new ArrayList<Intent>();
+                }
+                cur.add(intent);
+            }
+        }
+        return cur;
+    }
+
+    boolean isPendingBroadcastProcessLocked(int pid) {
+        return mFgBroadcastQueue.isPendingBroadcastProcessLocked(pid)
+                || mBgBroadcastQueue.isPendingBroadcastProcessLocked(pid);
+    }
+
+    void skipPendingBroadcastLocked(int pid) {
+            Slog.w(TAG, "Unattached app died before broadcast acknowledged, skipping");
+            for (BroadcastQueue queue : mBroadcastQueues) {
+                queue.skipPendingBroadcastLocked(pid);
+            }
+    }
+
+    // The app just attached; send any pending broadcasts that it should receive
+    boolean sendPendingBroadcastsLocked(ProcessRecord app) {
+        boolean didSomething = false;
+        for (BroadcastQueue queue : mBroadcastQueues) {
+            didSomething |= queue.sendPendingBroadcastsLocked(app);
+        }
+        return didSomething;
+    }
+
+    public Intent registerReceiver(IApplicationThread caller, String callerPackage,
+            IIntentReceiver receiver, IntentFilter filter, String permission, int userId) {
+        enforceNotIsolatedCaller("registerReceiver");
+        int callingUid;
+        int callingPid;
+        synchronized(this) {
+            ProcessRecord callerApp = null;
+            if (caller != null) {
+                callerApp = getRecordForAppLocked(caller);
+                if (callerApp == null) {
+                    throw new SecurityException(
+                            "Unable to find app for caller " + caller
+                            + " (pid=" + Binder.getCallingPid()
+                            + ") when registering receiver " + receiver);
+                }
+                if (callerApp.info.uid != Process.SYSTEM_UID &&
+                        !callerApp.pkgList.containsKey(callerPackage) &&
+                        !"android".equals(callerPackage)) {
+                    throw new SecurityException("Given caller package " + callerPackage
+                            + " is not running in process " + callerApp);
+                }
+                callingUid = callerApp.info.uid;
+                callingPid = callerApp.pid;
+            } else {
+                callerPackage = null;
+                callingUid = Binder.getCallingUid();
+                callingPid = Binder.getCallingPid();
+            }
+
+            userId = this.handleIncomingUser(callingPid, callingUid, userId,
+                    true, true, "registerReceiver", callerPackage);
+
+            List allSticky = null;
+
+            // Look for any matching sticky broadcasts...
+            Iterator actions = filter.actionsIterator();
+            if (actions != null) {
+                while (actions.hasNext()) {
+                    String action = (String)actions.next();
+                    allSticky = getStickiesLocked(action, filter, allSticky,
+                            UserHandle.USER_ALL);
+                    allSticky = getStickiesLocked(action, filter, allSticky,
+                            UserHandle.getUserId(callingUid));
+                }
+            } else {
+                allSticky = getStickiesLocked(null, filter, allSticky,
+                        UserHandle.USER_ALL);
+                allSticky = getStickiesLocked(null, filter, allSticky,
+                        UserHandle.getUserId(callingUid));
+            }
+
+            // The first sticky in the list is returned directly back to
+            // the client.
+            Intent sticky = allSticky != null ? (Intent)allSticky.get(0) : null;
+
+            if (DEBUG_BROADCAST) Slog.v(TAG, "Register receiver " + filter
+                    + ": " + sticky);
+
+            if (receiver == null) {
+                return sticky;
+            }
+
+            ReceiverList rl
+                = (ReceiverList)mRegisteredReceivers.get(receiver.asBinder());
+            if (rl == null) {
+                rl = new ReceiverList(this, callerApp, callingPid, callingUid,
+                        userId, receiver);
+                if (rl.app != null) {
+                    rl.app.receivers.add(rl);
+                } else {
+                    try {
+                        receiver.asBinder().linkToDeath(rl, 0);
+                    } catch (RemoteException e) {
+                        return sticky;
+                    }
+                    rl.linkedToDeath = true;
+                }
+                mRegisteredReceivers.put(receiver.asBinder(), rl);
+            } else if (rl.uid != callingUid) {
+                throw new IllegalArgumentException(
+                        "Receiver requested to register for uid " + callingUid
+                        + " was previously registered for uid " + rl.uid);
+            } else if (rl.pid != callingPid) {
+                throw new IllegalArgumentException(
+                        "Receiver requested to register for pid " + callingPid
+                        + " was previously registered for pid " + rl.pid);
+            } else if (rl.userId != userId) {
+                throw new IllegalArgumentException(
+                        "Receiver requested to register for user " + userId
+                        + " was previously registered for user " + rl.userId);
+            }
+            BroadcastFilter bf = new BroadcastFilter(filter, rl, callerPackage,
+                    permission, callingUid, userId);
+            rl.add(bf);
+            if (!bf.debugCheck()) {
+                Slog.w(TAG, "==> For Dynamic broadast");
+            }
+            mReceiverResolver.addFilter(bf);
+
+            // Enqueue broadcasts for all existing stickies that match
+            // this filter.
+            if (allSticky != null) {
+                ArrayList receivers = new ArrayList();
+                receivers.add(bf);
+
+                int N = allSticky.size();
+                for (int i=0; i<N; i++) {
+                    Intent intent = (Intent)allSticky.get(i);
+                    BroadcastQueue queue = broadcastQueueForIntent(intent);
+                    BroadcastRecord r = new BroadcastRecord(queue, intent, null,
+                            null, -1, -1, null, null, AppOpsManager.OP_NONE, receivers, null, 0,
+                            null, null, false, true, true, -1);
+                    queue.enqueueParallelBroadcastLocked(r);
+                    queue.scheduleBroadcastsLocked();
+                }
+            }
+
+            return sticky;
+        }
+    }
+
+    public void unregisterReceiver(IIntentReceiver receiver) {
+        if (DEBUG_BROADCAST) Slog.v(TAG, "Unregister receiver: " + receiver);
+
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            boolean doTrim = false;
+
+            synchronized(this) {
+                ReceiverList rl = mRegisteredReceivers.get(receiver.asBinder());
+                if (rl != null) {
+                    if (rl.curBroadcast != null) {
+                        BroadcastRecord r = rl.curBroadcast;
+                        final boolean doNext = finishReceiverLocked(
+                                receiver.asBinder(), r.resultCode, r.resultData,
+                                r.resultExtras, r.resultAbort);
+                        if (doNext) {
+                            doTrim = true;
+                            r.queue.processNextBroadcast(false);
+                        }
+                    }
+
+                    if (rl.app != null) {
+                        rl.app.receivers.remove(rl);
+                    }
+                    removeReceiverLocked(rl);
+                    if (rl.linkedToDeath) {
+                        rl.linkedToDeath = false;
+                        rl.receiver.asBinder().unlinkToDeath(rl, 0);
+                    }
+                }
+            }
+
+            // If we actually concluded any broadcasts, we might now be able
+            // to trim the recipients' apps from our working set
+            if (doTrim) {
+                trimApplications();
+                return;
+            }
+
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    void removeReceiverLocked(ReceiverList rl) {
+        mRegisteredReceivers.remove(rl.receiver.asBinder());
+        int N = rl.size();
+        for (int i=0; i<N; i++) {
+            mReceiverResolver.removeFilter(rl.get(i));
+        }
+    }
+    
+    private final void sendPackageBroadcastLocked(int cmd, String[] packages, int userId) {
+        for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
+            ProcessRecord r = mLruProcesses.get(i);
+            if (r.thread != null && (userId == UserHandle.USER_ALL || r.userId == userId)) {
+                try {
+                    r.thread.dispatchPackageBroadcast(cmd, packages);
+                } catch (RemoteException ex) {
+                }
+            }
+        }
+    }
+
+    private List<ResolveInfo> collectReceiverComponents(Intent intent, String resolvedType,
+            int[] users) {
+        List<ResolveInfo> receivers = null;
+        try {
+            HashSet<ComponentName> singleUserReceivers = null;
+            boolean scannedFirstReceivers = false;
+            for (int user : users) {
+                List<ResolveInfo> newReceivers = AppGlobals.getPackageManager()
+                        .queryIntentReceivers(intent, resolvedType, STOCK_PM_FLAGS, user);
+                if (user != 0 && newReceivers != null) {
+                    // If this is not the primary user, we need to check for
+                    // any receivers that should be filtered out.
+                    for (int i=0; i<newReceivers.size(); i++) {
+                        ResolveInfo ri = newReceivers.get(i);
+                        if ((ri.activityInfo.flags&ActivityInfo.FLAG_PRIMARY_USER_ONLY) != 0) {
+                            newReceivers.remove(i);
+                            i--;
+                        }
+                    }
+                }
+                if (newReceivers != null && newReceivers.size() == 0) {
+                    newReceivers = null;
+                }
+                if (receivers == null) {
+                    receivers = newReceivers;
+                } else if (newReceivers != null) {
+                    // We need to concatenate the additional receivers
+                    // found with what we have do far.  This would be easy,
+                    // but we also need to de-dup any receivers that are
+                    // singleUser.
+                    if (!scannedFirstReceivers) {
+                        // Collect any single user receivers we had already retrieved.
+                        scannedFirstReceivers = true;
+                        for (int i=0; i<receivers.size(); i++) {
+                            ResolveInfo ri = receivers.get(i);
+                            if ((ri.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) {
+                                ComponentName cn = new ComponentName(
+                                        ri.activityInfo.packageName, ri.activityInfo.name);
+                                if (singleUserReceivers == null) {
+                                    singleUserReceivers = new HashSet<ComponentName>();
+                                }
+                                singleUserReceivers.add(cn);
+                            }
+                        }
+                    }
+                    // Add the new results to the existing results, tracking
+                    // and de-dupping single user receivers.
+                    for (int i=0; i<newReceivers.size(); i++) {
+                        ResolveInfo ri = newReceivers.get(i);
+                        if ((ri.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) {
+                            ComponentName cn = new ComponentName(
+                                    ri.activityInfo.packageName, ri.activityInfo.name);
+                            if (singleUserReceivers == null) {
+                                singleUserReceivers = new HashSet<ComponentName>();
+                            }
+                            if (!singleUserReceivers.contains(cn)) {
+                                singleUserReceivers.add(cn);
+                                receivers.add(ri);
+                            }
+                        } else {
+                            receivers.add(ri);
+                        }
+                    }
+                }
+            }
+        } catch (RemoteException ex) {
+            // pm is in same process, this will never happen.
+        }
+        return receivers;
+    }
+
+    private final int broadcastIntentLocked(ProcessRecord callerApp,
+            String callerPackage, Intent intent, String resolvedType,
+            IIntentReceiver resultTo, int resultCode, String resultData,
+            Bundle map, String requiredPermission, int appOp,
+            boolean ordered, boolean sticky, int callingPid, int callingUid,
+            int userId) {
+        intent = new Intent(intent);
+
+        // By default broadcasts do not go to stopped apps.
+        intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
+
+        if (DEBUG_BROADCAST_LIGHT) Slog.v(
+            TAG, (sticky ? "Broadcast sticky: ": "Broadcast: ") + intent
+            + " ordered=" + ordered + " userid=" + userId);
+        if ((resultTo != null) && !ordered) {
+            Slog.w(TAG, "Broadcast " + intent + " not ordered but result callback requested!");
+        }
+
+        userId = handleIncomingUser(callingPid, callingUid, userId,
+                true, false, "broadcast", callerPackage);
+
+        // Make sure that the user who is receiving this broadcast is started.
+        // If not, we will just skip it.
+        if (userId != UserHandle.USER_ALL && mStartedUsers.get(userId) == null) {
+            if (callingUid != Process.SYSTEM_UID || (intent.getFlags()
+                    & Intent.FLAG_RECEIVER_BOOT_UPGRADE) == 0) {
+                Slog.w(TAG, "Skipping broadcast of " + intent
+                        + ": user " + userId + " is stopped");
+                return ActivityManager.BROADCAST_SUCCESS;
+            }
+        }
+
+        /*
+         * Prevent non-system code (defined here to be non-persistent
+         * processes) from sending protected broadcasts.
+         */
+        int callingAppId = UserHandle.getAppId(callingUid);
+        if (callingAppId == Process.SYSTEM_UID || callingAppId == Process.PHONE_UID
+            || callingAppId == Process.SHELL_UID || callingAppId == Process.BLUETOOTH_UID ||
+            callingUid == 0) {
+            // Always okay.
+        } else if (callerApp == null || !callerApp.persistent) {
+            try {
+                if (AppGlobals.getPackageManager().isProtectedBroadcast(
+                        intent.getAction())) {
+                    String msg = "Permission Denial: not allowed to send broadcast "
+                            + intent.getAction() + " from pid="
+                            + callingPid + ", uid=" + callingUid;
+                    Slog.w(TAG, msg);
+                    throw new SecurityException(msg);
+                } else if (AppWidgetManager.ACTION_APPWIDGET_CONFIGURE.equals(intent.getAction())) {
+                    // Special case for compatibility: we don't want apps to send this,
+                    // but historically it has not been protected and apps may be using it
+                    // to poke their own app widget.  So, instead of making it protected,
+                    // just limit it to the caller.
+                    if (callerApp == null) {
+                        String msg = "Permission Denial: not allowed to send broadcast "
+                                + intent.getAction() + " from unknown caller.";
+                        Slog.w(TAG, msg);
+                        throw new SecurityException(msg);
+                    } else if (intent.getComponent() != null) {
+                        // They are good enough to send to an explicit component...  verify
+                        // it is being sent to the calling app.
+                        if (!intent.getComponent().getPackageName().equals(
+                                callerApp.info.packageName)) {
+                            String msg = "Permission Denial: not allowed to send broadcast "
+                                    + intent.getAction() + " to "
+                                    + intent.getComponent().getPackageName() + " from "
+                                    + callerApp.info.packageName;
+                            Slog.w(TAG, msg);
+                            throw new SecurityException(msg);
+                        }
+                    } else {
+                        // Limit broadcast to their own package.
+                        intent.setPackage(callerApp.info.packageName);
+                    }
+                }
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Remote exception", e);
+                return ActivityManager.BROADCAST_SUCCESS;
+            }
+        }
+
+        // Handle special intents: if this broadcast is from the package
+        // manager about a package being removed, we need to remove all of
+        // its activities from the history stack.
+        final boolean uidRemoved = Intent.ACTION_UID_REMOVED.equals(
+                intent.getAction());
+        if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())
+                || Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())
+                || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(intent.getAction())
+                || uidRemoved) {
+            if (checkComponentPermission(
+                    android.Manifest.permission.BROADCAST_PACKAGE_REMOVED,
+                    callingPid, callingUid, -1, true)
+                    == PackageManager.PERMISSION_GRANTED) {
+                if (uidRemoved) {
+                    final Bundle intentExtras = intent.getExtras();
+                    final int uid = intentExtras != null
+                            ? intentExtras.getInt(Intent.EXTRA_UID) : -1;
+                    if (uid >= 0) {
+                        BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics();
+                        synchronized (bs) {
+                            bs.removeUidStatsLocked(uid);
+                        }
+                        mAppOpsService.uidRemoved(uid);
+                    }
+                } else {
+                    // If resources are unavailable just force stop all
+                    // those packages and flush the attribute cache as well.
+                    if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(intent.getAction())) {
+                        String list[] = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+                        if (list != null && (list.length > 0)) {
+                            for (String pkg : list) {
+                                forceStopPackageLocked(pkg, -1, false, true, true, false, userId,
+                                        "storage unmount");
+                            }
+                            sendPackageBroadcastLocked(
+                                    IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE, list, userId);
+                        }
+                    } else {
+                        Uri data = intent.getData();
+                        String ssp;
+                        if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
+                            boolean removed = Intent.ACTION_PACKAGE_REMOVED.equals(
+                                    intent.getAction());
+                            if (!intent.getBooleanExtra(Intent.EXTRA_DONT_KILL_APP, false)) {
+                                forceStopPackageLocked(ssp, UserHandle.getAppId(
+                                        intent.getIntExtra(Intent.EXTRA_UID, -1)), false, true, true,
+                                        false, userId, removed ? "pkg removed" : "pkg changed");
+                            }
+                            if (removed) {
+                                sendPackageBroadcastLocked(IApplicationThread.PACKAGE_REMOVED,
+                                        new String[] {ssp}, userId);
+                                if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
+                                    mAppOpsService.packageRemoved(
+                                            intent.getIntExtra(Intent.EXTRA_UID, -1), ssp);
+
+                                    // Remove all permissions granted from/to this package
+                                    removeUriPermissionsForPackageLocked(ssp, userId, true);
+                                }
+                            }
+                        }
+                    }
+                }
+            } else {
+                String msg = "Permission Denial: " + intent.getAction()
+                        + " broadcast from " + callerPackage + " (pid=" + callingPid
+                        + ", uid=" + callingUid + ")"
+                        + " requires "
+                        + android.Manifest.permission.BROADCAST_PACKAGE_REMOVED;
+                Slog.w(TAG, msg);
+                throw new SecurityException(msg);
+            }
+
+        // Special case for adding a package: by default turn on compatibility
+        // mode.
+        } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
+            Uri data = intent.getData();
+            String ssp;
+            if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
+                mCompatModePackages.handlePackageAddedLocked(ssp,
+                        intent.getBooleanExtra(Intent.EXTRA_REPLACING, false));
+            }
+        }
+
+        /*
+         * If this is the time zone changed action, queue up a message that will reset the timezone
+         * of all currently running processes. This message will get queued up before the broadcast
+         * happens.
+         */
+        if (intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
+            mHandler.sendEmptyMessage(UPDATE_TIME_ZONE);
+        }
+
+        if (intent.ACTION_CLEAR_DNS_CACHE.equals(intent.getAction())) {
+            mHandler.sendEmptyMessage(CLEAR_DNS_CACHE_MSG);
+        }
+
+        if (Proxy.PROXY_CHANGE_ACTION.equals(intent.getAction())) {
+            ProxyProperties proxy = intent.getParcelableExtra("proxy");
+            mHandler.sendMessage(mHandler.obtainMessage(UPDATE_HTTP_PROXY_MSG, proxy));
+        }
+
+        // Add to the sticky list if requested.
+        if (sticky) {
+            if (checkPermission(android.Manifest.permission.BROADCAST_STICKY,
+                    callingPid, callingUid)
+                    != PackageManager.PERMISSION_GRANTED) {
+                String msg = "Permission Denial: broadcastIntent() requesting a sticky broadcast from pid="
+                        + callingPid + ", uid=" + callingUid
+                        + " requires " + android.Manifest.permission.BROADCAST_STICKY;
+                Slog.w(TAG, msg);
+                throw new SecurityException(msg);
+            }
+            if (requiredPermission != null) {
+                Slog.w(TAG, "Can't broadcast sticky intent " + intent
+                        + " and enforce permission " + requiredPermission);
+                return ActivityManager.BROADCAST_STICKY_CANT_HAVE_PERMISSION;
+            }
+            if (intent.getComponent() != null) {
+                throw new SecurityException(
+                        "Sticky broadcasts can't target a specific component");
+            }
+            // We use userId directly here, since the "all" target is maintained
+            // as a separate set of sticky broadcasts.
+            if (userId != UserHandle.USER_ALL) {
+                // But first, if this is not a broadcast to all users, then
+                // make sure it doesn't conflict with an existing broadcast to
+                // all users.
+                ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(
+                        UserHandle.USER_ALL);
+                if (stickies != null) {
+                    ArrayList<Intent> list = stickies.get(intent.getAction());
+                    if (list != null) {
+                        int N = list.size();
+                        int i;
+                        for (i=0; i<N; i++) {
+                            if (intent.filterEquals(list.get(i))) {
+                                throw new IllegalArgumentException(
+                                        "Sticky broadcast " + intent + " for user "
+                                        + userId + " conflicts with existing global broadcast");
+                            }
+                        }
+                    }
+                }
+            }
+            ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
+            if (stickies == null) {
+                stickies = new ArrayMap<String, ArrayList<Intent>>();
+                mStickyBroadcasts.put(userId, stickies);
+            }
+            ArrayList<Intent> list = stickies.get(intent.getAction());
+            if (list == null) {
+                list = new ArrayList<Intent>();
+                stickies.put(intent.getAction(), list);
+            }
+            int N = list.size();
+            int i;
+            for (i=0; i<N; i++) {
+                if (intent.filterEquals(list.get(i))) {
+                    // This sticky already exists, replace it.
+                    list.set(i, new Intent(intent));
+                    break;
+                }
+            }
+            if (i >= N) {
+                list.add(new Intent(intent));
+            }
+        }
+
+        int[] users;
+        if (userId == UserHandle.USER_ALL) {
+            // Caller wants broadcast to go to all started users.
+            users = mStartedUserArray;
+        } else {
+            // Caller wants broadcast to go to one specific user.
+            users = new int[] {userId};
+        }
+
+        // Figure out who all will receive this broadcast.
+        List receivers = null;
+        List<BroadcastFilter> registeredReceivers = null;
+        // Need to resolve the intent to interested receivers...
+        if ((intent.getFlags()&Intent.FLAG_RECEIVER_REGISTERED_ONLY)
+                 == 0) {
+            receivers = collectReceiverComponents(intent, resolvedType, users);
+        }
+        if (intent.getComponent() == null) {
+            registeredReceivers = mReceiverResolver.queryIntent(intent,
+                    resolvedType, false, userId);
+        }
+
+        final boolean replacePending =
+                (intent.getFlags()&Intent.FLAG_RECEIVER_REPLACE_PENDING) != 0;
+        
+        if (DEBUG_BROADCAST) Slog.v(TAG, "Enqueing broadcast: " + intent.getAction()
+                + " replacePending=" + replacePending);
+        
+        int NR = registeredReceivers != null ? registeredReceivers.size() : 0;
+        if (!ordered && NR > 0) {
+            // If we are not serializing this broadcast, then send the
+            // registered receivers separately so they don't wait for the
+            // components to be launched.
+            final BroadcastQueue queue = broadcastQueueForIntent(intent);
+            BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
+                    callerPackage, callingPid, callingUid, resolvedType, requiredPermission,
+                    appOp, registeredReceivers, resultTo, resultCode, resultData, map,
+                    ordered, sticky, false, userId);
+            if (DEBUG_BROADCAST) Slog.v(
+                    TAG, "Enqueueing parallel broadcast " + r);
+            final boolean replaced = replacePending && queue.replaceParallelBroadcastLocked(r);
+            if (!replaced) {
+                queue.enqueueParallelBroadcastLocked(r);
+                queue.scheduleBroadcastsLocked();
+            }
+            registeredReceivers = null;
+            NR = 0;
+        }
+
+        // Merge into one list.
+        int ir = 0;
+        if (receivers != null) {
+            // A special case for PACKAGE_ADDED: do not allow the package
+            // being added to see this broadcast.  This prevents them from
+            // using this as a back door to get run as soon as they are
+            // installed.  Maybe in the future we want to have a special install
+            // broadcast or such for apps, but we'd like to deliberately make
+            // this decision.
+            String skipPackages[] = null;
+            if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())
+                    || Intent.ACTION_PACKAGE_RESTARTED.equals(intent.getAction())
+                    || Intent.ACTION_PACKAGE_DATA_CLEARED.equals(intent.getAction())) {
+                Uri data = intent.getData();
+                if (data != null) {
+                    String pkgName = data.getSchemeSpecificPart();
+                    if (pkgName != null) {
+                        skipPackages = new String[] { pkgName };
+                    }
+                }
+            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(intent.getAction())) {
+                skipPackages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+            }
+            if (skipPackages != null && (skipPackages.length > 0)) {
+                for (String skipPackage : skipPackages) {
+                    if (skipPackage != null) {
+                        int NT = receivers.size();
+                        for (int it=0; it<NT; it++) {
+                            ResolveInfo curt = (ResolveInfo)receivers.get(it);
+                            if (curt.activityInfo.packageName.equals(skipPackage)) {
+                                receivers.remove(it);
+                                it--;
+                                NT--;
+                            }
+                        }
+                    }
+                }
+            }
+
+            int NT = receivers != null ? receivers.size() : 0;
+            int it = 0;
+            ResolveInfo curt = null;
+            BroadcastFilter curr = null;
+            while (it < NT && ir < NR) {
+                if (curt == null) {
+                    curt = (ResolveInfo)receivers.get(it);
+                }
+                if (curr == null) {
+                    curr = registeredReceivers.get(ir);
+                }
+                if (curr.getPriority() >= curt.priority) {
+                    // Insert this broadcast record into the final list.
+                    receivers.add(it, curr);
+                    ir++;
+                    curr = null;
+                    it++;
+                    NT++;
+                } else {
+                    // Skip to the next ResolveInfo in the final list.
+                    it++;
+                    curt = null;
+                }
+            }
+        }
+        while (ir < NR) {
+            if (receivers == null) {
+                receivers = new ArrayList();
+            }
+            receivers.add(registeredReceivers.get(ir));
+            ir++;
+        }
+
+        if ((receivers != null && receivers.size() > 0)
+                || resultTo != null) {
+            BroadcastQueue queue = broadcastQueueForIntent(intent);
+            BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
+                    callerPackage, callingPid, callingUid, resolvedType,
+                    requiredPermission, appOp, receivers, resultTo, resultCode,
+                    resultData, map, ordered, sticky, false, userId);
+            if (DEBUG_BROADCAST) Slog.v(
+                    TAG, "Enqueueing ordered broadcast " + r
+                    + ": prev had " + queue.mOrderedBroadcasts.size());
+            if (DEBUG_BROADCAST) {
+                int seq = r.intent.getIntExtra("seq", -1);
+                Slog.i(TAG, "Enqueueing broadcast " + r.intent.getAction() + " seq=" + seq);
+            }
+            boolean replaced = replacePending && queue.replaceOrderedBroadcastLocked(r); 
+            if (!replaced) {
+                queue.enqueueOrderedBroadcastLocked(r);
+                queue.scheduleBroadcastsLocked();
+            }
+        }
+
+        return ActivityManager.BROADCAST_SUCCESS;
+    }
+
+    final Intent verifyBroadcastLocked(Intent intent) {
+        // Refuse possible leaked file descriptors
+        if (intent != null && intent.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        int flags = intent.getFlags();
+
+        if (!mProcessesReady) {
+            // if the caller really truly claims to know what they're doing, go
+            // ahead and allow the broadcast without launching any receivers
+            if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT) != 0) {
+                intent = new Intent(intent);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+            } else if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) {
+                Slog.e(TAG, "Attempt to launch receivers of broadcast intent " + intent
+                        + " before boot completion");
+                throw new IllegalStateException("Cannot broadcast before boot completed");
+            }
+        }
+
+        if ((flags&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
+            throw new IllegalArgumentException(
+                    "Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
+        }
+
+        return intent;
+    }
+
+    public final int broadcastIntent(IApplicationThread caller,
+            Intent intent, String resolvedType, IIntentReceiver resultTo,
+            int resultCode, String resultData, Bundle map,
+            String requiredPermission, int appOp, boolean serialized, boolean sticky, int userId) {
+        enforceNotIsolatedCaller("broadcastIntent");
+        synchronized(this) {
+            intent = verifyBroadcastLocked(intent);
+            
+            final ProcessRecord callerApp = getRecordForAppLocked(caller);
+            final int callingPid = Binder.getCallingPid();
+            final int callingUid = Binder.getCallingUid();
+            final long origId = Binder.clearCallingIdentity();
+            int res = broadcastIntentLocked(callerApp,
+                    callerApp != null ? callerApp.info.packageName : null,
+                    intent, resolvedType, resultTo,
+                    resultCode, resultData, map, requiredPermission, appOp, serialized, sticky,
+                    callingPid, callingUid, userId);
+            Binder.restoreCallingIdentity(origId);
+            return res;
+        }
+    }
+
+    int broadcastIntentInPackage(String packageName, int uid,
+            Intent intent, String resolvedType, IIntentReceiver resultTo,
+            int resultCode, String resultData, Bundle map,
+            String requiredPermission, boolean serialized, boolean sticky, int userId) {
+        synchronized(this) {
+            intent = verifyBroadcastLocked(intent);
+
+            final long origId = Binder.clearCallingIdentity();
+            int res = broadcastIntentLocked(null, packageName, intent, resolvedType,
+                    resultTo, resultCode, resultData, map, requiredPermission,
+                    AppOpsManager.OP_NONE, serialized, sticky, -1, uid, userId);
+            Binder.restoreCallingIdentity(origId);
+            return res;
+        }
+    }
+
+    public final void unbroadcastIntent(IApplicationThread caller, Intent intent, int userId) {
+        // Refuse possible leaked file descriptors
+        if (intent != null && intent.hasFileDescriptors() == true) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        userId = handleIncomingUser(Binder.getCallingPid(),
+                Binder.getCallingUid(), userId, true, false, "removeStickyBroadcast", null);
+
+        synchronized(this) {
+            if (checkCallingPermission(android.Manifest.permission.BROADCAST_STICKY)
+                    != PackageManager.PERMISSION_GRANTED) {
+                String msg = "Permission Denial: unbroadcastIntent() from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid()
+                        + " requires " + android.Manifest.permission.BROADCAST_STICKY;
+                Slog.w(TAG, msg);
+                throw new SecurityException(msg);
+            }
+            ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
+            if (stickies != null) {
+                ArrayList<Intent> list = stickies.get(intent.getAction());
+                if (list != null) {
+                    int N = list.size();
+                    int i;
+                    for (i=0; i<N; i++) {
+                        if (intent.filterEquals(list.get(i))) {
+                            list.remove(i);
+                            break;
+                        }
+                    }
+                    if (list.size() <= 0) {
+                        stickies.remove(intent.getAction());
+                    }
+                }
+                if (stickies.size() <= 0) {
+                    mStickyBroadcasts.remove(userId);
+                }
+            }
+        }
+    }
+
+    private final boolean finishReceiverLocked(IBinder receiver, int resultCode,
+            String resultData, Bundle resultExtras, boolean resultAbort) {
+        final BroadcastRecord r = broadcastRecordForReceiverLocked(receiver);
+        if (r == null) {
+            Slog.w(TAG, "finishReceiver called but not found on queue");
+            return false;
+        }
+
+        return r.queue.finishReceiverLocked(r, resultCode, resultData, resultExtras, resultAbort, false);
+    }
+
+    void backgroundServicesFinishedLocked(int userId) {
+        for (BroadcastQueue queue : mBroadcastQueues) {
+            queue.backgroundServicesFinishedLocked(userId);
+        }
+    }
+
+    public void finishReceiver(IBinder who, int resultCode, String resultData,
+            Bundle resultExtras, boolean resultAbort) {
+        if (DEBUG_BROADCAST) Slog.v(TAG, "Finish receiver: " + who);
+
+        // Refuse possible leaked file descriptors
+        if (resultExtras != null && resultExtras.hasFileDescriptors()) {
+            throw new IllegalArgumentException("File descriptors passed in Bundle");
+        }
+
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            boolean doNext = false;
+            BroadcastRecord r;
+
+            synchronized(this) {
+                r = broadcastRecordForReceiverLocked(who);
+                if (r != null) {
+                    doNext = r.queue.finishReceiverLocked(r, resultCode,
+                        resultData, resultExtras, resultAbort, true);
+                }
+            }
+
+            if (doNext) {
+                r.queue.processNextBroadcast(false);
+            }
+            trimApplications();
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+    
+    // =========================================================
+    // INSTRUMENTATION
+    // =========================================================
+
+    public boolean startInstrumentation(ComponentName className,
+            String profileFile, int flags, Bundle arguments,
+            IInstrumentationWatcher watcher, IUiAutomationConnection uiAutomationConnection,
+            int userId) {
+        enforceNotIsolatedCaller("startInstrumentation");
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
+                userId, false, true, "startInstrumentation", null);
+        // Refuse possible leaked file descriptors
+        if (arguments != null && arguments.hasFileDescriptors()) {
+            throw new IllegalArgumentException("File descriptors passed in Bundle");
+        }
+
+        synchronized(this) {
+            InstrumentationInfo ii = null;
+            ApplicationInfo ai = null;
+            try {
+                ii = mContext.getPackageManager().getInstrumentationInfo(
+                    className, STOCK_PM_FLAGS);
+                ai = AppGlobals.getPackageManager().getApplicationInfo(
+                        ii.targetPackage, STOCK_PM_FLAGS, userId);
+            } catch (PackageManager.NameNotFoundException e) {
+            } catch (RemoteException e) {
+            }
+            if (ii == null) {
+                reportStartInstrumentationFailure(watcher, className,
+                        "Unable to find instrumentation info for: " + className);
+                return false;
+            }
+            if (ai == null) {
+                reportStartInstrumentationFailure(watcher, className,
+                        "Unable to find instrumentation target package: " + ii.targetPackage);
+                return false;
+            }
+
+            int match = mContext.getPackageManager().checkSignatures(
+                    ii.targetPackage, ii.packageName);
+            if (match < 0 && match != PackageManager.SIGNATURE_FIRST_NOT_SIGNED) {
+                String msg = "Permission Denial: starting instrumentation "
+                        + className + " from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingPid()
+                        + " not allowed because package " + ii.packageName
+                        + " does not have a signature matching the target "
+                        + ii.targetPackage;
+                reportStartInstrumentationFailure(watcher, className, msg);
+                throw new SecurityException(msg);
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+            // Instrumentation can kill and relaunch even persistent processes
+            forceStopPackageLocked(ii.targetPackage, -1, true, false, true, true, userId,
+                    "start instr");
+            ProcessRecord app = addAppLocked(ai, false);
+            app.instrumentationClass = className;
+            app.instrumentationInfo = ai;
+            app.instrumentationProfileFile = profileFile;
+            app.instrumentationArguments = arguments;
+            app.instrumentationWatcher = watcher;
+            app.instrumentationUiAutomationConnection = uiAutomationConnection;
+            app.instrumentationResultClass = className;
+            Binder.restoreCallingIdentity(origId);
+        }
+
+        return true;
+    }
+    
+    /**
+     * Report errors that occur while attempting to start Instrumentation.  Always writes the 
+     * error to the logs, but if somebody is watching, send the report there too.  This enables
+     * the "am" command to report errors with more information.
+     * 
+     * @param watcher The IInstrumentationWatcher.  Null if there isn't one.
+     * @param cn The component name of the instrumentation.
+     * @param report The error report.
+     */
+    private void reportStartInstrumentationFailure(IInstrumentationWatcher watcher, 
+            ComponentName cn, String report) {
+        Slog.w(TAG, report);
+        try {
+            if (watcher != null) {
+                Bundle results = new Bundle();
+                results.putString(Instrumentation.REPORT_KEY_IDENTIFIER, "ActivityManagerService");
+                results.putString("Error", report);
+                watcher.instrumentationStatus(cn, -1, results);
+            }
+        } catch (RemoteException e) {
+            Slog.w(TAG, e);
+        }
+    }
+
+    void finishInstrumentationLocked(ProcessRecord app, int resultCode, Bundle results) {
+        if (app.instrumentationWatcher != null) {
+            try {
+                // NOTE:  IInstrumentationWatcher *must* be oneway here
+                app.instrumentationWatcher.instrumentationFinished(
+                    app.instrumentationClass,
+                    resultCode,
+                    results);
+            } catch (RemoteException e) {
+            }
+        }
+        if (app.instrumentationUiAutomationConnection != null) {
+            try {
+                app.instrumentationUiAutomationConnection.shutdown();
+            } catch (RemoteException re) {
+                /* ignore */
+            }
+            // Only a UiAutomation can set this flag and now that
+            // it is finished we make sure it is reset to its default.
+            mUserIsMonkey = false;
+        }
+        app.instrumentationWatcher = null;
+        app.instrumentationUiAutomationConnection = null;
+        app.instrumentationClass = null;
+        app.instrumentationInfo = null;
+        app.instrumentationProfileFile = null;
+        app.instrumentationArguments = null;
+
+        forceStopPackageLocked(app.info.packageName, -1, false, false, true, true, app.userId,
+                "finished inst");
+    }
+
+    public void finishInstrumentation(IApplicationThread target,
+            int resultCode, Bundle results) {
+        int userId = UserHandle.getCallingUserId();
+        // Refuse possible leaked file descriptors
+        if (results != null && results.hasFileDescriptors()) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+
+        synchronized(this) {
+            ProcessRecord app = getRecordForAppLocked(target);
+            if (app == null) {
+                Slog.w(TAG, "finishInstrumentation: no app for " + target);
+                return;
+            }
+            final long origId = Binder.clearCallingIdentity();
+            finishInstrumentationLocked(app, resultCode, results);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    // =========================================================
+    // CONFIGURATION
+    // =========================================================
+    
+    public ConfigurationInfo getDeviceConfigurationInfo() {
+        ConfigurationInfo config = new ConfigurationInfo();
+        synchronized (this) {
+            config.reqTouchScreen = mConfiguration.touchscreen;
+            config.reqKeyboardType = mConfiguration.keyboard;
+            config.reqNavigation = mConfiguration.navigation;
+            if (mConfiguration.navigation == Configuration.NAVIGATION_DPAD
+                    || mConfiguration.navigation == Configuration.NAVIGATION_TRACKBALL) {
+                config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
+            }
+            if (mConfiguration.keyboard != Configuration.KEYBOARD_UNDEFINED
+                    && mConfiguration.keyboard != Configuration.KEYBOARD_NOKEYS) {
+                config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
+            }
+            config.reqGlEsVersion = GL_ES_VERSION;
+        }
+        return config;
+    }
+
+    ActivityStack getFocusedStack() {
+        return mStackSupervisor.getFocusedStack();
+    }
+
+    public Configuration getConfiguration() {
+        Configuration ci;
+        synchronized(this) {
+            ci = new Configuration(mConfiguration);
+        }
+        return ci;
+    }
+
+    public void updatePersistentConfiguration(Configuration values) {
+        enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
+                "updateConfiguration()");
+        enforceCallingPermission(android.Manifest.permission.WRITE_SETTINGS,
+                "updateConfiguration()");
+        if (values == null) {
+            throw new NullPointerException("Configuration must not be null");
+        }
+
+        synchronized(this) {
+            final long origId = Binder.clearCallingIdentity();
+            updateConfigurationLocked(values, null, true, false);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    public void updateConfiguration(Configuration values) {
+        enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
+                "updateConfiguration()");
+
+        synchronized(this) {
+            if (values == null && mWindowManager != null) {
+                // sentinel: fetch the current configuration from the window manager
+                values = mWindowManager.computeNewConfiguration();
+            }
+
+            if (mWindowManager != null) {
+                mProcessList.applyDisplaySize(mWindowManager);
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+            if (values != null) {
+                Settings.System.clearConfiguration(values);
+            }
+            updateConfigurationLocked(values, null, false, false);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    /**
+     * Do either or both things: (1) change the current configuration, and (2)
+     * make sure the given activity is running with the (now) current
+     * configuration.  Returns true if the activity has been left running, or
+     * false if <var>starting</var> is being destroyed to match the new
+     * configuration.
+     * @param persistent TODO
+     */
+    boolean updateConfigurationLocked(Configuration values,
+            ActivityRecord starting, boolean persistent, boolean initLocale) {
+        int changes = 0;
+
+        if (values != null) {
+            Configuration newConfig = new Configuration(mConfiguration);
+            changes = newConfig.updateFrom(values);
+            if (changes != 0) {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
+                    Slog.i(TAG, "Updating configuration to: " + values);
+                }
+                
+                EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes);
+
+                if (values.locale != null && !initLocale) {
+                    saveLocaleLocked(values.locale, 
+                                     !values.locale.equals(mConfiguration.locale),
+                                     values.userSetLocale);
+                }
+
+                mConfigurationSeq++;
+                if (mConfigurationSeq <= 0) {
+                    mConfigurationSeq = 1;
+                }
+                newConfig.seq = mConfigurationSeq;
+                mConfiguration = newConfig;
+                Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + newConfig);
+
+                final Configuration configCopy = new Configuration(mConfiguration);
+                
+                // TODO: If our config changes, should we auto dismiss any currently
+                // showing dialogs?
+                mShowDialogs = shouldShowDialogs(newConfig);
+
+                AttributeCache ac = AttributeCache.instance();
+                if (ac != null) {
+                    ac.updateConfiguration(configCopy);
+                }
+
+                // Make sure all resources in our process are updated
+                // right now, so that anyone who is going to retrieve
+                // resource values after we return will be sure to get
+                // the new ones.  This is especially important during
+                // boot, where the first config change needs to guarantee
+                // all resources have that config before following boot
+                // code is executed.
+                mSystemThread.applyConfigurationToResources(configCopy);
+
+                if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) {
+                    Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
+                    msg.obj = new Configuration(configCopy);
+                    mHandler.sendMessage(msg);
+                }
+        
+                for (int i=mLruProcesses.size()-1; i>=0; i--) {
+                    ProcessRecord app = mLruProcesses.get(i);
+                    try {
+                        if (app.thread != null) {
+                            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending to proc "
+                                    + app.processName + " new config " + mConfiguration);
+                            app.thread.scheduleConfigurationChanged(configCopy);
+                        }
+                    } catch (Exception e) {
+                    }
+                }
+                Intent intent = new Intent(Intent.ACTION_CONFIGURATION_CHANGED);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                        | Intent.FLAG_RECEIVER_REPLACE_PENDING
+                        | Intent.FLAG_RECEIVER_FOREGROUND);
+                broadcastIntentLocked(null, null, intent, null, null, 0, null, null,
+                        null, AppOpsManager.OP_NONE, false, false, MY_PID,
+                        Process.SYSTEM_UID, UserHandle.USER_ALL);
+                if ((changes&ActivityInfo.CONFIG_LOCALE) != 0) {
+                    intent = new Intent(Intent.ACTION_LOCALE_CHANGED);
+                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+                    broadcastIntentLocked(null, null, intent,
+                            null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                            false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+                }
+            }
+        }
+
+        boolean kept = true;
+        final ActivityStack mainStack = mStackSupervisor.getFocusedStack();
+        // mainStack is null during startup.
+        if (mainStack != null) {
+            if (changes != 0 && starting == null) {
+                // If the configuration changed, and the caller is not already
+                // in the process of starting an activity, then find the top
+                // activity to check if its configuration needs to change.
+                starting = mainStack.topRunningActivityLocked(null);
+            }
+
+            if (starting != null) {
+                kept = mainStack.ensureActivityConfigurationLocked(starting, changes);
+                // And we need to make sure at this point that all other activities
+                // are made visible with the correct configuration.
+                mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes);
+            }
+        }
+
+        if (values != null && mWindowManager != null) {
+            mWindowManager.setNewConfiguration(mConfiguration);
+        }
+
+        return kept;
+    }
+
+    /**
+     * Decide based on the configuration whether we should shouw the ANR,
+     * crash, etc dialogs.  The idea is that if there is no affordnace to
+     * press the on-screen buttons, we shouldn't show the dialog.
+     *
+     * A thought: SystemUI might also want to get told about this, the Power
+     * dialog / global actions also might want different behaviors.
+     */
+    private static final boolean shouldShowDialogs(Configuration config) {
+        return !(config.keyboard == Configuration.KEYBOARD_NOKEYS
+                && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH);
+    }
+
+    /**
+     * Save the locale.  You must be inside a synchronized (this) block.
+     */
+    private void saveLocaleLocked(Locale l, boolean isDiff, boolean isPersist) {
+        if(isDiff) {
+            SystemProperties.set("user.language", l.getLanguage());
+            SystemProperties.set("user.region", l.getCountry());
+        } 
+
+        if(isPersist) {
+            SystemProperties.set("persist.sys.language", l.getLanguage());
+            SystemProperties.set("persist.sys.country", l.getCountry());
+            SystemProperties.set("persist.sys.localevar", l.getVariant());
+        }
+    }
+
+    @Override
+    public boolean targetTaskAffinityMatchesActivity(IBinder token, String destAffinity) {
+        ActivityRecord srec = ActivityRecord.forToken(token);
+        return srec != null && srec.task.affinity != null &&
+                srec.task.affinity.equals(destAffinity);
+    }
+
+    public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode,
+            Intent resultData) {
+
+        synchronized (this) {
+            final ActivityStack stack = ActivityRecord.getStackLocked(token);
+            if (stack != null) {
+                return stack.navigateUpToLocked(token, destIntent, resultCode, resultData);
+            }
+            return false;
+        }
+    }
+
+    public int getLaunchedFromUid(IBinder activityToken) {
+        ActivityRecord srec = ActivityRecord.forToken(activityToken);
+        if (srec == null) {
+            return -1;
+        }
+        return srec.launchedFromUid;
+    }
+
+    public String getLaunchedFromPackage(IBinder activityToken) {
+        ActivityRecord srec = ActivityRecord.forToken(activityToken);
+        if (srec == null) {
+            return null;
+        }
+        return srec.launchedFromPackage;
+    }
+
+    // =========================================================
+    // LIFETIME MANAGEMENT
+    // =========================================================
+
+    // Returns which broadcast queue the app is the current [or imminent] receiver
+    // on, or 'null' if the app is not an active broadcast recipient.
+    private BroadcastQueue isReceivingBroadcast(ProcessRecord app) {
+        BroadcastRecord r = app.curReceiver;
+        if (r != null) {
+            return r.queue;
+        }
+
+        // It's not the current receiver, but it might be starting up to become one
+        synchronized (this) {
+            for (BroadcastQueue queue : mBroadcastQueues) {
+                r = queue.mPendingBroadcast;
+                if (r != null && r.curApp == app) {
+                    // found it; report which queue it's in
+                    return queue;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private final int computeOomAdjLocked(ProcessRecord app, int cachedAdj, ProcessRecord TOP_APP,
+            boolean doingAll, long now) {
+        if (mAdjSeq == app.adjSeq) {
+            // This adjustment has already been computed.
+            return app.curRawAdj;
+        }
+
+        if (app.thread == null) {
+            app.adjSeq = mAdjSeq;
+            app.curSchedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
+            app.curProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
+            return (app.curAdj=app.curRawAdj=ProcessList.CACHED_APP_MAX_ADJ);
+        }
+
+        app.adjTypeCode = ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN;
+        app.adjSource = null;
+        app.adjTarget = null;
+        app.empty = false;
+        app.cached = false;
+
+        final int activitiesSize = app.activities.size();
+
+        if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) {
+            // The max adjustment doesn't allow this app to be anything
+            // below foreground, so it is not worth doing work for it.
+            app.adjType = "fixed";
+            app.adjSeq = mAdjSeq;
+            app.curRawAdj = app.maxAdj;
+            app.foregroundActivities = false;
+            app.keeping = true;
+            app.curSchedGroup = Process.THREAD_GROUP_DEFAULT;
+            app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT;
+            // System process can do UI, and when they do we want to have
+            // them trim their memory after the user leaves the UI.  To
+            // facilitate this, here we need to determine whether or not it
+            // is currently showing UI.
+            app.systemNoUi = true;
+            if (app == TOP_APP) {
+                app.systemNoUi = false;
+            } else if (activitiesSize > 0) {
+                for (int j = 0; j < activitiesSize; j++) {
+                    final ActivityRecord r = app.activities.get(j);
+                    if (r.visible) {
+                        app.systemNoUi = false;
+                    }
+                }
+            }
+            if (!app.systemNoUi) {
+                app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT_UI;
+            }
+            return (app.curAdj=app.maxAdj);
+        }
+
+        app.keeping = false;
+        app.systemNoUi = false;
+
+        // Determine the importance of the process, starting with most
+        // important to least, and assign an appropriate OOM adjustment.
+        int adj;
+        int schedGroup;
+        int procState;
+        boolean foregroundActivities = false;
+        boolean interesting = false;
+        BroadcastQueue queue;
+        if (app == TOP_APP) {
+            // The last app on the list is the foreground app.
+            adj = ProcessList.FOREGROUND_APP_ADJ;
+            schedGroup = Process.THREAD_GROUP_DEFAULT;
+            app.adjType = "top-activity";
+            foregroundActivities = true;
+            interesting = true;
+            procState = ActivityManager.PROCESS_STATE_TOP;
+        } else if (app.instrumentationClass != null) {
+            // Don't want to kill running instrumentation.
+            adj = ProcessList.FOREGROUND_APP_ADJ;
+            schedGroup = Process.THREAD_GROUP_DEFAULT;
+            app.adjType = "instrumentation";
+            interesting = true;
+            procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+        } else if ((queue = isReceivingBroadcast(app)) != null) {
+            // An app that is currently receiving a broadcast also
+            // counts as being in the foreground for OOM killer purposes.
+            // It's placed in a sched group based on the nature of the
+            // broadcast as reflected by which queue it's active in.
+            adj = ProcessList.FOREGROUND_APP_ADJ;
+            schedGroup = (queue == mFgBroadcastQueue)
+                    ? Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
+            app.adjType = "broadcast";
+            procState = ActivityManager.PROCESS_STATE_RECEIVER;
+        } else if (app.executingServices.size() > 0) {
+            // An app that is currently executing a service callback also
+            // counts as being in the foreground.
+            adj = ProcessList.FOREGROUND_APP_ADJ;
+            schedGroup = app.execServicesFg ?
+                    Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
+            app.adjType = "exec-service";
+            procState = ActivityManager.PROCESS_STATE_SERVICE;
+            //Slog.i(TAG, "EXEC " + (app.execServicesFg ? "FG" : "BG") + ": " + app);
+        } else {
+            // As far as we know the process is empty.  We may change our mind later.
+            schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
+            // At this point we don't actually know the adjustment.  Use the cached adj
+            // value that the caller wants us to.
+            adj = cachedAdj;
+            procState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
+            app.cached = true;
+            app.empty = true;
+            app.adjType = "cch-empty";
+        }
+
+        // Examine all activities if not already foreground.
+        if (!foregroundActivities && activitiesSize > 0) {
+            for (int j = 0; j < activitiesSize; j++) {
+                final ActivityRecord r = app.activities.get(j);
+                if (r.app != app) {
+                    Slog.w(TAG, "Wtf, activity " + r + " in proc activity list not using proc "
+                            + app + "?!?");
+                    continue;
+                }
+                if (r.visible) {
+                    // App has a visible activity; only upgrade adjustment.
+                    if (adj > ProcessList.VISIBLE_APP_ADJ) {
+                        adj = ProcessList.VISIBLE_APP_ADJ;
+                        app.adjType = "visible";
+                    }
+                    if (procState > ActivityManager.PROCESS_STATE_TOP) {
+                        procState = ActivityManager.PROCESS_STATE_TOP;
+                    }
+                    schedGroup = Process.THREAD_GROUP_DEFAULT;
+                    app.cached = false;
+                    app.empty = false;
+                    foregroundActivities = true;
+                    break;
+                } else if (r.state == ActivityState.PAUSING || r.state == ActivityState.PAUSED) {
+                    if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+                        adj = ProcessList.PERCEPTIBLE_APP_ADJ;
+                        app.adjType = "pausing";
+                    }
+                    if (procState > ActivityManager.PROCESS_STATE_TOP) {
+                        procState = ActivityManager.PROCESS_STATE_TOP;
+                    }
+                    schedGroup = Process.THREAD_GROUP_DEFAULT;
+                    app.cached = false;
+                    app.empty = false;
+                    foregroundActivities = true;
+                } else if (r.state == ActivityState.STOPPING) {
+                    if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+                        adj = ProcessList.PERCEPTIBLE_APP_ADJ;
+                        app.adjType = "stopping";
+                    }
+                    // For the process state, we will at this point consider the
+                    // process to be cached.  It will be cached either as an activity
+                    // or empty depending on whether the activity is finishing.  We do
+                    // this so that we can treat the process as cached for purposes of
+                    // memory trimming (determing current memory level, trim command to
+                    // send to process) since there can be an arbitrary number of stopping
+                    // processes and they should soon all go into the cached state.
+                    if (!r.finishing) {
+                        if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
+                            procState = ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
+                        }
+                    }
+                    app.cached = false;
+                    app.empty = false;
+                    foregroundActivities = true;
+                } else {
+                    if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
+                        procState = ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
+                        app.adjType = "cch-act";
+                    }
+                }
+            }
+        }
+
+        if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+            if (app.foregroundServices) {
+                // The user is aware of this app, so make it visible.
+                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
+                procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+                app.cached = false;
+                app.adjType = "fg-service";
+                schedGroup = Process.THREAD_GROUP_DEFAULT;
+            } else if (app.forcingToForeground != null) {
+                // The user is aware of this app, so make it visible.
+                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
+                procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+                app.cached = false;
+                app.adjType = "force-fg";
+                app.adjSource = app.forcingToForeground;
+                schedGroup = Process.THREAD_GROUP_DEFAULT;
+            }
+        }
+
+        if (app.foregroundServices) {
+            interesting = true;
+        }
+
+        if (app == mHeavyWeightProcess) {
+            if (adj > ProcessList.HEAVY_WEIGHT_APP_ADJ) {
+                // We don't want to kill the current heavy-weight process.
+                adj = ProcessList.HEAVY_WEIGHT_APP_ADJ;
+                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
+                app.cached = false;
+                app.adjType = "heavy";
+            }
+            if (procState > ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
+                procState = ActivityManager.PROCESS_STATE_HEAVY_WEIGHT;
+            }
+        }
+
+        if (app == mHomeProcess) {
+            if (adj > ProcessList.HOME_APP_ADJ) {
+                // This process is hosting what we currently consider to be the
+                // home app, so we don't want to let it go into the background.
+                adj = ProcessList.HOME_APP_ADJ;
+                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
+                app.cached = false;
+                app.adjType = "home";
+            }
+            if (procState > ActivityManager.PROCESS_STATE_HOME) {
+                procState = ActivityManager.PROCESS_STATE_HOME;
+            }
+        }
+
+        if (app == mPreviousProcess && app.activities.size() > 0) {
+            if (adj > ProcessList.PREVIOUS_APP_ADJ) {
+                // This was the previous process that showed UI to the user.
+                // We want to try to keep it around more aggressively, to give
+                // a good experience around switching between two apps.
+                adj = ProcessList.PREVIOUS_APP_ADJ;
+                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
+                app.cached = false;
+                app.adjType = "previous";
+            }
+            if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
+                procState = ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
+            }
+        }
+
+        if (false) Slog.i(TAG, "OOM " + app + ": initial adj=" + adj
+                + " reason=" + app.adjType);
+
+        // By default, we use the computed adjustment.  It may be changed if
+        // there are applications dependent on our services or providers, but
+        // this gives us a baseline and makes sure we don't get into an
+        // infinite recursion.
+        app.adjSeq = mAdjSeq;
+        app.curRawAdj = adj;
+        app.hasStartedServices = false;
+
+        if (mBackupTarget != null && app == mBackupTarget.app) {
+            // If possible we want to avoid killing apps while they're being backed up
+            if (adj > ProcessList.BACKUP_APP_ADJ) {
+                if (DEBUG_BACKUP) Slog.v(TAG, "oom BACKUP_APP_ADJ for " + app);
+                adj = ProcessList.BACKUP_APP_ADJ;
+                if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
+                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
+                }
+                app.adjType = "backup";
+                app.cached = false;
+            }
+            if (procState > ActivityManager.PROCESS_STATE_BACKUP) {
+                procState = ActivityManager.PROCESS_STATE_BACKUP;
+            }
+        }
+
+        boolean mayBeTop = false;
+
+        for (int is = app.services.size()-1;
+                is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
+                        || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
+                        || procState > ActivityManager.PROCESS_STATE_TOP);
+                is--) {
+            ServiceRecord s = app.services.valueAt(is);
+            if (s.startRequested) {
+                app.hasStartedServices = true;
+                if (procState > ActivityManager.PROCESS_STATE_SERVICE) {
+                    procState = ActivityManager.PROCESS_STATE_SERVICE;
+                }
+                if (app.hasShownUi && app != mHomeProcess) {
+                    // If this process has shown some UI, let it immediately
+                    // go to the LRU list because it may be pretty heavy with
+                    // UI stuff.  We'll tag it with a label just to help
+                    // debug and understand what is going on.
+                    if (adj > ProcessList.SERVICE_ADJ) {
+                        app.adjType = "cch-started-ui-services";
+                    }
+                } else {
+                    if (now < (s.lastActivity + ActiveServices.MAX_SERVICE_INACTIVITY)) {
+                        // This service has seen some activity within
+                        // recent memory, so we will keep its process ahead
+                        // of the background processes.
+                        if (adj > ProcessList.SERVICE_ADJ) {
+                            adj = ProcessList.SERVICE_ADJ;
+                            app.adjType = "started-services";
+                            app.cached = false;
+                        }
+                    }
+                    // If we have let the service slide into the background
+                    // state, still have some text describing what it is doing
+                    // even though the service no longer has an impact.
+                    if (adj > ProcessList.SERVICE_ADJ) {
+                        app.adjType = "cch-started-services";
+                    }
+                }
+                // Don't kill this process because it is doing work; it
+                // has said it is doing work.
+                app.keeping = true;
+            }
+            for (int conni = s.connections.size()-1;
+                    conni >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
+                            || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
+                            || procState > ActivityManager.PROCESS_STATE_TOP);
+                    conni--) {
+                ArrayList<ConnectionRecord> clist = s.connections.valueAt(conni);
+                for (int i = 0;
+                        i < clist.size() && (adj > ProcessList.FOREGROUND_APP_ADJ
+                                || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
+                                || procState > ActivityManager.PROCESS_STATE_TOP);
+                        i++) {
+                    // XXX should compute this based on the max of
+                    // all connected clients.
+                    ConnectionRecord cr = clist.get(i);
+                    if (cr.binding.client == app) {
+                        // Binding to ourself is not interesting.
+                        continue;
+                    }
+                    if ((cr.flags&Context.BIND_WAIVE_PRIORITY) == 0) {
+                        ProcessRecord client = cr.binding.client;
+                        int clientAdj = computeOomAdjLocked(client, cachedAdj,
+                                TOP_APP, doingAll, now);
+                        int clientProcState = client.curProcState;
+                        if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
+                            // If the other app is cached for any reason, for purposes here
+                            // we are going to consider it empty.  The specific cached state
+                            // doesn't propagate except under certain conditions.
+                            clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
+                        }
+                        String adjType = null;
+                        if ((cr.flags&Context.BIND_ALLOW_OOM_MANAGEMENT) != 0) {
+                            // Not doing bind OOM management, so treat
+                            // this guy more like a started service.
+                            if (app.hasShownUi && app != mHomeProcess) {
+                                // If this process has shown some UI, let it immediately
+                                // go to the LRU list because it may be pretty heavy with
+                                // UI stuff.  We'll tag it with a label just to help
+                                // debug and understand what is going on.
+                                if (adj > clientAdj) {
+                                    adjType = "cch-bound-ui-services";
+                                }
+                                app.cached = false;
+                                clientAdj = adj;
+                                clientProcState = procState;
+                            } else {
+                                if (now >= (s.lastActivity
+                                        + ActiveServices.MAX_SERVICE_INACTIVITY)) {
+                                    // This service has not seen activity within
+                                    // recent memory, so allow it to drop to the
+                                    // LRU list if there is no other reason to keep
+                                    // it around.  We'll also tag it with a label just
+                                    // to help debug and undertand what is going on.
+                                    if (adj > clientAdj) {
+                                        adjType = "cch-bound-services";
+                                    }
+                                    clientAdj = adj;
+                                }
+                            }
+                        }
+                        if (adj > clientAdj) {
+                            // If this process has recently shown UI, and
+                            // the process that is binding to it is less
+                            // important than being visible, then we don't
+                            // care about the binding as much as we care
+                            // about letting this process get into the LRU
+                            // list to be killed and restarted if needed for
+                            // memory.
+                            if (app.hasShownUi && app != mHomeProcess
+                                    && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+                                adjType = "cch-bound-ui-services";
+                            } else {
+                                if ((cr.flags&(Context.BIND_ABOVE_CLIENT
+                                        |Context.BIND_IMPORTANT)) != 0) {
+                                    adj = clientAdj;
+                                } else if ((cr.flags&Context.BIND_NOT_VISIBLE) != 0
+                                        && clientAdj < ProcessList.PERCEPTIBLE_APP_ADJ
+                                        && adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+                                    adj = ProcessList.PERCEPTIBLE_APP_ADJ;
+                                } else if (clientAdj > ProcessList.VISIBLE_APP_ADJ) {
+                                    adj = clientAdj;
+                                } else {
+                                    if (adj > ProcessList.VISIBLE_APP_ADJ) {
+                                        adj = ProcessList.VISIBLE_APP_ADJ;
+                                    }
+                                }
+                                if (!client.cached) {
+                                    app.cached = false;
+                                }
+                                if (client.keeping) {
+                                    app.keeping = true;
+                                }
+                                adjType = "service";
+                            }
+                        }
+                        if ((cr.flags&Context.BIND_NOT_FOREGROUND) == 0) {
+                            if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
+                                schedGroup = Process.THREAD_GROUP_DEFAULT;
+                            }
+                            if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
+                                if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
+                                    // Special handling of clients who are in the top state.
+                                    // We *may* want to consider this process to be in the
+                                    // top state as well, but only if there is not another
+                                    // reason for it to be running.  Being on the top is a
+                                    // special state, meaning you are specifically running
+                                    // for the current top app.  If the process is already
+                                    // running in the background for some other reason, it
+                                    // is more important to continue considering it to be
+                                    // in the background state.
+                                    mayBeTop = true;
+                                    clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
+                                } else {
+                                    // Special handling for above-top states (persistent
+                                    // processes).  These should not bring the current process
+                                    // into the top state, since they are not on top.  Instead
+                                    // give them the best state after that.
+                                    clientProcState =
+                                            ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+                                }
+                            }
+                        } else {
+                            if (clientProcState <
+                                    ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
+                                clientProcState =
+                                        ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
+                            }
+                        }
+                        if (procState > clientProcState) {
+                            procState = clientProcState;
+                        }
+                        if (procState < ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+                                && (cr.flags&Context.BIND_SHOWING_UI) != 0) {
+                            app.pendingUiClean = true;
+                        }
+                        if (adjType != null) {
+                            app.adjType = adjType;
+                            app.adjTypeCode = ActivityManager.RunningAppProcessInfo
+                                    .REASON_SERVICE_IN_USE;
+                            app.adjSource = cr.binding.client;
+                            app.adjSourceOom = clientAdj;
+                            app.adjTarget = s.name;
+                        }
+                    }
+                    final ActivityRecord a = cr.activity;
+                    if ((cr.flags&Context.BIND_ADJUST_WITH_ACTIVITY) != 0) {
+                        if (a != null && adj > ProcessList.FOREGROUND_APP_ADJ &&
+                                (a.visible || a.state == ActivityState.RESUMED
+                                 || a.state == ActivityState.PAUSING)) {
+                            adj = ProcessList.FOREGROUND_APP_ADJ;
+                            if ((cr.flags&Context.BIND_NOT_FOREGROUND) == 0) {
+                                schedGroup = Process.THREAD_GROUP_DEFAULT;
+                            }
+                            app.cached = false;
+                            app.adjType = "service";
+                            app.adjTypeCode = ActivityManager.RunningAppProcessInfo
+                                    .REASON_SERVICE_IN_USE;
+                            app.adjSource = a;
+                            app.adjSourceOom = adj;
+                            app.adjTarget = s.name;
+                        }
+                    }
+                }
+            }
+        }
+
+        for (int provi = app.pubProviders.size()-1;
+                provi >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
+                        || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
+                        || procState > ActivityManager.PROCESS_STATE_TOP);
+                provi--) {
+            ContentProviderRecord cpr = app.pubProviders.valueAt(provi);
+            for (int i = cpr.connections.size()-1;
+                    i >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
+                            || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
+                            || procState > ActivityManager.PROCESS_STATE_TOP);
+                    i--) {
+                ContentProviderConnection conn = cpr.connections.get(i);
+                ProcessRecord client = conn.client;
+                if (client == app) {
+                    // Being our own client is not interesting.
+                    continue;
+                }
+                int clientAdj = computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now);
+                int clientProcState = client.curProcState;
+                if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
+                    // If the other app is cached for any reason, for purposes here
+                    // we are going to consider it empty.
+                    clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
+                }
+                if (adj > clientAdj) {
+                    if (app.hasShownUi && app != mHomeProcess
+                            && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
+                        app.adjType = "cch-ui-provider";
+                    } else {
+                        adj = clientAdj > ProcessList.FOREGROUND_APP_ADJ
+                                ? clientAdj : ProcessList.FOREGROUND_APP_ADJ;
+                        app.adjType = "provider";
+                    }
+                    app.cached &= client.cached;
+                    app.keeping |= client.keeping;
+                    app.adjTypeCode = ActivityManager.RunningAppProcessInfo
+                            .REASON_PROVIDER_IN_USE;
+                    app.adjSource = client;
+                    app.adjSourceOom = clientAdj;
+                    app.adjTarget = cpr.name;
+                }
+                if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
+                    if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
+                        // Special handling of clients who are in the top state.
+                        // We *may* want to consider this process to be in the
+                        // top state as well, but only if there is not another
+                        // reason for it to be running.  Being on the top is a
+                        // special state, meaning you are specifically running
+                        // for the current top app.  If the process is already
+                        // running in the background for some other reason, it
+                        // is more important to continue considering it to be
+                        // in the background state.
+                        mayBeTop = true;
+                        clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
+                    } else {
+                        // Special handling for above-top states (persistent
+                        // processes).  These should not bring the current process
+                        // into the top state, since they are not on top.  Instead
+                        // give them the best state after that.
+                        clientProcState =
+                                ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+                    }
+                }
+                if (procState > clientProcState) {
+                    procState = clientProcState;
+                }
+                if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
+                    schedGroup = Process.THREAD_GROUP_DEFAULT;
+                }
+            }
+            // If the provider has external (non-framework) process
+            // dependencies, ensure that its adjustment is at least
+            // FOREGROUND_APP_ADJ.
+            if (cpr.hasExternalProcessHandles()) {
+                if (adj > ProcessList.FOREGROUND_APP_ADJ) {
+                    adj = ProcessList.FOREGROUND_APP_ADJ;
+                    schedGroup = Process.THREAD_GROUP_DEFAULT;
+                    app.cached = false;
+                    app.keeping = true;
+                    app.adjType = "provider";
+                    app.adjTarget = cpr.name;
+                }
+                if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
+                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+                }
+            }
+        }
+
+        if (mayBeTop && procState > ActivityManager.PROCESS_STATE_TOP) {
+            // A client of one of our services or providers is in the top state.  We
+            // *may* want to be in the top state, but not if we are already running in
+            // the background for some other reason.  For the decision here, we are going
+            // to pick out a few specific states that we want to remain in when a client
+            // is top (states that tend to be longer-term) and otherwise allow it to go
+            // to the top state.
+            switch (procState) {
+                case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
+                case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
+                case ActivityManager.PROCESS_STATE_SERVICE:
+                    // These all are longer-term states, so pull them up to the top
+                    // of the background states, but not all the way to the top state.
+                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
+                    break;
+                default:
+                    // Otherwise, top is a better choice, so take it.
+                    procState = ActivityManager.PROCESS_STATE_TOP;
+                    break;
+            }
+        }
+
+        if (procState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY && app.hasClientActivities) {
+            // This is a cached process, but with client activities.  Mark it so.
+            procState = ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
+            app.adjType = "cch-client-act";
+        }
+
+        if (adj == ProcessList.SERVICE_ADJ) {
+            if (doingAll) {
+                app.serviceb = mNewNumAServiceProcs > (mNumServiceProcs/3);
+                mNewNumServiceProcs++;
+                //Slog.i(TAG, "ADJ " + app + " serviceb=" + app.serviceb);
+                if (!app.serviceb) {
+                    // This service isn't far enough down on the LRU list to
+                    // normally be a B service, but if we are low on RAM and it
+                    // is large we want to force it down since we would prefer to
+                    // keep launcher over it.
+                    if (mLastMemoryLevel > ProcessStats.ADJ_MEM_FACTOR_NORMAL
+                            && app.lastPss >= mProcessList.getCachedRestoreThresholdKb()) {
+                        app.serviceHighRam = true;
+                        app.serviceb = true;
+                        //Slog.i(TAG, "ADJ " + app + " high ram!");
+                    } else {
+                        mNewNumAServiceProcs++;
+                        //Slog.i(TAG, "ADJ " + app + " not high ram!");
+                    }
+                } else {
+                    app.serviceHighRam = false;
+                }
+            }
+            if (app.serviceb) {
+                adj = ProcessList.SERVICE_B_ADJ;
+            }
+        }
+
+        app.curRawAdj = adj;
+        
+        //Slog.i(TAG, "OOM ADJ " + app + ": pid=" + app.pid +
+        //      " adj=" + adj + " curAdj=" + app.curAdj + " maxAdj=" + app.maxAdj);
+        if (adj > app.maxAdj) {
+            adj = app.maxAdj;
+            if (app.maxAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
+                schedGroup = Process.THREAD_GROUP_DEFAULT;
+            }
+        }
+        if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
+            app.keeping = true;
+        }
+
+        // Do final modification to adj.  Everything we do between here and applying
+        // the final setAdj must be done in this function, because we will also use
+        // it when computing the final cached adj later.  Note that we don't need to
+        // worry about this for max adj above, since max adj will always be used to
+        // keep it out of the cached vaues.
+        adj = app.modifyRawOomAdj(adj);
+
+        app.curProcState = procState;
+
+        int importance = app.memImportance;
+        if (importance == 0 || adj != app.curAdj || schedGroup != app.curSchedGroup) {
+            app.curAdj = adj;
+            app.curSchedGroup = schedGroup;
+            if (!interesting) {
+                // For this reporting, if there is not something explicitly
+                // interesting in this process then we will push it to the
+                // background importance.
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+            } else if (adj >= ProcessList.CACHED_APP_MIN_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+            } else if (adj >= ProcessList.SERVICE_B_ADJ) {
+                importance =  ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
+            } else if (adj >= ProcessList.HOME_APP_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+            } else if (adj >= ProcessList.SERVICE_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
+            } else if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
+            } else if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
+            } else if (adj >= ProcessList.VISIBLE_APP_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
+            } else if (adj >= ProcessList.FOREGROUND_APP_ADJ) {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
+            } else {
+                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERSISTENT;
+            }
+        }
+
+        int changes = importance != app.memImportance ? ProcessChangeItem.CHANGE_IMPORTANCE : 0;
+        if (foregroundActivities != app.foregroundActivities) {
+            changes |= ProcessChangeItem.CHANGE_ACTIVITIES;
+        }
+        if (changes != 0) {
+            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Changes in " + app + ": " + changes);
+            app.memImportance = importance;
+            app.foregroundActivities = foregroundActivities;
+            int i = mPendingProcessChanges.size()-1;
+            ProcessChangeItem item = null;
+            while (i >= 0) {
+                item = mPendingProcessChanges.get(i);
+                if (item.pid == app.pid) {
+                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Re-using existing item: " + item);
+                    break;
+                }
+                i--;
+            }
+            if (i < 0) {
+                // No existing item in pending changes; need a new one.
+                final int NA = mAvailProcessChanges.size();
+                if (NA > 0) {
+                    item = mAvailProcessChanges.remove(NA-1);
+                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Retreiving available item: " + item);
+                } else {
+                    item = new ProcessChangeItem();
+                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Allocating new item: " + item);
+                }
+                item.changes = 0;
+                item.pid = app.pid;
+                item.uid = app.info.uid;
+                if (mPendingProcessChanges.size() == 0) {
+                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG,
+                            "*** Enqueueing dispatch processes changed!");
+                    mHandler.obtainMessage(DISPATCH_PROCESSES_CHANGED).sendToTarget();
+                }
+                mPendingProcessChanges.add(item);
+            }
+            item.changes |= changes;
+            item.importance = importance;
+            item.foregroundActivities = foregroundActivities;
+            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Item "
+                    + Integer.toHexString(System.identityHashCode(item))
+                    + " " + app.toShortString() + ": changes=" + item.changes
+                    + " importance=" + item.importance
+                    + " foreground=" + item.foregroundActivities
+                    + " type=" + app.adjType + " source=" + app.adjSource
+                    + " target=" + app.adjTarget);
+        }
+
+        return app.curRawAdj;
+    }
+
+    /**
+     * Schedule PSS collection of a process.
+     */
+    void requestPssLocked(ProcessRecord proc, int procState) {
+        if (mPendingPssProcesses.contains(proc)) {
+            return;
+        }
+        if (mPendingPssProcesses.size() == 0) {
+            mBgHandler.sendEmptyMessage(COLLECT_PSS_BG_MSG);
+        }
+        if (DEBUG_PSS) Slog.d(TAG, "Requesting PSS of: " + proc);
+        proc.pssProcState = procState;
+        mPendingPssProcesses.add(proc);
+    }
+
+    /**
+     * Schedule PSS collection of all processes.
+     */
+    void requestPssAllProcsLocked(long now, boolean always, boolean memLowered) {
+        if (!always) {
+            if (now < (mLastFullPssTime +
+                    (memLowered ? FULL_PSS_LOWERED_INTERVAL : FULL_PSS_MIN_INTERVAL))) {
+                return;
+            }
+        }
+        if (DEBUG_PSS) Slog.d(TAG, "Requesting PSS of all procs!  memLowered=" + memLowered);
+        mLastFullPssTime = now;
+        mPendingPssProcesses.ensureCapacity(mLruProcesses.size());
+        mPendingPssProcesses.clear();
+        for (int i=mLruProcesses.size()-1; i>=0; i--) {
+            ProcessRecord app = mLruProcesses.get(i);
+            if (memLowered || now > (app.lastStateTime+ProcessList.PSS_ALL_INTERVAL)) {
+                app.pssProcState = app.setProcState;
+                app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
+                        mSleeping, now);
+                mPendingPssProcesses.add(app);
+            }
+        }
+        mBgHandler.sendEmptyMessage(COLLECT_PSS_BG_MSG);
+    }
+
+    /**
+     * Ask a given process to GC right now.
+     */
+    final void performAppGcLocked(ProcessRecord app) {
+        try {
+            app.lastRequestedGc = SystemClock.uptimeMillis();
+            if (app.thread != null) {
+                if (app.reportLowMemory) {
+                    app.reportLowMemory = false;
+                    app.thread.scheduleLowMemory();
+                } else {
+                    app.thread.processInBackground();
+                }
+            }
+        } catch (Exception e) {
+            // whatever.
+        }
+    }
+    
+    /**
+     * Returns true if things are idle enough to perform GCs.
+     */
+    private final boolean canGcNowLocked() {
+        boolean processingBroadcasts = false;
+        for (BroadcastQueue q : mBroadcastQueues) {
+            if (q.mParallelBroadcasts.size() != 0 || q.mOrderedBroadcasts.size() != 0) {
+                processingBroadcasts = true;
+            }
+        }
+        return !processingBroadcasts
+                && (mSleeping || mStackSupervisor.allResumedActivitiesIdle());
+    }
+    
+    /**
+     * Perform GCs on all processes that are waiting for it, but only
+     * if things are idle.
+     */
+    final void performAppGcsLocked() {
+        final int N = mProcessesToGc.size();
+        if (N <= 0) {
+            return;
+        }
+        if (canGcNowLocked()) {
+            while (mProcessesToGc.size() > 0) {
+                ProcessRecord proc = mProcessesToGc.remove(0);
+                if (proc.curRawAdj > ProcessList.PERCEPTIBLE_APP_ADJ || proc.reportLowMemory) {
+                    if ((proc.lastRequestedGc+GC_MIN_INTERVAL)
+                            <= SystemClock.uptimeMillis()) {
+                        // To avoid spamming the system, we will GC processes one
+                        // at a time, waiting a few seconds between each.
+                        performAppGcLocked(proc);
+                        scheduleAppGcsLocked();
+                        return;
+                    } else {
+                        // It hasn't been long enough since we last GCed this
+                        // process...  put it in the list to wait for its time.
+                        addProcessToGcListLocked(proc);
+                        break;
+                    }
+                }
+            }
+            
+            scheduleAppGcsLocked();
+        }
+    }
+    
+    /**
+     * If all looks good, perform GCs on all processes waiting for them.
+     */
+    final void performAppGcsIfAppropriateLocked() {
+        if (canGcNowLocked()) {
+            performAppGcsLocked();
+            return;
+        }
+        // Still not idle, wait some more.
+        scheduleAppGcsLocked();
+    }
+
+    /**
+     * Schedule the execution of all pending app GCs.
+     */
+    final void scheduleAppGcsLocked() {
+        mHandler.removeMessages(GC_BACKGROUND_PROCESSES_MSG);
+        
+        if (mProcessesToGc.size() > 0) {
+            // Schedule a GC for the time to the next process.
+            ProcessRecord proc = mProcessesToGc.get(0);
+            Message msg = mHandler.obtainMessage(GC_BACKGROUND_PROCESSES_MSG);
+            
+            long when = proc.lastRequestedGc + GC_MIN_INTERVAL;
+            long now = SystemClock.uptimeMillis();
+            if (when < (now+GC_TIMEOUT)) {
+                when = now + GC_TIMEOUT;
+            }
+            mHandler.sendMessageAtTime(msg, when);
+        }
+    }
+    
+    /**
+     * Add a process to the array of processes waiting to be GCed.  Keeps the
+     * list in sorted order by the last GC time.  The process can't already be
+     * on the list.
+     */
+    final void addProcessToGcListLocked(ProcessRecord proc) {
+        boolean added = false;
+        for (int i=mProcessesToGc.size()-1; i>=0; i--) {
+            if (mProcessesToGc.get(i).lastRequestedGc <
+                    proc.lastRequestedGc) {
+                added = true;
+                mProcessesToGc.add(i+1, proc);
+                break;
+            }
+        }
+        if (!added) {
+            mProcessesToGc.add(0, proc);
+        }
+    }
+    
+    /**
+     * Set up to ask a process to GC itself.  This will either do it
+     * immediately, or put it on the list of processes to gc the next
+     * time things are idle.
+     */
+    final void scheduleAppGcLocked(ProcessRecord app) {
+        long now = SystemClock.uptimeMillis();
+        if ((app.lastRequestedGc+GC_MIN_INTERVAL) > now) {
+            return;
+        }
+        if (!mProcessesToGc.contains(app)) {
+            addProcessToGcListLocked(app);
+            scheduleAppGcsLocked();
+        }
+    }
+
+    final void checkExcessivePowerUsageLocked(boolean doKills) {
+        updateCpuStatsNow();
+
+        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+        boolean doWakeKills = doKills;
+        boolean doCpuKills = doKills;
+        if (mLastPowerCheckRealtime == 0) {
+            doWakeKills = false;
+        }
+        if (mLastPowerCheckUptime == 0) {
+            doCpuKills = false;
+        }
+        if (stats.isScreenOn()) {
+            doWakeKills = false;
+        }
+        final long curRealtime = SystemClock.elapsedRealtime();
+        final long realtimeSince = curRealtime - mLastPowerCheckRealtime;
+        final long curUptime = SystemClock.uptimeMillis();
+        final long uptimeSince = curUptime - mLastPowerCheckUptime;
+        mLastPowerCheckRealtime = curRealtime;
+        mLastPowerCheckUptime = curUptime;
+        if (realtimeSince < WAKE_LOCK_MIN_CHECK_DURATION) {
+            doWakeKills = false;
+        }
+        if (uptimeSince < CPU_MIN_CHECK_DURATION) {
+            doCpuKills = false;
+        }
+        int i = mLruProcesses.size();
+        while (i > 0) {
+            i--;
+            ProcessRecord app = mLruProcesses.get(i);
+            if (!app.keeping) {
+                long wtime;
+                synchronized (stats) {
+                    wtime = stats.getProcessWakeTime(app.info.uid,
+                            app.pid, curRealtime);
+                }
+                long wtimeUsed = wtime - app.lastWakeTime;
+                long cputimeUsed = app.curCpuTime - app.lastCpuTime;
+                if (DEBUG_POWER) {
+                    StringBuilder sb = new StringBuilder(128);
+                    sb.append("Wake for ");
+                    app.toShortString(sb);
+                    sb.append(": over ");
+                    TimeUtils.formatDuration(realtimeSince, sb);
+                    sb.append(" used ");
+                    TimeUtils.formatDuration(wtimeUsed, sb);
+                    sb.append(" (");
+                    sb.append((wtimeUsed*100)/realtimeSince);
+                    sb.append("%)");
+                    Slog.i(TAG, sb.toString());
+                    sb.setLength(0);
+                    sb.append("CPU for ");
+                    app.toShortString(sb);
+                    sb.append(": over ");
+                    TimeUtils.formatDuration(uptimeSince, sb);
+                    sb.append(" used ");
+                    TimeUtils.formatDuration(cputimeUsed, sb);
+                    sb.append(" (");
+                    sb.append((cputimeUsed*100)/uptimeSince);
+                    sb.append("%)");
+                    Slog.i(TAG, sb.toString());
+                }
+                // If a process has held a wake lock for more
+                // than 50% of the time during this period,
+                // that sounds bad.  Kill!
+                if (doWakeKills && realtimeSince > 0
+                        && ((wtimeUsed*100)/realtimeSince) >= 50) {
+                    synchronized (stats) {
+                        stats.reportExcessiveWakeLocked(app.info.uid, app.processName,
+                                realtimeSince, wtimeUsed);
+                    }
+                    killUnneededProcessLocked(app, "excessive wake held " + wtimeUsed
+                            + " during " + realtimeSince);
+                    app.baseProcessTracker.reportExcessiveWake(app.pkgList);
+                } else if (doCpuKills && uptimeSince > 0
+                        && ((cputimeUsed*100)/uptimeSince) >= 50) {
+                    synchronized (stats) {
+                        stats.reportExcessiveCpuLocked(app.info.uid, app.processName,
+                                uptimeSince, cputimeUsed);
+                    }
+                    killUnneededProcessLocked(app, "excessive cpu " + cputimeUsed
+                            + " during " + uptimeSince);
+                    app.baseProcessTracker.reportExcessiveCpu(app.pkgList);
+                } else {
+                    app.lastWakeTime = wtime;
+                    app.lastCpuTime = app.curCpuTime;
+                }
+            }
+        }
+    }
+
+    private final boolean applyOomAdjLocked(ProcessRecord app, boolean wasKeeping,
+            ProcessRecord TOP_APP, boolean doingAll, boolean reportingProcessState, long now) {
+        boolean success = true;
+
+        if (app.curRawAdj != app.setRawAdj) {
+            if (wasKeeping && !app.keeping) {
+                // This app is no longer something we want to keep.  Note
+                // its current wake lock time to later know to kill it if
+                // it is not behaving well.
+                BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
+                synchronized (stats) {
+                    app.lastWakeTime = stats.getProcessWakeTime(app.info.uid,
+                            app.pid, SystemClock.elapsedRealtime());
+                }
+                app.lastCpuTime = app.curCpuTime;
+            }
+
+            app.setRawAdj = app.curRawAdj;
+        }
+
+        if (app.curAdj != app.setAdj) {
+            ProcessList.setOomAdj(app.pid, app.curAdj);
+            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(
+                TAG, "Set " + app.pid + " " + app.processName +
+                " adj " + app.curAdj + ": " + app.adjType);
+            app.setAdj = app.curAdj;
+        }
+
+        if (app.setSchedGroup != app.curSchedGroup) {
+            app.setSchedGroup = app.curSchedGroup;
+            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                    "Setting process group of " + app.processName
+                    + " to " + app.curSchedGroup);
+            if (app.waitingToKill != null &&
+                    app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
+                killUnneededProcessLocked(app, app.waitingToKill);
+                success = false;
+            } else {
+                if (true) {
+                    long oldId = Binder.clearCallingIdentity();
+                    try {
+                        Process.setProcessGroup(app.pid, app.curSchedGroup);
+                    } catch (Exception e) {
+                        Slog.w(TAG, "Failed setting process group of " + app.pid
+                                + " to " + app.curSchedGroup);
+                        e.printStackTrace();
+                    } finally {
+                        Binder.restoreCallingIdentity(oldId);
+                    }
+                } else {
+                    if (app.thread != null) {
+                        try {
+                            app.thread.setSchedulingGroup(app.curSchedGroup);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                }
+                Process.setSwappiness(app.pid,
+                        app.curSchedGroup <= Process.THREAD_GROUP_BG_NONINTERACTIVE);
+            }
+        }
+        if (app.repProcState != app.curProcState) {
+            app.repProcState = app.curProcState;
+            if (!reportingProcessState && app.thread != null) {
+                try {
+                    if (false) {
+                        //RuntimeException h = new RuntimeException("here");
+                        Slog.i(TAG, "Sending new process state " + app.repProcState
+                                + " to " + app /*, h*/);
+                    }
+                    app.thread.setProcessState(app.repProcState);
+                } catch (RemoteException e) {
+                }
+            }
+        }
+        if (app.setProcState < 0 || ProcessList.procStatesDifferForMem(app.curProcState,
+                app.setProcState)) {
+            app.lastStateTime = now;
+            app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
+                    mSleeping, now);
+            if (DEBUG_PSS) Slog.d(TAG, "Process state change from "
+                    + ProcessList.makeProcStateString(app.setProcState) + " to "
+                    + ProcessList.makeProcStateString(app.curProcState) + " next pss in "
+                    + (app.nextPssTime-now) + ": " + app);
+        } else {
+            if (now > app.nextPssTime || (now > (app.lastPssTime+ProcessList.PSS_MAX_INTERVAL)
+                    && now > (app.lastStateTime+ProcessList.PSS_MIN_TIME_FROM_STATE_CHANGE))) {
+                requestPssLocked(app, app.setProcState);
+                app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, false,
+                        mSleeping, now);
+            } else if (false && DEBUG_PSS) {
+                Slog.d(TAG, "Not requesting PSS of " + app + ": next=" + (app.nextPssTime-now));
+            }
+        }
+        if (app.setProcState != app.curProcState) {
+            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                    "Proc state change of " + app.processName
+                    + " to " + app.curProcState);
+            app.setProcState = app.curProcState;
+            if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) {
+                app.notCachedSinceIdle = false;
+            }
+            if (!doingAll) {
+                setProcessTrackerState(app, mProcessStats.getMemFactorLocked(), now);
+            } else {
+                app.procStateChanged = true;
+            }
+        }
+        return success;
+    }
+
+    private final void setProcessTrackerState(ProcessRecord proc, int memFactor, long now) {
+        if (proc.thread != null && proc.baseProcessTracker != null) {
+            proc.baseProcessTracker.setState(proc.repProcState, memFactor, now, proc.pkgList);
+        }
+    }
+
+    private final boolean updateOomAdjLocked(ProcessRecord app, int cachedAdj,
+            ProcessRecord TOP_APP, boolean doingAll, boolean reportingProcessState, long now) {
+        if (app.thread == null) {
+            return false;
+        }
+
+        final boolean wasKeeping = app.keeping;
+
+        computeOomAdjLocked(app, cachedAdj, TOP_APP, doingAll, now);
+
+        return applyOomAdjLocked(app, wasKeeping, TOP_APP, doingAll,
+                reportingProcessState, now);
+    }
+
+    private final ActivityRecord resumedAppLocked() {
+        return mStackSupervisor.resumedAppLocked();
+    }
+
+    final boolean updateOomAdjLocked(ProcessRecord app) {
+        return updateOomAdjLocked(app, false);
+    }
+
+    final boolean updateOomAdjLocked(ProcessRecord app, boolean doingProcessState) {
+        final ActivityRecord TOP_ACT = resumedAppLocked();
+        final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null;
+        final boolean wasCached = app.cached;
+
+        mAdjSeq++;
+
+        // This is the desired cached adjusment we want to tell it to use.
+        // If our app is currently cached, we know it, and that is it.  Otherwise,
+        // we don't know it yet, and it needs to now be cached we will then
+        // need to do a complete oom adj.
+        final int cachedAdj = app.curRawAdj >= ProcessList.CACHED_APP_MIN_ADJ
+                ? app.curRawAdj : ProcessList.UNKNOWN_ADJ;
+        boolean success = updateOomAdjLocked(app, cachedAdj, TOP_APP, false, doingProcessState,
+                SystemClock.uptimeMillis());
+        if (wasCached != app.cached || app.curRawAdj == ProcessList.UNKNOWN_ADJ) {
+            // Changed to/from cached state, so apps after it in the LRU
+            // list may also be changed.
+            updateOomAdjLocked();
+        }
+        return success;
+    }
+
+    final void updateOomAdjLocked() {
+        final ActivityRecord TOP_ACT = resumedAppLocked();
+        final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null;
+        final long now = SystemClock.uptimeMillis();
+        final long oldTime = now - ProcessList.MAX_EMPTY_TIME;
+        final int N = mLruProcesses.size();
+
+        if (false) {
+            RuntimeException e = new RuntimeException();
+            e.fillInStackTrace();
+            Slog.i(TAG, "updateOomAdj: top=" + TOP_ACT, e);
+        }
+
+        mAdjSeq++;
+        mNewNumServiceProcs = 0;
+        mNewNumAServiceProcs = 0;
+
+        final int emptyProcessLimit;
+        final int cachedProcessLimit;
+        if (mProcessLimit <= 0) {
+            emptyProcessLimit = cachedProcessLimit = 0;
+        } else if (mProcessLimit == 1) {
+            emptyProcessLimit = 1;
+            cachedProcessLimit = 0;
+        } else {
+            emptyProcessLimit = ProcessList.computeEmptyProcessLimit(mProcessLimit);
+            cachedProcessLimit = mProcessLimit - emptyProcessLimit;
+        }
+
+        // Let's determine how many processes we have running vs.
+        // how many slots we have for background processes; we may want
+        // to put multiple processes in a slot of there are enough of
+        // them.
+        int numSlots = (ProcessList.CACHED_APP_MAX_ADJ
+                - ProcessList.CACHED_APP_MIN_ADJ + 1) / 2;
+        int numEmptyProcs = N - mNumNonCachedProcs - mNumCachedHiddenProcs;
+        if (numEmptyProcs > cachedProcessLimit) {
+            // If there are more empty processes than our limit on cached
+            // processes, then use the cached process limit for the factor.
+            // This ensures that the really old empty processes get pushed
+            // down to the bottom, so if we are running low on memory we will
+            // have a better chance at keeping around more cached processes
+            // instead of a gazillion empty processes.
+            numEmptyProcs = cachedProcessLimit;
+        }
+        int emptyFactor = numEmptyProcs/numSlots;
+        if (emptyFactor < 1) emptyFactor = 1;
+        int cachedFactor = (mNumCachedHiddenProcs > 0 ? mNumCachedHiddenProcs : 1)/numSlots;
+        if (cachedFactor < 1) cachedFactor = 1;
+        int stepCached = 0;
+        int stepEmpty = 0;
+        int numCached = 0;
+        int numEmpty = 0;
+        int numTrimming = 0;
+
+        mNumNonCachedProcs = 0;
+        mNumCachedHiddenProcs = 0;
+
+        // First update the OOM adjustment for each of the
+        // application processes based on their current state.
+        int curCachedAdj = ProcessList.CACHED_APP_MIN_ADJ;
+        int nextCachedAdj = curCachedAdj+1;
+        int curEmptyAdj = ProcessList.CACHED_APP_MIN_ADJ;
+        int nextEmptyAdj = curEmptyAdj+2;
+        for (int i=N-1; i>=0; i--) {
+            ProcessRecord app = mLruProcesses.get(i);
+            if (!app.killedByAm && app.thread != null) {
+                app.procStateChanged = false;
+                final boolean wasKeeping = app.keeping;
+                computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now);
+
+                // If we haven't yet assigned the final cached adj
+                // to the process, do that now.
+                if (app.curAdj >= ProcessList.UNKNOWN_ADJ) {
+                    switch (app.curProcState) {
+                        case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY:
+                        case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
+                            // This process is a cached process holding activities...
+                            // assign it the next cached value for that type, and then
+                            // step that cached level.
+                            app.curRawAdj = curCachedAdj;
+                            app.curAdj = app.modifyRawOomAdj(curCachedAdj);
+                            if (DEBUG_LRU && false) Slog.d(TAG, "Assigning activity LRU #" + i
+                                    + " adj: " + app.curAdj + " (curCachedAdj=" + curCachedAdj
+                                    + ")");
+                            if (curCachedAdj != nextCachedAdj) {
+                                stepCached++;
+                                if (stepCached >= cachedFactor) {
+                                    stepCached = 0;
+                                    curCachedAdj = nextCachedAdj;
+                                    nextCachedAdj += 2;
+                                    if (nextCachedAdj > ProcessList.CACHED_APP_MAX_ADJ) {
+                                        nextCachedAdj = ProcessList.CACHED_APP_MAX_ADJ;
+                                    }
+                                }
+                            }
+                            break;
+                        default:
+                            // For everything else, assign next empty cached process
+                            // level and bump that up.  Note that this means that
+                            // long-running services that have dropped down to the
+                            // cached level will be treated as empty (since their process
+                            // state is still as a service), which is what we want.
+                            app.curRawAdj = curEmptyAdj;
+                            app.curAdj = app.modifyRawOomAdj(curEmptyAdj);
+                            if (DEBUG_LRU && false) Slog.d(TAG, "Assigning empty LRU #" + i
+                                    + " adj: " + app.curAdj + " (curEmptyAdj=" + curEmptyAdj
+                                    + ")");
+                            if (curEmptyAdj != nextEmptyAdj) {
+                                stepEmpty++;
+                                if (stepEmpty >= emptyFactor) {
+                                    stepEmpty = 0;
+                                    curEmptyAdj = nextEmptyAdj;
+                                    nextEmptyAdj += 2;
+                                    if (nextEmptyAdj > ProcessList.CACHED_APP_MAX_ADJ) {
+                                        nextEmptyAdj = ProcessList.CACHED_APP_MAX_ADJ;
+                                    }
+                                }
+                            }
+                            break;
+                    }
+                }
+
+                applyOomAdjLocked(app, wasKeeping, TOP_APP, true, false, now);
+
+                // Count the number of process types.
+                switch (app.curProcState) {
+                    case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY:
+                    case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
+                        mNumCachedHiddenProcs++;
+                        numCached++;
+                        if (numCached > cachedProcessLimit) {
+                            killUnneededProcessLocked(app, "cached #" + numCached);
+                        }
+                        break;
+                    case ActivityManager.PROCESS_STATE_CACHED_EMPTY:
+                        if (numEmpty > ProcessList.TRIM_EMPTY_APPS
+                                && app.lastActivityTime < oldTime) {
+                            killUnneededProcessLocked(app, "empty for "
+                                    + ((oldTime + ProcessList.MAX_EMPTY_TIME - app.lastActivityTime)
+                                    / 1000) + "s");
+                        } else {
+                            numEmpty++;
+                            if (numEmpty > emptyProcessLimit) {
+                                killUnneededProcessLocked(app, "empty #" + numEmpty);
+                            }
+                        }
+                        break;
+                    default:
+                        mNumNonCachedProcs++;
+                        break;
+                }
+
+                if (app.isolated && app.services.size() <= 0) {
+                    // If this is an isolated process, and there are no
+                    // services running in it, then the process is no longer
+                    // needed.  We agressively kill these because we can by
+                    // definition not re-use the same process again, and it is
+                    // good to avoid having whatever code was running in them
+                    // left sitting around after no longer needed.
+                    killUnneededProcessLocked(app, "isolated not needed");
+                }
+
+                if (app.curProcState >= ActivityManager.PROCESS_STATE_HOME
+                        && !app.killedByAm) {
+                    numTrimming++;
+                }
+            }
+        }
+
+        mNumServiceProcs = mNewNumServiceProcs;
+
+        // Now determine the memory trimming level of background processes.
+        // Unfortunately we need to start at the back of the list to do this
+        // properly.  We only do this if the number of background apps we
+        // are managing to keep around is less than half the maximum we desire;
+        // if we are keeping a good number around, we'll let them use whatever
+        // memory they want.
+        final int numCachedAndEmpty = numCached + numEmpty;
+        int memFactor;
+        if (numCached <= ProcessList.TRIM_CACHED_APPS
+                && numEmpty <= ProcessList.TRIM_EMPTY_APPS) {
+            if (numCachedAndEmpty <= ProcessList.TRIM_CRITICAL_THRESHOLD) {
+                memFactor = ProcessStats.ADJ_MEM_FACTOR_CRITICAL;
+            } else if (numCachedAndEmpty <= ProcessList.TRIM_LOW_THRESHOLD) {
+                memFactor = ProcessStats.ADJ_MEM_FACTOR_LOW;
+            } else {
+                memFactor = ProcessStats.ADJ_MEM_FACTOR_MODERATE;
+            }
+        } else {
+            memFactor = ProcessStats.ADJ_MEM_FACTOR_NORMAL;
+        }
+        // We always allow the memory level to go up (better).  We only allow it to go
+        // down if we are in a state where that is allowed, *and* the total number of processes
+        // has gone down since last time.
+        if (DEBUG_OOM_ADJ) Slog.d(TAG, "oom: memFactor=" + memFactor + " last=" + mLastMemoryLevel
+                + " allowLow=" + mAllowLowerMemLevel + " numProcs=" + mLruProcesses.size()
+                + " last=" + mLastNumProcesses);
+        if (memFactor > mLastMemoryLevel) {
+            if (!mAllowLowerMemLevel || mLruProcesses.size() >= mLastNumProcesses) {
+                memFactor = mLastMemoryLevel;
+                if (DEBUG_OOM_ADJ) Slog.d(TAG, "Keeping last mem factor!");
+            }
+        }
+        mLastMemoryLevel = memFactor;
+        mLastNumProcesses = mLruProcesses.size();
+        boolean allChanged = mProcessStats.setMemFactorLocked(memFactor, !mSleeping, now);
+        final int trackerMemFactor = mProcessStats.getMemFactorLocked();
+        if (memFactor != ProcessStats.ADJ_MEM_FACTOR_NORMAL) {
+            if (mLowRamStartTime == 0) {
+                mLowRamStartTime = now;
+            }
+            int step = 0;
+            int fgTrimLevel;
+            switch (memFactor) {
+                case ProcessStats.ADJ_MEM_FACTOR_CRITICAL:
+                    fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL;
+                    break;
+                case ProcessStats.ADJ_MEM_FACTOR_LOW:
+                    fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW;
+                    break;
+                default:
+                    fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE;
+                    break;
+            }
+            int factor = numTrimming/3;
+            int minFactor = 2;
+            if (mHomeProcess != null) minFactor++;
+            if (mPreviousProcess != null) minFactor++;
+            if (factor < minFactor) factor = minFactor;
+            int curLevel = ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
+            for (int i=N-1; i>=0; i--) {
+                ProcessRecord app = mLruProcesses.get(i);
+                if (allChanged || app.procStateChanged) {
+                    setProcessTrackerState(app, trackerMemFactor, now);
+                    app.procStateChanged = false;
+                }
+                if (app.curProcState >= ActivityManager.PROCESS_STATE_HOME
+                        && !app.killedByAm) {
+                    if (app.trimMemoryLevel < curLevel && app.thread != null) {
+                        try {
+                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                                    "Trimming memory of " + app.processName
+                                    + " to " + curLevel);
+                            app.thread.scheduleTrimMemory(curLevel);
+                        } catch (RemoteException e) {
+                        }
+                        if (false) {
+                            // For now we won't do this; our memory trimming seems
+                            // to be good enough at this point that destroying
+                            // activities causes more harm than good.
+                            if (curLevel >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE
+                                    && app != mHomeProcess && app != mPreviousProcess) {
+                                // Need to do this on its own message because the stack may not
+                                // be in a consistent state at this point.
+                                // For these apps we will also finish their activities
+                                // to help them free memory.
+                                mStackSupervisor.scheduleDestroyAllActivities(app, "trim");
+                            }
+                        }
+                    }
+                    app.trimMemoryLevel = curLevel;
+                    step++;
+                    if (step >= factor) {
+                        step = 0;
+                        switch (curLevel) {
+                            case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
+                                curLevel = ComponentCallbacks2.TRIM_MEMORY_MODERATE;
+                                break;
+                            case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
+                                curLevel = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND;
+                                break;
+                        }
+                    }
+                } else if (app.curProcState == ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
+                    if (app.trimMemoryLevel < ComponentCallbacks2.TRIM_MEMORY_BACKGROUND
+                            && app.thread != null) {
+                        try {
+                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                                    "Trimming memory of heavy-weight " + app.processName
+                                    + " to " + ComponentCallbacks2.TRIM_MEMORY_BACKGROUND);
+                            app.thread.scheduleTrimMemory(
+                                    ComponentCallbacks2.TRIM_MEMORY_BACKGROUND);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                    app.trimMemoryLevel = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND;
+                } else {
+                    if ((app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+                            || app.systemNoUi) && app.pendingUiClean) {
+                        // If this application is now in the background and it
+                        // had done UI, then give it the special trim level to
+                        // have it free UI resources.
+                        final int level = ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN;
+                        if (app.trimMemoryLevel < level && app.thread != null) {
+                            try {
+                                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                                        "Trimming memory of bg-ui " + app.processName
+                                        + " to " + level);
+                                app.thread.scheduleTrimMemory(level);
+                            } catch (RemoteException e) {
+                            }
+                        }
+                        app.pendingUiClean = false;
+                    }
+                    if (app.trimMemoryLevel < fgTrimLevel && app.thread != null) {
+                        try {
+                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                                    "Trimming memory of fg " + app.processName
+                                    + " to " + fgTrimLevel);
+                            app.thread.scheduleTrimMemory(fgTrimLevel);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                    app.trimMemoryLevel = fgTrimLevel;
+                }
+            }
+        } else {
+            if (mLowRamStartTime != 0) {
+                mLowRamTimeSinceLastIdle += now - mLowRamStartTime;
+                mLowRamStartTime = 0;
+            }
+            for (int i=N-1; i>=0; i--) {
+                ProcessRecord app = mLruProcesses.get(i);
+                if (allChanged || app.procStateChanged) {
+                    setProcessTrackerState(app, trackerMemFactor, now);
+                    app.procStateChanged = false;
+                }
+                if ((app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+                        || app.systemNoUi) && app.pendingUiClean) {
+                    if (app.trimMemoryLevel < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN
+                            && app.thread != null) {
+                        try {
+                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
+                                    "Trimming memory of ui hidden " + app.processName
+                                    + " to " + ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
+                            app.thread.scheduleTrimMemory(
+                                    ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                    app.pendingUiClean = false;
+                }
+                app.trimMemoryLevel = 0;
+            }
+        }
+
+        if (mAlwaysFinishActivities) {
+            // Need to do this on its own message because the stack may not
+            // be in a consistent state at this point.
+            mStackSupervisor.scheduleDestroyAllActivities(null, "always-finish");
+        }
+
+        if (allChanged) {
+            requestPssAllProcsLocked(now, false, mProcessStats.isMemFactorLowered());
+        }
+
+        if (mProcessStats.shouldWriteNowLocked(now)) {
+            mHandler.post(new Runnable() {
+                @Override public void run() {
+                    synchronized (ActivityManagerService.this) {
+                        mProcessStats.writeStateAsyncLocked();
+                    }
+                }
+            });
+        }
+
+        if (DEBUG_OOM_ADJ) {
+            Slog.d(TAG, "Did OOM ADJ in " + (SystemClock.uptimeMillis()-now) + "ms");
+        }
+    }
+
+    final void trimApplications() {
+        synchronized (this) {
+            int i;
+
+            // First remove any unused application processes whose package
+            // has been removed.
+            for (i=mRemovedProcesses.size()-1; i>=0; i--) {
+                final ProcessRecord app = mRemovedProcesses.get(i);
+                if (app.activities.size() == 0
+                        && app.curReceiver == null && app.services.size() == 0) {
+                    Slog.i(
+                        TAG, "Exiting empty application process "
+                        + app.processName + " ("
+                        + (app.thread != null ? app.thread.asBinder() : null)
+                        + ")\n");
+                    if (app.pid > 0 && app.pid != MY_PID) {
+                        EventLog.writeEvent(EventLogTags.AM_KILL, app.userId, app.pid,
+                                app.processName, app.setAdj, "empty");
+                        app.killedByAm = true;
+                        Process.killProcessQuiet(app.pid);
+                    } else {
+                        try {
+                            app.thread.scheduleExit();
+                        } catch (Exception e) {
+                            // Ignore exceptions.
+                        }
+                    }
+                    cleanUpApplicationRecordLocked(app, false, true, -1);
+                    mRemovedProcesses.remove(i);
+                    
+                    if (app.persistent) {
+                        if (app.persistent) {
+                            addAppLocked(app.info, false);
+                        }
+                    }
+                }
+            }
+
+            // Now update the oom adj for all processes.
+            updateOomAdjLocked();
+        }
+    }
+
+    /** This method sends the specified signal to each of the persistent apps */
+    public void signalPersistentProcesses(int sig) throws RemoteException {
+        if (sig != Process.SIGNAL_USR1) {
+            throw new SecurityException("Only SIGNAL_USR1 is allowed");
+        }
+
+        synchronized (this) {
+            if (checkCallingPermission(android.Manifest.permission.SIGNAL_PERSISTENT_PROCESSES)
+                    != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("Requires permission "
+                        + android.Manifest.permission.SIGNAL_PERSISTENT_PROCESSES);
+            }
+
+            for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
+                ProcessRecord r = mLruProcesses.get(i);
+                if (r.thread != null && r.persistent) {
+                    Process.sendSignal(r.pid, sig);
+                }
+            }
+        }
+    }
+
+    private void stopProfilerLocked(ProcessRecord proc, String path, int profileType) {
+        if (proc == null || proc == mProfileProc) {
+            proc = mProfileProc;
+            path = mProfileFile;
+            profileType = mProfileType;
+            clearProfilerLocked();
+        }
+        if (proc == null) {
+            return;
+        }
+        try {
+            proc.thread.profilerControl(false, path, null, profileType);
+        } catch (RemoteException e) {
+            throw new IllegalStateException("Process disappeared");
+        }
+    }
+
+    private void clearProfilerLocked() {
+        if (mProfileFd != null) {
+            try {
+                mProfileFd.close();
+            } catch (IOException e) {
+            }
+        }
+        mProfileApp = null;
+        mProfileProc = null;
+        mProfileFile = null;
+        mProfileType = 0;
+        mAutoStopProfiler = false;
+    }
+
+    public boolean profileControl(String process, int userId, boolean start,
+            String path, ParcelFileDescriptor fd, int profileType) throws RemoteException {
+
+        try {
+            synchronized (this) {
+                // note: hijacking SET_ACTIVITY_WATCHER, but should be changed to
+                // its own permission.
+                if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    throw new SecurityException("Requires permission "
+                            + android.Manifest.permission.SET_ACTIVITY_WATCHER);
+                }
+
+                if (start && fd == null) {
+                    throw new IllegalArgumentException("null fd");
+                }
+
+                ProcessRecord proc = null;
+                if (process != null) {
+                    proc = findProcessLocked(process, userId, "profileControl");
+                }
+
+                if (start && (proc == null || proc.thread == null)) {
+                    throw new IllegalArgumentException("Unknown process: " + process);
+                }
+
+                if (start) {
+                    stopProfilerLocked(null, null, 0);
+                    setProfileApp(proc.info, proc.processName, path, fd, false);
+                    mProfileProc = proc;
+                    mProfileType = profileType;
+                    try {
+                        fd = fd.dup();
+                    } catch (IOException e) {
+                        fd = null;
+                    }
+                    proc.thread.profilerControl(start, path, fd, profileType);
+                    fd = null;
+                    mProfileFd = null;
+                } else {
+                    stopProfilerLocked(proc, path, profileType);
+                    if (fd != null) {
+                        try {
+                            fd.close();
+                        } catch (IOException e) {
+                        }
+                    }
+                }
+
+                return true;
+            }
+        } catch (RemoteException e) {
+            throw new IllegalStateException("Process disappeared");
+        } finally {
+            if (fd != null) {
+                try {
+                    fd.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    private ProcessRecord findProcessLocked(String process, int userId, String callName) {
+        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
+                userId, true, true, callName, null);
+        ProcessRecord proc = null;
+        try {
+            int pid = Integer.parseInt(process);
+            synchronized (mPidsSelfLocked) {
+                proc = mPidsSelfLocked.get(pid);
+            }
+        } catch (NumberFormatException e) {
+        }
+
+        if (proc == null) {
+            ArrayMap<String, SparseArray<ProcessRecord>> all
+                    = mProcessNames.getMap();
+            SparseArray<ProcessRecord> procs = all.get(process);
+            if (procs != null && procs.size() > 0) {
+                proc = procs.valueAt(0);
+                if (userId != UserHandle.USER_ALL && proc.userId != userId) {
+                    for (int i=1; i<procs.size(); i++) {
+                        ProcessRecord thisProc = procs.valueAt(i);
+                        if (thisProc.userId == userId) {
+                            proc = thisProc;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+
+        return proc;
+    }
+
+    public boolean dumpHeap(String process, int userId, boolean managed,
+            String path, ParcelFileDescriptor fd) throws RemoteException {
+
+        try {
+            synchronized (this) {
+                // note: hijacking SET_ACTIVITY_WATCHER, but should be changed to
+                // its own permission (same as profileControl).
+                if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    throw new SecurityException("Requires permission "
+                            + android.Manifest.permission.SET_ACTIVITY_WATCHER);
+                }
+
+                if (fd == null) {
+                    throw new IllegalArgumentException("null fd");
+                }
+
+                ProcessRecord proc = findProcessLocked(process, userId, "dumpHeap");
+                if (proc == null || proc.thread == null) {
+                    throw new IllegalArgumentException("Unknown process: " + process);
+                }
+
+                boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+                if (!isDebuggable) {
+                    if ((proc.info.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
+                        throw new SecurityException("Process not debuggable: " + proc);
+                    }
+                }
+
+                proc.thread.dumpHeap(managed, path, fd);
+                fd = null;
+                return true;
+            }
+        } catch (RemoteException e) {
+            throw new IllegalStateException("Process disappeared");
+        } finally {
+            if (fd != null) {
+                try {
+                    fd.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    /** In this method we try to acquire our lock to make sure that we have not deadlocked */
+    public void monitor() {
+        synchronized (this) { }
+    }
+
+    void onCoreSettingsChange(Bundle settings) {
+        for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
+            ProcessRecord processRecord = mLruProcesses.get(i);
+            try {
+                if (processRecord.thread != null) {
+                    processRecord.thread.setCoreSettings(settings);
+                }
+            } catch (RemoteException re) {
+                /* ignore */
+            }
+        }
+    }
+
+    // Multi-user methods
+
+    @Override
+    public boolean switchUser(final int userId) {
+        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: switchUser() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized (this) {
+                final int oldUserId = mCurrentUserId;
+                if (oldUserId == userId) {
+                    return true;
+                }
+
+                final UserInfo userInfo = getUserManagerLocked().getUserInfo(userId);
+                if (userInfo == null) {
+                    Slog.w(TAG, "No user info for user #" + userId);
+                    return false;
+                }
+
+                mWindowManager.startFreezingScreen(R.anim.screen_user_exit,
+                        R.anim.screen_user_enter);
+
+                boolean needStart = false;
+
+                // If the user we are switching to is not currently started, then
+                // we need to start it now.
+                if (mStartedUsers.get(userId) == null) {
+                    mStartedUsers.put(userId, new UserStartedState(new UserHandle(userId), false));
+                    updateStartedUserArrayLocked();
+                    needStart = true;
+                }
+
+                mCurrentUserId = userId;
+                final Integer userIdInt = Integer.valueOf(userId);
+                mUserLru.remove(userIdInt);
+                mUserLru.add(userIdInt);
+
+                mWindowManager.setCurrentUser(userId);
+
+                // Once the internal notion of the active user has switched, we lock the device
+                // with the option to show the user switcher on the keyguard.
+                mWindowManager.lockNow(null);
+
+                final UserStartedState uss = mStartedUsers.get(userId);
+
+                // Make sure user is in the started state.  If it is currently
+                // stopping, we need to knock that off.
+                if (uss.mState == UserStartedState.STATE_STOPPING) {
+                    // If we are stopping, we haven't sent ACTION_SHUTDOWN,
+                    // so we can just fairly silently bring the user back from
+                    // the almost-dead.
+                    uss.mState = UserStartedState.STATE_RUNNING;
+                    updateStartedUserArrayLocked();
+                    needStart = true;
+                } else if (uss.mState == UserStartedState.STATE_SHUTDOWN) {
+                    // This means ACTION_SHUTDOWN has been sent, so we will
+                    // need to treat this as a new boot of the user.
+                    uss.mState = UserStartedState.STATE_BOOTING;
+                    updateStartedUserArrayLocked();
+                    needStart = true;
+                }
+
+                mHandler.removeMessages(REPORT_USER_SWITCH_MSG);
+                mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG);
+                mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_MSG,
+                        oldUserId, userId, uss));
+                mHandler.sendMessageDelayed(mHandler.obtainMessage(USER_SWITCH_TIMEOUT_MSG,
+                        oldUserId, userId, uss), USER_SWITCH_TIMEOUT);
+                if (needStart) {
+                    Intent intent = new Intent(Intent.ACTION_USER_STARTED);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                            | Intent.FLAG_RECEIVER_FOREGROUND);
+                    intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
+                    broadcastIntentLocked(null, null, intent,
+                            null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                            false, false, MY_PID, Process.SYSTEM_UID, userId);
+                }
+
+                if ((userInfo.flags&UserInfo.FLAG_INITIALIZED) == 0) {
+                    if (userId != 0) {
+                        Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE);
+                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
+                        broadcastIntentLocked(null, null, intent, null,
+                                new IIntentReceiver.Stub() {
+                                    public void performReceive(Intent intent, int resultCode,
+                                            String data, Bundle extras, boolean ordered,
+                                            boolean sticky, int sendingUser) {
+                                        userInitialized(uss, userId);
+                                    }
+                                }, 0, null, null, null, AppOpsManager.OP_NONE,
+                                true, false, MY_PID, Process.SYSTEM_UID,
+                                userId);
+                        uss.initializing = true;
+                    } else {
+                        getUserManagerLocked().makeInitialized(userInfo.id);
+                    }
+                }
+
+                boolean homeInFront = mStackSupervisor.switchUserLocked(userId, uss);
+                if (homeInFront) {
+                    startHomeActivityLocked(userId);
+                } else {
+                    mStackSupervisor.resumeTopActivitiesLocked();
+                }
+
+                EventLogTags.writeAmSwitchUser(userId);
+                getUserManagerLocked().userForeground(userId);
+                sendUserSwitchBroadcastsLocked(oldUserId, userId);
+                if (needStart) {
+                    Intent intent = new Intent(Intent.ACTION_USER_STARTING);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                    intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
+                    broadcastIntentLocked(null, null, intent,
+                            null, new IIntentReceiver.Stub() {
+                                @Override
+                                public void performReceive(Intent intent, int resultCode, String data,
+                                        Bundle extras, boolean ordered, boolean sticky, int sendingUser)
+                                        throws RemoteException {
+                                }
+                            }, 0, null, null,
+                            android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
+                            true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+
+        return true;
+    }
+
+    void sendUserSwitchBroadcastsLocked(int oldUserId, int newUserId) {
+        long ident = Binder.clearCallingIdentity();
+        try {
+            Intent intent;
+            if (oldUserId >= 0) {
+                intent = new Intent(Intent.ACTION_USER_BACKGROUND);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                        | Intent.FLAG_RECEIVER_FOREGROUND);
+                intent.putExtra(Intent.EXTRA_USER_HANDLE, oldUserId);
+                broadcastIntentLocked(null, null, intent,
+                        null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                        false, false, MY_PID, Process.SYSTEM_UID, oldUserId);
+            }
+            if (newUserId >= 0) {
+                intent = new Intent(Intent.ACTION_USER_FOREGROUND);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                        | Intent.FLAG_RECEIVER_FOREGROUND);
+                intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId);
+                broadcastIntentLocked(null, null, intent,
+                        null, null, 0, null, null, null, AppOpsManager.OP_NONE,
+                        false, false, MY_PID, Process.SYSTEM_UID, newUserId);
+                intent = new Intent(Intent.ACTION_USER_SWITCHED);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+                        | Intent.FLAG_RECEIVER_FOREGROUND);
+                intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId);
+                broadcastIntentLocked(null, null, intent,
+                        null, null, 0, null, null,
+                        android.Manifest.permission.MANAGE_USERS, AppOpsManager.OP_NONE,
+                        false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    void dispatchUserSwitch(final UserStartedState uss, final int oldUserId,
+            final int newUserId) {
+        final int N = mUserSwitchObservers.beginBroadcast();
+        if (N > 0) {
+            final IRemoteCallback callback = new IRemoteCallback.Stub() {
+                int mCount = 0;
+                @Override
+                public void sendResult(Bundle data) throws RemoteException {
+                    synchronized (ActivityManagerService.this) {
+                        if (mCurUserSwitchCallback == this) {
+                            mCount++;
+                            if (mCount == N) {
+                                sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
+                            }
+                        }
+                    }
+                }
+            };
+            synchronized (this) {
+                uss.switching = true;
+                mCurUserSwitchCallback = callback;
+            }
+            for (int i=0; i<N; i++) {
+                try {
+                    mUserSwitchObservers.getBroadcastItem(i).onUserSwitching(
+                            newUserId, callback);
+                } catch (RemoteException e) {
+                }
+            }
+        } else {
+            synchronized (this) {
+                sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
+            }
+        }
+        mUserSwitchObservers.finishBroadcast();
+    }
+
+    void timeoutUserSwitch(UserStartedState uss, int oldUserId, int newUserId) {
+        synchronized (this) {
+            Slog.w(TAG, "User switch timeout: from " + oldUserId + " to " + newUserId);
+            sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
+        }
+    }
+
+    void sendContinueUserSwitchLocked(UserStartedState uss, int oldUserId, int newUserId) {
+        mCurUserSwitchCallback = null;
+        mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG);
+        mHandler.sendMessage(mHandler.obtainMessage(CONTINUE_USER_SWITCH_MSG,
+                oldUserId, newUserId, uss));
+    }
+
+    void userInitialized(UserStartedState uss, int newUserId) {
+        completeSwitchAndInitalize(uss, newUserId, true, false);
+    }
+
+    void continueUserSwitch(UserStartedState uss, int oldUserId, int newUserId) {
+        completeSwitchAndInitalize(uss, newUserId, false, true);
+    }
+
+    void completeSwitchAndInitalize(UserStartedState uss, int newUserId,
+            boolean clearInitializing, boolean clearSwitching) {
+        boolean unfrozen = false;
+        synchronized (this) {
+            if (clearInitializing) {
+                uss.initializing = false;
+                getUserManagerLocked().makeInitialized(uss.mHandle.getIdentifier());
+            }
+            if (clearSwitching) {
+                uss.switching = false;
+            }
+            if (!uss.switching && !uss.initializing) {
+                mWindowManager.stopFreezingScreen();
+                unfrozen = true;
+            }
+        }
+        if (unfrozen) {
+            final int N = mUserSwitchObservers.beginBroadcast();
+            for (int i=0; i<N; i++) {
+                try {
+                    mUserSwitchObservers.getBroadcastItem(i).onUserSwitchComplete(newUserId);
+                } catch (RemoteException e) {
+                }
+            }
+            mUserSwitchObservers.finishBroadcast();
+        }
+    }
+
+    void finishUserSwitch(UserStartedState uss) {
+        synchronized (this) {
+            if (uss.mState == UserStartedState.STATE_BOOTING
+                    && mStartedUsers.get(uss.mHandle.getIdentifier()) == uss) {
+                uss.mState = UserStartedState.STATE_RUNNING;
+                final int userId = uss.mHandle.getIdentifier();
+                Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
+                intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
+                intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT);
+                broadcastIntentLocked(null, null, intent,
+                        null, null, 0, null, null,
+                        android.Manifest.permission.RECEIVE_BOOT_COMPLETED, AppOpsManager.OP_NONE,
+                        true, false, MY_PID, Process.SYSTEM_UID, userId);
+            }
+            int num = mUserLru.size();
+            int i = 0;
+            while (num > MAX_RUNNING_USERS && i < mUserLru.size()) {
+                Integer oldUserId = mUserLru.get(i);
+                UserStartedState oldUss = mStartedUsers.get(oldUserId);
+                if (oldUss == null) {
+                    // Shouldn't happen, but be sane if it does.
+                    mUserLru.remove(i);
+                    num--;
+                    continue;
+                }
+                if (oldUss.mState == UserStartedState.STATE_STOPPING
+                        || oldUss.mState == UserStartedState.STATE_SHUTDOWN) {
+                    // This user is already stopping, doesn't count.
+                    num--;
+                    i++;
+                    continue;
+                }
+                if (oldUserId == UserHandle.USER_OWNER || oldUserId == mCurrentUserId) {
+                    // Owner and current can't be stopped, but count as running.
+                    i++;
+                    continue;
+                }
+                // This is a user to be stopped.
+                stopUserLocked(oldUserId, null);
+                num--;
+                i++;
+            }
+        }
+    }
+
+    @Override
+    public int stopUser(final int userId, final IStopUserCallback callback) {
+        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: switchUser() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+        if (userId <= 0) {
+            throw new IllegalArgumentException("Can't stop primary user " + userId);
+        }
+        synchronized (this) {
+            return stopUserLocked(userId, callback);
+        }
+    }
+
+    private int stopUserLocked(final int userId, final IStopUserCallback callback) {
+        if (mCurrentUserId == userId) {
+            return ActivityManager.USER_OP_IS_CURRENT;
+        }
+
+        final UserStartedState uss = mStartedUsers.get(userId);
+        if (uss == null) {
+            // User is not started, nothing to do...  but we do need to
+            // callback if requested.
+            if (callback != null) {
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            callback.userStopped(userId);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                });
+            }
+            return ActivityManager.USER_OP_SUCCESS;
+        }
+
+        if (callback != null) {
+            uss.mStopCallbacks.add(callback);
+        }
+
+        if (uss.mState != UserStartedState.STATE_STOPPING
+                && uss.mState != UserStartedState.STATE_SHUTDOWN) {
+            uss.mState = UserStartedState.STATE_STOPPING;
+            updateStartedUserArrayLocked();
+
+            long ident = Binder.clearCallingIdentity();
+            try {
+                // We are going to broadcast ACTION_USER_STOPPING and then
+                // once that is done send a final ACTION_SHUTDOWN and then
+                // stop the user.
+                final Intent stoppingIntent = new Intent(Intent.ACTION_USER_STOPPING);
+                stoppingIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                stoppingIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
+                stoppingIntent.putExtra(Intent.EXTRA_SHUTDOWN_USERSPACE_ONLY, true);
+                final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN);
+                // This is the result receiver for the final shutdown broadcast.
+                final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() {
+                    @Override
+                    public void performReceive(Intent intent, int resultCode, String data,
+                            Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
+                        finishUserStop(uss);
+                    }
+                };
+                // This is the result receiver for the initial stopping broadcast.
+                final IIntentReceiver stoppingReceiver = new IIntentReceiver.Stub() {
+                    @Override
+                    public void performReceive(Intent intent, int resultCode, String data,
+                            Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
+                        // On to the next.
+                        synchronized (ActivityManagerService.this) {
+                            if (uss.mState != UserStartedState.STATE_STOPPING) {
+                                // Whoops, we are being started back up.  Abort, abort!
+                                return;
+                            }
+                            uss.mState = UserStartedState.STATE_SHUTDOWN;
+                        }
+                        broadcastIntentLocked(null, null, shutdownIntent,
+                                null, shutdownReceiver, 0, null, null, null, AppOpsManager.OP_NONE,
+                                true, false, MY_PID, Process.SYSTEM_UID, userId);
+                    }
+                };
+                // Kick things off.
+                broadcastIntentLocked(null, null, stoppingIntent,
+                        null, stoppingReceiver, 0, null, null,
+                        android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
+                        true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        return ActivityManager.USER_OP_SUCCESS;
+    }
+
+    void finishUserStop(UserStartedState uss) {
+        final int userId = uss.mHandle.getIdentifier();
+        boolean stopped;
+        ArrayList<IStopUserCallback> callbacks;
+        synchronized (this) {
+            callbacks = new ArrayList<IStopUserCallback>(uss.mStopCallbacks);
+            if (mStartedUsers.get(userId) != uss) {
+                stopped = false;
+            } else if (uss.mState != UserStartedState.STATE_SHUTDOWN) {
+                stopped = false;
+            } else {
+                stopped = true;
+                // User can no longer run.
+                mStartedUsers.remove(userId);
+                mUserLru.remove(Integer.valueOf(userId));
+                updateStartedUserArrayLocked();
+
+                // Clean up all state and processes associated with the user.
+                // Kill all the processes for the user.
+                forceStopUserLocked(userId, "finish user");
+            }
+        }
+
+        for (int i=0; i<callbacks.size(); i++) {
+            try {
+                if (stopped) callbacks.get(i).userStopped(userId);
+                else callbacks.get(i).userStopAborted(userId);
+            } catch (RemoteException e) {
+            }
+        }
+
+        mStackSupervisor.removeUserLocked(userId);
+    }
+
+    @Override
+    public UserInfo getCurrentUser() {
+        if ((checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
+                != PackageManager.PERMISSION_GRANTED) && (
+                checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+                != PackageManager.PERMISSION_GRANTED)) {
+            String msg = "Permission Denial: getCurrentUser() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+        synchronized (this) {
+            return getUserManagerLocked().getUserInfo(mCurrentUserId);
+        }
+    }
+
+    int getCurrentUserIdLocked() {
+        return mCurrentUserId;
+    }
+
+    @Override
+    public boolean isUserRunning(int userId, boolean orStopped) {
+        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: isUserRunning() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+        synchronized (this) {
+            return isUserRunningLocked(userId, orStopped);
+        }
+    }
+
+    boolean isUserRunningLocked(int userId, boolean orStopped) {
+        UserStartedState state = mStartedUsers.get(userId);
+        if (state == null) {
+            return false;
+        }
+        if (orStopped) {
+            return true;
+        }
+        return state.mState != UserStartedState.STATE_STOPPING
+                && state.mState != UserStartedState.STATE_SHUTDOWN;
+    }
+
+    @Override
+    public int[] getRunningUserIds() {
+        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: isUserRunning() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+        synchronized (this) {
+            return mStartedUserArray;
+        }
+    }
+
+    private void updateStartedUserArrayLocked() {
+        int num = 0;
+        for (int i=0; i<mStartedUsers.size();  i++) {
+            UserStartedState uss = mStartedUsers.valueAt(i);
+            // This list does not include stopping users.
+            if (uss.mState != UserStartedState.STATE_STOPPING
+                    && uss.mState != UserStartedState.STATE_SHUTDOWN) {
+                num++;
+            }
+        }
+        mStartedUserArray = new int[num];
+        num = 0;
+        for (int i=0; i<mStartedUsers.size();  i++) {
+            UserStartedState uss = mStartedUsers.valueAt(i);
+            if (uss.mState != UserStartedState.STATE_STOPPING
+                    && uss.mState != UserStartedState.STATE_SHUTDOWN) {
+                mStartedUserArray[num] = mStartedUsers.keyAt(i);
+                num++;
+            }
+        }
+    }
+
+    @Override
+    public void registerUserSwitchObserver(IUserSwitchObserver observer) {
+        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+                != PackageManager.PERMISSION_GRANTED) {
+            String msg = "Permission Denial: registerUserSwitchObserver() from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        mUserSwitchObservers.register(observer);
+    }
+
+    @Override
+    public void unregisterUserSwitchObserver(IUserSwitchObserver observer) {
+        mUserSwitchObservers.unregister(observer);
+    }
+
+    private boolean userExists(int userId) {
+        if (userId == 0) {
+            return true;
+        }
+        UserManagerService ums = getUserManagerLocked();
+        return ums != null ? (ums.getUserInfo(userId) != null) : false;
+    }
+
+    int[] getUsersLocked() {
+        UserManagerService ums = getUserManagerLocked();
+        return ums != null ? ums.getUserIds() : new int[] { 0 };
+    }
+
+    UserManagerService getUserManagerLocked() {
+        if (mUserManager == null) {
+            IBinder b = ServiceManager.getService(Context.USER_SERVICE);
+            mUserManager = (UserManagerService)IUserManager.Stub.asInterface(b);
+        }
+        return mUserManager;
+    }
+
+    private int applyUserId(int uid, int userId) {
+        return UserHandle.getUid(userId, uid);
+    }
+
+    ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) {
+        if (info == null) return null;
+        ApplicationInfo newInfo = new ApplicationInfo(info);
+        newInfo.uid = applyUserId(info.uid, userId);
+        newInfo.dataDir = USER_DATA_DIR + userId + "/"
+                + info.packageName;
+        return newInfo;
+    }
+
+    ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId) {
+        if (aInfo == null
+                || (userId < 1 && aInfo.applicationInfo.uid < UserHandle.PER_USER_RANGE)) {
+            return aInfo;
+        }
+
+        ActivityInfo info = new ActivityInfo(aInfo);
+        info.applicationInfo = getAppInfoForUser(info.applicationInfo, userId);
+        return info;
+    }
+}
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
new file mode 100644
index 0000000..a27288a
--- /dev/null
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -0,0 +1,1071 @@
+/*
+ * Copyright (C) 2006 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.os.Trace;
+import com.android.internal.R.styleable;
+import com.android.internal.app.ResolverActivity;
+import com.android.server.AttributeCache;
+import com.android.server.am.ActivityStack.ActivityState;
+import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
+
+import android.app.ActivityOptions;
+import android.app.ResultInfo;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.res.CompatibilityInfo;
+import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Slog;
+import android.util.TimeUtils;
+import android.view.IApplicationToken;
+import android.view.WindowManager;
+
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashSet;
+
+/**
+ * An entry in the history stack, representing an activity.
+ */
+final class ActivityRecord {
+    static final String TAG = ActivityManagerService.TAG;
+    static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
+    final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recent";
+
+    final ActivityManagerService service; // owner
+    final IApplicationToken.Stub appToken; // window manager token
+    final ActivityInfo info; // all about me
+    final int launchedFromUid; // always the uid who started the activity.
+    final String launchedFromPackage; // always the package who started the activity.
+    final int userId;          // Which user is this running for?
+    final Intent intent;    // the original intent that generated us
+    final ComponentName realActivity;  // the intent component, or target of an alias.
+    final String shortComponentName; // the short component name of the intent
+    final String resolvedType; // as per original caller;
+    final String packageName; // the package implementing intent's component
+    final String processName; // process where this component wants to run
+    final String taskAffinity; // as per ActivityInfo.taskAffinity
+    final boolean stateNotNeeded; // As per ActivityInfo.flags
+    boolean fullscreen; // covers the full screen?
+    final boolean noDisplay;  // activity is not displayed?
+    final boolean componentSpecified;  // did caller specifiy an explicit component?
+
+    static final int APPLICATION_ACTIVITY_TYPE = 0;
+    static final int HOME_ACTIVITY_TYPE = 1;
+    static final int RECENTS_ACTIVITY_TYPE = 2;
+    int mActivityType;
+
+    final String baseDir;   // where activity source (resources etc) located
+    final String resDir;   // where public activity source (public resources etc) located
+    final String dataDir;   // where activity data should go
+    CharSequence nonLocalizedLabel;  // the label information from the package mgr.
+    int labelRes;           // the label information from the package mgr.
+    int icon;               // resource identifier of activity's icon.
+    int logo;               // resource identifier of activity's logo.
+    int theme;              // resource identifier of activity's theme.
+    int realTheme;          // actual theme resource we will use, never 0.
+    int windowFlags;        // custom window flags for preview window.
+    TaskRecord task;        // the task this is in.
+    ThumbnailHolder thumbHolder; // where our thumbnails should go.
+    long displayStartTime;  // when we started launching this activity
+    long fullyDrawnStartTime; // when we started launching this activity
+    long startTime;         // last time this activity was started
+    long lastVisibleTime;   // last time this activity became visible
+    long cpuTimeAtResume;   // the cpu time of host process at the time of resuming activity
+    long pauseTime;         // last time we started pausing the activity
+    long launchTickTime;    // base time for launch tick messages
+    Configuration configuration; // configuration activity was last running in
+    CompatibilityInfo compat;// last used compatibility mode
+    ActivityRecord resultTo; // who started this entry, so will get our reply
+    final String resultWho; // additional identifier for use by resultTo.
+    final int requestCode;  // code given by requester (resultTo)
+    ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
+    HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
+    ArrayList<Intent> newIntents; // any pending new intents for single-top mode
+    ActivityOptions pendingOptions; // most recently given options
+    HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
+    UriPermissionOwner uriPermissions; // current special URI access perms.
+    ProcessRecord app;      // if non-null, hosting application
+    ActivityState state;    // current state we are in
+    Bundle  icicle;         // last saved activity state
+    boolean frontOfTask;    // is this the root activity of its task?
+    boolean launchFailed;   // set if a launched failed, to abort on 2nd try
+    boolean haveState;      // have we gotten the last activity state?
+    boolean stopped;        // is activity pause finished?
+    boolean delayedResume;  // not yet resumed because of stopped app switches?
+    boolean finishing;      // activity in pending finish list?
+    boolean configDestroy;  // need to destroy due to config change?
+    int configChangeFlags;  // which config values have changed
+    boolean keysPaused;     // has key dispatching been paused for it?
+    int launchMode;         // the launch mode activity attribute.
+    boolean visible;        // does this activity's window need to be shown?
+    boolean sleeping;       // have we told the activity to sleep?
+    boolean waitingVisible; // true if waiting for a new act to become vis
+    boolean nowVisible;     // is this activity's window visible?
+    boolean thumbnailNeeded;// has someone requested a thumbnail?
+    boolean idle;           // has the activity gone idle?
+    boolean hasBeenLaunched;// has this activity ever been launched?
+    boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
+    boolean immersive;      // immersive mode (don't interrupt if possible)
+    boolean forceNewConfig; // force re-create with new config next time
+    int launchCount;        // count of launches since last state
+    long lastLaunchTime;    // time of last lauch of this activity
+    ArrayList<ActivityStack> mChildContainers = new ArrayList<ActivityStack>();
+
+    String stringName;      // for caching of toString().
+
+    private boolean inHistory;  // are we in the history stack?
+    final ActivityStackSupervisor mStackSupervisor;
+    ActivityContainer mInitialActivityContainer;
+
+    void dump(PrintWriter pw, String prefix) {
+        final long now = SystemClock.uptimeMillis();
+        pw.print(prefix); pw.print("packageName="); pw.print(packageName);
+                pw.print(" processName="); pw.println(processName);
+        pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
+                pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
+                pw.print(" userId="); pw.println(userId);
+        pw.print(prefix); pw.print("app="); pw.println(app);
+        pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
+        pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
+                pw.print(" task="); pw.println(task);
+        pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
+        pw.print(prefix); pw.print("realActivity=");
+                pw.println(realActivity.flattenToShortString());
+        pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
+        if (!resDir.equals(baseDir)) {
+            pw.print(prefix); pw.print("resDir="); pw.println(resDir);
+        }
+        pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
+        pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
+                pw.print(" componentSpecified="); pw.print(componentSpecified);
+                pw.print(" mActivityType="); pw.println(mActivityType);
+        pw.print(prefix); pw.print("compat="); pw.print(compat);
+                pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
+                pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
+                pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
+        pw.print(prefix); pw.print("config="); pw.println(configuration);
+        if (resultTo != null || resultWho != null) {
+            pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
+                    pw.print(" resultWho="); pw.print(resultWho);
+                    pw.print(" resultCode="); pw.println(requestCode);
+        }
+        if (results != null) {
+            pw.print(prefix); pw.print("results="); pw.println(results);
+        }
+        if (pendingResults != null && pendingResults.size() > 0) {
+            pw.print(prefix); pw.println("Pending Results:");
+            for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
+                PendingIntentRecord pir = wpir != null ? wpir.get() : null;
+                pw.print(prefix); pw.print("  - ");
+                if (pir == null) {
+                    pw.println("null");
+                } else {
+                    pw.println(pir);
+                    pir.dump(pw, prefix + "    ");
+                }
+            }
+        }
+        if (newIntents != null && newIntents.size() > 0) {
+            pw.print(prefix); pw.println("Pending New Intents:");
+            for (int i=0; i<newIntents.size(); i++) {
+                Intent intent = newIntents.get(i);
+                pw.print(prefix); pw.print("  - ");
+                if (intent == null) {
+                    pw.println("null");
+                } else {
+                    pw.println(intent.toShortString(false, true, false, true));
+                }
+            }
+        }
+        if (pendingOptions != null) {
+            pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
+        }
+        if (uriPermissions != null) {
+            if (uriPermissions.readUriPermissions != null) {
+                pw.print(prefix); pw.print("readUriPermissions=");
+                        pw.println(uriPermissions.readUriPermissions);
+            }
+            if (uriPermissions.writeUriPermissions != null) {
+                pw.print(prefix); pw.print("writeUriPermissions=");
+                        pw.println(uriPermissions.writeUriPermissions);
+            }
+        }
+        pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
+                pw.print(" launchCount="); pw.print(launchCount);
+                pw.print(" lastLaunchTime=");
+                if (lastLaunchTime == 0) pw.print("0");
+                else TimeUtils.formatDuration(lastLaunchTime, now, pw);
+                pw.println();
+        pw.print(prefix); pw.print("haveState="); pw.print(haveState);
+                pw.print(" icicle="); pw.println(icicle);
+        pw.print(prefix); pw.print("state="); pw.print(state);
+                pw.print(" stopped="); pw.print(stopped);
+                pw.print(" delayedResume="); pw.print(delayedResume);
+                pw.print(" finishing="); pw.println(finishing);
+        pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
+                pw.print(" inHistory="); pw.print(inHistory);
+                pw.print(" visible="); pw.print(visible);
+                pw.print(" sleeping="); pw.print(sleeping);
+                pw.print(" idle="); pw.println(idle);
+        pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
+                pw.print(" noDisplay="); pw.print(noDisplay);
+                pw.print(" immersive="); pw.print(immersive);
+                pw.print(" launchMode="); pw.println(launchMode);
+        pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
+                pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
+                pw.print(" forceNewConfig="); pw.println(forceNewConfig);
+        pw.print(prefix); pw.print("mActivityType=");
+                pw.println(activityTypeToString(mActivityType));
+        pw.print(prefix); pw.print("thumbHolder: ");
+                pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
+                if (thumbHolder != null) {
+                    pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
+                    pw.print(" desc="); pw.print(thumbHolder.lastDescription);
+                }
+                pw.println();
+        if (displayStartTime != 0 || startTime != 0) {
+            pw.print(prefix); pw.print("displayStartTime=");
+                    if (displayStartTime == 0) pw.print("0");
+                    else TimeUtils.formatDuration(displayStartTime, now, pw);
+                    pw.print(" startTime=");
+                    if (startTime == 0) pw.print("0");
+                    else TimeUtils.formatDuration(startTime, now, pw);
+                    pw.println();
+        }
+        if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
+            pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
+                    pw.print(" nowVisible="); pw.print(nowVisible);
+                    pw.print(" lastVisibleTime=");
+                    if (lastVisibleTime == 0) pw.print("0");
+                    else TimeUtils.formatDuration(lastVisibleTime, now, pw);
+                    pw.println();
+        }
+        if (configDestroy || configChangeFlags != 0) {
+            pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
+                    pw.print(" configChangeFlags=");
+                    pw.println(Integer.toHexString(configChangeFlags));
+        }
+        if (connections != null) {
+            pw.print(prefix); pw.print("connections="); pw.println(connections);
+        }
+    }
+
+    static class Token extends IApplicationToken.Stub {
+        final WeakReference<ActivityRecord> weakActivity;
+
+        Token(ActivityRecord activity) {
+            weakActivity = new WeakReference<ActivityRecord>(activity);
+        }
+
+        @Override public void windowsDrawn() {
+            ActivityRecord activity = weakActivity.get();
+            if (activity != null) {
+                activity.windowsDrawn();
+            }
+        }
+
+        @Override public void windowsVisible() {
+            ActivityRecord activity = weakActivity.get();
+            if (activity != null) {
+                activity.windowsVisible();
+            }
+        }
+
+        @Override public void windowsGone() {
+            ActivityRecord activity = weakActivity.get();
+            if (activity != null) {
+                activity.windowsGone();
+            }
+        }
+
+        @Override public boolean keyDispatchingTimedOut(String reason) {
+            ActivityRecord activity = weakActivity.get();
+            return activity != null && activity.keyDispatchingTimedOut(reason);
+        }
+
+        @Override public long getKeyDispatchingTimeout() {
+            ActivityRecord activity = weakActivity.get();
+            if (activity != null) {
+                return activity.getKeyDispatchingTimeout();
+            }
+            return 0;
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("Token{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(' ');
+            sb.append(weakActivity.get());
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+    static ActivityRecord forToken(IBinder token) {
+        try {
+            return token != null ? ((Token)token).weakActivity.get() : null;
+        } catch (ClassCastException e) {
+            Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
+            return null;
+        }
+    }
+
+    boolean isNotResolverActivity() {
+        return !ResolverActivity.class.getName().equals(realActivity.getClassName());
+    }
+
+    ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
+            int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
+            ActivityInfo aInfo, Configuration _configuration,
+            ActivityRecord _resultTo, String _resultWho, int _reqCode,
+            boolean _componentSpecified, ActivityStackSupervisor supervisor,
+            ActivityContainer container) {
+        service = _service;
+        appToken = new Token(this);
+        info = aInfo;
+        launchedFromUid = _launchedFromUid;
+        launchedFromPackage = _launchedFromPackage;
+        userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
+        intent = _intent;
+        shortComponentName = _intent.getComponent().flattenToShortString();
+        resolvedType = _resolvedType;
+        componentSpecified = _componentSpecified;
+        configuration = _configuration;
+        resultTo = _resultTo;
+        resultWho = _resultWho;
+        requestCode = _reqCode;
+        state = ActivityState.INITIALIZING;
+        frontOfTask = false;
+        launchFailed = false;
+        stopped = false;
+        delayedResume = false;
+        finishing = false;
+        configDestroy = false;
+        keysPaused = false;
+        inHistory = false;
+        visible = true;
+        waitingVisible = false;
+        nowVisible = false;
+        thumbnailNeeded = false;
+        idle = false;
+        hasBeenLaunched = false;
+        mStackSupervisor = supervisor;
+        mInitialActivityContainer = container;
+
+        // This starts out true, since the initial state of an activity
+        // is that we have everything, and we shouldn't never consider it
+        // lacking in state to be removed if it dies.
+        haveState = true;
+
+        if (aInfo != null) {
+            if (aInfo.targetActivity == null
+                    || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
+                    || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
+                realActivity = _intent.getComponent();
+            } else {
+                realActivity = new ComponentName(aInfo.packageName,
+                        aInfo.targetActivity);
+            }
+            taskAffinity = aInfo.taskAffinity;
+            stateNotNeeded = (aInfo.flags&
+                    ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
+            baseDir = aInfo.applicationInfo.sourceDir;
+            resDir = aInfo.applicationInfo.publicSourceDir;
+            dataDir = aInfo.applicationInfo.dataDir;
+            nonLocalizedLabel = aInfo.nonLocalizedLabel;
+            labelRes = aInfo.labelRes;
+            if (nonLocalizedLabel == null && labelRes == 0) {
+                ApplicationInfo app = aInfo.applicationInfo;
+                nonLocalizedLabel = app.nonLocalizedLabel;
+                labelRes = app.labelRes;
+            }
+            icon = aInfo.getIconResource();
+            logo = aInfo.getLogoResource();
+            theme = aInfo.getThemeResource();
+            realTheme = theme;
+            if (realTheme == 0) {
+                realTheme = aInfo.applicationInfo.targetSdkVersion
+                        < Build.VERSION_CODES.HONEYCOMB
+                        ? android.R.style.Theme
+                        : android.R.style.Theme_Holo;
+            }
+            if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
+                windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
+            }
+            if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
+                    && _caller != null
+                    && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
+                            || aInfo.applicationInfo.uid == _caller.info.uid)) {
+                processName = _caller.processName;
+            } else {
+                processName = aInfo.processName;
+            }
+
+            if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
+                intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+            }
+
+            packageName = aInfo.applicationInfo.packageName;
+            launchMode = aInfo.launchMode;
+
+            AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
+                    realTheme, com.android.internal.R.styleable.Window, userId);
+            fullscreen = ent != null && !ent.array.getBoolean(
+                    com.android.internal.R.styleable.Window_windowIsFloating, false)
+                    && !ent.array.getBoolean(
+                    com.android.internal.R.styleable.Window_windowIsTranslucent, false);
+            noDisplay = ent != null && ent.array.getBoolean(
+                    com.android.internal.R.styleable.Window_windowNoDisplay, false);
+
+            if ((!_componentSpecified || _launchedFromUid == Process.myUid()
+                    || _launchedFromUid == 0) &&
+                    Intent.ACTION_MAIN.equals(_intent.getAction()) &&
+                    _intent.hasCategory(Intent.CATEGORY_HOME) &&
+                    _intent.getCategories().size() == 1 &&
+                    _intent.getData() == null &&
+                    _intent.getType() == null &&
+                    (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
+                    isNotResolverActivity()) {
+                // This sure looks like a home activity!
+                mActivityType = HOME_ACTIVITY_TYPE;
+            } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
+                mActivityType = RECENTS_ACTIVITY_TYPE;
+            } else {
+                mActivityType = APPLICATION_ACTIVITY_TYPE;
+            }
+
+            immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
+        } else {
+            realActivity = null;
+            taskAffinity = null;
+            stateNotNeeded = false;
+            baseDir = null;
+            resDir = null;
+            dataDir = null;
+            processName = null;
+            packageName = null;
+            fullscreen = true;
+            noDisplay = false;
+            mActivityType = APPLICATION_ACTIVITY_TYPE;
+            immersive = false;
+        }
+    }
+
+    void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
+        if (task != null && task.removeActivity(this)) {
+            if (task != newTask) {
+                task.stack.removeTask(task);
+            } else {
+                Slog.d(TAG, "!!! REMOVE THIS LOG !!! setTask: nearly removed stack=" +
+                        (newTask == null ? null : newTask.stack));
+            }
+        }
+        if (inHistory && !finishing) {
+            if (task != null) {
+                task.numActivities--;
+            }
+            if (newTask != null) {
+                newTask.numActivities++;
+            }
+        }
+        if (newThumbHolder == null) {
+            newThumbHolder = newTask;
+        }
+        task = newTask;
+        if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
+            // This is the start of a new sub-task.
+            if (thumbHolder == null) {
+                thumbHolder = new ThumbnailHolder();
+            }
+        } else {
+            thumbHolder = newThumbHolder;
+        }
+    }
+
+    boolean changeWindowTranslucency(boolean toOpaque) {
+        if (fullscreen == toOpaque) {
+            return false;
+        }
+        AttributeCache.Entry ent =
+                AttributeCache.instance().get(packageName, realTheme, styleable.Window, userId);
+        if (ent == null
+                || !ent.array.getBoolean(styleable.Window_windowIsTranslucent, false)
+                || ent.array.getBoolean(styleable.Window_windowIsFloating, false)) {
+            return false;
+        }
+
+        // Keep track of the number of fullscreen activities in this task.
+        task.numFullscreen += toOpaque ? +1 : -1;
+
+        fullscreen = toOpaque;
+        return true;
+    }
+
+    void putInHistory() {
+        if (!inHistory) {
+            inHistory = true;
+            if (task != null && !finishing) {
+                task.numActivities++;
+            }
+        }
+    }
+
+    void takeFromHistory() {
+        if (inHistory) {
+            inHistory = false;
+            if (task != null && !finishing) {
+                task.numActivities--;
+                task = null;
+            }
+            clearOptionsLocked();
+        }
+    }
+
+    boolean isInHistory() {
+        return inHistory;
+    }
+
+    boolean isHomeActivity() {
+        return mActivityType == HOME_ACTIVITY_TYPE;
+    }
+
+    boolean isRecentsActivity() {
+        return mActivityType == RECENTS_ACTIVITY_TYPE;
+    }
+
+    boolean isApplicationActivity() {
+        return mActivityType == APPLICATION_ACTIVITY_TYPE;
+    }
+
+    void makeFinishing() {
+        if (!finishing) {
+            finishing = true;
+            if (task != null && inHistory) {
+                task.numActivities--;
+            }
+            if (stopped) {
+                clearOptionsLocked();
+            }
+        }
+    }
+
+    boolean isRootActivity() {
+        final ArrayList<ActivityRecord> activities = task.mActivities;
+        return activities.size() == 0 || this == activities.get(0);
+    }
+
+    UriPermissionOwner getUriPermissionsLocked() {
+        if (uriPermissions == null) {
+            uriPermissions = new UriPermissionOwner(service, this);
+        }
+        return uriPermissions;
+    }
+
+    void addResultLocked(ActivityRecord from, String resultWho,
+            int requestCode, int resultCode,
+            Intent resultData) {
+        ActivityResult r = new ActivityResult(from, resultWho,
+        		requestCode, resultCode, resultData);
+        if (results == null) {
+            results = new ArrayList<ResultInfo>();
+        }
+        results.add(r);
+    }
+
+    void removeResultsLocked(ActivityRecord from, String resultWho,
+            int requestCode) {
+        if (results != null) {
+            for (int i=results.size()-1; i>=0; i--) {
+                ActivityResult r = (ActivityResult)results.get(i);
+                if (r.mFrom != from) continue;
+                if (r.mResultWho == null) {
+                    if (resultWho != null) continue;
+                } else {
+                    if (!r.mResultWho.equals(resultWho)) continue;
+                }
+                if (r.mRequestCode != requestCode) continue;
+
+                results.remove(i);
+            }
+        }
+    }
+
+    void addNewIntentLocked(Intent intent) {
+        if (newIntents == null) {
+            newIntents = new ArrayList<Intent>();
+        }
+        newIntents.add(intent);
+    }
+
+    /**
+     * Deliver a new Intent to an existing activity, so that its onNewIntent()
+     * method will be called at the proper time.
+     */
+    final void deliverNewIntentLocked(int callingUid, Intent intent) {
+        // The activity now gets access to the data associated with this Intent.
+        service.grantUriPermissionFromIntentLocked(callingUid, packageName,
+                intent, getUriPermissionsLocked());
+        // We want to immediately deliver the intent to the activity if
+        // it is currently the top resumed activity...  however, if the
+        // device is sleeping, then all activities are stopped, so in that
+        // case we will deliver it if this is the current top activity on its
+        // stack.
+        boolean unsent = true;
+        if ((state == ActivityState.RESUMED || (service.mSleeping
+                        && task.stack.topRunningActivityLocked(null) == this))
+                && app != null && app.thread != null) {
+            try {
+                ArrayList<Intent> ar = new ArrayList<Intent>();
+                intent = new Intent(intent);
+                ar.add(intent);
+                app.thread.scheduleNewIntent(ar, appToken);
+                unsent = false;
+            } catch (RemoteException e) {
+                Slog.w(ActivityManagerService.TAG,
+                        "Exception thrown sending new intent to " + this, e);
+            } catch (NullPointerException e) {
+                Slog.w(ActivityManagerService.TAG,
+                        "Exception thrown sending new intent to " + this, e);
+            }
+        }
+        if (unsent) {
+            addNewIntentLocked(new Intent(intent));
+        }
+    }
+
+    void updateOptionsLocked(Bundle options) {
+        if (options != null) {
+            if (pendingOptions != null) {
+                pendingOptions.abort();
+            }
+            pendingOptions = new ActivityOptions(options);
+        }
+    }
+
+    void updateOptionsLocked(ActivityOptions options) {
+        if (options != null) {
+            if (pendingOptions != null) {
+                pendingOptions.abort();
+            }
+            pendingOptions = options;
+        }
+    }
+
+    void applyOptionsLocked() {
+        if (pendingOptions != null) {
+            final int animationType = pendingOptions.getAnimationType();
+            switch (animationType) {
+                case ActivityOptions.ANIM_CUSTOM:
+                    service.mWindowManager.overridePendingAppTransition(
+                            pendingOptions.getPackageName(),
+                            pendingOptions.getCustomEnterResId(),
+                            pendingOptions.getCustomExitResId(),
+                            pendingOptions.getOnAnimationStartListener());
+                    break;
+                case ActivityOptions.ANIM_SCALE_UP:
+                    service.mWindowManager.overridePendingAppTransitionScaleUp(
+                            pendingOptions.getStartX(), pendingOptions.getStartY(),
+                            pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
+                    if (intent.getSourceBounds() == null) {
+                        intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
+                                pendingOptions.getStartY(),
+                                pendingOptions.getStartX()+pendingOptions.getStartWidth(),
+                                pendingOptions.getStartY()+pendingOptions.getStartHeight()));
+                    }
+                    break;
+                case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
+                case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
+                    boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
+                    service.mWindowManager.overridePendingAppTransitionThumb(
+                            pendingOptions.getThumbnail(),
+                            pendingOptions.getStartX(), pendingOptions.getStartY(),
+                            pendingOptions.getOnAnimationStartListener(),
+                            scaleUp);
+                    if (intent.getSourceBounds() == null) {
+                        intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
+                                pendingOptions.getStartY(),
+                                pendingOptions.getStartX()
+                                        + pendingOptions.getThumbnail().getWidth(),
+                                pendingOptions.getStartY()
+                                        + pendingOptions.getThumbnail().getHeight()));
+                    }
+                    break;
+            }
+            pendingOptions = null;
+        }
+    }
+
+    void clearOptionsLocked() {
+        if (pendingOptions != null) {
+            pendingOptions.abort();
+            pendingOptions = null;
+        }
+    }
+
+    ActivityOptions takeOptionsLocked() {
+        ActivityOptions opts = pendingOptions;
+        pendingOptions = null;
+        return opts;
+    }
+
+    void removeUriPermissionsLocked() {
+        if (uriPermissions != null) {
+            uriPermissions.removeUriPermissionsLocked();
+            uriPermissions = null;
+        }
+    }
+
+    void pauseKeyDispatchingLocked() {
+        if (!keysPaused) {
+            keysPaused = true;
+            service.mWindowManager.pauseKeyDispatching(appToken);
+        }
+    }
+
+    void resumeKeyDispatchingLocked() {
+        if (keysPaused) {
+            keysPaused = false;
+            service.mWindowManager.resumeKeyDispatching(appToken);
+        }
+    }
+
+    void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
+        if (thumbHolder != null) {
+            if (newThumbnail != null) {
+                if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
+                        "Setting thumbnail of " + this + " holder " + thumbHolder
+                        + " to " + newThumbnail);
+                thumbHolder.lastThumbnail = newThumbnail;
+            }
+            thumbHolder.lastDescription = description;
+        }
+    }
+
+    void startLaunchTickingLocked() {
+        if (ActivityManagerService.IS_USER_BUILD) {
+            return;
+        }
+        if (launchTickTime == 0) {
+            launchTickTime = SystemClock.uptimeMillis();
+            continueLaunchTickingLocked();
+        }
+    }
+
+    boolean continueLaunchTickingLocked() {
+        if (launchTickTime != 0) {
+            final ActivityStack stack = task.stack;
+            Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
+            stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
+            stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
+            return true;
+        }
+        return false;
+    }
+
+    void finishLaunchTickingLocked() {
+        launchTickTime = 0;
+        task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
+    }
+
+    // IApplicationToken
+
+    public boolean mayFreezeScreenLocked(ProcessRecord app) {
+        // Only freeze the screen if this activity is currently attached to
+        // an application, and that application is not blocked or unresponding.
+        // In any other case, we can't count on getting the screen unfrozen,
+        // so it is best to leave as-is.
+        return app != null && !app.crashing && !app.notResponding;
+    }
+
+    public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
+        if (mayFreezeScreenLocked(app)) {
+            service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
+        }
+    }
+
+    public void stopFreezingScreenLocked(boolean force) {
+        if (force || frozenBeforeDestroy) {
+            frozenBeforeDestroy = false;
+            service.mWindowManager.stopAppFreezingScreen(appToken, force);
+        }
+    }
+
+    public void reportFullyDrawnLocked() {
+        final long curTime = SystemClock.uptimeMillis();
+        if (displayStartTime != 0) {
+            reportLaunchTimeLocked(curTime);
+        }
+        if (fullyDrawnStartTime != 0) {
+            final ActivityStack stack = task.stack;
+            final long thisTime = curTime - fullyDrawnStartTime;
+            final long totalTime = stack.mFullyDrawnStartTime != 0
+                    ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
+            if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
+                Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
+                EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
+                        userId, System.identityHashCode(this), shortComponentName,
+                        thisTime, totalTime);
+                StringBuilder sb = service.mStringBuilder;
+                sb.setLength(0);
+                sb.append("Fully drawn ");
+                sb.append(shortComponentName);
+                sb.append(": ");
+                TimeUtils.formatDuration(thisTime, sb);
+                if (thisTime != totalTime) {
+                    sb.append(" (total ");
+                    TimeUtils.formatDuration(totalTime, sb);
+                    sb.append(")");
+                }
+                Log.i(ActivityManagerService.TAG, sb.toString());
+            }
+            if (totalTime > 0) {
+                service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
+            }
+            fullyDrawnStartTime = 0;
+            stack.mFullyDrawnStartTime = 0;
+        }
+    }
+
+    private void reportLaunchTimeLocked(final long curTime) {
+        final ActivityStack stack = task.stack;
+        final long thisTime = curTime - displayStartTime;
+        final long totalTime = stack.mLaunchStartTime != 0
+                ? (curTime - stack.mLaunchStartTime) : thisTime;
+        if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
+            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
+            EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
+                    userId, System.identityHashCode(this), shortComponentName,
+                    thisTime, totalTime);
+            StringBuilder sb = service.mStringBuilder;
+            sb.setLength(0);
+            sb.append("Displayed ");
+            sb.append(shortComponentName);
+            sb.append(": ");
+            TimeUtils.formatDuration(thisTime, sb);
+            if (thisTime != totalTime) {
+                sb.append(" (total ");
+                TimeUtils.formatDuration(totalTime, sb);
+                sb.append(")");
+            }
+            Log.i(ActivityManagerService.TAG, sb.toString());
+        }
+        mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
+        if (totalTime > 0) {
+            service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
+        }
+        displayStartTime = 0;
+        stack.mLaunchStartTime = 0;
+    }
+
+    public void windowsDrawn() {
+        synchronized(service) {
+            if (displayStartTime != 0) {
+                reportLaunchTimeLocked(SystemClock.uptimeMillis());
+            }
+            startTime = 0;
+            finishLaunchTickingLocked();
+        }
+    }
+
+    public void windowsVisible() {
+        synchronized(service) {
+            mStackSupervisor.reportActivityVisibleLocked(this);
+            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
+                    ActivityManagerService.TAG, "windowsVisible(): " + this);
+            if (!nowVisible) {
+                nowVisible = true;
+                lastVisibleTime = SystemClock.uptimeMillis();
+                if (!idle) {
+                    // Instead of doing the full stop routine here, let's just
+                    // hide any activities we now can, and let them stop when
+                    // the normal idle happens.
+                    mStackSupervisor.processStoppingActivitiesLocked(false);
+                } else {
+                    // If this activity was already idle, then we now need to
+                    // make sure we perform the full stop of any activities
+                    // that are waiting to do so.  This is because we won't
+                    // do that while they are still waiting for this one to
+                    // become visible.
+                    final int N = mStackSupervisor.mWaitingVisibleActivities.size();
+                    if (N > 0) {
+                        for (int i=0; i<N; i++) {
+                            ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
+                            r.waitingVisible = false;
+                            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
+                                    ActivityManagerService.TAG,
+                                    "Was waiting for visible: " + r);
+                        }
+                        mStackSupervisor.mWaitingVisibleActivities.clear();
+                        mStackSupervisor.scheduleIdleLocked();
+                    }
+                }
+                service.scheduleAppGcsLocked();
+            }
+        }
+    }
+
+    public void windowsGone() {
+        if (ActivityManagerService.DEBUG_SWITCH) Log.v(
+                ActivityManagerService.TAG, "windowsGone(): " + this);
+        nowVisible = false;
+    }
+
+    private ActivityRecord getWaitingHistoryRecordLocked() {
+        // First find the real culprit...  if we are waiting
+        // for another app to start, then we have paused dispatching
+        // for this activity.
+        ActivityRecord r = this;
+        final ActivityStack stack = task.stack;
+        if (r.waitingVisible) {
+            // Hmmm, who might we be waiting for?
+            r = stack.mResumedActivity;
+            if (r == null) {
+                r = stack.mPausingActivity;
+            }
+            // Both of those null?  Fall back to 'this' again
+            if (r == null) {
+                r = this;
+            }
+        }
+
+        return r;
+    }
+
+    public boolean keyDispatchingTimedOut(String reason) {
+        ActivityRecord r;
+        ProcessRecord anrApp;
+        synchronized(service) {
+            r = getWaitingHistoryRecordLocked();
+            anrApp = r != null ? r.app : null;
+        }
+        return service.inputDispatchingTimedOut(anrApp, r, this, false, reason);
+    }
+
+    /** Returns the key dispatching timeout for this application token. */
+    public long getKeyDispatchingTimeout() {
+        synchronized(service) {
+            ActivityRecord r = getWaitingHistoryRecordLocked();
+            return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
+        }
+    }
+
+    /**
+     * This method will return true if the activity is either visible, is becoming visible, is
+     * currently pausing, or is resumed.
+     */
+    public boolean isInterestingToUserLocked() {
+        return visible || nowVisible || state == ActivityState.PAUSING ||
+                state == ActivityState.RESUMED;
+    }
+
+    public void setSleeping(boolean _sleeping) {
+        if (sleeping == _sleeping) {
+            return;
+        }
+        if (app != null && app.thread != null) {
+            try {
+                app.thread.scheduleSleeping(appToken, _sleeping);
+                if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
+                    mStackSupervisor.mGoingToSleepActivities.add(this);
+                }
+                sleeping = _sleeping;
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
+            }
+        }
+    }
+
+    static void activityResumedLocked(IBinder token) {
+        final ActivityRecord r = ActivityRecord.forToken(token);
+        if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
+        r.icicle = null;
+        r.haveState = false;
+    }
+
+    static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
+        final ActivityRecord r = ActivityRecord.forToken(token);
+        if (r == null) {
+            return -1;
+        }
+        final TaskRecord task = r.task;
+        switch (task.mActivities.indexOf(r)) {
+            case -1: return -1;
+            case 0: return task.taskId;
+            default: return onlyRoot ? -1 : task.taskId;
+        }
+    }
+
+    static ActivityRecord isInStackLocked(IBinder token) {
+        final ActivityRecord r = ActivityRecord.forToken(token);
+        if (r != null) {
+            return r.task.stack.isInStackLocked(token);
+        }
+        return null;
+    }
+
+    static ActivityStack getStackLocked(IBinder token) {
+        final ActivityRecord r = ActivityRecord.isInStackLocked(token);
+        if (r != null) {
+            return r.task.stack;
+        }
+        return null;
+    }
+
+    private String activityTypeToString(int type) {
+        switch (type) {
+            case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
+            case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
+            case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
+            default: return Integer.toString(type);
+        }
+    }
+
+    @Override
+    public String toString() {
+        if (stringName != null) {
+            return stringName + " t" + (task == null ? -1 : task.taskId) +
+                    (finishing ? " f}" : "}");
+        }
+        StringBuilder sb = new StringBuilder(128);
+        sb.append("ActivityRecord{");
+        sb.append(Integer.toHexString(System.identityHashCode(this)));
+        sb.append(" u");
+        sb.append(userId);
+        sb.append(' ');
+        sb.append(intent.getComponent().flattenToShortString());
+        stringName = sb.toString();
+        return toString();
+    }
+}
diff --git a/services/java/com/android/server/am/ActivityResult.java b/services/core/java/com/android/server/am/ActivityResult.java
similarity index 100%
rename from services/java/com/android/server/am/ActivityResult.java
rename to services/core/java/com/android/server/am/ActivityResult.java
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
new file mode 100755
index 0000000..68ef815
--- /dev/null
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -0,0 +1,3678 @@
+/*
+ * Copyright (C) 2010 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 static com.android.server.am.ActivityManagerService.TAG;
+import static com.android.server.am.ActivityManagerService.localLOGV;
+import static com.android.server.am.ActivityManagerService.DEBUG_CLEANUP;
+import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION;
+import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE;
+import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS;
+import static com.android.server.am.ActivityManagerService.DEBUG_STACK;
+import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH;
+import static com.android.server.am.ActivityManagerService.DEBUG_TASKS;
+import static com.android.server.am.ActivityManagerService.DEBUG_TRANSITION;
+import static com.android.server.am.ActivityManagerService.DEBUG_USER_LEAVING;
+import static com.android.server.am.ActivityManagerService.DEBUG_VISBILITY;
+import static com.android.server.am.ActivityManagerService.VALIDATE_TOKENS;
+
+import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
+import static com.android.server.am.ActivityStackSupervisor.DEBUG_APP;
+import static com.android.server.am.ActivityStackSupervisor.DEBUG_SAVED_STATE;
+import static com.android.server.am.ActivityStackSupervisor.DEBUG_STATES;
+import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
+
+import com.android.internal.os.BatteryStatsImpl;
+import com.android.server.Watchdog;
+import com.android.server.am.ActivityManagerService.ItemMatcher;
+import com.android.server.am.ActivityStackSupervisor.ActivityContainer;
+import com.android.server.wm.AppTransition;
+import com.android.server.wm.TaskGroup;
+import com.android.server.wm.WindowManagerService;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityOptions;
+import android.app.AppGlobals;
+import android.app.IActivityController;
+import android.app.IThumbnailReceiver;
+import android.app.ResultInfo;
+import android.app.ActivityManager.RunningTaskInfo;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.Trace;
+import android.os.UserHandle;
+import android.util.EventLog;
+import android.util.Slog;
+import android.view.Display;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * State and management of a single stack of activities.
+ */
+final class ActivityStack {
+
+    // Ticks during which we check progress while waiting for an app to launch.
+    static final int LAUNCH_TICK = 500;
+
+    // How long we wait until giving up on the last activity to pause.  This
+    // is short because it directly impacts the responsiveness of starting the
+    // next activity.
+    static final int PAUSE_TIMEOUT = 500;
+
+    // How long we wait for the activity to tell us it has stopped before
+    // giving up.  This is a good amount of time because we really need this
+    // from the application in order to get its saved state.
+    static final int STOP_TIMEOUT = 10*1000;
+
+    // How long we wait until giving up on an activity telling us it has
+    // finished destroying itself.
+    static final int DESTROY_TIMEOUT = 10*1000;
+
+    // How long until we reset a task when the user returns to it.  Currently
+    // disabled.
+    static final long ACTIVITY_INACTIVE_RESET_TIME = 0;
+
+    // How long between activity launches that we consider safe to not warn
+    // the user about an unexpected activity being launched on top.
+    static final long START_WARN_TIME = 5*1000;
+
+    // Set to false to disable the preview that is shown while a new activity
+    // is being started.
+    static final boolean SHOW_APP_STARTING_PREVIEW = true;
+
+    // How long to wait for all background Activities to redraw following a call to
+    // convertToTranslucent().
+    static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000;
+
+    static final boolean SCREENSHOT_FORCE_565 = ActivityManager
+            .isLowRamDeviceStatic() ? true : false;
+
+    enum ActivityState {
+        INITIALIZING,
+        RESUMED,
+        PAUSING,
+        PAUSED,
+        STOPPING,
+        STOPPED,
+        FINISHING,
+        DESTROYING,
+        DESTROYED
+    }
+
+    final ActivityManagerService mService;
+    final WindowManagerService mWindowManager;
+
+    /**
+     * The back history of all previous (and possibly still
+     * running) activities.  It contains #TaskRecord objects.
+     */
+    private ArrayList<TaskRecord> mTaskHistory = new ArrayList<TaskRecord>();
+
+    /**
+     * Used for validating app tokens with window manager.
+     */
+    final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<TaskGroup>();
+
+    /**
+     * List of running activities, sorted by recent usage.
+     * The first entry in the list is the least recently used.
+     * It contains HistoryRecord objects.
+     */
+    final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<ActivityRecord>();
+
+    /**
+     * Animations that for the current transition have requested not to
+     * be considered for the transition animation.
+     */
+    final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<ActivityRecord>();
+
+    /**
+     * When we are in the process of pausing an activity, before starting the
+     * next one, this variable holds the activity that is currently being paused.
+     */
+    ActivityRecord mPausingActivity = null;
+
+    /**
+     * This is the last activity that we put into the paused state.  This is
+     * used to determine if we need to do an activity transition while sleeping,
+     * when we normally hold the top activity paused.
+     */
+    ActivityRecord mLastPausedActivity = null;
+
+    /**
+     * Activities that specify No History must be removed once the user navigates away from them.
+     * If the device goes to sleep with such an activity in the paused state then we save it here
+     * and finish it later if another activity replaces it on wakeup.
+     */
+    ActivityRecord mLastNoHistoryActivity = null;
+
+    /**
+     * Current activity that is resumed, or null if there is none.
+     */
+    ActivityRecord mResumedActivity = null;
+
+    /**
+     * This is the last activity that has been started.  It is only used to
+     * identify when multiple activities are started at once so that the user
+     * can be warned they may not be in the activity they think they are.
+     */
+    ActivityRecord mLastStartedActivity = null;
+
+    // The topmost Activity passed to convertToTranslucent(). When non-null it means we are
+    // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they
+    // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the
+    // Activity in mTranslucentActivityWaiting is notified via
+    // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last
+    // background activity being drawn then the same call will be made with a true value.
+    ActivityRecord mTranslucentActivityWaiting = null;
+    ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent =
+            new ArrayList<ActivityRecord>();
+
+    /**
+     * Set when we know we are going to be calling updateConfiguration()
+     * soon, so want to skip intermediate config checks.
+     */
+    boolean mConfigWillChange;
+
+    long mLaunchStartTime = 0;
+    long mFullyDrawnStartTime = 0;
+
+    /**
+     * Save the most recent screenshot for reuse. This keeps Recents from taking two identical
+     * screenshots, one for the Recents thumbnail and one for the pauseActivity thumbnail.
+     */
+    private ActivityRecord mLastScreenshotActivity = null;
+    private Bitmap mLastScreenshotBitmap = null;
+
+    int mThumbnailWidth = -1;
+    int mThumbnailHeight = -1;
+
+    int mCurrentUser;
+
+    final int mStackId;
+    final ActivityContainer mActivityContainer;
+    /** The other stacks, in order, on the attached display. Updated at attach/detach time. */
+    ArrayList<ActivityStack> mStacks;
+    /** The attached Display's unique identifier, or -1 if detached */
+    int mDisplayId;
+
+    /** Run all ActivityStacks through this */
+    final ActivityStackSupervisor mStackSupervisor;
+
+    static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1;
+    static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2;
+    static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3;
+    static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4;
+    static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5;
+    static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6;
+
+    static class ScheduleDestroyArgs {
+        final ProcessRecord mOwner;
+        final boolean mOomAdj;
+        final String mReason;
+        ScheduleDestroyArgs(ProcessRecord owner, boolean oomAdj, String reason) {
+            mOwner = owner;
+            mOomAdj = oomAdj;
+            mReason = reason;
+        }
+    }
+
+    final Handler mHandler;
+
+    final class ActivityStackHandler extends Handler {
+        //public Handler() {
+        //    if (localLOGV) Slog.v(TAG, "Handler started!");
+        //}
+        ActivityStackHandler(Looper looper) {
+            super(looper);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case PAUSE_TIMEOUT_MSG: {
+                    ActivityRecord r = (ActivityRecord)msg.obj;
+                    // We don't at this point know if the activity is fullscreen,
+                    // so we need to be conservative and assume it isn't.
+                    Slog.w(TAG, "Activity pause timeout for " + r);
+                    synchronized (mService) {
+                        if (r.app != null) {
+                            mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r);
+                        }
+                        activityPausedLocked(r.appToken, true);
+                    }
+                } break;
+                case LAUNCH_TICK_MSG: {
+                    ActivityRecord r = (ActivityRecord)msg.obj;
+                    synchronized (mService) {
+                        if (r.continueLaunchTickingLocked()) {
+                            mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r);
+                        }
+                    }
+                } break;
+                case DESTROY_TIMEOUT_MSG: {
+                    ActivityRecord r = (ActivityRecord)msg.obj;
+                    // We don't at this point know if the activity is fullscreen,
+                    // so we need to be conservative and assume it isn't.
+                    Slog.w(TAG, "Activity destroy timeout for " + r);
+                    synchronized (mService) {
+                        activityDestroyedLocked(r != null ? r.appToken : null);
+                    }
+                } break;
+                case STOP_TIMEOUT_MSG: {
+                    ActivityRecord r = (ActivityRecord)msg.obj;
+                    // We don't at this point know if the activity is fullscreen,
+                    // so we need to be conservative and assume it isn't.
+                    Slog.w(TAG, "Activity stop timeout for " + r);
+                    synchronized (mService) {
+                        if (r.isInHistory()) {
+                            activityStoppedLocked(r, null, null, null);
+                        }
+                    }
+                } break;
+                case DESTROY_ACTIVITIES_MSG: {
+                    ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj;
+                    synchronized (mService) {
+                        destroyActivitiesLocked(args.mOwner, args.mOomAdj, args.mReason);
+                    }
+                } break;
+                case TRANSLUCENT_TIMEOUT_MSG: {
+                    synchronized (mService) {
+                        notifyActivityDrawnLocked(null);
+                    }
+                } break;
+            }
+        }
+    }
+
+    int numActivities() {
+        int count = 0;
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            count += mTaskHistory.get(taskNdx).mActivities.size();
+        }
+        return count;
+    }
+
+    ActivityStack(ActivityStackSupervisor.ActivityContainer activityContainer) {
+        mActivityContainer = activityContainer;
+        mStackSupervisor = activityContainer.getOuter();
+        mService = mStackSupervisor.mService;
+        mHandler = new ActivityStackHandler(mService.mHandler.getLooper());
+        mWindowManager = mService.mWindowManager;
+        mStackId = activityContainer.mStackId;
+        mCurrentUser = mService.mCurrentUserId;
+    }
+
+    boolean okToShow(ActivityRecord r) {
+        return r.userId == mCurrentUser
+                || (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0;
+    }
+
+    final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(notTop);
+            if (r != null) {
+                return r;
+            }
+        }
+        return null;
+    }
+
+    final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            final ArrayList<ActivityRecord> activities = task.mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                ActivityRecord r = activities.get(activityNdx);
+                if (!r.finishing && !r.delayedResume && r != notTop && okToShow(r)) {
+                    return r;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * This is a simplified version of topRunningActivityLocked that provides a number of
+     * optional skip-over modes.  It is intended for use with the ActivityController hook only.
+     *
+     * @param token If non-null, any history records matching this token will be skipped.
+     * @param taskId If non-zero, we'll attempt to skip over records with the same task ID.
+     *
+     * @return Returns the HistoryRecord of the next activity on the stack.
+     */
+    final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            TaskRecord task = mTaskHistory.get(taskNdx);
+            if (task.taskId == taskId) {
+                continue;
+            }
+            ArrayList<ActivityRecord> activities = task.mActivities;
+            for (int i = activities.size() - 1; i >= 0; --i) {
+                final ActivityRecord r = activities.get(i);
+                // Note: the taskId check depends on real taskId fields being non-zero
+                if (!r.finishing && (token != r.appToken) && okToShow(r)) {
+                    return r;
+                }
+            }
+        }
+        return null;
+    }
+
+    final ActivityRecord topActivity() {
+        // Iterate to find the first non-empty task stack. Note that this code can
+        // be simplified once we stop storing tasks with empty mActivities lists.
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                return activities.get(activityNdx);
+            }
+        }
+        return null;
+    }
+
+    final TaskRecord topTask() {
+        final int size = mTaskHistory.size();
+        if (size > 0) {
+            return mTaskHistory.get(size - 1);
+        }
+        return null;
+    }
+
+    TaskRecord taskForIdLocked(int id) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            if (task.taskId == id) {
+                return task;
+            }
+        }
+        return null;
+    }
+
+    ActivityRecord isInStackLocked(IBinder token) {
+        final ActivityRecord r = ActivityRecord.forToken(token);
+        if (r != null) {
+            final TaskRecord task = r.task;
+            if (task.mActivities.contains(r) && mTaskHistory.contains(task)) {
+                if (task.stack != this) Slog.w(TAG,
+                    "Illegal state! task does not point to stack it is in.");
+                return r;
+            }
+        }
+        return null;
+    }
+
+    final boolean updateLRUListLocked(ActivityRecord r) {
+        final boolean hadit = mLRUActivities.remove(r);
+        mLRUActivities.add(r);
+        return hadit;
+    }
+
+    final boolean isHomeStack() {
+        return mStackId == HOME_STACK_ID;
+    }
+
+    final boolean isOnHomeDisplay() {
+        return isAttached() &&
+                mActivityContainer.mActivityDisplay.mDisplayId == Display.DEFAULT_DISPLAY;
+    }
+
+    final void moveToFront() {
+        if (isAttached()) {
+            if (isOnHomeDisplay()) {
+                mStackSupervisor.moveHomeStack(isHomeStack());
+            }
+            mStacks.remove(this);
+            mStacks.add(this);
+        }
+    }
+
+    final boolean isAttached() {
+        return mStacks != null;
+    }
+
+    /**
+     * Returns the top activity in any existing task matching the given
+     * Intent.  Returns null if no such task is found.
+     */
+    ActivityRecord findTaskLocked(ActivityRecord target) {
+        Intent intent = target.intent;
+        ActivityInfo info = target.info;
+        ComponentName cls = intent.getComponent();
+        if (info.targetActivity != null) {
+            cls = new ComponentName(info.packageName, info.targetActivity);
+        }
+        final int userId = UserHandle.getUserId(info.applicationInfo.uid);
+
+        if (DEBUG_TASKS) Slog.d(TAG, "Looking for task of " + target + " in " + this);
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            if (task.userId != userId) {
+                // Looking for a different task.
+                if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": different user");
+                continue;
+            }
+            final ActivityRecord r = task.getTopActivity();
+            if (r == null || r.finishing || r.userId != userId ||
+                    r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
+                if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": mismatch root " + r);
+                continue;
+            }
+
+            if (DEBUG_TASKS) Slog.d(TAG, "Comparing existing cls="
+                    + r.task.intent.getComponent().flattenToShortString()
+                    + "/aff=" + r.task.affinity + " to new cls="
+                    + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity);
+            if (task.affinity != null) {
+                if (task.affinity.equals(info.taskAffinity)) {
+                    if (DEBUG_TASKS) Slog.d(TAG, "Found matching affinity!");
+                    return r;
+                }
+            } else if (task.intent != null && task.intent.getComponent().equals(cls)) {
+                if (DEBUG_TASKS) Slog.d(TAG, "Found matching class!");
+                //dump();
+                if (DEBUG_TASKS) Slog.d(TAG, "For Intent " + intent + " bringing to top: "
+                        + r.intent);
+                return r;
+            } else if (task.affinityIntent != null
+                    && task.affinityIntent.getComponent().equals(cls)) {
+                if (DEBUG_TASKS) Slog.d(TAG, "Found matching class!");
+                //dump();
+                if (DEBUG_TASKS) Slog.d(TAG, "For Intent " + intent + " bringing to top: "
+                        + r.intent);
+                return r;
+            } else if (DEBUG_TASKS) {
+                Slog.d(TAG, "Not a match: " + task);
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns the first activity (starting from the top of the stack) that
+     * is the same as the given activity.  Returns null if no such activity
+     * is found.
+     */
+    ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) {
+        ComponentName cls = intent.getComponent();
+        if (info.targetActivity != null) {
+            cls = new ComponentName(info.packageName, info.targetActivity);
+        }
+        final int userId = UserHandle.getUserId(info.applicationInfo.uid);
+
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            TaskRecord task = mTaskHistory.get(taskNdx);
+            if (task.userId != mCurrentUser) {
+                return null;
+            }
+            final ArrayList<ActivityRecord> activities = task.mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                ActivityRecord r = activities.get(activityNdx);
+                if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) {
+                    //Slog.i(TAG, "Found matching class!");
+                    //dump();
+                    //Slog.i(TAG, "For Intent " + intent + " bringing to top: " + r.intent);
+                    return r;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /*
+     * Move the activities around in the stack to bring a user to the foreground.
+     */
+    final void switchUserLocked(int userId) {
+        if (mCurrentUser == userId) {
+            return;
+        }
+        mCurrentUser = userId;
+
+        // Move userId's tasks to the top.
+        int index = mTaskHistory.size();
+        for (int i = 0; i < index; ) {
+            TaskRecord task = mTaskHistory.get(i);
+            if (task.userId == userId) {
+                if (DEBUG_TASKS) Slog.d(TAG, "switchUserLocked: stack=" + getStackId() +
+                        " moving " + task + " to top");
+                mTaskHistory.remove(i);
+                mTaskHistory.add(task);
+                --index;
+                // Use same value for i.
+            } else {
+                ++i;
+            }
+        }
+        if (VALIDATE_TOKENS) {
+            validateAppTokensLocked();
+        }
+    }
+
+    void minimalResumeActivityLocked(ActivityRecord r) {
+        r.state = ActivityState.RESUMED;
+        if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + r
+                + " (starting new instance)");
+        r.stopped = false;
+        mResumedActivity = r;
+        r.task.touchActiveTime();
+        mService.addRecentTaskLocked(r.task);
+        completeResumeLocked(r);
+        mStackSupervisor.checkReadyForSleepLocked();
+        setLaunchTime(r);
+        if (DEBUG_SAVED_STATE) Slog.i(TAG, "Launch completed; removing icicle of " + r.icicle);
+    }
+
+    private void startLaunchTraces() {
+        if (mFullyDrawnStartTime != 0)  {
+            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
+        }
+        Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
+        Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
+    }
+
+    private void stopFullyDrawnTraceIfNeeded() {
+        if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) {
+            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
+            mFullyDrawnStartTime = 0;
+        }
+    }
+
+    void setLaunchTime(ActivityRecord r) {
+        if (r.displayStartTime == 0) {
+            r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis();
+            if (mLaunchStartTime == 0) {
+                startLaunchTraces();
+                mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime;
+            }
+        } else if (mLaunchStartTime == 0) {
+            startLaunchTraces();
+            mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis();
+        }
+    }
+
+    void clearLaunchTime(ActivityRecord r) {
+        // Make sure that there is no activity waiting for this to launch.
+        if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) {
+            r.displayStartTime = r.fullyDrawnStartTime = 0;
+        } else {
+            mStackSupervisor.removeTimeoutsForActivityLocked(r);
+            mStackSupervisor.scheduleIdleTimeoutLocked(r);
+        }
+    }
+
+    void awakeFromSleepingLocked() {
+        // Ensure activities are no longer sleeping.
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                activities.get(activityNdx).setSleeping(false);
+            }
+        }
+    }
+
+    /**
+     * @return true if something must be done before going to sleep.
+     */
+    boolean checkReadyForSleepLocked() {
+        if (mResumedActivity != null) {
+            // Still have something resumed; can't sleep until it is paused.
+            if (DEBUG_PAUSE) Slog.v(TAG, "Sleep needs to pause " + mResumedActivity);
+            if (DEBUG_USER_LEAVING) Slog.v(TAG, "Sleep => pause with userLeaving=false");
+            startPausingLocked(false, true);
+            return true;
+        }
+        if (mPausingActivity != null) {
+            // Still waiting for something to pause; can't sleep yet.
+            if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still waiting to pause " + mPausingActivity);
+            return true;
+        }
+
+        return false;
+    }
+
+    void goToSleep() {
+        ensureActivitiesVisibleLocked(null, 0);
+
+        // Make sure any stopped but visible activities are now sleeping.
+        // This ensures that the activity's onStop() is called.
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) {
+                    r.setSleeping(true);
+                }
+            }
+        }
+    }
+
+    public final Bitmap screenshotActivities(ActivityRecord who) {
+        if (who.noDisplay) {
+            return null;
+        }
+
+        TaskRecord tr = who.task;
+        if (mService.getMostRecentTask() != tr && tr.intent != null &&
+                (tr.intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) != 0) {
+            // If this task is being excluded from recents, we don't want to take
+            // the expense of capturing a thumbnail, since we will never show it.
+            return null;
+        }
+
+        Resources res = mService.mContext.getResources();
+        int w = mThumbnailWidth;
+        int h = mThumbnailHeight;
+        if (w < 0) {
+            mThumbnailWidth = w =
+                res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width);
+            mThumbnailHeight = h =
+                res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height);
+        }
+
+        if (w > 0) {
+            if (who != mLastScreenshotActivity || mLastScreenshotBitmap == null
+                    || mLastScreenshotActivity.state == ActivityState.RESUMED
+                    || mLastScreenshotBitmap.getWidth() != w
+                    || mLastScreenshotBitmap.getHeight() != h) {
+                mLastScreenshotActivity = who;
+                mLastScreenshotBitmap = mWindowManager.screenshotApplications(
+                        who.appToken, Display.DEFAULT_DISPLAY, w, h, SCREENSHOT_FORCE_565);
+            }
+            if (mLastScreenshotBitmap != null) {
+                return mLastScreenshotBitmap.copy(mLastScreenshotBitmap.getConfig(), true);
+            }
+        }
+        return null;
+    }
+
+    final void startPausingLocked(boolean userLeaving, boolean uiSleeping) {
+        if (mPausingActivity != null) {
+            Slog.e(TAG, "Trying to pause when pause is already pending for "
+                  + mPausingActivity, new RuntimeException("here").fillInStackTrace());
+        }
+        ActivityRecord prev = mResumedActivity;
+        if (prev == null) {
+            Slog.e(TAG, "Trying to pause when nothing is resumed",
+                    new RuntimeException("here").fillInStackTrace());
+            mStackSupervisor.resumeTopActivitiesLocked();
+            return;
+        }
+
+        if (mActivityContainer.mParentActivity == null) {
+            // Top level stack, not a child. Look for child stacks.
+            mStackSupervisor.pauseChildStacks(prev, userLeaving, uiSleeping);
+        }
+
+        if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSING: " + prev);
+        else if (DEBUG_PAUSE) Slog.v(TAG, "Start pausing: " + prev);
+        mResumedActivity = null;
+        mPausingActivity = prev;
+        mLastPausedActivity = prev;
+        mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0
+                || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null;
+        prev.state = ActivityState.PAUSING;
+        prev.task.touchActiveTime();
+        clearLaunchTime(prev);
+        final ActivityRecord next = mStackSupervisor.topRunningActivityLocked();
+        if (next == null || next.task != prev.task) {
+            prev.updateThumbnail(screenshotActivities(prev), null);
+        }
+        stopFullyDrawnTraceIfNeeded();
+
+        mService.updateCpuStats();
+
+        if (prev.app != null && prev.app.thread != null) {
+            if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending pause: " + prev);
+            try {
+                EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY,
+                        prev.userId, System.identityHashCode(prev),
+                        prev.shortComponentName);
+                mService.updateUsageStats(prev, false);
+                prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing,
+                        userLeaving, prev.configChangeFlags);
+            } catch (Exception e) {
+                // Ignore exception, if process died other code will cleanup.
+                Slog.w(TAG, "Exception thrown during pause", e);
+                mPausingActivity = null;
+                mLastPausedActivity = null;
+                mLastNoHistoryActivity = null;
+            }
+        } else {
+            mPausingActivity = null;
+            mLastPausedActivity = null;
+            mLastNoHistoryActivity = null;
+        }
+
+        // If we are not going to sleep, we want to ensure the device is
+        // awake until the next activity is started.
+        if (!mService.isSleepingOrShuttingDown()) {
+            mStackSupervisor.acquireLaunchWakelock();
+        }
+
+        if (mPausingActivity != null) {
+            // Have the window manager pause its key dispatching until the new
+            // activity has started.  If we're pausing the activity just because
+            // the screen is being turned off and the UI is sleeping, don't interrupt
+            // key dispatch; the same activity will pick it up again on wakeup.
+            if (!uiSleeping) {
+                prev.pauseKeyDispatchingLocked();
+            } else {
+                if (DEBUG_PAUSE) Slog.v(TAG, "Key dispatch not paused for screen off");
+            }
+
+            // Schedule a pause timeout in case the app doesn't respond.
+            // We don't give it much time because this directly impacts the
+            // responsiveness seen by the user.
+            Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG);
+            msg.obj = prev;
+            prev.pauseTime = SystemClock.uptimeMillis();
+            mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT);
+            if (DEBUG_PAUSE) Slog.v(TAG, "Waiting for pause to complete...");
+        } else {
+            // This activity failed to schedule the
+            // pause, so just treat it as being paused now.
+            if (DEBUG_PAUSE) Slog.v(TAG, "Activity not running, resuming next.");
+            mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
+        }
+    }
+
+    final void activityPausedLocked(IBinder token, boolean timeout) {
+        if (DEBUG_PAUSE) Slog.v(
+            TAG, "Activity paused: token=" + token + ", timeout=" + timeout);
+
+        final ActivityRecord r = isInStackLocked(token);
+        if (r != null) {
+            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
+            if (mPausingActivity == r) {
+                if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSED: " + r
+                        + (timeout ? " (due to timeout)" : " (pause complete)"));
+                r.state = ActivityState.PAUSED;
+                completePauseLocked();
+            } else {
+                EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE,
+                        r.userId, System.identityHashCode(r), r.shortComponentName,
+                        mPausingActivity != null
+                            ? mPausingActivity.shortComponentName : "(none)");
+            }
+        }
+    }
+
+    final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbnail,
+            CharSequence description) {
+        if (r.state != ActivityState.STOPPING) {
+            Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r);
+            mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
+            return;
+        }
+        if (DEBUG_SAVED_STATE) Slog.i(TAG, "Saving icicle of " + r + ": " + icicle);
+        if (icicle != null) {
+            // If icicle is null, this is happening due to a timeout, so we
+            // haven't really saved the state.
+            r.icicle = icicle;
+            r.haveState = true;
+            r.launchCount = 0;
+            r.updateThumbnail(thumbnail, description);
+        }
+        if (!r.stopped) {
+            if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r + " (stop complete)");
+            mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
+            r.stopped = true;
+            r.state = ActivityState.STOPPED;
+            if (r.finishing) {
+                r.clearOptionsLocked();
+            } else {
+                if (r.configDestroy) {
+                    destroyActivityLocked(r, true, false, "stop-config");
+                    mStackSupervisor.resumeTopActivitiesLocked();
+                } else {
+                    mStackSupervisor.updatePreviousProcessLocked(r);
+                }
+            }
+        }
+    }
+
+    private void completePauseLocked() {
+        ActivityRecord prev = mPausingActivity;
+        if (DEBUG_PAUSE) Slog.v(TAG, "Complete pause: " + prev);
+
+        if (prev != null) {
+            if (prev.finishing) {
+                if (DEBUG_PAUSE) Slog.v(TAG, "Executing finish of activity: " + prev);
+                prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false);
+            } else if (prev.app != null) {
+                if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending stop: " + prev);
+                if (prev.waitingVisible) {
+                    prev.waitingVisible = false;
+                    mStackSupervisor.mWaitingVisibleActivities.remove(prev);
+                    if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(
+                            TAG, "Complete pause, no longer waiting: " + prev);
+                }
+                if (prev.configDestroy) {
+                    // The previous is being paused because the configuration
+                    // is changing, which means it is actually stopping...
+                    // To juggle the fact that we are also starting a new
+                    // instance right now, we need to first completely stop
+                    // the current instance before starting the new one.
+                    if (DEBUG_PAUSE) Slog.v(TAG, "Destroying after pause: " + prev);
+                    destroyActivityLocked(prev, true, false, "pause-config");
+                } else {
+                    mStackSupervisor.mStoppingActivities.add(prev);
+                    if (mStackSupervisor.mStoppingActivities.size() > 3 ||
+                            prev.frontOfTask && mTaskHistory.size() <= 1) {
+                        // If we already have a few activities waiting to stop,
+                        // then give up on things going idle and start clearing
+                        // them out. Or if r is the last of activity of the last task the stack
+                        // will be empty and must be cleared immediately.
+                        if (DEBUG_PAUSE) Slog.v(TAG, "To many pending stops, forcing idle");
+                        mStackSupervisor.scheduleIdleLocked();
+                    } else {
+                        mStackSupervisor.checkReadyForSleepLocked();
+                    }
+                }
+            } else {
+                if (DEBUG_PAUSE) Slog.v(TAG, "App died during pause, not stopping: " + prev);
+                prev = null;
+            }
+            mPausingActivity = null;
+        }
+
+        final ActivityStack topStack = mStackSupervisor.getFocusedStack();
+        if (!mService.isSleepingOrShuttingDown()) {
+            mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null);
+        } else {
+            mStackSupervisor.checkReadyForSleepLocked();
+            ActivityRecord top = topStack.topRunningActivityLocked(null);
+            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 (prev != null) {
+            prev.resumeKeyDispatchingLocked();
+
+            if (prev.app != null && prev.cpuTimeAtResume > 0
+                    && mService.mBatteryStatsService.isOnBattery()) {
+                long diff;
+                synchronized (mService.mProcessCpuThread) {
+                    diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid)
+                            - prev.cpuTimeAtResume;
+                }
+                if (diff > 0) {
+                    BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics();
+                    synchronized (bsi) {
+                        BatteryStatsImpl.Uid.Proc ps =
+                                bsi.getProcessStatsLocked(prev.info.applicationInfo.uid,
+                                        prev.info.packageName);
+                        if (ps != null) {
+                            ps.addForegroundTimeLocked(diff);
+                        }
+                    }
+                }
+            }
+            prev.cpuTimeAtResume = 0; // reset it
+        }
+    }
+
+    /**
+     * Once we know that we have asked an application to put an activity in
+     * the resumed state (either by launching it or explicitly telling it),
+     * this function updates the rest of our state to match that fact.
+     */
+    private void completeResumeLocked(ActivityRecord next) {
+        next.idle = false;
+        next.results = null;
+        next.newIntents = null;
+        if (next.nowVisible) {
+            // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
+            mStackSupervisor.dismissKeyguard();
+        }
+
+        // schedule an idle timeout in case the app doesn't do it for us.
+        mStackSupervisor.scheduleIdleTimeoutLocked(next);
+
+        mStackSupervisor.reportResumedActivityLocked(next);
+
+        next.resumeKeyDispatchingLocked();
+        mNoAnimActivities.clear();
+
+        // Mark the point when the activity is resuming
+        // TODO: To be more accurate, the mark should be before the onCreate,
+        //       not after the onResume. But for subsequent starts, onResume is fine.
+        if (next.app != null) {
+            synchronized (mService.mProcessCpuThread) {
+                next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid);
+            }
+        } else {
+            next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process
+        }
+    }
+
+    /**
+     * Determine if home should be visible below the passed record.
+     * @param record activity we are querying for.
+     * @return true if home is visible below the passed activity, false otherwise.
+     */
+    boolean isActivityOverHome(ActivityRecord record) {
+        // Start at record and go down, look for either home or a visible fullscreen activity.
+        final TaskRecord recordTask = record.task;
+        for (int taskNdx = mTaskHistory.indexOf(recordTask); taskNdx >= 0; --taskNdx) {
+            TaskRecord task = mTaskHistory.get(taskNdx);
+            final ArrayList<ActivityRecord> activities = task.mActivities;
+            final int startNdx =
+                    task == recordTask ? activities.indexOf(record) : activities.size() - 1;
+            for (int activityNdx = startNdx; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.isHomeActivity()) {
+                    return true;
+                }
+                if (!r.finishing && r.fullscreen) {
+                    // Passed activity is over a fullscreen activity.
+                    return false;
+                }
+            }
+            if (task.mOnTopOfHome) {
+                // Got to the bottom of a task on top of home without finding a visible fullscreen
+                // activity. Home is visible.
+                return true;
+            }
+        }
+        // Got to the bottom of this stack and still don't know. If this is over the home stack
+        // then record is over home. May not work if we ever get more than two layers.
+        return mStackSupervisor.isFrontStack(this);
+    }
+
+    /**
+     * Version of ensureActivitiesVisible that can easily be called anywhere.
+     */
+    final boolean ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) {
+        return ensureActivitiesVisibleLocked(starting, configChanges, false);
+    }
+
+    final boolean ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges,
+            boolean forceHomeShown) {
+        ActivityRecord r = topRunningActivityLocked(null);
+        return r != null &&
+                ensureActivitiesVisibleLocked(r, starting, null, configChanges, forceHomeShown);
+    }
+
+    /**
+     * Make sure that all activities that need to be visible (that is, they
+     * currently can be seen by the user) actually are.
+     */
+    final boolean ensureActivitiesVisibleLocked(ActivityRecord top, ActivityRecord starting,
+            String onlyThisProcess, int configChanges, boolean forceHomeShown) {
+        if (DEBUG_VISBILITY) Slog.v(
+                TAG, "ensureActivitiesVisible behind " + top
+                + " configChanges=0x" + Integer.toHexString(configChanges));
+
+        if (mTranslucentActivityWaiting != top) {
+            mUndrawnActivitiesBelowTopTranslucent.clear();
+            if (mTranslucentActivityWaiting != null) {
+                // Call the callback with a timeout indication.
+                notifyActivityDrawnLocked(null);
+                mTranslucentActivityWaiting = null;
+            }
+            mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG);
+        }
+
+        // If the top activity is not fullscreen, then we need to
+        // make sure any activities under it are now visible.
+        boolean aboveTop = true;
+        boolean showHomeBehindStack = false;
+        boolean behindFullscreen = !mStackSupervisor.isFrontStack(this) &&
+                !(forceHomeShown && isHomeStack());
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            final ArrayList<ActivityRecord> activities = task.mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.finishing) {
+                    continue;
+                }
+                if (aboveTop && r != top) {
+                    continue;
+                }
+                aboveTop = false;
+                if (!behindFullscreen) {
+                    if (DEBUG_VISBILITY) Slog.v(
+                            TAG, "Make visible? " + r + " finishing=" + r.finishing
+                            + " state=" + r.state);
+
+                    final boolean doThisProcess = onlyThisProcess == null
+                            || onlyThisProcess.equals(r.processName);
+
+                    // First: if this is not the current activity being started, make
+                    // sure it matches the current configuration.
+                    if (r != starting && doThisProcess) {
+                        ensureActivityConfigurationLocked(r, 0);
+                    }
+
+                    if (r.app == null || r.app.thread == null) {
+                        if (onlyThisProcess == null || onlyThisProcess.equals(r.processName)) {
+                            // This activity needs to be visible, but isn't even
+                            // running...  get it started, but don't resume it
+                            // at this point.
+                            if (DEBUG_VISBILITY) Slog.v(TAG, "Start and freeze screen for " + r);
+                            if (r != starting) {
+                                r.startFreezingScreenLocked(r.app, configChanges);
+                            }
+                            if (!r.visible) {
+                                if (DEBUG_VISBILITY) Slog.v(
+                                        TAG, "Starting and making visible: " + r);
+                                r.visible = true;
+                                mWindowManager.setAppVisibility(r.appToken, true);
+                            }
+                            if (r != starting) {
+                                mStackSupervisor.startSpecificActivityLocked(r, false, false);
+                            }
+                        }
+
+                    } else if (r.visible) {
+                        // If this activity is already visible, then there is nothing
+                        // else to do here.
+                        if (DEBUG_VISBILITY) Slog.v(TAG, "Skipping: already visible at " + r);
+                        r.stopFreezingScreenLocked(false);
+
+                    } else if (onlyThisProcess == null) {
+                        // This activity is not currently visible, but is running.
+                        // Tell it to become visible.
+                        r.visible = true;
+                        if (r.state != ActivityState.RESUMED && r != starting) {
+                            // If this activity is paused, tell it
+                            // to now show its window.
+                            if (DEBUG_VISBILITY) Slog.v(
+                                    TAG, "Making visible and scheduling visibility: " + r);
+                            try {
+                                if (mTranslucentActivityWaiting != null) {
+                                    mUndrawnActivitiesBelowTopTranslucent.add(r);
+                                }
+                                mWindowManager.setAppVisibility(r.appToken, true);
+                                r.sleeping = false;
+                                r.app.pendingUiClean = true;
+                                r.app.thread.scheduleWindowVisibility(r.appToken, true);
+                                r.stopFreezingScreenLocked(false);
+                            } catch (Exception e) {
+                                // Just skip on any failure; we'll make it
+                                // visible when it next restarts.
+                                Slog.w(TAG, "Exception thrown making visibile: "
+                                        + r.intent.getComponent(), e);
+                            }
+                        }
+                    }
+
+                    // Aggregate current change flags.
+                    configChanges |= r.configChangeFlags;
+
+                    if (r.fullscreen) {
+                        // At this point, nothing else needs to be shown
+                        if (DEBUG_VISBILITY) Slog.v(TAG, "Fullscreen: at " + r);
+                        behindFullscreen = true;
+                    } else if (isActivityOverHome(r)) {
+                        if (DEBUG_VISBILITY) Slog.v(TAG, "Showing home: at " + r);
+                        showHomeBehindStack = true;
+                        behindFullscreen = !isHomeStack() && r.frontOfTask && task.mOnTopOfHome;
+                    }
+                } else {
+                    if (DEBUG_VISBILITY) Slog.v(
+                        TAG, "Make invisible? " + r + " finishing=" + r.finishing
+                        + " state=" + r.state
+                        + " behindFullscreen=" + behindFullscreen);
+                    // Now for any activities that aren't visible to the user, make
+                    // sure they no longer are keeping the screen frozen.
+                    if (r.visible) {
+                        if (DEBUG_VISBILITY) Slog.v(TAG, "Making invisible: " + r);
+                        r.visible = false;
+                        try {
+                            mWindowManager.setAppVisibility(r.appToken, false);
+                            switch (r.state) {
+                                case STOPPING:
+                                case STOPPED:
+                                    if (r.app != null && r.app.thread != null) {
+                                        if (DEBUG_VISBILITY) Slog.v(
+                                                TAG, "Scheduling invisibility: " + r);
+                                        r.app.thread.scheduleWindowVisibility(r.appToken, false);
+                                    }
+                                    break;
+
+                                case INITIALIZING:
+                                case RESUMED:
+                                case PAUSING:
+                                case PAUSED:
+                                    // This case created for transitioning activities from
+                                    // translucent to opaque {@link Activity#convertToOpaque}.
+                                    if (!mStackSupervisor.mStoppingActivities.contains(r)) {
+                                        mStackSupervisor.mStoppingActivities.add(r);
+                                    }
+                                    mStackSupervisor.scheduleIdleLocked();
+                                    break;
+
+                                default:
+                                    break;
+                            }
+                        } catch (Exception e) {
+                            // Just skip on any failure; we'll make it
+                            // visible when it next restarts.
+                            Slog.w(TAG, "Exception thrown making hidden: "
+                                    + r.intent.getComponent(), e);
+                        }
+                    } else {
+                        if (DEBUG_VISBILITY) Slog.v(TAG, "Already invisible: " + r);
+                    }
+                }
+            }
+        }
+        return showHomeBehindStack;
+    }
+
+    void convertToTranslucent(ActivityRecord r) {
+        mTranslucentActivityWaiting = r;
+        mUndrawnActivitiesBelowTopTranslucent.clear();
+        mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT);
+    }
+
+    /**
+     * Called as activities below the top translucent activity are redrawn. When the last one is
+     * redrawn notify the top activity by calling
+     * {@link Activity#onTranslucentConversionComplete}.
+     *
+     * @param r The most recent background activity to be drawn. Or, if r is null then a timeout
+     * occurred and the activity will be notified immediately.
+     */
+    void notifyActivityDrawnLocked(ActivityRecord r) {
+        if ((r == null)
+                || (mUndrawnActivitiesBelowTopTranslucent.remove(r) &&
+                        mUndrawnActivitiesBelowTopTranslucent.isEmpty())) {
+            // The last undrawn activity below the top has just been drawn. If there is an
+            // opaque activity at the top, notify it that it can become translucent safely now.
+            final ActivityRecord waitingActivity = mTranslucentActivityWaiting;
+            mTranslucentActivityWaiting = null;
+            mUndrawnActivitiesBelowTopTranslucent.clear();
+            mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG);
+
+            if (waitingActivity != null) {
+                mWindowManager.setWindowOpaque(waitingActivity.appToken, false);
+                if (waitingActivity.app != null && waitingActivity.app.thread != null) {
+                    try {
+                        waitingActivity.app.thread.scheduleTranslucentConversionComplete(
+                                waitingActivity.appToken, r != null);
+                    } catch (RemoteException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Ensure that the top activity in the stack is resumed.
+     *
+     * @param prev The previously resumed activity, for when in the process
+     * of pausing; can be null to call from elsewhere.
+     *
+     * @return Returns true if something is being resumed, or false if
+     * nothing happened.
+     */
+    final boolean resumeTopActivityLocked(ActivityRecord prev) {
+        return resumeTopActivityLocked(prev, null);
+    }
+
+    final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
+        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
+
+        ActivityRecord parent = mActivityContainer.mParentActivity;
+        if (parent != null && parent.state != ActivityState.RESUMED) {
+            // Do not resume this stack if its parent is not resumed.
+            // TODO: If in a loop, make sure that parent stack resumeTopActivity is called 1st.
+            return false;
+        }
+
+        // Find the first activity that is not finishing.
+        ActivityRecord next = topRunningActivityLocked(null);
+
+        // Remember how we'll process this pause/resume situation, and ensure
+        // that the state is reset however we wind up proceeding.
+        final boolean userLeaving = mStackSupervisor.mUserLeaving;
+        mStackSupervisor.mUserLeaving = false;
+
+        if (next == null) {
+            // There are no more activities!  Let's just start up the
+            // Launcher...
+            ActivityOptions.abort(options);
+            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: No more activities go home");
+            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+            // Only resume home if on home display
+            return isOnHomeDisplay() && mStackSupervisor.resumeHomeActivity(prev);
+        }
+
+        next.delayedResume = false;
+
+        // If the top activity is the resumed one, nothing to do.
+        if (mResumedActivity == next && next.state == ActivityState.RESUMED &&
+                    mStackSupervisor.allResumedActivitiesComplete()) {
+            // Make sure we have executed any pending transitions, since there
+            // should be nothing left to do at this point.
+            mWindowManager.executeAppTransition();
+            mNoAnimActivities.clear();
+            ActivityOptions.abort(options);
+            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Top activity resumed " + next);
+            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+            return false;
+        }
+
+        final TaskRecord nextTask = next.task;
+        final TaskRecord prevTask = prev != null ? prev.task : null;
+        if (prevTask != null && prevTask.mOnTopOfHome && prev.finishing && prev.frontOfTask) {
+            if (DEBUG_STACK)  mStackSupervisor.validateTopActivitiesLocked();
+            if (prevTask == nextTask) {
+                prevTask.setFrontOfTask();
+            } else if (prevTask != topTask()) {
+                // This task is going away but it was supposed to return to the home task.
+                // Now the task above it has to return to the home task instead.
+                final int taskNdx = mTaskHistory.indexOf(prevTask) + 1;
+                mTaskHistory.get(taskNdx).mOnTopOfHome = true;
+            } else {
+                if (DEBUG_STATES && isOnHomeDisplay()) Slog.d(TAG,
+                        "resumeTopActivityLocked: Launching home next");
+                // Only resume home if on home display
+                return isOnHomeDisplay() && mStackSupervisor.resumeHomeActivity(prev);
+            }
+        }
+
+        // If we are sleeping, and there is no resumed activity, and the top
+        // activity is paused, well that is the state we want.
+        if (mService.isSleepingOrShuttingDown()
+                && mLastPausedActivity == next
+                && mStackSupervisor.allPausedActivitiesComplete()) {
+            // Make sure we have executed any pending transitions, since there
+            // should be nothing left to do at this point.
+            mWindowManager.executeAppTransition();
+            mNoAnimActivities.clear();
+            ActivityOptions.abort(options);
+            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Going to sleep and all paused");
+            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+            return false;
+        }
+
+        // Make sure that the user who owns this activity is started.  If not,
+        // we will just leave it as is because someone should be bringing
+        // another user's activities to the top of the stack.
+        if (mService.mStartedUsers.get(next.userId) == null) {
+            Slog.w(TAG, "Skipping resume of top activity " + next
+                    + ": user " + next.userId + " is stopped");
+            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+            return false;
+        }
+
+        // The activity may be waiting for stop, but that is no longer
+        // appropriate for it.
+        mStackSupervisor.mStoppingActivities.remove(next);
+        mStackSupervisor.mGoingToSleepActivities.remove(next);
+        next.sleeping = false;
+        mStackSupervisor.mWaitingVisibleActivities.remove(next);
+
+        next.updateOptionsLocked(options);
+
+        if (DEBUG_SWITCH) Slog.v(TAG, "Resuming " + next);
+
+        // If we are currently pausing an activity, then don't do anything
+        // until that is done.
+        if (!mStackSupervisor.allPausedActivitiesComplete()) {
+            if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG,
+                    "resumeTopActivityLocked: Skip resume: some activity pausing.");
+            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+            return false;
+        }
+
+        // Okay we are now going to start a switch, to 'next'.  We may first
+        // have to pause the current activity, but this is an important point
+        // where we have decided to go to 'next' so keep track of that.
+        // XXX "App Redirected" dialog is getting too many false positives
+        // at this point, so turn off for now.
+        if (false) {
+            if (mLastStartedActivity != null && !mLastStartedActivity.finishing) {
+                long now = SystemClock.uptimeMillis();
+                final boolean inTime = mLastStartedActivity.startTime != 0
+                        && (mLastStartedActivity.startTime + START_WARN_TIME) >= now;
+                final int lastUid = mLastStartedActivity.info.applicationInfo.uid;
+                final int nextUid = next.info.applicationInfo.uid;
+                if (inTime && lastUid != nextUid
+                        && lastUid != next.launchedFromUid
+                        && mService.checkPermission(
+                                android.Manifest.permission.STOP_APP_SWITCHES,
+                                -1, next.launchedFromUid)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    mService.showLaunchWarningLocked(mLastStartedActivity, next);
+                } else {
+                    next.startTime = now;
+                    mLastStartedActivity = next;
+                }
+            } else {
+                next.startTime = SystemClock.uptimeMillis();
+                mLastStartedActivity = next;
+            }
+        }
+
+        // We need to start pausing the current activity so the top one
+        // can be resumed...
+        boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving);
+        if (mResumedActivity != null) {
+            pausing = true;
+            startPausingLocked(userLeaving, false);
+            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Pausing " + mResumedActivity);
+        }
+        if (pausing) {
+            if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG,
+                    "resumeTopActivityLocked: Skip resume: need to start pausing");
+            // At this point we want to put the upcoming activity's process
+            // at the top of the LRU list, since we know we will be needing it
+            // very soon and it would be a waste to let it get killed if it
+            // happens to be sitting towards the end.
+            if (next.app != null && next.app.thread != null) {
+                // No reason to do full oom adj update here; we'll let that
+                // happen whenever it needs to later.
+                mService.updateLruProcessLocked(next.app, true, null);
+            }
+            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+            return true;
+        }
+
+        // If the most recent activity was noHistory but was only stopped rather
+        // than stopped+finished because the device went to sleep, we need to make
+        // sure to finish it as we're making a new activity topmost.
+        if (mService.mSleeping && mLastNoHistoryActivity != null &&
+                !mLastNoHistoryActivity.finishing) {
+            if (DEBUG_STATES) Slog.d(TAG, "no-history finish of " + mLastNoHistoryActivity +
+                    " on new resume");
+            requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED,
+                    null, "no-history", false);
+            mLastNoHistoryActivity = null;
+        }
+
+        if (prev != null && prev != next) {
+            if (!prev.waitingVisible && next != null && !next.nowVisible) {
+                prev.waitingVisible = true;
+                mStackSupervisor.mWaitingVisibleActivities.add(prev);
+                if (DEBUG_SWITCH) Slog.v(
+                        TAG, "Resuming top, waiting visible to hide: " + prev);
+            } else {
+                // The next activity is already visible, so hide the previous
+                // activity's windows right now so we can show the new one ASAP.
+                // We only do this if the previous is finishing, which should mean
+                // it is on top of the one being resumed so hiding it quickly
+                // is good.  Otherwise, we want to do the normal route of allowing
+                // the resumed activity to be shown so we can decide if the
+                // previous should actually be hidden depending on whether the
+                // new one is found to be full-screen or not.
+                if (prev.finishing) {
+                    mWindowManager.setAppVisibility(prev.appToken, false);
+                    if (DEBUG_SWITCH) Slog.v(TAG, "Not waiting for visible to hide: "
+                            + prev + ", waitingVisible="
+                            + (prev != null ? prev.waitingVisible : null)
+                            + ", nowVisible=" + next.nowVisible);
+                } else {
+                    if (DEBUG_SWITCH) Slog.v(TAG, "Previous already visible but still waiting to hide: "
+                        + prev + ", waitingVisible="
+                        + (prev != null ? prev.waitingVisible : null)
+                        + ", nowVisible=" + next.nowVisible);
+                }
+            }
+        }
+
+        // Launching this app's activity, make sure the app is no longer
+        // considered stopped.
+        try {
+            AppGlobals.getPackageManager().setPackageStoppedState(
+                    next.packageName, false, next.userId); /* TODO: Verify if correct userid */
+        } catch (RemoteException e1) {
+        } catch (IllegalArgumentException e) {
+            Slog.w(TAG, "Failed trying to unstop package "
+                    + next.packageName + ": " + e);
+        }
+
+        // We are starting up the next activity, so tell the window manager
+        // that the previous one will be hidden soon.  This way it can know
+        // to ignore it when computing the desired screen orientation.
+        boolean anim = true;
+        if (prev != null) {
+            if (prev.finishing) {
+                if (DEBUG_TRANSITION) Slog.v(TAG,
+                        "Prepare close transition: prev=" + prev);
+                if (mNoAnimActivities.contains(prev)) {
+                    anim = false;
+                    mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
+                } else {
+                    mWindowManager.prepareAppTransition(prev.task == next.task
+                            ? AppTransition.TRANSIT_ACTIVITY_CLOSE
+                            : AppTransition.TRANSIT_TASK_CLOSE, false);
+                }
+                mWindowManager.setAppWillBeHidden(prev.appToken);
+                mWindowManager.setAppVisibility(prev.appToken, false);
+            } else {
+                if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: prev=" + prev);
+                if (mNoAnimActivities.contains(next)) {
+                    anim = false;
+                    mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
+                } else {
+                    mWindowManager.prepareAppTransition(prev.task == next.task
+                            ? AppTransition.TRANSIT_ACTIVITY_OPEN
+                            : AppTransition.TRANSIT_TASK_OPEN, false);
+                }
+            }
+            if (false) {
+                mWindowManager.setAppWillBeHidden(prev.appToken);
+                mWindowManager.setAppVisibility(prev.appToken, false);
+            }
+        } else {
+            if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: no previous");
+            if (mNoAnimActivities.contains(next)) {
+                anim = false;
+                mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
+            } else {
+                mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false);
+            }
+        }
+        if (anim) {
+            next.applyOptionsLocked();
+        } else {
+            next.clearOptionsLocked();
+        }
+
+        ActivityStack lastStack = mStackSupervisor.getLastStack();
+        if (next.app != null && next.app.thread != null) {
+            if (DEBUG_SWITCH) Slog.v(TAG, "Resume running: " + next);
+
+            // This activity is now becoming visible.
+            mWindowManager.setAppVisibility(next.appToken, true);
+
+            // schedule launch ticks to collect information about slow apps.
+            next.startLaunchTickingLocked();
+
+            ActivityRecord lastResumedActivity =
+                    lastStack == null ? null :lastStack.mResumedActivity;
+            ActivityState lastState = next.state;
+
+            mService.updateCpuStats();
+
+            if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + next + " (in existing)");
+            next.state = ActivityState.RESUMED;
+            mResumedActivity = next;
+            next.task.touchActiveTime();
+            mService.addRecentTaskLocked(next.task);
+            mService.updateLruProcessLocked(next.app, true, null);
+            updateLRUListLocked(next);
+            mService.updateOomAdjLocked();
+
+            // Have the window manager re-evaluate the orientation of
+            // the screen based on the new activity order.
+            boolean notUpdated = true;
+            if (mStackSupervisor.isFrontStack(this)) {
+                Configuration config = mWindowManager.updateOrientationFromAppTokens(
+                        mService.mConfiguration,
+                        next.mayFreezeScreenLocked(next.app) ? next.appToken : null);
+                if (config != null) {
+                    next.frozenBeforeDestroy = true;
+                }
+                notUpdated = !mService.updateConfigurationLocked(config, next, false, false);
+            }
+
+            if (notUpdated) {
+                // The configuration update wasn't able to keep the existing
+                // instance of the activity, and instead started a new one.
+                // We should be all done, but let's just make sure our activity
+                // is still at the top and schedule another run if something
+                // weird happened.
+                ActivityRecord nextNext = topRunningActivityLocked(null);
+                if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG,
+                        "Activity config changed during resume: " + next
+                        + ", new next: " + nextNext);
+                if (nextNext != next) {
+                    // Do over!
+                    mStackSupervisor.scheduleResumeTopActivities();
+                }
+                if (mStackSupervisor.reportResumedActivityLocked(next)) {
+                    mNoAnimActivities.clear();
+                    if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+                    return true;
+                }
+                if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+                return false;
+            }
+
+            try {
+                // Deliver all pending results.
+                ArrayList<ResultInfo> a = next.results;
+                if (a != null) {
+                    final int N = a.size();
+                    if (!next.finishing && N > 0) {
+                        if (DEBUG_RESULTS) Slog.v(
+                                TAG, "Delivering results to " + next
+                                + ": " + a);
+                        next.app.thread.scheduleSendResult(next.appToken, a);
+                    }
+                }
+
+                if (next.newIntents != null) {
+                    next.app.thread.scheduleNewIntent(next.newIntents, next.appToken);
+                }
+
+                EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY,
+                        next.userId, System.identityHashCode(next),
+                        next.task.taskId, next.shortComponentName);
+
+                next.sleeping = false;
+                mService.showAskCompatModeDialogLocked(next);
+                next.app.pendingUiClean = true;
+                next.app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP);
+                next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState,
+                        mService.isNextTransitionForward());
+
+                mStackSupervisor.checkReadyForSleepLocked();
+
+                if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Resumed " + next);
+            } catch (Exception e) {
+                // Whoops, need to restart this activity!
+                if (DEBUG_STATES) Slog.v(TAG, "Resume failed; resetting state to "
+                        + lastState + ": " + next);
+                next.state = lastState;
+                if (lastStack != null) {
+                    lastStack.mResumedActivity = lastResumedActivity;
+                }
+                Slog.i(TAG, "Restarting because process died: " + next);
+                if (!next.hasBeenLaunched) {
+                    next.hasBeenLaunched = true;
+                } else  if (SHOW_APP_STARTING_PREVIEW && lastStack != null &&
+                        mStackSupervisor.isFrontStack(lastStack)) {
+                    mWindowManager.setAppStartingWindow(
+                            next.appToken, next.packageName, next.theme,
+                            mService.compatibilityInfoForPackageLocked(next.info.applicationInfo),
+                            next.nonLocalizedLabel, next.labelRes, next.icon, next.logo,
+                            next.windowFlags, null, true);
+                }
+                mStackSupervisor.startSpecificActivityLocked(next, true, false);
+                if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+                return true;
+            }
+
+            // From this point on, if something goes wrong there is no way
+            // to recover the activity.
+            try {
+                next.visible = true;
+                completeResumeLocked(next);
+            } catch (Exception e) {
+                // If any exception gets thrown, toss away this
+                // activity and try the next one.
+                Slog.w(TAG, "Exception thrown during resume of " + next, e);
+                requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null,
+                        "resume-exception", true);
+                if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+                return true;
+            }
+            next.stopped = false;
+
+        } else {
+            // Whoops, need to restart this activity!
+            if (!next.hasBeenLaunched) {
+                next.hasBeenLaunched = true;
+            } else {
+                if (SHOW_APP_STARTING_PREVIEW) {
+                    mWindowManager.setAppStartingWindow(
+                            next.appToken, next.packageName, next.theme,
+                            mService.compatibilityInfoForPackageLocked(
+                                    next.info.applicationInfo),
+                            next.nonLocalizedLabel,
+                            next.labelRes, next.icon, next.logo, next.windowFlags,
+                            null, true);
+                }
+                if (DEBUG_SWITCH) Slog.v(TAG, "Restarting: " + next);
+            }
+            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Restarting " + next);
+            mStackSupervisor.startSpecificActivityLocked(next, true, true);
+        }
+
+        if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+        return true;
+    }
+
+    private void insertTaskAtTop(TaskRecord task) {
+        // If this is being moved to the top by another activity or being launched from the home
+        // activity, set mOnTopOfHome accordingly.
+        if (isOnHomeDisplay()) {
+            ActivityStack lastStack = mStackSupervisor.getLastStack();
+            final boolean fromHome = lastStack.isHomeStack();
+            if (!isHomeStack() && (fromHome || topTask() != task)) {
+                task.mOnTopOfHome = fromHome;
+            }
+        } else {
+            task.mOnTopOfHome = false;
+        }
+
+        mTaskHistory.remove(task);
+        // Now put task at top.
+        int stackNdx = mTaskHistory.size();
+        if (task.userId != mCurrentUser) {
+            // Put non-current user tasks below current user tasks.
+            while (--stackNdx >= 0) {
+                if (mTaskHistory.get(stackNdx).userId != mCurrentUser) {
+                    break;
+                }
+            }
+            ++stackNdx;
+        }
+        mTaskHistory.add(stackNdx, task);
+    }
+
+    final void startActivityLocked(ActivityRecord r, boolean newTask,
+            boolean doResume, boolean keepCurTransition, Bundle options) {
+        TaskRecord rTask = r.task;
+        final int taskId = rTask.taskId;
+        if (taskForIdLocked(taskId) == null || newTask) {
+            // Last activity in task had been removed or ActivityManagerService is reusing task.
+            // Insert or replace.
+            // Might not even be in.
+            insertTaskAtTop(rTask);
+            mWindowManager.moveTaskToTop(taskId);
+        }
+        TaskRecord task = null;
+        if (!newTask) {
+            // If starting in an existing task, find where that is...
+            boolean startIt = true;
+            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+                task = mTaskHistory.get(taskNdx);
+                if (task == r.task) {
+                    // Here it is!  Now, if this is not yet visible to the
+                    // user, then just add it without starting; it will
+                    // get started when the user navigates back to it.
+                    if (!startIt) {
+                        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task "
+                                + task, new RuntimeException("here").fillInStackTrace());
+                        task.addActivityToTop(r);
+                        r.putInHistory();
+                        mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
+                                r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
+                                (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,
+                                r.userId, r.info.configChanges);
+                        if (VALIDATE_TOKENS) {
+                            validateAppTokensLocked();
+                        }
+                        ActivityOptions.abort(options);
+                        return;
+                    }
+                    break;
+                } else if (task.numFullscreen > 0) {
+                    startIt = false;
+                }
+            }
+        }
+
+        // Place a new activity at top of stack, so it is next to interact
+        // with the user.
+
+        // If we are not placing the new activity frontmost, we do not want
+        // to deliver the onUserLeaving callback to the actual frontmost
+        // activity
+        if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) {
+            mStackSupervisor.mUserLeaving = false;
+            if (DEBUG_USER_LEAVING) Slog.v(TAG,
+                    "startActivity() behind front, mUserLeaving=false");
+        }
+
+        task = r.task;
+
+        // Slot the activity into the history stack and proceed
+        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to stack to task " + task,
+                new RuntimeException("here").fillInStackTrace());
+        task.addActivityToTop(r);
+        task.setFrontOfTask();
+
+        r.putInHistory();
+        if (!isHomeStack() || numActivities() > 0) {
+            // We want to show the starting preview window if we are
+            // switching to a new task, or the next activity's process is
+            // not currently running.
+            boolean showStartingIcon = newTask;
+            ProcessRecord proc = r.app;
+            if (proc == null) {
+                proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid);
+            }
+            if (proc == null || proc.thread == null) {
+                showStartingIcon = true;
+            }
+            if (DEBUG_TRANSITION) Slog.v(TAG,
+                    "Prepare open transition: starting " + r);
+            if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
+                mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition);
+                mNoAnimActivities.add(r);
+            } else {
+                mWindowManager.prepareAppTransition(newTask
+                        ? AppTransition.TRANSIT_TASK_OPEN
+                        : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition);
+                mNoAnimActivities.remove(r);
+            }
+            r.updateOptionsLocked(options);
+            mWindowManager.addAppToken(task.mActivities.indexOf(r),
+                    r.appToken, r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
+                    (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId,
+                    r.info.configChanges);
+            boolean doShow = true;
+            if (newTask) {
+                // Even though this activity is starting fresh, we still need
+                // to reset it to make sure we apply affinities to move any
+                // existing activities from other tasks in to it.
+                // If the caller has requested that the target task be
+                // reset, then do so.
+                if ((r.intent.getFlags()
+                        &Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
+                    resetTaskIfNeededLocked(r, r);
+                    doShow = topRunningNonDelayedActivityLocked(null) == r;
+                }
+            }
+            if (SHOW_APP_STARTING_PREVIEW && doShow) {
+                // Figure out if we are transitioning from another activity that is
+                // "has the same starting icon" as the next one.  This allows the
+                // window manager to keep the previous window it had previously
+                // created, if it still had one.
+                ActivityRecord prev = mResumedActivity;
+                if (prev != null) {
+                    // We don't want to reuse the previous starting preview if:
+                    // (1) The current activity is in a different task.
+                    if (prev.task != r.task) {
+                        prev = null;
+                    }
+                    // (2) The current activity is already displayed.
+                    else if (prev.nowVisible) {
+                        prev = null;
+                    }
+                }
+                mWindowManager.setAppStartingWindow(
+                        r.appToken, r.packageName, r.theme,
+                        mService.compatibilityInfoForPackageLocked(
+                                r.info.applicationInfo), r.nonLocalizedLabel,
+                        r.labelRes, r.icon, r.logo, r.windowFlags,
+                        prev != null ? prev.appToken : null, showStartingIcon);
+            }
+        } else {
+            // If this is the first activity, don't do any fancy animations,
+            // because there is nothing for it to animate on top of.
+            mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
+                    r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
+                    (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId,
+                    r.info.configChanges);
+            ActivityOptions.abort(options);
+        }
+        if (VALIDATE_TOKENS) {
+            validateAppTokensLocked();
+        }
+
+        if (doResume) {
+            mStackSupervisor.resumeTopActivitiesLocked();
+        }
+    }
+
+    final void validateAppTokensLocked() {
+        mValidateAppTokens.clear();
+        mValidateAppTokens.ensureCapacity(numActivities());
+        final int numTasks = mTaskHistory.size();
+        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
+            TaskRecord task = mTaskHistory.get(taskNdx);
+            final ArrayList<ActivityRecord> activities = task.mActivities;
+            if (activities.isEmpty()) {
+                continue;
+            }
+            TaskGroup group = new TaskGroup();
+            group.taskId = task.taskId;
+            mValidateAppTokens.add(group);
+            final int numActivities = activities.size();
+            for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                group.tokens.add(r.appToken);
+            }
+        }
+        mWindowManager.validateAppTokens(mStackId, mValidateAppTokens);
+    }
+
+    /**
+     * Perform a reset of the given task, if needed as part of launching it.
+     * Returns the new HistoryRecord at the top of the task.
+     */
+    /**
+     * Helper method for #resetTaskIfNeededLocked.
+     * We are inside of the task being reset...  we'll either finish this activity, push it out
+     * for another task, or leave it as-is.
+     * @param task The task containing the Activity (taskTop) that might be reset.
+     * @param forceReset
+     * @return An ActivityOptions that needs to be processed.
+     */
+    final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) {
+        ActivityOptions topOptions = null;
+
+        int replyChainEnd = -1;
+        boolean canMoveOptions = true;
+
+        // We only do this for activities that are not the root of the task (since if we finish
+        // the root, we may no longer have the task!).
+        final ArrayList<ActivityRecord> activities = task.mActivities;
+        final int numActivities = activities.size();
+        for (int i = numActivities - 1; i > 0; --i ) {
+            ActivityRecord target = activities.get(i);
+
+            final int flags = target.info.flags;
+            final boolean finishOnTaskLaunch =
+                    (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0;
+            final boolean allowTaskReparenting =
+                    (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0;
+            final boolean clearWhenTaskReset =
+                    (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0;
+
+            if (!finishOnTaskLaunch
+                    && !clearWhenTaskReset
+                    && target.resultTo != null) {
+                // If this activity is sending a reply to a previous
+                // activity, we can't do anything with it now until
+                // we reach the start of the reply chain.
+                // XXX note that we are assuming the result is always
+                // to the previous activity, which is almost always
+                // the case but we really shouldn't count on.
+                if (replyChainEnd < 0) {
+                    replyChainEnd = i;
+                }
+            } else if (!finishOnTaskLaunch
+                    && !clearWhenTaskReset
+                    && allowTaskReparenting
+                    && target.taskAffinity != null
+                    && !target.taskAffinity.equals(task.affinity)) {
+                // If this activity has an affinity for another
+                // task, then we need to move it out of here.  We will
+                // move it as far out of the way as possible, to the
+                // bottom of the activity stack.  This also keeps it
+                // correctly ordered with any activities we previously
+                // moved.
+                final ThumbnailHolder newThumbHolder;
+                final TaskRecord targetTask;
+                final ActivityRecord bottom =
+                        !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ?
+                                mTaskHistory.get(0).mActivities.get(0) : null;
+                if (bottom != null && target.taskAffinity != null
+                        && target.taskAffinity.equals(bottom.task.affinity)) {
+                    // If the activity currently at the bottom has the
+                    // same task affinity as the one we are moving,
+                    // then merge it into the same task.
+                    targetTask = bottom.task;
+                    newThumbHolder = bottom.thumbHolder == null ? targetTask : bottom.thumbHolder;
+                    if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target
+                            + " out to bottom task " + bottom.task);
+                } else {
+                    targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info,
+                            null, false);
+                    newThumbHolder = targetTask;
+                    targetTask.affinityIntent = target.intent;
+                    if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target
+                            + " out to new task " + target.task);
+                }
+
+                if (clearWhenTaskReset) {
+                    // This is the start of a new sub-task.
+                    if (target.thumbHolder == null) {
+                        target.thumbHolder = new ThumbnailHolder();
+                    }
+                } else {
+                    target.thumbHolder = newThumbHolder;
+                }
+
+                final int targetTaskId = targetTask.taskId;
+                mWindowManager.setAppGroupId(target.appToken, targetTaskId);
+
+                boolean noOptions = canMoveOptions;
+                final int start = replyChainEnd < 0 ? i : replyChainEnd;
+                for (int srcPos = start; srcPos >= i; --srcPos) {
+                    final ActivityRecord p = activities.get(srcPos);
+                    if (p.finishing) {
+                        continue;
+                    }
+
+                    ThumbnailHolder curThumbHolder = p.thumbHolder;
+                    canMoveOptions = false;
+                    if (noOptions && topOptions == null) {
+                        topOptions = p.takeOptionsLocked();
+                        if (topOptions != null) {
+                            noOptions = false;
+                        }
+                    }
+                    if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing activity " + p + " from task="
+                            + task + " adding to task=" + targetTask
+                            + " Callers=" + Debug.getCallers(4));
+                    if (DEBUG_TASKS) Slog.v(TAG, "Pushing next activity " + p
+                            + " out to target's task " + target.task);
+                    p.setTask(targetTask, curThumbHolder, false);
+                    targetTask.addActivityAtBottom(p);
+
+                    mWindowManager.setAppGroupId(p.appToken, targetTaskId);
+                }
+
+                mWindowManager.moveTaskToBottom(targetTaskId);
+                if (VALIDATE_TOKENS) {
+                    validateAppTokensLocked();
+                }
+
+                replyChainEnd = -1;
+            } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) {
+                // If the activity should just be removed -- either
+                // because it asks for it, or the task should be
+                // cleared -- then finish it and anything that is
+                // part of its reply chain.
+                int end;
+                if (clearWhenTaskReset) {
+                    // In this case, we want to finish this activity
+                    // and everything above it, so be sneaky and pretend
+                    // like these are all in the reply chain.
+                    end = numActivities - 1;
+                } else if (replyChainEnd < 0) {
+                    end = i;
+                } else {
+                    end = replyChainEnd;
+                }
+                boolean noOptions = canMoveOptions;
+                for (int srcPos = i; srcPos <= end; srcPos++) {
+                    ActivityRecord p = activities.get(srcPos);
+                    if (p.finishing) {
+                        continue;
+                    }
+                    canMoveOptions = false;
+                    if (noOptions && topOptions == null) {
+                        topOptions = p.takeOptionsLocked();
+                        if (topOptions != null) {
+                            noOptions = false;
+                        }
+                    }
+                    if (DEBUG_TASKS) Slog.w(TAG,
+                            "resetTaskIntendedTask: calling finishActivity on " + p);
+                    if (finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false)) {
+                        end--;
+                        srcPos--;
+                    }
+                }
+                replyChainEnd = -1;
+            } else {
+                // If we were in the middle of a chain, well the
+                // activity that started it all doesn't want anything
+                // special, so leave it all as-is.
+                replyChainEnd = -1;
+            }
+        }
+
+        return topOptions;
+    }
+
+    /**
+     * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given
+     * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop.
+     * @param affinityTask The task we are looking for an affinity to.
+     * @param task Task that resetTaskIfNeededLocked.taskTop belongs to.
+     * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked.
+     * @param forceReset Flag passed in to resetTaskIfNeededLocked.
+     */
+    private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task,
+            boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) {
+        int replyChainEnd = -1;
+        final int taskId = task.taskId;
+        final String taskAffinity = task.affinity;
+
+        final ArrayList<ActivityRecord> activities = affinityTask.mActivities;
+        final int numActivities = activities.size();
+        // Do not operate on the root Activity.
+        for (int i = numActivities - 1; i > 0; --i) {
+            ActivityRecord target = activities.get(i);
+
+            final int flags = target.info.flags;
+            boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0;
+            boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0;
+
+            if (target.resultTo != null) {
+                // If this activity is sending a reply to a previous
+                // activity, we can't do anything with it now until
+                // we reach the start of the reply chain.
+                // XXX note that we are assuming the result is always
+                // to the previous activity, which is almost always
+                // the case but we really shouldn't count on.
+                if (replyChainEnd < 0) {
+                    replyChainEnd = i;
+                }
+            } else if (topTaskIsHigher
+                    && allowTaskReparenting
+                    && taskAffinity != null
+                    && taskAffinity.equals(target.taskAffinity)) {
+                // This activity has an affinity for our task. Either remove it if we are
+                // clearing or move it over to our task.  Note that
+                // we currently punt on the case where we are resetting a
+                // task that is not at the top but who has activities above
+                // with an affinity to it...  this is really not a normal
+                // case, and we will need to later pull that task to the front
+                // and usually at that point we will do the reset and pick
+                // up those remaining activities.  (This only happens if
+                // someone starts an activity in a new task from an activity
+                // in a task that is not currently on top.)
+                if (forceReset || finishOnTaskLaunch) {
+                    final int start = replyChainEnd >= 0 ? replyChainEnd : i;
+                    if (DEBUG_TASKS) Slog.v(TAG, "Finishing task at index " + start + " to " + i);
+                    for (int srcPos = start; srcPos >= i; --srcPos) {
+                        final ActivityRecord p = activities.get(srcPos);
+                        if (p.finishing) {
+                            continue;
+                        }
+                        finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false);
+                    }
+                } else {
+                    if (taskInsertionPoint < 0) {
+                        taskInsertionPoint = task.mActivities.size();
+
+                    }
+
+                    final int start = replyChainEnd >= 0 ? replyChainEnd : i;
+                    if (DEBUG_TASKS) Slog.v(TAG, "Reparenting from task=" + affinityTask + ":"
+                            + start + "-" + i + " to task=" + task + ":" + taskInsertionPoint);
+                    for (int srcPos = start; srcPos >= i; --srcPos) {
+                        final ActivityRecord p = activities.get(srcPos);
+                        p.setTask(task, null, false);
+                        task.addActivityAtIndex(taskInsertionPoint, p);
+
+                        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + p
+                                + " to stack at " + task,
+                                new RuntimeException("here").fillInStackTrace());
+                        if (DEBUG_TASKS) Slog.v(TAG, "Pulling activity " + p + " from " + srcPos
+                                + " in to resetting task " + task);
+                        mWindowManager.setAppGroupId(p.appToken, taskId);
+                    }
+                    mWindowManager.moveTaskToTop(taskId);
+                    if (VALIDATE_TOKENS) {
+                        validateAppTokensLocked();
+                    }
+
+                    // Now we've moved it in to place...  but what if this is
+                    // a singleTop activity and we have put it on top of another
+                    // instance of the same activity?  Then we drop the instance
+                    // below so it remains singleTop.
+                    if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
+                        ArrayList<ActivityRecord> taskActivities = task.mActivities;
+                        int targetNdx = taskActivities.indexOf(target);
+                        if (targetNdx > 0) {
+                            ActivityRecord p = taskActivities.get(targetNdx - 1);
+                            if (p.intent.getComponent().equals(target.intent.getComponent())) {
+                                finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace",
+                                        false);
+                            }
+                        }
+                    }
+                }
+
+                replyChainEnd = -1;
+            }
+        }
+        return taskInsertionPoint;
+    }
+
+    final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
+            ActivityRecord newActivity) {
+        boolean forceReset =
+                (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0;
+        if (ACTIVITY_INACTIVE_RESET_TIME > 0
+                && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) {
+            if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) {
+                forceReset = true;
+            }
+        }
+
+        final TaskRecord task = taskTop.task;
+
+        /** False until we evaluate the TaskRecord associated with taskTop. Switches to true
+         * for remaining tasks. Used for later tasks to reparent to task. */
+        boolean taskFound = false;
+
+        /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */
+        ActivityOptions topOptions = null;
+
+        // Preserve the location for reparenting in the new task.
+        int reparentInsertionPoint = -1;
+
+        for (int i = mTaskHistory.size() - 1; i >= 0; --i) {
+            final TaskRecord targetTask = mTaskHistory.get(i);
+
+            if (targetTask == task) {
+                topOptions = resetTargetTaskIfNeededLocked(task, forceReset);
+                taskFound = true;
+            } else {
+                reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task,
+                        taskFound, forceReset, reparentInsertionPoint);
+            }
+        }
+
+        int taskNdx = mTaskHistory.indexOf(task);
+        do {
+            taskTop = mTaskHistory.get(taskNdx--).getTopActivity();
+        } while (taskTop == null && taskNdx >= 0);
+
+        if (topOptions != null) {
+            // If we got some ActivityOptions from an activity on top that
+            // was removed from the task, propagate them to the new real top.
+            if (taskTop != null) {
+                taskTop.updateOptionsLocked(topOptions);
+            } else {
+                topOptions.abort();
+            }
+        }
+
+        return taskTop;
+    }
+
+    void sendActivityResultLocked(int callingUid, ActivityRecord r,
+            String resultWho, int requestCode, int resultCode, Intent data) {
+
+        if (callingUid > 0) {
+            mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
+                    data, r.getUriPermissionsLocked());
+        }
+
+        if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r
+                + " : who=" + resultWho + " req=" + requestCode
+                + " res=" + resultCode + " data=" + data);
+        if (mResumedActivity == r && r.app != null && r.app.thread != null) {
+            try {
+                ArrayList<ResultInfo> list = new ArrayList<ResultInfo>();
+                list.add(new ResultInfo(resultWho, requestCode,
+                        resultCode, data));
+                r.app.thread.scheduleSendResult(r.appToken, list);
+                return;
+            } catch (Exception e) {
+                Slog.w(TAG, "Exception thrown sending result to " + r, e);
+            }
+        }
+
+        r.addResultLocked(null, resultWho, requestCode, resultCode, data);
+    }
+
+    private void adjustFocusedActivityLocked(ActivityRecord r) {
+        if (mStackSupervisor.isFrontStack(this) && mService.mFocusedActivity == r) {
+            ActivityRecord next = topRunningActivityLocked(null);
+            if (next != r) {
+                final TaskRecord task = r.task;
+                if (r.frontOfTask && task == topTask() && task.mOnTopOfHome) {
+                    mStackSupervisor.moveHomeToTop();
+                }
+            }
+            mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked());
+        }
+    }
+
+    final void stopActivityLocked(ActivityRecord r) {
+        if (DEBUG_SWITCH) Slog.d(TAG, "Stopping: " + r);
+        if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0
+                || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) {
+            if (!r.finishing) {
+                if (!mService.mSleeping) {
+                    if (DEBUG_STATES) {
+                        Slog.d(TAG, "no-history finish of " + r);
+                    }
+                    requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
+                            "no-history", false);
+                } else {
+                    if (DEBUG_STATES) Slog.d(TAG, "Not finishing noHistory " + r
+                            + " on stop because we're just sleeping");
+                }
+            }
+        }
+
+        if (r.app != null && r.app.thread != null) {
+            adjustFocusedActivityLocked(r);
+            r.resumeKeyDispatchingLocked();
+            try {
+                r.stopped = false;
+                if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r
+                        + " (stop requested)");
+                r.state = ActivityState.STOPPING;
+                if (DEBUG_VISBILITY) Slog.v(
+                        TAG, "Stopping visible=" + r.visible + " for " + r);
+                if (!r.visible) {
+                    mWindowManager.setAppVisibility(r.appToken, false);
+                }
+                r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags);
+                if (mService.isSleepingOrShuttingDown()) {
+                    r.setSleeping(true);
+                }
+                Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r);
+                mHandler.sendMessageDelayed(msg, STOP_TIMEOUT);
+            } catch (Exception e) {
+                // Maybe just ignore exceptions here...  if the process
+                // has crashed, our death notification will clean things
+                // up.
+                Slog.w(TAG, "Exception thrown during pause", e);
+                // Just in case, assume it to be stopped.
+                r.stopped = true;
+                if (DEBUG_STATES) Slog.v(TAG, "Stop failed; moving to STOPPED: " + r);
+                r.state = ActivityState.STOPPED;
+                if (r.configDestroy) {
+                    destroyActivityLocked(r, true, false, "stop-except");
+                }
+            }
+        }
+    }
+
+    /**
+     * @return Returns true if the activity is being finished, false if for
+     * some reason it is being left as-is.
+     */
+    final boolean requestFinishActivityLocked(IBinder token, int resultCode,
+            Intent resultData, String reason, boolean oomAdj) {
+        ActivityRecord r = isInStackLocked(token);
+        if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(
+                TAG, "Finishing activity token=" + token + " r="
+                + ", result=" + resultCode + ", data=" + resultData
+                + ", reason=" + reason);
+        if (r == null) {
+            return false;
+        }
+
+        finishActivityLocked(r, resultCode, resultData, reason, oomAdj);
+        return true;
+    }
+
+    final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                ActivityRecord r = activities.get(activityNdx);
+                if (r.resultTo == self && r.requestCode == requestCode) {
+                    if ((r.resultWho == null && resultWho == null) ||
+                        (r.resultWho != null && r.resultWho.equals(resultWho))) {
+                        finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub",
+                                false);
+                    }
+                }
+            }
+        }
+        mService.updateOomAdjLocked();
+    }
+
+    final void finishTopRunningActivityLocked(ProcessRecord app) {
+        ActivityRecord r = topRunningActivityLocked(null);
+        if (r != null && r.app == app) {
+            // If the top running activity is from this crashing
+            // process, then terminate it to avoid getting in a loop.
+            Slog.w(TAG, "  Force finishing activity "
+                    + r.intent.getComponent().flattenToShortString());
+            int taskNdx = mTaskHistory.indexOf(r.task);
+            int activityNdx = r.task.mActivities.indexOf(r);
+            finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false);
+            // Also terminate any activities below it that aren't yet
+            // stopped, to avoid a situation where one will get
+            // re-start our crashing activity once it gets resumed again.
+            --activityNdx;
+            if (activityNdx < 0) {
+                do {
+                    --taskNdx;
+                    if (taskNdx < 0) {
+                        break;
+                    }
+                    activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1;
+                } while (activityNdx < 0);
+            }
+            if (activityNdx >= 0) {
+                r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx);
+                if (r.state == ActivityState.RESUMED
+                        || r.state == ActivityState.PAUSING
+                        || r.state == ActivityState.PAUSED) {
+                    if (!r.isHomeActivity() || mService.mHomeProcess != r.app) {
+                        Slog.w(TAG, "  Force finishing activity "
+                                + r.intent.getComponent().flattenToShortString());
+                        finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false);
+                    }
+                }
+            }
+        }
+    }
+
+    final boolean finishActivityAffinityLocked(ActivityRecord r) {
+        ArrayList<ActivityRecord> activities = r.task.mActivities;
+        for (int index = activities.indexOf(r); index >= 0; --index) {
+            ActivityRecord cur = activities.get(index);
+            if (!Objects.equals(cur.taskAffinity, r.taskAffinity)) {
+                break;
+            }
+            finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true);
+        }
+        return true;
+    }
+
+    final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) {
+        // send the result
+        ActivityRecord resultTo = r.resultTo;
+        if (resultTo != null) {
+            if (DEBUG_RESULTS) Slog.v(TAG, "Adding result to " + resultTo
+                    + " who=" + r.resultWho + " req=" + r.requestCode
+                    + " res=" + resultCode + " data=" + resultData);
+            if (r.info.applicationInfo.uid > 0) {
+                mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid,
+                        resultTo.packageName, resultData,
+                        resultTo.getUriPermissionsLocked());
+            }
+            resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode,
+                                     resultData);
+            r.resultTo = null;
+        }
+        else if (DEBUG_RESULTS) Slog.v(TAG, "No result destination from " + r);
+
+        // Make sure this HistoryRecord is not holding on to other resources,
+        // because clients have remote IPC references to this object so we
+        // can't assume that will go away and want to avoid circular IPC refs.
+        r.results = null;
+        r.pendingResults = null;
+        r.newIntents = null;
+        r.icicle = null;
+    }
+
+    /**
+     * @return Returns true if this activity has been removed from the history
+     * list, or false if it is still in the list and will be removed later.
+     */
+    final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData,
+            String reason, boolean oomAdj) {
+        if (r.finishing) {
+            Slog.w(TAG, "Duplicate finish request for " + r);
+            return false;
+        }
+
+        r.makeFinishing();
+        EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,
+                r.userId, System.identityHashCode(r),
+                r.task.taskId, r.shortComponentName, reason);
+        final ArrayList<ActivityRecord> activities = r.task.mActivities;
+        final int index = activities.indexOf(r);
+        if (index < (activities.size() - 1)) {
+            r.task.setFrontOfTask();
+            if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
+                // If the caller asked that this activity (and all above it)
+                // be cleared when the task is reset, don't lose that information,
+                // but propagate it up to the next activity.
+                ActivityRecord next = activities.get(index+1);
+                next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
+            }
+        }
+
+        r.pauseKeyDispatchingLocked();
+
+        adjustFocusedActivityLocked(r);
+
+        finishActivityResultsLocked(r, resultCode, resultData);
+
+        if (!mService.mPendingThumbnails.isEmpty()) {
+            // There are clients waiting to receive thumbnails so, in case
+            // this is an activity that someone is waiting for, add it
+            // to the pending list so we can correctly update the clients.
+            mStackSupervisor.mCancelledThumbnails.add(r);
+        }
+
+        if (mResumedActivity == r) {
+            boolean endTask = index <= 0;
+            if (DEBUG_VISBILITY || DEBUG_TRANSITION) Slog.v(TAG,
+                    "Prepare close transition: finishing " + r);
+            mWindowManager.prepareAppTransition(endTask
+                    ? AppTransition.TRANSIT_TASK_CLOSE
+                    : AppTransition.TRANSIT_ACTIVITY_CLOSE, false);
+
+            // Tell window manager to prepare for this one to be removed.
+            mWindowManager.setAppVisibility(r.appToken, false);
+
+            if (mPausingActivity == null) {
+                if (DEBUG_PAUSE) Slog.v(TAG, "Finish needs to pause: " + r);
+                if (DEBUG_USER_LEAVING) Slog.v(TAG, "finish() => pause with userLeaving=false");
+                startPausingLocked(false, false);
+            }
+
+        } else if (r.state != ActivityState.PAUSING) {
+            // If the activity is PAUSING, we will complete the finish once
+            // it is done pausing; else we can just directly finish it here.
+            if (DEBUG_PAUSE) Slog.v(TAG, "Finish not pausing: " + r);
+            return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null;
+        } else {
+            if (DEBUG_PAUSE) Slog.v(TAG, "Finish waiting for pause of: " + r);
+        }
+
+        return false;
+    }
+
+    static final int FINISH_IMMEDIATELY = 0;
+    static final int FINISH_AFTER_PAUSE = 1;
+    static final int FINISH_AFTER_VISIBLE = 2;
+
+    final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) {
+        // First things first: if this activity is currently visible,
+        // and the resumed activity is not yet visible, then hold off on
+        // finishing until the resumed one becomes visible.
+        if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) {
+            if (!mStackSupervisor.mStoppingActivities.contains(r)) {
+                mStackSupervisor.mStoppingActivities.add(r);
+                if (mStackSupervisor.mStoppingActivities.size() > 3
+                        || r.frontOfTask && mTaskHistory.size() <= 1) {
+                    // If we already have a few activities waiting to stop,
+                    // then give up on things going idle and start clearing
+                    // them out. Or if r is the last of activity of the last task the stack
+                    // will be empty and must be cleared immediately.
+                    mStackSupervisor.scheduleIdleLocked();
+                } else {
+                    mStackSupervisor.checkReadyForSleepLocked();
+                }
+            }
+            if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r
+                    + " (finish requested)");
+            r.state = ActivityState.STOPPING;
+            if (oomAdj) {
+                mService.updateOomAdjLocked();
+            }
+            return r;
+        }
+
+        // make sure the record is cleaned out of other places.
+        mStackSupervisor.mStoppingActivities.remove(r);
+        mStackSupervisor.mGoingToSleepActivities.remove(r);
+        mStackSupervisor.mWaitingVisibleActivities.remove(r);
+        if (mResumedActivity == r) {
+            mResumedActivity = null;
+        }
+        final ActivityState prevState = r.state;
+        if (DEBUG_STATES) Slog.v(TAG, "Moving to FINISHING: " + r);
+        r.state = ActivityState.FINISHING;
+
+        if (mode == FINISH_IMMEDIATELY
+                || prevState == ActivityState.STOPPED
+                || prevState == ActivityState.INITIALIZING) {
+            // If this activity is already stopped, we can just finish
+            // it right now.
+            boolean activityRemoved = destroyActivityLocked(r, true,
+                    oomAdj, "finish-imm");
+            if (activityRemoved) {
+                mStackSupervisor.resumeTopActivitiesLocked();
+            }
+            return activityRemoved ? null : r;
+        }
+
+        // Need to go through the full pause cycle to get this
+        // activity into the stopped state and then finish it.
+        if (localLOGV) Slog.v(TAG, "Enqueueing pending finish: " + r);
+        mStackSupervisor.mFinishingActivities.add(r);
+        r.resumeKeyDispatchingLocked();
+        mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
+        return r;
+    }
+
+    final boolean navigateUpToLocked(IBinder token, Intent destIntent, int resultCode,
+            Intent resultData) {
+        final ActivityRecord srec = ActivityRecord.forToken(token);
+        final TaskRecord task = srec.task;
+        final ArrayList<ActivityRecord> activities = task.mActivities;
+        final int start = activities.indexOf(srec);
+        if (!mTaskHistory.contains(task) || (start < 0)) {
+            return false;
+        }
+        int finishTo = start - 1;
+        ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo);
+        boolean foundParentInTask = false;
+        final ComponentName dest = destIntent.getComponent();
+        if (start > 0 && dest != null) {
+            for (int i = finishTo; i >= 0; i--) {
+                ActivityRecord r = activities.get(i);
+                if (r.info.packageName.equals(dest.getPackageName()) &&
+                        r.info.name.equals(dest.getClassName())) {
+                    finishTo = i;
+                    parent = r;
+                    foundParentInTask = true;
+                    break;
+                }
+            }
+        }
+
+        IActivityController controller = mService.mController;
+        if (controller != null) {
+            ActivityRecord next = topRunningActivityLocked(srec.appToken, 0);
+            if (next != null) {
+                // ask watcher if this is allowed
+                boolean resumeOK = true;
+                try {
+                    resumeOK = controller.activityResuming(next.packageName);
+                } catch (RemoteException e) {
+                    mService.mController = null;
+                    Watchdog.getInstance().setActivityController(null);
+                }
+
+                if (!resumeOK) {
+                    return false;
+                }
+            }
+        }
+        final long origId = Binder.clearCallingIdentity();
+        for (int i = start; i > finishTo; i--) {
+            ActivityRecord r = activities.get(i);
+            requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true);
+            // Only return the supplied result for the first activity finished
+            resultCode = Activity.RESULT_CANCELED;
+            resultData = null;
+        }
+
+        if (parent != null && foundParentInTask) {
+            final int parentLaunchMode = parent.info.launchMode;
+            final int destIntentFlags = destIntent.getFlags();
+            if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE ||
+                    parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK ||
+                    parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP ||
+                    (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
+                parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent);
+            } else {
+                try {
+                    ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo(
+                            destIntent.getComponent(), 0, srec.userId);
+                    int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent,
+                            null, aInfo, parent.appToken, null,
+                            0, -1, parent.launchedFromUid, parent.launchedFromPackage,
+                            0, null, true, null, null);
+                    foundParentInTask = res == ActivityManager.START_SUCCESS;
+                } catch (RemoteException e) {
+                    foundParentInTask = false;
+                }
+                requestFinishActivityLocked(parent.appToken, resultCode,
+                        resultData, "navigate-up", true);
+            }
+        }
+        Binder.restoreCallingIdentity(origId);
+        return foundParentInTask;
+    }
+    /**
+     * Perform the common clean-up of an activity record.  This is called both
+     * as part of destroyActivityLocked() (when destroying the client-side
+     * representation) and cleaning things up as a result of its hosting
+     * processing going away, in which case there is no remaining client-side
+     * state to destroy so only the cleanup here is needed.
+     */
+    final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
+            boolean setState) {
+        if (mResumedActivity == r) {
+            mResumedActivity = null;
+        }
+        if (mService.mFocusedActivity == r) {
+            mService.mFocusedActivity = null;
+        }
+
+        r.configDestroy = false;
+        r.frozenBeforeDestroy = false;
+
+        if (setState) {
+            if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (cleaning up)");
+            r.state = ActivityState.DESTROYED;
+            if (DEBUG_APP) Slog.v(TAG, "Clearing app during cleanUp for activity " + r);
+            r.app = null;
+        }
+
+        // Make sure this record is no longer in the pending finishes list.
+        // This could happen, for example, if we are trimming activities
+        // down to the max limit while they are still waiting to finish.
+        mStackSupervisor.mFinishingActivities.remove(r);
+        mStackSupervisor.mWaitingVisibleActivities.remove(r);
+
+        // Remove any pending results.
+        if (r.finishing && r.pendingResults != null) {
+            for (WeakReference<PendingIntentRecord> apr : r.pendingResults) {
+                PendingIntentRecord rec = apr.get();
+                if (rec != null) {
+                    mService.cancelIntentSenderLocked(rec, false);
+                }
+            }
+            r.pendingResults = null;
+        }
+
+        if (cleanServices) {
+            cleanUpActivityServicesLocked(r);
+        }
+
+        if (!mService.mPendingThumbnails.isEmpty()) {
+            // There are clients waiting to receive thumbnails so, in case
+            // this is an activity that someone is waiting for, add it
+            // to the pending list so we can correctly update the clients.
+            mStackSupervisor.mCancelledThumbnails.add(r);
+        }
+
+        // Get rid of any pending idle timeouts.
+        removeTimeoutsForActivityLocked(r);
+    }
+
+    private void removeTimeoutsForActivityLocked(ActivityRecord r) {
+        mStackSupervisor.removeTimeoutsForActivityLocked(r);
+        mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
+        mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
+        mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
+        r.finishLaunchTickingLocked();
+    }
+
+    private void removeActivityFromHistoryLocked(ActivityRecord r) {
+        mStackSupervisor.removeChildActivityContainers(r);
+        finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null);
+        r.makeFinishing();
+        if (DEBUG_ADD_REMOVE) {
+            RuntimeException here = new RuntimeException("here");
+            here.fillInStackTrace();
+            Slog.i(TAG, "Removing activity " + r + " from stack");
+        }
+        r.takeFromHistory();
+        removeTimeoutsForActivityLocked(r);
+        if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (removed from history)");
+        r.state = ActivityState.DESTROYED;
+        if (DEBUG_APP) Slog.v(TAG, "Clearing app during remove for activity " + r);
+        r.app = null;
+        mWindowManager.removeAppToken(r.appToken);
+        if (VALIDATE_TOKENS) {
+            validateAppTokensLocked();
+        }
+        final TaskRecord task = r.task;
+        if (task != null && task.removeActivity(r)) {
+            if (DEBUG_STACK) Slog.i(TAG,
+                    "removeActivityFromHistoryLocked: last activity removed from " + this);
+            if (mStackSupervisor.isFrontStack(this) && task == topTask() && task.mOnTopOfHome) {
+                mStackSupervisor.moveHomeToTop();
+            }
+            removeTask(task);
+        }
+        cleanUpActivityServicesLocked(r);
+        r.removeUriPermissionsLocked();
+    }
+
+    /**
+     * Perform clean-up of service connections in an activity record.
+     */
+    final void cleanUpActivityServicesLocked(ActivityRecord r) {
+        // Throw away any services that have been bound by this activity.
+        if (r.connections != null) {
+            Iterator<ConnectionRecord> it = r.connections.iterator();
+            while (it.hasNext()) {
+                ConnectionRecord c = it.next();
+                mService.mServices.removeConnectionLocked(c, null, r);
+            }
+            r.connections = null;
+        }
+    }
+
+    final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String reason) {
+        Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG);
+        msg.obj = new ScheduleDestroyArgs(owner, oomAdj, reason);
+        mHandler.sendMessage(msg);
+    }
+
+    final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) {
+        boolean lastIsOpaque = false;
+        boolean activityRemoved = false;
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.finishing) {
+                    continue;
+                }
+                if (r.fullscreen) {
+                    lastIsOpaque = true;
+                }
+                if (owner != null && r.app != owner) {
+                    continue;
+                }
+                if (!lastIsOpaque) {
+                    continue;
+                }
+                // We can destroy this one if we have its icicle saved and
+                // it is not in the process of pausing/stopping/finishing.
+                if (r.app != null && r != mResumedActivity && r != mPausingActivity
+                        && r.haveState && !r.visible && r.stopped
+                        && r.state != ActivityState.DESTROYING
+                        && r.state != ActivityState.DESTROYED) {
+                    if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state
+                            + " resumed=" + mResumedActivity
+                            + " pausing=" + mPausingActivity);
+                    if (destroyActivityLocked(r, true, oomAdj, reason)) {
+                        activityRemoved = true;
+                    }
+                }
+            }
+        }
+        if (activityRemoved) {
+            mStackSupervisor.resumeTopActivitiesLocked();
+
+        }
+    }
+
+    /**
+     * Destroy the current CLIENT SIDE instance of an activity.  This may be
+     * called both when actually finishing an activity, or when performing
+     * a configuration switch where we destroy the current client-side object
+     * but then create a new client-side object for this same HistoryRecord.
+     */
+    final boolean destroyActivityLocked(ActivityRecord r,
+            boolean removeFromApp, boolean oomAdj, String reason) {
+        if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(
+            TAG, "Removing activity from " + reason + ": token=" + r
+              + ", app=" + (r.app != null ? r.app.processName : "(null)"));
+        EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY,
+                r.userId, System.identityHashCode(r),
+                r.task.taskId, r.shortComponentName, reason);
+
+        boolean removedFromHistory = false;
+
+        cleanUpActivityLocked(r, false, false);
+
+        final boolean hadApp = r.app != null;
+
+        if (hadApp) {
+            if (removeFromApp) {
+                r.app.activities.remove(r);
+                if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) {
+                    mService.mHeavyWeightProcess = null;
+                    mService.mHandler.sendEmptyMessage(
+                            ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG);
+                }
+                if (r.app.activities.isEmpty()) {
+                    // No longer have activities, so update LRU list and oom adj.
+                    mService.updateLruProcessLocked(r.app, false, null);
+                    mService.updateOomAdjLocked();
+                }
+            }
+
+            boolean skipDestroy = false;
+
+            try {
+                if (DEBUG_SWITCH) Slog.i(TAG, "Destroying: " + r);
+                r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing,
+                        r.configChangeFlags);
+            } catch (Exception e) {
+                // We can just ignore exceptions here...  if the process
+                // has crashed, our death notification will clean things
+                // up.
+                //Slog.w(TAG, "Exception thrown during finish", e);
+                if (r.finishing) {
+                    removeActivityFromHistoryLocked(r);
+                    removedFromHistory = true;
+                    skipDestroy = true;
+                }
+            }
+
+            r.nowVisible = false;
+
+            // If the activity is finishing, we need to wait on removing it
+            // from the list to give it a chance to do its cleanup.  During
+            // that time it may make calls back with its token so we need to
+            // be able to find it on the list and so we don't want to remove
+            // it from the list yet.  Otherwise, we can just immediately put
+            // it in the destroyed state since we are not removing it from the
+            // list.
+            if (r.finishing && !skipDestroy) {
+                if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYING: " + r
+                        + " (destroy requested)");
+                r.state = ActivityState.DESTROYING;
+                Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r);
+                mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT);
+            } else {
+                if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (destroy skipped)");
+                r.state = ActivityState.DESTROYED;
+                if (DEBUG_APP) Slog.v(TAG, "Clearing app during destroy for activity " + r);
+                r.app = null;
+            }
+        } else {
+            // remove this record from the history.
+            if (r.finishing) {
+                removeActivityFromHistoryLocked(r);
+                removedFromHistory = true;
+            } else {
+                if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (no app)");
+                r.state = ActivityState.DESTROYED;
+                if (DEBUG_APP) Slog.v(TAG, "Clearing app during destroy for activity " + r);
+                r.app = null;
+            }
+        }
+
+        r.configChangeFlags = 0;
+
+        if (!mLRUActivities.remove(r) && hadApp) {
+            Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list");
+        }
+
+        return removedFromHistory;
+    }
+
+    final void activityDestroyedLocked(IBinder token) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            ActivityRecord r = ActivityRecord.forToken(token);
+            if (r != null) {
+                mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
+            }
+
+            if (isInStackLocked(token) != null) {
+                if (r.state == ActivityState.DESTROYING) {
+                    cleanUpActivityLocked(r, true, false);
+                    removeActivityFromHistoryLocked(r);
+                }
+            }
+            mStackSupervisor.resumeTopActivitiesLocked();
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list,
+            ProcessRecord app, String listName) {
+        int i = list.size();
+        if (DEBUG_CLEANUP) Slog.v(
+            TAG, "Removing app " + app + " from list " + listName
+            + " with " + i + " entries");
+        while (i > 0) {
+            i--;
+            ActivityRecord r = list.get(i);
+            if (DEBUG_CLEANUP) Slog.v(TAG, "Record #" + i + " " + r);
+            if (r.app == app) {
+                if (DEBUG_CLEANUP) Slog.v(TAG, "---> REMOVING this entry!");
+                list.remove(i);
+                removeTimeoutsForActivityLocked(r);
+            }
+        }
+    }
+
+    boolean removeHistoryRecordsForAppLocked(ProcessRecord app) {
+        removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities");
+        removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app,
+                "mStoppingActivities");
+        removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app,
+                "mGoingToSleepActivities");
+        removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app,
+                "mWaitingVisibleActivities");
+        removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app,
+                "mFinishingActivities");
+
+        boolean hasVisibleActivities = false;
+
+        // Clean out the history list.
+        int i = numActivities();
+        if (DEBUG_CLEANUP) Slog.v(
+            TAG, "Removing app " + app + " from history with " + i + " entries");
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                --i;
+                if (DEBUG_CLEANUP) Slog.v(
+                    TAG, "Record #" + i + " " + r + ": app=" + r.app);
+                if (r.app == app) {
+                    boolean remove;
+                    if ((!r.haveState && !r.stateNotNeeded) || r.finishing) {
+                        // Don't currently have state for the activity, or
+                        // it is finishing -- always remove it.
+                        remove = true;
+                    } else if (r.launchCount > 2 &&
+                            r.lastLaunchTime > (SystemClock.uptimeMillis()-60000)) {
+                        // We have launched this activity too many times since it was
+                        // able to run, so give up and remove it.
+                        remove = true;
+                    } else {
+                        // The process may be gone, but the activity lives on!
+                        remove = false;
+                    }
+                    if (remove) {
+                        if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) {
+                            RuntimeException here = new RuntimeException("here");
+                            here.fillInStackTrace();
+                            Slog.i(TAG, "Removing activity " + r + " from stack at " + i
+                                    + ": haveState=" + r.haveState
+                                    + " stateNotNeeded=" + r.stateNotNeeded
+                                    + " finishing=" + r.finishing
+                                    + " state=" + r.state, here);
+                        }
+                        if (!r.finishing) {
+                            Slog.w(TAG, "Force removing " + r + ": app died, no saved state");
+                            EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,
+                                    r.userId, System.identityHashCode(r),
+                                    r.task.taskId, r.shortComponentName,
+                                    "proc died without state saved");
+                            if (r.state == ActivityState.RESUMED) {
+                                mService.updateUsageStats(r, false);
+                            }
+                        }
+                        removeActivityFromHistoryLocked(r);
+
+                    } else {
+                        // We have the current state for this activity, so
+                        // it can be restarted later when needed.
+                        if (localLOGV) Slog.v(
+                            TAG, "Keeping entry, setting app to null");
+                        if (r.visible) {
+                            hasVisibleActivities = true;
+                        }
+                        if (DEBUG_APP) Slog.v(TAG, "Clearing app during removeHistory for activity "
+                                + r);
+                        r.app = null;
+                        r.nowVisible = false;
+                        if (!r.haveState) {
+                            if (DEBUG_SAVED_STATE) Slog.i(TAG,
+                                    "App died, clearing saved state of " + r);
+                            r.icicle = null;
+                        }
+                    }
+
+                    cleanUpActivityLocked(r, true, true);
+                }
+            }
+        }
+
+        return hasVisibleActivities;
+    }
+
+    final void updateTransitLocked(int transit, Bundle options) {
+        if (options != null) {
+            ActivityRecord r = topRunningActivityLocked(null);
+            if (r != null && r.state != ActivityState.RESUMED) {
+                r.updateOptionsLocked(options);
+            } else {
+                ActivityOptions.abort(options);
+            }
+        }
+        mWindowManager.prepareAppTransition(transit, false);
+    }
+
+    void moveHomeTaskToTop() {
+        final int top = mTaskHistory.size() - 1;
+        for (int taskNdx = top; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            if (task.isHomeTask()) {
+                if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG, "moveHomeTaskToTop: moving " + task);
+                mTaskHistory.remove(taskNdx);
+                mTaskHistory.add(top, task);
+                mWindowManager.moveTaskToTop(task.taskId);
+                return;
+            }
+        }
+    }
+
+    final boolean findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) {
+        final TaskRecord task = taskForIdLocked(taskId);
+        if (task != null) {
+            if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) {
+                mStackSupervisor.mUserLeaving = true;
+            }
+            if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) {
+                // Caller wants the home activity moved with it.  To accomplish this,
+                // we'll just indicate that this task returns to the home task.
+                task.mOnTopOfHome = true;
+            }
+            moveTaskToFrontLocked(task, null, options);
+            return true;
+        }
+        return false;
+    }
+
+    final void moveTaskToFrontLocked(TaskRecord tr, ActivityRecord reason, Bundle options) {
+        if (DEBUG_SWITCH) Slog.v(TAG, "moveTaskToFront: " + tr);
+
+        final int numTasks = mTaskHistory.size();
+        final int index = mTaskHistory.indexOf(tr);
+        if (numTasks == 0 || index < 0)  {
+            // nothing to do!
+            if (reason != null &&
+                    (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
+                ActivityOptions.abort(options);
+            } else {
+                updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options);
+            }
+            return;
+        }
+
+        moveToFront();
+
+        // Shift all activities with this task up to the top
+        // of the stack, keeping them in the same internal order.
+        insertTaskAtTop(tr);
+
+        if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to front transition: task=" + tr);
+        if (reason != null &&
+                (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
+            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
+            ActivityRecord r = topRunningActivityLocked(null);
+            if (r != null) {
+                mNoAnimActivities.add(r);
+            }
+            ActivityOptions.abort(options);
+        } else {
+            updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options);
+        }
+
+        mWindowManager.moveTaskToTop(tr.taskId);
+
+        mStackSupervisor.resumeTopActivitiesLocked();
+        EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId);
+
+        if (VALIDATE_TOKENS) {
+            validateAppTokensLocked();
+        }
+    }
+
+    /**
+     * Worker method for rearranging history stack. Implements the function of moving all
+     * activities for a specific task (gathering them if disjoint) into a single group at the
+     * bottom of the stack.
+     *
+     * If a watcher is installed, the action is preflighted and the watcher has an opportunity
+     * to premeptively cancel the move.
+     *
+     * @param taskId The taskId to collect and move to the bottom.
+     * @return Returns true if the move completed, false if not.
+     */
+    final boolean moveTaskToBackLocked(int taskId, ActivityRecord reason) {
+        Slog.i(TAG, "moveTaskToBack: " + taskId);
+
+        // If we have a watcher, preflight the move before committing to it.  First check
+        // for *other* available tasks, but if none are available, then try again allowing the
+        // current task to be selected.
+        if (mStackSupervisor.isFrontStack(this) && mService.mController != null) {
+            ActivityRecord next = topRunningActivityLocked(null, taskId);
+            if (next == null) {
+                next = topRunningActivityLocked(null, 0);
+            }
+            if (next != null) {
+                // ask watcher if this is allowed
+                boolean moveOK = true;
+                try {
+                    moveOK = mService.mController.activityResuming(next.packageName);
+                } catch (RemoteException e) {
+                    mService.mController = null;
+                    Watchdog.getInstance().setActivityController(null);
+                }
+                if (!moveOK) {
+                    return false;
+                }
+            }
+        }
+
+        if (DEBUG_TRANSITION) Slog.v(TAG,
+                "Prepare to back transition: task=" + taskId);
+
+        final TaskRecord tr = taskForIdLocked(taskId);
+        if (tr == null) {
+            return false;
+        }
+
+        mTaskHistory.remove(tr);
+        mTaskHistory.add(0, tr);
+
+        // There is an assumption that moving a task to the back moves it behind the home activity.
+        // We make sure here that some activity in the stack will launch home.
+        ActivityRecord lastActivity = null;
+        int numTasks = mTaskHistory.size();
+        for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            if (task.mOnTopOfHome) {
+                break;
+            }
+            if (taskNdx == 1) {
+                // Set the last task before tr to go to home.
+                task.mOnTopOfHome = true;
+            }
+        }
+
+        if (reason != null &&
+                (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
+            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
+            ActivityRecord r = topRunningActivityLocked(null);
+            if (r != null) {
+                mNoAnimActivities.add(r);
+            }
+        } else {
+            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false);
+        }
+        mWindowManager.moveTaskToBottom(taskId);
+
+        if (VALIDATE_TOKENS) {
+            validateAppTokensLocked();
+        }
+
+        final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null;
+        if (task == tr && tr.mOnTopOfHome || numTasks <= 1 && isOnHomeDisplay()) {
+            tr.mOnTopOfHome = false;
+            return mStackSupervisor.resumeHomeActivity(null);
+        }
+
+        mStackSupervisor.resumeTopActivitiesLocked();
+        return true;
+    }
+
+    static final void logStartActivity(int tag, ActivityRecord r,
+            TaskRecord task) {
+        final Uri data = r.intent.getData();
+        final String strData = data != null ? data.toSafeString() : null;
+
+        EventLog.writeEvent(tag,
+                r.userId, System.identityHashCode(r), task.taskId,
+                r.shortComponentName, r.intent.getAction(),
+                r.intent.getType(), strData, r.intent.getFlags());
+    }
+
+    /**
+     * Make sure the given activity matches the current configuration.  Returns
+     * false if the activity had to be destroyed.  Returns true if the
+     * configuration is the same, or the activity will remain running as-is
+     * for whatever reason.  Ensures the HistoryRecord is updated with the
+     * correct configuration and all other bookkeeping is handled.
+     */
+    final boolean ensureActivityConfigurationLocked(ActivityRecord r,
+            int globalChanges) {
+        if (mConfigWillChange) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Skipping config check (will change): " + r);
+            return true;
+        }
+
+        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                "Ensuring correct configuration: " + r);
+
+        // Short circuit: if the two configurations are the exact same
+        // object (the common case), then there is nothing to do.
+        Configuration newConfig = mService.mConfiguration;
+        if (r.configuration == newConfig && !r.forceNewConfig) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Configuration unchanged in " + r);
+            return true;
+        }
+
+        // We don't worry about activities that are finishing.
+        if (r.finishing) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Configuration doesn't matter in finishing " + r);
+            r.stopFreezingScreenLocked(false);
+            return true;
+        }
+
+        // Okay we now are going to make this activity have the new config.
+        // But then we need to figure out how it needs to deal with that.
+        Configuration oldConfig = r.configuration;
+        r.configuration = newConfig;
+
+        // Determine what has changed.  May be nothing, if this is a config
+        // that has come back from the app after going idle.  In that case
+        // we just want to leave the official config object now in the
+        // activity and do nothing else.
+        final int changes = oldConfig.diff(newConfig);
+        if (changes == 0 && !r.forceNewConfig) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Configuration no differences in " + r);
+            return true;
+        }
+
+        // If the activity isn't currently running, just leave the new
+        // configuration and it will pick that up next time it starts.
+        if (r.app == null || r.app.thread == null) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Configuration doesn't matter not running " + r);
+            r.stopFreezingScreenLocked(false);
+            r.forceNewConfig = false;
+            return true;
+        }
+
+        // Figure out how to handle the changes between the configurations.
+        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
+            Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x"
+                    + Integer.toHexString(changes) + ", handles=0x"
+                    + Integer.toHexString(r.info.getRealConfigChanged())
+                    + ", newConfig=" + newConfig);
+        }
+        if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) {
+            // Aha, the activity isn't handling the change, so DIE DIE DIE.
+            r.configChangeFlags |= changes;
+            r.startFreezingScreenLocked(r.app, globalChanges);
+            r.forceNewConfig = false;
+            if (r.app == null || r.app.thread == null) {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Config is destroying non-running " + r);
+                destroyActivityLocked(r, true, false, "config");
+            } else if (r.state == ActivityState.PAUSING) {
+                // A little annoying: we are waiting for this activity to
+                // finish pausing.  Let's not do anything now, but just
+                // flag that it needs to be restarted when done pausing.
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Config is skipping already pausing " + r);
+                r.configDestroy = true;
+                return true;
+            } else if (r.state == ActivityState.RESUMED) {
+                // Try to optimize this case: the configuration is changing
+                // and we need to restart the top, resumed activity.
+                // Instead of doing the normal handshaking, just say
+                // "restart!".
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Config is relaunching resumed " + r);
+                relaunchActivityLocked(r, r.configChangeFlags, true);
+                r.configChangeFlags = 0;
+            } else {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Config is relaunching non-resumed " + r);
+                relaunchActivityLocked(r, r.configChangeFlags, false);
+                r.configChangeFlags = 0;
+            }
+
+            // All done...  tell the caller we weren't able to keep this
+            // activity around.
+            return false;
+        }
+
+        // Default case: the activity can handle this new configuration, so
+        // hand it over.  Note that we don't need to give it the new
+        // configuration, since we always send configuration changes to all
+        // process when they happen so it can just use whatever configuration
+        // it last got.
+        if (r.app != null && r.app.thread != null) {
+            try {
+                if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + r);
+                r.app.thread.scheduleActivityConfigurationChanged(r.appToken);
+            } catch (RemoteException e) {
+                // If process died, whatever.
+            }
+        }
+        r.stopFreezingScreenLocked(false);
+
+        return true;
+    }
+
+    private boolean relaunchActivityLocked(ActivityRecord r,
+            int changes, boolean andResume) {
+        List<ResultInfo> results = null;
+        List<Intent> newIntents = null;
+        if (andResume) {
+            results = r.results;
+            newIntents = r.newIntents;
+        }
+        if (DEBUG_SWITCH) Slog.v(TAG, "Relaunching: " + r
+                + " with results=" + results + " newIntents=" + newIntents
+                + " andResume=" + andResume);
+        EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
+                : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r),
+                r.task.taskId, r.shortComponentName);
+
+        r.startFreezingScreenLocked(r.app, 0);
+
+        mStackSupervisor.removeChildActivityContainers(r);
+
+        try {
+            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG,
+                    (andResume ? "Relaunching to RESUMED " : "Relaunching to PAUSED ")
+                    + r);
+            r.forceNewConfig = false;
+            r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents,
+                    changes, !andResume, new Configuration(mService.mConfiguration));
+            // 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.
+        } catch (RemoteException e) {
+            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, "Relaunch failed", e);
+        }
+
+        if (andResume) {
+            r.results = null;
+            r.newIntents = null;
+            r.state = ActivityState.RESUMED;
+        } else {
+            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
+            r.state = ActivityState.PAUSED;
+        }
+
+        return true;
+    }
+
+    boolean willActivityBeVisibleLocked(IBinder token) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.appToken == token) {
+                    return true;
+                }
+                if (r.fullscreen && !r.finishing) {
+                    return false;
+                }
+            }
+        }
+        final ActivityRecord r = ActivityRecord.forToken(token);
+        if (r == null) {
+            return false;
+        }
+        if (r.finishing) Slog.e(TAG, "willActivityBeVisibleLocked: Returning false,"
+                + " would have returned true for r=" + r);
+        return !r.finishing;
+    }
+
+    void closeSystemDialogsLocked() {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) {
+                    finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true);
+                }
+            }
+        }
+    }
+
+    boolean forceStopPackageLocked(String name, boolean doit, boolean evenPersistent, int userId) {
+        boolean didSomething = false;
+        TaskRecord lastTask = null;
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            int numActivities = activities.size();
+            for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
+                ActivityRecord r = activities.get(activityNdx);
+                final boolean samePackage = r.packageName.equals(name)
+                        || (name == null && r.userId == userId);
+                if ((userId == UserHandle.USER_ALL || r.userId == userId)
+                        && (samePackage || r.task == lastTask)
+                        && (r.app == null || evenPersistent || !r.app.persistent)) {
+                    if (!doit) {
+                        if (r.finishing) {
+                            // If this activity is just finishing, then it is not
+                            // interesting as far as something to stop.
+                            continue;
+                        }
+                        return true;
+                    }
+                    didSomething = true;
+                    Slog.i(TAG, "  Force finishing activity " + r);
+                    if (samePackage) {
+                        if (r.app != null) {
+                            r.app.removed = true;
+                        }
+                        r.app = null;
+                    }
+                    lastTask = r.task;
+                    if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop",
+                            true)) {
+                        // r has been deleted from mActivities, accommodate.
+                        --numActivities;
+                        --activityNdx;
+                    }
+                }
+            }
+        }
+        return didSomething;
+    }
+
+    ActivityRecord getTasksLocked(IThumbnailReceiver receiver,
+            PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
+        ActivityRecord topRecord = null;
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            ActivityRecord r = null;
+            ActivityRecord top = null;
+            int numActivities = 0;
+            int numRunning = 0;
+            final ArrayList<ActivityRecord> activities = task.mActivities;
+            if (activities.isEmpty()) {
+                continue;
+            }
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                r = activities.get(activityNdx);
+
+                // Initialize state for next task if needed.
+                if (top == null || (top.state == ActivityState.INITIALIZING)) {
+                    top = r;
+                    numActivities = numRunning = 0;
+                }
+
+                // Add 'r' into the current task.
+                numActivities++;
+                if (r.app != null && r.app.thread != null) {
+                    numRunning++;
+                }
+
+                if (localLOGV) Slog.v(
+                    TAG, r.intent.getComponent().flattenToShortString()
+                    + ": task=" + r.task);
+            }
+
+            RunningTaskInfo ci = new RunningTaskInfo();
+            ci.id = task.taskId;
+            ci.baseActivity = r.intent.getComponent();
+            ci.topActivity = top.intent.getComponent();
+            ci.lastActiveTime = task.lastActiveTime;
+
+            if (top.thumbHolder != null) {
+                ci.description = top.thumbHolder.lastDescription;
+            }
+            ci.numActivities = numActivities;
+            ci.numRunning = numRunning;
+            //System.out.println(
+            //    "#" + maxNum + ": " + " descr=" + ci.description);
+            if (receiver != null) {
+                if (localLOGV) Slog.v(
+                    TAG, "State=" + top.state + "Idle=" + top.idle
+                    + " app=" + top.app
+                    + " thr=" + (top.app != null ? top.app.thread : null));
+                if (top.state == ActivityState.RESUMED || top.state == ActivityState.PAUSING) {
+                    if (top.idle && top.app != null && top.app.thread != null) {
+                        topRecord = top;
+                    } else {
+                        top.thumbnailNeeded = true;
+                    }
+                }
+                pending.pendingRecords.add(top);
+            }
+            list.add(ci);
+        }
+        return topRecord;
+    }
+
+    public void unhandledBackLocked() {
+        final int top = mTaskHistory.size() - 1;
+        if (DEBUG_SWITCH) Slog.d(
+            TAG, "Performing unhandledBack(): top activity at " + top);
+        if (top >= 0) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities;
+            int activityTop = activities.size() - 1;
+            if (activityTop > 0) {
+                finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null,
+                        "unhandled-back", true);
+            }
+        }
+    }
+
+    /**
+     * Reset local parameters because an app's activity died.
+     * @param app The app of the activity that died.
+     * @return result from removeHistoryRecordsForAppLocked.
+     */
+    boolean handleAppDiedLocked(ProcessRecord app) {
+        if (mPausingActivity != null && mPausingActivity.app == app) {
+            if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG,
+                    "App died while pausing: " + mPausingActivity);
+            mPausingActivity = null;
+        }
+        if (mLastPausedActivity != null && mLastPausedActivity.app == app) {
+            mLastPausedActivity = null;
+            mLastNoHistoryActivity = null;
+        }
+
+        return removeHistoryRecordsForAppLocked(app);
+    }
+
+    void handleAppCrashLocked(ProcessRecord app) {
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord r = activities.get(activityNdx);
+                if (r.app == app) {
+                    Slog.w(TAG, "  Force finishing activity "
+                            + r.intent.getComponent().flattenToShortString());
+                    finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false);
+                }
+            }
+        }
+    }
+
+    boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll,
+            boolean dumpClient, String dumpPackage, boolean needSep, String header) {
+        boolean printed = false;
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = mTaskHistory.get(taskNdx);
+            printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw,
+                    mTaskHistory.get(taskNdx).mActivities, "    ", "Hist", true, !dumpAll,
+                    dumpClient, dumpPackage, needSep, header,
+                    "    Task id #" + task.taskId);
+            if (printed) {
+                header = null;
+            }
+        }
+        return printed;
+    }
+
+    ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) {
+        ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
+
+        if ("all".equals(name)) {
+            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+                activities.addAll(mTaskHistory.get(taskNdx).mActivities);
+            }
+        } else if ("top".equals(name)) {
+            final int top = mTaskHistory.size() - 1;
+            if (top >= 0) {
+                final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities;
+                int listTop = list.size() - 1;
+                if (listTop >= 0) {
+                    activities.add(list.get(listTop));
+                }
+            }
+        } else {
+            ItemMatcher matcher = new ItemMatcher();
+            matcher.build(name);
+
+            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+                for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) {
+                    if (matcher.match(r1, r1.intent.getComponent())) {
+                        activities.add(r1);
+                    }
+                }
+            }
+        }
+
+        return activities;
+    }
+
+    ActivityRecord restartPackage(String packageName) {
+        ActivityRecord starting = topRunningActivityLocked(null);
+
+        // All activities that came from the package must be
+        // restarted as if there was a config change.
+        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ActivityRecord a = activities.get(activityNdx);
+                if (a.info.packageName.equals(packageName)) {
+                    a.forceNewConfig = true;
+                    if (starting != null && a == starting && a.visible) {
+                        a.startFreezingScreenLocked(starting.app,
+                                ActivityInfo.CONFIG_SCREEN_LAYOUT);
+                    }
+                }
+            }
+        }
+
+        return starting;
+    }
+
+    void removeTask(TaskRecord task) {
+        mWindowManager.removeTask(task.taskId);
+        final ActivityRecord r = mResumedActivity;
+        if (r != null && r.task == task) {
+            mResumedActivity = null;
+        }
+
+        final int taskNdx = mTaskHistory.indexOf(task);
+        final int topTaskNdx = mTaskHistory.size() - 1;
+        if (task.mOnTopOfHome && taskNdx < topTaskNdx) {
+            mTaskHistory.get(taskNdx + 1).mOnTopOfHome = true;
+        }
+        mTaskHistory.remove(task);
+
+        if (mTaskHistory.isEmpty()) {
+            if (DEBUG_STACK) Slog.i(TAG, "removeTask: moving to back stack=" + this);
+            if (isOnHomeDisplay()) {
+                mStackSupervisor.moveHomeStack(!isHomeStack());
+            }
+            if (mStacks != null) {
+                mStacks.remove(this);
+                mStacks.add(0, this);
+            }
+        }
+    }
+
+    TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, boolean toTop) {
+        TaskRecord task = new TaskRecord(taskId, info, intent);
+        addTask(task, toTop);
+        return task;
+    }
+
+    ArrayList<TaskRecord> getAllTasks() {
+        return new ArrayList<TaskRecord>(mTaskHistory);
+    }
+
+    void addTask(final TaskRecord task, final boolean toTop) {
+        task.stack = this;
+        if (toTop) {
+            insertTaskAtTop(task);
+        } else {
+            mTaskHistory.add(0, task);
+        }
+    }
+
+    public int getStackId() {
+        return mStackId;
+    }
+
+    @Override
+    public String toString() {
+        return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this))
+                + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}";
+    }
+}
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
new file mode 100644
index 0000000..bf93c5a
--- /dev/null
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -0,0 +1,3191 @@
+/*
+ * Copyright (C) 2013 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 static android.Manifest.permission.START_ANY_ACTIVITY;
+import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
+import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
+import static com.android.server.am.ActivityManagerService.localLOGV;
+import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION;
+import static com.android.server.am.ActivityManagerService.DEBUG_FOCUS;
+import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE;
+import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS;
+import static com.android.server.am.ActivityManagerService.DEBUG_STACK;
+import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH;
+import static com.android.server.am.ActivityManagerService.DEBUG_TASKS;
+import static com.android.server.am.ActivityManagerService.DEBUG_USER_LEAVING;
+import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG;
+import static com.android.server.am.ActivityManagerService.TAG;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityManager.StackInfo;
+import android.app.ActivityOptions;
+import android.app.AppGlobals;
+import android.app.IActivityContainer;
+import android.app.IActivityContainerCallback;
+import android.app.IActivityManager;
+import android.app.IApplicationThread;
+import android.app.IThumbnailReceiver;
+import android.app.PendingIntent;
+import android.app.ActivityManager.RunningTaskInfo;
+import android.app.IActivityManager.WaitResult;
+import android.app.ResultInfo;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.IIntentSender;
+import android.content.Intent;
+import android.content.IntentSender;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Configuration;
+import android.graphics.Point;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.DisplayManager.DisplayListener;
+import android.hardware.display.DisplayManagerGlobal;
+import android.hardware.display.VirtualDisplay;
+import android.hardware.input.InputManager;
+import android.hardware.input.InputManagerInternal;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.ParcelFileDescriptor;
+import android.os.PowerManager;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.util.EventLog;
+import android.util.Slog;
+import android.util.SparseArray;
+
+import android.util.SparseIntArray;
+import android.view.Display;
+import android.view.DisplayInfo;
+import android.view.InputEvent;
+import android.view.Surface;
+import com.android.internal.app.HeavyWeightSwitcherActivity;
+import com.android.internal.os.TransferPipe;
+import com.android.server.LocalServices;
+import com.android.server.am.ActivityManagerService.PendingActivityLaunch;
+import com.android.server.am.ActivityStack.ActivityState;
+import com.android.server.wm.WindowManagerService;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
+
+public final class ActivityStackSupervisor implements DisplayListener {
+    static final boolean DEBUG = ActivityManagerService.DEBUG || false;
+    static final boolean DEBUG_ADD_REMOVE = DEBUG || false;
+    static final boolean DEBUG_APP = DEBUG || false;
+    static final boolean DEBUG_SAVED_STATE = DEBUG || false;
+    static final boolean DEBUG_STATES = DEBUG || false;
+    static final boolean DEBUG_IDLE = DEBUG || false;
+
+    public static final int HOME_STACK_ID = 0;
+
+    /** How long we wait until giving up on the last activity telling us it is idle. */
+    static final int IDLE_TIMEOUT = 10*1000;
+
+    /** How long we can hold the sleep wake lock before giving up. */
+    static final int SLEEP_TIMEOUT = 5*1000;
+
+    // How long we can hold the launch wake lock before giving up.
+    static final int LAUNCH_TIMEOUT = 10*1000;
+
+    static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG;
+    static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1;
+    static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2;
+    static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3;
+    static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4;
+    static final int HANDLE_DISPLAY_ADDED = FIRST_SUPERVISOR_STACK_MSG + 5;
+    static final int HANDLE_DISPLAY_CHANGED = FIRST_SUPERVISOR_STACK_MSG + 6;
+    static final int HANDLE_DISPLAY_REMOVED = FIRST_SUPERVISOR_STACK_MSG + 7;
+
+    private final static String VIRTUAL_DISPLAY_BASE_NAME = "ActivityViewVirtualDisplay";
+
+    // For debugging to make sure the caller when acquiring/releasing our
+    // wake lock is the system process.
+    static final boolean VALIDATE_WAKE_LOCK_CALLER = false;
+
+    final ActivityManagerService mService;
+
+    final ActivityStackSupervisorHandler mHandler;
+
+    /** Short cut */
+    WindowManagerService mWindowManager;
+    DisplayManager mDisplayManager;
+
+    /** Dismiss the keyguard after the next activity is displayed? */
+    boolean mDismissKeyguardOnNextActivity = false;
+
+    /** Identifier counter for all ActivityStacks */
+    private int mLastStackId = HOME_STACK_ID;
+
+    /** Task identifier that activities are currently being started in.  Incremented each time a
+     * new task is created. */
+    private int mCurTaskId = 0;
+
+    /** The current user */
+    private int mCurrentUser;
+
+    /** The stack containing the launcher app. Assumed to always be attached to
+     * Display.DEFAULT_DISPLAY. */
+    private ActivityStack mHomeStack;
+
+    /** The stack currently receiving input or launching the next activity. */
+    private ActivityStack mFocusedStack;
+
+    /** If this is the same as mFocusedStack then the activity on the top of the focused stack has
+     * been resumed. If stacks are changing position this will hold the old stack until the new
+     * stack becomes resumed after which it will be set to mFocusedStack. */
+    private ActivityStack mLastFocusedStack;
+
+    /** List of activities that are waiting for a new activity to become visible before completing
+     * whatever operation they are supposed to do. */
+    final ArrayList<ActivityRecord> mWaitingVisibleActivities = new ArrayList<ActivityRecord>();
+
+    /** List of processes waiting to find out about the next visible activity. */
+    final ArrayList<IActivityManager.WaitResult> mWaitingActivityVisible =
+            new ArrayList<IActivityManager.WaitResult>();
+
+    /** List of processes waiting to find out about the next launched activity. */
+    final ArrayList<IActivityManager.WaitResult> mWaitingActivityLaunched =
+            new ArrayList<IActivityManager.WaitResult>();
+
+    /** List of activities that are ready to be stopped, but waiting for the next activity to
+     * settle down before doing so. */
+    final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<ActivityRecord>();
+
+    /** List of activities that are ready to be finished, but waiting for the previous activity to
+     * settle down before doing so.  It contains ActivityRecord objects. */
+    final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<ActivityRecord>();
+
+    /** List of activities that are in the process of going to sleep. */
+    final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<ActivityRecord>();
+
+    /** List of ActivityRecord objects that have been finished and must still report back to a
+     * pending thumbnail receiver. */
+    final ArrayList<ActivityRecord> mCancelledThumbnails = new ArrayList<ActivityRecord>();
+
+    /** Used on user changes */
+    final ArrayList<UserStartedState> mStartingUsers = new ArrayList<UserStartedState>();
+
+    /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity
+     * is being brought in front of us. */
+    boolean mUserLeaving = false;
+
+    /** Set when we have taken too long waiting to go to sleep. */
+    boolean mSleepTimeout = false;
+
+    /**
+     * We don't want to allow the device to go to sleep while in the process
+     * of launching an activity.  This is primarily to allow alarm intent
+     * receivers to launch an activity and get that to run before the device
+     * goes back to sleep.
+     */
+    final PowerManager.WakeLock mLaunchingActivity;
+
+    /**
+     * Set when the system is going to sleep, until we have
+     * successfully paused the current activity and released our wake lock.
+     * At that point the system is allowed to actually sleep.
+     */
+    final PowerManager.WakeLock mGoingToSleep;
+
+    /** Stack id of the front stack when user switched, indexed by userId. */
+    SparseIntArray mUserStackInFront = new SparseIntArray(2);
+
+    // TODO: Add listener for removal of references.
+    /** Mapping from (ActivityStack/TaskStack).mStackId to their current state */
+    SparseArray<WeakReference<ActivityContainer>> mActivityContainers =
+            new SparseArray<WeakReference<ActivityContainer>>();
+
+    /** Mapping from displayId to display current state */
+    private SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<ActivityDisplay>();
+
+    InputManagerInternal mInputManagerInternal;
+
+    public ActivityStackSupervisor(ActivityManagerService service) {
+        mService = service;
+        PowerManager pm = (PowerManager)mService.mContext.getSystemService(Context.POWER_SERVICE);
+        mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep");
+        mHandler = new ActivityStackSupervisorHandler(mService.mHandler.getLooper());
+        if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
+            throw new IllegalStateException("Calling must be system uid");
+        }
+        mLaunchingActivity =
+                pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch");
+        mLaunchingActivity.setReferenceCounted(false);
+    }
+
+    void setWindowManager(WindowManagerService wm) {
+        synchronized (mService) {
+            mWindowManager = wm;
+
+            mDisplayManager =
+                    (DisplayManager)mService.mContext.getSystemService(Context.DISPLAY_SERVICE);
+            mDisplayManager.registerDisplayListener(this, null);
+
+            Display[] displays = mDisplayManager.getDisplays();
+            for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) {
+                final int displayId = displays[displayNdx].getDisplayId();
+                ActivityDisplay activityDisplay = new ActivityDisplay(displayId);
+                mActivityDisplays.put(displayId, activityDisplay);
+            }
+
+            createStackOnDisplay(null, HOME_STACK_ID, Display.DEFAULT_DISPLAY);
+            mHomeStack = mFocusedStack = mLastFocusedStack = getStack(HOME_STACK_ID);
+
+            mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
+        }
+    }
+
+    void dismissKeyguard() {
+        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
+        if (mDismissKeyguardOnNextActivity) {
+            mDismissKeyguardOnNextActivity = false;
+            mWindowManager.dismissKeyguard();
+        }
+    }
+
+    ActivityStack getFocusedStack() {
+        return mFocusedStack;
+    }
+
+    ActivityStack getLastStack() {
+        return mLastFocusedStack;
+    }
+
+    // TODO: Split into two methods isFrontStack for any visible stack and isFrontmostStack for the
+    // top of all visible stacks.
+    boolean isFrontStack(ActivityStack stack) {
+        final ActivityRecord parent = stack.mActivityContainer.mParentActivity;
+        if (parent != null) {
+            stack = parent.task.stack;
+        }
+        ArrayList<ActivityStack> stacks = stack.mStacks;
+        if (stacks != null && !stacks.isEmpty()) {
+            return stack == stacks.get(stacks.size() - 1);
+        }
+        return false;
+    }
+
+    void moveHomeStack(boolean toFront) {
+        ArrayList<ActivityStack> stacks = mHomeStack.mStacks;
+        int topNdx = stacks.size() - 1;
+        if (topNdx <= 0) {
+            return;
+        }
+        ActivityStack topStack = stacks.get(topNdx);
+        final boolean homeInFront = topStack == mHomeStack;
+        if (homeInFront != toFront) {
+            mLastFocusedStack = topStack;
+            stacks.remove(mHomeStack);
+            stacks.add(toFront ? topNdx : 0, mHomeStack);
+            mFocusedStack = stacks.get(topNdx);
+            if (DEBUG_STACK) Slog.d(TAG, "moveHomeTask: topStack old=" + topStack + " new="
+                    + mFocusedStack);
+        }
+    }
+
+    void moveHomeToTop() {
+        moveHomeStack(true);
+        mHomeStack.moveHomeTaskToTop();
+    }
+
+    boolean resumeHomeActivity(ActivityRecord prev) {
+        moveHomeToTop();
+        if (prev != null) {
+            prev.task.mOnTopOfHome = false;
+        }
+        ActivityRecord r = mHomeStack.topRunningActivityLocked(null);
+        if (r != null && r.isHomeActivity()) {
+            mService.setFocusedActivityLocked(r);
+            return resumeTopActivitiesLocked(mHomeStack, prev, null);
+        }
+        return mService.startHomeActivityLocked(mCurrentUser);
+    }
+
+    void setDismissKeyguard(boolean dismiss) {
+        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen(" dismiss=" + dismiss);
+        mDismissKeyguardOnNextActivity = dismiss;
+    }
+
+    TaskRecord anyTaskForIdLocked(int id) {
+        int numDisplays = mActivityDisplays.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                ActivityStack stack = stacks.get(stackNdx);
+                TaskRecord task = stack.taskForIdLocked(id);
+                if (task != null) {
+                    return task;
+                }
+            }
+        }
+        return null;
+    }
+
+    ActivityRecord isInAnyStackLocked(IBinder token) {
+        int numDisplays = mActivityDisplays.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityRecord r = stacks.get(stackNdx).isInStackLocked(token);
+                if (r != null) {
+                    return r;
+                }
+            }
+        }
+        return null;
+    }
+
+    int getNextTaskId() {
+        do {
+            mCurTaskId++;
+            if (mCurTaskId <= 0) {
+                mCurTaskId = 1;
+            }
+        } while (anyTaskForIdLocked(mCurTaskId) != null);
+        return mCurTaskId;
+    }
+
+    ActivityRecord resumedAppLocked() {
+        ActivityStack stack = getFocusedStack();
+        if (stack == null) {
+            return null;
+        }
+        ActivityRecord resumedActivity = stack.mResumedActivity;
+        if (resumedActivity == null || resumedActivity.app == null) {
+            resumedActivity = stack.mPausingActivity;
+            if (resumedActivity == null || resumedActivity.app == null) {
+                resumedActivity = stack.topRunningActivityLocked(null);
+            }
+        }
+        return resumedActivity;
+    }
+
+    boolean attachApplicationLocked(ProcessRecord app) throws Exception {
+        final String processName = app.processName;
+        boolean didSomething = false;
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (!isFrontStack(stack)) {
+                    continue;
+                }
+                ActivityRecord hr = stack.topRunningActivityLocked(null);
+                if (hr != null) {
+                    if (hr.app == null && app.uid == hr.info.applicationInfo.uid
+                            && processName.equals(hr.processName)) {
+                        try {
+                            if (realStartActivityLocked(hr, app, true, true)) {
+                                didSomething = true;
+                            }
+                        } catch (Exception e) {
+                            Slog.w(TAG, "Exception in new application when starting activity "
+                                  + hr.intent.getComponent().flattenToShortString(), e);
+                            throw e;
+                        }
+                    }
+                }
+            }
+        }
+        if (!didSomething) {
+            ensureActivitiesVisibleLocked(null, 0);
+        }
+        return didSomething;
+    }
+
+    boolean allResumedActivitiesIdle() {
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (!isFrontStack(stack) || stack.numActivities() == 0) {
+                    continue;
+                }
+                final ActivityRecord resumedActivity = stack.mResumedActivity;
+                if (resumedActivity == null || !resumedActivity.idle) {
+                    if (DEBUG_STATES) Slog.d(TAG, "allResumedActivitiesIdle: stack="
+                             + stack.mStackId + " " + resumedActivity + " not idle");
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    boolean allResumedActivitiesComplete() {
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (isFrontStack(stack)) {
+                    final ActivityRecord r = stack.mResumedActivity;
+                    if (r != null && r.state != ActivityState.RESUMED) {
+                        return false;
+                    }
+                }
+            }
+        }
+        // TODO: Not sure if this should check if all Paused are complete too.
+        if (DEBUG_STACK) Slog.d(TAG,
+                "allResumedActivitiesComplete: mLastFocusedStack changing from=" +
+                mLastFocusedStack + " to=" + mFocusedStack);
+        mLastFocusedStack = mFocusedStack;
+        return true;
+    }
+
+    boolean allResumedActivitiesVisible() {
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                final ActivityRecord r = stack.mResumedActivity;
+                if (r != null && (!r.nowVisible || r.waitingVisible)) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Pause all activities in either all of the stacks or just the back stacks.
+     * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving().
+     * @return true if any activity was paused as a result of this call.
+     */
+    boolean pauseBackStacks(boolean userLeaving) {
+        boolean someActivityPaused = false;
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (!isFrontStack(stack) && stack.mResumedActivity != null) {
+                    if (DEBUG_STATES) Slog.d(TAG, "pauseBackStacks: stack=" + stack +
+                            " mResumedActivity=" + stack.mResumedActivity);
+                    stack.startPausingLocked(userLeaving, false);
+                    someActivityPaused = true;
+                }
+            }
+        }
+        return someActivityPaused;
+    }
+
+    boolean allPausedActivitiesComplete() {
+        boolean pausing = true;
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                final ActivityRecord r = stack.mPausingActivity;
+                if (r != null && r.state != ActivityState.PAUSED
+                        && r.state != ActivityState.STOPPED
+                        && r.state != ActivityState.STOPPING) {
+                    if (DEBUG_STATES) {
+                        Slog.d(TAG, "allPausedActivitiesComplete: r=" + r + " state=" + r.state);
+                        pausing = false;
+                    } else {
+                        return false;
+                    }
+                }
+            }
+        }
+        return pausing;
+    }
+
+    void pauseChildStacks(ActivityRecord parent, boolean userLeaving, boolean uiSleeping) {
+		// TODO: Put all stacks in supervisor and iterate through them instead.
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (stack.mResumedActivity != null &&
+                        stack.mActivityContainer.mParentActivity == parent) {
+                    stack.startPausingLocked(userLeaving, uiSleeping);
+                }
+            }
+        }
+    }
+
+    void reportActivityVisibleLocked(ActivityRecord r) {
+        for (int i = mWaitingActivityVisible.size()-1; i >= 0; i--) {
+            WaitResult w = mWaitingActivityVisible.get(i);
+            w.timeout = false;
+            if (r != null) {
+                w.who = new ComponentName(r.info.packageName, r.info.name);
+            }
+            w.totalTime = SystemClock.uptimeMillis() - w.thisTime;
+            w.thisTime = w.totalTime;
+        }
+        mService.notifyAll();
+        dismissKeyguard();
+    }
+
+    void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r,
+            long thisTime, long totalTime) {
+        for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) {
+            WaitResult w = mWaitingActivityLaunched.remove(i);
+            w.timeout = timeout;
+            if (r != null) {
+                w.who = new ComponentName(r.info.packageName, r.info.name);
+            }
+            w.thisTime = thisTime;
+            w.totalTime = totalTime;
+        }
+        mService.notifyAll();
+    }
+
+    ActivityRecord topRunningActivityLocked() {
+        final ActivityStack focusedStack = getFocusedStack();
+        ActivityRecord r = focusedStack.topRunningActivityLocked(null);
+        if (r != null) {
+            return r;
+        }
+
+        // Return to the home stack.
+        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)) {
+                r = stack.topRunningActivityLocked(null);
+                if (r != null) {
+                    return r;
+                }
+            }
+        }
+        return null;
+    }
+
+    ActivityRecord getTasksLocked(int maxNum, IThumbnailReceiver receiver,
+            PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
+        ActivityRecord r = null;
+
+        // Gather all of the running tasks for each stack into runningTaskLists.
+        ArrayList<ArrayList<RunningTaskInfo>> runningTaskLists =
+                new ArrayList<ArrayList<RunningTaskInfo>>();
+        final int numDisplays = mActivityDisplays.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                ArrayList<RunningTaskInfo> stackTaskList = new ArrayList<RunningTaskInfo>();
+                runningTaskLists.add(stackTaskList);
+                final ActivityRecord ar = stack.getTasksLocked(receiver, pending, stackTaskList);
+                if (r == null && isFrontStack(stack)) {
+                    r = ar;
+                }
+            }
+        }
+
+        // The lists are already sorted from most recent to oldest. Just pull the most recent off
+        // each list and add it to list. Stop when all lists are empty or maxNum reached.
+        while (maxNum > 0) {
+            long mostRecentActiveTime = Long.MIN_VALUE;
+            ArrayList<RunningTaskInfo> selectedStackList = null;
+            final int numTaskLists = runningTaskLists.size();
+            for (int stackNdx = 0; stackNdx < numTaskLists; ++stackNdx) {
+                ArrayList<RunningTaskInfo> stackTaskList = runningTaskLists.get(stackNdx);
+                if (!stackTaskList.isEmpty()) {
+                    final long lastActiveTime = stackTaskList.get(0).lastActiveTime;
+                    if (lastActiveTime > mostRecentActiveTime) {
+                        mostRecentActiveTime = lastActiveTime;
+                        selectedStackList = stackTaskList;
+                    }
+                }
+            }
+            if (selectedStackList != null) {
+                list.add(selectedStackList.remove(0));
+                --maxNum;
+            } else {
+                break;
+            }
+        }
+
+        return r;
+    }
+
+    ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags,
+            String profileFile, ParcelFileDescriptor profileFd, int userId) {
+        // Collect information about the target of the Intent.
+        ActivityInfo aInfo;
+        try {
+            ResolveInfo rInfo =
+                AppGlobals.getPackageManager().resolveIntent(
+                        intent, resolvedType,
+                        PackageManager.MATCH_DEFAULT_ONLY
+                                    | ActivityManagerService.STOCK_PM_FLAGS, userId);
+            aInfo = rInfo != null ? rInfo.activityInfo : null;
+        } catch (RemoteException e) {
+            aInfo = null;
+        }
+
+        if (aInfo != null) {
+            // Store the found target back into the intent, because now that
+            // we have it we never want to do this again.  For example, if the
+            // user navigates back to this point in the history, we should
+            // always restart the exact same activity.
+            intent.setComponent(new ComponentName(
+                    aInfo.applicationInfo.packageName, aInfo.name));
+
+            // Don't debug things in the system process
+            if ((startFlags&ActivityManager.START_FLAG_DEBUG) != 0) {
+                if (!aInfo.processName.equals("system")) {
+                    mService.setDebugApp(aInfo.processName, true, false);
+                }
+            }
+
+            if ((startFlags&ActivityManager.START_FLAG_OPENGL_TRACES) != 0) {
+                if (!aInfo.processName.equals("system")) {
+                    mService.setOpenGlTraceApp(aInfo.applicationInfo, aInfo.processName);
+                }
+            }
+
+            if (profileFile != null) {
+                if (!aInfo.processName.equals("system")) {
+                    mService.setProfileApp(aInfo.applicationInfo, aInfo.processName,
+                            profileFile, profileFd,
+                            (startFlags&ActivityManager.START_FLAG_AUTO_STOP_PROFILER) != 0);
+                }
+            }
+        }
+        return aInfo;
+    }
+
+    void startHomeActivity(Intent intent, ActivityInfo aInfo) {
+        moveHomeToTop();
+        startActivityLocked(null, intent, null, aInfo, null, null, 0, 0, 0, null, 0,
+                null, false, null, null);
+    }
+
+    final int startActivityMayWait(IApplicationThread caller, int callingUid,
+            String callingPackage, Intent intent, String resolvedType, IBinder resultTo,
+            String resultWho, int requestCode, int startFlags, String profileFile,
+            ParcelFileDescriptor profileFd, WaitResult outResult, Configuration config,
+            Bundle options, int userId, IActivityContainer iContainer) {
+        // Refuse possible leaked file descriptors
+        if (intent != null && intent.hasFileDescriptors()) {
+            throw new IllegalArgumentException("File descriptors passed in Intent");
+        }
+        boolean componentSpecified = intent.getComponent() != null;
+
+        // Don't modify the client's object!
+        intent = new Intent(intent);
+
+        // Collect information about the target of the Intent.
+        ActivityInfo aInfo = resolveActivity(intent, resolvedType, startFlags,
+                profileFile, profileFd, userId);
+
+        ActivityContainer container = (ActivityContainer)iContainer;
+        synchronized (mService) {
+            int callingPid;
+            if (callingUid >= 0) {
+                callingPid = -1;
+            } else if (caller == null) {
+                callingPid = Binder.getCallingPid();
+                callingUid = Binder.getCallingUid();
+            } else {
+                callingPid = callingUid = -1;
+            }
+
+            final ActivityStack stack;
+            if (container == null || container.mStack.isOnHomeDisplay()) {
+                stack = getFocusedStack();
+            } else {
+                stack = container.mStack;
+            }
+            stack.mConfigWillChange = config != null
+                    && mService.mConfiguration.diff(config) != 0;
+            if (DEBUG_CONFIGURATION) Slog.v(TAG,
+                    "Starting activity when config will change = " + stack.mConfigWillChange);
+
+            final long origId = Binder.clearCallingIdentity();
+
+            if (aInfo != null &&
+                    (aInfo.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
+                // This may be a heavy-weight process!  Check to see if we already
+                // have another, different heavy-weight process running.
+                if (aInfo.processName.equals(aInfo.applicationInfo.packageName)) {
+                    if (mService.mHeavyWeightProcess != null &&
+                            (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid ||
+                            !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) {
+                        int realCallingUid = callingUid;
+                        if (caller != null) {
+                            ProcessRecord callerApp = mService.getRecordForAppLocked(caller);
+                            if (callerApp != null) {
+                                realCallingUid = callerApp.info.uid;
+                            } else {
+                                Slog.w(TAG, "Unable to find app for caller " + caller
+                                      + " (pid=" + callingPid + ") when starting: "
+                                      + intent.toString());
+                                ActivityOptions.abort(options);
+                                return ActivityManager.START_PERMISSION_DENIED;
+                            }
+                        }
+
+                        IIntentSender target = mService.getIntentSenderLocked(
+                                ActivityManager.INTENT_SENDER_ACTIVITY, "android",
+                                realCallingUid, userId, null, null, 0, new Intent[] { intent },
+                                new String[] { resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT
+                                | PendingIntent.FLAG_ONE_SHOT, null);
+
+                        Intent newIntent = new Intent();
+                        if (requestCode >= 0) {
+                            // Caller is requesting a result.
+                            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_HAS_RESULT, true);
+                        }
+                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT,
+                                new IntentSender(target));
+                        if (mService.mHeavyWeightProcess.activities.size() > 0) {
+                            ActivityRecord hist = mService.mHeavyWeightProcess.activities.get(0);
+                            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_APP,
+                                    hist.packageName);
+                            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_TASK,
+                                    hist.task.taskId);
+                        }
+                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_NEW_APP,
+                                aInfo.packageName);
+                        newIntent.setFlags(intent.getFlags());
+                        newIntent.setClassName("android",
+                                HeavyWeightSwitcherActivity.class.getName());
+                        intent = newIntent;
+                        resolvedType = null;
+                        caller = null;
+                        callingUid = Binder.getCallingUid();
+                        callingPid = Binder.getCallingPid();
+                        componentSpecified = true;
+                        try {
+                            ResolveInfo rInfo =
+                                AppGlobals.getPackageManager().resolveIntent(
+                                        intent, null,
+                                        PackageManager.MATCH_DEFAULT_ONLY
+                                        | ActivityManagerService.STOCK_PM_FLAGS, userId);
+                            aInfo = rInfo != null ? rInfo.activityInfo : null;
+                            aInfo = mService.getActivityInfoForUser(aInfo, userId);
+                        } catch (RemoteException e) {
+                            aInfo = null;
+                        }
+                    }
+                }
+            }
+
+            int res = startActivityLocked(caller, intent, resolvedType, aInfo, resultTo, resultWho,
+                    requestCode, callingPid, callingUid, callingPackage, startFlags, options,
+                    componentSpecified, null, container);
+
+            if (stack.mConfigWillChange) {
+                // If the caller also wants to switch to a new configuration,
+                // do so now.  This allows a clean switch, as we are waiting
+                // for the current activity to pause (so we will not destroy
+                // it), and have not yet started the next activity.
+                mService.enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
+                        "updateConfiguration()");
+                stack.mConfigWillChange = false;
+                if (DEBUG_CONFIGURATION) Slog.v(TAG,
+                        "Updating to new configuration after starting activity.");
+                mService.updateConfigurationLocked(config, null, false, false);
+            }
+
+            Binder.restoreCallingIdentity(origId);
+
+            if (outResult != null) {
+                outResult.result = res;
+                if (res == ActivityManager.START_SUCCESS) {
+                    mWaitingActivityLaunched.add(outResult);
+                    do {
+                        try {
+                            mService.wait();
+                        } catch (InterruptedException e) {
+                        }
+                    } while (!outResult.timeout && outResult.who == null);
+                } else if (res == ActivityManager.START_TASK_TO_FRONT) {
+                    ActivityRecord r = stack.topRunningActivityLocked(null);
+                    if (r.nowVisible) {
+                        outResult.timeout = false;
+                        outResult.who = new ComponentName(r.info.packageName, r.info.name);
+                        outResult.totalTime = 0;
+                        outResult.thisTime = 0;
+                    } else {
+                        outResult.thisTime = SystemClock.uptimeMillis();
+                        mWaitingActivityVisible.add(outResult);
+                        do {
+                            try {
+                                mService.wait();
+                            } catch (InterruptedException e) {
+                            }
+                        } while (!outResult.timeout && outResult.who == null);
+                    }
+                }
+            }
+
+            return res;
+        }
+    }
+
+    final int startActivities(IApplicationThread caller, int callingUid, String callingPackage,
+            Intent[] intents, String[] resolvedTypes, IBinder resultTo,
+            Bundle options, int userId) {
+        if (intents == null) {
+            throw new NullPointerException("intents is null");
+        }
+        if (resolvedTypes == null) {
+            throw new NullPointerException("resolvedTypes is null");
+        }
+        if (intents.length != resolvedTypes.length) {
+            throw new IllegalArgumentException("intents are length different than resolvedTypes");
+        }
+
+
+        int callingPid;
+        if (callingUid >= 0) {
+            callingPid = -1;
+        } else if (caller == null) {
+            callingPid = Binder.getCallingPid();
+            callingUid = Binder.getCallingUid();
+        } else {
+            callingPid = callingUid = -1;
+        }
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (mService) {
+                ActivityRecord[] outActivity = new ActivityRecord[1];
+                for (int i=0; i<intents.length; i++) {
+                    Intent intent = intents[i];
+                    if (intent == null) {
+                        continue;
+                    }
+
+                    // Refuse possible leaked file descriptors
+                    if (intent != null && intent.hasFileDescriptors()) {
+                        throw new IllegalArgumentException("File descriptors passed in Intent");
+                    }
+
+                    boolean componentSpecified = intent.getComponent() != null;
+
+                    // Don't modify the client's object!
+                    intent = new Intent(intent);
+
+                    // Collect information about the target of the Intent.
+                    ActivityInfo aInfo = resolveActivity(intent, resolvedTypes[i],
+                            0, null, null, userId);
+                    // TODO: New, check if this is correct
+                    aInfo = mService.getActivityInfoForUser(aInfo, userId);
+
+                    if (aInfo != null &&
+                            (aInfo.applicationInfo.flags & ApplicationInfo.FLAG_CANT_SAVE_STATE)
+                                    != 0) {
+                        throw new IllegalArgumentException(
+                                "FLAG_CANT_SAVE_STATE not supported here");
+                    }
+
+                    Bundle theseOptions;
+                    if (options != null && i == intents.length-1) {
+                        theseOptions = options;
+                    } else {
+                        theseOptions = null;
+                    }
+                    int res = startActivityLocked(caller, intent, resolvedTypes[i],
+                            aInfo, resultTo, null, -1, callingPid, callingUid, callingPackage,
+                            0, theseOptions, componentSpecified, outActivity, null);
+                    if (res < 0) {
+                        return res;
+                    }
+
+                    resultTo = outActivity[0] != null ? outActivity[0].appToken : null;
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+
+        return ActivityManager.START_SUCCESS;
+    }
+
+    final boolean realStartActivityLocked(ActivityRecord r,
+            ProcessRecord app, boolean andResume, boolean checkConfig)
+            throws RemoteException {
+
+        r.startFreezingScreenLocked(app, 0);
+        if (false) Slog.d(TAG, "realStartActivity: setting app visibility true");
+        mWindowManager.setAppVisibility(r.appToken, true);
+
+        // schedule launch ticks to collect information about slow apps.
+        r.startLaunchTickingLocked();
+
+        // Have the window manager re-evaluate the orientation of
+        // the screen based on the new activity order.  Note that
+        // as a result of this, it can call back into the activity
+        // manager with a new orientation.  We don't care about that,
+        // because the activity is not currently running so we are
+        // just restarting it anyway.
+        if (checkConfig) {
+            Configuration config = mWindowManager.updateOrientationFromAppTokens(
+                    mService.mConfiguration,
+                    r.mayFreezeScreenLocked(app) ? r.appToken : null);
+            mService.updateConfigurationLocked(config, r, false, false);
+        }
+
+        r.app = app;
+        app.waitingToKill = null;
+        r.launchCount++;
+        r.lastLaunchTime = SystemClock.uptimeMillis();
+
+        if (localLOGV) Slog.v(TAG, "Launching: " + r);
+
+        int idx = app.activities.indexOf(r);
+        if (idx < 0) {
+            app.activities.add(r);
+        }
+        mService.updateLruProcessLocked(app, true, null);
+        mService.updateOomAdjLocked();
+
+        final ActivityStack stack = r.task.stack;
+        try {
+            if (app.thread == null) {
+                throw new RemoteException();
+            }
+            List<ResultInfo> results = null;
+            List<Intent> newIntents = null;
+            if (andResume) {
+                results = r.results;
+                newIntents = r.newIntents;
+            }
+            if (DEBUG_SWITCH) Slog.v(TAG, "Launching: " + r
+                    + " icicle=" + r.icicle
+                    + " with results=" + results + " newIntents=" + newIntents
+                    + " andResume=" + andResume);
+            if (andResume) {
+                EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY,
+                        r.userId, System.identityHashCode(r),
+                        r.task.taskId, r.shortComponentName);
+            }
+            if (r.isHomeActivity() && r.isNotResolverActivity()) {
+                // Home process is the root process of the task.
+                mService.mHomeProcess = r.task.mActivities.get(0).app;
+            }
+            mService.ensurePackageDexOpt(r.intent.getComponent().getPackageName());
+            r.sleeping = false;
+            r.forceNewConfig = false;
+            mService.showAskCompatModeDialogLocked(r);
+            r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
+            String profileFile = null;
+            ParcelFileDescriptor profileFd = null;
+            boolean profileAutoStop = false;
+            if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) {
+                if (mService.mProfileProc == null || mService.mProfileProc == app) {
+                    mService.mProfileProc = app;
+                    profileFile = mService.mProfileFile;
+                    profileFd = mService.mProfileFd;
+                    profileAutoStop = mService.mAutoStopProfiler;
+                }
+            }
+            app.hasShownUi = true;
+            app.pendingUiClean = true;
+            if (profileFd != null) {
+                try {
+                    profileFd = profileFd.dup();
+                } catch (IOException e) {
+                    if (profileFd != null) {
+                        try {
+                            profileFd.close();
+                        } catch (IOException o) {
+                        }
+                        profileFd = null;
+                    }
+                }
+            }
+            app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP);
+            app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken,
+                    System.identityHashCode(r), r.info,
+                    new Configuration(mService.mConfiguration), r.compat,
+                    app.repProcState, r.icicle, results, newIntents, !andResume,
+                    mService.isNextTransitionForward(), profileFile, profileFd,
+                    profileAutoStop);
+
+            if ((app.info.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
+                // This may be a heavy-weight process!  Note that the package
+                // manager will ensure that only activity can run in the main
+                // process of the .apk, which is the only thing that will be
+                // considered heavy-weight.
+                if (app.processName.equals(app.info.packageName)) {
+                    if (mService.mHeavyWeightProcess != null
+                            && mService.mHeavyWeightProcess != app) {
+                        Slog.w(TAG, "Starting new heavy weight process " + app
+                                + " when already running "
+                                + mService.mHeavyWeightProcess);
+                    }
+                    mService.mHeavyWeightProcess = app;
+                    Message msg = mService.mHandler.obtainMessage(
+                            ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG);
+                    msg.obj = r;
+                    mService.mHandler.sendMessage(msg);
+                }
+            }
+
+        } catch (RemoteException e) {
+            if (r.launchFailed) {
+                // This is the second time we failed -- finish activity
+                // and give up.
+                Slog.e(TAG, "Second failure launching "
+                      + r.intent.getComponent().flattenToShortString()
+                      + ", giving up", e);
+                mService.appDiedLocked(app, app.pid, app.thread);
+                stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
+                        "2nd-crash", false);
+                return false;
+            }
+
+            // This is the first time we failed -- restart process and
+            // retry.
+            app.activities.remove(r);
+            throw e;
+        }
+
+        r.launchFailed = false;
+        if (stack.updateLRUListLocked(r)) {
+            Slog.w(TAG, "Activity " + r
+                  + " being launched, but already in LRU list");
+        }
+
+        if (andResume) {
+            // As part of the process of launching, ActivityThread also performs
+            // 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.
+            if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r
+                    + " (starting in stopped state)");
+            r.state = ActivityState.STOPPED;
+            r.stopped = true;
+        }
+
+        // Launch the new version setup screen if needed.  We do this -after-
+        // launching the initial activity (that is, home), so that it can have
+        // a chance to initialize itself while in the background, making the
+        // switch back to it faster and look better.
+        if (isFrontStack(stack)) {
+            mService.startSetupActivityLocked();
+        }
+
+        return true;
+    }
+
+    void startSpecificActivityLocked(ActivityRecord r,
+            boolean andResume, boolean checkConfig) {
+        // Is this activity's application already running?
+        ProcessRecord app = mService.getProcessRecordLocked(r.processName,
+                r.info.applicationInfo.uid, true);
+
+        r.task.stack.setLaunchTime(r);
+
+        if (app != null && app.thread != null) {
+            try {
+                if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0
+                        || !"android".equals(r.info.packageName)) {
+                    // Don't add this if it is a platform component that is marked
+                    // to run in multiple processes, because this is actually
+                    // part of the framework so doesn't make sense to track as a
+                    // separate apk in the process.
+                    app.addPackage(r.info.packageName, mService.mProcessStats);
+                }
+                realStartActivityLocked(r, app, andResume, checkConfig);
+                return;
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Exception when starting activity "
+                        + r.intent.getComponent().flattenToShortString(), e);
+            }
+
+            // If a dead object exception was thrown -- fall through to
+            // restart the application.
+        }
+
+        mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0,
+                "activity", r.intent.getComponent(), false, false, true);
+    }
+
+    final int startActivityLocked(IApplicationThread caller,
+            Intent intent, String resolvedType, ActivityInfo aInfo, IBinder resultTo,
+            String resultWho, int requestCode,
+            int callingPid, int callingUid, String callingPackage, int startFlags, Bundle options,
+            boolean componentSpecified, ActivityRecord[] outActivity, ActivityContainer container) {
+        int err = ActivityManager.START_SUCCESS;
+
+        ProcessRecord callerApp = null;
+        if (caller != null) {
+            callerApp = mService.getRecordForAppLocked(caller);
+            if (callerApp != null) {
+                callingPid = callerApp.pid;
+                callingUid = callerApp.info.uid;
+            } else {
+                Slog.w(TAG, "Unable to find app for caller " + caller
+                      + " (pid=" + callingPid + ") when starting: "
+                      + intent.toString());
+                err = ActivityManager.START_PERMISSION_DENIED;
+            }
+        }
+
+        if (err == ActivityManager.START_SUCCESS) {
+            final int userId = aInfo != null ? UserHandle.getUserId(aInfo.applicationInfo.uid) : 0;
+            Slog.i(TAG, "START u" + userId + " {" + intent.toShortString(true, true, true, false)
+                    + "} from pid " + (callerApp != null ? callerApp.pid : callingPid)
+                    + " on display " + (container == null ? (mFocusedStack == null ?
+                            Display.DEFAULT_DISPLAY : mFocusedStack.mDisplayId) :
+                            (container.mActivityDisplay == null ? Display.DEFAULT_DISPLAY :
+                                    container.mActivityDisplay.mDisplayId)));
+        }
+
+        ActivityRecord sourceRecord = null;
+        ActivityRecord resultRecord = null;
+        if (resultTo != null) {
+            sourceRecord = isInAnyStackLocked(resultTo);
+            if (DEBUG_RESULTS) Slog.v(
+                TAG, "Will send result to " + resultTo + " " + sourceRecord);
+            if (sourceRecord != null) {
+                if (requestCode >= 0 && !sourceRecord.finishing) {
+                    resultRecord = sourceRecord;
+                }
+            }
+        }
+        ActivityStack resultStack = resultRecord == null ? null : resultRecord.task.stack;
+
+        int launchFlags = intent.getFlags();
+
+        if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0
+                && sourceRecord != null) {
+            // Transfer the result target from the source activity to the new
+            // one being started, including any failures.
+            if (requestCode >= 0) {
+                ActivityOptions.abort(options);
+                return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT;
+            }
+            resultRecord = sourceRecord.resultTo;
+            resultWho = sourceRecord.resultWho;
+            requestCode = sourceRecord.requestCode;
+            sourceRecord.resultTo = null;
+            if (resultRecord != null) {
+                resultRecord.removeResultsLocked(
+                    sourceRecord, resultWho, requestCode);
+            }
+            if (sourceRecord.launchedFromUid == callingUid) {
+                // The new activity is being launched from the same uid as the previous
+                // activity in the flow, and asking to forward its result back to the
+                // previous.  In this case the activity is serving as a trampoline between
+                // the two, so we also want to update its launchedFromPackage to be the
+                // same as the previous activity.  Note that this is safe, since we know
+                // these two packages come from the same uid; the caller could just as
+                // well have supplied that same package name itself.  This specifially
+                // deals with the case of an intent picker/chooser being launched in the app
+                // flow to redirect to an activity picked by the user, where we want the final
+                // activity to consider it to have been launched by the previous app activity.
+                callingPackage = sourceRecord.launchedFromPackage;
+            }
+        }
+
+        if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) {
+            // We couldn't find a class that can handle the given Intent.
+            // That's the end of that!
+            err = ActivityManager.START_INTENT_NOT_RESOLVED;
+        }
+
+        if (err == ActivityManager.START_SUCCESS && aInfo == null) {
+            // We couldn't find the specific class specified in the Intent.
+            // Also the end of the line.
+            err = ActivityManager.START_CLASS_NOT_FOUND;
+        }
+
+        if (err != ActivityManager.START_SUCCESS) {
+            if (resultRecord != null) {
+                resultStack.sendActivityResultLocked(-1,
+                    resultRecord, resultWho, requestCode,
+                    Activity.RESULT_CANCELED, null);
+            }
+            setDismissKeyguard(false);
+            ActivityOptions.abort(options);
+            return err;
+        }
+
+        final int startAnyPerm = mService.checkPermission(
+                START_ANY_ACTIVITY, callingPid, callingUid);
+        final int componentPerm = mService.checkComponentPermission(aInfo.permission, callingPid,
+                callingUid, aInfo.applicationInfo.uid, aInfo.exported);
+        if (startAnyPerm != PERMISSION_GRANTED && componentPerm != PERMISSION_GRANTED) {
+            if (resultRecord != null) {
+                resultStack.sendActivityResultLocked(-1,
+                    resultRecord, resultWho, requestCode,
+                    Activity.RESULT_CANCELED, null);
+            }
+            setDismissKeyguard(false);
+            String msg;
+            if (!aInfo.exported) {
+                msg = "Permission Denial: starting " + intent.toString()
+                        + " from " + callerApp + " (pid=" + callingPid
+                        + ", uid=" + callingUid + ")"
+                        + " not exported from uid " + aInfo.applicationInfo.uid;
+            } else {
+                msg = "Permission Denial: starting " + intent.toString()
+                        + " from " + callerApp + " (pid=" + callingPid
+                        + ", uid=" + callingUid + ")"
+                        + " requires " + aInfo.permission;
+            }
+            Slog.w(TAG, msg);
+            throw new SecurityException(msg);
+        }
+
+        boolean abort = !mService.mIntentFirewall.checkStartActivity(intent, callingUid,
+                callingPid, resolvedType, aInfo.applicationInfo);
+
+        if (mService.mController != null) {
+            try {
+                // The Intent we give to the watcher has the extra data
+                // stripped off, since it can contain private information.
+                Intent watchIntent = intent.cloneFilter();
+                abort |= !mService.mController.activityStarting(watchIntent,
+                        aInfo.applicationInfo.packageName);
+            } catch (RemoteException e) {
+                mService.mController = null;
+            }
+        }
+
+        if (abort) {
+            if (resultRecord != null) {
+                resultStack.sendActivityResultLocked(-1, resultRecord, resultWho, requestCode,
+                        Activity.RESULT_CANCELED, null);
+            }
+            // We pretend to the caller that it was really started, but
+            // they will just get a cancel result.
+            setDismissKeyguard(false);
+            ActivityOptions.abort(options);
+            return ActivityManager.START_SUCCESS;
+        }
+
+        ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage,
+                intent, resolvedType, aInfo, mService.mConfiguration, resultRecord, resultWho,
+                requestCode, componentSpecified, this, container);
+        if (outActivity != null) {
+            outActivity[0] = r;
+        }
+
+        final ActivityStack stack = getFocusedStack();
+        if (stack.mResumedActivity == null
+                || stack.mResumedActivity.info.applicationInfo.uid != callingUid) {
+            if (!mService.checkAppSwitchAllowedLocked(callingPid, callingUid, "Activity start")) {
+                PendingActivityLaunch pal =
+                        new PendingActivityLaunch(r, sourceRecord, startFlags, stack);
+                mService.mPendingActivityLaunches.add(pal);
+                setDismissKeyguard(false);
+                ActivityOptions.abort(options);
+                return ActivityManager.START_SWITCHES_CANCELED;
+            }
+        }
+
+        if (mService.mDidAppSwitch) {
+            // This is the second allowed switch since we stopped switches,
+            // so now just generally allow switches.  Use case: user presses
+            // home (switches disabled, switch to home, mDidAppSwitch now true);
+            // user taps a home icon (coming from home so allowed, we hit here
+            // and now allow anyone to switch again).
+            mService.mAppSwitchesAllowedTime = 0;
+        } else {
+            mService.mDidAppSwitch = true;
+        }
+
+        mService.doPendingActivityLaunchesLocked(false);
+
+        err = startActivityUncheckedLocked(r, sourceRecord, startFlags, true, options);
+
+        if (allPausedActivitiesComplete()) {
+            // If someone asked to have the keyguard dismissed on the next
+            // activity start, but we are not actually doing an activity
+            // switch...  just dismiss the keyguard now, because we
+            // probably want to see whatever is behind it.
+            dismissKeyguard();
+        }
+        return err;
+    }
+
+    ActivityStack adjustStackFocus(ActivityRecord r) {
+        final TaskRecord task = r.task;
+        if (r.isApplicationActivity() || (task != null && task.isApplicationTask())) {
+            if (task != null) {
+                final ActivityStack taskStack = task.stack;
+                if (taskStack.isOnHomeDisplay()) {
+                    if (mFocusedStack != taskStack) {
+                        if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG, "adjustStackFocus: Setting " +
+                                "focused stack to r=" + r + " task=" + task);
+                        mFocusedStack = taskStack;
+                    } else {
+                        if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
+                            "adjustStackFocus: Focused stack already=" + mFocusedStack);
+                    }
+                }
+                return taskStack;
+            }
+
+            final ActivityContainer container = r.mInitialActivityContainer;
+            if (container != null) {
+                // The first time put it on the desired stack, after this put on task stack.
+                r.mInitialActivityContainer = null;
+                return container.mStack;
+            }
+
+            if (mFocusedStack != mHomeStack) {
+                if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
+                        "adjustStackFocus: Have a focused stack=" + mFocusedStack);
+                return mFocusedStack;
+            }
+
+            final ArrayList<ActivityStack> homeDisplayStacks = mHomeStack.mStacks;
+            for (int stackNdx = homeDisplayStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = homeDisplayStacks.get(stackNdx);
+                if (!stack.isHomeStack()) {
+                    if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
+                            "adjustStackFocus: Setting focused stack=" + stack);
+                    mFocusedStack = stack;
+                    return mFocusedStack;
+                }
+            }
+
+            // Need to create an app stack for this user.
+            int stackId = createStackOnDisplay(null, getNextStackId(), Display.DEFAULT_DISPLAY);
+            if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG, "adjustStackFocus: New stack r=" + r +
+                    " stackId=" + stackId);
+            mFocusedStack = getStack(stackId);
+            return mFocusedStack;
+        }
+        return mHomeStack;
+    }
+
+    void setFocusedStack(ActivityRecord r) {
+        if (r != null) {
+            final TaskRecord task = r.task;
+            boolean isHomeActivity = !r.isApplicationActivity();
+            if (!isHomeActivity && task != null) {
+                isHomeActivity = !task.isApplicationTask();
+            }
+            if (!isHomeActivity && task != null) {
+                final ActivityRecord parent = task.stack.mActivityContainer.mParentActivity;
+                isHomeActivity = parent != null && parent.isHomeActivity();
+            }
+            moveHomeStack(isHomeActivity);
+        }
+    }
+
+    final int startActivityUncheckedLocked(ActivityRecord r,
+            ActivityRecord sourceRecord, int startFlags, boolean doResume,
+            Bundle options) {
+        final Intent intent = r.intent;
+        final int callingUid = r.launchedFromUid;
+
+        int launchFlags = intent.getFlags();
+
+        // We'll invoke onUserLeaving before onPause only if the launching
+        // activity did not explicitly state that this is an automated launch.
+        mUserLeaving = (launchFlags&Intent.FLAG_ACTIVITY_NO_USER_ACTION) == 0;
+        if (DEBUG_USER_LEAVING) Slog.v(TAG, "startActivity() => mUserLeaving=" + 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) {
+            r.delayedResume = true;
+        }
+
+        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 = getFocusedStack().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;
+            }
+        }
+
+        if (sourceRecord == null) {
+            // This activity is not being started from another...  in this
+            // case we -always- start a new task.
+            if ((launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
+                Slog.w(TAG, "startActivity called from non-Activity context; forcing " +
+                        "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
+                launchFlags |= Intent.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 |= Intent.FLAG_ACTIVITY_NEW_TASK;
+        } else if (r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE
+                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
+            // The activity being started is a single instance...  it always
+            // gets launched into its own task.
+            launchFlags |= Intent.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&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
+                    Slog.w(TAG, "startActivity called from finishing " + sourceRecord
+                            + "; forcing " + "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
+                    launchFlags |= Intent.FLAG_ACTIVITY_NEW_TASK;
+                    newTaskInfo = sourceRecord.info;
+                    newTaskIntent = sourceRecord.task.intent;
+                }
+                sourceRecord = null;
+                sourceStack = null;
+            } else {
+                sourceStack = sourceRecord.task.stack;
+            }
+        } else {
+            sourceStack = null;
+        }
+
+        if (r.resultTo != null && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
+            // 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;
+        }
+
+        boolean addingToTask = false;
+        boolean movedHome = false;
+        TaskRecord reuseTask = null;
+        ActivityStack targetStack;
+        if (((launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
+                (launchFlags&Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0)
+                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK
+                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
+            // If bring to front is requested, and no result is requested, and
+            // we can find a task that was started with this same
+            // component, then instead of launching bring that one to the front.
+            if (r.resultTo == null) {
+                // 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.
+                ActivityRecord intentActivity = r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE
+                        ? findTaskLocked(r)
+                        : findActivityLocked(intent, r.info);
+                if (intentActivity != null) {
+                    if (r.task == null) {
+                        r.task = intentActivity.task;
+                    }
+                    targetStack = intentActivity.task.stack;
+                    targetStack.mLastPausedActivity = null;
+                    if (DEBUG_TASKS) Slog.d(TAG, "Bring to front target: " + targetStack
+                            + " from " + intentActivity);
+                    targetStack.moveToFront();
+                    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(intent, r.info);
+                    }
+                    // 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 lastStack = getLastStack();
+                    ActivityRecord curTop = lastStack == null?
+                            null : lastStack.topRunningNonDelayedActivityLocked(notTop);
+                    if (curTop != null && (curTop.task != intentActivity.task ||
+                            curTop.task != lastStack.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.
+                            movedHome = true;
+                            targetStack.moveTaskToFrontLocked(intentActivity.task, r, options);
+                            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.mOnTopOfHome = true;
+                            }
+                            options = null;
+                        }
+                    }
+                    // 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) {
+                            resumeTopActivitiesLocked(targetStack, null, options);
+                        } else {
+                            ActivityOptions.abort(options);
+                        }
+                        return ActivityManager.START_RETURN_INTENT_TO_CALLER;
+                    }
+                    if ((launchFlags &
+                            (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK))
+                            == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.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.intent, r.info);
+                    } else if ((launchFlags&Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0
+                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK
+                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
+                        // 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.intent, r.info);
+                            }
+                            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,
+                                    r, top.task);
+                            top.deliverNewIntentLocked(callingUid, r.intent);
+                        } 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;
+                        }
+                    } 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
+                                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP)
+                                && intentActivity.realActivity.equals(r.realActivity)) {
+                            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, r,
+                                    intentActivity.task);
+                            if (intentActivity.frontOfTask) {
+                                intentActivity.task.setIntent(r.intent, r.info);
+                            }
+                            intentActivity.deliverNewIntentLocked(callingUid, r.intent);
+                        } 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.intent, r.info);
+                    }
+                    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);
+                        } else {
+                            ActivityOptions.abort(options);
+                        }
+                        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 = getFocusedStack();
+            ActivityRecord top = topStack.topRunningNonDelayedActivityLocked(notTop);
+            if (top != null && r.resultTo == null) {
+                if (top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
+                    if (top.app != null && top.app.thread != null) {
+                        if ((launchFlags&Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0
+                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP
+                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
+                            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) {
+                                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);
+                            return ActivityManager.START_DELIVERED_TO_TOP;
+                        }
+                    }
+                }
+            }
+
+        } else {
+            if (r.resultTo != 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;
+
+        // Should this be considered a new task?
+        if (r.resultTo == null && !addingToTask
+                && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
+            targetStack = adjustStackFocus(r);
+            targetStack.moveToFront();
+            if (reuseTask == null) {
+                r.setTask(targetStack.createTaskRecord(getNextTaskId(),
+                        newTaskInfo != null ? newTaskInfo : r.info,
+                        newTaskIntent != null ? newTaskIntent : intent,
+                        true), null, true);
+                if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new task " +
+                        r.task);
+            } else {
+                r.setTask(reuseTask, reuseTask, true);
+            }
+            newTask = true;
+            if (!movedHome) {
+                if ((launchFlags &
+                        (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME))
+                        == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.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.mOnTopOfHome = r.task.stack.isOnHomeDisplay();
+                }
+            }
+        } else if (sourceRecord != null) {
+            TaskRecord sourceTask = sourceRecord.task;
+            targetStack = sourceTask.stack;
+            targetStack.moveToFront();
+            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);
+                    // 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);
+                    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, sourceRecord.thumbHolder, false);
+            if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r
+                    + " in existing task " + r.task + " from source " + sourceRecord);
+
+        } 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 = adjustStackFocus(r);
+            targetStack.moveToFront();
+            ActivityRecord prev = targetStack.topActivity();
+            r.setTask(prev != null ? prev.task
+                    : targetStack.createTaskRecord(getNextTaskId(), r.info, intent, true),
+                    null, true);
+            if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r
+                    + " in new guessed " + r.task);
+        }
+
+        mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
+                intent, r.getUriPermissionsLocked());
+
+        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, doResume, keepCurTransition, options);
+        mService.setFocusedActivityLocked(r);
+        return ActivityManager.START_SUCCESS;
+    }
+
+    void acquireLaunchWakelock() {
+        if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
+            throw new IllegalStateException("Calling must be system uid");
+        }
+        mLaunchingActivity.acquire();
+        if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) {
+            // To be safe, don't allow the wake lock to be held for too long.
+            mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT);
+        }
+    }
+
+    // Checked.
+    final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout,
+            Configuration config) {
+        if (localLOGV) Slog.v(TAG, "Activity idle: " + token);
+
+        ArrayList<ActivityRecord> stops = null;
+        ArrayList<ActivityRecord> finishes = null;
+        ArrayList<UserStartedState> startingUsers = null;
+        int NS = 0;
+        int NF = 0;
+        IApplicationThread sendThumbnail = null;
+        boolean booting = false;
+        boolean enableScreen = false;
+        boolean activityRemoved = false;
+
+        ActivityRecord r = ActivityRecord.forToken(token);
+        if (r != null) {
+            if (DEBUG_IDLE) Slog.d(TAG, "activityIdleInternalLocked: Callers=" +
+                    Debug.getCallers(4));
+            mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
+            r.finishLaunchTickingLocked();
+            if (fromTimeout) {
+                reportActivityLaunchedLocked(fromTimeout, r, -1, -1);
+            }
+
+            // This is a hack to semi-deal with a race condition
+            // in the client where it can be constructed with a
+            // newer configuration from when we asked it to launch.
+            // We'll update with whatever configuration it now says
+            // it used to launch.
+            if (config != null) {
+                r.configuration = config;
+            }
+
+            // We are now idle.  If someone is waiting for a thumbnail from
+            // us, we can now deliver.
+            r.idle = true;
+
+            if (r.thumbnailNeeded && r.app != null && r.app.thread != null) {
+                sendThumbnail = r.app.thread;
+                r.thumbnailNeeded = false;
+            }
+
+            //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout);
+            if (!mService.mBooted && isFrontStack(r.task.stack)) {
+                mService.mBooted = true;
+                enableScreen = true;
+            }
+        }
+
+        if (allResumedActivitiesIdle()) {
+            if (r != null) {
+                mService.scheduleAppGcsLocked();
+            }
+
+            if (mLaunchingActivity.isHeld()) {
+                mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
+                if (VALIDATE_WAKE_LOCK_CALLER &&
+                        Binder.getCallingUid() != Process.myUid()) {
+                    throw new IllegalStateException("Calling must be system uid");
+                }
+                mLaunchingActivity.release();
+            }
+            ensureActivitiesVisibleLocked(null, 0);
+        }
+
+        // Atomically retrieve all of the other things to do.
+        stops = processStoppingActivitiesLocked(true);
+        NS = stops != null ? stops.size() : 0;
+        if ((NF=mFinishingActivities.size()) > 0) {
+            finishes = new ArrayList<ActivityRecord>(mFinishingActivities);
+            mFinishingActivities.clear();
+        }
+
+        final ArrayList<ActivityRecord> thumbnails;
+        final int NT = mCancelledThumbnails.size();
+        if (NT > 0) {
+            thumbnails = new ArrayList<ActivityRecord>(mCancelledThumbnails);
+            mCancelledThumbnails.clear();
+        } else {
+            thumbnails = null;
+        }
+
+        if (isFrontStack(mHomeStack)) {
+            booting = mService.mBooting;
+            mService.mBooting = false;
+        }
+
+        if (mStartingUsers.size() > 0) {
+            startingUsers = new ArrayList<UserStartedState>(mStartingUsers);
+            mStartingUsers.clear();
+        }
+
+        // Perform the following actions from unsynchronized state.
+        final IApplicationThread thumbnailThread = sendThumbnail;
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                if (thumbnailThread != null) {
+                    try {
+                        thumbnailThread.requestThumbnail(token);
+                    } catch (Exception e) {
+                        Slog.w(TAG, "Exception thrown when requesting thumbnail", e);
+                        mService.sendPendingThumbnail(null, token, null, null, true);
+                    }
+                }
+
+                // Report back to any thumbnail receivers.
+                for (int i = 0; i < NT; i++) {
+                    ActivityRecord r = thumbnails.get(i);
+                    mService.sendPendingThumbnail(r, null, null, null, true);
+                }
+            }
+        });
+
+        // Stop any activities that are scheduled to do so but have been
+        // waiting for the next one to start.
+        for (int i = 0; i < NS; i++) {
+            r = stops.get(i);
+            final ActivityStack stack = r.task.stack;
+            if (r.finishing) {
+                stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false);
+            } else {
+                stack.stopActivityLocked(r);
+            }
+        }
+
+        // Finish any activities that are scheduled to do so but have been
+        // waiting for the next one to start.
+        for (int i = 0; i < NF; i++) {
+            r = finishes.get(i);
+            activityRemoved |= r.task.stack.destroyActivityLocked(r, true, false, "finish-idle");
+        }
+
+        if (booting) {
+            mService.finishBooting();
+        } else if (startingUsers != null) {
+            for (int i = 0; i < startingUsers.size(); i++) {
+                mService.finishUserSwitch(startingUsers.get(i));
+            }
+        }
+
+        mService.trimApplications();
+        //dump();
+        //mWindowManager.dump();
+
+        if (enableScreen) {
+            mService.enableScreenAfterBoot();
+        }
+
+        if (activityRemoved) {
+            resumeTopActivitiesLocked();
+        }
+
+        return r;
+    }
+
+    boolean handleAppDiedLocked(ProcessRecord app) {
+        boolean hasVisibleActivities = false;
+        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) {
+                hasVisibleActivities |= stacks.get(stackNdx).handleAppDiedLocked(app);
+            }
+        }
+        return hasVisibleActivities;
+    }
+
+    void closeSystemDialogsLocked() {
+        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) {
+                stacks.get(stackNdx).closeSystemDialogsLocked();
+            }
+        }
+    }
+
+    void removeUserLocked(int userId) {
+        mUserStackInFront.delete(userId);
+    }
+
+    /**
+     * @return true if some activity was finished (or would have finished if doit were true).
+     */
+    boolean forceStopPackageLocked(String name, boolean doit, boolean evenPersistent, int userId) {
+        boolean didSomething = false;
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            final int numStacks = stacks.size();
+            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (stack.forceStopPackageLocked(name, doit, evenPersistent, userId)) {
+                    didSomething = true;
+                }
+            }
+        }
+        return didSomething;
+    }
+
+    void updatePreviousProcessLocked(ActivityRecord r) {
+        // Now that this process has stopped, we may want to consider
+        // it to be the previous app to try to keep around in case
+        // the user wants to return to it.
+
+        // First, found out what is currently the foreground app, so that
+        // we don't blow away the previous app if this activity is being
+        // hosted by the process that is actually still the foreground.
+        ProcessRecord fgApp = null;
+        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 (isFrontStack(stack)) {
+                    if (stack.mResumedActivity != null) {
+                        fgApp = stack.mResumedActivity.app;
+                    } else if (stack.mPausingActivity != null) {
+                        fgApp = stack.mPausingActivity.app;
+                    }
+                    break;
+                }
+            }
+        }
+
+        // Now set this one as the previous process, only if that really
+        // makes sense to.
+        if (r.app != null && fgApp != null && r.app != fgApp
+                && r.lastVisibleTime > mService.mPreviousProcessVisibleTime
+                && r.app != mService.mHomeProcess) {
+            mService.mPreviousProcess = r.app;
+            mService.mPreviousProcessVisibleTime = r.lastVisibleTime;
+        }
+    }
+
+    boolean resumeTopActivitiesLocked() {
+        return resumeTopActivitiesLocked(null, null, null);
+    }
+
+    boolean resumeTopActivitiesLocked(ActivityStack targetStack, ActivityRecord target,
+            Bundle targetOptions) {
+        if (targetStack == null) {
+            targetStack = getFocusedStack();
+        }
+        // Do targetStack first.
+        boolean result = false;
+        if (isFrontStack(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 (isFrontStack(stack)) {
+                    stack.resumeTopActivityLocked(null);
+                }
+            }
+        }
+        return result;
+    }
+
+    void finishTopRunningActivityLocked(ProcessRecord app) {
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            final int numStacks = stacks.size();
+            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                stack.finishTopRunningActivityLocked(app);
+            }
+        }
+    }
+
+    void findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) {
+        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) {
+                if (stacks.get(stackNdx).findTaskToMoveToFrontLocked(taskId, flags, options)) {
+                    if (DEBUG_STACK) Slog.d(TAG, "findTaskToMoveToFront: moved to front of stack="
+                            + stacks.get(stackNdx));
+                    return;
+                }
+            }
+        }
+    }
+
+    ActivityStack getStack(int stackId) {
+        WeakReference<ActivityContainer> weakReference = mActivityContainers.get(stackId);
+        if (weakReference != null) {
+            ActivityContainer activityContainer = weakReference.get();
+            if (activityContainer != null) {
+                return activityContainer.mStack;
+            } else {
+                mActivityContainers.remove(stackId);
+            }
+        }
+        return null;
+    }
+
+    ArrayList<ActivityStack> getStacks() {
+        ArrayList<ActivityStack> allStacks = new ArrayList<ActivityStack>();
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            allStacks.addAll(mActivityDisplays.valueAt(displayNdx).mStacks);
+        }
+        return allStacks;
+    }
+
+    IBinder getHomeActivityToken() {
+        final ArrayList<TaskRecord> tasks = mHomeStack.getAllTasks();
+        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            final TaskRecord task = tasks.get(taskNdx);
+            if (task.isHomeTask()) {
+                final ArrayList<ActivityRecord> activities = task.mActivities;
+                for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                    final ActivityRecord r = activities.get(activityNdx);
+                    if (r.isHomeActivity()) {
+                        return r.appToken;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    ActivityContainer createActivityContainer(ActivityRecord parentActivity, int stackId,
+            IActivityContainerCallback callback) {
+        ActivityContainer activityContainer = new ActivityContainer(parentActivity, stackId,
+                callback);
+        mActivityContainers.put(stackId, new WeakReference<ActivityContainer>(activityContainer));
+        if (parentActivity != null) {
+            parentActivity.mChildContainers.add(activityContainer.mStack);
+        }
+        return activityContainer;
+    }
+
+    ActivityContainer createActivityContainer(ActivityRecord parentActivity,
+            IActivityContainerCallback callback) {
+        return createActivityContainer(parentActivity, getNextStackId(), callback);
+    }
+
+    void removeChildActivityContainers(ActivityRecord parentActivity) {
+        for (int ndx = mActivityContainers.size() - 1; ndx >= 0; --ndx) {
+            final ActivityContainer container = mActivityContainers.valueAt(ndx).get();
+            if (container == null) {
+                mActivityContainers.removeAt(ndx);
+                continue;
+            }
+            if (container.mParentActivity != parentActivity) {
+                continue;
+            }
+
+            ActivityStack stack = container.mStack;
+            ActivityRecord top = stack.topRunningNonDelayedActivityLocked(null);
+            if (top != null) {
+                // TODO: Make sure the next activity doesn't start up when top is destroyed.
+                stack.destroyActivityLocked(top, true, true, "stack parent destroyed");
+            }
+            mActivityContainers.removeAt(ndx);
+            container.detachLocked();
+        }
+    }
+
+    void deleteActivityContainer(IActivityContainer container) {
+        ActivityContainer activityContainer = (ActivityContainer)container;
+        if (activityContainer != null) {
+            activityContainer.mStack.destroyActivitiesLocked(null, true,
+                    "deleteActivityContainer");
+            final ActivityRecord parent = activityContainer.mParentActivity;
+            if (parent != null) {
+                parent.mChildContainers.remove(activityContainer);
+            }
+            final int stackId = activityContainer.mStackId;
+            mActivityContainers.remove(stackId);
+            mWindowManager.removeStack(stackId);
+        }
+    }
+
+    private int createStackOnDisplay(ActivityRecord parentActivity, int stackId, int displayId) {
+        ActivityDisplay activityDisplay = mActivityDisplays.get(displayId);
+        if (activityDisplay == null) {
+            return -1;
+        }
+
+        ActivityContainer activityContainer =
+                createActivityContainer(parentActivity, stackId, null);
+        activityContainer.attachToDisplayLocked(activityDisplay);
+        return stackId;
+    }
+
+    int getNextStackId() {
+        while (true) {
+            if (++mLastStackId <= HOME_STACK_ID) {
+                mLastStackId = HOME_STACK_ID + 1;
+            }
+            if (getStack(mLastStackId) == null) {
+                break;
+            }
+        }
+        return mLastStackId;
+    }
+
+    void moveTaskToStack(int taskId, int stackId, boolean toTop) {
+        final TaskRecord task = anyTaskForIdLocked(taskId);
+        if (task == null) {
+            return;
+        }
+        final ActivityStack stack = getStack(stackId);
+        if (stack == null) {
+            Slog.w(TAG, "moveTaskToStack: no stack for id=" + stackId);
+            return;
+        }
+        task.stack.removeTask(task);
+        stack.addTask(task, toTop);
+        mWindowManager.addTask(taskId, stackId, toTop);
+        resumeTopActivitiesLocked();
+    }
+
+    ActivityRecord findTaskLocked(ActivityRecord r) {
+        if (DEBUG_TASKS) Slog.d(TAG, "Looking for task of " + r);
+        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 (!r.isApplicationActivity() && !stack.isHomeStack()) {
+                    if (DEBUG_TASKS) Slog.d(TAG, "Skipping stack: " + stack);
+                    continue;
+                }
+                final ActivityRecord ar = stack.findTaskLocked(r);
+                if (ar != null) {
+                    return ar;
+                }
+            }
+        }
+        if (DEBUG_TASKS) Slog.d(TAG, "No task found");
+        return null;
+    }
+
+    ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) {
+        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 ActivityRecord ar = stacks.get(stackNdx).findActivityLocked(intent, info);
+                if (ar != null) {
+                    return ar;
+                }
+            }
+        }
+        return null;
+    }
+
+    void goingToSleepLocked() {
+        scheduleSleepTimeout();
+        if (!mGoingToSleep.isHeld()) {
+            mGoingToSleep.acquire();
+            if (mLaunchingActivity.isHeld()) {
+                if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
+                    throw new IllegalStateException("Calling must be system uid");
+                }
+                mLaunchingActivity.release();
+                mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
+            }
+        }
+        checkReadyForSleepLocked();
+    }
+
+    boolean shutdownLocked(int timeout) {
+        boolean timedout = false;
+        goingToSleepLocked();
+
+        final long endTime = System.currentTimeMillis() + timeout;
+        while (true) {
+            boolean cantShutdown = false;
+            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) {
+                    cantShutdown |= stacks.get(stackNdx).checkReadyForSleepLocked();
+                }
+            }
+            if (cantShutdown) {
+                long timeRemaining = endTime - System.currentTimeMillis();
+                if (timeRemaining > 0) {
+                    try {
+                        mService.wait(timeRemaining);
+                    } catch (InterruptedException e) {
+                    }
+                } else {
+                    Slog.w(TAG, "Activity manager shutdown timed out");
+                    timedout = true;
+                    break;
+                }
+            } else {
+                break;
+            }
+        }
+
+        // Force checkReadyForSleep to complete.
+        mSleepTimeout = true;
+        checkReadyForSleepLocked();
+
+        return timedout;
+    }
+
+    void comeOutOfSleepIfNeededLocked() {
+        removeSleepTimeouts();
+        if (mGoingToSleep.isHeld()) {
+            mGoingToSleep.release();
+        }
+        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);
+                stack.awakeFromSleepingLocked();
+                if (isFrontStack(stack)) {
+                    resumeTopActivitiesLocked();
+                }
+            }
+        }
+        mGoingToSleepActivities.clear();
+    }
+
+    void activitySleptLocked(ActivityRecord r) {
+        mGoingToSleepActivities.remove(r);
+        checkReadyForSleepLocked();
+    }
+
+    void checkReadyForSleepLocked() {
+        if (!mService.isSleepingOrShuttingDown()) {
+            // Do not care.
+            return;
+        }
+
+        if (!mSleepTimeout) {
+            boolean dontSleep = false;
+            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) {
+                    dontSleep |= stacks.get(stackNdx).checkReadyForSleepLocked();
+                }
+            }
+
+            if (mStoppingActivities.size() > 0) {
+                // Still need to tell some activities to stop; can't sleep yet.
+                if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still need to stop "
+                        + mStoppingActivities.size() + " activities");
+                scheduleIdleLocked();
+                dontSleep = true;
+            }
+
+            if (mGoingToSleepActivities.size() > 0) {
+                // Still need to tell some activities to sleep; can't sleep yet.
+                if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still need to sleep "
+                        + mGoingToSleepActivities.size() + " activities");
+                dontSleep = true;
+            }
+
+            if (dontSleep) {
+                return;
+            }
+        }
+
+        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) {
+                stacks.get(stackNdx).goToSleep();
+            }
+        }
+
+        removeSleepTimeouts();
+
+        if (mGoingToSleep.isHeld()) {
+            mGoingToSleep.release();
+        }
+        if (mService.mShuttingDown) {
+            mService.notifyAll();
+        }
+    }
+
+    boolean reportResumedActivityLocked(ActivityRecord r) {
+        final ActivityStack stack = r.task.stack;
+        if (isFrontStack(stack)) {
+            mService.updateUsageStats(r, true);
+        }
+        if (allResumedActivitiesComplete()) {
+            ensureActivitiesVisibleLocked(null, 0);
+            mWindowManager.executeAppTransition();
+            return true;
+        }
+        return false;
+    }
+
+    void handleAppCrashLocked(ProcessRecord app) {
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            final int numStacks = stacks.size();
+            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                stack.handleAppCrashLocked(app);
+            }
+        }
+    }
+
+    void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) {
+        // First the front stacks. In case any are not fullscreen and are in front of home.
+        boolean showHomeBehindStack = false;
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            final int topStackNdx = stacks.size() - 1;
+            for (int stackNdx = topStackNdx; stackNdx >= 0; --stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                if (stackNdx == topStackNdx) {
+                    // Top stack.
+                    showHomeBehindStack =
+                            stack.ensureActivitiesVisibleLocked(starting, configChanges);
+                } else {
+                    // Back stack.
+                    stack.ensureActivitiesVisibleLocked(starting, configChanges,
+                            showHomeBehindStack);
+                }
+            }
+        }
+    }
+
+    void scheduleDestroyAllActivities(ProcessRecord app, String reason) {
+        for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
+            final ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            final int numStacks = stacks.size();
+            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                stack.scheduleDestroyActivities(app, false, reason);
+            }
+        }
+    }
+
+    boolean switchUserLocked(int userId, UserStartedState uss) {
+        mUserStackInFront.put(mCurrentUser, getFocusedStack().getStackId());
+        final int restoreStackId = mUserStackInFront.get(userId, HOME_STACK_ID);
+        mCurrentUser = userId;
+
+        mStartingUsers.add(uss);
+        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);
+                stack.switchUserLocked(userId);
+                mWindowManager.moveTaskToTop(stack.topTask().taskId);
+            }
+        }
+
+        ActivityStack stack = getStack(restoreStackId);
+        if (stack == null) {
+            stack = mHomeStack;
+        }
+        final boolean homeInFront = stack.isHomeStack();
+        if (stack.isOnHomeDisplay()) {
+            moveHomeStack(homeInFront);
+            mWindowManager.moveTaskToTop(stack.topTask().taskId);
+        } else {
+            // Stack was moved to another display while user was swapped out.
+            resumeHomeActivity(null);
+        }
+        return homeInFront;
+    }
+
+    final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove) {
+        int N = mStoppingActivities.size();
+        if (N <= 0) return null;
+
+        ArrayList<ActivityRecord> stops = null;
+
+        final boolean nowVisible = allResumedActivitiesVisible();
+        for (int i=0; i<N; i++) {
+            ActivityRecord s = mStoppingActivities.get(i);
+            if (localLOGV) Slog.v(TAG, "Stopping " + s + ": nowVisible="
+                    + nowVisible + " waitingVisible=" + s.waitingVisible
+                    + " finishing=" + s.finishing);
+            if (s.waitingVisible && nowVisible) {
+                mWaitingVisibleActivities.remove(s);
+                s.waitingVisible = false;
+                if (s.finishing) {
+                    // If this activity is finishing, it is sitting on top of
+                    // everyone else but we now know it is no longer needed...
+                    // so get rid of it.  Otherwise, we need to go through the
+                    // normal flow and hide it once we determine that it is
+                    // hidden by the activities in front of it.
+                    if (localLOGV) Slog.v(TAG, "Before stopping, can hide: " + s);
+                    mWindowManager.setAppVisibility(s.appToken, false);
+                }
+            }
+            if ((!s.waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
+                if (localLOGV) Slog.v(TAG, "Ready to stop: " + s);
+                if (stops == null) {
+                    stops = new ArrayList<ActivityRecord>();
+                }
+                stops.add(s);
+                mStoppingActivities.remove(i);
+                N--;
+                i--;
+            }
+        }
+
+        return stops;
+    }
+
+    void validateTopActivitiesLocked() {
+        // FIXME
+/*        for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final ActivityStack stack = stacks.get(stackNdx);
+            final ActivityRecord r = stack.topRunningActivityLocked(null);
+            final ActivityState state = r == null ? ActivityState.DESTROYED : r.state;
+            if (isFrontStack(stack)) {
+                if (r == null) {
+                    Slog.e(TAG, "validateTop...: null top activity, stack=" + stack);
+                } else {
+                    final ActivityRecord pausing = stack.mPausingActivity;
+                    if (pausing != null && pausing == r) {
+                        Slog.e(TAG, "validateTop...: top stack has pausing activity r=" + r +
+                            " state=" + state);
+                    }
+                    if (state != ActivityState.INITIALIZING && state != ActivityState.RESUMED) {
+                        Slog.e(TAG, "validateTop...: activity in front not resumed r=" + r +
+                                " state=" + state);
+                    }
+                }
+            } else {
+                final ActivityRecord resumed = stack.mResumedActivity;
+                if (resumed != null && resumed == r) {
+                    Slog.e(TAG, "validateTop...: back stack has resumed activity r=" + r +
+                        " state=" + state);
+                }
+                if (r != null && (state == ActivityState.INITIALIZING
+                        || state == ActivityState.RESUMED)) {
+                    Slog.e(TAG, "validateTop...: activity in back resumed r=" + r +
+                            " state=" + state);
+                }
+            }
+        }
+*/
+    }
+
+    public void dump(PrintWriter pw, String prefix) {
+        pw.print(prefix); pw.print("mDismissKeyguardOnNextActivity=");
+                pw.println(mDismissKeyguardOnNextActivity);
+        pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack);
+                pw.print(" mLastFocusedStack="); pw.println(mLastFocusedStack);
+        pw.print(prefix); pw.println("mSleepTimeout=" + mSleepTimeout);
+        pw.print(prefix); pw.println("mCurTaskId=" + mCurTaskId);
+        pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront);
+        pw.print(prefix); pw.println("mActivityContainers=" + mActivityContainers);
+    }
+
+    ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) {
+        return getFocusedStack().getDumpActivitiesLocked(name);
+    }
+
+    static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage,
+            boolean needSep, String prefix) {
+        if (activity != null) {
+            if (dumpPackage == null || dumpPackage.equals(activity.packageName)) {
+                if (needSep) {
+                    pw.println();
+                }
+                pw.print(prefix);
+                pw.println(activity);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll,
+            boolean dumpClient, String dumpPackage) {
+        boolean printed = false;
+        boolean needSep = false;
+        for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) {
+            ActivityDisplay activityDisplay = mActivityDisplays.valueAt(displayNdx);
+            pw.print("Display #"); pw.println(activityDisplay.mDisplayId);
+            ArrayList<ActivityStack> stacks = activityDisplay.mStacks;
+            final int numStacks = stacks.size();
+            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+                final ActivityStack stack = stacks.get(stackNdx);
+                StringBuilder stackHeader = new StringBuilder(128);
+                stackHeader.append("  Stack #");
+                stackHeader.append(stack.mStackId);
+                stackHeader.append(":");
+                printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage,
+                        needSep, stackHeader.toString());
+                printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, "    ", "Run", false,
+                        !dumpAll, false, dumpPackage, true,
+                        "    Running activities (most recent first):", null);
+
+                needSep = printed;
+                boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep,
+                        "    mPausingActivity: ");
+                if (pr) {
+                    printed = true;
+                    needSep = false;
+                }
+                pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep,
+                        "    mResumedActivity: ");
+                if (pr) {
+                    printed = true;
+                    needSep = false;
+                }
+                if (dumpAll) {
+                    pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep,
+                            "    mLastPausedActivity: ");
+                    if (pr) {
+                        printed = true;
+                        needSep = true;
+                    }
+                    printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage,
+                            needSep, "    mLastNoHistoryActivity: ");
+                }
+                needSep = printed;
+            }
+        }
+
+        printed |= dumpHistoryList(fd, pw, mFinishingActivities, "  ", "Fin", false, !dumpAll,
+                false, dumpPackage, true, "  Activities waiting to finish:", null);
+        printed |= dumpHistoryList(fd, pw, mStoppingActivities, "  ", "Stop", false, !dumpAll,
+                false, dumpPackage, true, "  Activities waiting to stop:", null);
+        printed |= dumpHistoryList(fd, pw, mWaitingVisibleActivities, "  ", "Wait", false, !dumpAll,
+                false, dumpPackage, true, "  Activities waiting for another to become visible:",
+                null);
+        printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, "  ", "Sleep", false, !dumpAll,
+                false, dumpPackage, true, "  Activities waiting to sleep:", null);
+        printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, "  ", "Sleep", false, !dumpAll,
+                false, dumpPackage, true, "  Activities waiting to sleep:", null);
+
+        return printed;
+    }
+
+    static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list,
+            String prefix, String label, boolean complete, boolean brief, boolean client,
+            String dumpPackage, boolean needNL, String header1, String header2) {
+        TaskRecord lastTask = null;
+        String innerPrefix = null;
+        String[] args = null;
+        boolean printed = false;
+        for (int i=list.size()-1; i>=0; i--) {
+            final ActivityRecord r = list.get(i);
+            if (dumpPackage != null && !dumpPackage.equals(r.packageName)) {
+                continue;
+            }
+            if (innerPrefix == null) {
+                innerPrefix = prefix + "      ";
+                args = new String[0];
+            }
+            printed = true;
+            final boolean full = !brief && (complete || !r.isInHistory());
+            if (needNL) {
+                pw.println("");
+                needNL = false;
+            }
+            if (header1 != null) {
+                pw.println(header1);
+                header1 = null;
+            }
+            if (header2 != null) {
+                pw.println(header2);
+                header2 = null;
+            }
+            if (lastTask != r.task) {
+                lastTask = r.task;
+                pw.print(prefix);
+                pw.print(full ? "* " : "  ");
+                pw.println(lastTask);
+                if (full) {
+                    lastTask.dump(pw, prefix + "  ");
+                } else if (complete) {
+                    // Complete + brief == give a summary.  Isn't that obvious?!?
+                    if (lastTask.intent != null) {
+                        pw.print(prefix); pw.print("  ");
+                                pw.println(lastTask.intent.toInsecureStringWithClip());
+                    }
+                }
+            }
+            pw.print(prefix); pw.print(full ? "  * " : "    "); pw.print(label);
+            pw.print(" #"); pw.print(i); pw.print(": ");
+            pw.println(r);
+            if (full) {
+                r.dump(pw, innerPrefix);
+            } else if (complete) {
+                // Complete + brief == give a summary.  Isn't that obvious?!?
+                pw.print(innerPrefix); pw.println(r.intent.toInsecureString());
+                if (r.app != null) {
+                    pw.print(innerPrefix); pw.println(r.app);
+                }
+            }
+            if (client && r.app != null && r.app.thread != null) {
+                // flush anything that is already in the PrintWriter since the thread is going
+                // to write to the file descriptor directly
+                pw.flush();
+                try {
+                    TransferPipe tp = new TransferPipe();
+                    try {
+                        r.app.thread.dumpActivity(tp.getWriteFd().getFileDescriptor(),
+                                r.appToken, innerPrefix, args);
+                        // Short timeout, since blocking here can
+                        // deadlock with the application.
+                        tp.go(fd, 2000);
+                    } finally {
+                        tp.kill();
+                    }
+                } catch (IOException e) {
+                    pw.println(innerPrefix + "Failure while dumping the activity: " + e);
+                } catch (RemoteException e) {
+                    pw.println(innerPrefix + "Got a RemoteException while dumping the activity");
+                }
+                needNL = true;
+            }
+        }
+        return printed;
+    }
+
+    void scheduleIdleTimeoutLocked(ActivityRecord next) {
+        if (DEBUG_IDLE) Slog.d(TAG, "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4));
+        Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next);
+        mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT);
+    }
+
+    final void scheduleIdleLocked() {
+        mHandler.sendEmptyMessage(IDLE_NOW_MSG);
+    }
+
+    void removeTimeoutsForActivityLocked(ActivityRecord r) {
+        if (DEBUG_IDLE) Slog.d(TAG, "removeTimeoutsForActivity: Callers=" + Debug.getCallers(4));
+        mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
+    }
+
+    final void scheduleResumeTopActivities() {
+        if (!mHandler.hasMessages(RESUME_TOP_ACTIVITY_MSG)) {
+            mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG);
+        }
+    }
+
+    void removeSleepTimeouts() {
+        mSleepTimeout = false;
+        mHandler.removeMessages(SLEEP_TIMEOUT_MSG);
+    }
+
+    final void scheduleSleepTimeout() {
+        removeSleepTimeouts();
+        mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT);
+    }
+
+    @Override
+    public void onDisplayAdded(int displayId) {
+        mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_ADDED, displayId, 0));
+    }
+
+    @Override
+    public void onDisplayRemoved(int displayId) {
+        mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_REMOVED, displayId, 0));
+    }
+
+    @Override
+    public void onDisplayChanged(int displayId) {
+        mHandler.sendMessage(mHandler.obtainMessage(HANDLE_DISPLAY_CHANGED, displayId, 0));
+    }
+
+    public void handleDisplayAddedLocked(int displayId) {
+        boolean newDisplay;
+        synchronized (mService) {
+            newDisplay = mActivityDisplays.get(displayId) == null;
+            if (newDisplay) {
+                ActivityDisplay activityDisplay = new ActivityDisplay(displayId);
+                mActivityDisplays.put(displayId, activityDisplay);
+            }
+        }
+        if (newDisplay) {
+            mWindowManager.onDisplayAdded(displayId);
+        }
+    }
+
+    public void handleDisplayRemovedLocked(int displayId) {
+        synchronized (mService) {
+            ActivityDisplay activityDisplay = mActivityDisplays.get(displayId);
+            if (activityDisplay != null) {
+                ArrayList<ActivityStack> stacks = activityDisplay.mStacks;
+                for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+                    stacks.get(stackNdx).mActivityContainer.detachLocked();
+                }
+                mActivityDisplays.remove(displayId);
+            }
+        }
+        mWindowManager.onDisplayRemoved(displayId);
+    }
+
+    public void handleDisplayChangedLocked(int displayId) {
+        synchronized (mService) {
+            ActivityDisplay activityDisplay = mActivityDisplays.get(displayId);
+            if (activityDisplay != null) {
+                // TODO: Update the bounds.
+            }
+        }
+        mWindowManager.onDisplayChanged(displayId);
+    }
+
+    StackInfo getStackInfo(ActivityStack stack) {
+        StackInfo info = new StackInfo();
+        mWindowManager.getStackBounds(stack.mStackId, info.bounds);
+        info.displayId = Display.DEFAULT_DISPLAY;
+        info.stackId = stack.mStackId;
+
+        ArrayList<TaskRecord> tasks = stack.getAllTasks();
+        final int numTasks = tasks.size();
+        int[] taskIds = new int[numTasks];
+        String[] taskNames = new String[numTasks];
+        for (int i = 0; i < numTasks; ++i) {
+            final TaskRecord task = tasks.get(i);
+            taskIds[i] = task.taskId;
+            taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString()
+                    : task.realActivity != null ? task.realActivity.flattenToString()
+                    : task.getTopActivity() != null ? task.getTopActivity().packageName
+                    : "unknown";
+        }
+        info.taskIds = taskIds;
+        info.taskNames = taskNames;
+        return info;
+    }
+
+    StackInfo getStackInfoLocked(int stackId) {
+        ActivityStack stack = getStack(stackId);
+        if (stack != null) {
+            return getStackInfo(stack);
+        }
+        return null;
+    }
+
+    ArrayList<StackInfo> getAllStackInfosLocked() {
+        ArrayList<StackInfo> list = new ArrayList<StackInfo>();
+        for (int displayNdx = 0; displayNdx < mActivityDisplays.size(); ++displayNdx) {
+            ArrayList<ActivityStack> stacks = mActivityDisplays.valueAt(displayNdx).mStacks;
+            for (int ndx = stacks.size() - 1; ndx >= 0; --ndx) {
+                list.add(getStackInfo(stacks.get(ndx)));
+            }
+        }
+        return list;
+    }
+
+    private final class ActivityStackSupervisorHandler extends Handler {
+
+        public ActivityStackSupervisorHandler(Looper looper) {
+            super(looper);
+        }
+
+        void activityIdleInternal(ActivityRecord r) {
+            synchronized (mService) {
+                activityIdleInternalLocked(r != null ? r.appToken : null, true, null);
+            }
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case IDLE_TIMEOUT_MSG: {
+                    if (DEBUG_IDLE) Slog.d(TAG, "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj);
+                    if (mService.mDidDexOpt) {
+                        mService.mDidDexOpt = false;
+                        Message nmsg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG);
+                        nmsg.obj = msg.obj;
+                        mHandler.sendMessageDelayed(nmsg, IDLE_TIMEOUT);
+                        return;
+                    }
+                    // We don't at this point know if the activity is fullscreen,
+                    // so we need to be conservative and assume it isn't.
+                    activityIdleInternal((ActivityRecord)msg.obj);
+                } break;
+                case IDLE_NOW_MSG: {
+                    if (DEBUG_IDLE) Slog.d(TAG, "handleMessage: IDLE_NOW_MSG: r=" + msg.obj);
+                    activityIdleInternal((ActivityRecord)msg.obj);
+                } break;
+                case RESUME_TOP_ACTIVITY_MSG: {
+                    synchronized (mService) {
+                        resumeTopActivitiesLocked();
+                    }
+                } break;
+                case SLEEP_TIMEOUT_MSG: {
+                    synchronized (mService) {
+                        if (mService.isSleepingOrShuttingDown()) {
+                            Slog.w(TAG, "Sleep timeout!  Sleeping now.");
+                            mSleepTimeout = true;
+                            checkReadyForSleepLocked();
+                        }
+                    }
+                } break;
+                case LAUNCH_TIMEOUT_MSG: {
+                    if (mService.mDidDexOpt) {
+                        mService.mDidDexOpt = false;
+                        mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT);
+                        return;
+                    }
+                    synchronized (mService) {
+                        if (mLaunchingActivity.isHeld()) {
+                            Slog.w(TAG, "Launch timeout has expired, giving up wake lock!");
+                            if (VALIDATE_WAKE_LOCK_CALLER
+                                    && Binder.getCallingUid() != Process.myUid()) {
+                                throw new IllegalStateException("Calling must be system uid");
+                            }
+                            mLaunchingActivity.release();
+                        }
+                    }
+                } break;
+                case HANDLE_DISPLAY_ADDED: {
+                    handleDisplayAddedLocked(msg.arg1);
+                } break;
+                case HANDLE_DISPLAY_CHANGED: {
+                    handleDisplayChangedLocked(msg.arg1);
+                } break;
+                case HANDLE_DISPLAY_REMOVED: {
+                    handleDisplayRemovedLocked(msg.arg1);
+                } break;
+            }
+        }
+    }
+
+    class ActivityContainer extends IActivityContainer.Stub {
+        final int mStackId;
+        final IActivityContainerCallback mCallback;
+        final ActivityStack mStack;
+        final ActivityRecord mParentActivity;
+        final String mIdString;
+
+        /** Display this ActivityStack is currently on. Null if not attached to a Display. */
+        ActivityDisplay mActivityDisplay;
+
+        ActivityContainer(ActivityRecord parentActivity, int stackId,
+                IActivityContainerCallback callback) {
+            synchronized (mService) {
+                mStackId = stackId;
+                mStack = new ActivityStack(this);
+                mParentActivity = parentActivity;
+                mCallback = callback;
+                mIdString = "ActivtyContainer{" + mStackId + ", parent=" + mParentActivity + "}";
+                if (DEBUG_STACK) Slog.d(TAG, "Creating " + this);
+            }
+        }
+
+        void attachToDisplayLocked(ActivityDisplay activityDisplay) {
+            if (DEBUG_STACK) Slog.d(TAG, "attachToDisplayLocked: " + this
+                    + " to display=" + activityDisplay);
+            mActivityDisplay = activityDisplay;
+            mStack.mDisplayId = activityDisplay.mDisplayId;
+            mStack.mStacks = activityDisplay.mStacks;
+
+            activityDisplay.attachActivities(mStack);
+            mWindowManager.attachStack(mStackId, activityDisplay.mDisplayId);
+        }
+
+        @Override
+        public void attachToDisplay(int displayId) {
+            synchronized (mService) {
+                ActivityDisplay activityDisplay = mActivityDisplays.get(displayId);
+                if (activityDisplay == null) {
+                    return;
+                }
+                attachToDisplayLocked(activityDisplay);
+            }
+        }
+
+        @Override
+        public int getDisplayId() {
+            if (mActivityDisplay != null) {
+                return mActivityDisplay.mDisplayId;
+            }
+            return -1;
+        }
+
+        @Override
+        public boolean injectEvent(InputEvent event) {
+            final long origId = Binder.clearCallingIdentity();
+            try {
+                if (mActivityDisplay != null) {
+                    return mInputManagerInternal.injectInputEvent(event,
+                            mActivityDisplay.mDisplayId,
+                            InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
+                }
+                return false;
+            } finally {
+                Binder.restoreCallingIdentity(origId);
+            }
+        }
+
+        private void detachLocked() {
+            if (DEBUG_STACK) Slog.d(TAG, "detachLocked: " + this + " from display="
+                    + mActivityDisplay + " Callers=" + Debug.getCallers(2));
+            if (mActivityDisplay != null) {
+                mActivityDisplay.detachActivitiesLocked(mStack);
+                mActivityDisplay = null;
+                mStack.mDisplayId = -1;
+                mStack.mStacks = null;
+                mWindowManager.detachStack(mStackId);
+            }
+        }
+
+        @Override
+        public void detachFromDisplay() {
+            synchronized (mService) {
+                detachLocked();
+            }
+        }
+
+        @Override
+        public final int startActivity(Intent intent) {
+            mService.enforceNotIsolatedCaller("ActivityContainer.startActivity");
+            int userId = mService.handleIncomingUser(Binder.getCallingPid(),
+                    Binder.getCallingUid(), mCurrentUser, false, true, "ActivityContainer", null);
+            // TODO: Switch to user app stacks here.
+            String mimeType = intent.getType();
+            if (mimeType == null && intent.getData() != null
+                    && "content".equals(intent.getData().getScheme())) {
+                mimeType = mService.getProviderMimeType(intent.getData(), userId);
+            }
+            return startActivityMayWait(null, -1, null, intent, mimeType, null, null, 0, 0, null,
+                    null, null, null, null, userId, this);
+        }
+
+        @Override
+        public final int startActivityIntentSender(IIntentSender intentSender) {
+            mService.enforceNotIsolatedCaller("ActivityContainer.startActivityIntentSender");
+
+            if (!(intentSender instanceof PendingIntentRecord)) {
+                throw new IllegalArgumentException("Bad PendingIntent object");
+            }
+
+            return ((PendingIntentRecord)intentSender).sendInner(0, null, null, null, null, null,
+                    null, 0, 0, 0, null, this);
+        }
+
+        @Override
+        public IBinder asBinder() {
+            return this;
+        }
+
+        @Override
+        public void attachToSurface(Surface surface, int width, int height, int density) {
+            mService.enforceNotIsolatedCaller("ActivityContainer.attachToSurface");
+
+            final long origId = Binder.clearCallingIdentity();
+            try {
+                synchronized (mService) {
+                    ActivityDisplay activityDisplay =
+                            new ActivityDisplay(surface, width, height, density);
+                    mActivityDisplays.put(activityDisplay.mDisplayId, activityDisplay);
+                    attachToDisplayLocked(activityDisplay);
+                    mStack.resumeTopActivityLocked(null);
+                }
+                if (DEBUG_STACK) Slog.d(TAG, "attachToSurface: " + this + " to display="
+                        + mActivityDisplay);
+            } finally {
+                Binder.restoreCallingIdentity(origId);
+            }
+        }
+
+        ActivityStackSupervisor getOuter() {
+            return ActivityStackSupervisor.this;
+        }
+
+        boolean isAttached() {
+            return mActivityDisplay != null;
+        }
+
+        void getBounds(Point outBounds) {
+            if (mActivityDisplay != null) {
+                mActivityDisplay.getBounds(outBounds);
+            } else {
+                outBounds.set(0, 0);
+            }
+        }
+
+        @Override
+        public String toString() {
+            return mIdString + (mActivityDisplay == null ? "N" : "A");
+        }
+    }
+
+    /** Exactly one of these classes per Display in the system. Capable of holding zero or more
+     * attached {@link ActivityStack}s */
+    final class ActivityDisplay {
+        /** Actual Display this object tracks. */
+        int mDisplayId;
+        Display mDisplay;
+        DisplayInfo mDisplayInfo = new DisplayInfo();
+        Surface mSurface;
+
+        /** All of the stacks on this display. Order matters, topmost stack is in front of all other
+         * stacks, bottommost behind. Accessed directly by ActivityManager package classes */
+        final ArrayList<ActivityStack> mStacks = new ArrayList<ActivityStack>();
+
+        /** If this display is for an ActivityView then the VirtualDisplay created for it is stored
+         * here. */
+        VirtualDisplay mVirtualDisplay;
+
+        ActivityDisplay(int displayId) {
+            init(mDisplayManager.getDisplay(displayId));
+        }
+
+        ActivityDisplay(Surface surface, int width, int height, int density) {
+            DisplayManagerGlobal dm = DisplayManagerGlobal.getInstance();
+            long ident = Binder.clearCallingIdentity();
+            try {
+                mVirtualDisplay = dm.createVirtualDisplay(mService.mContext,
+                        VIRTUAL_DISPLAY_BASE_NAME, width, height, density, surface,
+                        DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC |
+                        DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+
+            init(mVirtualDisplay.getDisplay());
+            mSurface = surface;
+
+            mWindowManager.handleDisplayAdded(mDisplayId);
+        }
+
+        private void init(Display display) {
+            mDisplay = display;
+            mDisplayId = display.getDisplayId();
+            mDisplay.getDisplayInfo(mDisplayInfo);
+        }
+
+        void attachActivities(ActivityStack stack) {
+            if (DEBUG_STACK) Slog.v(TAG, "attachActivities: attaching " + stack + " to displayId="
+                    + mDisplayId);
+            mStacks.add(stack);
+        }
+
+        void detachActivitiesLocked(ActivityStack stack) {
+            if (DEBUG_STACK) Slog.v(TAG, "detachActivitiesLocked: detaching " + stack
+                    + " from displayId=" + mDisplayId);
+            mStacks.remove(stack);
+            if (mStacks.isEmpty() && mVirtualDisplay != null) {
+                mVirtualDisplay.release();
+                mVirtualDisplay = null;
+            }
+            mSurface.release();
+        }
+
+        void getBounds(Point bounds) {
+            mDisplay.getDisplayInfo(mDisplayInfo);
+            bounds.x = mDisplayInfo.appWidth;
+            bounds.y = mDisplayInfo.appHeight;
+        }
+
+        @Override
+        public String toString() {
+            return "ActivityDisplay={" + mDisplayId + (mVirtualDisplay == null ? "" : "V")
+                    + " numStacks=" + mStacks.size() + "}";
+        }
+    }
+}
diff --git a/services/java/com/android/server/am/AppBindRecord.java b/services/core/java/com/android/server/am/AppBindRecord.java
similarity index 100%
rename from services/java/com/android/server/am/AppBindRecord.java
rename to services/core/java/com/android/server/am/AppBindRecord.java
diff --git a/services/java/com/android/server/am/AppErrorDialog.java b/services/core/java/com/android/server/am/AppErrorDialog.java
similarity index 100%
rename from services/java/com/android/server/am/AppErrorDialog.java
rename to services/core/java/com/android/server/am/AppErrorDialog.java
diff --git a/services/java/com/android/server/am/AppErrorResult.java b/services/core/java/com/android/server/am/AppErrorResult.java
similarity index 100%
rename from services/java/com/android/server/am/AppErrorResult.java
rename to services/core/java/com/android/server/am/AppErrorResult.java
diff --git a/services/java/com/android/server/am/AppNotRespondingDialog.java b/services/core/java/com/android/server/am/AppNotRespondingDialog.java
similarity index 100%
rename from services/java/com/android/server/am/AppNotRespondingDialog.java
rename to services/core/java/com/android/server/am/AppNotRespondingDialog.java
diff --git a/services/java/com/android/server/am/AppWaitingForDebuggerDialog.java b/services/core/java/com/android/server/am/AppWaitingForDebuggerDialog.java
similarity index 100%
rename from services/java/com/android/server/am/AppWaitingForDebuggerDialog.java
rename to services/core/java/com/android/server/am/AppWaitingForDebuggerDialog.java
diff --git a/services/java/com/android/server/am/BackupRecord.java b/services/core/java/com/android/server/am/BackupRecord.java
similarity index 100%
rename from services/java/com/android/server/am/BackupRecord.java
rename to services/core/java/com/android/server/am/BackupRecord.java
diff --git a/services/java/com/android/server/am/BaseErrorDialog.java b/services/core/java/com/android/server/am/BaseErrorDialog.java
similarity index 100%
rename from services/java/com/android/server/am/BaseErrorDialog.java
rename to services/core/java/com/android/server/am/BaseErrorDialog.java
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
new file mode 100644
index 0000000..ff06513
--- /dev/null
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -0,0 +1,580 @@
+/*
+ * Copyright (C) 2006-2007 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.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothHeadset;
+import android.bluetooth.BluetoothProfile;
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.BatteryStats;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Process;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.os.WorkSource;
+import android.telephony.SignalStrength;
+import android.telephony.TelephonyManager;
+import android.util.Slog;
+
+import com.android.internal.app.IBatteryStats;
+import com.android.internal.os.BatteryStatsImpl;
+import com.android.internal.os.PowerProfile;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.List;
+
+/**
+ * All information we are collecting about things that can happen that impact
+ * battery life.
+ */
+public final class BatteryStatsService extends IBatteryStats.Stub {
+    static IBatteryStats sService;
+    
+    final BatteryStatsImpl mStats;
+    Context mContext;
+    private boolean mBluetoothPendingStats;
+    private BluetoothHeadset mBluetoothHeadset;
+
+    BatteryStatsService(String filename, Handler handler) {
+        mStats = new BatteryStatsImpl(filename, handler);
+    }
+    
+    public void publish(Context context) {
+        mContext = context;
+        ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());
+        mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
+        mStats.setRadioScanningTimeout(mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_radioScanningTimeout)
+                * 1000L);
+    }
+    
+    public void shutdown() {
+        Slog.w("BatteryStats", "Writing battery stats before shutdown...");
+        synchronized (mStats) {
+            mStats.shutdownLocked();
+        }
+    }
+    
+    public static IBatteryStats getService() {
+        if (sService != null) {
+            return sService;
+        }
+        IBinder b = ServiceManager.getService(BatteryStats.SERVICE_NAME);
+        sService = asInterface(b);
+        return sService;
+    }
+    
+    /**
+     * @return the current statistics object, which may be modified
+     * to reflect events that affect battery usage.  You must lock the
+     * stats object before doing anything with it.
+     */
+    public BatteryStatsImpl getActiveStatistics() {
+        return mStats;
+    }
+    
+    public byte[] getStatistics() {
+        mContext.enforceCallingPermission(
+                android.Manifest.permission.BATTERY_STATS, null);
+        //Slog.i("foo", "SENDING BATTERY INFO:");
+        //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
+        Parcel out = Parcel.obtain();
+        mStats.writeToParcel(out, 0);
+        byte[] data = out.marshall();
+        out.recycle();
+        return data;
+    }
+    
+    public void noteStartWakelock(int uid, int pid, String name, int type) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStartWakeLocked(uid, pid, name, type);
+        }
+    }
+
+    public void noteStopWakelock(int uid, int pid, String name, int type) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStopWakeLocked(uid, pid, name, type);
+        }
+    }
+
+    public void noteStartWakelockFromSource(WorkSource ws, int pid, String name, int type) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStartWakeFromSourceLocked(ws, pid, name, type);
+        }
+    }
+
+    public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, int type) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStopWakeFromSourceLocked(ws, pid, name, type);
+        }
+    }
+
+    public void noteStartSensor(int uid, int sensor) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStartSensorLocked(uid, sensor);
+        }
+    }
+    
+    public void noteStopSensor(int uid, int sensor) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStopSensorLocked(uid, sensor);
+        }
+    }
+    
+    public void noteVibratorOn(int uid, long durationMillis) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteVibratorOnLocked(uid, durationMillis);
+        }
+    }
+
+    public void noteVibratorOff(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteVibratorOffLocked(uid);
+        }
+    }
+
+    public void noteStartGps(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStartGpsLocked(uid);
+        }
+    }
+    
+    public void noteStopGps(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteStopGpsLocked(uid);
+        }
+    }
+        
+    public void noteScreenOn() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteScreenOnLocked();
+        }
+    }
+    
+    public void noteScreenBrightness(int brightness) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteScreenBrightnessLocked(brightness);
+        }
+    }
+    
+    public void noteScreenOff() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteScreenOffLocked();
+        }
+    }
+
+    public void noteInputEvent() {
+        enforceCallingPermission();
+        mStats.noteInputEventAtomic();
+    }
+    
+    public void noteUserActivity(int uid, int event) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteUserActivityLocked(uid, event);
+        }
+    }
+    
+    public void notePhoneOn() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.notePhoneOnLocked();
+        }
+    }
+    
+    public void notePhoneOff() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.notePhoneOffLocked();
+        }
+    }
+    
+    public void notePhoneSignalStrength(SignalStrength signalStrength) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.notePhoneSignalStrengthLocked(signalStrength);
+        }
+    }
+    
+    public void notePhoneDataConnectionState(int dataType, boolean hasData) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
+        }
+    }
+
+    public void notePhoneState(int state) {
+        enforceCallingPermission();
+        int simState = TelephonyManager.getDefault().getSimState();
+        synchronized (mStats) {
+            mStats.notePhoneStateLocked(state, simState);
+        }
+    }
+
+    public void noteWifiOn() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiOnLocked();
+        }
+    }
+    
+    public void noteWifiOff() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiOffLocked();
+        }
+    }
+
+    public void noteStartAudio(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteAudioOnLocked(uid);
+        }
+    }
+
+    public void noteStopAudio(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteAudioOffLocked(uid);
+        }
+    }
+
+    public void noteStartVideo(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteVideoOnLocked(uid);
+        }
+    }
+
+    public void noteStopVideo(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteVideoOffLocked(uid);
+        }
+    }
+
+    public void noteWifiRunning(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiRunningLocked(ws);
+        }
+    }
+
+    public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiRunningChangedLocked(oldWs, newWs);
+        }
+    }
+
+    public void noteWifiStopped(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiStoppedLocked(ws);
+        }
+    }
+
+    public void noteBluetoothOn() {
+        enforceCallingPermission();
+        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+        if (adapter != null) {
+            adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
+                                    BluetoothProfile.HEADSET);
+        }
+        synchronized (mStats) {
+            if (mBluetoothHeadset != null) {
+                mStats.noteBluetoothOnLocked();
+                mStats.setBtHeadset(mBluetoothHeadset);
+            } else {
+                mBluetoothPendingStats = true;
+            }
+        }
+    }
+
+    private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
+        new BluetoothProfile.ServiceListener() {
+        public void onServiceConnected(int profile, BluetoothProfile proxy) {
+            mBluetoothHeadset = (BluetoothHeadset) proxy;
+            synchronized (mStats) {
+                if (mBluetoothPendingStats) {
+                    mStats.noteBluetoothOnLocked();
+                    mStats.setBtHeadset(mBluetoothHeadset);
+                    mBluetoothPendingStats = false;
+                }
+            }
+        }
+
+        public void onServiceDisconnected(int profile) {
+            mBluetoothHeadset = null;
+        }
+    };
+
+    public void noteBluetoothOff() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mBluetoothPendingStats = false;
+            mStats.noteBluetoothOffLocked();
+        }
+    }
+    
+    public void noteFullWifiLockAcquired(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteFullWifiLockAcquiredLocked(uid);
+        }
+    }
+    
+    public void noteFullWifiLockReleased(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteFullWifiLockReleasedLocked(uid);
+        }
+    }
+
+    public void noteWifiScanStarted(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiScanStartedLocked(uid);
+        }
+    }
+
+    public void noteWifiScanStopped(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiScanStoppedLocked(uid);
+        }
+    }
+
+    public void noteWifiMulticastEnabled(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiMulticastEnabledLocked(uid);
+        }
+    }
+
+    public void noteWifiMulticastDisabled(int uid) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiMulticastDisabledLocked(uid);
+        }
+    }
+
+    public void noteFullWifiLockAcquiredFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteFullWifiLockAcquiredFromSourceLocked(ws);
+        }
+    }
+
+    public void noteFullWifiLockReleasedFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteFullWifiLockReleasedFromSourceLocked(ws);
+        }
+    }
+
+    public void noteWifiScanStartedFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiScanStartedFromSourceLocked(ws);
+        }
+    }
+
+    public void noteWifiScanStoppedFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiScanStoppedFromSourceLocked(ws);
+        }
+    }
+
+    public void noteWifiBatchedScanStartedFromSource(WorkSource ws, int csph) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiBatchedScanStartedFromSourceLocked(ws, csph);
+        }
+    }
+
+    public void noteWifiBatchedScanStoppedFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiBatchedScanStoppedFromSourceLocked(ws);
+        }
+    }
+
+    public void noteWifiMulticastEnabledFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiMulticastEnabledFromSourceLocked(ws);
+        }
+    }
+
+    public void noteWifiMulticastDisabledFromSource(WorkSource ws) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteWifiMulticastDisabledFromSourceLocked(ws);
+        }
+    }
+
+    @Override
+    public void noteNetworkInterfaceType(String iface, int type) {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteNetworkInterfaceTypeLocked(iface, type);
+        }
+    }
+
+    @Override
+    public void noteNetworkStatsEnabled() {
+        enforceCallingPermission();
+        synchronized (mStats) {
+            mStats.noteNetworkStatsEnabledLocked();
+        }
+    }
+
+    public boolean isOnBattery() {
+        return mStats.isOnBattery();
+    }
+    
+    public void setBatteryState(int status, int health, int plugType, int level,
+            int temp, int volt) {
+        enforceCallingPermission();
+        mStats.setBatteryState(status, health, plugType, level, temp, volt);
+    }
+    
+    public long getAwakeTimeBattery() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.BATTERY_STATS, null);
+        return mStats.getAwakeTimeBattery();
+    }
+
+    public long getAwakeTimePlugged() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.BATTERY_STATS, null);
+        return mStats.getAwakeTimePlugged();
+    }
+
+    public void enforceCallingPermission() {
+        if (Binder.getCallingPid() == Process.myPid()) {
+            return;
+        }
+        mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+    }
+    
+    private void dumpHelp(PrintWriter pw) {
+        pw.println("Battery stats (batterystats) dump options:");
+        pw.println("  [--checkin] [-c] [--unplugged] [--reset] [--write] [-h] [<package.name>]");
+        pw.println("  --checkin: format output for a checkin report.");
+        pw.println("  --unplugged: only output data since last unplugged.");
+        pw.println("  --reset: reset the stats, clearing all current data.");
+        pw.println("  --write: force write current collected stats to disk.");
+        pw.println("  -h: print this help text.");
+        pw.println("  <package.name>: optional name of package to filter output by.");
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump BatteryStats from from pid="
+                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                    + " without permission " + android.Manifest.permission.DUMP);
+            return;
+        }
+
+        boolean isCheckin = false;
+        boolean includeHistory = false;
+        boolean isUnpluggedOnly = false;
+        boolean noOutput = false;
+        int reqUid = -1;
+        if (args != null) {
+            for (String arg : args) {
+                if ("--checkin".equals(arg)) {
+                    isCheckin = true;
+                } else if ("-c".equals(arg)) {
+                    isCheckin = true;
+                    includeHistory = true;
+                } else if ("--unplugged".equals(arg)) {
+                    isUnpluggedOnly = true;
+                } else if ("--reset".equals(arg)) {
+                    synchronized (mStats) {
+                        mStats.resetAllStatsLocked();
+                        pw.println("Battery stats reset.");
+                        noOutput = true;
+                    }
+                } else if ("--write".equals(arg)) {
+                    synchronized (mStats) {
+                        mStats.writeSyncLocked();
+                        pw.println("Battery stats written.");
+                        noOutput = true;
+                    }
+                } else if ("-h".equals(arg)) {
+                    dumpHelp(pw);
+                    return;
+                } else if ("-a".equals(arg)) {
+                    // fall through
+                } else if (arg.length() > 0 && arg.charAt(0) == '-'){
+                    pw.println("Unknown option: " + arg);
+                    dumpHelp(pw);
+                    return;
+                } else {
+                    // Not an option, last argument must be a package name.
+                    try {
+                        reqUid = mContext.getPackageManager().getPackageUid(arg,
+                                UserHandle.getCallingUserId());
+                    } catch (PackageManager.NameNotFoundException e) {
+                        pw.println("Unknown package: " + arg);
+                        dumpHelp(pw);
+                        return;
+                    }
+                }
+            }
+        }
+        if (noOutput) {
+            return;
+        }
+        if (isCheckin) {
+            List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
+            synchronized (mStats) {
+                mStats.dumpCheckinLocked(pw, apps, isUnpluggedOnly, includeHistory);
+            }
+        } else {
+            synchronized (mStats) {
+                mStats.dumpLocked(pw, isUnpluggedOnly, reqUid);
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/am/BroadcastFilter.java b/services/core/java/com/android/server/am/BroadcastFilter.java
similarity index 100%
rename from services/java/com/android/server/am/BroadcastFilter.java
rename to services/core/java/com/android/server/am/BroadcastFilter.java
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
new file mode 100644
index 0000000..aef9e5c
--- /dev/null
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -0,0 +1,1228 @@
+/*
+ * 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.server.am;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+import android.app.ActivityManager;
+import android.app.AppGlobals;
+import android.app.AppOpsManager;
+import android.content.ComponentName;
+import android.content.IIntentReceiver;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Slog;
+
+/**
+ * BROADCASTS
+ *
+ * We keep two broadcast queues and associated bookkeeping, one for those at
+ * foreground priority, and one for normal (background-priority) broadcasts.
+ */
+public final class BroadcastQueue {
+    static final String TAG = "BroadcastQueue";
+    static final String TAG_MU = ActivityManagerService.TAG_MU;
+    static final boolean DEBUG_BROADCAST = ActivityManagerService.DEBUG_BROADCAST;
+    static final boolean DEBUG_BROADCAST_LIGHT = ActivityManagerService.DEBUG_BROADCAST_LIGHT;
+    static final boolean DEBUG_MU = ActivityManagerService.DEBUG_MU;
+
+    static final int MAX_BROADCAST_HISTORY = ActivityManager.isLowRamDeviceStatic() ? 10 : 50;
+    static final int MAX_BROADCAST_SUMMARY_HISTORY
+            = ActivityManager.isLowRamDeviceStatic() ? 25 : 300;
+
+    final ActivityManagerService mService;
+
+    /**
+     * Recognizable moniker for this queue
+     */
+    final String mQueueName;
+
+    /**
+     * Timeout period for this queue's broadcasts
+     */
+    final long mTimeoutPeriod;
+
+    /**
+     * If true, we can delay broadcasts while waiting services to finish in the previous
+     * receiver's process.
+     */
+    final boolean mDelayBehindServices;
+
+    /**
+     * Lists of all active broadcasts that are to be executed immediately
+     * (without waiting for another broadcast to finish).  Currently this only
+     * contains broadcasts to registered receivers, to avoid spinning up
+     * a bunch of processes to execute IntentReceiver components.  Background-
+     * and foreground-priority broadcasts are queued separately.
+     */
+    final ArrayList<BroadcastRecord> mParallelBroadcasts = new ArrayList<BroadcastRecord>();
+
+    /**
+     * List of all active broadcasts that are to be executed one at a time.
+     * The object at the top of the list is the currently activity broadcasts;
+     * those after it are waiting for the top to finish.  As with parallel
+     * broadcasts, separate background- and foreground-priority queues are
+     * maintained.
+     */
+    final ArrayList<BroadcastRecord> mOrderedBroadcasts = new ArrayList<BroadcastRecord>();
+
+    /**
+     * Historical data of past broadcasts, for debugging.
+     */
+    final BroadcastRecord[] mBroadcastHistory = new BroadcastRecord[MAX_BROADCAST_HISTORY];
+
+    /**
+     * Summary of historical data of past broadcasts, for debugging.
+     */
+    final Intent[] mBroadcastSummaryHistory = new Intent[MAX_BROADCAST_SUMMARY_HISTORY];
+
+    /**
+     * Set when we current have a BROADCAST_INTENT_MSG in flight.
+     */
+    boolean mBroadcastsScheduled = false;
+
+    /**
+     * True if we have a pending unexpired BROADCAST_TIMEOUT_MSG posted to our handler.
+     */
+    boolean mPendingBroadcastTimeoutMessage;
+
+    /**
+     * Intent broadcasts that we have tried to start, but are
+     * waiting for the application's process to be created.  We only
+     * need one per scheduling class (instead of a list) because we always
+     * process broadcasts one at a time, so no others can be started while
+     * waiting for this one.
+     */
+    BroadcastRecord mPendingBroadcast = null;
+
+    /**
+     * The receiver index that is pending, to restart the broadcast if needed.
+     */
+    int mPendingBroadcastRecvIndex;
+
+    static final int BROADCAST_INTENT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG;
+    static final int BROADCAST_TIMEOUT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG + 1;
+
+    final BroadcastHandler mHandler;
+
+    private final class BroadcastHandler extends Handler {
+        public BroadcastHandler(Looper looper) {
+            super(looper, null, true);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case BROADCAST_INTENT_MSG: {
+                    if (DEBUG_BROADCAST) Slog.v(
+                            TAG, "Received BROADCAST_INTENT_MSG");
+                    processNextBroadcast(true);
+                } break;
+                case BROADCAST_TIMEOUT_MSG: {
+                    synchronized (mService) {
+                        broadcastTimeoutLocked(true);
+                    }
+                } break;
+            }
+        }
+    };
+
+    private final class AppNotResponding implements Runnable {
+        private final ProcessRecord mApp;
+        private final String mAnnotation;
+
+        public AppNotResponding(ProcessRecord app, String annotation) {
+            mApp = app;
+            mAnnotation = annotation;
+        }
+
+        @Override
+        public void run() {
+            mService.appNotResponding(mApp, null, null, false, mAnnotation);
+        }
+    }
+
+    BroadcastQueue(ActivityManagerService service, Handler handler,
+            String name, long timeoutPeriod, boolean allowDelayBehindServices) {
+        mService = service;
+        mHandler = new BroadcastHandler(handler.getLooper());
+        mQueueName = name;
+        mTimeoutPeriod = timeoutPeriod;
+        mDelayBehindServices = allowDelayBehindServices;
+    }
+
+    public boolean isPendingBroadcastProcessLocked(int pid) {
+        return mPendingBroadcast != null && mPendingBroadcast.curApp.pid == pid;
+    }
+
+    public void enqueueParallelBroadcastLocked(BroadcastRecord r) {
+        mParallelBroadcasts.add(r);
+    }
+
+    public void enqueueOrderedBroadcastLocked(BroadcastRecord r) {
+        mOrderedBroadcasts.add(r);
+    }
+
+    public final boolean replaceParallelBroadcastLocked(BroadcastRecord r) {
+        for (int i=mParallelBroadcasts.size()-1; i>=0; i--) {
+            if (r.intent.filterEquals(mParallelBroadcasts.get(i).intent)) {
+                if (DEBUG_BROADCAST) Slog.v(TAG,
+                        "***** DROPPING PARALLEL ["
+                + mQueueName + "]: " + r.intent);
+                mParallelBroadcasts.set(i, r);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public final boolean replaceOrderedBroadcastLocked(BroadcastRecord r) {
+        for (int i=mOrderedBroadcasts.size()-1; i>0; i--) {
+            if (r.intent.filterEquals(mOrderedBroadcasts.get(i).intent)) {
+                if (DEBUG_BROADCAST) Slog.v(TAG,
+                        "***** DROPPING ORDERED ["
+                        + mQueueName + "]: " + r.intent);
+                mOrderedBroadcasts.set(i, r);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private final void processCurBroadcastLocked(BroadcastRecord r,
+            ProcessRecord app) throws RemoteException {
+        if (DEBUG_BROADCAST)  Slog.v(TAG,
+                "Process cur broadcast " + r + " for app " + app);
+        if (app.thread == null) {
+            throw new RemoteException();
+        }
+        r.receiver = app.thread.asBinder();
+        r.curApp = app;
+        app.curReceiver = r;
+        app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER);
+        mService.updateLruProcessLocked(app, false, null);
+        mService.updateOomAdjLocked();
+
+        // Tell the application to launch this receiver.
+        r.intent.setComponent(r.curComponent);
+
+        boolean started = false;
+        try {
+            if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG,
+                    "Delivering to component " + r.curComponent
+                    + ": " + r);
+            mService.ensurePackageDexOpt(r.intent.getComponent().getPackageName());
+            app.thread.scheduleReceiver(new Intent(r.intent), r.curReceiver,
+                    mService.compatibilityInfoForPackageLocked(r.curReceiver.applicationInfo),
+                    r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId,
+                    app.repProcState);
+            if (DEBUG_BROADCAST)  Slog.v(TAG,
+                    "Process cur broadcast " + r + " DELIVERED for app " + app);
+            started = true;
+        } finally {
+            if (!started) {
+                if (DEBUG_BROADCAST)  Slog.v(TAG,
+                        "Process cur broadcast " + r + ": NOT STARTED!");
+                r.receiver = null;
+                r.curApp = null;
+                app.curReceiver = null;
+            }
+        }
+    }
+
+    public boolean sendPendingBroadcastsLocked(ProcessRecord app) {
+        boolean didSomething = false;
+        final BroadcastRecord br = mPendingBroadcast;
+        if (br != null && br.curApp.pid == app.pid) {
+            try {
+                mPendingBroadcast = null;
+                processCurBroadcastLocked(br, app);
+                didSomething = true;
+            } catch (Exception e) {
+                Slog.w(TAG, "Exception in new application when starting receiver "
+                        + br.curComponent.flattenToShortString(), e);
+                logBroadcastReceiverDiscardLocked(br);
+                finishReceiverLocked(br, br.resultCode, br.resultData,
+                        br.resultExtras, br.resultAbort, false);
+                scheduleBroadcastsLocked();
+                // We need to reset the state if we failed to start the receiver.
+                br.state = BroadcastRecord.IDLE;
+                throw new RuntimeException(e.getMessage());
+            }
+        }
+        return didSomething;
+    }
+
+    public void skipPendingBroadcastLocked(int pid) {
+        final BroadcastRecord br = mPendingBroadcast;
+        if (br != null && br.curApp.pid == pid) {
+            br.state = BroadcastRecord.IDLE;
+            br.nextReceiver = mPendingBroadcastRecvIndex;
+            mPendingBroadcast = null;
+            scheduleBroadcastsLocked();
+        }
+    }
+
+    public void skipCurrentReceiverLocked(ProcessRecord app) {
+        boolean reschedule = false;
+        BroadcastRecord r = app.curReceiver;
+        if (r != null) {
+            // The current broadcast is waiting for this app's receiver
+            // to be finished.  Looks like that's not going to happen, so
+            // let the broadcast continue.
+            logBroadcastReceiverDiscardLocked(r);
+            finishReceiverLocked(r, r.resultCode, r.resultData,
+                    r.resultExtras, r.resultAbort, false);
+            reschedule = true;
+        }
+
+        r = mPendingBroadcast;
+        if (r != null && r.curApp == app) {
+            if (DEBUG_BROADCAST) Slog.v(TAG,
+                    "[" + mQueueName + "] skip & discard pending app " + r);
+            logBroadcastReceiverDiscardLocked(r);
+            finishReceiverLocked(r, r.resultCode, r.resultData,
+                    r.resultExtras, r.resultAbort, false);
+            reschedule = true;
+        }
+        if (reschedule) {
+            scheduleBroadcastsLocked();
+        }
+    }
+
+    public void scheduleBroadcastsLocked() {
+        if (DEBUG_BROADCAST) Slog.v(TAG, "Schedule broadcasts ["
+                + mQueueName + "]: current="
+                + mBroadcastsScheduled);
+
+        if (mBroadcastsScheduled) {
+            return;
+        }
+        mHandler.sendMessage(mHandler.obtainMessage(BROADCAST_INTENT_MSG, this));
+        mBroadcastsScheduled = true;
+    }
+
+    public BroadcastRecord getMatchingOrderedReceiver(IBinder receiver) {
+        if (mOrderedBroadcasts.size() > 0) {
+            final BroadcastRecord r = mOrderedBroadcasts.get(0);
+            if (r != null && r.receiver == receiver) {
+                return r;
+            }
+        }
+        return null;
+    }
+
+    public boolean finishReceiverLocked(BroadcastRecord r, int resultCode,
+            String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices) {
+        final int state = r.state;
+        final ActivityInfo receiver = r.curReceiver;
+        r.state = BroadcastRecord.IDLE;
+        if (state == BroadcastRecord.IDLE) {
+            Slog.w(TAG, "finishReceiver [" + mQueueName + "] called but state is IDLE");
+        }
+        r.receiver = null;
+        r.intent.setComponent(null);
+        if (r.curApp != null) {
+            r.curApp.curReceiver = null;
+        }
+        if (r.curFilter != null) {
+            r.curFilter.receiverList.curBroadcast = null;
+        }
+        r.curFilter = null;
+        r.curReceiver = null;
+        r.curApp = null;
+        mPendingBroadcast = null;
+
+        r.resultCode = resultCode;
+        r.resultData = resultData;
+        r.resultExtras = resultExtras;
+        if (resultAbort && (r.intent.getFlags()&Intent.FLAG_RECEIVER_NO_ABORT) == 0) {
+            r.resultAbort = resultAbort;
+        } else {
+            r.resultAbort = false;
+        }
+
+        if (waitForServices && r.curComponent != null && r.queue.mDelayBehindServices
+                && r.queue.mOrderedBroadcasts.size() > 0
+                && r.queue.mOrderedBroadcasts.get(0) == r) {
+            ActivityInfo nextReceiver;
+            if (r.nextReceiver < r.receivers.size()) {
+                Object obj = r.receivers.get(r.nextReceiver);
+                nextReceiver = (obj instanceof ActivityInfo) ? (ActivityInfo)obj : null;
+            } else {
+                nextReceiver = null;
+            }
+            // Don't do this if the next receive is in the same process as the current one.
+            if (receiver == null || nextReceiver == null
+                    || receiver.applicationInfo.uid != nextReceiver.applicationInfo.uid
+                    || !receiver.processName.equals(nextReceiver.processName)) {
+                // In this case, we are ready to process the next receiver for the current broadcast,
+                // but are on a queue that would like to wait for services to finish before moving
+                // on.  If there are background services currently starting, then we will go into a
+                // special state where we hold off on continuing this broadcast until they are done.
+                if (mService.mServices.hasBackgroundServices(r.userId)) {
+                    Slog.i(ActivityManagerService.TAG, "Delay finish: "
+                            + r.curComponent.flattenToShortString());
+                    r.state = BroadcastRecord.WAITING_SERVICES;
+                    return false;
+                }
+            }
+        }
+
+        r.curComponent = null;
+
+        // We will process the next receiver right now if this is finishing
+        // an app receiver (which is always asynchronous) or after we have
+        // come back from calling a receiver.
+        return state == BroadcastRecord.APP_RECEIVE
+                || state == BroadcastRecord.CALL_DONE_RECEIVE;
+    }
+
+    public void backgroundServicesFinishedLocked(int userId) {
+        if (mOrderedBroadcasts.size() > 0) {
+            BroadcastRecord br = mOrderedBroadcasts.get(0);
+            if (br.userId == userId && br.state == BroadcastRecord.WAITING_SERVICES) {
+                Slog.i(ActivityManagerService.TAG, "Resuming delayed broadcast");
+                br.curComponent = null;
+                br.state = BroadcastRecord.IDLE;
+                processNextBroadcast(false);
+            }
+        }
+    }
+
+    private static void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver,
+            Intent intent, int resultCode, String data, Bundle extras,
+            boolean ordered, boolean sticky, int sendingUser) throws RemoteException {
+        // Send the intent to the receiver asynchronously using one-way binder calls.
+        if (app != null && app.thread != null) {
+            // If we have an app thread, do the call through that so it is
+            // correctly ordered with other one-way calls.
+            app.thread.scheduleRegisteredReceiver(receiver, intent, resultCode,
+                    data, extras, ordered, sticky, sendingUser, app.repProcState);
+        } else {
+            receiver.performReceive(intent, resultCode, data, extras, ordered,
+                    sticky, sendingUser);
+        }
+    }
+
+    private final void deliverToRegisteredReceiverLocked(BroadcastRecord r,
+            BroadcastFilter filter, boolean ordered) {
+        boolean skip = false;
+        if (filter.requiredPermission != null) {
+            int perm = mService.checkComponentPermission(filter.requiredPermission,
+                    r.callingPid, r.callingUid, -1, true);
+            if (perm != PackageManager.PERMISSION_GRANTED) {
+                Slog.w(TAG, "Permission Denial: broadcasting "
+                        + r.intent.toString()
+                        + " from " + r.callerPackage + " (pid="
+                        + r.callingPid + ", uid=" + r.callingUid + ")"
+                        + " requires " + filter.requiredPermission
+                        + " due to registered receiver " + filter);
+                skip = true;
+            }
+        }
+        if (!skip && r.requiredPermission != null) {
+            int perm = mService.checkComponentPermission(r.requiredPermission,
+                    filter.receiverList.pid, filter.receiverList.uid, -1, true);
+            if (perm != PackageManager.PERMISSION_GRANTED) {
+                Slog.w(TAG, "Permission Denial: receiving "
+                        + r.intent.toString()
+                        + " to " + filter.receiverList.app
+                        + " (pid=" + filter.receiverList.pid
+                        + ", uid=" + filter.receiverList.uid + ")"
+                        + " requires " + r.requiredPermission
+                        + " due to sender " + r.callerPackage
+                        + " (uid " + r.callingUid + ")");
+                skip = true;
+            }
+        }
+        if (r.appOp != AppOpsManager.OP_NONE) {
+            int mode = mService.mAppOpsService.noteOperation(r.appOp,
+                    filter.receiverList.uid, filter.packageName);
+            if (mode != AppOpsManager.MODE_ALLOWED) {
+                if (DEBUG_BROADCAST)  Slog.v(TAG,
+                        "App op " + r.appOp + " not allowed for broadcast to uid "
+                        + filter.receiverList.uid + " pkg " + filter.packageName);
+                skip = true;
+            }
+        }
+        if (!skip) {
+            skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid,
+                    r.callingPid, r.resolvedType, filter.receiverList.uid);
+        }
+
+        if (filter.receiverList.app == null || filter.receiverList.app.crashing) {
+            Slog.w(TAG, "Skipping deliver [" + mQueueName + "] " + r
+                    + " to " + filter.receiverList + ": process crashing");
+            skip = true;
+        }
+
+        if (!skip) {
+            // If this is not being sent as an ordered broadcast, then we
+            // don't want to touch the fields that keep track of the current
+            // state of ordered broadcasts.
+            if (ordered) {
+                r.receiver = filter.receiverList.receiver.asBinder();
+                r.curFilter = filter;
+                filter.receiverList.curBroadcast = r;
+                r.state = BroadcastRecord.CALL_IN_RECEIVE;
+                if (filter.receiverList.app != null) {
+                    // Bump hosting application to no longer be in background
+                    // scheduling class.  Note that we can't do that if there
+                    // isn't an app...  but we can only be in that case for
+                    // things that directly call the IActivityManager API, which
+                    // are already core system stuff so don't matter for this.
+                    r.curApp = filter.receiverList.app;
+                    filter.receiverList.app.curReceiver = r;
+                    mService.updateOomAdjLocked(r.curApp, true);
+                }
+            }
+            try {
+                if (DEBUG_BROADCAST_LIGHT) {
+                    int seq = r.intent.getIntExtra("seq", -1);
+                    Slog.i(TAG, "Delivering to " + filter
+                            + " (seq=" + seq + "): " + r);
+                }
+                performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver,
+                    new Intent(r.intent), r.resultCode, r.resultData,
+                    r.resultExtras, r.ordered, r.initialSticky, r.userId);
+                if (ordered) {
+                    r.state = BroadcastRecord.CALL_DONE_RECEIVE;
+                }
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Failure sending broadcast " + r.intent, e);
+                if (ordered) {
+                    r.receiver = null;
+                    r.curFilter = null;
+                    filter.receiverList.curBroadcast = null;
+                    if (filter.receiverList.app != null) {
+                        filter.receiverList.app.curReceiver = null;
+                    }
+                }
+            }
+        }
+    }
+
+    final void processNextBroadcast(boolean fromMsg) {
+        synchronized(mService) {
+            BroadcastRecord r;
+
+            if (DEBUG_BROADCAST) Slog.v(TAG, "processNextBroadcast ["
+                    + mQueueName + "]: "
+                    + mParallelBroadcasts.size() + " broadcasts, "
+                    + mOrderedBroadcasts.size() + " ordered broadcasts");
+
+            mService.updateCpuStats();
+
+            if (fromMsg) {
+                mBroadcastsScheduled = false;
+            }
+
+            // First, deliver any non-serialized broadcasts right away.
+            while (mParallelBroadcasts.size() > 0) {
+                r = mParallelBroadcasts.remove(0);
+                r.dispatchTime = SystemClock.uptimeMillis();
+                r.dispatchClockTime = System.currentTimeMillis();
+                final int N = r.receivers.size();
+                if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing parallel broadcast ["
+                        + mQueueName + "] " + r);
+                for (int i=0; i<N; i++) {
+                    Object target = r.receivers.get(i);
+                    if (DEBUG_BROADCAST)  Slog.v(TAG,
+                            "Delivering non-ordered on [" + mQueueName + "] to registered "
+                            + target + ": " + r);
+                    deliverToRegisteredReceiverLocked(r, (BroadcastFilter)target, false);
+                }
+                addBroadcastToHistoryLocked(r);
+                if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Done with parallel broadcast ["
+                        + mQueueName + "] " + r);
+            }
+
+            // Now take care of the next serialized one...
+
+            // If we are waiting for a process to come up to handle the next
+            // broadcast, then do nothing at this point.  Just in case, we
+            // check that the process we're waiting for still exists.
+            if (mPendingBroadcast != null) {
+                if (DEBUG_BROADCAST_LIGHT) {
+                    Slog.v(TAG, "processNextBroadcast ["
+                            + mQueueName + "]: waiting for "
+                            + mPendingBroadcast.curApp);
+                }
+
+                boolean isDead;
+                synchronized (mService.mPidsSelfLocked) {
+                    ProcessRecord proc = mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid);
+                    isDead = proc == null || proc.crashing;
+                }
+                if (!isDead) {
+                    // It's still alive, so keep waiting
+                    return;
+                } else {
+                    Slog.w(TAG, "pending app  ["
+                            + mQueueName + "]" + mPendingBroadcast.curApp
+                            + " died before responding to broadcast");
+                    mPendingBroadcast.state = BroadcastRecord.IDLE;
+                    mPendingBroadcast.nextReceiver = mPendingBroadcastRecvIndex;
+                    mPendingBroadcast = null;
+                }
+            }
+
+            boolean looped = false;
+            
+            do {
+                if (mOrderedBroadcasts.size() == 0) {
+                    // No more broadcasts pending, so all done!
+                    mService.scheduleAppGcsLocked();
+                    if (looped) {
+                        // If we had finished the last ordered broadcast, then
+                        // make sure all processes have correct oom and sched
+                        // adjustments.
+                        mService.updateOomAdjLocked();
+                    }
+                    return;
+                }
+                r = mOrderedBroadcasts.get(0);
+                boolean forceReceive = false;
+
+                // Ensure that even if something goes awry with the timeout
+                // detection, we catch "hung" broadcasts here, discard them,
+                // and continue to make progress.
+                //
+                // This is only done if the system is ready so that PRE_BOOT_COMPLETED
+                // receivers don't get executed with timeouts. They're intended for
+                // one time heavy lifting after system upgrades and can take
+                // significant amounts of time.
+                int numReceivers = (r.receivers != null) ? r.receivers.size() : 0;
+                if (mService.mProcessesReady && r.dispatchTime > 0) {
+                    long now = SystemClock.uptimeMillis();
+                    if ((numReceivers > 0) &&
+                            (now > r.dispatchTime + (2*mTimeoutPeriod*numReceivers))) {
+                        Slog.w(TAG, "Hung broadcast ["
+                                + mQueueName + "] discarded after timeout failure:"
+                                + " now=" + now
+                                + " dispatchTime=" + r.dispatchTime
+                                + " startTime=" + r.receiverTime
+                                + " intent=" + r.intent
+                                + " numReceivers=" + numReceivers
+                                + " nextReceiver=" + r.nextReceiver
+                                + " state=" + r.state);
+                        broadcastTimeoutLocked(false); // forcibly finish this broadcast
+                        forceReceive = true;
+                        r.state = BroadcastRecord.IDLE;
+                    }
+                }
+
+                if (r.state != BroadcastRecord.IDLE) {
+                    if (DEBUG_BROADCAST) Slog.d(TAG,
+                            "processNextBroadcast("
+                            + mQueueName + ") called when not idle (state="
+                            + r.state + ")");
+                    return;
+                }
+
+                if (r.receivers == null || r.nextReceiver >= numReceivers
+                        || r.resultAbort || forceReceive) {
+                    // No more receivers for this broadcast!  Send the final
+                    // result if requested...
+                    if (r.resultTo != null) {
+                        try {
+                            if (DEBUG_BROADCAST) {
+                                int seq = r.intent.getIntExtra("seq", -1);
+                                Slog.i(TAG, "Finishing broadcast ["
+                                        + mQueueName + "] " + r.intent.getAction()
+                                        + " seq=" + seq + " app=" + r.callerApp);
+                            }
+                            performReceiveLocked(r.callerApp, r.resultTo,
+                                new Intent(r.intent), r.resultCode,
+                                r.resultData, r.resultExtras, false, false, r.userId);
+                            // Set this to null so that the reference
+                            // (local and remote) isn't kept in the mBroadcastHistory.
+                            r.resultTo = null;
+                        } catch (RemoteException e) {
+                            Slog.w(TAG, "Failure ["
+                                    + mQueueName + "] sending broadcast result of "
+                                    + r.intent, e);
+                        }
+                    }
+
+                    if (DEBUG_BROADCAST) Slog.v(TAG, "Cancelling BROADCAST_TIMEOUT_MSG");
+                    cancelBroadcastTimeoutLocked();
+
+                    if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Finished with ordered broadcast "
+                            + r);
+
+                    // ... and on to the next...
+                    addBroadcastToHistoryLocked(r);
+                    mOrderedBroadcasts.remove(0);
+                    r = null;
+                    looped = true;
+                    continue;
+                }
+            } while (r == null);
+
+            // Get the next receiver...
+            int recIdx = r.nextReceiver++;
+
+            // Keep track of when this receiver started, and make sure there
+            // is a timeout message pending to kill it if need be.
+            r.receiverTime = SystemClock.uptimeMillis();
+            if (recIdx == 0) {
+                r.dispatchTime = r.receiverTime;
+                r.dispatchClockTime = System.currentTimeMillis();
+                if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing ordered broadcast ["
+                        + mQueueName + "] " + r);
+            }
+            if (! mPendingBroadcastTimeoutMessage) {
+                long timeoutTime = r.receiverTime + mTimeoutPeriod;
+                if (DEBUG_BROADCAST) Slog.v(TAG,
+                        "Submitting BROADCAST_TIMEOUT_MSG ["
+                        + mQueueName + "] for " + r + " at " + timeoutTime);
+                setBroadcastTimeoutLocked(timeoutTime);
+            }
+
+            Object nextReceiver = r.receivers.get(recIdx);
+            if (nextReceiver instanceof BroadcastFilter) {
+                // Simple case: this is a registered receiver who gets
+                // a direct call.
+                BroadcastFilter filter = (BroadcastFilter)nextReceiver;
+                if (DEBUG_BROADCAST)  Slog.v(TAG,
+                        "Delivering ordered ["
+                        + mQueueName + "] to registered "
+                        + filter + ": " + r);
+                deliverToRegisteredReceiverLocked(r, filter, r.ordered);
+                if (r.receiver == null || !r.ordered) {
+                    // The receiver has already finished, so schedule to
+                    // process the next one.
+                    if (DEBUG_BROADCAST) Slog.v(TAG, "Quick finishing ["
+                            + mQueueName + "]: ordered="
+                            + r.ordered + " receiver=" + r.receiver);
+                    r.state = BroadcastRecord.IDLE;
+                    scheduleBroadcastsLocked();
+                }
+                return;
+            }
+
+            // Hard case: need to instantiate the receiver, possibly
+            // starting its application process to host it.
+
+            ResolveInfo info =
+                (ResolveInfo)nextReceiver;
+            ComponentName component = new ComponentName(
+                    info.activityInfo.applicationInfo.packageName,
+                    info.activityInfo.name);
+
+            boolean skip = false;
+            int perm = mService.checkComponentPermission(info.activityInfo.permission,
+                    r.callingPid, r.callingUid, info.activityInfo.applicationInfo.uid,
+                    info.activityInfo.exported);
+            if (perm != PackageManager.PERMISSION_GRANTED) {
+                if (!info.activityInfo.exported) {
+                    Slog.w(TAG, "Permission Denial: broadcasting "
+                            + r.intent.toString()
+                            + " from " + r.callerPackage + " (pid=" + r.callingPid
+                            + ", uid=" + r.callingUid + ")"
+                            + " is not exported from uid " + info.activityInfo.applicationInfo.uid
+                            + " due to receiver " + component.flattenToShortString());
+                } else {
+                    Slog.w(TAG, "Permission Denial: broadcasting "
+                            + r.intent.toString()
+                            + " from " + r.callerPackage + " (pid=" + r.callingPid
+                            + ", uid=" + r.callingUid + ")"
+                            + " requires " + info.activityInfo.permission
+                            + " due to receiver " + component.flattenToShortString());
+                }
+                skip = true;
+            }
+            if (info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID &&
+                r.requiredPermission != null) {
+                try {
+                    perm = AppGlobals.getPackageManager().
+                            checkPermission(r.requiredPermission,
+                                    info.activityInfo.applicationInfo.packageName);
+                } catch (RemoteException e) {
+                    perm = PackageManager.PERMISSION_DENIED;
+                }
+                if (perm != PackageManager.PERMISSION_GRANTED) {
+                    Slog.w(TAG, "Permission Denial: receiving "
+                            + r.intent + " to "
+                            + component.flattenToShortString()
+                            + " requires " + r.requiredPermission
+                            + " due to sender " + r.callerPackage
+                            + " (uid " + r.callingUid + ")");
+                    skip = true;
+                }
+            }
+            if (r.appOp != AppOpsManager.OP_NONE) {
+                int mode = mService.mAppOpsService.noteOperation(r.appOp,
+                        info.activityInfo.applicationInfo.uid, info.activityInfo.packageName);
+                if (mode != AppOpsManager.MODE_ALLOWED) {
+                    if (DEBUG_BROADCAST)  Slog.v(TAG,
+                            "App op " + r.appOp + " not allowed for broadcast to uid "
+                            + info.activityInfo.applicationInfo.uid + " pkg "
+                            + info.activityInfo.packageName);
+                    skip = true;
+                }
+            }
+            if (!skip) {
+                skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid,
+                        r.callingPid, r.resolvedType, info.activityInfo.applicationInfo.uid);
+            }
+            boolean isSingleton = false;
+            try {
+                isSingleton = mService.isSingleton(info.activityInfo.processName,
+                        info.activityInfo.applicationInfo,
+                        info.activityInfo.name, info.activityInfo.flags);
+            } catch (SecurityException e) {
+                Slog.w(TAG, e.getMessage());
+                skip = true;
+            }
+            if ((info.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) {
+                if (ActivityManager.checkUidPermission(
+                        android.Manifest.permission.INTERACT_ACROSS_USERS,
+                        info.activityInfo.applicationInfo.uid)
+                                != PackageManager.PERMISSION_GRANTED) {
+                    Slog.w(TAG, "Permission Denial: Receiver " + component.flattenToShortString()
+                            + " requests FLAG_SINGLE_USER, but app does not hold "
+                            + android.Manifest.permission.INTERACT_ACROSS_USERS);
+                    skip = true;
+                }
+            }
+            if (r.curApp != null && r.curApp.crashing) {
+                // If the target process is crashing, just skip it.
+                Slog.w(TAG, "Skipping deliver ordered [" + mQueueName + "] " + r
+                        + " to " + r.curApp + ": process crashing");
+                skip = true;
+            }
+            if (!skip) {
+                boolean isAvailable = false;
+                try {
+                    isAvailable = AppGlobals.getPackageManager().isPackageAvailable(
+                            info.activityInfo.packageName,
+                            UserHandle.getUserId(info.activityInfo.applicationInfo.uid));
+                } catch (Exception e) {
+                    // all such failures mean we skip this receiver
+                    Slog.w(TAG, "Exception getting recipient info for "
+                            + info.activityInfo.packageName, e);
+                }
+                if (!isAvailable) {
+                    if (DEBUG_BROADCAST) {
+                        Slog.v(TAG, "Skipping delivery to " + info.activityInfo.packageName
+                                + " / " + info.activityInfo.applicationInfo.uid
+                                + " : package no longer available");
+                    }
+                    skip = true;
+                }
+            }
+
+            if (skip) {
+                if (DEBUG_BROADCAST)  Slog.v(TAG,
+                        "Skipping delivery of ordered ["
+                        + mQueueName + "] " + r + " for whatever reason");
+                r.receiver = null;
+                r.curFilter = null;
+                r.state = BroadcastRecord.IDLE;
+                scheduleBroadcastsLocked();
+                return;
+            }
+
+            r.state = BroadcastRecord.APP_RECEIVE;
+            String targetProcess = info.activityInfo.processName;
+            r.curComponent = component;
+            if (r.callingUid != Process.SYSTEM_UID && isSingleton) {
+                info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0);
+            }
+            r.curReceiver = info.activityInfo;
+            if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) {
+                Slog.v(TAG_MU, "Updated broadcast record activity info for secondary user, "
+                        + info.activityInfo + ", callingUid = " + r.callingUid + ", uid = "
+                        + info.activityInfo.applicationInfo.uid);
+            }
+
+            // Broadcast is being executed, its package can't be stopped.
+            try {
+                AppGlobals.getPackageManager().setPackageStoppedState(
+                        r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid));
+            } catch (RemoteException e) {
+            } catch (IllegalArgumentException e) {
+                Slog.w(TAG, "Failed trying to unstop package "
+                        + r.curComponent.getPackageName() + ": " + e);
+            }
+
+            // Is this receiver's application already running?
+            ProcessRecord app = mService.getProcessRecordLocked(targetProcess,
+                    info.activityInfo.applicationInfo.uid, false);
+            if (app != null && app.thread != null) {
+                try {
+                    app.addPackage(info.activityInfo.packageName, mService.mProcessStats);
+                    processCurBroadcastLocked(r, app);
+                    return;
+                } catch (RemoteException e) {
+                    Slog.w(TAG, "Exception when sending broadcast to "
+                          + r.curComponent, e);
+                } catch (RuntimeException e) {
+                    Log.wtf(TAG, "Failed sending broadcast to "
+                            + r.curComponent + " with " + r.intent, e);
+                    // If some unexpected exception happened, just skip
+                    // this broadcast.  At this point we are not in the call
+                    // from a client, so throwing an exception out from here
+                    // will crash the entire system instead of just whoever
+                    // sent the broadcast.
+                    logBroadcastReceiverDiscardLocked(r);
+                    finishReceiverLocked(r, r.resultCode, r.resultData,
+                            r.resultExtras, r.resultAbort, false);
+                    scheduleBroadcastsLocked();
+                    // We need to reset the state if we failed to start the receiver.
+                    r.state = BroadcastRecord.IDLE;
+                    return;
+                }
+
+                // If a dead object exception was thrown -- fall through to
+                // restart the application.
+            }
+
+            // Not running -- get it started, to be executed when the app comes up.
+            if (DEBUG_BROADCAST)  Slog.v(TAG,
+                    "Need to start app ["
+                    + mQueueName + "] " + targetProcess + " for broadcast " + r);
+            if ((r.curApp=mService.startProcessLocked(targetProcess,
+                    info.activityInfo.applicationInfo, true,
+                    r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,
+                    "broadcast", r.curComponent,
+                    (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false))
+                            == null) {
+                // Ah, this recipient is unavailable.  Finish it if necessary,
+                // and mark the broadcast record as ready for the next.
+                Slog.w(TAG, "Unable to launch app "
+                        + info.activityInfo.applicationInfo.packageName + "/"
+                        + info.activityInfo.applicationInfo.uid + " for broadcast "
+                        + r.intent + ": process is bad");
+                logBroadcastReceiverDiscardLocked(r);
+                finishReceiverLocked(r, r.resultCode, r.resultData,
+                        r.resultExtras, r.resultAbort, false);
+                scheduleBroadcastsLocked();
+                r.state = BroadcastRecord.IDLE;
+                return;
+            }
+
+            mPendingBroadcast = r;
+            mPendingBroadcastRecvIndex = recIdx;
+        }
+    }
+
+    final void setBroadcastTimeoutLocked(long timeoutTime) {
+        if (! mPendingBroadcastTimeoutMessage) {
+            Message msg = mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG, this);
+            mHandler.sendMessageAtTime(msg, timeoutTime);
+            mPendingBroadcastTimeoutMessage = true;
+        }
+    }
+
+    final void cancelBroadcastTimeoutLocked() {
+        if (mPendingBroadcastTimeoutMessage) {
+            mHandler.removeMessages(BROADCAST_TIMEOUT_MSG, this);
+            mPendingBroadcastTimeoutMessage = false;
+        }
+    }
+
+    final void broadcastTimeoutLocked(boolean fromMsg) {
+        if (fromMsg) {
+            mPendingBroadcastTimeoutMessage = false;
+        }
+
+        if (mOrderedBroadcasts.size() == 0) {
+            return;
+        }
+
+        long now = SystemClock.uptimeMillis();
+        BroadcastRecord r = mOrderedBroadcasts.get(0);
+        if (fromMsg) {
+            if (mService.mDidDexOpt) {
+                // Delay timeouts until dexopt finishes.
+                mService.mDidDexOpt = false;
+                long timeoutTime = SystemClock.uptimeMillis() + mTimeoutPeriod;
+                setBroadcastTimeoutLocked(timeoutTime);
+                return;
+            }
+            if (!mService.mProcessesReady) {
+                // Only process broadcast timeouts if the system is ready. That way
+                // PRE_BOOT_COMPLETED broadcasts can't timeout as they are intended
+                // to do heavy lifting for system up.
+                return;
+            }
+
+            long timeoutTime = r.receiverTime + mTimeoutPeriod;
+            if (timeoutTime > now) {
+                // We can observe premature timeouts because we do not cancel and reset the
+                // broadcast timeout message after each receiver finishes.  Instead, we set up
+                // an initial timeout then kick it down the road a little further as needed
+                // when it expires.
+                if (DEBUG_BROADCAST) Slog.v(TAG,
+                        "Premature timeout ["
+                        + mQueueName + "] @ " + now + ": resetting BROADCAST_TIMEOUT_MSG for "
+                        + timeoutTime);
+                setBroadcastTimeoutLocked(timeoutTime);
+                return;
+            }
+        }
+
+        BroadcastRecord br = mOrderedBroadcasts.get(0);
+        if (br.state == BroadcastRecord.WAITING_SERVICES) {
+            // In this case the broadcast had already finished, but we had decided to wait
+            // for started services to finish as well before going on.  So if we have actually
+            // waited long enough time timeout the broadcast, let's give up on the whole thing
+            // and just move on to the next.
+            Slog.i(ActivityManagerService.TAG, "Waited long enough for: " + (br.curComponent != null
+                    ? br.curComponent.flattenToShortString() : "(null)"));
+            br.curComponent = null;
+            br.state = BroadcastRecord.IDLE;
+            processNextBroadcast(false);
+            return;
+        }
+
+        Slog.w(TAG, "Timeout of broadcast " + r + " - receiver=" + r. receiver
+                + ", started " + (now - r.receiverTime) + "ms ago");
+        r.receiverTime = now;
+        r.anrCount++;
+
+        // Current receiver has passed its expiration date.
+        if (r.nextReceiver <= 0) {
+            Slog.w(TAG, "Timeout on receiver with nextReceiver <= 0");
+            return;
+        }
+
+        ProcessRecord app = null;
+        String anrMessage = null;
+
+        Object curReceiver = r.receivers.get(r.nextReceiver-1);
+        Slog.w(TAG, "Receiver during timeout: " + curReceiver);
+        logBroadcastReceiverDiscardLocked(r);
+        if (curReceiver instanceof BroadcastFilter) {
+            BroadcastFilter bf = (BroadcastFilter)curReceiver;
+            if (bf.receiverList.pid != 0
+                    && bf.receiverList.pid != ActivityManagerService.MY_PID) {
+                synchronized (mService.mPidsSelfLocked) {
+                    app = mService.mPidsSelfLocked.get(
+                            bf.receiverList.pid);
+                }
+            }
+        } else {
+            app = r.curApp;
+        }
+
+        if (app != null) {
+            anrMessage = "Broadcast of " + r.intent.toString();
+        }
+
+        if (mPendingBroadcast == r) {
+            mPendingBroadcast = null;
+        }
+
+        // Move on to the next receiver.
+        finishReceiverLocked(r, r.resultCode, r.resultData,
+                r.resultExtras, r.resultAbort, false);
+        scheduleBroadcastsLocked();
+
+        if (anrMessage != null) {
+            // Post the ANR to the handler since we do not want to process ANRs while
+            // potentially holding our lock.
+            mHandler.post(new AppNotResponding(app, anrMessage));
+        }
+    }
+
+    private final void addBroadcastToHistoryLocked(BroadcastRecord r) {
+        if (r.callingUid < 0) {
+            // This was from a registerReceiver() call; ignore it.
+            return;
+        }
+        System.arraycopy(mBroadcastHistory, 0, mBroadcastHistory, 1,
+                MAX_BROADCAST_HISTORY-1);
+        r.finishTime = SystemClock.uptimeMillis();
+        mBroadcastHistory[0] = r;
+        System.arraycopy(mBroadcastSummaryHistory, 0, mBroadcastSummaryHistory, 1,
+                MAX_BROADCAST_SUMMARY_HISTORY-1);
+        mBroadcastSummaryHistory[0] = r.intent;
+    }
+
+    final void logBroadcastReceiverDiscardLocked(BroadcastRecord r) {
+        if (r.nextReceiver > 0) {
+            Object curReceiver = r.receivers.get(r.nextReceiver-1);
+            if (curReceiver instanceof BroadcastFilter) {
+                BroadcastFilter bf = (BroadcastFilter) curReceiver;
+                EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_FILTER,
+                        bf.owningUserId, System.identityHashCode(r),
+                        r.intent.getAction(),
+                        r.nextReceiver - 1,
+                        System.identityHashCode(bf));
+            } else {
+                ResolveInfo ri = (ResolveInfo)curReceiver;
+                EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP,
+                        UserHandle.getUserId(ri.activityInfo.applicationInfo.uid),
+                        System.identityHashCode(r), r.intent.getAction(),
+                        r.nextReceiver - 1, ri.toString());
+            }
+        } else {
+            Slog.w(TAG, "Discarding broadcast before first receiver is invoked: "
+                    + r);
+            EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP,
+                    -1, System.identityHashCode(r),
+                    r.intent.getAction(),
+                    r.nextReceiver,
+                    "NONE");
+        }
+    }
+
+    final boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args,
+            int opti, boolean dumpAll, String dumpPackage, boolean needSep) {
+        if (mParallelBroadcasts.size() > 0 || mOrderedBroadcasts.size() > 0
+                || mPendingBroadcast != null) {
+            boolean printed = false;
+            for (int i=mParallelBroadcasts.size()-1; i>=0; i--) {
+                BroadcastRecord br = mParallelBroadcasts.get(i);
+                if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) {
+                    continue;
+                }
+                if (!printed) {
+                    if (needSep) {
+                        pw.println();
+                    }
+                    needSep = true;
+                    printed = true;
+                    pw.println("  Active broadcasts [" + mQueueName + "]:");
+                }
+                pw.println("  Active Broadcast " + mQueueName + " #" + i + ":");
+                br.dump(pw, "    ");
+            }
+            printed = false;
+            needSep = true;
+            for (int i=mOrderedBroadcasts.size()-1; i>=0; i--) {
+                BroadcastRecord br = mOrderedBroadcasts.get(i);
+                if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) {
+                    continue;
+                }
+                if (!printed) {
+                    if (needSep) {
+                        pw.println();
+                    }
+                    needSep = true;
+                    printed = true;
+                    pw.println("  Active ordered broadcasts [" + mQueueName + "]:");
+                }
+                pw.println("  Active Ordered Broadcast " + mQueueName + " #" + i + ":");
+                mOrderedBroadcasts.get(i).dump(pw, "    ");
+            }
+            if (dumpPackage == null || (mPendingBroadcast != null
+                    && dumpPackage.equals(mPendingBroadcast.callerPackage))) {
+                if (needSep) {
+                    pw.println();
+                }
+                pw.println("  Pending broadcast [" + mQueueName + "]:");
+                if (mPendingBroadcast != null) {
+                    mPendingBroadcast.dump(pw, "    ");
+                } else {
+                    pw.println("    (null)");
+                }
+                needSep = true;
+            }
+        }
+
+        int i;
+        boolean printed = false;
+        for (i=0; i<MAX_BROADCAST_HISTORY; i++) {
+            BroadcastRecord r = mBroadcastHistory[i];
+            if (r == null) {
+                break;
+            }
+            if (dumpPackage != null && !dumpPackage.equals(r.callerPackage)) {
+                continue;
+            }
+            if (!printed) {
+                if (needSep) {
+                    pw.println();
+                }
+                needSep = true;
+                pw.println("  Historical broadcasts [" + mQueueName + "]:");
+                printed = true;
+            }
+            if (dumpAll) {
+                pw.print("  Historical Broadcast " + mQueueName + " #");
+                        pw.print(i); pw.println(":");
+                r.dump(pw, "    ");
+            } else {
+                pw.print("  #"); pw.print(i); pw.print(": "); pw.println(r);
+                pw.print("    ");
+                pw.println(r.intent.toShortString(false, true, true, false));
+                if (r.targetComp != null && r.targetComp != r.intent.getComponent()) {
+                    pw.print("    targetComp: "); pw.println(r.targetComp.toShortString());
+                }
+                Bundle bundle = r.intent.getExtras();
+                if (bundle != null) {
+                    pw.print("    extras: "); pw.println(bundle.toString());
+                }
+            }
+        }
+
+        if (dumpPackage == null) {
+            if (dumpAll) {
+                i = 0;
+                printed = false;
+            }
+            for (; i<MAX_BROADCAST_SUMMARY_HISTORY; i++) {
+                Intent intent = mBroadcastSummaryHistory[i];
+                if (intent == null) {
+                    break;
+                }
+                if (!printed) {
+                    if (needSep) {
+                        pw.println();
+                    }
+                    needSep = true;
+                    pw.println("  Historical broadcasts summary [" + mQueueName + "]:");
+                    printed = true;
+                }
+                if (!dumpAll && i >= 50) {
+                    pw.println("  ...");
+                    break;
+                }
+                pw.print("  #"); pw.print(i); pw.print(": ");
+                pw.println(intent.toShortString(false, true, true, false));
+                Bundle bundle = intent.getExtras();
+                if (bundle != null) {
+                    pw.print("    extras: "); pw.println(bundle.toString());
+                }
+            }
+        }
+
+        return needSep;
+    }
+}
diff --git a/services/java/com/android/server/am/BroadcastRecord.java b/services/core/java/com/android/server/am/BroadcastRecord.java
similarity index 100%
rename from services/java/com/android/server/am/BroadcastRecord.java
rename to services/core/java/com/android/server/am/BroadcastRecord.java
diff --git a/services/java/com/android/server/am/CompatModeDialog.java b/services/core/java/com/android/server/am/CompatModeDialog.java
similarity index 100%
rename from services/java/com/android/server/am/CompatModeDialog.java
rename to services/core/java/com/android/server/am/CompatModeDialog.java
diff --git a/services/core/java/com/android/server/am/CompatModePackages.java b/services/core/java/com/android/server/am/CompatModePackages.java
new file mode 100644
index 0000000..ec500c2
--- /dev/null
+++ b/services/core/java/com/android/server/am/CompatModePackages.java
@@ -0,0 +1,412 @@
+/*
+ * 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.server.am;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import com.android.internal.util.FastXmlSerializer;
+
+import android.app.ActivityManager;
+import android.app.AppGlobals;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.res.CompatibilityInfo;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.util.AtomicFile;
+import android.util.Slog;
+import android.util.Xml;
+
+public final class CompatModePackages {
+    private final String TAG = ActivityManagerService.TAG;
+    private final boolean DEBUG_CONFIGURATION = ActivityManagerService.DEBUG_CONFIGURATION;
+
+    private final ActivityManagerService mService;
+    private final AtomicFile mFile;
+
+    // Compatibility state: no longer ask user to select the mode.
+    public static final int COMPAT_FLAG_DONT_ASK = 1<<0;
+    // Compatibility state: compatibility mode is enabled.
+    public static final int COMPAT_FLAG_ENABLED = 1<<1;
+
+    private final HashMap<String, Integer> mPackages = new HashMap<String, Integer>();
+
+    private static final int MSG_WRITE = ActivityManagerService.FIRST_COMPAT_MODE_MSG;
+
+    private final CompatHandler mHandler;
+
+    private final class CompatHandler extends Handler {
+        public CompatHandler(Looper looper) {
+            super(looper, null, true);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_WRITE:
+                    saveCompatModes();
+                    break;
+            }
+        }
+    };
+
+    public CompatModePackages(ActivityManagerService service, File systemDir, Handler handler) {
+        mService = service;
+        mFile = new AtomicFile(new File(systemDir, "packages-compat.xml"));
+        mHandler = new CompatHandler(handler.getLooper());
+
+        FileInputStream fis = null;
+        try {
+            fis = mFile.openRead();
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(fis, null);
+            int eventType = parser.getEventType();
+            while (eventType != XmlPullParser.START_TAG &&
+                    eventType != XmlPullParser.END_DOCUMENT) {
+                eventType = parser.next();
+            }
+            if (eventType == XmlPullParser.END_DOCUMENT) {
+                return;
+            }
+
+            String tagName = parser.getName();
+            if ("compat-packages".equals(tagName)) {
+                eventType = parser.next();
+                do {
+                    if (eventType == XmlPullParser.START_TAG) {
+                        tagName = parser.getName();
+                        if (parser.getDepth() == 2) {
+                            if ("pkg".equals(tagName)) {
+                                String pkg = parser.getAttributeValue(null, "name");
+                                if (pkg != null) {
+                                    String mode = parser.getAttributeValue(null, "mode");
+                                    int modeInt = 0;
+                                    if (mode != null) {
+                                        try {
+                                            modeInt = Integer.parseInt(mode);
+                                        } catch (NumberFormatException e) {
+                                        }
+                                    }
+                                    mPackages.put(pkg, modeInt);
+                                }
+                            }
+                        }
+                    }
+                    eventType = parser.next();
+                } while (eventType != XmlPullParser.END_DOCUMENT);
+            }
+        } catch (XmlPullParserException e) {
+            Slog.w(TAG, "Error reading compat-packages", e);
+        } catch (java.io.IOException e) {
+            if (fis != null) Slog.w(TAG, "Error reading compat-packages", e);
+        } finally {
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (java.io.IOException e1) {
+                }
+            }
+        }
+    }
+
+    public HashMap<String, Integer> getPackages() {
+        return mPackages;
+    }
+
+    private int getPackageFlags(String packageName) {
+        Integer flags = mPackages.get(packageName);
+        return flags != null ? flags : 0;
+    }
+
+    public void handlePackageAddedLocked(String packageName, boolean updated) {
+        ApplicationInfo ai = null;
+        try {
+            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
+        } catch (RemoteException e) {
+        }
+        if (ai == null) {
+            return;
+        }
+        CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
+        final boolean mayCompat = !ci.alwaysSupportsScreen()
+                && !ci.neverSupportsScreen();
+
+        if (updated) {
+            // Update -- if the app no longer can run in compat mode, clear
+            // any current settings for it.
+            if (!mayCompat && mPackages.containsKey(packageName)) {
+                mPackages.remove(packageName);
+                mHandler.removeMessages(MSG_WRITE);
+                Message msg = mHandler.obtainMessage(MSG_WRITE);
+                mHandler.sendMessageDelayed(msg, 10000);
+            }
+        }
+    }
+
+    public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
+        CompatibilityInfo ci = new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
+                mService.mConfiguration.smallestScreenWidthDp,
+                (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0);
+        //Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci);
+        return ci;
+    }
+
+    public int computeCompatModeLocked(ApplicationInfo ai) {
+        boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0;
+        CompatibilityInfo info = new CompatibilityInfo(ai,
+                mService.mConfiguration.screenLayout,
+                mService.mConfiguration.smallestScreenWidthDp, enabled);
+        if (info.alwaysSupportsScreen()) {
+            return ActivityManager.COMPAT_MODE_NEVER;
+        }
+        if (info.neverSupportsScreen()) {
+            return ActivityManager.COMPAT_MODE_ALWAYS;
+        }
+        return enabled ? ActivityManager.COMPAT_MODE_ENABLED
+                : ActivityManager.COMPAT_MODE_DISABLED;
+    }
+
+    public boolean getFrontActivityAskCompatModeLocked() {
+        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
+        if (r == null) {
+            return false;
+        }
+        return getPackageAskCompatModeLocked(r.packageName);
+    }
+
+    public boolean getPackageAskCompatModeLocked(String packageName) {
+        return (getPackageFlags(packageName)&COMPAT_FLAG_DONT_ASK) == 0;
+    }
+
+    public void setFrontActivityAskCompatModeLocked(boolean ask) {
+        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
+        if (r != null) {
+            setPackageAskCompatModeLocked(r.packageName, ask);
+        }
+    }
+
+    public void setPackageAskCompatModeLocked(String packageName, boolean ask) {
+        int curFlags = getPackageFlags(packageName);
+        int newFlags = ask ? (curFlags&~COMPAT_FLAG_DONT_ASK) : (curFlags|COMPAT_FLAG_DONT_ASK);
+        if (curFlags != newFlags) {
+            if (newFlags != 0) {
+                mPackages.put(packageName, newFlags);
+            } else {
+                mPackages.remove(packageName);
+            }
+            mHandler.removeMessages(MSG_WRITE);
+            Message msg = mHandler.obtainMessage(MSG_WRITE);
+            mHandler.sendMessageDelayed(msg, 10000);
+        }
+    }
+
+    public int getFrontActivityScreenCompatModeLocked() {
+        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
+        if (r == null) {
+            return ActivityManager.COMPAT_MODE_UNKNOWN;
+        }
+        return computeCompatModeLocked(r.info.applicationInfo);
+    }
+
+    public void setFrontActivityScreenCompatModeLocked(int mode) {
+        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
+        if (r == null) {
+            Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity");
+            return;
+        }
+        setPackageScreenCompatModeLocked(r.info.applicationInfo, mode);
+    }
+
+    public int getPackageScreenCompatModeLocked(String packageName) {
+        ApplicationInfo ai = null;
+        try {
+            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
+        } catch (RemoteException e) {
+        }
+        if (ai == null) {
+            return ActivityManager.COMPAT_MODE_UNKNOWN;
+        }
+        return computeCompatModeLocked(ai);
+    }
+
+    public void setPackageScreenCompatModeLocked(String packageName, int mode) {
+        ApplicationInfo ai = null;
+        try {
+            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
+        } catch (RemoteException e) {
+        }
+        if (ai == null) {
+            Slog.w(TAG, "setPackageScreenCompatMode failed: unknown package " + packageName);
+            return;
+        }
+        setPackageScreenCompatModeLocked(ai, mode);
+    }
+
+    private void setPackageScreenCompatModeLocked(ApplicationInfo ai, int mode) {
+        final String packageName = ai.packageName;
+
+        int curFlags = getPackageFlags(packageName);
+
+        boolean enable;
+        switch (mode) {
+            case ActivityManager.COMPAT_MODE_DISABLED:
+                enable = false;
+                break;
+            case ActivityManager.COMPAT_MODE_ENABLED:
+                enable = true;
+                break;
+            case ActivityManager.COMPAT_MODE_TOGGLE:
+                enable = (curFlags&COMPAT_FLAG_ENABLED) == 0;
+                break;
+            default:
+                Slog.w(TAG, "Unknown screen compat mode req #" + mode + "; ignoring");
+                return;
+        }
+
+        int newFlags = curFlags;
+        if (enable) {
+            newFlags |= COMPAT_FLAG_ENABLED;
+        } else {
+            newFlags &= ~COMPAT_FLAG_ENABLED;
+        }
+
+        CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
+        if (ci.alwaysSupportsScreen()) {
+            Slog.w(TAG, "Ignoring compat mode change of " + packageName
+                    + "; compatibility never needed");
+            newFlags = 0;
+        }
+        if (ci.neverSupportsScreen()) {
+            Slog.w(TAG, "Ignoring compat mode change of " + packageName
+                    + "; compatibility always needed");
+            newFlags = 0;
+        }
+
+        if (newFlags != curFlags) {
+            if (newFlags != 0) {
+                mPackages.put(packageName, newFlags);
+            } else {
+                mPackages.remove(packageName);
+            }
+
+            // Need to get compatibility info in new state.
+            ci = compatibilityInfoForPackageLocked(ai);
+
+            mHandler.removeMessages(MSG_WRITE);
+            Message msg = mHandler.obtainMessage(MSG_WRITE);
+            mHandler.sendMessageDelayed(msg, 10000);
+
+            final ActivityStack stack = mService.getFocusedStack();
+            ActivityRecord starting = stack.restartPackage(packageName);
+
+            // Tell all processes that loaded this package about the change.
+            for (int i=mService.mLruProcesses.size()-1; i>=0; i--) {
+                ProcessRecord app = mService.mLruProcesses.get(i);
+                if (!app.pkgList.containsKey(packageName)) {
+                    continue;
+                }
+                try {
+                    if (app.thread != null) {
+                        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending to proc "
+                                + app.processName + " new compat " + ci);
+                        app.thread.updatePackageCompatibilityInfo(packageName, ci);
+                    }
+                } catch (Exception e) {
+                }
+            }
+
+            if (starting != null) {
+                stack.ensureActivityConfigurationLocked(starting, 0);
+                // And we need to make sure at this point that all other activities
+                // are made visible with the correct configuration.
+                stack.ensureActivitiesVisibleLocked(starting, 0);
+            }
+        }
+    }
+
+    void saveCompatModes() {
+        HashMap<String, Integer> pkgs;
+        synchronized (mService) {
+            pkgs = new HashMap<String, Integer>(mPackages);
+        }
+
+        FileOutputStream fos = null;
+
+        try {
+            fos = mFile.startWrite();
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            out.startDocument(null, true);
+            out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+            out.startTag(null, "compat-packages");
+
+            final IPackageManager pm = AppGlobals.getPackageManager();
+            final int screenLayout = mService.mConfiguration.screenLayout;
+            final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
+            final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
+            while (it.hasNext()) {
+                Map.Entry<String, Integer> entry = it.next();
+                String pkg = entry.getKey();
+                int mode = entry.getValue();
+                if (mode == 0) {
+                    continue;
+                }
+                ApplicationInfo ai = null;
+                try {
+                    ai = pm.getApplicationInfo(pkg, 0, 0);
+                } catch (RemoteException e) {
+                }
+                if (ai == null) {
+                    continue;
+                }
+                CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout,
+                        smallestScreenWidthDp, false);
+                if (info.alwaysSupportsScreen()) {
+                    continue;
+                }
+                if (info.neverSupportsScreen()) {
+                    continue;
+                }
+                out.startTag(null, "pkg");
+                out.attribute(null, "name", pkg);
+                out.attribute(null, "mode", Integer.toString(mode));
+                out.endTag(null, "pkg");
+            }
+
+            out.endTag(null, "compat-packages");
+            out.endDocument();
+
+            mFile.finishWrite(fos);
+        } catch (java.io.IOException e1) {
+            Slog.w(TAG, "Error writing compat packages", e1);
+            if (fos != null) {
+                mFile.failWrite(fos);
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/am/ConnectionRecord.java b/services/core/java/com/android/server/am/ConnectionRecord.java
similarity index 100%
rename from services/java/com/android/server/am/ConnectionRecord.java
rename to services/core/java/com/android/server/am/ConnectionRecord.java
diff --git a/services/java/com/android/server/am/ContentProviderConnection.java b/services/core/java/com/android/server/am/ContentProviderConnection.java
similarity index 100%
rename from services/java/com/android/server/am/ContentProviderConnection.java
rename to services/core/java/com/android/server/am/ContentProviderConnection.java
diff --git a/services/java/com/android/server/am/ContentProviderRecord.java b/services/core/java/com/android/server/am/ContentProviderRecord.java
similarity index 100%
rename from services/java/com/android/server/am/ContentProviderRecord.java
rename to services/core/java/com/android/server/am/ContentProviderRecord.java
diff --git a/services/java/com/android/server/am/CoreSettingsObserver.java b/services/core/java/com/android/server/am/CoreSettingsObserver.java
similarity index 100%
rename from services/java/com/android/server/am/CoreSettingsObserver.java
rename to services/core/java/com/android/server/am/CoreSettingsObserver.java
diff --git a/services/java/com/android/server/am/EventLogTags.logtags b/services/core/java/com/android/server/am/EventLogTags.logtags
similarity index 100%
rename from services/java/com/android/server/am/EventLogTags.logtags
rename to services/core/java/com/android/server/am/EventLogTags.logtags
diff --git a/services/java/com/android/server/am/FactoryErrorDialog.java b/services/core/java/com/android/server/am/FactoryErrorDialog.java
similarity index 100%
rename from services/java/com/android/server/am/FactoryErrorDialog.java
rename to services/core/java/com/android/server/am/FactoryErrorDialog.java
diff --git a/services/java/com/android/server/am/IntentBindRecord.java b/services/core/java/com/android/server/am/IntentBindRecord.java
similarity index 100%
rename from services/java/com/android/server/am/IntentBindRecord.java
rename to services/core/java/com/android/server/am/IntentBindRecord.java
diff --git a/services/java/com/android/server/am/LaunchWarningWindow.java b/services/core/java/com/android/server/am/LaunchWarningWindow.java
similarity index 100%
rename from services/java/com/android/server/am/LaunchWarningWindow.java
rename to services/core/java/com/android/server/am/LaunchWarningWindow.java
diff --git a/services/core/java/com/android/server/am/NativeCrashListener.java b/services/core/java/com/android/server/am/NativeCrashListener.java
new file mode 100644
index 0000000..b12843b
--- /dev/null
+++ b/services/core/java/com/android/server/am/NativeCrashListener.java
@@ -0,0 +1,285 @@
+/*
+ * Copyright (C) 2013 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.app.ApplicationErrorReport.CrashInfo;
+import android.util.Slog;
+
+import libcore.io.ErrnoException;
+import libcore.io.Libcore;
+import libcore.io.StructTimeval;
+import libcore.io.StructUcred;
+
+import static libcore.io.OsConstants.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.net.InetSocketAddress;
+import java.net.InetUnixAddress;
+
+/**
+ * Set up a Unix domain socket that debuggerd will connect() to in
+ * order to write a description of a native crash.  The crash info is
+ * then parsed and forwarded to the ActivityManagerService's normal
+ * crash handling code.
+ *
+ * Note that this component runs in a separate thread.
+ */
+final class NativeCrashListener extends Thread {
+    static final String TAG = "NativeCrashListener";
+    static final boolean DEBUG = false;
+    static final boolean MORE_DEBUG = DEBUG && false;
+
+    // Must match the path defined in debuggerd.c.
+    static final String DEBUGGERD_SOCKET_PATH = "/data/system/ndebugsocket";
+
+    // Use a short timeout on socket operations and abandon the connection
+    // on hard errors
+    static final long SOCKET_TIMEOUT_MILLIS = 2000;  // 2 seconds
+
+    final ActivityManagerService mAm;
+
+    /*
+     * Spin the actual work of handling a debuggerd crash report into a
+     * separate thread so that the listener can go immediately back to
+     * accepting incoming connections.
+     */
+    class NativeCrashReporter extends Thread {
+        ProcessRecord mApp;
+        int mSignal;
+        String mCrashReport;
+
+        NativeCrashReporter(ProcessRecord app, int signal, String report) {
+            super("NativeCrashReport");
+            mApp = app;
+            mSignal = signal;
+            mCrashReport = report;
+        }
+
+        @Override
+        public void run() {
+            try {
+                CrashInfo ci = new CrashInfo();
+                ci.exceptionClassName = "Native crash";
+                ci.exceptionMessage = Libcore.os.strsignal(mSignal);
+                ci.throwFileName = "unknown";
+                ci.throwClassName = "unknown";
+                ci.throwMethodName = "unknown";
+                ci.stackTrace = mCrashReport;
+
+                if (DEBUG) Slog.v(TAG, "Calling handleApplicationCrash()");
+                mAm.handleApplicationCrashInner("native_crash", mApp, mApp.processName, ci);
+                if (DEBUG) Slog.v(TAG, "<-- handleApplicationCrash() returned");
+            } catch (Exception e) {
+                Slog.e(TAG, "Unable to report native crash", e);
+            }
+        }
+    }
+
+    /*
+     * Daemon thread that accept()s incoming domain socket connections from debuggerd
+     * and processes the crash dump that is passed through.
+     */
+    NativeCrashListener(ActivityManagerService am) {
+        mAm = am;
+    }
+
+    @Override
+    public void run() {
+        final byte[] ackSignal = new byte[1];
+
+        if (DEBUG) Slog.i(TAG, "Starting up");
+
+        // The file system entity for this socket is created with 0700 perms, owned
+        // by system:system.  debuggerd runs as root, so is capable of connecting to
+        // it, but 3rd party apps cannot.
+        {
+            File socketFile = new File(DEBUGGERD_SOCKET_PATH);
+            if (socketFile.exists()) {
+                socketFile.delete();
+            }
+        }
+
+        try {
+            FileDescriptor serverFd = Libcore.os.socket(AF_UNIX, SOCK_STREAM, 0);
+            final InetUnixAddress sockAddr = new InetUnixAddress(DEBUGGERD_SOCKET_PATH);
+            Libcore.os.bind(serverFd, sockAddr, 0);
+            Libcore.os.listen(serverFd, 1);
+
+            while (true) {
+                InetSocketAddress peer = new InetSocketAddress();
+                FileDescriptor peerFd = null;
+                try {
+                    if (MORE_DEBUG) Slog.v(TAG, "Waiting for debuggerd connection");
+                    peerFd = Libcore.os.accept(serverFd, peer);
+                    if (MORE_DEBUG) Slog.v(TAG, "Got debuggerd socket " + peerFd);
+                    if (peerFd != null) {
+                        // Only the superuser is allowed to talk to us over this socket
+                        StructUcred credentials =
+                                Libcore.os.getsockoptUcred(peerFd, SOL_SOCKET, SO_PEERCRED);
+                        if (credentials.uid == 0) {
+                            // the reporting thread may take responsibility for
+                            // acking the debugger; make sure we play along.
+                            consumeNativeCrashData(peerFd);
+                        }
+                    }
+                } catch (Exception e) {
+                    Slog.w(TAG, "Error handling connection", e);
+                } finally {
+                    // Always ack debuggerd's connection to us.  The actual
+                    // byte written is irrelevant.
+                    if (peerFd != null) {
+                        try {
+                            Libcore.os.write(peerFd, ackSignal, 0, 1);
+                        } catch (Exception e) {
+                            /* we don't care about failures here */
+                            if (MORE_DEBUG) {
+                                Slog.d(TAG, "Exception writing ack: " + e.getMessage());
+                            }
+                        }
+                        try {
+                            Libcore.os.close(peerFd);
+                        } catch (ErrnoException e) {
+                            if (MORE_DEBUG) {
+                                Slog.d(TAG, "Exception closing socket: " + e.getMessage());
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            Slog.e(TAG, "Unable to init native debug socket!", e);
+        }
+    }
+
+    static int unpackInt(byte[] buf, int offset) {
+        int b0, b1, b2, b3;
+
+        b0 = ((int) buf[offset]) & 0xFF; // mask against sign extension
+        b1 = ((int) buf[offset+1]) & 0xFF;
+        b2 = ((int) buf[offset+2]) & 0xFF;
+        b3 = ((int) buf[offset+3]) & 0xFF;
+        return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
+    }
+
+    static int readExactly(FileDescriptor fd, byte[] buffer, int offset, int numBytes)
+            throws ErrnoException {
+        int totalRead = 0;
+        while (numBytes > 0) {
+            int n = Libcore.os.read(fd, buffer, offset + totalRead, numBytes);
+            if (n <= 0) {
+                if (DEBUG) {
+                    Slog.w(TAG, "Needed " + numBytes + " but saw " + n);
+                }
+                return -1;  // premature EOF or timeout
+            }
+            numBytes -= n;
+            totalRead += n;
+        }
+        return totalRead;
+    }
+
+    // Read the crash report from the debuggerd connection
+    void consumeNativeCrashData(FileDescriptor fd) {
+        if (MORE_DEBUG) Slog.i(TAG, "debuggerd connected");
+        final byte[] buf = new byte[4096];
+        final ByteArrayOutputStream os = new ByteArrayOutputStream(4096);
+
+        try {
+            StructTimeval timeout = StructTimeval.fromMillis(SOCKET_TIMEOUT_MILLIS);
+            Libcore.os.setsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO, timeout);
+            Libcore.os.setsockoptTimeval(fd, SOL_SOCKET, SO_SNDTIMEO, timeout);
+
+            // first, the pid and signal number
+            int headerBytes = readExactly(fd, buf, 0, 8);
+            if (headerBytes != 8) {
+                // protocol failure; give up
+                Slog.e(TAG, "Unable to read from debuggerd");
+                return;
+            }
+
+            int pid = unpackInt(buf, 0);
+            int signal = unpackInt(buf, 4);
+            if (DEBUG) {
+                Slog.v(TAG, "Read pid=" + pid + " signal=" + signal);
+            }
+
+            // now the text of the dump
+            if (pid > 0) {
+                final ProcessRecord pr;
+                synchronized (mAm.mPidsSelfLocked) {
+                    pr = mAm.mPidsSelfLocked.get(pid);
+                }
+                if (pr != null) {
+                    // Don't attempt crash reporting for persistent apps
+                    if (pr.persistent) {
+                        if (DEBUG) {
+                            Slog.v(TAG, "Skipping report for persistent app " + pr);
+                        }
+                        return;
+                    }
+
+                    int bytes;
+                    do {
+                        // get some data
+                        bytes = Libcore.os.read(fd, buf, 0, buf.length);
+                        if (bytes > 0) {
+                            if (MORE_DEBUG) {
+                                String s = new String(buf, 0, bytes, "UTF-8");
+                                Slog.v(TAG, "READ=" + bytes + "> " + s);
+                            }
+                            // did we just get the EOD null byte?
+                            if (buf[bytes-1] == 0) {
+                                os.write(buf, 0, bytes-1);  // exclude the EOD token
+                                break;
+                            }
+                            // no EOD, so collect it and read more
+                            os.write(buf, 0, bytes);
+                        }
+                    } while (bytes > 0);
+
+                    // Okay, we've got the report.
+                    if (DEBUG) Slog.v(TAG, "processing");
+
+                    // Mark the process record as being a native crash so that the
+                    // cleanup mechanism knows we're still submitting the report
+                    // even though the process will vanish as soon as we let
+                    // debuggerd proceed.
+                    synchronized (mAm) {
+                        pr.crashing = true;
+                        pr.forceCrashReport = true;
+                    }
+
+                    // Crash reporting is synchronous but we want to let debuggerd
+                    // go about it business right away, so we spin off the actual
+                    // reporting logic on a thread and let it take it's time.
+                    final String reportString = new String(os.toByteArray(), "UTF-8");
+                    (new NativeCrashReporter(pr, signal, reportString)).start();
+                } else {
+                    Slog.w(TAG, "Couldn't find ProcessRecord for pid " + pid);
+                }
+            } else {
+                Slog.e(TAG, "Bogus pid!");
+            }
+        } catch (Exception e) {
+            Slog.e(TAG, "Exception dealing with report", e);
+            // ugh, fail.
+        }
+    }
+
+}
diff --git a/services/core/java/com/android/server/am/PendingIntentRecord.java b/services/core/java/com/android/server/am/PendingIntentRecord.java
new file mode 100644
index 0000000..00fa216
--- /dev/null
+++ b/services/core/java/com/android/server/am/PendingIntentRecord.java
@@ -0,0 +1,366 @@
+/*
+ * Copyright (C) 2006 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.app.ActivityManager;
+import android.app.IActivityContainer;
+import android.content.IIntentSender;
+import android.content.IIntentReceiver;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.util.Slog;
+
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+
+final class PendingIntentRecord extends IIntentSender.Stub {
+    final ActivityManagerService owner;
+    final Key key;
+    final int uid;
+    final WeakReference<PendingIntentRecord> ref;
+    boolean sent = false;
+    boolean canceled = false;
+
+    String stringName;
+    
+    final static class Key {
+        final int type;
+        final String packageName;
+        final ActivityRecord activity;
+        final String who;
+        final int requestCode;
+        final Intent requestIntent;
+        final String requestResolvedType;
+        final Bundle options;
+        Intent[] allIntents;
+        String[] allResolvedTypes;
+        final int flags;
+        final int hashCode;
+        final int userId;
+        
+        private static final int ODD_PRIME_NUMBER = 37;
+        
+        Key(int _t, String _p, ActivityRecord _a, String _w,
+                int _r, Intent[] _i, String[] _it, int _f, Bundle _o, int _userId) {
+            type = _t;
+            packageName = _p;
+            activity = _a;
+            who = _w;
+            requestCode = _r;
+            requestIntent = _i != null ? _i[_i.length-1] : null;
+            requestResolvedType = _it != null ? _it[_it.length-1] : null;
+            allIntents = _i;
+            allResolvedTypes = _it;
+            flags = _f;
+            options = _o;
+            userId = _userId;
+
+            int hash = 23;
+            hash = (ODD_PRIME_NUMBER*hash) + _f;
+            hash = (ODD_PRIME_NUMBER*hash) + _r;
+            hash = (ODD_PRIME_NUMBER*hash) + _userId;
+            if (_w != null) {
+                hash = (ODD_PRIME_NUMBER*hash) + _w.hashCode();
+            }
+            if (_a != null) {
+                hash = (ODD_PRIME_NUMBER*hash) + _a.hashCode();
+            }
+            if (requestIntent != null) {
+                hash = (ODD_PRIME_NUMBER*hash) + requestIntent.filterHashCode();
+            }
+            if (requestResolvedType != null) {
+                hash = (ODD_PRIME_NUMBER*hash) + requestResolvedType.hashCode();
+            }
+            hash = (ODD_PRIME_NUMBER*hash) + _p.hashCode();
+            hash = (ODD_PRIME_NUMBER*hash) + _t;
+            hashCode = hash;
+            //Slog.i(ActivityManagerService.TAG, this + " hashCode=0x"
+            //        + Integer.toHexString(hashCode));
+        }
+        
+        public boolean equals(Object otherObj) {
+            if (otherObj == null) {
+                return false;
+            }
+            try {
+                Key other = (Key)otherObj;
+                if (type != other.type) {
+                    return false;
+                }
+                if (userId != other.userId){
+                    return false;
+                }
+                if (!packageName.equals(other.packageName)) {
+                    return false;
+                }
+                if (activity != other.activity) {
+                    return false;
+                }
+                if (who != other.who) {
+                    if (who != null) {
+                        if (!who.equals(other.who)) {
+                            return false;
+                        }
+                    } else if (other.who != null) {
+                        return false;
+                    }
+                }
+                if (requestCode != other.requestCode) {
+                    return false;
+                }
+                if (requestIntent != other.requestIntent) {
+                    if (requestIntent != null) {
+                        if (!requestIntent.filterEquals(other.requestIntent)) {
+                            return false;
+                        }
+                    } else if (other.requestIntent != null) {
+                        return false;
+                    }
+                }
+                if (requestResolvedType != other.requestResolvedType) {
+                    if (requestResolvedType != null) {
+                        if (!requestResolvedType.equals(other.requestResolvedType)) {
+                            return false;
+                        }
+                    } else if (other.requestResolvedType != null) {
+                        return false;
+                    }
+                }
+                if (flags != other.flags) {
+                    return false;
+                }
+                return true;
+            } catch (ClassCastException e) {
+            }
+            return false;
+        }
+
+        public int hashCode() {
+            return hashCode;
+        }
+        
+        public String toString() {
+            return "Key{" + typeName() + " pkg=" + packageName
+                + " intent="
+                + (requestIntent != null
+                        ? requestIntent.toShortString(false, true, false, false) : "<null>")
+                + " flags=0x" + Integer.toHexString(flags) + " u=" + userId + "}";
+        }
+        
+        String typeName() {
+            switch (type) {
+                case ActivityManager.INTENT_SENDER_ACTIVITY:
+                    return "startActivity";
+                case ActivityManager.INTENT_SENDER_BROADCAST:
+                    return "broadcastIntent";
+                case ActivityManager.INTENT_SENDER_SERVICE:
+                    return "startService";
+                case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT:
+                    return "activityResult";
+            }
+            return Integer.toString(type);
+        }
+    }
+    
+    PendingIntentRecord(ActivityManagerService _owner, Key _k, int _u) {
+        owner = _owner;
+        key = _k;
+        uid = _u;
+        ref = new WeakReference<PendingIntentRecord>(this);
+    }
+
+    public int send(int code, Intent intent, String resolvedType,
+            IIntentReceiver finishedReceiver, String requiredPermission) {
+        return sendInner(code, intent, resolvedType, finishedReceiver,
+                requiredPermission, null, null, 0, 0, 0, null, null);
+    }
+    
+    int sendInner(int code, Intent intent, String resolvedType,
+            IIntentReceiver finishedReceiver, String requiredPermission,
+            IBinder resultTo, String resultWho, int requestCode,
+            int flagsMask, int flagsValues, Bundle options, IActivityContainer container) {
+        synchronized(owner) {
+            if (!canceled) {
+                sent = true;
+                if ((key.flags&PendingIntent.FLAG_ONE_SHOT) != 0) {
+                    owner.cancelIntentSenderLocked(this, true);
+                    canceled = true;
+                }
+                Intent finalIntent = key.requestIntent != null
+                        ? new Intent(key.requestIntent) : new Intent();
+                if (intent != null) {
+                    int changes = finalIntent.fillIn(intent, key.flags);
+                    if ((changes&Intent.FILL_IN_DATA) == 0) {
+                        resolvedType = key.requestResolvedType;
+                    }
+                } else {
+                    resolvedType = key.requestResolvedType;
+                }
+                flagsMask &= ~Intent.IMMUTABLE_FLAGS;
+                flagsValues &= flagsMask;
+                finalIntent.setFlags((finalIntent.getFlags()&~flagsMask) | flagsValues);
+                
+                final long origId = Binder.clearCallingIdentity();
+                
+                boolean sendFinish = finishedReceiver != null;
+                int userId = key.userId;
+                if (userId == UserHandle.USER_CURRENT) {
+                    userId = owner.getCurrentUserIdLocked();
+                }
+                switch (key.type) {
+                    case ActivityManager.INTENT_SENDER_ACTIVITY:
+                        if (options == null) {
+                            options = key.options;
+                        } else if (key.options != null) {
+                            Bundle opts = new Bundle(key.options);
+                            opts.putAll(options);
+                            options = opts;
+                        }
+                        try {
+                            if (key.allIntents != null && key.allIntents.length > 1) {
+                                Intent[] allIntents = new Intent[key.allIntents.length];
+                                String[] allResolvedTypes = new String[key.allIntents.length];
+                                System.arraycopy(key.allIntents, 0, allIntents, 0,
+                                        key.allIntents.length);
+                                if (key.allResolvedTypes != null) {
+                                    System.arraycopy(key.allResolvedTypes, 0, allResolvedTypes, 0,
+                                            key.allResolvedTypes.length);
+                                }
+                                allIntents[allIntents.length-1] = finalIntent;
+                                allResolvedTypes[allResolvedTypes.length-1] = resolvedType;
+                                owner.startActivitiesInPackage(uid, key.packageName, allIntents,
+                                        allResolvedTypes, resultTo, options, userId);
+                            } else {
+                                owner.startActivityInPackage(uid, key.packageName, finalIntent,
+                                        resolvedType, resultTo, resultWho, requestCode, 0,
+                                        options, userId, container);
+                            }
+                        } catch (RuntimeException e) {
+                            Slog.w(ActivityManagerService.TAG,
+                                    "Unable to send startActivity intent", e);
+                        }
+                        break;
+                    case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT:
+                        key.activity.task.stack.sendActivityResultLocked(-1, key.activity,
+                                key.who, key.requestCode, code, finalIntent);
+                        break;
+                    case ActivityManager.INTENT_SENDER_BROADCAST:
+                        try {
+                            // If a completion callback has been requested, require
+                            // that the broadcast be delivered synchronously
+                            owner.broadcastIntentInPackage(key.packageName, uid,
+                                    finalIntent, resolvedType,
+                                    finishedReceiver, code, null, null,
+                                requiredPermission, (finishedReceiver != null), false, userId);
+                            sendFinish = false;
+                        } catch (RuntimeException e) {
+                            Slog.w(ActivityManagerService.TAG,
+                                    "Unable to send startActivity intent", e);
+                        }
+                        break;
+                    case ActivityManager.INTENT_SENDER_SERVICE:
+                        try {
+                            owner.startServiceInPackage(uid,
+                                    finalIntent, resolvedType, userId);
+                        } catch (RuntimeException e) {
+                            Slog.w(ActivityManagerService.TAG,
+                                    "Unable to send startService intent", e);
+                        }
+                        break;
+                }
+                
+                if (sendFinish) {
+                    try {
+                        finishedReceiver.performReceive(new Intent(finalIntent), 0,
+                                null, null, false, false, key.userId);
+                    } catch (RemoteException e) {
+                    }
+                }
+                
+                Binder.restoreCallingIdentity(origId);
+                
+                return 0;
+            }
+        }
+        return ActivityManager.START_CANCELED;
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            if (!canceled) {
+                owner.mHandler.sendMessage(owner.mHandler.obtainMessage(
+                        ActivityManagerService.FINALIZE_PENDING_INTENT_MSG, this));
+            }
+        } finally {
+            super.finalize();
+        }
+    }
+
+    public void completeFinalize() {
+        synchronized(owner) {
+            WeakReference<PendingIntentRecord> current =
+                    owner.mIntentSenderRecords.get(key);
+            if (current == ref) {
+                owner.mIntentSenderRecords.remove(key);
+            }
+        }
+    }
+    
+    void dump(PrintWriter pw, String prefix) {
+        pw.print(prefix); pw.print("uid="); pw.print(uid);
+                pw.print(" packageName="); pw.print(key.packageName);
+                pw.print(" type="); pw.print(key.typeName());
+                pw.print(" flags=0x"); pw.println(Integer.toHexString(key.flags));
+        if (key.activity != null || key.who != null) {
+            pw.print(prefix); pw.print("activity="); pw.print(key.activity);
+                    pw.print(" who="); pw.println(key.who);
+        }
+        if (key.requestCode != 0 || key.requestResolvedType != null) {
+            pw.print(prefix); pw.print("requestCode="); pw.print(key.requestCode);
+                    pw.print(" requestResolvedType="); pw.println(key.requestResolvedType);
+        }
+        if (key.requestIntent != null) {
+            pw.print(prefix); pw.print("requestIntent=");
+                    pw.println(key.requestIntent.toShortString(false, true, true, true));
+        }
+        if (sent || canceled) {
+            pw.print(prefix); pw.print("sent="); pw.print(sent);
+                    pw.print(" canceled="); pw.println(canceled);
+        }
+    }
+
+    public String toString() {
+        if (stringName != null) {
+            return stringName;
+        }
+        StringBuilder sb = new StringBuilder(128);
+        sb.append("PendingIntentRecord{");
+        sb.append(Integer.toHexString(System.identityHashCode(this)));
+        sb.append(' ');
+        sb.append(key.packageName);
+        sb.append(' ');
+        sb.append(key.typeName());
+        sb.append('}');
+        return stringName = sb.toString();
+    }
+}
diff --git a/services/java/com/android/server/am/PendingThumbnailsRecord.java b/services/core/java/com/android/server/am/PendingThumbnailsRecord.java
similarity index 100%
rename from services/java/com/android/server/am/PendingThumbnailsRecord.java
rename to services/core/java/com/android/server/am/PendingThumbnailsRecord.java
diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java
new file mode 100644
index 0000000..f5920c8
--- /dev/null
+++ b/services/core/java/com/android/server/am/ProcessList.java
@@ -0,0 +1,594 @@
+/*
+ * 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.server.am;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+import android.app.ActivityManager;
+import com.android.internal.util.MemInfoReader;
+import com.android.server.wm.WindowManagerService;
+
+import android.content.res.Resources;
+import android.graphics.Point;
+import android.os.SystemProperties;
+import android.net.LocalSocketAddress;
+import android.net.LocalSocket;
+import android.util.Slog;
+import android.view.Display;
+
+/**
+ * Activity manager code dealing with processes.
+ */
+final class ProcessList {
+    // The minimum time we allow between crashes, for us to consider this
+    // application to be bad and stop and its services and reject broadcasts.
+    static final int MIN_CRASH_INTERVAL = 60*1000;
+
+    // OOM adjustments for processes in various states:
+
+    // Adjustment used in certain places where we don't know it yet.
+    // (Generally this is something that is going to be cached, but we
+    // don't know the exact value in the cached range to assign yet.)
+    static final int UNKNOWN_ADJ = 16;
+
+    // This is a process only hosting activities that are not visible,
+    // so it can be killed without any disruption.
+    static final int CACHED_APP_MAX_ADJ = 15;
+    static final int CACHED_APP_MIN_ADJ = 9;
+
+    // The B list of SERVICE_ADJ -- these are the old and decrepit
+    // services that aren't as shiny and interesting as the ones in the A list.
+    static final int SERVICE_B_ADJ = 8;
+
+    // This is the process of the previous application that the user was in.
+    // This process is kept above other things, because it is very common to
+    // switch back to the previous app.  This is important both for recent
+    // task switch (toggling between the two top recent apps) as well as normal
+    // UI flow such as clicking on a URI in the e-mail app to view in the browser,
+    // and then pressing back to return to e-mail.
+    static final int PREVIOUS_APP_ADJ = 7;
+
+    // This is a process holding the home application -- we want to try
+    // avoiding killing it, even if it would normally be in the background,
+    // because the user interacts with it so much.
+    static final int HOME_APP_ADJ = 6;
+
+    // This is a process holding an application service -- killing it will not
+    // have much of an impact as far as the user is concerned.
+    static final int SERVICE_ADJ = 5;
+
+    // This is a process with a heavy-weight application.  It is in the
+    // background, but we want to try to avoid killing it.  Value set in
+    // system/rootdir/init.rc on startup.
+    static final int HEAVY_WEIGHT_APP_ADJ = 4;
+
+    // This is a process currently hosting a backup operation.  Killing it
+    // is not entirely fatal but is generally a bad idea.
+    static final int BACKUP_APP_ADJ = 3;
+
+    // This is a process only hosting components that are perceptible to the
+    // user, and we really want to avoid killing them, but they are not
+    // immediately visible. An example is background music playback.
+    static final int PERCEPTIBLE_APP_ADJ = 2;
+
+    // This is a process only hosting activities that are visible to the
+    // user, so we'd prefer they don't disappear.
+    static final int VISIBLE_APP_ADJ = 1;
+
+    // This is the process running the current foreground app.  We'd really
+    // rather not kill it!
+    static final int FOREGROUND_APP_ADJ = 0;
+
+    // This is a system persistent process, such as telephony.  Definitely
+    // don't want to kill it, but doing so is not completely fatal.
+    static final int PERSISTENT_PROC_ADJ = -12;
+
+    // The system process runs at the default adjustment.
+    static final int SYSTEM_ADJ = -16;
+
+    // Special code for native processes that are not being managed by the system (so
+    // don't have an oom adj assigned by the system).
+    static final int NATIVE_ADJ = -17;
+
+    // Memory pages are 4K.
+    static final int PAGE_SIZE = 4*1024;
+
+    // The minimum number of cached apps we want to be able to keep around,
+    // without empty apps being able to push them out of memory.
+    static final int MIN_CACHED_APPS = 2;
+
+    // The maximum number of cached processes we will keep around before killing them.
+    // NOTE: this constant is *only* a control to not let us go too crazy with
+    // keeping around processes on devices with large amounts of RAM.  For devices that
+    // are tighter on RAM, the out of memory killer is responsible for killing background
+    // processes as RAM is needed, and we should *never* be relying on this limit to
+    // kill them.  Also note that this limit only applies to cached background processes;
+    // we have no limit on the number of service, visible, foreground, or other such
+    // processes and the number of those processes does not count against the cached
+    // process limit.
+    static final int MAX_CACHED_APPS = 24;
+
+    // We allow empty processes to stick around for at most 30 minutes.
+    static final long MAX_EMPTY_TIME = 30*60*1000;
+
+    // The maximum number of empty app processes we will let sit around.
+    private static final int MAX_EMPTY_APPS = computeEmptyProcessLimit(MAX_CACHED_APPS);
+
+    // The number of empty apps at which we don't consider it necessary to do
+    // memory trimming.
+    static final int TRIM_EMPTY_APPS = MAX_EMPTY_APPS/2;
+
+    // The number of cached at which we don't consider it necessary to do
+    // memory trimming.
+    static final int TRIM_CACHED_APPS = ((MAX_CACHED_APPS-MAX_EMPTY_APPS)*2)/3;
+
+    // Threshold of number of cached+empty where we consider memory critical.
+    static final int TRIM_CRITICAL_THRESHOLD = 3;
+
+    // Threshold of number of cached+empty where we consider memory critical.
+    static final int TRIM_LOW_THRESHOLD = 5;
+
+    // Low Memory Killer Daemon command codes.
+    // These must be kept in sync with the definitions in lmkd.c
+    //
+    // LMK_TARGET <minfree> <minkillprio> ... (up to 6 pairs)
+    // LMK_PROCPRIO <pid> <prio>
+    // LMK_PROCREMOVE <pid>
+    static final byte LMK_TARGET = 0;
+    static final byte LMK_PROCPRIO = 1;
+    static final byte LMK_PROCREMOVE = 2;
+
+    // These are the various interesting memory levels that we will give to
+    // the OOM killer.  Note that the OOM killer only supports 6 slots, so we
+    // can't give it a different value for every possible kind of process.
+    private final int[] mOomAdj = new int[] {
+            FOREGROUND_APP_ADJ, VISIBLE_APP_ADJ, PERCEPTIBLE_APP_ADJ,
+            BACKUP_APP_ADJ, CACHED_APP_MIN_ADJ, CACHED_APP_MAX_ADJ
+    };
+    // These are the low-end OOM level limits.  This is appropriate for an
+    // HVGA or smaller phone with less than 512MB.  Values are in KB.
+    private final int[] mOomMinFreeLow = new int[] {
+            8192, 12288, 16384,
+            24576, 28672, 32768
+    };
+    // These are the high-end OOM level limits.  This is appropriate for a
+    // 1280x800 or larger screen with around 1GB RAM.  Values are in KB.
+    private final int[] mOomMinFreeHigh = new int[] {
+            49152, 61440, 73728,
+            86016, 98304, 122880
+    };
+    // The actual OOM killer memory levels we are using.
+    private final int[] mOomMinFree = new int[mOomAdj.length];
+
+    private final long mTotalMemMb;
+
+    private long mCachedRestoreLevel;
+
+    private boolean mHaveDisplaySize;
+
+    private static LocalSocket sLmkdSocket;
+    private static OutputStream sLmkdOutputStream;
+
+    ProcessList() {
+        MemInfoReader minfo = new MemInfoReader();
+        minfo.readMemInfo();
+        mTotalMemMb = minfo.getTotalSize()/(1024*1024);
+        updateOomLevels(0, 0, false);
+    }
+
+    void applyDisplaySize(WindowManagerService wm) {
+        if (!mHaveDisplaySize) {
+            Point p = new Point();
+            wm.getBaseDisplaySize(Display.DEFAULT_DISPLAY, p);
+            if (p.x != 0 && p.y != 0) {
+                updateOomLevels(p.x, p.y, true);
+                mHaveDisplaySize = true;
+            }
+        }
+    }
+
+    private void updateOomLevels(int displayWidth, int displayHeight, boolean write) {
+        // Scale buckets from avail memory: at 300MB we use the lowest values to
+        // 700MB or more for the top values.
+        float scaleMem = ((float)(mTotalMemMb-300))/(700-300);
+
+        // Scale buckets from screen size.
+        int minSize = 480*800;  //  384000
+        int maxSize = 1280*800; // 1024000  230400 870400  .264
+        float scaleDisp = ((float)(displayWidth*displayHeight)-minSize)/(maxSize-minSize);
+        if (false) {
+            Slog.i("XXXXXX", "scaleMem=" + scaleMem);
+            Slog.i("XXXXXX", "scaleDisp=" + scaleDisp + " dw=" + displayWidth
+                    + " dh=" + displayHeight);
+        }
+
+        float scale = scaleMem > scaleDisp ? scaleMem : scaleDisp;
+        if (scale < 0) scale = 0;
+        else if (scale > 1) scale = 1;
+        int minfree_adj = Resources.getSystem().getInteger(
+                com.android.internal.R.integer.config_lowMemoryKillerMinFreeKbytesAdjust);
+        int minfree_abs = Resources.getSystem().getInteger(
+                com.android.internal.R.integer.config_lowMemoryKillerMinFreeKbytesAbsolute);
+        if (false) {
+            Slog.i("XXXXXX", "minfree_adj=" + minfree_adj + " minfree_abs=" + minfree_abs);
+        }
+
+        for (int i=0; i<mOomAdj.length; i++) {
+            int low = mOomMinFreeLow[i];
+            int high = mOomMinFreeHigh[i];
+            mOomMinFree[i] = (int)(low + ((high-low)*scale));
+        }
+
+        if (minfree_abs >= 0) {
+            for (int i=0; i<mOomAdj.length; i++) {
+                mOomMinFree[i] = (int)((float)minfree_abs * mOomMinFree[i] / mOomMinFree[mOomAdj.length - 1]);
+            }
+        }
+
+        if (minfree_adj != 0) {
+            for (int i=0; i<mOomAdj.length; i++) {
+                mOomMinFree[i] += (int)((float)minfree_adj * mOomMinFree[i] / mOomMinFree[mOomAdj.length - 1]);
+                if (mOomMinFree[i] < 0) {
+                    mOomMinFree[i] = 0;
+                }
+            }
+        }
+
+        // The maximum size we will restore a process from cached to background, when under
+        // memory duress, is 1/3 the size we have reserved for kernel caches and other overhead
+        // before killing background processes.
+        mCachedRestoreLevel = (getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024) / 3;
+
+        // Ask the kernel to try to keep enough memory free to allocate 3 full
+        // screen 32bpp buffers without entering direct reclaim.
+        int reserve = displayWidth * displayHeight * 4 * 3 / 1024;
+        int reserve_adj = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAdjust);
+        int reserve_abs = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAbsolute);
+
+        if (reserve_abs >= 0) {
+            reserve = reserve_abs;
+        }
+
+        if (reserve_adj != 0) {
+            reserve += reserve_adj;
+            if (reserve < 0) {
+                reserve = 0;
+            }
+        }
+
+        if (write) {
+            ByteBuffer buf = ByteBuffer.allocate(4 * (2*mOomAdj.length + 1));
+            buf.putInt(LMK_TARGET);
+            for (int i=0; i<mOomAdj.length; i++) {
+                buf.putInt((mOomMinFree[i]*1024)/PAGE_SIZE);
+                buf.putInt(mOomAdj[i]);
+            }
+
+            writeLmkd(buf);
+            SystemProperties.set("sys.sysctl.extra_free_kbytes", Integer.toString(reserve));
+        }
+        // GB: 2048,3072,4096,6144,7168,8192
+        // HC: 8192,10240,12288,14336,16384,20480
+    }
+
+    public static int computeEmptyProcessLimit(int totalProcessLimit) {
+        return (totalProcessLimit*2)/3;
+    }
+
+    private static String buildOomTag(String prefix, String space, int val, int base) {
+        if (val == base) {
+            if (space == null) return prefix;
+            return prefix + "  ";
+        }
+        return prefix + "+" + Integer.toString(val-base);
+    }
+
+    public static String makeOomAdjString(int setAdj) {
+        if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
+            return buildOomTag("cch", "  ", setAdj, ProcessList.CACHED_APP_MIN_ADJ);
+        } else if (setAdj >= ProcessList.SERVICE_B_ADJ) {
+            return buildOomTag("svcb ", null, setAdj, ProcessList.SERVICE_B_ADJ);
+        } else if (setAdj >= ProcessList.PREVIOUS_APP_ADJ) {
+            return buildOomTag("prev ", null, setAdj, ProcessList.PREVIOUS_APP_ADJ);
+        } else if (setAdj >= ProcessList.HOME_APP_ADJ) {
+            return buildOomTag("home ", null, setAdj, ProcessList.HOME_APP_ADJ);
+        } else if (setAdj >= ProcessList.SERVICE_ADJ) {
+            return buildOomTag("svc  ", null, setAdj, ProcessList.SERVICE_ADJ);
+        } else if (setAdj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
+            return buildOomTag("hvy  ", null, setAdj, ProcessList.HEAVY_WEIGHT_APP_ADJ);
+        } else if (setAdj >= ProcessList.BACKUP_APP_ADJ) {
+            return buildOomTag("bkup ", null, setAdj, ProcessList.BACKUP_APP_ADJ);
+        } else if (setAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
+            return buildOomTag("prcp ", null, setAdj, ProcessList.PERCEPTIBLE_APP_ADJ);
+        } else if (setAdj >= ProcessList.VISIBLE_APP_ADJ) {
+            return buildOomTag("vis  ", null, setAdj, ProcessList.VISIBLE_APP_ADJ);
+        } else if (setAdj >= ProcessList.FOREGROUND_APP_ADJ) {
+            return buildOomTag("fore ", null, setAdj, ProcessList.FOREGROUND_APP_ADJ);
+        } else if (setAdj >= ProcessList.PERSISTENT_PROC_ADJ) {
+            return buildOomTag("pers ", null, setAdj, ProcessList.PERSISTENT_PROC_ADJ);
+        } else if (setAdj >= ProcessList.SYSTEM_ADJ) {
+            return buildOomTag("sys  ", null, setAdj, ProcessList.SYSTEM_ADJ);
+        } else if (setAdj >= ProcessList.NATIVE_ADJ) {
+            return buildOomTag("ntv  ", null, setAdj, ProcessList.NATIVE_ADJ);
+        } else {
+            return Integer.toString(setAdj);
+        }
+    }
+
+    public static String makeProcStateString(int curProcState) {
+        String procState;
+        switch (curProcState) {
+            case -1:
+                procState = "N ";
+                break;
+            case ActivityManager.PROCESS_STATE_PERSISTENT:
+                procState = "P ";
+                break;
+            case ActivityManager.PROCESS_STATE_PERSISTENT_UI:
+                procState = "PU";
+                break;
+            case ActivityManager.PROCESS_STATE_TOP:
+                procState = "T ";
+                break;
+            case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
+                procState = "IF";
+                break;
+            case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
+                procState = "IB";
+                break;
+            case ActivityManager.PROCESS_STATE_BACKUP:
+                procState = "BU";
+                break;
+            case ActivityManager.PROCESS_STATE_HEAVY_WEIGHT:
+                procState = "HW";
+                break;
+            case ActivityManager.PROCESS_STATE_SERVICE:
+                procState = "S ";
+                break;
+            case ActivityManager.PROCESS_STATE_RECEIVER:
+                procState = "R ";
+                break;
+            case ActivityManager.PROCESS_STATE_HOME:
+                procState = "HO";
+                break;
+            case ActivityManager.PROCESS_STATE_LAST_ACTIVITY:
+                procState = "LA";
+                break;
+            case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY:
+                procState = "CA";
+                break;
+            case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
+                procState = "Ca";
+                break;
+            case ActivityManager.PROCESS_STATE_CACHED_EMPTY:
+                procState = "CE";
+                break;
+            default:
+                procState = "??";
+                break;
+        }
+        return procState;
+    }
+
+    public static void appendRamKb(StringBuilder sb, long ramKb) {
+        for (int j=0, fact=10; j<6; j++, fact*=10) {
+            if (ramKb < fact) {
+                sb.append(' ');
+            }
+        }
+        sb.append(ramKb);
+    }
+
+    // The minimum amount of time after a state change it is safe ro collect PSS.
+    public static final int PSS_MIN_TIME_FROM_STATE_CHANGE = 15*1000;
+
+    // The maximum amount of time we want to go between PSS collections.
+    public static final int PSS_MAX_INTERVAL = 30*60*1000;
+
+    // The minimum amount of time between successive PSS requests for *all* processes.
+    public static final int PSS_ALL_INTERVAL = 10*60*1000;
+
+    // The minimum amount of time between successive PSS requests for a process.
+    private static final int PSS_SHORT_INTERVAL = 2*60*1000;
+
+    // The amount of time until PSS when a process first becomes top.
+    private static final int PSS_FIRST_TOP_INTERVAL = 10*1000;
+
+    // The amount of time until PSS when a process first goes into the background.
+    private static final int PSS_FIRST_BACKGROUND_INTERVAL = 20*1000;
+
+    // The amount of time until PSS when a process first becomes cached.
+    private static final int PSS_FIRST_CACHED_INTERVAL = 30*1000;
+
+    // The amount of time until PSS when an important process stays in the same state.
+    private static final int PSS_SAME_IMPORTANT_INTERVAL = 15*60*1000;
+
+    // The amount of time until PSS when a service process stays in the same state.
+    private static final int PSS_SAME_SERVICE_INTERVAL = 20*60*1000;
+
+    // The amount of time until PSS when a cached process stays in the same state.
+    private static final int PSS_SAME_CACHED_INTERVAL = 30*60*1000;
+
+    public static final int PROC_MEM_PERSISTENT = 0;
+    public static final int PROC_MEM_TOP = 1;
+    public static final int PROC_MEM_IMPORTANT = 2;
+    public static final int PROC_MEM_SERVICE = 3;
+    public static final int PROC_MEM_CACHED = 4;
+
+    private static final int[] sProcStateToProcMem = new int[] {
+        PROC_MEM_PERSISTENT,            // ActivityManager.PROCESS_STATE_PERSISTENT
+        PROC_MEM_PERSISTENT,            // ActivityManager.PROCESS_STATE_PERSISTENT_UI
+        PROC_MEM_TOP,                   // ActivityManager.PROCESS_STATE_TOP
+        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
+        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_BACKUP
+        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT
+        PROC_MEM_SERVICE,               // ActivityManager.PROCESS_STATE_SERVICE
+        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_RECEIVER
+        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_HOME
+        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_LAST_ACTIVITY
+        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY
+        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT
+        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_CACHED_EMPTY
+    };
+
+    private static final long[] sFirstAwakePssTimes = new long[] {
+        PSS_SHORT_INTERVAL,             // ActivityManager.PROCESS_STATE_PERSISTENT
+        PSS_SHORT_INTERVAL,             // ActivityManager.PROCESS_STATE_PERSISTENT_UI
+        PSS_FIRST_TOP_INTERVAL,         // ActivityManager.PROCESS_STATE_TOP
+        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
+        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_BACKUP
+        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT
+        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_SERVICE
+        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_RECEIVER
+        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_HOME
+        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_LAST_ACTIVITY
+        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY
+        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT
+        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_CACHED_EMPTY
+    };
+
+    private static final long[] sSameAwakePssTimes = new long[] {
+        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_PERSISTENT
+        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_PERSISTENT_UI
+        PSS_SHORT_INTERVAL,             // ActivityManager.PROCESS_STATE_TOP
+        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
+        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
+        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_BACKUP
+        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT
+        PSS_SAME_SERVICE_INTERVAL,      // ActivityManager.PROCESS_STATE_SERVICE
+        PSS_SAME_SERVICE_INTERVAL,      // ActivityManager.PROCESS_STATE_RECEIVER
+        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_HOME
+        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_LAST_ACTIVITY
+        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY
+        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT
+        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_CACHED_EMPTY
+    };
+
+    public static boolean procStatesDifferForMem(int procState1, int procState2) {
+        return sProcStateToProcMem[procState1] != sProcStateToProcMem[procState2];
+    }
+
+    public static long computeNextPssTime(int procState, boolean first, boolean sleeping,
+            long now) {
+        final long[] table = sleeping
+                ? (first
+                        ? sFirstAwakePssTimes
+                        : sSameAwakePssTimes)
+                : (first
+                        ? sFirstAwakePssTimes
+                        : sSameAwakePssTimes);
+        return now + table[procState];
+    }
+
+    long getMemLevel(int adjustment) {
+        for (int i=0; i<mOomAdj.length; i++) {
+            if (adjustment <= mOomAdj[i]) {
+                return mOomMinFree[i] * 1024;
+            }
+        }
+        return mOomMinFree[mOomAdj.length-1] * 1024;
+    }
+
+    /**
+     * Return the maximum pss size in kb that we consider a process acceptable to
+     * restore from its cached state for running in the background when RAM is low.
+     */
+    long getCachedRestoreThresholdKb() {
+        return mCachedRestoreLevel;
+    }
+
+    /**
+     * Set the out-of-memory badness adjustment for a process.
+     *
+     * @param pid The process identifier to set.
+     * @param amt Adjustment value -- lmkd allows -16 to +15.
+     *
+     * {@hide}
+     */
+    public static final void setOomAdj(int pid, int amt) {
+        if (amt == UNKNOWN_ADJ)
+            return;
+
+        ByteBuffer buf = ByteBuffer.allocate(4 * 3);
+        buf.putInt(LMK_PROCPRIO);
+        buf.putInt(pid);
+        buf.putInt(amt);
+        writeLmkd(buf);
+    }
+
+    /*
+     * {@hide}
+     */
+    public static final void remove(int pid) {
+        ByteBuffer buf = ByteBuffer.allocate(4 * 2);
+        buf.putInt(LMK_PROCREMOVE);
+        buf.putInt(pid);
+        writeLmkd(buf);
+    }
+
+    private static boolean openLmkdSocket() {
+        try {
+            sLmkdSocket = new LocalSocket(LocalSocket.SOCKET_SEQPACKET);
+            sLmkdSocket.connect(
+                new LocalSocketAddress("lmkd",
+                        LocalSocketAddress.Namespace.RESERVED));
+            sLmkdOutputStream = sLmkdSocket.getOutputStream();
+        } catch (IOException ex) {
+            Slog.w(ActivityManagerService.TAG,
+                   "lowmemorykiller daemon socket open failed");
+            sLmkdSocket = null;
+            return false;
+        }
+
+        return true;
+    }
+
+    private static void writeLmkd(ByteBuffer buf) {
+
+        for (int i = 0; i < 3; i++) {
+            if (sLmkdSocket == null) {
+                    if (openLmkdSocket() == false) {
+                        try {
+                            Thread.sleep(1000);
+                        } catch (InterruptedException ie) {
+                        }
+                        continue;
+                    }
+            }
+
+            try {
+                sLmkdOutputStream.write(buf.array(), 0, buf.position());
+                return;
+            } catch (IOException ex) {
+                Slog.w(ActivityManagerService.TAG,
+                       "Error writing to lowmemorykiller socket");
+
+                try {
+                    sLmkdSocket.close();
+                } catch (IOException ex2) {
+                }
+
+                sLmkdSocket = null;
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/am/ProcessMemInfo.java b/services/core/java/com/android/server/am/ProcessMemInfo.java
similarity index 100%
rename from services/java/com/android/server/am/ProcessMemInfo.java
rename to services/core/java/com/android/server/am/ProcessMemInfo.java
diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
similarity index 100%
rename from services/java/com/android/server/am/ProcessRecord.java
rename to services/core/java/com/android/server/am/ProcessRecord.java
diff --git a/services/java/com/android/server/am/ProcessStatsService.java b/services/core/java/com/android/server/am/ProcessStatsService.java
similarity index 100%
rename from services/java/com/android/server/am/ProcessStatsService.java
rename to services/core/java/com/android/server/am/ProcessStatsService.java
diff --git a/services/java/com/android/server/am/ProviderMap.java b/services/core/java/com/android/server/am/ProviderMap.java
similarity index 100%
rename from services/java/com/android/server/am/ProviderMap.java
rename to services/core/java/com/android/server/am/ProviderMap.java
diff --git a/services/java/com/android/server/am/ReceiverList.java b/services/core/java/com/android/server/am/ReceiverList.java
similarity index 100%
rename from services/java/com/android/server/am/ReceiverList.java
rename to services/core/java/com/android/server/am/ReceiverList.java
diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java
new file mode 100644
index 0000000..cb04835
--- /dev/null
+++ b/services/core/java/com/android/server/am/ServiceRecord.java
@@ -0,0 +1,544 @@
+/*
+ * Copyright (C) 2006 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 com.android.internal.app.ProcessStats;
+import com.android.internal.os.BatteryStatsImpl;
+import com.android.server.LocalServices;
+import com.android.server.notification.NotificationManagerInternal;
+
+import android.app.INotificationManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ServiceInfo;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.ArrayMap;
+import android.util.Slog;
+import android.util.TimeUtils;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A running application service.
+ */
+final class ServiceRecord extends Binder {
+    // Maximum number of delivery attempts before giving up.
+    static final int MAX_DELIVERY_COUNT = 3;
+
+    // Maximum number of times it can fail during execution before giving up.
+    static final int MAX_DONE_EXECUTING_COUNT = 6;
+
+    final ActivityManagerService ams;
+    final BatteryStatsImpl.Uid.Pkg.Serv stats;
+    final ComponentName name; // service component.
+    final String shortName; // name.flattenToShortString().
+    final Intent.FilterComparison intent;
+                            // original intent used to find service.
+    final ServiceInfo serviceInfo;
+                            // all information about the service.
+    final ApplicationInfo appInfo;
+                            // information about service's app.
+    final int userId;       // user that this service is running as
+    final String packageName; // the package implementing intent's component
+    final String processName; // process where this component wants to run
+    final String permission;// permission needed to access service
+    final String baseDir;   // where activity source (resources etc) located
+    final String resDir;   // where public activity source (public resources etc) located
+    final String dataDir;   // where activity data should go
+    final boolean exported; // from ServiceInfo.exported
+    final Runnable restarter; // used to schedule retries of starting the service
+    final long createTime;  // when this service was created
+    final ArrayMap<Intent.FilterComparison, IntentBindRecord> bindings
+            = new ArrayMap<Intent.FilterComparison, IntentBindRecord>();
+                            // All active bindings to the service.
+    final ArrayMap<IBinder, ArrayList<ConnectionRecord>> connections
+            = new ArrayMap<IBinder, ArrayList<ConnectionRecord>>();
+                            // IBinder -> ConnectionRecord of all bound clients
+
+    ProcessRecord app;      // where this service is running or null.
+    ProcessRecord isolatedProc; // keep track of isolated process, if requested
+    ProcessStats.ServiceState tracker; // tracking service execution, may be null
+    ProcessStats.ServiceState restartTracker; // tracking service restart
+    boolean delayed;        // are we waiting to start this service in the background?
+    boolean isForeground;   // is service currently in foreground mode?
+    int foregroundId;       // Notification ID of last foreground req.
+    Notification foregroundNoti; // Notification record of foreground state.
+    long lastActivity;      // last time there was some activity on the service.
+    long startingBgTimeout;  // time at which we scheduled this for a delayed start.
+    boolean startRequested; // someone explicitly called start?
+    boolean delayedStop;    // service has been stopped but is in a delayed start?
+    boolean stopIfKilled;   // last onStart() said to stop if service killed?
+    boolean callStart;      // last onStart() has asked to alway be called on restart.
+    int executeNesting;     // number of outstanding operations keeping foreground.
+    boolean executeFg;      // should we be executing in the foreground?
+    long executingStart;    // start time of last execute request.
+    boolean createdFromFg;  // was this service last created due to a foreground process call?
+    int crashCount;         // number of times proc has crashed with service running
+    int totalRestartCount;  // number of times we have had to restart.
+    int restartCount;       // number of restarts performed in a row.
+    long restartDelay;      // delay until next restart attempt.
+    long restartTime;       // time of last restart.
+    long nextRestartTime;   // time when restartDelay will expire.
+
+    String stringName;      // caching of toString
+    
+    private int lastStartId;    // identifier of most recent start request.
+
+    static class StartItem {
+        final ServiceRecord sr;
+        final boolean taskRemoved;
+        final int id;
+        final Intent intent;
+        final ActivityManagerService.NeededUriGrants neededGrants;
+        long deliveredTime;
+        int deliveryCount;
+        int doneExecutingCount;
+        UriPermissionOwner uriPermissions;
+
+        String stringName;      // caching of toString
+
+        StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent,
+                ActivityManagerService.NeededUriGrants _neededGrants) {
+            sr = _sr;
+            taskRemoved = _taskRemoved;
+            id = _id;
+            intent = _intent;
+            neededGrants = _neededGrants;
+        }
+
+        UriPermissionOwner getUriPermissionsLocked() {
+            if (uriPermissions == null) {
+                uriPermissions = new UriPermissionOwner(sr.ams, this);
+            }
+            return uriPermissions;
+        }
+
+        void removeUriPermissionsLocked() {
+            if (uriPermissions != null) {
+                uriPermissions.removeUriPermissionsLocked();
+                uriPermissions = null;
+            }
+        }
+
+        public String toString() {
+            if (stringName != null) {
+                return stringName;
+            }
+            StringBuilder sb = new StringBuilder(128);
+            sb.append("ServiceRecord{")
+                .append(Integer.toHexString(System.identityHashCode(sr)))
+                .append(' ').append(sr.shortName)
+                .append(" StartItem ")
+                .append(Integer.toHexString(System.identityHashCode(this)))
+                .append(" id=").append(id).append('}');
+            return stringName = sb.toString();
+        }
+    }
+
+    final ArrayList<StartItem> deliveredStarts = new ArrayList<StartItem>();
+                            // start() arguments which been delivered.
+    final ArrayList<StartItem> pendingStarts = new ArrayList<StartItem>();
+                            // start() arguments that haven't yet been delivered.
+
+    void dumpStartList(PrintWriter pw, String prefix, List<StartItem> list, long now) {
+        final int N = list.size();
+        for (int i=0; i<N; i++) {
+            StartItem si = list.get(i);
+            pw.print(prefix); pw.print("#"); pw.print(i);
+                    pw.print(" id="); pw.print(si.id);
+                    if (now != 0) {
+                        pw.print(" dur=");
+                        TimeUtils.formatDuration(si.deliveredTime, now, pw);
+                    }
+                    if (si.deliveryCount != 0) {
+                        pw.print(" dc="); pw.print(si.deliveryCount);
+                    }
+                    if (si.doneExecutingCount != 0) {
+                        pw.print(" dxc="); pw.print(si.doneExecutingCount);
+                    }
+                    pw.println("");
+            pw.print(prefix); pw.print("  intent=");
+                    if (si.intent != null) pw.println(si.intent.toString());
+                    else pw.println("null");
+            if (si.neededGrants != null) {
+                pw.print(prefix); pw.print("  neededGrants=");
+                        pw.println(si.neededGrants);
+            }
+            if (si.uriPermissions != null) {
+                if (si.uriPermissions.readUriPermissions != null) {
+                    pw.print(prefix); pw.print("  readUriPermissions=");
+                            pw.println(si.uriPermissions.readUriPermissions);
+                }
+                if (si.uriPermissions.writeUriPermissions != null) {
+                    pw.print(prefix); pw.print("  writeUriPermissions=");
+                            pw.println(si.uriPermissions.writeUriPermissions);
+                }
+            }
+        }
+    }
+    
+    void dump(PrintWriter pw, String prefix) {
+        pw.print(prefix); pw.print("intent={");
+                pw.print(intent.getIntent().toShortString(false, true, false, true));
+                pw.println('}');
+        pw.print(prefix); pw.print("packageName="); pw.println(packageName);
+        pw.print(prefix); pw.print("processName="); pw.println(processName);
+        if (permission != null) {
+            pw.print(prefix); pw.print("permission="); pw.println(permission);
+        }
+        long now = SystemClock.uptimeMillis();
+        long nowReal = SystemClock.elapsedRealtime();
+        pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
+        if (!resDir.equals(baseDir)) {
+            pw.print(prefix); pw.print("resDir="); pw.println(resDir);
+        }
+        pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
+        pw.print(prefix); pw.print("app="); pw.println(app);
+        if (isolatedProc != null) {
+            pw.print(prefix); pw.print("isolatedProc="); pw.println(isolatedProc);
+        }
+        if (delayed) {
+            pw.print(prefix); pw.print("delayed="); pw.println(delayed);
+        }
+        if (isForeground || foregroundId != 0) {
+            pw.print(prefix); pw.print("isForeground="); pw.print(isForeground);
+                    pw.print(" foregroundId="); pw.print(foregroundId);
+                    pw.print(" foregroundNoti="); pw.println(foregroundNoti);
+        }
+        pw.print(prefix); pw.print("createTime=");
+                TimeUtils.formatDuration(createTime, nowReal, pw);
+                pw.print(" startingBgTimeout=");
+                TimeUtils.formatDuration(startingBgTimeout, now, pw);
+                pw.println();
+        pw.print(prefix); pw.print("lastActivity=");
+                TimeUtils.formatDuration(lastActivity, now, pw);
+                pw.print(" restartTime=");
+                TimeUtils.formatDuration(restartTime, now, pw);
+                pw.print(" createdFromFg="); pw.println(createdFromFg);
+        if (startRequested || delayedStop || lastStartId != 0) {
+            pw.print(prefix); pw.print("startRequested="); pw.print(startRequested);
+                    pw.print(" delayedStop="); pw.print(delayedStop);
+                    pw.print(" stopIfKilled="); pw.print(stopIfKilled);
+                    pw.print(" callStart="); pw.print(callStart);
+                    pw.print(" lastStartId="); pw.println(lastStartId);
+        }
+        if (executeNesting != 0) {
+            pw.print(prefix); pw.print("executeNesting="); pw.print(executeNesting);
+                    pw.print(" executeFg="); pw.print(executeFg);
+                    pw.print(" executingStart=");
+                    TimeUtils.formatDuration(executingStart, now, pw);
+                    pw.println();
+        }
+        if (crashCount != 0 || restartCount != 0
+                || restartDelay != 0 || nextRestartTime != 0) {
+            pw.print(prefix); pw.print("restartCount="); pw.print(restartCount);
+                    pw.print(" restartDelay=");
+                    TimeUtils.formatDuration(restartDelay, now, pw);
+                    pw.print(" nextRestartTime=");
+                    TimeUtils.formatDuration(nextRestartTime, now, pw);
+                    pw.print(" crashCount="); pw.println(crashCount);
+        }
+        if (deliveredStarts.size() > 0) {
+            pw.print(prefix); pw.println("Delivered Starts:");
+            dumpStartList(pw, prefix, deliveredStarts, now);
+        }
+        if (pendingStarts.size() > 0) {
+            pw.print(prefix); pw.println("Pending Starts:");
+            dumpStartList(pw, prefix, pendingStarts, 0);
+        }
+        if (bindings.size() > 0) {
+            pw.print(prefix); pw.println("Bindings:");
+            for (int i=0; i<bindings.size(); i++) {
+                IntentBindRecord b = bindings.valueAt(i);
+                pw.print(prefix); pw.print("* IntentBindRecord{");
+                        pw.print(Integer.toHexString(System.identityHashCode(b)));
+                        if ((b.collectFlags()&Context.BIND_AUTO_CREATE) != 0) {
+                            pw.append(" CREATE");
+                        }
+                        pw.println("}:");
+                b.dumpInService(pw, prefix + "  ");
+            }
+        }
+        if (connections.size() > 0) {
+            pw.print(prefix); pw.println("All Connections:");
+            for (int conni=0; conni<connections.size(); conni++) {
+                ArrayList<ConnectionRecord> c = connections.valueAt(conni);
+                for (int i=0; i<c.size(); i++) {
+                    pw.print(prefix); pw.print("  "); pw.println(c.get(i));
+                }
+            }
+        }
+    }
+
+    ServiceRecord(ActivityManagerService ams,
+            BatteryStatsImpl.Uid.Pkg.Serv servStats, ComponentName name,
+            Intent.FilterComparison intent, ServiceInfo sInfo, boolean callerIsFg,
+            Runnable restarter) {
+        this.ams = ams;
+        this.stats = servStats;
+        this.name = name;
+        shortName = name.flattenToShortString();
+        this.intent = intent;
+        serviceInfo = sInfo;
+        appInfo = sInfo.applicationInfo;
+        packageName = sInfo.applicationInfo.packageName;
+        processName = sInfo.processName;
+        permission = sInfo.permission;
+        baseDir = sInfo.applicationInfo.sourceDir;
+        resDir = sInfo.applicationInfo.publicSourceDir;
+        dataDir = sInfo.applicationInfo.dataDir;
+        exported = sInfo.exported;
+        this.restarter = restarter;
+        createTime = SystemClock.elapsedRealtime();
+        lastActivity = SystemClock.uptimeMillis();
+        userId = UserHandle.getUserId(appInfo.uid);
+        createdFromFg = callerIsFg;
+    }
+
+    public ProcessStats.ServiceState getTracker() {
+        if (tracker != null) {
+            return tracker;
+        }
+        if ((serviceInfo.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) == 0) {
+            tracker = ams.mProcessStats.getServiceStateLocked(serviceInfo.packageName,
+                    serviceInfo.applicationInfo.uid, serviceInfo.processName, serviceInfo.name);
+            tracker.applyNewOwner(this);
+        }
+        return tracker;
+    }
+
+    public void forceClearTracker() {
+        if (tracker != null) {
+            tracker.clearCurrentOwner(this, true);
+            tracker = null;
+        }
+    }
+
+    public void makeRestarting(int memFactor, long now) {
+        if (restartTracker == null) {
+            if ((serviceInfo.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) == 0) {
+                restartTracker = ams.mProcessStats.getServiceStateLocked(serviceInfo.packageName,
+                        serviceInfo.applicationInfo.uid, serviceInfo.processName, serviceInfo.name);
+            }
+            if (restartTracker == null) {
+                return;
+            }
+        }
+        restartTracker.setRestarting(true, memFactor, now);
+    }
+
+    public AppBindRecord retrieveAppBindingLocked(Intent intent,
+            ProcessRecord app) {
+        Intent.FilterComparison filter = new Intent.FilterComparison(intent);
+        IntentBindRecord i = bindings.get(filter);
+        if (i == null) {
+            i = new IntentBindRecord(this, filter);
+            bindings.put(filter, i);
+        }
+        AppBindRecord a = i.apps.get(app);
+        if (a != null) {
+            return a;
+        }
+        a = new AppBindRecord(this, i, app);
+        i.apps.put(app, a);
+        return a;
+    }
+
+    public boolean hasAutoCreateConnections() {
+        // XXX should probably keep a count of the number of auto-create
+        // connections directly in the service.
+        for (int conni=connections.size()-1; conni>=0; conni--) {
+            ArrayList<ConnectionRecord> cr = connections.valueAt(conni);
+            for (int i=0; i<cr.size(); i++) {
+                if ((cr.get(i).flags&Context.BIND_AUTO_CREATE) != 0) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    public void resetRestartCounter() {
+        restartCount = 0;
+        restartDelay = 0;
+        restartTime = 0;
+    }
+    
+    public StartItem findDeliveredStart(int id, boolean remove) {
+        final int N = deliveredStarts.size();
+        for (int i=0; i<N; i++) {
+            StartItem si = deliveredStarts.get(i);
+            if (si.id == id) {
+                if (remove) deliveredStarts.remove(i);
+                return si;
+            }
+        }
+        
+        return null;
+    }
+    
+    public int getLastStartId() {
+        return lastStartId;
+    }
+
+    public int makeNextStartId() {
+        lastStartId++;
+        if (lastStartId < 1) {
+            lastStartId = 1;
+        }
+        return lastStartId;
+    }
+
+    public void postNotification() {
+        final int appUid = appInfo.uid;
+        final int appPid = app.pid;
+        if (foregroundId != 0 && foregroundNoti != null) {
+            // Do asynchronous communication with notification manager to
+            // avoid deadlocks.
+            final String localPackageName = packageName;
+            final int localForegroundId = foregroundId;
+            final Notification localForegroundNoti = foregroundNoti;
+            ams.mHandler.post(new Runnable() {
+                public void run() {
+                    NotificationManagerInternal nm = LocalServices.getService(
+                            NotificationManagerInternal.class);
+                    if (nm == null) {
+                        return;
+                    }
+                    try {
+                        if (localForegroundNoti.icon == 0) {
+                            // It is not correct for the caller to supply a notification
+                            // icon, but this used to be able to slip through, so for
+                            // those dirty apps give it the app's icon.
+                            localForegroundNoti.icon = appInfo.icon;
+
+                            // Do not allow apps to present a sneaky invisible content view either.
+                            localForegroundNoti.contentView = null;
+                            localForegroundNoti.bigContentView = null;
+                            CharSequence appName = appInfo.loadLabel(
+                                    ams.mContext.getPackageManager());
+                            if (appName == null) {
+                                appName = appInfo.packageName;
+                            }
+                            Context ctx = null;
+                            try {
+                                ctx = ams.mContext.createPackageContext(
+                                        appInfo.packageName, 0);
+                                Intent runningIntent = new Intent(
+                                        Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+                                runningIntent.setData(Uri.fromParts("package",
+                                        appInfo.packageName, null));
+                                PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0,
+                                        runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+                                localForegroundNoti.setLatestEventInfo(ctx,
+                                        ams.mContext.getString(
+                                                com.android.internal.R.string
+                                                        .app_running_notification_title,
+                                                appName),
+                                        ams.mContext.getString(
+                                                com.android.internal.R.string
+                                                        .app_running_notification_text,
+                                                appName),
+                                        pi);
+                            } catch (PackageManager.NameNotFoundException e) {
+                                localForegroundNoti.icon = 0;
+                            }
+                        }
+                        if (localForegroundNoti.icon == 0) {
+                            // Notifications whose icon is 0 are defined to not show
+                            // a notification, silently ignoring it.  We don't want to
+                            // just ignore it, we want to prevent the service from
+                            // being foreground.
+                            throw new RuntimeException("icon must be non-zero");
+                        }
+                        int[] outId = new int[1];
+                        nm.enqueueNotification(localPackageName, localPackageName,
+                                appUid, appPid, null, localForegroundId, localForegroundNoti,
+                                outId, userId);
+                    } catch (RuntimeException e) {
+                        Slog.w(ActivityManagerService.TAG,
+                                "Error showing notification for service", e);
+                        // If it gave us a garbage notification, it doesn't
+                        // get to be foreground.
+                        ams.setServiceForeground(name, ServiceRecord.this,
+                                0, null, true);
+                        ams.crashApplication(appUid, appPid, localPackageName,
+                                "Bad notification for startForeground: " + e);
+                    }
+                }
+            });
+        }
+    }
+    
+    public void cancelNotification() {
+        if (foregroundId != 0) {
+            // Do asynchronous communication with notification manager to
+            // avoid deadlocks.
+            final String localPackageName = packageName;
+            final int localForegroundId = foregroundId;
+            ams.mHandler.post(new Runnable() {
+                public void run() {
+                    INotificationManager inm = NotificationManager.getService();
+                    if (inm == null) {
+                        return;
+                    }
+                    try {
+                        inm.cancelNotificationWithTag(localPackageName, null,
+                                localForegroundId, userId);
+                    } catch (RuntimeException e) {
+                        Slog.w(ActivityManagerService.TAG,
+                                "Error canceling notification for service", e);
+                    } catch (RemoteException e) {
+                    }
+                }
+            });
+        }
+    }
+    
+    public void clearDeliveredStartsLocked() {
+        for (int i=deliveredStarts.size()-1; i>=0; i--) {
+            deliveredStarts.get(i).removeUriPermissionsLocked();
+        }
+        deliveredStarts.clear();
+    }
+
+    public String toString() {
+        if (stringName != null) {
+            return stringName;
+        }
+        StringBuilder sb = new StringBuilder(128);
+        sb.append("ServiceRecord{")
+            .append(Integer.toHexString(System.identityHashCode(this)))
+            .append(" u").append(userId)
+            .append(' ').append(shortName).append('}');
+        return stringName = sb.toString();
+    }
+}
diff --git a/services/java/com/android/server/am/StrictModeViolationDialog.java b/services/core/java/com/android/server/am/StrictModeViolationDialog.java
similarity index 100%
rename from services/java/com/android/server/am/StrictModeViolationDialog.java
rename to services/core/java/com/android/server/am/StrictModeViolationDialog.java
diff --git a/services/java/com/android/server/am/TaskAccessInfo.java b/services/core/java/com/android/server/am/TaskAccessInfo.java
similarity index 100%
rename from services/java/com/android/server/am/TaskAccessInfo.java
rename to services/core/java/com/android/server/am/TaskAccessInfo.java
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
new file mode 100644
index 0000000..9740812
--- /dev/null
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -0,0 +1,528 @@
+/*
+ * Copyright (C) 2006 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 static com.android.server.am.ActivityManagerService.TAG;
+import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.ActivityOptions;
+import android.app.IThumbnailRetriever;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.graphics.Bitmap;
+import android.os.UserHandle;
+import android.util.Slog;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+final class TaskRecord extends ThumbnailHolder {
+    final int taskId;       // Unique identifier for this task.
+    final String affinity;  // The affinity name for this task, or null.
+    Intent intent;          // The original intent that started the task.
+    Intent affinityIntent;  // Intent of affinity-moved activity that started this task.
+    ComponentName origActivity; // The non-alias activity component of the intent.
+    ComponentName realActivity; // The actual activity component that started the task.
+    int numActivities;      // Current number of activities in this task.
+    long lastActiveTime;    // Last time this task was active, including sleep.
+    boolean rootWasReset;   // True if the intent at the root of the task had
+                            // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
+    boolean askedCompatMode;// Have asked the user about compat mode for this task.
+
+    String stringName;      // caching of toString() result.
+    int userId;             // user for which this task was created
+
+    int numFullscreen;      // Number of fullscreen activities.
+
+    /** List of all activities in the task arranged in history order */
+    final ArrayList<ActivityRecord> mActivities = new ArrayList<ActivityRecord>();
+
+    /** Current stack */
+    ActivityStack stack;
+
+    /** Takes on same set of values as ActivityRecord.mActivityType */
+    private int mTaskType;
+
+    /** Launch the home activity when leaving this task. Will be false for tasks that are not on
+     * Display.DEFAULT_DISPLAY. */
+    boolean mOnTopOfHome = false;
+
+    TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
+        taskId = _taskId;
+        affinity = info.taskAffinity;
+        setIntent(_intent, info);
+    }
+
+    void touchActiveTime() {
+        lastActiveTime = android.os.SystemClock.elapsedRealtime();
+    }
+
+    long getInactiveDuration() {
+        return android.os.SystemClock.elapsedRealtime() - lastActiveTime;
+    }
+
+    void setIntent(Intent _intent, ActivityInfo info) {
+        stringName = null;
+
+        if (info.targetActivity == null) {
+            if (_intent != null) {
+                // If this Intent has a selector, we want to clear it for the
+                // recent task since it is not relevant if the user later wants
+                // to re-launch the app.
+                if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
+                    _intent = new Intent(_intent);
+                    _intent.setSelector(null);
+                    _intent.setSourceBounds(null);
+                }
+            }
+            if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
+                    "Setting Intent of " + this + " to " + _intent);
+            intent = _intent;
+            realActivity = _intent != null ? _intent.getComponent() : null;
+            origActivity = null;
+        } else {
+            ComponentName targetComponent = new ComponentName(
+                    info.packageName, info.targetActivity);
+            if (_intent != null) {
+                Intent targetIntent = new Intent(_intent);
+                targetIntent.setComponent(targetComponent);
+                targetIntent.setSelector(null);
+                targetIntent.setSourceBounds(null);
+                if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
+                        "Setting Intent of " + this + " to target " + targetIntent);
+                intent = targetIntent;
+                realActivity = targetComponent;
+                origActivity = _intent.getComponent();
+            } else {
+                intent = null;
+                realActivity = targetComponent;
+                origActivity = new ComponentName(info.packageName, info.name);
+            }
+        }
+
+        if (intent != null &&
+                (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
+            // Once we are set to an Intent with this flag, we count this
+            // task as having a true root activity.
+            rootWasReset = true;
+        }
+
+        if (info.applicationInfo != null) {
+            userId = UserHandle.getUserId(info.applicationInfo.uid);
+        }
+    }
+
+    void disposeThumbnail() {
+        super.disposeThumbnail();
+        for (int i=mActivities.size()-1; i>=0; i--) {
+            ThumbnailHolder thumb = mActivities.get(i).thumbHolder;
+            if (thumb != this) {
+                thumb.disposeThumbnail();
+            }
+        }
+    }
+
+    ActivityRecord getTopActivity() {
+        for (int i = mActivities.size() - 1; i >= 0; --i) {
+            final ActivityRecord r = mActivities.get(i);
+            if (r.finishing) {
+                continue;
+            }
+            return r;
+        }
+        return null;
+    }
+
+    ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
+        for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
+            ActivityRecord r = mActivities.get(activityNdx);
+            if (!r.finishing && r != notTop && stack.okToShow(r)) {
+                return r;
+            }
+        }
+        return null;
+    }
+
+    /** Call after activity movement or finish to make sure that frontOfTask is set correctly */
+    final void setFrontOfTask() {
+        boolean foundFront = false;
+        final int numActivities = mActivities.size();
+        for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
+            final ActivityRecord r = mActivities.get(activityNdx);
+            if (foundFront || r.finishing) {
+                r.frontOfTask = false;
+            } else {
+                r.frontOfTask = true;
+                // Set frontOfTask false for every following activity.
+                foundFront = true;
+            }
+        }
+    }
+
+    /**
+     * Reorder the history stack so that the passed activity is brought to the front.
+     */
+    final void moveActivityToFrontLocked(ActivityRecord newTop) {
+        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop
+            + " to stack at top", new RuntimeException("here").fillInStackTrace());
+
+        mActivities.remove(newTop);
+        mActivities.add(newTop);
+
+        setFrontOfTask();
+    }
+
+    void addActivityAtBottom(ActivityRecord r) {
+        addActivityAtIndex(0, r);
+    }
+
+    void addActivityToTop(ActivityRecord r) {
+        addActivityAtIndex(mActivities.size(), r);
+    }
+
+    void addActivityAtIndex(int index, ActivityRecord r) {
+        // Remove r first, and if it wasn't already in the list and it's fullscreen, count it.
+        if (!mActivities.remove(r) && r.fullscreen) {
+            // Was not previously in list.
+            numFullscreen++;
+        }
+        // Only set this based on the first activity
+        if (mActivities.isEmpty()) {
+            mTaskType = r.mActivityType;
+        } else {
+            // Otherwise make all added activities match this one.
+            r.mActivityType = mTaskType;
+        }
+        mActivities.add(index, r);
+    }
+
+    /** @return true if this was the last activity in the task */
+    boolean removeActivity(ActivityRecord r) {
+        if (mActivities.remove(r) && r.fullscreen) {
+            // Was previously in list.
+            numFullscreen--;
+        }
+        return mActivities.size() == 0;
+    }
+
+    /**
+     * Completely remove all activities associated with an existing
+     * task starting at a specified index.
+     */
+    final void performClearTaskAtIndexLocked(int activityNdx) {
+        int numActivities = mActivities.size();
+        for ( ; activityNdx < numActivities; ++activityNdx) {
+            final ActivityRecord r = mActivities.get(activityNdx);
+            if (r.finishing) {
+                continue;
+            }
+            if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", false)) {
+                --activityNdx;
+                --numActivities;
+            }
+        }
+    }
+
+    /**
+     * Completely remove all activities associated with an existing task.
+     */
+    final void performClearTaskLocked() {
+        performClearTaskAtIndexLocked(0);
+    }
+
+    /**
+     * Perform clear operation as requested by
+     * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
+     * stack to the given task, then look for
+     * an instance of that activity in the stack and, if found, finish all
+     * activities on top of it and return the instance.
+     *
+     * @param newR Description of the new activity being started.
+     * @return Returns the old activity that should be continued to be used,
+     * or null if none was found.
+     */
+    final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
+        int numActivities = mActivities.size();
+        for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
+            ActivityRecord r = mActivities.get(activityNdx);
+            if (r.finishing) {
+                continue;
+            }
+            if (r.realActivity.equals(newR.realActivity)) {
+                // Here it is!  Now finish everything in front...
+                final ActivityRecord ret = r;
+
+                for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
+                    r = mActivities.get(activityNdx);
+                    if (r.finishing) {
+                        continue;
+                    }
+                    ActivityOptions opts = r.takeOptionsLocked();
+                    if (opts != null) {
+                        ret.updateOptionsLocked(opts);
+                    }
+                    if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear",
+                            false)) {
+                        --activityNdx;
+                        --numActivities;
+                    }
+                }
+
+                // Finally, if this is a normal launch mode (that is, not
+                // expecting onNewIntent()), then we will finish the current
+                // instance of the activity so a new fresh one can be started.
+                if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
+                        && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
+                    if (!ret.finishing) {
+                        stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null,
+                                "clear", false);
+                        return null;
+                    }
+                }
+
+                return ret;
+            }
+        }
+
+        return null;
+    }
+
+    public ActivityManager.TaskThumbnails getTaskThumbnailsLocked() {
+        TaskAccessInfo info = getTaskAccessInfoLocked(true);
+        final ActivityRecord resumedActivity = stack.mResumedActivity;
+        if (resumedActivity != null && resumedActivity.thumbHolder == this) {
+            info.mainThumbnail = stack.screenshotActivities(resumedActivity);
+        }
+        if (info.mainThumbnail == null) {
+            info.mainThumbnail = lastThumbnail;
+        }
+        return info;
+    }
+
+    public Bitmap getTaskTopThumbnailLocked() {
+        final ActivityRecord resumedActivity = stack.mResumedActivity;
+        if (resumedActivity != null && resumedActivity.task == this) {
+            // This task is the current resumed task, we just need to take
+            // a screenshot of it and return that.
+            return stack.screenshotActivities(resumedActivity);
+        }
+        // Return the information about the task, to figure out the top
+        // thumbnail to return.
+        TaskAccessInfo info = getTaskAccessInfoLocked(true);
+        if (info.numSubThumbbails <= 0) {
+            return info.mainThumbnail != null ? info.mainThumbnail : lastThumbnail;
+        }
+        return info.subtasks.get(info.numSubThumbbails-1).holder.lastThumbnail;
+    }
+
+    public ActivityRecord removeTaskActivitiesLocked(int subTaskIndex,
+            boolean taskRequired) {
+        TaskAccessInfo info = getTaskAccessInfoLocked(false);
+        if (info.root == null) {
+            if (taskRequired) {
+                Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId);
+            }
+            return null;
+        }
+
+        if (subTaskIndex < 0) {
+            // Just remove the entire task.
+            performClearTaskAtIndexLocked(info.rootIndex);
+            return info.root;
+        }
+
+        if (subTaskIndex >= info.subtasks.size()) {
+            if (taskRequired) {
+                Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex);
+            }
+            return null;
+        }
+
+        // Remove all of this task's activities starting at the sub task.
+        TaskAccessInfo.SubTask subtask = info.subtasks.get(subTaskIndex);
+        performClearTaskAtIndexLocked(subtask.index);
+        return subtask.activity;
+    }
+
+    boolean isHomeTask() {
+        return mTaskType == ActivityRecord.HOME_ACTIVITY_TYPE;
+    }
+
+    boolean isApplicationTask() {
+        return mTaskType == ActivityRecord.APPLICATION_ACTIVITY_TYPE;
+    }
+
+    public TaskAccessInfo getTaskAccessInfoLocked(boolean inclThumbs) {
+        final TaskAccessInfo thumbs = new TaskAccessInfo();
+        // How many different sub-thumbnails?
+        final int NA = mActivities.size();
+        int j = 0;
+        ThumbnailHolder holder = null;
+        while (j < NA) {
+            ActivityRecord ar = mActivities.get(j);
+            if (!ar.finishing) {
+                thumbs.root = ar;
+                thumbs.rootIndex = j;
+                holder = ar.thumbHolder;
+                if (holder != null) {
+                    thumbs.mainThumbnail = holder.lastThumbnail;
+                }
+                j++;
+                break;
+            }
+            j++;
+        }
+
+        if (j >= NA) {
+            return thumbs;
+        }
+
+        ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>();
+        thumbs.subtasks = subtasks;
+        while (j < NA) {
+            ActivityRecord ar = mActivities.get(j);
+            j++;
+            if (ar.finishing) {
+                continue;
+            }
+            if (ar.thumbHolder != holder && holder != null) {
+                thumbs.numSubThumbbails++;
+                holder = ar.thumbHolder;
+                TaskAccessInfo.SubTask sub = new TaskAccessInfo.SubTask();
+                sub.holder = holder;
+                sub.activity = ar;
+                sub.index = j-1;
+                subtasks.add(sub);
+            }
+        }
+        if (thumbs.numSubThumbbails > 0) {
+            thumbs.retriever = new IThumbnailRetriever.Stub() {
+                @Override
+                public Bitmap getThumbnail(int index) {
+                    if (index < 0 || index >= thumbs.subtasks.size()) {
+                        return null;
+                    }
+                    TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index);
+                    ActivityRecord resumedActivity = stack.mResumedActivity;
+                    if (resumedActivity != null && resumedActivity.thumbHolder == sub.holder) {
+                        return stack.screenshotActivities(resumedActivity);
+                    }
+                    return sub.holder.lastThumbnail;
+                }
+            };
+        }
+        return thumbs;
+    }
+
+    /**
+     * Find the activity in the history stack within the given task.  Returns
+     * the index within the history at which it's found, or < 0 if not found.
+     */
+    final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
+        final ComponentName realActivity = r.realActivity;
+        for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
+            ActivityRecord candidate = mActivities.get(activityNdx);
+            if (candidate.finishing) {
+                continue;
+            }
+            if (candidate.realActivity.equals(realActivity)) {
+                return candidate;
+            }
+        }
+        return null;
+    }
+
+    void dump(PrintWriter pw, String prefix) {
+        if (numActivities != 0 || rootWasReset || userId != 0 || numFullscreen != 0) {
+            pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
+                    pw.print(" rootWasReset="); pw.print(rootWasReset);
+                    pw.print(" userId="); pw.print(userId);
+                    pw.print(" mTaskType="); pw.print(mTaskType);
+                    pw.print(" numFullscreen="); pw.print(numFullscreen);
+                    pw.print(" mOnTopOfHome="); pw.println(mOnTopOfHome);
+        }
+        if (affinity != null) {
+            pw.print(prefix); pw.print("affinity="); pw.println(affinity);
+        }
+        if (intent != null) {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append(prefix); sb.append("intent={");
+            intent.toShortString(sb, false, true, false, true);
+            sb.append('}');
+            pw.println(sb.toString());
+        }
+        if (affinityIntent != null) {
+            StringBuilder sb = new StringBuilder(128);
+            sb.append(prefix); sb.append("affinityIntent={");
+            affinityIntent.toShortString(sb, false, true, false, true);
+            sb.append('}');
+            pw.println(sb.toString());
+        }
+        if (origActivity != null) {
+            pw.print(prefix); pw.print("origActivity=");
+            pw.println(origActivity.flattenToShortString());
+        }
+        if (realActivity != null) {
+            pw.print(prefix); pw.print("realActivity=");
+            pw.println(realActivity.flattenToShortString());
+        }
+        pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
+        if (!askedCompatMode) {
+            pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode);
+        }
+        pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail);
+                pw.print(" lastDescription="); pw.println(lastDescription);
+        pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime);
+                pw.print(" (inactive for ");
+                pw.print((getInactiveDuration()/1000)); pw.println("s)");
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(128);
+        if (stringName != null) {
+            sb.append(stringName);
+            sb.append(" U=");
+            sb.append(userId);
+            sb.append(" sz=");
+            sb.append(mActivities.size());
+            sb.append('}');
+            return sb.toString();
+        }
+        sb.append("TaskRecord{");
+        sb.append(Integer.toHexString(System.identityHashCode(this)));
+        sb.append(" #");
+        sb.append(taskId);
+        if (affinity != null) {
+            sb.append(" A=");
+            sb.append(affinity);
+        } else if (intent != null) {
+            sb.append(" I=");
+            sb.append(intent.getComponent().flattenToShortString());
+        } else if (affinityIntent != null) {
+            sb.append(" aI=");
+            sb.append(affinityIntent.getComponent().flattenToShortString());
+        } else {
+            sb.append(" ??");
+        }
+        stringName = sb.toString();
+        return toString();
+    }
+}
diff --git a/services/java/com/android/server/am/ThumbnailHolder.java b/services/core/java/com/android/server/am/ThumbnailHolder.java
similarity index 100%
rename from services/java/com/android/server/am/ThumbnailHolder.java
rename to services/core/java/com/android/server/am/ThumbnailHolder.java
diff --git a/services/java/com/android/server/am/UriPermission.java b/services/core/java/com/android/server/am/UriPermission.java
similarity index 100%
rename from services/java/com/android/server/am/UriPermission.java
rename to services/core/java/com/android/server/am/UriPermission.java
diff --git a/services/java/com/android/server/am/UriPermissionOwner.java b/services/core/java/com/android/server/am/UriPermissionOwner.java
similarity index 100%
rename from services/java/com/android/server/am/UriPermissionOwner.java
rename to services/core/java/com/android/server/am/UriPermissionOwner.java
diff --git a/services/core/java/com/android/server/am/UsageStatsService.java b/services/core/java/com/android/server/am/UsageStatsService.java
new file mode 100644
index 0000000..09cb344
--- /dev/null
+++ b/services/core/java/com/android/server/am/UsageStatsService.java
@@ -0,0 +1,1178 @@
+/*
+ * Copyright (C) 2006-2007 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.app.AppGlobals;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.FileUtils;
+import android.os.Parcel;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.util.ArrayMap;
+import android.util.AtomicFile;
+import android.util.Slog;
+import android.util.Xml;
+
+import com.android.internal.app.IUsageStats;
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.os.PkgUsageStats;
+import com.android.internal.util.FastXmlSerializer;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This service collects the statistics associated with usage
+ * of various components, like when a particular package is launched or
+ * paused and aggregates events like number of time a component is launched
+ * total duration of a component launch.
+ */
+public final class UsageStatsService extends IUsageStats.Stub {
+    public static final String SERVICE_NAME = "usagestats";
+    private static final boolean localLOGV = false;
+    private static final boolean REPORT_UNEXPECTED = false;
+    private static final String TAG = "UsageStats";
+    
+    // Current on-disk Parcel version
+    private static final int VERSION = 1008;
+
+    private static final int CHECKIN_VERSION = 4;
+    
+    private static final String FILE_PREFIX = "usage-";
+
+    private static final String FILE_HISTORY = FILE_PREFIX + "history.xml";
+
+    private static final int FILE_WRITE_INTERVAL = 30*60*1000; //ms
+    
+    private static final int MAX_NUM_FILES = 5;
+    
+    private static final int NUM_LAUNCH_TIME_BINS = 10;
+    private static final int[] LAUNCH_TIME_BINS = {
+        250, 500, 750, 1000, 1500, 2000, 3000, 4000, 5000
+    };
+    
+    static IUsageStats sService;
+    private Context mContext;
+    // structure used to maintain statistics since the last checkin.
+    final private ArrayMap<String, PkgUsageStatsExtended> mStats;
+
+    // Maintains the last time any component was resumed, for all time.
+    final private ArrayMap<String, ArrayMap<String, Long>> mLastResumeTimes;
+
+    // To remove last-resume time stats when a pacakge is removed.
+    private PackageMonitor mPackageMonitor;
+
+    // Lock to update package stats. Methods suffixed by SLOCK should invoked with
+    // this lock held
+    final Object mStatsLock;
+    // Lock to write to file. Methods suffixed by FLOCK should invoked with
+    // this lock held.
+    final Object mFileLock;
+    // Order of locks is mFileLock followed by mStatsLock to avoid deadlocks
+    private String mLastResumedPkg;
+    private String mLastResumedComp;
+    private boolean mIsResumed;
+    private File mFile;
+    private AtomicFile mHistoryFile;
+    private String mFileLeaf;
+    private File mDir;
+
+    private Calendar mCal; // guarded by itself
+
+    private final AtomicInteger mLastWriteDay = new AtomicInteger(-1);
+    private final AtomicLong mLastWriteElapsedTime = new AtomicLong(0);
+    private final AtomicBoolean mUnforcedDiskWriteRunning = new AtomicBoolean(false);
+    
+    static class TimeStats {
+        int count;
+        int[] times = new int[NUM_LAUNCH_TIME_BINS];
+        
+        TimeStats() {
+        }
+        
+        void incCount() {
+            count++;
+        }
+        
+        void add(int val) {
+            final int[] bins = LAUNCH_TIME_BINS;
+            for (int i=0; i<NUM_LAUNCH_TIME_BINS-1; i++) {
+                if (val < bins[i]) {
+                    times[i]++;
+                    return;
+                }
+            }
+            times[NUM_LAUNCH_TIME_BINS-1]++;
+        }
+        
+        TimeStats(Parcel in) {
+            count = in.readInt();
+            final int[] localTimes = times;
+            for (int i=0; i<NUM_LAUNCH_TIME_BINS; i++) {
+                localTimes[i] = in.readInt();
+            }
+        }
+        
+        void writeToParcel(Parcel out) {
+            out.writeInt(count);
+            final int[] localTimes = times;
+            for (int i=0; i<NUM_LAUNCH_TIME_BINS; i++) {
+                out.writeInt(localTimes[i]);
+            }
+        }
+    }
+    
+    private class PkgUsageStatsExtended {
+        final ArrayMap<String, TimeStats> mLaunchTimes
+                = new ArrayMap<String, TimeStats>();
+        final ArrayMap<String, TimeStats> mFullyDrawnTimes
+                = new ArrayMap<String, TimeStats>();
+        int mLaunchCount;
+        long mUsageTime;
+        long mPausedTime;
+        long mResumedTime;
+        
+        PkgUsageStatsExtended() {
+            mLaunchCount = 0;
+            mUsageTime = 0;
+        }
+        
+        PkgUsageStatsExtended(Parcel in) {
+            mLaunchCount = in.readInt();
+            mUsageTime = in.readLong();
+            if (localLOGV) Slog.v(TAG, "Launch count: " + mLaunchCount
+                    + ", Usage time:" + mUsageTime);
+            
+            final int numLaunchTimeStats = in.readInt();
+            if (localLOGV) Slog.v(TAG, "Reading launch times: " + numLaunchTimeStats);
+            mLaunchTimes.ensureCapacity(numLaunchTimeStats);
+            for (int i=0; i<numLaunchTimeStats; i++) {
+                String comp = in.readString();
+                if (localLOGV) Slog.v(TAG, "Component: " + comp);
+                TimeStats times = new TimeStats(in);
+                mLaunchTimes.put(comp, times);
+            }
+
+            final int numFullyDrawnTimeStats = in.readInt();
+            if (localLOGV) Slog.v(TAG, "Reading fully drawn times: " + numFullyDrawnTimeStats);
+            mFullyDrawnTimes.ensureCapacity(numFullyDrawnTimeStats);
+            for (int i=0; i<numFullyDrawnTimeStats; i++) {
+                String comp = in.readString();
+                if (localLOGV) Slog.v(TAG, "Component: " + comp);
+                TimeStats times = new TimeStats(in);
+                mFullyDrawnTimes.put(comp, times);
+            }
+        }
+
+        void updateResume(String comp, boolean launched) {
+            if (launched) {
+                mLaunchCount ++;
+            }
+            mResumedTime = SystemClock.elapsedRealtime();
+        }
+        
+        void updatePause() {
+            mPausedTime =  SystemClock.elapsedRealtime();
+            mUsageTime += (mPausedTime - mResumedTime);
+        }
+        
+        void addLaunchCount(String comp) {
+            TimeStats times = mLaunchTimes.get(comp);
+            if (times == null) {
+                times = new TimeStats();
+                mLaunchTimes.put(comp, times);
+            }
+            times.incCount();
+        }
+        
+        void addLaunchTime(String comp, int millis) {
+            TimeStats times = mLaunchTimes.get(comp);
+            if (times == null) {
+                times = new TimeStats();
+                mLaunchTimes.put(comp, times);
+            }
+            times.add(millis);
+        }
+
+        void addFullyDrawnTime(String comp, int millis) {
+            TimeStats times = mFullyDrawnTimes.get(comp);
+            if (times == null) {
+                times = new TimeStats();
+                mFullyDrawnTimes.put(comp, times);
+            }
+            times.add(millis);
+        }
+
+        void writeToParcel(Parcel out) {
+            out.writeInt(mLaunchCount);
+            out.writeLong(mUsageTime);
+            final int numLaunchTimeStats = mLaunchTimes.size();
+            out.writeInt(numLaunchTimeStats);
+            for (int i=0; i<numLaunchTimeStats; i++) {
+                out.writeString(mLaunchTimes.keyAt(i));
+                mLaunchTimes.valueAt(i).writeToParcel(out);
+            }
+            final int numFullyDrawnTimeStats = mFullyDrawnTimes.size();
+            out.writeInt(numFullyDrawnTimeStats);
+            for (int i=0; i<numFullyDrawnTimeStats; i++) {
+                out.writeString(mFullyDrawnTimes.keyAt(i));
+                mFullyDrawnTimes.valueAt(i).writeToParcel(out);
+            }
+        }
+        
+        void clear() {
+            mLaunchTimes.clear();
+            mFullyDrawnTimes.clear();
+            mLaunchCount = 0;
+            mUsageTime = 0;
+        }
+    }
+    
+    UsageStatsService(String dir) {
+        mStats = new ArrayMap<String, PkgUsageStatsExtended>();
+        mLastResumeTimes = new ArrayMap<String, ArrayMap<String, Long>>();
+        mStatsLock = new Object();
+        mFileLock = new Object();
+        mDir = new File(dir);
+        mCal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0"));
+        
+        mDir.mkdir();
+        
+        // Remove any old usage files from previous versions.
+        File parentDir = mDir.getParentFile();
+        String fList[] = parentDir.list();
+        if (fList != null) {
+            String prefix = mDir.getName() + ".";
+            int i = fList.length;
+            while (i > 0) {
+                i--;
+                if (fList[i].startsWith(prefix)) {
+                    Slog.i(TAG, "Deleting old usage file: " + fList[i]);
+                    (new File(parentDir, fList[i])).delete();
+                }
+            }
+        }
+        
+        // Update current stats which are binned by date
+        mFileLeaf = getCurrentDateStr(FILE_PREFIX);
+        mFile = new File(mDir, mFileLeaf);
+        mHistoryFile = new AtomicFile(new File(mDir, FILE_HISTORY));
+        readStatsFromFile();
+        readHistoryStatsFromFile();
+        mLastWriteElapsedTime.set(SystemClock.elapsedRealtime());
+        // mCal was set by getCurrentDateStr(), want to use that same time.
+        mLastWriteDay.set(mCal.get(Calendar.DAY_OF_YEAR));
+    }
+
+    /*
+     * Utility method to convert date into string.
+     */
+    private String getCurrentDateStr(String prefix) {
+        StringBuilder sb = new StringBuilder();
+        synchronized (mCal) {
+            mCal.setTimeInMillis(System.currentTimeMillis());
+            if (prefix != null) {
+                sb.append(prefix);
+            }
+            sb.append(mCal.get(Calendar.YEAR));
+            int mm = mCal.get(Calendar.MONTH) - Calendar.JANUARY +1;
+            if (mm < 10) {
+                sb.append("0");
+            }
+            sb.append(mm);
+            int dd = mCal.get(Calendar.DAY_OF_MONTH);
+            if (dd < 10) {
+                sb.append("0");
+            }
+            sb.append(dd);
+        }
+        return sb.toString();
+    }
+    
+    private Parcel getParcelForFile(File file) throws IOException {
+        FileInputStream stream = new FileInputStream(file);
+        byte[] raw = readFully(stream);
+        Parcel in = Parcel.obtain();
+        in.unmarshall(raw, 0, raw.length);
+        in.setDataPosition(0);
+        stream.close();
+        return in;
+    }
+    
+    private void readStatsFromFile() {
+        File newFile = mFile;
+        synchronized (mFileLock) {
+            try {
+                if (newFile.exists()) {
+                    readStatsFLOCK(newFile);
+                } else {
+                    // Check for file limit before creating a new file
+                    checkFileLimitFLOCK();
+                    newFile.createNewFile();
+                }
+            } catch (IOException e) {
+                Slog.w(TAG,"Error : " + e + " reading data from file:" + newFile);
+            }
+        }
+    }
+    
+    private void readStatsFLOCK(File file) throws IOException {
+        Parcel in = getParcelForFile(file);
+        int vers = in.readInt();
+        if (vers != VERSION) {
+            Slog.w(TAG, "Usage stats version changed; dropping");
+            return;
+        }
+        int N = in.readInt();
+        while (N > 0) {
+            N--;
+            String pkgName = in.readString();
+            if (pkgName == null) {
+                break;
+            }
+            if (localLOGV) Slog.v(TAG, "Reading package #" + N + ": " + pkgName);
+            PkgUsageStatsExtended pus = new PkgUsageStatsExtended(in);
+            synchronized (mStatsLock) {
+                mStats.put(pkgName, pus);
+            }
+        }
+    }
+
+    private void readHistoryStatsFromFile() {
+        synchronized (mFileLock) {
+            if (mHistoryFile.getBaseFile().exists()) {
+                readHistoryStatsFLOCK(mHistoryFile);
+            }
+        }
+    }
+
+    private void readHistoryStatsFLOCK(AtomicFile file) {
+        FileInputStream fis = null;
+        try {
+            fis = mHistoryFile.openRead();
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(fis, null);
+            int eventType = parser.getEventType();
+            while (eventType != XmlPullParser.START_TAG &&
+                    eventType != XmlPullParser.END_DOCUMENT) {
+                eventType = parser.next();
+            }
+            if (eventType == XmlPullParser.END_DOCUMENT) {
+                return;
+            }
+
+            String tagName = parser.getName();
+            if ("usage-history".equals(tagName)) {
+                String pkg = null;
+                do {
+                    eventType = parser.next();
+                    if (eventType == XmlPullParser.START_TAG) {
+                        tagName = parser.getName();
+                        int depth = parser.getDepth();
+                        if ("pkg".equals(tagName) && depth == 2) {
+                            pkg = parser.getAttributeValue(null, "name");
+                        } else if ("comp".equals(tagName) && depth == 3 && pkg != null) {
+                            String comp = parser.getAttributeValue(null, "name");
+                            String lastResumeTimeStr = parser.getAttributeValue(null, "lrt");
+                            if (comp != null && lastResumeTimeStr != null) {
+                                try {
+                                    long lastResumeTime = Long.parseLong(lastResumeTimeStr);
+                                    synchronized (mStatsLock) {
+                                        ArrayMap<String, Long> lrt = mLastResumeTimes.get(pkg);
+                                        if (lrt == null) {
+                                            lrt = new ArrayMap<String, Long>();
+                                            mLastResumeTimes.put(pkg, lrt);
+                                        }
+                                        lrt.put(comp, lastResumeTime);
+                                    }
+                                } catch (NumberFormatException e) {
+                                }
+                            }
+                        }
+                    } else if (eventType == XmlPullParser.END_TAG) {
+                        if ("pkg".equals(parser.getName())) {
+                            pkg = null;
+                        }
+                    }
+                } while (eventType != XmlPullParser.END_DOCUMENT);
+            }
+        } catch (XmlPullParserException e) {
+            Slog.w(TAG,"Error reading history stats: " + e);
+        } catch (IOException e) {
+            Slog.w(TAG,"Error reading history stats: " + e);
+        } finally {
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    private ArrayList<String> getUsageStatsFileListFLOCK() {
+        // Check if there are too many files in the system and delete older files
+        String fList[] = mDir.list();
+        if (fList == null) {
+            return null;
+        }
+        ArrayList<String> fileList = new ArrayList<String>();
+        for (String file : fList) {
+            if (!file.startsWith(FILE_PREFIX)) {
+                continue;
+            }
+            if (file.endsWith(".bak")) {
+                (new File(mDir, file)).delete();
+                continue;
+            }
+            fileList.add(file);
+        }
+        return fileList;
+    }
+    
+    private void checkFileLimitFLOCK() {
+        // Get all usage stats output files
+        ArrayList<String> fileList = getUsageStatsFileListFLOCK();
+        if (fileList == null) {
+            // Strange but we dont have to delete any thing
+            return;
+        }
+        int count = fileList.size();
+        if (count <= MAX_NUM_FILES) {
+            return;
+        }
+        // Sort files
+        Collections.sort(fileList);
+        count -= MAX_NUM_FILES;
+        // Delete older files
+        for (int i = 0; i < count; i++) {
+            String fileName = fileList.get(i);
+            File file = new File(mDir, fileName);
+            Slog.i(TAG, "Deleting usage file : " + fileName);
+            file.delete();
+        }
+    }
+
+    /**
+     * Conditionally start up a disk write if it's been awhile, or the
+     * day has rolled over.
+     *
+     * This is called indirectly from user-facing actions (when
+     * 'force' is false) so it tries to be quick, without writing to
+     * disk directly or acquiring heavy locks.
+     *
+     * @params force  do an unconditional, synchronous stats flush
+     *                to disk on the current thread.
+     * @params forceWriteHistoryStats Force writing of historical stats.
+     */
+    private void writeStatsToFile(final boolean force, final boolean forceWriteHistoryStats) {
+        int curDay;
+        synchronized (mCal) {
+            mCal.setTimeInMillis(System.currentTimeMillis());
+            curDay = mCal.get(Calendar.DAY_OF_YEAR);
+        }
+        final boolean dayChanged = curDay != mLastWriteDay.get();
+
+        // Determine if the day changed...  note that this will be wrong
+        // if the year has changed but we are in the same day of year...
+        // we can probably live with this.
+        final long currElapsedTime = SystemClock.elapsedRealtime();
+
+        // Fast common path, without taking the often-contentious
+        // mFileLock.
+        if (!force) {
+            if (!dayChanged &&
+                (currElapsedTime - mLastWriteElapsedTime.get()) < FILE_WRITE_INTERVAL) {
+                // wait till the next update
+                return;
+            }
+            if (mUnforcedDiskWriteRunning.compareAndSet(false, true)) {
+                new Thread("UsageStatsService_DiskWriter") {
+                    public void run() {
+                        try {
+                            if (localLOGV) Slog.d(TAG, "Disk writer thread starting.");
+                            writeStatsToFile(true, false);
+                        } finally {
+                            mUnforcedDiskWriteRunning.set(false);
+                            if (localLOGV) Slog.d(TAG, "Disk writer thread ending.");
+                        }
+                    }
+                }.start();
+            }
+            return;
+        }
+
+        synchronized (mFileLock) {
+            // Get the most recent file
+            mFileLeaf = getCurrentDateStr(FILE_PREFIX);
+            // Copy current file to back up
+            File backupFile = null;
+            if (mFile != null && mFile.exists()) {
+                backupFile = new File(mFile.getPath() + ".bak");
+                if (!backupFile.exists()) {
+                    if (!mFile.renameTo(backupFile)) {
+                        Slog.w(TAG, "Failed to persist new stats");
+                        return;
+                    }
+                } else {
+                    mFile.delete();
+                }
+            }
+
+            try {
+                // Write mStats to file
+                writeStatsFLOCK(mFile);
+                mLastWriteElapsedTime.set(currElapsedTime);
+                if (dayChanged) {
+                    mLastWriteDay.set(curDay);
+                    // clear stats
+                    synchronized (mStats) {
+                        mStats.clear();
+                    }
+                    mFile = new File(mDir, mFileLeaf);
+                    checkFileLimitFLOCK();
+                }
+
+                if (dayChanged || forceWriteHistoryStats) {
+                    // Write history stats daily, or when forced (due to shutdown).
+                    writeHistoryStatsFLOCK(mHistoryFile);
+                }
+
+                // Delete the backup file
+                if (backupFile != null) {
+                    backupFile.delete();
+                }
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed writing stats to file:" + mFile);
+                if (backupFile != null) {
+                    mFile.delete();
+                    backupFile.renameTo(mFile);
+                }
+            }
+        }
+        if (localLOGV) Slog.d(TAG, "Dumped usage stats.");
+    }
+
+    private void writeStatsFLOCK(File file) throws IOException {
+        FileOutputStream stream = new FileOutputStream(file);
+        try {
+            Parcel out = Parcel.obtain();
+            writeStatsToParcelFLOCK(out);
+            stream.write(out.marshall());
+            out.recycle();
+            stream.flush();
+        } finally {
+            FileUtils.sync(stream);
+            stream.close();
+        }
+    }
+
+    private void writeStatsToParcelFLOCK(Parcel out) {
+        synchronized (mStatsLock) {
+            out.writeInt(VERSION);
+            Set<String> keys = mStats.keySet();
+            out.writeInt(keys.size());
+            for (String key : keys) {
+                PkgUsageStatsExtended pus = mStats.get(key);
+                out.writeString(key);
+                pus.writeToParcel(out);
+            }
+        }
+    }
+
+    /** Filter out stats for any packages which aren't present anymore. */
+    private void filterHistoryStats() {
+        synchronized (mStatsLock) {
+            IPackageManager pm = AppGlobals.getPackageManager();
+            for (int i=0; i<mLastResumeTimes.size(); i++) {
+                String pkg = mLastResumeTimes.keyAt(i);
+                try {
+                    if (pm.getPackageUid(pkg, 0) < 0) {
+                        mLastResumeTimes.removeAt(i);
+                        i--;
+                    }
+                } catch (RemoteException e) {
+                }
+            }
+        }
+    }
+
+    private void writeHistoryStatsFLOCK(AtomicFile historyFile) {
+        FileOutputStream fos = null;
+        try {
+            fos = historyFile.startWrite();
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            out.startDocument(null, true);
+            out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+            out.startTag(null, "usage-history");
+            synchronized (mStatsLock) {
+                for (int i=0; i<mLastResumeTimes.size(); i++) {
+                    out.startTag(null, "pkg");
+                    out.attribute(null, "name", mLastResumeTimes.keyAt(i));
+                    ArrayMap<String, Long> comp = mLastResumeTimes.valueAt(i);
+                    for (int j=0; j<comp.size(); j++) {
+                        out.startTag(null, "comp");
+                        out.attribute(null, "name", comp.keyAt(j));
+                        out.attribute(null, "lrt", comp.valueAt(j).toString());
+                        out.endTag(null, "comp");
+                    }
+                    out.endTag(null, "pkg");
+                }
+            }
+            out.endTag(null, "usage-history");
+            out.endDocument();
+
+            historyFile.finishWrite(fos);
+        } catch (IOException e) {
+            Slog.w(TAG,"Error writing history stats" + e);
+            if (fos != null) {
+                historyFile.failWrite(fos);
+            }
+        }
+    }
+
+    public void publish(Context context) {
+        mContext = context;
+        ServiceManager.addService(SERVICE_NAME, asBinder());
+    }
+
+    /**
+     * Start watching packages to remove stats when a package is uninstalled.
+     * May only be called when the package manager is ready.
+     */
+    public void monitorPackages() {
+        mPackageMonitor = new PackageMonitor() {
+            @Override
+            public void onPackageRemovedAllUsers(String packageName, int uid) {
+                synchronized (mStatsLock) {
+                    mLastResumeTimes.remove(packageName);
+                }
+            }
+        };
+        mPackageMonitor.register(mContext, null, true);
+        filterHistoryStats();
+    }
+
+    public void shutdown() {
+        if (mPackageMonitor != null) {
+            mPackageMonitor.unregister();
+        }
+        Slog.i(TAG, "Writing usage stats before shutdown...");
+        writeStatsToFile(true, true);
+    }
+
+    public static IUsageStats getService() {
+        if (sService != null) {
+            return sService;
+        }
+        IBinder b = ServiceManager.getService(SERVICE_NAME);
+        sService = asInterface(b);
+        return sService;
+    }
+    
+    public void noteResumeComponent(ComponentName componentName) {
+        enforceCallingPermission();
+        String pkgName;
+        synchronized (mStatsLock) {
+            if ((componentName == null) ||
+                    ((pkgName = componentName.getPackageName()) == null)) {
+                return;
+            }
+            
+            final boolean samePackage = pkgName.equals(mLastResumedPkg);
+            if (mIsResumed) {
+                if (mLastResumedPkg != null) {
+                    // We last resumed some other package...  just pause it now
+                    // to recover.
+                    if (REPORT_UNEXPECTED) Slog.i(TAG, "Unexpected resume of " + pkgName
+                            + " while already resumed in " + mLastResumedPkg);
+                    PkgUsageStatsExtended pus = mStats.get(mLastResumedPkg);
+                    if (pus != null) {
+                        pus.updatePause();
+                    }
+                }
+            }
+            
+            final boolean sameComp = samePackage
+                    && componentName.getClassName().equals(mLastResumedComp);
+            
+            mIsResumed = true;
+            mLastResumedPkg = pkgName;
+            mLastResumedComp = componentName.getClassName();
+            
+            if (localLOGV) Slog.i(TAG, "started component:" + pkgName);
+            PkgUsageStatsExtended pus = mStats.get(pkgName);
+            if (pus == null) {
+                pus = new PkgUsageStatsExtended();
+                mStats.put(pkgName, pus);
+            }
+            pus.updateResume(mLastResumedComp, !samePackage);
+            if (!sameComp) {
+                pus.addLaunchCount(mLastResumedComp);
+            }
+
+            ArrayMap<String, Long> componentResumeTimes = mLastResumeTimes.get(pkgName);
+            if (componentResumeTimes == null) {
+                componentResumeTimes = new ArrayMap<String, Long>();
+                mLastResumeTimes.put(pkgName, componentResumeTimes);
+            }
+            componentResumeTimes.put(mLastResumedComp, System.currentTimeMillis());
+        }
+    }
+
+    public void notePauseComponent(ComponentName componentName) {
+        enforceCallingPermission();
+        
+        synchronized (mStatsLock) {
+            String pkgName;
+            if ((componentName == null) ||
+                    ((pkgName = componentName.getPackageName()) == null)) {
+                return;
+            }
+            if (!mIsResumed) {
+                if (REPORT_UNEXPECTED) Slog.i(TAG, "Something wrong here, didn't expect "
+                        + pkgName + " to be paused");
+                return;
+            }
+            mIsResumed = false;
+            
+            if (localLOGV) Slog.i(TAG, "paused component:"+pkgName);
+        
+            PkgUsageStatsExtended pus = mStats.get(pkgName);
+            if (pus == null) {
+                // Weird some error here
+                Slog.i(TAG, "No package stats for pkg:"+pkgName);
+                return;
+            }
+            pus.updatePause();
+        }
+        
+        // Persist current data to file if needed.
+        writeStatsToFile(false, false);
+    }
+    
+    public void noteLaunchTime(ComponentName componentName, int millis) {
+        enforceCallingPermission();
+        String pkgName;
+        if ((componentName == null) ||
+                ((pkgName = componentName.getPackageName()) == null)) {
+            return;
+        }
+        
+        // Persist current data to file if needed.
+        writeStatsToFile(false, false);
+        
+        synchronized (mStatsLock) {
+            PkgUsageStatsExtended pus = mStats.get(pkgName);
+            if (pus != null) {
+                pus.addLaunchTime(componentName.getClassName(), millis);
+            }
+        }
+    }
+    
+    public void noteFullyDrawnTime(ComponentName componentName, int millis) {
+        enforceCallingPermission();
+        String pkgName;
+        if ((componentName == null) ||
+                ((pkgName = componentName.getPackageName()) == null)) {
+            return;
+        }
+
+        // Persist current data to file if needed.
+        writeStatsToFile(false, false);
+
+        synchronized (mStatsLock) {
+            PkgUsageStatsExtended pus = mStats.get(pkgName);
+            if (pus != null) {
+                pus.addFullyDrawnTime(componentName.getClassName(), millis);
+            }
+        }
+    }
+
+    public void enforceCallingPermission() {
+        if (Binder.getCallingPid() == Process.myPid()) {
+            return;
+        }
+        mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
+                Binder.getCallingPid(), Binder.getCallingUid(), null);
+    }
+    
+    public PkgUsageStats getPkgUsageStats(ComponentName componentName) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.PACKAGE_USAGE_STATS, null);
+        String pkgName;
+        if ((componentName == null) ||
+                ((pkgName = componentName.getPackageName()) == null)) {
+            return null;
+        }
+        synchronized (mStatsLock) {
+            PkgUsageStatsExtended pus = mStats.get(pkgName);
+            Map<String, Long> lastResumeTimes = mLastResumeTimes.get(pkgName);
+            if (pus == null && lastResumeTimes == null) {
+                return null;
+            }
+            int launchCount = pus != null ? pus.mLaunchCount : 0;
+            long usageTime = pus != null ? pus.mUsageTime : 0;
+            return new PkgUsageStats(pkgName, launchCount, usageTime, lastResumeTimes);
+        }
+    }
+    
+    public PkgUsageStats[] getAllPkgUsageStats() {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.PACKAGE_USAGE_STATS, null);
+        synchronized (mStatsLock) {
+            int size = mLastResumeTimes.size();
+            if (size <= 0) {
+                return null;
+            }
+            PkgUsageStats retArr[] = new PkgUsageStats[size];
+            for (int i=0; i<size; i++) {
+                String pkg = mLastResumeTimes.keyAt(i);
+                long usageTime = 0;
+                int launchCount = 0;
+
+                PkgUsageStatsExtended pus = mStats.get(pkg);
+                if (pus != null) {
+                    usageTime = pus.mUsageTime;
+                    launchCount = pus.mLaunchCount;
+                }
+                retArr[i] = new PkgUsageStats(pkg, launchCount, usageTime,
+                        mLastResumeTimes.valueAt(i));
+            }
+            return retArr;
+        }
+    }
+    
+    static byte[] readFully(FileInputStream stream) throws java.io.IOException {
+        int pos = 0;
+        int avail = stream.available();
+        byte[] data = new byte[avail];
+        while (true) {
+            int amt = stream.read(data, pos, data.length-pos);
+            if (amt <= 0) {
+                return data;
+            }
+            pos += amt;
+            avail = stream.available();
+            if (avail > data.length-pos) {
+                byte[] newData = new byte[pos+avail];
+                System.arraycopy(data, 0, newData, 0, pos);
+                data = newData;
+            }
+        }
+    }
+    
+    private void collectDumpInfoFLOCK(PrintWriter pw, boolean isCompactOutput,
+            boolean deleteAfterPrint, HashSet<String> packages) {
+        List<String> fileList = getUsageStatsFileListFLOCK();
+        if (fileList == null) {
+            return;
+        }
+        Collections.sort(fileList);
+        for (String file : fileList) {
+            if (deleteAfterPrint && file.equalsIgnoreCase(mFileLeaf)) {
+                // In this mode we don't print the current day's stats, since
+                // they are incomplete.
+                continue;
+            }
+            File dFile = new File(mDir, file);
+            String dateStr = file.substring(FILE_PREFIX.length());
+            if (dateStr.length() > 0 && (dateStr.charAt(0) <= '0' || dateStr.charAt(0) >= '9')) {
+                // If the remainder does not start with a number, it is not a date,
+                // so we should ignore it for purposes here.
+                continue;
+            }
+            try {
+                Parcel in = getParcelForFile(dFile);
+                collectDumpInfoFromParcelFLOCK(in, pw, dateStr, isCompactOutput,
+                        packages);
+                if (deleteAfterPrint) {
+                    // Delete old file after collecting info only for checkin requests
+                    dFile.delete();
+                }
+            } catch (FileNotFoundException e) {
+                Slog.w(TAG, "Failed with "+e+" when collecting dump info from file : " + file);
+                return;
+            } catch (IOException e) {
+                Slog.w(TAG, "Failed with "+e+" when collecting dump info from file : "+file);
+            }      
+        }
+    }
+    
+    private void collectDumpInfoFromParcelFLOCK(Parcel in, PrintWriter pw,
+            String date, boolean isCompactOutput, HashSet<String> packages) {
+        StringBuilder sb = new StringBuilder(512);
+        if (isCompactOutput) {
+            sb.append("D:");
+            sb.append(CHECKIN_VERSION);
+            sb.append(',');
+        } else {
+            sb.append("Date: ");
+        }
+        
+        sb.append(date);
+        
+        int vers = in.readInt();
+        if (vers != VERSION) {
+            sb.append(" (old data version)");
+            pw.println(sb.toString());
+            return;
+        }
+        
+        pw.println(sb.toString());
+        int N = in.readInt();
+        
+        while (N > 0) {
+            N--;
+            String pkgName = in.readString();
+            if (pkgName == null) {
+                break;
+            }
+            sb.setLength(0);
+            PkgUsageStatsExtended pus = new PkgUsageStatsExtended(in);
+            if (packages != null && !packages.contains(pkgName)) {
+                // This package has not been requested -- don't print
+                // anything for it.
+            } else if (isCompactOutput) {
+                sb.append("P:");
+                sb.append(pkgName);
+                sb.append(',');
+                sb.append(pus.mLaunchCount);
+                sb.append(',');
+                sb.append(pus.mUsageTime);
+                sb.append('\n');
+                final int NLT = pus.mLaunchTimes.size();
+                for (int i=0; i<NLT; i++) {
+                    sb.append("A:");
+                    String activity = pus.mLaunchTimes.keyAt(i);
+                    sb.append(activity);
+                    TimeStats times = pus.mLaunchTimes.valueAt(i);
+                    sb.append(',');
+                    sb.append(times.count);
+                    for (int j=0; j<NUM_LAUNCH_TIME_BINS; j++) {
+                        sb.append(",");
+                        sb.append(times.times[j]);
+                    }
+                    sb.append('\n');
+                }
+                final int NFDT = pus.mFullyDrawnTimes.size();
+                for (int i=0; i<NFDT; i++) {
+                    sb.append("A:");
+                    String activity = pus.mFullyDrawnTimes.keyAt(i);
+                    sb.append(activity);
+                    TimeStats times = pus.mFullyDrawnTimes.valueAt(i);
+                    for (int j=0; j<NUM_LAUNCH_TIME_BINS; j++) {
+                        sb.append(",");
+                        sb.append(times.times[j]);
+                    }
+                    sb.append('\n');
+                }
+
+            } else {
+                sb.append("  ");
+                sb.append(pkgName);
+                sb.append(": ");
+                sb.append(pus.mLaunchCount);
+                sb.append(" times, ");
+                sb.append(pus.mUsageTime);
+                sb.append(" ms");
+                sb.append('\n');
+                final int NLT = pus.mLaunchTimes.size();
+                for (int i=0; i<NLT; i++) {
+                    sb.append("    ");
+                    sb.append(pus.mLaunchTimes.keyAt(i));
+                    TimeStats times = pus.mLaunchTimes.valueAt(i);
+                    sb.append(": ");
+                    sb.append(times.count);
+                    sb.append(" starts");
+                    int lastBin = 0;
+                    for (int j=0; j<NUM_LAUNCH_TIME_BINS-1; j++) {
+                        if (times.times[j] != 0) {
+                            sb.append(", ");
+                            sb.append(lastBin);
+                            sb.append('-');
+                            sb.append(LAUNCH_TIME_BINS[j]);
+                            sb.append("ms=");
+                            sb.append(times.times[j]);
+                        }
+                        lastBin = LAUNCH_TIME_BINS[j];
+                    }
+                    if (times.times[NUM_LAUNCH_TIME_BINS-1] != 0) {
+                        sb.append(", ");
+                        sb.append(">=");
+                        sb.append(lastBin);
+                        sb.append("ms=");
+                        sb.append(times.times[NUM_LAUNCH_TIME_BINS-1]);
+                    }
+                    sb.append('\n');
+                }
+                final int NFDT = pus.mFullyDrawnTimes.size();
+                for (int i=0; i<NFDT; i++) {
+                    sb.append("    ");
+                    sb.append(pus.mFullyDrawnTimes.keyAt(i));
+                    TimeStats times = pus.mFullyDrawnTimes.valueAt(i);
+                    sb.append(": fully drawn ");
+                    boolean needComma = false;
+                    int lastBin = 0;
+                    for (int j=0; j<NUM_LAUNCH_TIME_BINS-1; j++) {
+                        if (times.times[j] != 0) {
+                            if (needComma) {
+                                sb.append(", ");
+                            } else {
+                                needComma = true;
+                            }
+                            sb.append(lastBin);
+                            sb.append('-');
+                            sb.append(LAUNCH_TIME_BINS[j]);
+                            sb.append("ms=");
+                            sb.append(times.times[j]);
+                        }
+                        lastBin = LAUNCH_TIME_BINS[j];
+                    }
+                    if (times.times[NUM_LAUNCH_TIME_BINS-1] != 0) {
+                        if (needComma) {
+                            sb.append(", ");
+                        }
+                        sb.append(">=");
+                        sb.append(lastBin);
+                        sb.append("ms=");
+                        sb.append(times.times[NUM_LAUNCH_TIME_BINS-1]);
+                    }
+                    sb.append('\n');
+                }
+            }
+            
+            pw.write(sb.toString());
+        }
+    }
+    
+    /**
+     * Searches array of arguments for the specified string
+     * @param args array of argument strings
+     * @param value value to search for
+     * @return true if the value is contained in the array
+     */
+    private static boolean scanArgs(String[] args, String value) {
+        if (args != null) {
+            for (String arg : args) {
+                if (value.equals(arg)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+    
+    /**
+     * Searches array of arguments for the specified string's data
+     * @param args array of argument strings
+     * @param value value to search for
+     * @return the string of data after the arg, or null if there is none
+     */
+    private static String scanArgsData(String[] args, String value) {
+        if (args != null) {
+            final int N = args.length;
+            for (int i=0; i<N; i++) {
+                if (value.equals(args[i])) {
+                    i++;
+                    return i < N ? args[i] : null;
+                }
+            }
+        }
+        return null;
+    }
+    
+    @Override
+    /*
+     * The data persisted to file is parsed and the stats are computed. 
+     */
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump UsageStats from from pid="
+                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
+                    + " without permission " + android.Manifest.permission.DUMP);
+            return;
+        }
+
+        final boolean isCheckinRequest = scanArgs(args, "--checkin");
+        final boolean isCompactOutput = isCheckinRequest || scanArgs(args, "-c");
+        final boolean deleteAfterPrint = isCheckinRequest || scanArgs(args, "-d");
+        final String rawPackages = scanArgsData(args, "--packages");
+        
+        // Make sure the current stats are written to the file.  This
+        // doesn't need to be done if we are deleting files after printing,
+        // since it that case we won't print the current stats.
+        if (!deleteAfterPrint) {
+            writeStatsToFile(true, false);
+        }
+        
+        HashSet<String> packages = null;
+        if (rawPackages != null) {
+            if (!"*".equals(rawPackages)) {
+                // A * is a wildcard to show all packages.
+                String[] names = rawPackages.split(",");
+                for (String n : names) {
+                    if (packages == null) {
+                        packages = new HashSet<String>();
+                    }
+                    packages.add(n);
+                }
+            }
+        } else if (isCheckinRequest) {
+            // If checkin doesn't specify any packages, then we simply won't
+            // show anything.
+            Slog.w(TAG, "Checkin without packages");
+            return;
+        }
+        
+        synchronized (mFileLock) {
+            collectDumpInfoFLOCK(pw, isCompactOutput, deleteAfterPrint, packages);
+        }
+    }
+
+}
diff --git a/services/java/com/android/server/am/UserStartedState.java b/services/core/java/com/android/server/am/UserStartedState.java
similarity index 100%
rename from services/java/com/android/server/am/UserStartedState.java
rename to services/core/java/com/android/server/am/UserStartedState.java
diff --git a/services/java/com/android/server/am/package.html b/services/core/java/com/android/server/am/package.html
similarity index 100%
rename from services/java/com/android/server/am/package.html
rename to services/core/java/com/android/server/am/package.html
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java
new file mode 100644
index 0000000..6aa596d
--- /dev/null
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -0,0 +1,366 @@
+/*
+ * 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.server.clipboard;
+
+import android.app.ActivityManagerNative;
+import android.app.AppGlobals;
+import android.app.AppOpsManager;
+import android.app.IActivityManager;
+import android.content.BroadcastReceiver;
+import android.content.ClipData;
+import android.content.ClipDescription;
+import android.content.IClipboard;
+import android.content.IOnPrimaryClipChangedListener;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Process;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.util.Pair;
+import android.util.Slog;
+import android.util.SparseArray;
+
+import java.util.HashSet;
+
+/**
+ * Implementation of the clipboard for copy and paste.
+ */
+public class ClipboardService extends IClipboard.Stub {
+
+    private static final String TAG = "ClipboardService";
+
+    private final Context mContext;
+    private final IActivityManager mAm;
+    private final PackageManager mPm;
+    private final AppOpsManager mAppOps;
+    private final IBinder mPermissionOwner;
+
+    private class ListenerInfo {
+        final int mUid;
+        final String mPackageName;
+        ListenerInfo(int uid, String packageName) {
+            mUid = uid;
+            mPackageName = packageName;
+        }
+    }
+
+    private class PerUserClipboard {
+        final int userId;
+
+        final RemoteCallbackList<IOnPrimaryClipChangedListener> primaryClipListeners
+                = new RemoteCallbackList<IOnPrimaryClipChangedListener>();
+
+        ClipData primaryClip;
+
+        final HashSet<String> activePermissionOwners
+                = new HashSet<String>();
+
+        PerUserClipboard(int userId) {
+            this.userId = userId;
+        }
+    }
+
+    private SparseArray<PerUserClipboard> mClipboards = new SparseArray<PerUserClipboard>();
+
+    /**
+     * Instantiates the clipboard.
+     */
+    public ClipboardService(Context context) {
+        mContext = context;
+        mAm = ActivityManagerNative.getDefault();
+        mPm = context.getPackageManager();
+        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
+        IBinder permOwner = null;
+        try {
+            permOwner = mAm.newUriPermissionOwner("clipboard");
+        } catch (RemoteException e) {
+            Slog.w("clipboard", "AM dead", e);
+        }
+        mPermissionOwner = permOwner;
+
+        // Remove the clipboard if a user is removed
+        IntentFilter userFilter = new IntentFilter();
+        userFilter.addAction(Intent.ACTION_USER_REMOVED);
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                String action = intent.getAction();
+                if (Intent.ACTION_USER_REMOVED.equals(action)) {
+                    removeClipboard(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
+                }
+            }
+        }, userFilter);
+    }
+
+    @Override
+    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+            throws RemoteException {
+        try {
+            return super.onTransact(code, data, reply, flags);
+        } catch (RuntimeException e) {
+            if (!(e instanceof SecurityException)) {
+                Slog.wtf("clipboard", "Exception: ", e);
+            }
+            throw e;
+        }
+        
+    }
+
+    private PerUserClipboard getClipboard() {
+        return getClipboard(UserHandle.getCallingUserId());
+    }
+
+    private PerUserClipboard getClipboard(int userId) {
+        synchronized (mClipboards) {
+            PerUserClipboard puc = mClipboards.get(userId);
+            if (puc == null) {
+                puc = new PerUserClipboard(userId);
+                mClipboards.put(userId, puc);
+            }
+            return puc;
+        }
+    }
+
+    private void removeClipboard(int userId) {
+        synchronized (mClipboards) {
+            mClipboards.remove(userId);
+        }
+    }
+
+    public void setPrimaryClip(ClipData clip, String callingPackage) {
+        synchronized (this) {
+            if (clip != null && clip.getItemCount() <= 0) {
+                throw new IllegalArgumentException("No items");
+            }
+            final int callingUid = Binder.getCallingUid();
+            if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, callingUid,
+                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
+                return;
+            }
+            checkDataOwnerLocked(clip, callingUid);
+            clearActiveOwnersLocked();
+            PerUserClipboard clipboard = getClipboard();
+            clipboard.primaryClip = clip;
+            final long ident = Binder.clearCallingIdentity();
+            final int n = clipboard.primaryClipListeners.beginBroadcast();
+            try {
+                for (int i = 0; i < n; i++) {
+                    try {
+                        ListenerInfo li = (ListenerInfo)
+                                clipboard.primaryClipListeners.getBroadcastCookie(i);
+                        if (mAppOps.checkOpNoThrow(AppOpsManager.OP_READ_CLIPBOARD, li.mUid,
+                                li.mPackageName) == AppOpsManager.MODE_ALLOWED) {
+                            clipboard.primaryClipListeners.getBroadcastItem(i)
+                                    .dispatchPrimaryClipChanged();
+                        }
+                    } catch (RemoteException e) {
+                        // The RemoteCallbackList will take care of removing
+                        // the dead object for us.
+                    }
+                }
+            } finally {
+                clipboard.primaryClipListeners.finishBroadcast();
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+    
+    public ClipData getPrimaryClip(String pkg) {
+        synchronized (this) {
+            if (mAppOps.noteOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
+                    pkg) != AppOpsManager.MODE_ALLOWED) {
+                return null;
+            }
+            addActiveOwnerLocked(Binder.getCallingUid(), pkg);
+            return getClipboard().primaryClip;
+        }
+    }
+
+    public ClipDescription getPrimaryClipDescription(String callingPackage) {
+        synchronized (this) {
+            if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
+                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
+                return null;
+            }
+            PerUserClipboard clipboard = getClipboard();
+            return clipboard.primaryClip != null ? clipboard.primaryClip.getDescription() : null;
+        }
+    }
+
+    public boolean hasPrimaryClip(String callingPackage) {
+        synchronized (this) {
+            if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
+                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
+                return false;
+            }
+            return getClipboard().primaryClip != null;
+        }
+    }
+
+    public void addPrimaryClipChangedListener(IOnPrimaryClipChangedListener listener,
+            String callingPackage) {
+        synchronized (this) {
+            getClipboard().primaryClipListeners.register(listener,
+                    new ListenerInfo(Binder.getCallingUid(), callingPackage));
+        }
+    }
+
+    public void removePrimaryClipChangedListener(IOnPrimaryClipChangedListener listener) {
+        synchronized (this) {
+            getClipboard().primaryClipListeners.unregister(listener);
+        }
+    }
+
+    public boolean hasClipboardText(String callingPackage) {
+        synchronized (this) {
+            if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
+                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
+                return false;
+            }
+            PerUserClipboard clipboard = getClipboard();
+            if (clipboard.primaryClip != null) {
+                CharSequence text = clipboard.primaryClip.getItemAt(0).getText();
+                return text != null && text.length() > 0;
+            }
+            return false;
+        }
+    }
+
+    private final void checkUriOwnerLocked(Uri uri, int uid) {
+        if (!"content".equals(uri.getScheme())) {
+            return;
+        }
+        long ident = Binder.clearCallingIdentity();
+        try {
+            // This will throw SecurityException for us.
+            mAm.checkGrantUriPermission(uid, null, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+        } catch (RemoteException e) {
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private final void checkItemOwnerLocked(ClipData.Item item, int uid) {
+        if (item.getUri() != null) {
+            checkUriOwnerLocked(item.getUri(), uid);
+        }
+        Intent intent = item.getIntent();
+        if (intent != null && intent.getData() != null) {
+            checkUriOwnerLocked(intent.getData(), uid);
+        }
+    }
+
+    private final void checkDataOwnerLocked(ClipData data, int uid) {
+        final int N = data.getItemCount();
+        for (int i=0; i<N; i++) {
+            checkItemOwnerLocked(data.getItemAt(i), uid);
+        }
+    }
+
+    private final void grantUriLocked(Uri uri, String pkg) {
+        long ident = Binder.clearCallingIdentity();
+        try {
+            mAm.grantUriPermissionFromOwner(mPermissionOwner, Process.myUid(), pkg, uri,
+                    Intent.FLAG_GRANT_READ_URI_PERMISSION);
+        } catch (RemoteException e) {
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private final void grantItemLocked(ClipData.Item item, String pkg) {
+        if (item.getUri() != null) {
+            grantUriLocked(item.getUri(), pkg);
+        }
+        Intent intent = item.getIntent();
+        if (intent != null && intent.getData() != null) {
+            grantUriLocked(intent.getData(), pkg);
+        }
+    }
+
+    private final void addActiveOwnerLocked(int uid, String pkg) {
+        final IPackageManager pm = AppGlobals.getPackageManager();
+        final int targetUserHandle = UserHandle.getCallingUserId();
+        final long oldIdentity = Binder.clearCallingIdentity();
+        try {
+            PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle);
+            if (pi == null) {
+                throw new IllegalArgumentException("Unknown package " + pkg);
+            }
+            if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) {
+                throw new SecurityException("Calling uid " + uid
+                        + " does not own package " + pkg);
+            }
+        } catch (RemoteException e) {
+            // Can't happen; the package manager is in the same process
+        } finally {
+            Binder.restoreCallingIdentity(oldIdentity);
+        }
+        PerUserClipboard clipboard = getClipboard();
+        if (clipboard.primaryClip != null && !clipboard.activePermissionOwners.contains(pkg)) {
+            final int N = clipboard.primaryClip.getItemCount();
+            for (int i=0; i<N; i++) {
+                grantItemLocked(clipboard.primaryClip.getItemAt(i), pkg);
+            }
+            clipboard.activePermissionOwners.add(pkg);
+        }
+    }
+
+    private final void revokeUriLocked(Uri uri) {
+        long ident = Binder.clearCallingIdentity();
+        try {
+            mAm.revokeUriPermissionFromOwner(mPermissionOwner, uri,
+                    Intent.FLAG_GRANT_READ_URI_PERMISSION
+                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+        } catch (RemoteException e) {
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private final void revokeItemLocked(ClipData.Item item) {
+        if (item.getUri() != null) {
+            revokeUriLocked(item.getUri());
+        }
+        Intent intent = item.getIntent();
+        if (intent != null && intent.getData() != null) {
+            revokeUriLocked(intent.getData());
+        }
+    }
+
+    private final void clearActiveOwnersLocked() {
+        PerUserClipboard clipboard = getClipboard();
+        clipboard.activePermissionOwners.clear();
+        if (clipboard.primaryClip == null) {
+            return;
+        }
+        final int N = clipboard.primaryClip.getItemCount();
+        for (int i=0; i<N; i++) {
+            revokeItemLocked(clipboard.primaryClip.getItemAt(i));
+        }
+    }
+}
diff --git a/services/java/com/android/server/connectivity/DataConnectionStats.java b/services/core/java/com/android/server/connectivity/DataConnectionStats.java
similarity index 100%
rename from services/java/com/android/server/connectivity/DataConnectionStats.java
rename to services/core/java/com/android/server/connectivity/DataConnectionStats.java
diff --git a/services/java/com/android/server/connectivity/Nat464Xlat.java b/services/core/java/com/android/server/connectivity/Nat464Xlat.java
similarity index 100%
rename from services/java/com/android/server/connectivity/Nat464Xlat.java
rename to services/core/java/com/android/server/connectivity/Nat464Xlat.java
diff --git a/services/java/com/android/server/connectivity/PacManager.java b/services/core/java/com/android/server/connectivity/PacManager.java
similarity index 100%
rename from services/java/com/android/server/connectivity/PacManager.java
rename to services/core/java/com/android/server/connectivity/PacManager.java
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java
new file mode 100644
index 0000000..adf1dfc
--- /dev/null
+++ b/services/core/java/com/android/server/connectivity/Tethering.java
@@ -0,0 +1,1590 @@
+/*
+ * Copyright (C) 2010 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.connectivity;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.hardware.usb.UsbManager;
+import android.net.ConnectivityManager;
+import android.net.IConnectivityManager;
+import android.net.INetworkManagementEventObserver;
+import android.net.INetworkStatsService;
+import android.net.InterfaceConfiguration;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.net.NetworkInfo;
+import android.net.NetworkUtils;
+import android.net.RouteInfo;
+import android.os.Binder;
+import android.os.INetworkManagementService;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.util.Log;
+
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.util.IState;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
+import com.android.server.IoThread;
+import com.android.server.net.BaseNetworkObserver;
+import com.google.android.collect.Lists;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @hide
+ *
+ * Timeout
+ *
+ * TODO - look for parent classes and code sharing
+ */
+public class Tethering extends BaseNetworkObserver {
+
+    private Context mContext;
+    private final static String TAG = "Tethering";
+    private final static boolean DBG = true;
+    private final static boolean VDBG = false;
+
+    // TODO - remove both of these - should be part of interface inspection/selection stuff
+    private String[] mTetherableUsbRegexs;
+    private String[] mTetherableWifiRegexs;
+    private String[] mTetherableBluetoothRegexs;
+    private Collection<Integer> mUpstreamIfaceTypes;
+
+    // used to synchronize public access to members
+    private Object mPublicSync;
+
+    private static final Integer MOBILE_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE);
+    private static final Integer HIPRI_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_HIPRI);
+    private static final Integer DUN_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_DUN);
+
+    // if we have to connect to mobile, what APN type should we use?  Calculated by examining the
+    // upstream type list and the DUN_REQUIRED secure-setting
+    private int mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_NONE;
+
+    private final INetworkManagementService mNMService;
+    private final INetworkStatsService mStatsService;
+    private final IConnectivityManager mConnService;
+    private Looper mLooper;
+
+    private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces
+
+    private BroadcastReceiver mStateReceiver;
+
+    private static final String USB_NEAR_IFACE_ADDR      = "192.168.42.129";
+    private static final int USB_PREFIX_LENGTH        = 24;
+
+    // USB is  192.168.42.1 and 255.255.255.0
+    // Wifi is 192.168.43.1 and 255.255.255.0
+    // BT is limited to max default of 5 connections. 192.168.44.1 to 192.168.48.1
+    // with 255.255.255.0
+
+    private String[] mDhcpRange;
+    private static final String[] DHCP_DEFAULT_RANGE = {
+        "192.168.42.2", "192.168.42.254", "192.168.43.2", "192.168.43.254",
+        "192.168.44.2", "192.168.44.254", "192.168.45.2", "192.168.45.254",
+        "192.168.46.2", "192.168.46.254", "192.168.47.2", "192.168.47.254",
+        "192.168.48.2", "192.168.48.254",
+    };
+
+    private String[] mDefaultDnsServers;
+    private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8";
+    private static final String DNS_DEFAULT_SERVER2 = "8.8.4.4";
+
+    private StateMachine mTetherMasterSM;
+
+    private Notification mTetheredNotification;
+
+    private boolean mRndisEnabled;       // track the RNDIS function enabled state
+    private boolean mUsbTetherRequested; // true if USB tethering should be started
+                                         // when RNDIS is enabled
+
+    public Tethering(Context context, INetworkManagementService nmService,
+            INetworkStatsService statsService, IConnectivityManager connService, Looper looper) {
+        mContext = context;
+        mNMService = nmService;
+        mStatsService = statsService;
+        mConnService = connService;
+        mLooper = looper;
+
+        mPublicSync = new Object();
+
+        mIfaces = new HashMap<String, TetherInterfaceSM>();
+
+        // make our own thread so we don't anr the system
+        mLooper = IoThread.get().getLooper();
+        mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper);
+        mTetherMasterSM.start();
+
+        mStateReceiver = new StateReceiver();
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(UsbManager.ACTION_USB_STATE);
+        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
+        mContext.registerReceiver(mStateReceiver, filter);
+
+        filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_MEDIA_SHARED);
+        filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
+        filter.addDataScheme("file");
+        mContext.registerReceiver(mStateReceiver, filter);
+
+        mDhcpRange = context.getResources().getStringArray(
+                com.android.internal.R.array.config_tether_dhcp_range);
+        if ((mDhcpRange.length == 0) || (mDhcpRange.length % 2 ==1)) {
+            mDhcpRange = DHCP_DEFAULT_RANGE;
+        }
+
+        // load device config info
+        updateConfiguration();
+
+        // TODO - remove and rely on real notifications of the current iface
+        mDefaultDnsServers = new String[2];
+        mDefaultDnsServers[0] = DNS_DEFAULT_SERVER1;
+        mDefaultDnsServers[1] = DNS_DEFAULT_SERVER2;
+    }
+
+    void updateConfiguration() {
+        String[] tetherableUsbRegexs = mContext.getResources().getStringArray(
+                com.android.internal.R.array.config_tether_usb_regexs);
+        String[] tetherableWifiRegexs = mContext.getResources().getStringArray(
+                com.android.internal.R.array.config_tether_wifi_regexs);
+        String[] tetherableBluetoothRegexs = mContext.getResources().getStringArray(
+                com.android.internal.R.array.config_tether_bluetooth_regexs);
+
+        int ifaceTypes[] = mContext.getResources().getIntArray(
+                com.android.internal.R.array.config_tether_upstream_types);
+        Collection<Integer> upstreamIfaceTypes = new ArrayList();
+        for (int i : ifaceTypes) {
+            upstreamIfaceTypes.add(new Integer(i));
+        }
+
+        synchronized (mPublicSync) {
+            mTetherableUsbRegexs = tetherableUsbRegexs;
+            mTetherableWifiRegexs = tetherableWifiRegexs;
+            mTetherableBluetoothRegexs = tetherableBluetoothRegexs;
+            mUpstreamIfaceTypes = upstreamIfaceTypes;
+        }
+
+        // check if the upstream type list needs to be modified due to secure-settings
+        checkDunRequired();
+    }
+
+    public void interfaceStatusChanged(String iface, boolean up) {
+        if (VDBG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up);
+        boolean found = false;
+        boolean usb = false;
+        synchronized (mPublicSync) {
+            if (isWifi(iface)) {
+                found = true;
+            } else if (isUsb(iface)) {
+                found = true;
+                usb = true;
+            } else if (isBluetooth(iface)) {
+                found = true;
+            }
+            if (found == false) return;
+
+            TetherInterfaceSM sm = mIfaces.get(iface);
+            if (up) {
+                if (sm == null) {
+                    sm = new TetherInterfaceSM(iface, mLooper, usb);
+                    mIfaces.put(iface, sm);
+                    sm.start();
+                }
+            } else {
+                if (isUsb(iface)) {
+                    // ignore usb0 down after enabling RNDIS
+                    // we will handle disconnect in interfaceRemoved instead
+                    if (VDBG) Log.d(TAG, "ignore interface down for " + iface);
+                } else if (sm != null) {
+                    sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
+                    mIfaces.remove(iface);
+                }
+            }
+        }
+    }
+
+    public void interfaceLinkStateChanged(String iface, boolean up) {
+        if (VDBG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up);
+        interfaceStatusChanged(iface, up);
+    }
+
+    private boolean isUsb(String iface) {
+        synchronized (mPublicSync) {
+            for (String regex : mTetherableUsbRegexs) {
+                if (iface.matches(regex)) return true;
+            }
+            return false;
+        }
+    }
+
+    public boolean isWifi(String iface) {
+        synchronized (mPublicSync) {
+            for (String regex : mTetherableWifiRegexs) {
+                if (iface.matches(regex)) return true;
+            }
+            return false;
+        }
+    }
+
+    public boolean isBluetooth(String iface) {
+        synchronized (mPublicSync) {
+            for (String regex : mTetherableBluetoothRegexs) {
+                if (iface.matches(regex)) return true;
+            }
+            return false;
+        }
+    }
+
+    public void interfaceAdded(String iface) {
+        if (VDBG) Log.d(TAG, "interfaceAdded " + iface);
+        boolean found = false;
+        boolean usb = false;
+        synchronized (mPublicSync) {
+            if (isWifi(iface)) {
+                found = true;
+            }
+            if (isUsb(iface)) {
+                found = true;
+                usb = true;
+            }
+            if (isBluetooth(iface)) {
+                found = true;
+            }
+            if (found == false) {
+                if (VDBG) Log.d(TAG, iface + " is not a tetherable iface, ignoring");
+                return;
+            }
+
+            TetherInterfaceSM sm = mIfaces.get(iface);
+            if (sm != null) {
+                if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring");
+                return;
+            }
+            sm = new TetherInterfaceSM(iface, mLooper, usb);
+            mIfaces.put(iface, sm);
+            sm.start();
+        }
+    }
+
+    public void interfaceRemoved(String iface) {
+        if (VDBG) Log.d(TAG, "interfaceRemoved " + iface);
+        synchronized (mPublicSync) {
+            TetherInterfaceSM sm = mIfaces.get(iface);
+            if (sm == null) {
+                if (VDBG) {
+                    Log.e(TAG, "attempting to remove unknown iface (" + iface + "), ignoring");
+                }
+                return;
+            }
+            sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
+            mIfaces.remove(iface);
+        }
+    }
+
+    public int tether(String iface) {
+        if (DBG) Log.d(TAG, "Tethering " + iface);
+        TetherInterfaceSM sm = null;
+        synchronized (mPublicSync) {
+            sm = mIfaces.get(iface);
+        }
+        if (sm == null) {
+            Log.e(TAG, "Tried to Tether an unknown iface :" + iface + ", ignoring");
+            return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
+        }
+        if (!sm.isAvailable() && !sm.isErrored()) {
+            Log.e(TAG, "Tried to Tether an unavailable iface :" + iface + ", ignoring");
+            return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
+        }
+        sm.sendMessage(TetherInterfaceSM.CMD_TETHER_REQUESTED);
+        return ConnectivityManager.TETHER_ERROR_NO_ERROR;
+    }
+
+    public int untether(String iface) {
+        if (DBG) Log.d(TAG, "Untethering " + iface);
+        TetherInterfaceSM sm = null;
+        synchronized (mPublicSync) {
+            sm = mIfaces.get(iface);
+        }
+        if (sm == null) {
+            Log.e(TAG, "Tried to Untether an unknown iface :" + iface + ", ignoring");
+            return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
+        }
+        if (sm.isErrored()) {
+            Log.e(TAG, "Tried to Untethered an errored iface :" + iface + ", ignoring");
+            return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
+        }
+        sm.sendMessage(TetherInterfaceSM.CMD_TETHER_UNREQUESTED);
+        return ConnectivityManager.TETHER_ERROR_NO_ERROR;
+    }
+
+    public int getLastTetherError(String iface) {
+        TetherInterfaceSM sm = null;
+        synchronized (mPublicSync) {
+            sm = mIfaces.get(iface);
+            if (sm == null) {
+                Log.e(TAG, "Tried to getLastTetherError on an unknown iface :" + iface +
+                        ", ignoring");
+                return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
+            }
+            return sm.getLastError();
+        }
+    }
+
+    // TODO - move all private methods used only by the state machine into the state machine
+    // to clarify what needs synchronized protection.
+    private void sendTetherStateChangedBroadcast() {
+        try {
+            if (!mConnService.isTetheringSupported()) return;
+        } catch (RemoteException e) {
+            return;
+        }
+
+        ArrayList<String> availableList = new ArrayList<String>();
+        ArrayList<String> activeList = new ArrayList<String>();
+        ArrayList<String> erroredList = new ArrayList<String>();
+
+        boolean wifiTethered = false;
+        boolean usbTethered = false;
+        boolean bluetoothTethered = false;
+
+        synchronized (mPublicSync) {
+            Set ifaces = mIfaces.keySet();
+            for (Object iface : ifaces) {
+                TetherInterfaceSM sm = mIfaces.get(iface);
+                if (sm != null) {
+                    if (sm.isErrored()) {
+                        erroredList.add((String)iface);
+                    } else if (sm.isAvailable()) {
+                        availableList.add((String)iface);
+                    } else if (sm.isTethered()) {
+                        if (isUsb((String)iface)) {
+                            usbTethered = true;
+                        } else if (isWifi((String)iface)) {
+                            wifiTethered = true;
+                      } else if (isBluetooth((String)iface)) {
+                            bluetoothTethered = true;
+                        }
+                        activeList.add((String)iface);
+                    }
+                }
+            }
+        }
+        Intent broadcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
+        broadcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
+                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER,
+                availableList);
+        broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, activeList);
+        broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER,
+                erroredList);
+        mContext.sendStickyBroadcastAsUser(broadcast, UserHandle.ALL);
+        if (DBG) {
+            Log.d(TAG, "sendTetherStateChangedBroadcast " + availableList.size() + ", " +
+                    activeList.size() + ", " + erroredList.size());
+        }
+
+        if (usbTethered) {
+            if (wifiTethered || bluetoothTethered) {
+                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general);
+            } else {
+                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_usb);
+            }
+        } else if (wifiTethered) {
+            if (bluetoothTethered) {
+                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general);
+            } else {
+                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_wifi);
+            }
+        } else if (bluetoothTethered) {
+            showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_bluetooth);
+        } else {
+            clearTetheredNotification();
+        }
+    }
+
+    private void showTetheredNotification(int icon) {
+        NotificationManager notificationManager =
+                (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+        if (notificationManager == null) {
+            return;
+        }
+
+        if (mTetheredNotification != null) {
+            if (mTetheredNotification.icon == icon) {
+                return;
+            }
+            notificationManager.cancelAsUser(null, mTetheredNotification.icon,
+                    UserHandle.ALL);
+        }
+
+        Intent intent = new Intent();
+        intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
+        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
+
+        PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0,
+                null, UserHandle.CURRENT);
+
+        Resources r = Resources.getSystem();
+        CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
+        CharSequence message = r.getText(com.android.internal.R.string.
+                tethered_notification_message);
+
+        if (mTetheredNotification == null) {
+            mTetheredNotification = new Notification();
+            mTetheredNotification.when = 0;
+        }
+        mTetheredNotification.icon = icon;
+        mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND;
+        mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT;
+        mTetheredNotification.tickerText = title;
+        mTetheredNotification.setLatestEventInfo(mContext, title, message, pi);
+
+        notificationManager.notifyAsUser(null, mTetheredNotification.icon,
+                mTetheredNotification, UserHandle.ALL);
+    }
+
+    private void clearTetheredNotification() {
+        NotificationManager notificationManager =
+            (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+        if (notificationManager != null && mTetheredNotification != null) {
+            notificationManager.cancelAsUser(null, mTetheredNotification.icon,
+                    UserHandle.ALL);
+            mTetheredNotification = null;
+        }
+    }
+
+    private class StateReceiver extends BroadcastReceiver {
+        public void onReceive(Context content, Intent intent) {
+            String action = intent.getAction();
+            if (action.equals(UsbManager.ACTION_USB_STATE)) {
+                synchronized (Tethering.this.mPublicSync) {
+                    boolean usbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
+                    mRndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false);
+                    // start tethering if we have a request pending
+                    if (usbConnected && mRndisEnabled && mUsbTetherRequested) {
+                        tetherUsb(true);
+                    }
+                    mUsbTetherRequested = false;
+                }
+            } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+                NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(
+                        ConnectivityManager.EXTRA_NETWORK_INFO);
+                if (networkInfo != null &&
+                        networkInfo.getDetailedState() != NetworkInfo.DetailedState.FAILED) {
+                    if (VDBG) Log.d(TAG, "Tethering got CONNECTIVITY_ACTION");
+                    mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED);
+                }
+            } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
+                updateConfiguration();
+            }
+        }
+    }
+
+    private void tetherUsb(boolean enable) {
+        if (VDBG) Log.d(TAG, "tetherUsb " + enable);
+
+        String[] ifaces = new String[0];
+        try {
+            ifaces = mNMService.listInterfaces();
+        } catch (Exception e) {
+            Log.e(TAG, "Error listing Interfaces", e);
+            return;
+        }
+        for (String iface : ifaces) {
+            if (isUsb(iface)) {
+                int result = (enable ? tether(iface) : untether(iface));
+                if (result == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+                    return;
+                }
+            }
+        }
+        Log.e(TAG, "unable start or stop USB tethering");
+    }
+
+    // configured when we start tethering and unconfig'd on error or conclusion
+    private boolean configureUsbIface(boolean enabled) {
+        if (VDBG) Log.d(TAG, "configureUsbIface(" + enabled + ")");
+
+        // toggle the USB interfaces
+        String[] ifaces = new String[0];
+        try {
+            ifaces = mNMService.listInterfaces();
+        } catch (Exception e) {
+            Log.e(TAG, "Error listing Interfaces", e);
+            return false;
+        }
+        for (String iface : ifaces) {
+            if (isUsb(iface)) {
+                InterfaceConfiguration ifcg = null;
+                try {
+                    ifcg = mNMService.getInterfaceConfig(iface);
+                    if (ifcg != null) {
+                        InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
+                        ifcg.setLinkAddress(new LinkAddress(addr, USB_PREFIX_LENGTH));
+                        if (enabled) {
+                            ifcg.setInterfaceUp();
+                        } else {
+                            ifcg.setInterfaceDown();
+                        }
+                        ifcg.clearFlag("running");
+                        mNMService.setInterfaceConfig(iface, ifcg);
+                    }
+                } catch (Exception e) {
+                    Log.e(TAG, "Error configuring interface " + iface, e);
+                    return false;
+                }
+            }
+         }
+
+        return true;
+    }
+
+    // TODO - return copies so people can't tamper
+    public String[] getTetherableUsbRegexs() {
+        return mTetherableUsbRegexs;
+    }
+
+    public String[] getTetherableWifiRegexs() {
+        return mTetherableWifiRegexs;
+    }
+
+    public String[] getTetherableBluetoothRegexs() {
+        return mTetherableBluetoothRegexs;
+    }
+
+    public int setUsbTethering(boolean enable) {
+        if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
+        UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
+
+        synchronized (mPublicSync) {
+            if (enable) {
+                if (mRndisEnabled) {
+                    tetherUsb(true);
+                } else {
+                    mUsbTetherRequested = true;
+                    usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false);
+                }
+            } else {
+                tetherUsb(false);
+                if (mRndisEnabled) {
+                    usbManager.setCurrentFunction(null, false);
+                }
+                mUsbTetherRequested = false;
+            }
+        }
+        return ConnectivityManager.TETHER_ERROR_NO_ERROR;
+    }
+
+    public int[] getUpstreamIfaceTypes() {
+        int values[];
+        synchronized (mPublicSync) {
+            updateConfiguration();  // TODO - remove?
+            values = new int[mUpstreamIfaceTypes.size()];
+            Iterator<Integer> iterator = mUpstreamIfaceTypes.iterator();
+            for (int i=0; i < mUpstreamIfaceTypes.size(); i++) {
+                values[i] = iterator.next();
+            }
+        }
+        return values;
+    }
+
+    public void checkDunRequired() {
+        int secureSetting = Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.TETHER_DUN_REQUIRED, 2);
+        synchronized (mPublicSync) {
+            // 2 = not set, 0 = DUN not required, 1 = DUN required
+            if (secureSetting != 2) {
+                int requiredApn = (secureSetting == 1 ?
+                        ConnectivityManager.TYPE_MOBILE_DUN :
+                        ConnectivityManager.TYPE_MOBILE_HIPRI);
+                if (requiredApn == ConnectivityManager.TYPE_MOBILE_DUN) {
+                    while (mUpstreamIfaceTypes.contains(MOBILE_TYPE)) {
+                        mUpstreamIfaceTypes.remove(MOBILE_TYPE);
+                    }
+                    while (mUpstreamIfaceTypes.contains(HIPRI_TYPE)) {
+                        mUpstreamIfaceTypes.remove(HIPRI_TYPE);
+                    }
+                    if (mUpstreamIfaceTypes.contains(DUN_TYPE) == false) {
+                        mUpstreamIfaceTypes.add(DUN_TYPE);
+                    }
+                } else {
+                    while (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
+                        mUpstreamIfaceTypes.remove(DUN_TYPE);
+                    }
+                    if (mUpstreamIfaceTypes.contains(MOBILE_TYPE) == false) {
+                        mUpstreamIfaceTypes.add(MOBILE_TYPE);
+                    }
+                    if (mUpstreamIfaceTypes.contains(HIPRI_TYPE) == false) {
+                        mUpstreamIfaceTypes.add(HIPRI_TYPE);
+                    }
+                }
+            }
+            if (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
+                mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_DUN;
+            } else {
+                mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI;
+            }
+        }
+    }
+
+    // TODO review API - maybe return ArrayList<String> here and below?
+    public String[] getTetheredIfaces() {
+        ArrayList<String> list = new ArrayList<String>();
+        synchronized (mPublicSync) {
+            Set keys = mIfaces.keySet();
+            for (Object key : keys) {
+                TetherInterfaceSM sm = mIfaces.get(key);
+                if (sm.isTethered()) {
+                    list.add((String)key);
+                }
+            }
+        }
+        String[] retVal = new String[list.size()];
+        for (int i=0; i < list.size(); i++) {
+            retVal[i] = list.get(i);
+        }
+        return retVal;
+    }
+
+    public String[] getTetherableIfaces() {
+        ArrayList<String> list = new ArrayList<String>();
+        synchronized (mPublicSync) {
+            Set keys = mIfaces.keySet();
+            for (Object key : keys) {
+                TetherInterfaceSM sm = mIfaces.get(key);
+                if (sm.isAvailable()) {
+                    list.add((String)key);
+                }
+            }
+        }
+        String[] retVal = new String[list.size()];
+        for (int i=0; i < list.size(); i++) {
+            retVal[i] = list.get(i);
+        }
+        return retVal;
+    }
+
+    public String[] getErroredIfaces() {
+        ArrayList<String> list = new ArrayList<String>();
+        synchronized (mPublicSync) {
+            Set keys = mIfaces.keySet();
+            for (Object key : keys) {
+                TetherInterfaceSM sm = mIfaces.get(key);
+                if (sm.isErrored()) {
+                    list.add((String)key);
+                }
+            }
+        }
+        String[] retVal = new String[list.size()];
+        for (int i= 0; i< list.size(); i++) {
+            retVal[i] = list.get(i);
+        }
+        return retVal;
+    }
+
+    //TODO: Temporary handling upstream change triggered without
+    //      CONNECTIVITY_ACTION. Only to accomodate interface
+    //      switch during HO.
+    //      @see bug/4455071
+    public void handleTetherIfaceChange() {
+        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED);
+    }
+
+    class TetherInterfaceSM extends StateMachine {
+        // notification from the master SM that it's not in tether mode
+        static final int CMD_TETHER_MODE_DEAD            =  1;
+        // request from the user that it wants to tether
+        static final int CMD_TETHER_REQUESTED            =  2;
+        // request from the user that it wants to untether
+        static final int CMD_TETHER_UNREQUESTED          =  3;
+        // notification that this interface is down
+        static final int CMD_INTERFACE_DOWN              =  4;
+        // notification that this interface is up
+        static final int CMD_INTERFACE_UP                =  5;
+        // notification from the master SM that it had an error turning on cellular dun
+        static final int CMD_CELL_DUN_ERROR              =  6;
+        // notification from the master SM that it had trouble enabling IP Forwarding
+        static final int CMD_IP_FORWARDING_ENABLE_ERROR  =  7;
+        // notification from the master SM that it had trouble disabling IP Forwarding
+        static final int CMD_IP_FORWARDING_DISABLE_ERROR =  8;
+        // notification from the master SM that it had trouble staring tethering
+        static final int CMD_START_TETHERING_ERROR       =  9;
+        // notification from the master SM that it had trouble stopping tethering
+        static final int CMD_STOP_TETHERING_ERROR        = 10;
+        // notification from the master SM that it had trouble setting the DNS forwarders
+        static final int CMD_SET_DNS_FORWARDERS_ERROR    = 11;
+        // the upstream connection has changed
+        static final int CMD_TETHER_CONNECTION_CHANGED   = 12;
+
+        private State mDefaultState;
+
+        private State mInitialState;
+        private State mStartingState;
+        private State mTetheredState;
+
+        private State mUnavailableState;
+
+        private boolean mAvailable;
+        private boolean mTethered;
+        int mLastError;
+
+        String mIfaceName;
+        String mMyUpstreamIfaceName;  // may change over time
+
+        boolean mUsb;
+
+        TetherInterfaceSM(String name, Looper looper, boolean usb) {
+            super(name, looper);
+            mIfaceName = name;
+            mUsb = usb;
+            setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
+
+            mInitialState = new InitialState();
+            addState(mInitialState);
+            mStartingState = new StartingState();
+            addState(mStartingState);
+            mTetheredState = new TetheredState();
+            addState(mTetheredState);
+            mUnavailableState = new UnavailableState();
+            addState(mUnavailableState);
+
+            setInitialState(mInitialState);
+        }
+
+        public String toString() {
+            String res = new String();
+            res += mIfaceName + " - ";
+            IState current = getCurrentState();
+            if (current == mInitialState) res += "InitialState";
+            if (current == mStartingState) res += "StartingState";
+            if (current == mTetheredState) res += "TetheredState";
+            if (current == mUnavailableState) res += "UnavailableState";
+            if (mAvailable) res += " - Available";
+            if (mTethered) res += " - Tethered";
+            res += " - lastError =" + mLastError;
+            return res;
+        }
+
+        public int getLastError() {
+            synchronized (Tethering.this.mPublicSync) {
+                return mLastError;
+            }
+        }
+
+        private void setLastError(int error) {
+            synchronized (Tethering.this.mPublicSync) {
+                mLastError = error;
+
+                if (isErrored()) {
+                    if (mUsb) {
+                        // note everything's been unwound by this point so nothing to do on
+                        // further error..
+                        Tethering.this.configureUsbIface(false);
+                    }
+                }
+            }
+        }
+
+        public boolean isAvailable() {
+            synchronized (Tethering.this.mPublicSync) {
+                return mAvailable;
+            }
+        }
+
+        private void setAvailable(boolean available) {
+            synchronized (Tethering.this.mPublicSync) {
+                mAvailable = available;
+            }
+        }
+
+        public boolean isTethered() {
+            synchronized (Tethering.this.mPublicSync) {
+                return mTethered;
+            }
+        }
+
+        private void setTethered(boolean tethered) {
+            synchronized (Tethering.this.mPublicSync) {
+                mTethered = tethered;
+            }
+        }
+
+        public boolean isErrored() {
+            synchronized (Tethering.this.mPublicSync) {
+                return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR);
+            }
+        }
+
+        class InitialState extends State {
+            @Override
+            public void enter() {
+                setAvailable(true);
+                setTethered(false);
+                sendTetherStateChangedBroadcast();
+            }
+
+            @Override
+            public boolean processMessage(Message message) {
+                if (DBG) Log.d(TAG, "InitialState.processMessage what=" + message.what);
+                boolean retValue = true;
+                switch (message.what) {
+                    case CMD_TETHER_REQUESTED:
+                        setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
+                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_REQUESTED,
+                                TetherInterfaceSM.this);
+                        transitionTo(mStartingState);
+                        break;
+                    case CMD_INTERFACE_DOWN:
+                        transitionTo(mUnavailableState);
+                        break;
+                    default:
+                        retValue = false;
+                        break;
+                }
+                return retValue;
+            }
+        }
+
+        class StartingState extends State {
+            @Override
+            public void enter() {
+                setAvailable(false);
+                if (mUsb) {
+                    if (!Tethering.this.configureUsbIface(true)) {
+                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
+                                TetherInterfaceSM.this);
+                        setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
+
+                        transitionTo(mInitialState);
+                        return;
+                    }
+                }
+                sendTetherStateChangedBroadcast();
+
+                // Skipping StartingState
+                transitionTo(mTetheredState);
+            }
+            @Override
+            public boolean processMessage(Message message) {
+                if (DBG) Log.d(TAG, "StartingState.processMessage what=" + message.what);
+                boolean retValue = true;
+                switch (message.what) {
+                    // maybe a parent class?
+                    case CMD_TETHER_UNREQUESTED:
+                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
+                                TetherInterfaceSM.this);
+                        if (mUsb) {
+                            if (!Tethering.this.configureUsbIface(false)) {
+                                setLastErrorAndTransitionToInitialState(
+                                    ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
+                                break;
+                            }
+                        }
+                        transitionTo(mInitialState);
+                        break;
+                    case CMD_CELL_DUN_ERROR:
+                    case CMD_IP_FORWARDING_ENABLE_ERROR:
+                    case CMD_IP_FORWARDING_DISABLE_ERROR:
+                    case CMD_START_TETHERING_ERROR:
+                    case CMD_STOP_TETHERING_ERROR:
+                    case CMD_SET_DNS_FORWARDERS_ERROR:
+                        setLastErrorAndTransitionToInitialState(
+                                ConnectivityManager.TETHER_ERROR_MASTER_ERROR);
+                        break;
+                    case CMD_INTERFACE_DOWN:
+                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
+                                TetherInterfaceSM.this);
+                        transitionTo(mUnavailableState);
+                        break;
+                    default:
+                        retValue = false;
+                }
+                return retValue;
+            }
+        }
+
+        class TetheredState extends State {
+            @Override
+            public void enter() {
+                try {
+                    mNMService.tetherInterface(mIfaceName);
+                } catch (Exception e) {
+                    Log.e(TAG, "Error Tethering: " + e.toString());
+                    setLastError(ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR);
+
+                    transitionTo(mInitialState);
+                    return;
+                }
+                if (DBG) Log.d(TAG, "Tethered " + mIfaceName);
+                setAvailable(false);
+                setTethered(true);
+                sendTetherStateChangedBroadcast();
+            }
+
+            private void cleanupUpstream() {
+                if (mMyUpstreamIfaceName != null) {
+                    // note that we don't care about errors here.
+                    // sometimes interfaces are gone before we get
+                    // to remove their rules, which generates errors.
+                    // just do the best we can.
+                    try {
+                        // about to tear down NAT; gather remaining statistics
+                        mStatsService.forceUpdate();
+                    } catch (Exception e) {
+                        if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString());
+                    }
+                    try {
+                        mNMService.disableNat(mIfaceName, mMyUpstreamIfaceName);
+                    } catch (Exception e) {
+                        if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString());
+                    }
+                    mMyUpstreamIfaceName = null;
+                }
+                return;
+            }
+
+            @Override
+            public boolean processMessage(Message message) {
+                if (DBG) Log.d(TAG, "TetheredState.processMessage what=" + message.what);
+                boolean retValue = true;
+                boolean error = false;
+                switch (message.what) {
+                    case CMD_TETHER_UNREQUESTED:
+                    case CMD_INTERFACE_DOWN:
+                        cleanupUpstream();
+                        try {
+                            mNMService.untetherInterface(mIfaceName);
+                        } catch (Exception e) {
+                            setLastErrorAndTransitionToInitialState(
+                                    ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR);
+                            break;
+                        }
+                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
+                                TetherInterfaceSM.this);
+                        if (message.what == CMD_TETHER_UNREQUESTED) {
+                            if (mUsb) {
+                                if (!Tethering.this.configureUsbIface(false)) {
+                                    setLastError(
+                                            ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
+                                }
+                            }
+                            transitionTo(mInitialState);
+                        } else if (message.what == CMD_INTERFACE_DOWN) {
+                            transitionTo(mUnavailableState);
+                        }
+                        if (DBG) Log.d(TAG, "Untethered " + mIfaceName);
+                        break;
+                    case CMD_TETHER_CONNECTION_CHANGED:
+                        String newUpstreamIfaceName = (String)(message.obj);
+                        if ((mMyUpstreamIfaceName == null && newUpstreamIfaceName == null) ||
+                                (mMyUpstreamIfaceName != null &&
+                                mMyUpstreamIfaceName.equals(newUpstreamIfaceName))) {
+                            if (VDBG) Log.d(TAG, "Connection changed noop - dropping");
+                            break;
+                        }
+                        cleanupUpstream();
+                        if (newUpstreamIfaceName != null) {
+                            try {
+                                mNMService.enableNat(mIfaceName, newUpstreamIfaceName);
+                            } catch (Exception e) {
+                                Log.e(TAG, "Exception enabling Nat: " + e.toString());
+                                try {
+                                    mNMService.untetherInterface(mIfaceName);
+                                } catch (Exception ee) {}
+
+                                setLastError(ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR);
+                                transitionTo(mInitialState);
+                                return true;
+                            }
+                        }
+                        mMyUpstreamIfaceName = newUpstreamIfaceName;
+                        break;
+                    case CMD_CELL_DUN_ERROR:
+                    case CMD_IP_FORWARDING_ENABLE_ERROR:
+                    case CMD_IP_FORWARDING_DISABLE_ERROR:
+                    case CMD_START_TETHERING_ERROR:
+                    case CMD_STOP_TETHERING_ERROR:
+                    case CMD_SET_DNS_FORWARDERS_ERROR:
+                        error = true;
+                        // fall through
+                    case CMD_TETHER_MODE_DEAD:
+                        cleanupUpstream();
+                        try {
+                            mNMService.untetherInterface(mIfaceName);
+                        } catch (Exception e) {
+                            setLastErrorAndTransitionToInitialState(
+                                    ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR);
+                            break;
+                        }
+                        if (error) {
+                            setLastErrorAndTransitionToInitialState(
+                                    ConnectivityManager.TETHER_ERROR_MASTER_ERROR);
+                            break;
+                        }
+                        if (DBG) Log.d(TAG, "Tether lost upstream connection " + mIfaceName);
+                        sendTetherStateChangedBroadcast();
+                        if (mUsb) {
+                            if (!Tethering.this.configureUsbIface(false)) {
+                                setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
+                            }
+                        }
+                        transitionTo(mInitialState);
+                        break;
+                    default:
+                        retValue = false;
+                        break;
+                }
+                return retValue;
+            }
+        }
+
+        class UnavailableState extends State {
+            @Override
+            public void enter() {
+                setAvailable(false);
+                setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
+                setTethered(false);
+                sendTetherStateChangedBroadcast();
+            }
+            @Override
+            public boolean processMessage(Message message) {
+                boolean retValue = true;
+                switch (message.what) {
+                    case CMD_INTERFACE_UP:
+                        transitionTo(mInitialState);
+                        break;
+                    default:
+                        retValue = false;
+                        break;
+                }
+                return retValue;
+            }
+        }
+
+        void setLastErrorAndTransitionToInitialState(int error) {
+            setLastError(error);
+            transitionTo(mInitialState);
+        }
+
+    }
+
+    class TetherMasterSM extends StateMachine {
+        // an interface SM has requested Tethering
+        static final int CMD_TETHER_MODE_REQUESTED   = 1;
+        // an interface SM has unrequested Tethering
+        static final int CMD_TETHER_MODE_UNREQUESTED = 2;
+        // upstream connection change - do the right thing
+        static final int CMD_UPSTREAM_CHANGED        = 3;
+        // we received notice that the cellular DUN connection is up
+        static final int CMD_CELL_CONNECTION_RENEW   = 4;
+        // we don't have a valid upstream conn, check again after a delay
+        static final int CMD_RETRY_UPSTREAM          = 5;
+
+        // This indicates what a timeout event relates to.  A state that
+        // sends itself a delayed timeout event and handles incoming timeout events
+        // should inc this when it is entered and whenever it sends a new timeout event.
+        // We do not flush the old ones.
+        private int mSequenceNumber;
+
+        private State mInitialState;
+        private State mTetherModeAliveState;
+
+        private State mSetIpForwardingEnabledErrorState;
+        private State mSetIpForwardingDisabledErrorState;
+        private State mStartTetheringErrorState;
+        private State mStopTetheringErrorState;
+        private State mSetDnsForwardersErrorState;
+
+        private ArrayList<TetherInterfaceSM> mNotifyList;
+
+        private int mCurrentConnectionSequence;
+        private int mMobileApnReserved = ConnectivityManager.TYPE_NONE;
+
+        private String mUpstreamIfaceName = null;
+
+        private static final int UPSTREAM_SETTLE_TIME_MS     = 10000;
+        private static final int CELL_CONNECTION_RENEW_MS    = 40000;
+
+        TetherMasterSM(String name, Looper looper) {
+            super(name, looper);
+
+            //Add states
+            mInitialState = new InitialState();
+            addState(mInitialState);
+            mTetherModeAliveState = new TetherModeAliveState();
+            addState(mTetherModeAliveState);
+
+            mSetIpForwardingEnabledErrorState = new SetIpForwardingEnabledErrorState();
+            addState(mSetIpForwardingEnabledErrorState);
+            mSetIpForwardingDisabledErrorState = new SetIpForwardingDisabledErrorState();
+            addState(mSetIpForwardingDisabledErrorState);
+            mStartTetheringErrorState = new StartTetheringErrorState();
+            addState(mStartTetheringErrorState);
+            mStopTetheringErrorState = new StopTetheringErrorState();
+            addState(mStopTetheringErrorState);
+            mSetDnsForwardersErrorState = new SetDnsForwardersErrorState();
+            addState(mSetDnsForwardersErrorState);
+
+            mNotifyList = new ArrayList<TetherInterfaceSM>();
+            setInitialState(mInitialState);
+        }
+
+        class TetherMasterUtilState extends State {
+            protected final static boolean TRY_TO_SETUP_MOBILE_CONNECTION = true;
+            protected final static boolean WAIT_FOR_NETWORK_TO_SETTLE     = false;
+
+            @Override
+            public boolean processMessage(Message m) {
+                return false;
+            }
+            protected String enableString(int apnType) {
+                switch (apnType) {
+                case ConnectivityManager.TYPE_MOBILE_DUN:
+                    return Phone.FEATURE_ENABLE_DUN_ALWAYS;
+                case ConnectivityManager.TYPE_MOBILE:
+                case ConnectivityManager.TYPE_MOBILE_HIPRI:
+                    return Phone.FEATURE_ENABLE_HIPRI;
+                }
+                return null;
+            }
+            protected boolean turnOnUpstreamMobileConnection(int apnType) {
+                boolean retValue = true;
+                if (apnType == ConnectivityManager.TYPE_NONE) return false;
+                if (apnType != mMobileApnReserved) turnOffUpstreamMobileConnection();
+                int result = PhoneConstants.APN_REQUEST_FAILED;
+                String enableString = enableString(apnType);
+                if (enableString == null) return false;
+                try {
+                    result = mConnService.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+                            enableString, new Binder());
+                } catch (Exception e) {
+                }
+                switch (result) {
+                case PhoneConstants.APN_ALREADY_ACTIVE:
+                case PhoneConstants.APN_REQUEST_STARTED:
+                    mMobileApnReserved = apnType;
+                    Message m = obtainMessage(CMD_CELL_CONNECTION_RENEW);
+                    m.arg1 = ++mCurrentConnectionSequence;
+                    sendMessageDelayed(m, CELL_CONNECTION_RENEW_MS);
+                    break;
+                case PhoneConstants.APN_REQUEST_FAILED:
+                default:
+                    retValue = false;
+                    break;
+                }
+
+                return retValue;
+            }
+            protected boolean turnOffUpstreamMobileConnection() {
+                // ignore pending renewal requests
+                ++mCurrentConnectionSequence;
+                if (mMobileApnReserved != ConnectivityManager.TYPE_NONE) {
+                    try {
+                        mConnService.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
+                                enableString(mMobileApnReserved));
+                    } catch (Exception e) {
+                        return false;
+                    }
+                    mMobileApnReserved = ConnectivityManager.TYPE_NONE;
+                }
+                return true;
+            }
+            protected boolean turnOnMasterTetherSettings() {
+                try {
+                    mNMService.setIpForwardingEnabled(true);
+                } catch (Exception e) {
+                    transitionTo(mSetIpForwardingEnabledErrorState);
+                    return false;
+                }
+                try {
+                    mNMService.startTethering(mDhcpRange);
+                } catch (Exception e) {
+                    try {
+                        mNMService.stopTethering();
+                        mNMService.startTethering(mDhcpRange);
+                    } catch (Exception ee) {
+                        transitionTo(mStartTetheringErrorState);
+                        return false;
+                    }
+                }
+                try {
+                    mNMService.setDnsForwarders(mDefaultDnsServers);
+                } catch (Exception e) {
+                    transitionTo(mSetDnsForwardersErrorState);
+                    return false;
+                }
+                return true;
+            }
+            protected boolean turnOffMasterTetherSettings() {
+                try {
+                    mNMService.stopTethering();
+                } catch (Exception e) {
+                    transitionTo(mStopTetheringErrorState);
+                    return false;
+                }
+                try {
+                    mNMService.setIpForwardingEnabled(false);
+                } catch (Exception e) {
+                    transitionTo(mSetIpForwardingDisabledErrorState);
+                    return false;
+                }
+                transitionTo(mInitialState);
+                return true;
+            }
+
+            protected void chooseUpstreamType(boolean tryCell) {
+                int upType = ConnectivityManager.TYPE_NONE;
+                String iface = null;
+
+                updateConfiguration(); // TODO - remove?
+
+                synchronized (mPublicSync) {
+                    if (VDBG) {
+                        Log.d(TAG, "chooseUpstreamType has upstream iface types:");
+                        for (Integer netType : mUpstreamIfaceTypes) {
+                            Log.d(TAG, " " + netType);
+                        }
+                    }
+
+                    for (Integer netType : mUpstreamIfaceTypes) {
+                        NetworkInfo info = null;
+                        try {
+                            info = mConnService.getNetworkInfo(netType.intValue());
+                        } catch (RemoteException e) { }
+                        if ((info != null) && info.isConnected()) {
+                            upType = netType.intValue();
+                            break;
+                        }
+                    }
+                }
+
+                if (DBG) {
+                    Log.d(TAG, "chooseUpstreamType(" + tryCell + "), preferredApn ="
+                            + mPreferredUpstreamMobileApn + ", got type=" + upType);
+                }
+
+                // if we're on DUN, put our own grab on it
+                if (upType == ConnectivityManager.TYPE_MOBILE_DUN ||
+                        upType == ConnectivityManager.TYPE_MOBILE_HIPRI) {
+                    turnOnUpstreamMobileConnection(upType);
+                } else if (upType != ConnectivityManager.TYPE_NONE) {
+                    /* If we've found an active upstream connection that's not DUN/HIPRI
+                     * we should stop any outstanding DUN/HIPRI start requests.
+                     *
+                     * If we found NONE we don't want to do this as we want any previous
+                     * requests to keep trying to bring up something we can use.
+                     */
+                    turnOffUpstreamMobileConnection();
+                }
+
+                if (upType == ConnectivityManager.TYPE_NONE) {
+                    boolean tryAgainLater = true;
+                    if ((tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) &&
+                            (turnOnUpstreamMobileConnection(mPreferredUpstreamMobileApn) == true)) {
+                        // we think mobile should be coming up - don't set a retry
+                        tryAgainLater = false;
+                    }
+                    if (tryAgainLater) {
+                        sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
+                    }
+                } else {
+                    LinkProperties linkProperties = null;
+                    try {
+                        linkProperties = mConnService.getLinkProperties(upType);
+                    } catch (RemoteException e) { }
+                    if (linkProperties != null) {
+                        // Find the interface with the default IPv4 route. It may be the
+                        // interface described by linkProperties, or one of the interfaces
+                        // stacked on top of it.
+                        Log.i(TAG, "Finding IPv4 upstream interface on: " + linkProperties);
+                        RouteInfo ipv4Default = RouteInfo.selectBestRoute(
+                            linkProperties.getAllRoutes(), Inet4Address.ANY);
+                        if (ipv4Default != null) {
+                            iface = ipv4Default.getInterface();
+                            Log.i(TAG, "Found interface " + ipv4Default.getInterface());
+                        } else {
+                            Log.i(TAG, "No IPv4 upstream interface, giving up.");
+                        }
+                    }
+
+                    if (iface != null) {
+                        String[] dnsServers = mDefaultDnsServers;
+                        Collection<InetAddress> dnses = linkProperties.getDnses();
+                        if (dnses != null) {
+                            // we currently only handle IPv4
+                            ArrayList<InetAddress> v4Dnses =
+                                    new ArrayList<InetAddress>(dnses.size());
+                            for (InetAddress dnsAddress : dnses) {
+                                if (dnsAddress instanceof Inet4Address) {
+                                    v4Dnses.add(dnsAddress);
+                                }
+                            }
+                            if (v4Dnses.size() > 0) {
+                                dnsServers = NetworkUtils.makeStrings(v4Dnses);
+                            }
+                        }
+                        try {
+                            mNMService.setDnsForwarders(dnsServers);
+                        } catch (Exception e) {
+                            transitionTo(mSetDnsForwardersErrorState);
+                        }
+                    }
+                }
+                notifyTetheredOfNewUpstreamIface(iface);
+            }
+
+            protected void notifyTetheredOfNewUpstreamIface(String ifaceName) {
+                if (DBG) Log.d(TAG, "notifying tethered with iface =" + ifaceName);
+                mUpstreamIfaceName = ifaceName;
+                for (TetherInterfaceSM sm : mNotifyList) {
+                    sm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED,
+                            ifaceName);
+                }
+            }
+        }
+
+        class InitialState extends TetherMasterUtilState {
+            @Override
+            public void enter() {
+            }
+            @Override
+            public boolean processMessage(Message message) {
+                if (DBG) Log.d(TAG, "MasterInitialState.processMessage what=" + message.what);
+                boolean retValue = true;
+                switch (message.what) {
+                    case CMD_TETHER_MODE_REQUESTED:
+                        TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
+                        if (VDBG) Log.d(TAG, "Tether Mode requested by " + who);
+                        mNotifyList.add(who);
+                        transitionTo(mTetherModeAliveState);
+                        break;
+                    case CMD_TETHER_MODE_UNREQUESTED:
+                        who = (TetherInterfaceSM)message.obj;
+                        if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who);
+                        int index = mNotifyList.indexOf(who);
+                        if (index != -1) {
+                            mNotifyList.remove(who);
+                        }
+                        break;
+                    default:
+                        retValue = false;
+                        break;
+                }
+                return retValue;
+            }
+        }
+
+        class TetherModeAliveState extends TetherMasterUtilState {
+            boolean mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE;
+            @Override
+            public void enter() {
+                turnOnMasterTetherSettings(); // may transition us out
+
+                mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE; // better try something first pass
+                                                        // or crazy tests cases will fail
+                chooseUpstreamType(mTryCell);
+                mTryCell = !mTryCell;
+            }
+            @Override
+            public void exit() {
+                turnOffUpstreamMobileConnection();
+                notifyTetheredOfNewUpstreamIface(null);
+            }
+            @Override
+            public boolean processMessage(Message message) {
+                if (DBG) Log.d(TAG, "TetherModeAliveState.processMessage what=" + message.what);
+                boolean retValue = true;
+                switch (message.what) {
+                    case CMD_TETHER_MODE_REQUESTED:
+                        TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
+                        if (VDBG) Log.d(TAG, "Tether Mode requested by " + who);
+                        mNotifyList.add(who);
+                        who.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED,
+                                mUpstreamIfaceName);
+                        break;
+                    case CMD_TETHER_MODE_UNREQUESTED:
+                        who = (TetherInterfaceSM)message.obj;
+                        if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who);
+                        int index = mNotifyList.indexOf(who);
+                        if (index != -1) {
+                            if (DBG) Log.d(TAG, "TetherModeAlive removing notifyee " + who);
+                            mNotifyList.remove(index);
+                            if (mNotifyList.isEmpty()) {
+                                turnOffMasterTetherSettings(); // transitions appropriately
+                            } else {
+                                if (DBG) {
+                                    Log.d(TAG, "TetherModeAlive still has " + mNotifyList.size() +
+                                            " live requests:");
+                                    for (Object o : mNotifyList) Log.d(TAG, "  " + o);
+                                }
+                            }
+                        } else {
+                           Log.e(TAG, "TetherModeAliveState UNREQUESTED has unknown who: " + who);
+                        }
+                        break;
+                    case CMD_UPSTREAM_CHANGED:
+                        // need to try DUN immediately if Wifi goes down
+                        mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE;
+                        chooseUpstreamType(mTryCell);
+                        mTryCell = !mTryCell;
+                        break;
+                    case CMD_CELL_CONNECTION_RENEW:
+                        // make sure we're still using a requested connection - may have found
+                        // wifi or something since then.
+                        if (mCurrentConnectionSequence == message.arg1) {
+                            if (VDBG) {
+                                Log.d(TAG, "renewing mobile connection - requeuing for another " +
+                                        CELL_CONNECTION_RENEW_MS + "ms");
+                            }
+                            turnOnUpstreamMobileConnection(mMobileApnReserved);
+                        }
+                        break;
+                    case CMD_RETRY_UPSTREAM:
+                        chooseUpstreamType(mTryCell);
+                        mTryCell = !mTryCell;
+                        break;
+                    default:
+                        retValue = false;
+                        break;
+                }
+                return retValue;
+            }
+        }
+
+        class ErrorState extends State {
+            int mErrorNotification;
+            @Override
+            public boolean processMessage(Message message) {
+                boolean retValue = true;
+                switch (message.what) {
+                    case CMD_TETHER_MODE_REQUESTED:
+                        TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
+                        who.sendMessage(mErrorNotification);
+                        break;
+                    default:
+                       retValue = false;
+                }
+                return retValue;
+            }
+            void notify(int msgType) {
+                mErrorNotification = msgType;
+                for (Object o : mNotifyList) {
+                    TetherInterfaceSM sm = (TetherInterfaceSM)o;
+                    sm.sendMessage(msgType);
+                }
+            }
+
+        }
+        class SetIpForwardingEnabledErrorState extends ErrorState {
+            @Override
+            public void enter() {
+                Log.e(TAG, "Error in setIpForwardingEnabled");
+                notify(TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR);
+            }
+        }
+
+        class SetIpForwardingDisabledErrorState extends ErrorState {
+            @Override
+            public void enter() {
+                Log.e(TAG, "Error in setIpForwardingDisabled");
+                notify(TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR);
+            }
+        }
+
+        class StartTetheringErrorState extends ErrorState {
+            @Override
+            public void enter() {
+                Log.e(TAG, "Error in startTethering");
+                notify(TetherInterfaceSM.CMD_START_TETHERING_ERROR);
+                try {
+                    mNMService.setIpForwardingEnabled(false);
+                } catch (Exception e) {}
+            }
+        }
+
+        class StopTetheringErrorState extends ErrorState {
+            @Override
+            public void enter() {
+                Log.e(TAG, "Error in stopTethering");
+                notify(TetherInterfaceSM.CMD_STOP_TETHERING_ERROR);
+                try {
+                    mNMService.setIpForwardingEnabled(false);
+                } catch (Exception e) {}
+            }
+        }
+
+        class SetDnsForwardersErrorState extends ErrorState {
+            @Override
+            public void enter() {
+                Log.e(TAG, "Error in setDnsForwarders");
+                notify(TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR);
+                try {
+                    mNMService.stopTethering();
+                } catch (Exception e) {}
+                try {
+                    mNMService.setIpForwardingEnabled(false);
+                } catch (Exception e) {}
+            }
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump ConnectivityService.Tether " +
+                    "from from pid=" + Binder.getCallingPid() + ", uid=" +
+                    Binder.getCallingUid());
+                    return;
+        }
+
+        synchronized (mPublicSync) {
+            pw.println("mUpstreamIfaceTypes: ");
+            for (Integer netType : mUpstreamIfaceTypes) {
+                pw.println(" " + netType);
+            }
+
+            pw.println();
+            pw.println("Tether state:");
+            for (Object o : mIfaces.values()) {
+                pw.println(" " + o);
+            }
+        }
+        pw.println();
+        return;
+    }
+}
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
new file mode 100644
index 0000000..0a58552
--- /dev/null
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -0,0 +1,1215 @@
+/*
+ * 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.server.connectivity;
+
+import static android.Manifest.permission.BIND_VPN_SERVICE;
+
+import android.app.AppGlobals;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+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.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.UserInfo;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.net.BaseNetworkStateTracker;
+import android.net.ConnectivityManager;
+import android.net.IConnectivityManager;
+import android.net.INetworkManagementEventObserver;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.net.LocalSocket;
+import android.net.LocalSocketAddress;
+import android.net.NetworkInfo;
+import android.net.NetworkUtils;
+import android.net.RouteInfo;
+import android.net.NetworkInfo.DetailedState;
+import android.os.Binder;
+import android.os.FileUtils;
+import android.os.IBinder;
+import android.os.INetworkManagementService;
+import android.os.Parcel;
+import android.os.ParcelFileDescriptor;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.SystemService;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.security.Credentials;
+import android.security.KeyStore;
+import android.util.Log;
+import android.util.SparseBooleanArray;
+import android.widget.Toast;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.R;
+import com.android.internal.net.LegacyVpnInfo;
+import com.android.internal.net.VpnConfig;
+import com.android.internal.net.VpnProfile;
+import com.android.internal.util.Preconditions;
+import com.android.server.ConnectivityService.VpnCallback;
+import com.android.server.net.BaseNetworkObserver;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import libcore.io.IoUtils;
+
+/**
+ * @hide
+ */
+public class Vpn extends BaseNetworkStateTracker {
+    private static final String TAG = "Vpn";
+    private static final boolean LOGD = true;
+    
+    // TODO: create separate trackers for each unique VPN to support
+    // automated reconnection
+
+    private final VpnCallback mCallback;
+
+    private String mPackage = VpnConfig.LEGACY_VPN;
+    private String mInterface;
+    private Connection mConnection;
+    private LegacyVpnRunner mLegacyVpnRunner;
+    private PendingIntent mStatusIntent;
+    private volatile boolean mEnableNotif = true;
+    private volatile boolean mEnableTeardown = true;
+    private final IConnectivityManager mConnService;
+    private VpnConfig mConfig;
+
+    /* list of users using this VPN. */
+    @GuardedBy("this")
+    private SparseBooleanArray mVpnUsers = null;
+    private BroadcastReceiver mUserIntentReceiver = null;
+
+    private final int mUserId;
+
+    public Vpn(Context context, VpnCallback callback, INetworkManagementService netService,
+            IConnectivityManager connService, int userId) {
+        // TODO: create dedicated TYPE_VPN network type
+        super(ConnectivityManager.TYPE_DUMMY);
+        mContext = context;
+        mCallback = callback;
+        mConnService = connService;
+        mUserId = userId;
+
+        try {
+            netService.registerObserver(mObserver);
+        } catch (RemoteException e) {
+            Log.wtf(TAG, "Problem registering observer", e);
+        }
+        if (userId == UserHandle.USER_OWNER) {
+            // Owner's VPN also needs to handle restricted users
+            mUserIntentReceiver = new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    final String action = intent.getAction();
+                    final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+                            UserHandle.USER_NULL);
+                    if (userId == UserHandle.USER_NULL) return;
+
+                    if (Intent.ACTION_USER_ADDED.equals(action)) {
+                        onUserAdded(userId);
+                    } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
+                        onUserRemoved(userId);
+                    }
+                }
+            };
+
+            IntentFilter intentFilter = new IntentFilter();
+            intentFilter.addAction(Intent.ACTION_USER_ADDED);
+            intentFilter.addAction(Intent.ACTION_USER_REMOVED);
+            mContext.registerReceiverAsUser(
+                    mUserIntentReceiver, UserHandle.ALL, intentFilter, null, null);
+        }
+    }
+
+    /**
+     * Set if this object is responsible for showing its own notifications. When
+     * {@code false}, notifications are handled externally by someone else.
+     */
+    public void setEnableNotifications(boolean enableNotif) {
+        mEnableNotif = enableNotif;
+    }
+
+    /**
+     * Set if this object is responsible for watching for {@link NetworkInfo}
+     * teardown. When {@code false}, teardown is handled externally by someone
+     * else.
+     */
+    public void setEnableTeardown(boolean enableTeardown) {
+        mEnableTeardown = enableTeardown;
+    }
+
+    @Override
+    protected void startMonitoringInternal() {
+        // Ignored; events are sent through callbacks for now
+    }
+
+    @Override
+    public boolean teardown() {
+        // TODO: finish migration to unique tracker for each VPN
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean reconnect() {
+        // TODO: finish migration to unique tracker for each VPN
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getTcpBufferSizesPropName() {
+        return PROP_TCP_BUFFER_UNKNOWN;
+    }
+
+    /**
+     * Update current state, dispaching event to listeners.
+     */
+    private void updateState(DetailedState detailedState, String reason) {
+        if (LOGD) Log.d(TAG, "setting state=" + detailedState + ", reason=" + reason);
+        mNetworkInfo.setDetailedState(detailedState, reason, null);
+        mCallback.onStateChanged(new NetworkInfo(mNetworkInfo));
+    }
+
+    /**
+     * Prepare for a VPN application. This method is designed to solve
+     * race conditions. It first compares the current prepared package
+     * with {@code oldPackage}. If they are the same, the prepared
+     * package is revoked and replaced with {@code newPackage}. If
+     * {@code oldPackage} is {@code null}, the comparison is omitted.
+     * If {@code newPackage} is the same package or {@code null}, the
+     * revocation is omitted. This method returns {@code true} if the
+     * operation is succeeded.
+     *
+     * Legacy VPN is handled specially since it is not a real package.
+     * It uses {@link VpnConfig#LEGACY_VPN} as its package name, and
+     * it can be revoked by itself.
+     *
+     * @param oldPackage The package name of the old VPN application.
+     * @param newPackage The package name of the new VPN application.
+     * @return true if the operation is succeeded.
+     */
+    public synchronized boolean prepare(String oldPackage, String newPackage) {
+        // Return false if the package does not match.
+        if (oldPackage != null && !oldPackage.equals(mPackage)) {
+            return false;
+        }
+
+        // Return true if we do not need to revoke.
+        if (newPackage == null ||
+                (newPackage.equals(mPackage) && !newPackage.equals(VpnConfig.LEGACY_VPN))) {
+            return true;
+        }
+
+        // Check if the caller is authorized.
+        enforceControlPermission();
+
+        // Reset the interface and hide the notification.
+        if (mInterface != null) {
+            final long token = Binder.clearCallingIdentity();
+            try {
+                mCallback.restore();
+                final int size = mVpnUsers.size();
+                final boolean forwardDns = (mConfig.dnsServers != null &&
+                        mConfig.dnsServers.size() != 0);
+                for (int i = 0; i < size; i++) {
+                    int user = mVpnUsers.keyAt(i);
+                    mCallback.clearUserForwarding(mInterface, user, forwardDns);
+                    hideNotification(user);
+                }
+
+                mCallback.clearMarkedForwarding(mInterface);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+            jniReset(mInterface);
+            mInterface = null;
+            mVpnUsers = null;
+        }
+
+        // Revoke the connection or stop LegacyVpnRunner.
+        if (mConnection != null) {
+            try {
+                mConnection.mService.transact(IBinder.LAST_CALL_TRANSACTION,
+                        Parcel.obtain(), null, IBinder.FLAG_ONEWAY);
+            } catch (Exception e) {
+                // ignore
+            }
+            mContext.unbindService(mConnection);
+            mConnection = null;
+        } else if (mLegacyVpnRunner != null) {
+            mLegacyVpnRunner.exit();
+            mLegacyVpnRunner = null;
+        }
+
+        Log.i(TAG, "Switched from " + mPackage + " to " + newPackage);
+        mPackage = newPackage;
+        mConfig = null;
+        updateState(DetailedState.IDLE, "prepare");
+        return true;
+    }
+
+    /**
+     * Protect a socket from VPN rules by binding it to the main routing table.
+     * The socket is NOT closed by this method.
+     *
+     * @param socket The socket to be bound.
+     */
+    public void protect(ParcelFileDescriptor socket) throws Exception {
+
+        PackageManager pm = mContext.getPackageManager();
+        int appUid = pm.getPackageUid(mPackage, mUserId);
+        if (Binder.getCallingUid() != appUid) {
+            throw new SecurityException("Unauthorized Caller");
+        }
+        // protect the socket from routing rules
+        final long token = Binder.clearCallingIdentity();
+        try {
+            mCallback.protect(socket);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+
+    }
+
+    /**
+     * Establish a VPN network and return the file descriptor of the VPN
+     * interface. This methods returns {@code null} if the application is
+     * revoked or not prepared.
+     *
+     * @param config The parameters to configure the network.
+     * @return The file descriptor of the VPN interface.
+     */
+    public synchronized ParcelFileDescriptor establish(VpnConfig config) {
+        // Check if the caller is already prepared.
+        UserManager mgr = UserManager.get(mContext);
+        PackageManager pm = mContext.getPackageManager();
+        ApplicationInfo app = null;
+        try {
+            app = AppGlobals.getPackageManager().getApplicationInfo(mPackage, 0, mUserId);
+            if (Binder.getCallingUid() != app.uid) {
+                return null;
+            }
+        } catch (Exception e) {
+            return null;
+        }
+        // Check if the service is properly declared.
+        Intent intent = new Intent(VpnConfig.SERVICE_INTERFACE);
+        intent.setClassName(mPackage, config.user);
+        long token = Binder.clearCallingIdentity();
+        try {
+            // Restricted users are not allowed to create VPNs, they are tied to Owner
+            UserInfo user = mgr.getUserInfo(mUserId);
+            if (user.isRestricted()) {
+                throw new SecurityException("Restricted users cannot establish VPNs");
+            }
+
+            ResolveInfo info = AppGlobals.getPackageManager().resolveService(intent,
+                                                                        null, 0, mUserId);
+            if (info == null) {
+                throw new SecurityException("Cannot find " + config.user);
+            }
+            if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
+                throw new SecurityException(config.user + " does not require " + BIND_VPN_SERVICE);
+            }
+        } catch (RemoteException e) {
+                throw new SecurityException("Cannot find " + config.user);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+
+        // Configure the interface. Abort if any of these steps fails.
+        ParcelFileDescriptor tun = ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
+        try {
+            updateState(DetailedState.CONNECTING, "establish");
+            String interfaze = jniGetName(tun.getFd());
+
+            // TEMP use the old jni calls until there is support for netd address setting
+            StringBuilder builder = new StringBuilder();
+            for (LinkAddress address : config.addresses) {
+                builder.append(" " + address);
+            }
+            if (jniSetAddresses(interfaze, builder.toString()) < 1) {
+                throw new IllegalArgumentException("At least one address must be specified");
+            }
+            Connection connection = new Connection();
+            if (!mContext.bindServiceAsUser(intent, connection, Context.BIND_AUTO_CREATE,
+                        new UserHandle(mUserId))) {
+                throw new IllegalStateException("Cannot bind " + config.user);
+            }
+            if (mConnection != null) {
+                mContext.unbindService(mConnection);
+            }
+            if (mInterface != null && !mInterface.equals(interfaze)) {
+                jniReset(mInterface);
+            }
+            mConnection = connection;
+            mInterface = interfaze;
+
+            // Fill more values.
+            config.user = mPackage;
+            config.interfaze = mInterface;
+            config.startTime = SystemClock.elapsedRealtime();
+            mConfig = config;
+            // Set up forwarding and DNS rules.
+            mVpnUsers = new SparseBooleanArray();
+            token = Binder.clearCallingIdentity();
+            try {
+                mCallback.setMarkedForwarding(mInterface);
+                mCallback.setRoutes(interfaze, config.routes);
+                mCallback.override(mInterface, config.dnsServers, config.searchDomains);
+                addVpnUserLocked(mUserId);
+
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+
+        } catch (RuntimeException e) {
+            updateState(DetailedState.FAILED, "establish");
+            IoUtils.closeQuietly(tun);
+            // make sure marked forwarding is cleared if it was set
+            try {
+                mCallback.clearMarkedForwarding(mInterface);
+            } catch (Exception ingored) {
+                // ignored
+            }
+            throw e;
+        }
+        Log.i(TAG, "Established by " + config.user + " on " + mInterface);
+
+
+        // If we are owner assign all Restricted Users to this VPN
+        if (mUserId == UserHandle.USER_OWNER) {
+            token = Binder.clearCallingIdentity();
+            try {
+                for (UserInfo user : mgr.getUsers()) {
+                    if (user.isRestricted()) {
+                        try {
+                            addVpnUserLocked(user.id);
+                        } catch (Exception e) {
+                            Log.wtf(TAG, "Failed to add user " + user.id + " to owner's VPN");
+                        }
+                    }
+                }
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+        // TODO: ensure that contract class eventually marks as connected
+        updateState(DetailedState.AUTHENTICATING, "establish");
+        return tun;
+    }
+
+    /**
+     * Check if a given address is covered by the VPN's routing rules.
+     */
+    public boolean isAddressCovered(InetAddress address) {
+        synchronized (Vpn.this) {
+            if (!isRunningLocked()) {
+                return false;
+            }
+            return RouteInfo.selectBestRoute(mConfig.routes, address) != null;
+        }
+    }
+
+    private boolean isRunningLocked() {
+        return mVpnUsers != null;
+    }
+
+    private void addVpnUserLocked(int user) {
+        enforceControlPermission();
+
+        if (!isRunningLocked()) {
+            throw new IllegalStateException("VPN is not active");
+        }
+
+        final boolean forwardDns = (mConfig.dnsServers != null &&
+                mConfig.dnsServers.size() != 0);
+
+        // add the user
+        mCallback.addUserForwarding(mInterface, user, forwardDns);
+        mVpnUsers.put(user, true);
+
+        // show the notification
+        if (!mPackage.equals(VpnConfig.LEGACY_VPN)) {
+            // Load everything for the user's notification
+            PackageManager pm = mContext.getPackageManager();
+            ApplicationInfo app = null;
+            try {
+                app = AppGlobals.getPackageManager().getApplicationInfo(mPackage, 0, mUserId);
+            } catch (RemoteException e) {
+                throw new IllegalStateException("Invalid application");
+            }
+            String label = app.loadLabel(pm).toString();
+            // Load the icon and convert it into a bitmap.
+            Drawable icon = app.loadIcon(pm);
+            Bitmap bitmap = null;
+            if (icon.getIntrinsicWidth() > 0 && icon.getIntrinsicHeight() > 0) {
+                int width = mContext.getResources().getDimensionPixelSize(
+                        android.R.dimen.notification_large_icon_width);
+                int height = mContext.getResources().getDimensionPixelSize(
+                        android.R.dimen.notification_large_icon_height);
+                icon.setBounds(0, 0, width, height);
+                bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+                Canvas c = new Canvas(bitmap);
+                icon.draw(c);
+                c.setBitmap(null);
+            }
+            showNotification(label, bitmap, user);
+        } else {
+            showNotification(null, null, user);
+        }
+    }
+
+    private void removeVpnUserLocked(int user) {
+            enforceControlPermission();
+
+            if (!isRunningLocked()) {
+                throw new IllegalStateException("VPN is not active");
+            }
+            final boolean forwardDns = (mConfig.dnsServers != null &&
+                    mConfig.dnsServers.size() != 0);
+            mCallback.clearUserForwarding(mInterface, user, forwardDns);
+            mVpnUsers.delete(user);
+            hideNotification(user);
+    }
+
+    private void onUserAdded(int userId) {
+        // If the user is restricted tie them to the owner's VPN
+        synchronized(Vpn.this) {
+            UserManager mgr = UserManager.get(mContext);
+            UserInfo user = mgr.getUserInfo(userId);
+            if (user.isRestricted()) {
+                try {
+                    addVpnUserLocked(userId);
+                } catch (Exception e) {
+                    Log.wtf(TAG, "Failed to add restricted user to owner", e);
+                }
+            }
+        }
+    }
+
+    private void onUserRemoved(int userId) {
+        // clean up if restricted
+        synchronized(Vpn.this) {
+            UserManager mgr = UserManager.get(mContext);
+            UserInfo user = mgr.getUserInfo(userId);
+            if (user.isRestricted()) {
+                try {
+                    removeVpnUserLocked(userId);
+                } catch (Exception e) {
+                    Log.wtf(TAG, "Failed to remove restricted user to owner", e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Return the configuration of the currently running VPN.
+     */
+    public VpnConfig getVpnConfig() {
+        enforceControlPermission();
+        return mConfig;
+    }
+
+    @Deprecated
+    public synchronized void interfaceStatusChanged(String iface, boolean up) {
+        try {
+            mObserver.interfaceStatusChanged(iface, up);
+        } catch (RemoteException e) {
+            // ignored; target is local
+        }
+    }
+
+    private INetworkManagementEventObserver mObserver = new BaseNetworkObserver() {
+        @Override
+        public void interfaceStatusChanged(String interfaze, boolean up) {
+            synchronized (Vpn.this) {
+                if (!up && mLegacyVpnRunner != null) {
+                    mLegacyVpnRunner.check(interfaze);
+                }
+            }
+        }
+
+        @Override
+        public void interfaceRemoved(String interfaze) {
+            synchronized (Vpn.this) {
+                if (interfaze.equals(mInterface) && jniCheck(interfaze) == 0) {
+                    final long token = Binder.clearCallingIdentity();
+                    try {
+                        final int size = mVpnUsers.size();
+                        final boolean forwardDns = (mConfig.dnsServers != null &&
+                                mConfig.dnsServers.size() != 0);
+                        for (int i = 0; i < size; i++) {
+                            int user = mVpnUsers.keyAt(i);
+                            mCallback.clearUserForwarding(mInterface, user, forwardDns);
+                            hideNotification(user);
+                        }
+                        mVpnUsers = null;
+                        mCallback.clearMarkedForwarding(mInterface);
+
+                        mCallback.restore();
+                    } finally {
+                        Binder.restoreCallingIdentity(token);
+                    }
+                    mInterface = null;
+                    if (mConnection != null) {
+                        mContext.unbindService(mConnection);
+                        mConnection = null;
+                        updateState(DetailedState.DISCONNECTED, "interfaceRemoved");
+                    } else if (mLegacyVpnRunner != null) {
+                        mLegacyVpnRunner.exit();
+                        mLegacyVpnRunner = null;
+                    }
+                }
+            }
+        }
+    };
+
+    private void enforceControlPermission() {
+        // System user is allowed to control VPN.
+        if (Binder.getCallingUid() == Process.SYSTEM_UID) {
+            return;
+        }
+        int appId = UserHandle.getAppId(Binder.getCallingUid());
+        final long token = Binder.clearCallingIdentity();
+        try {
+            // System VPN dialogs are also allowed to control VPN.
+            PackageManager pm = mContext.getPackageManager();
+            ApplicationInfo app = pm.getApplicationInfo(VpnConfig.DIALOGS_PACKAGE, 0);
+            if (((app.flags & ApplicationInfo.FLAG_SYSTEM) != 0) && (appId == app.uid)) {
+                return;
+            }
+        } catch (Exception e) {
+            // ignore
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+
+        throw new SecurityException("Unauthorized Caller");
+    }
+
+    private class Connection implements ServiceConnection {
+        private IBinder mService;
+
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            mService = service;
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+            mService = null;
+        }
+    }
+
+    private void showNotification(String label, Bitmap icon, int user) {
+        if (!mEnableNotif) return;
+        mStatusIntent = VpnConfig.getIntentForStatusPanel(mContext);
+
+        NotificationManager nm = (NotificationManager)
+                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        if (nm != null) {
+            String title = (label == null) ? mContext.getString(R.string.vpn_title) :
+                    mContext.getString(R.string.vpn_title_long, label);
+            String text = (mConfig.session == null) ? mContext.getString(R.string.vpn_text) :
+                    mContext.getString(R.string.vpn_text_long, mConfig.session);
+
+            Notification notification = new Notification.Builder(mContext)
+                    .setSmallIcon(R.drawable.vpn_connected)
+                    .setLargeIcon(icon)
+                    .setContentTitle(title)
+                    .setContentText(text)
+                    .setContentIntent(mStatusIntent)
+                    .setDefaults(0)
+                    .setOngoing(true)
+                    .build();
+            nm.notifyAsUser(null, R.drawable.vpn_connected, notification, new UserHandle(user));
+        }
+    }
+
+    private void hideNotification(int user) {
+        if (!mEnableNotif) return;
+        mStatusIntent = null;
+
+        NotificationManager nm = (NotificationManager)
+                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        if (nm != null) {
+            nm.cancelAsUser(null, R.drawable.vpn_connected, new UserHandle(user));
+        }
+    }
+
+    private native int jniCreate(int mtu);
+    private native String jniGetName(int tun);
+    private native int jniSetAddresses(String interfaze, String addresses);
+    private native int jniSetRoutes(String interfaze, String routes);
+    private native void jniReset(String interfaze);
+    private native int jniCheck(String interfaze);
+
+    private static RouteInfo findIPv4DefaultRoute(LinkProperties prop) {
+        for (RouteInfo route : prop.getAllRoutes()) {
+            // Currently legacy VPN only works on IPv4.
+            if (route.isDefaultRoute() && route.getGateway() instanceof Inet4Address) {
+                return route;
+            }
+        }
+
+        throw new IllegalStateException("Unable to find IPv4 default gateway");
+    }
+
+    /**
+     * Start legacy VPN, controlling native daemons as needed. Creates a
+     * secondary thread to perform connection work, returning quickly.
+     */
+    public void startLegacyVpn(VpnProfile profile, KeyStore keyStore, LinkProperties egress) {
+        enforceControlPermission();
+        if (!keyStore.isUnlocked()) {
+            throw new IllegalStateException("KeyStore isn't unlocked");
+        }
+
+        final RouteInfo ipv4DefaultRoute = findIPv4DefaultRoute(egress);
+        final String gateway = ipv4DefaultRoute.getGateway().getHostAddress();
+        final String iface = ipv4DefaultRoute.getInterface();
+
+        // Load certificates.
+        String privateKey = "";
+        String userCert = "";
+        String caCert = "";
+        String serverCert = "";
+        if (!profile.ipsecUserCert.isEmpty()) {
+            privateKey = Credentials.USER_PRIVATE_KEY + profile.ipsecUserCert;
+            byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecUserCert);
+            userCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
+        }
+        if (!profile.ipsecCaCert.isEmpty()) {
+            byte[] value = keyStore.get(Credentials.CA_CERTIFICATE + profile.ipsecCaCert);
+            caCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
+        }
+        if (!profile.ipsecServerCert.isEmpty()) {
+            byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecServerCert);
+            serverCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
+        }
+        if (privateKey == null || userCert == null || caCert == null || serverCert == null) {
+            throw new IllegalStateException("Cannot load credentials");
+        }
+
+        // Prepare arguments for racoon.
+        String[] racoon = null;
+        switch (profile.type) {
+            case VpnProfile.TYPE_L2TP_IPSEC_PSK:
+                racoon = new String[] {
+                    iface, profile.server, "udppsk", profile.ipsecIdentifier,
+                    profile.ipsecSecret, "1701",
+                };
+                break;
+            case VpnProfile.TYPE_L2TP_IPSEC_RSA:
+                racoon = new String[] {
+                    iface, profile.server, "udprsa", privateKey, userCert,
+                    caCert, serverCert, "1701",
+                };
+                break;
+            case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
+                racoon = new String[] {
+                    iface, profile.server, "xauthpsk", profile.ipsecIdentifier,
+                    profile.ipsecSecret, profile.username, profile.password, "", gateway,
+                };
+                break;
+            case VpnProfile.TYPE_IPSEC_XAUTH_RSA:
+                racoon = new String[] {
+                    iface, profile.server, "xauthrsa", privateKey, userCert,
+                    caCert, serverCert, profile.username, profile.password, "", gateway,
+                };
+                break;
+            case VpnProfile.TYPE_IPSEC_HYBRID_RSA:
+                racoon = new String[] {
+                    iface, profile.server, "hybridrsa",
+                    caCert, serverCert, profile.username, profile.password, "", gateway,
+                };
+                break;
+        }
+
+        // Prepare arguments for mtpd.
+        String[] mtpd = null;
+        switch (profile.type) {
+            case VpnProfile.TYPE_PPTP:
+                mtpd = new String[] {
+                    iface, "pptp", profile.server, "1723",
+                    "name", profile.username, "password", profile.password,
+                    "linkname", "vpn", "refuse-eap", "nodefaultroute",
+                    "usepeerdns", "idle", "1800", "mtu", "1400", "mru", "1400",
+                    (profile.mppe ? "+mppe" : "nomppe"),
+                };
+                break;
+            case VpnProfile.TYPE_L2TP_IPSEC_PSK:
+            case VpnProfile.TYPE_L2TP_IPSEC_RSA:
+                mtpd = new String[] {
+                    iface, "l2tp", profile.server, "1701", profile.l2tpSecret,
+                    "name", profile.username, "password", profile.password,
+                    "linkname", "vpn", "refuse-eap", "nodefaultroute",
+                    "usepeerdns", "idle", "1800", "mtu", "1400", "mru", "1400",
+                };
+                break;
+        }
+
+        VpnConfig config = new VpnConfig();
+        config.legacy = true;
+        config.user = profile.key;
+        config.interfaze = iface;
+        config.session = profile.name;
+
+        config.addLegacyRoutes(profile.routes);
+        if (!profile.dnsServers.isEmpty()) {
+            config.dnsServers = Arrays.asList(profile.dnsServers.split(" +"));
+        }
+        if (!profile.searchDomains.isEmpty()) {
+            config.searchDomains = Arrays.asList(profile.searchDomains.split(" +"));
+        }
+        startLegacyVpn(config, racoon, mtpd);
+    }
+
+    private synchronized void startLegacyVpn(VpnConfig config, String[] racoon, String[] mtpd) {
+        stopLegacyVpn();
+
+        // Prepare for the new request. This also checks the caller.
+        prepare(null, VpnConfig.LEGACY_VPN);
+        updateState(DetailedState.CONNECTING, "startLegacyVpn");
+
+        // Start a new LegacyVpnRunner and we are done!
+        mLegacyVpnRunner = new LegacyVpnRunner(config, racoon, mtpd);
+        mLegacyVpnRunner.start();
+    }
+
+    public synchronized void stopLegacyVpn() {
+        if (mLegacyVpnRunner != null) {
+            mLegacyVpnRunner.exit();
+            mLegacyVpnRunner = null;
+
+            synchronized (LegacyVpnRunner.TAG) {
+                // wait for old thread to completely finish before spinning up
+                // new instance, otherwise state updates can be out of order.
+            }
+        }
+    }
+
+    /**
+     * Return the information of the current ongoing legacy VPN.
+     */
+    public synchronized LegacyVpnInfo getLegacyVpnInfo() {
+        // Check if the caller is authorized.
+        enforceControlPermission();
+        if (mLegacyVpnRunner == null) return null;
+
+        final LegacyVpnInfo info = new LegacyVpnInfo();
+        info.key = mConfig.user;
+        info.state = LegacyVpnInfo.stateFromNetworkInfo(mNetworkInfo);
+        if (mNetworkInfo.isConnected()) {
+            info.intent = mStatusIntent;
+        }
+        return info;
+    }
+
+    public VpnConfig getLegacyVpnConfig() {
+        if (mLegacyVpnRunner != null) {
+            return mConfig;
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Bringing up a VPN connection takes time, and that is all this thread
+     * does. Here we have plenty of time. The only thing we need to take
+     * care of is responding to interruptions as soon as possible. Otherwise
+     * requests will be piled up. This can be done in a Handler as a state
+     * machine, but it is much easier to read in the current form.
+     */
+    private class LegacyVpnRunner extends Thread {
+        private static final String TAG = "LegacyVpnRunner";
+
+        private final String[] mDaemons;
+        private final String[][] mArguments;
+        private final LocalSocket[] mSockets;
+        private final String mOuterInterface;
+        private final AtomicInteger mOuterConnection =
+                new AtomicInteger(ConnectivityManager.TYPE_NONE);
+
+        private long mTimer = -1;
+
+        /**
+         * Watch for the outer connection (passing in the constructor) going away.
+         */
+        private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                if (!mEnableTeardown) return;
+
+                if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
+                    if (intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE,
+                            ConnectivityManager.TYPE_NONE) == mOuterConnection.get()) {
+                        NetworkInfo info = (NetworkInfo)intent.getExtra(
+                                ConnectivityManager.EXTRA_NETWORK_INFO);
+                        if (info != null && !info.isConnectedOrConnecting()) {
+                            try {
+                                mObserver.interfaceStatusChanged(mOuterInterface, false);
+                            } catch (RemoteException e) {}
+                        }
+                    }
+                }
+            }
+        };
+
+        public LegacyVpnRunner(VpnConfig config, String[] racoon, String[] mtpd) {
+            super(TAG);
+            mConfig = config;
+            mDaemons = new String[] {"racoon", "mtpd"};
+            // TODO: clear arguments from memory once launched
+            mArguments = new String[][] {racoon, mtpd};
+            mSockets = new LocalSocket[mDaemons.length];
+
+            // This is the interface which VPN is running on,
+            // mConfig.interfaze will change to point to OUR
+            // internal interface soon. TODO - add inner/outer to mconfig
+            // TODO - we have a race - if the outer iface goes away/disconnects before we hit this
+            // we will leave the VPN up.  We should check that it's still there/connected after
+            // registering
+            mOuterInterface = mConfig.interfaze;
+
+            try {
+                mOuterConnection.set(
+                        mConnService.findConnectionTypeForIface(mOuterInterface));
+            } catch (Exception e) {
+                mOuterConnection.set(ConnectivityManager.TYPE_NONE);
+            }
+
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+            mContext.registerReceiver(mBroadcastReceiver, filter);
+        }
+
+        public void check(String interfaze) {
+            if (interfaze.equals(mOuterInterface)) {
+                Log.i(TAG, "Legacy VPN is going down with " + interfaze);
+                exit();
+            }
+        }
+
+        public void exit() {
+            // We assume that everything is reset after stopping the daemons.
+            interrupt();
+            for (LocalSocket socket : mSockets) {
+                IoUtils.closeQuietly(socket);
+            }
+            updateState(DetailedState.DISCONNECTED, "exit");
+            try {
+                mContext.unregisterReceiver(mBroadcastReceiver);
+            } catch (IllegalArgumentException e) {}
+        }
+
+        @Override
+        public void run() {
+            // Wait for the previous thread since it has been interrupted.
+            Log.v(TAG, "Waiting");
+            synchronized (TAG) {
+                Log.v(TAG, "Executing");
+                execute();
+                monitorDaemons();
+            }
+        }
+
+        private void checkpoint(boolean yield) throws InterruptedException {
+            long now = SystemClock.elapsedRealtime();
+            if (mTimer == -1) {
+                mTimer = now;
+                Thread.sleep(1);
+            } else if (now - mTimer <= 60000) {
+                Thread.sleep(yield ? 200 : 1);
+            } else {
+                updateState(DetailedState.FAILED, "checkpoint");
+                throw new IllegalStateException("Time is up");
+            }
+        }
+
+        private void execute() {
+            // Catch all exceptions so we can clean up few things.
+            boolean initFinished = false;
+            try {
+                // Initialize the timer.
+                checkpoint(false);
+
+                // Wait for the daemons to stop.
+                for (String daemon : mDaemons) {
+                    while (!SystemService.isStopped(daemon)) {
+                        checkpoint(true);
+                    }
+                }
+
+                // Clear the previous state.
+                File state = new File("/data/misc/vpn/state");
+                state.delete();
+                if (state.exists()) {
+                    throw new IllegalStateException("Cannot delete the state");
+                }
+                new File("/data/misc/vpn/abort").delete();
+                initFinished = true;
+
+                // Check if we need to restart any of the daemons.
+                boolean restart = false;
+                for (String[] arguments : mArguments) {
+                    restart = restart || (arguments != null);
+                }
+                if (!restart) {
+                    updateState(DetailedState.DISCONNECTED, "execute");
+                    return;
+                }
+                updateState(DetailedState.CONNECTING, "execute");
+
+                // Start the daemon with arguments.
+                for (int i = 0; i < mDaemons.length; ++i) {
+                    String[] arguments = mArguments[i];
+                    if (arguments == null) {
+                        continue;
+                    }
+
+                    // Start the daemon.
+                    String daemon = mDaemons[i];
+                    SystemService.start(daemon);
+
+                    // Wait for the daemon to start.
+                    while (!SystemService.isRunning(daemon)) {
+                        checkpoint(true);
+                    }
+
+                    // Create the control socket.
+                    mSockets[i] = new LocalSocket();
+                    LocalSocketAddress address = new LocalSocketAddress(
+                            daemon, LocalSocketAddress.Namespace.RESERVED);
+
+                    // Wait for the socket to connect.
+                    while (true) {
+                        try {
+                            mSockets[i].connect(address);
+                            break;
+                        } catch (Exception e) {
+                            // ignore
+                        }
+                        checkpoint(true);
+                    }
+                    mSockets[i].setSoTimeout(500);
+
+                    // Send over the arguments.
+                    OutputStream out = mSockets[i].getOutputStream();
+                    for (String argument : arguments) {
+                        byte[] bytes = argument.getBytes(StandardCharsets.UTF_8);
+                        if (bytes.length >= 0xFFFF) {
+                            throw new IllegalArgumentException("Argument is too large");
+                        }
+                        out.write(bytes.length >> 8);
+                        out.write(bytes.length);
+                        out.write(bytes);
+                        checkpoint(false);
+                    }
+                    out.write(0xFF);
+                    out.write(0xFF);
+                    out.flush();
+
+                    // Wait for End-of-File.
+                    InputStream in = mSockets[i].getInputStream();
+                    while (true) {
+                        try {
+                            if (in.read() == -1) {
+                                break;
+                            }
+                        } catch (Exception e) {
+                            // ignore
+                        }
+                        checkpoint(true);
+                    }
+                }
+
+                // Wait for the daemons to create the new state.
+                while (!state.exists()) {
+                    // Check if a running daemon is dead.
+                    for (int i = 0; i < mDaemons.length; ++i) {
+                        String daemon = mDaemons[i];
+                        if (mArguments[i] != null && !SystemService.isRunning(daemon)) {
+                            throw new IllegalStateException(daemon + " is dead");
+                        }
+                    }
+                    checkpoint(true);
+                }
+
+                // Now we are connected. Read and parse the new state.
+                String[] parameters = FileUtils.readTextFile(state, 0, null).split("\n", -1);
+                if (parameters.length != 6) {
+                    throw new IllegalStateException("Cannot parse the state");
+                }
+
+                // Set the interface and the addresses in the config.
+                mConfig.interfaze = parameters[0].trim();
+
+                mConfig.addLegacyAddresses(parameters[1]);
+                // Set the routes if they are not set in the config.
+                if (mConfig.routes == null || mConfig.routes.isEmpty()) {
+                    mConfig.addLegacyRoutes(parameters[2]);
+                }
+
+                // Set the DNS servers if they are not set in the config.
+                if (mConfig.dnsServers == null || mConfig.dnsServers.size() == 0) {
+                    String dnsServers = parameters[3].trim();
+                    if (!dnsServers.isEmpty()) {
+                        mConfig.dnsServers = Arrays.asList(dnsServers.split(" "));
+                    }
+                }
+
+                // Set the search domains if they are not set in the config.
+                if (mConfig.searchDomains == null || mConfig.searchDomains.size() == 0) {
+                    String searchDomains = parameters[4].trim();
+                    if (!searchDomains.isEmpty()) {
+                        mConfig.searchDomains = Arrays.asList(searchDomains.split(" "));
+                    }
+                }
+
+                // Set the routes.
+                long token = Binder.clearCallingIdentity();
+                try {
+                    mCallback.setMarkedForwarding(mConfig.interfaze);
+                    mCallback.setRoutes(mConfig.interfaze, mConfig.routes);
+                } finally {
+                    Binder.restoreCallingIdentity(token);
+                }
+
+                // Here is the last step and it must be done synchronously.
+                synchronized (Vpn.this) {
+                    // Set the start time
+                    mConfig.startTime = SystemClock.elapsedRealtime();
+
+                    // Check if the thread is interrupted while we are waiting.
+                    checkpoint(false);
+
+                    // Check if the interface is gone while we are waiting.
+                    if (jniCheck(mConfig.interfaze) == 0) {
+                        throw new IllegalStateException(mConfig.interfaze + " is gone");
+                    }
+
+                    // Now INetworkManagementEventObserver is watching our back.
+                    mInterface = mConfig.interfaze;
+                    mVpnUsers = new SparseBooleanArray();
+
+                    token = Binder.clearCallingIdentity();
+                    try {
+                        mCallback.override(mInterface, mConfig.dnsServers, mConfig.searchDomains);
+                        addVpnUserLocked(mUserId);
+                    } finally {
+                        Binder.restoreCallingIdentity(token);
+                    }
+
+                    // Assign all restircted users to this VPN
+                    // (Legacy VPNs are Owner only)
+                    UserManager mgr = UserManager.get(mContext);
+                    token = Binder.clearCallingIdentity();
+                    try {
+                        for (UserInfo user : mgr.getUsers()) {
+                            if (user.isRestricted()) {
+                                try {
+                                    addVpnUserLocked(user.id);
+                                } catch (Exception e) {
+                                    Log.wtf(TAG, "Failed to add user " + user.id
+                                            + " to owner's VPN");
+                                }
+                            }
+                        }
+                    } finally {
+                        Binder.restoreCallingIdentity(token);
+                    }
+                    Log.i(TAG, "Connected!");
+                    updateState(DetailedState.CONNECTED, "execute");
+                }
+            } catch (Exception e) {
+                Log.i(TAG, "Aborting", e);
+                // make sure the routing is cleared
+                try {
+                    mCallback.clearMarkedForwarding(mConfig.interfaze);
+                } catch (Exception ignored) {
+                }
+                exit();
+            } finally {
+                // Kill the daemons if they fail to stop.
+                if (!initFinished) {
+                    for (String daemon : mDaemons) {
+                        SystemService.stop(daemon);
+                    }
+                }
+
+                // Do not leave an unstable state.
+                if (!initFinished || mNetworkInfo.getDetailedState() == DetailedState.CONNECTING) {
+                    updateState(DetailedState.FAILED, "execute");
+                }
+            }
+        }
+
+        /**
+         * Monitor the daemons we started, moving to disconnected state if the
+         * underlying services fail.
+         */
+        private void monitorDaemons() {
+            if (!mNetworkInfo.isConnected()) {
+                return;
+            }
+
+            try {
+                while (true) {
+                    Thread.sleep(2000);
+                    for (int i = 0; i < mDaemons.length; i++) {
+                        if (mArguments[i] != null && SystemService.isStopped(mDaemons[i])) {
+                            return;
+                        }
+                    }
+                }
+            } catch (InterruptedException e) {
+                Log.d(TAG, "interrupted during monitorDaemons(); stopping services");
+            } finally {
+                for (String daemon : mDaemons) {
+                    SystemService.stop(daemon);
+                }
+
+                updateState(DetailedState.DISCONNECTED, "babysit");
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/content/ContentService.java b/services/core/java/com/android/server/content/ContentService.java
similarity index 100%
rename from services/java/com/android/server/content/ContentService.java
rename to services/core/java/com/android/server/content/ContentService.java
diff --git a/services/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java
similarity index 100%
rename from services/java/com/android/server/content/SyncManager.java
rename to services/core/java/com/android/server/content/SyncManager.java
diff --git a/services/java/com/android/server/content/SyncOperation.java b/services/core/java/com/android/server/content/SyncOperation.java
similarity index 100%
rename from services/java/com/android/server/content/SyncOperation.java
rename to services/core/java/com/android/server/content/SyncOperation.java
diff --git a/services/java/com/android/server/content/SyncQueue.java b/services/core/java/com/android/server/content/SyncQueue.java
similarity index 100%
rename from services/java/com/android/server/content/SyncQueue.java
rename to services/core/java/com/android/server/content/SyncQueue.java
diff --git a/services/core/java/com/android/server/content/SyncStorageEngine.java b/services/core/java/com/android/server/content/SyncStorageEngine.java
new file mode 100644
index 0000000..124bc60
--- /dev/null
+++ b/services/core/java/com/android/server/content/SyncStorageEngine.java
@@ -0,0 +1,2644 @@
+/*
+ * 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.
+ */
+
+package com.android.server.content;
+
+import android.accounts.Account;
+import android.accounts.AccountAndUser;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.ISyncStatusObserver;
+import android.content.PeriodicSync;
+import android.content.SyncInfo;
+import android.content.SyncStatusInfo;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
+import android.database.sqlite.SQLiteQueryBuilder;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.Message;
+import android.os.Parcel;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+import android.util.AtomicFile;
+import android.util.Log;
+import android.util.Pair;
+import android.util.SparseArray;
+import android.util.Xml;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.FastXmlSerializer;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.TimeZone;
+
+/**
+ * Singleton that tracks the sync data and overall sync
+ * history on the device.
+ *
+ * @hide
+ */
+public class SyncStorageEngine extends Handler {
+
+    private static final String TAG = "SyncManager";
+    private static final boolean DEBUG = false;
+    private static final String TAG_FILE = "SyncManagerFile";
+
+    private static final String XML_ATTR_NEXT_AUTHORITY_ID = "nextAuthorityId";
+    private static final String XML_ATTR_LISTEN_FOR_TICKLES = "listen-for-tickles";
+    private static final String XML_ATTR_SYNC_RANDOM_OFFSET = "offsetInSeconds";
+    private static final String XML_ATTR_ENABLED = "enabled";
+    private static final String XML_ATTR_USER = "user";
+    private static final String XML_TAG_LISTEN_FOR_TICKLES = "listenForTickles";
+
+    /** Default time for a periodic sync. */
+    private static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day
+
+    /** Percentage of period that is flex by default, if no flex is set. */
+    private static final double DEFAULT_FLEX_PERCENT_SYNC = 0.04;
+
+    /** Lower bound on sync time from which we assign a default flex time. */
+    private static final long DEFAULT_MIN_FLEX_ALLOWED_SECS = 5;
+
+    @VisibleForTesting
+    static final long MILLIS_IN_4WEEKS = 1000L * 60 * 60 * 24 * 7 * 4;
+
+    /** Enum value for a sync start event. */
+    public static final int EVENT_START = 0;
+
+    /** Enum value for a sync stop event. */
+    public static final int EVENT_STOP = 1;
+
+    // TODO: i18n -- grab these out of resources.
+    /** String names for the sync event types. */
+    public static final String[] EVENTS = { "START", "STOP" };
+
+    /** Enum value for a server-initiated sync. */
+    public static final int SOURCE_SERVER = 0;
+
+    /** Enum value for a local-initiated sync. */
+    public static final int SOURCE_LOCAL = 1;
+    /**
+     * Enum value for a poll-based sync (e.g., upon connection to
+     * network)
+     */
+    public static final int SOURCE_POLL = 2;
+
+    /** Enum value for a user-initiated sync. */
+    public static final int SOURCE_USER = 3;
+
+    /** Enum value for a periodic sync. */
+    public static final int SOURCE_PERIODIC = 4;
+
+    public static final long NOT_IN_BACKOFF_MODE = -1;
+
+    // TODO: i18n -- grab these out of resources.
+    /** String names for the sync source types. */
+    public static final String[] SOURCES = { "SERVER",
+                                             "LOCAL",
+                                             "POLL",
+                                             "USER",
+                                             "PERIODIC" };
+
+    // The MESG column will contain one of these or one of the Error types.
+    public static final String MESG_SUCCESS = "success";
+    public static final String MESG_CANCELED = "canceled";
+
+    public static final int MAX_HISTORY = 100;
+
+    private static final int MSG_WRITE_STATUS = 1;
+    private static final long WRITE_STATUS_DELAY = 1000*60*10; // 10 minutes
+
+    private static final int MSG_WRITE_STATISTICS = 2;
+    private static final long WRITE_STATISTICS_DELAY = 1000*60*30; // 1/2 hour
+
+    private static final boolean SYNC_ENABLED_DEFAULT = false;
+
+    // the version of the accounts xml file format
+    private static final int ACCOUNTS_VERSION = 2;
+
+    private static HashMap<String, String> sAuthorityRenames;
+
+    static {
+        sAuthorityRenames = new HashMap<String, String>();
+        sAuthorityRenames.put("contacts", "com.android.contacts");
+        sAuthorityRenames.put("calendar", "com.android.calendar");
+    }
+
+    public static class PendingOperation {
+        final Account account;
+        final int userId;
+        final int reason;
+        final int syncSource;
+        final String authority;
+        final Bundle extras;        // note: read-only.
+        final ComponentName serviceName;
+        final boolean expedited;
+
+        int authorityId;
+        byte[] flatExtras;
+
+        PendingOperation(Account account, int userId, int reason, int source,
+                String authority, Bundle extras, boolean expedited) {
+            this.account = account;
+            this.userId = userId;
+            this.syncSource = source;
+            this.reason = reason;
+            this.authority = authority;
+            this.extras = extras != null ? new Bundle(extras) : extras;
+            this.expedited = expedited;
+            this.authorityId = -1;
+            this.serviceName = null;
+        }
+
+        PendingOperation(PendingOperation other) {
+            this.account = other.account;
+            this.userId = other.userId;
+            this.reason = other.reason;
+            this.syncSource = other.syncSource;
+            this.authority = other.authority;
+            this.extras = other.extras;
+            this.authorityId = other.authorityId;
+            this.expedited = other.expedited;
+            this.serviceName = other.serviceName;
+        }
+    }
+
+    static class AccountInfo {
+        final AccountAndUser accountAndUser;
+        final HashMap<String, AuthorityInfo> authorities =
+                new HashMap<String, AuthorityInfo>();
+
+        AccountInfo(AccountAndUser accountAndUser) {
+            this.accountAndUser = accountAndUser;
+        }
+    }
+
+    public static class AuthorityInfo {
+        final ComponentName service;
+        final Account account;
+        final int userId;
+        final String authority;
+        final int ident;
+        boolean enabled;
+        int syncable;
+        long backoffTime;
+        long backoffDelay;
+        long delayUntil;
+        final ArrayList<PeriodicSync> periodicSyncs;
+
+        /**
+         * Copy constructor for making deep-ish copies. Only the bundles stored
+         * in periodic syncs can make unexpected changes.
+         *
+         * @param toCopy AuthorityInfo to be copied.
+         */
+        AuthorityInfo(AuthorityInfo toCopy) {
+            account = toCopy.account;
+            userId = toCopy.userId;
+            authority = toCopy.authority;
+            service = toCopy.service;
+            ident = toCopy.ident;
+            enabled = toCopy.enabled;
+            syncable = toCopy.syncable;
+            backoffTime = toCopy.backoffTime;
+            backoffDelay = toCopy.backoffDelay;
+            delayUntil = toCopy.delayUntil;
+            periodicSyncs = new ArrayList<PeriodicSync>();
+            for (PeriodicSync sync : toCopy.periodicSyncs) {
+                // Still not a perfect copy, because we are just copying the mappings.
+                periodicSyncs.add(new PeriodicSync(sync));
+            }
+        }
+
+        /**
+         * Create an authority with one periodic sync scheduled with an empty bundle and syncing
+         * every day. An empty bundle is considered equal to any other bundle see
+         * {@link PeriodicSync.syncExtrasEquals}.
+         * @param account Account that this authority syncs.
+         * @param userId which user this sync is registered for.
+         * @param userId user for which this authority is registered.
+         * @param ident id of this authority.
+         */
+        AuthorityInfo(Account account, int userId, String authority, int ident) {
+            this.account = account;
+            this.userId = userId;
+            this.authority = authority;
+            this.service = null;
+            this.ident = ident;
+            enabled = SYNC_ENABLED_DEFAULT;
+            syncable = -1; // default to "unknown"
+            backoffTime = -1; // if < 0 then we aren't in backoff mode
+            backoffDelay = -1; // if < 0 then we aren't in backoff mode
+            periodicSyncs = new ArrayList<PeriodicSync>();
+            // Old version adds one periodic sync a day.
+            periodicSyncs.add(new PeriodicSync(account, authority,
+                                new Bundle(),
+                                DEFAULT_POLL_FREQUENCY_SECONDS,
+                                calculateDefaultFlexTime(DEFAULT_POLL_FREQUENCY_SECONDS)));
+        }
+
+        /**
+         * Create an authority with one periodic sync scheduled with an empty bundle and syncing
+         * every day using a sync service.
+         * @param cname sync service identifier.
+         * @param userId user for which this authority is registered.
+         * @param ident id of this authority.
+         */
+        AuthorityInfo(ComponentName cname, int userId, int ident) {
+            this.account = null;
+            this.userId = userId;
+            this.authority = null;
+            this.service = cname;
+            this.ident = ident;
+            // Sync service is always enabled.
+            enabled = true;
+            syncable = -1; // default to "unknown"
+            backoffTime = -1; // if < 0 then we aren't in backoff mode
+            backoffDelay = -1; // if < 0 then we aren't in backoff mode
+            periodicSyncs = new ArrayList<PeriodicSync>();
+            periodicSyncs.add(new PeriodicSync(account, authority,
+                                new Bundle(),
+                                DEFAULT_POLL_FREQUENCY_SECONDS,
+                                calculateDefaultFlexTime(DEFAULT_POLL_FREQUENCY_SECONDS)));
+        }
+    }
+
+    public static class SyncHistoryItem {
+        int authorityId;
+        int historyId;
+        long eventTime;
+        long elapsedTime;
+        int source;
+        int event;
+        long upstreamActivity;
+        long downstreamActivity;
+        String mesg;
+        boolean initialization;
+        Bundle extras;
+        int reason;
+    }
+
+    public static class DayStats {
+        public final int day;
+        public int successCount;
+        public long successTime;
+        public int failureCount;
+        public long failureTime;
+
+        public DayStats(int day) {
+            this.day = day;
+        }
+    }
+
+    interface OnSyncRequestListener {
+        /**
+         * Called when a sync is needed on an account(s) due to some change in state.
+         * @param account
+         * @param userId
+         * @param reason
+         * @param authority
+         * @param extras
+         */
+        public void onSyncRequest(Account account, int userId, int reason, String authority,
+                Bundle extras);
+    }
+
+    // Primary list of all syncable authorities.  Also our global lock.
+    private final SparseArray<AuthorityInfo> mAuthorities =
+            new SparseArray<AuthorityInfo>();
+
+    private final HashMap<AccountAndUser, AccountInfo> mAccounts
+            = new HashMap<AccountAndUser, AccountInfo>();
+
+    private final ArrayList<PendingOperation> mPendingOperations =
+            new ArrayList<PendingOperation>();
+
+    private final SparseArray<ArrayList<SyncInfo>> mCurrentSyncs
+            = new SparseArray<ArrayList<SyncInfo>>();
+
+    private final SparseArray<SyncStatusInfo> mSyncStatus =
+            new SparseArray<SyncStatusInfo>();
+
+    private final ArrayList<SyncHistoryItem> mSyncHistory =
+            new ArrayList<SyncHistoryItem>();
+
+    private final RemoteCallbackList<ISyncStatusObserver> mChangeListeners
+            = new RemoteCallbackList<ISyncStatusObserver>();
+
+    /** Reverse mapping for component name -> <userid -> authority id>. */
+    private final HashMap<ComponentName, SparseArray<AuthorityInfo>> mServices =
+            new HashMap<ComponentName, SparseArray<AuthorityInfo>>();
+
+    private int mNextAuthorityId = 0;
+
+    // We keep 4 weeks of stats.
+    private final DayStats[] mDayStats = new DayStats[7*4];
+    private final Calendar mCal;
+    private int mYear;
+    private int mYearInDays;
+
+    private final Context mContext;
+
+    private static volatile SyncStorageEngine sSyncStorageEngine = null;
+
+    private int mSyncRandomOffset;
+
+    /**
+     * This file contains the core engine state: all accounts and the
+     * settings for them.  It must never be lost, and should be changed
+     * infrequently, so it is stored as an XML file.
+     */
+    private final AtomicFile mAccountInfoFile;
+
+    /**
+     * This file contains the current sync status.  We would like to retain
+     * it across boots, but its loss is not the end of the world, so we store
+     * this information as binary data.
+     */
+    private final AtomicFile mStatusFile;
+
+    /**
+     * This file contains sync statistics.  This is purely debugging information
+     * so is written infrequently and can be thrown away at any time.
+     */
+    private final AtomicFile mStatisticsFile;
+
+    /**
+     * This file contains the pending sync operations.  It is a binary file,
+     * which must be updated every time an operation is added or removed,
+     * so we have special handling of it.
+     */
+    private final AtomicFile mPendingFile;
+    private static final int PENDING_FINISH_TO_WRITE = 4;
+    private int mNumPendingFinished = 0;
+
+    private int mNextHistoryId = 0;
+    private SparseArray<Boolean> mMasterSyncAutomatically = new SparseArray<Boolean>();
+    private boolean mDefaultMasterSyncAutomatically;
+
+    private OnSyncRequestListener mSyncRequestListener;
+
+    private SyncStorageEngine(Context context, File dataDir) {
+        mContext = context;
+        sSyncStorageEngine = this;
+
+        mCal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0"));
+
+        mDefaultMasterSyncAutomatically = mContext.getResources().getBoolean(
+               com.android.internal.R.bool.config_syncstorageengine_masterSyncAutomatically);
+
+        File systemDir = new File(dataDir, "system");
+        File syncDir = new File(systemDir, "sync");
+        syncDir.mkdirs();
+
+        maybeDeleteLegacyPendingInfoLocked(syncDir);
+
+        mAccountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
+        mStatusFile = new AtomicFile(new File(syncDir, "status.bin"));
+        mPendingFile = new AtomicFile(new File(syncDir, "pending.xml"));
+        mStatisticsFile = new AtomicFile(new File(syncDir, "stats.bin"));
+
+        readAccountInfoLocked();
+        readStatusLocked();
+        readPendingOperationsLocked();
+        readStatisticsLocked();
+        readAndDeleteLegacyAccountInfoLocked();
+        writeAccountInfoLocked();
+        writeStatusLocked();
+        writePendingOperationsLocked();
+        writeStatisticsLocked();
+    }
+
+    public static SyncStorageEngine newTestInstance(Context context) {
+        return new SyncStorageEngine(context, context.getFilesDir());
+    }
+
+    public static void init(Context context) {
+        if (sSyncStorageEngine != null) {
+            return;
+        }
+        // This call will return the correct directory whether Encrypted File Systems is
+        // enabled or not.
+        File dataDir = Environment.getSecureDataDirectory();
+        sSyncStorageEngine = new SyncStorageEngine(context, dataDir);
+    }
+
+    public static SyncStorageEngine getSingleton() {
+        if (sSyncStorageEngine == null) {
+            throw new IllegalStateException("not initialized");
+        }
+        return sSyncStorageEngine;
+    }
+
+    protected void setOnSyncRequestListener(OnSyncRequestListener listener) {
+        if (mSyncRequestListener == null) {
+            mSyncRequestListener = listener;
+        }
+    }
+
+    @Override public void handleMessage(Message msg) {
+        if (msg.what == MSG_WRITE_STATUS) {
+            synchronized (mAuthorities) {
+                writeStatusLocked();
+            }
+        } else if (msg.what == MSG_WRITE_STATISTICS) {
+            synchronized (mAuthorities) {
+                writeStatisticsLocked();
+            }
+        }
+    }
+
+    public int getSyncRandomOffset() {
+        return mSyncRandomOffset;
+    }
+
+    public void addStatusChangeListener(int mask, ISyncStatusObserver callback) {
+        synchronized (mAuthorities) {
+            mChangeListeners.register(callback, mask);
+        }
+    }
+
+    public void removeStatusChangeListener(ISyncStatusObserver callback) {
+        synchronized (mAuthorities) {
+            mChangeListeners.unregister(callback);
+        }
+    }
+
+    /**
+     * Figure out a reasonable flex time for cases where none is provided (old api calls).
+     * @param syncTimeSeconds requested sync time from now.
+     * @return amount of seconds before syncTimeSeconds that the sync can occur.
+     *      I.e.
+     *      earliest_sync_time = syncTimeSeconds - calculateDefaultFlexTime(syncTimeSeconds)
+     * The flex time is capped at a percentage of the {@link DEFAULT_POLL_FREQUENCY_SECONDS}.
+     */
+    public static long calculateDefaultFlexTime(long syncTimeSeconds) {
+        if (syncTimeSeconds < DEFAULT_MIN_FLEX_ALLOWED_SECS) {
+            // Small enough sync request time that we don't add flex time - developer probably
+            // wants to wait for an operation to occur before syncing so we honour the
+            // request time.
+            return 0L;
+        } else if (syncTimeSeconds < DEFAULT_POLL_FREQUENCY_SECONDS) {
+            return (long) (syncTimeSeconds * DEFAULT_FLEX_PERCENT_SYNC);
+        } else {
+            // Large enough sync request time that we cap the flex time.
+            return (long) (DEFAULT_POLL_FREQUENCY_SECONDS * DEFAULT_FLEX_PERCENT_SYNC);
+        }
+    }
+
+    private void reportChange(int which) {
+        ArrayList<ISyncStatusObserver> reports = null;
+        synchronized (mAuthorities) {
+            int i = mChangeListeners.beginBroadcast();
+            while (i > 0) {
+                i--;
+                Integer mask = (Integer)mChangeListeners.getBroadcastCookie(i);
+                if ((which & mask.intValue()) == 0) {
+                    continue;
+                }
+                if (reports == null) {
+                    reports = new ArrayList<ISyncStatusObserver>(i);
+                }
+                reports.add(mChangeListeners.getBroadcastItem(i));
+            }
+            mChangeListeners.finishBroadcast();
+        }
+
+        if (DEBUG) {
+            Log.v(TAG, "reportChange " + which + " to: " + reports);
+        }
+
+        if (reports != null) {
+            int i = reports.size();
+            while (i > 0) {
+                i--;
+                try {
+                    reports.get(i).onStatusChanged(which);
+                } catch (RemoteException e) {
+                    // The remote callback list will take care of this for us.
+                }
+            }
+        }
+    }
+
+    public boolean getSyncAutomatically(Account account, int userId, String providerName) {
+        synchronized (mAuthorities) {
+            if (account != null) {
+                AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
+                        "getSyncAutomatically");
+                return authority != null && authority.enabled;
+            }
+
+            int i = mAuthorities.size();
+            while (i > 0) {
+                i--;
+                AuthorityInfo authority = mAuthorities.valueAt(i);
+                if (authority.authority.equals(providerName)
+                        && authority.userId == userId
+                        && authority.enabled) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    public void setSyncAutomatically(Account account, int userId, String providerName,
+            boolean sync) {
+        if (DEBUG) {
+            Log.d(TAG, "setSyncAutomatically: " + /* account + */" provider " + providerName
+                    + ", user " + userId + " -> " + sync);
+        }
+        synchronized (mAuthorities) {
+            AuthorityInfo authority = getOrCreateAuthorityLocked(account, userId, providerName, -1,
+                    false);
+            if (authority.enabled == sync) {
+                if (DEBUG) {
+                    Log.d(TAG, "setSyncAutomatically: already set to " + sync + ", doing nothing");
+                }
+                return;
+            }
+            authority.enabled = sync;
+            writeAccountInfoLocked();
+        }
+
+        if (sync) {
+            requestSync(account, userId, SyncOperation.REASON_SYNC_AUTO, providerName,
+                    new Bundle());
+        }
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+    }
+
+    public int getIsSyncable(Account account, int userId, String providerName) {
+        synchronized (mAuthorities) {
+            if (account != null) {
+                AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
+                        "getIsSyncable");
+                if (authority == null) {
+                    return -1;
+                }
+                return authority.syncable;
+            }
+
+            int i = mAuthorities.size();
+            while (i > 0) {
+                i--;
+                AuthorityInfo authority = mAuthorities.valueAt(i);
+                if (authority.authority.equals(providerName)) {
+                    return authority.syncable;
+                }
+            }
+            return -1;
+        }
+    }
+
+    public void setIsSyncable(Account account, int userId, String providerName, int syncable) {
+        if (syncable > 1) {
+            syncable = 1;
+        } else if (syncable < -1) {
+            syncable = -1;
+        }
+        if (DEBUG) {
+            Log.d(TAG, "setIsSyncable: " + account + ", provider " + providerName
+                    + ", user " + userId + " -> " + syncable);
+        }
+        synchronized (mAuthorities) {
+            AuthorityInfo authority =
+                    getOrCreateAuthorityLocked(account, userId, providerName, -1, false);
+            if (authority.syncable == syncable) {
+                if (DEBUG) {
+                    Log.d(TAG, "setIsSyncable: already set to " + syncable + ", doing nothing");
+                }
+                return;
+            }
+            authority.syncable = syncable;
+            writeAccountInfoLocked();
+        }
+
+        if (syncable > 0) {
+            requestSync(account, userId, SyncOperation.REASON_IS_SYNCABLE,  providerName,
+                    new Bundle());
+        }
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+    }
+
+    public Pair<Long, Long> getBackoff(Account account, int userId, String providerName) {
+        synchronized (mAuthorities) {
+            AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
+                    "getBackoff");
+            if (authority == null || authority.backoffTime < 0) {
+                return null;
+            }
+            return Pair.create(authority.backoffTime, authority.backoffDelay);
+        }
+    }
+
+    public void setBackoff(Account account, int userId, String providerName,
+            long nextSyncTime, long nextDelay) {
+        if (DEBUG) {
+            Log.v(TAG, "setBackoff: " + account + ", provider " + providerName
+                    + ", user " + userId
+                    + " -> nextSyncTime " + nextSyncTime + ", nextDelay " + nextDelay);
+        }
+        boolean changed = false;
+        synchronized (mAuthorities) {
+            if (account == null || providerName == null) {
+                for (AccountInfo accountInfo : mAccounts.values()) {
+                    if (account != null && !account.equals(accountInfo.accountAndUser.account)
+                            && userId != accountInfo.accountAndUser.userId) {
+                        continue;
+                    }
+                    for (AuthorityInfo authorityInfo : accountInfo.authorities.values()) {
+                        if (providerName != null
+                                && !providerName.equals(authorityInfo.authority)) {
+                            continue;
+                        }
+                        if (authorityInfo.backoffTime != nextSyncTime
+                                || authorityInfo.backoffDelay != nextDelay) {
+                            authorityInfo.backoffTime = nextSyncTime;
+                            authorityInfo.backoffDelay = nextDelay;
+                            changed = true;
+                        }
+                    }
+                }
+            } else {
+                AuthorityInfo authority =
+                        getOrCreateAuthorityLocked(account, userId, providerName, -1 /* ident */,
+                                true);
+                if (authority.backoffTime == nextSyncTime && authority.backoffDelay == nextDelay) {
+                    return;
+                }
+                authority.backoffTime = nextSyncTime;
+                authority.backoffDelay = nextDelay;
+                changed = true;
+            }
+        }
+
+        if (changed) {
+            reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+        }
+    }
+
+    /**
+     * Callers of this function need to hold a lock for syncQueue object passed in. Bear in mind
+     * this function grabs the lock for {@link #mAuthorities}
+     * @param syncQueue queue containing pending sync operations.
+     */
+    public void clearAllBackoffsLocked(SyncQueue syncQueue) {
+        boolean changed = false;
+        synchronized (mAuthorities) {
+            for (AccountInfo accountInfo : mAccounts.values()) {
+                for (AuthorityInfo authorityInfo : accountInfo.authorities.values()) {
+                    if (authorityInfo.backoffTime != NOT_IN_BACKOFF_MODE
+                            || authorityInfo.backoffDelay != NOT_IN_BACKOFF_MODE) {
+                        if (DEBUG) {
+                            Log.v(TAG, "clearAllBackoffs:"
+                                    + " authority:" + authorityInfo.authority
+                                    + " account:" + accountInfo.accountAndUser.account.name
+                                    + " user:" + accountInfo.accountAndUser.userId
+                                    + " backoffTime was: " + authorityInfo.backoffTime
+                                    + " backoffDelay was: " + authorityInfo.backoffDelay);
+                        }
+                        authorityInfo.backoffTime = NOT_IN_BACKOFF_MODE;
+                        authorityInfo.backoffDelay = NOT_IN_BACKOFF_MODE;
+                        syncQueue.onBackoffChanged(accountInfo.accountAndUser.account,
+                                accountInfo.accountAndUser.userId, authorityInfo.authority, 0);
+                        changed = true;
+                    }
+                }
+            }
+        }
+
+        if (changed) {
+            reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+        }
+    }
+
+    public void setDelayUntilTime(Account account, int userId, String providerName,
+            long delayUntil) {
+        if (DEBUG) {
+            Log.v(TAG, "setDelayUntil: " + account + ", provider " + providerName
+                    + ", user " + userId + " -> delayUntil " + delayUntil);
+        }
+        synchronized (mAuthorities) {
+            AuthorityInfo authority = getOrCreateAuthorityLocked(
+                    account, userId, providerName, -1 /* ident */, true);
+            if (authority.delayUntil == delayUntil) {
+                return;
+            }
+            authority.delayUntil = delayUntil;
+        }
+
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+    }
+
+    public long getDelayUntilTime(Account account, int userId, String providerName) {
+        synchronized (mAuthorities) {
+            AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
+                    "getDelayUntil");
+            if (authority == null) {
+                return 0;
+            }
+            return authority.delayUntil;
+        }
+    }
+
+    private void updateOrRemovePeriodicSync(PeriodicSync toUpdate, int userId, boolean add) {
+        if (DEBUG) {
+            Log.v(TAG, "addOrRemovePeriodicSync: " + toUpdate.account + ", user " + userId
+                    + ", provider " + toUpdate.authority
+                    + " -> period " + toUpdate.period + ", extras " + toUpdate.extras);
+        }
+        synchronized (mAuthorities) {
+            if (toUpdate.period <= 0 && add) {
+                Log.e(TAG, "period < 0, should never happen in updateOrRemovePeriodicSync: add-"
+                        + add);
+            }
+            if (toUpdate.extras == null) {
+                Log.e(TAG, "null extras, should never happen in updateOrRemovePeriodicSync: add-"
+                        + add);
+            }
+            try {
+                AuthorityInfo authority =
+                        getOrCreateAuthorityLocked(toUpdate.account, userId, toUpdate.authority,
+                                -1, false);
+                if (add) {
+                    // add this periodic sync if an equivalent periodic doesn't already exist.
+                    boolean alreadyPresent = false;
+                    for (int i = 0, N = authority.periodicSyncs.size(); i < N; i++) {
+                        PeriodicSync syncInfo = authority.periodicSyncs.get(i);
+                        if (PeriodicSync.syncExtrasEquals(
+                                toUpdate.extras,
+                                syncInfo.extras)) {
+                            if (toUpdate.period == syncInfo.period &&
+                                    toUpdate.flexTime == syncInfo.flexTime) {
+                                // Absolutely the same.
+                                return;
+                            }
+                            authority.periodicSyncs.set(i, new PeriodicSync(toUpdate));
+                            alreadyPresent = true;
+                            break;
+                        }
+                    }
+                    // If we added an entry to the periodicSyncs array also add an entry to
+                    // the periodic syncs status to correspond to it.
+                    if (!alreadyPresent) {
+                        authority.periodicSyncs.add(new PeriodicSync(toUpdate));
+                        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
+                        status.setPeriodicSyncTime(authority.periodicSyncs.size() - 1, 0L);
+                    }
+                } else {
+                    // Remove any periodic syncs that match the authority and extras.
+                    SyncStatusInfo status = mSyncStatus.get(authority.ident);
+                    boolean changed = false;
+                    Iterator<PeriodicSync> iterator = authority.periodicSyncs.iterator();
+                    int i = 0;
+                    while (iterator.hasNext()) {
+                        PeriodicSync syncInfo = iterator.next();
+                        if (PeriodicSync.syncExtrasEquals(syncInfo.extras, toUpdate.extras)) {
+                            iterator.remove();
+                            changed = true;
+                            // If we removed an entry from the periodicSyncs array also
+                            // remove the corresponding entry from the status
+                            if (status != null) {
+                                status.removePeriodicSyncTime(i);
+                            } else {
+                                Log.e(TAG, "Tried removing sync status on remove periodic sync but"
+                                        + "did not find it.");
+                            }
+                        } else {
+                            i++;
+                        }
+                    }
+                    if (!changed) {
+                        return;
+                    }
+                }
+            } finally {
+                writeAccountInfoLocked();
+                writeStatusLocked();
+            }
+        }
+
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+    }
+
+    public void addPeriodicSync(PeriodicSync toAdd, int userId) {
+        updateOrRemovePeriodicSync(toAdd, userId, true /* add */);
+    }
+
+    public void removePeriodicSync(PeriodicSync toRemove, int userId) {
+        updateOrRemovePeriodicSync(toRemove, userId, false /* remove */);
+    }
+
+    public List<PeriodicSync> getPeriodicSyncs(Account account, int userId, String providerName) {
+        ArrayList<PeriodicSync> syncs = new ArrayList<PeriodicSync>();
+        synchronized (mAuthorities) {
+            AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
+                    "getPeriodicSyncs");
+            if (authority != null) {
+                for (PeriodicSync item : authority.periodicSyncs) {
+                    // Copy and send out. Necessary for thread-safety although it's parceled.
+                    syncs.add(new PeriodicSync(item));
+                }
+            }
+        }
+        return syncs;
+    }
+
+    public void setMasterSyncAutomatically(boolean flag, int userId) {
+        synchronized (mAuthorities) {
+            Boolean auto = mMasterSyncAutomatically.get(userId);
+            if (auto != null && (boolean) auto == flag) {
+                return;
+            }
+            mMasterSyncAutomatically.put(userId, flag);
+            writeAccountInfoLocked();
+        }
+        if (flag) {
+            requestSync(null, userId, SyncOperation.REASON_MASTER_SYNC_AUTO, null,
+                    new Bundle());
+        }
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
+        mContext.sendBroadcast(ContentResolver.ACTION_SYNC_CONN_STATUS_CHANGED);
+    }
+
+    public boolean getMasterSyncAutomatically(int userId) {
+        synchronized (mAuthorities) {
+            Boolean auto = mMasterSyncAutomatically.get(userId);
+            return auto == null ? mDefaultMasterSyncAutomatically : auto;
+        }
+    }
+
+    public void removeAuthority(Account account, int userId, String authority) {
+        synchronized (mAuthorities) {
+            removeAuthorityLocked(account, userId, authority, true /* doWrite */);
+        }
+    }
+
+    public AuthorityInfo getAuthority(int authorityId) {
+        synchronized (mAuthorities) {
+            return mAuthorities.get(authorityId);
+        }
+    }
+
+    /**
+     * Returns true if there is currently a sync operation for the given
+     * account or authority actively being processed.
+     */
+    public boolean isSyncActive(Account account, int userId, String authority) {
+        synchronized (mAuthorities) {
+            for (SyncInfo syncInfo : getCurrentSyncs(userId)) {
+                AuthorityInfo ainfo = getAuthority(syncInfo.authorityId);
+                if (ainfo != null && ainfo.account.equals(account)
+                        && ainfo.authority.equals(authority)
+                        && ainfo.userId == userId) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    public PendingOperation insertIntoPending(PendingOperation op) {
+        synchronized (mAuthorities) {
+            if (DEBUG) {
+                Log.v(TAG, "insertIntoPending: account=" + op.account
+                        + " user=" + op.userId
+                        + " auth=" + op.authority
+                        + " src=" + op.syncSource
+                        + " extras=" + op.extras);
+            }
+
+            AuthorityInfo authority = getOrCreateAuthorityLocked(op.account, op.userId,
+                    op.authority,
+                    -1 /* desired identifier */,
+                    true /* write accounts to storage */);
+            if (authority == null) {
+                return null;
+            }
+
+            op = new PendingOperation(op);
+            op.authorityId = authority.ident;
+            mPendingOperations.add(op);
+            appendPendingOperationLocked(op);
+
+            SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
+            status.pending = true;
+        }
+
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
+        return op;
+    }
+
+    /**
+     * Remove from list of pending operations. If successful, search through list for matching
+     * authorities. If there are no more pending syncs for the same authority/account/userid,
+     * update the SyncStatusInfo for that authority(authority here is the internal representation
+     * of a 'sync operation'.
+     * @param op
+     * @return
+     */
+    public boolean deleteFromPending(PendingOperation op) {
+        boolean res = false;
+        synchronized (mAuthorities) {
+            if (DEBUG) {
+                Log.v(TAG, "deleteFromPending: account=" + op.account
+                    + " user=" + op.userId
+                    + " auth=" + op.authority
+                    + " src=" + op.syncSource
+                    + " extras=" + op.extras);
+            }
+            if (mPendingOperations.remove(op)) {
+                if (mPendingOperations.size() == 0
+                        || mNumPendingFinished >= PENDING_FINISH_TO_WRITE) {
+                    writePendingOperationsLocked();
+                    mNumPendingFinished = 0;
+                } else {
+                    mNumPendingFinished++;
+                }
+
+                AuthorityInfo authority = getAuthorityLocked(op.account, op.userId, op.authority,
+                        "deleteFromPending");
+                if (authority != null) {
+                    if (DEBUG) Log.v(TAG, "removing - " + authority.toString());
+                    final int N = mPendingOperations.size();
+                    boolean morePending = false;
+                    for (int i=0; i<N; i++) {
+                        PendingOperation cur = mPendingOperations.get(i);
+                        if (cur.account.equals(op.account)
+                                && cur.authority.equals(op.authority)
+                                && cur.userId == op.userId) {
+                            morePending = true;
+                            break;
+                        }
+                    }
+
+                    if (!morePending) {
+                        if (DEBUG) Log.v(TAG, "no more pending!");
+                        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
+                        status.pending = false;
+                    }
+                }
+
+                res = true;
+            }
+        }
+
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
+        return res;
+    }
+
+    /**
+     * Return a copy of the current array of pending operations.  The
+     * PendingOperation objects are the real objects stored inside, so that
+     * they can be used with deleteFromPending().
+     */
+    public ArrayList<PendingOperation> getPendingOperations() {
+        synchronized (mAuthorities) {
+            return new ArrayList<PendingOperation>(mPendingOperations);
+        }
+    }
+
+    /**
+     * Return the number of currently pending operations.
+     */
+    public int getPendingOperationCount() {
+        synchronized (mAuthorities) {
+            return mPendingOperations.size();
+        }
+    }
+
+    /**
+     * Called when the set of account has changed, given the new array of
+     * active accounts.
+     */
+    public void doDatabaseCleanup(Account[] accounts, int userId) {
+        synchronized (mAuthorities) {
+            if (DEBUG) Log.v(TAG, "Updating for new accounts...");
+            SparseArray<AuthorityInfo> removing = new SparseArray<AuthorityInfo>();
+            Iterator<AccountInfo> accIt = mAccounts.values().iterator();
+            while (accIt.hasNext()) {
+                AccountInfo acc = accIt.next();
+                if (!ArrayUtils.contains(accounts, acc.accountAndUser.account)
+                        && acc.accountAndUser.userId == userId) {
+                    // This account no longer exists...
+                    if (DEBUG) {
+                        Log.v(TAG, "Account removed: " + acc.accountAndUser);
+                    }
+                    for (AuthorityInfo auth : acc.authorities.values()) {
+                        removing.put(auth.ident, auth);
+                    }
+                    accIt.remove();
+                }
+            }
+
+            // Clean out all data structures.
+            int i = removing.size();
+            if (i > 0) {
+                while (i > 0) {
+                    i--;
+                    int ident = removing.keyAt(i);
+                    mAuthorities.remove(ident);
+                    int j = mSyncStatus.size();
+                    while (j > 0) {
+                        j--;
+                        if (mSyncStatus.keyAt(j) == ident) {
+                            mSyncStatus.remove(mSyncStatus.keyAt(j));
+                        }
+                    }
+                    j = mSyncHistory.size();
+                    while (j > 0) {
+                        j--;
+                        if (mSyncHistory.get(j).authorityId == ident) {
+                            mSyncHistory.remove(j);
+                        }
+                    }
+                }
+                writeAccountInfoLocked();
+                writeStatusLocked();
+                writePendingOperationsLocked();
+                writeStatisticsLocked();
+            }
+        }
+    }
+
+    /**
+     * Called when a sync is starting. Supply a valid ActiveSyncContext with information
+     * about the sync.
+     */
+    public SyncInfo addActiveSync(SyncManager.ActiveSyncContext activeSyncContext) {
+        final SyncInfo syncInfo;
+        synchronized (mAuthorities) {
+            if (DEBUG) {
+                Log.v(TAG, "setActiveSync: account="
+                    + activeSyncContext.mSyncOperation.account
+                    + " auth=" + activeSyncContext.mSyncOperation.authority
+                    + " src=" + activeSyncContext.mSyncOperation.syncSource
+                    + " extras=" + activeSyncContext.mSyncOperation.extras);
+            }
+            AuthorityInfo authority = getOrCreateAuthorityLocked(
+                    activeSyncContext.mSyncOperation.account,
+                    activeSyncContext.mSyncOperation.userId,
+                    activeSyncContext.mSyncOperation.authority,
+                    -1 /* assign a new identifier if creating a new authority */,
+                    true /* write to storage if this results in a change */);
+            syncInfo = new SyncInfo(authority.ident,
+                    authority.account, authority.authority,
+                    activeSyncContext.mStartTime);
+            getCurrentSyncs(authority.userId).add(syncInfo);
+        }
+
+        reportActiveChange();
+        return syncInfo;
+    }
+
+    /**
+     * Called to indicate that a previously active sync is no longer active.
+     */
+    public void removeActiveSync(SyncInfo syncInfo, int userId) {
+        synchronized (mAuthorities) {
+            if (DEBUG) {
+                Log.v(TAG, "removeActiveSync: account=" + syncInfo.account
+                        + " user=" + userId
+                        + " auth=" + syncInfo.authority);
+            }
+            getCurrentSyncs(userId).remove(syncInfo);
+        }
+
+        reportActiveChange();
+    }
+
+    /**
+     * To allow others to send active change reports, to poke clients.
+     */
+    public void reportActiveChange() {
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE);
+    }
+
+    /**
+     * Note that sync has started for the given account and authority.
+     */
+    public long insertStartSyncEvent(Account accountName, int userId, int reason,
+            String authorityName, long now, int source, boolean initialization, Bundle extras) {
+        long id;
+        synchronized (mAuthorities) {
+            if (DEBUG) {
+                Log.v(TAG, "insertStartSyncEvent: account=" + accountName + "user=" + userId
+                    + " auth=" + authorityName + " source=" + source);
+            }
+            AuthorityInfo authority = getAuthorityLocked(accountName, userId, authorityName,
+                    "insertStartSyncEvent");
+            if (authority == null) {
+                return -1;
+            }
+            SyncHistoryItem item = new SyncHistoryItem();
+            item.initialization = initialization;
+            item.authorityId = authority.ident;
+            item.historyId = mNextHistoryId++;
+            if (mNextHistoryId < 0) mNextHistoryId = 0;
+            item.eventTime = now;
+            item.source = source;
+            item.reason = reason;
+            item.extras = extras;
+            item.event = EVENT_START;
+            mSyncHistory.add(0, item);
+            while (mSyncHistory.size() > MAX_HISTORY) {
+                mSyncHistory.remove(mSyncHistory.size()-1);
+            }
+            id = item.historyId;
+            if (DEBUG) Log.v(TAG, "returning historyId " + id);
+        }
+
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
+        return id;
+    }
+
+    public void stopSyncEvent(long historyId, long elapsedTime, String resultMessage,
+            long downstreamActivity, long upstreamActivity) {
+        synchronized (mAuthorities) {
+            if (DEBUG) {
+                Log.v(TAG, "stopSyncEvent: historyId=" + historyId);
+            }
+            SyncHistoryItem item = null;
+            int i = mSyncHistory.size();
+            while (i > 0) {
+                i--;
+                item = mSyncHistory.get(i);
+                if (item.historyId == historyId) {
+                    break;
+                }
+                item = null;
+            }
+
+            if (item == null) {
+                Log.w(TAG, "stopSyncEvent: no history for id " + historyId);
+                return;
+            }
+
+            item.elapsedTime = elapsedTime;
+            item.event = EVENT_STOP;
+            item.mesg = resultMessage;
+            item.downstreamActivity = downstreamActivity;
+            item.upstreamActivity = upstreamActivity;
+
+            SyncStatusInfo status = getOrCreateSyncStatusLocked(item.authorityId);
+
+            status.numSyncs++;
+            status.totalElapsedTime += elapsedTime;
+            switch (item.source) {
+                case SOURCE_LOCAL:
+                    status.numSourceLocal++;
+                    break;
+                case SOURCE_POLL:
+                    status.numSourcePoll++;
+                    break;
+                case SOURCE_USER:
+                    status.numSourceUser++;
+                    break;
+                case SOURCE_SERVER:
+                    status.numSourceServer++;
+                    break;
+                case SOURCE_PERIODIC:
+                    status.numSourcePeriodic++;
+                    break;
+            }
+
+            boolean writeStatisticsNow = false;
+            int day = getCurrentDayLocked();
+            if (mDayStats[0] == null) {
+                mDayStats[0] = new DayStats(day);
+            } else if (day != mDayStats[0].day) {
+                System.arraycopy(mDayStats, 0, mDayStats, 1, mDayStats.length-1);
+                mDayStats[0] = new DayStats(day);
+                writeStatisticsNow = true;
+            } else if (mDayStats[0] == null) {
+            }
+            final DayStats ds = mDayStats[0];
+
+            final long lastSyncTime = (item.eventTime + elapsedTime);
+            boolean writeStatusNow = false;
+            if (MESG_SUCCESS.equals(resultMessage)) {
+                // - if successful, update the successful columns
+                if (status.lastSuccessTime == 0 || status.lastFailureTime != 0) {
+                    writeStatusNow = true;
+                }
+                status.lastSuccessTime = lastSyncTime;
+                status.lastSuccessSource = item.source;
+                status.lastFailureTime = 0;
+                status.lastFailureSource = -1;
+                status.lastFailureMesg = null;
+                status.initialFailureTime = 0;
+                ds.successCount++;
+                ds.successTime += elapsedTime;
+            } else if (!MESG_CANCELED.equals(resultMessage)) {
+                if (status.lastFailureTime == 0) {
+                    writeStatusNow = true;
+                }
+                status.lastFailureTime = lastSyncTime;
+                status.lastFailureSource = item.source;
+                status.lastFailureMesg = resultMessage;
+                if (status.initialFailureTime == 0) {
+                    status.initialFailureTime = lastSyncTime;
+                }
+                ds.failureCount++;
+                ds.failureTime += elapsedTime;
+            }
+
+            if (writeStatusNow) {
+                writeStatusLocked();
+            } else if (!hasMessages(MSG_WRITE_STATUS)) {
+                sendMessageDelayed(obtainMessage(MSG_WRITE_STATUS),
+                        WRITE_STATUS_DELAY);
+            }
+            if (writeStatisticsNow) {
+                writeStatisticsLocked();
+            } else if (!hasMessages(MSG_WRITE_STATISTICS)) {
+                sendMessageDelayed(obtainMessage(MSG_WRITE_STATISTICS),
+                        WRITE_STATISTICS_DELAY);
+            }
+        }
+
+        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
+    }
+
+    /**
+     * Return a list of the currently active syncs. Note that the returned
+     * items are the real, live active sync objects, so be careful what you do
+     * with it.
+     */
+    private List<SyncInfo> getCurrentSyncs(int userId) {
+        synchronized (mAuthorities) {
+            return getCurrentSyncsLocked(userId);
+        }
+    }
+
+    /**
+     * @return a copy of the current syncs data structure. Will not return
+     * null.
+     */
+    public List<SyncInfo> getCurrentSyncsCopy(int userId) {
+        synchronized (mAuthorities) {
+            final List<SyncInfo> syncs = getCurrentSyncsLocked(userId);
+            final List<SyncInfo> syncsCopy = new ArrayList<SyncInfo>();
+            for (SyncInfo sync : syncs) {
+                syncsCopy.add(new SyncInfo(sync));
+            }
+            return syncsCopy;
+        }
+    }
+
+    private List<SyncInfo> getCurrentSyncsLocked(int userId) {
+        ArrayList<SyncInfo> syncs = mCurrentSyncs.get(userId);
+        if (syncs == null) {
+            syncs = new ArrayList<SyncInfo>();
+            mCurrentSyncs.put(userId, syncs);
+        }
+        return syncs;
+    }
+
+    /**
+     * Return an array of the current sync status for all authorities.  Note
+     * that the objects inside the array are the real, live status objects,
+     * so be careful what you do with them.
+     */
+    public ArrayList<SyncStatusInfo> getSyncStatus() {
+        synchronized (mAuthorities) {
+            final int N = mSyncStatus.size();
+            ArrayList<SyncStatusInfo> ops = new ArrayList<SyncStatusInfo>(N);
+            for (int i=0; i<N; i++) {
+                ops.add(mSyncStatus.valueAt(i));
+            }
+            return ops;
+        }
+    }
+
+    /**
+     * Return a copy of the specified authority with the corresponding sync status
+     */
+    public Pair<AuthorityInfo, SyncStatusInfo> getCopyOfAuthorityWithSyncStatus(
+            Account account, int userId, String authority) {
+        synchronized (mAuthorities) {
+            AuthorityInfo authorityInfo = getOrCreateAuthorityLocked(account, userId, authority,
+                    -1 /* assign a new identifier if creating a new authority */,
+                    true /* write to storage if this results in a change */);
+            return createCopyPairOfAuthorityWithSyncStatusLocked(authorityInfo);
+        }
+    }
+
+    /**
+     * Return a copy of all authorities with their corresponding sync status
+     */
+    public ArrayList<Pair<AuthorityInfo, SyncStatusInfo>> getCopyOfAllAuthoritiesWithSyncStatus() {
+        synchronized (mAuthorities) {
+            ArrayList<Pair<AuthorityInfo, SyncStatusInfo>> infos =
+                    new ArrayList<Pair<AuthorityInfo, SyncStatusInfo>>(mAuthorities.size());
+            for (int i = 0; i < mAuthorities.size(); i++) {
+                infos.add(createCopyPairOfAuthorityWithSyncStatusLocked(mAuthorities.valueAt(i)));
+            }
+            return infos;
+        }
+    }
+
+    /**
+     * Returns the status that matches the authority and account.
+     *
+     * @param account the account we want to check
+     * @param authority the authority whose row should be selected
+     * @return the SyncStatusInfo for the authority or null if none found.
+     */
+    public SyncStatusInfo getStatusByAccountAndAuthority(Account account, int userId,
+            String authority) {
+        if (account == null || authority == null) {
+          return null;
+        }
+        synchronized (mAuthorities) {
+            final int N = mSyncStatus.size();
+            for (int i=0; i<N; i++) {
+                SyncStatusInfo cur = mSyncStatus.valueAt(i);
+                AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
+
+                if (ainfo != null && ainfo.authority.equals(authority)
+                        && ainfo.userId == userId
+                        && account.equals(ainfo.account)) {
+                  return cur;
+                }
+            }
+            return null;
+        }
+    }
+
+    /**
+     * Return true if the pending status is true of any matching authorities.
+     */
+    public boolean isSyncPending(Account account, int userId, String authority) {
+        synchronized (mAuthorities) {
+            final int N = mSyncStatus.size();
+            for (int i=0; i<N; i++) {
+                SyncStatusInfo cur = mSyncStatus.valueAt(i);
+                AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
+                if (ainfo == null) {
+                    continue;
+                }
+                if (userId != ainfo.userId) {
+                    continue;
+                }
+                if (account != null && !ainfo.account.equals(account)) {
+                    continue;
+                }
+                if (ainfo.authority.equals(authority) && cur.pending) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    /**
+     * Return an array of the current sync status for all authorities.  Note
+     * that the objects inside the array are the real, live status objects,
+     * so be careful what you do with them.
+     */
+    public ArrayList<SyncHistoryItem> getSyncHistory() {
+        synchronized (mAuthorities) {
+            final int N = mSyncHistory.size();
+            ArrayList<SyncHistoryItem> items = new ArrayList<SyncHistoryItem>(N);
+            for (int i=0; i<N; i++) {
+                items.add(mSyncHistory.get(i));
+            }
+            return items;
+        }
+    }
+
+    /**
+     * Return an array of the current per-day statistics.  Note
+     * that the objects inside the array are the real, live status objects,
+     * so be careful what you do with them.
+     */
+    public DayStats[] getDayStatistics() {
+        synchronized (mAuthorities) {
+            DayStats[] ds = new DayStats[mDayStats.length];
+            System.arraycopy(mDayStats, 0, ds, 0, ds.length);
+            return ds;
+        }
+    }
+
+    private Pair<AuthorityInfo, SyncStatusInfo> createCopyPairOfAuthorityWithSyncStatusLocked(
+            AuthorityInfo authorityInfo) {
+        SyncStatusInfo syncStatusInfo = getOrCreateSyncStatusLocked(authorityInfo.ident);
+        return Pair.create(new AuthorityInfo(authorityInfo), new SyncStatusInfo(syncStatusInfo));
+    }
+
+    private int getCurrentDayLocked() {
+        mCal.setTimeInMillis(System.currentTimeMillis());
+        final int dayOfYear = mCal.get(Calendar.DAY_OF_YEAR);
+        if (mYear != mCal.get(Calendar.YEAR)) {
+            mYear = mCal.get(Calendar.YEAR);
+            mCal.clear();
+            mCal.set(Calendar.YEAR, mYear);
+            mYearInDays = (int)(mCal.getTimeInMillis()/86400000);
+        }
+        return dayOfYear + mYearInDays;
+    }
+
+    /**
+     * Retrieve an authority, returning null if one does not exist.
+     *
+     * @param accountName The name of the account for the authority.
+     * @param authorityName The name of the authority itself.
+     * @param tag If non-null, this will be used in a log message if the
+     * requested authority does not exist.
+     */
+    private AuthorityInfo getAuthorityLocked(Account accountName, int userId, String authorityName,
+            String tag) {
+        AccountAndUser au = new AccountAndUser(accountName, userId);
+        AccountInfo accountInfo = mAccounts.get(au);
+        if (accountInfo == null) {
+            if (tag != null) {
+                if (DEBUG) {
+                    Log.v(TAG, tag + ": unknown account " + au);
+                }
+            }
+            return null;
+        }
+        AuthorityInfo authority = accountInfo.authorities.get(authorityName);
+        if (authority == null) {
+            if (tag != null) {
+                if (DEBUG) {
+                    Log.v(TAG, tag + ": unknown authority " + authorityName);
+                }
+            }
+            return null;
+        }
+
+        return authority;
+    }
+
+    /**
+     * Retrieve an authority, returning null if one does not exist.
+     *
+     * @param service The service name used for this sync.
+     * @param userId The user for whom this sync is scheduled.
+     * @param tag If non-null, this will be used in a log message if the
+     * requested authority does not exist.
+     */
+    private AuthorityInfo getAuthorityLocked(ComponentName service, int userId, String tag) {
+        AuthorityInfo authority = mServices.get(service).get(userId);
+        if (authority == null) {
+            if (tag != null) {
+                if (DEBUG) {
+                    Log.v(TAG, tag + " No authority info found for " + service + " for user "
+                            + userId);
+                }
+            }
+            return null;
+        }
+        return authority;
+    }
+
+    /**
+     * @param cname identifier for the service.
+     * @param userId for the syncs corresponding to this authority.
+     * @param ident unique identifier for authority. -1 for none.
+     * @param doWrite if true, update the accounts.xml file on the disk.
+     * @return the authority that corresponds to the provided sync service, creating it if none
+     * exists.
+     */
+    private AuthorityInfo getOrCreateAuthorityLocked(ComponentName cname, int userId, int ident,
+            boolean doWrite) {
+        SparseArray<AuthorityInfo> aInfo = mServices.get(cname);
+        if (aInfo == null) {
+            aInfo = new SparseArray<AuthorityInfo>();
+            mServices.put(cname, aInfo);
+        }
+        AuthorityInfo authority = aInfo.get(userId);
+        if (authority == null) {
+            if (ident < 0) {
+                ident = mNextAuthorityId;
+                mNextAuthorityId++;
+                doWrite = true;
+            }
+            if (DEBUG) {
+                Log.v(TAG, "created a new AuthorityInfo for " + cname.getPackageName()
+                        + ", " + cname.getClassName()
+                        + ", user: " + userId);
+            }
+            authority = new AuthorityInfo(cname, userId, ident);
+            aInfo.put(userId, authority);
+            mAuthorities.put(ident, authority);
+            if (doWrite) {
+                writeAccountInfoLocked();
+            }
+        }
+        return authority;
+    }
+
+    private AuthorityInfo getOrCreateAuthorityLocked(Account accountName, int userId,
+            String authorityName, int ident, boolean doWrite) {
+        AccountAndUser au = new AccountAndUser(accountName, userId);
+        AccountInfo account = mAccounts.get(au);
+        if (account == null) {
+            account = new AccountInfo(au);
+            mAccounts.put(au, account);
+        }
+        AuthorityInfo authority = account.authorities.get(authorityName);
+        if (authority == null) {
+            if (ident < 0) {
+                ident = mNextAuthorityId;
+                mNextAuthorityId++;
+                doWrite = true;
+            }
+            if (DEBUG) {
+                Log.v(TAG, "created a new AuthorityInfo for " + accountName
+                        + ", user " + userId
+                        + ", provider " + authorityName);
+            }
+            authority = new AuthorityInfo(accountName, userId, authorityName, ident);
+            account.authorities.put(authorityName, authority);
+            mAuthorities.put(ident, authority);
+            if (doWrite) {
+                writeAccountInfoLocked();
+            }
+        }
+
+        return authority;
+    }
+
+    private void removeAuthorityLocked(Account account, int userId, String authorityName,
+            boolean doWrite) {
+        AccountInfo accountInfo = mAccounts.get(new AccountAndUser(account, userId));
+        if (accountInfo != null) {
+            final AuthorityInfo authorityInfo = accountInfo.authorities.remove(authorityName);
+            if (authorityInfo != null) {
+                mAuthorities.remove(authorityInfo.ident);
+                if (doWrite) {
+                    writeAccountInfoLocked();
+                }
+            }
+        }
+    }
+
+    /**
+     * Updates (in a synchronized way) the periodic sync time of the specified
+     * authority id and target periodic sync
+     */
+    public void setPeriodicSyncTime(
+            int authorityId, PeriodicSync targetPeriodicSync, long when) {
+        boolean found = false;
+        final AuthorityInfo authorityInfo;
+        synchronized (mAuthorities) {
+            authorityInfo = mAuthorities.get(authorityId);
+            for (int i = 0; i < authorityInfo.periodicSyncs.size(); i++) {
+                PeriodicSync periodicSync = authorityInfo.periodicSyncs.get(i);
+                if (targetPeriodicSync.equals(periodicSync)) {
+                    mSyncStatus.get(authorityId).setPeriodicSyncTime(i, when);
+                    found = true;
+                    break;
+                }
+            }
+        }
+        if (!found) {
+            Log.w(TAG, "Ignoring setPeriodicSyncTime request for a sync that does not exist. " +
+                    "Authority: " + authorityInfo.authority);
+        }
+    }
+
+    private SyncStatusInfo getOrCreateSyncStatusLocked(int authorityId) {
+        SyncStatusInfo status = mSyncStatus.get(authorityId);
+        if (status == null) {
+            status = new SyncStatusInfo(authorityId);
+            mSyncStatus.put(authorityId, status);
+        }
+        return status;
+    }
+
+    public void writeAllState() {
+        synchronized (mAuthorities) {
+            // Account info is always written so no need to do it here.
+
+            if (mNumPendingFinished > 0) {
+                // Only write these if they are out of date.
+                writePendingOperationsLocked();
+            }
+
+            // Just always write these...  they are likely out of date.
+            writeStatusLocked();
+            writeStatisticsLocked();
+        }
+    }
+
+    /**
+     * public for testing
+     */
+    public void clearAndReadState() {
+        synchronized (mAuthorities) {
+            mAuthorities.clear();
+            mAccounts.clear();
+            mServices.clear();
+            mPendingOperations.clear();
+            mSyncStatus.clear();
+            mSyncHistory.clear();
+
+            readAccountInfoLocked();
+            readStatusLocked();
+            readPendingOperationsLocked();
+            readStatisticsLocked();
+            readAndDeleteLegacyAccountInfoLocked();
+            writeAccountInfoLocked();
+            writeStatusLocked();
+            writePendingOperationsLocked();
+            writeStatisticsLocked();
+        }
+    }
+
+    /**
+     * Read all account information back in to the initial engine state.
+     */
+    private void readAccountInfoLocked() {
+        int highestAuthorityId = -1;
+        FileInputStream fis = null;
+        try {
+            fis = mAccountInfoFile.openRead();
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.v(TAG, "Reading " + mAccountInfoFile.getBaseFile());
+            }
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(fis, null);
+            int eventType = parser.getEventType();
+            while (eventType != XmlPullParser.START_TAG &&
+                    eventType != XmlPullParser.END_DOCUMENT) {
+                eventType = parser.next();
+            }
+            if (eventType == XmlPullParser.END_DOCUMENT) {
+                Log.i(TAG, "No initial accounts");
+                return;
+            }
+
+            String tagName = parser.getName();
+            if ("accounts".equals(tagName)) {
+                String listen = parser.getAttributeValue(null, XML_ATTR_LISTEN_FOR_TICKLES);
+                String versionString = parser.getAttributeValue(null, "version");
+                int version;
+                try {
+                    version = (versionString == null) ? 0 : Integer.parseInt(versionString);
+                } catch (NumberFormatException e) {
+                    version = 0;
+                }
+                String nextIdString = parser.getAttributeValue(null, XML_ATTR_NEXT_AUTHORITY_ID);
+                try {
+                    int id = (nextIdString == null) ? 0 : Integer.parseInt(nextIdString);
+                    mNextAuthorityId = Math.max(mNextAuthorityId, id);
+                } catch (NumberFormatException e) {
+                    // don't care
+                }
+                String offsetString = parser.getAttributeValue(null, XML_ATTR_SYNC_RANDOM_OFFSET);
+                try {
+                    mSyncRandomOffset = (offsetString == null) ? 0 : Integer.parseInt(offsetString);
+                } catch (NumberFormatException e) {
+                    mSyncRandomOffset = 0;
+                }
+                if (mSyncRandomOffset == 0) {
+                    Random random = new Random(System.currentTimeMillis());
+                    mSyncRandomOffset = random.nextInt(86400);
+                }
+                mMasterSyncAutomatically.put(0, listen == null || Boolean.parseBoolean(listen));
+                eventType = parser.next();
+                AuthorityInfo authority = null;
+                PeriodicSync periodicSync = null;
+                do {
+                    if (eventType == XmlPullParser.START_TAG) {
+                        tagName = parser.getName();
+                        if (parser.getDepth() == 2) {
+                            if ("authority".equals(tagName)) {
+                                authority = parseAuthority(parser, version);
+                                periodicSync = null;
+                                if (authority.ident > highestAuthorityId) {
+                                    highestAuthorityId = authority.ident;
+                                }
+                            } else if (XML_TAG_LISTEN_FOR_TICKLES.equals(tagName)) {
+                                parseListenForTickles(parser);
+                            }
+                        } else if (parser.getDepth() == 3) {
+                            if ("periodicSync".equals(tagName) && authority != null) {
+                                periodicSync = parsePeriodicSync(parser, authority);
+                            }
+                        } else if (parser.getDepth() == 4 && periodicSync != null) {
+                            if ("extra".equals(tagName)) {
+                                parseExtra(parser, periodicSync.extras);
+                            }
+                        }
+                    }
+                    eventType = parser.next();
+                } while (eventType != XmlPullParser.END_DOCUMENT);
+            }
+        } catch (XmlPullParserException e) {
+            Log.w(TAG, "Error reading accounts", e);
+            return;
+        } catch (java.io.IOException e) {
+            if (fis == null) Log.i(TAG, "No initial accounts");
+            else Log.w(TAG, "Error reading accounts", e);
+            return;
+        } finally {
+            mNextAuthorityId = Math.max(highestAuthorityId + 1, mNextAuthorityId);
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (java.io.IOException e1) {
+                }
+            }
+        }
+
+        maybeMigrateSettingsForRenamedAuthorities();
+    }
+
+    /**
+     * Ensure the old pending.bin is deleted, as it has been changed to pending.xml.
+     * pending.xml was used starting in KLP.
+     * @param syncDir directory where the sync files are located.
+     */
+    private void maybeDeleteLegacyPendingInfoLocked(File syncDir) {
+        File file = new File(syncDir, "pending.bin");
+        if (!file.exists()) {
+            return;
+        } else {
+            file.delete();
+        }
+    }
+
+    /**
+     * some authority names have changed. copy over their settings and delete the old ones
+     * @return true if a change was made
+     */
+    private boolean maybeMigrateSettingsForRenamedAuthorities() {
+        boolean writeNeeded = false;
+
+        ArrayList<AuthorityInfo> authoritiesToRemove = new ArrayList<AuthorityInfo>();
+        final int N = mAuthorities.size();
+        for (int i=0; i<N; i++) {
+            AuthorityInfo authority = mAuthorities.valueAt(i);
+            // skip this authority if it isn't one of the renamed ones
+            final String newAuthorityName = sAuthorityRenames.get(authority.authority);
+            if (newAuthorityName == null) {
+                continue;
+            }
+
+            // remember this authority so we can remove it later. we can't remove it
+            // now without messing up this loop iteration
+            authoritiesToRemove.add(authority);
+
+            // this authority isn't enabled, no need to copy it to the new authority name since
+            // the default is "disabled"
+            if (!authority.enabled) {
+                continue;
+            }
+
+            // if we already have a record of this new authority then don't copy over the settings
+            if (getAuthorityLocked(authority.account, authority.userId, newAuthorityName, "cleanup")
+                    != null) {
+                continue;
+            }
+
+            AuthorityInfo newAuthority = getOrCreateAuthorityLocked(authority.account,
+                    authority.userId, newAuthorityName, -1 /* ident */, false /* doWrite */);
+            newAuthority.enabled = true;
+            writeNeeded = true;
+        }
+
+        for (AuthorityInfo authorityInfo : authoritiesToRemove) {
+            removeAuthorityLocked(authorityInfo.account, authorityInfo.userId,
+                    authorityInfo.authority, false /* doWrite */);
+            writeNeeded = true;
+        }
+
+        return writeNeeded;
+    }
+
+    private void parseListenForTickles(XmlPullParser parser) {
+        String user = parser.getAttributeValue(null, XML_ATTR_USER);
+        int userId = 0;
+        try {
+            userId = Integer.parseInt(user);
+        } catch (NumberFormatException e) {
+            Log.e(TAG, "error parsing the user for listen-for-tickles", e);
+        } catch (NullPointerException e) {
+            Log.e(TAG, "the user in listen-for-tickles is null", e);
+        }
+        String enabled = parser.getAttributeValue(null, XML_ATTR_ENABLED);
+        boolean listen = enabled == null || Boolean.parseBoolean(enabled);
+        mMasterSyncAutomatically.put(userId, listen);
+    }
+
+    private AuthorityInfo parseAuthority(XmlPullParser parser, int version) {
+        AuthorityInfo authority = null;
+        int id = -1;
+        try {
+            id = Integer.parseInt(parser.getAttributeValue(null, "id"));
+        } catch (NumberFormatException e) {
+            Log.e(TAG, "error parsing the id of the authority", e);
+        } catch (NullPointerException e) {
+            Log.e(TAG, "the id of the authority is null", e);
+        }
+        if (id >= 0) {
+            String authorityName = parser.getAttributeValue(null, "authority");
+            String enabled = parser.getAttributeValue(null, XML_ATTR_ENABLED);
+            String syncable = parser.getAttributeValue(null, "syncable");
+            String accountName = parser.getAttributeValue(null, "account");
+            String accountType = parser.getAttributeValue(null, "type");
+            String user = parser.getAttributeValue(null, XML_ATTR_USER);
+            String packageName = parser.getAttributeValue(null, "package");
+            String className = parser.getAttributeValue(null, "class");
+            int userId = user == null ? 0 : Integer.parseInt(user);
+            if (accountType == null) {
+                accountType = "com.google";
+                syncable = "unknown";
+            }
+            authority = mAuthorities.get(id);
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.v(TAG, "Adding authority: account="
+                        + accountName + " auth=" + authorityName
+                        + " user=" + userId
+                        + " enabled=" + enabled
+                        + " syncable=" + syncable);
+            }
+            if (authority == null) {
+                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                    Log.v(TAG, "Creating entry");
+                }
+                if (accountName != null && accountType != null) {
+                    authority = getOrCreateAuthorityLocked(
+                            new Account(accountName, accountType), userId, authorityName, id,
+                                false);
+                } else {
+                    authority = getOrCreateAuthorityLocked(
+                            new ComponentName(packageName, className), userId, id, false);
+                }
+                // If the version is 0 then we are upgrading from a file format that did not
+                // know about periodic syncs. In that case don't clear the list since we
+                // want the default, which is a daily periodic sync.
+                // Otherwise clear out this default list since we will populate it later with
+                // the periodic sync descriptions that are read from the configuration file.
+                if (version > 0) {
+                    authority.periodicSyncs.clear();
+                }
+            }
+            if (authority != null) {
+                authority.enabled = enabled == null || Boolean.parseBoolean(enabled);
+                if ("unknown".equals(syncable)) {
+                    authority.syncable = -1;
+                } else {
+                    authority.syncable =
+                            (syncable == null || Boolean.parseBoolean(syncable)) ? 1 : 0;
+                }
+            } else {
+                Log.w(TAG, "Failure adding authority: account="
+                        + accountName + " auth=" + authorityName
+                        + " enabled=" + enabled
+                        + " syncable=" + syncable);
+            }
+        }
+        return authority;
+    }
+
+    /**
+     * Parse a periodic sync from accounts.xml. Sets the bundle to be empty.
+     */
+    private PeriodicSync parsePeriodicSync(XmlPullParser parser, AuthorityInfo authority) {
+        Bundle extras = new Bundle(); // Gets filled in later.
+        String periodValue = parser.getAttributeValue(null, "period");
+        String flexValue = parser.getAttributeValue(null, "flex");
+        final long period;
+        long flextime;
+        try {
+            period = Long.parseLong(periodValue);
+        } catch (NumberFormatException e) {
+            Log.e(TAG, "error parsing the period of a periodic sync", e);
+            return null;
+        } catch (NullPointerException e) {
+            Log.e(TAG, "the period of a periodic sync is null", e);
+            return null;
+        }
+        try {
+            flextime = Long.parseLong(flexValue);
+        } catch (NumberFormatException e) {
+            Log.e(TAG, "Error formatting value parsed for periodic sync flex: " + flexValue);
+            flextime = calculateDefaultFlexTime(period);
+        } catch (NullPointerException expected) {
+            flextime = calculateDefaultFlexTime(period);
+            Log.d(TAG, "No flex time specified for this sync, using a default. period: "
+            + period + " flex: " + flextime);
+        }
+        final PeriodicSync periodicSync =
+                new PeriodicSync(authority.account, authority.authority, extras,
+                        period, flextime);
+        authority.periodicSyncs.add(periodicSync);
+        return periodicSync;
+    }
+
+    private void parseExtra(XmlPullParser parser, Bundle extras) {
+        String name = parser.getAttributeValue(null, "name");
+        String type = parser.getAttributeValue(null, "type");
+        String value1 = parser.getAttributeValue(null, "value1");
+        String value2 = parser.getAttributeValue(null, "value2");
+
+        try {
+            if ("long".equals(type)) {
+                extras.putLong(name, Long.parseLong(value1));
+            } else if ("integer".equals(type)) {
+                extras.putInt(name, Integer.parseInt(value1));
+            } else if ("double".equals(type)) {
+                extras.putDouble(name, Double.parseDouble(value1));
+            } else if ("float".equals(type)) {
+                extras.putFloat(name, Float.parseFloat(value1));
+            } else if ("boolean".equals(type)) {
+                extras.putBoolean(name, Boolean.parseBoolean(value1));
+            } else if ("string".equals(type)) {
+                extras.putString(name, value1);
+            } else if ("account".equals(type)) {
+                extras.putParcelable(name, new Account(value1, value2));
+            }
+        } catch (NumberFormatException e) {
+            Log.e(TAG, "error parsing bundle value", e);
+        } catch (NullPointerException e) {
+            Log.e(TAG, "error parsing bundle value", e);
+        }
+    }
+
+    /**
+     * Write all account information to the account file.
+     */
+    private void writeAccountInfoLocked() {
+        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+            Log.v(TAG, "Writing new " + mAccountInfoFile.getBaseFile());
+        }
+        FileOutputStream fos = null;
+
+        try {
+            fos = mAccountInfoFile.startWrite();
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            out.startDocument(null, true);
+            out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+
+            out.startTag(null, "accounts");
+            out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
+            out.attribute(null, XML_ATTR_NEXT_AUTHORITY_ID, Integer.toString(mNextAuthorityId));
+            out.attribute(null, XML_ATTR_SYNC_RANDOM_OFFSET, Integer.toString(mSyncRandomOffset));
+
+            // Write the Sync Automatically flags for each user
+            final int M = mMasterSyncAutomatically.size();
+            for (int m = 0; m < M; m++) {
+                int userId = mMasterSyncAutomatically.keyAt(m);
+                Boolean listen = mMasterSyncAutomatically.valueAt(m);
+                out.startTag(null, XML_TAG_LISTEN_FOR_TICKLES);
+                out.attribute(null, XML_ATTR_USER, Integer.toString(userId));
+                out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(listen));
+                out.endTag(null, XML_TAG_LISTEN_FOR_TICKLES);
+            }
+
+            final int N = mAuthorities.size();
+            for (int i = 0; i < N; i++) {
+                AuthorityInfo authority = mAuthorities.valueAt(i);
+                out.startTag(null, "authority");
+                out.attribute(null, "id", Integer.toString(authority.ident));
+                out.attribute(null, XML_ATTR_USER, Integer.toString(authority.userId));
+                out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(authority.enabled));
+                if (authority.service == null) {
+                    out.attribute(null, "account", authority.account.name);
+                    out.attribute(null, "type", authority.account.type);
+                    out.attribute(null, "authority", authority.authority);
+                } else {
+                    out.attribute(null, "package", authority.service.getPackageName());
+                    out.attribute(null, "class", authority.service.getClassName());
+                }
+                if (authority.syncable < 0) {
+                    out.attribute(null, "syncable", "unknown");
+                } else {
+                    out.attribute(null, "syncable", Boolean.toString(authority.syncable != 0));
+                }
+                for (PeriodicSync periodicSync : authority.periodicSyncs) {
+                    out.startTag(null, "periodicSync");
+                    out.attribute(null, "period", Long.toString(periodicSync.period));
+                    out.attribute(null, "flex", Long.toString(periodicSync.flexTime));
+                    final Bundle extras = periodicSync.extras;
+                    extrasToXml(out, extras);
+                    out.endTag(null, "periodicSync");
+                }
+                out.endTag(null, "authority");
+            }
+            out.endTag(null, "accounts");
+            out.endDocument();
+            mAccountInfoFile.finishWrite(fos);
+        } catch (java.io.IOException e1) {
+            Log.w(TAG, "Error writing accounts", e1);
+            if (fos != null) {
+                mAccountInfoFile.failWrite(fos);
+            }
+        }
+    }
+
+    static int getIntColumn(Cursor c, String name) {
+        return c.getInt(c.getColumnIndex(name));
+    }
+
+    static long getLongColumn(Cursor c, String name) {
+        return c.getLong(c.getColumnIndex(name));
+    }
+
+    /**
+     * Load sync engine state from the old syncmanager database, and then
+     * erase it.  Note that we don't deal with pending operations, active
+     * sync, or history.
+     */
+    private void readAndDeleteLegacyAccountInfoLocked() {
+        // Look for old database to initialize from.
+        File file = mContext.getDatabasePath("syncmanager.db");
+        if (!file.exists()) {
+            return;
+        }
+        String path = file.getPath();
+        SQLiteDatabase db = null;
+        try {
+            db = SQLiteDatabase.openDatabase(path, null,
+                    SQLiteDatabase.OPEN_READONLY);
+        } catch (SQLiteException e) {
+        }
+
+        if (db != null) {
+            final boolean hasType = db.getVersion() >= 11;
+
+            // Copy in all of the status information, as well as accounts.
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.v(TAG, "Reading legacy sync accounts db");
+            }
+            SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+            qb.setTables("stats, status");
+            HashMap<String,String> map = new HashMap<String,String>();
+            map.put("_id", "status._id as _id");
+            map.put("account", "stats.account as account");
+            if (hasType) {
+                map.put("account_type", "stats.account_type as account_type");
+            }
+            map.put("authority", "stats.authority as authority");
+            map.put("totalElapsedTime", "totalElapsedTime");
+            map.put("numSyncs", "numSyncs");
+            map.put("numSourceLocal", "numSourceLocal");
+            map.put("numSourcePoll", "numSourcePoll");
+            map.put("numSourceServer", "numSourceServer");
+            map.put("numSourceUser", "numSourceUser");
+            map.put("lastSuccessSource", "lastSuccessSource");
+            map.put("lastSuccessTime", "lastSuccessTime");
+            map.put("lastFailureSource", "lastFailureSource");
+            map.put("lastFailureTime", "lastFailureTime");
+            map.put("lastFailureMesg", "lastFailureMesg");
+            map.put("pending", "pending");
+            qb.setProjectionMap(map);
+            qb.appendWhere("stats._id = status.stats_id");
+            Cursor c = qb.query(db, null, null, null, null, null, null);
+            while (c.moveToNext()) {
+                String accountName = c.getString(c.getColumnIndex("account"));
+                String accountType = hasType
+                        ? c.getString(c.getColumnIndex("account_type")) : null;
+                if (accountType == null) {
+                    accountType = "com.google";
+                }
+                String authorityName = c.getString(c.getColumnIndex("authority"));
+                AuthorityInfo authority = this.getOrCreateAuthorityLocked(
+                        new Account(accountName, accountType), 0 /* legacy is single-user */,
+                        authorityName, -1, false);
+                if (authority != null) {
+                    int i = mSyncStatus.size();
+                    boolean found = false;
+                    SyncStatusInfo st = null;
+                    while (i > 0) {
+                        i--;
+                        st = mSyncStatus.valueAt(i);
+                        if (st.authorityId == authority.ident) {
+                            found = true;
+                            break;
+                        }
+                    }
+                    if (!found) {
+                        st = new SyncStatusInfo(authority.ident);
+                        mSyncStatus.put(authority.ident, st);
+                    }
+                    st.totalElapsedTime = getLongColumn(c, "totalElapsedTime");
+                    st.numSyncs = getIntColumn(c, "numSyncs");
+                    st.numSourceLocal = getIntColumn(c, "numSourceLocal");
+                    st.numSourcePoll = getIntColumn(c, "numSourcePoll");
+                    st.numSourceServer = getIntColumn(c, "numSourceServer");
+                    st.numSourceUser = getIntColumn(c, "numSourceUser");
+                    st.numSourcePeriodic = 0;
+                    st.lastSuccessSource = getIntColumn(c, "lastSuccessSource");
+                    st.lastSuccessTime = getLongColumn(c, "lastSuccessTime");
+                    st.lastFailureSource = getIntColumn(c, "lastFailureSource");
+                    st.lastFailureTime = getLongColumn(c, "lastFailureTime");
+                    st.lastFailureMesg = c.getString(c.getColumnIndex("lastFailureMesg"));
+                    st.pending = getIntColumn(c, "pending") != 0;
+                }
+            }
+
+            c.close();
+
+            // Retrieve the settings.
+            qb = new SQLiteQueryBuilder();
+            qb.setTables("settings");
+            c = qb.query(db, null, null, null, null, null, null);
+            while (c.moveToNext()) {
+                String name = c.getString(c.getColumnIndex("name"));
+                String value = c.getString(c.getColumnIndex("value"));
+                if (name == null) continue;
+                if (name.equals("listen_for_tickles")) {
+                    setMasterSyncAutomatically(value == null || Boolean.parseBoolean(value), 0);
+                } else if (name.startsWith("sync_provider_")) {
+                    String provider = name.substring("sync_provider_".length(),
+                            name.length());
+                    int i = mAuthorities.size();
+                    while (i > 0) {
+                        i--;
+                        AuthorityInfo authority = mAuthorities.valueAt(i);
+                        if (authority.authority.equals(provider)) {
+                            authority.enabled = value == null || Boolean.parseBoolean(value);
+                            authority.syncable = 1;
+                        }
+                    }
+                }
+            }
+
+            c.close();
+
+            db.close();
+
+            (new File(path)).delete();
+        }
+    }
+
+    public static final int STATUS_FILE_END = 0;
+    public static final int STATUS_FILE_ITEM = 100;
+
+    /**
+     * Read all sync status back in to the initial engine state.
+     */
+    private void readStatusLocked() {
+        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+            Log.v(TAG, "Reading " + mStatusFile.getBaseFile());
+        }
+        try {
+            byte[] data = mStatusFile.readFully();
+            Parcel in = Parcel.obtain();
+            in.unmarshall(data, 0, data.length);
+            in.setDataPosition(0);
+            int token;
+            while ((token=in.readInt()) != STATUS_FILE_END) {
+                if (token == STATUS_FILE_ITEM) {
+                    SyncStatusInfo status = new SyncStatusInfo(in);
+                    if (mAuthorities.indexOfKey(status.authorityId) >= 0) {
+                        status.pending = false;
+                        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                            Log.v(TAG, "Adding status for id "
+                                    + status.authorityId);
+                        }
+                        mSyncStatus.put(status.authorityId, status);
+                    }
+                } else {
+                    // Ooops.
+                    Log.w(TAG, "Unknown status token: " + token);
+                    break;
+                }
+            }
+        } catch (java.io.IOException e) {
+            Log.i(TAG, "No initial status");
+        }
+    }
+
+    /**
+     * Write all sync status to the sync status file.
+     */
+    private void writeStatusLocked() {
+        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+            Log.v(TAG, "Writing new " + mStatusFile.getBaseFile());
+        }
+
+        // The file is being written, so we don't need to have a scheduled
+        // write until the next change.
+        removeMessages(MSG_WRITE_STATUS);
+
+        FileOutputStream fos = null;
+        try {
+            fos = mStatusFile.startWrite();
+            Parcel out = Parcel.obtain();
+            final int N = mSyncStatus.size();
+            for (int i=0; i<N; i++) {
+                SyncStatusInfo status = mSyncStatus.valueAt(i);
+                out.writeInt(STATUS_FILE_ITEM);
+                status.writeToParcel(out, 0);
+            }
+            out.writeInt(STATUS_FILE_END);
+            fos.write(out.marshall());
+            out.recycle();
+
+            mStatusFile.finishWrite(fos);
+        } catch (java.io.IOException e1) {
+            Log.w(TAG, "Error writing status", e1);
+            if (fos != null) {
+                mStatusFile.failWrite(fos);
+            }
+        }
+    }
+
+    public static final int PENDING_OPERATION_VERSION = 3;
+
+    /** Read all pending operations back in to the initial engine state. */
+    private void readPendingOperationsLocked() {
+        FileInputStream fis = null;
+        if (!mPendingFile.getBaseFile().exists()) {
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.v(TAG_FILE, "No pending operation file.");
+                return;
+            }
+        }
+        try {
+            fis = mPendingFile.openRead();
+            XmlPullParser parser;
+            parser = Xml.newPullParser();
+            parser.setInput(fis, null);
+
+            int eventType = parser.getEventType();
+            while (eventType != XmlPullParser.START_TAG &&
+                    eventType != XmlPullParser.END_DOCUMENT) {
+                eventType = parser.next();
+            }
+            if (eventType == XmlPullParser.END_DOCUMENT) return; // Nothing to read.
+
+            String tagName = parser.getName();
+            do {
+                PendingOperation pop = null;
+                if (eventType == XmlPullParser.START_TAG) {
+                    try {
+                        tagName = parser.getName();
+                        if (parser.getDepth() == 1 && "op".equals(tagName)) {
+                            // Verify version.
+                            String versionString =
+                                    parser.getAttributeValue(null, XML_ATTR_VERSION);
+                            if (versionString == null ||
+                                    Integer.parseInt(versionString) != PENDING_OPERATION_VERSION) {
+                                Log.w(TAG, "Unknown pending operation version " + versionString);
+                                throw new java.io.IOException("Unknown version.");
+                            }
+                            int authorityId = Integer.valueOf(parser.getAttributeValue(
+                                    null, XML_ATTR_AUTHORITYID));
+                            boolean expedited = Boolean.valueOf(parser.getAttributeValue(
+                                    null, XML_ATTR_EXPEDITED));
+                            int syncSource = Integer.valueOf(parser.getAttributeValue(
+                                    null, XML_ATTR_SOURCE));
+                            int reason = Integer.valueOf(parser.getAttributeValue(
+                                    null, XML_ATTR_REASON));
+                            AuthorityInfo authority = mAuthorities.get(authorityId);
+                            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                                Log.v(TAG_FILE, authorityId + " " + expedited + " " + syncSource + " "
+                                        + reason);
+                            }
+                            if (authority != null) {
+                                pop = new PendingOperation(
+                                        authority.account, authority.userId, reason,
+                                        syncSource, authority.authority, new Bundle(),
+                                        expedited);
+                                pop.flatExtras = null; // No longer used.
+                                mPendingOperations.add(pop);
+                                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                                    Log.v(TAG_FILE, "Adding pending op: "
+                                            + pop.authority
+                                            + " src=" + pop.syncSource
+                                            + " reason=" + pop.reason
+                                            + " expedited=" + pop.expedited);
+                                }
+                            } else {
+                                // Skip non-existent authority.
+                                pop = null;
+                                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                                    Log.v(TAG_FILE, "No authority found for " + authorityId
+                                            + ", skipping");
+                                }
+                            }
+                        } else if (parser.getDepth() == 2 &&
+                                pop != null &&
+                                "extra".equals(tagName)) {
+                            parseExtra(parser, pop.extras);
+                        }
+                    } catch (NumberFormatException e) {
+                        Log.d(TAG, "Invalid data in xml file.", e);
+                    }
+                }
+                eventType = parser.next();
+            } while(eventType != XmlPullParser.END_DOCUMENT);
+        } catch (java.io.IOException e) {
+            Log.w(TAG_FILE, "Error reading pending data.", e);
+        } catch (XmlPullParserException e) {
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.w(TAG_FILE, "Error parsing pending ops xml.", e);
+            }
+        } finally {
+            if (fis != null) {
+                try {
+                    fis.close();
+                } catch (java.io.IOException e1) {}
+            }
+        }
+    }
+
+    private static final String XML_ATTR_AUTHORITYID = "authority_id";
+    private static final String XML_ATTR_SOURCE = "source";
+    private static final String XML_ATTR_EXPEDITED = "expedited";
+    private static final String XML_ATTR_REASON = "reason";
+    private static final String XML_ATTR_VERSION = "version";
+
+    /**
+     * Write all currently pending ops to the pending ops file.
+     */
+    private void writePendingOperationsLocked() {
+        final int N = mPendingOperations.size();
+        FileOutputStream fos = null;
+        try {
+            if (N == 0) {
+                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                    Log.v(TAG_FILE, "Truncating " + mPendingFile.getBaseFile());
+                }
+                mPendingFile.truncate();
+                return;
+            }
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.v(TAG_FILE, "Writing new " + mPendingFile.getBaseFile());
+            }
+            fos = mPendingFile.startWrite();
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+
+            for (int i = 0; i < N; i++) {
+                PendingOperation pop = mPendingOperations.get(i);
+                writePendingOperationLocked(pop, out);
+            }
+            out.endDocument();
+            mPendingFile.finishWrite(fos);
+        } catch (java.io.IOException e1) {
+            Log.w(TAG, "Error writing pending operations", e1);
+            if (fos != null) {
+                mPendingFile.failWrite(fos);
+            }
+        }
+    }
+
+    /** Write all currently pending ops to the pending ops file. */
+     private void writePendingOperationLocked(PendingOperation pop, XmlSerializer out)
+             throws IOException {
+         // Pending operation.
+         out.startTag(null, "op");
+
+         out.attribute(null, XML_ATTR_VERSION, Integer.toString(PENDING_OPERATION_VERSION));
+         out.attribute(null, XML_ATTR_AUTHORITYID, Integer.toString(pop.authorityId));
+         out.attribute(null, XML_ATTR_SOURCE, Integer.toString(pop.syncSource));
+         out.attribute(null, XML_ATTR_EXPEDITED, Boolean.toString(pop.expedited));
+         out.attribute(null, XML_ATTR_REASON, Integer.toString(pop.reason));
+         extrasToXml(out, pop.extras);
+
+         out.endTag(null, "op");
+     }
+
+    /**
+     * Append the given operation to the pending ops file; if unable to,
+     * write all pending ops.
+     */
+    private void appendPendingOperationLocked(PendingOperation op) {
+        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+            Log.v(TAG, "Appending to " + mPendingFile.getBaseFile());
+        }
+        FileOutputStream fos = null;
+        try {
+            fos = mPendingFile.openAppend();
+        } catch (java.io.IOException e) {
+            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+                Log.v(TAG, "Failed append; writing full file");
+            }
+            writePendingOperationsLocked();
+            return;
+        }
+
+        try {
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            writePendingOperationLocked(op, out);
+            out.endDocument();
+            mPendingFile.finishWrite(fos);
+        } catch (java.io.IOException e1) {
+            Log.w(TAG, "Error writing appending operation", e1);
+            mPendingFile.failWrite(fos);
+        } finally {
+            try {
+                fos.close();
+            } catch (IOException e) {}
+        }
+    }
+
+    static private byte[] flattenBundle(Bundle bundle) {
+        byte[] flatData = null;
+        Parcel parcel = Parcel.obtain();
+        try {
+            bundle.writeToParcel(parcel, 0);
+            flatData = parcel.marshall();
+        } finally {
+            parcel.recycle();
+        }
+        return flatData;
+    }
+
+    static private Bundle unflattenBundle(byte[] flatData) {
+        Bundle bundle;
+        Parcel parcel = Parcel.obtain();
+        try {
+            parcel.unmarshall(flatData, 0, flatData.length);
+            parcel.setDataPosition(0);
+            bundle = parcel.readBundle();
+        } catch (RuntimeException e) {
+            // A RuntimeException is thrown if we were unable to parse the parcel.
+            // Create an empty parcel in this case.
+            bundle = new Bundle();
+        } finally {
+            parcel.recycle();
+        }
+        return bundle;
+    }
+
+    private void extrasToXml(XmlSerializer out, Bundle extras) throws java.io.IOException {
+        for (String key : extras.keySet()) {
+            out.startTag(null, "extra");
+            out.attribute(null, "name", key);
+            final Object value = extras.get(key);
+            if (value instanceof Long) {
+                out.attribute(null, "type", "long");
+                out.attribute(null, "value1", value.toString());
+            } else if (value instanceof Integer) {
+                out.attribute(null, "type", "integer");
+                out.attribute(null, "value1", value.toString());
+            } else if (value instanceof Boolean) {
+                out.attribute(null, "type", "boolean");
+                out.attribute(null, "value1", value.toString());
+            } else if (value instanceof Float) {
+                out.attribute(null, "type", "float");
+                out.attribute(null, "value1", value.toString());
+            } else if (value instanceof Double) {
+                out.attribute(null, "type", "double");
+                out.attribute(null, "value1", value.toString());
+            } else if (value instanceof String) {
+                out.attribute(null, "type", "string");
+                out.attribute(null, "value1", value.toString());
+            } else if (value instanceof Account) {
+                out.attribute(null, "type", "account");
+                out.attribute(null, "value1", ((Account)value).name);
+                out.attribute(null, "value2", ((Account)value).type);
+            }
+            out.endTag(null, "extra");
+        }
+    }
+
+    private void requestSync(Account account, int userId, int reason, String authority,
+            Bundle extras) {
+        // If this is happening in the system process, then call the syncrequest listener
+        // to make a request back to the SyncManager directly.
+        // If this is probably a test instance, then call back through the ContentResolver
+        // which will know which userId to apply based on the Binder id.
+        if (android.os.Process.myUid() == android.os.Process.SYSTEM_UID
+                && mSyncRequestListener != null) {
+            mSyncRequestListener.onSyncRequest(account, userId, reason, authority, extras);
+        } else {
+            ContentResolver.requestSync(account, authority, extras);
+        }
+    }
+
+    public static final int STATISTICS_FILE_END = 0;
+    public static final int STATISTICS_FILE_ITEM_OLD = 100;
+    public static final int STATISTICS_FILE_ITEM = 101;
+
+    /**
+     * Read all sync statistics back in to the initial engine state.
+     */
+    private void readStatisticsLocked() {
+        try {
+            byte[] data = mStatisticsFile.readFully();
+            Parcel in = Parcel.obtain();
+            in.unmarshall(data, 0, data.length);
+            in.setDataPosition(0);
+            int token;
+            int index = 0;
+            while ((token=in.readInt()) != STATISTICS_FILE_END) {
+                if (token == STATISTICS_FILE_ITEM
+                        || token == STATISTICS_FILE_ITEM_OLD) {
+                    int day = in.readInt();
+                    if (token == STATISTICS_FILE_ITEM_OLD) {
+                        day = day - 2009 + 14245;  // Magic!
+                    }
+                    DayStats ds = new DayStats(day);
+                    ds.successCount = in.readInt();
+                    ds.successTime = in.readLong();
+                    ds.failureCount = in.readInt();
+                    ds.failureTime = in.readLong();
+                    if (index < mDayStats.length) {
+                        mDayStats[index] = ds;
+                        index++;
+                    }
+                } else {
+                    // Ooops.
+                    Log.w(TAG, "Unknown stats token: " + token);
+                    break;
+                }
+            }
+        } catch (java.io.IOException e) {
+            Log.i(TAG, "No initial statistics");
+        }
+    }
+
+    /**
+     * Write all sync statistics to the sync status file.
+     */
+    private void writeStatisticsLocked() {
+        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
+            Log.v(TAG, "Writing new " + mStatisticsFile.getBaseFile());
+        }
+
+        // The file is being written, so we don't need to have a scheduled
+        // write until the next change.
+        removeMessages(MSG_WRITE_STATISTICS);
+
+        FileOutputStream fos = null;
+        try {
+            fos = mStatisticsFile.startWrite();
+            Parcel out = Parcel.obtain();
+            final int N = mDayStats.length;
+            for (int i=0; i<N; i++) {
+                DayStats ds = mDayStats[i];
+                if (ds == null) {
+                    break;
+                }
+                out.writeInt(STATISTICS_FILE_ITEM);
+                out.writeInt(ds.day);
+                out.writeInt(ds.successCount);
+                out.writeLong(ds.successTime);
+                out.writeInt(ds.failureCount);
+                out.writeLong(ds.failureTime);
+            }
+            out.writeInt(STATISTICS_FILE_END);
+            fos.write(out.marshall());
+            out.recycle();
+
+            mStatisticsFile.finishWrite(fos);
+        } catch (java.io.IOException e1) {
+            Log.w(TAG, "Error writing stats", e1);
+            if (fos != null) {
+                mStatisticsFile.failWrite(fos);
+            }
+        }
+    }
+
+    /**
+     * Dump state of PendingOperations.
+     */
+    public void dumpPendingOperations(StringBuilder sb) {
+        sb.append("Pending Ops: ").append(mPendingOperations.size()).append(" operation(s)\n");
+        for (PendingOperation pop : mPendingOperations) {
+            sb.append("(" + pop.account)
+                .append(", u" + pop.userId)
+                .append(", " + pop.authority)
+                .append(", " + pop.extras)
+                .append(")\n");
+        }
+    }
+}
diff --git a/services/java/com/android/server/display/DisplayAdapter.java b/services/core/java/com/android/server/display/DisplayAdapter.java
similarity index 100%
rename from services/java/com/android/server/display/DisplayAdapter.java
rename to services/core/java/com/android/server/display/DisplayAdapter.java
diff --git a/services/core/java/com/android/server/display/DisplayDevice.java b/services/core/java/com/android/server/display/DisplayDevice.java
new file mode 100644
index 0000000..9ec1122
--- /dev/null
+++ b/services/core/java/com/android/server/display/DisplayDevice.java
@@ -0,0 +1,214 @@
+/*
+ * 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.server.display;
+
+import android.graphics.Rect;
+import android.hardware.display.DisplayViewport;
+import android.os.IBinder;
+import android.view.Surface;
+import android.view.SurfaceControl;
+
+import java.io.PrintWriter;
+
+/**
+ * Represents a physical display device such as the built-in display
+ * an external monitor, or a WiFi display.
+ * <p>
+ * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock.
+ * </p>
+ */
+abstract class DisplayDevice {
+    private final DisplayAdapter mDisplayAdapter;
+    private final IBinder mDisplayToken;
+
+    // The display device does not manage these properties itself, they are set by
+    // the display manager service.  The display device shouldn't really be looking at these.
+    private int mCurrentLayerStack = -1;
+    private int mCurrentOrientation = -1;
+    private Rect mCurrentLayerStackRect;
+    private Rect mCurrentDisplayRect;
+
+    // The display device owns its surface, but it should only set it
+    // within a transaction from performTraversalInTransactionLocked.
+    private Surface mCurrentSurface;
+
+    public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken) {
+        mDisplayAdapter = displayAdapter;
+        mDisplayToken = displayToken;
+    }
+
+    /**
+     * Gets the display adapter that owns the display device.
+     *
+     * @return The display adapter.
+     */
+    public final DisplayAdapter getAdapterLocked() {
+        return mDisplayAdapter;
+    }
+
+    /**
+     * Gets the Surface Flinger display token for this display.
+     *
+     * @return The display token, or null if the display is not being managed
+     * by Surface Flinger.
+     */
+    public final IBinder getDisplayTokenLocked() {
+        return mDisplayToken;
+    }
+
+    /**
+     * Gets the name of the display device.
+     *
+     * @return The display device name.
+     */
+    public final String getNameLocked() {
+        return getDisplayDeviceInfoLocked().name;
+    }
+
+    /**
+     * Gets information about the display device.
+     *
+     * The information returned should not change between calls unless the display
+     * adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event and
+     * {@link #applyPendingDisplayDeviceInfoChangesLocked()} has been called to apply
+     * the pending changes.
+     *
+     * @return The display device info, which should be treated as immutable by the caller.
+     * The display device should allocate a new display device info object whenever
+     * the data changes.
+     */
+    public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked();
+
+    /**
+     * Applies any pending changes to the observable state of the display device
+     * if the display adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event.
+     */
+    public void applyPendingDisplayDeviceInfoChangesLocked() {
+    }
+
+    /**
+     * Gives the display device a chance to update its properties while in a transaction.
+     */
+    public void performTraversalInTransactionLocked() {
+    }
+
+    /**
+     * Blanks the display, if supported.
+     */
+    public void blankLocked() {
+    }
+
+    /**
+     * Unblanks the display, if supported.
+     */
+    public void unblankLocked() {
+    }
+
+    /**
+     * Sets the display layer stack while in a transaction.
+     */
+    public final void setLayerStackInTransactionLocked(int layerStack) {
+        if (mCurrentLayerStack != layerStack) {
+            mCurrentLayerStack = layerStack;
+            SurfaceControl.setDisplayLayerStack(mDisplayToken, layerStack);
+        }
+    }
+
+    /**
+     * Sets the display projection while in a transaction.
+     *
+     * @param orientation defines the display's orientation
+     * @param layerStackRect defines which area of the window manager coordinate
+     *            space will be used
+     * @param displayRect defines where on the display will layerStackRect be
+     *            mapped to. displayRect is specified post-orientation, that is
+     *            it uses the orientation seen by the end-user
+     */
+    public final void setProjectionInTransactionLocked(int orientation,
+            Rect layerStackRect, Rect displayRect) {
+        if (mCurrentOrientation != orientation
+                || mCurrentLayerStackRect == null
+                || !mCurrentLayerStackRect.equals(layerStackRect)
+                || mCurrentDisplayRect == null
+                || !mCurrentDisplayRect.equals(displayRect)) {
+            mCurrentOrientation = orientation;
+
+            if (mCurrentLayerStackRect == null) {
+                mCurrentLayerStackRect = new Rect();
+            }
+            mCurrentLayerStackRect.set(layerStackRect);
+
+            if (mCurrentDisplayRect == null) {
+                mCurrentDisplayRect = new Rect();
+            }
+            mCurrentDisplayRect.set(displayRect);
+
+            SurfaceControl.setDisplayProjection(mDisplayToken,
+                    orientation, layerStackRect, displayRect);
+        }
+    }
+
+    /**
+     * Sets the display surface while in a transaction.
+     */
+    public final void setSurfaceInTransactionLocked(Surface surface) {
+        if (mCurrentSurface != surface) {
+            mCurrentSurface = surface;
+            SurfaceControl.setDisplaySurface(mDisplayToken, surface);
+        }
+    }
+
+    /**
+     * Populates the specified viewport object with orientation,
+     * physical and logical rects based on the display's current projection.
+     */
+    public final void populateViewportLocked(DisplayViewport viewport) {
+        viewport.orientation = mCurrentOrientation;
+
+        if (mCurrentLayerStackRect != null) {
+            viewport.logicalFrame.set(mCurrentLayerStackRect);
+        } else {
+            viewport.logicalFrame.setEmpty();
+        }
+
+        if (mCurrentDisplayRect != null) {
+            viewport.physicalFrame.set(mCurrentDisplayRect);
+        } else {
+            viewport.physicalFrame.setEmpty();
+        }
+
+        boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90
+                || mCurrentOrientation == Surface.ROTATION_270);
+        DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
+        viewport.deviceWidth = isRotated ? info.height : info.width;
+        viewport.deviceHeight = isRotated ? info.width : info.height;
+    }
+
+    /**
+     * Dumps the local state of the display device.
+     * Does not need to dump the display device info because that is already dumped elsewhere.
+     */
+    public void dumpLocked(PrintWriter pw) {
+        pw.println("mAdapter=" + mDisplayAdapter.getName());
+        pw.println("mDisplayToken=" + mDisplayToken);
+        pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
+        pw.println("mCurrentOrientation=" + mCurrentOrientation);
+        pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect);
+        pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect);
+        pw.println("mCurrentSurface=" + mCurrentSurface);
+    }
+}
diff --git a/services/core/java/com/android/server/display/DisplayDeviceInfo.java b/services/core/java/com/android/server/display/DisplayDeviceInfo.java
new file mode 100644
index 0000000..75f1f53
--- /dev/null
+++ b/services/core/java/com/android/server/display/DisplayDeviceInfo.java
@@ -0,0 +1,313 @@
+/*
+ * 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.server.display;
+
+import android.hardware.display.DisplayViewport;
+import android.util.DisplayMetrics;
+import android.view.Display;
+import android.view.Surface;
+
+import libcore.util.Objects;
+
+/**
+ * Describes the characteristics of a physical display device.
+ */
+final class DisplayDeviceInfo {
+    /**
+     * Flag: Indicates that this display device should be considered the default display
+     * device of the system.
+     */
+    public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
+
+    /**
+     * Flag: Indicates that the orientation of this display device is coupled to the
+     * rotation of its associated logical display.
+     * <p>
+     * This flag should be applied to the default display to indicate that the user
+     * physically rotates the display when content is presented in a different orientation.
+     * The display manager will apply a coordinate transformation assuming that the
+     * physical orientation of the display matches the logical orientation of its content.
+     * </p><p>
+     * The flag should not be set when the display device is mounted in a fixed orientation
+     * such as on a desk.  The display manager will apply a coordinate transformation
+     * such as a scale and translation to letterbox or pillarbox format under the
+     * assumption that the physical orientation of the display is invariant.
+     * </p>
+     */
+    public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1;
+
+    /**
+     * Flag: Indicates that this display device has secure video output, such as HDCP.
+     */
+    public static final int FLAG_SECURE = 1 << 2;
+
+    /**
+     * Flag: Indicates that this display device supports compositing
+     * from gralloc protected buffers.
+     */
+    public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 3;
+
+    /**
+     * Flag: Indicates that the display device is owned by a particular application
+     * and that no other application should be able to interact with it.
+     * Should typically be used together with {@link #FLAG_OWN_CONTENT_ONLY}.
+     */
+    public static final int FLAG_PRIVATE = 1 << 4;
+
+    /**
+     * Flag: Indicates that the display device is not blanked automatically by
+     * the power manager.
+     */
+    public static final int FLAG_NEVER_BLANK = 1 << 5;
+
+    /**
+     * Flag: Indicates that the display is suitable for presentations.
+     */
+    public static final int FLAG_PRESENTATION = 1 << 6;
+
+    /**
+     * Flag: Only show this display's own content; do not mirror
+     * the content of another display.
+     */
+    public static final int FLAG_OWN_CONTENT_ONLY = 1 << 7;
+
+    /**
+     * Touch attachment: Display does not receive touch.
+     */
+    public static final int TOUCH_NONE = 0;
+
+    /**
+     * Touch attachment: Touch input is via the internal interface.
+     */
+    public static final int TOUCH_INTERNAL = 1;
+
+    /**
+     * Touch attachment: Touch input is via an external interface, such as USB.
+     */
+    public static final int TOUCH_EXTERNAL = 2;
+
+    /**
+     * Gets the name of the display device, which may be derived from
+     * EDID or other sources.  The name may be displayed to the user.
+     */
+    public String name;
+
+    /**
+     * The width of the display in its natural orientation, in pixels.
+     * This value is not affected by display rotation.
+     */
+    public int width;
+
+    /**
+     * The height of the display in its natural orientation, in pixels.
+     * This value is not affected by display rotation.
+     */
+    public int height;
+
+    /**
+     * The refresh rate of the display.
+     */
+    public float refreshRate;
+
+    /**
+     * The nominal apparent density of the display in DPI used for layout calculations.
+     * This density is sensitive to the viewing distance.  A big TV and a tablet may have
+     * the same apparent density even though the pixels on the TV are much bigger than
+     * those on the tablet.
+     */
+    public int densityDpi;
+
+    /**
+     * The physical density of the display in DPI in the X direction.
+     * This density should specify the physical size of each pixel.
+     */
+    public float xDpi;
+
+    /**
+     * The physical density of the display in DPI in the X direction.
+     * This density should specify the physical size of each pixel.
+     */
+    public float yDpi;
+
+    /**
+     * Display flags.
+     */
+    public int flags;
+
+    /**
+     * The touch attachment, per {@link DisplayViewport#touch}.
+     */
+    public int touch;
+
+    /**
+     * The additional rotation to apply to all content presented on the display device
+     * relative to its physical coordinate system.  Default is {@link Surface#ROTATION_0}.
+     * <p>
+     * This field can be used to compensate for the fact that the display has been
+     * physically rotated relative to its natural orientation such as an HDMI monitor
+     * that has been mounted sideways to appear to be portrait rather than landscape.
+     * </p>
+     */
+    public int rotation = Surface.ROTATION_0;
+
+    /**
+     * Display type.
+     */
+    public int type;
+
+    /**
+     * Display address, or null if none.
+     * Interpretation varies by display type.
+     */
+    public String address;
+
+    /**
+     * The UID of the application that owns this display, or zero if it is owned by the system.
+     * <p>
+     * If the display is private, then only the owner can use it.
+     * </p>
+     */
+    public int ownerUid;
+
+    /**
+     * The package name of the application that owns this display, or null if it is
+     * owned by the system.
+     * <p>
+     * If the display is private, then only the owner can use it.
+     * </p>
+     */
+    public String ownerPackageName;
+
+    public void setAssumedDensityForExternalDisplay(int width, int height) {
+        densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
+        // Technically, these values should be smaller than the apparent density
+        // but we don't know the physical size of the display.
+        xDpi = densityDpi;
+        yDpi = densityDpi;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
+    }
+
+    public boolean equals(DisplayDeviceInfo other) {
+        return other != null
+                && Objects.equal(name, other.name)
+                && width == other.width
+                && height == other.height
+                && refreshRate == other.refreshRate
+                && densityDpi == other.densityDpi
+                && xDpi == other.xDpi
+                && yDpi == other.yDpi
+                && flags == other.flags
+                && touch == other.touch
+                && rotation == other.rotation
+                && type == other.type
+                && Objects.equal(address, other.address)
+                && ownerUid == other.ownerUid
+                && Objects.equal(ownerPackageName, other.ownerPackageName);
+    }
+
+    @Override
+    public int hashCode() {
+        return 0; // don't care
+    }
+
+    public void copyFrom(DisplayDeviceInfo other) {
+        name = other.name;
+        width = other.width;
+        height = other.height;
+        refreshRate = other.refreshRate;
+        densityDpi = other.densityDpi;
+        xDpi = other.xDpi;
+        yDpi = other.yDpi;
+        flags = other.flags;
+        touch = other.touch;
+        rotation = other.rotation;
+        type = other.type;
+        address = other.address;
+        ownerUid = other.ownerUid;
+        ownerPackageName = other.ownerPackageName;
+    }
+
+    // For debugging purposes
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("DisplayDeviceInfo{\"");
+        sb.append(name).append("\": ").append(width).append(" x ").append(height);
+        sb.append(", ").append(refreshRate).append(" fps, ");
+        sb.append("density ").append(densityDpi);
+        sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
+        sb.append(", touch ").append(touchToString(touch));
+        sb.append(", rotation ").append(rotation);
+        sb.append(", type ").append(Display.typeToString(type));
+        if (address != null) {
+            sb.append(", address ").append(address);
+        }
+        if (ownerUid != 0 || ownerPackageName != null) {
+            sb.append(", owner ").append(ownerPackageName);
+            sb.append(" (uid ").append(ownerUid).append(")");
+        }
+        sb.append(flagsToString(flags));
+        sb.append("}");
+        return sb.toString();
+    }
+
+    private static String touchToString(int touch) {
+        switch (touch) {
+            case TOUCH_NONE:
+                return "NONE";
+            case TOUCH_INTERNAL:
+                return "INTERNAL";
+            case TOUCH_EXTERNAL:
+                return "EXTERNAL";
+            default:
+                return Integer.toString(touch);
+        }
+    }
+
+    private static String flagsToString(int flags) {
+        StringBuilder msg = new StringBuilder();
+        if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
+            msg.append(", FLAG_DEFAULT_DISPLAY");
+        }
+        if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
+            msg.append(", FLAG_ROTATES_WITH_CONTENT");
+        }
+        if ((flags & FLAG_SECURE) != 0) {
+            msg.append(", FLAG_SECURE");
+        }
+        if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
+            msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
+        }
+        if ((flags & FLAG_PRIVATE) != 0) {
+            msg.append(", FLAG_PRIVATE");
+        }
+        if ((flags & FLAG_NEVER_BLANK) != 0) {
+            msg.append(", FLAG_NEVER_BLANK");
+        }
+        if ((flags & FLAG_PRESENTATION) != 0) {
+            msg.append(", FLAG_PRESENTATION");
+        }
+        if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) {
+            msg.append(", FLAG_OWN_CONTENT_ONLY");
+        }
+        return msg.toString();
+    }
+}
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
new file mode 100644
index 0000000..6be6405
--- /dev/null
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -0,0 +1,1364 @@
+/*
+ * 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.server.display;
+
+import com.android.internal.util.IndentingPrintWriter;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.DisplayManagerGlobal;
+import android.hardware.display.DisplayManagerInternal;
+import android.hardware.display.DisplayViewport;
+import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener;
+import android.hardware.display.IDisplayManager;
+import android.hardware.display.IDisplayManagerCallback;
+import android.hardware.display.WifiDisplayStatus;
+import android.hardware.input.InputManagerInternal;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IBinder.DeathRecipient;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.text.TextUtils;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.view.Display;
+import android.view.DisplayInfo;
+import android.view.Surface;
+import android.view.WindowManagerInternal;
+
+import com.android.server.DisplayThread;
+import com.android.server.LocalServices;
+import com.android.server.SystemService;
+import com.android.server.UiThread;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * Manages attached displays.
+ * <p>
+ * The {@link DisplayManagerService} manages the global lifecycle of displays,
+ * decides how to configure logical displays based on the physical display devices currently
+ * attached, sends notifications to the system and to applications when the state
+ * changes, and so on.
+ * </p><p>
+ * The display manager service relies on a collection of {@link DisplayAdapter} components,
+ * for discovering and configuring physical display devices attached to the system.
+ * There are separate display adapters for each manner that devices are attached:
+ * one display adapter for built-in local displays, one for simulated non-functional
+ * displays when the system is headless, one for simulated overlay displays used for
+ * development, one for wifi displays, etc.
+ * </p><p>
+ * Display adapters are only weakly coupled to the display manager service.
+ * Display adapters communicate changes in display device state to the display manager
+ * service asynchronously via a {@link DisplayAdapter.Listener} registered
+ * by the display manager service.  This separation of concerns is important for
+ * two main reasons.  First, it neatly encapsulates the responsibilities of these
+ * two classes: display adapters handle individual display devices whereas
+ * the display manager service handles the global state.  Second, it eliminates
+ * the potential for deadlocks resulting from asynchronous display device discovery.
+ * </p>
+ *
+ * <h3>Synchronization</h3>
+ * <p>
+ * Because the display manager may be accessed by multiple threads, the synchronization
+ * story gets a little complicated.  In particular, the window manager may call into
+ * the display manager while holding a surface transaction with the expectation that
+ * it can apply changes immediately.  Unfortunately, that means we can't just do
+ * everything asynchronously (*grump*).
+ * </p><p>
+ * To make this work, all of the objects that belong to the display manager must
+ * use the same lock.  We call this lock the synchronization root and it has a unique
+ * type {@link DisplayManagerService.SyncRoot}.  Methods that require this lock are
+ * named with the "Locked" suffix.
+ * </p><p>
+ * Where things get tricky is that the display manager is not allowed to make
+ * any potentially reentrant calls, especially into the window manager.  We generally
+ * avoid this by making all potentially reentrant out-calls asynchronous.
+ * </p>
+ */
+public final class DisplayManagerService extends SystemService {
+    private static final String TAG = "DisplayManagerService";
+    private static final boolean DEBUG = false;
+
+    // When this system property is set to 0, WFD is forcibly disabled on boot.
+    // When this system property is set to 1, WFD is forcibly enabled on boot.
+    // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
+    private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
+
+    private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
+
+    private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER = 1;
+    private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
+    private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
+    private static final int MSG_REQUEST_TRAVERSAL = 4;
+    private static final int MSG_UPDATE_VIEWPORT = 5;
+
+    private static final int DISPLAY_BLANK_STATE_UNKNOWN = 0;
+    private static final int DISPLAY_BLANK_STATE_BLANKED = 1;
+    private static final int DISPLAY_BLANK_STATE_UNBLANKED = 2;
+
+    private final Context mContext;
+    private final DisplayManagerHandler mHandler;
+    private final Handler mUiHandler;
+    private final DisplayAdapterListener mDisplayAdapterListener;
+    private WindowManagerInternal mWindowManagerInternal;
+    private InputManagerInternal mInputManagerInternal;
+
+    // The synchronization root for the display manager.
+    // This lock guards most of the display manager's state.
+    // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
+    // into WindowManagerService methods that require mWindowMap while holding this unless you are
+    // very very sure that no deadlock can occur.
+    private final SyncRoot mSyncRoot = new SyncRoot();
+
+    // True if in safe mode.
+    // This option may disable certain display adapters.
+    public boolean mSafeMode;
+
+    // True if we are in a special boot mode where only core applications and
+    // services should be started.  This option may disable certain display adapters.
+    public boolean mOnlyCore;
+
+    // True if the display manager service should pretend there is only one display
+    // and only tell applications about the existence of the default logical display.
+    // The display manager can still mirror content to secondary displays but applications
+    // cannot present unique content on those displays.
+    // Used for demonstration purposes only.
+    private final boolean mSingleDisplayDemoMode;
+
+    // All callback records indexed by calling process id.
+    public final SparseArray<CallbackRecord> mCallbacks =
+            new SparseArray<CallbackRecord>();
+
+    // List of all currently registered display adapters.
+    private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
+
+    // List of all currently connected display devices.
+    private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
+
+    // List of all logical displays indexed by logical display id.
+    private final SparseArray<LogicalDisplay> mLogicalDisplays =
+            new SparseArray<LogicalDisplay>();
+    private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
+
+    // List of all display transaction listeners.
+    private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
+            new CopyOnWriteArrayList<DisplayTransactionListener>();
+
+    // Set to true if all displays have been blanked by the power manager.
+    private int mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNKNOWN;
+
+    // Set to true when there are pending display changes that have yet to be applied
+    // to the surface flinger state.
+    private boolean mPendingTraversal;
+
+    // The Wifi display adapter, or null if not registered.
+    private WifiDisplayAdapter mWifiDisplayAdapter;
+
+    // The number of active wifi display scan requests.
+    private int mWifiDisplayScanRequestCount;
+
+    // The virtual display adapter, or null if not registered.
+    private VirtualDisplayAdapter mVirtualDisplayAdapter;
+
+    // Viewports of the default display and the display that should receive touch
+    // input from an external source.  Used by the input system.
+    private final DisplayViewport mDefaultViewport = new DisplayViewport();
+    private final DisplayViewport mExternalTouchViewport = new DisplayViewport();
+
+    // Persistent data store for all internal settings maintained by the display manager service.
+    private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
+
+    // Temporary callback list, used when sending display events to applications.
+    // May be used outside of the lock but only on the handler thread.
+    private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
+
+    // Temporary display info, used for comparing display configurations.
+    private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
+
+    // Temporary viewports, used when sending new viewport information to the
+    // input system.  May be used outside of the lock but only on the handler thread.
+    private final DisplayViewport mTempDefaultViewport = new DisplayViewport();
+    private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport();
+
+    public DisplayManagerService(Context context) {
+        super(context);
+        mContext = context;
+        mHandler = new DisplayManagerHandler(DisplayThread.get().getLooper());
+        mUiHandler = UiThread.getHandler();
+        mDisplayAdapterListener = new DisplayAdapterListener();
+        mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
+    }
+
+    @Override
+    public void onStart() {
+        mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER);
+
+        publishBinderService(Context.DISPLAY_SERVICE, new BinderService(),
+                true /*allowIsolated*/);
+        publishLocalService(DisplayManagerInternal.class, new LocalService());
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == PHASE_WAIT_FOR_DEFAULT_DISPLAY) {
+            synchronized (mSyncRoot) {
+                long timeout = SystemClock.uptimeMillis() + WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
+                while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null) {
+                    long delay = timeout - SystemClock.uptimeMillis();
+                    if (delay <= 0) {
+                        throw new RuntimeException("Timeout waiting for default display "
+                                + "to be initialized.");
+                    }
+                    if (DEBUG) {
+                        Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
+                    }
+                    try {
+                        mSyncRoot.wait(delay);
+                    } catch (InterruptedException ex) {
+                    }
+                }
+            }
+        }
+    }
+
+    // TODO: Use dependencies or a boot phase
+    public void windowManagerAndInputReady() {
+        synchronized (mSyncRoot) {
+            mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
+            mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
+            scheduleTraversalLocked(false);
+        }
+    }
+
+    /**
+     * Called when the system is ready to go.
+     */
+    public void systemReady(boolean safeMode, boolean onlyCore) {
+        synchronized (mSyncRoot) {
+            mSafeMode = safeMode;
+            mOnlyCore = onlyCore;
+        }
+
+        mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
+    }
+
+    private void registerDisplayTransactionListenerInternal(
+            DisplayTransactionListener listener) {
+        // List is self-synchronized copy-on-write.
+        mDisplayTransactionListeners.add(listener);
+    }
+
+    private void unregisterDisplayTransactionListenerInternal(
+            DisplayTransactionListener listener) {
+        // List is self-synchronized copy-on-write.
+        mDisplayTransactionListeners.remove(listener);
+    }
+
+    private void setDisplayInfoOverrideFromWindowManagerInternal(
+            int displayId, DisplayInfo info) {
+        synchronized (mSyncRoot) {
+            LogicalDisplay display = mLogicalDisplays.get(displayId);
+            if (display != null) {
+                if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
+                    sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
+                    scheduleTraversalLocked(false);
+                }
+            }
+        }
+    }
+
+    private void performTraversalInTransactionFromWindowManagerInternal() {
+        synchronized (mSyncRoot) {
+            if (!mPendingTraversal) {
+                return;
+            }
+            mPendingTraversal = false;
+
+            performTraversalInTransactionLocked();
+        }
+
+        // List is self-synchronized copy-on-write.
+        for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
+            listener.onDisplayTransaction();
+        }
+    }
+
+    private void blankAllDisplaysFromPowerManagerInternal() {
+        synchronized (mSyncRoot) {
+            if (mAllDisplayBlankStateFromPowerManager != DISPLAY_BLANK_STATE_BLANKED) {
+                mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_BLANKED;
+                updateAllDisplayBlankingLocked();
+                scheduleTraversalLocked(false);
+            }
+        }
+    }
+
+    private void unblankAllDisplaysFromPowerManagerInternal() {
+        synchronized (mSyncRoot) {
+            if (mAllDisplayBlankStateFromPowerManager != DISPLAY_BLANK_STATE_UNBLANKED) {
+                mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNBLANKED;
+                updateAllDisplayBlankingLocked();
+                scheduleTraversalLocked(false);
+            }
+        }
+    }
+
+    private DisplayInfo getDisplayInfoInternal(int displayId, int callingUid) {
+        synchronized (mSyncRoot) {
+            LogicalDisplay display = mLogicalDisplays.get(displayId);
+            if (display != null) {
+                DisplayInfo info = display.getDisplayInfoLocked();
+                if (info.hasAccess(callingUid)) {
+                    return info;
+                }
+            }
+            return null;
+        }
+    }
+
+    private int[] getDisplayIdsInternal(int callingUid) {
+        synchronized (mSyncRoot) {
+            final int count = mLogicalDisplays.size();
+            int[] displayIds = new int[count];
+            int n = 0;
+            for (int i = 0; i < count; i++) {
+                LogicalDisplay display = mLogicalDisplays.valueAt(i);
+                DisplayInfo info = display.getDisplayInfoLocked();
+                if (info.hasAccess(callingUid)) {
+                    displayIds[n++] = mLogicalDisplays.keyAt(i);
+                }
+            }
+            if (n != count) {
+                displayIds = Arrays.copyOfRange(displayIds, 0, n);
+            }
+            return displayIds;
+        }
+    }
+
+    private void registerCallbackInternal(IDisplayManagerCallback callback, int callingPid) {
+        synchronized (mSyncRoot) {
+            if (mCallbacks.get(callingPid) != null) {
+                throw new SecurityException("The calling process has already "
+                        + "registered an IDisplayManagerCallback.");
+            }
+
+            CallbackRecord record = new CallbackRecord(callingPid, callback);
+            try {
+                IBinder binder = callback.asBinder();
+                binder.linkToDeath(record, 0);
+            } catch (RemoteException ex) {
+                // give up
+                throw new RuntimeException(ex);
+            }
+
+            mCallbacks.put(callingPid, record);
+        }
+    }
+
+    private void onCallbackDied(CallbackRecord record) {
+        synchronized (mSyncRoot) {
+            mCallbacks.remove(record.mPid);
+            stopWifiDisplayScanLocked(record);
+        }
+    }
+
+    private void startWifiDisplayScanInternal(int callingPid) {
+        synchronized (mSyncRoot) {
+            CallbackRecord record = mCallbacks.get(callingPid);
+            if (record == null) {
+                throw new IllegalStateException("The calling process has not "
+                        + "registered an IDisplayManagerCallback.");
+            }
+            startWifiDisplayScanLocked(record);
+        }
+    }
+
+    private void startWifiDisplayScanLocked(CallbackRecord record) {
+        if (!record.mWifiDisplayScanRequested) {
+            record.mWifiDisplayScanRequested = true;
+            if (mWifiDisplayScanRequestCount++ == 0) {
+                if (mWifiDisplayAdapter != null) {
+                    mWifiDisplayAdapter.requestStartScanLocked();
+                }
+            }
+        }
+    }
+
+    private void stopWifiDisplayScanInternal(int callingPid) {
+        synchronized (mSyncRoot) {
+            CallbackRecord record = mCallbacks.get(callingPid);
+            if (record == null) {
+                throw new IllegalStateException("The calling process has not "
+                        + "registered an IDisplayManagerCallback.");
+            }
+            stopWifiDisplayScanLocked(record);
+        }
+    }
+
+    private void stopWifiDisplayScanLocked(CallbackRecord record) {
+        if (record.mWifiDisplayScanRequested) {
+            record.mWifiDisplayScanRequested = false;
+            if (--mWifiDisplayScanRequestCount == 0) {
+                if (mWifiDisplayAdapter != null) {
+                    mWifiDisplayAdapter.requestStopScanLocked();
+                }
+            } else if (mWifiDisplayScanRequestCount < 0) {
+                Log.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
+                        + mWifiDisplayScanRequestCount);
+                mWifiDisplayScanRequestCount = 0;
+            }
+        }
+    }
+
+    private void connectWifiDisplayInternal(String address) {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                mWifiDisplayAdapter.requestConnectLocked(address);
+            }
+        }
+    }
+
+    private void pauseWifiDisplayInternal() {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                mWifiDisplayAdapter.requestPauseLocked();
+            }
+        }
+    }
+
+    private void resumeWifiDisplayInternal() {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                mWifiDisplayAdapter.requestResumeLocked();
+            }
+        }
+    }
+
+    private void disconnectWifiDisplayInternal() {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                mWifiDisplayAdapter.requestDisconnectLocked();
+            }
+        }
+    }
+
+    private void renameWifiDisplayInternal(String address, String alias) {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                mWifiDisplayAdapter.requestRenameLocked(address, alias);
+            }
+        }
+    }
+
+    private void forgetWifiDisplayInternal(String address) {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                mWifiDisplayAdapter.requestForgetLocked(address);
+            }
+        }
+    }
+
+    private WifiDisplayStatus getWifiDisplayStatusInternal() {
+        synchronized (mSyncRoot) {
+            if (mWifiDisplayAdapter != null) {
+                return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
+            }
+            return new WifiDisplayStatus();
+        }
+    }
+
+    private int createVirtualDisplayInternal(IBinder appToken, int callingUid, String packageName,
+            String name, int width, int height, int densityDpi, Surface surface, int flags) {
+        synchronized (mSyncRoot) {
+            if (mVirtualDisplayAdapter == null) {
+                Slog.w(TAG, "Rejecting request to create private virtual display "
+                        + "because the virtual display adapter is not available.");
+                return -1;
+            }
+
+            DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
+                    appToken, callingUid, packageName, name, width, height, densityDpi,
+                    surface, flags);
+            if (device == null) {
+                return -1;
+            }
+
+            handleDisplayDeviceAddedLocked(device);
+            LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
+            if (display != null) {
+                return display.getDisplayIdLocked();
+            }
+
+            // Something weird happened and the logical display was not created.
+            Slog.w(TAG, "Rejecting request to create virtual display "
+                    + "because the logical display was not created.");
+            mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
+            handleDisplayDeviceRemovedLocked(device);
+        }
+        return -1;
+    }
+
+    private void releaseVirtualDisplayInternal(IBinder appToken) {
+        synchronized (mSyncRoot) {
+            if (mVirtualDisplayAdapter == null) {
+                return;
+            }
+
+            DisplayDevice device =
+                    mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
+            if (device != null) {
+                handleDisplayDeviceRemovedLocked(device);
+            }
+        }
+    }
+
+    private void registerDefaultDisplayAdapter() {
+        // Register default display adapter.
+        synchronized (mSyncRoot) {
+            registerDisplayAdapterLocked(new LocalDisplayAdapter(
+                    mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
+        }
+    }
+
+    private void registerAdditionalDisplayAdapters() {
+        synchronized (mSyncRoot) {
+            if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
+                registerOverlayDisplayAdapterLocked();
+                registerWifiDisplayAdapterLocked();
+                registerVirtualDisplayAdapterLocked();
+            }
+        }
+    }
+
+    private void registerOverlayDisplayAdapterLocked() {
+        registerDisplayAdapterLocked(new OverlayDisplayAdapter(
+                mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
+    }
+
+    private void registerWifiDisplayAdapterLocked() {
+        if (mContext.getResources().getBoolean(
+                com.android.internal.R.bool.config_enableWifiDisplay)
+                || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
+            mWifiDisplayAdapter = new WifiDisplayAdapter(
+                    mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
+                    mPersistentDataStore);
+            registerDisplayAdapterLocked(mWifiDisplayAdapter);
+        }
+    }
+
+    private void registerVirtualDisplayAdapterLocked() {
+        mVirtualDisplayAdapter = new VirtualDisplayAdapter(
+                mSyncRoot, mContext, mHandler, mDisplayAdapterListener);
+        registerDisplayAdapterLocked(mVirtualDisplayAdapter);
+    }
+
+    private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
+        // In safe mode, we disable non-essential display adapters to give the user
+        // an opportunity to fix broken settings or other problems that might affect
+        // system stability.
+        // In only-core mode, we disable non-essential display adapters to minimize
+        // the number of dependencies that are started while in this mode and to
+        // prevent problems that might occur due to the device being encrypted.
+        return !mSafeMode && !mOnlyCore;
+    }
+
+    private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
+        mDisplayAdapters.add(adapter);
+        adapter.registerLocked();
+    }
+
+    private void handleDisplayDeviceAdded(DisplayDevice device) {
+        synchronized (mSyncRoot) {
+            handleDisplayDeviceAddedLocked(device);
+        }
+    }
+
+    private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
+        if (mDisplayDevices.contains(device)) {
+            Slog.w(TAG, "Attempted to add already added display device: "
+                    + device.getDisplayDeviceInfoLocked());
+            return;
+        }
+
+        Slog.i(TAG, "Display device added: " + device.getDisplayDeviceInfoLocked());
+
+        mDisplayDevices.add(device);
+        addLogicalDisplayLocked(device);
+        updateDisplayBlankingLocked(device);
+        scheduleTraversalLocked(false);
+    }
+
+    private void handleDisplayDeviceChanged(DisplayDevice device) {
+        synchronized (mSyncRoot) {
+            if (!mDisplayDevices.contains(device)) {
+                Slog.w(TAG, "Attempted to change non-existent display device: "
+                        + device.getDisplayDeviceInfoLocked());
+                return;
+            }
+
+            Slog.i(TAG, "Display device changed: " + device.getDisplayDeviceInfoLocked());
+
+            device.applyPendingDisplayDeviceInfoChangesLocked();
+            if (updateLogicalDisplaysLocked()) {
+                scheduleTraversalLocked(false);
+            }
+        }
+    }
+
+    private void handleDisplayDeviceRemoved(DisplayDevice device) {
+        synchronized (mSyncRoot) {
+            handleDisplayDeviceRemovedLocked(device);
+        }
+    }
+    private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
+        if (!mDisplayDevices.remove(device)) {
+            Slog.w(TAG, "Attempted to remove non-existent display device: "
+                    + device.getDisplayDeviceInfoLocked());
+            return;
+        }
+
+        Slog.i(TAG, "Display device removed: " + device.getDisplayDeviceInfoLocked());
+
+        updateLogicalDisplaysLocked();
+        scheduleTraversalLocked(false);
+    }
+
+    private void updateAllDisplayBlankingLocked() {
+        final int count = mDisplayDevices.size();
+        for (int i = 0; i < count; i++) {
+            DisplayDevice device = mDisplayDevices.get(i);
+            updateDisplayBlankingLocked(device);
+        }
+    }
+
+    private void updateDisplayBlankingLocked(DisplayDevice device) {
+        // Blank or unblank the display immediately to match the state requested
+        // by the power manager (if known).
+        DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
+        if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
+            switch (mAllDisplayBlankStateFromPowerManager) {
+                case DISPLAY_BLANK_STATE_BLANKED:
+                    device.blankLocked();
+                    break;
+                case DISPLAY_BLANK_STATE_UNBLANKED:
+                    device.unblankLocked();
+                    break;
+            }
+        }
+    }
+
+    // Adds a new logical display based on the given display device.
+    // Sends notifications if needed.
+    private void addLogicalDisplayLocked(DisplayDevice device) {
+        DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
+        boolean isDefault = (deviceInfo.flags
+                & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
+        if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
+            Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
+            isDefault = false;
+        }
+
+        if (!isDefault && mSingleDisplayDemoMode) {
+            Slog.i(TAG, "Not creating a logical display for a secondary display "
+                    + " because single display demo mode is enabled: " + deviceInfo);
+            return;
+        }
+
+        final int displayId = assignDisplayIdLocked(isDefault);
+        final int layerStack = assignLayerStackLocked(displayId);
+
+        LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
+        display.updateLocked(mDisplayDevices);
+        if (!display.isValidLocked()) {
+            // This should never happen currently.
+            Slog.w(TAG, "Ignoring display device because the logical display "
+                    + "created from it was not considered valid: " + deviceInfo);
+            return;
+        }
+
+        mLogicalDisplays.put(displayId, display);
+
+        // Wake up waitForDefaultDisplay.
+        if (isDefault) {
+            mSyncRoot.notifyAll();
+        }
+
+        sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
+    }
+
+    private int assignDisplayIdLocked(boolean isDefault) {
+        return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
+    }
+
+    private int assignLayerStackLocked(int displayId) {
+        // Currently layer stacks and display ids are the same.
+        // This need not be the case.
+        return displayId;
+    }
+
+    // Updates all existing logical displays given the current set of display devices.
+    // Removes invalid logical displays.
+    // Sends notifications if needed.
+    private boolean updateLogicalDisplaysLocked() {
+        boolean changed = false;
+        for (int i = mLogicalDisplays.size(); i-- > 0; ) {
+            final int displayId = mLogicalDisplays.keyAt(i);
+            LogicalDisplay display = mLogicalDisplays.valueAt(i);
+
+            mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
+            display.updateLocked(mDisplayDevices);
+            if (!display.isValidLocked()) {
+                mLogicalDisplays.removeAt(i);
+                sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
+                changed = true;
+            } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
+                sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
+                changed = true;
+            }
+        }
+        return changed;
+    }
+
+    private void performTraversalInTransactionLocked() {
+        // Clear all viewports before configuring displays so that we can keep
+        // track of which ones we have configured.
+        clearViewportsLocked();
+
+        // Configure each display device.
+        final int count = mDisplayDevices.size();
+        for (int i = 0; i < count; i++) {
+            DisplayDevice device = mDisplayDevices.get(i);
+            configureDisplayInTransactionLocked(device);
+            device.performTraversalInTransactionLocked();
+        }
+
+        // Tell the input system about these new viewports.
+        if (mInputManagerInternal != null) {
+            mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
+        }
+    }
+
+    private void setDisplayHasContentInternal(int displayId, boolean hasContent,
+            boolean inTraversal) {
+        synchronized (mSyncRoot) {
+            LogicalDisplay display = mLogicalDisplays.get(displayId);
+            if (display != null && display.hasContentLocked() != hasContent) {
+                if (DEBUG) {
+                    Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
+                            + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
+                }
+
+                display.setHasContentLocked(hasContent);
+                scheduleTraversalLocked(inTraversal);
+            }
+        }
+    }
+
+    private void clearViewportsLocked() {
+        mDefaultViewport.valid = false;
+        mExternalTouchViewport.valid = false;
+    }
+
+    private void configureDisplayInTransactionLocked(DisplayDevice device) {
+        final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
+        final boolean ownContent = (info.flags & DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY) != 0;
+
+        // Find the logical display that the display device is showing.
+        // Certain displays only ever show their own content.
+        LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
+        if (!ownContent) {
+            if (display != null && !display.hasContentLocked()) {
+                // If the display does not have any content of its own, then
+                // automatically mirror the default logical display contents.
+                display = null;
+            }
+            if (display == null) {
+                display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
+            }
+        }
+
+        // Apply the logical display configuration to the display device.
+        if (display == null) {
+            // TODO: no logical display for the device, blank it
+            Slog.w(TAG, "Missing logical display to use for physical display device: "
+                    + device.getDisplayDeviceInfoLocked());
+            return;
+        }
+        boolean isBlanked = (mAllDisplayBlankStateFromPowerManager == DISPLAY_BLANK_STATE_BLANKED)
+                && (info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0;
+        display.configureDisplayInTransactionLocked(device, isBlanked);
+
+        // Update the viewports if needed.
+        if (!mDefaultViewport.valid
+                && (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
+            setViewportLocked(mDefaultViewport, display, device);
+        }
+        if (!mExternalTouchViewport.valid
+                && info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
+            setViewportLocked(mExternalTouchViewport, display, device);
+        }
+    }
+
+    private static void setViewportLocked(DisplayViewport viewport,
+            LogicalDisplay display, DisplayDevice device) {
+        viewport.valid = true;
+        viewport.displayId = display.getDisplayIdLocked();
+        device.populateViewportLocked(viewport);
+    }
+
+    private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
+        final int count = mLogicalDisplays.size();
+        for (int i = 0; i < count; i++) {
+            LogicalDisplay display = mLogicalDisplays.valueAt(i);
+            if (display.getPrimaryDisplayDeviceLocked() == device) {
+                return display;
+            }
+        }
+        return null;
+    }
+
+    private void sendDisplayEventLocked(int displayId, int event) {
+        Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
+        mHandler.sendMessage(msg);
+    }
+
+    // Requests that performTraversalsInTransactionFromWindowManager be called at a
+    // later time to apply changes to surfaces and displays.
+    private void scheduleTraversalLocked(boolean inTraversal) {
+        if (!mPendingTraversal && mWindowManagerInternal != null) {
+            mPendingTraversal = true;
+            if (!inTraversal) {
+                mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
+            }
+        }
+    }
+
+    // Runs on Handler thread.
+    // Delivers display event notifications to callbacks.
+    private void deliverDisplayEvent(int displayId, int event) {
+        if (DEBUG) {
+            Slog.d(TAG, "Delivering display event: displayId="
+                    + displayId + ", event=" + event);
+        }
+
+        // Grab the lock and copy the callbacks.
+        final int count;
+        synchronized (mSyncRoot) {
+            count = mCallbacks.size();
+            mTempCallbacks.clear();
+            for (int i = 0; i < count; i++) {
+                mTempCallbacks.add(mCallbacks.valueAt(i));
+            }
+        }
+
+        // After releasing the lock, send the notifications out.
+        for (int i = 0; i < count; i++) {
+            mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
+        }
+        mTempCallbacks.clear();
+    }
+
+    private void dumpInternal(PrintWriter pw) {
+        pw.println("DISPLAY MANAGER (dumpsys display)");
+
+        synchronized (mSyncRoot) {
+            pw.println("  mOnlyCode=" + mOnlyCore);
+            pw.println("  mSafeMode=" + mSafeMode);
+            pw.println("  mPendingTraversal=" + mPendingTraversal);
+            pw.println("  mAllDisplayBlankStateFromPowerManager="
+                    + mAllDisplayBlankStateFromPowerManager);
+            pw.println("  mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
+            pw.println("  mDefaultViewport=" + mDefaultViewport);
+            pw.println("  mExternalTouchViewport=" + mExternalTouchViewport);
+            pw.println("  mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
+            pw.println("  mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
+
+            IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "    ");
+            ipw.increaseIndent();
+
+            pw.println();
+            pw.println("Display Adapters: size=" + mDisplayAdapters.size());
+            for (DisplayAdapter adapter : mDisplayAdapters) {
+                pw.println("  " + adapter.getName());
+                adapter.dumpLocked(ipw);
+            }
+
+            pw.println();
+            pw.println("Display Devices: size=" + mDisplayDevices.size());
+            for (DisplayDevice device : mDisplayDevices) {
+                pw.println("  " + device.getDisplayDeviceInfoLocked());
+                device.dumpLocked(ipw);
+            }
+
+            final int logicalDisplayCount = mLogicalDisplays.size();
+            pw.println();
+            pw.println("Logical Displays: size=" + logicalDisplayCount);
+            for (int i = 0; i < logicalDisplayCount; i++) {
+                int displayId = mLogicalDisplays.keyAt(i);
+                LogicalDisplay display = mLogicalDisplays.valueAt(i);
+                pw.println("  Display " + displayId + ":");
+                display.dumpLocked(ipw);
+            }
+
+            final int callbackCount = mCallbacks.size();
+            pw.println();
+            pw.println("Callbacks: size=" + callbackCount);
+            for (int i = 0; i < callbackCount; i++) {
+                CallbackRecord callback = mCallbacks.valueAt(i);
+                pw.println("  " + i + ": mPid=" + callback.mPid
+                        + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
+            }
+        }
+    }
+
+    /**
+     * This is the object that everything in the display manager locks on.
+     * We make it an inner class within the {@link DisplayManagerService} to so that it is
+     * clear that the object belongs to the display manager service and that it is
+     * a unique object with a special purpose.
+     */
+    public static final class SyncRoot {
+    }
+
+    private final class DisplayManagerHandler extends Handler {
+        public DisplayManagerHandler(Looper looper) {
+            super(looper, null, true /*async*/);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER:
+                    registerDefaultDisplayAdapter();
+                    break;
+
+                case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
+                    registerAdditionalDisplayAdapters();
+                    break;
+
+                case MSG_DELIVER_DISPLAY_EVENT:
+                    deliverDisplayEvent(msg.arg1, msg.arg2);
+                    break;
+
+                case MSG_REQUEST_TRAVERSAL:
+                    mWindowManagerInternal.requestTraversalFromDisplayManager();
+                    break;
+
+                case MSG_UPDATE_VIEWPORT: {
+                    synchronized (mSyncRoot) {
+                        mTempDefaultViewport.copyFrom(mDefaultViewport);
+                        mTempExternalTouchViewport.copyFrom(mExternalTouchViewport);
+                    }
+                    mInputManagerInternal.setDisplayViewports(
+                            mTempDefaultViewport, mTempExternalTouchViewport);
+                    break;
+                }
+            }
+        }
+    }
+
+    private final class DisplayAdapterListener implements DisplayAdapter.Listener {
+        @Override
+        public void onDisplayDeviceEvent(DisplayDevice device, int event) {
+            switch (event) {
+                case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
+                    handleDisplayDeviceAdded(device);
+                    break;
+
+                case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
+                    handleDisplayDeviceChanged(device);
+                    break;
+
+                case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
+                    handleDisplayDeviceRemoved(device);
+                    break;
+            }
+        }
+
+        @Override
+        public void onTraversalRequested() {
+            synchronized (mSyncRoot) {
+                scheduleTraversalLocked(false);
+            }
+        }
+    }
+
+    private final class CallbackRecord implements DeathRecipient {
+        public final int mPid;
+        private final IDisplayManagerCallback mCallback;
+
+        public boolean mWifiDisplayScanRequested;
+
+        public CallbackRecord(int pid, IDisplayManagerCallback callback) {
+            mPid = pid;
+            mCallback = callback;
+        }
+
+        @Override
+        public void binderDied() {
+            if (DEBUG) {
+                Slog.d(TAG, "Display listener for pid " + mPid + " died.");
+            }
+            onCallbackDied(this);
+        }
+
+        public void notifyDisplayEventAsync(int displayId, int event) {
+            try {
+                mCallback.onDisplayEvent(displayId, event);
+            } catch (RemoteException ex) {
+                Slog.w(TAG, "Failed to notify process "
+                        + mPid + " that displays changed, assuming it died.", ex);
+                binderDied();
+            }
+        }
+    }
+
+    private final class BinderService extends IDisplayManager.Stub {
+        /**
+         * Returns information about the specified logical display.
+         *
+         * @param displayId The logical display id.
+         * @return The logical display info, or null if the display does not exist.  The
+         * returned object must be treated as immutable.
+         */
+        @Override // Binder call
+        public DisplayInfo getDisplayInfo(int displayId) {
+            final int callingUid = Binder.getCallingUid();
+            final long token = Binder.clearCallingIdentity();
+            try {
+                return getDisplayInfoInternal(displayId, callingUid);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        /**
+         * Returns the list of all display ids.
+         */
+        @Override // Binder call
+        public int[] getDisplayIds() {
+            final int callingUid = Binder.getCallingUid();
+            final long token = Binder.clearCallingIdentity();
+            try {
+                return getDisplayIdsInternal(callingUid);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void registerCallback(IDisplayManagerCallback callback) {
+            if (callback == null) {
+                throw new IllegalArgumentException("listener must not be null");
+            }
+
+            final int callingPid = Binder.getCallingPid();
+            final long token = Binder.clearCallingIdentity();
+            try {
+                registerCallbackInternal(callback, callingPid);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void startWifiDisplayScan() {
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to start wifi display scans");
+
+            final int callingPid = Binder.getCallingPid();
+            final long token = Binder.clearCallingIdentity();
+            try {
+                startWifiDisplayScanInternal(callingPid);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void stopWifiDisplayScan() {
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to stop wifi display scans");
+
+            final int callingPid = Binder.getCallingPid();
+            final long token = Binder.clearCallingIdentity();
+            try {
+                stopWifiDisplayScanInternal(callingPid);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void connectWifiDisplay(String address) {
+            if (address == null) {
+                throw new IllegalArgumentException("address must not be null");
+            }
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to connect to a wifi display");
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                connectWifiDisplayInternal(address);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void disconnectWifiDisplay() {
+            // This request does not require special permissions.
+            // Any app can request disconnection from the currently active wifi display.
+            // This exception should no longer be needed once wifi display control moves
+            // to the media router service.
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                disconnectWifiDisplayInternal();
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void renameWifiDisplay(String address, String alias) {
+            if (address == null) {
+                throw new IllegalArgumentException("address must not be null");
+            }
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to rename to a wifi display");
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                renameWifiDisplayInternal(address, alias);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void forgetWifiDisplay(String address) {
+            if (address == null) {
+                throw new IllegalArgumentException("address must not be null");
+            }
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to forget to a wifi display");
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                forgetWifiDisplayInternal(address);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void pauseWifiDisplay() {
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to pause a wifi display session");
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                pauseWifiDisplayInternal();
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void resumeWifiDisplay() {
+            mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
+                    "Permission required to resume a wifi display session");
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                resumeWifiDisplayInternal();
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public WifiDisplayStatus getWifiDisplayStatus() {
+            // This request does not require special permissions.
+            // Any app can get information about available wifi displays.
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                return getWifiDisplayStatusInternal();
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public int createVirtualDisplay(IBinder appToken, String packageName,
+                String name, int width, int height, int densityDpi, Surface surface, int flags) {
+            final int callingUid = Binder.getCallingUid();
+            if (!validatePackageName(callingUid, packageName)) {
+                throw new SecurityException("packageName must match the calling uid");
+            }
+            if (appToken == null) {
+                throw new IllegalArgumentException("appToken must not be null");
+            }
+            if (TextUtils.isEmpty(name)) {
+                throw new IllegalArgumentException("name must be non-null and non-empty");
+            }
+            if (width <= 0 || height <= 0 || densityDpi <= 0) {
+                throw new IllegalArgumentException("width, height, and densityDpi must be "
+                        + "greater than 0");
+            }
+            if (surface == null) {
+                throw new IllegalArgumentException("surface must not be null");
+            }
+            if (callingUid != Process.SYSTEM_UID &&
+                    (flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
+                if (mContext.checkCallingPermission(android.Manifest.permission.CAPTURE_VIDEO_OUTPUT)
+                        != PackageManager.PERMISSION_GRANTED
+                        && mContext.checkCallingPermission(
+                                android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
+                                != PackageManager.PERMISSION_GRANTED) {
+                    throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
+                            + "CAPTURE_SECURE_VIDEO_OUTPUT permission to create a "
+                            + "public virtual display.");
+                }
+            }
+            if ((flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
+                if (mContext.checkCallingPermission(
+                        android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
+                            + "to create a secure virtual display.");
+                }
+            }
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                return createVirtualDisplayInternal(appToken, callingUid, packageName,
+                        name, width, height, densityDpi, surface, flags);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void releaseVirtualDisplay(IBinder appToken) {
+            final long token = Binder.clearCallingIdentity();
+            try {
+                releaseVirtualDisplayInternal(appToken);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        @Override // Binder call
+        public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
+            if (mContext == null
+                    || mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
+                            != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump DisplayManager from from pid="
+                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            final long token = Binder.clearCallingIdentity();
+            try {
+                dumpInternal(pw);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+
+        private boolean validatePackageName(int uid, String packageName) {
+            if (packageName != null) {
+                String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
+                if (packageNames != null) {
+                    for (String n : packageNames) {
+                        if (n.equals(packageName)) {
+                            return true;
+                        }
+                    }
+                }
+            }
+            return false;
+        }
+    }
+
+    private final class LocalService extends DisplayManagerInternal {
+        @Override
+        public void blankAllDisplaysFromPowerManager() {
+            blankAllDisplaysFromPowerManagerInternal();
+        }
+
+        @Override
+        public void unblankAllDisplaysFromPowerManager() {
+            unblankAllDisplaysFromPowerManagerInternal();
+        }
+
+        @Override
+        public DisplayInfo getDisplayInfo(int displayId) {
+            return getDisplayInfoInternal(displayId, Process.myUid());
+        }
+
+        @Override
+        public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
+            if (listener == null) {
+                throw new IllegalArgumentException("listener must not be null");
+            }
+
+            registerDisplayTransactionListenerInternal(listener);
+        }
+
+        @Override
+        public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
+            if (listener == null) {
+                throw new IllegalArgumentException("listener must not be null");
+            }
+
+            unregisterDisplayTransactionListenerInternal(listener);
+        }
+
+        @Override
+        public void setDisplayInfoOverrideFromWindowManager(int displayId, DisplayInfo info) {
+            setDisplayInfoOverrideFromWindowManagerInternal(displayId, info);
+        }
+
+        @Override
+        public void performTraversalInTransactionFromWindowManager() {
+            performTraversalInTransactionFromWindowManagerInternal();
+        }
+
+        @Override
+        public void setDisplayHasContent(int displayId, boolean hasContent, boolean inTraversal) {
+            setDisplayHasContentInternal(displayId, hasContent, inTraversal);
+        }
+    }
+}
diff --git a/services/java/com/android/server/display/LocalDisplayAdapter.java b/services/core/java/com/android/server/display/LocalDisplayAdapter.java
similarity index 100%
rename from services/java/com/android/server/display/LocalDisplayAdapter.java
rename to services/core/java/com/android/server/display/LocalDisplayAdapter.java
diff --git a/services/java/com/android/server/display/LogicalDisplay.java b/services/core/java/com/android/server/display/LogicalDisplay.java
similarity index 100%
rename from services/java/com/android/server/display/LogicalDisplay.java
rename to services/core/java/com/android/server/display/LogicalDisplay.java
diff --git a/services/java/com/android/server/display/OverlayDisplayAdapter.java b/services/core/java/com/android/server/display/OverlayDisplayAdapter.java
similarity index 100%
rename from services/java/com/android/server/display/OverlayDisplayAdapter.java
rename to services/core/java/com/android/server/display/OverlayDisplayAdapter.java
diff --git a/services/java/com/android/server/display/OverlayDisplayWindow.java b/services/core/java/com/android/server/display/OverlayDisplayWindow.java
similarity index 100%
rename from services/java/com/android/server/display/OverlayDisplayWindow.java
rename to services/core/java/com/android/server/display/OverlayDisplayWindow.java
diff --git a/services/java/com/android/server/display/PersistentDataStore.java b/services/core/java/com/android/server/display/PersistentDataStore.java
similarity index 100%
rename from services/java/com/android/server/display/PersistentDataStore.java
rename to services/core/java/com/android/server/display/PersistentDataStore.java
diff --git a/services/core/java/com/android/server/display/VirtualDisplayAdapter.java b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
new file mode 100644
index 0000000..95ca0d2
--- /dev/null
+++ b/services/core/java/com/android/server/display/VirtualDisplayAdapter.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2013 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.display;
+
+import android.content.Context;
+import android.hardware.display.DisplayManager;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IBinder.DeathRecipient;
+import android.os.RemoteException;
+import android.util.ArrayMap;
+import android.util.Slog;
+import android.view.Display;
+import android.view.Surface;
+import android.view.SurfaceControl;
+
+/**
+ * A display adapter that provides virtual displays on behalf of applications.
+ * <p>
+ * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock.
+ * </p>
+ */
+final class VirtualDisplayAdapter extends DisplayAdapter {
+    static final String TAG = "VirtualDisplayAdapter";
+    static final boolean DEBUG = false;
+
+    private final ArrayMap<IBinder, VirtualDisplayDevice> mVirtualDisplayDevices =
+            new ArrayMap<IBinder, VirtualDisplayDevice>();
+
+    // Called with SyncRoot lock held.
+    public VirtualDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
+            Context context, Handler handler, Listener listener) {
+        super(syncRoot, context, handler, listener, TAG);
+    }
+
+    public DisplayDevice createVirtualDisplayLocked(IBinder appToken,
+            int ownerUid, String ownerPackageName,
+            String name, int width, int height, int densityDpi, Surface surface, int flags) {
+        boolean secure = (flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0;
+        IBinder displayToken = SurfaceControl.createDisplay(name, secure);
+        VirtualDisplayDevice device = new VirtualDisplayDevice(displayToken, appToken,
+                ownerUid, ownerPackageName, name, width, height, densityDpi, surface, flags);
+
+        try {
+            appToken.linkToDeath(device, 0);
+        } catch (RemoteException ex) {
+            device.destroyLocked();
+            return null;
+        }
+
+        mVirtualDisplayDevices.put(appToken, device);
+
+        // Return the display device without actually sending the event indicating
+        // that it was added.  The caller will handle it.
+        return device;
+    }
+
+    public DisplayDevice releaseVirtualDisplayLocked(IBinder appToken) {
+        VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
+        if (device != null) {
+            device.destroyLocked();
+            appToken.unlinkToDeath(device, 0);
+        }
+
+        // Return the display device that was removed without actually sending the
+        // event indicating that it was removed.  The caller will handle it.
+        return device;
+    }
+
+    private void handleBinderDiedLocked(IBinder appToken) {
+        VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
+        if (device != null) {
+            Slog.i(TAG, "Virtual display device released because application token died: "
+                    + device.mOwnerPackageName);
+            device.destroyLocked();
+            sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED);
+        }
+    }
+
+    private final class VirtualDisplayDevice extends DisplayDevice
+            implements DeathRecipient {
+        private final IBinder mAppToken;
+        private final int mOwnerUid;
+        final String mOwnerPackageName;
+        private final String mName;
+        private final int mWidth;
+        private final int mHeight;
+        private final int mDensityDpi;
+        private final int mFlags;
+
+        private Surface mSurface;
+        private DisplayDeviceInfo mInfo;
+
+        public VirtualDisplayDevice(IBinder displayToken,
+                IBinder appToken, int ownerUid, String ownerPackageName,
+                String name, int width, int height, int densityDpi, Surface surface, int flags) {
+            super(VirtualDisplayAdapter.this, displayToken);
+            mAppToken = appToken;
+            mOwnerUid = ownerUid;
+            mOwnerPackageName = ownerPackageName;
+            mName = name;
+            mWidth = width;
+            mHeight = height;
+            mDensityDpi = densityDpi;
+            mSurface = surface;
+            mFlags = flags;
+        }
+
+        @Override
+        public void binderDied() {
+            synchronized (getSyncRoot()) {
+                if (mSurface != null) {
+                    handleBinderDiedLocked(mAppToken);
+                }
+            }
+        }
+
+        public void destroyLocked() {
+            if (mSurface != null) {
+                mSurface.release();
+                mSurface = null;
+            }
+            SurfaceControl.destroyDisplay(getDisplayTokenLocked());
+        }
+
+        @Override
+        public void performTraversalInTransactionLocked() {
+            if (mSurface != null) {
+                setSurfaceInTransactionLocked(mSurface);
+            }
+        }
+
+        @Override
+        public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
+            if (mInfo == null) {
+                mInfo = new DisplayDeviceInfo();
+                mInfo.name = mName;
+                mInfo.width = mWidth;
+                mInfo.height = mHeight;
+                mInfo.refreshRate = 60;
+                mInfo.densityDpi = mDensityDpi;
+                mInfo.xDpi = mDensityDpi;
+                mInfo.yDpi = mDensityDpi;
+                mInfo.flags = 0;
+                if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0) {
+                    mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE
+                            | DisplayDeviceInfo.FLAG_NEVER_BLANK
+                            | DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY;
+                } else if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY) != 0) {
+                    mInfo.flags |= DisplayDeviceInfo.FLAG_OWN_CONTENT_ONLY;
+                }
+                if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
+                    mInfo.flags |= DisplayDeviceInfo.FLAG_SECURE;
+                }
+                if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION) != 0) {
+                    mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;
+                }
+                mInfo.type = Display.TYPE_VIRTUAL;
+                mInfo.touch = DisplayDeviceInfo.TOUCH_NONE;
+                mInfo.ownerUid = mOwnerUid;
+                mInfo.ownerPackageName = mOwnerPackageName;
+            }
+            return mInfo;
+        }
+    }
+}
diff --git a/services/java/com/android/server/display/WifiDisplayAdapter.java b/services/core/java/com/android/server/display/WifiDisplayAdapter.java
similarity index 100%
rename from services/java/com/android/server/display/WifiDisplayAdapter.java
rename to services/core/java/com/android/server/display/WifiDisplayAdapter.java
diff --git a/services/java/com/android/server/display/WifiDisplayController.java b/services/core/java/com/android/server/display/WifiDisplayController.java
similarity index 100%
rename from services/java/com/android/server/display/WifiDisplayController.java
rename to services/core/java/com/android/server/display/WifiDisplayController.java
diff --git a/services/core/java/com/android/server/dreams/DreamController.java b/services/core/java/com/android/server/dreams/DreamController.java
new file mode 100644
index 0000000..649b5c9
--- /dev/null
+++ b/services/core/java/com/android/server/dreams/DreamController.java
@@ -0,0 +1,280 @@
+/*
+ * 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.server.dreams;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.IBinder.DeathRecipient;
+import android.os.UserHandle;
+import android.service.dreams.DreamService;
+import android.service.dreams.IDreamService;
+import android.util.Slog;
+import android.view.IWindowManager;
+import android.view.WindowManager;
+import android.view.WindowManagerGlobal;
+
+import java.io.PrintWriter;
+import java.util.NoSuchElementException;
+
+/**
+ * Internal controller for starting and stopping the current dream and managing related state.
+ *
+ * Assumes all operations are called from the dream handler thread.
+ */
+final class DreamController {
+    private static final String TAG = "DreamController";
+
+    // How long we wait for a newly bound dream to create the service connection
+    private static final int DREAM_CONNECTION_TIMEOUT = 5 * 1000;
+
+    private final Context mContext;
+    private final Handler mHandler;
+    private final Listener mListener;
+    private final IWindowManager mIWindowManager;
+
+    private final Intent mDreamingStartedIntent = new Intent(Intent.ACTION_DREAMING_STARTED)
+            .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+    private final Intent mDreamingStoppedIntent = new Intent(Intent.ACTION_DREAMING_STOPPED)
+            .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+
+    private final Intent mCloseNotificationShadeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+
+    private DreamRecord mCurrentDream;
+
+    private final Runnable mStopUnconnectedDreamRunnable = new Runnable() {
+        @Override
+        public void run() {
+            if (mCurrentDream != null && mCurrentDream.mBound && !mCurrentDream.mConnected) {
+                Slog.w(TAG, "Bound dream did not connect in the time allotted");
+                stopDream();
+            }
+        }
+    };
+
+    public DreamController(Context context, Handler handler, Listener listener) {
+        mContext = context;
+        mHandler = handler;
+        mListener = listener;
+        mIWindowManager = WindowManagerGlobal.getWindowManagerService();
+    }
+
+    public void dump(PrintWriter pw) {
+        pw.println("Dreamland:");
+        if (mCurrentDream != null) {
+            pw.println("  mCurrentDream:");
+            pw.println("    mToken=" + mCurrentDream.mToken);
+            pw.println("    mName=" + mCurrentDream.mName);
+            pw.println("    mIsTest=" + mCurrentDream.mIsTest);
+            pw.println("    mCanDoze=" + mCurrentDream.mCanDoze);
+            pw.println("    mUserId=" + mCurrentDream.mUserId);
+            pw.println("    mBound=" + mCurrentDream.mBound);
+            pw.println("    mService=" + mCurrentDream.mService);
+            pw.println("    mSentStartBroadcast=" + mCurrentDream.mSentStartBroadcast);
+        } else {
+            pw.println("  mCurrentDream: null");
+        }
+    }
+
+    public void startDream(Binder token, ComponentName name,
+            boolean isTest, boolean canDoze, int userId) {
+        stopDream();
+
+        // Close the notification shade. Don't need to send to all, but better to be explicit.
+        mContext.sendBroadcastAsUser(mCloseNotificationShadeIntent, UserHandle.ALL);
+
+        Slog.i(TAG, "Starting dream: name=" + name
+                + ", isTest=" + isTest + ", canDoze=" + canDoze
+                + ", userId=" + userId);
+
+        mCurrentDream = new DreamRecord(token, name, isTest, canDoze, userId);
+
+        try {
+            mIWindowManager.addWindowToken(token, WindowManager.LayoutParams.TYPE_DREAM);
+        } catch (RemoteException ex) {
+            Slog.e(TAG, "Unable to add window token for dream.", ex);
+            stopDream();
+            return;
+        }
+
+        Intent intent = new Intent(DreamService.SERVICE_INTERFACE);
+        intent.setComponent(name);
+        intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+        try {
+            if (!mContext.bindServiceAsUser(intent, mCurrentDream,
+                    Context.BIND_AUTO_CREATE, new UserHandle(userId))) {
+                Slog.e(TAG, "Unable to bind dream service: " + intent);
+                stopDream();
+                return;
+            }
+        } catch (SecurityException ex) {
+            Slog.e(TAG, "Unable to bind dream service: " + intent, ex);
+            stopDream();
+            return;
+        }
+
+        mCurrentDream.mBound = true;
+        mHandler.postDelayed(mStopUnconnectedDreamRunnable, DREAM_CONNECTION_TIMEOUT);
+    }
+
+    public void stopDream() {
+        if (mCurrentDream == null) {
+            return;
+        }
+
+        final DreamRecord oldDream = mCurrentDream;
+        mCurrentDream = null;
+        Slog.i(TAG, "Stopping dream: name=" + oldDream.mName
+                + ", isTest=" + oldDream.mIsTest + ", canDoze=" + oldDream.mCanDoze
+                + ", userId=" + oldDream.mUserId);
+
+        mHandler.removeCallbacks(mStopUnconnectedDreamRunnable);
+
+        if (oldDream.mSentStartBroadcast) {
+            mContext.sendBroadcastAsUser(mDreamingStoppedIntent, UserHandle.ALL);
+        }
+
+        if (oldDream.mService != null) {
+            // Tell the dream that it's being stopped so that
+            // it can shut down nicely before we yank its window token out from
+            // under it.
+            try {
+                oldDream.mService.detach();
+            } catch (RemoteException ex) {
+                // we don't care; this thing is on the way out
+            }
+
+            try {
+                oldDream.mService.asBinder().unlinkToDeath(oldDream, 0);
+            } catch (NoSuchElementException ex) {
+                // don't care
+            }
+            oldDream.mService = null;
+        }
+
+        if (oldDream.mBound) {
+            mContext.unbindService(oldDream);
+        }
+
+        try {
+            mIWindowManager.removeWindowToken(oldDream.mToken);
+        } catch (RemoteException ex) {
+            Slog.w(TAG, "Error removing window token for dream.", ex);
+        }
+
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                mListener.onDreamStopped(oldDream.mToken);
+            }
+        });
+    }
+
+    private void attach(IDreamService service) {
+        try {
+            service.asBinder().linkToDeath(mCurrentDream, 0);
+            service.attach(mCurrentDream.mToken, mCurrentDream.mCanDoze);
+        } catch (RemoteException ex) {
+            Slog.e(TAG, "The dream service died unexpectedly.", ex);
+            stopDream();
+            return;
+        }
+
+        mCurrentDream.mService = service;
+
+        if (!mCurrentDream.mIsTest) {
+            mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL);
+            mCurrentDream.mSentStartBroadcast = true;
+        }
+    }
+
+    /**
+     * Callback interface to be implemented by the {@link DreamManagerService}.
+     */
+    public interface Listener {
+        void onDreamStopped(Binder token);
+    }
+
+    private final class DreamRecord implements DeathRecipient, ServiceConnection {
+        public final Binder mToken;
+        public final ComponentName mName;
+        public final boolean mIsTest;
+        public final boolean mCanDoze;
+        public final int mUserId;
+
+        public boolean mBound;
+        public boolean mConnected;
+        public IDreamService mService;
+        public boolean mSentStartBroadcast;
+
+        public DreamRecord(Binder token, ComponentName name,
+                boolean isTest, boolean canDoze, int userId) {
+            mToken = token;
+            mName = name;
+            mIsTest = isTest;
+            mCanDoze = canDoze;
+            mUserId  = userId;
+        }
+
+        // May be called on any thread.
+        @Override
+        public void binderDied() {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    mService = null;
+                    if (mCurrentDream == DreamRecord.this) {
+                        stopDream();
+                    }
+                }
+            });
+        }
+
+        // May be called on any thread.
+        @Override
+        public void onServiceConnected(ComponentName name, final IBinder service) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    mConnected = true;
+                    if (mCurrentDream == DreamRecord.this && mService == null) {
+                        attach(IDreamService.Stub.asInterface(service));
+                    }
+                }
+            });
+        }
+
+        // May be called on any thread.
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    mService = null;
+                    if (mCurrentDream == DreamRecord.this) {
+                        stopDream();
+                    }
+                }
+            });
+        }
+    }
+}
\ No newline at end of file
diff --git a/services/core/java/com/android/server/dreams/DreamManagerService.java b/services/core/java/com/android/server/dreams/DreamManagerService.java
new file mode 100644
index 0000000..fd2f8a1
--- /dev/null
+++ b/services/core/java/com/android/server/dreams/DreamManagerService.java
@@ -0,0 +1,655 @@
+/*
+ * 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.server.dreams;
+
+import com.android.internal.util.DumpUtils;
+import com.android.server.FgThread;
+import com.android.server.SystemService;
+
+import android.Manifest;
+import android.app.ActivityManager;
+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.content.pm.PackageManager.NameNotFoundException;
+import android.os.Binder;
+import android.os.Build;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.service.dreams.DreamManagerInternal;
+import android.service.dreams.DreamService;
+import android.service.dreams.IDozeHardware;
+import android.service.dreams.IDreamManager;
+import android.text.TextUtils;
+import android.util.Slog;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import libcore.util.Objects;
+
+/**
+ * Service api for managing dreams.
+ *
+ * @hide
+ */
+public final class DreamManagerService extends SystemService {
+    private static final boolean DEBUG = false;
+    private static final String TAG = "DreamManagerService";
+
+    private final Object mLock = new Object();
+
+    private final Context mContext;
+    private final DreamHandler mHandler;
+    private final DreamController mController;
+    private final PowerManager mPowerManager;
+    private final PowerManager.WakeLock mDozeWakeLock;
+    private final McuHal mMcuHal; // synchronized on self
+
+    private Binder mCurrentDreamToken;
+    private ComponentName mCurrentDreamName;
+    private int mCurrentDreamUserId;
+    private boolean mCurrentDreamIsTest;
+    private boolean mCurrentDreamCanDoze;
+    private boolean mCurrentDreamIsDozing;
+    private DozeHardwareWrapper mCurrentDreamDozeHardware;
+
+    public DreamManagerService(Context context) {
+        super(context);
+        mContext = context;
+        mHandler = new DreamHandler(FgThread.get().getLooper());
+        mController = new DreamController(context, mHandler, mControllerListener);
+
+        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+        mDozeWakeLock = mPowerManager.newWakeLock(PowerManager.DOZE_WAKE_LOCK, TAG);
+
+        mMcuHal = McuHal.open();
+        if (mMcuHal != null) {
+            mMcuHal.reset();
+        }
+    }
+
+    @Override
+    public void onStart() {
+        publishBinderService(DreamService.DREAM_SERVICE, new BinderService());
+        publishLocalService(DreamManagerInternal.class, new LocalService());
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
+            mContext.registerReceiver(new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    synchronized (mLock) {
+                        stopDreamLocked();
+                    }
+                }
+            }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
+        }
+    }
+
+    private void dumpInternal(PrintWriter pw) {
+        pw.println("DREAM MANAGER (dumpsys dreams)");
+        pw.println();
+
+        pw.println("mMcuHal=" + mMcuHal);
+        pw.println();
+        pw.println("mCurrentDreamToken=" + mCurrentDreamToken);
+        pw.println("mCurrentDreamName=" + mCurrentDreamName);
+        pw.println("mCurrentDreamUserId=" + mCurrentDreamUserId);
+        pw.println("mCurrentDreamIsTest=" + mCurrentDreamIsTest);
+        pw.println("mCurrentDreamCanDoze=" + mCurrentDreamCanDoze);
+        pw.println("mCurrentDreamIsDozing=" + mCurrentDreamIsDozing);
+        pw.println("mCurrentDreamDozeHardware=" + mCurrentDreamDozeHardware);
+        pw.println();
+
+        DumpUtils.dumpAsync(mHandler, new DumpUtils.Dump() {
+            @Override
+            public void dump(PrintWriter pw) {
+                mController.dump(pw);
+            }
+        }, pw, 200);
+    }
+
+    private boolean isDreamingInternal() {
+        synchronized (mLock) {
+            return mCurrentDreamToken != null && !mCurrentDreamIsTest;
+        }
+    }
+
+    private void requestDreamInternal() {
+        // Ask the power manager to nap.  It will eventually call back into
+        // startDream() if/when it is appropriate to start dreaming.
+        // Because napping could cause the screen to turn off immediately if the dream
+        // cannot be started, we keep one eye open and gently poke user activity.
+        long time = SystemClock.uptimeMillis();
+        mPowerManager.userActivity(time, true /*noChangeLights*/);
+        mPowerManager.nap(time);
+    }
+
+    private void requestAwakenInternal() {
+        // Treat an explicit request to awaken as user activity so that the
+        // device doesn't immediately go to sleep if the timeout expired,
+        // for example when being undocked.
+        long time = SystemClock.uptimeMillis();
+        mPowerManager.userActivity(time, false /*noChangeLights*/);
+        stopDreamInternal();
+    }
+
+    private void finishSelfInternal(IBinder token) {
+        if (DEBUG) {
+            Slog.d(TAG, "Dream finished: " + token);
+        }
+
+        // Note that a dream finishing and self-terminating is not
+        // itself considered user activity.  If the dream is ending because
+        // the user interacted with the device then user activity will already
+        // have been poked so the device will stay awake a bit longer.
+        // If the dream is ending on its own for other reasons and no wake
+        // locks are held and the user activity timeout has expired then the
+        // device may simply go to sleep.
+        synchronized (mLock) {
+            if (mCurrentDreamToken == token) {
+                stopDreamLocked();
+            }
+        }
+    }
+
+    private void testDreamInternal(ComponentName dream, int userId) {
+        synchronized (mLock) {
+            startDreamLocked(dream, true /*isTest*/, false /*canDoze*/, userId);
+        }
+    }
+
+    private void startDreamInternal(boolean doze) {
+        final int userId = ActivityManager.getCurrentUser();
+        final ComponentName dream = doze ? getDozeComponent() : chooseDreamForUser(userId);
+        if (dream != null) {
+            synchronized (mLock) {
+                startDreamLocked(dream, false /*isTest*/, doze, userId);
+            }
+        }
+    }
+
+    private void stopDreamInternal() {
+        synchronized (mLock) {
+            stopDreamLocked();
+        }
+    }
+
+    private void startDozingInternal(IBinder token) {
+        if (DEBUG) {
+            Slog.d(TAG, "Dream requested to start dozing: " + token);
+        }
+
+        synchronized (mLock) {
+            if (mCurrentDreamToken == token && mCurrentDreamCanDoze
+                    && !mCurrentDreamIsDozing) {
+                mCurrentDreamIsDozing = true;
+                mDozeWakeLock.acquire();
+            }
+        }
+    }
+
+    private void stopDozingInternal(IBinder token) {
+        if (DEBUG) {
+            Slog.d(TAG, "Dream requested to stop dozing: " + token);
+        }
+
+        synchronized (mLock) {
+            if (mCurrentDreamToken == token && mCurrentDreamIsDozing) {
+                mCurrentDreamIsDozing = false;
+                mDozeWakeLock.release();
+            }
+        }
+    }
+
+    private IDozeHardware getDozeHardwareInternal(IBinder token) {
+        synchronized (mLock) {
+            if (mCurrentDreamToken == token && mCurrentDreamCanDoze
+                    && mCurrentDreamDozeHardware == null && mMcuHal != null) {
+                mCurrentDreamDozeHardware = new DozeHardwareWrapper();
+                return mCurrentDreamDozeHardware;
+            }
+            return null;
+        }
+    }
+
+    private ComponentName chooseDreamForUser(int userId) {
+        ComponentName[] dreams = getDreamComponentsForUser(userId);
+        return dreams != null && dreams.length != 0 ? dreams[0] : null;
+    }
+
+    private ComponentName[] getDreamComponentsForUser(int userId) {
+        String names = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+                Settings.Secure.SCREENSAVER_COMPONENTS,
+                userId);
+        ComponentName[] components = componentsFromString(names);
+
+        // first, ensure components point to valid services
+        List<ComponentName> validComponents = new ArrayList<ComponentName>();
+        if (components != null) {
+            for (ComponentName component : components) {
+                if (serviceExists(component)) {
+                    validComponents.add(component);
+                } else {
+                    Slog.w(TAG, "Dream " + component + " does not exist");
+                }
+            }
+        }
+
+        // fallback to the default dream component if necessary
+        if (validComponents.isEmpty()) {
+            ComponentName defaultDream = getDefaultDreamComponentForUser(userId);
+            if (defaultDream != null) {
+                Slog.w(TAG, "Falling back to default dream " + defaultDream);
+                validComponents.add(defaultDream);
+            }
+        }
+        return validComponents.toArray(new ComponentName[validComponents.size()]);
+    }
+
+    private void setDreamComponentsForUser(int userId, ComponentName[] componentNames) {
+        Settings.Secure.putStringForUser(mContext.getContentResolver(),
+                Settings.Secure.SCREENSAVER_COMPONENTS,
+                componentsToString(componentNames),
+                userId);
+    }
+
+    private ComponentName getDefaultDreamComponentForUser(int userId) {
+        String name = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+                Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
+                userId);
+        return name == null ? null : ComponentName.unflattenFromString(name);
+    }
+
+    private ComponentName getDozeComponent() {
+        // Read the component from a system property to facilitate debugging.
+        // Note that for production devices, the dream should actually be declared in
+        // a config.xml resource.
+        String name = Build.IS_DEBUGGABLE ? SystemProperties.get("debug.doze.component") : null;
+        if (TextUtils.isEmpty(name)) {
+            // Read the component from a config.xml resource.
+            // The value should be specified in a resource overlay for the product.
+            name = mContext.getResources().getString(
+                    com.android.internal.R.string.config_dozeComponent);
+        }
+        return TextUtils.isEmpty(name) ? null : ComponentName.unflattenFromString(name);
+    }
+
+    private boolean serviceExists(ComponentName name) {
+        try {
+            return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null;
+        } catch (NameNotFoundException e) {
+            return false;
+        }
+    }
+
+    private void startDreamLocked(final ComponentName name,
+            final boolean isTest, final boolean canDoze, final int userId) {
+        if (Objects.equal(mCurrentDreamName, name)
+                && mCurrentDreamIsTest == isTest
+                && mCurrentDreamCanDoze == canDoze
+                && mCurrentDreamUserId == userId) {
+            return;
+        }
+
+        stopDreamLocked();
+
+        if (DEBUG) Slog.i(TAG, "Entering dreamland.");
+
+        final Binder newToken = new Binder();
+        mCurrentDreamToken = newToken;
+        mCurrentDreamName = name;
+        mCurrentDreamIsTest = isTest;
+        mCurrentDreamCanDoze = canDoze;
+        mCurrentDreamUserId = userId;
+
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                mController.startDream(newToken, name, isTest, canDoze, userId);
+            }
+        });
+    }
+
+    private void stopDreamLocked() {
+        if (mCurrentDreamToken != null) {
+            if (DEBUG) Slog.i(TAG, "Leaving dreamland.");
+
+            cleanupDreamLocked();
+
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    mController.stopDream();
+                }
+            });
+        }
+    }
+
+    private void cleanupDreamLocked() {
+        mCurrentDreamToken = null;
+        mCurrentDreamName = null;
+        mCurrentDreamIsTest = false;
+        mCurrentDreamCanDoze = false;
+        mCurrentDreamUserId = 0;
+        if (mCurrentDreamIsDozing) {
+            mCurrentDreamIsDozing = false;
+            mDozeWakeLock.release();
+        }
+        if (mCurrentDreamDozeHardware != null) {
+            mCurrentDreamDozeHardware.release();
+            mCurrentDreamDozeHardware = null;
+        }
+    }
+
+    private void checkPermission(String permission) {
+        if (mContext.checkCallingOrSelfPermission(permission)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
+                    + ", must have permission " + permission);
+        }
+    }
+
+    private static String componentsToString(ComponentName[] componentNames) {
+        StringBuilder names = new StringBuilder();
+        if (componentNames != null) {
+            for (ComponentName componentName : componentNames) {
+                if (names.length() > 0) {
+                    names.append(',');
+                }
+                names.append(componentName.flattenToString());
+            }
+        }
+        return names.toString();
+    }
+
+    private static ComponentName[] componentsFromString(String names) {
+        if (names == null) {
+            return null;
+        }
+        String[] namesArray = names.split(",");
+        ComponentName[] componentNames = new ComponentName[namesArray.length];
+        for (int i = 0; i < namesArray.length; i++) {
+            componentNames[i] = ComponentName.unflattenFromString(namesArray[i]);
+        }
+        return componentNames;
+    }
+
+    private final DreamController.Listener mControllerListener = new DreamController.Listener() {
+        @Override
+        public void onDreamStopped(Binder token) {
+            synchronized (mLock) {
+                if (mCurrentDreamToken == token) {
+                    cleanupDreamLocked();
+                }
+            }
+        }
+    };
+
+    /**
+     * Handler for asynchronous operations performed by the dream manager.
+     * Ensures operations to {@link DreamController} are single-threaded.
+     */
+    private final class DreamHandler extends Handler {
+        public DreamHandler(Looper looper) {
+            super(looper, null, true /*async*/);
+        }
+    }
+
+    private final class BinderService extends IDreamManager.Stub {
+        @Override // Binder call
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump DreamManager from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                dumpInternal(pw);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public ComponentName[] getDreamComponents() {
+            checkPermission(android.Manifest.permission.READ_DREAM_STATE);
+
+            final int userId = UserHandle.getCallingUserId();
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return getDreamComponentsForUser(userId);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void setDreamComponents(ComponentName[] componentNames) {
+            checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
+
+            final int userId = UserHandle.getCallingUserId();
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setDreamComponentsForUser(userId, componentNames);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public ComponentName getDefaultDreamComponent() {
+            checkPermission(android.Manifest.permission.READ_DREAM_STATE);
+
+            final int userId = UserHandle.getCallingUserId();
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return getDefaultDreamComponentForUser(userId);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public boolean isDreaming() {
+            checkPermission(android.Manifest.permission.READ_DREAM_STATE);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return isDreamingInternal();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void dream() {
+            checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                requestDreamInternal();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void testDream(ComponentName dream) {
+            if (dream == null) {
+                throw new IllegalArgumentException("dream must not be null");
+            }
+            checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
+
+            final int callingUserId = UserHandle.getCallingUserId();
+            final int currentUserId = ActivityManager.getCurrentUser();
+            if (callingUserId != currentUserId) {
+                // This check is inherently prone to races but at least it's something.
+                Slog.w(TAG, "Aborted attempt to start a test dream while a different "
+                        + " user is active: callingUserId=" + callingUserId
+                        + ", currentUserId=" + currentUserId);
+                return;
+            }
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                testDreamInternal(dream, callingUserId);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void awaken() {
+            checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                requestAwakenInternal();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void finishSelf(IBinder token) {
+            // Requires no permission, called by Dream from an arbitrary process.
+            if (token == null) {
+                throw new IllegalArgumentException("token must not be null");
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                finishSelfInternal(token);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void startDozing(IBinder token) {
+            // Requires no permission, called by Dream from an arbitrary process.
+            if (token == null) {
+                throw new IllegalArgumentException("token must not be null");
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                startDozingInternal(token);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void stopDozing(IBinder token) {
+            // Requires no permission, called by Dream from an arbitrary process.
+            if (token == null) {
+                throw new IllegalArgumentException("token must not be null");
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                stopDozingInternal(token);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public IDozeHardware getDozeHardware(IBinder token) {
+            // Requires no permission, called by Dream from an arbitrary process.
+            if (token == null) {
+                throw new IllegalArgumentException("token must not be null");
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return getDozeHardwareInternal(token);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    private final class LocalService extends DreamManagerInternal {
+        @Override
+        public void startDream(boolean doze) {
+            startDreamInternal(doze);
+        }
+
+        @Override
+        public void stopDream() {
+            stopDreamInternal();
+        }
+
+        @Override
+        public boolean isDreaming() {
+            return isDreamingInternal();
+        }
+    }
+
+    private final class DozeHardwareWrapper extends IDozeHardware.Stub {
+        private boolean mReleased;
+
+        public void release() {
+            synchronized (mMcuHal) {
+                if (!mReleased) {
+                    mReleased = true;
+                    mMcuHal.reset();
+                }
+            }
+        }
+
+        @Override // Binder call
+        public byte[] sendMessage(String msg, byte[] arg) {
+            if (msg == null) {
+                throw new IllegalArgumentException("msg must not be null");
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                synchronized (mMcuHal) {
+                    if (mReleased) {
+                        throw new IllegalStateException("This operation cannot be performed "
+                                + "because the dream has ended.");
+                    }
+                    return mMcuHal.sendMessage(msg, arg);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/dreams/McuHal.java b/services/core/java/com/android/server/dreams/McuHal.java
new file mode 100644
index 0000000..1dc79c7
--- /dev/null
+++ b/services/core/java/com/android/server/dreams/McuHal.java
@@ -0,0 +1,46 @@
+/*
+ * 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.server.dreams;
+
+import android.service.dreams.DozeHardware;
+
+/**
+ * Provides access to the low-level microcontroller hardware abstraction layer.
+ */
+final class McuHal {
+    private final long mPtr;
+
+    private static native long nativeOpen();
+    private static native byte[] nativeSendMessage(long ptr, String msg, byte[] arg);
+
+    private McuHal(long ptr) {
+        mPtr = ptr;
+    }
+
+    public static McuHal open() {
+        long ptr = nativeOpen();
+        return ptr != 0 ? new McuHal(ptr) : null;
+    }
+
+    public void reset() {
+        sendMessage(DozeHardware.MSG_ENABLE_MCU, DozeHardware.VALUE_OFF);
+    }
+
+    public byte[] sendMessage(String msg, byte[] arg) {
+        return nativeSendMessage(mPtr, msg, arg);
+    }
+}
diff --git a/services/java/com/android/server/firewall/AndFilter.java b/services/core/java/com/android/server/firewall/AndFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/AndFilter.java
rename to services/core/java/com/android/server/firewall/AndFilter.java
diff --git a/services/java/com/android/server/firewall/CategoryFilter.java b/services/core/java/com/android/server/firewall/CategoryFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/CategoryFilter.java
rename to services/core/java/com/android/server/firewall/CategoryFilter.java
diff --git a/services/java/com/android/server/firewall/Filter.java b/services/core/java/com/android/server/firewall/Filter.java
similarity index 100%
rename from services/java/com/android/server/firewall/Filter.java
rename to services/core/java/com/android/server/firewall/Filter.java
diff --git a/services/java/com/android/server/firewall/FilterFactory.java b/services/core/java/com/android/server/firewall/FilterFactory.java
similarity index 100%
rename from services/java/com/android/server/firewall/FilterFactory.java
rename to services/core/java/com/android/server/firewall/FilterFactory.java
diff --git a/services/java/com/android/server/firewall/FilterList.java b/services/core/java/com/android/server/firewall/FilterList.java
similarity index 100%
rename from services/java/com/android/server/firewall/FilterList.java
rename to services/core/java/com/android/server/firewall/FilterList.java
diff --git a/services/core/java/com/android/server/firewall/IntentFirewall.java b/services/core/java/com/android/server/firewall/IntentFirewall.java
new file mode 100644
index 0000000..88a2207
--- /dev/null
+++ b/services/core/java/com/android/server/firewall/IntentFirewall.java
@@ -0,0 +1,609 @@
+/*
+ * Copyright (C) 2013 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.firewall;
+
+import android.app.AppGlobals;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageManager;
+import android.os.Environment;
+import android.os.FileObserver;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.util.ArrayMap;
+import android.util.Slog;
+import android.util.Xml;
+import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.XmlUtils;
+import com.android.server.EventLogTags;
+import com.android.server.IntentResolver;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+public class IntentFirewall {
+    static final String TAG = "IntentFirewall";
+
+    // e.g. /data/system/ifw or /data/secure/system/ifw
+    private static final File RULES_DIR = new File(Environment.getSystemSecureDirectory(), "ifw");
+
+    private static final int LOG_PACKAGES_MAX_LENGTH = 150;
+    private static final int LOG_PACKAGES_SUFFICIENT_LENGTH = 125;
+
+    private static final String TAG_RULES = "rules";
+    private static final String TAG_ACTIVITY = "activity";
+    private static final String TAG_SERVICE = "service";
+    private static final String TAG_BROADCAST = "broadcast";
+
+    private static final int TYPE_ACTIVITY = 0;
+    private static final int TYPE_BROADCAST = 1;
+    private static final int TYPE_SERVICE = 2;
+
+    private static final HashMap<String, FilterFactory> factoryMap;
+
+    private final AMSInterface mAms;
+
+    private final RuleObserver mObserver;
+
+    private FirewallIntentResolver mActivityResolver = new FirewallIntentResolver();
+    private FirewallIntentResolver mBroadcastResolver = new FirewallIntentResolver();
+    private FirewallIntentResolver mServiceResolver = new FirewallIntentResolver();
+
+    static {
+        FilterFactory[] factories = new FilterFactory[] {
+                AndFilter.FACTORY,
+                OrFilter.FACTORY,
+                NotFilter.FACTORY,
+
+                StringFilter.ACTION,
+                StringFilter.COMPONENT,
+                StringFilter.COMPONENT_NAME,
+                StringFilter.COMPONENT_PACKAGE,
+                StringFilter.DATA,
+                StringFilter.HOST,
+                StringFilter.MIME_TYPE,
+                StringFilter.SCHEME,
+                StringFilter.PATH,
+                StringFilter.SSP,
+
+                CategoryFilter.FACTORY,
+                SenderFilter.FACTORY,
+                SenderPermissionFilter.FACTORY,
+                PortFilter.FACTORY
+        };
+
+        // load factor ~= .75
+        factoryMap = new HashMap<String, FilterFactory>(factories.length * 4 / 3);
+        for (int i=0; i<factories.length; i++) {
+            FilterFactory factory = factories[i];
+            factoryMap.put(factory.getTagName(), factory);
+        }
+    }
+
+    public IntentFirewall(AMSInterface ams, Handler handler) {
+        mAms = ams;
+        mHandler = new FirewallHandler(handler.getLooper());
+        File rulesDir = getRulesDir();
+        rulesDir.mkdirs();
+
+        readRulesDir(rulesDir);
+
+        mObserver = new RuleObserver(rulesDir);
+        mObserver.startWatching();
+    }
+
+    /**
+     * This is called from ActivityManager to check if a start activity intent should be allowed.
+     * It is assumed the caller is already holding the global ActivityManagerService lock.
+     */
+    public boolean checkStartActivity(Intent intent, int callerUid, int callerPid,
+            String resolvedType, ApplicationInfo resolvedApp) {
+        return checkIntent(mActivityResolver, intent.getComponent(), TYPE_ACTIVITY, intent,
+                callerUid, callerPid, resolvedType, resolvedApp.uid);
+    }
+
+    public boolean checkService(ComponentName resolvedService, Intent intent, int callerUid,
+            int callerPid, String resolvedType, ApplicationInfo resolvedApp) {
+        return checkIntent(mServiceResolver, resolvedService, TYPE_SERVICE, intent, callerUid,
+                callerPid, resolvedType, resolvedApp.uid);
+    }
+
+    public boolean checkBroadcast(Intent intent, int callerUid, int callerPid,
+            String resolvedType, int receivingUid) {
+        return checkIntent(mBroadcastResolver, intent.getComponent(), TYPE_BROADCAST, intent,
+                callerUid, callerPid, resolvedType, receivingUid);
+    }
+
+    public boolean checkIntent(FirewallIntentResolver resolver, ComponentName resolvedComponent,
+            int intentType, Intent intent, int callerUid, int callerPid, String resolvedType,
+            int receivingUid) {
+        boolean log = false;
+        boolean block = false;
+
+        // For the first pass, find all the rules that have at least one intent-filter or
+        // component-filter that matches this intent
+        List<Rule> candidateRules;
+        candidateRules = resolver.queryIntent(intent, resolvedType, false, 0);
+        if (candidateRules == null) {
+            candidateRules = new ArrayList<Rule>();
+        }
+        resolver.queryByComponent(resolvedComponent, candidateRules);
+
+        // For the second pass, try to match the potentially more specific conditions in each
+        // rule against the intent
+        for (int i=0; i<candidateRules.size(); i++) {
+            Rule rule = candidateRules.get(i);
+            if (rule.matches(this, resolvedComponent, intent, callerUid, callerPid, resolvedType,
+                    receivingUid)) {
+                block |= rule.getBlock();
+                log |= rule.getLog();
+
+                // if we've already determined that we should both block and log, there's no need
+                // to continue trying rules
+                if (block && log) {
+                    break;
+                }
+            }
+        }
+
+        if (log) {
+            logIntent(intentType, intent, callerUid, resolvedType);
+        }
+
+        return !block;
+    }
+
+    private static void logIntent(int intentType, Intent intent, int callerUid,
+            String resolvedType) {
+        // The component shouldn't be null, but let's double check just to be safe
+        ComponentName cn = intent.getComponent();
+        String shortComponent = null;
+        if (cn != null) {
+            shortComponent = cn.flattenToShortString();
+        }
+
+        String callerPackages = null;
+        int callerPackageCount = 0;
+        IPackageManager pm = AppGlobals.getPackageManager();
+        if (pm != null) {
+            try {
+                String[] callerPackagesArray = pm.getPackagesForUid(callerUid);
+                if (callerPackagesArray != null) {
+                    callerPackageCount = callerPackagesArray.length;
+                    callerPackages = joinPackages(callerPackagesArray);
+                }
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Remote exception while retrieving packages", ex);
+            }
+        }
+
+        EventLogTags.writeIfwIntentMatched(intentType, shortComponent, callerUid,
+                callerPackageCount, callerPackages, intent.getAction(), resolvedType,
+                intent.getDataString(), intent.getFlags());
+    }
+
+    /**
+     * Joins a list of package names such that the resulting string is no more than
+     * LOG_PACKAGES_MAX_LENGTH.
+     *
+     * Only full package names will be added to the result, unless every package is longer than the
+     * limit, in which case one of the packages will be truncated and added. In this case, an
+     * additional '-' character will be added to the end of the string, to denote the truncation.
+     *
+     * If it encounters a package that won't fit in the remaining space, it will continue on to the
+     * next package, unless the total length of the built string so far is greater than
+     * LOG_PACKAGES_SUFFICIENT_LENGTH, in which case it will stop and return what it has.
+     */
+    private static String joinPackages(String[] packages) {
+        boolean first = true;
+        StringBuilder sb = new StringBuilder();
+        for (int i=0; i<packages.length; i++) {
+            String pkg = packages[i];
+
+            // + 1 length for the comma. This logic technically isn't correct for the first entry,
+            // but it's not critical.
+            if (sb.length() + pkg.length() + 1 < LOG_PACKAGES_MAX_LENGTH) {
+                if (!first) {
+                    sb.append(',');
+                } else {
+                    first = false;
+                }
+                sb.append(pkg);
+            } else if (sb.length() >= LOG_PACKAGES_SUFFICIENT_LENGTH) {
+                return sb.toString();
+            }
+        }
+        if (sb.length() == 0 && packages.length > 0) {
+            String pkg = packages[0];
+            // truncating from the end - the last part of the package name is more likely to be
+            // interesting/unique
+            return pkg.substring(pkg.length() - LOG_PACKAGES_MAX_LENGTH + 1) + '-';
+        }
+        return null;
+    }
+
+    public static File getRulesDir() {
+        return RULES_DIR;
+    }
+
+    /**
+     * Reads rules from all xml files (*.xml) in the given directory, and replaces our set of rules
+     * with the newly read rules.
+     *
+     * We only check for files ending in ".xml", to allow for temporary files that are atomically
+     * renamed to .xml
+     *
+     * All calls to this method from the file observer come through a handler and are inherently
+     * serialized
+     */
+    private void readRulesDir(File rulesDir) {
+        FirewallIntentResolver[] resolvers = new FirewallIntentResolver[3];
+        for (int i=0; i<resolvers.length; i++) {
+            resolvers[i] = new FirewallIntentResolver();
+        }
+
+        File[] files = rulesDir.listFiles();
+        for (int i=0; i<files.length; i++) {
+            File file = files[i];
+
+            if (file.getName().endsWith(".xml")) {
+                readRules(file, resolvers);
+            }
+        }
+
+        Slog.i(TAG, "Read new rules (A:" + resolvers[TYPE_ACTIVITY].filterSet().size() +
+                " B:" + resolvers[TYPE_BROADCAST].filterSet().size() +
+                " S:" + resolvers[TYPE_SERVICE].filterSet().size() + ")");
+
+        synchronized (mAms.getAMSLock()) {
+            mActivityResolver = resolvers[TYPE_ACTIVITY];
+            mBroadcastResolver = resolvers[TYPE_BROADCAST];
+            mServiceResolver = resolvers[TYPE_SERVICE];
+        }
+    }
+
+    /**
+     * Reads rules from the given file and add them to the given resolvers
+     */
+    private void readRules(File rulesFile, FirewallIntentResolver[] resolvers) {
+        // some temporary lists to hold the rules while we parse the xml file, so that we can
+        // add the rules all at once, after we know there weren't any major structural problems
+        // with the xml file
+        List<List<Rule>> rulesByType = new ArrayList<List<Rule>>(3);
+        for (int i=0; i<3; i++) {
+            rulesByType.add(new ArrayList<Rule>());
+        }
+
+        FileInputStream fis;
+        try {
+            fis = new FileInputStream(rulesFile);
+        } catch (FileNotFoundException ex) {
+            // Nope, no rules. Nothing else to do!
+            return;
+        }
+
+        try {
+            XmlPullParser parser = Xml.newPullParser();
+
+            parser.setInput(fis, null);
+
+            XmlUtils.beginDocument(parser, TAG_RULES);
+
+            int outerDepth = parser.getDepth();
+            while (XmlUtils.nextElementWithin(parser, outerDepth)) {
+                int ruleType = -1;
+
+                String tagName = parser.getName();
+                if (tagName.equals(TAG_ACTIVITY)) {
+                    ruleType = TYPE_ACTIVITY;
+                } else if (tagName.equals(TAG_BROADCAST)) {
+                    ruleType = TYPE_BROADCAST;
+                } else if (tagName.equals(TAG_SERVICE)) {
+                    ruleType = TYPE_SERVICE;
+                }
+
+                if (ruleType != -1) {
+                    Rule rule = new Rule();
+
+                    List<Rule> rules = rulesByType.get(ruleType);
+
+                    // if we get an error while parsing a particular rule, we'll just ignore
+                    // that rule and continue on with the next rule
+                    try {
+                        rule.readFromXml(parser);
+                    } catch (XmlPullParserException ex) {
+                        Slog.e(TAG, "Error reading an intent firewall rule from " + rulesFile, ex);
+                        continue;
+                    }
+
+                    rules.add(rule);
+                }
+            }
+        } catch (XmlPullParserException ex) {
+            // if there was an error outside of a specific rule, then there are probably
+            // structural problems with the xml file, and we should completely ignore it
+            Slog.e(TAG, "Error reading intent firewall rules from " + rulesFile, ex);
+            return;
+        } catch (IOException ex) {
+            Slog.e(TAG, "Error reading intent firewall rules from " + rulesFile, ex);
+            return;
+        } finally {
+            try {
+                fis.close();
+            } catch (IOException ex) {
+                Slog.e(TAG, "Error while closing " + rulesFile, ex);
+            }
+        }
+
+        for (int ruleType=0; ruleType<rulesByType.size(); ruleType++) {
+            List<Rule> rules = rulesByType.get(ruleType);
+            FirewallIntentResolver resolver = resolvers[ruleType];
+
+            for (int ruleIndex=0; ruleIndex<rules.size(); ruleIndex++) {
+                Rule rule = rules.get(ruleIndex);
+                for (int i=0; i<rule.getIntentFilterCount(); i++) {
+                    resolver.addFilter(rule.getIntentFilter(i));
+                }
+                for (int i=0; i<rule.getComponentFilterCount(); i++) {
+                    resolver.addComponentFilter(rule.getComponentFilter(i), rule);
+                }
+            }
+        }
+    }
+
+    static Filter parseFilter(XmlPullParser parser) throws IOException, XmlPullParserException {
+        String elementName = parser.getName();
+
+        FilterFactory factory = factoryMap.get(elementName);
+
+        if (factory == null) {
+            throw new XmlPullParserException("Unknown element in filter list: " + elementName);
+        }
+        return factory.newFilter(parser);
+    }
+
+    /**
+     * Represents a single activity/service/broadcast rule within one of the xml files.
+     *
+     * Rules are matched against an incoming intent in two phases. The goal of the first phase
+     * is to select a subset of rules that might match a given intent.
+     *
+     * For the first phase, we use a combination of intent filters (via an IntentResolver)
+     * and component filters to select which rules to check. If a rule has multiple intent or
+     * component filters, only a single filter must match for the rule to be passed on to the
+     * second phase.
+     *
+     * In the second phase, we check the specific conditions in each rule against the values in the
+     * intent. All top level conditions (but not filters) in the rule must match for the rule as a
+     * whole to match.
+     *
+     * If the rule matches, then we block or log the intent, as specified by the rule. If multiple
+     * rules match, we combine the block/log flags from any matching rule.
+     */
+    private static class Rule extends AndFilter {
+        private static final String TAG_INTENT_FILTER = "intent-filter";
+        private static final String TAG_COMPONENT_FILTER = "component-filter";
+        private static final String ATTR_NAME = "name";
+
+        private static final String ATTR_BLOCK = "block";
+        private static final String ATTR_LOG = "log";
+
+        private final ArrayList<FirewallIntentFilter> mIntentFilters =
+                new ArrayList<FirewallIntentFilter>(1);
+        private final ArrayList<ComponentName> mComponentFilters = new ArrayList<ComponentName>(0);
+        private boolean block;
+        private boolean log;
+
+        @Override
+        public Rule readFromXml(XmlPullParser parser) throws IOException, XmlPullParserException {
+            block = Boolean.parseBoolean(parser.getAttributeValue(null, ATTR_BLOCK));
+            log = Boolean.parseBoolean(parser.getAttributeValue(null, ATTR_LOG));
+
+            super.readFromXml(parser);
+            return this;
+        }
+
+        @Override
+        protected void readChild(XmlPullParser parser) throws IOException, XmlPullParserException {
+            String currentTag = parser.getName();
+
+            if (currentTag.equals(TAG_INTENT_FILTER)) {
+                FirewallIntentFilter intentFilter = new FirewallIntentFilter(this);
+                intentFilter.readFromXml(parser);
+                mIntentFilters.add(intentFilter);
+            } else if (currentTag.equals(TAG_COMPONENT_FILTER)) {
+                String componentStr = parser.getAttributeValue(null, ATTR_NAME);
+                if (componentStr == null) {
+                    throw new XmlPullParserException("Component name must be specified.",
+                            parser, null);
+                }
+
+                ComponentName componentName = ComponentName.unflattenFromString(componentStr);
+                if (componentName == null) {
+                    throw new XmlPullParserException("Invalid component name: " + componentStr);
+                }
+
+                mComponentFilters.add(componentName);
+            } else {
+                super.readChild(parser);
+            }
+        }
+
+        public int getIntentFilterCount() {
+            return mIntentFilters.size();
+        }
+
+        public FirewallIntentFilter getIntentFilter(int index) {
+            return mIntentFilters.get(index);
+        }
+
+        public int getComponentFilterCount() {
+            return mComponentFilters.size();
+        }
+
+        public ComponentName getComponentFilter(int index) {
+            return mComponentFilters.get(index);
+        }
+        public boolean getBlock() {
+            return block;
+        }
+
+        public boolean getLog() {
+            return log;
+        }
+    }
+
+    private static class FirewallIntentFilter extends IntentFilter {
+        private final Rule rule;
+
+        public FirewallIntentFilter(Rule rule) {
+            this.rule = rule;
+        }
+    }
+
+    private static class FirewallIntentResolver
+            extends IntentResolver<FirewallIntentFilter, Rule> {
+        @Override
+        protected boolean allowFilterResult(FirewallIntentFilter filter, List<Rule> dest) {
+            return !dest.contains(filter.rule);
+        }
+
+        @Override
+        protected boolean isPackageForFilter(String packageName, FirewallIntentFilter filter) {
+            return true;
+        }
+
+        @Override
+        protected FirewallIntentFilter[] newArray(int size) {
+            return new FirewallIntentFilter[size];
+        }
+
+        @Override
+        protected Rule newResult(FirewallIntentFilter filter, int match, int userId) {
+            return filter.rule;
+        }
+
+        @Override
+        protected void sortResults(List<Rule> results) {
+            // there's no need to sort the results
+            return;
+        }
+
+        public void queryByComponent(ComponentName componentName, List<Rule> candidateRules) {
+            Rule[] rules = mRulesByComponent.get(componentName);
+            if (rules != null) {
+                candidateRules.addAll(Arrays.asList(rules));
+            }
+        }
+
+        public void addComponentFilter(ComponentName componentName, Rule rule) {
+            Rule[] rules = mRulesByComponent.get(componentName);
+            rules = ArrayUtils.appendElement(Rule.class, rules, rule);
+            mRulesByComponent.put(componentName, rules);
+        }
+
+        private final ArrayMap<ComponentName, Rule[]> mRulesByComponent =
+                new ArrayMap<ComponentName, Rule[]>(0);
+    }
+
+    final FirewallHandler mHandler;
+
+    private final class FirewallHandler extends Handler {
+        public FirewallHandler(Looper looper) {
+            super(looper, null, true);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            readRulesDir(getRulesDir());
+        }
+    };
+
+    /**
+     * Monitors for the creation/deletion/modification of any .xml files in the rule directory
+     */
+    private class RuleObserver extends FileObserver {
+        private static final int MONITORED_EVENTS = FileObserver.CREATE|FileObserver.MOVED_TO|
+                FileObserver.CLOSE_WRITE|FileObserver.DELETE|FileObserver.MOVED_FROM;
+
+        public RuleObserver(File monitoredDir) {
+            super(monitoredDir.getAbsolutePath(), MONITORED_EVENTS);
+        }
+
+        @Override
+        public void onEvent(int event, String path) {
+            if (path.endsWith(".xml")) {
+                // we wait 250ms before taking any action on an event, in order to dedup multiple
+                // events. E.g. a delete event followed by a create event followed by a subsequent
+                // write+close event
+                mHandler.removeMessages(0);
+                mHandler.sendEmptyMessageDelayed(0, 250);
+            }
+        }
+    }
+
+    /**
+     * This interface contains the methods we need from ActivityManagerService. This allows AMS to
+     * export these methods to us without making them public, and also makes it easier to test this
+     * component.
+     */
+    public interface AMSInterface {
+        int checkComponentPermission(String permission, int pid, int uid,
+                int owningUid, boolean exported);
+        Object getAMSLock();
+    }
+
+    /**
+     * Checks if the caller has access to a component
+     *
+     * @param permission If present, the caller must have this permission
+     * @param pid The pid of the caller
+     * @param uid The uid of the caller
+     * @param owningUid The uid of the application that owns the component
+     * @param exported Whether the component is exported
+     * @return True if the caller can access the described component
+     */
+    boolean checkComponentPermission(String permission, int pid, int uid, int owningUid,
+            boolean exported) {
+        return mAms.checkComponentPermission(permission, pid, uid, owningUid, exported) ==
+                PackageManager.PERMISSION_GRANTED;
+    }
+
+    boolean signaturesMatch(int uid1, int uid2) {
+        try {
+            IPackageManager pm = AppGlobals.getPackageManager();
+            return pm.checkUidSignatures(uid1, uid2) == PackageManager.SIGNATURE_MATCH;
+        } catch (RemoteException ex) {
+            Slog.e(TAG, "Remote exception while checking signatures", ex);
+            return false;
+        }
+    }
+
+}
diff --git a/services/java/com/android/server/firewall/NotFilter.java b/services/core/java/com/android/server/firewall/NotFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/NotFilter.java
rename to services/core/java/com/android/server/firewall/NotFilter.java
diff --git a/services/java/com/android/server/firewall/OrFilter.java b/services/core/java/com/android/server/firewall/OrFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/OrFilter.java
rename to services/core/java/com/android/server/firewall/OrFilter.java
diff --git a/services/java/com/android/server/firewall/PortFilter.java b/services/core/java/com/android/server/firewall/PortFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/PortFilter.java
rename to services/core/java/com/android/server/firewall/PortFilter.java
diff --git a/services/java/com/android/server/firewall/SenderFilter.java b/services/core/java/com/android/server/firewall/SenderFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/SenderFilter.java
rename to services/core/java/com/android/server/firewall/SenderFilter.java
diff --git a/services/java/com/android/server/firewall/SenderPermissionFilter.java b/services/core/java/com/android/server/firewall/SenderPermissionFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/SenderPermissionFilter.java
rename to services/core/java/com/android/server/firewall/SenderPermissionFilter.java
diff --git a/services/java/com/android/server/firewall/StringFilter.java b/services/core/java/com/android/server/firewall/StringFilter.java
similarity index 100%
rename from services/java/com/android/server/firewall/StringFilter.java
rename to services/core/java/com/android/server/firewall/StringFilter.java
diff --git a/services/core/java/com/android/server/input/InputApplicationHandle.java b/services/core/java/com/android/server/input/InputApplicationHandle.java
new file mode 100644
index 0000000..3cf7edc
--- /dev/null
+++ b/services/core/java/com/android/server/input/InputApplicationHandle.java
@@ -0,0 +1,54 @@
+/*
+ * 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.server.input;
+
+/**
+ * Functions as a handle for an application that can receive input.
+ * Enables the native input dispatcher to refer indirectly to the window manager's
+ * application window token.
+ * @hide
+ */
+public final class InputApplicationHandle {
+    // Pointer to the native input application handle.
+    // This field is lazily initialized via JNI.
+    @SuppressWarnings("unused")
+    private long ptr;
+
+    // The window manager's application window token.
+    public final Object appWindowToken;
+
+    // Application name.
+    public String name;
+
+    // Dispatching timeout.
+    public long dispatchingTimeoutNanos;
+
+    private native void nativeDispose();
+
+    public InputApplicationHandle(Object appWindowToken) {
+        this.appWindowToken = appWindowToken;
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            nativeDispose();
+        } finally {
+            super.finalize();
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java
new file mode 100644
index 0000000..e49382e
--- /dev/null
+++ b/services/core/java/com/android/server/input/InputManagerService.java
@@ -0,0 +1,1700 @@
+/*
+ * Copyright (C) 2010 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.input;
+
+import android.view.Display;
+import com.android.internal.R;
+import com.android.internal.util.XmlUtils;
+import com.android.server.DisplayThread;
+import com.android.server.LocalServices;
+import com.android.server.Watchdog;
+
+import org.xmlpull.v1.XmlPullParser;
+
+import android.Manifest;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.database.ContentObserver;
+import android.hardware.display.DisplayViewport;
+import android.hardware.input.IInputDevicesChangedListener;
+import android.hardware.input.IInputManager;
+import android.hardware.input.InputDeviceIdentifier;
+import android.hardware.input.InputManager;
+import android.hardware.input.InputManagerInternal;
+import android.hardware.input.KeyboardLayout;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.MessageQueue;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.Xml;
+import android.view.IInputFilter;
+import android.view.IInputFilterHost;
+import android.view.InputChannel;
+import android.view.InputDevice;
+import android.view.InputEvent;
+import android.view.KeyEvent;
+import android.view.PointerIcon;
+import android.view.ViewConfiguration;
+import android.view.WindowManagerPolicy;
+import android.widget.Toast;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import libcore.io.Streams;
+import libcore.util.Objects;
+
+/*
+ * Wraps the C++ InputManager and provides its callbacks.
+ */
+public class InputManagerService extends IInputManager.Stub
+        implements Watchdog.Monitor {
+    static final String TAG = "InputManager";
+    static final boolean DEBUG = false;
+
+    private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
+
+    private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1;
+    private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2;
+    private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3;
+    private static final int MSG_UPDATE_KEYBOARD_LAYOUTS = 4;
+    private static final int MSG_RELOAD_DEVICE_ALIASES = 5;
+
+    // Pointer to native input manager service object.
+    private final long mPtr;
+
+    private final Context mContext;
+    private final InputManagerHandler mHandler;
+
+    private WindowManagerCallbacks mWindowManagerCallbacks;
+    private WiredAccessoryCallbacks mWiredAccessoryCallbacks;
+    private boolean mSystemReady;
+    private NotificationManager mNotificationManager;
+
+    // Persistent data store.  Must be locked each time during use.
+    private final PersistentDataStore mDataStore = new PersistentDataStore();
+
+    // List of currently registered input devices changed listeners by process id.
+    private Object mInputDevicesLock = new Object();
+    private boolean mInputDevicesChangedPending; // guarded by mInputDevicesLock
+    private InputDevice[] mInputDevices = new InputDevice[0];
+    private final SparseArray<InputDevicesChangedListenerRecord> mInputDevicesChangedListeners =
+            new SparseArray<InputDevicesChangedListenerRecord>(); // guarded by mInputDevicesLock
+    private final ArrayList<InputDevicesChangedListenerRecord>
+            mTempInputDevicesChangedListenersToNotify =
+                    new ArrayList<InputDevicesChangedListenerRecord>(); // handler thread only
+    private final ArrayList<InputDevice>
+            mTempFullKeyboards = new ArrayList<InputDevice>(); // handler thread only
+    private boolean mKeyboardLayoutNotificationShown;
+    private PendingIntent mKeyboardLayoutIntent;
+    private Toast mSwitchedKeyboardLayoutToast;
+
+    // State for vibrator tokens.
+    private Object mVibratorLock = new Object();
+    private HashMap<IBinder, VibratorToken> mVibratorTokens =
+            new HashMap<IBinder, VibratorToken>();
+    private int mNextVibratorTokenValue;
+
+    // State for the currently installed input filter.
+    final Object mInputFilterLock = new Object();
+    IInputFilter mInputFilter; // guarded by mInputFilterLock
+    InputFilterHost mInputFilterHost; // guarded by mInputFilterLock
+
+    private static native long nativeInit(InputManagerService service,
+            Context context, MessageQueue messageQueue);
+    private static native void nativeStart(long ptr);
+    private static native void nativeSetDisplayViewport(long ptr, boolean external,
+            int displayId, int rotation,
+            int logicalLeft, int logicalTop, int logicalRight, int logicalBottom,
+            int physicalLeft, int physicalTop, int physicalRight, int physicalBottom,
+            int deviceWidth, int deviceHeight);
+
+    private static native int nativeGetScanCodeState(long ptr,
+            int deviceId, int sourceMask, int scanCode);
+    private static native int nativeGetKeyCodeState(long ptr,
+            int deviceId, int sourceMask, int keyCode);
+    private static native int nativeGetSwitchState(long ptr,
+            int deviceId, int sourceMask, int sw);
+    private static native boolean nativeHasKeys(long ptr,
+            int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
+    private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel,
+            InputWindowHandle inputWindowHandle, boolean monitor);
+    private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel);
+    private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
+    private static native int nativeInjectInputEvent(long ptr, InputEvent event, int displayId,
+            int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
+            int policyFlags);
+    private static native void nativeSetInputWindows(long ptr, InputWindowHandle[] windowHandles);
+    private static native void nativeSetInputDispatchMode(long ptr, boolean enabled, boolean frozen);
+    private static native void nativeSetSystemUiVisibility(long ptr, int visibility);
+    private static native void nativeSetFocusedApplication(long ptr,
+            InputApplicationHandle application);
+    private static native boolean nativeTransferTouchFocus(long ptr,
+            InputChannel fromChannel, InputChannel toChannel);
+    private static native void nativeSetPointerSpeed(long ptr, int speed);
+    private static native void nativeSetShowTouches(long ptr, boolean enabled);
+    private static native void nativeVibrate(long ptr, int deviceId, long[] pattern,
+            int repeat, int token);
+    private static native void nativeCancelVibrate(long ptr, int deviceId, int token);
+    private static native void nativeReloadKeyboardLayouts(long ptr);
+    private static native void nativeReloadDeviceAliases(long ptr);
+    private static native String nativeDump(long ptr);
+    private static native void nativeMonitor(long ptr);
+
+    // Input event injection constants defined in InputDispatcher.h.
+    private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
+    private static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
+    private static final int INPUT_EVENT_INJECTION_FAILED = 2;
+    private static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
+
+    // Maximum number of milliseconds to wait for input event injection.
+    private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
+
+    // Key states (may be returned by queries about the current state of a
+    // particular key code, scan code or switch).
+
+    /** The key state is unknown or the requested key itself is not supported. */
+    public static final int KEY_STATE_UNKNOWN = -1;
+
+    /** The key is up. /*/
+    public static final int KEY_STATE_UP = 0;
+
+    /** The key is down. */
+    public static final int KEY_STATE_DOWN = 1;
+
+    /** The key is down but is a virtual key press that is being emulated by the system. */
+    public static final int KEY_STATE_VIRTUAL = 2;
+
+    /** Scan code: Mouse / trackball button. */
+    public static final int BTN_MOUSE = 0x110;
+
+    // Switch code values must match bionic/libc/kernel/common/linux/input.h
+    /** Switch code: Lid switch.  When set, lid is shut. */
+    public static final int SW_LID = 0x00;
+
+    /** Switch code: Keypad slide.  When set, keyboard is exposed. */
+    public static final int SW_KEYPAD_SLIDE = 0x0a;
+
+    /** Switch code: Headphone.  When set, headphone is inserted. */
+    public static final int SW_HEADPHONE_INSERT = 0x02;
+
+    /** Switch code: Microphone.  When set, microphone is inserted. */
+    public static final int SW_MICROPHONE_INSERT = 0x04;
+
+    /** Switch code: Headphone/Microphone Jack.  When set, something is inserted. */
+    public static final int SW_JACK_PHYSICAL_INSERT = 0x07;
+
+    public static final int SW_LID_BIT = 1 << SW_LID;
+    public static final int SW_KEYPAD_SLIDE_BIT = 1 << SW_KEYPAD_SLIDE;
+    public static final int SW_HEADPHONE_INSERT_BIT = 1 << SW_HEADPHONE_INSERT;
+    public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT;
+    public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT;
+    public static final int SW_JACK_BITS =
+            SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT;
+
+    /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */
+    final boolean mUseDevInputEventForAudioJack;
+
+    public InputManagerService(Context context) {
+        this.mContext = context;
+        this.mHandler = new InputManagerHandler(DisplayThread.get().getLooper());
+
+        mUseDevInputEventForAudioJack =
+                context.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack);
+        Slog.i(TAG, "Initializing input manager, mUseDevInputEventForAudioJack="
+                + mUseDevInputEventForAudioJack);
+        mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());
+
+        LocalServices.addService(InputManagerInternal.class, new LocalService());
+    }
+
+    public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks) {
+        mWindowManagerCallbacks = callbacks;
+    }
+
+    public void setWiredAccessoryCallbacks(WiredAccessoryCallbacks callbacks) {
+        mWiredAccessoryCallbacks = callbacks;
+    }
+
+    public void start() {
+        Slog.i(TAG, "Starting input manager");
+        nativeStart(mPtr);
+
+        // Add ourself to the Watchdog monitors.
+        Watchdog.getInstance().addMonitor(this);
+
+        registerPointerSpeedSettingObserver();
+        registerShowTouchesSettingObserver();
+
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                updatePointerSpeedFromSettings();
+                updateShowTouchesFromSettings();
+            }
+        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
+
+        updatePointerSpeedFromSettings();
+        updateShowTouchesFromSettings();
+    }
+
+    // TODO(BT) Pass in paramter for bluetooth system
+    public void systemRunning() {
+        if (DEBUG) {
+            Slog.d(TAG, "System ready.");
+        }
+        mNotificationManager = (NotificationManager)mContext.getSystemService(
+                Context.NOTIFICATION_SERVICE);
+        mSystemReady = true;
+
+        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+        filter.addDataScheme("package");
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                updateKeyboardLayouts();
+            }
+        }, filter, null, mHandler);
+
+        filter = new IntentFilter(BluetoothDevice.ACTION_ALIAS_CHANGED);
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                reloadDeviceAliases();
+            }
+        }, filter, null, mHandler);
+
+        mHandler.sendEmptyMessage(MSG_RELOAD_DEVICE_ALIASES);
+        mHandler.sendEmptyMessage(MSG_UPDATE_KEYBOARD_LAYOUTS);
+    }
+
+    private void reloadKeyboardLayouts() {
+        if (DEBUG) {
+            Slog.d(TAG, "Reloading keyboard layouts.");
+        }
+        nativeReloadKeyboardLayouts(mPtr);
+    }
+
+    private void reloadDeviceAliases() {
+        if (DEBUG) {
+            Slog.d(TAG, "Reloading device names.");
+        }
+        nativeReloadDeviceAliases(mPtr);
+    }
+
+    private void setDisplayViewportsInternal(DisplayViewport defaultViewport,
+            DisplayViewport externalTouchViewport) {
+        if (defaultViewport.valid) {
+            setDisplayViewport(false, defaultViewport);
+        }
+
+        if (externalTouchViewport.valid) {
+            setDisplayViewport(true, externalTouchViewport);
+        } else if (defaultViewport.valid) {
+            setDisplayViewport(true, defaultViewport);
+        }
+    }
+
+    private void setDisplayViewport(boolean external, DisplayViewport viewport) {
+        nativeSetDisplayViewport(mPtr, external,
+                viewport.displayId, viewport.orientation,
+                viewport.logicalFrame.left, viewport.logicalFrame.top,
+                viewport.logicalFrame.right, viewport.logicalFrame.bottom,
+                viewport.physicalFrame.left, viewport.physicalFrame.top,
+                viewport.physicalFrame.right, viewport.physicalFrame.bottom,
+                viewport.deviceWidth, viewport.deviceHeight);
+    }
+
+    /**
+     * Gets the current state of a key or button by key code.
+     * @param deviceId The input device id, or -1 to consult all devices.
+     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
+     * consider all input sources.  An input device is consulted if at least one of its
+     * non-class input source bits matches the specified source mask.
+     * @param keyCode The key code to check.
+     * @return The key state.
+     */
+    public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
+        return nativeGetKeyCodeState(mPtr, deviceId, sourceMask, keyCode);
+    }
+
+    /**
+     * Gets the current state of a key or button by scan code.
+     * @param deviceId The input device id, or -1 to consult all devices.
+     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
+     * consider all input sources.  An input device is consulted if at least one of its
+     * non-class input source bits matches the specified source mask.
+     * @param scanCode The scan code to check.
+     * @return The key state.
+     */
+    public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
+        return nativeGetScanCodeState(mPtr, deviceId, sourceMask, scanCode);
+    }
+
+    /**
+     * Gets the current state of a switch by switch code.
+     * @param deviceId The input device id, or -1 to consult all devices.
+     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
+     * consider all input sources.  An input device is consulted if at least one of its
+     * non-class input source bits matches the specified source mask.
+     * @param switchCode The switch code to check.
+     * @return The switch state.
+     */
+    public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
+        return nativeGetSwitchState(mPtr, deviceId, sourceMask, switchCode);
+    }
+
+    /**
+     * Determines whether the specified key codes are supported by a particular device.
+     * @param deviceId The input device id, or -1 to consult all devices.
+     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
+     * consider all input sources.  An input device is consulted if at least one of its
+     * non-class input source bits matches the specified source mask.
+     * @param keyCodes The array of key codes to check.
+     * @param keyExists An array at least as large as keyCodes whose entries will be set
+     * to true or false based on the presence or absence of support for the corresponding
+     * key codes.
+     * @return True if the lookup was successful, false otherwise.
+     */
+    @Override // Binder call
+    public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
+        if (keyCodes == null) {
+            throw new IllegalArgumentException("keyCodes must not be null.");
+        }
+        if (keyExists == null || keyExists.length < keyCodes.length) {
+            throw new IllegalArgumentException("keyExists must not be null and must be at "
+                    + "least as large as keyCodes.");
+        }
+
+        return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists);
+    }
+
+    /**
+     * Creates an input channel that will receive all input from the input dispatcher.
+     * @param inputChannelName The input channel name.
+     * @return The input channel.
+     */
+    public InputChannel monitorInput(String inputChannelName) {
+        if (inputChannelName == null) {
+            throw new IllegalArgumentException("inputChannelName must not be null.");
+        }
+
+        InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
+        nativeRegisterInputChannel(mPtr, inputChannels[0], null, true);
+        inputChannels[0].dispose(); // don't need to retain the Java object reference
+        return inputChannels[1];
+    }
+
+    /**
+     * Registers an input channel so that it can be used as an input event target.
+     * @param inputChannel The input channel to register.
+     * @param inputWindowHandle The handle of the input window associated with the
+     * input channel, or null if none.
+     */
+    public void registerInputChannel(InputChannel inputChannel,
+            InputWindowHandle inputWindowHandle) {
+        if (inputChannel == null) {
+            throw new IllegalArgumentException("inputChannel must not be null.");
+        }
+
+        nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false);
+    }
+
+    /**
+     * Unregisters an input channel.
+     * @param inputChannel The input channel to unregister.
+     */
+    public void unregisterInputChannel(InputChannel inputChannel) {
+        if (inputChannel == null) {
+            throw new IllegalArgumentException("inputChannel must not be null.");
+        }
+
+        nativeUnregisterInputChannel(mPtr, inputChannel);
+    }
+
+    /**
+     * Sets an input filter that will receive all input events before they are dispatched.
+     * The input filter may then reinterpret input events or inject new ones.
+     *
+     * To ensure consistency, the input dispatcher automatically drops all events
+     * in progress whenever an input filter is installed or uninstalled.  After an input
+     * filter is uninstalled, it can no longer send input events unless it is reinstalled.
+     * Any events it attempts to send after it has been uninstalled will be dropped.
+     *
+     * @param filter The input filter, or null to remove the current filter.
+     */
+    public void setInputFilter(IInputFilter filter) {
+        synchronized (mInputFilterLock) {
+            final IInputFilter oldFilter = mInputFilter;
+            if (oldFilter == filter) {
+                return; // nothing to do
+            }
+
+            if (oldFilter != null) {
+                mInputFilter = null;
+                mInputFilterHost.disconnectLocked();
+                mInputFilterHost = null;
+                try {
+                    oldFilter.uninstall();
+                } catch (RemoteException re) {
+                    /* ignore */
+                }
+            }
+
+            if (filter != null) {
+                mInputFilter = filter;
+                mInputFilterHost = new InputFilterHost();
+                try {
+                    filter.install(mInputFilterHost);
+                } catch (RemoteException re) {
+                    /* ignore */
+                }
+            }
+
+            nativeSetInputFilterEnabled(mPtr, filter != null);
+        }
+    }
+
+    @Override // Binder call
+    public boolean injectInputEvent(InputEvent event, int mode) {
+        return injectInputEventInternal(event, Display.DEFAULT_DISPLAY, mode);
+    }
+
+    private boolean injectInputEventInternal(InputEvent event, int displayId, int mode) {
+        if (event == null) {
+            throw new IllegalArgumentException("event must not be null");
+        }
+        if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC
+                && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH
+                && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) {
+            throw new IllegalArgumentException("mode is invalid");
+        }
+
+        final int pid = Binder.getCallingPid();
+        final int uid = Binder.getCallingUid();
+        final long ident = Binder.clearCallingIdentity();
+        final int result;
+        try {
+            result = nativeInjectInputEvent(mPtr, event, displayId, pid, uid, mode,
+                    INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+        switch (result) {
+            case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
+                Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");
+                throw new SecurityException(
+                        "Injecting to another application requires INJECT_EVENTS permission");
+            case INPUT_EVENT_INJECTION_SUCCEEDED:
+                return true;
+            case INPUT_EVENT_INJECTION_TIMED_OUT:
+                Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");
+                return false;
+            case INPUT_EVENT_INJECTION_FAILED:
+            default:
+                Slog.w(TAG, "Input event injection from pid " + pid + " failed.");
+                return false;
+        }
+    }
+
+    /**
+     * Gets information about the input device with the specified id.
+     * @param deviceId The device id.
+     * @return The input device or null if not found.
+     */
+    @Override // Binder call
+    public InputDevice getInputDevice(int deviceId) {
+        synchronized (mInputDevicesLock) {
+            final int count = mInputDevices.length;
+            for (int i = 0; i < count; i++) {
+                final InputDevice inputDevice = mInputDevices[i];
+                if (inputDevice.getId() == deviceId) {
+                    return inputDevice;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Gets the ids of all input devices in the system.
+     * @return The input device ids.
+     */
+    @Override // Binder call
+    public int[] getInputDeviceIds() {
+        synchronized (mInputDevicesLock) {
+            final int count = mInputDevices.length;
+            int[] ids = new int[count];
+            for (int i = 0; i < count; i++) {
+                ids[i] = mInputDevices[i].getId();
+            }
+            return ids;
+        }
+    }
+
+    /**
+     * Gets all input devices in the system.
+     * @return The array of input devices.
+     */
+    public InputDevice[] getInputDevices() {
+        synchronized (mInputDevicesLock) {
+            return mInputDevices;
+        }
+    }
+
+    @Override // Binder call
+    public void registerInputDevicesChangedListener(IInputDevicesChangedListener listener) {
+        if (listener == null) {
+            throw new IllegalArgumentException("listener must not be null");
+        }
+
+        synchronized (mInputDevicesLock) {
+            int callingPid = Binder.getCallingPid();
+            if (mInputDevicesChangedListeners.get(callingPid) != null) {
+                throw new SecurityException("The calling process has already "
+                        + "registered an InputDevicesChangedListener.");
+            }
+
+            InputDevicesChangedListenerRecord record =
+                    new InputDevicesChangedListenerRecord(callingPid, listener);
+            try {
+                IBinder binder = listener.asBinder();
+                binder.linkToDeath(record, 0);
+            } catch (RemoteException ex) {
+                // give up
+                throw new RuntimeException(ex);
+            }
+
+            mInputDevicesChangedListeners.put(callingPid, record);
+        }
+    }
+
+    private void onInputDevicesChangedListenerDied(int pid) {
+        synchronized (mInputDevicesLock) {
+            mInputDevicesChangedListeners.remove(pid);
+        }
+    }
+
+    // Must be called on handler.
+    private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
+        // Scan for changes.
+        int numFullKeyboardsAdded = 0;
+        mTempInputDevicesChangedListenersToNotify.clear();
+        mTempFullKeyboards.clear();
+        final int numListeners;
+        final int[] deviceIdAndGeneration;
+        synchronized (mInputDevicesLock) {
+            if (!mInputDevicesChangedPending) {
+                return;
+            }
+            mInputDevicesChangedPending = false;
+
+            numListeners = mInputDevicesChangedListeners.size();
+            for (int i = 0; i < numListeners; i++) {
+                mTempInputDevicesChangedListenersToNotify.add(
+                        mInputDevicesChangedListeners.valueAt(i));
+            }
+
+            final int numDevices = mInputDevices.length;
+            deviceIdAndGeneration = new int[numDevices * 2];
+            for (int i = 0; i < numDevices; i++) {
+                final InputDevice inputDevice = mInputDevices[i];
+                deviceIdAndGeneration[i * 2] = inputDevice.getId();
+                deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration();
+
+                if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
+                    if (!containsInputDeviceWithDescriptor(oldInputDevices,
+                            inputDevice.getDescriptor())) {
+                        mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
+                    } else {
+                        mTempFullKeyboards.add(inputDevice);
+                    }
+                }
+            }
+        }
+
+        // Notify listeners.
+        for (int i = 0; i < numListeners; i++) {
+            mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged(
+                    deviceIdAndGeneration);
+        }
+        mTempInputDevicesChangedListenersToNotify.clear();
+
+        // Check for missing keyboard layouts.
+        if (mNotificationManager != null) {
+            final int numFullKeyboards = mTempFullKeyboards.size();
+            boolean missingLayoutForExternalKeyboard = false;
+            boolean missingLayoutForExternalKeyboardAdded = false;
+            synchronized (mDataStore) {
+                for (int i = 0; i < numFullKeyboards; i++) {
+                    final InputDevice inputDevice = mTempFullKeyboards.get(i);
+                    if (mDataStore.getCurrentKeyboardLayout(inputDevice.getDescriptor()) == null) {
+                        missingLayoutForExternalKeyboard = true;
+                        if (i < numFullKeyboardsAdded) {
+                            missingLayoutForExternalKeyboardAdded = true;
+                        }
+                    }
+                }
+            }
+            if (missingLayoutForExternalKeyboard) {
+                if (missingLayoutForExternalKeyboardAdded) {
+                    showMissingKeyboardLayoutNotification();
+                }
+            } else if (mKeyboardLayoutNotificationShown) {
+                hideMissingKeyboardLayoutNotification();
+            }
+        }
+        mTempFullKeyboards.clear();
+    }
+
+    // Must be called on handler.
+    private void showMissingKeyboardLayoutNotification() {
+        if (!mKeyboardLayoutNotificationShown) {
+            if (mKeyboardLayoutIntent == null) {
+                final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS");
+                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
+                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                mKeyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0,
+                        intent, 0, null, UserHandle.CURRENT);
+            }
+
+            Resources r = mContext.getResources();
+            Notification notification = new Notification.Builder(mContext)
+                    .setContentTitle(r.getString(
+                            R.string.select_keyboard_layout_notification_title))
+                    .setContentText(r.getString(
+                            R.string.select_keyboard_layout_notification_message))
+                    .setContentIntent(mKeyboardLayoutIntent)
+                    .setSmallIcon(R.drawable.ic_settings_language)
+                    .setPriority(Notification.PRIORITY_LOW)
+                    .build();
+            mNotificationManager.notifyAsUser(null,
+                    R.string.select_keyboard_layout_notification_title,
+                    notification, UserHandle.ALL);
+            mKeyboardLayoutNotificationShown = true;
+        }
+    }
+
+    // Must be called on handler.
+    private void hideMissingKeyboardLayoutNotification() {
+        if (mKeyboardLayoutNotificationShown) {
+            mKeyboardLayoutNotificationShown = false;
+            mNotificationManager.cancelAsUser(null,
+                    R.string.select_keyboard_layout_notification_title,
+                    UserHandle.ALL);
+        }
+    }
+
+    // Must be called on handler.
+    private void updateKeyboardLayouts() {
+        // Scan all input devices state for keyboard layouts that have been uninstalled.
+        final HashSet<String> availableKeyboardLayouts = new HashSet<String>();
+        visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
+            @Override
+            public void visitKeyboardLayout(Resources resources,
+                    String descriptor, String label, String collection, int keyboardLayoutResId) {
+                availableKeyboardLayouts.add(descriptor);
+            }
+        });
+        synchronized (mDataStore) {
+            try {
+                mDataStore.removeUninstalledKeyboardLayouts(availableKeyboardLayouts);
+            } finally {
+                mDataStore.saveIfNeeded();
+            }
+        }
+
+        // Reload keyboard layouts.
+        reloadKeyboardLayouts();
+    }
+
+    private static boolean containsInputDeviceWithDescriptor(InputDevice[] inputDevices,
+            String descriptor) {
+        final int numDevices = inputDevices.length;
+        for (int i = 0; i < numDevices; i++) {
+            final InputDevice inputDevice = inputDevices[i];
+            if (inputDevice.getDescriptor().equals(descriptor)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override // Binder call
+    public KeyboardLayout[] getKeyboardLayouts() {
+        final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>();
+        visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
+            @Override
+            public void visitKeyboardLayout(Resources resources,
+                    String descriptor, String label, String collection, int keyboardLayoutResId) {
+                list.add(new KeyboardLayout(descriptor, label, collection));
+            }
+        });
+        return list.toArray(new KeyboardLayout[list.size()]);
+    }
+
+    @Override // Binder call
+    public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) {
+        if (keyboardLayoutDescriptor == null) {
+            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
+        }
+
+        final KeyboardLayout[] result = new KeyboardLayout[1];
+        visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
+            @Override
+            public void visitKeyboardLayout(Resources resources,
+                    String descriptor, String label, String collection, int keyboardLayoutResId) {
+                result[0] = new KeyboardLayout(descriptor, label, collection);
+            }
+        });
+        if (result[0] == null) {
+            Log.w(TAG, "Could not get keyboard layout with descriptor '"
+                    + keyboardLayoutDescriptor + "'.");
+        }
+        return result[0];
+    }
+
+    private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) {
+        final PackageManager pm = mContext.getPackageManager();
+        Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
+        for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent,
+                PackageManager.GET_META_DATA)) {
+            visitKeyboardLayoutsInPackage(pm, resolveInfo.activityInfo, null, visitor);
+        }
+    }
+
+    private void visitKeyboardLayout(String keyboardLayoutDescriptor,
+            KeyboardLayoutVisitor visitor) {
+        KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor);
+        if (d != null) {
+            final PackageManager pm = mContext.getPackageManager();
+            try {
+                ActivityInfo receiver = pm.getReceiverInfo(
+                        new ComponentName(d.packageName, d.receiverName),
+                        PackageManager.GET_META_DATA);
+                visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, visitor);
+            } catch (NameNotFoundException ex) {
+            }
+        }
+    }
+
+    private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver,
+            String keyboardName, KeyboardLayoutVisitor visitor) {
+        Bundle metaData = receiver.metaData;
+        if (metaData == null) {
+            return;
+        }
+
+        int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
+        if (configResId == 0) {
+            Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS
+                    + "' on receiver " + receiver.packageName + "/" + receiver.name);
+            return;
+        }
+
+        CharSequence receiverLabel = receiver.loadLabel(pm);
+        String collection = receiverLabel != null ? receiverLabel.toString() : "";
+
+        try {
+            Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
+            XmlResourceParser parser = resources.getXml(configResId);
+            try {
+                XmlUtils.beginDocument(parser, "keyboard-layouts");
+
+                for (;;) {
+                    XmlUtils.nextElement(parser);
+                    String element = parser.getName();
+                    if (element == null) {
+                        break;
+                    }
+                    if (element.equals("keyboard-layout")) {
+                        TypedArray a = resources.obtainAttributes(
+                                parser, com.android.internal.R.styleable.KeyboardLayout);
+                        try {
+                            String name = a.getString(
+                                    com.android.internal.R.styleable.KeyboardLayout_name);
+                            String label = a.getString(
+                                    com.android.internal.R.styleable.KeyboardLayout_label);
+                            int keyboardLayoutResId = a.getResourceId(
+                                    com.android.internal.R.styleable.KeyboardLayout_keyboardLayout,
+                                    0);
+                            if (name == null || label == null || keyboardLayoutResId == 0) {
+                                Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' "
+                                        + "attributes in keyboard layout "
+                                        + "resource from receiver "
+                                        + receiver.packageName + "/" + receiver.name);
+                            } else {
+                                String descriptor = KeyboardLayoutDescriptor.format(
+                                        receiver.packageName, receiver.name, name);
+                                if (keyboardName == null || name.equals(keyboardName)) {
+                                    visitor.visitKeyboardLayout(resources, descriptor,
+                                            label, collection, keyboardLayoutResId);
+                                }
+                            }
+                        } finally {
+                            a.recycle();
+                        }
+                    } else {
+                        Log.w(TAG, "Skipping unrecognized element '" + element
+                                + "' in keyboard layout resource from receiver "
+                                + receiver.packageName + "/" + receiver.name);
+                    }
+                }
+            } finally {
+                parser.close();
+            }
+        } catch (Exception ex) {
+            Log.w(TAG, "Could not parse keyboard layout resource from receiver "
+                    + receiver.packageName + "/" + receiver.name, ex);
+        }
+    }
+
+    /**
+     * Builds a layout descriptor for the vendor/product. This returns the
+     * descriptor for ids that aren't useful (such as the default 0, 0).
+     */
+    private String getLayoutDescriptor(InputDeviceIdentifier identifier) {
+        if (identifier == null || identifier.getDescriptor() == null) {
+            throw new IllegalArgumentException("identifier and descriptor must not be null");
+        }
+
+        if (identifier.getVendorId() == 0 && identifier.getProductId() == 0) {
+            return identifier.getDescriptor();
+        }
+        StringBuilder bob = new StringBuilder();
+        bob.append("vendor:").append(identifier.getVendorId());
+        bob.append(",product:").append(identifier.getProductId());
+        return bob.toString();
+    }
+
+    @Override // Binder call
+    public String getCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier) {
+
+        String key = getLayoutDescriptor(identifier);
+        synchronized (mDataStore) {
+            String layout = null;
+            // try loading it using the layout descriptor if we have it
+            layout = mDataStore.getCurrentKeyboardLayout(key);
+            if (layout == null && !key.equals(identifier.getDescriptor())) {
+                // if it doesn't exist fall back to the device descriptor
+                layout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
+            }
+            if (DEBUG) {
+                Slog.d(TAG, "Loaded keyboard layout id for " + key + " and got "
+                        + layout);
+            }
+            return layout;
+        }
+    }
+
+    @Override // Binder call
+    public void setCurrentKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+            String keyboardLayoutDescriptor) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
+                "setCurrentKeyboardLayoutForInputDevice()")) {
+            throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
+        }
+        if (keyboardLayoutDescriptor == null) {
+            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
+        }
+
+        String key = getLayoutDescriptor(identifier);
+        synchronized (mDataStore) {
+            try {
+                if (mDataStore.setCurrentKeyboardLayout(key, keyboardLayoutDescriptor)) {
+                    if (DEBUG) {
+                        Slog.d(TAG, "Saved keyboard layout using " + key);
+                    }
+                    mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
+                }
+            } finally {
+                mDataStore.saveIfNeeded();
+            }
+        }
+    }
+
+    @Override // Binder call
+    public String[] getKeyboardLayoutsForInputDevice(InputDeviceIdentifier identifier) {
+        String key = getLayoutDescriptor(identifier);
+        synchronized (mDataStore) {
+            String[] layouts = mDataStore.getKeyboardLayouts(key);
+            if ((layouts == null || layouts.length == 0)
+                    && !key.equals(identifier.getDescriptor())) {
+                layouts = mDataStore.getKeyboardLayouts(identifier.getDescriptor());
+            }
+            return layouts;
+        }
+    }
+
+    @Override // Binder call
+    public void addKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+            String keyboardLayoutDescriptor) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
+                "addKeyboardLayoutForInputDevice()")) {
+            throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
+        }
+        if (keyboardLayoutDescriptor == null) {
+            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
+        }
+
+        String key = getLayoutDescriptor(identifier);
+        synchronized (mDataStore) {
+            try {
+                String oldLayout = mDataStore.getCurrentKeyboardLayout(key);
+                if (oldLayout == null && !key.equals(identifier.getDescriptor())) {
+                    oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
+                }
+                if (mDataStore.addKeyboardLayout(key, keyboardLayoutDescriptor)
+                        && !Objects.equal(oldLayout,
+                                mDataStore.getCurrentKeyboardLayout(key))) {
+                    mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
+                }
+            } finally {
+                mDataStore.saveIfNeeded();
+            }
+        }
+    }
+
+    @Override // Binder call
+    public void removeKeyboardLayoutForInputDevice(InputDeviceIdentifier identifier,
+            String keyboardLayoutDescriptor) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
+                "removeKeyboardLayoutForInputDevice()")) {
+            throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
+        }
+        if (keyboardLayoutDescriptor == null) {
+            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
+        }
+
+        String key = getLayoutDescriptor(identifier);
+        synchronized (mDataStore) {
+            try {
+                String oldLayout = mDataStore.getCurrentKeyboardLayout(key);
+                if (oldLayout == null && !key.equals(identifier.getDescriptor())) {
+                    oldLayout = mDataStore.getCurrentKeyboardLayout(identifier.getDescriptor());
+                }
+                boolean removed = mDataStore.removeKeyboardLayout(key, keyboardLayoutDescriptor);
+                if (!key.equals(identifier.getDescriptor())) {
+                    // We need to remove from both places to ensure it is gone
+                    removed |= mDataStore.removeKeyboardLayout(identifier.getDescriptor(),
+                            keyboardLayoutDescriptor);
+                }
+                if (removed && !Objects.equal(oldLayout,
+                                mDataStore.getCurrentKeyboardLayout(key))) {
+                    mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
+                }
+            } finally {
+                mDataStore.saveIfNeeded();
+            }
+        }
+    }
+
+    public void switchKeyboardLayout(int deviceId, int direction) {
+        mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, deviceId, direction).sendToTarget();
+    }
+
+    // Must be called on handler.
+    private void handleSwitchKeyboardLayout(int deviceId, int direction) {
+        final InputDevice device = getInputDevice(deviceId);
+        if (device != null) {
+            final boolean changed;
+            final String keyboardLayoutDescriptor;
+
+            String key = getLayoutDescriptor(device.getIdentifier());
+            synchronized (mDataStore) {
+                try {
+                    changed = mDataStore.switchKeyboardLayout(key, direction);
+                    keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout(
+                            key);
+                } finally {
+                    mDataStore.saveIfNeeded();
+                }
+            }
+
+            if (changed) {
+                if (mSwitchedKeyboardLayoutToast != null) {
+                    mSwitchedKeyboardLayoutToast.cancel();
+                    mSwitchedKeyboardLayoutToast = null;
+                }
+                if (keyboardLayoutDescriptor != null) {
+                    KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor);
+                    if (keyboardLayout != null) {
+                        mSwitchedKeyboardLayoutToast = Toast.makeText(
+                                mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT);
+                        mSwitchedKeyboardLayoutToast.show();
+                    }
+                }
+
+                reloadKeyboardLayouts();
+            }
+        }
+    }
+
+    public void setInputWindows(InputWindowHandle[] windowHandles) {
+        nativeSetInputWindows(mPtr, windowHandles);
+    }
+
+    public void setFocusedApplication(InputApplicationHandle application) {
+        nativeSetFocusedApplication(mPtr, application);
+    }
+
+    public void setInputDispatchMode(boolean enabled, boolean frozen) {
+        nativeSetInputDispatchMode(mPtr, enabled, frozen);
+    }
+
+    public void setSystemUiVisibility(int visibility) {
+        nativeSetSystemUiVisibility(mPtr, visibility);
+    }
+
+    /**
+     * Atomically transfers touch focus from one window to another as identified by
+     * their input channels.  It is possible for multiple windows to have
+     * touch focus if they support split touch dispatch
+     * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
+     * method only transfers touch focus of the specified window without affecting
+     * other windows that may also have touch focus at the same time.
+     * @param fromChannel The channel of a window that currently has touch focus.
+     * @param toChannel The channel of the window that should receive touch focus in
+     * place of the first.
+     * @return True if the transfer was successful.  False if the window with the
+     * specified channel did not actually have touch focus at the time of the request.
+     */
+    public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
+        if (fromChannel == null) {
+            throw new IllegalArgumentException("fromChannel must not be null.");
+        }
+        if (toChannel == null) {
+            throw new IllegalArgumentException("toChannel must not be null.");
+        }
+        return nativeTransferTouchFocus(mPtr, fromChannel, toChannel);
+    }
+
+    @Override // Binder call
+    public void tryPointerSpeed(int speed) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED,
+                "tryPointerSpeed()")) {
+            throw new SecurityException("Requires SET_POINTER_SPEED permission");
+        }
+
+        if (speed < InputManager.MIN_POINTER_SPEED || speed > InputManager.MAX_POINTER_SPEED) {
+            throw new IllegalArgumentException("speed out of range");
+        }
+
+        setPointerSpeedUnchecked(speed);
+    }
+
+    public void updatePointerSpeedFromSettings() {
+        int speed = getPointerSpeedSetting();
+        setPointerSpeedUnchecked(speed);
+    }
+
+    private void setPointerSpeedUnchecked(int speed) {
+        speed = Math.min(Math.max(speed, InputManager.MIN_POINTER_SPEED),
+                InputManager.MAX_POINTER_SPEED);
+        nativeSetPointerSpeed(mPtr, speed);
+    }
+
+    private void registerPointerSpeedSettingObserver() {
+        mContext.getContentResolver().registerContentObserver(
+                Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
+                new ContentObserver(mHandler) {
+                    @Override
+                    public void onChange(boolean selfChange) {
+                        updatePointerSpeedFromSettings();
+                    }
+                }, UserHandle.USER_ALL);
+    }
+
+    private int getPointerSpeedSetting() {
+        int speed = InputManager.DEFAULT_POINTER_SPEED;
+        try {
+            speed = Settings.System.getIntForUser(mContext.getContentResolver(),
+                    Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT);
+        } catch (SettingNotFoundException snfe) {
+        }
+        return speed;
+    }
+
+    public void updateShowTouchesFromSettings() {
+        int setting = getShowTouchesSetting(0);
+        nativeSetShowTouches(mPtr, setting != 0);
+    }
+
+    private void registerShowTouchesSettingObserver() {
+        mContext.getContentResolver().registerContentObserver(
+                Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true,
+                new ContentObserver(mHandler) {
+                    @Override
+                    public void onChange(boolean selfChange) {
+                        updateShowTouchesFromSettings();
+                    }
+                }, UserHandle.USER_ALL);
+    }
+
+    private int getShowTouchesSetting(int defaultValue) {
+        int result = defaultValue;
+        try {
+            result = Settings.System.getIntForUser(mContext.getContentResolver(),
+                    Settings.System.SHOW_TOUCHES, UserHandle.USER_CURRENT);
+        } catch (SettingNotFoundException snfe) {
+        }
+        return result;
+    }
+
+    // Binder call
+    @Override
+    public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) {
+        if (repeat >= pattern.length) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+
+        VibratorToken v;
+        synchronized (mVibratorLock) {
+            v = mVibratorTokens.get(token);
+            if (v == null) {
+                v = new VibratorToken(deviceId, token, mNextVibratorTokenValue++);
+                try {
+                    token.linkToDeath(v, 0);
+                } catch (RemoteException ex) {
+                    // give up
+                    throw new RuntimeException(ex);
+                }
+                mVibratorTokens.put(token, v);
+            }
+        }
+
+        synchronized (v) {
+            v.mVibrating = true;
+            nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue);
+        }
+    }
+
+    // Binder call
+    @Override
+    public void cancelVibrate(int deviceId, IBinder token) {
+        VibratorToken v;
+        synchronized (mVibratorLock) {
+            v = mVibratorTokens.get(token);
+            if (v == null || v.mDeviceId != deviceId) {
+                return; // nothing to cancel
+            }
+        }
+
+        cancelVibrateIfNeeded(v);
+    }
+
+    void onVibratorTokenDied(VibratorToken v) {
+        synchronized (mVibratorLock) {
+            mVibratorTokens.remove(v.mToken);
+        }
+
+        cancelVibrateIfNeeded(v);
+    }
+
+    private void cancelVibrateIfNeeded(VibratorToken v) {
+        synchronized (v) {
+            if (v.mVibrating) {
+                nativeCancelVibrate(mPtr, v.mDeviceId, v.mTokenValue);
+                v.mVibrating = false;
+            }
+        }
+    }
+
+    @Override
+    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump InputManager from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        pw.println("INPUT MANAGER (dumpsys input)\n");
+        String dumpStr = nativeDump(mPtr);
+        if (dumpStr != null) {
+            pw.println(dumpStr);
+        }
+    }
+
+    private boolean checkCallingPermission(String permission, String func) {
+        // Quick check: if the calling permission is me, it's all okay.
+        if (Binder.getCallingPid() == Process.myPid()) {
+            return true;
+        }
+
+        if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {
+            return true;
+        }
+        String msg = "Permission Denial: " + func + " from pid="
+                + Binder.getCallingPid()
+                + ", uid=" + Binder.getCallingUid()
+                + " requires " + permission;
+        Slog.w(TAG, msg);
+        return false;
+    }
+
+    // Called by the heartbeat to ensure locks are not held indefinitely (for deadlock detection).
+    @Override
+    public void monitor() {
+        synchronized (mInputFilterLock) { }
+        nativeMonitor(mPtr);
+    }
+
+    // Native callback.
+    private void notifyConfigurationChanged(long whenNanos) {
+        mWindowManagerCallbacks.notifyConfigurationChanged();
+    }
+
+    // Native callback.
+    private void notifyInputDevicesChanged(InputDevice[] inputDevices) {
+        synchronized (mInputDevicesLock) {
+            if (!mInputDevicesChangedPending) {
+                mInputDevicesChangedPending = true;
+                mHandler.obtainMessage(MSG_DELIVER_INPUT_DEVICES_CHANGED,
+                        mInputDevices).sendToTarget();
+            }
+
+            mInputDevices = inputDevices;
+        }
+    }
+
+    // Native callback.
+    private void notifySwitch(long whenNanos, int switchValues, int switchMask) {
+        if (DEBUG) {
+            Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues)
+                    + ", mask=" + Integer.toHexString(switchMask));
+        }
+
+        if ((switchMask & SW_LID_BIT) != 0) {
+            final boolean lidOpen = ((switchValues & SW_LID_BIT) == 0);
+            mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen);
+        }
+
+        if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) {
+            mWiredAccessoryCallbacks.notifyWiredAccessoryChanged(whenNanos, switchValues,
+                    switchMask);
+        }
+    }
+
+    // Native callback.
+    private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
+        mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle);
+    }
+
+    // Native callback.
+    private long notifyANR(InputApplicationHandle inputApplicationHandle,
+            InputWindowHandle inputWindowHandle, String reason) {
+        return mWindowManagerCallbacks.notifyANR(
+                inputApplicationHandle, inputWindowHandle, reason);
+    }
+
+    // Native callback.
+    final boolean filterInputEvent(InputEvent event, int policyFlags) {
+        synchronized (mInputFilterLock) {
+            if (mInputFilter != null) {
+                try {
+                    mInputFilter.filterInputEvent(event, policyFlags);
+                } catch (RemoteException e) {
+                    /* ignore */
+                }
+                return false;
+            }
+        }
+        event.recycle();
+        return true;
+    }
+
+    // Native callback.
+    private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
+        return mWindowManagerCallbacks.interceptKeyBeforeQueueing(
+                event, policyFlags, isScreenOn);
+    }
+
+    // Native callback.
+    private int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags) {
+        return mWindowManagerCallbacks.interceptMotionBeforeQueueingWhenScreenOff(
+                whenNanos, policyFlags);
+    }
+
+    // Native callback.
+    private long interceptKeyBeforeDispatching(InputWindowHandle focus,
+            KeyEvent event, int policyFlags) {
+        return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
+    }
+
+    // Native callback.
+    private KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
+            KeyEvent event, int policyFlags) {
+        return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
+    }
+
+    // Native callback.
+    private boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
+        return mContext.checkPermission(android.Manifest.permission.INJECT_EVENTS,
+                injectorPid, injectorUid) == PackageManager.PERMISSION_GRANTED;
+    }
+
+    // Native callback.
+    private int getVirtualKeyQuietTimeMillis() {
+        return mContext.getResources().getInteger(
+                com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
+    }
+
+    // Native callback.
+    private String[] getExcludedDeviceNames() {
+        ArrayList<String> names = new ArrayList<String>();
+
+        // Read partner-provided list of excluded input devices
+        XmlPullParser parser = null;
+        // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
+        File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
+        FileReader confreader = null;
+        try {
+            confreader = new FileReader(confFile);
+            parser = Xml.newPullParser();
+            parser.setInput(confreader);
+            XmlUtils.beginDocument(parser, "devices");
+
+            while (true) {
+                XmlUtils.nextElement(parser);
+                if (!"device".equals(parser.getName())) {
+                    break;
+                }
+                String name = parser.getAttributeValue(null, "name");
+                if (name != null) {
+                    names.add(name);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            // It's ok if the file does not exist.
+        } catch (Exception e) {
+            Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
+        } finally {
+            try { if (confreader != null) confreader.close(); } catch (IOException e) { }
+        }
+
+        return names.toArray(new String[names.size()]);
+    }
+
+    // Native callback.
+    private int getKeyRepeatTimeout() {
+        return ViewConfiguration.getKeyRepeatTimeout();
+    }
+
+    // Native callback.
+    private int getKeyRepeatDelay() {
+        return ViewConfiguration.getKeyRepeatDelay();
+    }
+
+    // Native callback.
+    private int getHoverTapTimeout() {
+        return ViewConfiguration.getHoverTapTimeout();
+    }
+
+    // Native callback.
+    private int getHoverTapSlop() {
+        return ViewConfiguration.getHoverTapSlop();
+    }
+
+    // Native callback.
+    private int getDoubleTapTimeout() {
+        return ViewConfiguration.getDoubleTapTimeout();
+    }
+
+    // Native callback.
+    private int getLongPressTimeout() {
+        return ViewConfiguration.getLongPressTimeout();
+    }
+
+    // Native callback.
+    private int getPointerLayer() {
+        return mWindowManagerCallbacks.getPointerLayer();
+    }
+
+    // Native callback.
+    private PointerIcon getPointerIcon() {
+        return PointerIcon.getDefaultIcon(mContext);
+    }
+
+    // Native callback.
+    private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
+        if (!mSystemReady) {
+            return null;
+        }
+
+        String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
+        if (keyboardLayoutDescriptor == null) {
+            return null;
+        }
+
+        final String[] result = new String[2];
+        visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
+            @Override
+            public void visitKeyboardLayout(Resources resources,
+                    String descriptor, String label, String collection, int keyboardLayoutResId) {
+                try {
+                    result[0] = descriptor;
+                    result[1] = Streams.readFully(new InputStreamReader(
+                            resources.openRawResource(keyboardLayoutResId)));
+                } catch (IOException ex) {
+                } catch (NotFoundException ex) {
+                }
+            }
+        });
+        if (result[0] == null) {
+            Log.w(TAG, "Could not get keyboard layout with descriptor '"
+                    + keyboardLayoutDescriptor + "'.");
+            return null;
+        }
+        return result;
+    }
+
+    // Native callback.
+    private String getDeviceAlias(String uniqueId) {
+        if (BluetoothAdapter.checkBluetoothAddress(uniqueId)) {
+            // TODO(BT) mBluetoothService.getRemoteAlias(uniqueId)
+            return null;
+        }
+        return null;
+    }
+
+    /**
+     * Callback interface implemented by the Window Manager.
+     */
+    public interface WindowManagerCallbacks {
+        public void notifyConfigurationChanged();
+
+        public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
+
+        public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle);
+
+        public long notifyANR(InputApplicationHandle inputApplicationHandle,
+                InputWindowHandle inputWindowHandle, String reason);
+
+        public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn);
+
+        public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags);
+
+        public long interceptKeyBeforeDispatching(InputWindowHandle focus,
+                KeyEvent event, int policyFlags);
+
+        public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
+                KeyEvent event, int policyFlags);
+
+        public int getPointerLayer();
+    }
+
+    /**
+     * Callback interface implemented by WiredAccessoryObserver.
+     */
+    public interface WiredAccessoryCallbacks {
+        public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask);
+    }
+
+    /**
+     * Private handler for the input manager.
+     */
+    private final class InputManagerHandler extends Handler {
+        public InputManagerHandler(Looper looper) {
+            super(looper, null, true /*async*/);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_DELIVER_INPUT_DEVICES_CHANGED:
+                    deliverInputDevicesChanged((InputDevice[])msg.obj);
+                    break;
+                case MSG_SWITCH_KEYBOARD_LAYOUT:
+                    handleSwitchKeyboardLayout(msg.arg1, msg.arg2);
+                    break;
+                case MSG_RELOAD_KEYBOARD_LAYOUTS:
+                    reloadKeyboardLayouts();
+                    break;
+                case MSG_UPDATE_KEYBOARD_LAYOUTS:
+                    updateKeyboardLayouts();
+                    break;
+                case MSG_RELOAD_DEVICE_ALIASES:
+                    reloadDeviceAliases();
+                    break;
+            }
+        }
+    }
+
+    /**
+     * Hosting interface for input filters to call back into the input manager.
+     */
+    private final class InputFilterHost extends IInputFilterHost.Stub {
+        private boolean mDisconnected;
+
+        public void disconnectLocked() {
+            mDisconnected = true;
+        }
+
+        @Override
+        public void sendInputEvent(InputEvent event, int policyFlags) {
+            if (event == null) {
+                throw new IllegalArgumentException("event must not be null");
+            }
+
+            synchronized (mInputFilterLock) {
+                if (!mDisconnected) {
+                    nativeInjectInputEvent(mPtr, event, Display.DEFAULT_DISPLAY, 0, 0,
+                            InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, 0,
+                            policyFlags | WindowManagerPolicy.FLAG_FILTERED);
+                }
+            }
+        }
+    }
+
+    private static final class KeyboardLayoutDescriptor {
+        public String packageName;
+        public String receiverName;
+        public String keyboardLayoutName;
+
+        public static String format(String packageName,
+                String receiverName, String keyboardName) {
+            return packageName + "/" + receiverName + "/" + keyboardName;
+        }
+
+        public static KeyboardLayoutDescriptor parse(String descriptor) {
+            int pos = descriptor.indexOf('/');
+            if (pos < 0 || pos + 1 == descriptor.length()) {
+                return null;
+            }
+            int pos2 = descriptor.indexOf('/', pos + 1);
+            if (pos2 < pos + 2 || pos2 + 1 == descriptor.length()) {
+                return null;
+            }
+
+            KeyboardLayoutDescriptor result = new KeyboardLayoutDescriptor();
+            result.packageName = descriptor.substring(0, pos);
+            result.receiverName = descriptor.substring(pos + 1, pos2);
+            result.keyboardLayoutName = descriptor.substring(pos2 + 1);
+            return result;
+        }
+    }
+
+    private interface KeyboardLayoutVisitor {
+        void visitKeyboardLayout(Resources resources,
+                String descriptor, String label, String collection, int keyboardLayoutResId);
+    }
+
+    private final class InputDevicesChangedListenerRecord implements DeathRecipient {
+        private final int mPid;
+        private final IInputDevicesChangedListener mListener;
+
+        public InputDevicesChangedListenerRecord(int pid, IInputDevicesChangedListener listener) {
+            mPid = pid;
+            mListener = listener;
+        }
+
+        @Override
+        public void binderDied() {
+            if (DEBUG) {
+                Slog.d(TAG, "Input devices changed listener for pid " + mPid + " died.");
+            }
+            onInputDevicesChangedListenerDied(mPid);
+        }
+
+        public void notifyInputDevicesChanged(int[] info) {
+            try {
+                mListener.onInputDevicesChanged(info);
+            } catch (RemoteException ex) {
+                Slog.w(TAG, "Failed to notify process "
+                        + mPid + " that input devices changed, assuming it died.", ex);
+                binderDied();
+            }
+        }
+    }
+
+    private final class VibratorToken implements DeathRecipient {
+        public final int mDeviceId;
+        public final IBinder mToken;
+        public final int mTokenValue;
+
+        public boolean mVibrating;
+
+        public VibratorToken(int deviceId, IBinder token, int tokenValue) {
+            mDeviceId = deviceId;
+            mToken = token;
+            mTokenValue = tokenValue;
+        }
+
+        @Override
+        public void binderDied() {
+            if (DEBUG) {
+                Slog.d(TAG, "Vibrator token died.");
+            }
+            onVibratorTokenDied(this);
+        }
+    }
+
+    private final class LocalService extends InputManagerInternal {
+        @Override
+        public void setDisplayViewports(
+                DisplayViewport defaultViewport, DisplayViewport externalTouchViewport) {
+            setDisplayViewportsInternal(defaultViewport, externalTouchViewport);
+        }
+
+        @Override
+        public boolean injectInputEvent(InputEvent event, int displayId, int mode) {
+            return injectInputEventInternal(event, displayId, mode);
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/input/InputWindowHandle.java b/services/core/java/com/android/server/input/InputWindowHandle.java
new file mode 100644
index 0000000..9a70f38
--- /dev/null
+++ b/services/core/java/com/android/server/input/InputWindowHandle.java
@@ -0,0 +1,111 @@
+/*
+ * 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.server.input;
+
+import android.graphics.Region;
+import android.view.InputChannel;
+
+/**
+ * Functions as a handle for a window that can receive input.
+ * Enables the native input dispatcher to refer indirectly to the window manager's window state.
+ * @hide
+ */
+public final class InputWindowHandle {
+    // Pointer to the native input window handle.
+    // This field is lazily initialized via JNI.
+    @SuppressWarnings("unused")
+    private long ptr;
+
+    // The input application handle.
+    public final InputApplicationHandle inputApplicationHandle;
+
+    // The window manager's window state.
+    public final Object windowState;
+
+    // The input channel associated with the window.
+    public InputChannel inputChannel;
+
+    // The window name.
+    public String name;
+
+    // Window layout params attributes.  (WindowManager.LayoutParams)
+    public int layoutParamsFlags;
+    public int layoutParamsPrivateFlags;
+    public int layoutParamsType;
+
+    // Dispatching timeout.
+    public long dispatchingTimeoutNanos;
+
+    // Window frame.
+    public int frameLeft;
+    public int frameTop;
+    public int frameRight;
+    public int frameBottom;
+
+    // Global scaling factor applied to touch events when they are dispatched
+    // to the window
+    public float scaleFactor;
+
+    // Window touchable region.
+    public final Region touchableRegion = new Region();
+
+    // Window is visible.
+    public boolean visible;
+
+    // Window can receive keys.
+    public boolean canReceiveKeys;
+
+    // Window has focus.
+    public boolean hasFocus;
+
+    // Window has wallpaper.  (window is the current wallpaper target)
+    public boolean hasWallpaper;
+
+    // Input event dispatching is paused.
+    public boolean paused;
+
+    // Window layer.
+    public int layer;
+
+    // Id of process and user that owns the window.
+    public int ownerPid;
+    public int ownerUid;
+
+    // Window input features.
+    public int inputFeatures;
+
+    // Display this input is on.
+    public final int displayId;
+
+    private native void nativeDispose();
+
+    public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
+            Object windowState, int displayId) {
+        this.inputApplicationHandle = inputApplicationHandle;
+        this.windowState = windowState;
+        this.displayId = displayId;
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        try {
+            nativeDispose();
+        } finally {
+            super.finalize();
+        }
+    }
+}
diff --git a/services/java/com/android/server/input/PersistentDataStore.java b/services/core/java/com/android/server/input/PersistentDataStore.java
similarity index 100%
rename from services/java/com/android/server/input/PersistentDataStore.java
rename to services/core/java/com/android/server/input/PersistentDataStore.java
diff --git a/services/core/java/com/android/server/lights/Light.java b/services/core/java/com/android/server/lights/Light.java
new file mode 100644
index 0000000..b496b4c6
--- /dev/null
+++ b/services/core/java/com/android/server/lights/Light.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2013 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.lights;
+
+public abstract class Light {
+    public static final int LIGHT_FLASH_NONE = 0;
+    public static final int LIGHT_FLASH_TIMED = 1;
+    public static final int LIGHT_FLASH_HARDWARE = 2;
+
+    /**
+     * Light brightness is managed by a user setting.
+     */
+    public static final int BRIGHTNESS_MODE_USER = 0;
+
+    /**
+     * Light brightness is managed by a light sensor.
+     */
+    public static final int BRIGHTNESS_MODE_SENSOR = 1;
+
+    public abstract void setBrightness(int brightness);
+    public abstract void setBrightness(int brightness, int brightnessMode);
+    public abstract void setColor(int color);
+    public abstract void setFlashing(int color, int mode, int onMS, int offMS);
+    public abstract void pulse();
+    public abstract void pulse(int color, int onMS);
+    public abstract void turnOff();
+}
\ No newline at end of file
diff --git a/services/core/java/com/android/server/lights/LightsManager.java b/services/core/java/com/android/server/lights/LightsManager.java
new file mode 100644
index 0000000..2f20509
--- /dev/null
+++ b/services/core/java/com/android/server/lights/LightsManager.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 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.lights;
+
+public abstract class LightsManager {
+    public static final int LIGHT_ID_BACKLIGHT = 0;
+    public static final int LIGHT_ID_KEYBOARD = 1;
+    public static final int LIGHT_ID_BUTTONS = 2;
+    public static final int LIGHT_ID_BATTERY = 3;
+    public static final int LIGHT_ID_NOTIFICATIONS = 4;
+    public static final int LIGHT_ID_ATTENTION = 5;
+    public static final int LIGHT_ID_BLUETOOTH = 6;
+    public static final int LIGHT_ID_WIFI = 7;
+    public static final int LIGHT_ID_COUNT = 8;
+
+    public abstract Light getLight(int id);
+}
diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java
new file mode 100644
index 0000000..62c0ec9
--- /dev/null
+++ b/services/core/java/com/android/server/lights/LightsService.java
@@ -0,0 +1,207 @@
+/*
+ * 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.server.lights;
+
+import com.android.server.SystemService;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Handler;
+import android.os.IHardwareService;
+import android.os.Message;
+import android.util.Slog;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+public class LightsService extends SystemService {
+    static final String TAG = "LightsService";
+    static final boolean DEBUG = false;
+
+    final LightImpl mLights[] = new LightImpl[LightsManager.LIGHT_ID_COUNT];
+
+    private final class LightImpl extends Light {
+
+        private LightImpl(int id) {
+            mId = id;
+        }
+
+        @Override
+        public void setBrightness(int brightness) {
+            setBrightness(brightness, BRIGHTNESS_MODE_USER);
+        }
+
+        @Override
+        public void setBrightness(int brightness, int brightnessMode) {
+            synchronized (this) {
+                int color = brightness & 0x000000ff;
+                color = 0xff000000 | (color << 16) | (color << 8) | color;
+                setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
+            }
+        }
+
+        @Override
+        public void setColor(int color) {
+            synchronized (this) {
+                setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, 0);
+            }
+        }
+
+        @Override
+        public void setFlashing(int color, int mode, int onMS, int offMS) {
+            synchronized (this) {
+                setLightLocked(color, mode, onMS, offMS, BRIGHTNESS_MODE_USER);
+            }
+        }
+
+        @Override
+        public void pulse() {
+            pulse(0x00ffffff, 7);
+        }
+
+        @Override
+        public void pulse(int color, int onMS) {
+            synchronized (this) {
+                if (mColor == 0 && !mFlashing) {
+                    setLightLocked(color, LIGHT_FLASH_HARDWARE, onMS, 1000, BRIGHTNESS_MODE_USER);
+                    mH.sendMessageDelayed(Message.obtain(mH, 1, this), onMS);
+                }
+            }
+        }
+
+        @Override
+        public void turnOff() {
+            synchronized (this) {
+                setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, 0);
+            }
+        }
+
+        private void stopFlashing() {
+            synchronized (this) {
+                setLightLocked(mColor, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_USER);
+            }
+        }
+
+        private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) {
+            if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) {
+                if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#"
+                        + Integer.toHexString(color));
+                mColor = color;
+                mMode = mode;
+                mOnMS = onMS;
+                mOffMS = offMS;
+                setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode);
+            }
+        }
+
+        private int mId;
+        private int mColor;
+        private int mMode;
+        private int mOnMS;
+        private int mOffMS;
+        private boolean mFlashing;
+    }
+
+    /* This class implements an obsolete API that was removed after eclair and re-added during the
+     * final moments of the froyo release to support flashlight apps that had been using the private
+     * IHardwareService API. This is expected to go away in the next release.
+     */
+    private final IHardwareService.Stub mLegacyFlashlightHack = new IHardwareService.Stub() {
+
+        private static final String FLASHLIGHT_FILE = "/sys/class/leds/spotlight/brightness";
+
+        public boolean getFlashlightEnabled() {
+            try {
+                FileInputStream fis = new FileInputStream(FLASHLIGHT_FILE);
+                int result = fis.read();
+                fis.close();
+                return (result != '0');
+            } catch (Exception e) {
+                return false;
+            }
+        }
+
+        public void setFlashlightEnabled(boolean on) {
+            final Context context = getContext();
+            if (context.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT)
+                    != PackageManager.PERMISSION_GRANTED &&
+                    context.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
+                    != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission");
+            }
+            try {
+                FileOutputStream fos = new FileOutputStream(FLASHLIGHT_FILE);
+                byte[] bytes = new byte[2];
+                bytes[0] = (byte)(on ? '1' : '0');
+                bytes[1] = '\n';
+                fos.write(bytes);
+                fos.close();
+            } catch (Exception e) {
+                // fail silently
+            }
+        }
+    };
+
+    public LightsService(Context context) {
+        super(context);
+
+        mNativePointer = init_native();
+
+        for (int i = 0; i < LightsManager.LIGHT_ID_COUNT; i++) {
+            mLights[i] = new LightImpl(i);
+        }
+    }
+
+    @Override
+    public void onStart() {
+        publishBinderService("hardware", mLegacyFlashlightHack);
+        publishLocalService(LightsManager.class, mService);
+    }
+
+    private final LightsManager mService = new LightsManager() {
+        @Override
+        public com.android.server.lights.Light getLight(int id) {
+            if (id < LIGHT_ID_COUNT) {
+                return mLights[id];
+            } else {
+                return null;
+            }
+        }
+    };
+
+    @Override
+    protected void finalize() throws Throwable {
+        finalize_native(mNativePointer);
+        super.finalize();
+    }
+
+    private Handler mH = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            LightImpl light = (LightImpl)msg.obj;
+            light.stopFlashing();
+        }
+    };
+
+    private static native long init_native();
+    private static native void finalize_native(long ptr);
+
+    static native void setLight_native(long ptr, int light, int color, int mode,
+            int onMS, int offMS, int brightnessMode);
+
+    private long mNativePointer;
+}
diff --git a/services/java/com/android/server/location/ComprehensiveCountryDetector.java b/services/core/java/com/android/server/location/ComprehensiveCountryDetector.java
similarity index 100%
rename from services/java/com/android/server/location/ComprehensiveCountryDetector.java
rename to services/core/java/com/android/server/location/ComprehensiveCountryDetector.java
diff --git a/services/java/com/android/server/location/CountryDetectorBase.java b/services/core/java/com/android/server/location/CountryDetectorBase.java
similarity index 100%
rename from services/java/com/android/server/location/CountryDetectorBase.java
rename to services/core/java/com/android/server/location/CountryDetectorBase.java
diff --git a/services/java/com/android/server/location/FlpHardwareProvider.java b/services/core/java/com/android/server/location/FlpHardwareProvider.java
similarity index 100%
rename from services/java/com/android/server/location/FlpHardwareProvider.java
rename to services/core/java/com/android/server/location/FlpHardwareProvider.java
diff --git a/services/java/com/android/server/location/FusedLocationHardwareSecure.java b/services/core/java/com/android/server/location/FusedLocationHardwareSecure.java
similarity index 100%
rename from services/java/com/android/server/location/FusedLocationHardwareSecure.java
rename to services/core/java/com/android/server/location/FusedLocationHardwareSecure.java
diff --git a/services/java/com/android/server/location/FusedProxy.java b/services/core/java/com/android/server/location/FusedProxy.java
similarity index 100%
rename from services/java/com/android/server/location/FusedProxy.java
rename to services/core/java/com/android/server/location/FusedProxy.java
diff --git a/services/java/com/android/server/location/GeocoderProxy.java b/services/core/java/com/android/server/location/GeocoderProxy.java
similarity index 100%
rename from services/java/com/android/server/location/GeocoderProxy.java
rename to services/core/java/com/android/server/location/GeocoderProxy.java
diff --git a/services/java/com/android/server/location/GeofenceManager.java b/services/core/java/com/android/server/location/GeofenceManager.java
similarity index 100%
rename from services/java/com/android/server/location/GeofenceManager.java
rename to services/core/java/com/android/server/location/GeofenceManager.java
diff --git a/services/java/com/android/server/location/GeofenceProxy.java b/services/core/java/com/android/server/location/GeofenceProxy.java
similarity index 100%
rename from services/java/com/android/server/location/GeofenceProxy.java
rename to services/core/java/com/android/server/location/GeofenceProxy.java
diff --git a/services/java/com/android/server/location/GeofenceState.java b/services/core/java/com/android/server/location/GeofenceState.java
similarity index 100%
rename from services/java/com/android/server/location/GeofenceState.java
rename to services/core/java/com/android/server/location/GeofenceState.java
diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java
similarity index 100%
rename from services/java/com/android/server/location/GpsLocationProvider.java
rename to services/core/java/com/android/server/location/GpsLocationProvider.java
diff --git a/services/java/com/android/server/location/GpsXtraDownloader.java b/services/core/java/com/android/server/location/GpsXtraDownloader.java
similarity index 100%
rename from services/java/com/android/server/location/GpsXtraDownloader.java
rename to services/core/java/com/android/server/location/GpsXtraDownloader.java
diff --git a/services/java/com/android/server/location/LocationBasedCountryDetector.java b/services/core/java/com/android/server/location/LocationBasedCountryDetector.java
similarity index 100%
rename from services/java/com/android/server/location/LocationBasedCountryDetector.java
rename to services/core/java/com/android/server/location/LocationBasedCountryDetector.java
diff --git a/services/java/com/android/server/location/LocationBlacklist.java b/services/core/java/com/android/server/location/LocationBlacklist.java
similarity index 100%
rename from services/java/com/android/server/location/LocationBlacklist.java
rename to services/core/java/com/android/server/location/LocationBlacklist.java
diff --git a/services/java/com/android/server/location/LocationFudger.java b/services/core/java/com/android/server/location/LocationFudger.java
similarity index 100%
rename from services/java/com/android/server/location/LocationFudger.java
rename to services/core/java/com/android/server/location/LocationFudger.java
diff --git a/services/java/com/android/server/location/LocationProviderInterface.java b/services/core/java/com/android/server/location/LocationProviderInterface.java
similarity index 100%
rename from services/java/com/android/server/location/LocationProviderInterface.java
rename to services/core/java/com/android/server/location/LocationProviderInterface.java
diff --git a/services/java/com/android/server/location/LocationProviderProxy.java b/services/core/java/com/android/server/location/LocationProviderProxy.java
similarity index 100%
rename from services/java/com/android/server/location/LocationProviderProxy.java
rename to services/core/java/com/android/server/location/LocationProviderProxy.java
diff --git a/services/java/com/android/server/location/MockProvider.java b/services/core/java/com/android/server/location/MockProvider.java
similarity index 100%
rename from services/java/com/android/server/location/MockProvider.java
rename to services/core/java/com/android/server/location/MockProvider.java
diff --git a/services/java/com/android/server/location/PassiveProvider.java b/services/core/java/com/android/server/location/PassiveProvider.java
similarity index 100%
rename from services/java/com/android/server/location/PassiveProvider.java
rename to services/core/java/com/android/server/location/PassiveProvider.java
diff --git a/services/core/java/com/android/server/media/MediaRouterService.java b/services/core/java/com/android/server/media/MediaRouterService.java
new file mode 100644
index 0000000..f91ea8c
--- /dev/null
+++ b/services/core/java/com/android/server/media/MediaRouterService.java
@@ -0,0 +1,1423 @@
+/*
+ * Copyright (C) 2013 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.media;
+
+import com.android.server.Watchdog;
+
+import android.Manifest;
+import android.app.ActivityManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.media.AudioSystem;
+import android.media.IMediaRouterClient;
+import android.media.IMediaRouterService;
+import android.media.MediaRouter;
+import android.media.MediaRouterClientState;
+import android.media.RemoteDisplayState;
+import android.media.RemoteDisplayState.RemoteDisplayInfo;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.text.TextUtils;
+import android.util.ArrayMap;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.TimeUtils;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Provides a mechanism for discovering media routes and manages media playback
+ * behalf of applications.
+ * <p>
+ * Currently supports discovering remote displays via remote display provider
+ * services that have been registered by applications.
+ * </p>
+ */
+public final class MediaRouterService extends IMediaRouterService.Stub
+        implements Watchdog.Monitor {
+    private static final String TAG = "MediaRouterService";
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+
+    /**
+     * Timeout in milliseconds for a selected route to transition from a
+     * disconnected state to a connecting state.  If we don't observe any
+     * progress within this interval, then we will give up and unselect the route.
+     */
+    static final long CONNECTING_TIMEOUT = 5000;
+
+    /**
+     * Timeout in milliseconds for a selected route to transition from a
+     * connecting state to a connected state.  If we don't observe any
+     * progress within this interval, then we will give up and unselect the route.
+     */
+    static final long CONNECTED_TIMEOUT = 60000;
+
+    private final Context mContext;
+
+    // State guarded by mLock.
+    private final Object mLock = new Object();
+    private final SparseArray<UserRecord> mUserRecords = new SparseArray<UserRecord>();
+    private final ArrayMap<IBinder, ClientRecord> mAllClientRecords =
+            new ArrayMap<IBinder, ClientRecord>();
+    private int mCurrentUserId = -1;
+
+    public MediaRouterService(Context context) {
+        mContext = context;
+        Watchdog.getInstance().addMonitor(this);
+    }
+
+    public void systemRunning() {
+        IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                if (intent.getAction().equals(Intent.ACTION_USER_SWITCHED)) {
+                    switchUser();
+                }
+            }
+        }, filter);
+
+        switchUser();
+    }
+
+    @Override
+    public void monitor() {
+        synchronized (mLock) { /* check for deadlock */ }
+    }
+
+    // Binder call
+    @Override
+    public void registerClientAsUser(IMediaRouterClient client, String packageName, int userId) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+
+        final int uid = Binder.getCallingUid();
+        if (!validatePackageName(uid, packageName)) {
+            throw new SecurityException("packageName must match the calling uid");
+        }
+
+        final int pid = Binder.getCallingPid();
+        final int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
+                false /*allowAll*/, true /*requireFull*/, "registerClientAsUser", packageName);
+        final boolean trusted = mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.CONFIGURE_WIFI_DISPLAY) ==
+                PackageManager.PERMISSION_GRANTED;
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                registerClientLocked(client, pid, packageName, resolvedUserId, trusted);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    @Override
+    public void unregisterClient(IMediaRouterClient client) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                unregisterClientLocked(client, false);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    @Override
+    public MediaRouterClientState getState(IMediaRouterClient client) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                return getStateLocked(client);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    @Override
+    public void setDiscoveryRequest(IMediaRouterClient client,
+            int routeTypes, boolean activeScan) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                setDiscoveryRequestLocked(client, routeTypes, activeScan);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    // A null routeId means that the client wants to unselect its current route.
+    // The explicit flag indicates whether the change was explicitly requested by the
+    // user or the application which may cause changes to propagate out to the rest
+    // of the system.  Should be false when the change is in response to a new globally
+    // selected route or a default selection.
+    @Override
+    public void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                setSelectedRouteLocked(client, routeId, explicit);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    @Override
+    public void requestSetVolume(IMediaRouterClient client, String routeId, int volume) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+        if (routeId == null) {
+            throw new IllegalArgumentException("routeId must not be null");
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                requestSetVolumeLocked(client, routeId, volume);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    @Override
+    public void requestUpdateVolume(IMediaRouterClient client, String routeId, int direction) {
+        if (client == null) {
+            throw new IllegalArgumentException("client must not be null");
+        }
+        if (routeId == null) {
+            throw new IllegalArgumentException("routeId must not be null");
+        }
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            synchronized (mLock) {
+                requestUpdateVolumeLocked(client, routeId, direction);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    // Binder call
+    @Override
+    public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump MediaRouterService from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        pw.println("MEDIA ROUTER SERVICE (dumpsys media_router)");
+        pw.println();
+        pw.println("Global state");
+        pw.println("  mCurrentUserId=" + mCurrentUserId);
+
+        synchronized (mLock) {
+            final int count = mUserRecords.size();
+            for (int i = 0; i < count; i++) {
+                UserRecord userRecord = mUserRecords.valueAt(i);
+                pw.println();
+                userRecord.dump(pw, "");
+            }
+        }
+    }
+
+    void switchUser() {
+        synchronized (mLock) {
+            int userId = ActivityManager.getCurrentUser();
+            if (mCurrentUserId != userId) {
+                final int oldUserId = mCurrentUserId;
+                mCurrentUserId = userId; // do this first
+
+                UserRecord oldUser = mUserRecords.get(oldUserId);
+                if (oldUser != null) {
+                    oldUser.mHandler.sendEmptyMessage(UserHandler.MSG_STOP);
+                    disposeUserIfNeededLocked(oldUser); // since no longer current user
+                }
+
+                UserRecord newUser = mUserRecords.get(userId);
+                if (newUser != null) {
+                    newUser.mHandler.sendEmptyMessage(UserHandler.MSG_START);
+                }
+            }
+        }
+    }
+
+    void clientDied(ClientRecord clientRecord) {
+        synchronized (mLock) {
+            unregisterClientLocked(clientRecord.mClient, true);
+        }
+    }
+
+    private void registerClientLocked(IMediaRouterClient client,
+            int pid, String packageName, int userId, boolean trusted) {
+        final IBinder binder = client.asBinder();
+        ClientRecord clientRecord = mAllClientRecords.get(binder);
+        if (clientRecord == null) {
+            boolean newUser = false;
+            UserRecord userRecord = mUserRecords.get(userId);
+            if (userRecord == null) {
+                userRecord = new UserRecord(userId);
+                newUser = true;
+            }
+            clientRecord = new ClientRecord(userRecord, client, pid, packageName, trusted);
+            try {
+                binder.linkToDeath(clientRecord, 0);
+            } catch (RemoteException ex) {
+                throw new RuntimeException("Media router client died prematurely.", ex);
+            }
+
+            if (newUser) {
+                mUserRecords.put(userId, userRecord);
+                initializeUserLocked(userRecord);
+            }
+
+            userRecord.mClientRecords.add(clientRecord);
+            mAllClientRecords.put(binder, clientRecord);
+            initializeClientLocked(clientRecord);
+        }
+    }
+
+    private void unregisterClientLocked(IMediaRouterClient client, boolean died) {
+        ClientRecord clientRecord = mAllClientRecords.remove(client.asBinder());
+        if (clientRecord != null) {
+            UserRecord userRecord = clientRecord.mUserRecord;
+            userRecord.mClientRecords.remove(clientRecord);
+            disposeClientLocked(clientRecord, died);
+            disposeUserIfNeededLocked(userRecord); // since client removed from user
+        }
+    }
+
+    private MediaRouterClientState getStateLocked(IMediaRouterClient client) {
+        ClientRecord clientRecord = mAllClientRecords.get(client.asBinder());
+        if (clientRecord != null) {
+            return clientRecord.getState();
+        }
+        return null;
+    }
+
+    private void setDiscoveryRequestLocked(IMediaRouterClient client,
+            int routeTypes, boolean activeScan) {
+        final IBinder binder = client.asBinder();
+        ClientRecord clientRecord = mAllClientRecords.get(binder);
+        if (clientRecord != null) {
+            // Only let the system discover remote display routes for now.
+            if (!clientRecord.mTrusted) {
+                routeTypes &= ~MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
+            }
+
+            if (clientRecord.mRouteTypes != routeTypes
+                    || clientRecord.mActiveScan != activeScan) {
+                if (DEBUG) {
+                    Slog.d(TAG, clientRecord + ": Set discovery request, routeTypes=0x"
+                            + Integer.toHexString(routeTypes) + ", activeScan=" + activeScan);
+                }
+                clientRecord.mRouteTypes = routeTypes;
+                clientRecord.mActiveScan = activeScan;
+                clientRecord.mUserRecord.mHandler.sendEmptyMessage(
+                        UserHandler.MSG_UPDATE_DISCOVERY_REQUEST);
+            }
+        }
+    }
+
+    private void setSelectedRouteLocked(IMediaRouterClient client,
+            String routeId, boolean explicit) {
+        ClientRecord clientRecord = mAllClientRecords.get(client.asBinder());
+        if (clientRecord != null) {
+            final String oldRouteId = clientRecord.mSelectedRouteId;
+            if (!Objects.equals(routeId, oldRouteId)) {
+                if (DEBUG) {
+                    Slog.d(TAG, clientRecord + ": Set selected route, routeId=" + routeId
+                            + ", oldRouteId=" + oldRouteId
+                            + ", explicit=" + explicit);
+                }
+
+                clientRecord.mSelectedRouteId = routeId;
+                if (explicit) {
+                    // Any app can disconnect from the globally selected route.
+                    if (oldRouteId != null) {
+                        clientRecord.mUserRecord.mHandler.obtainMessage(
+                                UserHandler.MSG_UNSELECT_ROUTE, oldRouteId).sendToTarget();
+                    }
+                    // Only let the system connect to new global routes for now.
+                    // A similar check exists in the display manager for wifi display.
+                    if (routeId != null && clientRecord.mTrusted) {
+                        clientRecord.mUserRecord.mHandler.obtainMessage(
+                                UserHandler.MSG_SELECT_ROUTE, routeId).sendToTarget();
+                    }
+                }
+            }
+        }
+    }
+
+    private void requestSetVolumeLocked(IMediaRouterClient client,
+            String routeId, int volume) {
+        final IBinder binder = client.asBinder();
+        ClientRecord clientRecord = mAllClientRecords.get(binder);
+        if (clientRecord != null) {
+            clientRecord.mUserRecord.mHandler.obtainMessage(
+                    UserHandler.MSG_REQUEST_SET_VOLUME, volume, 0, routeId).sendToTarget();
+        }
+    }
+
+    private void requestUpdateVolumeLocked(IMediaRouterClient client,
+            String routeId, int direction) {
+        final IBinder binder = client.asBinder();
+        ClientRecord clientRecord = mAllClientRecords.get(binder);
+        if (clientRecord != null) {
+            clientRecord.mUserRecord.mHandler.obtainMessage(
+                    UserHandler.MSG_REQUEST_UPDATE_VOLUME, direction, 0, routeId).sendToTarget();
+        }
+    }
+
+    private void initializeUserLocked(UserRecord userRecord) {
+        if (DEBUG) {
+            Slog.d(TAG, userRecord + ": Initialized");
+        }
+        if (userRecord.mUserId == mCurrentUserId) {
+            userRecord.mHandler.sendEmptyMessage(UserHandler.MSG_START);
+        }
+    }
+
+    private void disposeUserIfNeededLocked(UserRecord userRecord) {
+        // If there are no records left and the user is no longer current then go ahead
+        // and purge the user record and all of its associated state.  If the user is current
+        // then leave it alone since we might be connected to a route or want to query
+        // the same route information again soon.
+        if (userRecord.mUserId != mCurrentUserId
+                && userRecord.mClientRecords.isEmpty()) {
+            if (DEBUG) {
+                Slog.d(TAG, userRecord + ": Disposed");
+            }
+            mUserRecords.remove(userRecord.mUserId);
+            // Note: User already stopped (by switchUser) so no need to send stop message here.
+        }
+    }
+
+    private void initializeClientLocked(ClientRecord clientRecord) {
+        if (DEBUG) {
+            Slog.d(TAG, clientRecord + ": Registered");
+        }
+    }
+
+    private void disposeClientLocked(ClientRecord clientRecord, boolean died) {
+        if (DEBUG) {
+            if (died) {
+                Slog.d(TAG, clientRecord + ": Died!");
+            } else {
+                Slog.d(TAG, clientRecord + ": Unregistered");
+            }
+        }
+        if (clientRecord.mRouteTypes != 0 || clientRecord.mActiveScan) {
+            clientRecord.mUserRecord.mHandler.sendEmptyMessage(
+                    UserHandler.MSG_UPDATE_DISCOVERY_REQUEST);
+        }
+        clientRecord.dispose();
+    }
+
+    private boolean validatePackageName(int uid, String packageName) {
+        if (packageName != null) {
+            String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
+            if (packageNames != null) {
+                for (String n : packageNames) {
+                    if (n.equals(packageName)) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Information about a particular client of the media router.
+     * The contents of this object is guarded by mLock.
+     */
+    final class ClientRecord implements DeathRecipient {
+        public final UserRecord mUserRecord;
+        public final IMediaRouterClient mClient;
+        public final int mPid;
+        public final String mPackageName;
+        public final boolean mTrusted;
+
+        public int mRouteTypes;
+        public boolean mActiveScan;
+        public String mSelectedRouteId;
+
+        public ClientRecord(UserRecord userRecord, IMediaRouterClient client,
+                int pid, String packageName, boolean trusted) {
+            mUserRecord = userRecord;
+            mClient = client;
+            mPid = pid;
+            mPackageName = packageName;
+            mTrusted = trusted;
+        }
+
+        public void dispose() {
+            mClient.asBinder().unlinkToDeath(this, 0);
+        }
+
+        @Override
+        public void binderDied() {
+            clientDied(this);
+        }
+
+        MediaRouterClientState getState() {
+            return mTrusted ? mUserRecord.mTrustedState : mUserRecord.mUntrustedState;
+        }
+
+        public void dump(PrintWriter pw, String prefix) {
+            pw.println(prefix + this);
+
+            final String indent = prefix + "  ";
+            pw.println(indent + "mTrusted=" + mTrusted);
+            pw.println(indent + "mRouteTypes=0x" + Integer.toHexString(mRouteTypes));
+            pw.println(indent + "mActiveScan=" + mActiveScan);
+            pw.println(indent + "mSelectedRouteId=" + mSelectedRouteId);
+        }
+
+        @Override
+        public String toString() {
+            return "Client " + mPackageName + " (pid " + mPid + ")";
+        }
+    }
+
+    /**
+     * Information about a particular user.
+     * The contents of this object is guarded by mLock.
+     */
+    final class UserRecord {
+        public final int mUserId;
+        public final ArrayList<ClientRecord> mClientRecords = new ArrayList<ClientRecord>();
+        public final UserHandler mHandler;
+        public MediaRouterClientState mTrustedState;
+        public MediaRouterClientState mUntrustedState;
+
+        public UserRecord(int userId) {
+            mUserId = userId;
+            mHandler = new UserHandler(MediaRouterService.this, this);
+        }
+
+        public void dump(final PrintWriter pw, String prefix) {
+            pw.println(prefix + this);
+
+            final String indent = prefix + "  ";
+            final int clientCount = mClientRecords.size();
+            if (clientCount != 0) {
+                for (int i = 0; i < clientCount; i++) {
+                    mClientRecords.get(i).dump(pw, indent);
+                }
+            } else {
+                pw.println(indent + "<no clients>");
+            }
+
+            pw.println(indent + "State");
+            pw.println(indent + "mTrustedState=" + mTrustedState);
+            pw.println(indent + "mUntrustedState=" + mUntrustedState);
+
+            if (!mHandler.runWithScissors(new Runnable() {
+                @Override
+                public void run() {
+                    mHandler.dump(pw, indent);
+                }
+            }, 1000)) {
+                pw.println(indent + "<could not dump handler state>");
+            }
+         }
+
+        @Override
+        public String toString() {
+            return "User " + mUserId;
+        }
+    }
+
+    /**
+     * Media router handler
+     * <p>
+     * Since remote display providers are designed to be single-threaded by nature,
+     * this class encapsulates all of the associated functionality and exports state
+     * to the service as it evolves.
+     * </p><p>
+     * One important task of this class is to keep track of the current globally selected
+     * route id for certain routes that have global effects, such as remote displays.
+     * Global route selections override local selections made within apps.  The change
+     * is propagated to all apps so that they are all in sync.  Synchronization works
+     * both ways.  Whenever the globally selected route is explicitly unselected by any
+     * app, then it becomes unselected globally and all apps are informed.
+     * </p><p>
+     * This class is currently hardcoded to work with remote display providers but
+     * it is intended to be eventually extended to support more general route providers
+     * similar to the support library media router.
+     * </p>
+     */
+    static final class UserHandler extends Handler
+            implements RemoteDisplayProviderWatcher.Callback,
+            RemoteDisplayProviderProxy.Callback {
+        public static final int MSG_START = 1;
+        public static final int MSG_STOP = 2;
+        public static final int MSG_UPDATE_DISCOVERY_REQUEST = 3;
+        public static final int MSG_SELECT_ROUTE = 4;
+        public static final int MSG_UNSELECT_ROUTE = 5;
+        public static final int MSG_REQUEST_SET_VOLUME = 6;
+        public static final int MSG_REQUEST_UPDATE_VOLUME = 7;
+        private static final int MSG_UPDATE_CLIENT_STATE = 8;
+        private static final int MSG_CONNECTION_TIMED_OUT = 9;
+
+        private static final int TIMEOUT_REASON_NOT_AVAILABLE = 1;
+        private static final int TIMEOUT_REASON_CONNECTION_LOST = 2;
+        private static final int TIMEOUT_REASON_WAITING_FOR_CONNECTING = 3;
+        private static final int TIMEOUT_REASON_WAITING_FOR_CONNECTED = 4;
+
+        // The relative order of these constants is important and expresses progress
+        // through the process of connecting to a route.
+        private static final int PHASE_NOT_AVAILABLE = -1;
+        private static final int PHASE_NOT_CONNECTED = 0;
+        private static final int PHASE_CONNECTING = 1;
+        private static final int PHASE_CONNECTED = 2;
+
+        private final MediaRouterService mService;
+        private final UserRecord mUserRecord;
+        private final RemoteDisplayProviderWatcher mWatcher;
+        private final ArrayList<ProviderRecord> mProviderRecords =
+                new ArrayList<ProviderRecord>();
+        private final ArrayList<IMediaRouterClient> mTempClients =
+                new ArrayList<IMediaRouterClient>();
+
+        private boolean mRunning;
+        private int mDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_NONE;
+        private RouteRecord mGloballySelectedRouteRecord;
+        private int mConnectionPhase = PHASE_NOT_AVAILABLE;
+        private int mConnectionTimeoutReason;
+        private long mConnectionTimeoutStartTime;
+        private boolean mClientStateUpdateScheduled;
+
+        public UserHandler(MediaRouterService service, UserRecord userRecord) {
+            super(Looper.getMainLooper(), null, true);
+            mService = service;
+            mUserRecord = userRecord;
+            mWatcher = new RemoteDisplayProviderWatcher(service.mContext, this,
+                    this, mUserRecord.mUserId);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_START: {
+                    start();
+                    break;
+                }
+                case MSG_STOP: {
+                    stop();
+                    break;
+                }
+                case MSG_UPDATE_DISCOVERY_REQUEST: {
+                    updateDiscoveryRequest();
+                    break;
+                }
+                case MSG_SELECT_ROUTE: {
+                    selectRoute((String)msg.obj);
+                    break;
+                }
+                case MSG_UNSELECT_ROUTE: {
+                    unselectRoute((String)msg.obj);
+                    break;
+                }
+                case MSG_REQUEST_SET_VOLUME: {
+                    requestSetVolume((String)msg.obj, msg.arg1);
+                    break;
+                }
+                case MSG_REQUEST_UPDATE_VOLUME: {
+                    requestUpdateVolume((String)msg.obj, msg.arg1);
+                    break;
+                }
+                case MSG_UPDATE_CLIENT_STATE: {
+                    updateClientState();
+                    break;
+                }
+                case MSG_CONNECTION_TIMED_OUT: {
+                    connectionTimedOut();
+                    break;
+                }
+            }
+        }
+
+        public void dump(PrintWriter pw, String prefix) {
+            pw.println(prefix + "Handler");
+
+            final String indent = prefix + "  ";
+            pw.println(indent + "mRunning=" + mRunning);
+            pw.println(indent + "mDiscoveryMode=" + mDiscoveryMode);
+            pw.println(indent + "mGloballySelectedRouteRecord=" + mGloballySelectedRouteRecord);
+            pw.println(indent + "mConnectionPhase=" + mConnectionPhase);
+            pw.println(indent + "mConnectionTimeoutReason=" + mConnectionTimeoutReason);
+            pw.println(indent + "mConnectionTimeoutStartTime=" + (mConnectionTimeoutReason != 0 ?
+                    TimeUtils.formatUptime(mConnectionTimeoutStartTime) : "<n/a>"));
+
+            mWatcher.dump(pw, prefix);
+
+            final int providerCount = mProviderRecords.size();
+            if (providerCount != 0) {
+                for (int i = 0; i < providerCount; i++) {
+                    mProviderRecords.get(i).dump(pw, prefix);
+                }
+            } else {
+                pw.println(indent + "<no providers>");
+            }
+        }
+
+        private void start() {
+            if (!mRunning) {
+                mRunning = true;
+                mWatcher.start(); // also starts all providers
+            }
+        }
+
+        private void stop() {
+            if (mRunning) {
+                mRunning = false;
+                unselectGloballySelectedRoute();
+                mWatcher.stop(); // also stops all providers
+            }
+        }
+
+        private void updateDiscoveryRequest() {
+            int routeTypes = 0;
+            boolean activeScan = false;
+            synchronized (mService.mLock) {
+                final int count = mUserRecord.mClientRecords.size();
+                for (int i = 0; i < count; i++) {
+                    ClientRecord clientRecord = mUserRecord.mClientRecords.get(i);
+                    routeTypes |= clientRecord.mRouteTypes;
+                    activeScan |= clientRecord.mActiveScan;
+                }
+            }
+
+            final int newDiscoveryMode;
+            if ((routeTypes & MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY) != 0) {
+                if (activeScan) {
+                    newDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_ACTIVE;
+                } else {
+                    newDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_PASSIVE;
+                }
+            } else {
+                newDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_NONE;
+            }
+
+            if (mDiscoveryMode != newDiscoveryMode) {
+                mDiscoveryMode = newDiscoveryMode;
+                final int count = mProviderRecords.size();
+                for (int i = 0; i < count; i++) {
+                    mProviderRecords.get(i).getProvider().setDiscoveryMode(mDiscoveryMode);
+                }
+            }
+        }
+
+        private void selectRoute(String routeId) {
+            if (routeId != null
+                    && (mGloballySelectedRouteRecord == null
+                            || !routeId.equals(mGloballySelectedRouteRecord.getUniqueId()))) {
+                RouteRecord routeRecord = findRouteRecord(routeId);
+                if (routeRecord != null) {
+                    unselectGloballySelectedRoute();
+
+                    Slog.i(TAG, "Selected global route:" + routeRecord);
+                    mGloballySelectedRouteRecord = routeRecord;
+                    checkGloballySelectedRouteState();
+                    routeRecord.getProvider().setSelectedDisplay(routeRecord.getDescriptorId());
+
+                    scheduleUpdateClientState();
+                }
+            }
+        }
+
+        private void unselectRoute(String routeId) {
+            if (routeId != null
+                    && mGloballySelectedRouteRecord != null
+                    && routeId.equals(mGloballySelectedRouteRecord.getUniqueId())) {
+                unselectGloballySelectedRoute();
+            }
+        }
+
+        private void unselectGloballySelectedRoute() {
+            if (mGloballySelectedRouteRecord != null) {
+                Slog.i(TAG, "Unselected global route:" + mGloballySelectedRouteRecord);
+                mGloballySelectedRouteRecord.getProvider().setSelectedDisplay(null);
+                mGloballySelectedRouteRecord = null;
+                checkGloballySelectedRouteState();
+
+                scheduleUpdateClientState();
+            }
+        }
+
+        private void requestSetVolume(String routeId, int volume) {
+            if (mGloballySelectedRouteRecord != null
+                    && routeId.equals(mGloballySelectedRouteRecord.getUniqueId())) {
+                mGloballySelectedRouteRecord.getProvider().setDisplayVolume(volume);
+            }
+        }
+
+        private void requestUpdateVolume(String routeId, int direction) {
+            if (mGloballySelectedRouteRecord != null
+                    && routeId.equals(mGloballySelectedRouteRecord.getUniqueId())) {
+                mGloballySelectedRouteRecord.getProvider().adjustDisplayVolume(direction);
+            }
+        }
+
+        @Override
+        public void addProvider(RemoteDisplayProviderProxy provider) {
+            provider.setCallback(this);
+            provider.setDiscoveryMode(mDiscoveryMode);
+            provider.setSelectedDisplay(null); // just to be safe
+
+            ProviderRecord providerRecord = new ProviderRecord(provider);
+            mProviderRecords.add(providerRecord);
+            providerRecord.updateDescriptor(provider.getDisplayState());
+
+            scheduleUpdateClientState();
+        }
+
+        @Override
+        public void removeProvider(RemoteDisplayProviderProxy provider) {
+            int index = findProviderRecord(provider);
+            if (index >= 0) {
+                ProviderRecord providerRecord = mProviderRecords.remove(index);
+                providerRecord.updateDescriptor(null); // mark routes invalid
+                provider.setCallback(null);
+                provider.setDiscoveryMode(RemoteDisplayState.DISCOVERY_MODE_NONE);
+
+                checkGloballySelectedRouteState();
+                scheduleUpdateClientState();
+            }
+        }
+
+        @Override
+        public void onDisplayStateChanged(RemoteDisplayProviderProxy provider,
+                RemoteDisplayState state) {
+            updateProvider(provider, state);
+        }
+
+        private void updateProvider(RemoteDisplayProviderProxy provider,
+                RemoteDisplayState state) {
+            int index = findProviderRecord(provider);
+            if (index >= 0) {
+                ProviderRecord providerRecord = mProviderRecords.get(index);
+                if (providerRecord.updateDescriptor(state)) {
+                    checkGloballySelectedRouteState();
+                    scheduleUpdateClientState();
+                }
+            }
+        }
+
+        /**
+         * This function is called whenever the state of the globally selected route
+         * may have changed.  It checks the state and updates timeouts or unselects
+         * the route as appropriate.
+         */
+        private void checkGloballySelectedRouteState() {
+            // Unschedule timeouts when the route is unselected.
+            if (mGloballySelectedRouteRecord == null) {
+                mConnectionPhase = PHASE_NOT_AVAILABLE;
+                updateConnectionTimeout(0);
+                return;
+            }
+
+            // Ensure that the route is still present and enabled.
+            if (!mGloballySelectedRouteRecord.isValid()
+                    || !mGloballySelectedRouteRecord.isEnabled()) {
+                updateConnectionTimeout(TIMEOUT_REASON_NOT_AVAILABLE);
+                return;
+            }
+
+            // Make sure we haven't lost our connection.
+            final int oldPhase = mConnectionPhase;
+            mConnectionPhase = getConnectionPhase(mGloballySelectedRouteRecord.getStatus());
+            if (oldPhase >= PHASE_CONNECTING && mConnectionPhase < PHASE_CONNECTING) {
+                updateConnectionTimeout(TIMEOUT_REASON_CONNECTION_LOST);
+                return;
+            }
+
+            // Check the route status.
+            switch (mConnectionPhase) {
+                case PHASE_CONNECTED:
+                    if (oldPhase != PHASE_CONNECTED) {
+                        Slog.i(TAG, "Connected to global route: "
+                                + mGloballySelectedRouteRecord);
+                    }
+                    updateConnectionTimeout(0);
+                    break;
+                case PHASE_CONNECTING:
+                    if (oldPhase != PHASE_CONNECTING) {
+                        Slog.i(TAG, "Connecting to global route: "
+                                + mGloballySelectedRouteRecord);
+                    }
+                    updateConnectionTimeout(TIMEOUT_REASON_WAITING_FOR_CONNECTED);
+                    break;
+                case PHASE_NOT_CONNECTED:
+                    updateConnectionTimeout(TIMEOUT_REASON_WAITING_FOR_CONNECTING);
+                    break;
+                case PHASE_NOT_AVAILABLE:
+                default:
+                    updateConnectionTimeout(TIMEOUT_REASON_NOT_AVAILABLE);
+                    break;
+            }
+        }
+
+        private void updateConnectionTimeout(int reason) {
+            if (reason != mConnectionTimeoutReason) {
+                if (mConnectionTimeoutReason != 0) {
+                    removeMessages(MSG_CONNECTION_TIMED_OUT);
+                }
+                mConnectionTimeoutReason = reason;
+                mConnectionTimeoutStartTime = SystemClock.uptimeMillis();
+                switch (reason) {
+                    case TIMEOUT_REASON_NOT_AVAILABLE:
+                    case TIMEOUT_REASON_CONNECTION_LOST:
+                        // Route became unavailable or connection lost.
+                        // Unselect it immediately.
+                        sendEmptyMessage(MSG_CONNECTION_TIMED_OUT);
+                        break;
+                    case TIMEOUT_REASON_WAITING_FOR_CONNECTING:
+                        // Waiting for route to start connecting.
+                        sendEmptyMessageDelayed(MSG_CONNECTION_TIMED_OUT, CONNECTING_TIMEOUT);
+                        break;
+                    case TIMEOUT_REASON_WAITING_FOR_CONNECTED:
+                        // Waiting for route to complete connection.
+                        sendEmptyMessageDelayed(MSG_CONNECTION_TIMED_OUT, CONNECTED_TIMEOUT);
+                        break;
+                }
+            }
+        }
+
+        private void connectionTimedOut() {
+            if (mConnectionTimeoutReason == 0 || mGloballySelectedRouteRecord == null) {
+                // Shouldn't get here.  There must be a bug somewhere.
+                Log.wtf(TAG, "Handled connection timeout for no reason.");
+                return;
+            }
+
+            switch (mConnectionTimeoutReason) {
+                case TIMEOUT_REASON_NOT_AVAILABLE:
+                    Slog.i(TAG, "Global route no longer available: "
+                            + mGloballySelectedRouteRecord);
+                    break;
+                case TIMEOUT_REASON_CONNECTION_LOST:
+                    Slog.i(TAG, "Global route connection lost: "
+                            + mGloballySelectedRouteRecord);
+                    break;
+                case TIMEOUT_REASON_WAITING_FOR_CONNECTING:
+                    Slog.i(TAG, "Global route timed out while waiting for "
+                            + "connection attempt to begin after "
+                            + (SystemClock.uptimeMillis() - mConnectionTimeoutStartTime)
+                            + " ms: " + mGloballySelectedRouteRecord);
+                    break;
+                case TIMEOUT_REASON_WAITING_FOR_CONNECTED:
+                    Slog.i(TAG, "Global route timed out while connecting after "
+                            + (SystemClock.uptimeMillis() - mConnectionTimeoutStartTime)
+                            + " ms: " + mGloballySelectedRouteRecord);
+                    break;
+            }
+            mConnectionTimeoutReason = 0;
+
+            unselectGloballySelectedRoute();
+        }
+
+        private void scheduleUpdateClientState() {
+            if (!mClientStateUpdateScheduled) {
+                mClientStateUpdateScheduled = true;
+                sendEmptyMessage(MSG_UPDATE_CLIENT_STATE);
+            }
+        }
+
+        private void updateClientState() {
+            mClientStateUpdateScheduled = false;
+
+            final String globallySelectedRouteId = mGloballySelectedRouteRecord != null ?
+                    mGloballySelectedRouteRecord.getUniqueId() : null;
+
+            // Build a new client state for trusted clients.
+            MediaRouterClientState trustedState = new MediaRouterClientState();
+            trustedState.globallySelectedRouteId = globallySelectedRouteId;
+            final int providerCount = mProviderRecords.size();
+            for (int i = 0; i < providerCount; i++) {
+                mProviderRecords.get(i).appendClientState(trustedState);
+            }
+
+            // Build a new client state for untrusted clients that can only see
+            // the currently selected route.
+            MediaRouterClientState untrustedState = new MediaRouterClientState();
+            untrustedState.globallySelectedRouteId = globallySelectedRouteId;
+            if (globallySelectedRouteId != null) {
+                untrustedState.routes.add(trustedState.getRoute(globallySelectedRouteId));
+            }
+
+            try {
+                synchronized (mService.mLock) {
+                    // Update the UserRecord.
+                    mUserRecord.mTrustedState = trustedState;
+                    mUserRecord.mUntrustedState = untrustedState;
+
+                    // Collect all clients.
+                    final int count = mUserRecord.mClientRecords.size();
+                    for (int i = 0; i < count; i++) {
+                        mTempClients.add(mUserRecord.mClientRecords.get(i).mClient);
+                    }
+                }
+
+                // Notify all clients (outside of the lock).
+                final int count = mTempClients.size();
+                for (int i = 0; i < count; i++) {
+                    try {
+                        mTempClients.get(i).onStateChanged();
+                    } catch (RemoteException ex) {
+                        // ignore errors, client probably died
+                    }
+                }
+            } finally {
+                // Clear the list in preparation for the next time.
+                mTempClients.clear();
+            }
+        }
+
+        private int findProviderRecord(RemoteDisplayProviderProxy provider) {
+            final int count = mProviderRecords.size();
+            for (int i = 0; i < count; i++) {
+                ProviderRecord record = mProviderRecords.get(i);
+                if (record.getProvider() == provider) {
+                    return i;
+                }
+            }
+            return -1;
+        }
+
+        private RouteRecord findRouteRecord(String uniqueId) {
+            final int count = mProviderRecords.size();
+            for (int i = 0; i < count; i++) {
+                RouteRecord record = mProviderRecords.get(i).findRouteByUniqueId(uniqueId);
+                if (record != null) {
+                    return record;
+                }
+            }
+            return null;
+        }
+
+        private static int getConnectionPhase(int status) {
+            switch (status) {
+                case MediaRouter.RouteInfo.STATUS_NONE:
+                case MediaRouter.RouteInfo.STATUS_CONNECTED:
+                    return PHASE_CONNECTED;
+                case MediaRouter.RouteInfo.STATUS_CONNECTING:
+                    return PHASE_CONNECTING;
+                case MediaRouter.RouteInfo.STATUS_SCANNING:
+                case MediaRouter.RouteInfo.STATUS_AVAILABLE:
+                    return PHASE_NOT_CONNECTED;
+                case MediaRouter.RouteInfo.STATUS_NOT_AVAILABLE:
+                case MediaRouter.RouteInfo.STATUS_IN_USE:
+                default:
+                    return PHASE_NOT_AVAILABLE;
+            }
+        }
+
+        static final class ProviderRecord {
+            private final RemoteDisplayProviderProxy mProvider;
+            private final String mUniquePrefix;
+            private final ArrayList<RouteRecord> mRoutes = new ArrayList<RouteRecord>();
+            private RemoteDisplayState mDescriptor;
+
+            public ProviderRecord(RemoteDisplayProviderProxy provider) {
+                mProvider = provider;
+                mUniquePrefix = provider.getFlattenedComponentName() + ":";
+            }
+
+            public RemoteDisplayProviderProxy getProvider() {
+                return mProvider;
+            }
+
+            public String getUniquePrefix() {
+                return mUniquePrefix;
+            }
+
+            public boolean updateDescriptor(RemoteDisplayState descriptor) {
+                boolean changed = false;
+                if (mDescriptor != descriptor) {
+                    mDescriptor = descriptor;
+
+                    // Update all existing routes and reorder them to match
+                    // the order of their descriptors.
+                    int targetIndex = 0;
+                    if (descriptor != null) {
+                        if (descriptor.isValid()) {
+                            final List<RemoteDisplayInfo> routeDescriptors = descriptor.displays;
+                            final int routeCount = routeDescriptors.size();
+                            for (int i = 0; i < routeCount; i++) {
+                                final RemoteDisplayInfo routeDescriptor =
+                                        routeDescriptors.get(i);
+                                final String descriptorId = routeDescriptor.id;
+                                final int sourceIndex = findRouteByDescriptorId(descriptorId);
+                                if (sourceIndex < 0) {
+                                    // Add the route to the provider.
+                                    String uniqueId = assignRouteUniqueId(descriptorId);
+                                    RouteRecord route =
+                                            new RouteRecord(this, descriptorId, uniqueId);
+                                    mRoutes.add(targetIndex++, route);
+                                    route.updateDescriptor(routeDescriptor);
+                                    changed = true;
+                                } else if (sourceIndex < targetIndex) {
+                                    // Ignore route with duplicate id.
+                                    Slog.w(TAG, "Ignoring route descriptor with duplicate id: "
+                                            + routeDescriptor);
+                                } else {
+                                    // Reorder existing route within the list.
+                                    RouteRecord route = mRoutes.get(sourceIndex);
+                                    Collections.swap(mRoutes, sourceIndex, targetIndex++);
+                                    changed |= route.updateDescriptor(routeDescriptor);
+                                }
+                            }
+                        } else {
+                            Slog.w(TAG, "Ignoring invalid descriptor from media route provider: "
+                                    + mProvider.getFlattenedComponentName());
+                        }
+                    }
+
+                    // Dispose all remaining routes that do not have matching descriptors.
+                    for (int i = mRoutes.size() - 1; i >= targetIndex; i--) {
+                        RouteRecord route = mRoutes.remove(i);
+                        route.updateDescriptor(null); // mark route invalid
+                        changed = true;
+                    }
+                }
+                return changed;
+            }
+
+            public void appendClientState(MediaRouterClientState state) {
+                final int routeCount = mRoutes.size();
+                for (int i = 0; i < routeCount; i++) {
+                    state.routes.add(mRoutes.get(i).getInfo());
+                }
+            }
+
+            public RouteRecord findRouteByUniqueId(String uniqueId) {
+                final int routeCount = mRoutes.size();
+                for (int i = 0; i < routeCount; i++) {
+                    RouteRecord route = mRoutes.get(i);
+                    if (route.getUniqueId().equals(uniqueId)) {
+                        return route;
+                    }
+                }
+                return null;
+            }
+
+            private int findRouteByDescriptorId(String descriptorId) {
+                final int routeCount = mRoutes.size();
+                for (int i = 0; i < routeCount; i++) {
+                    RouteRecord route = mRoutes.get(i);
+                    if (route.getDescriptorId().equals(descriptorId)) {
+                        return i;
+                    }
+                }
+                return -1;
+            }
+
+            public void dump(PrintWriter pw, String prefix) {
+                pw.println(prefix + this);
+
+                final String indent = prefix + "  ";
+                mProvider.dump(pw, indent);
+
+                final int routeCount = mRoutes.size();
+                if (routeCount != 0) {
+                    for (int i = 0; i < routeCount; i++) {
+                        mRoutes.get(i).dump(pw, indent);
+                    }
+                } else {
+                    pw.println(indent + "<no routes>");
+                }
+            }
+
+            @Override
+            public String toString() {
+                return "Provider " + mProvider.getFlattenedComponentName();
+            }
+
+            private String assignRouteUniqueId(String descriptorId) {
+                return mUniquePrefix + descriptorId;
+            }
+        }
+
+        static final class RouteRecord {
+            private final ProviderRecord mProviderRecord;
+            private final String mDescriptorId;
+            private final MediaRouterClientState.RouteInfo mMutableInfo;
+            private MediaRouterClientState.RouteInfo mImmutableInfo;
+            private RemoteDisplayInfo mDescriptor;
+
+            public RouteRecord(ProviderRecord providerRecord,
+                    String descriptorId, String uniqueId) {
+                mProviderRecord = providerRecord;
+                mDescriptorId = descriptorId;
+                mMutableInfo = new MediaRouterClientState.RouteInfo(uniqueId);
+            }
+
+            public RemoteDisplayProviderProxy getProvider() {
+                return mProviderRecord.getProvider();
+            }
+
+            public ProviderRecord getProviderRecord() {
+                return mProviderRecord;
+            }
+
+            public String getDescriptorId() {
+                return mDescriptorId;
+            }
+
+            public String getUniqueId() {
+                return mMutableInfo.id;
+            }
+
+            public MediaRouterClientState.RouteInfo getInfo() {
+                if (mImmutableInfo == null) {
+                    mImmutableInfo = new MediaRouterClientState.RouteInfo(mMutableInfo);
+                }
+                return mImmutableInfo;
+            }
+
+            public boolean isValid() {
+                return mDescriptor != null;
+            }
+
+            public boolean isEnabled() {
+                return mMutableInfo.enabled;
+            }
+
+            public int getStatus() {
+                return mMutableInfo.statusCode;
+            }
+
+            public boolean updateDescriptor(RemoteDisplayInfo descriptor) {
+                boolean changed = false;
+                if (mDescriptor != descriptor) {
+                    mDescriptor = descriptor;
+                    if (descriptor != null) {
+                        final String name = computeName(descriptor);
+                        if (!Objects.equals(mMutableInfo.name, name)) {
+                            mMutableInfo.name = name;
+                            changed = true;
+                        }
+                        final String description = computeDescription(descriptor);
+                        if (!Objects.equals(mMutableInfo.description, description)) {
+                            mMutableInfo.description = description;
+                            changed = true;
+                        }
+                        final int supportedTypes = computeSupportedTypes(descriptor);
+                        if (mMutableInfo.supportedTypes != supportedTypes) {
+                            mMutableInfo.supportedTypes = supportedTypes;
+                            changed = true;
+                        }
+                        final boolean enabled = computeEnabled(descriptor);
+                        if (mMutableInfo.enabled != enabled) {
+                            mMutableInfo.enabled = enabled;
+                            changed = true;
+                        }
+                        final int statusCode = computeStatusCode(descriptor);
+                        if (mMutableInfo.statusCode != statusCode) {
+                            mMutableInfo.statusCode = statusCode;
+                            changed = true;
+                        }
+                        final int playbackType = computePlaybackType(descriptor);
+                        if (mMutableInfo.playbackType != playbackType) {
+                            mMutableInfo.playbackType = playbackType;
+                            changed = true;
+                        }
+                        final int playbackStream = computePlaybackStream(descriptor);
+                        if (mMutableInfo.playbackStream != playbackStream) {
+                            mMutableInfo.playbackStream = playbackStream;
+                            changed = true;
+                        }
+                        final int volume = computeVolume(descriptor);
+                        if (mMutableInfo.volume != volume) {
+                            mMutableInfo.volume = volume;
+                            changed = true;
+                        }
+                        final int volumeMax = computeVolumeMax(descriptor);
+                        if (mMutableInfo.volumeMax != volumeMax) {
+                            mMutableInfo.volumeMax = volumeMax;
+                            changed = true;
+                        }
+                        final int volumeHandling = computeVolumeHandling(descriptor);
+                        if (mMutableInfo.volumeHandling != volumeHandling) {
+                            mMutableInfo.volumeHandling = volumeHandling;
+                            changed = true;
+                        }
+                        final int presentationDisplayId = computePresentationDisplayId(descriptor);
+                        if (mMutableInfo.presentationDisplayId != presentationDisplayId) {
+                            mMutableInfo.presentationDisplayId = presentationDisplayId;
+                            changed = true;
+                        }
+                    }
+                }
+                if (changed) {
+                    mImmutableInfo = null;
+                }
+                return changed;
+            }
+
+            public void dump(PrintWriter pw, String prefix) {
+                pw.println(prefix + this);
+
+                final String indent = prefix + "  ";
+                pw.println(indent + "mMutableInfo=" + mMutableInfo);
+                pw.println(indent + "mDescriptorId=" + mDescriptorId);
+                pw.println(indent + "mDescriptor=" + mDescriptor);
+            }
+
+            @Override
+            public String toString() {
+                return "Route " + mMutableInfo.name + " (" + mMutableInfo.id + ")";
+            }
+
+            private static String computeName(RemoteDisplayInfo descriptor) {
+                // Note that isValid() already ensures the name is non-empty.
+                return descriptor.name;
+            }
+
+            private static String computeDescription(RemoteDisplayInfo descriptor) {
+                final String description = descriptor.description;
+                return TextUtils.isEmpty(description) ? null : description;
+            }
+
+            private static int computeSupportedTypes(RemoteDisplayInfo descriptor) {
+                return MediaRouter.ROUTE_TYPE_LIVE_AUDIO
+                        | MediaRouter.ROUTE_TYPE_LIVE_VIDEO
+                        | MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
+            }
+
+            private static boolean computeEnabled(RemoteDisplayInfo descriptor) {
+                switch (descriptor.status) {
+                    case RemoteDisplayInfo.STATUS_CONNECTED:
+                    case RemoteDisplayInfo.STATUS_CONNECTING:
+                    case RemoteDisplayInfo.STATUS_AVAILABLE:
+                        return true;
+                    default:
+                        return false;
+                }
+            }
+
+            private static int computeStatusCode(RemoteDisplayInfo descriptor) {
+                switch (descriptor.status) {
+                    case RemoteDisplayInfo.STATUS_NOT_AVAILABLE:
+                        return MediaRouter.RouteInfo.STATUS_NOT_AVAILABLE;
+                    case RemoteDisplayInfo.STATUS_AVAILABLE:
+                        return MediaRouter.RouteInfo.STATUS_AVAILABLE;
+                    case RemoteDisplayInfo.STATUS_IN_USE:
+                        return MediaRouter.RouteInfo.STATUS_IN_USE;
+                    case RemoteDisplayInfo.STATUS_CONNECTING:
+                        return MediaRouter.RouteInfo.STATUS_CONNECTING;
+                    case RemoteDisplayInfo.STATUS_CONNECTED:
+                        return MediaRouter.RouteInfo.STATUS_CONNECTED;
+                    default:
+                        return MediaRouter.RouteInfo.STATUS_NONE;
+                }
+            }
+
+            private static int computePlaybackType(RemoteDisplayInfo descriptor) {
+                return MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE;
+            }
+
+            private static int computePlaybackStream(RemoteDisplayInfo descriptor) {
+                return AudioSystem.STREAM_MUSIC;
+            }
+
+            private static int computeVolume(RemoteDisplayInfo descriptor) {
+                final int volume = descriptor.volume;
+                final int volumeMax = descriptor.volumeMax;
+                if (volume < 0) {
+                    return 0;
+                } else if (volume > volumeMax) {
+                    return volumeMax;
+                }
+                return volume;
+            }
+
+            private static int computeVolumeMax(RemoteDisplayInfo descriptor) {
+                final int volumeMax = descriptor.volumeMax;
+                return volumeMax > 0 ? volumeMax : 0;
+            }
+
+            private static int computeVolumeHandling(RemoteDisplayInfo descriptor) {
+                final int volumeHandling = descriptor.volumeHandling;
+                switch (volumeHandling) {
+                    case RemoteDisplayInfo.PLAYBACK_VOLUME_VARIABLE:
+                        return MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE;
+                    case RemoteDisplayInfo.PLAYBACK_VOLUME_FIXED:
+                    default:
+                        return MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
+                }
+            }
+
+            private static int computePresentationDisplayId(RemoteDisplayInfo descriptor) {
+                // The MediaRouter class validates that the id corresponds to an extant
+                // presentation display.  So all we do here is canonicalize the null case.
+                final int displayId = descriptor.presentationDisplayId;
+                return displayId < 0 ? -1 : displayId;
+            }
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/media/RemoteDisplayProviderProxy.java b/services/core/java/com/android/server/media/RemoteDisplayProviderProxy.java
new file mode 100644
index 0000000..a5fe9f2
--- /dev/null
+++ b/services/core/java/com/android/server/media/RemoteDisplayProviderProxy.java
@@ -0,0 +1,442 @@
+/*
+ * Copyright (C) 2013 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.media;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.media.IRemoteDisplayCallback;
+import android.media.IRemoteDisplayProvider;
+import android.media.RemoteDisplayState;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.IBinder.DeathRecipient;
+import android.os.UserHandle;
+import android.util.Log;
+import android.util.Slog;
+
+import java.io.PrintWriter;
+import java.lang.ref.WeakReference;
+import java.util.Objects;
+
+/**
+ * Maintains a connection to a particular remote display provider service.
+ */
+final class RemoteDisplayProviderProxy implements ServiceConnection {
+    private static final String TAG = "RemoteDisplayProvider";  // max. 23 chars
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+
+    private final Context mContext;
+    private final ComponentName mComponentName;
+    private final int mUserId;
+    private final Handler mHandler;
+
+    private Callback mDisplayStateCallback;
+
+    // Connection state
+    private boolean mRunning;
+    private boolean mBound;
+    private Connection mActiveConnection;
+    private boolean mConnectionReady;
+
+    // Logical state
+    private int mDiscoveryMode;
+    private String mSelectedDisplayId;
+    private RemoteDisplayState mDisplayState;
+    private boolean mScheduledDisplayStateChangedCallback;
+
+    public RemoteDisplayProviderProxy(Context context, ComponentName componentName,
+            int userId) {
+        mContext = context;
+        mComponentName = componentName;
+        mUserId = userId;
+        mHandler = new Handler();
+    }
+
+    public void dump(PrintWriter pw, String prefix) {
+        pw.println(prefix + "Proxy");
+        pw.println(prefix + "  mUserId=" + mUserId);
+        pw.println(prefix + "  mRunning=" + mRunning);
+        pw.println(prefix + "  mBound=" + mBound);
+        pw.println(prefix + "  mActiveConnection=" + mActiveConnection);
+        pw.println(prefix + "  mConnectionReady=" + mConnectionReady);
+        pw.println(prefix + "  mDiscoveryMode=" + mDiscoveryMode);
+        pw.println(prefix + "  mSelectedDisplayId=" + mSelectedDisplayId);
+        pw.println(prefix + "  mDisplayState=" + mDisplayState);
+    }
+
+    public void setCallback(Callback callback) {
+        mDisplayStateCallback = callback;
+    }
+
+    public RemoteDisplayState getDisplayState() {
+        return mDisplayState;
+    }
+
+    public void setDiscoveryMode(int mode) {
+        if (mDiscoveryMode != mode) {
+            mDiscoveryMode = mode;
+            if (mConnectionReady) {
+                mActiveConnection.setDiscoveryMode(mode);
+            }
+            updateBinding();
+        }
+    }
+
+    public void setSelectedDisplay(String id) {
+        if (!Objects.equals(mSelectedDisplayId, id)) {
+            if (mConnectionReady && mSelectedDisplayId != null) {
+                mActiveConnection.disconnect(mSelectedDisplayId);
+            }
+            mSelectedDisplayId = id;
+            if (mConnectionReady && id != null) {
+                mActiveConnection.connect(id);
+            }
+            updateBinding();
+        }
+    }
+
+    public void setDisplayVolume(int volume) {
+        if (mConnectionReady && mSelectedDisplayId != null) {
+            mActiveConnection.setVolume(mSelectedDisplayId, volume);
+        }
+    }
+
+    public void adjustDisplayVolume(int delta) {
+        if (mConnectionReady && mSelectedDisplayId != null) {
+            mActiveConnection.adjustVolume(mSelectedDisplayId, delta);
+        }
+    }
+
+    public boolean hasComponentName(String packageName, String className) {
+        return mComponentName.getPackageName().equals(packageName)
+                && mComponentName.getClassName().equals(className);
+    }
+
+    public String getFlattenedComponentName() {
+        return mComponentName.flattenToShortString();
+    }
+
+    public void start() {
+        if (!mRunning) {
+            if (DEBUG) {
+                Slog.d(TAG, this + ": Starting");
+            }
+
+            mRunning = true;
+            updateBinding();
+        }
+    }
+
+    public void stop() {
+        if (mRunning) {
+            if (DEBUG) {
+                Slog.d(TAG, this + ": Stopping");
+            }
+
+            mRunning = false;
+            updateBinding();
+        }
+    }
+
+    public void rebindIfDisconnected() {
+        if (mActiveConnection == null && shouldBind()) {
+            unbind();
+            bind();
+        }
+    }
+
+    private void updateBinding() {
+        if (shouldBind()) {
+            bind();
+        } else {
+            unbind();
+        }
+    }
+
+    private boolean shouldBind() {
+        if (mRunning) {
+            // Bind whenever there is a discovery request or selected display.
+            if (mDiscoveryMode != RemoteDisplayState.DISCOVERY_MODE_NONE
+                    || mSelectedDisplayId != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private void bind() {
+        if (!mBound) {
+            if (DEBUG) {
+                Slog.d(TAG, this + ": Binding");
+            }
+
+            Intent service = new Intent(RemoteDisplayState.SERVICE_INTERFACE);
+            service.setComponent(mComponentName);
+            try {
+                mBound = mContext.bindServiceAsUser(service, this, Context.BIND_AUTO_CREATE,
+                        new UserHandle(mUserId));
+                if (!mBound && DEBUG) {
+                    Slog.d(TAG, this + ": Bind failed");
+                }
+            } catch (SecurityException ex) {
+                if (DEBUG) {
+                    Slog.d(TAG, this + ": Bind failed", ex);
+                }
+            }
+        }
+    }
+
+    private void unbind() {
+        if (mBound) {
+            if (DEBUG) {
+                Slog.d(TAG, this + ": Unbinding");
+            }
+
+            mBound = false;
+            disconnect();
+            mContext.unbindService(this);
+        }
+    }
+
+    @Override
+    public void onServiceConnected(ComponentName name, IBinder service) {
+        if (DEBUG) {
+            Slog.d(TAG, this + ": Connected");
+        }
+
+        if (mBound) {
+            disconnect();
+
+            IRemoteDisplayProvider provider = IRemoteDisplayProvider.Stub.asInterface(service);
+            if (provider != null) {
+                Connection connection = new Connection(provider);
+                if (connection.register()) {
+                    mActiveConnection = connection;
+                } else {
+                    if (DEBUG) {
+                        Slog.d(TAG, this + ": Registration failed");
+                    }
+                }
+            } else {
+                Slog.e(TAG, this + ": Service returned invalid remote display provider binder");
+            }
+        }
+    }
+
+    @Override
+    public void onServiceDisconnected(ComponentName name) {
+        if (DEBUG) {
+            Slog.d(TAG, this + ": Service disconnected");
+        }
+        disconnect();
+    }
+
+    private void onConnectionReady(Connection connection) {
+        if (mActiveConnection == connection) {
+            mConnectionReady = true;
+
+            if (mDiscoveryMode != RemoteDisplayState.DISCOVERY_MODE_NONE) {
+                mActiveConnection.setDiscoveryMode(mDiscoveryMode);
+            }
+            if (mSelectedDisplayId != null) {
+                mActiveConnection.connect(mSelectedDisplayId);
+            }
+        }
+    }
+
+    private void onConnectionDied(Connection connection) {
+        if (mActiveConnection == connection) {
+            if (DEBUG) {
+                Slog.d(TAG, this + ": Service connection died");
+            }
+            disconnect();
+        }
+    }
+
+    private void onDisplayStateChanged(Connection connection, RemoteDisplayState state) {
+        if (mActiveConnection == connection) {
+            if (DEBUG) {
+                Slog.d(TAG, this + ": State changed, state=" + state);
+            }
+            setDisplayState(state);
+        }
+    }
+
+    private void disconnect() {
+        if (mActiveConnection != null) {
+            if (mSelectedDisplayId != null) {
+                mActiveConnection.disconnect(mSelectedDisplayId);
+            }
+            mConnectionReady = false;
+            mActiveConnection.dispose();
+            mActiveConnection = null;
+            setDisplayState(null);
+        }
+    }
+
+    private void setDisplayState(RemoteDisplayState state) {
+        if (!Objects.equals(mDisplayState, state)) {
+            mDisplayState = state;
+            if (!mScheduledDisplayStateChangedCallback) {
+                mScheduledDisplayStateChangedCallback = true;
+                mHandler.post(mDisplayStateChanged);
+            }
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "Service connection " + mComponentName.flattenToShortString();
+    }
+
+    private final Runnable mDisplayStateChanged = new Runnable() {
+        @Override
+        public void run() {
+            mScheduledDisplayStateChangedCallback = false;
+            if (mDisplayStateCallback != null) {
+                mDisplayStateCallback.onDisplayStateChanged(
+                        RemoteDisplayProviderProxy.this, mDisplayState);
+            }
+        }
+    };
+
+    public interface Callback {
+        void onDisplayStateChanged(RemoteDisplayProviderProxy provider, RemoteDisplayState state);
+    }
+
+    private final class Connection implements DeathRecipient {
+        private final IRemoteDisplayProvider mProvider;
+        private final ProviderCallback mCallback;
+
+        public Connection(IRemoteDisplayProvider provider) {
+            mProvider = provider;
+            mCallback = new ProviderCallback(this);
+        }
+
+        public boolean register() {
+            try {
+                mProvider.asBinder().linkToDeath(this, 0);
+                mProvider.setCallback(mCallback);
+                mHandler.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        onConnectionReady(Connection.this);
+                    }
+                });
+                return true;
+            } catch (RemoteException ex) {
+                binderDied();
+            }
+            return false;
+        }
+
+        public void dispose() {
+            mProvider.asBinder().unlinkToDeath(this, 0);
+            mCallback.dispose();
+        }
+
+        public void setDiscoveryMode(int mode) {
+            try {
+                mProvider.setDiscoveryMode(mode);
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Failed to deliver request to set discovery mode.", ex);
+            }
+        }
+
+        public void connect(String id) {
+            try {
+                mProvider.connect(id);
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Failed to deliver request to connect to display.", ex);
+            }
+        }
+
+        public void disconnect(String id) {
+            try {
+                mProvider.disconnect(id);
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Failed to deliver request to disconnect from display.", ex);
+            }
+        }
+
+        public void setVolume(String id, int volume) {
+            try {
+                mProvider.setVolume(id, volume);
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Failed to deliver request to set display volume.", ex);
+            }
+        }
+
+        public void adjustVolume(String id, int volume) {
+            try {
+                mProvider.adjustVolume(id, volume);
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Failed to deliver request to adjust display volume.", ex);
+            }
+        }
+
+        @Override
+        public void binderDied() {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    onConnectionDied(Connection.this);
+                }
+            });
+        }
+
+        void postStateChanged(final RemoteDisplayState state) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    onDisplayStateChanged(Connection.this, state);
+                }
+            });
+        }
+    }
+
+    /**
+     * Receives callbacks from the service.
+     * <p>
+     * This inner class is static and only retains a weak reference to the connection
+     * to prevent the client from being leaked in case the service is holding an
+     * active reference to the client's callback.
+     * </p>
+     */
+    private static final class ProviderCallback extends IRemoteDisplayCallback.Stub {
+        private final WeakReference<Connection> mConnectionRef;
+
+        public ProviderCallback(Connection connection) {
+            mConnectionRef = new WeakReference<Connection>(connection);
+        }
+
+        public void dispose() {
+            mConnectionRef.clear();
+        }
+
+        @Override
+        public void onStateChanged(RemoteDisplayState state) throws RemoteException {
+            Connection connection = mConnectionRef.get();
+            if (connection != null) {
+                connection.postStateChanged(state);
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/media/RemoteDisplayProviderWatcher.java b/services/core/java/com/android/server/media/RemoteDisplayProviderWatcher.java
similarity index 100%
rename from services/java/com/android/server/media/RemoteDisplayProviderWatcher.java
rename to services/core/java/com/android/server/media/RemoteDisplayProviderWatcher.java
diff --git a/services/java/com/android/server/net/LockdownVpnTracker.java b/services/core/java/com/android/server/net/LockdownVpnTracker.java
similarity index 100%
rename from services/java/com/android/server/net/LockdownVpnTracker.java
rename to services/core/java/com/android/server/net/LockdownVpnTracker.java
diff --git a/services/java/com/android/server/net/NetworkIdentitySet.java b/services/core/java/com/android/server/net/NetworkIdentitySet.java
similarity index 100%
rename from services/java/com/android/server/net/NetworkIdentitySet.java
rename to services/core/java/com/android/server/net/NetworkIdentitySet.java
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
new file mode 100644
index 0000000..eb7cc4c
--- /dev/null
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -0,0 +1,2089 @@
+/*
+ * 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.server.net;
+
+import static android.Manifest.permission.ACCESS_NETWORK_STATE;
+import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
+import static android.Manifest.permission.DUMP;
+import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
+import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
+import static android.Manifest.permission.READ_PHONE_STATE;
+import static android.content.Intent.ACTION_PACKAGE_ADDED;
+import static android.content.Intent.ACTION_UID_REMOVED;
+import static android.content.Intent.ACTION_USER_ADDED;
+import static android.content.Intent.ACTION_USER_REMOVED;
+import static android.content.Intent.EXTRA_UID;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
+import static android.net.ConnectivityManager.TYPE_ETHERNET;
+import static android.net.ConnectivityManager.TYPE_MOBILE;
+import static android.net.ConnectivityManager.TYPE_WIFI;
+import static android.net.ConnectivityManager.TYPE_WIMAX;
+import static android.net.ConnectivityManager.isNetworkTypeMobile;
+import static android.net.NetworkPolicy.CYCLE_NONE;
+import static android.net.NetworkPolicy.LIMIT_DISABLED;
+import static android.net.NetworkPolicy.SNOOZE_NEVER;
+import static android.net.NetworkPolicy.WARNING_DISABLED;
+import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE;
+import static android.net.NetworkPolicyManager.POLICY_NONE;
+import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
+import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
+import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
+import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
+import static android.net.NetworkPolicyManager.dumpPolicy;
+import static android.net.NetworkPolicyManager.dumpRules;
+import static android.net.NetworkTemplate.MATCH_ETHERNET;
+import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
+import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
+import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
+import static android.net.NetworkTemplate.MATCH_WIFI;
+import static android.net.NetworkTemplate.buildTemplateMobileAll;
+import static android.net.TrafficStats.MB_IN_BYTES;
+import static android.net.wifi.WifiManager.CHANGE_REASON_ADDED;
+import static android.net.wifi.WifiManager.CHANGE_REASON_REMOVED;
+import static android.net.wifi.WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION;
+import static android.net.wifi.WifiManager.EXTRA_CHANGE_REASON;
+import static android.net.wifi.WifiManager.EXTRA_NETWORK_INFO;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_CONFIGURATION;
+import static android.net.wifi.WifiManager.EXTRA_WIFI_INFO;
+import static android.telephony.TelephonyManager.SIM_STATE_READY;
+import static android.text.format.DateUtils.DAY_IN_MILLIS;
+import static com.android.internal.util.ArrayUtils.appendInt;
+import static com.android.internal.util.Preconditions.checkNotNull;
+import static com.android.internal.util.XmlUtils.readBooleanAttribute;
+import static com.android.internal.util.XmlUtils.readIntAttribute;
+import static com.android.internal.util.XmlUtils.readLongAttribute;
+import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
+import static com.android.internal.util.XmlUtils.writeIntAttribute;
+import static com.android.internal.util.XmlUtils.writeLongAttribute;
+import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT;
+import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_UPDATED;
+import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
+import static org.xmlpull.v1.XmlPullParser.START_TAG;
+
+import android.app.IActivityManager;
+import android.app.INotificationManager;
+import android.app.IProcessObserver;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.UserInfo;
+import android.content.res.Resources;
+import android.net.ConnectivityManager;
+import android.net.IConnectivityManager;
+import android.net.INetworkManagementEventObserver;
+import android.net.INetworkPolicyListener;
+import android.net.INetworkPolicyManager;
+import android.net.INetworkStatsService;
+import android.net.NetworkIdentity;
+import android.net.NetworkInfo;
+import android.net.NetworkPolicy;
+import android.net.NetworkQuotaInfo;
+import android.net.NetworkState;
+import android.net.NetworkTemplate;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.INetworkManagementService;
+import android.os.IPowerManager;
+import android.os.Message;
+import android.os.MessageQueue.IdleHandler;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+import android.text.format.Formatter;
+import android.text.format.Time;
+import android.util.AtomicFile;
+import android.util.Log;
+import android.util.NtpTrustedTime;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.SparseBooleanArray;
+import android.util.SparseIntArray;
+import android.util.TrustedTime;
+import android.util.Xml;
+
+import com.android.internal.R;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.IndentingPrintWriter;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Maps;
+import com.google.android.collect.Sets;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import libcore.io.IoUtils;
+
+/**
+ * Service that maintains low-level network policy rules, using
+ * {@link NetworkStatsService} statistics to drive those rules.
+ * <p>
+ * Derives active rules by combining a given policy with other system status,
+ * and delivers to listeners, such as {@link ConnectivityManager}, for
+ * enforcement.
+ */
+public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
+    private static final String TAG = "NetworkPolicy";
+    private static final boolean LOGD = false;
+    private static final boolean LOGV = false;
+
+    private static final int VERSION_INIT = 1;
+    private static final int VERSION_ADDED_SNOOZE = 2;
+    private static final int VERSION_ADDED_RESTRICT_BACKGROUND = 3;
+    private static final int VERSION_ADDED_METERED = 4;
+    private static final int VERSION_SPLIT_SNOOZE = 5;
+    private static final int VERSION_ADDED_TIMEZONE = 6;
+    private static final int VERSION_ADDED_INFERRED = 7;
+    private static final int VERSION_SWITCH_APP_ID = 8;
+    private static final int VERSION_ADDED_NETWORK_ID = 9;
+    private static final int VERSION_SWITCH_UID = 10;
+    private static final int VERSION_LATEST = VERSION_SWITCH_UID;
+
+    @VisibleForTesting
+    public static final int TYPE_WARNING = 0x1;
+    @VisibleForTesting
+    public static final int TYPE_LIMIT = 0x2;
+    @VisibleForTesting
+    public static final int TYPE_LIMIT_SNOOZED = 0x3;
+
+    private static final String TAG_POLICY_LIST = "policy-list";
+    private static final String TAG_NETWORK_POLICY = "network-policy";
+    private static final String TAG_UID_POLICY = "uid-policy";
+    private static final String TAG_APP_POLICY = "app-policy";
+
+    private static final String ATTR_VERSION = "version";
+    private static final String ATTR_RESTRICT_BACKGROUND = "restrictBackground";
+    private static final String ATTR_NETWORK_TEMPLATE = "networkTemplate";
+    private static final String ATTR_SUBSCRIBER_ID = "subscriberId";
+    private static final String ATTR_NETWORK_ID = "networkId";
+    private static final String ATTR_CYCLE_DAY = "cycleDay";
+    private static final String ATTR_CYCLE_TIMEZONE = "cycleTimezone";
+    private static final String ATTR_WARNING_BYTES = "warningBytes";
+    private static final String ATTR_LIMIT_BYTES = "limitBytes";
+    private static final String ATTR_LAST_SNOOZE = "lastSnooze";
+    private static final String ATTR_LAST_WARNING_SNOOZE = "lastWarningSnooze";
+    private static final String ATTR_LAST_LIMIT_SNOOZE = "lastLimitSnooze";
+    private static final String ATTR_METERED = "metered";
+    private static final String ATTR_INFERRED = "inferred";
+    private static final String ATTR_UID = "uid";
+    private static final String ATTR_APP_ID = "appId";
+    private static final String ATTR_POLICY = "policy";
+
+    private static final String TAG_ALLOW_BACKGROUND = TAG + ":allowBackground";
+
+    private static final String ACTION_ALLOW_BACKGROUND =
+            "com.android.server.net.action.ALLOW_BACKGROUND";
+    private static final String ACTION_SNOOZE_WARNING =
+            "com.android.server.net.action.SNOOZE_WARNING";
+
+    private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
+
+    private static final int MSG_RULES_CHANGED = 1;
+    private static final int MSG_METERED_IFACES_CHANGED = 2;
+    private static final int MSG_FOREGROUND_ACTIVITIES_CHANGED = 3;
+    private static final int MSG_PROCESS_DIED = 4;
+    private static final int MSG_LIMIT_REACHED = 5;
+    private static final int MSG_RESTRICT_BACKGROUND_CHANGED = 6;
+    private static final int MSG_ADVISE_PERSIST_THRESHOLD = 7;
+    private static final int MSG_SCREEN_ON_CHANGED = 8;
+
+    private final Context mContext;
+    private final IActivityManager mActivityManager;
+    private final IPowerManager mPowerManager;
+    private final INetworkStatsService mNetworkStats;
+    private final INetworkManagementService mNetworkManager;
+    private final TrustedTime mTime;
+
+    private IConnectivityManager mConnManager;
+    private INotificationManager mNotifManager;
+
+    private final Object mRulesLock = new Object();
+
+    private volatile boolean mScreenOn;
+    private volatile boolean mRestrictBackground;
+
+    private final boolean mSuppressDefaultPolicy;
+
+    /** Defined network policies. */
+    private HashMap<NetworkTemplate, NetworkPolicy> mNetworkPolicy = Maps.newHashMap();
+    /** Currently active network rules for ifaces. */
+    private HashMap<NetworkPolicy, String[]> mNetworkRules = Maps.newHashMap();
+
+    /** Defined UID policies. */
+    private SparseIntArray mUidPolicy = new SparseIntArray();
+    /** Currently derived rules for each UID. */
+    private SparseIntArray mUidRules = new SparseIntArray();
+
+    /** Set of ifaces that are metered. */
+    private HashSet<String> mMeteredIfaces = Sets.newHashSet();
+    /** Set of over-limit templates that have been notified. */
+    private HashSet<NetworkTemplate> mOverLimitNotified = Sets.newHashSet();
+
+    /** Set of currently active {@link Notification} tags. */
+    private HashSet<String> mActiveNotifs = Sets.newHashSet();
+
+    /** Foreground at both UID and PID granularity. */
+    private SparseBooleanArray mUidForeground = new SparseBooleanArray();
+    private SparseArray<SparseBooleanArray> mUidPidForeground = new SparseArray<
+            SparseBooleanArray>();
+
+    private final RemoteCallbackList<INetworkPolicyListener> mListeners = new RemoteCallbackList<
+            INetworkPolicyListener>();
+
+    private final Handler mHandler;
+
+    private final AtomicFile mPolicyFile;
+
+    // TODO: keep whitelist of system-critical services that should never have
+    // rules enforced, such as system, phone, and radio UIDs.
+
+    // TODO: migrate notifications to SystemUI
+
+    public NetworkPolicyManagerService(Context context, IActivityManager activityManager,
+            IPowerManager powerManager, INetworkStatsService networkStats,
+            INetworkManagementService networkManagement) {
+        this(context, activityManager, powerManager, networkStats, networkManagement,
+                NtpTrustedTime.getInstance(context), getSystemDir(), false);
+    }
+
+    private static File getSystemDir() {
+        return new File(Environment.getDataDirectory(), "system");
+    }
+
+    public NetworkPolicyManagerService(Context context, IActivityManager activityManager,
+            IPowerManager powerManager, INetworkStatsService networkStats,
+            INetworkManagementService networkManagement, TrustedTime time, File systemDir,
+            boolean suppressDefaultPolicy) {
+        mContext = checkNotNull(context, "missing context");
+        mActivityManager = checkNotNull(activityManager, "missing activityManager");
+        mPowerManager = checkNotNull(powerManager, "missing powerManager");
+        mNetworkStats = checkNotNull(networkStats, "missing networkStats");
+        mNetworkManager = checkNotNull(networkManagement, "missing networkManagement");
+        mTime = checkNotNull(time, "missing TrustedTime");
+
+        HandlerThread thread = new HandlerThread(TAG);
+        thread.start();
+        mHandler = new Handler(thread.getLooper(), mHandlerCallback);
+
+        mSuppressDefaultPolicy = suppressDefaultPolicy;
+
+        mPolicyFile = new AtomicFile(new File(systemDir, "netpolicy.xml"));
+    }
+
+    public void bindConnectivityManager(IConnectivityManager connManager) {
+        mConnManager = checkNotNull(connManager, "missing IConnectivityManager");
+    }
+
+    public void bindNotificationManager(INotificationManager notifManager) {
+        mNotifManager = checkNotNull(notifManager, "missing INotificationManager");
+    }
+
+    public void systemReady() {
+        if (!isBandwidthControlEnabled()) {
+            Slog.w(TAG, "bandwidth controls disabled, unable to enforce policy");
+            return;
+        }
+
+        synchronized (mRulesLock) {
+            // read policy from disk
+            readPolicyLocked();
+
+            if (mRestrictBackground) {
+                updateRulesForRestrictBackgroundLocked();
+                updateNotificationsLocked();
+            }
+        }
+
+        updateScreenOn();
+
+        try {
+            mActivityManager.registerProcessObserver(mProcessObserver);
+            mNetworkManager.registerObserver(mAlertObserver);
+        } catch (RemoteException e) {
+            // ignored; both services live in system_server
+        }
+
+        // TODO: traverse existing processes to know foreground state, or have
+        // activitymanager dispatch current state when new observer attached.
+
+        final IntentFilter screenFilter = new IntentFilter();
+        screenFilter.addAction(Intent.ACTION_SCREEN_ON);
+        screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
+        mContext.registerReceiver(mScreenReceiver, screenFilter);
+
+        // watch for network interfaces to be claimed
+        final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION_IMMEDIATE);
+        mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
+
+        // listen for package changes to update policy
+        final IntentFilter packageFilter = new IntentFilter();
+        packageFilter.addAction(ACTION_PACKAGE_ADDED);
+        packageFilter.addDataScheme("package");
+        mContext.registerReceiver(mPackageReceiver, packageFilter, null, mHandler);
+
+        // listen for UID changes to update policy
+        mContext.registerReceiver(
+                mUidRemovedReceiver, new IntentFilter(ACTION_UID_REMOVED), null, mHandler);
+
+        // listen for user changes to update policy
+        final IntentFilter userFilter = new IntentFilter();
+        userFilter.addAction(ACTION_USER_ADDED);
+        userFilter.addAction(ACTION_USER_REMOVED);
+        mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);
+
+        // listen for stats update events
+        final IntentFilter statsFilter = new IntentFilter(ACTION_NETWORK_STATS_UPDATED);
+        mContext.registerReceiver(
+                mStatsReceiver, statsFilter, READ_NETWORK_USAGE_HISTORY, mHandler);
+
+        // listen for restrict background changes from notifications
+        final IntentFilter allowFilter = new IntentFilter(ACTION_ALLOW_BACKGROUND);
+        mContext.registerReceiver(mAllowReceiver, allowFilter, MANAGE_NETWORK_POLICY, mHandler);
+
+        // listen for snooze warning from notifications
+        final IntentFilter snoozeWarningFilter = new IntentFilter(ACTION_SNOOZE_WARNING);
+        mContext.registerReceiver(mSnoozeWarningReceiver, snoozeWarningFilter,
+                MANAGE_NETWORK_POLICY, mHandler);
+
+        // listen for configured wifi networks to be removed
+        final IntentFilter wifiConfigFilter = new IntentFilter(CONFIGURED_NETWORKS_CHANGED_ACTION);
+        mContext.registerReceiver(
+                mWifiConfigReceiver, wifiConfigFilter, CONNECTIVITY_INTERNAL, mHandler);
+
+        // listen for wifi state changes to catch metered hint
+        final IntentFilter wifiStateFilter = new IntentFilter(
+                WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        mContext.registerReceiver(
+                mWifiStateReceiver, wifiStateFilter, CONNECTIVITY_INTERNAL, mHandler);
+
+    }
+
+    private IProcessObserver mProcessObserver = new IProcessObserver.Stub() {
+        @Override
+        public void onForegroundActivitiesChanged(int pid, int uid, boolean foregroundActivities) {
+            mHandler.obtainMessage(MSG_FOREGROUND_ACTIVITIES_CHANGED,
+                    pid, uid, foregroundActivities).sendToTarget();
+        }
+
+        @Override
+        public void onImportanceChanged(int pid, int uid, int importance) {
+        }
+
+        @Override
+        public void onProcessDied(int pid, int uid) {
+            mHandler.obtainMessage(MSG_PROCESS_DIED, pid, uid).sendToTarget();
+        }
+    };
+
+    private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // screen-related broadcasts are protected by system, no need
+            // for permissions check.
+            mHandler.obtainMessage(MSG_SCREEN_ON_CHANGED).sendToTarget();
+        }
+    };
+
+    private BroadcastReceiver mPackageReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and PACKAGE_ADDED is protected
+
+            final String action = intent.getAction();
+            final int uid = intent.getIntExtra(EXTRA_UID, -1);
+            if (uid == -1) return;
+
+            if (ACTION_PACKAGE_ADDED.equals(action)) {
+                // update rules for UID, since it might be subject to
+                // global background data policy
+                if (LOGV) Slog.v(TAG, "ACTION_PACKAGE_ADDED for uid=" + uid);
+                synchronized (mRulesLock) {
+                    updateRulesForUidLocked(uid);
+                }
+            }
+        }
+    };
+
+    private BroadcastReceiver mUidRemovedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and UID_REMOVED is protected
+
+            final int uid = intent.getIntExtra(EXTRA_UID, -1);
+            if (uid == -1) return;
+
+            // remove any policy and update rules to clean up
+            if (LOGV) Slog.v(TAG, "ACTION_UID_REMOVED for uid=" + uid);
+            synchronized (mRulesLock) {
+                mUidPolicy.delete(uid);
+                updateRulesForUidLocked(uid);
+                writePolicyLocked();
+            }
+        }
+    };
+
+    private BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and USER_ADDED and USER_REMOVED
+            // broadcasts are protected
+
+            final String action = intent.getAction();
+            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+            if (userId == -1) return;
+
+            // Remove any policies for given user; both cleaning up after a
+            // USER_REMOVED, and one last sanity check during USER_ADDED
+            removePoliciesForUserLocked(userId);
+
+            // Update global restrict for new user
+            synchronized (mRulesLock) {
+                updateRulesForRestrictBackgroundLocked();
+            }
+        }
+    };
+
+    /**
+     * Receiver that watches for {@link INetworkStatsService} updates, which we
+     * use to check against {@link NetworkPolicy#warningBytes}.
+     */
+    private BroadcastReceiver mStatsReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified
+            // READ_NETWORK_USAGE_HISTORY permission above.
+
+            maybeRefreshTrustedTime();
+            synchronized (mRulesLock) {
+                updateNetworkEnabledLocked();
+                updateNotificationsLocked();
+            }
+        }
+    };
+
+    /**
+     * Receiver that watches for {@link Notification} control of
+     * {@link #mRestrictBackground}.
+     */
+    private BroadcastReceiver mAllowReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified MANAGE_NETWORK_POLICY
+            // permission above.
+
+            setRestrictBackground(false);
+        }
+    };
+
+    /**
+     * Receiver that watches for {@link Notification} control of
+     * {@link NetworkPolicy#lastWarningSnooze}.
+     */
+    private BroadcastReceiver mSnoozeWarningReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified MANAGE_NETWORK_POLICY
+            // permission above.
+
+            final NetworkTemplate template = intent.getParcelableExtra(EXTRA_NETWORK_TEMPLATE);
+            performSnooze(template, TYPE_WARNING);
+        }
+    };
+
+    /**
+     * Receiver that watches for {@link WifiConfiguration} to be changed.
+     */
+    private BroadcastReceiver mWifiConfigReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified CONNECTIVITY_INTERNAL
+            // permission above.
+
+            final int reason = intent.getIntExtra(EXTRA_CHANGE_REASON, CHANGE_REASON_ADDED);
+            if (reason == CHANGE_REASON_REMOVED) {
+                final WifiConfiguration config = intent.getParcelableExtra(
+                        EXTRA_WIFI_CONFIGURATION);
+                if (config.SSID != null) {
+                    final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(config.SSID);
+                    synchronized (mRulesLock) {
+                        if (mNetworkPolicy.containsKey(template)) {
+                            mNetworkPolicy.remove(template);
+                            writePolicyLocked();
+                        }
+                    }
+                }
+            }
+        }
+    };
+
+    /**
+     * Receiver that watches {@link WifiInfo} state changes to infer metered
+     * state. Ignores hints when policy is user-defined.
+     */
+    private BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified CONNECTIVITY_INTERNAL
+            // permission above.
+
+            // ignore when not connected
+            final NetworkInfo netInfo = intent.getParcelableExtra(EXTRA_NETWORK_INFO);
+            if (!netInfo.isConnected()) return;
+
+            final WifiInfo info = intent.getParcelableExtra(EXTRA_WIFI_INFO);
+            final boolean meteredHint = info.getMeteredHint();
+
+            final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(info.getSSID());
+            synchronized (mRulesLock) {
+                NetworkPolicy policy = mNetworkPolicy.get(template);
+                if (policy == null && meteredHint) {
+                    // policy doesn't exist, and AP is hinting that it's
+                    // metered: create an inferred policy.
+                    policy = new NetworkPolicy(template, CYCLE_NONE, Time.TIMEZONE_UTC,
+                            WARNING_DISABLED, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER,
+                            meteredHint, true);
+                    addNetworkPolicyLocked(policy);
+
+                } else if (policy != null && policy.inferred) {
+                    // policy exists, and was inferred: update its current
+                    // metered state.
+                    policy.metered = meteredHint;
+
+                    // since this is inferred for each wifi session, just update
+                    // rules without persisting.
+                    updateNetworkRulesLocked();
+                }
+            }
+        }
+    };
+
+    /**
+     * Observer that watches for {@link INetworkManagementService} alerts.
+     */
+    private INetworkManagementEventObserver mAlertObserver = new BaseNetworkObserver() {
+        @Override
+        public void limitReached(String limitName, String iface) {
+            // only someone like NMS should be calling us
+            mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+            if (!LIMIT_GLOBAL_ALERT.equals(limitName)) {
+                mHandler.obtainMessage(MSG_LIMIT_REACHED, iface).sendToTarget();
+            }
+        }
+    };
+
+    /**
+     * Check {@link NetworkPolicy} against current {@link INetworkStatsService}
+     * to show visible notifications as needed.
+     */
+    private void updateNotificationsLocked() {
+        if (LOGV) Slog.v(TAG, "updateNotificationsLocked()");
+
+        // keep track of previously active notifications
+        final HashSet<String> beforeNotifs = Sets.newHashSet();
+        beforeNotifs.addAll(mActiveNotifs);
+        mActiveNotifs.clear();
+
+        // TODO: when switching to kernel notifications, compute next future
+        // cycle boundary to recompute notifications.
+
+        // examine stats for each active policy
+        final long currentTime = currentTimeMillis();
+        for (NetworkPolicy policy : mNetworkPolicy.values()) {
+            // ignore policies that aren't relevant to user
+            if (!isTemplateRelevant(policy.template)) continue;
+            if (!policy.hasCycle()) continue;
+
+            final long start = computeLastCycleBoundary(currentTime, policy);
+            final long end = currentTime;
+            final long totalBytes = getTotalBytes(policy.template, start, end);
+
+            if (policy.isOverLimit(totalBytes)) {
+                if (policy.lastLimitSnooze >= start) {
+                    enqueueNotification(policy, TYPE_LIMIT_SNOOZED, totalBytes);
+                } else {
+                    enqueueNotification(policy, TYPE_LIMIT, totalBytes);
+                    notifyOverLimitLocked(policy.template);
+                }
+
+            } else {
+                notifyUnderLimitLocked(policy.template);
+
+                if (policy.isOverWarning(totalBytes) && policy.lastWarningSnooze < start) {
+                    enqueueNotification(policy, TYPE_WARNING, totalBytes);
+                }
+            }
+        }
+
+        // ongoing notification when restricting background data
+        if (mRestrictBackground) {
+            enqueueRestrictedNotification(TAG_ALLOW_BACKGROUND);
+        }
+
+        // cancel stale notifications that we didn't renew above
+        for (String tag : beforeNotifs) {
+            if (!mActiveNotifs.contains(tag)) {
+                cancelNotification(tag);
+            }
+        }
+    }
+
+    /**
+     * Test if given {@link NetworkTemplate} is relevant to user based on
+     * current device state, such as when
+     * {@link TelephonyManager#getSubscriberId()} matches. This is regardless of
+     * data connection status.
+     */
+    private boolean isTemplateRelevant(NetworkTemplate template) {
+        final TelephonyManager tele = TelephonyManager.from(mContext);
+
+        switch (template.getMatchRule()) {
+            case MATCH_MOBILE_3G_LOWER:
+            case MATCH_MOBILE_4G:
+            case MATCH_MOBILE_ALL:
+                // mobile templates are relevant when SIM is ready and
+                // subscriberId matches.
+                if (tele.getSimState() == SIM_STATE_READY) {
+                    return Objects.equals(tele.getSubscriberId(), template.getSubscriberId());
+                } else {
+                    return false;
+                }
+        }
+        return true;
+    }
+
+    /**
+     * Notify that given {@link NetworkTemplate} is over
+     * {@link NetworkPolicy#limitBytes}, potentially showing dialog to user.
+     */
+    private void notifyOverLimitLocked(NetworkTemplate template) {
+        if (!mOverLimitNotified.contains(template)) {
+            mContext.startActivity(buildNetworkOverLimitIntent(template));
+            mOverLimitNotified.add(template);
+        }
+    }
+
+    private void notifyUnderLimitLocked(NetworkTemplate template) {
+        mOverLimitNotified.remove(template);
+    }
+
+    /**
+     * Build unique tag that identifies an active {@link NetworkPolicy}
+     * notification of a specific type, like {@link #TYPE_LIMIT}.
+     */
+    private String buildNotificationTag(NetworkPolicy policy, int type) {
+        return TAG + ":" + policy.template.hashCode() + ":" + type;
+    }
+
+    /**
+     * Show notification for combined {@link NetworkPolicy} and specific type,
+     * like {@link #TYPE_LIMIT}. Okay to call multiple times.
+     */
+    private void enqueueNotification(NetworkPolicy policy, int type, long totalBytes) {
+        final String tag = buildNotificationTag(policy, type);
+        final Notification.Builder builder = new Notification.Builder(mContext);
+        builder.setOnlyAlertOnce(true);
+        builder.setWhen(0L);
+
+        final Resources res = mContext.getResources();
+        switch (type) {
+            case TYPE_WARNING: {
+                final CharSequence title = res.getText(R.string.data_usage_warning_title);
+                final CharSequence body = res.getString(R.string.data_usage_warning_body);
+
+                builder.setSmallIcon(R.drawable.stat_notify_error);
+                builder.setTicker(title);
+                builder.setContentTitle(title);
+                builder.setContentText(body);
+
+                final Intent snoozeIntent = buildSnoozeWarningIntent(policy.template);
+                builder.setDeleteIntent(PendingIntent.getBroadcast(
+                        mContext, 0, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+
+                final Intent viewIntent = buildViewDataUsageIntent(policy.template);
+                builder.setContentIntent(PendingIntent.getActivity(
+                        mContext, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+
+                break;
+            }
+            case TYPE_LIMIT: {
+                final CharSequence body = res.getText(R.string.data_usage_limit_body);
+
+                final CharSequence title;
+                switch (policy.template.getMatchRule()) {
+                    case MATCH_MOBILE_3G_LOWER:
+                        title = res.getText(R.string.data_usage_3g_limit_title);
+                        break;
+                    case MATCH_MOBILE_4G:
+                        title = res.getText(R.string.data_usage_4g_limit_title);
+                        break;
+                    case MATCH_MOBILE_ALL:
+                        title = res.getText(R.string.data_usage_mobile_limit_title);
+                        break;
+                    case MATCH_WIFI:
+                        title = res.getText(R.string.data_usage_wifi_limit_title);
+                        break;
+                    default:
+                        title = null;
+                        break;
+                }
+
+                builder.setOngoing(true);
+                builder.setSmallIcon(R.drawable.stat_notify_disabled);
+                builder.setTicker(title);
+                builder.setContentTitle(title);
+                builder.setContentText(body);
+
+                final Intent intent = buildNetworkOverLimitIntent(policy.template);
+                builder.setContentIntent(PendingIntent.getActivity(
+                        mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
+                break;
+            }
+            case TYPE_LIMIT_SNOOZED: {
+                final long overBytes = totalBytes - policy.limitBytes;
+                final CharSequence body = res.getString(R.string.data_usage_limit_snoozed_body,
+                        Formatter.formatFileSize(mContext, overBytes));
+
+                final CharSequence title;
+                switch (policy.template.getMatchRule()) {
+                    case MATCH_MOBILE_3G_LOWER:
+                        title = res.getText(R.string.data_usage_3g_limit_snoozed_title);
+                        break;
+                    case MATCH_MOBILE_4G:
+                        title = res.getText(R.string.data_usage_4g_limit_snoozed_title);
+                        break;
+                    case MATCH_MOBILE_ALL:
+                        title = res.getText(R.string.data_usage_mobile_limit_snoozed_title);
+                        break;
+                    case MATCH_WIFI:
+                        title = res.getText(R.string.data_usage_wifi_limit_snoozed_title);
+                        break;
+                    default:
+                        title = null;
+                        break;
+                }
+
+                builder.setOngoing(true);
+                builder.setSmallIcon(R.drawable.stat_notify_error);
+                builder.setTicker(title);
+                builder.setContentTitle(title);
+                builder.setContentText(body);
+
+                final Intent intent = buildViewDataUsageIntent(policy.template);
+                builder.setContentIntent(PendingIntent.getActivity(
+                        mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
+                break;
+            }
+        }
+
+        // TODO: move to NotificationManager once we can mock it
+        // XXX what to do about multi-user?
+        try {
+            final String packageName = mContext.getPackageName();
+            final int[] idReceived = new int[1];
+            mNotifManager.enqueueNotificationWithTag(
+                    packageName, packageName, tag, 0x0, builder.getNotification(), idReceived,
+                    UserHandle.USER_OWNER);
+            mActiveNotifs.add(tag);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    /**
+     * Show ongoing notification to reflect that {@link #mRestrictBackground}
+     * has been enabled.
+     */
+    private void enqueueRestrictedNotification(String tag) {
+        final Resources res = mContext.getResources();
+        final Notification.Builder builder = new Notification.Builder(mContext);
+
+        final CharSequence title = res.getText(R.string.data_usage_restricted_title);
+        final CharSequence body = res.getString(R.string.data_usage_restricted_body);
+
+        builder.setOnlyAlertOnce(true);
+        builder.setOngoing(true);
+        builder.setSmallIcon(R.drawable.stat_notify_error);
+        builder.setTicker(title);
+        builder.setContentTitle(title);
+        builder.setContentText(body);
+
+        final Intent intent = buildAllowBackgroundDataIntent();
+        builder.setContentIntent(
+                PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
+
+        // TODO: move to NotificationManager once we can mock it
+        // XXX what to do about multi-user?
+        try {
+            final String packageName = mContext.getPackageName();
+            final int[] idReceived = new int[1];
+            mNotifManager.enqueueNotificationWithTag(packageName, packageName, tag,
+                    0x0, builder.getNotification(), idReceived, UserHandle.USER_OWNER);
+            mActiveNotifs.add(tag);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    private void cancelNotification(String tag) {
+        // TODO: move to NotificationManager once we can mock it
+        // XXX what to do about multi-user?
+        try {
+            final String packageName = mContext.getPackageName();
+            mNotifManager.cancelNotificationWithTag(
+                    packageName, tag, 0x0, UserHandle.USER_OWNER);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    /**
+     * Receiver that watches for {@link IConnectivityManager} to claim network
+     * interfaces. Used to apply {@link NetworkPolicy} to matching networks.
+     */
+    private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // on background handler thread, and verified CONNECTIVITY_INTERNAL
+            // permission above.
+
+            maybeRefreshTrustedTime();
+            synchronized (mRulesLock) {
+                ensureActiveMobilePolicyLocked();
+                updateNetworkEnabledLocked();
+                updateNetworkRulesLocked();
+                updateNotificationsLocked();
+            }
+        }
+    };
+
+    /**
+     * Proactively control network data connections when they exceed
+     * {@link NetworkPolicy#limitBytes}.
+     */
+    private void updateNetworkEnabledLocked() {
+        if (LOGV) Slog.v(TAG, "updateNetworkEnabledLocked()");
+
+        // TODO: reset any policy-disabled networks when any policy is removed
+        // completely, which is currently rare case.
+
+        final long currentTime = currentTimeMillis();
+        for (NetworkPolicy policy : mNetworkPolicy.values()) {
+            // shortcut when policy has no limit
+            if (policy.limitBytes == LIMIT_DISABLED || !policy.hasCycle()) {
+                setNetworkTemplateEnabled(policy.template, true);
+                continue;
+            }
+
+            final long start = computeLastCycleBoundary(currentTime, policy);
+            final long end = currentTime;
+            final long totalBytes = getTotalBytes(policy.template, start, end);
+
+            // disable data connection when over limit and not snoozed
+            final boolean overLimitWithoutSnooze = policy.isOverLimit(totalBytes)
+                    && policy.lastLimitSnooze < start;
+            final boolean networkEnabled = !overLimitWithoutSnooze;
+
+            setNetworkTemplateEnabled(policy.template, networkEnabled);
+        }
+    }
+
+    /**
+     * Control {@link IConnectivityManager#setPolicyDataEnable(int, boolean)}
+     * for the given {@link NetworkTemplate}.
+     */
+    private void setNetworkTemplateEnabled(NetworkTemplate template, boolean enabled) {
+        final TelephonyManager tele = TelephonyManager.from(mContext);
+
+        switch (template.getMatchRule()) {
+            case MATCH_MOBILE_3G_LOWER:
+            case MATCH_MOBILE_4G:
+            case MATCH_MOBILE_ALL:
+                // TODO: offer more granular control over radio states once
+                // 4965893 is available.
+                if (tele.getSimState() == SIM_STATE_READY
+                        && Objects.equals(tele.getSubscriberId(), template.getSubscriberId())) {
+                    setPolicyDataEnable(TYPE_MOBILE, enabled);
+                    setPolicyDataEnable(TYPE_WIMAX, enabled);
+                }
+                break;
+            case MATCH_WIFI:
+                setPolicyDataEnable(TYPE_WIFI, enabled);
+                break;
+            case MATCH_ETHERNET:
+                setPolicyDataEnable(TYPE_ETHERNET, enabled);
+                break;
+            default:
+                throw new IllegalArgumentException("unexpected template");
+        }
+    }
+
+    /**
+     * Examine all connected {@link NetworkState}, looking for
+     * {@link NetworkPolicy} that need to be enforced. When matches found, set
+     * remaining quota based on usage cycle and historical stats.
+     */
+    private void updateNetworkRulesLocked() {
+        if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
+
+        final NetworkState[] states;
+        try {
+            states = mConnManager.getAllNetworkState();
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+            return;
+        }
+
+        // first, derive identity for all connected networks, which can be used
+        // to match against templates.
+        final HashMap<NetworkIdentity, String> networks = Maps.newHashMap();
+        for (NetworkState state : states) {
+            // stash identity and iface away for later use
+            if (state.networkInfo.isConnected()) {
+                final String iface = state.linkProperties.getInterfaceName();
+                final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
+                networks.put(ident, iface);
+            }
+        }
+
+        // build list of rules and ifaces to enforce them against
+        mNetworkRules.clear();
+        final ArrayList<String> ifaceList = Lists.newArrayList();
+        for (NetworkPolicy policy : mNetworkPolicy.values()) {
+
+            // collect all active ifaces that match this template
+            ifaceList.clear();
+            for (Map.Entry<NetworkIdentity, String> entry : networks.entrySet()) {
+                final NetworkIdentity ident = entry.getKey();
+                if (policy.template.matches(ident)) {
+                    final String iface = entry.getValue();
+                    ifaceList.add(iface);
+                }
+            }
+
+            if (ifaceList.size() > 0) {
+                final String[] ifaces = ifaceList.toArray(new String[ifaceList.size()]);
+                mNetworkRules.put(policy, ifaces);
+            }
+        }
+
+        long lowestRule = Long.MAX_VALUE;
+        final HashSet<String> newMeteredIfaces = Sets.newHashSet();
+
+        // apply each policy that we found ifaces for; compute remaining data
+        // based on current cycle and historical stats, and push to kernel.
+        final long currentTime = currentTimeMillis();
+        for (NetworkPolicy policy : mNetworkRules.keySet()) {
+            final String[] ifaces = mNetworkRules.get(policy);
+
+            final long start;
+            final long totalBytes;
+            if (policy.hasCycle()) {
+                start = computeLastCycleBoundary(currentTime, policy);
+                totalBytes = getTotalBytes(policy.template, start, currentTime);
+            } else {
+                start = Long.MAX_VALUE;
+                totalBytes = 0;
+            }
+
+            if (LOGD) {
+                Slog.d(TAG, "applying policy " + policy.toString() + " to ifaces "
+                        + Arrays.toString(ifaces));
+            }
+
+            final boolean hasWarning = policy.warningBytes != LIMIT_DISABLED;
+            final boolean hasLimit = policy.limitBytes != LIMIT_DISABLED;
+            if (hasLimit || policy.metered) {
+                final long quotaBytes;
+                if (!hasLimit) {
+                    // metered network, but no policy limit; we still need to
+                    // restrict apps, so push really high quota.
+                    quotaBytes = Long.MAX_VALUE;
+                } else if (policy.lastLimitSnooze >= start) {
+                    // snoozing past quota, but we still need to restrict apps,
+                    // so push really high quota.
+                    quotaBytes = Long.MAX_VALUE;
+                } else {
+                    // remaining "quota" bytes are based on total usage in
+                    // current cycle. kernel doesn't like 0-byte rules, so we
+                    // set 1-byte quota and disable the radio later.
+                    quotaBytes = Math.max(1, policy.limitBytes - totalBytes);
+                }
+
+                if (ifaces.length > 1) {
+                    // TODO: switch to shared quota once NMS supports
+                    Slog.w(TAG, "shared quota unsupported; generating rule for each iface");
+                }
+
+                for (String iface : ifaces) {
+                    removeInterfaceQuota(iface);
+                    setInterfaceQuota(iface, quotaBytes);
+                    newMeteredIfaces.add(iface);
+                }
+            }
+
+            // keep track of lowest warning or limit of active policies
+            if (hasWarning && policy.warningBytes < lowestRule) {
+                lowestRule = policy.warningBytes;
+            }
+            if (hasLimit && policy.limitBytes < lowestRule) {
+                lowestRule = policy.limitBytes;
+            }
+        }
+
+        mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget();
+
+        // remove quota on any trailing interfaces
+        for (String iface : mMeteredIfaces) {
+            if (!newMeteredIfaces.contains(iface)) {
+                removeInterfaceQuota(iface);
+            }
+        }
+        mMeteredIfaces = newMeteredIfaces;
+
+        final String[] meteredIfaces = mMeteredIfaces.toArray(new String[mMeteredIfaces.size()]);
+        mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget();
+    }
+
+    /**
+     * Once any {@link #mNetworkPolicy} are loaded from disk, ensure that we
+     * have at least a default mobile policy defined.
+     */
+    private void ensureActiveMobilePolicyLocked() {
+        if (LOGV) Slog.v(TAG, "ensureActiveMobilePolicyLocked()");
+        if (mSuppressDefaultPolicy) return;
+
+        final TelephonyManager tele = TelephonyManager.from(mContext);
+
+        // avoid creating policy when SIM isn't ready
+        if (tele.getSimState() != SIM_STATE_READY) return;
+
+        final String subscriberId = tele.getSubscriberId();
+        final NetworkIdentity probeIdent = new NetworkIdentity(
+                TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, null, false);
+
+        // examine to see if any policy is defined for active mobile
+        boolean mobileDefined = false;
+        for (NetworkPolicy policy : mNetworkPolicy.values()) {
+            if (policy.template.matches(probeIdent)) {
+                mobileDefined = true;
+            }
+        }
+
+        if (!mobileDefined) {
+            Slog.i(TAG, "no policy for active mobile network; generating default policy");
+
+            // build default mobile policy, and assume usage cycle starts today
+            final long warningBytes = mContext.getResources().getInteger(
+                    com.android.internal.R.integer.config_networkPolicyDefaultWarning)
+                    * MB_IN_BYTES;
+
+            final Time time = new Time();
+            time.setToNow();
+
+            final int cycleDay = time.monthDay;
+            final String cycleTimezone = time.timezone;
+
+            final NetworkTemplate template = buildTemplateMobileAll(subscriberId);
+            final NetworkPolicy policy = new NetworkPolicy(template, cycleDay, cycleTimezone,
+                    warningBytes, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER, true, true);
+            addNetworkPolicyLocked(policy);
+        }
+    }
+
+    private void readPolicyLocked() {
+        if (LOGV) Slog.v(TAG, "readPolicyLocked()");
+
+        // clear any existing policy and read from disk
+        mNetworkPolicy.clear();
+        mUidPolicy.clear();
+
+        FileInputStream fis = null;
+        try {
+            fis = mPolicyFile.openRead();
+            final XmlPullParser in = Xml.newPullParser();
+            in.setInput(fis, null);
+
+            int type;
+            int version = VERSION_INIT;
+            while ((type = in.next()) != END_DOCUMENT) {
+                final String tag = in.getName();
+                if (type == START_TAG) {
+                    if (TAG_POLICY_LIST.equals(tag)) {
+                        version = readIntAttribute(in, ATTR_VERSION);
+                        if (version >= VERSION_ADDED_RESTRICT_BACKGROUND) {
+                            mRestrictBackground = readBooleanAttribute(
+                                    in, ATTR_RESTRICT_BACKGROUND);
+                        } else {
+                            mRestrictBackground = false;
+                        }
+
+                    } else if (TAG_NETWORK_POLICY.equals(tag)) {
+                        final int networkTemplate = readIntAttribute(in, ATTR_NETWORK_TEMPLATE);
+                        final String subscriberId = in.getAttributeValue(null, ATTR_SUBSCRIBER_ID);
+                        final String networkId;
+                        if (version >= VERSION_ADDED_NETWORK_ID) {
+                            networkId = in.getAttributeValue(null, ATTR_NETWORK_ID);
+                        } else {
+                            networkId = null;
+                        }
+                        final int cycleDay = readIntAttribute(in, ATTR_CYCLE_DAY);
+                        final String cycleTimezone;
+                        if (version >= VERSION_ADDED_TIMEZONE) {
+                            cycleTimezone = in.getAttributeValue(null, ATTR_CYCLE_TIMEZONE);
+                        } else {
+                            cycleTimezone = Time.TIMEZONE_UTC;
+                        }
+                        final long warningBytes = readLongAttribute(in, ATTR_WARNING_BYTES);
+                        final long limitBytes = readLongAttribute(in, ATTR_LIMIT_BYTES);
+                        final long lastLimitSnooze;
+                        if (version >= VERSION_SPLIT_SNOOZE) {
+                            lastLimitSnooze = readLongAttribute(in, ATTR_LAST_LIMIT_SNOOZE);
+                        } else if (version >= VERSION_ADDED_SNOOZE) {
+                            lastLimitSnooze = readLongAttribute(in, ATTR_LAST_SNOOZE);
+                        } else {
+                            lastLimitSnooze = SNOOZE_NEVER;
+                        }
+                        final boolean metered;
+                        if (version >= VERSION_ADDED_METERED) {
+                            metered = readBooleanAttribute(in, ATTR_METERED);
+                        } else {
+                            switch (networkTemplate) {
+                                case MATCH_MOBILE_3G_LOWER:
+                                case MATCH_MOBILE_4G:
+                                case MATCH_MOBILE_ALL:
+                                    metered = true;
+                                    break;
+                                default:
+                                    metered = false;
+                            }
+                        }
+                        final long lastWarningSnooze;
+                        if (version >= VERSION_SPLIT_SNOOZE) {
+                            lastWarningSnooze = readLongAttribute(in, ATTR_LAST_WARNING_SNOOZE);
+                        } else {
+                            lastWarningSnooze = SNOOZE_NEVER;
+                        }
+                        final boolean inferred;
+                        if (version >= VERSION_ADDED_INFERRED) {
+                            inferred = readBooleanAttribute(in, ATTR_INFERRED);
+                        } else {
+                            inferred = false;
+                        }
+
+                        final NetworkTemplate template = new NetworkTemplate(
+                                networkTemplate, subscriberId, networkId);
+                        mNetworkPolicy.put(template, new NetworkPolicy(template, cycleDay,
+                                cycleTimezone, warningBytes, limitBytes, lastWarningSnooze,
+                                lastLimitSnooze, metered, inferred));
+
+                    } else if (TAG_UID_POLICY.equals(tag)) {
+                        final int uid = readIntAttribute(in, ATTR_UID);
+                        final int policy = readIntAttribute(in, ATTR_POLICY);
+
+                        if (UserHandle.isApp(uid)) {
+                            setUidPolicyUnchecked(uid, policy, false);
+                        } else {
+                            Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
+                        }
+                    } else if (TAG_APP_POLICY.equals(tag)) {
+                        final int appId = readIntAttribute(in, ATTR_APP_ID);
+                        final int policy = readIntAttribute(in, ATTR_POLICY);
+
+                        // TODO: set for other users during upgrade
+                        final int uid = UserHandle.getUid(UserHandle.USER_OWNER, appId);
+                        if (UserHandle.isApp(uid)) {
+                            setUidPolicyUnchecked(uid, policy, false);
+                        } else {
+                            Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
+                        }
+                    }
+                }
+            }
+
+        } catch (FileNotFoundException e) {
+            // missing policy is okay, probably first boot
+            upgradeLegacyBackgroundData();
+        } catch (IOException e) {
+            Log.wtf(TAG, "problem reading network policy", e);
+        } catch (XmlPullParserException e) {
+            Log.wtf(TAG, "problem reading network policy", e);
+        } finally {
+            IoUtils.closeQuietly(fis);
+        }
+    }
+
+    /**
+     * Upgrade legacy background data flags, notifying listeners of one last
+     * change to always-true.
+     */
+    private void upgradeLegacyBackgroundData() {
+        mRestrictBackground = Settings.Secure.getInt(
+                mContext.getContentResolver(), Settings.Secure.BACKGROUND_DATA, 1) != 1;
+
+        // kick off one last broadcast if restricted
+        if (mRestrictBackground) {
+            final Intent broadcast = new Intent(
+                    ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
+            mContext.sendBroadcastAsUser(broadcast, UserHandle.ALL);
+        }
+    }
+
+    private void writePolicyLocked() {
+        if (LOGV) Slog.v(TAG, "writePolicyLocked()");
+
+        FileOutputStream fos = null;
+        try {
+            fos = mPolicyFile.startWrite();
+
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(fos, "utf-8");
+            out.startDocument(null, true);
+
+            out.startTag(null, TAG_POLICY_LIST);
+            writeIntAttribute(out, ATTR_VERSION, VERSION_LATEST);
+            writeBooleanAttribute(out, ATTR_RESTRICT_BACKGROUND, mRestrictBackground);
+
+            // write all known network policies
+            for (NetworkPolicy policy : mNetworkPolicy.values()) {
+                final NetworkTemplate template = policy.template;
+
+                out.startTag(null, TAG_NETWORK_POLICY);
+                writeIntAttribute(out, ATTR_NETWORK_TEMPLATE, template.getMatchRule());
+                final String subscriberId = template.getSubscriberId();
+                if (subscriberId != null) {
+                    out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
+                }
+                final String networkId = template.getNetworkId();
+                if (networkId != null) {
+                    out.attribute(null, ATTR_NETWORK_ID, networkId);
+                }
+                writeIntAttribute(out, ATTR_CYCLE_DAY, policy.cycleDay);
+                out.attribute(null, ATTR_CYCLE_TIMEZONE, policy.cycleTimezone);
+                writeLongAttribute(out, ATTR_WARNING_BYTES, policy.warningBytes);
+                writeLongAttribute(out, ATTR_LIMIT_BYTES, policy.limitBytes);
+                writeLongAttribute(out, ATTR_LAST_WARNING_SNOOZE, policy.lastWarningSnooze);
+                writeLongAttribute(out, ATTR_LAST_LIMIT_SNOOZE, policy.lastLimitSnooze);
+                writeBooleanAttribute(out, ATTR_METERED, policy.metered);
+                writeBooleanAttribute(out, ATTR_INFERRED, policy.inferred);
+                out.endTag(null, TAG_NETWORK_POLICY);
+            }
+
+            // write all known uid policies
+            for (int i = 0; i < mUidPolicy.size(); i++) {
+                final int uid = mUidPolicy.keyAt(i);
+                final int policy = mUidPolicy.valueAt(i);
+
+                // skip writing empty policies
+                if (policy == POLICY_NONE) continue;
+
+                out.startTag(null, TAG_UID_POLICY);
+                writeIntAttribute(out, ATTR_UID, uid);
+                writeIntAttribute(out, ATTR_POLICY, policy);
+                out.endTag(null, TAG_UID_POLICY);
+            }
+
+            out.endTag(null, TAG_POLICY_LIST);
+            out.endDocument();
+
+            mPolicyFile.finishWrite(fos);
+        } catch (IOException e) {
+            if (fos != null) {
+                mPolicyFile.failWrite(fos);
+            }
+        }
+    }
+
+    @Override
+    public void setUidPolicy(int uid, int policy) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        if (!UserHandle.isApp(uid)) {
+            throw new IllegalArgumentException("cannot apply policy to UID " + uid);
+        }
+
+        setUidPolicyUnchecked(uid, policy, true);
+    }
+
+    private void setUidPolicyUnchecked(int uid, int policy, boolean persist) {
+        final int oldPolicy;
+        synchronized (mRulesLock) {
+            oldPolicy = getUidPolicy(uid);
+            mUidPolicy.put(uid, policy);
+
+            // uid policy changed, recompute rules and persist policy.
+            updateRulesForUidLocked(uid);
+            if (persist) {
+                writePolicyLocked();
+            }
+        }
+    }
+
+    @Override
+    public int getUidPolicy(int uid) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        synchronized (mRulesLock) {
+            return mUidPolicy.get(uid, POLICY_NONE);
+        }
+    }
+
+    @Override
+    public int[] getUidsWithPolicy(int policy) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        int[] uids = new int[0];
+        synchronized (mRulesLock) {
+            for (int i = 0; i < mUidPolicy.size(); i++) {
+                final int uid = mUidPolicy.keyAt(i);
+                final int uidPolicy = mUidPolicy.valueAt(i);
+                if (uidPolicy == policy) {
+                    uids = appendInt(uids, uid);
+                }
+            }
+        }
+        return uids;
+    }
+
+    /**
+     * Remove any policies associated with given {@link UserHandle}, persisting
+     * if any changes are made.
+     */
+    private void removePoliciesForUserLocked(int userId) {
+        if (LOGV) Slog.v(TAG, "removePoliciesForUserLocked()");
+
+        int[] uids = new int[0];
+        for (int i = 0; i < mUidPolicy.size(); i++) {
+            final int uid = mUidPolicy.keyAt(i);
+            if (UserHandle.getUserId(uid) == userId) {
+                uids = appendInt(uids, uid);
+            }
+        }
+
+        if (uids.length > 0) {
+            for (int uid : uids) {
+                mUidPolicy.delete(uid);
+                updateRulesForUidLocked(uid);
+            }
+            writePolicyLocked();
+        }
+    }
+
+    @Override
+    public void registerListener(INetworkPolicyListener listener) {
+        // TODO: create permission for observing network policy
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        mListeners.register(listener);
+
+        // TODO: consider dispatching existing rules to new listeners
+    }
+
+    @Override
+    public void unregisterListener(INetworkPolicyListener listener) {
+        // TODO: create permission for observing network policy
+        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
+
+        mListeners.unregister(listener);
+    }
+
+    @Override
+    public void setNetworkPolicies(NetworkPolicy[] policies) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        maybeRefreshTrustedTime();
+        synchronized (mRulesLock) {
+            mNetworkPolicy.clear();
+            for (NetworkPolicy policy : policies) {
+                mNetworkPolicy.put(policy.template, policy);
+            }
+
+            updateNetworkEnabledLocked();
+            updateNetworkRulesLocked();
+            updateNotificationsLocked();
+            writePolicyLocked();
+        }
+    }
+
+    private void addNetworkPolicyLocked(NetworkPolicy policy) {
+        mNetworkPolicy.put(policy.template, policy);
+
+        updateNetworkEnabledLocked();
+        updateNetworkRulesLocked();
+        updateNotificationsLocked();
+        writePolicyLocked();
+    }
+
+    @Override
+    public NetworkPolicy[] getNetworkPolicies() {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+        mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, TAG);
+
+        synchronized (mRulesLock) {
+            return mNetworkPolicy.values().toArray(new NetworkPolicy[mNetworkPolicy.size()]);
+        }
+    }
+
+    @Override
+    public void snoozeLimit(NetworkTemplate template) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        final long token = Binder.clearCallingIdentity();
+        try {
+            performSnooze(template, TYPE_LIMIT);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    private void performSnooze(NetworkTemplate template, int type) {
+        maybeRefreshTrustedTime();
+        final long currentTime = currentTimeMillis();
+        synchronized (mRulesLock) {
+            // find and snooze local policy that matches
+            final NetworkPolicy policy = mNetworkPolicy.get(template);
+            if (policy == null) {
+                throw new IllegalArgumentException("unable to find policy for " + template);
+            }
+
+            switch (type) {
+                case TYPE_WARNING:
+                    policy.lastWarningSnooze = currentTime;
+                    break;
+                case TYPE_LIMIT:
+                    policy.lastLimitSnooze = currentTime;
+                    break;
+                default:
+                    throw new IllegalArgumentException("unexpected type");
+            }
+
+            updateNetworkEnabledLocked();
+            updateNetworkRulesLocked();
+            updateNotificationsLocked();
+            writePolicyLocked();
+        }
+    }
+
+    @Override
+    public void setRestrictBackground(boolean restrictBackground) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        maybeRefreshTrustedTime();
+        synchronized (mRulesLock) {
+            mRestrictBackground = restrictBackground;
+            updateRulesForRestrictBackgroundLocked();
+            updateNotificationsLocked();
+            writePolicyLocked();
+        }
+
+        mHandler.obtainMessage(MSG_RESTRICT_BACKGROUND_CHANGED, restrictBackground ? 1 : 0, 0)
+                .sendToTarget();
+    }
+
+    @Override
+    public boolean getRestrictBackground() {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        synchronized (mRulesLock) {
+            return mRestrictBackground;
+        }
+    }
+
+    private NetworkPolicy findPolicyForNetworkLocked(NetworkIdentity ident) {
+        for (NetworkPolicy policy : mNetworkPolicy.values()) {
+            if (policy.template.matches(ident)) {
+                return policy;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public NetworkQuotaInfo getNetworkQuotaInfo(NetworkState state) {
+        mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
+
+        // only returns usage summary, so we don't require caller to have
+        // READ_NETWORK_USAGE_HISTORY.
+        final long token = Binder.clearCallingIdentity();
+        try {
+            return getNetworkQuotaInfoUnchecked(state);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    private NetworkQuotaInfo getNetworkQuotaInfoUnchecked(NetworkState state) {
+        final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
+
+        final NetworkPolicy policy;
+        synchronized (mRulesLock) {
+            policy = findPolicyForNetworkLocked(ident);
+        }
+
+        if (policy == null || !policy.hasCycle()) {
+            // missing policy means we can't derive useful quota info
+            return null;
+        }
+
+        final long currentTime = currentTimeMillis();
+
+        // find total bytes used under policy
+        final long start = computeLastCycleBoundary(currentTime, policy);
+        final long end = currentTime;
+        final long totalBytes = getTotalBytes(policy.template, start, end);
+
+        // report soft and hard limits under policy
+        final long softLimitBytes = policy.warningBytes != WARNING_DISABLED ? policy.warningBytes
+                : NetworkQuotaInfo.NO_LIMIT;
+        final long hardLimitBytes = policy.limitBytes != LIMIT_DISABLED ? policy.limitBytes
+                : NetworkQuotaInfo.NO_LIMIT;
+
+        return new NetworkQuotaInfo(totalBytes, softLimitBytes, hardLimitBytes);
+    }
+
+    @Override
+    public boolean isNetworkMetered(NetworkState state) {
+        final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
+
+        // roaming networks are always considered metered
+        if (ident.getRoaming()) {
+            return true;
+        }
+
+        final NetworkPolicy policy;
+        synchronized (mRulesLock) {
+            policy = findPolicyForNetworkLocked(ident);
+        }
+
+        if (policy != null) {
+            return policy.metered;
+        } else {
+            final int type = state.networkInfo.getType();
+            if (isNetworkTypeMobile(type) || type == TYPE_WIMAX) {
+                return true;
+            }
+            return false;
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+        mContext.enforceCallingOrSelfPermission(DUMP, TAG);
+
+        final IndentingPrintWriter fout = new IndentingPrintWriter(writer, "  ");
+
+        final HashSet<String> argSet = new HashSet<String>();
+        for (String arg : args) {
+            argSet.add(arg);
+        }
+
+        synchronized (mRulesLock) {
+            if (argSet.contains("--unsnooze")) {
+                for (NetworkPolicy policy : mNetworkPolicy.values()) {
+                    policy.clearSnooze();
+                }
+
+                updateNetworkEnabledLocked();
+                updateNetworkRulesLocked();
+                updateNotificationsLocked();
+                writePolicyLocked();
+
+                fout.println("Cleared snooze timestamps");
+                return;
+            }
+
+            fout.print("Restrict background: "); fout.println(mRestrictBackground);
+            fout.println("Network policies:");
+            fout.increaseIndent();
+            for (NetworkPolicy policy : mNetworkPolicy.values()) {
+                fout.println(policy.toString());
+            }
+            fout.decreaseIndent();
+
+            fout.println("Policy for UIDs:");
+            fout.increaseIndent();
+            int size = mUidPolicy.size();
+            for (int i = 0; i < size; i++) {
+                final int uid = mUidPolicy.keyAt(i);
+                final int policy = mUidPolicy.valueAt(i);
+                fout.print("UID=");
+                fout.print(uid);
+                fout.print(" policy=");
+                dumpPolicy(fout, policy);
+                fout.println();
+            }
+            fout.decreaseIndent();
+
+            final SparseBooleanArray knownUids = new SparseBooleanArray();
+            collectKeys(mUidForeground, knownUids);
+            collectKeys(mUidRules, knownUids);
+
+            fout.println("Status for known UIDs:");
+            fout.increaseIndent();
+            size = knownUids.size();
+            for (int i = 0; i < size; i++) {
+                final int uid = knownUids.keyAt(i);
+                fout.print("UID=");
+                fout.print(uid);
+
+                fout.print(" foreground=");
+                final int foregroundIndex = mUidPidForeground.indexOfKey(uid);
+                if (foregroundIndex < 0) {
+                    fout.print("UNKNOWN");
+                } else {
+                    dumpSparseBooleanArray(fout, mUidPidForeground.valueAt(foregroundIndex));
+                }
+
+                fout.print(" rules=");
+                final int rulesIndex = mUidRules.indexOfKey(uid);
+                if (rulesIndex < 0) {
+                    fout.print("UNKNOWN");
+                } else {
+                    dumpRules(fout, mUidRules.valueAt(rulesIndex));
+                }
+
+                fout.println();
+            }
+            fout.decreaseIndent();
+        }
+    }
+
+    @Override
+    public boolean isUidForeground(int uid) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
+
+        synchronized (mRulesLock) {
+            // only really in foreground when screen is also on
+            return mUidForeground.get(uid, false) && mScreenOn;
+        }
+    }
+
+    /**
+     * Foreground for PID changed; recompute foreground at UID level. If
+     * changed, will trigger {@link #updateRulesForUidLocked(int)}.
+     */
+    private void computeUidForegroundLocked(int uid) {
+        final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
+
+        // current pid is dropping foreground; examine other pids
+        boolean uidForeground = false;
+        final int size = pidForeground.size();
+        for (int i = 0; i < size; i++) {
+            if (pidForeground.valueAt(i)) {
+                uidForeground = true;
+                break;
+            }
+        }
+
+        final boolean oldUidForeground = mUidForeground.get(uid, false);
+        if (oldUidForeground != uidForeground) {
+            // foreground changed, push updated rules
+            mUidForeground.put(uid, uidForeground);
+            updateRulesForUidLocked(uid);
+        }
+    }
+
+    private void updateScreenOn() {
+        synchronized (mRulesLock) {
+            try {
+                mScreenOn = mPowerManager.isScreenOn();
+            } catch (RemoteException e) {
+                // ignored; service lives in system_server
+            }
+            updateRulesForScreenLocked();
+        }
+    }
+
+    /**
+     * Update rules that might be changed by {@link #mScreenOn} value.
+     */
+    private void updateRulesForScreenLocked() {
+        // only update rules for anyone with foreground activities
+        final int size = mUidForeground.size();
+        for (int i = 0; i < size; i++) {
+            if (mUidForeground.valueAt(i)) {
+                final int uid = mUidForeground.keyAt(i);
+                updateRulesForUidLocked(uid);
+            }
+        }
+    }
+
+    /**
+     * Update rules that might be changed by {@link #mRestrictBackground} value.
+     */
+    private void updateRulesForRestrictBackgroundLocked() {
+        final PackageManager pm = mContext.getPackageManager();
+        final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+
+        // update rules for all installed applications
+        final List<UserInfo> users = um.getUsers();
+        final List<ApplicationInfo> apps = pm.getInstalledApplications(
+                PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
+
+        for (UserInfo user : users) {
+            for (ApplicationInfo app : apps) {
+                final int uid = UserHandle.getUid(user.id, app.uid);
+                updateRulesForUidLocked(uid);
+            }
+        }
+
+        // limit data usage for some internal system services
+        updateRulesForUidLocked(android.os.Process.MEDIA_UID);
+        updateRulesForUidLocked(android.os.Process.DRM_UID);
+    }
+
+    private static boolean isUidValidForRules(int uid) {
+        // allow rules on specific system services, and any apps
+        if (uid == android.os.Process.MEDIA_UID || uid == android.os.Process.DRM_UID
+                || UserHandle.isApp(uid)) {
+            return true;
+        }
+
+        return false;
+    }
+
+    private void updateRulesForUidLocked(int uid) {
+        if (!isUidValidForRules(uid)) return;
+
+        final int uidPolicy = getUidPolicy(uid);
+        final boolean uidForeground = isUidForeground(uid);
+
+        // derive active rules based on policy and active state
+        int uidRules = RULE_ALLOW_ALL;
+        if (!uidForeground && (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
+            // uid in background, and policy says to block metered data
+            uidRules = RULE_REJECT_METERED;
+        }
+        if (!uidForeground && mRestrictBackground) {
+            // uid in background, and global background disabled
+            uidRules = RULE_REJECT_METERED;
+        }
+
+        // TODO: only dispatch when rules actually change
+
+        if (uidRules == RULE_ALLOW_ALL) {
+            mUidRules.delete(uid);
+        } else {
+            mUidRules.put(uid, uidRules);
+        }
+
+        final boolean rejectMetered = (uidRules & RULE_REJECT_METERED) != 0;
+        setUidNetworkRules(uid, rejectMetered);
+
+        // dispatch changed rule to existing listeners
+        mHandler.obtainMessage(MSG_RULES_CHANGED, uid, uidRules).sendToTarget();
+
+        try {
+            // adjust stats accounting based on foreground status
+            mNetworkStats.setUidForeground(uid, uidForeground);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    private Handler.Callback mHandlerCallback = new Handler.Callback() {
+        @Override
+        public boolean handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_RULES_CHANGED: {
+                    final int uid = msg.arg1;
+                    final int uidRules = msg.arg2;
+                    final int length = mListeners.beginBroadcast();
+                    for (int i = 0; i < length; i++) {
+                        final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
+                        if (listener != null) {
+                            try {
+                                listener.onUidRulesChanged(uid, uidRules);
+                            } catch (RemoteException e) {
+                            }
+                        }
+                    }
+                    mListeners.finishBroadcast();
+                    return true;
+                }
+                case MSG_METERED_IFACES_CHANGED: {
+                    final String[] meteredIfaces = (String[]) msg.obj;
+                    final int length = mListeners.beginBroadcast();
+                    for (int i = 0; i < length; i++) {
+                        final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
+                        if (listener != null) {
+                            try {
+                                listener.onMeteredIfacesChanged(meteredIfaces);
+                            } catch (RemoteException e) {
+                            }
+                        }
+                    }
+                    mListeners.finishBroadcast();
+                    return true;
+                }
+                case MSG_FOREGROUND_ACTIVITIES_CHANGED: {
+                    final int pid = msg.arg1;
+                    final int uid = msg.arg2;
+                    final boolean foregroundActivities = (Boolean) msg.obj;
+
+                    synchronized (mRulesLock) {
+                        // because a uid can have multiple pids running inside, we need to
+                        // remember all pid states and summarize foreground at uid level.
+
+                        // record foreground for this specific pid
+                        SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
+                        if (pidForeground == null) {
+                            pidForeground = new SparseBooleanArray(2);
+                            mUidPidForeground.put(uid, pidForeground);
+                        }
+                        pidForeground.put(pid, foregroundActivities);
+                        computeUidForegroundLocked(uid);
+                    }
+                    return true;
+                }
+                case MSG_PROCESS_DIED: {
+                    final int pid = msg.arg1;
+                    final int uid = msg.arg2;
+
+                    synchronized (mRulesLock) {
+                        // clear records and recompute, when they exist
+                        final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
+                        if (pidForeground != null) {
+                            pidForeground.delete(pid);
+                            computeUidForegroundLocked(uid);
+                        }
+                    }
+                    return true;
+                }
+                case MSG_LIMIT_REACHED: {
+                    final String iface = (String) msg.obj;
+
+                    maybeRefreshTrustedTime();
+                    synchronized (mRulesLock) {
+                        if (mMeteredIfaces.contains(iface)) {
+                            try {
+                                // force stats update to make sure we have
+                                // numbers that caused alert to trigger.
+                                mNetworkStats.forceUpdate();
+                            } catch (RemoteException e) {
+                                // ignored; service lives in system_server
+                            }
+
+                            updateNetworkEnabledLocked();
+                            updateNotificationsLocked();
+                        }
+                    }
+                    return true;
+                }
+                case MSG_RESTRICT_BACKGROUND_CHANGED: {
+                    final boolean restrictBackground = msg.arg1 != 0;
+                    final int length = mListeners.beginBroadcast();
+                    for (int i = 0; i < length; i++) {
+                        final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
+                        if (listener != null) {
+                            try {
+                                listener.onRestrictBackgroundChanged(restrictBackground);
+                            } catch (RemoteException e) {
+                            }
+                        }
+                    }
+                    mListeners.finishBroadcast();
+                    return true;
+                }
+                case MSG_ADVISE_PERSIST_THRESHOLD: {
+                    final long lowestRule = (Long) msg.obj;
+                    try {
+                        // make sure stats are recorded frequently enough; we aim
+                        // for 2MB threshold for 2GB/month rules.
+                        final long persistThreshold = lowestRule / 1000;
+                        mNetworkStats.advisePersistThreshold(persistThreshold);
+                    } catch (RemoteException e) {
+                        // ignored; service lives in system_server
+                    }
+                    return true;
+                }
+                case MSG_SCREEN_ON_CHANGED: {
+                    updateScreenOn();
+                    return true;
+                }
+                default: {
+                    return false;
+                }
+            }
+        }
+    };
+
+    private void setInterfaceQuota(String iface, long quotaBytes) {
+        try {
+            mNetworkManager.setInterfaceQuota(iface, quotaBytes);
+        } catch (IllegalStateException e) {
+            Log.wtf(TAG, "problem setting interface quota", e);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    private void removeInterfaceQuota(String iface) {
+        try {
+            mNetworkManager.removeInterfaceQuota(iface);
+        } catch (IllegalStateException e) {
+            Log.wtf(TAG, "problem removing interface quota", e);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    private void setUidNetworkRules(int uid, boolean rejectOnQuotaInterfaces) {
+        try {
+            mNetworkManager.setUidNetworkRules(uid, rejectOnQuotaInterfaces);
+        } catch (IllegalStateException e) {
+            Log.wtf(TAG, "problem setting uid rules", e);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    /**
+     * Control {@link IConnectivityManager#setPolicyDataEnable(int, boolean)}.
+     */
+    private void setPolicyDataEnable(int networkType, boolean enabled) {
+        try {
+            mConnManager.setPolicyDataEnable(networkType, enabled);
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+        }
+    }
+
+    private long getTotalBytes(NetworkTemplate template, long start, long end) {
+        try {
+            return mNetworkStats.getNetworkTotalBytes(template, start, end);
+        } catch (RuntimeException e) {
+            Slog.w(TAG, "problem reading network stats: " + e);
+            return 0;
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+            return 0;
+        }
+    }
+
+    private boolean isBandwidthControlEnabled() {
+        final long token = Binder.clearCallingIdentity();
+        try {
+            return mNetworkManager.isBandwidthControlEnabled();
+        } catch (RemoteException e) {
+            // ignored; service lives in system_server
+            return false;
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    /**
+     * Try refreshing {@link #mTime} when stale.
+     */
+    private void maybeRefreshTrustedTime() {
+        if (mTime.getCacheAge() > TIME_CACHE_MAX_AGE) {
+            mTime.forceRefresh();
+        }
+    }
+
+    private long currentTimeMillis() {
+        return mTime.hasCache() ? mTime.currentTimeMillis() : System.currentTimeMillis();
+    }
+
+    private static Intent buildAllowBackgroundDataIntent() {
+        return new Intent(ACTION_ALLOW_BACKGROUND);
+    }
+
+    private static Intent buildSnoozeWarningIntent(NetworkTemplate template) {
+        final Intent intent = new Intent(ACTION_SNOOZE_WARNING);
+        intent.putExtra(EXTRA_NETWORK_TEMPLATE, template);
+        return intent;
+    }
+
+    private static Intent buildNetworkOverLimitIntent(NetworkTemplate template) {
+        final Intent intent = new Intent();
+        intent.setComponent(new ComponentName(
+                "com.android.systemui", "com.android.systemui.net.NetworkOverLimitActivity"));
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.putExtra(EXTRA_NETWORK_TEMPLATE, template);
+        return intent;
+    }
+
+    private static Intent buildViewDataUsageIntent(NetworkTemplate template) {
+        final Intent intent = new Intent();
+        intent.setComponent(new ComponentName(
+                "com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity"));
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.putExtra(EXTRA_NETWORK_TEMPLATE, template);
+        return intent;
+    }
+
+    @VisibleForTesting
+    public void addIdleHandler(IdleHandler handler) {
+        mHandler.getLooper().getQueue().addIdleHandler(handler);
+    }
+
+    private static void collectKeys(SparseIntArray source, SparseBooleanArray target) {
+        final int size = source.size();
+        for (int i = 0; i < size; i++) {
+            target.put(source.keyAt(i), true);
+        }
+    }
+
+    private static void collectKeys(SparseBooleanArray source, SparseBooleanArray target) {
+        final int size = source.size();
+        for (int i = 0; i < size; i++) {
+            target.put(source.keyAt(i), true);
+        }
+    }
+
+    private static void dumpSparseBooleanArray(PrintWriter fout, SparseBooleanArray value) {
+        fout.print("[");
+        final int size = value.size();
+        for (int i = 0; i < size; i++) {
+            fout.print(value.keyAt(i) + "=" + value.valueAt(i));
+            if (i < size - 1) fout.print(",");
+        }
+        fout.print("]");
+    }
+}
diff --git a/services/core/java/com/android/server/net/NetworkStatsCollection.java b/services/core/java/com/android/server/net/NetworkStatsCollection.java
new file mode 100644
index 0000000..475482f
--- /dev/null
+++ b/services/core/java/com/android/server/net/NetworkStatsCollection.java
@@ -0,0 +1,534 @@
+/*
+ * 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.server.net;
+
+import static android.net.NetworkStats.IFACE_ALL;
+import static android.net.NetworkStats.SET_ALL;
+import static android.net.NetworkStats.SET_DEFAULT;
+import static android.net.NetworkStats.TAG_NONE;
+import static android.net.NetworkStats.UID_ALL;
+import static android.net.TrafficStats.UID_REMOVED;
+
+import android.net.NetworkIdentity;
+import android.net.NetworkStats;
+import android.net.NetworkStatsHistory;
+import android.net.NetworkTemplate;
+import android.net.TrafficStats;
+import android.text.format.DateUtils;
+import android.util.AtomicFile;
+
+import com.android.internal.util.ArrayUtils;
+import com.android.internal.util.FileRotator;
+import com.android.internal.util.IndentingPrintWriter;
+import com.google.android.collect.Lists;
+import com.google.android.collect.Maps;
+
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ProtocolException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import libcore.io.IoUtils;
+
+/**
+ * Collection of {@link NetworkStatsHistory}, stored based on combined key of
+ * {@link NetworkIdentitySet}, UID, set, and tag. Knows how to persist itself.
+ */
+public class NetworkStatsCollection implements FileRotator.Reader {
+    /** File header magic number: "ANET" */
+    private static final int FILE_MAGIC = 0x414E4554;
+
+    private static final int VERSION_NETWORK_INIT = 1;
+
+    private static final int VERSION_UID_INIT = 1;
+    private static final int VERSION_UID_WITH_IDENT = 2;
+    private static final int VERSION_UID_WITH_TAG = 3;
+    private static final int VERSION_UID_WITH_SET = 4;
+
+    private static final int VERSION_UNIFIED_INIT = 16;
+
+    private HashMap<Key, NetworkStatsHistory> mStats = Maps.newHashMap();
+
+    private final long mBucketDuration;
+
+    private long mStartMillis;
+    private long mEndMillis;
+    private long mTotalBytes;
+    private boolean mDirty;
+
+    public NetworkStatsCollection(long bucketDuration) {
+        mBucketDuration = bucketDuration;
+        reset();
+    }
+
+    public void reset() {
+        mStats.clear();
+        mStartMillis = Long.MAX_VALUE;
+        mEndMillis = Long.MIN_VALUE;
+        mTotalBytes = 0;
+        mDirty = false;
+    }
+
+    public long getStartMillis() {
+        return mStartMillis;
+    }
+
+    /**
+     * Return first atomic bucket in this collection, which is more conservative
+     * than {@link #mStartMillis}.
+     */
+    public long getFirstAtomicBucketMillis() {
+        if (mStartMillis == Long.MAX_VALUE) {
+            return Long.MAX_VALUE;
+        } else {
+            return mStartMillis + mBucketDuration;
+        }
+    }
+
+    public long getEndMillis() {
+        return mEndMillis;
+    }
+
+    public long getTotalBytes() {
+        return mTotalBytes;
+    }
+
+    public boolean isDirty() {
+        return mDirty;
+    }
+
+    public void clearDirty() {
+        mDirty = false;
+    }
+
+    public boolean isEmpty() {
+        return mStartMillis == Long.MAX_VALUE && mEndMillis == Long.MIN_VALUE;
+    }
+
+    /**
+     * Combine all {@link NetworkStatsHistory} in this collection which match
+     * the requested parameters.
+     */
+    public NetworkStatsHistory getHistory(
+            NetworkTemplate template, int uid, int set, int tag, int fields) {
+        return getHistory(template, uid, set, tag, fields, Long.MIN_VALUE, Long.MAX_VALUE);
+    }
+
+    /**
+     * Combine all {@link NetworkStatsHistory} in this collection which match
+     * the requested parameters.
+     */
+    public NetworkStatsHistory getHistory(
+            NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end) {
+        final NetworkStatsHistory combined = new NetworkStatsHistory(
+                mBucketDuration, estimateBuckets(), fields);
+        for (Map.Entry<Key, NetworkStatsHistory> entry : mStats.entrySet()) {
+            final Key key = entry.getKey();
+            final boolean setMatches = set == SET_ALL || key.set == set;
+            if (key.uid == uid && setMatches && key.tag == tag
+                    && templateMatches(template, key.ident)) {
+                combined.recordHistory(entry.getValue(), start, end);
+            }
+        }
+        return combined;
+    }
+
+    /**
+     * Summarize all {@link NetworkStatsHistory} in this collection which match
+     * the requested parameters.
+     */
+    public NetworkStats getSummary(NetworkTemplate template, long start, long end) {
+        final long now = System.currentTimeMillis();
+
+        final NetworkStats stats = new NetworkStats(end - start, 24);
+        final NetworkStats.Entry entry = new NetworkStats.Entry();
+        NetworkStatsHistory.Entry historyEntry = null;
+
+        // shortcut when we know stats will be empty
+        if (start == end) return stats;
+
+        for (Map.Entry<Key, NetworkStatsHistory> mapEntry : mStats.entrySet()) {
+            final Key key = mapEntry.getKey();
+            if (templateMatches(template, key.ident)) {
+                final NetworkStatsHistory history = mapEntry.getValue();
+                historyEntry = history.getValues(start, end, now, historyEntry);
+
+                entry.iface = IFACE_ALL;
+                entry.uid = key.uid;
+                entry.set = key.set;
+                entry.tag = key.tag;
+                entry.rxBytes = historyEntry.rxBytes;
+                entry.rxPackets = historyEntry.rxPackets;
+                entry.txBytes = historyEntry.txBytes;
+                entry.txPackets = historyEntry.txPackets;
+                entry.operations = historyEntry.operations;
+
+                if (!entry.isEmpty()) {
+                    stats.combineValues(entry);
+                }
+            }
+        }
+
+        return stats;
+    }
+
+    /**
+     * Record given {@link android.net.NetworkStats.Entry} into this collection.
+     */
+    public void recordData(NetworkIdentitySet ident, int uid, int set, int tag, long start,
+            long end, NetworkStats.Entry entry) {
+        final NetworkStatsHistory history = findOrCreateHistory(ident, uid, set, tag);
+        history.recordData(start, end, entry);
+        noteRecordedHistory(history.getStart(), history.getEnd(), entry.rxBytes + entry.txBytes);
+    }
+
+    /**
+     * Record given {@link NetworkStatsHistory} into this collection.
+     */
+    private void recordHistory(Key key, NetworkStatsHistory history) {
+        if (history.size() == 0) return;
+        noteRecordedHistory(history.getStart(), history.getEnd(), history.getTotalBytes());
+
+        NetworkStatsHistory target = mStats.get(key);
+        if (target == null) {
+            target = new NetworkStatsHistory(history.getBucketDuration());
+            mStats.put(key, target);
+        }
+        target.recordEntireHistory(history);
+    }
+
+    /**
+     * Record all {@link NetworkStatsHistory} contained in the given collection
+     * into this collection.
+     */
+    public void recordCollection(NetworkStatsCollection another) {
+        for (Map.Entry<Key, NetworkStatsHistory> entry : another.mStats.entrySet()) {
+            recordHistory(entry.getKey(), entry.getValue());
+        }
+    }
+
+    private NetworkStatsHistory findOrCreateHistory(
+            NetworkIdentitySet ident, int uid, int set, int tag) {
+        final Key key = new Key(ident, uid, set, tag);
+        final NetworkStatsHistory existing = mStats.get(key);
+
+        // update when no existing, or when bucket duration changed
+        NetworkStatsHistory updated = null;
+        if (existing == null) {
+            updated = new NetworkStatsHistory(mBucketDuration, 10);
+        } else if (existing.getBucketDuration() != mBucketDuration) {
+            updated = new NetworkStatsHistory(existing, mBucketDuration);
+        }
+
+        if (updated != null) {
+            mStats.put(key, updated);
+            return updated;
+        } else {
+            return existing;
+        }
+    }
+
+    @Override
+    public void read(InputStream in) throws IOException {
+        read(new DataInputStream(in));
+    }
+
+    public void read(DataInputStream in) throws IOException {
+        // verify file magic header intact
+        final int magic = in.readInt();
+        if (magic != FILE_MAGIC) {
+            throw new ProtocolException("unexpected magic: " + magic);
+        }
+
+        final int version = in.readInt();
+        switch (version) {
+            case VERSION_UNIFIED_INIT: {
+                // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
+                final int identSize = in.readInt();
+                for (int i = 0; i < identSize; i++) {
+                    final NetworkIdentitySet ident = new NetworkIdentitySet(in);
+
+                    final int size = in.readInt();
+                    for (int j = 0; j < size; j++) {
+                        final int uid = in.readInt();
+                        final int set = in.readInt();
+                        final int tag = in.readInt();
+
+                        final Key key = new Key(ident, uid, set, tag);
+                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
+                        recordHistory(key, history);
+                    }
+                }
+                break;
+            }
+            default: {
+                throw new ProtocolException("unexpected version: " + version);
+            }
+        }
+    }
+
+    public void write(DataOutputStream out) throws IOException {
+        // cluster key lists grouped by ident
+        final HashMap<NetworkIdentitySet, ArrayList<Key>> keysByIdent = Maps.newHashMap();
+        for (Key key : mStats.keySet()) {
+            ArrayList<Key> keys = keysByIdent.get(key.ident);
+            if (keys == null) {
+                keys = Lists.newArrayList();
+                keysByIdent.put(key.ident, keys);
+            }
+            keys.add(key);
+        }
+
+        out.writeInt(FILE_MAGIC);
+        out.writeInt(VERSION_UNIFIED_INIT);
+
+        out.writeInt(keysByIdent.size());
+        for (NetworkIdentitySet ident : keysByIdent.keySet()) {
+            final ArrayList<Key> keys = keysByIdent.get(ident);
+            ident.writeToStream(out);
+
+            out.writeInt(keys.size());
+            for (Key key : keys) {
+                final NetworkStatsHistory history = mStats.get(key);
+                out.writeInt(key.uid);
+                out.writeInt(key.set);
+                out.writeInt(key.tag);
+                history.writeToStream(out);
+            }
+        }
+
+        out.flush();
+    }
+
+    @Deprecated
+    public void readLegacyNetwork(File file) throws IOException {
+        final AtomicFile inputFile = new AtomicFile(file);
+
+        DataInputStream in = null;
+        try {
+            in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
+
+            // verify file magic header intact
+            final int magic = in.readInt();
+            if (magic != FILE_MAGIC) {
+                throw new ProtocolException("unexpected magic: " + magic);
+            }
+
+            final int version = in.readInt();
+            switch (version) {
+                case VERSION_NETWORK_INIT: {
+                    // network := size *(NetworkIdentitySet NetworkStatsHistory)
+                    final int size = in.readInt();
+                    for (int i = 0; i < size; i++) {
+                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
+                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
+
+                        final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
+                        recordHistory(key, history);
+                    }
+                    break;
+                }
+                default: {
+                    throw new ProtocolException("unexpected version: " + version);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            // missing stats is okay, probably first boot
+        } finally {
+            IoUtils.closeQuietly(in);
+        }
+    }
+
+    @Deprecated
+    public void readLegacyUid(File file, boolean onlyTags) throws IOException {
+        final AtomicFile inputFile = new AtomicFile(file);
+
+        DataInputStream in = null;
+        try {
+            in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
+
+            // verify file magic header intact
+            final int magic = in.readInt();
+            if (magic != FILE_MAGIC) {
+                throw new ProtocolException("unexpected magic: " + magic);
+            }
+
+            final int version = in.readInt();
+            switch (version) {
+                case VERSION_UID_INIT: {
+                    // uid := size *(UID NetworkStatsHistory)
+
+                    // drop this data version, since we don't have a good
+                    // mapping into NetworkIdentitySet.
+                    break;
+                }
+                case VERSION_UID_WITH_IDENT: {
+                    // uid := size *(NetworkIdentitySet size *(UID NetworkStatsHistory))
+
+                    // drop this data version, since this version only existed
+                    // for a short time.
+                    break;
+                }
+                case VERSION_UID_WITH_TAG:
+                case VERSION_UID_WITH_SET: {
+                    // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
+                    final int identSize = in.readInt();
+                    for (int i = 0; i < identSize; i++) {
+                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
+
+                        final int size = in.readInt();
+                        for (int j = 0; j < size; j++) {
+                            final int uid = in.readInt();
+                            final int set = (version >= VERSION_UID_WITH_SET) ? in.readInt()
+                                    : SET_DEFAULT;
+                            final int tag = in.readInt();
+
+                            final Key key = new Key(ident, uid, set, tag);
+                            final NetworkStatsHistory history = new NetworkStatsHistory(in);
+
+                            if ((tag == TAG_NONE) != onlyTags) {
+                                recordHistory(key, history);
+                            }
+                        }
+                    }
+                    break;
+                }
+                default: {
+                    throw new ProtocolException("unexpected version: " + version);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            // missing stats is okay, probably first boot
+        } finally {
+            IoUtils.closeQuietly(in);
+        }
+    }
+
+    /**
+     * Remove any {@link NetworkStatsHistory} attributed to the requested UID,
+     * moving any {@link NetworkStats#TAG_NONE} series to
+     * {@link TrafficStats#UID_REMOVED}.
+     */
+    public void removeUids(int[] uids) {
+        final ArrayList<Key> knownKeys = Lists.newArrayList();
+        knownKeys.addAll(mStats.keySet());
+
+        // migrate all UID stats into special "removed" bucket
+        for (Key key : knownKeys) {
+            if (ArrayUtils.contains(uids, key.uid)) {
+                // only migrate combined TAG_NONE history
+                if (key.tag == TAG_NONE) {
+                    final NetworkStatsHistory uidHistory = mStats.get(key);
+                    final NetworkStatsHistory removedHistory = findOrCreateHistory(
+                            key.ident, UID_REMOVED, SET_DEFAULT, TAG_NONE);
+                    removedHistory.recordEntireHistory(uidHistory);
+                }
+                mStats.remove(key);
+                mDirty = true;
+            }
+        }
+    }
+
+    private void noteRecordedHistory(long startMillis, long endMillis, long totalBytes) {
+        if (startMillis < mStartMillis) mStartMillis = startMillis;
+        if (endMillis > mEndMillis) mEndMillis = endMillis;
+        mTotalBytes += totalBytes;
+        mDirty = true;
+    }
+
+    private int estimateBuckets() {
+        return (int) (Math.min(mEndMillis - mStartMillis, DateUtils.WEEK_IN_MILLIS * 5)
+                / mBucketDuration);
+    }
+
+    public void dump(IndentingPrintWriter pw) {
+        final ArrayList<Key> keys = Lists.newArrayList();
+        keys.addAll(mStats.keySet());
+        Collections.sort(keys);
+
+        for (Key key : keys) {
+            pw.print("ident="); pw.print(key.ident.toString());
+            pw.print(" uid="); pw.print(key.uid);
+            pw.print(" set="); pw.print(NetworkStats.setToString(key.set));
+            pw.print(" tag="); pw.println(NetworkStats.tagToString(key.tag));
+
+            final NetworkStatsHistory history = mStats.get(key);
+            pw.increaseIndent();
+            history.dump(pw, true);
+            pw.decreaseIndent();
+        }
+    }
+
+    /**
+     * Test if given {@link NetworkTemplate} matches any {@link NetworkIdentity}
+     * in the given {@link NetworkIdentitySet}.
+     */
+    private static boolean templateMatches(NetworkTemplate template, NetworkIdentitySet identSet) {
+        for (NetworkIdentity ident : identSet) {
+            if (template.matches(ident)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static class Key implements Comparable<Key> {
+        public final NetworkIdentitySet ident;
+        public final int uid;
+        public final int set;
+        public final int tag;
+
+        private final int hashCode;
+
+        public Key(NetworkIdentitySet ident, int uid, int set, int tag) {
+            this.ident = ident;
+            this.uid = uid;
+            this.set = set;
+            this.tag = tag;
+            hashCode = Objects.hash(ident, uid, set, tag);
+        }
+
+        @Override
+        public int hashCode() {
+            return hashCode;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj instanceof Key) {
+                final Key key = (Key) obj;
+                return uid == key.uid && set == key.set && tag == key.tag
+                        && Objects.equals(ident, key.ident);
+            }
+            return false;
+        }
+
+        @Override
+        public int compareTo(Key another) {
+            return Integer.compare(uid, another.uid);
+        }
+    }
+}
diff --git a/services/java/com/android/server/net/NetworkStatsRecorder.java b/services/core/java/com/android/server/net/NetworkStatsRecorder.java
similarity index 100%
rename from services/java/com/android/server/net/NetworkStatsRecorder.java
rename to services/core/java/com/android/server/net/NetworkStatsRecorder.java
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java
similarity index 100%
rename from services/java/com/android/server/net/NetworkStatsService.java
rename to services/core/java/com/android/server/net/NetworkStatsService.java
diff --git a/services/core/java/com/android/server/notification/NotificationDelegate.java b/services/core/java/com/android/server/notification/NotificationDelegate.java
new file mode 100644
index 0000000..df2aaca
--- /dev/null
+++ b/services/core/java/com/android/server/notification/NotificationDelegate.java
@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) 2013, 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.notification;
+
+public interface NotificationDelegate {
+    void onSetDisabled(int status);
+    void onClearAll();
+    void onNotificationClick(String pkg, String tag, int id);
+    void onNotificationClear(String pkg, String tag, int id);
+    void onNotificationError(String pkg, String tag, int id,
+            int uid, int initialPid, String message);
+    void onPanelRevealed();
+}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerInternal.java b/services/core/java/com/android/server/notification/NotificationManagerInternal.java
new file mode 100644
index 0000000..b695b68
--- /dev/null
+++ b/services/core/java/com/android/server/notification/NotificationManagerInternal.java
@@ -0,0 +1,24 @@
+/*
+ * 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.server.notification;
+
+import android.app.Notification;
+
+public interface NotificationManagerInternal {
+    void enqueueNotification(String pkg, String basePkg, int callingUid, int callingPid,
+            String tag, int id, Notification notification, int[] idReceived, int userId);
+}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
new file mode 100644
index 0000000..bd4442e
--- /dev/null
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -0,0 +1,2456 @@
+/*
+ * Copyright (C) 2007 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.notification;
+
+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.app.ActivityManager;
+import android.app.ActivityManagerNative;
+import android.app.AppGlobals;
+import android.app.AppOpsManager;
+import android.app.IActivityManager;
+import android.app.INotificationManager;
+import android.app.ITransientNotification;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.app.StatusBarManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.graphics.Bitmap;
+import android.media.AudioManager;
+import android.media.IRingtonePlayer;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.os.Vibrator;
+import android.provider.Settings;
+import android.service.notification.INotificationListener;
+import android.service.notification.NotificationListenerService;
+import android.service.notification.StatusBarNotification;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+import android.util.AtomicFile;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Slog;
+import android.util.Xml;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
+import android.widget.Toast;
+
+import com.android.internal.R;
+
+import com.android.internal.notification.NotificationScorer;
+import com.android.server.EventLogTags;
+import com.android.server.statusbar.StatusBarManagerInternal;
+import com.android.server.SystemService;
+import com.android.server.lights.Light;
+import com.android.server.lights.LightsManager;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Array;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import libcore.io.IoUtils;
+
+/** {@hide} */
+public class NotificationManagerService extends SystemService {
+    static final String TAG = "NotificationService";
+    static final boolean DBG = false;
+
+    static final int MAX_PACKAGE_NOTIFICATIONS = 50;
+
+    // message codes
+    static final int MESSAGE_TIMEOUT = 2;
+
+    static final int LONG_DELAY = 3500; // 3.5 seconds
+    static final int SHORT_DELAY = 2000; // 2 seconds
+
+    static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
+    static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps
+
+    static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;
+    static final boolean SCORE_ONGOING_HIGHER = false;
+
+    static final int JUNK_SCORE = -1000;
+    static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10;
+    static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER;
+
+    // Notifications with scores below this will not interrupt the user, either via LED or
+    // sound or vibration
+    static final int SCORE_INTERRUPTION_THRESHOLD =
+            Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
+
+    static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
+    static final boolean ENABLE_BLOCKED_TOASTS = true;
+
+    static final String ENABLED_NOTIFICATION_LISTENERS_SEPARATOR = ":";
+
+    private IActivityManager mAm;
+    AudioManager mAudioManager;
+    StatusBarManagerInternal mStatusBar;
+    Vibrator mVibrator;
+
+    final IBinder mForegroundToken = new Binder();
+    private WorkerHandler mHandler;
+
+    private Light mNotificationLight;
+    Light mAttentionLight;
+    private int mDefaultNotificationColor;
+    private int mDefaultNotificationLedOn;
+
+    private int mDefaultNotificationLedOff;
+    private long[] mDefaultVibrationPattern;
+
+    private long[] mFallbackVibrationPattern;
+    boolean mSystemReady;
+
+    int mDisabledNotifications;
+    NotificationRecord mSoundNotification;
+    NotificationRecord mVibrateNotification;
+
+    // for enabling and disabling notification pulse behavior
+    private boolean mScreenOn = true;
+    private boolean mInCall = false;
+    private boolean mNotificationPulseEnabled;
+
+    // used as a mutex for access to all active notifications & listeners
+    final ArrayList<NotificationRecord> mNotificationList =
+            new ArrayList<NotificationRecord>();
+
+    final ArrayList<ToastRecord> mToastQueue = new ArrayList<ToastRecord>();
+
+    ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>();
+    NotificationRecord mLedNotification;
+
+    private AppOpsManager mAppOps;
+
+    // contains connections to all connected listeners, including app services
+    // and system listeners
+    private ArrayList<NotificationListenerInfo> mListeners
+            = new ArrayList<NotificationListenerInfo>();
+    // things that will be put into mListeners as soon as they're ready
+    private ArrayList<String> mServicesBinding = new ArrayList<String>();
+    // lists the component names of all enabled (and therefore connected) listener
+    // app services for the current user only
+    private HashSet<ComponentName> mEnabledListenersForCurrentUser
+            = new HashSet<ComponentName>();
+    // Just the packages from mEnabledListenersForCurrentUser
+    private HashSet<String> mEnabledListenerPackageNames = new HashSet<String>();
+
+    // Notification control database. For now just contains disabled packages.
+    private AtomicFile mPolicyFile;
+    private HashSet<String> mBlockedPackages = new HashSet<String>();
+
+    private static final int DB_VERSION = 1;
+
+    private static final String TAG_BODY = "notification-policy";
+    private static final String ATTR_VERSION = "version";
+
+    private static final String TAG_BLOCKED_PKGS = "blocked-packages";
+    private static final String TAG_PACKAGE = "package";
+    private static final String ATTR_NAME = "name";
+
+    final ArrayList<NotificationScorer> mScorers = new ArrayList<NotificationScorer>();
+
+    private class NotificationListenerInfo implements IBinder.DeathRecipient {
+        INotificationListener listener;
+        ComponentName component;
+        int userid;
+        boolean isSystem;
+        ServiceConnection connection;
+
+        public NotificationListenerInfo(INotificationListener listener, ComponentName component,
+                int userid, boolean isSystem) {
+            this.listener = listener;
+            this.component = component;
+            this.userid = userid;
+            this.isSystem = isSystem;
+            this.connection = null;
+        }
+
+        public NotificationListenerInfo(INotificationListener listener, ComponentName component,
+                int userid, ServiceConnection connection) {
+            this.listener = listener;
+            this.component = component;
+            this.userid = userid;
+            this.isSystem = false;
+            this.connection = connection;
+        }
+
+        boolean enabledAndUserMatches(StatusBarNotification sbn) {
+            final int nid = sbn.getUserId();
+            if (!isEnabledForCurrentUser()) {
+                return false;
+            }
+            if (this.userid == UserHandle.USER_ALL) return true;
+            return (nid == UserHandle.USER_ALL || nid == this.userid);
+        }
+
+        public void notifyPostedIfUserMatch(StatusBarNotification sbn) {
+            if (!enabledAndUserMatches(sbn)) {
+                return;
+            }
+            try {
+                listener.onNotificationPosted(sbn);
+            } catch (RemoteException ex) {
+                Log.e(TAG, "unable to notify listener (posted): " + listener, ex);
+            }
+        }
+
+        public void notifyRemovedIfUserMatch(StatusBarNotification sbn) {
+            if (!enabledAndUserMatches(sbn)) return;
+            try {
+                listener.onNotificationRemoved(sbn);
+            } catch (RemoteException ex) {
+                Log.e(TAG, "unable to notify listener (removed): " + listener, ex);
+            }
+        }
+
+        @Override
+        public void binderDied() {
+            // Remove the listener, but don't unbind from the service. The system will bring the
+            // service back up, and the onServiceConnected handler will readd the listener with the
+            // new binding. If this isn't a bound service, and is just a registered
+            // INotificationListener, just removing it from the list is all we need to do anyway.
+            removeListenerImpl(this.listener, this.userid);
+        }
+
+        /** convenience method for looking in mEnabledListenersForCurrentUser */
+        public boolean isEnabledForCurrentUser() {
+            if (this.isSystem) return true;
+            if (this.connection == null) return false;
+            return mEnabledListenersForCurrentUser.contains(this.component);
+        }
+    }
+
+    private static class Archive {
+        static final int BUFFER_SIZE = 250;
+        ArrayDeque<StatusBarNotification> mBuffer = new ArrayDeque<StatusBarNotification>(BUFFER_SIZE);
+
+        public Archive() {
+        }
+
+        public String toString() {
+            final StringBuilder sb = new StringBuilder();
+            final int N = mBuffer.size();
+            sb.append("Archive (");
+            sb.append(N);
+            sb.append(" notification");
+            sb.append((N==1)?")":"s)");
+            return sb.toString();
+        }
+
+        public void record(StatusBarNotification nr) {
+            if (mBuffer.size() == BUFFER_SIZE) {
+                mBuffer.removeFirst();
+            }
+
+            // We don't want to store the heavy bits of the notification in the archive,
+            // but other clients in the system process might be using the object, so we
+            // store a (lightened) copy.
+            mBuffer.addLast(nr.cloneLight());
+        }
+
+
+        public void clear() {
+            mBuffer.clear();
+        }
+
+        public Iterator<StatusBarNotification> descendingIterator() {
+            return mBuffer.descendingIterator();
+        }
+        public Iterator<StatusBarNotification> ascendingIterator() {
+            return mBuffer.iterator();
+        }
+        public Iterator<StatusBarNotification> filter(
+                final Iterator<StatusBarNotification> iter, final String pkg, final int userId) {
+            return new Iterator<StatusBarNotification>() {
+                StatusBarNotification mNext = findNext();
+
+                private StatusBarNotification findNext() {
+                    while (iter.hasNext()) {
+                        StatusBarNotification nr = iter.next();
+                        if ((pkg == null || nr.getPackageName() == pkg)
+                                && (userId == UserHandle.USER_ALL || nr.getUserId() == userId)) {
+                            return nr;
+                        }
+                    }
+                    return null;
+                }
+
+                @Override
+                public boolean hasNext() {
+                    return mNext == null;
+                }
+
+                @Override
+                public StatusBarNotification next() {
+                    StatusBarNotification next = mNext;
+                    if (next == null) {
+                        throw new NoSuchElementException();
+                    }
+                    mNext = findNext();
+                    return next;
+                }
+
+                @Override
+                public void remove() {
+                    iter.remove();
+                }
+            };
+        }
+
+        public StatusBarNotification[] getArray(int count) {
+            if (count == 0) count = Archive.BUFFER_SIZE;
+            final StatusBarNotification[] a
+                    = new StatusBarNotification[Math.min(count, mBuffer.size())];
+            Iterator<StatusBarNotification> iter = descendingIterator();
+            int i=0;
+            while (iter.hasNext() && i < count) {
+                a[i++] = iter.next();
+            }
+            return a;
+        }
+
+        public StatusBarNotification[] getArray(int count, String pkg, int userId) {
+            if (count == 0) count = Archive.BUFFER_SIZE;
+            final StatusBarNotification[] a
+                    = new StatusBarNotification[Math.min(count, mBuffer.size())];
+            Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId);
+            int i=0;
+            while (iter.hasNext() && i < count) {
+                a[i++] = iter.next();
+            }
+            return a;
+        }
+
+    }
+
+    Archive mArchive = new Archive();
+
+    private void loadBlockDb() {
+        synchronized(mBlockedPackages) {
+            if (mPolicyFile == null) {
+                File dir = new File("/data/system");
+                mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml"));
+
+                mBlockedPackages.clear();
+
+                FileInputStream infile = null;
+                try {
+                    infile = mPolicyFile.openRead();
+                    final XmlPullParser parser = Xml.newPullParser();
+                    parser.setInput(infile, null);
+
+                    int type;
+                    String tag;
+                    int version = DB_VERSION;
+                    while ((type = parser.next()) != END_DOCUMENT) {
+                        tag = parser.getName();
+                        if (type == START_TAG) {
+                            if (TAG_BODY.equals(tag)) {
+                                version = Integer.parseInt(
+                                        parser.getAttributeValue(null, ATTR_VERSION));
+                            } else if (TAG_BLOCKED_PKGS.equals(tag)) {
+                                while ((type = parser.next()) != END_DOCUMENT) {
+                                    tag = parser.getName();
+                                    if (TAG_PACKAGE.equals(tag)) {
+                                        mBlockedPackages.add(
+                                                parser.getAttributeValue(null, ATTR_NAME));
+                                    } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) {
+                                        break;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                } catch (FileNotFoundException e) {
+                    // No data yet
+                } catch (IOException e) {
+                    Log.wtf(TAG, "Unable to read blocked notifications database", e);
+                } catch (NumberFormatException e) {
+                    Log.wtf(TAG, "Unable to parse blocked notifications database", e);
+                } catch (XmlPullParserException e) {
+                    Log.wtf(TAG, "Unable to parse blocked notifications database", e);
+                } finally {
+                    IoUtils.closeQuietly(infile);
+                }
+            }
+        }
+    }
+
+    /** Use this when you actually want to post a notification or toast.
+     *
+     * Unchecked. Not exposed via Binder, but can be called in the course of enqueue*().
+     */
+    private boolean noteNotificationOp(String pkg, int uid) {
+        if (mAppOps.noteOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
+                != AppOpsManager.MODE_ALLOWED) {
+            Slog.v(TAG, "notifications are disabled by AppOps for " + pkg);
+            return false;
+        }
+        return true;
+    }
+
+    private static String idDebugString(Context baseContext, String packageName, int id) {
+        Context c = null;
+
+        if (packageName != null) {
+            try {
+                c = baseContext.createPackageContext(packageName, 0);
+            } catch (NameNotFoundException e) {
+                c = baseContext;
+            }
+        } else {
+            c = baseContext;
+        }
+
+        String pkg;
+        String type;
+        String name;
+
+        Resources r = c.getResources();
+        try {
+            return r.getResourceName(id);
+        } catch (Resources.NotFoundException e) {
+            return "<name unknown>";
+        }
+    }
+
+
+    /**
+     * Remove notification access for any services that no longer exist.
+     */
+    void disableNonexistentListeners() {
+        int currentUser = ActivityManager.getCurrentUser();
+        String flatIn = Settings.Secure.getStringForUser(
+                getContext().getContentResolver(),
+                Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
+                currentUser);
+        if (!TextUtils.isEmpty(flatIn)) {
+            if (DBG) Slog.v(TAG, "flat before: " + flatIn);
+            PackageManager pm = getContext().getPackageManager();
+            List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
+                    new Intent(NotificationListenerService.SERVICE_INTERFACE),
+                    PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
+                    currentUser);
+
+            Set<ComponentName> installed = new HashSet<ComponentName>();
+            for (int i = 0, count = installedServices.size(); i < count; i++) {
+                ResolveInfo resolveInfo = installedServices.get(i);
+                ServiceInfo info = resolveInfo.serviceInfo;
+
+                if (!android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE.equals(
+                                info.permission)) {
+                    Slog.w(TAG, "Skipping notification listener service "
+                            + info.packageName + "/" + info.name
+                            + ": it does not require the permission "
+                            + android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);
+                    continue;
+                }
+                installed.add(new ComponentName(info.packageName, info.name));
+            }
+
+            String flatOut = "";
+            if (!installed.isEmpty()) {
+                String[] enabled = flatIn.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
+                ArrayList<String> remaining = new ArrayList<String>(enabled.length);
+                for (int i = 0; i < enabled.length; i++) {
+                    ComponentName enabledComponent = ComponentName.unflattenFromString(enabled[i]);
+                    if (installed.contains(enabledComponent)) {
+                        remaining.add(enabled[i]);
+                    }
+                }
+                flatOut = TextUtils.join(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR, remaining);
+            }
+            if (DBG) Slog.v(TAG, "flat after: " + flatOut);
+            if (!flatIn.equals(flatOut)) {
+                Settings.Secure.putStringForUser(getContext().getContentResolver(),
+                        Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
+                        flatOut, currentUser);
+            }
+        }
+    }
+
+    /**
+     * Called whenever packages change, the user switches, or ENABLED_NOTIFICATION_LISTENERS
+     * is altered. (For example in response to USER_SWITCHED in our broadcast receiver)
+     */
+    void rebindListenerServices() {
+        final int currentUser = ActivityManager.getCurrentUser();
+        String flat = Settings.Secure.getStringForUser(
+                getContext().getContentResolver(),
+                Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
+                currentUser);
+
+        NotificationListenerInfo[] toRemove = new NotificationListenerInfo[mListeners.size()];
+        final ArrayList<ComponentName> toAdd;
+
+        synchronized (mNotificationList) {
+            // unbind and remove all existing listeners
+            toRemove = mListeners.toArray(toRemove);
+
+            toAdd = new ArrayList<ComponentName>();
+            final HashSet<ComponentName> newEnabled = new HashSet<ComponentName>();
+            final HashSet<String> newPackages = new HashSet<String>();
+
+            // decode the list of components
+            if (flat != null) {
+                String[] components = flat.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
+                for (int i=0; i<components.length; i++) {
+                    final ComponentName component
+                            = ComponentName.unflattenFromString(components[i]);
+                    if (component != null) {
+                        newEnabled.add(component);
+                        toAdd.add(component);
+                        newPackages.add(component.getPackageName());
+                    }
+                }
+
+                mEnabledListenersForCurrentUser = newEnabled;
+                mEnabledListenerPackageNames = newPackages;
+            }
+        }
+
+        for (NotificationListenerInfo info : toRemove) {
+            final ComponentName component = info.component;
+            final int oldUser = info.userid;
+            Slog.v(TAG, "disabling notification listener for user " + oldUser + ": " + component);
+            unregisterListenerService(component, info.userid);
+        }
+
+        final int N = toAdd.size();
+        for (int i=0; i<N; i++) {
+            final ComponentName component = toAdd.get(i);
+            Slog.v(TAG, "enabling notification listener for user " + currentUser + ": "
+                    + component);
+            registerListenerService(component, currentUser);
+        }
+    }
+
+
+    /**
+     * Version of registerListener that takes the name of a
+     * {@link android.service.notification.NotificationListenerService} to bind to.
+     *
+     * This is the mechanism by which third parties may subscribe to notifications.
+     */
+    private void registerListenerService(final ComponentName name, final int userid) {
+        checkCallerIsSystem();
+
+        if (DBG) Slog.v(TAG, "registerListenerService: " + name + " u=" + userid);
+
+        synchronized (mNotificationList) {
+            final String servicesBindingTag = name.toString() + "/" + userid;
+            if (mServicesBinding.contains(servicesBindingTag)) {
+                // stop registering this thing already! we're working on it
+                return;
+            }
+            mServicesBinding.add(servicesBindingTag);
+
+            final int N = mListeners.size();
+            for (int i=N-1; i>=0; i--) {
+                final NotificationListenerInfo info = mListeners.get(i);
+                if (name.equals(info.component)
+                        && info.userid == userid) {
+                    // cut old connections
+                    if (DBG) Slog.v(TAG, "    disconnecting old listener: " + info.listener);
+                    mListeners.remove(i);
+                    if (info.connection != null) {
+                        getContext().unbindService(info.connection);
+                    }
+                }
+            }
+
+            Intent intent = new Intent(NotificationListenerService.SERVICE_INTERFACE);
+            intent.setComponent(name);
+
+            intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
+                    R.string.notification_listener_binding_label);
+
+            final PendingIntent pendingIntent = PendingIntent.getActivity(
+                    getContext(), 0, new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS), 0);
+            intent.putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
+
+            try {
+                if (DBG) Slog.v(TAG, "binding: " + intent);
+                if (!getContext().bindServiceAsUser(intent,
+                        new ServiceConnection() {
+                            INotificationListener mListener;
+
+                            @Override
+                            public void onServiceConnected(ComponentName name, IBinder service) {
+                                synchronized (mNotificationList) {
+                                    mServicesBinding.remove(servicesBindingTag);
+                                    try {
+                                        mListener = INotificationListener.Stub.asInterface(service);
+                                        NotificationListenerInfo info
+                                                = new NotificationListenerInfo(
+                                                mListener, name, userid, this);
+                                        service.linkToDeath(info, 0);
+                                        mListeners.add(info);
+                                    } catch (RemoteException e) {
+                                        // already dead
+                                    }
+                                }
+                            }
+
+                            @Override
+                            public void onServiceDisconnected(ComponentName name) {
+                                Slog.v(TAG, "notification listener connection lost: " + name);
+                            }
+                        },
+                        Context.BIND_AUTO_CREATE,
+                        new UserHandle(userid)))
+                {
+                    mServicesBinding.remove(servicesBindingTag);
+                    Slog.w(TAG, "Unable to bind listener service: " + intent);
+                    return;
+                }
+            } catch (SecurityException ex) {
+                Slog.e(TAG, "Unable to bind listener service: " + intent, ex);
+                return;
+            }
+        }
+    }
+
+
+    /**
+     * Remove a listener service for the given user by ComponentName
+     */
+    private void unregisterListenerService(ComponentName name, int userid) {
+        checkCallerIsSystem();
+
+        synchronized (mNotificationList) {
+            final int N = mListeners.size();
+            for (int i=N-1; i>=0; i--) {
+                final NotificationListenerInfo info = mListeners.get(i);
+                if (name.equals(info.component)
+                        && info.userid == userid) {
+                    mListeners.remove(i);
+                    if (info.connection != null) {
+                        try {
+                            getContext().unbindService(info.connection);
+                        } catch (IllegalArgumentException ex) {
+                            // something happened to the service: we think we have a connection
+                            // but it's bogus.
+                            Slog.e(TAG, "Listener " + name + " could not be unbound: " + ex);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * asynchronously notify all listeners about a new notification
+     */
+    void notifyPostedLocked(NotificationRecord n) {
+        // make a copy in case changes are made to the underlying Notification object
+        final StatusBarNotification sbn = n.sbn.clone();
+        for (final NotificationListenerInfo info : mListeners) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    info.notifyPostedIfUserMatch(sbn);
+                }});
+        }
+    }
+
+    /**
+     * asynchronously notify all listeners about a removed notification
+     */
+    void notifyRemovedLocked(NotificationRecord n) {
+        // make a copy in case changes are made to the underlying Notification object
+        // NOTE: this copy is lightweight: it doesn't include heavyweight parts of the notification
+        final StatusBarNotification sbn_light = n.sbn.cloneLight();
+
+        for (final NotificationListenerInfo info : mListeners) {
+            mHandler.post(new Runnable() {
+                @Override
+                public void run() {
+                    info.notifyRemovedIfUserMatch(sbn_light);
+                }});
+        }
+    }
+
+    // -- APIs to support listeners clicking/clearing notifications --
+
+    private void checkNullListener(INotificationListener listener) {
+        if (listener == null) {
+            throw new IllegalArgumentException("Listener must not be null");
+        }
+    }
+
+    private NotificationListenerInfo checkListenerToken(INotificationListener listener) {
+        checkNullListener(listener);
+        final IBinder token = listener.asBinder();
+        final int N = mListeners.size();
+        for (int i=0; i<N; i++) {
+            final NotificationListenerInfo info = mListeners.get(i);
+            if (info.listener.asBinder() == token) return info;
+        }
+        throw new SecurityException("Disallowed call from unknown listener: " + listener);
+    }
+
+
+
+    // -- end of listener APIs --
+
+    public static final class NotificationRecord
+    {
+        final StatusBarNotification sbn;
+        IBinder statusBarKey;
+
+        NotificationRecord(StatusBarNotification sbn)
+        {
+            this.sbn = sbn;
+        }
+
+        public Notification getNotification() { return sbn.getNotification(); }
+        public int getFlags() { return sbn.getNotification().flags; }
+        public int getUserId() { return sbn.getUserId(); }
+
+        void dump(PrintWriter pw, String prefix, Context baseContext) {
+            final Notification notification = sbn.getNotification();
+            pw.println(prefix + this);
+            pw.println(prefix + "  uid=" + sbn.getUid() + " userId=" + sbn.getUserId());
+            pw.println(prefix + "  icon=0x" + Integer.toHexString(notification.icon)
+                    + " / " + idDebugString(baseContext, sbn.getPackageName(), notification.icon));
+            pw.println(prefix + "  pri=" + notification.priority + " score=" + sbn.getScore());
+            pw.println(prefix + "  contentIntent=" + notification.contentIntent);
+            pw.println(prefix + "  deleteIntent=" + notification.deleteIntent);
+            pw.println(prefix + "  tickerText=" + notification.tickerText);
+            pw.println(prefix + "  contentView=" + notification.contentView);
+            pw.println(prefix + String.format("  defaults=0x%08x flags=0x%08x",
+                    notification.defaults, notification.flags));
+            pw.println(prefix + "  sound=" + notification.sound);
+            pw.println(prefix + "  vibrate=" + Arrays.toString(notification.vibrate));
+            pw.println(prefix + String.format("  led=0x%08x onMs=%d offMs=%d",
+                    notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
+            if (notification.actions != null && notification.actions.length > 0) {
+                pw.println(prefix + "  actions={");
+                final int N = notification.actions.length;
+                for (int i=0; i<N; i++) {
+                    final Notification.Action action = notification.actions[i];
+                    pw.println(String.format("%s    [%d] \"%s\" -> %s",
+                            prefix,
+                            i,
+                            action.title,
+                            action.actionIntent.toString()
+                            ));
+                }
+                pw.println(prefix + "  }");
+            }
+            if (notification.extras != null && notification.extras.size() > 0) {
+                pw.println(prefix + "  extras={");
+                for (String key : notification.extras.keySet()) {
+                    pw.print(prefix + "    " + key + "=");
+                    Object val = notification.extras.get(key);
+                    if (val == null) {
+                        pw.println("null");
+                    } else {
+                        pw.print(val.toString());
+                        if (val instanceof Bitmap) {
+                            pw.print(String.format(" (%dx%d)",
+                                    ((Bitmap) val).getWidth(),
+                                    ((Bitmap) val).getHeight()));
+                        } else if (val.getClass().isArray()) {
+                            pw.println(" {");
+                            final int N = Array.getLength(val);
+                            for (int i=0; i<N; i++) {
+                                if (i > 0) pw.println(",");
+                                pw.print(prefix + "      " + Array.get(val, i));
+                            }
+                            pw.print("\n" + prefix + "    }");
+                        }
+                        pw.println();
+                    }
+                }
+                pw.println(prefix + "  }");
+            }
+        }
+
+        @Override
+        public final String toString() {
+            return String.format(
+                    "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d: %s)",
+                    System.identityHashCode(this),
+                    this.sbn.getPackageName(), this.sbn.getUser(), this.sbn.getId(),
+                    this.sbn.getTag(), this.sbn.getScore(), this.sbn.getNotification());
+        }
+    }
+
+    private static final class ToastRecord
+    {
+        final int pid;
+        final String pkg;
+        final ITransientNotification callback;
+        int duration;
+
+        ToastRecord(int pid, String pkg, ITransientNotification callback, int duration)
+        {
+            this.pid = pid;
+            this.pkg = pkg;
+            this.callback = callback;
+            this.duration = duration;
+        }
+
+        void update(int duration) {
+            this.duration = duration;
+        }
+
+        void dump(PrintWriter pw, String prefix) {
+            pw.println(prefix + this);
+        }
+
+        @Override
+        public final String toString()
+        {
+            return "ToastRecord{"
+                + Integer.toHexString(System.identityHashCode(this))
+                + " pkg=" + pkg
+                + " callback=" + callback
+                + " duration=" + duration;
+        }
+    }
+
+    private final NotificationDelegate mNotificationDelegate = new NotificationDelegate() {
+
+        @Override
+        public void onSetDisabled(int status) {
+            synchronized (mNotificationList) {
+                mDisabledNotifications = status;
+                if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
+                    // cancel whatever's going on
+                    long identity = Binder.clearCallingIdentity();
+                    try {
+                        final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
+                        if (player != null) {
+                            player.stopAsync();
+                        }
+                    } catch (RemoteException e) {
+                    } finally {
+                        Binder.restoreCallingIdentity(identity);
+                    }
+
+                    identity = Binder.clearCallingIdentity();
+                    try {
+                        mVibrator.cancel();
+                    } finally {
+                        Binder.restoreCallingIdentity(identity);
+                    }
+                }
+            }
+        }
+
+        @Override
+        public void onClearAll() {
+            // XXX to be totally correct, the caller should tell us which user
+            // this is for.
+            cancelAll(ActivityManager.getCurrentUser());
+        }
+
+        @Override
+        public void onNotificationClick(String pkg, String tag, int id) {
+            // XXX to be totally correct, the caller should tell us which user
+            // this is for.
+            cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
+                    Notification.FLAG_FOREGROUND_SERVICE, false,
+                    ActivityManager.getCurrentUser());
+        }
+
+        @Override
+        public void onNotificationClear(String pkg, String tag, int id) {
+            // XXX to be totally correct, the caller should tell us which user
+            // this is for.
+            cancelNotification(pkg, tag, id, 0,
+                Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
+                true, ActivityManager.getCurrentUser());
+        }
+
+        @Override
+        public void onPanelRevealed() {
+            synchronized (mNotificationList) {
+                // sound
+                mSoundNotification = null;
+
+                long identity = Binder.clearCallingIdentity();
+                try {
+                    final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
+                    if (player != null) {
+                        player.stopAsync();
+                    }
+                } catch (RemoteException e) {
+                } finally {
+                    Binder.restoreCallingIdentity(identity);
+                }
+
+                // vibrate
+                mVibrateNotification = null;
+                identity = Binder.clearCallingIdentity();
+                try {
+                    mVibrator.cancel();
+                } finally {
+                    Binder.restoreCallingIdentity(identity);
+                }
+
+                // light
+                mLights.clear();
+                mLedNotification = null;
+                updateLightsLocked();
+            }
+        }
+
+        @Override
+        public void onNotificationError(String pkg, String tag, int id,
+                int uid, int initialPid, String message) {
+            Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
+                    + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
+            // XXX to be totally correct, the caller should tell us which user
+            // this is for.
+            cancelNotification(pkg, tag, id, 0, 0, false, UserHandle.getUserId(uid));
+            long ident = Binder.clearCallingIdentity();
+            try {
+                ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
+                        "Bad notification posted from package " + pkg
+                        + ": " + message);
+            } catch (RemoteException e) {
+            }
+            Binder.restoreCallingIdentity(ident);
+        }
+    };
+
+    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+
+            boolean queryRestart = false;
+            boolean queryRemove = false;
+            boolean packageChanged = false;
+            boolean cancelNotifications = true;
+            
+            if (action.equals(Intent.ACTION_PACKAGE_ADDED)
+                    || (queryRemove=action.equals(Intent.ACTION_PACKAGE_REMOVED))
+                    || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
+                    || (packageChanged=action.equals(Intent.ACTION_PACKAGE_CHANGED))
+                    || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
+                    || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
+                String pkgList[] = null;
+                boolean queryReplace = queryRemove &&
+                        intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
+                if (DBG) Slog.i(TAG, "queryReplace=" + queryReplace);
+                if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
+                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
+                } else if (queryRestart) {
+                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
+                } else {
+                    Uri uri = intent.getData();
+                    if (uri == null) {
+                        return;
+                    }
+                    String pkgName = uri.getSchemeSpecificPart();
+                    if (pkgName == null) {
+                        return;
+                    }
+                    if (packageChanged) {
+                        // We cancel notifications for packages which have just been disabled
+                        try {
+                            final int enabled = getContext().getPackageManager()
+                                    .getApplicationEnabledSetting(pkgName);
+                            if (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+                                    || enabled == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
+                                cancelNotifications = false;
+                            }
+                        } catch (IllegalArgumentException e) {
+                            // Package doesn't exist; probably racing with uninstall.
+                            // cancelNotifications is already true, so nothing to do here.
+                            if (DBG) {
+                                Slog.i(TAG, "Exception trying to look up app enabled setting", e);
+                            }
+                        }
+                    }
+                    pkgList = new String[]{pkgName};
+                }
+
+                boolean anyListenersInvolved = false;
+                if (pkgList != null && (pkgList.length > 0)) {
+                    for (String pkgName : pkgList) {
+                        if (cancelNotifications) {
+                            cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart,
+                                    UserHandle.USER_ALL);
+                        }
+                        if (mEnabledListenerPackageNames.contains(pkgName)) {
+                            anyListenersInvolved = true;
+                        }
+                    }
+                }
+
+                if (anyListenersInvolved) {
+                    // if we're not replacing a package, clean up orphaned bits
+                    if (!queryReplace) {
+                        disableNonexistentListeners();
+                    }
+                    // make sure we're still bound to any of our
+                    // listeners who may have just upgraded
+                    rebindListenerServices();
+                }
+            } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
+                // Keep track of screen on/off state, but do not turn off the notification light
+                // until user passes through the lock screen or views the notification.
+                mScreenOn = true;
+            } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
+                mScreenOn = false;
+            } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
+                mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
+                        TelephonyManager.EXTRA_STATE_OFFHOOK));
+                updateNotificationPulse();
+            } else if (action.equals(Intent.ACTION_USER_STOPPED)) {
+                int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+                if (userHandle >= 0) {
+                    cancelAllNotificationsInt(null, 0, 0, true, userHandle);
+                }
+            } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
+                // turn off LED when user passes through lock screen
+                mNotificationLight.turnOff();
+            } else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
+                // reload per-user settings
+                mSettingsObserver.update(null);
+            }
+        }
+    };
+
+    class SettingsObserver extends ContentObserver {
+        private final Uri NOTIFICATION_LIGHT_PULSE_URI
+                = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
+
+        private final Uri ENABLED_NOTIFICATION_LISTENERS_URI
+                = Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
+
+        SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        void observe() {
+            ContentResolver resolver = getContext().getContentResolver();
+            resolver.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI,
+                    false, this, UserHandle.USER_ALL);
+            resolver.registerContentObserver(ENABLED_NOTIFICATION_LISTENERS_URI,
+                    false, this, UserHandle.USER_ALL);
+            update(null);
+        }
+
+        @Override public void onChange(boolean selfChange, Uri uri) {
+            update(uri);
+        }
+
+        public void update(Uri uri) {
+            ContentResolver resolver = getContext().getContentResolver();
+            if (uri == null || NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) {
+                boolean pulseEnabled = Settings.System.getInt(resolver,
+                            Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
+                if (mNotificationPulseEnabled != pulseEnabled) {
+                    mNotificationPulseEnabled = pulseEnabled;
+                    updateNotificationPulse();
+                }
+            }
+            if (uri == null || ENABLED_NOTIFICATION_LISTENERS_URI.equals(uri)) {
+                rebindListenerServices();
+            }
+        }
+    }
+
+    private SettingsObserver mSettingsObserver;
+
+    static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) {
+        int[] ar = r.getIntArray(resid);
+        if (ar == null) {
+            return def;
+        }
+        final int len = ar.length > maxlen ? maxlen : ar.length;
+        long[] out = new long[len];
+        for (int i=0; i<len; i++) {
+            out[i] = ar[i];
+        }
+        return out;
+    }
+
+    public NotificationManagerService(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onStart() {
+        mAm = ActivityManagerNative.getDefault();
+        mAppOps = (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE);
+        mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
+
+        mHandler = new WorkerHandler();
+
+        importOldBlockDb();
+
+        mStatusBar = getLocalService(StatusBarManagerInternal.class);
+        mStatusBar.setNotificationDelegate(mNotificationDelegate);
+
+        final LightsManager lights = getLocalService(LightsManager.class);
+        mNotificationLight = lights.getLight(LightsManager.LIGHT_ID_NOTIFICATIONS);
+        mAttentionLight = lights.getLight(LightsManager.LIGHT_ID_ATTENTION);
+
+        Resources resources = getContext().getResources();
+        mDefaultNotificationColor = resources.getColor(
+                R.color.config_defaultNotificationColor);
+        mDefaultNotificationLedOn = resources.getInteger(
+                R.integer.config_defaultNotificationLedOn);
+        mDefaultNotificationLedOff = resources.getInteger(
+                R.integer.config_defaultNotificationLedOff);
+
+        mDefaultVibrationPattern = getLongArray(resources,
+                R.array.config_defaultNotificationVibePattern,
+                VIBRATE_PATTERN_MAXLEN,
+                DEFAULT_VIBRATE_PATTERN);
+
+        mFallbackVibrationPattern = getLongArray(resources,
+                R.array.config_notificationFallbackVibePattern,
+                VIBRATE_PATTERN_MAXLEN,
+                DEFAULT_VIBRATE_PATTERN);
+
+        // Don't start allowing notifications until the setup wizard has run once.
+        // After that, including subsequent boots, init with notifications turned on.
+        // This works on the first boot because the setup wizard will toggle this
+        // flag at least once and we'll go back to 0 after that.
+        if (0 == Settings.Global.getInt(getContext().getContentResolver(),
+                    Settings.Global.DEVICE_PROVISIONED, 0)) {
+            mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
+        }
+
+        // register for various Intents
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_SCREEN_ON);
+        filter.addAction(Intent.ACTION_SCREEN_OFF);
+        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
+        filter.addAction(Intent.ACTION_USER_PRESENT);
+        filter.addAction(Intent.ACTION_USER_STOPPED);
+        filter.addAction(Intent.ACTION_USER_SWITCHED);
+        getContext().registerReceiver(mIntentReceiver, filter);
+        IntentFilter pkgFilter = new IntentFilter();
+        pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
+        pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+        pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+        pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
+        pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
+        pkgFilter.addDataScheme("package");
+        getContext().registerReceiver(mIntentReceiver, pkgFilter);
+        IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+        getContext().registerReceiver(mIntentReceiver, sdFilter);
+
+        mSettingsObserver = new SettingsObserver(mHandler);
+        mSettingsObserver.observe();
+
+        // spin up NotificationScorers
+        String[] notificationScorerNames = resources.getStringArray(
+                R.array.config_notificationScorers);
+        for (String scorerName : notificationScorerNames) {
+            try {
+                Class<?> scorerClass = getContext().getClassLoader().loadClass(scorerName);
+                NotificationScorer scorer = (NotificationScorer) scorerClass.newInstance();
+                scorer.initialize(getContext());
+                mScorers.add(scorer);
+            } catch (ClassNotFoundException e) {
+                Slog.w(TAG, "Couldn't find scorer " + scorerName + ".", e);
+            } catch (InstantiationException e) {
+                Slog.w(TAG, "Couldn't instantiate scorer " + scorerName + ".", e);
+            } catch (IllegalAccessException e) {
+                Slog.w(TAG, "Problem accessing scorer " + scorerName + ".", e);
+            }
+        }
+
+        publishBinderService(Context.NOTIFICATION_SERVICE, mService);
+        publishLocalService(NotificationManagerInternal.class, mInternalService);
+    }
+
+    /**
+     * Read the old XML-based app block database and import those blockages into the AppOps system.
+     */
+    private void importOldBlockDb() {
+        loadBlockDb();
+
+        PackageManager pm = getContext().getPackageManager();
+        for (String pkg : mBlockedPackages) {
+            PackageInfo info = null;
+            try {
+                info = pm.getPackageInfo(pkg, 0);
+                setNotificationsEnabledForPackageImpl(pkg, info.applicationInfo.uid, false);
+            } catch (NameNotFoundException e) {
+                // forget you
+            }
+        }
+        mBlockedPackages.clear();
+        if (mPolicyFile != null) {
+            mPolicyFile.delete();
+        }
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
+            // no beeping until we're basically done booting
+            mSystemReady = true;
+
+            // Grab our optional AudioService
+            mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
+
+            // make sure our listener services are properly bound
+            rebindListenerServices();
+        }
+    }
+
+    void setNotificationsEnabledForPackageImpl(String pkg, int uid, boolean enabled) {
+        Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
+
+        mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
+                enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
+
+        // Now, cancel any outstanding notifications that are part of a just-disabled app
+        if (ENABLE_BLOCKED_NOTIFICATIONS && !enabled) {
+            cancelAllNotificationsInt(pkg, 0, 0, true, UserHandle.getUserId(uid));
+        }
+    }
+
+    private final IBinder mService = new INotificationManager.Stub() {
+        // Toasts
+        // ============================================================================
+
+        @Override
+        public void enqueueToast(String pkg, ITransientNotification callback, int duration)
+        {
+            if (DBG) {
+                Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback
+                        + " duration=" + duration);
+            }
+
+            if (pkg == null || callback == null) {
+                Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback);
+                return ;
+            }
+
+            final boolean isSystemToast = isCallerSystem() || ("android".equals(pkg));
+
+            if (ENABLE_BLOCKED_TOASTS && !noteNotificationOp(pkg, Binder.getCallingUid())) {
+                if (!isSystemToast) {
+                    Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request.");
+                    return;
+                }
+            }
+
+            synchronized (mToastQueue) {
+                int callingPid = Binder.getCallingPid();
+                long callingId = Binder.clearCallingIdentity();
+                try {
+                    ToastRecord record;
+                    int index = indexOfToastLocked(pkg, callback);
+                    // If it's already in the queue, we update it in place, we don't
+                    // move it to the end of the queue.
+                    if (index >= 0) {
+                        record = mToastQueue.get(index);
+                        record.update(duration);
+                    } else {
+                        // Limit the number of toasts that any given package except the android
+                        // package can enqueue.  Prevents DOS attacks and deals with leaks.
+                        if (!isSystemToast) {
+                            int count = 0;
+                            final int N = mToastQueue.size();
+                            for (int i=0; i<N; i++) {
+                                 final ToastRecord r = mToastQueue.get(i);
+                                 if (r.pkg.equals(pkg)) {
+                                     count++;
+                                     if (count >= MAX_PACKAGE_NOTIFICATIONS) {
+                                         Slog.e(TAG, "Package has already posted " + count
+                                                + " toasts. Not showing more. Package=" + pkg);
+                                         return;
+                                     }
+                                 }
+                            }
+                        }
+
+                        record = new ToastRecord(callingPid, pkg, callback, duration);
+                        mToastQueue.add(record);
+                        index = mToastQueue.size() - 1;
+                        keepProcessAliveLocked(callingPid);
+                    }
+                    // If it's at index 0, it's the current toast.  It doesn't matter if it's
+                    // new or just been updated.  Call back and tell it to show itself.
+                    // If the callback fails, this will remove it from the list, so don't
+                    // assume that it's valid after this.
+                    if (index == 0) {
+                        showNextToastLocked();
+                    }
+                } finally {
+                    Binder.restoreCallingIdentity(callingId);
+                }
+            }
+        }
+
+        @Override
+        public void cancelToast(String pkg, ITransientNotification callback) {
+            Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
+
+            if (pkg == null || callback == null) {
+                Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback);
+                return ;
+            }
+
+            synchronized (mToastQueue) {
+                long callingId = Binder.clearCallingIdentity();
+                try {
+                    int index = indexOfToastLocked(pkg, callback);
+                    if (index >= 0) {
+                        cancelToastLocked(index);
+                    } else {
+                        Slog.w(TAG, "Toast already cancelled. pkg=" + pkg
+                                + " callback=" + callback);
+                    }
+                } finally {
+                    Binder.restoreCallingIdentity(callingId);
+                }
+            }
+        }
+
+        @Override
+        public void enqueueNotificationWithTag(String pkg, String basePkg, String tag, int id,
+                Notification notification, int[] idOut, int userId) throws RemoteException {
+            enqueueNotificationInternal(pkg, basePkg, Binder.getCallingUid(),
+                    Binder.getCallingPid(), tag, id, notification, idOut, userId);
+        }
+
+        @Override
+        public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) {
+            checkCallerIsSystemOrSameApp(pkg);
+            userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
+                    Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg);
+            // Don't allow client applications to cancel foreground service notis.
+            cancelNotification(pkg, tag, id, 0,
+                    Binder.getCallingUid() == Process.SYSTEM_UID
+                    ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false, userId);
+        }
+
+        @Override
+        public void cancelAllNotifications(String pkg, int userId) {
+            checkCallerIsSystemOrSameApp(pkg);
+
+            userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
+                    Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg);
+
+            // Calling from user space, don't allow the canceling of actively
+            // running foreground services.
+            cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId);
+        }
+
+        @Override
+        public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
+            checkCallerIsSystem();
+
+            setNotificationsEnabledForPackageImpl(pkg, uid, enabled);
+        }
+
+        /**
+         * Use this when you just want to know if notifications are OK for this package.
+         */
+        @Override
+        public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
+            checkCallerIsSystem();
+            return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
+                    == AppOpsManager.MODE_ALLOWED);
+        }
+
+        /**
+         * System-only API for getting a list of current (i.e. not cleared) notifications.
+         *
+         * Requires ACCESS_NOTIFICATIONS which is signature|system.
+         */
+        @Override
+        public StatusBarNotification[] getActiveNotifications(String callingPkg) {
+            // enforce() will ensure the calling uid has the correct permission
+            getContext().enforceCallingOrSelfPermission(
+                    android.Manifest.permission.ACCESS_NOTIFICATIONS,
+                    "NotificationManagerService.getActiveNotifications");
+
+            StatusBarNotification[] tmp = null;
+            int uid = Binder.getCallingUid();
+
+            // noteOp will check to make sure the callingPkg matches the uid
+            if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
+                    == AppOpsManager.MODE_ALLOWED) {
+                synchronized (mNotificationList) {
+                    tmp = new StatusBarNotification[mNotificationList.size()];
+                    final int N = mNotificationList.size();
+                    for (int i=0; i<N; i++) {
+                        tmp[i] = mNotificationList.get(i).sbn;
+                    }
+                }
+            }
+            return tmp;
+        }
+
+        /**
+         * System-only API for getting a list of recent (cleared, no longer shown) notifications.
+         *
+         * Requires ACCESS_NOTIFICATIONS which is signature|system.
+         */
+        @Override
+        public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) {
+            // enforce() will ensure the calling uid has the correct permission
+            getContext().enforceCallingOrSelfPermission(
+                    android.Manifest.permission.ACCESS_NOTIFICATIONS,
+                    "NotificationManagerService.getHistoricalNotifications");
+
+            StatusBarNotification[] tmp = null;
+            int uid = Binder.getCallingUid();
+
+            // noteOp will check to make sure the callingPkg matches the uid
+            if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
+                    == AppOpsManager.MODE_ALLOWED) {
+                synchronized (mArchive) {
+                    tmp = mArchive.getArray(count);
+                }
+            }
+            return tmp;
+        }
+
+        /**
+         * Register a listener binder directly with the notification manager.
+         *
+         * Only works with system callers. Apps should extend
+         * {@link android.service.notification.NotificationListenerService}.
+         */
+        @Override
+        public void registerListener(final INotificationListener listener,
+                final ComponentName component, final int userid) {
+            checkCallerIsSystem();
+            checkNullListener(listener);
+            registerListenerImpl(listener, component, userid);
+        }
+
+        /**
+         * Remove a listener binder directly
+         */
+        @Override
+        public void unregisterListener(INotificationListener listener, int userid) {
+            checkNullListener(listener);
+            // no need to check permissions; if your listener binder is in the list,
+            // that's proof that you had permission to add it in the first place
+            unregisterListenerImpl(listener, userid);
+        }
+
+        /**
+         * Allow an INotificationListener to simulate a "clear all" operation.
+         *
+         * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onClearAllNotifications}
+         *
+         * @param token The binder for the listener, to check that the caller is allowed
+         */
+        @Override
+        public void cancelAllNotificationsFromListener(INotificationListener token) {
+            NotificationListenerInfo info = checkListenerToken(token);
+            long identity = Binder.clearCallingIdentity();
+            try {
+                cancelAll(info.userid);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        /**
+         * Allow an INotificationListener to simulate clearing (dismissing) a single notification.
+         *
+         * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onNotificationClear}
+         *
+         * @param token The binder for the listener, to check that the caller is allowed
+         */
+        @Override
+        public void cancelNotificationFromListener(INotificationListener token, String pkg,
+                String tag, int id) {
+            NotificationListenerInfo info = checkListenerToken(token);
+            long identity = Binder.clearCallingIdentity();
+            try {
+                cancelNotification(pkg, tag, id, 0,
+                        Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
+                        true,
+                        info.userid);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        /**
+         * Allow an INotificationListener to request the list of outstanding notifications seen by
+         * the current user. Useful when starting up, after which point the listener callbacks
+         * should be used.
+         *
+         * @param token The binder for the listener, to check that the caller is allowed
+         */
+        @Override
+        public StatusBarNotification[] getActiveNotificationsFromListener(
+                INotificationListener token) {
+            NotificationListenerInfo info = checkListenerToken(token);
+
+            StatusBarNotification[] result = new StatusBarNotification[0];
+            ArrayList<StatusBarNotification> list = new ArrayList<StatusBarNotification>();
+            synchronized (mNotificationList) {
+                final int N = mNotificationList.size();
+                for (int i=0; i<N; i++) {
+                    StatusBarNotification sbn = mNotificationList.get(i).sbn;
+                    if (info.enabledAndUserMatches(sbn)) {
+                        list.add(sbn);
+                    }
+                }
+            }
+            return list.toArray(result);
+        }
+
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump NotificationManager from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            dumpImpl(pw);
+        }
+    };
+
+    void dumpImpl(PrintWriter pw) {
+        pw.println("Current Notification Manager state:");
+
+        pw.println("  Listeners (" + mEnabledListenersForCurrentUser.size()
+                + ") enabled for current user:");
+        for (ComponentName cmpt : mEnabledListenersForCurrentUser) {
+            pw.println("    " + cmpt);
+        }
+
+        pw.println("  Live listeners (" + mListeners.size() + "):");
+        for (NotificationListenerInfo info : mListeners) {
+            pw.println("    " + info.component
+                    + " (user " + info.userid + "): " + info.listener
+                    + (info.isSystem?" SYSTEM":""));
+        }
+
+        int N;
+
+        synchronized (mToastQueue) {
+            N = mToastQueue.size();
+            if (N > 0) {
+                pw.println("  Toast Queue:");
+                for (int i=0; i<N; i++) {
+                    mToastQueue.get(i).dump(pw, "    ");
+                }
+                pw.println("  ");
+            }
+
+        }
+
+        synchronized (mNotificationList) {
+            N = mNotificationList.size();
+            if (N > 0) {
+                pw.println("  Notification List:");
+                for (int i=0; i<N; i++) {
+                    mNotificationList.get(i).dump(pw, "    ", getContext());
+                }
+                pw.println("  ");
+            }
+
+            N = mLights.size();
+            if (N > 0) {
+                pw.println("  Lights List:");
+                for (int i=0; i<N; i++) {
+                    pw.println("    " + mLights.get(i));
+                }
+                pw.println("  ");
+            }
+
+            pw.println("  mSoundNotification=" + mSoundNotification);
+            pw.println("  mVibrateNotification=" + mVibrateNotification);
+            pw.println("  mDisabledNotifications=0x"
+                    + Integer.toHexString(mDisabledNotifications));
+            pw.println("  mSystemReady=" + mSystemReady);
+            pw.println("  mArchive=" + mArchive.toString());
+            Iterator<StatusBarNotification> iter = mArchive.descendingIterator();
+            int i=0;
+            while (iter.hasNext()) {
+                pw.println("    " + iter.next());
+                if (++i >= 5) {
+                    if (iter.hasNext()) pw.println("    ...");
+                    break;
+                }
+            }
+
+        }
+    }
+
+    /**
+     * The private API only accessible to the system process.
+     */
+    private final NotificationManagerInternal mInternalService = new NotificationManagerInternal() {
+        @Override
+        public void enqueueNotification(String pkg, String basePkg, int callingUid, int callingPid,
+                String tag, int id, Notification notification, int[] idReceived, int userId) {
+            enqueueNotificationInternal(pkg, basePkg, callingUid, callingPid, tag, id, notification,
+                    idReceived, userId);
+        }
+    };
+
+    void enqueueNotificationInternal(final String pkg, String basePkg, final int callingUid,
+            final int callingPid, final String tag, final int id, final Notification notification,
+            int[] idOut, int incomingUserId) {
+        if (DBG) {
+            Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id
+                    + " notification=" + notification);
+        }
+        checkCallerIsSystemOrSameApp(pkg);
+        final boolean isSystemNotification = isUidSystem(callingUid) || ("android".equals(pkg));
+
+        final int userId = ActivityManager.handleIncomingUser(callingPid,
+                callingUid, incomingUserId, true, false, "enqueueNotification", pkg);
+        final UserHandle user = new UserHandle(userId);
+
+        // Limit the number of notifications that any given package except the android
+        // package can enqueue.  Prevents DOS attacks and deals with leaks.
+        if (!isSystemNotification) {
+            synchronized (mNotificationList) {
+                int count = 0;
+                final int N = mNotificationList.size();
+                for (int i=0; i<N; i++) {
+                    final NotificationRecord r = mNotificationList.get(i);
+                    if (r.sbn.getPackageName().equals(pkg) && r.sbn.getUserId() == userId) {
+                        count++;
+                        if (count >= MAX_PACKAGE_NOTIFICATIONS) {
+                            Slog.e(TAG, "Package has already posted " + count
+                                    + " notifications.  Not showing more.  package=" + pkg);
+                            return;
+                        }
+                    }
+                }
+            }
+        }
+
+        // This conditional is a dirty hack to limit the logging done on
+        //     behalf of the download manager without affecting other apps.
+        if (!pkg.equals("com.android.providers.downloads")
+                || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
+            EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId,
+                    notification.toString());
+        }
+
+        if (pkg == null || notification == null) {
+            throw new IllegalArgumentException("null not allowed: pkg=" + pkg
+                    + " id=" + id + " notification=" + notification);
+        }
+        if (notification.icon != 0) {
+            if (notification.contentView == null) {
+                throw new IllegalArgumentException("contentView required: pkg=" + pkg
+                        + " id=" + id + " notification=" + notification);
+            }
+        }
+
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+
+                // === Scoring ===
+
+                // 0. Sanitize inputs
+                notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN,
+                        Notification.PRIORITY_MAX);
+                // Migrate notification flags to scores
+                if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
+                    if (notification.priority < Notification.PRIORITY_MAX) {
+                        notification.priority = Notification.PRIORITY_MAX;
+                    }
+                } else if (SCORE_ONGOING_HIGHER &&
+                        0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
+                    if (notification.priority < Notification.PRIORITY_HIGH) {
+                        notification.priority = Notification.PRIORITY_HIGH;
+                    }
+                }
+
+                // 1. initial score: buckets of 10, around the app
+                int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20]
+
+                // 2. Consult external heuristics (TBD)
+
+                // 3. Apply local rules
+
+                int initialScore = score;
+                if (!mScorers.isEmpty()) {
+                    if (DBG) Slog.v(TAG, "Initial score is " + score + ".");
+                    for (NotificationScorer scorer : mScorers) {
+                        try {
+                            score = scorer.getScore(notification, score);
+                        } catch (Throwable t) {
+                            Slog.w(TAG, "Scorer threw on .getScore.", t);
+                        }
+                    }
+                    if (DBG) Slog.v(TAG, "Final score is " + score + ".");
+                }
+
+                // add extra to indicate score modified by NotificationScorer
+                notification.extras.putBoolean(Notification.EXTRA_SCORE_MODIFIED,
+                        score != initialScore);
+
+                // blocked apps
+                if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
+                    if (!isSystemNotification) {
+                        score = JUNK_SCORE;
+                        Slog.e(TAG, "Suppressing notification from package " + pkg
+                                + " by user request.");
+                    }
+                }
+
+                if (DBG) {
+                    Slog.v(TAG, "Assigned score=" + score + " to " + notification);
+                }
+
+                if (score < SCORE_DISPLAY_THRESHOLD) {
+                    // Notification will be blocked because the score is too low.
+                    return;
+                }
+
+                // Should this notification make noise, vibe, or use the LED?
+                final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD);
+
+                synchronized (mNotificationList) {
+                    final StatusBarNotification n = new StatusBarNotification(
+                            pkg, id, tag, callingUid, callingPid, score, notification, user);
+                    NotificationRecord r = new NotificationRecord(n);
+                    NotificationRecord old = null;
+
+                    int index = indexOfNotificationLocked(pkg, tag, id, userId);
+                    if (index < 0) {
+                        mNotificationList.add(r);
+                    } else {
+                        old = mNotificationList.remove(index);
+                        mNotificationList.add(index, r);
+                        // Make sure we don't lose the foreground service state.
+                        if (old != null) {
+                            notification.flags |=
+                                old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE;
+                        }
+                    }
+
+                    // Ensure if this is a foreground service that the proper additional
+                    // flags are set.
+                    if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) {
+                        notification.flags |= Notification.FLAG_ONGOING_EVENT
+                                | Notification.FLAG_NO_CLEAR;
+                    }
+
+                    final int currentUser;
+                    final long token = Binder.clearCallingIdentity();
+                    try {
+                        currentUser = ActivityManager.getCurrentUser();
+                    } finally {
+                        Binder.restoreCallingIdentity(token);
+                    }
+
+                    if (notification.icon != 0) {
+                        if (old != null && old.statusBarKey != null) {
+                            r.statusBarKey = old.statusBarKey;
+                            final long identity = Binder.clearCallingIdentity();
+                            try {
+                                mStatusBar.updateNotification(r.statusBarKey, n);
+                            } finally {
+                                Binder.restoreCallingIdentity(identity);
+                            }
+                        } else {
+                            final long identity = Binder.clearCallingIdentity();
+                            try {
+                                r.statusBarKey = mStatusBar.addNotification(n);
+                                if ((n.getNotification().flags & Notification.FLAG_SHOW_LIGHTS) != 0
+                                        && canInterrupt) {
+                                    mAttentionLight.pulse();
+                                }
+                            } finally {
+                                Binder.restoreCallingIdentity(identity);
+                            }
+                        }
+                        // Send accessibility events only for the current user.
+                        if (currentUser == userId) {
+                            sendAccessibilityEvent(notification, pkg);
+                        }
+
+                        notifyPostedLocked(r);
+                    } else {
+                        Slog.e(TAG, "Not posting notification with icon==0: " + notification);
+                        if (old != null && old.statusBarKey != null) {
+                            final long identity = Binder.clearCallingIdentity();
+                            try {
+                                mStatusBar.removeNotification(old.statusBarKey);
+                            } finally {
+                                Binder.restoreCallingIdentity(identity);
+                            }
+
+                            notifyRemovedLocked(r);
+                        }
+                        // ATTENTION: in a future release we will bail out here
+                        // so that we do not play sounds, show lights, etc. for invalid
+                        // notifications
+                        Slog.e(TAG, "WARNING: In a future release this will crash the app: "
+                                + n.getPackageName());
+                    }
+
+                    // If we're not supposed to beep, vibrate, etc. then don't.
+                    if (((mDisabledNotifications
+                            & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0)
+                            && (!(old != null
+                                && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
+                            && (r.getUserId() == UserHandle.USER_ALL ||
+                                (r.getUserId() == userId && r.getUserId() == currentUser))
+                            && canInterrupt
+                            && mSystemReady
+                            && mAudioManager != null) {
+
+                        // sound
+
+                        // should we use the default notification sound? (indicated either by
+                        // DEFAULT_SOUND or because notification.sound is pointing at
+                        // Settings.System.NOTIFICATION_SOUND)
+                        final boolean useDefaultSound =
+                               (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
+                                       Settings.System.DEFAULT_NOTIFICATION_URI
+                                               .equals(notification.sound);
+
+                        Uri soundUri = null;
+                        boolean hasValidSound = false;
+
+                        if (useDefaultSound) {
+                            soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
+
+                            // check to see if the default notification sound is silent
+                            ContentResolver resolver = getContext().getContentResolver();
+                            hasValidSound = Settings.System.getString(resolver,
+                                   Settings.System.NOTIFICATION_SOUND) != null;
+                        } else if (notification.sound != null) {
+                            soundUri = notification.sound;
+                            hasValidSound = (soundUri != null);
+                        }
+
+                        if (hasValidSound) {
+                            boolean looping =
+                                    (notification.flags & Notification.FLAG_INSISTENT) != 0;
+                            int audioStreamType;
+                            if (notification.audioStreamType >= 0) {
+                                audioStreamType = notification.audioStreamType;
+                            } else {
+                                audioStreamType = DEFAULT_STREAM_TYPE;
+                            }
+                            mSoundNotification = r;
+                            // do not play notifications if stream volume is 0 (typically because
+                            // ringer mode is silent) or if there is a user of exclusive audio focus
+                            if ((mAudioManager.getStreamVolume(audioStreamType) != 0)
+                                    && !mAudioManager.isAudioFocusExclusive()) {
+                                final long identity = Binder.clearCallingIdentity();
+                                try {
+                                    final IRingtonePlayer player =
+                                            mAudioManager.getRingtonePlayer();
+                                    if (player != null) {
+                                        player.playAsync(soundUri, user, looping, audioStreamType);
+                                    }
+                                } catch (RemoteException e) {
+                                } finally {
+                                    Binder.restoreCallingIdentity(identity);
+                                }
+                            }
+                        }
+
+                        // vibrate
+                        // Does the notification want to specify its own vibration?
+                        final boolean hasCustomVibrate = notification.vibrate != null;
+
+                        // new in 4.2: if there was supposed to be a sound and we're in vibrate
+                        // mode, and no other vibration is specified, we fall back to vibration
+                        final boolean convertSoundToVibration =
+                                   !hasCustomVibrate
+                                && hasValidSound
+                                && (mAudioManager.getRingerMode()
+                                           == AudioManager.RINGER_MODE_VIBRATE);
+
+                        // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
+                        final boolean useDefaultVibrate =
+                                (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
+
+                        if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate)
+                                && !(mAudioManager.getRingerMode()
+                                        == AudioManager.RINGER_MODE_SILENT)) {
+                            mVibrateNotification = r;
+
+                            if (useDefaultVibrate || convertSoundToVibration) {
+                                // Escalate privileges so we can use the vibrator even if the
+                                // notifying app does not have the VIBRATE permission.
+                                long identity = Binder.clearCallingIdentity();
+                                try {
+                                    mVibrator.vibrate(r.sbn.getUid(), r.sbn.getBasePkg(),
+                                        useDefaultVibrate ? mDefaultVibrationPattern
+                                            : mFallbackVibrationPattern,
+                                        ((notification.flags & Notification.FLAG_INSISTENT) != 0)
+                                                ? 0: -1);
+                                } finally {
+                                    Binder.restoreCallingIdentity(identity);
+                                }
+                            } else if (notification.vibrate.length > 1) {
+                                // If you want your own vibration pattern, you need the VIBRATE
+                                // permission
+                                mVibrator.vibrate(r.sbn.getUid(), r.sbn.getBasePkg(),
+                                        notification.vibrate,
+                                    ((notification.flags & Notification.FLAG_INSISTENT) != 0)
+                                            ? 0: -1);
+                            }
+                        }
+                    }
+
+                    // light
+                    // the most recent thing gets the light
+                    mLights.remove(old);
+                    if (mLedNotification == old) {
+                        mLedNotification = null;
+                    }
+                    //Slog.i(TAG, "notification.lights="
+                    //        + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS)
+                    //                  != 0));
+                    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
+                            && canInterrupt) {
+                        mLights.add(r);
+                        updateLightsLocked();
+                    } else {
+                        if (old != null
+                                && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
+                            updateLightsLocked();
+                        }
+                    }
+                }
+            }
+        });
+
+        idOut[0] = id;
+    }
+
+     void registerListenerImpl(final INotificationListener listener,
+            final ComponentName component, final int userid) {
+        synchronized (mNotificationList) {
+            try {
+                NotificationListenerInfo info
+                        = new NotificationListenerInfo(listener, component, userid, true);
+                listener.asBinder().linkToDeath(info, 0);
+                mListeners.add(info);
+            } catch (RemoteException e) {
+                // already dead
+            }
+        }
+    }
+
+    /**
+     * Removes a listener from the list and unbinds from its service.
+     */
+    void unregisterListenerImpl(final INotificationListener listener, final int userid) {
+        NotificationListenerInfo info = removeListenerImpl(listener, userid);
+        if (info != null && info.connection != null) {
+            getContext().unbindService(info.connection);
+        }
+    }
+
+    /**
+     * Removes a listener from the list but does not unbind from the listener's service.
+     *
+     * @return the removed listener.
+     */
+    NotificationListenerInfo removeListenerImpl(
+            final INotificationListener listener, final int userid) {
+        NotificationListenerInfo listenerInfo = null;
+        synchronized (mNotificationList) {
+            final int N = mListeners.size();
+            for (int i=N-1; i>=0; i--) {
+                final NotificationListenerInfo info = mListeners.get(i);
+                if (info.listener.asBinder() == listener.asBinder()
+                        && info.userid == userid) {
+                    listenerInfo = mListeners.remove(i);
+                }
+            }
+        }
+        return listenerInfo;
+    }
+
+    void showNextToastLocked() {
+        ToastRecord record = mToastQueue.get(0);
+        while (record != null) {
+            if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback);
+            try {
+                record.callback.show();
+                scheduleTimeoutLocked(record);
+                return;
+            } catch (RemoteException e) {
+                Slog.w(TAG, "Object died trying to show notification " + record.callback
+                        + " in package " + record.pkg);
+                // remove it from the list and let the process die
+                int index = mToastQueue.indexOf(record);
+                if (index >= 0) {
+                    mToastQueue.remove(index);
+                }
+                keepProcessAliveLocked(record.pid);
+                if (mToastQueue.size() > 0) {
+                    record = mToastQueue.get(0);
+                } else {
+                    record = null;
+                }
+            }
+        }
+    }
+
+    void cancelToastLocked(int index) {
+        ToastRecord record = mToastQueue.get(index);
+        try {
+            record.callback.hide();
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Object died trying to hide notification " + record.callback
+                    + " in package " + record.pkg);
+            // don't worry about this, we're about to remove it from
+            // the list anyway
+        }
+        mToastQueue.remove(index);
+        keepProcessAliveLocked(record.pid);
+        if (mToastQueue.size() > 0) {
+            // Show the next one. If the callback fails, this will remove
+            // it from the list, so don't assume that the list hasn't changed
+            // after this point.
+            showNextToastLocked();
+        }
+    }
+
+    private void scheduleTimeoutLocked(ToastRecord r)
+    {
+        mHandler.removeCallbacksAndMessages(r);
+        Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
+        long delay = r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY;
+        mHandler.sendMessageDelayed(m, delay);
+    }
+
+    private void handleTimeout(ToastRecord record)
+    {
+        if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback);
+        synchronized (mToastQueue) {
+            int index = indexOfToastLocked(record.pkg, record.callback);
+            if (index >= 0) {
+                cancelToastLocked(index);
+            }
+        }
+    }
+
+    // lock on mToastQueue
+    int indexOfToastLocked(String pkg, ITransientNotification callback)
+    {
+        IBinder cbak = callback.asBinder();
+        ArrayList<ToastRecord> list = mToastQueue;
+        int len = list.size();
+        for (int i=0; i<len; i++) {
+            ToastRecord r = list.get(i);
+            if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    // lock on mToastQueue
+    void keepProcessAliveLocked(int pid)
+    {
+        int toastCount = 0; // toasts from this pid
+        ArrayList<ToastRecord> list = mToastQueue;
+        int N = list.size();
+        for (int i=0; i<N; i++) {
+            ToastRecord r = list.get(i);
+            if (r.pid == pid) {
+                toastCount++;
+            }
+        }
+        try {
+            mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0);
+        } catch (RemoteException e) {
+            // Shouldn't happen.
+        }
+    }
+
+    private final class WorkerHandler extends Handler
+    {
+        @Override
+        public void handleMessage(Message msg)
+        {
+            switch (msg.what)
+            {
+                case MESSAGE_TIMEOUT:
+                    handleTimeout((ToastRecord)msg.obj);
+                    break;
+            }
+        }
+    }
+
+
+    // Notifications
+    // ============================================================================
+    static int clamp(int x, int low, int high) {
+        return (x < low) ? low : ((x > high) ? high : x);
+    }
+
+    void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
+        AccessibilityManager manager = AccessibilityManager.getInstance(getContext());
+        if (!manager.isEnabled()) {
+            return;
+        }
+
+        AccessibilityEvent event =
+            AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
+        event.setPackageName(packageName);
+        event.setClassName(Notification.class.getName());
+        event.setParcelableData(notification);
+        CharSequence tickerText = notification.tickerText;
+        if (!TextUtils.isEmpty(tickerText)) {
+            event.getText().add(tickerText);
+        }
+
+        manager.sendAccessibilityEvent(event);
+    }
+
+    private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
+        // tell the app
+        if (sendDelete) {
+            if (r.getNotification().deleteIntent != null) {
+                try {
+                    r.getNotification().deleteIntent.send();
+                } catch (PendingIntent.CanceledException ex) {
+                    // do nothing - there's no relevant way to recover, and
+                    //     no reason to let this propagate
+                    Slog.w(TAG, "canceled PendingIntent for " + r.sbn.getPackageName(), ex);
+                }
+            }
+        }
+
+        // status bar
+        if (r.getNotification().icon != 0) {
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                mStatusBar.removeNotification(r.statusBarKey);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+            r.statusBarKey = null;
+            notifyRemovedLocked(r);
+        }
+
+        // sound
+        if (mSoundNotification == r) {
+            mSoundNotification = null;
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                final IRingtonePlayer player = mAudioManager.getRingtonePlayer();
+                if (player != null) {
+                    player.stopAsync();
+                }
+            } catch (RemoteException e) {
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        // vibrate
+        if (mVibrateNotification == r) {
+            mVibrateNotification = null;
+            long identity = Binder.clearCallingIdentity();
+            try {
+                mVibrator.cancel();
+            }
+            finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        // light
+        mLights.remove(r);
+        if (mLedNotification == r) {
+            mLedNotification = null;
+        }
+
+        // Save it for users of getHistoricalNotifications()
+        mArchive.record(r.sbn);
+    }
+
+    /**
+     * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
+     * and none of the {@code mustNotHaveFlags}.
+     */
+    void cancelNotification(final String pkg, final String tag, final int id,
+            final int mustHaveFlags, final int mustNotHaveFlags, final boolean sendDelete,
+            final int userId) {
+        // In enqueueNotificationInternal notifications are added by scheduling the
+        // work on the worker handler. Hence, we also schedule the cancel on this
+        // handler to avoid a scenario where an add notification call followed by a
+        // remove notification call ends up in not removing the notification.
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId,
+                        mustHaveFlags, mustNotHaveFlags);
+
+                synchronized (mNotificationList) {
+                    int index = indexOfNotificationLocked(pkg, tag, id, userId);
+                    if (index >= 0) {
+                        NotificationRecord r = mNotificationList.get(index);
+
+                        if ((r.getNotification().flags & mustHaveFlags) != mustHaveFlags) {
+                            return;
+                        }
+                        if ((r.getNotification().flags & mustNotHaveFlags) != 0) {
+                            return;
+                        }
+
+                        mNotificationList.remove(index);
+
+                        cancelNotificationLocked(r, sendDelete);
+                        updateLightsLocked();
+                    }
+                }
+            }
+        });
+    }
+
+    /**
+     * Determine whether the userId applies to the notification in question, either because
+     * they match exactly, or one of them is USER_ALL (which is treated as a wildcard).
+     */
+    private boolean notificationMatchesUserId(NotificationRecord r, int userId) {
+        return
+                // looking for USER_ALL notifications? match everything
+                   userId == UserHandle.USER_ALL
+                // a notification sent to USER_ALL matches any query
+                || r.getUserId() == UserHandle.USER_ALL
+                // an exact user match
+                || r.getUserId() == userId;
+    }
+
+    /**
+     * Cancels all notifications from a given package that have all of the
+     * {@code mustHaveFlags}.
+     */
+    boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
+            int mustNotHaveFlags, boolean doit, int userId) {
+        EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId,
+                mustHaveFlags, mustNotHaveFlags);
+
+        synchronized (mNotificationList) {
+            final int N = mNotificationList.size();
+            boolean canceledSomething = false;
+            for (int i = N-1; i >= 0; --i) {
+                NotificationRecord r = mNotificationList.get(i);
+                if (!notificationMatchesUserId(r, userId)) {
+                    continue;
+                }
+                // Don't remove notifications to all, if there's no package name specified
+                if (r.getUserId() == UserHandle.USER_ALL && pkg == null) {
+                    continue;
+                }
+                if ((r.getFlags() & mustHaveFlags) != mustHaveFlags) {
+                    continue;
+                }
+                if ((r.getFlags() & mustNotHaveFlags) != 0) {
+                    continue;
+                }
+                if (pkg != null && !r.sbn.getPackageName().equals(pkg)) {
+                    continue;
+                }
+                canceledSomething = true;
+                if (!doit) {
+                    return true;
+                }
+                mNotificationList.remove(i);
+                cancelNotificationLocked(r, false);
+            }
+            if (canceledSomething) {
+                updateLightsLocked();
+            }
+            return canceledSomething;
+        }
+    }
+
+
+
+    // Return true if the UID is a system or phone UID and therefore should not have
+    // any notifications or toasts blocked.
+    boolean isUidSystem(int uid) {
+        final int appid = UserHandle.getAppId(uid);
+        return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID || uid == 0);
+    }
+
+    // same as isUidSystem(int, int) for the Binder caller's UID.
+    boolean isCallerSystem() {
+        return isUidSystem(Binder.getCallingUid());
+    }
+
+    void checkCallerIsSystem() {
+        if (isCallerSystem()) {
+            return;
+        }
+        throw new SecurityException("Disallowed call for uid " + Binder.getCallingUid());
+    }
+
+    void checkCallerIsSystemOrSameApp(String pkg) {
+        if (isCallerSystem()) {
+            return;
+        }
+        final int uid = Binder.getCallingUid();
+        try {
+            ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo(
+                    pkg, 0, UserHandle.getCallingUserId());
+            if (!UserHandle.isSameApp(ai.uid, uid)) {
+                throw new SecurityException("Calling uid " + uid + " gave package"
+                        + pkg + " which is owned by uid " + ai.uid);
+            }
+        } catch (RemoteException re) {
+            throw new SecurityException("Unknown package " + pkg + "\n" + re);
+        }
+    }
+
+    void cancelAll(int userId) {
+        synchronized (mNotificationList) {
+            final int N = mNotificationList.size();
+            for (int i=N-1; i>=0; i--) {
+                NotificationRecord r = mNotificationList.get(i);
+
+                if (!notificationMatchesUserId(r, userId)) {
+                    continue;
+                }
+
+                if ((r.getFlags() & (Notification.FLAG_ONGOING_EVENT
+                                | Notification.FLAG_NO_CLEAR)) == 0) {
+                    mNotificationList.remove(i);
+                    cancelNotificationLocked(r, true);
+                }
+            }
+
+            updateLightsLocked();
+        }
+    }
+
+    // lock on mNotificationList
+    void updateLightsLocked()
+    {
+        // handle notification lights
+        if (mLedNotification == null) {
+            // get next notification, if any
+            int n = mLights.size();
+            if (n > 0) {
+                mLedNotification = mLights.get(n-1);
+            }
+        }
+
+        // Don't flash while we are in a call or screen is on
+        if (mLedNotification == null || mInCall || mScreenOn) {
+            mNotificationLight.turnOff();
+        } else {
+            final Notification ledno = mLedNotification.sbn.getNotification();
+            int ledARGB = ledno.ledARGB;
+            int ledOnMS = ledno.ledOnMS;
+            int ledOffMS = ledno.ledOffMS;
+            if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
+                ledARGB = mDefaultNotificationColor;
+                ledOnMS = mDefaultNotificationLedOn;
+                ledOffMS = mDefaultNotificationLedOff;
+            }
+            if (mNotificationPulseEnabled) {
+                // pulse repeatedly
+                mNotificationLight.setFlashing(ledARGB, Light.LIGHT_FLASH_TIMED,
+                        ledOnMS, ledOffMS);
+            }
+        }
+    }
+
+    // lock on mNotificationList
+    int indexOfNotificationLocked(String pkg, String tag, int id, int userId)
+    {
+        ArrayList<NotificationRecord> list = mNotificationList;
+        final int len = list.size();
+        for (int i=0; i<len; i++) {
+            NotificationRecord r = list.get(i);
+            if (!notificationMatchesUserId(r, userId) || r.sbn.getId() != id) {
+                continue;
+            }
+            if (tag == null) {
+                if (r.sbn.getTag() != null) {
+                    continue;
+                }
+            } else {
+                if (!tag.equals(r.sbn.getTag())) {
+                    continue;
+                }
+            }
+            if (r.sbn.getPackageName().equals(pkg)) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private void updateNotificationPulse() {
+        synchronized (mNotificationList) {
+            updateLightsLocked();
+        }
+    }
+}
diff --git a/services/java/com/android/server/os/SchedulingPolicyService.java b/services/core/java/com/android/server/os/SchedulingPolicyService.java
similarity index 100%
rename from services/java/com/android/server/os/SchedulingPolicyService.java
rename to services/core/java/com/android/server/os/SchedulingPolicyService.java
diff --git a/services/java/com/android/server/pm/BasePermission.java b/services/core/java/com/android/server/pm/BasePermission.java
similarity index 100%
rename from services/java/com/android/server/pm/BasePermission.java
rename to services/core/java/com/android/server/pm/BasePermission.java
diff --git a/services/java/com/android/server/pm/GrantedPermissions.java b/services/core/java/com/android/server/pm/GrantedPermissions.java
similarity index 100%
rename from services/java/com/android/server/pm/GrantedPermissions.java
rename to services/core/java/com/android/server/pm/GrantedPermissions.java
diff --git a/services/core/java/com/android/server/pm/Installer.java b/services/core/java/com/android/server/pm/Installer.java
new file mode 100644
index 0000000..6185e50
--- /dev/null
+++ b/services/core/java/com/android/server/pm/Installer.java
@@ -0,0 +1,385 @@
+/*
+ * 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.server.pm;
+
+import com.android.server.SystemService;
+
+import android.content.Context;
+import android.content.pm.PackageStats;
+import android.net.LocalSocket;
+import android.net.LocalSocketAddress;
+import android.util.Slog;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public final class Installer extends SystemService {
+    private static final String TAG = "Installer";
+
+    private static final boolean LOCAL_DEBUG = false;
+
+    InputStream mIn;
+    OutputStream mOut;
+    LocalSocket mSocket;
+
+    byte buf[] = new byte[1024];
+    int buflen = 0;
+
+    public Installer(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onStart() {
+        Slog.i(TAG, "Waiting for installd to be ready.");
+        ping();
+    }
+
+    private boolean connect() {
+        if (mSocket != null) {
+            return true;
+        }
+        Slog.i(TAG, "connecting...");
+        try {
+            mSocket = new LocalSocket();
+
+            LocalSocketAddress address = new LocalSocketAddress("installd",
+                    LocalSocketAddress.Namespace.RESERVED);
+
+            mSocket.connect(address);
+
+            mIn = mSocket.getInputStream();
+            mOut = mSocket.getOutputStream();
+        } catch (IOException ex) {
+            disconnect();
+            return false;
+        }
+        return true;
+    }
+
+    private void disconnect() {
+        Slog.i(TAG, "disconnecting...");
+        try {
+            if (mSocket != null)
+                mSocket.close();
+        } catch (IOException ex) {
+        }
+        try {
+            if (mIn != null)
+                mIn.close();
+        } catch (IOException ex) {
+        }
+        try {
+            if (mOut != null)
+                mOut.close();
+        } catch (IOException ex) {
+        }
+        mSocket = null;
+        mIn = null;
+        mOut = null;
+    }
+
+    private boolean readBytes(byte buffer[], int len) {
+        int off = 0, count;
+        if (len < 0)
+            return false;
+        while (off != len) {
+            try {
+                count = mIn.read(buffer, off, len - off);
+                if (count <= 0) {
+                    Slog.e(TAG, "read error " + count);
+                    break;
+                }
+                off += count;
+            } catch (IOException ex) {
+                Slog.e(TAG, "read exception");
+                break;
+            }
+        }
+        if (LOCAL_DEBUG) {
+            Slog.i(TAG, "read " + len + " bytes");
+        }
+        if (off == len)
+            return true;
+        disconnect();
+        return false;
+    }
+
+    private boolean readReply() {
+        int len;
+        buflen = 0;
+        if (!readBytes(buf, 2))
+            return false;
+        len = (((int) buf[0]) & 0xff) | ((((int) buf[1]) & 0xff) << 8);
+        if ((len < 1) || (len > 1024)) {
+            Slog.e(TAG, "invalid reply length (" + len + ")");
+            disconnect();
+            return false;
+        }
+        if (!readBytes(buf, len))
+            return false;
+        buflen = len;
+        return true;
+    }
+
+    private boolean writeCommand(String _cmd) {
+        byte[] cmd = _cmd.getBytes();
+        int len = cmd.length;
+        if ((len < 1) || (len > 1024))
+            return false;
+        buf[0] = (byte) (len & 0xff);
+        buf[1] = (byte) ((len >> 8) & 0xff);
+        try {
+            mOut.write(buf, 0, 2);
+            mOut.write(cmd, 0, len);
+        } catch (IOException ex) {
+            Slog.e(TAG, "write error");
+            disconnect();
+            return false;
+        }
+        return true;
+    }
+
+    private synchronized String transaction(String cmd) {
+        if (!connect()) {
+            Slog.e(TAG, "connection failed");
+            return "-1";
+        }
+
+        if (!writeCommand(cmd)) {
+            /*
+             * If installd died and restarted in the background (unlikely but
+             * possible) we'll fail on the next write (this one). Try to
+             * reconnect and write the command one more time before giving up.
+             */
+            Slog.e(TAG, "write command failed? reconnect!");
+            if (!connect() || !writeCommand(cmd)) {
+                return "-1";
+            }
+        }
+        if (LOCAL_DEBUG) {
+            Slog.i(TAG, "send: '" + cmd + "'");
+        }
+        if (readReply()) {
+            String s = new String(buf, 0, buflen);
+            if (LOCAL_DEBUG) {
+                Slog.i(TAG, "recv: '" + s + "'");
+            }
+            return s;
+        } else {
+            if (LOCAL_DEBUG) {
+                Slog.i(TAG, "fail");
+            }
+            return "-1";
+        }
+    }
+
+    private int execute(String cmd) {
+        String res = transaction(cmd);
+        try {
+            return Integer.parseInt(res);
+        } catch (NumberFormatException ex) {
+            return -1;
+        }
+    }
+
+    public int install(String name, int uid, int gid, String seinfo) {
+        StringBuilder builder = new StringBuilder("install");
+        builder.append(' ');
+        builder.append(name);
+        builder.append(' ');
+        builder.append(uid);
+        builder.append(' ');
+        builder.append(gid);
+        builder.append(' ');
+        builder.append(seinfo != null ? seinfo : "!");
+        return execute(builder.toString());
+    }
+
+    public int dexopt(String apkPath, int uid, boolean isPublic) {
+        StringBuilder builder = new StringBuilder("dexopt");
+        builder.append(' ');
+        builder.append(apkPath);
+        builder.append(' ');
+        builder.append(uid);
+        builder.append(isPublic ? " 1" : " 0");
+        return execute(builder.toString());
+    }
+
+    public int movedex(String srcPath, String dstPath) {
+        StringBuilder builder = new StringBuilder("movedex");
+        builder.append(' ');
+        builder.append(srcPath);
+        builder.append(' ');
+        builder.append(dstPath);
+        return execute(builder.toString());
+    }
+
+    public int rmdex(String codePath) {
+        StringBuilder builder = new StringBuilder("rmdex");
+        builder.append(' ');
+        builder.append(codePath);
+        return execute(builder.toString());
+    }
+
+    public int remove(String name, int userId) {
+        StringBuilder builder = new StringBuilder("remove");
+        builder.append(' ');
+        builder.append(name);
+        builder.append(' ');
+        builder.append(userId);
+        return execute(builder.toString());
+    }
+
+    public int rename(String oldname, String newname) {
+        StringBuilder builder = new StringBuilder("rename");
+        builder.append(' ');
+        builder.append(oldname);
+        builder.append(' ');
+        builder.append(newname);
+        return execute(builder.toString());
+    }
+
+    public int fixUid(String name, int uid, int gid) {
+        StringBuilder builder = new StringBuilder("fixuid");
+        builder.append(' ');
+        builder.append(name);
+        builder.append(' ');
+        builder.append(uid);
+        builder.append(' ');
+        builder.append(gid);
+        return execute(builder.toString());
+    }
+
+    public int deleteCacheFiles(String name, int userId) {
+        StringBuilder builder = new StringBuilder("rmcache");
+        builder.append(' ');
+        builder.append(name);
+        builder.append(' ');
+        builder.append(userId);
+        return execute(builder.toString());
+    }
+
+    public int createUserData(String name, int uid, int userId, String seinfo) {
+        StringBuilder builder = new StringBuilder("mkuserdata");
+        builder.append(' ');
+        builder.append(name);
+        builder.append(' ');
+        builder.append(uid);
+        builder.append(' ');
+        builder.append(userId);
+        builder.append(' ');
+        builder.append(seinfo != null ? seinfo : "!");
+        return execute(builder.toString());
+    }
+
+    public int removeUserDataDirs(int userId) {
+        StringBuilder builder = new StringBuilder("rmuser");
+        builder.append(' ');
+        builder.append(userId);
+        return execute(builder.toString());
+    }
+
+    public int clearUserData(String name, int userId) {
+        StringBuilder builder = new StringBuilder("rmuserdata");
+        builder.append(' ');
+        builder.append(name);
+        builder.append(' ');
+        builder.append(userId);
+        return execute(builder.toString());
+    }
+
+    public boolean ping() {
+        if (execute("ping") < 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public int freeCache(long freeStorageSize) {
+        StringBuilder builder = new StringBuilder("freecache");
+        builder.append(' ');
+        builder.append(String.valueOf(freeStorageSize));
+        return execute(builder.toString());
+    }
+
+    public int getSizeInfo(String pkgName, int persona, String apkPath, String libDirPath,
+            String fwdLockApkPath, String asecPath, PackageStats pStats) {
+        StringBuilder builder = new StringBuilder("getsize");
+        builder.append(' ');
+        builder.append(pkgName);
+        builder.append(' ');
+        builder.append(persona);
+        builder.append(' ');
+        builder.append(apkPath);
+        builder.append(' ');
+        builder.append(libDirPath != null ? libDirPath : "!");
+        builder.append(' ');
+        builder.append(fwdLockApkPath != null ? fwdLockApkPath : "!");
+        builder.append(' ');
+        builder.append(asecPath != null ? asecPath : "!");
+
+        String s = transaction(builder.toString());
+        String res[] = s.split(" ");
+
+        if ((res == null) || (res.length != 5)) {
+            return -1;
+        }
+        try {
+            pStats.codeSize = Long.parseLong(res[1]);
+            pStats.dataSize = Long.parseLong(res[2]);
+            pStats.cacheSize = Long.parseLong(res[3]);
+            pStats.externalCodeSize = Long.parseLong(res[4]);
+            return Integer.parseInt(res[0]);
+        } catch (NumberFormatException e) {
+            return -1;
+        }
+    }
+
+    public int moveFiles() {
+        return execute("movefiles");
+    }
+
+    /**
+     * Links the native library directory in an application's directory to its
+     * real location.
+     *
+     * @param dataPath data directory where the application is
+     * @param nativeLibPath target native library path
+     * @return -1 on error
+     */
+    public int linkNativeLibraryDirectory(String dataPath, String nativeLibPath, int userId) {
+        if (dataPath == null) {
+            Slog.e(TAG, "linkNativeLibraryDirectory dataPath is null");
+            return -1;
+        } else if (nativeLibPath == null) {
+            Slog.e(TAG, "linkNativeLibraryDirectory nativeLibPath is null");
+            return -1;
+        }
+
+        StringBuilder builder = new StringBuilder("linklib ");
+        builder.append(dataPath);
+        builder.append(' ');
+        builder.append(nativeLibPath);
+        builder.append(' ');
+        builder.append(userId);
+
+        return execute(builder.toString());
+    }
+}
diff --git a/services/java/com/android/server/pm/KeySetManager.java b/services/core/java/com/android/server/pm/KeySetManager.java
similarity index 100%
rename from services/java/com/android/server/pm/KeySetManager.java
rename to services/core/java/com/android/server/pm/KeySetManager.java
diff --git a/services/java/com/android/server/pm/PackageKeySetData.java b/services/core/java/com/android/server/pm/PackageKeySetData.java
similarity index 100%
rename from services/java/com/android/server/pm/PackageKeySetData.java
rename to services/core/java/com/android/server/pm/PackageKeySetData.java
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
new file mode 100755
index 0000000..0f2bea6
--- /dev/null
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -0,0 +1,11667 @@
+/*
+ * Copyright (C) 2006 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.pm;
+
+import static android.Manifest.permission.GRANT_REVOKE_PERMISSIONS;
+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 com.android.internal.util.ArrayUtils.appendInt;
+import static com.android.internal.util.ArrayUtils.removeInt;
+import static libcore.io.OsConstants.S_IRWXU;
+import static libcore.io.OsConstants.S_IRGRP;
+import static libcore.io.OsConstants.S_IXGRP;
+import static libcore.io.OsConstants.S_IROTH;
+import static libcore.io.OsConstants.S_IXOTH;
+
+import com.android.internal.app.IMediaContainerService;
+import com.android.internal.app.ResolverActivity;
+import com.android.internal.content.NativeLibraryHelper;
+import com.android.internal.content.PackageHelper;
+import com.android.internal.util.FastPrintWriter;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.XmlUtils;
+import com.android.server.EventLogTags;
+import com.android.server.IntentResolver;
+import com.android.server.ServiceThread;
+
+import com.android.server.LocalServices;
+import com.android.server.Watchdog;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.app.ActivityManager;
+import android.app.ActivityManagerNative;
+import android.app.IActivityManager;
+import android.app.admin.IDevicePolicyManager;
+import android.app.backup.IBackupManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.IIntentReceiver;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.IntentSender;
+import android.content.ServiceConnection;
+import android.content.IntentSender.SendIntentException;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ContainerEncryptionParams;
+import android.content.pm.FeatureInfo;
+import android.content.pm.IPackageDataObserver;
+import android.content.pm.IPackageDeleteObserver;
+import android.content.pm.IPackageInstallObserver;
+import android.content.pm.IPackageManager;
+import android.content.pm.IPackageMoveObserver;
+import android.content.pm.IPackageStatsObserver;
+import android.content.pm.InstrumentationInfo;
+import android.content.pm.PackageCleanItem;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageInfoLite;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageParser;
+import android.content.pm.PackageUserState;
+import android.content.pm.PackageParser.ActivityIntentInfo;
+import android.content.pm.PackageStats;
+import android.content.pm.ParceledListSlice;
+import android.content.pm.PermissionGroupInfo;
+import android.content.pm.PermissionInfo;
+import android.content.pm.ProviderInfo;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.pm.Signature;
+import android.content.pm.ManifestDigest;
+import android.content.pm.VerificationParams;
+import android.content.pm.VerifierDeviceIdentity;
+import android.content.pm.VerifierInfo;
+import android.content.res.Resources;
+import android.hardware.display.DisplayManager;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.FileObserver;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Parcel;
+import android.os.ParcelFileDescriptor;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SELinux;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.Environment.UserEnvironment;
+import android.os.UserManager;
+import android.security.KeyStore;
+import android.security.SystemKeyStore;
+import android.text.TextUtils;
+import android.util.DisplayMetrics;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.LogPrinter;
+import android.util.PrintStreamPrinter;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.Xml;
+import android.view.Display;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
+import java.security.cert.CertificateException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import libcore.io.ErrnoException;
+import libcore.io.IoUtils;
+import libcore.io.Libcore;
+import libcore.io.StructStat;
+
+import com.android.internal.R;
+import com.android.server.storage.DeviceStorageMonitorInternal;
+
+/**
+ * Keep track of all those .apks everywhere.
+ * 
+ * This is very central to the platform's security; please run the unit
+ * tests whenever making modifications here:
+ * 
+mmm frameworks/base/tests/AndroidTests
+adb install -r -f out/target/product/passion/data/app/AndroidTests.apk
+adb shell am instrument -w -e class com.android.unit_tests.PackageManagerTests com.android.unit_tests/android.test.InstrumentationTestRunner
+ * 
+ * {@hide}
+ */
+public class PackageManagerService extends IPackageManager.Stub {
+    static final String TAG = "PackageManager";
+    static final boolean DEBUG_SETTINGS = false;
+    static final boolean DEBUG_PREFERRED = false;
+    static final boolean DEBUG_UPGRADE = false;
+    private static final boolean DEBUG_INSTALL = false;
+    private static final boolean DEBUG_REMOVE = false;
+    private static final boolean DEBUG_BROADCASTS = false;
+    private static final boolean DEBUG_SHOW_INFO = false;
+    private static final boolean DEBUG_PACKAGE_INFO = false;
+    private static final boolean DEBUG_INTENT_MATCHING = false;
+    private static final boolean DEBUG_PACKAGE_SCANNING = false;
+    private static final boolean DEBUG_APP_DIR_OBSERVER = false;
+    private static final boolean DEBUG_VERIFY = false;
+
+    private static final int RADIO_UID = Process.PHONE_UID;
+    private static final int LOG_UID = Process.LOG_UID;
+    private static final int NFC_UID = Process.NFC_UID;
+    private static final int BLUETOOTH_UID = Process.BLUETOOTH_UID;
+    private static final int SHELL_UID = Process.SHELL_UID;
+
+    private static final boolean GET_CERTIFICATES = true;
+
+    private static final int REMOVE_EVENTS =
+        FileObserver.CLOSE_WRITE | FileObserver.DELETE | FileObserver.MOVED_FROM;
+    private static final int ADD_EVENTS =
+        FileObserver.CLOSE_WRITE /*| FileObserver.CREATE*/ | FileObserver.MOVED_TO;
+
+    private static final int OBSERVER_EVENTS = REMOVE_EVENTS | ADD_EVENTS;
+    // Suffix used during package installation when copying/moving
+    // package apks to install directory.
+    private static final String INSTALL_PACKAGE_SUFFIX = "-";
+
+    static final int SCAN_MONITOR = 1<<0;
+    static final int SCAN_NO_DEX = 1<<1;
+    static final int SCAN_FORCE_DEX = 1<<2;
+    static final int SCAN_UPDATE_SIGNATURE = 1<<3;
+    static final int SCAN_NEW_INSTALL = 1<<4;
+    static final int SCAN_NO_PATHS = 1<<5;
+    static final int SCAN_UPDATE_TIME = 1<<6;
+    static final int SCAN_DEFER_DEX = 1<<7;
+    static final int SCAN_BOOTING = 1<<8;
+    static final int SCAN_DELETE_DATA_ON_FAILURES = 1<<9;
+
+    static final int REMOVE_CHATTY = 1<<16;
+
+    /**
+     * Timeout (in milliseconds) after which the watchdog should declare that
+     * our handler thread is wedged.  The usual default for such things is one
+     * minute but we sometimes do very lengthy I/O operations on this thread,
+     * such as installing multi-gigabyte applications, so ours needs to be longer.
+     */
+    private static final long WATCHDOG_TIMEOUT = 1000*60*10;     // ten minutes
+
+    /**
+     * Whether verification is enabled by default.
+     */
+    private static final boolean DEFAULT_VERIFY_ENABLE = true;
+
+    /**
+     * The default maximum time to wait for the verification agent to return in
+     * milliseconds.
+     */
+    private static final long DEFAULT_VERIFICATION_TIMEOUT = 10 * 1000;
+
+    /**
+     * The default response for package verification timeout.
+     *
+     * This can be either PackageManager.VERIFICATION_ALLOW or
+     * PackageManager.VERIFICATION_REJECT.
+     */
+    private static final int DEFAULT_VERIFICATION_RESPONSE = PackageManager.VERIFICATION_ALLOW;
+
+    static final String DEFAULT_CONTAINER_PACKAGE = "com.android.defcontainer";
+
+    static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
+            DEFAULT_CONTAINER_PACKAGE,
+            "com.android.defcontainer.DefaultContainerService");
+
+    private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
+
+    private static final String LIB_DIR_NAME = "lib";
+
+    static final String mTempContainerPrefix = "smdl2tmp";
+
+    final ServiceThread mHandlerThread;
+    final PackageHandler mHandler;
+
+    final int mSdkVersion = Build.VERSION.SDK_INT;
+    final String mSdkCodename = "REL".equals(Build.VERSION.CODENAME)
+            ? null : Build.VERSION.CODENAME;
+
+    final Context mContext;
+    final boolean mFactoryTest;
+    final boolean mOnlyCore;
+    final boolean mNoDexOpt;
+    final DisplayMetrics mMetrics;
+    final int mDefParseFlags;
+    final String[] mSeparateProcesses;
+
+    // This is where all application persistent data goes.
+    final File mAppDataDir;
+
+    // This is where all application persistent data goes for secondary users.
+    final File mUserAppDataDir;
+
+    /** The location for ASEC container files on internal storage. */
+    final String mAsecInternalPath;
+
+    // This is the object monitoring the framework dir.
+    final FileObserver mFrameworkInstallObserver;
+
+    // This is the object monitoring the system app dir.
+    final FileObserver mSystemInstallObserver;
+
+    // This is the object monitoring the privileged system app dir.
+    final FileObserver mPrivilegedInstallObserver;
+
+    // This is the object monitoring the system app dir.
+    final FileObserver mVendorInstallObserver;
+
+    // This is the object monitoring mAppInstallDir.
+    final FileObserver mAppInstallObserver;
+
+    // This is the object monitoring mDrmAppPrivateInstallDir.
+    final FileObserver mDrmAppInstallObserver;
+
+    // Used for privilege escalation. MUST NOT BE CALLED WITH mPackages
+    // LOCK HELD.  Can be called with mInstallLock held.
+    final Installer mInstaller;
+
+    final File mAppInstallDir;
+
+    /**
+     * Directory to which applications installed internally have native
+     * libraries copied.
+     */
+    private File mAppLibInstallDir;
+
+    // Directory containing the private parts (e.g. code and non-resource assets) of forward-locked
+    // apps.
+    final File mDrmAppPrivateInstallDir;
+
+    // ----------------------------------------------------------------
+
+    // Lock for state used when installing and doing other long running
+    // operations.  Methods that must be called with this lock held have
+    // the prefix "LI".
+    final Object mInstallLock = new Object();
+
+    // These are the directories in the 3rd party applications installed dir
+    // that we have currently loaded packages from.  Keys are the application's
+    // installed zip file (absolute codePath), and values are Package.
+    final HashMap<String, PackageParser.Package> mAppDirs =
+            new HashMap<String, PackageParser.Package>();
+
+    // Information for the parser to write more useful error messages.
+    int mLastScanError;
+
+    // ----------------------------------------------------------------
+
+    // Keys are String (package name), values are Package.  This also serves
+    // as the lock for the global state.  Methods that must be called with
+    // this lock held have the prefix "LP".
+    final HashMap<String, PackageParser.Package> mPackages =
+            new HashMap<String, PackageParser.Package>();
+
+    final Settings mSettings;
+    boolean mRestoredSettings;
+
+    // Group-ids that are given to all packages as read from etc/permissions/*.xml.
+    int[] mGlobalGids;
+
+    // These are the built-in uid -> permission mappings that were read from the
+    // etc/permissions.xml file.
+    final SparseArray<HashSet<String>> mSystemPermissions =
+            new SparseArray<HashSet<String>>();
+
+    static final class SharedLibraryEntry {
+        final String path;
+        final String apk;
+
+        SharedLibraryEntry(String _path, String _apk) {
+            path = _path;
+            apk = _apk;
+        }
+    }
+
+    // These are the built-in shared libraries that were read from the
+    // etc/permissions.xml file.
+    final HashMap<String, SharedLibraryEntry> mSharedLibraries
+            = new HashMap<String, SharedLibraryEntry>();
+
+    // Temporary for building the final shared libraries for an .apk.
+    String[] mTmpSharedLibraries = null;
+
+    // These are the features this devices supports that were read from the
+    // etc/permissions.xml file.
+    final HashMap<String, FeatureInfo> mAvailableFeatures =
+            new HashMap<String, FeatureInfo>();
+
+    // If mac_permissions.xml was found for seinfo labeling.
+    boolean mFoundPolicyFile;
+
+    // All available activities, for your resolving pleasure.
+    final ActivityIntentResolver mActivities =
+            new ActivityIntentResolver();
+
+    // All available receivers, for your resolving pleasure.
+    final ActivityIntentResolver mReceivers =
+            new ActivityIntentResolver();
+
+    // All available services, for your resolving pleasure.
+    final ServiceIntentResolver mServices = new ServiceIntentResolver();
+
+    // All available providers, for your resolving pleasure.
+    final ProviderIntentResolver mProviders = new ProviderIntentResolver();
+
+    // Mapping from provider base names (first directory in content URI codePath)
+    // to the provider information.
+    final HashMap<String, PackageParser.Provider> mProvidersByAuthority =
+            new HashMap<String, PackageParser.Provider>();
+
+    // Mapping from instrumentation class names to info about them.
+    final HashMap<ComponentName, PackageParser.Instrumentation> mInstrumentation =
+            new HashMap<ComponentName, PackageParser.Instrumentation>();
+
+    // Mapping from permission names to info about them.
+    final HashMap<String, PackageParser.PermissionGroup> mPermissionGroups =
+            new HashMap<String, PackageParser.PermissionGroup>();
+
+    // Packages whose data we have transfered into another package, thus
+    // should no longer exist.
+    final HashSet<String> mTransferedPackages = new HashSet<String>();
+    
+    // Broadcast actions that are only available to the system.
+    final HashSet<String> mProtectedBroadcasts = new HashSet<String>();
+
+    /** List of packages waiting for verification. */
+    final SparseArray<PackageVerificationState> mPendingVerification
+            = new SparseArray<PackageVerificationState>();
+
+    HashSet<PackageParser.Package> mDeferredDexOpt = null;
+
+    /** Token for keys in mPendingVerification. */
+    private int mPendingVerificationToken = 0;
+
+    boolean mSystemReady;
+    boolean mSafeMode;
+    boolean mHasSystemUidErrors;
+
+    ApplicationInfo mAndroidApplication;
+    final ActivityInfo mResolveActivity = new ActivityInfo();
+    final ResolveInfo mResolveInfo = new ResolveInfo();
+    ComponentName mResolveComponentName;
+    PackageParser.Package mPlatformPackage;
+    ComponentName mCustomResolverComponentName;
+
+    boolean mResolverReplaced = false;
+
+    // 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>
+        final SparseArray<HashMap<String, ArrayList<String>>> mUidMap;
+
+        public PendingPackageBroadcasts() {
+            mUidMap = new SparseArray<HashMap<String, ArrayList<String>>>(2);
+        }
+
+        public ArrayList<String> get(int userId, String packageName) {
+            HashMap<String, ArrayList<String>> packages = getOrAllocate(userId);
+            return packages.get(packageName);
+        }
+
+        public void put(int userId, String packageName, ArrayList<String> components) {
+            HashMap<String, ArrayList<String>> packages = getOrAllocate(userId);
+            packages.put(packageName, components);
+        }
+
+        public void remove(int userId, String packageName) {
+            HashMap<String, ArrayList<String>> packages = mUidMap.get(userId);
+            if (packages != null) {
+                packages.remove(packageName);
+            }
+        }
+
+        public void remove(int userId) {
+            mUidMap.remove(userId);
+        }
+
+        public int userIdCount() {
+            return mUidMap.size();
+        }
+
+        public int userIdAt(int n) {
+            return mUidMap.keyAt(n);
+        }
+
+        public HashMap<String, ArrayList<String>> packagesForUserId(int userId) {
+            return mUidMap.get(userId);
+        }
+
+        public int size() {
+            // total number of pending broadcast entries across all userIds
+            int num = 0;
+            for (int i = 0; i< mUidMap.size(); i++) {
+                num += mUidMap.valueAt(i).size();
+            }
+            return num;
+        }
+
+        public void clear() {
+            mUidMap.clear();
+        }
+
+        private HashMap<String, ArrayList<String>> getOrAllocate(int userId) {
+            HashMap<String, ArrayList<String>> map = mUidMap.get(userId);
+            if (map == null) {
+                map = new HashMap<String, ArrayList<String>>();
+                mUidMap.put(userId, map);
+            }
+            return map;
+        }
+    }
+    final PendingPackageBroadcasts mPendingBroadcasts = new PendingPackageBroadcasts();
+
+    // Service Connection to remote media container service to copy
+    // package uri's from external media onto secure containers
+    // or internal storage.
+    private IMediaContainerService mContainerService = null;
+
+    static final int SEND_PENDING_BROADCAST = 1;
+    static final int MCS_BOUND = 3;
+    static final int END_COPY = 4;
+    static final int INIT_COPY = 5;
+    static final int MCS_UNBIND = 6;
+    static final int START_CLEANING_PACKAGE = 7;
+    static final int FIND_INSTALL_LOC = 8;
+    static final int POST_INSTALL = 9;
+    static final int MCS_RECONNECT = 10;
+    static final int MCS_GIVE_UP = 11;
+    static final int UPDATED_MEDIA_STATUS = 12;
+    static final int WRITE_SETTINGS = 13;
+    static final int WRITE_PACKAGE_RESTRICTIONS = 14;
+    static final int PACKAGE_VERIFIED = 15;
+    static final int CHECK_PENDING_VERIFICATION = 16;
+
+    static final int WRITE_SETTINGS_DELAY = 10*1000;  // 10 seconds
+
+    // Delay time in millisecs
+    static final int BROADCAST_DELAY = 10 * 1000;
+
+    static UserManagerService sUserManager;
+
+    // Stores a list of users whose package restrictions file needs to be updated
+    private HashSet<Integer> mDirtyUsers = new HashSet<Integer>();
+
+    final private DefaultContainerConnection mDefContainerConn =
+            new DefaultContainerConnection();
+    class DefaultContainerConnection implements ServiceConnection {
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceConnected");
+            IMediaContainerService imcs =
+                IMediaContainerService.Stub.asInterface(service);
+            mHandler.sendMessage(mHandler.obtainMessage(MCS_BOUND, imcs));
+        }
+
+        public void onServiceDisconnected(ComponentName name) {
+            if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceDisconnected");
+        }
+    };
+
+    // Recordkeeping of restore-after-install operations that are currently in flight
+    // between the Package Manager and the Backup Manager
+    class PostInstallData {
+        public InstallArgs args;
+        public PackageInstalledInfo res;
+
+        PostInstallData(InstallArgs _a, PackageInstalledInfo _r) {
+            args = _a;
+            res = _r;
+        }
+    };
+    final SparseArray<PostInstallData> mRunningInstalls = new SparseArray<PostInstallData>();
+    int mNextInstallToken = 1;  // nonzero; will be wrapped back to 1 when ++ overflows
+
+    private final String mRequiredVerifierPackage;
+
+    class PackageHandler extends Handler {
+        private boolean mBound = false;
+        final ArrayList<HandlerParams> mPendingInstalls =
+            new ArrayList<HandlerParams>();
+
+        private boolean connectToService() {
+            if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to bind to" +
+                    " DefaultContainerService");
+            Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
+            Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
+            if (mContext.bindServiceAsUser(service, mDefContainerConn,
+                    Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
+                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+                mBound = true;
+                return true;
+            }
+            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+            return false;
+        }
+
+        private void disconnectService() {
+            mContainerService = null;
+            mBound = false;
+            Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
+            mContext.unbindService(mDefContainerConn);
+            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+        }
+
+        PackageHandler(Looper looper) {
+            super(looper);
+        }
+
+        public void handleMessage(Message msg) {
+            try {
+                doHandleMessage(msg);
+            } finally {
+                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+            }
+        }
+        
+        void doHandleMessage(Message msg) {
+            switch (msg.what) {
+                case INIT_COPY: {
+                    HandlerParams params = (HandlerParams) msg.obj;
+                    int idx = mPendingInstalls.size();
+                    if (DEBUG_INSTALL) Slog.i(TAG, "init_copy idx=" + idx + ": " + params);
+                    // If a bind was already initiated we dont really
+                    // need to do anything. The pending install
+                    // will be processed later on.
+                    if (!mBound) {
+                        // If this is the only one pending we might
+                        // have to bind to the service again.
+                        if (!connectToService()) {
+                            Slog.e(TAG, "Failed to bind to media container service");
+                            params.serviceError();
+                            return;
+                        } else {
+                            // Once we bind to the service, the first
+                            // pending request will be processed.
+                            mPendingInstalls.add(idx, params);
+                        }
+                    } else {
+                        mPendingInstalls.add(idx, params);
+                        // Already bound to the service. Just make
+                        // sure we trigger off processing the first request.
+                        if (idx == 0) {
+                            mHandler.sendEmptyMessage(MCS_BOUND);
+                        }
+                    }
+                    break;
+                }
+                case MCS_BOUND: {
+                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_bound");
+                    if (msg.obj != null) {
+                        mContainerService = (IMediaContainerService) msg.obj;
+                    }
+                    if (mContainerService == null) {
+                        // Something seriously wrong. Bail out
+                        Slog.e(TAG, "Cannot bind to media container service");
+                        for (HandlerParams params : mPendingInstalls) {
+                            // Indicate service bind error
+                            params.serviceError();
+                        }
+                        mPendingInstalls.clear();
+                    } else if (mPendingInstalls.size() > 0) {
+                        HandlerParams params = mPendingInstalls.get(0);
+                        if (params != null) {
+                            if (params.startCopy()) {
+                                // We are done...  look for more work or to
+                                // go idle.
+                                if (DEBUG_SD_INSTALL) Log.i(TAG,
+                                        "Checking for more work or unbind...");
+                                // Delete pending install
+                                if (mPendingInstalls.size() > 0) {
+                                    mPendingInstalls.remove(0);
+                                }
+                                if (mPendingInstalls.size() == 0) {
+                                    if (mBound) {
+                                        if (DEBUG_SD_INSTALL) Log.i(TAG,
+                                                "Posting delayed MCS_UNBIND");
+                                        removeMessages(MCS_UNBIND);
+                                        Message ubmsg = obtainMessage(MCS_UNBIND);
+                                        // Unbind after a little delay, to avoid
+                                        // continual thrashing.
+                                        sendMessageDelayed(ubmsg, 10000);
+                                    }
+                                } else {
+                                    // There are more pending requests in queue.
+                                    // Just post MCS_BOUND message to trigger processing
+                                    // of next pending install.
+                                    if (DEBUG_SD_INSTALL) Log.i(TAG,
+                                            "Posting MCS_BOUND for next woek");
+                                    mHandler.sendEmptyMessage(MCS_BOUND);
+                                }
+                            }
+                        }
+                    } else {
+                        // Should never happen ideally.
+                        Slog.w(TAG, "Empty queue");
+                    }
+                    break;
+                }
+                case MCS_RECONNECT: {
+                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_reconnect");
+                    if (mPendingInstalls.size() > 0) {
+                        if (mBound) {
+                            disconnectService();
+                        }
+                        if (!connectToService()) {
+                            Slog.e(TAG, "Failed to bind to media container service");
+                            for (HandlerParams params : mPendingInstalls) {
+                                // Indicate service bind error
+                                params.serviceError();
+                            }
+                            mPendingInstalls.clear();
+                        }
+                    }
+                    break;
+                }
+                case MCS_UNBIND: {
+                    // If there is no actual work left, then time to unbind.
+                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_unbind");
+
+                    if (mPendingInstalls.size() == 0 && mPendingVerification.size() == 0) {
+                        if (mBound) {
+                            if (DEBUG_INSTALL) Slog.i(TAG, "calling disconnectService()");
+
+                            disconnectService();
+                        }
+                    } else if (mPendingInstalls.size() > 0) {
+                        // There are more pending requests in queue.
+                        // Just post MCS_BOUND message to trigger processing
+                        // of next pending install.
+                        mHandler.sendEmptyMessage(MCS_BOUND);
+                    }
+
+                    break;
+                }
+                case MCS_GIVE_UP: {
+                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_giveup too many retries");
+                    mPendingInstalls.remove(0);
+                    break;
+                }
+                case SEND_PENDING_BROADCAST: {
+                    String packages[];
+                    ArrayList<String> components[];
+                    int size = 0;
+                    int uids[];
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
+                    synchronized (mPackages) {
+                        if (mPendingBroadcasts == null) {
+                            return;
+                        }
+                        size = mPendingBroadcasts.size();
+                        if (size <= 0) {
+                            // Nothing to be done. Just return
+                            return;
+                        }
+                        packages = new String[size];
+                        components = new ArrayList[size];
+                        uids = new int[size];
+                        int i = 0;  // filling out the above arrays
+
+                        for (int n = 0; n < mPendingBroadcasts.userIdCount(); n++) {
+                            int packageUserId = mPendingBroadcasts.userIdAt(n);
+                            Iterator<Map.Entry<String, ArrayList<String>>> it
+                                    = mPendingBroadcasts.packagesForUserId(packageUserId)
+                                            .entrySet().iterator();
+                            while (it.hasNext() && i < size) {
+                                Map.Entry<String, ArrayList<String>> ent = it.next();
+                                packages[i] = ent.getKey();
+                                components[i] = ent.getValue();
+                                PackageSetting ps = mSettings.mPackages.get(ent.getKey());
+                                uids[i] = (ps != null)
+                                        ? UserHandle.getUid(packageUserId, ps.appId)
+                                        : -1;
+                                i++;
+                            }
+                        }
+                        size = i;
+                        mPendingBroadcasts.clear();
+                    }
+                    // Send broadcasts
+                    for (int i = 0; i < size; i++) {
+                        sendPackageChangedBroadcast(packages[i], true, components[i], uids[i]);
+                    }
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+                    break;
+                }
+                case START_CLEANING_PACKAGE: {
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
+                    final String packageName = (String)msg.obj;
+                    final int userId = msg.arg1;
+                    final boolean andCode = msg.arg2 != 0;
+                    synchronized (mPackages) {
+                        if (userId == UserHandle.USER_ALL) {
+                            int[] users = sUserManager.getUserIds();
+                            for (int user : users) {
+                                mSettings.addPackageToCleanLPw(
+                                        new PackageCleanItem(user, packageName, andCode));
+                            }
+                        } else {
+                            mSettings.addPackageToCleanLPw(
+                                    new PackageCleanItem(userId, packageName, andCode));
+                        }
+                    }
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+                    startCleaningPackages();
+                } break;
+                case POST_INSTALL: {
+                    if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1);
+                    PostInstallData data = mRunningInstalls.get(msg.arg1);
+                    mRunningInstalls.delete(msg.arg1);
+                    boolean deleteOld = false;
+
+                    if (data != null) {
+                        InstallArgs args = data.args;
+                        PackageInstalledInfo res = data.res;
+
+                        if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
+                            res.removedInfo.sendBroadcast(false, true, false);
+                            Bundle extras = new Bundle(1);
+                            extras.putInt(Intent.EXTRA_UID, res.uid);
+                            // Determine the set of users who are adding this
+                            // package for the first time vs. those who are seeing
+                            // an update.
+                            int[] firstUsers;
+                            int[] updateUsers = new int[0];
+                            if (res.origUsers == null || res.origUsers.length == 0) {
+                                firstUsers = res.newUsers;
+                            } else {
+                                firstUsers = new int[0];
+                                for (int i=0; i<res.newUsers.length; i++) {
+                                    int user = res.newUsers[i];
+                                    boolean isNew = true;
+                                    for (int j=0; j<res.origUsers.length; j++) {
+                                        if (res.origUsers[j] == user) {
+                                            isNew = false;
+                                            break;
+                                        }
+                                    }
+                                    if (isNew) {
+                                        int[] newFirst = new int[firstUsers.length+1];
+                                        System.arraycopy(firstUsers, 0, newFirst, 0,
+                                                firstUsers.length);
+                                        newFirst[firstUsers.length] = user;
+                                        firstUsers = newFirst;
+                                    } else {
+                                        int[] newUpdate = new int[updateUsers.length+1];
+                                        System.arraycopy(updateUsers, 0, newUpdate, 0,
+                                                updateUsers.length);
+                                        newUpdate[updateUsers.length] = user;
+                                        updateUsers = newUpdate;
+                                    }
+                                }
+                            }
+                            sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
+                                    res.pkg.applicationInfo.packageName,
+                                    extras, null, null, firstUsers);
+                            final boolean update = res.removedInfo.removedPackage != null;
+                            if (update) {
+                                extras.putBoolean(Intent.EXTRA_REPLACING, true);
+                            }
+                            sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
+                                    res.pkg.applicationInfo.packageName,
+                                    extras, null, null, updateUsers);
+                            if (update) {
+                                sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED,
+                                        res.pkg.applicationInfo.packageName,
+                                        extras, null, null, updateUsers);
+                                sendPackageBroadcast(Intent.ACTION_MY_PACKAGE_REPLACED,
+                                        null, null,
+                                        res.pkg.applicationInfo.packageName, null, updateUsers);
+
+                                // treat asec-hosted packages like removable media on upgrade
+                                if (isForwardLocked(res.pkg) || isExternal(res.pkg)) {
+                                    if (DEBUG_INSTALL) {
+                                        Slog.i(TAG, "upgrading pkg " + res.pkg
+                                                + " is ASEC-hosted -> AVAILABLE");
+                                    }
+                                    int[] uidArray = new int[] { res.pkg.applicationInfo.uid };
+                                    ArrayList<String> pkgList = new ArrayList<String>(1);
+                                    pkgList.add(res.pkg.applicationInfo.packageName);
+                                    sendResourcesChangedBroadcast(true, true,
+                                            pkgList,uidArray, null);
+                                }
+                            }
+                            if (res.removedInfo.args != null) {
+                                // Remove the replaced package's older resources safely now
+                                deleteOld = true;
+                            }
+
+                            // Log current value of "unknown sources" setting
+                            EventLog.writeEvent(EventLogTags.UNKNOWN_SOURCES_ENABLED,
+                                getUnknownSourcesSettings());
+                        }
+                        // Force a gc to clear up things
+                        Runtime.getRuntime().gc();
+                        // We delete after a gc for applications  on sdcard.
+                        if (deleteOld) {
+                            synchronized (mInstallLock) {
+                                res.removedInfo.args.doPostDeleteLI(true);
+                            }
+                        }
+                        if (args.observer != null) {
+                            try {
+                                args.observer.packageInstalled(res.name, res.returnCode);
+                            } catch (RemoteException e) {
+                                Slog.i(TAG, "Observer no longer exists.");
+                            }
+                        }
+                    } else {
+                        Slog.e(TAG, "Bogus post-install token " + msg.arg1);
+                    }
+                } break;
+                case UPDATED_MEDIA_STATUS: {
+                    if (DEBUG_SD_INSTALL) Log.i(TAG, "Got message UPDATED_MEDIA_STATUS");
+                    boolean reportStatus = msg.arg1 == 1;
+                    boolean doGc = msg.arg2 == 1;
+                    if (DEBUG_SD_INSTALL) Log.i(TAG, "reportStatus=" + reportStatus + ", doGc = " + doGc);
+                    if (doGc) {
+                        // Force a gc to clear up stale containers.
+                        Runtime.getRuntime().gc();
+                    }
+                    if (msg.obj != null) {
+                        @SuppressWarnings("unchecked")
+                        Set<AsecInstallArgs> args = (Set<AsecInstallArgs>) msg.obj;
+                        if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading all containers");
+                        // Unload containers
+                        unloadAllContainers(args);
+                    }
+                    if (reportStatus) {
+                        try {
+                            if (DEBUG_SD_INSTALL) Log.i(TAG, "Invoking MountService call back");
+                            PackageHelper.getMountService().finishMediaUpdate();
+                        } catch (RemoteException e) {
+                            Log.e(TAG, "MountService not running?");
+                        }
+                    }
+                } break;
+                case WRITE_SETTINGS: {
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
+                    synchronized (mPackages) {
+                        removeMessages(WRITE_SETTINGS);
+                        removeMessages(WRITE_PACKAGE_RESTRICTIONS);
+                        mSettings.writeLPr();
+                        mDirtyUsers.clear();
+                    }
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+                } break;
+                case WRITE_PACKAGE_RESTRICTIONS: {
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
+                    synchronized (mPackages) {
+                        removeMessages(WRITE_PACKAGE_RESTRICTIONS);
+                        for (int userId : mDirtyUsers) {
+                            mSettings.writePackageRestrictionsLPr(userId);
+                        }
+                        mDirtyUsers.clear();
+                    }
+                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
+                } break;
+                case CHECK_PENDING_VERIFICATION: {
+                    final int verificationId = msg.arg1;
+                    final PackageVerificationState state = mPendingVerification.get(verificationId);
+
+                    if ((state != null) && !state.timeoutExtended()) {
+                        final InstallArgs args = state.getInstallArgs();
+                        Slog.i(TAG, "Verification timed out for " + args.packageURI.toString());
+                        mPendingVerification.remove(verificationId);
+
+                        int ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
+
+                        if (getDefaultVerificationResponse() == PackageManager.VERIFICATION_ALLOW) {
+                            Slog.i(TAG, "Continuing with installation of "
+                                    + args.packageURI.toString());
+                            state.setVerifierResponse(Binder.getCallingUid(),
+                                    PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);
+                            broadcastPackageVerified(verificationId, args.packageURI,
+                                    PackageManager.VERIFICATION_ALLOW,
+                                    state.getInstallArgs().getUser());
+                            try {
+                                ret = args.copyApk(mContainerService, true);
+                            } catch (RemoteException e) {
+                                Slog.e(TAG, "Could not contact the ContainerService");
+                            }
+                        } else {
+                            broadcastPackageVerified(verificationId, args.packageURI,
+                                    PackageManager.VERIFICATION_REJECT,
+                                    state.getInstallArgs().getUser());
+                        }
+
+                        processPendingInstall(args, ret);
+                        mHandler.sendEmptyMessage(MCS_UNBIND);
+                    }
+                    break;
+                }
+                case PACKAGE_VERIFIED: {
+                    final int verificationId = msg.arg1;
+
+                    final PackageVerificationState state = mPendingVerification.get(verificationId);
+                    if (state == null) {
+                        Slog.w(TAG, "Invalid verification token " + verificationId + " received");
+                        break;
+                    }
+
+                    final PackageVerificationResponse response = (PackageVerificationResponse) msg.obj;
+
+                    state.setVerifierResponse(response.callerUid, response.code);
+
+                    if (state.isVerificationComplete()) {
+                        mPendingVerification.remove(verificationId);
+
+                        final InstallArgs args = state.getInstallArgs();
+
+                        int ret;
+                        if (state.isInstallAllowed()) {
+                            ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+                            broadcastPackageVerified(verificationId, args.packageURI,
+                                    response.code, state.getInstallArgs().getUser());
+                            try {
+                                ret = args.copyApk(mContainerService, true);
+                            } catch (RemoteException e) {
+                                Slog.e(TAG, "Could not contact the ContainerService");
+                            }
+                        } else {
+                            ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
+                        }
+
+                        processPendingInstall(args, ret);
+
+                        mHandler.sendEmptyMessage(MCS_UNBIND);
+                    }
+
+                    break;
+                }
+            }
+        }
+    }
+
+    void scheduleWriteSettingsLocked() {
+        if (!mHandler.hasMessages(WRITE_SETTINGS)) {
+            mHandler.sendEmptyMessageDelayed(WRITE_SETTINGS, WRITE_SETTINGS_DELAY);
+        }
+    }
+
+    void scheduleWritePackageRestrictionsLocked(int userId) {
+        if (!sUserManager.exists(userId)) return;
+        mDirtyUsers.add(userId);
+        if (!mHandler.hasMessages(WRITE_PACKAGE_RESTRICTIONS)) {
+            mHandler.sendEmptyMessageDelayed(WRITE_PACKAGE_RESTRICTIONS, WRITE_SETTINGS_DELAY);
+        }
+    }
+
+    public static final IPackageManager main(Context context, Installer installer,
+            boolean factoryTest, boolean onlyCore) {
+        PackageManagerService m = new PackageManagerService(context, installer,
+                factoryTest, onlyCore);
+        ServiceManager.addService("package", m);
+        return m;
+    }
+
+    static String[] splitString(String str, char sep) {
+        int count = 1;
+        int i = 0;
+        while ((i=str.indexOf(sep, i)) >= 0) {
+            count++;
+            i++;
+        }
+
+        String[] res = new String[count];
+        i=0;
+        count = 0;
+        int lastI=0;
+        while ((i=str.indexOf(sep, i)) >= 0) {
+            res[count] = str.substring(lastI, i);
+            count++;
+            i++;
+            lastI = i;
+        }
+        res[count] = str.substring(lastI, str.length());
+        return res;
+    }
+
+    private static void getDefaultDisplayMetrics(Context context, DisplayMetrics metrics) {
+        DisplayManager displayManager = (DisplayManager) context.getSystemService(
+                Context.DISPLAY_SERVICE);
+        displayManager.getDisplay(Display.DEFAULT_DISPLAY).getMetrics(metrics);
+    }
+
+    public PackageManagerService(Context context, Installer installer,
+            boolean factoryTest, boolean onlyCore) {
+        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START,
+                SystemClock.uptimeMillis());
+
+        if (mSdkVersion <= 0) {
+            Slog.w(TAG, "**** ro.build.version.sdk not set!");
+        }
+
+        mContext = context;
+        mFactoryTest = factoryTest;
+        mOnlyCore = onlyCore;
+        mNoDexOpt = "eng".equals(SystemProperties.get("ro.build.type"));
+        mMetrics = new DisplayMetrics();
+        mSettings = new Settings(context);
+        mSettings.addSharedUserLPw("android.uid.system", Process.SYSTEM_UID,
+                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
+        mSettings.addSharedUserLPw("android.uid.phone", RADIO_UID,
+                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
+        mSettings.addSharedUserLPw("android.uid.log", LOG_UID,
+                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
+        mSettings.addSharedUserLPw("android.uid.nfc", NFC_UID,
+                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
+        mSettings.addSharedUserLPw("android.uid.bluetooth", BLUETOOTH_UID,
+                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
+        mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID,
+                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
+
+        String separateProcesses = SystemProperties.get("debug.separate_processes");
+        if (separateProcesses != null && separateProcesses.length() > 0) {
+            if ("*".equals(separateProcesses)) {
+                mDefParseFlags = PackageParser.PARSE_IGNORE_PROCESSES;
+                mSeparateProcesses = null;
+                Slog.w(TAG, "Running with debug.separate_processes: * (ALL)");
+            } else {
+                mDefParseFlags = 0;
+                mSeparateProcesses = separateProcesses.split(",");
+                Slog.w(TAG, "Running with debug.separate_processes: "
+                        + separateProcesses);
+            }
+        } else {
+            mDefParseFlags = 0;
+            mSeparateProcesses = null;
+        }
+
+        mInstaller = installer;
+
+        getDefaultDisplayMetrics(context, mMetrics);
+
+        synchronized (mInstallLock) {
+        // writer
+        synchronized (mPackages) {
+            mHandlerThread = new ServiceThread(TAG,
+                    Process.THREAD_PRIORITY_BACKGROUND, true /*allowIo*/);
+            mHandlerThread.start();
+            mHandler = new PackageHandler(mHandlerThread.getLooper());
+            Watchdog.getInstance().addThread(mHandler, WATCHDOG_TIMEOUT);
+
+            File dataDir = Environment.getDataDirectory();
+            mAppDataDir = new File(dataDir, "data");
+            mAppInstallDir = new File(dataDir, "app");
+            mAppLibInstallDir = new File(dataDir, "app-lib");
+            mAsecInternalPath = new File(dataDir, "app-asec").getPath();
+            mUserAppDataDir = new File(dataDir, "user");
+            mDrmAppPrivateInstallDir = new File(dataDir, "app-private");
+
+            sUserManager = new UserManagerService(context, this,
+                    mInstallLock, mPackages);
+
+            readPermissions();
+
+            mFoundPolicyFile = SELinuxMMAC.readInstallPolicy();
+
+            mRestoredSettings = mSettings.readLPw(this, sUserManager.getUsers(false),
+                    mSdkVersion, mOnlyCore);
+
+            String customResolverActivity = Resources.getSystem().getString(
+                    R.string.config_customResolverActivity);
+            if (TextUtils.isEmpty(customResolverActivity)) {
+                customResolverActivity = null;
+            } else {
+                mCustomResolverComponentName = ComponentName.unflattenFromString(
+                        customResolverActivity);
+            }
+
+            long startTime = SystemClock.uptimeMillis();
+
+            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SYSTEM_SCAN_START,
+                    startTime);
+
+            // Set flag to monitor and not change apk file paths when
+            // scanning install directories.
+            int scanMode = SCAN_MONITOR | SCAN_NO_PATHS | SCAN_DEFER_DEX | SCAN_BOOTING;
+            if (mNoDexOpt) {
+                Slog.w(TAG, "Running ENG build: no pre-dexopt!");
+                scanMode |= SCAN_NO_DEX;
+            }
+
+            final HashSet<String> alreadyDexOpted = new HashSet<String>();
+
+            /**
+             * Add everything in the in the boot class path to the
+             * list of process files because dexopt will have been run
+             * if necessary during zygote startup.
+             */
+            String bootClassPath = System.getProperty("java.boot.class.path");
+            if (bootClassPath != null) {
+                String[] paths = splitString(bootClassPath, ':');
+                for (int i=0; i<paths.length; i++) {
+                    alreadyDexOpted.add(paths[i]);
+                }
+            } else {
+                Slog.w(TAG, "No BOOTCLASSPATH found!");
+            }
+
+            boolean didDexOpt = false;
+
+            /**
+             * Ensure all external libraries have had dexopt run on them.
+             */
+            if (mSharedLibraries.size() > 0) {
+                Iterator<SharedLibraryEntry> libs = mSharedLibraries.values().iterator();
+                while (libs.hasNext()) {
+                    String lib = libs.next().path;
+                    if (lib == null) {
+                        continue;
+                    }
+                    try {
+                        if (dalvik.system.DexFile.isDexOptNeeded(lib)) {
+                            alreadyDexOpted.add(lib);
+                            mInstaller.dexopt(lib, Process.SYSTEM_UID, true);
+                            didDexOpt = true;
+                        }
+                    } catch (FileNotFoundException e) {
+                        Slog.w(TAG, "Library not found: " + lib);
+                    } catch (IOException e) {
+                        Slog.w(TAG, "Cannot dexopt " + lib + "; is it an APK or JAR? "
+                                + e.getMessage());
+                    }
+                }
+            }
+
+            File frameworkDir = new File(Environment.getRootDirectory(), "framework");
+
+            // Gross hack for now: we know this file doesn't contain any
+            // code, so don't dexopt it to avoid the resulting log spew.
+            alreadyDexOpted.add(frameworkDir.getPath() + "/framework-res.apk");
+
+            // Gross hack for now: we know this file is only part of
+            // the boot class path for art, so don't dexopt it to
+            // avoid the resulting log spew.
+            alreadyDexOpted.add(frameworkDir.getPath() + "/core-libart.jar");
+
+            /**
+             * And there are a number of commands implemented in Java, which
+             * we currently need to do the dexopt on so that they can be
+             * run from a non-root shell.
+             */
+            String[] frameworkFiles = frameworkDir.list();
+            if (frameworkFiles != null) {
+                for (int i=0; i<frameworkFiles.length; i++) {
+                    File libPath = new File(frameworkDir, frameworkFiles[i]);
+                    String path = libPath.getPath();
+                    // Skip the file if we alrady did it.
+                    if (alreadyDexOpted.contains(path)) {
+                        continue;
+                    }
+                    // Skip the file if it is not a type we want to dexopt.
+                    if (!path.endsWith(".apk") && !path.endsWith(".jar")) {
+                        continue;
+                    }
+                    try {
+                        if (dalvik.system.DexFile.isDexOptNeeded(path)) {
+                            mInstaller.dexopt(path, Process.SYSTEM_UID, true);
+                            didDexOpt = true;
+                        }
+                    } catch (FileNotFoundException e) {
+                        Slog.w(TAG, "Jar not found: " + path);
+                    } catch (IOException e) {
+                        Slog.w(TAG, "Exception reading jar: " + path, e);
+                    }
+                }
+            }
+
+            if (didDexOpt) {
+                File dalvikCacheDir = new File(dataDir, "dalvik-cache");
+
+                // If we had to do a dexopt of one of the previous
+                // things, then something on the system has changed.
+                // Consider this significant, and wipe away all other
+                // existing dexopt files to ensure we don't leave any
+                // dangling around.
+                String[] files = dalvikCacheDir.list();
+                if (files != null) {
+                    for (int i=0; i<files.length; i++) {
+                        String fn = files[i];
+                        if (fn.startsWith("data@app@")
+                                || fn.startsWith("data@app-private@")) {
+                            Slog.i(TAG, "Pruning dalvik file: " + fn);
+                            (new File(dalvikCacheDir, fn)).delete();
+                        }
+                    }
+                }
+            }
+
+            // Find base frameworks (resource packages without code).
+            mFrameworkInstallObserver = new AppDirObserver(
+                frameworkDir.getPath(), OBSERVER_EVENTS, true, false);
+            mFrameworkInstallObserver.startWatching();
+            scanDirLI(frameworkDir, PackageParser.PARSE_IS_SYSTEM
+                    | PackageParser.PARSE_IS_SYSTEM_DIR
+                    | PackageParser.PARSE_IS_PRIVILEGED,
+                    scanMode | SCAN_NO_DEX, 0);
+
+            // Collected privileged system packages.
+            File privilegedAppDir = new File(Environment.getRootDirectory(), "priv-app");
+            mPrivilegedInstallObserver = new AppDirObserver(
+                    privilegedAppDir.getPath(), OBSERVER_EVENTS, true, true);
+            mPrivilegedInstallObserver.startWatching();
+                scanDirLI(privilegedAppDir, PackageParser.PARSE_IS_SYSTEM
+                        | PackageParser.PARSE_IS_SYSTEM_DIR
+                        | PackageParser.PARSE_IS_PRIVILEGED, scanMode, 0);
+
+            // Collect ordinary system packages.
+            File systemAppDir = new File(Environment.getRootDirectory(), "app");
+            mSystemInstallObserver = new AppDirObserver(
+                systemAppDir.getPath(), OBSERVER_EVENTS, true, false);
+            mSystemInstallObserver.startWatching();
+            scanDirLI(systemAppDir, PackageParser.PARSE_IS_SYSTEM
+                    | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0);
+
+            // Collect all vendor packages.
+            File vendorAppDir = new File("/vendor/app");
+            mVendorInstallObserver = new AppDirObserver(
+                vendorAppDir.getPath(), OBSERVER_EVENTS, true, false);
+            mVendorInstallObserver.startWatching();
+            scanDirLI(vendorAppDir, PackageParser.PARSE_IS_SYSTEM
+                    | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0);
+
+            if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands");
+            mInstaller.moveFiles();
+
+            // Prune any system packages that no longer exist.
+            final List<String> possiblyDeletedUpdatedSystemApps = new ArrayList<String>();
+            if (!mOnlyCore) {
+                Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator();
+                while (psit.hasNext()) {
+                    PackageSetting ps = psit.next();
+
+                    /*
+                     * If this is not a system app, it can't be a
+                     * disable system app.
+                     */
+                    if ((ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
+                        continue;
+                    }
+
+                    /*
+                     * If the package is scanned, it's not erased.
+                     */
+                    final PackageParser.Package scannedPkg = mPackages.get(ps.name);
+                    if (scannedPkg != null) {
+                        /*
+                         * If the system app is both scanned and in the
+                         * disabled packages list, then it must have been
+                         * added via OTA. Remove it from the currently
+                         * scanned package so the previously user-installed
+                         * application can be scanned.
+                         */
+                        if (mSettings.isDisabledSystemPackageLPr(ps.name)) {
+                            Slog.i(TAG, "Expecting better updatd system app for " + ps.name
+                                    + "; removing system app");
+                            removePackageLI(ps, true);
+                        }
+
+                        continue;
+                    }
+
+                    if (!mSettings.isDisabledSystemPackageLPr(ps.name)) {
+                        psit.remove();
+                        String msg = "System package " + ps.name
+                                + " no longer exists; wiping its data";
+                        reportSettingsProblem(Log.WARN, msg);
+                        removeDataDirsLI(ps.name);
+                    } else {
+                        final PackageSetting disabledPs = mSettings.getDisabledSystemPkgLPr(ps.name);
+                        if (disabledPs.codePath == null || !disabledPs.codePath.exists()) {
+                            possiblyDeletedUpdatedSystemApps.add(ps.name);
+                        }
+                    }
+                }
+            }
+
+            //look for any incomplete package installations
+            ArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackagesLPr();
+            //clean up list
+            for(int i = 0; i < deletePkgsList.size(); i++) {
+                //clean up here
+                cleanupInstallFailedPackage(deletePkgsList.get(i));
+            }
+            //delete tmp files
+            deleteTempPackageFiles();
+
+            // Remove any shared userIDs that have no associated packages
+            mSettings.pruneSharedUsersLPw();
+
+            if (!mOnlyCore) {
+                EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START,
+                        SystemClock.uptimeMillis());
+                mAppInstallObserver = new AppDirObserver(
+                    mAppInstallDir.getPath(), OBSERVER_EVENTS, false, false);
+                mAppInstallObserver.startWatching();
+                scanDirLI(mAppInstallDir, 0, scanMode, 0);
+    
+                mDrmAppInstallObserver = new AppDirObserver(
+                    mDrmAppPrivateInstallDir.getPath(), OBSERVER_EVENTS, false, false);
+                mDrmAppInstallObserver.startWatching();
+                scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK,
+                        scanMode, 0);
+
+                /**
+                 * Remove disable package settings for any updated system
+                 * apps that were removed via an OTA. If they're not a
+                 * previously-updated app, remove them completely.
+                 * Otherwise, just revoke their system-level permissions.
+                 */
+                for (String deletedAppName : possiblyDeletedUpdatedSystemApps) {
+                    PackageParser.Package deletedPkg = mPackages.get(deletedAppName);
+                    mSettings.removeDisabledSystemPackageLPw(deletedAppName);
+
+                    String msg;
+                    if (deletedPkg == null) {
+                        msg = "Updated system package " + deletedAppName
+                                + " no longer exists; wiping its data";
+                        removeDataDirsLI(deletedAppName);
+                    } else {
+                        msg = "Updated system app + " + deletedAppName
+                                + " no longer present; removing system privileges for "
+                                + deletedAppName;
+
+                        deletedPkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM;
+
+                        PackageSetting deletedPs = mSettings.mPackages.get(deletedAppName);
+                        deletedPs.pkgFlags &= ~ApplicationInfo.FLAG_SYSTEM;
+                    }
+                    reportSettingsProblem(Log.WARN, msg);
+                }
+            } else {
+                mAppInstallObserver = null;
+                mDrmAppInstallObserver = null;
+            }
+
+            // Now that we know all of the shared libraries, update all clients to have
+            // the correct library paths.
+            updateAllSharedLibrariesLPw();
+
+            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SCAN_END,
+                    SystemClock.uptimeMillis());
+            Slog.i(TAG, "Time to scan packages: "
+                    + ((SystemClock.uptimeMillis()-startTime)/1000f)
+                    + " seconds");
+
+            // If the platform SDK has changed since the last time we booted,
+            // we need to re-grant app permission to catch any new ones that
+            // appear.  This is really a hack, and means that apps can in some
+            // cases get permissions that the user didn't initially explicitly
+            // allow...  it would be nice to have some better way to handle
+            // this situation.
+            final boolean regrantPermissions = mSettings.mInternalSdkPlatform
+                    != mSdkVersion;
+            if (regrantPermissions) Slog.i(TAG, "Platform changed from "
+                    + mSettings.mInternalSdkPlatform + " to " + mSdkVersion
+                    + "; regranting permissions for internal storage");
+            mSettings.mInternalSdkPlatform = mSdkVersion;
+            
+            updatePermissionsLPw(null, null, UPDATE_PERMISSIONS_ALL
+                    | (regrantPermissions
+                            ? (UPDATE_PERMISSIONS_REPLACE_PKG|UPDATE_PERMISSIONS_REPLACE_ALL)
+                            : 0));
+
+            // If this is the first boot, and it is a normal boot, then
+            // we need to initialize the default preferred apps.
+            if (!mRestoredSettings && !onlyCore) {
+                mSettings.readDefaultPreferredAppsLPw(this, 0);
+            }
+
+            // can downgrade to reader
+            mSettings.writeLPr();
+
+            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_READY,
+                    SystemClock.uptimeMillis());
+
+            // Now after opening every single application zip, make sure they
+            // are all flushed.  Not really needed, but keeps things nice and
+            // tidy.
+            Runtime.getRuntime().gc();
+
+            mRequiredVerifierPackage = getRequiredVerifierLPr();
+        } // synchronized (mPackages)
+        } // synchronized (mInstallLock)
+    }
+
+    public boolean isFirstBoot() {
+        return !mRestoredSettings;
+    }
+
+    public boolean isOnlyCoreApps() {
+        return mOnlyCore;
+    }
+
+    private String getRequiredVerifierLPr() {
+        final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
+        final List<ResolveInfo> receivers = queryIntentReceivers(verification, PACKAGE_MIME_TYPE,
+                PackageManager.GET_DISABLED_COMPONENTS, 0 /* TODO: Which userId? */);
+
+        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;
+
+            final PackageSetting ps = mSettings.mPackages.get(packageName);
+            if (ps == null) {
+                continue;
+            }
+
+            final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
+            if (!gp.grantedPermissions
+                    .contains(android.Manifest.permission.PACKAGE_VERIFICATION_AGENT)) {
+                continue;
+            }
+
+            if (requiredVerifier != null) {
+                throw new RuntimeException("There can be only one required verifier");
+            }
+
+            requiredVerifier = packageName;
+        }
+
+        return requiredVerifier;
+    }
+
+    @Override
+    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+            throws RemoteException {
+        try {
+            return super.onTransact(code, data, reply, flags);
+        } catch (RuntimeException e) {
+            if (!(e instanceof SecurityException) && !(e instanceof IllegalArgumentException)) {
+                Slog.wtf(TAG, "Package Manager Crash", e);
+            }
+            throw e;
+        }
+    }
+
+    void cleanupInstallFailedPackage(PackageSetting ps) {
+        Slog.i(TAG, "Cleaning up incompletely installed app: " + ps.name);
+        removeDataDirsLI(ps.name);
+        if (ps.codePath != null) {
+            if (!ps.codePath.delete()) {
+                Slog.w(TAG, "Unable to remove old code file: " + ps.codePath);
+            }
+        }
+        if (ps.resourcePath != null) {
+            if (!ps.resourcePath.delete() && !ps.resourcePath.equals(ps.codePath)) {
+                Slog.w(TAG, "Unable to remove old code file: " + ps.resourcePath);
+            }
+        }
+        mSettings.removePackageLPw(ps.name);
+    }
+
+    void readPermissions() {
+        // Read permissions from .../etc/permission directory.
+        File libraryDir = new File(Environment.getRootDirectory(), "etc/permissions");
+        if (!libraryDir.exists() || !libraryDir.isDirectory()) {
+            Slog.w(TAG, "No directory " + libraryDir + ", skipping");
+            return;
+        }
+        if (!libraryDir.canRead()) {
+            Slog.w(TAG, "Directory " + libraryDir + " cannot be read");
+            return;
+        }
+
+        // Iterate over the files in the directory and scan .xml files
+        for (File f : libraryDir.listFiles()) {
+            // We'll read platform.xml last
+            if (f.getPath().endsWith("etc/permissions/platform.xml")) {
+                continue;
+            }
+
+            if (!f.getPath().endsWith(".xml")) {
+                Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring");
+                continue;
+            }
+            if (!f.canRead()) {
+                Slog.w(TAG, "Permissions library file " + f + " cannot be read");
+                continue;
+            }
+
+            readPermissionsFromXml(f);
+        }
+
+        // Read permissions from .../etc/permissions/platform.xml last so it will take precedence
+        final File permFile = new File(Environment.getRootDirectory(),
+                "etc/permissions/platform.xml");
+        readPermissionsFromXml(permFile);
+    }
+
+    private void readPermissionsFromXml(File permFile) {
+        FileReader permReader = null;
+        try {
+            permReader = new FileReader(permFile);
+        } catch (FileNotFoundException e) {
+            Slog.w(TAG, "Couldn't find or open permissions file " + permFile);
+            return;
+        }
+
+        try {
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(permReader);
+
+            XmlUtils.beginDocument(parser, "permissions");
+
+            while (true) {
+                XmlUtils.nextElement(parser);
+                if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
+                    break;
+                }
+
+                String name = parser.getName();
+                if ("group".equals(name)) {
+                    String gidStr = parser.getAttributeValue(null, "gid");
+                    if (gidStr != null) {
+                        int gid = Process.getGidForName(gidStr);
+                        mGlobalGids = appendInt(mGlobalGids, gid);
+                    } else {
+                        Slog.w(TAG, "<group> without gid at "
+                                + parser.getPositionDescription());
+                    }
+
+                    XmlUtils.skipCurrentTag(parser);
+                    continue;
+                } else if ("permission".equals(name)) {
+                    String perm = parser.getAttributeValue(null, "name");
+                    if (perm == null) {
+                        Slog.w(TAG, "<permission> without name at "
+                                + parser.getPositionDescription());
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    perm = perm.intern();
+                    readPermission(parser, perm);
+
+                } else if ("assign-permission".equals(name)) {
+                    String perm = parser.getAttributeValue(null, "name");
+                    if (perm == null) {
+                        Slog.w(TAG, "<assign-permission> without name at "
+                                + parser.getPositionDescription());
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    String uidStr = parser.getAttributeValue(null, "uid");
+                    if (uidStr == null) {
+                        Slog.w(TAG, "<assign-permission> without uid at "
+                                + parser.getPositionDescription());
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    int uid = Process.getUidForName(uidStr);
+                    if (uid < 0) {
+                        Slog.w(TAG, "<assign-permission> with unknown uid \""
+                                + uidStr + "\" at "
+                                + parser.getPositionDescription());
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    perm = perm.intern();
+                    HashSet<String> perms = mSystemPermissions.get(uid);
+                    if (perms == null) {
+                        perms = new HashSet<String>();
+                        mSystemPermissions.put(uid, perms);
+                    }
+                    perms.add(perm);
+                    XmlUtils.skipCurrentTag(parser);
+
+                } else if ("library".equals(name)) {
+                    String lname = parser.getAttributeValue(null, "name");
+                    String lfile = parser.getAttributeValue(null, "file");
+                    if (lname == null) {
+                        Slog.w(TAG, "<library> without name at "
+                                + parser.getPositionDescription());
+                    } else if (lfile == null) {
+                        Slog.w(TAG, "<library> without file at "
+                                + parser.getPositionDescription());
+                    } else {
+                        //Log.i(TAG, "Got library " + lname + " in " + lfile);
+                        mSharedLibraries.put(lname, new SharedLibraryEntry(lfile, null));
+                    }
+                    XmlUtils.skipCurrentTag(parser);
+                    continue;
+
+                } else if ("feature".equals(name)) {
+                    String fname = parser.getAttributeValue(null, "name");
+                    if (fname == null) {
+                        Slog.w(TAG, "<feature> without name at "
+                                + parser.getPositionDescription());
+                    } else {
+                        //Log.i(TAG, "Got feature " + fname);
+                        FeatureInfo fi = new FeatureInfo();
+                        fi.name = fname;
+                        mAvailableFeatures.put(fname, fi);
+                    }
+                    XmlUtils.skipCurrentTag(parser);
+                    continue;
+
+                } else {
+                    XmlUtils.skipCurrentTag(parser);
+                    continue;
+                }
+
+            }
+            permReader.close();
+        } catch (XmlPullParserException e) {
+            Slog.w(TAG, "Got execption parsing permissions.", e);
+        } catch (IOException e) {
+            Slog.w(TAG, "Got execption parsing permissions.", e);
+        }
+    }
+
+    void readPermission(XmlPullParser parser, String name)
+            throws IOException, XmlPullParserException {
+
+        name = name.intern();
+
+        BasePermission bp = mSettings.mPermissions.get(name);
+        if (bp == null) {
+            bp = new BasePermission(name, null, BasePermission.TYPE_BUILTIN);
+            mSettings.mPermissions.put(name, bp);
+        }
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+               && (type != XmlPullParser.END_TAG
+                       || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG
+                    || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if ("group".equals(tagName)) {
+                String gidStr = parser.getAttributeValue(null, "gid");
+                if (gidStr != null) {
+                    int gid = Process.getGidForName(gidStr);
+                    bp.gids = appendInt(bp.gids, gid);
+                } else {
+                    Slog.w(TAG, "<group> without gid at "
+                            + parser.getPositionDescription());
+                }
+            }
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    static int[] appendInts(int[] cur, int[] add) {
+        if (add == null) return cur;
+        if (cur == null) return add;
+        final int N = add.length;
+        for (int i=0; i<N; i++) {
+            cur = appendInt(cur, add[i]);
+        }
+        return cur;
+    }
+
+    static int[] removeInts(int[] cur, int[] rem) {
+        if (rem == null) return cur;
+        if (cur == null) return cur;
+        final int N = rem.length;
+        for (int i=0; i<N; i++) {
+            cur = removeInt(cur, rem[i]);
+        }
+        return cur;
+    }
+
+    PackageInfo generatePackageInfo(PackageParser.Package p, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        PackageInfo pi;
+        final PackageSetting ps = (PackageSetting) p.mExtras;
+        if (ps == null) {
+            return null;
+        }
+        final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
+        final PackageUserState state = ps.readUserState(userId);
+        return PackageParser.generatePackageInfo(p, gp.gids, flags,
+                ps.firstInstallTime, ps.lastUpdateTime, gp.grantedPermissions,
+                state, userId);
+    }
+
+    public boolean isPackageAvailable(String packageName, int userId) {
+        if (!sUserManager.exists(userId)) return false;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "is package available");
+        synchronized (mPackages) {
+            PackageParser.Package p = mPackages.get(packageName);
+            if (p != null) {
+                final PackageSetting ps = (PackageSetting) p.mExtras;
+                if (ps != null) {
+                    final PackageUserState state = ps.readUserState(userId);
+                    if (state != null) {
+                        return PackageParser.isAvailable(state);
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public PackageInfo getPackageInfo(String packageName, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get package info");
+        // reader
+        synchronized (mPackages) {
+            PackageParser.Package p = mPackages.get(packageName);
+            if (DEBUG_PACKAGE_INFO)
+                Log.v(TAG, "getPackageInfo " + packageName + ": " + p);
+            if (p != null) {
+                return generatePackageInfo(p, flags, userId);
+            }
+            if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
+                return generatePackageInfoFromSettingsLPw(packageName, flags, userId);
+            }
+        }
+        return null;
+    }
+
+    public String[] currentToCanonicalPackageNames(String[] names) {
+        String[] out = new String[names.length];
+        // reader
+        synchronized (mPackages) {
+            for (int i=names.length-1; i>=0; i--) {
+                PackageSetting ps = mSettings.mPackages.get(names[i]);
+                out[i] = ps != null && ps.realName != null ? ps.realName : names[i];
+            }
+        }
+        return out;
+    }
+    
+    public String[] canonicalToCurrentPackageNames(String[] names) {
+        String[] out = new String[names.length];
+        // reader
+        synchronized (mPackages) {
+            for (int i=names.length-1; i>=0; i--) {
+                String cur = mSettings.mRenamedPackages.get(names[i]);
+                out[i] = cur != null ? cur : names[i];
+            }
+        }
+        return out;
+    }
+
+    @Override
+    public int getPackageUid(String packageName, int userId) {
+        if (!sUserManager.exists(userId)) return -1;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get package uid");
+        // reader
+        synchronized (mPackages) {
+            PackageParser.Package p = mPackages.get(packageName);
+            if(p != null) {
+                return UserHandle.getUid(userId, p.applicationInfo.uid);
+            }
+            PackageSetting ps = mSettings.mPackages.get(packageName);
+            if((ps == null) || (ps.pkg == null) || (ps.pkg.applicationInfo == null)) {
+                return -1;
+            }
+            p = ps.pkg;
+            return p != null ? UserHandle.getUid(userId, p.applicationInfo.uid) : -1;
+        }
+    }
+
+    @Override
+    public int[] getPackageGids(String packageName) {
+        // reader
+        synchronized (mPackages) {
+            PackageParser.Package p = mPackages.get(packageName);
+            if (DEBUG_PACKAGE_INFO)
+                Log.v(TAG, "getPackageGids" + packageName + ": " + p);
+            if (p != null) {
+                final PackageSetting ps = (PackageSetting)p.mExtras;
+                return ps.getGids();
+            }
+        }
+        // stupid thing to indicate an error.
+        return new int[0];
+    }
+
+    static final PermissionInfo generatePermissionInfo(
+            BasePermission bp, int flags) {
+        if (bp.perm != null) {
+            return PackageParser.generatePermissionInfo(bp.perm, flags);
+        }
+        PermissionInfo pi = new PermissionInfo();
+        pi.name = bp.name;
+        pi.packageName = bp.sourcePackage;
+        pi.nonLocalizedLabel = bp.name;
+        pi.protectionLevel = bp.protectionLevel;
+        return pi;
+    }
+    
+    public PermissionInfo getPermissionInfo(String name, int flags) {
+        // reader
+        synchronized (mPackages) {
+            final BasePermission p = mSettings.mPermissions.get(name);
+            if (p != null) {
+                return generatePermissionInfo(p, flags);
+            }
+            return null;
+        }
+    }
+
+    public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) {
+        // reader
+        synchronized (mPackages) {
+            ArrayList<PermissionInfo> out = new ArrayList<PermissionInfo>(10);
+            for (BasePermission p : mSettings.mPermissions.values()) {
+                if (group == null) {
+                    if (p.perm == null || p.perm.info.group == null) {
+                        out.add(generatePermissionInfo(p, flags));
+                    }
+                } else {
+                    if (p.perm != null && group.equals(p.perm.info.group)) {
+                        out.add(PackageParser.generatePermissionInfo(p.perm, flags));
+                    }
+                }
+            }
+
+            if (out.size() > 0) {
+                return out;
+            }
+            return mPermissionGroups.containsKey(group) ? out : null;
+        }
+    }
+
+    public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) {
+        // reader
+        synchronized (mPackages) {
+            return PackageParser.generatePermissionGroupInfo(
+                    mPermissionGroups.get(name), flags);
+        }
+    }
+
+    public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
+        // reader
+        synchronized (mPackages) {
+            final int N = mPermissionGroups.size();
+            ArrayList<PermissionGroupInfo> out
+                    = new ArrayList<PermissionGroupInfo>(N);
+            for (PackageParser.PermissionGroup pg : mPermissionGroups.values()) {
+                out.add(PackageParser.generatePermissionGroupInfo(pg, flags));
+            }
+            return out;
+        }
+    }
+
+    private ApplicationInfo generateApplicationInfoFromSettingsLPw(String packageName, int flags,
+            int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        PackageSetting ps = mSettings.mPackages.get(packageName);
+        if (ps != null) {
+            if (ps.pkg == null) {
+                PackageInfo pInfo = generatePackageInfoFromSettingsLPw(packageName,
+                        flags, userId);
+                if (pInfo != null) {
+                    return pInfo.applicationInfo;
+                }
+                return null;
+            }
+            return PackageParser.generateApplicationInfo(ps.pkg, flags,
+                    ps.readUserState(userId), userId);
+        }
+        return null;
+    }
+
+    private PackageInfo generatePackageInfoFromSettingsLPw(String packageName, int flags,
+            int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        PackageSetting ps = mSettings.mPackages.get(packageName);
+        if (ps != null) {
+            PackageParser.Package pkg = ps.pkg;
+            if (pkg == null) {
+                if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) == 0) {
+                    return null;
+                }
+                pkg = new PackageParser.Package(packageName);
+                pkg.applicationInfo.packageName = packageName;
+                pkg.applicationInfo.flags = ps.pkgFlags | ApplicationInfo.FLAG_IS_DATA_ONLY;
+                pkg.applicationInfo.publicSourceDir = ps.resourcePathString;
+                pkg.applicationInfo.sourceDir = ps.codePathString;
+                pkg.applicationInfo.dataDir =
+                        getDataPathForPackage(packageName, 0).getPath();
+                pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString;
+            }
+            return generatePackageInfo(pkg, flags, userId);
+        }
+        return null;
+    }
+
+    @Override
+    public ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get application info");
+        // writer
+        synchronized (mPackages) {
+            PackageParser.Package p = mPackages.get(packageName);
+            if (DEBUG_PACKAGE_INFO) Log.v(
+                    TAG, "getApplicationInfo " + packageName
+                    + ": " + p);
+            if (p != null) {
+                PackageSetting ps = mSettings.mPackages.get(packageName);
+                if (ps == null) return null;
+                // Note: isEnabledLP() does not apply here - always return info
+                return PackageParser.generateApplicationInfo(
+                        p, flags, ps.readUserState(userId), userId);
+            }
+            if ("android".equals(packageName)||"system".equals(packageName)) {
+                return mAndroidApplication;
+            }
+            if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
+                return generateApplicationInfoFromSettingsLPw(packageName, flags, userId);
+            }
+        }
+        return null;
+    }
+
+
+    public void freeStorageAndNotify(final long freeStorageSize, final IPackageDataObserver observer) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CLEAR_APP_CACHE, null);
+        // Queue up an async operation since clearing cache may take a little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                mHandler.removeCallbacks(this);
+                int retCode = -1;
+                synchronized (mInstallLock) {
+                    retCode = mInstaller.freeCache(freeStorageSize);
+                    if (retCode < 0) {
+                        Slog.w(TAG, "Couldn't clear application caches");
+                    }
+                }
+                if (observer != null) {
+                    try {
+                        observer.onRemoveCompleted(null, (retCode >= 0));
+                    } catch (RemoteException e) {
+                        Slog.w(TAG, "RemoveException when invoking call back");
+                    }
+                }
+            }
+        });
+    }
+
+    public void freeStorage(final long freeStorageSize, final IntentSender pi) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CLEAR_APP_CACHE, null);
+        // Queue up an async operation since clearing cache may take a little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                mHandler.removeCallbacks(this);
+                int retCode = -1;
+                synchronized (mInstallLock) {
+                    retCode = mInstaller.freeCache(freeStorageSize);
+                    if (retCode < 0) {
+                        Slog.w(TAG, "Couldn't clear application caches");
+                    }
+                }
+                if(pi != null) {
+                    try {
+                        // Callback via pending intent
+                        int code = (retCode >= 0) ? 1 : 0;
+                        pi.sendIntent(null, code, null,
+                                null, null);
+                    } catch (SendIntentException e1) {
+                        Slog.i(TAG, "Failed to send pending intent");
+                    }
+                }
+            }
+        });
+    }
+
+    @Override
+    public ActivityInfo getActivityInfo(ComponentName component, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get activity info");
+        synchronized (mPackages) {
+            PackageParser.Activity a = mActivities.mActivities.get(component);
+
+            if (DEBUG_PACKAGE_INFO) Log.v(TAG, "getActivityInfo " + component + ": " + a);
+            if (a != null && mSettings.isEnabledLPr(a.info, flags, userId)) {
+                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
+                if (ps == null) return null;
+                return PackageParser.generateActivityInfo(a, flags, ps.readUserState(userId),
+                        userId);
+            }
+            if (mResolveComponentName.equals(component)) {
+                return mResolveActivity;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public ActivityInfo getReceiverInfo(ComponentName component, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get receiver info");
+        synchronized (mPackages) {
+            PackageParser.Activity a = mReceivers.mActivities.get(component);
+            if (DEBUG_PACKAGE_INFO) Log.v(
+                TAG, "getReceiverInfo " + component + ": " + a);
+            if (a != null && mSettings.isEnabledLPr(a.info, flags, userId)) {
+                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
+                if (ps == null) return null;
+                return PackageParser.generateActivityInfo(a, flags, ps.readUserState(userId),
+                        userId);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public ServiceInfo getServiceInfo(ComponentName component, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get service info");
+        synchronized (mPackages) {
+            PackageParser.Service s = mServices.mServices.get(component);
+            if (DEBUG_PACKAGE_INFO) Log.v(
+                TAG, "getServiceInfo " + component + ": " + s);
+            if (s != null && mSettings.isEnabledLPr(s.info, flags, userId)) {
+                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
+                if (ps == null) return null;
+                return PackageParser.generateServiceInfo(s, flags, ps.readUserState(userId),
+                        userId);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public ProviderInfo getProviderInfo(ComponentName component, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get provider info");
+        synchronized (mPackages) {
+            PackageParser.Provider p = mProviders.mProviders.get(component);
+            if (DEBUG_PACKAGE_INFO) Log.v(
+                TAG, "getProviderInfo " + component + ": " + p);
+            if (p != null && mSettings.isEnabledLPr(p.info, flags, userId)) {
+                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
+                if (ps == null) return null;
+                return PackageParser.generateProviderInfo(p, flags, ps.readUserState(userId),
+                        userId);
+            }
+        }
+        return null;
+    }
+
+    public String[] getSystemSharedLibraryNames() {
+        Set<String> libSet;
+        synchronized (mPackages) {
+            libSet = mSharedLibraries.keySet();
+            int size = libSet.size();
+            if (size > 0) {
+                String[] libs = new String[size];
+                libSet.toArray(libs);
+                return libs;
+            }
+        }
+        return null;
+    }
+
+    public FeatureInfo[] getSystemAvailableFeatures() {
+        Collection<FeatureInfo> featSet;
+        synchronized (mPackages) {
+            featSet = mAvailableFeatures.values();
+            int size = featSet.size();
+            if (size > 0) {
+                FeatureInfo[] features = new FeatureInfo[size+1];
+                featSet.toArray(features);
+                FeatureInfo fi = new FeatureInfo();
+                fi.reqGlEsVersion = SystemProperties.getInt("ro.opengles.version",
+                        FeatureInfo.GL_ES_VERSION_UNDEFINED);
+                features[size] = fi;
+                return features;
+            }
+        }
+        return null;
+    }
+
+    public boolean hasSystemFeature(String name) {
+        synchronized (mPackages) {
+            return mAvailableFeatures.containsKey(name);
+        }
+    }
+
+    private void checkValidCaller(int uid, int userId) {
+        if (UserHandle.getUserId(uid) == userId || uid == Process.SYSTEM_UID || uid == 0)
+            return;
+
+        throw new SecurityException("Caller uid=" + uid
+                + " is not privileged to communicate with user=" + userId);
+    }
+
+    public int checkPermission(String permName, String pkgName) {
+        synchronized (mPackages) {
+            PackageParser.Package p = mPackages.get(pkgName);
+            if (p != null && p.mExtras != null) {
+                PackageSetting ps = (PackageSetting)p.mExtras;
+                if (ps.sharedUser != null) {
+                    if (ps.sharedUser.grantedPermissions.contains(permName)) {
+                        return PackageManager.PERMISSION_GRANTED;
+                    }
+                } else if (ps.grantedPermissions.contains(permName)) {
+                    return PackageManager.PERMISSION_GRANTED;
+                }
+            }
+        }
+        return PackageManager.PERMISSION_DENIED;
+    }
+
+    public int checkUidPermission(String permName, int uid) {
+        synchronized (mPackages) {
+            Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
+            if (obj != null) {
+                GrantedPermissions gp = (GrantedPermissions)obj;
+                if (gp.grantedPermissions.contains(permName)) {
+                    return PackageManager.PERMISSION_GRANTED;
+                }
+            } else {
+                HashSet<String> perms = mSystemPermissions.get(uid);
+                if (perms != null && perms.contains(permName)) {
+                    return PackageManager.PERMISSION_GRANTED;
+                }
+            }
+        }
+        return PackageManager.PERMISSION_DENIED;
+    }
+
+    /**
+     * Checks if the request is from the system or an app that has INTERACT_ACROSS_USERS
+     * or INTERACT_ACROSS_USERS_FULL permissions, if the userid is not for the caller.
+     * @param message the message to log on security exception
+     * @return
+     */
+    private void enforceCrossUserPermission(int callingUid, int userId,
+            boolean requireFullPermission, String message) {
+        if (userId < 0) {
+            throw new IllegalArgumentException("Invalid userId " + userId);
+        }
+        if (userId == UserHandle.getUserId(callingUid)) return;
+        if (callingUid != Process.SYSTEM_UID && callingUid != 0) {
+            if (requireFullPermission) {
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
+            } else {
+                try {
+                    mContext.enforceCallingOrSelfPermission(
+                            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
+                } catch (SecurityException se) {
+                    mContext.enforceCallingOrSelfPermission(
+                            android.Manifest.permission.INTERACT_ACROSS_USERS, message);
+                }
+            }
+        }
+    }
+
+    private BasePermission findPermissionTreeLP(String permName) {
+        for(BasePermission bp : mSettings.mPermissionTrees.values()) {
+            if (permName.startsWith(bp.name) &&
+                    permName.length() > bp.name.length() &&
+                    permName.charAt(bp.name.length()) == '.') {
+                return bp;
+            }
+        }
+        return null;
+    }
+
+    private BasePermission checkPermissionTreeLP(String permName) {
+        if (permName != null) {
+            BasePermission bp = findPermissionTreeLP(permName);
+            if (bp != null) {
+                if (bp.uid == UserHandle.getAppId(Binder.getCallingUid())) {
+                    return bp;
+                }
+                throw new SecurityException("Calling uid "
+                        + Binder.getCallingUid()
+                        + " is not allowed to add to permission tree "
+                        + bp.name + " owned by uid " + bp.uid);
+            }
+        }
+        throw new SecurityException("No permission tree found for " + permName);
+    }
+
+    static boolean compareStrings(CharSequence s1, CharSequence s2) {
+        if (s1 == null) {
+            return s2 == null;
+        }
+        if (s2 == null) {
+            return false;
+        }
+        if (s1.getClass() != s2.getClass()) {
+            return false;
+        }
+        return s1.equals(s2);
+    }
+    
+    static boolean comparePermissionInfos(PermissionInfo pi1, PermissionInfo pi2) {
+        if (pi1.icon != pi2.icon) return false;
+        if (pi1.logo != pi2.logo) return false;
+        if (pi1.protectionLevel != pi2.protectionLevel) return false;
+        if (!compareStrings(pi1.name, pi2.name)) return false;
+        if (!compareStrings(pi1.nonLocalizedLabel, pi2.nonLocalizedLabel)) return false;
+        // We'll take care of setting this one.
+        if (!compareStrings(pi1.packageName, pi2.packageName)) return false;
+        // These are not currently stored in settings.
+        //if (!compareStrings(pi1.group, pi2.group)) return false;
+        //if (!compareStrings(pi1.nonLocalizedDescription, pi2.nonLocalizedDescription)) return false;
+        //if (pi1.labelRes != pi2.labelRes) return false;
+        //if (pi1.descriptionRes != pi2.descriptionRes) return false;
+        return true;
+    }
+    
+    boolean addPermissionLocked(PermissionInfo info, boolean async) {
+        if (info.labelRes == 0 && info.nonLocalizedLabel == null) {
+            throw new SecurityException("Label must be specified in permission");
+        }
+        BasePermission tree = checkPermissionTreeLP(info.name);
+        BasePermission bp = mSettings.mPermissions.get(info.name);
+        boolean added = bp == null;
+        boolean changed = true;
+        int fixedLevel = PermissionInfo.fixProtectionLevel(info.protectionLevel);
+        if (added) {
+            bp = new BasePermission(info.name, tree.sourcePackage,
+                    BasePermission.TYPE_DYNAMIC);
+        } else if (bp.type != BasePermission.TYPE_DYNAMIC) {
+            throw new SecurityException(
+                    "Not allowed to modify non-dynamic permission "
+                    + info.name);
+        } else {
+            if (bp.protectionLevel == fixedLevel
+                    && bp.perm.owner.equals(tree.perm.owner)
+                    && bp.uid == tree.uid
+                    && comparePermissionInfos(bp.perm.info, info)) {
+                changed = false;
+            }
+        }
+        bp.protectionLevel = fixedLevel;
+        info = new PermissionInfo(info);
+        info.protectionLevel = fixedLevel;
+        bp.perm = new PackageParser.Permission(tree.perm.owner, info);
+        bp.perm.info.packageName = tree.perm.info.packageName;
+        bp.uid = tree.uid;
+        if (added) {
+            mSettings.mPermissions.put(info.name, bp);
+        }
+        if (changed) {
+            if (!async) {
+                mSettings.writeLPr();
+            } else {
+                scheduleWriteSettingsLocked();
+            }
+        }
+        return added;
+    }
+
+    public boolean addPermission(PermissionInfo info) {
+        synchronized (mPackages) {
+            return addPermissionLocked(info, false);
+        }
+    }
+
+    public boolean addPermissionAsync(PermissionInfo info) {
+        synchronized (mPackages) {
+            return addPermissionLocked(info, true);
+        }
+    }
+
+    public void removePermission(String name) {
+        synchronized (mPackages) {
+            checkPermissionTreeLP(name);
+            BasePermission bp = mSettings.mPermissions.get(name);
+            if (bp != null) {
+                if (bp.type != BasePermission.TYPE_DYNAMIC) {
+                    throw new SecurityException(
+                            "Not allowed to modify non-dynamic permission "
+                            + name);
+                }
+                mSettings.mPermissions.remove(name);
+                mSettings.writeLPr();
+            }
+        }
+    }
+
+    private static void checkGrantRevokePermissions(PackageParser.Package pkg, BasePermission bp) {
+        int index = pkg.requestedPermissions.indexOf(bp.name);
+        if (index == -1) {
+            throw new SecurityException("Package " + pkg.packageName
+                    + " has not requested permission " + bp.name);
+        }
+        boolean isNormal =
+                ((bp.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE)
+                        == PermissionInfo.PROTECTION_NORMAL);
+        boolean isDangerous =
+                ((bp.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE)
+                        == PermissionInfo.PROTECTION_DANGEROUS);
+        boolean isDevelopment =
+                ((bp.protectionLevel&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
+
+        if (!isNormal && !isDangerous && !isDevelopment) {
+            throw new SecurityException("Permission " + bp.name
+                    + " is not a changeable permission type");
+        }
+
+        if (isNormal || isDangerous) {
+            if (pkg.requestedPermissionsRequired.get(index)) {
+                throw new SecurityException("Can't change " + bp.name
+                        + ". It is required by the application");
+            }
+        }
+    }
+
+    public void grantPermission(String packageName, String permissionName) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.GRANT_REVOKE_PERMISSIONS, null);
+        synchronized (mPackages) {
+            final PackageParser.Package pkg = mPackages.get(packageName);
+            if (pkg == null) {
+                throw new IllegalArgumentException("Unknown package: " + packageName);
+            }
+            final BasePermission bp = mSettings.mPermissions.get(permissionName);
+            if (bp == null) {
+                throw new IllegalArgumentException("Unknown permission: " + permissionName);
+            }
+
+            checkGrantRevokePermissions(pkg, bp);
+
+            final PackageSetting ps = (PackageSetting) pkg.mExtras;
+            if (ps == null) {
+                return;
+            }
+            final GrantedPermissions gp = (ps.sharedUser != null) ? ps.sharedUser : ps;
+            if (gp.grantedPermissions.add(permissionName)) {
+                if (ps.haveGids) {
+                    gp.gids = appendInts(gp.gids, bp.gids);
+                }
+                mSettings.writeLPr();
+            }
+        }
+    }
+
+    public void revokePermission(String packageName, String permissionName) {
+        int changedAppId = -1;
+
+        synchronized (mPackages) {
+            final PackageParser.Package pkg = mPackages.get(packageName);
+            if (pkg == null) {
+                throw new IllegalArgumentException("Unknown package: " + packageName);
+            }
+            if (pkg.applicationInfo.uid != Binder.getCallingUid()) {
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.GRANT_REVOKE_PERMISSIONS, null);
+            }
+            final BasePermission bp = mSettings.mPermissions.get(permissionName);
+            if (bp == null) {
+                throw new IllegalArgumentException("Unknown permission: " + permissionName);
+            }
+
+            checkGrantRevokePermissions(pkg, bp);
+
+            final PackageSetting ps = (PackageSetting) pkg.mExtras;
+            if (ps == null) {
+                return;
+            }
+            final GrantedPermissions gp = (ps.sharedUser != null) ? ps.sharedUser : ps;
+            if (gp.grantedPermissions.remove(permissionName)) {
+                gp.grantedPermissions.remove(permissionName);
+                if (ps.haveGids) {
+                    gp.gids = removeInts(gp.gids, bp.gids);
+                }
+                mSettings.writeLPr();
+                changedAppId = ps.appId;
+            }
+        }
+
+        if (changedAppId >= 0) {
+            // We changed the perm on someone, kill its processes.
+            IActivityManager am = ActivityManagerNative.getDefault();
+            if (am != null) {
+                final int callingUserId = UserHandle.getCallingUserId();
+                final long ident = Binder.clearCallingIdentity();
+                try {
+                    //XXX we should only revoke for the calling user's app permissions,
+                    // but for now we impact all users.
+                    //am.killUid(UserHandle.getUid(callingUserId, changedAppId),
+                    //        "revoke " + permissionName);
+                    int[] users = sUserManager.getUserIds();
+                    for (int user : users) {
+                        am.killUid(UserHandle.getUid(user, changedAppId),
+                                "revoke " + permissionName);
+                    }
+                } catch (RemoteException e) {
+                } finally {
+                    Binder.restoreCallingIdentity(ident);
+                }
+            }
+        }
+    }
+
+    public boolean isProtectedBroadcast(String actionName) {
+        synchronized (mPackages) {
+            return mProtectedBroadcasts.contains(actionName);
+        }
+    }
+
+    public int checkSignatures(String pkg1, String pkg2) {
+        synchronized (mPackages) {
+            final PackageParser.Package p1 = mPackages.get(pkg1);
+            final PackageParser.Package p2 = mPackages.get(pkg2);
+            if (p1 == null || p1.mExtras == null
+                    || p2 == null || p2.mExtras == null) {
+                return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
+            }
+            return compareSignatures(p1.mSignatures, p2.mSignatures);
+        }
+    }
+
+    public int checkUidSignatures(int uid1, int uid2) {
+        // Map to base uids.
+        uid1 = UserHandle.getAppId(uid1);
+        uid2 = UserHandle.getAppId(uid2);
+        // reader
+        synchronized (mPackages) {
+            Signature[] s1;
+            Signature[] s2;
+            Object obj = mSettings.getUserIdLPr(uid1);
+            if (obj != null) {
+                if (obj instanceof SharedUserSetting) {
+                    s1 = ((SharedUserSetting)obj).signatures.mSignatures;
+                } else if (obj instanceof PackageSetting) {
+                    s1 = ((PackageSetting)obj).signatures.mSignatures;
+                } else {
+                    return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
+                }
+            } else {
+                return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
+            }
+            obj = mSettings.getUserIdLPr(uid2);
+            if (obj != null) {
+                if (obj instanceof SharedUserSetting) {
+                    s2 = ((SharedUserSetting)obj).signatures.mSignatures;
+                } else if (obj instanceof PackageSetting) {
+                    s2 = ((PackageSetting)obj).signatures.mSignatures;
+                } else {
+                    return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
+                }
+            } else {
+                return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
+            }
+            return compareSignatures(s1, s2);
+        }
+    }
+
+    /**
+     * Compares two sets of signatures. Returns:
+     * <br />
+     * {@link PackageManager#SIGNATURE_NEITHER_SIGNED}: if both signature sets are null,
+     * <br />
+     * {@link PackageManager#SIGNATURE_FIRST_NOT_SIGNED}: if the first signature set is null,
+     * <br />
+     * {@link PackageManager#SIGNATURE_SECOND_NOT_SIGNED}: if the second signature set is null,
+     * <br />
+     * {@link PackageManager#SIGNATURE_MATCH}: if the two signature sets are identical,
+     * <br />
+     * {@link PackageManager#SIGNATURE_NO_MATCH}: if the two signature sets differ.
+     */
+    static int compareSignatures(Signature[] s1, Signature[] s2) {
+        if (s1 == null) {
+            return s2 == null
+                    ? PackageManager.SIGNATURE_NEITHER_SIGNED
+                    : PackageManager.SIGNATURE_FIRST_NOT_SIGNED;
+        }
+
+        if (s2 == null) {
+            return PackageManager.SIGNATURE_SECOND_NOT_SIGNED;
+        }
+
+        if (s1.length != s2.length) {
+            return PackageManager.SIGNATURE_NO_MATCH;
+        }
+
+        // Since both signature sets are of size 1, we can compare without HashSets.
+        if (s1.length == 1) {
+            return s1[0].equals(s2[0]) ?
+                    PackageManager.SIGNATURE_MATCH :
+                    PackageManager.SIGNATURE_NO_MATCH;
+        }
+
+        HashSet<Signature> set1 = new HashSet<Signature>();
+        for (Signature sig : s1) {
+            set1.add(sig);
+        }
+        HashSet<Signature> set2 = new HashSet<Signature>();
+        for (Signature sig : s2) {
+            set2.add(sig);
+        }
+        // Make sure s2 contains all signatures in s1.
+        if (set1.equals(set2)) {
+            return PackageManager.SIGNATURE_MATCH;
+        }
+        return PackageManager.SIGNATURE_NO_MATCH;
+    }
+
+    public String[] getPackagesForUid(int uid) {
+        uid = UserHandle.getAppId(uid);
+        // reader
+        synchronized (mPackages) {
+            Object obj = mSettings.getUserIdLPr(uid);
+            if (obj instanceof SharedUserSetting) {
+                final SharedUserSetting sus = (SharedUserSetting) obj;
+                final int N = sus.packages.size();
+                final String[] res = new String[N];
+                final Iterator<PackageSetting> it = sus.packages.iterator();
+                int i = 0;
+                while (it.hasNext()) {
+                    res[i++] = it.next().name;
+                }
+                return res;
+            } else if (obj instanceof PackageSetting) {
+                final PackageSetting ps = (PackageSetting) obj;
+                return new String[] { ps.name };
+            }
+        }
+        return null;
+    }
+
+    public String getNameForUid(int uid) {
+        // reader
+        synchronized (mPackages) {
+            Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
+            if (obj instanceof SharedUserSetting) {
+                final SharedUserSetting sus = (SharedUserSetting) obj;
+                return sus.name + ":" + sus.userId;
+            } else if (obj instanceof PackageSetting) {
+                final PackageSetting ps = (PackageSetting) obj;
+                return ps.name;
+            }
+        }
+        return null;
+    }
+
+    public int getUidForSharedUser(String sharedUserName) {
+        if(sharedUserName == null) {
+            return -1;
+        }
+        // reader
+        synchronized (mPackages) {
+            final SharedUserSetting suid = mSettings.getSharedUserLPw(sharedUserName, 0, false);
+            if (suid == null) {
+                return -1;
+            }
+            return suid.userId;
+        }
+    }
+
+    public int getFlagsForUid(int uid) {
+        synchronized (mPackages) {
+            Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
+            if (obj instanceof SharedUserSetting) {
+                final SharedUserSetting sus = (SharedUserSetting) obj;
+                return sus.pkgFlags;
+            } else if (obj instanceof PackageSetting) {
+                final PackageSetting ps = (PackageSetting) obj;
+                return ps.pkgFlags;
+            }
+        }
+        return 0;
+    }
+
+    @Override
+    public ResolveInfo resolveIntent(Intent intent, String resolvedType,
+            int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "resolve intent");
+        List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
+        return chooseBestActivity(intent, resolvedType, flags, query, userId);
+    }
+
+    @Override
+    public void setLastChosenActivity(Intent intent, String resolvedType, int flags,
+            IntentFilter filter, int match, ComponentName activity) {
+        final int userId = UserHandle.getCallingUserId();
+        if (DEBUG_PREFERRED) {
+            Log.v(TAG, "setLastChosenActivity intent=" + intent
+                + " resolvedType=" + resolvedType
+                + " flags=" + flags
+                + " filter=" + filter
+                + " match=" + match
+                + " activity=" + activity);
+            filter.dump(new PrintStreamPrinter(System.out), "    ");
+        }
+        intent.setComponent(null);
+        List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
+        // Find any earlier preferred or last chosen entries and nuke them
+        findPreferredActivity(intent, resolvedType,
+                flags, query, 0, false, true, false, userId);
+        // Add the new activity as the last chosen for this filter
+        addPreferredActivityInternal(filter, match, null, activity, false, userId);
+    }
+
+    @Override
+    public ResolveInfo getLastChosenActivity(Intent intent, String resolvedType, int flags) {
+        final int userId = UserHandle.getCallingUserId();
+        if (DEBUG_PREFERRED) Log.v(TAG, "Querying last chosen activity for " + intent);
+        List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
+        return findPreferredActivity(intent, resolvedType, flags, query, 0,
+                false, false, false, userId);
+    }
+
+    private ResolveInfo chooseBestActivity(Intent intent, String resolvedType,
+            int flags, List<ResolveInfo> query, int userId) {
+        if (query != null) {
+            final int N = query.size();
+            if (N == 1) {
+                return query.get(0);
+            } else if (N > 1) {
+                final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);
+                // If there is more than one activity with the same priority,
+                // then let the user decide between them.
+                ResolveInfo r0 = query.get(0);
+                ResolveInfo r1 = query.get(1);
+                if (DEBUG_INTENT_MATCHING || debug) {
+                    Slog.v(TAG, r0.activityInfo.name + "=" + r0.priority + " vs "
+                            + r1.activityInfo.name + "=" + r1.priority);
+                }
+                // If the first activity has a higher priority, or a different
+                // default, then it is always desireable to pick it.
+                if (r0.priority != r1.priority
+                        || r0.preferredOrder != r1.preferredOrder
+                        || r0.isDefault != r1.isDefault) {
+                    return query.get(0);
+                }
+                // If we have saved a preference for a preferred activity for
+                // this Intent, use that.
+                ResolveInfo ri = findPreferredActivity(intent, resolvedType,
+                        flags, query, r0.priority, true, false, debug, userId);
+                if (ri != null) {
+                    return ri;
+                }
+                if (userId != 0) {
+                    ri = new ResolveInfo(mResolveInfo);
+                    ri.activityInfo = new ActivityInfo(ri.activityInfo);
+                    ri.activityInfo.applicationInfo = new ApplicationInfo(
+                            ri.activityInfo.applicationInfo);
+                    ri.activityInfo.applicationInfo.uid = UserHandle.getUid(userId,
+                            UserHandle.getAppId(ri.activityInfo.applicationInfo.uid));
+                    return ri;
+                }
+                return mResolveInfo;
+            }
+        }
+        return null;
+    }
+
+    ResolveInfo findPreferredActivity(Intent intent, String resolvedType, int flags,
+            List<ResolveInfo> query, int priority, boolean always,
+            boolean removeMatches, boolean debug, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        // writer
+        synchronized (mPackages) {
+            if (intent.getSelector() != null) {
+                intent = intent.getSelector();
+            }
+            if (DEBUG_PREFERRED) intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
+            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
+            // Get the list of preferred activities that handle the intent
+            if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Looking for preferred activities...");
+            List<PreferredActivity> prefs = pir != null
+                    ? pir.queryIntent(intent, resolvedType,
+                            (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId)
+                    : null;
+            if (prefs != null && prefs.size() > 0) {
+                // First figure out how good the original match set is.
+                // We will only allow preferred activities that came
+                // from the same match quality.
+                int match = 0;
+
+                if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Figuring out best match...");
+
+                final int N = query.size();
+                for (int j=0; j<N; j++) {
+                    final ResolveInfo ri = query.get(j);
+                    if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Match for " + ri.activityInfo
+                            + ": 0x" + Integer.toHexString(match));
+                    if (ri.match > match) {
+                        match = ri.match;
+                    }
+                }
+
+                if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Best match: 0x"
+                        + Integer.toHexString(match));
+
+                match &= IntentFilter.MATCH_CATEGORY_MASK;
+                final int M = prefs.size();
+                for (int i=0; i<M; i++) {
+                    final PreferredActivity pa = prefs.get(i);
+                    if (DEBUG_PREFERRED || debug) {
+                        Slog.v(TAG, "Checking PreferredActivity ds="
+                                + (pa.countDataSchemes() > 0 ? pa.getDataScheme(0) : "<none>")
+                                + "\n  component=" + pa.mPref.mComponent);
+                        pa.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
+                    }
+                    if (pa.mPref.mMatch != match) {
+                        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Skipping bad match "
+                                + Integer.toHexString(pa.mPref.mMatch));
+                        continue;
+                    }
+                    // If it's not an "always" type preferred activity and that's what we're
+                    // looking for, skip it.
+                    if (always && !pa.mPref.mAlways) {
+                        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Skipping mAlways=false entry");
+                        continue;
+                    }
+                    final ActivityInfo ai = getActivityInfo(pa.mPref.mComponent,
+                            flags | PackageManager.GET_DISABLED_COMPONENTS, userId);
+                    if (DEBUG_PREFERRED || debug) {
+                        Slog.v(TAG, "Found preferred activity:");
+                        if (ai != null) {
+                            ai.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
+                        } else {
+                            Slog.v(TAG, "  null");
+                        }
+                    }
+                    if (ai == null) {
+                        // This previously registered preferred activity
+                        // component is no longer known.  Most likely an update
+                        // to the app was installed and in the new version this
+                        // component no longer exists.  Clean it up by removing
+                        // it from the preferred activities list, and skip it.
+                        Slog.w(TAG, "Removing dangling preferred activity: "
+                                + pa.mPref.mComponent);
+                        pir.removeFilter(pa);
+                        continue;
+                    }
+                    for (int j=0; j<N; j++) {
+                        final ResolveInfo ri = query.get(j);
+                        if (!ri.activityInfo.applicationInfo.packageName
+                                .equals(ai.applicationInfo.packageName)) {
+                            continue;
+                        }
+                        if (!ri.activityInfo.name.equals(ai.name)) {
+                            continue;
+                        }
+
+                        if (removeMatches) {
+                            pir.removeFilter(pa);
+                            if (DEBUG_PREFERRED) {
+                                Slog.v(TAG, "Removing match " + pa.mPref.mComponent);
+                            }
+                            break;
+                        }
+
+                        // Okay we found a previously set preferred or last chosen app.
+                        // If the result set is different from when this
+                        // was created, we need to clear it and re-ask the
+                        // user their preference, if we're looking for an "always" type entry.
+                        if (always && !pa.mPref.sameSet(query, priority)) {
+                            Slog.i(TAG, "Result set changed, dropping preferred activity for "
+                                    + intent + " type " + resolvedType);
+                            if (DEBUG_PREFERRED) {
+                                Slog.v(TAG, "Removing preferred activity since set changed "
+                                        + pa.mPref.mComponent);
+                            }
+                            pir.removeFilter(pa);
+                            // Re-add the filter as a "last chosen" entry (!always)
+                            PreferredActivity lastChosen = new PreferredActivity(
+                                    pa, pa.mPref.mMatch, null, pa.mPref.mComponent, false);
+                            pir.addFilter(lastChosen);
+                            mSettings.writePackageRestrictionsLPr(userId);
+                            return null;
+                        }
+
+                        // Yay! Either the set matched or we're looking for the last chosen
+                        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Returning preferred activity: "
+                                + ri.activityInfo.packageName + "/" + ri.activityInfo.name);
+                        mSettings.writePackageRestrictionsLPr(userId);
+                        return ri;
+                    }
+                }
+            }
+            mSettings.writePackageRestrictionsLPr(userId);
+        }
+        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "No preferred activity to return");
+        return null;
+    }
+
+    @Override
+    public List<ResolveInfo> queryIntentActivities(Intent intent,
+            String resolvedType, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return Collections.emptyList();
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "query intent activities");
+        ComponentName comp = intent.getComponent();
+        if (comp == null) {
+            if (intent.getSelector() != null) {
+                intent = intent.getSelector(); 
+                comp = intent.getComponent();
+            }
+        }
+
+        if (comp != null) {
+            final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
+            final ActivityInfo ai = getActivityInfo(comp, flags, userId);
+            if (ai != null) {
+                final ResolveInfo ri = new ResolveInfo();
+                ri.activityInfo = ai;
+                list.add(ri);
+            }
+            return list;
+        }
+
+        // reader
+        synchronized (mPackages) {
+            final String pkgName = intent.getPackage();
+            if (pkgName == null) {
+                return mActivities.queryIntent(intent, resolvedType, flags, userId);
+            }
+            final PackageParser.Package pkg = mPackages.get(pkgName);
+            if (pkg != null) {
+                return mActivities.queryIntentForPackage(intent, resolvedType, flags,
+                        pkg.activities, userId);
+            }
+            return new ArrayList<ResolveInfo>();
+        }
+    }
+
+    @Override
+    public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller,
+            Intent[] specifics, String[] specificTypes, Intent intent,
+            String resolvedType, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return Collections.emptyList();
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, false,
+                "query intent activity options");
+        final String resultsAction = intent.getAction();
+
+        List<ResolveInfo> results = queryIntentActivities(intent, resolvedType, flags
+                | PackageManager.GET_RESOLVED_FILTER, userId);
+
+        if (DEBUG_INTENT_MATCHING) {
+            Log.v(TAG, "Query " + intent + ": " + results);
+        }
+
+        int specificsPos = 0;
+        int N;
+
+        // todo: note that the algorithm used here is O(N^2).  This
+        // isn't a problem in our current environment, but if we start running
+        // into situations where we have more than 5 or 10 matches then this
+        // should probably be changed to something smarter...
+
+        // First we go through and resolve each of the specific items
+        // that were supplied, taking care of removing any corresponding
+        // duplicate items in the generic resolve list.
+        if (specifics != null) {
+            for (int i=0; i<specifics.length; i++) {
+                final Intent sintent = specifics[i];
+                if (sintent == null) {
+                    continue;
+                }
+
+                if (DEBUG_INTENT_MATCHING) {
+                    Log.v(TAG, "Specific #" + i + ": " + sintent);
+                }
+
+                String action = sintent.getAction();
+                if (resultsAction != null && resultsAction.equals(action)) {
+                    // If this action was explicitly requested, then don't
+                    // remove things that have it.
+                    action = null;
+                }
+
+                ResolveInfo ri = null;
+                ActivityInfo ai = null;
+
+                ComponentName comp = sintent.getComponent();
+                if (comp == null) {
+                    ri = resolveIntent(
+                        sintent,
+                        specificTypes != null ? specificTypes[i] : null,
+                            flags, userId);
+                    if (ri == null) {
+                        continue;
+                    }
+                    if (ri == mResolveInfo) {
+                        // ACK!  Must do something better with this.
+                    }
+                    ai = ri.activityInfo;
+                    comp = new ComponentName(ai.applicationInfo.packageName,
+                            ai.name);
+                } else {
+                    ai = getActivityInfo(comp, flags, userId);
+                    if (ai == null) {
+                        continue;
+                    }
+                }
+
+                // Look for any generic query activities that are duplicates
+                // of this specific one, and remove them from the results.
+                if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Specific #" + i + ": " + ai);
+                N = results.size();
+                int j;
+                for (j=specificsPos; j<N; j++) {
+                    ResolveInfo sri = results.get(j);
+                    if ((sri.activityInfo.name.equals(comp.getClassName())
+                            && sri.activityInfo.applicationInfo.packageName.equals(
+                                    comp.getPackageName()))
+                        || (action != null && sri.filter.matchAction(action))) {
+                        results.remove(j);
+                        if (DEBUG_INTENT_MATCHING) Log.v(
+                            TAG, "Removing duplicate item from " + j
+                            + " due to specific " + specificsPos);
+                        if (ri == null) {
+                            ri = sri;
+                        }
+                        j--;
+                        N--;
+                    }
+                }
+
+                // Add this specific item to its proper place.
+                if (ri == null) {
+                    ri = new ResolveInfo();
+                    ri.activityInfo = ai;
+                }
+                results.add(specificsPos, ri);
+                ri.specificIndex = i;
+                specificsPos++;
+            }
+        }
+
+        // Now we go through the remaining generic results and remove any
+        // duplicate actions that are found here.
+        N = results.size();
+        for (int i=specificsPos; i<N-1; i++) {
+            final ResolveInfo rii = results.get(i);
+            if (rii.filter == null) {
+                continue;
+            }
+
+            // Iterate over all of the actions of this result's intent
+            // filter...  typically this should be just one.
+            final Iterator<String> it = rii.filter.actionsIterator();
+            if (it == null) {
+                continue;
+            }
+            while (it.hasNext()) {
+                final String action = it.next();
+                if (resultsAction != null && resultsAction.equals(action)) {
+                    // If this action was explicitly requested, then don't
+                    // remove things that have it.
+                    continue;
+                }
+                for (int j=i+1; j<N; j++) {
+                    final ResolveInfo rij = results.get(j);
+                    if (rij.filter != null && rij.filter.hasAction(action)) {
+                        results.remove(j);
+                        if (DEBUG_INTENT_MATCHING) Log.v(
+                            TAG, "Removing duplicate item from " + j
+                            + " due to action " + action + " at " + i);
+                        j--;
+                        N--;
+                    }
+                }
+            }
+
+            // If the caller didn't request filter information, drop it now
+            // so we don't have to marshall/unmarshall it.
+            if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) {
+                rii.filter = null;
+            }
+        }
+
+        // Filter out the caller activity if so requested.
+        if (caller != null) {
+            N = results.size();
+            for (int i=0; i<N; i++) {
+                ActivityInfo ainfo = results.get(i).activityInfo;
+                if (caller.getPackageName().equals(ainfo.applicationInfo.packageName)
+                        && caller.getClassName().equals(ainfo.name)) {
+                    results.remove(i);
+                    break;
+                }
+            }
+        }
+
+        // If the caller didn't request filter information,
+        // drop them now so we don't have to
+        // marshall/unmarshall it.
+        if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) {
+            N = results.size();
+            for (int i=0; i<N; i++) {
+                results.get(i).filter = null;
+            }
+        }
+
+        if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Result: " + results);
+        return results;
+    }
+
+    @Override
+    public List<ResolveInfo> queryIntentReceivers(Intent intent, String resolvedType, int flags,
+            int userId) {
+        if (!sUserManager.exists(userId)) return Collections.emptyList();
+        ComponentName comp = intent.getComponent();
+        if (comp == null) {
+            if (intent.getSelector() != null) {
+                intent = intent.getSelector(); 
+                comp = intent.getComponent();
+            }
+        }
+        if (comp != null) {
+            List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
+            ActivityInfo ai = getReceiverInfo(comp, flags, userId);
+            if (ai != null) {
+                ResolveInfo ri = new ResolveInfo();
+                ri.activityInfo = ai;
+                list.add(ri);
+            }
+            return list;
+        }
+
+        // reader
+        synchronized (mPackages) {
+            String pkgName = intent.getPackage();
+            if (pkgName == null) {
+                return mReceivers.queryIntent(intent, resolvedType, flags, userId);
+            }
+            final PackageParser.Package pkg = mPackages.get(pkgName);
+            if (pkg != null) {
+                return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers,
+                        userId);
+            }
+            return null;
+        }
+    }
+
+    @Override
+    public ResolveInfo resolveService(Intent intent, String resolvedType, int flags, int userId) {
+        List<ResolveInfo> query = queryIntentServices(intent, resolvedType, flags, userId);
+        if (!sUserManager.exists(userId)) return null;
+        if (query != null) {
+            if (query.size() >= 1) {
+                // If there is more than one service with the same priority,
+                // just arbitrarily pick the first one.
+                return query.get(0);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public List<ResolveInfo> queryIntentServices(Intent intent, String resolvedType, int flags,
+            int userId) {
+        if (!sUserManager.exists(userId)) return Collections.emptyList();
+        ComponentName comp = intent.getComponent();
+        if (comp == null) {
+            if (intent.getSelector() != null) {
+                intent = intent.getSelector(); 
+                comp = intent.getComponent();
+            }
+        }
+        if (comp != null) {
+            final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
+            final ServiceInfo si = getServiceInfo(comp, flags, userId);
+            if (si != null) {
+                final ResolveInfo ri = new ResolveInfo();
+                ri.serviceInfo = si;
+                list.add(ri);
+            }
+            return list;
+        }
+
+        // reader
+        synchronized (mPackages) {
+            String pkgName = intent.getPackage();
+            if (pkgName == null) {
+                return mServices.queryIntent(intent, resolvedType, flags, userId);
+            }
+            final PackageParser.Package pkg = mPackages.get(pkgName);
+            if (pkg != null) {
+                return mServices.queryIntentForPackage(intent, resolvedType, flags, pkg.services,
+                        userId);
+            }
+            return null;
+        }
+    }
+
+    @Override
+    public List<ResolveInfo> queryIntentContentProviders(
+            Intent intent, String resolvedType, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return Collections.emptyList();
+        ComponentName comp = intent.getComponent();
+        if (comp == null) {
+            if (intent.getSelector() != null) {
+                intent = intent.getSelector();
+                comp = intent.getComponent();
+            }
+        }
+        if (comp != null) {
+            final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
+            final ProviderInfo pi = getProviderInfo(comp, flags, userId);
+            if (pi != null) {
+                final ResolveInfo ri = new ResolveInfo();
+                ri.providerInfo = pi;
+                list.add(ri);
+            }
+            return list;
+        }
+
+        // reader
+        synchronized (mPackages) {
+            String pkgName = intent.getPackage();
+            if (pkgName == null) {
+                return mProviders.queryIntent(intent, resolvedType, flags, userId);
+            }
+            final PackageParser.Package pkg = mPackages.get(pkgName);
+            if (pkg != null) {
+                return mProviders.queryIntentForPackage(
+                        intent, resolvedType, flags, pkg.providers, userId);
+            }
+            return null;
+        }
+    }
+
+    @Override
+    public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, int userId) {
+        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
+
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "get installed packages");
+
+        // writer
+        synchronized (mPackages) {
+            ArrayList<PackageInfo> list;
+            if (listUninstalled) {
+                list = new ArrayList<PackageInfo>(mSettings.mPackages.size());
+                for (PackageSetting ps : mSettings.mPackages.values()) {
+                    PackageInfo pi;
+                    if (ps.pkg != null) {
+                        pi = generatePackageInfo(ps.pkg, flags, userId);
+                    } else {
+                        pi = generatePackageInfoFromSettingsLPw(ps.name, flags, userId);
+                    }
+                    if (pi != null) {
+                        list.add(pi);
+                    }
+                }
+            } else {
+                list = new ArrayList<PackageInfo>(mPackages.size());
+                for (PackageParser.Package p : mPackages.values()) {
+                    PackageInfo pi = generatePackageInfo(p, flags, userId);
+                    if (pi != null) {
+                        list.add(pi);
+                    }
+                }
+            }
+
+            return new ParceledListSlice<PackageInfo>(list);
+        }
+    }
+
+    private void addPackageHoldingPermissions(ArrayList<PackageInfo> list, PackageSetting ps,
+            String[] permissions, boolean[] tmp, int flags, int userId) {
+        int numMatch = 0;
+        final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
+        for (int i=0; i<permissions.length; i++) {
+            if (gp.grantedPermissions.contains(permissions[i])) {
+                tmp[i] = true;
+                numMatch++;
+            } else {
+                tmp[i] = false;
+            }
+        }
+        if (numMatch == 0) {
+            return;
+        }
+        PackageInfo pi;
+        if (ps.pkg != null) {
+            pi = generatePackageInfo(ps.pkg, flags, userId);
+        } else {
+            pi = generatePackageInfoFromSettingsLPw(ps.name, flags, userId);
+        }
+        if ((flags&PackageManager.GET_PERMISSIONS) == 0) {
+            if (numMatch == permissions.length) {
+                pi.requestedPermissions = permissions;
+            } else {
+                pi.requestedPermissions = new String[numMatch];
+                numMatch = 0;
+                for (int i=0; i<permissions.length; i++) {
+                    if (tmp[i]) {
+                        pi.requestedPermissions[numMatch] = permissions[i];
+                        numMatch++;
+                    }
+                }
+            }
+        }
+        list.add(pi);
+    }
+
+    @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;
+
+        // writer
+        synchronized (mPackages) {
+            ArrayList<PackageInfo> list = new ArrayList<PackageInfo>();
+            boolean[] tmpBools = new boolean[permissions.length];
+            if (listUninstalled) {
+                for (PackageSetting ps : mSettings.mPackages.values()) {
+                    addPackageHoldingPermissions(list, ps, permissions, tmpBools, flags, userId);
+                }
+            } else {
+                for (PackageParser.Package pkg : mPackages.values()) {
+                    PackageSetting ps = (PackageSetting)pkg.mExtras;
+                    if (ps != null) {
+                        addPackageHoldingPermissions(list, ps, permissions, tmpBools, flags,
+                                userId);
+                    }
+                }
+            }
+
+            return new ParceledListSlice<PackageInfo>(list);
+        }
+    }
+
+    @Override
+    public ParceledListSlice<ApplicationInfo> getInstalledApplications(int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
+
+        // writer
+        synchronized (mPackages) {
+            ArrayList<ApplicationInfo> list;
+            if (listUninstalled) {
+                list = new ArrayList<ApplicationInfo>(mSettings.mPackages.size());
+                for (PackageSetting ps : mSettings.mPackages.values()) {
+                    ApplicationInfo ai;
+                    if (ps.pkg != null) {
+                        ai = PackageParser.generateApplicationInfo(ps.pkg, flags,
+                                ps.readUserState(userId), userId);
+                    } else {
+                        ai = generateApplicationInfoFromSettingsLPw(ps.name, flags, userId);
+                    }
+                    if (ai != null) {
+                        list.add(ai);
+                    }
+                }
+            } else {
+                list = new ArrayList<ApplicationInfo>(mPackages.size());
+                for (PackageParser.Package p : mPackages.values()) {
+                    if (p.mExtras != null) {
+                        ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags,
+                                ((PackageSetting)p.mExtras).readUserState(userId), userId);
+                        if (ai != null) {
+                            list.add(ai);
+                        }
+                    }
+                }
+            }
+
+            return new ParceledListSlice<ApplicationInfo>(list);
+        }
+    }
+
+    public List<ApplicationInfo> getPersistentApplications(int flags) {
+        final ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>();
+
+        // reader
+        synchronized (mPackages) {
+            final Iterator<PackageParser.Package> i = mPackages.values().iterator();
+            final int userId = UserHandle.getCallingUserId();
+            while (i.hasNext()) {
+                final PackageParser.Package p = i.next();
+                if (p.applicationInfo != null
+                        && (p.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) != 0
+                        && (!mSafeMode || isSystemApp(p))) {
+                    PackageSetting ps = mSettings.mPackages.get(p.packageName);
+                    if (ps != null) {
+                        ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags,
+                                ps.readUserState(userId), userId);
+                        if (ai != null) {
+                            finalList.add(ai);
+                        }
+                    }
+                }
+            }
+        }
+
+        return finalList;
+    }
+
+    @Override
+    public ProviderInfo resolveContentProvider(String name, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return null;
+        // reader
+        synchronized (mPackages) {
+            final PackageParser.Provider provider = mProvidersByAuthority.get(name);
+            PackageSetting ps = provider != null
+                    ? mSettings.mPackages.get(provider.owner.packageName)
+                    : null;
+            return ps != null
+                    && mSettings.isEnabledLPr(provider.info, flags, userId)
+                    && (!mSafeMode || (provider.info.applicationInfo.flags
+                            &ApplicationInfo.FLAG_SYSTEM) != 0)
+                    ? PackageParser.generateProviderInfo(provider, flags,
+                            ps.readUserState(userId), userId)
+                    : null;
+        }
+    }
+
+    /**
+     * @deprecated
+     */
+    @Deprecated
+    public void querySyncProviders(List<String> outNames, List<ProviderInfo> outInfo) {
+        // reader
+        synchronized (mPackages) {
+            final Iterator<Map.Entry<String, PackageParser.Provider>> i = mProvidersByAuthority
+                    .entrySet().iterator();
+            final int userId = UserHandle.getCallingUserId();
+            while (i.hasNext()) {
+                Map.Entry<String, PackageParser.Provider> entry = i.next();
+                PackageParser.Provider p = entry.getValue();
+                PackageSetting ps = mSettings.mPackages.get(p.owner.packageName);
+
+                if (ps != null && p.syncable
+                        && (!mSafeMode || (p.info.applicationInfo.flags
+                                &ApplicationInfo.FLAG_SYSTEM) != 0)) {
+                    ProviderInfo info = PackageParser.generateProviderInfo(p, 0,
+                            ps.readUserState(userId), userId);
+                    if (info != null) {
+                        outNames.add(entry.getKey());
+                        outInfo.add(info);
+                    }
+                }
+            }
+        }
+    }
+
+    public List<ProviderInfo> queryContentProviders(String processName,
+            int uid, int flags) {
+        ArrayList<ProviderInfo> finalList = null;
+        // reader
+        synchronized (mPackages) {
+            final Iterator<PackageParser.Provider> i = mProviders.mProviders.values().iterator();
+            final int userId = processName != null ?
+                    UserHandle.getUserId(uid) : UserHandle.getCallingUserId();
+            while (i.hasNext()) {
+                final PackageParser.Provider p = i.next();
+                PackageSetting ps = mSettings.mPackages.get(p.owner.packageName);
+                if (ps != null && p.info.authority != null
+                        && (processName == null
+                                || (p.info.processName.equals(processName)
+                                        && UserHandle.isSameApp(p.info.applicationInfo.uid, uid)))
+                        && mSettings.isEnabledLPr(p.info, flags, userId)
+                        && (!mSafeMode
+                                || (p.info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)) {
+                    if (finalList == null) {
+                        finalList = new ArrayList<ProviderInfo>(3);
+                    }
+                    ProviderInfo info = PackageParser.generateProviderInfo(p, flags,
+                            ps.readUserState(userId), userId);
+                    if (info != null) {
+                        finalList.add(info);
+                    }
+                }
+            }
+        }
+
+        if (finalList != null) {
+            Collections.sort(finalList, mProviderInitOrderSorter);
+        }
+
+        return finalList;
+    }
+
+    public InstrumentationInfo getInstrumentationInfo(ComponentName name,
+            int flags) {
+        // reader
+        synchronized (mPackages) {
+            final PackageParser.Instrumentation i = mInstrumentation.get(name);
+            return PackageParser.generateInstrumentationInfo(i, flags);
+        }
+    }
+
+    public List<InstrumentationInfo> queryInstrumentation(String targetPackage,
+            int flags) {
+        ArrayList<InstrumentationInfo> finalList =
+            new ArrayList<InstrumentationInfo>();
+
+        // reader
+        synchronized (mPackages) {
+            final Iterator<PackageParser.Instrumentation> i = mInstrumentation.values().iterator();
+            while (i.hasNext()) {
+                final PackageParser.Instrumentation p = i.next();
+                if (targetPackage == null
+                        || targetPackage.equals(p.info.targetPackage)) {
+                    InstrumentationInfo ii = PackageParser.generateInstrumentationInfo(p,
+                            flags);
+                    if (ii != null) {
+                        finalList.add(ii);
+                    }
+                }
+            }
+        }
+
+        return finalList;
+    }
+
+    private void scanDirLI(File dir, int flags, int scanMode, long currentTime) {
+        String[] files = dir.list();
+        if (files == null) {
+            Log.d(TAG, "No files in app dir " + dir);
+            return;
+        }
+
+        if (DEBUG_PACKAGE_SCANNING) {
+            Log.d(TAG, "Scanning app dir " + dir + " scanMode=" + scanMode
+                    + " flags=0x" + Integer.toHexString(flags));
+        }
+
+        int i;
+        for (i=0; i<files.length; i++) {
+            File file = new File(dir, files[i]);
+            if (!isPackageFilename(files[i])) {
+                // Ignore entries which are not apk's
+                continue;
+            }
+            PackageParser.Package pkg = scanPackageLI(file,
+                    flags|PackageParser.PARSE_MUST_BE_APK, scanMode, currentTime, null);
+            // Don't mess around with apps in system partition.
+            if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 &&
+                    mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) {
+                // Delete the apk
+                Slog.w(TAG, "Cleaning up failed install of " + file);
+                file.delete();
+            }
+        }
+    }
+
+    private static File getSettingsProblemFile() {
+        File dataDir = Environment.getDataDirectory();
+        File systemDir = new File(dataDir, "system");
+        File fname = new File(systemDir, "uiderrors.txt");
+        return fname;
+    }
+    
+    static void reportSettingsProblem(int priority, String msg) {
+        try {
+            File fname = getSettingsProblemFile();
+            FileOutputStream out = new FileOutputStream(fname, true);
+            PrintWriter pw = new FastPrintWriter(out);
+            SimpleDateFormat formatter = new SimpleDateFormat();
+            String dateString = formatter.format(new Date(System.currentTimeMillis()));
+            pw.println(dateString + ": " + msg);
+            pw.close();
+            FileUtils.setPermissions(
+                    fname.toString(),
+                    FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH,
+                    -1, -1);
+        } catch (java.io.IOException e) {
+        }
+        Slog.println(priority, TAG, msg);
+    }
+
+    private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps,
+            PackageParser.Package pkg, File srcFile, int parseFlags) {
+        if (GET_CERTIFICATES) {
+            if (ps != null
+                    && ps.codePath.equals(srcFile)
+                    && ps.timeStamp == srcFile.lastModified()) {
+                if (ps.signatures.mSignatures != null
+                        && ps.signatures.mSignatures.length != 0) {
+                    // Optimization: reuse the existing cached certificates
+                    // if the package appears to be unchanged.
+                    pkg.mSignatures = ps.signatures.mSignatures;
+                    return true;
+                }
+                
+                Slog.w(TAG, "PackageSetting for " + ps.name + " is missing signatures.  Collecting certs again to recover them.");
+            } else {
+                Log.i(TAG, srcFile.toString() + " changed; collecting certs");
+            }
+            
+            if (!pp.collectCertificates(pkg, parseFlags)) {
+                mLastScanError = pp.getParseError();
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /*
+     *  Scan a package and return the newly parsed package.
+     *  Returns null in case of errors and the error code is stored in mLastScanError
+     */
+    private PackageParser.Package scanPackageLI(File scanFile,
+            int parseFlags, int scanMode, long currentTime, UserHandle user) {
+        mLastScanError = PackageManager.INSTALL_SUCCEEDED;
+        String scanPath = scanFile.getPath();
+        if (DEBUG_INSTALL) Slog.d(TAG, "Parsing: " + scanPath);
+        parseFlags |= mDefParseFlags;
+        PackageParser pp = new PackageParser(scanPath);
+        pp.setSeparateProcesses(mSeparateProcesses);
+        pp.setOnlyCoreApps(mOnlyCore);
+        final PackageParser.Package pkg = pp.parsePackage(scanFile,
+                scanPath, mMetrics, parseFlags);
+
+        if (pkg == null) {
+            mLastScanError = pp.getParseError();
+            return null;
+        }
+
+        PackageSetting ps = null;
+        PackageSetting updatedPkg;
+        // reader
+        synchronized (mPackages) {
+            // Look to see if we already know about this package.
+            String oldName = mSettings.mRenamedPackages.get(pkg.packageName);
+            if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) {
+                // This package has been renamed to its original name.  Let's
+                // use that.
+                ps = mSettings.peekPackageLPr(oldName);
+            }
+            // If there was no original package, see one for the real package name.
+            if (ps == null) {
+                ps = mSettings.peekPackageLPr(pkg.packageName);
+            }
+            // Check to see if this package could be hiding/updating a system
+            // package.  Must look for it either under the original or real
+            // package name depending on our state.
+            updatedPkg = mSettings.getDisabledSystemPkgLPr(ps != null ? ps.name : pkg.packageName);
+            if (DEBUG_INSTALL && updatedPkg != null) Slog.d(TAG, "updatedPkg = " + updatedPkg);
+        }
+        // First check if this is a system package that may involve an update
+        if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
+            if (ps != null && !ps.codePath.equals(scanFile)) {
+                // The path has changed from what was last scanned...  check the
+                // version of the new path against what we have stored to determine
+                // what to do.
+                if (DEBUG_INSTALL) Slog.d(TAG, "Path changing from " + ps.codePath);
+                if (pkg.mVersionCode < ps.versionCode) {
+                    // The system package has been updated and the code path does not match
+                    // Ignore entry. Skip it.
+                    Log.i(TAG, "Package " + ps.name + " at " + scanFile
+                            + " 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 : "
+                                + ps.name + " changing from " + updatedPkg.codePathString
+                                + " to " + scanFile);
+                        updatedPkg.codePath = scanFile;
+                        updatedPkg.codePathString = scanFile.toString();
+                        // This is the point at which we know that the system-disk APK
+                        // for this package has moved during a reboot (e.g. due to an OTA),
+                        // so we need to reevaluate it for privilege policy.
+                        if (locationIsPrivileged(scanFile)) {
+                            updatedPkg.pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED;
+                        }
+                    }
+                    updatedPkg.pkg = pkg;
+                    mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
+                    return null;
+                } else {
+                    // The current app on the system partion is better than
+                    // what we have updated to on the data partition; switch
+                    // back to the system partition version.
+                    // At this point, its safely assumed that package installation for
+                    // apps in system partition will go through. If not there won't be a working
+                    // version of the app
+                    // writer
+                    synchronized (mPackages) {
+                        // Just remove the loaded entries from package lists.
+                        mPackages.remove(ps.name);
+                    }
+                    Slog.w(TAG, "Package " + ps.name + " at " + scanFile
+                            + "reverting from " + ps.codePathString
+                            + ": new version " + pkg.mVersionCode
+                            + " better than installed " + ps.versionCode);
+
+                    InstallArgs args = createInstallArgs(packageFlagsToInstallFlags(ps),
+                            ps.codePathString, ps.resourcePathString, ps.nativeLibraryPathString);
+                    synchronized (mInstallLock) {
+                        args.cleanUpResourcesLI();
+                    }
+                    synchronized (mPackages) {
+                        mSettings.enableSystemPackageLPw(ps.name);
+                    }
+                }
+            }
+        }
+
+        if (updatedPkg != null) {
+            // An updated system app will not have the PARSE_IS_SYSTEM flag set
+            // initially
+            parseFlags |= PackageParser.PARSE_IS_SYSTEM;
+
+            // An updated privileged app will not have the PARSE_IS_PRIVILEGED
+            // flag set initially
+            if ((updatedPkg.pkgFlags & ApplicationInfo.FLAG_PRIVILEGED) != 0) {
+                parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
+            }
+        }
+        // Verify certificates against what was last scanned
+        if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) {
+            Slog.w(TAG, "Failed verifying certificates for package:" + pkg.packageName);
+            return null;
+        }
+
+        /*
+         * A new system app appeared, but we already had a non-system one of the
+         * same name installed earlier.
+         */
+        boolean shouldHideSystemApp = false;
+        if (updatedPkg == null && ps != null
+                && (parseFlags & PackageParser.PARSE_IS_SYSTEM_DIR) != 0 && !isSystemApp(ps)) {
+            /*
+             * Check to make sure the signatures match first. If they don't,
+             * wipe the installed application and its data.
+             */
+            if (compareSignatures(ps.signatures.mSignatures, pkg.mSignatures)
+                    != PackageManager.SIGNATURE_MATCH) {
+                if (DEBUG_INSTALL) Slog.d(TAG, "Signature mismatch!");
+                deletePackageLI(pkg.packageName, null, true, null, null, 0, null, false);
+                ps = null;
+            } else {
+                /*
+                 * If the newly-added system app is an older version than the
+                 * already installed version, hide it. It will be scanned later
+                 * and re-added like an update.
+                 */
+                if (pkg.mVersionCode < ps.versionCode) {
+                    shouldHideSystemApp = true;
+                } else {
+                    /*
+                     * The newly found system app is a newer version that the
+                     * one previously installed. Simply remove the
+                     * already-installed application and replace it with our own
+                     * while keeping the application data.
+                     */
+                    Slog.w(TAG, "Package " + ps.name + " at " + scanFile + "reverting from "
+                            + ps.codePathString + ": new version " + pkg.mVersionCode
+                            + " better than installed " + ps.versionCode);
+                    InstallArgs args = createInstallArgs(packageFlagsToInstallFlags(ps),
+                            ps.codePathString, ps.resourcePathString, ps.nativeLibraryPathString);
+                    synchronized (mInstallLock) {
+                        args.cleanUpResourcesLI();
+                    }
+                }
+            }
+        }
+
+        // The apk is forward locked (not public) if its code and resources
+        // are kept in different files. (except for app in either system or
+        // vendor path).
+        // TODO grab this value from PackageSettings
+        if ((parseFlags & PackageParser.PARSE_IS_SYSTEM_DIR) == 0) {
+            if (ps != null && !ps.codePath.equals(ps.resourcePath)) {
+                parseFlags |= PackageParser.PARSE_FORWARD_LOCK;
+            }
+        }
+
+        String codePath = null;
+        String resPath = null;
+        if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) {
+            if (ps != null && ps.resourcePathString != null) {
+                resPath = ps.resourcePathString;
+            } else {
+                // Should not happen at all. Just log an error.
+                Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName);
+            }
+        } else {
+            resPath = pkg.mScanPath;
+        }
+
+        codePath = pkg.mScanPath;
+        // Set application objects path explicitly.
+        setApplicationInfoPaths(pkg, codePath, resPath);
+        // Note that we invoke the following method only if we are about to unpack an application
+        PackageParser.Package scannedPkg = scanPackageLI(pkg, parseFlags, scanMode
+                | SCAN_UPDATE_SIGNATURE, currentTime, user);
+
+        /*
+         * If the system app should be overridden by a previously installed
+         * data, hide the system app now and let the /data/app scan pick it up
+         * again.
+         */
+        if (shouldHideSystemApp) {
+            synchronized (mPackages) {
+                /*
+                 * We have to grant systems permissions before we hide, because
+                 * grantPermissions will assume the package update is trying to
+                 * expand its permissions.
+                 */
+                grantPermissionsLPw(pkg, true);
+                mSettings.disableSystemPackageLPw(pkg.packageName);
+            }
+        }
+
+        return scannedPkg;
+    }
+
+    private static void setApplicationInfoPaths(PackageParser.Package pkg, String destCodePath,
+            String destResPath) {
+        pkg.mPath = pkg.mScanPath = destCodePath;
+        pkg.applicationInfo.sourceDir = destCodePath;
+        pkg.applicationInfo.publicSourceDir = destResPath;
+    }
+
+    private static String fixProcessName(String defProcessName,
+            String processName, int uid) {
+        if (processName == null) {
+            return defProcessName;
+        }
+        return processName;
+    }
+
+    private boolean verifySignaturesLP(PackageSetting pkgSetting,
+            PackageParser.Package pkg) {
+        if (pkgSetting.signatures.mSignatures != null) {
+            // Already existing package. Make sure signatures match
+            if (compareSignatures(pkgSetting.signatures.mSignatures, pkg.mSignatures) !=
+                PackageManager.SIGNATURE_MATCH) {
+                    Slog.e(TAG, "Package " + pkg.packageName
+                            + " signatures do not match the previously installed version; ignoring!");
+                    mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE;
+                    return false;
+                }
+        }
+        // Check for shared user signatures
+        if (pkgSetting.sharedUser != null && pkgSetting.sharedUser.signatures.mSignatures != null) {
+            if (compareSignatures(pkgSetting.sharedUser.signatures.mSignatures,
+                    pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
+                Slog.e(TAG, "Package " + pkg.packageName
+                        + " has no signatures that match those in shared user "
+                        + pkgSetting.sharedUser.name + "; ignoring!");
+                mLastScanError = PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Enforces that only the system UID or root's UID can call a method exposed
+     * via Binder.
+     *
+     * @param message used as message if SecurityException is thrown
+     * @throws SecurityException if the caller is not system or root
+     */
+    private static final void enforceSystemOrRoot(String message) {
+        final int uid = Binder.getCallingUid();
+        if (uid != Process.SYSTEM_UID && uid != 0) {
+            throw new SecurityException(message);
+        }
+    }
+
+    public void performBootDexOpt() {
+        HashSet<PackageParser.Package> pkgs = null;
+        synchronized (mPackages) {
+            pkgs = mDeferredDexOpt;
+            mDeferredDexOpt = null;
+        }
+        if (pkgs != null) {
+            int i = 0;
+            for (PackageParser.Package pkg : pkgs) {
+                if (!isFirstBoot()) {
+                    i++;
+                    try {
+                        ActivityManagerNative.getDefault().showBootMessage(
+                                mContext.getResources().getString(
+                                        com.android.internal.R.string.android_upgrading_apk,
+                                        i, pkgs.size()), true);
+                    } catch (RemoteException e) {
+                    }
+                }
+                PackageParser.Package p = pkg;
+                synchronized (mInstallLock) {
+                    if (!p.mDidDexOpt) {
+                        performDexOptLI(p, false, false, true);
+                    }
+                }
+            }
+        }
+    }
+
+    public boolean performDexOpt(String packageName) {
+        enforceSystemOrRoot("Only the system can request dexopt be performed");
+
+        if (!mNoDexOpt) {
+            return false;
+        }
+
+        PackageParser.Package p;
+        synchronized (mPackages) {
+            p = mPackages.get(packageName);
+            if (p == null || p.mDidDexOpt) {
+                return false;
+            }
+        }
+        synchronized (mInstallLock) {
+            return performDexOptLI(p, false, false, true) == DEX_OPT_PERFORMED;
+        }
+    }
+
+    private void performDexOptLibsLI(ArrayList<String> libs, boolean forceDex, boolean defer,
+            HashSet<String> done) {
+        for (int i=0; i<libs.size(); i++) {
+            PackageParser.Package libPkg;
+            String libName;
+            synchronized (mPackages) {
+                libName = libs.get(i);
+                SharedLibraryEntry lib = mSharedLibraries.get(libName);
+                if (lib != null && lib.apk != null) {
+                    libPkg = mPackages.get(lib.apk);
+                } else {
+                    libPkg = null;
+                }
+            }
+            if (libPkg != null && !done.contains(libName)) {
+                performDexOptLI(libPkg, forceDex, defer, done);
+            }
+        }
+    }
+
+    static final int DEX_OPT_SKIPPED = 0;
+    static final int DEX_OPT_PERFORMED = 1;
+    static final int DEX_OPT_DEFERRED = 2;
+    static final int DEX_OPT_FAILED = -1;
+
+    private int performDexOptLI(PackageParser.Package pkg, boolean forceDex, boolean defer,
+            HashSet<String> done) {
+        boolean performed = false;
+        if (done != null) {
+            done.add(pkg.packageName);
+            if (pkg.usesLibraries != null) {
+                performDexOptLibsLI(pkg.usesLibraries, forceDex, defer, done);
+            }
+            if (pkg.usesOptionalLibraries != null) {
+                performDexOptLibsLI(pkg.usesOptionalLibraries, forceDex, defer, done);
+            }
+        }
+        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) {
+            String path = pkg.mScanPath;
+            int ret = 0;
+            try {
+                if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) {
+                    if (!forceDex && defer) {
+                        if (mDeferredDexOpt == null) {
+                            mDeferredDexOpt = new HashSet<PackageParser.Package>();
+                        }
+                        mDeferredDexOpt.add(pkg);
+                        return DEX_OPT_DEFERRED;
+                    } else {
+                        Log.i(TAG, "Running dexopt on: " + pkg.applicationInfo.packageName);
+                        final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
+                        ret = mInstaller.dexopt(path, sharedGid, !isForwardLocked(pkg));
+                        pkg.mDidDexOpt = true;
+                        performed = true;
+                    }
+                }
+            } catch (FileNotFoundException e) {
+                Slog.w(TAG, "Apk not found for dexopt: " + path);
+                ret = -1;
+            } catch (IOException e) {
+                Slog.w(TAG, "IOException reading apk: " + path, e);
+                ret = -1;
+            } catch (dalvik.system.StaleDexCacheError e) {
+                Slog.w(TAG, "StaleDexCacheError when reading apk: " + path, e);
+                ret = -1;
+            } catch (Exception e) {
+                Slog.w(TAG, "Exception when doing dexopt : ", e);
+                ret = -1;
+            }
+            if (ret < 0) {
+                //error from installer
+                return DEX_OPT_FAILED;
+            }
+        }
+
+        return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED;
+    }
+
+    private int performDexOptLI(PackageParser.Package pkg, boolean forceDex, boolean defer,
+            boolean inclDependencies) {
+        HashSet<String> done;
+        boolean performed = false;
+        if (inclDependencies && (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null)) {
+            done = new HashSet<String>();
+            done.add(pkg.packageName);
+        } else {
+            done = null;
+        }
+        return performDexOptLI(pkg, forceDex, defer, done);
+    }
+
+    private boolean verifyPackageUpdateLPr(PackageSetting oldPkg, PackageParser.Package newPkg) {
+        if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+            Slog.w(TAG, "Unable to update from " + oldPkg.name
+                    + " to " + newPkg.packageName
+                    + ": old package not in system partition");
+            return false;
+        } else if (mPackages.get(oldPkg.name) != null) {
+            Slog.w(TAG, "Unable to update from " + oldPkg.name
+                    + " to " + newPkg.packageName
+                    + ": old package still exists");
+            return false;
+        }
+        return true;
+    }
+
+    File getDataPathForUser(int userId) {
+        return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId);
+    }
+
+    private File getDataPathForPackage(String packageName, int userId) {
+        /*
+         * Until we fully support multiple users, return the directory we
+         * previously would have. The PackageManagerTests will need to be
+         * revised when this is changed back..
+         */
+        if (userId == 0) {
+            return new File(mAppDataDir, packageName);
+        } else {
+            return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId
+                + File.separator + packageName);
+        }
+    }
+
+    private int createDataDirsLI(String packageName, int uid, String seinfo) {
+        int[] users = sUserManager.getUserIds();
+        int res = mInstaller.install(packageName, uid, uid, seinfo);
+        if (res < 0) {
+            return res;
+        }
+        for (int user : users) {
+            if (user != 0) {
+                res = mInstaller.createUserData(packageName,
+                        UserHandle.getUid(user, uid), user, seinfo);
+                if (res < 0) {
+                    return res;
+                }
+            }
+        }
+        return res;
+    }
+
+    private int removeDataDirsLI(String packageName) {
+        int[] users = sUserManager.getUserIds();
+        int res = 0;
+        for (int user : users) {
+            int resInner = mInstaller.remove(packageName, user);
+            if (resInner < 0) {
+                res = resInner;
+            }
+        }
+
+        final File nativeLibraryFile = new File(mAppLibInstallDir, packageName);
+        NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryFile);
+        if (!nativeLibraryFile.delete()) {
+            Slog.w(TAG, "Couldn't delete native library directory " + nativeLibraryFile.getPath());
+        }
+
+        return res;
+    }
+
+    private int addSharedLibraryLPw(final SharedLibraryEntry file, int num,
+            PackageParser.Package changingLib) {
+        if (file.path != null) {
+            mTmpSharedLibraries[num] = file.path;
+            return num+1;
+        }
+        PackageParser.Package p = mPackages.get(file.apk);
+        if (changingLib != null && changingLib.packageName.equals(file.apk)) {
+            // If we are doing this while in the middle of updating a library apk,
+            // then we need to make sure to use that new apk for determining the
+            // dependencies here.  (We haven't yet finished committing the new apk
+            // to the package manager state.)
+            if (p == null || p.packageName.equals(changingLib.packageName)) {
+                p = changingLib;
+            }
+        }
+        if (p != null) {
+            String path = p.mPath;
+            for (int i=0; i<num; i++) {
+                if (mTmpSharedLibraries[i].equals(path)) {
+                    return num;
+                }
+            }
+            mTmpSharedLibraries[num] = p.mPath;
+            return num+1;
+        }
+        return num;
+    }
+
+    private boolean updateSharedLibrariesLPw(PackageParser.Package pkg,
+            PackageParser.Package changingLib) {
+        if (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null) {
+            if (mTmpSharedLibraries == null ||
+                    mTmpSharedLibraries.length < mSharedLibraries.size()) {
+                mTmpSharedLibraries = new String[mSharedLibraries.size()];
+            }
+            int num = 0;
+            int N = pkg.usesLibraries != null ? pkg.usesLibraries.size() : 0;
+            for (int i=0; i<N; i++) {
+                final SharedLibraryEntry file = mSharedLibraries.get(pkg.usesLibraries.get(i));
+                if (file == null) {
+                    Slog.e(TAG, "Package " + pkg.packageName
+                            + " requires unavailable shared library "
+                            + pkg.usesLibraries.get(i) + "; failing!");
+                    mLastScanError = PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY;
+                    return false;
+                }
+                num = addSharedLibraryLPw(file, num, changingLib);
+            }
+            N = pkg.usesOptionalLibraries != null ? pkg.usesOptionalLibraries.size() : 0;
+            for (int i=0; i<N; i++) {
+                final SharedLibraryEntry file = mSharedLibraries.get(pkg.usesOptionalLibraries.get(i));
+                if (file == null) {
+                    Slog.w(TAG, "Package " + pkg.packageName
+                            + " desires unavailable shared library "
+                            + pkg.usesOptionalLibraries.get(i) + "; ignoring!");
+                } else {
+                    num = addSharedLibraryLPw(file, num, changingLib);
+                }
+            }
+            if (num > 0) {
+                pkg.usesLibraryFiles = new String[num];
+                System.arraycopy(mTmpSharedLibraries, 0,
+                        pkg.usesLibraryFiles, 0, num);
+            } else {
+                pkg.usesLibraryFiles = null;
+            }
+        }
+        return true;
+    }
+
+    private static boolean hasString(List<String> list, List<String> which) {
+        if (list == null) {
+            return false;
+        }
+        for (int i=list.size()-1; i>=0; i--) {
+            for (int j=which.size()-1; j>=0; j--) {
+                if (which.get(j).equals(list.get(i))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    private void updateAllSharedLibrariesLPw() {
+        for (PackageParser.Package pkg : mPackages.values()) {
+            updateSharedLibrariesLPw(pkg, null);
+        }
+    }
+
+    private ArrayList<PackageParser.Package> updateAllSharedLibrariesLPw(
+            PackageParser.Package changingPkg) {
+        ArrayList<PackageParser.Package> res = null;
+        for (PackageParser.Package pkg : mPackages.values()) {
+            if (hasString(pkg.usesLibraries, changingPkg.libraryNames)
+                    || hasString(pkg.usesOptionalLibraries, changingPkg.libraryNames)) {
+                if (res == null) {
+                    res = new ArrayList<PackageParser.Package>();
+                }
+                res.add(pkg);
+                updateSharedLibrariesLPw(pkg, changingPkg);
+            }
+        }
+        return res;
+    }
+
+    private PackageParser.Package scanPackageLI(PackageParser.Package pkg,
+            int parseFlags, int scanMode, long currentTime, UserHandle user) {
+        File scanFile = new File(pkg.mScanPath);
+        if (scanFile == null || pkg.applicationInfo.sourceDir == null ||
+                pkg.applicationInfo.publicSourceDir == null) {
+            // Bail out. The resource and code paths haven't been set.
+            Slog.w(TAG, " Code and resource paths haven't been set correctly");
+            mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK;
+            return null;
+        }
+
+        if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
+            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
+        }
+
+        if ((parseFlags&PackageParser.PARSE_IS_PRIVILEGED) != 0) {
+            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_PRIVILEGED;
+        }
+
+        if (mCustomResolverComponentName != null &&
+                mCustomResolverComponentName.getPackageName().equals(pkg.packageName)) {
+            setUpCustomResolverActivity(pkg);
+        }
+
+        if (pkg.packageName.equals("android")) {
+            synchronized (mPackages) {
+                if (mAndroidApplication != null) {
+                    Slog.w(TAG, "*************************************************");
+                    Slog.w(TAG, "Core android package being redefined.  Skipping.");
+                    Slog.w(TAG, " file=" + scanFile);
+                    Slog.w(TAG, "*************************************************");
+                    mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
+                    return null;
+                }
+
+                // Set up information for our fall-back user intent resolution activity.
+                mPlatformPackage = pkg;
+                pkg.mVersionCode = mSdkVersion;
+                mAndroidApplication = pkg.applicationInfo;
+
+                if (!mResolverReplaced) {
+                    mResolveActivity.applicationInfo = mAndroidApplication;
+                    mResolveActivity.name = ResolverActivity.class.getName();
+                    mResolveActivity.packageName = mAndroidApplication.packageName;
+                    mResolveActivity.processName = "system:ui";
+                    mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
+                    mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
+                    mResolveActivity.theme = com.android.internal.R.style.Theme_Holo_Dialog_Alert;
+                    mResolveActivity.exported = true;
+                    mResolveActivity.enabled = true;
+                    mResolveInfo.activityInfo = mResolveActivity;
+                    mResolveInfo.priority = 0;
+                    mResolveInfo.preferredOrder = 0;
+                    mResolveInfo.match = 0;
+                    mResolveComponentName = new ComponentName(
+                            mAndroidApplication.packageName, mResolveActivity.name);
+                }
+            }
+        }
+
+        if (DEBUG_PACKAGE_SCANNING) {
+            if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                Log.d(TAG, "Scanning package " + pkg.packageName);
+        }
+
+        if (mPackages.containsKey(pkg.packageName)
+                || mSharedLibraries.containsKey(pkg.packageName)) {
+            Slog.w(TAG, "Application package " + pkg.packageName
+                    + " already installed.  Skipping duplicate.");
+            mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
+            return null;
+        }
+
+        // Initialize package source and resource directories
+        File destCodeFile = new File(pkg.applicationInfo.sourceDir);
+        File destResourceFile = new File(pkg.applicationInfo.publicSourceDir);
+
+        SharedUserSetting suid = null;
+        PackageSetting pkgSetting = null;
+
+        if (!isSystemApp(pkg)) {
+            // Only system apps can use these features.
+            pkg.mOriginalPackages = null;
+            pkg.mRealPackage = null;
+            pkg.mAdoptPermissions = null;
+        }
+
+        // writer
+        synchronized (mPackages) {
+            if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) {
+                // Check all shared libraries and map to their actual file path.
+                // We only do this here for apps not on a system dir, because those
+                // are the only ones that can fail an install due to this.  We
+                // will take care of the system apps by updating all of their
+                // library paths after the scan is done.
+                if (!updateSharedLibrariesLPw(pkg, null)) {
+                    return null;
+                }
+            }
+
+            if (pkg.mSharedUserId != null) {
+                suid = mSettings.getSharedUserLPw(pkg.mSharedUserId, 0, true);
+                if (suid == null) {
+                    Slog.w(TAG, "Creating application package " + pkg.packageName
+                            + " for shared user failed");
+                    mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                    return null;
+                }
+                if (DEBUG_PACKAGE_SCANNING) {
+                    if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                        Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" + suid.userId
+                                + "): packages=" + suid.packages);
+                }
+            }
+            
+            // Check if we are renaming from an original package name.
+            PackageSetting origPackage = null;
+            String realName = null;
+            if (pkg.mOriginalPackages != null) {
+                // This package may need to be renamed to a previously
+                // installed name.  Let's check on that...
+                final String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage);
+                if (pkg.mOriginalPackages.contains(renamed)) {
+                    // This package had originally been installed as the
+                    // original name, and we have already taken care of
+                    // transitioning to the new one.  Just update the new
+                    // one to continue using the old name.
+                    realName = pkg.mRealPackage;
+                    if (!pkg.packageName.equals(renamed)) {
+                        // Callers into this function may have already taken
+                        // care of renaming the package; only do it here if
+                        // it is not already done.
+                        pkg.setPackageName(renamed);
+                    }
+                    
+                } else {
+                    for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) {
+                        if ((origPackage = mSettings.peekPackageLPr(
+                                pkg.mOriginalPackages.get(i))) != null) {
+                            // We do have the package already installed under its
+                            // original name...  should we use it?
+                            if (!verifyPackageUpdateLPr(origPackage, pkg)) {
+                                // New package is not compatible with original.
+                                origPackage = null;
+                                continue;
+                            } else if (origPackage.sharedUser != null) {
+                                // Make sure uid is compatible between packages.
+                                if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) {
+                                    Slog.w(TAG, "Unable to migrate data from " + origPackage.name
+                                            + " to " + pkg.packageName + ": old uid "
+                                            + origPackage.sharedUser.name
+                                            + " differs from " + pkg.mSharedUserId);
+                                    origPackage = null;
+                                    continue;
+                                }
+                            } else {
+                                if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package "
+                                        + pkg.packageName + " to old name " + origPackage.name);
+                            }
+                            break;
+                        }
+                    }
+                }
+            }
+            
+            if (mTransferedPackages.contains(pkg.packageName)) {
+                Slog.w(TAG, "Package " + pkg.packageName
+                        + " was transferred to another, but its .apk remains");
+            }
+            
+            // Just create the setting, don't add it yet. For already existing packages
+            // the PkgSetting exists already and doesn't have to be created.
+            pkgSetting = mSettings.getPackageLPw(pkg, origPackage, realName, suid, destCodeFile,
+                    destResourceFile, pkg.applicationInfo.nativeLibraryDir,
+                    pkg.applicationInfo.flags, user, false);
+            if (pkgSetting == null) {
+                Slog.w(TAG, "Creating application package " + pkg.packageName + " failed");
+                mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                return null;
+            }
+            
+            if (pkgSetting.origPackage != null) {
+                // If we are first transitioning from an original package,
+                // fix up the new package's name now.  We need to do this after
+                // looking up the package under its new name, so getPackageLP
+                // can take care of fiddling things correctly.
+                pkg.setPackageName(origPackage.name);
+                
+                // File a report about this.
+                String msg = "New package " + pkgSetting.realName
+                        + " renamed to replace old package " + pkgSetting.name;
+                reportSettingsProblem(Log.WARN, msg);
+                
+                // Make a note of it.
+                mTransferedPackages.add(origPackage.name);
+                
+                // No longer need to retain this.
+                pkgSetting.origPackage = null;
+            }
+            
+            if (realName != null) {
+                // Make a note of it.
+                mTransferedPackages.add(pkg.packageName);
+            }
+            
+            if (mSettings.isDisabledSystemPackageLPr(pkg.packageName)) {
+                pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+            }
+
+            if (mFoundPolicyFile) {
+                SELinuxMMAC.assignSeinfoValue(pkg);
+            }
+
+            pkg.applicationInfo.uid = pkgSetting.appId;
+            pkg.mExtras = pkgSetting;
+
+            if (!verifySignaturesLP(pkgSetting, pkg)) {
+                if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) {
+                    return null;
+                }
+                // The signature has changed, but this package is in the system
+                // image...  let's recover!
+                pkgSetting.signatures.mSignatures = pkg.mSignatures;
+                // However...  if this package is part of a shared user, but it
+                // doesn't match the signature of the shared user, let's fail.
+                // What this means is that you can't change the signatures
+                // associated with an overall shared user, which doesn't seem all
+                // that unreasonable.
+                if (pkgSetting.sharedUser != null) {
+                    if (compareSignatures(pkgSetting.sharedUser.signatures.mSignatures,
+                            pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
+                        Log.w(TAG, "Signature mismatch for shared user : " + pkgSetting.sharedUser);
+                        mLastScanError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
+                        return null;
+                    }
+                }
+                // File a report about this.
+                String msg = "System package " + pkg.packageName
+                        + " signature changed; retaining data.";
+                reportSettingsProblem(Log.WARN, msg);
+            }
+
+            // Verify that this new package doesn't have any content providers
+            // that conflict with existing packages.  Only do this if the
+            // package isn't already installed, since we don't want to break
+            // things that are installed.
+            if ((scanMode&SCAN_NEW_INSTALL) != 0) {
+                final int N = pkg.providers.size();
+                int i;
+                for (i=0; i<N; i++) {
+                    PackageParser.Provider p = pkg.providers.get(i);
+                    if (p.info.authority != null) {
+                        String names[] = p.info.authority.split(";");
+                        for (int j = 0; j < names.length; j++) {
+                            if (mProvidersByAuthority.containsKey(names[j])) {
+                                PackageParser.Provider other = mProvidersByAuthority.get(names[j]);
+                                Slog.w(TAG, "Can't install because provider name " + names[j] +
+                                        " (in package " + pkg.applicationInfo.packageName +
+                                        ") is already used by "
+                                        + ((other != null && other.getComponentName() != null)
+                                                ? other.getComponentName().getPackageName() : "?"));
+                                mLastScanError = PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER;
+                                return null;
+                            }
+                        }
+                    }
+                }
+            }
+
+            if (pkg.mAdoptPermissions != null) {
+                // This package wants to adopt ownership of permissions from
+                // another package.
+                for (int i = pkg.mAdoptPermissions.size() - 1; i >= 0; i--) {
+                    final String origName = pkg.mAdoptPermissions.get(i);
+                    final PackageSetting orig = mSettings.peekPackageLPr(origName);
+                    if (orig != null) {
+                        if (verifyPackageUpdateLPr(orig, pkg)) {
+                            Slog.i(TAG, "Adopting permissions from " + origName + " to "
+                                    + pkg.packageName);
+                            mSettings.transferPermissionsLPw(origName, pkg.packageName);
+                        }
+                    }
+                }
+            }
+        }
+
+        final String pkgName = pkg.packageName;
+        
+        final long scanFileTime = scanFile.lastModified();
+        final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0;
+        pkg.applicationInfo.processName = fixProcessName(
+                pkg.applicationInfo.packageName,
+                pkg.applicationInfo.processName,
+                pkg.applicationInfo.uid);
+
+        File dataPath;
+        if (mPlatformPackage == pkg) {
+            // The system package is special.
+            dataPath = new File (Environment.getDataDirectory(), "system");
+            pkg.applicationInfo.dataDir = dataPath.getPath();
+        } else {
+            // This is a normal package, need to make its data directory.
+            dataPath = getDataPathForPackage(pkg.packageName, 0);
+
+            boolean uidError = false;
+
+            if (dataPath.exists()) {
+                int currentUid = 0;
+                try {
+                    StructStat stat = Libcore.os.stat(dataPath.getPath());
+                    currentUid = stat.st_uid;
+                } catch (ErrnoException e) {
+                    Slog.e(TAG, "Couldn't stat path " + dataPath.getPath(), e);
+                }
+
+                // If we have mismatched owners for the data path, we have a problem.
+                if (currentUid != pkg.applicationInfo.uid) {
+                    boolean recovered = false;
+                    if (currentUid == 0) {
+                        // The directory somehow became owned by root.  Wow.
+                        // This is probably because the system was stopped while
+                        // installd was in the middle of messing with its libs
+                        // directory.  Ask installd to fix that.
+                        int ret = mInstaller.fixUid(pkgName, pkg.applicationInfo.uid,
+                                pkg.applicationInfo.uid);
+                        if (ret >= 0) {
+                            recovered = true;
+                            String msg = "Package " + pkg.packageName
+                                    + " unexpectedly changed to uid 0; recovered to " +
+                                    + pkg.applicationInfo.uid;
+                            reportSettingsProblem(Log.WARN, msg);
+                        }
+                    }
+                    if (!recovered && ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0
+                            || (scanMode&SCAN_BOOTING) != 0)) {
+                        // If this is a system app, we can at least delete its
+                        // current data so the application will still work.
+                        int ret = removeDataDirsLI(pkgName);
+                        if (ret >= 0) {
+                            // TODO: Kill the processes first
+                            // Old data gone!
+                            String prefix = (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0
+                                    ? "System package " : "Third party package ";
+                            String msg = prefix + pkg.packageName
+                                    + " has changed from uid: "
+                                    + currentUid + " to "
+                                    + pkg.applicationInfo.uid + "; old data erased";
+                            reportSettingsProblem(Log.WARN, msg);
+                            recovered = true;
+
+                            // And now re-install the app.
+                            ret = createDataDirsLI(pkgName, pkg.applicationInfo.uid,
+                                                   pkg.applicationInfo.seinfo);
+                            if (ret == -1) {
+                                // Ack should not happen!
+                                msg = prefix + pkg.packageName
+                                        + " could not have data directory re-created after delete.";
+                                reportSettingsProblem(Log.WARN, msg);
+                                mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                                return null;
+                            }
+                        }
+                        if (!recovered) {
+                            mHasSystemUidErrors = true;
+                        }
+                    } else if (!recovered) {
+                        // If we allow this install to proceed, we will be broken.
+                        // Abort, abort!
+                        mLastScanError = PackageManager.INSTALL_FAILED_UID_CHANGED;
+                        return null;
+                    }
+                    if (!recovered) {
+                        pkg.applicationInfo.dataDir = "/mismatched_uid/settings_"
+                            + pkg.applicationInfo.uid + "/fs_"
+                            + currentUid;
+                        pkg.applicationInfo.nativeLibraryDir = pkg.applicationInfo.dataDir;
+                        String msg = "Package " + pkg.packageName
+                                + " has mismatched uid: "
+                                + currentUid + " on disk, "
+                                + pkg.applicationInfo.uid + " in settings";
+                        // writer
+                        synchronized (mPackages) {
+                            mSettings.mReadMessages.append(msg);
+                            mSettings.mReadMessages.append('\n');
+                            uidError = true;
+                            if (!pkgSetting.uidError) {
+                                reportSettingsProblem(Log.ERROR, msg);
+                            }
+                        }
+                    }
+                }
+                pkg.applicationInfo.dataDir = dataPath.getPath();
+            } else {
+                if (DEBUG_PACKAGE_SCANNING) {
+                    if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                        Log.v(TAG, "Want this data dir: " + dataPath);
+                }
+                //invoke installer to do the actual installation
+                int ret = createDataDirsLI(pkgName, pkg.applicationInfo.uid,
+                                           pkg.applicationInfo.seinfo);
+                if (ret < 0) {
+                    // Error from installer
+                    mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                    return null;
+                }
+
+                if (dataPath.exists()) {
+                    pkg.applicationInfo.dataDir = dataPath.getPath();
+                } else {
+                    Slog.w(TAG, "Unable to create data directory: " + dataPath);
+                    pkg.applicationInfo.dataDir = null;
+                }
+            }
+
+            /*
+             * Set the data dir to the default "/data/data/<package name>/lib"
+             * if we got here without anyone telling us different (e.g., apps
+             * stored on SD card have their native libraries stored in the ASEC
+             * container with the APK).
+             *
+             * This happens during an upgrade from a package settings file that
+             * doesn't have a native library path attribute at all.
+             */
+            if (pkg.applicationInfo.nativeLibraryDir == null && pkg.applicationInfo.dataDir != null) {
+                if (pkgSetting.nativeLibraryPathString == null) {
+                    setInternalAppNativeLibraryPath(pkg, pkgSetting);
+                } else {
+                    pkg.applicationInfo.nativeLibraryDir = pkgSetting.nativeLibraryPathString;
+                }
+            }
+
+            pkgSetting.uidError = uidError;
+        }
+
+        String path = scanFile.getPath();
+        /* Note: We don't want to unpack the native binaries for
+         *        system applications, unless they have been updated
+         *        (the binaries are already under /system/lib).
+         *        Also, don't unpack libs for apps on the external card
+         *        since they should have their libraries in the ASEC
+         *        container already.
+         *
+         *        In other words, we're going to unpack the binaries
+         *        only for non-system apps and system app upgrades.
+         */
+        if (pkg.applicationInfo.nativeLibraryDir != null) {
+            try {
+                File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
+                final String dataPathString = dataPath.getCanonicalPath();
+
+                if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) {
+                    /*
+                     * Upgrading from a previous version of the OS sometimes
+                     * leaves native libraries in the /data/data/<app>/lib
+                     * directory for system apps even when they shouldn't be.
+                     * Recent changes in the JNI library search path
+                     * necessitates we remove those to match previous behavior.
+                     */
+                    if (NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryDir)) {
+                        Log.i(TAG, "removed obsolete native libraries for system package "
+                                + path);
+                    }
+                } else {
+                    if (!isForwardLocked(pkg) && !isExternal(pkg)) {
+                        /*
+                         * Update native library dir if it starts with
+                         * /data/data
+                         */
+                        if (nativeLibraryDir.getPath().startsWith(dataPathString)) {
+                            setInternalAppNativeLibraryPath(pkg, pkgSetting);
+                            nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
+                        }
+
+                        try {
+                            if (copyNativeLibrariesForInternalApp(scanFile, nativeLibraryDir) != PackageManager.INSTALL_SUCCEEDED) {
+                                Slog.e(TAG, "Unable to copy native libraries");
+                                mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+                                return null;
+                            }
+                        } catch (IOException e) {
+                            Slog.e(TAG, "Unable to copy native libraries", e);
+                            mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+                            return null;
+                        }
+                    }
+
+                    if (DEBUG_INSTALL) Slog.i(TAG, "Linking native library dir for " + path);
+                    final int[] userIds = sUserManager.getUserIds();
+                    synchronized (mInstallLock) {
+                        for (int userId : userIds) {
+                            if (mInstaller.linkNativeLibraryDirectory(pkg.packageName,
+                                    pkg.applicationInfo.nativeLibraryDir, userId) < 0) {
+                                Slog.w(TAG, "Failed linking native library dir (user=" + userId
+                                        + ")");
+                                mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+                                return null;
+                            }
+                        }
+                    }
+                }
+            } catch (IOException ioe) {
+                Slog.e(TAG, "Unable to get canonical file " + ioe.toString());
+            }
+        }
+        pkg.mScanPath = path;
+
+        if ((scanMode&SCAN_NO_DEX) == 0) {
+            if (performDexOptLI(pkg, forceDex, (scanMode&SCAN_DEFER_DEX) != 0, false)
+                    == DEX_OPT_FAILED) {
+                if ((scanMode & SCAN_DELETE_DATA_ON_FAILURES) != 0) {
+                    removeDataDirsLI(pkg.packageName);
+                }
+
+                mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT;
+                return null;
+            }
+        }
+
+        if (mFactoryTest && pkg.requestedPermissions.contains(
+                android.Manifest.permission.FACTORY_TEST)) {
+            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST;
+        }
+
+        ArrayList<PackageParser.Package> clientLibPkgs = null;
+
+        // writer
+        synchronized (mPackages) {
+            if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
+                // Only system apps can add new shared libraries.
+                if (pkg.libraryNames != null) {
+                    for (int i=0; i<pkg.libraryNames.size(); i++) {
+                        String name = pkg.libraryNames.get(i);
+                        boolean allowed = false;
+                        if (isUpdatedSystemApp(pkg)) {
+                            // New library entries can only be added through the
+                            // system image.  This is important to get rid of a lot
+                            // of nasty edge cases: for example if we allowed a non-
+                            // system update of the app to add a library, then uninstalling
+                            // the update would make the library go away, and assumptions
+                            // we made such as through app install filtering would now
+                            // have allowed apps on the device which aren't compatible
+                            // with it.  Better to just have the restriction here, be
+                            // conservative, and create many fewer cases that can negatively
+                            // impact the user experience.
+                            final PackageSetting sysPs = mSettings
+                                    .getDisabledSystemPkgLPr(pkg.packageName);
+                            if (sysPs.pkg != null && sysPs.pkg.libraryNames != null) {
+                                for (int j=0; j<sysPs.pkg.libraryNames.size(); j++) {
+                                    if (name.equals(sysPs.pkg.libraryNames.get(j))) {
+                                        allowed = true;
+                                        allowed = true;
+                                        break;
+                                    }
+                                }
+                            }
+                        } else {
+                            allowed = true;
+                        }
+                        if (allowed) {
+                            if (!mSharedLibraries.containsKey(name)) {
+                                mSharedLibraries.put(name, new SharedLibraryEntry(null,
+                                        pkg.packageName));
+                            } else if (!name.equals(pkg.packageName)) {
+                                Slog.w(TAG, "Package " + pkg.packageName + " library "
+                                        + name + " already exists; skipping");
+                            }
+                        } else {
+                            Slog.w(TAG, "Package " + pkg.packageName + " declares lib "
+                                    + name + " that is not declared on system image; skipping");
+                        }
+                    }
+                    if ((scanMode&SCAN_BOOTING) == 0) {
+                        // If we are not booting, we need to update any applications
+                        // that are clients of our shared library.  If we are booting,
+                        // this will all be done once the scan is complete.
+                        clientLibPkgs = updateAllSharedLibrariesLPw(pkg);
+                    }
+                }
+            }
+        }
+
+        // We also need to dexopt any apps that are dependent on this library.  Note that
+        // if these fail, we should abort the install since installing the library will
+        // result in some apps being broken.
+        if (clientLibPkgs != null) {
+            if ((scanMode&SCAN_NO_DEX) == 0) {
+                for (int i=0; i<clientLibPkgs.size(); i++) {
+                    PackageParser.Package clientPkg = clientLibPkgs.get(i);
+                    if (performDexOptLI(clientPkg, forceDex, (scanMode&SCAN_DEFER_DEX) != 0, false)
+                            == DEX_OPT_FAILED) {
+                        if ((scanMode & SCAN_DELETE_DATA_ON_FAILURES) != 0) {
+                            removeDataDirsLI(pkg.packageName);
+                        }
+
+                        mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT;
+                        return null;
+                    }
+                }
+            }
+        }
+
+        // Request the ActivityManager to kill the process(only for existing packages)
+        // so that we do not end up in a confused state while the user is still using the older
+        // version of the application while the new one gets installed.
+        if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
+            // If the package lives in an asec, tell everyone that the container is going
+            // away so they can clean up any references to its resources (which would prevent
+            // vold from being able to unmount the asec)
+            if (isForwardLocked(pkg) || isExternal(pkg)) {
+                if (DEBUG_INSTALL) {
+                    Slog.i(TAG, "upgrading pkg " + pkg + " is ASEC-hosted -> UNAVAILABLE");
+                }
+                final int[] uidArray = new int[] { pkg.applicationInfo.uid };
+                final ArrayList<String> pkgList = new ArrayList<String>(1);
+                pkgList.add(pkg.applicationInfo.packageName);
+                sendResourcesChangedBroadcast(false, true, pkgList, uidArray, null);
+            }
+
+            // Post the request that it be killed now that the going-away broadcast is en route
+            killApplication(pkg.applicationInfo.packageName,
+                        pkg.applicationInfo.uid, "update pkg");
+        }
+
+        // Also need to kill any apps that are dependent on the library.
+        if (clientLibPkgs != null) {
+            for (int i=0; i<clientLibPkgs.size(); i++) {
+                PackageParser.Package clientPkg = clientLibPkgs.get(i);
+                killApplication(clientPkg.applicationInfo.packageName,
+                        clientPkg.applicationInfo.uid, "update lib");
+            }
+        }
+
+        // writer
+        synchronized (mPackages) {
+            // We don't expect installation to fail beyond this point,
+            if ((scanMode&SCAN_MONITOR) != 0) {
+                mAppDirs.put(pkg.mPath, pkg);
+            }
+            // Add the new setting to mSettings
+            mSettings.insertPackageSettingLPw(pkgSetting, pkg);
+            // Add the new setting to mPackages
+            mPackages.put(pkg.applicationInfo.packageName, pkg);
+            // Make sure we don't accidentally delete its data.
+            final Iterator<PackageCleanItem> iter = mSettings.mPackagesToBeCleaned.iterator();
+            while (iter.hasNext()) {
+                PackageCleanItem item = iter.next();
+                if (pkgName.equals(item.packageName)) {
+                    iter.remove();
+                }
+            }
+
+            // Take care of first install / last update times.
+            if (currentTime != 0) {
+                if (pkgSetting.firstInstallTime == 0) {
+                    pkgSetting.firstInstallTime = pkgSetting.lastUpdateTime = currentTime;
+                } else if ((scanMode&SCAN_UPDATE_TIME) != 0) {
+                    pkgSetting.lastUpdateTime = currentTime;
+                }
+            } else if (pkgSetting.firstInstallTime == 0) {
+                // We need *something*.  Take time time stamp of the file.
+                pkgSetting.firstInstallTime = pkgSetting.lastUpdateTime = scanFileTime;
+            } else if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) != 0) {
+                if (scanFileTime != pkgSetting.timeStamp) {
+                    // A package on the system image has changed; consider this
+                    // to be an update.
+                    pkgSetting.lastUpdateTime = scanFileTime;
+                }
+            }
+
+            // Add the package's KeySets to the global KeySetManager
+            KeySetManager ksm = mSettings.mKeySetManager;
+            try {
+                ksm.addSigningKeySetToPackage(pkg.packageName, pkg.mSigningKeys);
+                if (pkg.mKeySetMapping != null) {
+                    for (Map.Entry<String, Set<PublicKey>> entry : pkg.mKeySetMapping.entrySet()) {
+                        if (entry.getValue() != null) {
+                            ksm.addDefinedKeySetToPackage(pkg.packageName,
+                                entry.getValue(), entry.getKey());
+                        }
+                    }
+                }
+            } catch (NullPointerException e) {
+                Slog.e(TAG, "Could not add KeySet to " + pkg.packageName, e);
+            } catch (IllegalArgumentException e) {
+                Slog.e(TAG, "Could not add KeySet to malformed package" + pkg.packageName, e);
+            }
+
+            int N = pkg.providers.size();
+            StringBuilder r = null;
+            int i;
+            for (i=0; i<N; i++) {
+                PackageParser.Provider p = pkg.providers.get(i);
+                p.info.processName = fixProcessName(pkg.applicationInfo.processName,
+                        p.info.processName, pkg.applicationInfo.uid);
+                mProviders.addProvider(p);
+                p.syncable = p.info.isSyncable;
+                if (p.info.authority != null) {
+                    String names[] = p.info.authority.split(";");
+                    p.info.authority = null;
+                    for (int j = 0; j < names.length; j++) {
+                        if (j == 1 && p.syncable) {
+                            // We only want the first authority for a provider to possibly be
+                            // syncable, so if we already added this provider using a different
+                            // authority clear the syncable flag. We copy the provider before
+                            // changing it because the mProviders object contains a reference
+                            // to a provider that we don't want to change.
+                            // Only do this for the second authority since the resulting provider
+                            // object can be the same for all future authorities for this provider.
+                            p = new PackageParser.Provider(p);
+                            p.syncable = false;
+                        }
+                        if (!mProvidersByAuthority.containsKey(names[j])) {
+                            mProvidersByAuthority.put(names[j], p);
+                            if (p.info.authority == null) {
+                                p.info.authority = names[j];
+                            } else {
+                                p.info.authority = p.info.authority + ";" + names[j];
+                            }
+                            if (DEBUG_PACKAGE_SCANNING) {
+                                if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                                    Log.d(TAG, "Registered content provider: " + names[j]
+                                            + ", className = " + p.info.name + ", isSyncable = "
+                                            + p.info.isSyncable);
+                            }
+                        } else {
+                            PackageParser.Provider other = mProvidersByAuthority.get(names[j]);
+                            Slog.w(TAG, "Skipping provider name " + names[j] +
+                                    " (in package " + pkg.applicationInfo.packageName +
+                                    "): name already used by "
+                                    + ((other != null && other.getComponentName() != null)
+                                            ? other.getComponentName().getPackageName() : "?"));
+                        }
+                    }
+                }
+                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                    if (r == null) {
+                        r = new StringBuilder(256);
+                    } else {
+                        r.append(' ');
+                    }
+                    r.append(p.info.name);
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Providers: " + r);
+            }
+
+            N = pkg.services.size();
+            r = null;
+            for (i=0; i<N; i++) {
+                PackageParser.Service s = pkg.services.get(i);
+                s.info.processName = fixProcessName(pkg.applicationInfo.processName,
+                        s.info.processName, pkg.applicationInfo.uid);
+                mServices.addService(s);
+                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                    if (r == null) {
+                        r = new StringBuilder(256);
+                    } else {
+                        r.append(' ');
+                    }
+                    r.append(s.info.name);
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Services: " + r);
+            }
+
+            N = pkg.receivers.size();
+            r = null;
+            for (i=0; i<N; i++) {
+                PackageParser.Activity a = pkg.receivers.get(i);
+                a.info.processName = fixProcessName(pkg.applicationInfo.processName,
+                        a.info.processName, pkg.applicationInfo.uid);
+                mReceivers.addActivity(a, "receiver");
+                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                    if (r == null) {
+                        r = new StringBuilder(256);
+                    } else {
+                        r.append(' ');
+                    }
+                    r.append(a.info.name);
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Receivers: " + r);
+            }
+
+            N = pkg.activities.size();
+            r = null;
+            for (i=0; i<N; i++) {
+                PackageParser.Activity a = pkg.activities.get(i);
+                a.info.processName = fixProcessName(pkg.applicationInfo.processName,
+                        a.info.processName, pkg.applicationInfo.uid);
+                mActivities.addActivity(a, "activity");
+                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                    if (r == null) {
+                        r = new StringBuilder(256);
+                    } else {
+                        r.append(' ');
+                    }
+                    r.append(a.info.name);
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Activities: " + r);
+            }
+
+            N = pkg.permissionGroups.size();
+            r = null;
+            for (i=0; i<N; i++) {
+                PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i);
+                PackageParser.PermissionGroup cur = mPermissionGroups.get(pg.info.name);
+                if (cur == null) {
+                    mPermissionGroups.put(pg.info.name, pg);
+                    if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                        if (r == null) {
+                            r = new StringBuilder(256);
+                        } else {
+                            r.append(' ');
+                        }
+                        r.append(pg.info.name);
+                    }
+                } else {
+                    Slog.w(TAG, "Permission group " + pg.info.name + " from package "
+                            + pg.info.packageName + " ignored: original from "
+                            + cur.info.packageName);
+                    if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                        if (r == null) {
+                            r = new StringBuilder(256);
+                        } else {
+                            r.append(' ');
+                        }
+                        r.append("DUP:");
+                        r.append(pg.info.name);
+                    }
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Permission Groups: " + r);
+            }
+
+            N = pkg.permissions.size();
+            r = null;
+            for (i=0; i<N; i++) {
+                PackageParser.Permission p = pkg.permissions.get(i);
+                HashMap<String, BasePermission> permissionMap =
+                        p.tree ? mSettings.mPermissionTrees
+                        : mSettings.mPermissions;
+                p.group = mPermissionGroups.get(p.info.group);
+                if (p.info.group == null || p.group != null) {
+                    BasePermission bp = permissionMap.get(p.info.name);
+                    if (bp == null) {
+                        bp = new BasePermission(p.info.name, p.info.packageName,
+                                BasePermission.TYPE_NORMAL);
+                        permissionMap.put(p.info.name, bp);
+                    }
+                    if (bp.perm == null) {
+                        if (bp.sourcePackage != null
+                                && !bp.sourcePackage.equals(p.info.packageName)) {
+                            // If this is a permission that was formerly defined by a non-system
+                            // app, but is now defined by a system app (following an upgrade),
+                            // discard the previous declaration and consider the system's to be
+                            // canonical.
+                            if (isSystemApp(p.owner)) {
+                                Slog.i(TAG, "New decl " + p.owner + " of permission  "
+                                        + p.info.name + " is system");
+                                bp.sourcePackage = null;
+                            }
+                        }
+                        if (bp.sourcePackage == null
+                                || bp.sourcePackage.equals(p.info.packageName)) {
+                            BasePermission tree = findPermissionTreeLP(p.info.name);
+                            if (tree == null
+                                    || tree.sourcePackage.equals(p.info.packageName)) {
+                                bp.packageSetting = pkgSetting;
+                                bp.perm = p;
+                                bp.uid = pkg.applicationInfo.uid;
+                                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                                    if (r == null) {
+                                        r = new StringBuilder(256);
+                                    } else {
+                                        r.append(' ');
+                                    }
+                                    r.append(p.info.name);
+                                }
+                            } else {
+                                Slog.w(TAG, "Permission " + p.info.name + " from package "
+                                        + p.info.packageName + " ignored: base tree "
+                                        + tree.name + " is from package "
+                                        + tree.sourcePackage);
+                            }
+                        } else {
+                            Slog.w(TAG, "Permission " + p.info.name + " from package "
+                                    + p.info.packageName + " ignored: original from "
+                                    + bp.sourcePackage);
+                        }
+                    } else if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                        if (r == null) {
+                            r = new StringBuilder(256);
+                        } else {
+                            r.append(' ');
+                        }
+                        r.append("DUP:");
+                        r.append(p.info.name);
+                    }
+                    if (bp.perm == p) {
+                        bp.protectionLevel = p.info.protectionLevel;
+                    }
+                } else {
+                    Slog.w(TAG, "Permission " + p.info.name + " from package "
+                            + p.info.packageName + " ignored: no group "
+                            + p.group);
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Permissions: " + r);
+            }
+
+            N = pkg.instrumentation.size();
+            r = null;
+            for (i=0; i<N; i++) {
+                PackageParser.Instrumentation a = pkg.instrumentation.get(i);
+                a.info.packageName = pkg.applicationInfo.packageName;
+                a.info.sourceDir = pkg.applicationInfo.sourceDir;
+                a.info.publicSourceDir = pkg.applicationInfo.publicSourceDir;
+                a.info.dataDir = pkg.applicationInfo.dataDir;
+                a.info.nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir;
+                mInstrumentation.put(a.getComponentName(), a);
+                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
+                    if (r == null) {
+                        r = new StringBuilder(256);
+                    } else {
+                        r.append(' ');
+                    }
+                    r.append(a.info.name);
+                }
+            }
+            if (r != null) {
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Instrumentation: " + r);
+            }
+
+            if (pkg.protectedBroadcasts != null) {
+                N = pkg.protectedBroadcasts.size();
+                for (i=0; i<N; i++) {
+                    mProtectedBroadcasts.add(pkg.protectedBroadcasts.get(i));
+                }
+            }
+
+            pkgSetting.setTimeStamp(scanFileTime);
+        }
+
+        return pkg;
+    }
+
+    private void setUpCustomResolverActivity(PackageParser.Package pkg) {
+        synchronized (mPackages) {
+            mResolverReplaced = true;
+            // Set up information for custom user intent resolution activity.
+            mResolveActivity.applicationInfo = pkg.applicationInfo;
+            mResolveActivity.name = mCustomResolverComponentName.getClassName();
+            mResolveActivity.packageName = pkg.applicationInfo.packageName;
+            mResolveActivity.processName = null;
+            mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
+            mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS |
+                    ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
+            mResolveActivity.theme = 0;
+            mResolveActivity.exported = true;
+            mResolveActivity.enabled = true;
+            mResolveInfo.activityInfo = mResolveActivity;
+            mResolveInfo.priority = 0;
+            mResolveInfo.preferredOrder = 0;
+            mResolveInfo.match = 0;
+            mResolveComponentName = mCustomResolverComponentName;
+            Slog.i(TAG, "Replacing default ResolverActivity with custom activity: " +
+                    mResolveComponentName);
+        }
+    }
+
+    private void setInternalAppNativeLibraryPath(PackageParser.Package pkg,
+            PackageSetting pkgSetting) {
+        final String apkLibPath = getApkName(pkgSetting.codePathString);
+        final String nativeLibraryPath = new File(mAppLibInstallDir, apkLibPath).getPath();
+        pkg.applicationInfo.nativeLibraryDir = nativeLibraryPath;
+        pkgSetting.nativeLibraryPathString = nativeLibraryPath;
+    }
+
+    private static int copyNativeLibrariesForInternalApp(File scanFile, final File nativeLibraryDir)
+            throws IOException {
+        if (!nativeLibraryDir.isDirectory()) {
+            nativeLibraryDir.delete();
+
+            if (!nativeLibraryDir.mkdir()) {
+                throw new IOException("Cannot create " + nativeLibraryDir.getPath());
+            }
+
+            try {
+                Libcore.os.chmod(nativeLibraryDir.getPath(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH
+                        | S_IXOTH);
+            } catch (ErrnoException e) {
+                throw new IOException("Cannot chmod native library directory "
+                        + nativeLibraryDir.getPath(), e);
+            }
+        } else if (!SELinux.restorecon(nativeLibraryDir)) {
+            throw new IOException("Cannot set SELinux context for " + nativeLibraryDir.getPath());
+        }
+
+        /*
+         * If this is an internal application or our nativeLibraryPath points to
+         * the app-lib directory, unpack the libraries if necessary.
+         */
+        return NativeLibraryHelper.copyNativeBinariesIfNeededLI(scanFile, nativeLibraryDir);
+    }
+
+    private void killApplication(String pkgName, int appId, String reason) {
+        // Request the ActivityManager to kill the process(only for existing packages)
+        // so that we do not end up in a confused state while the user is still using the older
+        // version of the application while the new one gets installed.
+        IActivityManager am = ActivityManagerNative.getDefault();
+        if (am != null) {
+            try {
+                am.killApplicationWithAppId(pkgName, appId, reason);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    void removePackageLI(PackageSetting ps, boolean chatty) {
+        if (DEBUG_INSTALL) {
+            if (chatty)
+                Log.d(TAG, "Removing package " + ps.name);
+        }
+
+        // writer
+        synchronized (mPackages) {
+            mPackages.remove(ps.name);
+            if (ps.codePathString != null) {
+                mAppDirs.remove(ps.codePathString);
+            }
+
+            final PackageParser.Package pkg = ps.pkg;
+            if (pkg != null) {
+                cleanPackageDataStructuresLILPw(pkg, chatty);
+            }
+        }
+    }
+
+    void removeInstalledPackageLI(PackageParser.Package pkg, boolean chatty) {
+        if (DEBUG_INSTALL) {
+            if (chatty)
+                Log.d(TAG, "Removing package " + pkg.applicationInfo.packageName);
+        }
+
+        // writer
+        synchronized (mPackages) {
+            mPackages.remove(pkg.applicationInfo.packageName);
+            if (pkg.mPath != null) {
+                mAppDirs.remove(pkg.mPath);
+            }
+            cleanPackageDataStructuresLILPw(pkg, chatty);
+        }
+    }
+
+    void cleanPackageDataStructuresLILPw(PackageParser.Package pkg, boolean chatty) {
+        int N = pkg.providers.size();
+        StringBuilder r = null;
+        int i;
+        for (i=0; i<N; i++) {
+            PackageParser.Provider p = pkg.providers.get(i);
+            mProviders.removeProvider(p);
+            if (p.info.authority == null) {
+
+                /* There was another ContentProvider with this authority when
+                 * this app was installed so this authority is null,
+                 * Ignore it as we don't have to unregister the provider.
+                 */
+                continue;
+            }
+            String names[] = p.info.authority.split(";");
+            for (int j = 0; j < names.length; j++) {
+                if (mProvidersByAuthority.get(names[j]) == p) {
+                    mProvidersByAuthority.remove(names[j]);
+                    if (DEBUG_REMOVE) {
+                        if (chatty)
+                            Log.d(TAG, "Unregistered content provider: " + names[j]
+                                    + ", className = " + p.info.name + ", isSyncable = "
+                                    + p.info.isSyncable);
+                    }
+                }
+            }
+            if (DEBUG_REMOVE && chatty) {
+                if (r == null) {
+                    r = new StringBuilder(256);
+                } else {
+                    r.append(' ');
+                }
+                r.append(p.info.name);
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Providers: " + r);
+        }
+
+        N = pkg.services.size();
+        r = null;
+        for (i=0; i<N; i++) {
+            PackageParser.Service s = pkg.services.get(i);
+            mServices.removeService(s);
+            if (chatty) {
+                if (r == null) {
+                    r = new StringBuilder(256);
+                } else {
+                    r.append(' ');
+                }
+                r.append(s.info.name);
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Services: " + r);
+        }
+
+        N = pkg.receivers.size();
+        r = null;
+        for (i=0; i<N; i++) {
+            PackageParser.Activity a = pkg.receivers.get(i);
+            mReceivers.removeActivity(a, "receiver");
+            if (DEBUG_REMOVE && chatty) {
+                if (r == null) {
+                    r = new StringBuilder(256);
+                } else {
+                    r.append(' ');
+                }
+                r.append(a.info.name);
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Receivers: " + r);
+        }
+
+        N = pkg.activities.size();
+        r = null;
+        for (i=0; i<N; i++) {
+            PackageParser.Activity a = pkg.activities.get(i);
+            mActivities.removeActivity(a, "activity");
+            if (DEBUG_REMOVE && chatty) {
+                if (r == null) {
+                    r = new StringBuilder(256);
+                } else {
+                    r.append(' ');
+                }
+                r.append(a.info.name);
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Activities: " + r);
+        }
+
+        N = pkg.permissions.size();
+        r = null;
+        for (i=0; i<N; i++) {
+            PackageParser.Permission p = pkg.permissions.get(i);
+            BasePermission bp = mSettings.mPermissions.get(p.info.name);
+            if (bp == null) {
+                bp = mSettings.mPermissionTrees.get(p.info.name);
+            }
+            if (bp != null && bp.perm == p) {
+                bp.perm = null;
+                if (DEBUG_REMOVE && chatty) {
+                    if (r == null) {
+                        r = new StringBuilder(256);
+                    } else {
+                        r.append(' ');
+                    }
+                    r.append(p.info.name);
+                }
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Permissions: " + r);
+        }
+
+        N = pkg.instrumentation.size();
+        r = null;
+        for (i=0; i<N; i++) {
+            PackageParser.Instrumentation a = pkg.instrumentation.get(i);
+            mInstrumentation.remove(a.getComponentName());
+            if (DEBUG_REMOVE && chatty) {
+                if (r == null) {
+                    r = new StringBuilder(256);
+                } else {
+                    r.append(' ');
+                }
+                r.append(a.info.name);
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Instrumentation: " + r);
+        }
+
+        r = null;
+        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
+            // Only system apps can hold shared libraries.
+            if (pkg.libraryNames != null) {
+                for (i=0; i<pkg.libraryNames.size(); i++) {
+                    String name = pkg.libraryNames.get(i);
+                    SharedLibraryEntry cur = mSharedLibraries.get(name);
+                    if (cur != null && cur.apk != null && cur.apk.equals(pkg.packageName)) {
+                        mSharedLibraries.remove(name);
+                        if (DEBUG_REMOVE && chatty) {
+                            if (r == null) {
+                                r = new StringBuilder(256);
+                            } else {
+                                r.append(' ');
+                            }
+                            r.append(name);
+                        }
+                    }
+                }
+            }
+        }
+        if (r != null) {
+            if (DEBUG_REMOVE) Log.d(TAG, "  Libraries: " + r);
+        }
+    }
+
+    private static final boolean isPackageFilename(String name) {
+        return name != null && name.endsWith(".apk");
+    }
+
+    private static boolean hasPermission(PackageParser.Package pkgInfo, String perm) {
+        for (int i=pkgInfo.permissions.size()-1; i>=0; i--) {
+            if (pkgInfo.permissions.get(i).info.name.equals(perm)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    static final int UPDATE_PERMISSIONS_ALL = 1<<0;
+    static final int UPDATE_PERMISSIONS_REPLACE_PKG = 1<<1;
+    static final int UPDATE_PERMISSIONS_REPLACE_ALL = 1<<2;
+
+    private void updatePermissionsLPw(String changingPkg,
+            PackageParser.Package pkgInfo, int flags) {
+        // Make sure there are no dangling permission trees.
+        Iterator<BasePermission> it = mSettings.mPermissionTrees.values().iterator();
+        while (it.hasNext()) {
+            final BasePermission bp = it.next();
+            if (bp.packageSetting == null) {
+                // We may not yet have parsed the package, so just see if
+                // we still know about its settings.
+                bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage);
+            }
+            if (bp.packageSetting == null) {
+                Slog.w(TAG, "Removing dangling permission tree: " + bp.name
+                        + " from package " + bp.sourcePackage);
+                it.remove();
+            } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
+                if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) {
+                    Slog.i(TAG, "Removing old permission tree: " + bp.name
+                            + " from package " + bp.sourcePackage);
+                    flags |= UPDATE_PERMISSIONS_ALL;
+                    it.remove();
+                }
+            }
+        }
+
+        // Make sure all dynamic permissions have been assigned to a package,
+        // and make sure there are no dangling permissions.
+        it = mSettings.mPermissions.values().iterator();
+        while (it.hasNext()) {
+            final BasePermission bp = it.next();
+            if (bp.type == BasePermission.TYPE_DYNAMIC) {
+                if (DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name="
+                        + bp.name + " pkg=" + bp.sourcePackage
+                        + " info=" + bp.pendingInfo);
+                if (bp.packageSetting == null && bp.pendingInfo != null) {
+                    final BasePermission tree = findPermissionTreeLP(bp.name);
+                    if (tree != null && tree.perm != null) {
+                        bp.packageSetting = tree.packageSetting;
+                        bp.perm = new PackageParser.Permission(tree.perm.owner,
+                                new PermissionInfo(bp.pendingInfo));
+                        bp.perm.info.packageName = tree.perm.info.packageName;
+                        bp.perm.info.name = bp.name;
+                        bp.uid = tree.uid;
+                    }
+                }
+            }
+            if (bp.packageSetting == null) {
+                // We may not yet have parsed the package, so just see if
+                // we still know about its settings.
+                bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage);
+            }
+            if (bp.packageSetting == null) {
+                Slog.w(TAG, "Removing dangling permission: " + bp.name
+                        + " from package " + bp.sourcePackage);
+                it.remove();
+            } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
+                if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) {
+                    Slog.i(TAG, "Removing old permission: " + bp.name
+                            + " from package " + bp.sourcePackage);
+                    flags |= UPDATE_PERMISSIONS_ALL;
+                    it.remove();
+                }
+            }
+        }
+
+        // Now update the permissions for all packages, in particular
+        // replace the granted permissions of the system packages.
+        if ((flags&UPDATE_PERMISSIONS_ALL) != 0) {
+            for (PackageParser.Package pkg : mPackages.values()) {
+                if (pkg != pkgInfo) {
+                    grantPermissionsLPw(pkg, (flags&UPDATE_PERMISSIONS_REPLACE_ALL) != 0);
+                }
+            }
+        }
+        
+        if (pkgInfo != null) {
+            grantPermissionsLPw(pkgInfo, (flags&UPDATE_PERMISSIONS_REPLACE_PKG) != 0);
+        }
+    }
+
+    private void grantPermissionsLPw(PackageParser.Package pkg, boolean replace) {
+        final PackageSetting ps = (PackageSetting) pkg.mExtras;
+        if (ps == null) {
+            return;
+        }
+        final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
+        HashSet<String> origPermissions = gp.grantedPermissions;
+        boolean changedPermission = false;
+
+        if (replace) {
+            ps.permissionsFixed = false;
+            if (gp == ps) {
+                origPermissions = new HashSet<String>(gp.grantedPermissions);
+                gp.grantedPermissions.clear();
+                gp.gids = mGlobalGids;
+            }
+        }
+
+        if (gp.gids == null) {
+            gp.gids = mGlobalGids;
+        }
+
+        final int N = pkg.requestedPermissions.size();
+        for (int i=0; i<N; i++) {
+            final String name = pkg.requestedPermissions.get(i);
+            final boolean required = pkg.requestedPermissionsRequired.get(i);
+            final BasePermission bp = mSettings.mPermissions.get(name);
+            if (DEBUG_INSTALL) {
+                if (gp != ps) {
+                    Log.i(TAG, "Package " + pkg.packageName + " checking " + name + ": " + bp);
+                }
+            }
+
+            if (bp == null || bp.packageSetting == null) {
+                Slog.w(TAG, "Unknown permission " + name
+                        + " in package " + pkg.packageName);
+                continue;
+            }
+
+            final String perm = bp.name;
+            boolean allowed;
+            boolean allowedSig = false;
+            final int level = bp.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
+            if (level == PermissionInfo.PROTECTION_NORMAL
+                    || level == PermissionInfo.PROTECTION_DANGEROUS) {
+                // We grant a normal or dangerous permission if any of the following
+                // are true:
+                // 1) The permission is required
+                // 2) The permission is optional, but was granted in the past
+                // 3) The permission is optional, but was requested by an
+                //    app in /system (not /data)
+                //
+                // Otherwise, reject the permission.
+                allowed = (required || origPermissions.contains(perm)
+                        || (isSystemApp(ps) && !isUpdatedSystemApp(ps)));
+            } else if (bp.packageSetting == null) {
+                // This permission is invalid; skip it.
+                allowed = false;
+            } else if (level == PermissionInfo.PROTECTION_SIGNATURE) {
+                allowed = grantSignaturePermission(perm, pkg, bp, origPermissions);
+                if (allowed) {
+                    allowedSig = true;
+                }
+            } else {
+                allowed = false;
+            }
+            if (DEBUG_INSTALL) {
+                if (gp != ps) {
+                    Log.i(TAG, "Package " + pkg.packageName + " granting " + perm);
+                }
+            }
+            if (allowed) {
+                if (!isSystemApp(ps) && ps.permissionsFixed) {
+                    // If this is an existing, non-system package, then
+                    // we can't add any new permissions to it.
+                    if (!allowedSig && !gp.grantedPermissions.contains(perm)) {
+                        // Except...  if this is a permission that was added
+                        // to the platform (note: need to only do this when
+                        // updating the platform).
+                        allowed = isNewPlatformPermissionForPackage(perm, pkg);
+                    }
+                }
+                if (allowed) {
+                    if (!gp.grantedPermissions.contains(perm)) {
+                        changedPermission = true;
+                        gp.grantedPermissions.add(perm);
+                        gp.gids = appendInts(gp.gids, bp.gids);
+                    } else if (!ps.haveGids) {
+                        gp.gids = appendInts(gp.gids, bp.gids);
+                    }
+                } else {
+                    Slog.w(TAG, "Not granting permission " + perm
+                            + " to package " + pkg.packageName
+                            + " because it was previously installed without");
+                }
+            } else {
+                if (gp.grantedPermissions.remove(perm)) {
+                    changedPermission = true;
+                    gp.gids = removeInts(gp.gids, bp.gids);
+                    Slog.i(TAG, "Un-granting permission " + perm
+                            + " from package " + pkg.packageName
+                            + " (protectionLevel=" + bp.protectionLevel
+                            + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags)
+                            + ")");
+                } else {
+                    Slog.w(TAG, "Not granting permission " + perm
+                            + " to package " + pkg.packageName
+                            + " (protectionLevel=" + bp.protectionLevel
+                            + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags)
+                            + ")");
+                }
+            }
+        }
+
+        if ((changedPermission || replace) && !ps.permissionsFixed &&
+                !isSystemApp(ps) || isUpdatedSystemApp(ps)){
+            // This is the first that we have heard about this package, so the
+            // permissions we have now selected are fixed until explicitly
+            // changed.
+            ps.permissionsFixed = true;
+        }
+        ps.haveGids = true;
+    }
+
+    private boolean isNewPlatformPermissionForPackage(String perm, PackageParser.Package pkg) {
+        boolean allowed = false;
+        final int NP = PackageParser.NEW_PERMISSIONS.length;
+        for (int ip=0; ip<NP; ip++) {
+            final PackageParser.NewPermissionInfo npi
+                    = PackageParser.NEW_PERMISSIONS[ip];
+            if (npi.name.equals(perm)
+                    && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) {
+                allowed = true;
+                Log.i(TAG, "Auto-granting " + perm + " to old pkg "
+                        + pkg.packageName);
+                break;
+            }
+        }
+        return allowed;
+    }
+
+    private boolean grantSignaturePermission(String perm, PackageParser.Package pkg,
+                                          BasePermission bp, HashSet<String> origPermissions) {
+        boolean allowed;
+        allowed = (compareSignatures(
+                bp.packageSetting.signatures.mSignatures, pkg.mSignatures)
+                        == PackageManager.SIGNATURE_MATCH)
+                || (compareSignatures(mPlatformPackage.mSignatures, pkg.mSignatures)
+                        == PackageManager.SIGNATURE_MATCH);
+        if (!allowed && (bp.protectionLevel
+                & PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) {
+            if (isSystemApp(pkg)) {
+                // For updated system applications, a system permission
+                // is granted only if it had been defined by the original application.
+                if (isUpdatedSystemApp(pkg)) {
+                    final PackageSetting sysPs = mSettings
+                            .getDisabledSystemPkgLPr(pkg.packageName);
+                    final GrantedPermissions origGp = sysPs.sharedUser != null
+                            ? sysPs.sharedUser : sysPs;
+
+                    if (origGp.grantedPermissions.contains(perm)) {
+                        // If the original was granted this permission, we take
+                        // that grant decision as read and propagate it to the
+                        // update.
+                        allowed = true;
+                    } else {
+                        // The system apk may have been updated with an older
+                        // version of the one on the data partition, but which
+                        // granted a new system permission that it didn't have
+                        // before.  In this case we do want to allow the app to
+                        // now get the new permission if the ancestral apk is
+                        // privileged to get it.
+                        if (sysPs.pkg != null && sysPs.isPrivileged()) {
+                            for (int j=0;
+                                    j<sysPs.pkg.requestedPermissions.size(); j++) {
+                                if (perm.equals(
+                                        sysPs.pkg.requestedPermissions.get(j))) {
+                                    allowed = true;
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                } else {
+                    allowed = isPrivilegedApp(pkg);
+                }
+            }
+        }
+        if (!allowed && (bp.protectionLevel
+                & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
+            // For development permissions, a development permission
+            // is granted only if it was already granted.
+            allowed = origPermissions.contains(perm);
+        }
+        return allowed;
+    }
+
+    final class ActivityIntentResolver
+            extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
+                boolean defaultOnly, int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
+            return super.queryIntent(intent, resolvedType, defaultOnly, userId);
+        }
+
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
+                int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            mFlags = flags;
+            return super.queryIntent(intent, resolvedType,
+                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
+        }
+
+        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
+                int flags, ArrayList<PackageParser.Activity> packageActivities, int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            if (packageActivities == null) {
+                return null;
+            }
+            mFlags = flags;
+            final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
+            final int N = packageActivities.size();
+            ArrayList<PackageParser.ActivityIntentInfo[]> listCut =
+                new ArrayList<PackageParser.ActivityIntentInfo[]>(N);
+
+            ArrayList<PackageParser.ActivityIntentInfo> intentFilters;
+            for (int i = 0; i < N; ++i) {
+                intentFilters = packageActivities.get(i).intents;
+                if (intentFilters != null && intentFilters.size() > 0) {
+                    PackageParser.ActivityIntentInfo[] array =
+                            new PackageParser.ActivityIntentInfo[intentFilters.size()];
+                    intentFilters.toArray(array);
+                    listCut.add(array);
+                }
+            }
+            return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
+        }
+
+        public final void addActivity(PackageParser.Activity a, String type) {
+            final boolean systemApp = isSystemApp(a.info.applicationInfo);
+            mActivities.put(a.getComponentName(), a);
+            if (DEBUG_SHOW_INFO)
+                Log.v(
+                TAG, "  " + type + " " +
+                (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
+            if (DEBUG_SHOW_INFO)
+                Log.v(TAG, "    Class=" + a.info.name);
+            final int NI = a.intents.size();
+            for (int j=0; j<NI; j++) {
+                PackageParser.ActivityIntentInfo intent = a.intents.get(j);
+                if (!systemApp && intent.getPriority() > 0 && "activity".equals(type)) {
+                    intent.setPriority(0);
+                    Log.w(TAG, "Package " + a.info.applicationInfo.packageName + " has activity "
+                            + a.className + " with priority > 0, forcing to 0");
+                }
+                if (DEBUG_SHOW_INFO) {
+                    Log.v(TAG, "    IntentFilter:");
+                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
+                }
+                if (!intent.debugCheck()) {
+                    Log.w(TAG, "==> For Activity " + a.info.name);
+                }
+                addFilter(intent);
+            }
+        }
+
+        public final void removeActivity(PackageParser.Activity a, String type) {
+            mActivities.remove(a.getComponentName());
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  " + type + " "
+                        + (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel
+                                : a.info.name) + ":");
+                Log.v(TAG, "    Class=" + a.info.name);
+            }
+            final int NI = a.intents.size();
+            for (int j=0; j<NI; j++) {
+                PackageParser.ActivityIntentInfo intent = a.intents.get(j);
+                if (DEBUG_SHOW_INFO) {
+                    Log.v(TAG, "    IntentFilter:");
+                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
+                }
+                removeFilter(intent);
+            }
+        }
+
+        @Override
+        protected boolean allowFilterResult(
+                PackageParser.ActivityIntentInfo filter, List<ResolveInfo> dest) {
+            ActivityInfo filterAi = filter.activity.info;
+            for (int i=dest.size()-1; i>=0; i--) {
+                ActivityInfo destAi = dest.get(i).activityInfo;
+                if (destAi.name == filterAi.name
+                        && destAi.packageName == filterAi.packageName) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        @Override
+        protected ActivityIntentInfo[] newArray(int size) {
+            return new ActivityIntentInfo[size];
+        }
+
+        @Override
+        protected boolean isFilterStopped(PackageParser.ActivityIntentInfo filter, int userId) {
+            if (!sUserManager.exists(userId)) return true;
+            PackageParser.Package p = filter.activity.owner;
+            if (p != null) {
+                PackageSetting ps = (PackageSetting)p.mExtras;
+                if (ps != null) {
+                    // System apps are never considered stopped for purposes of
+                    // filtering, because there may be no way for the user to
+                    // actually re-launch them.
+                    return (ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0
+                            && ps.getStopped(userId);
+                }
+            }
+            return false;
+        }
+
+        @Override
+        protected boolean isPackageForFilter(String packageName,
+                PackageParser.ActivityIntentInfo info) {
+            return packageName.equals(info.activity.owner.packageName);
+        }
+        
+        @Override
+        protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info,
+                int match, int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            if (!mSettings.isEnabledLPr(info.activity.info, mFlags, userId)) {
+                return null;
+            }
+            final PackageParser.Activity activity = info.activity;
+            if (mSafeMode && (activity.info.applicationInfo.flags
+                    &ApplicationInfo.FLAG_SYSTEM) == 0) {
+                return null;
+            }
+            PackageSetting ps = (PackageSetting) activity.owner.mExtras;
+            if (ps == null) {
+                return null;
+            }
+            ActivityInfo ai = PackageParser.generateActivityInfo(activity, mFlags,
+                    ps.readUserState(userId), userId);
+            if (ai == null) {
+                return null;
+            }
+            final ResolveInfo res = new ResolveInfo();
+            res.activityInfo = ai;
+            if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) {
+                res.filter = info;
+            }
+            res.priority = info.getPriority();
+            res.preferredOrder = activity.owner.mPreferredOrder;
+            //System.out.println("Result: " + res.activityInfo.className +
+            //                   " = " + res.priority);
+            res.match = match;
+            res.isDefault = info.hasDefault;
+            res.labelRes = info.labelRes;
+            res.nonLocalizedLabel = info.nonLocalizedLabel;
+            res.icon = info.icon;
+            res.system = isSystemApp(res.activityInfo.applicationInfo);
+            return res;
+        }
+
+        @Override
+        protected void sortResults(List<ResolveInfo> results) {
+            Collections.sort(results, mResolvePrioritySorter);
+        }
+
+        @Override
+        protected void dumpFilter(PrintWriter out, String prefix,
+                PackageParser.ActivityIntentInfo filter) {
+            out.print(prefix); out.print(
+                    Integer.toHexString(System.identityHashCode(filter.activity)));
+                    out.print(' ');
+                    filter.activity.printComponentShortName(out);
+                    out.print(" filter ");
+                    out.println(Integer.toHexString(System.identityHashCode(filter)));
+        }
+
+//        List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) {
+//            final Iterator<ResolveInfo> i = resolveInfoList.iterator();
+//            final List<ResolveInfo> retList = Lists.newArrayList();
+//            while (i.hasNext()) {
+//                final ResolveInfo resolveInfo = i.next();
+//                if (isEnabledLP(resolveInfo.activityInfo)) {
+//                    retList.add(resolveInfo);
+//                }
+//            }
+//            return retList;
+//        }
+
+        // Keys are String (activity class name), values are Activity.
+        private final HashMap<ComponentName, PackageParser.Activity> mActivities
+                = new HashMap<ComponentName, PackageParser.Activity>();
+        private int mFlags;
+    }
+
+    private final class ServiceIntentResolver
+            extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
+                boolean defaultOnly, int userId) {
+            mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
+            return super.queryIntent(intent, resolvedType, defaultOnly, userId);
+        }
+
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
+                int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            mFlags = flags;
+            return super.queryIntent(intent, resolvedType,
+                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
+        }
+
+        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
+                int flags, ArrayList<PackageParser.Service> packageServices, int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            if (packageServices == null) {
+                return null;
+            }
+            mFlags = flags;
+            final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
+            final int N = packageServices.size();
+            ArrayList<PackageParser.ServiceIntentInfo[]> listCut =
+                new ArrayList<PackageParser.ServiceIntentInfo[]>(N);
+
+            ArrayList<PackageParser.ServiceIntentInfo> intentFilters;
+            for (int i = 0; i < N; ++i) {
+                intentFilters = packageServices.get(i).intents;
+                if (intentFilters != null && intentFilters.size() > 0) {
+                    PackageParser.ServiceIntentInfo[] array =
+                            new PackageParser.ServiceIntentInfo[intentFilters.size()];
+                    intentFilters.toArray(array);
+                    listCut.add(array);
+                }
+            }
+            return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
+        }
+
+        public final void addService(PackageParser.Service s) {
+            mServices.put(s.getComponentName(), s);
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  "
+                        + (s.info.nonLocalizedLabel != null
+                        ? s.info.nonLocalizedLabel : s.info.name) + ":");
+                Log.v(TAG, "    Class=" + s.info.name);
+            }
+            final int NI = s.intents.size();
+            int j;
+            for (j=0; j<NI; j++) {
+                PackageParser.ServiceIntentInfo intent = s.intents.get(j);
+                if (DEBUG_SHOW_INFO) {
+                    Log.v(TAG, "    IntentFilter:");
+                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
+                }
+                if (!intent.debugCheck()) {
+                    Log.w(TAG, "==> For Service " + s.info.name);
+                }
+                addFilter(intent);
+            }
+        }
+
+        public final void removeService(PackageParser.Service s) {
+            mServices.remove(s.getComponentName());
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  " + (s.info.nonLocalizedLabel != null
+                        ? s.info.nonLocalizedLabel : s.info.name) + ":");
+                Log.v(TAG, "    Class=" + s.info.name);
+            }
+            final int NI = s.intents.size();
+            int j;
+            for (j=0; j<NI; j++) {
+                PackageParser.ServiceIntentInfo intent = s.intents.get(j);
+                if (DEBUG_SHOW_INFO) {
+                    Log.v(TAG, "    IntentFilter:");
+                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
+                }
+                removeFilter(intent);
+            }
+        }
+
+        @Override
+        protected boolean allowFilterResult(
+                PackageParser.ServiceIntentInfo filter, List<ResolveInfo> dest) {
+            ServiceInfo filterSi = filter.service.info;
+            for (int i=dest.size()-1; i>=0; i--) {
+                ServiceInfo destAi = dest.get(i).serviceInfo;
+                if (destAi.name == filterSi.name
+                        && destAi.packageName == filterSi.packageName) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        @Override
+        protected PackageParser.ServiceIntentInfo[] newArray(int size) {
+            return new PackageParser.ServiceIntentInfo[size];
+        }
+
+        @Override
+        protected boolean isFilterStopped(PackageParser.ServiceIntentInfo filter, int userId) {
+            if (!sUserManager.exists(userId)) return true;
+            PackageParser.Package p = filter.service.owner;
+            if (p != null) {
+                PackageSetting ps = (PackageSetting)p.mExtras;
+                if (ps != null) {
+                    // System apps are never considered stopped for purposes of
+                    // filtering, because there may be no way for the user to
+                    // actually re-launch them.
+                    return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
+                            && ps.getStopped(userId);
+                }
+            }
+            return false;
+        }
+
+        @Override
+        protected boolean isPackageForFilter(String packageName,
+                PackageParser.ServiceIntentInfo info) {
+            return packageName.equals(info.service.owner.packageName);
+        }
+        
+        @Override
+        protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter,
+                int match, int userId) {
+            if (!sUserManager.exists(userId)) return null;
+            final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter;
+            if (!mSettings.isEnabledLPr(info.service.info, mFlags, userId)) {
+                return null;
+            }
+            final PackageParser.Service service = info.service;
+            if (mSafeMode && (service.info.applicationInfo.flags
+                    &ApplicationInfo.FLAG_SYSTEM) == 0) {
+                return null;
+            }
+            PackageSetting ps = (PackageSetting) service.owner.mExtras;
+            if (ps == null) {
+                return null;
+            }
+            ServiceInfo si = PackageParser.generateServiceInfo(service, mFlags,
+                    ps.readUserState(userId), userId);
+            if (si == null) {
+                return null;
+            }
+            final ResolveInfo res = new ResolveInfo();
+            res.serviceInfo = si;
+            if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) {
+                res.filter = filter;
+            }
+            res.priority = info.getPriority();
+            res.preferredOrder = service.owner.mPreferredOrder;
+            //System.out.println("Result: " + res.activityInfo.className +
+            //                   " = " + res.priority);
+            res.match = match;
+            res.isDefault = info.hasDefault;
+            res.labelRes = info.labelRes;
+            res.nonLocalizedLabel = info.nonLocalizedLabel;
+            res.icon = info.icon;
+            res.system = isSystemApp(res.serviceInfo.applicationInfo);
+            return res;
+        }
+
+        @Override
+        protected void sortResults(List<ResolveInfo> results) {
+            Collections.sort(results, mResolvePrioritySorter);
+        }
+
+        @Override
+        protected void dumpFilter(PrintWriter out, String prefix,
+                PackageParser.ServiceIntentInfo filter) {
+            out.print(prefix); out.print(
+                    Integer.toHexString(System.identityHashCode(filter.service)));
+                    out.print(' ');
+                    filter.service.printComponentShortName(out);
+                    out.print(" filter ");
+                    out.println(Integer.toHexString(System.identityHashCode(filter)));
+        }
+
+//        List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) {
+//            final Iterator<ResolveInfo> i = resolveInfoList.iterator();
+//            final List<ResolveInfo> retList = Lists.newArrayList();
+//            while (i.hasNext()) {
+//                final ResolveInfo resolveInfo = (ResolveInfo) i;
+//                if (isEnabledLP(resolveInfo.serviceInfo)) {
+//                    retList.add(resolveInfo);
+//                }
+//            }
+//            return retList;
+//        }
+
+        // Keys are String (activity class name), values are Activity.
+        private final HashMap<ComponentName, PackageParser.Service> mServices
+                = new HashMap<ComponentName, PackageParser.Service>();
+        private int mFlags;
+    };
+
+    private final class ProviderIntentResolver
+            extends IntentResolver<PackageParser.ProviderIntentInfo, ResolveInfo> {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
+                boolean defaultOnly, int userId) {
+            mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
+            return super.queryIntent(intent, resolvedType, defaultOnly, userId);
+        }
+
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
+                int userId) {
+            if (!sUserManager.exists(userId))
+                return null;
+            mFlags = flags;
+            return super.queryIntent(intent, resolvedType,
+                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
+        }
+
+        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
+                int flags, ArrayList<PackageParser.Provider> packageProviders, int userId) {
+            if (!sUserManager.exists(userId))
+                return null;
+            if (packageProviders == null) {
+                return null;
+            }
+            mFlags = flags;
+            final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
+            final int N = packageProviders.size();
+            ArrayList<PackageParser.ProviderIntentInfo[]> listCut =
+                    new ArrayList<PackageParser.ProviderIntentInfo[]>(N);
+
+            ArrayList<PackageParser.ProviderIntentInfo> intentFilters;
+            for (int i = 0; i < N; ++i) {
+                intentFilters = packageProviders.get(i).intents;
+                if (intentFilters != null && intentFilters.size() > 0) {
+                    PackageParser.ProviderIntentInfo[] array =
+                            new PackageParser.ProviderIntentInfo[intentFilters.size()];
+                    intentFilters.toArray(array);
+                    listCut.add(array);
+                }
+            }
+            return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
+        }
+
+        public final void addProvider(PackageParser.Provider p) {
+            mProviders.put(p.getComponentName(), p);
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  "
+                        + (p.info.nonLocalizedLabel != null
+                                ? p.info.nonLocalizedLabel : p.info.name) + ":");
+                Log.v(TAG, "    Class=" + p.info.name);
+            }
+            final int NI = p.intents.size();
+            int j;
+            for (j = 0; j < NI; j++) {
+                PackageParser.ProviderIntentInfo intent = p.intents.get(j);
+                if (DEBUG_SHOW_INFO) {
+                    Log.v(TAG, "    IntentFilter:");
+                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
+                }
+                if (!intent.debugCheck()) {
+                    Log.w(TAG, "==> For Provider " + p.info.name);
+                }
+                addFilter(intent);
+            }
+        }
+
+        public final void removeProvider(PackageParser.Provider p) {
+            mProviders.remove(p.getComponentName());
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  " + (p.info.nonLocalizedLabel != null
+                        ? p.info.nonLocalizedLabel : p.info.name) + ":");
+                Log.v(TAG, "    Class=" + p.info.name);
+            }
+            final int NI = p.intents.size();
+            int j;
+            for (j = 0; j < NI; j++) {
+                PackageParser.ProviderIntentInfo intent = p.intents.get(j);
+                if (DEBUG_SHOW_INFO) {
+                    Log.v(TAG, "    IntentFilter:");
+                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
+                }
+                removeFilter(intent);
+            }
+        }
+
+        @Override
+        protected boolean allowFilterResult(
+                PackageParser.ProviderIntentInfo filter, List<ResolveInfo> dest) {
+            ProviderInfo filterPi = filter.provider.info;
+            for (int i = dest.size() - 1; i >= 0; i--) {
+                ProviderInfo destPi = dest.get(i).providerInfo;
+                if (destPi.name == filterPi.name
+                        && destPi.packageName == filterPi.packageName) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        @Override
+        protected PackageParser.ProviderIntentInfo[] newArray(int size) {
+            return new PackageParser.ProviderIntentInfo[size];
+        }
+
+        @Override
+        protected boolean isFilterStopped(PackageParser.ProviderIntentInfo filter, int userId) {
+            if (!sUserManager.exists(userId))
+                return true;
+            PackageParser.Package p = filter.provider.owner;
+            if (p != null) {
+                PackageSetting ps = (PackageSetting) p.mExtras;
+                if (ps != null) {
+                    // System apps are never considered stopped for purposes of
+                    // filtering, because there may be no way for the user to
+                    // actually re-launch them.
+                    return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
+                            && ps.getStopped(userId);
+                }
+            }
+            return false;
+        }
+
+        @Override
+        protected boolean isPackageForFilter(String packageName,
+                PackageParser.ProviderIntentInfo info) {
+            return packageName.equals(info.provider.owner.packageName);
+        }
+
+        @Override
+        protected ResolveInfo newResult(PackageParser.ProviderIntentInfo filter,
+                int match, int userId) {
+            if (!sUserManager.exists(userId))
+                return null;
+            final PackageParser.ProviderIntentInfo info = filter;
+            if (!mSettings.isEnabledLPr(info.provider.info, mFlags, userId)) {
+                return null;
+            }
+            final PackageParser.Provider provider = info.provider;
+            if (mSafeMode && (provider.info.applicationInfo.flags
+                    & ApplicationInfo.FLAG_SYSTEM) == 0) {
+                return null;
+            }
+            PackageSetting ps = (PackageSetting) provider.owner.mExtras;
+            if (ps == null) {
+                return null;
+            }
+            ProviderInfo pi = PackageParser.generateProviderInfo(provider, mFlags,
+                    ps.readUserState(userId), userId);
+            if (pi == null) {
+                return null;
+            }
+            final ResolveInfo res = new ResolveInfo();
+            res.providerInfo = pi;
+            if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
+                res.filter = filter;
+            }
+            res.priority = info.getPriority();
+            res.preferredOrder = provider.owner.mPreferredOrder;
+            res.match = match;
+            res.isDefault = info.hasDefault;
+            res.labelRes = info.labelRes;
+            res.nonLocalizedLabel = info.nonLocalizedLabel;
+            res.icon = info.icon;
+            res.system = isSystemApp(res.providerInfo.applicationInfo);
+            return res;
+        }
+
+        @Override
+        protected void sortResults(List<ResolveInfo> results) {
+            Collections.sort(results, mResolvePrioritySorter);
+        }
+
+        @Override
+        protected void dumpFilter(PrintWriter out, String prefix,
+                PackageParser.ProviderIntentInfo filter) {
+            out.print(prefix);
+            out.print(
+                    Integer.toHexString(System.identityHashCode(filter.provider)));
+            out.print(' ');
+            filter.provider.printComponentShortName(out);
+            out.print(" filter ");
+            out.println(Integer.toHexString(System.identityHashCode(filter)));
+        }
+
+        private final HashMap<ComponentName, PackageParser.Provider> mProviders
+                = new HashMap<ComponentName, PackageParser.Provider>();
+        private int mFlags;
+    };
+
+    private static final Comparator<ResolveInfo> mResolvePrioritySorter =
+            new Comparator<ResolveInfo>() {
+        public int compare(ResolveInfo r1, ResolveInfo r2) {
+            int v1 = r1.priority;
+            int v2 = r2.priority;
+            //System.out.println("Comparing: q1=" + q1 + " q2=" + q2);
+            if (v1 != v2) {
+                return (v1 > v2) ? -1 : 1;
+            }
+            v1 = r1.preferredOrder;
+            v2 = r2.preferredOrder;
+            if (v1 != v2) {
+                return (v1 > v2) ? -1 : 1;
+            }
+            if (r1.isDefault != r2.isDefault) {
+                return r1.isDefault ? -1 : 1;
+            }
+            v1 = r1.match;
+            v2 = r2.match;
+            //System.out.println("Comparing: m1=" + m1 + " m2=" + m2);
+            if (v1 != v2) {
+                return (v1 > v2) ? -1 : 1;
+            }
+            if (r1.system != r2.system) {
+                return r1.system ? -1 : 1;
+            }
+            return 0;
+        }
+    };
+
+    private static final Comparator<ProviderInfo> mProviderInitOrderSorter =
+            new Comparator<ProviderInfo>() {
+        public int compare(ProviderInfo p1, ProviderInfo p2) {
+            final int v1 = p1.initOrder;
+            final int v2 = p2.initOrder;
+            return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0);
+        }
+    };
+
+    static final void sendPackageBroadcast(String action, String pkg,
+            Bundle extras, String targetPkg, IIntentReceiver finishedReceiver,
+            int[] userIds) {
+        IActivityManager am = ActivityManagerNative.getDefault();
+        if (am != null) {
+            try {
+                if (userIds == null) {
+                    userIds = am.getRunningUserIds();
+                }
+                for (int id : userIds) {
+                    final Intent intent = new Intent(action,
+                            pkg != null ? Uri.fromParts("package", pkg, null) : null);
+                    if (extras != null) {
+                        intent.putExtras(extras);
+                    }
+                    if (targetPkg != null) {
+                        intent.setPackage(targetPkg);
+                    }
+                    // Modify the UID when posting to other users
+                    int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
+                    if (uid > 0 && UserHandle.getUserId(uid) != id) {
+                        uid = UserHandle.getUid(id, UserHandle.getAppId(uid));
+                        intent.putExtra(Intent.EXTRA_UID, uid);
+                    }
+                    intent.putExtra(Intent.EXTRA_USER_HANDLE, id);
+                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+                    if (DEBUG_BROADCASTS) {
+                        RuntimeException here = new RuntimeException("here");
+                        here.fillInStackTrace();
+                        Slog.d(TAG, "Sending to user " + id + ": "
+                                + intent.toShortString(false, true, false, false)
+                                + " " + intent.getExtras(), here);
+                    }
+                    am.broadcastIntent(null, intent, null, finishedReceiver,
+                            0, null, null, null, android.app.AppOpsManager.OP_NONE,
+                            finishedReceiver != null, false, id);
+                }
+            } catch (RemoteException ex) {
+            }
+        }
+    }
+
+    /**
+     * Check if the external storage media is available. This is true if there
+     * is a mounted external storage medium or if the external storage is
+     * emulated.
+     */
+    private boolean isExternalMediaAvailable() {
+        return mMediaMounted || Environment.isExternalStorageEmulated();
+    }
+
+    public PackageCleanItem nextPackageToClean(PackageCleanItem lastPackage) {
+        // writer
+        synchronized (mPackages) {
+            if (!isExternalMediaAvailable()) {
+                // If the external storage is no longer mounted at this point,
+                // the caller may not have been able to delete all of this
+                // packages files and can not delete any more.  Bail.
+                return null;
+            }
+            final ArrayList<PackageCleanItem> pkgs = mSettings.mPackagesToBeCleaned;
+            if (lastPackage != null) {
+                pkgs.remove(lastPackage);
+            }
+            if (pkgs.size() > 0) {
+                return pkgs.get(0);
+            }
+        }
+        return null;
+    }
+
+    void schedulePackageCleaning(String packageName, int userId, boolean andCode) {
+        if (false) {
+            RuntimeException here = new RuntimeException("here");
+            here.fillInStackTrace();
+            Slog.d(TAG, "Schedule cleaning " + packageName + " user=" + userId
+                    + " andCode=" + andCode, here);
+        }
+        mHandler.sendMessage(mHandler.obtainMessage(START_CLEANING_PACKAGE,
+                userId, andCode ? 1 : 0, packageName));
+    }
+    
+    void startCleaningPackages() {
+        // reader
+        synchronized (mPackages) {
+            if (!isExternalMediaAvailable()) {
+                return;
+            }
+            if (mSettings.mPackagesToBeCleaned.isEmpty()) {
+                return;
+            }
+        }
+        Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE);
+        intent.setComponent(DEFAULT_CONTAINER_COMPONENT);
+        IActivityManager am = ActivityManagerNative.getDefault();
+        if (am != null) {
+            try {
+                am.startService(null, intent, null, UserHandle.USER_OWNER);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+    
+    private final class AppDirObserver extends FileObserver {
+        public AppDirObserver(String path, int mask, boolean isrom, boolean isPrivileged) {
+            super(path, mask);
+            mRootDir = path;
+            mIsRom = isrom;
+            mIsPrivileged = isPrivileged;
+        }
+
+        public void onEvent(int event, String path) {
+            String removedPackage = null;
+            int removedAppId = -1;
+            int[] removedUsers = null;
+            String addedPackage = null;
+            int addedAppId = -1;
+            int[] addedUsers = null;
+
+            // TODO post a message to the handler to obtain serial ordering
+            synchronized (mInstallLock) {
+                String fullPathStr = null;
+                File fullPath = null;
+                if (path != null) {
+                    fullPath = new File(mRootDir, path);
+                    fullPathStr = fullPath.getPath();
+                }
+
+                if (DEBUG_APP_DIR_OBSERVER)
+                    Log.v(TAG, "File " + fullPathStr + " changed: " + Integer.toHexString(event));
+
+                if (!isPackageFilename(path)) {
+                    if (DEBUG_APP_DIR_OBSERVER)
+                        Log.v(TAG, "Ignoring change of non-package file: " + fullPathStr);
+                    return;
+                }
+
+                // Ignore packages that are being installed or
+                // have just been installed.
+                if (ignoreCodePath(fullPathStr)) {
+                    return;
+                }
+                PackageParser.Package p = null;
+                PackageSetting ps = null;
+                // reader
+                synchronized (mPackages) {
+                    p = mAppDirs.get(fullPathStr);
+                    if (p != null) {
+                        ps = mSettings.mPackages.get(p.applicationInfo.packageName);
+                        if (ps != null) {
+                            removedUsers = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
+                        } else {
+                            removedUsers = sUserManager.getUserIds();
+                        }
+                    }
+                    addedUsers = sUserManager.getUserIds();
+                }
+                if ((event&REMOVE_EVENTS) != 0) {
+                    if (ps != null) {
+                        if (DEBUG_REMOVE) Slog.d(TAG, "Package disappeared: " + ps);
+                        removePackageLI(ps, true);
+                        removedPackage = ps.name;
+                        removedAppId = ps.appId;
+                    }
+                }
+
+                if ((event&ADD_EVENTS) != 0) {
+                    if (p == null) {
+                        if (DEBUG_INSTALL) Slog.d(TAG, "New file appeared: " + fullPath);
+                        int flags = PackageParser.PARSE_CHATTY | PackageParser.PARSE_MUST_BE_APK;
+                        if (mIsRom) {
+                            flags |= PackageParser.PARSE_IS_SYSTEM
+                                    | PackageParser.PARSE_IS_SYSTEM_DIR;
+                            if (mIsPrivileged) {
+                                flags |= PackageParser.PARSE_IS_PRIVILEGED;
+                            }
+                        }
+                        p = scanPackageLI(fullPath, flags,
+                                SCAN_MONITOR | SCAN_NO_PATHS | SCAN_UPDATE_TIME,
+                                System.currentTimeMillis(), UserHandle.ALL);
+                        if (p != null) {
+                            /*
+                             * TODO this seems dangerous as the package may have
+                             * changed since we last acquired the mPackages
+                             * lock.
+                             */
+                            // writer
+                            synchronized (mPackages) {
+                                updatePermissionsLPw(p.packageName, p,
+                                        p.permissions.size() > 0 ? UPDATE_PERMISSIONS_ALL : 0);
+                            }
+                            addedPackage = p.applicationInfo.packageName;
+                            addedAppId = UserHandle.getAppId(p.applicationInfo.uid);
+                        }
+                    }
+                }
+
+                // reader
+                synchronized (mPackages) {
+                    mSettings.writeLPr();
+                }
+            }
+
+            if (removedPackage != null) {
+                Bundle extras = new Bundle(1);
+                extras.putInt(Intent.EXTRA_UID, removedAppId);
+                extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false);
+                sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage,
+                        extras, null, null, removedUsers);
+            }
+            if (addedPackage != null) {
+                Bundle extras = new Bundle(1);
+                extras.putInt(Intent.EXTRA_UID, addedAppId);
+                sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage,
+                        extras, null, null, addedUsers);
+            }
+        }
+
+        private final String mRootDir;
+        private final boolean mIsRom;
+        private final boolean mIsPrivileged;
+    }
+
+    /* Called when a downloaded package installation has been confirmed by the user */
+    public void installPackage(
+            final Uri packageURI, final IPackageInstallObserver observer, final int flags) {
+        installPackage(packageURI, observer, flags, null);
+    }
+
+    /* Called when a downloaded package installation has been confirmed by the user */
+    public void installPackage(
+            final Uri packageURI, final IPackageInstallObserver observer, final int flags,
+            final String installerPackageName) {
+        installPackageWithVerification(packageURI, observer, flags, installerPackageName, null,
+                null, null);
+    }
+
+    @Override
+    public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
+            int flags, String installerPackageName, Uri verificationURI,
+            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
+        VerificationParams verificationParams = new VerificationParams(verificationURI, null, null,
+                VerificationParams.NO_UID, manifestDigest);
+        installPackageWithVerificationAndEncryption(packageURI, observer, flags,
+                installerPackageName, verificationParams, encryptionParams);
+    }
+
+    public void installPackageWithVerificationAndEncryption(Uri packageURI,
+            IPackageInstallObserver observer, int flags, String installerPackageName,
+            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.INSTALL_PACKAGES,
+                null);
+
+        final int uid = Binder.getCallingUid();
+        if (isUserRestricted(UserHandle.getUserId(uid), UserManager.DISALLOW_INSTALL_APPS)) {
+            try {
+                observer.packageInstalled("", PackageManager.INSTALL_FAILED_USER_RESTRICTED);
+            } catch (RemoteException re) {
+            }
+            return;
+        }
+
+        UserHandle user;
+        if ((flags&PackageManager.INSTALL_ALL_USERS) != 0) {
+            user = UserHandle.ALL;
+        } else {
+            user = new UserHandle(UserHandle.getUserId(uid));
+        }
+
+        final int filteredFlags;
+
+        if (uid == Process.SHELL_UID || uid == 0) {
+            if (DEBUG_INSTALL) {
+                Slog.v(TAG, "Install from ADB");
+            }
+            filteredFlags = flags | PackageManager.INSTALL_FROM_ADB;
+        } else {
+            filteredFlags = flags & ~PackageManager.INSTALL_FROM_ADB;
+        }
+
+        verificationParams.setInstallerUid(uid);
+
+        final Message msg = mHandler.obtainMessage(INIT_COPY);
+        msg.obj = new InstallParams(packageURI, observer, filteredFlags, installerPackageName,
+                verificationParams, encryptionParams, user);
+        mHandler.sendMessage(msg);
+    }
+
+    private void sendPackageAddedForUser(String packageName, PackageSetting pkgSetting, int userId) {
+        Bundle extras = new Bundle(1);
+        extras.putInt(Intent.EXTRA_UID, UserHandle.getUid(userId, pkgSetting.appId));
+
+        sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
+                packageName, extras, null, null, new int[] {userId});
+        try {
+            IActivityManager am = ActivityManagerNative.getDefault();
+            final boolean isSystem =
+                    isSystemApp(pkgSetting) || isUpdatedSystemApp(pkgSetting);
+            if (isSystem && am.isUserRunning(userId, false)) {
+                // The just-installed/enabled app is bundled on the system, so presumed
+                // to be able to run automatically without needing an explicit launch.
+                // Send it a BOOT_COMPLETED if it would ordinarily have gotten one.
+                Intent bcIntent = new Intent(Intent.ACTION_BOOT_COMPLETED)
+                        .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
+                        .setPackage(packageName);
+                am.broadcastIntent(null, bcIntent, null, null, 0, null, null, null,
+                        android.app.AppOpsManager.OP_NONE, false, false, userId);
+            }
+        } catch (RemoteException e) {
+            // shouldn't happen
+            Slog.w(TAG, "Unable to bootstrap installed package", e);
+        }
+    }
+
+    @Override
+    public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked,
+            int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
+        PackageSetting pkgSetting;
+        final int uid = Binder.getCallingUid();
+        if (UserHandle.getUserId(uid) != userId) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                    "setApplicationBlockedSetting for user " + userId);
+        }
+
+        if (blocked && isPackageDeviceAdmin(packageName, userId)) {
+            Slog.w(TAG, "Not blocking package " + packageName + ": has active device admin");
+            return false;
+        }
+
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            boolean sendAdded = false;
+            boolean sendRemoved = false;
+            // writer
+            synchronized (mPackages) {
+                pkgSetting = mSettings.mPackages.get(packageName);
+                if (pkgSetting == null) {
+                    return false;
+                }
+                if (pkgSetting.getBlocked(userId) != blocked) {
+                    pkgSetting.setBlocked(blocked, userId);
+                    mSettings.writePackageRestrictionsLPr(userId);
+                    if (blocked) {
+                        sendRemoved = true;
+                    } else {
+                        sendAdded = true;
+                    }
+                }
+            }
+            if (sendAdded) {
+                sendPackageAddedForUser(packageName, pkgSetting, userId);
+                return true;
+            }
+            if (sendRemoved) {
+                killApplication(packageName, UserHandle.getUid(userId, pkgSetting.appId),
+                        "blocking pkg");
+                sendPackageBlockedForUser(packageName, pkgSetting, userId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+        return false;
+    }
+
+    private void sendPackageBlockedForUser(String packageName, PackageSetting pkgSetting,
+            int userId) {
+        final PackageRemovedInfo info = new PackageRemovedInfo();
+        info.removedPackage = packageName;
+        info.removedUsers = new int[] {userId};
+        info.uid = UserHandle.getUid(userId, pkgSetting.appId);
+        info.sendBroadcast(false, false, false);
+    }
+
+    /**
+     * Returns true if application is not found or there was an error. Otherwise it returns
+     * the blocked state of the package for the given user.
+     */
+    @Override
+    public boolean getApplicationBlockedSettingAsUser(String packageName, int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
+        PackageSetting pkgSetting;
+        final int uid = Binder.getCallingUid();
+        if (UserHandle.getUserId(uid) != userId) {
+            mContext.enforceCallingPermission(
+                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                    "getApplicationBlocked for user " + userId);
+        }
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            // writer
+            synchronized (mPackages) {
+                pkgSetting = mSettings.mPackages.get(packageName);
+                if (pkgSetting == null) {
+                    return true;
+                }
+                return pkgSetting.getBlocked(userId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+    }
+
+    /**
+     * @hide
+     */
+    @Override
+    public int installExistingPackageAsUser(String packageName, int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.INSTALL_PACKAGES,
+                null);
+        PackageSetting pkgSetting;
+        final int uid = Binder.getCallingUid();
+        if (UserHandle.getUserId(uid) != userId) {
+            mContext.enforceCallingPermission(
+                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                    "installExistingPackage for user " + userId);
+        }
+        if (isUserRestricted(userId, UserManager.DISALLOW_INSTALL_APPS)) {
+            return PackageManager.INSTALL_FAILED_USER_RESTRICTED;
+        }
+
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            boolean sendAdded = false;
+            Bundle extras = new Bundle(1);
+
+            // writer
+            synchronized (mPackages) {
+                pkgSetting = mSettings.mPackages.get(packageName);
+                if (pkgSetting == null) {
+                    return PackageManager.INSTALL_FAILED_INVALID_URI;
+                }
+                if (!pkgSetting.getInstalled(userId)) {
+                    pkgSetting.setInstalled(true, userId);
+                    pkgSetting.setBlocked(false, userId);
+                    mSettings.writePackageRestrictionsLPr(userId);
+                    sendAdded = true;
+                }
+            }
+
+            if (sendAdded) {
+                sendPackageAddedForUser(packageName, pkgSetting, userId);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+
+        return PackageManager.INSTALL_SUCCEEDED;
+    }
+
+    private boolean isUserRestricted(int userId, String restrictionKey) {
+        Bundle restrictions = sUserManager.getUserRestrictions(userId);
+        if (restrictions.getBoolean(restrictionKey, false)) {
+            Log.w(TAG, "User is restricted: " + restrictionKey);
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void verifyPendingInstall(int id, int verificationCode) throws RemoteException {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
+                "Only package verification agents can verify applications");
+
+        final Message msg = mHandler.obtainMessage(PACKAGE_VERIFIED);
+        final PackageVerificationResponse response = new PackageVerificationResponse(
+                verificationCode, Binder.getCallingUid());
+        msg.arg1 = id;
+        msg.obj = response;
+        mHandler.sendMessage(msg);
+    }
+
+    @Override
+    public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
+            long millisecondsToDelay) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
+                "Only package verification agents can extend verification timeouts");
+
+        final PackageVerificationState state = mPendingVerification.get(id);
+        final PackageVerificationResponse response = new PackageVerificationResponse(
+                verificationCodeAtTimeout, Binder.getCallingUid());
+
+        if (millisecondsToDelay > PackageManager.MAXIMUM_VERIFICATION_TIMEOUT) {
+            millisecondsToDelay = PackageManager.MAXIMUM_VERIFICATION_TIMEOUT;
+        }
+        if (millisecondsToDelay < 0) {
+            millisecondsToDelay = 0;
+        }
+        if ((verificationCodeAtTimeout != PackageManager.VERIFICATION_ALLOW)
+                && (verificationCodeAtTimeout != PackageManager.VERIFICATION_REJECT)) {
+            verificationCodeAtTimeout = PackageManager.VERIFICATION_REJECT;
+        }
+
+        if ((state != null) && !state.timeoutExtended()) {
+            state.extendTimeout();
+
+            final Message msg = mHandler.obtainMessage(PACKAGE_VERIFIED);
+            msg.arg1 = id;
+            msg.obj = response;
+            mHandler.sendMessageDelayed(msg, millisecondsToDelay);
+        }
+    }
+
+    private void broadcastPackageVerified(int verificationId, Uri packageUri,
+            int verificationCode, UserHandle user) {
+        final Intent intent = new Intent(Intent.ACTION_PACKAGE_VERIFIED);
+        intent.setDataAndType(packageUri, PACKAGE_MIME_TYPE);
+        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+        intent.putExtra(PackageManager.EXTRA_VERIFICATION_ID, verificationId);
+        intent.putExtra(PackageManager.EXTRA_VERIFICATION_RESULT, verificationCode);
+
+        mContext.sendBroadcastAsUser(intent, user,
+                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT);
+    }
+
+    private ComponentName matchComponentForVerifier(String packageName,
+            List<ResolveInfo> receivers) {
+        ActivityInfo targetReceiver = null;
+
+        final int NR = receivers.size();
+        for (int i = 0; i < NR; i++) {
+            final ResolveInfo info = receivers.get(i);
+            if (info.activityInfo == null) {
+                continue;
+            }
+
+            if (packageName.equals(info.activityInfo.packageName)) {
+                targetReceiver = info.activityInfo;
+                break;
+            }
+        }
+
+        if (targetReceiver == null) {
+            return null;
+        }
+
+        return new ComponentName(targetReceiver.packageName, targetReceiver.name);
+    }
+
+    private List<ComponentName> matchVerifiers(PackageInfoLite pkgInfo,
+            List<ResolveInfo> receivers, final PackageVerificationState verificationState) {
+        if (pkgInfo.verifiers.length == 0) {
+            return null;
+        }
+
+        final int N = pkgInfo.verifiers.length;
+        final List<ComponentName> sufficientVerifiers = new ArrayList<ComponentName>(N + 1);
+        for (int i = 0; i < N; i++) {
+            final VerifierInfo verifierInfo = pkgInfo.verifiers[i];
+
+            final ComponentName comp = matchComponentForVerifier(verifierInfo.packageName,
+                    receivers);
+            if (comp == null) {
+                continue;
+            }
+
+            final int verifierUid = getUidForVerifier(verifierInfo);
+            if (verifierUid == -1) {
+                continue;
+            }
+
+            if (DEBUG_VERIFY) {
+                Slog.d(TAG, "Added sufficient verifier " + verifierInfo.packageName
+                        + " with the correct signature");
+            }
+            sufficientVerifiers.add(comp);
+            verificationState.addSufficientVerifier(verifierUid);
+        }
+
+        return sufficientVerifiers;
+    }
+
+    private int getUidForVerifier(VerifierInfo verifierInfo) {
+        synchronized (mPackages) {
+            final PackageParser.Package pkg = mPackages.get(verifierInfo.packageName);
+            if (pkg == null) {
+                return -1;
+            } else if (pkg.mSignatures.length != 1) {
+                Slog.i(TAG, "Verifier package " + verifierInfo.packageName
+                        + " has more than one signature; ignoring");
+                return -1;
+            }
+
+            /*
+             * If the public key of the package's signature does not match
+             * our expected public key, then this is a different package and
+             * we should skip.
+             */
+
+            final byte[] expectedPublicKey;
+            try {
+                final Signature verifierSig = pkg.mSignatures[0];
+                final PublicKey publicKey = verifierSig.getPublicKey();
+                expectedPublicKey = publicKey.getEncoded();
+            } catch (CertificateException e) {
+                return -1;
+            }
+
+            final byte[] actualPublicKey = verifierInfo.publicKey.getEncoded();
+
+            if (!Arrays.equals(actualPublicKey, expectedPublicKey)) {
+                Slog.i(TAG, "Verifier package " + verifierInfo.packageName
+                        + " does not have the expected public key; ignoring");
+                return -1;
+            }
+
+            return pkg.applicationInfo.uid;
+        }
+    }
+
+    public void finishPackageInstall(int token) {
+        enforceSystemOrRoot("Only the system is allowed to finish installs");
+
+        if (DEBUG_INSTALL) {
+            Slog.v(TAG, "BM finishing package install for " + token);
+        }
+
+        final Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0);
+        mHandler.sendMessage(msg);
+    }
+
+    /**
+     * Get the verification agent timeout.
+     *
+     * @return verification timeout in milliseconds
+     */
+    private long getVerificationTimeout() {
+        return android.provider.Settings.Global.getLong(mContext.getContentResolver(),
+                android.provider.Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
+                DEFAULT_VERIFICATION_TIMEOUT);
+    }
+
+    /**
+     * Get the default verification agent response code.
+     *
+     * @return default verification response code
+     */
+    private int getDefaultVerificationResponse() {
+        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
+                android.provider.Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE,
+                DEFAULT_VERIFICATION_RESPONSE);
+    }
+
+    /**
+     * Check whether or not package verification has been enabled.
+     *
+     * @return true if verification should be performed
+     */
+    private boolean isVerificationEnabled(int flags) {
+        if (!DEFAULT_VERIFY_ENABLE) {
+            return false;
+        }
+
+        // Check if installing from ADB
+        if ((flags & PackageManager.INSTALL_FROM_ADB) != 0) {
+            // Do not run verification in a test harness environment
+            if (ActivityManager.isRunningInTestHarness()) {
+                return false;
+            }
+            // Check if the developer does not want package verification for ADB installs
+            if (android.provider.Settings.Global.getInt(mContext.getContentResolver(),
+                    android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) == 0) {
+                return false;
+            }
+        }
+
+        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
+                android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 1;
+    }
+
+    /**
+     * Get the "allow unknown sources" setting.
+     *
+     * @return the current "allow unknown sources" setting
+     */
+    private int getUnknownSourcesSettings() {
+        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
+                android.provider.Settings.Global.INSTALL_NON_MARKET_APPS,
+                -1);
+    }
+
+    public void setInstallerPackageName(String targetPackage, String installerPackageName) {
+        final int uid = Binder.getCallingUid();
+        // writer
+        synchronized (mPackages) {
+            PackageSetting targetPackageSetting = mSettings.mPackages.get(targetPackage);
+            if (targetPackageSetting == null) {
+                throw new IllegalArgumentException("Unknown target package: " + targetPackage);
+            }
+
+            PackageSetting installerPackageSetting;
+            if (installerPackageName != null) {
+                installerPackageSetting = mSettings.mPackages.get(installerPackageName);
+                if (installerPackageSetting == null) {
+                    throw new IllegalArgumentException("Unknown installer package: "
+                            + installerPackageName);
+                }
+            } else {
+                installerPackageSetting = null;
+            }
+
+            Signature[] callerSignature;
+            Object obj = mSettings.getUserIdLPr(uid);
+            if (obj != null) {
+                if (obj instanceof SharedUserSetting) {
+                    callerSignature = ((SharedUserSetting)obj).signatures.mSignatures;
+                } else if (obj instanceof PackageSetting) {
+                    callerSignature = ((PackageSetting)obj).signatures.mSignatures;
+                } else {
+                    throw new SecurityException("Bad object " + obj + " for uid " + uid);
+                }
+            } else {
+                throw new SecurityException("Unknown calling uid " + uid);
+            }
+
+            // Verify: can't set installerPackageName to a package that is
+            // not signed with the same cert as the caller.
+            if (installerPackageSetting != null) {
+                if (compareSignatures(callerSignature,
+                        installerPackageSetting.signatures.mSignatures)
+                        != PackageManager.SIGNATURE_MATCH) {
+                    throw new SecurityException(
+                            "Caller does not have same cert as new installer package "
+                            + installerPackageName);
+                }
+            }
+
+            // Verify: if target already has an installer package, it must
+            // be signed with the same cert as the caller.
+            if (targetPackageSetting.installerPackageName != null) {
+                PackageSetting setting = mSettings.mPackages.get(
+                        targetPackageSetting.installerPackageName);
+                // If the currently set package isn't valid, then it's always
+                // okay to change it.
+                if (setting != null) {
+                    if (compareSignatures(callerSignature,
+                            setting.signatures.mSignatures)
+                            != PackageManager.SIGNATURE_MATCH) {
+                        throw new SecurityException(
+                                "Caller does not have same cert as old installer package "
+                                + targetPackageSetting.installerPackageName);
+                    }
+                }
+            }
+
+            // Okay!
+            targetPackageSetting.installerPackageName = installerPackageName;
+            scheduleWriteSettingsLocked();
+        }
+    }
+
+    private void processPendingInstall(final InstallArgs args, final int currentStatus) {
+        // Queue up an async operation since the package installation may take a little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                mHandler.removeCallbacks(this);
+                 // Result object to be returned
+                PackageInstalledInfo res = new PackageInstalledInfo();
+                res.returnCode = currentStatus;
+                res.uid = -1;
+                res.pkg = null;
+                res.removedInfo = new PackageRemovedInfo();
+                if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
+                    args.doPreInstall(res.returnCode);
+                    synchronized (mInstallLock) {
+                        installPackageLI(args, true, res);
+                    }
+                    args.doPostInstall(res.returnCode, res.uid);
+                }
+
+                // A restore should be performed at this point if (a) the install
+                // succeeded, (b) the operation is not an update, and (c) the new
+                // package has a backupAgent defined.
+                final boolean update = res.removedInfo.removedPackage != null;
+                boolean doRestore = (!update
+                        && res.pkg != null
+                        && res.pkg.applicationInfo.backupAgentName != null);
+
+                // Set up the post-install work request bookkeeping.  This will be used
+                // and cleaned up by the post-install event handling regardless of whether
+                // there's a restore pass performed.  Token values are >= 1.
+                int token;
+                if (mNextInstallToken < 0) mNextInstallToken = 1;
+                token = mNextInstallToken++;
+
+                PostInstallData data = new PostInstallData(args, res);
+                mRunningInstalls.put(token, data);
+                if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token);
+
+                if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && doRestore) {
+                    // Pass responsibility to the Backup Manager.  It will perform a
+                    // restore if appropriate, then pass responsibility back to the
+                    // Package Manager to run the post-install observer callbacks
+                    // and broadcasts.
+                    IBackupManager bm = IBackupManager.Stub.asInterface(
+                            ServiceManager.getService(Context.BACKUP_SERVICE));
+                    if (bm != null) {
+                        if (DEBUG_INSTALL) Log.v(TAG, "token " + token
+                                + " to BM for possible restore");
+                        try {
+                            bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token);
+                        } catch (RemoteException e) {
+                            // can't happen; the backup manager is local
+                        } catch (Exception e) {
+                            Slog.e(TAG, "Exception trying to enqueue restore", e);
+                            doRestore = false;
+                        }
+                    } else {
+                        Slog.e(TAG, "Backup Manager not found!");
+                        doRestore = false;
+                    }
+                }
+
+                if (!doRestore) {
+                    // No restore possible, or the Backup Manager was mysteriously not
+                    // available -- just fire the post-install work request directly.
+                    if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token);
+                    Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0);
+                    mHandler.sendMessage(msg);
+                }
+            }
+        });
+    }
+
+    private abstract class HandlerParams {
+        private static final int MAX_RETRIES = 4;
+
+        /**
+         * Number of times startCopy() has been attempted and had a non-fatal
+         * error.
+         */
+        private int mRetries = 0;
+
+        /** User handle for the user requesting the information or installation. */
+        private final UserHandle mUser;
+
+        HandlerParams(UserHandle user) {
+            mUser = user;
+        }
+
+        UserHandle getUser() {
+            return mUser;
+        }
+
+        final boolean startCopy() {
+            boolean res;
+            try {
+                if (DEBUG_INSTALL) Slog.i(TAG, "startCopy " + mUser + ": " + this);
+
+                if (++mRetries > MAX_RETRIES) {
+                    Slog.w(TAG, "Failed to invoke remote methods on default container service. Giving up");
+                    mHandler.sendEmptyMessage(MCS_GIVE_UP);
+                    handleServiceError();
+                    return false;
+                } else {
+                    handleStartCopy();
+                    res = true;
+                }
+            } catch (RemoteException e) {
+                if (DEBUG_INSTALL) Slog.i(TAG, "Posting install MCS_RECONNECT");
+                mHandler.sendEmptyMessage(MCS_RECONNECT);
+                res = false;
+            }
+            handleReturnCode();
+            return res;
+        }
+
+        final void serviceError() {
+            if (DEBUG_INSTALL) Slog.i(TAG, "serviceError");
+            handleServiceError();
+            handleReturnCode();
+        }
+
+        abstract void handleStartCopy() throws RemoteException;
+        abstract void handleServiceError();
+        abstract void handleReturnCode();
+    }
+
+    class MeasureParams extends HandlerParams {
+        private final PackageStats mStats;
+        private boolean mSuccess;
+
+        private final IPackageStatsObserver mObserver;
+
+        public MeasureParams(PackageStats stats, IPackageStatsObserver observer) {
+            super(new UserHandle(stats.userHandle));
+            mObserver = observer;
+            mStats = stats;
+        }
+
+        @Override
+        public String toString() {
+            return "MeasureParams{"
+                + Integer.toHexString(System.identityHashCode(this))
+                + " " + mStats.packageName + "}";
+        }
+
+        @Override
+        void handleStartCopy() throws RemoteException {
+            synchronized (mInstallLock) {
+                mSuccess = getPackageSizeInfoLI(mStats.packageName, mStats.userHandle, mStats);
+            }
+
+            final boolean mounted;
+            if (Environment.isExternalStorageEmulated()) {
+                mounted = true;
+            } else {
+                final String status = Environment.getExternalStorageState();
+                mounted = (Environment.MEDIA_MOUNTED.equals(status)
+                        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(status));
+            }
+
+            if (mounted) {
+                final UserEnvironment userEnv = new UserEnvironment(mStats.userHandle);
+
+                mStats.externalCacheSize = calculateDirectorySize(mContainerService,
+                        userEnv.buildExternalStorageAppCacheDirs(mStats.packageName));
+
+                mStats.externalDataSize = calculateDirectorySize(mContainerService,
+                        userEnv.buildExternalStorageAppDataDirs(mStats.packageName));
+
+                // Always subtract cache size, since it's a subdirectory
+                mStats.externalDataSize -= mStats.externalCacheSize;
+
+                mStats.externalMediaSize = calculateDirectorySize(mContainerService,
+                        userEnv.buildExternalStorageAppMediaDirs(mStats.packageName));
+
+                mStats.externalObbSize = calculateDirectorySize(mContainerService,
+                        userEnv.buildExternalStorageAppObbDirs(mStats.packageName));
+            }
+        }
+
+        @Override
+        void handleReturnCode() {
+            if (mObserver != null) {
+                try {
+                    mObserver.onGetStatsCompleted(mStats, mSuccess);
+                } catch (RemoteException e) {
+                    Slog.i(TAG, "Observer no longer exists.");
+                }
+            }
+        }
+
+        @Override
+        void handleServiceError() {
+            Slog.e(TAG, "Could not measure application " + mStats.packageName
+                            + " external storage");
+        }
+    }
+
+    private static long calculateDirectorySize(IMediaContainerService mcs, File[] paths)
+            throws RemoteException {
+        long result = 0;
+        for (File path : paths) {
+            result += mcs.calculateDirectorySize(path.getAbsolutePath());
+        }
+        return result;
+    }
+
+    private static void clearDirectory(IMediaContainerService mcs, File[] paths) {
+        for (File path : paths) {
+            try {
+                mcs.clearDirectory(path.getAbsolutePath());
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    class InstallParams extends HandlerParams {
+        final IPackageInstallObserver observer;
+        int flags;
+
+        private final Uri mPackageURI;
+        final String installerPackageName;
+        final VerificationParams verificationParams;
+        private InstallArgs mArgs;
+        private int mRet;
+        private File mTempPackage;
+        final ContainerEncryptionParams encryptionParams;
+
+        InstallParams(Uri packageURI,
+                IPackageInstallObserver observer, int flags,
+                String installerPackageName, VerificationParams verificationParams,
+                ContainerEncryptionParams encryptionParams, UserHandle user) {
+            super(user);
+            this.mPackageURI = packageURI;
+            this.flags = flags;
+            this.observer = observer;
+            this.installerPackageName = installerPackageName;
+            this.verificationParams = verificationParams;
+            this.encryptionParams = encryptionParams;
+        }
+
+        @Override
+        public String toString() {
+            return "InstallParams{"
+                + Integer.toHexString(System.identityHashCode(this))
+                + " " + mPackageURI + "}";
+        }
+
+        public ManifestDigest getManifestDigest() {
+            if (verificationParams == null) {
+                return null;
+            }
+            return verificationParams.getManifestDigest();
+        }
+
+        private int installLocationPolicy(PackageInfoLite pkgLite, int flags) {
+            String packageName = pkgLite.packageName;
+            int installLocation = pkgLite.installLocation;
+            boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0;
+            // reader
+            synchronized (mPackages) {
+                PackageParser.Package pkg = mPackages.get(packageName);
+                if (pkg != null) {
+                    if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
+                        // Check for downgrading.
+                        if ((flags & PackageManager.INSTALL_ALLOW_DOWNGRADE) == 0) {
+                            if (pkgLite.versionCode < pkg.mVersionCode) {
+                                Slog.w(TAG, "Can't install update of " + packageName
+                                        + " update version " + pkgLite.versionCode
+                                        + " is older than installed version "
+                                        + pkg.mVersionCode);
+                                return PackageHelper.RECOMMEND_FAILED_VERSION_DOWNGRADE;
+                            }
+                        }
+                        // Check for updated system application.
+                        if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                            if (onSd) {
+                                Slog.w(TAG, "Cannot install update to system app on sdcard");
+                                return PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION;
+                            }
+                            return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
+                        } else {
+                            if (onSd) {
+                                // Install flag overrides everything.
+                                return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
+                            }
+                            // If current upgrade specifies particular preference
+                            if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
+                                // Application explicitly specified internal.
+                                return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
+                            } else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
+                                // App explictly prefers external. Let policy decide
+                            } else {
+                                // Prefer previous location
+                                if (isExternal(pkg)) {
+                                    return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
+                                }
+                                return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
+                            }
+                        }
+                    } else {
+                        // Invalid install. Return error code
+                        return PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS;
+                    }
+                }
+            }
+            // All the special cases have been taken care of.
+            // Return result based on recommended install location.
+            if (onSd) {
+                return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
+            }
+            return pkgLite.recommendedInstallLocation;
+        }
+
+        private long getMemoryLowThreshold() {
+            final DeviceStorageMonitorInternal
+                    dsm = LocalServices.getService(DeviceStorageMonitorInternal.class);
+            if (dsm == null) {
+                return 0L;
+            }
+            return dsm.getMemoryLowThreshold();
+        }
+
+        /*
+         * Invoke remote method to get package information and install
+         * location values. Override install location based on default
+         * policy if needed and then create install arguments based
+         * on the install location.
+         */
+        public void handleStartCopy() throws RemoteException {
+            int ret = PackageManager.INSTALL_SUCCEEDED;
+            final boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0;
+            final boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0;
+            PackageInfoLite pkgLite = null;
+
+            if (onInt && onSd) {
+                // Check if both bits are set.
+                Slog.w(TAG, "Conflicting flags specified for installing on both internal and external");
+                ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
+            } else {
+                final long lowThreshold = getMemoryLowThreshold();
+                if (lowThreshold == 0L) {
+                    Log.w(TAG, "Couldn't get low memory threshold; no free limit imposed");
+                }
+
+                try {
+                    mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, mPackageURI,
+                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
+
+                    final File packageFile;
+                    if (encryptionParams != null || !"file".equals(mPackageURI.getScheme())) {
+                        mTempPackage = createTempPackageFile(mDrmAppPrivateInstallDir);
+                        if (mTempPackage != null) {
+                            ParcelFileDescriptor out;
+                            try {
+                                out = ParcelFileDescriptor.open(mTempPackage,
+                                        ParcelFileDescriptor.MODE_READ_WRITE);
+                            } catch (FileNotFoundException e) {
+                                out = null;
+                                Slog.e(TAG, "Failed to create temporary file for : " + mPackageURI);
+                            }
+
+                            // Make a temporary file for decryption.
+                            ret = mContainerService
+                                    .copyResource(mPackageURI, encryptionParams, out);
+                            IoUtils.closeQuietly(out);
+
+                            packageFile = mTempPackage;
+
+                            FileUtils.setPermissions(packageFile.getAbsolutePath(),
+                                    FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP
+                                            | FileUtils.S_IROTH,
+                                    -1, -1);
+                        } else {
+                            packageFile = null;
+                        }
+                    } else {
+                        packageFile = new File(mPackageURI.getPath());
+                    }
+
+                    if (packageFile != null) {
+                        // Remote call to find out default install location
+                        final String packageFilePath = packageFile.getAbsolutePath();
+                        pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath, flags,
+                                lowThreshold);
+
+                        /*
+                         * If we have too little free space, try to free cache
+                         * before giving up.
+                         */
+                        if (pkgLite.recommendedInstallLocation
+                                == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE) {
+                            final long size = mContainerService.calculateInstalledSize(
+                                    packageFilePath, isForwardLocked());
+                            if (mInstaller.freeCache(size + lowThreshold) >= 0) {
+                                pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath,
+                                        flags, lowThreshold);
+                            }
+                            /*
+                             * The cache free must have deleted the file we
+                             * downloaded to install.
+                             *
+                             * TODO: fix the "freeCache" call to not delete
+                             *       the file we care about.
+                             */
+                            if (pkgLite.recommendedInstallLocation
+                                    == PackageHelper.RECOMMEND_FAILED_INVALID_URI) {
+                                pkgLite.recommendedInstallLocation
+                                    = PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
+                            }
+                        }
+                    }
+                } finally {
+                    mContext.revokeUriPermission(mPackageURI,
+                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                }
+            }
+
+            if (ret == PackageManager.INSTALL_SUCCEEDED) {
+                int loc = pkgLite.recommendedInstallLocation;
+                if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION) {
+                    ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
+                } else if (loc == PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS) {
+                    ret = PackageManager.INSTALL_FAILED_ALREADY_EXISTS;
+                } else if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE) {
+                    ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) {
+                    ret = PackageManager.INSTALL_FAILED_INVALID_APK;
+                } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_URI) {
+                    ret = PackageManager.INSTALL_FAILED_INVALID_URI;
+                } else if (loc == PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE) {
+                    ret = PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE;
+                } else {
+                    // Override with defaults if needed.
+                    loc = installLocationPolicy(pkgLite, flags);
+                    if (loc == PackageHelper.RECOMMEND_FAILED_VERSION_DOWNGRADE) {
+                        ret = PackageManager.INSTALL_FAILED_VERSION_DOWNGRADE;
+                    } else if (!onSd && !onInt) {
+                        // Override install location with flags
+                        if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) {
+                            // Set the flag to install on external media.
+                            flags |= PackageManager.INSTALL_EXTERNAL;
+                            flags &= ~PackageManager.INSTALL_INTERNAL;
+                        } else {
+                            // Make sure the flag for installing on external
+                            // media is unset
+                            flags |= PackageManager.INSTALL_INTERNAL;
+                            flags &= ~PackageManager.INSTALL_EXTERNAL;
+                        }
+                    }
+                }
+            }
+
+            final InstallArgs args = createInstallArgs(this);
+            mArgs = args;
+
+            if (ret == PackageManager.INSTALL_SUCCEEDED) {
+                 /*
+                 * ADB installs appear as UserHandle.USER_ALL, and can only be performed by
+                 * UserHandle.USER_OWNER, so use the package verifier for UserHandle.USER_OWNER.
+                 */
+                int userIdentifier = getUser().getIdentifier();
+                if (userIdentifier == UserHandle.USER_ALL
+                        && ((flags & PackageManager.INSTALL_FROM_ADB) != 0)) {
+                    userIdentifier = UserHandle.USER_OWNER;
+                }
+
+                /*
+                 * Determine if we have any installed package verifiers. If we
+                 * do, then we'll defer to them to verify the packages.
+                 */
+                final int requiredUid = mRequiredVerifierPackage == null ? -1
+                        : getPackageUid(mRequiredVerifierPackage, userIdentifier);
+                if (requiredUid != -1 && isVerificationEnabled(flags)) {
+                    final Intent verification = new Intent(
+                            Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
+                    verification.setDataAndType(getPackageUri(), PACKAGE_MIME_TYPE);
+                    verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+
+                    final List<ResolveInfo> receivers = queryIntentReceivers(verification,
+                            PACKAGE_MIME_TYPE, PackageManager.GET_DISABLED_COMPONENTS,
+                            0 /* TODO: Which userId? */);
+
+                    if (DEBUG_VERIFY) {
+                        Slog.d(TAG, "Found " + receivers.size() + " verifiers for intent "
+                                + verification.toString() + " with " + pkgLite.verifiers.length
+                                + " optional verifiers");
+                    }
+
+                    final int verificationId = mPendingVerificationToken++;
+
+                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_ID, verificationId);
+
+                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALLER_PACKAGE,
+                            installerPackageName);
+
+                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALL_FLAGS, flags);
+
+                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_PACKAGE_NAME,
+                            pkgLite.packageName);
+
+                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_VERSION_CODE,
+                            pkgLite.versionCode);
+
+                    if (verificationParams != null) {
+                        if (verificationParams.getVerificationURI() != null) {
+                           verification.putExtra(PackageManager.EXTRA_VERIFICATION_URI,
+                                 verificationParams.getVerificationURI());
+                        }
+                        if (verificationParams.getOriginatingURI() != null) {
+                            verification.putExtra(Intent.EXTRA_ORIGINATING_URI,
+                                  verificationParams.getOriginatingURI());
+                        }
+                        if (verificationParams.getReferrer() != null) {
+                            verification.putExtra(Intent.EXTRA_REFERRER,
+                                  verificationParams.getReferrer());
+                        }
+                        if (verificationParams.getOriginatingUid() >= 0) {
+                            verification.putExtra(Intent.EXTRA_ORIGINATING_UID,
+                                  verificationParams.getOriginatingUid());
+                        }
+                        if (verificationParams.getInstallerUid() >= 0) {
+                            verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALLER_UID,
+                                  verificationParams.getInstallerUid());
+                        }
+                    }
+
+                    final PackageVerificationState verificationState = new PackageVerificationState(
+                            requiredUid, args);
+
+                    mPendingVerification.append(verificationId, verificationState);
+
+                    final List<ComponentName> sufficientVerifiers = matchVerifiers(pkgLite,
+                            receivers, verificationState);
+
+                    /*
+                     * If any sufficient verifiers were listed in the package
+                     * manifest, attempt to ask them.
+                     */
+                    if (sufficientVerifiers != null) {
+                        final int N = sufficientVerifiers.size();
+                        if (N == 0) {
+                            Slog.i(TAG, "Additional verifiers required, but none installed.");
+                            ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
+                        } else {
+                            for (int i = 0; i < N; i++) {
+                                final ComponentName verifierComponent = sufficientVerifiers.get(i);
+
+                                final Intent sufficientIntent = new Intent(verification);
+                                sufficientIntent.setComponent(verifierComponent);
+
+                                mContext.sendBroadcastAsUser(sufficientIntent, getUser());
+                            }
+                        }
+                    }
+
+                    final ComponentName requiredVerifierComponent = matchComponentForVerifier(
+                            mRequiredVerifierPackage, receivers);
+                    if (ret == PackageManager.INSTALL_SUCCEEDED
+                            && mRequiredVerifierPackage != null) {
+                        /*
+                         * Send the intent to the required verification agent,
+                         * but only start the verification timeout after the
+                         * target BroadcastReceivers have run.
+                         */
+                        verification.setComponent(requiredVerifierComponent);
+                        mContext.sendOrderedBroadcastAsUser(verification, getUser(),
+                                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
+                                new BroadcastReceiver() {
+                                    @Override
+                                    public void onReceive(Context context, Intent intent) {
+                                        final Message msg = mHandler
+                                                .obtainMessage(CHECK_PENDING_VERIFICATION);
+                                        msg.arg1 = verificationId;
+                                        mHandler.sendMessageDelayed(msg, getVerificationTimeout());
+                                    }
+                                }, null, 0, null, null);
+
+                        /*
+                         * We don't want the copy to proceed until verification
+                         * succeeds, so null out this field.
+                         */
+                        mArgs = null;
+                    }
+                } else {
+                    /*
+                     * No package verification is enabled, so immediately start
+                     * the remote call to initiate copy using temporary file.
+                     */
+                    ret = args.copyApk(mContainerService, true);
+                }
+            }
+
+            mRet = ret;
+        }
+
+        @Override
+        void handleReturnCode() {
+            // If mArgs is null, then MCS couldn't be reached. When it
+            // reconnects, it will try again to install. At that point, this
+            // will succeed.
+            if (mArgs != null) {
+                processPendingInstall(mArgs, mRet);
+
+                if (mTempPackage != null) {
+                    if (!mTempPackage.delete()) {
+                        Slog.w(TAG, "Couldn't delete temporary file: " +
+                                mTempPackage.getAbsolutePath());
+                    }
+                }
+            }
+        }
+
+        @Override
+        void handleServiceError() {
+            mArgs = createInstallArgs(this);
+            mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+        }
+
+        public boolean isForwardLocked() {
+            return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
+        }
+
+        public Uri getPackageUri() {
+            if (mTempPackage != null) {
+                return Uri.fromFile(mTempPackage);
+            } else {
+                return mPackageURI;
+            }
+        }
+    }
+
+    /*
+     * Utility class used in movePackage api.
+     * srcArgs and targetArgs are not set for invalid flags and make
+     * sure to do null checks when invoking methods on them.
+     * We probably want to return ErrorPrams for both failed installs
+     * and moves.
+     */
+    class MoveParams extends HandlerParams {
+        final IPackageMoveObserver observer;
+        final int flags;
+        final String packageName;
+        final InstallArgs srcArgs;
+        final InstallArgs targetArgs;
+        int uid;
+        int mRet;
+
+        MoveParams(InstallArgs srcArgs, IPackageMoveObserver observer, int flags,
+                String packageName, String dataDir, int uid, UserHandle user) {
+            super(user);
+            this.srcArgs = srcArgs;
+            this.observer = observer;
+            this.flags = flags;
+            this.packageName = packageName;
+            this.uid = uid;
+            if (srcArgs != null) {
+                Uri packageUri = Uri.fromFile(new File(srcArgs.getCodePath()));
+                targetArgs = createInstallArgs(packageUri, flags, packageName, dataDir);
+            } else {
+                targetArgs = null;
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "MoveParams{"
+                + Integer.toHexString(System.identityHashCode(this))
+                + " " + packageName + "}";
+        }
+
+        public void handleStartCopy() throws RemoteException {
+            mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+            // Check for storage space on target medium
+            if (!targetArgs.checkFreeStorage(mContainerService)) {
+                Log.w(TAG, "Insufficient storage to install");
+                return;
+            }
+
+            mRet = srcArgs.doPreCopy();
+            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
+                return;
+            }
+
+            mRet = targetArgs.copyApk(mContainerService, false);
+            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
+                srcArgs.doPostCopy(uid);
+                return;
+            }
+
+            mRet = srcArgs.doPostCopy(uid);
+            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
+                return;
+            }
+
+            mRet = targetArgs.doPreInstall(mRet);
+            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
+                return;
+            }
+
+            if (DEBUG_SD_INSTALL) {
+                StringBuilder builder = new StringBuilder();
+                if (srcArgs != null) {
+                    builder.append("src: ");
+                    builder.append(srcArgs.getCodePath());
+                }
+                if (targetArgs != null) {
+                    builder.append(" target : ");
+                    builder.append(targetArgs.getCodePath());
+                }
+                Log.i(TAG, builder.toString());
+            }
+        }
+
+        @Override
+        void handleReturnCode() {
+            targetArgs.doPostInstall(mRet, uid);
+            int currentStatus = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
+            if (mRet == PackageManager.INSTALL_SUCCEEDED) {
+                currentStatus = PackageManager.MOVE_SUCCEEDED;
+            } else if (mRet == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){
+                currentStatus = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
+            }
+            processPendingMove(this, currentStatus);
+        }
+
+        @Override
+        void handleServiceError() {
+            mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+        }
+    }
+
+    /**
+     * Used during creation of InstallArgs
+     *
+     * @param flags package installation flags
+     * @return true if should be installed on external storage
+     */
+    private static boolean installOnSd(int flags) {
+        if ((flags & PackageManager.INSTALL_INTERNAL) != 0) {
+            return false;
+        }
+        if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Used during creation of InstallArgs
+     *
+     * @param flags package installation flags
+     * @return true if should be installed as forward locked
+     */
+    private static boolean installForwardLocked(int flags) {
+        return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
+    }
+
+    private InstallArgs createInstallArgs(InstallParams params) {
+        if (installOnSd(params.flags) || params.isForwardLocked()) {
+            return new AsecInstallArgs(params);
+        } else {
+            return new FileInstallArgs(params);
+        }
+    }
+
+    private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath,
+            String nativeLibraryPath) {
+        final boolean isInAsec;
+        if (installOnSd(flags)) {
+            /* Apps on SD card are always in ASEC containers. */
+            isInAsec = true;
+        } else if (installForwardLocked(flags)
+                && !fullCodePath.startsWith(mDrmAppPrivateInstallDir.getAbsolutePath())) {
+            /*
+             * Forward-locked apps are only in ASEC containers if they're the
+             * new style
+             */
+            isInAsec = true;
+        } else {
+            isInAsec = false;
+        }
+
+        if (isInAsec) {
+            return new AsecInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath,
+                    installOnSd(flags), installForwardLocked(flags));
+        } else {
+            return new FileInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath);
+        }
+    }
+
+    // Used by package mover
+    private InstallArgs createInstallArgs(Uri packageURI, int flags, String pkgName, String dataDir) {
+        if (installOnSd(flags) || installForwardLocked(flags)) {
+            String cid = getNextCodePath(packageURI.getPath(), pkgName, "/"
+                    + AsecInstallArgs.RES_FILE_NAME);
+            return new AsecInstallArgs(packageURI, cid, installOnSd(flags),
+                    installForwardLocked(flags));
+        } else {
+            return new FileInstallArgs(packageURI, pkgName, dataDir);
+        }
+    }
+
+    static abstract class InstallArgs {
+        final IPackageInstallObserver observer;
+        // Always refers to PackageManager flags only
+        final int flags;
+        final Uri packageURI;
+        final String installerPackageName;
+        final ManifestDigest manifestDigest;
+        final UserHandle user;
+
+        InstallArgs(Uri packageURI, IPackageInstallObserver observer, int flags,
+                String installerPackageName, ManifestDigest manifestDigest,
+                UserHandle user) {
+            this.packageURI = packageURI;
+            this.flags = flags;
+            this.observer = observer;
+            this.installerPackageName = installerPackageName;
+            this.manifestDigest = manifestDigest;
+            this.user = user;
+        }
+
+        abstract void createCopyFile();
+        abstract int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException;
+        abstract int doPreInstall(int status);
+        abstract boolean doRename(int status, String pkgName, String oldCodePath);
+
+        abstract int doPostInstall(int status, int uid);
+        abstract String getCodePath();
+        abstract String getResourcePath();
+        abstract String getNativeLibraryPath();
+        // Need installer lock especially for dex file removal.
+        abstract void cleanUpResourcesLI();
+        abstract boolean doPostDeleteLI(boolean delete);
+        abstract boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException;
+
+        /**
+         * Called before the source arguments are copied. This is used mostly
+         * for MoveParams when it needs to read the source file to put it in the
+         * destination.
+         */
+        int doPreCopy() {
+            return PackageManager.INSTALL_SUCCEEDED;
+        }
+
+        /**
+         * Called after the source arguments are copied. This is used mostly for
+         * MoveParams when it needs to read the source file to put it in the
+         * destination.
+         *
+         * @return
+         */
+        int doPostCopy(int uid) {
+            return PackageManager.INSTALL_SUCCEEDED;
+        }
+
+        protected boolean isFwdLocked() {
+            return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
+        }
+
+        UserHandle getUser() {
+            return user;
+        }
+    }
+
+    class FileInstallArgs extends InstallArgs {
+        File installDir;
+        String codeFileName;
+        String resourceFileName;
+        String libraryPath;
+        boolean created = false;
+
+        FileInstallArgs(InstallParams params) {
+            super(params.getPackageUri(), params.observer, params.flags,
+                    params.installerPackageName, params.getManifestDigest(),
+                    params.getUser());
+        }
+
+        FileInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath) {
+            super(null, null, 0, null, null, null);
+            File codeFile = new File(fullCodePath);
+            installDir = codeFile.getParentFile();
+            codeFileName = fullCodePath;
+            resourceFileName = fullResourcePath;
+            libraryPath = nativeLibraryPath;
+        }
+
+        FileInstallArgs(Uri packageURI, String pkgName, String dataDir) {
+            super(packageURI, null, 0, null, null, null);
+            installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir;
+            String apkName = getNextCodePath(null, pkgName, ".apk");
+            codeFileName = new File(installDir, apkName + ".apk").getPath();
+            resourceFileName = getResourcePathFromCodePath();
+            libraryPath = new File(mAppLibInstallDir, pkgName).getPath();
+        }
+
+        boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException {
+            final long lowThreshold;
+
+            final DeviceStorageMonitorInternal
+                    dsm = LocalServices.getService(DeviceStorageMonitorInternal.class);
+            if (dsm == null) {
+                Log.w(TAG, "Couldn't get low memory threshold; no free limit imposed");
+                lowThreshold = 0L;
+            } else {
+                if (dsm.isMemoryLow()) {
+                    Log.w(TAG, "Memory is reported as being too low; aborting package install");
+                    return false;
+                }
+
+                lowThreshold = dsm.getMemoryLowThreshold();
+            }
+
+            try {
+                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
+                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                return imcs.checkInternalFreeStorage(packageURI, isFwdLocked(), lowThreshold);
+            } finally {
+                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            }
+        }
+
+        String getCodePath() {
+            return codeFileName;
+        }
+
+        void createCopyFile() {
+            installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir;
+            codeFileName = createTempPackageFile(installDir).getPath();
+            resourceFileName = getResourcePathFromCodePath();
+            libraryPath = getLibraryPathFromCodePath();
+            created = true;
+        }
+
+        int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException {
+            if (temp) {
+                // Generate temp file name
+                createCopyFile();
+            }
+            // Get a ParcelFileDescriptor to write to the output file
+            File codeFile = new File(codeFileName);
+            if (!created) {
+                try {
+                    codeFile.createNewFile();
+                    // Set permissions
+                    if (!setPermissions()) {
+                        // Failed setting permissions.
+                        return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                    }
+                } catch (IOException e) {
+                   Slog.w(TAG, "Failed to create file " + codeFile);
+                   return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                }
+            }
+            ParcelFileDescriptor out = null;
+            try {
+                out = ParcelFileDescriptor.open(codeFile, ParcelFileDescriptor.MODE_READ_WRITE);
+            } catch (FileNotFoundException e) {
+                Slog.e(TAG, "Failed to create file descriptor for : " + codeFileName);
+                return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+            }
+            // Copy the resource now
+            int ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+            try {
+                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
+                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                ret = imcs.copyResource(packageURI, null, out);
+            } finally {
+                IoUtils.closeQuietly(out);
+                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            }
+
+            if (isFwdLocked()) {
+                final File destResourceFile = new File(getResourcePath());
+
+                // Copy the public files
+                try {
+                    PackageHelper.extractPublicFiles(codeFileName, destResourceFile);
+                } catch (IOException e) {
+                    Slog.e(TAG, "Couldn't create a new zip file for the public parts of a"
+                            + " forward-locked app.");
+                    destResourceFile.delete();
+                    return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                }
+            }
+
+            final File nativeLibraryFile = new File(getNativeLibraryPath());
+            Slog.i(TAG, "Copying native libraries to " + nativeLibraryFile.getPath());
+            if (nativeLibraryFile.exists()) {
+                NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryFile);
+                nativeLibraryFile.delete();
+            }
+            try {
+                int copyRet = copyNativeLibrariesForInternalApp(codeFile, nativeLibraryFile);
+                if (copyRet != PackageManager.INSTALL_SUCCEEDED) {
+                    return copyRet;
+                }
+            } catch (IOException e) {
+                Slog.e(TAG, "Copying native libraries failed", e);
+                ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+            }
+
+            return ret;
+        }
+
+        int doPreInstall(int status) {
+            if (status != PackageManager.INSTALL_SUCCEEDED) {
+                cleanUp();
+            }
+            return status;
+        }
+
+        boolean doRename(int status, final String pkgName, String oldCodePath) {
+            if (status != PackageManager.INSTALL_SUCCEEDED) {
+                cleanUp();
+                return false;
+            } else {
+                final File oldCodeFile = new File(getCodePath());
+                final File oldResourceFile = new File(getResourcePath());
+                final File oldLibraryFile = new File(getNativeLibraryPath());
+
+                // Rename APK file based on packageName
+                final String apkName = getNextCodePath(oldCodePath, pkgName, ".apk");
+                final File newCodeFile = new File(installDir, apkName + ".apk");
+                if (!oldCodeFile.renameTo(newCodeFile)) {
+                    return false;
+                }
+                codeFileName = newCodeFile.getPath();
+
+                // Rename public resource file if it's forward-locked.
+                final File newResFile = new File(getResourcePathFromCodePath());
+                if (isFwdLocked() && !oldResourceFile.renameTo(newResFile)) {
+                    return false;
+                }
+                resourceFileName = newResFile.getPath();
+
+                // Rename library path
+                final File newLibraryFile = new File(getLibraryPathFromCodePath());
+                if (newLibraryFile.exists()) {
+                    NativeLibraryHelper.removeNativeBinariesFromDirLI(newLibraryFile);
+                    newLibraryFile.delete();
+                }
+                if (!oldLibraryFile.renameTo(newLibraryFile)) {
+                    Slog.e(TAG, "Cannot rename native library directory "
+                            + oldLibraryFile.getPath() + " to " + newLibraryFile.getPath());
+                    return false;
+                }
+                libraryPath = newLibraryFile.getPath();
+
+                // Attempt to set permissions
+                if (!setPermissions()) {
+                    return false;
+                }
+
+                if (!SELinux.restorecon(newCodeFile)) {
+                    return false;
+                }
+
+                return true;
+            }
+        }
+
+        int doPostInstall(int status, int uid) {
+            if (status != PackageManager.INSTALL_SUCCEEDED) {
+                cleanUp();
+            }
+            return status;
+        }
+
+        String getResourcePath() {
+            return resourceFileName;
+        }
+
+        private String getResourcePathFromCodePath() {
+            final String codePath = getCodePath();
+            if (isFwdLocked()) {
+                final StringBuilder sb = new StringBuilder();
+
+                sb.append(mAppInstallDir.getPath());
+                sb.append('/');
+                sb.append(getApkName(codePath));
+                sb.append(".zip");
+
+                /*
+                 * If our APK is a temporary file, mark the resource as a
+                 * temporary file as well so it can be cleaned up after
+                 * catastrophic failure.
+                 */
+                if (codePath.endsWith(".tmp")) {
+                    sb.append(".tmp");
+                }
+
+                return sb.toString();
+            } else {
+                return codePath;
+            }
+        }
+
+        private String getLibraryPathFromCodePath() {
+            return new File(mAppLibInstallDir, getApkName(getCodePath())).getPath();
+        }
+
+        @Override
+        String getNativeLibraryPath() {
+            if (libraryPath == null) {
+                libraryPath = getLibraryPathFromCodePath();
+            }
+            return libraryPath;
+        }
+
+        private boolean cleanUp() {
+            boolean ret = true;
+            String sourceDir = getCodePath();
+            String publicSourceDir = getResourcePath();
+            if (sourceDir != null) {
+                File sourceFile = new File(sourceDir);
+                if (!sourceFile.exists()) {
+                    Slog.w(TAG, "Package source " + sourceDir + " does not exist.");
+                    ret = false;
+                }
+                // Delete application's code and resources
+                sourceFile.delete();
+            }
+            if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) {
+                final File publicSourceFile = new File(publicSourceDir);
+                if (!publicSourceFile.exists()) {
+                    Slog.w(TAG, "Package public source " + publicSourceFile + " does not exist.");
+                }
+                if (publicSourceFile.exists()) {
+                    publicSourceFile.delete();
+                }
+            }
+
+            if (libraryPath != null) {
+                File nativeLibraryFile = new File(libraryPath);
+                NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryFile);
+                if (!nativeLibraryFile.delete()) {
+                    Slog.w(TAG, "Couldn't delete native library directory " + libraryPath);
+                }
+            }
+
+            return ret;
+        }
+
+        void cleanUpResourcesLI() {
+            String sourceDir = getCodePath();
+            if (cleanUp()) {
+                int retCode = mInstaller.rmdex(sourceDir);
+                if (retCode < 0) {
+                    Slog.w(TAG, "Couldn't remove dex file for package: "
+                            +  " at location "
+                            + sourceDir + ", retcode=" + retCode);
+                    // we don't consider this to be a failure of the core package deletion
+                }
+            }
+        }
+
+        private boolean setPermissions() {
+            // TODO Do this in a more elegant way later on. for now just a hack
+            if (!isFwdLocked()) {
+                final int filePermissions =
+                    FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP
+                    |FileUtils.S_IROTH;
+                int retCode = FileUtils.setPermissions(getCodePath(), filePermissions, -1, -1);
+                if (retCode != 0) {
+                    Slog.e(TAG, "Couldn't set new package file permissions for " +
+                            getCodePath()
+                            + ". The return code was: " + retCode);
+                    // TODO Define new internal error
+                    return false;
+                }
+                return true;
+            }
+            return true;
+        }
+
+        boolean doPostDeleteLI(boolean delete) {
+            // XXX err, shouldn't we respect the delete flag?
+            cleanUpResourcesLI();
+            return true;
+        }
+    }
+
+    private boolean isAsecExternal(String cid) {
+        final String asecPath = PackageHelper.getSdFilesystem(cid);
+        return !asecPath.startsWith(mAsecInternalPath);
+    }
+
+    /**
+     * Extract the MountService "container ID" from the full code path of an
+     * .apk.
+     */
+    static String cidFromCodePath(String fullCodePath) {
+        int eidx = fullCodePath.lastIndexOf("/");
+        String subStr1 = fullCodePath.substring(0, eidx);
+        int sidx = subStr1.lastIndexOf("/");
+        return subStr1.substring(sidx+1, eidx);
+    }
+
+    class AsecInstallArgs extends InstallArgs {
+        static final String RES_FILE_NAME = "pkg.apk";
+        static final String PUBLIC_RES_FILE_NAME = "res.zip";
+
+        String cid;
+        String packagePath;
+        String resourcePath;
+        String libraryPath;
+
+        AsecInstallArgs(InstallParams params) {
+            super(params.getPackageUri(), params.observer, params.flags,
+                    params.installerPackageName, params.getManifestDigest(),
+                    params.getUser());
+        }
+
+        AsecInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath,
+                boolean isExternal, boolean isForwardLocked) {
+            super(null, null, (isExternal ? PackageManager.INSTALL_EXTERNAL : 0)
+                    | (isForwardLocked ? PackageManager.INSTALL_FORWARD_LOCK : 0),
+                    null, null, null);
+            // Extract cid from fullCodePath
+            int eidx = fullCodePath.lastIndexOf("/");
+            String subStr1 = fullCodePath.substring(0, eidx);
+            int sidx = subStr1.lastIndexOf("/");
+            cid = subStr1.substring(sidx+1, eidx);
+            setCachePath(subStr1);
+        }
+
+        AsecInstallArgs(String cid, boolean isForwardLocked) {
+            super(null, null, (isAsecExternal(cid) ? PackageManager.INSTALL_EXTERNAL : 0)
+                    | (isForwardLocked ? PackageManager.INSTALL_FORWARD_LOCK : 0),
+                    null, null, null);
+            this.cid = cid;
+            setCachePath(PackageHelper.getSdDir(cid));
+        }
+
+        AsecInstallArgs(Uri packageURI, String cid, boolean isExternal, boolean isForwardLocked) {
+            super(packageURI, null, (isExternal ? PackageManager.INSTALL_EXTERNAL : 0)
+                    | (isForwardLocked ? PackageManager.INSTALL_FORWARD_LOCK : 0),
+                    null, null, null);
+            this.cid = cid;
+        }
+
+        void createCopyFile() {
+            cid = getTempContainerId();
+        }
+
+        boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException {
+            try {
+                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
+                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                return imcs.checkExternalFreeStorage(packageURI, isFwdLocked());
+            } finally {
+                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            }
+        }
+
+        private final boolean isExternal() {
+            return (flags & PackageManager.INSTALL_EXTERNAL) != 0;
+        }
+
+        int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException {
+            if (temp) {
+                createCopyFile();
+            } else {
+                /*
+                 * Pre-emptively destroy the container since it's destroyed if
+                 * copying fails due to it existing anyway.
+                 */
+                PackageHelper.destroySdDir(cid);
+            }
+
+            final String newCachePath;
+            try {
+                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
+                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
+                newCachePath = imcs.copyResourceToContainer(packageURI, cid, getEncryptKey(),
+                        RES_FILE_NAME, PUBLIC_RES_FILE_NAME, isExternal(), isFwdLocked());
+            } finally {
+                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
+            }
+
+            if (newCachePath != null) {
+                setCachePath(newCachePath);
+                return PackageManager.INSTALL_SUCCEEDED;
+            } else {
+                return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
+            }
+        }
+
+        @Override
+        String getCodePath() {
+            return packagePath;
+        }
+
+        @Override
+        String getResourcePath() {
+            return resourcePath;
+        }
+
+        @Override
+        String getNativeLibraryPath() {
+            return libraryPath;
+        }
+
+        int doPreInstall(int status) {
+            if (status != PackageManager.INSTALL_SUCCEEDED) {
+                // Destroy container
+                PackageHelper.destroySdDir(cid);
+            } else {
+                boolean mounted = PackageHelper.isContainerMounted(cid);
+                if (!mounted) {
+                    String newCachePath = PackageHelper.mountSdDir(cid, getEncryptKey(),
+                            Process.SYSTEM_UID);
+                    if (newCachePath != null) {
+                        setCachePath(newCachePath);
+                    } else {
+                        return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
+                    }
+                }
+            }
+            return status;
+        }
+
+        boolean doRename(int status, final String pkgName,
+                String oldCodePath) {
+            String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME);
+            String newCachePath = null;
+            if (PackageHelper.isContainerMounted(cid)) {
+                // Unmount the container
+                if (!PackageHelper.unMountSdDir(cid)) {
+                    Slog.i(TAG, "Failed to unmount " + cid + " before renaming");
+                    return false;
+                }
+            }
+            if (!PackageHelper.renameSdDir(cid, newCacheId)) {
+                Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId +
+                        " which might be stale. Will try to clean up.");
+                // Clean up the stale container and proceed to recreate.
+                if (!PackageHelper.destroySdDir(newCacheId)) {
+                    Slog.e(TAG, "Very strange. Cannot clean up stale container " + newCacheId);
+                    return false;
+                }
+                // Successfully cleaned up stale container. Try to rename again.
+                if (!PackageHelper.renameSdDir(cid, newCacheId)) {
+                    Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId
+                            + " inspite of cleaning it up.");
+                    return false;
+                }
+            }
+            if (!PackageHelper.isContainerMounted(newCacheId)) {
+                Slog.w(TAG, "Mounting container " + newCacheId);
+                newCachePath = PackageHelper.mountSdDir(newCacheId,
+                        getEncryptKey(), Process.SYSTEM_UID);
+            } else {
+                newCachePath = PackageHelper.getSdDir(newCacheId);
+            }
+            if (newCachePath == null) {
+                Slog.w(TAG, "Failed to get cache path for  " + newCacheId);
+                return false;
+            }
+            Log.i(TAG, "Succesfully renamed " + cid +
+                    " to " + newCacheId +
+                    " at new path: " + newCachePath);
+            cid = newCacheId;
+            setCachePath(newCachePath);
+            return true;
+        }
+
+        private void setCachePath(String newCachePath) {
+            File cachePath = new File(newCachePath);
+            libraryPath = new File(cachePath, LIB_DIR_NAME).getPath();
+            packagePath = new File(cachePath, RES_FILE_NAME).getPath();
+
+            if (isFwdLocked()) {
+                resourcePath = new File(cachePath, PUBLIC_RES_FILE_NAME).getPath();
+            } else {
+                resourcePath = packagePath;
+            }
+        }
+
+        int doPostInstall(int status, int uid) {
+            if (status != PackageManager.INSTALL_SUCCEEDED) {
+                cleanUp();
+            } else {
+                final int groupOwner;
+                final String protectedFile;
+                if (isFwdLocked()) {
+                    groupOwner = UserHandle.getSharedAppGid(uid);
+                    protectedFile = RES_FILE_NAME;
+                } else {
+                    groupOwner = -1;
+                    protectedFile = null;
+                }
+
+                if (uid < Process.FIRST_APPLICATION_UID
+                        || !PackageHelper.fixSdPermissions(cid, groupOwner, protectedFile)) {
+                    Slog.e(TAG, "Failed to finalize " + cid);
+                    PackageHelper.destroySdDir(cid);
+                    return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
+                }
+
+                boolean mounted = PackageHelper.isContainerMounted(cid);
+                if (!mounted) {
+                    PackageHelper.mountSdDir(cid, getEncryptKey(), Process.myUid());
+                }
+            }
+            return status;
+        }
+
+        private void cleanUp() {
+            if (DEBUG_SD_INSTALL) Slog.i(TAG, "cleanUp");
+
+            // Destroy secure container
+            PackageHelper.destroySdDir(cid);
+        }
+
+        void cleanUpResourcesLI() {
+            String sourceFile = getCodePath();
+            // Remove dex file
+            int retCode = mInstaller.rmdex(sourceFile);
+            if (retCode < 0) {
+                Slog.w(TAG, "Couldn't remove dex file for package: "
+                        + " at location "
+                        + sourceFile.toString() + ", retcode=" + retCode);
+                // we don't consider this to be a failure of the core package deletion
+            }
+            cleanUp();
+        }
+
+        boolean matchContainer(String app) {
+            if (cid.startsWith(app)) {
+                return true;
+            }
+            return false;
+        }
+
+        String getPackageName() {
+            return getAsecPackageName(cid);
+        }
+
+        boolean doPostDeleteLI(boolean delete) {
+            boolean ret = false;
+            boolean mounted = PackageHelper.isContainerMounted(cid);
+            if (mounted) {
+                // Unmount first
+                ret = PackageHelper.unMountSdDir(cid);
+            }
+            if (ret && delete) {
+                cleanUpResourcesLI();
+            }
+            return ret;
+        }
+
+        @Override
+        int doPreCopy() {
+            if (isFwdLocked()) {
+                if (!PackageHelper.fixSdPermissions(cid,
+                        getPackageUid(DEFAULT_CONTAINER_PACKAGE, 0), RES_FILE_NAME)) {
+                    return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
+                }
+            }
+
+            return PackageManager.INSTALL_SUCCEEDED;
+        }
+
+        @Override
+        int doPostCopy(int uid) {
+            if (isFwdLocked()) {
+                if (uid < Process.FIRST_APPLICATION_UID
+                        || !PackageHelper.fixSdPermissions(cid, UserHandle.getSharedAppGid(uid),
+                                RES_FILE_NAME)) {
+                    Slog.e(TAG, "Failed to finalize " + cid);
+                    PackageHelper.destroySdDir(cid);
+                    return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
+                }
+            }
+
+            return PackageManager.INSTALL_SUCCEEDED;
+        }
+    };
+
+    static String getAsecPackageName(String packageCid) {
+        int idx = packageCid.lastIndexOf("-");
+        if (idx == -1) {
+            return packageCid;
+        }
+        return packageCid.substring(0, idx);
+    }
+
+    // Utility method used to create code paths based on package name and available index.
+    private static String getNextCodePath(String oldCodePath, String prefix, String suffix) {
+        String idxStr = "";
+        int idx = 1;
+        // Fall back to default value of idx=1 if prefix is not
+        // part of oldCodePath
+        if (oldCodePath != null) {
+            String subStr = oldCodePath;
+            // Drop the suffix right away
+            if (subStr.endsWith(suffix)) {
+                subStr = subStr.substring(0, subStr.length() - suffix.length());
+            }
+            // If oldCodePath already contains prefix find out the
+            // ending index to either increment or decrement.
+            int sidx = subStr.lastIndexOf(prefix);
+            if (sidx != -1) {
+                subStr = subStr.substring(sidx + prefix.length());
+                if (subStr != null) {
+                    if (subStr.startsWith(INSTALL_PACKAGE_SUFFIX)) {
+                        subStr = subStr.substring(INSTALL_PACKAGE_SUFFIX.length());
+                    }
+                    try {
+                        idx = Integer.parseInt(subStr);
+                        if (idx <= 1) {
+                            idx++;
+                        } else {
+                            idx--;
+                        }
+                    } catch(NumberFormatException e) {
+                    }
+                }
+            }
+        }
+        idxStr = INSTALL_PACKAGE_SUFFIX + Integer.toString(idx);
+        return prefix + idxStr;
+    }
+
+    // Utility method used to ignore ADD/REMOVE events
+    // by directory observer.
+    private static boolean ignoreCodePath(String fullPathStr) {
+        String apkName = getApkName(fullPathStr);
+        int idx = apkName.lastIndexOf(INSTALL_PACKAGE_SUFFIX);
+        if (idx != -1 && ((idx+1) < apkName.length())) {
+            // Make sure the package ends with a numeral
+            String version = apkName.substring(idx+1);
+            try {
+                Integer.parseInt(version);
+                return true;
+            } catch (NumberFormatException e) {}
+        }
+        return false;
+    }
+    
+    // Utility method that returns the relative package path with respect
+    // to the installation directory. Like say for /data/data/com.test-1.apk
+    // string com.test-1 is returned.
+    static String getApkName(String codePath) {
+        if (codePath == null) {
+            return null;
+        }
+        int sidx = codePath.lastIndexOf("/");
+        int eidx = codePath.lastIndexOf(".");
+        if (eidx == -1) {
+            eidx = codePath.length();
+        } else if (eidx == 0) {
+            Slog.w(TAG, " Invalid code path, "+ codePath + " Not a valid apk name");
+            return null;
+        }
+        return codePath.substring(sidx+1, eidx);
+    }
+
+    class PackageInstalledInfo {
+        String name;
+        int uid;
+        // The set of users that originally had this package installed.
+        int[] origUsers;
+        // The set of users that now have this package installed.
+        int[] newUsers;
+        PackageParser.Package pkg;
+        int returnCode;
+        PackageRemovedInfo removedInfo;
+    }
+
+    /*
+     * Install a non-existing package.
+     */
+    private void installNewPackageLI(PackageParser.Package pkg,
+            int parseFlags, int scanMode, UserHandle user,
+            String installerPackageName, PackageInstalledInfo res) {
+        // Remember this for later, in case we need to rollback this install
+        String pkgName = pkg.packageName;
+
+        if (DEBUG_INSTALL) Slog.d(TAG, "installNewPackageLI: " + pkg);
+        boolean dataDirExists = getDataPathForPackage(pkg.packageName, 0).exists();
+        synchronized(mPackages) {
+            if (mSettings.mRenamedPackages.containsKey(pkgName)) {
+                // A package with the same name is already installed, though
+                // it has been renamed to an older name.  The package we
+                // are trying to install should be installed as an update to
+                // the existing one, but that has not been requested, so bail.
+                Slog.w(TAG, "Attempt to re-install " + pkgName
+                        + " without first uninstalling package running as "
+                        + mSettings.mRenamedPackages.get(pkgName));
+                res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS;
+                return;
+            }
+            if (mPackages.containsKey(pkgName) || mAppDirs.containsKey(pkg.mPath)) {
+                // Don't allow installation over an existing package with the same name.
+                Slog.w(TAG, "Attempt to re-install " + pkgName
+                        + " without first uninstalling.");
+                res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS;
+                return;
+            }
+        }
+        mLastScanError = PackageManager.INSTALL_SUCCEEDED;
+        PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanMode,
+                System.currentTimeMillis(), user);
+        if (newPackage == null) {
+            Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath);
+            if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) {
+                res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK;
+            }
+        } else {
+            updateSettingsLI(newPackage,
+                    installerPackageName,
+                    null, null,
+                    res);
+            // delete the partially installed application. the data directory will have to be
+            // restored if it was already existing
+            if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
+                // remove package from internal structures.  Note that we want deletePackageX to
+                // delete the package data and cache directories that it created in
+                // scanPackageLocked, unless those directories existed before we even tried to
+                // install.
+                deletePackageLI(pkgName, UserHandle.ALL, false, null, null,
+                        dataDirExists ? PackageManager.DELETE_KEEP_DATA : 0,
+                                res.removedInfo, true);
+            }
+        }
+    }
+
+    private void replacePackageLI(PackageParser.Package pkg,
+            int parseFlags, int scanMode, UserHandle user,
+            String installerPackageName, PackageInstalledInfo res) {
+
+        PackageParser.Package oldPackage;
+        String pkgName = pkg.packageName;
+        int[] allUsers;
+        boolean[] perUserInstalled;
+
+        // First find the old package info and check signatures
+        synchronized(mPackages) {
+            oldPackage = mPackages.get(pkgName);
+            if (DEBUG_INSTALL) Slog.d(TAG, "replacePackageLI: new=" + pkg + ", old=" + oldPackage);
+            if (compareSignatures(oldPackage.mSignatures, pkg.mSignatures)
+                    != PackageManager.SIGNATURE_MATCH) {
+                Slog.w(TAG, "New package has a different signature: " + pkgName);
+                res.returnCode = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
+                return;
+            }
+
+            // In case of rollback, remember per-user/profile install state
+            PackageSetting ps = mSettings.mPackages.get(pkgName);
+            allUsers = sUserManager.getUserIds();
+            perUserInstalled = new boolean[allUsers.length];
+            for (int i = 0; i < allUsers.length; i++) {
+                perUserInstalled[i] = ps != null ? ps.getInstalled(allUsers[i]) : false;
+            }
+        }
+        boolean sysPkg = (isSystemApp(oldPackage));
+        if (sysPkg) {
+            replaceSystemPackageLI(oldPackage, pkg, parseFlags, scanMode,
+                    user, allUsers, perUserInstalled, installerPackageName, res);
+        } else {
+            replaceNonSystemPackageLI(oldPackage, pkg, parseFlags, scanMode,
+                    user, allUsers, perUserInstalled, installerPackageName, res);
+        }
+    }
+
+    private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage,
+            PackageParser.Package pkg, int parseFlags, int scanMode, UserHandle user,
+            int[] allUsers, boolean[] perUserInstalled,
+            String installerPackageName, PackageInstalledInfo res) {
+        PackageParser.Package newPackage = null;
+        String pkgName = deletedPackage.packageName;
+        boolean deletedPkg = true;
+        boolean updatedSettings = false;
+
+        if (DEBUG_INSTALL) Slog.d(TAG, "replaceNonSystemPackageLI: new=" + pkg + ", old="
+                + deletedPackage);
+        long origUpdateTime;
+        if (pkg.mExtras != null) {
+            origUpdateTime = ((PackageSetting)pkg.mExtras).lastUpdateTime;
+        } else {
+            origUpdateTime = 0;
+        }
+
+        // First delete the existing package while retaining the data directory
+        if (!deletePackageLI(pkgName, null, true, null, null, PackageManager.DELETE_KEEP_DATA,
+                res.removedInfo, true)) {
+            // If the existing package wasn't successfully deleted
+            res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
+            deletedPkg = false;
+        } else {
+            // Successfully deleted the old package. Now proceed with re-installation
+            mLastScanError = PackageManager.INSTALL_SUCCEEDED;
+            newPackage = scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_TIME,
+                    System.currentTimeMillis(), user);
+            if (newPackage == null) {
+                Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath);
+                if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) {
+                    res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK;
+                }
+            } else {
+                updateSettingsLI(newPackage,
+                        installerPackageName,
+                        allUsers, perUserInstalled,
+                        res);
+                updatedSettings = true;
+            }
+        }
+
+        if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
+            // remove package from internal structures.  Note that we want deletePackageX to
+            // delete the package data and cache directories that it created in
+            // scanPackageLocked, unless those directories existed before we even tried to
+            // install.
+            if(updatedSettings) {
+                if (DEBUG_INSTALL) Slog.d(TAG, "Install failed, rolling pack: " + pkgName);
+                deletePackageLI(
+                        pkgName, null, true, allUsers, perUserInstalled,
+                        PackageManager.DELETE_KEEP_DATA,
+                                res.removedInfo, true);
+            }
+            // Since we failed to install the new package we need to restore the old
+            // package that we deleted.
+            if(deletedPkg) {
+                if (DEBUG_INSTALL) Slog.d(TAG, "Install failed, reinstalling: " + deletedPackage);
+                File restoreFile = new File(deletedPackage.mPath);
+                // Parse old package
+                boolean oldOnSd = isExternal(deletedPackage);
+                int oldParseFlags  = mDefParseFlags | PackageParser.PARSE_CHATTY |
+                        (isForwardLocked(deletedPackage) ? PackageParser.PARSE_FORWARD_LOCK : 0) |
+                        (oldOnSd ? PackageParser.PARSE_ON_SDCARD : 0);
+                int oldScanMode = (oldOnSd ? 0 : SCAN_MONITOR) | SCAN_UPDATE_SIGNATURE
+                        | SCAN_UPDATE_TIME;
+                if (scanPackageLI(restoreFile, oldParseFlags, oldScanMode,
+                        origUpdateTime, null) == null) {
+                    Slog.e(TAG, "Failed to restore package : " + pkgName + " after failed upgrade");
+                    return;
+                }
+                // Restore of old package succeeded. Update permissions.
+                // writer
+                synchronized (mPackages) {
+                    updatePermissionsLPw(deletedPackage.packageName, deletedPackage,
+                            UPDATE_PERMISSIONS_ALL);
+                    // can downgrade to reader
+                    mSettings.writeLPr();
+                }
+                Slog.i(TAG, "Successfully restored package : " + pkgName + " after failed upgrade");
+            }
+        }
+    }
+
+    private void replaceSystemPackageLI(PackageParser.Package deletedPackage,
+            PackageParser.Package pkg, int parseFlags, int scanMode, UserHandle user,
+            int[] allUsers, boolean[] perUserInstalled,
+            String installerPackageName, PackageInstalledInfo res) {
+        if (DEBUG_INSTALL) Slog.d(TAG, "replaceSystemPackageLI: new=" + pkg
+                + ", old=" + deletedPackage);
+        PackageParser.Package newPackage = null;
+        boolean updatedSettings = false;
+        parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING |
+                PackageParser.PARSE_IS_SYSTEM;
+        if ((deletedPackage.applicationInfo.flags&ApplicationInfo.FLAG_PRIVILEGED) != 0) {
+            parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
+        }
+        String packageName = deletedPackage.packageName;
+        res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
+        if (packageName == null) {
+            Slog.w(TAG, "Attempt to delete null packageName.");
+            return;
+        }
+        PackageParser.Package oldPkg;
+        PackageSetting oldPkgSetting;
+        // reader
+        synchronized (mPackages) {
+            oldPkg = mPackages.get(packageName);
+            oldPkgSetting = mSettings.mPackages.get(packageName);
+            if((oldPkg == null) || (oldPkg.applicationInfo == null) ||
+                    (oldPkgSetting == null)) {
+                Slog.w(TAG, "Couldn't find package:"+packageName+" information");
+                return;
+            }
+        }
+
+        killApplication(packageName, oldPkg.applicationInfo.uid, "replace sys pkg");
+
+        res.removedInfo.uid = oldPkg.applicationInfo.uid;
+        res.removedInfo.removedPackage = packageName;
+        // Remove existing system package
+        removePackageLI(oldPkgSetting, true);
+        // writer
+        synchronized (mPackages) {
+            if (!mSettings.disableSystemPackageLPw(packageName) && deletedPackage != null) {
+                // We didn't need to disable the .apk as a current system package,
+                // which means we are replacing another update that is already
+                // installed.  We need to make sure to delete the older one's .apk.
+                res.removedInfo.args = createInstallArgs(0,
+                        deletedPackage.applicationInfo.sourceDir,
+                        deletedPackage.applicationInfo.publicSourceDir,
+                        deletedPackage.applicationInfo.nativeLibraryDir);
+            } else {
+                res.removedInfo.args = null;
+            }
+        }
+        
+        // Successfully disabled the old package. Now proceed with re-installation
+        mLastScanError = PackageManager.INSTALL_SUCCEEDED;
+        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+        newPackage = scanPackageLI(pkg, parseFlags, scanMode, 0, user);
+        if (newPackage == null) {
+            Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath);
+            if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) {
+                res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK;
+            }
+        } else {
+            if (newPackage.mExtras != null) {
+                final PackageSetting newPkgSetting = (PackageSetting)newPackage.mExtras;
+                newPkgSetting.firstInstallTime = oldPkgSetting.firstInstallTime;
+                newPkgSetting.lastUpdateTime = System.currentTimeMillis();
+            }
+            updateSettingsLI(newPackage, installerPackageName, allUsers, perUserInstalled, res);
+            updatedSettings = true;
+        }
+
+        if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
+            // Re installation failed. Restore old information
+            // Remove new pkg information
+            if (newPackage != null) {
+                removeInstalledPackageLI(newPackage, true);
+            }
+            // Add back the old system package
+            scanPackageLI(oldPkg, parseFlags, SCAN_MONITOR | SCAN_UPDATE_SIGNATURE, 0, user);
+            // Restore the old system information in Settings
+            synchronized(mPackages) {
+                if (updatedSettings) {
+                    mSettings.enableSystemPackageLPw(packageName);
+                    mSettings.setInstallerPackageName(packageName,
+                            oldPkgSetting.installerPackageName);
+                }
+                mSettings.writeLPr();
+            }
+        }
+    }
+
+    // Utility method used to move dex files during install.
+    private int moveDexFilesLI(PackageParser.Package newPackage) {
+        int retCode;
+        if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) {
+            retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath);
+            if (retCode != 0) {
+                if (mNoDexOpt) {
+                    /*
+                     * If we're in an engineering build, programs are lazily run
+                     * through dexopt. If the .dex file doesn't exist yet, it
+                     * will be created when the program is run next.
+                     */
+                    Slog.i(TAG, "dex file doesn't exist, skipping move: " + newPackage.mPath);
+                } else {
+                    Slog.e(TAG, "Couldn't rename dex file: " + newPackage.mPath);
+                    return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+                }
+            }
+        }
+        return PackageManager.INSTALL_SUCCEEDED;
+    }
+
+    private void updateSettingsLI(PackageParser.Package newPackage, String installerPackageName,
+            int[] allUsers, boolean[] perUserInstalled,
+            PackageInstalledInfo res) {
+        String pkgName = newPackage.packageName;
+        synchronized (mPackages) {
+            //write settings. the installStatus will be incomplete at this stage.
+            //note that the new package setting would have already been
+            //added to mPackages. It hasn't been persisted yet.
+            mSettings.setInstallStatus(pkgName, PackageSettingBase.PKG_INSTALL_INCOMPLETE);
+            mSettings.writeLPr();
+        }
+
+        if ((res.returnCode = moveDexFilesLI(newPackage))
+                != PackageManager.INSTALL_SUCCEEDED) {
+            // Discontinue if moving dex files failed.
+            return;
+        }
+
+        if (DEBUG_INSTALL) Slog.d(TAG, "New package installed in " + newPackage.mPath);
+
+        synchronized (mPackages) {
+            updatePermissionsLPw(newPackage.packageName, newPackage,
+                    UPDATE_PERMISSIONS_REPLACE_PKG | (newPackage.permissions.size() > 0
+                            ? UPDATE_PERMISSIONS_ALL : 0));
+            // For system-bundled packages, we assume that installing an upgraded version
+            // of the package implies that the user actually wants to run that new code,
+            // so we enable the package.
+            if (isSystemApp(newPackage)) {
+                // NB: implicit assumption that system package upgrades apply to all users
+                if (DEBUG_INSTALL) {
+                    Slog.d(TAG, "Implicitly enabling system package on upgrade: " + pkgName);
+                }
+                PackageSetting ps = mSettings.mPackages.get(pkgName);
+                if (ps != null) {
+                    if (res.origUsers != null) {
+                        for (int userHandle : res.origUsers) {
+                            ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT,
+                                    userHandle, installerPackageName);
+                        }
+                    }
+                    // Also convey the prior install/uninstall state
+                    if (allUsers != null && perUserInstalled != null) {
+                        for (int i = 0; i < allUsers.length; i++) {
+                            if (DEBUG_INSTALL) {
+                                Slog.d(TAG, "    user " + allUsers[i]
+                                        + " => " + perUserInstalled[i]);
+                            }
+                            ps.setInstalled(perUserInstalled[i], allUsers[i]);
+                        }
+                        // these install state changes will be persisted in the
+                        // upcoming call to mSettings.writeLPr().
+                    }
+                }
+            }
+            res.name = pkgName;
+            res.uid = newPackage.applicationInfo.uid;
+            res.pkg = newPackage;
+            mSettings.setInstallStatus(pkgName, PackageSettingBase.PKG_INSTALL_COMPLETE);
+            mSettings.setInstallerPackageName(pkgName, installerPackageName);
+            res.returnCode = PackageManager.INSTALL_SUCCEEDED;
+            //to update install status
+            mSettings.writeLPr();
+        }
+    }
+
+    private void installPackageLI(InstallArgs args,
+            boolean newInstall, PackageInstalledInfo res) {
+        int pFlags = args.flags;
+        String installerPackageName = args.installerPackageName;
+        File tmpPackageFile = new File(args.getCodePath());
+        boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0);
+        boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0);
+        boolean replace = false;
+        int scanMode = (onSd ? 0 : SCAN_MONITOR) | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE
+                | (newInstall ? SCAN_NEW_INSTALL : 0);
+        // Result object to be returned
+        res.returnCode = PackageManager.INSTALL_SUCCEEDED;
+
+        if (DEBUG_INSTALL) Slog.d(TAG, "installPackageLI: path=" + tmpPackageFile);
+        // Retrieve PackageSettings and parse package
+        int parseFlags = mDefParseFlags | PackageParser.PARSE_CHATTY
+                | (forwardLocked ? PackageParser.PARSE_FORWARD_LOCK : 0)
+                | (onSd ? PackageParser.PARSE_ON_SDCARD : 0);
+        PackageParser pp = new PackageParser(tmpPackageFile.getPath());
+        pp.setSeparateProcesses(mSeparateProcesses);
+        final PackageParser.Package pkg = pp.parsePackage(tmpPackageFile,
+                null, mMetrics, parseFlags);
+        if (pkg == null) {
+            res.returnCode = pp.getParseError();
+            return;
+        }
+        String pkgName = res.name = pkg.packageName;
+        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) {
+            if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) {
+                res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY;
+                return;
+            }
+        }
+        if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) {
+            res.returnCode = pp.getParseError();
+            return;
+        }
+
+        /* If the installer passed in a manifest digest, compare it now. */
+        if (args.manifestDigest != null) {
+            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.returnCode = PackageManager.INSTALL_FAILED_PACKAGE_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;
+        boolean systemApp = false;
+        synchronized (mPackages) {
+            // Check if installing already existing package
+            if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
+                String oldName = mSettings.mRenamedPackages.get(pkgName);
+                if (pkg.mOriginalPackages != null
+                        && pkg.mOriginalPackages.contains(oldName)
+                        && mPackages.containsKey(oldName)) {
+                    // This package is derived from an original package,
+                    // and this device has been updating from that original
+                    // name.  We must continue using the original name, so
+                    // rename the new package here.
+                    pkg.setPackageName(oldName);
+                    pkgName = pkg.packageName;
+                    replace = true;
+                    if (DEBUG_INSTALL) Slog.d(TAG, "Replacing existing renamed package: oldName="
+                            + oldName + " pkgName=" + pkgName);
+                } else if (mPackages.containsKey(pkgName)) {
+                    // This package, under its official name, already exists
+                    // on the device; we should replace it.
+                    replace = true;
+                    if (DEBUG_INSTALL) Slog.d(TAG, "Replace existing pacakge: " + pkgName);
+                }
+            }
+            PackageSetting ps = mSettings.mPackages.get(pkgName);
+            if (ps != null) {
+                if (DEBUG_INSTALL) Slog.d(TAG, "Existing package: " + ps);
+                oldCodePath = mSettings.mPackages.get(pkgName).codePathString;
+                if (ps.pkg != null && ps.pkg.applicationInfo != null) {
+                    systemApp = (ps.pkg.applicationInfo.flags &
+                            ApplicationInfo.FLAG_SYSTEM) != 0;
+                }
+                res.origUsers = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
+            }
+        }
+
+        if (systemApp && onSd) {
+            // Disable updates to system apps on sdcard
+            Slog.w(TAG, "Cannot install updates to system apps on sdcard");
+            res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
+            return;
+        }
+
+        if (!args.doRename(res.returnCode, pkgName, oldCodePath)) {
+            res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+            return;
+        }
+        // Set application objects path explicitly after the rename
+        setApplicationInfoPaths(pkg, args.getCodePath(), args.getResourcePath());
+        pkg.applicationInfo.nativeLibraryDir = args.getNativeLibraryPath();
+        if (replace) {
+            replacePackageLI(pkg, parseFlags, scanMode, args.user,
+                    installerPackageName, res);
+        } else {
+            installNewPackageLI(pkg, parseFlags, scanMode | SCAN_DELETE_DATA_ON_FAILURES, args.user,
+                    installerPackageName, res);
+        }
+        synchronized (mPackages) {
+            final PackageSetting ps = mSettings.mPackages.get(pkgName);
+            if (ps != null) {
+                res.newUsers = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
+            }
+        }
+    }
+
+    private static boolean isForwardLocked(PackageParser.Package pkg) {
+        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0;
+    }
+
+
+    private boolean isForwardLocked(PackageSetting ps) {
+        return (ps.pkgFlags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0;
+    }
+
+    private static boolean isExternal(PackageParser.Package pkg) {
+        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
+    }
+
+    private static boolean isExternal(PackageSetting ps) {
+        return (ps.pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
+    }
+
+    private static boolean isSystemApp(PackageParser.Package pkg) {
+        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+    }
+
+    private static boolean isPrivilegedApp(PackageParser.Package pkg) {
+        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_PRIVILEGED) != 0;
+    }
+
+    private static boolean isSystemApp(ApplicationInfo info) {
+        return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+    }
+
+    private static boolean isSystemApp(PackageSetting ps) {
+        return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
+    }
+
+    private static boolean isUpdatedSystemApp(PackageSetting ps) {
+        return (ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
+    }
+
+    private static boolean isUpdatedSystemApp(PackageParser.Package pkg) {
+        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
+    }
+
+    private int packageFlagsToInstallFlags(PackageSetting ps) {
+        int installFlags = 0;
+        if (isExternal(ps)) {
+            installFlags |= PackageManager.INSTALL_EXTERNAL;
+        }
+        if (isForwardLocked(ps)) {
+            installFlags |= PackageManager.INSTALL_FORWARD_LOCK;
+        }
+        return installFlags;
+    }
+
+    private void deleteTempPackageFiles() {
+        final FilenameFilter filter = new FilenameFilter() {
+            public boolean accept(File dir, String name) {
+                return name.startsWith("vmdl") && name.endsWith(".tmp");
+            }
+        };
+        deleteTempPackageFilesInDirectory(mAppInstallDir, filter);
+        deleteTempPackageFilesInDirectory(mDrmAppPrivateInstallDir, filter);
+    }
+
+    private static final void deleteTempPackageFilesInDirectory(File directory,
+            FilenameFilter filter) {
+        final String[] tmpFilesList = directory.list(filter);
+        if (tmpFilesList == null) {
+            return;
+        }
+        for (int i = 0; i < tmpFilesList.length; i++) {
+            final File tmpFile = new File(directory, tmpFilesList[i]);
+            tmpFile.delete();
+        }
+    }
+
+    private File createTempPackageFile(File installDir) {
+        File tmpPackageFile;
+        try {
+            tmpPackageFile = File.createTempFile("vmdl", ".tmp", installDir);
+        } catch (IOException e) {
+            Slog.e(TAG, "Couldn't create temp file for downloaded package file.");
+            return null;
+        }
+        try {
+            FileUtils.setPermissions(
+                    tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR,
+                    -1, -1);
+            if (!SELinux.restorecon(tmpPackageFile)) {
+                return null;
+            }
+        } catch (IOException e) {
+            Slog.e(TAG, "Trouble getting the canoncical path for a temp file.");
+            return null;
+        }
+        return tmpPackageFile;
+    }
+
+    @Override
+    public void deletePackageAsUser(final String packageName,
+                                    final IPackageDeleteObserver observer,
+                                    final int userId, final int flags) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.DELETE_PACKAGES, null);
+        final int uid = Binder.getCallingUid();
+        if (UserHandle.getUserId(uid) != userId) {
+            mContext.enforceCallingPermission(
+                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+                    "deletePackage for user " + userId);
+        }
+        if (isUserRestricted(userId, UserManager.DISALLOW_UNINSTALL_APPS)) {
+            try {
+                observer.packageDeleted(packageName, PackageManager.DELETE_FAILED_USER_RESTRICTED);
+            } catch (RemoteException re) {
+            }
+            return;
+        }
+
+        if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageAsUser: pkg=" + packageName + " user=" + userId);
+        // Queue up an async operation since the package deletion may take a little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                mHandler.removeCallbacks(this);
+                final int returnCode = deletePackageX(packageName, userId, flags);
+                if (observer != null) {
+                    try {
+                        observer.packageDeleted(packageName, returnCode);
+                    } catch (RemoteException e) {
+                        Log.i(TAG, "Observer no longer exists.");
+                    } //end catch
+                } //end if
+            } //end run
+        });
+    }
+
+    private boolean isPackageDeviceAdmin(String packageName, int userId) {
+        IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface(
+                ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
+        try {
+            if (dpm != null && (dpm.packageHasActiveAdmins(packageName, userId)
+                    || dpm.isDeviceOwner(packageName))) {
+                return true;
+            }
+        } catch (RemoteException e) {
+        }
+        return false;
+    }
+
+    /**
+     *  This method is an internal method that could be get invoked either
+     *  to delete an installed package or to clean up a failed installation.
+     *  After deleting an installed package, a broadcast is sent to notify any
+     *  listeners that the package has been installed. For cleaning up a failed
+     *  installation, the broadcast is not necessary since the package's
+     *  installation wouldn't have sent the initial broadcast either
+     *  The key steps in deleting a package are
+     *  deleting the package information in internal structures like mPackages,
+     *  deleting the packages base directories through installd
+     *  updating mSettings to reflect current status
+     *  persisting settings for later use
+     *  sending a broadcast if necessary
+     */
+    private int deletePackageX(String packageName, int userId, int flags) {
+        final PackageRemovedInfo info = new PackageRemovedInfo();
+        final boolean res;
+
+        if (isPackageDeviceAdmin(packageName, userId)) {
+            Slog.w(TAG, "Not removing package " + packageName + ": has active device admin");
+            return PackageManager.DELETE_FAILED_DEVICE_POLICY_MANAGER;
+        }
+
+        boolean removedForAllUsers = false;
+        boolean systemUpdate = false;
+
+        // for the uninstall-updates case and restricted profiles, remember the per-
+        // userhandle installed state
+        int[] allUsers;
+        boolean[] perUserInstalled;
+        synchronized (mPackages) {
+            PackageSetting ps = mSettings.mPackages.get(packageName);
+            allUsers = sUserManager.getUserIds();
+            perUserInstalled = new boolean[allUsers.length];
+            for (int i = 0; i < allUsers.length; i++) {
+                perUserInstalled[i] = ps != null ? ps.getInstalled(allUsers[i]) : false;
+            }
+        }
+
+        synchronized (mInstallLock) {
+            if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageX: pkg=" + packageName + " user=" + userId);
+            res = deletePackageLI(packageName,
+                    (flags & PackageManager.DELETE_ALL_USERS) != 0
+                            ? UserHandle.ALL : new UserHandle(userId),
+                    true, allUsers, perUserInstalled,
+                    flags | REMOVE_CHATTY, info, true);
+            systemUpdate = info.isRemovedPackageSystemUpdate;
+            if (res && !systemUpdate && mPackages.get(packageName) == null) {
+                removedForAllUsers = true;
+            }
+            if (DEBUG_REMOVE) Slog.d(TAG, "delete res: systemUpdate=" + systemUpdate
+                    + " removedForAllUsers=" + removedForAllUsers);
+        }
+
+        if (res) {
+            info.sendBroadcast(true, systemUpdate, removedForAllUsers);
+
+            // If the removed package was a system update, the old system package
+            // was re-enabled; we need to broadcast this information
+            if (systemUpdate) {
+                Bundle extras = new Bundle(1);
+                extras.putInt(Intent.EXTRA_UID, info.removedAppId >= 0
+                        ? info.removedAppId : info.uid);
+                extras.putBoolean(Intent.EXTRA_REPLACING, true);
+
+                sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName,
+                        extras, null, null, null);
+                sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName,
+                        extras, null, null, null);
+                sendPackageBroadcast(Intent.ACTION_MY_PACKAGE_REPLACED, null,
+                        null, packageName, null, null);
+            }
+        }
+        // Force a gc here.
+        Runtime.getRuntime().gc();
+        // Delete the resources here after sending the broadcast to let
+        // other processes clean up before deleting resources.
+        if (info.args != null) {
+            synchronized (mInstallLock) {
+                info.args.doPostDeleteLI(true);
+            }
+        }
+
+        return res ? PackageManager.DELETE_SUCCEEDED : PackageManager.DELETE_FAILED_INTERNAL_ERROR;
+    }
+
+    static class PackageRemovedInfo {
+        String removedPackage;
+        int uid = -1;
+        int removedAppId = -1;
+        int[] removedUsers = null;
+        boolean isRemovedPackageSystemUpdate = false;
+        // Clean up resources deleted packages.
+        InstallArgs args = null;
+
+        void sendBroadcast(boolean fullRemove, boolean replacing, boolean removedForAllUsers) {
+            Bundle extras = new Bundle(1);
+            extras.putInt(Intent.EXTRA_UID, removedAppId >= 0 ? removedAppId : uid);
+            extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove);
+            if (replacing) {
+                extras.putBoolean(Intent.EXTRA_REPLACING, true);
+            }
+            extras.putBoolean(Intent.EXTRA_REMOVED_FOR_ALL_USERS, removedForAllUsers);
+            if (removedPackage != null) {
+                sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage,
+                        extras, null, null, removedUsers);
+                if (fullRemove && !replacing) {
+                    sendPackageBroadcast(Intent.ACTION_PACKAGE_FULLY_REMOVED, removedPackage,
+                            extras, null, null, removedUsers);
+                }
+            }
+            if (removedAppId >= 0) {
+                sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras, null, null,
+                        removedUsers);
+            }
+        }
+    }
+
+    /*
+     * This method deletes the package from internal data structures. If the DONT_DELETE_DATA
+     * flag is not set, the data directory is removed as well.
+     * make sure this flag is set for partially installed apps. If not its meaningless to
+     * delete a partially installed application.
+     */
+    private void removePackageDataLI(PackageSetting ps,
+            int[] allUserHandles, boolean[] perUserInstalled,
+            PackageRemovedInfo outInfo, int flags, boolean writeSettings) {
+        String packageName = ps.name;
+        if (DEBUG_REMOVE) Slog.d(TAG, "removePackageDataLI: " + ps);
+        removePackageLI(ps, (flags&REMOVE_CHATTY) != 0);
+        // Retrieve object to delete permissions for shared user later on
+        final PackageSetting deletedPs;
+        // reader
+        synchronized (mPackages) {
+            deletedPs = mSettings.mPackages.get(packageName);
+            if (outInfo != null) {
+                outInfo.removedPackage = packageName;
+                outInfo.removedUsers = deletedPs != null
+                        ? deletedPs.queryInstalledUsers(sUserManager.getUserIds(), true)
+                        : null;
+            }
+        }
+        if ((flags&PackageManager.DELETE_KEEP_DATA) == 0) {
+            removeDataDirsLI(packageName);
+            schedulePackageCleaning(packageName, UserHandle.USER_ALL, true);
+        }
+        // writer
+        synchronized (mPackages) {
+            if (deletedPs != null) {
+                if ((flags&PackageManager.DELETE_KEEP_DATA) == 0) {
+                    if (outInfo != null) {
+                        outInfo.removedAppId = mSettings.removePackageLPw(packageName);
+                    }
+                    if (deletedPs != null) {
+                        updatePermissionsLPw(deletedPs.name, null, 0);
+                        if (deletedPs.sharedUser != null) {
+                            // remove permissions associated with package
+                            mSettings.updateSharedUserPermsLPw(deletedPs, mGlobalGids);
+                        }
+                    }
+                    clearPackagePreferredActivitiesLPw(deletedPs.name, UserHandle.USER_ALL);
+                }
+                // make sure to preserve per-user disabled state if this removal was just
+                // a downgrade of a system app to the factory package
+                if (allUserHandles != null && perUserInstalled != null) {
+                    if (DEBUG_REMOVE) {
+                        Slog.d(TAG, "Propagating install state across downgrade");
+                    }
+                    for (int i = 0; i < allUserHandles.length; i++) {
+                        if (DEBUG_REMOVE) {
+                            Slog.d(TAG, "    user " + allUserHandles[i]
+                                    + " => " + perUserInstalled[i]);
+                        }
+                        ps.setInstalled(perUserInstalled[i], allUserHandles[i]);
+                    }
+                }
+            }
+            // can downgrade to reader
+            if (writeSettings) {
+                // Save settings now
+                mSettings.writeLPr();
+            }
+        }
+        if (outInfo != null) {
+            // A user ID was deleted here. Go through all users and remove it
+            // from KeyStore.
+            removeKeystoreDataIfNeeded(UserHandle.USER_ALL, outInfo.removedAppId);
+        }
+    }
+
+    static boolean locationIsPrivileged(File path) {
+        try {
+            final String privilegedAppDir = new File(Environment.getRootDirectory(), "priv-app")
+                    .getCanonicalPath();
+            return path.getCanonicalPath().startsWith(privilegedAppDir);
+        } catch (IOException e) {
+            Slog.e(TAG, "Unable to access code path " + path);
+        }
+        return false;
+    }
+
+    /*
+     * Tries to delete system package.
+     */
+    private boolean deleteSystemPackageLI(PackageSetting newPs,
+            int[] allUserHandles, boolean[] perUserInstalled,
+            int flags, PackageRemovedInfo outInfo, boolean writeSettings) {
+        final boolean applyUserRestrictions
+                = (allUserHandles != null) && (perUserInstalled != null);
+        PackageSetting disabledPs = null;
+        // Confirm if the system package has been updated
+        // An updated system app can be deleted. This will also have to restore
+        // the system pkg from system partition
+        // reader
+        synchronized (mPackages) {
+            disabledPs = mSettings.getDisabledSystemPkgLPr(newPs.name);
+        }
+        if (DEBUG_REMOVE) Slog.d(TAG, "deleteSystemPackageLI: newPs=" + newPs
+                + " disabledPs=" + disabledPs);
+        if (disabledPs == null) {
+            Slog.w(TAG, "Attempt to delete unknown system package "+ newPs.name);
+            return false;
+        } else if (DEBUG_REMOVE) {
+            Slog.d(TAG, "Deleting system pkg from data partition");
+        }
+        if (DEBUG_REMOVE) {
+            if (applyUserRestrictions) {
+                Slog.d(TAG, "Remembering install states:");
+                for (int i = 0; i < allUserHandles.length; i++) {
+                    Slog.d(TAG, "   u=" + allUserHandles[i] + " inst=" + perUserInstalled[i]);
+                }
+            }
+        }
+        // Delete the updated package
+        outInfo.isRemovedPackageSystemUpdate = true;
+        if (disabledPs.versionCode < newPs.versionCode) {
+            // Delete data for downgrades
+            flags &= ~PackageManager.DELETE_KEEP_DATA;
+        } else {
+            // Preserve data by setting flag
+            flags |= PackageManager.DELETE_KEEP_DATA;
+        }
+        boolean ret = deleteInstalledPackageLI(newPs, true, flags,
+                allUserHandles, perUserInstalled, outInfo, writeSettings);
+        if (!ret) {
+            return false;
+        }
+        // writer
+        synchronized (mPackages) {
+            // Reinstate the old system package
+            mSettings.enableSystemPackageLPw(newPs.name);
+            // Remove any native libraries from the upgraded package.
+            NativeLibraryHelper.removeNativeBinariesLI(newPs.nativeLibraryPathString);
+        }
+        // Install the system package
+        if (DEBUG_REMOVE) Slog.d(TAG, "Re-installing system package: " + disabledPs);
+        int parseFlags = PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM;
+        if (locationIsPrivileged(disabledPs.codePath)) {
+            parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
+        }
+        PackageParser.Package newPkg = scanPackageLI(disabledPs.codePath,
+                parseFlags, SCAN_MONITOR | SCAN_NO_PATHS, 0, null);
+
+        if (newPkg == null) {
+            Slog.w(TAG, "Failed to restore system package:" + newPs.name
+                    + " with error:" + mLastScanError);
+            return false;
+        }
+        // writer
+        synchronized (mPackages) {
+            updatePermissionsLPw(newPkg.packageName, newPkg,
+                    UPDATE_PERMISSIONS_ALL | UPDATE_PERMISSIONS_REPLACE_PKG);
+            if (applyUserRestrictions) {
+                if (DEBUG_REMOVE) {
+                    Slog.d(TAG, "Propagating install state across reinstall");
+                }
+                PackageSetting ps = mSettings.mPackages.get(newPkg.packageName);
+                for (int i = 0; i < allUserHandles.length; i++) {
+                    if (DEBUG_REMOVE) {
+                        Slog.d(TAG, "    user " + allUserHandles[i]
+                                + " => " + perUserInstalled[i]);
+                    }
+                    ps.setInstalled(perUserInstalled[i], allUserHandles[i]);
+                }
+                // Regardless of writeSettings we need to ensure that this restriction
+                // state propagation is persisted
+                mSettings.writeAllUsersPackageRestrictionsLPr();
+            }
+            // can downgrade to reader here
+            if (writeSettings) {
+                mSettings.writeLPr();
+            }
+        }
+        return true;
+    }
+
+    private boolean deleteInstalledPackageLI(PackageSetting ps,
+            boolean deleteCodeAndResources, int flags,
+            int[] allUserHandles, boolean[] perUserInstalled,
+            PackageRemovedInfo outInfo, boolean writeSettings) {
+        if (outInfo != null) {
+            outInfo.uid = ps.appId;
+        }
+
+        // Delete package data from internal structures and also remove data if flag is set
+        removePackageDataLI(ps, allUserHandles, perUserInstalled, outInfo, flags, writeSettings);
+
+        // Delete application code and resources
+        if (deleteCodeAndResources && (outInfo != null)) {
+            outInfo.args = createInstallArgs(packageFlagsToInstallFlags(ps), ps.codePathString,
+                    ps.resourcePathString, ps.nativeLibraryPathString);
+        }
+        return true;
+    }
+
+    /*
+     * This method handles package deletion in general
+     */
+    private boolean deletePackageLI(String packageName, UserHandle user,
+            boolean deleteCodeAndResources, int[] allUserHandles, boolean[] perUserInstalled,
+            int flags, PackageRemovedInfo outInfo,
+            boolean writeSettings) {
+        if (packageName == null) {
+            Slog.w(TAG, "Attempt to delete null packageName.");
+            return false;
+        }
+        if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageLI: " + packageName + " user " + user);
+        PackageSetting ps;
+        boolean dataOnly = false;
+        int removeUser = -1;
+        int appId = -1;
+        synchronized (mPackages) {
+            ps = mSettings.mPackages.get(packageName);
+            if (ps == null) {
+                Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
+                return false;
+            }
+            if ((!isSystemApp(ps) || (flags&PackageManager.DELETE_SYSTEM_APP) != 0) && user != null
+                    && user.getIdentifier() != UserHandle.USER_ALL) {
+                // The caller is asking that the package only be deleted for a single
+                // user.  To do this, we just mark its uninstalled state and delete
+                // its data.  If this is a system app, we only allow this to happen if
+                // they have set the special DELETE_SYSTEM_APP which requests different
+                // semantics than normal for uninstalling system apps.
+                if (DEBUG_REMOVE) Slog.d(TAG, "Only deleting for single user");
+                ps.setUserState(user.getIdentifier(),
+                        COMPONENT_ENABLED_STATE_DEFAULT,
+                        false, //installed
+                        true,  //stopped
+                        true,  //notLaunched
+                        false, //blocked
+                        null, null, null);
+                if (!isSystemApp(ps)) {
+                    if (ps.isAnyInstalled(sUserManager.getUserIds())) {
+                        // Other user still have this package installed, so all
+                        // we need to do is clear this user's data and save that
+                        // it is uninstalled.
+                        if (DEBUG_REMOVE) Slog.d(TAG, "Still installed by other users");
+                        removeUser = user.getIdentifier();
+                        appId = ps.appId;
+                        mSettings.writePackageRestrictionsLPr(removeUser);
+                    } else {
+                        // We need to set it back to 'installed' so the uninstall
+                        // broadcasts will be sent correctly.
+                        if (DEBUG_REMOVE) Slog.d(TAG, "Not installed by other users, full delete");
+                        ps.setInstalled(true, user.getIdentifier());
+                    }
+                } else {
+                    // This is a system app, so we assume that the
+                    // other users still have this package installed, so all
+                    // we need to do is clear this user's data and save that
+                    // it is uninstalled.
+                    if (DEBUG_REMOVE) Slog.d(TAG, "Deleting system app");
+                    removeUser = user.getIdentifier();
+                    appId = ps.appId;
+                    mSettings.writePackageRestrictionsLPr(removeUser);
+                }
+            }
+        }
+
+        if (removeUser >= 0) {
+            // From above, we determined that we are deleting this only
+            // for a single user.  Continue the work here.
+            if (DEBUG_REMOVE) Slog.d(TAG, "Updating install state for user: " + removeUser);
+            if (outInfo != null) {
+                outInfo.removedPackage = packageName;
+                outInfo.removedAppId = appId;
+                outInfo.removedUsers = new int[] {removeUser};
+            }
+            mInstaller.clearUserData(packageName, removeUser);
+            removeKeystoreDataIfNeeded(removeUser, appId);
+            schedulePackageCleaning(packageName, removeUser, false);
+            return true;
+        }
+
+        if (dataOnly) {
+            // Delete application data first
+            if (DEBUG_REMOVE) Slog.d(TAG, "Removing package data only");
+            removePackageDataLI(ps, null, null, outInfo, flags, writeSettings);
+            return true;
+        }
+
+        boolean ret = false;
+        mSettings.mKeySetManager.removeAppKeySetData(packageName);
+        if (isSystemApp(ps)) {
+            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);
+            // Kill application pre-emptively especially for apps on sd.
+            killApplication(packageName, ps.appId, "uninstall pkg");
+            ret = deleteInstalledPackageLI(ps, deleteCodeAndResources, flags,
+                    allUserHandles, perUserInstalled,
+                    outInfo, writeSettings);
+        }
+
+        return ret;
+    }
+
+    private final class ClearStorageConnection implements ServiceConnection {
+        IMediaContainerService mContainerService;
+
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            synchronized (this) {
+                mContainerService = IMediaContainerService.Stub.asInterface(service);
+                notifyAll();
+            }
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+        }
+    }
+
+    private void clearExternalStorageDataSync(String packageName, int userId, boolean allData) {
+        final boolean mounted;
+        if (Environment.isExternalStorageEmulated()) {
+            mounted = true;
+        } else {
+            final String status = Environment.getExternalStorageState();
+
+            mounted = status.equals(Environment.MEDIA_MOUNTED)
+                    || status.equals(Environment.MEDIA_MOUNTED_READ_ONLY);
+        }
+
+        if (!mounted) {
+            return;
+        }
+
+        final Intent containerIntent = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
+        int[] users;
+        if (userId == UserHandle.USER_ALL) {
+            users = sUserManager.getUserIds();
+        } else {
+            users = new int[] { userId };
+        }
+        final ClearStorageConnection conn = new ClearStorageConnection();
+        if (mContext.bindServiceAsUser(
+                containerIntent, conn, Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
+            try {
+                for (int curUser : users) {
+                    long timeout = SystemClock.uptimeMillis() + 5000;
+                    synchronized (conn) {
+                        long now = SystemClock.uptimeMillis();
+                        while (conn.mContainerService == null && now < timeout) {
+                            try {
+                                conn.wait(timeout - now);
+                            } catch (InterruptedException e) {
+                            }
+                        }
+                    }
+                    if (conn.mContainerService == null) {
+                        return;
+                    }
+
+                    final UserEnvironment userEnv = new UserEnvironment(curUser);
+                    clearDirectory(conn.mContainerService,
+                            userEnv.buildExternalStorageAppCacheDirs(packageName));
+                    if (allData) {
+                        clearDirectory(conn.mContainerService,
+                                userEnv.buildExternalStorageAppDataDirs(packageName));
+                        clearDirectory(conn.mContainerService,
+                                userEnv.buildExternalStorageAppMediaDirs(packageName));
+                    }
+                }
+            } finally {
+                mContext.unbindService(conn);
+            }
+        }
+    }
+
+    @Override
+    public void clearApplicationUserData(final String packageName,
+            final IPackageDataObserver observer, final int userId) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.CLEAR_APP_USER_DATA, null);
+        enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "clear application data");
+        // Queue up an async operation since the package deletion may take a little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                mHandler.removeCallbacks(this);
+                final boolean succeeded;
+                synchronized (mInstallLock) {
+                    succeeded = clearApplicationUserDataLI(packageName, userId);
+                }
+                clearExternalStorageDataSync(packageName, userId, true);
+                if (succeeded) {
+                    // invoke DeviceStorageMonitor's update method to clear any notifications
+                    DeviceStorageMonitorInternal
+                            dsm = LocalServices.getService(DeviceStorageMonitorInternal.class);
+                    if (dsm != null) {
+                        dsm.checkMemory();
+                    }
+                }
+                if(observer != null) {
+                    try {
+                        observer.onRemoveCompleted(packageName, succeeded);
+                    } catch (RemoteException e) {
+                        Log.i(TAG, "Observer no longer exists.");
+                    }
+                } //end if observer
+            } //end run
+        });
+    }
+
+    private boolean clearApplicationUserDataLI(String packageName, int userId) {
+        if (packageName == null) {
+            Slog.w(TAG, "Attempt to delete null packageName.");
+            return false;
+        }
+        PackageParser.Package p;
+        boolean dataOnly = false;
+        final int appId;
+        synchronized (mPackages) {
+            p = mPackages.get(packageName);
+            if (p == null) {
+                dataOnly = true;
+                PackageSetting ps = mSettings.mPackages.get(packageName);
+                if ((ps == null) || (ps.pkg == null)) {
+                    Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
+                    return false;
+                }
+                p = ps.pkg;
+            }
+            if (!dataOnly) {
+                // need to check this only for fully installed applications
+                if (p == null) {
+                    Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
+                    return false;
+                }
+                final ApplicationInfo applicationInfo = p.applicationInfo;
+                if (applicationInfo == null) {
+                    Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
+                    return false;
+                }
+            }
+            if (p != null && p.applicationInfo != null) {
+                appId = p.applicationInfo.uid;
+            } else {
+                appId = -1;
+            }
+        }
+        int retCode = mInstaller.clearUserData(packageName, userId);
+        if (retCode < 0) {
+            Slog.w(TAG, "Couldn't remove cache files for package: "
+                    + packageName);
+            return false;
+        }
+        removeKeystoreDataIfNeeded(userId, appId);
+        return true;
+    }
+
+    /**
+     * Remove entries from the keystore daemon. Will only remove it if the
+     * {@code appId} is valid.
+     */
+    private static void removeKeystoreDataIfNeeded(int userId, int appId) {
+        if (appId < 0) {
+            return;
+        }
+
+        final KeyStore keyStore = KeyStore.getInstance();
+        if (keyStore != null) {
+            if (userId == UserHandle.USER_ALL) {
+                for (final int individual : sUserManager.getUserIds()) {
+                    keyStore.clearUid(UserHandle.getUid(individual, appId));
+                }
+            } else {
+                keyStore.clearUid(UserHandle.getUid(userId, appId));
+            }
+        } else {
+            Slog.w(TAG, "Could not contact keystore to clear entries for app id " + appId);
+        }
+    }
+
+    public void deleteApplicationCacheFiles(final String packageName,
+            final IPackageDataObserver observer) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.DELETE_CACHE_FILES, null);
+        // Queue up an async operation since the package deletion may take a little while.
+        final int userId = UserHandle.getCallingUserId();
+        mHandler.post(new Runnable() {
+            public void run() {
+                mHandler.removeCallbacks(this);
+                final boolean succeded;
+                synchronized (mInstallLock) {
+                    succeded = deleteApplicationCacheFilesLI(packageName, userId);
+                }
+                clearExternalStorageDataSync(packageName, userId, false);
+                if(observer != null) {
+                    try {
+                        observer.onRemoveCompleted(packageName, succeded);
+                    } catch (RemoteException e) {
+                        Log.i(TAG, "Observer no longer exists.");
+                    }
+                } //end if observer
+            } //end run
+        });
+    }
+
+    private boolean deleteApplicationCacheFilesLI(String packageName, int userId) {
+        if (packageName == null) {
+            Slog.w(TAG, "Attempt to delete null packageName.");
+            return false;
+        }
+        PackageParser.Package p;
+        synchronized (mPackages) {
+            p = mPackages.get(packageName);
+        }
+        if (p == null) {
+            Slog.w(TAG, "Package named '" + packageName +"' doesn't exist.");
+            return false;
+        }
+        final ApplicationInfo applicationInfo = p.applicationInfo;
+        if (applicationInfo == null) {
+            Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
+            return false;
+        }
+        int retCode = mInstaller.deleteCacheFiles(packageName, userId);
+        if (retCode < 0) {
+            Slog.w(TAG, "Couldn't remove cache files for package: "
+                       + packageName + " u" + userId);
+            return false;
+        }
+        return true;
+    }
+
+    public void getPackageSizeInfo(final String packageName, int userHandle,
+            final IPackageStatsObserver observer) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.GET_PACKAGE_SIZE, null);
+
+        PackageStats stats = new PackageStats(packageName, userHandle);
+
+        /*
+         * Queue up an async operation since the package measurement may take a
+         * little while.
+         */
+        Message msg = mHandler.obtainMessage(INIT_COPY);
+        msg.obj = new MeasureParams(stats, observer);
+        mHandler.sendMessage(msg);
+    }
+
+    private boolean getPackageSizeInfoLI(String packageName, int userHandle,
+            PackageStats pStats) {
+        if (packageName == null) {
+            Slog.w(TAG, "Attempt to get size of null packageName.");
+            return false;
+        }
+        PackageParser.Package p;
+        boolean dataOnly = false;
+        String libDirPath = null;
+        String asecPath = null;
+        synchronized (mPackages) {
+            p = mPackages.get(packageName);
+            PackageSetting ps = mSettings.mPackages.get(packageName);
+            if(p == null) {
+                dataOnly = true;
+                if((ps == null) || (ps.pkg == null)) {
+                    Slog.w(TAG, "Package named '" + packageName +"' doesn't exist.");
+                    return false;
+                }
+                p = ps.pkg;
+            }
+            if (ps != null) {
+                libDirPath = ps.nativeLibraryPathString;
+            }
+            if (p != null && (isExternal(p) || isForwardLocked(p))) {
+                String secureContainerId = cidFromCodePath(p.applicationInfo.sourceDir);
+                if (secureContainerId != null) {
+                    asecPath = PackageHelper.getSdFilesystem(secureContainerId);
+                }
+            }
+        }
+        String publicSrcDir = null;
+        if(!dataOnly) {
+            final ApplicationInfo applicationInfo = p.applicationInfo;
+            if (applicationInfo == null) {
+                Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
+                return false;
+            }
+            if (isForwardLocked(p)) {
+                publicSrcDir = applicationInfo.publicSourceDir;
+            }
+        }
+        int res = mInstaller.getSizeInfo(packageName, userHandle, p.mPath, libDirPath,
+                publicSrcDir, asecPath, pStats);
+        if (res < 0) {
+            return false;
+        }
+
+        // Fix-up for forward-locked applications in ASEC containers.
+        if (!isExternal(p)) {
+            pStats.codeSize += pStats.externalCodeSize;
+            pStats.externalCodeSize = 0L;
+        }
+
+        return true;
+    }
+
+
+    public void addPackageToPreferred(String packageName) {
+        Slog.w(TAG, "addPackageToPreferred: this is now a no-op");
+    }
+
+    public void removePackageFromPreferred(String packageName) {
+        Slog.w(TAG, "removePackageFromPreferred: this is now a no-op");
+    }
+
+    public List<PackageInfo> getPreferredPackages(int flags) {
+        return new ArrayList<PackageInfo>();
+    }
+
+    private int getUidTargetSdkVersionLockedLPr(int uid) {
+        Object obj = mSettings.getUserIdLPr(uid);
+        if (obj instanceof SharedUserSetting) {
+            final SharedUserSetting sus = (SharedUserSetting) obj;
+            int vers = Build.VERSION_CODES.CUR_DEVELOPMENT;
+            final Iterator<PackageSetting> it = sus.packages.iterator();
+            while (it.hasNext()) {
+                final PackageSetting ps = it.next();
+                if (ps.pkg != null) {
+                    int v = ps.pkg.applicationInfo.targetSdkVersion;
+                    if (v < vers) vers = v;
+                }
+            }
+            return vers;
+        } else if (obj instanceof PackageSetting) {
+            final PackageSetting ps = (PackageSetting) obj;
+            if (ps.pkg != null) {
+                return ps.pkg.applicationInfo.targetSdkVersion;
+            }
+        }
+        return Build.VERSION_CODES.CUR_DEVELOPMENT;
+    }
+
+    public void addPreferredActivity(IntentFilter filter, int match,
+            ComponentName[] set, ComponentName activity, int userId) {
+        addPreferredActivityInternal(filter, match, set, activity, true, userId);
+    }
+
+    private void addPreferredActivityInternal(IntentFilter filter, int match,
+            ComponentName[] set, ComponentName activity, boolean always, int userId) {
+        // writer
+        int callingUid = Binder.getCallingUid();
+        enforceCrossUserPermission(callingUid, userId, true, "add preferred activity");
+        if (filter.countActions() == 0) {
+            Slog.w(TAG, "Cannot set a preferred activity with no filter actions");
+            return;
+        }
+        synchronized (mPackages) {
+            if (mContext.checkCallingOrSelfPermission(
+                    android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
+                    != PackageManager.PERMISSION_GRANTED) {
+                if (getUidTargetSdkVersionLockedLPr(callingUid)
+                        < Build.VERSION_CODES.FROYO) {
+                    Slog.w(TAG, "Ignoring addPreferredActivity() from uid "
+                            + callingUid);
+                    return;
+                }
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
+            }
+
+            Slog.i(TAG, "Adding preferred activity " + activity + " for user " + userId + " :");
+            filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
+            mSettings.editPreferredActivitiesLPw(userId).addFilter(
+                    new PreferredActivity(filter, match, set, activity, always));
+            mSettings.writePackageRestrictionsLPr(userId);
+        }
+    }
+
+    public void replacePreferredActivity(IntentFilter filter, int match,
+            ComponentName[] set, ComponentName activity) {
+        if (filter.countActions() != 1) {
+            throw new IllegalArgumentException(
+                    "replacePreferredActivity expects filter to have only 1 action.");
+        }
+        if (filter.countDataAuthorities() != 0
+                || filter.countDataPaths() != 0
+                || filter.countDataSchemes() > 1
+                || filter.countDataTypes() != 0) {
+            throw new IllegalArgumentException(
+                    "replacePreferredActivity expects filter to have no data authorities, " +
+                    "paths, or types; and at most one scheme.");
+        }
+        synchronized (mPackages) {
+            if (mContext.checkCallingOrSelfPermission(
+                    android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
+                    != PackageManager.PERMISSION_GRANTED) {
+                if (getUidTargetSdkVersionLockedLPr(Binder.getCallingUid())
+                        < Build.VERSION_CODES.FROYO) {
+                    Slog.w(TAG, "Ignoring replacePreferredActivity() from uid "
+                            + Binder.getCallingUid());
+                    return;
+                }
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
+            }
+
+            final int callingUserId = UserHandle.getCallingUserId();
+            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(callingUserId);
+            if (pir != null) {
+                Intent intent = new Intent(filter.getAction(0)).addCategory(filter.getCategory(0));
+                if (filter.countDataSchemes() == 1) {
+                    Uri.Builder builder = new Uri.Builder();
+                    builder.scheme(filter.getDataScheme(0));
+                    intent.setData(builder.build());
+                }
+                List<PreferredActivity> matches = pir.queryIntent(
+                        intent, null, true, callingUserId);
+                if (DEBUG_PREFERRED) {
+                    Slog.i(TAG, matches.size() + " preferred matches for " + intent);
+                }
+                for (int i = 0; i < matches.size(); i++) {
+                    PreferredActivity pa = matches.get(i);
+                    if (DEBUG_PREFERRED) {
+                        Slog.i(TAG, "Removing preferred activity "
+                                + pa.mPref.mComponent + ":");
+                        filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
+                    }
+                    pir.removeFilter(pa);
+                }
+            }
+            addPreferredActivityInternal(filter, match, set, activity, true, callingUserId);
+        }
+    }
+
+    public void clearPackagePreferredActivities(String packageName) {
+        final int uid = Binder.getCallingUid();
+        // writer
+        synchronized (mPackages) {
+            PackageParser.Package pkg = mPackages.get(packageName);
+            if (pkg == null || pkg.applicationInfo.uid != uid) {
+                if (mContext.checkCallingOrSelfPermission(
+                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    if (getUidTargetSdkVersionLockedLPr(Binder.getCallingUid())
+                            < Build.VERSION_CODES.FROYO) {
+                        Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid "
+                                + Binder.getCallingUid());
+                        return;
+                    }
+                    mContext.enforceCallingOrSelfPermission(
+                            android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
+                }
+            }
+
+            int user = UserHandle.getCallingUserId();
+            if (clearPackagePreferredActivitiesLPw(packageName, user)) {
+                mSettings.writePackageRestrictionsLPr(user);
+                scheduleWriteSettingsLocked();
+            }
+        }
+    }
+
+    /** This method takes a specific user id as well as UserHandle.USER_ALL. */
+    boolean clearPackagePreferredActivitiesLPw(String packageName, int userId) {
+        ArrayList<PreferredActivity> removed = null;
+        boolean changed = false;
+        for (int i=0; i<mSettings.mPreferredActivities.size(); i++) {
+            final int thisUserId = mSettings.mPreferredActivities.keyAt(i);
+            PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
+            if (userId != UserHandle.USER_ALL && userId != thisUserId) {
+                continue;
+            }
+            Iterator<PreferredActivity> it = pir.filterIterator();
+            while (it.hasNext()) {
+                PreferredActivity pa = it.next();
+                // Mark entry for removal only if it matches the package name
+                // and the entry is of type "always".
+                if (packageName == null ||
+                        (pa.mPref.mComponent.getPackageName().equals(packageName)
+                                && pa.mPref.mAlways)) {
+                    if (removed == null) {
+                        removed = new ArrayList<PreferredActivity>();
+                    }
+                    removed.add(pa);
+                }
+            }
+            if (removed != null) {
+                for (int j=0; j<removed.size(); j++) {
+                    PreferredActivity pa = removed.get(j);
+                    pir.removeFilter(pa);
+                }
+                changed = true;
+            }
+        }
+        return changed;
+    }
+
+    public void resetPreferredActivities(int userId) {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
+        // writer
+        synchronized (mPackages) {
+            int user = UserHandle.getCallingUserId();
+            clearPackagePreferredActivitiesLPw(null, user);
+            mSettings.readDefaultPreferredAppsLPw(this, user);
+            mSettings.writePackageRestrictionsLPr(user);
+            scheduleWriteSettingsLocked();
+        }
+    }
+
+    public int getPreferredActivities(List<IntentFilter> outFilters,
+            List<ComponentName> outActivities, String packageName) {
+
+        int num = 0;
+        final int userId = UserHandle.getCallingUserId();
+        // reader
+        synchronized (mPackages) {
+            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
+            if (pir != null) {
+                final Iterator<PreferredActivity> it = pir.filterIterator();
+                while (it.hasNext()) {
+                    final PreferredActivity pa = it.next();
+                    if (packageName == null
+                            || (pa.mPref.mComponent.getPackageName().equals(packageName)
+                                    && pa.mPref.mAlways)) {
+                        if (outFilters != null) {
+                            outFilters.add(new IntentFilter(pa));
+                        }
+                        if (outActivities != null) {
+                            outActivities.add(pa.mPref.mComponent);
+                        }
+                    }
+                }
+            }
+        }
+
+        return num;
+    }
+
+    @Override
+    public ComponentName getHomeActivities(List<ResolveInfo> allHomeCandidates) {
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.addCategory(Intent.CATEGORY_HOME);
+
+        final int callingUserId = UserHandle.getCallingUserId();
+        List<ResolveInfo> list = queryIntentActivities(intent, null,
+                PackageManager.GET_META_DATA, callingUserId);
+        ResolveInfo preferred = findPreferredActivity(intent, null, 0, list, 0,
+                true, false, false, callingUserId);
+
+        allHomeCandidates.clear();
+        if (list != null) {
+            for (ResolveInfo ri : list) {
+                allHomeCandidates.add(ri);
+            }
+        }
+        return (preferred == null || preferred.activityInfo == null)
+                ? null
+                : new ComponentName(preferred.activityInfo.packageName,
+                        preferred.activityInfo.name);
+    }
+
+    @Override
+    public void setApplicationEnabledSetting(String appPackageName,
+            int newState, int flags, int userId, String callingPackage) {
+        if (!sUserManager.exists(userId)) return;
+        if (callingPackage == null) {
+            callingPackage = Integer.toString(Binder.getCallingUid());
+        }
+        setEnabledSetting(appPackageName, null, newState, flags, userId, callingPackage);
+    }
+
+    @Override
+    public void setComponentEnabledSetting(ComponentName componentName,
+            int newState, int flags, int userId) {
+        if (!sUserManager.exists(userId)) return;
+        setEnabledSetting(componentName.getPackageName(),
+                componentName.getClassName(), newState, flags, userId, null);
+    }
+
+    private void setEnabledSetting(final String packageName, String className, int newState,
+            final int flags, int userId, String callingPackage) {
+        if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT
+              || newState == COMPONENT_ENABLED_STATE_ENABLED
+              || newState == COMPONENT_ENABLED_STATE_DISABLED
+              || newState == COMPONENT_ENABLED_STATE_DISABLED_USER
+              || newState == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
+            throw new IllegalArgumentException("Invalid new component state: "
+                    + newState);
+        }
+        PackageSetting pkgSetting;
+        final int uid = Binder.getCallingUid();
+        final int permission = mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);
+        enforceCrossUserPermission(uid, userId, false, "set enabled");
+        final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED);
+        boolean sendNow = false;
+        boolean isApp = (className == null);
+        String componentName = isApp ? packageName : className;
+        int packageUid = -1;
+        ArrayList<String> components;
+
+        // writer
+        synchronized (mPackages) {
+            pkgSetting = mSettings.mPackages.get(packageName);
+            if (pkgSetting == null) {
+                if (className == null) {
+                    throw new IllegalArgumentException(
+                            "Unknown package: " + packageName);
+                }
+                throw new IllegalArgumentException(
+                        "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)) {
+                throw new SecurityException(
+                        "Permission Denial: attempt to change component state from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + uid + ", package uid=" + pkgSetting.appId);
+            }
+            if (className == null) {
+                // We're dealing with an application/package level state change
+                if (pkgSetting.getEnabled(userId) == newState) {
+                    // Nothing to do
+                    return;
+                }
+                if (newState == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
+                    || newState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
+                    // Don't care about who enables an app.
+                    callingPackage = null;
+                }
+                pkgSetting.setEnabled(newState, userId, callingPackage);
+                // pkgSetting.pkg.mSetEnabled = newState;
+            } else {
+                // We're dealing with a component level state change
+                // First, verify that this is a valid class name.
+                PackageParser.Package pkg = pkgSetting.pkg;
+                if (pkg == null || !pkg.hasComponentClassName(className)) {
+                    if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.JELLY_BEAN) {
+                        throw new IllegalArgumentException("Component class " + className
+                                + " does not exist in " + packageName);
+                    } else {
+                        Slog.w(TAG, "Failed setComponentEnabledSetting: component class "
+                                + className + " does not exist in " + packageName);
+                    }
+                }
+                switch (newState) {
+                case COMPONENT_ENABLED_STATE_ENABLED:
+                    if (!pkgSetting.enableComponentLPw(className, userId)) {
+                        return;
+                    }
+                    break;
+                case COMPONENT_ENABLED_STATE_DISABLED:
+                    if (!pkgSetting.disableComponentLPw(className, userId)) {
+                        return;
+                    }
+                    break;
+                case COMPONENT_ENABLED_STATE_DEFAULT:
+                    if (!pkgSetting.restoreComponentLPw(className, userId)) {
+                        return;
+                    }
+                    break;
+                default:
+                    Slog.e(TAG, "Invalid new component state: " + newState);
+                    return;
+                }
+            }
+            mSettings.writePackageRestrictionsLPr(userId);
+            components = mPendingBroadcasts.get(userId, packageName);
+            final boolean newPackage = components == null;
+            if (newPackage) {
+                components = new ArrayList<String>();
+            }
+            if (!components.contains(componentName)) {
+                components.add(componentName);
+            }
+            if ((flags&PackageManager.DONT_KILL_APP) == 0) {
+                sendNow = true;
+                // Purge entry from pending broadcast list if another one exists already
+                // since we are sending one right away.
+                mPendingBroadcasts.remove(userId, packageName);
+            } else {
+                if (newPackage) {
+                    mPendingBroadcasts.put(userId, packageName, components);
+                }
+                if (!mHandler.hasMessages(SEND_PENDING_BROADCAST)) {
+                    // Schedule a message
+                    mHandler.sendEmptyMessageDelayed(SEND_PENDING_BROADCAST, BROADCAST_DELAY);
+                }
+            }
+        }
+
+        long callingId = Binder.clearCallingIdentity();
+        try {
+            if (sendNow) {
+                packageUid = UserHandle.getUid(userId, pkgSetting.appId);
+                sendPackageChangedBroadcast(packageName,
+                        (flags&PackageManager.DONT_KILL_APP) != 0, components, packageUid);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingId);
+        }
+    }
+
+    private void sendPackageChangedBroadcast(String packageName,
+            boolean killFlag, ArrayList<String> componentNames, int packageUid) {
+        if (DEBUG_INSTALL)
+            Log.v(TAG, "Sending package changed: package=" + packageName + " components="
+                    + componentNames);
+        Bundle extras = new Bundle(4);
+        extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0));
+        String nameList[] = new String[componentNames.size()];
+        componentNames.toArray(nameList);
+        extras.putStringArray(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST, nameList);
+        extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, killFlag);
+        extras.putInt(Intent.EXTRA_UID, packageUid);
+        sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED,  packageName, extras, null, null,
+                new int[] {UserHandle.getUserId(packageUid)});
+    }
+
+    public void setPackageStoppedState(String packageName, boolean stopped, int userId) {
+        if (!sUserManager.exists(userId)) return;
+        final int uid = Binder.getCallingUid();
+        final int permission = mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);
+        final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED);
+        enforceCrossUserPermission(uid, userId, true, "stop package");
+        // writer
+        synchronized (mPackages) {
+            if (mSettings.setPackageStoppedStateLPw(packageName, stopped, allowedByPermission,
+                    uid, userId)) {
+                scheduleWritePackageRestrictionsLocked(userId);
+            }
+        }
+    }
+
+    public String getInstallerPackageName(String packageName) {
+        // reader
+        synchronized (mPackages) {
+            return mSettings.getInstallerPackageNameLPr(packageName);
+        }
+    }
+
+    @Override
+    public int getApplicationEnabledSetting(String packageName, int userId) {
+        if (!sUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
+        int uid = Binder.getCallingUid();
+        enforceCrossUserPermission(uid, userId, false, "get enabled");
+        // reader
+        synchronized (mPackages) {
+            return mSettings.getApplicationEnabledSettingLPr(packageName, userId);
+        }
+    }
+
+    @Override
+    public int getComponentEnabledSetting(ComponentName componentName, int userId) {
+        if (!sUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
+        int uid = Binder.getCallingUid();
+        enforceCrossUserPermission(uid, userId, false, "get component enabled");
+        // reader
+        synchronized (mPackages) {
+            return mSettings.getComponentEnabledSettingLPr(componentName, userId);
+        }
+    }
+
+    public void enterSafeMode() {
+        enforceSystemOrRoot("Only the system can request entering safe mode");
+
+        if (!mSystemReady) {
+            mSafeMode = true;
+        }
+    }
+
+    public void systemReady() {
+        mSystemReady = true;
+
+        // Read the compatibilty setting when the system is ready.
+        boolean compatibilityModeEnabled = android.provider.Settings.Global.getInt(
+                mContext.getContentResolver(),
+                android.provider.Settings.Global.COMPATIBILITY_MODE, 1) == 1;
+        PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled);
+        if (DEBUG_SETTINGS) {
+            Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled);
+        }
+
+        synchronized (mPackages) {
+            // Verify that all of the preferred activity components actually
+            // exist.  It is possible for applications to be updated and at
+            // that point remove a previously declared activity component that
+            // had been set as a preferred activity.  We try to clean this up
+            // the next time we encounter that preferred activity, but it is
+            // possible for the user flow to never be able to return to that
+            // situation so here we do a sanity check to make sure we haven't
+            // left any junk around.
+            ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>();
+            for (int i=0; i<mSettings.mPreferredActivities.size(); i++) {
+                PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
+                removed.clear();
+                for (PreferredActivity pa : pir.filterSet()) {
+                    if (mActivities.mActivities.get(pa.mPref.mComponent) == null) {
+                        removed.add(pa);
+                    }
+                }
+                if (removed.size() > 0) {
+                    for (int j=0; j<removed.size(); j++) {
+                        PreferredActivity pa = removed.get(i);
+                        Slog.w(TAG, "Removing dangling preferred activity: "
+                                + pa.mPref.mComponent);
+                        pir.removeFilter(pa);
+                    }
+                    mSettings.writePackageRestrictionsLPr(
+                            mSettings.mPreferredActivities.keyAt(i));
+                }
+            }
+        }
+        sUserManager.systemReady();
+    }
+
+    public boolean isSafeMode() {
+        return mSafeMode;
+    }
+
+    public boolean hasSystemUidErrors() {
+        return mHasSystemUidErrors;
+    }
+
+    static String arrayToString(int[] array) {
+        StringBuffer buf = new StringBuffer(128);
+        buf.append('[');
+        if (array != null) {
+            for (int i=0; i<array.length; i++) {
+                if (i > 0) buf.append(", ");
+                buf.append(array[i]);
+            }
+        }
+        buf.append(']');
+        return buf.toString();
+    }
+
+    static class DumpState {
+        public static final int DUMP_LIBS = 1 << 0;
+
+        public static final int DUMP_FEATURES = 1 << 1;
+
+        public static final int DUMP_RESOLVERS = 1 << 2;
+
+        public static final int DUMP_PERMISSIONS = 1 << 3;
+
+        public static final int DUMP_PACKAGES = 1 << 4;
+
+        public static final int DUMP_SHARED_USERS = 1 << 5;
+
+        public static final int DUMP_MESSAGES = 1 << 6;
+
+        public static final int DUMP_PROVIDERS = 1 << 7;
+
+        public static final int DUMP_VERIFIERS = 1 << 8;
+
+        public static final int DUMP_PREFERRED = 1 << 9;
+
+        public static final int DUMP_PREFERRED_XML = 1 << 10;
+
+        public static final int DUMP_KEYSETS = 1 << 11;
+
+        public static final int OPTION_SHOW_FILTERS = 1 << 0;
+
+        private int mTypes;
+
+        private int mOptions;
+
+        private boolean mTitlePrinted;
+
+        private SharedUserSetting mSharedUser;
+
+        public boolean isDumping(int type) {
+            if (mTypes == 0 && type != DUMP_PREFERRED_XML) {
+                return true;
+            }
+
+            return (mTypes & type) != 0;
+        }
+
+        public void setDump(int type) {
+            mTypes |= type;
+        }
+
+        public boolean isOptionEnabled(int option) {
+            return (mOptions & option) != 0;
+        }
+
+        public void setOptionEnabled(int option) {
+            mOptions |= option;
+        }
+
+        public boolean onTitlePrinted() {
+            final boolean printed = mTitlePrinted;
+            mTitlePrinted = true;
+            return printed;
+        }
+
+        public boolean getTitlePrinted() {
+            return mTitlePrinted;
+        }
+
+        public void setTitlePrinted(boolean enabled) {
+            mTitlePrinted = enabled;
+        }
+
+        public SharedUserSetting getSharedUser() {
+            return mSharedUser;
+        }
+
+        public void setSharedUser(SharedUserSetting user) {
+            mSharedUser = user;
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump ActivityManager from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid()
+                    + " without permission "
+                    + android.Manifest.permission.DUMP);
+            return;
+        }
+
+        DumpState dumpState = new DumpState();
+        boolean fullPreferred = false;
+        boolean checkin = false;
+
+        String packageName = null;
+        
+        int opti = 0;
+        while (opti < args.length) {
+            String opt = args[opti];
+            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
+                break;
+            }
+            opti++;
+            if ("-a".equals(opt)) {
+                // Right now we only know how to print all.
+            } else if ("-h".equals(opt)) {
+                pw.println("Package manager dump options:");
+                pw.println("  [-h] [-f] [--checkin] [cmd] ...");
+                pw.println("    --checkin: dump for a checkin");
+                pw.println("    -f: print details of intent filters");
+                pw.println("    -h: print this help");
+                pw.println("  cmd may be one of:");
+                pw.println("    l[ibraries]: list known shared libraries");
+                pw.println("    f[ibraries]: list device features");
+                pw.println("    r[esolvers]: dump intent resolvers");
+                pw.println("    perm[issions]: dump permissions");
+                pw.println("    pref[erred]: print preferred package settings");
+                pw.println("    preferred-xml [--full]: print preferred package settings as xml");
+                pw.println("    prov[iders]: dump content providers");
+                pw.println("    p[ackages]: dump installed packages");
+                pw.println("    s[hared-users]: dump shared user IDs");
+                pw.println("    m[essages]: print collected runtime messages");
+                pw.println("    v[erifiers]: print package verifier info");
+                pw.println("    <package.name>: info about given package");
+                pw.println("    k[eysets]: print known keysets");
+                return;
+            } else if ("--checkin".equals(opt)) {
+                checkin = true;
+            } else if ("-f".equals(opt)) {
+                dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
+            } else {
+                pw.println("Unknown argument: " + opt + "; use -h for help");
+            }
+        }
+
+        // Is the caller requesting to dump a particular piece of data?
+        if (opti < args.length) {
+            String cmd = args[opti];
+            opti++;
+            // Is this a package name?
+            if ("android".equals(cmd) || cmd.contains(".")) {
+                packageName = cmd;
+                // When dumping a single package, we always dump all of its
+                // filter information since the amount of data will be reasonable.
+                dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
+            } else if ("l".equals(cmd) || "libraries".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_LIBS);
+            } else if ("f".equals(cmd) || "features".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_FEATURES);
+            } else if ("r".equals(cmd) || "resolvers".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_RESOLVERS);
+            } else if ("perm".equals(cmd) || "permissions".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_PERMISSIONS);
+            } else if ("pref".equals(cmd) || "preferred".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_PREFERRED);
+            } else if ("preferred-xml".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_PREFERRED_XML);
+                if (opti < args.length && "--full".equals(args[opti])) {
+                    fullPreferred = true;
+                    opti++;
+                }
+            } else if ("p".equals(cmd) || "packages".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_PACKAGES);
+            } else if ("s".equals(cmd) || "shared-users".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_SHARED_USERS);
+            } else if ("prov".equals(cmd) || "providers".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_PROVIDERS);
+            } else if ("m".equals(cmd) || "messages".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_MESSAGES);
+            } else if ("v".equals(cmd) || "verifiers".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_VERIFIERS);
+            } else if ("k".equals(cmd) || "keysets".equals(cmd)) {
+                dumpState.setDump(DumpState.DUMP_KEYSETS);
+            }
+        }
+
+        if (checkin) {
+            pw.println("vers,1");
+        }
+
+        // reader
+        synchronized (mPackages) {
+            if (dumpState.isDumping(DumpState.DUMP_VERIFIERS) && packageName == null) {
+                if (!checkin) {
+                    if (dumpState.onTitlePrinted())
+                        pw.println();
+                    pw.println("Verifiers:");
+                    pw.print("  Required: ");
+                    pw.print(mRequiredVerifierPackage);
+                    pw.print(" (uid=");
+                    pw.print(getPackageUid(mRequiredVerifierPackage, 0));
+                    pw.println(")");
+                } else if (mRequiredVerifierPackage != null) {
+                    pw.print("vrfy,"); pw.print(mRequiredVerifierPackage);
+                    pw.print(","); pw.println(getPackageUid(mRequiredVerifierPackage, 0));
+                }
+            }
+
+            if (dumpState.isDumping(DumpState.DUMP_LIBS) && packageName == null) {
+                boolean printedHeader = false;
+                final Iterator<String> it = mSharedLibraries.keySet().iterator();
+                while (it.hasNext()) {
+                    String name = it.next();
+                    SharedLibraryEntry ent = mSharedLibraries.get(name);
+                    if (!checkin) {
+                        if (!printedHeader) {
+                            if (dumpState.onTitlePrinted())
+                                pw.println();
+                            pw.println("Libraries:");
+                            printedHeader = true;
+                        }
+                        pw.print("  ");
+                    } else {
+                        pw.print("lib,");
+                    }
+                    pw.print(name);
+                    if (!checkin) {
+                        pw.print(" -> ");
+                    }
+                    if (ent.path != null) {
+                        if (!checkin) {
+                            pw.print("(jar) ");
+                            pw.print(ent.path);
+                        } else {
+                            pw.print(",jar,");
+                            pw.print(ent.path);
+                        }
+                    } else {
+                        if (!checkin) {
+                            pw.print("(apk) ");
+                            pw.print(ent.apk);
+                        } else {
+                            pw.print(",apk,");
+                            pw.print(ent.apk);
+                        }
+                    }
+                    pw.println();
+                }
+            }
+
+            if (dumpState.isDumping(DumpState.DUMP_FEATURES) && packageName == null) {
+                if (dumpState.onTitlePrinted())
+                    pw.println();
+                if (!checkin) {
+                    pw.println("Features:");
+                }
+                Iterator<String> it = mAvailableFeatures.keySet().iterator();
+                while (it.hasNext()) {
+                    String name = it.next();
+                    if (!checkin) {
+                        pw.print("  ");
+                    } else {
+                        pw.print("feat,");
+                    }
+                    pw.println(name);
+                }
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_RESOLVERS)) {
+                if (mActivities.dump(pw, dumpState.getTitlePrinted() ? "\nActivity Resolver Table:"
+                        : "Activity Resolver Table:", "  ", packageName,
+                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
+                    dumpState.setTitlePrinted(true);
+                }
+                if (mReceivers.dump(pw, dumpState.getTitlePrinted() ? "\nReceiver Resolver Table:"
+                        : "Receiver Resolver Table:", "  ", packageName,
+                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
+                    dumpState.setTitlePrinted(true);
+                }
+                if (mServices.dump(pw, dumpState.getTitlePrinted() ? "\nService Resolver Table:"
+                        : "Service Resolver Table:", "  ", packageName,
+                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
+                    dumpState.setTitlePrinted(true);
+                }
+                if (mProviders.dump(pw, dumpState.getTitlePrinted() ? "\nProvider Resolver Table:"
+                        : "Provider Resolver Table:", "  ", packageName,
+                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
+                    dumpState.setTitlePrinted(true);
+                }
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED)) {
+                for (int i=0; i<mSettings.mPreferredActivities.size(); i++) {
+                    PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
+                    int user = mSettings.mPreferredActivities.keyAt(i);
+                    if (pir.dump(pw,
+                            dumpState.getTitlePrinted()
+                                ? "\nPreferred Activities User " + user + ":"
+                                : "Preferred Activities User " + user + ":", "  ",
+                            packageName, true)) {
+                        dumpState.setTitlePrinted(true);
+                    }
+                }
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED_XML)) {
+                pw.flush();
+                FileOutputStream fout = new FileOutputStream(fd);
+                BufferedOutputStream str = new BufferedOutputStream(fout);
+                XmlSerializer serializer = new FastXmlSerializer();
+                try {
+                    serializer.setOutput(str, "utf-8");
+                    serializer.startDocument(null, true);
+                    serializer.setFeature(
+                            "http://xmlpull.org/v1/doc/features.html#indent-output", true);
+                    mSettings.writePreferredActivitiesLPr(serializer, 0, fullPreferred);
+                    serializer.endDocument();
+                    serializer.flush();
+                } catch (IllegalArgumentException e) {
+                    pw.println("Failed writing: " + e);
+                } catch (IllegalStateException e) {
+                    pw.println("Failed writing: " + e);
+                } catch (IOException e) {
+                    pw.println("Failed writing: " + e);
+                }
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_PERMISSIONS)) {
+                mSettings.dumpPermissionsLPr(pw, packageName, dumpState);
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_PROVIDERS)) {
+                boolean printedSomething = false;
+                for (PackageParser.Provider p : mProviders.mProviders.values()) {
+                    if (packageName != null && !packageName.equals(p.info.packageName)) {
+                        continue;
+                    }
+                    if (!printedSomething) {
+                        if (dumpState.onTitlePrinted())
+                            pw.println();
+                        pw.println("Registered ContentProviders:");
+                        printedSomething = true;
+                    }
+                    pw.print("  "); p.printComponentShortName(pw); pw.println(":");
+                    pw.print("    "); pw.println(p.toString());
+                }
+                printedSomething = false;
+                for (Map.Entry<String, PackageParser.Provider> entry :
+                        mProvidersByAuthority.entrySet()) {
+                    PackageParser.Provider p = entry.getValue();
+                    if (packageName != null && !packageName.equals(p.info.packageName)) {
+                        continue;
+                    }
+                    if (!printedSomething) {
+                        if (dumpState.onTitlePrinted())
+                            pw.println();
+                        pw.println("ContentProvider Authorities:");
+                        printedSomething = true;
+                    }
+                    pw.print("  ["); pw.print(entry.getKey()); pw.println("]:");
+                    pw.print("    "); pw.println(p.toString());
+                    if (p.info != null && p.info.applicationInfo != null) {
+                        final String appInfo = p.info.applicationInfo.toString();
+                        pw.print("      applicationInfo="); pw.println(appInfo);
+                    }
+                }
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_KEYSETS)) {
+                mSettings.mKeySetManager.dump(pw, packageName, dumpState);
+            }
+
+            if (dumpState.isDumping(DumpState.DUMP_PACKAGES)) {
+                mSettings.dumpPackagesLPr(pw, packageName, dumpState, checkin);
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_SHARED_USERS)) {
+                mSettings.dumpSharedUsersLPr(pw, packageName, dumpState);
+            }
+
+            if (!checkin && dumpState.isDumping(DumpState.DUMP_MESSAGES) && packageName == null) {
+                if (dumpState.onTitlePrinted())
+                    pw.println();
+                mSettings.dumpReadMessagesLPr(pw, dumpState);
+
+                pw.println();
+                pw.println("Package warning messages:");
+                final File fname = getSettingsProblemFile();
+                FileInputStream in = null;
+                try {
+                    in = new FileInputStream(fname);
+                    final int avail = in.available();
+                    final byte[] data = new byte[avail];
+                    in.read(data);
+                    pw.print(new String(data));
+                } catch (FileNotFoundException e) {
+                } catch (IOException e) {
+                } finally {
+                    if (in != null) {
+                        try {
+                            in.close();
+                        } catch (IOException e) {
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // ------- apps on sdcard specific code -------
+    static final boolean DEBUG_SD_INSTALL = false;
+
+    private static final String SD_ENCRYPTION_KEYSTORE_NAME = "AppsOnSD";
+
+    private static final String SD_ENCRYPTION_ALGORITHM = "AES";
+
+    private boolean mMediaMounted = false;
+
+    private String getEncryptKey() {
+        try {
+            String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(
+                    SD_ENCRYPTION_KEYSTORE_NAME);
+            if (sdEncKey == null) {
+                sdEncKey = SystemKeyStore.getInstance().generateNewKeyHexString(128,
+                        SD_ENCRYPTION_ALGORITHM, SD_ENCRYPTION_KEYSTORE_NAME);
+                if (sdEncKey == null) {
+                    Slog.e(TAG, "Failed to create encryption keys");
+                    return null;
+                }
+            }
+            return sdEncKey;
+        } catch (NoSuchAlgorithmException nsae) {
+            Slog.e(TAG, "Failed to create encryption keys with exception: " + nsae);
+            return null;
+        } catch (IOException ioe) {
+            Slog.e(TAG, "Failed to retrieve encryption keys with exception: " + ioe);
+            return null;
+        }
+
+    }
+
+    /* package */static String getTempContainerId() {
+        int tmpIdx = 1;
+        String list[] = PackageHelper.getSecureContainerList();
+        if (list != null) {
+            for (final String name : list) {
+                // Ignore null and non-temporary container entries
+                if (name == null || !name.startsWith(mTempContainerPrefix)) {
+                    continue;
+                }
+
+                String subStr = name.substring(mTempContainerPrefix.length());
+                try {
+                    int cid = Integer.parseInt(subStr);
+                    if (cid >= tmpIdx) {
+                        tmpIdx = cid + 1;
+                    }
+                } catch (NumberFormatException e) {
+                }
+            }
+        }
+        return mTempContainerPrefix + tmpIdx;
+    }
+
+    /*
+     * Update media status on PackageManager.
+     */
+    public void updateExternalMediaStatus(final boolean mediaStatus, final boolean reportStatus) {
+        int callingUid = Binder.getCallingUid();
+        if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
+            throw new SecurityException("Media status can only be updated by the system");
+        }
+        // reader; this apparently protects mMediaMounted, but should probably
+        // be a different lock in that case.
+        synchronized (mPackages) {
+            Log.i(TAG, "Updating external media status from "
+                    + (mMediaMounted ? "mounted" : "unmounted") + " to "
+                    + (mediaStatus ? "mounted" : "unmounted"));
+            if (DEBUG_SD_INSTALL)
+                Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" + mediaStatus
+                        + ", mMediaMounted=" + mMediaMounted);
+            if (mediaStatus == mMediaMounted) {
+                final Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, reportStatus ? 1
+                        : 0, -1);
+                mHandler.sendMessage(msg);
+                return;
+            }
+            mMediaMounted = mediaStatus;
+        }
+        // Queue up an async operation since the package installation may take a
+        // little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                updateExternalMediaStatusInner(mediaStatus, reportStatus, true);
+            }
+        });
+    }
+
+    /**
+     * Called by MountService when the initial ASECs to scan are available.
+     * Should block until all the ASEC containers are finished being scanned.
+     */
+    public void scanAvailableAsecs() {
+        updateExternalMediaStatusInner(true, false, false);
+    }
+
+    /*
+     * Collect information of applications on external media, map them against
+     * existing containers and update information based on current mount status.
+     * Please note that we always have to report status if reportStatus has been
+     * set to true especially when unloading packages.
+     */
+    private void updateExternalMediaStatusInner(boolean isMounted, boolean reportStatus,
+            boolean externalStorage) {
+        // Collection of uids
+        int uidArr[] = null;
+        // Collection of stale containers
+        HashSet<String> removeCids = new HashSet<String>();
+        // Collection of packages on external media with valid containers.
+        HashMap<AsecInstallArgs, String> processCids = new HashMap<AsecInstallArgs, String>();
+        // Get list of secure containers.
+        final String list[] = PackageHelper.getSecureContainerList();
+        if (list == null || list.length == 0) {
+            Log.i(TAG, "No secure containers on sdcard");
+        } else {
+            // Process list of secure containers and categorize them
+            // as active or stale based on their package internal state.
+            int uidList[] = new int[list.length];
+            int num = 0;
+            // reader
+            synchronized (mPackages) {
+                for (String cid : list) {
+                    if (DEBUG_SD_INSTALL)
+                        Log.i(TAG, "Processing container " + cid);
+                    String pkgName = getAsecPackageName(cid);
+                    if (pkgName == null) {
+                        if (DEBUG_SD_INSTALL)
+                            Log.i(TAG, "Container : " + cid + " stale");
+                        removeCids.add(cid);
+                        continue;
+                    }
+                    if (DEBUG_SD_INSTALL)
+                        Log.i(TAG, "Looking for pkg : " + pkgName);
+
+                    final PackageSetting ps = mSettings.mPackages.get(pkgName);
+                    if (ps == null) {
+                        Log.i(TAG, "Deleting container with no matching settings " + cid);
+                        removeCids.add(cid);
+                        continue;
+                    }
+
+                    /*
+                     * Skip packages that are not external if we're unmounting
+                     * external storage.
+                     */
+                    if (externalStorage && !isMounted && !isExternal(ps)) {
+                        continue;
+                    }
+
+                    final AsecInstallArgs args = new AsecInstallArgs(cid, isForwardLocked(ps));
+                    // The package status is changed only if the code path
+                    // matches between settings and the container id.
+                    if (ps.codePathString != null && ps.codePathString.equals(args.getCodePath())) {
+                        if (DEBUG_SD_INSTALL) {
+                            Log.i(TAG, "Container : " + cid + " corresponds to pkg : " + pkgName
+                                    + " at code path: " + ps.codePathString);
+                        }
+
+                        // We do have a valid package installed on sdcard
+                        processCids.put(args, ps.codePathString);
+                        final int uid = ps.appId;
+                        if (uid != -1) {
+                            uidList[num++] = uid;
+                        }
+                    } else {
+                        Log.i(TAG, "Deleting stale container for " + cid);
+                        removeCids.add(cid);
+                    }
+                }
+            }
+
+            if (num > 0) {
+                // Sort uid list
+                Arrays.sort(uidList, 0, num);
+                // Throw away duplicates
+                uidArr = new int[num];
+                uidArr[0] = uidList[0];
+                int di = 0;
+                for (int i = 1; i < num; i++) {
+                    if (uidList[i - 1] != uidList[i]) {
+                        uidArr[di++] = uidList[i];
+                    }
+                }
+            }
+        }
+        // Process packages with valid entries.
+        if (isMounted) {
+            if (DEBUG_SD_INSTALL)
+                Log.i(TAG, "Loading packages");
+            loadMediaPackages(processCids, uidArr, removeCids);
+            startCleaningPackages();
+        } else {
+            if (DEBUG_SD_INSTALL)
+                Log.i(TAG, "Unloading packages");
+            unloadMediaPackages(processCids, uidArr, reportStatus);
+        }
+    }
+
+   private void sendResourcesChangedBroadcast(boolean mediaStatus, boolean replacing,
+           ArrayList<String> pkgList, int uidArr[], IIntentReceiver finishedReceiver) {
+        int size = pkgList.size();
+        if (size > 0) {
+            // Send broadcasts here
+            Bundle extras = new Bundle();
+            extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, pkgList
+                    .toArray(new String[size]));
+            if (uidArr != null) {
+                extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidArr);
+            }
+            if (replacing) {
+                extras.putBoolean(Intent.EXTRA_REPLACING, replacing);
+            }
+            String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
+                    : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE;
+            sendPackageBroadcast(action, null, extras, null, finishedReceiver, null);
+        }
+    }
+
+   /*
+     * Look at potentially valid container ids from processCids If package
+     * information doesn't match the one on record or package scanning fails,
+     * the cid is added to list of removeCids. We currently don't delete stale
+     * containers.
+     */
+   private void loadMediaPackages(HashMap<AsecInstallArgs, String> processCids, int uidArr[],
+            HashSet<String> removeCids) {
+        ArrayList<String> pkgList = new ArrayList<String>();
+        Set<AsecInstallArgs> keys = processCids.keySet();
+        boolean doGc = false;
+        for (AsecInstallArgs args : keys) {
+            String codePath = processCids.get(args);
+            if (DEBUG_SD_INSTALL)
+                Log.i(TAG, "Loading container : " + args.cid);
+            int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
+            try {
+                // Make sure there are no container errors first.
+                if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) != PackageManager.INSTALL_SUCCEEDED) {
+                    Slog.e(TAG, "Failed to mount cid : " + args.cid
+                            + " when installing from sdcard");
+                    continue;
+                }
+                // Check code path here.
+                if (codePath == null || !codePath.equals(args.getCodePath())) {
+                    Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath()
+                            + " does not match one in settings " + codePath);
+                    continue;
+                }
+                // Parse package
+                int parseFlags = mDefParseFlags;
+                if (args.isExternal()) {
+                    parseFlags |= PackageParser.PARSE_ON_SDCARD;
+                }
+                if (args.isFwdLocked()) {
+                    parseFlags |= PackageParser.PARSE_FORWARD_LOCK;
+                }
+
+                doGc = true;
+                synchronized (mInstallLock) {
+                    final PackageParser.Package pkg = scanPackageLI(new File(codePath), parseFlags,
+                            0, 0, null);
+                    // Scan the package
+                    if (pkg != null) {
+                        /*
+                         * TODO why is the lock being held? doPostInstall is
+                         * called in other places without the lock. This needs
+                         * to be straightened out.
+                         */
+                        // writer
+                        synchronized (mPackages) {
+                            retCode = PackageManager.INSTALL_SUCCEEDED;
+                            pkgList.add(pkg.packageName);
+                            // Post process args
+                            args.doPostInstall(PackageManager.INSTALL_SUCCEEDED,
+                                    pkg.applicationInfo.uid);
+                        }
+                    } else {
+                        Slog.i(TAG, "Failed to install pkg from  " + codePath + " from sdcard");
+                    }
+                }
+
+            } finally {
+                if (retCode != PackageManager.INSTALL_SUCCEEDED) {
+                    // Don't destroy container here. Wait till gc clears things
+                    // up.
+                    removeCids.add(args.cid);
+                }
+            }
+        }
+        // writer
+        synchronized (mPackages) {
+            // If the platform SDK has changed since the last time we booted,
+            // we need to re-grant app permission to catch any new ones that
+            // appear. This is really a hack, and means that apps can in some
+            // cases get permissions that the user didn't initially explicitly
+            // allow... it would be nice to have some better way to handle
+            // this situation.
+            final boolean regrantPermissions = mSettings.mExternalSdkPlatform != mSdkVersion;
+            if (regrantPermissions)
+                Slog.i(TAG, "Platform changed from " + mSettings.mExternalSdkPlatform + " to "
+                        + mSdkVersion + "; regranting permissions for external storage");
+            mSettings.mExternalSdkPlatform = mSdkVersion;
+
+            // Make sure group IDs have been assigned, and any permission
+            // changes in other apps are accounted for
+            updatePermissionsLPw(null, null, UPDATE_PERMISSIONS_ALL
+                    | (regrantPermissions
+                            ? (UPDATE_PERMISSIONS_REPLACE_PKG|UPDATE_PERMISSIONS_REPLACE_ALL)
+                            : 0));
+            // can downgrade to reader
+            // Persist settings
+            mSettings.writeLPr();
+        }
+        // Send a broadcast to let everyone know we are done processing
+        if (pkgList.size() > 0) {
+            sendResourcesChangedBroadcast(true, false, pkgList, uidArr, null);
+        }
+        // Force gc to avoid any stale parser references that we might have.
+        if (doGc) {
+            Runtime.getRuntime().gc();
+        }
+        // List stale containers and destroy stale temporary containers.
+        if (removeCids != null) {
+            for (String cid : removeCids) {
+                if (cid.startsWith(mTempContainerPrefix)) {
+                    Log.i(TAG, "Destroying stale temporary container " + cid);
+                    PackageHelper.destroySdDir(cid);
+                } else {
+                    Log.w(TAG, "Container " + cid + " is stale");
+               }
+           }
+        }
+    }
+
+   /*
+     * Utility method to unload a list of specified containers
+     */
+    private void unloadAllContainers(Set<AsecInstallArgs> cidArgs) {
+        // Just unmount all valid containers.
+        for (AsecInstallArgs arg : cidArgs) {
+            synchronized (mInstallLock) {
+                arg.doPostDeleteLI(false);
+           }
+       }
+   }
+
+    /*
+     * Unload packages mounted on external media. This involves deleting package
+     * data from internal structures, sending broadcasts about diabled packages,
+     * gc'ing to free up references, unmounting all secure containers
+     * corresponding to packages on external media, and posting a
+     * UPDATED_MEDIA_STATUS message if status has been requested. Please note
+     * that we always have to post this message if status has been requested no
+     * matter what.
+     */
+    private void unloadMediaPackages(HashMap<AsecInstallArgs, String> processCids, int uidArr[],
+            final boolean reportStatus) {
+        if (DEBUG_SD_INSTALL)
+            Log.i(TAG, "unloading media packages");
+        ArrayList<String> pkgList = new ArrayList<String>();
+        ArrayList<AsecInstallArgs> failedList = new ArrayList<AsecInstallArgs>();
+        final Set<AsecInstallArgs> keys = processCids.keySet();
+        for (AsecInstallArgs args : keys) {
+            String pkgName = args.getPackageName();
+            if (DEBUG_SD_INSTALL)
+                Log.i(TAG, "Trying to unload pkg : " + pkgName);
+            // Delete package internally
+            PackageRemovedInfo outInfo = new PackageRemovedInfo();
+            synchronized (mInstallLock) {
+                boolean res = deletePackageLI(pkgName, null, false, null, null,
+                        PackageManager.DELETE_KEEP_DATA, outInfo, false);
+                if (res) {
+                    pkgList.add(pkgName);
+                } else {
+                    Slog.e(TAG, "Failed to delete pkg from sdcard : " + pkgName);
+                    failedList.add(args);
+                }
+            }
+        }
+
+        // reader
+        synchronized (mPackages) {
+            // We didn't update the settings after removing each package;
+            // write them now for all packages.
+            mSettings.writeLPr();
+        }
+
+        // We have to absolutely send UPDATED_MEDIA_STATUS only
+        // after confirming that all the receivers processed the ordered
+        // broadcast when packages get disabled, force a gc to clean things up.
+        // and unload all the containers.
+        if (pkgList.size() > 0) {
+            sendResourcesChangedBroadcast(false, false, pkgList, uidArr,
+                    new IIntentReceiver.Stub() {
+                public void performReceive(Intent intent, int resultCode, String data,
+                        Bundle extras, boolean ordered, boolean sticky,
+                        int sendingUser) throws RemoteException {
+                    Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS,
+                            reportStatus ? 1 : 0, 1, keys);
+                    mHandler.sendMessage(msg);
+                }
+            });
+        } else {
+            Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, reportStatus ? 1 : 0, -1,
+                    keys);
+            mHandler.sendMessage(msg);
+        }
+    }
+
+    /** Binder call */
+    @Override
+    public void movePackage(final String packageName, final IPackageMoveObserver observer,
+            final int flags) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
+        UserHandle user = new UserHandle(UserHandle.getCallingUserId());
+        int returnCode = PackageManager.MOVE_SUCCEEDED;
+        int currFlags = 0;
+        int newFlags = 0;
+        // reader
+        synchronized (mPackages) {
+            PackageParser.Package pkg = mPackages.get(packageName);
+            if (pkg == null) {
+                returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
+            } else {
+                // Disable moving fwd locked apps and system packages
+                if (pkg.applicationInfo != null && isSystemApp(pkg)) {
+                    Slog.w(TAG, "Cannot move system application");
+                    returnCode = PackageManager.MOVE_FAILED_SYSTEM_PACKAGE;
+                } else if (pkg.mOperationPending) {
+                    Slog.w(TAG, "Attempt to move package which has pending operations");
+                    returnCode = PackageManager.MOVE_FAILED_OPERATION_PENDING;
+                } else {
+                    // Find install location first
+                    if ((flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0
+                            && (flags & PackageManager.MOVE_INTERNAL) != 0) {
+                        Slog.w(TAG, "Ambigous flags specified for move location.");
+                        returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION;
+                    } else {
+                        newFlags = (flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 ? PackageManager.INSTALL_EXTERNAL
+                                : PackageManager.INSTALL_INTERNAL;
+                        currFlags = isExternal(pkg) ? PackageManager.INSTALL_EXTERNAL
+                                : PackageManager.INSTALL_INTERNAL;
+
+                        if (newFlags == currFlags) {
+                            Slog.w(TAG, "No move required. Trying to move to same location");
+                            returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION;
+                        } else {
+                            if (isForwardLocked(pkg)) {
+                                currFlags |= PackageManager.INSTALL_FORWARD_LOCK;
+                                newFlags |= PackageManager.INSTALL_FORWARD_LOCK;
+                            }
+                        }
+                    }
+                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
+                        pkg.mOperationPending = true;
+                    }
+                }
+            }
+
+            /*
+             * TODO this next block probably shouldn't be inside the lock. We
+             * can't guarantee these won't change after this is fired off
+             * anyway.
+             */
+            if (returnCode != PackageManager.MOVE_SUCCEEDED) {
+                processPendingMove(new MoveParams(null, observer, 0, packageName,
+                        null, -1, user),
+                        returnCode);
+            } else {
+                Message msg = mHandler.obtainMessage(INIT_COPY);
+                InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir,
+                        pkg.applicationInfo.publicSourceDir, pkg.applicationInfo.nativeLibraryDir);
+                MoveParams mp = new MoveParams(srcArgs, observer, newFlags, packageName,
+                        pkg.applicationInfo.dataDir, pkg.applicationInfo.uid, user);
+                msg.obj = mp;
+                mHandler.sendMessage(msg);
+            }
+        }
+    }
+
+    private void processPendingMove(final MoveParams mp, final int currentStatus) {
+        // Queue up an async operation since the package deletion may take a
+        // little while.
+        mHandler.post(new Runnable() {
+            public void run() {
+                // TODO fix this; this does nothing.
+                mHandler.removeCallbacks(this);
+                int returnCode = currentStatus;
+                if (currentStatus == PackageManager.MOVE_SUCCEEDED) {
+                    int uidArr[] = null;
+                    ArrayList<String> pkgList = null;
+                    synchronized (mPackages) {
+                        PackageParser.Package pkg = mPackages.get(mp.packageName);
+                        if (pkg == null) {
+                            Slog.w(TAG, " Package " + mp.packageName
+                                    + " doesn't exist. Aborting move");
+                            returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
+                        } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) {
+                            Slog.w(TAG, "Package " + mp.packageName + " code path changed from "
+                                    + mp.srcArgs.getCodePath() + " to "
+                                    + pkg.applicationInfo.sourceDir
+                                    + " Aborting move and returning error");
+                            returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
+                        } else {
+                            uidArr = new int[] {
+                                pkg.applicationInfo.uid
+                            };
+                            pkgList = new ArrayList<String>();
+                            pkgList.add(mp.packageName);
+                        }
+                    }
+                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
+                        // Send resources unavailable broadcast
+                        sendResourcesChangedBroadcast(false, true, pkgList, uidArr, null);
+                        // Update package code and resource paths
+                        synchronized (mInstallLock) {
+                            synchronized (mPackages) {
+                                PackageParser.Package pkg = mPackages.get(mp.packageName);
+                                // Recheck for package again.
+                                if (pkg == null) {
+                                    Slog.w(TAG, " Package " + mp.packageName
+                                            + " doesn't exist. Aborting move");
+                                    returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
+                                } else if (!mp.srcArgs.getCodePath().equals(
+                                        pkg.applicationInfo.sourceDir)) {
+                                    Slog.w(TAG, "Package " + mp.packageName
+                                            + " code path changed from " + mp.srcArgs.getCodePath()
+                                            + " to " + pkg.applicationInfo.sourceDir
+                                            + " Aborting move and returning error");
+                                    returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
+                                } else {
+                                    final String oldCodePath = pkg.mPath;
+                                    final String newCodePath = mp.targetArgs.getCodePath();
+                                    final String newResPath = mp.targetArgs.getResourcePath();
+                                    final String newNativePath = mp.targetArgs
+                                            .getNativeLibraryPath();
+
+                                    final File newNativeDir = new File(newNativePath);
+
+                                    if (!isForwardLocked(pkg) && !isExternal(pkg)) {
+                                        NativeLibraryHelper.copyNativeBinariesIfNeededLI(
+                                                new File(newCodePath), newNativeDir);
+                                    }
+                                    final int[] users = sUserManager.getUserIds();
+                                    for (int user : users) {
+                                        if (mInstaller.linkNativeLibraryDirectory(pkg.packageName,
+                                                newNativePath, user) < 0) {
+                                            returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
+                                        }
+                                    }
+
+                                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
+                                        pkg.mPath = newCodePath;
+                                        // Move dex files around
+                                        if (moveDexFilesLI(pkg) != PackageManager.INSTALL_SUCCEEDED) {
+                                            // Moving of dex files failed. Set
+                                            // error code and abort move.
+                                            pkg.mPath = pkg.mScanPath;
+                                            returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
+                                        }
+                                    }
+
+                                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
+                                        pkg.mScanPath = newCodePath;
+                                        pkg.applicationInfo.sourceDir = newCodePath;
+                                        pkg.applicationInfo.publicSourceDir = newResPath;
+                                        pkg.applicationInfo.nativeLibraryDir = newNativePath;
+                                        PackageSetting ps = (PackageSetting) pkg.mExtras;
+                                        ps.codePath = new File(pkg.applicationInfo.sourceDir);
+                                        ps.codePathString = ps.codePath.getPath();
+                                        ps.resourcePath = new File(
+                                                pkg.applicationInfo.publicSourceDir);
+                                        ps.resourcePathString = ps.resourcePath.getPath();
+                                        ps.nativeLibraryPathString = newNativePath;
+                                        // Set the application info flag
+                                        // correctly.
+                                        if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) {
+                                            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
+                                        } else {
+                                            pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE;
+                                        }
+                                        ps.setFlags(pkg.applicationInfo.flags);
+                                        mAppDirs.remove(oldCodePath);
+                                        mAppDirs.put(newCodePath, pkg);
+                                        // Persist settings
+                                        mSettings.writeLPr();
+                                    }
+                                }
+                            }
+                        }
+                        // Send resources available broadcast
+                        sendResourcesChangedBroadcast(true, false, pkgList, uidArr, null);
+                    }
+                }
+                if (returnCode != PackageManager.MOVE_SUCCEEDED) {
+                    // Clean up failed installation
+                    if (mp.targetArgs != null) {
+                        mp.targetArgs.doPostInstall(PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
+                                -1);
+                    }
+                } else {
+                    // Force a gc to clear things up.
+                    Runtime.getRuntime().gc();
+                    // Delete older code
+                    synchronized (mInstallLock) {
+                        mp.srcArgs.doPostDeleteLI(true);
+                    }
+                }
+
+                // Allow more operations on this file if we didn't fail because
+                // an operation was already pending for this package.
+                if (returnCode != PackageManager.MOVE_FAILED_OPERATION_PENDING) {
+                    synchronized (mPackages) {
+                        PackageParser.Package pkg = mPackages.get(mp.packageName);
+                        if (pkg != null) {
+                            pkg.mOperationPending = false;
+                       }
+                   }
+                }
+
+                IPackageMoveObserver observer = mp.observer;
+                if (observer != null) {
+                    try {
+                        observer.packageMoved(mp.packageName, returnCode);
+                    } catch (RemoteException e) {
+                        Log.i(TAG, "Observer no longer exists.");
+                    }
+                }
+            }
+        });
+    }
+
+    public boolean setInstallLocation(int loc) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,
+                null);
+        if (getInstallLocation() == loc) {
+            return true;
+        }
+        if (loc == PackageHelper.APP_INSTALL_AUTO || loc == PackageHelper.APP_INSTALL_INTERNAL
+                || loc == PackageHelper.APP_INSTALL_EXTERNAL) {
+            android.provider.Settings.Global.putInt(mContext.getContentResolver(),
+                    android.provider.Settings.Global.DEFAULT_INSTALL_LOCATION, loc);
+            return true;
+        }
+        return false;
+   }
+
+    public int getInstallLocation() {
+        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
+                android.provider.Settings.Global.DEFAULT_INSTALL_LOCATION,
+                PackageHelper.APP_INSTALL_AUTO);
+    }
+
+    /** Called by UserManagerService */
+    void cleanUpUserLILPw(int userHandle) {
+        mDirtyUsers.remove(userHandle);
+        mSettings.removeUserLPr(userHandle);
+        mPendingBroadcasts.remove(userHandle);
+        if (mInstaller != null) {
+            // Technically, we shouldn't be doing this with the package lock
+            // held.  However, this is very rare, and there is already so much
+            // other disk I/O going on, that we'll let it slide for now.
+            mInstaller.removeUserDataDirs(userHandle);
+        }
+    }
+
+    /** Called by UserManagerService */
+    void createNewUserLILPw(int userHandle, File path) {
+        if (mInstaller != null) {
+            mSettings.createNewUserLILPw(this, mInstaller, userHandle, path);
+        }
+    }
+
+    @Override
+    public VerifierDeviceIdentity getVerifierDeviceIdentity() throws RemoteException {
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
+                "Only package verification agents can read the verifier device identity");
+
+        synchronized (mPackages) {
+            return mSettings.getVerifierDeviceIdentityLPw();
+        }
+    }
+
+    @Override
+    public void setPermissionEnforced(String permission, boolean enforced) {
+        mContext.enforceCallingOrSelfPermission(GRANT_REVOKE_PERMISSIONS, null);
+        if (READ_EXTERNAL_STORAGE.equals(permission)) {
+            synchronized (mPackages) {
+                if (mSettings.mReadExternalStorageEnforced == null
+                        || mSettings.mReadExternalStorageEnforced != enforced) {
+                    mSettings.mReadExternalStorageEnforced = enforced;
+                    mSettings.writeLPr();
+                }
+            }
+            // kill any non-foreground processes so we restart them and
+            // grant/revoke the GID.
+            final IActivityManager am = ActivityManagerNative.getDefault();
+            if (am != null) {
+                final long token = Binder.clearCallingIdentity();
+                try {
+                    am.killProcessesBelowForeground("setPermissionEnforcement");
+                } catch (RemoteException e) {
+                } finally {
+                    Binder.restoreCallingIdentity(token);
+                }
+            }
+        } else {
+            throw new IllegalArgumentException("No selective enforcement for " + permission);
+        }
+    }
+
+    @Override
+    @Deprecated
+    public boolean isPermissionEnforced(String permission) {
+        return true;
+    }
+
+    @Override
+    public boolean isStorageLow() {
+        final long token = Binder.clearCallingIdentity();
+        try {
+            final DeviceStorageMonitorInternal
+                    dsm = LocalServices.getService(DeviceStorageMonitorInternal.class);
+            if (dsm != null) {
+                return dsm.isMemoryLow();
+            } else {
+                return false;
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+}
diff --git a/services/java/com/android/server/pm/PackageSetting.java b/services/core/java/com/android/server/pm/PackageSetting.java
similarity index 100%
rename from services/java/com/android/server/pm/PackageSetting.java
rename to services/core/java/com/android/server/pm/PackageSetting.java
diff --git a/services/java/com/android/server/pm/PackageSettingBase.java b/services/core/java/com/android/server/pm/PackageSettingBase.java
similarity index 100%
rename from services/java/com/android/server/pm/PackageSettingBase.java
rename to services/core/java/com/android/server/pm/PackageSettingBase.java
diff --git a/services/java/com/android/server/pm/PackageSignatures.java b/services/core/java/com/android/server/pm/PackageSignatures.java
similarity index 100%
rename from services/java/com/android/server/pm/PackageSignatures.java
rename to services/core/java/com/android/server/pm/PackageSignatures.java
diff --git a/services/java/com/android/server/pm/PackageVerificationResponse.java b/services/core/java/com/android/server/pm/PackageVerificationResponse.java
similarity index 100%
rename from services/java/com/android/server/pm/PackageVerificationResponse.java
rename to services/core/java/com/android/server/pm/PackageVerificationResponse.java
diff --git a/services/java/com/android/server/pm/PackageVerificationState.java b/services/core/java/com/android/server/pm/PackageVerificationState.java
similarity index 100%
rename from services/java/com/android/server/pm/PackageVerificationState.java
rename to services/core/java/com/android/server/pm/PackageVerificationState.java
diff --git a/services/java/com/android/server/pm/PendingPackage.java b/services/core/java/com/android/server/pm/PendingPackage.java
similarity index 100%
rename from services/java/com/android/server/pm/PendingPackage.java
rename to services/core/java/com/android/server/pm/PendingPackage.java
diff --git a/services/core/java/com/android/server/pm/PreferredActivity.java b/services/core/java/com/android/server/pm/PreferredActivity.java
new file mode 100644
index 0000000..8916926
--- /dev/null
+++ b/services/core/java/com/android/server/pm/PreferredActivity.java
@@ -0,0 +1,79 @@
+/*
+ * 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.server.pm;
+
+import com.android.internal.util.XmlUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.content.ComponentName;
+import android.content.IntentFilter;
+import android.util.Log;
+
+import java.io.IOException;
+
+class PreferredActivity extends IntentFilter implements PreferredComponent.Callbacks {
+    private static final String TAG = "PreferredActivity";
+
+    private static final boolean DEBUG_FILTERS = false;
+
+    final PreferredComponent mPref;
+
+    PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity,
+            boolean always) {
+        super(filter);
+        mPref = new PreferredComponent(this, match, set, activity, always);
+    }
+
+    PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
+        mPref = new PreferredComponent(this, parser);
+    }
+
+    public void writeToXml(XmlSerializer serializer, boolean full) throws IOException {
+        mPref.writeToXml(serializer, full);
+        serializer.startTag(null, "filter");
+            super.writeToXml(serializer);
+        serializer.endTag(null, "filter");
+    }
+
+    public boolean onReadTag(String tagName, XmlPullParser parser) throws XmlPullParserException,
+            IOException {
+        if (tagName.equals("filter")) {
+            if (DEBUG_FILTERS) {
+                Log.i(TAG, "Starting to parse filter...");
+            }
+            readFromXml(parser);
+            if (DEBUG_FILTERS) {
+                Log.i(TAG, "Finished filter: depth=" + parser.getDepth() + " tag="
+                        + parser.getName());
+            }
+        } else {
+            PackageManagerService.reportSettingsProblem(Log.WARN,
+                    "Unknown element under <preferred-activities>: " + parser.getName());
+            XmlUtils.skipCurrentTag(parser);
+        }
+        return true;
+    }
+
+    @Override
+    public String toString() {
+        return "PreferredActivity{0x" + Integer.toHexString(System.identityHashCode(this))
+                + " " + mPref.mComponent.flattenToShortString() + "}";
+    }
+}
diff --git a/services/core/java/com/android/server/pm/PreferredComponent.java b/services/core/java/com/android/server/pm/PreferredComponent.java
new file mode 100644
index 0000000..f437372
--- /dev/null
+++ b/services/core/java/com/android/server/pm/PreferredComponent.java
@@ -0,0 +1,234 @@
+/*
+ * 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.server.pm;
+
+import com.android.internal.util.XmlUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.content.ComponentName;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ResolveInfo;
+import android.util.Slog;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+public class PreferredComponent {
+    private static final String TAG_SET = "set";
+    private static final String ATTR_ALWAYS = "always"; // boolean
+    private static final String ATTR_MATCH = "match"; // number
+    private static final String ATTR_NAME = "name"; // component name
+    private static final String ATTR_SET = "set"; // number
+
+    public final int mMatch;
+    public final ComponentName mComponent;
+    // Whether this is to be the one that's always chosen. If false, it's the most recently chosen.
+    public boolean mAlways;
+
+    private final String[] mSetPackages;
+    private final String[] mSetClasses;
+    private final String[] mSetComponents;
+    private final String mShortComponent;
+    private String mParseError;
+
+    private final Callbacks mCallbacks;
+
+    public interface Callbacks {
+        public boolean onReadTag(String tagName, XmlPullParser parser)
+                throws XmlPullParserException, IOException;
+    }
+
+    public PreferredComponent(Callbacks callbacks, int match, ComponentName[] set,
+            ComponentName component, boolean always) {
+        mCallbacks = callbacks;
+        mMatch = match&IntentFilter.MATCH_CATEGORY_MASK;
+        mComponent = component;
+        mAlways = always;
+        mShortComponent = component.flattenToShortString();
+        mParseError = null;
+        if (set != null) {
+            final int N = set.length;
+            String[] myPackages = new String[N];
+            String[] myClasses = new String[N];
+            String[] myComponents = new String[N];
+            for (int i=0; i<N; i++) {
+                ComponentName cn = set[i];
+                if (cn == null) {
+                    mSetPackages = null;
+                    mSetClasses = null;
+                    mSetComponents = null;
+                    return;
+                }
+                myPackages[i] = cn.getPackageName().intern();
+                myClasses[i] = cn.getClassName().intern();
+                myComponents[i] = cn.flattenToShortString();
+            }
+            mSetPackages = myPackages;
+            mSetClasses = myClasses;
+            mSetComponents = myComponents;
+        } else {
+            mSetPackages = null;
+            mSetClasses = null;
+            mSetComponents = null;
+        }
+    }
+
+    public PreferredComponent(Callbacks callbacks, XmlPullParser parser)
+            throws XmlPullParserException, IOException {
+        mCallbacks = callbacks;
+        mShortComponent = parser.getAttributeValue(null, ATTR_NAME);
+        mComponent = ComponentName.unflattenFromString(mShortComponent);
+        if (mComponent == null) {
+            mParseError = "Bad activity name " + mShortComponent;
+        }
+        String matchStr = parser.getAttributeValue(null, ATTR_MATCH);
+        mMatch = matchStr != null ? Integer.parseInt(matchStr, 16) : 0;
+        String setCountStr = parser.getAttributeValue(null, ATTR_SET);
+        int setCount = setCountStr != null ? Integer.parseInt(setCountStr) : 0;
+        String alwaysStr = parser.getAttributeValue(null, ATTR_ALWAYS);
+        mAlways = alwaysStr != null ? Boolean.parseBoolean(alwaysStr) : true;
+
+        String[] myPackages = setCount > 0 ? new String[setCount] : null;
+        String[] myClasses = setCount > 0 ? new String[setCount] : null;
+        String[] myComponents = setCount > 0 ? new String[setCount] : null;
+
+        int setPos = 0;
+
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+               && (type != XmlPullParser.END_TAG
+                       || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG
+                    || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            //Log.i(TAG, "Parse outerDepth=" + outerDepth + " depth="
+            //        + parser.getDepth() + " tag=" + tagName);
+            if (tagName.equals(TAG_SET)) {
+                String name = parser.getAttributeValue(null, ATTR_NAME);
+                if (name == null) {
+                    if (mParseError == null) {
+                        mParseError = "No name in set tag in preferred activity "
+                            + mShortComponent;
+                    }
+                } else if (setPos >= setCount) {
+                    if (mParseError == null) {
+                        mParseError = "Too many set tags in preferred activity "
+                            + mShortComponent;
+                    }
+                } else {
+                    ComponentName cn = ComponentName.unflattenFromString(name);
+                    if (cn == null) {
+                        if (mParseError == null) {
+                            mParseError = "Bad set name " + name + " in preferred activity "
+                                + mShortComponent;
+                        }
+                    } else {
+                        myPackages[setPos] = cn.getPackageName();
+                        myClasses[setPos] = cn.getClassName();
+                        myComponents[setPos] = name;
+                        setPos++;
+                    }
+                }
+                XmlUtils.skipCurrentTag(parser);
+            } else if (!mCallbacks.onReadTag(tagName, parser)) {
+                Slog.w("PreferredComponent", "Unknown element: " + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+
+        if (setPos != setCount) {
+            if (mParseError == null) {
+                mParseError = "Not enough set tags (expected " + setCount
+                    + " but found " + setPos + ") in " + mShortComponent;
+            }
+        }
+
+        mSetPackages = myPackages;
+        mSetClasses = myClasses;
+        mSetComponents = myComponents;
+    }
+
+    public String getParseError() {
+        return mParseError;
+    }
+
+    public void writeToXml(XmlSerializer serializer, boolean full) throws IOException {
+        final int NS = mSetClasses != null ? mSetClasses.length : 0;
+        serializer.attribute(null, ATTR_NAME, mShortComponent);
+        if (full) {
+            if (mMatch != 0) {
+                serializer.attribute(null, ATTR_MATCH, Integer.toHexString(mMatch));
+            }
+            serializer.attribute(null, ATTR_ALWAYS, Boolean.toString(mAlways));
+            serializer.attribute(null, ATTR_SET, Integer.toString(NS));
+            for (int s=0; s<NS; s++) {
+                serializer.startTag(null, TAG_SET);
+                serializer.attribute(null, ATTR_NAME, mSetComponents[s]);
+                serializer.endTag(null, TAG_SET);
+            }
+        }
+    }
+
+    public boolean sameSet(List<ResolveInfo> query, int priority) {
+        if (mSetPackages == null) return false;
+        final int NQ = query.size();
+        final int NS = mSetPackages.length;
+        int numMatch = 0;
+        for (int i=0; i<NQ; i++) {
+            ResolveInfo ri = query.get(i);
+            if (ri.priority != priority) continue;
+            ActivityInfo ai = ri.activityInfo;
+            boolean good = false;
+            for (int j=0; j<NS; j++) {
+                if (mSetPackages[j].equals(ai.packageName)
+                        && mSetClasses[j].equals(ai.name)) {
+                    numMatch++;
+                    good = true;
+                    break;
+                }
+            }
+            if (!good) return false;
+        }
+        return numMatch == NS;
+    }
+
+    public void dump(PrintWriter out, String prefix, Object ident) {
+        out.print(prefix); out.print(
+                Integer.toHexString(System.identityHashCode(ident)));
+                out.print(' ');
+                out.println(mShortComponent);
+        out.print(prefix); out.print(" mMatch=0x");
+                out.print(Integer.toHexString(mMatch));
+                out.print(" mAlways="); out.println(mAlways);
+        if (mSetComponents != null) {
+            out.print(prefix); out.println("  Selected from:");
+            for (int i=0; i<mSetComponents.length; i++) {
+                out.print(prefix); out.print("    ");
+                        out.println(mSetComponents[i]);
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/pm/PreferredIntentResolver.java b/services/core/java/com/android/server/pm/PreferredIntentResolver.java
similarity index 100%
rename from services/java/com/android/server/pm/PreferredIntentResolver.java
rename to services/core/java/com/android/server/pm/PreferredIntentResolver.java
diff --git a/services/core/java/com/android/server/pm/SELinuxMMAC.java b/services/core/java/com/android/server/pm/SELinuxMMAC.java
new file mode 100644
index 0000000..1d68afa
--- /dev/null
+++ b/services/core/java/com/android/server/pm/SELinuxMMAC.java
@@ -0,0 +1,394 @@
+/*
+ * 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.server.pm;
+
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageParser;
+import android.content.pm.Signature;
+import android.os.Environment;
+import android.util.Slog;
+import android.util.Xml;
+
+import com.android.internal.util.XmlUtils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import java.util.HashMap;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ * Centralized access to SELinux MMAC (middleware MAC) implementation.
+ * {@hide}
+ */
+public final class SELinuxMMAC {
+
+    private static final String TAG = "SELinuxMMAC";
+
+    private static final boolean DEBUG_POLICY = false;
+    private static final boolean DEBUG_POLICY_INSTALL = DEBUG_POLICY || false;
+
+    // Signature seinfo values read from policy.
+    private static HashMap<Signature, Policy> sSigSeinfo =
+        new HashMap<Signature, Policy>();
+
+    // Default seinfo read from policy.
+    private static String sDefaultSeinfo = null;
+
+    // Locations of potential install policy files.
+    private static final File[] INSTALL_POLICY_FILE = {
+        new File(Environment.getDataDirectory(), "security/mac_permissions.xml"),
+        new File(Environment.getRootDirectory(), "etc/security/mac_permissions.xml"),
+        null};
+
+    // Signature policy stanzas
+    static class Policy {
+        private String seinfo;
+        private final HashMap<String, String> pkgMap;
+
+        Policy() {
+            seinfo = null;
+            pkgMap = new HashMap<String, String>();
+        }
+
+        void putSeinfo(String seinfoValue) {
+            seinfo = seinfoValue;
+        }
+
+        void putPkg(String pkg, String seinfoValue) {
+            pkgMap.put(pkg, seinfoValue);
+        }
+
+        // Valid policy stanza means there exists a global
+        // seinfo value or at least one package policy.
+        boolean isValid() {
+            return (seinfo != null) || (!pkgMap.isEmpty());
+        }
+
+        String checkPolicy(String pkgName) {
+            // Check for package name seinfo value first.
+            String seinfoValue = pkgMap.get(pkgName);
+            if (seinfoValue != null) {
+                return seinfoValue;
+            }
+
+            // Return the global seinfo value.
+            return seinfo;
+        }
+    }
+
+    private static void flushInstallPolicy() {
+        sSigSeinfo.clear();
+        sDefaultSeinfo = null;
+    }
+
+    /**
+     * Parses an MMAC install policy from a predefined list of locations.
+     * @param none
+     * @return boolean indicating whether an install policy was correctly parsed.
+     */
+    public static boolean readInstallPolicy() {
+
+        return readInstallPolicy(INSTALL_POLICY_FILE);
+    }
+
+    /**
+     * Parses an MMAC install policy given as an argument.
+     * @param File object representing the path of the policy.
+     * @return boolean indicating whether the install policy was correctly parsed.
+     */
+    public static boolean readInstallPolicy(File policyFile) {
+
+        return readInstallPolicy(new File[]{policyFile,null});
+    }
+
+    private static boolean readInstallPolicy(File[] policyFiles) {
+        // Temp structures to hold the rules while we parse the xml file.
+        // We add all the rules together once we know there's no structural problems.
+        HashMap<Signature, Policy> sigSeinfo = new HashMap<Signature, Policy>();
+        String defaultSeinfo = null;
+
+        FileReader policyFile = null;
+        int i = 0;
+        while (policyFile == null && policyFiles != null && policyFiles[i] != null) {
+            try {
+                policyFile = new FileReader(policyFiles[i]);
+                break;
+            } catch (FileNotFoundException e) {
+                Slog.d(TAG,"Couldn't find install policy " + policyFiles[i].getPath());
+            }
+            i++;
+        }
+
+        if (policyFile == null) {
+            Slog.d(TAG, "No policy file found. All seinfo values will be null.");
+            return false;
+        }
+
+        Slog.d(TAG, "Using install policy file " + policyFiles[i].getPath());
+
+        try {
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(policyFile);
+
+            XmlUtils.beginDocument(parser, "policy");
+            while (true) {
+                XmlUtils.nextElement(parser);
+                if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
+                    break;
+                }
+
+                String tagName = parser.getName();
+                if ("signer".equals(tagName)) {
+                    String cert = parser.getAttributeValue(null, "signature");
+                    if (cert == null) {
+                        Slog.w(TAG, "<signer> without signature at "
+                               + parser.getPositionDescription());
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    Signature signature;
+                    try {
+                        signature = new Signature(cert);
+                    } catch (IllegalArgumentException e) {
+                        Slog.w(TAG, "<signer> with bad signature at "
+                               + parser.getPositionDescription(), e);
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    Policy policy = readPolicyTags(parser);
+                    if (policy.isValid()) {
+                        sigSeinfo.put(signature, policy);
+                    }
+                } else if ("default".equals(tagName)) {
+                    // Value is null if default tag is absent or seinfo tag is malformed.
+                    defaultSeinfo = readSeinfoTag(parser);
+                    if (DEBUG_POLICY_INSTALL)
+                        Slog.i(TAG, "<default> tag assigned seinfo=" + defaultSeinfo);
+
+                } else {
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+        } catch (XmlPullParserException e) {
+            // An error outside of a stanza means a structural problem
+            // with the xml file. So ignore it.
+            Slog.w(TAG, "Got exception parsing ", e);
+            return false;
+        } catch (IOException e) {
+            Slog.w(TAG, "Got exception parsing ", e);
+            return false;
+        } finally {
+            try {
+                policyFile.close();
+            } catch (IOException e) {
+                //omit
+            }
+        }
+
+        flushInstallPolicy();
+        sSigSeinfo = sigSeinfo;
+        sDefaultSeinfo = defaultSeinfo;
+
+        return true;
+    }
+
+    private static Policy readPolicyTags(XmlPullParser parser) throws
+            IOException, XmlPullParserException {
+
+        int type;
+        int outerDepth = parser.getDepth();
+        Policy policy = new Policy();
+        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+               && (type != XmlPullParser.END_TAG
+                   || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG
+                || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if ("seinfo".equals(tagName)) {
+                String seinfo = parseSeinfo(parser);
+                if (seinfo != null) {
+                    policy.putSeinfo(seinfo);
+                }
+                XmlUtils.skipCurrentTag(parser);
+            } else if ("package".equals(tagName)) {
+                String pkg = parser.getAttributeValue(null, "name");
+                if (!validatePackageName(pkg)) {
+                    Slog.w(TAG, "<package> without valid name at "
+                           + parser.getPositionDescription());
+                    XmlUtils.skipCurrentTag(parser);
+                    continue;
+                }
+
+                String seinfo = readSeinfoTag(parser);
+                if (seinfo != null) {
+                    policy.putPkg(pkg, seinfo);
+                }
+            } else {
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+        return policy;
+    }
+
+    private static String readSeinfoTag(XmlPullParser parser) throws
+            IOException, XmlPullParserException {
+
+        int type;
+        int outerDepth = parser.getDepth();
+        String seinfo = null;
+        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+               && (type != XmlPullParser.END_TAG
+                   || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG
+                || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if ("seinfo".equals(tagName)) {
+                seinfo = parseSeinfo(parser);
+            }
+            XmlUtils.skipCurrentTag(parser);
+        }
+        return seinfo;
+    }
+
+    private static String parseSeinfo(XmlPullParser parser) {
+
+        String seinfoValue = parser.getAttributeValue(null, "value");
+        if (!validateValue(seinfoValue)) {
+            Slog.w(TAG, "<seinfo> without valid value at "
+                   + parser.getPositionDescription());
+            seinfoValue = null;
+        }
+        return seinfoValue;
+    }
+
+    /**
+     * General validation routine for package names.
+     * Returns a boolean indicating if the passed string
+     * is a valid android package name.
+     */
+    private static boolean validatePackageName(String name) {
+        if (name == null)
+            return false;
+
+        final int N = name.length();
+        boolean hasSep = false;
+        boolean front = true;
+        for (int i=0; i<N; i++) {
+            final char c = name.charAt(i);
+            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
+                front = false;
+                continue;
+            }
+            if (!front) {
+                if ((c >= '0' && c <= '9') || c == '_') {
+                    continue;
+                }
+            }
+            if (c == '.') {
+                hasSep = true;
+                front = true;
+                continue;
+            }
+            return false;
+        }
+        return hasSep;
+    }
+
+    /**
+     * General validation routine for tag values.
+     * Returns a boolean indicating if the passed string
+     * contains only letters or underscores.
+     */
+    private static boolean validateValue(String name) {
+        if (name == null)
+            return false;
+
+        final int N = name.length();
+        if (N == 0)
+            return false;
+
+        for (int i = 0; i < N; i++) {
+            final char c = name.charAt(i);
+            if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c != '_')) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Labels a package based on an seinfo tag from install policy.
+     * The label is attached to the ApplicationInfo instance of the package.
+     * @param PackageParser.Package object representing the package
+     *         to labeled.
+     * @return boolean which determines whether a non null seinfo label
+     *         was assigned to the package. A null value simply meaning that
+     *         no policy matched.
+     */
+    public static boolean assignSeinfoValue(PackageParser.Package pkg) {
+
+        /*
+         * Non system installed apps should be treated the same. This
+         * means that any post-loaded apk will be assigned the default
+         * tag, if one exists in the policy, else null, without respect
+         * to the signing key.
+         */
+        if (((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ||
+            ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)) {
+
+            // We just want one of the signatures to match.
+            for (Signature s : pkg.mSignatures) {
+                if (s == null)
+                    continue;
+
+                Policy policy = sSigSeinfo.get(s);
+                if (policy != null) {
+                    String seinfo = policy.checkPolicy(pkg.packageName);
+                    if (seinfo != null) {
+                        pkg.applicationInfo.seinfo = seinfo;
+                        if (DEBUG_POLICY_INSTALL)
+                            Slog.i(TAG, "package (" + pkg.packageName +
+                                   ") labeled with seinfo=" + seinfo);
+
+                        return true;
+                    }
+                }
+            }
+        }
+
+        // If we have a default seinfo value then great, otherwise
+        // we set a null object and that is what we started with.
+        pkg.applicationInfo.seinfo = sDefaultSeinfo;
+        if (DEBUG_POLICY_INSTALL)
+            Slog.i(TAG, "package (" + pkg.packageName + ") labeled with seinfo="
+                   + (sDefaultSeinfo == null ? "null" : sDefaultSeinfo));
+
+        return (sDefaultSeinfo != null);
+    }
+}
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
new file mode 100644
index 0000000..8f18b23
--- /dev/null
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -0,0 +1,3227 @@
+/*
+ * 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.server.pm;
+
+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.os.Process.SYSTEM_UID;
+import static android.os.Process.PACKAGE_INFO_GID;
+
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
+import android.os.PatternMatcher;
+import android.util.LogPrinter;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.JournaledFile;
+import com.android.internal.util.XmlUtils;
+import com.android.server.pm.PackageManagerService.DumpState;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ComponentInfo;
+import android.content.pm.KeySet;
+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.os.Binder;
+import android.os.Environment;
+import android.os.FileUtils;
+import android.os.Process;
+import android.os.UserHandle;
+import android.util.Log;
+import android.util.LongSparseArray;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.Xml;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.PublicKey;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import libcore.io.IoUtils;
+
+/**
+ * Holds information about dynamic settings.
+ */
+final class Settings {
+    private static final String TAG = "PackageSettings";
+
+    private static final boolean DEBUG_STOPPED = false;
+    private static final boolean DEBUG_MU = false;
+
+    private static final String TAG_READ_EXTERNAL_STORAGE = "read-external-storage";
+    private static final String ATTR_ENFORCEMENT = "enforcement";
+
+    private static final String TAG_ITEM = "item";
+    private static final String TAG_DISABLED_COMPONENTS = "disabled-components";
+    private static final String TAG_ENABLED_COMPONENTS = "enabled-components";
+    private static final String TAG_PACKAGE_RESTRICTIONS = "package-restrictions";
+    private static final String TAG_PACKAGE = "pkg";
+
+    private static final String ATTR_NAME = "name";
+    private static final String ATTR_USER = "user";
+    private static final String ATTR_CODE = "code";
+    private static final String ATTR_NOT_LAUNCHED = "nl";
+    private static final String ATTR_ENABLED = "enabled";
+    private static final String ATTR_ENABLED_CALLER = "enabledCaller";
+    private static final String ATTR_STOPPED = "stopped";
+    private static final String ATTR_BLOCKED = "blocked";
+    private static final String ATTR_INSTALLED = "inst";
+
+    private final File mSettingsFilename;
+    private final File mBackupSettingsFilename;
+    private final File mPackageListFilename;
+    private final File mStoppedPackagesFilename;
+    private final File mBackupStoppedPackagesFilename;
+
+    final HashMap<String, PackageSetting> mPackages =
+            new HashMap<String, PackageSetting>();
+    // List of replaced system applications
+    private final HashMap<String, PackageSetting> mDisabledSysPackages =
+        new HashMap<String, PackageSetting>();
+
+    private static int mFirstAvailableUid = 0;
+
+    // These are the last platform API version we were using for
+    // the apps installed on internal and external storage.  It is
+    // used to grant newer permissions one time during a system upgrade.
+    int mInternalSdkPlatform;
+    int mExternalSdkPlatform;
+
+    Boolean mReadExternalStorageEnforced;
+
+    /** Device identity for the purpose of package verification. */
+    private VerifierDeviceIdentity mVerifierDeviceIdentity;
+
+    // The user's preferred activities associated with particular intent
+    // filters.
+    final SparseArray<PreferredIntentResolver> mPreferredActivities =
+            new SparseArray<PreferredIntentResolver>();
+
+    final HashMap<String, SharedUserSetting> mSharedUsers =
+            new HashMap<String, SharedUserSetting>();
+    private final ArrayList<Object> mUserIds = new ArrayList<Object>();
+    private final SparseArray<Object> mOtherUserIds =
+            new SparseArray<Object>();
+
+    // For reading/writing settings file.
+    private final ArrayList<Signature> mPastSignatures =
+            new ArrayList<Signature>();
+
+    // Mapping from permission names to info about them.
+    final HashMap<String, BasePermission> mPermissions =
+            new HashMap<String, BasePermission>();
+
+    // Mapping from permission tree names to info about them.
+    final HashMap<String, BasePermission> mPermissionTrees =
+            new HashMap<String, BasePermission>();
+
+    // Packages that have been uninstalled and still need their external
+    // storage data deleted.
+    final ArrayList<PackageCleanItem> mPackagesToBeCleaned = new ArrayList<PackageCleanItem>();
+    
+    // Packages that have been renamed since they were first installed.
+    // Keys are the new names of the packages, values are the original
+    // names.  The packages appear everwhere else under their original
+    // names.
+    final HashMap<String, String> mRenamedPackages = new HashMap<String, String>();
+    
+    final StringBuilder mReadMessages = new StringBuilder();
+
+    /**
+     * Used to track packages that have a shared user ID that hasn't been read
+     * in yet.
+     * <p>
+     * TODO: make this just a local variable that is passed in during package
+     * scanning to make it less confusing.
+     */
+    private final ArrayList<PendingPackage> mPendingPackages = new ArrayList<PendingPackage>();
+
+    private final Context mContext;
+
+    private final File mSystemDir;
+
+    public final KeySetManager mKeySetManager = new KeySetManager(mPackages);
+
+    Settings(Context context) {
+        this(context, Environment.getDataDirectory());
+    }
+
+    Settings(Context context, File dataDir) {
+        mContext = context;
+        mSystemDir = new File(dataDir, "system");
+        mSystemDir.mkdirs();
+        FileUtils.setPermissions(mSystemDir.toString(),
+                FileUtils.S_IRWXU|FileUtils.S_IRWXG
+                |FileUtils.S_IROTH|FileUtils.S_IXOTH,
+                -1, -1);
+        mSettingsFilename = new File(mSystemDir, "packages.xml");
+        mBackupSettingsFilename = new File(mSystemDir, "packages-backup.xml");
+        mPackageListFilename = new File(mSystemDir, "packages.list");
+        FileUtils.setPermissions(mPackageListFilename, 0660, SYSTEM_UID, PACKAGE_INFO_GID);
+
+        // Deprecated: Needed for migration
+        mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml");
+        mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml");
+    }
+
+    PackageSetting getPackageLPw(PackageParser.Package pkg, PackageSetting origPackage,
+            String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
+            String nativeLibraryPathString, int pkgFlags, UserHandle user, boolean add) {
+        final String name = pkg.packageName;
+        PackageSetting p = getPackageLPw(name, origPackage, realName, sharedUser, codePath,
+                resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags,
+                user, add, true /* allowInstall */);
+        return p;
+    }
+
+    PackageSetting peekPackageLPr(String name) {
+        return mPackages.get(name);
+    }
+
+    void setInstallStatus(String pkgName, int status) {
+        PackageSetting p = mPackages.get(pkgName);
+        if(p != null) {
+            if(p.getInstallStatus() != status) {
+                p.setInstallStatus(status);
+            }
+        }
+    }
+
+    void setInstallerPackageName(String pkgName,
+            String installerPkgName) {
+        PackageSetting p = mPackages.get(pkgName);
+        if(p != null) {
+            p.setInstallerPackageName(installerPkgName);
+        }
+    }
+
+    SharedUserSetting getSharedUserLPw(String name,
+            int pkgFlags, boolean create) {
+        SharedUserSetting s = mSharedUsers.get(name);
+        if (s == null) {
+            if (!create) {
+                return null;
+            }
+            s = new SharedUserSetting(name, pkgFlags);
+            s.userId = newUserIdLPw(s);
+            Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId);
+            // < 0 means we couldn't assign a userid; fall out and return
+            // s, which is currently null
+            if (s.userId >= 0) {
+                mSharedUsers.put(name, s);
+            }
+        }
+
+        return s;
+    }
+
+    boolean disableSystemPackageLPw(String name) {
+        final PackageSetting p = mPackages.get(name);
+        if(p == null) {
+            Log.w(PackageManagerService.TAG, "Package:"+name+" is not an installed package");
+            return false;
+        }
+        final PackageSetting dp = mDisabledSysPackages.get(name);
+        // always make sure the system package code and resource paths dont change
+        if (dp == null) {
+            if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
+                p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+            }
+            mDisabledSysPackages.put(name, p);
+
+            // a little trick...  when we install the new package, we don't
+            // want to modify the existing PackageSetting for the built-in
+            // version.  so at this point we need a new PackageSetting that
+            // is okay to muck with.
+            PackageSetting newp = new PackageSetting(p);
+            replacePackageLPw(name, newp);
+            return true;
+        }
+        return false;
+    }
+
+    PackageSetting enableSystemPackageLPw(String name) {
+        PackageSetting p = mDisabledSysPackages.get(name);
+        if(p == null) {
+            Log.w(PackageManagerService.TAG, "Package:"+name+" is not disabled");
+            return null;
+        }
+        // Reset flag in ApplicationInfo object
+        if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
+            p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
+        }
+        PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath,
+                p.nativeLibraryPathString, p.appId, p.versionCode, p.pkgFlags);
+        mDisabledSysPackages.remove(name);
+        return ret;
+    }
+
+    boolean isDisabledSystemPackageLPr(String name) {
+        return mDisabledSysPackages.containsKey(name);
+    }
+
+    void removeDisabledSystemPackageLPw(String name) {
+        mDisabledSysPackages.remove(name);
+    }
+
+    PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath,
+            String nativeLibraryPathString, int uid, int vc, int pkgFlags) {
+        PackageSetting p = mPackages.get(name);
+        if (p != null) {
+            if (p.appId == uid) {
+                return p;
+            }
+            PackageManagerService.reportSettingsProblem(Log.ERROR,
+                    "Adding duplicate package, keeping first: " + name);
+            return null;
+        }
+        p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString,
+                vc, pkgFlags);
+        p.appId = uid;
+        if (addUserIdLPw(uid, p, name)) {
+            mPackages.put(name, p);
+            return p;
+        }
+        return null;
+    }
+
+    SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags) {
+        SharedUserSetting s = mSharedUsers.get(name);
+        if (s != null) {
+            if (s.userId == uid) {
+                return s;
+            }
+            PackageManagerService.reportSettingsProblem(Log.ERROR,
+                    "Adding duplicate shared user, keeping first: " + name);
+            return null;
+        }
+        s = new SharedUserSetting(name, pkgFlags);
+        s.userId = uid;
+        if (addUserIdLPw(uid, s, name)) {
+            mSharedUsers.put(name, s);
+            return s;
+        }
+        return null;
+    }
+
+    void pruneSharedUsersLPw() {
+        ArrayList<String> removeStage = new ArrayList<String>();
+        for (Map.Entry<String,SharedUserSetting> entry : mSharedUsers.entrySet()) {
+            final SharedUserSetting sus = entry.getValue();
+            if (sus == null || sus.packages.size() == 0) {
+                removeStage.add(entry.getKey());
+            }
+        }
+        for (int i = 0; i < removeStage.size(); i++) {
+            mSharedUsers.remove(removeStage.get(i));
+        }
+    }
+
+    // Transfer ownership of permissions from one package to another.
+    void transferPermissionsLPw(String origPkg, String newPkg) {
+        // Transfer ownership of permissions to the new package.
+        for (int i=0; i<2; i++) {
+            HashMap<String, BasePermission> permissions =
+                    i == 0 ? mPermissionTrees : mPermissions;
+            for (BasePermission bp : permissions.values()) {
+                if (origPkg.equals(bp.sourcePackage)) {
+                    if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG,
+                            "Moving permission " + bp.name
+                            + " from pkg " + bp.sourcePackage
+                            + " to " + newPkg);
+                    bp.sourcePackage = newPkg;
+                    bp.packageSetting = null;
+                    bp.perm = null;
+                    if (bp.pendingInfo != null) {
+                        bp.pendingInfo.packageName = newPkg;
+                    }
+                    bp.uid = 0;
+                    bp.gids = null;
+                }
+            }
+        }
+    }
+
+    private PackageSetting getPackageLPw(String name, PackageSetting origPackage,
+            String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
+            String nativeLibraryPathString, int vc, int pkgFlags,
+            UserHandle installUser, boolean add, boolean allowInstall) {
+        PackageSetting p = mPackages.get(name);
+        if (p != null) {
+            if (!p.codePath.equals(codePath)) {
+                // Check to see if its a disabled system app
+                if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                    // This is an updated system app with versions in both system
+                    // and data partition. Just let the most recent version
+                    // take precedence.
+                    Slog.w(PackageManagerService.TAG, "Trying to update system app code path from "
+                            + p.codePathString + " to " + codePath.toString());
+                } else {
+                    // Just a change in the code path is not an issue, but
+                    // let's log a message about it.
+                    Slog.i(PackageManagerService.TAG, "Package " + name + " codePath changed from "
+                            + p.codePath + " to " + codePath + "; Retaining data and using new");
+                    /*
+                     * Since we've changed paths, we need to prefer the new
+                     * native library path over the one stored in the
+                     * package settings since we might have moved from
+                     * internal to external storage or vice versa.
+                     */
+                    p.nativeLibraryPathString = nativeLibraryPathString;
+                }
+            }
+            if (p.sharedUser != sharedUser) {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Package " + name + " shared user changed from "
+                        + (p.sharedUser != null ? p.sharedUser.name : "<nothing>")
+                        + " to "
+                        + (sharedUser != null ? sharedUser.name : "<nothing>")
+                        + "; replacing with new");
+                p = null;
+            } else {
+                // If what we are scanning is a system (and possibly privileged) package,
+                // then make it so, regardless of whether it was previously installed only
+                // in the data partition.
+                final int sysPrivFlags = pkgFlags
+                        & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_PRIVILEGED);
+                p.pkgFlags |= sysPrivFlags;
+            }
+        }
+        if (p == null) {
+            if (origPackage != null) {
+                // We are consuming the data from an existing package.
+                p = new PackageSetting(origPackage.name, name, codePath, resourcePath,
+                        nativeLibraryPathString, vc, pkgFlags);
+                if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package "
+                        + name + " is adopting original package " + origPackage.name);
+                // Note that we will retain the new package's signature so
+                // that we can keep its data.
+                PackageSignatures s = p.signatures;
+                p.copyFrom(origPackage);
+                p.signatures = s;
+                p.sharedUser = origPackage.sharedUser;
+                p.appId = origPackage.appId;
+                p.origPackage = origPackage;
+                mRenamedPackages.put(name, origPackage.name);
+                name = origPackage.name;
+                // Update new package state.
+                p.setTimeStamp(codePath.lastModified());
+            } else {
+                p = new PackageSetting(name, realName, codePath, resourcePath,
+                        nativeLibraryPathString, vc, pkgFlags);
+                p.setTimeStamp(codePath.lastModified());
+                p.sharedUser = sharedUser;
+                // If this is not a system app, it starts out stopped.
+                if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+                    if (DEBUG_STOPPED) {
+                        RuntimeException e = new RuntimeException("here");
+                        e.fillInStackTrace();
+                        Slog.i(PackageManagerService.TAG, "Stopping package " + name, e);
+                    }
+                    List<UserInfo> users = getAllUsers();
+                    if (users != null && allowInstall) {
+                        for (UserInfo user : users) {
+                            // By default we consider this app to be installed
+                            // for the user if no user has been specified (which
+                            // means to leave it at its original value, and the
+                            // original default value is true), or we are being
+                            // asked to install for all users, or this is the
+                            // user we are installing for.
+                            final boolean installed = installUser == null
+                                    || installUser.getIdentifier() == UserHandle.USER_ALL
+                                    || installUser.getIdentifier() == user.id;
+                            p.setUserState(user.id, COMPONENT_ENABLED_STATE_DEFAULT,
+                                    installed,
+                                    true, // stopped,
+                                    true, // notLaunched
+                                    false, // blocked
+                                    null, null, null);
+                            writePackageRestrictionsLPr(user.id);
+                        }
+                    }
+                }
+                if (sharedUser != null) {
+                    p.appId = sharedUser.userId;
+                } else {
+                    // Clone the setting here for disabled system packages
+                    PackageSetting dis = mDisabledSysPackages.get(name);
+                    if (dis != null) {
+                        // For disabled packages a new setting is created
+                        // from the existing user id. This still has to be
+                        // added to list of user id's
+                        // Copy signatures from previous setting
+                        if (dis.signatures.mSignatures != null) {
+                            p.signatures.mSignatures = dis.signatures.mSignatures.clone();
+                        }
+                        p.appId = dis.appId;
+                        // Clone permissions
+                        p.grantedPermissions = new HashSet<String>(dis.grantedPermissions);
+                        // Clone component info
+                        List<UserInfo> users = getAllUsers();
+                        if (users != null) {
+                            for (UserInfo user : users) {
+                                int userId = user.id;
+                                p.setDisabledComponentsCopy(
+                                        dis.getDisabledComponents(userId), userId);
+                                p.setEnabledComponentsCopy(
+                                        dis.getEnabledComponents(userId), userId);
+                            }
+                        }
+                        // Add new setting to list of user ids
+                        addUserIdLPw(p.appId, p, name);
+                    } else {
+                        // Assign new user id
+                        p.appId = newUserIdLPw(p);
+                    }
+                }
+            }
+            if (p.appId < 0) {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Package " + name + " could not be assigned a valid uid");
+                return null;
+            }
+            if (add) {
+                // Finish adding new package by adding it and updating shared
+                // user preferences
+                addPackageSettingLPw(p, name, sharedUser);
+            }
+        } else {
+            if (installUser != null && allowInstall) {
+                // The caller has explicitly specified the user they want this
+                // package installed for, and the package already exists.
+                // Make sure it conforms to the new request.
+                List<UserInfo> users = getAllUsers();
+                if (users != null) {
+                    for (UserInfo user : users) {
+                        if (installUser.getIdentifier() == UserHandle.USER_ALL
+                                || installUser.getIdentifier() == user.id) {
+                            boolean installed = p.getInstalled(user.id);
+                            if (!installed) {
+                                p.setInstalled(true, user.id);
+                                writePackageRestrictionsLPr(user.id);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return p;
+    }
+
+    void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) {
+        p.pkg = pkg;
+        // pkg.mSetEnabled = p.getEnabled(userId);
+        // pkg.mSetStopped = p.getStopped(userId);
+        final String codePath = pkg.applicationInfo.sourceDir;
+        final String resourcePath = pkg.applicationInfo.publicSourceDir;
+        // Update code path if needed
+        if (!codePath.equalsIgnoreCase(p.codePathString)) {
+            Slog.w(PackageManagerService.TAG, "Code path for pkg : " + p.pkg.packageName +
+                    " changing from " + p.codePathString + " to " + codePath);
+            p.codePath = new File(codePath);
+            p.codePathString = codePath;
+        }
+        //Update resource path if needed
+        if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) {
+            Slog.w(PackageManagerService.TAG, "Resource path for pkg : " + p.pkg.packageName +
+                    " changing from " + p.resourcePathString + " to " + resourcePath);
+            p.resourcePath = new File(resourcePath);
+            p.resourcePathString = resourcePath;
+        }
+        // Update the native library path if needed
+        final String nativeLibraryPath = pkg.applicationInfo.nativeLibraryDir;
+        if (nativeLibraryPath != null
+                && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) {
+            p.nativeLibraryPathString = nativeLibraryPath;
+        }
+        // Update version code if needed
+        if (pkg.mVersionCode != p.versionCode) {
+            p.versionCode = pkg.mVersionCode;
+        }
+        // Update signatures if needed.
+        if (p.signatures.mSignatures == null) {
+            p.signatures.assignSignatures(pkg.mSignatures);
+        }
+        // Update flags if needed.
+        if (pkg.applicationInfo.flags != p.pkgFlags) {
+            p.pkgFlags = pkg.applicationInfo.flags;
+        }
+        // If this app defines a shared user id initialize
+        // the shared user signatures as well.
+        if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) {
+            p.sharedUser.signatures.assignSignatures(pkg.mSignatures);
+        }
+        addPackageSettingLPw(p, pkg.packageName, p.sharedUser);
+    }
+
+    // Utility method that adds a PackageSetting to mPackages and
+    // completes updating the shared user attributes
+    private void addPackageSettingLPw(PackageSetting p, String name,
+            SharedUserSetting sharedUser) {
+        mPackages.put(name, p);
+        if (sharedUser != null) {
+            if (p.sharedUser != null && p.sharedUser != sharedUser) {
+                PackageManagerService.reportSettingsProblem(Log.ERROR,
+                        "Package " + p.name + " was user "
+                        + p.sharedUser + " but is now " + sharedUser
+                        + "; I am not changing its files so it will probably fail!");
+                p.sharedUser.removePackage(p);
+            } else if (p.appId != sharedUser.userId) {
+                PackageManagerService.reportSettingsProblem(Log.ERROR,
+                    "Package " + p.name + " was user id " + p.appId
+                    + " but is now user " + sharedUser
+                    + " with id " + sharedUser.userId
+                    + "; I am not changing its files so it will probably fail!");
+            }
+
+            sharedUser.addPackage(p);
+            p.sharedUser = sharedUser;
+            p.appId = sharedUser.userId;
+        }
+    }
+
+    /*
+     * Update the shared user setting when a package using
+     * specifying the shared user id is removed. The gids
+     * associated with each permission of the deleted package
+     * are removed from the shared user's gid list only if its
+     * not in use by other permissions of packages in the
+     * shared user setting.
+     */
+    void updateSharedUserPermsLPw(PackageSetting deletedPs, int[] globalGids) {
+        if ((deletedPs == null) || (deletedPs.pkg == null)) {
+            Slog.i(PackageManagerService.TAG,
+                    "Trying to update info for null package. Just ignoring");
+            return;
+        }
+        // No sharedUserId
+        if (deletedPs.sharedUser == null) {
+            return;
+        }
+        SharedUserSetting sus = deletedPs.sharedUser;
+        // Update permissions
+        for (String eachPerm : deletedPs.pkg.requestedPermissions) {
+            boolean used = false;
+            if (!sus.grantedPermissions.contains(eachPerm)) {
+                continue;
+            }
+            for (PackageSetting pkg:sus.packages) {
+                if (pkg.pkg != null &&
+                        !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) &&
+                        pkg.pkg.requestedPermissions.contains(eachPerm)) {
+                    used = true;
+                    break;
+                }
+            }
+            if (!used) {
+                // can safely delete this permission from list
+                sus.grantedPermissions.remove(eachPerm);
+            }
+        }
+        // Update gids
+        int newGids[] = globalGids;
+        for (String eachPerm : sus.grantedPermissions) {
+            BasePermission bp = mPermissions.get(eachPerm);
+            if (bp != null) {
+                newGids = PackageManagerService.appendInts(newGids, bp.gids);
+            }
+        }
+        sus.gids = newGids;
+    }
+
+    int removePackageLPw(String name) {
+        final PackageSetting p = mPackages.get(name);
+        if (p != null) {
+            mPackages.remove(name);
+            if (p.sharedUser != null) {
+                p.sharedUser.removePackage(p);
+                if (p.sharedUser.packages.size() == 0) {
+                    mSharedUsers.remove(p.sharedUser.name);
+                    removeUserIdLPw(p.sharedUser.userId);
+                    return p.sharedUser.userId;
+                }
+            } else {
+                removeUserIdLPw(p.appId);
+                return p.appId;
+            }
+        }
+        return -1;
+    }
+
+    private void replacePackageLPw(String name, PackageSetting newp) {
+        final PackageSetting p = mPackages.get(name);
+        if (p != null) {
+            if (p.sharedUser != null) {
+                p.sharedUser.removePackage(p);
+                p.sharedUser.addPackage(newp);
+            } else {
+                replaceUserIdLPw(p.appId, newp);
+            }
+        }
+        mPackages.put(name, newp);
+    }
+
+    private boolean addUserIdLPw(int uid, Object obj, Object name) {
+        if (uid > Process.LAST_APPLICATION_UID) {
+            return false;
+        }
+
+        if (uid >= Process.FIRST_APPLICATION_UID) {
+            int N = mUserIds.size();
+            final int index = uid - Process.FIRST_APPLICATION_UID;
+            while (index >= N) {
+                mUserIds.add(null);
+                N++;
+            }
+            if (mUserIds.get(index) != null) {
+                PackageManagerService.reportSettingsProblem(Log.ERROR,
+                        "Adding duplicate user id: " + uid
+                        + " name=" + name);
+                return false;
+            }
+            mUserIds.set(index, obj);
+        } else {
+            if (mOtherUserIds.get(uid) != null) {
+                PackageManagerService.reportSettingsProblem(Log.ERROR,
+                        "Adding duplicate shared id: " + uid
+                        + " name=" + name);
+                return false;
+            }
+            mOtherUserIds.put(uid, obj);
+        }
+        return true;
+    }
+
+    public Object getUserIdLPr(int uid) {
+        if (uid >= Process.FIRST_APPLICATION_UID) {
+            final int N = mUserIds.size();
+            final int index = uid - Process.FIRST_APPLICATION_UID;
+            return index < N ? mUserIds.get(index) : null;
+        } else {
+            return mOtherUserIds.get(uid);
+        }
+    }
+
+    private void removeUserIdLPw(int uid) {
+        if (uid >= Process.FIRST_APPLICATION_UID) {
+            final int N = mUserIds.size();
+            final int index = uid - Process.FIRST_APPLICATION_UID;
+            if (index < N) mUserIds.set(index, null);
+        } else {
+            mOtherUserIds.remove(uid);
+        }
+        setFirstAvailableUid(uid+1);
+    }
+
+    private void replaceUserIdLPw(int uid, Object obj) {
+        if (uid >= Process.FIRST_APPLICATION_UID) {
+            final int N = mUserIds.size();
+            final int index = uid - Process.FIRST_APPLICATION_UID;
+            if (index < N) mUserIds.set(index, obj);
+        } else {
+            mOtherUserIds.put(uid, obj);
+        }
+    }
+
+    PreferredIntentResolver editPreferredActivitiesLPw(int userId) {
+        PreferredIntentResolver pir = mPreferredActivities.get(userId);
+        if (pir == null) {
+            pir = new PreferredIntentResolver();
+            mPreferredActivities.put(userId, pir);
+        }
+        return pir;
+    }
+
+    private File getUserPackagesStateFile(int userId) {
+        return new File(Environment.getUserSystemDirectory(userId), "package-restrictions.xml");
+    }
+
+    private File getUserPackagesStateBackupFile(int userId) {
+        return new File(Environment.getUserSystemDirectory(userId),
+                "package-restrictions-backup.xml");
+    }
+
+    void writeAllUsersPackageRestrictionsLPr() {
+        List<UserInfo> users = getAllUsers();
+        if (users == null) return;
+
+        for (UserInfo user : users) {
+            writePackageRestrictionsLPr(user.id);
+        }
+    }
+
+    void readAllUsersPackageRestrictionsLPr() {
+        List<UserInfo> users = getAllUsers();
+        if (users == null) {
+            readPackageRestrictionsLPr(0);
+            return;
+        }
+
+        for (UserInfo user : users) {
+            readPackageRestrictionsLPr(user.id);
+        }
+    }
+
+    private void readPreferredActivitiesLPw(XmlPullParser parser, int userId)
+            throws XmlPullParserException, IOException {
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                PreferredActivity pa = new PreferredActivity(parser);
+                if (pa.mPref.getParseError() == null) {
+                    editPreferredActivitiesLPw(userId).addFilter(pa);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: <preferred-activity> "
+                                    + pa.mPref.getParseError() + " at "
+                                    + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element under <preferred-activities>: " + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+    }
+
+    void readPackageRestrictionsLPr(int userId) {
+        if (DEBUG_MU) {
+            Log.i(TAG, "Reading package restrictions for user=" + userId);
+        }
+        FileInputStream str = null;
+        File userPackagesStateFile = getUserPackagesStateFile(userId);
+        File backupFile = getUserPackagesStateBackupFile(userId);
+        if (backupFile.exists()) {
+            try {
+                str = new FileInputStream(backupFile);
+                mReadMessages.append("Reading from backup stopped packages file\n");
+                PackageManagerService.reportSettingsProblem(Log.INFO,
+                        "Need to read from backup stopped packages file");
+                if (userPackagesStateFile.exists()) {
+                    // If both the backup and normal file exist, we
+                    // ignore the normal one since it might have been
+                    // corrupted.
+                    Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
+                            + userPackagesStateFile);
+                    userPackagesStateFile.delete();
+                }
+            } catch (java.io.IOException e) {
+                // We'll try for the normal settings file.
+            }
+        }
+
+        try {
+            if (str == null) {
+                if (!userPackagesStateFile.exists()) {
+                    mReadMessages.append("No stopped packages file found\n");
+                    PackageManagerService.reportSettingsProblem(Log.INFO,
+                            "No stopped packages file; "
+                            + "assuming all started");
+                    // At first boot, make sure no packages are stopped.
+                    // We usually want to have third party apps initialize
+                    // in the stopped state, but not at first boot.  Also
+                    // consider all applications to be installed.
+                    for (PackageSetting pkg : mPackages.values()) {
+                        pkg.setUserState(userId, COMPONENT_ENABLED_STATE_DEFAULT,
+                                true,   // installed
+                                false,  // stopped
+                                false,  // notLaunched
+                                false,  // blocked
+                                null, null, null);
+                    }
+                    return;
+                }
+                str = new FileInputStream(userPackagesStateFile);
+            }
+            final XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(str, null);
+
+            int type;
+            while ((type=parser.next()) != XmlPullParser.START_TAG
+                       && type != XmlPullParser.END_DOCUMENT) {
+                ;
+            }
+
+            if (type != XmlPullParser.START_TAG) {
+                mReadMessages.append("No start tag found in package restrictions file\n");
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "No start tag found in package manager stopped packages");
+                return;
+            }
+
+            int outerDepth = parser.getDepth();
+            PackageSetting ps = null;
+            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                   && (type != XmlPullParser.END_TAG
+                           || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG
+                        || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+
+                String tagName = parser.getName();
+                if (tagName.equals(TAG_PACKAGE)) {
+                    String name = parser.getAttributeValue(null, ATTR_NAME);
+                    ps = mPackages.get(name);
+                    if (ps == null) {
+                        Slog.w(PackageManagerService.TAG, "No package known for stopped package: "
+                                + name);
+                        XmlUtils.skipCurrentTag(parser);
+                        continue;
+                    }
+                    final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
+                    final int enabled = enabledStr == null
+                            ? COMPONENT_ENABLED_STATE_DEFAULT : Integer.parseInt(enabledStr);
+                    final String enabledCaller = parser.getAttributeValue(null,
+                            ATTR_ENABLED_CALLER);
+                    final String installedStr = parser.getAttributeValue(null, ATTR_INSTALLED);
+                    final boolean installed = installedStr == null
+                            ? true : Boolean.parseBoolean(installedStr);
+                    final String stoppedStr = parser.getAttributeValue(null, ATTR_STOPPED);
+                    final boolean stopped = stoppedStr == null
+                            ? false : Boolean.parseBoolean(stoppedStr);
+                    final String blockedStr = parser.getAttributeValue(null, ATTR_BLOCKED);
+                    final boolean blocked = blockedStr == null
+                            ? false : Boolean.parseBoolean(blockedStr);
+                    final String notLaunchedStr = parser.getAttributeValue(null, ATTR_NOT_LAUNCHED);
+                    final boolean notLaunched = stoppedStr == null
+                            ? false : Boolean.parseBoolean(notLaunchedStr);
+
+                    HashSet<String> enabledComponents = null;
+                    HashSet<String> disabledComponents = null;
+
+                    int packageDepth = parser.getDepth();
+                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                            && (type != XmlPullParser.END_TAG
+                            || parser.getDepth() > packageDepth)) {
+                        if (type == XmlPullParser.END_TAG
+                                || type == XmlPullParser.TEXT) {
+                            continue;
+                        }
+                        tagName = parser.getName();
+                        if (tagName.equals(TAG_ENABLED_COMPONENTS)) {
+                            enabledComponents = readComponentsLPr(parser);
+                        } else if (tagName.equals(TAG_DISABLED_COMPONENTS)) {
+                            disabledComponents = readComponentsLPr(parser);
+                        }
+                    }
+
+                    ps.setUserState(userId, enabled, installed, stopped, notLaunched, blocked,
+                            enabledCaller, enabledComponents, disabledComponents);
+                } else if (tagName.equals("preferred-activities")) {
+                    readPreferredActivitiesLPw(parser, userId);
+                } else {
+                    Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
+                          + parser.getName());
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+
+            str.close();
+
+        } catch (XmlPullParserException e) {
+            mReadMessages.append("Error reading: " + e.toString());
+            PackageManagerService.reportSettingsProblem(Log.ERROR,
+                    "Error reading stopped packages: " + e);
+            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
+
+        } catch (java.io.IOException e) {
+            mReadMessages.append("Error reading: " + e.toString());
+            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
+            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
+        }
+    }
+
+    private HashSet<String> readComponentsLPr(XmlPullParser parser)
+            throws IOException, XmlPullParserException {
+        HashSet<String> components = null;
+        int type;
+        int outerDepth = parser.getDepth();
+        String tagName;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG
+                || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG
+                    || type == XmlPullParser.TEXT) {
+                continue;
+            }
+            tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                String componentName = parser.getAttributeValue(null, ATTR_NAME);
+                if (componentName != null) {
+                    if (components == null) {
+                        components = new HashSet<String>();
+                    }
+                    components.add(componentName);
+                }
+            }
+        }
+        return components;
+    }
+
+    void writePreferredActivitiesLPr(XmlSerializer serializer, int userId, boolean full)
+            throws IllegalArgumentException, IllegalStateException, IOException {
+        serializer.startTag(null, "preferred-activities");
+        PreferredIntentResolver pir = mPreferredActivities.get(userId);
+        if (pir != null) {
+            for (final PreferredActivity pa : pir.filterSet()) {
+                serializer.startTag(null, TAG_ITEM);
+                pa.writeToXml(serializer, full);
+                serializer.endTag(null, TAG_ITEM);
+            }
+        }
+        serializer.endTag(null, "preferred-activities");
+    }
+
+    void writePackageRestrictionsLPr(int userId) {
+        if (DEBUG_MU) {
+            Log.i(TAG, "Writing package restrictions for user=" + userId);
+        }
+        // Keep the old stopped packages around until we know the new ones have
+        // been successfully written.
+        File userPackagesStateFile = getUserPackagesStateFile(userId);
+        File backupFile = getUserPackagesStateBackupFile(userId);
+        new File(userPackagesStateFile.getParent()).mkdirs();
+        if (userPackagesStateFile.exists()) {
+            // Presence of backup settings file indicates that we failed
+            // to persist packages earlier. So preserve the older
+            // backup for future reference since the current packages
+            // might have been corrupted.
+            if (!backupFile.exists()) {
+                if (!userPackagesStateFile.renameTo(backupFile)) {
+                    Log.wtf(PackageManagerService.TAG, "Unable to backup user packages state file, "
+                            + "current changes will be lost at reboot");
+                    return;
+                }
+            } else {
+                userPackagesStateFile.delete();
+                Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup");
+            }
+        }
+
+        try {
+            final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile);
+            final BufferedOutputStream str = new BufferedOutputStream(fstr);
+
+            final XmlSerializer serializer = new FastXmlSerializer();
+            serializer.setOutput(str, "utf-8");
+            serializer.startDocument(null, true);
+            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+
+            serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS);
+
+            for (final PackageSetting pkg : mPackages.values()) {
+                PackageUserState ustate = pkg.readUserState(userId);
+                if (ustate.stopped || ustate.notLaunched || !ustate.installed
+                        || ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT
+                        || ustate.blocked
+                        || (ustate.enabledComponents != null
+                                && ustate.enabledComponents.size() > 0)
+                        || (ustate.disabledComponents != null
+                                && ustate.disabledComponents.size() > 0)) {
+                    serializer.startTag(null, TAG_PACKAGE);
+                    serializer.attribute(null, ATTR_NAME, pkg.name);
+                    if (DEBUG_MU) Log.i(TAG, "  pkg=" + pkg.name + ", state=" + ustate.enabled);
+
+                    if (!ustate.installed) {
+                        serializer.attribute(null, ATTR_INSTALLED, "false");
+                    }
+                    if (ustate.stopped) {
+                        serializer.attribute(null, ATTR_STOPPED, "true");
+                    }
+                    if (ustate.notLaunched) {
+                        serializer.attribute(null, ATTR_NOT_LAUNCHED, "true");
+                    }
+                    if (ustate.blocked) {
+                        serializer.attribute(null, ATTR_BLOCKED, "true");
+                    }
+                    if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) {
+                        serializer.attribute(null, ATTR_ENABLED,
+                                Integer.toString(ustate.enabled));
+                        if (ustate.lastDisableAppCaller != null) {
+                            serializer.attribute(null, ATTR_ENABLED_CALLER,
+                                    ustate.lastDisableAppCaller);
+                        }
+                    }
+                    if (ustate.enabledComponents != null
+                            && ustate.enabledComponents.size() > 0) {
+                        serializer.startTag(null, TAG_ENABLED_COMPONENTS);
+                        for (final String name : ustate.enabledComponents) {
+                            serializer.startTag(null, TAG_ITEM);
+                            serializer.attribute(null, ATTR_NAME, name);
+                            serializer.endTag(null, TAG_ITEM);
+                        }
+                        serializer.endTag(null, TAG_ENABLED_COMPONENTS);
+                    }
+                    if (ustate.disabledComponents != null
+                            && ustate.disabledComponents.size() > 0) {
+                        serializer.startTag(null, TAG_DISABLED_COMPONENTS);
+                        for (final String name : ustate.disabledComponents) {
+                            serializer.startTag(null, TAG_ITEM);
+                            serializer.attribute(null, ATTR_NAME, name);
+                            serializer.endTag(null, TAG_ITEM);
+                        }
+                        serializer.endTag(null, TAG_DISABLED_COMPONENTS);
+                    }
+                    serializer.endTag(null, TAG_PACKAGE);
+                }
+            }
+
+            writePreferredActivitiesLPr(serializer, userId, true);
+
+            serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS);
+
+            serializer.endDocument();
+
+            str.flush();
+            FileUtils.sync(fstr);
+            str.close();
+
+            // New settings successfully written, old ones are no longer
+            // needed.
+            backupFile.delete();
+            FileUtils.setPermissions(userPackagesStateFile.toString(),
+                    FileUtils.S_IRUSR|FileUtils.S_IWUSR
+                    |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
+                    -1, -1);
+
+            // Done, all is good!
+            return;
+        } catch(java.io.IOException e) {
+            Log.wtf(PackageManagerService.TAG,
+                    "Unable to write package manager user packages state, "
+                    + " current changes will be lost at reboot", e);
+        }
+
+        // Clean up partially written files
+        if (userPackagesStateFile.exists()) {
+            if (!userPackagesStateFile.delete()) {
+                Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: "
+                        + mStoppedPackagesFilename);
+            }
+        }
+    }
+
+    // Note: assumed "stopped" field is already cleared in all packages.
+    // Legacy reader, used to read in the old file format after an upgrade. Not used after that.
+    void readStoppedLPw() {
+        FileInputStream str = null;
+        if (mBackupStoppedPackagesFilename.exists()) {
+            try {
+                str = new FileInputStream(mBackupStoppedPackagesFilename);
+                mReadMessages.append("Reading from backup stopped packages file\n");
+                PackageManagerService.reportSettingsProblem(Log.INFO,
+                        "Need to read from backup stopped packages file");
+                if (mSettingsFilename.exists()) {
+                    // If both the backup and normal file exist, we
+                    // ignore the normal one since it might have been
+                    // corrupted.
+                    Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
+                            + mStoppedPackagesFilename);
+                    mStoppedPackagesFilename.delete();
+                }
+            } catch (java.io.IOException e) {
+                // We'll try for the normal settings file.
+            }
+        }
+
+        try {
+            if (str == null) {
+                if (!mStoppedPackagesFilename.exists()) {
+                    mReadMessages.append("No stopped packages file found\n");
+                    PackageManagerService.reportSettingsProblem(Log.INFO,
+                            "No stopped packages file file; assuming all started");
+                    // At first boot, make sure no packages are stopped.
+                    // We usually want to have third party apps initialize
+                    // in the stopped state, but not at first boot.
+                    for (PackageSetting pkg : mPackages.values()) {
+                        pkg.setStopped(false, 0);
+                        pkg.setNotLaunched(false, 0);
+                    }
+                    return;
+                }
+                str = new FileInputStream(mStoppedPackagesFilename);
+            }
+            final XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(str, null);
+
+            int type;
+            while ((type=parser.next()) != XmlPullParser.START_TAG
+                       && type != XmlPullParser.END_DOCUMENT) {
+                ;
+            }
+
+            if (type != XmlPullParser.START_TAG) {
+                mReadMessages.append("No start tag found in stopped packages file\n");
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "No start tag found in package manager stopped packages");
+                return;
+            }
+
+            int outerDepth = parser.getDepth();
+            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                   && (type != XmlPullParser.END_TAG
+                           || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG
+                        || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+
+                String tagName = parser.getName();
+                if (tagName.equals(TAG_PACKAGE)) {
+                    String name = parser.getAttributeValue(null, ATTR_NAME);
+                    PackageSetting ps = mPackages.get(name);
+                    if (ps != null) {
+                        ps.setStopped(true, 0);
+                        if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) {
+                            ps.setNotLaunched(true, 0);
+                        }
+                    } else {
+                        Slog.w(PackageManagerService.TAG,
+                                "No package known for stopped package: " + name);
+                    }
+                    XmlUtils.skipCurrentTag(parser);
+                } else {
+                    Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
+                          + parser.getName());
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+
+            str.close();
+
+        } catch (XmlPullParserException e) {
+            mReadMessages.append("Error reading: " + e.toString());
+            PackageManagerService.reportSettingsProblem(Log.ERROR,
+                    "Error reading stopped packages: " + e);
+            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
+
+        } catch (java.io.IOException e) {
+            mReadMessages.append("Error reading: " + e.toString());
+            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
+            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
+
+        }
+    }
+
+    void writeLPr() {
+        //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024);
+
+        // Keep the old settings around until we know the new ones have
+        // been successfully written.
+        if (mSettingsFilename.exists()) {
+            // Presence of backup settings file indicates that we failed
+            // to persist settings earlier. So preserve the older
+            // backup for future reference since the current settings
+            // might have been corrupted.
+            if (!mBackupSettingsFilename.exists()) {
+                if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
+                    Log.wtf(PackageManagerService.TAG, "Unable to backup package manager settings, "
+                            + " current changes will be lost at reboot");
+                    return;
+                }
+            } else {
+                mSettingsFilename.delete();
+                Slog.w(PackageManagerService.TAG, "Preserving older settings backup");
+            }
+        }
+
+        mPastSignatures.clear();
+
+        try {
+            FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
+            BufferedOutputStream str = new BufferedOutputStream(fstr);
+
+            //XmlSerializer serializer = XmlUtils.serializerInstance();
+            XmlSerializer serializer = new FastXmlSerializer();
+            serializer.setOutput(str, "utf-8");
+            serializer.startDocument(null, true);
+            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+
+            serializer.startTag(null, "packages");
+
+            serializer.startTag(null, "last-platform-version");
+            serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform));
+            serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform));
+            serializer.endTag(null, "last-platform-version");
+
+            if (mVerifierDeviceIdentity != null) {
+                serializer.startTag(null, "verifier");
+                serializer.attribute(null, "device", mVerifierDeviceIdentity.toString());
+                serializer.endTag(null, "verifier");
+            }
+
+            if (mReadExternalStorageEnforced != null) {
+                serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE);
+                serializer.attribute(
+                        null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0");
+                serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE);
+            }
+
+            serializer.startTag(null, "permission-trees");
+            for (BasePermission bp : mPermissionTrees.values()) {
+                writePermissionLPr(serializer, bp);
+            }
+            serializer.endTag(null, "permission-trees");
+
+            serializer.startTag(null, "permissions");
+            for (BasePermission bp : mPermissions.values()) {
+                writePermissionLPr(serializer, bp);
+            }
+            serializer.endTag(null, "permissions");
+
+            for (final PackageSetting pkg : mPackages.values()) {
+                writePackageLPr(serializer, pkg);
+            }
+
+            for (final PackageSetting pkg : mDisabledSysPackages.values()) {
+                writeDisabledSysPackageLPr(serializer, pkg);
+            }
+
+            for (final SharedUserSetting usr : mSharedUsers.values()) {
+                serializer.startTag(null, "shared-user");
+                serializer.attribute(null, ATTR_NAME, usr.name);
+                serializer.attribute(null, "userId",
+                        Integer.toString(usr.userId));
+                usr.signatures.writeXml(serializer, "sigs", mPastSignatures);
+                serializer.startTag(null, "perms");
+                for (String name : usr.grantedPermissions) {
+                    serializer.startTag(null, TAG_ITEM);
+                    serializer.attribute(null, ATTR_NAME, name);
+                    serializer.endTag(null, TAG_ITEM);
+                }
+                serializer.endTag(null, "perms");
+                serializer.endTag(null, "shared-user");
+            }
+
+            if (mPackagesToBeCleaned.size() > 0) {
+                for (PackageCleanItem item : mPackagesToBeCleaned) {
+                    final String userStr = Integer.toString(item.userId);
+                    serializer.startTag(null, "cleaning-package");
+                    serializer.attribute(null, ATTR_NAME, item.packageName);
+                    serializer.attribute(null, ATTR_CODE, item.andCode ? "true" : "false");
+                    serializer.attribute(null, ATTR_USER, userStr);
+                    serializer.endTag(null, "cleaning-package");
+                }
+            }
+            
+            if (mRenamedPackages.size() > 0) {
+                for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
+                    serializer.startTag(null, "renamed-package");
+                    serializer.attribute(null, "new", e.getKey());
+                    serializer.attribute(null, "old", e.getValue());
+                    serializer.endTag(null, "renamed-package");
+                }
+            }
+            
+            mKeySetManager.writeKeySetManagerLPr(serializer);
+
+            serializer.endTag(null, "packages");
+
+            serializer.endDocument();
+
+            str.flush();
+            FileUtils.sync(fstr);
+            str.close();
+
+            // New settings successfully written, old ones are no longer
+            // needed.
+            mBackupSettingsFilename.delete();
+            FileUtils.setPermissions(mSettingsFilename.toString(),
+                    FileUtils.S_IRUSR|FileUtils.S_IWUSR
+                    |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
+                    -1, -1);
+
+            // Write package list file now, use a JournaledFile.
+            File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp");
+            JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
+
+            final File writeTarget = journal.chooseForWrite();
+            fstr = new FileOutputStream(writeTarget);
+            str = new BufferedOutputStream(fstr);
+            try {
+                FileUtils.setPermissions(fstr.getFD(), 0660, SYSTEM_UID, PACKAGE_INFO_GID);
+
+                StringBuilder sb = new StringBuilder();
+                for (final PackageSetting pkg : mPackages.values()) {
+                    if (pkg.pkg == null || pkg.pkg.applicationInfo == null) {
+                        Slog.w(TAG, "Skipping " + pkg + " due to missing metadata");
+                        continue;
+                    }
+
+                    final ApplicationInfo ai = pkg.pkg.applicationInfo;
+                    final String dataPath = ai.dataDir;
+                    final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
+                    final int[] gids = pkg.getGids();
+
+                    // Avoid any application that has a space in its path.
+                    if (dataPath.indexOf(" ") >= 0)
+                        continue;
+
+                    // we store on each line the following information for now:
+                    //
+                    // pkgName    - package name
+                    // userId     - application-specific user id
+                    // debugFlag  - 0 or 1 if the package is debuggable.
+                    // dataPath   - path to package's data path
+                    // seinfo     - seinfo label for the app (assigned at install time)
+                    // gids       - supplementary gids this app launches with
+                    //
+                    // NOTE: We prefer not to expose all ApplicationInfo flags for now.
+                    //
+                    // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS
+                    // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES:
+                    //   system/core/run-as/run-as.c
+                    //   system/core/sdcard/sdcard.c
+                    //
+                    sb.setLength(0);
+                    sb.append(ai.packageName);
+                    sb.append(" ");
+                    sb.append((int)ai.uid);
+                    sb.append(isDebug ? " 1 " : " 0 ");
+                    sb.append(dataPath);
+                    sb.append(" ");
+                    sb.append(ai.seinfo);
+                    sb.append(" ");
+                    if (gids != null && gids.length > 0) {
+                        sb.append(gids[0]);
+                        for (int i = 1; i < gids.length; i++) {
+                            sb.append(",");
+                            sb.append(gids[i]);
+                        }
+                    } else {
+                        sb.append("none");
+                    }
+                    sb.append("\n");
+                    str.write(sb.toString().getBytes());
+                }
+                str.flush();
+                FileUtils.sync(fstr);
+                str.close();
+                journal.commit();
+            } catch (Exception e) {
+                Log.wtf(TAG, "Failed to write packages.list", e);
+                IoUtils.closeQuietly(str);
+                journal.rollback();
+            }
+
+            writeAllUsersPackageRestrictionsLPr();
+            return;
+
+        } catch(XmlPullParserException e) {
+            Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
+                    + "current changes will be lost at reboot", e);
+        } catch(java.io.IOException e) {
+            Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
+                    + "current changes will be lost at reboot", e);
+        }
+        // Clean up partially written files
+        if (mSettingsFilename.exists()) {
+            if (!mSettingsFilename.delete()) {
+                Log.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: "
+                        + mSettingsFilename);
+            }
+        }
+        //Debug.stopMethodTracing();
+    }
+
+    void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
+            throws java.io.IOException {
+        serializer.startTag(null, "updated-package");
+        serializer.attribute(null, ATTR_NAME, pkg.name);
+        if (pkg.realName != null) {
+            serializer.attribute(null, "realName", pkg.realName);
+        }
+        serializer.attribute(null, "codePath", pkg.codePathString);
+        serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
+        serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
+        serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
+        serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
+        if (!pkg.resourcePathString.equals(pkg.codePathString)) {
+            serializer.attribute(null, "resourcePath", pkg.resourcePathString);
+        }
+        if (pkg.nativeLibraryPathString != null) {
+            serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
+        }
+        if (pkg.sharedUser == null) {
+            serializer.attribute(null, "userId", Integer.toString(pkg.appId));
+        } else {
+            serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId));
+        }
+        serializer.startTag(null, "perms");
+        if (pkg.sharedUser == null) {
+            // If this is a shared user, the permissions will
+            // be written there. We still need to write an
+            // empty permissions list so permissionsFixed will
+            // be set.
+            for (final String name : pkg.grantedPermissions) {
+                BasePermission bp = mPermissions.get(name);
+                if (bp != null) {
+                    // We only need to write signature or system permissions but
+                    // this wont
+                    // match the semantics of grantedPermissions. So write all
+                    // permissions.
+                    serializer.startTag(null, TAG_ITEM);
+                    serializer.attribute(null, ATTR_NAME, name);
+                    serializer.endTag(null, TAG_ITEM);
+                }
+            }
+        }
+        serializer.endTag(null, "perms");
+        serializer.endTag(null, "updated-package");
+    }
+
+    void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg)
+            throws java.io.IOException {
+        serializer.startTag(null, "package");
+        serializer.attribute(null, ATTR_NAME, pkg.name);
+        if (pkg.realName != null) {
+            serializer.attribute(null, "realName", pkg.realName);
+        }
+        serializer.attribute(null, "codePath", pkg.codePathString);
+        if (!pkg.resourcePathString.equals(pkg.codePathString)) {
+            serializer.attribute(null, "resourcePath", pkg.resourcePathString);
+        }
+        if (pkg.nativeLibraryPathString != null) {
+            serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
+        }
+        serializer.attribute(null, "flags", Integer.toString(pkg.pkgFlags));
+        serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
+        serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
+        serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
+        serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
+        if (pkg.sharedUser == null) {
+            serializer.attribute(null, "userId", Integer.toString(pkg.appId));
+        } else {
+            serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId));
+        }
+        if (pkg.uidError) {
+            serializer.attribute(null, "uidError", "true");
+        }
+        if (pkg.installStatus == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
+            serializer.attribute(null, "installStatus", "false");
+        }
+        if (pkg.installerPackageName != null) {
+            serializer.attribute(null, "installer", pkg.installerPackageName);
+        }
+        pkg.signatures.writeXml(serializer, "sigs", mPastSignatures);
+        if ((pkg.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
+            serializer.startTag(null, "perms");
+            if (pkg.sharedUser == null) {
+                // If this is a shared user, the permissions will
+                // be written there. We still need to write an
+                // empty permissions list so permissionsFixed will
+                // be set.
+                for (final String name : pkg.grantedPermissions) {
+                    serializer.startTag(null, TAG_ITEM);
+                    serializer.attribute(null, ATTR_NAME, name);
+                    serializer.endTag(null, TAG_ITEM);
+                }
+            }
+            serializer.endTag(null, "perms");
+        }
+
+        writeSigningKeySetsLPr(serializer, pkg.keySetData);
+        writeKeySetAliasesLPr(serializer, pkg.keySetData);
+
+        serializer.endTag(null, "package");
+    }
+
+    void writeSigningKeySetsLPr(XmlSerializer serializer,
+            PackageKeySetData data) throws IOException {
+        for (long id : data.getSigningKeySets()) {
+            serializer.startTag(null, "signing-keyset");
+            serializer.attribute(null, "identifier", Long.toString(id));
+            serializer.endTag(null, "signing-keyset");
+        }
+    }
+
+    void writeKeySetAliasesLPr(XmlSerializer serializer,
+            PackageKeySetData data) throws IOException {
+        for (Map.Entry<String, Long> e: data.getAliases().entrySet()) {
+            serializer.startTag(null, "defined-keyset");
+            serializer.attribute(null, "alias", e.getKey());
+            serializer.attribute(null, "identifier", Long.toString(e.getValue()));
+            serializer.endTag(null, "defined-keyset");
+        }
+    }
+
+    void writePermissionLPr(XmlSerializer serializer, BasePermission bp)
+            throws XmlPullParserException, java.io.IOException {
+        if (bp.type != BasePermission.TYPE_BUILTIN && bp.sourcePackage != null) {
+            serializer.startTag(null, TAG_ITEM);
+            serializer.attribute(null, ATTR_NAME, bp.name);
+            serializer.attribute(null, "package", bp.sourcePackage);
+            if (bp.protectionLevel != PermissionInfo.PROTECTION_NORMAL) {
+                serializer.attribute(null, "protection", Integer.toString(bp.protectionLevel));
+            }
+            if (PackageManagerService.DEBUG_SETTINGS)
+                Log.v(PackageManagerService.TAG, "Writing perm: name=" + bp.name + " type="
+                        + bp.type);
+            if (bp.type == BasePermission.TYPE_DYNAMIC) {
+                final PermissionInfo pi = bp.perm != null ? bp.perm.info : bp.pendingInfo;
+                if (pi != null) {
+                    serializer.attribute(null, "type", "dynamic");
+                    if (pi.icon != 0) {
+                        serializer.attribute(null, "icon", Integer.toString(pi.icon));
+                    }
+                    if (pi.nonLocalizedLabel != null) {
+                        serializer.attribute(null, "label", pi.nonLocalizedLabel.toString());
+                    }
+                }
+            }
+            serializer.endTag(null, TAG_ITEM);
+        }
+    }
+
+    ArrayList<PackageSetting> getListOfIncompleteInstallPackagesLPr() {
+        final HashSet<String> kList = new HashSet<String>(mPackages.keySet());
+        final Iterator<String> its = kList.iterator();
+        final ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>();
+        while (its.hasNext()) {
+            final String key = its.next();
+            final PackageSetting ps = mPackages.get(key);
+            if (ps.getInstallStatus() == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
+                ret.add(ps);
+            }
+        }
+        return ret;
+    }
+
+    void addPackageToCleanLPw(PackageCleanItem pkg) {
+        if (!mPackagesToBeCleaned.contains(pkg)) {
+            mPackagesToBeCleaned.add(pkg);
+        }
+    }
+
+    boolean readLPw(PackageManagerService service, List<UserInfo> users, int sdkVersion,
+            boolean onlyCore) {
+        FileInputStream str = null;
+        if (mBackupSettingsFilename.exists()) {
+            try {
+                str = new FileInputStream(mBackupSettingsFilename);
+                mReadMessages.append("Reading from backup settings file\n");
+                PackageManagerService.reportSettingsProblem(Log.INFO,
+                        "Need to read from backup settings file");
+                if (mSettingsFilename.exists()) {
+                    // If both the backup and settings file exist, we
+                    // ignore the settings since it might have been
+                    // corrupted.
+                    Slog.w(PackageManagerService.TAG, "Cleaning up settings file "
+                            + mSettingsFilename);
+                    mSettingsFilename.delete();
+                }
+            } catch (java.io.IOException e) {
+                // We'll try for the normal settings file.
+            }
+        }
+
+        mPendingPackages.clear();
+        mPastSignatures.clear();
+
+        try {
+            if (str == null) {
+                if (!mSettingsFilename.exists()) {
+                    mReadMessages.append("No settings file found\n");
+                    PackageManagerService.reportSettingsProblem(Log.INFO,
+                            "No settings file; creating initial state");
+                    mInternalSdkPlatform = mExternalSdkPlatform = sdkVersion;
+                    return false;
+                }
+                str = new FileInputStream(mSettingsFilename);
+            }
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(str, null);
+
+            int type;
+            while ((type = parser.next()) != XmlPullParser.START_TAG
+                    && type != XmlPullParser.END_DOCUMENT) {
+                ;
+            }
+
+            if (type != XmlPullParser.START_TAG) {
+                mReadMessages.append("No start tag found in settings file\n");
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "No start tag found in package manager settings");
+                Log.wtf(PackageManagerService.TAG,
+                        "No start tag found in package manager settings");
+                return false;
+            }
+
+            int outerDepth = parser.getDepth();
+            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+
+                String tagName = parser.getName();
+                if (tagName.equals("package")) {
+                    readPackageLPw(parser);
+                } else if (tagName.equals("permissions")) {
+                    readPermissionsLPw(mPermissions, parser);
+                } else if (tagName.equals("permission-trees")) {
+                    readPermissionsLPw(mPermissionTrees, parser);
+                } else if (tagName.equals("shared-user")) {
+                    readSharedUserLPw(parser);
+                } else if (tagName.equals("preferred-packages")) {
+                    // no longer used.
+                } else if (tagName.equals("preferred-activities")) {
+                    // Upgrading from old single-user implementation;
+                    // these are the preferred activities for user 0.
+                    readPreferredActivitiesLPw(parser, 0);
+                } else if (tagName.equals("updated-package")) {
+                    readDisabledSysPackageLPw(parser);
+                } else if (tagName.equals("cleaning-package")) {
+                    String name = parser.getAttributeValue(null, ATTR_NAME);
+                    String userStr = parser.getAttributeValue(null, ATTR_USER);
+                    String codeStr = parser.getAttributeValue(null, ATTR_CODE);
+                    if (name != null) {
+                        int userId = 0;
+                        boolean andCode = true;
+                        try {
+                            if (userStr != null) {
+                                userId = Integer.parseInt(userStr);
+                            }
+                        } catch (NumberFormatException e) {
+                        }
+                        if (codeStr != null) {
+                            andCode = Boolean.parseBoolean(codeStr);
+                        }
+                        addPackageToCleanLPw(new PackageCleanItem(userId, name, andCode));
+                    }
+                } else if (tagName.equals("renamed-package")) {
+                    String nname = parser.getAttributeValue(null, "new");
+                    String oname = parser.getAttributeValue(null, "old");
+                    if (nname != null && oname != null) {
+                        mRenamedPackages.put(nname, oname);
+                    }
+                } else if (tagName.equals("last-platform-version")) {
+                    mInternalSdkPlatform = mExternalSdkPlatform = 0;
+                    try {
+                        String internal = parser.getAttributeValue(null, "internal");
+                        if (internal != null) {
+                            mInternalSdkPlatform = Integer.parseInt(internal);
+                        }
+                        String external = parser.getAttributeValue(null, "external");
+                        if (external != null) {
+                            mExternalSdkPlatform = Integer.parseInt(external);
+                        }
+                    } catch (NumberFormatException e) {
+                    }
+                } else if (tagName.equals("verifier")) {
+                    final String deviceIdentity = parser.getAttributeValue(null, "device");
+                    try {
+                        mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity);
+                    } catch (IllegalArgumentException e) {
+                        Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: "
+                                + e.getMessage());
+                    }
+                } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
+                    final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT);
+                    mReadExternalStorageEnforced = "1".equals(enforcement);
+                } else if (tagName.equals("keyset-settings")) {
+                    mKeySetManager.readKeySetsLPw(parser);
+                } else {
+                    Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: "
+                            + parser.getName());
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+
+            str.close();
+
+        } catch (XmlPullParserException e) {
+            mReadMessages.append("Error reading: " + e.toString());
+            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
+            Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
+
+        } catch (java.io.IOException e) {
+            mReadMessages.append("Error reading: " + e.toString());
+            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
+            Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
+        }
+
+        final int N = mPendingPackages.size();
+        for (int i = 0; i < N; i++) {
+            final PendingPackage pp = mPendingPackages.get(i);
+            Object idObj = getUserIdLPr(pp.sharedId);
+            if (idObj != null && idObj instanceof SharedUserSetting) {
+                PackageSetting p = getPackageLPw(pp.name, null, pp.realName,
+                        (SharedUserSetting) idObj, pp.codePath, pp.resourcePath,
+                        pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags,
+                        null, true /* add */, false /* allowInstall */);
+                if (p == null) {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Unable to create application package for " + pp.name);
+                    continue;
+                }
+                p.copyFrom(pp);
+            } else if (idObj != null) {
+                String msg = "Bad package setting: package " + pp.name + " has shared uid "
+                        + pp.sharedId + " that is not a shared uid\n";
+                mReadMessages.append(msg);
+                PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
+            } else {
+                String msg = "Bad package setting: package " + pp.name + " has shared uid "
+                        + pp.sharedId + " that is not defined\n";
+                mReadMessages.append(msg);
+                PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
+            }
+        }
+        mPendingPackages.clear();
+
+        if (mBackupStoppedPackagesFilename.exists()
+                || mStoppedPackagesFilename.exists()) {
+            // Read old file
+            readStoppedLPw();
+            mBackupStoppedPackagesFilename.delete();
+            mStoppedPackagesFilename.delete();
+            // Migrate to new file format
+            writePackageRestrictionsLPr(0);
+        } else {
+            if (users == null) {
+                readPackageRestrictionsLPr(0);
+            } else {
+                for (UserInfo user : users) {
+                    readPackageRestrictionsLPr(user.id);
+                }
+            }
+        }
+
+        /*
+         * Make sure all the updated system packages have their shared users
+         * associated with them.
+         */
+        final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator();
+        while (disabledIt.hasNext()) {
+            final PackageSetting disabledPs = disabledIt.next();
+            final Object id = getUserIdLPr(disabledPs.appId);
+            if (id != null && id instanceof SharedUserSetting) {
+                disabledPs.sharedUser = (SharedUserSetting) id;
+            }
+        }
+
+        mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, "
+                + mSharedUsers.size() + " shared uids\n");
+
+        return true;
+    }
+
+    void readDefaultPreferredAppsLPw(PackageManagerService service, int userId) {
+        // First pull data from any pre-installed apps.
+        for (PackageSetting ps : mPackages.values()) {
+            if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null
+                    && ps.pkg.preferredActivityFilters != null) {
+                ArrayList<PackageParser.ActivityIntentInfo> intents
+                        = ps.pkg.preferredActivityFilters;
+                for (int i=0; i<intents.size(); i++) {
+                    PackageParser.ActivityIntentInfo aii = intents.get(i);
+                    applyDefaultPreferredActivityLPw(service, aii, new ComponentName(
+                            ps.name, aii.activity.className), userId);
+                }
+            }
+        }
+
+        // Read preferred apps from .../etc/preferred-apps directory.
+        File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
+        if (!preferredDir.exists() || !preferredDir.isDirectory()) {
+            return;
+        }
+        if (!preferredDir.canRead()) {
+            Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
+            return;
+        }
+
+        // Iterate over the files in the directory and scan .xml files
+        for (File f : preferredDir.listFiles()) {
+            if (!f.getPath().endsWith(".xml")) {
+                Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
+                continue;
+            }
+            if (!f.canRead()) {
+                Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
+                continue;
+            }
+
+            if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f);
+            FileInputStream str = null;
+            try {
+                str = new FileInputStream(f);
+                XmlPullParser parser = Xml.newPullParser();
+                parser.setInput(str, null);
+
+                int type;
+                while ((type = parser.next()) != XmlPullParser.START_TAG
+                        && type != XmlPullParser.END_DOCUMENT) {
+                    ;
+                }
+
+                if (type != XmlPullParser.START_TAG) {
+                    Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
+                    continue;
+                }
+                if (!"preferred-activities".equals(parser.getName())) {
+                    Slog.w(TAG, "Preferred apps file " + f
+                            + " does not start with 'preferred-activities'");
+                    continue;
+                }
+                readDefaultPreferredActivitiesLPw(service, parser, userId);
+            } catch (XmlPullParserException e) {
+                Slog.w(TAG, "Error reading apps file " + f, e);
+            } catch (IOException e) {
+                Slog.w(TAG, "Error reading apps file " + f, e);
+            } finally {
+                if (str != null) {
+                    try {
+                        str.close();
+                    } catch (IOException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    private void applyDefaultPreferredActivityLPw(PackageManagerService service,
+            IntentFilter tmpPa, ComponentName cn, int userId) {
+        // The initial preferences only specify the target activity
+        // component and intent-filter, not the set of matches.  So we
+        // now need to query for the matches to build the correct
+        // preferred activity entry.
+        if (PackageManagerService.DEBUG_PREFERRED) {
+            Log.d(TAG, "Processing preferred:");
+            tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), "  ");
+        }
+        Intent intent = new Intent();
+        int flags = 0;
+        intent.setAction(tmpPa.getAction(0));
+        for (int i=0; i<tmpPa.countCategories(); i++) {
+            String cat = tmpPa.getCategory(i);
+            if (cat.equals(Intent.CATEGORY_DEFAULT)) {
+                flags |= PackageManager.MATCH_DEFAULT_ONLY;
+            } else {
+                intent.addCategory(cat);
+            }
+        }
+
+        boolean doNonData = true;
+        boolean hasSchemes = false;
+
+        for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) {
+            boolean doScheme = true;
+            String scheme = tmpPa.getDataScheme(ischeme);
+            if (scheme != null && !scheme.isEmpty()) {
+                hasSchemes = true;
+            }
+            for (int issp=0; issp<tmpPa.countDataSchemeSpecificParts(); issp++) {
+                Uri.Builder builder = new Uri.Builder();
+                builder.scheme(scheme);
+                PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp);
+                builder.opaquePart(ssp.getPath());
+                Intent finalIntent = new Intent(intent);
+                finalIntent.setData(builder.build());
+                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
+                        scheme, ssp, null, null, null, userId);
+                doScheme = false;
+            }
+            for (int iauth=0; iauth<tmpPa.countDataAuthorities(); iauth++) {
+                boolean doAuth = true;
+                IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth);
+                for (int ipath=0; ipath<tmpPa.countDataPaths(); ipath++) {
+                    Uri.Builder builder = new Uri.Builder();
+                    builder.scheme(scheme);
+                    if (auth.getHost() != null) {
+                        builder.authority(auth.getHost());
+                    }
+                    PatternMatcher path = tmpPa.getDataPath(ipath);
+                    builder.path(path.getPath());
+                    Intent finalIntent = new Intent(intent);
+                    finalIntent.setData(builder.build());
+                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
+                            scheme, null, auth, path, null, userId);
+                    doAuth = doScheme = false;
+                }
+                if (doAuth) {
+                    Uri.Builder builder = new Uri.Builder();
+                    builder.scheme(scheme);
+                    if (auth.getHost() != null) {
+                        builder.authority(auth.getHost());
+                    }
+                    Intent finalIntent = new Intent(intent);
+                    finalIntent.setData(builder.build());
+                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
+                            scheme, null, auth, null, null, userId);
+                    doScheme = false;
+                }
+            }
+            if (doScheme) {
+                Uri.Builder builder = new Uri.Builder();
+                builder.scheme(scheme);
+                Intent finalIntent = new Intent(intent);
+                finalIntent.setData(builder.build());
+                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
+                        scheme, null, null, null, null, userId);
+            }
+            doNonData = false;
+        }
+
+        for (int idata=0; idata<tmpPa.countDataTypes(); idata++) {
+            String mimeType = tmpPa.getDataType(idata);
+            if (hasSchemes) {
+                Uri.Builder builder = new Uri.Builder();
+                for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) {
+                    String scheme = tmpPa.getDataScheme(ischeme);
+                    if (scheme != null && !scheme.isEmpty()) {
+                        Intent finalIntent = new Intent(intent);
+                        builder.scheme(scheme);
+                        finalIntent.setDataAndType(builder.build(), mimeType);
+                        applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
+                                scheme, null, null, null, mimeType, userId);
+                    }
+                }
+            } else {
+                Intent finalIntent = new Intent(intent);
+                finalIntent.setType(mimeType);
+                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
+                        null, null, null, null, mimeType, userId);
+            }
+            doNonData = false;
+        }
+
+        if (doNonData) {
+            applyDefaultPreferredActivityLPw(service, intent, flags, cn,
+                    null, null, null, null, null, userId);
+        }
+    }
+
+    private void applyDefaultPreferredActivityLPw(PackageManagerService service,
+            Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp,
+            IntentFilter.AuthorityEntry auth, PatternMatcher path, String mimeType,
+            int userId) {
+        List<ResolveInfo> ri = service.mActivities.queryIntent(intent,
+                intent.getType(), flags, 0);
+        if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
+                + " results: " + ri);
+        int match = 0;
+        if (ri != null && ri.size() > 1) {
+            boolean haveAct = false;
+            boolean haveNonSys = false;
+            ComponentName[] set = new ComponentName[ri.size()];
+            for (int i=0; i<ri.size(); i++) {
+                ActivityInfo ai = ri.get(i).activityInfo;
+                set[i] = new ComponentName(ai.packageName, ai.name);
+                if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+                    // If any of the matches are not system apps, then
+                    // there is a third party app that is now an option...
+                    // so don't set a default since we don't want to hide it.
+                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
+                            + ai.packageName + "/" + ai.name + ": non-system!");
+                    haveNonSys = true;
+                    break;
+                } else if (cn.getPackageName().equals(ai.packageName)
+                        && cn.getClassName().equals(ai.name)) {
+                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
+                            + ai.packageName + "/" + ai.name + ": default!");
+                    haveAct = true;
+                    match = ri.get(i).match;
+                } else {
+                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
+                            + ai.packageName + "/" + ai.name + ": skipped");
+                }
+            }
+            if (haveAct && !haveNonSys) {
+                IntentFilter filter = new IntentFilter();
+                if (intent.getAction() != null) {
+                    filter.addAction(intent.getAction());
+                }
+                if (intent.getCategories() != null) {
+                    for (String cat : intent.getCategories()) {
+                        filter.addCategory(cat);
+                    }
+                }
+                if ((flags&PackageManager.MATCH_DEFAULT_ONLY) != 0) {
+                    filter.addCategory(Intent.CATEGORY_DEFAULT);
+                }
+                if (scheme != null) {
+                    filter.addDataScheme(scheme);
+                }
+                if (ssp != null) {
+                    filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType());
+                }
+                if (auth != null) {
+                    filter.addDataAuthority(auth);
+                }
+                if (path != null) {
+                    filter.addDataPath(path);
+                }
+                if (intent.getType() != null) {
+                    try {
+                        filter.addDataType(intent.getType());
+                    } catch (IntentFilter.MalformedMimeTypeException ex) {
+                        Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn);
+                    }
+                }
+                PreferredActivity pa = new PreferredActivity(filter, match, set, cn, true);
+                editPreferredActivitiesLPw(userId).addFilter(pa);
+            } else if (!haveNonSys) {
+                Slog.w(TAG, "No component found for default preferred activity " + cn);
+            }
+        }
+    }
+
+    private void readDefaultPreferredActivitiesLPw(PackageManagerService service,
+            XmlPullParser parser, int userId)
+            throws XmlPullParserException, IOException {
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                PreferredActivity tmpPa = new PreferredActivity(parser);
+                if (tmpPa.mPref.getParseError() == null) {
+                    applyDefaultPreferredActivityLPw(service, tmpPa, tmpPa.mPref.mComponent,
+                            userId);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: <preferred-activity> "
+                                    + tmpPa.mPref.getParseError() + " at "
+                                    + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element under <preferred-activities>: " + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+    }
+
+    private int readInt(XmlPullParser parser, String ns, String name, int defValue) {
+        String v = parser.getAttributeValue(ns, name);
+        try {
+            if (v == null) {
+                return defValue;
+            }
+            return Integer.parseInt(v);
+        } catch (NumberFormatException e) {
+            PackageManagerService.reportSettingsProblem(Log.WARN,
+                    "Error in package manager settings: attribute " + name
+                            + " has bad integer value " + v + " at "
+                            + parser.getPositionDescription());
+        }
+        return defValue;
+    }
+
+    private void readPermissionsLPw(HashMap<String, BasePermission> out, XmlPullParser parser)
+            throws IOException, XmlPullParserException {
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            final String tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                final String name = parser.getAttributeValue(null, ATTR_NAME);
+                final String sourcePackage = parser.getAttributeValue(null, "package");
+                final String ptype = parser.getAttributeValue(null, "type");
+                if (name != null && sourcePackage != null) {
+                    final boolean dynamic = "dynamic".equals(ptype);
+                    final BasePermission bp = new BasePermission(name, sourcePackage,
+                            dynamic ? BasePermission.TYPE_DYNAMIC : BasePermission.TYPE_NORMAL);
+                    bp.protectionLevel = readInt(parser, null, "protection",
+                            PermissionInfo.PROTECTION_NORMAL);
+                    bp.protectionLevel = PermissionInfo.fixProtectionLevel(bp.protectionLevel);
+                    if (dynamic) {
+                        PermissionInfo pi = new PermissionInfo();
+                        pi.packageName = sourcePackage.intern();
+                        pi.name = name.intern();
+                        pi.icon = readInt(parser, null, "icon", 0);
+                        pi.nonLocalizedLabel = parser.getAttributeValue(null, "label");
+                        pi.protectionLevel = bp.protectionLevel;
+                        bp.pendingInfo = pi;
+                    }
+                    out.put(bp.name, bp);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: permissions has" + " no name at "
+                                    + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element reading permissions: " + parser.getName() + " at "
+                                + parser.getPositionDescription());
+            }
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException,
+            IOException {
+        String name = parser.getAttributeValue(null, ATTR_NAME);
+        String realName = parser.getAttributeValue(null, "realName");
+        String codePathStr = parser.getAttributeValue(null, "codePath");
+        String resourcePathStr = parser.getAttributeValue(null, "resourcePath");
+        String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
+        if (resourcePathStr == null) {
+            resourcePathStr = codePathStr;
+        }
+        String version = parser.getAttributeValue(null, "version");
+        int versionCode = 0;
+        if (version != null) {
+            try {
+                versionCode = Integer.parseInt(version);
+            } catch (NumberFormatException e) {
+            }
+        }
+
+        int pkgFlags = 0;
+        pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
+        final File codePathFile = new File(codePathStr);
+        if (PackageManagerService.locationIsPrivileged(codePathFile)) {
+            pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED;
+        }
+        PackageSetting ps = new PackageSetting(name, realName, codePathFile,
+                new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags);
+        String timeStampStr = parser.getAttributeValue(null, "ft");
+        if (timeStampStr != null) {
+            try {
+                long timeStamp = Long.parseLong(timeStampStr, 16);
+                ps.setTimeStamp(timeStamp);
+            } catch (NumberFormatException e) {
+            }
+        } else {
+            timeStampStr = parser.getAttributeValue(null, "ts");
+            if (timeStampStr != null) {
+                try {
+                    long timeStamp = Long.parseLong(timeStampStr);
+                    ps.setTimeStamp(timeStamp);
+                } catch (NumberFormatException e) {
+                }
+            }
+        }
+        timeStampStr = parser.getAttributeValue(null, "it");
+        if (timeStampStr != null) {
+            try {
+                ps.firstInstallTime = Long.parseLong(timeStampStr, 16);
+            } catch (NumberFormatException e) {
+            }
+        }
+        timeStampStr = parser.getAttributeValue(null, "ut");
+        if (timeStampStr != null) {
+            try {
+                ps.lastUpdateTime = Long.parseLong(timeStampStr, 16);
+            } catch (NumberFormatException e) {
+            }
+        }
+        String idStr = parser.getAttributeValue(null, "userId");
+        ps.appId = idStr != null ? Integer.parseInt(idStr) : 0;
+        if (ps.appId <= 0) {
+            String sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
+            ps.appId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
+        }
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals("perms")) {
+                readGrantedPermissionsLPw(parser, ps.grantedPermissions);
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element under <updated-package>: " + parser.getName());
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+
+        mDisabledSysPackages.put(name, ps);
+    }
+
+    private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException {
+        String name = null;
+        String realName = null;
+        String idStr = null;
+        String sharedIdStr = null;
+        String codePathStr = null;
+        String resourcePathStr = null;
+        String nativeLibraryPathStr = null;
+        String systemStr = null;
+        String installerPackageName = null;
+        String uidError = null;
+        int pkgFlags = 0;
+        long timeStamp = 0;
+        long firstInstallTime = 0;
+        long lastUpdateTime = 0;
+        PackageSettingBase packageSetting = null;
+        String version = null;
+        int versionCode = 0;
+        try {
+            name = parser.getAttributeValue(null, ATTR_NAME);
+            realName = parser.getAttributeValue(null, "realName");
+            idStr = parser.getAttributeValue(null, "userId");
+            uidError = parser.getAttributeValue(null, "uidError");
+            sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
+            codePathStr = parser.getAttributeValue(null, "codePath");
+            resourcePathStr = parser.getAttributeValue(null, "resourcePath");
+            nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
+            version = parser.getAttributeValue(null, "version");
+            if (version != null) {
+                try {
+                    versionCode = Integer.parseInt(version);
+                } catch (NumberFormatException e) {
+                }
+            }
+            installerPackageName = parser.getAttributeValue(null, "installer");
+
+            systemStr = parser.getAttributeValue(null, "flags");
+            if (systemStr != null) {
+                try {
+                    pkgFlags = Integer.parseInt(systemStr);
+                } catch (NumberFormatException e) {
+                }
+            } else {
+                // For backward compatibility
+                systemStr = parser.getAttributeValue(null, "system");
+                if (systemStr != null) {
+                    pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM
+                            : 0;
+                } else {
+                    // Old settings that don't specify system... just treat
+                    // them as system, good enough.
+                    pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
+                }
+            }
+            String timeStampStr = parser.getAttributeValue(null, "ft");
+            if (timeStampStr != null) {
+                try {
+                    timeStamp = Long.parseLong(timeStampStr, 16);
+                } catch (NumberFormatException e) {
+                }
+            } else {
+                timeStampStr = parser.getAttributeValue(null, "ts");
+                if (timeStampStr != null) {
+                    try {
+                        timeStamp = Long.parseLong(timeStampStr);
+                    } catch (NumberFormatException e) {
+                    }
+                }
+            }
+            timeStampStr = parser.getAttributeValue(null, "it");
+            if (timeStampStr != null) {
+                try {
+                    firstInstallTime = Long.parseLong(timeStampStr, 16);
+                } catch (NumberFormatException e) {
+                }
+            }
+            timeStampStr = parser.getAttributeValue(null, "ut");
+            if (timeStampStr != null) {
+                try {
+                    lastUpdateTime = Long.parseLong(timeStampStr, 16);
+                } catch (NumberFormatException e) {
+                }
+            }
+            if (PackageManagerService.DEBUG_SETTINGS)
+                Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr
+                        + " sharedUserId=" + sharedIdStr);
+            int userId = idStr != null ? Integer.parseInt(idStr) : 0;
+            if (resourcePathStr == null) {
+                resourcePathStr = codePathStr;
+            }
+            if (realName != null) {
+                realName = realName.intern();
+            }
+            if (name == null) {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Error in package manager settings: <package> has no name at "
+                                + parser.getPositionDescription());
+            } else if (codePathStr == null) {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Error in package manager settings: <package> has no codePath at "
+                                + parser.getPositionDescription());
+            } else if (userId > 0) {
+                packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
+                        new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode,
+                        pkgFlags);
+                if (PackageManagerService.DEBUG_SETTINGS)
+                    Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId="
+                            + userId + " pkg=" + packageSetting);
+                if (packageSetting == null) {
+                    PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid "
+                            + userId + " while parsing settings at "
+                            + parser.getPositionDescription());
+                } else {
+                    packageSetting.setTimeStamp(timeStamp);
+                    packageSetting.firstInstallTime = firstInstallTime;
+                    packageSetting.lastUpdateTime = lastUpdateTime;
+                }
+            } else if (sharedIdStr != null) {
+                userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
+                if (userId > 0) {
+                    packageSetting = new PendingPackage(name.intern(), realName, new File(
+                            codePathStr), new File(resourcePathStr), nativeLibraryPathStr, userId,
+                            versionCode, pkgFlags);
+                    packageSetting.setTimeStamp(timeStamp);
+                    packageSetting.firstInstallTime = firstInstallTime;
+                    packageSetting.lastUpdateTime = lastUpdateTime;
+                    mPendingPackages.add((PendingPackage) packageSetting);
+                    if (PackageManagerService.DEBUG_SETTINGS)
+                        Log.i(PackageManagerService.TAG, "Reading package " + name
+                                + ": sharedUserId=" + userId + " pkg=" + packageSetting);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: package " + name
+                                    + " has bad sharedId " + sharedIdStr + " at "
+                                    + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Error in package manager settings: package " + name + " has bad userId "
+                                + idStr + " at " + parser.getPositionDescription());
+            }
+        } catch (NumberFormatException e) {
+            PackageManagerService.reportSettingsProblem(Log.WARN,
+                    "Error in package manager settings: package " + name + " has bad userId "
+                            + idStr + " at " + parser.getPositionDescription());
+        }
+        if (packageSetting != null) {
+            packageSetting.uidError = "true".equals(uidError);
+            packageSetting.installerPackageName = installerPackageName;
+            packageSetting.nativeLibraryPathString = nativeLibraryPathStr;
+            // Handle legacy string here for single-user mode
+            final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
+            if (enabledStr != null) {
+                try {
+                    packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null);
+                } catch (NumberFormatException e) {
+                    if (enabledStr.equalsIgnoreCase("true")) {
+                        packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null);
+                    } else if (enabledStr.equalsIgnoreCase("false")) {
+                        packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null);
+                    } else if (enabledStr.equalsIgnoreCase("default")) {
+                        packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
+                    } else {
+                        PackageManagerService.reportSettingsProblem(Log.WARN,
+                                "Error in package manager settings: package " + name
+                                        + " has bad enabled value: " + idStr + " at "
+                                        + parser.getPositionDescription());
+                    }
+                }
+            } else {
+                packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
+            }
+
+            final String installStatusStr = parser.getAttributeValue(null, "installStatus");
+            if (installStatusStr != null) {
+                if (installStatusStr.equalsIgnoreCase("false")) {
+                    packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_INCOMPLETE;
+                } else {
+                    packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_COMPLETE;
+                }
+            }
+
+            int outerDepth = parser.getDepth();
+            int type;
+            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+
+                String tagName = parser.getName();
+                // Legacy 
+                if (tagName.equals(TAG_DISABLED_COMPONENTS)) {
+                    readDisabledComponentsLPw(packageSetting, parser, 0);
+                } else if (tagName.equals(TAG_ENABLED_COMPONENTS)) {
+                    readEnabledComponentsLPw(packageSetting, parser, 0);
+                } else if (tagName.equals("sigs")) {
+                    packageSetting.signatures.readXml(parser, mPastSignatures);
+                } else if (tagName.equals("perms")) {
+                    readGrantedPermissionsLPw(parser, packageSetting.grantedPermissions);
+                    packageSetting.permissionsFixed = true;
+                } else if (tagName.equals("signing-keyset")) {
+                    long id = Long.parseLong(parser.getAttributeValue(null, "identifier"));
+                    packageSetting.keySetData.addSigningKeySet(id);
+                    if (false) Slog.d(TAG, "Adding signing keyset " + Long.toString(id)
+                            + " to " + name);
+                } else if (tagName.equals("defined-keyset")) {
+                    long id = Long.parseLong(parser.getAttributeValue(null, "identifier"));
+                    String alias = parser.getAttributeValue(null, "alias");
+                    packageSetting.keySetData.addDefinedKeySet(id, alias);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Unknown element under <package>: " + parser.getName());
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+
+
+        } else {
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
+            int userId) throws IOException, XmlPullParserException {
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                String name = parser.getAttributeValue(null, ATTR_NAME);
+                if (name != null) {
+                    packageSetting.addDisabledComponent(name.intern(), userId);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: <disabled-components> has"
+                                    + " no name at " + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element under <disabled-components>: " + parser.getName());
+            }
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
+            int userId) throws IOException, XmlPullParserException {
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                String name = parser.getAttributeValue(null, ATTR_NAME);
+                if (name != null) {
+                    packageSetting.addEnabledComponent(name.intern(), userId);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: <enabled-components> has"
+                                    + " no name at " + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element under <enabled-components>: " + parser.getName());
+            }
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException,IOException {
+        String name = null;
+        String idStr = null;
+        int pkgFlags = 0;
+        SharedUserSetting su = null;
+        try {
+            name = parser.getAttributeValue(null, ATTR_NAME);
+            idStr = parser.getAttributeValue(null, "userId");
+            int userId = idStr != null ? Integer.parseInt(idStr) : 0;
+            if ("true".equals(parser.getAttributeValue(null, "system"))) {
+                pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
+            }
+            if (name == null) {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Error in package manager settings: <shared-user> has no name at "
+                                + parser.getPositionDescription());
+            } else if (userId == 0) {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Error in package manager settings: shared-user " + name
+                                + " has bad userId " + idStr + " at "
+                                + parser.getPositionDescription());
+            } else {
+                if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags)) == null) {
+                    PackageManagerService
+                            .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at "
+                                    + parser.getPositionDescription());
+                }
+            }
+        } catch (NumberFormatException e) {
+            PackageManagerService.reportSettingsProblem(Log.WARN,
+                    "Error in package manager settings: package " + name + " has bad userId "
+                            + idStr + " at " + parser.getPositionDescription());
+        }
+        ;
+
+        if (su != null) {
+            int outerDepth = parser.getDepth();
+            int type;
+            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+
+                String tagName = parser.getName();
+                if (tagName.equals("sigs")) {
+                    su.signatures.readXml(parser, mPastSignatures);
+                } else if (tagName.equals("perms")) {
+                    readGrantedPermissionsLPw(parser, su.grantedPermissions);
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Unknown element under <shared-user>: " + parser.getName());
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+
+        } else {
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    private void readGrantedPermissionsLPw(XmlPullParser parser, HashSet<String> outPerms)
+            throws IOException, XmlPullParserException {
+        int outerDepth = parser.getDepth();
+        int type;
+        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
+                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                continue;
+            }
+
+            String tagName = parser.getName();
+            if (tagName.equals(TAG_ITEM)) {
+                String name = parser.getAttributeValue(null, ATTR_NAME);
+                if (name != null) {
+                    outPerms.add(name.intern());
+                } else {
+                    PackageManagerService.reportSettingsProblem(Log.WARN,
+                            "Error in package manager settings: <perms> has" + " no name at "
+                                    + parser.getPositionDescription());
+                }
+            } else {
+                PackageManagerService.reportSettingsProblem(Log.WARN,
+                        "Unknown element under <perms>: " + parser.getName());
+            }
+            XmlUtils.skipCurrentTag(parser);
+        }
+    }
+
+    void createNewUserLILPw(PackageManagerService service, Installer installer,
+            int userHandle, File path) {
+        path.mkdir();
+        FileUtils.setPermissions(path.toString(), FileUtils.S_IRWXU | FileUtils.S_IRWXG
+                | FileUtils.S_IXOTH, -1, -1);
+        for (PackageSetting ps : mPackages.values()) {
+            // Only system apps are initially installed.
+            ps.setInstalled((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0, userHandle);
+            // Need to create a data directory for all apps under this user.
+            installer.createUserData(ps.name,
+                    UserHandle.getUid(userHandle, ps.appId), userHandle,
+                    ps.pkg.applicationInfo.seinfo);
+        }
+        readDefaultPreferredAppsLPw(service, userHandle);
+        writePackageRestrictionsLPr(userHandle);
+    }
+
+    void removeUserLPr(int userId) {
+        Set<Entry<String, PackageSetting>> entries = mPackages.entrySet();
+        for (Entry<String, PackageSetting> entry : entries) {
+            entry.getValue().removeUser(userId);
+        }
+        mPreferredActivities.remove(userId);
+        File file = getUserPackagesStateFile(userId);
+        file.delete();
+        file = getUserPackagesStateBackupFile(userId);
+        file.delete();
+    }
+
+    // This should be called (at least) whenever an application is removed
+    private void setFirstAvailableUid(int uid) {
+        if (uid > mFirstAvailableUid) {
+            mFirstAvailableUid = uid;
+        }
+    }
+
+    // Returns -1 if we could not find an available UserId to assign
+    private int newUserIdLPw(Object obj) {
+        // Let's be stupidly inefficient for now...
+        final int N = mUserIds.size();
+        for (int i = mFirstAvailableUid; i < N; i++) {
+            if (mUserIds.get(i) == null) {
+                mUserIds.set(i, obj);
+                return Process.FIRST_APPLICATION_UID + i;
+            }
+        }
+
+        // None left?
+        if (N > (Process.LAST_APPLICATION_UID-Process.FIRST_APPLICATION_UID)) {
+            return -1;
+        }
+
+        mUserIds.add(obj);
+        return Process.FIRST_APPLICATION_UID + N;
+    }
+
+    public VerifierDeviceIdentity getVerifierDeviceIdentityLPw() {
+        if (mVerifierDeviceIdentity == null) {
+            mVerifierDeviceIdentity = VerifierDeviceIdentity.generate();
+
+            writeLPr();
+        }
+
+        return mVerifierDeviceIdentity;
+    }
+
+    public PackageSetting getDisabledSystemPkgLPr(String name) {
+        PackageSetting ps = mDisabledSysPackages.get(name);
+        return ps;
+    }
+
+    private String compToString(HashSet<String> cmp) {
+        return cmp != null ? Arrays.toString(cmp.toArray()) : "[]";
+    }
+ 
+    boolean isEnabledLPr(ComponentInfo componentInfo, int flags, int userId) {
+        if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
+            return true;
+        }
+        final String pkgName = componentInfo.packageName;
+        final PackageSetting packageSettings = mPackages.get(pkgName);
+        if (PackageManagerService.DEBUG_SETTINGS) {
+            Log.v(PackageManagerService.TAG, "isEnabledLock - packageName = "
+                    + componentInfo.packageName + " componentName = " + componentInfo.name);
+            Log.v(PackageManagerService.TAG, "enabledComponents: "
+                    + compToString(packageSettings.getEnabledComponents(userId)));
+            Log.v(PackageManagerService.TAG, "disabledComponents: "
+                    + compToString(packageSettings.getDisabledComponents(userId)));
+        }
+        if (packageSettings == null) {
+            return false;
+        }
+        PackageUserState ustate = packageSettings.readUserState(userId);
+        if ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0) {
+            if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
+                return true;
+            }
+        }
+        if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED
+                || ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_USER
+                || ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
+                || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled
+                    && ustate.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) {
+            return false;
+        }
+        if (ustate.enabledComponents != null
+                && ustate.enabledComponents.contains(componentInfo.name)) {
+            return true;
+        }
+        if (ustate.disabledComponents != null
+                && ustate.disabledComponents.contains(componentInfo.name)) {
+            return false;
+        }
+        return componentInfo.enabled;
+    }
+
+    String getInstallerPackageNameLPr(String packageName) {
+        final PackageSetting pkg = mPackages.get(packageName);
+        if (pkg == null) {
+            throw new IllegalArgumentException("Unknown package: " + packageName);
+        }
+        return pkg.installerPackageName;
+    }
+
+    int getApplicationEnabledSettingLPr(String packageName, int userId) {
+        final PackageSetting pkg = mPackages.get(packageName);
+        if (pkg == null) {
+            throw new IllegalArgumentException("Unknown package: " + packageName);
+        }
+        return pkg.getEnabled(userId);
+    }
+
+    int getComponentEnabledSettingLPr(ComponentName componentName, int userId) {
+        final String packageName = componentName.getPackageName();
+        final PackageSetting pkg = mPackages.get(packageName);
+        if (pkg == null) {
+            throw new IllegalArgumentException("Unknown component: " + componentName);
+        }
+        final String classNameStr = componentName.getClassName();
+        return pkg.getCurrentEnabledStateLPr(classNameStr, userId);
+    }
+
+    boolean setPackageStoppedStateLPw(String packageName, boolean stopped,
+            boolean allowedByPermission, int uid, int userId) {
+        int appId = UserHandle.getAppId(uid);
+        final PackageSetting pkgSetting = mPackages.get(packageName);
+        if (pkgSetting == null) {
+            throw new IllegalArgumentException("Unknown package: " + packageName);
+        }
+        if (!allowedByPermission && (appId != pkgSetting.appId)) {
+            throw new SecurityException(
+                    "Permission Denial: attempt to change stopped state from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + uid + ", package uid=" + pkgSetting.appId);
+        }
+        if (DEBUG_STOPPED) {
+            if (stopped) {
+                RuntimeException e = new RuntimeException("here");
+                e.fillInStackTrace();
+                Slog.i(TAG, "Stopping package " + packageName, e);
+            }
+        }
+        if (pkgSetting.getStopped(userId) != stopped) {
+            pkgSetting.setStopped(stopped, userId);
+            // pkgSetting.pkg.mSetStopped = stopped;
+            if (pkgSetting.getNotLaunched(userId)) {
+                if (pkgSetting.installerPackageName != null) {
+                    PackageManagerService.sendPackageBroadcast(Intent.ACTION_PACKAGE_FIRST_LAUNCH,
+                            pkgSetting.name, null,
+                            pkgSetting.installerPackageName, null, new int[] {userId});
+                }
+                pkgSetting.setNotLaunched(false, userId);
+            }
+            return true;
+        }
+        return false;
+    }
+
+    private List<UserInfo> getAllUsers() {
+        long id = Binder.clearCallingIdentity();
+        try {
+            return UserManagerService.getInstance().getUsers(false);
+        } catch (NullPointerException npe) {
+            // packagemanager not yet initialized
+        } finally {
+            Binder.restoreCallingIdentity(id);
+        }
+        return null;
+    }
+
+    static final void printFlags(PrintWriter pw, int val, Object[] spec) {
+        pw.print("[ ");
+        for (int i=0; i<spec.length; i+=2) {
+            int mask = (Integer)spec[i];
+            if ((val & mask) != 0) {
+                pw.print(spec[i+1]);
+                pw.print(" ");
+            }
+        }
+        pw.print("]");
+    }
+
+    static final Object[] FLAG_DUMP_SPEC = new Object[] {
+        ApplicationInfo.FLAG_SYSTEM, "SYSTEM",
+        ApplicationInfo.FLAG_DEBUGGABLE, "DEBUGGABLE",
+        ApplicationInfo.FLAG_HAS_CODE, "HAS_CODE",
+        ApplicationInfo.FLAG_PERSISTENT, "PERSISTENT",
+        ApplicationInfo.FLAG_FACTORY_TEST, "FACTORY_TEST",
+        ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING, "ALLOW_TASK_REPARENTING",
+        ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA, "ALLOW_CLEAR_USER_DATA",
+        ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, "UPDATED_SYSTEM_APP",
+        ApplicationInfo.FLAG_TEST_ONLY, "TEST_ONLY",
+        ApplicationInfo.FLAG_VM_SAFE_MODE, "VM_SAFE_MODE",
+        ApplicationInfo.FLAG_ALLOW_BACKUP, "ALLOW_BACKUP",
+        ApplicationInfo.FLAG_KILL_AFTER_RESTORE, "KILL_AFTER_RESTORE",
+        ApplicationInfo.FLAG_RESTORE_ANY_VERSION, "RESTORE_ANY_VERSION",
+        ApplicationInfo.FLAG_EXTERNAL_STORAGE, "EXTERNAL_STORAGE",
+        ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP",
+        ApplicationInfo.FLAG_PRIVILEGED, "PRIVILEGED",
+        ApplicationInfo.FLAG_FORWARD_LOCK, "FORWARD_LOCK",
+        ApplicationInfo.FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE",
+    };
+
+    void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag, PackageSetting ps,
+            SimpleDateFormat sdf, Date date, List<UserInfo> users) {
+        if (checkinTag != null) {
+            pw.print(checkinTag);
+            pw.print(",");
+            pw.print(ps.realName != null ? ps.realName : ps.name);
+            pw.print(",");
+            pw.print(ps.appId);
+            pw.print(",");
+            pw.print(ps.versionCode);
+            pw.print(",");
+            pw.print(ps.firstInstallTime);
+            pw.print(",");
+            pw.print(ps.lastUpdateTime);
+            pw.print(",");
+            pw.print(ps.installerPackageName != null ? ps.installerPackageName : "?");
+            pw.println();
+            for (UserInfo user : users) {
+                pw.print(checkinTag);
+                pw.print("-");
+                pw.print("usr");
+                pw.print(",");
+                pw.print(user.id);
+                pw.print(",");
+                pw.print(ps.getInstalled(user.id) ? "I" : "i");
+                pw.print(ps.getBlocked(user.id) ? "B" : "b");
+                pw.print(ps.getStopped(user.id) ? "S" : "s");
+                pw.print(ps.getNotLaunched(user.id) ? "l" : "L");
+                pw.print(",");
+                pw.print(ps.getEnabled(user.id));
+                String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id);
+                pw.print(",");
+                pw.print(lastDisabledAppCaller != null ? lastDisabledAppCaller : "?");
+                pw.println();
+            }
+            return;
+        }
+
+        pw.print(prefix); pw.print("Package [");
+            pw.print(ps.realName != null ? ps.realName : ps.name);
+            pw.print("] (");
+            pw.print(Integer.toHexString(System.identityHashCode(ps)));
+            pw.println("):");
+
+        if (ps.realName != null) {
+            pw.print(prefix); pw.print("  compat name=");
+            pw.println(ps.name);
+        }
+
+        pw.print(prefix); pw.print("  userId="); pw.print(ps.appId);
+                pw.print(" gids="); pw.println(PackageManagerService.arrayToString(ps.gids));
+        if (ps.sharedUser != null) {
+            pw.print(prefix); pw.print("  sharedUser="); pw.println(ps.sharedUser);
+        }
+        pw.print(prefix); pw.print("  pkg="); pw.println(ps.pkg);
+        pw.print(prefix); pw.print("  codePath="); pw.println(ps.codePathString);
+        pw.print(prefix); pw.print("  resourcePath="); pw.println(ps.resourcePathString);
+        pw.print(prefix); pw.print("  nativeLibraryPath="); pw.println(ps.nativeLibraryPathString);
+        pw.print(prefix); pw.print("  versionCode="); pw.print(ps.versionCode);
+        if (ps.pkg != null) {
+            pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion);
+        }
+        pw.println();
+        if (ps.pkg != null) {
+            pw.print(prefix); pw.print("  versionName="); pw.println(ps.pkg.mVersionName);
+            pw.print(prefix); pw.print("  applicationInfo=");
+                pw.println(ps.pkg.applicationInfo.toString());
+            pw.print(prefix); pw.print("  flags="); printFlags(pw, ps.pkg.applicationInfo.flags,
+                    FLAG_DUMP_SPEC); pw.println();
+            pw.print(prefix); pw.print("  dataDir="); pw.println(ps.pkg.applicationInfo.dataDir);
+            if (ps.pkg.mOperationPending) {
+                pw.print(prefix); pw.println("  mOperationPending=true");
+            }
+            pw.print(prefix); pw.print("  supportsScreens=[");
+            boolean first = true;
+            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
+                if (!first)
+                    pw.print(", ");
+                first = false;
+                pw.print("small");
+            }
+            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) {
+                if (!first)
+                    pw.print(", ");
+                first = false;
+                pw.print("medium");
+            }
+            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
+                if (!first)
+                    pw.print(", ");
+                first = false;
+                pw.print("large");
+            }
+            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
+                if (!first)
+                    pw.print(", ");
+                first = false;
+                pw.print("xlarge");
+            }
+            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
+                if (!first)
+                    pw.print(", ");
+                first = false;
+                pw.print("resizeable");
+            }
+            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
+                if (!first)
+                    pw.print(", ");
+                first = false;
+                pw.print("anyDensity");
+            }
+            pw.println("]");
+            if (ps.pkg.libraryNames != null && ps.pkg.libraryNames.size() > 0) {
+                pw.print(prefix); pw.println("  libraries:");
+                for (int i=0; i<ps.pkg.libraryNames.size(); i++) {
+                    pw.print(prefix); pw.print("    "); pw.println(ps.pkg.libraryNames.get(i));
+                }
+            }
+            if (ps.pkg.usesLibraries != null && ps.pkg.usesLibraries.size() > 0) {
+                pw.print(prefix); pw.println("  usesLibraries:");
+                for (int i=0; i<ps.pkg.usesLibraries.size(); i++) {
+                    pw.print(prefix); pw.print("    "); pw.println(ps.pkg.usesLibraries.get(i));
+                }
+            }
+            if (ps.pkg.usesOptionalLibraries != null
+                    && ps.pkg.usesOptionalLibraries.size() > 0) {
+                pw.print(prefix); pw.println("  usesOptionalLibraries:");
+                for (int i=0; i<ps.pkg.usesOptionalLibraries.size(); i++) {
+                    pw.print(prefix); pw.print("    ");
+                        pw.println(ps.pkg.usesOptionalLibraries.get(i));
+                }
+            }
+            if (ps.pkg.usesLibraryFiles != null
+                    && ps.pkg.usesLibraryFiles.length > 0) {
+                pw.print(prefix); pw.println("  usesLibraryFiles:");
+                for (int i=0; i<ps.pkg.usesLibraryFiles.length; i++) {
+                    pw.print(prefix); pw.print("    "); pw.println(ps.pkg.usesLibraryFiles[i]);
+                }
+            }
+        }
+        pw.print(prefix); pw.print("  timeStamp=");
+            date.setTime(ps.timeStamp);
+            pw.println(sdf.format(date));
+        pw.print(prefix); pw.print("  firstInstallTime=");
+            date.setTime(ps.firstInstallTime);
+            pw.println(sdf.format(date));
+        pw.print(prefix); pw.print("  lastUpdateTime=");
+            date.setTime(ps.lastUpdateTime);
+            pw.println(sdf.format(date));
+        if (ps.installerPackageName != null) {
+            pw.print(prefix); pw.print("  installerPackageName=");
+                    pw.println(ps.installerPackageName);
+        }
+        pw.print(prefix); pw.print("  signatures="); pw.println(ps.signatures);
+        pw.print(prefix); pw.print("  permissionsFixed="); pw.print(ps.permissionsFixed);
+                pw.print(" haveGids="); pw.print(ps.haveGids);
+                pw.print(" installStatus="); pw.println(ps.installStatus);
+        pw.print(prefix); pw.print("  pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC);
+                pw.println();
+        for (UserInfo user : users) {
+            pw.print(prefix); pw.print("  User "); pw.print(user.id); pw.print(": ");
+            pw.print(" installed=");
+            pw.print(ps.getInstalled(user.id));
+            pw.print(" blocked=");
+            pw.print(ps.getBlocked(user.id));
+            pw.print(" stopped=");
+            pw.print(ps.getStopped(user.id));
+            pw.print(" notLaunched=");
+            pw.print(ps.getNotLaunched(user.id));
+            pw.print(" enabled=");
+            pw.println(ps.getEnabled(user.id));
+            String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id);
+            if (lastDisabledAppCaller != null) {
+                pw.print(prefix); pw.print("    lastDisabledCaller: ");
+                        pw.println(lastDisabledAppCaller);
+            }
+            HashSet<String> cmp = ps.getDisabledComponents(user.id);
+            if (cmp != null && cmp.size() > 0) {
+                pw.print(prefix); pw.println("    disabledComponents:");
+                for (String s : cmp) {
+                    pw.print(prefix); pw.print("    "); pw.println(s);
+                }
+            }
+            cmp = ps.getEnabledComponents(user.id);
+            if (cmp != null && cmp.size() > 0) {
+                pw.print(prefix); pw.println("    enabledComponents:");
+                for (String s : cmp) {
+                    pw.print(prefix); pw.print("    "); pw.println(s);
+                }
+            }
+        }
+        if (ps.grantedPermissions.size() > 0) {
+            pw.print(prefix); pw.println("  grantedPermissions:");
+            for (String s : ps.grantedPermissions) {
+                pw.print(prefix); pw.print("    "); pw.println(s);
+            }
+        }
+    }
+
+    void dumpPackagesLPr(PrintWriter pw, String packageName, DumpState dumpState, boolean checkin) {
+        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        final Date date = new Date();
+        boolean printedSomething = false;
+        List<UserInfo> users = getAllUsers();
+        for (final PackageSetting ps : mPackages.values()) {
+            if (packageName != null && !packageName.equals(ps.realName)
+                    && !packageName.equals(ps.name)) {
+                continue;
+            }
+
+            if (!checkin && packageName != null) {
+                dumpState.setSharedUser(ps.sharedUser);
+            }
+
+            if (!checkin && !printedSomething) {
+                if (dumpState.onTitlePrinted())
+                    pw.println();
+                pw.println("Packages:");
+                printedSomething = true;
+            }
+            dumpPackageLPr(pw, "  ", checkin ? "pkg" : null, ps, sdf, date, users);
+        }
+
+        printedSomething = false;
+        if (!checkin && mRenamedPackages.size() > 0) {
+            for (final Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
+                if (packageName != null && !packageName.equals(e.getKey())
+                        && !packageName.equals(e.getValue())) {
+                    continue;
+                }
+                if (!checkin) {
+                    if (!printedSomething) {
+                        if (dumpState.onTitlePrinted())
+                            pw.println();
+                        pw.println("Renamed packages:");
+                        printedSomething = true;
+                    }
+                    pw.print("  ");
+                } else {
+                    pw.print("ren,");
+                }
+                pw.print(e.getKey());
+                pw.print(checkin ? " -> " : ",");
+                pw.println(e.getValue());
+            }
+        }
+
+        printedSomething = false;
+        if (mDisabledSysPackages.size() > 0) {
+            for (final PackageSetting ps : mDisabledSysPackages.values()) {
+                if (packageName != null && !packageName.equals(ps.realName)
+                        && !packageName.equals(ps.name)) {
+                    continue;
+                }
+                if (!checkin && !printedSomething) {
+                    if (dumpState.onTitlePrinted())
+                        pw.println();
+                    pw.println("Hidden system packages:");
+                    printedSomething = true;
+                }
+                dumpPackageLPr(pw, "  ", checkin ? "dis" : null, ps, sdf, date, users);
+            }
+        }
+    }
+
+    void dumpPermissionsLPr(PrintWriter pw, String packageName, DumpState dumpState) {
+        boolean printedSomething = false;
+        for (BasePermission p : mPermissions.values()) {
+            if (packageName != null && !packageName.equals(p.sourcePackage)) {
+                continue;
+            }
+            if (!printedSomething) {
+                if (dumpState.onTitlePrinted())
+                    pw.println();
+                pw.println("Permissions:");
+                printedSomething = true;
+            }
+            pw.print("  Permission ["); pw.print(p.name); pw.print("] (");
+                    pw.print(Integer.toHexString(System.identityHashCode(p)));
+                    pw.println("):");
+            pw.print("    sourcePackage="); pw.println(p.sourcePackage);
+            pw.print("    uid="); pw.print(p.uid);
+                    pw.print(" gids="); pw.print(PackageManagerService.arrayToString(p.gids));
+                    pw.print(" type="); pw.print(p.type);
+                    pw.print(" prot=");
+                    pw.println(PermissionInfo.protectionToString(p.protectionLevel));
+            if (p.packageSetting != null) {
+                pw.print("    packageSetting="); pw.println(p.packageSetting);
+            }
+            if (p.perm != null) {
+                pw.print("    perm="); pw.println(p.perm);
+            }
+            if (READ_EXTERNAL_STORAGE.equals(p.name)) {
+                pw.print("    enforced=");
+                pw.println(mReadExternalStorageEnforced);
+            }
+        }
+    }
+
+    void dumpSharedUsersLPr(PrintWriter pw, String packageName, DumpState dumpState) {
+        boolean printedSomething = false;
+        for (SharedUserSetting su : mSharedUsers.values()) {
+            if (packageName != null && su != dumpState.getSharedUser()) {
+                continue;
+            }
+            if (!printedSomething) {
+                if (dumpState.onTitlePrinted())
+                    pw.println();
+                pw.println("Shared users:");
+                printedSomething = true;
+            }
+            pw.print("  SharedUser [");
+            pw.print(su.name);
+            pw.print("] (");
+            pw.print(Integer.toHexString(System.identityHashCode(su)));
+                    pw.println("):");
+            pw.print("    userId=");
+            pw.print(su.userId);
+            pw.print(" gids=");
+            pw.println(PackageManagerService.arrayToString(su.gids));
+            pw.println("    grantedPermissions:");
+            for (String s : su.grantedPermissions) {
+                pw.print("      ");
+                pw.println(s);
+            }
+        }
+    }
+
+    void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) {
+        pw.println("Settings parse messages:");
+        pw.print(mReadMessages.toString());
+    }
+}
diff --git a/services/java/com/android/server/pm/SharedUserSetting.java b/services/core/java/com/android/server/pm/SharedUserSetting.java
similarity index 100%
rename from services/java/com/android/server/pm/SharedUserSetting.java
rename to services/core/java/com/android/server/pm/SharedUserSetting.java
diff --git a/services/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
similarity index 100%
rename from services/java/com/android/server/pm/UserManagerService.java
rename to services/core/java/com/android/server/pm/UserManagerService.java
diff --git a/services/java/com/android/server/power/DisplayBlanker.java b/services/core/java/com/android/server/power/DisplayBlanker.java
similarity index 100%
rename from services/java/com/android/server/power/DisplayBlanker.java
rename to services/core/java/com/android/server/power/DisplayBlanker.java
diff --git a/services/core/java/com/android/server/power/DisplayPowerController.java b/services/core/java/com/android/server/power/DisplayPowerController.java
new file mode 100644
index 0000000..e83f734
--- /dev/null
+++ b/services/core/java/com/android/server/power/DisplayPowerController.java
@@ -0,0 +1,1377 @@
+/*
+ * 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.server.power;
+
+import com.android.server.lights.LightsManager;
+import com.android.server.twilight.TwilightListener;
+import com.android.server.twilight.TwilightManager;
+import com.android.server.twilight.TwilightState;
+
+import android.animation.Animator;
+import android.animation.ObjectAnimator;
+import android.content.Context;
+import android.content.res.Resources;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.SystemClock;
+import android.text.format.DateUtils;
+import android.util.FloatMath;
+import android.util.Slog;
+import android.util.Spline;
+import android.util.TimeUtils;
+
+import java.io.PrintWriter;
+
+/**
+ * Controls the power state of the display.
+ *
+ * Handles the proximity sensor, light sensor, and animations between states
+ * including the screen off animation.
+ *
+ * This component acts independently of the rest of the power manager service.
+ * In particular, it does not share any state and it only communicates
+ * via asynchronous callbacks to inform the power manager that something has
+ * changed.
+ *
+ * Everything this class does internally is serialized on its handler although
+ * it may be accessed by other threads from the outside.
+ *
+ * Note that the power manager service guarantees that it will hold a suspend
+ * blocker as long as the display is not ready.  So most of the work done here
+ * does not need to worry about holding a suspend blocker unless it happens
+ * independently of the display ready signal.
+ *
+ * For debugging, you can make the electron beam and brightness animations run
+ * slower by changing the "animator duration scale" option in Development Settings.
+ */
+final class DisplayPowerController {
+    private static final String TAG = "DisplayPowerController";
+
+    private static boolean DEBUG = false;
+    private static final boolean DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT = false;
+    private static final boolean DEBUG_PRETEND_LIGHT_SENSOR_ABSENT = false;
+
+    // If true, uses the electron beam on animation.
+    // We might want to turn this off if we cannot get a guarantee that the screen
+    // actually turns on and starts showing new content after the call to set the
+    // screen state returns.  Playing the animation can also be somewhat slow.
+    private static final boolean USE_ELECTRON_BEAM_ON_ANIMATION = false;
+
+    // If true, enables the use of the screen auto-brightness adjustment setting.
+    private static final boolean USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT =
+            PowerManager.useScreenAutoBrightnessAdjustmentFeature();
+
+    // The maximum range of gamma adjustment possible using the screen
+    // auto-brightness adjustment setting.
+    private static final float SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA = 3.0f;
+
+    // The minimum reduction in brightness when dimmed.
+    private static final int SCREEN_DIM_MINIMUM_REDUCTION = 10;
+
+    // If true, enables the use of the current time as an auto-brightness adjustment.
+    // The basic idea here is to expand the dynamic range of auto-brightness
+    // when it is especially dark outside.  The light sensor tends to perform
+    // poorly at low light levels so we compensate for it by making an
+    // assumption about the environment.
+    private static final boolean USE_TWILIGHT_ADJUSTMENT =
+            PowerManager.useTwilightAdjustmentFeature();
+
+    // Specifies the maximum magnitude of the time of day adjustment.
+    private static final float TWILIGHT_ADJUSTMENT_MAX_GAMMA = 1.5f;
+
+    // The amount of time after or before sunrise over which to start adjusting
+    // the gamma.  We want the change to happen gradually so that it is below the
+    // threshold of perceptibility and so that the adjustment has maximum effect
+    // well after dusk.
+    private static final long TWILIGHT_ADJUSTMENT_TIME = DateUtils.HOUR_IN_MILLIS * 2;
+
+    private static final int ELECTRON_BEAM_ON_ANIMATION_DURATION_MILLIS = 250;
+    private static final int ELECTRON_BEAM_OFF_ANIMATION_DURATION_MILLIS = 400;
+
+    private static final int MSG_UPDATE_POWER_STATE = 1;
+    private static final int MSG_PROXIMITY_SENSOR_DEBOUNCED = 2;
+    private static final int MSG_LIGHT_SENSOR_DEBOUNCED = 3;
+
+    private static final int PROXIMITY_UNKNOWN = -1;
+    private static final int PROXIMITY_NEGATIVE = 0;
+    private static final int PROXIMITY_POSITIVE = 1;
+
+    // Proximity sensor debounce delay in milliseconds for positive or negative transitions.
+    private static final int PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY = 0;
+    private static final int PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY = 250;
+
+    // Trigger proximity if distance is less than 5 cm.
+    private static final float TYPICAL_PROXIMITY_THRESHOLD = 5.0f;
+
+    // Light sensor event rate in milliseconds.
+    private static final int LIGHT_SENSOR_RATE_MILLIS = 1000;
+
+    // A rate for generating synthetic light sensor events in the case where the light
+    // sensor hasn't reported any new data in a while and we need it to update the
+    // debounce filter.  We only synthesize light sensor measurements when needed.
+    private static final int SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS =
+            LIGHT_SENSOR_RATE_MILLIS * 2;
+
+    // Brightness animation ramp rate in brightness units per second.
+    private static final int BRIGHTNESS_RAMP_RATE_FAST = 200;
+    private static final int BRIGHTNESS_RAMP_RATE_SLOW = 40;
+
+    // IIR filter time constants in milliseconds for computing two moving averages of
+    // the light samples.  One is a long-term average and the other is a short-term average.
+    // We can use these filters to assess trends in ambient brightness.
+    // The short term average gives us a filtered but relatively low latency measurement.
+    // The long term average informs us about the overall trend.
+    private static final long SHORT_TERM_AVERAGE_LIGHT_TIME_CONSTANT = 1000;
+    private static final long LONG_TERM_AVERAGE_LIGHT_TIME_CONSTANT = 5000;
+
+    // Stability requirements in milliseconds for accepting a new brightness
+    // level.  This is used for debouncing the light sensor.  Different constants
+    // are used to debounce the light sensor when adapting to brighter or darker environments.
+    // This parameter controls how quickly brightness changes occur in response to
+    // an observed change in light level that exceeds the hysteresis threshold.
+    private static final long BRIGHTENING_LIGHT_DEBOUNCE = 4000;
+    private static final long DARKENING_LIGHT_DEBOUNCE = 8000;
+
+    // Hysteresis constraints for brightening or darkening.
+    // The recent lux must have changed by at least this fraction relative to the
+    // current ambient lux before a change will be considered.
+    private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f;
+    private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f;
+
+    private final Object mLock = new Object();
+
+    // Notifier for sending asynchronous notifications.
+    private final Notifier mNotifier;
+
+    // The display suspend blocker.
+    // Held while there are pending state change notifications.
+    private final SuspendBlocker mDisplaySuspendBlocker;
+
+    // The display blanker.
+    private final DisplayBlanker mDisplayBlanker;
+
+    // Our handler.
+    private final DisplayControllerHandler mHandler;
+
+    // Asynchronous callbacks into the power manager service.
+    // Only invoked from the handler thread while no locks are held.
+    private final Callbacks mCallbacks;
+    private Handler mCallbackHandler;
+
+    // The lights service.
+    private final LightsManager mLights;
+
+    // The twilight service.
+    private final TwilightManager mTwilight;
+
+    // The sensor manager.
+    private final SensorManager mSensorManager;
+
+    // The proximity sensor, or null if not available or needed.
+    private Sensor mProximitySensor;
+
+    // The light sensor, or null if not available or needed.
+    private Sensor mLightSensor;
+
+    // The doze screen brightness.
+    private final int mScreenBrightnessDozeConfig;
+
+    // The dim screen brightness.
+    private final int mScreenBrightnessDimConfig;
+
+    // The minimum allowed brightness.
+    private final int mScreenBrightnessRangeMinimum;
+
+    // The maximum allowed brightness.
+    private final int mScreenBrightnessRangeMaximum;
+
+    // True if auto-brightness should be used.
+    private boolean mUseSoftwareAutoBrightnessConfig;
+
+    // The auto-brightness spline adjustment.
+    // The brightness values have been scaled to a range of 0..1.
+    private Spline mScreenAutoBrightnessSpline;
+
+    // Amount of time to delay auto-brightness after screen on while waiting for
+    // the light sensor to warm-up in milliseconds.
+    // May be 0 if no warm-up is required.
+    private int mLightSensorWarmUpTimeConfig;
+
+    // True if we should fade the screen while turning it off, false if we should play
+    // a stylish electron beam animation instead.
+    private boolean mElectronBeamFadesConfig;
+
+    // The pending power request.
+    // Initially null until the first call to requestPowerState.
+    // Guarded by mLock.
+    private DisplayPowerRequest mPendingRequestLocked;
+
+    // True if a request has been made to wait for the proximity sensor to go negative.
+    // Guarded by mLock.
+    private boolean mPendingWaitForNegativeProximityLocked;
+
+    // True if the pending power request or wait for negative proximity flag
+    // has been changed since the last update occurred.
+    // Guarded by mLock.
+    private boolean mPendingRequestChangedLocked;
+
+    // Set to true when the important parts of the pending power request have been applied.
+    // The important parts are mainly the screen state.  Brightness changes may occur
+    // concurrently.
+    // Guarded by mLock.
+    private boolean mDisplayReadyLocked;
+
+    // Set to true if a power state update is required.
+    // Guarded by mLock.
+    private boolean mPendingUpdatePowerStateLocked;
+
+    /* The following state must only be accessed by the handler thread. */
+
+    // The currently requested power state.
+    // The power controller will progressively update its internal state to match
+    // the requested power state.  Initially null until the first update.
+    private DisplayPowerRequest mPowerRequest;
+
+    // The current power state.
+    // Must only be accessed on the handler thread.
+    private DisplayPowerState mPowerState;
+
+    // True if the device should wait for negative proximity sensor before
+    // waking up the screen.  This is set to false as soon as a negative
+    // proximity sensor measurement is observed or when the device is forced to
+    // go to sleep by the user.  While true, the screen remains off.
+    private boolean mWaitingForNegativeProximity;
+
+    // The actual proximity sensor threshold value.
+    private float mProximityThreshold;
+
+    // Set to true if the proximity sensor listener has been registered
+    // with the sensor manager.
+    private boolean mProximitySensorEnabled;
+
+    // The debounced proximity sensor state.
+    private int mProximity = PROXIMITY_UNKNOWN;
+
+    // The raw non-debounced proximity sensor state.
+    private int mPendingProximity = PROXIMITY_UNKNOWN;
+    private long mPendingProximityDebounceTime = -1; // -1 if fully debounced
+
+    // True if the screen was turned off because of the proximity sensor.
+    // When the screen turns on again, we report user activity to the power manager.
+    private boolean mScreenOffBecauseOfProximity;
+
+    // True if the screen on is being blocked.
+    private boolean mScreenOnWasBlocked;
+
+    // The elapsed real time when the screen on was blocked.
+    private long mScreenOnBlockStartRealTime;
+
+    // Set to true if the light sensor is enabled.
+    private boolean mLightSensorEnabled;
+
+    // The time when the light sensor was enabled.
+    private long mLightSensorEnableTime;
+
+    // The currently accepted nominal ambient light level.
+    private float mAmbientLux;
+
+    // True if mAmbientLux holds a valid value.
+    private boolean mAmbientLuxValid;
+
+    // The ambient light level threshold at which to brighten or darken the screen.
+    private float mBrighteningLuxThreshold;
+    private float mDarkeningLuxThreshold;
+
+    // The most recent light sample.
+    private float mLastObservedLux;
+
+    // The time of the most light recent sample.
+    private long mLastObservedLuxTime;
+
+    // The number of light samples collected since the light sensor was enabled.
+    private int mRecentLightSamples;
+
+    // The long-term and short-term filtered light measurements.
+    private float mRecentShortTermAverageLux;
+    private float mRecentLongTermAverageLux;
+
+    // The direction in which the average lux is moving relative to the current ambient lux.
+    //    0 if not changing or within hysteresis threshold.
+    //    1 if brightening beyond hysteresis threshold.
+    //   -1 if darkening beyond hysteresis threshold.
+    private int mDebounceLuxDirection;
+
+    // The time when the average lux last changed direction.
+    private long mDebounceLuxTime;
+
+    // The screen brightness level that has been chosen by the auto-brightness
+    // algorithm.  The actual brightness should ramp towards this value.
+    // We preserve this value even when we stop using the light sensor so
+    // that we can quickly revert to the previous auto-brightness level
+    // while the light sensor warms up.
+    // Use -1 if there is no current auto-brightness value available.
+    private int mScreenAutoBrightness = -1;
+
+    // The last screen auto-brightness gamma.  (For printing in dump() only.)
+    private float mLastScreenAutoBrightnessGamma = 1.0f;
+
+    // True if the screen auto-brightness value is actually being used to
+    // set the display brightness.
+    private boolean mUsingScreenAutoBrightness;
+
+    // Animators.
+    private ObjectAnimator mElectronBeamOnAnimator;
+    private ObjectAnimator mElectronBeamOffAnimator;
+    private RampAnimator<DisplayPowerState> mScreenBrightnessRampAnimator;
+
+    // Twilight changed.  We might recalculate auto-brightness values.
+    private boolean mTwilightChanged;
+
+    /**
+     * Creates the display power controller.
+     */
+    public DisplayPowerController(Looper looper, Context context, Notifier notifier,
+            LightsManager lights, TwilightManager twilight, SensorManager sensorManager,
+            SuspendBlocker displaySuspendBlocker, DisplayBlanker displayBlanker,
+            Callbacks callbacks, Handler callbackHandler) {
+        mHandler = new DisplayControllerHandler(looper);
+        mNotifier = notifier;
+        mDisplaySuspendBlocker = displaySuspendBlocker;
+        mDisplayBlanker = displayBlanker;
+        mCallbacks = callbacks;
+        mCallbackHandler = callbackHandler;
+
+        mLights = lights;
+        mTwilight = twilight;
+        mSensorManager = sensorManager;
+
+        final Resources resources = context.getResources();
+
+        mScreenBrightnessDozeConfig = clampAbsoluteBrightness(resources.getInteger(
+                com.android.internal.R.integer.config_screenBrightnessDoze));
+
+        mScreenBrightnessDimConfig = clampAbsoluteBrightness(resources.getInteger(
+                com.android.internal.R.integer.config_screenBrightnessDim));
+
+        int screenBrightnessMinimum = Math.min(resources.getInteger(
+                com.android.internal.R.integer.config_screenBrightnessSettingMinimum),
+                mScreenBrightnessDimConfig);
+
+        mUseSoftwareAutoBrightnessConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_automatic_brightness_available);
+        if (mUseSoftwareAutoBrightnessConfig) {
+            int[] lux = resources.getIntArray(
+                    com.android.internal.R.array.config_autoBrightnessLevels);
+            int[] screenBrightness = resources.getIntArray(
+                    com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
+
+            mScreenAutoBrightnessSpline = createAutoBrightnessSpline(lux, screenBrightness);
+            if (mScreenAutoBrightnessSpline == null) {
+                Slog.e(TAG, "Error in config.xml.  config_autoBrightnessLcdBacklightValues "
+                        + "(size " + screenBrightness.length + ") "
+                        + "must be monotic and have exactly one more entry than "
+                        + "config_autoBrightnessLevels (size " + lux.length + ") "
+                        + "which must be strictly increasing.  "
+                        + "Auto-brightness will be disabled.");
+                mUseSoftwareAutoBrightnessConfig = false;
+            } else {
+                if (screenBrightness[0] < screenBrightnessMinimum) {
+                    screenBrightnessMinimum = screenBrightness[0];
+                }
+            }
+
+            mLightSensorWarmUpTimeConfig = resources.getInteger(
+                    com.android.internal.R.integer.config_lightSensorWarmupTime);
+        }
+
+        mScreenBrightnessRangeMinimum = clampAbsoluteBrightness(screenBrightnessMinimum);
+        mScreenBrightnessRangeMaximum = PowerManager.BRIGHTNESS_ON;
+
+        mElectronBeamFadesConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_animateScreenLights);
+
+        if (!DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT) {
+            mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
+            if (mProximitySensor != null) {
+                mProximityThreshold = Math.min(mProximitySensor.getMaximumRange(),
+                        TYPICAL_PROXIMITY_THRESHOLD);
+            }
+        }
+
+        if (mUseSoftwareAutoBrightnessConfig
+                && !DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
+            mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
+        }
+
+        if (mUseSoftwareAutoBrightnessConfig && USE_TWILIGHT_ADJUSTMENT) {
+            mTwilight.registerListener(mTwilightListener, mHandler);
+        }
+    }
+
+    private static Spline createAutoBrightnessSpline(int[] lux, int[] brightness) {
+        try {
+            final int n = brightness.length;
+            float[] x = new float[n];
+            float[] y = new float[n];
+            y[0] = normalizeAbsoluteBrightness(brightness[0]);
+            for (int i = 1; i < n; i++) {
+                x[i] = lux[i - 1];
+                y[i] = normalizeAbsoluteBrightness(brightness[i]);
+            }
+
+            Spline spline = Spline.createMonotoneCubicSpline(x, y);
+            if (DEBUG) {
+                Slog.d(TAG, "Auto-brightness spline: " + spline);
+                for (float v = 1f; v < lux[lux.length - 1] * 1.25f; v *= 1.25f) {
+                    Slog.d(TAG, String.format("  %7.1f: %7.1f", v, spline.interpolate(v)));
+                }
+            }
+            return spline;
+        } catch (IllegalArgumentException ex) {
+            Slog.e(TAG, "Could not create auto-brightness spline.", ex);
+            return null;
+        }
+    }
+
+    /**
+     * Returns true if the proximity sensor screen-off function is available.
+     */
+    public boolean isProximitySensorAvailable() {
+        return mProximitySensor != null;
+    }
+
+    /**
+     * Requests a new power state.
+     * The controller makes a copy of the provided object and then
+     * begins adjusting the power state to match what was requested.
+     *
+     * @param request The requested power state.
+     * @param waitForNegativeProximity If true, issues a request to wait for
+     * negative proximity before turning the screen back on, assuming the screen
+     * was turned off by the proximity sensor.
+     * @return True if display is ready, false if there are important changes that must
+     * be made asynchronously (such as turning the screen on), in which case the caller
+     * should grab a wake lock, watch for {@link Callbacks#onStateChanged()} then try
+     * the request again later until the state converges.
+     */
+    public boolean requestPowerState(DisplayPowerRequest request,
+            boolean waitForNegativeProximity) {
+        if (DEBUG) {
+            Slog.d(TAG, "requestPowerState: "
+                    + request + ", waitForNegativeProximity=" + waitForNegativeProximity);
+        }
+
+        synchronized (mLock) {
+            boolean changed = false;
+
+            if (waitForNegativeProximity
+                    && !mPendingWaitForNegativeProximityLocked) {
+                mPendingWaitForNegativeProximityLocked = true;
+                changed = true;
+            }
+
+            if (mPendingRequestLocked == null) {
+                mPendingRequestLocked = new DisplayPowerRequest(request);
+                changed = true;
+            } else if (!mPendingRequestLocked.equals(request)) {
+                mPendingRequestLocked.copyFrom(request);
+                changed = true;
+            }
+
+            if (changed) {
+                mDisplayReadyLocked = false;
+            }
+
+            if (changed && !mPendingRequestChangedLocked) {
+                mPendingRequestChangedLocked = true;
+                sendUpdatePowerStateLocked();
+            }
+
+            return mDisplayReadyLocked;
+        }
+    }
+
+    private void sendUpdatePowerState() {
+        synchronized (mLock) {
+            sendUpdatePowerStateLocked();
+        }
+    }
+
+    private void sendUpdatePowerStateLocked() {
+        if (!mPendingUpdatePowerStateLocked) {
+            mPendingUpdatePowerStateLocked = true;
+            Message msg = mHandler.obtainMessage(MSG_UPDATE_POWER_STATE);
+            msg.setAsynchronous(true);
+            mHandler.sendMessage(msg);
+        }
+    }
+
+    private void initialize() {
+        mPowerState = new DisplayPowerState(new ElectronBeam(), mDisplayBlanker,
+                mLights.getLight(LightsManager.LIGHT_ID_BACKLIGHT));
+
+        mElectronBeamOnAnimator = ObjectAnimator.ofFloat(
+                mPowerState, DisplayPowerState.ELECTRON_BEAM_LEVEL, 0.0f, 1.0f);
+        mElectronBeamOnAnimator.setDuration(ELECTRON_BEAM_ON_ANIMATION_DURATION_MILLIS);
+        mElectronBeamOnAnimator.addListener(mAnimatorListener);
+
+        mElectronBeamOffAnimator = ObjectAnimator.ofFloat(
+                mPowerState, DisplayPowerState.ELECTRON_BEAM_LEVEL, 1.0f, 0.0f);
+        mElectronBeamOffAnimator.setDuration(ELECTRON_BEAM_OFF_ANIMATION_DURATION_MILLIS);
+        mElectronBeamOffAnimator.addListener(mAnimatorListener);
+
+        mScreenBrightnessRampAnimator = new RampAnimator<DisplayPowerState>(
+                mPowerState, DisplayPowerState.SCREEN_BRIGHTNESS);
+    }
+
+    private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() {
+        @Override
+        public void onAnimationStart(Animator animation) {
+        }
+        @Override
+        public void onAnimationEnd(Animator animation) {
+            sendUpdatePowerState();
+        }
+        @Override
+        public void onAnimationRepeat(Animator animation) {
+        }
+        @Override
+        public void onAnimationCancel(Animator animation) {
+        }
+    };
+
+    private void updatePowerState() {
+        // Update the power state request.
+        final boolean mustNotify;
+        boolean mustInitialize = false;
+        boolean updateAutoBrightness = mTwilightChanged;
+        boolean wasDimOrDoze = false;
+        mTwilightChanged = false;
+
+        synchronized (mLock) {
+            mPendingUpdatePowerStateLocked = false;
+            if (mPendingRequestLocked == null) {
+                return; // wait until first actual power request
+            }
+
+            if (mPowerRequest == null) {
+                mPowerRequest = new DisplayPowerRequest(mPendingRequestLocked);
+                mWaitingForNegativeProximity = mPendingWaitForNegativeProximityLocked;
+                mPendingWaitForNegativeProximityLocked = false;
+                mPendingRequestChangedLocked = false;
+                mustInitialize = true;
+            } else if (mPendingRequestChangedLocked) {
+                if (mPowerRequest.screenAutoBrightnessAdjustment
+                        != mPendingRequestLocked.screenAutoBrightnessAdjustment) {
+                    updateAutoBrightness = true;
+                }
+                wasDimOrDoze = (mPowerRequest.screenState == DisplayPowerRequest.SCREEN_STATE_DIM
+                        || mPowerRequest.screenState == DisplayPowerRequest.SCREEN_STATE_DOZE);
+                mPowerRequest.copyFrom(mPendingRequestLocked);
+                mWaitingForNegativeProximity |= mPendingWaitForNegativeProximityLocked;
+                mPendingWaitForNegativeProximityLocked = false;
+                mPendingRequestChangedLocked = false;
+                mDisplayReadyLocked = false;
+            }
+
+            mustNotify = !mDisplayReadyLocked;
+        }
+
+        // Initialize things the first time the power state is changed.
+        if (mustInitialize) {
+            initialize();
+        }
+
+        // Apply the proximity sensor.
+        if (mProximitySensor != null) {
+            if (mPowerRequest.useProximitySensor
+                    && mPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
+                setProximitySensorEnabled(true);
+                if (!mScreenOffBecauseOfProximity
+                        && mProximity == PROXIMITY_POSITIVE) {
+                    mScreenOffBecauseOfProximity = true;
+                    sendOnProximityPositiveWithWakelock();
+                }
+            } else if (mWaitingForNegativeProximity
+                    && mScreenOffBecauseOfProximity
+                    && mProximity == PROXIMITY_POSITIVE
+                    && mPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
+                setProximitySensorEnabled(true);
+            } else {
+                setProximitySensorEnabled(false);
+                mWaitingForNegativeProximity = false;
+            }
+            if (mScreenOffBecauseOfProximity
+                    && mProximity != PROXIMITY_POSITIVE) {
+                mScreenOffBecauseOfProximity = false;
+                sendOnProximityNegativeWithWakelock();
+            }
+        } else {
+            mWaitingForNegativeProximity = false;
+        }
+
+        // Turn on the light sensor if needed.
+        if (mLightSensor != null) {
+            setLightSensorEnabled(mPowerRequest.wantLightSensorEnabled(),
+                    updateAutoBrightness);
+        }
+
+        // Set the screen brightness.
+        if (mPowerRequest.wantScreenOnAny()) {
+            int target;
+            boolean slow;
+            if (mScreenAutoBrightness >= 0 && mLightSensorEnabled) {
+                // Use current auto-brightness value.
+                target = mScreenAutoBrightness;
+                slow = mUsingScreenAutoBrightness;
+                mUsingScreenAutoBrightness = true;
+            } else {
+                // Light sensor is disabled or not ready yet.
+                // Use the current brightness setting from the request, which is expected
+                // provide a nominal default value for the case where auto-brightness
+                // is not ready yet.
+                target = mPowerRequest.screenBrightness;
+                slow = false;
+                mUsingScreenAutoBrightness = false;
+            }
+            if (mPowerRequest.screenState == DisplayPowerRequest.SCREEN_STATE_DOZE) {
+                // Dim quickly to the doze state.
+                target = mScreenBrightnessDozeConfig;
+                slow = false;
+            } else if (mPowerRequest.screenState == DisplayPowerRequest.SCREEN_STATE_DIM) {
+                // Dim quickly by at least some minimum amount.
+                target = Math.min(target - SCREEN_DIM_MINIMUM_REDUCTION,
+                        mScreenBrightnessDimConfig);
+                slow = false;
+            } else if (wasDimOrDoze) {
+                // Brighten quickly.
+                slow = false;
+            }
+            animateScreenBrightness(clampScreenBrightness(target),
+                    slow ? BRIGHTNESS_RAMP_RATE_SLOW : BRIGHTNESS_RAMP_RATE_FAST);
+        } else {
+            // Screen is off.  Don't bother changing the brightness.
+            mUsingScreenAutoBrightness = false;
+        }
+
+        // Animate the screen on or off unless blocked.
+        if (mScreenOffBecauseOfProximity) {
+            // Screen off due to proximity.
+            setScreenOn(false);
+            unblockScreenOn();
+        } else if (mPowerRequest.wantScreenOnAny()) {
+            // Want screen on.
+            // Wait for previous off animation to complete beforehand.
+            // It is relatively short but if we cancel it and switch to the
+            // on animation immediately then the results are pretty ugly.
+            if (!mElectronBeamOffAnimator.isStarted()) {
+                // Turn the screen on.  The contents of the screen may not yet
+                // be visible if the electron beam has not been dismissed because
+                // its last frame of animation is solid black.
+                setScreenOn(true);
+
+                if (mPowerRequest.blockScreenOn
+                        && mPowerState.getElectronBeamLevel() == 0.0f) {
+                    blockScreenOn();
+                } else {
+                    unblockScreenOn();
+                    if (USE_ELECTRON_BEAM_ON_ANIMATION) {
+                        if (!mElectronBeamOnAnimator.isStarted()) {
+                            if (mPowerState.getElectronBeamLevel() == 1.0f) {
+                                mPowerState.dismissElectronBeam();
+                            } else if (mPowerState.prepareElectronBeam(
+                                    mElectronBeamFadesConfig ?
+                                            ElectronBeam.MODE_FADE :
+                                                    ElectronBeam.MODE_WARM_UP)) {
+                                mElectronBeamOnAnimator.start();
+                            } else {
+                                mElectronBeamOnAnimator.end();
+                            }
+                        }
+                    } else {
+                        mPowerState.setElectronBeamLevel(1.0f);
+                        mPowerState.dismissElectronBeam();
+                    }
+                }
+            }
+        } else {
+            // Want screen off.
+            // Wait for previous on animation to complete beforehand.
+            unblockScreenOn();
+            if (!mElectronBeamOnAnimator.isStarted()) {
+                if (!mElectronBeamOffAnimator.isStarted()) {
+                    if (mPowerState.getElectronBeamLevel() == 0.0f) {
+                        setScreenOn(false);
+                    } else if (mPowerState.prepareElectronBeam(
+                            mElectronBeamFadesConfig ?
+                                    ElectronBeam.MODE_FADE :
+                                            ElectronBeam.MODE_COOL_DOWN)
+                            && mPowerState.isScreenOn()) {
+                        mElectronBeamOffAnimator.start();
+                    } else {
+                        mElectronBeamOffAnimator.end();
+                    }
+                }
+            }
+        }
+
+        // Report whether the display is ready for use.
+        // We mostly care about the screen state here, ignoring brightness changes
+        // which will be handled asynchronously.
+        if (mustNotify
+                && !mScreenOnWasBlocked
+                && !mElectronBeamOnAnimator.isStarted()
+                && !mElectronBeamOffAnimator.isStarted()
+                && mPowerState.waitUntilClean(mCleanListener)) {
+            synchronized (mLock) {
+                if (!mPendingRequestChangedLocked) {
+                    mDisplayReadyLocked = true;
+
+                    if (DEBUG) {
+                        Slog.d(TAG, "Display ready!");
+                    }
+                }
+            }
+            sendOnStateChangedWithWakelock();
+        }
+    }
+
+    private void blockScreenOn() {
+        if (!mScreenOnWasBlocked) {
+            mScreenOnWasBlocked = true;
+            if (DEBUG) {
+                Slog.d(TAG, "Blocked screen on.");
+                mScreenOnBlockStartRealTime = SystemClock.elapsedRealtime();
+            }
+        }
+    }
+
+    private void unblockScreenOn() {
+        if (mScreenOnWasBlocked) {
+            mScreenOnWasBlocked = false;
+            long delay = SystemClock.elapsedRealtime() - mScreenOnBlockStartRealTime;
+            if (delay > 1000 || DEBUG) {
+                Slog.d(TAG, "Unblocked screen on after " + delay + " ms");
+            }
+        }
+    }
+
+    private void setScreenOn(boolean on) {
+        if (mPowerState.isScreenOn() != on) {
+            mPowerState.setScreenOn(on);
+            if (on) {
+                mNotifier.onScreenOn();
+            } else {
+                mNotifier.onScreenOff();
+            }
+        }
+    }
+
+    private int clampScreenBrightness(int value) {
+        return clamp(value, mScreenBrightnessRangeMinimum, mScreenBrightnessRangeMaximum);
+    }
+
+    private static int clampAbsoluteBrightness(int value) {
+        return clamp(value, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
+    }
+
+    private static int clamp(int value, int min, int max) {
+        if (value <= min) {
+            return min;
+        }
+        if (value >= max) {
+            return max;
+        }
+        return value;
+    }
+
+    private static float normalizeAbsoluteBrightness(int value) {
+        return (float)clampAbsoluteBrightness(value) / PowerManager.BRIGHTNESS_ON;
+    }
+
+    private void animateScreenBrightness(int target, int rate) {
+        if (mScreenBrightnessRampAnimator.animateTo(target, rate)) {
+            mNotifier.onScreenBrightness(target);
+        }
+    }
+
+    private final Runnable mCleanListener = new Runnable() {
+        @Override
+        public void run() {
+            sendUpdatePowerState();
+        }
+    };
+
+    private void setProximitySensorEnabled(boolean enable) {
+        if (enable) {
+            if (!mProximitySensorEnabled) {
+                // Register the listener.
+                // Proximity sensor state already cleared initially.
+                mProximitySensorEnabled = true;
+                mSensorManager.registerListener(mProximitySensorListener, mProximitySensor,
+                        SensorManager.SENSOR_DELAY_NORMAL, mHandler);
+            }
+        } else {
+            if (mProximitySensorEnabled) {
+                // Unregister the listener.
+                // Clear the proximity sensor state for next time.
+                mProximitySensorEnabled = false;
+                mProximity = PROXIMITY_UNKNOWN;
+                mPendingProximity = PROXIMITY_UNKNOWN;
+                mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
+                mSensorManager.unregisterListener(mProximitySensorListener);
+                clearPendingProximityDebounceTime(); // release wake lock (must be last)
+            }
+        }
+    }
+
+    private void handleProximitySensorEvent(long time, boolean positive) {
+        if (mProximitySensorEnabled) {
+            if (mPendingProximity == PROXIMITY_NEGATIVE && !positive) {
+                return; // no change
+            }
+            if (mPendingProximity == PROXIMITY_POSITIVE && positive) {
+                return; // no change
+            }
+
+            // Only accept a proximity sensor reading if it remains
+            // stable for the entire debounce delay.  We hold a wake lock while
+            // debouncing the sensor.
+            mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
+            if (positive) {
+                mPendingProximity = PROXIMITY_POSITIVE;
+                setPendingProximityDebounceTime(
+                        time + PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY); // acquire wake lock
+            } else {
+                mPendingProximity = PROXIMITY_NEGATIVE;
+                setPendingProximityDebounceTime(
+                        time + PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY); // acquire wake lock
+            }
+
+            // Debounce the new sensor reading.
+            debounceProximitySensor();
+        }
+    }
+
+    private void debounceProximitySensor() {
+        if (mProximitySensorEnabled
+                && mPendingProximity != PROXIMITY_UNKNOWN
+                && mPendingProximityDebounceTime >= 0) {
+            final long now = SystemClock.uptimeMillis();
+            if (mPendingProximityDebounceTime <= now) {
+                // Sensor reading accepted.  Apply the change then release the wake lock.
+                mProximity = mPendingProximity;
+                updatePowerState();
+                clearPendingProximityDebounceTime(); // release wake lock (must be last)
+            } else {
+                // Need to wait a little longer.
+                // Debounce again later.  We continue holding a wake lock while waiting.
+                Message msg = mHandler.obtainMessage(MSG_PROXIMITY_SENSOR_DEBOUNCED);
+                msg.setAsynchronous(true);
+                mHandler.sendMessageAtTime(msg, mPendingProximityDebounceTime);
+            }
+        }
+    }
+
+    private void clearPendingProximityDebounceTime() {
+        if (mPendingProximityDebounceTime >= 0) {
+            mPendingProximityDebounceTime = -1;
+            mDisplaySuspendBlocker.release(); // release wake lock
+        }
+    }
+
+    private void setPendingProximityDebounceTime(long debounceTime) {
+        if (mPendingProximityDebounceTime < 0) {
+            mDisplaySuspendBlocker.acquire(); // acquire wake lock
+        }
+        mPendingProximityDebounceTime = debounceTime;
+    }
+
+    private void setLightSensorEnabled(boolean enable, boolean updateAutoBrightness) {
+        if (enable) {
+            if (!mLightSensorEnabled) {
+                updateAutoBrightness = true;
+                mLightSensorEnabled = true;
+                mLightSensorEnableTime = SystemClock.uptimeMillis();
+                mSensorManager.registerListener(mLightSensorListener, mLightSensor,
+                        LIGHT_SENSOR_RATE_MILLIS * 1000, mHandler);
+            }
+        } else {
+            if (mLightSensorEnabled) {
+                mLightSensorEnabled = false;
+                mAmbientLuxValid = false;
+                mRecentLightSamples = 0;
+                mHandler.removeMessages(MSG_LIGHT_SENSOR_DEBOUNCED);
+                mSensorManager.unregisterListener(mLightSensorListener);
+            }
+        }
+        if (updateAutoBrightness) {
+            updateAutoBrightness(false);
+        }
+    }
+
+    private void handleLightSensorEvent(long time, float lux) {
+        mHandler.removeMessages(MSG_LIGHT_SENSOR_DEBOUNCED);
+
+        applyLightSensorMeasurement(time, lux);
+        updateAmbientLux(time);
+    }
+
+    private void applyLightSensorMeasurement(long time, float lux) {
+        // Update our filters.
+        mRecentLightSamples += 1;
+        if (mRecentLightSamples == 1) {
+            mRecentShortTermAverageLux = lux;
+            mRecentLongTermAverageLux = lux;
+        } else {
+            final long timeDelta = time - mLastObservedLuxTime;
+            mRecentShortTermAverageLux += (lux - mRecentShortTermAverageLux)
+                    * timeDelta / (SHORT_TERM_AVERAGE_LIGHT_TIME_CONSTANT + timeDelta);
+            mRecentLongTermAverageLux += (lux - mRecentLongTermAverageLux)
+                    * timeDelta / (LONG_TERM_AVERAGE_LIGHT_TIME_CONSTANT + timeDelta);
+        }
+
+        // Remember this sample value.
+        mLastObservedLux = lux;
+        mLastObservedLuxTime = time;
+    }
+
+    private void setAmbientLux(float lux) {
+        mAmbientLux = lux;
+        mBrighteningLuxThreshold = mAmbientLux * (1.0f + BRIGHTENING_LIGHT_HYSTERESIS);
+        mDarkeningLuxThreshold = mAmbientLux * (1.0f - DARKENING_LIGHT_HYSTERESIS);
+    }
+
+    private void updateAmbientLux(long time) {
+        // If the light sensor was just turned on then immediately update our initial
+        // estimate of the current ambient light level.
+        if (!mAmbientLuxValid) {
+            final long timeWhenSensorWarmedUp =
+                mLightSensorWarmUpTimeConfig + mLightSensorEnableTime;
+            if (time < timeWhenSensorWarmedUp) {
+                mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED,
+                        timeWhenSensorWarmedUp);
+                return;
+            }
+            setAmbientLux(mRecentShortTermAverageLux);
+            mAmbientLuxValid = true;
+            mDebounceLuxDirection = 0;
+            mDebounceLuxTime = time;
+            if (DEBUG) {
+                Slog.d(TAG, "updateAmbientLux: Initializing: "
+                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+                        + ", mAmbientLux=" + mAmbientLux);
+            }
+            updateAutoBrightness(true);
+        } else if (mRecentShortTermAverageLux > mBrighteningLuxThreshold
+                && mRecentLongTermAverageLux > mBrighteningLuxThreshold) {
+            // The ambient environment appears to be brightening.
+            if (mDebounceLuxDirection <= 0) {
+                mDebounceLuxDirection = 1;
+                mDebounceLuxTime = time;
+                if (DEBUG) {
+                    Slog.d(TAG, "updateAmbientLux: Possibly brightened, waiting for "
+                            + BRIGHTENING_LIGHT_DEBOUNCE + " ms: "
+                            + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
+                            + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+                            + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+                            + ", mAmbientLux=" + mAmbientLux);
+                }
+            }
+            long debounceTime = mDebounceLuxTime + BRIGHTENING_LIGHT_DEBOUNCE;
+            if (time < debounceTime) {
+                mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED, debounceTime);
+                return;
+            }
+            setAmbientLux(mRecentShortTermAverageLux);
+            if (DEBUG) {
+                Slog.d(TAG, "updateAmbientLux: Brightened: "
+                        + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
+                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+                        + ", mAmbientLux=" + mAmbientLux);
+            }
+            updateAutoBrightness(true);
+        } else if (mRecentShortTermAverageLux < mDarkeningLuxThreshold
+                && mRecentLongTermAverageLux < mDarkeningLuxThreshold) {
+            // The ambient environment appears to be darkening.
+            if (mDebounceLuxDirection >= 0) {
+                mDebounceLuxDirection = -1;
+                mDebounceLuxTime = time;
+                if (DEBUG) {
+                    Slog.d(TAG, "updateAmbientLux: Possibly darkened, waiting for "
+                            + DARKENING_LIGHT_DEBOUNCE + " ms: "
+                            + "mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
+                            + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+                            + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+                            + ", mAmbientLux=" + mAmbientLux);
+                }
+            }
+            long debounceTime = mDebounceLuxTime + DARKENING_LIGHT_DEBOUNCE;
+            if (time < debounceTime) {
+                mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED, debounceTime);
+                return;
+            }
+            // Be conservative about reducing the brightness, only reduce it a little bit
+            // at a time to avoid having to bump it up again soon.
+            setAmbientLux(Math.max(mRecentShortTermAverageLux, mRecentLongTermAverageLux));
+            if (DEBUG) {
+                Slog.d(TAG, "updateAmbientLux: Darkened: "
+                        + "mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
+                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+                        + ", mAmbientLux=" + mAmbientLux);
+            }
+            updateAutoBrightness(true);
+        } else if (mDebounceLuxDirection != 0) {
+            // No change or change is within the hysteresis thresholds.
+            mDebounceLuxDirection = 0;
+            mDebounceLuxTime = time;
+            if (DEBUG) {
+                Slog.d(TAG, "updateAmbientLux: Canceled debounce: "
+                        + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
+                        + ", mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
+                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
+                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
+                        + ", mAmbientLux=" + mAmbientLux);
+            }
+        }
+
+        // Now that we've done all of that, we haven't yet posted a debounce
+        // message. So consider the case where current lux is beyond the
+        // threshold. It's possible that the light sensor may not report values
+        // if the light level does not change, so we need to occasionally
+        // synthesize sensor readings in order to make sure the brightness is
+        // adjusted accordingly. Note these thresholds may have changed since
+        // we entered the function because we called setAmbientLux and
+        // updateAutoBrightness along the way.
+        if (mLastObservedLux > mBrighteningLuxThreshold
+                || mLastObservedLux < mDarkeningLuxThreshold) {
+            mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED,
+                    time + SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS);
+        }
+    }
+
+    private void debounceLightSensor() {
+        if (mLightSensorEnabled) {
+            long time = SystemClock.uptimeMillis();
+            if (time >= mLastObservedLuxTime + SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS) {
+                if (DEBUG) {
+                    Slog.d(TAG, "debounceLightSensor: Synthesizing light sensor measurement "
+                            + "after " + (time - mLastObservedLuxTime) + " ms.");
+                }
+                applyLightSensorMeasurement(time, mLastObservedLux);
+            }
+            updateAmbientLux(time);
+        }
+    }
+
+    private void updateAutoBrightness(boolean sendUpdate) {
+        if (!mAmbientLuxValid) {
+            return;
+        }
+
+        float value = mScreenAutoBrightnessSpline.interpolate(mAmbientLux);
+        float gamma = 1.0f;
+
+        if (USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT
+                && mPowerRequest.screenAutoBrightnessAdjustment != 0.0f) {
+            final float adjGamma = FloatMath.pow(SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA,
+                    Math.min(1.0f, Math.max(-1.0f,
+                            -mPowerRequest.screenAutoBrightnessAdjustment)));
+            gamma *= adjGamma;
+            if (DEBUG) {
+                Slog.d(TAG, "updateAutoBrightness: adjGamma=" + adjGamma);
+            }
+        }
+
+        if (USE_TWILIGHT_ADJUSTMENT) {
+            TwilightState state = mTwilight.getCurrentState();
+            if (state != null && state.isNight()) {
+                final long now = System.currentTimeMillis();
+                final float earlyGamma =
+                        getTwilightGamma(now, state.getYesterdaySunset(), state.getTodaySunrise());
+                final float lateGamma =
+                        getTwilightGamma(now, state.getTodaySunset(), state.getTomorrowSunrise());
+                gamma *= earlyGamma * lateGamma;
+                if (DEBUG) {
+                    Slog.d(TAG, "updateAutoBrightness: earlyGamma=" + earlyGamma
+                            + ", lateGamma=" + lateGamma);
+                }
+            }
+        }
+
+        if (gamma != 1.0f) {
+            final float in = value;
+            value = FloatMath.pow(value, gamma);
+            if (DEBUG) {
+                Slog.d(TAG, "updateAutoBrightness: gamma=" + gamma
+                        + ", in=" + in + ", out=" + value);
+            }
+        }
+
+        int newScreenAutoBrightness = clampScreenBrightness(
+                Math.round(value * PowerManager.BRIGHTNESS_ON));
+        if (mScreenAutoBrightness != newScreenAutoBrightness) {
+            if (DEBUG) {
+                Slog.d(TAG, "updateAutoBrightness: mScreenAutoBrightness="
+                        + mScreenAutoBrightness + ", newScreenAutoBrightness="
+                        + newScreenAutoBrightness);
+            }
+
+            mScreenAutoBrightness = newScreenAutoBrightness;
+            mLastScreenAutoBrightnessGamma = gamma;
+            if (sendUpdate) {
+                sendUpdatePowerState();
+            }
+        }
+    }
+
+    private static float getTwilightGamma(long now, long lastSunset, long nextSunrise) {
+        if (lastSunset < 0 || nextSunrise < 0
+                || now < lastSunset || now > nextSunrise) {
+            return 1.0f;
+        }
+
+        if (now < lastSunset + TWILIGHT_ADJUSTMENT_TIME) {
+            return lerp(1.0f, TWILIGHT_ADJUSTMENT_MAX_GAMMA,
+                    (float)(now - lastSunset) / TWILIGHT_ADJUSTMENT_TIME);
+        }
+
+        if (now > nextSunrise - TWILIGHT_ADJUSTMENT_TIME) {
+            return lerp(1.0f, TWILIGHT_ADJUSTMENT_MAX_GAMMA,
+                    (float)(nextSunrise - now) / TWILIGHT_ADJUSTMENT_TIME);
+        }
+
+        return TWILIGHT_ADJUSTMENT_MAX_GAMMA;
+    }
+
+    private static float lerp(float x, float y, float alpha) {
+        return x + (y - x) * alpha;
+    }
+
+    private void sendOnStateChangedWithWakelock() {
+        mDisplaySuspendBlocker.acquire();
+        mCallbackHandler.post(mOnStateChangedRunnable);
+    }
+
+    private final Runnable mOnStateChangedRunnable = new Runnable() {
+        @Override
+        public void run() {
+            mCallbacks.onStateChanged();
+            mDisplaySuspendBlocker.release();
+        }
+    };
+
+    private void sendOnProximityPositiveWithWakelock() {
+        mDisplaySuspendBlocker.acquire();
+        mCallbackHandler.post(mOnProximityPositiveRunnable);
+    }
+
+    private final Runnable mOnProximityPositiveRunnable = new Runnable() {
+        @Override
+        public void run() {
+            mCallbacks.onProximityPositive();
+            mDisplaySuspendBlocker.release();
+        }
+    };
+
+    private void sendOnProximityNegativeWithWakelock() {
+        mDisplaySuspendBlocker.acquire();
+        mCallbackHandler.post(mOnProximityNegativeRunnable);
+    }
+
+    private final Runnable mOnProximityNegativeRunnable = new Runnable() {
+        @Override
+        public void run() {
+            mCallbacks.onProximityNegative();
+            mDisplaySuspendBlocker.release();
+        }
+    };
+
+    public void dump(final PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println();
+            pw.println("Display Controller Locked State:");
+            pw.println("  mDisplayReadyLocked=" + mDisplayReadyLocked);
+            pw.println("  mPendingRequestLocked=" + mPendingRequestLocked);
+            pw.println("  mPendingRequestChangedLocked=" + mPendingRequestChangedLocked);
+            pw.println("  mPendingWaitForNegativeProximityLocked="
+                    + mPendingWaitForNegativeProximityLocked);
+            pw.println("  mPendingUpdatePowerStateLocked=" + mPendingUpdatePowerStateLocked);
+        }
+
+        pw.println();
+        pw.println("Display Controller Configuration:");
+        pw.println("  mScreenBrightnessDozeConfig=" + mScreenBrightnessDozeConfig);
+        pw.println("  mScreenBrightnessDimConfig=" + mScreenBrightnessDimConfig);
+        pw.println("  mScreenBrightnessRangeMinimum=" + mScreenBrightnessRangeMinimum);
+        pw.println("  mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum);
+        pw.println("  mUseSoftwareAutoBrightnessConfig="
+                + mUseSoftwareAutoBrightnessConfig);
+        pw.println("  mScreenAutoBrightnessSpline=" + mScreenAutoBrightnessSpline);
+        pw.println("  mLightSensorWarmUpTimeConfig=" + mLightSensorWarmUpTimeConfig);
+
+        mHandler.runWithScissors(new Runnable() {
+            @Override
+            public void run() {
+                dumpLocal(pw);
+            }
+        }, 1000);
+    }
+
+    private void dumpLocal(PrintWriter pw) {
+        pw.println();
+        pw.println("Display Controller Thread State:");
+        pw.println("  mPowerRequest=" + mPowerRequest);
+        pw.println("  mWaitingForNegativeProximity=" + mWaitingForNegativeProximity);
+
+        pw.println("  mProximitySensor=" + mProximitySensor);
+        pw.println("  mProximitySensorEnabled=" + mProximitySensorEnabled);
+        pw.println("  mProximityThreshold=" + mProximityThreshold);
+        pw.println("  mProximity=" + proximityToString(mProximity));
+        pw.println("  mPendingProximity=" + proximityToString(mPendingProximity));
+        pw.println("  mPendingProximityDebounceTime="
+                + TimeUtils.formatUptime(mPendingProximityDebounceTime));
+        pw.println("  mScreenOffBecauseOfProximity=" + mScreenOffBecauseOfProximity);
+
+        pw.println("  mLightSensor=" + mLightSensor);
+        pw.println("  mLightSensorEnabled=" + mLightSensorEnabled);
+        pw.println("  mLightSensorEnableTime="
+                + TimeUtils.formatUptime(mLightSensorEnableTime));
+        pw.println("  mAmbientLux=" + mAmbientLux);
+        pw.println("  mAmbientLuxValid=" + mAmbientLuxValid);
+        pw.println("  mLastObservedLux=" + mLastObservedLux);
+        pw.println("  mLastObservedLuxTime="
+                + TimeUtils.formatUptime(mLastObservedLuxTime));
+        pw.println("  mRecentLightSamples=" + mRecentLightSamples);
+        pw.println("  mRecentShortTermAverageLux=" + mRecentShortTermAverageLux);
+        pw.println("  mRecentLongTermAverageLux=" + mRecentLongTermAverageLux);
+        pw.println("  mDebounceLuxDirection=" + mDebounceLuxDirection);
+        pw.println("  mDebounceLuxTime=" + TimeUtils.formatUptime(mDebounceLuxTime));
+        pw.println("  mScreenAutoBrightness=" + mScreenAutoBrightness);
+        pw.println("  mUsingScreenAutoBrightness=" + mUsingScreenAutoBrightness);
+        pw.println("  mLastScreenAutoBrightnessGamma=" + mLastScreenAutoBrightnessGamma);
+        pw.println("  mTwilight.getCurrentState()=" + mTwilight.getCurrentState());
+
+        if (mElectronBeamOnAnimator != null) {
+            pw.println("  mElectronBeamOnAnimator.isStarted()=" +
+                    mElectronBeamOnAnimator.isStarted());
+        }
+        if (mElectronBeamOffAnimator != null) {
+            pw.println("  mElectronBeamOffAnimator.isStarted()=" +
+                    mElectronBeamOffAnimator.isStarted());
+        }
+
+        if (mPowerState != null) {
+            mPowerState.dump(pw);
+        }
+    }
+
+    private static String proximityToString(int state) {
+        switch (state) {
+            case PROXIMITY_UNKNOWN:
+                return "Unknown";
+            case PROXIMITY_NEGATIVE:
+                return "Negative";
+            case PROXIMITY_POSITIVE:
+                return "Positive";
+            default:
+                return Integer.toString(state);
+        }
+    }
+
+    /**
+     * Asynchronous callbacks from the power controller to the power manager service.
+     */
+    public interface Callbacks {
+        void onStateChanged();
+        void onProximityPositive();
+        void onProximityNegative();
+    }
+
+    private final class DisplayControllerHandler extends Handler {
+        public DisplayControllerHandler(Looper looper) {
+            super(looper, null, true /*async*/);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_UPDATE_POWER_STATE:
+                    updatePowerState();
+                    break;
+
+                case MSG_PROXIMITY_SENSOR_DEBOUNCED:
+                    debounceProximitySensor();
+                    break;
+
+                case MSG_LIGHT_SENSOR_DEBOUNCED:
+                    debounceLightSensor();
+                    break;
+            }
+        }
+    }
+
+    private final SensorEventListener mProximitySensorListener = new SensorEventListener() {
+        @Override
+        public void onSensorChanged(SensorEvent event) {
+            if (mProximitySensorEnabled) {
+                final long time = SystemClock.uptimeMillis();
+                final float distance = event.values[0];
+                boolean positive = distance >= 0.0f && distance < mProximityThreshold;
+                handleProximitySensorEvent(time, positive);
+            }
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor sensor, int accuracy) {
+            // Not used.
+        }
+    };
+
+    private final SensorEventListener mLightSensorListener = new SensorEventListener() {
+        @Override
+        public void onSensorChanged(SensorEvent event) {
+            if (mLightSensorEnabled) {
+                final long time = SystemClock.uptimeMillis();
+                final float lux = event.values[0];
+                handleLightSensorEvent(time, lux);
+            }
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor sensor, int accuracy) {
+            // Not used.
+        }
+    };
+
+    private final TwilightListener mTwilightListener = new TwilightListener() {
+        @Override
+        public void onTwilightStateChanged() {
+            mTwilightChanged = true;
+            updatePowerState();
+        }
+    };
+}
diff --git a/services/core/java/com/android/server/power/DisplayPowerRequest.java b/services/core/java/com/android/server/power/DisplayPowerRequest.java
new file mode 100644
index 0000000..6061a40
--- /dev/null
+++ b/services/core/java/com/android/server/power/DisplayPowerRequest.java
@@ -0,0 +1,135 @@
+/*
+ * 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.server.power;
+
+import android.os.PowerManager;
+
+/**
+ * Describes the requested power state of the display.
+ *
+ * This object is intended to describe the general characteristics of the
+ * power state, such as whether the screen should be on or off and the current
+ * brightness controls leaving the {@link DisplayPowerController} to manage the
+ * details of how the transitions between states should occur.  The goal is for
+ * the {@link PowerManagerService} to focus on the global power state and not
+ * have to micro-manage screen off animations, auto-brightness and other effects.
+ */
+final class DisplayPowerRequest {
+    public static final int SCREEN_STATE_OFF = 0;
+    public static final int SCREEN_STATE_DOZE = 1;
+    public static final int SCREEN_STATE_DIM = 2;
+    public static final int SCREEN_STATE_BRIGHT = 3;
+
+    // The requested minimum screen power state: off, doze, dim or bright.
+    public int screenState;
+
+    // If true, the proximity sensor overrides the screen state when an object is
+    // nearby, turning it off temporarily until the object is moved away.
+    public boolean useProximitySensor;
+
+    // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
+    // The display power controller may choose to clamp the brightness.
+    // When auto-brightness is enabled, this field should specify a nominal default
+    // value to use while waiting for the light sensor to report enough data.
+    public int screenBrightness;
+
+    // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
+    public float screenAutoBrightnessAdjustment;
+
+    // If true, enables automatic brightness control.
+    public boolean useAutoBrightness;
+
+    // If true, prevents the screen from completely turning on if it is currently off.
+    // The display does not enter a "ready" state if this flag is true and screen on is
+    // blocked.  The window manager policy blocks screen on while it prepares the keyguard to
+    // prevent the user from seeing intermediate updates.
+    //
+    // Technically, we may not block the screen itself from turning on (because that introduces
+    // extra unnecessary latency) but we do prevent content on screen from becoming
+    // visible to the user.
+    public boolean blockScreenOn;
+
+    public DisplayPowerRequest() {
+        screenState = SCREEN_STATE_BRIGHT;
+        useProximitySensor = false;
+        screenBrightness = PowerManager.BRIGHTNESS_ON;
+        screenAutoBrightnessAdjustment = 0.0f;
+        useAutoBrightness = false;
+        blockScreenOn = false;
+    }
+
+    public DisplayPowerRequest(DisplayPowerRequest other) {
+        copyFrom(other);
+    }
+
+    // Returns true if we want the screen on in any mode, including doze.
+    public boolean wantScreenOnAny() {
+        return screenState != SCREEN_STATE_OFF;
+    }
+
+    // Returns true if we want the screen on in a normal mode, excluding doze.
+    // This is usually what we want to tell the rest of the system.  For compatibility
+    // reasons, we pretend the screen is off when dozing.
+    public boolean wantScreenOnNormal() {
+        return screenState == SCREEN_STATE_DIM || screenState == SCREEN_STATE_BRIGHT;
+    }
+
+    public boolean wantLightSensorEnabled() {
+        // Specifically, we don't want the light sensor while dozing.
+        return useAutoBrightness && wantScreenOnNormal();
+    }
+
+    public void copyFrom(DisplayPowerRequest other) {
+        screenState = other.screenState;
+        useProximitySensor = other.useProximitySensor;
+        screenBrightness = other.screenBrightness;
+        screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
+        useAutoBrightness = other.useAutoBrightness;
+        blockScreenOn = other.blockScreenOn;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return o instanceof DisplayPowerRequest
+                && equals((DisplayPowerRequest)o);
+    }
+
+    public boolean equals(DisplayPowerRequest other) {
+        return other != null
+                && screenState == other.screenState
+                && useProximitySensor == other.useProximitySensor
+                && screenBrightness == other.screenBrightness
+                && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
+                && useAutoBrightness == other.useAutoBrightness
+                && blockScreenOn == other.blockScreenOn;
+    }
+
+    @Override
+    public int hashCode() {
+        return 0; // don't care
+    }
+
+    @Override
+    public String toString() {
+        return "screenState=" + screenState
+                + ", useProximitySensor=" + useProximitySensor
+                + ", screenBrightness=" + screenBrightness
+                + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
+                + ", useAutoBrightness=" + useAutoBrightness
+                + ", blockScreenOn=" + blockScreenOn;
+    }
+}
diff --git a/services/core/java/com/android/server/power/DisplayPowerState.java b/services/core/java/com/android/server/power/DisplayPowerState.java
new file mode 100644
index 0000000..8e331ad
--- /dev/null
+++ b/services/core/java/com/android/server/power/DisplayPowerState.java
@@ -0,0 +1,421 @@
+/*
+ * 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.server.power;
+
+import com.android.server.lights.Light;
+
+import android.os.AsyncTask;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.PowerManager;
+import android.util.FloatProperty;
+import android.util.IntProperty;
+import android.util.Slog;
+import android.view.Choreographer;
+
+import java.io.PrintWriter;
+
+/**
+ * Controls the display power state.
+ * <p>
+ * This component is similar in nature to a {@link View} except that it describes
+ * the properties of a display.  When properties are changed, the component
+ * invalidates itself and posts a callback to apply the changes in a consistent order.
+ * This mechanism enables multiple properties of the display power state to be animated
+ * together smoothly by the animation framework.  Some of the work to blank or unblank
+ * the display is done on a separate thread to avoid blocking the looper.
+ * </p><p>
+ * This component must only be created or accessed by the {@link Looper} thread
+ * that belongs to the {@link DisplayPowerController}.
+ * </p><p>
+ * We don't need to worry about holding a suspend blocker here because the
+ * {@link PowerManagerService} does that for us whenever there is a change
+ * in progress.
+ * </p>
+ */
+final class DisplayPowerState {
+    private static final String TAG = "DisplayPowerState";
+
+    private static boolean DEBUG = false;
+
+    private final Handler mHandler;
+    private final Choreographer mChoreographer;
+    private final ElectronBeam mElectronBeam;
+    private final DisplayBlanker mDisplayBlanker;
+    private final Light mBacklight;
+    private final PhotonicModulator mPhotonicModulator;
+
+    private boolean mScreenOn;
+    private int mScreenBrightness;
+    private boolean mScreenReady;
+    private boolean mScreenUpdatePending;
+
+    private boolean mElectronBeamPrepared;
+    private float mElectronBeamLevel;
+    private boolean mElectronBeamReady;
+    private boolean mElectronBeamDrawPending;
+
+    private Runnable mCleanListener;
+
+    public DisplayPowerState(ElectronBeam electronBean,
+            DisplayBlanker displayBlanker, Light backlight) {
+        mHandler = new Handler(true /*async*/);
+        mChoreographer = Choreographer.getInstance();
+        mElectronBeam = electronBean;
+        mDisplayBlanker = displayBlanker;
+        mBacklight = backlight;
+        mPhotonicModulator = new PhotonicModulator();
+
+        // At boot time, we know that the screen is on and the electron beam
+        // animation is not playing.  We don't know the screen's brightness though,
+        // so prepare to set it to a known state when the state is next applied.
+        // Although we set the brightness to full on here, the display power controller
+        // will reset the brightness to a new level immediately before the changes
+        // actually have a chance to be applied.
+        mScreenOn = true;
+        mScreenBrightness = PowerManager.BRIGHTNESS_ON;
+        scheduleScreenUpdate();
+
+        mElectronBeamPrepared = false;
+        mElectronBeamLevel = 1.0f;
+        mElectronBeamReady = true;
+    }
+
+    public static final FloatProperty<DisplayPowerState> ELECTRON_BEAM_LEVEL =
+            new FloatProperty<DisplayPowerState>("electronBeamLevel") {
+        @Override
+        public void setValue(DisplayPowerState object, float value) {
+            object.setElectronBeamLevel(value);
+        }
+
+        @Override
+        public Float get(DisplayPowerState object) {
+            return object.getElectronBeamLevel();
+        }
+    };
+
+    public static final IntProperty<DisplayPowerState> SCREEN_BRIGHTNESS =
+            new IntProperty<DisplayPowerState>("screenBrightness") {
+        @Override
+        public void setValue(DisplayPowerState object, int value) {
+            object.setScreenBrightness(value);
+        }
+
+        @Override
+        public Integer get(DisplayPowerState object) {
+            return object.getScreenBrightness();
+        }
+    };
+
+    /**
+     * Sets whether the screen is on or off.
+     */
+    public void setScreenOn(boolean on) {
+        if (mScreenOn != on) {
+            if (DEBUG) {
+                Slog.d(TAG, "setScreenOn: on=" + on);
+            }
+
+            mScreenOn = on;
+            mScreenReady = false;
+            scheduleScreenUpdate();
+        }
+    }
+
+    /**
+     * Returns true if the screen is on.
+     */
+    public boolean isScreenOn() {
+        return mScreenOn;
+    }
+
+    /**
+     * Sets the display brightness.
+     *
+     * @param brightness The brightness, ranges from 0 (minimum / off) to 255 (brightest).
+     */
+    public void setScreenBrightness(int brightness) {
+        if (mScreenBrightness != brightness) {
+            if (DEBUG) {
+                Slog.d(TAG, "setScreenBrightness: brightness=" + brightness);
+            }
+
+            mScreenBrightness = brightness;
+            if (mScreenOn) {
+                mScreenReady = false;
+                scheduleScreenUpdate();
+            }
+        }
+    }
+
+    /**
+     * Gets the screen brightness.
+     */
+    public int getScreenBrightness() {
+        return mScreenBrightness;
+    }
+
+    /**
+     * Prepares the electron beam to turn on or off.
+     * This method should be called before starting an animation because it
+     * can take a fair amount of time to prepare the electron beam surface.
+     *
+     * @param mode The electron beam animation mode to prepare.
+     * @return True if the electron beam was prepared.
+     */
+    public boolean prepareElectronBeam(int mode) {
+        if (!mElectronBeam.prepare(mode)) {
+            mElectronBeamPrepared = false;
+            mElectronBeamReady = true;
+            return false;
+        }
+
+        mElectronBeamPrepared = true;
+        mElectronBeamReady = false;
+        scheduleElectronBeamDraw();
+        return true;
+    }
+
+    /**
+     * Dismisses the electron beam surface.
+     */
+    public void dismissElectronBeam() {
+        mElectronBeam.dismiss();
+        mElectronBeamPrepared = false;
+        mElectronBeamReady = true;
+    }
+
+    /**
+     * Sets the level of the electron beam steering current.
+     *
+     * The display is blanked when the level is 0.0.  In normal use, the electron
+     * beam should have a value of 1.0.  The electron beam is unstable in between
+     * these states and the picture quality may be compromised.  For best effect,
+     * the electron beam should be warmed up or cooled off slowly.
+     *
+     * Warning: Electron beam emits harmful radiation.  Avoid direct exposure to
+     * skin or eyes.
+     *
+     * @param level The level, ranges from 0.0 (full off) to 1.0 (full on).
+     */
+    public void setElectronBeamLevel(float level) {
+        if (mElectronBeamLevel != level) {
+            if (DEBUG) {
+                Slog.d(TAG, "setElectronBeamLevel: level=" + level);
+            }
+
+            mElectronBeamLevel = level;
+            if (mScreenOn) {
+                mScreenReady = false;
+                scheduleScreenUpdate(); // update backlight brightness
+            }
+            if (mElectronBeamPrepared) {
+                mElectronBeamReady = false;
+                scheduleElectronBeamDraw();
+            }
+        }
+    }
+
+    /**
+     * Gets the level of the electron beam steering current.
+     */
+    public float getElectronBeamLevel() {
+        return mElectronBeamLevel;
+    }
+
+    /**
+     * Returns true if no properties have been invalidated.
+     * Otherwise, returns false and promises to invoke the specified listener
+     * when the properties have all been applied.
+     * The listener always overrides any previously set listener.
+     */
+    public boolean waitUntilClean(Runnable listener) {
+        if (!mScreenReady || !mElectronBeamReady) {
+            mCleanListener = listener;
+            return false;
+        } else {
+            mCleanListener = null;
+            return true;
+        }
+    }
+
+    public void dump(PrintWriter pw) {
+        pw.println();
+        pw.println("Display Power State:");
+        pw.println("  mScreenOn=" + mScreenOn);
+        pw.println("  mScreenBrightness=" + mScreenBrightness);
+        pw.println("  mScreenReady=" + mScreenReady);
+        pw.println("  mScreenUpdatePending=" + mScreenUpdatePending);
+        pw.println("  mElectronBeamPrepared=" + mElectronBeamPrepared);
+        pw.println("  mElectronBeamLevel=" + mElectronBeamLevel);
+        pw.println("  mElectronBeamReady=" + mElectronBeamReady);
+        pw.println("  mElectronBeamDrawPending=" + mElectronBeamDrawPending);
+
+        mPhotonicModulator.dump(pw);
+        mElectronBeam.dump(pw);
+    }
+
+    private void scheduleScreenUpdate() {
+        if (!mScreenUpdatePending) {
+            mScreenUpdatePending = true;
+            postScreenUpdateThreadSafe();
+        }
+    }
+
+    private void postScreenUpdateThreadSafe() {
+        mHandler.removeCallbacks(mScreenUpdateRunnable);
+        mHandler.post(mScreenUpdateRunnable);
+    }
+
+    private void scheduleElectronBeamDraw() {
+        if (!mElectronBeamDrawPending) {
+            mElectronBeamDrawPending = true;
+            mChoreographer.postCallback(Choreographer.CALLBACK_TRAVERSAL,
+                    mElectronBeamDrawRunnable, null);
+        }
+    }
+
+    private void invokeCleanListenerIfNeeded() {
+        final Runnable listener = mCleanListener;
+        if (listener != null && mScreenReady && mElectronBeamReady) {
+            mCleanListener = null;
+            listener.run();
+        }
+    }
+
+    private final Runnable mScreenUpdateRunnable = new Runnable() {
+        @Override
+        public void run() {
+            mScreenUpdatePending = false;
+
+            int brightness = mScreenOn && mElectronBeamLevel > 0f ? mScreenBrightness : 0;
+            if (mPhotonicModulator.setState(mScreenOn, brightness)) {
+                if (DEBUG) {
+                    Slog.d(TAG, "Screen ready");
+                }
+                mScreenReady = true;
+                invokeCleanListenerIfNeeded();
+            } else {
+                if (DEBUG) {
+                    Slog.d(TAG, "Screen not ready");
+                }
+            }
+        }
+    };
+
+    private final Runnable mElectronBeamDrawRunnable = new Runnable() {
+        @Override
+        public void run() {
+            mElectronBeamDrawPending = false;
+
+            if (mElectronBeamPrepared) {
+                mElectronBeam.draw(mElectronBeamLevel);
+            }
+
+            mElectronBeamReady = true;
+            invokeCleanListenerIfNeeded();
+        }
+    };
+
+    /**
+     * Updates the state of the screen and backlight asynchronously on a separate thread.
+     */
+    private final class PhotonicModulator {
+        private static final boolean INITIAL_SCREEN_ON = false; // unknown, assume off
+        private static final int INITIAL_BACKLIGHT = -1; // unknown
+
+        private final Object mLock = new Object();
+
+        private boolean mPendingOn = INITIAL_SCREEN_ON;
+        private int mPendingBacklight = INITIAL_BACKLIGHT;
+        private boolean mActualOn = INITIAL_SCREEN_ON;
+        private int mActualBacklight = INITIAL_BACKLIGHT;
+        private boolean mChangeInProgress;
+
+        public boolean setState(boolean on, int backlight) {
+            synchronized (mLock) {
+                if (on != mPendingOn || backlight != mPendingBacklight) {
+                    if (DEBUG) {
+                        Slog.d(TAG, "Requesting new screen state: on=" + on
+                                + ", backlight=" + backlight);
+                    }
+
+                    mPendingOn = on;
+                    mPendingBacklight = backlight;
+
+                    if (!mChangeInProgress) {
+                        mChangeInProgress = true;
+                        AsyncTask.THREAD_POOL_EXECUTOR.execute(mTask);
+                    }
+                }
+                return !mChangeInProgress;
+            }
+        }
+
+        public void dump(PrintWriter pw) {
+            pw.println();
+            pw.println("Photonic Modulator State:");
+            pw.println("  mPendingOn=" + mPendingOn);
+            pw.println("  mPendingBacklight=" + mPendingBacklight);
+            pw.println("  mActualOn=" + mActualOn);
+            pw.println("  mActualBacklight=" + mActualBacklight);
+            pw.println("  mChangeInProgress=" + mChangeInProgress);
+        }
+
+        private final Runnable mTask = new Runnable() {
+            @Override
+            public void run() {
+                // Apply pending changes until done.
+                for (;;) {
+                    final boolean on;
+                    final boolean onChanged;
+                    final int backlight;
+                    final boolean backlightChanged;
+                    synchronized (mLock) {
+                        on = mPendingOn;
+                        onChanged = (on != mActualOn);
+                        backlight = mPendingBacklight;
+                        backlightChanged = (backlight != mActualBacklight);
+                        if (!onChanged && !backlightChanged) {
+                            mChangeInProgress = false;
+                            break;
+                        }
+                        mActualOn = on;
+                        mActualBacklight = backlight;
+                    }
+
+                    if (DEBUG) {
+                        Slog.d(TAG, "Updating screen state: on=" + on
+                                + ", backlight=" + backlight);
+                    }
+                    if (onChanged && on) {
+                        mDisplayBlanker.unblankAllDisplays();
+                    }
+                    if (backlightChanged) {
+                        mBacklight.setBrightness(backlight);
+                    }
+                    if (onChanged && !on) {
+                        mDisplayBlanker.blankAllDisplays();
+                    }
+                }
+
+                // Let the outer class know that all changes have been applied.
+                postScreenUpdateThreadSafe();
+            }
+        };
+    }
+}
diff --git a/services/core/java/com/android/server/power/ElectronBeam.java b/services/core/java/com/android/server/power/ElectronBeam.java
new file mode 100644
index 0000000..64921d7
--- /dev/null
+++ b/services/core/java/com/android/server/power/ElectronBeam.java
@@ -0,0 +1,736 @@
+/*
+ * 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.server.power;
+
+import java.io.PrintWriter;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import android.graphics.PixelFormat;
+import android.graphics.SurfaceTexture;
+import android.hardware.display.DisplayManagerInternal;
+import android.hardware.display.DisplayManagerInternal.DisplayTransactionListener;
+import android.opengl.EGL14;
+import android.opengl.EGLConfig;
+import android.opengl.EGLContext;
+import android.opengl.EGLDisplay;
+import android.opengl.EGLSurface;
+import android.opengl.GLES10;
+import android.opengl.GLES11Ext;
+import android.os.Looper;
+import android.util.FloatMath;
+import android.util.Slog;
+import android.view.Display;
+import android.view.DisplayInfo;
+import android.view.Surface.OutOfResourcesException;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.view.SurfaceSession;
+
+import com.android.server.LocalServices;
+
+/**
+ * Bzzzoooop!  *crackle*
+ * <p>
+ * Animates a screen transition from on to off or off to on by applying
+ * some GL transformations to a screenshot.
+ * </p><p>
+ * This component must only be created or accessed by the {@link Looper} thread
+ * that belongs to the {@link DisplayPowerController}.
+ * </p>
+ */
+final class ElectronBeam {
+    private static final String TAG = "ElectronBeam";
+
+    private static final boolean DEBUG = false;
+
+    // The layer for the electron beam surface.
+    // This is currently hardcoded to be one layer above the boot animation.
+    private static final int ELECTRON_BEAM_LAYER = 0x40000001;
+
+    // The relative proportion of the animation to spend performing
+    // the horizontal stretch effect.  The remainder is spent performing
+    // the vertical stretch effect.
+    private static final float HSTRETCH_DURATION = 0.5f;
+    private static final float VSTRETCH_DURATION = 1.0f - HSTRETCH_DURATION;
+
+    // The number of frames to draw when preparing the animation so that it will
+    // be ready to run smoothly.  We use 3 frames because we are triple-buffered.
+    // See code for details.
+    private static final int DEJANK_FRAMES = 3;
+
+    // Set to true when the animation context has been fully prepared.
+    private boolean mPrepared;
+    private int mMode;
+
+    private final DisplayManagerInternal mDisplayManagerInternal;
+    private int mDisplayLayerStack; // layer stack associated with primary display
+    private int mDisplayWidth;      // real width, not rotated
+    private int mDisplayHeight;     // real height, not rotated
+    private SurfaceSession mSurfaceSession;
+    private SurfaceControl mSurfaceControl;
+    private Surface mSurface;
+    private NaturalSurfaceLayout mSurfaceLayout;
+    private EGLDisplay mEglDisplay;
+    private EGLConfig mEglConfig;
+    private EGLContext mEglContext;
+    private EGLSurface mEglSurface;
+    private boolean mSurfaceVisible;
+    private float mSurfaceAlpha;
+
+    // Texture names.  We only use one texture, which contains the screenshot.
+    private final int[] mTexNames = new int[1];
+    private boolean mTexNamesGenerated;
+    private final float mTexMatrix[] = new float[16];
+
+    // Vertex and corresponding texture coordinates.
+    // We have 4 2D vertices, so 8 elements.  The vertices form a quad.
+    private final FloatBuffer mVertexBuffer = createNativeFloatBuffer(8);
+    private final FloatBuffer mTexCoordBuffer = createNativeFloatBuffer(8);
+
+    /**
+     * Animates an electron beam warming up.
+     */
+    public static final int MODE_WARM_UP = 0;
+
+    /**
+     * Animates an electron beam shutting off.
+     */
+    public static final int MODE_COOL_DOWN = 1;
+
+    /**
+     * Animates a simple dim layer to fade the contents of the screen in or out progressively.
+     */
+    public static final int MODE_FADE = 2;
+
+
+    public ElectronBeam() {
+        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
+    }
+
+    /**
+     * Warms up the electron beam in preparation for turning on or off.
+     * This method prepares a GL context, and captures a screen shot.
+     *
+     * @param mode The desired mode for the upcoming animation.
+     * @return True if the electron beam is ready, false if it is uncontrollable.
+     */
+    public boolean prepare(int mode) {
+        if (DEBUG) {
+            Slog.d(TAG, "prepare: mode=" + mode);
+        }
+
+        mMode = mode;
+
+        // Get the display size and layer stack.
+        // This is not expected to change while the electron beam surface is showing.
+        DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(Display.DEFAULT_DISPLAY);
+        mDisplayLayerStack = displayInfo.layerStack;
+        mDisplayWidth = displayInfo.getNaturalWidth();
+        mDisplayHeight = displayInfo.getNaturalHeight();
+
+        // Prepare the surface for drawing.
+        if (!tryPrepare()) {
+            dismiss();
+            return false;
+        }
+
+        // Done.
+        mPrepared = true;
+
+        // Dejanking optimization.
+        // Some GL drivers can introduce a lot of lag in the first few frames as they
+        // initialize their state and allocate graphics buffers for rendering.
+        // Work around this problem by rendering the first frame of the animation a few
+        // times.  The rest of the animation should run smoothly thereafter.
+        // The frames we draw here aren't visible because we are essentially just
+        // painting the screenshot as-is.
+        if (mode == MODE_COOL_DOWN) {
+            for (int i = 0; i < DEJANK_FRAMES; i++) {
+                draw(1.0f);
+            }
+        }
+        return true;
+    }
+
+    private boolean tryPrepare() {
+        if (createSurface()) {
+            if (mMode == MODE_FADE) {
+                return true;
+            }
+            return createEglContext()
+                    && createEglSurface()
+                    && captureScreenshotTextureAndSetViewport();
+        }
+        return false;
+    }
+
+    /**
+     * Dismisses the electron beam animation surface and cleans up.
+     *
+     * To prevent stray photons from leaking out after the electron beam has been
+     * turned off, it is a good idea to defer dismissing the animation until the
+     * electron beam has been turned back on fully.
+     */
+    public void dismiss() {
+        if (DEBUG) {
+            Slog.d(TAG, "dismiss");
+        }
+
+        destroyScreenshotTexture();
+        destroyEglSurface();
+        destroySurface();
+        mPrepared = false;
+    }
+
+    /**
+     * Draws an animation frame showing the electron beam activated at the
+     * specified level.
+     *
+     * @param level The electron beam level.
+     * @return True if successful.
+     */
+    public boolean draw(float level) {
+        if (DEBUG) {
+            Slog.d(TAG, "drawFrame: level=" + level);
+        }
+
+        if (!mPrepared) {
+            return false;
+        }
+
+        if (mMode == MODE_FADE) {
+            return showSurface(1.0f - level);
+        }
+
+        if (!attachEglContext()) {
+            return false;
+        }
+        try {
+            // Clear frame to solid black.
+            GLES10.glClearColor(0f, 0f, 0f, 1f);
+            GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT);
+
+            // Draw the frame.
+            if (level < HSTRETCH_DURATION) {
+                drawHStretch(1.0f - (level / HSTRETCH_DURATION));
+            } else {
+                drawVStretch(1.0f - ((level - HSTRETCH_DURATION) / VSTRETCH_DURATION));
+            }
+            if (checkGlErrors("drawFrame")) {
+                return false;
+            }
+
+            EGL14.eglSwapBuffers(mEglDisplay, mEglSurface);
+        } finally {
+            detachEglContext();
+        }
+        return showSurface(1.0f);
+    }
+
+    /**
+     * Draws a frame where the content of the electron beam is collapsing inwards upon
+     * itself vertically with red / green / blue channels dispersing and eventually
+     * merging down to a single horizontal line.
+     *
+     * @param stretch The stretch factor.  0.0 is no collapse, 1.0 is full collapse.
+     */
+    private void drawVStretch(float stretch) {
+        // compute interpolation scale factors for each color channel
+        final float ar = scurve(stretch, 7.5f);
+        final float ag = scurve(stretch, 8.0f);
+        final float ab = scurve(stretch, 8.5f);
+        if (DEBUG) {
+            Slog.d(TAG, "drawVStretch: stretch=" + stretch
+                    + ", ar=" + ar + ", ag=" + ag + ", ab=" + ab);
+        }
+
+        // set blending
+        GLES10.glBlendFunc(GLES10.GL_ONE, GLES10.GL_ONE);
+        GLES10.glEnable(GLES10.GL_BLEND);
+
+        // bind vertex buffer
+        GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
+        GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
+
+        // set-up texturing
+        GLES10.glDisable(GLES10.GL_TEXTURE_2D);
+        GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
+
+        // bind texture and set blending for drawing planes
+        GLES10.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexNames[0]);
+        GLES10.glTexEnvx(GLES10.GL_TEXTURE_ENV, GLES10.GL_TEXTURE_ENV_MODE,
+                mMode == MODE_WARM_UP ? GLES10.GL_MODULATE : GLES10.GL_REPLACE);
+        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);
+        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
+        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_CLAMP_TO_EDGE);
+        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
+                GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_CLAMP_TO_EDGE);
+        GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
+        GLES10.glTexCoordPointer(2, GLES10.GL_FLOAT, 0, mTexCoordBuffer);
+        GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
+
+        // draw the red plane
+        setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ar);
+        GLES10.glColorMask(true, false, false, true);
+        GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
+
+        // draw the green plane
+        setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag);
+        GLES10.glColorMask(false, true, false, true);
+        GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
+
+        // draw the blue plane
+        setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ab);
+        GLES10.glColorMask(false, false, true, true);
+        GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
+
+        // clean up after drawing planes
+        GLES10.glDisable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
+        GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
+        GLES10.glColorMask(true, true, true, true);
+
+        // draw the white highlight (we use the last vertices)
+        if (mMode == MODE_COOL_DOWN) {
+            GLES10.glColor4f(ag, ag, ag, 1.0f);
+            GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
+        }
+
+        // clean up
+        GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
+        GLES10.glDisable(GLES10.GL_BLEND);
+    }
+
+    /**
+     * Draws a frame where the electron beam has been stretched out into
+     * a thin white horizontal line that fades as it collapses inwards.
+     *
+     * @param stretch The stretch factor.  0.0 is maximum stretch / no fade,
+     * 1.0 is collapsed / maximum fade.
+     */
+    private void drawHStretch(float stretch) {
+        // compute interpolation scale factor
+        final float ag = scurve(stretch, 8.0f);
+        if (DEBUG) {
+            Slog.d(TAG, "drawHStretch: stretch=" + stretch + ", ag=" + ag);
+        }
+
+        if (stretch < 1.0f) {
+            // bind vertex buffer
+            GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
+            GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
+
+            // draw narrow fading white line
+            setHStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag);
+            GLES10.glColor4f(1.0f - ag*0.75f, 1.0f - ag*0.75f, 1.0f - ag*0.75f, 1.0f);
+            GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
+
+            // clean up
+            GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
+        }
+    }
+
+    private static void setVStretchQuad(FloatBuffer vtx, float dw, float dh, float a) {
+        final float w = dw + (dw * a);
+        final float h = dh - (dh * a);
+        final float x = (dw - w) * 0.5f;
+        final float y = (dh - h) * 0.5f;
+        setQuad(vtx, x, y, w, h);
+    }
+
+    private static void setHStretchQuad(FloatBuffer vtx, float dw, float dh, float a) {
+        final float w = 2 * dw * (1.0f - a);
+        final float h = 1.0f;
+        final float x = (dw - w) * 0.5f;
+        final float y = (dh - h) * 0.5f;
+        setQuad(vtx, x, y, w, h);
+    }
+
+    private static void setQuad(FloatBuffer vtx, float x, float y, float w, float h) {
+        if (DEBUG) {
+            Slog.d(TAG, "setQuad: x=" + x + ", y=" + y + ", w=" + w + ", h=" + h);
+        }
+        vtx.put(0, x);
+        vtx.put(1, y);
+        vtx.put(2, x);
+        vtx.put(3, y + h);
+        vtx.put(4, x + w);
+        vtx.put(5, y + h);
+        vtx.put(6, x + w);
+        vtx.put(7, y);
+    }
+
+    private boolean captureScreenshotTextureAndSetViewport() {
+        if (!attachEglContext()) {
+            return false;
+        }
+        try {
+            if (!mTexNamesGenerated) {
+                GLES10.glGenTextures(1, mTexNames, 0);
+                if (checkGlErrors("glGenTextures")) {
+                    return false;
+                }
+                mTexNamesGenerated = true;
+            }
+
+            final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
+            final Surface s = new Surface(st);
+            try {
+                SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(
+                        SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
+            } finally {
+                s.release();
+            }
+
+            st.updateTexImage();
+            st.getTransformMatrix(mTexMatrix);
+
+            // Set up texture coordinates for a quad.
+            // We might need to change this if the texture ends up being
+            // a different size from the display for some reason.
+            mTexCoordBuffer.put(0, 0f); mTexCoordBuffer.put(1, 0f);
+            mTexCoordBuffer.put(2, 0f); mTexCoordBuffer.put(3, 1f);
+            mTexCoordBuffer.put(4, 1f); mTexCoordBuffer.put(5, 1f);
+            mTexCoordBuffer.put(6, 1f); mTexCoordBuffer.put(7, 0f);
+
+            // Set up our viewport.
+            GLES10.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
+            GLES10.glMatrixMode(GLES10.GL_PROJECTION);
+            GLES10.glLoadIdentity();
+            GLES10.glOrthof(0, mDisplayWidth, 0, mDisplayHeight, 0, 1);
+            GLES10.glMatrixMode(GLES10.GL_MODELVIEW);
+            GLES10.glLoadIdentity();
+            GLES10.glMatrixMode(GLES10.GL_TEXTURE);
+            GLES10.glLoadIdentity();
+            GLES10.glLoadMatrixf(mTexMatrix, 0);
+        } finally {
+            detachEglContext();
+        }
+        return true;
+    }
+
+    private void destroyScreenshotTexture() {
+        if (mTexNamesGenerated) {
+            mTexNamesGenerated = false;
+            if (attachEglContext()) {
+                try {
+                    GLES10.glDeleteTextures(1, mTexNames, 0);
+                    checkGlErrors("glDeleteTextures");
+                } finally {
+                    detachEglContext();
+                }
+            }
+        }
+    }
+
+    private boolean createEglContext() {
+        if (mEglDisplay == null) {
+            mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
+            if (mEglDisplay == EGL14.EGL_NO_DISPLAY) {
+                logEglError("eglGetDisplay");
+                return false;
+            }
+
+            int[] version = new int[2];
+            if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) {
+                mEglDisplay = null;
+                logEglError("eglInitialize");
+                return false;
+            }
+        }
+
+        if (mEglConfig == null) {
+            int[] eglConfigAttribList = new int[] {
+                    EGL14.EGL_RED_SIZE, 8,
+                    EGL14.EGL_GREEN_SIZE, 8,
+                    EGL14.EGL_BLUE_SIZE, 8,
+                    EGL14.EGL_ALPHA_SIZE, 8,
+                    EGL14.EGL_NONE
+            };
+            int[] numEglConfigs = new int[1];
+            EGLConfig[] eglConfigs = new EGLConfig[1];
+            if (!EGL14.eglChooseConfig(mEglDisplay, eglConfigAttribList, 0,
+                    eglConfigs, 0, eglConfigs.length, numEglConfigs, 0)) {
+                logEglError("eglChooseConfig");
+                return false;
+            }
+            mEglConfig = eglConfigs[0];
+        }
+
+        if (mEglContext == null) {
+            int[] eglContextAttribList = new int[] {
+                    EGL14.EGL_NONE
+            };
+            mEglContext = EGL14.eglCreateContext(mEglDisplay, mEglConfig,
+                    EGL14.EGL_NO_CONTEXT, eglContextAttribList, 0);
+            if (mEglContext == null) {
+                logEglError("eglCreateContext");
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /* not used because it is too expensive to create / destroy contexts all of the time
+    private void destroyEglContext() {
+        if (mEglContext != null) {
+            if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) {
+                logEglError("eglDestroyContext");
+            }
+            mEglContext = null;
+        }
+    }*/
+
+    private boolean createSurface() {
+        if (mSurfaceSession == null) {
+            mSurfaceSession = new SurfaceSession();
+        }
+
+        SurfaceControl.openTransaction();
+        try {
+            if (mSurfaceControl == null) {
+                try {
+                    int flags;
+                    if (mMode == MODE_FADE) {
+                        flags = SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN;
+                    } else {
+                        flags = SurfaceControl.OPAQUE | SurfaceControl.HIDDEN;
+                    }
+                    mSurfaceControl = new SurfaceControl(mSurfaceSession,
+                            "ElectronBeam", mDisplayWidth, mDisplayHeight,
+                            PixelFormat.OPAQUE, flags);
+                } catch (OutOfResourcesException ex) {
+                    Slog.e(TAG, "Unable to create surface.", ex);
+                    return false;
+                }
+            }
+
+            mSurfaceControl.setLayerStack(mDisplayLayerStack);
+            mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight);
+            mSurface = new Surface();
+            mSurface.copyFrom(mSurfaceControl);
+
+            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal, mSurfaceControl);
+            mSurfaceLayout.onDisplayTransaction();
+        } finally {
+            SurfaceControl.closeTransaction();
+        }
+        return true;
+    }
+
+    private boolean createEglSurface() {
+        if (mEglSurface == null) {
+            int[] eglSurfaceAttribList = new int[] {
+                    EGL14.EGL_NONE
+            };
+            // turn our SurfaceControl into a Surface
+            mEglSurface = EGL14.eglCreateWindowSurface(mEglDisplay, mEglConfig, mSurface,
+                    eglSurfaceAttribList, 0);
+            if (mEglSurface == null) {
+                logEglError("eglCreateWindowSurface");
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private void destroyEglSurface() {
+        if (mEglSurface != null) {
+            if (!EGL14.eglDestroySurface(mEglDisplay, mEglSurface)) {
+                logEglError("eglDestroySurface");
+            }
+            mEglSurface = null;
+        }
+    }
+
+    private void destroySurface() {
+        if (mSurfaceControl != null) {
+            mSurfaceLayout.dispose();
+            mSurfaceLayout = null;
+            SurfaceControl.openTransaction();
+            try {
+                mSurfaceControl.destroy();
+                mSurface.release();
+            } finally {
+                SurfaceControl.closeTransaction();
+            }
+            mSurfaceControl = null;
+            mSurfaceVisible = false;
+            mSurfaceAlpha = 0f;
+        }
+    }
+
+    private boolean showSurface(float alpha) {
+        if (!mSurfaceVisible || mSurfaceAlpha != alpha) {
+            SurfaceControl.openTransaction();
+            try {
+                mSurfaceControl.setLayer(ELECTRON_BEAM_LAYER);
+                mSurfaceControl.setAlpha(alpha);
+                mSurfaceControl.show();
+            } finally {
+                SurfaceControl.closeTransaction();
+            }
+            mSurfaceVisible = true;
+            mSurfaceAlpha = alpha;
+        }
+        return true;
+    }
+
+    private boolean attachEglContext() {
+        if (mEglSurface == null) {
+            return false;
+        }
+        if (!EGL14.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
+            logEglError("eglMakeCurrent");
+            return false;
+        }
+        return true;
+    }
+
+    private void detachEglContext() {
+        if (mEglDisplay != null) {
+            EGL14.eglMakeCurrent(mEglDisplay,
+                    EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
+        }
+    }
+
+    /**
+     * Interpolates a value in the range 0 .. 1 along a sigmoid curve
+     * yielding a result in the range 0 .. 1 scaled such that:
+     * scurve(0) == 0, scurve(0.5) == 0.5, scurve(1) == 1.
+     */
+    private static float scurve(float value, float s) {
+        // A basic sigmoid has the form y = 1.0f / FloatMap.exp(-x * s).
+        // Here we take the input datum and shift it by 0.5 so that the
+        // domain spans the range -0.5 .. 0.5 instead of 0 .. 1.
+        final float x = value - 0.5f;
+
+        // Next apply the sigmoid function to the scaled value
+        // which produces a value in the range 0 .. 1 so we subtract
+        // 0.5 to get a value in the range -0.5 .. 0.5 instead.
+        final float y = sigmoid(x, s) - 0.5f;
+
+        // To obtain the desired boundary conditions we need to scale
+        // the result so that it fills a range of -1 .. 1.
+        final float v = sigmoid(0.5f, s) - 0.5f;
+
+        // And finally remap the value back to a range of 0 .. 1.
+        return y / v * 0.5f + 0.5f;
+    }
+
+    private static float sigmoid(float x, float s) {
+        return 1.0f / (1.0f + FloatMath.exp(-x * s));
+    }
+
+    private static FloatBuffer createNativeFloatBuffer(int size) {
+        ByteBuffer bb = ByteBuffer.allocateDirect(size * 4);
+        bb.order(ByteOrder.nativeOrder());
+        return bb.asFloatBuffer();
+    }
+
+    private static void logEglError(String func) {
+        Slog.e(TAG, func + " failed: error " + EGL14.eglGetError(), new Throwable());
+    }
+
+    private static boolean checkGlErrors(String func) {
+        return checkGlErrors(func, true);
+    }
+
+    private static boolean checkGlErrors(String func, boolean log) {
+        boolean hadError = false;
+        int error;
+        while ((error = GLES10.glGetError()) != GLES10.GL_NO_ERROR) {
+            if (log) {
+                Slog.e(TAG, func + " failed: error " + error, new Throwable());
+            }
+            hadError = true;
+        }
+        return hadError;
+    }
+
+    public void dump(PrintWriter pw) {
+        pw.println();
+        pw.println("Electron Beam State:");
+        pw.println("  mPrepared=" + mPrepared);
+        pw.println("  mMode=" + mMode);
+        pw.println("  mDisplayLayerStack=" + mDisplayLayerStack);
+        pw.println("  mDisplayWidth=" + mDisplayWidth);
+        pw.println("  mDisplayHeight=" + mDisplayHeight);
+        pw.println("  mSurfaceVisible=" + mSurfaceVisible);
+        pw.println("  mSurfaceAlpha=" + mSurfaceAlpha);
+    }
+
+    /**
+     * Keeps a surface aligned with the natural orientation of the device.
+     * Updates the position and transformation of the matrix whenever the display
+     * is rotated.  This is a little tricky because the display transaction
+     * callback can be invoked on any thread, not necessarily the thread that
+     * owns the electron beam.
+     */
+    private static final class NaturalSurfaceLayout implements DisplayTransactionListener {
+        private final DisplayManagerInternal mDisplayManagerInternal;
+        private SurfaceControl mSurfaceControl;
+
+        public NaturalSurfaceLayout(DisplayManagerInternal displayManagerInternal,
+                SurfaceControl surfaceControl) {
+            mDisplayManagerInternal = displayManagerInternal;
+            mSurfaceControl = surfaceControl;
+            mDisplayManagerInternal.registerDisplayTransactionListener(this);
+        }
+
+        public void dispose() {
+            synchronized (this) {
+                mSurfaceControl = null;
+            }
+            mDisplayManagerInternal.unregisterDisplayTransactionListener(this);
+        }
+
+        @Override
+        public void onDisplayTransaction() {
+            synchronized (this) {
+                if (mSurfaceControl == null) {
+                    return;
+                }
+
+                DisplayInfo displayInfo =
+                        mDisplayManagerInternal.getDisplayInfo(Display.DEFAULT_DISPLAY);
+                switch (displayInfo.rotation) {
+                    case Surface.ROTATION_0:
+                        mSurfaceControl.setPosition(0, 0);
+                        mSurfaceControl.setMatrix(1, 0, 0, 1);
+                        break;
+                    case Surface.ROTATION_90:
+                        mSurfaceControl.setPosition(0, displayInfo.logicalHeight);
+                        mSurfaceControl.setMatrix(0, -1, 1, 0);
+                        break;
+                    case Surface.ROTATION_180:
+                        mSurfaceControl.setPosition(displayInfo.logicalWidth, displayInfo.logicalHeight);
+                        mSurfaceControl.setMatrix(-1, 0, 0, -1);
+                        break;
+                    case Surface.ROTATION_270:
+                        mSurfaceControl.setPosition(displayInfo.logicalWidth, 0);
+                        mSurfaceControl.setMatrix(0, 1, -1, 0);
+                        break;
+                }
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
similarity index 100%
rename from services/java/com/android/server/power/Notifier.java
rename to services/core/java/com/android/server/power/Notifier.java
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
new file mode 100644
index 0000000..c251af1
--- /dev/null
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -0,0 +1,2948 @@
+/*
+ * Copyright (C) 2007 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.power;
+
+import com.android.internal.app.IAppOpsService;
+import com.android.internal.app.IBatteryStats;
+import com.android.server.BatteryService;
+import com.android.server.EventLogTags;
+import com.android.server.LocalServices;
+import com.android.server.ServiceThread;
+import com.android.server.lights.Light;
+import com.android.server.lights.LightsManager;
+import com.android.server.twilight.TwilightManager;
+import com.android.server.Watchdog;
+
+import android.Manifest;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.hardware.SensorManager;
+import android.hardware.SystemSensorManager;
+import android.hardware.display.DisplayManagerInternal;
+import android.net.Uri;
+import android.os.BatteryManager;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IPowerManager;
+import android.os.Looper;
+import android.os.Message;
+import android.os.PowerManager;
+import android.os.PowerManagerInternal;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.SystemService;
+import android.os.UserHandle;
+import android.os.WorkSource;
+import android.provider.Settings;
+import android.service.dreams.DreamManagerInternal;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.Slog;
+import android.util.TimeUtils;
+import android.view.WindowManagerPolicy;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+import libcore.util.Objects;
+
+/**
+ * The power manager service is responsible for coordinating power management
+ * functions on the device.
+ */
+public final class PowerManagerService extends com.android.server.SystemService
+        implements Watchdog.Monitor {
+    private static final String TAG = "PowerManagerService";
+
+    private static final boolean DEBUG = false;
+    private static final boolean DEBUG_SPEW = DEBUG && true;
+
+    // Message: Sent when a user activity timeout occurs to update the power state.
+    private static final int MSG_USER_ACTIVITY_TIMEOUT = 1;
+    // Message: Sent when the device enters or exits a dreaming or dozing state.
+    private static final int MSG_SANDMAN = 2;
+    // Message: Sent when the screen on blocker is released.
+    private static final int MSG_SCREEN_ON_BLOCKER_RELEASED = 3;
+    // Message: Sent to poll whether the boot animation has terminated.
+    private static final int MSG_CHECK_IF_BOOT_ANIMATION_FINISHED = 4;
+
+    // Dirty bit: mWakeLocks changed
+    private static final int DIRTY_WAKE_LOCKS = 1 << 0;
+    // Dirty bit: mWakefulness changed
+    private static final int DIRTY_WAKEFULNESS = 1 << 1;
+    // Dirty bit: user activity was poked or may have timed out
+    private static final int DIRTY_USER_ACTIVITY = 1 << 2;
+    // Dirty bit: actual display power state was updated asynchronously
+    private static final int DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED = 1 << 3;
+    // Dirty bit: mBootCompleted changed
+    private static final int DIRTY_BOOT_COMPLETED = 1 << 4;
+    // Dirty bit: settings changed
+    private static final int DIRTY_SETTINGS = 1 << 5;
+    // Dirty bit: mIsPowered changed
+    private static final int DIRTY_IS_POWERED = 1 << 6;
+    // Dirty bit: mStayOn changed
+    private static final int DIRTY_STAY_ON = 1 << 7;
+    // Dirty bit: battery state changed
+    private static final int DIRTY_BATTERY_STATE = 1 << 8;
+    // Dirty bit: proximity state changed
+    private static final int DIRTY_PROXIMITY_POSITIVE = 1 << 9;
+    // Dirty bit: screen on blocker state became held or unheld
+    private static final int DIRTY_SCREEN_ON_BLOCKER_RELEASED = 1 << 10;
+    // Dirty bit: dock state changed
+    private static final int DIRTY_DOCK_STATE = 1 << 11;
+
+    // Wakefulness: The device is asleep and can only be awoken by a call to wakeUp().
+    // The screen should be off or in the process of being turned off by the display controller.
+    // The device typically passes through the dozing state first.
+    private static final int WAKEFULNESS_ASLEEP = 0;
+    // Wakefulness: The device is fully awake.  It can be put to sleep by a call to goToSleep().
+    // When the user activity timeout expires, the device may start dreaming or go to sleep.
+    private static final int WAKEFULNESS_AWAKE = 1;
+    // Wakefulness: The device is dreaming.  It can be awoken by a call to wakeUp(),
+    // which ends the dream.  The device goes to sleep when goToSleep() is called, when
+    // the dream ends or when unplugged.
+    // User activity may brighten the screen but does not end the dream.
+    private static final int WAKEFULNESS_DREAMING = 2;
+    // Wakefulness: The device is dozing.  It is almost asleep but is allowing a special
+    // low-power "doze" dream to run which keeps the display on but lets the application
+    // processor be suspended.  It can be awoken by a call to wakeUp() which ends the dream.
+    // The device fully goes to sleep if the dream cannot be started or ends on its own.
+    private static final int WAKEFULNESS_DOZING = 3;
+
+    // Summarizes the state of all active wakelocks.
+    private static final int WAKE_LOCK_CPU = 1 << 0;
+    private static final int WAKE_LOCK_SCREEN_BRIGHT = 1 << 1;
+    private static final int WAKE_LOCK_SCREEN_DIM = 1 << 2;
+    private static final int WAKE_LOCK_BUTTON_BRIGHT = 1 << 3;
+    private static final int WAKE_LOCK_PROXIMITY_SCREEN_OFF = 1 << 4;
+    private static final int WAKE_LOCK_STAY_AWAKE = 1 << 5; // only set if already awake
+    private static final int WAKE_LOCK_DOZE = 1 << 6;
+
+    // Summarizes the user activity state.
+    private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0;
+    private static final int USER_ACTIVITY_SCREEN_DIM = 1 << 1;
+
+    // Default and minimum screen off timeout in milliseconds.
+    private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000;
+    private static final int MINIMUM_SCREEN_OFF_TIMEOUT = 10 * 1000;
+
+    // The screen dim duration, in milliseconds.
+    // This is subtracted from the end of the screen off timeout so the
+    // minimum screen off timeout should be longer than this.
+    private static final int SCREEN_DIM_DURATION = 7 * 1000;
+
+    // The maximum screen dim time expressed as a ratio relative to the screen
+    // off timeout.  If the screen off timeout is very short then we want the
+    // dim timeout to also be quite short so that most of the time is spent on.
+    // Otherwise the user won't get much screen on time before dimming occurs.
+    private static final float MAXIMUM_SCREEN_DIM_RATIO = 0.2f;
+
+    // The name of the boot animation service in init.rc.
+    private static final String BOOT_ANIMATION_SERVICE = "bootanim";
+
+    // Poll interval in milliseconds for watching boot animation finished.
+    private static final int BOOT_ANIMATION_POLL_INTERVAL = 200;
+
+    private final Context mContext;
+    private LightsManager mLightsManager;
+    private BatteryService mBatteryService;
+    private DisplayManagerInternal mDisplayManagerInternal;
+    private IBatteryStats mBatteryStats;
+    private IAppOpsService mAppOps;
+    private ServiceThread mHandlerThread;
+    private PowerManagerHandler mHandler;
+    private WindowManagerPolicy mPolicy;
+    private Notifier mNotifier;
+    private DisplayPowerController mDisplayPowerController;
+    private WirelessChargerDetector mWirelessChargerDetector;
+    private SettingsObserver mSettingsObserver;
+    private DreamManagerInternal mDreamManager;
+    private Light mAttentionLight;
+
+    private final Object mLock = new Object();
+
+    // A bitfield that indicates what parts of the power state have
+    // changed and need to be recalculated.
+    private int mDirty;
+
+    // Indicates whether the device is awake or asleep or somewhere in between.
+    // This is distinct from the screen power state, which is managed separately.
+    private int mWakefulness;
+
+    // True if the sandman has just been summoned for the first time since entering the
+    // dreaming or dozing state.  Indicates whether a new dream should begin.
+    private boolean mSandmanSummoned;
+
+    // True if MSG_SANDMAN has been scheduled.
+    private boolean mSandmanScheduled;
+
+    // Table of all suspend blockers.
+    // There should only be a few of these.
+    private final ArrayList<SuspendBlocker> mSuspendBlockers = new ArrayList<SuspendBlocker>();
+
+    // Table of all wake locks acquired by applications.
+    private final ArrayList<WakeLock> mWakeLocks = new ArrayList<WakeLock>();
+
+    // A bitfield that summarizes the state of all active wakelocks.
+    private int mWakeLockSummary;
+
+    // If true, instructs the display controller to wait for the proximity sensor to
+    // go negative before turning the screen on.
+    private boolean mRequestWaitForNegativeProximity;
+
+    // Timestamp of the last time the device was awoken or put to sleep.
+    private long mLastWakeTime;
+    private long mLastSleepTime;
+
+    // True if we need to send a wake up or go to sleep finished notification
+    // when the display is ready.
+    private boolean mSendWakeUpFinishedNotificationWhenReady;
+    private boolean mSendGoToSleepFinishedNotificationWhenReady;
+
+    // Timestamp of the last call to user activity.
+    private long mLastUserActivityTime;
+    private long mLastUserActivityTimeNoChangeLights;
+
+    // A bitfield that summarizes the effect of the user activity timer.
+    // A zero value indicates that the user activity timer has expired.
+    private int mUserActivitySummary;
+
+    // The desired display power state.  The actual state may lag behind the
+    // requested because it is updated asynchronously by the display power controller.
+    private final DisplayPowerRequest mDisplayPowerRequest = new DisplayPowerRequest();
+
+    // True if the display power state has been fully applied, which means the display
+    // is actually on or actually off or whatever was requested.
+    private boolean mDisplayReady;
+
+    // The suspend blocker used to keep the CPU alive when an application has acquired
+    // a wake lock.
+    private final SuspendBlocker mWakeLockSuspendBlocker;
+
+    // True if the wake lock suspend blocker has been acquired.
+    private boolean mHoldingWakeLockSuspendBlocker;
+
+    // The suspend blocker used to keep the CPU alive when the display is on, the
+    // display is getting ready or there is user activity (in which case the display
+    // must be on).
+    private final SuspendBlocker mDisplaySuspendBlocker;
+
+    // True if the display suspend blocker has been acquired.
+    private boolean mHoldingDisplaySuspendBlocker;
+
+    // The screen on blocker used to keep the screen from turning on while the lock
+    // screen is coming up.
+    private final ScreenOnBlockerImpl mScreenOnBlocker;
+
+    // The display blanker used to turn the screen on or off.
+    private final DisplayBlankerImpl mDisplayBlanker;
+
+    // True if systemReady() has been called.
+    private boolean mSystemReady;
+
+    // True if boot completed occurred.  We keep the screen on until this happens.
+    private boolean mBootCompleted;
+
+    // True if auto-suspend mode is enabled.
+    // Refer to autosuspend.h.
+    private boolean mAutoSuspendModeEnabled;
+
+    // True if interactive mode is enabled.
+    // Refer to power.h.
+    private boolean mInteractiveModeEnabled;
+
+    // True if the device is plugged into a power source.
+    private boolean mIsPowered;
+
+    // The current plug type, such as BatteryManager.BATTERY_PLUGGED_WIRELESS.
+    private int mPlugType;
+
+    // The current battery level percentage.
+    private int mBatteryLevel;
+
+    // The battery level percentage at the time the dream started.
+    // This is used to terminate a dream and go to sleep if the battery is
+    // draining faster than it is charging and the user activity timeout has expired.
+    private int mBatteryLevelWhenDreamStarted;
+
+    // The current dock state.
+    private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
+
+    // True to decouple auto-suspend mode from the display state.
+    private boolean mDecoupleAutoSuspendModeFromDisplayConfig;
+
+    // True to decouple interactive mode from the display state.
+    private boolean mDecoupleInteractiveModeFromDisplayConfig;
+
+    // True if the device should wake up when plugged or unplugged.
+    private boolean mWakeUpWhenPluggedOrUnpluggedConfig;
+
+    // True if the device should suspend when the screen is off due to proximity.
+    private boolean mSuspendWhenScreenOffDueToProximityConfig;
+
+    // True if dreams are supported on this device.
+    private boolean mDreamsSupportedConfig;
+
+    // Default value for dreams enabled
+    private boolean mDreamsEnabledByDefaultConfig;
+
+    // Default value for dreams activate-on-sleep
+    private boolean mDreamsActivatedOnSleepByDefaultConfig;
+
+    // Default value for dreams activate-on-dock
+    private boolean mDreamsActivatedOnDockByDefaultConfig;
+
+    // True if dreams can run while not plugged in.
+    private boolean mDreamsEnabledOnBatteryConfig;
+
+    // Minimum battery level to allow dreaming when powered.
+    // Use -1 to disable this safety feature.
+    private int mDreamsBatteryLevelMinimumWhenPoweredConfig;
+
+    // Minimum battery level to allow dreaming when not powered.
+    // Use -1 to disable this safety feature.
+    private int mDreamsBatteryLevelMinimumWhenNotPoweredConfig;
+
+    // If the battery level drops by this percentage and the user activity timeout
+    // has expired, then assume the device is receiving insufficient current to charge
+    // effectively and terminate the dream.  Use -1 to disable this safety feature.
+    private int mDreamsBatteryLevelDrainCutoffConfig;
+
+    // True if dreams are enabled by the user.
+    private boolean mDreamsEnabledSetting;
+
+    // True if dreams should be activated on sleep.
+    private boolean mDreamsActivateOnSleepSetting;
+
+    // True if dreams should be activated on dock.
+    private boolean mDreamsActivateOnDockSetting;
+
+    // The screen off timeout setting value in milliseconds.
+    private int mScreenOffTimeoutSetting;
+
+    // The maximum allowable screen off timeout according to the device
+    // administration policy.  Overrides other settings.
+    private int mMaximumScreenOffTimeoutFromDeviceAdmin = Integer.MAX_VALUE;
+
+    // The stay on while plugged in setting.
+    // A bitfield of battery conditions under which to make the screen stay on.
+    private int mStayOnWhilePluggedInSetting;
+
+    // True if the device should stay on.
+    private boolean mStayOn;
+
+    // True if the proximity sensor reads a positive result.
+    private boolean mProximityPositive;
+
+    // Screen brightness setting limits.
+    private int mScreenBrightnessSettingMinimum;
+    private int mScreenBrightnessSettingMaximum;
+    private int mScreenBrightnessSettingDefault;
+
+    // The screen brightness setting, from 0 to 255.
+    // Use -1 if no value has been set.
+    private int mScreenBrightnessSetting;
+
+    // The screen auto-brightness adjustment setting, from -1 to 1.
+    // Use 0 if there is no adjustment.
+    private float mScreenAutoBrightnessAdjustmentSetting;
+
+    // The screen brightness mode.
+    // One of the Settings.System.SCREEN_BRIGHTNESS_MODE_* constants.
+    private int mScreenBrightnessModeSetting;
+
+    // The screen brightness setting override from the window manager
+    // to allow the current foreground activity to override the brightness.
+    // Use -1 to disable.
+    private int mScreenBrightnessOverrideFromWindowManager = -1;
+
+    // The user activity timeout override from the window manager
+    // to allow the current foreground activity to override the user activity timeout.
+    // Use -1 to disable.
+    private long mUserActivityTimeoutOverrideFromWindowManager = -1;
+
+    // The screen brightness setting override from the settings application
+    // to temporarily adjust the brightness until next updated,
+    // Use -1 to disable.
+    private int mTemporaryScreenBrightnessSettingOverride = -1;
+
+    // The screen brightness adjustment setting override from the settings
+    // application to temporarily adjust the auto-brightness adjustment factor
+    // until next updated, in the range -1..1.
+    // Use NaN to disable.
+    private float mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = Float.NaN;
+
+    // Time when we last logged a warning about calling userActivity() without permission.
+    private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE;
+
+    private native void nativeInit();
+
+    private static native void nativeSetPowerState(boolean screenOn, boolean screenBright);
+    private static native void nativeAcquireSuspendBlocker(String name);
+    private static native void nativeReleaseSuspendBlocker(String name);
+    private static native void nativeSetInteractive(boolean enable);
+    private static native void nativeSetAutoSuspend(boolean enable);
+
+    public PowerManagerService(Context context) {
+        super(context);
+        mContext = context;
+        synchronized (mLock) {
+            mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks");
+            mDisplaySuspendBlocker = createSuspendBlockerLocked("PowerManagerService.Display");
+            mDisplaySuspendBlocker.acquire();
+            mHoldingDisplaySuspendBlocker = true;
+
+            mScreenOnBlocker = new ScreenOnBlockerImpl();
+            mDisplayBlanker = new DisplayBlankerImpl();
+            mWakefulness = WAKEFULNESS_AWAKE;
+        }
+
+        nativeInit();
+        nativeSetPowerState(true, true);
+    }
+
+    @Override
+    public void onStart() {
+        publishBinderService(Context.POWER_SERVICE, new BinderService());
+        publishLocalService(PowerManagerInternal.class, new LocalService());
+    }
+
+    /**
+     * Initialize the power manager.
+     * Must be called before any other functions within the power manager are called.
+     */
+    public void init(LightsManager ls,
+            BatteryService bs, IBatteryStats bss,
+            IAppOpsService appOps) {
+        mLightsManager = ls;
+        mBatteryService = bs;
+        mBatteryStats = bss;
+        mAppOps = appOps;
+        mDisplayManagerInternal = getLocalService(DisplayManagerInternal.class);
+        mHandlerThread = new ServiceThread(TAG,
+                Process.THREAD_PRIORITY_DISPLAY, false /*allowIo*/);
+        mHandlerThread.start();
+        mHandler = new PowerManagerHandler(mHandlerThread.getLooper());
+
+        Watchdog.getInstance().addMonitor(this);
+        Watchdog.getInstance().addThread(mHandler);
+
+        // Forcibly turn the screen on at boot so that it is in a known power state.
+        // We do this in init() rather than in the constructor because setting the
+        // screen state requires a call into surface flinger which then needs to call back
+        // into the activity manager to check permissions.  Unfortunately the
+        // activity manager is not running when the constructor is called, so we
+        // have to defer setting the screen state until this point.
+        mDisplayBlanker.unblankAllDisplays();
+    }
+
+    void setPolicy(WindowManagerPolicy policy) {
+        synchronized (mLock) {
+            mPolicy = policy;
+        }
+    }
+
+    public void systemReady() {
+        synchronized (mLock) {
+            mSystemReady = true;
+            mDreamManager = LocalServices.getService(DreamManagerInternal.class);
+
+            PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+            mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting();
+            mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting();
+            mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting();
+
+            SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
+
+            // The notifier runs on the system server's main looper so as not to interfere
+            // with the animations and other critical functions of the power manager.
+            mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats,
+                    mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
+                    mScreenOnBlocker, mPolicy);
+
+            // The display power controller runs on the power manager service's
+            // own handler thread to ensure timely operation.
+            mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(),
+                    mContext, mNotifier, mLightsManager,
+                    LocalServices.getService(TwilightManager.class), sensorManager,
+                    mDisplaySuspendBlocker, mDisplayBlanker,
+                    mDisplayPowerControllerCallbacks, mHandler);
+
+            mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
+                    createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"),
+                    mHandler);
+            mSettingsObserver = new SettingsObserver(mHandler);
+            mAttentionLight = mLightsManager.getLight(LightsManager.LIGHT_ID_ATTENTION);
+
+            // Register for broadcasts from other components of the system.
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+            mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);
+
+            filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_BOOT_COMPLETED);
+            mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler);
+
+            filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_DREAMING_STARTED);
+            filter.addAction(Intent.ACTION_DREAMING_STOPPED);
+            mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler);
+
+            filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_USER_SWITCHED);
+            mContext.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
+
+            filter = new IntentFilter();
+            filter.addAction(Intent.ACTION_DOCK_EVENT);
+            mContext.registerReceiver(new DockReceiver(), filter, null, mHandler);
+
+            // Register for settings changes.
+            final ContentResolver resolver = mContext.getContentResolver();
+            resolver.registerContentObserver(Settings.Secure.getUriFor(
+                    Settings.Secure.SCREENSAVER_ENABLED),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+            resolver.registerContentObserver(Settings.Secure.getUriFor(
+                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+            resolver.registerContentObserver(Settings.Secure.getUriFor(
+                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+            resolver.registerContentObserver(Settings.System.getUriFor(
+                    Settings.System.SCREEN_OFF_TIMEOUT),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+            resolver.registerContentObserver(Settings.Global.getUriFor(
+                    Settings.Global.STAY_ON_WHILE_PLUGGED_IN),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+            resolver.registerContentObserver(Settings.System.getUriFor(
+                    Settings.System.SCREEN_BRIGHTNESS),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+            resolver.registerContentObserver(Settings.System.getUriFor(
+                    Settings.System.SCREEN_BRIGHTNESS_MODE),
+                    false, mSettingsObserver, UserHandle.USER_ALL);
+
+            // Go.
+            readConfigurationLocked();
+            updateSettingsLocked();
+            mDirty |= DIRTY_BATTERY_STATE;
+            updatePowerStateLocked();
+        }
+    }
+
+    private void readConfigurationLocked() {
+        final Resources resources = mContext.getResources();
+
+        mDecoupleAutoSuspendModeFromDisplayConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_powerDecoupleAutoSuspendModeFromDisplay);
+        mDecoupleInteractiveModeFromDisplayConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_powerDecoupleInteractiveModeFromDisplay);
+        mWakeUpWhenPluggedOrUnpluggedConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_unplugTurnsOnScreen);
+        mSuspendWhenScreenOffDueToProximityConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);
+        mDreamsSupportedConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_dreamsSupported);
+        mDreamsEnabledByDefaultConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_dreamsEnabledByDefault);
+        mDreamsActivatedOnSleepByDefaultConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
+        mDreamsActivatedOnDockByDefaultConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
+        mDreamsEnabledOnBatteryConfig = resources.getBoolean(
+                com.android.internal.R.bool.config_dreamsEnabledOnBattery);
+        mDreamsBatteryLevelMinimumWhenPoweredConfig = resources.getInteger(
+                com.android.internal.R.integer.config_dreamsBatteryLevelMinimumWhenPowered);
+        mDreamsBatteryLevelMinimumWhenNotPoweredConfig = resources.getInteger(
+                com.android.internal.R.integer.config_dreamsBatteryLevelMinimumWhenNotPowered);
+        mDreamsBatteryLevelDrainCutoffConfig = resources.getInteger(
+                com.android.internal.R.integer.config_dreamsBatteryLevelDrainCutoff);
+    }
+
+    private void updateSettingsLocked() {
+        final ContentResolver resolver = mContext.getContentResolver();
+
+        mDreamsEnabledSetting = (Settings.Secure.getIntForUser(resolver,
+                Settings.Secure.SCREENSAVER_ENABLED,
+                mDreamsEnabledByDefaultConfig ? 1 : 0,
+                UserHandle.USER_CURRENT) != 0);
+        mDreamsActivateOnSleepSetting = (Settings.Secure.getIntForUser(resolver,
+                Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
+                mDreamsActivatedOnSleepByDefaultConfig ? 1 : 0,
+                UserHandle.USER_CURRENT) != 0);
+        mDreamsActivateOnDockSetting = (Settings.Secure.getIntForUser(resolver,
+                Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
+                mDreamsActivatedOnDockByDefaultConfig ? 1 : 0,
+                UserHandle.USER_CURRENT) != 0);
+        mScreenOffTimeoutSetting = Settings.System.getIntForUser(resolver,
+                Settings.System.SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT,
+                UserHandle.USER_CURRENT);
+        mStayOnWhilePluggedInSetting = Settings.Global.getInt(resolver,
+                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC);
+
+        final int oldScreenBrightnessSetting = mScreenBrightnessSetting;
+        mScreenBrightnessSetting = Settings.System.getIntForUser(resolver,
+                Settings.System.SCREEN_BRIGHTNESS, mScreenBrightnessSettingDefault,
+                UserHandle.USER_CURRENT);
+        if (oldScreenBrightnessSetting != mScreenBrightnessSetting) {
+            mTemporaryScreenBrightnessSettingOverride = -1;
+        }
+
+        final float oldScreenAutoBrightnessAdjustmentSetting =
+                mScreenAutoBrightnessAdjustmentSetting;
+        mScreenAutoBrightnessAdjustmentSetting = Settings.System.getFloatForUser(resolver,
+                Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f,
+                UserHandle.USER_CURRENT);
+        if (oldScreenAutoBrightnessAdjustmentSetting != mScreenAutoBrightnessAdjustmentSetting) {
+            mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = Float.NaN;
+        }
+
+        mScreenBrightnessModeSetting = Settings.System.getIntForUser(resolver,
+                Settings.System.SCREEN_BRIGHTNESS_MODE,
+                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
+
+        mDirty |= DIRTY_SETTINGS;
+    }
+
+    private void handleSettingsChangedLocked() {
+        updateSettingsLocked();
+        updatePowerStateLocked();
+    }
+
+    private void acquireWakeLockInternal(IBinder lock, int flags, String tag, String packageName,
+            WorkSource ws, int uid, int pid) {
+        synchronized (mLock) {
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "acquireWakeLockInternal: lock=" + Objects.hashCode(lock)
+                        + ", flags=0x" + Integer.toHexString(flags)
+                        + ", tag=\"" + tag + "\", ws=" + ws + ", uid=" + uid + ", pid=" + pid);
+            }
+
+            WakeLock wakeLock;
+            int index = findWakeLockIndexLocked(lock);
+            if (index >= 0) {
+                wakeLock = mWakeLocks.get(index);
+                if (!wakeLock.hasSameProperties(flags, tag, ws, uid, pid)) {
+                    // Update existing wake lock.  This shouldn't happen but is harmless.
+                    notifyWakeLockReleasedLocked(wakeLock);
+                    wakeLock.updateProperties(flags, tag, packageName, ws, uid, pid);
+                    notifyWakeLockAcquiredLocked(wakeLock);
+                }
+            } else {
+                wakeLock = new WakeLock(lock, flags, tag, packageName, ws, uid, pid);
+                try {
+                    lock.linkToDeath(wakeLock, 0);
+                } catch (RemoteException ex) {
+                    throw new IllegalArgumentException("Wake lock is already dead.");
+                }
+                notifyWakeLockAcquiredLocked(wakeLock);
+                mWakeLocks.add(wakeLock);
+            }
+
+            applyWakeLockFlagsOnAcquireLocked(wakeLock);
+            mDirty |= DIRTY_WAKE_LOCKS;
+            updatePowerStateLocked();
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private static boolean isScreenLock(final WakeLock wakeLock) {
+        switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
+            case PowerManager.FULL_WAKE_LOCK:
+            case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
+            case PowerManager.SCREEN_DIM_WAKE_LOCK:
+                return true;
+        }
+        return false;
+    }
+
+    private void applyWakeLockFlagsOnAcquireLocked(WakeLock wakeLock) {
+        if ((wakeLock.mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0
+                && isScreenLock(wakeLock)) {
+            wakeUpNoUpdateLocked(SystemClock.uptimeMillis());
+        }
+    }
+
+    private void releaseWakeLockInternal(IBinder lock, int flags) {
+        synchronized (mLock) {
+            int index = findWakeLockIndexLocked(lock);
+            if (index < 0) {
+                if (DEBUG_SPEW) {
+                    Slog.d(TAG, "releaseWakeLockInternal: lock=" + Objects.hashCode(lock)
+                            + " [not found], flags=0x" + Integer.toHexString(flags));
+                }
+                return;
+            }
+
+            WakeLock wakeLock = mWakeLocks.get(index);
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "releaseWakeLockInternal: lock=" + Objects.hashCode(lock)
+                        + " [" + wakeLock.mTag + "], flags=0x" + Integer.toHexString(flags));
+            }
+
+            mWakeLocks.remove(index);
+            notifyWakeLockReleasedLocked(wakeLock);
+            wakeLock.mLock.unlinkToDeath(wakeLock, 0);
+
+            if ((flags & PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE) != 0) {
+                mRequestWaitForNegativeProximity = true;
+            }
+
+            applyWakeLockFlagsOnReleaseLocked(wakeLock);
+            mDirty |= DIRTY_WAKE_LOCKS;
+            updatePowerStateLocked();
+        }
+    }
+
+    private void handleWakeLockDeath(WakeLock wakeLock) {
+        synchronized (mLock) {
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "handleWakeLockDeath: lock=" + Objects.hashCode(wakeLock.mLock)
+                        + " [" + wakeLock.mTag + "]");
+            }
+
+            int index = mWakeLocks.indexOf(wakeLock);
+            if (index < 0) {
+                return;
+            }
+
+            mWakeLocks.remove(index);
+            notifyWakeLockReleasedLocked(wakeLock);
+
+            applyWakeLockFlagsOnReleaseLocked(wakeLock);
+            mDirty |= DIRTY_WAKE_LOCKS;
+            updatePowerStateLocked();
+        }
+    }
+
+    private void applyWakeLockFlagsOnReleaseLocked(WakeLock wakeLock) {
+        if ((wakeLock.mFlags & PowerManager.ON_AFTER_RELEASE) != 0
+                && isScreenLock(wakeLock)) {
+            userActivityNoUpdateLocked(SystemClock.uptimeMillis(),
+                    PowerManager.USER_ACTIVITY_EVENT_OTHER,
+                    PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS,
+                    wakeLock.mOwnerUid);
+        }
+    }
+
+    private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws) {
+        synchronized (mLock) {
+            int index = findWakeLockIndexLocked(lock);
+            if (index < 0) {
+                if (DEBUG_SPEW) {
+                    Slog.d(TAG, "updateWakeLockWorkSourceInternal: lock=" + Objects.hashCode(lock)
+                            + " [not found], ws=" + ws);
+                }
+                throw new IllegalArgumentException("Wake lock not active");
+            }
+
+            WakeLock wakeLock = mWakeLocks.get(index);
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "updateWakeLockWorkSourceInternal: lock=" + Objects.hashCode(lock)
+                        + " [" + wakeLock.mTag + "], ws=" + ws);
+            }
+
+            if (!wakeLock.hasSameWorkSource(ws)) {
+                notifyWakeLockReleasedLocked(wakeLock);
+                wakeLock.updateWorkSource(ws);
+                notifyWakeLockAcquiredLocked(wakeLock);
+            }
+        }
+    }
+
+    private int findWakeLockIndexLocked(IBinder lock) {
+        final int count = mWakeLocks.size();
+        for (int i = 0; i < count; i++) {
+            if (mWakeLocks.get(i).mLock == lock) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    private void notifyWakeLockAcquiredLocked(WakeLock wakeLock) {
+        if (mSystemReady) {
+            wakeLock.mNotifiedAcquired = true;
+            mNotifier.onWakeLockAcquired(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName,
+                    wakeLock.mOwnerUid, wakeLock.mOwnerPid, wakeLock.mWorkSource);
+        }
+    }
+
+    private void notifyWakeLockReleasedLocked(WakeLock wakeLock) {
+        if (mSystemReady && wakeLock.mNotifiedAcquired) {
+            wakeLock.mNotifiedAcquired = false;
+            mNotifier.onWakeLockReleased(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName,
+                    wakeLock.mOwnerUid, wakeLock.mOwnerPid, wakeLock.mWorkSource);
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private boolean isWakeLockLevelSupportedInternal(int level) {
+        synchronized (mLock) {
+            switch (level) {
+                case PowerManager.PARTIAL_WAKE_LOCK:
+                case PowerManager.SCREEN_DIM_WAKE_LOCK:
+                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
+                case PowerManager.FULL_WAKE_LOCK:
+                case PowerManager.DOZE_WAKE_LOCK:
+                    return true;
+
+                case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
+                    return mSystemReady && mDisplayPowerController.isProximitySensorAvailable();
+
+                default:
+                    return false;
+            }
+        }
+    }
+
+    // Called from native code.
+    private void userActivityFromNative(long eventTime, int event, int flags) {
+        userActivityInternal(eventTime, event, flags, Process.SYSTEM_UID);
+    }
+
+    private void userActivityInternal(long eventTime, int event, int flags, int uid) {
+        synchronized (mLock) {
+            if (userActivityNoUpdateLocked(eventTime, event, flags, uid)) {
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    private boolean userActivityNoUpdateLocked(long eventTime, int event, int flags, int uid) {
+        if (DEBUG_SPEW) {
+            Slog.d(TAG, "userActivityNoUpdateLocked: eventTime=" + eventTime
+                    + ", event=" + event + ", flags=0x" + Integer.toHexString(flags)
+                    + ", uid=" + uid);
+        }
+
+        if (eventTime < mLastSleepTime || eventTime < mLastWakeTime
+                || mWakefulness == WAKEFULNESS_ASLEEP || mWakefulness == WAKEFULNESS_DOZING
+                || !mBootCompleted || !mSystemReady) {
+            return false;
+        }
+
+        mNotifier.onUserActivity(event, uid);
+
+        if ((flags & PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS) != 0) {
+            if (eventTime > mLastUserActivityTimeNoChangeLights
+                    && eventTime > mLastUserActivityTime) {
+                mLastUserActivityTimeNoChangeLights = eventTime;
+                mDirty |= DIRTY_USER_ACTIVITY;
+                return true;
+            }
+        } else {
+            if (eventTime > mLastUserActivityTime) {
+                mLastUserActivityTime = eventTime;
+                mDirty |= DIRTY_USER_ACTIVITY;
+                return true;
+            }
+        }
+        return false;
+    }
+
+    // Called from native code.
+    private void wakeUpFromNative(long eventTime) {
+        wakeUpInternal(eventTime);
+    }
+
+    private void wakeUpInternal(long eventTime) {
+        synchronized (mLock) {
+            if (wakeUpNoUpdateLocked(eventTime)) {
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    private boolean wakeUpNoUpdateLocked(long eventTime) {
+        if (DEBUG_SPEW) {
+            Slog.d(TAG, "wakeUpNoUpdateLocked: eventTime=" + eventTime);
+        }
+
+        if (eventTime < mLastSleepTime || mWakefulness == WAKEFULNESS_AWAKE
+                || !mBootCompleted || !mSystemReady) {
+            return false;
+        }
+
+        switch (mWakefulness) {
+            case WAKEFULNESS_ASLEEP:
+                Slog.i(TAG, "Waking up from sleep...");
+                break;
+            case WAKEFULNESS_DREAMING:
+                Slog.i(TAG, "Waking up from dream...");
+                break;
+            case WAKEFULNESS_DOZING:
+                Slog.i(TAG, "Waking up from dozing...");
+                break;
+        }
+
+        if (mWakefulness != WAKEFULNESS_DREAMING) {
+            sendPendingNotificationsLocked();
+            mNotifier.onWakeUpStarted();
+            mSendWakeUpFinishedNotificationWhenReady = true;
+        }
+
+        mLastWakeTime = eventTime;
+        mWakefulness = WAKEFULNESS_AWAKE;
+        mDirty |= DIRTY_WAKEFULNESS;
+
+        userActivityNoUpdateLocked(
+                eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
+        return true;
+    }
+
+    // Called from native code.
+    private void goToSleepFromNative(long eventTime, int reason) {
+        goToSleepInternal(eventTime, reason);
+    }
+
+    private void goToSleepInternal(long eventTime, int reason) {
+        synchronized (mLock) {
+            if (goToSleepNoUpdateLocked(eventTime, reason)) {
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    // This method is called goToSleep for historical reasons but we actually start
+    // dozing before really going to sleep.
+    @SuppressWarnings("deprecation")
+    private boolean goToSleepNoUpdateLocked(long eventTime, int reason) {
+        if (DEBUG_SPEW) {
+            Slog.d(TAG, "goToSleepNoUpdateLocked: eventTime=" + eventTime + ", reason=" + reason);
+        }
+
+        if (eventTime < mLastWakeTime
+                || mWakefulness == WAKEFULNESS_ASLEEP
+                || mWakefulness == WAKEFULNESS_DOZING
+                || !mBootCompleted || !mSystemReady) {
+            return false;
+        }
+
+        switch (reason) {
+            case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN:
+                Slog.i(TAG, "Going to sleep due to device administration policy...");
+                break;
+            case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT:
+                Slog.i(TAG, "Going to sleep due to screen timeout...");
+                break;
+            default:
+                Slog.i(TAG, "Going to sleep by user request...");
+                reason = PowerManager.GO_TO_SLEEP_REASON_USER;
+                break;
+        }
+
+        sendPendingNotificationsLocked();
+        mNotifier.onGoToSleepStarted(reason);
+        mSendGoToSleepFinishedNotificationWhenReady = true;
+
+        mLastSleepTime = eventTime;
+        mDirty |= DIRTY_WAKEFULNESS;
+        mWakefulness = WAKEFULNESS_DOZING;
+        mSandmanSummoned = true;
+
+        // Report the number of wake locks that will be cleared by going to sleep.
+        int numWakeLocksCleared = 0;
+        final int numWakeLocks = mWakeLocks.size();
+        for (int i = 0; i < numWakeLocks; i++) {
+            final WakeLock wakeLock = mWakeLocks.get(i);
+            switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
+                case PowerManager.FULL_WAKE_LOCK:
+                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
+                case PowerManager.SCREEN_DIM_WAKE_LOCK:
+                    numWakeLocksCleared += 1;
+                    break;
+            }
+        }
+        EventLog.writeEvent(EventLogTags.POWER_SLEEP_REQUESTED, numWakeLocksCleared);
+        return true;
+    }
+
+    private void napInternal(long eventTime) {
+        synchronized (mLock) {
+            if (napNoUpdateLocked(eventTime)) {
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    private boolean napNoUpdateLocked(long eventTime) {
+        if (DEBUG_SPEW) {
+            Slog.d(TAG, "napNoUpdateLocked: eventTime=" + eventTime);
+        }
+
+        if (eventTime < mLastWakeTime || mWakefulness != WAKEFULNESS_AWAKE
+                || !mBootCompleted || !mSystemReady) {
+            return false;
+        }
+
+        Slog.i(TAG, "Nap time...");
+
+        mDirty |= DIRTY_WAKEFULNESS;
+        mWakefulness = WAKEFULNESS_DREAMING;
+        mSandmanSummoned = true;
+        return true;
+    }
+
+    // Done dozing, drop everything and go to sleep.
+    private boolean reallyGoToSleepNoUpdateLocked(long eventTime) {
+        if (DEBUG_SPEW) {
+            Slog.d(TAG, "reallyGoToSleepNoUpdateLocked: eventTime=" + eventTime);
+        }
+
+        if (eventTime < mLastWakeTime || mWakefulness == WAKEFULNESS_ASLEEP
+                || !mBootCompleted || !mSystemReady) {
+            return false;
+        }
+
+        Slog.i(TAG, "Sleeping...");
+
+        mDirty |= DIRTY_WAKEFULNESS;
+        mWakefulness = WAKEFULNESS_ASLEEP;
+        return true;
+    }
+
+    /**
+     * Updates the global power state based on dirty bits recorded in mDirty.
+     *
+     * This is the main function that performs power state transitions.
+     * We centralize them here so that we can recompute the power state completely
+     * each time something important changes, and ensure that we do it the same
+     * way each time.  The point is to gather all of the transition logic here.
+     */
+    private void updatePowerStateLocked() {
+        if (!mSystemReady || mDirty == 0) {
+            return;
+        }
+        if (!Thread.holdsLock(mLock)) {
+            Slog.wtf(TAG, "Power manager lock was not held when calling updatePowerStateLocked");
+        }
+
+        // Phase 0: Basic state updates.
+        updateIsPoweredLocked(mDirty);
+        updateStayOnLocked(mDirty);
+
+        // Phase 1: Update wakefulness.
+        // Loop because the wake lock and user activity computations are influenced
+        // by changes in wakefulness.
+        final long now = SystemClock.uptimeMillis();
+        int dirtyPhase2 = 0;
+        for (;;) {
+            int dirtyPhase1 = mDirty;
+            dirtyPhase2 |= dirtyPhase1;
+            mDirty = 0;
+
+            updateWakeLockSummaryLocked(dirtyPhase1);
+            updateUserActivitySummaryLocked(now, dirtyPhase1);
+            if (!updateWakefulnessLocked(dirtyPhase1)) {
+                break;
+            }
+        }
+
+        // Phase 2: Update dreams and display power state.
+        updateDreamLocked(dirtyPhase2);
+        updateDisplayPowerStateLocked(dirtyPhase2);
+
+        // Phase 3: Send notifications, if needed.
+        if (mDisplayReady) {
+            sendPendingNotificationsLocked();
+        }
+
+        // Phase 4: Update suspend blocker.
+        // Because we might release the last suspend blocker here, we need to make sure
+        // we finished everything else first!
+        updateSuspendBlockerLocked();
+    }
+
+    private void sendPendingNotificationsLocked() {
+        if (mSendWakeUpFinishedNotificationWhenReady) {
+            mSendWakeUpFinishedNotificationWhenReady = false;
+            mNotifier.onWakeUpFinished();
+        }
+        if (mSendGoToSleepFinishedNotificationWhenReady) {
+            mSendGoToSleepFinishedNotificationWhenReady = false;
+            mNotifier.onGoToSleepFinished();
+        }
+    }
+
+    /**
+     * Updates the value of mIsPowered.
+     * Sets DIRTY_IS_POWERED if a change occurred.
+     */
+    private void updateIsPoweredLocked(int dirty) {
+        if ((dirty & DIRTY_BATTERY_STATE) != 0) {
+            final boolean wasPowered = mIsPowered;
+            final int oldPlugType = mPlugType;
+            mIsPowered = mBatteryService.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
+            mPlugType = mBatteryService.getPlugType();
+            mBatteryLevel = mBatteryService.getBatteryLevel();
+
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered
+                        + ", mIsPowered=" + mIsPowered
+                        + ", oldPlugType=" + oldPlugType
+                        + ", mPlugType=" + mPlugType
+                        + ", mBatteryLevel=" + mBatteryLevel);
+            }
+
+            if (wasPowered != mIsPowered || oldPlugType != mPlugType) {
+                mDirty |= DIRTY_IS_POWERED;
+
+                // Update wireless dock detection state.
+                final boolean dockedOnWirelessCharger = mWirelessChargerDetector.update(
+                        mIsPowered, mPlugType, mBatteryLevel);
+
+                // Treat plugging and unplugging the devices as a user activity.
+                // Users find it disconcerting when they plug or unplug the device
+                // and it shuts off right away.
+                // Some devices also wake the device when plugged or unplugged because
+                // they don't have a charging LED.
+                final long now = SystemClock.uptimeMillis();
+                if (shouldWakeUpWhenPluggedOrUnpluggedLocked(wasPowered, oldPlugType,
+                        dockedOnWirelessCharger)) {
+                    wakeUpNoUpdateLocked(now);
+                }
+                userActivityNoUpdateLocked(
+                        now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
+
+                // Tell the notifier whether wireless charging has started so that
+                // it can provide feedback to the user.
+                if (dockedOnWirelessCharger) {
+                    mNotifier.onWirelessChargingStarted();
+                }
+            }
+        }
+    }
+
+    private boolean shouldWakeUpWhenPluggedOrUnpluggedLocked(
+            boolean wasPowered, int oldPlugType, boolean dockedOnWirelessCharger) {
+        // Don't wake when powered unless configured to do so.
+        if (!mWakeUpWhenPluggedOrUnpluggedConfig) {
+            return false;
+        }
+
+        // Don't wake when undocked from wireless charger.
+        // See WirelessChargerDetector for justification.
+        if (wasPowered && !mIsPowered
+                && oldPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
+            return false;
+        }
+
+        // Don't wake when docked on wireless charger unless we are certain of it.
+        // See WirelessChargerDetector for justification.
+        if (!wasPowered && mIsPowered
+                && mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS
+                && !dockedOnWirelessCharger) {
+            return false;
+        }
+
+        // If already dreaming and becoming powered, then don't wake.
+        if (mIsPowered && mWakefulness == WAKEFULNESS_DREAMING) {
+            return false;
+        }
+
+        // Otherwise wake up!
+        return true;
+    }
+
+    /**
+     * Updates the value of mStayOn.
+     * Sets DIRTY_STAY_ON if a change occurred.
+     */
+    private void updateStayOnLocked(int dirty) {
+        if ((dirty & (DIRTY_BATTERY_STATE | DIRTY_SETTINGS)) != 0) {
+            final boolean wasStayOn = mStayOn;
+            if (mStayOnWhilePluggedInSetting != 0
+                    && !isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
+                mStayOn = mBatteryService.isPowered(mStayOnWhilePluggedInSetting);
+            } else {
+                mStayOn = false;
+            }
+
+            if (mStayOn != wasStayOn) {
+                mDirty |= DIRTY_STAY_ON;
+            }
+        }
+    }
+
+    /**
+     * Updates the value of mWakeLockSummary to summarize the state of all active wake locks.
+     * Note that most wake-locks are ignored when the system is asleep.
+     *
+     * This function must have no other side-effects.
+     */
+    @SuppressWarnings("deprecation")
+    private void updateWakeLockSummaryLocked(int dirty) {
+        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_WAKEFULNESS)) != 0) {
+            mWakeLockSummary = 0;
+
+            final int numWakeLocks = mWakeLocks.size();
+            for (int i = 0; i < numWakeLocks; i++) {
+                final WakeLock wakeLock = mWakeLocks.get(i);
+                switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
+                    case PowerManager.PARTIAL_WAKE_LOCK:
+                        mWakeLockSummary |= WAKE_LOCK_CPU;
+                        break;
+                    case PowerManager.FULL_WAKE_LOCK:
+                        if (mWakefulness == WAKEFULNESS_AWAKE
+                                || mWakefulness == WAKEFULNESS_DREAMING) {
+                            mWakeLockSummary |= WAKE_LOCK_CPU
+                                    | WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_BUTTON_BRIGHT;
+                        }
+                        if (mWakefulness == WAKEFULNESS_AWAKE) {
+                            mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
+                        }
+                        break;
+                    case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
+                        if (mWakefulness == WAKEFULNESS_AWAKE
+                                || mWakefulness == WAKEFULNESS_DREAMING) {
+                            mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_SCREEN_BRIGHT;
+                        }
+                        if (mWakefulness == WAKEFULNESS_AWAKE) {
+                            mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
+                        }
+                        break;
+                    case PowerManager.SCREEN_DIM_WAKE_LOCK:
+                        if (mWakefulness == WAKEFULNESS_AWAKE
+                                || mWakefulness == WAKEFULNESS_DREAMING) {
+                            mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_SCREEN_DIM;
+                        }
+                        if (mWakefulness == WAKEFULNESS_AWAKE) {
+                            mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
+                        }
+                        break;
+                    case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
+                        if (mWakefulness == WAKEFULNESS_AWAKE
+                                || mWakefulness == WAKEFULNESS_DREAMING
+                                || mWakefulness == WAKEFULNESS_DOZING) {
+                            mWakeLockSummary |= WAKE_LOCK_PROXIMITY_SCREEN_OFF;
+                        }
+                        break;
+                    case PowerManager.DOZE_WAKE_LOCK:
+                        if (mWakefulness == WAKEFULNESS_DOZING) {
+                            mWakeLockSummary |= WAKE_LOCK_DOZE;
+                        }
+                        break;
+                }
+            }
+
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "updateWakeLockSummaryLocked: mWakefulness="
+                        + wakefulnessToString(mWakefulness)
+                        + ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary));
+            }
+        }
+    }
+
+    /**
+     * Updates the value of mUserActivitySummary to summarize the user requested
+     * state of the system such as whether the screen should be bright or dim.
+     * Note that user activity is ignored when the system is asleep.
+     *
+     * This function must have no other side-effects.
+     */
+    private void updateUserActivitySummaryLocked(long now, int dirty) {
+        // Update the status of the user activity timeout timer.
+        if ((dirty & (DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS | DIRTY_SETTINGS)) != 0) {
+            mHandler.removeMessages(MSG_USER_ACTIVITY_TIMEOUT);
+
+            long nextTimeout = 0;
+            if (mWakefulness == WAKEFULNESS_AWAKE
+                    || mWakefulness == WAKEFULNESS_DREAMING) {
+                final int screenOffTimeout = getScreenOffTimeoutLocked();
+                final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
+
+                mUserActivitySummary = 0;
+                if (mLastUserActivityTime >= mLastWakeTime) {
+                    nextTimeout = mLastUserActivityTime
+                            + screenOffTimeout - screenDimDuration;
+                    if (now < nextTimeout) {
+                        mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;
+                    } else {
+                        nextTimeout = mLastUserActivityTime + screenOffTimeout;
+                        if (now < nextTimeout) {
+                            mUserActivitySummary |= USER_ACTIVITY_SCREEN_DIM;
+                        }
+                    }
+                }
+                if (mUserActivitySummary == 0
+                        && mLastUserActivityTimeNoChangeLights >= mLastWakeTime) {
+                    nextTimeout = mLastUserActivityTimeNoChangeLights + screenOffTimeout;
+                    if (now < nextTimeout
+                            && mDisplayPowerRequest.wantScreenOnNormal()) {
+                        mUserActivitySummary = mDisplayPowerRequest.screenState
+                                == DisplayPowerRequest.SCREEN_STATE_BRIGHT ?
+                                USER_ACTIVITY_SCREEN_BRIGHT : USER_ACTIVITY_SCREEN_DIM;
+                    }
+                }
+                if (mUserActivitySummary != 0) {
+                    Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
+                    msg.setAsynchronous(true);
+                    mHandler.sendMessageAtTime(msg, nextTimeout);
+                }
+            } else {
+                mUserActivitySummary = 0;
+            }
+
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "updateUserActivitySummaryLocked: mWakefulness="
+                        + wakefulnessToString(mWakefulness)
+                        + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
+                        + ", nextTimeout=" + TimeUtils.formatUptime(nextTimeout));
+            }
+        }
+    }
+
+    /**
+     * Called when a user activity timeout has occurred.
+     * Simply indicates that something about user activity has changed so that the new
+     * state can be recomputed when the power state is updated.
+     *
+     * This function must have no other side-effects besides setting the dirty
+     * bit and calling update power state.  Wakefulness transitions are handled elsewhere.
+     */
+    private void handleUserActivityTimeout() { // runs on handler thread
+        synchronized (mLock) {
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "handleUserActivityTimeout");
+            }
+
+            mDirty |= DIRTY_USER_ACTIVITY;
+            updatePowerStateLocked();
+        }
+    }
+
+    private int getScreenOffTimeoutLocked() {
+        int timeout = mScreenOffTimeoutSetting;
+        if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
+            timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
+        }
+        if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {
+            timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);
+        }
+        return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);
+    }
+
+    private int getScreenDimDurationLocked(int screenOffTimeout) {
+        return Math.min(SCREEN_DIM_DURATION,
+                (int)(screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO));
+    }
+
+    /**
+     * Updates the wakefulness of the device.
+     *
+     * This is the function that decides whether the device should start dreaming
+     * based on the current wake locks and user activity state.  It may modify mDirty
+     * if the wakefulness changes.
+     *
+     * Returns true if the wakefulness changed and we need to restart power state calculation.
+     */
+    private boolean updateWakefulnessLocked(int dirty) {
+        boolean changed = false;
+        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_BOOT_COMPLETED
+                | DIRTY_WAKEFULNESS | DIRTY_STAY_ON | DIRTY_PROXIMITY_POSITIVE
+                | DIRTY_DOCK_STATE)) != 0) {
+            if (mWakefulness == WAKEFULNESS_AWAKE && isItBedTimeYetLocked()) {
+                if (DEBUG_SPEW) {
+                    Slog.d(TAG, "updateWakefulnessLocked: Bed time...");
+                }
+                final long time = SystemClock.uptimeMillis();
+                if (shouldNapAtBedTimeLocked()) {
+                    changed = napNoUpdateLocked(time);
+                } else {
+                    changed = goToSleepNoUpdateLocked(time,
+                            PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
+                }
+            }
+        }
+        return changed;
+    }
+
+    /**
+     * Returns true if the device should automatically nap and start dreaming when the user
+     * activity timeout has expired and it's bedtime.
+     */
+    private boolean shouldNapAtBedTimeLocked() {
+        return mDreamsActivateOnSleepSetting
+                || (mDreamsActivateOnDockSetting
+                        && mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED);
+    }
+
+    /**
+     * Returns true if the device should go to sleep now.
+     * Also used when exiting a dream to determine whether we should go back
+     * to being fully awake or else go to sleep for good.
+     */
+    private boolean isItBedTimeYetLocked() {
+        return mBootCompleted && !isBeingKeptAwakeLocked();
+    }
+
+    /**
+     * Returns true if the device is being kept awake by a wake lock, user activity
+     * or the stay on while powered setting.  We also keep the phone awake when
+     * the proximity sensor returns a positive result so that the device does not
+     * lock while in a phone call.  This function only controls whether the device
+     * will go to sleep or dream which is independent of whether it will be allowed
+     * to suspend.
+     */
+    private boolean isBeingKeptAwakeLocked() {
+        return mStayOn
+                || mProximityPositive
+                || (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) != 0
+                || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT
+                        | USER_ACTIVITY_SCREEN_DIM)) != 0;
+    }
+
+    /**
+     * Determines whether to post a message to the sandman to update the dream state.
+     */
+    private void updateDreamLocked(int dirty) {
+        if ((dirty & (DIRTY_WAKEFULNESS
+                | DIRTY_USER_ACTIVITY
+                | DIRTY_WAKE_LOCKS
+                | DIRTY_BOOT_COMPLETED
+                | DIRTY_SETTINGS
+                | DIRTY_IS_POWERED
+                | DIRTY_STAY_ON
+                | DIRTY_PROXIMITY_POSITIVE
+                | DIRTY_BATTERY_STATE)) != 0) {
+            scheduleSandmanLocked();
+        }
+    }
+
+    private void scheduleSandmanLocked() {
+        if (!mSandmanScheduled) {
+            mSandmanScheduled = true;
+            Message msg = mHandler.obtainMessage(MSG_SANDMAN);
+            msg.setAsynchronous(true);
+            mHandler.sendMessage(msg);
+        }
+    }
+
+    /**
+     * Called when the device enters or exits a dreaming or dozing state.
+     *
+     * We do this asynchronously because we must call out of the power manager to start
+     * the dream and we don't want to hold our lock while doing so.  There is a risk that
+     * the device will wake or go to sleep in the meantime so we have to handle that case.
+     */
+    private void handleSandman() { // runs on handler thread
+        // Handle preconditions.
+        final boolean startDreaming;
+        final int wakefulness;
+        synchronized (mLock) {
+            mSandmanScheduled = false;
+            wakefulness = mWakefulness;
+            if (mSandmanSummoned) {
+                startDreaming = ((wakefulness == WAKEFULNESS_DREAMING && canDreamLocked())
+                        || wakefulness == WAKEFULNESS_DOZING);
+                mSandmanSummoned = false;
+            } else {
+                startDreaming = false;
+            }
+        }
+
+        // Start dreaming if needed.
+        // We only control the dream on the handler thread, so we don't need to worry about
+        // concurrent attempts to start or stop the dream.
+        final boolean isDreaming;
+        if (mDreamManager != null) {
+            // Restart the dream whenever the sandman is summoned.
+            if (startDreaming) {
+                mDreamManager.stopDream();
+                mDreamManager.startDream(wakefulness == WAKEFULNESS_DOZING);
+            }
+            isDreaming = mDreamManager.isDreaming();
+        } else {
+            isDreaming = false;
+        }
+
+        // Update dream state.
+        synchronized (mLock) {
+            // Remember the initial battery level when the dream started.
+            if (startDreaming && isDreaming) {
+                mBatteryLevelWhenDreamStarted = mBatteryLevel;
+                if (wakefulness == WAKEFULNESS_DOZING) {
+                    Slog.i(TAG, "Dozing...");
+                } else {
+                    Slog.i(TAG, "Dreaming...");
+                }
+            }
+
+            // If preconditions changed, wait for the next iteration to determine
+            // whether the dream should continue (or be restarted).
+            if (mSandmanSummoned || mWakefulness != wakefulness) {
+                return; // wait for next cycle
+            }
+
+            // Determine whether the dream should continue.
+            if (wakefulness == WAKEFULNESS_DREAMING) {
+                if (isDreaming && canDreamLocked()) {
+                    if (mDreamsBatteryLevelDrainCutoffConfig >= 0
+                            && mBatteryLevel < mBatteryLevelWhenDreamStarted
+                                    - mDreamsBatteryLevelDrainCutoffConfig
+                            && !isBeingKeptAwakeLocked()) {
+                        // If the user activity timeout expired and the battery appears
+                        // to be draining faster than it is charging then stop dreaming
+                        // and go to sleep.
+                        Slog.i(TAG, "Stopping dream because the battery appears to "
+                                + "be draining faster than it is charging.  "
+                                + "Battery level when dream started: "
+                                + mBatteryLevelWhenDreamStarted + "%.  "
+                                + "Battery level now: " + mBatteryLevel + "%.");
+                    } else {
+                        return; // continue dreaming
+                    }
+                }
+
+                // Dream has ended or will be stopped.  Update the power state.
+                if (isItBedTimeYetLocked()) {
+                    goToSleepNoUpdateLocked(SystemClock.uptimeMillis(),
+                            PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
+                    updatePowerStateLocked();
+                } else {
+                    wakeUpNoUpdateLocked(SystemClock.uptimeMillis());
+                    updatePowerStateLocked();
+                }
+            } else if (wakefulness == WAKEFULNESS_DOZING) {
+                if (isDreaming) {
+                    return; // continue dozing
+                }
+
+                // Doze has ended or will be stopped.  Update the power state.
+                reallyGoToSleepNoUpdateLocked(SystemClock.uptimeMillis());
+                updatePowerStateLocked();
+            }
+        }
+
+        // Stop dream.
+        if (isDreaming) {
+            mDreamManager.stopDream();
+        }
+    }
+
+    /**
+     * Returns true if the device is allowed to dream in its current state.
+     * This function is not called when dozing.
+     */
+    private boolean canDreamLocked() {
+        if (mWakefulness != WAKEFULNESS_DREAMING
+                || !mDreamsSupportedConfig
+                || !mDreamsEnabledSetting
+                || !mDisplayPowerRequest.wantScreenOnNormal()
+                || !mBootCompleted) {
+            return false;
+        }
+        if (!isBeingKeptAwakeLocked()) {
+            if (!mIsPowered && !mDreamsEnabledOnBatteryConfig) {
+                return false;
+            }
+            if (!mIsPowered
+                    && mDreamsBatteryLevelMinimumWhenNotPoweredConfig >= 0
+                    && mBatteryLevel < mDreamsBatteryLevelMinimumWhenNotPoweredConfig) {
+                return false;
+            }
+            if (mIsPowered
+                    && mDreamsBatteryLevelMinimumWhenPoweredConfig >= 0
+                    && mBatteryLevel < mDreamsBatteryLevelMinimumWhenPoweredConfig) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private void handleScreenOnBlockerReleased() {
+        synchronized (mLock) {
+            mDirty |= DIRTY_SCREEN_ON_BLOCKER_RELEASED;
+            updatePowerStateLocked();
+        }
+    }
+
+    /**
+     * Updates the display power state asynchronously.
+     * When the update is finished, mDisplayReady will be set to true.  The display
+     * controller posts a message to tell us when the actual display power state
+     * has been updated so we come back here to double-check and finish up.
+     *
+     * This function recalculates the display power state each time.
+     */
+    private void updateDisplayPowerStateLocked(int dirty) {
+        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS
+                | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED
+                | DIRTY_SETTINGS | DIRTY_SCREEN_ON_BLOCKER_RELEASED)) != 0) {
+            final int newScreenState = getDesiredScreenPowerStateLocked();
+            mDisplayPowerRequest.screenState = newScreenState;
+            nativeSetPowerState(isScreenOnLocked(),
+                    newScreenState == DisplayPowerRequest.SCREEN_STATE_BRIGHT);
+
+            int screenBrightness = mScreenBrightnessSettingDefault;
+            float screenAutoBrightnessAdjustment = 0.0f;
+            boolean autoBrightness = (mScreenBrightnessModeSetting ==
+                    Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
+            if (isValidBrightness(mScreenBrightnessOverrideFromWindowManager)) {
+                screenBrightness = mScreenBrightnessOverrideFromWindowManager;
+                autoBrightness = false;
+            } else if (isValidBrightness(mTemporaryScreenBrightnessSettingOverride)) {
+                screenBrightness = mTemporaryScreenBrightnessSettingOverride;
+            } else if (isValidBrightness(mScreenBrightnessSetting)) {
+                screenBrightness = mScreenBrightnessSetting;
+            }
+            if (autoBrightness) {
+                screenBrightness = mScreenBrightnessSettingDefault;
+                if (isValidAutoBrightnessAdjustment(
+                        mTemporaryScreenAutoBrightnessAdjustmentSettingOverride)) {
+                    screenAutoBrightnessAdjustment =
+                            mTemporaryScreenAutoBrightnessAdjustmentSettingOverride;
+                } else if (isValidAutoBrightnessAdjustment(
+                        mScreenAutoBrightnessAdjustmentSetting)) {
+                    screenAutoBrightnessAdjustment = mScreenAutoBrightnessAdjustmentSetting;
+                }
+            }
+            screenBrightness = Math.max(Math.min(screenBrightness,
+                    mScreenBrightnessSettingMaximum), mScreenBrightnessSettingMinimum);
+            screenAutoBrightnessAdjustment = Math.max(Math.min(
+                    screenAutoBrightnessAdjustment, 1.0f), -1.0f);
+            mDisplayPowerRequest.screenBrightness = screenBrightness;
+            mDisplayPowerRequest.screenAutoBrightnessAdjustment =
+                    screenAutoBrightnessAdjustment;
+            mDisplayPowerRequest.useAutoBrightness = autoBrightness;
+
+            mDisplayPowerRequest.useProximitySensor = shouldUseProximitySensorLocked();
+
+            mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld();
+
+            mDisplayReady = mDisplayPowerController.requestPowerState(mDisplayPowerRequest,
+                    mRequestWaitForNegativeProximity);
+            mRequestWaitForNegativeProximity = false;
+
+            if (DEBUG_SPEW) {
+                Slog.d(TAG, "updateScreenStateLocked: mDisplayReady=" + mDisplayReady
+                        + ", newScreenState=" + newScreenState
+                        + ", mWakefulness=" + mWakefulness
+                        + ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary)
+                        + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
+                        + ", mBootCompleted=" + mBootCompleted);
+            }
+        }
+    }
+
+    private static boolean isValidBrightness(int value) {
+        return value >= 0 && value <= 255;
+    }
+
+    private static boolean isValidAutoBrightnessAdjustment(float value) {
+        // Handles NaN by always returning false.
+        return value >= -1.0f && value <= 1.0f;
+    }
+
+    private int getDesiredScreenPowerStateLocked() {
+        if (mWakefulness == WAKEFULNESS_ASLEEP) {
+            return DisplayPowerRequest.SCREEN_STATE_OFF;
+        }
+
+        if ((mWakeLockSummary & WAKE_LOCK_DOZE) != 0) {
+            return DisplayPowerRequest.SCREEN_STATE_DOZE;
+        }
+
+        if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0
+                || (mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0
+                || !mBootCompleted) {
+            return DisplayPowerRequest.SCREEN_STATE_BRIGHT;
+        }
+
+        return DisplayPowerRequest.SCREEN_STATE_DIM;
+    }
+
+    private final DisplayPowerController.Callbacks mDisplayPowerControllerCallbacks =
+            new DisplayPowerController.Callbacks() {
+        @Override
+        public void onStateChanged() {
+            synchronized (mLock) {
+                mDirty |= DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED;
+                updatePowerStateLocked();
+            }
+        }
+
+        @Override
+        public void onProximityPositive() {
+            synchronized (mLock) {
+                mProximityPositive = true;
+                mDirty |= DIRTY_PROXIMITY_POSITIVE;
+                updatePowerStateLocked();
+            }
+        }
+
+        @Override
+        public void onProximityNegative() {
+            synchronized (mLock) {
+                mProximityPositive = false;
+                mDirty |= DIRTY_PROXIMITY_POSITIVE;
+                userActivityNoUpdateLocked(SystemClock.uptimeMillis(),
+                        PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
+                updatePowerStateLocked();
+            }
+        }
+    };
+
+    private boolean shouldUseProximitySensorLocked() {
+        return (mWakeLockSummary & WAKE_LOCK_PROXIMITY_SCREEN_OFF) != 0;
+    }
+
+    /**
+     * Updates the suspend blocker that keeps the CPU alive.
+     *
+     * This function must have no other side-effects.
+     */
+    private void updateSuspendBlockerLocked() {
+        final boolean needWakeLockSuspendBlocker = ((mWakeLockSummary & WAKE_LOCK_CPU) != 0);
+        final boolean needDisplaySuspendBlocker = needDisplaySuspendBlockerLocked();
+        final boolean autoSuspend = !needDisplaySuspendBlocker;
+
+        // Disable auto-suspend if needed.
+        if (!autoSuspend) {
+            if (mDecoupleAutoSuspendModeFromDisplayConfig) {
+                setAutoSuspendModeLocked(false);
+            }
+            if (mDecoupleInteractiveModeFromDisplayConfig) {
+                setInteractiveModeLocked(true);
+            }
+        }
+
+        // First acquire suspend blockers if needed.
+        if (needWakeLockSuspendBlocker && !mHoldingWakeLockSuspendBlocker) {
+            mWakeLockSuspendBlocker.acquire();
+            mHoldingWakeLockSuspendBlocker = true;
+        }
+        if (needDisplaySuspendBlocker && !mHoldingDisplaySuspendBlocker) {
+            mDisplaySuspendBlocker.acquire();
+            mHoldingDisplaySuspendBlocker = true;
+        }
+
+        // Then release suspend blockers if needed.
+        if (!needWakeLockSuspendBlocker && mHoldingWakeLockSuspendBlocker) {
+            mWakeLockSuspendBlocker.release();
+            mHoldingWakeLockSuspendBlocker = false;
+        }
+        if (!needDisplaySuspendBlocker && mHoldingDisplaySuspendBlocker) {
+            mDisplaySuspendBlocker.release();
+            mHoldingDisplaySuspendBlocker = false;
+        }
+
+        // Enable auto-suspend if needed.
+        if (autoSuspend) {
+            if (mDecoupleInteractiveModeFromDisplayConfig) {
+                setInteractiveModeLocked(false);
+            }
+            if (mDecoupleAutoSuspendModeFromDisplayConfig) {
+                setAutoSuspendModeLocked(true);
+            }
+        }
+    }
+
+    /**
+     * Return true if we must keep a suspend blocker active on behalf of the display.
+     * We do so if the screen is on or is in transition between states.
+     */
+    private boolean needDisplaySuspendBlockerLocked() {
+        if (!mDisplayReady) {
+            return true;
+        }
+        if (mDisplayPowerRequest.wantScreenOnNormal()) {
+            // If we asked for the screen to be on but it is off due to the proximity
+            // sensor then we may suspend but only if the configuration allows it.
+            // On some hardware it may not be safe to suspend because the proximity
+            // sensor may not be correctly configured as a wake-up source.
+            if (!mDisplayPowerRequest.useProximitySensor || !mProximityPositive
+                    || !mSuspendWhenScreenOffDueToProximityConfig) {
+                return true;
+            }
+        }
+        // Let the system suspend if the screen is off or dozing.
+        return false;
+    }
+
+    private void setAutoSuspendModeLocked(boolean enable) {
+        if (enable != mAutoSuspendModeEnabled) {
+            if (DEBUG) {
+                Slog.d(TAG, "Setting auto-suspend mode to " + enable);
+            }
+            mAutoSuspendModeEnabled = enable;
+            nativeSetAutoSuspend(enable);
+        }
+    }
+
+    private void setInteractiveModeLocked(boolean enable) {
+        if (enable != mInteractiveModeEnabled) {
+            if (DEBUG) {
+                Slog.d(TAG, "Setting interactive mode to " + enable);
+            }
+            mInteractiveModeEnabled = enable;
+            nativeSetInteractive(enable);
+        }
+    }
+
+    private boolean isScreenOnInternal() {
+        synchronized (mLock) {
+            // XXX This is a temporary hack to let certain parts of the system pretend the
+            // screen is still on even when dozing and we would normally want to report
+            // screen off.  Will be removed when the window manager is modified to use
+            // the true blanking state of the display.
+            return isScreenOnLocked()
+                    || mWakefulness == WAKEFULNESS_DOZING;
+        }
+    }
+
+    private boolean isScreenOnLocked() {
+        return mWakefulness == WAKEFULNESS_AWAKE
+                || mWakefulness == WAKEFULNESS_DREAMING;
+    }
+
+    private void handleBatteryStateChangedLocked() {
+        mDirty |= DIRTY_BATTERY_STATE;
+        updatePowerStateLocked();
+    }
+
+    private void startWatchingForBootAnimationFinished() {
+        mHandler.sendEmptyMessage(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED);
+    }
+
+    private void checkIfBootAnimationFinished() {
+        if (DEBUG) {
+            Slog.d(TAG, "Check if boot animation finished...");
+        }
+
+        if (SystemService.isRunning(BOOT_ANIMATION_SERVICE)) {
+            mHandler.sendEmptyMessageDelayed(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED,
+                    BOOT_ANIMATION_POLL_INTERVAL);
+            return;
+        }
+
+        synchronized (mLock) {
+            if (!mBootCompleted) {
+                Slog.i(TAG, "Boot animation finished.");
+                handleBootCompletedLocked();
+            }
+        }
+    }
+
+    private void handleBootCompletedLocked() {
+        final long now = SystemClock.uptimeMillis();
+        mBootCompleted = true;
+        mDirty |= DIRTY_BOOT_COMPLETED;
+        userActivityNoUpdateLocked(
+                now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
+        updatePowerStateLocked();
+    }
+
+    private void shutdownOrRebootInternal(final boolean shutdown, final boolean confirm,
+            final String reason, boolean wait) {
+        if (mHandler == null || !mSystemReady) {
+            throw new IllegalStateException("Too early to call shutdown() or reboot()");
+        }
+
+        Runnable runnable = new Runnable() {
+            @Override
+            public void run() {
+                synchronized (this) {
+                    if (shutdown) {
+                        ShutdownThread.shutdown(mContext, confirm);
+                    } else {
+                        ShutdownThread.reboot(mContext, reason, confirm);
+                    }
+                }
+            }
+        };
+
+        // ShutdownThread must run on a looper capable of displaying the UI.
+        Message msg = Message.obtain(mHandler, runnable);
+        msg.setAsynchronous(true);
+        mHandler.sendMessage(msg);
+
+        // PowerManager.reboot() is documented not to return so just wait for the inevitable.
+        if (wait) {
+            synchronized (runnable) {
+                while (true) {
+                    try {
+                        runnable.wait();
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+        }
+    }
+
+    private void crashInternal(final String message) {
+        Thread t = new Thread("PowerManagerService.crash()") {
+            @Override
+            public void run() {
+                throw new RuntimeException(message);
+            }
+        };
+        try {
+            t.start();
+            t.join();
+        } catch (InterruptedException e) {
+            Log.wtf(TAG, e);
+        }
+    }
+
+    private void setStayOnSettingInternal(int val) {
+        Settings.Global.putInt(mContext.getContentResolver(),
+                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, val);
+    }
+
+    private void setMaximumScreenOffTimeoutFromDeviceAdminInternal(int timeMs) {
+        synchronized (mLock) {
+            mMaximumScreenOffTimeoutFromDeviceAdmin = timeMs;
+            mDirty |= DIRTY_SETTINGS;
+            updatePowerStateLocked();
+        }
+    }
+
+    private boolean isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() {
+        return mMaximumScreenOffTimeoutFromDeviceAdmin >= 0
+                && mMaximumScreenOffTimeoutFromDeviceAdmin < Integer.MAX_VALUE;
+    }
+
+    private void setAttentionLightInternal(boolean on, int color) {
+        Light light;
+        synchronized (mLock) {
+            if (!mSystemReady) {
+                return;
+            }
+            light = mAttentionLight;
+        }
+
+        // Control light outside of lock.
+        light.setFlashing(color, Light.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0);
+    }
+
+    private void setScreenBrightnessOverrideFromWindowManagerInternal(int brightness) {
+        synchronized (mLock) {
+            if (mScreenBrightnessOverrideFromWindowManager != brightness) {
+                mScreenBrightnessOverrideFromWindowManager = brightness;
+                mDirty |= DIRTY_SETTINGS;
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    private void setUserActivityTimeoutOverrideFromWindowManagerInternal(long timeoutMillis) {
+        synchronized (mLock) {
+            if (mUserActivityTimeoutOverrideFromWindowManager != timeoutMillis) {
+                mUserActivityTimeoutOverrideFromWindowManager = timeoutMillis;
+                mDirty |= DIRTY_SETTINGS;
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    private void setTemporaryScreenBrightnessSettingOverrideInternal(int brightness) {
+        synchronized (mLock) {
+            if (mTemporaryScreenBrightnessSettingOverride != brightness) {
+                mTemporaryScreenBrightnessSettingOverride = brightness;
+                mDirty |= DIRTY_SETTINGS;
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    private void setTemporaryScreenAutoBrightnessAdjustmentSettingOverrideInternal(float adj) {
+        synchronized (mLock) {
+            // Note: This condition handles NaN because NaN is not equal to any other
+            // value, including itself.
+            if (mTemporaryScreenAutoBrightnessAdjustmentSettingOverride != adj) {
+                mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = adj;
+                mDirty |= DIRTY_SETTINGS;
+                updatePowerStateLocked();
+            }
+        }
+    }
+
+    /**
+     * Low-level function turn the device off immediately, without trying
+     * to be clean.  Most people should use {@link ShutdownThread} for a clean shutdown.
+     */
+    public static void lowLevelShutdown() {
+        SystemProperties.set("sys.powerctl", "shutdown");
+    }
+
+    /**
+     * Low-level function to reboot the device. On success, this function
+     * doesn't return. If more than 5 seconds passes from the time,
+     * a reboot is requested, this method returns.
+     *
+     * @param reason code to pass to the kernel (e.g. "recovery"), or null.
+     */
+    public static void lowLevelReboot(String reason) {
+        if (reason == null) {
+            reason = "";
+        }
+        SystemProperties.set("sys.powerctl", "reboot," + reason);
+        try {
+            Thread.sleep(20000);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+    }
+
+    @Override // Watchdog.Monitor implementation
+    public void monitor() {
+        // Grab and release lock for watchdog monitor to detect deadlocks.
+        synchronized (mLock) {
+        }
+    }
+
+    private void dumpInternal(PrintWriter pw) {
+        pw.println("POWER MANAGER (dumpsys power)\n");
+
+        final DisplayPowerController dpc;
+        final WirelessChargerDetector wcd;
+        synchronized (mLock) {
+            pw.println("Power Manager State:");
+            pw.println("  mDirty=0x" + Integer.toHexString(mDirty));
+            pw.println("  mWakefulness=" + wakefulnessToString(mWakefulness));
+            pw.println("  mIsPowered=" + mIsPowered);
+            pw.println("  mPlugType=" + mPlugType);
+            pw.println("  mBatteryLevel=" + mBatteryLevel);
+            pw.println("  mBatteryLevelWhenDreamStarted=" + mBatteryLevelWhenDreamStarted);
+            pw.println("  mDockState=" + mDockState);
+            pw.println("  mStayOn=" + mStayOn);
+            pw.println("  mProximityPositive=" + mProximityPositive);
+            pw.println("  mBootCompleted=" + mBootCompleted);
+            pw.println("  mSystemReady=" + mSystemReady);
+            pw.println("  mAutoSuspendModeEnabled=" + mAutoSuspendModeEnabled);
+            pw.println("  mInteactiveModeEnabled=" + mInteractiveModeEnabled);
+            pw.println("  mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary));
+            pw.println("  mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary));
+            pw.println("  mRequestWaitForNegativeProximity=" + mRequestWaitForNegativeProximity);
+            pw.println("  mSandmanScheduled=" + mSandmanScheduled);
+            pw.println("  mSandmanSummoned=" + mSandmanSummoned);
+            pw.println("  mLastWakeTime=" + TimeUtils.formatUptime(mLastWakeTime));
+            pw.println("  mLastSleepTime=" + TimeUtils.formatUptime(mLastSleepTime));
+            pw.println("  mSendWakeUpFinishedNotificationWhenReady="
+                    + mSendWakeUpFinishedNotificationWhenReady);
+            pw.println("  mSendGoToSleepFinishedNotificationWhenReady="
+                    + mSendGoToSleepFinishedNotificationWhenReady);
+            pw.println("  mLastUserActivityTime=" + TimeUtils.formatUptime(mLastUserActivityTime));
+            pw.println("  mLastUserActivityTimeNoChangeLights="
+                    + TimeUtils.formatUptime(mLastUserActivityTimeNoChangeLights));
+            pw.println("  mDisplayReady=" + mDisplayReady);
+            pw.println("  mHoldingWakeLockSuspendBlocker=" + mHoldingWakeLockSuspendBlocker);
+            pw.println("  mHoldingDisplaySuspendBlocker=" + mHoldingDisplaySuspendBlocker);
+
+            pw.println();
+            pw.println("Settings and Configuration:");
+            pw.println("  mDecoupleAutoSuspendModeFromDisplayConfig="
+                    + mDecoupleAutoSuspendModeFromDisplayConfig);
+            pw.println("  mDecoupleInteractiveModeFromDisplayConfig="
+                    + mDecoupleInteractiveModeFromDisplayConfig);
+            pw.println("  mWakeUpWhenPluggedOrUnpluggedConfig="
+                    + mWakeUpWhenPluggedOrUnpluggedConfig);
+            pw.println("  mSuspendWhenScreenOffDueToProximityConfig="
+                    + mSuspendWhenScreenOffDueToProximityConfig);
+            pw.println("  mDreamsSupportedConfig=" + mDreamsSupportedConfig);
+            pw.println("  mDreamsEnabledByDefaultConfig=" + mDreamsEnabledByDefaultConfig);
+            pw.println("  mDreamsActivatedOnSleepByDefaultConfig="
+                    + mDreamsActivatedOnSleepByDefaultConfig);
+            pw.println("  mDreamsActivatedOnDockByDefaultConfig="
+                    + mDreamsActivatedOnDockByDefaultConfig);
+            pw.println("  mDreamsEnabledOnBatteryConfig="
+                    + mDreamsEnabledOnBatteryConfig);
+            pw.println("  mDreamsBatteryLevelMinimumWhenPoweredConfig="
+                    + mDreamsBatteryLevelMinimumWhenPoweredConfig);
+            pw.println("  mDreamsBatteryLevelMinimumWhenNotPoweredConfig="
+                    + mDreamsBatteryLevelMinimumWhenNotPoweredConfig);
+            pw.println("  mDreamsBatteryLevelDrainCutoffConfig="
+                    + mDreamsBatteryLevelDrainCutoffConfig);
+            pw.println("  mDreamsEnabledSetting=" + mDreamsEnabledSetting);
+            pw.println("  mDreamsActivateOnSleepSetting=" + mDreamsActivateOnSleepSetting);
+            pw.println("  mDreamsActivateOnDockSetting=" + mDreamsActivateOnDockSetting);
+            pw.println("  mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting);
+            pw.println("  mMaximumScreenOffTimeoutFromDeviceAdmin="
+                    + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced="
+                    + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")");
+            pw.println("  mStayOnWhilePluggedInSetting=" + mStayOnWhilePluggedInSetting);
+            pw.println("  mScreenBrightnessSetting=" + mScreenBrightnessSetting);
+            pw.println("  mScreenAutoBrightnessAdjustmentSetting="
+                    + mScreenAutoBrightnessAdjustmentSetting);
+            pw.println("  mScreenBrightnessModeSetting=" + mScreenBrightnessModeSetting);
+            pw.println("  mScreenBrightnessOverrideFromWindowManager="
+                    + mScreenBrightnessOverrideFromWindowManager);
+            pw.println("  mUserActivityTimeoutOverrideFromWindowManager="
+                    + mUserActivityTimeoutOverrideFromWindowManager);
+            pw.println("  mTemporaryScreenBrightnessSettingOverride="
+                    + mTemporaryScreenBrightnessSettingOverride);
+            pw.println("  mTemporaryScreenAutoBrightnessAdjustmentSettingOverride="
+                    + mTemporaryScreenAutoBrightnessAdjustmentSettingOverride);
+            pw.println("  mScreenBrightnessSettingMinimum=" + mScreenBrightnessSettingMinimum);
+            pw.println("  mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum);
+            pw.println("  mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault);
+
+            final int screenOffTimeout = getScreenOffTimeoutLocked();
+            final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
+            pw.println();
+            pw.println("Screen off timeout: " + screenOffTimeout + " ms");
+            pw.println("Screen dim duration: " + screenDimDuration + " ms");
+
+            pw.println();
+            pw.println("Wake Locks: size=" + mWakeLocks.size());
+            for (WakeLock wl : mWakeLocks) {
+                pw.println("  " + wl);
+            }
+
+            pw.println();
+            pw.println("Suspend Blockers: size=" + mSuspendBlockers.size());
+            for (SuspendBlocker sb : mSuspendBlockers) {
+                pw.println("  " + sb);
+            }
+
+            pw.println();
+            pw.println("Screen On Blocker: " + mScreenOnBlocker);
+
+            pw.println();
+            pw.println("Display Blanker: " + mDisplayBlanker);
+
+            dpc = mDisplayPowerController;
+            wcd = mWirelessChargerDetector;
+        }
+
+        if (dpc != null) {
+            dpc.dump(pw);
+        }
+
+        if (wcd != null) {
+            wcd.dump(pw);
+        }
+    }
+
+    private SuspendBlocker createSuspendBlockerLocked(String name) {
+        SuspendBlocker suspendBlocker = new SuspendBlockerImpl(name);
+        mSuspendBlockers.add(suspendBlocker);
+        return suspendBlocker;
+    }
+
+    private static String wakefulnessToString(int wakefulness) {
+        switch (wakefulness) {
+            case WAKEFULNESS_ASLEEP:
+                return "Asleep";
+            case WAKEFULNESS_AWAKE:
+                return "Awake";
+            case WAKEFULNESS_DREAMING:
+                return "Dreaming";
+            case WAKEFULNESS_DOZING:
+                return "Dozing";
+            default:
+                return Integer.toString(wakefulness);
+        }
+    }
+
+    private static WorkSource copyWorkSource(WorkSource workSource) {
+        return workSource != null ? new WorkSource(workSource) : null;
+    }
+
+    private final class BatteryReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (mLock) {
+                handleBatteryStateChangedLocked();
+            }
+        }
+    }
+
+    private final class BootCompletedReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            // This is our early signal that the system thinks it has finished booting.
+            // However, the boot animation may still be running for a few more seconds
+            // since it is ultimately in charge of when it terminates.
+            // Defer transitioning into the boot completed state until the animation exits.
+            // We do this so that the screen does not start to dim prematurely before
+            // the user has actually had a chance to interact with the device.
+            startWatchingForBootAnimationFinished();
+        }
+    }
+
+    private final class DreamReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (mLock) {
+                scheduleSandmanLocked();
+            }
+        }
+    }
+
+    private final class UserSwitchedReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (mLock) {
+                handleSettingsChangedLocked();
+            }
+        }
+    }
+
+    private final class DockReceiver extends BroadcastReceiver {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (mLock) {
+                int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
+                        Intent.EXTRA_DOCK_STATE_UNDOCKED);
+                if (mDockState != dockState) {
+                    mDockState = dockState;
+                    mDirty |= DIRTY_DOCK_STATE;
+                    updatePowerStateLocked();
+                }
+            }
+        }
+    }
+
+    private final class SettingsObserver extends ContentObserver {
+        public SettingsObserver(Handler handler) {
+            super(handler);
+        }
+
+        @Override
+        public void onChange(boolean selfChange, Uri uri) {
+            synchronized (mLock) {
+                handleSettingsChangedLocked();
+            }
+        }
+    }
+
+    /**
+     * Handler for asynchronous operations performed by the power manager.
+     */
+    private final class PowerManagerHandler extends Handler {
+        public PowerManagerHandler(Looper looper) {
+            super(looper, null, true /*async*/);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_USER_ACTIVITY_TIMEOUT:
+                    handleUserActivityTimeout();
+                    break;
+                case MSG_SANDMAN:
+                    handleSandman();
+                    break;
+                case MSG_SCREEN_ON_BLOCKER_RELEASED:
+                    handleScreenOnBlockerReleased();
+                    break;
+                case MSG_CHECK_IF_BOOT_ANIMATION_FINISHED:
+                    checkIfBootAnimationFinished();
+                    break;
+            }
+        }
+    }
+
+    /**
+     * Represents a wake lock that has been acquired by an application.
+     */
+    private final class WakeLock implements IBinder.DeathRecipient {
+        public final IBinder mLock;
+        public int mFlags;
+        public String mTag;
+        public final String mPackageName;
+        public WorkSource mWorkSource;
+        public final int mOwnerUid;
+        public final int mOwnerPid;
+        public boolean mNotifiedAcquired;
+
+        public WakeLock(IBinder lock, int flags, String tag, String packageName,
+                WorkSource workSource, int ownerUid, int ownerPid) {
+            mLock = lock;
+            mFlags = flags;
+            mTag = tag;
+            mPackageName = packageName;
+            mWorkSource = copyWorkSource(workSource);
+            mOwnerUid = ownerUid;
+            mOwnerPid = ownerPid;
+        }
+
+        @Override
+        public void binderDied() {
+            PowerManagerService.this.handleWakeLockDeath(this);
+        }
+
+        public boolean hasSameProperties(int flags, String tag, WorkSource workSource,
+                int ownerUid, int ownerPid) {
+            return mFlags == flags
+                    && mTag.equals(tag)
+                    && hasSameWorkSource(workSource)
+                    && mOwnerUid == ownerUid
+                    && mOwnerPid == ownerPid;
+        }
+
+        public void updateProperties(int flags, String tag, String packageName,
+                WorkSource workSource, int ownerUid, int ownerPid) {
+            if (!mPackageName.equals(packageName)) {
+                throw new IllegalStateException("Existing wake lock package name changed: "
+                        + mPackageName + " to " + packageName);
+            }
+            if (mOwnerUid != ownerUid) {
+                throw new IllegalStateException("Existing wake lock uid changed: "
+                        + mOwnerUid + " to " + ownerUid);
+            }
+            if (mOwnerPid != ownerPid) {
+                throw new IllegalStateException("Existing wake lock pid changed: "
+                        + mOwnerPid + " to " + ownerPid);
+            }
+            mFlags = flags;
+            mTag = tag;
+            updateWorkSource(workSource);
+        }
+
+        public boolean hasSameWorkSource(WorkSource workSource) {
+            return Objects.equal(mWorkSource, workSource);
+        }
+
+        public void updateWorkSource(WorkSource workSource) {
+            mWorkSource = copyWorkSource(workSource);
+        }
+
+        @Override
+        public String toString() {
+            return getLockLevelString()
+                    + " '" + mTag + "'" + getLockFlagsString()
+                    + " (uid=" + mOwnerUid + ", pid=" + mOwnerPid + ", ws=" + mWorkSource + ")";
+        }
+
+        @SuppressWarnings("deprecation")
+        private String getLockLevelString() {
+            switch (mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
+                case PowerManager.FULL_WAKE_LOCK:
+                    return "FULL_WAKE_LOCK                ";
+                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
+                    return "SCREEN_BRIGHT_WAKE_LOCK       ";
+                case PowerManager.SCREEN_DIM_WAKE_LOCK:
+                    return "SCREEN_DIM_WAKE_LOCK          ";
+                case PowerManager.PARTIAL_WAKE_LOCK:
+                    return "PARTIAL_WAKE_LOCK             ";
+                case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
+                    return "PROXIMITY_SCREEN_OFF_WAKE_LOCK";
+                case PowerManager.DOZE_WAKE_LOCK:
+                    return "DOZE_WAKE_LOCK                ";
+                default:
+                    return "???                           ";
+            }
+        }
+
+        private String getLockFlagsString() {
+            String result = "";
+            if ((mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0) {
+                result += " ACQUIRE_CAUSES_WAKEUP";
+            }
+            if ((mFlags & PowerManager.ON_AFTER_RELEASE) != 0) {
+                result += " ON_AFTER_RELEASE";
+            }
+            return result;
+        }
+    }
+
+    private final class SuspendBlockerImpl implements SuspendBlocker {
+        private final String mName;
+        private int mReferenceCount;
+
+        public SuspendBlockerImpl(String name) {
+            mName = name;
+        }
+
+        @Override
+        protected void finalize() throws Throwable {
+            try {
+                if (mReferenceCount != 0) {
+                    Log.wtf(TAG, "Suspend blocker \"" + mName
+                            + "\" was finalized without being released!");
+                    mReferenceCount = 0;
+                    nativeReleaseSuspendBlocker(mName);
+                }
+            } finally {
+                super.finalize();
+            }
+        }
+
+        @Override
+        public void acquire() {
+            synchronized (this) {
+                mReferenceCount += 1;
+                if (mReferenceCount == 1) {
+                    if (DEBUG_SPEW) {
+                        Slog.d(TAG, "Acquiring suspend blocker \"" + mName + "\".");
+                    }
+                    nativeAcquireSuspendBlocker(mName);
+                }
+            }
+        }
+
+        @Override
+        public void release() {
+            synchronized (this) {
+                mReferenceCount -= 1;
+                if (mReferenceCount == 0) {
+                    if (DEBUG_SPEW) {
+                        Slog.d(TAG, "Releasing suspend blocker \"" + mName + "\".");
+                    }
+                    nativeReleaseSuspendBlocker(mName);
+                } else if (mReferenceCount < 0) {
+                    Log.wtf(TAG, "Suspend blocker \"" + mName
+                            + "\" was released without being acquired!", new Throwable());
+                    mReferenceCount = 0;
+                }
+            }
+        }
+
+        @Override
+        public String toString() {
+            synchronized (this) {
+                return mName + ": ref count=" + mReferenceCount;
+            }
+        }
+    }
+
+    private final class ScreenOnBlockerImpl implements ScreenOnBlocker {
+        private int mNestCount;
+
+        public boolean isHeld() {
+            synchronized (this) {
+                return mNestCount != 0;
+            }
+        }
+
+        @Override
+        public void acquire() {
+            synchronized (this) {
+                mNestCount += 1;
+                if (DEBUG) {
+                    Slog.d(TAG, "Screen on blocked: mNestCount=" + mNestCount);
+                }
+            }
+        }
+
+        @Override
+        public void release() {
+            synchronized (this) {
+                mNestCount -= 1;
+                if (mNestCount < 0) {
+                    Log.wtf(TAG, "Screen on blocker was released without being acquired!",
+                            new Throwable());
+                    mNestCount = 0;
+                }
+                if (mNestCount == 0) {
+                    mHandler.sendEmptyMessage(MSG_SCREEN_ON_BLOCKER_RELEASED);
+                }
+                if (DEBUG) {
+                    Slog.d(TAG, "Screen on unblocked: mNestCount=" + mNestCount);
+                }
+            }
+        }
+
+        @Override
+        public String toString() {
+            synchronized (this) {
+                return "held=" + (mNestCount != 0) + ", mNestCount=" + mNestCount;
+            }
+        }
+    }
+
+    private final class DisplayBlankerImpl implements DisplayBlanker {
+        private boolean mBlanked;
+
+        @Override
+        public void blankAllDisplays() {
+            synchronized (this) {
+                mBlanked = true;
+                mDisplayManagerInternal.blankAllDisplaysFromPowerManager();
+                if (!mDecoupleInteractiveModeFromDisplayConfig) {
+                    setInteractiveModeLocked(false);
+                }
+                if (!mDecoupleAutoSuspendModeFromDisplayConfig) {
+                    setAutoSuspendModeLocked(true);
+                }
+            }
+        }
+
+        @Override
+        public void unblankAllDisplays() {
+            synchronized (this) {
+                if (!mDecoupleAutoSuspendModeFromDisplayConfig) {
+                    setAutoSuspendModeLocked(false);
+                }
+                if (!mDecoupleInteractiveModeFromDisplayConfig) {
+                    setInteractiveModeLocked(true);
+                }
+                mDisplayManagerInternal.unblankAllDisplaysFromPowerManager();
+                mBlanked = false;
+            }
+        }
+
+        @Override
+        public String toString() {
+            synchronized (this) {
+                return "blanked=" + mBlanked;
+            }
+        }
+    }
+
+    private final class BinderService extends IPowerManager.Stub {
+        @Override // Binder call
+        public void acquireWakeLockWithUid(IBinder lock, int flags, String tag,
+                String packageName, int uid) {
+            acquireWakeLock(lock, flags, tag, packageName, new WorkSource(uid));
+        }
+
+        @Override // Binder call
+        public void acquireWakeLock(IBinder lock, int flags, String tag, String packageName,
+                WorkSource ws) {
+            if (lock == null) {
+                throw new IllegalArgumentException("lock must not be null");
+            }
+            if (packageName == null) {
+                throw new IllegalArgumentException("packageName must not be null");
+            }
+            PowerManager.validateWakeLockParameters(flags, tag);
+
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
+            if (ws != null && ws.size() != 0) {
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.UPDATE_DEVICE_STATS, null);
+            } else {
+                ws = null;
+            }
+
+            final int uid = Binder.getCallingUid();
+            final int pid = Binder.getCallingPid();
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                acquireWakeLockInternal(lock, flags, tag, packageName, ws, uid, pid);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void releaseWakeLock(IBinder lock, int flags) {
+            if (lock == null) {
+                throw new IllegalArgumentException("lock must not be null");
+            }
+
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                releaseWakeLockInternal(lock, flags);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void updateWakeLockUids(IBinder lock, int[] uids) {
+            WorkSource ws = null;
+
+            if (uids != null) {
+                ws = new WorkSource();
+                // XXX should WorkSource have a way to set uids as an int[] instead of adding them
+                // one at a time?
+                for (int i = 0; i < uids.length; i++) {
+                    ws.add(uids[i]);
+                }
+            }
+            updateWakeLockWorkSource(lock, ws);
+        }
+
+        @Override // Binder call
+        public void updateWakeLockWorkSource(IBinder lock, WorkSource ws) {
+            if (lock == null) {
+                throw new IllegalArgumentException("lock must not be null");
+            }
+
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
+            if (ws != null && ws.size() != 0) {
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.UPDATE_DEVICE_STATS, null);
+            } else {
+                ws = null;
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                updateWakeLockWorkSourceInternal(lock, ws);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public boolean isWakeLockLevelSupported(int level) {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return isWakeLockLevelSupportedInternal(level);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void userActivity(long eventTime, int event, int flags) {
+            final long now = SystemClock.uptimeMillis();
+            if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER)
+                    != PackageManager.PERMISSION_GRANTED) {
+                // Once upon a time applications could call userActivity().
+                // Now we require the DEVICE_POWER permission.  Log a warning and ignore the
+                // request instead of throwing a SecurityException so we don't break old apps.
+                synchronized (mLock) {
+                    if (now >= mLastWarningAboutUserActivityPermission + (5 * 60 * 1000)) {
+                        mLastWarningAboutUserActivityPermission = now;
+                        Slog.w(TAG, "Ignoring call to PowerManager.userActivity() because the "
+                                + "caller does not have DEVICE_POWER permission.  "
+                                + "Please fix your app!  "
+                                + " pid=" + Binder.getCallingPid()
+                                + " uid=" + Binder.getCallingUid());
+                    }
+                }
+                return;
+            }
+
+            if (eventTime > SystemClock.uptimeMillis()) {
+                throw new IllegalArgumentException("event time must not be in the future");
+            }
+
+            final int uid = Binder.getCallingUid();
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                userActivityInternal(eventTime, event, flags, uid);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void wakeUp(long eventTime) {
+            if (eventTime > SystemClock.uptimeMillis()) {
+                throw new IllegalArgumentException("event time must not be in the future");
+            }
+
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                wakeUpInternal(eventTime);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void goToSleep(long eventTime, int reason) {
+            if (eventTime > SystemClock.uptimeMillis()) {
+                throw new IllegalArgumentException("event time must not be in the future");
+            }
+
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                goToSleepInternal(eventTime, reason);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public void nap(long eventTime) {
+            if (eventTime > SystemClock.uptimeMillis()) {
+                throw new IllegalArgumentException("event time must not be in the future");
+            }
+
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                napInternal(eventTime);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        public boolean isScreenOn() {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                return isScreenOnInternal();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Reboots the device.
+         *
+         * @param confirm If true, shows a reboot confirmation dialog.
+         * @param reason The reason for the reboot, or null if none.
+         * @param wait If true, this call waits for the reboot to complete and does not return.
+         */
+        @Override // Binder call
+        public void reboot(boolean confirm, String reason, boolean wait) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                shutdownOrRebootInternal(false, confirm, reason, wait);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Shuts down the device.
+         *
+         * @param confirm If true, shows a shutdown confirmation dialog.
+         * @param wait If true, this call waits for the shutdown to complete and does not return.
+         */
+        @Override // Binder call
+        public void shutdown(boolean confirm, boolean wait) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                shutdownOrRebootInternal(true, confirm, null, wait);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Crash the runtime (causing a complete restart of the Android framework).
+         * Requires REBOOT permission.  Mostly for testing.  Should not return.
+         */
+        @Override // Binder call
+        public void crash(String message) {
+            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                crashInternal(message);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Set the setting that determines whether the device stays on when plugged in.
+         * The argument is a bit string, with each bit specifying a power source that,
+         * when the device is connected to that source, causes the device to stay on.
+         * See {@link android.os.BatteryManager} for the list of power sources that
+         * can be specified. Current values include
+         * {@link android.os.BatteryManager#BATTERY_PLUGGED_AC}
+         * and {@link android.os.BatteryManager#BATTERY_PLUGGED_USB}
+         *
+         * Used by "adb shell svc power stayon ..."
+         *
+         * @param val an {@code int} containing the bits that specify which power sources
+         * should cause the device to stay on.
+         */
+        @Override // Binder call
+        public void setStayOnSetting(int val) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.WRITE_SETTINGS, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setStayOnSettingInternal(val);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Used by device administration to set the maximum screen off timeout.
+         *
+         * This method must only be called by the device administration policy manager.
+         */
+        @Override // Binder call
+        public void setMaximumScreenOffTimeoutFromDeviceAdmin(int timeMs) {
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setMaximumScreenOffTimeoutFromDeviceAdminInternal(timeMs);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Used by the settings application and brightness control widgets to
+         * temporarily override the current screen brightness setting so that the
+         * user can observe the effect of an intended settings change without applying
+         * it immediately.
+         *
+         * The override will be canceled when the setting value is next updated.
+         *
+         * @param brightness The overridden brightness.
+         *
+         * @see android.provider.Settings.System#SCREEN_BRIGHTNESS
+         */
+        @Override // Binder call
+        public void setTemporaryScreenBrightnessSettingOverride(int brightness) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setTemporaryScreenBrightnessSettingOverrideInternal(brightness);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Used by the settings application and brightness control widgets to
+         * temporarily override the current screen auto-brightness adjustment setting so that the
+         * user can observe the effect of an intended settings change without applying
+         * it immediately.
+         *
+         * The override will be canceled when the setting value is next updated.
+         *
+         * @param adj The overridden brightness, or Float.NaN to disable the override.
+         *
+         * @see Settings.System#SCREEN_AUTO_BRIGHTNESS_ADJ
+         */
+        @Override // Binder call
+        public void setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(float adj) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setTemporaryScreenAutoBrightnessAdjustmentSettingOverrideInternal(adj);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Used by the phone application to make the attention LED flash when ringing.
+         */
+        @Override // Binder call
+        public void setAttentionLight(boolean on, int color) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setAttentionLightInternal(on, color);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override // Binder call
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump PowerManager from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                dumpInternal(pw);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    private final class LocalService extends PowerManagerInternal {
+        /**
+         * Used by the window manager to override the screen brightness based on the
+         * current foreground activity.
+         *
+         * This method must only be called by the window manager.
+         *
+         * @param brightness The overridden brightness, or -1 to disable the override.
+         */
+        @Override
+        public void setScreenBrightnessOverrideFromWindowManager(int brightness) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setScreenBrightnessOverrideFromWindowManagerInternal(brightness);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        /**
+         * Used by the window manager to override the button brightness based on the
+         * current foreground activity.
+         *
+         * This method must only be called by the window manager.
+         *
+         * @param brightness The overridden brightness, or -1 to disable the override.
+         */
+        @Override
+        public void setButtonBrightnessOverrideFromWindowManager(int brightness) {
+            // Do nothing.
+            // Button lights are not currently supported in the new implementation.
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+        }
+
+        /**
+         * Used by the window manager to override the user activity timeout based on the
+         * current foreground activity.  It can only be used to make the timeout shorter
+         * than usual, not longer.
+         *
+         * This method must only be called by the window manager.
+         *
+         * @param timeoutMillis The overridden timeout, or -1 to disable the override.
+         */
+        @Override
+        public void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.DEVICE_POWER, null);
+
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                setUserActivityTimeoutOverrideFromWindowManagerInternal(timeoutMillis);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+
+        @Override
+        public void setPolicy(WindowManagerPolicy policy) {
+            PowerManagerService.this.setPolicy(policy);
+        }
+    }
+}
diff --git a/services/java/com/android/server/power/RampAnimator.java b/services/core/java/com/android/server/power/RampAnimator.java
similarity index 100%
rename from services/java/com/android/server/power/RampAnimator.java
rename to services/core/java/com/android/server/power/RampAnimator.java
diff --git a/services/java/com/android/server/power/ScreenOnBlocker.java b/services/core/java/com/android/server/power/ScreenOnBlocker.java
similarity index 100%
rename from services/java/com/android/server/power/ScreenOnBlocker.java
rename to services/core/java/com/android/server/power/ScreenOnBlocker.java
diff --git a/services/java/com/android/server/power/ShutdownThread.java b/services/core/java/com/android/server/power/ShutdownThread.java
similarity index 100%
rename from services/java/com/android/server/power/ShutdownThread.java
rename to services/core/java/com/android/server/power/ShutdownThread.java
diff --git a/services/java/com/android/server/power/SuspendBlocker.java b/services/core/java/com/android/server/power/SuspendBlocker.java
similarity index 100%
rename from services/java/com/android/server/power/SuspendBlocker.java
rename to services/core/java/com/android/server/power/SuspendBlocker.java
diff --git a/services/java/com/android/server/power/WirelessChargerDetector.java b/services/core/java/com/android/server/power/WirelessChargerDetector.java
similarity index 100%
rename from services/java/com/android/server/power/WirelessChargerDetector.java
rename to services/core/java/com/android/server/power/WirelessChargerDetector.java
diff --git a/services/java/com/android/server/search/SearchManagerService.java b/services/core/java/com/android/server/search/SearchManagerService.java
similarity index 100%
rename from services/java/com/android/server/search/SearchManagerService.java
rename to services/core/java/com/android/server/search/SearchManagerService.java
diff --git a/services/java/com/android/server/search/Searchables.java b/services/core/java/com/android/server/search/Searchables.java
similarity index 100%
rename from services/java/com/android/server/search/Searchables.java
rename to services/core/java/com/android/server/search/Searchables.java
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
new file mode 100644
index 0000000..4f75189
--- /dev/null
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerInternal.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2013, 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.statusbar;
+
+import com.android.server.notification.NotificationDelegate;
+
+import android.os.IBinder;
+import android.service.notification.StatusBarNotification;
+
+public interface StatusBarManagerInternal {
+    void setNotificationDelegate(NotificationDelegate delegate);
+    IBinder addNotification(StatusBarNotification notification);
+    void updateNotification(IBinder key, StatusBarNotification notification);
+    void removeNotification(IBinder key);
+}
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
new file mode 100644
index 0000000..2ae467e
--- /dev/null
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -0,0 +1,701 @@
+/*
+ * Copyright (C) 2007 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.statusbar;
+
+import android.app.StatusBarManager;
+import android.os.Binder;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.service.notification.StatusBarNotification;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.util.Slog;
+
+import com.android.internal.statusbar.IStatusBar;
+import com.android.internal.statusbar.IStatusBarService;
+import com.android.internal.statusbar.StatusBarIcon;
+import com.android.internal.statusbar.StatusBarIconList;
+import com.android.server.LocalServices;
+import com.android.server.notification.NotificationDelegate;
+import com.android.server.wm.WindowManagerService;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * A note on locking:  We rely on the fact that calls onto mBar are oneway or
+ * if they are local, that they just enqueue messages to not deadlock.
+ */
+public class StatusBarManagerService extends IStatusBarService.Stub
+    implements WindowManagerService.OnHardKeyboardStatusChangeListener
+{
+    private static final String TAG = "StatusBarManagerService";
+    private static final boolean SPEW = false;
+
+    private final Context mContext;
+    private final WindowManagerService mWindowManager;
+    private Handler mHandler = new Handler();
+    private NotificationDelegate mNotificationDelegate;
+    private volatile IStatusBar mBar;
+    private StatusBarIconList mIcons = new StatusBarIconList();
+    private HashMap<IBinder,StatusBarNotification> mNotifications
+            = new HashMap<IBinder,StatusBarNotification>();
+
+    // for disabling the status bar
+    private final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
+    private IBinder mSysUiVisToken = new Binder();
+    private int mDisabled = 0;
+
+    private Object mLock = new Object();
+    // encompasses lights-out mode and other flags defined on View
+    private int mSystemUiVisibility = 0;
+    private boolean mMenuVisible = false;
+    private int mImeWindowVis = 0;
+    private int mImeBackDisposition;
+    private IBinder mImeToken = null;
+    private int mCurrentUserId;
+
+    private class DisableRecord implements IBinder.DeathRecipient {
+        int userId;
+        String pkg;
+        int what;
+        IBinder token;
+
+        public void binderDied() {
+            Slog.i(TAG, "binder died for pkg=" + pkg);
+            disableInternal(userId, 0, token, pkg);
+            token.unlinkToDeath(this, 0);
+        }
+    }
+
+    /**
+     * Construct the service, add the status bar view to the window manager
+     */
+    public StatusBarManagerService(Context context, WindowManagerService windowManager) {
+        mContext = context;
+        mWindowManager = windowManager;
+        mWindowManager.setOnHardKeyboardStatusChangeListener(this);
+
+        final Resources res = context.getResources();
+        mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
+
+        LocalServices.addService(StatusBarManagerInternal.class, mInternalService);
+    }
+
+    /**
+     * Private API used by NotificationManagerService.
+     */
+    private final StatusBarManagerInternal mInternalService = new StatusBarManagerInternal() {
+        @Override
+        public void setNotificationDelegate(NotificationDelegate delegate) {
+            synchronized (mNotifications) {
+                mNotificationDelegate = delegate;
+            }
+        }
+
+        @Override
+        public IBinder addNotification(StatusBarNotification notification) {
+            synchronized (mNotifications) {
+                IBinder key = new Binder();
+                mNotifications.put(key, notification);
+                if (mBar != null) {
+                    try {
+                        mBar.addNotification(key, notification);
+                    } catch (RemoteException ex) {
+                    }
+                }
+                return key;
+            }
+        }
+
+        @Override
+        public void updateNotification(IBinder key, StatusBarNotification notification) {
+            synchronized (mNotifications) {
+                if (!mNotifications.containsKey(key)) {
+                    throw new IllegalArgumentException("updateNotification key not found: " + key);
+                }
+                mNotifications.put(key, notification);
+                if (mBar != null) {
+                    try {
+                        mBar.updateNotification(key, notification);
+                    } catch (RemoteException ex) {
+                    }
+                }
+            }
+        }
+
+        @Override
+        public void removeNotification(IBinder key) {
+            synchronized (mNotifications) {
+                final StatusBarNotification n = mNotifications.remove(key);
+                if (n == null) {
+                    Slog.e(TAG, "removeNotification key not found: " + key);
+                    return;
+                }
+                if (mBar != null) {
+                    try {
+                        mBar.removeNotification(key);
+                    } catch (RemoteException ex) {
+                    }
+                }
+            }
+        }
+    };
+
+    // ================================================================================
+    // From IStatusBarService
+    // ================================================================================
+    @Override
+    public void expandNotificationsPanel() {
+        enforceExpandStatusBar();
+
+        if (mBar != null) {
+            try {
+                mBar.animateExpandNotificationsPanel();
+            } catch (RemoteException ex) {
+            }
+        }
+    }
+
+    @Override
+    public void collapsePanels() {
+        enforceExpandStatusBar();
+
+        if (mBar != null) {
+            try {
+                mBar.animateCollapsePanels();
+            } catch (RemoteException ex) {
+            }
+        }
+    }
+
+    @Override
+    public void expandSettingsPanel() {
+        enforceExpandStatusBar();
+
+        if (mBar != null) {
+            try {
+                mBar.animateExpandSettingsPanel();
+            } catch (RemoteException ex) {
+            }
+        }
+    }
+
+    @Override
+    public void disable(int what, IBinder token, String pkg) {
+        disableInternal(mCurrentUserId, what, token, pkg);
+    }
+
+    private void disableInternal(int userId, int what, IBinder token, String pkg) {
+        enforceStatusBar();
+
+        synchronized (mLock) {
+            disableLocked(userId, what, token, pkg);
+        }
+    }
+
+    private void disableLocked(int userId, int what, IBinder token, String pkg) {
+        // It's important that the the callback and the call to mBar get done
+        // in the same order when multiple threads are calling this function
+        // so they are paired correctly.  The messages on the handler will be
+        // handled in the order they were enqueued, but will be outside the lock.
+        manageDisableListLocked(userId, what, token, pkg);
+
+        // Ensure state for the current user is applied, even if passed a non-current user.
+        final int net = gatherDisableActionsLocked(mCurrentUserId);
+        if (net != mDisabled) {
+            mDisabled = net;
+            mHandler.post(new Runnable() {
+                    public void run() {
+                        mNotificationDelegate.onSetDisabled(net);
+                    }
+                });
+            if (mBar != null) {
+                try {
+                    mBar.disable(net);
+                } catch (RemoteException ex) {
+                }
+            }
+        }
+    }
+
+    @Override
+    public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
+            String contentDescription) {
+        enforceStatusBar();
+
+        synchronized (mIcons) {
+            int index = mIcons.getSlotIndex(slot);
+            if (index < 0) {
+                throw new SecurityException("invalid status bar icon slot: " + slot);
+            }
+
+            StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.OWNER, iconId,
+                    iconLevel, 0,
+                    contentDescription);
+            //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
+            mIcons.setIcon(index, icon);
+
+            if (mBar != null) {
+                try {
+                    mBar.setIcon(index, icon);
+                } catch (RemoteException ex) {
+                }
+            }
+        }
+    }
+
+    @Override
+    public void setIconVisibility(String slot, boolean visible) {
+        enforceStatusBar();
+
+        synchronized (mIcons) {
+            int index = mIcons.getSlotIndex(slot);
+            if (index < 0) {
+                throw new SecurityException("invalid status bar icon slot: " + slot);
+            }
+
+            StatusBarIcon icon = mIcons.getIcon(index);
+            if (icon == null) {
+                return;
+            }
+
+            if (icon.visible != visible) {
+                icon.visible = visible;
+
+                if (mBar != null) {
+                    try {
+                        mBar.setIcon(index, icon);
+                    } catch (RemoteException ex) {
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public void removeIcon(String slot) {
+        enforceStatusBar();
+
+        synchronized (mIcons) {
+            int index = mIcons.getSlotIndex(slot);
+            if (index < 0) {
+                throw new SecurityException("invalid status bar icon slot: " + slot);
+            }
+
+            mIcons.removeIcon(index);
+
+            if (mBar != null) {
+                try {
+                    mBar.removeIcon(index);
+                } catch (RemoteException ex) {
+                }
+            }
+        }
+    }
+
+    /** 
+     * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
+     * response to a window with FLAG_NEEDS_MENU_KEY set.
+     */
+    @Override
+    public void topAppWindowChanged(final boolean menuVisible) {
+        enforceStatusBar();
+
+        if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
+
+        synchronized(mLock) {
+            mMenuVisible = menuVisible;
+            mHandler.post(new Runnable() {
+                    public void run() {
+                        if (mBar != null) {
+                            try {
+                                mBar.topAppWindowChanged(menuVisible);
+                            } catch (RemoteException ex) {
+                            }
+                        }
+                    }
+                });
+        }
+    }
+
+    @Override
+    public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
+        enforceStatusBar();
+
+        if (SPEW) {
+            Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
+        }
+
+        synchronized(mLock) {
+            // In case of IME change, we need to call up setImeWindowStatus() regardless of
+            // mImeWindowVis because mImeWindowVis may not have been set to false when the
+            // previous IME was destroyed.
+            mImeWindowVis = vis;
+            mImeBackDisposition = backDisposition;
+            mImeToken = token;
+            mHandler.post(new Runnable() {
+                public void run() {
+                    if (mBar != null) {
+                        try {
+                            mBar.setImeWindowStatus(token, vis, backDisposition);
+                        } catch (RemoteException ex) {
+                        }
+                    }
+                }
+            });
+        }
+    }
+
+    @Override
+    public void setSystemUiVisibility(int vis, int mask) {
+        // also allows calls from window manager which is in this process.
+        enforceStatusBarService();
+
+        if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
+
+        synchronized (mLock) {
+            updateUiVisibilityLocked(vis, mask);
+            disableLocked(
+                    mCurrentUserId,
+                    vis & StatusBarManager.DISABLE_MASK,
+                    mSysUiVisToken,
+                    "WindowManager.LayoutParams");
+        }
+    }
+
+    private void updateUiVisibilityLocked(final int vis, final int mask) {
+        if (mSystemUiVisibility != vis) {
+            mSystemUiVisibility = vis;
+            mHandler.post(new Runnable() {
+                    public void run() {
+                        if (mBar != null) {
+                            try {
+                                mBar.setSystemUiVisibility(vis, mask);
+                            } catch (RemoteException ex) {
+                            }
+                        }
+                    }
+                });
+        }
+    }
+
+    @Override
+    public void setHardKeyboardEnabled(final boolean enabled) {
+        mHandler.post(new Runnable() {
+            public void run() {
+                mWindowManager.setHardKeyboardEnabled(enabled);
+            }
+        });
+    }
+
+    @Override
+    public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
+        mHandler.post(new Runnable() {
+            public void run() {
+                if (mBar != null) {
+                    try {
+                        mBar.setHardKeyboardStatus(available, enabled);
+                    } catch (RemoteException ex) {
+                    }
+                }
+            }
+        });
+    }
+
+    @Override
+    public void toggleRecentApps() {
+        if (mBar != null) {
+            try {
+                mBar.toggleRecentApps();
+            } catch (RemoteException ex) {}
+        }
+    }
+
+    @Override
+    public void preloadRecentApps() {
+        if (mBar != null) {
+            try {
+                mBar.preloadRecentApps();
+            } catch (RemoteException ex) {}
+        }
+    }
+
+    @Override
+    public void cancelPreloadRecentApps() {
+        if (mBar != null) {
+            try {
+                mBar.cancelPreloadRecentApps();
+            } catch (RemoteException ex) {}
+        }
+    }
+
+    @Override
+    public void setCurrentUser(int newUserId) {
+        if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
+        mCurrentUserId = newUserId;
+    }
+
+    @Override
+    public void setWindowState(int window, int state) {
+        if (mBar != null) {
+            try {
+                mBar.setWindowState(window, state);
+            } catch (RemoteException ex) {}
+        }
+    }
+
+    private void enforceStatusBar() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
+                "StatusBarManagerService");
+    }
+
+    private void enforceExpandStatusBar() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
+                "StatusBarManagerService");
+    }
+
+    private void enforceStatusBarService() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
+                "StatusBarManagerService");
+    }
+
+    // ================================================================================
+    // Callbacks from the status bar service.
+    // ================================================================================
+    @Override
+    public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
+            List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
+            int switches[], List<IBinder> binders) {
+        enforceStatusBarService();
+
+        Slog.i(TAG, "registerStatusBar bar=" + bar);
+        mBar = bar;
+        synchronized (mIcons) {
+            iconList.copyFrom(mIcons);
+        }
+        synchronized (mNotifications) {
+            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
+                notificationKeys.add(e.getKey());
+                notifications.add(e.getValue());
+            }
+        }
+        synchronized (mLock) {
+            switches[0] = gatherDisableActionsLocked(mCurrentUserId);
+            switches[1] = mSystemUiVisibility;
+            switches[2] = mMenuVisible ? 1 : 0;
+            switches[3] = mImeWindowVis;
+            switches[4] = mImeBackDisposition;
+            binders.add(mImeToken);
+        }
+        switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
+        switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
+    }
+
+    /**
+     * The status bar service should call this each time the user brings the panel from
+     * invisible to visible in order to clear the notification light.
+     */
+    @Override
+    public void onPanelRevealed() {
+        enforceStatusBarService();
+        long identity = Binder.clearCallingIdentity();
+        try {
+            // tell the notification manager to turn off the lights.
+            mNotificationDelegate.onPanelRevealed();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
+    public void onNotificationClick(String pkg, String tag, int id) {
+        enforceStatusBarService();
+        long identity = Binder.clearCallingIdentity();
+        try {
+            mNotificationDelegate.onNotificationClick(pkg, tag, id);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
+    public void onNotificationError(String pkg, String tag, int id,
+            int uid, int initialPid, String message) {
+        enforceStatusBarService();
+        long identity = Binder.clearCallingIdentity();
+        try {
+            // WARNING: this will call back into us to do the remove.  Don't hold any locks.
+            mNotificationDelegate.onNotificationError(pkg, tag, id, uid, initialPid, message);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
+    public void onNotificationClear(String pkg, String tag, int id) {
+        enforceStatusBarService();
+        long identity = Binder.clearCallingIdentity();
+        try {
+            mNotificationDelegate.onNotificationClear(pkg, tag, id);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    @Override
+    public void onClearAllNotifications() {
+        enforceStatusBarService();
+        long identity = Binder.clearCallingIdentity();
+        try {
+            mNotificationDelegate.onClearAll();
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+
+    // ================================================================================
+    // Can be called from any thread
+    // ================================================================================
+
+    // lock on mDisableRecords
+    void manageDisableListLocked(int userId, int what, IBinder token, String pkg) {
+        if (SPEW) {
+            Slog.d(TAG, "manageDisableList userId=" + userId
+                    + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
+        }
+        // update the list
+        final int N = mDisableRecords.size();
+        DisableRecord tok = null;
+        int i;
+        for (i=0; i<N; i++) {
+            DisableRecord t = mDisableRecords.get(i);
+            if (t.token == token && t.userId == userId) {
+                tok = t;
+                break;
+            }
+        }
+        if (what == 0 || !token.isBinderAlive()) {
+            if (tok != null) {
+                mDisableRecords.remove(i);
+                tok.token.unlinkToDeath(tok, 0);
+            }
+        } else {
+            if (tok == null) {
+                tok = new DisableRecord();
+                tok.userId = userId;
+                try {
+                    token.linkToDeath(tok, 0);
+                }
+                catch (RemoteException ex) {
+                    return; // give up
+                }
+                mDisableRecords.add(tok);
+            }
+            tok.what = what;
+            tok.token = token;
+            tok.pkg = pkg;
+        }
+    }
+
+    // lock on mDisableRecords
+    int gatherDisableActionsLocked(int userId) {
+        final int N = mDisableRecords.size();
+        // gather the new net flags
+        int net = 0;
+        for (int i=0; i<N; i++) {
+            final DisableRecord rec = mDisableRecords.get(i);
+            if (rec.userId == userId) {
+                net |= rec.what;
+            }
+        }
+        return net;
+    }
+
+    // ================================================================================
+    // Always called from UI thread
+    // ================================================================================
+
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump StatusBar from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        synchronized (mIcons) {
+            mIcons.dump(pw);
+        }
+
+        synchronized (mNotifications) {
+            int i=0;
+            pw.println("Notification list:");
+            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
+                pw.printf("  %2d: %s\n", i, e.getValue().toString());
+                i++;
+            }
+        }
+
+        synchronized (mLock) {
+            pw.println("  mDisabled=0x" + Integer.toHexString(mDisabled));
+            final int N = mDisableRecords.size();
+            pw.println("  mDisableRecords.size=" + N);
+            for (int i=0; i<N; i++) {
+                DisableRecord tok = mDisableRecords.get(i);
+                pw.println("    [" + i + "] userId=" + tok.userId
+                                + " what=0x" + Integer.toHexString(tok.what)
+                                + " pkg=" + tok.pkg
+                                + " token=" + tok.token);
+            }
+        }
+    }
+
+    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
+                    || Intent.ACTION_SCREEN_OFF.equals(action)) {
+                collapsePanels();
+            }
+            /*
+            else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
+                updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
+                        intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
+                        intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
+                        intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
+            }
+            else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
+                updateResources();
+            }
+            */
+        }
+    };
+
+}
diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorInternal.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorInternal.java
new file mode 100644
index 0000000..a91a81b
--- /dev/null
+++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorInternal.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (c) 2013, 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.storage;
+
+public interface DeviceStorageMonitorInternal {
+    boolean isMemoryLow();
+    long getMemoryLowThreshold();
+    void checkMemory();
+}
+
diff --git a/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
new file mode 100644
index 0000000..43a99e0
--- /dev/null
+++ b/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
@@ -0,0 +1,505 @@
+/*
+ * Copyright (C) 2007-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.server.storage;
+
+import com.android.server.EventLogTags;
+import com.android.server.SystemService;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.IPackageDataObserver;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageManager;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.FileObserver;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.StatFs;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.storage.StorageManager;
+import android.provider.Settings;
+import android.text.format.Formatter;
+import android.util.EventLog;
+import android.util.Slog;
+import android.util.TimeUtils;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * This class implements a service to monitor the amount of disk
+ * storage space on the device.  If the free storage on device is less
+ * than a tunable threshold value (a secure settings parameter;
+ * default 10%) a low memory notification is displayed to alert the
+ * user. If the user clicks on the low memory notification the
+ * Application Manager application gets launched to let the user free
+ * storage space.
+ *
+ * Event log events: A low memory event with the free storage on
+ * device in bytes is logged to the event log when the device goes low
+ * on storage space.  The amount of free storage on the device is
+ * periodically logged to the event log. The log interval is a secure
+ * settings parameter with a default value of 12 hours.  When the free
+ * storage differential goes below a threshold (again a secure
+ * settings parameter with a default value of 2MB), the free memory is
+ * logged to the event log.
+ */
+public class DeviceStorageMonitorService extends SystemService {
+    static final String TAG = "DeviceStorageMonitorService";
+
+    static final boolean DEBUG = false;
+    static final boolean localLOGV = false;
+
+    static final int DEVICE_MEMORY_WHAT = 1;
+    private static final int MONITOR_INTERVAL = 1; //in minutes
+    private static final int LOW_MEMORY_NOTIFICATION_ID = 1;
+
+    private static final int DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES = 12*60; //in minutes
+    private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB
+    private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000;
+
+    private long mFreeMem;  // on /data
+    private long mFreeMemAfterLastCacheClear;  // on /data
+    private long mLastReportedFreeMem;
+    private long mLastReportedFreeMemTime;
+    boolean mLowMemFlag=false;
+    private boolean mMemFullFlag=false;
+    private final ContentResolver mResolver;
+    private final long mTotalMemory;  // on /data
+    private final StatFs mDataFileStats;
+    private final StatFs mSystemFileStats;
+    private final StatFs mCacheFileStats;
+
+    private static final File DATA_PATH = Environment.getDataDirectory();
+    private static final File SYSTEM_PATH = Environment.getRootDirectory();
+    private static final File CACHE_PATH = Environment.getDownloadCacheDirectory();
+
+    private long mThreadStartTime = -1;
+    boolean mClearSucceeded = false;
+    boolean mClearingCache;
+    private final Intent mStorageLowIntent;
+    private final Intent mStorageOkIntent;
+    private final Intent mStorageFullIntent;
+    private final Intent mStorageNotFullIntent;
+    private CachePackageDataObserver mClearCacheObserver;
+    private CacheFileDeletedObserver mCacheFileDeletedObserver;
+    private static final int _TRUE = 1;
+    private static final int _FALSE = 0;
+    // This is the raw threshold that has been set at which we consider
+    // storage to be low.
+    long mMemLowThreshold;
+    // This is the threshold at which we start trying to flush caches
+    // to get below the low threshold limit.  It is less than the low
+    // threshold; we will allow storage to get a bit beyond the limit
+    // before flushing and checking if we are actually low.
+    private long mMemCacheStartTrimThreshold;
+    // This is the threshold that we try to get to when deleting cache
+    // files.  This is greater than the low threshold so that we will flush
+    // more files than absolutely needed, to reduce the frequency that
+    // flushing takes place.
+    private long mMemCacheTrimToThreshold;
+    private long mMemFullThreshold;
+
+    /**
+     * This string is used for ServiceManager access to this class.
+     */
+    static final String SERVICE = "devicestoragemonitor";
+
+    /**
+    * Handler that checks the amount of disk space on the device and sends a
+    * notification if the device runs low on disk space
+    */
+    private final Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            //don't handle an invalid message
+            if (msg.what != DEVICE_MEMORY_WHAT) {
+                Slog.e(TAG, "Will not process invalid message");
+                return;
+            }
+            checkMemory(msg.arg1 == _TRUE);
+        }
+    };
+
+    private class CachePackageDataObserver extends IPackageDataObserver.Stub {
+        public void onRemoveCompleted(String packageName, boolean succeeded) {
+            mClearSucceeded = succeeded;
+            mClearingCache = false;
+            if(localLOGV) Slog.i(TAG, " Clear succeeded:"+mClearSucceeded
+                    +", mClearingCache:"+mClearingCache+" Forcing memory check");
+            postCheckMemoryMsg(false, 0);
+        }
+    }
+
+    private void restatDataDir() {
+        try {
+            mDataFileStats.restat(DATA_PATH.getAbsolutePath());
+            mFreeMem = (long) mDataFileStats.getAvailableBlocks() *
+                mDataFileStats.getBlockSize();
+        } catch (IllegalArgumentException e) {
+            // use the old value of mFreeMem
+        }
+        // Allow freemem to be overridden by debug.freemem for testing
+        String debugFreeMem = SystemProperties.get("debug.freemem");
+        if (!"".equals(debugFreeMem)) {
+            mFreeMem = Long.parseLong(debugFreeMem);
+        }
+        // Read the log interval from secure settings
+        long freeMemLogInterval = Settings.Global.getLong(mResolver,
+                Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
+                DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000;
+        //log the amount of free memory in event log
+        long currTime = SystemClock.elapsedRealtime();
+        if((mLastReportedFreeMemTime == 0) ||
+           (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) {
+            mLastReportedFreeMemTime = currTime;
+            long mFreeSystem = -1, mFreeCache = -1;
+            try {
+                mSystemFileStats.restat(SYSTEM_PATH.getAbsolutePath());
+                mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() *
+                    mSystemFileStats.getBlockSize();
+            } catch (IllegalArgumentException e) {
+                // ignore; report -1
+            }
+            try {
+                mCacheFileStats.restat(CACHE_PATH.getAbsolutePath());
+                mFreeCache = (long) mCacheFileStats.getAvailableBlocks() *
+                    mCacheFileStats.getBlockSize();
+            } catch (IllegalArgumentException e) {
+                // ignore; report -1
+            }
+            EventLog.writeEvent(EventLogTags.FREE_STORAGE_LEFT,
+                                mFreeMem, mFreeSystem, mFreeCache);
+        }
+        // Read the reporting threshold from secure settings
+        long threshold = Settings.Global.getLong(mResolver,
+                Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
+                DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD);
+        // If mFree changed significantly log the new value
+        long delta = mFreeMem - mLastReportedFreeMem;
+        if (delta > threshold || delta < -threshold) {
+            mLastReportedFreeMem = mFreeMem;
+            EventLog.writeEvent(EventLogTags.FREE_STORAGE_CHANGED, mFreeMem);
+        }
+    }
+
+    private void clearCache() {
+        if (mClearCacheObserver == null) {
+            // Lazy instantiation
+            mClearCacheObserver = new CachePackageDataObserver();
+        }
+        mClearingCache = true;
+        try {
+            if (localLOGV) Slog.i(TAG, "Clearing cache");
+            IPackageManager.Stub.asInterface(ServiceManager.getService("package")).
+                    freeStorageAndNotify(mMemCacheTrimToThreshold, mClearCacheObserver);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Failed to get handle for PackageManger Exception: "+e);
+            mClearingCache = false;
+            mClearSucceeded = false;
+        }
+    }
+
+    void checkMemory(boolean checkCache) {
+        //if the thread that was started to clear cache is still running do nothing till its
+        //finished clearing cache. Ideally this flag could be modified by clearCache
+        // and should be accessed via a lock but even if it does this test will fail now and
+        //hopefully the next time this flag will be set to the correct value.
+        if(mClearingCache) {
+            if(localLOGV) Slog.i(TAG, "Thread already running just skip");
+            //make sure the thread is not hung for too long
+            long diffTime = System.currentTimeMillis() - mThreadStartTime;
+            if(diffTime > (10*60*1000)) {
+                Slog.w(TAG, "Thread that clears cache file seems to run for ever");
+            }
+        } else {
+            restatDataDir();
+            if (localLOGV)  Slog.v(TAG, "freeMemory="+mFreeMem);
+
+            //post intent to NotificationManager to display icon if necessary
+            if (mFreeMem < mMemLowThreshold) {
+                if (checkCache) {
+                    // We are allowed to clear cache files at this point to
+                    // try to get down below the limit, because this is not
+                    // the initial call after a cache clear has been attempted.
+                    // In this case we will try a cache clear if our free
+                    // space has gone below the cache clear limit.
+                    if (mFreeMem < mMemCacheStartTrimThreshold) {
+                        // We only clear the cache if the free storage has changed
+                        // a significant amount since the last time.
+                        if ((mFreeMemAfterLastCacheClear-mFreeMem)
+                                >= ((mMemLowThreshold-mMemCacheStartTrimThreshold)/4)) {
+                            // See if clearing cache helps
+                            // Note that clearing cache is asynchronous and so we do a
+                            // memory check again once the cache has been cleared.
+                            mThreadStartTime = System.currentTimeMillis();
+                            mClearSucceeded = false;
+                            clearCache();
+                        }
+                    }
+                } else {
+                    // This is a call from after clearing the cache.  Note
+                    // the amount of free storage at this point.
+                    mFreeMemAfterLastCacheClear = mFreeMem;
+                    if (!mLowMemFlag) {
+                        // We tried to clear the cache, but that didn't get us
+                        // below the low storage limit.  Tell the user.
+                        Slog.i(TAG, "Running low on memory. Sending notification");
+                        sendNotification();
+                        mLowMemFlag = true;
+                    } else {
+                        if (localLOGV) Slog.v(TAG, "Running low on memory " +
+                                "notification already sent. do nothing");
+                    }
+                }
+            } else {
+                mFreeMemAfterLastCacheClear = mFreeMem;
+                if (mLowMemFlag) {
+                    Slog.i(TAG, "Memory available. Cancelling notification");
+                    cancelNotification();
+                    mLowMemFlag = false;
+                }
+            }
+            if (mFreeMem < mMemFullThreshold) {
+                if (!mMemFullFlag) {
+                    sendFullNotification();
+                    mMemFullFlag = true;
+                }
+            } else {
+                if (mMemFullFlag) {
+                    cancelFullNotification();
+                    mMemFullFlag = false;
+                }
+            }
+        }
+        if(localLOGV) Slog.i(TAG, "Posting Message again");
+        //keep posting messages to itself periodically
+        postCheckMemoryMsg(true, DEFAULT_CHECK_INTERVAL);
+    }
+
+    void postCheckMemoryMsg(boolean clearCache, long delay) {
+        // Remove queued messages
+        mHandler.removeMessages(DEVICE_MEMORY_WHAT);
+        mHandler.sendMessageDelayed(mHandler.obtainMessage(DEVICE_MEMORY_WHAT,
+                clearCache ?_TRUE : _FALSE, 0),
+                delay);
+    }
+
+    public DeviceStorageMonitorService(Context context) {
+        super(context);
+        mLastReportedFreeMemTime = 0;
+        mResolver = context.getContentResolver();
+        //create StatFs object
+        mDataFileStats = new StatFs(DATA_PATH.getAbsolutePath());
+        mSystemFileStats = new StatFs(SYSTEM_PATH.getAbsolutePath());
+        mCacheFileStats = new StatFs(CACHE_PATH.getAbsolutePath());
+        //initialize total storage on device
+        mTotalMemory = (long)mDataFileStats.getBlockCount() *
+                        mDataFileStats.getBlockSize();
+        mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW);
+        mStorageLowIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK);
+        mStorageOkIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        mStorageFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_FULL);
+        mStorageFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+        mStorageNotFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_NOT_FULL);
+        mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+    }
+
+    /**
+    * Initializes the disk space threshold value and posts an empty message to
+    * kickstart the process.
+    */
+    @Override
+    public void onStart() {
+        // cache storage thresholds
+        final StorageManager sm = StorageManager.from(getContext());
+        mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH);
+        mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH);
+
+        mMemCacheStartTrimThreshold = ((mMemLowThreshold*3)+mMemFullThreshold)/4;
+        mMemCacheTrimToThreshold = mMemLowThreshold
+                + ((mMemLowThreshold-mMemCacheStartTrimThreshold)*2);
+        mFreeMemAfterLastCacheClear = mTotalMemory;
+        checkMemory(true);
+
+        mCacheFileDeletedObserver = new CacheFileDeletedObserver();
+        mCacheFileDeletedObserver.startWatching();
+
+        publishBinderService(SERVICE, mRemoteService);
+        publishLocalService(DeviceStorageMonitorInternal.class, mLocalService);
+    }
+
+    private final DeviceStorageMonitorInternal mLocalService = new DeviceStorageMonitorInternal() {
+        @Override
+        public void checkMemory() {
+            // force an early check
+            postCheckMemoryMsg(true, 0);
+        }
+
+        @Override
+        public boolean isMemoryLow() {
+            return mLowMemFlag;
+        }
+
+        @Override
+        public long getMemoryLowThreshold() {
+            return mMemLowThreshold;
+        }
+    };
+
+    private final IBinder mRemoteService = new Binder() {
+        @Override
+        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+
+                pw.println("Permission Denial: can't dump " + SERVICE + " from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            dumpImpl(pw);
+        }
+    };
+
+    void dumpImpl(PrintWriter pw) {
+        final Context context = getContext();
+
+        pw.println("Current DeviceStorageMonitor state:");
+
+        pw.print("  mFreeMem="); pw.print(Formatter.formatFileSize(context, mFreeMem));
+        pw.print(" mTotalMemory=");
+        pw.println(Formatter.formatFileSize(context, mTotalMemory));
+
+        pw.print("  mFreeMemAfterLastCacheClear=");
+        pw.println(Formatter.formatFileSize(context, mFreeMemAfterLastCacheClear));
+
+        pw.print("  mLastReportedFreeMem=");
+        pw.print(Formatter.formatFileSize(context, mLastReportedFreeMem));
+        pw.print(" mLastReportedFreeMemTime=");
+        TimeUtils.formatDuration(mLastReportedFreeMemTime, SystemClock.elapsedRealtime(), pw);
+        pw.println();
+
+        pw.print("  mLowMemFlag="); pw.print(mLowMemFlag);
+        pw.print(" mMemFullFlag="); pw.println(mMemFullFlag);
+
+        pw.print("  mClearSucceeded="); pw.print(mClearSucceeded);
+        pw.print(" mClearingCache="); pw.println(mClearingCache);
+
+        pw.print("  mMemLowThreshold=");
+        pw.print(Formatter.formatFileSize(context, mMemLowThreshold));
+        pw.print(" mMemFullThreshold=");
+        pw.println(Formatter.formatFileSize(context, mMemFullThreshold));
+
+        pw.print("  mMemCacheStartTrimThreshold=");
+        pw.print(Formatter.formatFileSize(context, mMemCacheStartTrimThreshold));
+        pw.print(" mMemCacheTrimToThreshold=");
+        pw.println(Formatter.formatFileSize(context, mMemCacheTrimToThreshold));
+    }
+
+    /**
+    * This method sends a notification to NotificationManager to display
+    * an error dialog indicating low disk space and launch the Installer
+    * application
+    */
+    private void sendNotification() {
+        final Context context = getContext();
+        if(localLOGV) Slog.i(TAG, "Sending low memory notification");
+        //log the event to event log with the amount of free storage(in bytes) left on the device
+        EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
+        //  Pack up the values and broadcast them to everyone
+        Intent lowMemIntent = new Intent(Environment.isExternalStorageEmulated()
+                ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS
+                : Intent.ACTION_MANAGE_PACKAGE_STORAGE);
+        lowMemIntent.putExtra("memory", mFreeMem);
+        lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        NotificationManager mNotificationMgr =
+                (NotificationManager)context.getSystemService(
+                        Context.NOTIFICATION_SERVICE);
+        CharSequence title = context.getText(
+                com.android.internal.R.string.low_internal_storage_view_title);
+        CharSequence details = context.getText(
+                com.android.internal.R.string.low_internal_storage_view_text);
+        PendingIntent intent = PendingIntent.getActivityAsUser(context, 0,  lowMemIntent, 0,
+                null, UserHandle.CURRENT);
+        Notification notification = new Notification();
+        notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
+        notification.tickerText = title;
+        notification.flags |= Notification.FLAG_NO_CLEAR;
+        notification.setLatestEventInfo(context, title, details, intent);
+        mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification,
+                UserHandle.ALL);
+        context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
+    }
+
+    /**
+     * Cancels low storage notification and sends OK intent.
+     */
+    private void cancelNotification() {
+        final Context context = getContext();
+        if(localLOGV) Slog.i(TAG, "Canceling low memory notification");
+        NotificationManager mNotificationMgr =
+                (NotificationManager)context.getSystemService(
+                        Context.NOTIFICATION_SERVICE);
+        //cancel notification since memory has been freed
+        mNotificationMgr.cancelAsUser(null, LOW_MEMORY_NOTIFICATION_ID, UserHandle.ALL);
+
+        context.removeStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
+        context.sendBroadcastAsUser(mStorageOkIntent, UserHandle.ALL);
+    }
+
+    /**
+     * Send a notification when storage is full.
+     */
+    private void sendFullNotification() {
+        if(localLOGV) Slog.i(TAG, "Sending memory full notification");
+        getContext().sendStickyBroadcastAsUser(mStorageFullIntent, UserHandle.ALL);
+    }
+
+    /**
+     * Cancels memory full notification and sends "not full" intent.
+     */
+    private void cancelFullNotification() {
+        if(localLOGV) Slog.i(TAG, "Canceling memory full notification");
+        getContext().removeStickyBroadcastAsUser(mStorageFullIntent, UserHandle.ALL);
+        getContext().sendBroadcastAsUser(mStorageNotFullIntent, UserHandle.ALL);
+    }
+
+    private static class CacheFileDeletedObserver extends FileObserver {
+        public CacheFileDeletedObserver() {
+            super(Environment.getDownloadCacheDirectory().getAbsolutePath(), FileObserver.DELETE);
+        }
+
+        @Override
+        public void onEvent(int event, String path) {
+            EventLogTags.writeCacheFileDeleted(path);
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/twilight/TwilightListener.java b/services/core/java/com/android/server/twilight/TwilightListener.java
new file mode 100644
index 0000000..29ead44
--- /dev/null
+++ b/services/core/java/com/android/server/twilight/TwilightListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2013 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.twilight;
+
+public interface TwilightListener {
+    void onTwilightStateChanged();
+}
\ No newline at end of file
diff --git a/services/core/java/com/android/server/twilight/TwilightManager.java b/services/core/java/com/android/server/twilight/TwilightManager.java
new file mode 100644
index 0000000..b3de58b
--- /dev/null
+++ b/services/core/java/com/android/server/twilight/TwilightManager.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2013 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.twilight;
+
+import android.os.Handler;
+
+public interface TwilightManager {
+    void registerListener(TwilightListener listener, Handler handler);
+    TwilightState getCurrentState();
+}
diff --git a/services/core/java/com/android/server/twilight/TwilightService.java b/services/core/java/com/android/server/twilight/TwilightService.java
new file mode 100644
index 0000000..a71961c
--- /dev/null
+++ b/services/core/java/com/android/server/twilight/TwilightService.java
@@ -0,0 +1,471 @@
+/*
+ * 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.server.twilight;
+
+import com.android.server.SystemService;
+import com.android.server.TwilightCalculator;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.location.Criteria;
+import android.location.Location;
+import android.location.LocationListener;
+import android.location.LocationManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.os.SystemClock;
+import android.text.format.DateUtils;
+import android.text.format.Time;
+import android.util.Slog;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import libcore.util.Objects;
+
+/**
+ * Figures out whether it's twilight time based on the user's location.
+ *
+ * Used by the UI mode manager and other components to adjust night mode
+ * effects based on sunrise and sunset.
+ */
+public final class TwilightService extends SystemService {
+    static final String TAG = "TwilightService";
+    static final boolean DEBUG = false;
+    static final String ACTION_UPDATE_TWILIGHT_STATE =
+            "com.android.server.action.UPDATE_TWILIGHT_STATE";
+
+    final Object mLock = new Object();
+
+    AlarmManager mAlarmManager;
+    LocationManager mLocationManager;
+    LocationHandler mLocationHandler;
+
+    final ArrayList<TwilightListenerRecord> mListeners =
+            new ArrayList<TwilightListenerRecord>();
+
+    TwilightState mTwilightState;
+
+    public TwilightService(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onStart() {
+        mAlarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
+        mLocationManager = (LocationManager) getContext().getSystemService(
+                Context.LOCATION_SERVICE);
+        mLocationHandler = new LocationHandler();
+
+        IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
+        filter.addAction(Intent.ACTION_TIME_CHANGED);
+        filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
+        filter.addAction(ACTION_UPDATE_TWILIGHT_STATE);
+        getContext().registerReceiver(mUpdateLocationReceiver, filter);
+
+        publishLocalService(TwilightManager.class, mService);
+    }
+
+    private static class TwilightListenerRecord implements Runnable {
+        private final TwilightListener mListener;
+        private final Handler mHandler;
+
+        public TwilightListenerRecord(TwilightListener listener, Handler handler) {
+            mListener = listener;
+            mHandler = handler;
+        }
+
+        public void postUpdate() {
+            mHandler.post(this);
+        }
+
+        @Override
+        public void run() {
+            mListener.onTwilightStateChanged();
+        }
+
+    }
+
+    private final TwilightManager mService = new TwilightManager() {
+        /**
+         * Gets the current twilight state.
+         *
+         * @return The current twilight state, or null if no information is available.
+         */
+        @Override
+        public TwilightState getCurrentState() {
+            synchronized (mLock) {
+                return mTwilightState;
+            }
+        }
+
+        /**
+         * Listens for twilight time.
+         *
+         * @param listener The listener.
+         */
+        @Override
+        public void registerListener(TwilightListener listener, Handler handler) {
+            synchronized (mLock) {
+                mListeners.add(new TwilightListenerRecord(listener, handler));
+
+                if (mListeners.size() == 1) {
+                    mLocationHandler.enableLocationUpdates();
+                }
+            }
+        }
+    };
+
+    private void setTwilightState(TwilightState state) {
+        synchronized (mLock) {
+            if (!Objects.equal(mTwilightState, state)) {
+                if (DEBUG) {
+                    Slog.d(TAG, "Twilight state changed: " + state);
+                }
+
+                mTwilightState = state;
+
+                final int listenerLen = mListeners.size();
+                for (int i = 0; i < listenerLen; i++) {
+                    mListeners.get(i).postUpdate();
+                }
+            }
+        }
+    }
+
+    // The user has moved if the accuracy circles of the two locations don't overlap.
+    private static boolean hasMoved(Location from, Location to) {
+        if (to == null) {
+            return false;
+        }
+
+        if (from == null) {
+            return true;
+        }
+
+        // if new location is older than the current one, the device hasn't moved.
+        if (to.getElapsedRealtimeNanos() < from.getElapsedRealtimeNanos()) {
+            return false;
+        }
+
+        // Get the distance between the two points.
+        float distance = from.distanceTo(to);
+
+        // Get the total accuracy radius for both locations.
+        float totalAccuracy = from.getAccuracy() + to.getAccuracy();
+
+        // If the distance is greater than the combined accuracy of the two
+        // points then they can't overlap and hence the user has moved.
+        return distance >= totalAccuracy;
+    }
+
+    private final class LocationHandler extends Handler {
+        private static final int MSG_ENABLE_LOCATION_UPDATES = 1;
+        private static final int MSG_GET_NEW_LOCATION_UPDATE = 2;
+        private static final int MSG_PROCESS_NEW_LOCATION = 3;
+        private static final int MSG_DO_TWILIGHT_UPDATE = 4;
+
+        private static final long LOCATION_UPDATE_MS = 24 * DateUtils.HOUR_IN_MILLIS;
+        private static final long MIN_LOCATION_UPDATE_MS = 30 * DateUtils.MINUTE_IN_MILLIS;
+        private static final float LOCATION_UPDATE_DISTANCE_METER = 1000 * 20;
+        private static final long LOCATION_UPDATE_ENABLE_INTERVAL_MIN = 5000;
+        private static final long LOCATION_UPDATE_ENABLE_INTERVAL_MAX =
+                15 * DateUtils.MINUTE_IN_MILLIS;
+        private static final double FACTOR_GMT_OFFSET_LONGITUDE =
+                1000.0 * 360.0 / DateUtils.DAY_IN_MILLIS;
+
+        private boolean mPassiveListenerEnabled;
+        private boolean mNetworkListenerEnabled;
+        private boolean mDidFirstInit;
+        private long mLastNetworkRegisterTime = -MIN_LOCATION_UPDATE_MS;
+        private long mLastUpdateInterval;
+        private Location mLocation;
+        private final TwilightCalculator mTwilightCalculator = new TwilightCalculator();
+
+        public void processNewLocation(Location location) {
+            Message msg = obtainMessage(MSG_PROCESS_NEW_LOCATION, location);
+            sendMessage(msg);
+        }
+
+        public void enableLocationUpdates() {
+            sendEmptyMessage(MSG_ENABLE_LOCATION_UPDATES);
+        }
+
+        public void requestLocationUpdate() {
+            sendEmptyMessage(MSG_GET_NEW_LOCATION_UPDATE);
+        }
+
+        public void requestTwilightUpdate() {
+            sendEmptyMessage(MSG_DO_TWILIGHT_UPDATE);
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_PROCESS_NEW_LOCATION: {
+                    final Location location = (Location)msg.obj;
+                    final boolean hasMoved = hasMoved(mLocation, location);
+                    final boolean hasBetterAccuracy = mLocation == null
+                            || location.getAccuracy() < mLocation.getAccuracy();
+                    if (DEBUG) {
+                        Slog.d(TAG, "Processing new location: " + location
+                               + ", hasMoved=" + hasMoved
+                               + ", hasBetterAccuracy=" + hasBetterAccuracy);
+                    }
+                    if (hasMoved || hasBetterAccuracy) {
+                        setLocation(location);
+                    }
+                    break;
+                }
+
+                case MSG_GET_NEW_LOCATION_UPDATE:
+                    if (!mNetworkListenerEnabled) {
+                        // Don't do anything -- we are still trying to get a
+                        // location.
+                        return;
+                    }
+                    if ((mLastNetworkRegisterTime + MIN_LOCATION_UPDATE_MS) >=
+                            SystemClock.elapsedRealtime()) {
+                        // Don't do anything -- it hasn't been long enough
+                        // since we last requested an update.
+                        return;
+                    }
+
+                    // Unregister the current location monitor, so we can
+                    // register a new one for it to get an immediate update.
+                    mNetworkListenerEnabled = false;
+                    mLocationManager.removeUpdates(mEmptyLocationListener);
+
+                    // Fall through to re-register listener.
+                case MSG_ENABLE_LOCATION_UPDATES:
+                    // enable network provider to receive at least location updates for a given
+                    // distance.
+                    boolean networkLocationEnabled;
+                    try {
+                        networkLocationEnabled =
+                            mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+                    } catch (Exception e) {
+                        // we may get IllegalArgumentException if network location provider
+                        // does not exist or is not yet installed.
+                        networkLocationEnabled = false;
+                    }
+                    if (!mNetworkListenerEnabled && networkLocationEnabled) {
+                        mNetworkListenerEnabled = true;
+                        mLastNetworkRegisterTime = SystemClock.elapsedRealtime();
+                        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
+                                LOCATION_UPDATE_MS, 0, mEmptyLocationListener);
+
+                        if (!mDidFirstInit) {
+                            mDidFirstInit = true;
+                            if (mLocation == null) {
+                                retrieveLocation();
+                            }
+                        }
+                    }
+
+                    // enable passive provider to receive updates from location fixes (gps
+                    // and network).
+                    boolean passiveLocationEnabled;
+                    try {
+                        passiveLocationEnabled =
+                            mLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER);
+                    } catch (Exception e) {
+                        // we may get IllegalArgumentException if passive location provider
+                        // does not exist or is not yet installed.
+                        passiveLocationEnabled = false;
+                    }
+
+                    if (!mPassiveListenerEnabled && passiveLocationEnabled) {
+                        mPassiveListenerEnabled = true;
+                        mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER,
+                                0, LOCATION_UPDATE_DISTANCE_METER , mLocationListener);
+                    }
+
+                    if (!(mNetworkListenerEnabled && mPassiveListenerEnabled)) {
+                        mLastUpdateInterval *= 1.5;
+                        if (mLastUpdateInterval == 0) {
+                            mLastUpdateInterval = LOCATION_UPDATE_ENABLE_INTERVAL_MIN;
+                        } else if (mLastUpdateInterval > LOCATION_UPDATE_ENABLE_INTERVAL_MAX) {
+                            mLastUpdateInterval = LOCATION_UPDATE_ENABLE_INTERVAL_MAX;
+                        }
+                        sendEmptyMessageDelayed(MSG_ENABLE_LOCATION_UPDATES, mLastUpdateInterval);
+                    }
+                    break;
+
+                case MSG_DO_TWILIGHT_UPDATE:
+                    updateTwilightState();
+                    break;
+            }
+        }
+
+        private void retrieveLocation() {
+            Location location = null;
+            final Iterator<String> providers =
+                    mLocationManager.getProviders(new Criteria(), true).iterator();
+            while (providers.hasNext()) {
+                final Location lastKnownLocation =
+                        mLocationManager.getLastKnownLocation(providers.next());
+                // pick the most recent location
+                if (location == null || (lastKnownLocation != null &&
+                        location.getElapsedRealtimeNanos() <
+                        lastKnownLocation.getElapsedRealtimeNanos())) {
+                    location = lastKnownLocation;
+                }
+            }
+
+            // In the case there is no location available (e.g. GPS fix or network location
+            // is not available yet), the longitude of the location is estimated using the timezone,
+            // latitude and accuracy are set to get a good average.
+            if (location == null) {
+                Time currentTime = new Time();
+                currentTime.set(System.currentTimeMillis());
+                double lngOffset = FACTOR_GMT_OFFSET_LONGITUDE *
+                        (currentTime.gmtoff - (currentTime.isDst > 0 ? 3600 : 0));
+                location = new Location("fake");
+                location.setLongitude(lngOffset);
+                location.setLatitude(0);
+                location.setAccuracy(417000.0f);
+                location.setTime(System.currentTimeMillis());
+                location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
+
+                if (DEBUG) {
+                    Slog.d(TAG, "Estimated location from timezone: " + location);
+                }
+            }
+
+            setLocation(location);
+        }
+
+        private void setLocation(Location location) {
+            mLocation = location;
+            updateTwilightState();
+        }
+
+        private void updateTwilightState() {
+            if (mLocation == null) {
+                setTwilightState(null);
+                return;
+            }
+
+            final long now = System.currentTimeMillis();
+
+            // calculate yesterday's twilight
+            mTwilightCalculator.calculateTwilight(now - DateUtils.DAY_IN_MILLIS,
+                    mLocation.getLatitude(), mLocation.getLongitude());
+            final long yesterdaySunset = mTwilightCalculator.mSunset;
+
+            // calculate today's twilight
+            mTwilightCalculator.calculateTwilight(now,
+                    mLocation.getLatitude(), mLocation.getLongitude());
+            final boolean isNight = (mTwilightCalculator.mState == TwilightCalculator.NIGHT);
+            final long todaySunrise = mTwilightCalculator.mSunrise;
+            final long todaySunset = mTwilightCalculator.mSunset;
+
+            // calculate tomorrow's twilight
+            mTwilightCalculator.calculateTwilight(now + DateUtils.DAY_IN_MILLIS,
+                    mLocation.getLatitude(), mLocation.getLongitude());
+            final long tomorrowSunrise = mTwilightCalculator.mSunrise;
+
+            // set twilight state
+            TwilightState state = new TwilightState(isNight, yesterdaySunset,
+                    todaySunrise, todaySunset, tomorrowSunrise);
+            if (DEBUG) {
+                Slog.d(TAG, "Updating twilight state: " + state);
+            }
+            setTwilightState(state);
+
+            // schedule next update
+            long nextUpdate = 0;
+            if (todaySunrise == -1 || todaySunset == -1) {
+                // In the case the day or night never ends the update is scheduled 12 hours later.
+                nextUpdate = now + 12 * DateUtils.HOUR_IN_MILLIS;
+            } else {
+                // add some extra time to be on the safe side.
+                nextUpdate += DateUtils.MINUTE_IN_MILLIS;
+
+                if (now > todaySunset) {
+                    nextUpdate += tomorrowSunrise;
+                } else if (now > todaySunrise) {
+                    nextUpdate += todaySunset;
+                } else {
+                    nextUpdate += todaySunrise;
+                }
+            }
+
+            if (DEBUG) {
+                Slog.d(TAG, "Next update in " + (nextUpdate - now) + " ms");
+            }
+
+            Intent updateIntent = new Intent(ACTION_UPDATE_TWILIGHT_STATE);
+            PendingIntent pendingIntent = PendingIntent.getBroadcast(
+                    getContext(), 0, updateIntent, 0);
+            mAlarmManager.cancel(pendingIntent);
+            mAlarmManager.setExact(AlarmManager.RTC, nextUpdate, pendingIntent);
+        }
+    }
+
+    private final BroadcastReceiver mUpdateLocationReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())
+                    && !intent.getBooleanExtra("state", false)) {
+                // Airplane mode is now off!
+                mLocationHandler.requestLocationUpdate();
+                return;
+            }
+
+            // Time zone has changed or alarm expired.
+            mLocationHandler.requestTwilightUpdate();
+        }
+    };
+
+    // A LocationListener to initialize the network location provider. The location updates
+    // are handled through the passive location provider.
+    private final LocationListener mEmptyLocationListener =  new LocationListener() {
+        public void onLocationChanged(Location location) {
+        }
+
+        public void onProviderDisabled(String provider) {
+        }
+
+        public void onProviderEnabled(String provider) {
+        }
+
+        public void onStatusChanged(String provider, int status, Bundle extras) {
+        }
+    };
+
+    private final LocationListener mLocationListener = new LocationListener() {
+        public void onLocationChanged(Location location) {
+            mLocationHandler.processNewLocation(location);
+        }
+
+        public void onProviderDisabled(String provider) {
+        }
+
+        public void onProviderEnabled(String provider) {
+        }
+
+        public void onStatusChanged(String provider, int status, Bundle extras) {
+        }
+    };
+}
diff --git a/services/core/java/com/android/server/twilight/TwilightState.java b/services/core/java/com/android/server/twilight/TwilightState.java
new file mode 100644
index 0000000..91e24d7
--- /dev/null
+++ b/services/core/java/com/android/server/twilight/TwilightState.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2013 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.twilight;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+/**
+ * Describes whether it is day or night.
+ * This object is immutable.
+ */
+public class TwilightState {
+    private final boolean mIsNight;
+    private final long mYesterdaySunset;
+    private final long mTodaySunrise;
+    private final long mTodaySunset;
+    private final long mTomorrowSunrise;
+
+    TwilightState(boolean isNight,
+            long yesterdaySunset,
+            long todaySunrise, long todaySunset,
+            long tomorrowSunrise) {
+        mIsNight = isNight;
+        mYesterdaySunset = yesterdaySunset;
+        mTodaySunrise = todaySunrise;
+        mTodaySunset = todaySunset;
+        mTomorrowSunrise = tomorrowSunrise;
+    }
+
+    /**
+     * Returns true if it is currently night time.
+     */
+    public boolean isNight() {
+        return mIsNight;
+    }
+
+    /**
+     * Returns the time of yesterday's sunset in the System.currentTimeMillis() timebase,
+     * or -1 if the sun never sets.
+     */
+    public long getYesterdaySunset() {
+        return mYesterdaySunset;
+    }
+
+    /**
+     * Returns the time of today's sunrise in the System.currentTimeMillis() timebase,
+     * or -1 if the sun never rises.
+     */
+    public long getTodaySunrise() {
+        return mTodaySunrise;
+    }
+
+    /**
+     * Returns the time of today's sunset in the System.currentTimeMillis() timebase,
+     * or -1 if the sun never sets.
+     */
+    public long getTodaySunset() {
+        return mTodaySunset;
+    }
+
+    /**
+     * Returns the time of tomorrow's sunrise in the System.currentTimeMillis() timebase,
+     * or -1 if the sun never rises.
+     */
+    public long getTomorrowSunrise() {
+        return mTomorrowSunrise;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return o instanceof TwilightState && equals((TwilightState)o);
+    }
+
+    public boolean equals(TwilightState other) {
+        return other != null
+                && mIsNight == other.mIsNight
+                && mYesterdaySunset == other.mYesterdaySunset
+                && mTodaySunrise == other.mTodaySunrise
+                && mTodaySunset == other.mTodaySunset
+                && mTomorrowSunrise == other.mTomorrowSunrise;
+    }
+
+    @Override
+    public int hashCode() {
+        return 0; // don't care
+    }
+
+    @Override
+    public String toString() {
+        DateFormat f = DateFormat.getDateTimeInstance();
+        return "{TwilightState: isNight=" + mIsNight
+                + ", mYesterdaySunset=" + f.format(new Date(mYesterdaySunset))
+                + ", mTodaySunrise=" + f.format(new Date(mTodaySunrise))
+                + ", mTodaySunset=" + f.format(new Date(mTodaySunset))
+                + ", mTomorrowSunrise=" + f.format(new Date(mTomorrowSunrise))
+                + "}";
+    }
+}
diff --git a/services/java/com/android/server/updates/CarrierProvisioningUrlsInstallReceiver.java b/services/core/java/com/android/server/updates/CarrierProvisioningUrlsInstallReceiver.java
similarity index 100%
rename from services/java/com/android/server/updates/CarrierProvisioningUrlsInstallReceiver.java
rename to services/core/java/com/android/server/updates/CarrierProvisioningUrlsInstallReceiver.java
diff --git a/services/java/com/android/server/updates/CertPinInstallReceiver.java b/services/core/java/com/android/server/updates/CertPinInstallReceiver.java
similarity index 100%
rename from services/java/com/android/server/updates/CertPinInstallReceiver.java
rename to services/core/java/com/android/server/updates/CertPinInstallReceiver.java
diff --git a/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java b/services/core/java/com/android/server/updates/ConfigUpdateInstallReceiver.java
similarity index 100%
rename from services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java
rename to services/core/java/com/android/server/updates/ConfigUpdateInstallReceiver.java
diff --git a/services/java/com/android/server/updates/IntentFirewallInstallReceiver.java b/services/core/java/com/android/server/updates/IntentFirewallInstallReceiver.java
similarity index 100%
rename from services/java/com/android/server/updates/IntentFirewallInstallReceiver.java
rename to services/core/java/com/android/server/updates/IntentFirewallInstallReceiver.java
diff --git a/services/core/java/com/android/server/updates/SELinuxPolicyInstallReceiver.java b/services/core/java/com/android/server/updates/SELinuxPolicyInstallReceiver.java
new file mode 100644
index 0000000..e430814
--- /dev/null
+++ b/services/core/java/com/android/server/updates/SELinuxPolicyInstallReceiver.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2013 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.updates;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.FileUtils;
+import android.os.SELinux;
+import android.os.SystemProperties;
+import android.provider.Settings;
+import android.util.Base64;
+import android.util.Slog;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import libcore.io.ErrnoException;
+import libcore.io.IoUtils;
+import libcore.io.Libcore;
+
+public class SELinuxPolicyInstallReceiver extends ConfigUpdateInstallReceiver {
+
+    private static final String TAG = "SELinuxPolicyInstallReceiver";
+
+    private static final String sepolicyPath = "sepolicy";
+    private static final String fileContextsPath = "file_contexts";
+    private static final String propertyContextsPath = "property_contexts";
+    private static final String seappContextsPath = "seapp_contexts";
+
+    public SELinuxPolicyInstallReceiver() {
+        super("/data/security/bundle", "sepolicy_bundle", "metadata/", "version");
+    }
+
+    private void backupContexts(File contexts) {
+        new File(contexts, seappContextsPath).renameTo(
+                new File(contexts, seappContextsPath + "_backup"));
+
+        new File(contexts, propertyContextsPath).renameTo(
+                new File(contexts, propertyContextsPath + "_backup"));
+
+        new File(contexts, fileContextsPath).renameTo(
+                new File(contexts, fileContextsPath + "_backup"));
+
+        new File(contexts, sepolicyPath).renameTo(
+                new File(contexts, sepolicyPath + "_backup"));
+    }
+
+    private void copyUpdate(File contexts) {
+        new File(updateDir, seappContextsPath).renameTo(new File(contexts, seappContextsPath));
+        new File(updateDir, propertyContextsPath).renameTo(new File(contexts, propertyContextsPath));
+        new File(updateDir, fileContextsPath).renameTo(new File(contexts, fileContextsPath));
+        new File(updateDir, sepolicyPath).renameTo(new File(contexts, sepolicyPath));
+    }
+
+    private int readInt(BufferedInputStream reader) throws IOException {
+        int value = 0;
+        for (int i=0; i < 4; i++) {
+            value = (value << 8) | reader.read();
+        }
+        return value;
+    }
+
+    private int[] readChunkLengths(BufferedInputStream bundle) throws IOException {
+        int[] chunks = new int[4];
+        chunks[0] = readInt(bundle);
+        chunks[1] = readInt(bundle);
+        chunks[2] = readInt(bundle);
+        chunks[3] = readInt(bundle);
+        return chunks;
+    }
+
+    private void installFile(File destination, BufferedInputStream stream, int length)
+            throws IOException {
+        byte[] chunk = new byte[length];
+        stream.read(chunk, 0, length);
+        writeUpdate(updateDir, destination, Base64.decode(chunk, Base64.DEFAULT));
+    }
+
+    private void unpackBundle() throws IOException {
+        BufferedInputStream stream = new BufferedInputStream(new FileInputStream(updateContent));
+        try {
+            int[] chunkLengths = readChunkLengths(stream);
+            installFile(new File(updateDir, seappContextsPath), stream, chunkLengths[0]);
+            installFile(new File(updateDir, propertyContextsPath), stream, chunkLengths[1]);
+            installFile(new File(updateDir, fileContextsPath), stream, chunkLengths[2]);
+            installFile(new File(updateDir, sepolicyPath), stream, chunkLengths[3]);
+        } finally {
+            IoUtils.closeQuietly(stream);
+        }
+    }
+
+    private void applyUpdate() throws IOException, ErrnoException {
+        Slog.i(TAG, "Applying SELinux policy");
+        File contexts = new File(updateDir.getParentFile(), "contexts");
+        File current = new File(updateDir.getParentFile(), "current");
+        File update = new File(updateDir.getParentFile(), "update");
+        File tmp = new File(updateDir.getParentFile(), "tmp");
+        if (current.exists()) {
+            Libcore.os.symlink(updateDir.getPath(), update.getPath());
+            Libcore.os.rename(update.getPath(), current.getPath());
+        } else {
+            Libcore.os.symlink(updateDir.getPath(), current.getPath());
+        }
+        contexts.mkdirs();
+        backupContexts(contexts);
+        copyUpdate(contexts);
+        Libcore.os.symlink(contexts.getPath(), tmp.getPath());
+        Libcore.os.rename(tmp.getPath(), current.getPath());
+        SystemProperties.set("selinux.reload_policy", "1");
+    }
+
+    @Override
+    protected void postInstall(Context context, Intent intent) {
+        try {
+            unpackBundle();
+            applyUpdate();
+        } catch (IllegalArgumentException e) {
+            Slog.e(TAG, "SELinux policy update malformed: ", e);
+        } catch (IOException e) {
+            Slog.e(TAG, "Could not update selinux policy: ", e);
+        } catch (ErrnoException e) {
+            Slog.e(TAG, "Could not update selinux policy: ", e);
+        }
+    }
+}
diff --git a/services/java/com/android/server/updates/SmsShortCodesInstallReceiver.java b/services/core/java/com/android/server/updates/SmsShortCodesInstallReceiver.java
similarity index 100%
rename from services/java/com/android/server/updates/SmsShortCodesInstallReceiver.java
rename to services/core/java/com/android/server/updates/SmsShortCodesInstallReceiver.java
diff --git a/services/java/com/android/server/updates/TZInfoInstallReceiver.java b/services/core/java/com/android/server/updates/TZInfoInstallReceiver.java
similarity index 100%
rename from services/java/com/android/server/updates/TZInfoInstallReceiver.java
rename to services/core/java/com/android/server/updates/TZInfoInstallReceiver.java
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
new file mode 100644
index 0000000..97ea52c
--- /dev/null
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -0,0 +1,1353 @@
+/*
+ * 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.server.wallpaper;
+
+import static android.os.ParcelFileDescriptor.*;
+
+import android.app.ActivityManagerNative;
+import android.app.AppGlobals;
+import android.app.IUserSwitchObserver;
+import android.app.IWallpaperManager;
+import android.app.IWallpaperManagerCallback;
+import android.app.PendingIntent;
+import android.app.WallpaperInfo;
+import android.app.backup.BackupManager;
+import android.app.backup.WallpaperBackupHelper;
+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.IPackageManager;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.UserInfo;
+import android.content.res.Resources;
+import android.graphics.Point;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.FileUtils;
+import android.os.IBinder;
+import android.os.IRemoteCallback;
+import android.os.RemoteException;
+import android.os.FileObserver;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteCallbackList;
+import android.os.SELinux;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.service.wallpaper.IWallpaperConnection;
+import android.service.wallpaper.IWallpaperEngine;
+import android.service.wallpaper.IWallpaperService;
+import android.service.wallpaper.WallpaperService;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.Xml;
+import android.view.Display;
+import android.view.IWindowManager;
+import android.view.WindowManager;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.List;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.JournaledFile;
+
+public class WallpaperManagerService extends IWallpaperManager.Stub {
+    static final String TAG = "WallpaperManagerService";
+    static final boolean DEBUG = false;
+
+    final Object mLock = new Object[0];
+
+    /**
+     * Minimum time between crashes of a wallpaper service for us to consider
+     * restarting it vs. just reverting to the static wallpaper.
+     */
+    static final long MIN_WALLPAPER_CRASH_TIME = 10000;
+    static final String WALLPAPER = "wallpaper";
+    static final String WALLPAPER_INFO = "wallpaper_info.xml";
+    /**
+     * Name of the component used to display bitmap wallpapers from either the gallery or
+     * built-in wallpapers.
+     */
+    static final ComponentName IMAGE_WALLPAPER = new ComponentName("com.android.systemui",
+            "com.android.systemui.ImageWallpaper");
+
+    /**
+     * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
+     * that the wallpaper has changed. The CREATE is triggered when there is no
+     * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
+     * everytime the wallpaper is changed.
+     */
+    private class WallpaperObserver extends FileObserver {
+
+        final WallpaperData mWallpaper;
+        final File mWallpaperDir;
+        final File mWallpaperFile;
+
+        public WallpaperObserver(WallpaperData wallpaper) {
+            super(getWallpaperDir(wallpaper.userId).getAbsolutePath(),
+                    CLOSE_WRITE | DELETE | DELETE_SELF);
+            mWallpaperDir = getWallpaperDir(wallpaper.userId);
+            mWallpaper = wallpaper;
+            mWallpaperFile = new File(mWallpaperDir, WALLPAPER);
+        }
+
+        @Override
+        public void onEvent(int event, String path) {
+            if (path == null) {
+                return;
+            }
+            synchronized (mLock) {
+                // changing the wallpaper means we'll need to back up the new one
+                long origId = Binder.clearCallingIdentity();
+                BackupManager bm = new BackupManager(mContext);
+                bm.dataChanged();
+                Binder.restoreCallingIdentity(origId);
+
+                File changedFile = new File(mWallpaperDir, path);
+                if (mWallpaperFile.equals(changedFile)) {
+                    notifyCallbacksLocked(mWallpaper);
+                    if (mWallpaper.wallpaperComponent == null || event != CLOSE_WRITE
+                            || mWallpaper.imageWallpaperPending) {
+                        if (event == CLOSE_WRITE) {
+                            mWallpaper.imageWallpaperPending = false;
+                        }
+                        bindWallpaperComponentLocked(IMAGE_WALLPAPER, true,
+                                false, mWallpaper, null);
+                        saveSettingsLocked(mWallpaper);
+                    }
+                }
+            }
+        }
+    }
+
+    final Context mContext;
+    final IWindowManager mIWindowManager;
+    final IPackageManager mIPackageManager;
+    final MyPackageMonitor mMonitor;
+    WallpaperData mLastWallpaper;
+
+    SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>();
+
+    int mCurrentUserId;
+
+    static class WallpaperData {
+
+        int userId;
+
+        File wallpaperFile;
+
+        /**
+         * Client is currently writing a new image wallpaper.
+         */
+        boolean imageWallpaperPending;
+
+        /**
+         * Resource name if using a picture from the wallpaper gallery
+         */
+        String name = "";
+
+        /**
+         * The component name of the currently set live wallpaper.
+         */
+        ComponentName wallpaperComponent;
+
+        /**
+         * The component name of the wallpaper that should be set next.
+         */
+        ComponentName nextWallpaperComponent;
+
+        WallpaperConnection connection;
+        long lastDiedTime;
+        boolean wallpaperUpdating;
+        WallpaperObserver wallpaperObserver;
+
+        /**
+         * List of callbacks registered they should each be notified when the wallpaper is changed.
+         */
+        private RemoteCallbackList<IWallpaperManagerCallback> callbacks
+                = new RemoteCallbackList<IWallpaperManagerCallback>();
+
+        int width = -1;
+        int height = -1;
+
+        WallpaperData(int userId) {
+            this.userId = userId;
+            wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
+        }
+    }
+
+    class WallpaperConnection extends IWallpaperConnection.Stub
+            implements ServiceConnection {
+        final WallpaperInfo mInfo;
+        final Binder mToken = new Binder();
+        IWallpaperService mService;
+        IWallpaperEngine mEngine;
+        WallpaperData mWallpaper;
+        IRemoteCallback mReply;
+
+        boolean mDimensionsChanged = false;
+
+        public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) {
+            mInfo = info;
+            mWallpaper = wallpaper;
+        }
+
+        @Override
+        public void onServiceConnected(ComponentName name, IBinder service) {
+            synchronized (mLock) {
+                if (mWallpaper.connection == this) {
+                    mWallpaper.lastDiedTime = SystemClock.uptimeMillis();
+                    mService = IWallpaperService.Stub.asInterface(service);
+                    attachServiceLocked(this, mWallpaper);
+                    // XXX should probably do saveSettingsLocked() later
+                    // when we have an engine, but I'm not sure about
+                    // locking there and anyway we always need to be able to
+                    // recover if there is something wrong.
+                    saveSettingsLocked(mWallpaper);
+                }
+            }
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName name) {
+            synchronized (mLock) {
+                mService = null;
+                mEngine = null;
+                if (mWallpaper.connection == this) {
+                    Slog.w(TAG, "Wallpaper service gone: " + mWallpaper.wallpaperComponent);
+                    if (!mWallpaper.wallpaperUpdating
+                            && (mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME)
+                                > SystemClock.uptimeMillis()
+                            && mWallpaper.userId == mCurrentUserId) {
+                        Slog.w(TAG, "Reverting to built-in wallpaper!");
+                        clearWallpaperLocked(true, mWallpaper.userId, null);
+                    }
+                }
+            }
+        }
+
+        @Override
+        public void attachEngine(IWallpaperEngine engine) {
+            synchronized (mLock) {
+                mEngine = engine;
+                if (mDimensionsChanged) {
+                    try {
+                        mEngine.setDesiredSize(mWallpaper.width, mWallpaper.height);
+                    } catch (RemoteException e) {
+                        Slog.w(TAG, "Failed to set wallpaper dimensions", e);
+                    }
+                    mDimensionsChanged = false;
+                }
+            }
+        }
+
+        @Override
+        public void engineShown(IWallpaperEngine engine) {
+            synchronized (mLock) {
+                if (mReply != null) {
+                    long ident = Binder.clearCallingIdentity();
+                    try {
+                        mReply.sendResult(null);
+                    } catch (RemoteException e) {
+                        Binder.restoreCallingIdentity(ident);
+                    }
+                    mReply = null;
+                }
+            }
+        }
+
+        @Override
+        public ParcelFileDescriptor setWallpaper(String name) {
+            synchronized (mLock) {
+                if (mWallpaper.connection == this) {
+                    return updateWallpaperBitmapLocked(name, mWallpaper);
+                }
+                return null;
+            }
+        }
+    }
+
+    class MyPackageMonitor extends PackageMonitor {
+        @Override
+        public void onPackageUpdateFinished(String packageName, int uid) {
+            synchronized (mLock) {
+                if (mCurrentUserId != getChangingUserId()) {
+                    return;
+                }
+                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
+                if (wallpaper != null) {
+                    if (wallpaper.wallpaperComponent != null
+                            && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
+                        wallpaper.wallpaperUpdating = false;
+                        ComponentName comp = wallpaper.wallpaperComponent;
+                        clearWallpaperComponentLocked(wallpaper);
+                        if (!bindWallpaperComponentLocked(comp, false, false,
+                                wallpaper, null)) {
+                            Slog.w(TAG, "Wallpaper no longer available; reverting to default");
+                            clearWallpaperLocked(false, wallpaper.userId, null);
+                        }
+                    }
+                }
+            }
+        }
+
+        @Override
+        public void onPackageModified(String packageName) {
+            synchronized (mLock) {
+                if (mCurrentUserId != getChangingUserId()) {
+                    return;
+                }
+                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
+                if (wallpaper != null) {
+                    if (wallpaper.wallpaperComponent == null
+                            || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
+                        return;
+                    }
+                    doPackagesChangedLocked(true, wallpaper);
+                }
+            }
+        }
+
+        @Override
+        public void onPackageUpdateStarted(String packageName, int uid) {
+            synchronized (mLock) {
+                if (mCurrentUserId != getChangingUserId()) {
+                    return;
+                }
+                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
+                if (wallpaper != null) {
+                    if (wallpaper.wallpaperComponent != null
+                            && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
+                        wallpaper.wallpaperUpdating = true;
+                    }
+                }
+            }
+        }
+
+        @Override
+        public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
+            synchronized (mLock) {
+                boolean changed = false;
+                if (mCurrentUserId != getChangingUserId()) {
+                    return false;
+                }
+                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
+                if (wallpaper != null) {
+                    boolean res = doPackagesChangedLocked(doit, wallpaper);
+                    changed |= res;
+                }
+                return changed;
+            }
+        }
+
+        @Override
+        public void onSomePackagesChanged() {
+            synchronized (mLock) {
+                if (mCurrentUserId != getChangingUserId()) {
+                    return;
+                }
+                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
+                if (wallpaper != null) {
+                    doPackagesChangedLocked(true, wallpaper);
+                }
+            }
+        }
+
+        boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) {
+            boolean changed = false;
+            if (wallpaper.wallpaperComponent != null) {
+                int change = isPackageDisappearing(wallpaper.wallpaperComponent
+                        .getPackageName());
+                if (change == PACKAGE_PERMANENT_CHANGE
+                        || change == PACKAGE_TEMPORARY_CHANGE) {
+                    changed = true;
+                    if (doit) {
+                        Slog.w(TAG, "Wallpaper uninstalled, removing: "
+                                + wallpaper.wallpaperComponent);
+                        clearWallpaperLocked(false, wallpaper.userId, null);
+                    }
+                }
+            }
+            if (wallpaper.nextWallpaperComponent != null) {
+                int change = isPackageDisappearing(wallpaper.nextWallpaperComponent
+                        .getPackageName());
+                if (change == PACKAGE_PERMANENT_CHANGE
+                        || change == PACKAGE_TEMPORARY_CHANGE) {
+                    wallpaper.nextWallpaperComponent = null;
+                }
+            }
+            if (wallpaper.wallpaperComponent != null
+                    && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) {
+                try {
+                    mContext.getPackageManager().getServiceInfo(
+                            wallpaper.wallpaperComponent, 0);
+                } catch (NameNotFoundException e) {
+                    Slog.w(TAG, "Wallpaper component gone, removing: "
+                            + wallpaper.wallpaperComponent);
+                    clearWallpaperLocked(false, wallpaper.userId, null);
+                }
+            }
+            if (wallpaper.nextWallpaperComponent != null
+                    && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) {
+                try {
+                    mContext.getPackageManager().getServiceInfo(
+                            wallpaper.nextWallpaperComponent, 0);
+                } catch (NameNotFoundException e) {
+                    wallpaper.nextWallpaperComponent = null;
+                }
+            }
+            return changed;
+        }
+    }
+    
+    public WallpaperManagerService(Context context) {
+        if (DEBUG) Slog.v(TAG, "WallpaperService startup");
+        mContext = context;
+        mIWindowManager = IWindowManager.Stub.asInterface(
+                ServiceManager.getService(Context.WINDOW_SERVICE));
+        mIPackageManager = AppGlobals.getPackageManager();
+        mMonitor = new MyPackageMonitor();
+        mMonitor.register(context, null, UserHandle.ALL, true);
+        getWallpaperDir(UserHandle.USER_OWNER).mkdirs();
+        loadSettingsLocked(UserHandle.USER_OWNER);
+    }
+    
+    private static File getWallpaperDir(int userId) {
+        return Environment.getUserSystemDirectory(userId);
+    }
+
+    @Override
+    protected void finalize() throws Throwable {
+        super.finalize();
+        for (int i = 0; i < mWallpaperMap.size(); i++) {
+            WallpaperData wallpaper = mWallpaperMap.valueAt(i);
+            wallpaper.wallpaperObserver.stopWatching();
+        }
+    }
+
+    public void systemRunning() {
+        if (DEBUG) Slog.v(TAG, "systemReady");
+        WallpaperData wallpaper = mWallpaperMap.get(UserHandle.USER_OWNER);
+        switchWallpaper(wallpaper, null);
+        wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
+        wallpaper.wallpaperObserver.startWatching();
+
+        IntentFilter userFilter = new IntentFilter();
+        userFilter.addAction(Intent.ACTION_USER_REMOVED);
+        userFilter.addAction(Intent.ACTION_USER_STOPPING);
+        mContext.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                String action = intent.getAction();
+                if (Intent.ACTION_USER_REMOVED.equals(action)) {
+                    onRemoveUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+                            UserHandle.USER_NULL));
+                }
+                // TODO: Race condition causing problems when cleaning up on stopping a user.
+                // Comment this out for now.
+                // else if (Intent.ACTION_USER_STOPPING.equals(action)) {
+                //     onStoppingUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+                //             UserHandle.USER_NULL));
+                // }
+            }
+        }, userFilter);
+
+        try {
+            ActivityManagerNative.getDefault().registerUserSwitchObserver(
+                    new IUserSwitchObserver.Stub() {
+                        @Override
+                        public void onUserSwitching(int newUserId, IRemoteCallback reply) {
+                            switchUser(newUserId, reply);
+                        }
+
+                        @Override
+                        public void onUserSwitchComplete(int newUserId) throws RemoteException {
+                        }
+                    });
+        } catch (RemoteException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    /** Called by SystemBackupAgent */
+    public String getName() {
+        // Verify caller is the system
+        if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
+            throw new RuntimeException("getName() can only be called from the system process");
+        }
+        synchronized (mLock) {
+            return mWallpaperMap.get(0).name;
+        }
+    }
+
+    void onStoppingUser(int userId) {
+        if (userId < 1) return;
+        synchronized (mLock) {
+            WallpaperData wallpaper = mWallpaperMap.get(userId);
+            if (wallpaper != null) {
+                if (wallpaper.wallpaperObserver != null) {
+                    wallpaper.wallpaperObserver.stopWatching();
+                    wallpaper.wallpaperObserver = null;
+                }
+                mWallpaperMap.remove(userId);
+            }
+        }
+    }
+
+    void onRemoveUser(int userId) {
+        if (userId < 1) return;
+        synchronized (mLock) {
+            onStoppingUser(userId);
+            File wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
+            wallpaperFile.delete();
+            File wallpaperInfoFile = new File(getWallpaperDir(userId), WALLPAPER_INFO);
+            wallpaperInfoFile.delete();
+        }
+    }
+
+    void switchUser(int userId, IRemoteCallback reply) {
+        synchronized (mLock) {
+            mCurrentUserId = userId;
+            WallpaperData wallpaper = mWallpaperMap.get(userId);
+            if (wallpaper == null) {
+                wallpaper = new WallpaperData(userId);
+                mWallpaperMap.put(userId, wallpaper);
+                loadSettingsLocked(userId);
+            }
+            // Not started watching yet, in case wallpaper data was loaded for other reasons.
+            if (wallpaper.wallpaperObserver == null) {
+                wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
+                wallpaper.wallpaperObserver.startWatching();
+            }
+            switchWallpaper(wallpaper, reply);
+        }
+    }
+
+    void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) {
+        synchronized (mLock) {
+            RuntimeException e = null;
+            try {
+                ComponentName cname = wallpaper.wallpaperComponent != null ?
+                        wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent;
+                if (bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) {
+                    return;
+                }
+            } catch (RuntimeException e1) {
+                e = e1;
+            }
+            Slog.w(TAG, "Failure starting previous wallpaper", e);
+            clearWallpaperLocked(false, wallpaper.userId, reply);
+        }
+    }
+
+    public void clearWallpaper() {
+        if (DEBUG) Slog.v(TAG, "clearWallpaper");
+        synchronized (mLock) {
+            clearWallpaperLocked(false, UserHandle.getCallingUserId(), null);
+        }
+    }
+
+    void clearWallpaperLocked(boolean defaultFailed, int userId, IRemoteCallback reply) {
+        WallpaperData wallpaper = mWallpaperMap.get(userId);
+        File f = new File(getWallpaperDir(userId), WALLPAPER);
+        if (f.exists()) {
+            f.delete();
+        }
+        final long ident = Binder.clearCallingIdentity();
+        RuntimeException e = null;
+        try {
+            wallpaper.imageWallpaperPending = false;
+            if (userId != mCurrentUserId) return;
+            if (bindWallpaperComponentLocked(defaultFailed
+                    ? IMAGE_WALLPAPER
+                    : null, true, false, wallpaper, reply)) {
+                return;
+            }
+        } catch (IllegalArgumentException e1) {
+            e = e1;
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+        
+        // This can happen if the default wallpaper component doesn't
+        // exist.  This should be a system configuration problem, but
+        // let's not let it crash the system and just live with no
+        // wallpaper.
+        Slog.e(TAG, "Default wallpaper component not found!", e);
+        clearWallpaperComponentLocked(wallpaper);
+        if (reply != null) {
+            try {
+                reply.sendResult(null);
+            } catch (RemoteException e1) {
+            }
+        }
+    }
+
+    public boolean hasNamedWallpaper(String name) {
+        synchronized (mLock) {
+            List<UserInfo> users;
+            long ident = Binder.clearCallingIdentity();
+            try {
+                users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+            for (UserInfo user: users) {
+                WallpaperData wd = mWallpaperMap.get(user.id);
+                if (wd == null) {
+                    // User hasn't started yet, so load her settings to peek at the wallpaper
+                    loadSettingsLocked(user.id);
+                    wd = mWallpaperMap.get(user.id);
+                }
+                if (wd != null && name.equals(wd.name)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    private Point getDefaultDisplaySize() {
+        Point p = new Point();
+        WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
+        Display d = wm.getDefaultDisplay();
+        d.getRealSize(p);
+        return p;
+    }
+
+    public void setDimensionHints(int width, int height) throws RemoteException {
+        checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
+        synchronized (mLock) {
+            int userId = UserHandle.getCallingUserId();
+            WallpaperData wallpaper = mWallpaperMap.get(userId);
+            if (wallpaper == null) {
+                throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
+            }
+            if (width <= 0 || height <= 0) {
+                throw new IllegalArgumentException("width and height must be > 0");
+            }
+            // Make sure it is at least as large as the display.
+            Point displaySize = getDefaultDisplaySize();
+            width = Math.max(width, displaySize.x);
+            height = Math.max(height, displaySize.y);
+
+            if (width != wallpaper.width || height != wallpaper.height) {
+                wallpaper.width = width;
+                wallpaper.height = height;
+                saveSettingsLocked(wallpaper);
+                if (mCurrentUserId != userId) return; // Don't change the properties now
+                if (wallpaper.connection != null) {
+                    if (wallpaper.connection.mEngine != null) {
+                        try {
+                            wallpaper.connection.mEngine.setDesiredSize(
+                                    width, height);
+                        } catch (RemoteException e) {
+                        }
+                        notifyCallbacksLocked(wallpaper);
+                    } else if (wallpaper.connection.mService != null) {
+                        // We've attached to the service but the engine hasn't attached back to us
+                        // yet. This means it will be created with the previous dimensions, so we
+                        // need to update it to the new dimensions once it attaches.
+                        wallpaper.connection.mDimensionsChanged = true;
+                    }
+                }
+            }
+        }
+    }
+
+    public int getWidthHint() throws RemoteException {
+        synchronized (mLock) {
+            WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
+            return wallpaper.width;
+        }
+    }
+
+    public int getHeightHint() throws RemoteException {
+        synchronized (mLock) {
+            WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
+            return wallpaper.height;
+        }
+    }
+
+    public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
+            Bundle outParams) {
+        synchronized (mLock) {
+            // This returns the current user's wallpaper, if called by a system service. Else it
+            // returns the wallpaper for the calling user.
+            int callingUid = Binder.getCallingUid();
+            int wallpaperUserId = 0;
+            if (callingUid == android.os.Process.SYSTEM_UID) {
+                wallpaperUserId = mCurrentUserId;
+            } else {
+                wallpaperUserId = UserHandle.getUserId(callingUid);
+            }
+            WallpaperData wallpaper = mWallpaperMap.get(wallpaperUserId);
+            try {
+                if (outParams != null) {
+                    outParams.putInt("width", wallpaper.width);
+                    outParams.putInt("height", wallpaper.height);
+                }
+                wallpaper.callbacks.register(cb);
+                File f = new File(getWallpaperDir(wallpaperUserId), WALLPAPER);
+                if (!f.exists()) {
+                    return null;
+                }
+                return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
+            } catch (FileNotFoundException e) {
+                /* Shouldn't happen as we check to see if the file exists */
+                Slog.w(TAG, "Error getting wallpaper", e);
+            }
+            return null;
+        }
+    }
+
+    public WallpaperInfo getWallpaperInfo() {
+        int userId = UserHandle.getCallingUserId();
+        synchronized (mLock) {
+            WallpaperData wallpaper = mWallpaperMap.get(userId);
+            if (wallpaper.connection != null) {
+                return wallpaper.connection.mInfo;
+            }
+            return null;
+        }
+    }
+
+    public ParcelFileDescriptor setWallpaper(String name) {
+        checkPermission(android.Manifest.permission.SET_WALLPAPER);
+        synchronized (mLock) {
+            if (DEBUG) Slog.v(TAG, "setWallpaper");
+            int userId = UserHandle.getCallingUserId();
+            WallpaperData wallpaper = mWallpaperMap.get(userId);
+            if (wallpaper == null) {
+                throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
+            }
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper);
+                if (pfd != null) {
+                    wallpaper.imageWallpaperPending = true;
+                }
+                return pfd;
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper) {
+        if (name == null) name = "";
+        try {
+            File dir = getWallpaperDir(wallpaper.userId);
+            if (!dir.exists()) {
+                dir.mkdir();
+                FileUtils.setPermissions(
+                        dir.getPath(),
+                        FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
+                        -1, -1);
+            }
+            File file = new File(dir, WALLPAPER);
+            ParcelFileDescriptor fd = ParcelFileDescriptor.open(file,
+                    MODE_CREATE|MODE_READ_WRITE);
+            if (!SELinux.restorecon(file)) {
+                return null;
+            }
+            wallpaper.name = name;
+            return fd;
+        } catch (FileNotFoundException e) {
+            Slog.w(TAG, "Error setting wallpaper", e);
+        }
+        return null;
+    }
+
+    public void setWallpaperComponent(ComponentName name) {
+        checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
+        synchronized (mLock) {
+            if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name);
+            int userId = UserHandle.getCallingUserId();
+            WallpaperData wallpaper = mWallpaperMap.get(userId);
+            if (wallpaper == null) {
+                throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
+            }
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                wallpaper.imageWallpaperPending = false;
+                bindWallpaperComponentLocked(name, false, true, wallpaper, null);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+    
+    boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force,
+            boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
+        if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
+        // Has the component changed?
+        if (!force) {
+            if (wallpaper.connection != null) {
+                if (wallpaper.wallpaperComponent == null) {
+                    if (componentName == null) {
+                        if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
+                        // Still using default wallpaper.
+                        return true;
+                    }
+                } else if (wallpaper.wallpaperComponent.equals(componentName)) {
+                    // Changing to same wallpaper.
+                    if (DEBUG) Slog.v(TAG, "same wallpaper");
+                    return true;
+                }
+            }
+        }
+        
+        try {
+            if (componentName == null) {
+                String defaultComponent = 
+                    mContext.getString(com.android.internal.R.string.default_wallpaper_component);
+                if (defaultComponent != null) {
+                    // See if there is a default wallpaper component specified
+                    componentName = ComponentName.unflattenFromString(defaultComponent);
+                    if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName);
+                }
+                if (componentName == null) {
+                    // Fall back to static image wallpaper
+                    componentName = IMAGE_WALLPAPER;
+                    //clearWallpaperComponentLocked();
+                    //return;
+                    if (DEBUG) Slog.v(TAG, "Using image wallpaper");
+                }
+            }
+            int serviceUserId = wallpaper.userId;
+            ServiceInfo si = mIPackageManager.getServiceInfo(componentName,
+                    PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
+            if (si == null) {
+                // The wallpaper component we're trying to use doesn't exist
+                Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
+                return false;
+            }
+            if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
+                String msg = "Selected service does not require "
+                        + android.Manifest.permission.BIND_WALLPAPER
+                        + ": " + componentName;
+                if (fromUser) {
+                    throw new SecurityException(msg);
+                }
+                Slog.w(TAG, msg);
+                return false;
+            }
+            
+            WallpaperInfo wi = null;
+            
+            Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
+            if (componentName != null && !componentName.equals(IMAGE_WALLPAPER)) {
+                // Make sure the selected service is actually a wallpaper service.
+                List<ResolveInfo> ris =
+                        mIPackageManager.queryIntentServices(intent,
+                                intent.resolveTypeIfNeeded(mContext.getContentResolver()),
+                                PackageManager.GET_META_DATA, serviceUserId);
+                for (int i=0; i<ris.size(); i++) {
+                    ServiceInfo rsi = ris.get(i).serviceInfo;
+                    if (rsi.name.equals(si.name) &&
+                            rsi.packageName.equals(si.packageName)) {
+                        try {
+                            wi = new WallpaperInfo(mContext, ris.get(i));
+                        } catch (XmlPullParserException e) {
+                            if (fromUser) {
+                                throw new IllegalArgumentException(e);
+                            }
+                            Slog.w(TAG, e);
+                            return false;
+                        } catch (IOException e) {
+                            if (fromUser) {
+                                throw new IllegalArgumentException(e);
+                            }
+                            Slog.w(TAG, e);
+                            return false;
+                        }
+                        break;
+                    }
+                }
+                if (wi == null) {
+                    String msg = "Selected service is not a wallpaper: "
+                            + componentName;
+                    if (fromUser) {
+                        throw new SecurityException(msg);
+                    }
+                    Slog.w(TAG, msg);
+                    return false;
+                }
+            }
+            
+            // Bind the service!
+            if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
+            WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
+            intent.setComponent(componentName);
+            intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
+                    com.android.internal.R.string.wallpaper_binding_label);
+            intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(
+                    mContext, 0,
+                    Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
+                            mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
+                    0, null, new UserHandle(serviceUserId)));
+            if (!mContext.bindServiceAsUser(intent, newConn,
+                    Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI,
+                    new UserHandle(serviceUserId))) {
+                String msg = "Unable to bind service: "
+                        + componentName;
+                if (fromUser) {
+                    throw new IllegalArgumentException(msg);
+                }
+                Slog.w(TAG, msg);
+                return false;
+            }
+            if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
+                detachWallpaperLocked(mLastWallpaper);
+            }
+            wallpaper.wallpaperComponent = componentName;
+            wallpaper.connection = newConn;
+            wallpaper.lastDiedTime = SystemClock.uptimeMillis();
+            newConn.mReply = reply;
+            try {
+                if (wallpaper.userId == mCurrentUserId) {
+                    if (DEBUG)
+                        Slog.v(TAG, "Adding window token: " + newConn.mToken);
+                    mIWindowManager.addWindowToken(newConn.mToken,
+                            WindowManager.LayoutParams.TYPE_WALLPAPER);
+                    mLastWallpaper = wallpaper;
+                }
+            } catch (RemoteException e) {
+            }
+        } catch (RemoteException e) {
+            String msg = "Remote exception for " + componentName + "\n" + e;
+            if (fromUser) {
+                throw new IllegalArgumentException(msg);
+            }
+            Slog.w(TAG, msg);
+            return false;
+        }
+        return true;
+    }
+
+    void detachWallpaperLocked(WallpaperData wallpaper) {
+        if (wallpaper.connection != null) {
+            if (wallpaper.connection.mReply != null) {
+                try {
+                    wallpaper.connection.mReply.sendResult(null);
+                } catch (RemoteException e) {
+                }
+                wallpaper.connection.mReply = null;
+            }
+            if (wallpaper.connection.mEngine != null) {
+                try {
+                    wallpaper.connection.mEngine.destroy();
+                } catch (RemoteException e) {
+                }
+            }
+            mContext.unbindService(wallpaper.connection);
+            try {
+                if (DEBUG)
+                    Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken);
+                mIWindowManager.removeWindowToken(wallpaper.connection.mToken);
+            } catch (RemoteException e) {
+            }
+            wallpaper.connection.mService = null;
+            wallpaper.connection.mEngine = null;
+            wallpaper.connection = null;
+        }
+    }
+
+    void clearWallpaperComponentLocked(WallpaperData wallpaper) {
+        wallpaper.wallpaperComponent = null;
+        detachWallpaperLocked(wallpaper);
+    }
+
+    void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
+        try {
+            conn.mService.attach(conn, conn.mToken,
+                    WindowManager.LayoutParams.TYPE_WALLPAPER, false,
+                    wallpaper.width, wallpaper.height);
+        } catch (RemoteException e) {
+            Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
+            if (!wallpaper.wallpaperUpdating) {
+                bindWallpaperComponentLocked(null, false, false, wallpaper, null);
+            }
+        }
+    }
+
+    private void notifyCallbacksLocked(WallpaperData wallpaper) {
+        final int n = wallpaper.callbacks.beginBroadcast();
+        for (int i = 0; i < n; i++) {
+            try {
+                wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged();
+            } catch (RemoteException e) {
+
+                // The RemoteCallbackList will take care of removing
+                // the dead object for us.
+            }
+        }
+        wallpaper.callbacks.finishBroadcast();
+        final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
+        mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId));
+    }
+
+    private void checkPermission(String permission) {
+        if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) {
+            throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
+                    + ", must have permission " + permission);
+        }
+    }
+
+    private static JournaledFile makeJournaledFile(int userId) {
+        final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath();
+        return new JournaledFile(new File(base), new File(base + ".tmp"));
+    }
+
+    private void saveSettingsLocked(WallpaperData wallpaper) {
+        JournaledFile journal = makeJournaledFile(wallpaper.userId);
+        FileOutputStream stream = null;
+        try {
+            stream = new FileOutputStream(journal.chooseForWrite(), false);
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(stream, "utf-8");
+            out.startDocument(null, true);
+
+            out.startTag(null, "wp");
+            out.attribute(null, "width", Integer.toString(wallpaper.width));
+            out.attribute(null, "height", Integer.toString(wallpaper.height));
+            out.attribute(null, "name", wallpaper.name);
+            if (wallpaper.wallpaperComponent != null
+                    && !wallpaper.wallpaperComponent.equals(IMAGE_WALLPAPER)) {
+                out.attribute(null, "component",
+                        wallpaper.wallpaperComponent.flattenToShortString());
+            }
+            out.endTag(null, "wp");
+
+            out.endDocument();
+            stream.close();
+            journal.commit();
+        } catch (IOException e) {
+            try {
+                if (stream != null) {
+                    stream.close();
+                }
+            } catch (IOException ex) {
+                // Ignore
+            }
+            journal.rollback();
+        }
+    }
+
+    private void migrateFromOld() {
+        File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY);
+        File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY);
+        if (oldWallpaper.exists()) {
+            File newWallpaper = new File(getWallpaperDir(0), WALLPAPER);
+            oldWallpaper.renameTo(newWallpaper);
+        }
+        if (oldInfo.exists()) {
+            File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO);
+            oldInfo.renameTo(newInfo);
+        }
+    }
+
+    private void loadSettingsLocked(int userId) {
+        if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
+        
+        JournaledFile journal = makeJournaledFile(userId);
+        FileInputStream stream = null;
+        File file = journal.chooseForRead();
+        if (!file.exists()) {
+            // This should only happen one time, when upgrading from a legacy system
+            migrateFromOld();
+        }
+        WallpaperData wallpaper = mWallpaperMap.get(userId);
+        if (wallpaper == null) {
+            wallpaper = new WallpaperData(userId);
+            mWallpaperMap.put(userId, wallpaper);
+        }
+        boolean success = false;
+        try {
+            stream = new FileInputStream(file);
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(stream, null);
+
+            int type;
+            do {
+                type = parser.next();
+                if (type == XmlPullParser.START_TAG) {
+                    String tag = parser.getName();
+                    if ("wp".equals(tag)) {
+                        wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
+                        wallpaper.height = Integer.parseInt(parser
+                                .getAttributeValue(null, "height"));
+                        wallpaper.name = parser.getAttributeValue(null, "name");
+                        String comp = parser.getAttributeValue(null, "component");
+                        wallpaper.nextWallpaperComponent = comp != null
+                                ? ComponentName.unflattenFromString(comp)
+                                : null;
+                        if (wallpaper.nextWallpaperComponent == null
+                                || "android".equals(wallpaper.nextWallpaperComponent
+                                        .getPackageName())) {
+                            wallpaper.nextWallpaperComponent = IMAGE_WALLPAPER;
+                        }
+                          
+                        if (DEBUG) {
+                            Slog.v(TAG, "mWidth:" + wallpaper.width);
+                            Slog.v(TAG, "mHeight:" + wallpaper.height);
+                            Slog.v(TAG, "mName:" + wallpaper.name);
+                            Slog.v(TAG, "mNextWallpaperComponent:"
+                                    + wallpaper.nextWallpaperComponent);
+                        }
+                    }
+                }
+            } while (type != XmlPullParser.END_DOCUMENT);
+            success = true;
+        } catch (FileNotFoundException e) {
+            Slog.w(TAG, "no current wallpaper -- first boot?");
+        } catch (NullPointerException e) {
+            Slog.w(TAG, "failed parsing " + file + " " + e);
+        } catch (NumberFormatException e) {
+            Slog.w(TAG, "failed parsing " + file + " " + e);
+        } catch (XmlPullParserException e) {
+            Slog.w(TAG, "failed parsing " + file + " " + e);
+        } catch (IOException e) {
+            Slog.w(TAG, "failed parsing " + file + " " + e);
+        } catch (IndexOutOfBoundsException e) {
+            Slog.w(TAG, "failed parsing " + file + " " + e);
+        }
+        try {
+            if (stream != null) {
+                stream.close();
+            }
+        } catch (IOException e) {
+            // Ignore
+        }
+
+        if (!success) {
+            wallpaper.width = -1;
+            wallpaper.height = -1;
+            wallpaper.name = "";
+        }
+
+        // We always want to have some reasonable width hint.
+        int baseSize = getMaximumSizeDimension();
+        if (wallpaper.width < baseSize) {
+            wallpaper.width = baseSize;
+        }
+        if (wallpaper.height < baseSize) {
+            wallpaper.height = baseSize;
+        }
+    }
+
+    private int getMaximumSizeDimension() {
+        WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
+        Display d = wm.getDefaultDisplay();
+        return d.getMaximumSizeDimension();
+    }
+
+    // Called by SystemBackupAgent after files are restored to disk.
+    public void settingsRestored() {
+        // Verify caller is the system
+        if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
+            throw new RuntimeException("settingsRestored() can only be called from the system process");
+        }
+        // TODO: If necessary, make it work for secondary users as well. This currently assumes
+        // restores only to the primary user
+        if (DEBUG) Slog.v(TAG, "settingsRestored");
+        WallpaperData wallpaper = null;
+        boolean success = false;
+        synchronized (mLock) {
+            loadSettingsLocked(0);
+            wallpaper = mWallpaperMap.get(0);
+            if (wallpaper.nextWallpaperComponent != null
+                    && !wallpaper.nextWallpaperComponent.equals(IMAGE_WALLPAPER)) {
+                if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
+                        wallpaper, null)) {
+                    // No such live wallpaper or other failure; fall back to the default
+                    // live wallpaper (since the profile being restored indicated that the
+                    // user had selected a live rather than static one).
+                    bindWallpaperComponentLocked(null, false, false, wallpaper, null);
+                }
+                success = true;
+            } else {
+                // If there's a wallpaper name, we use that.  If that can't be loaded, then we
+                // use the default.
+                if ("".equals(wallpaper.name)) {
+                    if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty");
+                    success = true;
+                } else {
+                    if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource");
+                    success = restoreNamedResourceLocked(wallpaper);
+                }
+                if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
+                if (success) {
+                    bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
+                            wallpaper, null);
+                }
+            }
+        }
+
+        if (!success) {
+            Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'");
+            wallpaper.name = "";
+            getWallpaperDir(0).delete();
+        }
+
+        synchronized (mLock) {
+            saveSettingsLocked(wallpaper);
+        }
+    }
+
+    boolean restoreNamedResourceLocked(WallpaperData wallpaper) {
+        if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) {
+            String resName = wallpaper.name.substring(4);
+
+            String pkg = null;
+            int colon = resName.indexOf(':');
+            if (colon > 0) {
+                pkg = resName.substring(0, colon);
+            }
+
+            String ident = null;
+            int slash = resName.lastIndexOf('/');
+            if (slash > 0) {
+                ident = resName.substring(slash+1);
+            }
+
+            String type = null;
+            if (colon > 0 && slash > 0 && (slash-colon) > 1) {
+                type = resName.substring(colon+1, slash);
+            }
+
+            if (pkg != null && ident != null && type != null) {
+                int resId = -1;
+                InputStream res = null;
+                FileOutputStream fos = null;
+                try {
+                    Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED);
+                    Resources r = c.getResources();
+                    resId = r.getIdentifier(resName, null, null);
+                    if (resId == 0) {
+                        Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type
+                                + " ident=" + ident);
+                        return false;
+                    }
+
+                    res = r.openRawResource(resId);
+                    if (wallpaper.wallpaperFile.exists()) {
+                        wallpaper.wallpaperFile.delete();
+                    }
+                    fos = new FileOutputStream(wallpaper.wallpaperFile);
+
+                    byte[] buffer = new byte[32768];
+                    int amt;
+                    while ((amt=res.read(buffer)) > 0) {
+                        fos.write(buffer, 0, amt);
+                    }
+                    // mWallpaperObserver will notice the close and send the change broadcast
+
+                    Slog.v(TAG, "Restored wallpaper: " + resName);
+                    return true;
+                } catch (NameNotFoundException e) {
+                    Slog.e(TAG, "Package name " + pkg + " not found");
+                } catch (Resources.NotFoundException e) {
+                    Slog.e(TAG, "Resource not found: " + resId);
+                } catch (IOException e) {
+                    Slog.e(TAG, "IOException while restoring wallpaper ", e);
+                } finally {
+                    if (res != null) {
+                        try {
+                            res.close();
+                        } catch (IOException ex) {}
+                    }
+                    if (fos != null) {
+                        FileUtils.sync(fos);
+                        try {
+                            fos.close();
+                        } catch (IOException ex) {}
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+            
+            pw.println("Permission Denial: can't dump wallpaper service from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        synchronized (mLock) {
+            pw.println("Current Wallpaper Service state:");
+            for (int i = 0; i < mWallpaperMap.size(); i++) {
+                WallpaperData wallpaper = mWallpaperMap.valueAt(i);
+                pw.println(" User " + wallpaper.userId + ":");
+                pw.print("  mWidth=");
+                pw.print(wallpaper.width);
+                pw.print(" mHeight=");
+                pw.println(wallpaper.height);
+                pw.print("  mName=");
+                pw.println(wallpaper.name);
+                pw.print("  mWallpaperComponent=");
+                pw.println(wallpaper.wallpaperComponent);
+                if (wallpaper.connection != null) {
+                    WallpaperConnection conn = wallpaper.connection;
+                    pw.print("  Wallpaper connection ");
+                    pw.print(conn);
+                    pw.println(":");
+                    if (conn.mInfo != null) {
+                        pw.print("    mInfo.component=");
+                        pw.println(conn.mInfo.getComponent());
+                    }
+                    pw.print("    mToken=");
+                    pw.println(conn.mToken);
+                    pw.print("    mService=");
+                    pw.println(conn.mService);
+                    pw.print("    mEngine=");
+                    pw.println(conn.mEngine);
+                    pw.print("    mLastDiedTime=");
+                    pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis());
+                }
+            }
+        }
+    }
+}
diff --git a/services/java/com/android/server/wifi/README.txt b/services/core/java/com/android/server/wifi/README.txt
similarity index 100%
rename from services/java/com/android/server/wifi/README.txt
rename to services/core/java/com/android/server/wifi/README.txt
diff --git a/services/java/com/android/server/wifi/WifiController.java b/services/core/java/com/android/server/wifi/WifiController.java
similarity index 100%
rename from services/java/com/android/server/wifi/WifiController.java
rename to services/core/java/com/android/server/wifi/WifiController.java
diff --git a/services/java/com/android/server/wifi/WifiNotificationController.java b/services/core/java/com/android/server/wifi/WifiNotificationController.java
similarity index 100%
rename from services/java/com/android/server/wifi/WifiNotificationController.java
rename to services/core/java/com/android/server/wifi/WifiNotificationController.java
diff --git a/services/java/com/android/server/wifi/WifiService.java b/services/core/java/com/android/server/wifi/WifiService.java
similarity index 100%
rename from services/java/com/android/server/wifi/WifiService.java
rename to services/core/java/com/android/server/wifi/WifiService.java
diff --git a/services/java/com/android/server/wifi/WifiSettingsStore.java b/services/core/java/com/android/server/wifi/WifiSettingsStore.java
similarity index 100%
rename from services/java/com/android/server/wifi/WifiSettingsStore.java
rename to services/core/java/com/android/server/wifi/WifiSettingsStore.java
diff --git a/services/java/com/android/server/wifi/WifiTrafficPoller.java b/services/core/java/com/android/server/wifi/WifiTrafficPoller.java
similarity index 100%
rename from services/java/com/android/server/wifi/WifiTrafficPoller.java
rename to services/core/java/com/android/server/wifi/WifiTrafficPoller.java
diff --git a/services/java/com/android/server/wm/AppTransition.java b/services/core/java/com/android/server/wm/AppTransition.java
similarity index 100%
rename from services/java/com/android/server/wm/AppTransition.java
rename to services/core/java/com/android/server/wm/AppTransition.java
diff --git a/services/core/java/com/android/server/wm/AppWindowAnimator.java b/services/core/java/com/android/server/wm/AppWindowAnimator.java
new file mode 100644
index 0000000..7fe895b
--- /dev/null
+++ b/services/core/java/com/android/server/wm/AppWindowAnimator.java
@@ -0,0 +1,348 @@
+/*
+ * 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.server.wm;
+
+import android.graphics.Matrix;
+import android.util.Slog;
+import android.util.TimeUtils;
+import android.view.Display;
+import android.view.SurfaceControl;
+import android.view.WindowManagerPolicy;
+import android.view.animation.Animation;
+import android.view.animation.Transformation;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+public class AppWindowAnimator {
+    static final String TAG = "AppWindowAnimator";
+
+    final AppWindowToken mAppToken;
+    final WindowManagerService mService;
+    final WindowAnimator mAnimator;
+
+    boolean animating;
+    Animation animation;
+    boolean hasTransformation;
+    final Transformation transformation = new Transformation();
+
+    // Have we been asked to have this token keep the screen frozen?
+    // Protect with mAnimator.
+    boolean freezingScreen;
+
+    /**
+     * How long we last kept the screen frozen.
+     */
+    int lastFreezeDuration;
+
+    // Offset to the window of all layers in the token, for use by
+    // AppWindowToken animations.
+    int animLayerAdjustment;
+
+    // Propagated from AppWindowToken.allDrawn, to determine when
+    // the state changes.
+    boolean allDrawn;
+
+    // Special surface for thumbnail animation.
+    SurfaceControl thumbnail;
+    int thumbnailTransactionSeq;
+    int thumbnailX;
+    int thumbnailY;
+    int thumbnailLayer;
+    Animation thumbnailAnimation;
+    final Transformation thumbnailTransformation = new Transformation();
+
+    /** WindowStateAnimator from mAppAnimator.allAppWindows as of last performLayout */
+    ArrayList<WindowStateAnimator> mAllAppWinAnimators = new ArrayList<WindowStateAnimator>();
+
+    static final Animation sDummyAnimation = new DummyAnimation();
+
+    public AppWindowAnimator(final AppWindowToken atoken) {
+        mAppToken = atoken;
+        mService = atoken.service;
+        mAnimator = atoken.mAnimator;
+    }
+
+    public void setAnimation(Animation anim, int width, int height) {
+        if (WindowManagerService.localLOGV) Slog.v(TAG, "Setting animation in " + mAppToken
+                + ": " + anim + " wxh=" + width + "x" + height
+                + " isVisible=" + mAppToken.isVisible());
+        animation = anim;
+        animating = false;
+        if (!anim.isInitialized()) {
+            anim.initialize(width, height, width, height);
+        }
+        anim.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
+        anim.scaleCurrentDuration(mService.mTransitionAnimationScale);
+        int zorder = anim.getZAdjustment();
+        int adj = 0;
+        if (zorder == Animation.ZORDER_TOP) {
+            adj = WindowManagerService.TYPE_LAYER_OFFSET;
+        } else if (zorder == Animation.ZORDER_BOTTOM) {
+            adj = -WindowManagerService.TYPE_LAYER_OFFSET;
+        }
+
+        if (animLayerAdjustment != adj) {
+            animLayerAdjustment = adj;
+            updateLayers();
+        }
+        // Start out animation gone if window is gone, or visible if window is visible.
+        transformation.clear();
+        transformation.setAlpha(mAppToken.isVisible() ? 1 : 0);
+        hasTransformation = true;
+    }
+
+    public void setDummyAnimation() {
+        if (WindowManagerService.localLOGV) Slog.v(TAG, "Setting dummy animation in " + mAppToken
+                + " isVisible=" + mAppToken.isVisible());
+        animation = sDummyAnimation;
+        hasTransformation = true;
+        transformation.clear();
+        transformation.setAlpha(mAppToken.isVisible() ? 1 : 0);
+    }
+
+    public void clearAnimation() {
+        if (animation != null) {
+            animation = null;
+            animating = true;
+        }
+        clearThumbnail();
+        if (mAppToken.deferClearAllDrawn) {
+            mAppToken.allDrawn = false;
+            mAppToken.deferClearAllDrawn = false;
+        }
+    }
+
+    public void clearThumbnail() {
+        if (thumbnail != null) {
+            thumbnail.destroy();
+            thumbnail = null;
+        }
+    }
+
+    void updateLayers() {
+        final int N = mAppToken.allAppWindows.size();
+        final int adj = animLayerAdjustment;
+        thumbnailLayer = -1;
+        for (int i=0; i<N; i++) {
+            final WindowState w = mAppToken.allAppWindows.get(i);
+            final WindowStateAnimator winAnimator = w.mWinAnimator;
+            winAnimator.mAnimLayer = w.mLayer + adj;
+            if (winAnimator.mAnimLayer > thumbnailLayer) {
+                thumbnailLayer = winAnimator.mAnimLayer;
+            }
+            if (WindowManagerService.DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
+                    + winAnimator.mAnimLayer);
+            if (w == mService.mInputMethodTarget && !mService.mInputMethodTargetWaitingAnim) {
+                mService.setInputMethodAnimLayerAdjustment(adj);
+            }
+            if (w == mService.mWallpaperTarget && mService.mLowerWallpaperTarget == null) {
+                mService.setWallpaperAnimLayerAdjustmentLocked(adj);
+            }
+        }
+    }
+
+    private void stepThumbnailAnimation(long currentTime) {
+        thumbnailTransformation.clear();
+        thumbnailAnimation.getTransformation(currentTime, thumbnailTransformation);
+        thumbnailTransformation.getMatrix().preTranslate(thumbnailX, thumbnailY);
+
+        ScreenRotationAnimation screenRotationAnimation =
+                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
+        final boolean screenAnimation = screenRotationAnimation != null
+                && screenRotationAnimation.isAnimating();
+        if (screenAnimation) {
+            thumbnailTransformation.postCompose(screenRotationAnimation.getEnterTransformation());
+        }
+        // cache often used attributes locally
+        final float tmpFloats[] = mService.mTmpFloats;
+        thumbnailTransformation.getMatrix().getValues(tmpFloats);
+        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail,
+                "thumbnail", "POS " + tmpFloats[Matrix.MTRANS_X]
+                + ", " + tmpFloats[Matrix.MTRANS_Y], null);
+        thumbnail.setPosition(tmpFloats[Matrix.MTRANS_X], tmpFloats[Matrix.MTRANS_Y]);
+        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail,
+                "thumbnail", "alpha=" + thumbnailTransformation.getAlpha()
+                + " layer=" + thumbnailLayer
+                + " matrix=[" + tmpFloats[Matrix.MSCALE_X]
+                + "," + tmpFloats[Matrix.MSKEW_Y]
+                + "][" + tmpFloats[Matrix.MSKEW_X]
+                + "," + tmpFloats[Matrix.MSCALE_Y] + "]", null);
+        thumbnail.setAlpha(thumbnailTransformation.getAlpha());
+        // The thumbnail is layered below the window immediately above this
+        // token's anim layer.
+        thumbnail.setLayer(thumbnailLayer + WindowManagerService.WINDOW_LAYER_MULTIPLIER
+                - WindowManagerService.LAYER_OFFSET_THUMBNAIL);
+        thumbnail.setMatrix(tmpFloats[Matrix.MSCALE_X], tmpFloats[Matrix.MSKEW_Y],
+                tmpFloats[Matrix.MSKEW_X], tmpFloats[Matrix.MSCALE_Y]);
+    }
+
+    private boolean stepAnimation(long currentTime) {
+        if (animation == null) {
+            return false;
+        }
+        transformation.clear();
+        final boolean more = animation.getTransformation(currentTime, transformation);
+        if (false && WindowManagerService.DEBUG_ANIM) Slog.v(
+            TAG, "Stepped animation in " + mAppToken + ": more=" + more + ", xform=" + transformation);
+        if (!more) {
+            animation = null;
+            clearThumbnail();
+            if (WindowManagerService.DEBUG_ANIM) Slog.v(
+                TAG, "Finished animation in " + mAppToken + " @ " + currentTime);
+        }
+        hasTransformation = more;
+        return more;
+    }
+
+    // This must be called while inside a transaction.
+    boolean stepAnimationLocked(long currentTime) {
+        if (mService.okToDisplay()) {
+            // We will run animations as long as the display isn't frozen.
+
+            if (animation == sDummyAnimation) {
+                // This guy is going to animate, but not yet.  For now count
+                // it as not animating for purposes of scheduling transactions;
+                // when it is really time to animate, this will be set to
+                // a real animation and the next call will execute normally.
+                return false;
+            }
+
+            if ((mAppToken.allDrawn || animating || mAppToken.startingDisplayed)
+                    && animation != null) {
+                if (!animating) {
+                    if (WindowManagerService.DEBUG_ANIM) Slog.v(
+                        TAG, "Starting animation in " + mAppToken +
+                        " @ " + currentTime + " scale=" + mService.mTransitionAnimationScale
+                        + " allDrawn=" + mAppToken.allDrawn + " animating=" + animating);
+                    animation.setStartTime(currentTime);
+                    animating = true;
+                    if (thumbnail != null) {
+                        thumbnail.show();
+                        thumbnailAnimation.setStartTime(currentTime);
+                    }
+                }
+                if (stepAnimation(currentTime)) {
+                    // animation isn't over, step any thumbnail and that's
+                    // it for now.
+                    if (thumbnail != null) {
+                        stepThumbnailAnimation(currentTime);
+                    }
+                    return true;
+                }
+            }
+        } else if (animation != null) {
+            // If the display is frozen, and there is a pending animation,
+            // clear it and make sure we run the cleanup code.
+            animating = true;
+            animation = null;
+        }
+
+        hasTransformation = false;
+
+        if (!animating && animation == null) {
+            return false;
+        }
+
+        mAnimator.setAppLayoutChanges(this, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM,
+                "AppWindowToken");
+
+        clearAnimation();
+        animating = false;
+        if (animLayerAdjustment != 0) {
+            animLayerAdjustment = 0;
+            updateLayers();
+        }
+        if (mService.mInputMethodTarget != null
+                && mService.mInputMethodTarget.mAppToken == mAppToken) {
+            mService.moveInputMethodWindowsIfNeededLocked(true);
+        }
+
+        if (WindowManagerService.DEBUG_ANIM) Slog.v(
+                TAG, "Animation done in " + mAppToken
+                + ": reportedVisible=" + mAppToken.reportedVisible);
+
+        transformation.clear();
+
+        final int N = mAllAppWinAnimators.size();
+        for (int i=0; i<N; i++) {
+            mAllAppWinAnimators.get(i).finishExit();
+        }
+        mAppToken.updateReportedVisibilityLocked();
+
+        return false;
+    }
+
+    boolean showAllWindowsLocked() {
+        boolean isAnimating = false;
+        final int NW = mAllAppWinAnimators.size();
+        for (int i=0; i<NW; i++) {
+            WindowStateAnimator winAnimator = mAllAppWinAnimators.get(i);
+            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
+                    "performing show on: " + winAnimator);
+            winAnimator.performShowLocked();
+            isAnimating |= winAnimator.isAnimating();
+        }
+        return isAnimating;
+    }
+
+    void dump(PrintWriter pw, String prefix, boolean dumpAll) {
+        pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
+        pw.print(prefix); pw.print("mAnimator="); pw.println(mAnimator);
+        pw.print(prefix); pw.print("freezingScreen="); pw.print(freezingScreen);
+                pw.print(" allDrawn="); pw.print(allDrawn);
+                pw.print(" animLayerAdjustment="); pw.println(animLayerAdjustment);
+        if (lastFreezeDuration != 0) {
+            pw.print(prefix); pw.print("lastFreezeDuration=");
+                    TimeUtils.formatDuration(lastFreezeDuration, pw); pw.println();
+        }
+        if (animating || animation != null) {
+            pw.print(prefix); pw.print("animating="); pw.println(animating);
+            pw.print(prefix); pw.print("animation="); pw.println(animation);
+        }
+        if (hasTransformation) {
+            pw.print(prefix); pw.print("XForm: ");
+                    transformation.printShortString(pw);
+                    pw.println();
+        }
+        if (thumbnail != null) {
+            pw.print(prefix); pw.print("thumbnail="); pw.print(thumbnail);
+                    pw.print(" x="); pw.print(thumbnailX);
+                    pw.print(" y="); pw.print(thumbnailY);
+                    pw.print(" layer="); pw.println(thumbnailLayer);
+            pw.print(prefix); pw.print("thumbnailAnimation="); pw.println(thumbnailAnimation);
+            pw.print(prefix); pw.print("thumbnailTransformation=");
+                    pw.println(thumbnailTransformation.toShortString());
+        }
+        for (int i=0; i<mAllAppWinAnimators.size(); i++) {
+            WindowStateAnimator wanim = mAllAppWinAnimators.get(i);
+            pw.print(prefix); pw.print("App Win Anim #"); pw.print(i);
+                    pw.print(": "); pw.println(wanim);
+        }
+    }
+
+    // This is an animation that does nothing: it just immediately finishes
+    // itself every time it is called.  It is used as a stub animation in cases
+    // where we want to synchronize multiple things that may be animating.
+    static final class DummyAnimation extends Animation {
+        @Override
+        public boolean getTransformation(long currentTime, Transformation outTransformation) {
+            return false;
+        }
+    }
+
+}
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
new file mode 100644
index 0000000..ca4ad8a
--- /dev/null
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -0,0 +1,307 @@
+/*
+ * 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.server.wm;
+
+import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
+
+import com.android.server.input.InputApplicationHandle;
+import com.android.server.wm.WindowManagerService.H;
+
+import android.content.pm.ActivityInfo;
+import android.os.Message;
+import android.os.RemoteException;
+import android.util.Slog;
+import android.view.IApplicationToken;
+import android.view.View;
+import android.view.WindowManager;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+class AppTokenList extends ArrayList<AppWindowToken> {
+}
+
+/**
+ * Version of WindowToken that is specifically for a particular application (or
+ * really activity) that is displaying windows.
+ */
+class AppWindowToken extends WindowToken {
+    // Non-null only for application tokens.
+    final IApplicationToken appToken;
+
+    // All of the windows and child windows that are included in this
+    // application token.  Note this list is NOT sorted!
+    final WindowList allAppWindows = new WindowList();
+    final AppWindowAnimator mAppAnimator;
+
+    final WindowAnimator mAnimator;
+
+    int groupId = -1;
+    boolean appFullscreen;
+    int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+    boolean layoutConfigChanges;
+    boolean showWhenLocked;
+
+    // The input dispatching timeout for this application token in nanoseconds.
+    long inputDispatchingTimeoutNanos;
+
+    // These are used for determining when all windows associated with
+    // an activity have been drawn, so they can be made visible together
+    // at the same time.
+    // initialize so that it doesn't match mTransactionSequence which is an int.
+    long lastTransactionSequence = Long.MIN_VALUE;
+    int numInterestingWindows;
+    int numDrawnWindows;
+    boolean inPendingTransaction;
+    boolean allDrawn;
+    // Set to true when this app creates a surface while in the middle of an animation. In that
+    // case do not clear allDrawn until the animation completes.
+    boolean deferClearAllDrawn;
+
+    // Is this token going to be hidden in a little while?  If so, it
+    // won't be taken into account for setting the screen orientation.
+    boolean willBeHidden;
+
+    // Is this window's surface needed?  This is almost like hidden, except
+    // it will sometimes be true a little earlier: when the token has
+    // been shown, but is still waiting for its app transition to execute
+    // before making its windows shown.
+    boolean hiddenRequested;
+
+    // Have we told the window clients to hide themselves?
+    boolean clientHidden;
+
+    // Last visibility state we reported to the app token.
+    boolean reportedVisible;
+
+    // Last drawn state we reported to the app token.
+    boolean reportedDrawn;
+
+    // Set to true when the token has been removed from the window mgr.
+    boolean removed;
+
+    // Information about an application starting window if displayed.
+    StartingData startingData;
+    WindowState startingWindow;
+    View startingView;
+    boolean startingDisplayed;
+    boolean startingMoved;
+    boolean firstWindowDrawn;
+
+    // Input application handle used by the input dispatcher.
+    final InputApplicationHandle mInputApplicationHandle;
+
+    boolean mDeferRemoval;
+
+    AppWindowToken(WindowManagerService _service, IApplicationToken _token) {
+        super(_service, _token.asBinder(),
+                WindowManager.LayoutParams.TYPE_APPLICATION, true);
+        appWindowToken = this;
+        appToken = _token;
+        mInputApplicationHandle = new InputApplicationHandle(this);
+        mAnimator = service.mAnimator;
+        mAppAnimator = new AppWindowAnimator(this);
+    }
+
+    void sendAppVisibilityToClients() {
+        final int N = allAppWindows.size();
+        for (int i=0; i<N; i++) {
+            WindowState win = allAppWindows.get(i);
+            if (win == startingWindow && clientHidden) {
+                // Don't hide the starting window.
+                continue;
+            }
+            try {
+                if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
+                        "Setting visibility of " + win + ": " + (!clientHidden));
+                win.mClient.dispatchAppVisibility(!clientHidden);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    void updateReportedVisibilityLocked() {
+        if (appToken == null) {
+            return;
+        }
+
+        int numInteresting = 0;
+        int numVisible = 0;
+        int numDrawn = 0;
+        boolean nowGone = true;
+
+        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
+                "Update reported visibility: " + this);
+        final int N = allAppWindows.size();
+        for (int i=0; i<N; i++) {
+            WindowState win = allAppWindows.get(i);
+            if (win == startingWindow || win.mAppFreezing
+                    || win.mViewVisibility != View.VISIBLE
+                    || win.mAttrs.type == TYPE_APPLICATION_STARTING
+                    || win.mDestroying) {
+                continue;
+            }
+            if (WindowManagerService.DEBUG_VISIBILITY) {
+                Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
+                        + win.isDrawnLw()
+                        + ", isAnimating=" + win.mWinAnimator.isAnimating());
+                if (!win.isDrawnLw()) {
+                    Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurfaceControl
+                            + " pv=" + win.mPolicyVisibility
+                            + " mDrawState=" + win.mWinAnimator.mDrawState
+                            + " ah=" + win.mAttachedHidden
+                            + " th="
+                            + (win.mAppToken != null
+                                    ? win.mAppToken.hiddenRequested : false)
+                            + " a=" + win.mWinAnimator.mAnimating);
+                }
+            }
+            numInteresting++;
+            if (win.isDrawnLw()) {
+                numDrawn++;
+                if (!win.mWinAnimator.isAnimating()) {
+                    numVisible++;
+                }
+                nowGone = false;
+            } else if (win.mWinAnimator.isAnimating()) {
+                nowGone = false;
+            }
+        }
+
+        boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
+        boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
+        if (!nowGone) {
+            // If the app is not yet gone, then it can only become visible/drawn.
+            if (!nowDrawn) {
+                nowDrawn = reportedDrawn;
+            }
+            if (!nowVisible) {
+                nowVisible = reportedVisible;
+            }
+        }
+        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
+                + numInteresting + " visible=" + numVisible);
+        if (nowDrawn != reportedDrawn) {
+            if (nowDrawn) {
+                Message m = service.mH.obtainMessage(
+                        H.REPORT_APPLICATION_TOKEN_DRAWN, this);
+                service.mH.sendMessage(m);
+            }
+            reportedDrawn = nowDrawn;
+        }
+        if (nowVisible != reportedVisible) {
+            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
+                    WindowManagerService.TAG, "Visibility changed in " + this
+                    + ": vis=" + nowVisible);
+            reportedVisible = nowVisible;
+            Message m = service.mH.obtainMessage(
+                    H.REPORT_APPLICATION_TOKEN_WINDOWS,
+                    nowVisible ? 1 : 0,
+                    nowGone ? 1 : 0,
+                    this);
+            service.mH.sendMessage(m);
+        }
+    }
+
+    WindowState findMainWindow() {
+        int j = windows.size();
+        while (j > 0) {
+            j--;
+            WindowState win = windows.get(j);
+            if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
+                    || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
+                return win;
+            }
+        }
+        return null;
+    }
+
+    boolean isVisible() {
+        final int N = allAppWindows.size();
+        for (int i=0; i<N; i++) {
+            WindowState win = allAppWindows.get(i);
+            if (!win.mAppFreezing
+                    && (win.mViewVisibility == View.VISIBLE ||
+                        (win.mWinAnimator.isAnimating() &&
+                                !service.mAppTransition.isTransitionSet()))
+                    && !win.mDestroying && win.isDrawnLw()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    void dump(PrintWriter pw, String prefix) {
+        super.dump(pw, prefix);
+        if (appToken != null) {
+            pw.print(prefix); pw.println("app=true");
+        }
+        if (allAppWindows.size() > 0) {
+            pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
+        }
+        pw.print(prefix); pw.print("groupId="); pw.print(groupId);
+                pw.print(" appFullscreen="); pw.print(appFullscreen);
+                pw.print(" requestedOrientation="); pw.println(requestedOrientation);
+        pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
+                pw.print(" clientHidden="); pw.print(clientHidden);
+                pw.print(" willBeHidden="); pw.print(willBeHidden);
+                pw.print(" reportedDrawn="); pw.print(reportedDrawn);
+                pw.print(" reportedVisible="); pw.println(reportedVisible);
+        if (paused) {
+            pw.print(prefix); pw.print("paused="); pw.println(paused);
+        }
+        if (numInterestingWindows != 0 || numDrawnWindows != 0
+                || allDrawn || mAppAnimator.allDrawn) {
+            pw.print(prefix); pw.print("numInterestingWindows=");
+                    pw.print(numInterestingWindows);
+                    pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
+                    pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
+                    pw.print(" allDrawn="); pw.print(allDrawn);
+                    pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
+                    pw.println(")");
+        }
+        if (inPendingTransaction) {
+            pw.print(prefix); pw.print("inPendingTransaction=");
+                    pw.println(inPendingTransaction);
+        }
+        if (startingData != null || removed || firstWindowDrawn) {
+            pw.print(prefix); pw.print("startingData="); pw.print(startingData);
+                    pw.print(" removed="); pw.print(removed);
+                    pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
+        }
+        if (startingWindow != null || startingView != null
+                || startingDisplayed || startingMoved) {
+            pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
+                    pw.print(" startingView="); pw.print(startingView);
+                    pw.print(" startingDisplayed="); pw.print(startingDisplayed);
+                    pw.print(" startingMoved"); pw.println(startingMoved);
+        }
+    }
+
+    @Override
+    public String toString() {
+        if (stringName == null) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("AppWindowToken{");
+            sb.append(Integer.toHexString(System.identityHashCode(this)));
+            sb.append(" token="); sb.append(token); sb.append('}');
+            stringName = sb.toString();
+        }
+        return stringName;
+    }
+}
diff --git a/services/java/com/android/server/wm/BlackFrame.java b/services/core/java/com/android/server/wm/BlackFrame.java
similarity index 100%
rename from services/java/com/android/server/wm/BlackFrame.java
rename to services/core/java/com/android/server/wm/BlackFrame.java
diff --git a/services/core/java/com/android/server/wm/DimLayer.java b/services/core/java/com/android/server/wm/DimLayer.java
new file mode 100644
index 0000000..c09ea5c
--- /dev/null
+++ b/services/core/java/com/android/server/wm/DimLayer.java
@@ -0,0 +1,323 @@
+/*
+ * 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.server.wm;
+
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.os.SystemClock;
+import android.util.Slog;
+import android.view.DisplayInfo;
+import android.view.SurfaceControl;
+
+import java.io.PrintWriter;
+
+public class DimLayer {
+    private static final String TAG = "DimLayer";
+    private static final boolean DEBUG = false;
+
+    /** Reference to the owner of this object. */
+    final DisplayContent mDisplayContent;
+
+    /** Actual surface that dims */
+    SurfaceControl mDimSurface;
+
+    /** Last value passed to mDimSurface.setAlpha() */
+    float mAlpha = 0;
+
+    /** Last value passed to mDimSurface.setLayer() */
+    int mLayer = -1;
+
+    /** Next values to pass to mDimSurface.setPosition() and mDimSurface.setSize() */
+    Rect mBounds = new Rect();
+
+    /** Last values passed to mDimSurface.setPosition() and mDimSurface.setSize() */
+    Rect mLastBounds = new Rect();
+
+    /** True after mDimSurface.show() has been called, false after mDimSurface.hide(). */
+    private boolean mShowing = false;
+
+    /** Value of mAlpha when beginning transition to mTargetAlpha */
+    float mStartAlpha = 0;
+
+    /** Final value of mAlpha following transition */
+    float mTargetAlpha = 0;
+
+    /** Time in units of SystemClock.uptimeMillis() at which the current transition started */
+    long mStartTime;
+
+    /** Time in milliseconds to take to transition from mStartAlpha to mTargetAlpha */
+    long mDuration;
+
+    /** Owning stack */
+    final TaskStack mStack;
+
+    DimLayer(WindowManagerService service, TaskStack stack, DisplayContent displayContent) {
+        mStack = stack;
+        mDisplayContent = displayContent;
+        final int displayId = mDisplayContent.getDisplayId();
+        if (DEBUG) Slog.v(TAG, "Ctor: displayId=" + displayId);
+        SurfaceControl.openTransaction();
+        try {
+            if (WindowManagerService.DEBUG_SURFACE_TRACE) {
+                mDimSurface = new WindowStateAnimator.SurfaceTrace(service.mFxSession,
+                    "DimSurface",
+                    16, 16, PixelFormat.OPAQUE,
+                    SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN);
+            } else {
+                mDimSurface = new SurfaceControl(service.mFxSession, TAG,
+                    16, 16, PixelFormat.OPAQUE,
+                    SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN);
+            }
+            if (WindowManagerService.SHOW_TRANSACTIONS ||
+                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(TAG,
+                            "  DIM " + mDimSurface + ": CREATE");
+            mDimSurface.setLayerStack(displayId);
+        } catch (Exception e) {
+            Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
+        } finally {
+            SurfaceControl.closeTransaction();
+        }
+    }
+
+    /** Return true if dim layer is showing */
+    boolean isDimming() {
+        return mTargetAlpha != 0;
+    }
+
+    /** Return true if in a transition period */
+    boolean isAnimating() {
+        return mTargetAlpha != mAlpha;
+    }
+
+    float getTargetAlpha() {
+        return mTargetAlpha;
+    }
+
+    void setLayer(int layer) {
+        if (mLayer != layer) {
+            mLayer = layer;
+            mDimSurface.setLayer(layer);
+        }
+    }
+
+    int getLayer() {
+        return mLayer;
+    }
+
+    private void setAlpha(float alpha) {
+        if (mAlpha != alpha) {
+            if (DEBUG) Slog.v(TAG, "setAlpha alpha=" + alpha);
+            try {
+                mDimSurface.setAlpha(alpha);
+                if (alpha == 0 && mShowing) {
+                    if (DEBUG) Slog.v(TAG, "setAlpha hiding");
+                    mDimSurface.hide();
+                    mShowing = false;
+                } else if (alpha > 0 && !mShowing) {
+                    if (DEBUG) Slog.v(TAG, "setAlpha showing");
+                    mDimSurface.show();
+                    mShowing = true;
+                }
+            } catch (RuntimeException e) {
+                Slog.w(TAG, "Failure setting alpha immediately", e);
+            }
+            mAlpha = alpha;
+        }
+    }
+
+    /**
+     * @param layer The new layer value.
+     * @param inTransaction Whether the call is made within a surface transaction.
+     */
+    void adjustSurface(int layer, boolean inTransaction) {
+        final int dw, dh;
+        final float xPos, yPos;
+        if (!mStack.isFullscreen()) {
+            dw = mBounds.width();
+            dh = mBounds.height();
+            xPos = mBounds.left;
+            yPos = mBounds.top;
+        } else {
+            // Set surface size to screen size.
+            final DisplayInfo info = mDisplayContent.getDisplayInfo();
+            // Multiply by 1.5 so that rotating a frozen surface that includes this does not expose
+            // a corner.
+            dw = (int) (info.logicalWidth * 1.5);
+            dh = (int) (info.logicalHeight * 1.5);
+            // back off position so 1/4 of Surface is before and 1/4 is after.
+            xPos = -1 * dw / 6;
+            yPos = -1 * dh / 6;
+        }
+
+        try {
+            if (!inTransaction) {
+                SurfaceControl.openTransaction();
+            }
+            mDimSurface.setPosition(xPos, yPos);
+            mDimSurface.setSize(dw, dh);
+            mDimSurface.setLayer(layer);
+        } catch (RuntimeException e) {
+            Slog.w(TAG, "Failure setting size or layer", e);
+        } finally {
+            if (!inTransaction) {
+                SurfaceControl.closeTransaction();
+            }
+        }
+        mLastBounds.set(mBounds);
+        mLayer = layer;
+    }
+
+    // Assumes that surface transactions are currently closed.
+    void setBounds(Rect bounds) {
+        mBounds.set(bounds);
+        if (isDimming() && !mLastBounds.equals(bounds)) {
+            adjustSurface(mLayer, false);
+        }
+    }
+
+    /**
+     * @param duration The time to test.
+     * @return True if the duration would lead to an earlier end to the current animation.
+     */
+    private boolean durationEndsEarlier(long duration) {
+        return SystemClock.uptimeMillis() + duration < mStartTime + mDuration;
+    }
+
+    /** Jump to the end of the animation.
+     * NOTE: Must be called with Surface transaction open. */
+    void show() {
+        if (isAnimating()) {
+            if (DEBUG) Slog.v(TAG, "show: immediate");
+            show(mLayer, mTargetAlpha, 0);
+        }
+    }
+
+    /**
+     * Begin an animation to a new dim value.
+     * NOTE: Must be called with Surface transaction open.
+     *
+     * @param layer The layer to set the surface to.
+     * @param alpha The dim value to end at.
+     * @param duration How long to take to get there in milliseconds.
+     */
+    void show(int layer, float alpha, long duration) {
+        if (DEBUG) Slog.v(TAG, "show: layer=" + layer + " alpha=" + alpha
+                + " duration=" + duration);
+        if (mDimSurface == null) {
+            Slog.e(TAG, "show: no Surface");
+            // Make sure isAnimating() returns false.
+            mTargetAlpha = mAlpha = 0;
+            return;
+        }
+
+        if (!mLastBounds.equals(mBounds) || mLayer != layer) {
+            adjustSurface(layer, true);
+        }
+
+        long curTime = SystemClock.uptimeMillis();
+        final boolean animating = isAnimating();
+        if ((animating && (mTargetAlpha != alpha || durationEndsEarlier(duration)))
+                || (!animating && mAlpha != alpha)) {
+            if (duration <= 0) {
+                // No animation required, just set values.
+                setAlpha(alpha);
+            } else {
+                // Start or continue animation with new parameters.
+                mStartAlpha = mAlpha;
+                mStartTime = curTime;
+                mDuration = duration;
+            }
+        }
+        if (DEBUG) Slog.v(TAG, "show: mStartAlpha=" + mStartAlpha + " mStartTime=" + mStartTime);
+        mTargetAlpha = alpha;
+    }
+
+    /** Immediate hide.
+     * NOTE: Must be called with Surface transaction open. */
+    void hide() {
+        if (mShowing) {
+            if (DEBUG) Slog.v(TAG, "hide: immediate");
+            hide(0);
+        }
+    }
+
+    /**
+     * Gradually fade to transparent.
+     * NOTE: Must be called with Surface transaction open.
+     *
+     * @param duration Time to fade in milliseconds.
+     */
+    void hide(long duration) {
+        if (mShowing && (mTargetAlpha != 0 || durationEndsEarlier(duration))) {
+            if (DEBUG) Slog.v(TAG, "hide: duration=" + duration);
+            show(mLayer, 0, duration);
+        }
+    }
+
+    /**
+     * Advance the dimming per the last #show(int, float, long) call.
+     * NOTE: Must be called with Surface transaction open.
+     *
+     * @return True if animation is still required after this step.
+     */
+    boolean stepAnimation() {
+        if (mDimSurface == null) {
+            Slog.e(TAG, "stepAnimation: null Surface");
+            // Ensure that isAnimating() returns false;
+            mTargetAlpha = mAlpha = 0;
+            return false;
+        }
+
+        if (isAnimating()) {
+            final long curTime = SystemClock.uptimeMillis();
+            final float alphaDelta = mTargetAlpha - mStartAlpha;
+            float alpha = mStartAlpha + alphaDelta * (curTime - mStartTime) / mDuration;
+            if (alphaDelta > 0 && alpha > mTargetAlpha ||
+                    alphaDelta < 0 && alpha < mTargetAlpha) {
+                // Don't exceed limits.
+                alpha = mTargetAlpha;
+            }
+            if (DEBUG) Slog.v(TAG, "stepAnimation: curTime=" + curTime + " alpha=" + alpha);
+            setAlpha(alpha);
+        }
+
+        return isAnimating();
+    }
+
+    /** Cleanup */
+    void destroySurface() {
+        if (DEBUG) Slog.v(TAG, "destroySurface.");
+        if (mDimSurface != null) {
+            mDimSurface.destroy();
+            mDimSurface = null;
+        }
+    }
+
+    public void printTo(String prefix, PrintWriter pw) {
+        pw.print(prefix); pw.print("mDimSurface="); pw.print(mDimSurface);
+                pw.print(" mLayer="); pw.print(mLayer);
+                pw.print(" mAlpha="); pw.println(mAlpha);
+        pw.print(prefix); pw.print("mLastBounds="); pw.print(mLastBounds.toShortString());
+                pw.print(" mBounds="); pw.println(mBounds.toShortString());
+        pw.print(prefix); pw.print("Last animation: ");
+                pw.print(" mDuration="); pw.print(mDuration);
+                pw.print(" mStartTime="); pw.print(mStartTime);
+                pw.print(" curTime="); pw.println(SystemClock.uptimeMillis());
+        pw.print(prefix); pw.print(" mStartAlpha="); pw.print(mStartAlpha);
+                pw.print(" mTargetAlpha="); pw.println(mTargetAlpha);
+    }
+}
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
new file mode 100644
index 0000000..d4bcd5c
--- /dev/null
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -0,0 +1,415 @@
+/*
+ * 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.server.wm;
+
+import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
+import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
+import static com.android.server.wm.WindowManagerService.TAG;
+
+import android.graphics.Rect;
+import android.graphics.Region;
+import android.util.Slog;
+import android.view.Display;
+import android.view.DisplayInfo;
+import android.view.Surface;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+class DisplayContentList extends ArrayList<DisplayContent> {
+}
+
+/**
+ * Utility class for keeping track of the WindowStates and other pertinent contents of a
+ * particular Display.
+ *
+ * IMPORTANT: No method from this class should ever be used without holding
+ * WindowManagerService.mWindowMap.
+ */
+class DisplayContent {
+
+    /** Unique identifier of this stack. */
+    private final int mDisplayId;
+
+    /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
+     * from mDisplayWindows; */
+    private final WindowList mWindows = new WindowList();
+
+    // This protects the following display size properties, so that
+    // getDisplaySize() doesn't need to acquire the global lock.  This is
+    // needed because the window manager sometimes needs to use ActivityThread
+    // while it has its global state locked (for example to load animation
+    // resources), but the ActivityThread also needs get the current display
+    // size sometimes when it has its package lock held.
+    //
+    // These will only be modified with both mWindowMap and mDisplaySizeLock
+    // held (in that order) so the window manager doesn't need to acquire this
+    // lock when needing these values in its normal operation.
+    final Object mDisplaySizeLock = new Object();
+    int mInitialDisplayWidth = 0;
+    int mInitialDisplayHeight = 0;
+    int mInitialDisplayDensity = 0;
+    int mBaseDisplayWidth = 0;
+    int mBaseDisplayHeight = 0;
+    int mBaseDisplayDensity = 0;
+    private final DisplayInfo mDisplayInfo = new DisplayInfo();
+    private final Display mDisplay;
+
+    Rect mBaseDisplayRect = new Rect();
+    Rect mContentRect = new Rect();
+
+    // Accessed directly by all users.
+    boolean layoutNeeded;
+    int pendingLayoutChanges;
+    final boolean isDefaultDisplay;
+
+    /** Window tokens that are in the process of exiting, but still on screen for animations. */
+    final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
+
+    /** Array containing all TaskStacks on this display.  Array
+     * is stored in display order with the current bottom stack at 0. */
+    private final ArrayList<TaskStack> mStacks = new ArrayList<TaskStack>();
+
+    /** A special TaskStack with id==HOME_STACK_ID that moves to the bottom whenever any TaskStack
+     * (except a future lockscreen TaskStack) moves to the top. */
+    private TaskStack mHomeStack = null;
+
+    /** Detect user tapping outside of current focused stack bounds .*/
+    StackTapPointerEventListener mTapDetector;
+
+    /** Detect user tapping outside of current focused stack bounds .*/
+    Region mTouchExcludeRegion = new Region();
+
+    /** Save allocating when calculating rects */
+    Rect mTmpRect = new Rect();
+
+    /** For gathering Task objects in order. */
+    final ArrayList<Task> mTmpTaskHistory = new ArrayList<Task>();
+
+    final WindowManagerService mService;
+
+    /** Remove this display when animation on it has completed. */
+    boolean mDeferredRemoval;
+
+    /**
+     * @param display May not be null.
+     * @param service You know.
+     */
+    DisplayContent(Display display, WindowManagerService service) {
+        mDisplay = display;
+        mDisplayId = display.getDisplayId();
+        display.getDisplayInfo(mDisplayInfo);
+        isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
+        mService = service;
+    }
+
+    int getDisplayId() {
+        return mDisplayId;
+    }
+
+    WindowList getWindowList() {
+        return mWindows;
+    }
+
+    Display getDisplay() {
+        return mDisplay;
+    }
+
+    DisplayInfo getDisplayInfo() {
+        return mDisplayInfo;
+    }
+
+    /**
+     * Returns true if the specified UID has access to this display.
+     */
+    public boolean hasAccess(int uid) {
+        return mDisplay.hasAccess(uid);
+    }
+
+    public boolean isPrivate() {
+        return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
+    }
+
+    ArrayList<TaskStack> getStacks() {
+        return mStacks;
+    }
+
+    /**
+     * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
+     * @return All the Tasks, in order, on this display.
+     */
+    ArrayList<Task> getTasks() {
+        mTmpTaskHistory.clear();
+        final int numStacks = mStacks.size();
+        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+            mTmpTaskHistory.addAll(mStacks.get(stackNdx).getTasks());
+        }
+        return mTmpTaskHistory;
+    }
+
+    TaskStack getHomeStack() {
+        if (mHomeStack == null) {
+            Slog.e(TAG, "getHomeStack: Returning null from this=" + this);
+        }
+        return mHomeStack;
+    }
+
+    void updateDisplayInfo() {
+        mDisplay.getDisplayInfo(mDisplayInfo);
+        for (int i = mStacks.size() - 1; i >= 0; --i) {
+            mStacks.get(i).updateDisplayInfo();
+        }
+    }
+
+    void getLogicalDisplayRect(Rect out) {
+        // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
+        final int orientation = mDisplayInfo.rotation;
+        boolean rotated = (orientation == Surface.ROTATION_90
+                || orientation == Surface.ROTATION_270);
+        final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
+        final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
+        int width = mDisplayInfo.logicalWidth;
+        int left = (physWidth - width) / 2;
+        int height = mDisplayInfo.logicalHeight;
+        int top = (physHeight - height) / 2;
+        out.set(left, top, left + width, top + height);
+    }
+
+    /** Refer to {@link WindowManagerService#attachStack(int, int)} */
+    void attachStack(TaskStack stack) {
+        if (stack.mStackId == HOME_STACK_ID) {
+            if (mHomeStack != null) {
+                throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
+            }
+            mHomeStack = stack;
+        }
+        mStacks.add(stack);
+        layoutNeeded = true;
+    }
+
+    void moveStack(TaskStack stack, boolean toTop) {
+        mStacks.remove(stack);
+        mStacks.add(toTop ? mStacks.size() : 0, stack);
+    }
+
+    void detachStack(TaskStack stack) {
+        mStacks.remove(stack);
+    }
+
+    /**
+     * Propagate the new bounds to all child stacks.
+     * @param contentRect The bounds to apply at the top level.
+     */
+    void resize(Rect contentRect) {
+        mContentRect.set(contentRect);
+    }
+
+    int stackIdFromPoint(int x, int y) {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mStacks.get(stackNdx);
+            stack.getBounds(mTmpRect);
+            if (mTmpRect.contains(x, y)) {
+                return stack.mStackId;
+            }
+        }
+        return -1;
+    }
+
+    void setTouchExcludeRegion(TaskStack focusedStack) {
+        mTouchExcludeRegion.set(mBaseDisplayRect);
+        WindowList windows = getWindowList();
+        for (int i = windows.size() - 1; i >= 0; --i) {
+            final WindowState win = windows.get(i);
+            final TaskStack stack = win.getStack();
+            if (win.isVisibleLw() && stack != null && stack != focusedStack) {
+                mTmpRect.set(win.mVisibleFrame);
+                mTmpRect.intersect(win.mVisibleInsets);
+                mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
+            }
+        }
+    }
+
+    void switchUserStacks(int newUserId) {
+        final WindowList windows = getWindowList();
+        for (int i = 0; i < windows.size(); i++) {
+            final WindowState win = windows.get(i);
+            if (win.isHiddenFromUserLocked()) {
+                if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing " + newUserId + " hiding "
+                        + win + ", attrs=" + win.mAttrs.type + ", belonging to "
+                        + win.mOwnerUid);
+                win.hideLw(false);
+            }
+        }
+
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            mStacks.get(stackNdx).switchUser(newUserId);
+        }
+    }
+
+    void resetAnimationBackgroundAnimator() {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            mStacks.get(stackNdx).resetAnimationBackgroundAnimator();
+        }
+    }
+
+    boolean animateDimLayers() {
+        boolean result = false;
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            result |= mStacks.get(stackNdx).animateDimLayers();
+        }
+        return result;
+    }
+
+    void resetDimming() {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            mStacks.get(stackNdx).resetDimmingTag();
+        }
+    }
+
+    boolean isDimming() {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            if (mStacks.get(stackNdx).isDimming()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    void stopDimmingIfNeeded() {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            mStacks.get(stackNdx).stopDimmingIfNeeded();
+        }
+    }
+
+    void close() {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            mStacks.get(stackNdx).close();
+        }
+    }
+
+    boolean isAnimating() {
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mStacks.get(stackNdx);
+            if (stack.isAnimating()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    void checkForDeferredActions() {
+        boolean animating = false;
+        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mStacks.get(stackNdx);
+            if (stack.isAnimating()) {
+                animating = true;
+            } else {
+                if (stack.mDeferDetach) {
+                    mService.detachStackLocked(this, stack);
+                }
+                final ArrayList<Task> tasks = stack.getTasks();
+                for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                    final Task task = tasks.get(taskNdx);
+                    AppTokenList tokens = task.mAppTokens;
+                    for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                        AppWindowToken wtoken = tokens.get(tokenNdx);
+                        if (wtoken.mDeferRemoval) {
+                            wtoken.mDeferRemoval = false;
+                            mService.removeAppFromTaskLocked(wtoken);
+                        }
+                    }
+                    if (task.mDeferRemoval) {
+                        task.mDeferRemoval = false;
+                        mService.removeTaskLocked(task);
+                    }
+                }
+            }
+        }
+        if (!animating && mDeferredRemoval) {
+            mService.onDisplayRemoved(mDisplayId);
+        }
+    }
+
+    public void dump(String prefix, PrintWriter pw) {
+        pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
+        final String subPrefix = "  " + prefix;
+        pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
+            pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
+            pw.print("dpi");
+            if (mInitialDisplayWidth != mBaseDisplayWidth
+                    || mInitialDisplayHeight != mBaseDisplayHeight
+                    || mInitialDisplayDensity != mBaseDisplayDensity) {
+                pw.print(" base=");
+                pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
+                pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
+            }
+            pw.print(" cur=");
+            pw.print(mDisplayInfo.logicalWidth);
+            pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
+            pw.print(" app=");
+            pw.print(mDisplayInfo.appWidth);
+            pw.print("x"); pw.print(mDisplayInfo.appHeight);
+            pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
+            pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
+            pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
+            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 bottom up Z order:");
+        int ndx = 0;
+        final int numStacks = mStacks.size();
+        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+            ArrayList<Task> tasks = mStacks.get(stackNdx).getTasks();
+            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                    final AppWindowToken wtoken = tokens.get(tokenNdx);
+                    pw.print("  App #"); pw.print(ndx++);
+                            pw.print(' '); pw.print(wtoken); pw.println(":");
+                    wtoken.dump(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--) {
+                WindowToken token = mExitingTokens.get(i);
+                pw.print("  Exiting #"); pw.print(i);
+                pw.print(' '); pw.print(token);
+                pw.println(':');
+                token.dump(pw, "    ");
+            }
+        }
+        pw.println();
+    }
+
+    @Override
+    public String toString() {
+        return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mStacks;
+    }
+}
diff --git a/services/java/com/android/server/wm/DisplayMagnifier.java b/services/core/java/com/android/server/wm/DisplayMagnifier.java
similarity index 100%
rename from services/java/com/android/server/wm/DisplayMagnifier.java
rename to services/core/java/com/android/server/wm/DisplayMagnifier.java
diff --git a/services/java/com/android/server/wm/DisplaySettings.java b/services/core/java/com/android/server/wm/DisplaySettings.java
similarity index 100%
rename from services/java/com/android/server/wm/DisplaySettings.java
rename to services/core/java/com/android/server/wm/DisplaySettings.java
diff --git a/services/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java
similarity index 100%
rename from services/java/com/android/server/wm/DragState.java
rename to services/core/java/com/android/server/wm/DragState.java
diff --git a/services/java/com/android/server/wm/FakeWindowImpl.java b/services/core/java/com/android/server/wm/FakeWindowImpl.java
similarity index 100%
rename from services/java/com/android/server/wm/FakeWindowImpl.java
rename to services/core/java/com/android/server/wm/FakeWindowImpl.java
diff --git a/services/core/java/com/android/server/wm/FocusedStackFrame.java b/services/core/java/com/android/server/wm/FocusedStackFrame.java
new file mode 100644
index 0000000..f1f5fe8
--- /dev/null
+++ b/services/core/java/com/android/server/wm/FocusedStackFrame.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2013 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.wm;
+
+import static com.android.server.wm.WindowManagerService.DEBUG_STACK;
+import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
+
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.Region;
+import android.util.Slog;
+import android.view.Display;
+import android.view.Surface.OutOfResourcesException;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.view.SurfaceSession;
+
+import com.android.server.wm.WindowStateAnimator.SurfaceTrace;
+
+class FocusedStackFrame {
+    private static final String TAG = "FocusedStackFrame";
+    private static final int THICKNESS = 10;
+    private static final float ALPHA = 0.3f;
+
+    private final SurfaceControl mSurfaceControl;
+    private final Surface mSurface = new Surface();
+    private final Rect mLastBounds = new Rect();
+    final Rect mBounds = new Rect();
+    private final Rect mTmpDrawRect = new Rect();
+
+    public FocusedStackFrame(Display display, SurfaceSession session) {
+        SurfaceControl ctrl = null;
+        try {
+            if (DEBUG_SURFACE_TRACE) {
+                ctrl = new SurfaceTrace(session, "FocusedStackFrame",
+                    1, 1, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
+            } else {
+                ctrl = new SurfaceControl(session, "FocusedStackFrame",
+                    1, 1, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
+            }
+            ctrl.setLayerStack(display.getLayerStack());
+            ctrl.setAlpha(ALPHA);
+            mSurface.copyFrom(ctrl);
+        } catch (OutOfResourcesException e) {
+        }
+        mSurfaceControl = ctrl;
+    }
+
+    private void draw(Rect bounds, int color) {
+        if (false && DEBUG_STACK) Slog.i(TAG, "draw: bounds=" + bounds.toShortString() +
+                " color=" + Integer.toHexString(color));
+        mTmpDrawRect.set(bounds);
+        Canvas c = null;
+        try {
+            c = mSurface.lockCanvas(mTmpDrawRect);
+        } catch (IllegalArgumentException e) {
+        } catch (Surface.OutOfResourcesException e) {
+        }
+        if (c == null) {
+            return;
+        }
+
+        final int w = bounds.width();
+        final int h = bounds.height();
+
+        // Top
+        mTmpDrawRect.set(0, 0, w, THICKNESS);
+        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
+        c.drawColor(color);
+        // Left (not including Top or Bottom stripe).
+        mTmpDrawRect.set(0, THICKNESS, THICKNESS, h - THICKNESS);
+        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
+        c.drawColor(color);
+        // Right (not including Top or Bottom stripe).
+        mTmpDrawRect.set(w - THICKNESS, THICKNESS, w, h - THICKNESS);
+        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
+        c.drawColor(color);
+        // Bottom
+        mTmpDrawRect.set(0, h - THICKNESS, w, h);
+        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
+        c.drawColor(color);
+
+        mSurface.unlockCanvasAndPost(c);
+    }
+
+    private void positionSurface(Rect bounds) {
+        if (false && DEBUG_STACK) Slog.i(TAG, "positionSurface: bounds=" + bounds.toShortString());
+        mSurfaceControl.setSize(bounds.width(), bounds.height());
+        mSurfaceControl.setPosition(bounds.left, bounds.top);
+    }
+
+    // Note: caller responsible for being inside
+    // Surface.openTransaction() / closeTransaction()
+    public void setVisibility(boolean on) {
+        if (false && DEBUG_STACK) Slog.i(TAG, "setVisibility: on=" + on +
+                " mLastBounds=" + mLastBounds.toShortString() +
+                " mBounds=" + mBounds.toShortString());
+        if (mSurfaceControl == null) {
+            return;
+        }
+        if (on) {
+            if (!mLastBounds.equals(mBounds)) {
+                // Erase the previous rectangle.
+                positionSurface(mLastBounds);
+                draw(mLastBounds, Color.TRANSPARENT);
+                // Draw the latest rectangle.
+                positionSurface(mBounds);
+                draw(mBounds, Color.WHITE);
+                // Update the history.
+                mLastBounds.set(mBounds);
+            }
+            mSurfaceControl.show();
+        } else {
+            mSurfaceControl.hide();
+        }
+    }
+
+    public void setBounds(TaskStack stack) {
+        stack.getBounds(mBounds);
+        if (false && DEBUG_STACK) Slog.i(TAG, "setBounds: bounds=" + mBounds);
+    }
+
+    public void setLayer(int layer) {
+        mSurfaceControl.setLayer(layer);
+    }
+}
diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java
new file mode 100644
index 0000000..4aae5c1
--- /dev/null
+++ b/services/core/java/com/android/server/wm/InputMonitor.java
@@ -0,0 +1,493 @@
+/*
+ * Copyright (C) 2010 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.wm;
+
+import com.android.server.input.InputManagerService;
+import com.android.server.input.InputApplicationHandle;
+import com.android.server.input.InputWindowHandle;
+
+import android.app.ActivityManagerNative;
+import android.graphics.Rect;
+import android.os.RemoteException;
+import android.util.Log;
+import android.util.Slog;
+import android.view.Display;
+import android.view.InputChannel;
+import android.view.KeyEvent;
+import android.view.WindowManager;
+
+import java.util.Arrays;
+
+final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
+    private final WindowManagerService mService;
+    
+    // Current window with input focus for keys and other non-touch events.  May be null.
+    private WindowState mInputFocus;
+    
+    // When true, prevents input dispatch from proceeding until set to false again.
+    private boolean mInputDispatchFrozen;
+    
+    // When true, input dispatch proceeds normally.  Otherwise all events are dropped.
+    // Initially false, so that input does not get dispatched until boot is finished at
+    // which point the ActivityManager will enable dispatching.
+    private boolean mInputDispatchEnabled;
+
+    // When true, need to call updateInputWindowsLw().
+    private boolean mUpdateInputWindowsNeeded = true;
+
+    // Array of window handles to provide to the input dispatcher.
+    private InputWindowHandle[] mInputWindowHandles;
+    private int mInputWindowHandleCount;
+
+    // Set to true when the first input device configuration change notification
+    // is received to indicate that the input devices are ready.
+    private final Object mInputDevicesReadyMonitor = new Object();
+    private boolean mInputDevicesReady;
+
+    Rect mTmpRect = new Rect();
+
+    public InputMonitor(WindowManagerService service) {
+        mService = service;
+    }
+    
+    /* Notifies the window manager about a broken input channel.
+     * 
+     * Called by the InputManager.
+     */
+    @Override
+    public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
+        if (inputWindowHandle == null) {
+            return;
+        }
+
+        synchronized (mService.mWindowMap) {
+            WindowState windowState = (WindowState) inputWindowHandle.windowState;
+            if (windowState != null) {
+                Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState);
+                mService.removeWindowLocked(windowState.mSession, windowState);
+            }
+        }
+    }
+    
+    /* Notifies the window manager about an application that is not responding.
+     * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
+     * 
+     * Called by the InputManager.
+     */
+    @Override
+    public long notifyANR(InputApplicationHandle inputApplicationHandle,
+            InputWindowHandle inputWindowHandle, String reason) {
+        AppWindowToken appWindowToken = null;
+        WindowState windowState = null;
+        boolean aboveSystem = false;
+        synchronized (mService.mWindowMap) {
+            if (inputWindowHandle != null) {
+                windowState = (WindowState) inputWindowHandle.windowState;
+                if (windowState != null) {
+                    appWindowToken = windowState.mAppToken;
+                }
+            }
+            if (appWindowToken == null && inputApplicationHandle != null) {
+                appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
+            }
+
+            if (windowState != null) {
+                Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
+                        + "sending to " + windowState.mAttrs.getTitle()
+                        + ".  Reason: " + reason);
+                // Figure out whether this window is layered above system windows.
+                // We need to do this here to help the activity manager know how to
+                // layer its ANR dialog.
+                int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw(
+                        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+                aboveSystem = windowState.mBaseLayer > systemAlertLayer;
+            } else if (appWindowToken != null) {
+                Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
+                        + "sending to application " + appWindowToken.stringName
+                        + ".  Reason: " + reason);
+            } else {
+                Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
+                        + ".  Reason: " + reason);
+            }
+
+            mService.saveANRStateLocked(appWindowToken, windowState, reason);
+        }
+
+        if (appWindowToken != null && appWindowToken.appToken != null) {
+            try {
+                // Notify the activity manager about the timeout and let it decide whether
+                // to abort dispatching or keep waiting.
+                boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason);
+                if (! abort) {
+                    // The activity manager declined to abort dispatching.
+                    // Wait a bit longer and timeout again later.
+                    return appWindowToken.inputDispatchingTimeoutNanos;
+                }
+            } catch (RemoteException ex) {
+            }
+        } else if (windowState != null) {
+            try {
+                // Notify the activity manager about the timeout and let it decide whether
+                // to abort dispatching or keep waiting.
+                long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut(
+                        windowState.mSession.mPid, aboveSystem, reason);
+                if (timeout >= 0) {
+                    // The activity manager declined to abort dispatching.
+                    // Wait a bit longer and timeout again later.
+                    return timeout;
+                }
+            } catch (RemoteException ex) {
+            }
+        }
+        return 0; // abort dispatching
+    }
+
+    private void addInputWindowHandleLw(final InputWindowHandle windowHandle) {
+        if (mInputWindowHandles == null) {
+            mInputWindowHandles = new InputWindowHandle[16];
+        }
+        if (mInputWindowHandleCount >= mInputWindowHandles.length) {
+            mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
+                    mInputWindowHandleCount * 2);
+        }
+        mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
+    }
+
+    private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle,
+            final WindowState child, int flags, int privateFlags, final int type,
+            final boolean isVisible, final boolean hasFocus, final boolean hasWallpaper) {
+        // Add a window to our list of input windows.
+        inputWindowHandle.name = child.toString();
+        final boolean modal = (flags & (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
+                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) == 0;
+        if (modal && child.mAppToken != null) {
+            // Limit the outer touch to the activity stack region.
+            flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
+            child.getStackBounds(mTmpRect);
+            inputWindowHandle.touchableRegion.set(mTmpRect);
+        } else {
+            // Not modal or full screen modal
+            child.getTouchableRegion(inputWindowHandle.touchableRegion);
+        }
+        inputWindowHandle.layoutParamsFlags = flags;
+        inputWindowHandle.layoutParamsPrivateFlags = privateFlags;
+        inputWindowHandle.layoutParamsType = type;
+        inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
+        inputWindowHandle.visible = isVisible;
+        inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
+        inputWindowHandle.hasFocus = hasFocus;
+        inputWindowHandle.hasWallpaper = hasWallpaper;
+        inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
+        inputWindowHandle.layer = child.mLayer;
+        inputWindowHandle.ownerPid = child.mSession.mPid;
+        inputWindowHandle.ownerUid = child.mSession.mUid;
+        inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
+
+        final Rect frame = child.mFrame;
+        inputWindowHandle.frameLeft = frame.left;
+        inputWindowHandle.frameTop = frame.top;
+        inputWindowHandle.frameRight = frame.right;
+        inputWindowHandle.frameBottom = frame.bottom;
+
+        if (child.mGlobalScale != 1) {
+            // If we are scaling the window, input coordinates need
+            // to be inversely scaled to map from what is on screen
+            // to what is actually being touched in the UI.
+            inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
+        } else {
+            inputWindowHandle.scaleFactor = 1;
+        }
+
+
+        addInputWindowHandleLw(inputWindowHandle);
+    }
+
+    private void clearInputWindowHandlesLw() {
+        while (mInputWindowHandleCount != 0) {
+            mInputWindowHandles[--mInputWindowHandleCount] = null;
+        }
+    }
+
+    public void setUpdateInputWindowsNeededLw() {
+        mUpdateInputWindowsNeeded = true;
+    }
+
+    /* Updates the cached window information provided to the input dispatcher. */
+    public void updateInputWindowsLw(boolean force) {
+        if (!force && !mUpdateInputWindowsNeeded) {
+            return;
+        }
+        mUpdateInputWindowsNeeded = false;
+
+        if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw");
+
+        // Populate the input window list with information about all of the windows that
+        // could potentially receive input.
+        // As an optimization, we could try to prune the list of windows but this turns
+        // out to be difficult because only the native code knows for sure which window
+        // currently has touch focus.
+        final WindowStateAnimator universeBackground = mService.mAnimator.mUniverseBackground;
+        final int aboveUniverseLayer = mService.mAnimator.mAboveUniverseLayer;
+        boolean addedUniverse = false;
+
+        // If there's a drag in flight, provide a pseudowindow to catch drag input
+        final boolean inDrag = (mService.mDragState != null);
+        if (inDrag) {
+            if (WindowManagerService.DEBUG_DRAG) {
+                Log.d(WindowManagerService.TAG, "Inserting drag window");
+            }
+            final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
+            if (dragWindowHandle != null) {
+                addInputWindowHandleLw(dragWindowHandle);
+            } else {
+                Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no "
+                        + "drag window handle.");
+            }
+        }
+
+        final int NFW = mService.mFakeWindows.size();
+        for (int i = 0; i < NFW; i++) {
+            addInputWindowHandleLw(mService.mFakeWindows.get(i).mWindowHandle);
+        }
+
+        // Add all windows on the default display.
+        final int numDisplays = mService.mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            WindowList windows = mService.mDisplayContents.valueAt(displayNdx).getWindowList();
+            for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
+                final WindowState child = windows.get(winNdx);
+                final InputChannel inputChannel = child.mInputChannel;
+                final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
+                if (inputChannel == null || inputWindowHandle == null || child.mRemoved) {
+                    // Skip this window because it cannot possibly receive input.
+                    continue;
+                }
+
+                final int flags = child.mAttrs.flags;
+                final int privateFlags = child.mAttrs.privateFlags;
+                final int type = child.mAttrs.type;
+
+                final boolean hasFocus = (child == mInputFocus);
+                final boolean isVisible = child.isVisibleLw();
+                final boolean hasWallpaper = (child == mService.mWallpaperTarget)
+                        && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
+                final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY);
+
+                // If there's a drag in progress and 'child' is a potential drop target,
+                // make sure it's been told about the drag
+                if (inDrag && isVisible && onDefaultDisplay) {
+                    mService.mDragState.sendDragStartedIfNeededLw(child);
+                }
+
+                if (universeBackground != null && !addedUniverse
+                        && child.mBaseLayer < aboveUniverseLayer && onDefaultDisplay) {
+                    final WindowState u = universeBackground.mWin;
+                    if (u.mInputChannel != null && u.mInputWindowHandle != null) {
+                        addInputWindowHandleLw(u.mInputWindowHandle, u, u.mAttrs.flags,
+                                u.mAttrs.privateFlags, u.mAttrs.type,
+                                true, u == mInputFocus, false);
+                    }
+                    addedUniverse = true;
+                }
+
+                if (child.mWinAnimator != universeBackground) {
+                    addInputWindowHandleLw(inputWindowHandle, child, flags, privateFlags, type,
+                            isVisible, hasFocus, hasWallpaper);
+                }
+            }
+        }
+
+        // Send windows to native code.
+        mService.mInputManager.setInputWindows(mInputWindowHandles);
+
+        // Clear the list in preparation for the next round.
+        clearInputWindowHandlesLw();
+
+        if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw");
+    }
+
+    /* Notifies that the input device configuration has changed. */
+    @Override
+    public void notifyConfigurationChanged() {
+        mService.sendNewConfiguration();
+
+        synchronized (mInputDevicesReadyMonitor) {
+            if (!mInputDevicesReady) {
+                mInputDevicesReady = true;
+                mInputDevicesReadyMonitor.notifyAll();
+            }
+        }
+    }
+
+    /* Waits until the built-in input devices have been configured. */
+    public boolean waitForInputDevicesReady(long timeoutMillis) {
+        synchronized (mInputDevicesReadyMonitor) {
+            if (!mInputDevicesReady) {
+                try {
+                    mInputDevicesReadyMonitor.wait(timeoutMillis);
+                } catch (InterruptedException ex) {
+                }
+            }
+            return mInputDevicesReady;
+        }
+    }
+
+    /* Notifies that the lid switch changed state. */
+    @Override
+    public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
+        mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
+    }
+
+    /* Provides an opportunity for the window manager policy to intercept early key
+     * processing as soon as the key has been read from the device. */
+    @Override
+    public int interceptKeyBeforeQueueing(
+            KeyEvent event, int policyFlags, boolean isScreenOn) {
+        return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
+    }
+
+    /* Provides an opportunity for the window manager policy to intercept early
+     * motion event processing when the screen is off since these events are normally
+     * dropped. */
+    @Override
+    public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags) {
+        return mService.mPolicy.interceptMotionBeforeQueueingWhenScreenOff(whenNanos, policyFlags);
+    }
+
+    /* Provides an opportunity for the window manager policy to process a key before
+     * ordinary dispatch. */
+    @Override
+    public long interceptKeyBeforeDispatching(
+            InputWindowHandle focus, KeyEvent event, int policyFlags) {
+        WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
+        return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
+    }
+
+    /* Provides an opportunity for the window manager policy to process a key that
+     * the application did not handle. */
+    @Override
+    public KeyEvent dispatchUnhandledKey(
+            InputWindowHandle focus, KeyEvent event, int policyFlags) {
+        WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
+        return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
+    }
+
+    /* Callback to get pointer layer. */
+    @Override
+    public int getPointerLayer() {
+        return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER)
+                * WindowManagerService.TYPE_LAYER_MULTIPLIER
+                + WindowManagerService.TYPE_LAYER_OFFSET;
+    }
+
+    /* Called when the current input focus changes.
+     * Layer assignment is assumed to be complete by the time this is called.
+     */
+    public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
+        if (WindowManagerService.DEBUG_FOCUS_LIGHT || WindowManagerService.DEBUG_INPUT) {
+            Slog.d(WindowManagerService.TAG, "Input focus has changed to " + newWindow);
+        }
+
+        if (newWindow != mInputFocus) {
+            if (newWindow != null && newWindow.canReceiveKeys()) {
+                // Displaying a window implicitly causes dispatching to be unpaused.
+                // This is to protect against bugs if someone pauses dispatching but
+                // forgets to resume.
+                newWindow.mToken.paused = false;
+            }
+
+            mInputFocus = newWindow;
+            setUpdateInputWindowsNeededLw();
+
+            if (updateInputWindows) {
+                updateInputWindowsLw(false /*force*/);
+            }
+        }
+    }
+
+    public void setFocusedAppLw(AppWindowToken newApp) {
+        // Focused app has changed.
+        if (newApp == null) {
+            mService.mInputManager.setFocusedApplication(null);
+        } else {
+            final InputApplicationHandle handle = newApp.mInputApplicationHandle;
+            handle.name = newApp.toString();
+            handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos;
+
+            mService.mInputManager.setFocusedApplication(handle);
+        }
+    }
+
+    public void pauseDispatchingLw(WindowToken window) {
+        if (! window.paused) {
+            if (WindowManagerService.DEBUG_INPUT) {
+                Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window);
+            }
+            
+            window.paused = true;
+            updateInputWindowsLw(true /*force*/);
+        }
+    }
+    
+    public void resumeDispatchingLw(WindowToken window) {
+        if (window.paused) {
+            if (WindowManagerService.DEBUG_INPUT) {
+                Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window);
+            }
+            
+            window.paused = false;
+            updateInputWindowsLw(true /*force*/);
+        }
+    }
+    
+    public void freezeInputDispatchingLw() {
+        if (! mInputDispatchFrozen) {
+            if (WindowManagerService.DEBUG_INPUT) {
+                Slog.v(WindowManagerService.TAG, "Freezing input dispatching");
+            }
+            
+            mInputDispatchFrozen = true;
+            updateInputDispatchModeLw();
+        }
+    }
+    
+    public void thawInputDispatchingLw() {
+        if (mInputDispatchFrozen) {
+            if (WindowManagerService.DEBUG_INPUT) {
+                Slog.v(WindowManagerService.TAG, "Thawing input dispatching");
+            }
+            
+            mInputDispatchFrozen = false;
+            updateInputDispatchModeLw();
+        }
+    }
+    
+    public void setEventDispatchingLw(boolean enabled) {
+        if (mInputDispatchEnabled != enabled) {
+            if (WindowManagerService.DEBUG_INPUT) {
+                Slog.v(WindowManagerService.TAG, "Setting event dispatching to " + enabled);
+            }
+            
+            mInputDispatchEnabled = enabled;
+            updateInputDispatchModeLw();
+        }
+    }
+    
+    private void updateInputDispatchModeLw() {
+        mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
+    }
+}
diff --git a/services/java/com/android/server/wm/KeyguardDisableHandler.java b/services/core/java/com/android/server/wm/KeyguardDisableHandler.java
similarity index 100%
rename from services/java/com/android/server/wm/KeyguardDisableHandler.java
rename to services/core/java/com/android/server/wm/KeyguardDisableHandler.java
diff --git a/services/java/com/android/server/wm/PointerEventDispatcher.java b/services/core/java/com/android/server/wm/PointerEventDispatcher.java
similarity index 100%
rename from services/java/com/android/server/wm/PointerEventDispatcher.java
rename to services/core/java/com/android/server/wm/PointerEventDispatcher.java
diff --git a/services/java/com/android/server/wm/ScreenRotationAnimation.java b/services/core/java/com/android/server/wm/ScreenRotationAnimation.java
similarity index 100%
rename from services/java/com/android/server/wm/ScreenRotationAnimation.java
rename to services/core/java/com/android/server/wm/ScreenRotationAnimation.java
diff --git a/services/core/java/com/android/server/wm/Session.java b/services/core/java/com/android/server/wm/Session.java
new file mode 100644
index 0000000..ca9076f
--- /dev/null
+++ b/services/core/java/com/android/server/wm/Session.java
@@ -0,0 +1,507 @@
+/*
+ * 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.server.wm;
+
+import android.view.IWindowId;
+import com.android.internal.view.IInputContext;
+import com.android.internal.view.IInputMethodClient;
+import com.android.internal.view.IInputMethodManager;
+import com.android.server.wm.WindowManagerService.H;
+
+import android.content.ClipData;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Rect;
+import android.graphics.Region;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserHandle;
+import android.util.Slog;
+import android.view.Display;
+import android.view.IWindow;
+import android.view.IWindowSession;
+import android.view.InputChannel;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.view.SurfaceSession;
+import android.view.WindowManager;
+
+import java.io.PrintWriter;
+
+/**
+ * This class represents an active client session.  There is generally one
+ * Session object per process that is interacting with the window manager.
+ */
+final class Session extends IWindowSession.Stub
+        implements IBinder.DeathRecipient {
+    final WindowManagerService mService;
+    final IInputMethodClient mClient;
+    final IInputContext mInputContext;
+    final int mUid;
+    final int mPid;
+    final String mStringName;
+    SurfaceSession mSurfaceSession;
+    int mNumWindow = 0;
+    boolean mClientDead = false;
+
+    public Session(WindowManagerService service, IInputMethodClient client,
+            IInputContext inputContext) {
+        mService = service;
+        mClient = client;
+        mInputContext = inputContext;
+        mUid = Binder.getCallingUid();
+        mPid = Binder.getCallingPid();
+        StringBuilder sb = new StringBuilder();
+        sb.append("Session{");
+        sb.append(Integer.toHexString(System.identityHashCode(this)));
+        sb.append(" ");
+        sb.append(mPid);
+        if (mUid < Process.FIRST_APPLICATION_UID) {
+            sb.append(":");
+            sb.append(mUid);
+        } else {
+            sb.append(":u");
+            sb.append(UserHandle.getUserId(mUid));
+            sb.append('a');
+            sb.append(UserHandle.getAppId(mUid));
+        }
+        sb.append("}");
+        mStringName = sb.toString();
+
+        synchronized (mService.mWindowMap) {
+            if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
+                IBinder b = ServiceManager.getService(
+                        Context.INPUT_METHOD_SERVICE);
+                mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
+            }
+        }
+        long ident = Binder.clearCallingIdentity();
+        try {
+            // Note: it is safe to call in to the input method manager
+            // here because we are not holding our lock.
+            if (mService.mInputMethodManager != null) {
+                mService.mInputMethodManager.addClient(client, inputContext,
+                        mUid, mPid);
+            } else {
+                client.setUsingInputMethod(false);
+            }
+            client.asBinder().linkToDeath(this, 0);
+        } catch (RemoteException e) {
+            // The caller has died, so we can just forget about this.
+            try {
+                if (mService.mInputMethodManager != null) {
+                    mService.mInputMethodManager.removeClient(client);
+                }
+            } catch (RemoteException ee) {
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+            throws RemoteException {
+        try {
+            return super.onTransact(code, data, reply, flags);
+        } catch (RuntimeException e) {
+            // Log all 'real' exceptions thrown to the caller
+            if (!(e instanceof SecurityException)) {
+                Slog.wtf(WindowManagerService.TAG, "Window Session Crash", e);
+            }
+            throw e;
+        }
+    }
+
+    public void binderDied() {
+        // Note: it is safe to call in to the input method manager
+        // here because we are not holding our lock.
+        try {
+            if (mService.mInputMethodManager != null) {
+                mService.mInputMethodManager.removeClient(mClient);
+            }
+        } catch (RemoteException e) {
+        }
+        synchronized(mService.mWindowMap) {
+            mClient.asBinder().unlinkToDeath(this, 0);
+            mClientDead = true;
+            killSessionLocked();
+        }
+    }
+
+    @Override
+    public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
+            int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
+        return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
+                outContentInsets, outInputChannel);
+    }
+
+    @Override
+    public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
+            int viewVisibility, int displayId, Rect outContentInsets,
+            InputChannel outInputChannel) {
+        return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
+                outContentInsets, outInputChannel);
+    }
+
+    @Override
+    public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
+            int viewVisibility, Rect outContentInsets) {
+        return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
+                Display.DEFAULT_DISPLAY, outContentInsets);
+    }
+
+    @Override
+    public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
+            int viewVisibility, int displayId, Rect outContentInsets) {
+        return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
+            outContentInsets, null);
+    }
+
+    public void remove(IWindow window) {
+        mService.removeWindow(this, window);
+    }
+
+    public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
+            int requestedWidth, int requestedHeight, int viewFlags,
+            int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
+            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
+        if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED relayout from "
+                + Binder.getCallingPid());
+        int res = mService.relayoutWindow(this, window, seq, attrs,
+                requestedWidth, requestedHeight, viewFlags, flags,
+                outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
+                outConfig, outSurface);
+        if (false) Slog.d(WindowManagerService.TAG, "<<<<<< EXITING relayout to "
+                + Binder.getCallingPid());
+        return res;
+    }
+
+    public void performDeferredDestroy(IWindow window) {
+        mService.performDeferredDestroyWindow(this, window);
+    }
+
+    public boolean outOfMemory(IWindow window) {
+        return mService.outOfMemoryWindow(this, window);
+    }
+
+    public void setTransparentRegion(IWindow window, Region region) {
+        mService.setTransparentRegionWindow(this, window, region);
+    }
+
+    public void setInsets(IWindow window, int touchableInsets,
+            Rect contentInsets, Rect visibleInsets, Region touchableArea) {
+        mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
+                visibleInsets, touchableArea);
+    }
+
+    public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
+        mService.getWindowDisplayFrame(this, window, outDisplayFrame);
+    }
+
+    public void finishDrawing(IWindow window) {
+        if (WindowManagerService.localLOGV) Slog.v(
+            WindowManagerService.TAG, "IWindow finishDrawing called for " + window);
+        mService.finishDrawingWindow(this, window);
+    }
+
+    public void setInTouchMode(boolean mode) {
+        synchronized(mService.mWindowMap) {
+            mService.mInTouchMode = mode;
+        }
+    }
+
+    public boolean getInTouchMode() {
+        synchronized(mService.mWindowMap) {
+            return mService.mInTouchMode;
+        }
+    }
+
+    public boolean performHapticFeedback(IWindow window, int effectId,
+            boolean always) {
+        synchronized(mService.mWindowMap) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                return mService.mPolicy.performHapticFeedbackLw(
+                        mService.windowForClientLocked(this, window, true),
+                        effectId, always);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    /* Drag/drop */
+    public IBinder prepareDrag(IWindow window, int flags,
+            int width, int height, Surface outSurface) {
+        return mService.prepareDragSurface(window, mSurfaceSession, flags,
+                width, height, outSurface);
+    }
+
+    public boolean performDrag(IWindow window, IBinder dragToken,
+            float touchX, float touchY, float thumbCenterX, float thumbCenterY,
+            ClipData data) {
+        if (WindowManagerService.DEBUG_DRAG) {
+            Slog.d(WindowManagerService.TAG, "perform drag: win=" + window + " data=" + data);
+        }
+
+        synchronized (mService.mWindowMap) {
+            if (mService.mDragState == null) {
+                Slog.w(WindowManagerService.TAG, "No drag prepared");
+                throw new IllegalStateException("performDrag() without prepareDrag()");
+            }
+
+            if (dragToken != mService.mDragState.mToken) {
+                Slog.w(WindowManagerService.TAG, "Performing mismatched drag");
+                throw new IllegalStateException("performDrag() does not match prepareDrag()");
+            }
+
+            WindowState callingWin = mService.windowForClientLocked(null, window, false);
+            if (callingWin == null) {
+                Slog.w(WindowManagerService.TAG, "Bad requesting window " + window);
+                return false;  // !!! TODO: throw here?
+            }
+
+            // !!! TODO: if input is not still focused on the initiating window, fail
+            // the drag initiation (e.g. an alarm window popped up just as the application
+            // called performDrag()
+
+            mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
+
+            // !!! TODO: extract the current touch (x, y) in screen coordinates.  That
+            // will let us eliminate the (touchX,touchY) parameters from the API.
+
+            // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
+            // the actual drag event dispatch stuff in the dragstate
+
+            final DisplayContent displayContent = callingWin.getDisplayContent();
+            if (displayContent == null) {
+               return false;
+            }
+            Display display = displayContent.getDisplay();
+            mService.mDragState.register(display);
+            mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
+            if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
+                    mService.mDragState.mServerChannel)) {
+                Slog.e(WindowManagerService.TAG, "Unable to transfer touch focus");
+                mService.mDragState.unregister();
+                mService.mDragState = null;
+                mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
+                return false;
+            }
+
+            mService.mDragState.mData = data;
+            mService.mDragState.mCurrentX = touchX;
+            mService.mDragState.mCurrentY = touchY;
+            mService.mDragState.broadcastDragStartedLw(touchX, touchY);
+
+            // remember the thumb offsets for later
+            mService.mDragState.mThumbOffsetX = thumbCenterX;
+            mService.mDragState.mThumbOffsetY = thumbCenterY;
+
+            // Make the surface visible at the proper location
+            final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
+            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
+                    WindowManagerService.TAG, ">>> OPEN TRANSACTION performDrag");
+            SurfaceControl.openTransaction();
+            try {
+                surfaceControl.setPosition(touchX - thumbCenterX,
+                        touchY - thumbCenterY);
+                surfaceControl.setAlpha(.7071f);
+                surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
+                surfaceControl.setLayerStack(display.getLayerStack());
+                surfaceControl.show();
+            } finally {
+                SurfaceControl.closeTransaction();
+                if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
+                        WindowManagerService.TAG, "<<< CLOSE TRANSACTION performDrag");
+            }
+        }
+
+        return true;    // success!
+    }
+
+    public void reportDropResult(IWindow window, boolean consumed) {
+        IBinder token = window.asBinder();
+        if (WindowManagerService.DEBUG_DRAG) {
+            Slog.d(WindowManagerService.TAG, "Drop result=" + consumed + " reported by " + token);
+        }
+
+        synchronized (mService.mWindowMap) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                if (mService.mDragState == null) {
+                    // Most likely the drop recipient ANRed and we ended the drag
+                    // out from under it.  Log the issue and move on.
+                    Slog.w(WindowManagerService.TAG, "Drop result given but no drag in progress");
+                    return;
+                }
+
+                if (mService.mDragState.mToken != token) {
+                    // We're in a drag, but the wrong window has responded.
+                    Slog.w(WindowManagerService.TAG, "Invalid drop-result claim by " + window);
+                    throw new IllegalStateException("reportDropResult() by non-recipient");
+                }
+
+                // The right window has responded, even if it's no longer around,
+                // so be sure to halt the timeout even if the later WindowState
+                // lookup fails.
+                mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
+                WindowState callingWin = mService.windowForClientLocked(null, window, false);
+                if (callingWin == null) {
+                    Slog.w(WindowManagerService.TAG, "Bad result-reporting window " + window);
+                    return;  // !!! TODO: throw here?
+                }
+
+                mService.mDragState.mDragResult = consumed;
+                mService.mDragState.endDragLw();
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void dragRecipientEntered(IWindow window) {
+        if (WindowManagerService.DEBUG_DRAG) {
+            Slog.d(WindowManagerService.TAG, "Drag into new candidate view @ " + window.asBinder());
+        }
+    }
+
+    public void dragRecipientExited(IWindow window) {
+        if (WindowManagerService.DEBUG_DRAG) {
+            Slog.d(WindowManagerService.TAG, "Drag from old candidate view @ " + window.asBinder());
+        }
+    }
+
+    public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
+        synchronized(mService.mWindowMap) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                mService.setWindowWallpaperPositionLocked(
+                        mService.windowForClientLocked(this, window, true),
+                        x, y, xStep, yStep);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void wallpaperOffsetsComplete(IBinder window) {
+        mService.wallpaperOffsetsComplete(window);
+    }
+
+    public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
+            int z, Bundle extras, boolean sync) {
+        synchronized(mService.mWindowMap) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                return mService.sendWindowWallpaperCommandLocked(
+                        mService.windowForClientLocked(this, window, true),
+                        action, x, y, z, extras, sync);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void wallpaperCommandComplete(IBinder window, Bundle result) {
+        mService.wallpaperCommandComplete(window, result);
+    }
+
+    public void setUniverseTransform(IBinder window, float alpha, float offx, float offy,
+            float dsdx, float dtdx, float dsdy, float dtdy) {
+        synchronized(mService.mWindowMap) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                mService.setUniverseTransformLocked(
+                        mService.windowForClientLocked(this, window, true),
+                        alpha, offx, offy, dsdx, dtdx, dsdy, dtdy);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void onRectangleOnScreenRequested(IBinder token, Rect rectangle, boolean immediate) {
+        synchronized(mService.mWindowMap) {
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                mService.onRectangleOnScreenRequested(token, rectangle, immediate);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+    }
+
+    public IWindowId getWindowId(IBinder window) {
+        return mService.getWindowId(window);
+    }
+
+    void windowAddedLocked() {
+        if (mSurfaceSession == null) {
+            if (WindowManagerService.localLOGV) Slog.v(
+                WindowManagerService.TAG, "First window added to " + this + ", creating SurfaceSession");
+            mSurfaceSession = new SurfaceSession();
+            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
+                    WindowManagerService.TAG, "  NEW SURFACE SESSION " + mSurfaceSession);
+            mService.mSessions.add(this);
+        }
+        mNumWindow++;
+    }
+
+    void windowRemovedLocked() {
+        mNumWindow--;
+        killSessionLocked();
+    }
+
+    void killSessionLocked() {
+        if (mNumWindow <= 0 && mClientDead) {
+            mService.mSessions.remove(this);
+            if (mSurfaceSession != null) {
+                if (WindowManagerService.localLOGV) Slog.v(
+                    WindowManagerService.TAG, "Last window removed from " + this
+                    + ", destroying " + mSurfaceSession);
+                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
+                        WindowManagerService.TAG, "  KILL SURFACE SESSION " + mSurfaceSession);
+                try {
+                    mSurfaceSession.kill();
+                } catch (Exception e) {
+                    Slog.w(WindowManagerService.TAG, "Exception thrown when killing surface session "
+                        + mSurfaceSession + " in session " + this
+                        + ": " + e.toString());
+                }
+                mSurfaceSession = null;
+            }
+        }
+    }
+
+    void dump(PrintWriter pw, String prefix) {
+        pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
+                pw.print(" mClientDead="); pw.print(mClientDead);
+                pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
+    }
+
+    @Override
+    public String toString() {
+        return mStringName;
+    }
+}
\ No newline at end of file
diff --git a/services/java/com/android/server/wm/StackTapPointerEventListener.java b/services/core/java/com/android/server/wm/StackTapPointerEventListener.java
similarity index 100%
rename from services/java/com/android/server/wm/StackTapPointerEventListener.java
rename to services/core/java/com/android/server/wm/StackTapPointerEventListener.java
diff --git a/services/java/com/android/server/wm/StartingData.java b/services/core/java/com/android/server/wm/StartingData.java
similarity index 100%
rename from services/java/com/android/server/wm/StartingData.java
rename to services/core/java/com/android/server/wm/StartingData.java
diff --git a/services/java/com/android/server/wm/StrictModeFlash.java b/services/core/java/com/android/server/wm/StrictModeFlash.java
similarity index 100%
rename from services/java/com/android/server/wm/StrictModeFlash.java
rename to services/core/java/com/android/server/wm/StrictModeFlash.java
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
new file mode 100644
index 0000000..09c4e20
--- /dev/null
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2013 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.wm;
+
+import static com.android.server.wm.WindowManagerService.TAG;
+
+import android.util.EventLog;
+import android.util.Slog;
+
+class Task {
+    TaskStack mStack;
+    final AppTokenList mAppTokens = new AppTokenList();
+    final int taskId;
+    final int mUserId;
+    boolean mDeferRemoval = false;
+
+    Task(AppWindowToken wtoken, TaskStack stack, int userId) {
+        taskId = wtoken.groupId;
+        mAppTokens.add(wtoken);
+        mStack = stack;
+        mUserId = userId;
+    }
+
+    DisplayContent getDisplayContent() {
+        return mStack.getDisplayContent();
+    }
+
+    void addAppToken(int addPos, AppWindowToken wtoken) {
+        final int lastPos = mAppTokens.size();
+        if (addPos > lastPos) {
+            // We lost an app token. Don't crash though.
+            Slog.e(TAG, "Task.addAppToken: Out of bounds attempt token=" + wtoken + " addPos="
+                    + addPos + " lastPos=" + lastPos);
+            addPos = lastPos;
+        }
+        mAppTokens.add(addPos, wtoken);
+        mDeferRemoval = false;
+    }
+
+    boolean removeAppToken(AppWindowToken wtoken) {
+        boolean removed = mAppTokens.remove(wtoken);
+        if (mAppTokens.size() == 0) {
+            EventLog.writeEvent(com.android.server.EventLogTags.WM_TASK_REMOVED, taskId,
+                    "removeAppToken: last token");
+        }
+        return removed;
+    }
+
+    @Override
+    public String toString() {
+        return "{taskId=" + taskId + " appTokens=" + mAppTokens + "}";
+    }
+}
diff --git a/services/java/com/android/server/wm/TaskGroup.java b/services/core/java/com/android/server/wm/TaskGroup.java
similarity index 100%
rename from services/java/com/android/server/wm/TaskGroup.java
rename to services/core/java/com/android/server/wm/TaskGroup.java
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
new file mode 100644
index 0000000..81db8b3
--- /dev/null
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -0,0 +1,400 @@
+/*
+ * Copyright (C) 2013 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.wm;
+
+import static com.android.server.wm.WindowManagerService.DEBUG_TASK_MOVEMENT;
+import static com.android.server.wm.WindowManagerService.TAG;
+
+import android.graphics.Rect;
+import android.os.Debug;
+import android.util.EventLog;
+import android.util.Slog;
+import android.util.TypedValue;
+import com.android.server.EventLogTags;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+public class TaskStack {
+    /** Amount of time in milliseconds to animate the dim surface from one value to another,
+     * when no window animation is driving it. */
+    private static final int DEFAULT_DIM_DURATION = 200;
+
+    /** Unique identifier */
+    final int mStackId;
+
+    /** The service */
+    private final WindowManagerService mService;
+
+    /** The display this stack sits under. */
+    private DisplayContent mDisplayContent;
+
+    /** The Tasks that define this stack. Oldest Tasks are at the bottom. The ordering must match
+     * mTaskHistory in the ActivityStack with the same mStackId */
+    private final ArrayList<Task> mTasks = new ArrayList<Task>();
+
+    /** For comparison with DisplayContent bounds. */
+    private Rect mTmpRect = new Rect();
+
+    /** Content limits relative to the DisplayContent this sits in. */
+    private Rect mBounds = new Rect();
+
+    /** Whether mBounds is fullscreen */
+    private boolean mFullscreen = true;
+
+    /** Used to support {@link android.view.WindowManager.LayoutParams#FLAG_DIM_BEHIND} */
+    private DimLayer mDimLayer;
+
+    /** The particular window with FLAG_DIM_BEHIND set. If null, hide mDimLayer. */
+    WindowStateAnimator mDimWinAnimator;
+
+    /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */
+    DimLayer mAnimationBackgroundSurface;
+
+    /** The particular window with an Animation with non-zero background color. */
+    WindowStateAnimator mAnimationBackgroundAnimator;
+
+    /** Set to false at the start of performLayoutAndPlaceSurfaces. If it is still false by the end
+     * then stop any dimming. */
+    boolean mDimmingTag;
+
+    /** Application tokens that are exiting, but still on screen for animations. */
+    final AppTokenList mExitingAppTokens = new AppTokenList();
+
+    /** Detach this stack from its display when animation completes. */
+    boolean mDeferDetach;
+
+    TaskStack(WindowManagerService service, int stackId) {
+        mService = service;
+        mStackId = stackId;
+        // TODO: remove bounds from log, they are always 0.
+        EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId, mBounds.left, mBounds.top,
+                mBounds.right, mBounds.bottom);
+    }
+
+    DisplayContent getDisplayContent() {
+        return mDisplayContent;
+    }
+
+    ArrayList<Task> getTasks() {
+        return mTasks;
+    }
+
+    void resizeWindows() {
+        final boolean underStatusBar = mBounds.top == 0;
+
+        final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
+        for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<AppWindowToken> activities = mTasks.get(taskNdx).mAppTokens;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ArrayList<WindowState> windows = activities.get(activityNdx).allAppWindows;
+                for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
+                    final WindowState win = windows.get(winNdx);
+                    if (!resizingWindows.contains(win)) {
+                        if (WindowManagerService.DEBUG_RESIZE) Slog.d(TAG,
+                                "setBounds: Resizing " + win);
+                        resizingWindows.add(win);
+                    }
+                    win.mUnderStatusBar = underStatusBar;
+                }
+            }
+        }
+    }
+
+    boolean setBounds(Rect bounds) {
+        boolean oldFullscreen = mFullscreen;
+        if (mDisplayContent != null) {
+            mDisplayContent.getLogicalDisplayRect(mTmpRect);
+            mFullscreen = mTmpRect.equals(bounds);
+        }
+
+        if (mBounds.equals(bounds) && oldFullscreen == mFullscreen) {
+            return false;
+        }
+
+        mDimLayer.setBounds(bounds);
+        mAnimationBackgroundSurface.setBounds(bounds);
+        mBounds.set(bounds);
+
+        return true;
+    }
+
+    void getBounds(Rect out) {
+        out.set(mBounds);
+    }
+
+    void updateDisplayInfo() {
+        if (mFullscreen && mDisplayContent != null) {
+            mDisplayContent.getLogicalDisplayRect(mTmpRect);
+            setBounds(mTmpRect);
+        }
+    }
+
+    boolean isFullscreen() {
+        return mFullscreen;
+    }
+
+    boolean isAnimating() {
+        for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            final ArrayList<AppWindowToken> activities = mTasks.get(taskNdx).mAppTokens;
+            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
+                final ArrayList<WindowState> windows = activities.get(activityNdx).allAppWindows;
+                for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
+                    if (windows.get(winNdx).mWinAnimator.isAnimating()) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Put a Task in this stack. Used for adding and moving.
+     * @param task The task to add.
+     * @param toTop Whether to add it to the top or bottom.
+     */
+    void addTask(Task task, boolean toTop) {
+        int stackNdx;
+        if (!toTop) {
+            stackNdx = 0;
+        } else {
+            stackNdx = mTasks.size();
+            final int currentUserId = mService.mCurrentUserId;
+            if (task.mUserId != currentUserId) {
+                // Place the task below all current user tasks.
+                while (--stackNdx >= 0) {
+                    if (currentUserId != mTasks.get(stackNdx).mUserId) {
+                        break;
+                    }
+                }
+                ++stackNdx;
+            }
+        }
+        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "addTask: task=" + task + " toTop=" + toTop
+                + " pos=" + stackNdx);
+        mTasks.add(stackNdx, task);
+
+        task.mStack = this;
+        mDisplayContent.moveStack(this, true);
+        EventLog.writeEvent(EventLogTags.WM_TASK_MOVED, task.taskId, toTop ? 1 : 0, stackNdx);
+    }
+
+    void moveTaskToTop(Task task) {
+        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "moveTaskToTop: task=" + task + " Callers="
+                + Debug.getCallers(6));
+        mTasks.remove(task);
+        addTask(task, true);
+    }
+
+    void moveTaskToBottom(Task task) {
+        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "moveTaskToBottom: task=" + task);
+        mTasks.remove(task);
+        addTask(task, false);
+    }
+
+    /**
+     * Delete a Task from this stack. If it is the last Task in the stack, move this stack to the
+     * back.
+     * @param task The Task to delete.
+     */
+    void removeTask(Task task) {
+        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "removeTask: task=" + task);
+        mTasks.remove(task);
+        if (mDisplayContent != null) {
+            if (mTasks.isEmpty()) {
+                mDisplayContent.moveStack(this, false);
+            }
+            mDisplayContent.layoutNeeded = true;
+        }
+    }
+
+    void attachDisplayContent(DisplayContent displayContent) {
+        if (mDisplayContent != null) {
+            throw new IllegalStateException("attachDisplayContent: Already attached");
+        }
+
+        mDisplayContent = displayContent;
+        mDimLayer = new DimLayer(mService, this, displayContent);
+        mAnimationBackgroundSurface = new DimLayer(mService, this, displayContent);
+        updateDisplayInfo();
+    }
+
+    void detachDisplay() {
+        EventLog.writeEvent(EventLogTags.WM_STACK_REMOVED, mStackId);
+        for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            mService.tmpRemoveTaskWindowsLocked(mTasks.get(taskNdx));
+        }
+        mAnimationBackgroundSurface.destroySurface();
+        mAnimationBackgroundSurface = null;
+        mDimLayer.destroySurface();
+        mDimLayer = null;
+        mDisplayContent = null;
+    }
+
+    void resetAnimationBackgroundAnimator() {
+        mAnimationBackgroundAnimator = null;
+        mAnimationBackgroundSurface.hide();
+    }
+
+    private long getDimBehindFadeDuration(long duration) {
+        TypedValue tv = new TypedValue();
+        mService.mContext.getResources().getValue(
+                com.android.internal.R.fraction.config_dimBehindFadeDuration, tv, true);
+        if (tv.type == TypedValue.TYPE_FRACTION) {
+            duration = (long)tv.getFraction(duration, duration);
+        } else if (tv.type >= TypedValue.TYPE_FIRST_INT && tv.type <= TypedValue.TYPE_LAST_INT) {
+            duration = tv.data;
+        }
+        return duration;
+    }
+
+    boolean animateDimLayers() {
+        final int dimLayer;
+        final float dimAmount;
+        if (mDimWinAnimator == null) {
+            dimLayer = mDimLayer.getLayer();
+            dimAmount = 0;
+        } else {
+            dimLayer = mDimWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM;
+            dimAmount = mDimWinAnimator.mWin.mAttrs.dimAmount;
+        }
+        final float targetAlpha = mDimLayer.getTargetAlpha();
+        if (targetAlpha != dimAmount) {
+            if (mDimWinAnimator == null) {
+                mDimLayer.hide(DEFAULT_DIM_DURATION);
+            } else {
+                long duration = (mDimWinAnimator.mAnimating && mDimWinAnimator.mAnimation != null)
+                        ? mDimWinAnimator.mAnimation.computeDurationHint()
+                        : DEFAULT_DIM_DURATION;
+                if (targetAlpha > dimAmount) {
+                    duration = getDimBehindFadeDuration(duration);
+                }
+                mDimLayer.show(dimLayer, dimAmount, duration);
+            }
+        } else if (mDimLayer.getLayer() != dimLayer) {
+            mDimLayer.setLayer(dimLayer);
+        }
+        if (mDimLayer.isAnimating()) {
+            if (!mService.okToDisplay()) {
+                // Jump to the end of the animation.
+                mDimLayer.show();
+            } else {
+                return mDimLayer.stepAnimation();
+            }
+        }
+        return false;
+    }
+
+    void resetDimmingTag() {
+        mDimmingTag = false;
+    }
+
+    void setDimmingTag() {
+        mDimmingTag = true;
+    }
+
+    boolean testDimmingTag() {
+        return mDimmingTag;
+    }
+
+    boolean isDimming() {
+        return mDimLayer.isDimming();
+    }
+
+    boolean isDimming(WindowStateAnimator winAnimator) {
+        return mDimWinAnimator == winAnimator && mDimLayer.isDimming();
+    }
+
+    void startDimmingIfNeeded(WindowStateAnimator newWinAnimator) {
+        // Only set dim params on the highest dimmed layer.
+        final WindowStateAnimator existingDimWinAnimator = mDimWinAnimator;
+        // Don't turn on for an unshown surface, or for any layer but the highest dimmed layer.
+        if (newWinAnimator.mSurfaceShown && (existingDimWinAnimator == null
+                || !existingDimWinAnimator.mSurfaceShown
+                || existingDimWinAnimator.mAnimLayer < newWinAnimator.mAnimLayer)) {
+            mDimWinAnimator = newWinAnimator;
+        }
+    }
+
+    void stopDimmingIfNeeded() {
+        if (!mDimmingTag && isDimming()) {
+            mDimWinAnimator = null;
+        }
+    }
+
+    void setAnimationBackground(WindowStateAnimator winAnimator, int color) {
+        int animLayer = winAnimator.mAnimLayer;
+        if (mAnimationBackgroundAnimator == null
+                || animLayer < mAnimationBackgroundAnimator.mAnimLayer) {
+            mAnimationBackgroundAnimator = winAnimator;
+            animLayer = mService.adjustAnimationBackground(winAnimator);
+            mAnimationBackgroundSurface.show(animLayer - WindowManagerService.LAYER_OFFSET_DIM,
+                    ((color >> 24) & 0xff) / 255f, 0);
+        }
+    }
+
+    void switchUser(int userId) {
+        int top = mTasks.size();
+        for (int taskNdx = 0; taskNdx < top; ++taskNdx) {
+            Task task = mTasks.get(taskNdx);
+            if (task.mUserId == userId) {
+                mTasks.remove(taskNdx);
+                mTasks.add(task);
+                --top;
+            }
+        }
+    }
+
+    void close() {
+        mDimLayer.mDimSurface.destroy();
+        mAnimationBackgroundSurface.mDimSurface.destroy();
+    }
+
+    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);
+        for (int taskNdx = 0; taskNdx < mTasks.size(); ++taskNdx) {
+            pw.print(prefix); pw.println(mTasks.get(taskNdx));
+        }
+        if (mAnimationBackgroundSurface.isDimming()) {
+            pw.print(prefix); pw.println("mWindowAnimationBackgroundSurface:");
+            mAnimationBackgroundSurface.printTo(prefix + "  ", pw);
+        }
+        if (mDimLayer.isDimming()) {
+            pw.print(prefix); pw.println("mDimLayer:");
+            mDimLayer.printTo(prefix, pw);
+            pw.print(prefix); pw.print("mDimWinAnimator="); pw.println(mDimWinAnimator);
+        }
+        if (!mExitingAppTokens.isEmpty()) {
+            pw.println();
+            pw.println("  Exiting application tokens:");
+            for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
+                WindowToken token = mExitingAppTokens.get(i);
+                pw.print("  Exiting App #"); pw.print(i);
+                pw.print(' '); pw.print(token);
+                pw.println(':');
+                token.dump(pw, "    ");
+            }
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "{stackId=" + mStackId + " tasks=" + mTasks + "}";
+    }
+}
diff --git a/services/java/com/android/server/wm/ViewServer.java b/services/core/java/com/android/server/wm/ViewServer.java
similarity index 100%
rename from services/java/com/android/server/wm/ViewServer.java
rename to services/core/java/com/android/server/wm/ViewServer.java
diff --git a/services/java/com/android/server/wm/Watermark.java b/services/core/java/com/android/server/wm/Watermark.java
similarity index 100%
rename from services/java/com/android/server/wm/Watermark.java
rename to services/core/java/com/android/server/wm/Watermark.java
diff --git a/services/core/java/com/android/server/wm/WindowAnimator.java b/services/core/java/com/android/server/wm/WindowAnimator.java
new file mode 100644
index 0000000..0c68258
--- /dev/null
+++ b/services/core/java/com/android/server/wm/WindowAnimator.java
@@ -0,0 +1,711 @@
+/*
+ * 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.server.wm;
+
+import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
+import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
+
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_UPDATE_ROTATION;
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_MAY_CHANGE;
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_FORCE_HIDING_CHANGED;
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_ACTION_PENDING;
+
+import android.content.Context;
+import android.os.Debug;
+import android.os.SystemClock;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.SparseIntArray;
+import android.util.TimeUtils;
+import android.view.Display;
+import android.view.SurfaceControl;
+import android.view.WindowManagerPolicy;
+import android.view.animation.Animation;
+
+import com.android.server.wm.WindowManagerService.LayoutFields;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+/**
+ * Singleton class that carries out the animations and Surface operations in a separate task
+ * on behalf of WindowManagerService.
+ */
+public class WindowAnimator {
+    private static final String TAG = "WindowAnimator";
+
+    final WindowManagerService mService;
+    final Context mContext;
+    final WindowManagerPolicy mPolicy;
+
+    boolean mAnimating;
+
+    final Runnable mAnimationRunnable;
+
+    /** Time of current animation step. Reset on each iteration */
+    long mCurrentTime;
+
+    /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
+     * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
+    private int mAnimTransactionSequence;
+
+    /** Window currently running an animation that has requested it be detached
+     * from the wallpaper.  This means we need to ensure the wallpaper is
+     * visible behind it in case it animates in a way that would allow it to be
+     * seen. If multiple windows satisfy this, use the lowest window. */
+    WindowState mWindowDetachedWallpaper = null;
+
+    WindowStateAnimator mUniverseBackground = null;
+    int mAboveUniverseLayer = 0;
+
+    int mBulkUpdateParams = 0;
+    Object mLastWindowFreezeSource;
+
+    SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators =
+            new SparseArray<DisplayContentsAnimator>(2);
+
+    boolean mInitialized = false;
+
+    // forceHiding states.
+    static final int KEYGUARD_NOT_SHOWN     = 0;
+    static final int KEYGUARD_ANIMATING_IN  = 1;
+    static final int KEYGUARD_SHOWN         = 2;
+    static final int KEYGUARD_ANIMATING_OUT = 3;
+    int mForceHiding = KEYGUARD_NOT_SHOWN;
+
+    private String forceHidingToString() {
+        switch (mForceHiding) {
+            case KEYGUARD_NOT_SHOWN:    return "KEYGUARD_NOT_SHOWN";
+            case KEYGUARD_ANIMATING_IN: return "KEYGUARD_ANIMATING_IN";
+            case KEYGUARD_SHOWN:        return "KEYGUARD_SHOWN";
+            case KEYGUARD_ANIMATING_OUT:return "KEYGUARD_ANIMATING_OUT";
+            default: return "KEYGUARD STATE UNKNOWN " + mForceHiding;
+        }
+    }
+
+    WindowAnimator(final WindowManagerService service) {
+        mService = service;
+        mContext = service.mContext;
+        mPolicy = service.mPolicy;
+
+        mAnimationRunnable = new Runnable() {
+            @Override
+            public void run() {
+                synchronized (mService.mWindowMap) {
+                    mService.mAnimationScheduled = false;
+                    animateLocked();
+                }
+            }
+        };
+    }
+
+    void addDisplayLocked(final int displayId) {
+        // Create the DisplayContentsAnimator object by retrieving it.
+        getDisplayContentsAnimatorLocked(displayId);
+        if (displayId == Display.DEFAULT_DISPLAY) {
+            mInitialized = true;
+        }
+    }
+
+    void removeDisplayLocked(final int displayId) {
+        final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
+        if (displayAnimator != null) {
+            if (displayAnimator.mScreenRotationAnimation != null) {
+                displayAnimator.mScreenRotationAnimation.kill();
+                displayAnimator.mScreenRotationAnimation = null;
+            }
+        }
+
+        mDisplayContentsAnimators.delete(displayId);
+    }
+
+    void hideWallpapersLocked(final WindowState w) {
+        final WindowState wallpaperTarget = mService.mWallpaperTarget;
+        final WindowState lowerWallpaperTarget = mService.mLowerWallpaperTarget;
+        final ArrayList<WindowToken> wallpaperTokens = mService.mWallpaperTokens;
+
+        if ((wallpaperTarget == w && lowerWallpaperTarget == null) || wallpaperTarget == null) {
+            final int numTokens = wallpaperTokens.size();
+            for (int i = numTokens - 1; i >= 0; i--) {
+                final WindowToken token = wallpaperTokens.get(i);
+                final int numWindows = token.windows.size();
+                for (int j = numWindows - 1; j >= 0; j--) {
+                    final WindowState wallpaper = token.windows.get(j);
+                    final WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
+                    if (!winAnimator.mLastHidden) {
+                        winAnimator.hide();
+                        mService.dispatchWallpaperVisibility(wallpaper, false);
+                        setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
+                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
+                    }
+                }
+                if (WindowManagerService.DEBUG_WALLPAPER_LIGHT && !token.hidden) Slog.d(TAG,
+                        "Hiding wallpaper " + token + " from " + w
+                        + " target=" + wallpaperTarget + " lower=" + lowerWallpaperTarget
+                        + "\n" + Debug.getCallers(5, "  "));
+                token.hidden = true;
+            }
+        }
+    }
+
+    private void updateAppWindowsLocked(int displayId) {
+        ArrayList<TaskStack> stacks = mService.getDisplayContentLocked(displayId).getStacks();
+        for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = stacks.get(stackNdx);
+            final ArrayList<Task> tasks = stack.getTasks();
+            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                    final AppWindowAnimator appAnimator = tokens.get(tokenNdx).mAppAnimator;
+                    final boolean wasAnimating = appAnimator.animation != null
+                            && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
+                    if (appAnimator.stepAnimationLocked(mCurrentTime)) {
+                        mAnimating = true;
+                    } else if (wasAnimating) {
+                        // stopped animating, do one more pass through the layout
+                        setAppLayoutChanges(appAnimator,
+                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
+                                "appToken " + appAnimator.mAppToken + " done");
+                        if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
+                                "updateWindowsApps...: done animating " + appAnimator.mAppToken);
+                    }
+                }
+            }
+
+            final AppTokenList exitingAppTokens = stack.mExitingAppTokens;
+            final int NEAT = exitingAppTokens.size();
+            for (int i = 0; i < NEAT; i++) {
+                final AppWindowAnimator appAnimator = exitingAppTokens.get(i).mAppAnimator;
+                final boolean wasAnimating = appAnimator.animation != null
+                        && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
+                if (appAnimator.stepAnimationLocked(mCurrentTime)) {
+                    mAnimating = true;
+                } else if (wasAnimating) {
+                    // stopped animating, do one more pass through the layout
+                    setAppLayoutChanges(appAnimator, WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
+                        "exiting appToken " + appAnimator.mAppToken + " done");
+                    if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
+                            "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken);
+                }
+            }
+        }
+    }
+
+    private void updateWindowsLocked(final int displayId) {
+        ++mAnimTransactionSequence;
+
+        final WindowList windows = mService.getWindowListLocked(displayId);
+        ArrayList<WindowStateAnimator> unForceHiding = null;
+        boolean wallpaperInUnForceHiding = false;
+        mForceHiding = KEYGUARD_NOT_SHOWN;
+
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            WindowState win = windows.get(i);
+            WindowStateAnimator winAnimator = win.mWinAnimator;
+            final int flags = winAnimator.mAttrFlags;
+
+            if (winAnimator.mSurfaceControl != null) {
+                final boolean wasAnimating = winAnimator.mWasAnimating;
+                final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
+
+                if (WindowManagerService.DEBUG_WALLPAPER) {
+                    Slog.v(TAG, win + ": wasAnimating=" + wasAnimating +
+                            ", nowAnimating=" + nowAnimating);
+                }
+
+                if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == win) {
+                    mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
+                    setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
+                            WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
+                    if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
+                        mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2",
+                                getPendingLayoutChanges(Display.DEFAULT_DISPLAY));
+                    }
+                }
+
+                if (mPolicy.doesForceHide(win, win.mAttrs)) {
+                    if (!wasAnimating && nowAnimating) {
+                        if (WindowManagerService.DEBUG_ANIM ||
+                                WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
+                                "Animation started that could impact force hide: " + win);
+                        mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
+                        setPendingLayoutChanges(displayId,
+                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
+                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
+                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3",
+                                    getPendingLayoutChanges(displayId));
+                        }
+                        mService.mFocusMayChange = true;
+                    }
+                    if (win.isReadyForDisplay()) {
+                        if (nowAnimating) {
+                            if (winAnimator.mAnimationIsEntrance) {
+                                mForceHiding = KEYGUARD_ANIMATING_IN;
+                            } else {
+                                mForceHiding = KEYGUARD_ANIMATING_OUT;
+                            }
+                        } else {
+                            mForceHiding = win.isDrawnLw() ? KEYGUARD_SHOWN : KEYGUARD_NOT_SHOWN;
+                        }
+                    }
+                    if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
+                            "Force hide " + mForceHiding
+                            + " hasSurface=" + win.mHasSurface
+                            + " policyVis=" + win.mPolicyVisibility
+                            + " destroying=" + win.mDestroying
+                            + " attHidden=" + win.mAttachedHidden
+                            + " vis=" + win.mViewVisibility
+                            + " hidden=" + win.mRootToken.hidden
+                            + " anim=" + win.mWinAnimator.mAnimation);
+                } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) {
+                    final boolean hideWhenLocked =
+                            (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0;
+                    final boolean changed;
+                    if (((mForceHiding == KEYGUARD_ANIMATING_IN)
+                                && (!winAnimator.isAnimating() || hideWhenLocked))
+                            || ((mForceHiding == KEYGUARD_SHOWN) && hideWhenLocked)) {
+                        changed = win.hideLw(false, false);
+                        if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
+                                "Now policy hidden: " + win);
+                    } else {
+                        changed = win.showLw(false, false);
+                        if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
+                                "Now policy shown: " + win);
+                        if (changed) {
+                            if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
+                                    && win.isVisibleNow() /*w.isReadyForDisplay()*/) {
+                                if (unForceHiding == null) {
+                                    unForceHiding = new ArrayList<WindowStateAnimator>();
+                                }
+                                unForceHiding.add(winAnimator);
+                                if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
+                                    wallpaperInUnForceHiding = true;
+                                }
+                            }
+                            final WindowState currentFocus = mService.mCurrentFocus;
+                            if (currentFocus == null || currentFocus.mLayer < win.mLayer) {
+                                // We are showing on to of the current
+                                // focus, so re-evaluate focus to make
+                                // sure it is correct.
+                                if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.v(TAG,
+                                        "updateWindowsLocked: setting mFocusMayChange true");
+                                mService.mFocusMayChange = true;
+                            }
+                        }
+                    }
+                    if (changed && (flags & FLAG_SHOW_WALLPAPER) != 0) {
+                        mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
+                        setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
+                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
+                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
+                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4",
+                                    getPendingLayoutChanges(Display.DEFAULT_DISPLAY));
+                        }
+                    }
+                }
+            }
+
+            final AppWindowToken atoken = win.mAppToken;
+            if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
+                if (atoken == null || atoken.allDrawn) {
+                    if (winAnimator.performShowLocked()) {
+                        setPendingLayoutChanges(displayId,
+                                WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
+                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
+                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5",
+                                    getPendingLayoutChanges(displayId));
+                        }
+                    }
+                }
+            }
+            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
+            if (appAnimator != null && appAnimator.thumbnail != null) {
+                if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) {
+                    appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence;
+                    appAnimator.thumbnailLayer = 0;
+                }
+                if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
+                    appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
+                }
+            }
+        } // end forall windows
+
+        // If we have windows that are being show due to them no longer
+        // being force-hidden, apply the appropriate animation to them.
+        if (unForceHiding != null) {
+            for (int i=unForceHiding.size()-1; i>=0; i--) {
+                Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding);
+                if (a != null) {
+                    final WindowStateAnimator winAnimator = unForceHiding.get(i);
+                    winAnimator.setAnimation(a);
+                    winAnimator.mAnimationIsEntrance = true;
+                }
+            }
+        }
+    }
+
+    private void updateWallpaperLocked(int displayId) {
+        mService.getDisplayContentLocked(displayId).resetAnimationBackgroundAnimator();
+
+        final WindowList windows = mService.getWindowListLocked(displayId);
+        WindowState detachedWallpaper = null;
+
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            final WindowState win = windows.get(i);
+            WindowStateAnimator winAnimator = win.mWinAnimator;
+            if (winAnimator.mSurfaceControl == null) {
+                continue;
+            }
+
+            final int flags = winAnimator.mAttrFlags;
+
+            // If this window is animating, make a note that we have
+            // an animating window and take care of a request to run
+            // a detached wallpaper animation.
+            if (winAnimator.mAnimating) {
+                if (winAnimator.mAnimation != null) {
+                    if ((flags & FLAG_SHOW_WALLPAPER) != 0
+                            && winAnimator.mAnimation.getDetachWallpaper()) {
+                        detachedWallpaper = win;
+                    }
+                    final int color = winAnimator.mAnimation.getBackgroundColor();
+                    if (color != 0) {
+                        win.getStack().setAnimationBackground(winAnimator, color);
+                    }
+                }
+                mAnimating = true;
+            }
+
+            // If this window's app token is running a detached wallpaper
+            // animation, make a note so we can ensure the wallpaper is
+            // displayed behind it.
+            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
+            if (appAnimator != null && appAnimator.animation != null
+                    && appAnimator.animating) {
+                if ((flags & FLAG_SHOW_WALLPAPER) != 0
+                        && appAnimator.animation.getDetachWallpaper()) {
+                    detachedWallpaper = win;
+                }
+
+                final int color = appAnimator.animation.getBackgroundColor();
+                if (color != 0) {
+                    win.getStack().setAnimationBackground(winAnimator, color);
+                }
+            }
+        } // end forall windows
+
+        if (mWindowDetachedWallpaper != detachedWallpaper) {
+            if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
+                    "Detached wallpaper changed from " + mWindowDetachedWallpaper
+                    + " to " + detachedWallpaper);
+            mWindowDetachedWallpaper = detachedWallpaper;
+            mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
+        }
+    }
+
+    /** See if any windows have been drawn, so they (and others associated with them) can now be
+     *  shown. */
+    private void testTokenMayBeDrawnLocked(int displayId) {
+        // See if any windows have been drawn, so they (and others
+        // associated with them) can now be shown.
+        final ArrayList<Task> tasks = mService.getDisplayContentLocked(displayId).getTasks();
+        final int numTasks = tasks.size();
+        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
+            final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+            final int numTokens = tokens.size();
+            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
+                final AppWindowToken wtoken = tokens.get(tokenNdx);
+                AppWindowAnimator appAnimator = wtoken.mAppAnimator;
+                final boolean allDrawn = wtoken.allDrawn;
+                if (allDrawn != appAnimator.allDrawn) {
+                    appAnimator.allDrawn = allDrawn;
+                    if (allDrawn) {
+                        // The token has now changed state to having all
+                        // windows shown...  what to do, what to do?
+                        if (appAnimator.freezingScreen) {
+                            appAnimator.showAllWindowsLocked();
+                            mService.unsetAppFreezingScreenLocked(wtoken, false, true);
+                            if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG,
+                                    "Setting mOrientationChangeComplete=true because wtoken "
+                                    + wtoken + " numInteresting=" + wtoken.numInterestingWindows
+                                    + " numDrawn=" + wtoken.numDrawnWindows);
+                            // This will set mOrientationChangeComplete and cause a pass through layout.
+                            setAppLayoutChanges(appAnimator,
+                                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
+                                    "testTokenMayBeDrawnLocked: freezingScreen");
+                        } else {
+                            setAppLayoutChanges(appAnimator,
+                                    WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM,
+                                    "testTokenMayBeDrawnLocked");
+
+                            // We can now show all of the drawn windows!
+                            if (!mService.mOpeningApps.contains(wtoken)) {
+                                mAnimating |= appAnimator.showAllWindowsLocked();
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    /** Locked on mService.mWindowMap. */
+    private void animateLocked() {
+        if (!mInitialized) {
+            return;
+        }
+
+        mCurrentTime = SystemClock.uptimeMillis();
+        mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
+        boolean wasAnimating = mAnimating;
+        mAnimating = false;
+        if (WindowManagerService.DEBUG_WINDOW_TRACE) {
+            Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
+        }
+
+        if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
+                TAG, ">>> OPEN TRANSACTION animateLocked");
+        SurfaceControl.openTransaction();
+        SurfaceControl.setAnimationTransaction();
+        try {
+            final int numDisplays = mDisplayContentsAnimators.size();
+            for (int i = 0; i < numDisplays; i++) {
+                final int displayId = mDisplayContentsAnimators.keyAt(i);
+                updateAppWindowsLocked(displayId);
+                DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
+
+                final ScreenRotationAnimation screenRotationAnimation =
+                        displayAnimator.mScreenRotationAnimation;
+                if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
+                    if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) {
+                        mAnimating = true;
+                    } else {
+                        mBulkUpdateParams |= SET_UPDATE_ROTATION;
+                        screenRotationAnimation.kill();
+                        displayAnimator.mScreenRotationAnimation = null;
+                    }
+                }
+
+                // Update animations of all applications, including those
+                // associated with exiting/removed apps
+                updateWindowsLocked(displayId);
+                updateWallpaperLocked(displayId);
+
+                final WindowList windows = mService.getWindowListLocked(displayId);
+                final int N = windows.size();
+                for (int j = 0; j < N; j++) {
+                    windows.get(j).mWinAnimator.prepareSurfaceLocked(true);
+                }
+            }
+
+            for (int i = 0; i < numDisplays; i++) {
+                final int displayId = mDisplayContentsAnimators.keyAt(i);
+
+                testTokenMayBeDrawnLocked(displayId);
+
+                final ScreenRotationAnimation screenRotationAnimation =
+                        mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation;
+                if (screenRotationAnimation != null) {
+                    screenRotationAnimation.updateSurfacesInTransaction();
+                }
+
+                mAnimating |= mService.getDisplayContentLocked(displayId).animateDimLayers();
+
+                //TODO (multidisplay): Magnification is supported only for the default display.
+                if (mService.mDisplayMagnifier != null && displayId == Display.DEFAULT_DISPLAY) {
+                    mService.mDisplayMagnifier.drawMagnifiedRegionBorderIfNeededLocked();
+                }
+            }
+
+            if (mAnimating) {
+                mService.scheduleAnimationLocked();
+            }
+
+            mService.setFocusedStackLayer();
+
+            if (mService.mWatermark != null) {
+                mService.mWatermark.drawIfNeeded();
+            }
+        } catch (RuntimeException e) {
+            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
+        } finally {
+            SurfaceControl.closeTransaction();
+            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
+                    TAG, "<<< CLOSE TRANSACTION animateLocked");
+        }
+
+        boolean hasPendingLayoutChanges = false;
+        final int numDisplays = mService.mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
+            final int pendingChanges = getPendingLayoutChanges(displayContent.getDisplayId());
+            if ((pendingChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
+                mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
+            }
+            if (pendingChanges != 0) {
+                hasPendingLayoutChanges = true;
+            }
+        }
+
+        boolean doRequest = false;
+        if (mBulkUpdateParams != 0) {
+            doRequest = mService.copyAnimToLayoutParamsLocked();
+        }
+
+        if (hasPendingLayoutChanges || doRequest) {
+            mService.requestTraversalLocked();
+        }
+
+        if (!mAnimating && wasAnimating) {
+            mService.requestTraversalLocked();
+        }
+        if (WindowManagerService.DEBUG_WINDOW_TRACE) {
+            Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating
+                + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
+                + " mPendingLayoutChanges(DEFAULT_DISPLAY)="
+                + Integer.toHexString(getPendingLayoutChanges(Display.DEFAULT_DISPLAY)));
+        }
+    }
+
+    static String bulkUpdateParamsToString(int bulkUpdateParams) {
+        StringBuilder builder = new StringBuilder(128);
+        if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) {
+            builder.append(" UPDATE_ROTATION");
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) {
+            builder.append(" WALLPAPER_MAY_CHANGE");
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) {
+            builder.append(" FORCE_HIDING_CHANGED");
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) != 0) {
+            builder.append(" ORIENTATION_CHANGE_COMPLETE");
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) {
+            builder.append(" TURN_ON_SCREEN");
+        }
+        return builder.toString();
+    }
+
+    public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) {
+        final String subPrefix = "  " + prefix;
+        final String subSubPrefix = "  " + subPrefix;
+
+        for (int i = 0; i < mDisplayContentsAnimators.size(); i++) {
+            pw.print(prefix); pw.print("DisplayContentsAnimator #");
+                    pw.print(mDisplayContentsAnimators.keyAt(i));
+                    pw.println(":");
+            DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
+            final WindowList windows =
+                    mService.getWindowListLocked(mDisplayContentsAnimators.keyAt(i));
+            final int N = windows.size();
+            for (int j = 0; j < N; j++) {
+                WindowStateAnimator wanim = windows.get(j).mWinAnimator;
+                pw.print(subPrefix); pw.print("Window #"); pw.print(j);
+                        pw.print(": "); pw.println(wanim);
+            }
+            if (displayAnimator.mScreenRotationAnimation != null) {
+                pw.print(subPrefix); pw.println("mScreenRotationAnimation:");
+                displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw);
+            } else if (dumpAll) {
+                pw.print(subPrefix); pw.println("no ScreenRotationAnimation ");
+            }
+        }
+
+        pw.println();
+
+        if (dumpAll) {
+            pw.print(prefix); pw.print("mAnimTransactionSequence=");
+                    pw.print(mAnimTransactionSequence);
+                    pw.print(" mForceHiding="); pw.println(forceHidingToString());
+            pw.print(prefix); pw.print("mCurrentTime=");
+                    pw.println(TimeUtils.formatUptime(mCurrentTime));
+        }
+        if (mBulkUpdateParams != 0) {
+            pw.print(prefix); pw.print("mBulkUpdateParams=0x");
+                    pw.print(Integer.toHexString(mBulkUpdateParams));
+                    pw.println(bulkUpdateParamsToString(mBulkUpdateParams));
+        }
+        if (mWindowDetachedWallpaper != null) {
+            pw.print(prefix); pw.print("mWindowDetachedWallpaper=");
+                pw.println(mWindowDetachedWallpaper);
+        }
+        if (mUniverseBackground != null) {
+            pw.print(prefix); pw.print("mUniverseBackground="); pw.print(mUniverseBackground);
+                    pw.print(" mAboveUniverseLayer="); pw.println(mAboveUniverseLayer);
+        }
+    }
+
+    int getPendingLayoutChanges(final int displayId) {
+        if (displayId < 0) {
+            return 0;
+        }
+        return mService.getDisplayContentLocked(displayId).pendingLayoutChanges;
+    }
+
+    void setPendingLayoutChanges(final int displayId, final int changes) {
+        if (displayId >= 0) {
+            mService.getDisplayContentLocked(displayId).pendingLayoutChanges |= changes;
+        }
+    }
+
+    void setAppLayoutChanges(final AppWindowAnimator appAnimator, final int changes, String s) {
+        // Used to track which displays layout changes have been done.
+        SparseIntArray displays = new SparseIntArray(2);
+        WindowList windows = appAnimator.mAppToken.allAppWindows;
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            final int displayId = windows.get(i).getDisplayId();
+            if (displayId >= 0 && displays.indexOfKey(displayId) < 0) {
+                setPendingLayoutChanges(displayId, changes);
+                if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
+                    mService.debugLayoutRepeats(s, getPendingLayoutChanges(displayId));
+                }
+                // Keep from processing this display again.
+                displays.put(displayId, changes);
+            }
+        }
+    }
+
+    private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) {
+        DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
+        if (displayAnimator == null) {
+            displayAnimator = new DisplayContentsAnimator();
+            mDisplayContentsAnimators.put(displayId, displayAnimator);
+        }
+        return displayAnimator;
+    }
+
+    void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) {
+        if (displayId >= 0) {
+            getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation = animation;
+        }
+    }
+
+    ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) {
+        if (displayId < 0) {
+            return null;
+        }
+        return getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation;
+    }
+
+    private class DisplayContentsAnimator {
+        ScreenRotationAnimation mScreenRotationAnimation = null;
+    }
+}
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
new file mode 100644
index 0000000..fb5d7a7
--- /dev/null
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -0,0 +1,10930 @@
+/*
+ * Copyright (C) 2007 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.wm;
+
+import static android.view.WindowManager.LayoutParams.*;
+
+import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+
+import android.app.AppOpsManager;
+import android.util.ArraySet;
+import android.util.TimeUtils;
+import android.view.IWindowId;
+
+import com.android.internal.app.IBatteryStats;
+import com.android.internal.policy.PolicyManager;
+import com.android.internal.policy.impl.PhoneWindowManager;
+import com.android.internal.util.FastPrintWriter;
+import com.android.internal.view.IInputContext;
+import com.android.internal.view.IInputMethodClient;
+import com.android.internal.view.IInputMethodManager;
+import com.android.internal.view.WindowManagerPolicyThread;
+import com.android.server.AttributeCache;
+import com.android.server.DisplayThread;
+import com.android.server.EventLogTags;
+import com.android.server.LocalServices;
+import com.android.server.UiThread;
+import com.android.server.Watchdog;
+import com.android.server.am.BatteryStatsService;
+import com.android.server.input.InputManagerService;
+import com.android.server.power.ShutdownThread;
+
+import android.Manifest;
+import android.app.ActivityManagerNative;
+import android.app.IActivityManager;
+import android.app.StatusBarManager;
+import android.app.admin.DevicePolicyManager;
+import android.animation.ValueAnimator;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.res.CompatibilityInfo;
+import android.content.res.Configuration;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.Config;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.PixelFormat;
+import android.graphics.Point;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Region;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.DisplayManagerInternal;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Debug;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IRemoteCallback;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Parcel;
+import android.os.ParcelFileDescriptor;
+import android.os.PowerManager;
+import android.os.PowerManagerInternal;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.StrictMode;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.Trace;
+import android.os.WorkSource;
+import android.provider.Settings;
+import android.util.DisplayMetrics;
+import android.util.EventLog;
+import android.util.FloatMath;
+import android.util.Log;
+import android.util.SparseArray;
+import android.util.Pair;
+import android.util.Slog;
+import android.util.SparseIntArray;
+import android.util.TypedValue;
+import android.view.Choreographer;
+import android.view.Display;
+import android.view.DisplayInfo;
+import android.view.Gravity;
+import android.view.IApplicationToken;
+import android.view.IInputFilter;
+import android.view.IMagnificationCallbacks;
+import android.view.IOnKeyguardExitResult;
+import android.view.IRotationWatcher;
+import android.view.IWindow;
+import android.view.IWindowManager;
+import android.view.IWindowSession;
+import android.view.InputChannel;
+import android.view.InputDevice;
+import android.view.InputEvent;
+import android.view.InputEventReceiver;
+import android.view.KeyEvent;
+import android.view.MagnificationSpec;
+import android.view.MotionEvent;
+import android.view.WindowManagerInternal;
+import android.view.Surface.OutOfResourcesException;
+import android.view.Surface;
+import android.view.SurfaceControl;
+import android.view.SurfaceSession;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.view.WindowManager;
+import android.view.WindowManagerGlobal;
+import android.view.WindowManagerPolicy;
+import android.view.WindowManager.LayoutParams;
+import android.view.WindowManagerPolicy.FakeWindow;
+import android.view.WindowManagerPolicy.PointerEventListener;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Transformation;
+
+import java.io.BufferedWriter;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.Socket;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+/** {@hide} */
+public class WindowManagerService extends IWindowManager.Stub
+        implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs {
+    static final String TAG = "WindowManager";
+    static final boolean DEBUG = false;
+    static final boolean DEBUG_ADD_REMOVE = false;
+    static final boolean DEBUG_FOCUS = false;
+    static final boolean DEBUG_FOCUS_LIGHT = DEBUG_FOCUS || false;
+    static final boolean DEBUG_ANIM = false;
+    static final boolean DEBUG_LAYOUT = false;
+    static final boolean DEBUG_RESIZE = false;
+    static final boolean DEBUG_LAYERS = false;
+    static final boolean DEBUG_INPUT = false;
+    static final boolean DEBUG_INPUT_METHOD = false;
+    static final boolean DEBUG_VISIBILITY = false;
+    static final boolean DEBUG_WINDOW_MOVEMENT = false;
+    static final boolean DEBUG_TOKEN_MOVEMENT = false;
+    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_REORDER = false;
+    static final boolean DEBUG_WALLPAPER = false;
+    static final boolean DEBUG_WALLPAPER_LIGHT = false || DEBUG_WALLPAPER;
+    static final boolean DEBUG_DRAG = false;
+    static final boolean DEBUG_SCREEN_ON = false;
+    static final boolean DEBUG_SCREENSHOT = false;
+    static final boolean DEBUG_BOOT = false;
+    static final boolean DEBUG_LAYOUT_REPEATS = true;
+    static final boolean DEBUG_SURFACE_TRACE = false;
+    static final boolean DEBUG_WINDOW_TRACE = false;
+    static final boolean DEBUG_TASK_MOVEMENT = false;
+    static final boolean DEBUG_STACK = false;
+    static final boolean DEBUG_DISPLAY = false;
+    static final boolean SHOW_SURFACE_ALLOC = false;
+    static final boolean SHOW_TRANSACTIONS = false;
+    static final boolean SHOW_LIGHT_TRANSACTIONS = false || SHOW_TRANSACTIONS;
+    static final boolean HIDE_STACK_CRAWLS = true;
+    static final int LAYOUT_REPEAT_THRESHOLD = 4;
+
+    static final boolean PROFILE_ORIENTATION = false;
+    static final boolean localLOGV = DEBUG;
+
+    /** How much to multiply the policy's type layer, to reserve room
+     * for multiple windows of the same type and Z-ordering adjustment
+     * with TYPE_LAYER_OFFSET. */
+    static final int TYPE_LAYER_MULTIPLIER = 10000;
+
+    /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
+     * or below others in the same layer. */
+    static final int TYPE_LAYER_OFFSET = 1000;
+
+    /** How much to increment the layer for each window, to reserve room
+     * for effect surfaces between them.
+     */
+    static final int WINDOW_LAYER_MULTIPLIER = 5;
+
+    /**
+     * Dim surface layer is immediately below target window.
+     */
+    static final int LAYER_OFFSET_DIM = 1;
+
+    /**
+     * Blur surface layer is immediately below dim layer.
+     */
+    static final int LAYER_OFFSET_BLUR = 2;
+
+    /**
+     * FocusedStackFrame layer is immediately above focused window.
+     */
+    static final int LAYER_OFFSET_FOCUSED_STACK = 1;
+
+    /**
+     * Animation thumbnail is as far as possible below the window above
+     * the thumbnail (or in other words as far as possible above the window
+     * below it).
+     */
+    static final int LAYER_OFFSET_THUMBNAIL = WINDOW_LAYER_MULTIPLIER-1;
+
+    /**
+     * Layer at which to put the rotation freeze snapshot.
+     */
+    static final int FREEZE_LAYER = (TYPE_LAYER_MULTIPLIER * 200) + 1;
+
+    /**
+     * Layer at which to put the mask for emulated screen sizes.
+     */
+    static final int MASK_LAYER = TYPE_LAYER_MULTIPLIER * 200;
+
+    /** The maximum length we will accept for a loaded animation duration:
+     * this is 10 seconds.
+     */
+    static final int MAX_ANIMATION_DURATION = 10*1000;
+
+    /** Amount of time (in milliseconds) to animate the fade-in-out transition for
+     * compatible windows.
+     */
+    static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
+
+    /** Amount of time (in milliseconds) to delay before declaring a window freeze timeout. */
+    static final int WINDOW_FREEZE_TIMEOUT_DURATION = 2000;
+
+    /** Amount of time (in milliseconds) to delay before declaring a starting window leaked. */
+    static final int STARTING_WINDOW_TIMEOUT_DURATION = 10000;
+
+    /**
+     * If true, the window manager will do its own custom freezing and general
+     * management of the screen during rotation.
+     */
+    static final boolean CUSTOM_SCREEN_ROTATION = true;
+
+    // Maximum number of milliseconds to wait for input devices to be enumerated before
+    // proceding with safe mode detection.
+    private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
+
+    // Default input dispatching timeout in nanoseconds.
+    static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
+
+    /** Minimum value for attachStack and resizeStack weight value */
+    public static final float STACK_WEIGHT_MIN = 0.2f;
+
+    /** Maximum value for attachStack and resizeStack weight value */
+    public static final float STACK_WEIGHT_MAX = 0.8f;
+
+    static final int UPDATE_FOCUS_NORMAL = 0;
+    static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
+    static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
+    static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
+
+    private static final String SYSTEM_SECURE = "ro.secure";
+    private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
+
+    private static final String DENSITY_OVERRIDE = "ro.config.density_override";
+    private static final String SIZE_OVERRIDE = "ro.config.size_override";
+
+    private static final int MAX_SCREENSHOT_RETRIES = 3;
+
+    final private KeyguardDisableHandler mKeyguardDisableHandler;
+
+    final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) {
+                mKeyguardDisableHandler.sendEmptyMessage(
+                    KeyguardDisableHandler.KEYGUARD_POLICY_CHANGED);
+            }
+        }
+    };
+
+    // Current user when multi-user is enabled. Don't show windows of non-current user.
+    int mCurrentUserId;
+
+    final Context mContext;
+
+    final boolean mHaveInputMethods;
+
+    final boolean mAllowBootMessages;
+
+    final boolean mLimitedAlphaCompositing;
+
+    final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
+
+    final IActivityManager mActivityManager;
+
+    final IBatteryStats mBatteryStats;
+
+    final AppOpsManager mAppOps;
+
+    final DisplaySettings mDisplaySettings;
+
+    /**
+     * All currently active sessions with clients.
+     */
+    final HashSet<Session> mSessions = new HashSet<Session>();
+
+    /**
+     * Mapping from an IWindow IBinder to the server's Window object.
+     * This is also used as the lock for all of our state.
+     * NOTE: Never call into methods that lock ActivityManagerService while holding this object.
+     */
+    final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
+
+    /**
+     * Mapping from a token IBinder to a WindowToken object.
+     */
+    final HashMap<IBinder, WindowToken> mTokenMap = new HashMap<IBinder, WindowToken>();
+
+    /**
+     * List of window tokens that have finished starting their application,
+     * and now need to have the policy remove their windows.
+     */
+    final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
+
+    /**
+     * Fake windows added to the window manager.  Note: ordered from top to
+     * bottom, opposite of mWindows.
+     */
+    final ArrayList<FakeWindowImpl> mFakeWindows = new ArrayList<FakeWindowImpl>();
+
+    /**
+     * Windows that are being resized.  Used so we can tell the client about
+     * the resize after closing the transaction in which we resized the
+     * underlying surface.
+     */
+    final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
+
+    /**
+     * Windows whose animations have ended and now must be removed.
+     */
+    final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
+
+    /**
+     * Stacks whose animations have ended and whose tasks, apps, selves may now be removed.
+     */
+    final ArraySet<TaskStack> mPendingStacksRemove = new ArraySet<TaskStack>();
+
+    /**
+     * Used when processing mPendingRemove to avoid working on the original array.
+     */
+    WindowState[] mPendingRemoveTmp = new WindowState[20];
+
+    /**
+     * Windows whose surface should be destroyed.
+     */
+    final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
+
+    /**
+     * Windows that have lost input focus and are waiting for the new
+     * focus window to be displayed before they are told about this.
+     */
+    ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
+
+    /**
+     * This is set when we have run out of memory, and will either be an empty
+     * list or contain windows that need to be force removed.
+     */
+    ArrayList<WindowState> mForceRemoves;
+
+    /**
+     * Windows that clients are waiting to have drawn.
+     */
+    ArrayList<Pair<WindowState, IRemoteCallback>> mWaitingForDrawn
+            = new ArrayList<Pair<WindowState, IRemoteCallback>>();
+
+    /**
+     * Windows that have called relayout() while we were running animations,
+     * so we need to tell when the animation is done.
+     */
+    final ArrayList<WindowState> mRelayoutWhileAnimating = new ArrayList<WindowState>();
+
+    /**
+     * Used when rebuilding window list to keep track of windows that have
+     * been removed.
+     */
+    WindowState[] mRebuildTmp = new WindowState[20];
+
+    IInputMethodManager mInputMethodManager;
+
+    DisplayMagnifier mDisplayMagnifier;
+
+    final SurfaceSession mFxSession;
+    Watermark mWatermark;
+    StrictModeFlash mStrictModeFlash;
+    FocusedStackFrame mFocusedStackFrame;
+
+    int mFocusedStackLayer;
+
+    final float[] mTmpFloats = new float[9];
+    final Rect mTmpContentRect = new Rect();
+
+    boolean mDisplayReady;
+    boolean mSafeMode;
+    boolean mDisplayEnabled = false;
+    boolean mSystemBooted = false;
+    boolean mForceDisplayEnabled = false;
+    boolean mShowingBootMessages = false;
+
+    String mLastANRState;
+
+    /** All DisplayContents in the world, kept here */
+    SparseArray<DisplayContent> mDisplayContents = new SparseArray<DisplayContent>(2);
+
+    int mRotation = 0;
+    int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+    boolean mAltOrientation = false;
+    ArrayList<IRotationWatcher> mRotationWatchers
+            = new ArrayList<IRotationWatcher>();
+    int mDeferredRotationPauseCount;
+
+    int mSystemDecorLayer = 0;
+    final Rect mScreenRect = new Rect();
+
+    boolean mTraversalScheduled = false;
+    boolean mDisplayFrozen = false;
+    long mDisplayFreezeTime = 0;
+    int mLastDisplayFreezeDuration = 0;
+    Object mLastFinishedFreezeSource = null;
+    boolean mWaitingForConfig = false;
+    boolean mWindowsFreezingScreen = false;
+    boolean mClientFreezingScreen = false;
+    int mAppsFreezingScreen = 0;
+    int mLastWindowForcedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+
+    int mLayoutSeq = 0;
+
+    int mLastStatusBarVisibility = 0;
+
+    // State while inside of layoutAndPlaceSurfacesLocked().
+    boolean mFocusMayChange;
+
+    Configuration mCurConfiguration = new Configuration();
+
+    // This is held as long as we have the screen frozen, to give us time to
+    // perform a rotation animation when turning off shows the lock screen which
+    // changes the orientation.
+    private final PowerManager.WakeLock mScreenFrozenLock;
+
+    final AppTransition mAppTransition;
+    boolean mStartingIconInTransition = false;
+    boolean mSkipAppTransitionAnimation = false;
+
+    final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
+    final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
+
+    boolean mIsTouchDevice;
+
+    final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
+    final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
+    final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
+    final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
+
+    final H mH = new H();
+
+    final Choreographer mChoreographer = Choreographer.getInstance();
+
+    WindowState mCurrentFocus = null;
+    WindowState mLastFocus = null;
+
+    /** This just indicates the window the input method is on top of, not
+     * necessarily the window its input is going to. */
+    WindowState mInputMethodTarget = null;
+
+    /** If true hold off on modifying the animation layer of mInputMethodTarget */
+    boolean mInputMethodTargetWaitingAnim;
+    int mInputMethodAnimLayerAdjustment;
+
+    WindowState mInputMethodWindow = null;
+    final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
+
+    boolean mHardKeyboardAvailable;
+    boolean mHardKeyboardEnabled;
+    OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
+
+    final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
+
+    // If non-null, this is the currently visible window that is associated
+    // with the wallpaper.
+    WindowState mWallpaperTarget = null;
+    // If non-null, we are in the middle of animating from one wallpaper target
+    // to another, and this is the lower one in Z-order.
+    WindowState mLowerWallpaperTarget = null;
+    // If non-null, we are in the middle of animating from one wallpaper target
+    // to another, and this is the higher one in Z-order.
+    WindowState mUpperWallpaperTarget = null;
+    int mWallpaperAnimLayerAdjustment;
+    float mLastWallpaperX = -1;
+    float mLastWallpaperY = -1;
+    float mLastWallpaperXStep = -1;
+    float mLastWallpaperYStep = -1;
+    // This is set when we are waiting for a wallpaper to tell us it is done
+    // changing its scroll position.
+    WindowState mWaitingOnWallpaper;
+    // The last time we had a timeout when waiting for a wallpaper.
+    long mLastWallpaperTimeoutTime;
+    // We give a wallpaper up to 150ms to finish scrolling.
+    static final long WALLPAPER_TIMEOUT = 150;
+    // Time we wait after a timeout before trying to wait again.
+    static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
+    boolean mAnimateWallpaperWithTarget;
+
+    AppWindowToken mFocusedApp = null;
+
+    PowerManager mPowerManager;
+    PowerManagerInternal mPowerManagerInternal;
+
+    float mWindowAnimationScale = 1.0f;
+    float mTransitionAnimationScale = 1.0f;
+    float mAnimatorDurationScale = 1.0f;
+
+    final InputManagerService mInputManager;
+    final DisplayManagerInternal mDisplayManagerInternal;
+    final DisplayManager mDisplayManager;
+
+    // Who is holding the screen on.
+    Session mHoldingScreenOn;
+    PowerManager.WakeLock mHoldingScreenWakeLock;
+
+    boolean mTurnOnScreen;
+
+    DragState mDragState = null;
+
+    // For frozen screen animations.
+    int mExitAnimId, mEnterAnimId;
+
+    /** Pulled out of performLayoutAndPlaceSurfacesLockedInner in order to refactor into multiple
+     * methods. */
+    class LayoutFields {
+        static final int SET_UPDATE_ROTATION                = 1 << 0;
+        static final int SET_WALLPAPER_MAY_CHANGE           = 1 << 1;
+        static final int SET_FORCE_HIDING_CHANGED           = 1 << 2;
+        static final int SET_ORIENTATION_CHANGE_COMPLETE    = 1 << 3;
+        static final int SET_TURN_ON_SCREEN                 = 1 << 4;
+        static final int SET_WALLPAPER_ACTION_PENDING       = 1 << 5;
+
+        boolean mWallpaperForceHidingChanged = false;
+        boolean mWallpaperMayChange = false;
+        boolean mOrientationChangeComplete = true;
+        Object mLastWindowFreezeSource = null;
+        private Session mHoldScreen = null;
+        private boolean mObscured = false;
+        private boolean mSyswin = false;
+        private float mScreenBrightness = -1;
+        private float mButtonBrightness = -1;
+        private long mUserActivityTimeout = -1;
+        private boolean mUpdateRotation = false;
+        boolean mWallpaperActionPending = false;
+
+        // Set to true when the display contains content to show the user.
+        // When false, the display manager may choose to mirror or blank the display.
+        boolean mDisplayHasContent = false;
+
+        // Only set while traversing the default display based on its content.
+        // Affects the behavior of mirroring on secondary displays.
+        boolean mObscureApplicationContentOnSecondaryDisplays = false;
+    }
+    final LayoutFields mInnerFields = new LayoutFields();
+
+    boolean mAnimationScheduled;
+
+    /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
+     * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
+    private int mTransactionSequence;
+
+    /** Only do a maximum of 6 repeated layouts. After that quit */
+    private int mLayoutRepeatCount;
+
+    final WindowAnimator mAnimator;
+
+    SparseArray<Task> mTaskIdToTask = new SparseArray<Task>();
+
+    /** All of the TaskStacks in the window manager, unordered. For an ordered list call
+     * DisplayContent.getStacks(). */
+    SparseArray<TaskStack> mStackIdToStack = new SparseArray<TaskStack>();
+
+    private final PointerEventDispatcher mPointerEventDispatcher;
+
+    final class DragInputEventReceiver extends InputEventReceiver {
+        public DragInputEventReceiver(InputChannel inputChannel, Looper looper) {
+            super(inputChannel, looper);
+        }
+
+        @Override
+        public void onInputEvent(InputEvent event) {
+            boolean handled = false;
+            try {
+                if (event instanceof MotionEvent
+                        && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
+                        && mDragState != null) {
+                    final MotionEvent motionEvent = (MotionEvent)event;
+                    boolean endDrag = false;
+                    final float newX = motionEvent.getRawX();
+                    final float newY = motionEvent.getRawY();
+
+                    switch (motionEvent.getAction()) {
+                    case MotionEvent.ACTION_DOWN: {
+                        if (DEBUG_DRAG) {
+                            Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
+                        }
+                    } break;
+
+                    case MotionEvent.ACTION_MOVE: {
+                        synchronized (mWindowMap) {
+                            // move the surface and tell the involved window(s) where we are
+                            mDragState.notifyMoveLw(newX, newY);
+                        }
+                    } break;
+
+                    case MotionEvent.ACTION_UP: {
+                        if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
+                                + newX + "," + newY);
+                        synchronized (mWindowMap) {
+                            endDrag = mDragState.notifyDropLw(newX, newY);
+                        }
+                    } break;
+
+                    case MotionEvent.ACTION_CANCEL: {
+                        if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
+                        endDrag = true;
+                    } break;
+                    }
+
+                    if (endDrag) {
+                        if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
+                        // tell all the windows that the drag has ended
+                        synchronized (mWindowMap) {
+                            mDragState.endDragLw();
+                        }
+                    }
+
+                    handled = true;
+                }
+            } catch (Exception e) {
+                Slog.e(TAG, "Exception caught by drag handleMotion", e);
+            } finally {
+                finishInputEvent(event, handled);
+            }
+        }
+    }
+
+    /**
+     * Whether the UI is currently running in touch mode (not showing
+     * navigational focus because the user is directly pressing the screen).
+     */
+    boolean mInTouchMode = true;
+
+    private ViewServer mViewServer;
+    private final ArrayList<WindowChangeListener> mWindowChangeListeners =
+        new ArrayList<WindowChangeListener>();
+    private boolean mWindowsChanged = false;
+
+    public interface WindowChangeListener {
+        public void windowsChanged();
+        public void focusChanged();
+    }
+
+    final Configuration mTempConfiguration = new Configuration();
+
+    // The desired scaling factor for compatible apps.
+    float mCompatibleScreenScale;
+
+    // If true, only the core apps and services are being launched because the device
+    // is in a special boot mode, such as being encrypted or waiting for a decryption password.
+    // For example, when this flag is true, there will be no wallpaper service.
+    final boolean mOnlyCore;
+
+    public static WindowManagerService main(final Context context,
+            final InputManagerService im,
+            final boolean haveInputMethods, final boolean showBootMsgs,
+            final boolean onlyCore) {
+        final WindowManagerService[] holder = new WindowManagerService[1];
+        DisplayThread.getHandler().runWithScissors(new Runnable() {
+            @Override
+            public void run() {
+                holder[0] = new WindowManagerService(context, im,
+                        haveInputMethods, showBootMsgs, onlyCore);
+            }
+        }, 0);
+        return holder[0];
+    }
+
+    private void initPolicy() {
+        UiThread.getHandler().runWithScissors(new Runnable() {
+            @Override
+            public void run() {
+                WindowManagerPolicyThread.set(Thread.currentThread(), Looper.myLooper());
+
+                mPolicy.init(mContext, WindowManagerService.this, WindowManagerService.this);
+                mAnimator.mAboveUniverseLayer = mPolicy.getAboveUniverseLayer()
+                        * TYPE_LAYER_MULTIPLIER
+                        + TYPE_LAYER_OFFSET;
+            }
+        }, 0);
+    }
+
+    private WindowManagerService(Context context, InputManagerService inputManager,
+            boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) {
+        mContext = context;
+        mHaveInputMethods = haveInputMethods;
+        mAllowBootMessages = showBootMsgs;
+        mOnlyCore = onlyCore;
+        mLimitedAlphaCompositing = context.getResources().getBoolean(
+                com.android.internal.R.bool.config_sf_limitedAlpha);
+        mInputManager = inputManager; // Must be before createDisplayContentLocked.
+        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
+        mDisplaySettings = new DisplaySettings(context);
+        mDisplaySettings.readSettingsLocked();
+
+        mPointerEventDispatcher = new PointerEventDispatcher(mInputManager.monitorInput(TAG));
+
+        mFxSession = new SurfaceSession();
+        mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
+        Display[] displays = mDisplayManager.getDisplays();
+        for (Display display : displays) {
+            createDisplayContentLocked(display);
+        }
+
+        mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy);
+
+        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
+        mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
+        mPowerManagerInternal.setPolicy(mPolicy); // TODO: register as local service instead
+        mScreenFrozenLock = mPowerManager.newWakeLock(
+                PowerManager.PARTIAL_WAKE_LOCK, "SCREEN_FROZEN");
+        mScreenFrozenLock.setReferenceCounted(false);
+
+        mAppTransition = new AppTransition(context, mH);
+
+        mActivityManager = ActivityManagerNative.getDefault();
+        mBatteryStats = BatteryStatsService.getService();
+        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
+        mAppOps.startWatchingMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, null,
+                new AppOpsManager.OnOpChangedInternalListener() {
+                    @Override
+                    public void onOpChanged(int op, String packageName) {
+                        updateAppOpsState();
+                    }
+                }
+        );
+
+        // Get persisted window scale setting
+        mWindowAnimationScale = Settings.Global.getFloat(context.getContentResolver(),
+                Settings.Global.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
+        mTransitionAnimationScale = Settings.Global.getFloat(context.getContentResolver(),
+                Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
+        setAnimatorDurationScale(Settings.Global.getFloat(context.getContentResolver(),
+                Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale));
+
+        // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
+        mContext.registerReceiver(mBroadcastReceiver, filter);
+
+        mHoldingScreenWakeLock = mPowerManager.newWakeLock(
+                PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG);
+        mHoldingScreenWakeLock.setReferenceCounted(false);
+
+        mAnimator = new WindowAnimator(this);
+
+        initPolicy();
+
+        // Add ourself to the Watchdog monitors.
+        Watchdog.getInstance().addMonitor(this);
+
+        SurfaceControl.openTransaction();
+        try {
+            createWatermarkInTransaction();
+            mFocusedStackFrame = new FocusedStackFrame(
+                    getDefaultDisplayContentLocked().getDisplay(), mFxSession);
+        } finally {
+            SurfaceControl.closeTransaction();
+        }
+
+        LocalServices.addService(WindowManagerInternal.class, new LocalService());
+    }
+
+    public InputMonitor getInputMonitor() {
+        return mInputMonitor;
+    }
+
+    @Override
+    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+            throws RemoteException {
+        try {
+            return super.onTransact(code, data, reply, flags);
+        } catch (RuntimeException e) {
+            // The window manager only throws security exceptions, so let's
+            // log all others.
+            if (!(e instanceof SecurityException)) {
+                Slog.wtf(TAG, "Window Manager Crash", e);
+            }
+            throw e;
+        }
+    }
+
+    private void placeWindowAfter(WindowState pos, WindowState window) {
+        final WindowList windows = pos.getWindowList();
+        final int i = windows.indexOf(pos);
+        if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
+            TAG, "Adding window " + window + " at "
+            + (i+1) + " of " + windows.size() + " (after " + pos + ")");
+        windows.add(i+1, window);
+        mWindowsChanged = true;
+    }
+
+    private void placeWindowBefore(WindowState pos, WindowState window) {
+        final WindowList windows = pos.getWindowList();
+        int i = windows.indexOf(pos);
+        if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
+            TAG, "Adding window " + window + " at "
+            + i + " of " + windows.size() + " (before " + pos + ")");
+        if (i < 0) {
+            Slog.w(TAG, "placeWindowBefore: Unable to find " + pos + " in " + windows);
+            i = 0;
+        }
+        windows.add(i, window);
+        mWindowsChanged = true;
+    }
+
+    //This method finds out the index of a window that has the same app token as
+    //win. used for z ordering the windows in mWindows
+    private int findIdxBasedOnAppTokens(WindowState win) {
+        WindowList windows = win.getWindowList();
+        for(int j = windows.size() - 1; j >= 0; j--) {
+            WindowState wentry = windows.get(j);
+            if(wentry.mAppToken == win.mAppToken) {
+                return j;
+            }
+        }
+        return -1;
+    }
+
+    /**
+     * Return the list of Windows from the passed token on the given Display.
+     * @param token The token with all the windows.
+     * @param displayContent The display we are interested in.
+     * @return List of windows from token that are on displayContent.
+     */
+    WindowList getTokenWindowsOnDisplay(WindowToken token, DisplayContent displayContent) {
+        final WindowList windowList = new WindowList();
+        final int count = token.windows.size();
+        for (int i = 0; i < count; i++) {
+            final WindowState win = token.windows.get(i);
+            if (win.getDisplayContent() == displayContent) {
+                windowList.add(win);
+            }
+        }
+        return windowList;
+    }
+
+    /**
+     * Recursive search through a WindowList and all of its windows' children.
+     * @param targetWin The window to search for.
+     * @param windows The list to search.
+     * @return The index of win in windows or of the window that is an ancestor of win.
+     */
+    private int indexOfWinInWindowList(WindowState targetWin, WindowList windows) {
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            final WindowState w = windows.get(i);
+            if (w == targetWin) {
+                return i;
+            }
+            if (!w.mChildWindows.isEmpty()) {
+                if (indexOfWinInWindowList(targetWin, w.mChildWindows) >= 0) {
+                    return i;
+                }
+            }
+        }
+        return -1;
+    }
+
+    private int addAppWindowToListLocked(final WindowState win) {
+        final IWindow client = win.mClient;
+        final WindowToken token = win.mToken;
+        final DisplayContent displayContent = win.getDisplayContent();
+
+        final WindowList windows = win.getWindowList();
+        final int N = windows.size();
+        WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent);
+        int tokenWindowsPos = 0;
+        int windowListPos = tokenWindowList.size();
+        if (!tokenWindowList.isEmpty()) {
+            // If this application has existing windows, we
+            // simply place the new window on top of them... but
+            // keep the starting window on top.
+            if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
+                // Base windows go behind everything else.
+                WindowState lowestWindow = tokenWindowList.get(0);
+                placeWindowBefore(lowestWindow, win);
+                tokenWindowsPos = indexOfWinInWindowList(lowestWindow, token.windows);
+            } else {
+                AppWindowToken atoken = win.mAppToken;
+                WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
+                if (atoken != null && lastWindow == atoken.startingWindow) {
+                    placeWindowBefore(lastWindow, win);
+                    tokenWindowsPos = indexOfWinInWindowList(lastWindow, token.windows);
+                } else {
+                    int newIdx = findIdxBasedOnAppTokens(win);
+                    //there is a window above this one associated with the same
+                    //apptoken note that the window could be a floating window
+                    //that was created later or a window at the top of the list of
+                    //windows associated with this token.
+                    if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
+                            "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of " +
+                            N);
+                    windows.add(newIdx + 1, win);
+                    if (newIdx < 0) {
+                        // No window from token found on win's display.
+                        tokenWindowsPos = 0;
+                    } else {
+                        tokenWindowsPos = indexOfWinInWindowList(
+                                windows.get(newIdx), token.windows) + 1;
+                    }
+                    mWindowsChanged = true;
+                }
+            }
+            return tokenWindowsPos;
+        }
+
+        // No windows from this token on this display
+        if (localLOGV) Slog.v(TAG, "Figuring out where to add app window " + client.asBinder()
+                + " (token=" + token + ")");
+        // Figure out where the window should go, based on the
+        // order of applications.
+        WindowState pos = null;
+
+        final ArrayList<Task> tasks = displayContent.getTasks();
+        int taskNdx;
+        int tokenNdx = -1;
+        for (taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+            for (tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                final AppWindowToken t = tokens.get(tokenNdx);
+                if (t == token) {
+                    --tokenNdx;
+                    if (tokenNdx < 0) {
+                        --taskNdx;
+                        if (taskNdx >= 0) {
+                            tokenNdx = tasks.get(taskNdx).mAppTokens.size() - 1;
+                        }
+                    }
+                    break;
+                }
+
+                // We haven't reached the token yet; if this token
+                // is not going to the bottom and has windows on this display, we can
+                // use it as an anchor for when we do reach the token.
+                tokenWindowList = getTokenWindowsOnDisplay(t, displayContent);
+                if (!t.sendingToBottom && tokenWindowList.size() > 0) {
+                    pos = tokenWindowList.get(0);
+                }
+            }
+            if (tokenNdx >= 0) {
+                // early exit
+                break;
+            }
+        }
+
+        // We now know the index into the apps.  If we found
+        // an app window above, that gives us the position; else
+        // we need to look some more.
+        if (pos != null) {
+            // Move behind any windows attached to this one.
+            WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
+            if (atoken != null) {
+                tokenWindowList =
+                        getTokenWindowsOnDisplay(atoken, displayContent);
+                final int NC = tokenWindowList.size();
+                if (NC > 0) {
+                    WindowState bottom = tokenWindowList.get(0);
+                    if (bottom.mSubLayer < 0) {
+                        pos = bottom;
+                    }
+                }
+            }
+            placeWindowBefore(pos, win);
+            return tokenWindowsPos;
+        }
+
+        // Continue looking down until we find the first
+        // token that has windows on this display.
+        for ( ; taskNdx >= 0; --taskNdx) {
+            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+            for ( ; tokenNdx >= 0; --tokenNdx) {
+                final AppWindowToken t = tokens.get(tokenNdx);
+                tokenWindowList = getTokenWindowsOnDisplay(t, displayContent);
+                final int NW = tokenWindowList.size();
+                if (NW > 0) {
+                    pos = tokenWindowList.get(NW-1);
+                    break;
+                }
+            }
+            if (tokenNdx >= 0) {
+                // found
+                break;
+            }
+        }
+
+        if (pos != null) {
+            // Move in front of any windows attached to this
+            // one.
+            WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
+            if (atoken != null) {
+                final int NC = atoken.windows.size();
+                if (NC > 0) {
+                    WindowState top = atoken.windows.get(NC-1);
+                    if (top.mSubLayer >= 0) {
+                        pos = top;
+                    }
+                }
+            }
+            placeWindowAfter(pos, win);
+            return tokenWindowsPos;
+        }
+
+        // Just search for the start of this layer.
+        final int myLayer = win.mBaseLayer;
+        int i;
+        for (i = 0; i < N; i++) {
+            WindowState w = windows.get(i);
+            if (w.mBaseLayer > myLayer) {
+                break;
+            }
+        }
+        if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
+                "Based on layer: Adding window " + win + " at " + i + " of " + N);
+        windows.add(i, win);
+        mWindowsChanged = true;
+        return tokenWindowsPos;
+    }
+
+    private void addFreeWindowToListLocked(final WindowState win) {
+        final WindowList windows = win.getWindowList();
+
+        // Figure out where window should go, based on layer.
+        final int myLayer = win.mBaseLayer;
+        int i;
+        for (i = windows.size() - 1; i >= 0; i--) {
+            if (windows.get(i).mBaseLayer <= myLayer) {
+                break;
+            }
+        }
+        i++;
+        if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
+                "Free window: Adding window " + win + " at " + i + " of " + windows.size());
+        windows.add(i, win);
+        mWindowsChanged = true;
+    }
+
+    private void addAttachedWindowToListLocked(final WindowState win, boolean addToToken) {
+        final WindowToken token = win.mToken;
+        final DisplayContent displayContent = win.getDisplayContent();
+        final WindowState attached = win.mAttachedWindow;
+
+        WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent);
+
+        // Figure out this window's ordering relative to the window
+        // it is attached to.
+        final int NA = tokenWindowList.size();
+        final int sublayer = win.mSubLayer;
+        int largestSublayer = Integer.MIN_VALUE;
+        WindowState windowWithLargestSublayer = null;
+        int i;
+        for (i = 0; i < NA; i++) {
+            WindowState w = tokenWindowList.get(i);
+            final int wSublayer = w.mSubLayer;
+            if (wSublayer >= largestSublayer) {
+                largestSublayer = wSublayer;
+                windowWithLargestSublayer = w;
+            }
+            if (sublayer < 0) {
+                // For negative sublayers, we go below all windows
+                // in the same sublayer.
+                if (wSublayer >= sublayer) {
+                    if (addToToken) {
+                        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
+                        token.windows.add(i, win);
+                    }
+                    placeWindowBefore(wSublayer >= 0 ? attached : w, win);
+                    break;
+                }
+            } else {
+                // For positive sublayers, we go above all windows
+                // in the same sublayer.
+                if (wSublayer > sublayer) {
+                    if (addToToken) {
+                        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
+                        token.windows.add(i, win);
+                    }
+                    placeWindowBefore(w, win);
+                    break;
+                }
+            }
+        }
+        if (i >= NA) {
+            if (addToToken) {
+                if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
+                token.windows.add(win);
+            }
+            if (sublayer < 0) {
+                placeWindowBefore(attached, win);
+            } else {
+                placeWindowAfter(largestSublayer >= 0
+                                 ? windowWithLargestSublayer
+                                 : attached,
+                                 win);
+            }
+        }
+    }
+
+    private void addWindowToListInOrderLocked(final WindowState win, boolean addToToken) {
+        if (DEBUG_FOCUS_LIGHT) Slog.d(TAG, "addWindowToListInOrderLocked: win=" + win +
+                " Callers=" + Debug.getCallers(4));
+        if (win.mAttachedWindow == null) {
+            final WindowToken token = win.mToken;
+            int tokenWindowsPos = 0;
+            if (token.appWindowToken != null) {
+                tokenWindowsPos = addAppWindowToListLocked(win);
+            } else {
+                addFreeWindowToListLocked(win);
+            }
+            if (addToToken) {
+                if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
+                token.windows.add(tokenWindowsPos, win);
+            }
+        } else {
+            addAttachedWindowToListLocked(win, addToToken);
+        }
+
+        if (win.mAppToken != null && addToToken) {
+            win.mAppToken.allAppWindows.add(win);
+        }
+    }
+
+    static boolean canBeImeTarget(WindowState w) {
+        final int fl = w.mAttrs.flags
+                & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
+        if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
+                || w.mAttrs.type == TYPE_APPLICATION_STARTING) {
+            if (DEBUG_INPUT_METHOD) {
+                Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
+                if (!w.isVisibleOrAdding()) {
+                    Slog.i(TAG, "  mSurface=" + w.mWinAnimator.mSurfaceControl
+                            + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
+                            + " policyVis=" + w.mPolicyVisibility
+                            + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim
+                            + " attachHid=" + w.mAttachedHidden
+                            + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
+                    if (w.mAppToken != null) {
+                        Slog.i(TAG, "  mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
+                    }
+                }
+            }
+            return w.isVisibleOrAdding();
+        }
+        return false;
+    }
+
+    /**
+     * Dig through the WindowStates and find the one that the Input Method will target.
+     * @param willMove
+     * @return The index+1 in mWindows of the discovered target.
+     */
+    int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
+        // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
+        // same display. Or even when the current IME/target are not on the same screen as the next
+        // IME/target. For now only look for input windows on the main screen.
+        WindowList windows = getDefaultWindowListLocked();
+        WindowState w = null;
+        int i;
+        for (i = windows.size() - 1; i >= 0; --i) {
+            WindowState win = windows.get(i);
+
+            if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
+                    + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags));
+            if (canBeImeTarget(win)) {
+                w = win;
+                //Slog.i(TAG, "Putting input method here!");
+
+                // Yet more tricksyness!  If this window is a "starting"
+                // window, we do actually want to be on top of it, but
+                // it is not -really- where input will go.  So if the caller
+                // is not actually looking to move the IME, look down below
+                // for a real window to target...
+                if (!willMove
+                        && w.mAttrs.type == TYPE_APPLICATION_STARTING
+                        && i > 0) {
+                    WindowState wb = windows.get(i-1);
+                    if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
+                        i--;
+                        w = wb;
+                    }
+                }
+                break;
+            }
+        }
+
+        // Now w is either mWindows[0] or an IME (or null if mWindows is empty).
+
+        if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
+
+        // Now, a special case -- if the last target's window is in the
+        // process of exiting, and is above the new target, keep on the
+        // last target to avoid flicker.  Consider for example a Dialog with
+        // the IME shown: when the Dialog is dismissed, we want to keep
+        // the IME above it until it is completely gone so it doesn't drop
+        // behind the dialog or its full-screen scrim.
+        final WindowState curTarget = mInputMethodTarget;
+        if (curTarget != null
+                && curTarget.isDisplayedLw()
+                && curTarget.isClosing()
+                && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
+            if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, not changing");
+            return windows.indexOf(curTarget) + 1;
+        }
+
+        if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
+                + w + " willMove=" + willMove);
+
+        if (willMove && w != null) {
+            AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
+            if (token != null) {
+
+                // Now some fun for dealing with window animations that
+                // modify the Z order.  We need to look at all windows below
+                // the current target that are in this app, finding the highest
+                // visible one in layering.
+                WindowState highestTarget = null;
+                int highestPos = 0;
+                if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
+                    WindowList curWindows = curTarget.getWindowList();
+                    int pos = curWindows.indexOf(curTarget);
+                    while (pos >= 0) {
+                        WindowState win = curWindows.get(pos);
+                        if (win.mAppToken != token) {
+                            break;
+                        }
+                        if (!win.mRemoved) {
+                            if (highestTarget == null || win.mWinAnimator.mAnimLayer >
+                                    highestTarget.mWinAnimator.mAnimLayer) {
+                                highestTarget = win;
+                                highestPos = pos;
+                            }
+                        }
+                        pos--;
+                    }
+                }
+
+                if (highestTarget != null) {
+                    if (DEBUG_INPUT_METHOD) Slog.v(TAG, mAppTransition + " " + highestTarget
+                            + " animating=" + highestTarget.mWinAnimator.isAnimating()
+                            + " layer=" + highestTarget.mWinAnimator.mAnimLayer
+                            + " new layer=" + w.mWinAnimator.mAnimLayer);
+
+                    if (mAppTransition.isTransitionSet()) {
+                        // If we are currently setting up for an animation,
+                        // hold everything until we can find out what will happen.
+                        mInputMethodTargetWaitingAnim = true;
+                        mInputMethodTarget = highestTarget;
+                        return highestPos + 1;
+                    } else if (highestTarget.mWinAnimator.isAnimating() &&
+                            highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
+                        // If the window we are currently targeting is involved
+                        // with an animation, and it is on top of the next target
+                        // we will be over, then hold off on moving until
+                        // that is done.
+                        mInputMethodTargetWaitingAnim = true;
+                        mInputMethodTarget = highestTarget;
+                        return highestPos + 1;
+                    }
+                }
+            }
+        }
+
+        //Slog.i(TAG, "Placing input method @" + (i+1));
+        if (w != null) {
+            if (willMove) {
+                if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to "
+                        + w + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4)));
+                mInputMethodTarget = w;
+                mInputMethodTargetWaitingAnim = false;
+                if (w.mAppToken != null) {
+                    setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment);
+                } else {
+                    setInputMethodAnimLayerAdjustment(0);
+                }
+            }
+            return i+1;
+        }
+        if (willMove) {
+            if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to null."
+                    + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4)));
+            mInputMethodTarget = null;
+            setInputMethodAnimLayerAdjustment(0);
+        }
+        return -1;
+    }
+
+    void addInputMethodWindowToListLocked(WindowState win) {
+        int pos = findDesiredInputMethodWindowIndexLocked(true);
+        if (pos >= 0) {
+            win.mTargetAppToken = mInputMethodTarget.mAppToken;
+            if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
+                    TAG, "Adding input method window " + win + " at " + pos);
+            // TODO(multidisplay): IMEs are only supported on the default display.
+            getDefaultWindowListLocked().add(pos, win);
+            mWindowsChanged = true;
+            moveInputMethodDialogsLocked(pos+1);
+            return;
+        }
+        win.mTargetAppToken = null;
+        addWindowToListInOrderLocked(win, true);
+        moveInputMethodDialogsLocked(pos);
+    }
+
+    void setInputMethodAnimLayerAdjustment(int adj) {
+        if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
+        mInputMethodAnimLayerAdjustment = adj;
+        WindowState imw = mInputMethodWindow;
+        if (imw != null) {
+            imw.mWinAnimator.mAnimLayer = imw.mLayer + adj;
+            if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
+                    + " anim layer: " + imw.mWinAnimator.mAnimLayer);
+            int wi = imw.mChildWindows.size();
+            while (wi > 0) {
+                wi--;
+                WindowState cw = imw.mChildWindows.get(wi);
+                cw.mWinAnimator.mAnimLayer = cw.mLayer + adj;
+                if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
+                        + " anim layer: " + cw.mWinAnimator.mAnimLayer);
+            }
+        }
+        int di = mInputMethodDialogs.size();
+        while (di > 0) {
+            di --;
+            imw = mInputMethodDialogs.get(di);
+            imw.mWinAnimator.mAnimLayer = imw.mLayer + adj;
+            if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
+                    + " anim layer: " + imw.mWinAnimator.mAnimLayer);
+        }
+    }
+
+    private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
+        WindowList windows = win.getWindowList();
+        int wpos = windows.indexOf(win);
+        if (wpos >= 0) {
+            if (wpos < interestingPos) interestingPos--;
+            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
+            windows.remove(wpos);
+            mWindowsChanged = true;
+            int NC = win.mChildWindows.size();
+            while (NC > 0) {
+                NC--;
+                WindowState cw = win.mChildWindows.get(NC);
+                int cpos = windows.indexOf(cw);
+                if (cpos >= 0) {
+                    if (cpos < interestingPos) interestingPos--;
+                    if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
+                            + cpos + ": " + cw);
+                    windows.remove(cpos);
+                }
+            }
+        }
+        return interestingPos;
+    }
+
+    private void reAddWindowToListInOrderLocked(WindowState win) {
+        addWindowToListInOrderLocked(win, false);
+        // This is a hack to get all of the child windows added as well
+        // at the right position.  Child windows should be rare and
+        // this case should be rare, so it shouldn't be that big a deal.
+        WindowList windows = win.getWindowList();
+        int wpos = windows.indexOf(win);
+        if (wpos >= 0) {
+            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos + ": " + win);
+            windows.remove(wpos);
+            mWindowsChanged = true;
+            reAddWindowLocked(wpos, win);
+        }
+    }
+
+    void logWindowList(final WindowList windows, String prefix) {
+        int N = windows.size();
+        while (N > 0) {
+            N--;
+            Slog.v(TAG, prefix + "#" + N + ": " + windows.get(N));
+        }
+    }
+
+    void moveInputMethodDialogsLocked(int pos) {
+        ArrayList<WindowState> dialogs = mInputMethodDialogs;
+
+        // TODO(multidisplay): IMEs are only supported on the default display.
+        WindowList windows = getDefaultWindowListLocked();
+        final int N = dialogs.size();
+        if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
+        for (int i=0; i<N; i++) {
+            pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
+        }
+        if (DEBUG_INPUT_METHOD) {
+            Slog.v(TAG, "Window list w/pos=" + pos);
+            logWindowList(windows, "  ");
+        }
+
+        if (pos >= 0) {
+            final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
+            if (pos < windows.size()) {
+                WindowState wp = windows.get(pos);
+                if (wp == mInputMethodWindow) {
+                    pos++;
+                }
+            }
+            if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
+            for (int i=0; i<N; i++) {
+                WindowState win = dialogs.get(i);
+                win.mTargetAppToken = targetAppToken;
+                pos = reAddWindowLocked(pos, win);
+            }
+            if (DEBUG_INPUT_METHOD) {
+                Slog.v(TAG, "Final window list:");
+                logWindowList(windows, "  ");
+            }
+            return;
+        }
+        for (int i=0; i<N; i++) {
+            WindowState win = dialogs.get(i);
+            win.mTargetAppToken = null;
+            reAddWindowToListInOrderLocked(win);
+            if (DEBUG_INPUT_METHOD) {
+                Slog.v(TAG, "No IM target, final list:");
+                logWindowList(windows, "  ");
+            }
+        }
+    }
+
+    boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
+        final WindowState imWin = mInputMethodWindow;
+        final int DN = mInputMethodDialogs.size();
+        if (imWin == null && DN == 0) {
+            return false;
+        }
+
+        // TODO(multidisplay): IMEs are only supported on the default display.
+        WindowList windows = getDefaultWindowListLocked();
+
+        int imPos = findDesiredInputMethodWindowIndexLocked(true);
+        if (imPos >= 0) {
+            // In this case, the input method windows are to be placed
+            // immediately above the window they are targeting.
+
+            // First check to see if the input method windows are already
+            // located here, and contiguous.
+            final int N = windows.size();
+            WindowState firstImWin = imPos < N
+                    ? windows.get(imPos) : null;
+
+            // Figure out the actual input method window that should be
+            // at the bottom of their stack.
+            WindowState baseImWin = imWin != null
+                    ? imWin : mInputMethodDialogs.get(0);
+            if (baseImWin.mChildWindows.size() > 0) {
+                WindowState cw = baseImWin.mChildWindows.get(0);
+                if (cw.mSubLayer < 0) baseImWin = cw;
+            }
+
+            if (firstImWin == baseImWin) {
+                // The windows haven't moved...  but are they still contiguous?
+                // First find the top IM window.
+                int pos = imPos+1;
+                while (pos < N) {
+                    if (!(windows.get(pos)).mIsImWindow) {
+                        break;
+                    }
+                    pos++;
+                }
+                pos++;
+                // Now there should be no more input method windows above.
+                while (pos < N) {
+                    if ((windows.get(pos)).mIsImWindow) {
+                        break;
+                    }
+                    pos++;
+                }
+                if (pos >= N) {
+                    // Z order is good.
+                    // The IM target window may be changed, so update the mTargetAppToken.
+                    if (imWin != null) {
+                        imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
+                    }
+                    return false;
+                }
+            }
+
+            if (imWin != null) {
+                if (DEBUG_INPUT_METHOD) {
+                    Slog.v(TAG, "Moving IM from " + imPos);
+                    logWindowList(windows, "  ");
+                }
+                imPos = tmpRemoveWindowLocked(imPos, imWin);
+                if (DEBUG_INPUT_METHOD) {
+                    Slog.v(TAG, "List after removing with new pos " + imPos + ":");
+                    logWindowList(windows, "  ");
+                }
+                imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
+                reAddWindowLocked(imPos, imWin);
+                if (DEBUG_INPUT_METHOD) {
+                    Slog.v(TAG, "List after moving IM to " + imPos + ":");
+                    logWindowList(windows, "  ");
+                }
+                if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
+            } else {
+                moveInputMethodDialogsLocked(imPos);
+            }
+
+        } else {
+            // In this case, the input method windows go in a fixed layer,
+            // because they aren't currently associated with a focus window.
+
+            if (imWin != null) {
+                if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
+                tmpRemoveWindowLocked(0, imWin);
+                imWin.mTargetAppToken = null;
+                reAddWindowToListInOrderLocked(imWin);
+                if (DEBUG_INPUT_METHOD) {
+                    Slog.v(TAG, "List with no IM target:");
+                    logWindowList(windows, "  ");
+                }
+                if (DN > 0) moveInputMethodDialogsLocked(-1);
+            } else {
+                moveInputMethodDialogsLocked(-1);
+            }
+
+        }
+
+        if (needAssignLayers) {
+            assignLayersLocked(windows);
+        }
+
+        return true;
+    }
+
+    final boolean isWallpaperVisible(WindowState wallpaperTarget) {
+        if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured="
+                + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
+                + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
+                        ? wallpaperTarget.mAppToken.mAppAnimator.animation : null)
+                + " upper=" + mUpperWallpaperTarget
+                + " lower=" + mLowerWallpaperTarget);
+        return (wallpaperTarget != null
+                        && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
+                                && wallpaperTarget.mAppToken.mAppAnimator.animation != null)))
+                || mUpperWallpaperTarget != null
+                || mLowerWallpaperTarget != null;
+    }
+
+    static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
+    static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
+
+    int adjustWallpaperWindowsLocked() {
+        mInnerFields.mWallpaperMayChange = false;
+        boolean targetChanged = false;
+
+        // TODO(multidisplay): Wallpapers on main screen only.
+        final DisplayInfo displayInfo = getDefaultDisplayContentLocked().getDisplayInfo();
+        final int dw = displayInfo.logicalWidth;
+        final int dh = displayInfo.logicalHeight;
+
+        // First find top-most window that has asked to be on top of the
+        // wallpaper; all wallpapers go behind it.
+        final WindowList windows = getDefaultWindowListLocked();
+        int N = windows.size();
+        WindowState w = null;
+        WindowState foundW = null;
+        int foundI = 0;
+        WindowState topCurW = null;
+        int topCurI = 0;
+        int windowDetachedI = -1;
+        int i = N;
+        while (i > 0) {
+            i--;
+            w = windows.get(i);
+            if ((w.mAttrs.type == TYPE_WALLPAPER)) {
+                if (topCurW == null) {
+                    topCurW = w;
+                    topCurI = i;
+                }
+                continue;
+            }
+            topCurW = null;
+            if (w != mAnimator.mWindowDetachedWallpaper && w.mAppToken != null) {
+                // If this window's app token is hidden and not animating,
+                // it is of no interest to us.
+                if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) {
+                    if (DEBUG_WALLPAPER) Slog.v(TAG,
+                            "Skipping hidden and not animating token: " + w);
+                    continue;
+                }
+            }
+            if (DEBUG_WALLPAPER) Slog.v(TAG, "Win #" + i + " " + w + ": isOnScreen="
+                    + w.isOnScreen() + " mDrawState=" + w.mWinAnimator.mDrawState);
+            if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isOnScreen()
+                    && (mWallpaperTarget == w || w.isDrawFinishedLw())) {
+                if (DEBUG_WALLPAPER) Slog.v(TAG,
+                        "Found wallpaper target: #" + i + "=" + w);
+                foundW = w;
+                foundI = i;
+                if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) {
+                    // The current wallpaper target is animating, so we'll
+                    // look behind it for another possible target and figure
+                    // out what is going on below.
+                    if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
+                            + ": token animating, looking behind.");
+                    continue;
+                }
+                break;
+            } else if (w == mAnimator.mWindowDetachedWallpaper) {
+                windowDetachedI = i;
+            }
+        }
+
+        if (foundW == null && windowDetachedI >= 0) {
+            if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
+                    "Found animating detached wallpaper activity: #" + i + "=" + w);
+            foundW = w;
+            foundI = windowDetachedI;
+        }
+
+        if (mWallpaperTarget != foundW
+                && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != foundW)) {
+            if (DEBUG_WALLPAPER_LIGHT) {
+                Slog.v(TAG, "New wallpaper target: " + foundW
+                        + " oldTarget: " + mWallpaperTarget);
+            }
+
+            mLowerWallpaperTarget = null;
+            mUpperWallpaperTarget = null;
+
+            WindowState oldW = mWallpaperTarget;
+            mWallpaperTarget = foundW;
+            targetChanged = true;
+
+            // Now what is happening...  if the current and new targets are
+            // animating, then we are in our super special mode!
+            if (foundW != null && oldW != null) {
+                boolean oldAnim = oldW.isAnimatingLw();
+                boolean foundAnim = foundW.isAnimatingLw();
+                if (DEBUG_WALLPAPER_LIGHT) {
+                    Slog.v(TAG, "New animation: " + foundAnim
+                            + " old animation: " + oldAnim);
+                }
+                if (foundAnim && oldAnim) {
+                    int oldI = windows.indexOf(oldW);
+                    if (DEBUG_WALLPAPER_LIGHT) {
+                        Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
+                    }
+                    if (oldI >= 0) {
+                        if (DEBUG_WALLPAPER_LIGHT) {
+                            Slog.v(TAG, "Animating wallpapers: old#" + oldI
+                                    + "=" + oldW + "; new#" + foundI
+                                    + "=" + foundW);
+                        }
+
+                        // Set the new target correctly.
+                        if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
+                            if (DEBUG_WALLPAPER_LIGHT) {
+                                Slog.v(TAG, "Old wallpaper still the target.");
+                            }
+                            mWallpaperTarget = oldW;
+                            foundW = oldW;
+                            foundI = oldI;
+                        }
+                        // Now set the upper and lower wallpaper targets
+                        // correctly, and make sure that we are positioning
+                        // the wallpaper below the lower.
+                        else if (foundI > oldI) {
+                            // The new target is on top of the old one.
+                            if (DEBUG_WALLPAPER_LIGHT) {
+                                Slog.v(TAG, "Found target above old target.");
+                            }
+                            mUpperWallpaperTarget = foundW;
+                            mLowerWallpaperTarget = oldW;
+                            foundW = oldW;
+                            foundI = oldI;
+                        } else {
+                            // The new target is below the old one.
+                            if (DEBUG_WALLPAPER_LIGHT) {
+                                Slog.v(TAG, "Found target below old target.");
+                            }
+                            mUpperWallpaperTarget = oldW;
+                            mLowerWallpaperTarget = foundW;
+                        }
+                    }
+                }
+            }
+
+        } else if (mLowerWallpaperTarget != null) {
+            // Is it time to stop animating?
+            if (!mLowerWallpaperTarget.isAnimatingLw() || !mUpperWallpaperTarget.isAnimatingLw()) {
+                if (DEBUG_WALLPAPER_LIGHT) {
+                    Slog.v(TAG, "No longer animating wallpaper targets!");
+                }
+                mLowerWallpaperTarget = null;
+                mUpperWallpaperTarget = null;
+                mWallpaperTarget = foundW;
+                targetChanged = true;
+            }
+        }
+
+        boolean visible = foundW != null;
+        if (visible) {
+            // The window is visible to the compositor...  but is it visible
+            // to the user?  That is what the wallpaper cares about.
+            visible = isWallpaperVisible(foundW);
+            if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
+
+            // If the wallpaper target is animating, we may need to copy
+            // its layer adjustment.  Only do this if we are not transfering
+            // between two wallpaper targets.
+            mWallpaperAnimLayerAdjustment =
+                    (mLowerWallpaperTarget == null && foundW.mAppToken != null)
+                    ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0;
+
+            final int maxLayer = mPolicy.getMaxWallpaperLayer()
+                    * TYPE_LAYER_MULTIPLIER
+                    + TYPE_LAYER_OFFSET;
+
+            // Now w is the window we are supposed to be behind...  but we
+            // need to be sure to also be behind any of its attached windows,
+            // AND any starting window associated with it, AND below the
+            // maximum layer the policy allows for wallpapers.
+            while (foundI > 0) {
+                WindowState wb = windows.get(foundI-1);
+                if (wb.mBaseLayer < maxLayer &&
+                        wb.mAttachedWindow != foundW &&
+                        (foundW.mAttachedWindow == null ||
+                                wb.mAttachedWindow != foundW.mAttachedWindow) &&
+                        (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
+                                foundW.mToken == null || wb.mToken != foundW.mToken)) {
+                    // This window is not related to the previous one in any
+                    // interesting way, so stop here.
+                    break;
+                }
+                foundW = wb;
+                foundI--;
+            }
+        } else {
+            if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
+        }
+
+        if (foundW == null && topCurW != null) {
+            // There is no wallpaper target, so it goes at the bottom.
+            // We will assume it is the same place as last time, if known.
+            foundW = topCurW;
+            foundI = topCurI+1;
+        } else {
+            // Okay i is the position immediately above the wallpaper.  Look at
+            // what is below it for later.
+            foundW = foundI > 0 ? windows.get(foundI-1) : null;
+        }
+
+        if (visible) {
+            if (mWallpaperTarget.mWallpaperX >= 0) {
+                mLastWallpaperX = mWallpaperTarget.mWallpaperX;
+                mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
+            }
+            if (mWallpaperTarget.mWallpaperY >= 0) {
+                mLastWallpaperY = mWallpaperTarget.mWallpaperY;
+                mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
+            }
+        }
+
+        // Start stepping backwards from here, ensuring that our wallpaper windows
+        // are correctly placed.
+        int changed = 0;
+        int curTokenIndex = mWallpaperTokens.size();
+        while (curTokenIndex > 0) {
+            curTokenIndex--;
+            WindowToken token = mWallpaperTokens.get(curTokenIndex);
+            if (token.hidden == visible) {
+                if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
+                        "Wallpaper token " + token + " hidden=" + !visible);
+                changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
+                token.hidden = !visible;
+                // Need to do a layout to ensure the wallpaper now has the
+                // correct size.
+                getDefaultDisplayContentLocked().layoutNeeded = true;
+            }
+
+            int curWallpaperIndex = token.windows.size();
+            while (curWallpaperIndex > 0) {
+                curWallpaperIndex--;
+                WindowState wallpaper = token.windows.get(curWallpaperIndex);
+
+                if (visible) {
+                    updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
+                }
+
+                // First, make sure the client has the current visibility
+                // state.
+                dispatchWallpaperVisibility(wallpaper, visible);
+
+                wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
+                if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win "
+                        + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer);
+
+                // First, if this window is at the current index, then all
+                // is well.
+                if (wallpaper == foundW) {
+                    foundI--;
+                    foundW = foundI > 0
+                            ? windows.get(foundI-1) : null;
+                    continue;
+                }
+
+                // The window didn't match...  the current wallpaper window,
+                // wherever it is, is in the wrong place, so make sure it is
+                // not in the list.
+                int oldIndex = windows.indexOf(wallpaper);
+                if (oldIndex >= 0) {
+                    if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
+                            + oldIndex + ": " + wallpaper);
+                    windows.remove(oldIndex);
+                    mWindowsChanged = true;
+                    if (oldIndex < foundI) {
+                        foundI--;
+                    }
+                }
+
+                // Now stick it in. For apps over wallpaper keep the wallpaper at the bottommost
+                // layer. For keyguard over wallpaper put the wallpaper under the keyguard.
+                int insertionIndex = 0;
+                if (visible && foundW != null) {
+                    final int type = foundW.mAttrs.type;
+                    if (type == TYPE_KEYGUARD || type == TYPE_KEYGUARD_SCRIM) {
+                        insertionIndex = windows.indexOf(foundW);
+                    }
+                }
+                if (DEBUG_WALLPAPER_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
+                    Slog.v(TAG, "Moving wallpaper " + wallpaper
+                            + " from " + oldIndex + " to " + insertionIndex);
+                }
+
+                windows.add(insertionIndex, wallpaper);
+                mWindowsChanged = true;
+                changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
+            }
+        }
+
+        /*
+        final TaskStack targetStack =
+                mWallpaperTarget == null ? null : mWallpaperTarget.getStack();
+        if ((changed & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0 &&
+                targetStack != null && !targetStack.isHomeStack()) {
+            // If the wallpaper target is not on the home stack then make sure that all windows
+            // from other non-home stacks are above the wallpaper.
+            for (i = foundI - 1; i >= 0; --i) {
+                WindowState win = windows.get(i);
+                if (!win.isVisibleLw()) {
+                    continue;
+                }
+                final TaskStack winStack = win.getStack();
+                if (winStack != null && !winStack.isHomeStack() && winStack != targetStack) {
+                    windows.remove(i);
+                    windows.add(foundI + 1, win);
+                }
+            }
+        }
+        */
+
+        if (targetChanged && DEBUG_WALLPAPER_LIGHT) {
+            Slog.d(TAG, "New wallpaper: target=" + mWallpaperTarget
+                    + " lower=" + mLowerWallpaperTarget + " upper="
+                    + mUpperWallpaperTarget);
+        }
+
+        return changed;
+    }
+
+    void setWallpaperAnimLayerAdjustmentLocked(int adj) {
+        if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
+                "Setting wallpaper layer adj to " + adj);
+        mWallpaperAnimLayerAdjustment = adj;
+        int curTokenIndex = mWallpaperTokens.size();
+        while (curTokenIndex > 0) {
+            curTokenIndex--;
+            WindowToken token = mWallpaperTokens.get(curTokenIndex);
+            int curWallpaperIndex = token.windows.size();
+            while (curWallpaperIndex > 0) {
+                curWallpaperIndex--;
+                WindowState wallpaper = token.windows.get(curWallpaperIndex);
+                wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + adj;
+                if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "setWallpaper win "
+                        + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer);
+            }
+        }
+    }
+
+    boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
+            boolean sync) {
+        boolean changed = false;
+        boolean rawChanged = false;
+        float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
+        float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
+        int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
+        int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
+        changed = wallpaperWin.mXOffset != offset;
+        if (changed) {
+            if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
+                    + wallpaperWin + " x: " + offset);
+            wallpaperWin.mXOffset = offset;
+        }
+        if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
+            wallpaperWin.mWallpaperX = wpx;
+            wallpaperWin.mWallpaperXStep = wpxs;
+            rawChanged = true;
+        }
+
+        float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
+        float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
+        int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
+        offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
+        if (wallpaperWin.mYOffset != offset) {
+            if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
+                    + wallpaperWin + " y: " + offset);
+            changed = true;
+            wallpaperWin.mYOffset = offset;
+        }
+        if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
+            wallpaperWin.mWallpaperY = wpy;
+            wallpaperWin.mWallpaperYStep = wpys;
+            rawChanged = true;
+        }
+
+        if (rawChanged && (wallpaperWin.mAttrs.privateFlags &
+                    WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) {
+            try {
+                if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
+                        + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
+                        + " y=" + wallpaperWin.mWallpaperY);
+                if (sync) {
+                    mWaitingOnWallpaper = wallpaperWin;
+                }
+                wallpaperWin.mClient.dispatchWallpaperOffsets(
+                        wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
+                        wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
+                if (sync) {
+                    if (mWaitingOnWallpaper != null) {
+                        long start = SystemClock.uptimeMillis();
+                        if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
+                                < start) {
+                            try {
+                                if (DEBUG_WALLPAPER) Slog.v(TAG,
+                                        "Waiting for offset complete...");
+                                mWindowMap.wait(WALLPAPER_TIMEOUT);
+                            } catch (InterruptedException e) {
+                            }
+                            if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
+                            if ((start+WALLPAPER_TIMEOUT)
+                                    < SystemClock.uptimeMillis()) {
+                                Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
+                                        + wallpaperWin);
+                                mLastWallpaperTimeoutTime = start;
+                            }
+                        }
+                        mWaitingOnWallpaper = null;
+                    }
+                }
+            } catch (RemoteException e) {
+            }
+        }
+
+        return changed;
+    }
+
+    void wallpaperOffsetsComplete(IBinder window) {
+        synchronized (mWindowMap) {
+            if (mWaitingOnWallpaper != null &&
+                    mWaitingOnWallpaper.mClient.asBinder() == window) {
+                mWaitingOnWallpaper = null;
+                mWindowMap.notifyAll();
+            }
+        }
+    }
+
+    void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
+        final DisplayContent displayContent = changingTarget.getDisplayContent();
+        if (displayContent == null) {
+            return;
+        }
+        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        final int dw = displayInfo.logicalWidth;
+        final int dh = displayInfo.logicalHeight;
+
+        WindowState target = mWallpaperTarget;
+        if (target != null) {
+            if (target.mWallpaperX >= 0) {
+                mLastWallpaperX = target.mWallpaperX;
+            } else if (changingTarget.mWallpaperX >= 0) {
+                mLastWallpaperX = changingTarget.mWallpaperX;
+            }
+            if (target.mWallpaperY >= 0) {
+                mLastWallpaperY = target.mWallpaperY;
+            } else if (changingTarget.mWallpaperY >= 0) {
+                mLastWallpaperY = changingTarget.mWallpaperY;
+            }
+        }
+
+        int curTokenIndex = mWallpaperTokens.size();
+        while (curTokenIndex > 0) {
+            curTokenIndex--;
+            WindowToken token = mWallpaperTokens.get(curTokenIndex);
+            int curWallpaperIndex = token.windows.size();
+            while (curWallpaperIndex > 0) {
+                curWallpaperIndex--;
+                WindowState wallpaper = token.windows.get(curWallpaperIndex);
+                if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
+                    WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
+                    winAnimator.computeShownFrameLocked();
+                    // No need to lay out the windows - we can just set the wallpaper position
+                    // directly.
+                    winAnimator.setWallpaperOffset(wallpaper.mShownFrame);
+                    // We only want to be synchronous with one wallpaper.
+                    sync = false;
+                }
+            }
+        }
+    }
+
+    /**
+     * Check wallpaper for visiblity change and notify window if so.
+     * @param wallpaper The wallpaper to test and notify.
+     * @param visible Current visibility.
+     */
+    void dispatchWallpaperVisibility(final WindowState wallpaper, final boolean visible) {
+        if (wallpaper.mWallpaperVisible != visible) {
+            wallpaper.mWallpaperVisible = visible;
+            try {
+                if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
+                        "Updating vis of wallpaper " + wallpaper
+                        + ": " + visible + " from:\n" + Debug.getCallers(4, "  "));
+                wallpaper.mClient.dispatchAppVisibility(visible);
+            } catch (RemoteException e) {
+            }
+        }
+    }
+
+    void updateWallpaperVisibilityLocked() {
+        final boolean visible = isWallpaperVisible(mWallpaperTarget);
+        final DisplayContent displayContent = mWallpaperTarget.getDisplayContent();
+        if (displayContent == null) {
+            return;
+        }
+        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        final int dw = displayInfo.logicalWidth;
+        final int dh = displayInfo.logicalHeight;
+
+        int curTokenIndex = mWallpaperTokens.size();
+        while (curTokenIndex > 0) {
+            curTokenIndex--;
+            WindowToken token = mWallpaperTokens.get(curTokenIndex);
+            if (token.hidden == visible) {
+                token.hidden = !visible;
+                // Need to do a layout to ensure the wallpaper now has the
+                // correct size.
+                getDefaultDisplayContentLocked().layoutNeeded = true;
+            }
+
+            int curWallpaperIndex = token.windows.size();
+            while (curWallpaperIndex > 0) {
+                curWallpaperIndex--;
+                WindowState wallpaper = token.windows.get(curWallpaperIndex);
+                if (visible) {
+                    updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
+                }
+
+                dispatchWallpaperVisibility(wallpaper, visible);
+            }
+        }
+    }
+
+    public int addWindow(Session session, IWindow client, int seq,
+            WindowManager.LayoutParams attrs, int viewVisibility, int displayId,
+            Rect outContentInsets, InputChannel outInputChannel) {
+        int[] appOp = new int[1];
+        int res = mPolicy.checkAddPermission(attrs, appOp);
+        if (res != WindowManagerGlobal.ADD_OKAY) {
+            return res;
+        }
+
+        boolean reportNewConfig = false;
+        WindowState attachedWindow = null;
+        WindowState win = null;
+        long origId;
+        final int type = attrs.type;
+
+        synchronized(mWindowMap) {
+            if (!mDisplayReady) {
+                throw new IllegalStateException("Display has not been initialialized");
+            }
+
+            final DisplayContent displayContent = getDisplayContentLocked(displayId);
+            if (displayContent == null) {
+                Slog.w(TAG, "Attempted to add window to a display that does not exist: "
+                        + displayId + ".  Aborting.");
+                return WindowManagerGlobal.ADD_INVALID_DISPLAY;
+            }
+            if (!displayContent.hasAccess(session.mUid)) {
+                Slog.w(TAG, "Attempted to add window to a display for which the application "
+                        + "does not have access: " + displayId + ".  Aborting.");
+                return WindowManagerGlobal.ADD_INVALID_DISPLAY;
+            }
+
+            if (mWindowMap.containsKey(client.asBinder())) {
+                Slog.w(TAG, "Window " + client + " is already added");
+                return WindowManagerGlobal.ADD_DUPLICATE_ADD;
+            }
+
+            if (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) {
+                attachedWindow = windowForClientLocked(null, attrs.token, false);
+                if (attachedWindow == null) {
+                    Slog.w(TAG, "Attempted to add window with token that is not a window: "
+                          + attrs.token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN;
+                }
+                if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
+                        && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
+                    Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
+                            + attrs.token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN;
+                }
+            }
+
+            if (type == TYPE_PRIVATE_PRESENTATION && !displayContent.isPrivate()) {
+                Slog.w(TAG, "Attempted to add private presentation window to a non-private display.  Aborting.");
+                return WindowManagerGlobal.ADD_PERMISSION_DENIED;
+            }
+
+            boolean addToken = false;
+            WindowToken token = mTokenMap.get(attrs.token);
+            if (token == null) {
+                if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
+                    Slog.w(TAG, "Attempted to add application window with unknown token "
+                          + attrs.token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+                if (type == TYPE_INPUT_METHOD) {
+                    Slog.w(TAG, "Attempted to add input method window with unknown token "
+                          + attrs.token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+                if (type == TYPE_WALLPAPER) {
+                    Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
+                          + attrs.token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+                if (type == TYPE_DREAM) {
+                    Slog.w(TAG, "Attempted to add Dream window with unknown token "
+                          + attrs.token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+                token = new WindowToken(this, attrs.token, -1, false);
+                addToken = true;
+            } else if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
+                AppWindowToken atoken = token.appWindowToken;
+                if (atoken == null) {
+                    Slog.w(TAG, "Attempted to add window with non-application token "
+                          + token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_NOT_APP_TOKEN;
+                } else if (atoken.removed) {
+                    Slog.w(TAG, "Attempted to add window with exiting application token "
+                          + token + ".  Aborting.");
+                    return WindowManagerGlobal.ADD_APP_EXITING;
+                }
+                if (type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
+                    // No need for this guy!
+                    if (localLOGV) Slog.v(
+                            TAG, "**** NO NEED TO START: " + attrs.getTitle());
+                    return WindowManagerGlobal.ADD_STARTING_NOT_NEEDED;
+                }
+            } else if (type == TYPE_INPUT_METHOD) {
+                if (token.windowType != TYPE_INPUT_METHOD) {
+                    Slog.w(TAG, "Attempted to add input method window with bad token "
+                            + attrs.token + ".  Aborting.");
+                      return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+            } else if (type == TYPE_WALLPAPER) {
+                if (token.windowType != TYPE_WALLPAPER) {
+                    Slog.w(TAG, "Attempted to add wallpaper window with bad token "
+                            + attrs.token + ".  Aborting.");
+                      return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+            } else if (type == TYPE_DREAM) {
+                if (token.windowType != TYPE_DREAM) {
+                    Slog.w(TAG, "Attempted to add Dream window with bad token "
+                            + attrs.token + ".  Aborting.");
+                      return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
+                }
+            }
+
+            win = new WindowState(this, session, client, token,
+                    attachedWindow, appOp[0], seq, attrs, viewVisibility, displayContent);
+            if (win.mDeathRecipient == null) {
+                // Client has apparently died, so there is no reason to
+                // continue.
+                Slog.w(TAG, "Adding window client " + client.asBinder()
+                        + " that is dead, aborting.");
+                return WindowManagerGlobal.ADD_APP_EXITING;
+            }
+
+            mPolicy.adjustWindowParamsLw(win.mAttrs);
+            win.setShowToOwnerOnlyLocked(mPolicy.checkShowToOwnerOnly(attrs));
+
+            res = mPolicy.prepareAddWindowLw(win, attrs);
+            if (res != WindowManagerGlobal.ADD_OKAY) {
+                return res;
+            }
+
+            if (outInputChannel != null && (attrs.inputFeatures
+                    & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) {
+                String name = win.makeInputChannelName();
+                InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
+                win.setInputChannel(inputChannels[0]);
+                inputChannels[1].transferTo(outInputChannel);
+
+                mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
+            }
+
+            // From now on, no exceptions or errors allowed!
+
+            res = WindowManagerGlobal.ADD_OKAY;
+
+            origId = Binder.clearCallingIdentity();
+
+            if (addToken) {
+                mTokenMap.put(attrs.token, token);
+            }
+            win.attach();
+            mWindowMap.put(client.asBinder(), win);
+            if (win.mAppOp != AppOpsManager.OP_NONE) {
+                if (mAppOps.startOpNoThrow(win.mAppOp, win.getOwningUid(), win.getOwningPackage())
+                        != AppOpsManager.MODE_ALLOWED) {
+                    win.setAppOpVisibilityLw(false);
+                }
+            }
+
+            if (type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
+                token.appWindowToken.startingWindow = win;
+                if (DEBUG_STARTING_WINDOW) Slog.v (TAG, "addWindow: " + token.appWindowToken
+                        + " startingWindow=" + win);
+                Message m = mH.obtainMessage(H.REMOVE_STARTING_TIMEOUT, token.appWindowToken);
+                mH.sendMessageDelayed(m, STARTING_WINDOW_TIMEOUT_DURATION);
+            }
+
+            boolean imMayMove = true;
+
+            if (type == TYPE_INPUT_METHOD) {
+                win.mGivenInsetsPending = true;
+                mInputMethodWindow = win;
+                addInputMethodWindowToListLocked(win);
+                imMayMove = false;
+            } else if (type == TYPE_INPUT_METHOD_DIALOG) {
+                mInputMethodDialogs.add(win);
+                addWindowToListInOrderLocked(win, true);
+                moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
+                imMayMove = false;
+            } else {
+                addWindowToListInOrderLocked(win, true);
+                if (type == TYPE_WALLPAPER) {
+                    mLastWallpaperTimeoutTime = 0;
+                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
+                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                } else if (mWallpaperTarget != null
+                        && mWallpaperTarget.mLayer >= win.mBaseLayer) {
+                    // If there is currently a wallpaper being shown, and
+                    // the base layer of the new window is below the current
+                    // layer of the target window, then adjust the wallpaper.
+                    // This is to avoid a new window being placed between the
+                    // wallpaper and its target.
+                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+                }
+            }
+
+            win.mWinAnimator.mEnterAnimationPending = true;
+
+            if (displayContent.isDefaultDisplay) {
+                mPolicy.getContentInsetHintLw(attrs, outContentInsets);
+            } else {
+                outContentInsets.setEmpty();
+            }
+
+            if (mInTouchMode) {
+                res |= WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE;
+            }
+            if (win.mAppToken == null || !win.mAppToken.clientHidden) {
+                res |= WindowManagerGlobal.ADD_FLAG_APP_VISIBLE;
+            }
+
+            mInputMonitor.setUpdateInputWindowsNeededLw();
+
+            boolean focusChanged = false;
+            if (win.canReceiveKeys()) {
+                focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
+                        false /*updateInputWindows*/);
+                if (focusChanged) {
+                    imMayMove = false;
+                }
+            }
+
+            if (imMayMove) {
+                moveInputMethodWindowsIfNeededLocked(false);
+            }
+
+            assignLayersLocked(displayContent.getWindowList());
+            // Don't do layout here, the window must call
+            // relayout to be displayed, so we'll do it there.
+
+            if (focusChanged) {
+                finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
+            }
+            mInputMonitor.updateInputWindowsLw(false /*force*/);
+
+            if (localLOGV) Slog.v(
+                TAG, "New client " + client.asBinder()
+                + ": window=" + win);
+
+            if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
+                reportNewConfig = true;
+            }
+        }
+
+        if (reportNewConfig) {
+            sendNewConfiguration();
+        }
+
+        Binder.restoreCallingIdentity(origId);
+
+        return res;
+    }
+
+    public void removeWindow(Session session, IWindow client) {
+        synchronized(mWindowMap) {
+            WindowState win = windowForClientLocked(session, client, false);
+            if (win == null) {
+                return;
+            }
+            removeWindowLocked(session, win);
+        }
+    }
+
+    public void removeWindowLocked(Session session, WindowState win) {
+        if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
+            if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "Starting window removed " + win);
+            removeStartingWindowTimeout(win.mAppToken);
+        }
+
+        if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && win==mCurrentFocus) Slog.v(
+                TAG, "Remove " + win + " client="
+                + Integer.toHexString(System.identityHashCode(win.mClient.asBinder()))
+                + ", surface=" + win.mWinAnimator.mSurfaceControl + " Callers="
+                + Debug.getCallers(4));
+
+        final long origId = Binder.clearCallingIdentity();
+
+        win.disposeInputChannel();
+
+        if (DEBUG_APP_TRANSITIONS) Slog.v(
+                TAG, "Remove " + win + ": mSurface=" + win.mWinAnimator.mSurfaceControl
+                + " mExiting=" + win.mExiting
+                + " isAnimating=" + win.mWinAnimator.isAnimating()
+                + " app-animation="
+                + (win.mAppToken != null ? win.mAppToken.mAppAnimator.animation : null)
+                + " inPendingTransaction="
+                + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
+                + " mDisplayFrozen=" + mDisplayFrozen);
+        // Visibility of the removed window. Will be used later to update orientation later on.
+        boolean wasVisible = false;
+        // First, see if we need to run an animation.  If we do, we have
+        // to hold off on removing the window until the animation is done.
+        // If the display is frozen, just remove immediately, since the
+        // animation wouldn't be seen.
+        if (win.mHasSurface && okToDisplay()) {
+            // If we are not currently running the exit animation, we
+            // need to see about starting one.
+            wasVisible = win.isWinVisibleLw();
+            if (wasVisible) {
+
+                int transit = WindowManagerPolicy.TRANSIT_EXIT;
+                if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
+                    transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
+                }
+                // Try starting an animation.
+                if (win.mWinAnimator.applyAnimationLocked(transit, false)) {
+                    win.mExiting = true;
+                }
+                //TODO (multidisplay): Magnification is supported only for the default display.
+                if (mDisplayMagnifier != null
+                        && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                    mDisplayMagnifier.onWindowTransitionLocked(win, transit);
+                }
+            }
+            if (win.mExiting || win.mWinAnimator.isAnimating()) {
+                // The exit animation is running... wait for it!
+                //Slog.i(TAG, "*** Running exit animation...");
+                win.mExiting = true;
+                win.mRemoveOnExit = true;
+                final DisplayContent displayContent = win.getDisplayContent();
+                if (displayContent != null) {
+                    displayContent.layoutNeeded = true;
+                }
+                updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                        false /*updateInputWindows*/);
+                performLayoutAndPlaceSurfacesLocked();
+                if (win.mAppToken != null) {
+                    win.mAppToken.updateReportedVisibilityLocked();
+                }
+                //dump();
+                Binder.restoreCallingIdentity(origId);
+                return;
+            }
+        }
+
+        removeWindowInnerLocked(session, win);
+        // Removing a visible window will effect the computed orientation
+        // So just update orientation if needed.
+        if (wasVisible && updateOrientationFromAppTokensLocked(false)) {
+            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+        }
+        updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    private void removeWindowInnerLocked(Session session, WindowState win) {
+        if (win.mRemoved) {
+            // Nothing to do.
+            return;
+        }
+
+        for (int i=win.mChildWindows.size()-1; i>=0; i--) {
+            WindowState cwin = win.mChildWindows.get(i);
+            Slog.w(TAG, "Force-removing child win " + cwin + " from container "
+                    + win);
+            removeWindowInnerLocked(cwin.mSession, cwin);
+        }
+
+        win.mRemoved = true;
+
+        if (mInputMethodTarget == win) {
+            moveInputMethodWindowsIfNeededLocked(false);
+        }
+
+        if (false) {
+            RuntimeException e = new RuntimeException("here");
+            e.fillInStackTrace();
+            Slog.w(TAG, "Removing window " + win, e);
+        }
+
+        mPolicy.removeWindowLw(win);
+        win.removeLocked();
+
+        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
+        mWindowMap.remove(win.mClient.asBinder());
+        if (win.mAppOp != AppOpsManager.OP_NONE) {
+            mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage());
+        }
+
+        mPendingRemove.remove(win);
+        mResizingWindows.remove(win);
+        mWindowsChanged = true;
+        if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
+
+        if (mInputMethodWindow == win) {
+            mInputMethodWindow = null;
+        } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
+            mInputMethodDialogs.remove(win);
+        }
+
+        final WindowToken token = win.mToken;
+        final AppWindowToken atoken = win.mAppToken;
+        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
+        token.windows.remove(win);
+        if (atoken != null) {
+            atoken.allAppWindows.remove(win);
+        }
+        if (localLOGV) Slog.v(
+                TAG, "**** Removing window " + win + ": count="
+                + token.windows.size());
+        if (token.windows.size() == 0) {
+            if (!token.explicit) {
+                mTokenMap.remove(token.token);
+            } else if (atoken != null) {
+                atoken.firstWindowDrawn = false;
+            }
+        }
+
+        if (atoken != null) {
+            if (atoken.startingWindow == win) {
+                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling startingWindow " + win);
+                removeStartingWindowTimeout(atoken);
+                atoken.startingWindow = null;
+            } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
+                // If this is the last window and we had requested a starting
+                // transition window, well there is no point now.
+                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling last startingWindow");
+                atoken.startingData = null;
+            } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
+                // If this is the last window except for a starting transition
+                // window, we need to get rid of the starting transition.
+                scheduleRemoveStartingWindow(atoken);
+            }
+        }
+
+        if (win.mAttrs.type == TYPE_WALLPAPER) {
+            mLastWallpaperTimeoutTime = 0;
+            getDefaultDisplayContentLocked().pendingLayoutChanges |=
+                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+        } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
+            getDefaultDisplayContentLocked().pendingLayoutChanges |=
+                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+        }
+
+        final WindowList windows = win.getWindowList();
+        if (windows != null) {
+            windows.remove(win);
+            if (!mInLayout) {
+                assignLayersLocked(windows);
+                final DisplayContent displayContent = win.getDisplayContent();
+                if (displayContent != null) {
+                    displayContent.layoutNeeded = true;
+                }
+                performLayoutAndPlaceSurfacesLocked();
+                if (win.mAppToken != null) {
+                    win.mAppToken.updateReportedVisibilityLocked();
+                }
+            }
+        }
+
+        mInputMonitor.updateInputWindowsLw(true /*force*/);
+    }
+
+    public void updateAppOpsState() {
+        synchronized(mWindowMap) {
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+                final int numWindows = windows.size();
+                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                    final WindowState win = windows.get(winNdx);
+                    if (win.mAppOp != AppOpsManager.OP_NONE) {
+                        final int mode = mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(),
+                                win.getOwningPackage());
+                        win.setAppOpVisibilityLw(mode == AppOpsManager.MODE_ALLOWED);
+                    }
+                }
+            }
+        }
+    }
+
+    static void logSurface(WindowState w, String msg, RuntimeException where) {
+        String str = "  SURFACE " + msg + ": " + w;
+        if (where != null) {
+            Slog.i(TAG, str, where);
+        } else {
+            Slog.i(TAG, str);
+        }
+    }
+
+    static void logSurface(SurfaceControl s, String title, String msg, RuntimeException where) {
+        String str = "  SURFACE " + s + ": " + msg + " / " + title;
+        if (where != null) {
+            Slog.i(TAG, str, where);
+        } else {
+            Slog.i(TAG, str);
+        }
+    }
+
+    void setTransparentRegionWindow(Session session, IWindow client, Region region) {
+        long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (mWindowMap) {
+                WindowState w = windowForClientLocked(session, client, false);
+                if ((w != null) && w.mHasSurface) {
+                    w.mWinAnimator.setTransparentRegionHintLocked(region);
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    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 (w != null) {
+                    w.mGivenInsetsPending = false;
+                    w.mGivenContentInsets.set(contentInsets);
+                    w.mGivenVisibleInsets.set(visibleInsets);
+                    w.mGivenTouchableRegion.set(touchableRegion);
+                    w.mTouchableInsets = touchableInsets;
+                    if (w.mGlobalScale != 1) {
+                        w.mGivenContentInsets.scale(w.mGlobalScale);
+                        w.mGivenVisibleInsets.scale(w.mGlobalScale);
+                        w.mGivenTouchableRegion.scale(w.mGlobalScale);
+                    }
+                    final DisplayContent displayContent = w.getDisplayContent();
+                    if (displayContent != null) {
+                        displayContent.layoutNeeded = true;
+                    }
+                    performLayoutAndPlaceSurfacesLocked();
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    public void getWindowDisplayFrame(Session session, IWindow client,
+            Rect outDisplayFrame) {
+        synchronized(mWindowMap) {
+            WindowState win = windowForClientLocked(session, client, false);
+            if (win == null) {
+                outDisplayFrame.setEmpty();
+                return;
+            }
+            outDisplayFrame.set(win.mDisplayFrame);
+        }
+    }
+
+    public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
+            float xStep, float yStep) {
+        if (window.mWallpaperX != x || window.mWallpaperY != y)  {
+            window.mWallpaperX = x;
+            window.mWallpaperY = y;
+            window.mWallpaperXStep = xStep;
+            window.mWallpaperYStep = yStep;
+            updateWallpaperOffsetLocked(window, true);
+        }
+    }
+
+    void wallpaperCommandComplete(IBinder window, Bundle result) {
+        synchronized (mWindowMap) {
+            if (mWaitingOnWallpaper != null &&
+                    mWaitingOnWallpaper.mClient.asBinder() == window) {
+                mWaitingOnWallpaper = null;
+                mWindowMap.notifyAll();
+            }
+        }
+    }
+
+    public Bundle sendWindowWallpaperCommandLocked(WindowState window,
+            String action, int x, int y, int z, Bundle extras, boolean sync) {
+        if (window == mWallpaperTarget || window == mLowerWallpaperTarget
+                || window == mUpperWallpaperTarget) {
+            boolean doWait = sync;
+            int curTokenIndex = mWallpaperTokens.size();
+            while (curTokenIndex > 0) {
+                curTokenIndex--;
+                WindowToken token = mWallpaperTokens.get(curTokenIndex);
+                int curWallpaperIndex = token.windows.size();
+                while (curWallpaperIndex > 0) {
+                    curWallpaperIndex--;
+                    WindowState wallpaper = token.windows.get(curWallpaperIndex);
+                    try {
+                        wallpaper.mClient.dispatchWallpaperCommand(action,
+                                x, y, z, extras, sync);
+                        // We only want to be synchronous with one wallpaper.
+                        sync = false;
+                    } catch (RemoteException e) {
+                    }
+                }
+            }
+
+            if (doWait) {
+                // XXX Need to wait for result.
+            }
+        }
+
+        return null;
+    }
+
+    public void setUniverseTransformLocked(WindowState window, float alpha,
+            float offx, float offy, float dsdx, float dtdx, float dsdy, float dtdy) {
+        Transformation transform = window.mWinAnimator.mUniverseTransform;
+        transform.setAlpha(alpha);
+        Matrix matrix = transform.getMatrix();
+        matrix.getValues(mTmpFloats);
+        mTmpFloats[Matrix.MTRANS_X] = offx;
+        mTmpFloats[Matrix.MTRANS_Y] = offy;
+        mTmpFloats[Matrix.MSCALE_X] = dsdx;
+        mTmpFloats[Matrix.MSKEW_Y] = dtdx;
+        mTmpFloats[Matrix.MSKEW_X] = dsdy;
+        mTmpFloats[Matrix.MSCALE_Y] = dtdy;
+        matrix.setValues(mTmpFloats);
+        final DisplayContent displayContent = window.getDisplayContent();
+        if (displayContent == null) {
+            return;
+        }
+
+        final DisplayInfo displayInfo = window.getDisplayContent().getDisplayInfo();
+        final RectF dispRect = new RectF(0, 0,
+                displayInfo.logicalWidth, displayInfo.logicalHeight);
+        matrix.mapRect(dispRect);
+        window.mGivenTouchableRegion.set(0, 0,
+                displayInfo.logicalWidth, displayInfo.logicalHeight);
+        window.mGivenTouchableRegion.op((int)dispRect.left, (int)dispRect.top,
+                (int)dispRect.right, (int)dispRect.bottom, Region.Op.DIFFERENCE);
+        window.mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
+        displayContent.layoutNeeded = true;
+        performLayoutAndPlaceSurfacesLocked();
+    }
+
+    public void onRectangleOnScreenRequested(IBinder token, Rect rectangle, boolean immediate) {
+        synchronized (mWindowMap) {
+            if (mDisplayMagnifier != null) {
+                WindowState window = mWindowMap.get(token);
+                //TODO (multidisplay): Magnification is supported only for the default display.
+                if (window != null && window.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                    mDisplayMagnifier.onRectangleOnScreenRequestedLocked(rectangle, immediate);
+                }
+            }
+        }
+    }
+
+    public IWindowId getWindowId(IBinder token) {
+        synchronized (mWindowMap) {
+            WindowState window = mWindowMap.get(token);
+            return window != null ? window.mWindowId : null;
+        }
+    }
+
+    public int relayoutWindow(Session session, IWindow client, int seq,
+            WindowManager.LayoutParams attrs, int requestedWidth,
+            int requestedHeight, int viewVisibility, int flags,
+            Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
+            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
+        boolean toBeDisplayed = false;
+        boolean inTouchMode;
+        boolean configChanged;
+        boolean surfaceChanged = false;
+        boolean animating;
+
+        // if they don't have this permission, mask out the status bar bits
+        int systemUiVisibility = 0;
+        if (attrs != null) {
+            systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
+            if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) {
+                if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
+                        != PackageManager.PERMISSION_GRANTED) {
+                    systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
+                }
+            }
+        }
+        long origId = Binder.clearCallingIdentity();
+
+        synchronized(mWindowMap) {
+            WindowState win = windowForClientLocked(session, client, false);
+            if (win == null) {
+                return 0;
+            }
+            WindowStateAnimator winAnimator = win.mWinAnimator;
+            if (win.mRequestedWidth != requestedWidth
+                    || win.mRequestedHeight != requestedHeight) {
+                win.mLayoutNeeded = true;
+                win.mRequestedWidth = requestedWidth;
+                win.mRequestedHeight = requestedHeight;
+            }
+            if (attrs != null && seq == win.mSeq) {
+                win.mSystemUiVisibility = systemUiVisibility;
+            }
+
+            if (attrs != null) {
+                mPolicy.adjustWindowParamsLw(attrs);
+            }
+
+            winAnimator.mSurfaceDestroyDeferred =
+                    (flags&WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY) != 0;
+
+            int attrChanges = 0;
+            int flagChanges = 0;
+            if (attrs != null) {
+                if (win.mAttrs.type != attrs.type) {
+                    throw new IllegalArgumentException(
+                            "Window type can not be changed after the window is added.");
+                }
+                flagChanges = win.mAttrs.flags ^= attrs.flags;
+                attrChanges = win.mAttrs.copyFrom(attrs);
+                if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED
+                        | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) {
+                    win.mLayoutNeeded = true;
+                }
+            }
+
+            if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": viewVisibility=" + viewVisibility
+                    + " req=" + requestedWidth + "x" + requestedHeight + " " + win.mAttrs);
+
+            win.mEnforceSizeCompat =
+                    (win.mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
+
+            if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
+                winAnimator.mAlpha = attrs.alpha;
+            }
+
+            final boolean scaledWindow =
+                ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
+
+            if (scaledWindow) {
+                // requested{Width|Height} Surface's physical size
+                // attrs.{width|height} Size on screen
+                win.mHScale = (attrs.width  != requestedWidth)  ?
+                        (attrs.width  / (float)requestedWidth) : 1.0f;
+                win.mVScale = (attrs.height != requestedHeight) ?
+                        (attrs.height / (float)requestedHeight) : 1.0f;
+            } else {
+                win.mHScale = win.mVScale = 1;
+            }
+
+            boolean imMayMove = (flagChanges & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0;
+
+            final boolean isDefaultDisplay = win.isDefaultDisplay();
+            boolean focusMayChange = isDefaultDisplay && (win.mViewVisibility != viewVisibility
+                    || ((flagChanges & FLAG_NOT_FOCUSABLE) != 0)
+                    || (!win.mRelayoutCalled));
+
+            boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
+                    && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
+            wallpaperMayMove |= (flagChanges & FLAG_SHOW_WALLPAPER) != 0;
+
+            win.mRelayoutCalled = true;
+            final int oldVisibility = win.mViewVisibility;
+            win.mViewVisibility = viewVisibility;
+            if (DEBUG_SCREEN_ON) {
+                RuntimeException stack = new RuntimeException();
+                stack.fillInStackTrace();
+                Slog.i(TAG, "Relayout " + win + ": oldVis=" + oldVisibility
+                        + " newVis=" + viewVisibility, stack);
+            }
+            if (viewVisibility == View.VISIBLE &&
+                    (win.mAppToken == null || !win.mAppToken.clientHidden)) {
+                toBeDisplayed = !win.isVisibleLw();
+                if (win.mExiting) {
+                    winAnimator.cancelExitAnimationForNextAnimationLocked();
+                    win.mExiting = false;
+                }
+                if (win.mDestroying) {
+                    win.mDestroying = false;
+                    mDestroySurface.remove(win);
+                }
+                if (oldVisibility == View.GONE) {
+                    winAnimator.mEnterAnimationPending = true;
+                }
+                if (toBeDisplayed) {
+                    if (win.isDrawnLw() && okToDisplay()) {
+                        winAnimator.applyEnterAnimationLocked();
+                    }
+                    if ((win.mAttrs.flags
+                            & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
+                        if (DEBUG_VISIBILITY) Slog.v(TAG,
+                                "Relayout window turning screen on: " + win);
+                        win.mTurnOnScreen = true;
+                    }
+                    if (win.isConfigChanged()) {
+                        if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + win
+                                + " visible with new config: " + mCurConfiguration);
+                        outConfig.setTo(mCurConfiguration);
+                    }
+                }
+                if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
+                    // To change the format, we need to re-build the surface.
+                    winAnimator.destroySurfaceLocked();
+                    toBeDisplayed = true;
+                    surfaceChanged = true;
+                }
+                try {
+                    if (!win.mHasSurface) {
+                        surfaceChanged = true;
+                    }
+                    SurfaceControl surfaceControl = winAnimator.createSurfaceLocked();
+                    if (surfaceControl != null) {
+                        outSurface.copyFrom(surfaceControl);
+                        if (SHOW_TRANSACTIONS) Slog.i(TAG,
+                                "  OUT SURFACE " + outSurface + ": copied");
+                    } else {
+                        // For some reason there isn't a surface.  Clear the
+                        // caller's object so they see the same state.
+                        outSurface.release();
+                    }
+                } catch (Exception e) {
+                    mInputMonitor.updateInputWindowsLw(true /*force*/);
+
+                    Slog.w(TAG, "Exception thrown when creating surface for client "
+                             + client + " (" + win.mAttrs.getTitle() + ")",
+                             e);
+                    Binder.restoreCallingIdentity(origId);
+                    return 0;
+                }
+                if (toBeDisplayed) {
+                    focusMayChange = isDefaultDisplay;
+                }
+                if (win.mAttrs.type == TYPE_INPUT_METHOD
+                        && mInputMethodWindow == null) {
+                    mInputMethodWindow = win;
+                    imMayMove = true;
+                }
+                if (win.mAttrs.type == TYPE_BASE_APPLICATION
+                        && win.mAppToken != null
+                        && win.mAppToken.startingWindow != null) {
+                    // Special handling of starting window over the base
+                    // window of the app: propagate lock screen flags to it,
+                    // to provide the correct semantics while starting.
+                    final int mask =
+                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
+                        | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
+                    WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
+                    sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
+                }
+            } else {
+                winAnimator.mEnterAnimationPending = false;
+                if (winAnimator.mSurfaceControl != null) {
+                    if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
+                            + ": mExiting=" + win.mExiting);
+                    // If we are not currently running the exit animation, we
+                    // need to see about starting one.
+                    if (!win.mExiting) {
+                        surfaceChanged = true;
+                        // Try starting an animation; if there isn't one, we
+                        // can destroy the surface right away.
+                        int transit = WindowManagerPolicy.TRANSIT_EXIT;
+                        if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
+                            transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
+                        }
+                        if (win.isWinVisibleLw() &&
+                                winAnimator.applyAnimationLocked(transit, false)) {
+                            focusMayChange = isDefaultDisplay;
+                            win.mExiting = true;
+                        } else if (win.mWinAnimator.isAnimating()) {
+                            // Currently in a hide animation... turn this into
+                            // an exit.
+                            win.mExiting = true;
+                        } else if (win == mWallpaperTarget) {
+                            // If the wallpaper is currently behind this
+                            // window, we need to change both of them inside
+                            // of a transaction to avoid artifacts.
+                            win.mExiting = true;
+                            win.mWinAnimator.mAnimating = true;
+                        } else {
+                            if (mInputMethodWindow == win) {
+                                mInputMethodWindow = null;
+                            }
+                            winAnimator.destroySurfaceLocked();
+                        }
+                        //TODO (multidisplay): Magnification is supported only for the default
+                        if (mDisplayMagnifier != null
+                                && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                            mDisplayMagnifier.onWindowTransitionLocked(win, transit);
+                        }
+                    }
+                }
+
+                outSurface.release();
+                if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
+            }
+
+            if (focusMayChange) {
+                //System.out.println("Focus may change: " + win.mAttrs.getTitle());
+                if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                        false /*updateInputWindows*/)) {
+                    imMayMove = false;
+                }
+                //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
+            }
+
+            // updateFocusedWindowLocked() already assigned layers so we only need to
+            // reassign them at this point if the IM window state gets shuffled
+            if (imMayMove && (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed)) {
+                // Little hack here -- we -should- be able to rely on the
+                // function to return true if the IME has moved and needs
+                // its layer recomputed.  However, if the IME was hidden
+                // and isn't actually moved in the list, its layer may be
+                // out of data so we make sure to recompute it.
+                assignLayersLocked(win.getWindowList());
+            }
+
+            if (wallpaperMayMove) {
+                getDefaultDisplayContentLocked().pendingLayoutChanges |=
+                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+            }
+
+            final DisplayContent displayContent = win.getDisplayContent();
+            if (displayContent != null) {
+                displayContent.layoutNeeded = true;
+            }
+            win.mGivenInsetsPending = (flags&WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0;
+            configChanged = updateOrientationFromAppTokensLocked(false);
+            performLayoutAndPlaceSurfacesLocked();
+            if (toBeDisplayed && win.mIsWallpaper) {
+                DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
+                updateWallpaperOffsetLocked(win,
+                        displayInfo.logicalWidth, displayInfo.logicalHeight, false);
+            }
+            if (win.mAppToken != null) {
+                win.mAppToken.updateReportedVisibilityLocked();
+            }
+            outFrame.set(win.mCompatFrame);
+            outOverscanInsets.set(win.mOverscanInsets);
+            outContentInsets.set(win.mContentInsets);
+            outVisibleInsets.set(win.mVisibleInsets);
+            if (localLOGV) Slog.v(
+                TAG, "Relayout given client " + client.asBinder()
+                + ", requestedWidth=" + requestedWidth
+                + ", requestedHeight=" + requestedHeight
+                + ", viewVisibility=" + viewVisibility
+                + "\nRelayout returning frame=" + outFrame
+                + ", surface=" + outSurface);
+
+            if (localLOGV || DEBUG_FOCUS) Slog.v(
+                TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
+
+            inTouchMode = mInTouchMode;
+            animating = mAnimator.mAnimating && win.mWinAnimator.isAnimating();
+            if (animating && !mRelayoutWhileAnimating.contains(win)) {
+                mRelayoutWhileAnimating.add(win);
+            }
+
+            mInputMonitor.updateInputWindowsLw(true /*force*/);
+
+            if (DEBUG_LAYOUT) {
+                Slog.v(TAG, "Relayout complete " + win + ": outFrame=" + outFrame.toShortString());
+            }
+        }
+
+        if (configChanged) {
+            sendNewConfiguration();
+        }
+
+        Binder.restoreCallingIdentity(origId);
+
+        return (inTouchMode ? WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE : 0)
+                | (toBeDisplayed ? WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME : 0)
+                | (surfaceChanged ? WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED : 0)
+                | (animating ? WindowManagerGlobal.RELAYOUT_RES_ANIMATING : 0);
+    }
+
+    public void performDeferredDestroyWindow(Session session, IWindow client) {
+        long origId = Binder.clearCallingIdentity();
+
+        try {
+            synchronized (mWindowMap) {
+                WindowState win = windowForClientLocked(session, client, false);
+                if (win == null) {
+                    return;
+                }
+                win.mWinAnimator.destroyDeferredSurfaceLocked();
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    public boolean outOfMemoryWindow(Session session, IWindow client) {
+        long origId = Binder.clearCallingIdentity();
+
+        try {
+            synchronized (mWindowMap) {
+                WindowState win = windowForClientLocked(session, client, false);
+                if (win == null) {
+                    return false;
+                }
+                return reclaimSomeSurfaceMemoryLocked(win.mWinAnimator, "from-client", false);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    public void finishDrawingWindow(Session session, IWindow client) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (mWindowMap) {
+                WindowState win = windowForClientLocked(session, client, false);
+                if (win != null && win.mWinAnimator.finishDrawingLocked()) {
+                    if ((win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
+                        getDefaultDisplayContentLocked().pendingLayoutChanges |=
+                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+                    }
+                    final DisplayContent displayContent = win.getDisplayContent();
+                    if (displayContent != null) {
+                        displayContent.layoutNeeded = true;
+                    }
+                    requestTraversalLocked();
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public void getWindowFrame(IBinder token, Rect outBounds) {
+        if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO,
+                "getWindowInfo()")) {
+            throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission.");
+        }
+        synchronized (mWindowMap) {
+            WindowState windowState = mWindowMap.get(token);
+            if (windowState != null) {
+                outBounds.set(windowState.mFrame);
+            } else {
+                outBounds.setEmpty();
+            }
+        }
+    }
+
+    @Override
+    public void setMagnificationSpec(MagnificationSpec spec) {
+        if (!checkCallingPermission(android.Manifest.permission.MAGNIFY_DISPLAY,
+                "setMagnificationSpec()")) {
+            throw new SecurityException("Requires MAGNIFY_DISPLAY permission.");
+        }
+        synchronized (mWindowMap) {
+            if (mDisplayMagnifier != null) {
+                mDisplayMagnifier.setMagnificationSpecLocked(spec);
+            } else {
+                throw new IllegalStateException("Magnification callbacks not set!");
+            }
+        }
+        if (Binder.getCallingPid() != android.os.Process.myPid()) {
+            spec.recycle();
+        }
+    }
+
+    @Override
+    public MagnificationSpec getCompatibleMagnificationSpecForWindow(IBinder windowToken) {
+        if (!checkCallingPermission(android.Manifest.permission.MAGNIFY_DISPLAY,
+                "getCompatibleMagnificationSpecForWindow()")) {
+            throw new SecurityException("Requires MAGNIFY_DISPLAY permission.");
+        }
+        synchronized (mWindowMap) {
+            WindowState windowState = mWindowMap.get(windowToken);
+            if (windowState == null) {
+                return null;
+            }
+            MagnificationSpec spec = null;
+            if (mDisplayMagnifier != null) {
+                spec = mDisplayMagnifier.getMagnificationSpecForWindowLocked(windowState);
+            }
+            if ((spec == null || spec.isNop()) && windowState.mGlobalScale == 1.0f) {
+                return null;
+            }
+            spec = (spec == null) ? MagnificationSpec.obtain() : MagnificationSpec.obtain(spec);
+            spec.scale *= windowState.mGlobalScale;
+            return spec;
+        }
+    }
+
+    @Override
+    public void setMagnificationCallbacks(IMagnificationCallbacks callbacks) {
+        if (!checkCallingPermission(android.Manifest.permission.MAGNIFY_DISPLAY,
+                "setMagnificationCallbacks()")) {
+            throw new SecurityException("Requires MAGNIFY_DISPLAY permission.");
+        }
+        synchronized (mWindowMap) {
+            if (mDisplayMagnifier == null) {
+                mDisplayMagnifier = new DisplayMagnifier(this, callbacks);
+            } else {
+                if (callbacks == null) {
+                    if (mDisplayMagnifier != null) {
+                        mDisplayMagnifier.destroyLocked();
+                        mDisplayMagnifier = null;
+                    }
+                } else {
+                    throw new IllegalStateException("Magnification callbacks already set!");
+                }
+            }
+        }
+    }
+
+    private boolean applyAnimationLocked(AppWindowToken atoken,
+            WindowManager.LayoutParams lp, int transit, boolean enter) {
+        // Only apply an animation if the display isn't frozen.  If it is
+        // frozen, there is no reason to animate and it can cause strange
+        // artifacts when we unfreeze the display if some different animation
+        // is running.
+        if (okToDisplay()) {
+            DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
+            final int width = displayInfo.appWidth;
+            final int height = displayInfo.appHeight;
+            if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "applyAnimation: atoken="
+                    + atoken);
+            Animation a = mAppTransition.loadAnimation(lp, transit, enter, width, height);
+            if (a != null) {
+                if (DEBUG_ANIM) {
+                    RuntimeException e = null;
+                    if (!HIDE_STACK_CRAWLS) {
+                        e = new RuntimeException();
+                        e.fillInStackTrace();
+                    }
+                    Slog.v(TAG, "Loaded animation " + a + " for " + atoken, e);
+                }
+                atoken.mAppAnimator.setAnimation(a, width, height);
+            }
+        } else {
+            atoken.mAppAnimator.clearAnimation();
+        }
+
+        return atoken.mAppAnimator.animation != null;
+    }
+
+    // -------------------------------------------------------------
+    // Application Window Tokens
+    // -------------------------------------------------------------
+
+    public void validateAppTokens(int stackId, List<TaskGroup> tasks) {
+        synchronized (mWindowMap) {
+            int t = tasks.size() - 1;
+            if (t < 0) {
+                Slog.w(TAG, "validateAppTokens: empty task list");
+                return;
+            }
+
+            TaskGroup task = tasks.get(0);
+            int taskId = task.taskId;
+            Task targetTask = mTaskIdToTask.get(taskId);
+            DisplayContent displayContent = targetTask.getDisplayContent();
+            if (displayContent == null) {
+                Slog.w(TAG, "validateAppTokens: no Display for taskId=" + taskId);
+                return;
+            }
+
+            final ArrayList<Task> localTasks = mStackIdToStack.get(stackId).getTasks();
+            int taskNdx;
+            for (taskNdx = localTasks.size() - 1; taskNdx >= 0 && t >= 0; --taskNdx, --t) {
+                AppTokenList localTokens = localTasks.get(taskNdx).mAppTokens;
+                task = tasks.get(t);
+                List<IApplicationToken> tokens = task.tokens;
+
+                DisplayContent lastDisplayContent = displayContent;
+                displayContent = mTaskIdToTask.get(taskId).getDisplayContent();
+                if (displayContent != lastDisplayContent) {
+                    Slog.w(TAG, "validateAppTokens: displayContent changed in TaskGroup list!");
+                    return;
+                }
+
+                int tokenNdx;
+                int v;
+                for (tokenNdx = localTokens.size() - 1, v = task.tokens.size() - 1;
+                        tokenNdx >= 0 && v >= 0; ) {
+                    final AppWindowToken atoken = localTokens.get(tokenNdx);
+                    if (atoken.removed) {
+                        --tokenNdx;
+                        continue;
+                    }
+                    if (tokens.get(v) != atoken.token) {
+                        break;
+                    }
+                    --tokenNdx;
+                    v--;
+                }
+
+                if (tokenNdx >= 0 || v >= 0) {
+                    break;
+                }
+            }
+
+            if (taskNdx >= 0 || t >= 0) {
+                Slog.w(TAG, "validateAppTokens: Mismatch! ActivityManager=" + tasks);
+                Slog.w(TAG, "validateAppTokens: Mismatch! WindowManager=" + localTasks);
+                Slog.w(TAG, "validateAppTokens: Mismatch! Callers=" + Debug.getCallers(4));
+            }
+        }
+    }
+
+    public void validateStackOrder(Integer[] remoteStackIds) {
+        // TODO:
+    }
+
+    boolean checkCallingPermission(String permission, String func) {
+        // Quick check: if the calling permission is me, it's all okay.
+        if (Binder.getCallingPid() == Process.myPid()) {
+            return true;
+        }
+
+        if (mContext.checkCallingPermission(permission)
+                == PackageManager.PERMISSION_GRANTED) {
+            return true;
+        }
+        String msg = "Permission Denial: " + func + " from pid="
+                + Binder.getCallingPid()
+                + ", uid=" + Binder.getCallingUid()
+                + " requires " + permission;
+        Slog.w(TAG, msg);
+        return false;
+    }
+
+    boolean okToDisplay() {
+        return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully();
+    }
+
+    AppWindowToken findAppWindowToken(IBinder token) {
+        WindowToken wtoken = mTokenMap.get(token);
+        if (wtoken == null) {
+            return null;
+        }
+        return wtoken.appWindowToken;
+    }
+
+    @Override
+    public void addWindowToken(IBinder token, int type) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "addWindowToken()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            WindowToken wtoken = mTokenMap.get(token);
+            if (wtoken != null) {
+                Slog.w(TAG, "Attempted to add existing input method token: " + token);
+                return;
+            }
+            wtoken = new WindowToken(this, token, type, true);
+            mTokenMap.put(token, wtoken);
+            if (type == TYPE_WALLPAPER) {
+                mWallpaperTokens.add(wtoken);
+            }
+        }
+    }
+
+    @Override
+    public void removeWindowToken(IBinder token) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "removeWindowToken()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        final long origId = Binder.clearCallingIdentity();
+        synchronized(mWindowMap) {
+            DisplayContent displayContent = null;
+            WindowToken wtoken = mTokenMap.remove(token);
+            if (wtoken != null) {
+                boolean delayed = false;
+                if (!wtoken.hidden) {
+                    final int N = wtoken.windows.size();
+                    boolean changed = false;
+
+                    for (int i=0; i<N; i++) {
+                        WindowState win = wtoken.windows.get(i);
+                        displayContent = win.getDisplayContent();
+
+                        if (win.mWinAnimator.isAnimating()) {
+                            delayed = true;
+                        }
+
+                        if (win.isVisibleNow()) {
+                            win.mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT,
+                                    false);
+                            //TODO (multidisplay): Magnification is supported only for the default
+                            if (mDisplayMagnifier != null && win.isDefaultDisplay()) {
+                                mDisplayMagnifier.onWindowTransitionLocked(win,
+                                        WindowManagerPolicy.TRANSIT_EXIT);
+                            }
+                            changed = true;
+                            if (displayContent != null) {
+                                displayContent.layoutNeeded = true;
+                            }
+                        }
+                    }
+
+                    wtoken.hidden = true;
+
+                    if (changed) {
+                        performLayoutAndPlaceSurfacesLocked();
+                        updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
+                                false /*updateInputWindows*/);
+                    }
+
+                    if (delayed) {
+                        if (displayContent != null) {
+                            displayContent.mExitingTokens.add(wtoken);
+                        }
+                    } else if (wtoken.windowType == TYPE_WALLPAPER) {
+                        mWallpaperTokens.remove(wtoken);
+                    }
+                }
+
+                mInputMonitor.updateInputWindowsLw(true /*force*/);
+            } else {
+                Slog.w(TAG, "Attempted to remove non-existing token: " + token);
+            }
+        }
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    private Task createTask(int taskId, int stackId, int userId, AppWindowToken atoken) {
+        if (DEBUG_STACK) Slog.i(TAG, "createTask: taskId=" + taskId + " stackId=" + stackId
+                + " atoken=" + atoken);
+        final TaskStack stack = mStackIdToStack.get(stackId);
+        if (stack == null) {
+            throw new IllegalArgumentException("addAppToken: invalid stackId=" + stackId);
+        }
+        EventLog.writeEvent(EventLogTags.WM_TASK_CREATED, taskId, stackId);
+        Task task = new Task(atoken, stack, userId);
+        mTaskIdToTask.put(taskId, task);
+        stack.addTask(task, true);
+        return task;
+    }
+
+    @Override
+    public void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId,
+            int requestedOrientation, boolean fullscreen, boolean showWhenLocked, int userId,
+            int configChanges) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "addAppToken()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        // Get the dispatching timeout here while we are not holding any locks so that it
+        // can be cached by the AppWindowToken.  The timeout value is used later by the
+        // input dispatcher in code that does hold locks.  If we did not cache the value
+        // here we would run the chance of introducing a deadlock between the window manager
+        // (which holds locks while updating the input dispatcher state) and the activity manager
+        // (which holds locks while querying the application token).
+        long inputDispatchingTimeoutNanos;
+        try {
+            inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
+        } catch (RemoteException ex) {
+            Slog.w(TAG, "Could not get dispatching timeout.", ex);
+            inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
+        }
+
+        synchronized(mWindowMap) {
+            AppWindowToken atoken = findAppWindowToken(token.asBinder());
+            if (atoken != null) {
+                Slog.w(TAG, "Attempted to add existing app token: " + token);
+                return;
+            }
+            atoken = new AppWindowToken(this, token);
+            atoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
+            atoken.groupId = taskId;
+            atoken.appFullscreen = fullscreen;
+            atoken.showWhenLocked = showWhenLocked;
+            atoken.requestedOrientation = requestedOrientation;
+            atoken.layoutConfigChanges = (configChanges &
+                    (ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) != 0;
+            if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + atoken
+                    + " to stack=" + stackId + " task=" + taskId + " at " + addPos);
+
+            Task task = mTaskIdToTask.get(taskId);
+            if (task == null) {
+                createTask(taskId, stackId, userId, atoken);
+            } else {
+                task.addAppToken(addPos, atoken);
+            }
+
+            mTokenMap.put(token.asBinder(), atoken);
+
+            // Application tokens start out hidden.
+            atoken.hidden = true;
+            atoken.hiddenRequested = true;
+
+            //dump();
+        }
+    }
+
+    @Override
+    public void setAppGroupId(IBinder token, int groupId) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppGroupId()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            final AppWindowToken atoken = findAppWindowToken(token);
+            if (atoken == null) {
+                Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
+                return;
+            }
+            final Task oldTask = mTaskIdToTask.get(atoken.groupId);
+            removeAppFromTaskLocked(atoken);
+
+            atoken.groupId = groupId;
+            Task newTask = mTaskIdToTask.get(groupId);
+            if (newTask == null) {
+                newTask = createTask(groupId, oldTask.mStack.mStackId, oldTask.mUserId, atoken);
+            }
+            newTask.mAppTokens.add(atoken);
+        }
+    }
+
+    public int getOrientationFromWindowsLocked() {
+        if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
+            // If the display is frozen, some activities may be in the middle
+            // of restarting, and thus have removed their old window.  If the
+            // window has the flag to hide the lock screen, then the lock screen
+            // can re-appear and inflict its own orientation on us.  Keep the
+            // orientation stable until this all settles down.
+            return mLastWindowForcedOrientation;
+        }
+
+        // TODO(multidisplay): Change to the correct display.
+        final WindowList windows = getDefaultWindowListLocked();
+        int pos = windows.size() - 1;
+        while (pos >= 0) {
+            WindowState win = windows.get(pos);
+            pos--;
+            if (win.mAppToken != null) {
+                // We hit an application window. so the orientation will be determined by the
+                // app window. No point in continuing further.
+                return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+            }
+            if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) {
+                continue;
+            }
+            int req = win.mAttrs.screenOrientation;
+            if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
+                    (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
+                continue;
+            }
+
+            if (DEBUG_ORIENTATION) Slog.v(TAG, win + " forcing orientation to " + req);
+            return (mLastWindowForcedOrientation=req);
+        }
+        return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+    }
+
+    public int getOrientationFromAppTokensLocked() {
+        int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+        boolean findingBehind = false;
+        boolean lastFullscreen = false;
+        // TODO: Multi window.
+        DisplayContent displayContent = getDefaultDisplayContentLocked();
+        final ArrayList<Task> tasks = displayContent.getTasks();
+        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+            final int firstToken = tokens.size() - 1;
+            for (int tokenNdx = firstToken; tokenNdx >= 0; --tokenNdx) {
+                final AppWindowToken atoken = tokens.get(tokenNdx);
+
+                if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + atoken);
+
+                // if we're about to tear down this window and not seek for
+                // the behind activity, don't use it for orientation
+                if (!findingBehind
+                        && (!atoken.hidden && atoken.hiddenRequested)) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken
+                            + " -- going to hide");
+                    continue;
+                }
+
+                if (tokenNdx == firstToken) {
+                    // If we have hit a new Task, and the bottom
+                    // of the previous group didn't explicitly say to use
+                    // the orientation behind it, and the last app was
+                    // full screen, then we'll stick with the
+                    // user's orientation.
+                    if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
+                            && lastFullscreen) {
+                        if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken
+                                + " -- end of group, return " + lastOrientation);
+                        return lastOrientation;
+                    }
+                }
+
+                // We ignore any hidden applications on the top.
+                if (atoken.hiddenRequested || atoken.willBeHidden) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken
+                            + " -- hidden on top");
+                    continue;
+                }
+
+                if (tokenNdx == 0) {
+                    // Last token in this task.
+                    lastOrientation = atoken.requestedOrientation;
+                }
+
+                int or = atoken.requestedOrientation;
+                // If this application is fullscreen, and didn't explicitly say
+                // to use the orientation behind it, then just take whatever
+                // orientation it has and ignores whatever is under it.
+                lastFullscreen = atoken.appFullscreen;
+                if (lastFullscreen
+                        && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken
+                            + " -- full screen, return " + or);
+                    return or;
+                }
+                // If this application has requested an explicit orientation,
+                // then use it.
+                if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
+                        && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken
+                            + " -- explicitly set, return " + or);
+                    return or;
+                }
+                findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
+            }
+        }
+        if (DEBUG_ORIENTATION) Slog.v(TAG, "No app is requesting an orientation");
+        return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+    }
+
+    @Override
+    public Configuration updateOrientationFromAppTokens(
+            Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "updateOrientationFromAppTokens()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        Configuration config = null;
+        long ident = Binder.clearCallingIdentity();
+
+        synchronized(mWindowMap) {
+            config = updateOrientationFromAppTokensLocked(currentConfig,
+                    freezeThisOneIfNeeded);
+        }
+
+        Binder.restoreCallingIdentity(ident);
+        return config;
+    }
+
+    private Configuration updateOrientationFromAppTokensLocked(
+            Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
+        Configuration config = null;
+
+        if (updateOrientationFromAppTokensLocked(false)) {
+            if (freezeThisOneIfNeeded != null) {
+                AppWindowToken atoken = findAppWindowToken(freezeThisOneIfNeeded);
+                if (atoken != null) {
+                    startAppFreezingScreenLocked(atoken);
+                }
+            }
+            config = computeNewConfigurationLocked();
+
+        } else if (currentConfig != null) {
+            // No obvious action we need to take, but if our current
+            // state mismatches the activity manager's, update it,
+            // disregarding font scale, which should remain set to
+            // the value of the previous configuration.
+            mTempConfiguration.setToDefaults();
+            mTempConfiguration.fontScale = currentConfig.fontScale;
+            if (computeScreenConfigurationLocked(mTempConfiguration)) {
+                if (currentConfig.diff(mTempConfiguration) != 0) {
+                    mWaitingForConfig = true;
+                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
+                    displayContent.layoutNeeded = true;
+                    int anim[] = new int[2];
+                    if (displayContent.isDimming()) {
+                        anim[0] = anim[1] = 0;
+                    } else {
+                        mPolicy.selectRotationAnimationLw(anim);
+                    }
+                    startFreezingDisplayLocked(false, anim[0], anim[1]);
+                    config = new Configuration(mTempConfiguration);
+                }
+            }
+        }
+
+        return config;
+    }
+
+    /*
+     * Determine the new desired orientation of the display, returning
+     * a non-null new Configuration if it has changed from the current
+     * orientation.  IF TRUE IS RETURNED SOMEONE MUST CALL
+     * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
+     * SCREEN.  This will typically be done for you if you call
+     * sendNewConfiguration().
+     *
+     * The orientation is computed from non-application windows first. If none of
+     * the non-application windows specify orientation, the orientation is computed from
+     * application tokens.
+     * @see android.view.IWindowManager#updateOrientationFromAppTokens(
+     * android.os.IBinder)
+     */
+    boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
+        long ident = Binder.clearCallingIdentity();
+        try {
+            int req = getOrientationFromWindowsLocked();
+            if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
+                req = getOrientationFromAppTokensLocked();
+            }
+
+            if (req != mForcedAppOrientation) {
+                mForcedAppOrientation = req;
+                //send a message to Policy indicating orientation change to take
+                //action like disabling/enabling sensors etc.,
+                mPolicy.setCurrentOrientationLw(req);
+                if (updateRotationUncheckedLocked(inTransaction)) {
+                    // changed
+                    return true;
+                }
+            }
+
+            return false;
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public void setNewConfiguration(Configuration config) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setNewConfiguration()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            mCurConfiguration = new Configuration(config);
+            if (mWaitingForConfig) {
+                mWaitingForConfig = false;
+                mLastFinishedFreezeSource = "new-config";
+            }
+            performLayoutAndPlaceSurfacesLocked();
+        }
+    }
+
+    @Override
+    public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppOrientation()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            AppWindowToken atoken = findAppWindowToken(token.asBinder());
+            if (atoken == null) {
+                Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
+                return;
+            }
+
+            atoken.requestedOrientation = requestedOrientation;
+        }
+    }
+
+    @Override
+    public int getAppOrientation(IApplicationToken token) {
+        synchronized(mWindowMap) {
+            AppWindowToken wtoken = findAppWindowToken(token.asBinder());
+            if (wtoken == null) {
+                return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+            }
+
+            return wtoken.requestedOrientation;
+        }
+    }
+
+    /** Call while in a Surface transaction. */
+    void setFocusedStackLayer() {
+        mFocusedStackLayer = 0;
+        if (mFocusedApp != null) {
+            final WindowList windows = mFocusedApp.allAppWindows;
+            for (int i = windows.size() - 1; i >= 0; --i) {
+                final WindowState win = windows.get(i);
+                final int animLayer = win.mWinAnimator.mAnimLayer;
+                if (win.mAttachedWindow == null && win.isVisibleLw() &&
+                        animLayer > mFocusedStackLayer) {
+                    mFocusedStackLayer = animLayer + LAYER_OFFSET_FOCUSED_STACK;
+                }
+            }
+        }
+        if (DEBUG_LAYERS) Slog.v(TAG, "Setting FocusedStackFrame to layer=" +
+                mFocusedStackLayer);
+        mFocusedStackFrame.setLayer(mFocusedStackLayer);
+    }
+
+    void setFocusedStackFrame() {
+        final TaskStack stack;
+        if (mFocusedApp != null) {
+            Task task = mTaskIdToTask.get(mFocusedApp.groupId);
+            stack = task.mStack;
+            final DisplayContent displayContent = task.getDisplayContent();
+            if (displayContent != null) {
+                displayContent.setTouchExcludeRegion(stack);
+            }
+        } else {
+            stack = null;
+        }
+        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setFocusedStackFrame");
+        SurfaceControl.openTransaction();
+        try {
+            if (stack == null) {
+                mFocusedStackFrame.setVisibility(false);
+            } else {
+                mFocusedStackFrame.setBounds(stack);
+                final boolean multipleStacks = !stack.isFullscreen();
+                mFocusedStackFrame.setVisibility(multipleStacks);
+            }
+        } finally {
+            SurfaceControl.closeTransaction();
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> CLOSE TRANSACTION setFocusedStackFrame");
+        }
+    }
+
+    @Override
+    public void setFocusedApp(IBinder token, boolean moveFocusNow) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setFocusedApp()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            final AppWindowToken newFocus;
+            if (token == null) {
+                if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
+                newFocus = null;
+            } else {
+                newFocus = findAppWindowToken(token);
+                if (newFocus == null) {
+                    Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
+                }
+                if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Set focused app to: " + newFocus
+                        + " old focus=" + mFocusedApp + " moveFocusNow=" + moveFocusNow);
+            }
+
+            final boolean changed = mFocusedApp != newFocus;
+            if (changed) {
+                mFocusedApp = newFocus;
+                mInputMonitor.setFocusedAppLw(null);
+            }
+
+            if (moveFocusNow && changed) {
+                final long origId = Binder.clearCallingIdentity();
+                updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
+                Binder.restoreCallingIdentity(origId);
+            }
+        }
+    }
+
+    @Override
+    public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "prepareAppTransition()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            if (DEBUG_APP_TRANSITIONS) Slog.v(
+                    TAG, "Prepare app transition: transit=" + transit
+                    + " " + mAppTransition
+                    + " alwaysKeepCurrent=" + alwaysKeepCurrent
+                    + " Callers=" + Debug.getCallers(3));
+            if (okToDisplay()) {
+                if (!mAppTransition.isTransitionSet() || mAppTransition.isTransitionNone()) {
+                    mAppTransition.setAppTransition(transit);
+                } else if (!alwaysKeepCurrent) {
+                    if (transit == AppTransition.TRANSIT_TASK_OPEN
+                            && mAppTransition.isTransitionEqual(
+                                    AppTransition.TRANSIT_TASK_CLOSE)) {
+                        // Opening a new task always supersedes a close for the anim.
+                        mAppTransition.setAppTransition(transit);
+                    } else if (transit == AppTransition.TRANSIT_ACTIVITY_OPEN
+                            && mAppTransition.isTransitionEqual(
+                                AppTransition.TRANSIT_ACTIVITY_CLOSE)) {
+                        // Opening a new activity always supersedes a close for the anim.
+                        mAppTransition.setAppTransition(transit);
+                    }
+                }
+                mAppTransition.prepare();
+                mStartingIconInTransition = false;
+                mSkipAppTransitionAnimation = false;
+                mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
+                mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, 5000);
+            }
+        }
+    }
+
+    @Override
+    public int getPendingAppTransition() {
+        return mAppTransition.getAppTransition();
+    }
+
+    @Override
+    public void overridePendingAppTransition(String packageName,
+            int enterAnim, int exitAnim, IRemoteCallback startedCallback) {
+        synchronized(mWindowMap) {
+            mAppTransition.overridePendingAppTransition(packageName, enterAnim, exitAnim,
+                    startedCallback);
+        }
+    }
+
+    @Override
+    public void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
+            int startHeight) {
+        synchronized(mWindowMap) {
+            mAppTransition.overridePendingAppTransitionScaleUp(startX, startY, startWidth,
+                    startHeight);
+        }
+    }
+
+    @Override
+    public void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX,
+            int startY, IRemoteCallback startedCallback, boolean scaleUp) {
+        synchronized(mWindowMap) {
+            mAppTransition.overridePendingAppTransitionThumb(srcThumb, startX, startY,
+                    startedCallback, scaleUp);
+        }
+    }
+
+    @Override
+    public void executeAppTransition() {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "executeAppTransition()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            if (DEBUG_APP_TRANSITIONS) {
+                RuntimeException e = new RuntimeException("here");
+                e.fillInStackTrace();
+                Slog.w(TAG, "Execute app transition: " + mAppTransition, e);
+            }
+            if (mAppTransition.isTransitionSet()) {
+                mAppTransition.setReady();
+                final long origId = Binder.clearCallingIdentity();
+                performLayoutAndPlaceSurfacesLocked();
+                Binder.restoreCallingIdentity(origId);
+            }
+        }
+    }
+
+    @Override
+    public void setAppStartingWindow(IBinder token, String pkg,
+            int theme, CompatibilityInfo compatInfo,
+            CharSequence nonLocalizedLabel, int labelRes, int icon, int logo,
+            int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppStartingWindow()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            if (DEBUG_STARTING_WINDOW) Slog.v(
+                    TAG, "setAppStartingWindow: token=" + token + " pkg=" + pkg
+                    + " transferFrom=" + transferFrom);
+
+            AppWindowToken wtoken = findAppWindowToken(token);
+            if (wtoken == null) {
+                Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
+                return;
+            }
+
+            // If the display is frozen, we won't do anything until the
+            // actual window is displayed so there is no reason to put in
+            // the starting window.
+            if (!okToDisplay()) {
+                return;
+            }
+
+            if (wtoken.startingData != null) {
+                return;
+            }
+
+            if (transferFrom != null) {
+                AppWindowToken ttoken = findAppWindowToken(transferFrom);
+                if (ttoken != null) {
+                    WindowState startingWindow = ttoken.startingWindow;
+                    if (startingWindow != null) {
+                        if (mStartingIconInTransition) {
+                            // In this case, the starting icon has already
+                            // been displayed, so start letting windows get
+                            // shown immediately without any more transitions.
+                            mSkipAppTransitionAnimation = true;
+                        }
+                        if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
+                                "Moving existing starting " + startingWindow + " from " + ttoken
+                                + " to " + wtoken);
+                        final long origId = Binder.clearCallingIdentity();
+
+                        // Transfer the starting window over to the new
+                        // token.
+                        wtoken.startingData = ttoken.startingData;
+                        wtoken.startingView = ttoken.startingView;
+                        wtoken.startingDisplayed = ttoken.startingDisplayed;
+                        ttoken.startingDisplayed = false;
+                        wtoken.startingWindow = startingWindow;
+                        wtoken.reportedVisible = ttoken.reportedVisible;
+                        ttoken.startingData = null;
+                        ttoken.startingView = null;
+                        ttoken.startingWindow = null;
+                        ttoken.startingMoved = true;
+                        startingWindow.mToken = wtoken;
+                        startingWindow.mRootToken = wtoken;
+                        startingWindow.mAppToken = wtoken;
+                        startingWindow.mWinAnimator.mAppAnimator = wtoken.mAppAnimator;
+
+                        if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) {
+                            Slog.v(TAG, "Removing starting window: " + startingWindow);
+                        }
+                        removeStartingWindowTimeout(ttoken);
+                        startingWindow.getWindowList().remove(startingWindow);
+                        mWindowsChanged = true;
+                        if (DEBUG_ADD_REMOVE) Slog.v(TAG,
+                                "Removing starting " + startingWindow + " from " + ttoken);
+                        ttoken.windows.remove(startingWindow);
+                        ttoken.allAppWindows.remove(startingWindow);
+                        addWindowToListInOrderLocked(startingWindow, true);
+
+                        // Propagate other interesting state between the
+                        // tokens.  If the old token is displayed, we should
+                        // immediately force the new one to be displayed.  If
+                        // it is animating, we need to move that animation to
+                        // the new one.
+                        if (ttoken.allDrawn) {
+                            wtoken.allDrawn = true;
+                            wtoken.deferClearAllDrawn = ttoken.deferClearAllDrawn;
+                        }
+                        if (ttoken.firstWindowDrawn) {
+                            wtoken.firstWindowDrawn = true;
+                        }
+                        if (!ttoken.hidden) {
+                            wtoken.hidden = false;
+                            wtoken.hiddenRequested = false;
+                            wtoken.willBeHidden = false;
+                        }
+                        if (wtoken.clientHidden != ttoken.clientHidden) {
+                            wtoken.clientHidden = ttoken.clientHidden;
+                            wtoken.sendAppVisibilityToClients();
+                        }
+                        final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator;
+                        final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator;
+                        if (tAppAnimator.animation != null) {
+                            wAppAnimator.animation = tAppAnimator.animation;
+                            wAppAnimator.animating = tAppAnimator.animating;
+                            wAppAnimator.animLayerAdjustment = tAppAnimator.animLayerAdjustment;
+                            tAppAnimator.animation = null;
+                            tAppAnimator.animLayerAdjustment = 0;
+                            wAppAnimator.updateLayers();
+                            tAppAnimator.updateLayers();
+                        }
+
+                        updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                                true /*updateInputWindows*/);
+                        getDefaultDisplayContentLocked().layoutNeeded = true;
+                        performLayoutAndPlaceSurfacesLocked();
+                        Binder.restoreCallingIdentity(origId);
+                        return;
+                    } else if (ttoken.startingData != null) {
+                        // The previous app was getting ready to show a
+                        // starting window, but hasn't yet done so.  Steal it!
+                        if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
+                                "Moving pending starting from " + ttoken
+                                + " to " + wtoken);
+                        wtoken.startingData = ttoken.startingData;
+                        ttoken.startingData = null;
+                        ttoken.startingMoved = true;
+                        Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
+                        // Note: we really want to do sendMessageAtFrontOfQueue() because we
+                        // want to process the message ASAP, before any other queued
+                        // messages.
+                        mH.sendMessageAtFrontOfQueue(m);
+                        return;
+                    }
+                    final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator;
+                    final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator;
+                    if (tAppAnimator.thumbnail != null) {
+                        // The old token is animating with a thumbnail, transfer
+                        // that to the new token.
+                        if (wAppAnimator.thumbnail != null) {
+                            wAppAnimator.thumbnail.destroy();
+                        }
+                        wAppAnimator.thumbnail = tAppAnimator.thumbnail;
+                        wAppAnimator.thumbnailX = tAppAnimator.thumbnailX;
+                        wAppAnimator.thumbnailY = tAppAnimator.thumbnailY;
+                        wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
+                        wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
+                        tAppAnimator.thumbnail = null;
+                    }
+                }
+            }
+
+            // There is no existing starting window, and the caller doesn't
+            // want us to create one, so that's it!
+            if (!createIfNeeded) {
+                return;
+            }
+
+            // If this is a translucent window, then don't
+            // show a starting window -- the current effect (a full-screen
+            // opaque starting window that fades away to the real contents
+            // when it is ready) does not work for this.
+            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Checking theme of starting window: 0x"
+                    + Integer.toHexString(theme));
+            if (theme != 0) {
+                AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
+                        com.android.internal.R.styleable.Window, mCurrentUserId);
+                if (ent == null) {
+                    // Whoops!  App doesn't exist.  Um.  Okay.  We'll just
+                    // pretend like we didn't see that.
+                    return;
+                }
+                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Translucent="
+                        + ent.array.getBoolean(
+                                com.android.internal.R.styleable.Window_windowIsTranslucent, false)
+                        + " Floating="
+                        + ent.array.getBoolean(
+                                com.android.internal.R.styleable.Window_windowIsFloating, false)
+                        + " ShowWallpaper="
+                        + ent.array.getBoolean(
+                                com.android.internal.R.styleable.Window_windowShowWallpaper, false));
+                if (ent.array.getBoolean(
+                        com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
+                    return;
+                }
+                if (ent.array.getBoolean(
+                        com.android.internal.R.styleable.Window_windowIsFloating, false)) {
+                    return;
+                }
+                if (ent.array.getBoolean(
+                        com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
+                    if (mWallpaperTarget == null) {
+                        // If this theme is requesting a wallpaper, and the wallpaper
+                        // is not curently visible, then this effectively serves as
+                        // an opaque window and our starting window transition animation
+                        // can still work.  We just need to make sure the starting window
+                        // is also showing the wallpaper.
+                        windowFlags |= FLAG_SHOW_WALLPAPER;
+                    } else {
+                        return;
+                    }
+                }
+            }
+
+            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Creating StartingData");
+            mStartingIconInTransition = true;
+            wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel,
+                    labelRes, icon, logo, windowFlags);
+            Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
+            // Note: we really want to do sendMessageAtFrontOfQueue() because we
+            // want to process the message ASAP, before any other queued
+            // messages.
+            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Enqueueing ADD_STARTING");
+            mH.sendMessageAtFrontOfQueue(m);
+        }
+    }
+
+    @Override
+    public void setAppWillBeHidden(IBinder token) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppWillBeHidden()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        AppWindowToken wtoken;
+
+        synchronized(mWindowMap) {
+            wtoken = findAppWindowToken(token);
+            if (wtoken == null) {
+                Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
+                return;
+            }
+            wtoken.willBeHidden = true;
+        }
+    }
+
+    public void setAppFullscreen(IBinder token, boolean toOpaque) {
+        AppWindowToken atoken = findAppWindowToken(token);
+        if (atoken != null) {
+            atoken.appFullscreen = toOpaque;
+            // When making translucent, wait until windows below have been drawn.
+            if (toOpaque) {
+                // Making opaque so do it now.
+                setWindowOpaque(token, true);
+            }
+            requestTraversal();
+        }
+    }
+
+    public void setWindowOpaque(IBinder token, boolean isOpaque) {
+        AppWindowToken wtoken = findAppWindowToken(token);
+        if (wtoken != null) {
+            WindowState win = wtoken.findMainWindow();
+            if (win != null) {
+                win.mWinAnimator.setOpaque(isOpaque);
+            }
+        }
+    }
+
+    boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
+            boolean visible, int transit, boolean performLayout) {
+        boolean delayed = false;
+
+        if (wtoken.clientHidden == visible) {
+            wtoken.clientHidden = !visible;
+            wtoken.sendAppVisibilityToClients();
+        }
+
+        wtoken.willBeHidden = false;
+        if (wtoken.hidden == visible) {
+            boolean changed = false;
+            if (DEBUG_APP_TRANSITIONS) Slog.v(
+                TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
+                + " performLayout=" + performLayout);
+
+            boolean runningAppAnimation = false;
+
+            if (transit != AppTransition.TRANSIT_UNSET) {
+                if (wtoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
+                    wtoken.mAppAnimator.animation = null;
+                }
+                if (applyAnimationLocked(wtoken, lp, transit, visible)) {
+                    delayed = runningAppAnimation = true;
+                }
+                WindowState window = wtoken.findMainWindow();
+                //TODO (multidisplay): Magnification is supported only for the default display.
+                if (window != null && mDisplayMagnifier != null
+                        && window.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                    mDisplayMagnifier.onAppWindowTransitionLocked(window, transit);
+                }
+                changed = true;
+            }
+
+            final int N = wtoken.allAppWindows.size();
+            for (int i=0; i<N; i++) {
+                WindowState win = wtoken.allAppWindows.get(i);
+                if (win == wtoken.startingWindow) {
+                    continue;
+                }
+
+                //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
+                //win.dump("  ");
+                if (visible) {
+                    if (!win.isVisibleNow()) {
+                        if (!runningAppAnimation) {
+                            win.mWinAnimator.applyAnimationLocked(
+                                    WindowManagerPolicy.TRANSIT_ENTER, true);
+                            //TODO (multidisplay): Magnification is supported only for the default
+                            if (mDisplayMagnifier != null
+                                    && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                                mDisplayMagnifier.onWindowTransitionLocked(win,
+                                        WindowManagerPolicy.TRANSIT_ENTER);
+                            }
+                        }
+                        changed = true;
+                        final DisplayContent displayContent = win.getDisplayContent();
+                        if (displayContent != null) {
+                            displayContent.layoutNeeded = true;
+                        }
+                    }
+                } else if (win.isVisibleNow()) {
+                    if (!runningAppAnimation) {
+                        win.mWinAnimator.applyAnimationLocked(
+                                WindowManagerPolicy.TRANSIT_EXIT, false);
+                        //TODO (multidisplay): Magnification is supported only for the default
+                        if (mDisplayMagnifier != null
+                                && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
+                            mDisplayMagnifier.onWindowTransitionLocked(win,
+                                    WindowManagerPolicy.TRANSIT_EXIT);
+                        }
+                    }
+                    changed = true;
+                    final DisplayContent displayContent = win.getDisplayContent();
+                    if (displayContent != null) {
+                        displayContent.layoutNeeded = true;
+                    }
+                }
+            }
+
+            wtoken.hidden = wtoken.hiddenRequested = !visible;
+            if (!visible) {
+                unsetAppFreezingScreenLocked(wtoken, true, true);
+            } else {
+                // If we are being set visible, and the starting window is
+                // not yet displayed, then make sure it doesn't get displayed.
+                WindowState swin = wtoken.startingWindow;
+                if (swin != null && !swin.isDrawnLw()) {
+                    swin.mPolicyVisibility = false;
+                    swin.mPolicyVisibilityAfterAnim = false;
+                 }
+            }
+
+            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
+                      + ": hidden=" + wtoken.hidden + " hiddenRequested="
+                      + wtoken.hiddenRequested);
+
+            if (changed) {
+                mInputMonitor.setUpdateInputWindowsNeededLw();
+                if (performLayout) {
+                    updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                            false /*updateInputWindows*/);
+                    performLayoutAndPlaceSurfacesLocked();
+                }
+                mInputMonitor.updateInputWindowsLw(false /*force*/);
+            }
+        }
+
+        if (wtoken.mAppAnimator.animation != null) {
+            delayed = true;
+        }
+
+        for (int i = wtoken.allAppWindows.size() - 1; i >= 0 && !delayed; i--) {
+            if (wtoken.allAppWindows.get(i).mWinAnimator.isWindowAnimating()) {
+                delayed = true;
+            }
+        }
+
+        return delayed;
+    }
+
+    @Override
+    public void setAppVisibility(IBinder token, boolean visible) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppVisibility()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        AppWindowToken wtoken;
+
+        synchronized(mWindowMap) {
+            wtoken = findAppWindowToken(token);
+            if (wtoken == null) {
+                Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
+                return;
+            }
+
+            if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
+                RuntimeException e = null;
+                if (!HIDE_STACK_CRAWLS) {
+                    e = new RuntimeException();
+                    e.fillInStackTrace();
+                }
+                Slog.v(TAG, "setAppVisibility(" + token + ", visible=" + visible
+                        + "): " + mAppTransition
+                        + " hidden=" + wtoken.hidden
+                        + " hiddenRequested=" + wtoken.hiddenRequested, e);
+            }
+
+            // If we are preparing an app transition, then delay changing
+            // the visibility of this token until we execute that transition.
+            if (okToDisplay() && mAppTransition.isTransitionSet()) {
+                wtoken.hiddenRequested = !visible;
+
+                if (!wtoken.startingDisplayed) {
+                    if (DEBUG_APP_TRANSITIONS) Slog.v(
+                            TAG, "Setting dummy animation on: " + wtoken);
+                    wtoken.mAppAnimator.setDummyAnimation();
+                }
+                mOpeningApps.remove(wtoken);
+                mClosingApps.remove(wtoken);
+                wtoken.waitingToShow = wtoken.waitingToHide = false;
+                wtoken.inPendingTransaction = true;
+                if (visible) {
+                    mOpeningApps.add(wtoken);
+                    wtoken.startingMoved = false;
+
+                    // If the token is currently hidden (should be the
+                    // common case), then we need to set up to wait for
+                    // its windows to be ready.
+                    if (wtoken.hidden) {
+                        wtoken.allDrawn = false;
+                        wtoken.deferClearAllDrawn = false;
+                        wtoken.waitingToShow = true;
+
+                        if (wtoken.clientHidden) {
+                            // In the case where we are making an app visible
+                            // but holding off for a transition, we still need
+                            // to tell the client to make its windows visible so
+                            // they get drawn.  Otherwise, we will wait on
+                            // performing the transition until all windows have
+                            // been drawn, they never will be, and we are sad.
+                            wtoken.clientHidden = false;
+                            wtoken.sendAppVisibilityToClients();
+                        }
+                    }
+                } else {
+                    mClosingApps.add(wtoken);
+
+                    // If the token is currently visible (should be the
+                    // common case), then set up to wait for it to be hidden.
+                    if (!wtoken.hidden) {
+                        wtoken.waitingToHide = true;
+                    }
+                }
+                return;
+            }
+
+            final long origId = Binder.clearCallingIdentity();
+            setTokenVisibilityLocked(wtoken, null, visible, AppTransition.TRANSIT_UNSET,
+                    true);
+            wtoken.updateReportedVisibilityLocked();
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
+            boolean unfreezeSurfaceNow, boolean force) {
+        if (wtoken.mAppAnimator.freezingScreen) {
+            if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
+                    + " force=" + force);
+            final int N = wtoken.allAppWindows.size();
+            boolean unfrozeWindows = false;
+            for (int i=0; i<N; i++) {
+                WindowState w = wtoken.allAppWindows.get(i);
+                if (w.mAppFreezing) {
+                    w.mAppFreezing = false;
+                    if (w.mHasSurface && !w.mOrientationChanging) {
+                        if (DEBUG_ORIENTATION) Slog.v(TAG, "set mOrientationChanging of " + w);
+                        w.mOrientationChanging = true;
+                        mInnerFields.mOrientationChangeComplete = false;
+                    }
+                    w.mLastFreezeDuration = 0;
+                    unfrozeWindows = true;
+                    final DisplayContent displayContent = w.getDisplayContent();
+                    if (displayContent != null) {
+                        displayContent.layoutNeeded = true;
+                    }
+                }
+            }
+            if (force || unfrozeWindows) {
+                if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
+                wtoken.mAppAnimator.freezingScreen = false;
+                wtoken.mAppAnimator.lastFreezeDuration = (int)(SystemClock.elapsedRealtime()
+                        - mDisplayFreezeTime);
+                mAppsFreezingScreen--;
+                mLastFinishedFreezeSource = wtoken;
+            }
+            if (unfreezeSurfaceNow) {
+                if (unfrozeWindows) {
+                    performLayoutAndPlaceSurfacesLocked();
+                }
+                stopFreezingDisplayLocked();
+            }
+        }
+    }
+
+    private void startAppFreezingScreenLocked(AppWindowToken wtoken) {
+        if (DEBUG_ORIENTATION) {
+            RuntimeException e = null;
+            if (!HIDE_STACK_CRAWLS) {
+                e = new RuntimeException();
+                e.fillInStackTrace();
+            }
+            Slog.i(TAG, "Set freezing of " + wtoken.appToken
+                    + ": hidden=" + wtoken.hidden + " freezing="
+                    + wtoken.mAppAnimator.freezingScreen, e);
+        }
+        if (!wtoken.hiddenRequested) {
+            if (!wtoken.mAppAnimator.freezingScreen) {
+                wtoken.mAppAnimator.freezingScreen = true;
+                wtoken.mAppAnimator.lastFreezeDuration = 0;
+                mAppsFreezingScreen++;
+                if (mAppsFreezingScreen == 1) {
+                    startFreezingDisplayLocked(false, 0, 0);
+                    mH.removeMessages(H.APP_FREEZE_TIMEOUT);
+                    mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 5000);
+                }
+            }
+            final int N = wtoken.allAppWindows.size();
+            for (int i=0; i<N; i++) {
+                WindowState w = wtoken.allAppWindows.get(i);
+                w.mAppFreezing = true;
+            }
+        }
+    }
+
+    @Override
+    public void startAppFreezingScreen(IBinder token, int configChanges) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppFreezingScreen()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            if (configChanges == 0 && okToDisplay()) {
+                if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
+                return;
+            }
+
+            AppWindowToken wtoken = findAppWindowToken(token);
+            if (wtoken == null || wtoken.appToken == null) {
+                Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
+                return;
+            }
+            final long origId = Binder.clearCallingIdentity();
+            startAppFreezingScreenLocked(wtoken);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    @Override
+    public void stopAppFreezingScreen(IBinder token, boolean force) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setAppFreezingScreen()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized(mWindowMap) {
+            AppWindowToken wtoken = findAppWindowToken(token);
+            if (wtoken == null || wtoken.appToken == null) {
+                return;
+            }
+            final long origId = Binder.clearCallingIdentity();
+            if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
+                    + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.mAppAnimator.freezingScreen);
+            unsetAppFreezingScreenLocked(wtoken, true, force);
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    void removeAppFromTaskLocked(AppWindowToken wtoken) {
+        final Task task = mTaskIdToTask.get(wtoken.groupId);
+        if (task != null) {
+            if (!task.removeAppToken(wtoken)) {
+                Slog.e(TAG, "removeAppFromTaskLocked: token=" + wtoken + " not found.");
+            }
+        }
+    }
+
+    @Override
+    public void removeAppToken(IBinder token) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "removeAppToken()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        AppWindowToken wtoken = null;
+        AppWindowToken startingToken = null;
+        boolean delayed = false;
+
+        final long origId = Binder.clearCallingIdentity();
+        synchronized(mWindowMap) {
+            WindowToken basewtoken = mTokenMap.remove(token);
+            if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
+                delayed = setTokenVisibilityLocked(wtoken, null, false,
+                        AppTransition.TRANSIT_UNSET, true);
+                wtoken.inPendingTransaction = false;
+                mOpeningApps.remove(wtoken);
+                wtoken.waitingToShow = false;
+                if (mClosingApps.contains(wtoken)) {
+                    delayed = true;
+                } else if (mAppTransition.isTransitionSet()) {
+                    mClosingApps.add(wtoken);
+                    wtoken.waitingToHide = true;
+                    delayed = true;
+                }
+                if (DEBUG_APP_TRANSITIONS) Slog.v(
+                        TAG, "Removing app " + wtoken + " delayed=" + delayed
+                        + " animation=" + wtoken.mAppAnimator.animation
+                        + " animating=" + wtoken.mAppAnimator.animating);
+                if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG, "removeAppToken: "
+                        + wtoken + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
+                final TaskStack stack = mTaskIdToTask.get(wtoken.groupId).mStack;
+                if (delayed) {
+                    // set the token aside because it has an active animation to be finished
+                    if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
+                            "removeAppToken make exiting: " + wtoken);
+                    stack.mExitingAppTokens.add(wtoken);
+                    wtoken.mDeferRemoval = true;
+                } else {
+                    // Make sure there is no animation running on this token,
+                    // so any windows associated with it will be removed as
+                    // soon as their animations are complete
+                    wtoken.mAppAnimator.clearAnimation();
+                    wtoken.mAppAnimator.animating = false;
+                    removeAppFromTaskLocked(wtoken);
+                }
+
+                wtoken.removed = true;
+                if (wtoken.startingData != null) {
+                    startingToken = wtoken;
+                }
+                unsetAppFreezingScreenLocked(wtoken, true, true);
+                if (mFocusedApp == wtoken) {
+                    if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Removing focused app token:" + wtoken);
+                    mFocusedApp = null;
+                    updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
+                    mInputMonitor.setFocusedAppLw(null);
+                }
+            } else {
+                Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
+            }
+
+            if (!delayed && wtoken != null) {
+                wtoken.updateReportedVisibilityLocked();
+            }
+        }
+        Binder.restoreCallingIdentity(origId);
+
+        // Will only remove if startingToken non null.
+        scheduleRemoveStartingWindow(startingToken);
+    }
+
+    void removeStartingWindowTimeout(AppWindowToken wtoken) {
+        if (wtoken != null) {
+            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, Debug.getCallers(1) +
+                    ": Remove starting window timeout " + wtoken + (wtoken != null ?
+                    " startingWindow=" + wtoken.startingWindow : ""));
+            mH.removeMessages(H.REMOVE_STARTING_TIMEOUT, wtoken);
+        }
+    }
+
+    void scheduleRemoveStartingWindow(AppWindowToken wtoken) {
+        if (wtoken != null && wtoken.startingWindow != null) {
+            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, Debug.getCallers(1) +
+                    ": Schedule remove starting " + wtoken + (wtoken != null ?
+                    " startingWindow=" + wtoken.startingWindow : ""));
+            removeStartingWindowTimeout(wtoken);
+            Message m = mH.obtainMessage(H.REMOVE_STARTING, wtoken);
+            mH.sendMessage(m);
+        }
+    }
+
+    private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
+        WindowList windows = token.windows;
+        final int NW = windows.size();
+        if (NW > 0) {
+            mWindowsChanged = true;
+        }
+        for (int i = 0; i < NW; i++) {
+            WindowState win = windows.get(i);
+            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
+            win.getWindowList().remove(win);
+            int j = win.mChildWindows.size();
+            while (j > 0) {
+                j--;
+                WindowState cwin = win.mChildWindows.get(j);
+                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
+                        "Tmp removing child window " + cwin);
+                cwin.getWindowList().remove(cwin);
+            }
+        }
+        return NW > 0;
+    }
+
+    void dumpAppTokensLocked() {
+        final int numStacks = mStackIdToStack.size();
+        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+            final TaskStack stack = mStackIdToStack.valueAt(stackNdx);
+            Slog.v(TAG, "  Stack #" + stack.mStackId + " tasks from bottom to top:");
+            final ArrayList<Task> tasks = stack.getTasks();
+            final int numTasks = tasks.size();
+            for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
+                final Task task = tasks.get(taskNdx);
+                Slog.v(TAG, "    Task #" + task.taskId + " activities from bottom to top:");
+                AppTokenList tokens = task.mAppTokens;
+                final int numTokens = tokens.size();
+                for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
+                    Slog.v(TAG, "      activity #" + tokenNdx + ": " + tokens.get(tokenNdx).token);
+                }
+            }
+        }
+    }
+
+    void dumpWindowsLocked() {
+        final int numDisplays = mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+            Slog.v(TAG, " Display #" + displayContent.getDisplayId());
+            final WindowList windows = displayContent.getWindowList();
+            for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
+                Slog.v(TAG, "  #" + winNdx + ": " + windows.get(winNdx));
+            }
+        }
+    }
+
+    private int findAppWindowInsertionPointLocked(AppWindowToken target) {
+        final int taskId = target.groupId;
+        Task targetTask = mTaskIdToTask.get(taskId);
+        if (targetTask == null) {
+            Slog.w(TAG, "findAppWindowInsertionPointLocked: no Task for " + target + " taskId="
+                    + taskId);
+            return 0;
+        }
+        DisplayContent displayContent = targetTask.getDisplayContent();
+        if (displayContent == null) {
+            Slog.w(TAG, "findAppWindowInsertionPointLocked: no DisplayContent for " + target);
+            return 0;
+        }
+        final WindowList windows = displayContent.getWindowList();
+        final int NW = windows.size();
+
+        boolean found = false;
+        final ArrayList<Task> tasks = displayContent.getTasks();
+        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+            final Task task = tasks.get(taskNdx);
+            if (!found && task.taskId != taskId) {
+                continue;
+            }
+            AppTokenList tokens = task.mAppTokens;
+            for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                final AppWindowToken wtoken = tokens.get(tokenNdx);
+                if (!found && wtoken == target) {
+                    found = true;
+                }
+                if (found) {
+                    // Find the first app token below the new position that has
+                    // a window displayed.
+                    if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows in " + wtoken.token);
+                    if (wtoken.sendingToBottom) {
+                        if (DEBUG_REORDER) Slog.v(TAG, "Skipping token -- currently sending to bottom");
+                        continue;
+                    }
+                    for (int i = wtoken.windows.size() - 1; i >= 0; --i) {
+                        WindowState win = wtoken.windows.get(i);
+                        for (int j = win.mChildWindows.size() - 1; j >= 0; --j) {
+                            WindowState cwin = win.mChildWindows.get(j);
+                            if (cwin.mSubLayer >= 0) {
+                                for (int pos = NW - 1; pos >= 0; pos--) {
+                                    if (windows.get(pos) == cwin) {
+                                        if (DEBUG_REORDER) Slog.v(TAG,
+                                                "Found child win @" + (pos + 1));
+                                        return pos + 1;
+                                    }
+                                }
+                            }
+                        }
+                        for (int pos = NW - 1; pos >= 0; pos--) {
+                            if (windows.get(pos) == win) {
+                                if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos + 1));
+                                return pos + 1;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        // Never put an app window underneath wallpaper.
+        for (int pos = NW - 1; pos >= 0; pos--) {
+            if (windows.get(pos).mIsWallpaper) {
+                if (DEBUG_REORDER) Slog.v(TAG, "Found wallpaper @" + pos);
+                return pos + 1;
+            }
+        }
+        return 0;
+    }
+
+    private final int reAddWindowLocked(int index, WindowState win) {
+        final WindowList windows = win.getWindowList();
+        final int NCW = win.mChildWindows.size();
+        boolean added = false;
+        for (int j=0; j<NCW; j++) {
+            WindowState cwin = win.mChildWindows.get(j);
+            if (!added && cwin.mSubLayer >= 0) {
+                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
+                        + index + ": " + cwin);
+                win.mRebuilding = false;
+                windows.add(index, win);
+                index++;
+                added = true;
+            }
+            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
+                    + index + ": " + cwin);
+            cwin.mRebuilding = false;
+            windows.add(index, cwin);
+            index++;
+        }
+        if (!added) {
+            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
+                    + index + ": " + win);
+            win.mRebuilding = false;
+            windows.add(index, win);
+            index++;
+        }
+        mWindowsChanged = true;
+        return index;
+    }
+
+    private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index,
+                                            WindowToken token) {
+        final int NW = token.windows.size();
+        for (int i=0; i<NW; i++) {
+            final WindowState win = token.windows.get(i);
+            final DisplayContent winDisplayContent = win.getDisplayContent();
+            if (winDisplayContent == displayContent || winDisplayContent == null) {
+                win.mDisplayContent = displayContent;
+                index = reAddWindowLocked(index, win);
+            }
+        }
+        return index;
+    }
+
+    void tmpRemoveTaskWindowsLocked(Task task) {
+        AppTokenList tokens = task.mAppTokens;
+        for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+            tmpRemoveAppWindowsLocked(tokens.get(tokenNdx));
+        }
+    }
+
+    void moveStackWindowsLocked(DisplayContent displayContent) {
+        // First remove all of the windows from the list.
+        final ArrayList<Task> tasks = displayContent.getTasks();
+        final int numTasks = tasks.size();
+        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
+            tmpRemoveTaskWindowsLocked(tasks.get(taskNdx));
+        }
+
+        // And now add them back at the correct place.
+        // Where to start adding?
+        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
+            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+            int pos = findAppWindowInsertionPointLocked(tokens.get(0));
+            final int numTokens = tokens.size();
+            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
+                final AppWindowToken wtoken = tokens.get(tokenNdx);
+                if (wtoken != null) {
+                    final int newPos = reAddAppWindowsLocked(displayContent, pos, wtoken);
+                    if (newPos != pos) {
+                        displayContent.layoutNeeded = true;
+                    }
+                    pos = newPos;
+                }
+            }
+        }
+
+        if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                false /*updateInputWindows*/)) {
+            assignLayersLocked(displayContent.getWindowList());
+        }
+
+        mInputMonitor.setUpdateInputWindowsNeededLw();
+        performLayoutAndPlaceSurfacesLocked();
+        mInputMonitor.updateInputWindowsLw(false /*force*/);
+
+        //dump();
+    }
+
+    public void moveTaskToTop(int taskId) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                Task task = mTaskIdToTask.get(taskId);
+                if (task == null) {
+                    // Normal behavior, addAppToken will be called next and task will be created.
+                    return;
+                }
+                final TaskStack stack = task.mStack;
+                final DisplayContent displayContent = task.getDisplayContent();
+                displayContent.moveStack(stack, true);
+                if (displayContent.isDefaultDisplay) {
+                    final TaskStack homeStack = displayContent.getHomeStack();
+                    if (homeStack != stack) {
+                        // When a non-home stack moves to the top, the home stack moves to the
+                        // bottom.
+                        displayContent.moveStack(homeStack, false);
+                    }
+                }
+                stack.moveTaskToTop(task);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    public void moveTaskToBottom(int taskId) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                Task task = mTaskIdToTask.get(taskId);
+                if (task == null) {
+                    Slog.e(TAG, "moveTaskToBottom: taskId=" + taskId
+                            + " not found in mTaskIdToTask");
+                    return;
+                }
+                final TaskStack stack = task.mStack;
+                stack.moveTaskToBottom(task);
+                moveStackWindowsLocked(stack.getDisplayContent());
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    /**
+     * Create a new TaskStack and place it on a DisplayContent.
+     * @param stackId The unique identifier of the new stack.
+     * @param displayId The unique identifier of the DisplayContent.
+     */
+    public void attachStack(int stackId, int displayId) {
+        final long origId = Binder.clearCallingIdentity();
+        try {
+            synchronized (mWindowMap) {
+                final DisplayContent displayContent = mDisplayContents.get(displayId);
+                if (displayContent != null) {
+                    TaskStack stack = mStackIdToStack.get(stackId);
+                    if (stack == null) {
+                        if (DEBUG_STACK) Slog.d(TAG, "attachStack: stackId=" + stackId);
+                        stack = new TaskStack(this, stackId);
+                        mStackIdToStack.put(stackId, stack);
+                    }
+                    stack.attachDisplayContent(displayContent);
+                    displayContent.attachStack(stack);
+                    moveStackWindowsLocked(displayContent);
+                    final WindowList windows = displayContent.getWindowList();
+                    for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
+                        windows.get(winNdx).reportResized();
+                    }
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+    }
+
+    void detachStackLocked(DisplayContent displayContent, TaskStack stack) {
+        displayContent.detachStack(stack);
+        stack.detachDisplay();
+    }
+
+    public void detachStack(int stackId) {
+        synchronized (mWindowMap) {
+            TaskStack stack = mStackIdToStack.get(stackId);
+            if (stack != null) {
+                final DisplayContent displayContent = stack.getDisplayContent();
+                if (displayContent != null) {
+                    if (stack.isAnimating()) {
+                        stack.mDeferDetach = true;
+                        return;
+                    }
+                    detachStackLocked(displayContent, stack);
+                }
+            }
+        }
+    }
+
+    public void removeStack(int stackId) {
+        mStackIdToStack.remove(stackId);
+    }
+
+    void removeTaskLocked(Task task) {
+        final int taskId = task.taskId;
+        final TaskStack stack = task.mStack;
+        if (stack.isAnimating()) {
+            if (DEBUG_STACK) Slog.i(TAG, "removeTask: deferring removing taskId=" + taskId);
+            task.mDeferRemoval = true;
+            return;
+        }
+        if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing taskId=" + taskId);
+        EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, taskId, "removeTask");
+        task.mDeferRemoval = false;
+        task.mStack.removeTask(task);
+        mTaskIdToTask.delete(task.taskId);
+    }
+
+    public void removeTask(int taskId) {
+        synchronized (mWindowMap) {
+            Task task = mTaskIdToTask.get(taskId);
+            if (task == null) {
+                if (DEBUG_STACK) Slog.i(TAG, "removeTask: could not find taskId=" + taskId);
+                return;
+            }
+            removeTaskLocked(task);
+        }
+    }
+
+    public void addTask(int taskId, int stackId, boolean toTop) {
+        synchronized (mWindowMap) {
+            if (DEBUG_STACK) Slog.i(TAG, "addTask: adding taskId=" + taskId
+                    + " to " + (toTop ? "top" : "bottom"));
+            Task task = mTaskIdToTask.get(taskId);
+            if (task == null) {
+                return;
+            }
+            TaskStack stack = mStackIdToStack.get(stackId);
+            stack.addTask(task, toTop);
+            final DisplayContent displayContent = stack.getDisplayContent();
+            displayContent.layoutNeeded = true;
+            performLayoutAndPlaceSurfacesLocked();
+        }
+    }
+
+    public void resizeStack(int stackId, Rect bounds) {
+        synchronized (mWindowMap) {
+            final TaskStack stack = mStackIdToStack.get(stackId);
+            if (stack == null) {
+                throw new IllegalArgumentException("resizeStack: stackId " + stackId
+                        + " not found.");
+            }
+            if (stack.setBounds(bounds)) {
+                stack.resizeWindows();
+                stack.getDisplayContent().layoutNeeded = true;
+                performLayoutAndPlaceSurfacesLocked();
+            }
+        }
+    }
+
+    public void getStackBounds(int stackId, Rect bounds) {
+        final TaskStack stack = mStackIdToStack.get(stackId);
+        if (stack != null) {
+            stack.getBounds(bounds);
+            return;
+        }
+        bounds.setEmpty();
+    }
+
+    // -------------------------------------------------------------
+    // Misc IWindowSession methods
+    // -------------------------------------------------------------
+
+    @Override
+    public void startFreezingScreen(int exitAnim, int enterAnim) {
+        if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN,
+                "startFreezingScreen()")) {
+            throw new SecurityException("Requires FREEZE_SCREEN permission");
+        }
+
+        synchronized(mWindowMap) {
+            if (!mClientFreezingScreen) {
+                mClientFreezingScreen = true;
+                final long origId = Binder.clearCallingIdentity();
+                try {
+                    startFreezingDisplayLocked(false, exitAnim, enterAnim);
+                    mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT);
+                    mH.sendEmptyMessageDelayed(H.CLIENT_FREEZE_TIMEOUT, 5000);
+                } finally {
+                    Binder.restoreCallingIdentity(origId);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void stopFreezingScreen() {
+        if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN,
+                "stopFreezingScreen()")) {
+            throw new SecurityException("Requires FREEZE_SCREEN permission");
+        }
+
+        synchronized(mWindowMap) {
+            if (mClientFreezingScreen) {
+                mClientFreezingScreen = false;
+                mLastFinishedFreezeSource = "client";
+                final long origId = Binder.clearCallingIdentity();
+                try {
+                    stopFreezingDisplayLocked();
+                } finally {
+                    Binder.restoreCallingIdentity(origId);
+                }
+            }
+        }
+    }
+
+    @Override
+    public void disableKeyguard(IBinder token, String tag) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
+            != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
+        }
+
+        mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage(
+                KeyguardDisableHandler.KEYGUARD_DISABLE, new Pair<IBinder, String>(token, tag)));
+    }
+
+    @Override
+    public void reenableKeyguard(IBinder token) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
+            != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
+        }
+
+        mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage(
+                KeyguardDisableHandler.KEYGUARD_REENABLE, token));
+    }
+
+    /**
+     * @see android.app.KeyguardManager#exitKeyguardSecurely
+     */
+    @Override
+    public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
+            != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
+        }
+        mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
+            @Override
+            public void onKeyguardExitResult(boolean success) {
+                try {
+                    callback.onKeyguardExitResult(success);
+                } catch (RemoteException e) {
+                    // Client has died, we don't care.
+                }
+            }
+        });
+    }
+
+    @Override
+    public boolean inKeyguardRestrictedInputMode() {
+        return mPolicy.inKeyguardRestrictedKeyInputMode();
+    }
+
+    @Override
+    public boolean isKeyguardLocked() {
+        return mPolicy.isKeyguardLocked();
+    }
+
+    @Override
+    public boolean isKeyguardSecure() {
+        return mPolicy.isKeyguardSecure();
+    }
+
+    @Override
+    public void dismissKeyguard() {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
+        }
+        synchronized(mWindowMap) {
+            mPolicy.dismissKeyguardLw();
+        }
+    }
+
+    @Override
+    public void closeSystemDialogs(String reason) {
+        synchronized(mWindowMap) {
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+                final int numWindows = windows.size();
+                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                    final WindowState w = windows.get(winNdx);
+                    if (w.mHasSurface) {
+                        try {
+                            w.mClient.closeSystemDialogs(reason);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    static float fixScale(float scale) {
+        if (scale < 0) scale = 0;
+        else if (scale > 20) scale = 20;
+        return Math.abs(scale);
+    }
+
+    @Override
+    public void setAnimationScale(int which, float scale) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
+                "setAnimationScale()")) {
+            throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
+        }
+
+        scale = fixScale(scale);
+        switch (which) {
+            case 0: mWindowAnimationScale = scale; break;
+            case 1: mTransitionAnimationScale = scale; break;
+            case 2: mAnimatorDurationScale = scale; break;
+        }
+
+        // Persist setting
+        mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE);
+    }
+
+    @Override
+    public void setAnimationScales(float[] scales) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
+                "setAnimationScale()")) {
+            throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
+        }
+
+        if (scales != null) {
+            if (scales.length >= 1) {
+                mWindowAnimationScale = fixScale(scales[0]);
+            }
+            if (scales.length >= 2) {
+                mTransitionAnimationScale = fixScale(scales[1]);
+            }
+            if (scales.length >= 3) {
+                setAnimatorDurationScale(fixScale(scales[2]));
+            }
+        }
+
+        // Persist setting
+        mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE);
+    }
+
+    private void setAnimatorDurationScale(float scale) {
+        mAnimatorDurationScale = scale;
+        ValueAnimator.setDurationScale(scale);
+    }
+
+    @Override
+    public float getAnimationScale(int which) {
+        switch (which) {
+            case 0: return mWindowAnimationScale;
+            case 1: return mTransitionAnimationScale;
+            case 2: return mAnimatorDurationScale;
+        }
+        return 0;
+    }
+
+    @Override
+    public float[] getAnimationScales() {
+        return new float[] { mWindowAnimationScale, mTransitionAnimationScale,
+                mAnimatorDurationScale };
+    }
+
+    @Override
+    public void registerPointerEventListener(PointerEventListener listener) {
+        mPointerEventDispatcher.registerInputEventListener(listener);
+    }
+
+    @Override
+    public void unregisterPointerEventListener(PointerEventListener listener) {
+        mPointerEventDispatcher.unregisterInputEventListener(listener);
+    }
+
+    // Called by window manager policy. Not exposed externally.
+    @Override
+    public int getLidState() {
+        int sw = mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY,
+                InputManagerService.SW_LID);
+        if (sw > 0) {
+            // Switch state: AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL.
+            return LID_CLOSED;
+        } else if (sw == 0) {
+            // Switch state: AKEY_STATE_UP.
+            return LID_OPEN;
+        } else {
+            // Switch state: AKEY_STATE_UNKNOWN.
+            return LID_ABSENT;
+        }
+    }
+
+    // Called by window manager policy.  Not exposed externally.
+    @Override
+    public void switchKeyboardLayout(int deviceId, int direction) {
+        mInputManager.switchKeyboardLayout(deviceId, direction);
+    }
+
+    // Called by window manager policy.  Not exposed externally.
+    @Override
+    public void shutdown(boolean confirm) {
+        ShutdownThread.shutdown(mContext, confirm);
+    }
+
+    // Called by window manager policy.  Not exposed externally.
+    @Override
+    public void rebootSafeMode(boolean confirm) {
+        ShutdownThread.rebootSafeMode(mContext, confirm);
+    }
+
+    @Override
+    public void setInputFilter(IInputFilter filter) {
+        if (!checkCallingPermission(android.Manifest.permission.FILTER_EVENTS, "setInputFilter()")) {
+            throw new SecurityException("Requires FILTER_EVENTS permission");
+        }
+        mInputManager.setInputFilter(filter);
+    }
+
+    @Override
+    public void setTouchExplorationEnabled(boolean enabled) {
+        mPolicy.setTouchExplorationEnabled(enabled);
+    }
+
+    public void setCurrentUser(final int newUserId) {
+        synchronized (mWindowMap) {
+            int oldUserId = mCurrentUserId;
+            mCurrentUserId = newUserId;
+            mAppTransition.setCurrentUser(newUserId);
+            mPolicy.setCurrentUserLw(newUserId);
+
+            // Hide windows that should not be seen by the new user.
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+                displayContent.switchUserStacks(newUserId);
+                rebuildAppWindowListLocked(displayContent);
+            }
+            performLayoutAndPlaceSurfacesLocked();
+        }
+    }
+
+    public void enableScreenAfterBoot() {
+        synchronized(mWindowMap) {
+            if (DEBUG_BOOT) {
+                RuntimeException here = new RuntimeException("here");
+                here.fillInStackTrace();
+                Slog.i(TAG, "enableScreenAfterBoot: mDisplayEnabled=" + mDisplayEnabled
+                        + " mForceDisplayEnabled=" + mForceDisplayEnabled
+                        + " mShowingBootMessages=" + mShowingBootMessages
+                        + " mSystemBooted=" + mSystemBooted, here);
+            }
+            if (mSystemBooted) {
+                return;
+            }
+            mSystemBooted = true;
+            hideBootMessagesLocked();
+            // If the screen still doesn't come up after 30 seconds, give
+            // up and turn it on.
+            mH.sendEmptyMessageDelayed(H.BOOT_TIMEOUT, 30*1000);
+        }
+
+        mPolicy.systemBooted();
+
+        performEnableScreen();
+    }
+
+    void enableScreenIfNeededLocked() {
+        if (DEBUG_BOOT) {
+            RuntimeException here = new RuntimeException("here");
+            here.fillInStackTrace();
+            Slog.i(TAG, "enableScreenIfNeededLocked: mDisplayEnabled=" + mDisplayEnabled
+                    + " mForceDisplayEnabled=" + mForceDisplayEnabled
+                    + " mShowingBootMessages=" + mShowingBootMessages
+                    + " mSystemBooted=" + mSystemBooted, here);
+        }
+        if (mDisplayEnabled) {
+            return;
+        }
+        if (!mSystemBooted && !mShowingBootMessages) {
+            return;
+        }
+        mH.sendEmptyMessage(H.ENABLE_SCREEN);
+    }
+
+    public void performBootTimeout() {
+        synchronized(mWindowMap) {
+            if (mDisplayEnabled) {
+                return;
+            }
+            Slog.w(TAG, "***** BOOT TIMEOUT: forcing display enabled");
+            mForceDisplayEnabled = true;
+        }
+        performEnableScreen();
+    }
+
+    public void performEnableScreen() {
+        synchronized(mWindowMap) {
+            if (DEBUG_BOOT) {
+                RuntimeException here = new RuntimeException("here");
+                here.fillInStackTrace();
+                Slog.i(TAG, "performEnableScreen: mDisplayEnabled=" + mDisplayEnabled
+                        + " mForceDisplayEnabled=" + mForceDisplayEnabled
+                        + " mShowingBootMessages=" + mShowingBootMessages
+                        + " mSystemBooted=" + mSystemBooted
+                        + " mOnlyCore=" + mOnlyCore, here);
+            }
+            if (mDisplayEnabled) {
+                return;
+            }
+            if (!mSystemBooted && !mShowingBootMessages) {
+                return;
+            }
+
+            if (!mForceDisplayEnabled) {
+                // Don't enable the screen until all existing windows
+                // have been drawn.
+                boolean haveBootMsg = false;
+                boolean haveApp = false;
+                // if the wallpaper service is disabled on the device, we're never going to have
+                // wallpaper, don't bother waiting for it
+                boolean haveWallpaper = false;
+                boolean wallpaperEnabled = mContext.getResources().getBoolean(
+                        com.android.internal.R.bool.config_enableWallpaperService)
+                        && !mOnlyCore;
+                boolean haveKeyguard = true;
+                // TODO(multidisplay): Expand to all displays?
+                final WindowList windows = getDefaultWindowListLocked();
+                final int N = windows.size();
+                for (int i=0; i<N; i++) {
+                    WindowState w = windows.get(i);
+                    if (w.mAttrs.type == TYPE_KEYGUARD) {
+                        // Only if there is a keyguard attached to the window manager
+                        // will we consider ourselves as having a keyguard.  If it
+                        // isn't attached, we don't know if it wants to be shown or
+                        // hidden.  If it is attached, we will say we have a keyguard
+                        // if the window doesn't want to be visible, because in that
+                        // case it explicitly doesn't want to be shown so we should
+                        // not delay turning the screen on for it.
+                        boolean vis = w.mViewVisibility == View.VISIBLE
+                                && w.mPolicyVisibility;
+                        haveKeyguard = !vis;
+                    }
+                    if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
+                        return;
+                    }
+                    if (w.isDrawnLw()) {
+                        if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
+                            haveBootMsg = true;
+                        } else if (w.mAttrs.type == TYPE_APPLICATION) {
+                            haveApp = true;
+                        } else if (w.mAttrs.type == TYPE_WALLPAPER) {
+                            haveWallpaper = true;
+                        } else if (w.mAttrs.type == TYPE_KEYGUARD) {
+                            haveKeyguard = true;
+                        }
+                    }
+                }
+
+                if (DEBUG_SCREEN_ON || DEBUG_BOOT) {
+                    Slog.i(TAG, "******** booted=" + mSystemBooted + " msg=" + mShowingBootMessages
+                            + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
+                            + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled
+                            + " haveKeyguard=" + haveKeyguard);
+                }
+
+                // If we are turning on the screen to show the boot message,
+                // don't do it until the boot message is actually displayed.
+                if (!mSystemBooted && !haveBootMsg) {
+                    return;
+                }
+
+                // If we are turning on the screen after the boot is completed
+                // normally, don't do so until we have the application and
+                // wallpaper.
+                if (mSystemBooted && ((!haveApp && !haveKeyguard) ||
+                        (wallpaperEnabled && !haveWallpaper))) {
+                    return;
+                }
+            }
+
+            mDisplayEnabled = true;
+            if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG, "******************** ENABLING SCREEN!");
+            if (false) {
+                StringWriter sw = new StringWriter();
+                PrintWriter pw = new FastPrintWriter(sw, false, 1024);
+                this.dump(null, pw, null);
+                pw.flush();
+                Slog.i(TAG, sw.toString());
+            }
+            try {
+                IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
+                if (surfaceFlinger != null) {
+                    //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
+                    Parcel data = Parcel.obtain();
+                    data.writeInterfaceToken("android.ui.ISurfaceComposer");
+                    surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED
+                                            data, null, 0);
+                    data.recycle();
+                }
+            } catch (RemoteException ex) {
+                Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
+            }
+
+            // Enable input dispatch.
+            mInputMonitor.setEventDispatchingLw(mEventDispatchingEnabled);
+        }
+
+        mPolicy.enableScreenAfterBoot();
+
+        // Make sure the last requested orientation has been applied.
+        updateRotationUnchecked(false, false);
+    }
+
+    public void showBootMessage(final CharSequence msg, final boolean always) {
+        boolean first = false;
+        synchronized(mWindowMap) {
+            if (DEBUG_BOOT) {
+                RuntimeException here = new RuntimeException("here");
+                here.fillInStackTrace();
+                Slog.i(TAG, "showBootMessage: msg=" + msg + " always=" + always
+                        + " mAllowBootMessages=" + mAllowBootMessages
+                        + " mShowingBootMessages=" + mShowingBootMessages
+                        + " mSystemBooted=" + mSystemBooted, here);
+            }
+            if (!mAllowBootMessages) {
+                return;
+            }
+            if (!mShowingBootMessages) {
+                if (!always) {
+                    return;
+                }
+                first = true;
+            }
+            if (mSystemBooted) {
+                return;
+            }
+            mShowingBootMessages = true;
+            mPolicy.showBootMessage(msg, always);
+        }
+        if (first) {
+            performEnableScreen();
+        }
+    }
+
+    public void hideBootMessagesLocked() {
+        if (DEBUG_BOOT) {
+            RuntimeException here = new RuntimeException("here");
+            here.fillInStackTrace();
+            Slog.i(TAG, "hideBootMessagesLocked: mDisplayEnabled=" + mDisplayEnabled
+                    + " mForceDisplayEnabled=" + mForceDisplayEnabled
+                    + " mShowingBootMessages=" + mShowingBootMessages
+                    + " mSystemBooted=" + mSystemBooted, here);
+        }
+        if (mShowingBootMessages) {
+            mShowingBootMessages = false;
+            mPolicy.hideBootMessages();
+        }
+    }
+
+    @Override
+    public void setInTouchMode(boolean mode) {
+        synchronized(mWindowMap) {
+            mInTouchMode = mode;
+        }
+    }
+
+    // TODO: more accounting of which pid(s) turned it on, keep count,
+    // only allow disables from pids which have count on, etc.
+    @Override
+    public void showStrictModeViolation(boolean on) {
+        int pid = Binder.getCallingPid();
+        mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, on ? 1 : 0, pid));
+    }
+
+    private void showStrictModeViolation(int arg, int pid) {
+        final boolean on = arg != 0;
+        synchronized(mWindowMap) {
+            // Ignoring requests to enable the red border from clients
+            // which aren't on screen.  (e.g. Broadcast Receivers in
+            // the background..)
+            if (on) {
+                boolean isVisible = false;
+                final int numDisplays = mDisplayContents.size();
+                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                    final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+                    final int numWindows = windows.size();
+                    for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                        final WindowState ws = windows.get(winNdx);
+                        if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
+                            isVisible = true;
+                            break;
+                        }
+                    }
+                }
+                if (!isVisible) {
+                    return;
+                }
+            }
+
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                    ">>> OPEN TRANSACTION showStrictModeViolation");
+            SurfaceControl.openTransaction();
+            try {
+                // TODO(multi-display): support multiple displays
+                if (mStrictModeFlash == null) {
+                    mStrictModeFlash = new StrictModeFlash(
+                            getDefaultDisplayContentLocked().getDisplay(), mFxSession);
+                }
+                mStrictModeFlash.setVisibility(on);
+            } finally {
+                SurfaceControl.closeTransaction();
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                        "<<< CLOSE TRANSACTION showStrictModeViolation");
+            }
+        }
+    }
+
+    @Override
+    public void setStrictModeVisualIndicatorPreference(String value) {
+        SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
+    }
+
+    /**
+     * Takes a snapshot of the screen.  In landscape mode this grabs the whole screen.
+     * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
+     * of the target image.
+     *
+     * @param displayId the Display to take a screenshot of.
+     * @param width the width of the target bitmap
+     * @param height the height of the target bitmap
+     * @param force565 if true the returned bitmap will be RGB_565, otherwise it
+     *                 will be the same config as the surface
+     */
+    @Override
+    public Bitmap screenshotApplications(IBinder appToken, int displayId, int width,
+            int height, boolean force565) {
+        if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
+                "screenshotApplications()")) {
+            throw new SecurityException("Requires READ_FRAME_BUFFER permission");
+        }
+
+        Bitmap rawss = null;
+
+        int maxLayer = 0;
+        final Rect frame = new Rect();
+
+        float scale = 0;
+        int dw, dh;
+        int rot = Surface.ROTATION_0;
+
+        boolean screenshotReady;
+        int minLayer;
+        if (appToken == null) {
+            screenshotReady = true;
+            minLayer = 0;
+        } else {
+            screenshotReady = false;
+            minLayer = Integer.MAX_VALUE;
+        }
+
+        int retryCount = 0;
+        WindowState appWin = null;
+
+        do {
+            if (retryCount++ > 0) {
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                }
+            }
+            synchronized(mWindowMap) {
+                final DisplayContent displayContent = getDisplayContentLocked(displayId);
+                if (displayContent == null) {
+                    return null;
+                }
+                final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+                dw = displayInfo.logicalWidth;
+                dh = displayInfo.logicalHeight;
+
+                int aboveAppLayer = mPolicy.windowTypeToLayerLw(TYPE_APPLICATION)
+                        * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
+                aboveAppLayer += TYPE_LAYER_MULTIPLIER;
+
+                boolean isImeTarget = mInputMethodTarget != null
+                        && mInputMethodTarget.mAppToken != null
+                        && mInputMethodTarget.mAppToken.appToken != null
+                        && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
+
+                // Figure out the part of the screen that is actually the app.
+                boolean including = false;
+                appWin = null;
+                final WindowList windows = displayContent.getWindowList();
+                final Rect stackBounds = new Rect();
+                for (int i = windows.size() - 1; i >= 0; i--) {
+                    WindowState ws = windows.get(i);
+                    if (!ws.mHasSurface) {
+                        continue;
+                    }
+                    if (ws.mLayer >= aboveAppLayer) {
+                        continue;
+                    }
+                    // When we will skip windows: when we are not including
+                    // ones behind a window we didn't skip, and we are actually
+                    // taking a screenshot of a specific app.
+                    if (!including && appToken != null) {
+                        // Also, we can possibly skip this window if it is not
+                        // an IME target or the application for the screenshot
+                        // is not the current IME target.
+                        if (!ws.mIsImWindow || !isImeTarget) {
+                            // And finally, this window is of no interest if it
+                            // is not associated with the screenshot app.
+                            if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
+                                continue;
+                            }
+                            appWin = ws;
+                            ws.getStackBounds(stackBounds);
+                        }
+                    }
+
+                    // We keep on including windows until we go past a full-screen
+                    // window.
+                    including = !ws.mIsImWindow && !ws.isFullscreen(dw, dh);
+
+                    final WindowStateAnimator winAnim = ws.mWinAnimator;
+                    if (maxLayer < winAnim.mSurfaceLayer) {
+                        maxLayer = winAnim.mSurfaceLayer;
+                    }
+                    if (minLayer > winAnim.mSurfaceLayer) {
+                        minLayer = winAnim.mSurfaceLayer;
+                    }
+
+                    // Don't include wallpaper in bounds calculation
+                    if (!ws.mIsWallpaper) {
+                        final Rect wf = ws.mFrame;
+                        final Rect cr = ws.mContentInsets;
+                        int left = wf.left + cr.left;
+                        int top = wf.top + cr.top;
+                        int right = wf.right - cr.right;
+                        int bottom = wf.bottom - cr.bottom;
+                        frame.union(left, top, right, bottom);
+                        frame.intersect(stackBounds);
+                    }
+
+                    if (ws.mAppToken != null && ws.mAppToken.token == appToken &&
+                            ws.isDisplayedLw()) {
+                        screenshotReady = true;
+                    }
+                }
+
+                if (appToken != null && appWin == null) {
+                    // Can't find a window to snapshot.
+                    if (DEBUG_SCREENSHOT) Slog.i(TAG,
+                            "Screenshot: Couldn't find a surface matching " + appToken);
+                    return null;
+                }
+                if (!screenshotReady) {
+                    // Delay and hope that window gets drawn.
+                    if (DEBUG_SCREENSHOT) Slog.i(TAG, "Screenshot: No image ready for " + appToken
+                            + ", " + appWin + " drawState=" + appWin.mWinAnimator.mDrawState);
+                    continue;
+                }
+
+                // Constrain frame to the screen size.
+                frame.intersect(0, 0, dw, dh);
+
+                if (frame.isEmpty() || maxLayer == 0) {
+                    if (DEBUG_SCREENSHOT) Slog.i(TAG, "Screenshot of " + appToken
+                            + ": returning null frame=" + frame.toShortString() + " maxLayer="
+                            + maxLayer);
+                    return null;
+                }
+
+                // The screenshot API does not apply the current screen rotation.
+                rot = getDefaultDisplayContentLocked().getDisplay().getRotation();
+                int fw = frame.width();
+                int fh = frame.height();
+
+                // Constrain thumbnail to smaller of screen width or height. Assumes aspect
+                // of thumbnail is the same as the screen (in landscape) or square.
+                scale = Math.max(width / (float) fw, height / (float) fh);
+                /*
+                float targetWidthScale = width / (float) fw;
+                float targetHeightScale = height / (float) fh;
+                if (fw <= fh) {
+                    scale = targetWidthScale;
+                    // If aspect of thumbnail is the same as the screen (in landscape),
+                    // select the slightly larger value so we fill the entire bitmap
+                    if (targetHeightScale > scale && (int) (targetHeightScale * fw) == width) {
+                        scale = targetHeightScale;
+                    }
+                } else {
+                    scale = targetHeightScale;
+                    // If aspect of thumbnail is the same as the screen (in landscape),
+                    // select the slightly larger value so we fill the entire bitmap
+                    if (targetWidthScale > scale && (int) (targetWidthScale * fh) == height) {
+                        scale = targetWidthScale;
+                    }
+                }
+                */
+
+                // The screen shot will contain the entire screen.
+                dw = (int)(dw*scale);
+                dh = (int)(dh*scale);
+                if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
+                    int tmp = dw;
+                    dw = dh;
+                    dh = tmp;
+                    rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
+                }
+                if (DEBUG_SCREENSHOT) {
+                    Slog.i(TAG, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
+                            + maxLayer + " appToken=" + appToken);
+                    for (int i = 0; i < windows.size(); i++) {
+                        WindowState win = windows.get(i);
+                        Slog.i(TAG, win + ": " + win.mLayer
+                                + " animLayer=" + win.mWinAnimator.mAnimLayer
+                                + " surfaceLayer=" + win.mWinAnimator.mSurfaceLayer);
+                    }
+                }
+                rawss = SurfaceControl.screenshot(dw, dh, minLayer, maxLayer);
+            }
+        } while (!screenshotReady && retryCount <= MAX_SCREENSHOT_RETRIES);
+        if (retryCount > MAX_SCREENSHOT_RETRIES)  Slog.i(TAG, "Screenshot max retries " +
+                retryCount + " of " + appToken + " appWin=" + (appWin == null ?
+                        "null" : (appWin + " drawState=" + appWin.mWinAnimator.mDrawState)));
+
+        if (rawss == null) {
+            Slog.w(TAG, "Screenshot failure taking screenshot for (" + dw + "x" + dh
+                    + ") to layer " + maxLayer);
+            return null;
+        }
+
+        Bitmap bm = Bitmap.createBitmap(width, height, force565 ? Config.RGB_565 : rawss.getConfig());
+        frame.scale(scale);
+        Matrix matrix = new Matrix();
+        ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
+        // TODO: Test for RTL vs. LTR and use frame.right-width instead of -frame.left
+        matrix.postTranslate(-FloatMath.ceil(frame.left), -FloatMath.ceil(frame.top));
+        Canvas canvas = new Canvas(bm);
+        canvas.drawColor(0xFF000000);
+        canvas.drawBitmap(rawss, matrix, null);
+        canvas.setBitmap(null);
+
+        if (DEBUG_SCREENSHOT) {
+            // TEST IF IT's ALL BLACK
+            int[] buffer = new int[bm.getWidth() * bm.getHeight()];
+            bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
+            boolean allBlack = true;
+            final int firstColor = buffer[0];
+            for (int i = 0; i < buffer.length; i++) {
+                if (buffer[i] != firstColor) {
+                    allBlack = false;
+                    break;
+                }
+            }
+            if (allBlack) {
+                Slog.i(TAG, "Screenshot " + appWin + " was monochrome(" +
+                        Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
+                        (appWin != null ? appWin.mWinAnimator.mSurfaceLayer : "null") +
+                        " minLayer=" + minLayer + " maxLayer=" + maxLayer);
+            }
+        }
+
+        rawss.recycle();
+        return bm;
+    }
+
+    /**
+     * Freeze rotation changes.  (Enable "rotation lock".)
+     * Persists across reboots.
+     * @param rotation The desired rotation to freeze to, or -1 to use the
+     * current rotation.
+     */
+    @Override
+    public void freezeRotation(int rotation) {
+        if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
+                "freezeRotation()")) {
+            throw new SecurityException("Requires SET_ORIENTATION permission");
+        }
+        if (rotation < -1 || rotation > Surface.ROTATION_270) {
+            throw new IllegalArgumentException("Rotation argument must be -1 or a valid "
+                    + "rotation constant.");
+        }
+
+        if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation);
+
+        long origId = Binder.clearCallingIdentity();
+        try {
+            mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED,
+                    rotation == -1 ? mRotation : rotation);
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+
+        updateRotationUnchecked(false, false);
+    }
+
+    /**
+     * Thaw rotation changes.  (Disable "rotation lock".)
+     * Persists across reboots.
+     */
+    @Override
+    public void thawRotation() {
+        if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
+                "thawRotation()")) {
+            throw new SecurityException("Requires SET_ORIENTATION permission");
+        }
+
+        if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation);
+
+        long origId = Binder.clearCallingIdentity();
+        try {
+            mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE,
+                    777); // rot not used
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+
+        updateRotationUnchecked(false, false);
+    }
+
+    /**
+     * Recalculate the current rotation.
+     *
+     * Called by the window manager policy whenever the state of the system changes
+     * such that the current rotation might need to be updated, such as when the
+     * device is docked or rotated into a new posture.
+     */
+    @Override
+    public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
+        updateRotationUnchecked(alwaysSendConfiguration, forceRelayout);
+    }
+
+    /**
+     * Temporarily pauses rotation changes until resumed.
+     *
+     * This can be used to prevent rotation changes from occurring while the user is
+     * performing certain operations, such as drag and drop.
+     *
+     * This call nests and must be matched by an equal number of calls to
+     * {@link #resumeRotationLocked}.
+     */
+    void pauseRotationLocked() {
+        mDeferredRotationPauseCount += 1;
+    }
+
+    /**
+     * Resumes normal rotation changes after being paused.
+     */
+    void resumeRotationLocked() {
+        if (mDeferredRotationPauseCount > 0) {
+            mDeferredRotationPauseCount -= 1;
+            if (mDeferredRotationPauseCount == 0) {
+                boolean changed = updateRotationUncheckedLocked(false);
+                if (changed) {
+                    mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+                }
+            }
+        }
+    }
+
+    public void updateRotationUnchecked(boolean alwaysSendConfiguration, boolean forceRelayout) {
+        if(DEBUG_ORIENTATION) Slog.v(TAG, "updateRotationUnchecked("
+                   + "alwaysSendConfiguration=" + alwaysSendConfiguration + ")");
+
+        long origId = Binder.clearCallingIdentity();
+        boolean changed;
+        synchronized(mWindowMap) {
+            changed = updateRotationUncheckedLocked(false);
+            if (!changed || forceRelayout) {
+                getDefaultDisplayContentLocked().layoutNeeded = true;
+                performLayoutAndPlaceSurfacesLocked();
+            }
+        }
+
+        if (changed || alwaysSendConfiguration) {
+            sendNewConfiguration();
+        }
+
+        Binder.restoreCallingIdentity(origId);
+    }
+
+    // TODO(multidisplay): Rotate any display?
+    /**
+     * Updates the current rotation.
+     *
+     * Returns true if the rotation has been changed.  In this case YOU
+     * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN.
+     */
+    public boolean updateRotationUncheckedLocked(boolean inTransaction) {
+        if (mDeferredRotationPauseCount > 0) {
+            // Rotation updates have been paused temporarily.  Defer the update until
+            // updates have been resumed.
+            if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, rotation is paused.");
+            return false;
+        }
+
+        ScreenRotationAnimation screenRotationAnimation =
+                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
+        if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
+            // Rotation updates cannot be performed while the previous rotation change
+            // animation is still in progress.  Skip this update.  We will try updating
+            // again after the animation is finished and the display is unfrozen.
+            if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, animation in progress.");
+            return false;
+        }
+
+        if (!mDisplayEnabled) {
+            // No point choosing a rotation if the display is not enabled.
+            if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, display is not enabled.");
+            return false;
+        }
+
+        // TODO: Implement forced rotation changes.
+        //       Set mAltOrientation to indicate that the application is receiving
+        //       an orientation that has different metrics than it expected.
+        //       eg. Portrait instead of Landscape.
+
+        int rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation);
+        boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw(
+                mForcedAppOrientation, rotation);
+
+        if (DEBUG_ORIENTATION) {
+            Slog.v(TAG, "Application requested orientation "
+                    + mForcedAppOrientation + ", got rotation " + rotation
+                    + " which has " + (altOrientation ? "incompatible" : "compatible")
+                    + " metrics");
+        }
+
+        if (mRotation == rotation && mAltOrientation == altOrientation) {
+            // No change.
+            return false;
+        }
+
+        if (DEBUG_ORIENTATION) {
+            Slog.v(TAG,
+                "Rotation changed to " + rotation + (altOrientation ? " (alt)" : "")
+                + " from " + mRotation + (mAltOrientation ? " (alt)" : "")
+                + ", forceApp=" + mForcedAppOrientation);
+        }
+
+        mRotation = rotation;
+        mAltOrientation = altOrientation;
+        mPolicy.setRotationLw(mRotation);
+
+        mWindowsFreezingScreen = true;
+        mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
+        mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT, WINDOW_FREEZE_TIMEOUT_DURATION);
+        mWaitingForConfig = true;
+        final DisplayContent displayContent = getDefaultDisplayContentLocked();
+        displayContent.layoutNeeded = true;
+        final int[] anim = new int[2];
+        if (displayContent.isDimming()) {
+            anim[0] = anim[1] = 0;
+        } else {
+            mPolicy.selectRotationAnimationLw(anim);
+        }
+        startFreezingDisplayLocked(inTransaction, anim[0], anim[1]);
+        // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
+        screenRotationAnimation =
+                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
+
+        // We need to update our screen size information to match the new
+        // rotation.  Note that this is redundant with the later call to
+        // sendNewConfiguration() that must be called after this function
+        // returns...  however we need to do the screen size part of that
+        // before then so we have the correct size to use when initializing
+        // the rotation animation for the new rotation.
+        computeScreenConfigurationLocked(null);
+
+        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        if (!inTransaction) {
+            if (SHOW_TRANSACTIONS) {
+                Slog.i(TAG, ">>> OPEN TRANSACTION setRotationUnchecked");
+            }
+            SurfaceControl.openTransaction();
+        }
+        try {
+            // NOTE: We disable the rotation in the emulator because
+            //       it doesn't support hardware OpenGL emulation yet.
+            if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
+                    && screenRotationAnimation.hasScreenshot()) {
+                if (screenRotationAnimation.setRotationInTransaction(
+                        rotation, mFxSession,
+                        MAX_ANIMATION_DURATION, mTransitionAnimationScale,
+                        displayInfo.logicalWidth, displayInfo.logicalHeight)) {
+                    scheduleAnimationLocked();
+                }
+            }
+
+            mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
+        } finally {
+            if (!inTransaction) {
+                SurfaceControl.closeTransaction();
+                if (SHOW_LIGHT_TRANSACTIONS) {
+                    Slog.i(TAG, "<<< CLOSE TRANSACTION setRotationUnchecked");
+                }
+            }
+        }
+
+        final WindowList windows = displayContent.getWindowList();
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            WindowState w = windows.get(i);
+            if (w.mHasSurface) {
+                if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w);
+                w.mOrientationChanging = true;
+                mInnerFields.mOrientationChangeComplete = false;
+            }
+            w.mLastFreezeDuration = 0;
+        }
+
+        for (int i=mRotationWatchers.size()-1; i>=0; i--) {
+            try {
+                mRotationWatchers.get(i).onRotationChanged(rotation);
+            } catch (RemoteException e) {
+            }
+        }
+
+        //TODO (multidisplay): Magnification is supported only for the default display.
+        if (mDisplayMagnifier != null
+                && displayContent.getDisplayId() == Display.DEFAULT_DISPLAY) {
+            mDisplayMagnifier.onRotationChangedLocked(getDefaultDisplayContentLocked(), rotation);
+        }
+
+        return true;
+    }
+
+    @Override
+    public int getRotation() {
+        return mRotation;
+    }
+
+    @Override
+    public boolean isRotationFrozen() {
+        return mPolicy.getUserRotationMode() == WindowManagerPolicy.USER_ROTATION_LOCKED;
+    }
+
+    @Override
+    public int watchRotation(IRotationWatcher watcher) {
+        final IBinder watcherBinder = watcher.asBinder();
+        IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
+            @Override
+            public void binderDied() {
+                synchronized (mWindowMap) {
+                    for (int i=0; i<mRotationWatchers.size(); i++) {
+                        if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
+                            IRotationWatcher removed = mRotationWatchers.remove(i);
+                            if (removed != null) {
+                                removed.asBinder().unlinkToDeath(this, 0);
+                            }
+                            i--;
+                        }
+                    }
+                }
+            }
+        };
+
+        synchronized (mWindowMap) {
+            try {
+                watcher.asBinder().linkToDeath(dr, 0);
+                mRotationWatchers.add(watcher);
+            } catch (RemoteException e) {
+                // Client died, no cleanup needed.
+            }
+
+            return mRotation;
+        }
+    }
+
+    @Override
+    public void removeRotationWatcher(IRotationWatcher watcher) {
+        final IBinder watcherBinder = watcher.asBinder();
+        synchronized (mWindowMap) {
+            for (int i=0; i<mRotationWatchers.size(); i++) {
+                if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
+                    mRotationWatchers.remove(i);
+                    i--;
+                }
+            }
+        }
+    }
+
+    /**
+     * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
+     * theme attribute) on devices that feature a physical options menu key attempt to position
+     * their menu panel window along the edge of the screen nearest the physical menu key.
+     * This lowers the travel distance between invoking the menu panel and selecting
+     * a menu option.
+     *
+     * This method helps control where that menu is placed. Its current implementation makes
+     * assumptions about the menu key and its relationship to the screen based on whether
+     * the device's natural orientation is portrait (width < height) or landscape.
+     *
+     * The menu key is assumed to be located along the bottom edge of natural-portrait
+     * devices and along the right edge of natural-landscape devices. If these assumptions
+     * do not hold for the target device, this method should be changed to reflect that.
+     *
+     * @return A {@link Gravity} value for placing the options menu window
+     */
+    @Override
+    public int getPreferredOptionsPanelGravity() {
+        synchronized (mWindowMap) {
+            final int rotation = getRotation();
+
+            // TODO(multidisplay): Assume that such devices physical keys are on the main screen.
+            final DisplayContent displayContent = getDefaultDisplayContentLocked();
+            if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) {
+                // On devices with a natural orientation of portrait
+                switch (rotation) {
+                    default:
+                    case Surface.ROTATION_0:
+                        return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
+                    case Surface.ROTATION_90:
+                        return Gravity.RIGHT | Gravity.BOTTOM;
+                    case Surface.ROTATION_180:
+                        return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
+                    case Surface.ROTATION_270:
+                        return Gravity.START | Gravity.BOTTOM;
+                }
+            }
+
+            // On devices with a natural orientation of landscape
+            switch (rotation) {
+                default:
+                case Surface.ROTATION_0:
+                    return Gravity.RIGHT | Gravity.BOTTOM;
+                case Surface.ROTATION_90:
+                    return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
+                case Surface.ROTATION_180:
+                    return Gravity.START | Gravity.BOTTOM;
+                case Surface.ROTATION_270:
+                    return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
+            }
+        }
+    }
+
+    /**
+     * Starts the view server on the specified port.
+     *
+     * @param port The port to listener to.
+     *
+     * @return True if the server was successfully started, false otherwise.
+     *
+     * @see com.android.server.wm.ViewServer
+     * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT
+     */
+    @Override
+    public boolean startViewServer(int port) {
+        if (isSystemSecure()) {
+            return false;
+        }
+
+        if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
+            return false;
+        }
+
+        if (port < 1024) {
+            return false;
+        }
+
+        if (mViewServer != null) {
+            if (!mViewServer.isRunning()) {
+                try {
+                    return mViewServer.start();
+                } catch (IOException e) {
+                    Slog.w(TAG, "View server did not start");
+                }
+            }
+            return false;
+        }
+
+        try {
+            mViewServer = new ViewServer(this, port);
+            return mViewServer.start();
+        } catch (IOException e) {
+            Slog.w(TAG, "View server did not start");
+        }
+        return false;
+    }
+
+    private boolean isSystemSecure() {
+        return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
+                "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
+    }
+
+    /**
+     * Stops the view server if it exists.
+     *
+     * @return True if the server stopped, false if it wasn't started or
+     *         couldn't be stopped.
+     *
+     * @see com.android.server.wm.ViewServer
+     */
+    @Override
+    public boolean stopViewServer() {
+        if (isSystemSecure()) {
+            return false;
+        }
+
+        if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
+            return false;
+        }
+
+        if (mViewServer != null) {
+            return mViewServer.stop();
+        }
+        return false;
+    }
+
+    /**
+     * Indicates whether the view server is running.
+     *
+     * @return True if the server is running, false otherwise.
+     *
+     * @see com.android.server.wm.ViewServer
+     */
+    @Override
+    public boolean isViewServerRunning() {
+        if (isSystemSecure()) {
+            return false;
+        }
+
+        if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
+            return false;
+        }
+
+        return mViewServer != null && mViewServer.isRunning();
+    }
+
+    /**
+     * Lists all availble windows in the system. The listing is written in the
+     * specified Socket's output stream with the following syntax:
+     * windowHashCodeInHexadecimal windowName
+     * Each line of the ouput represents a different window.
+     *
+     * @param client The remote client to send the listing to.
+     * @return False if an error occured, true otherwise.
+     */
+    boolean viewServerListWindows(Socket client) {
+        if (isSystemSecure()) {
+            return false;
+        }
+
+        boolean result = true;
+
+        WindowList windows = new WindowList();
+        synchronized (mWindowMap) {
+            //noinspection unchecked
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+                windows.addAll(displayContent.getWindowList());
+            }
+        }
+
+        BufferedWriter out = null;
+
+        // Any uncaught exception will crash the system process
+        try {
+            OutputStream clientStream = client.getOutputStream();
+            out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
+
+            final int count = windows.size();
+            for (int i = 0; i < count; i++) {
+                final WindowState w = windows.get(i);
+                out.write(Integer.toHexString(System.identityHashCode(w)));
+                out.write(' ');
+                out.append(w.mAttrs.getTitle());
+                out.write('\n');
+            }
+
+            out.write("DONE.\n");
+            out.flush();
+        } catch (Exception e) {
+            result = false;
+        } finally {
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    result = false;
+                }
+            }
+        }
+
+        return result;
+    }
+
+    // TODO(multidisplay): Extend to multiple displays.
+    /**
+     * Returns the focused window in the following format:
+     * windowHashCodeInHexadecimal windowName
+     *
+     * @param client The remote client to send the listing to.
+     * @return False if an error occurred, true otherwise.
+     */
+    boolean viewServerGetFocusedWindow(Socket client) {
+        if (isSystemSecure()) {
+            return false;
+        }
+
+        boolean result = true;
+
+        WindowState focusedWindow = getFocusedWindow();
+
+        BufferedWriter out = null;
+
+        // Any uncaught exception will crash the system process
+        try {
+            OutputStream clientStream = client.getOutputStream();
+            out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
+
+            if(focusedWindow != null) {
+                out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
+                out.write(' ');
+                out.append(focusedWindow.mAttrs.getTitle());
+            }
+            out.write('\n');
+            out.flush();
+        } catch (Exception e) {
+            result = false;
+        } finally {
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    result = false;
+                }
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * Sends a command to a target window. The result of the command, if any, will be
+     * written in the output stream of the specified socket.
+     *
+     * The parameters must follow this syntax:
+     * windowHashcode extra
+     *
+     * Where XX is the length in characeters of the windowTitle.
+     *
+     * The first parameter is the target window. The window with the specified hashcode
+     * will be the target. If no target can be found, nothing happens. The extra parameters
+     * will be delivered to the target window and as parameters to the command itself.
+     *
+     * @param client The remote client to sent the result, if any, to.
+     * @param command The command to execute.
+     * @param parameters The command parameters.
+     *
+     * @return True if the command was successfully delivered, false otherwise. This does
+     *         not indicate whether the command itself was successful.
+     */
+    boolean viewServerWindowCommand(Socket client, String command, String parameters) {
+        if (isSystemSecure()) {
+            return false;
+        }
+
+        boolean success = true;
+        Parcel data = null;
+        Parcel reply = null;
+
+        BufferedWriter out = null;
+
+        // Any uncaught exception will crash the system process
+        try {
+            // Find the hashcode of the window
+            int index = parameters.indexOf(' ');
+            if (index == -1) {
+                index = parameters.length();
+            }
+            final String code = parameters.substring(0, index);
+            int hashCode = (int) Long.parseLong(code, 16);
+
+            // Extract the command's parameter after the window description
+            if (index < parameters.length()) {
+                parameters = parameters.substring(index + 1);
+            } else {
+                parameters = "";
+            }
+
+            final WindowState window = findWindow(hashCode);
+            if (window == null) {
+                return false;
+            }
+
+            data = Parcel.obtain();
+            data.writeInterfaceToken("android.view.IWindow");
+            data.writeString(command);
+            data.writeString(parameters);
+            data.writeInt(1);
+            ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
+
+            reply = Parcel.obtain();
+
+            final IBinder binder = window.mClient.asBinder();
+            // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
+            binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
+
+            reply.readException();
+
+            if (!client.isOutputShutdown()) {
+                out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
+                out.write("DONE\n");
+                out.flush();
+            }
+
+        } catch (Exception e) {
+            Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
+            success = false;
+        } finally {
+            if (data != null) {
+                data.recycle();
+            }
+            if (reply != null) {
+                reply.recycle();
+            }
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException e) {
+
+                }
+            }
+        }
+
+        return success;
+    }
+
+    public void addWindowChangeListener(WindowChangeListener listener) {
+        synchronized(mWindowMap) {
+            mWindowChangeListeners.add(listener);
+        }
+    }
+
+    public void removeWindowChangeListener(WindowChangeListener listener) {
+        synchronized(mWindowMap) {
+            mWindowChangeListeners.remove(listener);
+        }
+    }
+
+    private void notifyWindowsChanged() {
+        WindowChangeListener[] windowChangeListeners;
+        synchronized(mWindowMap) {
+            if(mWindowChangeListeners.isEmpty()) {
+                return;
+            }
+            windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
+            windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
+        }
+        int N = windowChangeListeners.length;
+        for(int i = 0; i < N; i++) {
+            windowChangeListeners[i].windowsChanged();
+        }
+    }
+
+    private void notifyFocusChanged() {
+        WindowChangeListener[] windowChangeListeners;
+        synchronized(mWindowMap) {
+            if(mWindowChangeListeners.isEmpty()) {
+                return;
+            }
+            windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
+            windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
+        }
+        int N = windowChangeListeners.length;
+        for(int i = 0; i < N; i++) {
+            windowChangeListeners[i].focusChanged();
+        }
+    }
+
+    private WindowState findWindow(int hashCode) {
+        if (hashCode == -1) {
+            // TODO(multidisplay): Extend to multiple displays.
+            return getFocusedWindow();
+        }
+
+        synchronized (mWindowMap) {
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+                final int numWindows = windows.size();
+                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                    final WindowState w = windows.get(winNdx);
+                    if (System.identityHashCode(w) == hashCode) {
+                        return w;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    /*
+     * Instruct the Activity Manager to fetch the current configuration and broadcast
+     * that to config-changed listeners if appropriate.
+     */
+    void sendNewConfiguration() {
+        try {
+            mActivityManager.updateConfiguration(null);
+        } catch (RemoteException e) {
+        }
+    }
+
+    public Configuration computeNewConfiguration() {
+        synchronized (mWindowMap) {
+            Configuration config = computeNewConfigurationLocked();
+            if (config == null && mWaitingForConfig) {
+                // Nothing changed but we are waiting for something... stop that!
+                mWaitingForConfig = false;
+                mLastFinishedFreezeSource = "new-config";
+                performLayoutAndPlaceSurfacesLocked();
+            }
+            return config;
+        }
+    }
+
+    Configuration computeNewConfigurationLocked() {
+        Configuration config = new Configuration();
+        config.fontScale = 0;
+        if (!computeScreenConfigurationLocked(config)) {
+            return null;
+        }
+        return config;
+    }
+
+    private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) {
+        // TODO: Multidisplay: for now only use with default display.
+        final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation);
+        if (width < displayInfo.smallestNominalAppWidth) {
+            displayInfo.smallestNominalAppWidth = width;
+        }
+        if (width > displayInfo.largestNominalAppWidth) {
+            displayInfo.largestNominalAppWidth = width;
+        }
+        final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation);
+        if (height < displayInfo.smallestNominalAppHeight) {
+            displayInfo.smallestNominalAppHeight = height;
+        }
+        if (height > displayInfo.largestNominalAppHeight) {
+            displayInfo.largestNominalAppHeight = height;
+        }
+    }
+
+    private int reduceConfigLayout(int curLayout, int rotation, float density,
+            int dw, int dh) {
+        // 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);
+
+        // Compute the screen layout size class for this rotation.
+        int longSize = w;
+        int shortSize = h;
+        if (longSize < shortSize) {
+            int tmp = longSize;
+            longSize = shortSize;
+            shortSize = tmp;
+        }
+        longSize = (int)(longSize/density);
+        shortSize = (int)(shortSize/density);
+        return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
+    }
+
+    private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
+                  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
+        // operation.  To this, start with the base screen size and compute the
+        // width under the different possible rotations.  We need to un-rotate
+        // the current screen dimensions before doing this.
+        int unrotDw, unrotDh;
+        if (rotated) {
+            unrotDw = dh;
+            unrotDh = dw;
+        } else {
+            unrotDw = dw;
+            unrotDh = dh;
+        }
+        displayInfo.smallestNominalAppWidth = 1<<30;
+        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);
+        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);
+        outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
+        outConfig.screenLayout = sl;
+    }
+
+    private int reduceCompatConfigWidthSize(int curSize, int rotation, 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);
+        float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
+        int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
+        if (curSize == 0 || size < curSize) {
+            curSize = size;
+        }
+        return curSize;
+    }
+
+    private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) {
+        // TODO: Multidisplay: for now only use with default display.
+        mTmpDisplayMetrics.setTo(dm);
+        final DisplayMetrics tmpDm = mTmpDisplayMetrics;
+        final int unrotDw, unrotDh;
+        if (rotated) {
+            unrotDw = dh;
+            unrotDh = dw;
+        } else {
+            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);
+        return sw;
+    }
+
+    boolean computeScreenConfigurationLocked(Configuration config) {
+        if (!mDisplayReady) {
+            return false;
+        }
+
+        // TODO(multidisplay): For now, apply Configuration to main screen only.
+        final DisplayContent displayContent = getDefaultDisplayContentLocked();
+
+        // Use the effective "visual" dimensions based on current rotation
+        final boolean rotated = (mRotation == Surface.ROTATION_90
+                || mRotation == Surface.ROTATION_270);
+        final int realdw = rotated ?
+                displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth;
+        final int realdh = rotated ?
+                displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight;
+        int dw = realdw;
+        int dh = realdh;
+
+        if (mAltOrientation) {
+            if (realdw > realdh) {
+                // Turn landscape into portrait.
+                int maxw = (int)(realdh/1.3f);
+                if (maxw < realdw) {
+                    dw = maxw;
+                }
+            } else {
+                // Turn portrait into landscape.
+                int maxh = (int)(realdw/1.3f);
+                if (maxh < realdh) {
+                    dh = maxh;
+                }
+            }
+        }
+
+        if (config != null) {
+            config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
+                    Configuration.ORIENTATION_LANDSCAPE;
+        }
+
+        // Update application display metrics.
+        final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
+        final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
+        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        synchronized(displayContent.mDisplaySizeLock) {
+            displayInfo.rotation = mRotation;
+            displayInfo.logicalWidth = dw;
+            displayInfo.logicalHeight = dh;
+            displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity;
+            displayInfo.appWidth = appWidth;
+            displayInfo.appHeight = appHeight;
+            displayInfo.getLogicalMetrics(mRealDisplayMetrics,
+                    CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
+            displayInfo.getAppMetrics(mDisplayMetrics);
+            mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
+                    displayContent.getDisplayId(), displayInfo);
+        }
+        if (false) {
+            Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight);
+        }
+
+        final DisplayMetrics dm = mDisplayMetrics;
+        mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm,
+                mCompatDisplayMetrics);
+
+        if (config != null) {
+            config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation)
+                    / dm.density);
+            config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation)
+                    / dm.density);
+            computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh, dm.density, config);
+
+            config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
+            config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
+            config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
+            config.densityDpi = displayContent.mBaseDisplayDensity;
+
+            // Update the configuration based on available input devices, lid switch,
+            // and platform configuration.
+            config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
+            config.keyboard = Configuration.KEYBOARD_NOKEYS;
+            config.navigation = Configuration.NAVIGATION_NONAV;
+
+            int keyboardPresence = 0;
+            int navigationPresence = 0;
+            final InputDevice[] devices = mInputManager.getInputDevices();
+            final int len = devices.length;
+            for (int i = 0; i < len; i++) {
+                InputDevice device = devices[i];
+                if (!device.isVirtual()) {
+                    final int sources = device.getSources();
+                    final int presenceFlag = device.isExternal() ?
+                            WindowManagerPolicy.PRESENCE_EXTERNAL :
+                                    WindowManagerPolicy.PRESENCE_INTERNAL;
+
+                    if (mIsTouchDevice) {
+                        if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
+                                InputDevice.SOURCE_TOUCHSCREEN) {
+                            config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
+                        }
+                    } else {
+                        config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
+                    }
+
+                    if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
+                        config.navigation = Configuration.NAVIGATION_TRACKBALL;
+                        navigationPresence |= presenceFlag;
+                    } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
+                            && config.navigation == Configuration.NAVIGATION_NONAV) {
+                        config.navigation = Configuration.NAVIGATION_DPAD;
+                        navigationPresence |= presenceFlag;
+                    }
+
+                    if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
+                        config.keyboard = Configuration.KEYBOARD_QWERTY;
+                        keyboardPresence |= presenceFlag;
+                    }
+                }
+            }
+
+            // Determine whether a hard keyboard is available and enabled.
+            boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
+            if (hardKeyboardAvailable != mHardKeyboardAvailable) {
+                mHardKeyboardAvailable = hardKeyboardAvailable;
+                mHardKeyboardEnabled = hardKeyboardAvailable;
+                mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
+                mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
+            }
+            if (!mHardKeyboardEnabled) {
+                config.keyboard = Configuration.KEYBOARD_NOKEYS;
+            }
+
+            // Let the policy update hidden states.
+            config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
+            config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
+            config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
+            mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
+        }
+
+        return true;
+    }
+
+    public boolean isHardKeyboardAvailable() {
+        synchronized (mWindowMap) {
+            return mHardKeyboardAvailable;
+        }
+    }
+
+    public boolean isHardKeyboardEnabled() {
+        synchronized (mWindowMap) {
+            return mHardKeyboardEnabled;
+        }
+    }
+
+    public void setHardKeyboardEnabled(boolean enabled) {
+        synchronized (mWindowMap) {
+            if (mHardKeyboardEnabled != enabled) {
+                mHardKeyboardEnabled = enabled;
+                mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+            }
+        }
+    }
+
+    public void setOnHardKeyboardStatusChangeListener(
+            OnHardKeyboardStatusChangeListener listener) {
+        synchronized (mWindowMap) {
+            mHardKeyboardStatusChangeListener = listener;
+        }
+    }
+
+    void notifyHardKeyboardStatusChange() {
+        final boolean available, enabled;
+        final OnHardKeyboardStatusChangeListener listener;
+        synchronized (mWindowMap) {
+            listener = mHardKeyboardStatusChangeListener;
+            available = mHardKeyboardAvailable;
+            enabled = mHardKeyboardEnabled;
+        }
+        if (listener != null) {
+            listener.onHardKeyboardStatusChange(available, enabled);
+        }
+    }
+
+    // -------------------------------------------------------------
+    // Drag and drop
+    // -------------------------------------------------------------
+
+    IBinder prepareDragSurface(IWindow window, SurfaceSession session,
+            int flags, int width, int height, Surface outSurface) {
+        if (DEBUG_DRAG) {
+            Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
+                    + " flags=" + Integer.toHexString(flags) + " win=" + window
+                    + " asbinder=" + window.asBinder());
+        }
+
+        final int callerPid = Binder.getCallingPid();
+        final long origId = Binder.clearCallingIdentity();
+        IBinder token = null;
+
+        try {
+            synchronized (mWindowMap) {
+                try {
+                    if (mDragState == null) {
+                        // TODO(multi-display): support other displays
+                        final DisplayContent displayContent = getDefaultDisplayContentLocked();
+                        final Display display = displayContent.getDisplay();
+                        SurfaceControl surface = new SurfaceControl(session, "drag surface",
+                                width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
+                        surface.setLayerStack(display.getLayerStack());
+                        if (SHOW_TRANSACTIONS) Slog.i(TAG, "  DRAG "
+                                + surface + ": CREATE");
+                        outSurface.copyFrom(surface);
+                        final IBinder winBinder = window.asBinder();
+                        token = new Binder();
+                        mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder);
+                        token = mDragState.mToken = new Binder();
+
+                        // 5 second timeout for this window to actually begin the drag
+                        mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
+                        Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
+                        mH.sendMessageDelayed(msg, 5000);
+                    } else {
+                        Slog.w(TAG, "Drag already in progress");
+                    }
+                } catch (OutOfResourcesException e) {
+                    Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
+                    if (mDragState != null) {
+                        mDragState.reset();
+                        mDragState = null;
+                    }
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
+        }
+
+        return token;
+    }
+
+    // -------------------------------------------------------------
+    // Input Events and Focus Management
+    // -------------------------------------------------------------
+
+    final InputMonitor mInputMonitor = new InputMonitor(this);
+    private boolean mEventDispatchingEnabled;
+
+    @Override
+    public void pauseKeyDispatching(IBinder _token) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "pauseKeyDispatching()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized (mWindowMap) {
+            WindowToken token = mTokenMap.get(_token);
+            if (token != null) {
+                mInputMonitor.pauseDispatchingLw(token);
+            }
+        }
+    }
+
+    @Override
+    public void resumeKeyDispatching(IBinder _token) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "resumeKeyDispatching()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized (mWindowMap) {
+            WindowToken token = mTokenMap.get(_token);
+            if (token != null) {
+                mInputMonitor.resumeDispatchingLw(token);
+            }
+        }
+    }
+
+    @Override
+    public void setEventDispatching(boolean enabled) {
+        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
+                "setEventDispatching()")) {
+            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
+        }
+
+        synchronized (mWindowMap) {
+            mEventDispatchingEnabled = enabled;
+            if (mDisplayEnabled) {
+                mInputMonitor.setEventDispatchingLw(enabled);
+            }
+            sendScreenStatusToClientsLocked();
+        }
+    }
+
+    @Override
+    public IBinder getFocusedWindowToken() {
+        if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO,
+                "getFocusedWindowToken()")) {
+            throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission.");
+        }
+        synchronized (mWindowMap) {
+            WindowState windowState = getFocusedWindowLocked();
+            if (windowState != null) {
+                return windowState.mClient.asBinder();
+            }
+            return null;
+        }
+    }
+
+    private WindowState getFocusedWindow() {
+        synchronized (mWindowMap) {
+            return getFocusedWindowLocked();
+        }
+    }
+
+    private WindowState getFocusedWindowLocked() {
+        return mCurrentFocus;
+    }
+
+    public boolean detectSafeMode() {
+        if (!mInputMonitor.waitForInputDevicesReady(
+                INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
+            Slog.w(TAG, "Devices still not ready after waiting "
+                   + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
+                   + " milliseconds before attempting to detect safe mode.");
+        }
+
+        int menuState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY,
+                KeyEvent.KEYCODE_MENU);
+        int sState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, KeyEvent.KEYCODE_S);
+        int dpadState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD,
+                KeyEvent.KEYCODE_DPAD_CENTER);
+        int trackballState = mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL,
+                InputManagerService.BTN_MOUSE);
+        int volumeDownState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY,
+                KeyEvent.KEYCODE_VOLUME_DOWN);
+        mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0
+                || volumeDownState > 0;
+        try {
+            if (SystemProperties.getInt(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, 0) != 0) {
+                mSafeMode = true;
+                SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, "");
+            }
+        } catch (IllegalArgumentException e) {
+        }
+        if (mSafeMode) {
+            Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState
+                    + " dpad=" + dpadState + " trackball=" + trackballState + ")");
+        } else {
+            Log.i(TAG, "SAFE MODE not enabled");
+        }
+        mPolicy.setSafeMode(mSafeMode);
+        return mSafeMode;
+    }
+
+    public void displayReady() {
+        displayReady(Display.DEFAULT_DISPLAY);
+
+        synchronized(mWindowMap) {
+            final DisplayContent displayContent = getDefaultDisplayContentLocked();
+            readForcedDisplaySizeAndDensityLocked(displayContent);
+            mDisplayReady = true;
+        }
+
+        try {
+            mActivityManager.updateConfiguration(null);
+        } catch (RemoteException e) {
+        }
+
+        synchronized(mWindowMap) {
+            mIsTouchDevice = mContext.getPackageManager().hasSystemFeature(
+                    PackageManager.FEATURE_TOUCHSCREEN);
+            configureDisplayPolicyLocked(getDefaultDisplayContentLocked());
+        }
+
+        try {
+            mActivityManager.updateConfiguration(null);
+        } catch (RemoteException e) {
+        }
+    }
+
+    private void displayReady(int displayId) {
+        synchronized(mWindowMap) {
+            final DisplayContent displayContent = getDisplayContentLocked(displayId);
+            if (displayContent != null) {
+                mAnimator.addDisplayLocked(displayId);
+                synchronized(displayContent.mDisplaySizeLock) {
+                    // Bootstrap the default logical display from the display manager.
+                    final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+                    DisplayInfo newDisplayInfo = mDisplayManagerInternal.getDisplayInfo(displayId);
+                    if (newDisplayInfo != null) {
+                        displayInfo.copyFrom(newDisplayInfo);
+                    }
+                    displayContent.mInitialDisplayWidth = displayInfo.logicalWidth;
+                    displayContent.mInitialDisplayHeight = displayInfo.logicalHeight;
+                    displayContent.mInitialDisplayDensity = displayInfo.logicalDensityDpi;
+                    displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth;
+                    displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight;
+                    displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity;
+                    displayContent.mBaseDisplayRect.set(0, 0,
+                            displayContent.mBaseDisplayWidth, displayContent.mBaseDisplayHeight);
+                }
+            }
+        }
+    }
+
+    public void systemReady() {
+        mPolicy.systemReady();
+    }
+
+    // TODO(multidisplay): Call isScreenOn for each display.
+    private void sendScreenStatusToClientsLocked() {
+        final boolean on = mPowerManager.isScreenOn();
+        final int numDisplays = mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+            final int numWindows = windows.size();
+            for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                try {
+                    windows.get(winNdx).mClient.dispatchScreenState(on);
+                } catch (RemoteException e) {
+                    // Ignored
+                }
+            }
+        }
+    }
+
+    // -------------------------------------------------------------
+    // Async Handler
+    // -------------------------------------------------------------
+
+    final class H extends Handler {
+        public static final int REPORT_FOCUS_CHANGE = 2;
+        public static final int REPORT_LOSING_FOCUS = 3;
+        public static final int DO_TRAVERSAL = 4;
+        public static final int ADD_STARTING = 5;
+        public static final int REMOVE_STARTING = 6;
+        public static final int FINISHED_STARTING = 7;
+        public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
+        public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9;
+        public static final int WINDOW_FREEZE_TIMEOUT = 11;
+
+        public static final int APP_TRANSITION_TIMEOUT = 13;
+        public static final int PERSIST_ANIMATION_SCALE = 14;
+        public static final int FORCE_GC = 15;
+        public static final int ENABLE_SCREEN = 16;
+        public static final int APP_FREEZE_TIMEOUT = 17;
+        public static final int SEND_NEW_CONFIGURATION = 18;
+        public static final int REPORT_WINDOWS_CHANGE = 19;
+        public static final int DRAG_START_TIMEOUT = 20;
+        public static final int DRAG_END_TIMEOUT = 21;
+        public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
+        public static final int BOOT_TIMEOUT = 23;
+        public static final int WAITING_FOR_DRAWN_TIMEOUT = 24;
+        public static final int SHOW_STRICT_MODE_VIOLATION = 25;
+        public static final int DO_ANIMATION_CALLBACK = 26;
+
+        public static final int DO_DISPLAY_ADDED = 27;
+        public static final int DO_DISPLAY_REMOVED = 28;
+        public static final int DO_DISPLAY_CHANGED = 29;
+
+        public static final int CLIENT_FREEZE_TIMEOUT = 30;
+        public static final int TAP_OUTSIDE_STACK = 31;
+        public static final int NOTIFY_ACTIVITY_DRAWN = 32;
+
+        public static final int REMOVE_STARTING_TIMEOUT = 33;
+
+        @Override
+        public void handleMessage(Message msg) {
+            if (DEBUG_WINDOW_TRACE) {
+                Slog.v(TAG, "handleMessage: entry what=" + msg.what);
+            }
+            switch (msg.what) {
+                case REPORT_FOCUS_CHANGE: {
+                    WindowState lastFocus;
+                    WindowState newFocus;
+
+                    synchronized(mWindowMap) {
+                        lastFocus = mLastFocus;
+                        newFocus = mCurrentFocus;
+                        if (lastFocus == newFocus) {
+                            // Focus is not changing, so nothing to do.
+                            return;
+                        }
+                        mLastFocus = newFocus;
+                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Focus moving from " + lastFocus +
+                                " to " + newFocus);
+                        if (newFocus != null && lastFocus != null
+                                && !newFocus.isDisplayedLw()) {
+                            //Slog.i(TAG, "Delaying loss of focus...");
+                            mLosingFocus.add(lastFocus);
+                            lastFocus = null;
+                        }
+                    }
+
+                    //System.out.println("Changing focus from " + lastFocus
+                    //                   + " to " + newFocus);
+                    if (newFocus != null) {
+                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Gaining focus: " + newFocus);
+                        newFocus.reportFocusChangedSerialized(true, mInTouchMode);
+                        notifyFocusChanged();
+                    }
+
+                    if (lastFocus != null) {
+                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Losing focus: " + lastFocus);
+                        lastFocus.reportFocusChangedSerialized(false, mInTouchMode);
+                    }
+                } break;
+
+                case REPORT_LOSING_FOCUS: {
+                    ArrayList<WindowState> losers;
+
+                    synchronized(mWindowMap) {
+                        losers = mLosingFocus;
+                        mLosingFocus = new ArrayList<WindowState>();
+                    }
+
+                    final int N = losers.size();
+                    for (int i=0; i<N; i++) {
+                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Losing delayed focus: " +
+                                losers.get(i));
+                        losers.get(i).reportFocusChangedSerialized(false, mInTouchMode);
+                    }
+                } break;
+
+                case DO_TRAVERSAL: {
+                    synchronized(mWindowMap) {
+                        mTraversalScheduled = false;
+                        performLayoutAndPlaceSurfacesLocked();
+                    }
+                } break;
+
+                case ADD_STARTING: {
+                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
+                    final StartingData sd = wtoken.startingData;
+
+                    if (sd == null) {
+                        // Animation has been canceled... do nothing.
+                        return;
+                    }
+
+                    if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
+                            + wtoken + ": pkg=" + sd.pkg);
+
+                    View view = null;
+                    try {
+                        view = mPolicy.addStartingWindow(
+                            wtoken.token, sd.pkg, sd.theme, sd.compatInfo,
+                            sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.logo, sd.windowFlags);
+                    } catch (Exception e) {
+                        Slog.w(TAG, "Exception when adding starting window", e);
+                    }
+
+                    if (view != null) {
+                        boolean abort = false;
+
+                        synchronized(mWindowMap) {
+                            if (wtoken.removed || wtoken.startingData == null) {
+                                // If the window was successfully added, then
+                                // we need to remove it.
+                                if (wtoken.startingWindow != null) {
+                                    if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
+                                            "Aborted starting " + wtoken
+                                            + ": removed=" + wtoken.removed
+                                            + " startingData=" + wtoken.startingData);
+                                    removeStartingWindowTimeout(wtoken);
+                                    wtoken.startingWindow = null;
+                                    wtoken.startingData = null;
+                                    abort = true;
+                                }
+                            } else {
+                                wtoken.startingView = view;
+                            }
+                            if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
+                                    "Added starting " + wtoken
+                                    + ": startingWindow="
+                                    + wtoken.startingWindow + " startingView="
+                                    + wtoken.startingView);
+                        }
+
+                        if (abort) {
+                            try {
+                                mPolicy.removeStartingWindow(wtoken.token, view);
+                            } catch (Exception e) {
+                                Slog.w(TAG, "Exception when removing starting window", e);
+                            }
+                        }
+                    }
+                } break;
+
+                case REMOVE_STARTING_TIMEOUT: {
+                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
+                    Slog.e(TAG, "Starting window " + wtoken + " timed out");
+                    // Fall through.
+                }
+                case REMOVE_STARTING: {
+                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
+                    IBinder token = null;
+                    View view = null;
+                    synchronized (mWindowMap) {
+                        if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
+                                + wtoken + ": startingWindow="
+                                + wtoken.startingWindow + " startingView="
+                                + wtoken.startingView);
+                        if (wtoken.startingWindow != null) {
+                            view = wtoken.startingView;
+                            token = wtoken.token;
+                            wtoken.startingData = null;
+                            wtoken.startingView = null;
+                            wtoken.startingWindow = null;
+                            wtoken.startingDisplayed = false;
+                        }
+                    }
+                    if (view != null) {
+                        try {
+                            mPolicy.removeStartingWindow(token, view);
+                        } catch (Exception e) {
+                            Slog.w(TAG, "Exception when removing starting window", e);
+                        }
+                    }
+                } break;
+
+                case FINISHED_STARTING: {
+                    IBinder token = null;
+                    View view = null;
+                    while (true) {
+                        synchronized (mWindowMap) {
+                            final int N = mFinishedStarting.size();
+                            if (N <= 0) {
+                                break;
+                            }
+                            AppWindowToken wtoken = mFinishedStarting.remove(N-1);
+
+                            if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
+                                    "Finished starting " + wtoken
+                                    + ": startingWindow=" + wtoken.startingWindow
+                                    + " startingView=" + wtoken.startingView);
+
+                            if (wtoken.startingWindow == null) {
+                                continue;
+                            }
+
+                            view = wtoken.startingView;
+                            token = wtoken.token;
+                            wtoken.startingData = null;
+                            wtoken.startingView = null;
+                            wtoken.startingWindow = null;
+                            wtoken.startingDisplayed = false;
+                        }
+
+                        try {
+                            mPolicy.removeStartingWindow(token, view);
+                        } catch (Exception e) {
+                            Slog.w(TAG, "Exception when removing starting window", e);
+                        }
+                    }
+                } break;
+
+                case REPORT_APPLICATION_TOKEN_DRAWN: {
+                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
+
+                    try {
+                        if (DEBUG_VISIBILITY) Slog.v(
+                                TAG, "Reporting drawn in " + wtoken);
+                        wtoken.appToken.windowsDrawn();
+                    } catch (RemoteException ex) {
+                    }
+                } break;
+
+                case REPORT_APPLICATION_TOKEN_WINDOWS: {
+                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
+
+                    boolean nowVisible = msg.arg1 != 0;
+                    boolean nowGone = msg.arg2 != 0;
+
+                    try {
+                        if (DEBUG_VISIBILITY) Slog.v(
+                                TAG, "Reporting visible in " + wtoken
+                                + " visible=" + nowVisible
+                                + " gone=" + nowGone);
+                        if (nowVisible) {
+                            wtoken.appToken.windowsVisible();
+                        } else {
+                            wtoken.appToken.windowsGone();
+                        }
+                    } catch (RemoteException ex) {
+                    }
+                } break;
+
+                case WINDOW_FREEZE_TIMEOUT: {
+                    // TODO(multidisplay): Can non-default displays rotate?
+                    synchronized (mWindowMap) {
+                        Slog.w(TAG, "Window freeze timeout expired.");
+                        final WindowList windows = getDefaultWindowListLocked();
+                        int i = windows.size();
+                        while (i > 0) {
+                            i--;
+                            WindowState w = windows.get(i);
+                            if (w.mOrientationChanging) {
+                                w.mOrientationChanging = false;
+                                w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
+                                        - mDisplayFreezeTime);
+                                Slog.w(TAG, "Force clearing orientation change: " + w);
+                            }
+                        }
+                        performLayoutAndPlaceSurfacesLocked();
+                    }
+                    break;
+                }
+
+                case APP_TRANSITION_TIMEOUT: {
+                    synchronized (mWindowMap) {
+                        if (mAppTransition.isTransitionSet()) {
+                            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** APP TRANSITION TIMEOUT");
+                            mAppTransition.setTimeout();
+                            performLayoutAndPlaceSurfacesLocked();
+                        }
+                    }
+                    break;
+                }
+
+                case PERSIST_ANIMATION_SCALE: {
+                    Settings.Global.putFloat(mContext.getContentResolver(),
+                            Settings.Global.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
+                    Settings.Global.putFloat(mContext.getContentResolver(),
+                            Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
+                    Settings.Global.putFloat(mContext.getContentResolver(),
+                            Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale);
+                    break;
+                }
+
+                case FORCE_GC: {
+                    synchronized (mWindowMap) {
+                        // Since we're holding both mWindowMap and mAnimator we don't need to
+                        // hold mAnimator.mLayoutToAnim.
+                        if (mAnimator.mAnimating || mAnimationScheduled) {
+                            // If we are animating, don't do the gc now but
+                            // delay a bit so we don't interrupt the animation.
+                            sendEmptyMessageDelayed(H.FORCE_GC, 2000);
+                            return;
+                        }
+                        // If we are currently rotating the display, it will
+                        // schedule a new message when done.
+                        if (mDisplayFrozen) {
+                            return;
+                        }
+                    }
+                    Runtime.getRuntime().gc();
+                    break;
+                }
+
+                case ENABLE_SCREEN: {
+                    performEnableScreen();
+                    break;
+                }
+
+                case APP_FREEZE_TIMEOUT: {
+                    synchronized (mWindowMap) {
+                        Slog.w(TAG, "App freeze timeout expired.");
+                        final int numStacks = mStackIdToStack.size();
+                        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+                            final TaskStack stack = mStackIdToStack.valueAt(stackNdx);
+                            final ArrayList<Task> tasks = stack.getTasks();
+                            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                                AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                                    AppWindowToken tok = tokens.get(tokenNdx);
+                                    if (tok.mAppAnimator.freezingScreen) {
+                                        Slog.w(TAG, "Force clearing freeze: " + tok);
+                                        unsetAppFreezingScreenLocked(tok, true, true);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    break;
+                }
+
+                case CLIENT_FREEZE_TIMEOUT: {
+                    synchronized (mWindowMap) {
+                        if (mClientFreezingScreen) {
+                            mClientFreezingScreen = false;
+                            mLastFinishedFreezeSource = "client-timeout";
+                            stopFreezingDisplayLocked();
+                        }
+                    }
+                    break;
+                }
+
+                case SEND_NEW_CONFIGURATION: {
+                    removeMessages(SEND_NEW_CONFIGURATION);
+                    sendNewConfiguration();
+                    break;
+                }
+
+                case REPORT_WINDOWS_CHANGE: {
+                    if (mWindowsChanged) {
+                        synchronized (mWindowMap) {
+                            mWindowsChanged = false;
+                        }
+                        notifyWindowsChanged();
+                    }
+                    break;
+                }
+
+                case DRAG_START_TIMEOUT: {
+                    IBinder win = (IBinder)msg.obj;
+                    if (DEBUG_DRAG) {
+                        Slog.w(TAG, "Timeout starting drag by win " + win);
+                    }
+                    synchronized (mWindowMap) {
+                        // !!! TODO: ANR the app that has failed to start the drag in time
+                        if (mDragState != null) {
+                            mDragState.unregister();
+                            mInputMonitor.updateInputWindowsLw(true /*force*/);
+                            mDragState.reset();
+                            mDragState = null;
+                        }
+                    }
+                    break;
+                }
+
+                case DRAG_END_TIMEOUT: {
+                    IBinder win = (IBinder)msg.obj;
+                    if (DEBUG_DRAG) {
+                        Slog.w(TAG, "Timeout ending drag to win " + win);
+                    }
+                    synchronized (mWindowMap) {
+                        // !!! TODO: ANR the drag-receiving app
+                        if (mDragState != null) {
+                            mDragState.mDragResult = false;
+                            mDragState.endDragLw();
+                        }
+                    }
+                    break;
+                }
+
+                case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
+                    notifyHardKeyboardStatusChange();
+                    break;
+                }
+
+                case BOOT_TIMEOUT: {
+                    performBootTimeout();
+                    break;
+                }
+
+                case WAITING_FOR_DRAWN_TIMEOUT: {
+                    Pair<WindowState, IRemoteCallback> pair;
+                    synchronized (mWindowMap) {
+                        pair = (Pair<WindowState, IRemoteCallback>)msg.obj;
+                        Slog.w(TAG, "Timeout waiting for drawn: " + pair.first);
+                        if (!mWaitingForDrawn.remove(pair)) {
+                            return;
+                        }
+                    }
+                    try {
+                        pair.second.sendResult(null);
+                    } catch (RemoteException e) {
+                    }
+                    break;
+                }
+
+                case SHOW_STRICT_MODE_VIOLATION: {
+                    showStrictModeViolation(msg.arg1, msg.arg2);
+                    break;
+                }
+
+                case DO_ANIMATION_CALLBACK: {
+                    try {
+                        ((IRemoteCallback)msg.obj).sendResult(null);
+                    } catch (RemoteException e) {
+                    }
+                    break;
+                }
+
+                case DO_DISPLAY_ADDED:
+                    handleDisplayAdded(msg.arg1);
+                    break;
+
+                case DO_DISPLAY_REMOVED:
+                    synchronized (mWindowMap) {
+                        handleDisplayRemovedLocked(msg.arg1);
+                    }
+                    break;
+
+                case DO_DISPLAY_CHANGED:
+                    synchronized (mWindowMap) {
+                        handleDisplayChangedLocked(msg.arg1);
+                    }
+                    break;
+
+                case TAP_OUTSIDE_STACK: {
+                    int stackId;
+                    synchronized (mWindowMap) {
+                        stackId = ((DisplayContent)msg.obj).stackIdFromPoint(msg.arg1, msg.arg2);
+                    }
+                    if (stackId >= 0) {
+                        try {
+                            mActivityManager.setFocusedStack(stackId);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                }
+                break;
+                case NOTIFY_ACTIVITY_DRAWN:
+                    try {
+                        mActivityManager.notifyActivityDrawn((IBinder) msg.obj);
+                    } catch (RemoteException e) {
+                    }
+                    break;
+            }
+            if (DEBUG_WINDOW_TRACE) {
+                Slog.v(TAG, "handleMessage: exit");
+            }
+        }
+    }
+
+    // -------------------------------------------------------------
+    // IWindowManager API
+    // -------------------------------------------------------------
+
+    @Override
+    public IWindowSession openSession(IInputMethodClient client,
+            IInputContext inputContext) {
+        if (client == null) throw new IllegalArgumentException("null client");
+        if (inputContext == null) throw new IllegalArgumentException("null inputContext");
+        Session session = new Session(this, client, inputContext);
+        return session;
+    }
+
+    @Override
+    public boolean inputMethodClientHasFocus(IInputMethodClient client) {
+        synchronized (mWindowMap) {
+            // The focus for the client is the window immediately below
+            // where we would place the input method window.
+            int idx = findDesiredInputMethodWindowIndexLocked(false);
+            if (idx > 0) {
+                // TODO(multidisplay): IMEs are only supported on the default display.
+                WindowState imFocus = getDefaultWindowListLocked().get(idx-1);
+                if (DEBUG_INPUT_METHOD) {
+                    Slog.i(TAG, "Desired input method target: " + imFocus);
+                    Slog.i(TAG, "Current focus: " + mCurrentFocus);
+                    Slog.i(TAG, "Last focus: " + mLastFocus);
+                }
+                if (imFocus != null) {
+                    // This may be a starting window, in which case we still want
+                    // to count it as okay.
+                    if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
+                            && imFocus.mAppToken != null) {
+                        // The client has definitely started, so it really should
+                        // have a window in this app token.  Let's look for it.
+                        for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
+                            WindowState w = imFocus.mAppToken.windows.get(i);
+                            if (w != imFocus) {
+                                Log.i(TAG, "Switching to real app window: " + w);
+                                imFocus = w;
+                                break;
+                            }
+                        }
+                    }
+                    if (DEBUG_INPUT_METHOD) {
+                        Slog.i(TAG, "IM target client: " + imFocus.mSession.mClient);
+                        if (imFocus.mSession.mClient != null) {
+                            Slog.i(TAG, "IM target client binder: "
+                                    + imFocus.mSession.mClient.asBinder());
+                            Slog.i(TAG, "Requesting client binder: " + client.asBinder());
+                        }
+                    }
+                    if (imFocus.mSession.mClient != null &&
+                            imFocus.mSession.mClient.asBinder() == client.asBinder()) {
+                        return true;
+                    }
+                }
+            }
+
+            // Okay, how about this...  what is the current focus?
+            // It seems in some cases we may not have moved the IM
+            // target window, such as when it was in a pop-up window,
+            // so let's also look at the current focus.  (An example:
+            // go to Gmail, start searching so the keyboard goes up,
+            // press home.  Sometimes the IME won't go down.)
+            // Would be nice to fix this more correctly, but it's
+            // way at the end of a release, and this should be good enough.
+            if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null
+                    && mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public void getInitialDisplaySize(int displayId, Point size) {
+        synchronized (mWindowMap) {
+            final DisplayContent displayContent = getDisplayContentLocked(displayId);
+            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
+                synchronized(displayContent.mDisplaySizeLock) {
+                    size.x = displayContent.mInitialDisplayWidth;
+                    size.y = displayContent.mInitialDisplayHeight;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void getBaseDisplaySize(int displayId, Point size) {
+        synchronized (mWindowMap) {
+            final DisplayContent displayContent = getDisplayContentLocked(displayId);
+            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
+                synchronized(displayContent.mDisplaySizeLock) {
+                    size.x = displayContent.mBaseDisplayWidth;
+                    size.y = displayContent.mBaseDisplayHeight;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void setForcedDisplaySize(int displayId, int width, int height) {
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
+                PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Must hold permission " +
+                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
+        }
+        if (displayId != Display.DEFAULT_DISPLAY) {
+            throw new IllegalArgumentException("Can only set the default display");
+        }
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                // Set some sort of reasonable bounds on the size of the display that we
+                // will try to emulate.
+                final int MIN_WIDTH = 200;
+                final int MIN_HEIGHT = 200;
+                final int MAX_SCALE = 2;
+                final DisplayContent displayContent = getDisplayContentLocked(displayId);
+                if (displayContent != null) {
+                    width = Math.min(Math.max(width, MIN_WIDTH),
+                            displayContent.mInitialDisplayWidth * MAX_SCALE);
+                    height = Math.min(Math.max(height, MIN_HEIGHT),
+                            displayContent.mInitialDisplayHeight * MAX_SCALE);
+                    setForcedDisplaySizeLocked(displayContent, width, height);
+                    Settings.Global.putString(mContext.getContentResolver(),
+                            Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height);
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) {
+        String sizeStr = Settings.Global.getString(mContext.getContentResolver(),
+                Settings.Global.DISPLAY_SIZE_FORCED);
+        if (sizeStr == null || sizeStr.length() == 0) {
+            sizeStr = SystemProperties.get(SIZE_OVERRIDE, null);
+        }
+        if (sizeStr != null && sizeStr.length() > 0) {
+            final int pos = sizeStr.indexOf(',');
+            if (pos > 0 && sizeStr.lastIndexOf(',') == pos) {
+                int width, height;
+                try {
+                    width = Integer.parseInt(sizeStr.substring(0, pos));
+                    height = Integer.parseInt(sizeStr.substring(pos+1));
+                    synchronized(displayContent.mDisplaySizeLock) {
+                        if (displayContent.mBaseDisplayWidth != width
+                                || displayContent.mBaseDisplayHeight != height) {
+                            Slog.i(TAG, "FORCED DISPLAY SIZE: " + width + "x" + height);
+                            displayContent.mBaseDisplayWidth = width;
+                            displayContent.mBaseDisplayHeight = height;
+                        }
+                    }
+                } catch (NumberFormatException ex) {
+                }
+            }
+        }
+        String densityStr = Settings.Global.getString(mContext.getContentResolver(),
+                Settings.Global.DISPLAY_DENSITY_FORCED);
+        if (densityStr == null || densityStr.length() == 0) {
+            densityStr = SystemProperties.get(DENSITY_OVERRIDE, null);
+        }
+        if (densityStr != null && densityStr.length() > 0) {
+            int density;
+            try {
+                density = Integer.parseInt(densityStr);
+                synchronized(displayContent.mDisplaySizeLock) {
+                    if (displayContent.mBaseDisplayDensity != density) {
+                        Slog.i(TAG, "FORCED DISPLAY DENSITY: " + density);
+                        displayContent.mBaseDisplayDensity = density;
+                    }
+                }
+            } catch (NumberFormatException ex) {
+            }
+        }
+    }
+
+    // displayContent must not be null
+    private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width, int height) {
+        Slog.i(TAG, "Using new display size: " + width + "x" + height);
+
+        synchronized(displayContent.mDisplaySizeLock) {
+            displayContent.mBaseDisplayWidth = width;
+            displayContent.mBaseDisplayHeight = height;
+        }
+        reconfigureDisplayLocked(displayContent);
+    }
+
+    @Override
+    public void clearForcedDisplaySize(int displayId) {
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
+                PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Must hold permission " +
+                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
+        }
+        if (displayId != Display.DEFAULT_DISPLAY) {
+            throw new IllegalArgumentException("Can only set the default display");
+        }
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                final DisplayContent displayContent = getDisplayContentLocked(displayId);
+                if (displayContent != null) {
+                    setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth,
+                            displayContent.mInitialDisplayHeight);
+                    Settings.Global.putString(mContext.getContentResolver(),
+                            Settings.Global.DISPLAY_SIZE_FORCED, "");
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    @Override
+    public int getInitialDisplayDensity(int displayId) {
+        synchronized (mWindowMap) {
+            final DisplayContent displayContent = getDisplayContentLocked(displayId);
+            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
+                synchronized(displayContent.mDisplaySizeLock) {
+                    return displayContent.mInitialDisplayDensity;
+                }
+            }
+        }
+        return -1;
+    }
+
+    @Override
+    public int getBaseDisplayDensity(int displayId) {
+        synchronized (mWindowMap) {
+            final DisplayContent displayContent = getDisplayContentLocked(displayId);
+            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
+                synchronized(displayContent.mDisplaySizeLock) {
+                    return displayContent.mBaseDisplayDensity;
+                }
+            }
+        }
+        return -1;
+    }
+
+    @Override
+    public void setForcedDisplayDensity(int displayId, int density) {
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
+                PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Must hold permission " +
+                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
+        }
+        if (displayId != Display.DEFAULT_DISPLAY) {
+            throw new IllegalArgumentException("Can only set the default display");
+        }
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                final DisplayContent displayContent = getDisplayContentLocked(displayId);
+                if (displayContent != null) {
+                    setForcedDisplayDensityLocked(displayContent, density);
+                    Settings.Global.putString(mContext.getContentResolver(),
+                            Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density));
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    // displayContent must not be null
+    private void setForcedDisplayDensityLocked(DisplayContent displayContent, int density) {
+        Slog.i(TAG, "Using new display density: " + density);
+
+        synchronized(displayContent.mDisplaySizeLock) {
+            displayContent.mBaseDisplayDensity = density;
+        }
+        reconfigureDisplayLocked(displayContent);
+    }
+
+    @Override
+    public void clearForcedDisplayDensity(int displayId) {
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
+                PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Must hold permission " +
+                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
+        }
+        if (displayId != Display.DEFAULT_DISPLAY) {
+            throw new IllegalArgumentException("Can only set the default display");
+        }
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                final DisplayContent displayContent = getDisplayContentLocked(displayId);
+                if (displayContent != null) {
+                    setForcedDisplayDensityLocked(displayContent,
+                            displayContent.mInitialDisplayDensity);
+                    Settings.Global.putString(mContext.getContentResolver(),
+                            Settings.Global.DISPLAY_DENSITY_FORCED, "");
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    // displayContent must not be null
+    private void reconfigureDisplayLocked(DisplayContent displayContent) {
+        // TODO: Multidisplay: for now only use with default display.
+        configureDisplayPolicyLocked(displayContent);
+        displayContent.layoutNeeded = true;
+
+        boolean configChanged = updateOrientationFromAppTokensLocked(false);
+        mTempConfiguration.setToDefaults();
+        mTempConfiguration.fontScale = mCurConfiguration.fontScale;
+        if (computeScreenConfigurationLocked(mTempConfiguration)) {
+            if (mCurConfiguration.diff(mTempConfiguration) != 0) {
+                configChanged = true;
+            }
+        }
+
+        if (configChanged) {
+            mWaitingForConfig = true;
+            startFreezingDisplayLocked(false, 0, 0);
+            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+        }
+
+        performLayoutAndPlaceSurfacesLocked();
+    }
+
+    private void configureDisplayPolicyLocked(DisplayContent displayContent) {
+        mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
+                displayContent.mBaseDisplayWidth,
+                displayContent.mBaseDisplayHeight,
+                displayContent.mBaseDisplayDensity);
+
+        DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        mPolicy.setDisplayOverscan(displayContent.getDisplay(),
+                displayInfo.overscanLeft, displayInfo.overscanTop,
+                displayInfo.overscanRight, displayInfo.overscanBottom);
+    }
+
+    @Override
+    public void setOverscan(int displayId, int left, int top, int right, int bottom) {
+        if (mContext.checkCallingOrSelfPermission(
+                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
+                PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Must hold permission " +
+                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
+        }
+        final long ident = Binder.clearCallingIdentity();
+        try {
+            synchronized(mWindowMap) {
+                DisplayContent displayContent = getDisplayContentLocked(displayId);
+                if (displayContent != null) {
+                    setOverscanLocked(displayContent, left, top, right, bottom);
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private void setOverscanLocked(DisplayContent displayContent,
+            int left, int top, int right, int bottom) {
+        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        synchronized (displayContent.mDisplaySizeLock) {
+            displayInfo.overscanLeft = left;
+            displayInfo.overscanTop = top;
+            displayInfo.overscanRight = right;
+            displayInfo.overscanBottom = bottom;
+        }
+
+        mDisplaySettings.setOverscanLocked(displayInfo.name, left, top, right, bottom);
+        mDisplaySettings.writeSettingsLocked();
+
+        reconfigureDisplayLocked(displayContent);
+    }
+
+    // -------------------------------------------------------------
+    // Internals
+    // -------------------------------------------------------------
+
+    final WindowState windowForClientLocked(Session session, IWindow client,
+            boolean throwOnError) {
+        return windowForClientLocked(session, client.asBinder(), throwOnError);
+    }
+
+    final WindowState windowForClientLocked(Session session, IBinder client,
+            boolean throwOnError) {
+        WindowState win = mWindowMap.get(client);
+        if (localLOGV) Slog.v(
+            TAG, "Looking up client " + client + ": " + win);
+        if (win == null) {
+            RuntimeException ex = new IllegalArgumentException(
+                    "Requested window " + client + " does not exist");
+            if (throwOnError) {
+                throw ex;
+            }
+            Slog.w(TAG, "Failed looking up window", ex);
+            return null;
+        }
+        if (session != null && win.mSession != session) {
+            RuntimeException ex = new IllegalArgumentException(
+                    "Requested window " + client + " is in session " +
+                    win.mSession + ", not " + session);
+            if (throwOnError) {
+                throw ex;
+            }
+            Slog.w(TAG, "Failed looking up window", ex);
+            return null;
+        }
+
+        return win;
+    }
+
+    final void rebuildAppWindowListLocked() {
+        rebuildAppWindowListLocked(getDefaultDisplayContentLocked());
+    }
+
+    private void rebuildAppWindowListLocked(final DisplayContent displayContent) {
+        final WindowList windows = displayContent.getWindowList();
+        int NW = windows.size();
+        int i;
+        int lastBelow = -1;
+        int numRemoved = 0;
+
+        if (mRebuildTmp.length < NW) {
+            mRebuildTmp = new WindowState[NW+10];
+        }
+
+        // First remove all existing app windows.
+        i=0;
+        while (i < NW) {
+            WindowState w = windows.get(i);
+            if (w.mAppToken != null) {
+                WindowState win = windows.remove(i);
+                win.mRebuilding = true;
+                mRebuildTmp[numRemoved] = win;
+                mWindowsChanged = true;
+                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Rebuild removing window: " + win);
+                NW--;
+                numRemoved++;
+                continue;
+            } else if (lastBelow == i-1) {
+                if (w.mAttrs.type == TYPE_WALLPAPER || w.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) {
+                    lastBelow = i;
+                }
+            }
+            i++;
+        }
+
+        // Keep whatever windows were below the app windows still below,
+        // by skipping them.
+        lastBelow++;
+        i = lastBelow;
+
+        // First add all of the exiting app tokens...  these are no longer
+        // in the main app list, but still have windows shown.  We put them
+        // in the back because now that the animation is over we no longer
+        // will care about them.
+        final ArrayList<TaskStack> stacks = displayContent.getStacks();
+        final int numStacks = stacks.size();
+        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+            AppTokenList exitingAppTokens = stacks.get(stackNdx).mExitingAppTokens;
+            int NT = exitingAppTokens.size();
+            for (int j = 0; j < NT; j++) {
+                i = reAddAppWindowsLocked(displayContent, i, exitingAppTokens.get(j));
+            }
+        }
+
+        // And add in the still active app tokens in Z order.
+        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
+            final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks();
+            final int numTasks = tasks.size();
+            for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
+                final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                final int numTokens = tokens.size();
+                for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
+                    final AppWindowToken wtoken = tokens.get(tokenNdx);
+                    if (wtoken.mDeferRemoval) {
+                        continue;
+                    }
+                    i = reAddAppWindowsLocked(displayContent, i, wtoken);
+                }
+            }
+        }
+
+        i -= lastBelow;
+        if (i != numRemoved) {
+            Slog.w(TAG, "On display=" + displayContent.getDisplayId() + " Rebuild removed " +
+                    numRemoved + " windows but added " + i,
+                    new RuntimeException("here").fillInStackTrace());
+            for (i=0; i<numRemoved; i++) {
+                WindowState ws = mRebuildTmp[i];
+                if (ws.mRebuilding) {
+                    StringWriter sw = new StringWriter();
+                    PrintWriter pw = new FastPrintWriter(sw, false, 1024);
+                    ws.dump(pw, "", true);
+                    pw.flush();
+                    Slog.w(TAG, "This window was lost: " + ws);
+                    Slog.w(TAG, sw.toString());
+                    ws.mWinAnimator.destroySurfaceLocked();
+                }
+            }
+            Slog.w(TAG, "Current app token list:");
+            dumpAppTokensLocked();
+            Slog.w(TAG, "Final window list:");
+            dumpWindowsLocked();
+        }
+    }
+
+    private final void assignLayersLocked(WindowList windows) {
+        int N = windows.size();
+        int curBaseLayer = 0;
+        int curLayer = 0;
+        int i;
+
+        if (DEBUG_LAYERS) Slog.v(TAG, "Assigning layers based on windows=" + windows,
+                new RuntimeException("here").fillInStackTrace());
+
+        boolean anyLayerChanged = false;
+
+        for (i=0; i<N; i++) {
+            final WindowState w = windows.get(i);
+            final WindowStateAnimator winAnimator = w.mWinAnimator;
+            boolean layerChanged = false;
+            int oldLayer = w.mLayer;
+            if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
+                    || (i > 0 && w.mIsWallpaper)) {
+                curLayer += WINDOW_LAYER_MULTIPLIER;
+                w.mLayer = curLayer;
+            } else {
+                curBaseLayer = curLayer = w.mBaseLayer;
+                w.mLayer = curLayer;
+            }
+            if (w.mLayer != oldLayer) {
+                layerChanged = true;
+                anyLayerChanged = true;
+            }
+            final AppWindowToken wtoken = w.mAppToken;
+            oldLayer = winAnimator.mAnimLayer;
+            if (w.mTargetAppToken != null) {
+                winAnimator.mAnimLayer =
+                        w.mLayer + w.mTargetAppToken.mAppAnimator.animLayerAdjustment;
+            } else if (wtoken != null) {
+                winAnimator.mAnimLayer =
+                        w.mLayer + wtoken.mAppAnimator.animLayerAdjustment;
+            } else {
+                winAnimator.mAnimLayer = w.mLayer;
+            }
+            if (w.mIsImWindow) {
+                winAnimator.mAnimLayer += mInputMethodAnimLayerAdjustment;
+            } else if (w.mIsWallpaper) {
+                winAnimator.mAnimLayer += mWallpaperAnimLayerAdjustment;
+            }
+            if (winAnimator.mAnimLayer != oldLayer) {
+                layerChanged = true;
+                anyLayerChanged = true;
+            }
+            if (layerChanged && w.getStack().isDimming(winAnimator)) {
+                // Force an animation pass just to update the mDimLayer layer.
+                scheduleAnimationLocked();
+            }
+            if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
+                    + "mBase=" + w.mBaseLayer
+                    + " mLayer=" + w.mLayer
+                    + (wtoken == null ?
+                            "" : " mAppLayer=" + wtoken.mAppAnimator.animLayerAdjustment)
+                    + " =mAnimLayer=" + winAnimator.mAnimLayer);
+            //System.out.println(
+            //    "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
+        }
+
+        //TODO (multidisplay): Magnification is supported only for the default display.
+        if (mDisplayMagnifier != null && anyLayerChanged
+                && windows.get(windows.size() - 1).getDisplayId() == Display.DEFAULT_DISPLAY) {
+            mDisplayMagnifier.onWindowLayersChangedLocked();
+        }
+    }
+
+    private final void performLayoutAndPlaceSurfacesLocked() {
+        int loopCount = 6;
+        do {
+            mTraversalScheduled = false;
+            performLayoutAndPlaceSurfacesLockedLoop();
+            mH.removeMessages(H.DO_TRAVERSAL);
+            loopCount--;
+        } while (mTraversalScheduled && loopCount > 0);
+        mInnerFields.mWallpaperActionPending = false;
+    }
+
+    private boolean mInLayout = false;
+    private final void performLayoutAndPlaceSurfacesLockedLoop() {
+        if (mInLayout) {
+            if (DEBUG) {
+                throw new RuntimeException("Recursive call!");
+            }
+            Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers="
+                    + Debug.getCallers(3));
+            return;
+        }
+
+        if (mWaitingForConfig) {
+            // Our configuration has changed (most likely rotation), but we
+            // don't yet have the complete configuration to report to
+            // applications.  Don't do any window layout until we have it.
+            return;
+        }
+
+        if (!mDisplayReady) {
+            // Not yet initialized, nothing to do.
+            return;
+        }
+
+        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout");
+        mInLayout = true;
+        boolean recoveringMemory = false;
+
+        try {
+            if (mForceRemoves != null) {
+                recoveringMemory = true;
+                // Wait a little bit for things to settle down, and off we go.
+                for (int i=0; i<mForceRemoves.size(); i++) {
+                    WindowState ws = mForceRemoves.get(i);
+                    Slog.i(TAG, "Force removing: " + ws);
+                    removeWindowInnerLocked(ws.mSession, ws);
+                }
+                mForceRemoves = null;
+                Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
+                Object tmp = new Object();
+                synchronized (tmp) {
+                    try {
+                        tmp.wait(250);
+                    } catch (InterruptedException e) {
+                    }
+                }
+            }
+        } catch (RuntimeException e) {
+            Log.wtf(TAG, "Unhandled exception while force removing for memory", e);
+        }
+
+        try {
+            performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
+
+            mInLayout = false;
+
+            if (needsLayout()) {
+                if (++mLayoutRepeatCount < 6) {
+                    requestTraversalLocked();
+                } else {
+                    Slog.e(TAG, "Performed 6 layouts in a row. Skipping");
+                    mLayoutRepeatCount = 0;
+                }
+            } else {
+                mLayoutRepeatCount = 0;
+            }
+
+            if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
+                mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
+                mH.sendEmptyMessage(H.REPORT_WINDOWS_CHANGE);
+            }
+        } catch (RuntimeException e) {
+            mInLayout = false;
+            Log.wtf(TAG, "Unhandled exception while laying out windows", e);
+        }
+
+        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
+    }
+
+    private final void performLayoutLockedInner(final DisplayContent displayContent,
+                                    boolean initial, boolean updateInputWindows) {
+        if (!displayContent.layoutNeeded) {
+            return;
+        }
+        displayContent.layoutNeeded = false;
+        WindowList windows = displayContent.getWindowList();
+        boolean isDefaultDisplay = displayContent.isDefaultDisplay;
+
+        DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        final int dw = displayInfo.logicalWidth;
+        final int dh = displayInfo.logicalHeight;
+
+        final int NFW = mFakeWindows.size();
+        for (int i=0; i<NFW; i++) {
+            mFakeWindows.get(i).layout(dw, dh);
+        }
+
+        final int N = windows.size();
+        int i;
+
+        if (DEBUG_LAYOUT) {
+            Slog.v(TAG, "-------------------------------------");
+            Slog.v(TAG, "performLayout: needed="
+                    + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh);
+        }
+
+        WindowStateAnimator universeBackground = null;
+
+        mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mRotation);
+        if (isDefaultDisplay) {
+            // Not needed on non-default displays.
+            mSystemDecorLayer = mPolicy.getSystemDecorLayerLw();
+            mScreenRect.set(0, 0, dw, dh);
+        }
+
+        mPolicy.getContentRectLw(mTmpContentRect);
+        displayContent.resize(mTmpContentRect);
+
+        int seq = mLayoutSeq+1;
+        if (seq < 0) seq = 0;
+        mLayoutSeq = seq;
+
+        boolean behindDream = false;
+
+        // First perform layout of any root windows (not attached
+        // to another window).
+        int topAttached = -1;
+        for (i = N-1; i >= 0; i--) {
+            final WindowState win = windows.get(i);
+
+            // Don't do layout of a window if it is not visible, or
+            // soon won't be visible, to avoid wasting time and funky
+            // changes while a window is animating away.
+            final boolean gone = (behindDream && mPolicy.canBeForceHidden(win, win.mAttrs))
+                    || win.isGoneForLayoutLw();
+
+            if (DEBUG_LAYOUT && !win.mLayoutAttached) {
+                Slog.v(TAG, "1ST PASS " + win
+                        + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
+                        + " mLayoutAttached=" + win.mLayoutAttached
+                        + " screen changed=" + win.isConfigChanged());
+                final AppWindowToken atoken = win.mAppToken;
+                if (gone) Slog.v(TAG, "  GONE: mViewVisibility="
+                        + win.mViewVisibility + " mRelayoutCalled="
+                        + win.mRelayoutCalled + " hidden="
+                        + win.mRootToken.hidden + " hiddenRequested="
+                        + (atoken != null && atoken.hiddenRequested)
+                        + " mAttachedHidden=" + win.mAttachedHidden);
+                else Slog.v(TAG, "  VIS: mViewVisibility="
+                        + win.mViewVisibility + " mRelayoutCalled="
+                        + win.mRelayoutCalled + " hidden="
+                        + win.mRootToken.hidden + " hiddenRequested="
+                        + (atoken != null && atoken.hiddenRequested)
+                        + " mAttachedHidden=" + win.mAttachedHidden);
+            }
+
+            // If this view is GONE, then skip it -- keep the current
+            // frame, and let the caller know so they can ignore it
+            // if they want.  (We do the normal layout for INVISIBLE
+            // windows, since that means "perform layout as normal,
+            // just don't display").
+            if (!gone || !win.mHaveFrame || win.mLayoutNeeded
+                    || ((win.isConfigChanged() || win.setInsetsChanged()) &&
+                            (win.mAttrs.type == TYPE_KEYGUARD ||
+                            win.mAppToken != null && win.mAppToken.layoutConfigChanges))
+                    || win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) {
+                if (!win.mLayoutAttached) {
+                    if (initial) {
+                        //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
+                        win.mContentChanged = false;
+                    }
+                    if (win.mAttrs.type == TYPE_DREAM) {
+                        // Don't layout windows behind a dream, so that if it
+                        // does stuff like hide the status bar we won't get a
+                        // bad transition when it goes away.
+                        behindDream = true;
+                    }
+                    win.mLayoutNeeded = false;
+                    win.prelayout();
+                    mPolicy.layoutWindowLw(win, win.mAttrs, null);
+                    win.mLayoutSeq = seq;
+                    if (DEBUG_LAYOUT) Slog.v(TAG, "  LAYOUT: mFrame="
+                            + win.mFrame + " mContainingFrame="
+                            + win.mContainingFrame + " mDisplayFrame="
+                            + win.mDisplayFrame);
+                } else {
+                    if (topAttached < 0) topAttached = i;
+                }
+            }
+            if (win.mViewVisibility == View.VISIBLE
+                    && win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND
+                    && universeBackground == null) {
+                universeBackground = win.mWinAnimator;
+            }
+        }
+
+        if (mAnimator.mUniverseBackground  != universeBackground) {
+            mFocusMayChange = true;
+            mAnimator.mUniverseBackground = universeBackground;
+        }
+
+        boolean attachedBehindDream = false;
+
+        // Now perform layout of attached windows, which usually
+        // depend on the position of the window they are attached to.
+        // XXX does not deal with windows that are attached to windows
+        // that are themselves attached.
+        for (i = topAttached; i >= 0; i--) {
+            final WindowState win = windows.get(i);
+
+            if (win.mLayoutAttached) {
+                if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win
+                        + " mHaveFrame=" + win.mHaveFrame
+                        + " mViewVisibility=" + win.mViewVisibility
+                        + " mRelayoutCalled=" + win.mRelayoutCalled);
+                // If this view is GONE, then skip it -- keep the current
+                // frame, and let the caller know so they can ignore it
+                // if they want.  (We do the normal layout for INVISIBLE
+                // windows, since that means "perform layout as normal,
+                // just don't display").
+                if (attachedBehindDream && mPolicy.canBeForceHidden(win, win.mAttrs)) {
+                    continue;
+                }
+                if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
+                        || !win.mHaveFrame || win.mLayoutNeeded) {
+                    if (initial) {
+                        //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
+                        win.mContentChanged = false;
+                    }
+                    win.mLayoutNeeded = false;
+                    win.prelayout();
+                    mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
+                    win.mLayoutSeq = seq;
+                    if (DEBUG_LAYOUT) Slog.v(TAG, "  LAYOUT: mFrame="
+                            + win.mFrame + " mContainingFrame="
+                            + win.mContainingFrame + " mDisplayFrame="
+                            + win.mDisplayFrame);
+                }
+            } else if (win.mAttrs.type == TYPE_DREAM) {
+                // Don't layout windows behind a dream, so that if it
+                // does stuff like hide the status bar we won't get a
+                // bad transition when it goes away.
+                attachedBehindDream = behindDream;
+            }
+        }
+
+        // Window frames may have changed.  Tell the input dispatcher about it.
+        mInputMonitor.setUpdateInputWindowsNeededLw();
+        if (updateInputWindows) {
+            mInputMonitor.updateInputWindowsLw(false /*force*/);
+        }
+
+        mPolicy.finishLayoutLw();
+    }
+
+    void makeWindowFreezingScreenIfNeededLocked(WindowState w) {
+        // If the screen is currently frozen or off, then keep
+        // it frozen/off until this window draws at its new
+        // orientation.
+        if (!okToDisplay()) {
+            if (DEBUG_ORIENTATION) Slog.v(TAG, "Changing surface while display frozen: " + w);
+            w.mOrientationChanging = true;
+            w.mLastFreezeDuration = 0;
+            mInnerFields.mOrientationChangeComplete = false;
+            if (!mWindowsFreezingScreen) {
+                mWindowsFreezingScreen = true;
+                // XXX should probably keep timeout from
+                // when we first froze the display.
+                mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
+                mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT,
+                        WINDOW_FREEZE_TIMEOUT_DURATION);
+            }
+        }
+    }
+
+    /**
+     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
+     * @param windows List of windows on default display.
+     * @return bitmap indicating if another pass through layout must be made.
+     */
+    public int handleAppTransitionReadyLocked(WindowList windows) {
+        int changes = 0;
+        int i;
+        int NN = mOpeningApps.size();
+        boolean goodToGo = true;
+        if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
+                "Checking " + NN + " opening apps (frozen="
+                + mDisplayFrozen + " timeout="
+                + mAppTransition.isTimeout() + ")...");
+        if (!mDisplayFrozen && !mAppTransition.isTimeout()) {
+            // If the display isn't frozen, wait to do anything until
+            // all of the apps are ready.  Otherwise just go because
+            // we'll unfreeze the display when everyone is ready.
+            for (i=0; i<NN && goodToGo; i++) {
+                AppWindowToken wtoken = mOpeningApps.get(i);
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
+                        "Check opening app=" + wtoken + ": allDrawn="
+                        + wtoken.allDrawn + " startingDisplayed="
+                        + wtoken.startingDisplayed + " startingMoved="
+                        + wtoken.startingMoved);
+                if (!wtoken.allDrawn && !wtoken.startingDisplayed
+                        && !wtoken.startingMoved) {
+                    goodToGo = false;
+                }
+            }
+        }
+        if (goodToGo) {
+            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
+            int transit = mAppTransition.getAppTransition();
+            if (mSkipAppTransitionAnimation) {
+                transit = AppTransition.TRANSIT_UNSET;
+            }
+            mAppTransition.goodToGo();
+            mStartingIconInTransition = false;
+            mSkipAppTransitionAnimation = false;
+
+            mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
+
+            rebuildAppWindowListLocked();
+
+            // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
+            WindowState oldWallpaper =
+                    mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating()
+                        && !mWallpaperTarget.mWinAnimator.isDummyAnimation()
+                    ? null : mWallpaperTarget;
+
+            mInnerFields.mWallpaperMayChange = false;
+
+            // The top-most window will supply the layout params,
+            // and we will determine it below.
+            LayoutParams animLp = null;
+            int bestAnimLayer = -1;
+            boolean fullscreenAnim = false;
+
+            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
+                    "New wallpaper target=" + mWallpaperTarget
+                    + ", oldWallpaper=" + oldWallpaper
+                    + ", lower target=" + mLowerWallpaperTarget
+                    + ", upper target=" + mUpperWallpaperTarget);
+
+            boolean openingAppHasWallpaper = false;
+            boolean closingAppHasWallpaper = false;
+            final AppWindowToken lowerWallpaperAppToken;
+            final AppWindowToken upperWallpaperAppToken;
+            if (mLowerWallpaperTarget == null) {
+                lowerWallpaperAppToken = upperWallpaperAppToken = null;
+            } else {
+                lowerWallpaperAppToken = mLowerWallpaperTarget.mAppToken;
+                upperWallpaperAppToken = mUpperWallpaperTarget.mAppToken;
+            }
+
+            // Do a first pass through the tokens for two
+            // things:
+            // (1) Determine if both the closing and opening
+            // app token sets are wallpaper targets, in which
+            // case special animations are needed
+            // (since the wallpaper needs to stay static
+            // behind them).
+            // (2) Find the layout params of the top-most
+            // application window in the tokens, which is
+            // what will control the animation theme.
+            final int NC = mClosingApps.size();
+            NN = NC + mOpeningApps.size();
+            for (i=0; i<NN; i++) {
+                final AppWindowToken wtoken;
+                if (i < NC) {
+                    wtoken = mClosingApps.get(i);
+                    if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
+                        closingAppHasWallpaper = true;
+                    }
+                } else {
+                    wtoken = mOpeningApps.get(i - NC);
+                    if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
+                        openingAppHasWallpaper = true;
+                    }
+                }
+
+                if (wtoken.appFullscreen) {
+                    WindowState ws = wtoken.findMainWindow();
+                    if (ws != null) {
+                        animLp = ws.mAttrs;
+                        bestAnimLayer = ws.mLayer;
+                        fullscreenAnim = true;
+                    }
+                } else if (!fullscreenAnim) {
+                    WindowState ws = wtoken.findMainWindow();
+                    if (ws != null) {
+                        if (ws.mLayer > bestAnimLayer) {
+                            animLp = ws.mAttrs;
+                            bestAnimLayer = ws.mLayer;
+                        }
+                    }
+                }
+            }
+
+            mAnimateWallpaperWithTarget = false;
+            if (closingAppHasWallpaper && openingAppHasWallpaper) {
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Wallpaper animation!");
+                switch (transit) {
+                    case AppTransition.TRANSIT_ACTIVITY_OPEN:
+                    case AppTransition.TRANSIT_TASK_OPEN:
+                    case AppTransition.TRANSIT_TASK_TO_FRONT:
+                        transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN;
+                        break;
+                    case AppTransition.TRANSIT_ACTIVITY_CLOSE:
+                    case AppTransition.TRANSIT_TASK_CLOSE:
+                    case AppTransition.TRANSIT_TASK_TO_BACK:
+                        transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE;
+                        break;
+                }
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit: " + transit);
+            } else if ((oldWallpaper != null) && !mOpeningApps.isEmpty()
+                    && !mOpeningApps.contains(oldWallpaper.mAppToken)) {
+                // We are transitioning from an activity with
+                // a wallpaper to one without.
+                transit = AppTransition.TRANSIT_WALLPAPER_CLOSE;
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
+                        "New transit away from wallpaper: " + transit);
+            } else if (mWallpaperTarget != null && mWallpaperTarget.isVisibleLw()) {
+                // We are transitioning from an activity without
+                // a wallpaper to now showing the wallpaper
+                transit = AppTransition.TRANSIT_WALLPAPER_OPEN;
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
+                        "New transit into wallpaper: " + transit);
+            } else {
+                mAnimateWallpaperWithTarget = true;
+            }
+
+            // If all closing windows are obscured, then there is
+            // no need to do an animation.  This is the case, for
+            // example, when this transition is being done behind
+            // the lock screen.
+            if (!mPolicy.allowAppAnimationsLw()) {
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
+                        "Animations disallowed by keyguard or dream.");
+                animLp = null;
+            }
+
+            AppWindowToken topOpeningApp = null;
+            int topOpeningLayer = 0;
+
+            NN = mOpeningApps.size();
+            for (i=0; i<NN; i++) {
+                AppWindowToken wtoken = mOpeningApps.get(i);
+                final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken);
+                appAnimator.clearThumbnail();
+                wtoken.inPendingTransaction = false;
+                appAnimator.animation = null;
+                setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
+                wtoken.updateReportedVisibilityLocked();
+                wtoken.waitingToShow = false;
+
+                appAnimator.mAllAppWinAnimators.clear();
+                final int N = wtoken.allAppWindows.size();
+                for (int j = 0; j < N; j++) {
+                    appAnimator.mAllAppWinAnimators.add(wtoken.allAppWindows.get(j).mWinAnimator);
+                }
+                mAnimator.mAnimating |= appAnimator.showAllWindowsLocked();
+
+                if (animLp != null) {
+                    int layer = -1;
+                    for (int j=0; j<wtoken.windows.size(); j++) {
+                        WindowState win = wtoken.windows.get(j);
+                        if (win.mWinAnimator.mAnimLayer > layer) {
+                            layer = win.mWinAnimator.mAnimLayer;
+                        }
+                    }
+                    if (topOpeningApp == null || layer > topOpeningLayer) {
+                        topOpeningApp = wtoken;
+                        topOpeningLayer = layer;
+                    }
+                }
+            }
+            NN = mClosingApps.size();
+            for (i=0; i<NN; i++) {
+                AppWindowToken wtoken = mClosingApps.get(i);
+                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken);
+                wtoken.mAppAnimator.clearThumbnail();
+                wtoken.inPendingTransaction = false;
+                wtoken.mAppAnimator.animation = null;
+                setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
+                wtoken.updateReportedVisibilityLocked();
+                wtoken.waitingToHide = false;
+                // Force the allDrawn flag, because we want to start
+                // this guy's animations regardless of whether it's
+                // gotten drawn.
+                wtoken.allDrawn = true;
+                wtoken.deferClearAllDrawn = false;
+            }
+
+            AppWindowAnimator appAnimator =
+                    topOpeningApp == null ? null : topOpeningApp.mAppAnimator;
+            Bitmap nextAppTransitionThumbnail = mAppTransition.getNextAppTransitionThumbnail();
+            if (nextAppTransitionThumbnail != null && appAnimator != null
+                    && appAnimator.animation != null) {
+                // This thumbnail animation is very special, we need to have
+                // an extra surface with the thumbnail included with the animation.
+                Rect dirty = new Rect(0, 0, nextAppTransitionThumbnail.getWidth(),
+                        nextAppTransitionThumbnail.getHeight());
+                try {
+                    // TODO(multi-display): support other displays
+                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
+                    final Display display = displayContent.getDisplay();
+                    SurfaceControl surfaceControl = new SurfaceControl(mFxSession,
+                            "thumbnail anim",
+                            dirty.width(), dirty.height(),
+                            PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
+                    surfaceControl.setLayerStack(display.getLayerStack());
+                    appAnimator.thumbnail = surfaceControl;
+                    if (SHOW_TRANSACTIONS) Slog.i(TAG, "  THUMBNAIL " + surfaceControl + ": CREATE");
+                    Surface drawSurface = new Surface();
+                    drawSurface.copyFrom(surfaceControl);
+                    Canvas c = drawSurface.lockCanvas(dirty);
+                    c.drawBitmap(nextAppTransitionThumbnail, 0, 0, null);
+                    drawSurface.unlockCanvasAndPost(c);
+                    drawSurface.release();
+                    appAnimator.thumbnailLayer = topOpeningLayer;
+                    DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
+                    Animation anim = mAppTransition.createThumbnailAnimationLocked(
+                            transit, true, true, displayInfo.appWidth, displayInfo.appHeight);
+                    appAnimator.thumbnailAnimation = anim;
+                    anim.restrictDuration(MAX_ANIMATION_DURATION);
+                    anim.scaleCurrentDuration(mTransitionAnimationScale);
+                    Point p = new Point();
+                    mAppTransition.getStartingPoint(p);
+                    appAnimator.thumbnailX = p.x;
+                    appAnimator.thumbnailY = p.y;
+                } catch (OutOfResourcesException e) {
+                    Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w=" + dirty.width()
+                            + " h=" + dirty.height(), e);
+                    appAnimator.clearThumbnail();
+                }
+            }
+
+            mAppTransition.postAnimationCallback();
+            mAppTransition.clear();
+
+            mOpeningApps.clear();
+            mClosingApps.clear();
+
+            // This has changed the visibility of windows, so perform
+            // a new layout to get them all up-to-date.
+            changes |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT
+                    | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
+            getDefaultDisplayContentLocked().layoutNeeded = true;
+
+            // TODO(multidisplay): IMEs are only supported on the default display.
+            if (windows == getDefaultWindowListLocked()
+                    && !moveInputMethodWindowsIfNeededLocked(true)) {
+                assignLayersLocked(windows);
+            }
+            updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false /*updateInputWindows*/);
+            mFocusMayChange = false;
+        }
+
+        return changes;
+    }
+
+    /**
+     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
+     * @return bitmap indicating if another pass through layout must be made.
+     */
+    private int handleAnimatingStoppedAndTransitionLocked() {
+        int changes = 0;
+
+        mAppTransition.setIdle();
+        // Restore window app tokens to the ActivityManager views
+        ArrayList<TaskStack> stacks = getDefaultDisplayContentLocked().getStacks();
+        for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks();
+            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                    tokens.get(tokenNdx).sendingToBottom = false;
+                }
+            }
+        }
+        rebuildAppWindowListLocked();
+
+        changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
+        if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
+                "Wallpaper layer changed: assigning layers + relayout");
+        moveInputMethodWindowsIfNeededLocked(true);
+        mInnerFields.mWallpaperMayChange = true;
+        // Since the window list has been rebuilt, focus might
+        // have to be recomputed since the actual order of windows
+        // might have changed again.
+        mFocusMayChange = true;
+
+        return changes;
+    }
+
+    private void updateResizingWindows(final WindowState w) {
+        final WindowStateAnimator winAnimator = w.mWinAnimator;
+        if (w.mHasSurface && w.mLayoutSeq == mLayoutSeq) {
+            w.setInsetsChanged();
+            boolean configChanged = w.isConfigChanged();
+            if (DEBUG_CONFIGURATION && configChanged) {
+                Slog.v(TAG, "Win " + w + " config changed: "
+                        + mCurConfiguration);
+            }
+            if (localLOGV) Slog.v(TAG, "Resizing " + w
+                    + ": configChanged=" + configChanged
+                    + " last=" + w.mLastFrame + " frame=" + w.mFrame);
+            w.mLastFrame.set(w.mFrame);
+            if (w.mContentInsetsChanged
+                    || w.mVisibleInsetsChanged
+                    || winAnimator.mSurfaceResized
+                    || configChanged) {
+                if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
+                    Slog.v(TAG, "Resize reasons for w=" + w + ": "
+                            + " contentInsetsChanged=" + w.mContentInsetsChanged
+                            + " " + w.mContentInsets.toShortString()
+                            + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
+                            + " " + w.mVisibleInsets.toShortString()
+                            + " surfaceResized=" + winAnimator.mSurfaceResized
+                            + " configChanged=" + configChanged);
+                }
+
+                w.mLastOverscanInsets.set(w.mOverscanInsets);
+                w.mLastContentInsets.set(w.mContentInsets);
+                w.mLastVisibleInsets.set(w.mVisibleInsets);
+                makeWindowFreezingScreenIfNeededLocked(w);
+                // If the orientation is changing, then we need to
+                // hold off on unfreezing the display until this
+                // window has been redrawn; to do that, we need
+                // to go through the process of getting informed
+                // by the application when it has finished drawing.
+                if (w.mOrientationChanging) {
+                    if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION) Slog.v(TAG,
+                            "Orientation start waiting for draw mDrawState=DRAW_PENDING in "
+                            + w + ", surface " + winAnimator.mSurfaceControl);
+                    winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
+                    if (w.mAppToken != null) {
+                        w.mAppToken.allDrawn = false;
+                        w.mAppToken.deferClearAllDrawn = false;
+                    }
+                }
+                if (!mResizingWindows.contains(w)) {
+                    if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
+                            "Resizing window " + w + " to " + winAnimator.mSurfaceW
+                            + "x" + winAnimator.mSurfaceH);
+                    mResizingWindows.add(w);
+                }
+            } else if (w.mOrientationChanging) {
+                if (w.isDrawnLw()) {
+                    if (DEBUG_ORIENTATION) Slog.v(TAG,
+                            "Orientation not waiting for draw in "
+                            + w + ", surface " + winAnimator.mSurfaceControl);
+                    w.mOrientationChanging = false;
+                    w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
+                            - mDisplayFreezeTime);
+                }
+            }
+        }
+    }
+
+    /**
+     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
+     *
+     * @param w WindowState this method is applied to.
+     * @param currentTime The time which animations use for calculating transitions.
+     * @param innerDw Width of app window.
+     * @param innerDh Height of app window.
+     */
+    private void handleNotObscuredLocked(final WindowState w, final long currentTime,
+                                         final int innerDw, final int innerDh) {
+        final WindowManager.LayoutParams attrs = w.mAttrs;
+        final int attrFlags = attrs.flags;
+        final boolean canBeSeen = w.isDisplayedLw();
+        final boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
+
+        if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) {
+            // This window completely covers everything behind it,
+            // so we want to leave all of them as undimmed (for
+            // performance reasons).
+            mInnerFields.mObscured = true;
+        }
+
+        if (w.mHasSurface) {
+            if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
+                mInnerFields.mHoldScreen = w.mSession;
+            }
+            if (!mInnerFields.mSyswin && w.mAttrs.screenBrightness >= 0
+                    && mInnerFields.mScreenBrightness < 0) {
+                mInnerFields.mScreenBrightness = w.mAttrs.screenBrightness;
+            }
+            if (!mInnerFields.mSyswin && w.mAttrs.buttonBrightness >= 0
+                    && mInnerFields.mButtonBrightness < 0) {
+                mInnerFields.mButtonBrightness = w.mAttrs.buttonBrightness;
+            }
+            if (!mInnerFields.mSyswin && w.mAttrs.userActivityTimeout >= 0
+                    && mInnerFields.mUserActivityTimeout < 0) {
+                mInnerFields.mUserActivityTimeout = w.mAttrs.userActivityTimeout;
+            }
+
+            final int type = attrs.type;
+            if (canBeSeen
+                    && (type == TYPE_SYSTEM_DIALOG
+                     || type == TYPE_RECENTS_OVERLAY
+                     || type == TYPE_KEYGUARD
+                     || type == TYPE_SYSTEM_ERROR)) {
+                mInnerFields.mSyswin = true;
+            }
+
+            if (canBeSeen) {
+                // This function assumes that the contents of the default display are
+                // processed first before secondary displays.
+                final DisplayContent displayContent = w.getDisplayContent();
+                if (displayContent != null && displayContent.isDefaultDisplay) {
+                    // While a dream or keyguard is showing, obscure ordinary application
+                    // content on secondary displays (by forcibly enabling mirroring unless
+                    // there is other content we want to show) but still allow opaque
+                    // keyguard dialogs to be shown.
+                    if (type == TYPE_DREAM || type == TYPE_KEYGUARD) {
+                        mInnerFields.mObscureApplicationContentOnSecondaryDisplays = true;
+                    }
+                    mInnerFields.mDisplayHasContent = true;
+                } else if (displayContent != null &&
+                        (!mInnerFields.mObscureApplicationContentOnSecondaryDisplays
+                        || (mInnerFields.mObscured && type == TYPE_KEYGUARD_DIALOG))) {
+                    // Allow full screen keyguard presentation dialogs to be seen.
+                    mInnerFields.mDisplayHasContent = true;
+                }
+            }
+        }
+    }
+
+    private void handleFlagDimBehind(WindowState w) {
+        final WindowManager.LayoutParams attrs = w.mAttrs;
+        if ((attrs.flags & FLAG_DIM_BEHIND) != 0
+                && w.isDisplayedLw()
+                && !w.mExiting) {
+            final WindowStateAnimator winAnimator = w.mWinAnimator;
+            final TaskStack stack = w.getStack();
+            stack.setDimmingTag();
+            if (!stack.isDimming(winAnimator)) {
+                if (localLOGV) Slog.v(TAG, "Win " + w + " start dimming.");
+                stack.startDimmingIfNeeded(winAnimator);
+            }
+        }
+    }
+
+    private void updateAllDrawnLocked(DisplayContent displayContent) {
+        // See if any windows have been drawn, so they (and others
+        // associated with them) can now be shown.
+        ArrayList<TaskStack> stacks = displayContent.getStacks();
+        for (int stackNdx = stacks.size() - 1; stackNdx >= 0; --stackNdx) {
+            final ArrayList<Task> tasks = stacks.get(stackNdx).getTasks();
+            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                    final AppWindowToken wtoken = tokens.get(tokenNdx);
+                    if (!wtoken.allDrawn) {
+                        int numInteresting = wtoken.numInterestingWindows;
+                        if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
+                            if (DEBUG_VISIBILITY) Slog.v(TAG,
+                                    "allDrawn: " + wtoken
+                                    + " interesting=" + numInteresting
+                                    + " drawn=" + wtoken.numDrawnWindows);
+                            wtoken.allDrawn = true;
+                            mH.obtainMessage(H.NOTIFY_ACTIVITY_DRAWN, wtoken.token).sendToTarget();
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // "Something has changed!  Let's make it correct now."
+    private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMemory) {
+        if (DEBUG_WINDOW_TRACE) {
+            Slog.v(TAG, "performLayoutAndPlaceSurfacesLockedInner: entry. Called by "
+                    + Debug.getCallers(3));
+        }
+
+        final long currentTime = SystemClock.uptimeMillis();
+
+        int i;
+
+        if (mFocusMayChange) {
+            mFocusMayChange = false;
+            updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
+                    false /*updateInputWindows*/);
+        }
+
+        // Initialize state of exiting tokens.
+        final int numDisplays = mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+            for (i=displayContent.mExitingTokens.size()-1; i>=0; i--) {
+                displayContent.mExitingTokens.get(i).hasVisible = false;
+            }
+        }
+
+        for (int stackNdx = mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
+            // Initialize state of exiting applications.
+            final AppTokenList exitingAppTokens =
+                    mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
+            for (int tokenNdx = exitingAppTokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
+                exitingAppTokens.get(tokenNdx).hasVisible = false;
+            }
+        }
+
+        mInnerFields.mHoldScreen = null;
+        mInnerFields.mScreenBrightness = -1;
+        mInnerFields.mButtonBrightness = -1;
+        mInnerFields.mUserActivityTimeout = -1;
+        mInnerFields.mObscureApplicationContentOnSecondaryDisplays = false;
+
+        mTransactionSequence++;
+
+        final DisplayContent defaultDisplay = getDefaultDisplayContentLocked();
+        final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
+        final int defaultDw = defaultInfo.logicalWidth;
+        final int defaultDh = defaultInfo.logicalHeight;
+
+        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
+        SurfaceControl.openTransaction();
+        try {
+
+            if (mWatermark != null) {
+                mWatermark.positionSurface(defaultDw, defaultDh);
+            }
+            if (mStrictModeFlash != null) {
+                mStrictModeFlash.positionSurface(defaultDw, defaultDh);
+            }
+
+            boolean focusDisplayed = false;
+
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+                boolean updateAllDrawn = false;
+                WindowList windows = displayContent.getWindowList();
+                DisplayInfo displayInfo = displayContent.getDisplayInfo();
+                final int displayId = displayContent.getDisplayId();
+                final int dw = displayInfo.logicalWidth;
+                final int dh = displayInfo.logicalHeight;
+                final int innerDw = displayInfo.appWidth;
+                final int innerDh = displayInfo.appHeight;
+                final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
+
+                // Reset for each display.
+                mInnerFields.mDisplayHasContent = false;
+
+                int repeats = 0;
+                do {
+                    repeats++;
+                    if (repeats > 6) {
+                        Slog.w(TAG, "Animation repeat aborted after too many iterations");
+                        displayContent.layoutNeeded = false;
+                        break;
+                    }
+
+                    if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("On entry to LockedInner",
+                        displayContent.pendingLayoutChanges);
+
+                    if ((displayContent.pendingLayoutChanges &
+                            WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
+                            (adjustWallpaperWindowsLocked() &
+                                    ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
+                        assignLayersLocked(windows);
+                        displayContent.layoutNeeded = true;
+                    }
+
+                    if (isDefaultDisplay && (displayContent.pendingLayoutChanges
+                            & WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
+                        if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
+                        if (updateOrientationFromAppTokensLocked(true)) {
+                            displayContent.layoutNeeded = true;
+                            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+                        }
+                    }
+
+                    if ((displayContent.pendingLayoutChanges
+                            & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
+                        displayContent.layoutNeeded = true;
+                    }
+
+                    // FIRST LOOP: Perform a layout, if needed.
+                    if (repeats < 4) {
+                        performLayoutLockedInner(displayContent, repeats == 1,
+                                false /*updateInputWindows*/);
+                    } else {
+                        Slog.w(TAG, "Layout repeat skipped after too many iterations");
+                    }
+
+                    // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think
+                    // it is animating.
+                    displayContent.pendingLayoutChanges = 0;
+
+                    if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("loop number "
+                            + mLayoutRepeatCount, displayContent.pendingLayoutChanges);
+
+                    if (isDefaultDisplay) {
+                        mPolicy.beginPostLayoutPolicyLw(dw, dh);
+                        for (i = windows.size() - 1; i >= 0; i--) {
+                            WindowState w = windows.get(i);
+                            if (w.mHasSurface) {
+                                mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs);
+                            }
+                        }
+                        displayContent.pendingLayoutChanges |= mPolicy.finishPostLayoutPolicyLw();
+                        if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats(
+                            "after finishPostLayoutPolicyLw", displayContent.pendingLayoutChanges);
+                    }
+                } while (displayContent.pendingLayoutChanges != 0);
+
+                mInnerFields.mObscured = false;
+                mInnerFields.mSyswin = false;
+                displayContent.resetDimming();
+
+                // Only used if default window
+                final boolean someoneLosingFocus = !mLosingFocus.isEmpty();
+
+                final int N = windows.size();
+                for (i=N-1; i>=0; i--) {
+                    WindowState w = windows.get(i);
+                    final TaskStack stack = w.getStack();
+                    if (stack == null) {
+                        continue;
+                    }
+
+                    final boolean obscuredChanged = w.mObscured != mInnerFields.mObscured;
+
+                    // Update effect.
+                    w.mObscured = mInnerFields.mObscured;
+                    if (!mInnerFields.mObscured) {
+                        handleNotObscuredLocked(w, currentTime, innerDw, innerDh);
+                    }
+
+                    if (!stack.testDimmingTag()) {
+                        handleFlagDimBehind(w);
+                    }
+
+                    if (isDefaultDisplay && obscuredChanged && (mWallpaperTarget == w)
+                            && w.isVisibleLw()) {
+                        // This is the wallpaper target and its obscured state
+                        // changed... make sure the current wallaper's visibility
+                        // has been updated accordingly.
+                        updateWallpaperVisibilityLocked();
+                    }
+
+                    final WindowStateAnimator winAnimator = w.mWinAnimator;
+
+                    // If the window has moved due to its containing
+                    // content frame changing, then we'd like to animate
+                    // it.
+                    if (w.mHasSurface && w.shouldAnimateMove()) {
+                        // Frame has moved, containing content frame
+                        // has also moved, and we're not currently animating...
+                        // let's do something.
+                        Animation a = AnimationUtils.loadAnimation(mContext,
+                                com.android.internal.R.anim.window_move_from_decor);
+                        winAnimator.setAnimation(a);
+                        winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left;
+                        winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top;
+                        try {
+                            w.mClient.moved(w.mFrame.left, w.mFrame.top);
+                        } catch (RemoteException e) {
+                        }
+                    }
+
+                    //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
+                    w.mContentChanged = false;
+
+                    // Moved from updateWindowsAndWallpaperLocked().
+                    if (w.mHasSurface) {
+                        // Take care of the window being ready to display.
+                        final boolean committed =
+                                winAnimator.commitFinishDrawingLocked(currentTime);
+                        if (isDefaultDisplay && committed) {
+                            if (w.mAttrs.type == TYPE_DREAM) {
+                                // HACK: When a dream is shown, it may at that
+                                // point hide the lock screen.  So we need to
+                                // redo the layout to let the phone window manager
+                                // make this happen.
+                                displayContent.pendingLayoutChanges |=
+                                        WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
+                                if (DEBUG_LAYOUT_REPEATS) {
+                                    debugLayoutRepeats(
+                                        "dream and commitFinishDrawingLocked true",
+                                        displayContent.pendingLayoutChanges);
+                                }
+                            }
+                            if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
+                                if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
+                                        "First draw done in potential wallpaper target " + w);
+                                mInnerFields.mWallpaperMayChange = true;
+                                displayContent.pendingLayoutChanges |=
+                                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+                                if (DEBUG_LAYOUT_REPEATS) {
+                                    debugLayoutRepeats(
+                                        "wallpaper and commitFinishDrawingLocked true",
+                                        displayContent.pendingLayoutChanges);
+                                }
+                            }
+                        }
+
+                        winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
+
+                        final AppWindowToken atoken = w.mAppToken;
+                        if (DEBUG_STARTING_WINDOW && atoken != null
+                                && w == atoken.startingWindow) {
+                            Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen="
+                                + w.isOnScreen() + " allDrawn=" + atoken.allDrawn
+                                + " freezingScreen=" + atoken.mAppAnimator.freezingScreen);
+                        }
+                        if (atoken != null
+                                && (!atoken.allDrawn || atoken.mAppAnimator.freezingScreen)) {
+                            if (atoken.lastTransactionSequence != mTransactionSequence) {
+                                atoken.lastTransactionSequence = mTransactionSequence;
+                                atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
+                                atoken.startingDisplayed = false;
+                            }
+                            if ((w.isOnScreen() || winAnimator.mAttrType == TYPE_BASE_APPLICATION)
+                                    && !w.mExiting && !w.mDestroying) {
+                                if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
+                                    Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
+                                            + ", isAnimating=" + winAnimator.isAnimating());
+                                    if (!w.isDrawnLw()) {
+                                        Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceControl
+                                                + " pv=" + w.mPolicyVisibility
+                                                + " mDrawState=" + winAnimator.mDrawState
+                                                + " ah=" + w.mAttachedHidden
+                                                + " th=" + atoken.hiddenRequested
+                                                + " a=" + winAnimator.mAnimating);
+                                    }
+                                }
+                                if (w != atoken.startingWindow) {
+                                    if (!atoken.mAppAnimator.freezingScreen || !w.mAppFreezing) {
+                                        atoken.numInterestingWindows++;
+                                        if (w.isDrawnLw()) {
+                                            atoken.numDrawnWindows++;
+                                            if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
+                                                    "tokenMayBeDrawn: " + atoken
+                                                    + " freezingScreen=" + atoken.mAppAnimator.freezingScreen
+                                                    + " mAppFreezing=" + w.mAppFreezing);
+                                            updateAllDrawn = true;
+                                        }
+                                    }
+                                } else if (w.isDrawnLw()) {
+                                    atoken.startingDisplayed = true;
+                                }
+                            }
+                        }
+                    }
+
+                    if (isDefaultDisplay && someoneLosingFocus && (w == mCurrentFocus)
+                            && w.isDisplayedLw()) {
+                        focusDisplayed = true;
+                    }
+
+                    updateResizingWindows(w);
+                }
+
+                mDisplayManagerInternal.setDisplayHasContent(displayId,
+                        mInnerFields.mDisplayHasContent,
+                        true /* inTraversal, must call performTraversalInTrans... below */);
+
+                getDisplayContentLocked(displayId).stopDimmingIfNeeded();
+
+                if (updateAllDrawn) {
+                    updateAllDrawnLocked(displayContent);
+                }
+            }
+
+            if (focusDisplayed) {
+                mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
+            }
+
+            // Give the display manager a chance to adjust properties
+            // like display rotation if it needs to.
+            mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();
+
+        } catch (RuntimeException e) {
+            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
+        } finally {
+            SurfaceControl.closeTransaction();
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                    "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
+        }
+
+        final WindowList defaultWindows = defaultDisplay.getWindowList();
+
+        // If we are ready to perform an app transition, check through
+        // all of the app tokens to be shown and see if they are ready
+        // to go.
+        if (mAppTransition.isReady()) {
+            defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked(defaultWindows);
+            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAppTransitionReadyLocked",
+                    defaultDisplay.pendingLayoutChanges);
+        }
+
+        if (!mAnimator.mAnimating && mAppTransition.isRunning()) {
+            // We have finished the animation of an app transition.  To do
+            // this, we have delayed a lot of operations like showing and
+            // hiding apps, moving apps in Z-order, etc.  The app token list
+            // reflects the correct Z-order, but the window list may now
+            // be out of sync with it.  So here we will just rebuild the
+            // entire app window list.  Fun!
+            defaultDisplay.pendingLayoutChanges |= handleAnimatingStoppedAndTransitionLocked();
+            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAnimStopAndXitionLock",
+                defaultDisplay.pendingLayoutChanges);
+        }
+
+        if (mInnerFields.mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
+                && !mAppTransition.isReady()) {
+            // At this point, there was a window with a wallpaper that
+            // was force hiding other windows behind it, but now it
+            // is going away.  This may be simple -- just animate
+            // away the wallpaper and its window -- or it may be
+            // hard -- the wallpaper now needs to be shown behind
+            // something that was hidden.
+            defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
+            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after animateAwayWallpaperLocked",
+                defaultDisplay.pendingLayoutChanges);
+        }
+        mInnerFields.mWallpaperForceHidingChanged = false;
+
+        if (mInnerFields.mWallpaperMayChange) {
+            if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change!  Adjusting");
+            defaultDisplay.pendingLayoutChanges |=
+                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("WallpaperMayChange",
+                    defaultDisplay.pendingLayoutChanges);
+        }
+
+        if (mFocusMayChange) {
+            mFocusMayChange = false;
+            if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
+                    false /*updateInputWindows*/)) {
+                defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
+            }
+        }
+
+        if (needsLayout()) {
+            defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
+            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded",
+                    defaultDisplay.pendingLayoutChanges);
+        }
+
+        for (i = mResizingWindows.size() - 1; i >= 0; i--) {
+            WindowState win = mResizingWindows.get(i);
+            if (win.mAppFreezing) {
+                // Don't remove this window until rotation has completed.
+                continue;
+            }
+            win.reportResized();
+            mResizingWindows.remove(i);
+        }
+
+        if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
+                "With display frozen, orientationChangeComplete="
+                + mInnerFields.mOrientationChangeComplete);
+        if (mInnerFields.mOrientationChangeComplete) {
+            if (mWindowsFreezingScreen) {
+                mWindowsFreezingScreen = false;
+                mLastFinishedFreezeSource = mInnerFields.mLastWindowFreezeSource;
+                mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
+            }
+            stopFreezingDisplayLocked();
+        }
+
+        // Destroy the surface of any windows that are no longer visible.
+        boolean wallpaperDestroyed = false;
+        i = mDestroySurface.size();
+        if (i > 0) {
+            do {
+                i--;
+                WindowState win = mDestroySurface.get(i);
+                win.mDestroying = false;
+                if (mInputMethodWindow == win) {
+                    mInputMethodWindow = null;
+                }
+                if (win == mWallpaperTarget) {
+                    wallpaperDestroyed = true;
+                }
+                win.mWinAnimator.destroySurfaceLocked();
+            } while (i > 0);
+            mDestroySurface.clear();
+        }
+
+        // Time to remove any exiting tokens?
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+            ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
+            for (i = exitingTokens.size() - 1; i >= 0; i--) {
+                WindowToken token = exitingTokens.get(i);
+                if (!token.hasVisible) {
+                    exitingTokens.remove(i);
+                    if (token.windowType == TYPE_WALLPAPER) {
+                        mWallpaperTokens.remove(token);
+                    }
+                }
+            }
+        }
+
+        // Time to remove any exiting applications?
+        for (int stackNdx = mStackIdToStack.size() - 1; stackNdx >= 0; --stackNdx) {
+            // Initialize state of exiting applications.
+            final AppTokenList exitingAppTokens =
+                    mStackIdToStack.valueAt(stackNdx).mExitingAppTokens;
+            for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
+                AppWindowToken token = exitingAppTokens.get(i);
+                if (!token.hasVisible && !mClosingApps.contains(token)) {
+                    // Make sure there is no animation running on this token,
+                    // so any windows associated with it will be removed as
+                    // soon as their animations are complete
+                    token.mAppAnimator.clearAnimation();
+                    token.mAppAnimator.animating = false;
+                    if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
+                            "performLayout: App token exiting now removed" + token);
+                    removeAppFromTaskLocked(token);
+                    exitingAppTokens.remove(i);
+                }
+            }
+        }
+
+        if (!mAnimator.mAnimating && mRelayoutWhileAnimating.size() > 0) {
+            for (int j=mRelayoutWhileAnimating.size()-1; j>=0; j--) {
+                try {
+                    mRelayoutWhileAnimating.get(j).mClient.doneAnimating();
+                } catch (RemoteException e) {
+                }
+            }
+            mRelayoutWhileAnimating.clear();
+        }
+
+        if (wallpaperDestroyed) {
+            defaultDisplay.pendingLayoutChanges |=
+                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
+            defaultDisplay.layoutNeeded = true;
+        }
+
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+            if (displayContent.pendingLayoutChanges != 0) {
+                displayContent.layoutNeeded = true;
+            }
+        }
+
+        // Finally update all input windows now that the window changes have stabilized.
+        mInputMonitor.updateInputWindowsLw(true /*force*/);
+
+        setHoldScreenLocked(mInnerFields.mHoldScreen);
+        if (!mDisplayFrozen) {
+            if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) {
+                mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(-1);
+            } else {
+                mPowerManagerInternal.setScreenBrightnessOverrideFromWindowManager(
+                        toBrightnessOverride(mInnerFields.mScreenBrightness));
+            }
+            if (mInnerFields.mButtonBrightness < 0 || mInnerFields.mButtonBrightness > 1.0f) {
+                mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(-1);
+            } else {
+                mPowerManagerInternal.setButtonBrightnessOverrideFromWindowManager(
+                        toBrightnessOverride(mInnerFields.mButtonBrightness));
+            }
+            mPowerManagerInternal.setUserActivityTimeoutOverrideFromWindowManager(
+                    mInnerFields.mUserActivityTimeout);
+        }
+
+        if (mTurnOnScreen) {
+            if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
+            mPowerManager.wakeUp(SystemClock.uptimeMillis());
+            mTurnOnScreen = false;
+        }
+
+        if (mInnerFields.mUpdateRotation) {
+            if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
+            if (updateRotationUncheckedLocked(false)) {
+                mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+            } else {
+                mInnerFields.mUpdateRotation = false;
+            }
+        }
+
+        if (mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded
+                && !mInnerFields.mUpdateRotation) {
+            checkDrawnWindowsLocked();
+        }
+
+        final int N = mPendingRemove.size();
+        if (N > 0) {
+            if (mPendingRemoveTmp.length < N) {
+                mPendingRemoveTmp = new WindowState[N+10];
+            }
+            mPendingRemove.toArray(mPendingRemoveTmp);
+            mPendingRemove.clear();
+            DisplayContentList displayList = new DisplayContentList();
+            for (i = 0; i < N; i++) {
+                WindowState w = mPendingRemoveTmp[i];
+                removeWindowInnerLocked(w.mSession, w);
+                final DisplayContent displayContent = w.getDisplayContent();
+                if (displayContent != null && !displayList.contains(displayContent)) {
+                    displayList.add(displayContent);
+                }
+            }
+
+            for (DisplayContent displayContent : displayList) {
+                assignLayersLocked(displayContent.getWindowList());
+                displayContent.layoutNeeded = true;
+            }
+        }
+
+        // Remove all deferred displays stacks, tasks, and activities.
+        for (int displayNdx = mDisplayContents.size() - 1; displayNdx >= 0; --displayNdx) {
+            mDisplayContents.valueAt(displayNdx).checkForDeferredActions();
+        }
+
+        setFocusedStackFrame();
+
+        // Check to see if we are now in a state where the screen should
+        // be enabled, because the window obscured flags have changed.
+        enableScreenIfNeededLocked();
+
+        scheduleAnimationLocked();
+
+        if (DEBUG_WINDOW_TRACE) {
+            Slog.e(TAG, "performLayoutAndPlaceSurfacesLockedInner exit: animating="
+                    + mAnimator.mAnimating);
+        }
+    }
+
+    private int toBrightnessOverride(float value) {
+        return (int)(value * PowerManager.BRIGHTNESS_ON);
+    }
+
+    void checkDrawnWindowsLocked() {
+        if (mWaitingForDrawn.size() > 0) {
+            for (int j=mWaitingForDrawn.size()-1; j>=0; j--) {
+                Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(j);
+                WindowState win = pair.first;
+                //Slog.i(TAG, "Waiting for drawn " + win + ": removed="
+                //        + win.mRemoved + " visible=" + win.isVisibleLw()
+                //        + " shown=" + win.mSurfaceShown);
+                if (win.mRemoved) {
+                    // Window has been removed; no draw will now happen, so stop waiting.
+                    Slog.w(TAG, "Aborted waiting for drawn: " + pair.first);
+                    try {
+                        pair.second.sendResult(null);
+                    } catch (RemoteException e) {
+                    }
+                    mWaitingForDrawn.remove(pair);
+                    mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
+                } else if (win.mWinAnimator.mSurfaceShown) {
+                    // Window is now drawn (and shown).
+                    try {
+                        pair.second.sendResult(null);
+                    } catch (RemoteException e) {
+                    }
+                    mWaitingForDrawn.remove(pair);
+                    mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
+                }
+            }
+        }
+    }
+
+    @Override
+    public boolean waitForWindowDrawn(IBinder token, IRemoteCallback callback) {
+        if (token != null && callback != null) {
+            synchronized (mWindowMap) {
+                WindowState win = windowForClientLocked(null, token, true);
+                if (win != null) {
+                    Pair<WindowState, IRemoteCallback> pair =
+                            new Pair<WindowState, IRemoteCallback>(win, callback);
+                    Message m = mH.obtainMessage(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
+                    mH.sendMessageDelayed(m, 2000);
+                    mWaitingForDrawn.add(pair);
+                    checkDrawnWindowsLocked();
+                    return true;
+                }
+                Slog.i(TAG, "waitForWindowDrawn: win null");
+            }
+        }
+        return false;
+    }
+
+    void setHoldScreenLocked(final Session newHoldScreen) {
+        final boolean hold = newHoldScreen != null;
+
+        if (hold && mHoldingScreenOn != newHoldScreen) {
+            mHoldingScreenWakeLock.setWorkSource(new WorkSource(newHoldScreen.mUid));
+        }
+        mHoldingScreenOn = newHoldScreen;
+
+        final boolean state = mHoldingScreenWakeLock.isHeld();
+        if (hold != state) {
+            if (hold) {
+                mHoldingScreenWakeLock.acquire();
+                mPolicy.keepScreenOnStartedLw();
+            } else {
+                mPolicy.keepScreenOnStoppedLw();
+                mHoldingScreenWakeLock.release();
+            }
+        }
+    }
+
+    void requestTraversal() {
+        synchronized (mWindowMap) {
+            requestTraversalLocked();
+        }
+    }
+
+    void requestTraversalLocked() {
+        if (!mTraversalScheduled) {
+            mTraversalScheduled = true;
+            mH.sendEmptyMessage(H.DO_TRAVERSAL);
+        }
+    }
+
+    /** Note that Locked in this case is on mLayoutToAnim */
+    void scheduleAnimationLocked() {
+        if (!mAnimationScheduled) {
+            mAnimationScheduled = true;
+            mChoreographer.postCallback(
+                    Choreographer.CALLBACK_ANIMATION, mAnimator.mAnimationRunnable, null);
+        }
+    }
+
+    private boolean needsLayout() {
+        final int numDisplays = mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+            if (displayContent.layoutNeeded) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    boolean copyAnimToLayoutParamsLocked() {
+        boolean doRequest = false;
+
+        final int bulkUpdateParams = mAnimator.mBulkUpdateParams;
+        if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) {
+            mInnerFields.mUpdateRotation = true;
+            doRequest = true;
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) {
+            mInnerFields.mWallpaperMayChange = true;
+            doRequest = true;
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) {
+            mInnerFields.mWallpaperForceHidingChanged = true;
+            doRequest = true;
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
+            mInnerFields.mOrientationChangeComplete = false;
+        } else {
+            mInnerFields.mOrientationChangeComplete = true;
+            mInnerFields.mLastWindowFreezeSource = mAnimator.mLastWindowFreezeSource;
+            if (mWindowsFreezingScreen) {
+                doRequest = true;
+            }
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) {
+            mTurnOnScreen = true;
+        }
+        if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_ACTION_PENDING) != 0) {
+            mInnerFields.mWallpaperActionPending = true;
+        }
+
+        return doRequest;
+    }
+
+    /** If a window that has an animation specifying a colored background and the current wallpaper
+     * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
+     * suddenly disappear. */
+    int adjustAnimationBackground(WindowStateAnimator winAnimator) {
+        WindowList windows = winAnimator.mWin.getWindowList();
+        for (int i = windows.size() - 1; i >= 0; --i) {
+            WindowState testWin = windows.get(i);
+            if (testWin.mIsWallpaper && testWin.isVisibleNow()) {
+                return testWin.mWinAnimator.mAnimLayer;
+            }
+        }
+        return winAnimator.mAnimLayer;
+    }
+
+    boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation,
+                                           boolean secure) {
+        final SurfaceControl surface = winAnimator.mSurfaceControl;
+        boolean leakedSurface = false;
+        boolean killedApps = false;
+
+        EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
+                winAnimator.mSession.mPid, operation);
+
+        if (mForceRemoves == null) {
+            mForceRemoves = new ArrayList<WindowState>();
+        }
+
+        long callingIdentity = Binder.clearCallingIdentity();
+        try {
+            // There was some problem...   first, do a sanity check of the
+            // window list to make sure we haven't left any dangling surfaces
+            // around.
+
+            Slog.i(TAG, "Out of memory for surface!  Looking for leaks...");
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+                final int numWindows = windows.size();
+                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                    final WindowState ws = windows.get(winNdx);
+                    WindowStateAnimator wsa = ws.mWinAnimator;
+                    if (wsa.mSurfaceControl != null) {
+                        if (!mSessions.contains(wsa.mSession)) {
+                            Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
+                                    + ws + " surface=" + wsa.mSurfaceControl
+                                    + " token=" + ws.mToken
+                                    + " pid=" + ws.mSession.mPid
+                                    + " uid=" + ws.mSession.mUid);
+                            if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
+                            wsa.mSurfaceControl.destroy();
+                            wsa.mSurfaceShown = false;
+                            wsa.mSurfaceControl = null;
+                            ws.mHasSurface = false;
+                            mForceRemoves.add(ws);
+                            leakedSurface = true;
+                        } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
+                            Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
+                                    + ws + " surface=" + wsa.mSurfaceControl
+                                    + " token=" + ws.mAppToken);
+                            if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
+                            wsa.mSurfaceControl.destroy();
+                            wsa.mSurfaceShown = false;
+                            wsa.mSurfaceControl = null;
+                            ws.mHasSurface = false;
+                            leakedSurface = true;
+                        }
+                    }
+                }
+            }
+
+            if (!leakedSurface) {
+                Slog.w(TAG, "No leaked surfaces; killing applicatons!");
+                SparseIntArray pidCandidates = new SparseIntArray();
+                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                    final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
+                    final int numWindows = windows.size();
+                    for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
+                        final WindowState ws = windows.get(winNdx);
+                        if (mForceRemoves.contains(ws)) {
+                            continue;
+                        }
+                        WindowStateAnimator wsa = ws.mWinAnimator;
+                        if (wsa.mSurfaceControl != null) {
+                            pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
+                        }
+                    }
+                    if (pidCandidates.size() > 0) {
+                        int[] pids = new int[pidCandidates.size()];
+                        for (int i=0; i<pids.length; i++) {
+                            pids[i] = pidCandidates.keyAt(i);
+                        }
+                        try {
+                            if (mActivityManager.killPids(pids, "Free memory", secure)) {
+                                killedApps = true;
+                            }
+                        } catch (RemoteException e) {
+                        }
+                    }
+                }
+            }
+
+            if (leakedSurface || killedApps) {
+                // We managed to reclaim some memory, so get rid of the trouble
+                // surface and ask the app to request another one.
+                Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
+                if (surface != null) {
+                    if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
+                            "RECOVER DESTROY", null);
+                    surface.destroy();
+                    winAnimator.mSurfaceShown = false;
+                    winAnimator.mSurfaceControl = null;
+                    winAnimator.mWin.mHasSurface = false;
+                    scheduleRemoveStartingWindow(winAnimator.mWin.mAppToken);
+                }
+
+                try {
+                    winAnimator.mWin.mClient.dispatchGetNewSurface();
+                } catch (RemoteException e) {
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(callingIdentity);
+        }
+
+        return leakedSurface || killedApps;
+    }
+
+    private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
+        WindowState newFocus = computeFocusedWindowLocked();
+        if (mCurrentFocus != newFocus) {
+            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus");
+            // This check makes sure that we don't already have the focus
+            // change message pending.
+            mH.removeMessages(H.REPORT_FOCUS_CHANGE);
+            mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
+            // TODO(multidisplay): Focused windows on default display only.
+            final DisplayContent displayContent = getDefaultDisplayContentLocked();
+            final boolean imWindowChanged = moveInputMethodWindowsIfNeededLocked(
+                    mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
+                            && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES);
+            if (imWindowChanged) {
+                displayContent.layoutNeeded = true;
+                newFocus = computeFocusedWindowLocked();
+            }
+
+            if (DEBUG_FOCUS_LIGHT || localLOGV) Slog.v(TAG, "Changing focus from " +
+                    mCurrentFocus + " to " + newFocus + " Callers=" + Debug.getCallers(4));
+            final WindowState oldFocus = mCurrentFocus;
+            mCurrentFocus = newFocus;
+            mLosingFocus.remove(newFocus);
+            int focusChanged = mPolicy.focusChangedLw(oldFocus, newFocus);
+
+            if (imWindowChanged && oldFocus != mInputMethodWindow) {
+                // Focus of the input method window changed. Perform layout if needed.
+                if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
+                    performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows);
+                    focusChanged &= ~WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
+                } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
+                    // Client will do the layout, but we need to assign layers
+                    // for handleNewWindowLocked() below.
+                    assignLayersLocked(displayContent.getWindowList());
+                }
+            }
+
+            if ((focusChanged & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
+                // The change in focus caused us to need to do a layout.  Okay.
+                displayContent.layoutNeeded = true;
+                if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
+                    performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows);
+                }
+            }
+
+            if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
+                // If we defer assigning layers, then the caller is responsible for
+                // doing this part.
+                finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
+            }
+
+            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
+            return true;
+        }
+        return false;
+    }
+
+    private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
+        mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
+    }
+
+    private WindowState computeFocusedWindowLocked() {
+        if (mAnimator.mUniverseBackground != null
+                && mAnimator.mUniverseBackground.mWin.canReceiveKeys()) {
+            return mAnimator.mUniverseBackground.mWin;
+        }
+
+        final int displayCount = mDisplayContents.size();
+        for (int i = 0; i < displayCount; i++) {
+            final DisplayContent displayContent = mDisplayContents.valueAt(i);
+            WindowState win = findFocusedWindowLocked(displayContent);
+            if (win != null) {
+                return win;
+            }
+        }
+        return null;
+    }
+
+    private WindowState findFocusedWindowLocked(DisplayContent displayContent) {
+        final WindowList windows = displayContent.getWindowList();
+        for (int i = windows.size() - 1; i >= 0; i--) {
+            final WindowState win = windows.get(i);
+
+            if (localLOGV || DEBUG_FOCUS) Slog.v(
+                TAG, "Looking for focus: " + i
+                + " = " + win
+                + ", flags=" + win.mAttrs.flags
+                + ", canReceive=" + win.canReceiveKeys());
+
+            AppWindowToken wtoken = win.mAppToken;
+
+            // If this window's application has been removed, just skip it.
+            if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
+                if (DEBUG_FOCUS) Slog.v(TAG, "Skipping " + wtoken + " because "
+                        + (wtoken.removed ? "removed" : "sendingToBottom"));
+                continue;
+            }
+
+            if (!win.canReceiveKeys()) {
+                continue;
+            }
+
+            // Descend through all of the app tokens and find the first that either matches
+            // win.mAppToken (return win) or mFocusedApp (return null).
+            if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING &&
+                    mFocusedApp != null) {
+                ArrayList<Task> tasks = displayContent.getTasks();
+                for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
+                    AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
+                    int tokenNdx = tokens.size() - 1;
+                    for ( ; tokenNdx >= 0; --tokenNdx) {
+                        final AppWindowToken token = tokens.get(tokenNdx);
+                        if (wtoken == token) {
+                            break;
+                        }
+                        if (mFocusedApp == token) {
+                            // Whoops, we are below the focused app...  no focus for you!
+                            if (localLOGV || DEBUG_FOCUS_LIGHT) Slog.v(TAG,
+                                    "findFocusedWindow: Reached focused app=" + mFocusedApp);
+                            return null;
+                        }
+                    }
+                    if (tokenNdx >= 0) {
+                        // Early exit from loop, must have found the matching token.
+                        break;
+                    }
+                }
+            }
+
+            if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: Found new focus @ " + i +
+                        " = " + win);
+            return win;
+        }
+
+        if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: No focusable windows.");
+        return null;
+    }
+
+    private void startFreezingDisplayLocked(boolean inTransaction, int exitAnim, int enterAnim) {
+        if (mDisplayFrozen) {
+            return;
+        }
+
+        if (!mDisplayReady || !mPolicy.isScreenOnFully()) {
+            // No need to freeze the screen before the system is ready or if
+            // the screen is off.
+            return;
+        }
+
+        mScreenFrozenLock.acquire();
+
+        mDisplayFrozen = true;
+        mDisplayFreezeTime = SystemClock.elapsedRealtime();
+        mLastFinishedFreezeSource = null;
+
+        mInputMonitor.freezeInputDispatchingLw();
+
+        // Clear the last input window -- that is just used for
+        // clean transitions between IMEs, and if we are freezing
+        // the screen then the whole world is changing behind the scenes.
+        mPolicy.setLastInputMethodWindowLw(null, null);
+
+        if (mAppTransition.isTransitionSet()) {
+            mAppTransition.freeze();
+        }
+
+        if (PROFILE_ORIENTATION) {
+            File file = new File("/data/system/frozen");
+            Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
+        }
+
+        if (CUSTOM_SCREEN_ROTATION) {
+            mExitAnimId = exitAnim;
+            mEnterAnimId = enterAnim;
+            final DisplayContent displayContent = getDefaultDisplayContentLocked();
+            final int displayId = displayContent.getDisplayId();
+            ScreenRotationAnimation screenRotationAnimation =
+                    mAnimator.getScreenRotationAnimationLocked(displayId);
+            if (screenRotationAnimation != null) {
+                screenRotationAnimation.kill();
+            }
+
+            // TODO(multidisplay): rotation on main screen only.
+            displayContent.updateDisplayInfo();
+            screenRotationAnimation = new ScreenRotationAnimation(mContext, displayContent,
+                    mFxSession, inTransaction, mPolicy.isDefaultOrientationForced());
+            mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
+        }
+    }
+
+    private void stopFreezingDisplayLocked() {
+        if (!mDisplayFrozen) {
+            return;
+        }
+
+        if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen
+                || mClientFreezingScreen) {
+            if (DEBUG_ORIENTATION) Slog.d(TAG,
+                "stopFreezingDisplayLocked: Returning mWaitingForConfig=" + mWaitingForConfig
+                + ", mAppsFreezingScreen=" + mAppsFreezingScreen
+                + ", mWindowsFreezingScreen=" + mWindowsFreezingScreen
+                + ", mClientFreezingScreen=" + mClientFreezingScreen);
+            return;
+        }
+
+        mDisplayFrozen = false;
+        mLastDisplayFreezeDuration = (int)(SystemClock.elapsedRealtime() - mDisplayFreezeTime);
+        StringBuilder sb = new StringBuilder(128);
+        sb.append("Screen frozen for ");
+        TimeUtils.formatDuration(mLastDisplayFreezeDuration, sb);
+        if (mLastFinishedFreezeSource != null) {
+            sb.append(" due to ");
+            sb.append(mLastFinishedFreezeSource);
+        }
+        Slog.i(TAG, sb.toString());
+        mH.removeMessages(H.APP_FREEZE_TIMEOUT);
+        mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT);
+        if (PROFILE_ORIENTATION) {
+            Debug.stopMethodTracing();
+        }
+
+        boolean updateRotation = false;
+
+        final DisplayContent displayContent = getDefaultDisplayContentLocked();
+        final int displayId = displayContent.getDisplayId();
+        ScreenRotationAnimation screenRotationAnimation =
+                mAnimator.getScreenRotationAnimationLocked(displayId);
+        if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
+                && screenRotationAnimation.hasScreenshot()) {
+            if (DEBUG_ORIENTATION) Slog.i(TAG, "**** Dismissing screen rotation animation");
+            // TODO(multidisplay): rotation on main screen only.
+            DisplayInfo displayInfo = displayContent.getDisplayInfo();
+            // Get rotation animation again, with new top window
+            boolean isDimming = displayContent.isDimming();
+            if (!mPolicy.validateRotationAnimationLw(mExitAnimId, mEnterAnimId, isDimming)) {
+                mExitAnimId = mEnterAnimId = 0;
+            }
+            if (screenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
+                    mTransitionAnimationScale, displayInfo.logicalWidth,
+                        displayInfo.logicalHeight, mExitAnimId, mEnterAnimId)) {
+                scheduleAnimationLocked();
+            } else {
+                screenRotationAnimation.kill();
+                screenRotationAnimation = null;
+                mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
+                updateRotation = true;
+            }
+        } else {
+            if (screenRotationAnimation != null) {
+                screenRotationAnimation.kill();
+                screenRotationAnimation = null;
+                mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
+            }
+            updateRotation = true;
+        }
+
+        mInputMonitor.thawInputDispatchingLw();
+
+        boolean configChanged;
+
+        // While the display is frozen we don't re-compute the orientation
+        // to avoid inconsistent states.  However, something interesting
+        // could have actually changed during that time so re-evaluate it
+        // now to catch that.
+        configChanged = updateOrientationFromAppTokensLocked(false);
+
+        // A little kludge: a lot could have happened while the
+        // display was frozen, so now that we are coming back we
+        // do a gc so that any remote references the system
+        // processes holds on others can be released if they are
+        // no longer needed.
+        mH.removeMessages(H.FORCE_GC);
+        mH.sendEmptyMessageDelayed(H.FORCE_GC, 2000);
+
+        mScreenFrozenLock.release();
+
+        if (updateRotation) {
+            if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
+            configChanged |= updateRotationUncheckedLocked(false);
+        }
+
+        if (configChanged) {
+            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
+        }
+    }
+
+    static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
+            DisplayMetrics dm) {
+        if (index < tokens.length) {
+            String str = tokens[index];
+            if (str != null && str.length() > 0) {
+                try {
+                    int val = Integer.parseInt(str);
+                    return val;
+                } catch (Exception e) {
+                }
+            }
+        }
+        if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
+            return defDps;
+        }
+        int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
+        return val;
+    }
+
+    void createWatermarkInTransaction() {
+        if (mWatermark != null) {
+            return;
+        }
+
+        File file = new File("/system/etc/setup.conf");
+        FileInputStream in = null;
+        DataInputStream ind = null;
+        try {
+            in = new FileInputStream(file);
+            ind = new DataInputStream(in);
+            String line = ind.readLine();
+            if (line != null) {
+                String[] toks = line.split("%");
+                if (toks != null && toks.length > 0) {
+                    mWatermark = new Watermark(getDefaultDisplayContentLocked().getDisplay(),
+                            mRealDisplayMetrics, mFxSession, toks);
+                }
+            }
+        } catch (FileNotFoundException e) {
+        } catch (IOException e) {
+        } finally {
+            if (ind != null) {
+                try {
+                    ind.close();
+                } catch (IOException e) {
+                }
+            } else if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
+
+    @Override
+    public void statusBarVisibilityChanged(int visibility) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
+                != PackageManager.PERMISSION_GRANTED) {
+            throw new SecurityException("Caller does not hold permission "
+                    + android.Manifest.permission.STATUS_BAR);
+        }
+
+        synchronized (mWindowMap) {
+            mLastStatusBarVisibility = visibility;
+            visibility = mPolicy.adjustSystemUiVisibilityLw(visibility);
+            updateStatusBarVisibilityLocked(visibility);
+        }
+    }
+
+    // TOOD(multidisplay): StatusBar on multiple screens?
+    void updateStatusBarVisibilityLocked(int visibility) {
+        mInputManager.setSystemUiVisibility(visibility);
+        final WindowList windows = getDefaultWindowListLocked();
+        final int N = windows.size();
+        for (int i = 0; i < N; i++) {
+            WindowState ws = windows.get(i);
+            try {
+                int curValue = ws.mSystemUiVisibility;
+                int diff = curValue ^ visibility;
+                // We are only interested in differences of one of the
+                // clearable flags...
+                diff &= View.SYSTEM_UI_CLEARABLE_FLAGS;
+                // ...if it has actually been cleared.
+                diff &= ~visibility;
+                int newValue = (curValue&~diff) | (visibility&diff);
+                if (newValue != curValue) {
+                    ws.mSeq++;
+                    ws.mSystemUiVisibility = newValue;
+                }
+                if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) {
+                    ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq,
+                            visibility, newValue, diff);
+                }
+            } catch (RemoteException e) {
+                // so sorry
+            }
+        }
+    }
+
+    @Override
+    public void reevaluateStatusBarVisibility() {
+        synchronized (mWindowMap) {
+            int visibility = mPolicy.adjustSystemUiVisibilityLw(mLastStatusBarVisibility);
+            updateStatusBarVisibilityLocked(visibility);
+            performLayoutAndPlaceSurfacesLocked();
+        }
+    }
+
+    @Override
+    public FakeWindow addFakeWindow(Looper looper,
+            InputEventReceiver.Factory inputEventReceiverFactory,
+            String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags,
+            boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) {
+        synchronized (mWindowMap) {
+            FakeWindowImpl fw = new FakeWindowImpl(this, looper, inputEventReceiverFactory,
+                    name, windowType,
+                    layoutParamsFlags, layoutParamsPrivateFlags, canReceiveKeys,
+                    hasFocus, touchFullscreen);
+            int i=0;
+            while (i<mFakeWindows.size()) {
+                if (mFakeWindows.get(i).mWindowLayer <= fw.mWindowLayer) {
+                    break;
+                }
+            }
+            mFakeWindows.add(i, fw);
+            mInputMonitor.updateInputWindowsLw(true);
+            return fw;
+        }
+    }
+
+    boolean removeFakeWindowLocked(FakeWindow window) {
+        synchronized (mWindowMap) {
+            if (mFakeWindows.remove(window)) {
+                mInputMonitor.updateInputWindowsLw(true);
+                return true;
+            }
+            return false;
+        }
+    }
+
+    // It is assumed that this method is called only by InputMethodManagerService.
+    public void saveLastInputMethodWindowForTransition() {
+        synchronized (mWindowMap) {
+            // TODO(multidisplay): Pass in the displayID.
+            DisplayContent displayContent = getDefaultDisplayContentLocked();
+            if (mInputMethodWindow != null) {
+                mPolicy.setLastInputMethodWindowLw(mInputMethodWindow, mInputMethodTarget);
+            }
+        }
+    }
+
+    @Override
+    public boolean hasNavigationBar() {
+        return mPolicy.hasNavigationBar();
+    }
+
+    @Override
+    public void lockNow(Bundle options) {
+        mPolicy.lockNow(options);
+    }
+
+    @Override
+    public boolean isSafeModeEnabled() {
+        return mSafeMode;
+    }
+
+    void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) {
+        pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)");
+        mPolicy.dump("    ", pw, args);
+    }
+
+    void dumpAnimatorLocked(PrintWriter pw, String[] args, boolean dumpAll) {
+        pw.println("WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)");
+        mAnimator.dumpLocked(pw, "    ", dumpAll);
+    }
+
+    void dumpTokensLocked(PrintWriter pw, boolean dumpAll) {
+        pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)");
+        if (mTokenMap.size() > 0) {
+            pw.println("  All tokens:");
+            Iterator<WindowToken> it = mTokenMap.values().iterator();
+            while (it.hasNext()) {
+                WindowToken token = it.next();
+                pw.print("  "); pw.print(token);
+                if (dumpAll) {
+                    pw.println(':');
+                    token.dump(pw, "    ");
+                } else {
+                    pw.println();
+                }
+            }
+        }
+        if (mWallpaperTokens.size() > 0) {
+            pw.println();
+            pw.println("  Wallpaper tokens:");
+            for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
+                WindowToken token = mWallpaperTokens.get(i);
+                pw.print("  Wallpaper #"); pw.print(i);
+                        pw.print(' '); pw.print(token);
+                if (dumpAll) {
+                    pw.println(':');
+                    token.dump(pw, "    ");
+                } else {
+                    pw.println();
+                }
+            }
+        }
+        if (mFinishedStarting.size() > 0) {
+            pw.println();
+            pw.println("  Finishing start of application tokens:");
+            for (int i=mFinishedStarting.size()-1; i>=0; i--) {
+                WindowToken token = mFinishedStarting.get(i);
+                pw.print("  Finished Starting #"); pw.print(i);
+                        pw.print(' '); pw.print(token);
+                if (dumpAll) {
+                    pw.println(':');
+                    token.dump(pw, "    ");
+                } else {
+                    pw.println();
+                }
+            }
+        }
+        if (mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
+            pw.println();
+            if (mOpeningApps.size() > 0) {
+                pw.print("  mOpeningApps="); pw.println(mOpeningApps);
+            }
+            if (mClosingApps.size() > 0) {
+                pw.print("  mClosingApps="); pw.println(mClosingApps);
+            }
+        }
+    }
+
+    void dumpSessionsLocked(PrintWriter pw, boolean dumpAll) {
+        pw.println("WINDOW MANAGER SESSIONS (dumpsys window sessions)");
+        if (mSessions.size() > 0) {
+            Iterator<Session> it = mSessions.iterator();
+            while (it.hasNext()) {
+                Session s = it.next();
+                pw.print("  Session "); pw.print(s); pw.println(':');
+                s.dump(pw, "    ");
+            }
+        }
+    }
+
+    void dumpDisplayContentsLocked(PrintWriter pw, boolean dumpAll) {
+        pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
+        if (mDisplayReady) {
+            final int numDisplays = mDisplayContents.size();
+            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+                displayContent.dump("  ", pw);
+            }
+        } else {
+            pw.println("  NO DISPLAY");
+        }
+    }
+
+    void dumpWindowsLocked(PrintWriter pw, boolean dumpAll,
+            ArrayList<WindowState> windows) {
+        pw.println("WINDOW MANAGER WINDOWS (dumpsys window windows)");
+        dumpWindowsNoHeaderLocked(pw, dumpAll, windows);
+    }
+
+    void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll,
+            ArrayList<WindowState> windows) {
+        final int numDisplays = mDisplayContents.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final WindowList windowList = mDisplayContents.valueAt(displayNdx).getWindowList();
+            for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
+                final WindowState w = windowList.get(winNdx);
+                if (windows == null || windows.contains(w)) {
+                    pw.print("  Window #"); pw.print(winNdx); pw.print(' ');
+                            pw.print(w); pw.println(":");
+                    w.dump(pw, "    ", dumpAll || windows != null);
+                }
+            }
+        }
+        if (mInputMethodDialogs.size() > 0) {
+            pw.println();
+            pw.println("  Input method dialogs:");
+            for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
+                WindowState w = mInputMethodDialogs.get(i);
+                if (windows == null || windows.contains(w)) {
+                    pw.print("  IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
+                }
+            }
+        }
+        if (mPendingRemove.size() > 0) {
+            pw.println();
+            pw.println("  Remove pending for:");
+            for (int i=mPendingRemove.size()-1; i>=0; i--) {
+                WindowState w = mPendingRemove.get(i);
+                if (windows == null || windows.contains(w)) {
+                    pw.print("  Remove #"); pw.print(i); pw.print(' ');
+                            pw.print(w);
+                    if (dumpAll) {
+                        pw.println(":");
+                        w.dump(pw, "    ", true);
+                    } else {
+                        pw.println();
+                    }
+                }
+            }
+        }
+        if (mForceRemoves != null && mForceRemoves.size() > 0) {
+            pw.println();
+            pw.println("  Windows force removing:");
+            for (int i=mForceRemoves.size()-1; i>=0; i--) {
+                WindowState w = mForceRemoves.get(i);
+                pw.print("  Removing #"); pw.print(i); pw.print(' ');
+                        pw.print(w);
+                if (dumpAll) {
+                    pw.println(":");
+                    w.dump(pw, "    ", true);
+                } else {
+                    pw.println();
+                }
+            }
+        }
+        if (mDestroySurface.size() > 0) {
+            pw.println();
+            pw.println("  Windows waiting to destroy their surface:");
+            for (int i=mDestroySurface.size()-1; i>=0; i--) {
+                WindowState w = mDestroySurface.get(i);
+                if (windows == null || windows.contains(w)) {
+                    pw.print("  Destroy #"); pw.print(i); pw.print(' ');
+                            pw.print(w);
+                    if (dumpAll) {
+                        pw.println(":");
+                        w.dump(pw, "    ", true);
+                    } else {
+                        pw.println();
+                    }
+                }
+            }
+        }
+        if (mLosingFocus.size() > 0) {
+            pw.println();
+            pw.println("  Windows losing focus:");
+            for (int i=mLosingFocus.size()-1; i>=0; i--) {
+                WindowState w = mLosingFocus.get(i);
+                if (windows == null || windows.contains(w)) {
+                    pw.print("  Losing #"); pw.print(i); pw.print(' ');
+                            pw.print(w);
+                    if (dumpAll) {
+                        pw.println(":");
+                        w.dump(pw, "    ", true);
+                    } else {
+                        pw.println();
+                    }
+                }
+            }
+        }
+        if (mResizingWindows.size() > 0) {
+            pw.println();
+            pw.println("  Windows waiting to resize:");
+            for (int i=mResizingWindows.size()-1; i>=0; i--) {
+                WindowState w = mResizingWindows.get(i);
+                if (windows == null || windows.contains(w)) {
+                    pw.print("  Resizing #"); pw.print(i); pw.print(' ');
+                            pw.print(w);
+                    if (dumpAll) {
+                        pw.println(":");
+                        w.dump(pw, "    ", true);
+                    } else {
+                        pw.println();
+                    }
+                }
+            }
+        }
+        if (mWaitingForDrawn.size() > 0) {
+            pw.println();
+            pw.println("  Clients waiting for these windows to be drawn:");
+            for (int i=mWaitingForDrawn.size()-1; i>=0; i--) {
+                Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(i);
+                pw.print("  Waiting #"); pw.print(i); pw.print(' '); pw.print(pair.first);
+                        pw.print(": "); pw.println(pair.second);
+            }
+        }
+        pw.println();
+        pw.print("  mCurConfiguration="); pw.println(this.mCurConfiguration);
+        pw.print("  mCurrentFocus="); pw.println(mCurrentFocus);
+        if (mLastFocus != mCurrentFocus) {
+            pw.print("  mLastFocus="); pw.println(mLastFocus);
+        }
+        pw.print("  mFocusedApp="); pw.println(mFocusedApp);
+        if (mInputMethodTarget != null) {
+            pw.print("  mInputMethodTarget="); pw.println(mInputMethodTarget);
+        }
+        pw.print("  mInTouchMode="); pw.print(mInTouchMode);
+                pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
+        pw.print("  mLastDisplayFreezeDuration=");
+                TimeUtils.formatDuration(mLastDisplayFreezeDuration, pw);
+                if ( mLastFinishedFreezeSource != null) {
+                    pw.print(" due to ");
+                    pw.print(mLastFinishedFreezeSource);
+                }
+                pw.println();
+        if (dumpAll) {
+            pw.print("  mSystemDecorLayer="); pw.print(mSystemDecorLayer);
+                    pw.print(" mScreenRect="); pw.println(mScreenRect.toShortString());
+            if (mLastStatusBarVisibility != 0) {
+                pw.print("  mLastStatusBarVisibility=0x");
+                        pw.println(Integer.toHexString(mLastStatusBarVisibility));
+            }
+            if (mInputMethodWindow != null) {
+                pw.print("  mInputMethodWindow="); pw.println(mInputMethodWindow);
+            }
+            pw.print("  mWallpaperTarget="); pw.println(mWallpaperTarget);
+            if (mLowerWallpaperTarget != null || mUpperWallpaperTarget != null) {
+                pw.print("  mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
+                pw.print("  mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
+            }
+            pw.print("  mLastWallpaperX="); pw.print(mLastWallpaperX);
+                    pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
+            if (mInputMethodAnimLayerAdjustment != 0 ||
+                    mWallpaperAnimLayerAdjustment != 0) {
+                pw.print("  mInputMethodAnimLayerAdjustment=");
+                        pw.print(mInputMethodAnimLayerAdjustment);
+                        pw.print("  mWallpaperAnimLayerAdjustment=");
+                        pw.println(mWallpaperAnimLayerAdjustment);
+            }
+            pw.print("  mSystemBooted="); pw.print(mSystemBooted);
+                    pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
+            if (needsLayout()) {
+                pw.print("  layoutNeeded on displays=");
+                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                    final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
+                    if (displayContent.layoutNeeded) {
+                        pw.print(displayContent.getDisplayId());
+                    }
+                }
+                pw.println();
+            }
+            pw.print("  mTransactionSequence="); pw.println(mTransactionSequence);
+            pw.print("  mDisplayFrozen="); pw.print(mDisplayFrozen);
+                    pw.print(" windows="); pw.print(mWindowsFreezingScreen);
+                    pw.print(" client="); pw.print(mClientFreezingScreen);
+                    pw.print(" apps="); pw.print(mAppsFreezingScreen);
+                    pw.print(" waitingForConfig="); pw.println(mWaitingForConfig);
+            pw.print("  mRotation="); pw.print(mRotation);
+                    pw.print(" mAltOrientation="); pw.println(mAltOrientation);
+            pw.print("  mLastWindowForcedOrientation="); pw.print(mLastWindowForcedOrientation);
+                    pw.print(" mForcedAppOrientation="); pw.println(mForcedAppOrientation);
+            pw.print("  mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
+            pw.print("  mWindowAnimationScale="); pw.print(mWindowAnimationScale);
+                    pw.print(" mTransitionWindowAnimationScale="); pw.print(mTransitionAnimationScale);
+                    pw.print(" mAnimatorDurationScale="); pw.println(mAnimatorDurationScale);
+            pw.print("  mTraversalScheduled="); pw.println(mTraversalScheduled);
+            pw.print("  mStartingIconInTransition="); pw.print(mStartingIconInTransition);
+                    pw.print(" mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
+            pw.println("  mLayoutToAnim:");
+            mAppTransition.dump(pw);
+        }
+    }
+
+    boolean dumpWindows(PrintWriter pw, String name, String[] args,
+            int opti, boolean dumpAll) {
+        WindowList windows = new WindowList();
+        if ("visible".equals(name)) {
+            synchronized(mWindowMap) {
+                final int numDisplays = mDisplayContents.size();
+                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                    final WindowList windowList =
+                            mDisplayContents.valueAt(displayNdx).getWindowList();
+                    for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
+                        final WindowState w = windowList.get(winNdx);
+                        if (w.mWinAnimator.mSurfaceShown) {
+                            windows.add(w);
+                        }
+                    }
+                }
+            }
+        } else {
+            int objectId = 0;
+            // See if this is an object ID.
+            try {
+                objectId = Integer.parseInt(name, 16);
+                name = null;
+            } catch (RuntimeException e) {
+            }
+            synchronized(mWindowMap) {
+                final int numDisplays = mDisplayContents.size();
+                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+                    final WindowList windowList =
+                            mDisplayContents.valueAt(displayNdx).getWindowList();
+                    for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
+                        final WindowState w = windowList.get(winNdx);
+                        if (name != null) {
+                            if (w.mAttrs.getTitle().toString().contains(name)) {
+                                windows.add(w);
+                            }
+                        } else if (System.identityHashCode(w) == objectId) {
+                            windows.add(w);
+                        }
+                    }
+                }
+            }
+        }
+
+        if (windows.size() <= 0) {
+            return false;
+        }
+
+        synchronized(mWindowMap) {
+            dumpWindowsLocked(pw, dumpAll, windows);
+        }
+        return true;
+    }
+
+    void dumpLastANRLocked(PrintWriter pw) {
+        pw.println("WINDOW MANAGER LAST ANR (dumpsys window lastanr)");
+        if (mLastANRState == null) {
+            pw.println("  <no ANR has occurred since boot>");
+        } else {
+            pw.println(mLastANRState);
+        }
+    }
+
+    /**
+     * Saves information about the state of the window manager at
+     * the time an ANR occurred before anything else in the system changes
+     * in response.
+     *
+     * @param appWindowToken The application that ANR'd, may be null.
+     * @param windowState The window that ANR'd, may be null.
+     * @param reason The reason for the ANR, may be null.
+     */
+    public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState,
+            String reason) {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new FastPrintWriter(sw, false, 1024);
+        pw.println("  ANR time: " + DateFormat.getInstance().format(new Date()));
+        if (appWindowToken != null) {
+            pw.println("  Application at fault: " + appWindowToken.stringName);
+        }
+        if (windowState != null) {
+            pw.println("  Window at fault: " + windowState.mAttrs.getTitle());
+        }
+        if (reason != null) {
+            pw.println("  Reason: " + reason);
+        }
+        pw.println();
+        dumpWindowsNoHeaderLocked(pw, true, null);
+        pw.close();
+        mLastANRState = sw.toString();
+    }
+
+    @Override
+    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
+                != PackageManager.PERMISSION_GRANTED) {
+            pw.println("Permission Denial: can't dump WindowManager from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        boolean dumpAll = false;
+
+        int opti = 0;
+        while (opti < args.length) {
+            String opt = args[opti];
+            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
+                break;
+            }
+            opti++;
+            if ("-a".equals(opt)) {
+                dumpAll = true;
+            } else if ("-h".equals(opt)) {
+                pw.println("Window manager dump options:");
+                pw.println("  [-a] [-h] [cmd] ...");
+                pw.println("  cmd may be one of:");
+                pw.println("    l[astanr]: last ANR information");
+                pw.println("    p[policy]: policy state");
+                pw.println("    a[animator]: animator state");
+                pw.println("    s[essions]: active sessions");
+                pw.println("    d[isplays]: active display contents");
+                pw.println("    t[okens]: token list");
+                pw.println("    w[indows]: window list");
+                pw.println("  cmd may also be a NAME to dump windows.  NAME may");
+                pw.println("    be a partial substring in a window name, a");
+                pw.println("    Window hex object identifier, or");
+                pw.println("    \"all\" for all windows, or");
+                pw.println("    \"visible\" for the visible windows.");
+                pw.println("  -a: include all available server state.");
+                return;
+            } else {
+                pw.println("Unknown argument: " + opt + "; use -h for help");
+            }
+        }
+
+        // Is the caller requesting to dump a particular piece of data?
+        if (opti < args.length) {
+            String cmd = args[opti];
+            opti++;
+            if ("lastanr".equals(cmd) || "l".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpLastANRLocked(pw);
+                }
+                return;
+            } else if ("policy".equals(cmd) || "p".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpPolicyLocked(pw, args, true);
+                }
+                return;
+            } else if ("animator".equals(cmd) || "a".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpAnimatorLocked(pw, args, true);
+                }
+                return;
+            } else if ("sessions".equals(cmd) || "s".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpSessionsLocked(pw, true);
+                }
+                return;
+            } else if ("displays".equals(cmd) || "d".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpDisplayContentsLocked(pw, true);
+                }
+                return;
+            } else if ("tokens".equals(cmd) || "t".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpTokensLocked(pw, true);
+                }
+                return;
+            } else if ("windows".equals(cmd) || "w".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpWindowsLocked(pw, true, null);
+                }
+                return;
+            } else if ("all".equals(cmd) || "a".equals(cmd)) {
+                synchronized(mWindowMap) {
+                    dumpWindowsLocked(pw, true, null);
+                }
+                return;
+            } else {
+                // Dumping a single name?
+                if (!dumpWindows(pw, cmd, args, opti, dumpAll)) {
+                    pw.println("Bad window command, or no windows match: " + cmd);
+                    pw.println("Use -h for help.");
+                }
+                return;
+            }
+        }
+
+        synchronized(mWindowMap) {
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpLastANRLocked(pw);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpPolicyLocked(pw, args, dumpAll);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpAnimatorLocked(pw, args, dumpAll);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpSessionsLocked(pw, dumpAll);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpDisplayContentsLocked(pw, dumpAll);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpTokensLocked(pw, dumpAll);
+            pw.println();
+            if (dumpAll) {
+                pw.println("-------------------------------------------------------------------------------");
+            }
+            dumpWindowsLocked(pw, dumpAll, null);
+        }
+    }
+
+    // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
+    @Override
+    public void monitor() {
+        synchronized (mWindowMap) { }
+    }
+
+    public interface OnHardKeyboardStatusChangeListener {
+        public void onHardKeyboardStatusChange(boolean available, boolean enabled);
+    }
+
+    void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {
+        if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) {
+            Slog.v(TAG, "Layouts looping: " + msg + ", mPendingLayoutChanges = 0x" +
+                    Integer.toHexString(pendingLayoutChanges));
+        }
+    }
+
+    private DisplayContent newDisplayContentLocked(final Display display) {
+        DisplayContent displayContent = new DisplayContent(display, this);
+        final int displayId = display.getDisplayId();
+        if (DEBUG_DISPLAY) Slog.v(TAG, "Adding display=" + display);
+        mDisplayContents.put(displayId, displayContent);
+
+        DisplayInfo displayInfo = displayContent.getDisplayInfo();
+        final Rect rect = new Rect();
+        mDisplaySettings.getOverscanLocked(displayInfo.name, rect);
+        synchronized (displayContent.mDisplaySizeLock) {
+            displayInfo.overscanLeft = rect.left;
+            displayInfo.overscanTop = rect.top;
+            displayInfo.overscanRight = rect.right;
+            displayInfo.overscanBottom = rect.bottom;
+            mDisplayManagerInternal.setDisplayInfoOverrideFromWindowManager(
+                    displayId, displayInfo);
+        }
+        configureDisplayPolicyLocked(displayContent);
+
+        // TODO: Create an input channel for each display with touch capability.
+        if (displayId == Display.DEFAULT_DISPLAY) {
+            displayContent.mTapDetector = new StackTapPointerEventListener(this, displayContent);
+            registerPointerEventListener(displayContent.mTapDetector);
+        }
+
+        return displayContent;
+    }
+
+    public void createDisplayContentLocked(final Display display) {
+        if (display == null) {
+            throw new IllegalArgumentException("getDisplayContent: display must not be null");
+        }
+        getDisplayContentLocked(display.getDisplayId());
+    }
+
+    /**
+     * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
+     * there is a Display for the displayId.
+     * @param displayId The display the caller is interested in.
+     * @return The DisplayContent associated with displayId or null if there is no Display for it.
+     */
+    public DisplayContent getDisplayContentLocked(final int displayId) {
+        DisplayContent displayContent = mDisplayContents.get(displayId);
+        if (displayContent == null) {
+            final Display display = mDisplayManager.getDisplay(displayId);
+            if (display != null) {
+                displayContent = newDisplayContentLocked(display);
+            }
+        }
+        return displayContent;
+    }
+
+    // There is an inherent assumption that this will never return null.
+    public DisplayContent getDefaultDisplayContentLocked() {
+        return getDisplayContentLocked(Display.DEFAULT_DISPLAY);
+    }
+
+    public WindowList getDefaultWindowListLocked() {
+        return getDefaultDisplayContentLocked().getWindowList();
+    }
+
+    public DisplayInfo getDefaultDisplayInfoLocked() {
+        return getDefaultDisplayContentLocked().getDisplayInfo();
+    }
+
+    /**
+     * Return the list of WindowStates associated on the passed display.
+     * @param display The screen to return windows from.
+     * @return The list of WindowStates on the screen, or null if the there is no screen.
+     */
+    public WindowList getWindowListLocked(final Display display) {
+        return getWindowListLocked(display.getDisplayId());
+    }
+
+    /**
+     * Return the list of WindowStates associated on the passed display.
+     * @param displayId The screen to return windows from.
+     * @return The list of WindowStates on the screen, or null if the there is no screen.
+     */
+    public WindowList getWindowListLocked(final int displayId) {
+        final DisplayContent displayContent = getDisplayContentLocked(displayId);
+        return displayContent != null ? displayContent.getWindowList() : null;
+    }
+
+    public void onDisplayAdded(int displayId) {
+        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0));
+    }
+
+    public void handleDisplayAdded(int displayId) {
+        synchronized (mWindowMap) {
+            final Display display = mDisplayManager.getDisplay(displayId);
+            if (display != null) {
+                createDisplayContentLocked(display);
+                displayReady(displayId);
+            }
+        }
+    }
+
+    public void onDisplayRemoved(int displayId) {
+        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0));
+    }
+
+    private void handleDisplayRemovedLocked(int displayId) {
+        final DisplayContent displayContent = getDisplayContentLocked(displayId);
+        if (displayContent != null) {
+            if (displayContent.isAnimating()) {
+                displayContent.mDeferredRemoval = true;
+                return;
+            }
+            if (DEBUG_DISPLAY) Slog.v(TAG, "Removing display=" + displayContent);
+            mDisplayContents.delete(displayId);
+            displayContent.close();
+            if (displayId == Display.DEFAULT_DISPLAY) {
+                unregisterPointerEventListener(displayContent.mTapDetector);
+            }
+        }
+        mAnimator.removeDisplayLocked(displayId);
+    }
+
+    public void onDisplayChanged(int displayId) {
+        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0));
+    }
+
+    private void handleDisplayChangedLocked(int displayId) {
+        final DisplayContent displayContent = getDisplayContentLocked(displayId);
+        if (displayContent != null) {
+            displayContent.updateDisplayInfo();
+        }
+    }
+
+    @Override
+    public Object getWindowManagerLock() {
+        return mWindowMap;
+    }
+
+    private final class LocalService extends WindowManagerInternal {
+        @Override
+        public void requestTraversalFromDisplayManager() {
+            requestTraversal();
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
new file mode 100644
index 0000000..9f3415e
--- /dev/null
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -0,0 +1,1560 @@
+/*
+ * 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.server.wm;
+
+import static com.android.server.wm.WindowManagerService.DEBUG_CONFIGURATION;
+import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
+import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
+import static com.android.server.wm.WindowManagerService.DEBUG_RESIZE;
+import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
+
+import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
+import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
+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_KEYGUARD;
+import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
+
+import android.app.AppOpsManager;
+import android.os.Debug;
+import android.os.RemoteCallbackList;
+import android.os.SystemClock;
+import android.util.TimeUtils;
+import android.view.IWindowFocusObserver;
+import android.view.IWindowId;
+import com.android.server.input.InputWindowHandle;
+
+import android.content.Context;
+import android.content.res.Configuration;
+import android.graphics.Matrix;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Region;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.util.Slog;
+import android.view.DisplayInfo;
+import android.view.Gravity;
+import android.view.IApplicationToken;
+import android.view.IWindow;
+import android.view.InputChannel;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.view.WindowManager;
+import android.view.WindowManagerPolicy;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+class WindowList extends ArrayList<WindowState> {
+}
+
+/**
+ * A window in the window manager.
+ */
+final class WindowState implements WindowManagerPolicy.WindowState {
+    static final String TAG = "WindowState";
+
+    final WindowManagerService mService;
+    final WindowManagerPolicy mPolicy;
+    final Context mContext;
+    final Session mSession;
+    final IWindow mClient;
+    final int mAppOp;
+    // UserId and appId of the owner. Don't display windows of non-current user.
+    final int mOwnerUid;
+    final IWindowId mWindowId;
+    WindowToken mToken;
+    WindowToken mRootToken;
+    AppWindowToken mAppToken;
+    AppWindowToken mTargetAppToken;
+
+    // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
+    // modified they will need to be locked.
+    final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
+    final DeathRecipient mDeathRecipient;
+    final WindowState mAttachedWindow;
+    final WindowList mChildWindows = new WindowList();
+    final int mBaseLayer;
+    final int mSubLayer;
+    final boolean mLayoutAttached;
+    final boolean mIsImWindow;
+    final boolean mIsWallpaper;
+    final boolean mIsFloatingLayer;
+    int mSeq;
+    boolean mEnforceSizeCompat;
+    int mViewVisibility;
+    int mSystemUiVisibility;
+    boolean mPolicyVisibility = true;
+    boolean mPolicyVisibilityAfterAnim = true;
+    boolean mAppOpVisibility = true;
+    boolean mAppFreezing;
+    boolean mAttachedHidden;    // is our parent window hidden?
+    boolean mWallpaperVisible;  // for wallpaper, what was last vis report?
+
+    RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
+
+    /**
+     * The window size that was requested by the application.  These are in
+     * the application's coordinate space (without compatibility scale applied).
+     */
+    int mRequestedWidth;
+    int mRequestedHeight;
+    int mLastRequestedWidth;
+    int mLastRequestedHeight;
+
+    int mLayer;
+    boolean mHaveFrame;
+    boolean mObscured;
+    boolean mTurnOnScreen;
+
+    int mLayoutSeq = -1;
+
+    Configuration mConfiguration = null;
+    // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
+    // Used only on {@link #TYPE_KEYGUARD}.
+    private boolean mConfigHasChanged;
+
+    /**
+     * Actual frame shown on-screen (may be modified by animation).  These
+     * are in the screen's coordinate space (WITH the compatibility scale
+     * applied).
+     */
+    final RectF mShownFrame = new RectF();
+
+    /**
+     * Insets that determine the actually visible area.  These are in the application's
+     * coordinate space (without compatibility scale applied).
+     */
+    final Rect mVisibleInsets = new Rect();
+    final Rect mLastVisibleInsets = new Rect();
+    boolean mVisibleInsetsChanged;
+
+    /**
+     * Insets that are covered by system windows (such as the status bar) and
+     * transient docking windows (such as the IME).  These are in the application's
+     * coordinate space (without compatibility scale applied).
+     */
+    final Rect mContentInsets = new Rect();
+    final Rect mLastContentInsets = new Rect();
+    boolean mContentInsetsChanged;
+
+    /**
+     * Insets that determine the area covered by the display overscan region.  These are in the
+     * application's coordinate space (without compatibility scale applied).
+     */
+    final Rect mOverscanInsets = new Rect();
+    final Rect mLastOverscanInsets = new Rect();
+    boolean mOverscanInsetsChanged;
+
+    /**
+     * Set to true if we are waiting for this window to receive its
+     * given internal insets before laying out other windows based on it.
+     */
+    boolean mGivenInsetsPending;
+
+    /**
+     * These are the content insets that were given during layout for
+     * this window, to be applied to windows behind it.
+     */
+    final Rect mGivenContentInsets = new Rect();
+
+    /**
+     * These are the visible insets that were given during layout for
+     * this window, to be applied to windows behind it.
+     */
+    final Rect mGivenVisibleInsets = new Rect();
+
+    /**
+     * This is the given touchable area relative to the window frame, or null if none.
+     */
+    final Region mGivenTouchableRegion = new Region();
+
+    /**
+     * Flag indicating whether the touchable region should be adjusted by
+     * the visible insets; if false the area outside the visible insets is
+     * NOT touchable, so we must use those to adjust the frame during hit
+     * tests.
+     */
+    int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
+
+    /**
+     * This is rectangle of the window's surface that is not covered by
+     * system decorations.
+     */
+    final Rect mSystemDecorRect = new Rect();
+    final Rect mLastSystemDecorRect = new Rect();
+
+    // Current transformation being applied.
+    float mGlobalScale=1;
+    float mInvGlobalScale=1;
+    float mHScale=1, mVScale=1;
+    float mLastHScale=1, mLastVScale=1;
+    final Matrix mTmpMatrix = new Matrix();
+
+    // "Real" frame that the application sees, in display coordinate space.
+    final Rect mFrame = new Rect();
+    final Rect mLastFrame = new Rect();
+    // Frame that is scaled to the application's coordinate space when in
+    // screen size compatibility mode.
+    final Rect mCompatFrame = new Rect();
+
+    final Rect mContainingFrame = new Rect();
+    final Rect mDisplayFrame = new Rect();
+    final Rect mOverscanFrame = new Rect();
+    final Rect mContentFrame = new Rect();
+    final Rect mParentFrame = new Rect();
+    final Rect mVisibleFrame = new Rect();
+    final Rect mDecorFrame = new Rect();
+
+    boolean mContentChanged;
+
+    // If a window showing a wallpaper: the requested offset for the
+    // wallpaper; if a wallpaper window: the currently applied offset.
+    float mWallpaperX = -1;
+    float mWallpaperY = -1;
+
+    // If a window showing a wallpaper: what fraction of the offset
+    // range corresponds to a full virtual screen.
+    float mWallpaperXStep = -1;
+    float mWallpaperYStep = -1;
+
+    // Wallpaper windows: pixels offset based on above variables.
+    int mXOffset;
+    int mYOffset;
+
+    /**
+     * This is set after IWindowSession.relayout() has been called at
+     * least once for the window.  It allows us to detect the situation
+     * where we don't yet have a surface, but should have one soon, so
+     * we can give the window focus before waiting for the relayout.
+     */
+    boolean mRelayoutCalled;
+
+    /**
+     * If the application has called relayout() with changes that can
+     * impact its window's size, we need to perform a layout pass on it
+     * even if it is not currently visible for layout.  This is set
+     * when in that case until the layout is done.
+     */
+    boolean mLayoutNeeded;
+
+    /** Currently running an exit animation? */
+    boolean mExiting;
+
+    /** Currently on the mDestroySurface list? */
+    boolean mDestroying;
+
+    /** Completely remove from window manager after exit animation? */
+    boolean mRemoveOnExit;
+
+    /**
+     * Set when the orientation is changing and this window has not yet
+     * been updated for the new orientation.
+     */
+    boolean mOrientationChanging;
+
+    /**
+     * How long we last kept the screen frozen.
+     */
+    int mLastFreezeDuration;
+
+    /** Is this window now (or just being) removed? */
+    boolean mRemoved;
+
+    /**
+     * Temp for keeping track of windows that have been removed when
+     * rebuilding window list.
+     */
+    boolean mRebuilding;
+
+    // Input channel and input window handle used by the input dispatcher.
+    final InputWindowHandle mInputWindowHandle;
+    InputChannel mInputChannel;
+
+    // Used to improve performance of toString()
+    String mStringNameCache;
+    CharSequence mLastTitle;
+    boolean mWasExiting;
+
+    final WindowStateAnimator mWinAnimator;
+
+    boolean mHasSurface = false;
+
+    DisplayContent  mDisplayContent;
+
+    /** When true this window can be displayed on screens owther than mOwnerUid's */
+    private boolean mShowToOwnerOnly;
+
+    /** When true this window is at the top of the screen and should be layed out to extend under
+     * the status bar */
+    boolean mUnderStatusBar = true;
+
+    WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
+           WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
+           int viewVisibility, final DisplayContent displayContent) {
+        mService = service;
+        mSession = s;
+        mClient = c;
+        mAppOp = appOp;
+        mToken = token;
+        mOwnerUid = s.mUid;
+        mWindowId = new IWindowId.Stub() {
+            @Override
+            public void registerFocusObserver(IWindowFocusObserver observer) {
+                WindowState.this.registerFocusObserver(observer);
+            }
+            @Override
+            public void unregisterFocusObserver(IWindowFocusObserver observer) {
+                WindowState.this.unregisterFocusObserver(observer);
+            }
+            @Override
+            public boolean isFocused() {
+                return WindowState.this.isFocused();
+            }
+        };
+        mAttrs.copyFrom(a);
+        mViewVisibility = viewVisibility;
+        mDisplayContent = displayContent;
+        mPolicy = mService.mPolicy;
+        mContext = mService.mContext;
+        DeathRecipient deathRecipient = new DeathRecipient();
+        mSeq = seq;
+        mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
+        if (WindowManagerService.localLOGV) Slog.v(
+            TAG, "Window " + this + " client=" + c.asBinder()
+            + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
+        try {
+            c.asBinder().linkToDeath(deathRecipient, 0);
+        } catch (RemoteException e) {
+            mDeathRecipient = null;
+            mAttachedWindow = null;
+            mLayoutAttached = false;
+            mIsImWindow = false;
+            mIsWallpaper = false;
+            mIsFloatingLayer = false;
+            mBaseLayer = 0;
+            mSubLayer = 0;
+            mInputWindowHandle = null;
+            mWinAnimator = null;
+            return;
+        }
+        mDeathRecipient = deathRecipient;
+
+        if ((mAttrs.type >= FIRST_SUB_WINDOW &&
+                mAttrs.type <= LAST_SUB_WINDOW)) {
+            // The multiplier here is to reserve space for multiple
+            // windows in the same type layer.
+            mBaseLayer = mPolicy.windowTypeToLayerLw(
+                    attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
+                    + WindowManagerService.TYPE_LAYER_OFFSET;
+            mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
+            mAttachedWindow = attachedWindow;
+            if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
+
+            int children_size = mAttachedWindow.mChildWindows.size();
+            if (children_size == 0) {
+                mAttachedWindow.mChildWindows.add(this);
+            } else {
+                for (int i = 0; i < children_size; i++) {
+                    WindowState child = mAttachedWindow.mChildWindows.get(i);
+                    if (mSubLayer < child.mSubLayer) {
+                        mAttachedWindow.mChildWindows.add(i, this);
+                        break;
+                    } else if (mSubLayer > child.mSubLayer) {
+                        continue;
+                    }
+
+                    if (mBaseLayer <= child.mBaseLayer) {
+                        mAttachedWindow.mChildWindows.add(i, this);
+                        break;
+                    }
+                }
+                if (children_size == mAttachedWindow.mChildWindows.size()) {
+                    mAttachedWindow.mChildWindows.add(this);
+                }
+            }
+
+            mLayoutAttached = mAttrs.type !=
+                    WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
+            mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
+                    || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
+            mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
+            mIsFloatingLayer = mIsImWindow || mIsWallpaper;
+        } else {
+            // The multiplier here is to reserve space for multiple
+            // windows in the same type layer.
+            mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
+                    * WindowManagerService.TYPE_LAYER_MULTIPLIER
+                    + WindowManagerService.TYPE_LAYER_OFFSET;
+            mSubLayer = 0;
+            mAttachedWindow = null;
+            mLayoutAttached = false;
+            mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
+                    || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
+            mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
+            mIsFloatingLayer = mIsImWindow || mIsWallpaper;
+        }
+
+        WindowState appWin = this;
+        while (appWin.mAttachedWindow != null) {
+            appWin = appWin.mAttachedWindow;
+        }
+        WindowToken appToken = appWin.mToken;
+        while (appToken.appWindowToken == null) {
+            WindowToken parent = mService.mTokenMap.get(appToken.token);
+            if (parent == null || appToken == parent) {
+                break;
+            }
+            appToken = parent;
+        }
+        mRootToken = appToken;
+        mAppToken = appToken.appWindowToken;
+
+        mWinAnimator = new WindowStateAnimator(this);
+        mWinAnimator.mAlpha = a.alpha;
+
+        mRequestedWidth = 0;
+        mRequestedHeight = 0;
+        mLastRequestedWidth = 0;
+        mLastRequestedHeight = 0;
+        mXOffset = 0;
+        mYOffset = 0;
+        mLayer = 0;
+        mInputWindowHandle = new InputWindowHandle(
+                mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
+                displayContent.getDisplayId());
+    }
+
+    void attach() {
+        if (WindowManagerService.localLOGV) Slog.v(
+            TAG, "Attaching " + this + " token=" + mToken
+            + ", list=" + mToken.windows);
+        mSession.windowAddedLocked();
+    }
+
+    @Override
+    public int getOwningUid() {
+        return mOwnerUid;
+    }
+
+    @Override
+    public String getOwningPackage() {
+        return mAttrs.packageName;
+    }
+
+    @Override
+    public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf) {
+        mHaveFrame = true;
+
+        TaskStack stack = mAppToken != null ? getStack() : null;
+        if (stack != null && !stack.isFullscreen()) {
+            getStackBounds(stack, mContainingFrame);
+            if (mUnderStatusBar) {
+                mContainingFrame.top = pf.top;
+            }
+        } else {
+            mContainingFrame.set(pf);
+        }
+
+        mDisplayFrame.set(df);
+
+        final int pw = mContainingFrame.width();
+        final int ph = mContainingFrame.height();
+
+        int w,h;
+        if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
+            if (mAttrs.width < 0) {
+                w = pw;
+            } else if (mEnforceSizeCompat) {
+                w = (int)(mAttrs.width * mGlobalScale + .5f);
+            } else {
+                w = mAttrs.width;
+            }
+            if (mAttrs.height < 0) {
+                h = ph;
+            } else if (mEnforceSizeCompat) {
+                h = (int)(mAttrs.height * mGlobalScale + .5f);
+            } else {
+                h = mAttrs.height;
+            }
+        } else {
+            if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
+                w = pw;
+            } else if (mEnforceSizeCompat) {
+                w = (int)(mRequestedWidth * mGlobalScale + .5f);
+            } else {
+                w = mRequestedWidth;
+            }
+            if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
+                h = ph;
+            } else if (mEnforceSizeCompat) {
+                h = (int)(mRequestedHeight * mGlobalScale + .5f);
+            } else {
+                h = mRequestedHeight;
+            }
+        }
+
+        if (!mParentFrame.equals(pf)) {
+            //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
+            //        + " to " + pf);
+            mParentFrame.set(pf);
+            mContentChanged = true;
+        }
+        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
+            mLastRequestedWidth = mRequestedWidth;
+            mLastRequestedHeight = mRequestedHeight;
+            mContentChanged = true;
+        }
+
+        mOverscanFrame.set(of);
+        mContentFrame.set(cf);
+        mVisibleFrame.set(vf);
+        mDecorFrame.set(dcf);
+
+        final int fw = mFrame.width();
+        final int fh = mFrame.height();
+
+        //System.out.println("In: w=" + w + " h=" + h + " container=" +
+        //                   container + " x=" + mAttrs.x + " y=" + mAttrs.y);
+
+        float x, y;
+        if (mEnforceSizeCompat) {
+            x = mAttrs.x * mGlobalScale;
+            y = mAttrs.y * mGlobalScale;
+        } else {
+            x = mAttrs.x;
+            y = mAttrs.y;
+        }
+
+        Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
+                (int) (x + mAttrs.horizontalMargin * pw),
+                (int) (y + mAttrs.verticalMargin * ph), mFrame);
+
+        //System.out.println("Out: " + mFrame);
+
+        // Now make sure the window fits in the overall display.
+        Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
+
+        // Make sure the content and visible frames are inside of the
+        // final window frame.
+        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));
+
+        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));
+
+        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));
+
+        mContentInsets.set(mContentFrame.left - mFrame.left,
+                mContentFrame.top - mFrame.top,
+                mFrame.right - mContentFrame.right,
+                mFrame.bottom - mContentFrame.bottom);
+
+        mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
+                mVisibleFrame.top - mFrame.top,
+                mFrame.right - mVisibleFrame.right,
+                mFrame.bottom - mVisibleFrame.bottom);
+
+        mCompatFrame.set(mFrame);
+        if (mEnforceSizeCompat) {
+            // If there is a size compatibility scale being applied to the
+            // window, we need to apply this to its insets so that they are
+            // reported to the app in its coordinate space.
+            mOverscanInsets.scale(mInvGlobalScale);
+            mContentInsets.scale(mInvGlobalScale);
+            mVisibleInsets.scale(mInvGlobalScale);
+
+            // Also the scaled frame that we report to the app needs to be
+            // adjusted to be in its coordinate space.
+            mCompatFrame.scale(mInvGlobalScale);
+        }
+
+        if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
+            final DisplayContent displayContent = getDisplayContent();
+            if (displayContent != null) {
+                final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+                mService.updateWallpaperOffsetLocked(this,
+                        displayInfo.logicalWidth, displayInfo.logicalHeight, false);
+            }
+        }
+
+        if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
+                "Resolving (mRequestedWidth="
+                + mRequestedWidth + ", mRequestedheight="
+                + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
+                + "): frame=" + mFrame.toShortString()
+                + " ci=" + mContentInsets.toShortString()
+                + " vi=" + mVisibleInsets.toShortString());
+    }
+
+    @Override
+    public Rect getFrameLw() {
+        return mFrame;
+    }
+
+    @Override
+    public RectF getShownFrameLw() {
+        return mShownFrame;
+    }
+
+    @Override
+    public Rect getDisplayFrameLw() {
+        return mDisplayFrame;
+    }
+
+    @Override
+    public Rect getOverscanFrameLw() {
+        return mOverscanFrame;
+    }
+
+    @Override
+    public Rect getContentFrameLw() {
+        return mContentFrame;
+    }
+
+    @Override
+    public Rect getVisibleFrameLw() {
+        return mVisibleFrame;
+    }
+
+    @Override
+    public boolean getGivenInsetsPendingLw() {
+        return mGivenInsetsPending;
+    }
+
+    @Override
+    public Rect getGivenContentInsetsLw() {
+        return mGivenContentInsets;
+    }
+
+    @Override
+    public Rect getGivenVisibleInsetsLw() {
+        return mGivenVisibleInsets;
+    }
+
+    @Override
+    public WindowManager.LayoutParams getAttrs() {
+        return mAttrs;
+    }
+
+    @Override
+    public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
+        int index = -1;
+        WindowState ws = this;
+        WindowList windows = getWindowList();
+        while (true) {
+            if ((ws.mAttrs.privateFlags
+                    & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
+                return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
+            }
+            // If we reached the bottom of the range of windows we are considering,
+            // assume no menu is needed.
+            if (ws == bottom) {
+                return false;
+            }
+            // The current window hasn't specified whether menu key is needed;
+            // look behind it.
+            // First, we may need to determine the starting position.
+            if (index < 0) {
+                index = windows.indexOf(ws);
+            }
+            index--;
+            if (index < 0) {
+                return false;
+            }
+            ws = windows.get(index);
+        }
+    }
+
+    @Override
+    public int getSystemUiVisibility() {
+        return mSystemUiVisibility;
+    }
+
+    @Override
+    public int getSurfaceLayer() {
+        return mLayer;
+    }
+
+    @Override
+    public IApplicationToken getAppToken() {
+        return mAppToken != null ? mAppToken.appToken : null;
+    }
+
+    boolean setInsetsChanged() {
+        mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
+        mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
+        mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
+        return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged;
+    }
+
+    public DisplayContent getDisplayContent() {
+        return mAppToken == null ? mDisplayContent : getStack().getDisplayContent();
+    }
+
+    public int getDisplayId() {
+        final DisplayContent displayContent = getDisplayContent();
+        if (displayContent == null) {
+            return -1;
+        }
+        return displayContent.getDisplayId();
+    }
+
+    TaskStack getStack() {
+        AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
+        if (wtoken != null) {
+            Task task = mService.mTaskIdToTask.get(wtoken.groupId);
+            if (task != null) {
+                if (task.mStack != null) {
+                    return task.mStack;
+                }
+                Slog.e(TAG, "getStack: mStack null for task=" + task);
+            } else {
+                Slog.e(TAG, "getStack: " + this + " couldn't find taskId=" + wtoken.groupId
+                    + " Callers=" + Debug.getCallers(4));
+            }
+        }
+        return mDisplayContent.getHomeStack();
+    }
+
+    void getStackBounds(Rect bounds) {
+        getStackBounds(getStack(), bounds);
+    }
+
+    private void getStackBounds(TaskStack stack, Rect bounds) {
+        if (stack != null) {
+            stack.getBounds(bounds);
+            return;
+        }
+        bounds.set(mFrame);
+    }
+
+    public long getInputDispatchingTimeoutNanos() {
+        return mAppToken != null
+                ? mAppToken.inputDispatchingTimeoutNanos
+                : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
+    }
+
+    @Override
+    public boolean hasAppShownWindows() {
+        return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
+    }
+
+    boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
+        if (dsdx < .99999f || dsdx > 1.00001f) return false;
+        if (dtdy < .99999f || dtdy > 1.00001f) return false;
+        if (dtdx < -.000001f || dtdx > .000001f) return false;
+        if (dsdy < -.000001f || dsdy > .000001f) return false;
+        return true;
+    }
+
+    void prelayout() {
+        if (mEnforceSizeCompat) {
+            mGlobalScale = mService.mCompatibleScreenScale;
+            mInvGlobalScale = 1/mGlobalScale;
+        } else {
+            mGlobalScale = mInvGlobalScale = 1;
+        }
+    }
+
+    /**
+     * Is this window visible?  It is not visible if there is no
+     * surface, or we are in the process of running an exit animation
+     * that will remove the surface, or its app token has been hidden.
+     */
+    @Override
+    public boolean isVisibleLw() {
+        final AppWindowToken atoken = mAppToken;
+        return mHasSurface && mPolicyVisibility && !mAttachedHidden
+                && (atoken == null || !atoken.hiddenRequested)
+                && !mExiting && !mDestroying;
+    }
+
+    /**
+     * Like {@link #isVisibleLw}, but also counts a window that is currently
+     * "hidden" behind the keyguard as visible.  This allows us to apply
+     * things like window flags that impact the keyguard.
+     * XXX I am starting to think we need to have ANOTHER visibility flag
+     * for this "hidden behind keyguard" state rather than overloading
+     * mPolicyVisibility.  Ungh.
+     */
+    @Override
+    public boolean isVisibleOrBehindKeyguardLw() {
+        if (mRootToken.waitingToShow &&
+                mService.mAppTransition.isTransitionSet()) {
+            return false;
+        }
+        final AppWindowToken atoken = mAppToken;
+        final boolean animating = atoken != null
+                ? (atoken.mAppAnimator.animation != null) : false;
+        return mHasSurface && !mDestroying && !mExiting
+                && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
+                && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
+                                && !mRootToken.hidden)
+                        || mWinAnimator.mAnimation != null || animating);
+    }
+
+    /**
+     * Is this window visible, ignoring its app token?  It is not visible
+     * if there is no surface, or we are in the process of running an exit animation
+     * that will remove the surface.
+     */
+    public boolean isWinVisibleLw() {
+        final AppWindowToken atoken = mAppToken;
+        return mHasSurface && mPolicyVisibility && !mAttachedHidden
+                && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
+                && !mExiting && !mDestroying;
+    }
+
+    /**
+     * The same as isVisible(), but follows the current hidden state of
+     * the associated app token, not the pending requested hidden state.
+     */
+    boolean isVisibleNow() {
+        return mHasSurface && mPolicyVisibility && !mAttachedHidden
+                && !mRootToken.hidden && !mExiting && !mDestroying;
+    }
+
+    /**
+     * Can this window possibly be a drag/drop target?  The test here is
+     * a combination of the above "visible now" with the check that the
+     * Input Manager uses when discarding windows from input consideration.
+     */
+    boolean isPotentialDragTarget() {
+        return isVisibleNow() && !mRemoved
+                && mInputChannel != null && mInputWindowHandle != null;
+    }
+
+    /**
+     * Same as isVisible(), but we also count it as visible between the
+     * call to IWindowSession.add() and the first relayout().
+     */
+    boolean isVisibleOrAdding() {
+        final AppWindowToken atoken = mAppToken;
+        return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
+                && mPolicyVisibility && !mAttachedHidden
+                && (atoken == null || !atoken.hiddenRequested)
+                && !mExiting && !mDestroying;
+    }
+
+    /**
+     * Is this window currently on-screen?  It is on-screen either if it
+     * is visible or it is currently running an animation before no longer
+     * being visible.
+     */
+    boolean isOnScreen() {
+        if (!mHasSurface || !mPolicyVisibility || mDestroying) {
+            return false;
+        }
+        final AppWindowToken atoken = mAppToken;
+        if (atoken != null) {
+            return ((!mAttachedHidden && !atoken.hiddenRequested)
+                    || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
+        }
+        return !mAttachedHidden || mWinAnimator.mAnimation != null;
+    }
+
+    /**
+     * Like isOnScreen(), but we don't return true if the window is part
+     * of a transition that has not yet been started.
+     */
+    boolean isReadyForDisplay() {
+        if (mRootToken.waitingToShow &&
+                mService.mAppTransition.isTransitionSet()) {
+            return false;
+        }
+        return mHasSurface && mPolicyVisibility && !mDestroying
+                && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
+                                && !mRootToken.hidden)
+                        || mWinAnimator.mAnimation != null
+                        || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
+    }
+
+    /**
+     * Like isReadyForDisplay(), but ignores any force hiding of the window due
+     * to the keyguard.
+     */
+    boolean isReadyForDisplayIgnoringKeyguard() {
+        if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
+            return false;
+        }
+        final AppWindowToken atoken = mAppToken;
+        if (atoken == null && !mPolicyVisibility) {
+            // If this is not an app window, and the policy has asked to force
+            // hide, then we really do want to hide.
+            return false;
+        }
+        return mHasSurface && !mDestroying
+                && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
+                                && !mRootToken.hidden)
+                        || mWinAnimator.mAnimation != null
+                        || ((atoken != null) && (atoken.mAppAnimator.animation != null)
+                                && !mWinAnimator.isDummyAnimation()));
+    }
+
+    /**
+     * Like isOnScreen, but returns false if the surface hasn't yet
+     * been drawn.
+     */
+    @Override
+    public boolean isDisplayedLw() {
+        final AppWindowToken atoken = mAppToken;
+        return isDrawnLw() && mPolicyVisibility
+            && ((!mAttachedHidden &&
+                    (atoken == null || !atoken.hiddenRequested))
+                        || mWinAnimator.mAnimating
+                        || (atoken != null && atoken.mAppAnimator.animation != null));
+    }
+
+    /**
+     * Return true if this window or its app token is currently animating.
+     */
+    @Override
+    public boolean isAnimatingLw() {
+        return mWinAnimator.mAnimation != null
+                || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
+    }
+
+    @Override
+    public boolean isGoneForLayoutLw() {
+        final AppWindowToken atoken = mAppToken;
+        return mViewVisibility == View.GONE
+                || !mRelayoutCalled
+                || (atoken == null && mRootToken.hidden)
+                || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
+                || mAttachedHidden
+                || (mExiting && !isAnimatingLw())
+                || mDestroying;
+    }
+
+    /**
+     * Returns true if the window has a surface that it has drawn a
+     * complete UI in to.
+     */
+    public boolean isDrawFinishedLw() {
+        return mHasSurface && !mDestroying &&
+                (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
+                || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
+                || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
+    }
+
+    /**
+     * Returns true if the window has a surface that it has drawn a
+     * complete UI in to.
+     */
+    public boolean isDrawnLw() {
+        return mHasSurface && !mDestroying &&
+                (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
+                || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
+    }
+
+    /**
+     * Return true if the window is opaque and fully drawn.  This indicates
+     * it may obscure windows behind it.
+     */
+    boolean isOpaqueDrawn() {
+        return (mAttrs.format == PixelFormat.OPAQUE
+                        || mAttrs.type == TYPE_WALLPAPER)
+                && isDrawnLw() && mWinAnimator.mAnimation == null
+                && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
+    }
+
+    /**
+     * Return whether this window is wanting to have a translation
+     * animation applied to it for an in-progress move.  (Only makes
+     * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
+     */
+    boolean shouldAnimateMove() {
+        return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
+                && (mFrame.top != mLastFrame.top
+                        || mFrame.left != mLastFrame.left)
+                && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
+                && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
+    }
+
+    boolean isFullscreen(int screenWidth, int screenHeight) {
+        return mFrame.left <= 0 && mFrame.top <= 0 &&
+                mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
+    }
+
+    boolean isConfigChanged() {
+        boolean configChanged = mConfiguration != mService.mCurConfiguration
+                && (mConfiguration == null
+                        || (mConfiguration.diff(mService.mCurConfiguration) != 0));
+
+        if (mAttrs.type == TYPE_KEYGUARD) {
+            // Retain configuration changed status until resetConfiguration called.
+            mConfigHasChanged |= configChanged;
+            configChanged = mConfigHasChanged;
+        }
+
+        return configChanged;
+    }
+
+    void removeLocked() {
+        disposeInputChannel();
+
+        if (mAttachedWindow != null) {
+            if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
+            mAttachedWindow.mChildWindows.remove(this);
+        }
+        mWinAnimator.destroyDeferredSurfaceLocked();
+        mWinAnimator.destroySurfaceLocked();
+        mSession.windowRemovedLocked();
+        try {
+            mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
+        } catch (RuntimeException e) {
+            // Ignore if it has already been removed (usually because
+            // we are doing this as part of processing a death note.)
+        }
+    }
+
+    void setConfiguration(final Configuration newConfig) {
+        mConfiguration = newConfig;
+        mConfigHasChanged = false;
+    }
+
+    void setInputChannel(InputChannel inputChannel) {
+        if (mInputChannel != null) {
+            throw new IllegalStateException("Window already has an input channel.");
+        }
+
+        mInputChannel = inputChannel;
+        mInputWindowHandle.inputChannel = inputChannel;
+    }
+
+    void disposeInputChannel() {
+        if (mInputChannel != null) {
+            mService.mInputManager.unregisterInputChannel(mInputChannel);
+
+            mInputChannel.dispose();
+            mInputChannel = null;
+        }
+
+        mInputWindowHandle.inputChannel = null;
+    }
+
+    private class DeathRecipient implements IBinder.DeathRecipient {
+        @Override
+        public void binderDied() {
+            try {
+                synchronized(mService.mWindowMap) {
+                    WindowState win = mService.windowForClientLocked(mSession, mClient, false);
+                    Slog.i(TAG, "WIN DEATH: " + win);
+                    if (win != null) {
+                        mService.removeWindowLocked(mSession, win);
+                    } else if (mHasSurface) {
+                        Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
+                        mService.removeWindowLocked(mSession, WindowState.this);
+                    }
+                }
+            } catch (IllegalArgumentException ex) {
+                // This will happen if the window has already been
+                // removed.
+            }
+        }
+    }
+
+    /**
+     * @return true if this window desires key events.
+     */
+    public final boolean canReceiveKeys() {
+        return isVisibleOrAdding()
+                && (mViewVisibility == View.VISIBLE)
+                && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
+    }
+
+    @Override
+    public boolean hasDrawnLw() {
+        return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
+    }
+
+    @Override
+    public boolean showLw(boolean doAnimation) {
+        return showLw(doAnimation, true);
+    }
+
+    boolean showLw(boolean doAnimation, boolean requestAnim) {
+        if (isHiddenFromUserLocked()) {
+            Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
+                    + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
+            return false;
+        }
+        if (!mAppOpVisibility) {
+            // Being hidden due to app op request.
+            return false;
+        }
+        if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
+            // Already showing.
+            return false;
+        }
+        if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
+        if (doAnimation) {
+            if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
+                    + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
+            if (!mService.okToDisplay()) {
+                doAnimation = false;
+            } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
+                // Check for the case where we are currently visible and
+                // not animating; we do not want to do animation at such a
+                // point to become visible when we already are.
+                doAnimation = false;
+            }
+        }
+        mPolicyVisibility = true;
+        mPolicyVisibilityAfterAnim = true;
+        if (doAnimation) {
+            mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
+        }
+        if (requestAnim) {
+            mService.scheduleAnimationLocked();
+        }
+        return true;
+    }
+
+    @Override
+    public boolean hideLw(boolean doAnimation) {
+        return hideLw(doAnimation, true);
+    }
+
+    boolean hideLw(boolean doAnimation, boolean requestAnim) {
+        if (doAnimation) {
+            if (!mService.okToDisplay()) {
+                doAnimation = false;
+            }
+        }
+        boolean current = doAnimation ? mPolicyVisibilityAfterAnim
+                : mPolicyVisibility;
+        if (!current) {
+            // Already hiding.
+            return false;
+        }
+        if (doAnimation) {
+            mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
+            if (mWinAnimator.mAnimation == null) {
+                doAnimation = false;
+            }
+        }
+        if (doAnimation) {
+            mPolicyVisibilityAfterAnim = false;
+        } else {
+            if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
+            mPolicyVisibilityAfterAnim = false;
+            mPolicyVisibility = false;
+            // Window is no longer visible -- make sure if we were waiting
+            // for it to be displayed before enabling the display, that
+            // we allow the display to be enabled now.
+            mService.enableScreenIfNeededLocked();
+            if (mService.mCurrentFocus == this) {
+                if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
+                        "WindowState.hideLw: setting mFocusMayChange true");
+                mService.mFocusMayChange = true;
+            }
+        }
+        if (requestAnim) {
+            mService.scheduleAnimationLocked();
+        }
+        return true;
+    }
+
+    public void setAppOpVisibilityLw(boolean state) {
+        if (mAppOpVisibility != state) {
+            mAppOpVisibility = state;
+            if (state) {
+                // If the policy visibility had last been to hide, then this
+                // will incorrectly show at this point since we lost that
+                // information.  Not a big deal -- for the windows that have app
+                // ops modifies they should only be hidden by policy due to the
+                // lock screen, and the user won't be changing this if locked.
+                // Plus it will quickly be fixed the next time we do a layout.
+                showLw(true, true);
+            } else {
+                hideLw(true, true);
+            }
+        }
+    }
+
+    @Override
+    public boolean isAlive() {
+        return mClient.asBinder().isBinderAlive();
+    }
+
+    boolean isClosing() {
+        return mExiting || (mService.mClosingApps.contains(mAppToken));
+    }
+
+    @Override
+    public boolean isDefaultDisplay() {
+        final DisplayContent displayContent = getDisplayContent();
+        if (displayContent == null) {
+            // Only a window that was on a non-default display can be detached from it.
+            return false;
+        }
+        return getDisplayContent().isDefaultDisplay;
+    }
+
+    public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
+        mShowToOwnerOnly = showToOwnerOnly;
+    }
+
+    boolean isHiddenFromUserLocked() {
+        // Attached windows are evaluated based on the window that they are attached to.
+        WindowState win = this;
+        while (win.mAttachedWindow != null) {
+            win = win.mAttachedWindow;
+        }
+        if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
+                && win.mAppToken != null && win.mAppToken.showWhenLocked) {
+            // Save some cycles by not calling getDisplayInfo unless it is an application
+            // window intended for all users.
+            final DisplayContent displayContent = win.getDisplayContent();
+            if (displayContent == null) {
+                return true;
+            }
+            final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+            if (win.mFrame.left <= 0 && win.mFrame.top <= 0
+                    && win.mFrame.right >= displayInfo.appWidth
+                    && win.mFrame.bottom >= displayInfo.appHeight) {
+                // Is a fullscreen window, like the clock alarm. Show to everyone.
+                return false;
+            }
+        }
+
+        return win.mShowToOwnerOnly
+                && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
+    }
+
+    private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
+        outRegion.set(
+                frame.left + inset.left, frame.top + inset.top,
+                frame.right - inset.right, frame.bottom - inset.bottom);
+    }
+
+    public void getTouchableRegion(Region outRegion) {
+        final Rect frame = mFrame;
+        switch (mTouchableInsets) {
+            default:
+            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
+                outRegion.set(frame);
+                break;
+            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
+                applyInsets(outRegion, frame, mGivenContentInsets);
+                break;
+            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
+                applyInsets(outRegion, frame, mGivenVisibleInsets);
+                break;
+            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
+                final Region givenTouchableRegion = mGivenTouchableRegion;
+                outRegion.set(givenTouchableRegion);
+                outRegion.translate(frame.left, frame.top);
+                break;
+            }
+        }
+    }
+
+    WindowList getWindowList() {
+        final DisplayContent displayContent = getDisplayContent();
+        return displayContent == null ? null : displayContent.getWindowList();
+    }
+
+    /**
+     * Report a focus change.  Must be called with no locks held, and consistently
+     * from the same serialized thread (such as dispatched from a handler).
+     */
+    public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
+        try {
+            mClient.windowFocusChanged(focused, inTouchMode);
+        } catch (RemoteException e) {
+        }
+        if (mFocusCallbacks != null) {
+            final int N = mFocusCallbacks.beginBroadcast();
+            for (int i=0; i<N; i++) {
+                IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
+                try {
+                    if (focused) {
+                        obs.focusGained(mWindowId.asBinder());
+                    } else {
+                        obs.focusLost(mWindowId.asBinder());
+                    }
+                } catch (RemoteException e) {
+                }
+            }
+            mFocusCallbacks.finishBroadcast();
+        }
+    }
+
+    void reportResized() {
+        try {
+            if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + this
+                    + ": " + mCompatFrame);
+            boolean configChanged = isConfigChanged();
+            if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) {
+                Slog.i(TAG, "Sending new config to window " + this + ": "
+                        + mWinAnimator.mSurfaceW + "x" + mWinAnimator.mSurfaceH
+                        + " / " + mService.mCurConfiguration);
+            }
+            setConfiguration(mService.mCurConfiguration);
+            if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
+                Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
+
+            final Rect frame = mFrame;
+            final Rect overscanInsets = mLastOverscanInsets;
+            final Rect contentInsets = mLastContentInsets;
+            final Rect visibleInsets = mLastVisibleInsets;
+            final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
+            final Configuration newConfig = configChanged ? mConfiguration : null;
+            if (mClient instanceof IWindow.Stub) {
+                // To prevent deadlock simulate one-way call if win.mClient is a local object.
+                mService.mH.post(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            mClient.resized(frame, overscanInsets, contentInsets,
+                                    visibleInsets, reportDraw, newConfig);
+                        } catch (RemoteException e) {
+                            // Not a remote call, RemoteException won't be raised.
+                        }
+                    }
+                });
+            } else {
+                mClient.resized(frame, overscanInsets, contentInsets, visibleInsets, reportDraw,
+                        newConfig);
+            }
+            mOverscanInsetsChanged = false;
+            mContentInsetsChanged = false;
+            mVisibleInsetsChanged = false;
+            mWinAnimator.mSurfaceResized = false;
+        } catch (RemoteException e) {
+            mOrientationChanging = false;
+            mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
+                    - mService.mDisplayFreezeTime);
+        }
+    }
+
+    public void registerFocusObserver(IWindowFocusObserver observer) {
+        synchronized(mService.mWindowMap) {
+            if (mFocusCallbacks == null) {
+                mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
+            }
+            mFocusCallbacks.register(observer);
+        }
+    }
+
+    public void unregisterFocusObserver(IWindowFocusObserver observer) {
+        synchronized(mService.mWindowMap) {
+            if (mFocusCallbacks != null) {
+                mFocusCallbacks.unregister(observer);
+            }
+        }
+    }
+
+    public boolean isFocused() {
+        synchronized(mService.mWindowMap) {
+            return mService.mCurrentFocus == this;
+        }
+    }
+
+    void dump(PrintWriter pw, String prefix, boolean dumpAll) {
+        pw.print(prefix); pw.print("mDisplayId="); pw.print(getDisplayId());
+                pw.print(" mSession="); pw.print(mSession);
+                pw.print(" mClient="); pw.println(mClient.asBinder());
+        pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
+                pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
+                pw.print(" package="); pw.print(mAttrs.packageName);
+                pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
+        pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
+        pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
+                pw.print(" h="); pw.print(mRequestedHeight);
+                pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
+        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
+            pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
+                    pw.print(" h="); pw.println(mLastRequestedHeight);
+        }
+        if (mAttachedWindow != null || mLayoutAttached) {
+            pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
+                    pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
+        }
+        if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
+            pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
+                    pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
+                    pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
+                    pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
+        }
+        if (dumpAll) {
+            pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
+                    pw.print(" mSubLayer="); pw.print(mSubLayer);
+                    pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
+                    pw.print((mTargetAppToken != null ?
+                            mTargetAppToken.mAppAnimator.animLayerAdjustment
+                          : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
+                    pw.print("="); pw.print(mWinAnimator.mAnimLayer);
+                    pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
+        }
+        if (dumpAll) {
+            pw.print(prefix); pw.print("mToken="); pw.println(mToken);
+            pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
+            if (mAppToken != null) {
+                pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
+            }
+            if (mTargetAppToken != null) {
+                pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
+            }
+            pw.print(prefix); pw.print("mViewVisibility=0x");
+            pw.print(Integer.toHexString(mViewVisibility));
+            pw.print(" mHaveFrame="); pw.print(mHaveFrame);
+            pw.print(" mObscured="); pw.println(mObscured);
+            pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
+            pw.print(" mSystemUiVisibility=0x");
+            pw.println(Integer.toHexString(mSystemUiVisibility));
+        }
+        if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
+                || mAttachedHidden) {
+            pw.print(prefix); pw.print("mPolicyVisibility=");
+                    pw.print(mPolicyVisibility);
+                    pw.print(" mPolicyVisibilityAfterAnim=");
+                    pw.print(mPolicyVisibilityAfterAnim);
+                    pw.print(" mAppOpVisibility=");
+                    pw.print(mAppOpVisibility);
+                    pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
+        }
+        if (!mRelayoutCalled || mLayoutNeeded) {
+            pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
+                    pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
+        }
+        if (mXOffset != 0 || mYOffset != 0) {
+            pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
+                    pw.print(" y="); pw.println(mYOffset);
+        }
+        if (dumpAll) {
+            pw.print(prefix); pw.print("mGivenContentInsets=");
+                    mGivenContentInsets.printShortString(pw);
+                    pw.print(" mGivenVisibleInsets=");
+                    mGivenVisibleInsets.printShortString(pw);
+                    pw.println();
+            if (mTouchableInsets != 0 || mGivenInsetsPending) {
+                pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
+                        pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
+                Region region = new Region();
+                getTouchableRegion(region);
+                pw.print(prefix); pw.print("touchable region="); pw.println(region);
+            }
+            pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
+        }
+        pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
+                pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
+                pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
+        if (dumpAll) {
+            pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
+                    pw.print(" last="); mLastFrame.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
+                    pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
+                    pw.println();
+        }
+        if (mEnforceSizeCompat) {
+            pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
+                    pw.println();
+        }
+        if (dumpAll) {
+            pw.print(prefix); pw.print("Frames: containing=");
+                    mContainingFrame.printShortString(pw);
+                    pw.print(" parent="); mParentFrame.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("    display="); mDisplayFrame.printShortString(pw);
+                    pw.print(" overscan="); mOverscanFrame.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("    content="); mContentFrame.printShortString(pw);
+                    pw.print(" visible="); mVisibleFrame.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("    decor="); mDecorFrame.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("Cur insets: overscan=");
+                    mOverscanInsets.printShortString(pw);
+                    pw.print(" content="); mContentInsets.printShortString(pw);
+                    pw.print(" visible="); mVisibleInsets.printShortString(pw);
+                    pw.println();
+            pw.print(prefix); pw.print("Lst insets: overscan=");
+                    mLastOverscanInsets.printShortString(pw);
+                    pw.print(" content="); mLastContentInsets.printShortString(pw);
+                    pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
+                    pw.println();
+        }
+        pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
+        mWinAnimator.dump(pw, prefix + "  ", dumpAll);
+        if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
+            pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
+                    pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
+                    pw.print(" mDestroying="); pw.print(mDestroying);
+                    pw.print(" mRemoved="); pw.println(mRemoved);
+        }
+        if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
+            pw.print(prefix); pw.print("mOrientationChanging=");
+                    pw.print(mOrientationChanging);
+                    pw.print(" mAppFreezing="); pw.print(mAppFreezing);
+                    pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
+        }
+        if (mLastFreezeDuration != 0) {
+            pw.print(prefix); pw.print("mLastFreezeDuration=");
+                    TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
+        }
+        if (mHScale != 1 || mVScale != 1) {
+            pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
+                    pw.print(" mVScale="); pw.println(mVScale);
+        }
+        if (mWallpaperX != -1 || mWallpaperY != -1) {
+            pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
+                    pw.print(" mWallpaperY="); pw.println(mWallpaperY);
+        }
+        if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
+            pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
+                    pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
+        }
+    }
+
+    String makeInputChannelName() {
+        return Integer.toHexString(System.identityHashCode(this))
+            + " " + mAttrs.getTitle();
+    }
+
+    @Override
+    public String toString() {
+        CharSequence title = mAttrs.getTitle();
+        if (title == null || title.length() <= 0) {
+            title = mAttrs.packageName;
+        }
+        if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
+            mLastTitle = title;
+            mWasExiting = mExiting;
+            mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
+                    + " u" + UserHandle.getUserId(mSession.mUid)
+                    + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
+        }
+        return mStringNameCache;
+    }
+}
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
new file mode 100644
index 0000000..93f6d22
--- /dev/null
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -0,0 +1,1710 @@
+/*
+ * 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.server.wm;
+
+import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
+import static com.android.server.wm.WindowManagerService.DEBUG_ANIM;
+import static com.android.server.wm.WindowManagerService.DEBUG_LAYERS;
+import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
+import static com.android.server.wm.WindowManagerService.DEBUG_STARTING_WINDOW;
+import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
+import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS;
+import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
+import static com.android.server.wm.WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
+import static com.android.server.wm.WindowManagerService.SHOW_SURFACE_ALLOC;
+import static com.android.server.wm.WindowManagerService.localLOGV;
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
+import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
+
+import android.content.Context;
+import android.graphics.Matrix;
+import android.graphics.PixelFormat;
+import android.graphics.Point;
+import android.graphics.PointF;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Region;
+import android.os.Debug;
+import android.util.Slog;
+import android.view.Display;
+import android.view.DisplayInfo;
+import android.view.MagnificationSpec;
+import android.view.Surface.OutOfResourcesException;
+import android.view.SurfaceControl;
+import android.view.SurfaceSession;
+import android.view.WindowManager;
+import android.view.WindowManagerPolicy;
+import android.view.WindowManager.LayoutParams;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.view.animation.Transformation;
+
+import com.android.server.wm.WindowManagerService.H;
+
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+class WinAnimatorList extends ArrayList<WindowStateAnimator> {
+}
+
+/**
+ * Keep track of animations and surface operations for a single WindowState.
+ **/
+class WindowStateAnimator {
+    static final String TAG = "WindowStateAnimator";
+
+    // Unchanging local convenience fields.
+    final WindowManagerService mService;
+    final WindowState mWin;
+    final WindowStateAnimator mAttachedWinAnimator;
+    final WindowAnimator mAnimator;
+    AppWindowAnimator mAppAnimator;
+    final Session mSession;
+    final WindowManagerPolicy mPolicy;
+    final Context mContext;
+    final boolean mIsWallpaper;
+
+    // If this is a universe background window, this is the transformation
+    // it is applying to the rest of the universe.
+    final Transformation mUniverseTransform = new Transformation();
+
+    // Currently running animation.
+    boolean mAnimating;
+    boolean mLocalAnimating;
+    Animation mAnimation;
+    boolean mAnimationIsEntrance;
+    boolean mHasTransformation;
+    boolean mHasLocalTransformation;
+    final Transformation mTransformation = new Transformation();
+    boolean mWasAnimating;      // Were we animating going into the most recent animation step?
+    int mAnimLayer;
+    int mLastLayer;
+
+    SurfaceControl mSurfaceControl;
+    SurfaceControl mPendingDestroySurface;
+
+    /**
+     * Set when we have changed the size of the surface, to know that
+     * we must tell them application to resize (and thus redraw itself).
+     */
+    boolean mSurfaceResized;
+
+    /**
+     * Set if the client has asked that the destroy of its surface be delayed
+     * until it explicitly says it is okay.
+     */
+    boolean mSurfaceDestroyDeferred;
+
+    float mShownAlpha = 0;
+    float mAlpha = 0;
+    float mLastAlpha = 0;
+
+    // Used to save animation distances between the time they are calculated and when they are
+    // used.
+    int mAnimDw;
+    int mAnimDh;
+    float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
+    float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
+
+    boolean mHaveMatrix;
+
+    // For debugging, this is the last information given to the surface flinger.
+    boolean mSurfaceShown;
+    float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
+    int mSurfaceLayer;
+    float mSurfaceAlpha;
+
+    // Set to true if, when the window gets displayed, it should perform
+    // an enter animation.
+    boolean mEnterAnimationPending;
+
+    /** This is set when there is no Surface */
+    static final int NO_SURFACE = 0;
+    /** This is set after the Surface has been created but before the window has been drawn. During
+     * this time the surface is hidden. */
+    static final int DRAW_PENDING = 1;
+    /** This is set after the window has finished drawing for the first time but before its surface
+     * is shown.  The surface will be displayed when the next layout is run. */
+    static final int COMMIT_DRAW_PENDING = 2;
+    /** This is set during the time after the window's drawing has been committed, and before its
+     * surface is actually shown.  It is used to delay showing the surface until all windows in a
+     * token are ready to be shown. */
+    static final int READY_TO_SHOW = 3;
+    /** Set when the window has been shown in the screen the first time. */
+    static final int HAS_DRAWN = 4;
+    static String drawStateToString(int state) {
+        switch (state) {
+            case NO_SURFACE: return "NO_SURFACE";
+            case DRAW_PENDING: return "DRAW_PENDING";
+            case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
+            case READY_TO_SHOW: return "READY_TO_SHOW";
+            case HAS_DRAWN: return "HAS_DRAWN";
+            default: return Integer.toString(state);
+        }
+    }
+    int mDrawState;
+
+    /** Was this window last hidden? */
+    boolean mLastHidden;
+
+    int mAttrFlags;
+    int mAttrType;
+
+    public WindowStateAnimator(final WindowState win) {
+        final WindowManagerService service = win.mService;
+
+        mService = service;
+        mAnimator = service.mAnimator;
+        mPolicy = service.mPolicy;
+        mContext = service.mContext;
+        final DisplayInfo displayInfo = win.getDisplayContent().getDisplayInfo();
+        mAnimDw = displayInfo.appWidth;
+        mAnimDh = displayInfo.appHeight;
+
+        mWin = win;
+        mAttachedWinAnimator = win.mAttachedWindow == null
+                ? null : win.mAttachedWindow.mWinAnimator;
+        mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
+        mSession = win.mSession;
+        mAttrFlags = win.mAttrs.flags;
+        mAttrType = win.mAttrs.type;
+        mIsWallpaper = win.mIsWallpaper;
+    }
+
+    public void setAnimation(Animation anim) {
+        if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
+        mAnimating = false;
+        mLocalAnimating = false;
+        mAnimation = anim;
+        mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
+        mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
+        // Start out animation gone if window is gone, or visible if window is visible.
+        mTransformation.clear();
+        mTransformation.setAlpha(mLastHidden ? 0 : 1);
+        mHasLocalTransformation = true;
+    }
+
+    public void clearAnimation() {
+        if (mAnimation != null) {
+            mAnimating = true;
+            mLocalAnimating = false;
+            mAnimation.cancel();
+            mAnimation = null;
+        }
+    }
+
+    /** Is the window or its container currently animating? */
+    boolean isAnimating() {
+        return mAnimation != null
+                || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
+                || (mAppAnimator != null &&
+                        (mAppAnimator.animation != null
+                                || mAppAnimator.mAppToken.inPendingTransaction));
+    }
+
+    /** Is the window animating the DummyAnimation? */
+    boolean isDummyAnimation() {
+        return mAppAnimator != null
+                && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
+    }
+
+    /** Is this window currently animating? */
+    boolean isWindowAnimating() {
+        return mAnimation != null;
+    }
+
+    void cancelExitAnimationForNextAnimationLocked() {
+        if (mAnimation != null) {
+            mAnimation.cancel();
+            mAnimation = null;
+            mLocalAnimating = false;
+            destroySurfaceLocked();
+        }
+    }
+
+    private boolean stepAnimation(long currentTime) {
+        if ((mAnimation == null) || !mLocalAnimating) {
+            return false;
+        }
+        mTransformation.clear();
+        final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
+        if (false && DEBUG_ANIM) Slog.v(
+            TAG, "Stepped animation in " + this +
+            ": more=" + more + ", xform=" + mTransformation);
+        return more;
+    }
+
+    // This must be called while inside a transaction.  Returns true if
+    // there is more animation to run.
+    boolean stepAnimationLocked(long currentTime) {
+        // Save the animation state as it was before this step so WindowManagerService can tell if
+        // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
+        mWasAnimating = mAnimating;
+        final DisplayContent displayContent = mWin.getDisplayContent();
+        if (displayContent != null && mService.okToDisplay()) {
+            // We will run animations as long as the display isn't frozen.
+
+            if (mWin.isDrawnLw() && mAnimation != null) {
+                mHasTransformation = true;
+                mHasLocalTransformation = true;
+                if (!mLocalAnimating) {
+                    if (DEBUG_ANIM) Slog.v(
+                        TAG, "Starting animation in " + this +
+                        " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
+                        " wh=" + mWin.mFrame.height() +
+                        " dw=" + mAnimDw + " dh=" + mAnimDh +
+                        " scale=" + mService.mWindowAnimationScale);
+                    mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
+                            mAnimDw, mAnimDh);
+                    final DisplayInfo displayInfo = displayContent.getDisplayInfo();
+                    mAnimDw = displayInfo.appWidth;
+                    mAnimDh = displayInfo.appHeight;
+                    mAnimation.setStartTime(currentTime);
+                    mLocalAnimating = true;
+                    mAnimating = true;
+                }
+                if ((mAnimation != null) && mLocalAnimating) {
+                    if (stepAnimation(currentTime)) {
+                        return true;
+                    }
+                }
+                if (DEBUG_ANIM) Slog.v(
+                    TAG, "Finished animation in " + this +
+                    " @ " + currentTime);
+                //WindowManagerService.this.dump();
+            }
+            mHasLocalTransformation = false;
+            if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
+                    && mAppAnimator.animation != null) {
+                // When our app token is animating, we kind-of pretend like
+                // we are as well.  Note the mLocalAnimating mAnimationIsEntrance
+                // part of this check means that we will only do this if
+                // our window is not currently exiting, or it is not
+                // locally animating itself.  The idea being that one that
+                // is exiting and doing a local animation should be removed
+                // once that animation is done.
+                mAnimating = true;
+                mHasTransformation = true;
+                mTransformation.clear();
+                return false;
+            } else if (mHasTransformation) {
+                // Little trick to get through the path below to act like
+                // we have finished an animation.
+                mAnimating = true;
+            } else if (isAnimating()) {
+                mAnimating = true;
+            }
+        } else if (mAnimation != null) {
+            // If the display is frozen, and there is a pending animation,
+            // clear it and make sure we run the cleanup code.
+            mAnimating = true;
+        }
+
+        if (!mAnimating && !mLocalAnimating) {
+            return false;
+        }
+
+        // Done animating, clean up.
+        if (DEBUG_ANIM) Slog.v(
+            TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
+            + ", reportedVisible="
+            + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
+
+        mAnimating = false;
+        mLocalAnimating = false;
+        if (mAnimation != null) {
+            mAnimation.cancel();
+            mAnimation = null;
+        }
+        if (mAnimator.mWindowDetachedWallpaper == mWin) {
+            mAnimator.mWindowDetachedWallpaper = null;
+        }
+        mAnimLayer = mWin.mLayer;
+        if (mWin.mIsImWindow) {
+            mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
+        } else if (mIsWallpaper) {
+            mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
+        }
+        if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
+                + " anim layer: " + mAnimLayer);
+        mHasTransformation = false;
+        mHasLocalTransformation = false;
+        if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
+            if (DEBUG_VISIBILITY) {
+                Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
+                        + mWin.mPolicyVisibilityAfterAnim);
+            }
+            mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
+            if (displayContent != null) {
+                displayContent.layoutNeeded = true;
+            }
+            if (!mWin.mPolicyVisibility) {
+                if (mService.mCurrentFocus == mWin) {
+                    if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
+                            "setAnimationLocked: setting mFocusMayChange true");
+                    mService.mFocusMayChange = true;
+                }
+                // Window is no longer visible -- make sure if we were waiting
+                // for it to be displayed before enabling the display, that
+                // we allow the display to be enabled now.
+                mService.enableScreenIfNeededLocked();
+            }
+        }
+        mTransformation.clear();
+        if (mDrawState == HAS_DRAWN
+                && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
+                && mWin.mAppToken != null
+                && mWin.mAppToken.firstWindowDrawn
+                && mWin.mAppToken.startingData != null) {
+            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
+                    + mWin.mToken + ": first real window done animating");
+            mService.mFinishedStarting.add(mWin.mAppToken);
+            mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
+        } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
+            // Upon completion of a not-visible to visible status bar animation a relayout is
+            // required.
+            if (displayContent != null) {
+                displayContent.layoutNeeded = true;
+            }
+        }
+
+        finishExit();
+        final int displayId = mWin.getDisplayId();
+        mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
+        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
+                "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
+
+        if (mWin.mAppToken != null) {
+            mWin.mAppToken.updateReportedVisibilityLocked();
+        }
+
+        return false;
+    }
+
+    void finishExit() {
+        if (WindowManagerService.DEBUG_ANIM) Slog.v(
+                TAG, "finishExit in " + this
+                + ": exiting=" + mWin.mExiting
+                + " remove=" + mWin.mRemoveOnExit
+                + " windowAnimating=" + isWindowAnimating());
+
+        final int N = mWin.mChildWindows.size();
+        for (int i=0; i<N; i++) {
+            mWin.mChildWindows.get(i).mWinAnimator.finishExit();
+        }
+
+        if (!mWin.mExiting) {
+            return;
+        }
+
+        if (isWindowAnimating()) {
+            return;
+        }
+
+        if (WindowManagerService.localLOGV) Slog.v(
+                TAG, "Exit animation finished in " + this
+                + ": remove=" + mWin.mRemoveOnExit);
+        if (mSurfaceControl != null) {
+            mService.mDestroySurface.add(mWin);
+            mWin.mDestroying = true;
+            if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(
+                mWin, "HIDE (finishExit)", null);
+            hide();
+        }
+        mWin.mExiting = false;
+        if (mWin.mRemoveOnExit) {
+            mService.mPendingRemove.add(mWin);
+            mWin.mRemoveOnExit = false;
+        }
+        mAnimator.hideWallpapersLocked(mWin);
+    }
+
+    void hide() {
+        if (!mLastHidden) {
+            //dump();
+            mLastHidden = true;
+            if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
+                    "HIDE (performLayout)", null);
+            if (mSurfaceControl != null) {
+                mSurfaceShown = false;
+                try {
+                    mSurfaceControl.hide();
+                } catch (RuntimeException e) {
+                    Slog.w(TAG, "Exception hiding surface in " + mWin);
+                }
+            }
+        }
+    }
+
+    boolean finishDrawingLocked() {
+        if (DEBUG_STARTING_WINDOW &&
+                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
+            Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
+                    + drawStateToString(mDrawState));
+        }
+        if (mDrawState == DRAW_PENDING) {
+            if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
+                Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
+                        + mSurfaceControl);
+            if (DEBUG_STARTING_WINDOW &&
+                    mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
+                Slog.v(TAG, "Draw state now committed in " + mWin);
+            }
+            mDrawState = COMMIT_DRAW_PENDING;
+            return true;
+        }
+        return false;
+    }
+
+    // This must be called while inside a transaction.
+    boolean commitFinishDrawingLocked(long currentTime) {
+        if (DEBUG_STARTING_WINDOW &&
+                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
+            Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
+                    + drawStateToString(mDrawState));
+        }
+        if (mDrawState != COMMIT_DRAW_PENDING) {
+            return false;
+        }
+        if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
+            Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl);
+        }
+        mDrawState = READY_TO_SHOW;
+        final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
+        final AppWindowToken atoken = mWin.mAppToken;
+        if (atoken == null || atoken.allDrawn || starting) {
+            performShowLocked();
+        }
+        return true;
+    }
+
+    static class SurfaceTrace extends SurfaceControl {
+        private final static String SURFACE_TAG = "SurfaceTrace";
+        final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
+
+        private float mSurfaceTraceAlpha = 0;
+        private int mLayer;
+        private final PointF mPosition = new PointF();
+        private final Point mSize = new Point();
+        private final Rect mWindowCrop = new Rect();
+        private boolean mShown = false;
+        private int mLayerStack;
+        private boolean mIsOpaque;
+        private final String mName;
+
+        public SurfaceTrace(SurfaceSession s,
+                       String name, int w, int h, int format, int flags)
+                   throws OutOfResourcesException {
+            super(s, name, w, h, format, flags);
+            mName = name != null ? name : "Not named";
+            mSize.set(w, h);
+            Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
+                    + Debug.getCallers(3));
+        }
+
+        @Override
+        public void setAlpha(float alpha) {
+            if (mSurfaceTraceAlpha != alpha) {
+                Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this + ". Called by "
+                        + Debug.getCallers(3));
+                mSurfaceTraceAlpha = alpha;
+            }
+            super.setAlpha(alpha);
+        }
+
+        @Override
+        public void setLayer(int zorder) {
+            if (zorder != mLayer) {
+                Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this + ". Called by "
+                        + Debug.getCallers(3));
+                mLayer = zorder;
+            }
+            super.setLayer(zorder);
+
+            sSurfaces.remove(this);
+            int i;
+            for (i = sSurfaces.size() - 1; i >= 0; i--) {
+                SurfaceTrace s = sSurfaces.get(i);
+                if (s.mLayer < zorder) {
+                    break;
+                }
+            }
+            sSurfaces.add(i + 1, this);
+        }
+
+        @Override
+        public void setPosition(float x, float y) {
+            if (x != mPosition.x || y != mPosition.y) {
+                Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:" + this
+                        + ". Called by " + Debug.getCallers(3));
+                mPosition.set(x, y);
+            }
+            super.setPosition(x, y);
+        }
+
+        @Override
+        public void setSize(int w, int h) {
+            if (w != mSize.x || h != mSize.y) {
+                Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:" + this + ". Called by "
+                        + Debug.getCallers(3));
+                mSize.set(w, h);
+            }
+            super.setSize(w, h);
+        }
+
+        @Override
+        public void setWindowCrop(Rect crop) {
+            if (crop != null) {
+                if (!crop.equals(mWindowCrop)) {
+                    Slog.v(SURFACE_TAG, "setWindowCrop(" + crop.toShortString() + "): OLD:" + this
+                            + ". Called by " + Debug.getCallers(3));
+                    mWindowCrop.set(crop);
+                }
+            }
+            super.setWindowCrop(crop);
+        }
+
+        @Override
+        public void setLayerStack(int layerStack) {
+            if (layerStack != mLayerStack) {
+                Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:" + this
+                        + ". Called by " + Debug.getCallers(3));
+                mLayerStack = layerStack;
+            }
+            super.setLayerStack(layerStack);
+        }
+
+        @Override
+        public void setOpaque(boolean isOpaque) {
+            if (isOpaque != mIsOpaque) {
+                Slog.v(SURFACE_TAG, "setOpaque(" + isOpaque + "): OLD:" + this
+                        + ". Called by " + Debug.getCallers(3));
+                mIsOpaque = isOpaque;
+            }
+            super.setOpaque(isOpaque);
+        }
+
+        @Override
+        public void hide() {
+            if (mShown) {
+                Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by " + Debug.getCallers(3));
+                mShown = false;
+            }
+            super.hide();
+        }
+
+        @Override
+        public void show() {
+            if (!mShown) {
+                Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by " + Debug.getCallers(3));
+                mShown = true;
+            }
+            super.show();
+        }
+
+        @Override
+        public void destroy() {
+            super.destroy();
+            Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " + Debug.getCallers(3));
+            sSurfaces.remove(this);
+        }
+
+        @Override
+        public void release() {
+            super.release();
+            Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
+                    + Debug.getCallers(3));
+            sSurfaces.remove(this);
+        }
+
+        static void dumpAllSurfaces() {
+            final int N = sSurfaces.size();
+            for (int i = 0; i < N; i++) {
+                Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
+                    + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer
+                    + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
+                    + " " + mSize.x + "x" + mSize.y
+                    + " crop=" + mWindowCrop.toShortString()
+                    + " opaque=" + mIsOpaque;
+        }
+    }
+
+    SurfaceControl createSurfaceLocked() {
+        if (mSurfaceControl == null) {
+            if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
+                    "createSurface " + this + ": mDrawState=DRAW_PENDING");
+            mDrawState = DRAW_PENDING;
+            if (mWin.mAppToken != null) {
+                if (mWin.mAppToken.mAppAnimator.animation == null) {
+                    mWin.mAppToken.allDrawn = false;
+                    mWin.mAppToken.deferClearAllDrawn = false;
+                } else {
+                    // Currently animating, persist current state of allDrawn until animation
+                    // is complete.
+                    mWin.mAppToken.deferClearAllDrawn = true;
+                }
+            }
+
+            mService.makeWindowFreezingScreenIfNeededLocked(mWin);
+
+            int flags = SurfaceControl.HIDDEN;
+            final WindowManager.LayoutParams attrs = mWin.mAttrs;
+
+            if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
+                flags |= SurfaceControl.SECURE;
+            }
+            if (DEBUG_VISIBILITY) Slog.v(
+                TAG, "Creating surface in session "
+                + mSession.mSurfaceSession + " window " + this
+                + " w=" + mWin.mCompatFrame.width()
+                + " h=" + mWin.mCompatFrame.height() + " format="
+                + attrs.format + " flags=" + flags);
+
+            int w = mWin.mCompatFrame.width();
+            int h = mWin.mCompatFrame.height();
+            if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
+                // for a scaled surface, we always want the requested
+                // size.
+                w = mWin.mRequestedWidth;
+                h = mWin.mRequestedHeight;
+            }
+
+            // Something is wrong and SurfaceFlinger will not like this,
+            // try to revert to sane values
+            if (w <= 0) w = 1;
+            if (h <= 0) h = 1;
+
+            mSurfaceShown = false;
+            mSurfaceLayer = 0;
+            mSurfaceAlpha = 0;
+            mSurfaceX = 0;
+            mSurfaceY = 0;
+            mSurfaceW = w;
+            mSurfaceH = h;
+            mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
+            try {
+                final boolean isHwAccelerated = (attrs.flags &
+                        WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
+                final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
+                if (!PixelFormat.formatHasAlpha(attrs.format)) {
+                    flags |= SurfaceControl.OPAQUE;
+                }
+                if (DEBUG_SURFACE_TRACE) {
+                    mSurfaceControl = new SurfaceTrace(
+                            mSession.mSurfaceSession,
+                            attrs.getTitle().toString(),
+                            w, h, format, flags);
+                } else {
+                    mSurfaceControl = new SurfaceControl(
+                        mSession.mSurfaceSession,
+                        attrs.getTitle().toString(),
+                        w, h, format, flags);
+                }
+                mWin.mHasSurface = true;
+                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
+                        "  CREATE SURFACE "
+                        + mSurfaceControl + " IN SESSION "
+                        + mSession.mSurfaceSession
+                        + ": pid=" + mSession.mPid + " format="
+                        + attrs.format + " flags=0x"
+                        + Integer.toHexString(flags)
+                        + " / " + this);
+            } catch (OutOfResourcesException e) {
+                mWin.mHasSurface = false;
+                Slog.w(TAG, "OutOfResourcesException creating surface");
+                mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
+                mDrawState = NO_SURFACE;
+                return null;
+            } catch (Exception e) {
+                mWin.mHasSurface = false;
+                Slog.e(TAG, "Exception creating surface", e);
+                mDrawState = NO_SURFACE;
+                return null;
+            }
+
+            if (WindowManagerService.localLOGV) Slog.v(
+                TAG, "Got surface: " + mSurfaceControl
+                + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
+                + ", animLayer=" + mAnimLayer);
+            if (SHOW_LIGHT_TRANSACTIONS) {
+                Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
+                WindowManagerService.logSurface(mWin, "CREATE pos=("
+                        + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
+                        + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
+                        + "), layer=" + mAnimLayer + " HIDE", null);
+            }
+            SurfaceControl.openTransaction();
+            try {
+                try {
+                    mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
+                    mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
+                    mSurfaceControl.setPosition(mSurfaceX, mSurfaceY);
+                    mSurfaceLayer = mAnimLayer;
+                    final DisplayContent displayContent = mWin.getDisplayContent();
+                    if (displayContent != null) {
+                        mSurfaceControl.setLayerStack(displayContent.getDisplay().getLayerStack());
+                    }
+                    mSurfaceControl.setLayer(mAnimLayer);
+                    mSurfaceControl.setAlpha(0);
+                    mSurfaceShown = false;
+                } catch (RuntimeException e) {
+                    Slog.w(TAG, "Error creating surface in " + w, e);
+                    mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
+                }
+                mLastHidden = true;
+            } finally {
+                SurfaceControl.closeTransaction();
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                        "<<< CLOSE TRANSACTION createSurfaceLocked");
+            }
+            if (WindowManagerService.localLOGV) Slog.v(
+                    TAG, "Created surface " + this);
+        }
+        return mSurfaceControl;
+    }
+
+    void destroySurfaceLocked() {
+        if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
+            mWin.mAppToken.startingDisplayed = false;
+        }
+
+        if (mSurfaceControl != null) {
+
+            int i = mWin.mChildWindows.size();
+            while (i > 0) {
+                i--;
+                WindowState c = mWin.mChildWindows.get(i);
+                c.mAttachedHidden = true;
+            }
+
+            try {
+                if (DEBUG_VISIBILITY) {
+                    RuntimeException e = null;
+                    if (!WindowManagerService.HIDE_STACK_CRAWLS) {
+                        e = new RuntimeException();
+                        e.fillInStackTrace();
+                    }
+                    Slog.w(TAG, "Window " + this + " destroying surface "
+                            + mSurfaceControl + ", session " + mSession, e);
+                }
+                if (mSurfaceDestroyDeferred) {
+                    if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) {
+                        if (mPendingDestroySurface != null) {
+                            if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
+                                RuntimeException e = null;
+                                if (!WindowManagerService.HIDE_STACK_CRAWLS) {
+                                    e = new RuntimeException();
+                                    e.fillInStackTrace();
+                                }
+                                WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
+                            }
+                            mPendingDestroySurface.destroy();
+                        }
+                        mPendingDestroySurface = mSurfaceControl;
+                    }
+                } else {
+                    if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
+                        RuntimeException e = null;
+                        if (!WindowManagerService.HIDE_STACK_CRAWLS) {
+                            e = new RuntimeException();
+                            e.fillInStackTrace();
+                        }
+                        WindowManagerService.logSurface(mWin, "DESTROY", e);
+                    }
+                    mSurfaceControl.destroy();
+                }
+                mAnimator.hideWallpapersLocked(mWin);
+            } catch (RuntimeException e) {
+                Slog.w(TAG, "Exception thrown when destroying Window " + this
+                    + " surface " + mSurfaceControl + " session " + mSession
+                    + ": " + e.toString());
+            }
+
+            mSurfaceShown = false;
+            mSurfaceControl = null;
+            mWin.mHasSurface = false;
+            mDrawState = NO_SURFACE;
+        }
+    }
+
+    void destroyDeferredSurfaceLocked() {
+        try {
+            if (mPendingDestroySurface != null) {
+                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
+                    RuntimeException e = null;
+                    if (!WindowManagerService.HIDE_STACK_CRAWLS) {
+                        e = new RuntimeException();
+                        e.fillInStackTrace();
+                    }
+                    WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
+                }
+                mPendingDestroySurface.destroy();
+                mAnimator.hideWallpapersLocked(mWin);
+            }
+        } catch (RuntimeException e) {
+            Slog.w(TAG, "Exception thrown when destroying Window "
+                    + this + " surface " + mPendingDestroySurface
+                    + " session " + mSession + ": " + e.toString());
+        }
+        mSurfaceDestroyDeferred = false;
+        mPendingDestroySurface = null;
+    }
+
+    void computeShownFrameLocked() {
+        final boolean selfTransformation = mHasLocalTransformation;
+        Transformation attachedTransformation =
+                (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
+                ? mAttachedWinAnimator.mTransformation : null;
+        Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
+                ? mAppAnimator.transformation : null;
+
+        // Wallpapers are animated based on the "real" window they
+        // are currently targeting.
+        final WindowState wallpaperTarget = mService.mWallpaperTarget;
+        if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
+            final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
+            if (wallpaperAnimator.mHasLocalTransformation &&
+                    wallpaperAnimator.mAnimation != null &&
+                    !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
+                attachedTransformation = wallpaperAnimator.mTransformation;
+                if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
+                    Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
+                }
+            }
+            final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
+                    null : wallpaperTarget.mAppToken.mAppAnimator;
+                if (wpAppAnimator != null && wpAppAnimator.hasTransformation
+                    && wpAppAnimator.animation != null
+                    && !wpAppAnimator.animation.getDetachWallpaper()) {
+                appTransformation = wpAppAnimator.transformation;
+                if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
+                    Slog.v(TAG, "WP target app xform: " + appTransformation);
+                }
+            }
+        }
+
+        final int displayId = mWin.getDisplayId();
+        final ScreenRotationAnimation screenRotationAnimation =
+                mAnimator.getScreenRotationAnimationLocked(displayId);
+        final boolean screenAnimation =
+                screenRotationAnimation != null && screenRotationAnimation.isAnimating();
+        if (selfTransformation || attachedTransformation != null
+                || appTransformation != null || screenAnimation) {
+            // cache often used attributes locally
+            final Rect frame = mWin.mFrame;
+            final float tmpFloats[] = mService.mTmpFloats;
+            final Matrix tmpMatrix = mWin.mTmpMatrix;
+
+            // Compute the desired transformation.
+            if (screenAnimation && screenRotationAnimation.isRotating()) {
+                // If we are doing a screen animation, the global rotation
+                // applied to windows can result in windows that are carefully
+                // aligned with each other to slightly separate, allowing you
+                // to see what is behind them.  An unsightly mess.  This...
+                // thing...  magically makes it call good: scale each window
+                // slightly (two pixels larger in each dimension, from the
+                // window's center).
+                final float w = frame.width();
+                final float h = frame.height();
+                if (w>=1 && h>=1) {
+                    tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
+                } else {
+                    tmpMatrix.reset();
+                }
+            } else {
+                tmpMatrix.reset();
+            }
+            tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
+            if (selfTransformation) {
+                tmpMatrix.postConcat(mTransformation.getMatrix());
+            }
+            tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
+            if (attachedTransformation != null) {
+                tmpMatrix.postConcat(attachedTransformation.getMatrix());
+            }
+            if (appTransformation != null) {
+                tmpMatrix.postConcat(appTransformation.getMatrix());
+            }
+            if (mAnimator.mUniverseBackground != null) {
+                tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
+            }
+            if (screenAnimation) {
+                tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
+            }
+            //TODO (multidisplay): Magnification is supported only for the default display.
+            if (mService.mDisplayMagnifier != null && displayId == Display.DEFAULT_DISPLAY) {
+                MagnificationSpec spec = mService.mDisplayMagnifier
+                        .getMagnificationSpecForWindowLocked(mWin);
+                if (spec != null && !spec.isNop()) {
+                    tmpMatrix.postScale(spec.scale, spec.scale);
+                    tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
+                }
+            }
+
+            // "convert" it into SurfaceFlinger's format
+            // (a 2x2 matrix + an offset)
+            // Here we must not transform the position of the surface
+            // since it is already included in the transformation.
+            //Slog.i(TAG, "Transform: " + matrix);
+
+            mHaveMatrix = true;
+            tmpMatrix.getValues(tmpFloats);
+            mDsDx = tmpFloats[Matrix.MSCALE_X];
+            mDtDx = tmpFloats[Matrix.MSKEW_Y];
+            mDsDy = tmpFloats[Matrix.MSKEW_X];
+            mDtDy = tmpFloats[Matrix.MSCALE_Y];
+            float x = tmpFloats[Matrix.MTRANS_X];
+            float y = tmpFloats[Matrix.MTRANS_Y];
+            int w = frame.width();
+            int h = frame.height();
+            mWin.mShownFrame.set(x, y, x+w, y+h);
+
+            // Now set the alpha...  but because our current hardware
+            // can't do alpha transformation on a non-opaque surface,
+            // turn it off if we are running an animation that is also
+            // transforming since it is more important to have that
+            // animation be smooth.
+            mShownAlpha = mAlpha;
+            if (!mService.mLimitedAlphaCompositing
+                    || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
+                    || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
+                            && x == frame.left && y == frame.top))) {
+                //Slog.i(TAG, "Applying alpha transform");
+                if (selfTransformation) {
+                    mShownAlpha *= mTransformation.getAlpha();
+                }
+                if (attachedTransformation != null) {
+                    mShownAlpha *= attachedTransformation.getAlpha();
+                }
+                if (appTransformation != null) {
+                    mShownAlpha *= appTransformation.getAlpha();
+                }
+                if (mAnimator.mUniverseBackground != null) {
+                    mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
+                }
+                if (screenAnimation) {
+                    mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
+                }
+            } else {
+                //Slog.i(TAG, "Not applying alpha transform");
+            }
+
+            if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
+                    && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
+                    TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
+                    + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
+                    + " attached=" + (attachedTransformation == null ?
+                            "null" : attachedTransformation.getAlpha())
+                    + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
+                    + " screen=" + (screenAnimation ?
+                            screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
+            return;
+        } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) {
+            return;
+        }
+
+        if (WindowManagerService.localLOGV) Slog.v(
+                TAG, "computeShownFrameLocked: " + this +
+                " not attached, mAlpha=" + mAlpha);
+
+        final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null
+                && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
+                && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer);
+        MagnificationSpec spec = null;
+        //TODO (multidisplay): Magnification is supported only for the default display.
+        if (mService.mDisplayMagnifier != null && displayId == Display.DEFAULT_DISPLAY) {
+            spec = mService.mDisplayMagnifier.getMagnificationSpecForWindowLocked(mWin);
+        }
+        if (applyUniverseTransformation || spec != null) {
+            final Rect frame = mWin.mFrame;
+            final float tmpFloats[] = mService.mTmpFloats;
+            final Matrix tmpMatrix = mWin.mTmpMatrix;
+
+            tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
+            tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
+
+            if (applyUniverseTransformation) {
+                tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
+            }
+
+            if (spec != null && !spec.isNop()) {
+                tmpMatrix.postScale(spec.scale, spec.scale);
+                tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
+            }
+
+            tmpMatrix.getValues(tmpFloats);
+
+            mHaveMatrix = true;
+            mDsDx = tmpFloats[Matrix.MSCALE_X];
+            mDtDx = tmpFloats[Matrix.MSKEW_Y];
+            mDsDy = tmpFloats[Matrix.MSKEW_X];
+            mDtDy = tmpFloats[Matrix.MSCALE_Y];
+            float x = tmpFloats[Matrix.MTRANS_X];
+            float y = tmpFloats[Matrix.MTRANS_Y];
+            int w = frame.width();
+            int h = frame.height();
+            mWin.mShownFrame.set(x, y, x + w, y + h);
+
+            mShownAlpha = mAlpha;
+            if (applyUniverseTransformation) {
+                mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
+            }
+        } else {
+            mWin.mShownFrame.set(mWin.mFrame);
+            if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
+                mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
+            }
+            mShownAlpha = mAlpha;
+            mHaveMatrix = false;
+            mDsDx = mWin.mGlobalScale;
+            mDtDx = 0;
+            mDsDy = 0;
+            mDtDy = mWin.mGlobalScale;
+        }
+    }
+
+    void applyDecorRect(final Rect decorRect) {
+        final WindowState w = mWin;
+        // Compute the offset of the window in relation to the decor rect.
+        final int offX = w.mXOffset + w.mFrame.left;
+        final int offY = w.mYOffset + w.mFrame.top;
+        // Initialize the decor rect to the entire frame.
+        w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
+        // Intersect with the decor rect, offsetted by window position.
+        w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
+                decorRect.right-offX, decorRect.bottom-offY);
+        // If size compatibility is being applied to the window, the
+        // surface is scaled relative to the screen.  Also apply this
+        // scaling to the crop rect.  We aren't using the standard rect
+        // scale function because we want to round things to make the crop
+        // always round to a larger rect to ensure we don't crop too
+        // much and hide part of the window that should be seen.
+        if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
+            final float scale = w.mInvGlobalScale;
+            w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
+            w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
+            w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
+            w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
+        }
+    }
+
+    void updateSurfaceWindowCrop(final boolean recoveringMemory) {
+        final WindowState w = mWin;
+        final DisplayContent displayContent = w.getDisplayContent();
+        if (displayContent == null) {
+            return;
+        }
+        DisplayInfo displayInfo = displayContent.getDisplayInfo();
+
+        // Need to recompute a new system decor rect each time.
+        if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
+            // Currently can't do this cropping for scaled windows.  We'll
+            // just keep the crop rect the same as the source surface.
+            w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
+        } else if (!w.isDefaultDisplay()) {
+            // On a different display there is no system decor.  Crop the window
+            // by the screen boundaries.
+            w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
+            w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
+                    displayInfo.logicalWidth - w.mCompatFrame.left,
+                    displayInfo.logicalHeight - w.mCompatFrame.top);
+        } else if (w.mLayer >= mService.mSystemDecorLayer) {
+            // Above the decor layer is easy, just use the entire window.
+            // Unless we have a universe background...  in which case all the
+            // windows need to be cropped by the screen, so they don't cover
+            // the universe background.
+            if (mAnimator.mUniverseBackground == null) {
+                w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
+                        w.mCompatFrame.height());
+            } else {
+                applyDecorRect(mService.mScreenRect);
+            }
+        } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
+                || w.mDecorFrame.isEmpty()) {
+            // The universe background isn't cropped, nor windows without policy decor.
+            w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
+                    w.mCompatFrame.height());
+        } else {
+            // Crop to the system decor specified by policy.
+            applyDecorRect(w.mDecorFrame);
+        }
+
+        if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
+            w.mLastSystemDecorRect.set(w.mSystemDecorRect);
+            try {
+                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
+                        "CROP " + w.mSystemDecorRect.toShortString(), null);
+                mSurfaceControl.setWindowCrop(w.mSystemDecorRect);
+            } catch (RuntimeException e) {
+                Slog.w(TAG, "Error setting crop surface of " + w
+                        + " crop=" + w.mSystemDecorRect.toShortString(), e);
+                if (!recoveringMemory) {
+                    mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
+                }
+            }
+        }
+    }
+
+    void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
+        final WindowState w = mWin;
+        int width, height;
+        if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
+            // for a scaled surface, we just want to use
+            // the requested size.
+            width  = w.mRequestedWidth;
+            height = w.mRequestedHeight;
+        } else {
+            width = w.mCompatFrame.width();
+            height = w.mCompatFrame.height();
+        }
+
+        if (width < 1) {
+            width = 1;
+        }
+        if (height < 1) {
+            height = 1;
+        }
+        final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
+        if (surfaceResized) {
+            mSurfaceW = width;
+            mSurfaceH = height;
+        }
+
+        final float left = w.mShownFrame.left;
+        final float top = w.mShownFrame.top;
+        if (mSurfaceX != left || mSurfaceY != top) {
+            try {
+                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
+                        "POS " + left + ", " + top, null);
+                mSurfaceX = left;
+                mSurfaceY = top;
+                mSurfaceControl.setPosition(left, top);
+            } catch (RuntimeException e) {
+                Slog.w(TAG, "Error positioning surface of " + w
+                        + " pos=(" + left
+                        + "," + top + ")", e);
+                if (!recoveringMemory) {
+                    mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
+                }
+            }
+        }
+
+        if (surfaceResized) {
+            try {
+                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
+                        "SIZE " + width + "x" + height, null);
+                mSurfaceResized = true;
+                mSurfaceControl.setSize(width, height);
+                mAnimator.setPendingLayoutChanges(w.getDisplayId(),
+                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
+                if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
+                    w.getStack().startDimmingIfNeeded(this);
+                }
+            } catch (RuntimeException e) {
+                // If something goes wrong with the surface (such
+                // as running out of memory), don't take down the
+                // entire system.
+                Slog.e(TAG, "Error resizing surface of " + w
+                        + " size=(" + width + "x" + height + ")", e);
+                if (!recoveringMemory) {
+                    mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
+                }
+            }
+        }
+
+        updateSurfaceWindowCrop(recoveringMemory);
+    }
+
+    public void prepareSurfaceLocked(final boolean recoveringMemory) {
+        final WindowState w = mWin;
+        if (mSurfaceControl == null) {
+            if (w.mOrientationChanging) {
+                if (DEBUG_ORIENTATION) {
+                    Slog.v(TAG, "Orientation change skips hidden " + w);
+                }
+                w.mOrientationChanging = false;
+            }
+            return;
+        }
+
+        boolean displayed = false;
+
+        computeShownFrameLocked();
+
+        setSurfaceBoundariesLocked(recoveringMemory);
+
+        if (mIsWallpaper && !mWin.mWallpaperVisible) {
+            // Wallpaper is no longer visible and there is no wp target => hide it.
+            hide();
+        } else if (w.mAttachedHidden || !w.isOnScreen()) {
+            hide();
+            mAnimator.hideWallpapersLocked(w);
+
+            // If we are waiting for this window to handle an
+            // orientation change, well, it is hidden, so
+            // doesn't really matter.  Note that this does
+            // introduce a potential glitch if the window
+            // becomes unhidden before it has drawn for the
+            // new orientation.
+            if (w.mOrientationChanging) {
+                w.mOrientationChanging = false;
+                if (DEBUG_ORIENTATION) Slog.v(TAG,
+                        "Orientation change skips hidden " + w);
+            }
+        } else if (mLastLayer != mAnimLayer
+                || mLastAlpha != mShownAlpha
+                || mLastDsDx != mDsDx
+                || mLastDtDx != mDtDx
+                || mLastDsDy != mDsDy
+                || mLastDtDy != mDtDy
+                || w.mLastHScale != w.mHScale
+                || w.mLastVScale != w.mVScale
+                || mLastHidden) {
+            displayed = true;
+            mLastAlpha = mShownAlpha;
+            mLastLayer = mAnimLayer;
+            mLastDsDx = mDsDx;
+            mLastDtDx = mDtDx;
+            mLastDsDy = mDsDy;
+            mLastDtDy = mDtDy;
+            w.mLastHScale = w.mHScale;
+            w.mLastVScale = w.mVScale;
+            if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
+                    "alpha=" + mShownAlpha + " layer=" + mAnimLayer
+                    + " matrix=[" + (mDsDx*w.mHScale)
+                    + "," + (mDtDx*w.mVScale)
+                    + "][" + (mDsDy*w.mHScale)
+                    + "," + (mDtDy*w.mVScale) + "]", null);
+            if (mSurfaceControl != null) {
+                try {
+                    mSurfaceAlpha = mShownAlpha;
+                    mSurfaceControl.setAlpha(mShownAlpha);
+                    mSurfaceLayer = mAnimLayer;
+                    mSurfaceControl.setLayer(mAnimLayer);
+                    mSurfaceControl.setMatrix(
+                        mDsDx*w.mHScale, mDtDx*w.mVScale,
+                        mDsDy*w.mHScale, mDtDy*w.mVScale);
+
+                    if (mLastHidden && mDrawState == HAS_DRAWN) {
+                        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
+                                "SHOW (performLayout)", null);
+                        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
+                                + " during relayout");
+                        if (showSurfaceRobustlyLocked()) {
+                            mLastHidden = false;
+                            if (mIsWallpaper) {
+                                mService.dispatchWallpaperVisibility(w, true);
+                            }
+                            // This draw means the difference between unique content and mirroring.
+                            // Run another pass through performLayout to set mHasContent in the
+                            // LogicalDisplay.
+                            mAnimator.setPendingLayoutChanges(w.getDisplayId(),
+                                    WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
+                        } else {
+                            w.mOrientationChanging = false;
+                        }
+                    }
+                    if (mSurfaceControl != null) {
+                        w.mToken.hasVisible = true;
+                    }
+                } catch (RuntimeException e) {
+                    Slog.w(TAG, "Error updating surface in " + w, e);
+                    if (!recoveringMemory) {
+                        mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
+                    }
+                }
+            }
+        } else {
+            if (DEBUG_ANIM && isAnimating()) {
+                Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
+            }
+            displayed = true;
+        }
+
+        if (displayed) {
+            if (w.mOrientationChanging) {
+                if (!w.isDrawnLw()) {
+                    mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
+                    mAnimator.mLastWindowFreezeSource = w;
+                    if (DEBUG_ORIENTATION) Slog.v(TAG,
+                            "Orientation continue waiting for draw in " + w);
+                } else {
+                    w.mOrientationChanging = false;
+                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
+                }
+            }
+            w.mToken.hasVisible = true;
+        }
+    }
+
+    void setTransparentRegionHintLocked(final Region region) {
+        if (mSurfaceControl == null) {
+            Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
+            return;
+        }
+        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setTransparentRegion");
+        SurfaceControl.openTransaction();
+        try {
+            if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
+                    "transparentRegionHint=" + region, null);
+            mSurfaceControl.setTransparentRegionHint(region);
+        } finally {
+            SurfaceControl.closeTransaction();
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                    "<<< CLOSE TRANSACTION setTransparentRegion");
+        }
+    }
+
+    void setWallpaperOffset(RectF shownFrame) {
+        final int left = (int) shownFrame.left;
+        final int top = (int) shownFrame.top;
+        if (mSurfaceX != left || mSurfaceY != top) {
+            mSurfaceX = left;
+            mSurfaceY = top;
+            if (mAnimating) {
+                // If this window (or its app token) is animating, then the position
+                // of the surface will be re-computed on the next animation frame.
+                // We can't poke it directly here because it depends on whatever
+                // transformation is being applied by the animation.
+                return;
+            }
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
+            SurfaceControl.openTransaction();
+            try {
+                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
+                        "POS " + left + ", " + top, null);
+                mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
+                updateSurfaceWindowCrop(false);
+            } catch (RuntimeException e) {
+                Slog.w(TAG, "Error positioning surface of " + mWin
+                        + " pos=(" + left + "," + top + ")", e);
+            } finally {
+                SurfaceControl.closeTransaction();
+                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
+                        "<<< CLOSE TRANSACTION setWallpaperOffset");
+            }
+        }
+    }
+
+    void setOpaque(boolean isOpaque) {
+        if (mSurfaceControl == null) {
+            return;
+        }
+        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setOpaque");
+        SurfaceControl.openTransaction();
+        try {
+            if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin, "isOpaque=" + isOpaque,
+                    null);
+            mSurfaceControl.setOpaque(isOpaque);
+        } finally {
+            SurfaceControl.closeTransaction();
+            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION setOpaque");
+        }
+    }
+
+    // This must be called while inside a transaction.
+    boolean performShowLocked() {
+        if (mWin.isHiddenFromUserLocked()) {
+            Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
+                    + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUid);
+            return false;
+        }
+        if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
+                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
+            RuntimeException e = null;
+            if (!WindowManagerService.HIDE_STACK_CRAWLS) {
+                e = new RuntimeException();
+                e.fillInStackTrace();
+            }
+            Slog.v(TAG, "performShow on " + this
+                    + ": mDrawState=" + mDrawState + " readyForDisplay="
+                    + mWin.isReadyForDisplayIgnoringKeyguard()
+                    + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
+                    + " during animation: policyVis=" + mWin.mPolicyVisibility
+                    + " attHidden=" + mWin.mAttachedHidden
+                    + " tok.hiddenRequested="
+                    + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
+                    + " tok.hidden="
+                    + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
+                    + " animating=" + mAnimating
+                    + " tok animating="
+                    + (mAppAnimator != null ? mAppAnimator.animating : false), e);
+        }
+        if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
+            if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
+                WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
+            if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
+                    mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
+                Slog.v(TAG, "Showing " + this
+                        + " during animation: policyVis=" + mWin.mPolicyVisibility
+                        + " attHidden=" + mWin.mAttachedHidden
+                        + " tok.hiddenRequested="
+                        + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
+                        + " tok.hidden="
+                        + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
+                        + " animating=" + mAnimating
+                        + " tok animating="
+                        + (mAppAnimator != null ? mAppAnimator.animating : false));
+            }
+
+            mService.enableScreenIfNeededLocked();
+
+            applyEnterAnimationLocked();
+
+            // Force the show in the next prepareSurfaceLocked() call.
+            mLastAlpha = -1;
+            if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
+                Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
+            mDrawState = HAS_DRAWN;
+            mService.scheduleAnimationLocked();
+
+            int i = mWin.mChildWindows.size();
+            while (i > 0) {
+                i--;
+                WindowState c = mWin.mChildWindows.get(i);
+                if (c.mAttachedHidden) {
+                    c.mAttachedHidden = false;
+                    if (c.mWinAnimator.mSurfaceControl != null) {
+                        c.mWinAnimator.performShowLocked();
+                        // It hadn't been shown, which means layout not
+                        // performed on it, so now we want to make sure to
+                        // do a layout.  If called from within the transaction
+                        // loop, this will cause it to restart with a new
+                        // layout.
+                        final DisplayContent displayContent = c.getDisplayContent();
+                        if (displayContent != null) {
+                            displayContent.layoutNeeded = true;
+                        }
+                    }
+                }
+            }
+
+            if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
+                    && mWin.mAppToken != null) {
+                mWin.mAppToken.firstWindowDrawn = true;
+
+                if (mWin.mAppToken.startingData != null) {
+                    if (WindowManagerService.DEBUG_STARTING_WINDOW ||
+                            WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
+                            "Finish starting " + mWin.mToken
+                            + ": first real window is shown, no animation");
+                    // If this initial window is animating, stop it -- we
+                    // will do an animation to reveal it from behind the
+                    // starting window, so there is no need for it to also
+                    // be doing its own stuff.
+                    clearAnimation();
+                    mService.mFinishedStarting.add(mWin.mAppToken);
+                    mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
+                }
+                mWin.mAppToken.updateReportedVisibilityLocked();
+            }
+
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * Have the surface flinger show a surface, robustly dealing with
+     * error conditions.  In particular, if there is not enough memory
+     * to show the surface, then we will try to get rid of other surfaces
+     * in order to succeed.
+     *
+     * @return Returns true if the surface was successfully shown.
+     */
+    boolean showSurfaceRobustlyLocked() {
+        try {
+            if (mSurfaceControl != null) {
+                mSurfaceShown = true;
+                mSurfaceControl.show();
+                if (mWin.mTurnOnScreen) {
+                    if (DEBUG_VISIBILITY) Slog.v(TAG,
+                            "Show surface turning screen on: " + mWin);
+                    mWin.mTurnOnScreen = false;
+                    mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
+                }
+            }
+            return true;
+        } catch (RuntimeException e) {
+            Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e);
+        }
+
+        mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
+
+        return false;
+    }
+
+    void applyEnterAnimationLocked() {
+        final int transit;
+        if (mEnterAnimationPending) {
+            mEnterAnimationPending = false;
+            transit = WindowManagerPolicy.TRANSIT_ENTER;
+        } else {
+            transit = WindowManagerPolicy.TRANSIT_SHOW;
+        }
+        applyAnimationLocked(transit, true);
+        //TODO (multidisplay): Magnification is supported only for the default display.
+        if (mService.mDisplayMagnifier != null
+                && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
+            mService.mDisplayMagnifier.onWindowTransitionLocked(mWin, transit);
+        }
+    }
+
+    /**
+     * Choose the correct animation and set it to the passed WindowState.
+     * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
+     *      then the animation will be app_starting_exit. Any other value loads the animation from
+     *      the switch statement below.
+     * @param isEntrance The animation type the last time this was called. Used to keep from
+     *      loading the same animation twice.
+     * @return true if an animation has been loaded.
+     */
+    boolean applyAnimationLocked(int transit, boolean isEntrance) {
+        if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
+            // If we are trying to apply an animation, but already running
+            // an animation of the same type, then just leave that one alone.
+            return true;
+        }
+
+        // Only apply an animation if the display isn't frozen.  If it is
+        // frozen, there is no reason to animate and it can cause strange
+        // artifacts when we unfreeze the display if some different animation
+        // is running.
+        if (mService.okToDisplay()) {
+            int anim = mPolicy.selectAnimationLw(mWin, transit);
+            int attr = -1;
+            Animation a = null;
+            if (anim != 0) {
+                a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
+            } else {
+                switch (transit) {
+                    case WindowManagerPolicy.TRANSIT_ENTER:
+                        attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
+                        break;
+                    case WindowManagerPolicy.TRANSIT_EXIT:
+                        attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
+                        break;
+                    case WindowManagerPolicy.TRANSIT_SHOW:
+                        attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
+                        break;
+                    case WindowManagerPolicy.TRANSIT_HIDE:
+                        attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
+                        break;
+                }
+                if (attr >= 0) {
+                    a = mService.mAppTransition.loadAnimation(mWin.mAttrs, attr);
+                }
+            }
+            if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
+                    "applyAnimation: win=" + this
+                    + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
+                    + " a=" + a
+                    + " transit=" + transit
+                    + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
+            if (a != null) {
+                if (WindowManagerService.DEBUG_ANIM) {
+                    RuntimeException e = null;
+                    if (!WindowManagerService.HIDE_STACK_CRAWLS) {
+                        e = new RuntimeException();
+                        e.fillInStackTrace();
+                    }
+                    Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
+                }
+                setAnimation(a);
+                mAnimationIsEntrance = isEntrance;
+            }
+        } else {
+            clearAnimation();
+        }
+
+        return mAnimation != null;
+    }
+
+    public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
+        if (mAnimating || mLocalAnimating || mAnimationIsEntrance
+                || mAnimation != null) {
+            pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
+                    pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
+                    pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
+                    pw.print(" mAnimation="); pw.println(mAnimation);
+        }
+        if (mHasTransformation || mHasLocalTransformation) {
+            pw.print(prefix); pw.print("XForm: has=");
+                    pw.print(mHasTransformation);
+                    pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
+                    pw.print(" "); mTransformation.printShortString(pw);
+                    pw.println();
+        }
+        if (mSurfaceControl != null) {
+            if (dumpAll) {
+                pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
+                pw.print(prefix); pw.print("mDrawState=");
+                pw.print(drawStateToString(mDrawState));
+                pw.print(" mLastHidden="); pw.println(mLastHidden);
+            }
+            pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
+                    pw.print(" layer="); pw.print(mSurfaceLayer);
+                    pw.print(" alpha="); pw.print(mSurfaceAlpha);
+                    pw.print(" rect=("); pw.print(mSurfaceX);
+                    pw.print(","); pw.print(mSurfaceY);
+                    pw.print(") "); pw.print(mSurfaceW);
+                    pw.print(" x "); pw.println(mSurfaceH);
+        }
+        if (mPendingDestroySurface != null) {
+            pw.print(prefix); pw.print("mPendingDestroySurface=");
+                    pw.println(mPendingDestroySurface);
+        }
+        if (mSurfaceResized || mSurfaceDestroyDeferred) {
+            pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
+                    pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
+        }
+        if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
+            pw.print(prefix); pw.print("mUniverseTransform=");
+                    mUniverseTransform.printShortString(pw);
+                    pw.println();
+        }
+        if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
+            pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
+                    pw.print(" mAlpha="); pw.print(mAlpha);
+                    pw.print(" mLastAlpha="); pw.println(mLastAlpha);
+        }
+        if (mHaveMatrix || mWin.mGlobalScale != 1) {
+            pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
+                    pw.print(" mDsDx="); pw.print(mDsDx);
+                    pw.print(" mDtDx="); pw.print(mDtDx);
+                    pw.print(" mDsDy="); pw.print(mDsDy);
+                    pw.print(" mDtDy="); pw.println(mDtDy);
+        }
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer sb = new StringBuffer("WindowStateAnimator{");
+        sb.append(Integer.toHexString(System.identityHashCode(this)));
+        sb.append(' ');
+        sb.append(mWin.mAttrs.getTitle());
+        sb.append('}');
+        return sb.toString();
+    }
+}
diff --git a/services/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
similarity index 100%
rename from services/java/com/android/server/wm/WindowToken.java
rename to services/core/java/com/android/server/wm/WindowToken.java
diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk
new file mode 100644
index 0000000..d1cfff4
--- /dev/null
+++ b/services/core/jni/Android.mk
@@ -0,0 +1,57 @@
+# This file is included by the top level services directory to collect source
+# files
+LOCAL_REL_DIR := core/jni
+
+LOCAL_SRC_FILES += \
+    $(LOCAL_REL_DIR)/com_android_server_AlarmManagerService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_AssetAtlasService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_ConsumerIrService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_dreams_McuHal.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_input_InputApplicationHandle.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_input_InputManagerService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_input_InputWindowHandle.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_lights_LightsService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_power_PowerManagerService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_SerialService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_SystemServer.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_UsbDeviceManager.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_UsbHostManager.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_VibratorService.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_location_GpsLocationProvider.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_location_FlpHardwareProvider.cpp \
+    $(LOCAL_REL_DIR)/com_android_server_connectivity_Vpn.cpp \
+    $(LOCAL_REL_DIR)/onload.cpp
+
+LOCAL_C_INCLUDES += \
+    $(JNI_H_INCLUDE) \
+    frameworks/base/services \
+    frameworks/base/libs \
+    frameworks/base/core/jni \
+    frameworks/native/services \
+    external/skia/include/core \
+    libcore/include \
+    libcore/include/libsuspend \
+	$(call include-path-for, libhardware)/hardware \
+	$(call include-path-for, libhardware_legacy)/hardware_legacy \
+
+LOCAL_SHARED_LIBRARIES += \
+    libandroid_runtime \
+    libandroidfw \
+    libbinder \
+    libcutils \
+    liblog \
+    libhardware \
+    libhardware_legacy \
+    libnativehelper \
+    libutils \
+    libui \
+    libinput \
+    libinputservice \
+    libsensorservice \
+    libskia \
+    libgui \
+    libusbhost \
+    libsuspend \
+    libEGL \
+    libGLESv2
+
diff --git a/services/core/jni/com_android_server_AlarmManagerService.cpp b/services/core/jni/com_android_server_AlarmManagerService.cpp
new file mode 100644
index 0000000..342515b
--- /dev/null
+++ b/services/core/jni/com_android_server_AlarmManagerService.cpp
@@ -0,0 +1,321 @@
+/* //device/libs/android_runtime/android_server_AlarmManagerService.cpp
+**
+** Copyright 2006, 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.
+*/
+
+#define LOG_TAG "AlarmManagerService"
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include <utils/Log.h>
+#include <utils/misc.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <sys/timerfd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <linux/ioctl.h>
+#include <linux/android_alarm.h>
+
+namespace android {
+
+static const size_t N_ANDROID_TIMERFDS = ANDROID_ALARM_TYPE_COUNT + 1;
+static const clockid_t android_alarm_to_clockid[N_ANDROID_TIMERFDS] = {
+    CLOCK_REALTIME_ALARM,
+    CLOCK_REALTIME,
+    CLOCK_BOOTTIME_ALARM,
+    CLOCK_BOOTTIME,
+    CLOCK_MONOTONIC,
+    CLOCK_REALTIME,
+};
+/* to match the legacy alarm driver implementation, we need an extra
+   CLOCK_REALTIME fd which exists specifically to be canceled on RTC changes */
+
+class AlarmImpl
+{
+public:
+    AlarmImpl(int *fds, size_t n_fds);
+    virtual ~AlarmImpl();
+
+    virtual int set(int type, struct timespec *ts) = 0;
+    virtual int waitForAlarm() = 0;
+
+protected:
+    int *fds;
+    size_t n_fds;
+};
+
+class AlarmImplAlarmDriver : public AlarmImpl
+{
+public:
+    AlarmImplAlarmDriver(int fd) : AlarmImpl(&fd, 1) { }
+
+    int set(int type, struct timespec *ts);
+    int waitForAlarm();
+};
+
+class AlarmImplTimerFd : public AlarmImpl
+{
+public:
+    AlarmImplTimerFd(int fds[N_ANDROID_TIMERFDS], int epollfd) :
+        AlarmImpl(fds, N_ANDROID_TIMERFDS), epollfd(epollfd) { }
+    ~AlarmImplTimerFd();
+
+    int set(int type, struct timespec *ts);
+    int waitForAlarm();
+
+private:
+    int epollfd;
+};
+
+AlarmImpl::AlarmImpl(int *fds_, size_t n_fds) : fds(new int[n_fds]),
+        n_fds(n_fds)
+{
+    memcpy(fds, fds_, n_fds * sizeof(fds[0]));
+}
+
+AlarmImpl::~AlarmImpl()
+{
+    for (size_t i = 0; i < n_fds; i++) {
+        close(fds[i]);
+    }
+    delete [] fds;
+}
+
+int AlarmImplAlarmDriver::set(int type, struct timespec *ts)
+{
+    return ioctl(fds[0], ANDROID_ALARM_SET(type), ts);
+}
+
+int AlarmImplAlarmDriver::waitForAlarm()
+{
+    return ioctl(fds[0], ANDROID_ALARM_WAIT);
+}
+
+AlarmImplTimerFd::~AlarmImplTimerFd()
+{
+    for (size_t i = 0; i < N_ANDROID_TIMERFDS; i++) {
+        epoll_ctl(epollfd, EPOLL_CTL_DEL, fds[i], NULL);
+    }
+    close(epollfd);
+}
+
+int AlarmImplTimerFd::set(int type, struct timespec *ts)
+{
+    if (type > ANDROID_ALARM_TYPE_COUNT) {
+        errno = EINVAL;
+        return -1;
+    }
+
+    if (!ts->tv_nsec && !ts->tv_sec) {
+        ts->tv_nsec = 1;
+    }
+    /* timerfd interprets 0 = disarm, so replace with a practically
+       equivalent deadline of 1 ns */
+
+    struct itimerspec spec;
+    memset(&spec, 0, sizeof(spec));
+    memcpy(&spec.it_value, ts, sizeof(spec.it_value));
+
+    return timerfd_settime(fds[type], TFD_TIMER_ABSTIME, &spec, NULL);
+}
+
+int AlarmImplTimerFd::waitForAlarm()
+{
+    epoll_event events[N_ANDROID_TIMERFDS];
+
+    int nevents = epoll_wait(epollfd, events, N_ANDROID_TIMERFDS, -1);
+    if (nevents < 0) {
+        return nevents;
+    }
+
+    int result = 0;
+    for (int i = 0; i < nevents; i++) {
+        uint32_t alarm_idx = events[i].data.u32;
+        uint64_t unused;
+        ssize_t err = read(fds[alarm_idx], &unused, sizeof(unused));
+        if (err < 0) {
+            if (alarm_idx == ANDROID_ALARM_TYPE_COUNT && errno == ECANCELED) {
+                result |= ANDROID_ALARM_TIME_CHANGE_MASK;
+            } else {
+                return err;
+            }
+        } else {
+            result |= (1 << alarm_idx);
+        }
+    }
+
+    return result;
+}
+
+static jint android_server_AlarmManagerService_setKernelTimezone(JNIEnv*, jobject, jlong, jint minswest)
+{
+    struct timezone tz;
+
+    tz.tz_minuteswest = minswest;
+    tz.tz_dsttime = 0;
+
+    int result = settimeofday(NULL, &tz);
+    if (result < 0) {
+        ALOGE("Unable to set kernel timezone to %d: %s\n", minswest, strerror(errno));
+        return -1;
+    } else {
+        ALOGD("Kernel timezone updated to %d minutes west of GMT\n", minswest);
+    }
+
+    return 0;
+}
+
+static jlong init_alarm_driver()
+{
+    int fd = open("/dev/alarm", O_RDWR);
+    if (fd < 0) {
+        ALOGV("opening alarm driver failed: %s", strerror(errno));
+        return 0;
+    }
+
+    AlarmImpl *ret = new AlarmImplAlarmDriver(fd);
+    return reinterpret_cast<jlong>(ret);
+}
+
+static jlong init_timerfd()
+{
+    int epollfd;
+    int fds[N_ANDROID_TIMERFDS];
+
+    epollfd = epoll_create(N_ANDROID_TIMERFDS);
+    if (epollfd < 0) {
+        ALOGV("epoll_create(%u) failed: %s", N_ANDROID_TIMERFDS,
+                strerror(errno));
+        return 0;
+    }
+
+    for (size_t i = 0; i < N_ANDROID_TIMERFDS; i++) {
+        fds[i] = timerfd_create(android_alarm_to_clockid[i], 0);
+        if (fds[i] < 0) {
+            ALOGV("timerfd_create(%u) failed: %s",  android_alarm_to_clockid[i],
+                    strerror(errno));
+            close(epollfd);
+            for (size_t j = 0; j < i; j++) {
+                close(fds[j]);
+            }
+            return 0;
+        }
+    }
+
+    AlarmImpl *ret = new AlarmImplTimerFd(fds, epollfd);
+
+    for (size_t i = 0; i < N_ANDROID_TIMERFDS; i++) {
+        epoll_event event;
+        event.events = EPOLLIN | EPOLLWAKEUP;
+        event.data.u32 = i;
+
+        int err = epoll_ctl(epollfd, EPOLL_CTL_ADD, fds[i], &event);
+        if (err < 0) {
+            ALOGV("epoll_ctl(EPOLL_CTL_ADD) failed: %s", strerror(errno));
+            delete ret;
+            return 0;
+        }
+    }
+
+    struct itimerspec spec;
+    memset(&spec, 0, sizeof(spec));
+    /* 0 = disarmed; the timerfd doesn't need to be armed to get
+       RTC change notifications, just set up as cancelable */
+
+    int err = timerfd_settime(fds[ANDROID_ALARM_TYPE_COUNT],
+            TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &spec, NULL);
+    if (err < 0) {
+        ALOGV("timerfd_settime() failed: %s", strerror(errno));
+        delete ret;
+        return 0;
+    }
+
+    return reinterpret_cast<jlong>(ret);
+}
+
+static jlong android_server_AlarmManagerService_init(JNIEnv*, jobject)
+{
+    jlong ret = init_alarm_driver();
+    if (ret) {
+        return ret;
+    }
+
+    return init_timerfd();
+}
+
+static void android_server_AlarmManagerService_close(JNIEnv*, jobject, jlong nativeData)
+{
+    AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
+    delete impl;
+}
+
+static void android_server_AlarmManagerService_set(JNIEnv*, jobject, jlong nativeData, jint type, jlong seconds, jlong nanoseconds)
+{
+    AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
+    struct timespec ts;
+    ts.tv_sec = seconds;
+    ts.tv_nsec = nanoseconds;
+
+    int result = impl->set(type, &ts);
+    if (result < 0)
+    {
+        ALOGE("Unable to set alarm to %lld.%09lld: %s\n", seconds, nanoseconds, strerror(errno));
+    }
+}
+
+static jint android_server_AlarmManagerService_waitForAlarm(JNIEnv*, jobject, jlong nativeData)
+{
+    AlarmImpl *impl = reinterpret_cast<AlarmImpl *>(nativeData);
+    int result = 0;
+
+    do
+    {
+        result = impl->waitForAlarm();
+    } while (result < 0 && errno == EINTR);
+
+    if (result < 0)
+    {
+        ALOGE("Unable to wait on alarm: %s\n", strerror(errno));
+        return 0;
+    }
+
+    return result;
+}
+
+static JNINativeMethod sMethods[] = {
+     /* name, signature, funcPtr */
+    {"init", "()J", (void*)android_server_AlarmManagerService_init},
+    {"close", "(J)V", (void*)android_server_AlarmManagerService_close},
+    {"set", "(JIJJ)V", (void*)android_server_AlarmManagerService_set},
+    {"waitForAlarm", "(J)I", (void*)android_server_AlarmManagerService_waitForAlarm},
+    {"setKernelTimezone", "(JI)I", (void*)android_server_AlarmManagerService_setKernelTimezone},
+};
+
+int register_android_server_AlarmManagerService(JNIEnv* env)
+{
+    return jniRegisterNativeMethods(env, "com/android/server/AlarmManagerService",
+                                    sMethods, NELEM(sMethods));
+}
+
+} /* namespace android */
diff --git a/services/core/jni/com_android_server_AssetAtlasService.cpp b/services/core/jni/com_android_server_AssetAtlasService.cpp
new file mode 100644
index 0000000..4a1b55d
--- /dev/null
+++ b/services/core/jni/com_android_server_AssetAtlasService.cpp
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#define LOG_TAG "AssetAtlasService"
+
+#include "jni.h"
+#include "JNIHelp.h"
+
+#include <android_view_GraphicBuffer.h>
+#include <cutils/log.h>
+
+#include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include <SkCanvas.h>
+#include <SkBitmap.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+// Defines
+// ----------------------------------------------------------------------------
+
+// Defines how long to wait for the GPU when uploading the atlas
+// This timeout is defined in nanoseconds (see EGL_KHR_fence_sync extension)
+#define FENCE_TIMEOUT 2000000000
+
+// ----------------------------------------------------------------------------
+// JNI Helpers
+// ----------------------------------------------------------------------------
+
+static struct {
+    jfieldID mFinalizer;
+    jfieldID mNativeCanvas;
+} gCanvasClassInfo;
+
+static struct {
+    jfieldID mNativeCanvas;
+} gCanvasFinalizerClassInfo;
+
+#define GET_LONG(object, field) \
+    env->GetLongField(object, field)
+
+#define SET_LONG(object, field, value) \
+    env->SetLongField(object, field, value)
+
+// ----------------------------------------------------------------------------
+// Canvas management
+// ----------------------------------------------------------------------------
+
+static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCanvas) {
+    jobject canvasFinalizerObj = env->GetObjectField(canvasObj, gCanvasClassInfo.mFinalizer);
+    SkCanvas* previousCanvas = reinterpret_cast<SkCanvas*>(
+            GET_LONG(canvasObj, gCanvasClassInfo.mNativeCanvas));
+    SET_LONG(canvasObj, gCanvasClassInfo.mNativeCanvas, (long) newCanvas);
+    SET_LONG(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (long) newCanvas);
+    SkSafeUnref(previousCanvas);
+}
+
+static SkBitmap* com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, jobject,
+        jobject canvas, jint width, jint height) {
+
+    SkBitmap* bitmap = new SkBitmap;
+    bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
+    bitmap->allocPixels();
+    bitmap->eraseColor(0);
+
+    SkCanvas* nativeCanvas = SkNEW_ARGS(SkCanvas, (*bitmap));
+    swapCanvasPtr(env, canvas, nativeCanvas);
+
+    return bitmap;
+}
+
+static void com_android_server_AssetAtlasService_releaseCanvas(JNIEnv* env, jobject,
+        jobject canvas, SkBitmap* bitmap) {
+
+    SkCanvas* nativeCanvas = SkNEW(SkCanvas);
+    swapCanvasPtr(env, canvas, nativeCanvas);
+
+    delete bitmap;
+}
+
+#define CLEANUP_GL_AND_RETURN(result) \
+    if (fence != EGL_NO_SYNC_KHR) eglDestroySyncKHR(display, fence); \
+    if (image) eglDestroyImageKHR(display, image); \
+    if (texture) glDeleteTextures(1, &texture); \
+    if (surface != EGL_NO_SURFACE) eglDestroySurface(display, surface); \
+    if (context != EGL_NO_CONTEXT) eglDestroyContext(display, context); \
+    eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \
+    eglReleaseThread(); \
+    eglTerminate(display); \
+    return result;
+
+static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject,
+        jobject graphicBuffer, SkBitmap* bitmap) {
+
+    // The goal of this method is to copy the bitmap into the GraphicBuffer
+    // using the GPU to swizzle the texture content
+    sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer));
+
+    if (buffer != NULL) {
+        EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+        if (display == EGL_NO_DISPLAY) return false;
+
+        EGLint major;
+        EGLint minor;
+        if (!eglInitialize(display, &major, &minor)) {
+            ALOGW("Could not initialize EGL");
+            return false;
+        }
+
+        // We're going to use a 1x1 pbuffer surface later on
+        // The configuration doesn't really matter for what we're trying to do
+        EGLint configAttrs[] = {
+                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+                EGL_RED_SIZE, 8,
+                EGL_GREEN_SIZE, 8,
+                EGL_BLUE_SIZE, 8,
+                EGL_ALPHA_SIZE, 0,
+                EGL_DEPTH_SIZE, 0,
+                EGL_STENCIL_SIZE, 0,
+                EGL_NONE
+        };
+        EGLConfig configs[1];
+        EGLint configCount;
+        if (!eglChooseConfig(display, configAttrs, configs, 1, &configCount)) {
+            ALOGW("Could not select EGL configuration");
+            eglReleaseThread();
+            eglTerminate(display);
+            return false;
+        }
+        if (configCount <= 0) {
+            ALOGW("Could not find EGL configuration");
+            eglReleaseThread();
+            eglTerminate(display);
+            return false;
+        }
+
+        // These objects are initialized below but the default "null"
+        // values are used to cleanup properly at any point in the
+        // initialization sequence
+        GLuint texture = 0;
+        EGLImageKHR image = EGL_NO_IMAGE_KHR;
+        EGLSurface surface = EGL_NO_SURFACE;
+        EGLSyncKHR fence = EGL_NO_SYNC_KHR;
+
+        EGLint attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+        EGLContext context = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, attrs);
+        if (context == EGL_NO_CONTEXT) {
+            ALOGW("Could not create EGL context");
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        // Create the 1x1 pbuffer
+        EGLint surfaceAttrs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
+        surface = eglCreatePbufferSurface(display, configs[0], surfaceAttrs);
+        if (surface == EGL_NO_SURFACE) {
+            ALOGW("Could not create EGL surface");
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        if (!eglMakeCurrent(display, surface, surface, context)) {
+            ALOGW("Could not change current EGL context");
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        // We use an EGLImage to access the content of the GraphicBuffer
+        // The EGL image is later bound to a 2D texture
+        EGLClientBuffer clientBuffer = (EGLClientBuffer) buffer->getNativeBuffer();
+        EGLint imageAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
+        image = eglCreateImageKHR(display, EGL_NO_CONTEXT,
+                EGL_NATIVE_BUFFER_ANDROID, clientBuffer, imageAttrs);
+        if (image == EGL_NO_IMAGE_KHR) {
+            ALOGW("Could not create EGL image");
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        glGenTextures(1, &texture);
+        glBindTexture(GL_TEXTURE_2D, texture);
+        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
+        if (glGetError() != GL_NO_ERROR) {
+            ALOGW("Could not create/bind texture");
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        // Upload the content of the bitmap in the GraphicBuffer
+        glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
+        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap->width(), bitmap->height(),
+                GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels());
+        if (glGetError() != GL_NO_ERROR) {
+            ALOGW("Could not upload to texture");
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        // The fence is used to wait for the texture upload to finish
+        // properly. We cannot rely on glFlush() and glFinish() as
+        // some drivers completely ignore these API calls
+        fence = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
+        if (fence == EGL_NO_SYNC_KHR) {
+            ALOGW("Could not create sync fence %#x", eglGetError());
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        // The flag EGL_SYNC_FLUSH_COMMANDS_BIT_KHR will trigger a
+        // pipeline flush (similar to what a glFlush() would do.)
+        EGLint waitStatus = eglClientWaitSyncKHR(display, fence,
+                EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, FENCE_TIMEOUT);
+        if (waitStatus != EGL_CONDITION_SATISFIED_KHR) {
+            ALOGW("Failed to wait for the fence %#x", eglGetError());
+            CLEANUP_GL_AND_RETURN(false);
+        }
+
+        CLEANUP_GL_AND_RETURN(true);
+    }
+
+    return false;
+}
+
+// ----------------------------------------------------------------------------
+// JNI Glue
+// ----------------------------------------------------------------------------
+
+#define FIND_CLASS(var, className) \
+        var = env->FindClass(className); \
+        LOG_FATAL_IF(! var, "Unable to find class " className);
+
+#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
+        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
+        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
+
+const char* const kClassPathName = "com/android/server/AssetAtlasService";
+
+static JNINativeMethod gMethods[] = {
+    { "nAcquireAtlasCanvas", "(Landroid/graphics/Canvas;II)I",
+            (void*) com_android_server_AssetAtlasService_acquireCanvas },
+    { "nReleaseAtlasCanvas", "(Landroid/graphics/Canvas;I)V",
+            (void*) com_android_server_AssetAtlasService_releaseCanvas },
+    { "nUploadAtlas", "(Landroid/view/GraphicBuffer;I)Z",
+            (void*) com_android_server_AssetAtlasService_upload },
+};
+
+int register_android_server_AssetAtlasService(JNIEnv* env) {
+    jclass clazz;
+
+    FIND_CLASS(clazz, "android/graphics/Canvas");
+    GET_FIELD_ID(gCanvasClassInfo.mFinalizer, clazz, "mFinalizer",
+            "Landroid/graphics/Canvas$CanvasFinalizer;");
+    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "J");
+
+    FIND_CLASS(clazz, "android/graphics/Canvas$CanvasFinalizer");
+    GET_FIELD_ID(gCanvasFinalizerClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "J");
+
+    return jniRegisterNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
+}
+
+};
diff --git a/services/jni/com_android_server_ConsumerIrService.cpp b/services/core/jni/com_android_server_ConsumerIrService.cpp
similarity index 100%
rename from services/jni/com_android_server_ConsumerIrService.cpp
rename to services/core/jni/com_android_server_ConsumerIrService.cpp
diff --git a/services/jni/com_android_server_SerialService.cpp b/services/core/jni/com_android_server_SerialService.cpp
similarity index 100%
rename from services/jni/com_android_server_SerialService.cpp
rename to services/core/jni/com_android_server_SerialService.cpp
diff --git a/services/jni/com_android_server_SystemServer.cpp b/services/core/jni/com_android_server_SystemServer.cpp
similarity index 100%
rename from services/jni/com_android_server_SystemServer.cpp
rename to services/core/jni/com_android_server_SystemServer.cpp
diff --git a/services/jni/com_android_server_UsbDeviceManager.cpp b/services/core/jni/com_android_server_UsbDeviceManager.cpp
similarity index 100%
rename from services/jni/com_android_server_UsbDeviceManager.cpp
rename to services/core/jni/com_android_server_UsbDeviceManager.cpp
diff --git a/services/core/jni/com_android_server_UsbHostManager.cpp b/services/core/jni/com_android_server_UsbHostManager.cpp
new file mode 100644
index 0000000..f1fa6cf
--- /dev/null
+++ b/services/core/jni/com_android_server_UsbHostManager.cpp
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#define LOG_TAG "UsbHostManagerJNI"
+#include "utils/Log.h"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include "android_runtime/AndroidRuntime.h"
+#include "android_runtime/Log.h"
+#include "utils/Vector.h"
+
+#include <usbhost/usbhost.h>
+
+#include <stdio.h>
+#include <asm/byteorder.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+namespace android
+{
+
+static struct parcel_file_descriptor_offsets_t
+{
+    jclass mClass;
+    jmethodID mConstructor;
+} gParcelFileDescriptorOffsets;
+
+static jmethodID method_usbDeviceAdded;
+static jmethodID method_usbDeviceRemoved;
+
+static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
+    if (env->ExceptionCheck()) {
+        ALOGE("An exception was thrown by callback '%s'.", methodName);
+        LOGE_EX(env);
+        env->ExceptionClear();
+    }
+}
+
+static int usb_device_added(const char *devname, void* client_data) {
+    struct usb_descriptor_header* desc;
+    struct usb_descriptor_iter iter;
+
+    struct usb_device *device = usb_device_open(devname);
+    if (!device) {
+        ALOGE("usb_device_open failed\n");
+        return 0;
+    }
+
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jobject thiz = (jobject)client_data;
+    Vector<int> interfaceValues;
+    Vector<int> endpointValues;
+    const usb_device_descriptor* deviceDesc = usb_device_get_device_descriptor(device);
+
+    uint16_t vendorId = usb_device_get_vendor_id(device);
+    uint16_t productId = usb_device_get_product_id(device);
+    uint8_t deviceClass = deviceDesc->bDeviceClass;
+    uint8_t deviceSubClass = deviceDesc->bDeviceSubClass;
+    uint8_t protocol = deviceDesc->bDeviceProtocol;
+    char *manufacturer = usb_device_get_manufacturer_name(device);
+    char *product = usb_device_get_product_name(device);
+    char *serial = usb_device_get_serial(device);
+
+    usb_descriptor_iter_init(device, &iter);
+
+    while ((desc = usb_descriptor_iter_next(&iter)) != NULL) {
+        if (desc->bDescriptorType == USB_DT_INTERFACE) {
+            struct usb_interface_descriptor *interface = (struct usb_interface_descriptor *)desc;
+
+            // push class, subclass, protocol and number of endpoints into interfaceValues vector
+            interfaceValues.add(interface->bInterfaceNumber);
+            interfaceValues.add(interface->bInterfaceClass);
+            interfaceValues.add(interface->bInterfaceSubClass);
+            interfaceValues.add(interface->bInterfaceProtocol);
+            interfaceValues.add(interface->bNumEndpoints);
+        } else if (desc->bDescriptorType == USB_DT_ENDPOINT) {
+            struct usb_endpoint_descriptor *endpoint = (struct usb_endpoint_descriptor *)desc;
+
+            // push address, attributes, max packet size and interval into endpointValues vector
+            endpointValues.add(endpoint->bEndpointAddress);
+            endpointValues.add(endpoint->bmAttributes);
+            endpointValues.add(__le16_to_cpu(endpoint->wMaxPacketSize));
+            endpointValues.add(endpoint->bInterval);
+        }
+    }
+
+    usb_device_close(device);
+
+    // handle generic device notification
+    int length = interfaceValues.size();
+    jintArray interfaceArray = env->NewIntArray(length);
+    env->SetIntArrayRegion(interfaceArray, 0, length, interfaceValues.array());
+
+    length = endpointValues.size();
+    jintArray endpointArray = env->NewIntArray(length);
+    env->SetIntArrayRegion(endpointArray, 0, length, endpointValues.array());
+
+    jstring deviceName = env->NewStringUTF(devname);
+    jstring manufacturerName = env->NewStringUTF(manufacturer);
+    jstring productName = env->NewStringUTF(product);
+    jstring serialNumber = env->NewStringUTF(serial);
+    env->CallVoidMethod(thiz, method_usbDeviceAdded,
+            deviceName, vendorId, productId, deviceClass,
+            deviceSubClass, protocol, manufacturerName,
+            productName, serialNumber, interfaceArray, endpointArray);
+
+    env->DeleteLocalRef(interfaceArray);
+    env->DeleteLocalRef(endpointArray);
+    env->DeleteLocalRef(serialNumber);
+    env->DeleteLocalRef(productName);
+    env->DeleteLocalRef(manufacturerName);
+    env->DeleteLocalRef(deviceName);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+
+    return 0;
+}
+
+static int usb_device_removed(const char *devname, void* client_data) {
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jobject thiz = (jobject)client_data;
+
+    jstring deviceName = env->NewStringUTF(devname);
+    env->CallVoidMethod(thiz, method_usbDeviceRemoved, deviceName);
+    env->DeleteLocalRef(deviceName);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+    return 0;
+}
+
+static void android_server_UsbHostManager_monitorUsbHostBus(JNIEnv *env, jobject thiz)
+{
+    struct usb_host_context* context = usb_host_init();
+    if (!context) {
+        ALOGE("usb_host_init failed");
+        return;
+    }
+    // this will never return so it is safe to pass thiz directly
+    usb_host_run(context, usb_device_added, usb_device_removed, NULL, (void *)thiz);
+}
+
+static jobject android_server_UsbHostManager_openDevice(JNIEnv *env, jobject thiz, jstring deviceName)
+{
+    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
+    struct usb_device* device = usb_device_open(deviceNameStr);
+    env->ReleaseStringUTFChars(deviceName, deviceNameStr);
+
+    if (!device)
+        return NULL;
+
+    int fd = usb_device_get_fd(device);
+    if (fd < 0)
+        return NULL;
+    int newFD = dup(fd);
+    usb_device_close(device);
+
+    jobject fileDescriptor = jniCreateFileDescriptor(env, newFD);
+    if (fileDescriptor == NULL) {
+        return NULL;
+    }
+    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
+        gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
+}
+
+static JNINativeMethod method_table[] = {
+    { "monitorUsbHostBus", "()V", (void*)android_server_UsbHostManager_monitorUsbHostBus },
+    { "nativeOpenDevice",  "(Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;",
+                                  (void*)android_server_UsbHostManager_openDevice },
+};
+
+int register_android_server_UsbHostManager(JNIEnv *env)
+{
+    jclass clazz = env->FindClass("com/android/server/usb/UsbHostManager");
+    if (clazz == NULL) {
+        ALOGE("Can't find com/android/server/usb/UsbHostManager");
+        return -1;
+    }
+    method_usbDeviceAdded = env->GetMethodID(clazz, "usbDeviceAdded", "(Ljava/lang/String;IIIIILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[I[I)V");
+    if (method_usbDeviceAdded == NULL) {
+        ALOGE("Can't find usbDeviceAdded");
+        return -1;
+    }
+    method_usbDeviceRemoved = env->GetMethodID(clazz, "usbDeviceRemoved", "(Ljava/lang/String;)V");
+    if (method_usbDeviceRemoved == NULL) {
+        ALOGE("Can't find usbDeviceRemoved");
+        return -1;
+    }
+
+    clazz = env->FindClass("android/os/ParcelFileDescriptor");
+    LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
+    gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
+    gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
+    LOG_FATAL_IF(gParcelFileDescriptorOffsets.mConstructor == NULL,
+                 "Unable to find constructor for android.os.ParcelFileDescriptor");
+
+    return jniRegisterNativeMethods(env, "com/android/server/usb/UsbHostManager",
+            method_table, NELEM(method_table));
+}
+
+};
diff --git a/services/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp
similarity index 100%
rename from services/jni/com_android_server_VibratorService.cpp
rename to services/core/jni/com_android_server_VibratorService.cpp
diff --git a/services/jni/com_android_server_connectivity_Vpn.cpp b/services/core/jni/com_android_server_connectivity_Vpn.cpp
similarity index 100%
rename from services/jni/com_android_server_connectivity_Vpn.cpp
rename to services/core/jni/com_android_server_connectivity_Vpn.cpp
diff --git a/services/core/jni/com_android_server_dreams_McuHal.cpp b/services/core/jni/com_android_server_dreams_McuHal.cpp
new file mode 100644
index 0000000..a6d9297
--- /dev/null
+++ b/services/core/jni/com_android_server_dreams_McuHal.cpp
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "McuHal"
+
+//#define LOG_NDEBUG 0
+
+#include "JNIHelp.h"
+#include "jni.h"
+
+#include <ScopedUtfChars.h>
+#include <ScopedPrimitiveArray.h>
+
+#include <utils/Errors.h>
+#include <utils/Log.h>
+#include <hardware/mcu.h>
+
+namespace android {
+
+static jlong nativeOpen(JNIEnv* env, jclass clazz) {
+    mcu_module_t* module = NULL;
+    status_t err = hw_get_module(MCU_HARDWARE_MODULE_ID,
+            (hw_module_t const**)&module);
+    if (err) {
+        ALOGE("Couldn't load %s module (%s)", MCU_HARDWARE_MODULE_ID, strerror(-err));
+        return 0;
+    }
+
+    err = module->init(module);
+    if (err) {
+        ALOGE("Couldn't initialize %s module (%s)", MCU_HARDWARE_MODULE_ID, strerror(-err));
+        return 0;
+    }
+
+    return reinterpret_cast<jlong>(module);
+}
+
+static jbyteArray nativeSendMessage(JNIEnv* env, jclass clazz,
+        jlong ptr, jstring msgStr, jbyteArray argArray) {
+    mcu_module_t* module = reinterpret_cast<mcu_module_t*>(ptr);
+
+    ScopedUtfChars msg(env, msgStr);
+    ALOGV("Sending message %s to MCU", msg.c_str());
+
+    void* result = NULL;
+    size_t resultSize = 0;
+    status_t err;
+    if (argArray) {
+        ScopedByteArrayRO arg(env, argArray);
+        err = module->sendMessage(module, msg.c_str(), arg.get(), arg.size(),
+                &result, &resultSize);
+    } else {
+        err = module->sendMessage(module, msg.c_str(), NULL, 0, &result, &resultSize);
+    }
+    if (err) {
+        ALOGE("Couldn't send message to MCU (%s)", strerror(-err));
+        return NULL;
+    }
+
+    if (!result) {
+        return NULL;
+    }
+
+    jbyteArray resultArray = env->NewByteArray(resultSize);
+    if (resultArray) {
+        env->SetByteArrayRegion(resultArray, 0, resultSize, static_cast<jbyte*>(result));
+    }
+    free(result);
+    return resultArray;
+}
+
+static JNINativeMethod gMcuHalMethods[] = {
+    /* name, signature, funcPtr */
+    { "nativeOpen", "()J",
+            (void*) nativeOpen },
+    { "nativeSendMessage", "(JLjava/lang/String;[B)[B",
+            (void*) nativeSendMessage },
+};
+
+int register_android_server_dreams_McuHal(JNIEnv* env) {
+    int res = jniRegisterNativeMethods(env, "com/android/server/dreams/McuHal",
+            gMcuHalMethods, NELEM(gMcuHalMethods));
+    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
+    return 0;
+}
+
+} /* namespace android */
diff --git a/services/core/jni/com_android_server_input_InputApplicationHandle.cpp b/services/core/jni/com_android_server_input_InputApplicationHandle.cpp
new file mode 100644
index 0000000..f943d16
--- /dev/null
+++ b/services/core/jni/com_android_server_input_InputApplicationHandle.cpp
@@ -0,0 +1,158 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "InputApplicationHandle"
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include <android_runtime/AndroidRuntime.h>
+#include <utils/threads.h>
+
+#include "com_android_server_input_InputApplicationHandle.h"
+
+namespace android {
+
+static struct {
+    jfieldID ptr;
+    jfieldID name;
+    jfieldID dispatchingTimeoutNanos;
+} gInputApplicationHandleClassInfo;
+
+static Mutex gHandleMutex;
+
+
+// --- NativeInputApplicationHandle ---
+
+NativeInputApplicationHandle::NativeInputApplicationHandle(jweak objWeak) :
+        mObjWeak(objWeak) {
+}
+
+NativeInputApplicationHandle::~NativeInputApplicationHandle() {
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->DeleteWeakGlobalRef(mObjWeak);
+}
+
+jobject NativeInputApplicationHandle::getInputApplicationHandleObjLocalRef(JNIEnv* env) {
+    return env->NewLocalRef(mObjWeak);
+}
+
+bool NativeInputApplicationHandle::updateInfo() {
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jobject obj = env->NewLocalRef(mObjWeak);
+    if (!obj) {
+        releaseInfo();
+        return false;
+    }
+
+    if (!mInfo) {
+        mInfo = new InputApplicationInfo();
+    }
+
+    jstring nameObj = jstring(env->GetObjectField(obj,
+            gInputApplicationHandleClassInfo.name));
+    if (nameObj) {
+        const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
+        mInfo->name.setTo(nameStr);
+        env->ReleaseStringUTFChars(nameObj, nameStr);
+        env->DeleteLocalRef(nameObj);
+    } else {
+        mInfo->name.setTo("<null>");
+    }
+
+    mInfo->dispatchingTimeout = env->GetLongField(obj,
+            gInputApplicationHandleClassInfo.dispatchingTimeoutNanos);
+
+    env->DeleteLocalRef(obj);
+    return true;
+}
+
+
+// --- Global functions ---
+
+sp<InputApplicationHandle> android_server_InputApplicationHandle_getHandle(
+        JNIEnv* env, jobject inputApplicationHandleObj) {
+    if (!inputApplicationHandleObj) {
+        return NULL;
+    }
+
+    AutoMutex _l(gHandleMutex);
+
+    jlong ptr = env->GetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr);
+    NativeInputApplicationHandle* handle;
+    if (ptr) {
+        handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
+    } else {
+        jweak objWeak = env->NewWeakGlobalRef(inputApplicationHandleObj);
+        handle = new NativeInputApplicationHandle(objWeak);
+        handle->incStrong((void*)android_server_InputApplicationHandle_getHandle);
+        env->SetLongField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr,
+                reinterpret_cast<jlong>(handle));
+    }
+    return handle;
+}
+
+
+// --- JNI ---
+
+static void android_server_InputApplicationHandle_nativeDispose(JNIEnv* env, jobject obj) {
+    AutoMutex _l(gHandleMutex);
+
+    jlong ptr = env->GetLongField(obj, gInputApplicationHandleClassInfo.ptr);
+    if (ptr) {
+        env->SetLongField(obj, gInputApplicationHandleClassInfo.ptr, 0);
+
+        NativeInputApplicationHandle* handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
+        handle->decStrong((void*)android_server_InputApplicationHandle_getHandle);
+    }
+}
+
+
+static JNINativeMethod gInputApplicationHandleMethods[] = {
+    /* name, signature, funcPtr */
+    { "nativeDispose", "()V",
+            (void*) android_server_InputApplicationHandle_nativeDispose },
+};
+
+#define FIND_CLASS(var, className) \
+        var = env->FindClass(className); \
+        LOG_FATAL_IF(! var, "Unable to find class " className);
+
+#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
+        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
+        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
+
+int register_android_server_InputApplicationHandle(JNIEnv* env) {
+    int res = jniRegisterNativeMethods(env, "com/android/server/input/InputApplicationHandle",
+            gInputApplicationHandleMethods, NELEM(gInputApplicationHandleMethods));
+    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
+
+    jclass clazz;
+    FIND_CLASS(clazz, "com/android/server/input/InputApplicationHandle");
+
+    GET_FIELD_ID(gInputApplicationHandleClassInfo.ptr, clazz,
+            "ptr", "J");
+
+    GET_FIELD_ID(gInputApplicationHandleClassInfo.name, clazz,
+            "name", "Ljava/lang/String;");
+
+    GET_FIELD_ID(gInputApplicationHandleClassInfo.dispatchingTimeoutNanos,
+            clazz,
+            "dispatchingTimeoutNanos", "J");
+
+    return 0;
+}
+
+} /* namespace android */
diff --git a/services/jni/com_android_server_input_InputApplicationHandle.h b/services/core/jni/com_android_server_input_InputApplicationHandle.h
similarity index 100%
rename from services/jni/com_android_server_input_InputApplicationHandle.h
rename to services/core/jni/com_android_server_input_InputApplicationHandle.h
diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp
new file mode 100644
index 0000000..3fccf53
--- /dev/null
+++ b/services/core/jni/com_android_server_input_InputManagerService.cpp
@@ -0,0 +1,1473 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#define LOG_TAG "InputManager-JNI"
+
+//#define LOG_NDEBUG 0
+
+// Log debug messages about InputReaderPolicy
+#define DEBUG_INPUT_READER_POLICY 0
+
+// Log debug messages about InputDispatcherPolicy
+#define DEBUG_INPUT_DISPATCHER_POLICY 0
+
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include <limits.h>
+#include <android_runtime/AndroidRuntime.h>
+#include <android_runtime/Log.h>
+
+#include <utils/Log.h>
+#include <utils/Looper.h>
+#include <utils/threads.h>
+
+#include <input/InputManager.h>
+#include <input/PointerController.h>
+#include <input/SpriteController.h>
+
+#include <android_os_MessageQueue.h>
+#include <android_view_InputDevice.h>
+#include <android_view_KeyEvent.h>
+#include <android_view_MotionEvent.h>
+#include <android_view_InputChannel.h>
+#include <android_view_PointerIcon.h>
+#include <android/graphics/GraphicsJNI.h>
+
+#include <ScopedLocalRef.h>
+#include <ScopedUtfChars.h>
+
+#include "com_android_server_power_PowerManagerService.h"
+#include "com_android_server_input_InputApplicationHandle.h"
+#include "com_android_server_input_InputWindowHandle.h"
+
+namespace android {
+
+// The exponent used to calculate the pointer speed scaling factor.
+// The scaling factor is calculated as 2 ^ (speed * exponent),
+// where the speed ranges from -7 to + 7 and is supplied by the user.
+static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
+
+static struct {
+    jmethodID notifyConfigurationChanged;
+    jmethodID notifyInputDevicesChanged;
+    jmethodID notifySwitch;
+    jmethodID notifyInputChannelBroken;
+    jmethodID notifyANR;
+    jmethodID filterInputEvent;
+    jmethodID interceptKeyBeforeQueueing;
+    jmethodID interceptMotionBeforeQueueingWhenScreenOff;
+    jmethodID interceptKeyBeforeDispatching;
+    jmethodID dispatchUnhandledKey;
+    jmethodID checkInjectEventsPermission;
+    jmethodID getVirtualKeyQuietTimeMillis;
+    jmethodID getExcludedDeviceNames;
+    jmethodID getKeyRepeatTimeout;
+    jmethodID getKeyRepeatDelay;
+    jmethodID getHoverTapTimeout;
+    jmethodID getHoverTapSlop;
+    jmethodID getDoubleTapTimeout;
+    jmethodID getLongPressTimeout;
+    jmethodID getPointerLayer;
+    jmethodID getPointerIcon;
+    jmethodID getKeyboardLayoutOverlay;
+    jmethodID getDeviceAlias;
+} gServiceClassInfo;
+
+static struct {
+    jclass clazz;
+} gInputDeviceClassInfo;
+
+static struct {
+    jclass clazz;
+} gKeyEventClassInfo;
+
+static struct {
+    jclass clazz;
+} gMotionEventClassInfo;
+
+static struct {
+    jclass clazz;
+    jmethodID constructor;
+} gInputDeviceIdentifierInfo;
+
+
+
+// --- Global functions ---
+
+template<typename T>
+inline static T min(const T& a, const T& b) {
+    return a < b ? a : b;
+}
+
+template<typename T>
+inline static T max(const T& a, const T& b) {
+    return a > b ? a : b;
+}
+
+static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
+        const sp<InputApplicationHandle>& inputApplicationHandle) {
+    if (inputApplicationHandle == NULL) {
+        return NULL;
+    }
+    return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
+            getInputApplicationHandleObjLocalRef(env);
+}
+
+static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
+        const sp<InputWindowHandle>& inputWindowHandle) {
+    if (inputWindowHandle == NULL) {
+        return NULL;
+    }
+    return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
+            getInputWindowHandleObjLocalRef(env);
+}
+
+static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
+        SpriteIcon* outSpriteIcon) {
+    PointerIcon pointerIcon;
+    status_t status = android_view_PointerIcon_loadSystemIcon(env,
+            contextObj, style, &pointerIcon);
+    if (!status) {
+        pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
+        outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
+        outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
+    }
+}
+
+enum {
+    WM_ACTION_PASS_TO_USER = 1,
+};
+
+
+// --- NativeInputManager ---
+
+class NativeInputManager : public virtual RefBase,
+    public virtual InputReaderPolicyInterface,
+    public virtual InputDispatcherPolicyInterface,
+    public virtual PointerControllerPolicyInterface {
+protected:
+    virtual ~NativeInputManager();
+
+public:
+    NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
+
+    inline sp<InputManager> getInputManager() const { return mInputManager; }
+
+    void dump(String8& dump);
+
+    void setDisplayViewport(bool external, const DisplayViewport& viewport);
+
+    status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
+            const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
+    status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
+
+    void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
+    void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
+    void setInputDispatchMode(bool enabled, bool frozen);
+    void setSystemUiVisibility(int32_t visibility);
+    void setPointerSpeed(int32_t speed);
+    void setShowTouches(bool enabled);
+
+    /* --- InputReaderPolicyInterface implementation --- */
+
+    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
+    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
+    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
+    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier);
+    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
+
+    /* --- InputDispatcherPolicyInterface implementation --- */
+
+    virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
+            uint32_t policyFlags);
+    virtual void notifyConfigurationChanged(nsecs_t when);
+    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
+            const sp<InputWindowHandle>& inputWindowHandle,
+            const String8& reason);
+    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
+    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
+    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
+    virtual bool isKeyRepeatEnabled();
+    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
+    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
+    virtual nsecs_t interceptKeyBeforeDispatching(
+            const sp<InputWindowHandle>& inputWindowHandle,
+            const KeyEvent* keyEvent, uint32_t policyFlags);
+    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
+            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
+    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
+    virtual bool checkInjectEventsPermissionNonReentrant(
+            int32_t injectorPid, int32_t injectorUid);
+
+    /* --- PointerControllerPolicyInterface implementation --- */
+
+    virtual void loadPointerResources(PointerResources* outResources);
+
+private:
+    sp<InputManager> mInputManager;
+
+    jobject mContextObj;
+    jobject mServiceObj;
+    sp<Looper> mLooper;
+
+    Mutex mLock;
+    struct Locked {
+        // Display size information.
+        DisplayViewport internalViewport;
+        DisplayViewport externalViewport;
+
+        // System UI visibility.
+        int32_t systemUiVisibility;
+
+        // Pointer speed.
+        int32_t pointerSpeed;
+
+        // True if pointer gestures are enabled.
+        bool pointerGesturesEnabled;
+
+        // Show touches feature enable/disable.
+        bool showTouches;
+
+        // Sprite controller singleton, created on first use.
+        sp<SpriteController> spriteController;
+
+        // Pointer controller singleton, created and destroyed as needed.
+        wp<PointerController> pointerController;
+    } mLocked;
+
+    void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
+    void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
+    void ensureSpriteControllerLocked();
+
+    // Power manager interactions.
+    bool isScreenOn();
+    bool isScreenBright();
+
+    static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
+
+    static inline JNIEnv* jniEnv() {
+        return AndroidRuntime::getJNIEnv();
+    }
+};
+
+
+
+NativeInputManager::NativeInputManager(jobject contextObj,
+        jobject serviceObj, const sp<Looper>& looper) :
+        mLooper(looper) {
+    JNIEnv* env = jniEnv();
+
+    mContextObj = env->NewGlobalRef(contextObj);
+    mServiceObj = env->NewGlobalRef(serviceObj);
+
+    {
+        AutoMutex _l(mLock);
+        mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
+        mLocked.pointerSpeed = 0;
+        mLocked.pointerGesturesEnabled = true;
+        mLocked.showTouches = false;
+    }
+
+    sp<EventHub> eventHub = new EventHub();
+    mInputManager = new InputManager(eventHub, this, this);
+}
+
+NativeInputManager::~NativeInputManager() {
+    JNIEnv* env = jniEnv();
+
+    env->DeleteGlobalRef(mContextObj);
+    env->DeleteGlobalRef(mServiceObj);
+}
+
+void NativeInputManager::dump(String8& dump) {
+    mInputManager->getReader()->dump(dump);
+    dump.append("\n");
+
+    mInputManager->getDispatcher()->dump(dump);
+    dump.append("\n");
+}
+
+bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
+    if (env->ExceptionCheck()) {
+        ALOGE("An exception was thrown by callback '%s'.", methodName);
+        LOGE_EX(env);
+        env->ExceptionClear();
+        return true;
+    }
+    return false;
+}
+
+void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
+    bool changed = false;
+    {
+        AutoMutex _l(mLock);
+
+        DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
+        if (v != viewport) {
+            changed = true;
+            v = viewport;
+
+            if (!external) {
+                sp<PointerController> controller = mLocked.pointerController.promote();
+                if (controller != NULL) {
+                    controller->setDisplayViewport(
+                            viewport.logicalRight - viewport.logicalLeft,
+                            viewport.logicalBottom - viewport.logicalTop,
+                            viewport.orientation);
+                }
+            }
+        }
+    }
+
+    if (changed) {
+        mInputManager->getReader()->requestRefreshConfiguration(
+                InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+    }
+}
+
+status_t NativeInputManager::registerInputChannel(JNIEnv* env,
+        const sp<InputChannel>& inputChannel,
+        const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
+    return mInputManager->getDispatcher()->registerInputChannel(
+            inputChannel, inputWindowHandle, monitor);
+}
+
+status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
+        const sp<InputChannel>& inputChannel) {
+    return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
+}
+
+void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
+    JNIEnv* env = jniEnv();
+
+    jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
+            gServiceClassInfo.getVirtualKeyQuietTimeMillis);
+    if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
+        outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
+    }
+
+    outConfig->excludedDeviceNames.clear();
+    jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
+            gServiceClassInfo.getExcludedDeviceNames));
+    if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
+        jsize length = env->GetArrayLength(excludedDeviceNames);
+        for (jsize i = 0; i < length; i++) {
+            jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
+            const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
+            outConfig->excludedDeviceNames.add(String8(deviceNameChars));
+            env->ReleaseStringUTFChars(item, deviceNameChars);
+            env->DeleteLocalRef(item);
+        }
+        env->DeleteLocalRef(excludedDeviceNames);
+    }
+
+    jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
+            gServiceClassInfo.getHoverTapTimeout);
+    if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
+        jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
+                gServiceClassInfo.getDoubleTapTimeout);
+        if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
+            jint longPressTimeout = env->CallIntMethod(mServiceObj,
+                    gServiceClassInfo.getLongPressTimeout);
+            if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
+                outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
+
+                // We must ensure that the tap-drag interval is significantly shorter than
+                // the long-press timeout because the tap is held down for the entire duration
+                // of the double-tap timeout.
+                jint tapDragInterval = max(min(longPressTimeout - 100,
+                        doubleTapTimeout), hoverTapTimeout);
+                outConfig->pointerGestureTapDragInterval =
+                        milliseconds_to_nanoseconds(tapDragInterval);
+            }
+        }
+    }
+
+    jint hoverTapSlop = env->CallIntMethod(mServiceObj,
+            gServiceClassInfo.getHoverTapSlop);
+    if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
+        outConfig->pointerGestureTapSlop = hoverTapSlop;
+    }
+
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
+                * POINTER_SPEED_EXPONENT);
+        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
+
+        outConfig->showTouches = mLocked.showTouches;
+
+        outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
+        outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
+    } // release lock
+}
+
+sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
+    AutoMutex _l(mLock);
+
+    sp<PointerController> controller = mLocked.pointerController.promote();
+    if (controller == NULL) {
+        ensureSpriteControllerLocked();
+
+        controller = new PointerController(this, mLooper, mLocked.spriteController);
+        mLocked.pointerController = controller;
+
+        DisplayViewport& v = mLocked.internalViewport;
+        controller->setDisplayViewport(
+                v.logicalRight - v.logicalLeft,
+                v.logicalBottom - v.logicalTop,
+                v.orientation);
+
+        JNIEnv* env = jniEnv();
+        jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
+                gServiceClassInfo.getPointerIcon);
+        if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
+            PointerIcon pointerIcon;
+            status_t status = android_view_PointerIcon_load(env, pointerIconObj,
+                    mContextObj, &pointerIcon);
+            if (!status && !pointerIcon.isNullIcon()) {
+                controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
+                        pointerIcon.hotSpotX, pointerIcon.hotSpotY));
+            } else {
+                controller->setPointerIcon(SpriteIcon());
+            }
+            env->DeleteLocalRef(pointerIconObj);
+        }
+
+        updateInactivityTimeoutLocked(controller);
+    }
+    return controller;
+}
+
+void NativeInputManager::ensureSpriteControllerLocked() {
+    if (mLocked.spriteController == NULL) {
+        JNIEnv* env = jniEnv();
+        jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
+        if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
+            layer = -1;
+        }
+        mLocked.spriteController = new SpriteController(mLooper, layer);
+    }
+}
+
+void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
+    JNIEnv* env = jniEnv();
+
+    size_t count = inputDevices.size();
+    jobjectArray inputDevicesObjArray = env->NewObjectArray(
+            count, gInputDeviceClassInfo.clazz, NULL);
+    if (inputDevicesObjArray) {
+        bool error = false;
+        for (size_t i = 0; i < count; i++) {
+            jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
+            if (!inputDeviceObj) {
+                error = true;
+                break;
+            }
+
+            env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
+            env->DeleteLocalRef(inputDeviceObj);
+        }
+
+        if (!error) {
+            env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
+                    inputDevicesObjArray);
+        }
+
+        env->DeleteLocalRef(inputDevicesObjArray);
+    }
+
+    checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
+}
+
+sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
+        const InputDeviceIdentifier& identifier) {
+    JNIEnv* env = jniEnv();
+
+    sp<KeyCharacterMap> result;
+    ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.string()));
+    ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz,
+            gInputDeviceIdentifierInfo.constructor, descriptor.get(),
+            identifier.vendor, identifier.product));
+    ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
+                gServiceClassInfo.getKeyboardLayoutOverlay, identifierObj.get())));
+    if (arrayObj.get()) {
+        ScopedLocalRef<jstring> filenameObj(env,
+                jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
+        ScopedLocalRef<jstring> contentsObj(env,
+                jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
+        ScopedUtfChars filenameChars(env, filenameObj.get());
+        ScopedUtfChars contentsChars(env, contentsObj.get());
+
+        KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
+                String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
+    }
+    checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
+    return result;
+}
+
+String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
+    JNIEnv* env = jniEnv();
+
+    ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
+    ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
+            gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
+    String8 result;
+    if (aliasObj.get()) {
+        ScopedUtfChars aliasChars(env, aliasObj.get());
+        result.setTo(aliasChars.c_str());
+    }
+    checkAndClearExceptionFromCallback(env, "getDeviceAlias");
+    return result;
+}
+
+void NativeInputManager::notifySwitch(nsecs_t when,
+        uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
+#if DEBUG_INPUT_DISPATCHER_POLICY
+    ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
+            when, switchValues, switchMask, policyFlags);
+#endif
+
+    JNIEnv* env = jniEnv();
+
+    env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
+            when, switchValues, switchMask);
+    checkAndClearExceptionFromCallback(env, "notifySwitch");
+}
+
+void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
+#if DEBUG_INPUT_DISPATCHER_POLICY
+    ALOGD("notifyConfigurationChanged - when=%lld", when);
+#endif
+
+    JNIEnv* env = jniEnv();
+
+    env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
+    checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
+}
+
+nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
+        const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
+#if DEBUG_INPUT_DISPATCHER_POLICY
+    ALOGD("notifyANR");
+#endif
+
+    JNIEnv* env = jniEnv();
+
+    jobject inputApplicationHandleObj =
+            getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
+    jobject inputWindowHandleObj =
+            getInputWindowHandleObjLocalRef(env, inputWindowHandle);
+    jstring reasonObj = env->NewStringUTF(reason.string());
+
+    jlong newTimeout = env->CallLongMethod(mServiceObj,
+                gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
+                reasonObj);
+    if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
+        newTimeout = 0; // abort dispatch
+    } else {
+        assert(newTimeout >= 0);
+    }
+
+    env->DeleteLocalRef(reasonObj);
+    env->DeleteLocalRef(inputWindowHandleObj);
+    env->DeleteLocalRef(inputApplicationHandleObj);
+    return newTimeout;
+}
+
+void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
+#if DEBUG_INPUT_DISPATCHER_POLICY
+    ALOGD("notifyInputChannelBroken");
+#endif
+
+    JNIEnv* env = jniEnv();
+
+    jobject inputWindowHandleObj =
+            getInputWindowHandleObjLocalRef(env, inputWindowHandle);
+    if (inputWindowHandleObj) {
+        env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
+                inputWindowHandleObj);
+        checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
+
+        env->DeleteLocalRef(inputWindowHandleObj);
+    }
+}
+
+void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
+    JNIEnv* env = jniEnv();
+
+    jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
+            gServiceClassInfo.getKeyRepeatTimeout);
+    if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
+        outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
+    }
+
+    jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
+            gServiceClassInfo.getKeyRepeatDelay);
+    if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
+        outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
+    }
+}
+
+bool NativeInputManager::isKeyRepeatEnabled() {
+    // Only enable automatic key repeating when the screen is on.
+    return isScreenOn();
+}
+
+void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
+    Vector<sp<InputWindowHandle> > windowHandles;
+
+    if (windowHandleObjArray) {
+        jsize length = env->GetArrayLength(windowHandleObjArray);
+        for (jsize i = 0; i < length; i++) {
+            jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
+            if (! windowHandleObj) {
+                break; // found null element indicating end of used portion of the array
+            }
+
+            sp<InputWindowHandle> windowHandle =
+                    android_server_InputWindowHandle_getHandle(env, windowHandleObj);
+            if (windowHandle != NULL) {
+                windowHandles.push(windowHandle);
+            }
+            env->DeleteLocalRef(windowHandleObj);
+        }
+    }
+
+    mInputManager->getDispatcher()->setInputWindows(windowHandles);
+
+    // Do this after the dispatcher has updated the window handle state.
+    bool newPointerGesturesEnabled = true;
+    size_t numWindows = windowHandles.size();
+    for (size_t i = 0; i < numWindows; i++) {
+        const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
+        const InputWindowInfo* windowInfo = windowHandle->getInfo();
+        if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
+                & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
+            newPointerGesturesEnabled = false;
+        }
+    }
+
+    uint32_t changes = 0;
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
+            mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
+            changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
+        }
+    } // release lock
+
+    if (changes) {
+        mInputManager->getReader()->requestRefreshConfiguration(changes);
+    }
+}
+
+void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
+    sp<InputApplicationHandle> applicationHandle =
+            android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
+    mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
+}
+
+void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
+    mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
+}
+
+void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
+    AutoMutex _l(mLock);
+
+    if (mLocked.systemUiVisibility != visibility) {
+        mLocked.systemUiVisibility = visibility;
+
+        sp<PointerController> controller = mLocked.pointerController.promote();
+        if (controller != NULL) {
+            updateInactivityTimeoutLocked(controller);
+        }
+    }
+}
+
+void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
+    bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
+    controller->setInactivityTimeout(lightsOut
+            ? PointerController::INACTIVITY_TIMEOUT_SHORT
+            : PointerController::INACTIVITY_TIMEOUT_NORMAL);
+}
+
+void NativeInputManager::setPointerSpeed(int32_t speed) {
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mLocked.pointerSpeed == speed) {
+            return;
+        }
+
+        ALOGI("Setting pointer speed to %d.", speed);
+        mLocked.pointerSpeed = speed;
+    } // release lock
+
+    mInputManager->getReader()->requestRefreshConfiguration(
+            InputReaderConfiguration::CHANGE_POINTER_SPEED);
+}
+
+void NativeInputManager::setShowTouches(bool enabled) {
+    { // acquire lock
+        AutoMutex _l(mLock);
+
+        if (mLocked.showTouches == enabled) {
+            return;
+        }
+
+        ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
+        mLocked.showTouches = enabled;
+    } // release lock
+
+    mInputManager->getReader()->requestRefreshConfiguration(
+            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
+}
+
+bool NativeInputManager::isScreenOn() {
+    return android_server_PowerManagerService_isScreenOn();
+}
+
+bool NativeInputManager::isScreenBright() {
+    return android_server_PowerManagerService_isScreenBright();
+}
+
+bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
+    jobject inputEventObj;
+
+    JNIEnv* env = jniEnv();
+    switch (inputEvent->getType()) {
+    case AINPUT_EVENT_TYPE_KEY:
+        inputEventObj = android_view_KeyEvent_fromNative(env,
+                static_cast<const KeyEvent*>(inputEvent));
+        break;
+    case AINPUT_EVENT_TYPE_MOTION:
+        inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
+                static_cast<const MotionEvent*>(inputEvent));
+        break;
+    default:
+        return true; // dispatch the event normally
+    }
+
+    if (!inputEventObj) {
+        ALOGE("Failed to obtain input event object for filterInputEvent.");
+        return true; // dispatch the event normally
+    }
+
+    // The callee is responsible for recycling the event.
+    jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
+            inputEventObj, policyFlags);
+    if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
+        pass = true;
+    }
+    env->DeleteLocalRef(inputEventObj);
+    return pass;
+}
+
+void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
+        uint32_t& policyFlags) {
+    // Policy:
+    // - Ignore untrusted events and pass them along.
+    // - Ask the window manager what to do with normal events and trusted injected events.
+    // - For normal events wake and brighten the screen if currently off or dim.
+    if ((policyFlags & POLICY_FLAG_TRUSTED)) {
+        nsecs_t when = keyEvent->getEventTime();
+        bool isScreenOn = this->isScreenOn();
+        bool isScreenBright = this->isScreenBright();
+
+        JNIEnv* env = jniEnv();
+        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
+        jint wmActions;
+        if (keyEventObj) {
+            wmActions = env->CallIntMethod(mServiceObj,
+                    gServiceClassInfo.interceptKeyBeforeQueueing,
+                    keyEventObj, policyFlags, isScreenOn);
+            if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
+                wmActions = 0;
+            }
+            android_view_KeyEvent_recycle(env, keyEventObj);
+            env->DeleteLocalRef(keyEventObj);
+        } else {
+            ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
+            wmActions = 0;
+        }
+
+        if (!(policyFlags & POLICY_FLAG_INJECTED)) {
+            if (!isScreenOn) {
+                policyFlags |= POLICY_FLAG_WOKE_HERE;
+            }
+
+            if (!isScreenBright) {
+                policyFlags |= POLICY_FLAG_BRIGHT_HERE;
+            }
+        }
+
+        handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
+    } else {
+        policyFlags |= POLICY_FLAG_PASS_TO_USER;
+    }
+}
+
+void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
+    // Policy:
+    // - Ignore untrusted events and pass them along.
+    // - No special filtering for injected events required at this time.
+    // - Filter normal events based on screen state.
+    // - For normal events brighten (but do not wake) the screen if currently dim.
+    if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
+        if (isScreenOn()) {
+            policyFlags |= POLICY_FLAG_PASS_TO_USER;
+
+            if (!isScreenBright()) {
+                policyFlags |= POLICY_FLAG_BRIGHT_HERE;
+            }
+        } else {
+            JNIEnv* env = jniEnv();
+            jint wmActions = env->CallIntMethod(mServiceObj,
+                        gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
+                        when, policyFlags);
+            if (checkAndClearExceptionFromCallback(env,
+                    "interceptMotionBeforeQueueingWhenScreenOff")) {
+                wmActions = 0;
+            }
+
+            policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
+            handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
+        }
+    } else {
+        policyFlags |= POLICY_FLAG_PASS_TO_USER;
+    }
+}
+
+void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
+        uint32_t& policyFlags) {
+    if (wmActions & WM_ACTION_PASS_TO_USER) {
+        policyFlags |= POLICY_FLAG_PASS_TO_USER;
+    } else {
+#if DEBUG_INPUT_DISPATCHER_POLICY
+        ALOGD("handleInterceptActions: Not passing key to user.");
+#endif
+    }
+}
+
+nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
+        const sp<InputWindowHandle>& inputWindowHandle,
+        const KeyEvent* keyEvent, uint32_t policyFlags) {
+    // Policy:
+    // - Ignore untrusted events and pass them along.
+    // - Filter normal events and trusted injected events through the window manager policy to
+    //   handle the HOME key and the like.
+    nsecs_t result = 0;
+    if (policyFlags & POLICY_FLAG_TRUSTED) {
+        JNIEnv* env = jniEnv();
+
+        // Note: inputWindowHandle may be null.
+        jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
+        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
+        if (keyEventObj) {
+            jlong delayMillis = env->CallLongMethod(mServiceObj,
+                    gServiceClassInfo.interceptKeyBeforeDispatching,
+                    inputWindowHandleObj, keyEventObj, policyFlags);
+            bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
+            android_view_KeyEvent_recycle(env, keyEventObj);
+            env->DeleteLocalRef(keyEventObj);
+            if (!error) {
+                if (delayMillis < 0) {
+                    result = -1;
+                } else if (delayMillis > 0) {
+                    result = milliseconds_to_nanoseconds(delayMillis);
+                }
+            }
+        } else {
+            ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
+        }
+        env->DeleteLocalRef(inputWindowHandleObj);
+    }
+    return result;
+}
+
+bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
+        const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
+    // Policy:
+    // - Ignore untrusted events and do not perform default handling.
+    bool result = false;
+    if (policyFlags & POLICY_FLAG_TRUSTED) {
+        JNIEnv* env = jniEnv();
+
+        // Note: inputWindowHandle may be null.
+        jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
+        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
+        if (keyEventObj) {
+            jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
+                    gServiceClassInfo.dispatchUnhandledKey,
+                    inputWindowHandleObj, keyEventObj, policyFlags);
+            if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
+                fallbackKeyEventObj = NULL;
+            }
+            android_view_KeyEvent_recycle(env, keyEventObj);
+            env->DeleteLocalRef(keyEventObj);
+
+            if (fallbackKeyEventObj) {
+                // Note: outFallbackKeyEvent may be the same object as keyEvent.
+                if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
+                        outFallbackKeyEvent)) {
+                    result = true;
+                }
+                android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
+                env->DeleteLocalRef(fallbackKeyEventObj);
+            }
+        } else {
+            ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
+        }
+        env->DeleteLocalRef(inputWindowHandleObj);
+    }
+    return result;
+}
+
+void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
+    android_server_PowerManagerService_userActivity(eventTime, eventType);
+}
+
+
+bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
+        int32_t injectorPid, int32_t injectorUid) {
+    JNIEnv* env = jniEnv();
+    jboolean result = env->CallBooleanMethod(mServiceObj,
+            gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
+    if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
+        result = false;
+    }
+    return result;
+}
+
+void NativeInputManager::loadPointerResources(PointerResources* outResources) {
+    JNIEnv* env = jniEnv();
+
+    loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
+            &outResources->spotHover);
+    loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
+            &outResources->spotTouch);
+    loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
+            &outResources->spotAnchor);
+}
+
+
+// ----------------------------------------------------------------------------
+
+static jlong nativeInit(JNIEnv* env, jclass clazz,
+        jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
+    sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
+    if (messageQueue == NULL) {
+        jniThrowRuntimeException(env, "MessageQueue is not initialized.");
+        return 0;
+    }
+
+    NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
+            messageQueue->getLooper());
+    im->incStrong(0);
+    return reinterpret_cast<jlong>(im);
+}
+
+static void nativeStart(JNIEnv* env, jclass clazz, jlong ptr) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    status_t result = im->getInputManager()->start();
+    if (result) {
+        jniThrowRuntimeException(env, "Input manager could not be started.");
+    }
+}
+
+static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jlong ptr, jboolean external,
+        jint displayId, jint orientation,
+        jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
+        jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
+        jint deviceWidth, jint deviceHeight) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    DisplayViewport v;
+    v.displayId = displayId;
+    v.orientation = orientation;
+    v.logicalLeft = logicalLeft;
+    v.logicalTop = logicalTop;
+    v.logicalRight = logicalRight;
+    v.logicalBottom = logicalBottom;
+    v.physicalLeft = physicalLeft;
+    v.physicalTop = physicalTop;
+    v.physicalRight = physicalRight;
+    v.physicalBottom = physicalBottom;
+    v.deviceWidth = deviceWidth;
+    v.deviceHeight = deviceHeight;
+    im->setDisplayViewport(external, v);
+}
+
+static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
+        jlong ptr, jint deviceId, jint sourceMask, jint scanCode) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    return (jint) im->getInputManager()->getReader()->getScanCodeState(
+            deviceId, uint32_t(sourceMask), scanCode);
+}
+
+static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
+        jlong ptr, jint deviceId, jint sourceMask, jint keyCode) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    return (jint) im->getInputManager()->getReader()->getKeyCodeState(
+            deviceId, uint32_t(sourceMask), keyCode);
+}
+
+static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
+        jlong ptr, jint deviceId, jint sourceMask, jint sw) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    return (jint) im->getInputManager()->getReader()->getSwitchState(
+            deviceId, uint32_t(sourceMask), sw);
+}
+
+static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
+        jlong ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
+    uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
+    jsize numCodes = env->GetArrayLength(keyCodes);
+    jboolean result;
+    if (numCodes == env->GetArrayLength(keyCodes)) {
+        if (im->getInputManager()->getReader()->hasKeys(
+                deviceId, uint32_t(sourceMask), numCodes, codes, flags)) {
+            result = JNI_TRUE;
+        } else {
+            result = JNI_FALSE;
+        }
+    } else {
+        result = JNI_FALSE;
+    }
+
+    env->ReleaseBooleanArrayElements(outFlags, flags, 0);
+    env->ReleaseIntArrayElements(keyCodes, codes, 0);
+    return result;
+}
+
+static void throwInputChannelNotInitialized(JNIEnv* env) {
+    jniThrowException(env, "java/lang/IllegalStateException",
+             "inputChannel is not initialized");
+}
+
+static void handleInputChannelDisposed(JNIEnv* env,
+        jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
+    NativeInputManager* im = static_cast<NativeInputManager*>(data);
+
+    ALOGW("Input channel object '%s' was disposed without first being unregistered with "
+            "the input manager!", inputChannel->getName().string());
+    im->unregisterInputChannel(env, inputChannel);
+}
+
+static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
+        jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
+            inputChannelObj);
+    if (inputChannel == NULL) {
+        throwInputChannelNotInitialized(env);
+        return;
+    }
+
+    sp<InputWindowHandle> inputWindowHandle =
+            android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
+
+    status_t status = im->registerInputChannel(
+            env, inputChannel, inputWindowHandle, monitor);
+    if (status) {
+        String8 message;
+        message.appendFormat("Failed to register input channel.  status=%d", status);
+        jniThrowRuntimeException(env, message.string());
+        return;
+    }
+
+    if (! monitor) {
+        android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
+                handleInputChannelDisposed, im);
+    }
+}
+
+static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
+        jlong ptr, jobject inputChannelObj) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
+            inputChannelObj);
+    if (inputChannel == NULL) {
+        throwInputChannelNotInitialized(env);
+        return;
+    }
+
+    android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
+
+    status_t status = im->unregisterInputChannel(env, inputChannel);
+    if (status && status != BAD_VALUE) { // ignore already unregistered channel
+        String8 message;
+        message.appendFormat("Failed to unregister input channel.  status=%d", status);
+        jniThrowRuntimeException(env, message.string());
+    }
+}
+
+static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
+        jlong ptr, jboolean enabled) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
+}
+
+static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
+        jlong ptr, jobject inputEventObj, jint displayId, jint injectorPid, jint injectorUid,
+        jint syncMode, jint timeoutMillis, jint policyFlags) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
+        KeyEvent keyEvent;
+        status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
+        if (status) {
+            jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
+            return INPUT_EVENT_INJECTION_FAILED;
+        }
+
+        return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
+                & keyEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
+                uint32_t(policyFlags));
+    } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
+        const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
+        if (!motionEvent) {
+            jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
+            return INPUT_EVENT_INJECTION_FAILED;
+        }
+
+        return (jint) im->getInputManager()->getDispatcher()->injectInputEvent(
+                motionEvent, displayId, injectorPid, injectorUid, syncMode, timeoutMillis,
+                uint32_t(policyFlags));
+    } else {
+        jniThrowRuntimeException(env, "Invalid input event type.");
+        return INPUT_EVENT_INJECTION_FAILED;
+    }
+}
+
+static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
+        jlong ptr, jobjectArray windowHandleObjArray) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->setInputWindows(env, windowHandleObjArray);
+}
+
+static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
+        jlong ptr, jobject applicationHandleObj) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->setFocusedApplication(env, applicationHandleObj);
+}
+
+static void nativeSetInputDispatchMode(JNIEnv* env,
+        jclass clazz, jlong ptr, jboolean enabled, jboolean frozen) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->setInputDispatchMode(enabled, frozen);
+}
+
+static void nativeSetSystemUiVisibility(JNIEnv* env,
+        jclass clazz, jlong ptr, jint visibility) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->setSystemUiVisibility(visibility);
+}
+
+static jboolean nativeTransferTouchFocus(JNIEnv* env,
+        jclass clazz, jlong ptr, jobject fromChannelObj, jobject toChannelObj) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    sp<InputChannel> fromChannel =
+            android_view_InputChannel_getInputChannel(env, fromChannelObj);
+    sp<InputChannel> toChannel =
+            android_view_InputChannel_getInputChannel(env, toChannelObj);
+
+    if (fromChannel == NULL || toChannel == NULL) {
+        return JNI_FALSE;
+    }
+
+    if (im->getInputManager()->getDispatcher()->
+            transferTouchFocus(fromChannel, toChannel)) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
+}
+
+static void nativeSetPointerSpeed(JNIEnv* env,
+        jclass clazz, jlong ptr, jint speed) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->setPointerSpeed(speed);
+}
+
+static void nativeSetShowTouches(JNIEnv* env,
+        jclass clazz, jlong ptr, jboolean enabled) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->setShowTouches(enabled);
+}
+
+static void nativeVibrate(JNIEnv* env,
+        jclass clazz, jlong ptr, jint deviceId, jlongArray patternObj,
+        jint repeat, jint token) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    size_t patternSize = env->GetArrayLength(patternObj);
+    if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
+        ALOGI("Skipped requested vibration because the pattern size is %d "
+                "which is more than the maximum supported size of %d.",
+                patternSize, MAX_VIBRATE_PATTERN_SIZE);
+        return; // limit to reasonable size
+    }
+
+    jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
+            patternObj, NULL));
+    nsecs_t pattern[patternSize];
+    for (size_t i = 0; i < patternSize; i++) {
+        pattern[i] = max(jlong(0), min(patternMillis[i],
+                (jlong)(MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL))) * 1000000LL;
+    }
+    env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
+
+    im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
+}
+
+static void nativeCancelVibrate(JNIEnv* env,
+        jclass clazz, jlong ptr, jint deviceId, jint token) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
+}
+
+static void nativeReloadKeyboardLayouts(JNIEnv* env,
+        jclass clazz, jlong ptr) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->getInputManager()->getReader()->requestRefreshConfiguration(
+            InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
+}
+
+static void nativeReloadDeviceAliases(JNIEnv* env,
+        jclass clazz, jlong ptr) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->getInputManager()->getReader()->requestRefreshConfiguration(
+            InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
+}
+
+static jstring nativeDump(JNIEnv* env, jclass clazz, jlong ptr) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    String8 dump;
+    im->dump(dump);
+    return env->NewStringUTF(dump.string());
+}
+
+static void nativeMonitor(JNIEnv* env, jclass clazz, jlong ptr) {
+    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
+
+    im->getInputManager()->getReader()->monitor();
+    im->getInputManager()->getDispatcher()->monitor();
+}
+
+// ----------------------------------------------------------------------------
+
+static JNINativeMethod gInputManagerMethods[] = {
+    /* name, signature, funcPtr */
+    { "nativeInit",
+            "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)J",
+            (void*) nativeInit },
+    { "nativeStart", "(J)V",
+            (void*) nativeStart },
+    { "nativeSetDisplayViewport", "(JZIIIIIIIIIIII)V",
+            (void*) nativeSetDisplayViewport },
+    { "nativeGetScanCodeState", "(JIII)I",
+            (void*) nativeGetScanCodeState },
+    { "nativeGetKeyCodeState", "(JIII)I",
+            (void*) nativeGetKeyCodeState },
+    { "nativeGetSwitchState", "(JIII)I",
+            (void*) nativeGetSwitchState },
+    { "nativeHasKeys", "(JII[I[Z)Z",
+            (void*) nativeHasKeys },
+    { "nativeRegisterInputChannel",
+            "(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
+            (void*) nativeRegisterInputChannel },
+    { "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
+            (void*) nativeUnregisterInputChannel },
+    { "nativeSetInputFilterEnabled", "(JZ)V",
+            (void*) nativeSetInputFilterEnabled },
+    { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIIII)I",
+            (void*) nativeInjectInputEvent },
+    { "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;)V",
+            (void*) nativeSetInputWindows },
+    { "nativeSetFocusedApplication", "(JLcom/android/server/input/InputApplicationHandle;)V",
+            (void*) nativeSetFocusedApplication },
+    { "nativeSetInputDispatchMode", "(JZZ)V",
+            (void*) nativeSetInputDispatchMode },
+    { "nativeSetSystemUiVisibility", "(JI)V",
+            (void*) nativeSetSystemUiVisibility },
+    { "nativeTransferTouchFocus", "(JLandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
+            (void*) nativeTransferTouchFocus },
+    { "nativeSetPointerSpeed", "(JI)V",
+            (void*) nativeSetPointerSpeed },
+    { "nativeSetShowTouches", "(JZ)V",
+            (void*) nativeSetShowTouches },
+    { "nativeVibrate", "(JI[JII)V",
+            (void*) nativeVibrate },
+    { "nativeCancelVibrate", "(JII)V",
+            (void*) nativeCancelVibrate },
+    { "nativeReloadKeyboardLayouts", "(J)V",
+            (void*) nativeReloadKeyboardLayouts },
+    { "nativeReloadDeviceAliases", "(J)V",
+            (void*) nativeReloadDeviceAliases },
+    { "nativeDump", "(J)Ljava/lang/String;",
+            (void*) nativeDump },
+    { "nativeMonitor", "(J)V",
+            (void*) nativeMonitor },
+};
+
+#define FIND_CLASS(var, className) \
+        var = env->FindClass(className); \
+        LOG_FATAL_IF(! var, "Unable to find class " className);
+
+#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
+        var = env->GetMethodID(clazz, methodName, methodDescriptor); \
+        LOG_FATAL_IF(! var, "Unable to find method " methodName);
+
+#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
+        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
+        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
+
+int register_android_server_InputManager(JNIEnv* env) {
+    int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
+            gInputManagerMethods, NELEM(gInputManagerMethods));
+    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
+
+    // Callbacks
+
+    jclass clazz;
+    FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
+
+    GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
+            "notifyConfigurationChanged", "(J)V");
+
+    GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
+            "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
+
+    GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
+            "notifySwitch", "(JII)V");
+
+    GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
+            "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
+
+    GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
+            "notifyANR",
+            "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
+
+    GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
+            "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
+
+    GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
+            "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
+
+    GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
+            clazz,
+            "interceptMotionBeforeQueueingWhenScreenOff", "(JI)I");
+
+    GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
+            "interceptKeyBeforeDispatching",
+            "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
+
+    GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
+            "dispatchUnhandledKey",
+            "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
+
+    GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
+            "checkInjectEventsPermission", "(II)Z");
+
+    GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
+            "getVirtualKeyQuietTimeMillis", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
+            "getExcludedDeviceNames", "()[Ljava/lang/String;");
+
+    GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
+            "getKeyRepeatTimeout", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
+            "getKeyRepeatDelay", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
+            "getHoverTapTimeout", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
+            "getHoverTapSlop", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
+            "getDoubleTapTimeout", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
+            "getLongPressTimeout", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
+            "getPointerLayer", "()I");
+
+    GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
+            "getPointerIcon", "()Landroid/view/PointerIcon;");
+
+    GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
+            "getKeyboardLayoutOverlay",
+            "(Landroid/hardware/input/InputDeviceIdentifier;)[Ljava/lang/String;");
+
+    GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
+            "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
+
+    // InputDevice
+
+    FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
+    gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
+
+    // KeyEvent
+
+    FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
+    gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
+
+    // MotionEvent
+
+    FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
+    gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
+
+    // InputDeviceIdentifier
+
+    FIND_CLASS(gInputDeviceIdentifierInfo.clazz, "android/hardware/input/InputDeviceIdentifier");
+    gInputDeviceIdentifierInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceIdentifierInfo.clazz));
+    GET_METHOD_ID(gInputDeviceIdentifierInfo.constructor, gInputDeviceIdentifierInfo.clazz,
+            "<init>", "(Ljava/lang/String;II)V");
+
+    return 0;
+}
+
+} /* namespace android */
diff --git a/services/core/jni/com_android_server_input_InputWindowHandle.cpp b/services/core/jni/com_android_server_input_InputWindowHandle.cpp
new file mode 100644
index 0000000..b80183c
--- /dev/null
+++ b/services/core/jni/com_android_server_input_InputWindowHandle.cpp
@@ -0,0 +1,309 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "InputWindowHandle"
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include <android_runtime/AndroidRuntime.h>
+#include <utils/threads.h>
+
+#include <android_view_InputChannel.h>
+#include <android/graphics/Region.h>
+
+#include "com_android_server_input_InputWindowHandle.h"
+#include "com_android_server_input_InputApplicationHandle.h"
+
+namespace android {
+
+static struct {
+    jfieldID ptr;
+    jfieldID inputApplicationHandle;
+    jfieldID inputChannel;
+    jfieldID name;
+    jfieldID layoutParamsFlags;
+    jfieldID layoutParamsPrivateFlags;
+    jfieldID layoutParamsType;
+    jfieldID dispatchingTimeoutNanos;
+    jfieldID frameLeft;
+    jfieldID frameTop;
+    jfieldID frameRight;
+    jfieldID frameBottom;
+    jfieldID scaleFactor;
+    jfieldID touchableRegion;
+    jfieldID visible;
+    jfieldID canReceiveKeys;
+    jfieldID hasFocus;
+    jfieldID hasWallpaper;
+    jfieldID paused;
+    jfieldID layer;
+    jfieldID ownerPid;
+    jfieldID ownerUid;
+    jfieldID inputFeatures;
+    jfieldID displayId;
+} gInputWindowHandleClassInfo;
+
+static Mutex gHandleMutex;
+
+
+// --- NativeInputWindowHandle ---
+
+NativeInputWindowHandle::NativeInputWindowHandle(
+        const sp<InputApplicationHandle>& inputApplicationHandle, jweak objWeak) :
+        InputWindowHandle(inputApplicationHandle),
+        mObjWeak(objWeak) {
+}
+
+NativeInputWindowHandle::~NativeInputWindowHandle() {
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->DeleteWeakGlobalRef(mObjWeak);
+}
+
+jobject NativeInputWindowHandle::getInputWindowHandleObjLocalRef(JNIEnv* env) {
+    return env->NewLocalRef(mObjWeak);
+}
+
+bool NativeInputWindowHandle::updateInfo() {
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jobject obj = env->NewLocalRef(mObjWeak);
+    if (!obj) {
+        releaseInfo();
+        return false;
+    }
+
+    if (!mInfo) {
+        mInfo = new InputWindowInfo();
+    }
+
+    jobject inputChannelObj = env->GetObjectField(obj,
+            gInputWindowHandleClassInfo.inputChannel);
+    if (inputChannelObj) {
+        mInfo->inputChannel = android_view_InputChannel_getInputChannel(env, inputChannelObj);
+        env->DeleteLocalRef(inputChannelObj);
+    } else {
+        mInfo->inputChannel.clear();
+    }
+
+    jstring nameObj = jstring(env->GetObjectField(obj,
+            gInputWindowHandleClassInfo.name));
+    if (nameObj) {
+        const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
+        mInfo->name.setTo(nameStr);
+        env->ReleaseStringUTFChars(nameObj, nameStr);
+        env->DeleteLocalRef(nameObj);
+    } else {
+        mInfo->name.setTo("<null>");
+    }
+
+    mInfo->layoutParamsFlags = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.layoutParamsFlags);
+    mInfo->layoutParamsPrivateFlags = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.layoutParamsPrivateFlags);
+    mInfo->layoutParamsType = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.layoutParamsType);
+    mInfo->dispatchingTimeout = env->GetLongField(obj,
+            gInputWindowHandleClassInfo.dispatchingTimeoutNanos);
+    mInfo->frameLeft = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.frameLeft);
+    mInfo->frameTop = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.frameTop);
+    mInfo->frameRight = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.frameRight);
+    mInfo->frameBottom = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.frameBottom);
+    mInfo->scaleFactor = env->GetFloatField(obj,
+            gInputWindowHandleClassInfo.scaleFactor);
+
+    jobject regionObj = env->GetObjectField(obj,
+            gInputWindowHandleClassInfo.touchableRegion);
+    if (regionObj) {
+        SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
+        mInfo->touchableRegion.set(*region);
+        env->DeleteLocalRef(regionObj);
+    } else {
+        mInfo->touchableRegion.setEmpty();
+    }
+
+    mInfo->visible = env->GetBooleanField(obj,
+            gInputWindowHandleClassInfo.visible);
+    mInfo->canReceiveKeys = env->GetBooleanField(obj,
+            gInputWindowHandleClassInfo.canReceiveKeys);
+    mInfo->hasFocus = env->GetBooleanField(obj,
+            gInputWindowHandleClassInfo.hasFocus);
+    mInfo->hasWallpaper = env->GetBooleanField(obj,
+            gInputWindowHandleClassInfo.hasWallpaper);
+    mInfo->paused = env->GetBooleanField(obj,
+            gInputWindowHandleClassInfo.paused);
+    mInfo->layer = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.layer);
+    mInfo->ownerPid = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.ownerPid);
+    mInfo->ownerUid = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.ownerUid);
+    mInfo->inputFeatures = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.inputFeatures);
+    mInfo->displayId = env->GetIntField(obj,
+            gInputWindowHandleClassInfo.displayId);
+
+    env->DeleteLocalRef(obj);
+    return true;
+}
+
+
+// --- Global functions ---
+
+sp<NativeInputWindowHandle> android_server_InputWindowHandle_getHandle(
+        JNIEnv* env, jobject inputWindowHandleObj) {
+    if (!inputWindowHandleObj) {
+        return NULL;
+    }
+
+    AutoMutex _l(gHandleMutex);
+
+    jlong ptr = env->GetLongField(inputWindowHandleObj, gInputWindowHandleClassInfo.ptr);
+    NativeInputWindowHandle* handle;
+    if (ptr) {
+        handle = reinterpret_cast<NativeInputWindowHandle*>(ptr);
+    } else {
+        jobject inputApplicationHandleObj = env->GetObjectField(inputWindowHandleObj,
+                gInputWindowHandleClassInfo.inputApplicationHandle);
+        sp<InputApplicationHandle> inputApplicationHandle =
+                android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
+        env->DeleteLocalRef(inputApplicationHandleObj);
+
+        jweak objWeak = env->NewWeakGlobalRef(inputWindowHandleObj);
+        handle = new NativeInputWindowHandle(inputApplicationHandle, objWeak);
+        handle->incStrong((void*)android_server_InputWindowHandle_getHandle);
+        env->SetLongField(inputWindowHandleObj, gInputWindowHandleClassInfo.ptr,
+                reinterpret_cast<jlong>(handle));
+    }
+    return handle;
+}
+
+
+// --- JNI ---
+
+static void android_server_InputWindowHandle_nativeDispose(JNIEnv* env, jobject obj) {
+    AutoMutex _l(gHandleMutex);
+
+    jlong ptr = env->GetLongField(obj, gInputWindowHandleClassInfo.ptr);
+    if (ptr) {
+        env->SetLongField(obj, gInputWindowHandleClassInfo.ptr, 0);
+
+        NativeInputWindowHandle* handle = reinterpret_cast<NativeInputWindowHandle*>(ptr);
+        handle->decStrong((void*)android_server_InputWindowHandle_getHandle);
+    }
+}
+
+
+static JNINativeMethod gInputWindowHandleMethods[] = {
+    /* name, signature, funcPtr */
+    { "nativeDispose", "()V",
+            (void*) android_server_InputWindowHandle_nativeDispose },
+};
+
+#define FIND_CLASS(var, className) \
+        var = env->FindClass(className); \
+        LOG_FATAL_IF(! var, "Unable to find class " className);
+
+#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
+        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
+        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
+
+int register_android_server_InputWindowHandle(JNIEnv* env) {
+    int res = jniRegisterNativeMethods(env, "com/android/server/input/InputWindowHandle",
+            gInputWindowHandleMethods, NELEM(gInputWindowHandleMethods));
+    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
+
+    jclass clazz;
+    FIND_CLASS(clazz, "com/android/server/input/InputWindowHandle");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.ptr, clazz,
+            "ptr", "J");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle,
+            clazz,
+            "inputApplicationHandle", "Lcom/android/server/input/InputApplicationHandle;");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.inputChannel, clazz,
+            "inputChannel", "Landroid/view/InputChannel;");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.name, clazz,
+            "name", "Ljava/lang/String;");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.layoutParamsFlags, clazz,
+            "layoutParamsFlags", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.layoutParamsPrivateFlags, clazz,
+            "layoutParamsPrivateFlags", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.layoutParamsType, clazz,
+            "layoutParamsType", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.dispatchingTimeoutNanos, clazz,
+            "dispatchingTimeoutNanos", "J");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.frameLeft, clazz,
+            "frameLeft", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.frameTop, clazz,
+            "frameTop", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.frameRight, clazz,
+            "frameRight", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.frameBottom, clazz,
+            "frameBottom", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.scaleFactor, clazz,
+            "scaleFactor", "F");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegion, clazz,
+            "touchableRegion", "Landroid/graphics/Region;");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.visible, clazz,
+            "visible", "Z");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.canReceiveKeys, clazz,
+            "canReceiveKeys", "Z");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.hasFocus, clazz,
+            "hasFocus", "Z");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.hasWallpaper, clazz,
+            "hasWallpaper", "Z");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.paused, clazz,
+            "paused", "Z");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.layer, clazz,
+            "layer", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.ownerPid, clazz,
+            "ownerPid", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.ownerUid, clazz,
+            "ownerUid", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.inputFeatures, clazz,
+            "inputFeatures", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.displayId, clazz,
+            "displayId", "I");
+    return 0;
+}
+
+} /* namespace android */
diff --git a/services/jni/com_android_server_input_InputWindowHandle.h b/services/core/jni/com_android_server_input_InputWindowHandle.h
similarity index 100%
rename from services/jni/com_android_server_input_InputWindowHandle.h
rename to services/core/jni/com_android_server_input_InputWindowHandle.h
diff --git a/services/core/jni/com_android_server_lights_LightsService.cpp b/services/core/jni/com_android_server_lights_LightsService.cpp
new file mode 100644
index 0000000..d51e044
--- /dev/null
+++ b/services/core/jni/com_android_server_lights_LightsService.cpp
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "LightsService"
+
+#include "jni.h"
+#include "JNIHelp.h"
+#include "android_runtime/AndroidRuntime.h"
+
+#include <utils/misc.h>
+#include <utils/Log.h>
+#include <hardware/hardware.h>
+#include <hardware/lights.h>
+
+#include <stdio.h>
+
+namespace android
+{
+
+// These values must correspond with the LIGHT_ID constants in
+// LightsService.java
+enum {
+    LIGHT_INDEX_BACKLIGHT = 0,
+    LIGHT_INDEX_KEYBOARD = 1,
+    LIGHT_INDEX_BUTTONS = 2,
+    LIGHT_INDEX_BATTERY = 3,
+    LIGHT_INDEX_NOTIFICATIONS = 4,
+    LIGHT_INDEX_ATTENTION = 5,
+    LIGHT_INDEX_BLUETOOTH = 6,
+    LIGHT_INDEX_WIFI = 7,
+    LIGHT_COUNT
+};
+
+struct Devices {
+    light_device_t* lights[LIGHT_COUNT];
+};
+
+static light_device_t* get_device(hw_module_t* module, char const* name)
+{
+    int err;
+    hw_device_t* device;
+    err = module->methods->open(module, name, &device);
+    if (err == 0) {
+        return (light_device_t*)device;
+    } else {
+        return NULL;
+    }
+}
+
+static jlong init_native(JNIEnv *env, jobject clazz)
+{
+    int err;
+    hw_module_t* module;
+    Devices* devices;
+    
+    devices = (Devices*)malloc(sizeof(Devices));
+
+    err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
+    if (err == 0) {
+        devices->lights[LIGHT_INDEX_BACKLIGHT]
+                = get_device(module, LIGHT_ID_BACKLIGHT);
+        devices->lights[LIGHT_INDEX_KEYBOARD]
+                = get_device(module, LIGHT_ID_KEYBOARD);
+        devices->lights[LIGHT_INDEX_BUTTONS]
+                = get_device(module, LIGHT_ID_BUTTONS);
+        devices->lights[LIGHT_INDEX_BATTERY]
+                = get_device(module, LIGHT_ID_BATTERY);
+        devices->lights[LIGHT_INDEX_NOTIFICATIONS]
+                = get_device(module, LIGHT_ID_NOTIFICATIONS);
+        devices->lights[LIGHT_INDEX_ATTENTION]
+                = get_device(module, LIGHT_ID_ATTENTION);
+        devices->lights[LIGHT_INDEX_BLUETOOTH]
+                = get_device(module, LIGHT_ID_BLUETOOTH);
+        devices->lights[LIGHT_INDEX_WIFI]
+                = get_device(module, LIGHT_ID_WIFI);
+    } else {
+        memset(devices, 0, sizeof(Devices));
+    }
+
+    return (jlong)devices;
+}
+
+static void finalize_native(JNIEnv *env, jobject clazz, jlong ptr)
+{
+    Devices* devices = (Devices*)ptr;
+    if (devices == NULL) {
+        return;
+    }
+
+    free(devices);
+}
+
+static void setLight_native(JNIEnv *env, jobject clazz, jlong ptr,
+        jint light, jint colorARGB, jint flashMode, jint onMS, jint offMS, jint brightnessMode)
+{
+    Devices* devices = (Devices*)ptr;
+    light_state_t state;
+
+    if (light < 0 || light >= LIGHT_COUNT || devices->lights[light] == NULL) {
+        return ;
+    }
+
+    memset(&state, 0, sizeof(light_state_t));
+    state.color = colorARGB;
+    state.flashMode = flashMode;
+    state.flashOnMS = onMS;
+    state.flashOffMS = offMS;
+    state.brightnessMode = brightnessMode;
+
+    {
+        ALOGD_IF_SLOW(50, "Excessive delay setting light");
+        devices->lights[light]->set_light(devices->lights[light], &state);
+    }
+}
+
+static JNINativeMethod method_table[] = {
+    { "init_native", "()J", (void*)init_native },
+    { "finalize_native", "(J)V", (void*)finalize_native },
+    { "setLight_native", "(JIIIIII)V", (void*)setLight_native },
+};
+
+int register_android_server_LightsService(JNIEnv *env)
+{
+    return jniRegisterNativeMethods(env, "com/android/server/lights/LightsService",
+            method_table, NELEM(method_table));
+}
+
+};
diff --git a/services/jni/com_android_server_location_FlpHardwareProvider.cpp b/services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
similarity index 100%
rename from services/jni/com_android_server_location_FlpHardwareProvider.cpp
rename to services/core/jni/com_android_server_location_FlpHardwareProvider.cpp
diff --git a/services/core/jni/com_android_server_location_GpsLocationProvider.cpp b/services/core/jni/com_android_server_location_GpsLocationProvider.cpp
new file mode 100644
index 0000000..e9ba116
--- /dev/null
+++ b/services/core/jni/com_android_server_location_GpsLocationProvider.cpp
@@ -0,0 +1,800 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "GpsLocationProvider"
+
+#define LOG_NDEBUG 0
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include "hardware/hardware.h"
+#include "hardware/gps.h"
+#include "hardware_legacy/power.h"
+#include "utils/Log.h"
+#include "utils/misc.h"
+#include "android_runtime/AndroidRuntime.h"
+#include "android_runtime/Log.h"
+
+#include <string.h>
+#include <pthread.h>
+
+static jobject mCallbacksObj = NULL;
+
+static jmethodID method_reportLocation;
+static jmethodID method_reportStatus;
+static jmethodID method_reportSvStatus;
+static jmethodID method_reportAGpsStatus;
+static jmethodID method_reportNmea;
+static jmethodID method_setEngineCapabilities;
+static jmethodID method_xtraDownloadRequest;
+static jmethodID method_reportNiNotification;
+static jmethodID method_requestRefLocation;
+static jmethodID method_requestSetID;
+static jmethodID method_requestUtcTime;
+static jmethodID method_reportGeofenceTransition;
+static jmethodID method_reportGeofenceStatus;
+static jmethodID method_reportGeofenceAddStatus;
+static jmethodID method_reportGeofenceRemoveStatus;
+static jmethodID method_reportGeofencePauseStatus;
+static jmethodID method_reportGeofenceResumeStatus;
+
+static const GpsInterface* sGpsInterface = NULL;
+static const GpsXtraInterface* sGpsXtraInterface = NULL;
+static const AGpsInterface* sAGpsInterface = NULL;
+static const GpsNiInterface* sGpsNiInterface = NULL;
+static const GpsDebugInterface* sGpsDebugInterface = NULL;
+static const AGpsRilInterface* sAGpsRilInterface = NULL;
+static const GpsGeofencingInterface* sGpsGeofencingInterface = NULL;
+
+// temporary storage for GPS callbacks
+static GpsSvStatus  sGpsSvStatus;
+static const char* sNmeaString;
+static int sNmeaStringLength;
+
+#define WAKE_LOCK_NAME  "GPS"
+
+namespace android {
+
+static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
+    if (env->ExceptionCheck()) {
+        ALOGE("An exception was thrown by callback '%s'.", methodName);
+        LOGE_EX(env);
+        env->ExceptionClear();
+    }
+}
+
+static void location_callback(GpsLocation* location)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags,
+            (jdouble)location->latitude, (jdouble)location->longitude,
+            (jdouble)location->altitude,
+            (jfloat)location->speed, (jfloat)location->bearing,
+            (jfloat)location->accuracy, (jlong)location->timestamp);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static void status_callback(GpsStatus* status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static void sv_status_callback(GpsSvStatus* sv_status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    memcpy(&sGpsSvStatus, sv_status, sizeof(sGpsSvStatus));
+    env->CallVoidMethod(mCallbacksObj, method_reportSvStatus);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    // The Java code will call back to read these values
+    // We do this to avoid creating unnecessary String objects
+    sNmeaString = nmea;
+    sNmeaStringLength = length;
+    env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static void set_capabilities_callback(uint32_t capabilities)
+{
+    ALOGD("set_capabilities_callback: %du\n", capabilities);
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static void acquire_wakelock_callback()
+{
+    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
+}
+
+static void release_wakelock_callback()
+{
+    release_wake_lock(WAKE_LOCK_NAME);
+}
+
+static void request_utc_time_callback()
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_requestUtcTime);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg)
+{
+    return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg);
+}
+
+GpsCallbacks sGpsCallbacks = {
+    sizeof(GpsCallbacks),
+    location_callback,
+    status_callback,
+    sv_status_callback,
+    nmea_callback,
+    set_capabilities_callback,
+    acquire_wakelock_callback,
+    release_wakelock_callback,
+    create_thread_callback,
+    request_utc_time_callback,
+};
+
+static void xtra_download_request_callback()
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+GpsXtraCallbacks sGpsXtraCallbacks = {
+    xtra_download_request_callback,
+    create_thread_callback,
+};
+
+static void agps_status_callback(AGpsStatus* agps_status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+
+    uint32_t ipaddr;
+    // ipaddr field was not included in original AGpsStatus
+    if (agps_status->size >= sizeof(AGpsStatus))
+        ipaddr = agps_status->ipaddr;
+    else
+        ipaddr = 0xFFFFFFFF;
+    env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus,
+                        agps_status->type, agps_status->status, ipaddr);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+AGpsCallbacks sAGpsCallbacks = {
+    agps_status_callback,
+    create_thread_callback,
+};
+
+static void gps_ni_notify_callback(GpsNiNotification *notification)
+{
+    ALOGD("gps_ni_notify_callback\n");
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jstring requestor_id = env->NewStringUTF(notification->requestor_id);
+    jstring text = env->NewStringUTF(notification->text);
+    jstring extras = env->NewStringUTF(notification->extras);
+
+    if (requestor_id && text && extras) {
+        env->CallVoidMethod(mCallbacksObj, method_reportNiNotification,
+            notification->notification_id, notification->ni_type,
+            notification->notify_flags, notification->timeout,
+            notification->default_response, requestor_id, text,
+            notification->requestor_id_encoding,
+            notification->text_encoding, extras);
+    } else {
+        ALOGE("out of memory in gps_ni_notify_callback\n");
+    }
+
+    if (requestor_id)
+        env->DeleteLocalRef(requestor_id);
+    if (text)
+        env->DeleteLocalRef(text);
+    if (extras)
+        env->DeleteLocalRef(extras);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+GpsNiCallbacks sGpsNiCallbacks = {
+    gps_ni_notify_callback,
+    create_thread_callback,
+};
+
+static void agps_request_set_id(uint32_t flags)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+static void agps_request_ref_location(uint32_t flags)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+}
+
+AGpsRilCallbacks sAGpsRilCallbacks = {
+    agps_request_set_id,
+    agps_request_ref_location,
+    create_thread_callback,
+};
+
+static void gps_geofence_transition_callback(int32_t geofence_id,  GpsLocation* location,
+        int32_t transition, GpsUtcTime timestamp)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+
+    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceTransition, geofence_id,
+            location->flags, (jdouble)location->latitude, (jdouble)location->longitude,
+            (jdouble)location->altitude,
+            (jfloat)location->speed, (jfloat)location->bearing,
+            (jfloat)location->accuracy, (jlong)location->timestamp,
+            transition, timestamp);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+};
+
+static void gps_geofence_status_callback(int32_t status, GpsLocation* location)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    jint flags = 0;
+    jdouble latitude = 0;
+    jdouble longitude = 0;
+    jdouble altitude = 0;
+    jfloat speed = 0;
+    jfloat bearing = 0;
+    jfloat accuracy = 0;
+    jlong timestamp = 0;
+    if (location != NULL) {
+        flags = location->flags;
+        latitude = location->latitude;
+        longitude = location->longitude;
+        altitude = location->altitude;
+        speed = location->speed;
+        bearing = location->bearing;
+        accuracy = location->accuracy;
+        timestamp = location->timestamp;
+    }
+
+    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceStatus, status,
+            flags, latitude, longitude, altitude, speed, bearing, accuracy, timestamp);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+};
+
+static void gps_geofence_add_callback(int32_t geofence_id, int32_t status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
+        ALOGE("Error in geofence_add_callback: %d\n", status);
+    }
+    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceAddStatus, geofence_id, status);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+};
+
+static void gps_geofence_remove_callback(int32_t geofence_id, int32_t status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
+        ALOGE("Error in geofence_remove_callback: %d\n", status);
+    }
+    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceRemoveStatus, geofence_id, status);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+};
+
+static void gps_geofence_resume_callback(int32_t geofence_id, int32_t status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
+        ALOGE("Error in geofence_resume_callback: %d\n", status);
+    }
+    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceResumeStatus, geofence_id, status);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+};
+
+static void gps_geofence_pause_callback(int32_t geofence_id, int32_t status)
+{
+    JNIEnv* env = AndroidRuntime::getJNIEnv();
+    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
+        ALOGE("Error in geofence_pause_callback: %d\n", status);
+    }
+    env->CallVoidMethod(mCallbacksObj, method_reportGeofencePauseStatus, geofence_id, status);
+    checkAndClearExceptionFromCallback(env, __FUNCTION__);
+};
+
+GpsGeofenceCallbacks sGpsGeofenceCallbacks = {
+    gps_geofence_transition_callback,
+    gps_geofence_status_callback,
+    gps_geofence_add_callback,
+    gps_geofence_remove_callback,
+    gps_geofence_pause_callback,
+    gps_geofence_resume_callback,
+    create_thread_callback,
+};
+
+static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) {
+    int err;
+    hw_module_t* module;
+
+    method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V");
+    method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
+    method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V");
+    method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(III)V");
+    method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V");
+    method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V");
+    method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
+    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification",
+            "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");
+    method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V");
+    method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V");
+    method_requestUtcTime = env->GetMethodID(clazz,"requestUtcTime","()V");
+    method_reportGeofenceTransition = env->GetMethodID(clazz,"reportGeofenceTransition",
+            "(IIDDDFFFJIJ)V");
+    method_reportGeofenceStatus = env->GetMethodID(clazz,"reportGeofenceStatus",
+            "(IIDDDFFFJ)V");
+    method_reportGeofenceAddStatus = env->GetMethodID(clazz,"reportGeofenceAddStatus",
+            "(II)V");
+    method_reportGeofenceRemoveStatus = env->GetMethodID(clazz,"reportGeofenceRemoveStatus",
+            "(II)V");
+    method_reportGeofenceResumeStatus = env->GetMethodID(clazz,"reportGeofenceResumeStatus",
+            "(II)V");
+    method_reportGeofencePauseStatus = env->GetMethodID(clazz,"reportGeofencePauseStatus",
+            "(II)V");
+
+    err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
+    if (err == 0) {
+        hw_device_t* device;
+        err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
+        if (err == 0) {
+            gps_device_t* gps_device = (gps_device_t *)device;
+            sGpsInterface = gps_device->get_gps_interface(gps_device);
+        }
+    }
+    if (sGpsInterface) {
+        sGpsXtraInterface =
+            (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE);
+        sAGpsInterface =
+            (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+        sGpsNiInterface =
+            (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
+        sGpsDebugInterface =
+            (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE);
+        sAGpsRilInterface =
+            (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE);
+        sGpsGeofencingInterface =
+            (const GpsGeofencingInterface*)sGpsInterface->get_extension(GPS_GEOFENCING_INTERFACE);
+    }
+}
+
+static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
+    if (sGpsInterface != NULL) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
+}
+
+static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj)
+{
+    // this must be set before calling into the HAL library
+    if (!mCallbacksObj)
+        mCallbacksObj = env->NewGlobalRef(obj);
+
+    // fail if the main interface fails to initialize
+    if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
+        return JNI_FALSE;
+
+    // if XTRA initialization fails we will disable it by sGpsXtraInterface to NULL,
+    // but continue to allow the rest of the GPS interface to work.
+    if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0)
+        sGpsXtraInterface = NULL;
+    if (sAGpsInterface)
+        sAGpsInterface->init(&sAGpsCallbacks);
+    if (sGpsNiInterface)
+        sGpsNiInterface->init(&sGpsNiCallbacks);
+    if (sAGpsRilInterface)
+        sAGpsRilInterface->init(&sAGpsRilCallbacks);
+    if (sGpsGeofencingInterface)
+        sGpsGeofencingInterface->init(&sGpsGeofenceCallbacks);
+
+    return JNI_TRUE;
+}
+
+static void android_location_GpsLocationProvider_cleanup(JNIEnv* env, jobject obj)
+{
+    if (sGpsInterface)
+        sGpsInterface->cleanup();
+}
+
+static jboolean android_location_GpsLocationProvider_set_position_mode(JNIEnv* env, jobject obj,
+        jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, jint preferred_time)
+{
+    if (sGpsInterface) {
+        if (sGpsInterface->set_position_mode(mode, recurrence, min_interval, preferred_accuracy,
+                preferred_time) == 0) {
+            return JNI_TRUE;
+        } else {
+            return JNI_FALSE;
+        }
+    }
+    else
+        return JNI_FALSE;
+}
+
+static jboolean android_location_GpsLocationProvider_start(JNIEnv* env, jobject obj)
+{
+    if (sGpsInterface) {
+        if (sGpsInterface->start() == 0) {
+            return JNI_TRUE;
+        } else {
+            return JNI_FALSE;
+        }
+    }
+    else
+        return JNI_FALSE;
+}
+
+static jboolean android_location_GpsLocationProvider_stop(JNIEnv* env, jobject obj)
+{
+    if (sGpsInterface) {
+        if (sGpsInterface->stop() == 0) {
+            return JNI_TRUE;
+        } else {
+            return JNI_FALSE;
+        }
+    }
+    else
+        return JNI_FALSE;
+}
+
+static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* env, jobject obj, jint flags)
+{
+    if (sGpsInterface)
+        sGpsInterface->delete_aiding_data(flags);
+}
+
+static jint android_location_GpsLocationProvider_read_sv_status(JNIEnv* env, jobject obj,
+        jintArray prnArray, jfloatArray snrArray, jfloatArray elevArray, jfloatArray azumArray,
+        jintArray maskArray)
+{
+    // this should only be called from within a call to reportSvStatus
+
+    jint* prns = env->GetIntArrayElements(prnArray, 0);
+    jfloat* snrs = env->GetFloatArrayElements(snrArray, 0);
+    jfloat* elev = env->GetFloatArrayElements(elevArray, 0);
+    jfloat* azim = env->GetFloatArrayElements(azumArray, 0);
+    jint* mask = env->GetIntArrayElements(maskArray, 0);
+
+    int num_svs = sGpsSvStatus.num_svs;
+    for (int i = 0; i < num_svs; i++) {
+        prns[i] = sGpsSvStatus.sv_list[i].prn;
+        snrs[i] = sGpsSvStatus.sv_list[i].snr;
+        elev[i] = sGpsSvStatus.sv_list[i].elevation;
+        azim[i] = sGpsSvStatus.sv_list[i].azimuth;
+    }
+    mask[0] = sGpsSvStatus.ephemeris_mask;
+    mask[1] = sGpsSvStatus.almanac_mask;
+    mask[2] = sGpsSvStatus.used_in_fix_mask;
+
+    env->ReleaseIntArrayElements(prnArray, prns, 0);
+    env->ReleaseFloatArrayElements(snrArray, snrs, 0);
+    env->ReleaseFloatArrayElements(elevArray, elev, 0);
+    env->ReleaseFloatArrayElements(azumArray, azim, 0);
+    env->ReleaseIntArrayElements(maskArray, mask, 0);
+    return (jint) num_svs;
+}
+
+static void android_location_GpsLocationProvider_agps_set_reference_location_cellid(JNIEnv* env,
+        jobject obj, jint type, jint mcc, jint mnc, jint lac, jint cid)
+{
+    AGpsRefLocation location;
+
+    if (!sAGpsRilInterface) {
+        ALOGE("no AGPS RIL interface in agps_set_reference_location_cellid");
+        return;
+    }
+
+    switch(type) {
+        case AGPS_REF_LOCATION_TYPE_GSM_CELLID:
+        case AGPS_REF_LOCATION_TYPE_UMTS_CELLID:
+            location.type = type;
+            location.u.cellID.mcc = mcc;
+            location.u.cellID.mnc = mnc;
+            location.u.cellID.lac = lac;
+            location.u.cellID.cid = cid;
+            break;
+        default:
+            ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__);
+            return;
+            break;
+    }
+    sAGpsRilInterface->set_ref_location(&location, sizeof(location));
+}
+
+static void android_location_GpsLocationProvider_agps_send_ni_message(JNIEnv* env,
+        jobject obj, jbyteArray ni_msg, jint size)
+{
+    size_t sz;
+
+    if (!sAGpsRilInterface) {
+        ALOGE("no AGPS RIL interface in send_ni_message");
+        return;
+    }
+    if (size < 0)
+        return;
+    sz = (size_t)size;
+    jbyte* b = env->GetByteArrayElements(ni_msg, 0);
+    sAGpsRilInterface->ni_message((uint8_t *)b,sz);
+    env->ReleaseByteArrayElements(ni_msg,b,0);
+}
+
+static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *env,
+        jobject obj, jint type, jstring  setid_string)
+{
+    if (!sAGpsRilInterface) {
+        ALOGE("no AGPS RIL interface in agps_set_id");
+        return;
+    }
+
+    const char *setid = env->GetStringUTFChars(setid_string, NULL);
+    sAGpsRilInterface->set_set_id(type, setid);
+    env->ReleaseStringUTFChars(setid_string, setid);
+}
+
+static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env, jobject obj,
+                                            jbyteArray nmeaArray, jint buffer_size)
+{
+    // this should only be called from within a call to reportNmea
+    jbyte* nmea = (jbyte *)env->GetPrimitiveArrayCritical(nmeaArray, 0);
+    int length = sNmeaStringLength;
+    if (length > buffer_size)
+        length = buffer_size;
+    memcpy(nmea, sNmeaString, length);
+    env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT);
+    return (jint) length;
+}
+
+static void android_location_GpsLocationProvider_inject_time(JNIEnv* env, jobject obj,
+        jlong time, jlong timeReference, jint uncertainty)
+{
+    if (sGpsInterface)
+        sGpsInterface->inject_time(time, timeReference, uncertainty);
+}
+
+static void android_location_GpsLocationProvider_inject_location(JNIEnv* env, jobject obj,
+        jdouble latitude, jdouble longitude, jfloat accuracy)
+{
+    if (sGpsInterface)
+        sGpsInterface->inject_location(latitude, longitude, accuracy);
+}
+
+static jboolean android_location_GpsLocationProvider_supports_xtra(JNIEnv* env, jobject obj)
+{
+    if (sGpsXtraInterface != NULL) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
+}
+
+static void android_location_GpsLocationProvider_inject_xtra_data(JNIEnv* env, jobject obj,
+        jbyteArray data, jint length)
+{
+    if (!sGpsXtraInterface) {
+        ALOGE("no XTRA interface in inject_xtra_data");
+        return;
+    }
+
+    jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0);
+    sGpsXtraInterface->inject_xtra_data((char *)bytes, length);
+    env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT);
+}
+
+static void android_location_GpsLocationProvider_agps_data_conn_open(JNIEnv* env, jobject obj, jstring apn)
+{
+    if (!sAGpsInterface) {
+        ALOGE("no AGPS interface in agps_data_conn_open");
+        return;
+    }
+    if (apn == NULL) {
+        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
+        return;
+    }
+    const char *apnStr = env->GetStringUTFChars(apn, NULL);
+    sAGpsInterface->data_conn_open(apnStr);
+    env->ReleaseStringUTFChars(apn, apnStr);
+}
+
+static void android_location_GpsLocationProvider_agps_data_conn_closed(JNIEnv* env, jobject obj)
+{
+    if (!sAGpsInterface) {
+        ALOGE("no AGPS interface in agps_data_conn_closed");
+        return;
+    }
+    sAGpsInterface->data_conn_closed();
+}
+
+static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* env, jobject obj)
+{
+    if (!sAGpsInterface) {
+        ALOGE("no AGPS interface in agps_data_conn_failed");
+        return;
+    }
+    sAGpsInterface->data_conn_failed();
+}
+
+static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject obj,
+        jint type, jstring hostname, jint port)
+{
+    if (!sAGpsInterface) {
+        ALOGE("no AGPS interface in set_agps_server");
+        return;
+    }
+    const char *c_hostname = env->GetStringUTFChars(hostname, NULL);
+    sAGpsInterface->set_server(type, c_hostname, port);
+    env->ReleaseStringUTFChars(hostname, c_hostname);
+}
+
+static void android_location_GpsLocationProvider_send_ni_response(JNIEnv* env, jobject obj,
+      jint notifId, jint response)
+{
+    if (!sGpsNiInterface) {
+        ALOGE("no NI interface in send_ni_response");
+        return;
+    }
+
+    sGpsNiInterface->respond(notifId, response);
+}
+
+static jstring android_location_GpsLocationProvider_get_internal_state(JNIEnv* env, jobject obj)
+{
+    jstring result = NULL;
+    if (sGpsDebugInterface) {
+        const size_t maxLength = 2047;
+        char buffer[maxLength+1];
+        size_t length = sGpsDebugInterface->get_internal_state(buffer, maxLength);
+        if (length > maxLength) length = maxLength;
+        buffer[length] = 0;
+        result = env->NewStringUTF(buffer);
+    }
+    return result;
+}
+
+static void android_location_GpsLocationProvider_update_network_state(JNIEnv* env, jobject obj,
+        jboolean connected, jint type, jboolean roaming, jboolean available, jstring extraInfo, jstring apn)
+{
+
+    if (sAGpsRilInterface && sAGpsRilInterface->update_network_state) {
+        if (extraInfo) {
+            const char *extraInfoStr = env->GetStringUTFChars(extraInfo, NULL);
+            sAGpsRilInterface->update_network_state(connected, type, roaming, extraInfoStr);
+            env->ReleaseStringUTFChars(extraInfo, extraInfoStr);
+        } else {
+            sAGpsRilInterface->update_network_state(connected, type, roaming, NULL);
+        }
+
+        // update_network_availability callback was not included in original AGpsRilInterface
+        if (sAGpsRilInterface->size >= sizeof(AGpsRilInterface)
+                && sAGpsRilInterface->update_network_availability) {
+            const char *c_apn = env->GetStringUTFChars(apn, NULL);
+            sAGpsRilInterface->update_network_availability(available, c_apn);
+            env->ReleaseStringUTFChars(apn, c_apn);
+        }
+    }
+}
+
+static jboolean android_location_GpsLocationProvider_is_geofence_supported(JNIEnv* env,
+          jobject obj) {
+    if (sGpsGeofencingInterface != NULL) {
+        return JNI_TRUE;
+    }
+    return JNI_FALSE;
+}
+
+static jboolean android_location_GpsLocationProvider_add_geofence(JNIEnv* env, jobject obj,
+        jint geofence_id, jdouble latitude, jdouble longitude, jdouble radius,
+        jint last_transition, jint monitor_transition, jint notification_responsiveness,
+        jint unknown_timer) {
+    if (sGpsGeofencingInterface != NULL) {
+        sGpsGeofencingInterface->add_geofence_area(geofence_id, latitude, longitude,
+                radius, last_transition, monitor_transition, notification_responsiveness,
+                unknown_timer);
+        return JNI_TRUE;
+    } else {
+        ALOGE("Geofence interface not available");
+    }
+    return JNI_FALSE;
+}
+
+static jboolean android_location_GpsLocationProvider_remove_geofence(JNIEnv* env, jobject obj,
+        jint geofence_id) {
+    if (sGpsGeofencingInterface != NULL) {
+        sGpsGeofencingInterface->remove_geofence_area(geofence_id);
+        return JNI_TRUE;
+    } else {
+        ALOGE("Geofence interface not available");
+    }
+    return JNI_FALSE;
+}
+
+static jboolean android_location_GpsLocationProvider_pause_geofence(JNIEnv* env, jobject obj,
+        jint geofence_id) {
+    if (sGpsGeofencingInterface != NULL) {
+        sGpsGeofencingInterface->pause_geofence(geofence_id);
+        return JNI_TRUE;
+    } else {
+        ALOGE("Geofence interface not available");
+    }
+    return JNI_FALSE;
+}
+
+static jboolean android_location_GpsLocationProvider_resume_geofence(JNIEnv* env, jobject obj,
+        jint geofence_id, jint monitor_transition) {
+    if (sGpsGeofencingInterface != NULL) {
+        sGpsGeofencingInterface->resume_geofence(geofence_id, monitor_transition);
+        return JNI_TRUE;
+    } else {
+        ALOGE("Geofence interface not available");
+    }
+    return JNI_FALSE;
+}
+
+static JNINativeMethod sMethods[] = {
+     /* name, signature, funcPtr */
+    {"class_init_native", "()V", (void *)android_location_GpsLocationProvider_class_init_native},
+    {"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported},
+    {"native_init", "()Z", (void*)android_location_GpsLocationProvider_init},
+    {"native_cleanup", "()V", (void*)android_location_GpsLocationProvider_cleanup},
+    {"native_set_position_mode", "(IIIII)Z", (void*)android_location_GpsLocationProvider_set_position_mode},
+    {"native_start", "()Z", (void*)android_location_GpsLocationProvider_start},
+    {"native_stop", "()Z", (void*)android_location_GpsLocationProvider_stop},
+    {"native_delete_aiding_data", "(I)V", (void*)android_location_GpsLocationProvider_delete_aiding_data},
+    {"native_read_sv_status", "([I[F[F[F[I)I", (void*)android_location_GpsLocationProvider_read_sv_status},
+    {"native_read_nmea", "([BI)I", (void*)android_location_GpsLocationProvider_read_nmea},
+    {"native_inject_time", "(JJI)V", (void*)android_location_GpsLocationProvider_inject_time},
+    {"native_inject_location", "(DDF)V", (void*)android_location_GpsLocationProvider_inject_location},
+    {"native_supports_xtra", "()Z", (void*)android_location_GpsLocationProvider_supports_xtra},
+    {"native_inject_xtra_data", "([BI)V", (void*)android_location_GpsLocationProvider_inject_xtra_data},
+    {"native_agps_data_conn_open", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open},
+    {"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed},
+    {"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed},
+    {"native_agps_set_id","(ILjava/lang/String;)V",(void*)android_location_GpsLocationProvider_agps_set_id},
+    {"native_agps_set_ref_location_cellid","(IIIII)V",(void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid},
+    {"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server},
+    {"native_send_ni_response", "(II)V", (void*)android_location_GpsLocationProvider_send_ni_response},
+    {"native_agps_ni_message", "([BI)V", (void *)android_location_GpsLocationProvider_agps_send_ni_message},
+    {"native_get_internal_state", "()Ljava/lang/String;", (void*)android_location_GpsLocationProvider_get_internal_state},
+    {"native_update_network_state", "(ZIZZLjava/lang/String;Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_update_network_state },
+    {"native_is_geofence_supported", "()Z", (void*) android_location_GpsLocationProvider_is_geofence_supported},
+    {"native_add_geofence", "(IDDDIIII)Z", (void *)android_location_GpsLocationProvider_add_geofence},
+    {"native_remove_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_remove_geofence},
+    {"native_pause_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_pause_geofence},
+    {"native_resume_geofence", "(II)Z", (void *)android_location_GpsLocationProvider_resume_geofence}
+};
+
+int register_android_server_location_GpsLocationProvider(JNIEnv* env)
+{
+    return jniRegisterNativeMethods(env, "com/android/server/location/GpsLocationProvider", sMethods, NELEM(sMethods));
+}
+
+} /* namespace android */
diff --git a/services/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp
similarity index 100%
rename from services/jni/com_android_server_power_PowerManagerService.cpp
rename to services/core/jni/com_android_server_power_PowerManagerService.cpp
diff --git a/services/jni/com_android_server_power_PowerManagerService.h b/services/core/jni/com_android_server_power_PowerManagerService.h
similarity index 100%
rename from services/jni/com_android_server_power_PowerManagerService.h
rename to services/core/jni/com_android_server_power_PowerManagerService.h
diff --git a/services/core/jni/onload.cpp b/services/core/jni/onload.cpp
new file mode 100644
index 0000000..00986d5
--- /dev/null
+++ b/services/core/jni/onload.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#include "JNIHelp.h"
+#include "jni.h"
+#include "utils/Log.h"
+#include "utils/misc.h"
+
+namespace android {
+int register_android_server_AlarmManagerService(JNIEnv* env);
+int register_android_server_ConsumerIrService(JNIEnv *env);
+int register_android_server_InputApplicationHandle(JNIEnv* env);
+int register_android_server_InputWindowHandle(JNIEnv* env);
+int register_android_server_InputManager(JNIEnv* env);
+int register_android_server_LightsService(JNIEnv* env);
+int register_android_server_PowerManagerService(JNIEnv* env);
+int register_android_server_SerialService(JNIEnv* env);
+int register_android_server_UsbDeviceManager(JNIEnv* env);
+int register_android_server_UsbHostManager(JNIEnv* env);
+int register_android_server_VibratorService(JNIEnv* env);
+int register_android_server_SystemServer(JNIEnv* env);
+int register_android_server_location_GpsLocationProvider(JNIEnv* env);
+int register_android_server_location_FlpHardwareProvider(JNIEnv* env);
+int register_android_server_connectivity_Vpn(JNIEnv* env);
+int register_android_server_AssetAtlasService(JNIEnv* env);
+int register_android_server_dreams_McuHal(JNIEnv* env);
+};
+
+using namespace android;
+
+extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
+{
+    JNIEnv* env = NULL;
+    jint result = -1;
+
+    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
+        ALOGE("GetEnv failed!");
+        return result;
+    }
+    ALOG_ASSERT(env, "Could not retrieve the env!");
+
+    register_android_server_PowerManagerService(env);
+    register_android_server_SerialService(env);
+    register_android_server_InputApplicationHandle(env);
+    register_android_server_InputWindowHandle(env);
+    register_android_server_InputManager(env);
+    register_android_server_LightsService(env);
+    register_android_server_AlarmManagerService(env);
+    register_android_server_UsbDeviceManager(env);
+    register_android_server_UsbHostManager(env);
+    register_android_server_VibratorService(env);
+    register_android_server_SystemServer(env);
+    register_android_server_location_GpsLocationProvider(env);
+    register_android_server_location_FlpHardwareProvider(env);
+    register_android_server_connectivity_Vpn(env);
+    register_android_server_AssetAtlasService(env);
+    register_android_server_ConsumerIrService(env);
+    register_android_server_dreams_McuHal(env);
+
+    return JNI_VERSION_1_4;
+}
diff --git a/services/devicepolicy/Android.mk b/services/devicepolicy/Android.mk
new file mode 100644
index 0000000..a55d138
--- /dev/null
+++ b/services/devicepolicy/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.devicepolicy
+
+LOCAL_SRC_FILES += \
+      $(call all-java-files-under,java)
+
+LOCAL_JAVA_LIBRARIES := conscrypt
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
new file mode 100644
index 0000000..296d852
--- /dev/null
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -0,0 +1,2990 @@
+/*
+ * Copyright (C) 2010 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.devicepolicy;
+
+import static android.Manifest.permission.MANAGE_CA_CERTIFICATES;
+
+import com.android.internal.R;
+import com.android.internal.os.storage.ExternalStorageFormatter;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.JournaledFile;
+import com.android.internal.util.XmlUtils;
+import com.android.internal.widget.LockPatternUtils;
+import com.android.org.conscrypt.TrustedCertificateStore;
+import com.android.server.SystemService;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.app.Activity;
+import android.app.ActivityManagerNative;
+import android.app.AlarmManager;
+import android.app.AppGlobals;
+import android.app.INotificationManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.admin.DeviceAdminInfo;
+import android.app.admin.DeviceAdminReceiver;
+import android.app.admin.DevicePolicyManager;
+import android.app.admin.IDevicePolicyManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.IPackageManager;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.Signature;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.pm.UserInfo;
+import android.net.ProxyProperties;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.IPowerManager;
+import android.os.PowerManager;
+import android.os.Process;
+import android.os.RecoverySystem;
+import android.os.RemoteCallback;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.security.Credentials;
+import android.security.IKeyChainService;
+import android.security.KeyChain;
+import android.security.KeyChain.KeyChainConnection;
+import android.util.AtomicFile;
+import android.util.Log;
+import android.util.PrintWriterPrinter;
+import android.util.Printer;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.Xml;
+import android.view.IWindowManager;
+import android.view.WindowManagerPolicy;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.security.KeyStore.TrustedCertificateEntry;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Implementation of the device policy APIs.
+ */
+public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
+
+    private static final String LOG_TAG = "DevicePolicyManagerService";
+
+    private static final String DEVICE_POLICIES_XML = "device_policies.xml";
+
+    private static final int REQUEST_EXPIRE_PASSWORD = 5571;
+
+    private static final long MS_PER_DAY = 86400 * 1000;
+
+    private static final long EXPIRATION_GRACE_PERIOD_MS = 5 * MS_PER_DAY; // 5 days, in ms
+
+    protected static final String ACTION_EXPIRED_PASSWORD_NOTIFICATION
+            = "com.android.server.ACTION_EXPIRED_PASSWORD_NOTIFICATION";
+
+    private static final int MONITORING_CERT_NOTIFICATION_ID = R.string.ssl_ca_cert_warning;
+
+    private static final boolean DBG = false;
+
+    final Context mContext;
+    final PowerManager.WakeLock mWakeLock;
+
+    IPowerManager mIPowerManager;
+    IWindowManager mIWindowManager;
+    NotificationManager mNotificationManager;
+
+    private DeviceOwner mDeviceOwner;
+
+    /**
+     * Whether or not device admin feature is supported. If it isn't return defaults for all
+     * public methods.
+     */
+    private boolean mHasFeature;
+
+    public static final class Lifecycle extends SystemService {
+        private DevicePolicyManagerService mService;
+
+        public Lifecycle(Context context) {
+            super(context);
+            mService = new DevicePolicyManagerService(context);
+        }
+
+        @Override
+        public void onStart() {
+            publishBinderService(Context.DEVICE_POLICY_SERVICE, mService);
+        }
+
+        @Override
+        public void onBootPhase(int phase) {
+            if (phase == PHASE_LOCK_SETTINGS_READY) {
+                mService.systemReady();
+            }
+        }
+    }
+    public static class DevicePolicyData {
+        int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+        int mActivePasswordLength = 0;
+        int mActivePasswordUpperCase = 0;
+        int mActivePasswordLowerCase = 0;
+        int mActivePasswordLetters = 0;
+        int mActivePasswordNumeric = 0;
+        int mActivePasswordSymbols = 0;
+        int mActivePasswordNonLetter = 0;
+        int mFailedPasswordAttempts = 0;
+
+        int mUserHandle;;
+        int mPasswordOwner = -1;
+        long mLastMaximumTimeToLock = -1;
+
+        final HashMap<ComponentName, ActiveAdmin> mAdminMap
+                = new HashMap<ComponentName, ActiveAdmin>();
+        final ArrayList<ActiveAdmin> mAdminList
+                = new ArrayList<ActiveAdmin>();
+
+        public DevicePolicyData(int userHandle) {
+            mUserHandle = userHandle;
+        }
+    }
+
+    final SparseArray<DevicePolicyData> mUserData = new SparseArray<DevicePolicyData>();
+
+    Handler mHandler = new Handler();
+
+    BroadcastReceiver mReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final String action = intent.getAction();
+            final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
+                    getSendingUserId());
+            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
+                    || ACTION_EXPIRED_PASSWORD_NOTIFICATION.equals(action)) {
+                if (DBG) Slog.v(LOG_TAG, "Sending password expiration notifications for action "
+                        + action + " for user " + userHandle);
+                mHandler.post(new Runnable() {
+                    public void run() {
+                        handlePasswordExpirationNotification(getUserData(userHandle));
+                    }
+                });
+            }
+            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
+                    || KeyChain.ACTION_STORAGE_CHANGED.equals(action)) {
+                manageMonitoringCertificateNotification(intent);
+            }
+            if (Intent.ACTION_USER_REMOVED.equals(action)) {
+                removeUserData(userHandle);
+            } else if (Intent.ACTION_USER_STARTED.equals(action)
+                    || Intent.ACTION_PACKAGE_CHANGED.equals(action)
+                    || Intent.ACTION_PACKAGE_REMOVED.equals(action)
+                    || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
+
+                if (Intent.ACTION_USER_STARTED.equals(action)) {
+                    // Reset the policy data
+                    synchronized (DevicePolicyManagerService.this) {
+                        mUserData.remove(userHandle);
+                    }
+                }
+
+                handlePackagesChanged(userHandle);
+            }
+        }
+    };
+
+    static class ActiveAdmin {
+        private static final String TAG_DISABLE_KEYGUARD_FEATURES = "disable-keyguard-features";
+        private static final String TAG_DISABLE_CAMERA = "disable-camera";
+        private static final String TAG_ENCRYPTION_REQUESTED = "encryption-requested";
+        private static final String TAG_PASSWORD_EXPIRATION_DATE = "password-expiration-date";
+        private static final String TAG_PASSWORD_EXPIRATION_TIMEOUT = "password-expiration-timeout";
+        private static final String TAG_GLOBAL_PROXY_EXCLUSION_LIST = "global-proxy-exclusion-list";
+        private static final String TAG_GLOBAL_PROXY_SPEC = "global-proxy-spec";
+        private static final String TAG_SPECIFIES_GLOBAL_PROXY = "specifies-global-proxy";
+        private static final String TAG_MAX_FAILED_PASSWORD_WIPE = "max-failed-password-wipe";
+        private static final String TAG_MAX_TIME_TO_UNLOCK = "max-time-to-unlock";
+        private static final String TAG_MIN_PASSWORD_NONLETTER = "min-password-nonletter";
+        private static final String TAG_MIN_PASSWORD_SYMBOLS = "min-password-symbols";
+        private static final String TAG_MIN_PASSWORD_NUMERIC = "min-password-numeric";
+        private static final String TAG_MIN_PASSWORD_LETTERS = "min-password-letters";
+        private static final String TAG_MIN_PASSWORD_LOWERCASE = "min-password-lowercase";
+        private static final String TAG_MIN_PASSWORD_UPPERCASE = "min-password-uppercase";
+        private static final String TAG_PASSWORD_HISTORY_LENGTH = "password-history-length";
+        private static final String TAG_MIN_PASSWORD_LENGTH = "min-password-length";
+        private static final String ATTR_VALUE = "value";
+        private static final String TAG_PASSWORD_QUALITY = "password-quality";
+        private static final String TAG_POLICIES = "policies";
+
+        final DeviceAdminInfo info;
+
+        int passwordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+
+        static final int DEF_MINIMUM_PASSWORD_LENGTH = 0;
+        int minimumPasswordLength = DEF_MINIMUM_PASSWORD_LENGTH;
+
+        static final int DEF_PASSWORD_HISTORY_LENGTH = 0;
+        int passwordHistoryLength = DEF_PASSWORD_HISTORY_LENGTH;
+
+        static final int DEF_MINIMUM_PASSWORD_UPPER_CASE = 0;
+        int minimumPasswordUpperCase = DEF_MINIMUM_PASSWORD_UPPER_CASE;
+
+        static final int DEF_MINIMUM_PASSWORD_LOWER_CASE = 0;
+        int minimumPasswordLowerCase = DEF_MINIMUM_PASSWORD_LOWER_CASE;
+
+        static final int DEF_MINIMUM_PASSWORD_LETTERS = 1;
+        int minimumPasswordLetters = DEF_MINIMUM_PASSWORD_LETTERS;
+
+        static final int DEF_MINIMUM_PASSWORD_NUMERIC = 1;
+        int minimumPasswordNumeric = DEF_MINIMUM_PASSWORD_NUMERIC;
+
+        static final int DEF_MINIMUM_PASSWORD_SYMBOLS = 1;
+        int minimumPasswordSymbols = DEF_MINIMUM_PASSWORD_SYMBOLS;
+
+        static final int DEF_MINIMUM_PASSWORD_NON_LETTER = 0;
+        int minimumPasswordNonLetter = DEF_MINIMUM_PASSWORD_NON_LETTER;
+
+        static final long DEF_MAXIMUM_TIME_TO_UNLOCK = 0;
+        long maximumTimeToUnlock = DEF_MAXIMUM_TIME_TO_UNLOCK;
+
+        static final int DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE = 0;
+        int maximumFailedPasswordsForWipe = DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE;
+
+        static final long DEF_PASSWORD_EXPIRATION_TIMEOUT = 0;
+        long passwordExpirationTimeout = DEF_PASSWORD_EXPIRATION_TIMEOUT;
+
+        static final long DEF_PASSWORD_EXPIRATION_DATE = 0;
+        long passwordExpirationDate = DEF_PASSWORD_EXPIRATION_DATE;
+
+        static final int DEF_KEYGUARD_FEATURES_DISABLED = 0; // none
+        int disabledKeyguardFeatures = DEF_KEYGUARD_FEATURES_DISABLED;
+
+        boolean encryptionRequested = false;
+        boolean disableCamera = false;
+
+        // TODO: review implementation decisions with frameworks team
+        boolean specifiesGlobalProxy = false;
+        String globalProxySpec = null;
+        String globalProxyExclusionList = null;
+
+        ActiveAdmin(DeviceAdminInfo _info) {
+            info = _info;
+        }
+
+        int getUid() { return info.getActivityInfo().applicationInfo.uid; }
+
+        public UserHandle getUserHandle() {
+            return new UserHandle(UserHandle.getUserId(info.getActivityInfo().applicationInfo.uid));
+        }
+
+        void writeToXml(XmlSerializer out)
+                throws IllegalArgumentException, IllegalStateException, IOException {
+            out.startTag(null, TAG_POLICIES);
+            info.writePoliciesToXml(out);
+            out.endTag(null, TAG_POLICIES);
+            if (passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
+                out.startTag(null, TAG_PASSWORD_QUALITY);
+                out.attribute(null, ATTR_VALUE, Integer.toString(passwordQuality));
+                out.endTag(null, TAG_PASSWORD_QUALITY);
+                if (minimumPasswordLength != DEF_MINIMUM_PASSWORD_LENGTH) {
+                    out.startTag(null, TAG_MIN_PASSWORD_LENGTH);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordLength));
+                    out.endTag(null, TAG_MIN_PASSWORD_LENGTH);
+                }
+                if(passwordHistoryLength != DEF_PASSWORD_HISTORY_LENGTH) {
+                    out.startTag(null, TAG_PASSWORD_HISTORY_LENGTH);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(passwordHistoryLength));
+                    out.endTag(null, TAG_PASSWORD_HISTORY_LENGTH);
+                }
+                if (minimumPasswordUpperCase != DEF_MINIMUM_PASSWORD_UPPER_CASE) {
+                    out.startTag(null, TAG_MIN_PASSWORD_UPPERCASE);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordUpperCase));
+                    out.endTag(null, TAG_MIN_PASSWORD_UPPERCASE);
+                }
+                if (minimumPasswordLowerCase != DEF_MINIMUM_PASSWORD_LOWER_CASE) {
+                    out.startTag(null, TAG_MIN_PASSWORD_LOWERCASE);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordLowerCase));
+                    out.endTag(null, TAG_MIN_PASSWORD_LOWERCASE);
+                }
+                if (minimumPasswordLetters != DEF_MINIMUM_PASSWORD_LETTERS) {
+                    out.startTag(null, TAG_MIN_PASSWORD_LETTERS);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordLetters));
+                    out.endTag(null, TAG_MIN_PASSWORD_LETTERS);
+                }
+                if (minimumPasswordNumeric != DEF_MINIMUM_PASSWORD_NUMERIC) {
+                    out.startTag(null, TAG_MIN_PASSWORD_NUMERIC);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordNumeric));
+                    out.endTag(null, TAG_MIN_PASSWORD_NUMERIC);
+                }
+                if (minimumPasswordSymbols != DEF_MINIMUM_PASSWORD_SYMBOLS) {
+                    out.startTag(null, TAG_MIN_PASSWORD_SYMBOLS);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordSymbols));
+                    out.endTag(null, TAG_MIN_PASSWORD_SYMBOLS);
+                }
+                if (minimumPasswordNonLetter > DEF_MINIMUM_PASSWORD_NON_LETTER) {
+                    out.startTag(null, TAG_MIN_PASSWORD_NONLETTER);
+                    out.attribute(null, ATTR_VALUE, Integer.toString(minimumPasswordNonLetter));
+                    out.endTag(null, TAG_MIN_PASSWORD_NONLETTER);
+                }
+            }
+            if (maximumTimeToUnlock != DEF_MAXIMUM_TIME_TO_UNLOCK) {
+                out.startTag(null, TAG_MAX_TIME_TO_UNLOCK);
+                out.attribute(null, ATTR_VALUE, Long.toString(maximumTimeToUnlock));
+                out.endTag(null, TAG_MAX_TIME_TO_UNLOCK);
+            }
+            if (maximumFailedPasswordsForWipe != DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE) {
+                out.startTag(null, TAG_MAX_FAILED_PASSWORD_WIPE);
+                out.attribute(null, ATTR_VALUE, Integer.toString(maximumFailedPasswordsForWipe));
+                out.endTag(null, TAG_MAX_FAILED_PASSWORD_WIPE);
+            }
+            if (specifiesGlobalProxy) {
+                out.startTag(null, TAG_SPECIFIES_GLOBAL_PROXY);
+                out.attribute(null, ATTR_VALUE, Boolean.toString(specifiesGlobalProxy));
+                out.endTag(null, TAG_SPECIFIES_GLOBAL_PROXY);
+                if (globalProxySpec != null) {
+                    out.startTag(null, TAG_GLOBAL_PROXY_SPEC);
+                    out.attribute(null, ATTR_VALUE, globalProxySpec);
+                    out.endTag(null, TAG_GLOBAL_PROXY_SPEC);
+                }
+                if (globalProxyExclusionList != null) {
+                    out.startTag(null, TAG_GLOBAL_PROXY_EXCLUSION_LIST);
+                    out.attribute(null, ATTR_VALUE, globalProxyExclusionList);
+                    out.endTag(null, TAG_GLOBAL_PROXY_EXCLUSION_LIST);
+                }
+            }
+            if (passwordExpirationTimeout != DEF_PASSWORD_EXPIRATION_TIMEOUT) {
+                out.startTag(null, TAG_PASSWORD_EXPIRATION_TIMEOUT);
+                out.attribute(null, ATTR_VALUE, Long.toString(passwordExpirationTimeout));
+                out.endTag(null, TAG_PASSWORD_EXPIRATION_TIMEOUT);
+            }
+            if (passwordExpirationDate != DEF_PASSWORD_EXPIRATION_DATE) {
+                out.startTag(null, TAG_PASSWORD_EXPIRATION_DATE);
+                out.attribute(null, ATTR_VALUE, Long.toString(passwordExpirationDate));
+                out.endTag(null, TAG_PASSWORD_EXPIRATION_DATE);
+            }
+            if (encryptionRequested) {
+                out.startTag(null, TAG_ENCRYPTION_REQUESTED);
+                out.attribute(null, ATTR_VALUE, Boolean.toString(encryptionRequested));
+                out.endTag(null, TAG_ENCRYPTION_REQUESTED);
+            }
+            if (disableCamera) {
+                out.startTag(null, TAG_DISABLE_CAMERA);
+                out.attribute(null, ATTR_VALUE, Boolean.toString(disableCamera));
+                out.endTag(null, TAG_DISABLE_CAMERA);
+            }
+            if (disabledKeyguardFeatures != DEF_KEYGUARD_FEATURES_DISABLED) {
+                out.startTag(null, TAG_DISABLE_KEYGUARD_FEATURES);
+                out.attribute(null, ATTR_VALUE, Integer.toString(disabledKeyguardFeatures));
+                out.endTag(null, TAG_DISABLE_KEYGUARD_FEATURES);
+            }
+        }
+
+        void readFromXml(XmlPullParser parser)
+                throws XmlPullParserException, IOException {
+            int outerDepth = parser.getDepth();
+            int type;
+            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                   && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+                String tag = parser.getName();
+                if (TAG_POLICIES.equals(tag)) {
+                    info.readPoliciesFromXml(parser);
+                } else if (TAG_PASSWORD_QUALITY.equals(tag)) {
+                    passwordQuality = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_LENGTH.equals(tag)) {
+                    minimumPasswordLength = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_PASSWORD_HISTORY_LENGTH.equals(tag)) {
+                    passwordHistoryLength = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_UPPERCASE.equals(tag)) {
+                    minimumPasswordUpperCase = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_LOWERCASE.equals(tag)) {
+                    minimumPasswordLowerCase = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_LETTERS.equals(tag)) {
+                    minimumPasswordLetters = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_NUMERIC.equals(tag)) {
+                    minimumPasswordNumeric = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_SYMBOLS.equals(tag)) {
+                    minimumPasswordSymbols = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MIN_PASSWORD_NONLETTER.equals(tag)) {
+                    minimumPasswordNonLetter = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MAX_TIME_TO_UNLOCK.equals(tag)) {
+                    maximumTimeToUnlock = Long.parseLong(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_MAX_FAILED_PASSWORD_WIPE.equals(tag)) {
+                    maximumFailedPasswordsForWipe = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_SPECIFIES_GLOBAL_PROXY.equals(tag)) {
+                    specifiesGlobalProxy = Boolean.parseBoolean(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_GLOBAL_PROXY_SPEC.equals(tag)) {
+                    globalProxySpec =
+                        parser.getAttributeValue(null, ATTR_VALUE);
+                } else if (TAG_GLOBAL_PROXY_EXCLUSION_LIST.equals(tag)) {
+                    globalProxyExclusionList =
+                        parser.getAttributeValue(null, ATTR_VALUE);
+                } else if (TAG_PASSWORD_EXPIRATION_TIMEOUT.equals(tag)) {
+                    passwordExpirationTimeout = Long.parseLong(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_PASSWORD_EXPIRATION_DATE.equals(tag)) {
+                    passwordExpirationDate = Long.parseLong(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_ENCRYPTION_REQUESTED.equals(tag)) {
+                    encryptionRequested = Boolean.parseBoolean(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_DISABLE_CAMERA.equals(tag)) {
+                    disableCamera = Boolean.parseBoolean(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else if (TAG_DISABLE_KEYGUARD_FEATURES.equals(tag)) {
+                    disabledKeyguardFeatures = Integer.parseInt(
+                            parser.getAttributeValue(null, ATTR_VALUE));
+                } else {
+                    Slog.w(LOG_TAG, "Unknown admin tag: " + tag);
+                }
+                XmlUtils.skipCurrentTag(parser);
+            }
+        }
+
+        void dump(String prefix, PrintWriter pw) {
+            pw.print(prefix); pw.print("uid="); pw.println(getUid());
+            pw.print(prefix); pw.println("policies:");
+            ArrayList<DeviceAdminInfo.PolicyInfo> pols = info.getUsedPolicies();
+            if (pols != null) {
+                for (int i=0; i<pols.size(); i++) {
+                    pw.print(prefix); pw.print("  "); pw.println(pols.get(i).tag);
+                }
+            }
+            pw.print(prefix); pw.print("passwordQuality=0x");
+                    pw.println(Integer.toHexString(passwordQuality));
+            pw.print(prefix); pw.print("minimumPasswordLength=");
+                    pw.println(minimumPasswordLength);
+            pw.print(prefix); pw.print("passwordHistoryLength=");
+                    pw.println(passwordHistoryLength);
+            pw.print(prefix); pw.print("minimumPasswordUpperCase=");
+                    pw.println(minimumPasswordUpperCase);
+            pw.print(prefix); pw.print("minimumPasswordLowerCase=");
+                    pw.println(minimumPasswordLowerCase);
+            pw.print(prefix); pw.print("minimumPasswordLetters=");
+                    pw.println(minimumPasswordLetters);
+            pw.print(prefix); pw.print("minimumPasswordNumeric=");
+                    pw.println(minimumPasswordNumeric);
+            pw.print(prefix); pw.print("minimumPasswordSymbols=");
+                    pw.println(minimumPasswordSymbols);
+            pw.print(prefix); pw.print("minimumPasswordNonLetter=");
+                    pw.println(minimumPasswordNonLetter);
+            pw.print(prefix); pw.print("maximumTimeToUnlock=");
+                    pw.println(maximumTimeToUnlock);
+            pw.print(prefix); pw.print("maximumFailedPasswordsForWipe=");
+                    pw.println(maximumFailedPasswordsForWipe);
+            pw.print(prefix); pw.print("specifiesGlobalProxy=");
+                    pw.println(specifiesGlobalProxy);
+            pw.print(prefix); pw.print("passwordExpirationTimeout=");
+                    pw.println(passwordExpirationTimeout);
+            pw.print(prefix); pw.print("passwordExpirationDate=");
+                    pw.println(passwordExpirationDate);
+            if (globalProxySpec != null) {
+                pw.print(prefix); pw.print("globalProxySpec=");
+                        pw.println(globalProxySpec);
+            }
+            if (globalProxyExclusionList != null) {
+                pw.print(prefix); pw.print("globalProxyEclusionList=");
+                        pw.println(globalProxyExclusionList);
+            }
+            pw.print(prefix); pw.print("encryptionRequested=");
+                    pw.println(encryptionRequested);
+            pw.print(prefix); pw.print("disableCamera=");
+                    pw.println(disableCamera);
+            pw.print(prefix); pw.print("disabledKeyguardFeatures=");
+                    pw.println(disabledKeyguardFeatures);
+        }
+    }
+
+    private void handlePackagesChanged(int userHandle) {
+        boolean removed = false;
+        if (DBG) Slog.d(LOG_TAG, "Handling package changes for user " + userHandle);
+        DevicePolicyData policy = getUserData(userHandle);
+        IPackageManager pm = AppGlobals.getPackageManager();
+        for (int i = policy.mAdminList.size() - 1; i >= 0; i--) {
+            ActiveAdmin aa = policy.mAdminList.get(i);
+            try {
+                if (pm.getPackageInfo(aa.info.getPackageName(), 0, userHandle) == null
+                        || pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle) == null) {
+                    removed = true;
+                    policy.mAdminList.remove(i);
+                    policy.mAdminMap.remove(aa.info.getComponent());
+                }
+            } catch (RemoteException re) {
+                // Shouldn't happen
+            }
+        }
+        if (removed) {
+            validatePasswordOwnerLocked(policy);
+            syncDeviceCapabilitiesLocked(policy);
+            saveSettingsLocked(policy.mUserHandle);
+        }
+    }
+
+    /**
+     * Instantiates the service.
+     */
+    public DevicePolicyManagerService(Context context) {
+        mContext = context;
+        mHasFeature = context.getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_DEVICE_ADMIN);
+        mWakeLock = ((PowerManager)context.getSystemService(Context.POWER_SERVICE))
+                .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DPM");
+        if (!mHasFeature) {
+            // Skip the rest of the initialization
+            return;
+        }
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
+        filter.addAction(ACTION_EXPIRED_PASSWORD_NOTIFICATION);
+        filter.addAction(Intent.ACTION_USER_REMOVED);
+        filter.addAction(Intent.ACTION_USER_STARTED);
+        filter.addAction(KeyChain.ACTION_STORAGE_CHANGED);
+        context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler);
+        filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+        filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
+        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
+        filter.addDataScheme("package");
+        context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler);
+    }
+
+    /**
+     * Creates and loads the policy data from xml.
+     * @param userHandle the user for whom to load the policy data
+     * @return
+     */
+    DevicePolicyData getUserData(int userHandle) {
+        synchronized (this) {
+            DevicePolicyData policy = mUserData.get(userHandle);
+            if (policy == null) {
+                policy = new DevicePolicyData(userHandle);
+                mUserData.append(userHandle, policy);
+                loadSettingsLocked(policy, userHandle);
+            }
+            return policy;
+        }
+    }
+
+    void removeUserData(int userHandle) {
+        synchronized (this) {
+            if (userHandle == UserHandle.USER_OWNER) {
+                Slog.w(LOG_TAG, "Tried to remove device policy file for user 0! Ignoring.");
+                return;
+            }
+            DevicePolicyData policy = mUserData.get(userHandle);
+            if (policy != null) {
+                mUserData.remove(userHandle);
+            }
+            File policyFile = new File(Environment.getUserSystemDirectory(userHandle),
+                    DEVICE_POLICIES_XML);
+            policyFile.delete();
+            Slog.i(LOG_TAG, "Removed device policy file " + policyFile.getAbsolutePath());
+        }
+    }
+
+    void loadDeviceOwner() {
+        synchronized (this) {
+            if (DeviceOwner.isRegistered()) {
+                mDeviceOwner = new DeviceOwner();
+            }
+        }
+    }
+
+    /**
+     * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
+     * reminders.  Clears alarm if no expirations are configured.
+     */
+    protected void setExpirationAlarmCheckLocked(Context context, DevicePolicyData policy) {
+        final long expiration = getPasswordExpirationLocked(null, policy.mUserHandle);
+        final long now = System.currentTimeMillis();
+        final long timeToExpire = expiration - now;
+        final long alarmTime;
+        if (expiration == 0) {
+            // No expirations are currently configured:  Cancel alarm.
+            alarmTime = 0;
+        } else if (timeToExpire <= 0) {
+            // The password has already expired:  Repeat every 24 hours.
+            alarmTime = now + MS_PER_DAY;
+        } else {
+            // Selecting the next alarm time:  Roll forward to the next 24 hour multiple before
+            // the expiration time.
+            long alarmInterval = timeToExpire % MS_PER_DAY;
+            if (alarmInterval == 0) {
+                alarmInterval = MS_PER_DAY;
+            }
+            alarmTime = now + alarmInterval;
+        }
+
+        long token = Binder.clearCallingIdentity();
+        try {
+            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+            PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD,
+                    new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION),
+                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT,
+                    new UserHandle(policy.mUserHandle));
+            am.cancel(pi);
+            if (alarmTime != 0) {
+                am.set(AlarmManager.RTC, alarmTime, pi);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
+    private IPowerManager getIPowerManager() {
+        if (mIPowerManager == null) {
+            IBinder b = ServiceManager.getService(Context.POWER_SERVICE);
+            mIPowerManager = IPowerManager.Stub.asInterface(b);
+        }
+        return mIPowerManager;
+    }
+
+    private IWindowManager getWindowManager() {
+        if (mIWindowManager == null) {
+            IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE);
+            mIWindowManager = IWindowManager.Stub.asInterface(b);
+        }
+        return mIWindowManager;
+    }
+
+    private NotificationManager getNotificationManager() {
+        if (mNotificationManager == null) {
+            mNotificationManager =
+                    (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+        }
+        return mNotificationManager;
+    }
+
+    ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who, int userHandle) {
+        ActiveAdmin admin = getUserData(userHandle).mAdminMap.get(who);
+        if (admin != null
+                && who.getPackageName().equals(admin.info.getActivityInfo().packageName)
+                && who.getClassName().equals(admin.info.getActivityInfo().name)) {
+            return admin;
+        }
+        return null;
+    }
+
+    ActiveAdmin getActiveAdminForCallerLocked(ComponentName who, int reqPolicy)
+            throws SecurityException {
+        final int callingUid = Binder.getCallingUid();
+        final int userHandle = UserHandle.getUserId(callingUid);
+        final DevicePolicyData policy = getUserData(userHandle);
+        if (who != null) {
+            ActiveAdmin admin = policy.mAdminMap.get(who);
+            if (admin == null) {
+                throw new SecurityException("No active admin " + who);
+            }
+            if (admin.getUid() != callingUid) {
+                throw new SecurityException("Admin " + who + " is not owned by uid "
+                        + Binder.getCallingUid());
+            }
+            if (!admin.info.usesPolicy(reqPolicy)) {
+                throw new SecurityException("Admin " + admin.info.getComponent()
+                        + " did not specify uses-policy for: "
+                        + admin.info.getTagForPolicy(reqPolicy));
+            }
+            return admin;
+        } else {
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (admin.getUid() == callingUid && admin.info.usesPolicy(reqPolicy)) {
+                    return admin;
+                }
+            }
+            throw new SecurityException("No active admin owned by uid "
+                    + Binder.getCallingUid() + " for policy #" + reqPolicy);
+        }
+    }
+
+    void sendAdminCommandLocked(ActiveAdmin admin, String action) {
+        sendAdminCommandLocked(admin, action, null);
+    }
+
+    void sendAdminCommandLocked(ActiveAdmin admin, String action, BroadcastReceiver result) {
+        Intent intent = new Intent(action);
+        intent.setComponent(admin.info.getComponent());
+        if (action.equals(DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING)) {
+            intent.putExtra("expiration", admin.passwordExpirationDate);
+        }
+        if (result != null) {
+            mContext.sendOrderedBroadcastAsUser(intent, admin.getUserHandle(),
+                    null, result, mHandler, Activity.RESULT_OK, null, null);
+        } else {
+            mContext.sendBroadcastAsUser(intent, UserHandle.OWNER);
+        }
+    }
+
+    void sendAdminCommandLocked(String action, int reqPolicy, int userHandle) {
+        final DevicePolicyData policy = getUserData(userHandle);
+        final int count = policy.mAdminList.size();
+        if (count > 0) {
+            for (int i = 0; i < count; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (admin.info.usesPolicy(reqPolicy)) {
+                    sendAdminCommandLocked(admin, action);
+                }
+            }
+        }
+    }
+
+    void removeActiveAdminLocked(final ComponentName adminReceiver, int userHandle) {
+        final ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
+        if (admin != null) {
+            sendAdminCommandLocked(admin,
+                    DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED,
+                    new BroadcastReceiver() {
+                        @Override
+                        public void onReceive(Context context, Intent intent) {
+                            synchronized (DevicePolicyManagerService.this) {
+                                int userHandle = admin.getUserHandle().getIdentifier();
+                                DevicePolicyData policy = getUserData(userHandle);
+                                boolean doProxyCleanup = admin.info.usesPolicy(
+                                        DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY);
+                                policy.mAdminList.remove(admin);
+                                policy.mAdminMap.remove(adminReceiver);
+                                validatePasswordOwnerLocked(policy);
+                                syncDeviceCapabilitiesLocked(policy);
+                                if (doProxyCleanup) {
+                                    resetGlobalProxyLocked(getUserData(userHandle));
+                                }
+                                saveSettingsLocked(userHandle);
+                                updateMaximumTimeToLockLocked(policy);
+                            }
+                        }
+            });
+        }
+    }
+
+    public DeviceAdminInfo findAdmin(ComponentName adminName, int userHandle) {
+        if (!mHasFeature) {
+            return null;
+        }
+        enforceCrossUserPermission(userHandle);
+        Intent resolveIntent = new Intent();
+        resolveIntent.setComponent(adminName);
+        List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers(
+                resolveIntent,
+                PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
+                userHandle);
+        if (infos == null || infos.size() <= 0) {
+            throw new IllegalArgumentException("Unknown admin: " + adminName);
+        }
+
+        try {
+            return new DeviceAdminInfo(mContext, infos.get(0));
+        } catch (XmlPullParserException e) {
+            Slog.w(LOG_TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName,
+                    e);
+            return null;
+        } catch (IOException e) {
+            Slog.w(LOG_TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName,
+                    e);
+            return null;
+        }
+    }
+
+    private static JournaledFile makeJournaledFile(int userHandle) {
+        final String base = userHandle == 0
+                ? "/data/system/" + DEVICE_POLICIES_XML
+                : new File(Environment.getUserSystemDirectory(userHandle), DEVICE_POLICIES_XML)
+                        .getAbsolutePath();
+        return new JournaledFile(new File(base), new File(base + ".tmp"));
+    }
+
+    private void saveSettingsLocked(int userHandle) {
+        DevicePolicyData policy = getUserData(userHandle);
+        JournaledFile journal = makeJournaledFile(userHandle);
+        FileOutputStream stream = null;
+        try {
+            stream = new FileOutputStream(journal.chooseForWrite(), false);
+            XmlSerializer out = new FastXmlSerializer();
+            out.setOutput(stream, "utf-8");
+            out.startDocument(null, true);
+
+            out.startTag(null, "policies");
+
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                ActiveAdmin ap = policy.mAdminList.get(i);
+                if (ap != null) {
+                    out.startTag(null, "admin");
+                    out.attribute(null, "name", ap.info.getComponent().flattenToString());
+                    ap.writeToXml(out);
+                    out.endTag(null, "admin");
+                }
+            }
+
+            if (policy.mPasswordOwner >= 0) {
+                out.startTag(null, "password-owner");
+                out.attribute(null, "value", Integer.toString(policy.mPasswordOwner));
+                out.endTag(null, "password-owner");
+            }
+
+            if (policy.mFailedPasswordAttempts != 0) {
+                out.startTag(null, "failed-password-attempts");
+                out.attribute(null, "value", Integer.toString(policy.mFailedPasswordAttempts));
+                out.endTag(null, "failed-password-attempts");
+            }
+
+            if (policy.mActivePasswordQuality != 0 || policy.mActivePasswordLength != 0
+                    || policy.mActivePasswordUpperCase != 0 || policy.mActivePasswordLowerCase != 0
+                    || policy.mActivePasswordLetters != 0 || policy.mActivePasswordNumeric != 0
+                    || policy.mActivePasswordSymbols != 0 || policy.mActivePasswordNonLetter != 0) {
+                out.startTag(null, "active-password");
+                out.attribute(null, "quality", Integer.toString(policy.mActivePasswordQuality));
+                out.attribute(null, "length", Integer.toString(policy.mActivePasswordLength));
+                out.attribute(null, "uppercase", Integer.toString(policy.mActivePasswordUpperCase));
+                out.attribute(null, "lowercase", Integer.toString(policy.mActivePasswordLowerCase));
+                out.attribute(null, "letters", Integer.toString(policy.mActivePasswordLetters));
+                out.attribute(null, "numeric", Integer
+                        .toString(policy.mActivePasswordNumeric));
+                out.attribute(null, "symbols", Integer.toString(policy.mActivePasswordSymbols));
+                out.attribute(null, "nonletter", Integer.toString(policy.mActivePasswordNonLetter));
+                out.endTag(null, "active-password");
+            }
+
+            out.endTag(null, "policies");
+
+            out.endDocument();
+            stream.close();
+            journal.commit();
+            sendChangedNotification(userHandle);
+        } catch (IOException e) {
+            try {
+                if (stream != null) {
+                    stream.close();
+                }
+            } catch (IOException ex) {
+                // Ignore
+            }
+            journal.rollback();
+        }
+    }
+
+    private void sendChangedNotification(int userHandle) {
+        Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
+        intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+        long ident = Binder.clearCallingIdentity();
+        try {
+            mContext.sendBroadcastAsUser(intent, new UserHandle(userHandle));
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private void loadSettingsLocked(DevicePolicyData policy, int userHandle) {
+        JournaledFile journal = makeJournaledFile(userHandle);
+        FileInputStream stream = null;
+        File file = journal.chooseForRead();
+        try {
+            stream = new FileInputStream(file);
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(stream, null);
+
+            int type;
+            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                    && type != XmlPullParser.START_TAG) {
+            }
+            String tag = parser.getName();
+            if (!"policies".equals(tag)) {
+                throw new XmlPullParserException(
+                        "Settings do not start with policies tag: found " + tag);
+            }
+            type = parser.next();
+            int outerDepth = parser.getDepth();
+            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                   && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
+                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
+                    continue;
+                }
+                tag = parser.getName();
+                if ("admin".equals(tag)) {
+                    String name = parser.getAttributeValue(null, "name");
+                    try {
+                        DeviceAdminInfo dai = findAdmin(
+                                ComponentName.unflattenFromString(name), userHandle);
+                        if (DBG && (UserHandle.getUserId(dai.getActivityInfo().applicationInfo.uid)
+                                != userHandle)) {
+                            Slog.w(LOG_TAG, "findAdmin returned an incorrect uid "
+                                    + dai.getActivityInfo().applicationInfo.uid + " for user "
+                                    + userHandle);
+                        }
+                        if (dai != null) {
+                            ActiveAdmin ap = new ActiveAdmin(dai);
+                            ap.readFromXml(parser);
+                            policy.mAdminMap.put(ap.info.getComponent(), ap);
+                            policy.mAdminList.add(ap);
+                        }
+                    } catch (RuntimeException e) {
+                        Slog.w(LOG_TAG, "Failed loading admin " + name, e);
+                    }
+                } else if ("failed-password-attempts".equals(tag)) {
+                    policy.mFailedPasswordAttempts = Integer.parseInt(
+                            parser.getAttributeValue(null, "value"));
+                    XmlUtils.skipCurrentTag(parser);
+                } else if ("password-owner".equals(tag)) {
+                    policy.mPasswordOwner = Integer.parseInt(
+                            parser.getAttributeValue(null, "value"));
+                    XmlUtils.skipCurrentTag(parser);
+                } else if ("active-password".equals(tag)) {
+                    policy.mActivePasswordQuality = Integer.parseInt(
+                            parser.getAttributeValue(null, "quality"));
+                    policy.mActivePasswordLength = Integer.parseInt(
+                            parser.getAttributeValue(null, "length"));
+                    policy.mActivePasswordUpperCase = Integer.parseInt(
+                            parser.getAttributeValue(null, "uppercase"));
+                    policy.mActivePasswordLowerCase = Integer.parseInt(
+                            parser.getAttributeValue(null, "lowercase"));
+                    policy.mActivePasswordLetters = Integer.parseInt(
+                            parser.getAttributeValue(null, "letters"));
+                    policy.mActivePasswordNumeric = Integer.parseInt(
+                            parser.getAttributeValue(null, "numeric"));
+                    policy.mActivePasswordSymbols = Integer.parseInt(
+                            parser.getAttributeValue(null, "symbols"));
+                    policy.mActivePasswordNonLetter = Integer.parseInt(
+                            parser.getAttributeValue(null, "nonletter"));
+                    XmlUtils.skipCurrentTag(parser);
+                } else {
+                    Slog.w(LOG_TAG, "Unknown tag: " + tag);
+                    XmlUtils.skipCurrentTag(parser);
+                }
+            }
+        } catch (NullPointerException e) {
+            Slog.w(LOG_TAG, "failed parsing " + file + " " + e);
+        } catch (NumberFormatException e) {
+            Slog.w(LOG_TAG, "failed parsing " + file + " " + e);
+        } catch (XmlPullParserException e) {
+            Slog.w(LOG_TAG, "failed parsing " + file + " " + e);
+        } catch (FileNotFoundException e) {
+            // Don't be noisy, this is normal if we haven't defined any policies.
+        } catch (IOException e) {
+            Slog.w(LOG_TAG, "failed parsing " + file + " " + e);
+        } catch (IndexOutOfBoundsException e) {
+            Slog.w(LOG_TAG, "failed parsing " + file + " " + e);
+        }
+        try {
+            if (stream != null) {
+                stream.close();
+            }
+        } catch (IOException e) {
+            // Ignore
+        }
+
+        // Validate that what we stored for the password quality matches
+        // sufficiently what is currently set.  Note that this is only
+        // a sanity check in case the two get out of sync; this should
+        // never normally happen.
+        LockPatternUtils utils = new LockPatternUtils(mContext);
+        if (utils.getActivePasswordQuality() < policy.mActivePasswordQuality) {
+            Slog.w(LOG_TAG, "Active password quality 0x"
+                    + Integer.toHexString(policy.mActivePasswordQuality)
+                    + " does not match actual quality 0x"
+                    + Integer.toHexString(utils.getActivePasswordQuality()));
+            policy.mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+            policy.mActivePasswordLength = 0;
+            policy.mActivePasswordUpperCase = 0;
+            policy.mActivePasswordLowerCase = 0;
+            policy.mActivePasswordLetters = 0;
+            policy.mActivePasswordNumeric = 0;
+            policy.mActivePasswordSymbols = 0;
+            policy.mActivePasswordNonLetter = 0;
+        }
+
+        validatePasswordOwnerLocked(policy);
+        syncDeviceCapabilitiesLocked(policy);
+        updateMaximumTimeToLockLocked(policy);
+    }
+
+    static void validateQualityConstant(int quality) {
+        switch (quality) {
+            case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
+            case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
+            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
+            case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
+            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
+            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
+                return;
+        }
+        throw new IllegalArgumentException("Invalid quality constant: 0x"
+                + Integer.toHexString(quality));
+    }
+
+    void validatePasswordOwnerLocked(DevicePolicyData policy) {
+        if (policy.mPasswordOwner >= 0) {
+            boolean haveOwner = false;
+            for (int i = policy.mAdminList.size() - 1; i >= 0; i--) {
+                if (policy.mAdminList.get(i).getUid() == policy.mPasswordOwner) {
+                    haveOwner = true;
+                    break;
+                }
+            }
+            if (!haveOwner) {
+                Slog.w(LOG_TAG, "Previous password owner " + policy.mPasswordOwner
+                        + " no longer active; disabling");
+                policy.mPasswordOwner = -1;
+            }
+        }
+    }
+
+    /**
+     * Pushes down policy information to the system for any policies related to general device
+     * capabilities that need to be enforced by lower level services (e.g. Camera services).
+     */
+    void syncDeviceCapabilitiesLocked(DevicePolicyData policy) {
+        // Ensure the status of the camera is synced down to the system. Interested native services
+        // should monitor this value and act accordingly.
+        boolean systemState = SystemProperties.getBoolean(SYSTEM_PROP_DISABLE_CAMERA, false);
+        boolean cameraDisabled = getCameraDisabled(null, policy.mUserHandle);
+        if (cameraDisabled != systemState) {
+            long token = Binder.clearCallingIdentity();
+            try {
+                String value = cameraDisabled ? "1" : "0";
+                if (DBG) Slog.v(LOG_TAG, "Change in camera state ["
+                        + SYSTEM_PROP_DISABLE_CAMERA + "] = " + value);
+                SystemProperties.set(SYSTEM_PROP_DISABLE_CAMERA, value);
+            } finally {
+                Binder.restoreCallingIdentity(token);
+            }
+        }
+    }
+
+    public void systemReady() {
+        if (!mHasFeature) {
+            return;
+        }
+        synchronized (this) {
+            loadSettingsLocked(getUserData(UserHandle.USER_OWNER), UserHandle.USER_OWNER);
+            loadDeviceOwner();
+        }
+    }
+
+    private void handlePasswordExpirationNotification(DevicePolicyData policy) {
+        synchronized (this) {
+            final long now = System.currentTimeMillis();
+            final int N = policy.mAdminList.size();
+            if (N <= 0) {
+                return;
+            }
+            for (int i=0; i < N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD)
+                        && admin.passwordExpirationTimeout > 0L
+                        && admin.passwordExpirationDate > 0L
+                        && now >= admin.passwordExpirationDate - EXPIRATION_GRACE_PERIOD_MS) {
+                    sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING);
+                }
+            }
+            setExpirationAlarmCheckLocked(mContext, policy);
+        }
+    }
+
+    private void manageMonitoringCertificateNotification(Intent intent) {
+        final NotificationManager notificationManager = getNotificationManager();
+
+        final boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled();
+        if (! hasCert) {
+            if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) {
+                UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+                for (UserInfo user : um.getUsers()) {
+                    notificationManager.cancelAsUser(
+                            null, MONITORING_CERT_NOTIFICATION_ID, user.getUserHandle());
+                }
+            }
+            return;
+        }
+        final boolean isManaged = getDeviceOwner() != null;
+        int smallIconId;
+        String contentText;
+        if (isManaged) {
+            contentText = mContext.getString(R.string.ssl_ca_cert_noti_managed,
+                    getDeviceOwnerName());
+            smallIconId = R.drawable.stat_sys_certificate_info;
+        } else {
+            contentText = mContext.getString(R.string.ssl_ca_cert_noti_by_unknown);
+            smallIconId = android.R.drawable.stat_sys_warning;
+        }
+
+        Intent dialogIntent = new Intent(Settings.ACTION_MONITORING_CERT_INFO);
+        dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+        dialogIntent.setPackage("com.android.settings");
+        // Notification will be sent individually to all users. The activity should start as
+        // whichever user is current when it starts.
+        PendingIntent notifyIntent = PendingIntent.getActivityAsUser(mContext, 0, dialogIntent,
+                PendingIntent.FLAG_UPDATE_CURRENT, null, UserHandle.CURRENT);
+
+        Notification noti = new Notification.Builder(mContext)
+            .setSmallIcon(smallIconId)
+            .setContentTitle(mContext.getString(R.string.ssl_ca_cert_warning))
+            .setContentText(contentText)
+            .setContentIntent(notifyIntent)
+            .setPriority(Notification.PRIORITY_HIGH)
+            .setShowWhen(false)
+            .build();
+
+        // If this is a boot intent, this will fire for each user. But if this is a storage changed
+        // intent, it will fire once, so we need to notify all users.
+        if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) {
+            UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+            for (UserInfo user : um.getUsers()) {
+                notificationManager.notifyAsUser(
+                        null, MONITORING_CERT_NOTIFICATION_ID, noti, user.getUserHandle());
+            }
+        } else {
+            notificationManager.notifyAsUser(
+                    null, MONITORING_CERT_NOTIFICATION_ID, noti, UserHandle.CURRENT);
+        }
+    }
+
+    /**
+     * @param adminReceiver The admin to add
+     * @param refreshing true = update an active admin, no error
+     */
+    public void setActiveAdmin(ComponentName adminReceiver, boolean refreshing, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.MANAGE_DEVICE_ADMINS, null);
+        enforceCrossUserPermission(userHandle);
+
+        DevicePolicyData policy = getUserData(userHandle);
+        DeviceAdminInfo info = findAdmin(adminReceiver, userHandle);
+        if (info == null) {
+            throw new IllegalArgumentException("Bad admin: " + adminReceiver);
+        }
+        synchronized (this) {
+            long ident = Binder.clearCallingIdentity();
+            try {
+                if (!refreshing
+                        && getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null) {
+                    throw new IllegalArgumentException("Admin is already added");
+                }
+                ActiveAdmin newAdmin = new ActiveAdmin(info);
+                policy.mAdminMap.put(adminReceiver, newAdmin);
+                int replaceIndex = -1;
+                if (refreshing) {
+                    final int N = policy.mAdminList.size();
+                    for (int i=0; i < N; i++) {
+                        ActiveAdmin oldAdmin = policy.mAdminList.get(i);
+                        if (oldAdmin.info.getComponent().equals(adminReceiver)) {
+                            replaceIndex = i;
+                            break;
+                        }
+                    }
+                }
+                if (replaceIndex == -1) {
+                    policy.mAdminList.add(newAdmin);
+                    enableIfNecessary(info.getPackageName(), userHandle);
+                } else {
+                    policy.mAdminList.set(replaceIndex, newAdmin);
+                }
+                saveSettingsLocked(userHandle);
+                sendAdminCommandLocked(newAdmin, DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public boolean isAdminActive(ComponentName adminReceiver, int userHandle) {
+        if (!mHasFeature) {
+            return false;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            return getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null;
+        }
+    }
+
+    public boolean hasGrantedPolicy(ComponentName adminReceiver, int policyId, int userHandle) {
+        if (!mHasFeature) {
+            return false;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            ActiveAdmin administrator = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
+            if (administrator == null) {
+                throw new SecurityException("No active admin " + adminReceiver);
+            }
+            return administrator.info.usesPolicy(policyId);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<ComponentName> getActiveAdmins(int userHandle) {
+        if (!mHasFeature) {
+            return Collections.EMPTY_LIST;
+        }
+
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            if (N <= 0) {
+                return null;
+            }
+            ArrayList<ComponentName> res = new ArrayList<ComponentName>(N);
+            for (int i=0; i<N; i++) {
+                res.add(policy.mAdminList.get(i).info.getComponent());
+            }
+            return res;
+        }
+    }
+
+    public boolean packageHasActiveAdmins(String packageName, int userHandle) {
+        if (!mHasFeature) {
+            return false;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                if (policy.mAdminList.get(i).info.getPackageName().equals(packageName)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    public void removeActiveAdmin(ComponentName adminReceiver, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
+            if (admin == null) {
+                return;
+            }
+            if (admin.getUid() != Binder.getCallingUid()) {
+                // If trying to remove device owner, refuse when the caller is not the owner.
+                if (mDeviceOwner != null
+                        && adminReceiver.getPackageName().equals(mDeviceOwner.getPackageName())) {
+                    return;
+                }
+                mContext.enforceCallingOrSelfPermission(
+                        android.Manifest.permission.MANAGE_DEVICE_ADMINS, null);
+            }
+            long ident = Binder.clearCallingIdentity();
+            try {
+                removeActiveAdminLocked(adminReceiver, userHandle);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void setPasswordQuality(ComponentName who, int quality, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        validateQualityConstant(quality);
+        enforceCrossUserPermission(userHandle);
+
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.passwordQuality != quality) {
+                ap.passwordQuality = quality;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordQuality(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+            DevicePolicyData policy = getUserData(userHandle);
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.passwordQuality : mode;
+            }
+
+            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;
+        }
+    }
+
+    public void setPasswordMinimumLength(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordLength != length) {
+                ap.minimumPasswordLength = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumLength(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordLength : length;
+            }
+
+            final int N = policy.mAdminList.size();
+            for  (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordLength) {
+                    length = admin.minimumPasswordLength;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordHistoryLength(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.passwordHistoryLength != length) {
+                ap.passwordHistoryLength = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordHistoryLength(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.passwordHistoryLength : length;
+            }
+
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.passwordHistoryLength) {
+                    length = admin.passwordHistoryLength;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordExpirationTimeout(ComponentName who, long timeout, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            if (timeout < 0) {
+                throw new IllegalArgumentException("Timeout must be >= 0 ms");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD);
+            // Calling this API automatically bumps the expiration date
+            final long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L;
+            ap.passwordExpirationDate = expiration;
+            ap.passwordExpirationTimeout = timeout;
+            if (timeout > 0L) {
+                Slog.w(LOG_TAG, "setPasswordExpiration(): password will expire on "
+                        + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT)
+                        .format(new Date(expiration)));
+            }
+            saveSettingsLocked(userHandle);
+            // in case this is the first one
+            setExpirationAlarmCheckLocked(mContext, getUserData(userHandle));
+        }
+    }
+
+    /**
+     * Return a single admin's expiration cycle time, or the min of all cycle times.
+     * Returns 0 if not configured.
+     */
+    public long getPasswordExpirationTimeout(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0L;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.passwordExpirationTimeout : 0L;
+            }
+
+            long timeout = 0L;
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (timeout == 0L || (admin.passwordExpirationTimeout != 0L
+                        && timeout > admin.passwordExpirationTimeout)) {
+                    timeout = admin.passwordExpirationTimeout;
+                }
+            }
+            return timeout;
+        }
+    }
+
+    /**
+     * Return a single admin's expiration date/time, or the min (soonest) for all admins.
+     * Returns 0 if not configured.
+     */
+    private long getPasswordExpirationLocked(ComponentName who, int userHandle) {
+        if (who != null) {
+            ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+            return admin != null ? admin.passwordExpirationDate : 0L;
+        }
+
+        long timeout = 0L;
+        DevicePolicyData policy = getUserData(userHandle);
+        final int N = policy.mAdminList.size();
+        for (int i = 0; i < N; i++) {
+            ActiveAdmin admin = policy.mAdminList.get(i);
+            if (timeout == 0L || (admin.passwordExpirationDate != 0
+                    && timeout > admin.passwordExpirationDate)) {
+                timeout = admin.passwordExpirationDate;
+            }
+        }
+        return timeout;
+    }
+
+    public long getPasswordExpiration(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0L;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            return getPasswordExpirationLocked(who, userHandle);
+        }
+    }
+
+    public void setPasswordMinimumUpperCase(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordUpperCase != length) {
+                ap.minimumPasswordUpperCase = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumUpperCase(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordUpperCase : length;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordUpperCase) {
+                    length = admin.minimumPasswordUpperCase;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordMinimumLowerCase(ComponentName who, int length, int userHandle) {
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordLowerCase != length) {
+                ap.minimumPasswordLowerCase = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumLowerCase(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordLowerCase : length;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordLowerCase) {
+                    length = admin.minimumPasswordLowerCase;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordMinimumLetters(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordLetters != length) {
+                ap.minimumPasswordLetters = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumLetters(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordLetters : length;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordLetters) {
+                    length = admin.minimumPasswordLetters;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordMinimumNumeric(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordNumeric != length) {
+                ap.minimumPasswordNumeric = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumNumeric(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordNumeric : length;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordNumeric) {
+                    length = admin.minimumPasswordNumeric;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordMinimumSymbols(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordSymbols != length) {
+                ap.minimumPasswordSymbols = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumSymbols(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordSymbols : length;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for  (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordSymbols) {
+                    length = admin.minimumPasswordSymbols;
+                }
+            }
+            return length;
+        }
+    }
+
+    public void setPasswordMinimumNonLetter(ComponentName who, int length, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
+            if (ap.minimumPasswordNonLetter != length) {
+                ap.minimumPasswordNonLetter = length;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getPasswordMinimumNonLetter(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            int length = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.minimumPasswordNonLetter : length;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (length < admin.minimumPasswordNonLetter) {
+                    length = admin.minimumPasswordNonLetter;
+                }
+            }
+            return length;
+        }
+    }
+
+    public boolean isActivePasswordSufficient(int userHandle) {
+        if (!mHasFeature) {
+            return true;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            // 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)
+                    || policy.mActivePasswordLength < getPasswordMinimumLength(null, userHandle)) {
+                return false;
+            }
+            if (policy.mActivePasswordQuality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
+                return true;
+            }
+            return policy.mActivePasswordUpperCase >= getPasswordMinimumUpperCase(null, userHandle)
+                && policy.mActivePasswordLowerCase >= getPasswordMinimumLowerCase(null, userHandle)
+                && policy.mActivePasswordLetters >= getPasswordMinimumLetters(null, userHandle)
+                && policy.mActivePasswordNumeric >= getPasswordMinimumNumeric(null, userHandle)
+                && policy.mActivePasswordSymbols >= getPasswordMinimumSymbols(null, userHandle)
+                && policy.mActivePasswordNonLetter >= getPasswordMinimumNonLetter(null, userHandle);
+        }
+    }
+
+    public int getCurrentFailedPasswordAttempts(int userHandle) {
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            // 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_WATCH_LOGIN);
+            return getUserData(userHandle).mFailedPasswordAttempts;
+        }
+    }
+
+    public void setMaximumFailedPasswordsForWipe(ComponentName who, int num, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            // This API can only be called by an active device admin,
+            // so try to retrieve it to check that the caller is one.
+            getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_WIPE_DATA);
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_WATCH_LOGIN);
+            if (ap.maximumFailedPasswordsForWipe != num) {
+                ap.maximumFailedPasswordsForWipe = num;
+                saveSettingsLocked(userHandle);
+            }
+        }
+    }
+
+    public int getMaximumFailedPasswordsForWipe(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            int count = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.maximumFailedPasswordsForWipe : count;
+            }
+
+            final int N = policy.mAdminList.size();
+            for  (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (count == 0) {
+                    count = admin.maximumFailedPasswordsForWipe;
+                } else if (admin.maximumFailedPasswordsForWipe != 0
+                        && count > admin.maximumFailedPasswordsForWipe) {
+                    count = admin.maximumFailedPasswordsForWipe;
+                }
+            }
+            return count;
+        }
+    }
+
+    public boolean resetPassword(String password, int flags, int userHandle) {
+        if (!mHasFeature) {
+            return false;
+        }
+        enforceCrossUserPermission(userHandle);
+        int quality;
+        synchronized (this) {
+            // 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_RESET_PASSWORD);
+            quality = getPasswordQuality(null, userHandle);
+            if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
+                int realQuality = LockPatternUtils.computePasswordQuality(password);
+                if (realQuality < quality
+                        && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
+                    Slog.w(LOG_TAG, "resetPassword: password quality 0x"
+                            + Integer.toHexString(realQuality)
+                            + " does not meet required quality 0x"
+                            + Integer.toHexString(quality));
+                    return false;
+                }
+                quality = Math.max(realQuality, quality);
+            }
+            int length = getPasswordMinimumLength(null, userHandle);
+            if (password.length() < length) {
+                Slog.w(LOG_TAG, "resetPassword: password length " + password.length()
+                        + " does not meet required length " + length);
+                return false;
+            }
+            if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
+                int letters = 0;
+                int uppercase = 0;
+                int lowercase = 0;
+                int numbers = 0;
+                int symbols = 0;
+                int nonletter = 0;
+                for (int i = 0; i < password.length(); i++) {
+                    char c = password.charAt(i);
+                    if (c >= 'A' && c <= 'Z') {
+                        letters++;
+                        uppercase++;
+                    } else if (c >= 'a' && c <= 'z') {
+                        letters++;
+                        lowercase++;
+                    } else if (c >= '0' && c <= '9') {
+                        numbers++;
+                        nonletter++;
+                    } else {
+                        symbols++;
+                        nonletter++;
+                    }
+                }
+                int neededLetters = getPasswordMinimumLetters(null, userHandle);
+                if(letters < neededLetters) {
+                    Slog.w(LOG_TAG, "resetPassword: number of letters " + letters
+                            + " does not meet required number of letters " + neededLetters);
+                    return false;
+                }
+                int neededNumbers = getPasswordMinimumNumeric(null, userHandle);
+                if (numbers < neededNumbers) {
+                    Slog.w(LOG_TAG, "resetPassword: number of numerical digits " + numbers
+                            + " does not meet required number of numerical digits "
+                            + neededNumbers);
+                    return false;
+                }
+                int neededLowerCase = getPasswordMinimumLowerCase(null, userHandle);
+                if (lowercase < neededLowerCase) {
+                    Slog.w(LOG_TAG, "resetPassword: number of lowercase letters " + lowercase
+                            + " does not meet required number of lowercase letters "
+                            + neededLowerCase);
+                    return false;
+                }
+                int neededUpperCase = getPasswordMinimumUpperCase(null, userHandle);
+                if (uppercase < neededUpperCase) {
+                    Slog.w(LOG_TAG, "resetPassword: number of uppercase letters " + uppercase
+                            + " does not meet required number of uppercase letters "
+                            + neededUpperCase);
+                    return false;
+                }
+                int neededSymbols = getPasswordMinimumSymbols(null, userHandle);
+                if (symbols < neededSymbols) {
+                    Slog.w(LOG_TAG, "resetPassword: number of special symbols " + symbols
+                            + " does not meet required number of special symbols " + neededSymbols);
+                    return false;
+                }
+                int neededNonLetter = getPasswordMinimumNonLetter(null, userHandle);
+                if (nonletter < neededNonLetter) {
+                    Slog.w(LOG_TAG, "resetPassword: number of non-letter characters " + nonletter
+                            + " does not meet required number of non-letter characters "
+                            + neededNonLetter);
+                    return false;
+                }
+            }
+        }
+
+        int callingUid = Binder.getCallingUid();
+        DevicePolicyData policy = getUserData(userHandle);
+        if (policy.mPasswordOwner >= 0 && policy.mPasswordOwner != callingUid) {
+            Slog.w(LOG_TAG, "resetPassword: already set by another uid and not entered by user");
+            return false;
+        }
+
+        // Don't do this with the lock held, because it is going to call
+        // back in to the service.
+        long ident = Binder.clearCallingIdentity();
+        try {
+            LockPatternUtils utils = new LockPatternUtils(mContext);
+            utils.saveLockPassword(password, quality, false, userHandle);
+            synchronized (this) {
+                int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY)
+                        != 0 ? callingUid : -1;
+                if (policy.mPasswordOwner != newOwner) {
+                    policy.mPasswordOwner = newOwner;
+                    saveSettingsLocked(userHandle);
+                }
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+
+        return true;
+    }
+
+    public void setMaximumTimeToLock(ComponentName who, long timeMs, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
+            if (ap.maximumTimeToUnlock != timeMs) {
+                ap.maximumTimeToUnlock = timeMs;
+                saveSettingsLocked(userHandle);
+                updateMaximumTimeToLockLocked(getUserData(userHandle));
+            }
+        }
+    }
+
+    void updateMaximumTimeToLockLocked(DevicePolicyData policy) {
+        long timeMs = getMaximumTimeToLock(null, policy.mUserHandle);
+        if (policy.mLastMaximumTimeToLock == timeMs) {
+            return;
+        }
+
+        long ident = Binder.clearCallingIdentity();
+        try {
+            if (timeMs <= 0) {
+                timeMs = Integer.MAX_VALUE;
+            } else {
+                // Make sure KEEP_SCREEN_ON is disabled, since that
+                // would allow bypassing of the maximum time to lock.
+                Settings.Global.putInt(mContext.getContentResolver(),
+                        Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0);
+            }
+
+            policy.mLastMaximumTimeToLock = timeMs;
+
+            try {
+                getIPowerManager().setMaximumScreenOffTimeoutFromDeviceAdmin((int)timeMs);
+            } catch (RemoteException e) {
+                Slog.w(LOG_TAG, "Failure talking with power manager", e);
+            }
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    public long getMaximumTimeToLock(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            long time = 0;
+
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return admin != null ? admin.maximumTimeToUnlock : time;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for  (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (time == 0) {
+                    time = admin.maximumTimeToUnlock;
+                } else if (admin.maximumTimeToUnlock != 0
+                        && time > admin.maximumTimeToUnlock) {
+                    time = admin.maximumTimeToUnlock;
+                }
+            }
+            return time;
+        }
+    }
+
+    public void lockNow() {
+        if (!mHasFeature) {
+            return;
+        }
+        synchronized (this) {
+            // 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_FORCE_LOCK);
+            lockNowUnchecked();
+        }
+    }
+
+    private void lockNowUnchecked() {
+        long ident = Binder.clearCallingIdentity();
+        try {
+            // Power off the display
+            getIPowerManager().goToSleep(SystemClock.uptimeMillis(),
+                    PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN);
+            // Ensure the device is locked
+            getWindowManager().lockNow(null);
+        } catch (RemoteException e) {
+        } finally {
+            Binder.restoreCallingIdentity(ident);
+        }
+    }
+
+    private boolean isExtStorageEncrypted() {
+        String state = SystemProperties.get("vold.decrypt");
+        return !"".equals(state);
+    }
+
+    public boolean installCaCert(byte[] certBuffer) throws RemoteException {
+        mContext.enforceCallingOrSelfPermission(MANAGE_CA_CERTIFICATES, null);
+        KeyChainConnection keyChainConnection = null;
+        byte[] pemCert;
+        try {
+            X509Certificate cert = parseCert(certBuffer);
+            pemCert =  Credentials.convertToPem(cert);
+        } catch (CertificateException ce) {
+            Log.e(LOG_TAG, "Problem converting cert", ce);
+            return false;
+        } catch (IOException ioe) {
+            Log.e(LOG_TAG, "Problem reading cert", ioe);
+            return false;
+        }
+        try {
+            keyChainConnection = KeyChain.bind(mContext);
+            try {
+                keyChainConnection.getService().installCaCertificate(pemCert);
+                return true;
+            } finally {
+                if (keyChainConnection != null) {
+                    keyChainConnection.close();
+                    keyChainConnection = null;
+                }
+            }
+        } catch (InterruptedException e1) {
+            Log.w(LOG_TAG, "installCaCertsToKeyChain(): ", e1);
+            Thread.currentThread().interrupt();
+        }
+        return false;
+    }
+
+    private static X509Certificate parseCert(byte[] certBuffer)
+            throws CertificateException, IOException {
+        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+        return (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(
+                certBuffer));
+    }
+
+    public void uninstallCaCert(final byte[] certBuffer) {
+        mContext.enforceCallingOrSelfPermission(MANAGE_CA_CERTIFICATES, null);
+        TrustedCertificateStore certStore = new TrustedCertificateStore();
+        String alias = null;
+        try {
+            X509Certificate cert = parseCert(certBuffer);
+            alias = certStore.getCertificateAlias(cert);
+        } catch (CertificateException ce) {
+            Log.e(LOG_TAG, "Problem creating X509Certificate", ce);
+            return;
+        } catch (IOException ioe) {
+            Log.e(LOG_TAG, "Problem reading certificate", ioe);
+            return;
+        }
+        try {
+            KeyChainConnection keyChainConnection = KeyChain.bind(mContext);
+            IKeyChainService service = keyChainConnection.getService();
+            try {
+                service.deleteCaCertificate(alias);
+            } catch (RemoteException e) {
+                Log.e(LOG_TAG, "from CaCertUninstaller: ", e);
+            } finally {
+                keyChainConnection.close();
+                keyChainConnection = null;
+            }
+        } catch (InterruptedException ie) {
+            Log.w(LOG_TAG, "CaCertUninstaller: ", ie);
+            Thread.currentThread().interrupt();
+        }
+    }
+
+    void wipeDataLocked(int flags) {
+        // If the SD card is encrypted and non-removable, we have to force a wipe.
+        boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted();
+        boolean wipeExtRequested = (flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0;
+
+        // Note: we can only do the wipe via ExternalStorageFormatter if the volume is not emulated.
+        if ((forceExtWipe || wipeExtRequested) && !Environment.isExternalStorageEmulated()) {
+            Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
+            intent.putExtra(ExternalStorageFormatter.EXTRA_ALWAYS_RESET, true);
+            intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
+            mWakeLock.acquire(10000);
+            mContext.startService(intent);
+        } else {
+            try {
+                RecoverySystem.rebootWipeUserData(mContext);
+            } catch (IOException e) {
+                Slog.w(LOG_TAG, "Failed requesting data wipe", e);
+            }
+        }
+    }
+
+    public void wipeData(int flags, final int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            // 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_WIPE_DATA);
+            long ident = Binder.clearCallingIdentity();
+            try {
+                wipeDeviceOrUserLocked(flags, userHandle);
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    private void wipeDeviceOrUserLocked(int flags, final int userHandle) {
+        if (userHandle == UserHandle.USER_OWNER) {
+            wipeDataLocked(flags);
+        } else {
+            lockNowUnchecked();
+            mHandler.post(new Runnable() {
+                public void run() {
+                    try {
+                        ActivityManagerNative.getDefault().switchUser(UserHandle.USER_OWNER);
+                        ((UserManager) mContext.getSystemService(Context.USER_SERVICE))
+                                .removeUser(userHandle);
+                    } catch (RemoteException re) {
+                        // Shouldn't happen
+                    }
+                }
+            });
+        }
+    }
+
+    public void getRemoveWarning(ComponentName comp, final RemoteCallback result, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
+
+        synchronized (this) {
+            ActiveAdmin admin = getActiveAdminUncheckedLocked(comp, userHandle);
+            if (admin == null) {
+                try {
+                    result.sendResult(null);
+                } catch (RemoteException e) {
+                }
+                return;
+            }
+            Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED);
+            intent.setComponent(admin.info.getComponent());
+            mContext.sendOrderedBroadcastAsUser(intent, new UserHandle(userHandle),
+                    null, new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    try {
+                        result.sendResult(getResultExtras(false));
+                    } catch (RemoteException e) {
+                    }
+                }
+            }, null, Activity.RESULT_OK, null, null);
+        }
+    }
+
+    public void setActivePasswordState(int quality, int length, int letters, int uppercase,
+            int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
+        DevicePolicyData p = getUserData(userHandle);
+
+        validateQualityConstant(quality);
+
+        synchronized (this) {
+            if (p.mActivePasswordQuality != quality || p.mActivePasswordLength != length
+                    || p.mFailedPasswordAttempts != 0 || p.mActivePasswordLetters != letters
+                    || p.mActivePasswordUpperCase != uppercase
+                    || p.mActivePasswordLowerCase != lowercase
+                    || p.mActivePasswordNumeric != numbers
+                    || p.mActivePasswordSymbols != symbols
+                    || p.mActivePasswordNonLetter != nonletter) {
+                long ident = Binder.clearCallingIdentity();
+                try {
+                    p.mActivePasswordQuality = quality;
+                    p.mActivePasswordLength = length;
+                    p.mActivePasswordLetters = letters;
+                    p.mActivePasswordLowerCase = lowercase;
+                    p.mActivePasswordUpperCase = uppercase;
+                    p.mActivePasswordNumeric = numbers;
+                    p.mActivePasswordSymbols = symbols;
+                    p.mActivePasswordNonLetter = nonletter;
+                    p.mFailedPasswordAttempts = 0;
+                    saveSettingsLocked(userHandle);
+                    updatePasswordExpirationsLocked(userHandle);
+                    setExpirationAlarmCheckLocked(mContext, p);
+                    sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED,
+                            DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD, userHandle);
+                } finally {
+                    Binder.restoreCallingIdentity(ident);
+                }
+            }
+        }
+    }
+
+    /**
+     * Called any time the device password is updated.  Resets all password expiration clocks.
+     */
+    private void updatePasswordExpirationsLocked(int userHandle) {
+        DevicePolicyData policy = getUserData(userHandle);
+        final int N = policy.mAdminList.size();
+        if (N > 0) {
+            for (int i=0; i<N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD)) {
+                    long timeout = admin.passwordExpirationTimeout;
+                    long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L;
+                    admin.passwordExpirationDate = expiration;
+                }
+            }
+            saveSettingsLocked(userHandle);
+        }
+    }
+
+    public void reportFailedPasswordAttempt(int userHandle) {
+        enforceCrossUserPermission(userHandle);
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
+
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            long ident = Binder.clearCallingIdentity();
+            try {
+                policy.mFailedPasswordAttempts++;
+                saveSettingsLocked(userHandle);
+                if (mHasFeature) {
+                    int max = getMaximumFailedPasswordsForWipe(null, userHandle);
+                    if (max > 0 && policy.mFailedPasswordAttempts >= max) {
+                        wipeDeviceOrUserLocked(0, userHandle);
+                    }
+                    sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED,
+                            DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
+    public void reportSuccessfulPasswordAttempt(int userHandle) {
+        enforceCrossUserPermission(userHandle);
+        mContext.enforceCallingOrSelfPermission(
+                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
+
+        synchronized (this) {
+            DevicePolicyData policy = getUserData(userHandle);
+            if (policy.mFailedPasswordAttempts != 0 || policy.mPasswordOwner >= 0) {
+                long ident = Binder.clearCallingIdentity();
+                try {
+                    policy.mFailedPasswordAttempts = 0;
+                    policy.mPasswordOwner = -1;
+                    saveSettingsLocked(userHandle);
+                    if (mHasFeature) {
+                        sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED,
+                                DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle);
+                    }
+                } finally {
+                    Binder.restoreCallingIdentity(ident);
+                }
+            }
+        }
+    }
+
+    public ComponentName setGlobalProxy(ComponentName who, String proxySpec,
+            String exclusionList, int userHandle) {
+        if (!mHasFeature) {
+            return null;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized(this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+
+            // Only check if owner has set global proxy. We don't allow other users to set it.
+            DevicePolicyData policy = getUserData(UserHandle.USER_OWNER);
+            ActiveAdmin admin = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY);
+
+            // Scan through active admins and find if anyone has already
+            // set the global proxy.
+            Set<ComponentName> compSet = policy.mAdminMap.keySet();
+            for  (ComponentName component : compSet) {
+                ActiveAdmin ap = policy.mAdminMap.get(component);
+                if ((ap.specifiesGlobalProxy) && (!component.equals(who))) {
+                    // Another admin already sets the global proxy
+                    // Return it to the caller.
+                    return component;
+                }
+            }
+
+            // If the user is not the owner, don't set the global proxy. Fail silently.
+            if (UserHandle.getCallingUserId() != UserHandle.USER_OWNER) {
+                Slog.w(LOG_TAG, "Only the owner is allowed to set the global proxy. User "
+                        + userHandle + " is not permitted.");
+                return null;
+            }
+            if (proxySpec == null) {
+                admin.specifiesGlobalProxy = false;
+                admin.globalProxySpec = null;
+                admin.globalProxyExclusionList = null;
+            } else {
+
+                admin.specifiesGlobalProxy = true;
+                admin.globalProxySpec = proxySpec;
+                admin.globalProxyExclusionList = exclusionList;
+            }
+
+            // Reset the global proxy accordingly
+            // Do this using system permissions, as apps cannot write to secure settings
+            long origId = Binder.clearCallingIdentity();
+            resetGlobalProxyLocked(policy);
+            Binder.restoreCallingIdentity(origId);
+            return null;
+        }
+    }
+
+    public ComponentName getGlobalProxyAdmin(int userHandle) {
+        if (!mHasFeature) {
+            return null;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized(this) {
+            DevicePolicyData policy = getUserData(UserHandle.USER_OWNER);
+            // Scan through active admins and find if anyone has already
+            // set the global proxy.
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin ap = policy.mAdminList.get(i);
+                if (ap.specifiesGlobalProxy) {
+                    // Device admin sets the global proxy
+                    // Return it to the caller.
+                    return ap.info.getComponent();
+                }
+            }
+        }
+        // No device admin sets the global proxy.
+        return null;
+    }
+
+    private void resetGlobalProxyLocked(DevicePolicyData policy) {
+        final int N = policy.mAdminList.size();
+        for (int i = 0; i < N; i++) {
+            ActiveAdmin ap = policy.mAdminList.get(i);
+            if (ap.specifiesGlobalProxy) {
+                saveGlobalProxyLocked(ap.globalProxySpec, ap.globalProxyExclusionList);
+                return;
+            }
+        }
+        // No device admins defining global proxies - reset global proxy settings to none
+        saveGlobalProxyLocked(null, null);
+    }
+
+    private void saveGlobalProxyLocked(String proxySpec, String exclusionList) {
+        if (exclusionList == null) {
+            exclusionList = "";
+        }
+        if (proxySpec == null) {
+            proxySpec = "";
+        }
+        // Remove white spaces
+        proxySpec = proxySpec.trim();
+        String data[] = proxySpec.split(":");
+        int proxyPort = 8080;
+        if (data.length > 1) {
+            try {
+                proxyPort = Integer.parseInt(data[1]);
+            } catch (NumberFormatException e) {}
+        }
+        exclusionList = exclusionList.trim();
+        ContentResolver res = mContext.getContentResolver();
+
+        ProxyProperties proxyProperties = new ProxyProperties(data[0], proxyPort, exclusionList);
+        if (!proxyProperties.isValid()) {
+            Slog.e(LOG_TAG, "Invalid proxy properties, ignoring: " + proxyProperties.toString());
+            return;
+        }
+        Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, data[0]);
+        Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, proxyPort);
+        Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
+                exclusionList);
+    }
+
+    /**
+     * Set the storage encryption request for a single admin.  Returns the new total request
+     * status (for all admins).
+     */
+    public int setStorageEncryption(ComponentName who, boolean encrypt, int userHandle) {
+        if (!mHasFeature) {
+            return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            // Check for permissions
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            // Only owner can set storage encryption
+            if (userHandle != UserHandle.USER_OWNER
+                    || UserHandle.getCallingUserId() != UserHandle.USER_OWNER) {
+                Slog.w(LOG_TAG, "Only owner is allowed to set storage encryption. User "
+                        + UserHandle.getCallingUserId() + " is not permitted.");
+                return 0;
+            }
+
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_ENCRYPTED_STORAGE);
+
+            // Quick exit:  If the filesystem does not support encryption, we can exit early.
+            if (!isEncryptionSupported()) {
+                return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
+            }
+
+            // (1) Record the value for the admin so it's sticky
+            if (ap.encryptionRequested != encrypt) {
+                ap.encryptionRequested = encrypt;
+                saveSettingsLocked(userHandle);
+            }
+
+            DevicePolicyData policy = getUserData(UserHandle.USER_OWNER);
+            // (2) Compute "max" for all admins
+            boolean newRequested = false;
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                newRequested |= policy.mAdminList.get(i).encryptionRequested;
+            }
+
+            // Notify OS of new request
+            setEncryptionRequested(newRequested);
+
+            // Return the new global request status
+            return newRequested
+                    ? DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE
+                    : DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE;
+        }
+    }
+
+    /**
+     * Get the current storage encryption request status for a given admin, or aggregate of all
+     * active admins.
+     */
+    public boolean getStorageEncryption(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return false;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            // Check for permissions if a particular caller is specified
+            if (who != null) {
+                // When checking for a single caller, status is based on caller's request
+                ActiveAdmin ap = getActiveAdminUncheckedLocked(who, userHandle);
+                return ap != null ? ap.encryptionRequested : false;
+            }
+
+            // If no particular caller is specified, return the aggregate set of requests.
+            // This is short circuited by returning true on the first hit.
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                if (policy.mAdminList.get(i).encryptionRequested) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    /**
+     * Get the current encryption status of the device.
+     */
+    public int getStorageEncryptionStatus(int userHandle) {
+        if (!mHasFeature) {
+            // Ok to return current status.
+        }
+        enforceCrossUserPermission(userHandle);
+        return getEncryptionStatus();
+    }
+
+    /**
+     * Hook to low-levels:  This should report if the filesystem supports encrypted storage.
+     */
+    private boolean isEncryptionSupported() {
+        // Note, this can be implemented as
+        //   return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
+        // But is provided as a separate internal method if there's a faster way to do a
+        // simple check for supported-or-not.
+        return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
+    }
+
+    /**
+     * Hook to low-levels:  Reporting the current status of encryption.
+     * @return A value such as {@link DevicePolicyManager#ENCRYPTION_STATUS_UNSUPPORTED} or
+     * {@link DevicePolicyManager#ENCRYPTION_STATUS_INACTIVE} or
+     * {@link DevicePolicyManager#ENCRYPTION_STATUS_ACTIVE}.
+     */
+    private int getEncryptionStatus() {
+        String status = SystemProperties.get("ro.crypto.state", "unsupported");
+        if ("encrypted".equalsIgnoreCase(status)) {
+            return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
+        } else if ("unencrypted".equalsIgnoreCase(status)) {
+            return DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE;
+        } else {
+            return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
+        }
+    }
+
+    /**
+     * Hook to low-levels:  If needed, record the new admin setting for encryption.
+     */
+    private void setEncryptionRequested(boolean encrypt) {
+    }
+
+    /**
+     * The system property used to share the state of the camera. The native camera service
+     * is expected to read this property and act accordingly.
+     */
+    public static final String SYSTEM_PROP_DISABLE_CAMERA = "sys.secpolicy.camera.disabled";
+
+    /**
+     * Disables all device cameras according to the specified admin.
+     */
+    public void setCameraDisabled(ComponentName who, boolean disabled, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_DISABLE_CAMERA);
+            if (ap.disableCamera != disabled) {
+                ap.disableCamera = disabled;
+                saveSettingsLocked(userHandle);
+            }
+            syncDeviceCapabilitiesLocked(getUserData(userHandle));
+        }
+    }
+
+    /**
+     * Gets whether or not all device cameras are disabled for a given admin, or disabled for any
+     * active admins.
+     */
+    public boolean getCameraDisabled(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return false;
+        }
+        synchronized (this) {
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return (admin != null) ? admin.disableCamera : false;
+            }
+
+            DevicePolicyData policy = getUserData(userHandle);
+            // Determine whether or not the device camera is disabled for any active admins.
+            final int N = policy.mAdminList.size();
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                if (admin.disableCamera) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    /**
+     * Selectively disable keyguard features.
+     */
+    public void setKeyguardDisabledFeatures(ComponentName who, int which, int userHandle) {
+        if (!mHasFeature) {
+            return;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who == null) {
+                throw new NullPointerException("ComponentName is null");
+            }
+            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
+                    DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES);
+            if (ap.disabledKeyguardFeatures != which) {
+                ap.disabledKeyguardFeatures = which;
+                saveSettingsLocked(userHandle);
+            }
+            syncDeviceCapabilitiesLocked(getUserData(userHandle));
+        }
+    }
+
+    /**
+     * Gets the disabled state for features in keyguard for the given admin,
+     * or the aggregate of all active admins if who is null.
+     */
+    public int getKeyguardDisabledFeatures(ComponentName who, int userHandle) {
+        if (!mHasFeature) {
+            return 0;
+        }
+        enforceCrossUserPermission(userHandle);
+        synchronized (this) {
+            if (who != null) {
+                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
+                return (admin != null) ? admin.disabledKeyguardFeatures : 0;
+            }
+
+            // Determine which keyguard features are disabled for any active admins.
+            DevicePolicyData policy = getUserData(userHandle);
+            final int N = policy.mAdminList.size();
+            int which = 0;
+            for (int i = 0; i < N; i++) {
+                ActiveAdmin admin = policy.mAdminList.get(i);
+                which |= admin.disabledKeyguardFeatures;
+            }
+            return which;
+        }
+    }
+
+    @Override
+    public boolean setDeviceOwner(String packageName, String ownerName) {
+        if (!mHasFeature) {
+            return false;
+        }
+        if (packageName == null
+                || !DeviceOwner.isInstalled(packageName, mContext.getPackageManager())) {
+            throw new IllegalArgumentException("Invalid package name " + packageName
+                    + " for device owner");
+        }
+        synchronized (this) {
+            if (mDeviceOwner == null && !isDeviceProvisioned()) {
+                mDeviceOwner = new DeviceOwner(packageName, ownerName);
+                mDeviceOwner.writeOwnerFile();
+                return true;
+            } else {
+                throw new IllegalStateException("Trying to set device owner to " + packageName
+                        + ", owner=" + mDeviceOwner.getPackageName()
+                        + ", device_provisioned=" + isDeviceProvisioned());
+            }
+        }
+    }
+
+    @Override
+    public boolean isDeviceOwner(String packageName) {
+        if (!mHasFeature) {
+            return false;
+        }
+        synchronized (this) {
+            return mDeviceOwner != null
+                    && mDeviceOwner.getPackageName().equals(packageName);
+        }
+    }
+
+    @Override
+    public String getDeviceOwner() {
+        if (!mHasFeature) {
+            return null;
+        }
+        synchronized (this) {
+            if (mDeviceOwner != null) {
+                return mDeviceOwner.getPackageName();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public String getDeviceOwnerName() {
+        if (!mHasFeature) {
+            return null;
+        }
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
+        synchronized (this) {
+            if (mDeviceOwner != null) {
+                return mDeviceOwner.getName();
+            }
+        }
+        return null;
+    }
+
+    private boolean isDeviceProvisioned() {
+        return Settings.Global.getInt(mContext.getContentResolver(),
+                Settings.Global.DEVICE_PROVISIONED, 0) > 0;
+    }
+
+    private void enforceCrossUserPermission(int userHandle) {
+        if (userHandle < 0) {
+            throw new IllegalArgumentException("Invalid userId " + userHandle);
+        }
+        final int callingUid = Binder.getCallingUid();
+        if (userHandle == UserHandle.getUserId(callingUid)) return;
+        if (callingUid != Process.SYSTEM_UID && callingUid != 0) {
+            mContext.enforceCallingOrSelfPermission(
+                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "Must be system or have"
+                    + " INTERACT_ACROSS_USERS_FULL permission");
+        }
+    }
+
+    private void enableIfNecessary(String packageName, int userId) {
+        try {
+            IPackageManager ipm = AppGlobals.getPackageManager();
+            ApplicationInfo ai = ipm.getApplicationInfo(packageName,
+                    PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
+                    userId);
+            if (ai.enabledSetting
+                    == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
+                ipm.setApplicationEnabledSetting(packageName,
+                        PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
+                        PackageManager.DONT_KILL_APP, userId, "DevicePolicyManager");
+            }
+        } catch (RemoteException e) {
+        }
+    }
+
+    @Override
+    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+                != PackageManager.PERMISSION_GRANTED) {
+
+            pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid="
+                    + Binder.getCallingPid()
+                    + ", uid=" + Binder.getCallingUid());
+            return;
+        }
+
+        final Printer p = new PrintWriterPrinter(pw);
+
+        synchronized (this) {
+            p.println("Current Device Policy Manager state:");
+
+            int userCount = mUserData.size();
+            for (int u = 0; u < userCount; u++) {
+                DevicePolicyData policy = getUserData(mUserData.keyAt(u));
+                p.println("  Enabled Device Admins (User " + policy.mUserHandle + "):");
+                final int N = policy.mAdminList.size();
+                for (int i=0; i<N; i++) {
+                    ActiveAdmin ap = policy.mAdminList.get(i);
+                    if (ap != null) {
+                        pw.print("  "); pw.print(ap.info.getComponent().flattenToShortString());
+                                pw.println(":");
+                        ap.dump("    ", pw);
+                    }
+                }
+
+                pw.println(" ");
+                pw.print("  mPasswordOwner="); pw.println(policy.mPasswordOwner);
+            }
+        }
+    }
+
+    static class DeviceOwner {
+        private static final String DEVICE_OWNER_XML = "device_owner.xml";
+        private static final String TAG_DEVICE_OWNER = "device-owner";
+        private static final String ATTR_NAME = "name";
+        private static final String ATTR_PACKAGE = "package";
+        private String mPackageName;
+        private String mOwnerName;
+
+        DeviceOwner() {
+            readOwnerFile();
+        }
+
+        DeviceOwner(String packageName, String ownerName) {
+            this.mPackageName = packageName;
+            this.mOwnerName = ownerName;
+        }
+
+        static boolean isRegistered() {
+            return new File(Environment.getSystemSecureDirectory(),
+                    DEVICE_OWNER_XML).exists();
+        }
+
+        String getPackageName() {
+            return mPackageName;
+        }
+
+        String getName() {
+            return mOwnerName;
+        }
+
+        static boolean isInstalled(String packageName, PackageManager pm) {
+            try {
+                PackageInfo pi;
+                if ((pi = pm.getPackageInfo(packageName, 0)) != null) {
+                    if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                        return true;
+                    }
+                }
+            } catch (NameNotFoundException nnfe) {
+                Slog.w(LOG_TAG, "Device Owner package " + packageName + " not installed.");
+            }
+            return false;
+        }
+
+        void readOwnerFile() {
+            AtomicFile file = new AtomicFile(new File(Environment.getSystemSecureDirectory(),
+                    DEVICE_OWNER_XML));
+            try {
+                FileInputStream input = file.openRead();
+                XmlPullParser parser = Xml.newPullParser();
+                parser.setInput(input, null);
+                int type;
+                while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
+                        && type != XmlPullParser.START_TAG) {
+                }
+                String tag = parser.getName();
+                if (!TAG_DEVICE_OWNER.equals(tag)) {
+                    throw new XmlPullParserException(
+                            "Device Owner file does not start with device-owner tag: found " + tag);
+                }
+                mPackageName = parser.getAttributeValue(null, ATTR_PACKAGE);
+                mOwnerName = parser.getAttributeValue(null, ATTR_NAME);
+                input.close();
+            } catch (XmlPullParserException xppe) {
+                Slog.e(LOG_TAG, "Error parsing device-owner file\n" + xppe);
+            } catch (IOException ioe) {
+                Slog.e(LOG_TAG, "IO Exception when reading device-owner file\n" + ioe);
+            }
+        }
+
+        void writeOwnerFile() {
+            synchronized (this) {
+                writeOwnerFileLocked();
+            }
+        }
+
+        private void writeOwnerFileLocked() {
+            AtomicFile file = new AtomicFile(new File(Environment.getSystemSecureDirectory(),
+                    DEVICE_OWNER_XML));
+            try {
+                FileOutputStream output = file.startWrite();
+                XmlSerializer out = new FastXmlSerializer();
+                out.setOutput(output, "utf-8");
+                out.startDocument(null, true);
+                out.startTag(null, TAG_DEVICE_OWNER);
+                out.attribute(null, ATTR_PACKAGE, mPackageName);
+                if (mOwnerName != null) {
+                    out.attribute(null, ATTR_NAME, mOwnerName);
+                }
+                out.endTag(null, TAG_DEVICE_OWNER);
+                out.endDocument();
+                out.flush();
+                file.finishWrite(output);
+            } catch (IOException ioe) {
+                Slog.e(LOG_TAG, "IO Exception when writing device-owner file\n" + ioe);
+            }
+        }
+    }
+}
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
deleted file mode 100644
index 4d70d5f..0000000
--- a/services/input/EventHub.cpp
+++ /dev/null
@@ -1,1583 +0,0 @@
-/*
- * Copyright (C) 2005 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.
- */
-
-#define LOG_TAG "EventHub"
-
-// #define LOG_NDEBUG 0
-
-#include "EventHub.h"
-
-#include <hardware_legacy/power.h>
-
-#include <cutils/properties.h>
-#include <utils/Log.h>
-#include <utils/Timers.h>
-#include <utils/threads.h>
-#include <utils/Errors.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <memory.h>
-#include <errno.h>
-#include <assert.h>
-
-#include <input/KeyLayoutMap.h>
-#include <input/KeyCharacterMap.h>
-#include <input/VirtualKeyMap.h>
-
-#include <string.h>
-#include <stdint.h>
-#include <dirent.h>
-
-#include <sys/inotify.h>
-#include <sys/epoll.h>
-#include <sys/ioctl.h>
-#include <sys/limits.h>
-#include <sys/sha1.h>
-
-/* this macro is used to tell if "bit" is set in "array"
- * it selects a byte from the array, and does a boolean AND
- * operation with a byte that only has the relevant bit set.
- * eg. to check for the 12th bit, we do (array[1] & 1<<4)
- */
-#define test_bit(bit, array)    (array[bit/8] & (1<<(bit%8)))
-
-/* this macro computes the number of bytes needed to represent a bit array of the specified size */
-#define sizeof_bit_array(bits)  ((bits + 7) / 8)
-
-#define INDENT "  "
-#define INDENT2 "    "
-#define INDENT3 "      "
-
-namespace android {
-
-static const char *WAKE_LOCK_ID = "KeyEvents";
-static const char *DEVICE_PATH = "/dev/input";
-
-/* return the larger integer */
-static inline int max(int v1, int v2)
-{
-    return (v1 > v2) ? v1 : v2;
-}
-
-static inline const char* toString(bool value) {
-    return value ? "true" : "false";
-}
-
-static String8 sha1(const String8& in) {
-    SHA1_CTX ctx;
-    SHA1Init(&ctx);
-    SHA1Update(&ctx, reinterpret_cast<const u_char*>(in.string()), in.size());
-    u_char digest[SHA1_DIGEST_LENGTH];
-    SHA1Final(digest, &ctx);
-
-    String8 out;
-    for (size_t i = 0; i < SHA1_DIGEST_LENGTH; i++) {
-        out.appendFormat("%02x", digest[i]);
-    }
-    return out;
-}
-
-static void setDescriptor(InputDeviceIdentifier& identifier) {
-    // Compute a device descriptor that uniquely identifies the device.
-    // The descriptor is assumed to be a stable identifier.  Its value should not
-    // change between reboots, reconnections, firmware updates or new releases of Android.
-    // Ideally, we also want the descriptor to be short and relatively opaque.
-    String8 rawDescriptor;
-    rawDescriptor.appendFormat(":%04x:%04x:", identifier.vendor, identifier.product);
-    if (!identifier.uniqueId.isEmpty()) {
-        rawDescriptor.append("uniqueId:");
-        rawDescriptor.append(identifier.uniqueId);
-    } if (identifier.vendor == 0 && identifier.product == 0) {
-        // If we don't know the vendor and product id, then the device is probably
-        // built-in so we need to rely on other information to uniquely identify
-        // the input device.  Usually we try to avoid relying on the device name or
-        // location but for built-in input device, they are unlikely to ever change.
-        if (!identifier.name.isEmpty()) {
-            rawDescriptor.append("name:");
-            rawDescriptor.append(identifier.name);
-        } else if (!identifier.location.isEmpty()) {
-            rawDescriptor.append("location:");
-            rawDescriptor.append(identifier.location);
-        }
-    }
-    identifier.descriptor = sha1(rawDescriptor);
-    ALOGV("Created descriptor: raw=%s, cooked=%s", rawDescriptor.string(),
-            identifier.descriptor.string());
-}
-
-// --- Global Functions ---
-
-uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses) {
-    // Touch devices get dibs on touch-related axes.
-    if (deviceClasses & INPUT_DEVICE_CLASS_TOUCH) {
-        switch (axis) {
-        case ABS_X:
-        case ABS_Y:
-        case ABS_PRESSURE:
-        case ABS_TOOL_WIDTH:
-        case ABS_DISTANCE:
-        case ABS_TILT_X:
-        case ABS_TILT_Y:
-        case ABS_MT_SLOT:
-        case ABS_MT_TOUCH_MAJOR:
-        case ABS_MT_TOUCH_MINOR:
-        case ABS_MT_WIDTH_MAJOR:
-        case ABS_MT_WIDTH_MINOR:
-        case ABS_MT_ORIENTATION:
-        case ABS_MT_POSITION_X:
-        case ABS_MT_POSITION_Y:
-        case ABS_MT_TOOL_TYPE:
-        case ABS_MT_BLOB_ID:
-        case ABS_MT_TRACKING_ID:
-        case ABS_MT_PRESSURE:
-        case ABS_MT_DISTANCE:
-            return INPUT_DEVICE_CLASS_TOUCH;
-        }
-    }
-
-    // Joystick devices get the rest.
-    return deviceClasses & INPUT_DEVICE_CLASS_JOYSTICK;
-}
-
-// --- EventHub::Device ---
-
-EventHub::Device::Device(int fd, int32_t id, const String8& path,
-        const InputDeviceIdentifier& identifier) :
-        next(NULL),
-        fd(fd), id(id), path(path), identifier(identifier),
-        classes(0), configuration(NULL), virtualKeyMap(NULL),
-        ffEffectPlaying(false), ffEffectId(-1), controllerNumber(0),
-        timestampOverrideSec(0), timestampOverrideUsec(0) {
-    memset(keyBitmask, 0, sizeof(keyBitmask));
-    memset(absBitmask, 0, sizeof(absBitmask));
-    memset(relBitmask, 0, sizeof(relBitmask));
-    memset(swBitmask, 0, sizeof(swBitmask));
-    memset(ledBitmask, 0, sizeof(ledBitmask));
-    memset(ffBitmask, 0, sizeof(ffBitmask));
-    memset(propBitmask, 0, sizeof(propBitmask));
-}
-
-EventHub::Device::~Device() {
-    close();
-    delete configuration;
-    delete virtualKeyMap;
-}
-
-void EventHub::Device::close() {
-    if (fd >= 0) {
-        ::close(fd);
-        fd = -1;
-    }
-}
-
-
-// --- EventHub ---
-
-const uint32_t EventHub::EPOLL_ID_INOTIFY;
-const uint32_t EventHub::EPOLL_ID_WAKE;
-const int EventHub::EPOLL_SIZE_HINT;
-const int EventHub::EPOLL_MAX_EVENTS;
-
-EventHub::EventHub(void) :
-        mBuiltInKeyboardId(NO_BUILT_IN_KEYBOARD), mNextDeviceId(1), mControllerNumbers(),
-        mOpeningDevices(0), mClosingDevices(0),
-        mNeedToSendFinishedDeviceScan(false),
-        mNeedToReopenDevices(false), mNeedToScanDevices(true),
-        mPendingEventCount(0), mPendingEventIndex(0), mPendingINotify(false) {
-    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
-
-    mEpollFd = epoll_create(EPOLL_SIZE_HINT);
-    LOG_ALWAYS_FATAL_IF(mEpollFd < 0, "Could not create epoll instance.  errno=%d", errno);
-
-    mINotifyFd = inotify_init();
-    int result = inotify_add_watch(mINotifyFd, DEVICE_PATH, IN_DELETE | IN_CREATE);
-    LOG_ALWAYS_FATAL_IF(result < 0, "Could not register INotify for %s.  errno=%d",
-            DEVICE_PATH, errno);
-
-    struct epoll_event eventItem;
-    memset(&eventItem, 0, sizeof(eventItem));
-    eventItem.events = EPOLLIN;
-    eventItem.data.u32 = EPOLL_ID_INOTIFY;
-    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mINotifyFd, &eventItem);
-    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add INotify to epoll instance.  errno=%d", errno);
-
-    int wakeFds[2];
-    result = pipe(wakeFds);
-    LOG_ALWAYS_FATAL_IF(result != 0, "Could not create wake pipe.  errno=%d", errno);
-
-    mWakeReadPipeFd = wakeFds[0];
-    mWakeWritePipeFd = wakeFds[1];
-
-    result = fcntl(mWakeReadPipeFd, F_SETFL, O_NONBLOCK);
-    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake read pipe non-blocking.  errno=%d",
-            errno);
-
-    result = fcntl(mWakeWritePipeFd, F_SETFL, O_NONBLOCK);
-    LOG_ALWAYS_FATAL_IF(result != 0, "Could not make wake write pipe non-blocking.  errno=%d",
-            errno);
-
-    eventItem.data.u32 = EPOLL_ID_WAKE;
-    result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem);
-    LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance.  errno=%d",
-            errno);
-}
-
-EventHub::~EventHub(void) {
-    closeAllDevicesLocked();
-
-    while (mClosingDevices) {
-        Device* device = mClosingDevices;
-        mClosingDevices = device->next;
-        delete device;
-    }
-
-    ::close(mEpollFd);
-    ::close(mINotifyFd);
-    ::close(mWakeReadPipeFd);
-    ::close(mWakeWritePipeFd);
-
-    release_wake_lock(WAKE_LOCK_ID);
-}
-
-InputDeviceIdentifier EventHub::getDeviceIdentifier(int32_t deviceId) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device == NULL) return InputDeviceIdentifier();
-    return device->identifier;
-}
-
-uint32_t EventHub::getDeviceClasses(int32_t deviceId) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device == NULL) return 0;
-    return device->classes;
-}
-
-int32_t EventHub::getDeviceControllerNumber(int32_t deviceId) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device == NULL) return 0;
-    return device->controllerNumber;
-}
-
-void EventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && device->configuration) {
-        *outConfiguration = *device->configuration;
-    } else {
-        outConfiguration->clear();
-    }
-}
-
-status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
-        RawAbsoluteAxisInfo* outAxisInfo) const {
-    outAxisInfo->clear();
-
-    if (axis >= 0 && axis <= ABS_MAX) {
-        AutoMutex _l(mLock);
-
-        Device* device = getDeviceLocked(deviceId);
-        if (device && !device->isVirtual() && test_bit(axis, device->absBitmask)) {
-            struct input_absinfo info;
-            if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
-                ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
-                     axis, device->identifier.name.string(), device->fd, errno);
-                return -errno;
-            }
-
-            if (info.minimum != info.maximum) {
-                outAxisInfo->valid = true;
-                outAxisInfo->minValue = info.minimum;
-                outAxisInfo->maxValue = info.maximum;
-                outAxisInfo->flat = info.flat;
-                outAxisInfo->fuzz = info.fuzz;
-                outAxisInfo->resolution = info.resolution;
-            }
-            return OK;
-        }
-    }
-    return -1;
-}
-
-bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const {
-    if (axis >= 0 && axis <= REL_MAX) {
-        AutoMutex _l(mLock);
-
-        Device* device = getDeviceLocked(deviceId);
-        if (device) {
-            return test_bit(axis, device->relBitmask);
-        }
-    }
-    return false;
-}
-
-bool EventHub::hasInputProperty(int32_t deviceId, int property) const {
-    if (property >= 0 && property <= INPUT_PROP_MAX) {
-        AutoMutex _l(mLock);
-
-        Device* device = getDeviceLocked(deviceId);
-        if (device) {
-            return test_bit(property, device->propBitmask);
-        }
-    }
-    return false;
-}
-
-int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
-    if (scanCode >= 0 && scanCode <= KEY_MAX) {
-        AutoMutex _l(mLock);
-
-        Device* device = getDeviceLocked(deviceId);
-        if (device && !device->isVirtual() && test_bit(scanCode, device->keyBitmask)) {
-            uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)];
-            memset(keyState, 0, sizeof(keyState));
-            if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
-                return test_bit(scanCode, keyState) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
-            }
-        }
-    }
-    return AKEY_STATE_UNKNOWN;
-}
-
-int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
-    AutoMutex _l(mLock);
-
-    Device* device = getDeviceLocked(deviceId);
-    if (device && !device->isVirtual() && device->keyMap.haveKeyLayout()) {
-        Vector<int32_t> scanCodes;
-        device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes);
-        if (scanCodes.size() != 0) {
-            uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)];
-            memset(keyState, 0, sizeof(keyState));
-            if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
-                for (size_t i = 0; i < scanCodes.size(); i++) {
-                    int32_t sc = scanCodes.itemAt(i);
-                    if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, keyState)) {
-                        return AKEY_STATE_DOWN;
-                    }
-                }
-                return AKEY_STATE_UP;
-            }
-        }
-    }
-    return AKEY_STATE_UNKNOWN;
-}
-
-int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
-    if (sw >= 0 && sw <= SW_MAX) {
-        AutoMutex _l(mLock);
-
-        Device* device = getDeviceLocked(deviceId);
-        if (device && !device->isVirtual() && test_bit(sw, device->swBitmask)) {
-            uint8_t swState[sizeof_bit_array(SW_MAX + 1)];
-            memset(swState, 0, sizeof(swState));
-            if (ioctl(device->fd, EVIOCGSW(sizeof(swState)), swState) >= 0) {
-                return test_bit(sw, swState) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
-            }
-        }
-    }
-    return AKEY_STATE_UNKNOWN;
-}
-
-status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const {
-    *outValue = 0;
-
-    if (axis >= 0 && axis <= ABS_MAX) {
-        AutoMutex _l(mLock);
-
-        Device* device = getDeviceLocked(deviceId);
-        if (device && !device->isVirtual() && test_bit(axis, device->absBitmask)) {
-            struct input_absinfo info;
-            if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
-                ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
-                     axis, device->identifier.name.string(), device->fd, errno);
-                return -errno;
-            }
-
-            *outValue = info.value;
-            return OK;
-        }
-    }
-    return -1;
-}
-
-bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
-        const int32_t* keyCodes, uint8_t* outFlags) const {
-    AutoMutex _l(mLock);
-
-    Device* device = getDeviceLocked(deviceId);
-    if (device && device->keyMap.haveKeyLayout()) {
-        Vector<int32_t> scanCodes;
-        for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
-            scanCodes.clear();
-
-            status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(
-                    keyCodes[codeIndex], &scanCodes);
-            if (! err) {
-                // check the possible scan codes identified by the layout map against the
-                // map of codes actually emitted by the driver
-                for (size_t sc = 0; sc < scanCodes.size(); sc++) {
-                    if (test_bit(scanCodes[sc], device->keyBitmask)) {
-                        outFlags[codeIndex] = 1;
-                        break;
-                    }
-                }
-            }
-        }
-        return true;
-    }
-    return false;
-}
-
-status_t EventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
-        int32_t* outKeycode, uint32_t* outFlags) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-
-    if (device) {
-        // Check the key character map first.
-        sp<KeyCharacterMap> kcm = device->getKeyCharacterMap();
-        if (kcm != NULL) {
-            if (!kcm->mapKey(scanCode, usageCode, outKeycode)) {
-                *outFlags = 0;
-                return NO_ERROR;
-            }
-        }
-
-        // Check the key layout next.
-        if (device->keyMap.haveKeyLayout()) {
-            if (!device->keyMap.keyLayoutMap->mapKey(
-                    scanCode, usageCode, outKeycode, outFlags)) {
-                return NO_ERROR;
-            }
-        }
-    }
-
-    *outKeycode = 0;
-    *outFlags = 0;
-    return NAME_NOT_FOUND;
-}
-
-status_t EventHub::mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-
-    if (device && device->keyMap.haveKeyLayout()) {
-        status_t err = device->keyMap.keyLayoutMap->mapAxis(scanCode, outAxisInfo);
-        if (err == NO_ERROR) {
-            return NO_ERROR;
-        }
-    }
-
-    return NAME_NOT_FOUND;
-}
-
-void EventHub::setExcludedDevices(const Vector<String8>& devices) {
-    AutoMutex _l(mLock);
-
-    mExcludedDevices = devices;
-}
-
-bool EventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && scanCode >= 0 && scanCode <= KEY_MAX) {
-        if (test_bit(scanCode, device->keyBitmask)) {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool EventHub::hasLed(int32_t deviceId, int32_t led) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && led >= 0 && led <= LED_MAX) {
-        if (test_bit(led, device->ledBitmask)) {
-            return true;
-        }
-    }
-    return false;
-}
-
-void EventHub::setLedState(int32_t deviceId, int32_t led, bool on) {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && !device->isVirtual() && led >= 0 && led <= LED_MAX) {
-        struct input_event ev;
-        ev.time.tv_sec = 0;
-        ev.time.tv_usec = 0;
-        ev.type = EV_LED;
-        ev.code = led;
-        ev.value = on ? 1 : 0;
-
-        ssize_t nWrite;
-        do {
-            nWrite = write(device->fd, &ev, sizeof(struct input_event));
-        } while (nWrite == -1 && errno == EINTR);
-    }
-}
-
-void EventHub::getVirtualKeyDefinitions(int32_t deviceId,
-        Vector<VirtualKeyDefinition>& outVirtualKeys) const {
-    outVirtualKeys.clear();
-
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && device->virtualKeyMap) {
-        outVirtualKeys.appendVector(device->virtualKeyMap->getVirtualKeys());
-    }
-}
-
-sp<KeyCharacterMap> EventHub::getKeyCharacterMap(int32_t deviceId) const {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device) {
-        return device->getKeyCharacterMap();
-    }
-    return NULL;
-}
-
-bool EventHub::setKeyboardLayoutOverlay(int32_t deviceId,
-        const sp<KeyCharacterMap>& map) {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device) {
-        if (map != device->overlayKeyMap) {
-            device->overlayKeyMap = map;
-            device->combinedKeyMap = KeyCharacterMap::combine(
-                    device->keyMap.keyCharacterMap, map);
-            return true;
-        }
-    }
-    return false;
-}
-
-void EventHub::vibrate(int32_t deviceId, nsecs_t duration) {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && !device->isVirtual()) {
-        ff_effect effect;
-        memset(&effect, 0, sizeof(effect));
-        effect.type = FF_RUMBLE;
-        effect.id = device->ffEffectId;
-        effect.u.rumble.strong_magnitude = 0xc000;
-        effect.u.rumble.weak_magnitude = 0xc000;
-        effect.replay.length = (duration + 999999LL) / 1000000LL;
-        effect.replay.delay = 0;
-        if (ioctl(device->fd, EVIOCSFF, &effect)) {
-            ALOGW("Could not upload force feedback effect to device %s due to error %d.",
-                    device->identifier.name.string(), errno);
-            return;
-        }
-        device->ffEffectId = effect.id;
-
-        struct input_event ev;
-        ev.time.tv_sec = 0;
-        ev.time.tv_usec = 0;
-        ev.type = EV_FF;
-        ev.code = device->ffEffectId;
-        ev.value = 1;
-        if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) {
-            ALOGW("Could not start force feedback effect on device %s due to error %d.",
-                    device->identifier.name.string(), errno);
-            return;
-        }
-        device->ffEffectPlaying = true;
-    }
-}
-
-void EventHub::cancelVibrate(int32_t deviceId) {
-    AutoMutex _l(mLock);
-    Device* device = getDeviceLocked(deviceId);
-    if (device && !device->isVirtual()) {
-        if (device->ffEffectPlaying) {
-            device->ffEffectPlaying = false;
-
-            struct input_event ev;
-            ev.time.tv_sec = 0;
-            ev.time.tv_usec = 0;
-            ev.type = EV_FF;
-            ev.code = device->ffEffectId;
-            ev.value = 0;
-            if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) {
-                ALOGW("Could not stop force feedback effect on device %s due to error %d.",
-                        device->identifier.name.string(), errno);
-                return;
-            }
-        }
-    }
-}
-
-EventHub::Device* EventHub::getDeviceLocked(int32_t deviceId) const {
-    if (deviceId == BUILT_IN_KEYBOARD_ID) {
-        deviceId = mBuiltInKeyboardId;
-    }
-    ssize_t index = mDevices.indexOfKey(deviceId);
-    return index >= 0 ? mDevices.valueAt(index) : NULL;
-}
-
-EventHub::Device* EventHub::getDeviceByPathLocked(const char* devicePath) const {
-    for (size_t i = 0; i < mDevices.size(); i++) {
-        Device* device = mDevices.valueAt(i);
-        if (device->path == devicePath) {
-            return device;
-        }
-    }
-    return NULL;
-}
-
-size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
-    ALOG_ASSERT(bufferSize >= 1);
-
-    AutoMutex _l(mLock);
-
-    struct input_event readBuffer[bufferSize];
-
-    RawEvent* event = buffer;
-    size_t capacity = bufferSize;
-    bool awoken = false;
-    for (;;) {
-        nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
-
-        // Reopen input devices if needed.
-        if (mNeedToReopenDevices) {
-            mNeedToReopenDevices = false;
-
-            ALOGI("Reopening all input devices due to a configuration change.");
-
-            closeAllDevicesLocked();
-            mNeedToScanDevices = true;
-            break; // return to the caller before we actually rescan
-        }
-
-        // Report any devices that had last been added/removed.
-        while (mClosingDevices) {
-            Device* device = mClosingDevices;
-            ALOGV("Reporting device closed: id=%d, name=%s\n",
-                 device->id, device->path.string());
-            mClosingDevices = device->next;
-            event->when = now;
-            event->deviceId = device->id == mBuiltInKeyboardId ? BUILT_IN_KEYBOARD_ID : device->id;
-            event->type = DEVICE_REMOVED;
-            event += 1;
-            delete device;
-            mNeedToSendFinishedDeviceScan = true;
-            if (--capacity == 0) {
-                break;
-            }
-        }
-
-        if (mNeedToScanDevices) {
-            mNeedToScanDevices = false;
-            scanDevicesLocked();
-            mNeedToSendFinishedDeviceScan = true;
-        }
-
-        while (mOpeningDevices != NULL) {
-            Device* device = mOpeningDevices;
-            ALOGV("Reporting device opened: id=%d, name=%s\n",
-                 device->id, device->path.string());
-            mOpeningDevices = device->next;
-            event->when = now;
-            event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
-            event->type = DEVICE_ADDED;
-            event += 1;
-            mNeedToSendFinishedDeviceScan = true;
-            if (--capacity == 0) {
-                break;
-            }
-        }
-
-        if (mNeedToSendFinishedDeviceScan) {
-            mNeedToSendFinishedDeviceScan = false;
-            event->when = now;
-            event->type = FINISHED_DEVICE_SCAN;
-            event += 1;
-            if (--capacity == 0) {
-                break;
-            }
-        }
-
-        // Grab the next input event.
-        bool deviceChanged = false;
-        while (mPendingEventIndex < mPendingEventCount) {
-            const struct epoll_event& eventItem = mPendingEventItems[mPendingEventIndex++];
-            if (eventItem.data.u32 == EPOLL_ID_INOTIFY) {
-                if (eventItem.events & EPOLLIN) {
-                    mPendingINotify = true;
-                } else {
-                    ALOGW("Received unexpected epoll event 0x%08x for INotify.", eventItem.events);
-                }
-                continue;
-            }
-
-            if (eventItem.data.u32 == EPOLL_ID_WAKE) {
-                if (eventItem.events & EPOLLIN) {
-                    ALOGV("awoken after wake()");
-                    awoken = true;
-                    char buffer[16];
-                    ssize_t nRead;
-                    do {
-                        nRead = read(mWakeReadPipeFd, buffer, sizeof(buffer));
-                    } while ((nRead == -1 && errno == EINTR) || nRead == sizeof(buffer));
-                } else {
-                    ALOGW("Received unexpected epoll event 0x%08x for wake read pipe.",
-                            eventItem.events);
-                }
-                continue;
-            }
-
-            ssize_t deviceIndex = mDevices.indexOfKey(eventItem.data.u32);
-            if (deviceIndex < 0) {
-                ALOGW("Received unexpected epoll event 0x%08x for unknown device id %d.",
-                        eventItem.events, eventItem.data.u32);
-                continue;
-            }
-
-            Device* device = mDevices.valueAt(deviceIndex);
-            if (eventItem.events & EPOLLIN) {
-                int32_t readSize = read(device->fd, readBuffer,
-                        sizeof(struct input_event) * capacity);
-                if (readSize == 0 || (readSize < 0 && errno == ENODEV)) {
-                    // Device was removed before INotify noticed.
-                    ALOGW("could not get event, removed? (fd: %d size: %d bufferSize: %d "
-                            "capacity: %d errno: %d)\n",
-                            device->fd, readSize, bufferSize, capacity, errno);
-                    deviceChanged = true;
-                    closeDeviceLocked(device);
-                } else if (readSize < 0) {
-                    if (errno != EAGAIN && errno != EINTR) {
-                        ALOGW("could not get event (errno=%d)", errno);
-                    }
-                } else if ((readSize % sizeof(struct input_event)) != 0) {
-                    ALOGE("could not get event (wrong size: %d)", readSize);
-                } else {
-                    int32_t deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
-
-                    size_t count = size_t(readSize) / sizeof(struct input_event);
-                    for (size_t i = 0; i < count; i++) {
-                        struct input_event& iev = readBuffer[i];
-                        ALOGV("%s got: time=%d.%06d, type=%d, code=%d, value=%d",
-                                device->path.string(),
-                                (int) iev.time.tv_sec, (int) iev.time.tv_usec,
-                                iev.type, iev.code, iev.value);
-
-                        // Some input devices may have a better concept of the time
-                        // when an input event was actually generated than the kernel
-                        // which simply timestamps all events on entry to evdev.
-                        // This is a custom Android extension of the input protocol
-                        // mainly intended for use with uinput based device drivers.
-                        if (iev.type == EV_MSC) {
-                            if (iev.code == MSC_ANDROID_TIME_SEC) {
-                                device->timestampOverrideSec = iev.value;
-                                continue;
-                            } else if (iev.code == MSC_ANDROID_TIME_USEC) {
-                                device->timestampOverrideUsec = iev.value;
-                                continue;
-                            }
-                        }
-                        if (device->timestampOverrideSec || device->timestampOverrideUsec) {
-                            iev.time.tv_sec = device->timestampOverrideSec;
-                            iev.time.tv_usec = device->timestampOverrideUsec;
-                            if (iev.type == EV_SYN && iev.code == SYN_REPORT) {
-                                device->timestampOverrideSec = 0;
-                                device->timestampOverrideUsec = 0;
-                            }
-                            ALOGV("applied override time %d.%06d",
-                                    int(iev.time.tv_sec), int(iev.time.tv_usec));
-                        }
-
-#ifdef HAVE_POSIX_CLOCKS
-                        // Use the time specified in the event instead of the current time
-                        // so that downstream code can get more accurate estimates of
-                        // event dispatch latency from the time the event is enqueued onto
-                        // the evdev client buffer.
-                        //
-                        // The event's timestamp fortuitously uses the same monotonic clock
-                        // time base as the rest of Android.  The kernel event device driver
-                        // (drivers/input/evdev.c) obtains timestamps using ktime_get_ts().
-                        // The systemTime(SYSTEM_TIME_MONOTONIC) function we use everywhere
-                        // calls clock_gettime(CLOCK_MONOTONIC) which is implemented as a
-                        // system call that also queries ktime_get_ts().
-                        event->when = nsecs_t(iev.time.tv_sec) * 1000000000LL
-                                + nsecs_t(iev.time.tv_usec) * 1000LL;
-                        ALOGV("event time %lld, now %lld", event->when, now);
-
-                        // Bug 7291243: Add a guard in case the kernel generates timestamps
-                        // that appear to be far into the future because they were generated
-                        // using the wrong clock source.
-                        //
-                        // This can happen because when the input device is initially opened
-                        // it has a default clock source of CLOCK_REALTIME.  Any input events
-                        // enqueued right after the device is opened will have timestamps
-                        // generated using CLOCK_REALTIME.  We later set the clock source
-                        // to CLOCK_MONOTONIC but it is already too late.
-                        //
-                        // Invalid input event timestamps can result in ANRs, crashes and
-                        // and other issues that are hard to track down.  We must not let them
-                        // propagate through the system.
-                        //
-                        // Log a warning so that we notice the problem and recover gracefully.
-                        if (event->when >= now + 10 * 1000000000LL) {
-                            // Double-check.  Time may have moved on.
-                            nsecs_t time = systemTime(SYSTEM_TIME_MONOTONIC);
-                            if (event->when > time) {
-                                ALOGW("An input event from %s has a timestamp that appears to "
-                                        "have been generated using the wrong clock source "
-                                        "(expected CLOCK_MONOTONIC): "
-                                        "event time %lld, current time %lld, call time %lld.  "
-                                        "Using current time instead.",
-                                        device->path.string(), event->when, time, now);
-                                event->when = time;
-                            } else {
-                                ALOGV("Event time is ok but failed the fast path and required "
-                                        "an extra call to systemTime: "
-                                        "event time %lld, current time %lld, call time %lld.",
-                                        event->when, time, now);
-                            }
-                        }
-#else
-                        event->when = now;
-#endif
-                        event->deviceId = deviceId;
-                        event->type = iev.type;
-                        event->code = iev.code;
-                        event->value = iev.value;
-                        event += 1;
-                        capacity -= 1;
-                    }
-                    if (capacity == 0) {
-                        // The result buffer is full.  Reset the pending event index
-                        // so we will try to read the device again on the next iteration.
-                        mPendingEventIndex -= 1;
-                        break;
-                    }
-                }
-            } else if (eventItem.events & EPOLLHUP) {
-                ALOGI("Removing device %s due to epoll hang-up event.",
-                        device->identifier.name.string());
-                deviceChanged = true;
-                closeDeviceLocked(device);
-            } else {
-                ALOGW("Received unexpected epoll event 0x%08x for device %s.",
-                        eventItem.events, device->identifier.name.string());
-            }
-        }
-
-        // readNotify() will modify the list of devices so this must be done after
-        // processing all other events to ensure that we read all remaining events
-        // before closing the devices.
-        if (mPendingINotify && mPendingEventIndex >= mPendingEventCount) {
-            mPendingINotify = false;
-            readNotifyLocked();
-            deviceChanged = true;
-        }
-
-        // Report added or removed devices immediately.
-        if (deviceChanged) {
-            continue;
-        }
-
-        // Return now if we have collected any events or if we were explicitly awoken.
-        if (event != buffer || awoken) {
-            break;
-        }
-
-        // Poll for events.  Mind the wake lock dance!
-        // We hold a wake lock at all times except during epoll_wait().  This works due to some
-        // subtle choreography.  When a device driver has pending (unread) events, it acquires
-        // a kernel wake lock.  However, once the last pending event has been read, the device
-        // driver will release the kernel wake lock.  To prevent the system from going to sleep
-        // when this happens, the EventHub holds onto its own user wake lock while the client
-        // is processing events.  Thus the system can only sleep if there are no events
-        // pending or currently being processed.
-        //
-        // The timeout is advisory only.  If the device is asleep, it will not wake just to
-        // service the timeout.
-        mPendingEventIndex = 0;
-
-        mLock.unlock(); // release lock before poll, must be before release_wake_lock
-        release_wake_lock(WAKE_LOCK_ID);
-
-        int pollResult = epoll_wait(mEpollFd, mPendingEventItems, EPOLL_MAX_EVENTS, timeoutMillis);
-
-        acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
-        mLock.lock(); // reacquire lock after poll, must be after acquire_wake_lock
-
-        if (pollResult == 0) {
-            // Timed out.
-            mPendingEventCount = 0;
-            break;
-        }
-
-        if (pollResult < 0) {
-            // An error occurred.
-            mPendingEventCount = 0;
-
-            // Sleep after errors to avoid locking up the system.
-            // Hopefully the error is transient.
-            if (errno != EINTR) {
-                ALOGW("poll failed (errno=%d)\n", errno);
-                usleep(100000);
-            }
-        } else {
-            // Some events occurred.
-            mPendingEventCount = size_t(pollResult);
-        }
-    }
-
-    // All done, return the number of events we read.
-    return event - buffer;
-}
-
-void EventHub::wake() {
-    ALOGV("wake() called");
-
-    ssize_t nWrite;
-    do {
-        nWrite = write(mWakeWritePipeFd, "W", 1);
-    } while (nWrite == -1 && errno == EINTR);
-
-    if (nWrite != 1 && errno != EAGAIN) {
-        ALOGW("Could not write wake signal, errno=%d", errno);
-    }
-}
-
-void EventHub::scanDevicesLocked() {
-    status_t res = scanDirLocked(DEVICE_PATH);
-    if(res < 0) {
-        ALOGE("scan dir failed for %s\n", DEVICE_PATH);
-    }
-    if (mDevices.indexOfKey(VIRTUAL_KEYBOARD_ID) < 0) {
-        createVirtualKeyboardLocked();
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-static bool containsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex) {
-    const uint8_t* end = array + endIndex;
-    array += startIndex;
-    while (array != end) {
-        if (*(array++) != 0) {
-            return true;
-        }
-    }
-    return false;
-}
-
-static const int32_t GAMEPAD_KEYCODES[] = {
-        AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C,
-        AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z,
-        AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1,
-        AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2,
-        AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR,
-        AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE,
-        AKEYCODE_BUTTON_1, AKEYCODE_BUTTON_2, AKEYCODE_BUTTON_3, AKEYCODE_BUTTON_4,
-        AKEYCODE_BUTTON_5, AKEYCODE_BUTTON_6, AKEYCODE_BUTTON_7, AKEYCODE_BUTTON_8,
-        AKEYCODE_BUTTON_9, AKEYCODE_BUTTON_10, AKEYCODE_BUTTON_11, AKEYCODE_BUTTON_12,
-        AKEYCODE_BUTTON_13, AKEYCODE_BUTTON_14, AKEYCODE_BUTTON_15, AKEYCODE_BUTTON_16,
-};
-
-status_t EventHub::openDeviceLocked(const char *devicePath) {
-    char buffer[80];
-
-    ALOGV("Opening device: %s", devicePath);
-
-    int fd = open(devicePath, O_RDWR | O_CLOEXEC);
-    if(fd < 0) {
-        ALOGE("could not open %s, %s\n", devicePath, strerror(errno));
-        return -1;
-    }
-
-    InputDeviceIdentifier identifier;
-
-    // Get device name.
-    if(ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) {
-        //fprintf(stderr, "could not get device name for %s, %s\n", devicePath, strerror(errno));
-    } else {
-        buffer[sizeof(buffer) - 1] = '\0';
-        identifier.name.setTo(buffer);
-    }
-
-    // Check to see if the device is on our excluded list
-    for (size_t i = 0; i < mExcludedDevices.size(); i++) {
-        const String8& item = mExcludedDevices.itemAt(i);
-        if (identifier.name == item) {
-            ALOGI("ignoring event id %s driver %s\n", devicePath, item.string());
-            close(fd);
-            return -1;
-        }
-    }
-
-    // Get device driver version.
-    int driverVersion;
-    if(ioctl(fd, EVIOCGVERSION, &driverVersion)) {
-        ALOGE("could not get driver version for %s, %s\n", devicePath, strerror(errno));
-        close(fd);
-        return -1;
-    }
-
-    // Get device identifier.
-    struct input_id inputId;
-    if(ioctl(fd, EVIOCGID, &inputId)) {
-        ALOGE("could not get device input id for %s, %s\n", devicePath, strerror(errno));
-        close(fd);
-        return -1;
-    }
-    identifier.bus = inputId.bustype;
-    identifier.product = inputId.product;
-    identifier.vendor = inputId.vendor;
-    identifier.version = inputId.version;
-
-    // Get device physical location.
-    if(ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) {
-        //fprintf(stderr, "could not get location for %s, %s\n", devicePath, strerror(errno));
-    } else {
-        buffer[sizeof(buffer) - 1] = '\0';
-        identifier.location.setTo(buffer);
-    }
-
-    // Get device unique id.
-    if(ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) {
-        //fprintf(stderr, "could not get idstring for %s, %s\n", devicePath, strerror(errno));
-    } else {
-        buffer[sizeof(buffer) - 1] = '\0';
-        identifier.uniqueId.setTo(buffer);
-    }
-
-    // Fill in the descriptor.
-    setDescriptor(identifier);
-
-    // Make file descriptor non-blocking for use with poll().
-    if (fcntl(fd, F_SETFL, O_NONBLOCK)) {
-        ALOGE("Error %d making device file descriptor non-blocking.", errno);
-        close(fd);
-        return -1;
-    }
-
-    // Allocate device.  (The device object takes ownership of the fd at this point.)
-    int32_t deviceId = mNextDeviceId++;
-    Device* device = new Device(fd, deviceId, String8(devicePath), identifier);
-
-    ALOGV("add device %d: %s\n", deviceId, devicePath);
-    ALOGV("  bus:        %04x\n"
-         "  vendor      %04x\n"
-         "  product     %04x\n"
-         "  version     %04x\n",
-        identifier.bus, identifier.vendor, identifier.product, identifier.version);
-    ALOGV("  name:       \"%s\"\n", identifier.name.string());
-    ALOGV("  location:   \"%s\"\n", identifier.location.string());
-    ALOGV("  unique id:  \"%s\"\n", identifier.uniqueId.string());
-    ALOGV("  descriptor: \"%s\"\n", identifier.descriptor.string());
-    ALOGV("  driver:     v%d.%d.%d\n",
-        driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff);
-
-    // Load the configuration file for the device.
-    loadConfigurationLocked(device);
-
-    // Figure out the kinds of events the device reports.
-    ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask);
-    ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(device->absBitmask)), device->absBitmask);
-    ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask);
-    ioctl(fd, EVIOCGBIT(EV_SW, sizeof(device->swBitmask)), device->swBitmask);
-    ioctl(fd, EVIOCGBIT(EV_LED, sizeof(device->ledBitmask)), device->ledBitmask);
-    ioctl(fd, EVIOCGBIT(EV_FF, sizeof(device->ffBitmask)), device->ffBitmask);
-    ioctl(fd, EVIOCGPROP(sizeof(device->propBitmask)), device->propBitmask);
-
-    // See if this is a keyboard.  Ignore everything in the button range except for
-    // joystick and gamepad buttons which are handled like keyboards for the most part.
-    bool haveKeyboardKeys = containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC))
-            || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK),
-                    sizeof_bit_array(KEY_MAX + 1));
-    bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
-                    sizeof_bit_array(BTN_MOUSE))
-            || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK),
-                    sizeof_bit_array(BTN_DIGI));
-    if (haveKeyboardKeys || haveGamepadButtons) {
-        device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
-    }
-
-    // See if this is a cursor device such as a trackball or mouse.
-    if (test_bit(BTN_MOUSE, device->keyBitmask)
-            && test_bit(REL_X, device->relBitmask)
-            && test_bit(REL_Y, device->relBitmask)) {
-        device->classes |= INPUT_DEVICE_CLASS_CURSOR;
-    }
-
-    // See if this is a touch pad.
-    // Is this a new modern multi-touch driver?
-    if (test_bit(ABS_MT_POSITION_X, device->absBitmask)
-            && test_bit(ABS_MT_POSITION_Y, device->absBitmask)) {
-        // Some joysticks such as the PS3 controller report axes that conflict
-        // with the ABS_MT range.  Try to confirm that the device really is
-        // a touch screen.
-        if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) {
-            device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
-        }
-    // Is this an old style single-touch driver?
-    } else if (test_bit(BTN_TOUCH, device->keyBitmask)
-            && test_bit(ABS_X, device->absBitmask)
-            && test_bit(ABS_Y, device->absBitmask)) {
-        device->classes |= INPUT_DEVICE_CLASS_TOUCH;
-    }
-
-    // See if this device is a joystick.
-    // Assumes that joysticks always have gamepad buttons in order to distinguish them
-    // from other devices such as accelerometers that also have absolute axes.
-    if (haveGamepadButtons) {
-        uint32_t assumedClasses = device->classes | INPUT_DEVICE_CLASS_JOYSTICK;
-        for (int i = 0; i <= ABS_MAX; i++) {
-            if (test_bit(i, device->absBitmask)
-                    && (getAbsAxisUsage(i, assumedClasses) & INPUT_DEVICE_CLASS_JOYSTICK)) {
-                device->classes = assumedClasses;
-                break;
-            }
-        }
-    }
-
-    // Check whether this device has switches.
-    for (int i = 0; i <= SW_MAX; i++) {
-        if (test_bit(i, device->swBitmask)) {
-            device->classes |= INPUT_DEVICE_CLASS_SWITCH;
-            break;
-        }
-    }
-
-    // Check whether this device supports the vibrator.
-    if (test_bit(FF_RUMBLE, device->ffBitmask)) {
-        device->classes |= INPUT_DEVICE_CLASS_VIBRATOR;
-    }
-
-    // Configure virtual keys.
-    if ((device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
-        // Load the virtual keys for the touch screen, if any.
-        // We do this now so that we can make sure to load the keymap if necessary.
-        status_t status = loadVirtualKeyMapLocked(device);
-        if (!status) {
-            device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
-        }
-    }
-
-    // Load the key map.
-    // We need to do this for joysticks too because the key layout may specify axes.
-    status_t keyMapStatus = NAME_NOT_FOUND;
-    if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
-        // Load the keymap for the device.
-        keyMapStatus = loadKeyMapLocked(device);
-    }
-
-    // Configure the keyboard, gamepad or virtual keyboard.
-    if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) {
-        // Register the keyboard as a built-in keyboard if it is eligible.
-        if (!keyMapStatus
-                && mBuiltInKeyboardId == NO_BUILT_IN_KEYBOARD
-                && isEligibleBuiltInKeyboard(device->identifier,
-                        device->configuration, &device->keyMap)) {
-            mBuiltInKeyboardId = device->id;
-        }
-
-        // 'Q' key support = cheap test of whether this is an alpha-capable kbd
-        if (hasKeycodeLocked(device, AKEYCODE_Q)) {
-            device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
-        }
-
-        // See if this device has a DPAD.
-        if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) &&
-                hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) &&
-                hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) &&
-                hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) &&
-                hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) {
-            device->classes |= INPUT_DEVICE_CLASS_DPAD;
-        }
-
-        // See if this device has a gamepad.
-        for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES)/sizeof(GAMEPAD_KEYCODES[0]); i++) {
-            if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) {
-                device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
-                break;
-            }
-        }
-
-        // Disable kernel key repeat since we handle it ourselves
-        unsigned int repeatRate[] = {0,0};
-        if (ioctl(fd, EVIOCSREP, repeatRate)) {
-            ALOGW("Unable to disable kernel key repeat for %s: %s", devicePath, strerror(errno));
-        }
-    }
-
-    // If the device isn't recognized as something we handle, don't monitor it.
-    if (device->classes == 0) {
-        ALOGV("Dropping device: id=%d, path='%s', name='%s'",
-                deviceId, devicePath, device->identifier.name.string());
-        delete device;
-        return -1;
-    }
-
-    // Determine whether the device is external or internal.
-    if (isExternalDeviceLocked(device)) {
-        device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
-    }
-
-    if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_GAMEPAD)) {
-        device->controllerNumber = getNextControllerNumberLocked(device);
-    }
-
-    // Register with epoll.
-    struct epoll_event eventItem;
-    memset(&eventItem, 0, sizeof(eventItem));
-    eventItem.events = EPOLLIN;
-    eventItem.data.u32 = deviceId;
-    if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)) {
-        ALOGE("Could not add device fd to epoll instance.  errno=%d", errno);
-        delete device;
-        return -1;
-    }
-
-    // Enable wake-lock behavior on kernels that support it.
-    // TODO: Only need this for devices that can really wake the system.
-    bool usingSuspendBlockIoctl = !ioctl(fd, EVIOCSSUSPENDBLOCK, 1);
-
-    // Tell the kernel that we want to use the monotonic clock for reporting timestamps
-    // associated with input events.  This is important because the input system
-    // uses the timestamps extensively and assumes they were recorded using the monotonic
-    // clock.
-    //
-    // In older kernel, before Linux 3.4, there was no way to tell the kernel which
-    // clock to use to input event timestamps.  The standard kernel behavior was to
-    // record a real time timestamp, which isn't what we want.  Android kernels therefore
-    // contained a patch to the evdev_event() function in drivers/input/evdev.c to
-    // replace the call to do_gettimeofday() with ktime_get_ts() to cause the monotonic
-    // clock to be used instead of the real time clock.
-    //
-    // As of Linux 3.4, there is a new EVIOCSCLOCKID ioctl to set the desired clock.
-    // Therefore, we no longer require the Android-specific kernel patch described above
-    // as long as we make sure to set select the monotonic clock.  We do that here.
-    int clockId = CLOCK_MONOTONIC;
-    bool usingClockIoctl = !ioctl(fd, EVIOCSCLOCKID, &clockId);
-
-    ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
-            "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, "
-            "usingSuspendBlockIoctl=%s, usingClockIoctl=%s",
-         deviceId, fd, devicePath, device->identifier.name.string(),
-         device->classes,
-         device->configurationFile.string(),
-         device->keyMap.keyLayoutFile.string(),
-         device->keyMap.keyCharacterMapFile.string(),
-         toString(mBuiltInKeyboardId == deviceId),
-         toString(usingSuspendBlockIoctl), toString(usingClockIoctl));
-
-    addDeviceLocked(device);
-    return 0;
-}
-
-void EventHub::createVirtualKeyboardLocked() {
-    InputDeviceIdentifier identifier;
-    identifier.name = "Virtual";
-    identifier.uniqueId = "<virtual>";
-    setDescriptor(identifier);
-
-    Device* device = new Device(-1, VIRTUAL_KEYBOARD_ID, String8("<virtual>"), identifier);
-    device->classes = INPUT_DEVICE_CLASS_KEYBOARD
-            | INPUT_DEVICE_CLASS_ALPHAKEY
-            | INPUT_DEVICE_CLASS_DPAD
-            | INPUT_DEVICE_CLASS_VIRTUAL;
-    loadKeyMapLocked(device);
-    addDeviceLocked(device);
-}
-
-void EventHub::addDeviceLocked(Device* device) {
-    mDevices.add(device->id, device);
-    device->next = mOpeningDevices;
-    mOpeningDevices = device;
-}
-
-void EventHub::loadConfigurationLocked(Device* device) {
-    device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(
-            device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);
-    if (device->configurationFile.isEmpty()) {
-        ALOGD("No input device configuration file found for device '%s'.",
-                device->identifier.name.string());
-    } else {
-        status_t status = PropertyMap::load(device->configurationFile,
-                &device->configuration);
-        if (status) {
-            ALOGE("Error loading input device configuration file for device '%s'.  "
-                    "Using default configuration.",
-                    device->identifier.name.string());
-        }
-    }
-}
-
-status_t EventHub::loadVirtualKeyMapLocked(Device* device) {
-    // The virtual key map is supplied by the kernel as a system board property file.
-    String8 path;
-    path.append("/sys/board_properties/virtualkeys.");
-    path.append(device->identifier.name);
-    if (access(path.string(), R_OK)) {
-        return NAME_NOT_FOUND;
-    }
-    return VirtualKeyMap::load(path, &device->virtualKeyMap);
-}
-
-status_t EventHub::loadKeyMapLocked(Device* device) {
-    return device->keyMap.load(device->identifier, device->configuration);
-}
-
-bool EventHub::isExternalDeviceLocked(Device* device) {
-    if (device->configuration) {
-        bool value;
-        if (device->configuration->tryGetProperty(String8("device.internal"), value)) {
-            return !value;
-        }
-    }
-    return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH;
-}
-
-int32_t EventHub::getNextControllerNumberLocked(Device* device) {
-    if (mControllerNumbers.isFull()) {
-        ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s",
-                device->identifier.name.string());
-        return 0;
-    }
-    // Since the controller number 0 is reserved for non-controllers, translate all numbers up by
-    // one
-    return static_cast<int32_t>(mControllerNumbers.markFirstUnmarkedBit() + 1);
-}
-
-void EventHub::releaseControllerNumberLocked(Device* device) {
-    int32_t num = device->controllerNumber;
-    device->controllerNumber= 0;
-    if (num == 0) {
-        return;
-    }
-    mControllerNumbers.clearBit(static_cast<uint32_t>(num - 1));
-}
-
-
-bool EventHub::hasKeycodeLocked(Device* device, int keycode) const {
-    if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) {
-        return false;
-    }
-    
-    Vector<int32_t> scanCodes;
-    device->keyMap.keyLayoutMap->findScanCodesForKey(keycode, &scanCodes);
-    const size_t N = scanCodes.size();
-    for (size_t i=0; i<N && i<=KEY_MAX; i++) {
-        int32_t sc = scanCodes.itemAt(i);
-        if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) {
-            return true;
-        }
-    }
-    
-    return false;
-}
-
-status_t EventHub::closeDeviceByPathLocked(const char *devicePath) {
-    Device* device = getDeviceByPathLocked(devicePath);
-    if (device) {
-        closeDeviceLocked(device);
-        return 0;
-    }
-    ALOGV("Remove device: %s not found, device may already have been removed.", devicePath);
-    return -1;
-}
-
-void EventHub::closeAllDevicesLocked() {
-    while (mDevices.size() > 0) {
-        closeDeviceLocked(mDevices.valueAt(mDevices.size() - 1));
-    }
-}
-
-void EventHub::closeDeviceLocked(Device* device) {
-    ALOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n",
-         device->path.string(), device->identifier.name.string(), device->id,
-         device->fd, device->classes);
-
-    if (device->id == mBuiltInKeyboardId) {
-        ALOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
-                device->path.string(), mBuiltInKeyboardId);
-        mBuiltInKeyboardId = NO_BUILT_IN_KEYBOARD;
-    }
-
-    if (!device->isVirtual()) {
-        if (epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)) {
-            ALOGW("Could not remove device fd from epoll instance.  errno=%d", errno);
-        }
-    }
-
-    releaseControllerNumberLocked(device);
-
-    mDevices.removeItem(device->id);
-    device->close();
-
-    // Unlink for opening devices list if it is present.
-    Device* pred = NULL;
-    bool found = false;
-    for (Device* entry = mOpeningDevices; entry != NULL; ) {
-        if (entry == device) {
-            found = true;
-            break;
-        }
-        pred = entry;
-        entry = entry->next;
-    }
-    if (found) {
-        // Unlink the device from the opening devices list then delete it.
-        // We don't need to tell the client that the device was closed because
-        // it does not even know it was opened in the first place.
-        ALOGI("Device %s was immediately closed after opening.", device->path.string());
-        if (pred) {
-            pred->next = device->next;
-        } else {
-            mOpeningDevices = device->next;
-        }
-        delete device;
-    } else {
-        // Link into closing devices list.
-        // The device will be deleted later after we have informed the client.
-        device->next = mClosingDevices;
-        mClosingDevices = device;
-    }
-}
-
-status_t EventHub::readNotifyLocked() {
-    int res;
-    char devname[PATH_MAX];
-    char *filename;
-    char event_buf[512];
-    int event_size;
-    int event_pos = 0;
-    struct inotify_event *event;
-
-    ALOGV("EventHub::readNotify nfd: %d\n", mINotifyFd);
-    res = read(mINotifyFd, event_buf, sizeof(event_buf));
-    if(res < (int)sizeof(*event)) {
-        if(errno == EINTR)
-            return 0;
-        ALOGW("could not get event, %s\n", strerror(errno));
-        return -1;
-    }
-    //printf("got %d bytes of event information\n", res);
-
-    strcpy(devname, DEVICE_PATH);
-    filename = devname + strlen(devname);
-    *filename++ = '/';
-
-    while(res >= (int)sizeof(*event)) {
-        event = (struct inotify_event *)(event_buf + event_pos);
-        //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
-        if(event->len) {
-            strcpy(filename, event->name);
-            if(event->mask & IN_CREATE) {
-                openDeviceLocked(devname);
-            } else {
-                ALOGI("Removing device '%s' due to inotify event\n", devname);
-                closeDeviceByPathLocked(devname);
-            }
-        }
-        event_size = sizeof(*event) + event->len;
-        res -= event_size;
-        event_pos += event_size;
-    }
-    return 0;
-}
-
-status_t EventHub::scanDirLocked(const char *dirname)
-{
-    char devname[PATH_MAX];
-    char *filename;
-    DIR *dir;
-    struct dirent *de;
-    dir = opendir(dirname);
-    if(dir == NULL)
-        return -1;
-    strcpy(devname, dirname);
-    filename = devname + strlen(devname);
-    *filename++ = '/';
-    while((de = readdir(dir))) {
-        if(de->d_name[0] == '.' &&
-           (de->d_name[1] == '\0' ||
-            (de->d_name[1] == '.' && de->d_name[2] == '\0')))
-            continue;
-        strcpy(filename, de->d_name);
-        openDeviceLocked(devname);
-    }
-    closedir(dir);
-    return 0;
-}
-
-void EventHub::requestReopenDevices() {
-    ALOGV("requestReopenDevices() called");
-
-    AutoMutex _l(mLock);
-    mNeedToReopenDevices = true;
-}
-
-void EventHub::dump(String8& dump) {
-    dump.append("Event Hub State:\n");
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        dump.appendFormat(INDENT "BuiltInKeyboardId: %d\n", mBuiltInKeyboardId);
-
-        dump.append(INDENT "Devices:\n");
-
-        for (size_t i = 0; i < mDevices.size(); i++) {
-            const Device* device = mDevices.valueAt(i);
-            if (mBuiltInKeyboardId == device->id) {
-                dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n",
-                        device->id, device->identifier.name.string());
-            } else {
-                dump.appendFormat(INDENT2 "%d: %s\n", device->id,
-                        device->identifier.name.string());
-            }
-            dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
-            dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
-            dump.appendFormat(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.string());
-            dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string());
-            dump.appendFormat(INDENT3 "ControllerNumber: %d\n", device->controllerNumber);
-            dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string());
-            dump.appendFormat(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, "
-                    "product=0x%04x, version=0x%04x\n",
-                    device->identifier.bus, device->identifier.vendor,
-                    device->identifier.product, device->identifier.version);
-            dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n",
-                    device->keyMap.keyLayoutFile.string());
-            dump.appendFormat(INDENT3 "KeyCharacterMapFile: %s\n",
-                    device->keyMap.keyCharacterMapFile.string());
-            dump.appendFormat(INDENT3 "ConfigurationFile: %s\n",
-                    device->configurationFile.string());
-            dump.appendFormat(INDENT3 "HaveKeyboardLayoutOverlay: %s\n",
-                    toString(device->overlayKeyMap != NULL));
-        }
-    } // release lock
-}
-
-void EventHub::monitor() {
-    // Acquire and release the lock to ensure that the event hub has not deadlocked.
-    mLock.lock();
-    mLock.unlock();
-}
-
-
-}; // namespace android
diff --git a/services/input/EventHub.h b/services/input/EventHub.h
deleted file mode 100644
index ae28f01..0000000
--- a/services/input/EventHub.h
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * Copyright (C) 2005 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 _RUNTIME_EVENT_HUB_H
-#define _RUNTIME_EVENT_HUB_H
-
-#include <input/Input.h>
-#include <input/InputDevice.h>
-#include <input/Keyboard.h>
-#include <input/KeyLayoutMap.h>
-#include <input/KeyCharacterMap.h>
-#include <input/VirtualKeyMap.h>
-#include <utils/String8.h>
-#include <utils/threads.h>
-#include <utils/Log.h>
-#include <utils/threads.h>
-#include <utils/List.h>
-#include <utils/Errors.h>
-#include <utils/PropertyMap.h>
-#include <utils/Vector.h>
-#include <utils/KeyedVector.h>
-#include <utils/BitSet.h>
-
-#include <linux/input.h>
-#include <sys/epoll.h>
-
-/* Convenience constants. */
-
-#define BTN_FIRST 0x100  // first button code
-#define BTN_LAST 0x15f   // last button code
-
-/*
- * These constants are used privately in Android to pass raw timestamps
- * through evdev from uinput device drivers because there is currently no
- * other way to transfer this information.  The evdev driver automatically
- * timestamps all input events with the time they were posted and clobbers
- * whatever information was passed in.
- *
- * For the purposes of this hack, the timestamp is specified in the
- * CLOCK_MONOTONIC timebase and is split into two EV_MSC events specifying
- * seconds and microseconds.
- */
-#define MSC_ANDROID_TIME_SEC 0x6
-#define MSC_ANDROID_TIME_USEC 0x7
-
-namespace android {
-
-enum {
-    // Device id of a special "virtual" keyboard that is always present.
-    VIRTUAL_KEYBOARD_ID = -1,
-    // Device id of the "built-in" keyboard if there is one.
-    BUILT_IN_KEYBOARD_ID = 0,
-};
-
-/*
- * A raw event as retrieved from the EventHub.
- */
-struct RawEvent {
-    nsecs_t when;
-    int32_t deviceId;
-    int32_t type;
-    int32_t code;
-    int32_t value;
-};
-
-/* Describes an absolute axis. */
-struct RawAbsoluteAxisInfo {
-    bool valid; // true if the information is valid, false otherwise
-
-    int32_t minValue;  // minimum value
-    int32_t maxValue;  // maximum value
-    int32_t flat;      // center flat position, eg. flat == 8 means center is between -8 and 8
-    int32_t fuzz;      // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
-    int32_t resolution; // resolution in units per mm or radians per mm
-
-    inline void clear() {
-        valid = false;
-        minValue = 0;
-        maxValue = 0;
-        flat = 0;
-        fuzz = 0;
-        resolution = 0;
-    }
-};
-
-/*
- * Input device classes.
- */
-enum {
-    /* The input device is a keyboard or has buttons. */
-    INPUT_DEVICE_CLASS_KEYBOARD      = 0x00000001,
-
-    /* The input device is an alpha-numeric keyboard (not just a dial pad). */
-    INPUT_DEVICE_CLASS_ALPHAKEY      = 0x00000002,
-
-    /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
-    INPUT_DEVICE_CLASS_TOUCH         = 0x00000004,
-
-    /* The input device is a cursor device such as a trackball or mouse. */
-    INPUT_DEVICE_CLASS_CURSOR        = 0x00000008,
-
-    /* The input device is a multi-touch touchscreen. */
-    INPUT_DEVICE_CLASS_TOUCH_MT      = 0x00000010,
-
-    /* The input device is a directional pad (implies keyboard, has DPAD keys). */
-    INPUT_DEVICE_CLASS_DPAD          = 0x00000020,
-
-    /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
-    INPUT_DEVICE_CLASS_GAMEPAD       = 0x00000040,
-
-    /* The input device has switches. */
-    INPUT_DEVICE_CLASS_SWITCH        = 0x00000080,
-
-    /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
-    INPUT_DEVICE_CLASS_JOYSTICK      = 0x00000100,
-
-    /* The input device has a vibrator (supports FF_RUMBLE). */
-    INPUT_DEVICE_CLASS_VIBRATOR      = 0x00000200,
-
-    /* The input device is virtual (not a real device, not part of UI configuration). */
-    INPUT_DEVICE_CLASS_VIRTUAL       = 0x40000000,
-
-    /* The input device is external (not built-in). */
-    INPUT_DEVICE_CLASS_EXTERNAL      = 0x80000000,
-};
-
-/*
- * Gets the class that owns an axis, in cases where multiple classes might claim
- * the same axis for different purposes.
- */
-extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses);
-
-/*
- * Grand Central Station for events.
- *
- * The event hub aggregates input events received across all known input
- * devices on the system, including devices that may be emulated by the simulator
- * environment.  In addition, the event hub generates fake input events to indicate
- * when devices are added or removed.
- *
- * The event hub provides a stream of input events (via the getEvent function).
- * It also supports querying the current actual state of input devices such as identifying
- * which keys are currently down.  Finally, the event hub keeps track of the capabilities of
- * individual input devices, such as their class and the set of key codes that they support.
- */
-class EventHubInterface : public virtual RefBase {
-protected:
-    EventHubInterface() { }
-    virtual ~EventHubInterface() { }
-
-public:
-    // Synthetic raw event type codes produced when devices are added or removed.
-    enum {
-        // Sent when a device is added.
-        DEVICE_ADDED = 0x10000000,
-        // Sent when a device is removed.
-        DEVICE_REMOVED = 0x20000000,
-        // Sent when all added/removed devices from the most recent scan have been reported.
-        // This event is always sent at least once.
-        FINISHED_DEVICE_SCAN = 0x30000000,
-
-        FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
-    };
-
-    virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
-
-    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
-
-    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0;
-
-    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
-
-    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
-            RawAbsoluteAxisInfo* outAxisInfo) const = 0;
-
-    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
-
-    virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
-
-    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
-            int32_t* outKeycode, uint32_t* outFlags) const = 0;
-
-    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
-            AxisInfo* outAxisInfo) const = 0;
-
-    // Sets devices that are excluded from opening.
-    // This can be used to ignore input devices for sensors.
-    virtual void setExcludedDevices(const Vector<String8>& devices) = 0;
-
-    /*
-     * Wait for events to become available and returns them.
-     * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
-     * This ensures that the device will not go to sleep while the event is being processed.
-     * If the device needs to remain awake longer than that, then the caller is responsible
-     * for taking care of it (say, by poking the power manager user activity timer).
-     *
-     * The timeout is advisory only.  If the device is asleep, it will not wake just to
-     * service the timeout.
-     *
-     * Returns the number of events obtained, or 0 if the timeout expired.
-     */
-    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
-
-    /*
-     * Query current input state.
-     */
-    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
-    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
-    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
-    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
-            int32_t* outValue) const = 0;
-
-    /*
-     * Examine key input devices for specific framework keycode support
-     */
-    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
-            uint8_t* outFlags) const = 0;
-
-    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
-    virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
-    virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
-
-    virtual void getVirtualKeyDefinitions(int32_t deviceId,
-            Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
-
-    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
-    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0;
-
-    /* Control the vibrator. */
-    virtual void vibrate(int32_t deviceId, nsecs_t duration) = 0;
-    virtual void cancelVibrate(int32_t deviceId) = 0;
-
-    /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
-    virtual void requestReopenDevices() = 0;
-
-    /* Wakes up getEvents() if it is blocked on a read. */
-    virtual void wake() = 0;
-
-    /* Dump EventHub state to a string. */
-    virtual void dump(String8& dump) = 0;
-
-    /* Called by the heatbeat to ensures that the reader has not deadlocked. */
-    virtual void monitor() = 0;
-};
-
-class EventHub : public EventHubInterface
-{
-public:
-    EventHub();
-
-    virtual uint32_t getDeviceClasses(int32_t deviceId) const;
-
-    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const;
-
-    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const;
-
-    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const;
-
-    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
-            RawAbsoluteAxisInfo* outAxisInfo) const;
-
-    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const;
-
-    virtual bool hasInputProperty(int32_t deviceId, int property) const;
-
-    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
-            int32_t* outKeycode, uint32_t* outFlags) const;
-
-    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
-            AxisInfo* outAxisInfo) const;
-
-    virtual void setExcludedDevices(const Vector<String8>& devices);
-
-    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const;
-    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const;
-    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const;
-    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const;
-
-    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags) const;
-
-    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize);
-
-    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const;
-    virtual bool hasLed(int32_t deviceId, int32_t led) const;
-    virtual void setLedState(int32_t deviceId, int32_t led, bool on);
-
-    virtual void getVirtualKeyDefinitions(int32_t deviceId,
-            Vector<VirtualKeyDefinition>& outVirtualKeys) const;
-
-    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const;
-    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map);
-
-    virtual void vibrate(int32_t deviceId, nsecs_t duration);
-    virtual void cancelVibrate(int32_t deviceId);
-
-    virtual void requestReopenDevices();
-
-    virtual void wake();
-
-    virtual void dump(String8& dump);
-    virtual void monitor();
-
-protected:
-    virtual ~EventHub();
-
-private:
-    struct Device {
-        Device* next;
-
-        int fd; // may be -1 if device is virtual
-        const int32_t id;
-        const String8 path;
-        const InputDeviceIdentifier identifier;
-
-        uint32_t classes;
-
-        uint8_t keyBitmask[(KEY_MAX + 1) / 8];
-        uint8_t absBitmask[(ABS_MAX + 1) / 8];
-        uint8_t relBitmask[(REL_MAX + 1) / 8];
-        uint8_t swBitmask[(SW_MAX + 1) / 8];
-        uint8_t ledBitmask[(LED_MAX + 1) / 8];
-        uint8_t ffBitmask[(FF_MAX + 1) / 8];
-        uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8];
-
-        String8 configurationFile;
-        PropertyMap* configuration;
-        VirtualKeyMap* virtualKeyMap;
-        KeyMap keyMap;
-
-        sp<KeyCharacterMap> overlayKeyMap;
-        sp<KeyCharacterMap> combinedKeyMap;
-
-        bool ffEffectPlaying;
-        int16_t ffEffectId; // initially -1
-
-        int32_t controllerNumber;
-
-        int32_t timestampOverrideSec;
-        int32_t timestampOverrideUsec;
-
-        Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier);
-        ~Device();
-
-        void close();
-
-        inline bool isVirtual() const { return fd < 0; }
-
-        const sp<KeyCharacterMap>& getKeyCharacterMap() const {
-            if (combinedKeyMap != NULL) {
-                return combinedKeyMap;
-            }
-            return keyMap.keyCharacterMap;
-        }
-    };
-
-    status_t openDeviceLocked(const char *devicePath);
-    void createVirtualKeyboardLocked();
-    void addDeviceLocked(Device* device);
-
-    status_t closeDeviceByPathLocked(const char *devicePath);
-    void closeDeviceLocked(Device* device);
-    void closeAllDevicesLocked();
-
-    status_t scanDirLocked(const char *dirname);
-    void scanDevicesLocked();
-    status_t readNotifyLocked();
-
-    Device* getDeviceLocked(int32_t deviceId) const;
-    Device* getDeviceByPathLocked(const char* devicePath) const;
-
-    bool hasKeycodeLocked(Device* device, int keycode) const;
-
-    void loadConfigurationLocked(Device* device);
-    status_t loadVirtualKeyMapLocked(Device* device);
-    status_t loadKeyMapLocked(Device* device);
-
-    bool isExternalDeviceLocked(Device* device);
-
-    int32_t getNextControllerNumberLocked(Device* device);
-    void releaseControllerNumberLocked(Device* device);
-
-    // Protect all internal state.
-    mutable Mutex mLock;
-
-    // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
-    // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
-    enum {
-        // Must not conflict with any other assigned device ids, including
-        // the virtual keyboard id (-1).
-        NO_BUILT_IN_KEYBOARD = -2,
-    };
-    int32_t mBuiltInKeyboardId;
-
-    int32_t mNextDeviceId;
-
-    BitSet32 mControllerNumbers;
-
-    KeyedVector<int32_t, Device*> mDevices;
-
-    Device *mOpeningDevices;
-    Device *mClosingDevices;
-
-    bool mNeedToSendFinishedDeviceScan;
-    bool mNeedToReopenDevices;
-    bool mNeedToScanDevices;
-    Vector<String8> mExcludedDevices;
-
-    int mEpollFd;
-    int mINotifyFd;
-    int mWakeReadPipeFd;
-    int mWakeWritePipeFd;
-
-    // Ids used for epoll notifications not associated with devices.
-    static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
-    static const uint32_t EPOLL_ID_WAKE = 0x80000002;
-
-    // Epoll FD list size hint.
-    static const int EPOLL_SIZE_HINT = 8;
-
-    // Maximum number of signalled FDs to handle at a time.
-    static const int EPOLL_MAX_EVENTS = 16;
-
-    // The array of pending epoll events and the index of the next event to be handled.
-    struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
-    size_t mPendingEventCount;
-    size_t mPendingEventIndex;
-    bool mPendingINotify;
-};
-
-}; // namespace android
-
-#endif // _RUNTIME_EVENT_HUB_H
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp
deleted file mode 100644
index 10a639e..0000000
--- a/services/input/InputDispatcher.cpp
+++ /dev/null
@@ -1,4470 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#define LOG_TAG "InputDispatcher"
-#define ATRACE_TAG ATRACE_TAG_INPUT
-
-//#define LOG_NDEBUG 0
-
-// Log detailed debug messages about each inbound event notification to the dispatcher.
-#define DEBUG_INBOUND_EVENT_DETAILS 0
-
-// Log detailed debug messages about each outbound event processed by the dispatcher.
-#define DEBUG_OUTBOUND_EVENT_DETAILS 0
-
-// Log debug messages about the dispatch cycle.
-#define DEBUG_DISPATCH_CYCLE 0
-
-// Log debug messages about registrations.
-#define DEBUG_REGISTRATION 0
-
-// Log debug messages about input event injection.
-#define DEBUG_INJECTION 0
-
-// Log debug messages about input focus tracking.
-#define DEBUG_FOCUS 0
-
-// Log debug messages about the app switch latency optimization.
-#define DEBUG_APP_SWITCH 0
-
-// Log debug messages about hover events.
-#define DEBUG_HOVER 0
-
-#include "InputDispatcher.h"
-
-#include <utils/Trace.h>
-#include <cutils/log.h>
-#include <androidfw/PowerManager.h>
-
-#include <stddef.h>
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <time.h>
-
-#define INDENT "  "
-#define INDENT2 "    "
-#define INDENT3 "      "
-#define INDENT4 "        "
-
-namespace android {
-
-// Default input dispatching timeout if there is no focused application or paused window
-// from which to determine an appropriate dispatching timeout.
-const nsecs_t DEFAULT_INPUT_DISPATCHING_TIMEOUT = 5000 * 1000000LL; // 5 sec
-
-// Amount of time to allow for all pending events to be processed when an app switch
-// key is on the way.  This is used to preempt input dispatch and drop input events
-// when an application takes too long to respond and the user has pressed an app switch key.
-const nsecs_t APP_SWITCH_TIMEOUT = 500 * 1000000LL; // 0.5sec
-
-// Amount of time to allow for an event to be dispatched (measured since its eventTime)
-// before considering it stale and dropping it.
-const nsecs_t STALE_EVENT_TIMEOUT = 10000 * 1000000LL; // 10sec
-
-// Amount of time to allow touch events to be streamed out to a connection before requiring
-// that the first event be finished.  This value extends the ANR timeout by the specified
-// amount.  For example, if streaming is allowed to get ahead by one second relative to the
-// queue of waiting unfinished events, then ANRs will similarly be delayed by one second.
-const nsecs_t STREAM_AHEAD_EVENT_TIMEOUT = 500 * 1000000LL; // 0.5sec
-
-// Log a warning when an event takes longer than this to process, even if an ANR does not occur.
-const nsecs_t SLOW_EVENT_PROCESSING_WARNING_TIMEOUT = 2000 * 1000000LL; // 2sec
-
-// Number of recent events to keep for debugging purposes.
-const size_t RECENT_QUEUE_MAX_SIZE = 10;
-
-static inline nsecs_t now() {
-    return systemTime(SYSTEM_TIME_MONOTONIC);
-}
-
-static inline const char* toString(bool value) {
-    return value ? "true" : "false";
-}
-
-static inline int32_t getMotionEventActionPointerIndex(int32_t action) {
-    return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
-            >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-}
-
-static bool isValidKeyAction(int32_t action) {
-    switch (action) {
-    case AKEY_EVENT_ACTION_DOWN:
-    case AKEY_EVENT_ACTION_UP:
-        return true;
-    default:
-        return false;
-    }
-}
-
-static bool validateKeyEvent(int32_t action) {
-    if (! isValidKeyAction(action)) {
-        ALOGE("Key event has invalid action code 0x%x", action);
-        return false;
-    }
-    return true;
-}
-
-static bool isValidMotionAction(int32_t action, size_t pointerCount) {
-    switch (action & AMOTION_EVENT_ACTION_MASK) {
-    case AMOTION_EVENT_ACTION_DOWN:
-    case AMOTION_EVENT_ACTION_UP:
-    case AMOTION_EVENT_ACTION_CANCEL:
-    case AMOTION_EVENT_ACTION_MOVE:
-    case AMOTION_EVENT_ACTION_OUTSIDE:
-    case AMOTION_EVENT_ACTION_HOVER_ENTER:
-    case AMOTION_EVENT_ACTION_HOVER_MOVE:
-    case AMOTION_EVENT_ACTION_HOVER_EXIT:
-    case AMOTION_EVENT_ACTION_SCROLL:
-        return true;
-    case AMOTION_EVENT_ACTION_POINTER_DOWN:
-    case AMOTION_EVENT_ACTION_POINTER_UP: {
-        int32_t index = getMotionEventActionPointerIndex(action);
-        return index >= 0 && size_t(index) < pointerCount;
-    }
-    default:
-        return false;
-    }
-}
-
-static bool validateMotionEvent(int32_t action, size_t pointerCount,
-        const PointerProperties* pointerProperties) {
-    if (! isValidMotionAction(action, pointerCount)) {
-        ALOGE("Motion event has invalid action code 0x%x", action);
-        return false;
-    }
-    if (pointerCount < 1 || pointerCount > MAX_POINTERS) {
-        ALOGE("Motion event has invalid pointer count %d; value must be between 1 and %d.",
-                pointerCount, MAX_POINTERS);
-        return false;
-    }
-    BitSet32 pointerIdBits;
-    for (size_t i = 0; i < pointerCount; i++) {
-        int32_t id = pointerProperties[i].id;
-        if (id < 0 || id > MAX_POINTER_ID) {
-            ALOGE("Motion event has invalid pointer id %d; value must be between 0 and %d",
-                    id, MAX_POINTER_ID);
-            return false;
-        }
-        if (pointerIdBits.hasBit(id)) {
-            ALOGE("Motion event has duplicate pointer id %d", id);
-            return false;
-        }
-        pointerIdBits.markBit(id);
-    }
-    return true;
-}
-
-static bool isMainDisplay(int32_t displayId) {
-    return displayId == ADISPLAY_ID_DEFAULT || displayId == ADISPLAY_ID_NONE;
-}
-
-static void dumpRegion(String8& dump, const SkRegion& region) {
-    if (region.isEmpty()) {
-        dump.append("<empty>");
-        return;
-    }
-
-    bool first = true;
-    for (SkRegion::Iterator it(region); !it.done(); it.next()) {
-        if (first) {
-            first = false;
-        } else {
-            dump.append("|");
-        }
-        const SkIRect& rect = it.rect();
-        dump.appendFormat("[%d,%d][%d,%d]", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom);
-    }
-}
-
-
-// --- InputDispatcher ---
-
-InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy) :
-    mPolicy(policy),
-    mPendingEvent(NULL), mAppSwitchSawKeyDown(false), mAppSwitchDueTime(LONG_LONG_MAX),
-    mNextUnblockedEvent(NULL),
-    mDispatchEnabled(false), mDispatchFrozen(false), mInputFilterEnabled(false),
-    mInputTargetWaitCause(INPUT_TARGET_WAIT_CAUSE_NONE) {
-    mLooper = new Looper(false);
-
-    mKeyRepeatState.lastKeyEntry = NULL;
-
-    policy->getDispatcherConfiguration(&mConfig);
-}
-
-InputDispatcher::~InputDispatcher() {
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        resetKeyRepeatLocked();
-        releasePendingEventLocked();
-        drainInboundQueueLocked();
-    }
-
-    while (mConnectionsByFd.size() != 0) {
-        unregisterInputChannel(mConnectionsByFd.valueAt(0)->inputChannel);
-    }
-}
-
-void InputDispatcher::dispatchOnce() {
-    nsecs_t nextWakeupTime = LONG_LONG_MAX;
-    { // acquire lock
-        AutoMutex _l(mLock);
-        mDispatcherIsAliveCondition.broadcast();
-
-        // Run a dispatch loop if there are no pending commands.
-        // The dispatch loop might enqueue commands to run afterwards.
-        if (!haveCommandsLocked()) {
-            dispatchOnceInnerLocked(&nextWakeupTime);
-        }
-
-        // Run all pending commands if there are any.
-        // If any commands were run then force the next poll to wake up immediately.
-        if (runCommandsLockedInterruptible()) {
-            nextWakeupTime = LONG_LONG_MIN;
-        }
-    } // release lock
-
-    // Wait for callback or timeout or wake.  (make sure we round up, not down)
-    nsecs_t currentTime = now();
-    int timeoutMillis = toMillisecondTimeoutDelay(currentTime, nextWakeupTime);
-    mLooper->pollOnce(timeoutMillis);
-}
-
-void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) {
-    nsecs_t currentTime = now();
-
-    // Reset the key repeat timer whenever we disallow key events, even if the next event
-    // is not a key.  This is to ensure that we abort a key repeat if the device is just coming
-    // out of sleep.
-    if (!mPolicy->isKeyRepeatEnabled()) {
-        resetKeyRepeatLocked();
-    }
-
-    // If dispatching is frozen, do not process timeouts or try to deliver any new events.
-    if (mDispatchFrozen) {
-#if DEBUG_FOCUS
-        ALOGD("Dispatch frozen.  Waiting some more.");
-#endif
-        return;
-    }
-
-    // Optimize latency of app switches.
-    // Essentially we start a short timeout when an app switch key (HOME / ENDCALL) has
-    // been pressed.  When it expires, we preempt dispatch and drop all other pending events.
-    bool isAppSwitchDue = mAppSwitchDueTime <= currentTime;
-    if (mAppSwitchDueTime < *nextWakeupTime) {
-        *nextWakeupTime = mAppSwitchDueTime;
-    }
-
-    // Ready to start a new event.
-    // If we don't already have a pending event, go grab one.
-    if (! mPendingEvent) {
-        if (mInboundQueue.isEmpty()) {
-            if (isAppSwitchDue) {
-                // The inbound queue is empty so the app switch key we were waiting
-                // for will never arrive.  Stop waiting for it.
-                resetPendingAppSwitchLocked(false);
-                isAppSwitchDue = false;
-            }
-
-            // Synthesize a key repeat if appropriate.
-            if (mKeyRepeatState.lastKeyEntry) {
-                if (currentTime >= mKeyRepeatState.nextRepeatTime) {
-                    mPendingEvent = synthesizeKeyRepeatLocked(currentTime);
-                } else {
-                    if (mKeyRepeatState.nextRepeatTime < *nextWakeupTime) {
-                        *nextWakeupTime = mKeyRepeatState.nextRepeatTime;
-                    }
-                }
-            }
-
-            // Nothing to do if there is no pending event.
-            if (!mPendingEvent) {
-                return;
-            }
-        } else {
-            // Inbound queue has at least one entry.
-            mPendingEvent = mInboundQueue.dequeueAtHead();
-            traceInboundQueueLengthLocked();
-        }
-
-        // Poke user activity for this event.
-        if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) {
-            pokeUserActivityLocked(mPendingEvent);
-        }
-
-        // Get ready to dispatch the event.
-        resetANRTimeoutsLocked();
-    }
-
-    // Now we have an event to dispatch.
-    // All events are eventually dequeued and processed this way, even if we intend to drop them.
-    ALOG_ASSERT(mPendingEvent != NULL);
-    bool done = false;
-    DropReason dropReason = DROP_REASON_NOT_DROPPED;
-    if (!(mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER)) {
-        dropReason = DROP_REASON_POLICY;
-    } else if (!mDispatchEnabled) {
-        dropReason = DROP_REASON_DISABLED;
-    }
-
-    if (mNextUnblockedEvent == mPendingEvent) {
-        mNextUnblockedEvent = NULL;
-    }
-
-    switch (mPendingEvent->type) {
-    case EventEntry::TYPE_CONFIGURATION_CHANGED: {
-        ConfigurationChangedEntry* typedEntry =
-                static_cast<ConfigurationChangedEntry*>(mPendingEvent);
-        done = dispatchConfigurationChangedLocked(currentTime, typedEntry);
-        dropReason = DROP_REASON_NOT_DROPPED; // configuration changes are never dropped
-        break;
-    }
-
-    case EventEntry::TYPE_DEVICE_RESET: {
-        DeviceResetEntry* typedEntry =
-                static_cast<DeviceResetEntry*>(mPendingEvent);
-        done = dispatchDeviceResetLocked(currentTime, typedEntry);
-        dropReason = DROP_REASON_NOT_DROPPED; // device resets are never dropped
-        break;
-    }
-
-    case EventEntry::TYPE_KEY: {
-        KeyEntry* typedEntry = static_cast<KeyEntry*>(mPendingEvent);
-        if (isAppSwitchDue) {
-            if (isAppSwitchKeyEventLocked(typedEntry)) {
-                resetPendingAppSwitchLocked(true);
-                isAppSwitchDue = false;
-            } else if (dropReason == DROP_REASON_NOT_DROPPED) {
-                dropReason = DROP_REASON_APP_SWITCH;
-            }
-        }
-        if (dropReason == DROP_REASON_NOT_DROPPED
-                && isStaleEventLocked(currentTime, typedEntry)) {
-            dropReason = DROP_REASON_STALE;
-        }
-        if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {
-            dropReason = DROP_REASON_BLOCKED;
-        }
-        done = dispatchKeyLocked(currentTime, typedEntry, &dropReason, nextWakeupTime);
-        break;
-    }
-
-    case EventEntry::TYPE_MOTION: {
-        MotionEntry* typedEntry = static_cast<MotionEntry*>(mPendingEvent);
-        if (dropReason == DROP_REASON_NOT_DROPPED && isAppSwitchDue) {
-            dropReason = DROP_REASON_APP_SWITCH;
-        }
-        if (dropReason == DROP_REASON_NOT_DROPPED
-                && isStaleEventLocked(currentTime, typedEntry)) {
-            dropReason = DROP_REASON_STALE;
-        }
-        if (dropReason == DROP_REASON_NOT_DROPPED && mNextUnblockedEvent) {
-            dropReason = DROP_REASON_BLOCKED;
-        }
-        done = dispatchMotionLocked(currentTime, typedEntry,
-                &dropReason, nextWakeupTime);
-        break;
-    }
-
-    default:
-        ALOG_ASSERT(false);
-        break;
-    }
-
-    if (done) {
-        if (dropReason != DROP_REASON_NOT_DROPPED) {
-            dropInboundEventLocked(mPendingEvent, dropReason);
-        }
-
-        releasePendingEventLocked();
-        *nextWakeupTime = LONG_LONG_MIN;  // force next poll to wake up immediately
-    }
-}
-
-bool InputDispatcher::enqueueInboundEventLocked(EventEntry* entry) {
-    bool needWake = mInboundQueue.isEmpty();
-    mInboundQueue.enqueueAtTail(entry);
-    traceInboundQueueLengthLocked();
-
-    switch (entry->type) {
-    case EventEntry::TYPE_KEY: {
-        // Optimize app switch latency.
-        // If the application takes too long to catch up then we drop all events preceding
-        // the app switch key.
-        KeyEntry* keyEntry = static_cast<KeyEntry*>(entry);
-        if (isAppSwitchKeyEventLocked(keyEntry)) {
-            if (keyEntry->action == AKEY_EVENT_ACTION_DOWN) {
-                mAppSwitchSawKeyDown = true;
-            } else if (keyEntry->action == AKEY_EVENT_ACTION_UP) {
-                if (mAppSwitchSawKeyDown) {
-#if DEBUG_APP_SWITCH
-                    ALOGD("App switch is pending!");
-#endif
-                    mAppSwitchDueTime = keyEntry->eventTime + APP_SWITCH_TIMEOUT;
-                    mAppSwitchSawKeyDown = false;
-                    needWake = true;
-                }
-            }
-        }
-        break;
-    }
-
-    case EventEntry::TYPE_MOTION: {
-        // Optimize case where the current application is unresponsive and the user
-        // decides to touch a window in a different application.
-        // If the application takes too long to catch up then we drop all events preceding
-        // the touch into the other window.
-        MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
-        if (motionEntry->action == AMOTION_EVENT_ACTION_DOWN
-                && (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER)
-                && mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY
-                && mInputTargetWaitApplicationHandle != NULL) {
-            int32_t displayId = motionEntry->displayId;
-            int32_t x = int32_t(motionEntry->pointerCoords[0].
-                    getAxisValue(AMOTION_EVENT_AXIS_X));
-            int32_t y = int32_t(motionEntry->pointerCoords[0].
-                    getAxisValue(AMOTION_EVENT_AXIS_Y));
-            sp<InputWindowHandle> touchedWindowHandle = findTouchedWindowAtLocked(displayId, x, y);
-            if (touchedWindowHandle != NULL
-                    && touchedWindowHandle->inputApplicationHandle
-                            != mInputTargetWaitApplicationHandle) {
-                // User touched a different application than the one we are waiting on.
-                // Flag the event, and start pruning the input queue.
-                mNextUnblockedEvent = motionEntry;
-                needWake = true;
-            }
-        }
-        break;
-    }
-    }
-
-    return needWake;
-}
-
-void InputDispatcher::addRecentEventLocked(EventEntry* entry) {
-    entry->refCount += 1;
-    mRecentQueue.enqueueAtTail(entry);
-    if (mRecentQueue.count() > RECENT_QUEUE_MAX_SIZE) {
-        mRecentQueue.dequeueAtHead()->release();
-    }
-}
-
-sp<InputWindowHandle> InputDispatcher::findTouchedWindowAtLocked(int32_t displayId,
-        int32_t x, int32_t y) {
-    // Traverse windows from front to back to find touched window.
-    size_t numWindows = mWindowHandles.size();
-    for (size_t i = 0; i < numWindows; i++) {
-        sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i);
-        const InputWindowInfo* windowInfo = windowHandle->getInfo();
-        if (windowInfo->displayId == displayId) {
-            int32_t flags = windowInfo->layoutParamsFlags;
-            int32_t privateFlags = windowInfo->layoutParamsPrivateFlags;
-
-            if (windowInfo->visible) {
-                if (!(flags & InputWindowInfo::FLAG_NOT_TOUCHABLE)) {
-                    bool isTouchModal = (flags & (InputWindowInfo::FLAG_NOT_FOCUSABLE
-                            | InputWindowInfo::FLAG_NOT_TOUCH_MODAL)) == 0;
-                    if (isTouchModal || windowInfo->touchableRegionContainsPoint(x, y)) {
-                        // Found window.
-                        return windowHandle;
-                    }
-                }
-            }
-
-            if (privateFlags & InputWindowInfo::PRIVATE_FLAG_SYSTEM_ERROR) {
-                // Error window is on top but not visible, so touch is dropped.
-                return NULL;
-            }
-        }
-    }
-    return NULL;
-}
-
-void InputDispatcher::dropInboundEventLocked(EventEntry* entry, DropReason dropReason) {
-    const char* reason;
-    switch (dropReason) {
-    case DROP_REASON_POLICY:
-#if DEBUG_INBOUND_EVENT_DETAILS
-        ALOGD("Dropped event because policy consumed it.");
-#endif
-        reason = "inbound event was dropped because the policy consumed it";
-        break;
-    case DROP_REASON_DISABLED:
-        ALOGI("Dropped event because input dispatch is disabled.");
-        reason = "inbound event was dropped because input dispatch is disabled";
-        break;
-    case DROP_REASON_APP_SWITCH:
-        ALOGI("Dropped event because of pending overdue app switch.");
-        reason = "inbound event was dropped because of pending overdue app switch";
-        break;
-    case DROP_REASON_BLOCKED:
-        ALOGI("Dropped event because the current application is not responding and the user "
-                "has started interacting with a different application.");
-        reason = "inbound event was dropped because the current application is not responding "
-                "and the user has started interacting with a different application";
-        break;
-    case DROP_REASON_STALE:
-        ALOGI("Dropped event because it is stale.");
-        reason = "inbound event was dropped because it is stale";
-        break;
-    default:
-        ALOG_ASSERT(false);
-        return;
-    }
-
-    switch (entry->type) {
-    case EventEntry::TYPE_KEY: {
-        CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason);
-        synthesizeCancelationEventsForAllConnectionsLocked(options);
-        break;
-    }
-    case EventEntry::TYPE_MOTION: {
-        MotionEntry* motionEntry = static_cast<MotionEntry*>(entry);
-        if (motionEntry->source & AINPUT_SOURCE_CLASS_POINTER) {
-            CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS, reason);
-            synthesizeCancelationEventsForAllConnectionsLocked(options);
-        } else {
-            CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS, reason);
-            synthesizeCancelationEventsForAllConnectionsLocked(options);
-        }
-        break;
-    }
-    }
-}
-
-bool InputDispatcher::isAppSwitchKeyCode(int32_t keyCode) {
-    return keyCode == AKEYCODE_HOME
-            || keyCode == AKEYCODE_ENDCALL
-            || keyCode == AKEYCODE_APP_SWITCH;
-}
-
-bool InputDispatcher::isAppSwitchKeyEventLocked(KeyEntry* keyEntry) {
-    return ! (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED)
-            && isAppSwitchKeyCode(keyEntry->keyCode)
-            && (keyEntry->policyFlags & POLICY_FLAG_TRUSTED)
-            && (keyEntry->policyFlags & POLICY_FLAG_PASS_TO_USER);
-}
-
-bool InputDispatcher::isAppSwitchPendingLocked() {
-    return mAppSwitchDueTime != LONG_LONG_MAX;
-}
-
-void InputDispatcher::resetPendingAppSwitchLocked(bool handled) {
-    mAppSwitchDueTime = LONG_LONG_MAX;
-
-#if DEBUG_APP_SWITCH
-    if (handled) {
-        ALOGD("App switch has arrived.");
-    } else {
-        ALOGD("App switch was abandoned.");
-    }
-#endif
-}
-
-bool InputDispatcher::isStaleEventLocked(nsecs_t currentTime, EventEntry* entry) {
-    return currentTime - entry->eventTime >= STALE_EVENT_TIMEOUT;
-}
-
-bool InputDispatcher::haveCommandsLocked() const {
-    return !mCommandQueue.isEmpty();
-}
-
-bool InputDispatcher::runCommandsLockedInterruptible() {
-    if (mCommandQueue.isEmpty()) {
-        return false;
-    }
-
-    do {
-        CommandEntry* commandEntry = mCommandQueue.dequeueAtHead();
-
-        Command command = commandEntry->command;
-        (this->*command)(commandEntry); // commands are implicitly 'LockedInterruptible'
-
-        commandEntry->connection.clear();
-        delete commandEntry;
-    } while (! mCommandQueue.isEmpty());
-    return true;
-}
-
-InputDispatcher::CommandEntry* InputDispatcher::postCommandLocked(Command command) {
-    CommandEntry* commandEntry = new CommandEntry(command);
-    mCommandQueue.enqueueAtTail(commandEntry);
-    return commandEntry;
-}
-
-void InputDispatcher::drainInboundQueueLocked() {
-    while (! mInboundQueue.isEmpty()) {
-        EventEntry* entry = mInboundQueue.dequeueAtHead();
-        releaseInboundEventLocked(entry);
-    }
-    traceInboundQueueLengthLocked();
-}
-
-void InputDispatcher::releasePendingEventLocked() {
-    if (mPendingEvent) {
-        resetANRTimeoutsLocked();
-        releaseInboundEventLocked(mPendingEvent);
-        mPendingEvent = NULL;
-    }
-}
-
-void InputDispatcher::releaseInboundEventLocked(EventEntry* entry) {
-    InjectionState* injectionState = entry->injectionState;
-    if (injectionState && injectionState->injectionResult == INPUT_EVENT_INJECTION_PENDING) {
-#if DEBUG_DISPATCH_CYCLE
-        ALOGD("Injected inbound event was dropped.");
-#endif
-        setInjectionResultLocked(entry, INPUT_EVENT_INJECTION_FAILED);
-    }
-    if (entry == mNextUnblockedEvent) {
-        mNextUnblockedEvent = NULL;
-    }
-    addRecentEventLocked(entry);
-    entry->release();
-}
-
-void InputDispatcher::resetKeyRepeatLocked() {
-    if (mKeyRepeatState.lastKeyEntry) {
-        mKeyRepeatState.lastKeyEntry->release();
-        mKeyRepeatState.lastKeyEntry = NULL;
-    }
-}
-
-InputDispatcher::KeyEntry* InputDispatcher::synthesizeKeyRepeatLocked(nsecs_t currentTime) {
-    KeyEntry* entry = mKeyRepeatState.lastKeyEntry;
-
-    // Reuse the repeated key entry if it is otherwise unreferenced.
-    uint32_t policyFlags = (entry->policyFlags & POLICY_FLAG_RAW_MASK)
-            | POLICY_FLAG_PASS_TO_USER | POLICY_FLAG_TRUSTED;
-    if (entry->refCount == 1) {
-        entry->recycle();
-        entry->eventTime = currentTime;
-        entry->policyFlags = policyFlags;
-        entry->repeatCount += 1;
-    } else {
-        KeyEntry* newEntry = new KeyEntry(currentTime,
-                entry->deviceId, entry->source, policyFlags,
-                entry->action, entry->flags, entry->keyCode, entry->scanCode,
-                entry->metaState, entry->repeatCount + 1, entry->downTime);
-
-        mKeyRepeatState.lastKeyEntry = newEntry;
-        entry->release();
-
-        entry = newEntry;
-    }
-    entry->syntheticRepeat = true;
-
-    // Increment reference count since we keep a reference to the event in
-    // mKeyRepeatState.lastKeyEntry in addition to the one we return.
-    entry->refCount += 1;
-
-    mKeyRepeatState.nextRepeatTime = currentTime + mConfig.keyRepeatDelay;
-    return entry;
-}
-
-bool InputDispatcher::dispatchConfigurationChangedLocked(
-        nsecs_t currentTime, ConfigurationChangedEntry* entry) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-    ALOGD("dispatchConfigurationChanged - eventTime=%lld", entry->eventTime);
-#endif
-
-    // Reset key repeating in case a keyboard device was added or removed or something.
-    resetKeyRepeatLocked();
-
-    // Enqueue a command to run outside the lock to tell the policy that the configuration changed.
-    CommandEntry* commandEntry = postCommandLocked(
-            & InputDispatcher::doNotifyConfigurationChangedInterruptible);
-    commandEntry->eventTime = entry->eventTime;
-    return true;
-}
-
-bool InputDispatcher::dispatchDeviceResetLocked(
-        nsecs_t currentTime, DeviceResetEntry* entry) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-    ALOGD("dispatchDeviceReset - eventTime=%lld, deviceId=%d", entry->eventTime, entry->deviceId);
-#endif
-
-    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
-            "device was reset");
-    options.deviceId = entry->deviceId;
-    synthesizeCancelationEventsForAllConnectionsLocked(options);
-    return true;
-}
-
-bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, KeyEntry* entry,
-        DropReason* dropReason, nsecs_t* nextWakeupTime) {
-    // Preprocessing.
-    if (! entry->dispatchInProgress) {
-        if (entry->repeatCount == 0
-                && entry->action == AKEY_EVENT_ACTION_DOWN
-                && (entry->policyFlags & POLICY_FLAG_TRUSTED)
-                && (!(entry->policyFlags & POLICY_FLAG_DISABLE_KEY_REPEAT))) {
-            if (mKeyRepeatState.lastKeyEntry
-                    && mKeyRepeatState.lastKeyEntry->keyCode == entry->keyCode) {
-                // We have seen two identical key downs in a row which indicates that the device
-                // driver is automatically generating key repeats itself.  We take note of the
-                // repeat here, but we disable our own next key repeat timer since it is clear that
-                // we will not need to synthesize key repeats ourselves.
-                entry->repeatCount = mKeyRepeatState.lastKeyEntry->repeatCount + 1;
-                resetKeyRepeatLocked();
-                mKeyRepeatState.nextRepeatTime = LONG_LONG_MAX; // don't generate repeats ourselves
-            } else {
-                // Not a repeat.  Save key down state in case we do see a repeat later.
-                resetKeyRepeatLocked();
-                mKeyRepeatState.nextRepeatTime = entry->eventTime + mConfig.keyRepeatTimeout;
-            }
-            mKeyRepeatState.lastKeyEntry = entry;
-            entry->refCount += 1;
-        } else if (! entry->syntheticRepeat) {
-            resetKeyRepeatLocked();
-        }
-
-        if (entry->repeatCount == 1) {
-            entry->flags |= AKEY_EVENT_FLAG_LONG_PRESS;
-        } else {
-            entry->flags &= ~AKEY_EVENT_FLAG_LONG_PRESS;
-        }
-
-        entry->dispatchInProgress = true;
-
-        logOutboundKeyDetailsLocked("dispatchKey - ", entry);
-    }
-
-    // Handle case where the policy asked us to try again later last time.
-    if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER) {
-        if (currentTime < entry->interceptKeyWakeupTime) {
-            if (entry->interceptKeyWakeupTime < *nextWakeupTime) {
-                *nextWakeupTime = entry->interceptKeyWakeupTime;
-            }
-            return false; // wait until next wakeup
-        }
-        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN;
-        entry->interceptKeyWakeupTime = 0;
-    }
-
-    // Give the policy a chance to intercept the key.
-    if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN) {
-        if (entry->policyFlags & POLICY_FLAG_PASS_TO_USER) {
-            CommandEntry* commandEntry = postCommandLocked(
-                    & InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible);
-            if (mFocusedWindowHandle != NULL) {
-                commandEntry->inputWindowHandle = mFocusedWindowHandle;
-            }
-            commandEntry->keyEntry = entry;
-            entry->refCount += 1;
-            return false; // wait for the command to run
-        } else {
-            entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE;
-        }
-    } else if (entry->interceptKeyResult == KeyEntry::INTERCEPT_KEY_RESULT_SKIP) {
-        if (*dropReason == DROP_REASON_NOT_DROPPED) {
-            *dropReason = DROP_REASON_POLICY;
-        }
-    }
-
-    // Clean up if dropping the event.
-    if (*dropReason != DROP_REASON_NOT_DROPPED) {
-        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
-                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
-        return true;
-    }
-
-    // Identify targets.
-    Vector<InputTarget> inputTargets;
-    int32_t injectionResult = findFocusedWindowTargetsLocked(currentTime,
-            entry, inputTargets, nextWakeupTime);
-    if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
-        return false;
-    }
-
-    setInjectionResultLocked(entry, injectionResult);
-    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
-        return true;
-    }
-
-    addMonitoringTargetsLocked(inputTargets);
-
-    // Dispatch the key.
-    dispatchEventLocked(currentTime, entry, inputTargets);
-    return true;
-}
-
-void InputDispatcher::logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-    ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
-            "action=0x%x, flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, "
-            "repeatCount=%d, downTime=%lld",
-            prefix,
-            entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
-            entry->action, entry->flags, entry->keyCode, entry->scanCode, entry->metaState,
-            entry->repeatCount, entry->downTime);
-#endif
-}
-
-bool InputDispatcher::dispatchMotionLocked(
-        nsecs_t currentTime, MotionEntry* entry, DropReason* dropReason, nsecs_t* nextWakeupTime) {
-    // Preprocessing.
-    if (! entry->dispatchInProgress) {
-        entry->dispatchInProgress = true;
-
-        logOutboundMotionDetailsLocked("dispatchMotion - ", entry);
-    }
-
-    // Clean up if dropping the event.
-    if (*dropReason != DROP_REASON_NOT_DROPPED) {
-        setInjectionResultLocked(entry, *dropReason == DROP_REASON_POLICY
-                ? INPUT_EVENT_INJECTION_SUCCEEDED : INPUT_EVENT_INJECTION_FAILED);
-        return true;
-    }
-
-    bool isPointerEvent = entry->source & AINPUT_SOURCE_CLASS_POINTER;
-
-    // Identify targets.
-    Vector<InputTarget> inputTargets;
-
-    bool conflictingPointerActions = false;
-    int32_t injectionResult;
-    if (isPointerEvent) {
-        // Pointer event.  (eg. touchscreen)
-        injectionResult = findTouchedWindowTargetsLocked(currentTime,
-                entry, inputTargets, nextWakeupTime, &conflictingPointerActions);
-    } else {
-        // Non touch event.  (eg. trackball)
-        injectionResult = findFocusedWindowTargetsLocked(currentTime,
-                entry, inputTargets, nextWakeupTime);
-    }
-    if (injectionResult == INPUT_EVENT_INJECTION_PENDING) {
-        return false;
-    }
-
-    setInjectionResultLocked(entry, injectionResult);
-    if (injectionResult != INPUT_EVENT_INJECTION_SUCCEEDED) {
-        return true;
-    }
-
-    // TODO: support sending secondary display events to input monitors
-    if (isMainDisplay(entry->displayId)) {
-        addMonitoringTargetsLocked(inputTargets);
-    }
-
-    // Dispatch the motion.
-    if (conflictingPointerActions) {
-        CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
-                "conflicting pointer actions");
-        synthesizeCancelationEventsForAllConnectionsLocked(options);
-    }
-    dispatchEventLocked(currentTime, entry, inputTargets);
-    return true;
-}
-
-
-void InputDispatcher::logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-    ALOGD("%seventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
-            "action=0x%x, flags=0x%x, "
-            "metaState=0x%x, buttonState=0x%x, "
-            "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%lld",
-            prefix,
-            entry->eventTime, entry->deviceId, entry->source, entry->policyFlags,
-            entry->action, entry->flags,
-            entry->metaState, entry->buttonState,
-            entry->edgeFlags, entry->xPrecision, entry->yPrecision,
-            entry->downTime);
-
-    for (uint32_t i = 0; i < entry->pointerCount; i++) {
-        ALOGD("  Pointer %d: id=%d, toolType=%d, "
-                "x=%f, y=%f, pressure=%f, size=%f, "
-                "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
-                "orientation=%f",
-                i, entry->pointerProperties[i].id,
-                entry->pointerProperties[i].toolType,
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
-                entry->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
-    }
-#endif
-}
-
-void InputDispatcher::dispatchEventLocked(nsecs_t currentTime,
-        EventEntry* eventEntry, const Vector<InputTarget>& inputTargets) {
-#if DEBUG_DISPATCH_CYCLE
-    ALOGD("dispatchEventToCurrentInputTargets");
-#endif
-
-    ALOG_ASSERT(eventEntry->dispatchInProgress); // should already have been set to true
-
-    pokeUserActivityLocked(eventEntry);
-
-    for (size_t i = 0; i < inputTargets.size(); i++) {
-        const InputTarget& inputTarget = inputTargets.itemAt(i);
-
-        ssize_t connectionIndex = getConnectionIndexLocked(inputTarget.inputChannel);
-        if (connectionIndex >= 0) {
-            sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
-            prepareDispatchCycleLocked(currentTime, connection, eventEntry, &inputTarget);
-        } else {
-#if DEBUG_FOCUS
-            ALOGD("Dropping event delivery to target with channel '%s' because it "
-                    "is no longer registered with the input dispatcher.",
-                    inputTarget.inputChannel->getName().string());
-#endif
-        }
-    }
-}
-
-int32_t InputDispatcher::handleTargetsNotReadyLocked(nsecs_t currentTime,
-        const EventEntry* entry,
-        const sp<InputApplicationHandle>& applicationHandle,
-        const sp<InputWindowHandle>& windowHandle,
-        nsecs_t* nextWakeupTime, const char* reason) {
-    if (applicationHandle == NULL && windowHandle == NULL) {
-        if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY) {
-#if DEBUG_FOCUS
-            ALOGD("Waiting for system to become ready for input.  Reason: %s", reason);
-#endif
-            mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY;
-            mInputTargetWaitStartTime = currentTime;
-            mInputTargetWaitTimeoutTime = LONG_LONG_MAX;
-            mInputTargetWaitTimeoutExpired = false;
-            mInputTargetWaitApplicationHandle.clear();
-        }
-    } else {
-        if (mInputTargetWaitCause != INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) {
-#if DEBUG_FOCUS
-            ALOGD("Waiting for application to become ready for input: %s.  Reason: %s",
-                    getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(),
-                    reason);
-#endif
-            nsecs_t timeout;
-            if (windowHandle != NULL) {
-                timeout = windowHandle->getDispatchingTimeout(DEFAULT_INPUT_DISPATCHING_TIMEOUT);
-            } else if (applicationHandle != NULL) {
-                timeout = applicationHandle->getDispatchingTimeout(
-                        DEFAULT_INPUT_DISPATCHING_TIMEOUT);
-            } else {
-                timeout = DEFAULT_INPUT_DISPATCHING_TIMEOUT;
-            }
-
-            mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY;
-            mInputTargetWaitStartTime = currentTime;
-            mInputTargetWaitTimeoutTime = currentTime + timeout;
-            mInputTargetWaitTimeoutExpired = false;
-            mInputTargetWaitApplicationHandle.clear();
-
-            if (windowHandle != NULL) {
-                mInputTargetWaitApplicationHandle = windowHandle->inputApplicationHandle;
-            }
-            if (mInputTargetWaitApplicationHandle == NULL && applicationHandle != NULL) {
-                mInputTargetWaitApplicationHandle = applicationHandle;
-            }
-        }
-    }
-
-    if (mInputTargetWaitTimeoutExpired) {
-        return INPUT_EVENT_INJECTION_TIMED_OUT;
-    }
-
-    if (currentTime >= mInputTargetWaitTimeoutTime) {
-        onANRLocked(currentTime, applicationHandle, windowHandle,
-                entry->eventTime, mInputTargetWaitStartTime, reason);
-
-        // Force poll loop to wake up immediately on next iteration once we get the
-        // ANR response back from the policy.
-        *nextWakeupTime = LONG_LONG_MIN;
-        return INPUT_EVENT_INJECTION_PENDING;
-    } else {
-        // Force poll loop to wake up when timeout is due.
-        if (mInputTargetWaitTimeoutTime < *nextWakeupTime) {
-            *nextWakeupTime = mInputTargetWaitTimeoutTime;
-        }
-        return INPUT_EVENT_INJECTION_PENDING;
-    }
-}
-
-void InputDispatcher::resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
-        const sp<InputChannel>& inputChannel) {
-    if (newTimeout > 0) {
-        // Extend the timeout.
-        mInputTargetWaitTimeoutTime = now() + newTimeout;
-    } else {
-        // Give up.
-        mInputTargetWaitTimeoutExpired = true;
-
-        // Input state will not be realistic.  Mark it out of sync.
-        if (inputChannel.get()) {
-            ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
-            if (connectionIndex >= 0) {
-                sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
-                sp<InputWindowHandle> windowHandle = connection->inputWindowHandle;
-
-                if (windowHandle != NULL) {
-                    mTouchState.removeWindow(windowHandle);
-                }
-
-                if (connection->status == Connection::STATUS_NORMAL) {
-                    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS,
-                            "application not responding");
-                    synthesizeCancelationEventsForConnectionLocked(connection, options);
-                }
-            }
-        }
-    }
-}
-
-nsecs_t InputDispatcher::getTimeSpentWaitingForApplicationLocked(
-        nsecs_t currentTime) {
-    if (mInputTargetWaitCause == INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY) {
-        return currentTime - mInputTargetWaitStartTime;
-    }
-    return 0;
-}
-
-void InputDispatcher::resetANRTimeoutsLocked() {
-#if DEBUG_FOCUS
-        ALOGD("Resetting ANR timeouts.");
-#endif
-
-    // Reset input target wait timeout.
-    mInputTargetWaitCause = INPUT_TARGET_WAIT_CAUSE_NONE;
-    mInputTargetWaitApplicationHandle.clear();
-}
-
-int32_t InputDispatcher::findFocusedWindowTargetsLocked(nsecs_t currentTime,
-        const EventEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime) {
-    int32_t injectionResult;
-
-    // If there is no currently focused window and no focused application
-    // then drop the event.
-    if (mFocusedWindowHandle == NULL) {
-        if (mFocusedApplicationHandle != NULL) {
-            injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
-                    mFocusedApplicationHandle, NULL, nextWakeupTime,
-                    "Waiting because no window has focus but there is a "
-                    "focused application that may eventually add a window "
-                    "when it finishes starting up.");
-            goto Unresponsive;
-        }
-
-        ALOGI("Dropping event because there is no focused window or focused application.");
-        injectionResult = INPUT_EVENT_INJECTION_FAILED;
-        goto Failed;
-    }
-
-    // Check permissions.
-    if (! checkInjectionPermission(mFocusedWindowHandle, entry->injectionState)) {
-        injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
-        goto Failed;
-    }
-
-    // If the currently focused window is paused then keep waiting.
-    if (mFocusedWindowHandle->getInfo()->paused) {
-        injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
-                mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime,
-                "Waiting because the focused window is paused.");
-        goto Unresponsive;
-    }
-
-    // If the currently focused window is still working on previous events then keep waiting.
-    if (!isWindowReadyForMoreInputLocked(currentTime, mFocusedWindowHandle, entry)) {
-        injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
-                mFocusedApplicationHandle, mFocusedWindowHandle, nextWakeupTime,
-                "Waiting because the focused window has not finished "
-                "processing the input events that were previously delivered to it.");
-        goto Unresponsive;
-    }
-
-    // Success!  Output targets.
-    injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
-    addWindowTargetLocked(mFocusedWindowHandle,
-            InputTarget::FLAG_FOREGROUND | InputTarget::FLAG_DISPATCH_AS_IS, BitSet32(0),
-            inputTargets);
-
-    // Done.
-Failed:
-Unresponsive:
-    nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime);
-    updateDispatchStatisticsLocked(currentTime, entry,
-            injectionResult, timeSpentWaitingForApplication);
-#if DEBUG_FOCUS
-    ALOGD("findFocusedWindow finished: injectionResult=%d, "
-            "timeSpentWaitingForApplication=%0.1fms",
-            injectionResult, timeSpentWaitingForApplication / 1000000.0);
-#endif
-    return injectionResult;
-}
-
-int32_t InputDispatcher::findTouchedWindowTargetsLocked(nsecs_t currentTime,
-        const MotionEntry* entry, Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
-        bool* outConflictingPointerActions) {
-    enum InjectionPermission {
-        INJECTION_PERMISSION_UNKNOWN,
-        INJECTION_PERMISSION_GRANTED,
-        INJECTION_PERMISSION_DENIED
-    };
-
-    nsecs_t startTime = now();
-
-    // For security reasons, we defer updating the touch state until we are sure that
-    // event injection will be allowed.
-    //
-    // FIXME In the original code, screenWasOff could never be set to true.
-    //       The reason is that the POLICY_FLAG_WOKE_HERE
-    //       and POLICY_FLAG_BRIGHT_HERE flags were set only when preprocessing raw
-    //       EV_KEY, EV_REL and EV_ABS events.  As it happens, the touch event was
-    //       actually enqueued using the policyFlags that appeared in the final EV_SYN
-    //       events upon which no preprocessing took place.  So policyFlags was always 0.
-    //       In the new native input dispatcher we're a bit more careful about event
-    //       preprocessing so the touches we receive can actually have non-zero policyFlags.
-    //       Unfortunately we obtain undesirable behavior.
-    //
-    //       Here's what happens:
-    //
-    //       When the device dims in anticipation of going to sleep, touches
-    //       in windows which have FLAG_TOUCHABLE_WHEN_WAKING cause
-    //       the device to brighten and reset the user activity timer.
-    //       Touches on other windows (such as the launcher window)
-    //       are dropped.  Then after a moment, the device goes to sleep.  Oops.
-    //
-    //       Also notice how screenWasOff was being initialized using POLICY_FLAG_BRIGHT_HERE
-    //       instead of POLICY_FLAG_WOKE_HERE...
-    //
-    bool screenWasOff = false; // original policy: policyFlags & POLICY_FLAG_BRIGHT_HERE;
-
-    int32_t displayId = entry->displayId;
-    int32_t action = entry->action;
-    int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
-
-    // Update the touch state as needed based on the properties of the touch event.
-    int32_t injectionResult = INPUT_EVENT_INJECTION_PENDING;
-    InjectionPermission injectionPermission = INJECTION_PERMISSION_UNKNOWN;
-    sp<InputWindowHandle> newHoverWindowHandle;
-
-    bool isSplit = mTouchState.split;
-    bool switchedDevice = mTouchState.deviceId >= 0 && mTouchState.displayId >= 0
-            && (mTouchState.deviceId != entry->deviceId
-                    || mTouchState.source != entry->source
-                    || mTouchState.displayId != displayId);
-    bool isHoverAction = (maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE
-            || maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER
-            || maskedAction == AMOTION_EVENT_ACTION_HOVER_EXIT);
-    bool newGesture = (maskedAction == AMOTION_EVENT_ACTION_DOWN
-            || maskedAction == AMOTION_EVENT_ACTION_SCROLL
-            || isHoverAction);
-    bool wrongDevice = false;
-    if (newGesture) {
-        bool down = maskedAction == AMOTION_EVENT_ACTION_DOWN;
-        if (switchedDevice && mTouchState.down && !down) {
-#if DEBUG_FOCUS
-            ALOGD("Dropping event because a pointer for a different device is already down.");
-#endif
-            mTempTouchState.copyFrom(mTouchState);
-            injectionResult = INPUT_EVENT_INJECTION_FAILED;
-            switchedDevice = false;
-            wrongDevice = true;
-            goto Failed;
-        }
-        mTempTouchState.reset();
-        mTempTouchState.down = down;
-        mTempTouchState.deviceId = entry->deviceId;
-        mTempTouchState.source = entry->source;
-        mTempTouchState.displayId = displayId;
-        isSplit = false;
-    } else {
-        mTempTouchState.copyFrom(mTouchState);
-    }
-
-    if (newGesture || (isSplit && maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN)) {
-        /* Case 1: New splittable pointer going down, or need target for hover or scroll. */
-
-        int32_t pointerIndex = getMotionEventActionPointerIndex(action);
-        int32_t x = int32_t(entry->pointerCoords[pointerIndex].
-                getAxisValue(AMOTION_EVENT_AXIS_X));
-        int32_t y = int32_t(entry->pointerCoords[pointerIndex].
-                getAxisValue(AMOTION_EVENT_AXIS_Y));
-        sp<InputWindowHandle> newTouchedWindowHandle;
-        sp<InputWindowHandle> topErrorWindowHandle;
-        bool isTouchModal = false;
-
-        // Traverse windows from front to back to find touched window and outside targets.
-        size_t numWindows = mWindowHandles.size();
-        for (size_t i = 0; i < numWindows; i++) {
-            sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i);
-            const InputWindowInfo* windowInfo = windowHandle->getInfo();
-            if (windowInfo->displayId != displayId) {
-                continue; // wrong display
-            }
-
-            int32_t privateFlags = windowInfo->layoutParamsPrivateFlags;
-            if (privateFlags & InputWindowInfo::PRIVATE_FLAG_SYSTEM_ERROR) {
-                if (topErrorWindowHandle == NULL) {
-                    topErrorWindowHandle = windowHandle;
-                }
-            }
-
-            int32_t flags = windowInfo->layoutParamsFlags;
-            if (windowInfo->visible) {
-                if (! (flags & InputWindowInfo::FLAG_NOT_TOUCHABLE)) {
-                    isTouchModal = (flags & (InputWindowInfo::FLAG_NOT_FOCUSABLE
-                            | InputWindowInfo::FLAG_NOT_TOUCH_MODAL)) == 0;
-                    if (isTouchModal || windowInfo->touchableRegionContainsPoint(x, y)) {
-                        if (! screenWasOff
-                                || (flags & InputWindowInfo::FLAG_TOUCHABLE_WHEN_WAKING)) {
-                            newTouchedWindowHandle = windowHandle;
-                        }
-                        break; // found touched window, exit window loop
-                    }
-                }
-
-                if (maskedAction == AMOTION_EVENT_ACTION_DOWN
-                        && (flags & InputWindowInfo::FLAG_WATCH_OUTSIDE_TOUCH)) {
-                    int32_t outsideTargetFlags = InputTarget::FLAG_DISPATCH_AS_OUTSIDE;
-                    if (isWindowObscuredAtPointLocked(windowHandle, x, y)) {
-                        outsideTargetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
-                    }
-
-                    mTempTouchState.addOrUpdateWindow(
-                            windowHandle, outsideTargetFlags, BitSet32(0));
-                }
-            }
-        }
-
-        // If there is an error window but it is not taking focus (typically because
-        // it is invisible) then wait for it.  Any other focused window may in
-        // fact be in ANR state.
-        if (topErrorWindowHandle != NULL && newTouchedWindowHandle != topErrorWindowHandle) {
-            injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
-                    NULL, NULL, nextWakeupTime,
-                    "Waiting because a system error window is about to be displayed.");
-            injectionPermission = INJECTION_PERMISSION_UNKNOWN;
-            goto Unresponsive;
-        }
-
-        // Figure out whether splitting will be allowed for this window.
-        if (newTouchedWindowHandle != NULL
-                && newTouchedWindowHandle->getInfo()->supportsSplitTouch()) {
-            // New window supports splitting.
-            isSplit = true;
-        } else if (isSplit) {
-            // New window does not support splitting but we have already split events.
-            // Ignore the new window.
-            newTouchedWindowHandle = NULL;
-        }
-
-        // Handle the case where we did not find a window.
-        if (newTouchedWindowHandle == NULL) {
-            // Try to assign the pointer to the first foreground window we find, if there is one.
-            newTouchedWindowHandle = mTempTouchState.getFirstForegroundWindowHandle();
-            if (newTouchedWindowHandle == NULL) {
-                ALOGI("Dropping event because there is no touchable window at (%d, %d).", x, y);
-                injectionResult = INPUT_EVENT_INJECTION_FAILED;
-                goto Failed;
-            }
-        }
-
-        // Set target flags.
-        int32_t targetFlags = InputTarget::FLAG_FOREGROUND | InputTarget::FLAG_DISPATCH_AS_IS;
-        if (isSplit) {
-            targetFlags |= InputTarget::FLAG_SPLIT;
-        }
-        if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) {
-            targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
-        }
-
-        // Update hover state.
-        if (isHoverAction) {
-            newHoverWindowHandle = newTouchedWindowHandle;
-        } else if (maskedAction == AMOTION_EVENT_ACTION_SCROLL) {
-            newHoverWindowHandle = mLastHoverWindowHandle;
-        }
-
-        // Update the temporary touch state.
-        BitSet32 pointerIds;
-        if (isSplit) {
-            uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
-            pointerIds.markBit(pointerId);
-        }
-        mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds);
-    } else {
-        /* Case 2: Pointer move, up, cancel or non-splittable pointer down. */
-
-        // If the pointer is not currently down, then ignore the event.
-        if (! mTempTouchState.down) {
-#if DEBUG_FOCUS
-            ALOGD("Dropping event because the pointer is not down or we previously "
-                    "dropped the pointer down event.");
-#endif
-            injectionResult = INPUT_EVENT_INJECTION_FAILED;
-            goto Failed;
-        }
-
-        // Check whether touches should slip outside of the current foreground window.
-        if (maskedAction == AMOTION_EVENT_ACTION_MOVE
-                && entry->pointerCount == 1
-                && mTempTouchState.isSlippery()) {
-            int32_t x = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X));
-            int32_t y = int32_t(entry->pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y));
-
-            sp<InputWindowHandle> oldTouchedWindowHandle =
-                    mTempTouchState.getFirstForegroundWindowHandle();
-            sp<InputWindowHandle> newTouchedWindowHandle =
-                    findTouchedWindowAtLocked(displayId, x, y);
-            if (oldTouchedWindowHandle != newTouchedWindowHandle
-                    && newTouchedWindowHandle != NULL) {
-#if DEBUG_FOCUS
-                ALOGD("Touch is slipping out of window %s into window %s.",
-                        oldTouchedWindowHandle->getName().string(),
-                        newTouchedWindowHandle->getName().string());
-#endif
-                // Make a slippery exit from the old window.
-                mTempTouchState.addOrUpdateWindow(oldTouchedWindowHandle,
-                        InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT, BitSet32(0));
-
-                // Make a slippery entrance into the new window.
-                if (newTouchedWindowHandle->getInfo()->supportsSplitTouch()) {
-                    isSplit = true;
-                }
-
-                int32_t targetFlags = InputTarget::FLAG_FOREGROUND
-                        | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER;
-                if (isSplit) {
-                    targetFlags |= InputTarget::FLAG_SPLIT;
-                }
-                if (isWindowObscuredAtPointLocked(newTouchedWindowHandle, x, y)) {
-                    targetFlags |= InputTarget::FLAG_WINDOW_IS_OBSCURED;
-                }
-
-                BitSet32 pointerIds;
-                if (isSplit) {
-                    pointerIds.markBit(entry->pointerProperties[0].id);
-                }
-                mTempTouchState.addOrUpdateWindow(newTouchedWindowHandle, targetFlags, pointerIds);
-            }
-        }
-    }
-
-    if (newHoverWindowHandle != mLastHoverWindowHandle) {
-        // Let the previous window know that the hover sequence is over.
-        if (mLastHoverWindowHandle != NULL) {
-#if DEBUG_HOVER
-            ALOGD("Sending hover exit event to window %s.",
-                    mLastHoverWindowHandle->getName().string());
-#endif
-            mTempTouchState.addOrUpdateWindow(mLastHoverWindowHandle,
-                    InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT, BitSet32(0));
-        }
-
-        // Let the new window know that the hover sequence is starting.
-        if (newHoverWindowHandle != NULL) {
-#if DEBUG_HOVER
-            ALOGD("Sending hover enter event to window %s.",
-                    newHoverWindowHandle->getName().string());
-#endif
-            mTempTouchState.addOrUpdateWindow(newHoverWindowHandle,
-                    InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER, BitSet32(0));
-        }
-    }
-
-    // Check permission to inject into all touched foreground windows and ensure there
-    // is at least one touched foreground window.
-    {
-        bool haveForegroundWindow = false;
-        for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
-            const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
-            if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
-                haveForegroundWindow = true;
-                if (! checkInjectionPermission(touchedWindow.windowHandle,
-                        entry->injectionState)) {
-                    injectionResult = INPUT_EVENT_INJECTION_PERMISSION_DENIED;
-                    injectionPermission = INJECTION_PERMISSION_DENIED;
-                    goto Failed;
-                }
-            }
-        }
-        if (! haveForegroundWindow) {
-#if DEBUG_FOCUS
-            ALOGD("Dropping event because there is no touched foreground window to receive it.");
-#endif
-            injectionResult = INPUT_EVENT_INJECTION_FAILED;
-            goto Failed;
-        }
-
-        // Permission granted to injection into all touched foreground windows.
-        injectionPermission = INJECTION_PERMISSION_GRANTED;
-    }
-
-    // Check whether windows listening for outside touches are owned by the same UID. If it is
-    // set the policy flag that we will not reveal coordinate information to this window.
-    if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
-        sp<InputWindowHandle> foregroundWindowHandle =
-                mTempTouchState.getFirstForegroundWindowHandle();
-        const int32_t foregroundWindowUid = foregroundWindowHandle->getInfo()->ownerUid;
-        for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
-            const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
-            if (touchedWindow.targetFlags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
-                sp<InputWindowHandle> inputWindowHandle = touchedWindow.windowHandle;
-                if (inputWindowHandle->getInfo()->ownerUid != foregroundWindowUid) {
-                    mTempTouchState.addOrUpdateWindow(inputWindowHandle,
-                            InputTarget::FLAG_ZERO_COORDS, BitSet32(0));
-                }
-            }
-        }
-    }
-
-    // Ensure all touched foreground windows are ready for new input.
-    for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
-        const TouchedWindow& touchedWindow = mTempTouchState.windows[i];
-        if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND) {
-            // If the touched window is paused then keep waiting.
-            if (touchedWindow.windowHandle->getInfo()->paused) {
-                injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
-                        NULL, touchedWindow.windowHandle, nextWakeupTime,
-                        "Waiting because the touched window is paused.");
-                goto Unresponsive;
-            }
-
-            // If the touched window is still working on previous events then keep waiting.
-            if (!isWindowReadyForMoreInputLocked(currentTime, touchedWindow.windowHandle, entry)) {
-                injectionResult = handleTargetsNotReadyLocked(currentTime, entry,
-                        NULL, touchedWindow.windowHandle, nextWakeupTime,
-                        "Waiting because the touched window has not finished "
-                        "processing the input events that were previously delivered to it.");
-                goto Unresponsive;
-            }
-        }
-    }
-
-    // If this is the first pointer going down and the touched window has a wallpaper
-    // then also add the touched wallpaper windows so they are locked in for the duration
-    // of the touch gesture.
-    // We do not collect wallpapers during HOVER_MOVE or SCROLL because the wallpaper
-    // engine only supports touch events.  We would need to add a mechanism similar
-    // to View.onGenericMotionEvent to enable wallpapers to handle these events.
-    if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
-        sp<InputWindowHandle> foregroundWindowHandle =
-                mTempTouchState.getFirstForegroundWindowHandle();
-        if (foregroundWindowHandle->getInfo()->hasWallpaper) {
-            for (size_t i = 0; i < mWindowHandles.size(); i++) {
-                sp<InputWindowHandle> windowHandle = mWindowHandles.itemAt(i);
-                const InputWindowInfo* info = windowHandle->getInfo();
-                if (info->displayId == displayId
-                        && windowHandle->getInfo()->layoutParamsType
-                                == InputWindowInfo::TYPE_WALLPAPER) {
-                    mTempTouchState.addOrUpdateWindow(windowHandle,
-                            InputTarget::FLAG_WINDOW_IS_OBSCURED
-                                    | InputTarget::FLAG_DISPATCH_AS_IS,
-                            BitSet32(0));
-                }
-            }
-        }
-    }
-
-    // Success!  Output targets.
-    injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
-
-    for (size_t i = 0; i < mTempTouchState.windows.size(); i++) {
-        const TouchedWindow& touchedWindow = mTempTouchState.windows.itemAt(i);
-        addWindowTargetLocked(touchedWindow.windowHandle, touchedWindow.targetFlags,
-                touchedWindow.pointerIds, inputTargets);
-    }
-
-    // Drop the outside or hover touch windows since we will not care about them
-    // in the next iteration.
-    mTempTouchState.filterNonAsIsTouchWindows();
-
-Failed:
-    // Check injection permission once and for all.
-    if (injectionPermission == INJECTION_PERMISSION_UNKNOWN) {
-        if (checkInjectionPermission(NULL, entry->injectionState)) {
-            injectionPermission = INJECTION_PERMISSION_GRANTED;
-        } else {
-            injectionPermission = INJECTION_PERMISSION_DENIED;
-        }
-    }
-
-    // Update final pieces of touch state if the injector had permission.
-    if (injectionPermission == INJECTION_PERMISSION_GRANTED) {
-        if (!wrongDevice) {
-            if (switchedDevice) {
-#if DEBUG_FOCUS
-                ALOGD("Conflicting pointer actions: Switched to a different device.");
-#endif
-                *outConflictingPointerActions = true;
-            }
-
-            if (isHoverAction) {
-                // Started hovering, therefore no longer down.
-                if (mTouchState.down) {
-#if DEBUG_FOCUS
-                    ALOGD("Conflicting pointer actions: Hover received while pointer was down.");
-#endif
-                    *outConflictingPointerActions = true;
-                }
-                mTouchState.reset();
-                if (maskedAction == AMOTION_EVENT_ACTION_HOVER_ENTER
-                        || maskedAction == AMOTION_EVENT_ACTION_HOVER_MOVE) {
-                    mTouchState.deviceId = entry->deviceId;
-                    mTouchState.source = entry->source;
-                    mTouchState.displayId = displayId;
-                }
-            } else if (maskedAction == AMOTION_EVENT_ACTION_UP
-                    || maskedAction == AMOTION_EVENT_ACTION_CANCEL) {
-                // All pointers up or canceled.
-                mTouchState.reset();
-            } else if (maskedAction == AMOTION_EVENT_ACTION_DOWN) {
-                // First pointer went down.
-                if (mTouchState.down) {
-#if DEBUG_FOCUS
-                    ALOGD("Conflicting pointer actions: Down received while already down.");
-#endif
-                    *outConflictingPointerActions = true;
-                }
-                mTouchState.copyFrom(mTempTouchState);
-            } else if (maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
-                // One pointer went up.
-                if (isSplit) {
-                    int32_t pointerIndex = getMotionEventActionPointerIndex(action);
-                    uint32_t pointerId = entry->pointerProperties[pointerIndex].id;
-
-                    for (size_t i = 0; i < mTempTouchState.windows.size(); ) {
-                        TouchedWindow& touchedWindow = mTempTouchState.windows.editItemAt(i);
-                        if (touchedWindow.targetFlags & InputTarget::FLAG_SPLIT) {
-                            touchedWindow.pointerIds.clearBit(pointerId);
-                            if (touchedWindow.pointerIds.isEmpty()) {
-                                mTempTouchState.windows.removeAt(i);
-                                continue;
-                            }
-                        }
-                        i += 1;
-                    }
-                }
-                mTouchState.copyFrom(mTempTouchState);
-            } else if (maskedAction == AMOTION_EVENT_ACTION_SCROLL) {
-                // Discard temporary touch state since it was only valid for this action.
-            } else {
-                // Save changes to touch state as-is for all other actions.
-                mTouchState.copyFrom(mTempTouchState);
-            }
-
-            // Update hover state.
-            mLastHoverWindowHandle = newHoverWindowHandle;
-        }
-    } else {
-#if DEBUG_FOCUS
-        ALOGD("Not updating touch focus because injection was denied.");
-#endif
-    }
-
-Unresponsive:
-    // Reset temporary touch state to ensure we release unnecessary references to input channels.
-    mTempTouchState.reset();
-
-    nsecs_t timeSpentWaitingForApplication = getTimeSpentWaitingForApplicationLocked(currentTime);
-    updateDispatchStatisticsLocked(currentTime, entry,
-            injectionResult, timeSpentWaitingForApplication);
-#if DEBUG_FOCUS
-    ALOGD("findTouchedWindow finished: injectionResult=%d, injectionPermission=%d, "
-            "timeSpentWaitingForApplication=%0.1fms",
-            injectionResult, injectionPermission, timeSpentWaitingForApplication / 1000000.0);
-#endif
-    return injectionResult;
-}
-
-void InputDispatcher::addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
-        int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets) {
-    inputTargets.push();
-
-    const InputWindowInfo* windowInfo = windowHandle->getInfo();
-    InputTarget& target = inputTargets.editTop();
-    target.inputChannel = windowInfo->inputChannel;
-    target.flags = targetFlags;
-    target.xOffset = - windowInfo->frameLeft;
-    target.yOffset = - windowInfo->frameTop;
-    target.scaleFactor = windowInfo->scaleFactor;
-    target.pointerIds = pointerIds;
-}
-
-void InputDispatcher::addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets) {
-    for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
-        inputTargets.push();
-
-        InputTarget& target = inputTargets.editTop();
-        target.inputChannel = mMonitoringChannels[i];
-        target.flags = InputTarget::FLAG_DISPATCH_AS_IS;
-        target.xOffset = 0;
-        target.yOffset = 0;
-        target.pointerIds.clear();
-        target.scaleFactor = 1.0f;
-    }
-}
-
-bool InputDispatcher::checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
-        const InjectionState* injectionState) {
-    if (injectionState
-            && (windowHandle == NULL
-                    || windowHandle->getInfo()->ownerUid != injectionState->injectorUid)
-            && !hasInjectionPermission(injectionState->injectorPid, injectionState->injectorUid)) {
-        if (windowHandle != NULL) {
-            ALOGW("Permission denied: injecting event from pid %d uid %d to window %s "
-                    "owned by uid %d",
-                    injectionState->injectorPid, injectionState->injectorUid,
-                    windowHandle->getName().string(),
-                    windowHandle->getInfo()->ownerUid);
-        } else {
-            ALOGW("Permission denied: injecting event from pid %d uid %d",
-                    injectionState->injectorPid, injectionState->injectorUid);
-        }
-        return false;
-    }
-    return true;
-}
-
-bool InputDispatcher::isWindowObscuredAtPointLocked(
-        const sp<InputWindowHandle>& windowHandle, int32_t x, int32_t y) const {
-    int32_t displayId = windowHandle->getInfo()->displayId;
-    size_t numWindows = mWindowHandles.size();
-    for (size_t i = 0; i < numWindows; i++) {
-        sp<InputWindowHandle> otherHandle = mWindowHandles.itemAt(i);
-        if (otherHandle == windowHandle) {
-            break;
-        }
-
-        const InputWindowInfo* otherInfo = otherHandle->getInfo();
-        if (otherInfo->displayId == displayId
-                && otherInfo->visible && !otherInfo->isTrustedOverlay()
-                && otherInfo->frameContainsPoint(x, y)) {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool InputDispatcher::isWindowReadyForMoreInputLocked(nsecs_t currentTime,
-        const sp<InputWindowHandle>& windowHandle, const EventEntry* eventEntry) {
-    ssize_t connectionIndex = getConnectionIndexLocked(windowHandle->getInputChannel());
-    if (connectionIndex >= 0) {
-        sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
-        if (connection->inputPublisherBlocked) {
-            return false;
-        }
-        if (eventEntry->type == EventEntry::TYPE_KEY) {
-            // If the event is a key event, then we must wait for all previous events to
-            // complete before delivering it because previous events may have the
-            // side-effect of transferring focus to a different window and we want to
-            // ensure that the following keys are sent to the new window.
-            //
-            // Suppose the user touches a button in a window then immediately presses "A".
-            // If the button causes a pop-up window to appear then we want to ensure that
-            // the "A" key is delivered to the new pop-up window.  This is because users
-            // often anticipate pending UI changes when typing on a keyboard.
-            // To obtain this behavior, we must serialize key events with respect to all
-            // prior input events.
-            return connection->outboundQueue.isEmpty()
-                    && connection->waitQueue.isEmpty();
-        }
-        // Touch events can always be sent to a window immediately because the user intended
-        // to touch whatever was visible at the time.  Even if focus changes or a new
-        // window appears moments later, the touch event was meant to be delivered to
-        // whatever window happened to be on screen at the time.
-        //
-        // Generic motion events, such as trackball or joystick events are a little trickier.
-        // Like key events, generic motion events are delivered to the focused window.
-        // Unlike key events, generic motion events don't tend to transfer focus to other
-        // windows and it is not important for them to be serialized.  So we prefer to deliver
-        // generic motion events as soon as possible to improve efficiency and reduce lag
-        // through batching.
-        //
-        // The one case where we pause input event delivery is when the wait queue is piling
-        // up with lots of events because the application is not responding.
-        // This condition ensures that ANRs are detected reliably.
-        if (!connection->waitQueue.isEmpty()
-                && currentTime >= connection->waitQueue.head->deliveryTime
-                        + STREAM_AHEAD_EVENT_TIMEOUT) {
-            return false;
-        }
-    }
-    return true;
-}
-
-String8 InputDispatcher::getApplicationWindowLabelLocked(
-        const sp<InputApplicationHandle>& applicationHandle,
-        const sp<InputWindowHandle>& windowHandle) {
-    if (applicationHandle != NULL) {
-        if (windowHandle != NULL) {
-            String8 label(applicationHandle->getName());
-            label.append(" - ");
-            label.append(windowHandle->getName());
-            return label;
-        } else {
-            return applicationHandle->getName();
-        }
-    } else if (windowHandle != NULL) {
-        return windowHandle->getName();
-    } else {
-        return String8("<unknown application or window>");
-    }
-}
-
-void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) {
-    if (mFocusedWindowHandle != NULL) {
-        const InputWindowInfo* info = mFocusedWindowHandle->getInfo();
-        if (info->inputFeatures & InputWindowInfo::INPUT_FEATURE_DISABLE_USER_ACTIVITY) {
-#if DEBUG_DISPATCH_CYCLE
-            ALOGD("Not poking user activity: disabled by window '%s'.", info->name.string());
-#endif
-            return;
-        }
-    }
-
-    int32_t eventType = USER_ACTIVITY_EVENT_OTHER;
-    switch (eventEntry->type) {
-    case EventEntry::TYPE_MOTION: {
-        const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry);
-        if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) {
-            return;
-        }
-
-        if (MotionEvent::isTouchEvent(motionEntry->source, motionEntry->action)) {
-            eventType = USER_ACTIVITY_EVENT_TOUCH;
-        }
-        break;
-    }
-    case EventEntry::TYPE_KEY: {
-        const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry);
-        if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) {
-            return;
-        }
-        eventType = USER_ACTIVITY_EVENT_BUTTON;
-        break;
-    }
-    }
-
-    CommandEntry* commandEntry = postCommandLocked(
-            & InputDispatcher::doPokeUserActivityLockedInterruptible);
-    commandEntry->eventTime = eventEntry->eventTime;
-    commandEntry->userActivityEventType = eventType;
-}
-
-void InputDispatcher::prepareDispatchCycleLocked(nsecs_t currentTime,
-        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) {
-#if DEBUG_DISPATCH_CYCLE
-    ALOGD("channel '%s' ~ prepareDispatchCycle - flags=0x%08x, "
-            "xOffset=%f, yOffset=%f, scaleFactor=%f, "
-            "pointerIds=0x%x",
-            connection->getInputChannelName(), inputTarget->flags,
-            inputTarget->xOffset, inputTarget->yOffset,
-            inputTarget->scaleFactor, inputTarget->pointerIds.value);
-#endif
-
-    // Skip this event if the connection status is not normal.
-    // We don't want to enqueue additional outbound events if the connection is broken.
-    if (connection->status != Connection::STATUS_NORMAL) {
-#if DEBUG_DISPATCH_CYCLE
-        ALOGD("channel '%s' ~ Dropping event because the channel status is %s",
-                connection->getInputChannelName(), connection->getStatusLabel());
-#endif
-        return;
-    }
-
-    // Split a motion event if needed.
-    if (inputTarget->flags & InputTarget::FLAG_SPLIT) {
-        ALOG_ASSERT(eventEntry->type == EventEntry::TYPE_MOTION);
-
-        MotionEntry* originalMotionEntry = static_cast<MotionEntry*>(eventEntry);
-        if (inputTarget->pointerIds.count() != originalMotionEntry->pointerCount) {
-            MotionEntry* splitMotionEntry = splitMotionEvent(
-                    originalMotionEntry, inputTarget->pointerIds);
-            if (!splitMotionEntry) {
-                return; // split event was dropped
-            }
-#if DEBUG_FOCUS
-            ALOGD("channel '%s' ~ Split motion event.",
-                    connection->getInputChannelName());
-            logOutboundMotionDetailsLocked("  ", splitMotionEntry);
-#endif
-            enqueueDispatchEntriesLocked(currentTime, connection,
-                    splitMotionEntry, inputTarget);
-            splitMotionEntry->release();
-            return;
-        }
-    }
-
-    // Not splitting.  Enqueue dispatch entries for the event as is.
-    enqueueDispatchEntriesLocked(currentTime, connection, eventEntry, inputTarget);
-}
-
-void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime,
-        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget) {
-    bool wasEmpty = connection->outboundQueue.isEmpty();
-
-    // Enqueue dispatch entries for the requested modes.
-    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
-            InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT);
-    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
-            InputTarget::FLAG_DISPATCH_AS_OUTSIDE);
-    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
-            InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER);
-    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
-            InputTarget::FLAG_DISPATCH_AS_IS);
-    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
-            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT);
-    enqueueDispatchEntryLocked(connection, eventEntry, inputTarget,
-            InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER);
-
-    // If the outbound queue was previously empty, start the dispatch cycle going.
-    if (wasEmpty && !connection->outboundQueue.isEmpty()) {
-        startDispatchCycleLocked(currentTime, connection);
-    }
-}
-
-void InputDispatcher::enqueueDispatchEntryLocked(
-        const sp<Connection>& connection, EventEntry* eventEntry, const InputTarget* inputTarget,
-        int32_t dispatchMode) {
-    int32_t inputTargetFlags = inputTarget->flags;
-    if (!(inputTargetFlags & dispatchMode)) {
-        return;
-    }
-    inputTargetFlags = (inputTargetFlags & ~InputTarget::FLAG_DISPATCH_MASK) | dispatchMode;
-
-    // This is a new event.
-    // Enqueue a new dispatch entry onto the outbound queue for this connection.
-    DispatchEntry* dispatchEntry = new DispatchEntry(eventEntry, // increments ref
-            inputTargetFlags, inputTarget->xOffset, inputTarget->yOffset,
-            inputTarget->scaleFactor);
-
-    // Apply target flags and update the connection's input state.
-    switch (eventEntry->type) {
-    case EventEntry::TYPE_KEY: {
-        KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry);
-        dispatchEntry->resolvedAction = keyEntry->action;
-        dispatchEntry->resolvedFlags = keyEntry->flags;
-
-        if (!connection->inputState.trackKey(keyEntry,
-                dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags)) {
-#if DEBUG_DISPATCH_CYCLE
-            ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent key event",
-                    connection->getInputChannelName());
-#endif
-            delete dispatchEntry;
-            return; // skip the inconsistent event
-        }
-        break;
-    }
-
-    case EventEntry::TYPE_MOTION: {
-        MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
-        if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) {
-            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_OUTSIDE;
-        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_EXIT) {
-            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_EXIT;
-        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_HOVER_ENTER) {
-            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER;
-        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
-            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_CANCEL;
-        } else if (dispatchMode & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER) {
-            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_DOWN;
-        } else {
-            dispatchEntry->resolvedAction = motionEntry->action;
-        }
-        if (dispatchEntry->resolvedAction == AMOTION_EVENT_ACTION_HOVER_MOVE
-                && !connection->inputState.isHovering(
-                        motionEntry->deviceId, motionEntry->source, motionEntry->displayId)) {
-#if DEBUG_DISPATCH_CYCLE
-        ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: filling in missing hover enter event",
-                connection->getInputChannelName());
-#endif
-            dispatchEntry->resolvedAction = AMOTION_EVENT_ACTION_HOVER_ENTER;
-        }
-
-        dispatchEntry->resolvedFlags = motionEntry->flags;
-        if (dispatchEntry->targetFlags & InputTarget::FLAG_WINDOW_IS_OBSCURED) {
-            dispatchEntry->resolvedFlags |= AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
-        }
-
-        if (!connection->inputState.trackMotion(motionEntry,
-                dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags)) {
-#if DEBUG_DISPATCH_CYCLE
-            ALOGD("channel '%s' ~ enqueueDispatchEntryLocked: skipping inconsistent motion event",
-                    connection->getInputChannelName());
-#endif
-            delete dispatchEntry;
-            return; // skip the inconsistent event
-        }
-        break;
-    }
-    }
-
-    // Remember that we are waiting for this dispatch to complete.
-    if (dispatchEntry->hasForegroundTarget()) {
-        incrementPendingForegroundDispatchesLocked(eventEntry);
-    }
-
-    // Enqueue the dispatch entry.
-    connection->outboundQueue.enqueueAtTail(dispatchEntry);
-    traceOutboundQueueLengthLocked(connection);
-}
-
-void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime,
-        const sp<Connection>& connection) {
-#if DEBUG_DISPATCH_CYCLE
-    ALOGD("channel '%s' ~ startDispatchCycle",
-            connection->getInputChannelName());
-#endif
-
-    while (connection->status == Connection::STATUS_NORMAL
-            && !connection->outboundQueue.isEmpty()) {
-        DispatchEntry* dispatchEntry = connection->outboundQueue.head;
-        dispatchEntry->deliveryTime = currentTime;
-
-        // Publish the event.
-        status_t status;
-        EventEntry* eventEntry = dispatchEntry->eventEntry;
-        switch (eventEntry->type) {
-        case EventEntry::TYPE_KEY: {
-            KeyEntry* keyEntry = static_cast<KeyEntry*>(eventEntry);
-
-            // Publish the key event.
-            status = connection->inputPublisher.publishKeyEvent(dispatchEntry->seq,
-                    keyEntry->deviceId, keyEntry->source,
-                    dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags,
-                    keyEntry->keyCode, keyEntry->scanCode,
-                    keyEntry->metaState, keyEntry->repeatCount, keyEntry->downTime,
-                    keyEntry->eventTime);
-            break;
-        }
-
-        case EventEntry::TYPE_MOTION: {
-            MotionEntry* motionEntry = static_cast<MotionEntry*>(eventEntry);
-
-            PointerCoords scaledCoords[MAX_POINTERS];
-            const PointerCoords* usingCoords = motionEntry->pointerCoords;
-
-            // Set the X and Y offset depending on the input source.
-            float xOffset, yOffset, scaleFactor;
-            if ((motionEntry->source & AINPUT_SOURCE_CLASS_POINTER)
-                    && !(dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS)) {
-                scaleFactor = dispatchEntry->scaleFactor;
-                xOffset = dispatchEntry->xOffset * scaleFactor;
-                yOffset = dispatchEntry->yOffset * scaleFactor;
-                if (scaleFactor != 1.0f) {
-                    for (size_t i = 0; i < motionEntry->pointerCount; i++) {
-                        scaledCoords[i] = motionEntry->pointerCoords[i];
-                        scaledCoords[i].scale(scaleFactor);
-                    }
-                    usingCoords = scaledCoords;
-                }
-            } else {
-                xOffset = 0.0f;
-                yOffset = 0.0f;
-                scaleFactor = 1.0f;
-
-                // We don't want the dispatch target to know.
-                if (dispatchEntry->targetFlags & InputTarget::FLAG_ZERO_COORDS) {
-                    for (size_t i = 0; i < motionEntry->pointerCount; i++) {
-                        scaledCoords[i].clear();
-                    }
-                    usingCoords = scaledCoords;
-                }
-            }
-
-            // Publish the motion event.
-            status = connection->inputPublisher.publishMotionEvent(dispatchEntry->seq,
-                    motionEntry->deviceId, motionEntry->source,
-                    dispatchEntry->resolvedAction, dispatchEntry->resolvedFlags,
-                    motionEntry->edgeFlags, motionEntry->metaState, motionEntry->buttonState,
-                    xOffset, yOffset,
-                    motionEntry->xPrecision, motionEntry->yPrecision,
-                    motionEntry->downTime, motionEntry->eventTime,
-                    motionEntry->pointerCount, motionEntry->pointerProperties,
-                    usingCoords);
-            break;
-        }
-
-        default:
-            ALOG_ASSERT(false);
-            return;
-        }
-
-        // Check the result.
-        if (status) {
-            if (status == WOULD_BLOCK) {
-                if (connection->waitQueue.isEmpty()) {
-                    ALOGE("channel '%s' ~ Could not publish event because the pipe is full. "
-                            "This is unexpected because the wait queue is empty, so the pipe "
-                            "should be empty and we shouldn't have any problems writing an "
-                            "event to it, status=%d", connection->getInputChannelName(), status);
-                    abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);
-                } else {
-                    // Pipe is full and we are waiting for the app to finish process some events
-                    // before sending more events to it.
-#if DEBUG_DISPATCH_CYCLE
-                    ALOGD("channel '%s' ~ Could not publish event because the pipe is full, "
-                            "waiting for the application to catch up",
-                            connection->getInputChannelName());
-#endif
-                    connection->inputPublisherBlocked = true;
-                }
-            } else {
-                ALOGE("channel '%s' ~ Could not publish event due to an unexpected error, "
-                        "status=%d", connection->getInputChannelName(), status);
-                abortBrokenDispatchCycleLocked(currentTime, connection, true /*notify*/);
-            }
-            return;
-        }
-
-        // Re-enqueue the event on the wait queue.
-        connection->outboundQueue.dequeue(dispatchEntry);
-        traceOutboundQueueLengthLocked(connection);
-        connection->waitQueue.enqueueAtTail(dispatchEntry);
-        traceWaitQueueLengthLocked(connection);
-    }
-}
-
-void InputDispatcher::finishDispatchCycleLocked(nsecs_t currentTime,
-        const sp<Connection>& connection, uint32_t seq, bool handled) {
-#if DEBUG_DISPATCH_CYCLE
-    ALOGD("channel '%s' ~ finishDispatchCycle - seq=%u, handled=%s",
-            connection->getInputChannelName(), seq, toString(handled));
-#endif
-
-    connection->inputPublisherBlocked = false;
-
-    if (connection->status == Connection::STATUS_BROKEN
-            || connection->status == Connection::STATUS_ZOMBIE) {
-        return;
-    }
-
-    // Notify other system components and prepare to start the next dispatch cycle.
-    onDispatchCycleFinishedLocked(currentTime, connection, seq, handled);
-}
-
-void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime,
-        const sp<Connection>& connection, bool notify) {
-#if DEBUG_DISPATCH_CYCLE
-    ALOGD("channel '%s' ~ abortBrokenDispatchCycle - notify=%s",
-            connection->getInputChannelName(), toString(notify));
-#endif
-
-    // Clear the dispatch queues.
-    drainDispatchQueueLocked(&connection->outboundQueue);
-    traceOutboundQueueLengthLocked(connection);
-    drainDispatchQueueLocked(&connection->waitQueue);
-    traceWaitQueueLengthLocked(connection);
-
-    // The connection appears to be unrecoverably broken.
-    // Ignore already broken or zombie connections.
-    if (connection->status == Connection::STATUS_NORMAL) {
-        connection->status = Connection::STATUS_BROKEN;
-
-        if (notify) {
-            // Notify other system components.
-            onDispatchCycleBrokenLocked(currentTime, connection);
-        }
-    }
-}
-
-void InputDispatcher::drainDispatchQueueLocked(Queue<DispatchEntry>* queue) {
-    while (!queue->isEmpty()) {
-        DispatchEntry* dispatchEntry = queue->dequeueAtHead();
-        releaseDispatchEntryLocked(dispatchEntry);
-    }
-}
-
-void InputDispatcher::releaseDispatchEntryLocked(DispatchEntry* dispatchEntry) {
-    if (dispatchEntry->hasForegroundTarget()) {
-        decrementPendingForegroundDispatchesLocked(dispatchEntry->eventEntry);
-    }
-    delete dispatchEntry;
-}
-
-int InputDispatcher::handleReceiveCallback(int fd, int events, void* data) {
-    InputDispatcher* d = static_cast<InputDispatcher*>(data);
-
-    { // acquire lock
-        AutoMutex _l(d->mLock);
-
-        ssize_t connectionIndex = d->mConnectionsByFd.indexOfKey(fd);
-        if (connectionIndex < 0) {
-            ALOGE("Received spurious receive callback for unknown input channel.  "
-                    "fd=%d, events=0x%x", fd, events);
-            return 0; // remove the callback
-        }
-
-        bool notify;
-        sp<Connection> connection = d->mConnectionsByFd.valueAt(connectionIndex);
-        if (!(events & (ALOOPER_EVENT_ERROR | ALOOPER_EVENT_HANGUP))) {
-            if (!(events & ALOOPER_EVENT_INPUT)) {
-                ALOGW("channel '%s' ~ Received spurious callback for unhandled poll event.  "
-                        "events=0x%x", connection->getInputChannelName(), events);
-                return 1;
-            }
-
-            nsecs_t currentTime = now();
-            bool gotOne = false;
-            status_t status;
-            for (;;) {
-                uint32_t seq;
-                bool handled;
-                status = connection->inputPublisher.receiveFinishedSignal(&seq, &handled);
-                if (status) {
-                    break;
-                }
-                d->finishDispatchCycleLocked(currentTime, connection, seq, handled);
-                gotOne = true;
-            }
-            if (gotOne) {
-                d->runCommandsLockedInterruptible();
-                if (status == WOULD_BLOCK) {
-                    return 1;
-                }
-            }
-
-            notify = status != DEAD_OBJECT || !connection->monitor;
-            if (notify) {
-                ALOGE("channel '%s' ~ Failed to receive finished signal.  status=%d",
-                        connection->getInputChannelName(), status);
-            }
-        } else {
-            // Monitor channels are never explicitly unregistered.
-            // We do it automatically when the remote endpoint is closed so don't warn
-            // about them.
-            notify = !connection->monitor;
-            if (notify) {
-                ALOGW("channel '%s' ~ Consumer closed input channel or an error occurred.  "
-                        "events=0x%x", connection->getInputChannelName(), events);
-            }
-        }
-
-        // Unregister the channel.
-        d->unregisterInputChannelLocked(connection->inputChannel, notify);
-        return 0; // remove the callback
-    } // release lock
-}
-
-void InputDispatcher::synthesizeCancelationEventsForAllConnectionsLocked(
-        const CancelationOptions& options) {
-    for (size_t i = 0; i < mConnectionsByFd.size(); i++) {
-        synthesizeCancelationEventsForConnectionLocked(
-                mConnectionsByFd.valueAt(i), options);
-    }
-}
-
-void InputDispatcher::synthesizeCancelationEventsForInputChannelLocked(
-        const sp<InputChannel>& channel, const CancelationOptions& options) {
-    ssize_t index = getConnectionIndexLocked(channel);
-    if (index >= 0) {
-        synthesizeCancelationEventsForConnectionLocked(
-                mConnectionsByFd.valueAt(index), options);
-    }
-}
-
-void InputDispatcher::synthesizeCancelationEventsForConnectionLocked(
-        const sp<Connection>& connection, const CancelationOptions& options) {
-    if (connection->status == Connection::STATUS_BROKEN) {
-        return;
-    }
-
-    nsecs_t currentTime = now();
-
-    Vector<EventEntry*> cancelationEvents;
-    connection->inputState.synthesizeCancelationEvents(currentTime,
-            cancelationEvents, options);
-
-    if (!cancelationEvents.isEmpty()) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-        ALOGD("channel '%s' ~ Synthesized %d cancelation events to bring channel back in sync "
-                "with reality: %s, mode=%d.",
-                connection->getInputChannelName(), cancelationEvents.size(),
-                options.reason, options.mode);
-#endif
-        for (size_t i = 0; i < cancelationEvents.size(); i++) {
-            EventEntry* cancelationEventEntry = cancelationEvents.itemAt(i);
-            switch (cancelationEventEntry->type) {
-            case EventEntry::TYPE_KEY:
-                logOutboundKeyDetailsLocked("cancel - ",
-                        static_cast<KeyEntry*>(cancelationEventEntry));
-                break;
-            case EventEntry::TYPE_MOTION:
-                logOutboundMotionDetailsLocked("cancel - ",
-                        static_cast<MotionEntry*>(cancelationEventEntry));
-                break;
-            }
-
-            InputTarget target;
-            sp<InputWindowHandle> windowHandle = getWindowHandleLocked(connection->inputChannel);
-            if (windowHandle != NULL) {
-                const InputWindowInfo* windowInfo = windowHandle->getInfo();
-                target.xOffset = -windowInfo->frameLeft;
-                target.yOffset = -windowInfo->frameTop;
-                target.scaleFactor = windowInfo->scaleFactor;
-            } else {
-                target.xOffset = 0;
-                target.yOffset = 0;
-                target.scaleFactor = 1.0f;
-            }
-            target.inputChannel = connection->inputChannel;
-            target.flags = InputTarget::FLAG_DISPATCH_AS_IS;
-
-            enqueueDispatchEntryLocked(connection, cancelationEventEntry, // increments ref
-                    &target, InputTarget::FLAG_DISPATCH_AS_IS);
-
-            cancelationEventEntry->release();
-        }
-
-        startDispatchCycleLocked(currentTime, connection);
-    }
-}
-
-InputDispatcher::MotionEntry*
-InputDispatcher::splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds) {
-    ALOG_ASSERT(pointerIds.value != 0);
-
-    uint32_t splitPointerIndexMap[MAX_POINTERS];
-    PointerProperties splitPointerProperties[MAX_POINTERS];
-    PointerCoords splitPointerCoords[MAX_POINTERS];
-
-    uint32_t originalPointerCount = originalMotionEntry->pointerCount;
-    uint32_t splitPointerCount = 0;
-
-    for (uint32_t originalPointerIndex = 0; originalPointerIndex < originalPointerCount;
-            originalPointerIndex++) {
-        const PointerProperties& pointerProperties =
-                originalMotionEntry->pointerProperties[originalPointerIndex];
-        uint32_t pointerId = uint32_t(pointerProperties.id);
-        if (pointerIds.hasBit(pointerId)) {
-            splitPointerIndexMap[splitPointerCount] = originalPointerIndex;
-            splitPointerProperties[splitPointerCount].copyFrom(pointerProperties);
-            splitPointerCoords[splitPointerCount].copyFrom(
-                    originalMotionEntry->pointerCoords[originalPointerIndex]);
-            splitPointerCount += 1;
-        }
-    }
-
-    if (splitPointerCount != pointerIds.count()) {
-        // This is bad.  We are missing some of the pointers that we expected to deliver.
-        // Most likely this indicates that we received an ACTION_MOVE events that has
-        // different pointer ids than we expected based on the previous ACTION_DOWN
-        // or ACTION_POINTER_DOWN events that caused us to decide to split the pointers
-        // in this way.
-        ALOGW("Dropping split motion event because the pointer count is %d but "
-                "we expected there to be %d pointers.  This probably means we received "
-                "a broken sequence of pointer ids from the input device.",
-                splitPointerCount, pointerIds.count());
-        return NULL;
-    }
-
-    int32_t action = originalMotionEntry->action;
-    int32_t maskedAction = action & AMOTION_EVENT_ACTION_MASK;
-    if (maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN
-            || maskedAction == AMOTION_EVENT_ACTION_POINTER_UP) {
-        int32_t originalPointerIndex = getMotionEventActionPointerIndex(action);
-        const PointerProperties& pointerProperties =
-                originalMotionEntry->pointerProperties[originalPointerIndex];
-        uint32_t pointerId = uint32_t(pointerProperties.id);
-        if (pointerIds.hasBit(pointerId)) {
-            if (pointerIds.count() == 1) {
-                // The first/last pointer went down/up.
-                action = maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN
-                        ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
-            } else {
-                // A secondary pointer went down/up.
-                uint32_t splitPointerIndex = 0;
-                while (pointerId != uint32_t(splitPointerProperties[splitPointerIndex].id)) {
-                    splitPointerIndex += 1;
-                }
-                action = maskedAction | (splitPointerIndex
-                        << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
-            }
-        } else {
-            // An unrelated pointer changed.
-            action = AMOTION_EVENT_ACTION_MOVE;
-        }
-    }
-
-    MotionEntry* splitMotionEntry = new MotionEntry(
-            originalMotionEntry->eventTime,
-            originalMotionEntry->deviceId,
-            originalMotionEntry->source,
-            originalMotionEntry->policyFlags,
-            action,
-            originalMotionEntry->flags,
-            originalMotionEntry->metaState,
-            originalMotionEntry->buttonState,
-            originalMotionEntry->edgeFlags,
-            originalMotionEntry->xPrecision,
-            originalMotionEntry->yPrecision,
-            originalMotionEntry->downTime,
-            originalMotionEntry->displayId,
-            splitPointerCount, splitPointerProperties, splitPointerCoords);
-
-    if (originalMotionEntry->injectionState) {
-        splitMotionEntry->injectionState = originalMotionEntry->injectionState;
-        splitMotionEntry->injectionState->refCount += 1;
-    }
-
-    return splitMotionEntry;
-}
-
-void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
-#if DEBUG_INBOUND_EVENT_DETAILS
-    ALOGD("notifyConfigurationChanged - eventTime=%lld", args->eventTime);
-#endif
-
-    bool needWake;
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        ConfigurationChangedEntry* newEntry = new ConfigurationChangedEntry(args->eventTime);
-        needWake = enqueueInboundEventLocked(newEntry);
-    } // release lock
-
-    if (needWake) {
-        mLooper->wake();
-    }
-}
-
-void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
-#if DEBUG_INBOUND_EVENT_DETAILS
-    ALOGD("notifyKey - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, action=0x%x, "
-            "flags=0x%x, keyCode=0x%x, scanCode=0x%x, metaState=0x%x, downTime=%lld",
-            args->eventTime, args->deviceId, args->source, args->policyFlags,
-            args->action, args->flags, args->keyCode, args->scanCode,
-            args->metaState, args->downTime);
-#endif
-    if (!validateKeyEvent(args->action)) {
-        return;
-    }
-
-    uint32_t policyFlags = args->policyFlags;
-    int32_t flags = args->flags;
-    int32_t metaState = args->metaState;
-    if ((policyFlags & POLICY_FLAG_VIRTUAL) || (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY)) {
-        policyFlags |= POLICY_FLAG_VIRTUAL;
-        flags |= AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY;
-    }
-    if (policyFlags & POLICY_FLAG_ALT) {
-        metaState |= AMETA_ALT_ON | AMETA_ALT_LEFT_ON;
-    }
-    if (policyFlags & POLICY_FLAG_ALT_GR) {
-        metaState |= AMETA_ALT_ON | AMETA_ALT_RIGHT_ON;
-    }
-    if (policyFlags & POLICY_FLAG_SHIFT) {
-        metaState |= AMETA_SHIFT_ON | AMETA_SHIFT_LEFT_ON;
-    }
-    if (policyFlags & POLICY_FLAG_CAPS_LOCK) {
-        metaState |= AMETA_CAPS_LOCK_ON;
-    }
-    if (policyFlags & POLICY_FLAG_FUNCTION) {
-        metaState |= AMETA_FUNCTION_ON;
-    }
-
-    policyFlags |= POLICY_FLAG_TRUSTED;
-
-    KeyEvent event;
-    event.initialize(args->deviceId, args->source, args->action,
-            flags, args->keyCode, args->scanCode, metaState, 0,
-            args->downTime, args->eventTime);
-
-    mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags);
-
-    if (policyFlags & POLICY_FLAG_WOKE_HERE) {
-        flags |= AKEY_EVENT_FLAG_WOKE_HERE;
-    }
-
-    bool needWake;
-    { // acquire lock
-        mLock.lock();
-
-        if (shouldSendKeyToInputFilterLocked(args)) {
-            mLock.unlock();
-
-            policyFlags |= POLICY_FLAG_FILTERED;
-            if (!mPolicy->filterInputEvent(&event, policyFlags)) {
-                return; // event was consumed by the filter
-            }
-
-            mLock.lock();
-        }
-
-        int32_t repeatCount = 0;
-        KeyEntry* newEntry = new KeyEntry(args->eventTime,
-                args->deviceId, args->source, policyFlags,
-                args->action, flags, args->keyCode, args->scanCode,
-                metaState, repeatCount, args->downTime);
-
-        needWake = enqueueInboundEventLocked(newEntry);
-        mLock.unlock();
-    } // release lock
-
-    if (needWake) {
-        mLooper->wake();
-    }
-}
-
-bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) {
-    return mInputFilterEnabled;
-}
-
-void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {
-#if DEBUG_INBOUND_EVENT_DETAILS
-    ALOGD("notifyMotion - eventTime=%lld, deviceId=%d, source=0x%x, policyFlags=0x%x, "
-            "action=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, edgeFlags=0x%x, "
-            "xPrecision=%f, yPrecision=%f, downTime=%lld",
-            args->eventTime, args->deviceId, args->source, args->policyFlags,
-            args->action, args->flags, args->metaState, args->buttonState,
-            args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime);
-    for (uint32_t i = 0; i < args->pointerCount; i++) {
-        ALOGD("  Pointer %d: id=%d, toolType=%d, "
-                "x=%f, y=%f, pressure=%f, size=%f, "
-                "touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, "
-                "orientation=%f",
-                i, args->pointerProperties[i].id,
-                args->pointerProperties[i].toolType,
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
-                args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
-    }
-#endif
-    if (!validateMotionEvent(args->action, args->pointerCount, args->pointerProperties)) {
-        return;
-    }
-
-    uint32_t policyFlags = args->policyFlags;
-    policyFlags |= POLICY_FLAG_TRUSTED;
-    mPolicy->interceptMotionBeforeQueueing(args->eventTime, /*byref*/ policyFlags);
-
-    bool needWake;
-    { // acquire lock
-        mLock.lock();
-
-        if (shouldSendMotionToInputFilterLocked(args)) {
-            mLock.unlock();
-
-            MotionEvent event;
-            event.initialize(args->deviceId, args->source, args->action, args->flags,
-                    args->edgeFlags, args->metaState, args->buttonState, 0, 0,
-                    args->xPrecision, args->yPrecision,
-                    args->downTime, args->eventTime,
-                    args->pointerCount, args->pointerProperties, args->pointerCoords);
-
-            policyFlags |= POLICY_FLAG_FILTERED;
-            if (!mPolicy->filterInputEvent(&event, policyFlags)) {
-                return; // event was consumed by the filter
-            }
-
-            mLock.lock();
-        }
-
-        // Just enqueue a new motion event.
-        MotionEntry* newEntry = new MotionEntry(args->eventTime,
-                args->deviceId, args->source, policyFlags,
-                args->action, args->flags, args->metaState, args->buttonState,
-                args->edgeFlags, args->xPrecision, args->yPrecision, args->downTime,
-                args->displayId,
-                args->pointerCount, args->pointerProperties, args->pointerCoords);
-
-        needWake = enqueueInboundEventLocked(newEntry);
-        mLock.unlock();
-    } // release lock
-
-    if (needWake) {
-        mLooper->wake();
-    }
-}
-
-bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) {
-    // TODO: support sending secondary display events to input filter
-    return mInputFilterEnabled && isMainDisplay(args->displayId);
-}
-
-void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
-#if DEBUG_INBOUND_EVENT_DETAILS
-    ALOGD("notifySwitch - eventTime=%lld, policyFlags=0x%x, switchValues=0x%08x, switchMask=0x%08x",
-            args->eventTime, args->policyFlags,
-            args->switchValues, args->switchMask);
-#endif
-
-    uint32_t policyFlags = args->policyFlags;
-    policyFlags |= POLICY_FLAG_TRUSTED;
-    mPolicy->notifySwitch(args->eventTime,
-            args->switchValues, args->switchMask, policyFlags);
-}
-
-void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
-#if DEBUG_INBOUND_EVENT_DETAILS
-    ALOGD("notifyDeviceReset - eventTime=%lld, deviceId=%d",
-            args->eventTime, args->deviceId);
-#endif
-
-    bool needWake;
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        DeviceResetEntry* newEntry = new DeviceResetEntry(args->eventTime, args->deviceId);
-        needWake = enqueueInboundEventLocked(newEntry);
-    } // release lock
-
-    if (needWake) {
-        mLooper->wake();
-    }
-}
-
-int32_t InputDispatcher::injectInputEvent(const InputEvent* event,
-        int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
-        uint32_t policyFlags) {
-#if DEBUG_INBOUND_EVENT_DETAILS
-    ALOGD("injectInputEvent - eventType=%d, injectorPid=%d, injectorUid=%d, "
-            "syncMode=%d, timeoutMillis=%d, policyFlags=0x%08x",
-            event->getType(), injectorPid, injectorUid, syncMode, timeoutMillis, policyFlags);
-#endif
-
-    nsecs_t endTime = now() + milliseconds_to_nanoseconds(timeoutMillis);
-
-    policyFlags |= POLICY_FLAG_INJECTED;
-    if (hasInjectionPermission(injectorPid, injectorUid)) {
-        policyFlags |= POLICY_FLAG_TRUSTED;
-    }
-
-    EventEntry* firstInjectedEntry;
-    EventEntry* lastInjectedEntry;
-    switch (event->getType()) {
-    case AINPUT_EVENT_TYPE_KEY: {
-        const KeyEvent* keyEvent = static_cast<const KeyEvent*>(event);
-        int32_t action = keyEvent->getAction();
-        if (! validateKeyEvent(action)) {
-            return INPUT_EVENT_INJECTION_FAILED;
-        }
-
-        int32_t flags = keyEvent->getFlags();
-        if (flags & AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY) {
-            policyFlags |= POLICY_FLAG_VIRTUAL;
-        }
-
-        if (!(policyFlags & POLICY_FLAG_FILTERED)) {
-            mPolicy->interceptKeyBeforeQueueing(keyEvent, /*byref*/ policyFlags);
-        }
-
-        if (policyFlags & POLICY_FLAG_WOKE_HERE) {
-            flags |= AKEY_EVENT_FLAG_WOKE_HERE;
-        }
-
-        mLock.lock();
-        firstInjectedEntry = new KeyEntry(keyEvent->getEventTime(),
-                keyEvent->getDeviceId(), keyEvent->getSource(),
-                policyFlags, action, flags,
-                keyEvent->getKeyCode(), keyEvent->getScanCode(), keyEvent->getMetaState(),
-                keyEvent->getRepeatCount(), keyEvent->getDownTime());
-        lastInjectedEntry = firstInjectedEntry;
-        break;
-    }
-
-    case AINPUT_EVENT_TYPE_MOTION: {
-        const MotionEvent* motionEvent = static_cast<const MotionEvent*>(event);
-        int32_t displayId = ADISPLAY_ID_DEFAULT;
-        int32_t action = motionEvent->getAction();
-        size_t pointerCount = motionEvent->getPointerCount();
-        const PointerProperties* pointerProperties = motionEvent->getPointerProperties();
-        if (! validateMotionEvent(action, pointerCount, pointerProperties)) {
-            return INPUT_EVENT_INJECTION_FAILED;
-        }
-
-        if (!(policyFlags & POLICY_FLAG_FILTERED)) {
-            nsecs_t eventTime = motionEvent->getEventTime();
-            mPolicy->interceptMotionBeforeQueueing(eventTime, /*byref*/ policyFlags);
-        }
-
-        mLock.lock();
-        const nsecs_t* sampleEventTimes = motionEvent->getSampleEventTimes();
-        const PointerCoords* samplePointerCoords = motionEvent->getSamplePointerCoords();
-        firstInjectedEntry = new MotionEntry(*sampleEventTimes,
-                motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags,
-                action, motionEvent->getFlags(),
-                motionEvent->getMetaState(), motionEvent->getButtonState(),
-                motionEvent->getEdgeFlags(),
-                motionEvent->getXPrecision(), motionEvent->getYPrecision(),
-                motionEvent->getDownTime(), displayId,
-                uint32_t(pointerCount), pointerProperties, samplePointerCoords);
-        lastInjectedEntry = firstInjectedEntry;
-        for (size_t i = motionEvent->getHistorySize(); i > 0; i--) {
-            sampleEventTimes += 1;
-            samplePointerCoords += pointerCount;
-            MotionEntry* nextInjectedEntry = new MotionEntry(*sampleEventTimes,
-                    motionEvent->getDeviceId(), motionEvent->getSource(), policyFlags,
-                    action, motionEvent->getFlags(),
-                    motionEvent->getMetaState(), motionEvent->getButtonState(),
-                    motionEvent->getEdgeFlags(),
-                    motionEvent->getXPrecision(), motionEvent->getYPrecision(),
-                    motionEvent->getDownTime(), displayId,
-                    uint32_t(pointerCount), pointerProperties, samplePointerCoords);
-            lastInjectedEntry->next = nextInjectedEntry;
-            lastInjectedEntry = nextInjectedEntry;
-        }
-        break;
-    }
-
-    default:
-        ALOGW("Cannot inject event of type %d", event->getType());
-        return INPUT_EVENT_INJECTION_FAILED;
-    }
-
-    InjectionState* injectionState = new InjectionState(injectorPid, injectorUid);
-    if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) {
-        injectionState->injectionIsAsync = true;
-    }
-
-    injectionState->refCount += 1;
-    lastInjectedEntry->injectionState = injectionState;
-
-    bool needWake = false;
-    for (EventEntry* entry = firstInjectedEntry; entry != NULL; ) {
-        EventEntry* nextEntry = entry->next;
-        needWake |= enqueueInboundEventLocked(entry);
-        entry = nextEntry;
-    }
-
-    mLock.unlock();
-
-    if (needWake) {
-        mLooper->wake();
-    }
-
-    int32_t injectionResult;
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (syncMode == INPUT_EVENT_INJECTION_SYNC_NONE) {
-            injectionResult = INPUT_EVENT_INJECTION_SUCCEEDED;
-        } else {
-            for (;;) {
-                injectionResult = injectionState->injectionResult;
-                if (injectionResult != INPUT_EVENT_INJECTION_PENDING) {
-                    break;
-                }
-
-                nsecs_t remainingTimeout = endTime - now();
-                if (remainingTimeout <= 0) {
-#if DEBUG_INJECTION
-                    ALOGD("injectInputEvent - Timed out waiting for injection result "
-                            "to become available.");
-#endif
-                    injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT;
-                    break;
-                }
-
-                mInjectionResultAvailableCondition.waitRelative(mLock, remainingTimeout);
-            }
-
-            if (injectionResult == INPUT_EVENT_INJECTION_SUCCEEDED
-                    && syncMode == INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED) {
-                while (injectionState->pendingForegroundDispatches != 0) {
-#if DEBUG_INJECTION
-                    ALOGD("injectInputEvent - Waiting for %d pending foreground dispatches.",
-                            injectionState->pendingForegroundDispatches);
-#endif
-                    nsecs_t remainingTimeout = endTime - now();
-                    if (remainingTimeout <= 0) {
-#if DEBUG_INJECTION
-                    ALOGD("injectInputEvent - Timed out waiting for pending foreground "
-                            "dispatches to finish.");
-#endif
-                        injectionResult = INPUT_EVENT_INJECTION_TIMED_OUT;
-                        break;
-                    }
-
-                    mInjectionSyncFinishedCondition.waitRelative(mLock, remainingTimeout);
-                }
-            }
-        }
-
-        injectionState->release();
-    } // release lock
-
-#if DEBUG_INJECTION
-    ALOGD("injectInputEvent - Finished with result %d.  "
-            "injectorPid=%d, injectorUid=%d",
-            injectionResult, injectorPid, injectorUid);
-#endif
-
-    return injectionResult;
-}
-
-bool InputDispatcher::hasInjectionPermission(int32_t injectorPid, int32_t injectorUid) {
-    return injectorUid == 0
-            || mPolicy->checkInjectEventsPermissionNonReentrant(injectorPid, injectorUid);
-}
-
-void InputDispatcher::setInjectionResultLocked(EventEntry* entry, int32_t injectionResult) {
-    InjectionState* injectionState = entry->injectionState;
-    if (injectionState) {
-#if DEBUG_INJECTION
-        ALOGD("Setting input event injection result to %d.  "
-                "injectorPid=%d, injectorUid=%d",
-                 injectionResult, injectionState->injectorPid, injectionState->injectorUid);
-#endif
-
-        if (injectionState->injectionIsAsync
-                && !(entry->policyFlags & POLICY_FLAG_FILTERED)) {
-            // Log the outcome since the injector did not wait for the injection result.
-            switch (injectionResult) {
-            case INPUT_EVENT_INJECTION_SUCCEEDED:
-                ALOGV("Asynchronous input event injection succeeded.");
-                break;
-            case INPUT_EVENT_INJECTION_FAILED:
-                ALOGW("Asynchronous input event injection failed.");
-                break;
-            case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
-                ALOGW("Asynchronous input event injection permission denied.");
-                break;
-            case INPUT_EVENT_INJECTION_TIMED_OUT:
-                ALOGW("Asynchronous input event injection timed out.");
-                break;
-            }
-        }
-
-        injectionState->injectionResult = injectionResult;
-        mInjectionResultAvailableCondition.broadcast();
-    }
-}
-
-void InputDispatcher::incrementPendingForegroundDispatchesLocked(EventEntry* entry) {
-    InjectionState* injectionState = entry->injectionState;
-    if (injectionState) {
-        injectionState->pendingForegroundDispatches += 1;
-    }
-}
-
-void InputDispatcher::decrementPendingForegroundDispatchesLocked(EventEntry* entry) {
-    InjectionState* injectionState = entry->injectionState;
-    if (injectionState) {
-        injectionState->pendingForegroundDispatches -= 1;
-
-        if (injectionState->pendingForegroundDispatches == 0) {
-            mInjectionSyncFinishedCondition.broadcast();
-        }
-    }
-}
-
-sp<InputWindowHandle> InputDispatcher::getWindowHandleLocked(
-        const sp<InputChannel>& inputChannel) const {
-    size_t numWindows = mWindowHandles.size();
-    for (size_t i = 0; i < numWindows; i++) {
-        const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i);
-        if (windowHandle->getInputChannel() == inputChannel) {
-            return windowHandle;
-        }
-    }
-    return NULL;
-}
-
-bool InputDispatcher::hasWindowHandleLocked(
-        const sp<InputWindowHandle>& windowHandle) const {
-    size_t numWindows = mWindowHandles.size();
-    for (size_t i = 0; i < numWindows; i++) {
-        if (mWindowHandles.itemAt(i) == windowHandle) {
-            return true;
-        }
-    }
-    return false;
-}
-
-void InputDispatcher::setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles) {
-#if DEBUG_FOCUS
-    ALOGD("setInputWindows");
-#endif
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        Vector<sp<InputWindowHandle> > oldWindowHandles = mWindowHandles;
-        mWindowHandles = inputWindowHandles;
-
-        sp<InputWindowHandle> newFocusedWindowHandle;
-        bool foundHoveredWindow = false;
-        for (size_t i = 0; i < mWindowHandles.size(); i++) {
-            const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i);
-            if (!windowHandle->updateInfo() || windowHandle->getInputChannel() == NULL) {
-                mWindowHandles.removeAt(i--);
-                continue;
-            }
-            if (windowHandle->getInfo()->hasFocus) {
-                newFocusedWindowHandle = windowHandle;
-            }
-            if (windowHandle == mLastHoverWindowHandle) {
-                foundHoveredWindow = true;
-            }
-        }
-
-        if (!foundHoveredWindow) {
-            mLastHoverWindowHandle = NULL;
-        }
-
-        if (mFocusedWindowHandle != newFocusedWindowHandle) {
-            if (mFocusedWindowHandle != NULL) {
-#if DEBUG_FOCUS
-                ALOGD("Focus left window: %s",
-                        mFocusedWindowHandle->getName().string());
-#endif
-                sp<InputChannel> focusedInputChannel = mFocusedWindowHandle->getInputChannel();
-                if (focusedInputChannel != NULL) {
-                    CancelationOptions options(CancelationOptions::CANCEL_NON_POINTER_EVENTS,
-                            "focus left window");
-                    synthesizeCancelationEventsForInputChannelLocked(
-                            focusedInputChannel, options);
-                }
-            }
-            if (newFocusedWindowHandle != NULL) {
-#if DEBUG_FOCUS
-                ALOGD("Focus entered window: %s",
-                        newFocusedWindowHandle->getName().string());
-#endif
-            }
-            mFocusedWindowHandle = newFocusedWindowHandle;
-        }
-
-        for (size_t i = 0; i < mTouchState.windows.size(); i++) {
-            TouchedWindow& touchedWindow = mTouchState.windows.editItemAt(i);
-            if (!hasWindowHandleLocked(touchedWindow.windowHandle)) {
-#if DEBUG_FOCUS
-                ALOGD("Touched window was removed: %s",
-                        touchedWindow.windowHandle->getName().string());
-#endif
-                sp<InputChannel> touchedInputChannel =
-                        touchedWindow.windowHandle->getInputChannel();
-                if (touchedInputChannel != NULL) {
-                    CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
-                            "touched window was removed");
-                    synthesizeCancelationEventsForInputChannelLocked(
-                            touchedInputChannel, options);
-                }
-                mTouchState.windows.removeAt(i--);
-            }
-        }
-
-        // Release information for windows that are no longer present.
-        // This ensures that unused input channels are released promptly.
-        // Otherwise, they might stick around until the window handle is destroyed
-        // which might not happen until the next GC.
-        for (size_t i = 0; i < oldWindowHandles.size(); i++) {
-            const sp<InputWindowHandle>& oldWindowHandle = oldWindowHandles.itemAt(i);
-            if (!hasWindowHandleLocked(oldWindowHandle)) {
-#if DEBUG_FOCUS
-                ALOGD("Window went away: %s", oldWindowHandle->getName().string());
-#endif
-                oldWindowHandle->releaseInfo();
-            }
-        }
-    } // release lock
-
-    // Wake up poll loop since it may need to make new input dispatching choices.
-    mLooper->wake();
-}
-
-void InputDispatcher::setFocusedApplication(
-        const sp<InputApplicationHandle>& inputApplicationHandle) {
-#if DEBUG_FOCUS
-    ALOGD("setFocusedApplication");
-#endif
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (inputApplicationHandle != NULL && inputApplicationHandle->updateInfo()) {
-            if (mFocusedApplicationHandle != inputApplicationHandle) {
-                if (mFocusedApplicationHandle != NULL) {
-                    resetANRTimeoutsLocked();
-                    mFocusedApplicationHandle->releaseInfo();
-                }
-                mFocusedApplicationHandle = inputApplicationHandle;
-            }
-        } else if (mFocusedApplicationHandle != NULL) {
-            resetANRTimeoutsLocked();
-            mFocusedApplicationHandle->releaseInfo();
-            mFocusedApplicationHandle.clear();
-        }
-
-#if DEBUG_FOCUS
-        //logDispatchStateLocked();
-#endif
-    } // release lock
-
-    // Wake up poll loop since it may need to make new input dispatching choices.
-    mLooper->wake();
-}
-
-void InputDispatcher::setInputDispatchMode(bool enabled, bool frozen) {
-#if DEBUG_FOCUS
-    ALOGD("setInputDispatchMode: enabled=%d, frozen=%d", enabled, frozen);
-#endif
-
-    bool changed;
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (mDispatchEnabled != enabled || mDispatchFrozen != frozen) {
-            if (mDispatchFrozen && !frozen) {
-                resetANRTimeoutsLocked();
-            }
-
-            if (mDispatchEnabled && !enabled) {
-                resetAndDropEverythingLocked("dispatcher is being disabled");
-            }
-
-            mDispatchEnabled = enabled;
-            mDispatchFrozen = frozen;
-            changed = true;
-        } else {
-            changed = false;
-        }
-
-#if DEBUG_FOCUS
-        //logDispatchStateLocked();
-#endif
-    } // release lock
-
-    if (changed) {
-        // Wake up poll loop since it may need to make new input dispatching choices.
-        mLooper->wake();
-    }
-}
-
-void InputDispatcher::setInputFilterEnabled(bool enabled) {
-#if DEBUG_FOCUS
-    ALOGD("setInputFilterEnabled: enabled=%d", enabled);
-#endif
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (mInputFilterEnabled == enabled) {
-            return;
-        }
-
-        mInputFilterEnabled = enabled;
-        resetAndDropEverythingLocked("input filter is being enabled or disabled");
-    } // release lock
-
-    // Wake up poll loop since there might be work to do to drop everything.
-    mLooper->wake();
-}
-
-bool InputDispatcher::transferTouchFocus(const sp<InputChannel>& fromChannel,
-        const sp<InputChannel>& toChannel) {
-#if DEBUG_FOCUS
-    ALOGD("transferTouchFocus: fromChannel=%s, toChannel=%s",
-            fromChannel->getName().string(), toChannel->getName().string());
-#endif
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        sp<InputWindowHandle> fromWindowHandle = getWindowHandleLocked(fromChannel);
-        sp<InputWindowHandle> toWindowHandle = getWindowHandleLocked(toChannel);
-        if (fromWindowHandle == NULL || toWindowHandle == NULL) {
-#if DEBUG_FOCUS
-            ALOGD("Cannot transfer focus because from or to window not found.");
-#endif
-            return false;
-        }
-        if (fromWindowHandle == toWindowHandle) {
-#if DEBUG_FOCUS
-            ALOGD("Trivial transfer to same window.");
-#endif
-            return true;
-        }
-        if (fromWindowHandle->getInfo()->displayId != toWindowHandle->getInfo()->displayId) {
-#if DEBUG_FOCUS
-            ALOGD("Cannot transfer focus because windows are on different displays.");
-#endif
-            return false;
-        }
-
-        bool found = false;
-        for (size_t i = 0; i < mTouchState.windows.size(); i++) {
-            const TouchedWindow& touchedWindow = mTouchState.windows[i];
-            if (touchedWindow.windowHandle == fromWindowHandle) {
-                int32_t oldTargetFlags = touchedWindow.targetFlags;
-                BitSet32 pointerIds = touchedWindow.pointerIds;
-
-                mTouchState.windows.removeAt(i);
-
-                int32_t newTargetFlags = oldTargetFlags
-                        & (InputTarget::FLAG_FOREGROUND
-                                | InputTarget::FLAG_SPLIT | InputTarget::FLAG_DISPATCH_AS_IS);
-                mTouchState.addOrUpdateWindow(toWindowHandle, newTargetFlags, pointerIds);
-
-                found = true;
-                break;
-            }
-        }
-
-        if (! found) {
-#if DEBUG_FOCUS
-            ALOGD("Focus transfer failed because from window did not have focus.");
-#endif
-            return false;
-        }
-
-        ssize_t fromConnectionIndex = getConnectionIndexLocked(fromChannel);
-        ssize_t toConnectionIndex = getConnectionIndexLocked(toChannel);
-        if (fromConnectionIndex >= 0 && toConnectionIndex >= 0) {
-            sp<Connection> fromConnection = mConnectionsByFd.valueAt(fromConnectionIndex);
-            sp<Connection> toConnection = mConnectionsByFd.valueAt(toConnectionIndex);
-
-            fromConnection->inputState.copyPointerStateTo(toConnection->inputState);
-            CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
-                    "transferring touch focus from this window to another window");
-            synthesizeCancelationEventsForConnectionLocked(fromConnection, options);
-        }
-
-#if DEBUG_FOCUS
-        logDispatchStateLocked();
-#endif
-    } // release lock
-
-    // Wake up poll loop since it may need to make new input dispatching choices.
-    mLooper->wake();
-    return true;
-}
-
-void InputDispatcher::resetAndDropEverythingLocked(const char* reason) {
-#if DEBUG_FOCUS
-    ALOGD("Resetting and dropping all events (%s).", reason);
-#endif
-
-    CancelationOptions options(CancelationOptions::CANCEL_ALL_EVENTS, reason);
-    synthesizeCancelationEventsForAllConnectionsLocked(options);
-
-    resetKeyRepeatLocked();
-    releasePendingEventLocked();
-    drainInboundQueueLocked();
-    resetANRTimeoutsLocked();
-
-    mTouchState.reset();
-    mLastHoverWindowHandle.clear();
-}
-
-void InputDispatcher::logDispatchStateLocked() {
-    String8 dump;
-    dumpDispatchStateLocked(dump);
-
-    char* text = dump.lockBuffer(dump.size());
-    char* start = text;
-    while (*start != '\0') {
-        char* end = strchr(start, '\n');
-        if (*end == '\n') {
-            *(end++) = '\0';
-        }
-        ALOGD("%s", start);
-        start = end;
-    }
-}
-
-void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
-    dump.appendFormat(INDENT "DispatchEnabled: %d\n", mDispatchEnabled);
-    dump.appendFormat(INDENT "DispatchFrozen: %d\n", mDispatchFrozen);
-
-    if (mFocusedApplicationHandle != NULL) {
-        dump.appendFormat(INDENT "FocusedApplication: name='%s', dispatchingTimeout=%0.3fms\n",
-                mFocusedApplicationHandle->getName().string(),
-                mFocusedApplicationHandle->getDispatchingTimeout(
-                        DEFAULT_INPUT_DISPATCHING_TIMEOUT) / 1000000.0);
-    } else {
-        dump.append(INDENT "FocusedApplication: <null>\n");
-    }
-    dump.appendFormat(INDENT "FocusedWindow: name='%s'\n",
-            mFocusedWindowHandle != NULL ? mFocusedWindowHandle->getName().string() : "<null>");
-
-    dump.appendFormat(INDENT "TouchDown: %s\n", toString(mTouchState.down));
-    dump.appendFormat(INDENT "TouchSplit: %s\n", toString(mTouchState.split));
-    dump.appendFormat(INDENT "TouchDeviceId: %d\n", mTouchState.deviceId);
-    dump.appendFormat(INDENT "TouchSource: 0x%08x\n", mTouchState.source);
-    dump.appendFormat(INDENT "TouchDisplayId: %d\n", mTouchState.displayId);
-    if (!mTouchState.windows.isEmpty()) {
-        dump.append(INDENT "TouchedWindows:\n");
-        for (size_t i = 0; i < mTouchState.windows.size(); i++) {
-            const TouchedWindow& touchedWindow = mTouchState.windows[i];
-            dump.appendFormat(INDENT2 "%d: name='%s', pointerIds=0x%0x, targetFlags=0x%x\n",
-                    i, touchedWindow.windowHandle->getName().string(),
-                    touchedWindow.pointerIds.value,
-                    touchedWindow.targetFlags);
-        }
-    } else {
-        dump.append(INDENT "TouchedWindows: <none>\n");
-    }
-
-    if (!mWindowHandles.isEmpty()) {
-        dump.append(INDENT "Windows:\n");
-        for (size_t i = 0; i < mWindowHandles.size(); i++) {
-            const sp<InputWindowHandle>& windowHandle = mWindowHandles.itemAt(i);
-            const InputWindowInfo* windowInfo = windowHandle->getInfo();
-
-            dump.appendFormat(INDENT2 "%d: name='%s', displayId=%d, "
-                    "paused=%s, hasFocus=%s, hasWallpaper=%s, "
-                    "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, "
-                    "frame=[%d,%d][%d,%d], scale=%f, "
-                    "touchableRegion=",
-                    i, windowInfo->name.string(), windowInfo->displayId,
-                    toString(windowInfo->paused),
-                    toString(windowInfo->hasFocus),
-                    toString(windowInfo->hasWallpaper),
-                    toString(windowInfo->visible),
-                    toString(windowInfo->canReceiveKeys),
-                    windowInfo->layoutParamsFlags, windowInfo->layoutParamsType,
-                    windowInfo->layer,
-                    windowInfo->frameLeft, windowInfo->frameTop,
-                    windowInfo->frameRight, windowInfo->frameBottom,
-                    windowInfo->scaleFactor);
-            dumpRegion(dump, windowInfo->touchableRegion);
-            dump.appendFormat(", inputFeatures=0x%08x", windowInfo->inputFeatures);
-            dump.appendFormat(", ownerPid=%d, ownerUid=%d, dispatchingTimeout=%0.3fms\n",
-                    windowInfo->ownerPid, windowInfo->ownerUid,
-                    windowInfo->dispatchingTimeout / 1000000.0);
-        }
-    } else {
-        dump.append(INDENT "Windows: <none>\n");
-    }
-
-    if (!mMonitoringChannels.isEmpty()) {
-        dump.append(INDENT "MonitoringChannels:\n");
-        for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
-            const sp<InputChannel>& channel = mMonitoringChannels[i];
-            dump.appendFormat(INDENT2 "%d: '%s'\n", i, channel->getName().string());
-        }
-    } else {
-        dump.append(INDENT "MonitoringChannels: <none>\n");
-    }
-
-    nsecs_t currentTime = now();
-
-    // Dump recently dispatched or dropped events from oldest to newest.
-    if (!mRecentQueue.isEmpty()) {
-        dump.appendFormat(INDENT "RecentQueue: length=%u\n", mRecentQueue.count());
-        for (EventEntry* entry = mRecentQueue.head; entry; entry = entry->next) {
-            dump.append(INDENT2);
-            entry->appendDescription(dump);
-            dump.appendFormat(", age=%0.1fms\n",
-                    (currentTime - entry->eventTime) * 0.000001f);
-        }
-    } else {
-        dump.append(INDENT "RecentQueue: <empty>\n");
-    }
-
-    // Dump event currently being dispatched.
-    if (mPendingEvent) {
-        dump.append(INDENT "PendingEvent:\n");
-        dump.append(INDENT2);
-        mPendingEvent->appendDescription(dump);
-        dump.appendFormat(", age=%0.1fms\n",
-                (currentTime - mPendingEvent->eventTime) * 0.000001f);
-    } else {
-        dump.append(INDENT "PendingEvent: <none>\n");
-    }
-
-    // Dump inbound events from oldest to newest.
-    if (!mInboundQueue.isEmpty()) {
-        dump.appendFormat(INDENT "InboundQueue: length=%u\n", mInboundQueue.count());
-        for (EventEntry* entry = mInboundQueue.head; entry; entry = entry->next) {
-            dump.append(INDENT2);
-            entry->appendDescription(dump);
-            dump.appendFormat(", age=%0.1fms\n",
-                    (currentTime - entry->eventTime) * 0.000001f);
-        }
-    } else {
-        dump.append(INDENT "InboundQueue: <empty>\n");
-    }
-
-    if (!mConnectionsByFd.isEmpty()) {
-        dump.append(INDENT "Connections:\n");
-        for (size_t i = 0; i < mConnectionsByFd.size(); i++) {
-            const sp<Connection>& connection = mConnectionsByFd.valueAt(i);
-            dump.appendFormat(INDENT2 "%d: channelName='%s', windowName='%s', "
-                    "status=%s, monitor=%s, inputPublisherBlocked=%s\n",
-                    i, connection->getInputChannelName(), connection->getWindowName(),
-                    connection->getStatusLabel(), toString(connection->monitor),
-                    toString(connection->inputPublisherBlocked));
-
-            if (!connection->outboundQueue.isEmpty()) {
-                dump.appendFormat(INDENT3 "OutboundQueue: length=%u\n",
-                        connection->outboundQueue.count());
-                for (DispatchEntry* entry = connection->outboundQueue.head; entry;
-                        entry = entry->next) {
-                    dump.append(INDENT4);
-                    entry->eventEntry->appendDescription(dump);
-                    dump.appendFormat(", targetFlags=0x%08x, resolvedAction=%d, age=%0.1fms\n",
-                            entry->targetFlags, entry->resolvedAction,
-                            (currentTime - entry->eventEntry->eventTime) * 0.000001f);
-                }
-            } else {
-                dump.append(INDENT3 "OutboundQueue: <empty>\n");
-            }
-
-            if (!connection->waitQueue.isEmpty()) {
-                dump.appendFormat(INDENT3 "WaitQueue: length=%u\n",
-                        connection->waitQueue.count());
-                for (DispatchEntry* entry = connection->waitQueue.head; entry;
-                        entry = entry->next) {
-                    dump.append(INDENT4);
-                    entry->eventEntry->appendDescription(dump);
-                    dump.appendFormat(", targetFlags=0x%08x, resolvedAction=%d, "
-                            "age=%0.1fms, wait=%0.1fms\n",
-                            entry->targetFlags, entry->resolvedAction,
-                            (currentTime - entry->eventEntry->eventTime) * 0.000001f,
-                            (currentTime - entry->deliveryTime) * 0.000001f);
-                }
-            } else {
-                dump.append(INDENT3 "WaitQueue: <empty>\n");
-            }
-        }
-    } else {
-        dump.append(INDENT "Connections: <none>\n");
-    }
-
-    if (isAppSwitchPendingLocked()) {
-        dump.appendFormat(INDENT "AppSwitch: pending, due in %0.1fms\n",
-                (mAppSwitchDueTime - now()) / 1000000.0);
-    } else {
-        dump.append(INDENT "AppSwitch: not pending\n");
-    }
-
-    dump.append(INDENT "Configuration:\n");
-    dump.appendFormat(INDENT2 "KeyRepeatDelay: %0.1fms\n",
-            mConfig.keyRepeatDelay * 0.000001f);
-    dump.appendFormat(INDENT2 "KeyRepeatTimeout: %0.1fms\n",
-            mConfig.keyRepeatTimeout * 0.000001f);
-}
-
-status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChannel,
-        const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
-#if DEBUG_REGISTRATION
-    ALOGD("channel '%s' ~ registerInputChannel - monitor=%s", inputChannel->getName().string(),
-            toString(monitor));
-#endif
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (getConnectionIndexLocked(inputChannel) >= 0) {
-            ALOGW("Attempted to register already registered input channel '%s'",
-                    inputChannel->getName().string());
-            return BAD_VALUE;
-        }
-
-        sp<Connection> connection = new Connection(inputChannel, inputWindowHandle, monitor);
-
-        int fd = inputChannel->getFd();
-        mConnectionsByFd.add(fd, connection);
-
-        if (monitor) {
-            mMonitoringChannels.push(inputChannel);
-        }
-
-        mLooper->addFd(fd, 0, ALOOPER_EVENT_INPUT, handleReceiveCallback, this);
-    } // release lock
-
-    // Wake the looper because some connections have changed.
-    mLooper->wake();
-    return OK;
-}
-
-status_t InputDispatcher::unregisterInputChannel(const sp<InputChannel>& inputChannel) {
-#if DEBUG_REGISTRATION
-    ALOGD("channel '%s' ~ unregisterInputChannel", inputChannel->getName().string());
-#endif
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        status_t status = unregisterInputChannelLocked(inputChannel, false /*notify*/);
-        if (status) {
-            return status;
-        }
-    } // release lock
-
-    // Wake the poll loop because removing the connection may have changed the current
-    // synchronization state.
-    mLooper->wake();
-    return OK;
-}
-
-status_t InputDispatcher::unregisterInputChannelLocked(const sp<InputChannel>& inputChannel,
-        bool notify) {
-    ssize_t connectionIndex = getConnectionIndexLocked(inputChannel);
-    if (connectionIndex < 0) {
-        ALOGW("Attempted to unregister already unregistered input channel '%s'",
-                inputChannel->getName().string());
-        return BAD_VALUE;
-    }
-
-    sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
-    mConnectionsByFd.removeItemsAt(connectionIndex);
-
-    if (connection->monitor) {
-        removeMonitorChannelLocked(inputChannel);
-    }
-
-    mLooper->removeFd(inputChannel->getFd());
-
-    nsecs_t currentTime = now();
-    abortBrokenDispatchCycleLocked(currentTime, connection, notify);
-
-    connection->status = Connection::STATUS_ZOMBIE;
-    return OK;
-}
-
-void InputDispatcher::removeMonitorChannelLocked(const sp<InputChannel>& inputChannel) {
-    for (size_t i = 0; i < mMonitoringChannels.size(); i++) {
-         if (mMonitoringChannels[i] == inputChannel) {
-             mMonitoringChannels.removeAt(i);
-             break;
-         }
-    }
-}
-
-ssize_t InputDispatcher::getConnectionIndexLocked(const sp<InputChannel>& inputChannel) {
-    ssize_t connectionIndex = mConnectionsByFd.indexOfKey(inputChannel->getFd());
-    if (connectionIndex >= 0) {
-        sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
-        if (connection->inputChannel.get() == inputChannel.get()) {
-            return connectionIndex;
-        }
-    }
-
-    return -1;
-}
-
-void InputDispatcher::onDispatchCycleFinishedLocked(
-        nsecs_t currentTime, const sp<Connection>& connection, uint32_t seq, bool handled) {
-    CommandEntry* commandEntry = postCommandLocked(
-            & InputDispatcher::doDispatchCycleFinishedLockedInterruptible);
-    commandEntry->connection = connection;
-    commandEntry->eventTime = currentTime;
-    commandEntry->seq = seq;
-    commandEntry->handled = handled;
-}
-
-void InputDispatcher::onDispatchCycleBrokenLocked(
-        nsecs_t currentTime, const sp<Connection>& connection) {
-    ALOGE("channel '%s' ~ Channel is unrecoverably broken and will be disposed!",
-            connection->getInputChannelName());
-
-    CommandEntry* commandEntry = postCommandLocked(
-            & InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible);
-    commandEntry->connection = connection;
-}
-
-void InputDispatcher::onANRLocked(
-        nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle,
-        const sp<InputWindowHandle>& windowHandle,
-        nsecs_t eventTime, nsecs_t waitStartTime, const char* reason) {
-    float dispatchLatency = (currentTime - eventTime) * 0.000001f;
-    float waitDuration = (currentTime - waitStartTime) * 0.000001f;
-    ALOGI("Application is not responding: %s.  "
-            "It has been %0.1fms since event, %0.1fms since wait started.  Reason: %s",
-            getApplicationWindowLabelLocked(applicationHandle, windowHandle).string(),
-            dispatchLatency, waitDuration, reason);
-
-    // Capture a record of the InputDispatcher state at the time of the ANR.
-    time_t t = time(NULL);
-    struct tm tm;
-    localtime_r(&t, &tm);
-    char timestr[64];
-    strftime(timestr, sizeof(timestr), "%F %T", &tm);
-    mLastANRState.clear();
-    mLastANRState.append(INDENT "ANR:\n");
-    mLastANRState.appendFormat(INDENT2 "Time: %s\n", timestr);
-    mLastANRState.appendFormat(INDENT2 "Window: %s\n",
-            getApplicationWindowLabelLocked(applicationHandle, windowHandle).string());
-    mLastANRState.appendFormat(INDENT2 "DispatchLatency: %0.1fms\n", dispatchLatency);
-    mLastANRState.appendFormat(INDENT2 "WaitDuration: %0.1fms\n", waitDuration);
-    mLastANRState.appendFormat(INDENT2 "Reason: %s\n", reason);
-    dumpDispatchStateLocked(mLastANRState);
-
-    CommandEntry* commandEntry = postCommandLocked(
-            & InputDispatcher::doNotifyANRLockedInterruptible);
-    commandEntry->inputApplicationHandle = applicationHandle;
-    commandEntry->inputWindowHandle = windowHandle;
-    commandEntry->reason = reason;
-}
-
-void InputDispatcher::doNotifyConfigurationChangedInterruptible(
-        CommandEntry* commandEntry) {
-    mLock.unlock();
-
-    mPolicy->notifyConfigurationChanged(commandEntry->eventTime);
-
-    mLock.lock();
-}
-
-void InputDispatcher::doNotifyInputChannelBrokenLockedInterruptible(
-        CommandEntry* commandEntry) {
-    sp<Connection> connection = commandEntry->connection;
-
-    if (connection->status != Connection::STATUS_ZOMBIE) {
-        mLock.unlock();
-
-        mPolicy->notifyInputChannelBroken(connection->inputWindowHandle);
-
-        mLock.lock();
-    }
-}
-
-void InputDispatcher::doNotifyANRLockedInterruptible(
-        CommandEntry* commandEntry) {
-    mLock.unlock();
-
-    nsecs_t newTimeout = mPolicy->notifyANR(
-            commandEntry->inputApplicationHandle, commandEntry->inputWindowHandle,
-            commandEntry->reason);
-
-    mLock.lock();
-
-    resumeAfterTargetsNotReadyTimeoutLocked(newTimeout,
-            commandEntry->inputWindowHandle != NULL
-                    ? commandEntry->inputWindowHandle->getInputChannel() : NULL);
-}
-
-void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible(
-        CommandEntry* commandEntry) {
-    KeyEntry* entry = commandEntry->keyEntry;
-
-    KeyEvent event;
-    initializeKeyEvent(&event, entry);
-
-    mLock.unlock();
-
-    nsecs_t delay = mPolicy->interceptKeyBeforeDispatching(commandEntry->inputWindowHandle,
-            &event, entry->policyFlags);
-
-    mLock.lock();
-
-    if (delay < 0) {
-        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_SKIP;
-    } else if (!delay) {
-        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_CONTINUE;
-    } else {
-        entry->interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER;
-        entry->interceptKeyWakeupTime = now() + delay;
-    }
-    entry->release();
-}
-
-void InputDispatcher::doDispatchCycleFinishedLockedInterruptible(
-        CommandEntry* commandEntry) {
-    sp<Connection> connection = commandEntry->connection;
-    nsecs_t finishTime = commandEntry->eventTime;
-    uint32_t seq = commandEntry->seq;
-    bool handled = commandEntry->handled;
-
-    // Handle post-event policy actions.
-    DispatchEntry* dispatchEntry = connection->findWaitQueueEntry(seq);
-    if (dispatchEntry) {
-        nsecs_t eventDuration = finishTime - dispatchEntry->deliveryTime;
-        if (eventDuration > SLOW_EVENT_PROCESSING_WARNING_TIMEOUT) {
-            String8 msg;
-            msg.appendFormat("Window '%s' spent %0.1fms processing the last input event: ",
-                    connection->getWindowName(), eventDuration * 0.000001f);
-            dispatchEntry->eventEntry->appendDescription(msg);
-            ALOGI("%s", msg.string());
-        }
-
-        bool restartEvent;
-        if (dispatchEntry->eventEntry->type == EventEntry::TYPE_KEY) {
-            KeyEntry* keyEntry = static_cast<KeyEntry*>(dispatchEntry->eventEntry);
-            restartEvent = afterKeyEventLockedInterruptible(connection,
-                    dispatchEntry, keyEntry, handled);
-        } else if (dispatchEntry->eventEntry->type == EventEntry::TYPE_MOTION) {
-            MotionEntry* motionEntry = static_cast<MotionEntry*>(dispatchEntry->eventEntry);
-            restartEvent = afterMotionEventLockedInterruptible(connection,
-                    dispatchEntry, motionEntry, handled);
-        } else {
-            restartEvent = false;
-        }
-
-        // Dequeue the event and start the next cycle.
-        // Note that because the lock might have been released, it is possible that the
-        // contents of the wait queue to have been drained, so we need to double-check
-        // a few things.
-        if (dispatchEntry == connection->findWaitQueueEntry(seq)) {
-            connection->waitQueue.dequeue(dispatchEntry);
-            traceWaitQueueLengthLocked(connection);
-            if (restartEvent && connection->status == Connection::STATUS_NORMAL) {
-                connection->outboundQueue.enqueueAtHead(dispatchEntry);
-                traceOutboundQueueLengthLocked(connection);
-            } else {
-                releaseDispatchEntryLocked(dispatchEntry);
-            }
-        }
-
-        // Start the next dispatch cycle for this connection.
-        startDispatchCycleLocked(now(), connection);
-    }
-}
-
-bool InputDispatcher::afterKeyEventLockedInterruptible(const sp<Connection>& connection,
-        DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled) {
-    if (!(keyEntry->flags & AKEY_EVENT_FLAG_FALLBACK)) {
-        // Get the fallback key state.
-        // Clear it out after dispatching the UP.
-        int32_t originalKeyCode = keyEntry->keyCode;
-        int32_t fallbackKeyCode = connection->inputState.getFallbackKey(originalKeyCode);
-        if (keyEntry->action == AKEY_EVENT_ACTION_UP) {
-            connection->inputState.removeFallbackKey(originalKeyCode);
-        }
-
-        if (handled || !dispatchEntry->hasForegroundTarget()) {
-            // If the application handles the original key for which we previously
-            // generated a fallback or if the window is not a foreground window,
-            // then cancel the associated fallback key, if any.
-            if (fallbackKeyCode != -1) {
-                // Dispatch the unhandled key to the policy with the cancel flag.
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-                ALOGD("Unhandled key event: Asking policy to cancel fallback action.  "
-                        "keyCode=%d, action=%d, repeatCount=%d, policyFlags=0x%08x",
-                        keyEntry->keyCode, keyEntry->action, keyEntry->repeatCount,
-                        keyEntry->policyFlags);
-#endif
-                KeyEvent event;
-                initializeKeyEvent(&event, keyEntry);
-                event.setFlags(event.getFlags() | AKEY_EVENT_FLAG_CANCELED);
-
-                mLock.unlock();
-
-                mPolicy->dispatchUnhandledKey(connection->inputWindowHandle,
-                        &event, keyEntry->policyFlags, &event);
-
-                mLock.lock();
-
-                // Cancel the fallback key.
-                if (fallbackKeyCode != AKEYCODE_UNKNOWN) {
-                    CancelationOptions options(CancelationOptions::CANCEL_FALLBACK_EVENTS,
-                            "application handled the original non-fallback key "
-                            "or is no longer a foreground target, "
-                            "canceling previously dispatched fallback key");
-                    options.keyCode = fallbackKeyCode;
-                    synthesizeCancelationEventsForConnectionLocked(connection, options);
-                }
-                connection->inputState.removeFallbackKey(originalKeyCode);
-            }
-        } else {
-            // If the application did not handle a non-fallback key, first check
-            // that we are in a good state to perform unhandled key event processing
-            // Then ask the policy what to do with it.
-            bool initialDown = keyEntry->action == AKEY_EVENT_ACTION_DOWN
-                    && keyEntry->repeatCount == 0;
-            if (fallbackKeyCode == -1 && !initialDown) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-                ALOGD("Unhandled key event: Skipping unhandled key event processing "
-                        "since this is not an initial down.  "
-                        "keyCode=%d, action=%d, repeatCount=%d, policyFlags=0x%08x",
-                        originalKeyCode, keyEntry->action, keyEntry->repeatCount,
-                        keyEntry->policyFlags);
-#endif
-                return false;
-            }
-
-            // Dispatch the unhandled key to the policy.
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-            ALOGD("Unhandled key event: Asking policy to perform fallback action.  "
-                    "keyCode=%d, action=%d, repeatCount=%d, policyFlags=0x%08x",
-                    keyEntry->keyCode, keyEntry->action, keyEntry->repeatCount,
-                    keyEntry->policyFlags);
-#endif
-            KeyEvent event;
-            initializeKeyEvent(&event, keyEntry);
-
-            mLock.unlock();
-
-            bool fallback = mPolicy->dispatchUnhandledKey(connection->inputWindowHandle,
-                    &event, keyEntry->policyFlags, &event);
-
-            mLock.lock();
-
-            if (connection->status != Connection::STATUS_NORMAL) {
-                connection->inputState.removeFallbackKey(originalKeyCode);
-                return false;
-            }
-
-            // Latch the fallback keycode for this key on an initial down.
-            // The fallback keycode cannot change at any other point in the lifecycle.
-            if (initialDown) {
-                if (fallback) {
-                    fallbackKeyCode = event.getKeyCode();
-                } else {
-                    fallbackKeyCode = AKEYCODE_UNKNOWN;
-                }
-                connection->inputState.setFallbackKey(originalKeyCode, fallbackKeyCode);
-            }
-
-            ALOG_ASSERT(fallbackKeyCode != -1);
-
-            // Cancel the fallback key if the policy decides not to send it anymore.
-            // We will continue to dispatch the key to the policy but we will no
-            // longer dispatch a fallback key to the application.
-            if (fallbackKeyCode != AKEYCODE_UNKNOWN
-                    && (!fallback || fallbackKeyCode != event.getKeyCode())) {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-                if (fallback) {
-                    ALOGD("Unhandled key event: Policy requested to send key %d"
-                            "as a fallback for %d, but on the DOWN it had requested "
-                            "to send %d instead.  Fallback canceled.",
-                            event.getKeyCode(), originalKeyCode, fallbackKeyCode);
-                } else {
-                    ALOGD("Unhandled key event: Policy did not request fallback for %d, "
-                            "but on the DOWN it had requested to send %d.  "
-                            "Fallback canceled.",
-                            originalKeyCode, fallbackKeyCode);
-                }
-#endif
-
-                CancelationOptions options(CancelationOptions::CANCEL_FALLBACK_EVENTS,
-                        "canceling fallback, policy no longer desires it");
-                options.keyCode = fallbackKeyCode;
-                synthesizeCancelationEventsForConnectionLocked(connection, options);
-
-                fallback = false;
-                fallbackKeyCode = AKEYCODE_UNKNOWN;
-                if (keyEntry->action != AKEY_EVENT_ACTION_UP) {
-                    connection->inputState.setFallbackKey(originalKeyCode,
-                            fallbackKeyCode);
-                }
-            }
-
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-            {
-                String8 msg;
-                const KeyedVector<int32_t, int32_t>& fallbackKeys =
-                        connection->inputState.getFallbackKeys();
-                for (size_t i = 0; i < fallbackKeys.size(); i++) {
-                    msg.appendFormat(", %d->%d", fallbackKeys.keyAt(i),
-                            fallbackKeys.valueAt(i));
-                }
-                ALOGD("Unhandled key event: %d currently tracked fallback keys%s.",
-                        fallbackKeys.size(), msg.string());
-            }
-#endif
-
-            if (fallback) {
-                // Restart the dispatch cycle using the fallback key.
-                keyEntry->eventTime = event.getEventTime();
-                keyEntry->deviceId = event.getDeviceId();
-                keyEntry->source = event.getSource();
-                keyEntry->flags = event.getFlags() | AKEY_EVENT_FLAG_FALLBACK;
-                keyEntry->keyCode = fallbackKeyCode;
-                keyEntry->scanCode = event.getScanCode();
-                keyEntry->metaState = event.getMetaState();
-                keyEntry->repeatCount = event.getRepeatCount();
-                keyEntry->downTime = event.getDownTime();
-                keyEntry->syntheticRepeat = false;
-
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-                ALOGD("Unhandled key event: Dispatching fallback key.  "
-                        "originalKeyCode=%d, fallbackKeyCode=%d, fallbackMetaState=%08x",
-                        originalKeyCode, fallbackKeyCode, keyEntry->metaState);
-#endif
-                return true; // restart the event
-            } else {
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-                ALOGD("Unhandled key event: No fallback key.");
-#endif
-            }
-        }
-    }
-    return false;
-}
-
-bool InputDispatcher::afterMotionEventLockedInterruptible(const sp<Connection>& connection,
-        DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled) {
-    return false;
-}
-
-void InputDispatcher::doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) {
-    mLock.unlock();
-
-    mPolicy->pokeUserActivity(commandEntry->eventTime, commandEntry->userActivityEventType);
-
-    mLock.lock();
-}
-
-void InputDispatcher::initializeKeyEvent(KeyEvent* event, const KeyEntry* entry) {
-    event->initialize(entry->deviceId, entry->source, entry->action, entry->flags,
-            entry->keyCode, entry->scanCode, entry->metaState, entry->repeatCount,
-            entry->downTime, entry->eventTime);
-}
-
-void InputDispatcher::updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry,
-        int32_t injectionResult, nsecs_t timeSpentWaitingForApplication) {
-    // TODO Write some statistics about how long we spend waiting.
-}
-
-void InputDispatcher::traceInboundQueueLengthLocked() {
-    if (ATRACE_ENABLED()) {
-        ATRACE_INT("iq", mInboundQueue.count());
-    }
-}
-
-void InputDispatcher::traceOutboundQueueLengthLocked(const sp<Connection>& connection) {
-    if (ATRACE_ENABLED()) {
-        char counterName[40];
-        snprintf(counterName, sizeof(counterName), "oq:%s", connection->getWindowName());
-        ATRACE_INT(counterName, connection->outboundQueue.count());
-    }
-}
-
-void InputDispatcher::traceWaitQueueLengthLocked(const sp<Connection>& connection) {
-    if (ATRACE_ENABLED()) {
-        char counterName[40];
-        snprintf(counterName, sizeof(counterName), "wq:%s", connection->getWindowName());
-        ATRACE_INT(counterName, connection->waitQueue.count());
-    }
-}
-
-void InputDispatcher::dump(String8& dump) {
-    AutoMutex _l(mLock);
-
-    dump.append("Input Dispatcher State:\n");
-    dumpDispatchStateLocked(dump);
-
-    if (!mLastANRState.isEmpty()) {
-        dump.append("\nInput Dispatcher State at time of last ANR:\n");
-        dump.append(mLastANRState);
-    }
-}
-
-void InputDispatcher::monitor() {
-    // Acquire and release the lock to ensure that the dispatcher has not deadlocked.
-    mLock.lock();
-    mLooper->wake();
-    mDispatcherIsAliveCondition.wait(mLock);
-    mLock.unlock();
-}
-
-
-// --- InputDispatcher::Queue ---
-
-template <typename T>
-uint32_t InputDispatcher::Queue<T>::count() const {
-    uint32_t result = 0;
-    for (const T* entry = head; entry; entry = entry->next) {
-        result += 1;
-    }
-    return result;
-}
-
-
-// --- InputDispatcher::InjectionState ---
-
-InputDispatcher::InjectionState::InjectionState(int32_t injectorPid, int32_t injectorUid) :
-        refCount(1),
-        injectorPid(injectorPid), injectorUid(injectorUid),
-        injectionResult(INPUT_EVENT_INJECTION_PENDING), injectionIsAsync(false),
-        pendingForegroundDispatches(0) {
-}
-
-InputDispatcher::InjectionState::~InjectionState() {
-}
-
-void InputDispatcher::InjectionState::release() {
-    refCount -= 1;
-    if (refCount == 0) {
-        delete this;
-    } else {
-        ALOG_ASSERT(refCount > 0);
-    }
-}
-
-
-// --- InputDispatcher::EventEntry ---
-
-InputDispatcher::EventEntry::EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags) :
-        refCount(1), type(type), eventTime(eventTime), policyFlags(policyFlags),
-        injectionState(NULL), dispatchInProgress(false) {
-}
-
-InputDispatcher::EventEntry::~EventEntry() {
-    releaseInjectionState();
-}
-
-void InputDispatcher::EventEntry::release() {
-    refCount -= 1;
-    if (refCount == 0) {
-        delete this;
-    } else {
-        ALOG_ASSERT(refCount > 0);
-    }
-}
-
-void InputDispatcher::EventEntry::releaseInjectionState() {
-    if (injectionState) {
-        injectionState->release();
-        injectionState = NULL;
-    }
-}
-
-
-// --- InputDispatcher::ConfigurationChangedEntry ---
-
-InputDispatcher::ConfigurationChangedEntry::ConfigurationChangedEntry(nsecs_t eventTime) :
-        EventEntry(TYPE_CONFIGURATION_CHANGED, eventTime, 0) {
-}
-
-InputDispatcher::ConfigurationChangedEntry::~ConfigurationChangedEntry() {
-}
-
-void InputDispatcher::ConfigurationChangedEntry::appendDescription(String8& msg) const {
-    msg.append("ConfigurationChangedEvent(), policyFlags=0x%08x",
-            policyFlags);
-}
-
-
-// --- InputDispatcher::DeviceResetEntry ---
-
-InputDispatcher::DeviceResetEntry::DeviceResetEntry(nsecs_t eventTime, int32_t deviceId) :
-        EventEntry(TYPE_DEVICE_RESET, eventTime, 0),
-        deviceId(deviceId) {
-}
-
-InputDispatcher::DeviceResetEntry::~DeviceResetEntry() {
-}
-
-void InputDispatcher::DeviceResetEntry::appendDescription(String8& msg) const {
-    msg.appendFormat("DeviceResetEvent(deviceId=%d), policyFlags=0x%08x",
-            deviceId, policyFlags);
-}
-
-
-// --- InputDispatcher::KeyEntry ---
-
-InputDispatcher::KeyEntry::KeyEntry(nsecs_t eventTime,
-        int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action,
-        int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
-        int32_t repeatCount, nsecs_t downTime) :
-        EventEntry(TYPE_KEY, eventTime, policyFlags),
-        deviceId(deviceId), source(source), action(action), flags(flags),
-        keyCode(keyCode), scanCode(scanCode), metaState(metaState),
-        repeatCount(repeatCount), downTime(downTime),
-        syntheticRepeat(false), interceptKeyResult(KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN),
-        interceptKeyWakeupTime(0) {
-}
-
-InputDispatcher::KeyEntry::~KeyEntry() {
-}
-
-void InputDispatcher::KeyEntry::appendDescription(String8& msg) const {
-    msg.appendFormat("KeyEvent(deviceId=%d, source=0x%08x, action=%d, "
-            "flags=0x%08x, keyCode=%d, scanCode=%d, metaState=0x%08x, "
-            "repeatCount=%d), policyFlags=0x%08x",
-            deviceId, source, action, flags, keyCode, scanCode, metaState,
-            repeatCount, policyFlags);
-}
-
-void InputDispatcher::KeyEntry::recycle() {
-    releaseInjectionState();
-
-    dispatchInProgress = false;
-    syntheticRepeat = false;
-    interceptKeyResult = KeyEntry::INTERCEPT_KEY_RESULT_UNKNOWN;
-    interceptKeyWakeupTime = 0;
-}
-
-
-// --- InputDispatcher::MotionEntry ---
-
-InputDispatcher::MotionEntry::MotionEntry(nsecs_t eventTime,
-        int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action, int32_t flags,
-        int32_t metaState, int32_t buttonState,
-        int32_t edgeFlags, float xPrecision, float yPrecision,
-        nsecs_t downTime, int32_t displayId, uint32_t pointerCount,
-        const PointerProperties* pointerProperties, const PointerCoords* pointerCoords) :
-        EventEntry(TYPE_MOTION, eventTime, policyFlags),
-        eventTime(eventTime),
-        deviceId(deviceId), source(source), action(action), flags(flags),
-        metaState(metaState), buttonState(buttonState), edgeFlags(edgeFlags),
-        xPrecision(xPrecision), yPrecision(yPrecision),
-        downTime(downTime), displayId(displayId), pointerCount(pointerCount) {
-    for (uint32_t i = 0; i < pointerCount; i++) {
-        this->pointerProperties[i].copyFrom(pointerProperties[i]);
-        this->pointerCoords[i].copyFrom(pointerCoords[i]);
-    }
-}
-
-InputDispatcher::MotionEntry::~MotionEntry() {
-}
-
-void InputDispatcher::MotionEntry::appendDescription(String8& msg) const {
-    msg.appendFormat("MotionEvent(deviceId=%d, source=0x%08x, action=%d, "
-            "flags=0x%08x, metaState=0x%08x, buttonState=0x%08x, edgeFlags=0x%08x, "
-            "xPrecision=%.1f, yPrecision=%.1f, displayId=%d, pointers=[",
-            deviceId, source, action, flags, metaState, buttonState, edgeFlags,
-            xPrecision, yPrecision, displayId);
-    for (uint32_t i = 0; i < pointerCount; i++) {
-        if (i) {
-            msg.append(", ");
-        }
-        msg.appendFormat("%d: (%.1f, %.1f)", pointerProperties[i].id,
-                pointerCoords[i].getX(), pointerCoords[i].getY());
-    }
-    msg.appendFormat("]), policyFlags=0x%08x", policyFlags);
-}
-
-
-// --- InputDispatcher::DispatchEntry ---
-
-volatile int32_t InputDispatcher::DispatchEntry::sNextSeqAtomic;
-
-InputDispatcher::DispatchEntry::DispatchEntry(EventEntry* eventEntry,
-        int32_t targetFlags, float xOffset, float yOffset, float scaleFactor) :
-        seq(nextSeq()),
-        eventEntry(eventEntry), targetFlags(targetFlags),
-        xOffset(xOffset), yOffset(yOffset), scaleFactor(scaleFactor),
-        deliveryTime(0), resolvedAction(0), resolvedFlags(0) {
-    eventEntry->refCount += 1;
-}
-
-InputDispatcher::DispatchEntry::~DispatchEntry() {
-    eventEntry->release();
-}
-
-uint32_t InputDispatcher::DispatchEntry::nextSeq() {
-    // Sequence number 0 is reserved and will never be returned.
-    uint32_t seq;
-    do {
-        seq = android_atomic_inc(&sNextSeqAtomic);
-    } while (!seq);
-    return seq;
-}
-
-
-// --- InputDispatcher::InputState ---
-
-InputDispatcher::InputState::InputState() {
-}
-
-InputDispatcher::InputState::~InputState() {
-}
-
-bool InputDispatcher::InputState::isNeutral() const {
-    return mKeyMementos.isEmpty() && mMotionMementos.isEmpty();
-}
-
-bool InputDispatcher::InputState::isHovering(int32_t deviceId, uint32_t source,
-        int32_t displayId) const {
-    for (size_t i = 0; i < mMotionMementos.size(); i++) {
-        const MotionMemento& memento = mMotionMementos.itemAt(i);
-        if (memento.deviceId == deviceId
-                && memento.source == source
-                && memento.displayId == displayId
-                && memento.hovering) {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool InputDispatcher::InputState::trackKey(const KeyEntry* entry,
-        int32_t action, int32_t flags) {
-    switch (action) {
-    case AKEY_EVENT_ACTION_UP: {
-        if (entry->flags & AKEY_EVENT_FLAG_FALLBACK) {
-            for (size_t i = 0; i < mFallbackKeys.size(); ) {
-                if (mFallbackKeys.valueAt(i) == entry->keyCode) {
-                    mFallbackKeys.removeItemsAt(i);
-                } else {
-                    i += 1;
-                }
-            }
-        }
-        ssize_t index = findKeyMemento(entry);
-        if (index >= 0) {
-            mKeyMementos.removeAt(index);
-            return true;
-        }
-        /* FIXME: We can't just drop the key up event because that prevents creating
-         * popup windows that are automatically shown when a key is held and then
-         * dismissed when the key is released.  The problem is that the popup will
-         * not have received the original key down, so the key up will be considered
-         * to be inconsistent with its observed state.  We could perhaps handle this
-         * by synthesizing a key down but that will cause other problems.
-         *
-         * So for now, allow inconsistent key up events to be dispatched.
-         *
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-        ALOGD("Dropping inconsistent key up event: deviceId=%d, source=%08x, "
-                "keyCode=%d, scanCode=%d",
-                entry->deviceId, entry->source, entry->keyCode, entry->scanCode);
-#endif
-        return false;
-        */
-        return true;
-    }
-
-    case AKEY_EVENT_ACTION_DOWN: {
-        ssize_t index = findKeyMemento(entry);
-        if (index >= 0) {
-            mKeyMementos.removeAt(index);
-        }
-        addKeyMemento(entry, flags);
-        return true;
-    }
-
-    default:
-        return true;
-    }
-}
-
-bool InputDispatcher::InputState::trackMotion(const MotionEntry* entry,
-        int32_t action, int32_t flags) {
-    int32_t actionMasked = action & AMOTION_EVENT_ACTION_MASK;
-    switch (actionMasked) {
-    case AMOTION_EVENT_ACTION_UP:
-    case AMOTION_EVENT_ACTION_CANCEL: {
-        ssize_t index = findMotionMemento(entry, false /*hovering*/);
-        if (index >= 0) {
-            mMotionMementos.removeAt(index);
-            return true;
-        }
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-        ALOGD("Dropping inconsistent motion up or cancel event: deviceId=%d, source=%08x, "
-                "actionMasked=%d",
-                entry->deviceId, entry->source, actionMasked);
-#endif
-        return false;
-    }
-
-    case AMOTION_EVENT_ACTION_DOWN: {
-        ssize_t index = findMotionMemento(entry, false /*hovering*/);
-        if (index >= 0) {
-            mMotionMementos.removeAt(index);
-        }
-        addMotionMemento(entry, flags, false /*hovering*/);
-        return true;
-    }
-
-    case AMOTION_EVENT_ACTION_POINTER_UP:
-    case AMOTION_EVENT_ACTION_POINTER_DOWN:
-    case AMOTION_EVENT_ACTION_MOVE: {
-        ssize_t index = findMotionMemento(entry, false /*hovering*/);
-        if (index >= 0) {
-            MotionMemento& memento = mMotionMementos.editItemAt(index);
-            memento.setPointers(entry);
-            return true;
-        }
-        if (actionMasked == AMOTION_EVENT_ACTION_MOVE
-                && (entry->source & (AINPUT_SOURCE_CLASS_JOYSTICK
-                        | AINPUT_SOURCE_CLASS_NAVIGATION))) {
-            // Joysticks and trackballs can send MOVE events without corresponding DOWN or UP.
-            return true;
-        }
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-        ALOGD("Dropping inconsistent motion pointer up/down or move event: "
-                "deviceId=%d, source=%08x, actionMasked=%d",
-                entry->deviceId, entry->source, actionMasked);
-#endif
-        return false;
-    }
-
-    case AMOTION_EVENT_ACTION_HOVER_EXIT: {
-        ssize_t index = findMotionMemento(entry, true /*hovering*/);
-        if (index >= 0) {
-            mMotionMementos.removeAt(index);
-            return true;
-        }
-#if DEBUG_OUTBOUND_EVENT_DETAILS
-        ALOGD("Dropping inconsistent motion hover exit event: deviceId=%d, source=%08x",
-                entry->deviceId, entry->source);
-#endif
-        return false;
-    }
-
-    case AMOTION_EVENT_ACTION_HOVER_ENTER:
-    case AMOTION_EVENT_ACTION_HOVER_MOVE: {
-        ssize_t index = findMotionMemento(entry, true /*hovering*/);
-        if (index >= 0) {
-            mMotionMementos.removeAt(index);
-        }
-        addMotionMemento(entry, flags, true /*hovering*/);
-        return true;
-    }
-
-    default:
-        return true;
-    }
-}
-
-ssize_t InputDispatcher::InputState::findKeyMemento(const KeyEntry* entry) const {
-    for (size_t i = 0; i < mKeyMementos.size(); i++) {
-        const KeyMemento& memento = mKeyMementos.itemAt(i);
-        if (memento.deviceId == entry->deviceId
-                && memento.source == entry->source
-                && memento.keyCode == entry->keyCode
-                && memento.scanCode == entry->scanCode) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-ssize_t InputDispatcher::InputState::findMotionMemento(const MotionEntry* entry,
-        bool hovering) const {
-    for (size_t i = 0; i < mMotionMementos.size(); i++) {
-        const MotionMemento& memento = mMotionMementos.itemAt(i);
-        if (memento.deviceId == entry->deviceId
-                && memento.source == entry->source
-                && memento.displayId == entry->displayId
-                && memento.hovering == hovering) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-void InputDispatcher::InputState::addKeyMemento(const KeyEntry* entry, int32_t flags) {
-    mKeyMementos.push();
-    KeyMemento& memento = mKeyMementos.editTop();
-    memento.deviceId = entry->deviceId;
-    memento.source = entry->source;
-    memento.keyCode = entry->keyCode;
-    memento.scanCode = entry->scanCode;
-    memento.metaState = entry->metaState;
-    memento.flags = flags;
-    memento.downTime = entry->downTime;
-    memento.policyFlags = entry->policyFlags;
-}
-
-void InputDispatcher::InputState::addMotionMemento(const MotionEntry* entry,
-        int32_t flags, bool hovering) {
-    mMotionMementos.push();
-    MotionMemento& memento = mMotionMementos.editTop();
-    memento.deviceId = entry->deviceId;
-    memento.source = entry->source;
-    memento.flags = flags;
-    memento.xPrecision = entry->xPrecision;
-    memento.yPrecision = entry->yPrecision;
-    memento.downTime = entry->downTime;
-    memento.displayId = entry->displayId;
-    memento.setPointers(entry);
-    memento.hovering = hovering;
-    memento.policyFlags = entry->policyFlags;
-}
-
-void InputDispatcher::InputState::MotionMemento::setPointers(const MotionEntry* entry) {
-    pointerCount = entry->pointerCount;
-    for (uint32_t i = 0; i < entry->pointerCount; i++) {
-        pointerProperties[i].copyFrom(entry->pointerProperties[i]);
-        pointerCoords[i].copyFrom(entry->pointerCoords[i]);
-    }
-}
-
-void InputDispatcher::InputState::synthesizeCancelationEvents(nsecs_t currentTime,
-        Vector<EventEntry*>& outEvents, const CancelationOptions& options) {
-    for (size_t i = 0; i < mKeyMementos.size(); i++) {
-        const KeyMemento& memento = mKeyMementos.itemAt(i);
-        if (shouldCancelKey(memento, options)) {
-            outEvents.push(new KeyEntry(currentTime,
-                    memento.deviceId, memento.source, memento.policyFlags,
-                    AKEY_EVENT_ACTION_UP, memento.flags | AKEY_EVENT_FLAG_CANCELED,
-                    memento.keyCode, memento.scanCode, memento.metaState, 0, memento.downTime));
-        }
-    }
-
-    for (size_t i = 0; i < mMotionMementos.size(); i++) {
-        const MotionMemento& memento = mMotionMementos.itemAt(i);
-        if (shouldCancelMotion(memento, options)) {
-            outEvents.push(new MotionEntry(currentTime,
-                    memento.deviceId, memento.source, memento.policyFlags,
-                    memento.hovering
-                            ? AMOTION_EVENT_ACTION_HOVER_EXIT
-                            : AMOTION_EVENT_ACTION_CANCEL,
-                    memento.flags, 0, 0, 0,
-                    memento.xPrecision, memento.yPrecision, memento.downTime,
-                    memento.displayId,
-                    memento.pointerCount, memento.pointerProperties, memento.pointerCoords));
-        }
-    }
-}
-
-void InputDispatcher::InputState::clear() {
-    mKeyMementos.clear();
-    mMotionMementos.clear();
-    mFallbackKeys.clear();
-}
-
-void InputDispatcher::InputState::copyPointerStateTo(InputState& other) const {
-    for (size_t i = 0; i < mMotionMementos.size(); i++) {
-        const MotionMemento& memento = mMotionMementos.itemAt(i);
-        if (memento.source & AINPUT_SOURCE_CLASS_POINTER) {
-            for (size_t j = 0; j < other.mMotionMementos.size(); ) {
-                const MotionMemento& otherMemento = other.mMotionMementos.itemAt(j);
-                if (memento.deviceId == otherMemento.deviceId
-                        && memento.source == otherMemento.source
-                        && memento.displayId == otherMemento.displayId) {
-                    other.mMotionMementos.removeAt(j);
-                } else {
-                    j += 1;
-                }
-            }
-            other.mMotionMementos.push(memento);
-        }
-    }
-}
-
-int32_t InputDispatcher::InputState::getFallbackKey(int32_t originalKeyCode) {
-    ssize_t index = mFallbackKeys.indexOfKey(originalKeyCode);
-    return index >= 0 ? mFallbackKeys.valueAt(index) : -1;
-}
-
-void InputDispatcher::InputState::setFallbackKey(int32_t originalKeyCode,
-        int32_t fallbackKeyCode) {
-    ssize_t index = mFallbackKeys.indexOfKey(originalKeyCode);
-    if (index >= 0) {
-        mFallbackKeys.replaceValueAt(index, fallbackKeyCode);
-    } else {
-        mFallbackKeys.add(originalKeyCode, fallbackKeyCode);
-    }
-}
-
-void InputDispatcher::InputState::removeFallbackKey(int32_t originalKeyCode) {
-    mFallbackKeys.removeItem(originalKeyCode);
-}
-
-bool InputDispatcher::InputState::shouldCancelKey(const KeyMemento& memento,
-        const CancelationOptions& options) {
-    if (options.keyCode != -1 && memento.keyCode != options.keyCode) {
-        return false;
-    }
-
-    if (options.deviceId != -1 && memento.deviceId != options.deviceId) {
-        return false;
-    }
-
-    switch (options.mode) {
-    case CancelationOptions::CANCEL_ALL_EVENTS:
-    case CancelationOptions::CANCEL_NON_POINTER_EVENTS:
-        return true;
-    case CancelationOptions::CANCEL_FALLBACK_EVENTS:
-        return memento.flags & AKEY_EVENT_FLAG_FALLBACK;
-    default:
-        return false;
-    }
-}
-
-bool InputDispatcher::InputState::shouldCancelMotion(const MotionMemento& memento,
-        const CancelationOptions& options) {
-    if (options.deviceId != -1 && memento.deviceId != options.deviceId) {
-        return false;
-    }
-
-    switch (options.mode) {
-    case CancelationOptions::CANCEL_ALL_EVENTS:
-        return true;
-    case CancelationOptions::CANCEL_POINTER_EVENTS:
-        return memento.source & AINPUT_SOURCE_CLASS_POINTER;
-    case CancelationOptions::CANCEL_NON_POINTER_EVENTS:
-        return !(memento.source & AINPUT_SOURCE_CLASS_POINTER);
-    default:
-        return false;
-    }
-}
-
-
-// --- InputDispatcher::Connection ---
-
-InputDispatcher::Connection::Connection(const sp<InputChannel>& inputChannel,
-        const sp<InputWindowHandle>& inputWindowHandle, bool monitor) :
-        status(STATUS_NORMAL), inputChannel(inputChannel), inputWindowHandle(inputWindowHandle),
-        monitor(monitor),
-        inputPublisher(inputChannel), inputPublisherBlocked(false) {
-}
-
-InputDispatcher::Connection::~Connection() {
-}
-
-const char* InputDispatcher::Connection::getWindowName() const {
-    if (inputWindowHandle != NULL) {
-        return inputWindowHandle->getName().string();
-    }
-    if (monitor) {
-        return "monitor";
-    }
-    return "?";
-}
-
-const char* InputDispatcher::Connection::getStatusLabel() const {
-    switch (status) {
-    case STATUS_NORMAL:
-        return "NORMAL";
-
-    case STATUS_BROKEN:
-        return "BROKEN";
-
-    case STATUS_ZOMBIE:
-        return "ZOMBIE";
-
-    default:
-        return "UNKNOWN";
-    }
-}
-
-InputDispatcher::DispatchEntry* InputDispatcher::Connection::findWaitQueueEntry(uint32_t seq) {
-    for (DispatchEntry* entry = waitQueue.head; entry != NULL; entry = entry->next) {
-        if (entry->seq == seq) {
-            return entry;
-        }
-    }
-    return NULL;
-}
-
-
-// --- InputDispatcher::CommandEntry ---
-
-InputDispatcher::CommandEntry::CommandEntry(Command command) :
-    command(command), eventTime(0), keyEntry(NULL), userActivityEventType(0),
-    seq(0), handled(false) {
-}
-
-InputDispatcher::CommandEntry::~CommandEntry() {
-}
-
-
-// --- InputDispatcher::TouchState ---
-
-InputDispatcher::TouchState::TouchState() :
-    down(false), split(false), deviceId(-1), source(0), displayId(-1) {
-}
-
-InputDispatcher::TouchState::~TouchState() {
-}
-
-void InputDispatcher::TouchState::reset() {
-    down = false;
-    split = false;
-    deviceId = -1;
-    source = 0;
-    displayId = -1;
-    windows.clear();
-}
-
-void InputDispatcher::TouchState::copyFrom(const TouchState& other) {
-    down = other.down;
-    split = other.split;
-    deviceId = other.deviceId;
-    source = other.source;
-    displayId = other.displayId;
-    windows = other.windows;
-}
-
-void InputDispatcher::TouchState::addOrUpdateWindow(const sp<InputWindowHandle>& windowHandle,
-        int32_t targetFlags, BitSet32 pointerIds) {
-    if (targetFlags & InputTarget::FLAG_SPLIT) {
-        split = true;
-    }
-
-    for (size_t i = 0; i < windows.size(); i++) {
-        TouchedWindow& touchedWindow = windows.editItemAt(i);
-        if (touchedWindow.windowHandle == windowHandle) {
-            touchedWindow.targetFlags |= targetFlags;
-            if (targetFlags & InputTarget::FLAG_DISPATCH_AS_SLIPPERY_EXIT) {
-                touchedWindow.targetFlags &= ~InputTarget::FLAG_DISPATCH_AS_IS;
-            }
-            touchedWindow.pointerIds.value |= pointerIds.value;
-            return;
-        }
-    }
-
-    windows.push();
-
-    TouchedWindow& touchedWindow = windows.editTop();
-    touchedWindow.windowHandle = windowHandle;
-    touchedWindow.targetFlags = targetFlags;
-    touchedWindow.pointerIds = pointerIds;
-}
-
-void InputDispatcher::TouchState::removeWindow(const sp<InputWindowHandle>& windowHandle) {
-    for (size_t i = 0; i < windows.size(); i++) {
-        if (windows.itemAt(i).windowHandle == windowHandle) {
-            windows.removeAt(i);
-            return;
-        }
-    }
-}
-
-void InputDispatcher::TouchState::filterNonAsIsTouchWindows() {
-    for (size_t i = 0 ; i < windows.size(); ) {
-        TouchedWindow& window = windows.editItemAt(i);
-        if (window.targetFlags & (InputTarget::FLAG_DISPATCH_AS_IS
-                | InputTarget::FLAG_DISPATCH_AS_SLIPPERY_ENTER)) {
-            window.targetFlags &= ~InputTarget::FLAG_DISPATCH_MASK;
-            window.targetFlags |= InputTarget::FLAG_DISPATCH_AS_IS;
-            i += 1;
-        } else {
-            windows.removeAt(i);
-        }
-    }
-}
-
-sp<InputWindowHandle> InputDispatcher::TouchState::getFirstForegroundWindowHandle() const {
-    for (size_t i = 0; i < windows.size(); i++) {
-        const TouchedWindow& window = windows.itemAt(i);
-        if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
-            return window.windowHandle;
-        }
-    }
-    return NULL;
-}
-
-bool InputDispatcher::TouchState::isSlippery() const {
-    // Must have exactly one foreground window.
-    bool haveSlipperyForegroundWindow = false;
-    for (size_t i = 0; i < windows.size(); i++) {
-        const TouchedWindow& window = windows.itemAt(i);
-        if (window.targetFlags & InputTarget::FLAG_FOREGROUND) {
-            if (haveSlipperyForegroundWindow
-                    || !(window.windowHandle->getInfo()->layoutParamsFlags
-                            & InputWindowInfo::FLAG_SLIPPERY)) {
-                return false;
-            }
-            haveSlipperyForegroundWindow = true;
-        }
-    }
-    return haveSlipperyForegroundWindow;
-}
-
-
-// --- InputDispatcherThread ---
-
-InputDispatcherThread::InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher) :
-        Thread(/*canCallJava*/ true), mDispatcher(dispatcher) {
-}
-
-InputDispatcherThread::~InputDispatcherThread() {
-}
-
-bool InputDispatcherThread::threadLoop() {
-    mDispatcher->dispatchOnce();
-    return true;
-}
-
-} // namespace android
diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h
deleted file mode 100644
index 190e7b2..0000000
--- a/services/input/InputDispatcher.h
+++ /dev/null
@@ -1,1123 +0,0 @@
-/*
- * Copyright (C) 2010 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 _UI_INPUT_DISPATCHER_H
-#define _UI_INPUT_DISPATCHER_H
-
-#include <input/Input.h>
-#include <input/InputTransport.h>
-#include <utils/KeyedVector.h>
-#include <utils/Vector.h>
-#include <utils/threads.h>
-#include <utils/Timers.h>
-#include <utils/RefBase.h>
-#include <utils/String8.h>
-#include <utils/Looper.h>
-#include <utils/BitSet.h>
-#include <cutils/atomic.h>
-
-#include <stddef.h>
-#include <unistd.h>
-#include <limits.h>
-
-#include "InputWindow.h"
-#include "InputApplication.h"
-#include "InputListener.h"
-
-
-namespace android {
-
-/*
- * Constants used to report the outcome of input event injection.
- */
-enum {
-    /* (INTERNAL USE ONLY) Specifies that injection is pending and its outcome is unknown. */
-    INPUT_EVENT_INJECTION_PENDING = -1,
-
-    /* Injection succeeded. */
-    INPUT_EVENT_INJECTION_SUCCEEDED = 0,
-
-    /* Injection failed because the injector did not have permission to inject
-     * into the application with input focus. */
-    INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1,
-
-    /* Injection failed because there were no available input targets. */
-    INPUT_EVENT_INJECTION_FAILED = 2,
-
-    /* Injection failed due to a timeout. */
-    INPUT_EVENT_INJECTION_TIMED_OUT = 3
-};
-
-/*
- * Constants used to determine the input event injection synchronization mode.
- */
-enum {
-    /* Injection is asynchronous and is assumed always to be successful. */
-    INPUT_EVENT_INJECTION_SYNC_NONE = 0,
-
-    /* Waits for previous events to be dispatched so that the input dispatcher can determine
-     * whether input event injection willbe permitted based on the current input focus.
-     * Does not wait for the input event to finish processing. */
-    INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1,
-
-    /* Waits for the input event to be completely processed. */
-    INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISHED = 2,
-};
-
-
-/*
- * An input target specifies how an input event is to be dispatched to a particular window
- * including the window's input channel, control flags, a timeout, and an X / Y offset to
- * be added to input event coordinates to compensate for the absolute position of the
- * window area.
- */
-struct InputTarget {
-    enum {
-        /* This flag indicates that the event is being delivered to a foreground application. */
-        FLAG_FOREGROUND = 1 << 0,
-
-        /* This flag indicates that the target of a MotionEvent is partly or wholly
-         * obscured by another visible window above it.  The motion event should be
-         * delivered with flag AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED. */
-        FLAG_WINDOW_IS_OBSCURED = 1 << 1,
-
-        /* This flag indicates that a motion event is being split across multiple windows. */
-        FLAG_SPLIT = 1 << 2,
-
-        /* This flag indicates that the pointer coordinates dispatched to the application
-         * will be zeroed out to avoid revealing information to an application. This is
-         * used in conjunction with FLAG_DISPATCH_AS_OUTSIDE to prevent apps not sharing
-         * the same UID from watching all touches. */
-        FLAG_ZERO_COORDS = 1 << 3,
-
-        /* This flag indicates that the event should be sent as is.
-         * Should always be set unless the event is to be transmuted. */
-        FLAG_DISPATCH_AS_IS = 1 << 8,
-
-        /* This flag indicates that a MotionEvent with AMOTION_EVENT_ACTION_DOWN falls outside
-         * of the area of this target and so should instead be delivered as an
-         * AMOTION_EVENT_ACTION_OUTSIDE to this target. */
-        FLAG_DISPATCH_AS_OUTSIDE = 1 << 9,
-
-        /* This flag indicates that a hover sequence is starting in the given window.
-         * The event is transmuted into ACTION_HOVER_ENTER. */
-        FLAG_DISPATCH_AS_HOVER_ENTER = 1 << 10,
-
-        /* This flag indicates that a hover event happened outside of a window which handled
-         * previous hover events, signifying the end of the current hover sequence for that
-         * window.
-         * The event is transmuted into ACTION_HOVER_ENTER. */
-        FLAG_DISPATCH_AS_HOVER_EXIT = 1 << 11,
-
-        /* This flag indicates that the event should be canceled.
-         * It is used to transmute ACTION_MOVE into ACTION_CANCEL when a touch slips
-         * outside of a window. */
-        FLAG_DISPATCH_AS_SLIPPERY_EXIT = 1 << 12,
-
-        /* This flag indicates that the event should be dispatched as an initial down.
-         * It is used to transmute ACTION_MOVE into ACTION_DOWN when a touch slips
-         * into a new window. */
-        FLAG_DISPATCH_AS_SLIPPERY_ENTER = 1 << 13,
-
-        /* Mask for all dispatch modes. */
-        FLAG_DISPATCH_MASK = FLAG_DISPATCH_AS_IS
-                | FLAG_DISPATCH_AS_OUTSIDE
-                | FLAG_DISPATCH_AS_HOVER_ENTER
-                | FLAG_DISPATCH_AS_HOVER_EXIT
-                | FLAG_DISPATCH_AS_SLIPPERY_EXIT
-                | FLAG_DISPATCH_AS_SLIPPERY_ENTER,
-    };
-
-    // The input channel to be targeted.
-    sp<InputChannel> inputChannel;
-
-    // Flags for the input target.
-    int32_t flags;
-
-    // The x and y offset to add to a MotionEvent as it is delivered.
-    // (ignored for KeyEvents)
-    float xOffset, yOffset;
-
-    // Scaling factor to apply to MotionEvent as it is delivered.
-    // (ignored for KeyEvents)
-    float scaleFactor;
-
-    // The subset of pointer ids to include in motion events dispatched to this input target
-    // if FLAG_SPLIT is set.
-    BitSet32 pointerIds;
-};
-
-
-/*
- * Input dispatcher configuration.
- *
- * Specifies various options that modify the behavior of the input dispatcher.
- * The values provided here are merely defaults. The actual values will come from ViewConfiguration
- * and are passed into the dispatcher during initialization.
- */
-struct InputDispatcherConfiguration {
-    // The key repeat initial timeout.
-    nsecs_t keyRepeatTimeout;
-
-    // The key repeat inter-key delay.
-    nsecs_t keyRepeatDelay;
-
-    InputDispatcherConfiguration() :
-            keyRepeatTimeout(500 * 1000000LL),
-            keyRepeatDelay(50 * 1000000LL) { }
-};
-
-
-/*
- * Input dispatcher policy interface.
- *
- * The input reader policy is used by the input reader to interact with the Window Manager
- * and other system components.
- *
- * The actual implementation is partially supported by callbacks into the DVM
- * via JNI.  This interface is also mocked in the unit tests.
- */
-class InputDispatcherPolicyInterface : public virtual RefBase {
-protected:
-    InputDispatcherPolicyInterface() { }
-    virtual ~InputDispatcherPolicyInterface() { }
-
-public:
-    /* Notifies the system that a configuration change has occurred. */
-    virtual void notifyConfigurationChanged(nsecs_t when) = 0;
-
-    /* Notifies the system that an application is not responding.
-     * Returns a new timeout to continue waiting, or 0 to abort dispatch. */
-    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
-            const sp<InputWindowHandle>& inputWindowHandle,
-            const String8& reason) = 0;
-
-    /* Notifies the system that an input channel is unrecoverably broken. */
-    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) = 0;
-
-    /* Gets the input dispatcher configuration. */
-    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) = 0;
-
-    /* Returns true if automatic key repeating is enabled. */
-    virtual bool isKeyRepeatEnabled() = 0;
-
-    /* Filters an input event.
-     * Return true to dispatch the event unmodified, false to consume the event.
-     * A filter can also transform and inject events later by passing POLICY_FLAG_FILTERED
-     * to injectInputEvent.
-     */
-    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) = 0;
-
-    /* Intercepts a key event immediately before queueing it.
-     * The policy can use this method as an opportunity to perform power management functions
-     * and early event preprocessing such as updating policy flags.
-     *
-     * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
-     * should be dispatched to applications.
-     */
-    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) = 0;
-
-    /* Intercepts a touch, trackball or other motion event before queueing it.
-     * The policy can use this method as an opportunity to perform power management functions
-     * and early event preprocessing such as updating policy flags.
-     *
-     * This method is expected to set the POLICY_FLAG_PASS_TO_USER policy flag if the event
-     * should be dispatched to applications.
-     */
-    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) = 0;
-
-    /* Allows the policy a chance to intercept a key before dispatching. */
-    virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags) = 0;
-
-    /* Allows the policy a chance to perform default processing for an unhandled key.
-     * Returns an alternate keycode to redispatch as a fallback, or 0 to give up. */
-    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) = 0;
-
-    /* Notifies the policy about switch events.
-     */
-    virtual void notifySwitch(nsecs_t when,
-            uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) = 0;
-
-    /* Poke user activity for an event dispatched to a window. */
-    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0;
-
-    /* Checks whether a given application pid/uid has permission to inject input events
-     * into other applications.
-     *
-     * This method is special in that its implementation promises to be non-reentrant and
-     * is safe to call while holding other locks.  (Most other methods make no such guarantees!)
-     */
-    virtual bool checkInjectEventsPermissionNonReentrant(
-            int32_t injectorPid, int32_t injectorUid) = 0;
-};
-
-
-/* Notifies the system about input events generated by the input reader.
- * The dispatcher is expected to be mostly asynchronous. */
-class InputDispatcherInterface : public virtual RefBase, public InputListenerInterface {
-protected:
-    InputDispatcherInterface() { }
-    virtual ~InputDispatcherInterface() { }
-
-public:
-    /* Dumps the state of the input dispatcher.
-     *
-     * This method may be called on any thread (usually by the input manager). */
-    virtual void dump(String8& dump) = 0;
-
-    /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
-    virtual void monitor() = 0;
-
-    /* Runs a single iteration of the dispatch loop.
-     * Nominally processes one queued event, a timeout, or a response from an input consumer.
-     *
-     * This method should only be called on the input dispatcher thread.
-     */
-    virtual void dispatchOnce() = 0;
-
-    /* Injects an input event and optionally waits for sync.
-     * The synchronization mode determines whether the method blocks while waiting for
-     * input injection to proceed.
-     * Returns one of the INPUT_EVENT_INJECTION_XXX constants.
-     *
-     * This method may be called on any thread (usually by the input manager).
-     */
-    virtual int32_t injectInputEvent(const InputEvent* event,
-            int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
-            uint32_t policyFlags) = 0;
-
-    /* Sets the list of input windows.
-     *
-     * This method may be called on any thread (usually by the input manager).
-     */
-    virtual void setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles) = 0;
-
-    /* Sets the focused application.
-     *
-     * This method may be called on any thread (usually by the input manager).
-     */
-    virtual void setFocusedApplication(
-            const sp<InputApplicationHandle>& inputApplicationHandle) = 0;
-
-    /* Sets the input dispatching mode.
-     *
-     * This method may be called on any thread (usually by the input manager).
-     */
-    virtual void setInputDispatchMode(bool enabled, bool frozen) = 0;
-
-    /* Sets whether input event filtering is enabled.
-     * When enabled, incoming input events are sent to the policy's filterInputEvent
-     * method instead of being dispatched.  The filter is expected to use
-     * injectInputEvent to inject the events it would like to have dispatched.
-     * It should include POLICY_FLAG_FILTERED in the policy flags during injection.
-     */
-    virtual void setInputFilterEnabled(bool enabled) = 0;
-
-    /* Transfers touch focus from the window associated with one channel to the
-     * window associated with the other channel.
-     *
-     * Returns true on success.  False if the window did not actually have touch focus.
-     */
-    virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
-            const sp<InputChannel>& toChannel) = 0;
-
-    /* Registers or unregister input channels that may be used as targets for input events.
-     * If monitor is true, the channel will receive a copy of all input events.
-     *
-     * These methods may be called on any thread (usually by the input manager).
-     */
-    virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
-            const sp<InputWindowHandle>& inputWindowHandle, bool monitor) = 0;
-    virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel) = 0;
-};
-
-/* Dispatches events to input targets.  Some functions of the input dispatcher, such as
- * identifying input targets, are controlled by a separate policy object.
- *
- * IMPORTANT INVARIANT:
- *     Because the policy can potentially block or cause re-entrance into the input dispatcher,
- *     the input dispatcher never calls into the policy while holding its internal locks.
- *     The implementation is also carefully designed to recover from scenarios such as an
- *     input channel becoming unregistered while identifying input targets or processing timeouts.
- *
- *     Methods marked 'Locked' must be called with the lock acquired.
- *
- *     Methods marked 'LockedInterruptible' must be called with the lock acquired but
- *     may during the course of their execution release the lock, call into the policy, and
- *     then reacquire the lock.  The caller is responsible for recovering gracefully.
- *
- *     A 'LockedInterruptible' method may called a 'Locked' method, but NOT vice-versa.
- */
-class InputDispatcher : public InputDispatcherInterface {
-protected:
-    virtual ~InputDispatcher();
-
-public:
-    explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy);
-
-    virtual void dump(String8& dump);
-    virtual void monitor();
-
-    virtual void dispatchOnce();
-
-    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
-    virtual void notifyKey(const NotifyKeyArgs* args);
-    virtual void notifyMotion(const NotifyMotionArgs* args);
-    virtual void notifySwitch(const NotifySwitchArgs* args);
-    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
-
-    virtual int32_t injectInputEvent(const InputEvent* event,
-            int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
-            uint32_t policyFlags);
-
-    virtual void setInputWindows(const Vector<sp<InputWindowHandle> >& inputWindowHandles);
-    virtual void setFocusedApplication(const sp<InputApplicationHandle>& inputApplicationHandle);
-    virtual void setInputDispatchMode(bool enabled, bool frozen);
-    virtual void setInputFilterEnabled(bool enabled);
-
-    virtual bool transferTouchFocus(const sp<InputChannel>& fromChannel,
-            const sp<InputChannel>& toChannel);
-
-    virtual status_t registerInputChannel(const sp<InputChannel>& inputChannel,
-            const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
-    virtual status_t unregisterInputChannel(const sp<InputChannel>& inputChannel);
-
-private:
-    template <typename T>
-    struct Link {
-        T* next;
-        T* prev;
-
-    protected:
-        inline Link() : next(NULL), prev(NULL) { }
-    };
-
-    struct InjectionState {
-        mutable int32_t refCount;
-
-        int32_t injectorPid;
-        int32_t injectorUid;
-        int32_t injectionResult;  // initially INPUT_EVENT_INJECTION_PENDING
-        bool injectionIsAsync; // set to true if injection is not waiting for the result
-        int32_t pendingForegroundDispatches; // the number of foreground dispatches in progress
-
-        InjectionState(int32_t injectorPid, int32_t injectorUid);
-        void release();
-
-    private:
-        ~InjectionState();
-    };
-
-    struct EventEntry : Link<EventEntry> {
-        enum {
-            TYPE_CONFIGURATION_CHANGED,
-            TYPE_DEVICE_RESET,
-            TYPE_KEY,
-            TYPE_MOTION
-        };
-
-        mutable int32_t refCount;
-        int32_t type;
-        nsecs_t eventTime;
-        uint32_t policyFlags;
-        InjectionState* injectionState;
-
-        bool dispatchInProgress; // initially false, set to true while dispatching
-
-        inline bool isInjected() const { return injectionState != NULL; }
-
-        void release();
-
-        virtual void appendDescription(String8& msg) const = 0;
-
-    protected:
-        EventEntry(int32_t type, nsecs_t eventTime, uint32_t policyFlags);
-        virtual ~EventEntry();
-        void releaseInjectionState();
-    };
-
-    struct ConfigurationChangedEntry : EventEntry {
-        ConfigurationChangedEntry(nsecs_t eventTime);
-        virtual void appendDescription(String8& msg) const;
-
-    protected:
-        virtual ~ConfigurationChangedEntry();
-    };
-
-    struct DeviceResetEntry : EventEntry {
-        int32_t deviceId;
-
-        DeviceResetEntry(nsecs_t eventTime, int32_t deviceId);
-        virtual void appendDescription(String8& msg) const;
-
-    protected:
-        virtual ~DeviceResetEntry();
-    };
-
-    struct KeyEntry : EventEntry {
-        int32_t deviceId;
-        uint32_t source;
-        int32_t action;
-        int32_t flags;
-        int32_t keyCode;
-        int32_t scanCode;
-        int32_t metaState;
-        int32_t repeatCount;
-        nsecs_t downTime;
-
-        bool syntheticRepeat; // set to true for synthetic key repeats
-
-        enum InterceptKeyResult {
-            INTERCEPT_KEY_RESULT_UNKNOWN,
-            INTERCEPT_KEY_RESULT_SKIP,
-            INTERCEPT_KEY_RESULT_CONTINUE,
-            INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER,
-        };
-        InterceptKeyResult interceptKeyResult; // set based on the interception result
-        nsecs_t interceptKeyWakeupTime; // used with INTERCEPT_KEY_RESULT_TRY_AGAIN_LATER
-
-        KeyEntry(nsecs_t eventTime,
-                int32_t deviceId, uint32_t source, uint32_t policyFlags, int32_t action,
-                int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
-                int32_t repeatCount, nsecs_t downTime);
-        virtual void appendDescription(String8& msg) const;
-        void recycle();
-
-    protected:
-        virtual ~KeyEntry();
-    };
-
-    struct MotionEntry : EventEntry {
-        nsecs_t eventTime;
-        int32_t deviceId;
-        uint32_t source;
-        int32_t action;
-        int32_t flags;
-        int32_t metaState;
-        int32_t buttonState;
-        int32_t edgeFlags;
-        float xPrecision;
-        float yPrecision;
-        nsecs_t downTime;
-        int32_t displayId;
-        uint32_t pointerCount;
-        PointerProperties pointerProperties[MAX_POINTERS];
-        PointerCoords pointerCoords[MAX_POINTERS];
-
-        MotionEntry(nsecs_t eventTime,
-                int32_t deviceId, uint32_t source, uint32_t policyFlags,
-                int32_t action, int32_t flags,
-                int32_t metaState, int32_t buttonState, int32_t edgeFlags,
-                float xPrecision, float yPrecision,
-                nsecs_t downTime, int32_t displayId, uint32_t pointerCount,
-                const PointerProperties* pointerProperties, const PointerCoords* pointerCoords);
-        virtual void appendDescription(String8& msg) const;
-
-    protected:
-        virtual ~MotionEntry();
-    };
-
-    // Tracks the progress of dispatching a particular event to a particular connection.
-    struct DispatchEntry : Link<DispatchEntry> {
-        const uint32_t seq; // unique sequence number, never 0
-
-        EventEntry* eventEntry; // the event to dispatch
-        int32_t targetFlags;
-        float xOffset;
-        float yOffset;
-        float scaleFactor;
-        nsecs_t deliveryTime; // time when the event was actually delivered
-
-        // Set to the resolved action and flags when the event is enqueued.
-        int32_t resolvedAction;
-        int32_t resolvedFlags;
-
-        DispatchEntry(EventEntry* eventEntry,
-                int32_t targetFlags, float xOffset, float yOffset, float scaleFactor);
-        ~DispatchEntry();
-
-        inline bool hasForegroundTarget() const {
-            return targetFlags & InputTarget::FLAG_FOREGROUND;
-        }
-
-        inline bool isSplit() const {
-            return targetFlags & InputTarget::FLAG_SPLIT;
-        }
-
-    private:
-        static volatile int32_t sNextSeqAtomic;
-
-        static uint32_t nextSeq();
-    };
-
-    // A command entry captures state and behavior for an action to be performed in the
-    // dispatch loop after the initial processing has taken place.  It is essentially
-    // a kind of continuation used to postpone sensitive policy interactions to a point
-    // in the dispatch loop where it is safe to release the lock (generally after finishing
-    // the critical parts of the dispatch cycle).
-    //
-    // The special thing about commands is that they can voluntarily release and reacquire
-    // the dispatcher lock at will.  Initially when the command starts running, the
-    // dispatcher lock is held.  However, if the command needs to call into the policy to
-    // do some work, it can release the lock, do the work, then reacquire the lock again
-    // before returning.
-    //
-    // This mechanism is a bit clunky but it helps to preserve the invariant that the dispatch
-    // never calls into the policy while holding its lock.
-    //
-    // Commands are implicitly 'LockedInterruptible'.
-    struct CommandEntry;
-    typedef void (InputDispatcher::*Command)(CommandEntry* commandEntry);
-
-    class Connection;
-    struct CommandEntry : Link<CommandEntry> {
-        CommandEntry(Command command);
-        ~CommandEntry();
-
-        Command command;
-
-        // parameters for the command (usage varies by command)
-        sp<Connection> connection;
-        nsecs_t eventTime;
-        KeyEntry* keyEntry;
-        sp<InputApplicationHandle> inputApplicationHandle;
-        sp<InputWindowHandle> inputWindowHandle;
-        String8 reason;
-        int32_t userActivityEventType;
-        uint32_t seq;
-        bool handled;
-    };
-
-    // Generic queue implementation.
-    template <typename T>
-    struct Queue {
-        T* head;
-        T* tail;
-
-        inline Queue() : head(NULL), tail(NULL) {
-        }
-
-        inline bool isEmpty() const {
-            return !head;
-        }
-
-        inline void enqueueAtTail(T* entry) {
-            entry->prev = tail;
-            if (tail) {
-                tail->next = entry;
-            } else {
-                head = entry;
-            }
-            entry->next = NULL;
-            tail = entry;
-        }
-
-        inline void enqueueAtHead(T* entry) {
-            entry->next = head;
-            if (head) {
-                head->prev = entry;
-            } else {
-                tail = entry;
-            }
-            entry->prev = NULL;
-            head = entry;
-        }
-
-        inline void dequeue(T* entry) {
-            if (entry->prev) {
-                entry->prev->next = entry->next;
-            } else {
-                head = entry->next;
-            }
-            if (entry->next) {
-                entry->next->prev = entry->prev;
-            } else {
-                tail = entry->prev;
-            }
-        }
-
-        inline T* dequeueAtHead() {
-            T* entry = head;
-            head = entry->next;
-            if (head) {
-                head->prev = NULL;
-            } else {
-                tail = NULL;
-            }
-            return entry;
-        }
-
-        uint32_t count() const;
-    };
-
-    /* Specifies which events are to be canceled and why. */
-    struct CancelationOptions {
-        enum Mode {
-            CANCEL_ALL_EVENTS = 0,
-            CANCEL_POINTER_EVENTS = 1,
-            CANCEL_NON_POINTER_EVENTS = 2,
-            CANCEL_FALLBACK_EVENTS = 3,
-        };
-
-        // The criterion to use to determine which events should be canceled.
-        Mode mode;
-
-        // Descriptive reason for the cancelation.
-        const char* reason;
-
-        // The specific keycode of the key event to cancel, or -1 to cancel any key event.
-        int32_t keyCode;
-
-        // The specific device id of events to cancel, or -1 to cancel events from any device.
-        int32_t deviceId;
-
-        CancelationOptions(Mode mode, const char* reason) :
-                mode(mode), reason(reason), keyCode(-1), deviceId(-1) { }
-    };
-
-    /* Tracks dispatched key and motion event state so that cancelation events can be
-     * synthesized when events are dropped. */
-    class InputState {
-    public:
-        InputState();
-        ~InputState();
-
-        // Returns true if there is no state to be canceled.
-        bool isNeutral() const;
-
-        // Returns true if the specified source is known to have received a hover enter
-        // motion event.
-        bool isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const;
-
-        // Records tracking information for a key event that has just been published.
-        // Returns true if the event should be delivered, false if it is inconsistent
-        // and should be skipped.
-        bool trackKey(const KeyEntry* entry, int32_t action, int32_t flags);
-
-        // Records tracking information for a motion event that has just been published.
-        // Returns true if the event should be delivered, false if it is inconsistent
-        // and should be skipped.
-        bool trackMotion(const MotionEntry* entry, int32_t action, int32_t flags);
-
-        // Synthesizes cancelation events for the current state and resets the tracked state.
-        void synthesizeCancelationEvents(nsecs_t currentTime,
-                Vector<EventEntry*>& outEvents, const CancelationOptions& options);
-
-        // Clears the current state.
-        void clear();
-
-        // Copies pointer-related parts of the input state to another instance.
-        void copyPointerStateTo(InputState& other) const;
-
-        // Gets the fallback key associated with a keycode.
-        // Returns -1 if none.
-        // Returns AKEYCODE_UNKNOWN if we are only dispatching the unhandled key to the policy.
-        int32_t getFallbackKey(int32_t originalKeyCode);
-
-        // Sets the fallback key for a particular keycode.
-        void setFallbackKey(int32_t originalKeyCode, int32_t fallbackKeyCode);
-
-        // Removes the fallback key for a particular keycode.
-        void removeFallbackKey(int32_t originalKeyCode);
-
-        inline const KeyedVector<int32_t, int32_t>& getFallbackKeys() const {
-            return mFallbackKeys;
-        }
-
-    private:
-        struct KeyMemento {
-            int32_t deviceId;
-            uint32_t source;
-            int32_t keyCode;
-            int32_t scanCode;
-            int32_t metaState;
-            int32_t flags;
-            nsecs_t downTime;
-            uint32_t policyFlags;
-        };
-
-        struct MotionMemento {
-            int32_t deviceId;
-            uint32_t source;
-            int32_t flags;
-            float xPrecision;
-            float yPrecision;
-            nsecs_t downTime;
-            int32_t displayId;
-            uint32_t pointerCount;
-            PointerProperties pointerProperties[MAX_POINTERS];
-            PointerCoords pointerCoords[MAX_POINTERS];
-            bool hovering;
-            uint32_t policyFlags;
-
-            void setPointers(const MotionEntry* entry);
-        };
-
-        Vector<KeyMemento> mKeyMementos;
-        Vector<MotionMemento> mMotionMementos;
-        KeyedVector<int32_t, int32_t> mFallbackKeys;
-
-        ssize_t findKeyMemento(const KeyEntry* entry) const;
-        ssize_t findMotionMemento(const MotionEntry* entry, bool hovering) const;
-
-        void addKeyMemento(const KeyEntry* entry, int32_t flags);
-        void addMotionMemento(const MotionEntry* entry, int32_t flags, bool hovering);
-
-        static bool shouldCancelKey(const KeyMemento& memento,
-                const CancelationOptions& options);
-        static bool shouldCancelMotion(const MotionMemento& memento,
-                const CancelationOptions& options);
-    };
-
-    /* Manages the dispatch state associated with a single input channel. */
-    class Connection : public RefBase {
-    protected:
-        virtual ~Connection();
-
-    public:
-        enum Status {
-            // Everything is peachy.
-            STATUS_NORMAL,
-            // An unrecoverable communication error has occurred.
-            STATUS_BROKEN,
-            // The input channel has been unregistered.
-            STATUS_ZOMBIE
-        };
-
-        Status status;
-        sp<InputChannel> inputChannel; // never null
-        sp<InputWindowHandle> inputWindowHandle; // may be null
-        bool monitor;
-        InputPublisher inputPublisher;
-        InputState inputState;
-
-        // True if the socket is full and no further events can be published until
-        // the application consumes some of the input.
-        bool inputPublisherBlocked;
-
-        // Queue of events that need to be published to the connection.
-        Queue<DispatchEntry> outboundQueue;
-
-        // Queue of events that have been published to the connection but that have not
-        // yet received a "finished" response from the application.
-        Queue<DispatchEntry> waitQueue;
-
-        explicit Connection(const sp<InputChannel>& inputChannel,
-                const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
-
-        inline const char* getInputChannelName() const { return inputChannel->getName().string(); }
-
-        const char* getWindowName() const;
-        const char* getStatusLabel() const;
-
-        DispatchEntry* findWaitQueueEntry(uint32_t seq);
-    };
-
-    enum DropReason {
-        DROP_REASON_NOT_DROPPED = 0,
-        DROP_REASON_POLICY = 1,
-        DROP_REASON_APP_SWITCH = 2,
-        DROP_REASON_DISABLED = 3,
-        DROP_REASON_BLOCKED = 4,
-        DROP_REASON_STALE = 5,
-    };
-
-    sp<InputDispatcherPolicyInterface> mPolicy;
-    InputDispatcherConfiguration mConfig;
-
-    Mutex mLock;
-
-    Condition mDispatcherIsAliveCondition;
-
-    sp<Looper> mLooper;
-
-    EventEntry* mPendingEvent;
-    Queue<EventEntry> mInboundQueue;
-    Queue<EventEntry> mRecentQueue;
-    Queue<CommandEntry> mCommandQueue;
-
-    void dispatchOnceInnerLocked(nsecs_t* nextWakeupTime);
-
-    // Enqueues an inbound event.  Returns true if mLooper->wake() should be called.
-    bool enqueueInboundEventLocked(EventEntry* entry);
-
-    // Cleans up input state when dropping an inbound event.
-    void dropInboundEventLocked(EventEntry* entry, DropReason dropReason);
-
-    // Adds an event to a queue of recent events for debugging purposes.
-    void addRecentEventLocked(EventEntry* entry);
-
-    // App switch latency optimization.
-    bool mAppSwitchSawKeyDown;
-    nsecs_t mAppSwitchDueTime;
-
-    static bool isAppSwitchKeyCode(int32_t keyCode);
-    bool isAppSwitchKeyEventLocked(KeyEntry* keyEntry);
-    bool isAppSwitchPendingLocked();
-    void resetPendingAppSwitchLocked(bool handled);
-
-    // Stale event latency optimization.
-    static bool isStaleEventLocked(nsecs_t currentTime, EventEntry* entry);
-
-    // Blocked event latency optimization.  Drops old events when the user intends
-    // to transfer focus to a new application.
-    EventEntry* mNextUnblockedEvent;
-
-    sp<InputWindowHandle> findTouchedWindowAtLocked(int32_t displayId, int32_t x, int32_t y);
-
-    // All registered connections mapped by channel file descriptor.
-    KeyedVector<int, sp<Connection> > mConnectionsByFd;
-
-    ssize_t getConnectionIndexLocked(const sp<InputChannel>& inputChannel);
-
-    // Input channels that will receive a copy of all input events.
-    Vector<sp<InputChannel> > mMonitoringChannels;
-
-    // Event injection and synchronization.
-    Condition mInjectionResultAvailableCondition;
-    bool hasInjectionPermission(int32_t injectorPid, int32_t injectorUid);
-    void setInjectionResultLocked(EventEntry* entry, int32_t injectionResult);
-
-    Condition mInjectionSyncFinishedCondition;
-    void incrementPendingForegroundDispatchesLocked(EventEntry* entry);
-    void decrementPendingForegroundDispatchesLocked(EventEntry* entry);
-
-    // Key repeat tracking.
-    struct KeyRepeatState {
-        KeyEntry* lastKeyEntry; // or null if no repeat
-        nsecs_t nextRepeatTime;
-    } mKeyRepeatState;
-
-    void resetKeyRepeatLocked();
-    KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime);
-
-    // Deferred command processing.
-    bool haveCommandsLocked() const;
-    bool runCommandsLockedInterruptible();
-    CommandEntry* postCommandLocked(Command command);
-
-    // Input filter processing.
-    bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args);
-    bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args);
-
-    // Inbound event processing.
-    void drainInboundQueueLocked();
-    void releasePendingEventLocked();
-    void releaseInboundEventLocked(EventEntry* entry);
-
-    // Dispatch state.
-    bool mDispatchEnabled;
-    bool mDispatchFrozen;
-    bool mInputFilterEnabled;
-
-    Vector<sp<InputWindowHandle> > mWindowHandles;
-
-    sp<InputWindowHandle> getWindowHandleLocked(const sp<InputChannel>& inputChannel) const;
-    bool hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const;
-
-    // Focus tracking for keys, trackball, etc.
-    sp<InputWindowHandle> mFocusedWindowHandle;
-
-    // Focus tracking for touch.
-    struct TouchedWindow {
-        sp<InputWindowHandle> windowHandle;
-        int32_t targetFlags;
-        BitSet32 pointerIds;        // zero unless target flag FLAG_SPLIT is set
-    };
-    struct TouchState {
-        bool down;
-        bool split;
-        int32_t deviceId; // id of the device that is currently down, others are rejected
-        uint32_t source;  // source of the device that is current down, others are rejected
-        int32_t displayId; // id to the display that currently has a touch, others are rejected
-        Vector<TouchedWindow> windows;
-
-        TouchState();
-        ~TouchState();
-        void reset();
-        void copyFrom(const TouchState& other);
-        void addOrUpdateWindow(const sp<InputWindowHandle>& windowHandle,
-                int32_t targetFlags, BitSet32 pointerIds);
-        void removeWindow(const sp<InputWindowHandle>& windowHandle);
-        void filterNonAsIsTouchWindows();
-        sp<InputWindowHandle> getFirstForegroundWindowHandle() const;
-        bool isSlippery() const;
-    };
-
-    TouchState mTouchState;
-    TouchState mTempTouchState;
-
-    // Focused application.
-    sp<InputApplicationHandle> mFocusedApplicationHandle;
-
-    // Dispatcher state at time of last ANR.
-    String8 mLastANRState;
-
-    // Dispatch inbound events.
-    bool dispatchConfigurationChangedLocked(
-            nsecs_t currentTime, ConfigurationChangedEntry* entry);
-    bool dispatchDeviceResetLocked(
-            nsecs_t currentTime, DeviceResetEntry* entry);
-    bool dispatchKeyLocked(
-            nsecs_t currentTime, KeyEntry* entry,
-            DropReason* dropReason, nsecs_t* nextWakeupTime);
-    bool dispatchMotionLocked(
-            nsecs_t currentTime, MotionEntry* entry,
-            DropReason* dropReason, nsecs_t* nextWakeupTime);
-    void dispatchEventLocked(nsecs_t currentTime, EventEntry* entry,
-            const Vector<InputTarget>& inputTargets);
-
-    void logOutboundKeyDetailsLocked(const char* prefix, const KeyEntry* entry);
-    void logOutboundMotionDetailsLocked(const char* prefix, const MotionEntry* entry);
-
-    // Keeping track of ANR timeouts.
-    enum InputTargetWaitCause {
-        INPUT_TARGET_WAIT_CAUSE_NONE,
-        INPUT_TARGET_WAIT_CAUSE_SYSTEM_NOT_READY,
-        INPUT_TARGET_WAIT_CAUSE_APPLICATION_NOT_READY,
-    };
-
-    InputTargetWaitCause mInputTargetWaitCause;
-    nsecs_t mInputTargetWaitStartTime;
-    nsecs_t mInputTargetWaitTimeoutTime;
-    bool mInputTargetWaitTimeoutExpired;
-    sp<InputApplicationHandle> mInputTargetWaitApplicationHandle;
-
-    // Contains the last window which received a hover event.
-    sp<InputWindowHandle> mLastHoverWindowHandle;
-
-    // Finding targets for input events.
-    int32_t handleTargetsNotReadyLocked(nsecs_t currentTime, const EventEntry* entry,
-            const sp<InputApplicationHandle>& applicationHandle,
-            const sp<InputWindowHandle>& windowHandle,
-            nsecs_t* nextWakeupTime, const char* reason);
-    void resumeAfterTargetsNotReadyTimeoutLocked(nsecs_t newTimeout,
-            const sp<InputChannel>& inputChannel);
-    nsecs_t getTimeSpentWaitingForApplicationLocked(nsecs_t currentTime);
-    void resetANRTimeoutsLocked();
-
-    int32_t findFocusedWindowTargetsLocked(nsecs_t currentTime, const EventEntry* entry,
-            Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime);
-    int32_t findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry* entry,
-            Vector<InputTarget>& inputTargets, nsecs_t* nextWakeupTime,
-            bool* outConflictingPointerActions);
-
-    void addWindowTargetLocked(const sp<InputWindowHandle>& windowHandle,
-            int32_t targetFlags, BitSet32 pointerIds, Vector<InputTarget>& inputTargets);
-    void addMonitoringTargetsLocked(Vector<InputTarget>& inputTargets);
-
-    void pokeUserActivityLocked(const EventEntry* eventEntry);
-    bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle,
-            const InjectionState* injectionState);
-    bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle,
-            int32_t x, int32_t y) const;
-    bool isWindowReadyForMoreInputLocked(nsecs_t currentTime,
-            const sp<InputWindowHandle>& windowHandle, const EventEntry* eventEntry);
-    String8 getApplicationWindowLabelLocked(const sp<InputApplicationHandle>& applicationHandle,
-            const sp<InputWindowHandle>& windowHandle);
-
-    // Manage the dispatch cycle for a single connection.
-    // These methods are deliberately not Interruptible because doing all of the work
-    // with the mutex held makes it easier to ensure that connection invariants are maintained.
-    // If needed, the methods post commands to run later once the critical bits are done.
-    void prepareDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
-            EventEntry* eventEntry, const InputTarget* inputTarget);
-    void enqueueDispatchEntriesLocked(nsecs_t currentTime, const sp<Connection>& connection,
-            EventEntry* eventEntry, const InputTarget* inputTarget);
-    void enqueueDispatchEntryLocked(const sp<Connection>& connection,
-            EventEntry* eventEntry, const InputTarget* inputTarget, int32_t dispatchMode);
-    void startDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection);
-    void finishDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
-            uint32_t seq, bool handled);
-    void abortBrokenDispatchCycleLocked(nsecs_t currentTime, const sp<Connection>& connection,
-            bool notify);
-    void drainDispatchQueueLocked(Queue<DispatchEntry>* queue);
-    void releaseDispatchEntryLocked(DispatchEntry* dispatchEntry);
-    static int handleReceiveCallback(int fd, int events, void* data);
-
-    void synthesizeCancelationEventsForAllConnectionsLocked(
-            const CancelationOptions& options);
-    void synthesizeCancelationEventsForInputChannelLocked(const sp<InputChannel>& channel,
-            const CancelationOptions& options);
-    void synthesizeCancelationEventsForConnectionLocked(const sp<Connection>& connection,
-            const CancelationOptions& options);
-
-    // Splitting motion events across windows.
-    MotionEntry* splitMotionEvent(const MotionEntry* originalMotionEntry, BitSet32 pointerIds);
-
-    // Reset and drop everything the dispatcher is doing.
-    void resetAndDropEverythingLocked(const char* reason);
-
-    // Dump state.
-    void dumpDispatchStateLocked(String8& dump);
-    void logDispatchStateLocked();
-
-    // Registration.
-    void removeMonitorChannelLocked(const sp<InputChannel>& inputChannel);
-    status_t unregisterInputChannelLocked(const sp<InputChannel>& inputChannel, bool notify);
-
-    // Add or remove a connection to the mActiveConnections vector.
-    void activateConnectionLocked(Connection* connection);
-    void deactivateConnectionLocked(Connection* connection);
-
-    // Interesting events that we might like to log or tell the framework about.
-    void onDispatchCycleFinishedLocked(
-            nsecs_t currentTime, const sp<Connection>& connection, uint32_t seq, bool handled);
-    void onDispatchCycleBrokenLocked(
-            nsecs_t currentTime, const sp<Connection>& connection);
-    void onANRLocked(
-            nsecs_t currentTime, const sp<InputApplicationHandle>& applicationHandle,
-            const sp<InputWindowHandle>& windowHandle,
-            nsecs_t eventTime, nsecs_t waitStartTime, const char* reason);
-
-    // Outbound policy interactions.
-    void doNotifyConfigurationChangedInterruptible(CommandEntry* commandEntry);
-    void doNotifyInputChannelBrokenLockedInterruptible(CommandEntry* commandEntry);
-    void doNotifyANRLockedInterruptible(CommandEntry* commandEntry);
-    void doInterceptKeyBeforeDispatchingLockedInterruptible(CommandEntry* commandEntry);
-    void doDispatchCycleFinishedLockedInterruptible(CommandEntry* commandEntry);
-    bool afterKeyEventLockedInterruptible(const sp<Connection>& connection,
-            DispatchEntry* dispatchEntry, KeyEntry* keyEntry, bool handled);
-    bool afterMotionEventLockedInterruptible(const sp<Connection>& connection,
-            DispatchEntry* dispatchEntry, MotionEntry* motionEntry, bool handled);
-    void doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry);
-    void initializeKeyEvent(KeyEvent* event, const KeyEntry* entry);
-
-    // Statistics gathering.
-    void updateDispatchStatisticsLocked(nsecs_t currentTime, const EventEntry* entry,
-            int32_t injectionResult, nsecs_t timeSpentWaitingForApplication);
-    void traceInboundQueueLengthLocked();
-    void traceOutboundQueueLengthLocked(const sp<Connection>& connection);
-    void traceWaitQueueLengthLocked(const sp<Connection>& connection);
-};
-
-/* Enqueues and dispatches input events, endlessly. */
-class InputDispatcherThread : public Thread {
-public:
-    explicit InputDispatcherThread(const sp<InputDispatcherInterface>& dispatcher);
-    ~InputDispatcherThread();
-
-private:
-    virtual bool threadLoop();
-
-    sp<InputDispatcherInterface> mDispatcher;
-};
-
-} // namespace android
-
-#endif // _UI_INPUT_DISPATCHER_H
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
deleted file mode 100644
index 03852a5..0000000
--- a/services/input/InputReader.cpp
+++ /dev/null
@@ -1,6530 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#define LOG_TAG "InputReader"
-
-//#define LOG_NDEBUG 0
-
-// Log debug messages for each raw event received from the EventHub.
-#define DEBUG_RAW_EVENTS 0
-
-// Log debug messages about touch screen filtering hacks.
-#define DEBUG_HACKS 0
-
-// Log debug messages about virtual key processing.
-#define DEBUG_VIRTUAL_KEYS 0
-
-// Log debug messages about pointers.
-#define DEBUG_POINTERS 0
-
-// Log debug messages about pointer assignment calculations.
-#define DEBUG_POINTER_ASSIGNMENT 0
-
-// Log debug messages about gesture detection.
-#define DEBUG_GESTURES 0
-
-// Log debug messages about the vibrator.
-#define DEBUG_VIBRATOR 0
-
-#include "InputReader.h"
-
-#include <cutils/log.h>
-#include <input/Keyboard.h>
-#include <input/VirtualKeyMap.h>
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <math.h>
-
-#define INDENT "  "
-#define INDENT2 "    "
-#define INDENT3 "      "
-#define INDENT4 "        "
-#define INDENT5 "          "
-
-namespace android {
-
-// --- Constants ---
-
-// Maximum number of slots supported when using the slot-based Multitouch Protocol B.
-static const size_t MAX_SLOTS = 32;
-
-// --- Static Functions ---
-
-template<typename T>
-inline static T abs(const T& value) {
-    return value < 0 ? - value : value;
-}
-
-template<typename T>
-inline static T min(const T& a, const T& b) {
-    return a < b ? a : b;
-}
-
-template<typename T>
-inline static void swap(T& a, T& b) {
-    T temp = a;
-    a = b;
-    b = temp;
-}
-
-inline static float avg(float x, float y) {
-    return (x + y) / 2;
-}
-
-inline static float distance(float x1, float y1, float x2, float y2) {
-    return hypotf(x1 - x2, y1 - y2);
-}
-
-inline static int32_t signExtendNybble(int32_t value) {
-    return value >= 8 ? value - 16 : value;
-}
-
-static inline const char* toString(bool value) {
-    return value ? "true" : "false";
-}
-
-static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation,
-        const int32_t map[][4], size_t mapSize) {
-    if (orientation != DISPLAY_ORIENTATION_0) {
-        for (size_t i = 0; i < mapSize; i++) {
-            if (value == map[i][0]) {
-                return map[i][orientation];
-            }
-        }
-    }
-    return value;
-}
-
-static const int32_t keyCodeRotationMap[][4] = {
-        // key codes enumerated counter-clockwise with the original (unrotated) key first
-        // no rotation,        90 degree rotation,  180 degree rotation, 270 degree rotation
-        { AKEYCODE_DPAD_DOWN,   AKEYCODE_DPAD_RIGHT,  AKEYCODE_DPAD_UP,     AKEYCODE_DPAD_LEFT },
-        { AKEYCODE_DPAD_RIGHT,  AKEYCODE_DPAD_UP,     AKEYCODE_DPAD_LEFT,   AKEYCODE_DPAD_DOWN },
-        { AKEYCODE_DPAD_UP,     AKEYCODE_DPAD_LEFT,   AKEYCODE_DPAD_DOWN,   AKEYCODE_DPAD_RIGHT },
-        { AKEYCODE_DPAD_LEFT,   AKEYCODE_DPAD_DOWN,   AKEYCODE_DPAD_RIGHT,  AKEYCODE_DPAD_UP },
-};
-static const size_t keyCodeRotationMapSize =
-        sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]);
-
-static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) {
-    return rotateValueUsingRotationMap(keyCode, orientation,
-            keyCodeRotationMap, keyCodeRotationMapSize);
-}
-
-static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) {
-    float temp;
-    switch (orientation) {
-    case DISPLAY_ORIENTATION_90:
-        temp = *deltaX;
-        *deltaX = *deltaY;
-        *deltaY = -temp;
-        break;
-
-    case DISPLAY_ORIENTATION_180:
-        *deltaX = -*deltaX;
-        *deltaY = -*deltaY;
-        break;
-
-    case DISPLAY_ORIENTATION_270:
-        temp = *deltaX;
-        *deltaX = -*deltaY;
-        *deltaY = temp;
-        break;
-    }
-}
-
-static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
-    return (sources & sourceMask & ~ AINPUT_SOURCE_CLASS_MASK) != 0;
-}
-
-// Returns true if the pointer should be reported as being down given the specified
-// button states.  This determines whether the event is reported as a touch event.
-static bool isPointerDown(int32_t buttonState) {
-    return buttonState &
-            (AMOTION_EVENT_BUTTON_PRIMARY | AMOTION_EVENT_BUTTON_SECONDARY
-                    | AMOTION_EVENT_BUTTON_TERTIARY);
-}
-
-static float calculateCommonVector(float a, float b) {
-    if (a > 0 && b > 0) {
-        return a < b ? a : b;
-    } else if (a < 0 && b < 0) {
-        return a > b ? a : b;
-    } else {
-        return 0;
-    }
-}
-
-static void synthesizeButtonKey(InputReaderContext* context, int32_t action,
-        nsecs_t when, int32_t deviceId, uint32_t source,
-        uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState,
-        int32_t buttonState, int32_t keyCode) {
-    if (
-            (action == AKEY_EVENT_ACTION_DOWN
-                    && !(lastButtonState & buttonState)
-                    && (currentButtonState & buttonState))
-            || (action == AKEY_EVENT_ACTION_UP
-                    && (lastButtonState & buttonState)
-                    && !(currentButtonState & buttonState))) {
-        NotifyKeyArgs args(when, deviceId, source, policyFlags,
-                action, 0, keyCode, 0, context->getGlobalMetaState(), when);
-        context->getListener()->notifyKey(&args);
-    }
-}
-
-static void synthesizeButtonKeys(InputReaderContext* context, int32_t action,
-        nsecs_t when, int32_t deviceId, uint32_t source,
-        uint32_t policyFlags, int32_t lastButtonState, int32_t currentButtonState) {
-    synthesizeButtonKey(context, action, when, deviceId, source, policyFlags,
-            lastButtonState, currentButtonState,
-            AMOTION_EVENT_BUTTON_BACK, AKEYCODE_BACK);
-    synthesizeButtonKey(context, action, when, deviceId, source, policyFlags,
-            lastButtonState, currentButtonState,
-            AMOTION_EVENT_BUTTON_FORWARD, AKEYCODE_FORWARD);
-}
-
-
-// --- InputReaderConfiguration ---
-
-bool InputReaderConfiguration::getDisplayInfo(bool external, DisplayViewport* outViewport) const {
-    const DisplayViewport& viewport = external ? mExternalDisplay : mInternalDisplay;
-    if (viewport.displayId >= 0) {
-        *outViewport = viewport;
-        return true;
-    }
-    return false;
-}
-
-void InputReaderConfiguration::setDisplayInfo(bool external, const DisplayViewport& viewport) {
-    DisplayViewport& v = external ? mExternalDisplay : mInternalDisplay;
-    v = viewport;
-}
-
-
-// --- InputReader ---
-
-InputReader::InputReader(const sp<EventHubInterface>& eventHub,
-        const sp<InputReaderPolicyInterface>& policy,
-        const sp<InputListenerInterface>& listener) :
-        mContext(this), mEventHub(eventHub), mPolicy(policy),
-        mGlobalMetaState(0), mGeneration(1),
-        mDisableVirtualKeysTimeout(LLONG_MIN), mNextTimeout(LLONG_MAX),
-        mConfigurationChangesToRefresh(0) {
-    mQueuedListener = new QueuedInputListener(listener);
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        refreshConfigurationLocked(0);
-        updateGlobalMetaStateLocked();
-    } // release lock
-}
-
-InputReader::~InputReader() {
-    for (size_t i = 0; i < mDevices.size(); i++) {
-        delete mDevices.valueAt(i);
-    }
-}
-
-void InputReader::loopOnce() {
-    int32_t oldGeneration;
-    int32_t timeoutMillis;
-    bool inputDevicesChanged = false;
-    Vector<InputDeviceInfo> inputDevices;
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        oldGeneration = mGeneration;
-        timeoutMillis = -1;
-
-        uint32_t changes = mConfigurationChangesToRefresh;
-        if (changes) {
-            mConfigurationChangesToRefresh = 0;
-            timeoutMillis = 0;
-            refreshConfigurationLocked(changes);
-        } else if (mNextTimeout != LLONG_MAX) {
-            nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
-            timeoutMillis = toMillisecondTimeoutDelay(now, mNextTimeout);
-        }
-    } // release lock
-
-    size_t count = mEventHub->getEvents(timeoutMillis, mEventBuffer, EVENT_BUFFER_SIZE);
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-        mReaderIsAliveCondition.broadcast();
-
-        if (count) {
-            processEventsLocked(mEventBuffer, count);
-        }
-
-        if (mNextTimeout != LLONG_MAX) {
-            nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
-            if (now >= mNextTimeout) {
-#if DEBUG_RAW_EVENTS
-                ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
-#endif
-                mNextTimeout = LLONG_MAX;
-                timeoutExpiredLocked(now);
-            }
-        }
-
-        if (oldGeneration != mGeneration) {
-            inputDevicesChanged = true;
-            getInputDevicesLocked(inputDevices);
-        }
-    } // release lock
-
-    // Send out a message that the describes the changed input devices.
-    if (inputDevicesChanged) {
-        mPolicy->notifyInputDevicesChanged(inputDevices);
-    }
-
-    // Flush queued events out to the listener.
-    // This must happen outside of the lock because the listener could potentially call
-    // back into the InputReader's methods, such as getScanCodeState, or become blocked
-    // on another thread similarly waiting to acquire the InputReader lock thereby
-    // resulting in a deadlock.  This situation is actually quite plausible because the
-    // listener is actually the input dispatcher, which calls into the window manager,
-    // which occasionally calls into the input reader.
-    mQueuedListener->flush();
-}
-
-void InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {
-    for (const RawEvent* rawEvent = rawEvents; count;) {
-        int32_t type = rawEvent->type;
-        size_t batchSize = 1;
-        if (type < EventHubInterface::FIRST_SYNTHETIC_EVENT) {
-            int32_t deviceId = rawEvent->deviceId;
-            while (batchSize < count) {
-                if (rawEvent[batchSize].type >= EventHubInterface::FIRST_SYNTHETIC_EVENT
-                        || rawEvent[batchSize].deviceId != deviceId) {
-                    break;
-                }
-                batchSize += 1;
-            }
-#if DEBUG_RAW_EVENTS
-            ALOGD("BatchSize: %d Count: %d", batchSize, count);
-#endif
-            processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
-        } else {
-            switch (rawEvent->type) {
-            case EventHubInterface::DEVICE_ADDED:
-                addDeviceLocked(rawEvent->when, rawEvent->deviceId);
-                break;
-            case EventHubInterface::DEVICE_REMOVED:
-                removeDeviceLocked(rawEvent->when, rawEvent->deviceId);
-                break;
-            case EventHubInterface::FINISHED_DEVICE_SCAN:
-                handleConfigurationChangedLocked(rawEvent->when);
-                break;
-            default:
-                ALOG_ASSERT(false); // can't happen
-                break;
-            }
-        }
-        count -= batchSize;
-        rawEvent += batchSize;
-    }
-}
-
-void InputReader::addDeviceLocked(nsecs_t when, int32_t deviceId) {
-    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-    if (deviceIndex >= 0) {
-        ALOGW("Ignoring spurious device added event for deviceId %d.", deviceId);
-        return;
-    }
-
-    InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(deviceId);
-    uint32_t classes = mEventHub->getDeviceClasses(deviceId);
-    int32_t controllerNumber = mEventHub->getDeviceControllerNumber(deviceId);
-
-    InputDevice* device = createDeviceLocked(deviceId, controllerNumber, identifier, classes);
-    device->configure(when, &mConfig, 0);
-    device->reset(when);
-
-    if (device->isIgnored()) {
-        ALOGI("Device added: id=%d, name='%s' (ignored non-input device)", deviceId,
-                identifier.name.string());
-    } else {
-        ALOGI("Device added: id=%d, name='%s', sources=0x%08x", deviceId,
-                identifier.name.string(), device->getSources());
-    }
-
-    mDevices.add(deviceId, device);
-    bumpGenerationLocked();
-}
-
-void InputReader::removeDeviceLocked(nsecs_t when, int32_t deviceId) {
-    InputDevice* device = NULL;
-    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-    if (deviceIndex < 0) {
-        ALOGW("Ignoring spurious device removed event for deviceId %d.", deviceId);
-        return;
-    }
-
-    device = mDevices.valueAt(deviceIndex);
-    mDevices.removeItemsAt(deviceIndex, 1);
-    bumpGenerationLocked();
-
-    if (device->isIgnored()) {
-        ALOGI("Device removed: id=%d, name='%s' (ignored non-input device)",
-                device->getId(), device->getName().string());
-    } else {
-        ALOGI("Device removed: id=%d, name='%s', sources=0x%08x",
-                device->getId(), device->getName().string(), device->getSources());
-    }
-
-    device->reset(when);
-    delete device;
-}
-
-InputDevice* InputReader::createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
-        const InputDeviceIdentifier& identifier, uint32_t classes) {
-    InputDevice* device = new InputDevice(&mContext, deviceId, bumpGenerationLocked(),
-            controllerNumber, identifier, classes);
-
-    // External devices.
-    if (classes & INPUT_DEVICE_CLASS_EXTERNAL) {
-        device->setExternal(true);
-    }
-
-    // Switch-like devices.
-    if (classes & INPUT_DEVICE_CLASS_SWITCH) {
-        device->addMapper(new SwitchInputMapper(device));
-    }
-
-    // Vibrator-like devices.
-    if (classes & INPUT_DEVICE_CLASS_VIBRATOR) {
-        device->addMapper(new VibratorInputMapper(device));
-    }
-
-    // Keyboard-like devices.
-    uint32_t keyboardSource = 0;
-    int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC;
-    if (classes & INPUT_DEVICE_CLASS_KEYBOARD) {
-        keyboardSource |= AINPUT_SOURCE_KEYBOARD;
-    }
-    if (classes & INPUT_DEVICE_CLASS_ALPHAKEY) {
-        keyboardType = AINPUT_KEYBOARD_TYPE_ALPHABETIC;
-    }
-    if (classes & INPUT_DEVICE_CLASS_DPAD) {
-        keyboardSource |= AINPUT_SOURCE_DPAD;
-    }
-    if (classes & INPUT_DEVICE_CLASS_GAMEPAD) {
-        keyboardSource |= AINPUT_SOURCE_GAMEPAD;
-    }
-
-    if (keyboardSource != 0) {
-        device->addMapper(new KeyboardInputMapper(device, keyboardSource, keyboardType));
-    }
-
-    // Cursor-like devices.
-    if (classes & INPUT_DEVICE_CLASS_CURSOR) {
-        device->addMapper(new CursorInputMapper(device));
-    }
-
-    // Touchscreens and touchpad devices.
-    if (classes & INPUT_DEVICE_CLASS_TOUCH_MT) {
-        device->addMapper(new MultiTouchInputMapper(device));
-    } else if (classes & INPUT_DEVICE_CLASS_TOUCH) {
-        device->addMapper(new SingleTouchInputMapper(device));
-    }
-
-    // Joystick-like devices.
-    if (classes & INPUT_DEVICE_CLASS_JOYSTICK) {
-        device->addMapper(new JoystickInputMapper(device));
-    }
-
-    return device;
-}
-
-void InputReader::processEventsForDeviceLocked(int32_t deviceId,
-        const RawEvent* rawEvents, size_t count) {
-    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-    if (deviceIndex < 0) {
-        ALOGW("Discarding event for unknown deviceId %d.", deviceId);
-        return;
-    }
-
-    InputDevice* device = mDevices.valueAt(deviceIndex);
-    if (device->isIgnored()) {
-        //ALOGD("Discarding event for ignored deviceId %d.", deviceId);
-        return;
-    }
-
-    device->process(rawEvents, count);
-}
-
-void InputReader::timeoutExpiredLocked(nsecs_t when) {
-    for (size_t i = 0; i < mDevices.size(); i++) {
-        InputDevice* device = mDevices.valueAt(i);
-        if (!device->isIgnored()) {
-            device->timeoutExpired(when);
-        }
-    }
-}
-
-void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
-    // Reset global meta state because it depends on the list of all configured devices.
-    updateGlobalMetaStateLocked();
-
-    // Enqueue configuration changed.
-    NotifyConfigurationChangedArgs args(when);
-    mQueuedListener->notifyConfigurationChanged(&args);
-}
-
-void InputReader::refreshConfigurationLocked(uint32_t changes) {
-    mPolicy->getReaderConfiguration(&mConfig);
-    mEventHub->setExcludedDevices(mConfig.excludedDeviceNames);
-
-    if (changes) {
-        ALOGI("Reconfiguring input devices.  changes=0x%08x", changes);
-        nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
-
-        if (changes & InputReaderConfiguration::CHANGE_MUST_REOPEN) {
-            mEventHub->requestReopenDevices();
-        } else {
-            for (size_t i = 0; i < mDevices.size(); i++) {
-                InputDevice* device = mDevices.valueAt(i);
-                device->configure(now, &mConfig, changes);
-            }
-        }
-    }
-}
-
-void InputReader::updateGlobalMetaStateLocked() {
-    mGlobalMetaState = 0;
-
-    for (size_t i = 0; i < mDevices.size(); i++) {
-        InputDevice* device = mDevices.valueAt(i);
-        mGlobalMetaState |= device->getMetaState();
-    }
-}
-
-int32_t InputReader::getGlobalMetaStateLocked() {
-    return mGlobalMetaState;
-}
-
-void InputReader::disableVirtualKeysUntilLocked(nsecs_t time) {
-    mDisableVirtualKeysTimeout = time;
-}
-
-bool InputReader::shouldDropVirtualKeyLocked(nsecs_t now,
-        InputDevice* device, int32_t keyCode, int32_t scanCode) {
-    if (now < mDisableVirtualKeysTimeout) {
-        ALOGI("Dropping virtual key from device %s because virtual keys are "
-                "temporarily disabled for the next %0.3fms.  keyCode=%d, scanCode=%d",
-                device->getName().string(),
-                (mDisableVirtualKeysTimeout - now) * 0.000001,
-                keyCode, scanCode);
-        return true;
-    } else {
-        return false;
-    }
-}
-
-void InputReader::fadePointerLocked() {
-    for (size_t i = 0; i < mDevices.size(); i++) {
-        InputDevice* device = mDevices.valueAt(i);
-        device->fadePointer();
-    }
-}
-
-void InputReader::requestTimeoutAtTimeLocked(nsecs_t when) {
-    if (when < mNextTimeout) {
-        mNextTimeout = when;
-        mEventHub->wake();
-    }
-}
-
-int32_t InputReader::bumpGenerationLocked() {
-    return ++mGeneration;
-}
-
-void InputReader::getInputDevices(Vector<InputDeviceInfo>& outInputDevices) {
-    AutoMutex _l(mLock);
-    getInputDevicesLocked(outInputDevices);
-}
-
-void InputReader::getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices) {
-    outInputDevices.clear();
-
-    size_t numDevices = mDevices.size();
-    for (size_t i = 0; i < numDevices; i++) {
-        InputDevice* device = mDevices.valueAt(i);
-        if (!device->isIgnored()) {
-            outInputDevices.push();
-            device->getDeviceInfo(&outInputDevices.editTop());
-        }
-    }
-}
-
-int32_t InputReader::getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
-        int32_t keyCode) {
-    AutoMutex _l(mLock);
-
-    return getStateLocked(deviceId, sourceMask, keyCode, &InputDevice::getKeyCodeState);
-}
-
-int32_t InputReader::getScanCodeState(int32_t deviceId, uint32_t sourceMask,
-        int32_t scanCode) {
-    AutoMutex _l(mLock);
-
-    return getStateLocked(deviceId, sourceMask, scanCode, &InputDevice::getScanCodeState);
-}
-
-int32_t InputReader::getSwitchState(int32_t deviceId, uint32_t sourceMask, int32_t switchCode) {
-    AutoMutex _l(mLock);
-
-    return getStateLocked(deviceId, sourceMask, switchCode, &InputDevice::getSwitchState);
-}
-
-int32_t InputReader::getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
-        GetStateFunc getStateFunc) {
-    int32_t result = AKEY_STATE_UNKNOWN;
-    if (deviceId >= 0) {
-        ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-        if (deviceIndex >= 0) {
-            InputDevice* device = mDevices.valueAt(deviceIndex);
-            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
-                result = (device->*getStateFunc)(sourceMask, code);
-            }
-        }
-    } else {
-        size_t numDevices = mDevices.size();
-        for (size_t i = 0; i < numDevices; i++) {
-            InputDevice* device = mDevices.valueAt(i);
-            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
-                // If any device reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
-                // value.  Otherwise, return AKEY_STATE_UP as long as one device reports it.
-                int32_t currentResult = (device->*getStateFunc)(sourceMask, code);
-                if (currentResult >= AKEY_STATE_DOWN) {
-                    return currentResult;
-                } else if (currentResult == AKEY_STATE_UP) {
-                    result = currentResult;
-                }
-            }
-        }
-    }
-    return result;
-}
-
-bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask,
-        size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) {
-    AutoMutex _l(mLock);
-
-    memset(outFlags, 0, numCodes);
-    return markSupportedKeyCodesLocked(deviceId, sourceMask, numCodes, keyCodes, outFlags);
-}
-
-bool InputReader::markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask,
-        size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) {
-    bool result = false;
-    if (deviceId >= 0) {
-        ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-        if (deviceIndex >= 0) {
-            InputDevice* device = mDevices.valueAt(deviceIndex);
-            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
-                result = device->markSupportedKeyCodes(sourceMask,
-                        numCodes, keyCodes, outFlags);
-            }
-        }
-    } else {
-        size_t numDevices = mDevices.size();
-        for (size_t i = 0; i < numDevices; i++) {
-            InputDevice* device = mDevices.valueAt(i);
-            if (! device->isIgnored() && sourcesMatchMask(device->getSources(), sourceMask)) {
-                result |= device->markSupportedKeyCodes(sourceMask,
-                        numCodes, keyCodes, outFlags);
-            }
-        }
-    }
-    return result;
-}
-
-void InputReader::requestRefreshConfiguration(uint32_t changes) {
-    AutoMutex _l(mLock);
-
-    if (changes) {
-        bool needWake = !mConfigurationChangesToRefresh;
-        mConfigurationChangesToRefresh |= changes;
-
-        if (needWake) {
-            mEventHub->wake();
-        }
-    }
-}
-
-void InputReader::vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
-        ssize_t repeat, int32_t token) {
-    AutoMutex _l(mLock);
-
-    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-    if (deviceIndex >= 0) {
-        InputDevice* device = mDevices.valueAt(deviceIndex);
-        device->vibrate(pattern, patternSize, repeat, token);
-    }
-}
-
-void InputReader::cancelVibrate(int32_t deviceId, int32_t token) {
-    AutoMutex _l(mLock);
-
-    ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
-    if (deviceIndex >= 0) {
-        InputDevice* device = mDevices.valueAt(deviceIndex);
-        device->cancelVibrate(token);
-    }
-}
-
-void InputReader::dump(String8& dump) {
-    AutoMutex _l(mLock);
-
-    mEventHub->dump(dump);
-    dump.append("\n");
-
-    dump.append("Input Reader State:\n");
-
-    for (size_t i = 0; i < mDevices.size(); i++) {
-        mDevices.valueAt(i)->dump(dump);
-    }
-
-    dump.append(INDENT "Configuration:\n");
-    dump.append(INDENT2 "ExcludedDeviceNames: [");
-    for (size_t i = 0; i < mConfig.excludedDeviceNames.size(); i++) {
-        if (i != 0) {
-            dump.append(", ");
-        }
-        dump.append(mConfig.excludedDeviceNames.itemAt(i).string());
-    }
-    dump.append("]\n");
-    dump.appendFormat(INDENT2 "VirtualKeyQuietTime: %0.1fms\n",
-            mConfig.virtualKeyQuietTime * 0.000001f);
-
-    dump.appendFormat(INDENT2 "PointerVelocityControlParameters: "
-            "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n",
-            mConfig.pointerVelocityControlParameters.scale,
-            mConfig.pointerVelocityControlParameters.lowThreshold,
-            mConfig.pointerVelocityControlParameters.highThreshold,
-            mConfig.pointerVelocityControlParameters.acceleration);
-
-    dump.appendFormat(INDENT2 "WheelVelocityControlParameters: "
-            "scale=%0.3f, lowThreshold=%0.3f, highThreshold=%0.3f, acceleration=%0.3f\n",
-            mConfig.wheelVelocityControlParameters.scale,
-            mConfig.wheelVelocityControlParameters.lowThreshold,
-            mConfig.wheelVelocityControlParameters.highThreshold,
-            mConfig.wheelVelocityControlParameters.acceleration);
-
-    dump.appendFormat(INDENT2 "PointerGesture:\n");
-    dump.appendFormat(INDENT3 "Enabled: %s\n",
-            toString(mConfig.pointerGesturesEnabled));
-    dump.appendFormat(INDENT3 "QuietInterval: %0.1fms\n",
-            mConfig.pointerGestureQuietInterval * 0.000001f);
-    dump.appendFormat(INDENT3 "DragMinSwitchSpeed: %0.1fpx/s\n",
-            mConfig.pointerGestureDragMinSwitchSpeed);
-    dump.appendFormat(INDENT3 "TapInterval: %0.1fms\n",
-            mConfig.pointerGestureTapInterval * 0.000001f);
-    dump.appendFormat(INDENT3 "TapDragInterval: %0.1fms\n",
-            mConfig.pointerGestureTapDragInterval * 0.000001f);
-    dump.appendFormat(INDENT3 "TapSlop: %0.1fpx\n",
-            mConfig.pointerGestureTapSlop);
-    dump.appendFormat(INDENT3 "MultitouchSettleInterval: %0.1fms\n",
-            mConfig.pointerGestureMultitouchSettleInterval * 0.000001f);
-    dump.appendFormat(INDENT3 "MultitouchMinDistance: %0.1fpx\n",
-            mConfig.pointerGestureMultitouchMinDistance);
-    dump.appendFormat(INDENT3 "SwipeTransitionAngleCosine: %0.1f\n",
-            mConfig.pointerGestureSwipeTransitionAngleCosine);
-    dump.appendFormat(INDENT3 "SwipeMaxWidthRatio: %0.1f\n",
-            mConfig.pointerGestureSwipeMaxWidthRatio);
-    dump.appendFormat(INDENT3 "MovementSpeedRatio: %0.1f\n",
-            mConfig.pointerGestureMovementSpeedRatio);
-    dump.appendFormat(INDENT3 "ZoomSpeedRatio: %0.1f\n",
-            mConfig.pointerGestureZoomSpeedRatio);
-}
-
-void InputReader::monitor() {
-    // Acquire and release the lock to ensure that the reader has not deadlocked.
-    mLock.lock();
-    mEventHub->wake();
-    mReaderIsAliveCondition.wait(mLock);
-    mLock.unlock();
-
-    // Check the EventHub
-    mEventHub->monitor();
-}
-
-
-// --- InputReader::ContextImpl ---
-
-InputReader::ContextImpl::ContextImpl(InputReader* reader) :
-        mReader(reader) {
-}
-
-void InputReader::ContextImpl::updateGlobalMetaState() {
-    // lock is already held by the input loop
-    mReader->updateGlobalMetaStateLocked();
-}
-
-int32_t InputReader::ContextImpl::getGlobalMetaState() {
-    // lock is already held by the input loop
-    return mReader->getGlobalMetaStateLocked();
-}
-
-void InputReader::ContextImpl::disableVirtualKeysUntil(nsecs_t time) {
-    // lock is already held by the input loop
-    mReader->disableVirtualKeysUntilLocked(time);
-}
-
-bool InputReader::ContextImpl::shouldDropVirtualKey(nsecs_t now,
-        InputDevice* device, int32_t keyCode, int32_t scanCode) {
-    // lock is already held by the input loop
-    return mReader->shouldDropVirtualKeyLocked(now, device, keyCode, scanCode);
-}
-
-void InputReader::ContextImpl::fadePointer() {
-    // lock is already held by the input loop
-    mReader->fadePointerLocked();
-}
-
-void InputReader::ContextImpl::requestTimeoutAtTime(nsecs_t when) {
-    // lock is already held by the input loop
-    mReader->requestTimeoutAtTimeLocked(when);
-}
-
-int32_t InputReader::ContextImpl::bumpGeneration() {
-    // lock is already held by the input loop
-    return mReader->bumpGenerationLocked();
-}
-
-InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
-    return mReader->mPolicy.get();
-}
-
-InputListenerInterface* InputReader::ContextImpl::getListener() {
-    return mReader->mQueuedListener.get();
-}
-
-EventHubInterface* InputReader::ContextImpl::getEventHub() {
-    return mReader->mEventHub.get();
-}
-
-
-// --- InputReaderThread ---
-
-InputReaderThread::InputReaderThread(const sp<InputReaderInterface>& reader) :
-        Thread(/*canCallJava*/ true), mReader(reader) {
-}
-
-InputReaderThread::~InputReaderThread() {
-}
-
-bool InputReaderThread::threadLoop() {
-    mReader->loopOnce();
-    return true;
-}
-
-
-// --- InputDevice ---
-
-InputDevice::InputDevice(InputReaderContext* context, int32_t id, int32_t generation,
-        int32_t controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes) :
-        mContext(context), mId(id), mGeneration(generation), mControllerNumber(controllerNumber),
-        mIdentifier(identifier), mClasses(classes),
-        mSources(0), mIsExternal(false), mDropUntilNextSync(false) {
-}
-
-InputDevice::~InputDevice() {
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        delete mMappers[i];
-    }
-    mMappers.clear();
-}
-
-void InputDevice::dump(String8& dump) {
-    InputDeviceInfo deviceInfo;
-    getDeviceInfo(& deviceInfo);
-
-    dump.appendFormat(INDENT "Device %d: %s\n", deviceInfo.getId(),
-            deviceInfo.getDisplayName().string());
-    dump.appendFormat(INDENT2 "Generation: %d\n", mGeneration);
-    dump.appendFormat(INDENT2 "IsExternal: %s\n", toString(mIsExternal));
-    dump.appendFormat(INDENT2 "Sources: 0x%08x\n", deviceInfo.getSources());
-    dump.appendFormat(INDENT2 "KeyboardType: %d\n", deviceInfo.getKeyboardType());
-
-    const Vector<InputDeviceInfo::MotionRange>& ranges = deviceInfo.getMotionRanges();
-    if (!ranges.isEmpty()) {
-        dump.append(INDENT2 "Motion Ranges:\n");
-        for (size_t i = 0; i < ranges.size(); i++) {
-            const InputDeviceInfo::MotionRange& range = ranges.itemAt(i);
-            const char* label = getAxisLabel(range.axis);
-            char name[32];
-            if (label) {
-                strncpy(name, label, sizeof(name));
-                name[sizeof(name) - 1] = '\0';
-            } else {
-                snprintf(name, sizeof(name), "%d", range.axis);
-            }
-            dump.appendFormat(INDENT3 "%s: source=0x%08x, "
-                    "min=%0.3f, max=%0.3f, flat=%0.3f, fuzz=%0.3f, resolution=%0.3f\n",
-                    name, range.source, range.min, range.max, range.flat, range.fuzz,
-                    range.resolution);
-        }
-    }
-
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->dump(dump);
-    }
-}
-
-void InputDevice::addMapper(InputMapper* mapper) {
-    mMappers.add(mapper);
-}
-
-void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) {
-    mSources = 0;
-
-    if (!isIgnored()) {
-        if (!changes) { // first time only
-            mContext->getEventHub()->getConfiguration(mId, &mConfiguration);
-        }
-
-        if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) {
-            if (!(mClasses & INPUT_DEVICE_CLASS_VIRTUAL)) {
-                sp<KeyCharacterMap> keyboardLayout =
-                        mContext->getPolicy()->getKeyboardLayoutOverlay(mIdentifier.descriptor);
-                if (mContext->getEventHub()->setKeyboardLayoutOverlay(mId, keyboardLayout)) {
-                    bumpGeneration();
-                }
-            }
-        }
-
-        if (!changes || (changes & InputReaderConfiguration::CHANGE_DEVICE_ALIAS)) {
-            if (!(mClasses & INPUT_DEVICE_CLASS_VIRTUAL)) {
-                String8 alias = mContext->getPolicy()->getDeviceAlias(mIdentifier);
-                if (mAlias != alias) {
-                    mAlias = alias;
-                    bumpGeneration();
-                }
-            }
-        }
-
-        size_t numMappers = mMappers.size();
-        for (size_t i = 0; i < numMappers; i++) {
-            InputMapper* mapper = mMappers[i];
-            mapper->configure(when, config, changes);
-            mSources |= mapper->getSources();
-        }
-    }
-}
-
-void InputDevice::reset(nsecs_t when) {
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->reset(when);
-    }
-
-    mContext->updateGlobalMetaState();
-
-    notifyReset(when);
-}
-
-void InputDevice::process(const RawEvent* rawEvents, size_t count) {
-    // Process all of the events in order for each mapper.
-    // We cannot simply ask each mapper to process them in bulk because mappers may
-    // have side-effects that must be interleaved.  For example, joystick movement events and
-    // gamepad button presses are handled by different mappers but they should be dispatched
-    // in the order received.
-    size_t numMappers = mMappers.size();
-    for (const RawEvent* rawEvent = rawEvents; count--; rawEvent++) {
-#if DEBUG_RAW_EVENTS
-        ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%lld",
-                rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
-                rawEvent->when);
-#endif
-
-        if (mDropUntilNextSync) {
-            if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
-                mDropUntilNextSync = false;
-#if DEBUG_RAW_EVENTS
-                ALOGD("Recovered from input event buffer overrun.");
-#endif
-            } else {
-#if DEBUG_RAW_EVENTS
-                ALOGD("Dropped input event while waiting for next input sync.");
-#endif
-            }
-        } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_DROPPED) {
-            ALOGI("Detected input event buffer overrun for device %s.", getName().string());
-            mDropUntilNextSync = true;
-            reset(rawEvent->when);
-        } else {
-            for (size_t i = 0; i < numMappers; i++) {
-                InputMapper* mapper = mMappers[i];
-                mapper->process(rawEvent);
-            }
-        }
-    }
-}
-
-void InputDevice::timeoutExpired(nsecs_t when) {
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->timeoutExpired(when);
-    }
-}
-
-void InputDevice::getDeviceInfo(InputDeviceInfo* outDeviceInfo) {
-    outDeviceInfo->initialize(mId, mGeneration, mControllerNumber, mIdentifier, mAlias,
-            mIsExternal);
-
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->populateDeviceInfo(outDeviceInfo);
-    }
-}
-
-int32_t InputDevice::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
-    return getState(sourceMask, keyCode, & InputMapper::getKeyCodeState);
-}
-
-int32_t InputDevice::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
-    return getState(sourceMask, scanCode, & InputMapper::getScanCodeState);
-}
-
-int32_t InputDevice::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
-    return getState(sourceMask, switchCode, & InputMapper::getSwitchState);
-}
-
-int32_t InputDevice::getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc) {
-    int32_t result = AKEY_STATE_UNKNOWN;
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        if (sourcesMatchMask(mapper->getSources(), sourceMask)) {
-            // If any mapper reports AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL, return that
-            // value.  Otherwise, return AKEY_STATE_UP as long as one mapper reports it.
-            int32_t currentResult = (mapper->*getStateFunc)(sourceMask, code);
-            if (currentResult >= AKEY_STATE_DOWN) {
-                return currentResult;
-            } else if (currentResult == AKEY_STATE_UP) {
-                result = currentResult;
-            }
-        }
-    }
-    return result;
-}
-
-bool InputDevice::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-        const int32_t* keyCodes, uint8_t* outFlags) {
-    bool result = false;
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        if (sourcesMatchMask(mapper->getSources(), sourceMask)) {
-            result |= mapper->markSupportedKeyCodes(sourceMask, numCodes, keyCodes, outFlags);
-        }
-    }
-    return result;
-}
-
-void InputDevice::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
-        int32_t token) {
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->vibrate(pattern, patternSize, repeat, token);
-    }
-}
-
-void InputDevice::cancelVibrate(int32_t token) {
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->cancelVibrate(token);
-    }
-}
-
-int32_t InputDevice::getMetaState() {
-    int32_t result = 0;
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        result |= mapper->getMetaState();
-    }
-    return result;
-}
-
-void InputDevice::fadePointer() {
-    size_t numMappers = mMappers.size();
-    for (size_t i = 0; i < numMappers; i++) {
-        InputMapper* mapper = mMappers[i];
-        mapper->fadePointer();
-    }
-}
-
-void InputDevice::bumpGeneration() {
-    mGeneration = mContext->bumpGeneration();
-}
-
-void InputDevice::notifyReset(nsecs_t when) {
-    NotifyDeviceResetArgs args(when, mId);
-    mContext->getListener()->notifyDeviceReset(&args);
-}
-
-
-// --- CursorButtonAccumulator ---
-
-CursorButtonAccumulator::CursorButtonAccumulator() {
-    clearButtons();
-}
-
-void CursorButtonAccumulator::reset(InputDevice* device) {
-    mBtnLeft = device->isKeyPressed(BTN_LEFT);
-    mBtnRight = device->isKeyPressed(BTN_RIGHT);
-    mBtnMiddle = device->isKeyPressed(BTN_MIDDLE);
-    mBtnBack = device->isKeyPressed(BTN_BACK);
-    mBtnSide = device->isKeyPressed(BTN_SIDE);
-    mBtnForward = device->isKeyPressed(BTN_FORWARD);
-    mBtnExtra = device->isKeyPressed(BTN_EXTRA);
-    mBtnTask = device->isKeyPressed(BTN_TASK);
-}
-
-void CursorButtonAccumulator::clearButtons() {
-    mBtnLeft = 0;
-    mBtnRight = 0;
-    mBtnMiddle = 0;
-    mBtnBack = 0;
-    mBtnSide = 0;
-    mBtnForward = 0;
-    mBtnExtra = 0;
-    mBtnTask = 0;
-}
-
-void CursorButtonAccumulator::process(const RawEvent* rawEvent) {
-    if (rawEvent->type == EV_KEY) {
-        switch (rawEvent->code) {
-        case BTN_LEFT:
-            mBtnLeft = rawEvent->value;
-            break;
-        case BTN_RIGHT:
-            mBtnRight = rawEvent->value;
-            break;
-        case BTN_MIDDLE:
-            mBtnMiddle = rawEvent->value;
-            break;
-        case BTN_BACK:
-            mBtnBack = rawEvent->value;
-            break;
-        case BTN_SIDE:
-            mBtnSide = rawEvent->value;
-            break;
-        case BTN_FORWARD:
-            mBtnForward = rawEvent->value;
-            break;
-        case BTN_EXTRA:
-            mBtnExtra = rawEvent->value;
-            break;
-        case BTN_TASK:
-            mBtnTask = rawEvent->value;
-            break;
-        }
-    }
-}
-
-uint32_t CursorButtonAccumulator::getButtonState() const {
-    uint32_t result = 0;
-    if (mBtnLeft) {
-        result |= AMOTION_EVENT_BUTTON_PRIMARY;
-    }
-    if (mBtnRight) {
-        result |= AMOTION_EVENT_BUTTON_SECONDARY;
-    }
-    if (mBtnMiddle) {
-        result |= AMOTION_EVENT_BUTTON_TERTIARY;
-    }
-    if (mBtnBack || mBtnSide) {
-        result |= AMOTION_EVENT_BUTTON_BACK;
-    }
-    if (mBtnForward || mBtnExtra) {
-        result |= AMOTION_EVENT_BUTTON_FORWARD;
-    }
-    return result;
-}
-
-
-// --- CursorMotionAccumulator ---
-
-CursorMotionAccumulator::CursorMotionAccumulator() {
-    clearRelativeAxes();
-}
-
-void CursorMotionAccumulator::reset(InputDevice* device) {
-    clearRelativeAxes();
-}
-
-void CursorMotionAccumulator::clearRelativeAxes() {
-    mRelX = 0;
-    mRelY = 0;
-}
-
-void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
-    if (rawEvent->type == EV_REL) {
-        switch (rawEvent->code) {
-        case REL_X:
-            mRelX = rawEvent->value;
-            break;
-        case REL_Y:
-            mRelY = rawEvent->value;
-            break;
-        }
-    }
-}
-
-void CursorMotionAccumulator::finishSync() {
-    clearRelativeAxes();
-}
-
-
-// --- CursorScrollAccumulator ---
-
-CursorScrollAccumulator::CursorScrollAccumulator() :
-        mHaveRelWheel(false), mHaveRelHWheel(false) {
-    clearRelativeAxes();
-}
-
-void CursorScrollAccumulator::configure(InputDevice* device) {
-    mHaveRelWheel = device->getEventHub()->hasRelativeAxis(device->getId(), REL_WHEEL);
-    mHaveRelHWheel = device->getEventHub()->hasRelativeAxis(device->getId(), REL_HWHEEL);
-}
-
-void CursorScrollAccumulator::reset(InputDevice* device) {
-    clearRelativeAxes();
-}
-
-void CursorScrollAccumulator::clearRelativeAxes() {
-    mRelWheel = 0;
-    mRelHWheel = 0;
-}
-
-void CursorScrollAccumulator::process(const RawEvent* rawEvent) {
-    if (rawEvent->type == EV_REL) {
-        switch (rawEvent->code) {
-        case REL_WHEEL:
-            mRelWheel = rawEvent->value;
-            break;
-        case REL_HWHEEL:
-            mRelHWheel = rawEvent->value;
-            break;
-        }
-    }
-}
-
-void CursorScrollAccumulator::finishSync() {
-    clearRelativeAxes();
-}
-
-
-// --- TouchButtonAccumulator ---
-
-TouchButtonAccumulator::TouchButtonAccumulator() :
-        mHaveBtnTouch(false), mHaveStylus(false) {
-    clearButtons();
-}
-
-void TouchButtonAccumulator::configure(InputDevice* device) {
-    mHaveBtnTouch = device->hasKey(BTN_TOUCH);
-    mHaveStylus = device->hasKey(BTN_TOOL_PEN)
-            || device->hasKey(BTN_TOOL_RUBBER)
-            || device->hasKey(BTN_TOOL_BRUSH)
-            || device->hasKey(BTN_TOOL_PENCIL)
-            || device->hasKey(BTN_TOOL_AIRBRUSH);
-}
-
-void TouchButtonAccumulator::reset(InputDevice* device) {
-    mBtnTouch = device->isKeyPressed(BTN_TOUCH);
-    mBtnStylus = device->isKeyPressed(BTN_STYLUS);
-    mBtnStylus2 = device->isKeyPressed(BTN_STYLUS);
-    mBtnToolFinger = device->isKeyPressed(BTN_TOOL_FINGER);
-    mBtnToolPen = device->isKeyPressed(BTN_TOOL_PEN);
-    mBtnToolRubber = device->isKeyPressed(BTN_TOOL_RUBBER);
-    mBtnToolBrush = device->isKeyPressed(BTN_TOOL_BRUSH);
-    mBtnToolPencil = device->isKeyPressed(BTN_TOOL_PENCIL);
-    mBtnToolAirbrush = device->isKeyPressed(BTN_TOOL_AIRBRUSH);
-    mBtnToolMouse = device->isKeyPressed(BTN_TOOL_MOUSE);
-    mBtnToolLens = device->isKeyPressed(BTN_TOOL_LENS);
-    mBtnToolDoubleTap = device->isKeyPressed(BTN_TOOL_DOUBLETAP);
-    mBtnToolTripleTap = device->isKeyPressed(BTN_TOOL_TRIPLETAP);
-    mBtnToolQuadTap = device->isKeyPressed(BTN_TOOL_QUADTAP);
-}
-
-void TouchButtonAccumulator::clearButtons() {
-    mBtnTouch = 0;
-    mBtnStylus = 0;
-    mBtnStylus2 = 0;
-    mBtnToolFinger = 0;
-    mBtnToolPen = 0;
-    mBtnToolRubber = 0;
-    mBtnToolBrush = 0;
-    mBtnToolPencil = 0;
-    mBtnToolAirbrush = 0;
-    mBtnToolMouse = 0;
-    mBtnToolLens = 0;
-    mBtnToolDoubleTap = 0;
-    mBtnToolTripleTap = 0;
-    mBtnToolQuadTap = 0;
-}
-
-void TouchButtonAccumulator::process(const RawEvent* rawEvent) {
-    if (rawEvent->type == EV_KEY) {
-        switch (rawEvent->code) {
-        case BTN_TOUCH:
-            mBtnTouch = rawEvent->value;
-            break;
-        case BTN_STYLUS:
-            mBtnStylus = rawEvent->value;
-            break;
-        case BTN_STYLUS2:
-            mBtnStylus2 = rawEvent->value;
-            break;
-        case BTN_TOOL_FINGER:
-            mBtnToolFinger = rawEvent->value;
-            break;
-        case BTN_TOOL_PEN:
-            mBtnToolPen = rawEvent->value;
-            break;
-        case BTN_TOOL_RUBBER:
-            mBtnToolRubber = rawEvent->value;
-            break;
-        case BTN_TOOL_BRUSH:
-            mBtnToolBrush = rawEvent->value;
-            break;
-        case BTN_TOOL_PENCIL:
-            mBtnToolPencil = rawEvent->value;
-            break;
-        case BTN_TOOL_AIRBRUSH:
-            mBtnToolAirbrush = rawEvent->value;
-            break;
-        case BTN_TOOL_MOUSE:
-            mBtnToolMouse = rawEvent->value;
-            break;
-        case BTN_TOOL_LENS:
-            mBtnToolLens = rawEvent->value;
-            break;
-        case BTN_TOOL_DOUBLETAP:
-            mBtnToolDoubleTap = rawEvent->value;
-            break;
-        case BTN_TOOL_TRIPLETAP:
-            mBtnToolTripleTap = rawEvent->value;
-            break;
-        case BTN_TOOL_QUADTAP:
-            mBtnToolQuadTap = rawEvent->value;
-            break;
-        }
-    }
-}
-
-uint32_t TouchButtonAccumulator::getButtonState() const {
-    uint32_t result = 0;
-    if (mBtnStylus) {
-        result |= AMOTION_EVENT_BUTTON_SECONDARY;
-    }
-    if (mBtnStylus2) {
-        result |= AMOTION_EVENT_BUTTON_TERTIARY;
-    }
-    return result;
-}
-
-int32_t TouchButtonAccumulator::getToolType() const {
-    if (mBtnToolMouse || mBtnToolLens) {
-        return AMOTION_EVENT_TOOL_TYPE_MOUSE;
-    }
-    if (mBtnToolRubber) {
-        return AMOTION_EVENT_TOOL_TYPE_ERASER;
-    }
-    if (mBtnToolPen || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush) {
-        return AMOTION_EVENT_TOOL_TYPE_STYLUS;
-    }
-    if (mBtnToolFinger || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap) {
-        return AMOTION_EVENT_TOOL_TYPE_FINGER;
-    }
-    return AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
-}
-
-bool TouchButtonAccumulator::isToolActive() const {
-    return mBtnTouch || mBtnToolFinger || mBtnToolPen || mBtnToolRubber
-            || mBtnToolBrush || mBtnToolPencil || mBtnToolAirbrush
-            || mBtnToolMouse || mBtnToolLens
-            || mBtnToolDoubleTap || mBtnToolTripleTap || mBtnToolQuadTap;
-}
-
-bool TouchButtonAccumulator::isHovering() const {
-    return mHaveBtnTouch && !mBtnTouch;
-}
-
-bool TouchButtonAccumulator::hasStylus() const {
-    return mHaveStylus;
-}
-
-
-// --- RawPointerAxes ---
-
-RawPointerAxes::RawPointerAxes() {
-    clear();
-}
-
-void RawPointerAxes::clear() {
-    x.clear();
-    y.clear();
-    pressure.clear();
-    touchMajor.clear();
-    touchMinor.clear();
-    toolMajor.clear();
-    toolMinor.clear();
-    orientation.clear();
-    distance.clear();
-    tiltX.clear();
-    tiltY.clear();
-    trackingId.clear();
-    slot.clear();
-}
-
-
-// --- RawPointerData ---
-
-RawPointerData::RawPointerData() {
-    clear();
-}
-
-void RawPointerData::clear() {
-    pointerCount = 0;
-    clearIdBits();
-}
-
-void RawPointerData::copyFrom(const RawPointerData& other) {
-    pointerCount = other.pointerCount;
-    hoveringIdBits = other.hoveringIdBits;
-    touchingIdBits = other.touchingIdBits;
-
-    for (uint32_t i = 0; i < pointerCount; i++) {
-        pointers[i] = other.pointers[i];
-
-        int id = pointers[i].id;
-        idToIndex[id] = other.idToIndex[id];
-    }
-}
-
-void RawPointerData::getCentroidOfTouchingPointers(float* outX, float* outY) const {
-    float x = 0, y = 0;
-    uint32_t count = touchingIdBits.count();
-    if (count) {
-        for (BitSet32 idBits(touchingIdBits); !idBits.isEmpty(); ) {
-            uint32_t id = idBits.clearFirstMarkedBit();
-            const Pointer& pointer = pointerForId(id);
-            x += pointer.x;
-            y += pointer.y;
-        }
-        x /= count;
-        y /= count;
-    }
-    *outX = x;
-    *outY = y;
-}
-
-
-// --- CookedPointerData ---
-
-CookedPointerData::CookedPointerData() {
-    clear();
-}
-
-void CookedPointerData::clear() {
-    pointerCount = 0;
-    hoveringIdBits.clear();
-    touchingIdBits.clear();
-}
-
-void CookedPointerData::copyFrom(const CookedPointerData& other) {
-    pointerCount = other.pointerCount;
-    hoveringIdBits = other.hoveringIdBits;
-    touchingIdBits = other.touchingIdBits;
-
-    for (uint32_t i = 0; i < pointerCount; i++) {
-        pointerProperties[i].copyFrom(other.pointerProperties[i]);
-        pointerCoords[i].copyFrom(other.pointerCoords[i]);
-
-        int id = pointerProperties[i].id;
-        idToIndex[id] = other.idToIndex[id];
-    }
-}
-
-
-// --- SingleTouchMotionAccumulator ---
-
-SingleTouchMotionAccumulator::SingleTouchMotionAccumulator() {
-    clearAbsoluteAxes();
-}
-
-void SingleTouchMotionAccumulator::reset(InputDevice* device) {
-    mAbsX = device->getAbsoluteAxisValue(ABS_X);
-    mAbsY = device->getAbsoluteAxisValue(ABS_Y);
-    mAbsPressure = device->getAbsoluteAxisValue(ABS_PRESSURE);
-    mAbsToolWidth = device->getAbsoluteAxisValue(ABS_TOOL_WIDTH);
-    mAbsDistance = device->getAbsoluteAxisValue(ABS_DISTANCE);
-    mAbsTiltX = device->getAbsoluteAxisValue(ABS_TILT_X);
-    mAbsTiltY = device->getAbsoluteAxisValue(ABS_TILT_Y);
-}
-
-void SingleTouchMotionAccumulator::clearAbsoluteAxes() {
-    mAbsX = 0;
-    mAbsY = 0;
-    mAbsPressure = 0;
-    mAbsToolWidth = 0;
-    mAbsDistance = 0;
-    mAbsTiltX = 0;
-    mAbsTiltY = 0;
-}
-
-void SingleTouchMotionAccumulator::process(const RawEvent* rawEvent) {
-    if (rawEvent->type == EV_ABS) {
-        switch (rawEvent->code) {
-        case ABS_X:
-            mAbsX = rawEvent->value;
-            break;
-        case ABS_Y:
-            mAbsY = rawEvent->value;
-            break;
-        case ABS_PRESSURE:
-            mAbsPressure = rawEvent->value;
-            break;
-        case ABS_TOOL_WIDTH:
-            mAbsToolWidth = rawEvent->value;
-            break;
-        case ABS_DISTANCE:
-            mAbsDistance = rawEvent->value;
-            break;
-        case ABS_TILT_X:
-            mAbsTiltX = rawEvent->value;
-            break;
-        case ABS_TILT_Y:
-            mAbsTiltY = rawEvent->value;
-            break;
-        }
-    }
-}
-
-
-// --- MultiTouchMotionAccumulator ---
-
-MultiTouchMotionAccumulator::MultiTouchMotionAccumulator() :
-        mCurrentSlot(-1), mSlots(NULL), mSlotCount(0), mUsingSlotsProtocol(false),
-        mHaveStylus(false) {
-}
-
-MultiTouchMotionAccumulator::~MultiTouchMotionAccumulator() {
-    delete[] mSlots;
-}
-
-void MultiTouchMotionAccumulator::configure(InputDevice* device,
-        size_t slotCount, bool usingSlotsProtocol) {
-    mSlotCount = slotCount;
-    mUsingSlotsProtocol = usingSlotsProtocol;
-    mHaveStylus = device->hasAbsoluteAxis(ABS_MT_TOOL_TYPE);
-
-    delete[] mSlots;
-    mSlots = new Slot[slotCount];
-}
-
-void MultiTouchMotionAccumulator::reset(InputDevice* device) {
-    // Unfortunately there is no way to read the initial contents of the slots.
-    // So when we reset the accumulator, we must assume they are all zeroes.
-    if (mUsingSlotsProtocol) {
-        // Query the driver for the current slot index and use it as the initial slot
-        // before we start reading events from the device.  It is possible that the
-        // current slot index will not be the same as it was when the first event was
-        // written into the evdev buffer, which means the input mapper could start
-        // out of sync with the initial state of the events in the evdev buffer.
-        // In the extremely unlikely case that this happens, the data from
-        // two slots will be confused until the next ABS_MT_SLOT event is received.
-        // This can cause the touch point to "jump", but at least there will be
-        // no stuck touches.
-        int32_t initialSlot;
-        status_t status = device->getEventHub()->getAbsoluteAxisValue(device->getId(),
-                ABS_MT_SLOT, &initialSlot);
-        if (status) {
-            ALOGD("Could not retrieve current multitouch slot index.  status=%d", status);
-            initialSlot = -1;
-        }
-        clearSlots(initialSlot);
-    } else {
-        clearSlots(-1);
-    }
-}
-
-void MultiTouchMotionAccumulator::clearSlots(int32_t initialSlot) {
-    if (mSlots) {
-        for (size_t i = 0; i < mSlotCount; i++) {
-            mSlots[i].clear();
-        }
-    }
-    mCurrentSlot = initialSlot;
-}
-
-void MultiTouchMotionAccumulator::process(const RawEvent* rawEvent) {
-    if (rawEvent->type == EV_ABS) {
-        bool newSlot = false;
-        if (mUsingSlotsProtocol) {
-            if (rawEvent->code == ABS_MT_SLOT) {
-                mCurrentSlot = rawEvent->value;
-                newSlot = true;
-            }
-        } else if (mCurrentSlot < 0) {
-            mCurrentSlot = 0;
-        }
-
-        if (mCurrentSlot < 0 || size_t(mCurrentSlot) >= mSlotCount) {
-#if DEBUG_POINTERS
-            if (newSlot) {
-                ALOGW("MultiTouch device emitted invalid slot index %d but it "
-                        "should be between 0 and %d; ignoring this slot.",
-                        mCurrentSlot, mSlotCount - 1);
-            }
-#endif
-        } else {
-            Slot* slot = &mSlots[mCurrentSlot];
-
-            switch (rawEvent->code) {
-            case ABS_MT_POSITION_X:
-                slot->mInUse = true;
-                slot->mAbsMTPositionX = rawEvent->value;
-                break;
-            case ABS_MT_POSITION_Y:
-                slot->mInUse = true;
-                slot->mAbsMTPositionY = rawEvent->value;
-                break;
-            case ABS_MT_TOUCH_MAJOR:
-                slot->mInUse = true;
-                slot->mAbsMTTouchMajor = rawEvent->value;
-                break;
-            case ABS_MT_TOUCH_MINOR:
-                slot->mInUse = true;
-                slot->mAbsMTTouchMinor = rawEvent->value;
-                slot->mHaveAbsMTTouchMinor = true;
-                break;
-            case ABS_MT_WIDTH_MAJOR:
-                slot->mInUse = true;
-                slot->mAbsMTWidthMajor = rawEvent->value;
-                break;
-            case ABS_MT_WIDTH_MINOR:
-                slot->mInUse = true;
-                slot->mAbsMTWidthMinor = rawEvent->value;
-                slot->mHaveAbsMTWidthMinor = true;
-                break;
-            case ABS_MT_ORIENTATION:
-                slot->mInUse = true;
-                slot->mAbsMTOrientation = rawEvent->value;
-                break;
-            case ABS_MT_TRACKING_ID:
-                if (mUsingSlotsProtocol && rawEvent->value < 0) {
-                    // The slot is no longer in use but it retains its previous contents,
-                    // which may be reused for subsequent touches.
-                    slot->mInUse = false;
-                } else {
-                    slot->mInUse = true;
-                    slot->mAbsMTTrackingId = rawEvent->value;
-                }
-                break;
-            case ABS_MT_PRESSURE:
-                slot->mInUse = true;
-                slot->mAbsMTPressure = rawEvent->value;
-                break;
-            case ABS_MT_DISTANCE:
-                slot->mInUse = true;
-                slot->mAbsMTDistance = rawEvent->value;
-                break;
-            case ABS_MT_TOOL_TYPE:
-                slot->mInUse = true;
-                slot->mAbsMTToolType = rawEvent->value;
-                slot->mHaveAbsMTToolType = true;
-                break;
-            }
-        }
-    } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_MT_REPORT) {
-        // MultiTouch Sync: The driver has returned all data for *one* of the pointers.
-        mCurrentSlot += 1;
-    }
-}
-
-void MultiTouchMotionAccumulator::finishSync() {
-    if (!mUsingSlotsProtocol) {
-        clearSlots(-1);
-    }
-}
-
-bool MultiTouchMotionAccumulator::hasStylus() const {
-    return mHaveStylus;
-}
-
-
-// --- MultiTouchMotionAccumulator::Slot ---
-
-MultiTouchMotionAccumulator::Slot::Slot() {
-    clear();
-}
-
-void MultiTouchMotionAccumulator::Slot::clear() {
-    mInUse = false;
-    mHaveAbsMTTouchMinor = false;
-    mHaveAbsMTWidthMinor = false;
-    mHaveAbsMTToolType = false;
-    mAbsMTPositionX = 0;
-    mAbsMTPositionY = 0;
-    mAbsMTTouchMajor = 0;
-    mAbsMTTouchMinor = 0;
-    mAbsMTWidthMajor = 0;
-    mAbsMTWidthMinor = 0;
-    mAbsMTOrientation = 0;
-    mAbsMTTrackingId = -1;
-    mAbsMTPressure = 0;
-    mAbsMTDistance = 0;
-    mAbsMTToolType = 0;
-}
-
-int32_t MultiTouchMotionAccumulator::Slot::getToolType() const {
-    if (mHaveAbsMTToolType) {
-        switch (mAbsMTToolType) {
-        case MT_TOOL_FINGER:
-            return AMOTION_EVENT_TOOL_TYPE_FINGER;
-        case MT_TOOL_PEN:
-            return AMOTION_EVENT_TOOL_TYPE_STYLUS;
-        }
-    }
-    return AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
-}
-
-
-// --- InputMapper ---
-
-InputMapper::InputMapper(InputDevice* device) :
-        mDevice(device), mContext(device->getContext()) {
-}
-
-InputMapper::~InputMapper() {
-}
-
-void InputMapper::populateDeviceInfo(InputDeviceInfo* info) {
-    info->addSource(getSources());
-}
-
-void InputMapper::dump(String8& dump) {
-}
-
-void InputMapper::configure(nsecs_t when,
-        const InputReaderConfiguration* config, uint32_t changes) {
-}
-
-void InputMapper::reset(nsecs_t when) {
-}
-
-void InputMapper::timeoutExpired(nsecs_t when) {
-}
-
-int32_t InputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
-    return AKEY_STATE_UNKNOWN;
-}
-
-int32_t InputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
-    return AKEY_STATE_UNKNOWN;
-}
-
-int32_t InputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
-    return AKEY_STATE_UNKNOWN;
-}
-
-bool InputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-        const int32_t* keyCodes, uint8_t* outFlags) {
-    return false;
-}
-
-void InputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
-        int32_t token) {
-}
-
-void InputMapper::cancelVibrate(int32_t token) {
-}
-
-int32_t InputMapper::getMetaState() {
-    return 0;
-}
-
-void InputMapper::fadePointer() {
-}
-
-status_t InputMapper::getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo) {
-    return getEventHub()->getAbsoluteAxisInfo(getDeviceId(), axis, axisInfo);
-}
-
-void InputMapper::bumpGeneration() {
-    mDevice->bumpGeneration();
-}
-
-void InputMapper::dumpRawAbsoluteAxisInfo(String8& dump,
-        const RawAbsoluteAxisInfo& axis, const char* name) {
-    if (axis.valid) {
-        dump.appendFormat(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n",
-                name, axis.minValue, axis.maxValue, axis.flat, axis.fuzz, axis.resolution);
-    } else {
-        dump.appendFormat(INDENT4 "%s: unknown range\n", name);
-    }
-}
-
-
-// --- SwitchInputMapper ---
-
-SwitchInputMapper::SwitchInputMapper(InputDevice* device) :
-        InputMapper(device), mUpdatedSwitchValues(0), mUpdatedSwitchMask(0) {
-}
-
-SwitchInputMapper::~SwitchInputMapper() {
-}
-
-uint32_t SwitchInputMapper::getSources() {
-    return AINPUT_SOURCE_SWITCH;
-}
-
-void SwitchInputMapper::process(const RawEvent* rawEvent) {
-    switch (rawEvent->type) {
-    case EV_SW:
-        processSwitch(rawEvent->code, rawEvent->value);
-        break;
-
-    case EV_SYN:
-        if (rawEvent->code == SYN_REPORT) {
-            sync(rawEvent->when);
-        }
-    }
-}
-
-void SwitchInputMapper::processSwitch(int32_t switchCode, int32_t switchValue) {
-    if (switchCode >= 0 && switchCode < 32) {
-        if (switchValue) {
-            mUpdatedSwitchValues |= 1 << switchCode;
-        }
-        mUpdatedSwitchMask |= 1 << switchCode;
-    }
-}
-
-void SwitchInputMapper::sync(nsecs_t when) {
-    if (mUpdatedSwitchMask) {
-        NotifySwitchArgs args(when, 0, mUpdatedSwitchValues, mUpdatedSwitchMask);
-        getListener()->notifySwitch(&args);
-
-        mUpdatedSwitchValues = 0;
-        mUpdatedSwitchMask = 0;
-    }
-}
-
-int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCode) {
-    return getEventHub()->getSwitchState(getDeviceId(), switchCode);
-}
-
-
-// --- VibratorInputMapper ---
-
-VibratorInputMapper::VibratorInputMapper(InputDevice* device) :
-        InputMapper(device), mVibrating(false) {
-}
-
-VibratorInputMapper::~VibratorInputMapper() {
-}
-
-uint32_t VibratorInputMapper::getSources() {
-    return 0;
-}
-
-void VibratorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
-    InputMapper::populateDeviceInfo(info);
-
-    info->setVibrator(true);
-}
-
-void VibratorInputMapper::process(const RawEvent* rawEvent) {
-    // TODO: Handle FF_STATUS, although it does not seem to be widely supported.
-}
-
-void VibratorInputMapper::vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
-        int32_t token) {
-#if DEBUG_VIBRATOR
-    String8 patternStr;
-    for (size_t i = 0; i < patternSize; i++) {
-        if (i != 0) {
-            patternStr.append(", ");
-        }
-        patternStr.appendFormat("%lld", pattern[i]);
-    }
-    ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%ld, token=%d",
-            getDeviceId(), patternStr.string(), repeat, token);
-#endif
-
-    mVibrating = true;
-    memcpy(mPattern, pattern, patternSize * sizeof(nsecs_t));
-    mPatternSize = patternSize;
-    mRepeat = repeat;
-    mToken = token;
-    mIndex = -1;
-
-    nextStep();
-}
-
-void VibratorInputMapper::cancelVibrate(int32_t token) {
-#if DEBUG_VIBRATOR
-    ALOGD("cancelVibrate: deviceId=%d, token=%d", getDeviceId(), token);
-#endif
-
-    if (mVibrating && mToken == token) {
-        stopVibrating();
-    }
-}
-
-void VibratorInputMapper::timeoutExpired(nsecs_t when) {
-    if (mVibrating) {
-        if (when >= mNextStepTime) {
-            nextStep();
-        } else {
-            getContext()->requestTimeoutAtTime(mNextStepTime);
-        }
-    }
-}
-
-void VibratorInputMapper::nextStep() {
-    mIndex += 1;
-    if (size_t(mIndex) >= mPatternSize) {
-        if (mRepeat < 0) {
-            // We are done.
-            stopVibrating();
-            return;
-        }
-        mIndex = mRepeat;
-    }
-
-    bool vibratorOn = mIndex & 1;
-    nsecs_t duration = mPattern[mIndex];
-    if (vibratorOn) {
-#if DEBUG_VIBRATOR
-        ALOGD("nextStep: sending vibrate deviceId=%d, duration=%lld",
-                getDeviceId(), duration);
-#endif
-        getEventHub()->vibrate(getDeviceId(), duration);
-    } else {
-#if DEBUG_VIBRATOR
-        ALOGD("nextStep: sending cancel vibrate deviceId=%d", getDeviceId());
-#endif
-        getEventHub()->cancelVibrate(getDeviceId());
-    }
-    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
-    mNextStepTime = now + duration;
-    getContext()->requestTimeoutAtTime(mNextStepTime);
-#if DEBUG_VIBRATOR
-    ALOGD("nextStep: scheduled timeout in %0.3fms", duration * 0.000001f);
-#endif
-}
-
-void VibratorInputMapper::stopVibrating() {
-    mVibrating = false;
-#if DEBUG_VIBRATOR
-    ALOGD("stopVibrating: sending cancel vibrate deviceId=%d", getDeviceId());
-#endif
-    getEventHub()->cancelVibrate(getDeviceId());
-}
-
-void VibratorInputMapper::dump(String8& dump) {
-    dump.append(INDENT2 "Vibrator Input Mapper:\n");
-    dump.appendFormat(INDENT3 "Vibrating: %s\n", toString(mVibrating));
-}
-
-
-// --- KeyboardInputMapper ---
-
-KeyboardInputMapper::KeyboardInputMapper(InputDevice* device,
-        uint32_t source, int32_t keyboardType) :
-        InputMapper(device), mSource(source),
-        mKeyboardType(keyboardType) {
-}
-
-KeyboardInputMapper::~KeyboardInputMapper() {
-}
-
-uint32_t KeyboardInputMapper::getSources() {
-    return mSource;
-}
-
-void KeyboardInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
-    InputMapper::populateDeviceInfo(info);
-
-    info->setKeyboardType(mKeyboardType);
-    info->setKeyCharacterMap(getEventHub()->getKeyCharacterMap(getDeviceId()));
-}
-
-void KeyboardInputMapper::dump(String8& dump) {
-    dump.append(INDENT2 "Keyboard Input Mapper:\n");
-    dumpParameters(dump);
-    dump.appendFormat(INDENT3 "KeyboardType: %d\n", mKeyboardType);
-    dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation);
-    dump.appendFormat(INDENT3 "KeyDowns: %d keys currently down\n", mKeyDowns.size());
-    dump.appendFormat(INDENT3 "MetaState: 0x%0x\n", mMetaState);
-    dump.appendFormat(INDENT3 "DownTime: %lld\n", mDownTime);
-}
-
-
-void KeyboardInputMapper::configure(nsecs_t when,
-        const InputReaderConfiguration* config, uint32_t changes) {
-    InputMapper::configure(when, config, changes);
-
-    if (!changes) { // first time only
-        // Configure basic parameters.
-        configureParameters();
-    }
-
-    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
-        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
-            DisplayViewport v;
-            if (config->getDisplayInfo(false /*external*/, &v)) {
-                mOrientation = v.orientation;
-            } else {
-                mOrientation = DISPLAY_ORIENTATION_0;
-            }
-        } else {
-            mOrientation = DISPLAY_ORIENTATION_0;
-        }
-    }
-}
-
-void KeyboardInputMapper::configureParameters() {
-    mParameters.orientationAware = false;
-    getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"),
-            mParameters.orientationAware);
-
-    mParameters.hasAssociatedDisplay = false;
-    if (mParameters.orientationAware) {
-        mParameters.hasAssociatedDisplay = true;
-    }
-}
-
-void KeyboardInputMapper::dumpParameters(String8& dump) {
-    dump.append(INDENT3 "Parameters:\n");
-    dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
-            toString(mParameters.hasAssociatedDisplay));
-    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
-            toString(mParameters.orientationAware));
-}
-
-void KeyboardInputMapper::reset(nsecs_t when) {
-    mMetaState = AMETA_NONE;
-    mDownTime = 0;
-    mKeyDowns.clear();
-    mCurrentHidUsage = 0;
-
-    resetLedState();
-
-    InputMapper::reset(when);
-}
-
-void KeyboardInputMapper::process(const RawEvent* rawEvent) {
-    switch (rawEvent->type) {
-    case EV_KEY: {
-        int32_t scanCode = rawEvent->code;
-        int32_t usageCode = mCurrentHidUsage;
-        mCurrentHidUsage = 0;
-
-        if (isKeyboardOrGamepadKey(scanCode)) {
-            int32_t keyCode;
-            uint32_t flags;
-            if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, &keyCode, &flags)) {
-                keyCode = AKEYCODE_UNKNOWN;
-                flags = 0;
-            }
-            processKey(rawEvent->when, rawEvent->value != 0, keyCode, scanCode, flags);
-        }
-        break;
-    }
-    case EV_MSC: {
-        if (rawEvent->code == MSC_SCAN) {
-            mCurrentHidUsage = rawEvent->value;
-        }
-        break;
-    }
-    case EV_SYN: {
-        if (rawEvent->code == SYN_REPORT) {
-            mCurrentHidUsage = 0;
-        }
-    }
-    }
-}
-
-bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) {
-    return scanCode < BTN_MOUSE
-        || scanCode >= KEY_OK
-        || (scanCode >= BTN_MISC && scanCode < BTN_MOUSE)
-        || (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI);
-}
-
-void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
-        int32_t scanCode, uint32_t policyFlags) {
-
-    if (down) {
-        // Rotate key codes according to orientation if needed.
-        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
-            keyCode = rotateKeyCode(keyCode, mOrientation);
-        }
-
-        // Add key down.
-        ssize_t keyDownIndex = findKeyDown(scanCode);
-        if (keyDownIndex >= 0) {
-            // key repeat, be sure to use same keycode as before in case of rotation
-            keyCode = mKeyDowns.itemAt(keyDownIndex).keyCode;
-        } else {
-            // key down
-            if ((policyFlags & POLICY_FLAG_VIRTUAL)
-                    && mContext->shouldDropVirtualKey(when,
-                            getDevice(), keyCode, scanCode)) {
-                return;
-            }
-
-            mKeyDowns.push();
-            KeyDown& keyDown = mKeyDowns.editTop();
-            keyDown.keyCode = keyCode;
-            keyDown.scanCode = scanCode;
-        }
-
-        mDownTime = when;
-    } else {
-        // Remove key down.
-        ssize_t keyDownIndex = findKeyDown(scanCode);
-        if (keyDownIndex >= 0) {
-            // key up, be sure to use same keycode as before in case of rotation
-            keyCode = mKeyDowns.itemAt(keyDownIndex).keyCode;
-            mKeyDowns.removeAt(size_t(keyDownIndex));
-        } else {
-            // key was not actually down
-            ALOGI("Dropping key up from device %s because the key was not down.  "
-                    "keyCode=%d, scanCode=%d",
-                    getDeviceName().string(), keyCode, scanCode);
-            return;
-        }
-    }
-
-    int32_t oldMetaState = mMetaState;
-    int32_t newMetaState = updateMetaState(keyCode, down, oldMetaState);
-    bool metaStateChanged = oldMetaState != newMetaState;
-    if (metaStateChanged) {
-        mMetaState = newMetaState;
-        updateLedState(false);
-    }
-
-    nsecs_t downTime = mDownTime;
-
-    // Key down on external an keyboard should wake the device.
-    // We don't do this for internal keyboards to prevent them from waking up in your pocket.
-    // For internal keyboards, the key layout file should specify the policy flags for
-    // each wake key individually.
-    // TODO: Use the input device configuration to control this behavior more finely.
-    if (down && getDevice()->isExternal()
-            && !(policyFlags & (POLICY_FLAG_WAKE | POLICY_FLAG_WAKE_DROPPED))) {
-        policyFlags |= POLICY_FLAG_WAKE_DROPPED;
-    }
-
-    if (metaStateChanged) {
-        getContext()->updateGlobalMetaState();
-    }
-
-    if (down && !isMetaKey(keyCode)) {
-        getContext()->fadePointer();
-    }
-
-    NotifyKeyArgs args(when, getDeviceId(), mSource, policyFlags,
-            down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
-            AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime);
-    getListener()->notifyKey(&args);
-}
-
-ssize_t KeyboardInputMapper::findKeyDown(int32_t scanCode) {
-    size_t n = mKeyDowns.size();
-    for (size_t i = 0; i < n; i++) {
-        if (mKeyDowns[i].scanCode == scanCode) {
-            return i;
-        }
-    }
-    return -1;
-}
-
-int32_t KeyboardInputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
-    return getEventHub()->getKeyCodeState(getDeviceId(), keyCode);
-}
-
-int32_t KeyboardInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
-    return getEventHub()->getScanCodeState(getDeviceId(), scanCode);
-}
-
-bool KeyboardInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-        const int32_t* keyCodes, uint8_t* outFlags) {
-    return getEventHub()->markSupportedKeyCodes(getDeviceId(), numCodes, keyCodes, outFlags);
-}
-
-int32_t KeyboardInputMapper::getMetaState() {
-    return mMetaState;
-}
-
-void KeyboardInputMapper::resetLedState() {
-    initializeLedState(mCapsLockLedState, LED_CAPSL);
-    initializeLedState(mNumLockLedState, LED_NUML);
-    initializeLedState(mScrollLockLedState, LED_SCROLLL);
-
-    updateLedState(true);
-}
-
-void KeyboardInputMapper::initializeLedState(LedState& ledState, int32_t led) {
-    ledState.avail = getEventHub()->hasLed(getDeviceId(), led);
-    ledState.on = false;
-}
-
-void KeyboardInputMapper::updateLedState(bool reset) {
-    updateLedStateForModifier(mCapsLockLedState, LED_CAPSL,
-            AMETA_CAPS_LOCK_ON, reset);
-    updateLedStateForModifier(mNumLockLedState, LED_NUML,
-            AMETA_NUM_LOCK_ON, reset);
-    updateLedStateForModifier(mScrollLockLedState, LED_SCROLLL,
-            AMETA_SCROLL_LOCK_ON, reset);
-}
-
-void KeyboardInputMapper::updateLedStateForModifier(LedState& ledState,
-        int32_t led, int32_t modifier, bool reset) {
-    if (ledState.avail) {
-        bool desiredState = (mMetaState & modifier) != 0;
-        if (reset || ledState.on != desiredState) {
-            getEventHub()->setLedState(getDeviceId(), led, desiredState);
-            ledState.on = desiredState;
-        }
-    }
-}
-
-
-// --- CursorInputMapper ---
-
-CursorInputMapper::CursorInputMapper(InputDevice* device) :
-        InputMapper(device) {
-}
-
-CursorInputMapper::~CursorInputMapper() {
-}
-
-uint32_t CursorInputMapper::getSources() {
-    return mSource;
-}
-
-void CursorInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
-    InputMapper::populateDeviceInfo(info);
-
-    if (mParameters.mode == Parameters::MODE_POINTER) {
-        float minX, minY, maxX, maxY;
-        if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
-            info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, minX, maxX, 0.0f, 0.0f, 0.0f);
-            info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, minY, maxY, 0.0f, 0.0f, 0.0f);
-        }
-    } else {
-        info->addMotionRange(AMOTION_EVENT_AXIS_X, mSource, -1.0f, 1.0f, 0.0f, mXScale, 0.0f);
-        info->addMotionRange(AMOTION_EVENT_AXIS_Y, mSource, -1.0f, 1.0f, 0.0f, mYScale, 0.0f);
-    }
-    info->addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, mSource, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
-
-    if (mCursorScrollAccumulator.haveRelativeVWheel()) {
-        info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
-    }
-    if (mCursorScrollAccumulator.haveRelativeHWheel()) {
-        info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
-    }
-}
-
-void CursorInputMapper::dump(String8& dump) {
-    dump.append(INDENT2 "Cursor Input Mapper:\n");
-    dumpParameters(dump);
-    dump.appendFormat(INDENT3 "XScale: %0.3f\n", mXScale);
-    dump.appendFormat(INDENT3 "YScale: %0.3f\n", mYScale);
-    dump.appendFormat(INDENT3 "XPrecision: %0.3f\n", mXPrecision);
-    dump.appendFormat(INDENT3 "YPrecision: %0.3f\n", mYPrecision);
-    dump.appendFormat(INDENT3 "HaveVWheel: %s\n",
-            toString(mCursorScrollAccumulator.haveRelativeVWheel()));
-    dump.appendFormat(INDENT3 "HaveHWheel: %s\n",
-            toString(mCursorScrollAccumulator.haveRelativeHWheel()));
-    dump.appendFormat(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale);
-    dump.appendFormat(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale);
-    dump.appendFormat(INDENT3 "Orientation: %d\n", mOrientation);
-    dump.appendFormat(INDENT3 "ButtonState: 0x%08x\n", mButtonState);
-    dump.appendFormat(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState)));
-    dump.appendFormat(INDENT3 "DownTime: %lld\n", mDownTime);
-}
-
-void CursorInputMapper::configure(nsecs_t when,
-        const InputReaderConfiguration* config, uint32_t changes) {
-    InputMapper::configure(when, config, changes);
-
-    if (!changes) { // first time only
-        mCursorScrollAccumulator.configure(getDevice());
-
-        // Configure basic parameters.
-        configureParameters();
-
-        // Configure device mode.
-        switch (mParameters.mode) {
-        case Parameters::MODE_POINTER:
-            mSource = AINPUT_SOURCE_MOUSE;
-            mXPrecision = 1.0f;
-            mYPrecision = 1.0f;
-            mXScale = 1.0f;
-            mYScale = 1.0f;
-            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
-            break;
-        case Parameters::MODE_NAVIGATION:
-            mSource = AINPUT_SOURCE_TRACKBALL;
-            mXPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
-            mYPrecision = TRACKBALL_MOVEMENT_THRESHOLD;
-            mXScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
-            mYScale = 1.0f / TRACKBALL_MOVEMENT_THRESHOLD;
-            break;
-        }
-
-        mVWheelScale = 1.0f;
-        mHWheelScale = 1.0f;
-    }
-
-    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
-        mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters);
-        mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters);
-        mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters);
-    }
-
-    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
-        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
-            DisplayViewport v;
-            if (config->getDisplayInfo(false /*external*/, &v)) {
-                mOrientation = v.orientation;
-            } else {
-                mOrientation = DISPLAY_ORIENTATION_0;
-            }
-        } else {
-            mOrientation = DISPLAY_ORIENTATION_0;
-        }
-        bumpGeneration();
-    }
-}
-
-void CursorInputMapper::configureParameters() {
-    mParameters.mode = Parameters::MODE_POINTER;
-    String8 cursorModeString;
-    if (getDevice()->getConfiguration().tryGetProperty(String8("cursor.mode"), cursorModeString)) {
-        if (cursorModeString == "navigation") {
-            mParameters.mode = Parameters::MODE_NAVIGATION;
-        } else if (cursorModeString != "pointer" && cursorModeString != "default") {
-            ALOGW("Invalid value for cursor.mode: '%s'", cursorModeString.string());
-        }
-    }
-
-    mParameters.orientationAware = false;
-    getDevice()->getConfiguration().tryGetProperty(String8("cursor.orientationAware"),
-            mParameters.orientationAware);
-
-    mParameters.hasAssociatedDisplay = false;
-    if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
-        mParameters.hasAssociatedDisplay = true;
-    }
-}
-
-void CursorInputMapper::dumpParameters(String8& dump) {
-    dump.append(INDENT3 "Parameters:\n");
-    dump.appendFormat(INDENT4 "HasAssociatedDisplay: %s\n",
-            toString(mParameters.hasAssociatedDisplay));
-
-    switch (mParameters.mode) {
-    case Parameters::MODE_POINTER:
-        dump.append(INDENT4 "Mode: pointer\n");
-        break;
-    case Parameters::MODE_NAVIGATION:
-        dump.append(INDENT4 "Mode: navigation\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-
-    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
-            toString(mParameters.orientationAware));
-}
-
-void CursorInputMapper::reset(nsecs_t when) {
-    mButtonState = 0;
-    mDownTime = 0;
-
-    mPointerVelocityControl.reset();
-    mWheelXVelocityControl.reset();
-    mWheelYVelocityControl.reset();
-
-    mCursorButtonAccumulator.reset(getDevice());
-    mCursorMotionAccumulator.reset(getDevice());
-    mCursorScrollAccumulator.reset(getDevice());
-
-    InputMapper::reset(when);
-}
-
-void CursorInputMapper::process(const RawEvent* rawEvent) {
-    mCursorButtonAccumulator.process(rawEvent);
-    mCursorMotionAccumulator.process(rawEvent);
-    mCursorScrollAccumulator.process(rawEvent);
-
-    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
-        sync(rawEvent->when);
-    }
-}
-
-void CursorInputMapper::sync(nsecs_t when) {
-    int32_t lastButtonState = mButtonState;
-    int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
-    mButtonState = currentButtonState;
-
-    bool wasDown = isPointerDown(lastButtonState);
-    bool down = isPointerDown(currentButtonState);
-    bool downChanged;
-    if (!wasDown && down) {
-        mDownTime = when;
-        downChanged = true;
-    } else if (wasDown && !down) {
-        downChanged = true;
-    } else {
-        downChanged = false;
-    }
-    nsecs_t downTime = mDownTime;
-    bool buttonsChanged = currentButtonState != lastButtonState;
-    bool buttonsPressed = currentButtonState & ~lastButtonState;
-
-    float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
-    float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
-    bool moved = deltaX != 0 || deltaY != 0;
-
-    // Rotate delta according to orientation if needed.
-    if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
-            && (deltaX != 0.0f || deltaY != 0.0f)) {
-        rotateDelta(mOrientation, &deltaX, &deltaY);
-    }
-
-    // Move the pointer.
-    PointerProperties pointerProperties;
-    pointerProperties.clear();
-    pointerProperties.id = 0;
-    pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE;
-
-    PointerCoords pointerCoords;
-    pointerCoords.clear();
-
-    float vscroll = mCursorScrollAccumulator.getRelativeVWheel();
-    float hscroll = mCursorScrollAccumulator.getRelativeHWheel();
-    bool scrolled = vscroll != 0 || hscroll != 0;
-
-    mWheelYVelocityControl.move(when, NULL, &vscroll);
-    mWheelXVelocityControl.move(when, &hscroll, NULL);
-
-    mPointerVelocityControl.move(when, &deltaX, &deltaY);
-
-    int32_t displayId;
-    if (mPointerController != NULL) {
-        if (moved || scrolled || buttonsChanged) {
-            mPointerController->setPresentation(
-                    PointerControllerInterface::PRESENTATION_POINTER);
-
-            if (moved) {
-                mPointerController->move(deltaX, deltaY);
-            }
-
-            if (buttonsChanged) {
-                mPointerController->setButtonState(currentButtonState);
-            }
-
-            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
-        }
-
-        float x, y;
-        mPointerController->getPosition(&x, &y);
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-        displayId = ADISPLAY_ID_DEFAULT;
-    } else {
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
-        displayId = ADISPLAY_ID_NONE;
-    }
-
-    pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, down ? 1.0f : 0.0f);
-
-    // Moving an external trackball or mouse should wake the device.
-    // We don't do this for internal cursor devices to prevent them from waking up
-    // the device in your pocket.
-    // TODO: Use the input device configuration to control this behavior more finely.
-    uint32_t policyFlags = 0;
-    if ((buttonsPressed || moved || scrolled) && getDevice()->isExternal()) {
-        policyFlags |= POLICY_FLAG_WAKE_DROPPED;
-    }
-
-    // Synthesize key down from buttons if needed.
-    synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
-            policyFlags, lastButtonState, currentButtonState);
-
-    // Send motion event.
-    if (downChanged || moved || scrolled || buttonsChanged) {
-        int32_t metaState = mContext->getGlobalMetaState();
-        int32_t motionEventAction;
-        if (downChanged) {
-            motionEventAction = down ? AMOTION_EVENT_ACTION_DOWN : AMOTION_EVENT_ACTION_UP;
-        } else if (down || mPointerController == NULL) {
-            motionEventAction = AMOTION_EVENT_ACTION_MOVE;
-        } else {
-            motionEventAction = AMOTION_EVENT_ACTION_HOVER_MOVE;
-        }
-
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                motionEventAction, 0, metaState, currentButtonState, 0,
-                displayId, 1, &pointerProperties, &pointerCoords,
-                mXPrecision, mYPrecision, downTime);
-        getListener()->notifyMotion(&args);
-
-        // Send hover move after UP to tell the application that the mouse is hovering now.
-        if (motionEventAction == AMOTION_EVENT_ACTION_UP
-                && mPointerController != NULL) {
-            NotifyMotionArgs hoverArgs(when, getDeviceId(), mSource, policyFlags,
-                    AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
-                    metaState, currentButtonState, AMOTION_EVENT_EDGE_FLAG_NONE,
-                    displayId, 1, &pointerProperties, &pointerCoords,
-                    mXPrecision, mYPrecision, downTime);
-            getListener()->notifyMotion(&hoverArgs);
-        }
-
-        // Send scroll events.
-        if (scrolled) {
-            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
-            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);
-
-            NotifyMotionArgs scrollArgs(when, getDeviceId(), mSource, policyFlags,
-                    AMOTION_EVENT_ACTION_SCROLL, 0, metaState, currentButtonState,
-                    AMOTION_EVENT_EDGE_FLAG_NONE,
-                    displayId, 1, &pointerProperties, &pointerCoords,
-                    mXPrecision, mYPrecision, downTime);
-            getListener()->notifyMotion(&scrollArgs);
-        }
-    }
-
-    // Synthesize key up from buttons if needed.
-    synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource,
-            policyFlags, lastButtonState, currentButtonState);
-
-    mCursorMotionAccumulator.finishSync();
-    mCursorScrollAccumulator.finishSync();
-}
-
-int32_t CursorInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
-    if (scanCode >= BTN_MOUSE && scanCode < BTN_JOYSTICK) {
-        return getEventHub()->getScanCodeState(getDeviceId(), scanCode);
-    } else {
-        return AKEY_STATE_UNKNOWN;
-    }
-}
-
-void CursorInputMapper::fadePointer() {
-    if (mPointerController != NULL) {
-        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-    }
-}
-
-
-// --- TouchInputMapper ---
-
-TouchInputMapper::TouchInputMapper(InputDevice* device) :
-        InputMapper(device),
-        mSource(0), mDeviceMode(DEVICE_MODE_DISABLED),
-        mSurfaceWidth(-1), mSurfaceHeight(-1), mSurfaceLeft(0), mSurfaceTop(0),
-        mSurfaceOrientation(DISPLAY_ORIENTATION_0) {
-}
-
-TouchInputMapper::~TouchInputMapper() {
-}
-
-uint32_t TouchInputMapper::getSources() {
-    return mSource;
-}
-
-void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
-    InputMapper::populateDeviceInfo(info);
-
-    if (mDeviceMode != DEVICE_MODE_DISABLED) {
-        info->addMotionRange(mOrientedRanges.x);
-        info->addMotionRange(mOrientedRanges.y);
-        info->addMotionRange(mOrientedRanges.pressure);
-
-        if (mOrientedRanges.haveSize) {
-            info->addMotionRange(mOrientedRanges.size);
-        }
-
-        if (mOrientedRanges.haveTouchSize) {
-            info->addMotionRange(mOrientedRanges.touchMajor);
-            info->addMotionRange(mOrientedRanges.touchMinor);
-        }
-
-        if (mOrientedRanges.haveToolSize) {
-            info->addMotionRange(mOrientedRanges.toolMajor);
-            info->addMotionRange(mOrientedRanges.toolMinor);
-        }
-
-        if (mOrientedRanges.haveOrientation) {
-            info->addMotionRange(mOrientedRanges.orientation);
-        }
-
-        if (mOrientedRanges.haveDistance) {
-            info->addMotionRange(mOrientedRanges.distance);
-        }
-
-        if (mOrientedRanges.haveTilt) {
-            info->addMotionRange(mOrientedRanges.tilt);
-        }
-
-        if (mCursorScrollAccumulator.haveRelativeVWheel()) {
-            info->addMotionRange(AMOTION_EVENT_AXIS_VSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f,
-                    0.0f);
-        }
-        if (mCursorScrollAccumulator.haveRelativeHWheel()) {
-            info->addMotionRange(AMOTION_EVENT_AXIS_HSCROLL, mSource, -1.0f, 1.0f, 0.0f, 0.0f,
-                    0.0f);
-        }
-        if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_BOX) {
-            const InputDeviceInfo::MotionRange& x = mOrientedRanges.x;
-            const InputDeviceInfo::MotionRange& y = mOrientedRanges.y;
-            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_1, mSource, x.min, x.max, x.flat,
-                    x.fuzz, x.resolution);
-            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_2, mSource, y.min, y.max, y.flat,
-                    y.fuzz, y.resolution);
-            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_3, mSource, x.min, x.max, x.flat,
-                    x.fuzz, x.resolution);
-            info->addMotionRange(AMOTION_EVENT_AXIS_GENERIC_4, mSource, y.min, y.max, y.flat,
-                    y.fuzz, y.resolution);
-        }
-        info->setButtonUnderPad(mParameters.hasButtonUnderPad);
-    }
-}
-
-void TouchInputMapper::dump(String8& dump) {
-    dump.append(INDENT2 "Touch Input Mapper:\n");
-    dumpParameters(dump);
-    dumpVirtualKeys(dump);
-    dumpRawPointerAxes(dump);
-    dumpCalibration(dump);
-    dumpSurface(dump);
-
-    dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n");
-    dump.appendFormat(INDENT4 "XTranslate: %0.3f\n", mXTranslate);
-    dump.appendFormat(INDENT4 "YTranslate: %0.3f\n", mYTranslate);
-    dump.appendFormat(INDENT4 "XScale: %0.3f\n", mXScale);
-    dump.appendFormat(INDENT4 "YScale: %0.3f\n", mYScale);
-    dump.appendFormat(INDENT4 "XPrecision: %0.3f\n", mXPrecision);
-    dump.appendFormat(INDENT4 "YPrecision: %0.3f\n", mYPrecision);
-    dump.appendFormat(INDENT4 "GeometricScale: %0.3f\n", mGeometricScale);
-    dump.appendFormat(INDENT4 "PressureScale: %0.3f\n", mPressureScale);
-    dump.appendFormat(INDENT4 "SizeScale: %0.3f\n", mSizeScale);
-    dump.appendFormat(INDENT4 "OrientationScale: %0.3f\n", mOrientationScale);
-    dump.appendFormat(INDENT4 "DistanceScale: %0.3f\n", mDistanceScale);
-    dump.appendFormat(INDENT4 "HaveTilt: %s\n", toString(mHaveTilt));
-    dump.appendFormat(INDENT4 "TiltXCenter: %0.3f\n", mTiltXCenter);
-    dump.appendFormat(INDENT4 "TiltXScale: %0.3f\n", mTiltXScale);
-    dump.appendFormat(INDENT4 "TiltYCenter: %0.3f\n", mTiltYCenter);
-    dump.appendFormat(INDENT4 "TiltYScale: %0.3f\n", mTiltYScale);
-
-    dump.appendFormat(INDENT3 "Last Button State: 0x%08x\n", mLastButtonState);
-
-    dump.appendFormat(INDENT3 "Last Raw Touch: pointerCount=%d\n",
-            mLastRawPointerData.pointerCount);
-    for (uint32_t i = 0; i < mLastRawPointerData.pointerCount; i++) {
-        const RawPointerData::Pointer& pointer = mLastRawPointerData.pointers[i];
-        dump.appendFormat(INDENT4 "[%d]: id=%d, x=%d, y=%d, pressure=%d, "
-                "touchMajor=%d, touchMinor=%d, toolMajor=%d, toolMinor=%d, "
-                "orientation=%d, tiltX=%d, tiltY=%d, distance=%d, "
-                "toolType=%d, isHovering=%s\n", i,
-                pointer.id, pointer.x, pointer.y, pointer.pressure,
-                pointer.touchMajor, pointer.touchMinor,
-                pointer.toolMajor, pointer.toolMinor,
-                pointer.orientation, pointer.tiltX, pointer.tiltY, pointer.distance,
-                pointer.toolType, toString(pointer.isHovering));
-    }
-
-    dump.appendFormat(INDENT3 "Last Cooked Touch: pointerCount=%d\n",
-            mLastCookedPointerData.pointerCount);
-    for (uint32_t i = 0; i < mLastCookedPointerData.pointerCount; i++) {
-        const PointerProperties& pointerProperties = mLastCookedPointerData.pointerProperties[i];
-        const PointerCoords& pointerCoords = mLastCookedPointerData.pointerCoords[i];
-        dump.appendFormat(INDENT4 "[%d]: id=%d, x=%0.3f, y=%0.3f, pressure=%0.3f, "
-                "touchMajor=%0.3f, touchMinor=%0.3f, toolMajor=%0.3f, toolMinor=%0.3f, "
-                "orientation=%0.3f, tilt=%0.3f, distance=%0.3f, "
-                "toolType=%d, isHovering=%s\n", i,
-                pointerProperties.id,
-                pointerCoords.getX(),
-                pointerCoords.getY(),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_TILT),
-                pointerCoords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE),
-                pointerProperties.toolType,
-                toString(mLastCookedPointerData.isHovering(i)));
-    }
-
-    if (mDeviceMode == DEVICE_MODE_POINTER) {
-        dump.appendFormat(INDENT3 "Pointer Gesture Detector:\n");
-        dump.appendFormat(INDENT4 "XMovementScale: %0.3f\n",
-                mPointerXMovementScale);
-        dump.appendFormat(INDENT4 "YMovementScale: %0.3f\n",
-                mPointerYMovementScale);
-        dump.appendFormat(INDENT4 "XZoomScale: %0.3f\n",
-                mPointerXZoomScale);
-        dump.appendFormat(INDENT4 "YZoomScale: %0.3f\n",
-                mPointerYZoomScale);
-        dump.appendFormat(INDENT4 "MaxSwipeWidth: %f\n",
-                mPointerGestureMaxSwipeWidth);
-    }
-}
-
-void TouchInputMapper::configure(nsecs_t when,
-        const InputReaderConfiguration* config, uint32_t changes) {
-    InputMapper::configure(when, config, changes);
-
-    mConfig = *config;
-
-    if (!changes) { // first time only
-        // Configure basic parameters.
-        configureParameters();
-
-        // Configure common accumulators.
-        mCursorScrollAccumulator.configure(getDevice());
-        mTouchButtonAccumulator.configure(getDevice());
-
-        // Configure absolute axis information.
-        configureRawPointerAxes();
-
-        // Prepare input device calibration.
-        parseCalibration();
-        resolveCalibration();
-    }
-
-    if (!changes || (changes & InputReaderConfiguration::CHANGE_POINTER_SPEED)) {
-        // Update pointer speed.
-        mPointerVelocityControl.setParameters(mConfig.pointerVelocityControlParameters);
-        mWheelXVelocityControl.setParameters(mConfig.wheelVelocityControlParameters);
-        mWheelYVelocityControl.setParameters(mConfig.wheelVelocityControlParameters);
-    }
-
-    bool resetNeeded = false;
-    if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO
-            | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT
-            | InputReaderConfiguration::CHANGE_SHOW_TOUCHES))) {
-        // Configure device sources, surface dimensions, orientation and
-        // scaling factors.
-        configureSurface(when, &resetNeeded);
-    }
-
-    if (changes && resetNeeded) {
-        // Send reset, unless this is the first time the device has been configured,
-        // in which case the reader will call reset itself after all mappers are ready.
-        getDevice()->notifyReset(when);
-    }
-}
-
-void TouchInputMapper::configureParameters() {
-    // Use the pointer presentation mode for devices that do not support distinct
-    // multitouch.  The spot-based presentation relies on being able to accurately
-    // locate two or more fingers on the touch pad.
-    mParameters.gestureMode = getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_SEMI_MT)
-            ? Parameters::GESTURE_MODE_POINTER : Parameters::GESTURE_MODE_SPOTS;
-
-    String8 gestureModeString;
-    if (getDevice()->getConfiguration().tryGetProperty(String8("touch.gestureMode"),
-            gestureModeString)) {
-        if (gestureModeString == "pointer") {
-            mParameters.gestureMode = Parameters::GESTURE_MODE_POINTER;
-        } else if (gestureModeString == "spots") {
-            mParameters.gestureMode = Parameters::GESTURE_MODE_SPOTS;
-        } else if (gestureModeString != "default") {
-            ALOGW("Invalid value for touch.gestureMode: '%s'", gestureModeString.string());
-        }
-    }
-
-    if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_DIRECT)) {
-        // The device is a touch screen.
-        mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;
-    } else if (getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_POINTER)) {
-        // The device is a pointing device like a track pad.
-        mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
-    } else if (getEventHub()->hasRelativeAxis(getDeviceId(), REL_X)
-            || getEventHub()->hasRelativeAxis(getDeviceId(), REL_Y)) {
-        // The device is a cursor device with a touch pad attached.
-        // By default don't use the touch pad to move the pointer.
-        mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;
-    } else {
-        // The device is a touch pad of unknown purpose.
-        mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
-    }
-
-    mParameters.hasButtonUnderPad=
-            getEventHub()->hasInputProperty(getDeviceId(), INPUT_PROP_BUTTONPAD);
-
-    String8 deviceTypeString;
-    if (getDevice()->getConfiguration().tryGetProperty(String8("touch.deviceType"),
-            deviceTypeString)) {
-        if (deviceTypeString == "touchScreen") {
-            mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_SCREEN;
-        } else if (deviceTypeString == "touchPad") {
-            mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_PAD;
-        } else if (deviceTypeString == "touchNavigation") {
-            mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_NAVIGATION;
-        } else if (deviceTypeString == "pointer") {
-            mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER;
-        } else if (deviceTypeString != "default") {
-            ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string());
-        }
-    }
-
-    mParameters.orientationAware = mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN;
-    getDevice()->getConfiguration().tryGetProperty(String8("touch.orientationAware"),
-            mParameters.orientationAware);
-
-    mParameters.hasAssociatedDisplay = false;
-    mParameters.associatedDisplayIsExternal = false;
-    if (mParameters.orientationAware
-            || mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
-            || mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {
-        mParameters.hasAssociatedDisplay = true;
-        mParameters.associatedDisplayIsExternal =
-                mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
-                        && getDevice()->isExternal();
-    }
-}
-
-void TouchInputMapper::dumpParameters(String8& dump) {
-    dump.append(INDENT3 "Parameters:\n");
-
-    switch (mParameters.gestureMode) {
-    case Parameters::GESTURE_MODE_POINTER:
-        dump.append(INDENT4 "GestureMode: pointer\n");
-        break;
-    case Parameters::GESTURE_MODE_SPOTS:
-        dump.append(INDENT4 "GestureMode: spots\n");
-        break;
-    default:
-        assert(false);
-    }
-
-    switch (mParameters.deviceType) {
-    case Parameters::DEVICE_TYPE_TOUCH_SCREEN:
-        dump.append(INDENT4 "DeviceType: touchScreen\n");
-        break;
-    case Parameters::DEVICE_TYPE_TOUCH_PAD:
-        dump.append(INDENT4 "DeviceType: touchPad\n");
-        break;
-    case Parameters::DEVICE_TYPE_TOUCH_NAVIGATION:
-        dump.append(INDENT4 "DeviceType: touchNavigation\n");
-        break;
-    case Parameters::DEVICE_TYPE_POINTER:
-        dump.append(INDENT4 "DeviceType: pointer\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-
-    dump.appendFormat(INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s\n",
-            toString(mParameters.hasAssociatedDisplay),
-            toString(mParameters.associatedDisplayIsExternal));
-    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
-            toString(mParameters.orientationAware));
-}
-
-void TouchInputMapper::configureRawPointerAxes() {
-    mRawPointerAxes.clear();
-}
-
-void TouchInputMapper::dumpRawPointerAxes(String8& dump) {
-    dump.append(INDENT3 "Raw Touch Axes:\n");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.x, "X");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.y, "Y");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.pressure, "Pressure");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.touchMajor, "TouchMajor");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.touchMinor, "TouchMinor");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.toolMajor, "ToolMajor");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.toolMinor, "ToolMinor");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.orientation, "Orientation");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.distance, "Distance");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.tiltX, "TiltX");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.tiltY, "TiltY");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.trackingId, "TrackingId");
-    dumpRawAbsoluteAxisInfo(dump, mRawPointerAxes.slot, "Slot");
-}
-
-void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
-    int32_t oldDeviceMode = mDeviceMode;
-
-    // Determine device mode.
-    if (mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER
-            && mConfig.pointerGesturesEnabled) {
-        mSource = AINPUT_SOURCE_MOUSE;
-        mDeviceMode = DEVICE_MODE_POINTER;
-        if (hasStylus()) {
-            mSource |= AINPUT_SOURCE_STYLUS;
-        }
-    } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
-            && mParameters.hasAssociatedDisplay) {
-        mSource = AINPUT_SOURCE_TOUCHSCREEN;
-        mDeviceMode = DEVICE_MODE_DIRECT;
-        if (hasStylus()) {
-            mSource |= AINPUT_SOURCE_STYLUS;
-        }
-    } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_NAVIGATION) {
-        mSource = AINPUT_SOURCE_TOUCH_NAVIGATION;
-        mDeviceMode = DEVICE_MODE_NAVIGATION;
-    } else {
-        mSource = AINPUT_SOURCE_TOUCHPAD;
-        mDeviceMode = DEVICE_MODE_UNSCALED;
-    }
-
-    // Ensure we have valid X and Y axes.
-    if (!mRawPointerAxes.x.valid || !mRawPointerAxes.y.valid) {
-        ALOGW(INDENT "Touch device '%s' did not report support for X or Y axis!  "
-                "The device will be inoperable.", getDeviceName().string());
-        mDeviceMode = DEVICE_MODE_DISABLED;
-        return;
-    }
-
-    // Raw width and height in the natural orientation.
-    int32_t rawWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
-    int32_t rawHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
-
-    // Get associated display dimensions.
-    DisplayViewport newViewport;
-    if (mParameters.hasAssociatedDisplay) {
-        if (!mConfig.getDisplayInfo(mParameters.associatedDisplayIsExternal, &newViewport)) {
-            ALOGI(INDENT "Touch device '%s' could not query the properties of its associated "
-                    "display.  The device will be inoperable until the display size "
-                    "becomes available.",
-                    getDeviceName().string());
-            mDeviceMode = DEVICE_MODE_DISABLED;
-            return;
-        }
-    } else {
-        newViewport.setNonDisplayViewport(rawWidth, rawHeight);
-    }
-    bool viewportChanged = mViewport != newViewport;
-    if (viewportChanged) {
-        mViewport = newViewport;
-
-        if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
-            // Convert rotated viewport to natural surface coordinates.
-            int32_t naturalLogicalWidth, naturalLogicalHeight;
-            int32_t naturalPhysicalWidth, naturalPhysicalHeight;
-            int32_t naturalPhysicalLeft, naturalPhysicalTop;
-            int32_t naturalDeviceWidth, naturalDeviceHeight;
-            switch (mViewport.orientation) {
-            case DISPLAY_ORIENTATION_90:
-                naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
-                naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
-                naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
-                naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
-                naturalPhysicalLeft = mViewport.deviceHeight - mViewport.physicalBottom;
-                naturalPhysicalTop = mViewport.physicalLeft;
-                naturalDeviceWidth = mViewport.deviceHeight;
-                naturalDeviceHeight = mViewport.deviceWidth;
-                break;
-            case DISPLAY_ORIENTATION_180:
-                naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
-                naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
-                naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
-                naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
-                naturalPhysicalLeft = mViewport.deviceWidth - mViewport.physicalRight;
-                naturalPhysicalTop = mViewport.deviceHeight - mViewport.physicalBottom;
-                naturalDeviceWidth = mViewport.deviceWidth;
-                naturalDeviceHeight = mViewport.deviceHeight;
-                break;
-            case DISPLAY_ORIENTATION_270:
-                naturalLogicalWidth = mViewport.logicalBottom - mViewport.logicalTop;
-                naturalLogicalHeight = mViewport.logicalRight - mViewport.logicalLeft;
-                naturalPhysicalWidth = mViewport.physicalBottom - mViewport.physicalTop;
-                naturalPhysicalHeight = mViewport.physicalRight - mViewport.physicalLeft;
-                naturalPhysicalLeft = mViewport.physicalTop;
-                naturalPhysicalTop = mViewport.deviceWidth - mViewport.physicalRight;
-                naturalDeviceWidth = mViewport.deviceHeight;
-                naturalDeviceHeight = mViewport.deviceWidth;
-                break;
-            case DISPLAY_ORIENTATION_0:
-            default:
-                naturalLogicalWidth = mViewport.logicalRight - mViewport.logicalLeft;
-                naturalLogicalHeight = mViewport.logicalBottom - mViewport.logicalTop;
-                naturalPhysicalWidth = mViewport.physicalRight - mViewport.physicalLeft;
-                naturalPhysicalHeight = mViewport.physicalBottom - mViewport.physicalTop;
-                naturalPhysicalLeft = mViewport.physicalLeft;
-                naturalPhysicalTop = mViewport.physicalTop;
-                naturalDeviceWidth = mViewport.deviceWidth;
-                naturalDeviceHeight = mViewport.deviceHeight;
-                break;
-            }
-
-            mSurfaceWidth = naturalLogicalWidth * naturalDeviceWidth / naturalPhysicalWidth;
-            mSurfaceHeight = naturalLogicalHeight * naturalDeviceHeight / naturalPhysicalHeight;
-            mSurfaceLeft = naturalPhysicalLeft * naturalLogicalWidth / naturalPhysicalWidth;
-            mSurfaceTop = naturalPhysicalTop * naturalLogicalHeight / naturalPhysicalHeight;
-
-            mSurfaceOrientation = mParameters.orientationAware ?
-                    mViewport.orientation : DISPLAY_ORIENTATION_0;
-        } else {
-            mSurfaceWidth = rawWidth;
-            mSurfaceHeight = rawHeight;
-            mSurfaceLeft = 0;
-            mSurfaceTop = 0;
-            mSurfaceOrientation = DISPLAY_ORIENTATION_0;
-        }
-    }
-
-    // If moving between pointer modes, need to reset some state.
-    bool deviceModeChanged = mDeviceMode != oldDeviceMode;
-    if (deviceModeChanged) {
-        mOrientedRanges.clear();
-    }
-
-    // Create pointer controller if needed.
-    if (mDeviceMode == DEVICE_MODE_POINTER ||
-            (mDeviceMode == DEVICE_MODE_DIRECT && mConfig.showTouches)) {
-        if (mPointerController == NULL) {
-            mPointerController = getPolicy()->obtainPointerController(getDeviceId());
-        }
-    } else {
-        mPointerController.clear();
-    }
-
-    if (viewportChanged || deviceModeChanged) {
-        ALOGI("Device reconfigured: id=%d, name='%s', size %dx%d, orientation %d, mode %d, "
-                "display id %d",
-                getDeviceId(), getDeviceName().string(), mSurfaceWidth, mSurfaceHeight,
-                mSurfaceOrientation, mDeviceMode, mViewport.displayId);
-
-        // Configure X and Y factors.
-        mXScale = float(mSurfaceWidth) / rawWidth;
-        mYScale = float(mSurfaceHeight) / rawHeight;
-        mXTranslate = -mSurfaceLeft;
-        mYTranslate = -mSurfaceTop;
-        mXPrecision = 1.0f / mXScale;
-        mYPrecision = 1.0f / mYScale;
-
-        mOrientedRanges.x.axis = AMOTION_EVENT_AXIS_X;
-        mOrientedRanges.x.source = mSource;
-        mOrientedRanges.y.axis = AMOTION_EVENT_AXIS_Y;
-        mOrientedRanges.y.source = mSource;
-
-        configureVirtualKeys();
-
-        // Scale factor for terms that are not oriented in a particular axis.
-        // If the pixels are square then xScale == yScale otherwise we fake it
-        // by choosing an average.
-        mGeometricScale = avg(mXScale, mYScale);
-
-        // Size of diagonal axis.
-        float diagonalSize = hypotf(mSurfaceWidth, mSurfaceHeight);
-
-        // Size factors.
-        if (mCalibration.sizeCalibration != Calibration::SIZE_CALIBRATION_NONE) {
-            if (mRawPointerAxes.touchMajor.valid
-                    && mRawPointerAxes.touchMajor.maxValue != 0) {
-                mSizeScale = 1.0f / mRawPointerAxes.touchMajor.maxValue;
-            } else if (mRawPointerAxes.toolMajor.valid
-                    && mRawPointerAxes.toolMajor.maxValue != 0) {
-                mSizeScale = 1.0f / mRawPointerAxes.toolMajor.maxValue;
-            } else {
-                mSizeScale = 0.0f;
-            }
-
-            mOrientedRanges.haveTouchSize = true;
-            mOrientedRanges.haveToolSize = true;
-            mOrientedRanges.haveSize = true;
-
-            mOrientedRanges.touchMajor.axis = AMOTION_EVENT_AXIS_TOUCH_MAJOR;
-            mOrientedRanges.touchMajor.source = mSource;
-            mOrientedRanges.touchMajor.min = 0;
-            mOrientedRanges.touchMajor.max = diagonalSize;
-            mOrientedRanges.touchMajor.flat = 0;
-            mOrientedRanges.touchMajor.fuzz = 0;
-            mOrientedRanges.touchMajor.resolution = 0;
-
-            mOrientedRanges.touchMinor = mOrientedRanges.touchMajor;
-            mOrientedRanges.touchMinor.axis = AMOTION_EVENT_AXIS_TOUCH_MINOR;
-
-            mOrientedRanges.toolMajor.axis = AMOTION_EVENT_AXIS_TOOL_MAJOR;
-            mOrientedRanges.toolMajor.source = mSource;
-            mOrientedRanges.toolMajor.min = 0;
-            mOrientedRanges.toolMajor.max = diagonalSize;
-            mOrientedRanges.toolMajor.flat = 0;
-            mOrientedRanges.toolMajor.fuzz = 0;
-            mOrientedRanges.toolMajor.resolution = 0;
-
-            mOrientedRanges.toolMinor = mOrientedRanges.toolMajor;
-            mOrientedRanges.toolMinor.axis = AMOTION_EVENT_AXIS_TOOL_MINOR;
-
-            mOrientedRanges.size.axis = AMOTION_EVENT_AXIS_SIZE;
-            mOrientedRanges.size.source = mSource;
-            mOrientedRanges.size.min = 0;
-            mOrientedRanges.size.max = 1.0;
-            mOrientedRanges.size.flat = 0;
-            mOrientedRanges.size.fuzz = 0;
-            mOrientedRanges.size.resolution = 0;
-        } else {
-            mSizeScale = 0.0f;
-        }
-
-        // Pressure factors.
-        mPressureScale = 0;
-        if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL
-                || mCalibration.pressureCalibration
-                        == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) {
-            if (mCalibration.havePressureScale) {
-                mPressureScale = mCalibration.pressureScale;
-            } else if (mRawPointerAxes.pressure.valid
-                    && mRawPointerAxes.pressure.maxValue != 0) {
-                mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue;
-            }
-        }
-
-        mOrientedRanges.pressure.axis = AMOTION_EVENT_AXIS_PRESSURE;
-        mOrientedRanges.pressure.source = mSource;
-        mOrientedRanges.pressure.min = 0;
-        mOrientedRanges.pressure.max = 1.0;
-        mOrientedRanges.pressure.flat = 0;
-        mOrientedRanges.pressure.fuzz = 0;
-        mOrientedRanges.pressure.resolution = 0;
-
-        // Tilt
-        mTiltXCenter = 0;
-        mTiltXScale = 0;
-        mTiltYCenter = 0;
-        mTiltYScale = 0;
-        mHaveTilt = mRawPointerAxes.tiltX.valid && mRawPointerAxes.tiltY.valid;
-        if (mHaveTilt) {
-            mTiltXCenter = avg(mRawPointerAxes.tiltX.minValue,
-                    mRawPointerAxes.tiltX.maxValue);
-            mTiltYCenter = avg(mRawPointerAxes.tiltY.minValue,
-                    mRawPointerAxes.tiltY.maxValue);
-            mTiltXScale = M_PI / 180;
-            mTiltYScale = M_PI / 180;
-
-            mOrientedRanges.haveTilt = true;
-
-            mOrientedRanges.tilt.axis = AMOTION_EVENT_AXIS_TILT;
-            mOrientedRanges.tilt.source = mSource;
-            mOrientedRanges.tilt.min = 0;
-            mOrientedRanges.tilt.max = M_PI_2;
-            mOrientedRanges.tilt.flat = 0;
-            mOrientedRanges.tilt.fuzz = 0;
-            mOrientedRanges.tilt.resolution = 0;
-        }
-
-        // Orientation
-        mOrientationScale = 0;
-        if (mHaveTilt) {
-            mOrientedRanges.haveOrientation = true;
-
-            mOrientedRanges.orientation.axis = AMOTION_EVENT_AXIS_ORIENTATION;
-            mOrientedRanges.orientation.source = mSource;
-            mOrientedRanges.orientation.min = -M_PI;
-            mOrientedRanges.orientation.max = M_PI;
-            mOrientedRanges.orientation.flat = 0;
-            mOrientedRanges.orientation.fuzz = 0;
-            mOrientedRanges.orientation.resolution = 0;
-        } else if (mCalibration.orientationCalibration !=
-                Calibration::ORIENTATION_CALIBRATION_NONE) {
-            if (mCalibration.orientationCalibration
-                    == Calibration::ORIENTATION_CALIBRATION_INTERPOLATED) {
-                if (mRawPointerAxes.orientation.valid) {
-                    if (mRawPointerAxes.orientation.maxValue > 0) {
-                        mOrientationScale = M_PI_2 / mRawPointerAxes.orientation.maxValue;
-                    } else if (mRawPointerAxes.orientation.minValue < 0) {
-                        mOrientationScale = -M_PI_2 / mRawPointerAxes.orientation.minValue;
-                    } else {
-                        mOrientationScale = 0;
-                    }
-                }
-            }
-
-            mOrientedRanges.haveOrientation = true;
-
-            mOrientedRanges.orientation.axis = AMOTION_EVENT_AXIS_ORIENTATION;
-            mOrientedRanges.orientation.source = mSource;
-            mOrientedRanges.orientation.min = -M_PI_2;
-            mOrientedRanges.orientation.max = M_PI_2;
-            mOrientedRanges.orientation.flat = 0;
-            mOrientedRanges.orientation.fuzz = 0;
-            mOrientedRanges.orientation.resolution = 0;
-        }
-
-        // Distance
-        mDistanceScale = 0;
-        if (mCalibration.distanceCalibration != Calibration::DISTANCE_CALIBRATION_NONE) {
-            if (mCalibration.distanceCalibration
-                    == Calibration::DISTANCE_CALIBRATION_SCALED) {
-                if (mCalibration.haveDistanceScale) {
-                    mDistanceScale = mCalibration.distanceScale;
-                } else {
-                    mDistanceScale = 1.0f;
-                }
-            }
-
-            mOrientedRanges.haveDistance = true;
-
-            mOrientedRanges.distance.axis = AMOTION_EVENT_AXIS_DISTANCE;
-            mOrientedRanges.distance.source = mSource;
-            mOrientedRanges.distance.min =
-                    mRawPointerAxes.distance.minValue * mDistanceScale;
-            mOrientedRanges.distance.max =
-                    mRawPointerAxes.distance.maxValue * mDistanceScale;
-            mOrientedRanges.distance.flat = 0;
-            mOrientedRanges.distance.fuzz =
-                    mRawPointerAxes.distance.fuzz * mDistanceScale;
-            mOrientedRanges.distance.resolution = 0;
-        }
-
-        // Compute oriented precision, scales and ranges.
-        // Note that the maximum value reported is an inclusive maximum value so it is one
-        // unit less than the total width or height of surface.
-        switch (mSurfaceOrientation) {
-        case DISPLAY_ORIENTATION_90:
-        case DISPLAY_ORIENTATION_270:
-            mOrientedXPrecision = mYPrecision;
-            mOrientedYPrecision = mXPrecision;
-
-            mOrientedRanges.x.min = mYTranslate;
-            mOrientedRanges.x.max = mSurfaceHeight + mYTranslate - 1;
-            mOrientedRanges.x.flat = 0;
-            mOrientedRanges.x.fuzz = 0;
-            mOrientedRanges.x.resolution = mRawPointerAxes.y.resolution * mYScale;
-
-            mOrientedRanges.y.min = mXTranslate;
-            mOrientedRanges.y.max = mSurfaceWidth + mXTranslate - 1;
-            mOrientedRanges.y.flat = 0;
-            mOrientedRanges.y.fuzz = 0;
-            mOrientedRanges.y.resolution = mRawPointerAxes.x.resolution * mXScale;
-            break;
-
-        default:
-            mOrientedXPrecision = mXPrecision;
-            mOrientedYPrecision = mYPrecision;
-
-            mOrientedRanges.x.min = mXTranslate;
-            mOrientedRanges.x.max = mSurfaceWidth + mXTranslate - 1;
-            mOrientedRanges.x.flat = 0;
-            mOrientedRanges.x.fuzz = 0;
-            mOrientedRanges.x.resolution = mRawPointerAxes.x.resolution * mXScale;
-
-            mOrientedRanges.y.min = mYTranslate;
-            mOrientedRanges.y.max = mSurfaceHeight + mYTranslate - 1;
-            mOrientedRanges.y.flat = 0;
-            mOrientedRanges.y.fuzz = 0;
-            mOrientedRanges.y.resolution = mRawPointerAxes.y.resolution * mYScale;
-            break;
-        }
-
-        if (mDeviceMode == DEVICE_MODE_POINTER) {
-            // Compute pointer gesture detection parameters.
-            float rawDiagonal = hypotf(rawWidth, rawHeight);
-            float displayDiagonal = hypotf(mSurfaceWidth, mSurfaceHeight);
-
-            // Scale movements such that one whole swipe of the touch pad covers a
-            // given area relative to the diagonal size of the display when no acceleration
-            // is applied.
-            // Assume that the touch pad has a square aspect ratio such that movements in
-            // X and Y of the same number of raw units cover the same physical distance.
-            mPointerXMovementScale = mConfig.pointerGestureMovementSpeedRatio
-                    * displayDiagonal / rawDiagonal;
-            mPointerYMovementScale = mPointerXMovementScale;
-
-            // Scale zooms to cover a smaller range of the display than movements do.
-            // This value determines the area around the pointer that is affected by freeform
-            // pointer gestures.
-            mPointerXZoomScale = mConfig.pointerGestureZoomSpeedRatio
-                    * displayDiagonal / rawDiagonal;
-            mPointerYZoomScale = mPointerXZoomScale;
-
-            // Max width between pointers to detect a swipe gesture is more than some fraction
-            // of the diagonal axis of the touch pad.  Touches that are wider than this are
-            // translated into freeform gestures.
-            mPointerGestureMaxSwipeWidth =
-                    mConfig.pointerGestureSwipeMaxWidthRatio * rawDiagonal;
-
-            // Abort current pointer usages because the state has changed.
-            abortPointerUsage(when, 0 /*policyFlags*/);
-        }
-
-        // Inform the dispatcher about the changes.
-        *outResetNeeded = true;
-        bumpGeneration();
-    }
-}
-
-void TouchInputMapper::dumpSurface(String8& dump) {
-    dump.appendFormat(INDENT3 "Viewport: displayId=%d, orientation=%d, "
-            "logicalFrame=[%d, %d, %d, %d], "
-            "physicalFrame=[%d, %d, %d, %d], "
-            "deviceSize=[%d, %d]\n",
-            mViewport.displayId, mViewport.orientation,
-            mViewport.logicalLeft, mViewport.logicalTop,
-            mViewport.logicalRight, mViewport.logicalBottom,
-            mViewport.physicalLeft, mViewport.physicalTop,
-            mViewport.physicalRight, mViewport.physicalBottom,
-            mViewport.deviceWidth, mViewport.deviceHeight);
-
-    dump.appendFormat(INDENT3 "SurfaceWidth: %dpx\n", mSurfaceWidth);
-    dump.appendFormat(INDENT3 "SurfaceHeight: %dpx\n", mSurfaceHeight);
-    dump.appendFormat(INDENT3 "SurfaceLeft: %d\n", mSurfaceLeft);
-    dump.appendFormat(INDENT3 "SurfaceTop: %d\n", mSurfaceTop);
-    dump.appendFormat(INDENT3 "SurfaceOrientation: %d\n", mSurfaceOrientation);
-}
-
-void TouchInputMapper::configureVirtualKeys() {
-    Vector<VirtualKeyDefinition> virtualKeyDefinitions;
-    getEventHub()->getVirtualKeyDefinitions(getDeviceId(), virtualKeyDefinitions);
-
-    mVirtualKeys.clear();
-
-    if (virtualKeyDefinitions.size() == 0) {
-        return;
-    }
-
-    mVirtualKeys.setCapacity(virtualKeyDefinitions.size());
-
-    int32_t touchScreenLeft = mRawPointerAxes.x.minValue;
-    int32_t touchScreenTop = mRawPointerAxes.y.minValue;
-    int32_t touchScreenWidth = mRawPointerAxes.x.maxValue - mRawPointerAxes.x.minValue + 1;
-    int32_t touchScreenHeight = mRawPointerAxes.y.maxValue - mRawPointerAxes.y.minValue + 1;
-
-    for (size_t i = 0; i < virtualKeyDefinitions.size(); i++) {
-        const VirtualKeyDefinition& virtualKeyDefinition =
-                virtualKeyDefinitions[i];
-
-        mVirtualKeys.add();
-        VirtualKey& virtualKey = mVirtualKeys.editTop();
-
-        virtualKey.scanCode = virtualKeyDefinition.scanCode;
-        int32_t keyCode;
-        uint32_t flags;
-        if (getEventHub()->mapKey(getDeviceId(), virtualKey.scanCode, 0, &keyCode, &flags)) {
-            ALOGW(INDENT "VirtualKey %d: could not obtain key code, ignoring",
-                    virtualKey.scanCode);
-            mVirtualKeys.pop(); // drop the key
-            continue;
-        }
-
-        virtualKey.keyCode = keyCode;
-        virtualKey.flags = flags;
-
-        // convert the key definition's display coordinates into touch coordinates for a hit box
-        int32_t halfWidth = virtualKeyDefinition.width / 2;
-        int32_t halfHeight = virtualKeyDefinition.height / 2;
-
-        virtualKey.hitLeft = (virtualKeyDefinition.centerX - halfWidth)
-                * touchScreenWidth / mSurfaceWidth + touchScreenLeft;
-        virtualKey.hitRight= (virtualKeyDefinition.centerX + halfWidth)
-                * touchScreenWidth / mSurfaceWidth + touchScreenLeft;
-        virtualKey.hitTop = (virtualKeyDefinition.centerY - halfHeight)
-                * touchScreenHeight / mSurfaceHeight + touchScreenTop;
-        virtualKey.hitBottom = (virtualKeyDefinition.centerY + halfHeight)
-                * touchScreenHeight / mSurfaceHeight + touchScreenTop;
-    }
-}
-
-void TouchInputMapper::dumpVirtualKeys(String8& dump) {
-    if (!mVirtualKeys.isEmpty()) {
-        dump.append(INDENT3 "Virtual Keys:\n");
-
-        for (size_t i = 0; i < mVirtualKeys.size(); i++) {
-            const VirtualKey& virtualKey = mVirtualKeys.itemAt(i);
-            dump.appendFormat(INDENT4 "%d: scanCode=%d, keyCode=%d, "
-                    "hitLeft=%d, hitRight=%d, hitTop=%d, hitBottom=%d\n",
-                    i, virtualKey.scanCode, virtualKey.keyCode,
-                    virtualKey.hitLeft, virtualKey.hitRight,
-                    virtualKey.hitTop, virtualKey.hitBottom);
-        }
-    }
-}
-
-void TouchInputMapper::parseCalibration() {
-    const PropertyMap& in = getDevice()->getConfiguration();
-    Calibration& out = mCalibration;
-
-    // Size
-    out.sizeCalibration = Calibration::SIZE_CALIBRATION_DEFAULT;
-    String8 sizeCalibrationString;
-    if (in.tryGetProperty(String8("touch.size.calibration"), sizeCalibrationString)) {
-        if (sizeCalibrationString == "none") {
-            out.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE;
-        } else if (sizeCalibrationString == "geometric") {
-            out.sizeCalibration = Calibration::SIZE_CALIBRATION_GEOMETRIC;
-        } else if (sizeCalibrationString == "diameter") {
-            out.sizeCalibration = Calibration::SIZE_CALIBRATION_DIAMETER;
-        } else if (sizeCalibrationString == "box") {
-            out.sizeCalibration = Calibration::SIZE_CALIBRATION_BOX;
-        } else if (sizeCalibrationString == "area") {
-            out.sizeCalibration = Calibration::SIZE_CALIBRATION_AREA;
-        } else if (sizeCalibrationString != "default") {
-            ALOGW("Invalid value for touch.size.calibration: '%s'",
-                    sizeCalibrationString.string());
-        }
-    }
-
-    out.haveSizeScale = in.tryGetProperty(String8("touch.size.scale"),
-            out.sizeScale);
-    out.haveSizeBias = in.tryGetProperty(String8("touch.size.bias"),
-            out.sizeBias);
-    out.haveSizeIsSummed = in.tryGetProperty(String8("touch.size.isSummed"),
-            out.sizeIsSummed);
-
-    // Pressure
-    out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_DEFAULT;
-    String8 pressureCalibrationString;
-    if (in.tryGetProperty(String8("touch.pressure.calibration"), pressureCalibrationString)) {
-        if (pressureCalibrationString == "none") {
-            out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE;
-        } else if (pressureCalibrationString == "physical") {
-            out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_PHYSICAL;
-        } else if (pressureCalibrationString == "amplitude") {
-            out.pressureCalibration = Calibration::PRESSURE_CALIBRATION_AMPLITUDE;
-        } else if (pressureCalibrationString != "default") {
-            ALOGW("Invalid value for touch.pressure.calibration: '%s'",
-                    pressureCalibrationString.string());
-        }
-    }
-
-    out.havePressureScale = in.tryGetProperty(String8("touch.pressure.scale"),
-            out.pressureScale);
-
-    // Orientation
-    out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_DEFAULT;
-    String8 orientationCalibrationString;
-    if (in.tryGetProperty(String8("touch.orientation.calibration"), orientationCalibrationString)) {
-        if (orientationCalibrationString == "none") {
-            out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE;
-        } else if (orientationCalibrationString == "interpolated") {
-            out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED;
-        } else if (orientationCalibrationString == "vector") {
-            out.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_VECTOR;
-        } else if (orientationCalibrationString != "default") {
-            ALOGW("Invalid value for touch.orientation.calibration: '%s'",
-                    orientationCalibrationString.string());
-        }
-    }
-
-    // Distance
-    out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_DEFAULT;
-    String8 distanceCalibrationString;
-    if (in.tryGetProperty(String8("touch.distance.calibration"), distanceCalibrationString)) {
-        if (distanceCalibrationString == "none") {
-            out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_NONE;
-        } else if (distanceCalibrationString == "scaled") {
-            out.distanceCalibration = Calibration::DISTANCE_CALIBRATION_SCALED;
-        } else if (distanceCalibrationString != "default") {
-            ALOGW("Invalid value for touch.distance.calibration: '%s'",
-                    distanceCalibrationString.string());
-        }
-    }
-
-    out.haveDistanceScale = in.tryGetProperty(String8("touch.distance.scale"),
-            out.distanceScale);
-
-    out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_DEFAULT;
-    String8 coverageCalibrationString;
-    if (in.tryGetProperty(String8("touch.coverage.calibration"), coverageCalibrationString)) {
-        if (coverageCalibrationString == "none") {
-            out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_NONE;
-        } else if (coverageCalibrationString == "box") {
-            out.coverageCalibration = Calibration::COVERAGE_CALIBRATION_BOX;
-        } else if (coverageCalibrationString != "default") {
-            ALOGW("Invalid value for touch.coverage.calibration: '%s'",
-                    coverageCalibrationString.string());
-        }
-    }
-}
-
-void TouchInputMapper::resolveCalibration() {
-    // Size
-    if (mRawPointerAxes.touchMajor.valid || mRawPointerAxes.toolMajor.valid) {
-        if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DEFAULT) {
-            mCalibration.sizeCalibration = Calibration::SIZE_CALIBRATION_GEOMETRIC;
-        }
-    } else {
-        mCalibration.sizeCalibration = Calibration::SIZE_CALIBRATION_NONE;
-    }
-
-    // Pressure
-    if (mRawPointerAxes.pressure.valid) {
-        if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_DEFAULT) {
-            mCalibration.pressureCalibration = Calibration::PRESSURE_CALIBRATION_PHYSICAL;
-        }
-    } else {
-        mCalibration.pressureCalibration = Calibration::PRESSURE_CALIBRATION_NONE;
-    }
-
-    // Orientation
-    if (mRawPointerAxes.orientation.valid) {
-        if (mCalibration.orientationCalibration == Calibration::ORIENTATION_CALIBRATION_DEFAULT) {
-            mCalibration.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_INTERPOLATED;
-        }
-    } else {
-        mCalibration.orientationCalibration = Calibration::ORIENTATION_CALIBRATION_NONE;
-    }
-
-    // Distance
-    if (mRawPointerAxes.distance.valid) {
-        if (mCalibration.distanceCalibration == Calibration::DISTANCE_CALIBRATION_DEFAULT) {
-            mCalibration.distanceCalibration = Calibration::DISTANCE_CALIBRATION_SCALED;
-        }
-    } else {
-        mCalibration.distanceCalibration = Calibration::DISTANCE_CALIBRATION_NONE;
-    }
-
-    // Coverage
-    if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_DEFAULT) {
-        mCalibration.coverageCalibration = Calibration::COVERAGE_CALIBRATION_NONE;
-    }
-}
-
-void TouchInputMapper::dumpCalibration(String8& dump) {
-    dump.append(INDENT3 "Calibration:\n");
-
-    // Size
-    switch (mCalibration.sizeCalibration) {
-    case Calibration::SIZE_CALIBRATION_NONE:
-        dump.append(INDENT4 "touch.size.calibration: none\n");
-        break;
-    case Calibration::SIZE_CALIBRATION_GEOMETRIC:
-        dump.append(INDENT4 "touch.size.calibration: geometric\n");
-        break;
-    case Calibration::SIZE_CALIBRATION_DIAMETER:
-        dump.append(INDENT4 "touch.size.calibration: diameter\n");
-        break;
-    case Calibration::SIZE_CALIBRATION_BOX:
-        dump.append(INDENT4 "touch.size.calibration: box\n");
-        break;
-    case Calibration::SIZE_CALIBRATION_AREA:
-        dump.append(INDENT4 "touch.size.calibration: area\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-
-    if (mCalibration.haveSizeScale) {
-        dump.appendFormat(INDENT4 "touch.size.scale: %0.3f\n",
-                mCalibration.sizeScale);
-    }
-
-    if (mCalibration.haveSizeBias) {
-        dump.appendFormat(INDENT4 "touch.size.bias: %0.3f\n",
-                mCalibration.sizeBias);
-    }
-
-    if (mCalibration.haveSizeIsSummed) {
-        dump.appendFormat(INDENT4 "touch.size.isSummed: %s\n",
-                toString(mCalibration.sizeIsSummed));
-    }
-
-    // Pressure
-    switch (mCalibration.pressureCalibration) {
-    case Calibration::PRESSURE_CALIBRATION_NONE:
-        dump.append(INDENT4 "touch.pressure.calibration: none\n");
-        break;
-    case Calibration::PRESSURE_CALIBRATION_PHYSICAL:
-        dump.append(INDENT4 "touch.pressure.calibration: physical\n");
-        break;
-    case Calibration::PRESSURE_CALIBRATION_AMPLITUDE:
-        dump.append(INDENT4 "touch.pressure.calibration: amplitude\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-
-    if (mCalibration.havePressureScale) {
-        dump.appendFormat(INDENT4 "touch.pressure.scale: %0.3f\n",
-                mCalibration.pressureScale);
-    }
-
-    // Orientation
-    switch (mCalibration.orientationCalibration) {
-    case Calibration::ORIENTATION_CALIBRATION_NONE:
-        dump.append(INDENT4 "touch.orientation.calibration: none\n");
-        break;
-    case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED:
-        dump.append(INDENT4 "touch.orientation.calibration: interpolated\n");
-        break;
-    case Calibration::ORIENTATION_CALIBRATION_VECTOR:
-        dump.append(INDENT4 "touch.orientation.calibration: vector\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-
-    // Distance
-    switch (mCalibration.distanceCalibration) {
-    case Calibration::DISTANCE_CALIBRATION_NONE:
-        dump.append(INDENT4 "touch.distance.calibration: none\n");
-        break;
-    case Calibration::DISTANCE_CALIBRATION_SCALED:
-        dump.append(INDENT4 "touch.distance.calibration: scaled\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-
-    if (mCalibration.haveDistanceScale) {
-        dump.appendFormat(INDENT4 "touch.distance.scale: %0.3f\n",
-                mCalibration.distanceScale);
-    }
-
-    switch (mCalibration.coverageCalibration) {
-    case Calibration::COVERAGE_CALIBRATION_NONE:
-        dump.append(INDENT4 "touch.coverage.calibration: none\n");
-        break;
-    case Calibration::COVERAGE_CALIBRATION_BOX:
-        dump.append(INDENT4 "touch.coverage.calibration: box\n");
-        break;
-    default:
-        ALOG_ASSERT(false);
-    }
-}
-
-void TouchInputMapper::reset(nsecs_t when) {
-    mCursorButtonAccumulator.reset(getDevice());
-    mCursorScrollAccumulator.reset(getDevice());
-    mTouchButtonAccumulator.reset(getDevice());
-
-    mPointerVelocityControl.reset();
-    mWheelXVelocityControl.reset();
-    mWheelYVelocityControl.reset();
-
-    mCurrentRawPointerData.clear();
-    mLastRawPointerData.clear();
-    mCurrentCookedPointerData.clear();
-    mLastCookedPointerData.clear();
-    mCurrentButtonState = 0;
-    mLastButtonState = 0;
-    mCurrentRawVScroll = 0;
-    mCurrentRawHScroll = 0;
-    mCurrentFingerIdBits.clear();
-    mLastFingerIdBits.clear();
-    mCurrentStylusIdBits.clear();
-    mLastStylusIdBits.clear();
-    mCurrentMouseIdBits.clear();
-    mLastMouseIdBits.clear();
-    mPointerUsage = POINTER_USAGE_NONE;
-    mSentHoverEnter = false;
-    mDownTime = 0;
-
-    mCurrentVirtualKey.down = false;
-
-    mPointerGesture.reset();
-    mPointerSimple.reset();
-
-    if (mPointerController != NULL) {
-        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-        mPointerController->clearSpots();
-    }
-
-    InputMapper::reset(when);
-}
-
-void TouchInputMapper::process(const RawEvent* rawEvent) {
-    mCursorButtonAccumulator.process(rawEvent);
-    mCursorScrollAccumulator.process(rawEvent);
-    mTouchButtonAccumulator.process(rawEvent);
-
-    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
-        sync(rawEvent->when);
-    }
-}
-
-void TouchInputMapper::sync(nsecs_t when) {
-    // Sync button state.
-    mCurrentButtonState = mTouchButtonAccumulator.getButtonState()
-            | mCursorButtonAccumulator.getButtonState();
-
-    // Sync scroll state.
-    mCurrentRawVScroll = mCursorScrollAccumulator.getRelativeVWheel();
-    mCurrentRawHScroll = mCursorScrollAccumulator.getRelativeHWheel();
-    mCursorScrollAccumulator.finishSync();
-
-    // Sync touch state.
-    bool havePointerIds = true;
-    mCurrentRawPointerData.clear();
-    syncTouch(when, &havePointerIds);
-
-#if DEBUG_RAW_EVENTS
-    if (!havePointerIds) {
-        ALOGD("syncTouch: pointerCount %d -> %d, no pointer ids",
-                mLastRawPointerData.pointerCount,
-                mCurrentRawPointerData.pointerCount);
-    } else {
-        ALOGD("syncTouch: pointerCount %d -> %d, touching ids 0x%08x -> 0x%08x, "
-                "hovering ids 0x%08x -> 0x%08x",
-                mLastRawPointerData.pointerCount,
-                mCurrentRawPointerData.pointerCount,
-                mLastRawPointerData.touchingIdBits.value,
-                mCurrentRawPointerData.touchingIdBits.value,
-                mLastRawPointerData.hoveringIdBits.value,
-                mCurrentRawPointerData.hoveringIdBits.value);
-    }
-#endif
-
-    // Reset state that we will compute below.
-    mCurrentFingerIdBits.clear();
-    mCurrentStylusIdBits.clear();
-    mCurrentMouseIdBits.clear();
-    mCurrentCookedPointerData.clear();
-
-    if (mDeviceMode == DEVICE_MODE_DISABLED) {
-        // Drop all input if the device is disabled.
-        mCurrentRawPointerData.clear();
-        mCurrentButtonState = 0;
-    } else {
-        // Preprocess pointer data.
-        if (!havePointerIds) {
-            assignPointerIds();
-        }
-
-        // Handle policy on initial down or hover events.
-        uint32_t policyFlags = 0;
-        bool initialDown = mLastRawPointerData.pointerCount == 0
-                && mCurrentRawPointerData.pointerCount != 0;
-        bool buttonsPressed = mCurrentButtonState & ~mLastButtonState;
-        if (initialDown || buttonsPressed) {
-            // If this is a touch screen, hide the pointer on an initial down.
-            if (mDeviceMode == DEVICE_MODE_DIRECT) {
-                getContext()->fadePointer();
-            }
-
-            // Initial downs on external touch devices should wake the device.
-            // We don't do this for internal touch screens to prevent them from waking
-            // up in your pocket.
-            // TODO: Use the input device configuration to control this behavior more finely.
-            if (getDevice()->isExternal()) {
-                policyFlags |= POLICY_FLAG_WAKE_DROPPED;
-            }
-        }
-
-        // Synthesize key down from raw buttons if needed.
-        synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_DOWN, when, getDeviceId(), mSource,
-                policyFlags, mLastButtonState, mCurrentButtonState);
-
-        // Consume raw off-screen touches before cooking pointer data.
-        // If touches are consumed, subsequent code will not receive any pointer data.
-        if (consumeRawTouches(when, policyFlags)) {
-            mCurrentRawPointerData.clear();
-        }
-
-        // Cook pointer data.  This call populates the mCurrentCookedPointerData structure
-        // with cooked pointer data that has the same ids and indices as the raw data.
-        // The following code can use either the raw or cooked data, as needed.
-        cookPointerData();
-
-        // Dispatch the touches either directly or by translation through a pointer on screen.
-        if (mDeviceMode == DEVICE_MODE_POINTER) {
-            for (BitSet32 idBits(mCurrentRawPointerData.touchingIdBits); !idBits.isEmpty(); ) {
-                uint32_t id = idBits.clearFirstMarkedBit();
-                const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
-                if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS
-                        || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) {
-                    mCurrentStylusIdBits.markBit(id);
-                } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_FINGER
-                        || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
-                    mCurrentFingerIdBits.markBit(id);
-                } else if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_MOUSE) {
-                    mCurrentMouseIdBits.markBit(id);
-                }
-            }
-            for (BitSet32 idBits(mCurrentRawPointerData.hoveringIdBits); !idBits.isEmpty(); ) {
-                uint32_t id = idBits.clearFirstMarkedBit();
-                const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
-                if (pointer.toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS
-                        || pointer.toolType == AMOTION_EVENT_TOOL_TYPE_ERASER) {
-                    mCurrentStylusIdBits.markBit(id);
-                }
-            }
-
-            // Stylus takes precedence over all tools, then mouse, then finger.
-            PointerUsage pointerUsage = mPointerUsage;
-            if (!mCurrentStylusIdBits.isEmpty()) {
-                mCurrentMouseIdBits.clear();
-                mCurrentFingerIdBits.clear();
-                pointerUsage = POINTER_USAGE_STYLUS;
-            } else if (!mCurrentMouseIdBits.isEmpty()) {
-                mCurrentFingerIdBits.clear();
-                pointerUsage = POINTER_USAGE_MOUSE;
-            } else if (!mCurrentFingerIdBits.isEmpty() || isPointerDown(mCurrentButtonState)) {
-                pointerUsage = POINTER_USAGE_GESTURES;
-            }
-
-            dispatchPointerUsage(when, policyFlags, pointerUsage);
-        } else {
-            if (mDeviceMode == DEVICE_MODE_DIRECT
-                    && mConfig.showTouches && mPointerController != NULL) {
-                mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT);
-                mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-
-                mPointerController->setButtonState(mCurrentButtonState);
-                mPointerController->setSpots(mCurrentCookedPointerData.pointerCoords,
-                        mCurrentCookedPointerData.idToIndex,
-                        mCurrentCookedPointerData.touchingIdBits);
-            }
-
-            dispatchHoverExit(when, policyFlags);
-            dispatchTouches(when, policyFlags);
-            dispatchHoverEnterAndMove(when, policyFlags);
-        }
-
-        // Synthesize key up from raw buttons if needed.
-        synthesizeButtonKeys(getContext(), AKEY_EVENT_ACTION_UP, when, getDeviceId(), mSource,
-                policyFlags, mLastButtonState, mCurrentButtonState);
-    }
-
-    // Copy current touch to last touch in preparation for the next cycle.
-    mLastRawPointerData.copyFrom(mCurrentRawPointerData);
-    mLastCookedPointerData.copyFrom(mCurrentCookedPointerData);
-    mLastButtonState = mCurrentButtonState;
-    mLastFingerIdBits = mCurrentFingerIdBits;
-    mLastStylusIdBits = mCurrentStylusIdBits;
-    mLastMouseIdBits = mCurrentMouseIdBits;
-
-    // Clear some transient state.
-    mCurrentRawVScroll = 0;
-    mCurrentRawHScroll = 0;
-}
-
-void TouchInputMapper::timeoutExpired(nsecs_t when) {
-    if (mDeviceMode == DEVICE_MODE_POINTER) {
-        if (mPointerUsage == POINTER_USAGE_GESTURES) {
-            dispatchPointerGestures(when, 0 /*policyFlags*/, true /*isTimeout*/);
-        }
-    }
-}
-
-bool TouchInputMapper::consumeRawTouches(nsecs_t when, uint32_t policyFlags) {
-    // Check for release of a virtual key.
-    if (mCurrentVirtualKey.down) {
-        if (mCurrentRawPointerData.touchingIdBits.isEmpty()) {
-            // Pointer went up while virtual key was down.
-            mCurrentVirtualKey.down = false;
-            if (!mCurrentVirtualKey.ignored) {
-#if DEBUG_VIRTUAL_KEYS
-                ALOGD("VirtualKeys: Generating key up: keyCode=%d, scanCode=%d",
-                        mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
-#endif
-                dispatchVirtualKey(when, policyFlags,
-                        AKEY_EVENT_ACTION_UP,
-                        AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY);
-            }
-            return true;
-        }
-
-        if (mCurrentRawPointerData.touchingIdBits.count() == 1) {
-            uint32_t id = mCurrentRawPointerData.touchingIdBits.firstMarkedBit();
-            const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
-            const VirtualKey* virtualKey = findVirtualKeyHit(pointer.x, pointer.y);
-            if (virtualKey && virtualKey->keyCode == mCurrentVirtualKey.keyCode) {
-                // Pointer is still within the space of the virtual key.
-                return true;
-            }
-        }
-
-        // Pointer left virtual key area or another pointer also went down.
-        // Send key cancellation but do not consume the touch yet.
-        // This is useful when the user swipes through from the virtual key area
-        // into the main display surface.
-        mCurrentVirtualKey.down = false;
-        if (!mCurrentVirtualKey.ignored) {
-#if DEBUG_VIRTUAL_KEYS
-            ALOGD("VirtualKeys: Canceling key: keyCode=%d, scanCode=%d",
-                    mCurrentVirtualKey.keyCode, mCurrentVirtualKey.scanCode);
-#endif
-            dispatchVirtualKey(when, policyFlags,
-                    AKEY_EVENT_ACTION_UP,
-                    AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
-                            | AKEY_EVENT_FLAG_CANCELED);
-        }
-    }
-
-    if (mLastRawPointerData.touchingIdBits.isEmpty()
-            && !mCurrentRawPointerData.touchingIdBits.isEmpty()) {
-        // Pointer just went down.  Check for virtual key press or off-screen touches.
-        uint32_t id = mCurrentRawPointerData.touchingIdBits.firstMarkedBit();
-        const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
-        if (!isPointInsideSurface(pointer.x, pointer.y)) {
-            // If exactly one pointer went down, check for virtual key hit.
-            // Otherwise we will drop the entire stroke.
-            if (mCurrentRawPointerData.touchingIdBits.count() == 1) {
-                const VirtualKey* virtualKey = findVirtualKeyHit(pointer.x, pointer.y);
-                if (virtualKey) {
-                    mCurrentVirtualKey.down = true;
-                    mCurrentVirtualKey.downTime = when;
-                    mCurrentVirtualKey.keyCode = virtualKey->keyCode;
-                    mCurrentVirtualKey.scanCode = virtualKey->scanCode;
-                    mCurrentVirtualKey.ignored = mContext->shouldDropVirtualKey(
-                            when, getDevice(), virtualKey->keyCode, virtualKey->scanCode);
-
-                    if (!mCurrentVirtualKey.ignored) {
-#if DEBUG_VIRTUAL_KEYS
-                        ALOGD("VirtualKeys: Generating key down: keyCode=%d, scanCode=%d",
-                                mCurrentVirtualKey.keyCode,
-                                mCurrentVirtualKey.scanCode);
-#endif
-                        dispatchVirtualKey(when, policyFlags,
-                                AKEY_EVENT_ACTION_DOWN,
-                                AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY);
-                    }
-                }
-            }
-            return true;
-        }
-    }
-
-    // Disable all virtual key touches that happen within a short time interval of the
-    // most recent touch within the screen area.  The idea is to filter out stray
-    // virtual key presses when interacting with the touch screen.
-    //
-    // Problems we're trying to solve:
-    //
-    // 1. While scrolling a list or dragging the window shade, the user swipes down into a
-    //    virtual key area that is implemented by a separate touch panel and accidentally
-    //    triggers a virtual key.
-    //
-    // 2. While typing in the on screen keyboard, the user taps slightly outside the screen
-    //    area and accidentally triggers a virtual key.  This often happens when virtual keys
-    //    are layed out below the screen near to where the on screen keyboard's space bar
-    //    is displayed.
-    if (mConfig.virtualKeyQuietTime > 0 && !mCurrentRawPointerData.touchingIdBits.isEmpty()) {
-        mContext->disableVirtualKeysUntil(when + mConfig.virtualKeyQuietTime);
-    }
-    return false;
-}
-
-void TouchInputMapper::dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
-        int32_t keyEventAction, int32_t keyEventFlags) {
-    int32_t keyCode = mCurrentVirtualKey.keyCode;
-    int32_t scanCode = mCurrentVirtualKey.scanCode;
-    nsecs_t downTime = mCurrentVirtualKey.downTime;
-    int32_t metaState = mContext->getGlobalMetaState();
-    policyFlags |= POLICY_FLAG_VIRTUAL;
-
-    NotifyKeyArgs args(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
-            keyEventAction, keyEventFlags, keyCode, scanCode, metaState, downTime);
-    getListener()->notifyKey(&args);
-}
-
-void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
-    BitSet32 currentIdBits = mCurrentCookedPointerData.touchingIdBits;
-    BitSet32 lastIdBits = mLastCookedPointerData.touchingIdBits;
-    int32_t metaState = getContext()->getGlobalMetaState();
-    int32_t buttonState = mCurrentButtonState;
-
-    if (currentIdBits == lastIdBits) {
-        if (!currentIdBits.isEmpty()) {
-            // No pointer id changes so this is a move event.
-            // The listener takes care of batching moves so we don't have to deal with that here.
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState,
-                    AMOTION_EVENT_EDGE_FLAG_NONE,
-                    mCurrentCookedPointerData.pointerProperties,
-                    mCurrentCookedPointerData.pointerCoords,
-                    mCurrentCookedPointerData.idToIndex,
-                    currentIdBits, -1,
-                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-        }
-    } else {
-        // There may be pointers going up and pointers going down and pointers moving
-        // all at the same time.
-        BitSet32 upIdBits(lastIdBits.value & ~currentIdBits.value);
-        BitSet32 downIdBits(currentIdBits.value & ~lastIdBits.value);
-        BitSet32 moveIdBits(lastIdBits.value & currentIdBits.value);
-        BitSet32 dispatchedIdBits(lastIdBits.value);
-
-        // Update last coordinates of pointers that have moved so that we observe the new
-        // pointer positions at the same time as other pointers that have just gone up.
-        bool moveNeeded = updateMovedPointers(
-                mCurrentCookedPointerData.pointerProperties,
-                mCurrentCookedPointerData.pointerCoords,
-                mCurrentCookedPointerData.idToIndex,
-                mLastCookedPointerData.pointerProperties,
-                mLastCookedPointerData.pointerCoords,
-                mLastCookedPointerData.idToIndex,
-                moveIdBits);
-        if (buttonState != mLastButtonState) {
-            moveNeeded = true;
-        }
-
-        // Dispatch pointer up events.
-        while (!upIdBits.isEmpty()) {
-            uint32_t upId = upIdBits.clearFirstMarkedBit();
-
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_POINTER_UP, 0, metaState, buttonState, 0,
-                    mLastCookedPointerData.pointerProperties,
-                    mLastCookedPointerData.pointerCoords,
-                    mLastCookedPointerData.idToIndex,
-                    dispatchedIdBits, upId,
-                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-            dispatchedIdBits.clearBit(upId);
-        }
-
-        // Dispatch move events if any of the remaining pointers moved from their old locations.
-        // Although applications receive new locations as part of individual pointer up
-        // events, they do not generally handle them except when presented in a move event.
-        if (moveNeeded) {
-            ALOG_ASSERT(moveIdBits.value == dispatchedIdBits.value);
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, 0,
-                    mCurrentCookedPointerData.pointerProperties,
-                    mCurrentCookedPointerData.pointerCoords,
-                    mCurrentCookedPointerData.idToIndex,
-                    dispatchedIdBits, -1,
-                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-        }
-
-        // Dispatch pointer down events using the new pointer locations.
-        while (!downIdBits.isEmpty()) {
-            uint32_t downId = downIdBits.clearFirstMarkedBit();
-            dispatchedIdBits.markBit(downId);
-
-            if (dispatchedIdBits.count() == 1) {
-                // First pointer is going down.  Set down time.
-                mDownTime = when;
-            }
-
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
-                    mCurrentCookedPointerData.pointerProperties,
-                    mCurrentCookedPointerData.pointerCoords,
-                    mCurrentCookedPointerData.idToIndex,
-                    dispatchedIdBits, downId,
-                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-        }
-    }
-}
-
-void TouchInputMapper::dispatchHoverExit(nsecs_t when, uint32_t policyFlags) {
-    if (mSentHoverEnter &&
-            (mCurrentCookedPointerData.hoveringIdBits.isEmpty()
-                    || !mCurrentCookedPointerData.touchingIdBits.isEmpty())) {
-        int32_t metaState = getContext()->getGlobalMetaState();
-        dispatchMotion(when, policyFlags, mSource,
-                AMOTION_EVENT_ACTION_HOVER_EXIT, 0, metaState, mLastButtonState, 0,
-                mLastCookedPointerData.pointerProperties,
-                mLastCookedPointerData.pointerCoords,
-                mLastCookedPointerData.idToIndex,
-                mLastCookedPointerData.hoveringIdBits, -1,
-                mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-        mSentHoverEnter = false;
-    }
-}
-
-void TouchInputMapper::dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags) {
-    if (mCurrentCookedPointerData.touchingIdBits.isEmpty()
-            && !mCurrentCookedPointerData.hoveringIdBits.isEmpty()) {
-        int32_t metaState = getContext()->getGlobalMetaState();
-        if (!mSentHoverEnter) {
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_HOVER_ENTER, 0, metaState, mCurrentButtonState, 0,
-                    mCurrentCookedPointerData.pointerProperties,
-                    mCurrentCookedPointerData.pointerCoords,
-                    mCurrentCookedPointerData.idToIndex,
-                    mCurrentCookedPointerData.hoveringIdBits, -1,
-                    mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-            mSentHoverEnter = true;
-        }
-
-        dispatchMotion(when, policyFlags, mSource,
-                AMOTION_EVENT_ACTION_HOVER_MOVE, 0, metaState, mCurrentButtonState, 0,
-                mCurrentCookedPointerData.pointerProperties,
-                mCurrentCookedPointerData.pointerCoords,
-                mCurrentCookedPointerData.idToIndex,
-                mCurrentCookedPointerData.hoveringIdBits, -1,
-                mOrientedXPrecision, mOrientedYPrecision, mDownTime);
-    }
-}
-
-void TouchInputMapper::cookPointerData() {
-    uint32_t currentPointerCount = mCurrentRawPointerData.pointerCount;
-
-    mCurrentCookedPointerData.clear();
-    mCurrentCookedPointerData.pointerCount = currentPointerCount;
-    mCurrentCookedPointerData.hoveringIdBits = mCurrentRawPointerData.hoveringIdBits;
-    mCurrentCookedPointerData.touchingIdBits = mCurrentRawPointerData.touchingIdBits;
-
-    // Walk through the the active pointers and map device coordinates onto
-    // surface coordinates and adjust for display orientation.
-    for (uint32_t i = 0; i < currentPointerCount; i++) {
-        const RawPointerData::Pointer& in = mCurrentRawPointerData.pointers[i];
-
-        // Size
-        float touchMajor, touchMinor, toolMajor, toolMinor, size;
-        switch (mCalibration.sizeCalibration) {
-        case Calibration::SIZE_CALIBRATION_GEOMETRIC:
-        case Calibration::SIZE_CALIBRATION_DIAMETER:
-        case Calibration::SIZE_CALIBRATION_BOX:
-        case Calibration::SIZE_CALIBRATION_AREA:
-            if (mRawPointerAxes.touchMajor.valid && mRawPointerAxes.toolMajor.valid) {
-                touchMajor = in.touchMajor;
-                touchMinor = mRawPointerAxes.touchMinor.valid ? in.touchMinor : in.touchMajor;
-                toolMajor = in.toolMajor;
-                toolMinor = mRawPointerAxes.toolMinor.valid ? in.toolMinor : in.toolMajor;
-                size = mRawPointerAxes.touchMinor.valid
-                        ? avg(in.touchMajor, in.touchMinor) : in.touchMajor;
-            } else if (mRawPointerAxes.touchMajor.valid) {
-                toolMajor = touchMajor = in.touchMajor;
-                toolMinor = touchMinor = mRawPointerAxes.touchMinor.valid
-                        ? in.touchMinor : in.touchMajor;
-                size = mRawPointerAxes.touchMinor.valid
-                        ? avg(in.touchMajor, in.touchMinor) : in.touchMajor;
-            } else if (mRawPointerAxes.toolMajor.valid) {
-                touchMajor = toolMajor = in.toolMajor;
-                touchMinor = toolMinor = mRawPointerAxes.toolMinor.valid
-                        ? in.toolMinor : in.toolMajor;
-                size = mRawPointerAxes.toolMinor.valid
-                        ? avg(in.toolMajor, in.toolMinor) : in.toolMajor;
-            } else {
-                ALOG_ASSERT(false, "No touch or tool axes.  "
-                        "Size calibration should have been resolved to NONE.");
-                touchMajor = 0;
-                touchMinor = 0;
-                toolMajor = 0;
-                toolMinor = 0;
-                size = 0;
-            }
-
-            if (mCalibration.haveSizeIsSummed && mCalibration.sizeIsSummed) {
-                uint32_t touchingCount = mCurrentRawPointerData.touchingIdBits.count();
-                if (touchingCount > 1) {
-                    touchMajor /= touchingCount;
-                    touchMinor /= touchingCount;
-                    toolMajor /= touchingCount;
-                    toolMinor /= touchingCount;
-                    size /= touchingCount;
-                }
-            }
-
-            if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_GEOMETRIC) {
-                touchMajor *= mGeometricScale;
-                touchMinor *= mGeometricScale;
-                toolMajor *= mGeometricScale;
-                toolMinor *= mGeometricScale;
-            } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_AREA) {
-                touchMajor = touchMajor > 0 ? sqrtf(touchMajor) : 0;
-                touchMinor = touchMajor;
-                toolMajor = toolMajor > 0 ? sqrtf(toolMajor) : 0;
-                toolMinor = toolMajor;
-            } else if (mCalibration.sizeCalibration == Calibration::SIZE_CALIBRATION_DIAMETER) {
-                touchMinor = touchMajor;
-                toolMinor = toolMajor;
-            }
-
-            mCalibration.applySizeScaleAndBias(&touchMajor);
-            mCalibration.applySizeScaleAndBias(&touchMinor);
-            mCalibration.applySizeScaleAndBias(&toolMajor);
-            mCalibration.applySizeScaleAndBias(&toolMinor);
-            size *= mSizeScale;
-            break;
-        default:
-            touchMajor = 0;
-            touchMinor = 0;
-            toolMajor = 0;
-            toolMinor = 0;
-            size = 0;
-            break;
-        }
-
-        // Pressure
-        float pressure;
-        switch (mCalibration.pressureCalibration) {
-        case Calibration::PRESSURE_CALIBRATION_PHYSICAL:
-        case Calibration::PRESSURE_CALIBRATION_AMPLITUDE:
-            pressure = in.pressure * mPressureScale;
-            break;
-        default:
-            pressure = in.isHovering ? 0 : 1;
-            break;
-        }
-
-        // Tilt and Orientation
-        float tilt;
-        float orientation;
-        if (mHaveTilt) {
-            float tiltXAngle = (in.tiltX - mTiltXCenter) * mTiltXScale;
-            float tiltYAngle = (in.tiltY - mTiltYCenter) * mTiltYScale;
-            orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle));
-            tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle));
-        } else {
-            tilt = 0;
-
-            switch (mCalibration.orientationCalibration) {
-            case Calibration::ORIENTATION_CALIBRATION_INTERPOLATED:
-                orientation = in.orientation * mOrientationScale;
-                break;
-            case Calibration::ORIENTATION_CALIBRATION_VECTOR: {
-                int32_t c1 = signExtendNybble((in.orientation & 0xf0) >> 4);
-                int32_t c2 = signExtendNybble(in.orientation & 0x0f);
-                if (c1 != 0 || c2 != 0) {
-                    orientation = atan2f(c1, c2) * 0.5f;
-                    float confidence = hypotf(c1, c2);
-                    float scale = 1.0f + confidence / 16.0f;
-                    touchMajor *= scale;
-                    touchMinor /= scale;
-                    toolMajor *= scale;
-                    toolMinor /= scale;
-                } else {
-                    orientation = 0;
-                }
-                break;
-            }
-            default:
-                orientation = 0;
-            }
-        }
-
-        // Distance
-        float distance;
-        switch (mCalibration.distanceCalibration) {
-        case Calibration::DISTANCE_CALIBRATION_SCALED:
-            distance = in.distance * mDistanceScale;
-            break;
-        default:
-            distance = 0;
-        }
-
-        // Coverage
-        int32_t rawLeft, rawTop, rawRight, rawBottom;
-        switch (mCalibration.coverageCalibration) {
-        case Calibration::COVERAGE_CALIBRATION_BOX:
-            rawLeft = (in.toolMinor & 0xffff0000) >> 16;
-            rawRight = in.toolMinor & 0x0000ffff;
-            rawBottom = in.toolMajor & 0x0000ffff;
-            rawTop = (in.toolMajor & 0xffff0000) >> 16;
-            break;
-        default:
-            rawLeft = rawTop = rawRight = rawBottom = 0;
-            break;
-        }
-
-        // X, Y, and the bounding box for coverage information
-        // Adjust coords for surface orientation.
-        float x, y, left, top, right, bottom;
-        switch (mSurfaceOrientation) {
-        case DISPLAY_ORIENTATION_90:
-            x = float(in.y - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
-            y = float(mRawPointerAxes.x.maxValue - in.x) * mXScale + mXTranslate;
-            left = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
-            right = float(rawBottom- mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
-            bottom = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate;
-            top = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate;
-            orientation -= M_PI_2;
-            if (orientation < mOrientedRanges.orientation.min) {
-                orientation += (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min);
-            }
-            break;
-        case DISPLAY_ORIENTATION_180:
-            x = float(mRawPointerAxes.x.maxValue - in.x) * mXScale + mXTranslate;
-            y = float(mRawPointerAxes.y.maxValue - in.y) * mYScale + mYTranslate;
-            left = float(mRawPointerAxes.x.maxValue - rawRight) * mXScale + mXTranslate;
-            right = float(mRawPointerAxes.x.maxValue - rawLeft) * mXScale + mXTranslate;
-            bottom = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate;
-            top = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate;
-            orientation -= M_PI;
-            if (orientation < mOrientedRanges.orientation.min) {
-                orientation += (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min);
-            }
-            break;
-        case DISPLAY_ORIENTATION_270:
-            x = float(mRawPointerAxes.y.maxValue - in.y) * mYScale + mYTranslate;
-            y = float(in.x - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
-            left = float(mRawPointerAxes.y.maxValue - rawBottom) * mYScale + mYTranslate;
-            right = float(mRawPointerAxes.y.maxValue - rawTop) * mYScale + mYTranslate;
-            bottom = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
-            top = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
-            orientation += M_PI_2;
-            if (orientation > mOrientedRanges.orientation.max) {
-                orientation -= (mOrientedRanges.orientation.max - mOrientedRanges.orientation.min);
-            }
-            break;
-        default:
-            x = float(in.x - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
-            y = float(in.y - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
-            left = float(rawLeft - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
-            right = float(rawRight - mRawPointerAxes.x.minValue) * mXScale + mXTranslate;
-            bottom = float(rawBottom - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
-            top = float(rawTop - mRawPointerAxes.y.minValue) * mYScale + mYTranslate;
-            break;
-        }
-
-        // Write output coords.
-        PointerCoords& out = mCurrentCookedPointerData.pointerCoords[i];
-        out.clear();
-        out.setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        out.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-        out.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
-        out.setAxisValue(AMOTION_EVENT_AXIS_SIZE, size);
-        out.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, touchMajor);
-        out.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, touchMinor);
-        out.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, orientation);
-        out.setAxisValue(AMOTION_EVENT_AXIS_TILT, tilt);
-        out.setAxisValue(AMOTION_EVENT_AXIS_DISTANCE, distance);
-        if (mCalibration.coverageCalibration == Calibration::COVERAGE_CALIBRATION_BOX) {
-            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_1, left);
-            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_2, top);
-            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_3, right);
-            out.setAxisValue(AMOTION_EVENT_AXIS_GENERIC_4, bottom);
-        } else {
-            out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, toolMajor);
-            out.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, toolMinor);
-        }
-
-        // Write output properties.
-        PointerProperties& properties = mCurrentCookedPointerData.pointerProperties[i];
-        uint32_t id = in.id;
-        properties.clear();
-        properties.id = id;
-        properties.toolType = in.toolType;
-
-        // Write id index.
-        mCurrentCookedPointerData.idToIndex[id] = i;
-    }
-}
-
-void TouchInputMapper::dispatchPointerUsage(nsecs_t when, uint32_t policyFlags,
-        PointerUsage pointerUsage) {
-    if (pointerUsage != mPointerUsage) {
-        abortPointerUsage(when, policyFlags);
-        mPointerUsage = pointerUsage;
-    }
-
-    switch (mPointerUsage) {
-    case POINTER_USAGE_GESTURES:
-        dispatchPointerGestures(when, policyFlags, false /*isTimeout*/);
-        break;
-    case POINTER_USAGE_STYLUS:
-        dispatchPointerStylus(when, policyFlags);
-        break;
-    case POINTER_USAGE_MOUSE:
-        dispatchPointerMouse(when, policyFlags);
-        break;
-    default:
-        break;
-    }
-}
-
-void TouchInputMapper::abortPointerUsage(nsecs_t when, uint32_t policyFlags) {
-    switch (mPointerUsage) {
-    case POINTER_USAGE_GESTURES:
-        abortPointerGestures(when, policyFlags);
-        break;
-    case POINTER_USAGE_STYLUS:
-        abortPointerStylus(when, policyFlags);
-        break;
-    case POINTER_USAGE_MOUSE:
-        abortPointerMouse(when, policyFlags);
-        break;
-    default:
-        break;
-    }
-
-    mPointerUsage = POINTER_USAGE_NONE;
-}
-
-void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlags,
-        bool isTimeout) {
-    // Update current gesture coordinates.
-    bool cancelPreviousGesture, finishPreviousGesture;
-    bool sendEvents = preparePointerGestures(when,
-            &cancelPreviousGesture, &finishPreviousGesture, isTimeout);
-    if (!sendEvents) {
-        return;
-    }
-    if (finishPreviousGesture) {
-        cancelPreviousGesture = false;
-    }
-
-    // Update the pointer presentation and spots.
-    if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-        mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_SPOT);
-        if (finishPreviousGesture || cancelPreviousGesture) {
-            mPointerController->clearSpots();
-        }
-        mPointerController->setSpots(mPointerGesture.currentGestureCoords,
-                mPointerGesture.currentGestureIdToIndex,
-                mPointerGesture.currentGestureIdBits);
-    } else {
-        mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
-    }
-
-    // Show or hide the pointer if needed.
-    switch (mPointerGesture.currentGestureMode) {
-    case PointerGesture::NEUTRAL:
-    case PointerGesture::QUIET:
-        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS
-                && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE
-                        || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) {
-            // Remind the user of where the pointer is after finishing a gesture with spots.
-            mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL);
-        }
-        break;
-    case PointerGesture::TAP:
-    case PointerGesture::TAP_DRAG:
-    case PointerGesture::BUTTON_CLICK_OR_DRAG:
-    case PointerGesture::HOVER:
-    case PointerGesture::PRESS:
-        // Unfade the pointer when the current gesture manipulates the
-        // area directly under the pointer.
-        mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
-        break;
-    case PointerGesture::SWIPE:
-    case PointerGesture::FREEFORM:
-        // Fade the pointer when the current gesture manipulates a different
-        // area and there are spots to guide the user experience.
-        if (mParameters.gestureMode == Parameters::GESTURE_MODE_SPOTS) {
-            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-        } else {
-            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
-        }
-        break;
-    }
-
-    // Send events!
-    int32_t metaState = getContext()->getGlobalMetaState();
-    int32_t buttonState = mCurrentButtonState;
-
-    // Update last coordinates of pointers that have moved so that we observe the new
-    // pointer positions at the same time as other pointers that have just gone up.
-    bool down = mPointerGesture.currentGestureMode == PointerGesture::TAP
-            || mPointerGesture.currentGestureMode == PointerGesture::TAP_DRAG
-            || mPointerGesture.currentGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG
-            || mPointerGesture.currentGestureMode == PointerGesture::PRESS
-            || mPointerGesture.currentGestureMode == PointerGesture::SWIPE
-            || mPointerGesture.currentGestureMode == PointerGesture::FREEFORM;
-    bool moveNeeded = false;
-    if (down && !cancelPreviousGesture && !finishPreviousGesture
-            && !mPointerGesture.lastGestureIdBits.isEmpty()
-            && !mPointerGesture.currentGestureIdBits.isEmpty()) {
-        BitSet32 movedGestureIdBits(mPointerGesture.currentGestureIdBits.value
-                & mPointerGesture.lastGestureIdBits.value);
-        moveNeeded = updateMovedPointers(mPointerGesture.currentGestureProperties,
-                mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
-                mPointerGesture.lastGestureProperties,
-                mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
-                movedGestureIdBits);
-        if (buttonState != mLastButtonState) {
-            moveNeeded = true;
-        }
-    }
-
-    // Send motion events for all pointers that went up or were canceled.
-    BitSet32 dispatchedGestureIdBits(mPointerGesture.lastGestureIdBits);
-    if (!dispatchedGestureIdBits.isEmpty()) {
-        if (cancelPreviousGesture) {
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_CANCEL, 0, metaState, buttonState,
-                    AMOTION_EVENT_EDGE_FLAG_NONE,
-                    mPointerGesture.lastGestureProperties,
-                    mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
-                    dispatchedGestureIdBits, -1,
-                    0, 0, mPointerGesture.downTime);
-
-            dispatchedGestureIdBits.clear();
-        } else {
-            BitSet32 upGestureIdBits;
-            if (finishPreviousGesture) {
-                upGestureIdBits = dispatchedGestureIdBits;
-            } else {
-                upGestureIdBits.value = dispatchedGestureIdBits.value
-                        & ~mPointerGesture.currentGestureIdBits.value;
-            }
-            while (!upGestureIdBits.isEmpty()) {
-                uint32_t id = upGestureIdBits.clearFirstMarkedBit();
-
-                dispatchMotion(when, policyFlags, mSource,
-                        AMOTION_EVENT_ACTION_POINTER_UP, 0,
-                        metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
-                        mPointerGesture.lastGestureProperties,
-                        mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
-                        dispatchedGestureIdBits, id,
-                        0, 0, mPointerGesture.downTime);
-
-                dispatchedGestureIdBits.clearBit(id);
-            }
-        }
-    }
-
-    // Send motion events for all pointers that moved.
-    if (moveNeeded) {
-        dispatchMotion(when, policyFlags, mSource,
-                AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
-                mPointerGesture.currentGestureProperties,
-                mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
-                dispatchedGestureIdBits, -1,
-                0, 0, mPointerGesture.downTime);
-    }
-
-    // Send motion events for all pointers that went down.
-    if (down) {
-        BitSet32 downGestureIdBits(mPointerGesture.currentGestureIdBits.value
-                & ~dispatchedGestureIdBits.value);
-        while (!downGestureIdBits.isEmpty()) {
-            uint32_t id = downGestureIdBits.clearFirstMarkedBit();
-            dispatchedGestureIdBits.markBit(id);
-
-            if (dispatchedGestureIdBits.count() == 1) {
-                mPointerGesture.downTime = when;
-            }
-
-            dispatchMotion(when, policyFlags, mSource,
-                    AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
-                    mPointerGesture.currentGestureProperties,
-                    mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
-                    dispatchedGestureIdBits, id,
-                    0, 0, mPointerGesture.downTime);
-        }
-    }
-
-    // Send motion events for hover.
-    if (mPointerGesture.currentGestureMode == PointerGesture::HOVER) {
-        dispatchMotion(when, policyFlags, mSource,
-                AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
-                metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
-                mPointerGesture.currentGestureProperties,
-                mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
-                mPointerGesture.currentGestureIdBits, -1,
-                0, 0, mPointerGesture.downTime);
-    } else if (dispatchedGestureIdBits.isEmpty()
-            && !mPointerGesture.lastGestureIdBits.isEmpty()) {
-        // Synthesize a hover move event after all pointers go up to indicate that
-        // the pointer is hovering again even if the user is not currently touching
-        // the touch pad.  This ensures that a view will receive a fresh hover enter
-        // event after a tap.
-        float x, y;
-        mPointerController->getPosition(&x, &y);
-
-        PointerProperties pointerProperties;
-        pointerProperties.clear();
-        pointerProperties.id = 0;
-        pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
-
-        PointerCoords pointerCoords;
-        pointerCoords.clear();
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
-                metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
-                mViewport.displayId, 1, &pointerProperties, &pointerCoords,
-                0, 0, mPointerGesture.downTime);
-        getListener()->notifyMotion(&args);
-    }
-
-    // Update state.
-    mPointerGesture.lastGestureMode = mPointerGesture.currentGestureMode;
-    if (!down) {
-        mPointerGesture.lastGestureIdBits.clear();
-    } else {
-        mPointerGesture.lastGestureIdBits = mPointerGesture.currentGestureIdBits;
-        for (BitSet32 idBits(mPointerGesture.currentGestureIdBits); !idBits.isEmpty(); ) {
-            uint32_t id = idBits.clearFirstMarkedBit();
-            uint32_t index = mPointerGesture.currentGestureIdToIndex[id];
-            mPointerGesture.lastGestureProperties[index].copyFrom(
-                    mPointerGesture.currentGestureProperties[index]);
-            mPointerGesture.lastGestureCoords[index].copyFrom(
-                    mPointerGesture.currentGestureCoords[index]);
-            mPointerGesture.lastGestureIdToIndex[id] = index;
-        }
-    }
-}
-
-void TouchInputMapper::abortPointerGestures(nsecs_t when, uint32_t policyFlags) {
-    // Cancel previously dispatches pointers.
-    if (!mPointerGesture.lastGestureIdBits.isEmpty()) {
-        int32_t metaState = getContext()->getGlobalMetaState();
-        int32_t buttonState = mCurrentButtonState;
-        dispatchMotion(when, policyFlags, mSource,
-                AMOTION_EVENT_ACTION_CANCEL, 0, metaState, buttonState,
-                AMOTION_EVENT_EDGE_FLAG_NONE,
-                mPointerGesture.lastGestureProperties,
-                mPointerGesture.lastGestureCoords, mPointerGesture.lastGestureIdToIndex,
-                mPointerGesture.lastGestureIdBits, -1,
-                0, 0, mPointerGesture.downTime);
-    }
-
-    // Reset the current pointer gesture.
-    mPointerGesture.reset();
-    mPointerVelocityControl.reset();
-
-    // Remove any current spots.
-    if (mPointerController != NULL) {
-        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-        mPointerController->clearSpots();
-    }
-}
-
-bool TouchInputMapper::preparePointerGestures(nsecs_t when,
-        bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout) {
-    *outCancelPreviousGesture = false;
-    *outFinishPreviousGesture = false;
-
-    // Handle TAP timeout.
-    if (isTimeout) {
-#if DEBUG_GESTURES
-        ALOGD("Gestures: Processing timeout");
-#endif
-
-        if (mPointerGesture.lastGestureMode == PointerGesture::TAP) {
-            if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
-                // The tap/drag timeout has not yet expired.
-                getContext()->requestTimeoutAtTime(mPointerGesture.tapUpTime
-                        + mConfig.pointerGestureTapDragInterval);
-            } else {
-                // The tap is finished.
-#if DEBUG_GESTURES
-                ALOGD("Gestures: TAP finished");
-#endif
-                *outFinishPreviousGesture = true;
-
-                mPointerGesture.activeGestureId = -1;
-                mPointerGesture.currentGestureMode = PointerGesture::NEUTRAL;
-                mPointerGesture.currentGestureIdBits.clear();
-
-                mPointerVelocityControl.reset();
-                return true;
-            }
-        }
-
-        // We did not handle this timeout.
-        return false;
-    }
-
-    const uint32_t currentFingerCount = mCurrentFingerIdBits.count();
-    const uint32_t lastFingerCount = mLastFingerIdBits.count();
-
-    // Update the velocity tracker.
-    {
-        VelocityTracker::Position positions[MAX_POINTERS];
-        uint32_t count = 0;
-        for (BitSet32 idBits(mCurrentFingerIdBits); !idBits.isEmpty(); count++) {
-            uint32_t id = idBits.clearFirstMarkedBit();
-            const RawPointerData::Pointer& pointer = mCurrentRawPointerData.pointerForId(id);
-            positions[count].x = pointer.x * mPointerXMovementScale;
-            positions[count].y = pointer.y * mPointerYMovementScale;
-        }
-        mPointerGesture.velocityTracker.addMovement(when,
-                mCurrentFingerIdBits, positions);
-    }
-
-    // If the gesture ever enters a mode other than TAP, HOVER or TAP_DRAG, without first returning
-    // to NEUTRAL, then we should not generate tap event.
-    if (mPointerGesture.lastGestureMode != PointerGesture::HOVER
-            && mPointerGesture.lastGestureMode != PointerGesture::TAP
-            && mPointerGesture.lastGestureMode != PointerGesture::TAP_DRAG) {
-        mPointerGesture.resetTap();
-    }
-
-    // Pick a new active touch id if needed.
-    // Choose an arbitrary pointer that just went down, if there is one.
-    // Otherwise choose an arbitrary remaining pointer.
-    // This guarantees we always have an active touch id when there is at least one pointer.
-    // We keep the same active touch id for as long as possible.
-    bool activeTouchChanged = false;
-    int32_t lastActiveTouchId = mPointerGesture.activeTouchId;
-    int32_t activeTouchId = lastActiveTouchId;
-    if (activeTouchId < 0) {
-        if (!mCurrentFingerIdBits.isEmpty()) {
-            activeTouchChanged = true;
-            activeTouchId = mPointerGesture.activeTouchId =
-                    mCurrentFingerIdBits.firstMarkedBit();
-            mPointerGesture.firstTouchTime = when;
-        }
-    } else if (!mCurrentFingerIdBits.hasBit(activeTouchId)) {
-        activeTouchChanged = true;
-        if (!mCurrentFingerIdBits.isEmpty()) {
-            activeTouchId = mPointerGesture.activeTouchId =
-                    mCurrentFingerIdBits.firstMarkedBit();
-        } else {
-            activeTouchId = mPointerGesture.activeTouchId = -1;
-        }
-    }
-
-    // Determine whether we are in quiet time.
-    bool isQuietTime = false;
-    if (activeTouchId < 0) {
-        mPointerGesture.resetQuietTime();
-    } else {
-        isQuietTime = when < mPointerGesture.quietTime + mConfig.pointerGestureQuietInterval;
-        if (!isQuietTime) {
-            if ((mPointerGesture.lastGestureMode == PointerGesture::PRESS
-                    || mPointerGesture.lastGestureMode == PointerGesture::SWIPE
-                    || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)
-                    && currentFingerCount < 2) {
-                // Enter quiet time when exiting swipe or freeform state.
-                // This is to prevent accidentally entering the hover state and flinging the
-                // pointer when finishing a swipe and there is still one pointer left onscreen.
-                isQuietTime = true;
-            } else if (mPointerGesture.lastGestureMode == PointerGesture::BUTTON_CLICK_OR_DRAG
-                    && currentFingerCount >= 2
-                    && !isPointerDown(mCurrentButtonState)) {
-                // Enter quiet time when releasing the button and there are still two or more
-                // fingers down.  This may indicate that one finger was used to press the button
-                // but it has not gone up yet.
-                isQuietTime = true;
-            }
-            if (isQuietTime) {
-                mPointerGesture.quietTime = when;
-            }
-        }
-    }
-
-    // Switch states based on button and pointer state.
-    if (isQuietTime) {
-        // Case 1: Quiet time. (QUIET)
-#if DEBUG_GESTURES
-        ALOGD("Gestures: QUIET for next %0.3fms", (mPointerGesture.quietTime
-                + mConfig.pointerGestureQuietInterval - when) * 0.000001f);
-#endif
-        if (mPointerGesture.lastGestureMode != PointerGesture::QUIET) {
-            *outFinishPreviousGesture = true;
-        }
-
-        mPointerGesture.activeGestureId = -1;
-        mPointerGesture.currentGestureMode = PointerGesture::QUIET;
-        mPointerGesture.currentGestureIdBits.clear();
-
-        mPointerVelocityControl.reset();
-    } else if (isPointerDown(mCurrentButtonState)) {
-        // Case 2: Button is pressed. (BUTTON_CLICK_OR_DRAG)
-        // The pointer follows the active touch point.
-        // Emit DOWN, MOVE, UP events at the pointer location.
-        //
-        // Only the active touch matters; other fingers are ignored.  This policy helps
-        // to handle the case where the user places a second finger on the touch pad
-        // to apply the necessary force to depress an integrated button below the surface.
-        // We don't want the second finger to be delivered to applications.
-        //
-        // For this to work well, we need to make sure to track the pointer that is really
-        // active.  If the user first puts one finger down to click then adds another
-        // finger to drag then the active pointer should switch to the finger that is
-        // being dragged.
-#if DEBUG_GESTURES
-        ALOGD("Gestures: BUTTON_CLICK_OR_DRAG activeTouchId=%d, "
-                "currentFingerCount=%d", activeTouchId, currentFingerCount);
-#endif
-        // Reset state when just starting.
-        if (mPointerGesture.lastGestureMode != PointerGesture::BUTTON_CLICK_OR_DRAG) {
-            *outFinishPreviousGesture = true;
-            mPointerGesture.activeGestureId = 0;
-        }
-
-        // Switch pointers if needed.
-        // Find the fastest pointer and follow it.
-        if (activeTouchId >= 0 && currentFingerCount > 1) {
-            int32_t bestId = -1;
-            float bestSpeed = mConfig.pointerGestureDragMinSwitchSpeed;
-            for (BitSet32 idBits(mCurrentFingerIdBits); !idBits.isEmpty(); ) {
-                uint32_t id = idBits.clearFirstMarkedBit();
-                float vx, vy;
-                if (mPointerGesture.velocityTracker.getVelocity(id, &vx, &vy)) {
-                    float speed = hypotf(vx, vy);
-                    if (speed > bestSpeed) {
-                        bestId = id;
-                        bestSpeed = speed;
-                    }
-                }
-            }
-            if (bestId >= 0 && bestId != activeTouchId) {
-                mPointerGesture.activeTouchId = activeTouchId = bestId;
-                activeTouchChanged = true;
-#if DEBUG_GESTURES
-                ALOGD("Gestures: BUTTON_CLICK_OR_DRAG switched pointers, "
-                        "bestId=%d, bestSpeed=%0.3f", bestId, bestSpeed);
-#endif
-            }
-        }
-
-        if (activeTouchId >= 0 && mLastFingerIdBits.hasBit(activeTouchId)) {
-            const RawPointerData::Pointer& currentPointer =
-                    mCurrentRawPointerData.pointerForId(activeTouchId);
-            const RawPointerData::Pointer& lastPointer =
-                    mLastRawPointerData.pointerForId(activeTouchId);
-            float deltaX = (currentPointer.x - lastPointer.x) * mPointerXMovementScale;
-            float deltaY = (currentPointer.y - lastPointer.y) * mPointerYMovementScale;
-
-            rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
-            mPointerVelocityControl.move(when, &deltaX, &deltaY);
-
-            // Move the pointer using a relative motion.
-            // When using spots, the click will occur at the position of the anchor
-            // spot and all other spots will move there.
-            mPointerController->move(deltaX, deltaY);
-        } else {
-            mPointerVelocityControl.reset();
-        }
-
-        float x, y;
-        mPointerController->getPosition(&x, &y);
-
-        mPointerGesture.currentGestureMode = PointerGesture::BUTTON_CLICK_OR_DRAG;
-        mPointerGesture.currentGestureIdBits.clear();
-        mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
-        mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
-        mPointerGesture.currentGestureProperties[0].clear();
-        mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
-        mPointerGesture.currentGestureProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
-        mPointerGesture.currentGestureCoords[0].clear();
-        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-    } else if (currentFingerCount == 0) {
-        // Case 3. No fingers down and button is not pressed. (NEUTRAL)
-        if (mPointerGesture.lastGestureMode != PointerGesture::NEUTRAL) {
-            *outFinishPreviousGesture = true;
-        }
-
-        // Watch for taps coming out of HOVER or TAP_DRAG mode.
-        // Checking for taps after TAP_DRAG allows us to detect double-taps.
-        bool tapped = false;
-        if ((mPointerGesture.lastGestureMode == PointerGesture::HOVER
-                || mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG)
-                && lastFingerCount == 1) {
-            if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) {
-                float x, y;
-                mPointerController->getPosition(&x, &y);
-                if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop
-                        && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
-#if DEBUG_GESTURES
-                    ALOGD("Gestures: TAP");
-#endif
-
-                    mPointerGesture.tapUpTime = when;
-                    getContext()->requestTimeoutAtTime(when
-                            + mConfig.pointerGestureTapDragInterval);
-
-                    mPointerGesture.activeGestureId = 0;
-                    mPointerGesture.currentGestureMode = PointerGesture::TAP;
-                    mPointerGesture.currentGestureIdBits.clear();
-                    mPointerGesture.currentGestureIdBits.markBit(
-                            mPointerGesture.activeGestureId);
-                    mPointerGesture.currentGestureIdToIndex[
-                            mPointerGesture.activeGestureId] = 0;
-                    mPointerGesture.currentGestureProperties[0].clear();
-                    mPointerGesture.currentGestureProperties[0].id =
-                            mPointerGesture.activeGestureId;
-                    mPointerGesture.currentGestureProperties[0].toolType =
-                            AMOTION_EVENT_TOOL_TYPE_FINGER;
-                    mPointerGesture.currentGestureCoords[0].clear();
-                    mPointerGesture.currentGestureCoords[0].setAxisValue(
-                            AMOTION_EVENT_AXIS_X, mPointerGesture.tapX);
-                    mPointerGesture.currentGestureCoords[0].setAxisValue(
-                            AMOTION_EVENT_AXIS_Y, mPointerGesture.tapY);
-                    mPointerGesture.currentGestureCoords[0].setAxisValue(
-                            AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-
-                    tapped = true;
-                } else {
-#if DEBUG_GESTURES
-                    ALOGD("Gestures: Not a TAP, deltaX=%f, deltaY=%f",
-                            x - mPointerGesture.tapX,
-                            y - mPointerGesture.tapY);
-#endif
-                }
-            } else {
-#if DEBUG_GESTURES
-                if (mPointerGesture.tapDownTime != LLONG_MIN) {
-                    ALOGD("Gestures: Not a TAP, %0.3fms since down",
-                            (when - mPointerGesture.tapDownTime) * 0.000001f);
-                } else {
-                    ALOGD("Gestures: Not a TAP, incompatible mode transitions");
-                }
-#endif
-            }
-        }
-
-        mPointerVelocityControl.reset();
-
-        if (!tapped) {
-#if DEBUG_GESTURES
-            ALOGD("Gestures: NEUTRAL");
-#endif
-            mPointerGesture.activeGestureId = -1;
-            mPointerGesture.currentGestureMode = PointerGesture::NEUTRAL;
-            mPointerGesture.currentGestureIdBits.clear();
-        }
-    } else if (currentFingerCount == 1) {
-        // Case 4. Exactly one finger down, button is not pressed. (HOVER or TAP_DRAG)
-        // The pointer follows the active touch point.
-        // When in HOVER, emit HOVER_MOVE events at the pointer location.
-        // When in TAP_DRAG, emit MOVE events at the pointer location.
-        ALOG_ASSERT(activeTouchId >= 0);
-
-        mPointerGesture.currentGestureMode = PointerGesture::HOVER;
-        if (mPointerGesture.lastGestureMode == PointerGesture::TAP) {
-            if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
-                float x, y;
-                mPointerController->getPosition(&x, &y);
-                if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop
-                        && fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
-                    mPointerGesture.currentGestureMode = PointerGesture::TAP_DRAG;
-                } else {
-#if DEBUG_GESTURES
-                    ALOGD("Gestures: Not a TAP_DRAG, deltaX=%f, deltaY=%f",
-                            x - mPointerGesture.tapX,
-                            y - mPointerGesture.tapY);
-#endif
-                }
-            } else {
-#if DEBUG_GESTURES
-                ALOGD("Gestures: Not a TAP_DRAG, %0.3fms time since up",
-                        (when - mPointerGesture.tapUpTime) * 0.000001f);
-#endif
-            }
-        } else if (mPointerGesture.lastGestureMode == PointerGesture::TAP_DRAG) {
-            mPointerGesture.currentGestureMode = PointerGesture::TAP_DRAG;
-        }
-
-        if (mLastFingerIdBits.hasBit(activeTouchId)) {
-            const RawPointerData::Pointer& currentPointer =
-                    mCurrentRawPointerData.pointerForId(activeTouchId);
-            const RawPointerData::Pointer& lastPointer =
-                    mLastRawPointerData.pointerForId(activeTouchId);
-            float deltaX = (currentPointer.x - lastPointer.x)
-                    * mPointerXMovementScale;
-            float deltaY = (currentPointer.y - lastPointer.y)
-                    * mPointerYMovementScale;
-
-            rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
-            mPointerVelocityControl.move(when, &deltaX, &deltaY);
-
-            // Move the pointer using a relative motion.
-            // When using spots, the hover or drag will occur at the position of the anchor spot.
-            mPointerController->move(deltaX, deltaY);
-        } else {
-            mPointerVelocityControl.reset();
-        }
-
-        bool down;
-        if (mPointerGesture.currentGestureMode == PointerGesture::TAP_DRAG) {
-#if DEBUG_GESTURES
-            ALOGD("Gestures: TAP_DRAG");
-#endif
-            down = true;
-        } else {
-#if DEBUG_GESTURES
-            ALOGD("Gestures: HOVER");
-#endif
-            if (mPointerGesture.lastGestureMode != PointerGesture::HOVER) {
-                *outFinishPreviousGesture = true;
-            }
-            mPointerGesture.activeGestureId = 0;
-            down = false;
-        }
-
-        float x, y;
-        mPointerController->getPosition(&x, &y);
-
-        mPointerGesture.currentGestureIdBits.clear();
-        mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
-        mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
-        mPointerGesture.currentGestureProperties[0].clear();
-        mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
-        mPointerGesture.currentGestureProperties[0].toolType =
-                AMOTION_EVENT_TOOL_TYPE_FINGER;
-        mPointerGesture.currentGestureCoords[0].clear();
-        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-        mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE,
-                down ? 1.0f : 0.0f);
-
-        if (lastFingerCount == 0 && currentFingerCount != 0) {
-            mPointerGesture.resetTap();
-            mPointerGesture.tapDownTime = when;
-            mPointerGesture.tapX = x;
-            mPointerGesture.tapY = y;
-        }
-    } else {
-        // Case 5. At least two fingers down, button is not pressed. (PRESS, SWIPE or FREEFORM)
-        // We need to provide feedback for each finger that goes down so we cannot wait
-        // for the fingers to move before deciding what to do.
-        //
-        // The ambiguous case is deciding what to do when there are two fingers down but they
-        // have not moved enough to determine whether they are part of a drag or part of a
-        // freeform gesture, or just a press or long-press at the pointer location.
-        //
-        // When there are two fingers we start with the PRESS hypothesis and we generate a
-        // down at the pointer location.
-        //
-        // When the two fingers move enough or when additional fingers are added, we make
-        // a decision to transition into SWIPE or FREEFORM mode accordingly.
-        ALOG_ASSERT(activeTouchId >= 0);
-
-        bool settled = when >= mPointerGesture.firstTouchTime
-                + mConfig.pointerGestureMultitouchSettleInterval;
-        if (mPointerGesture.lastGestureMode != PointerGesture::PRESS
-                && mPointerGesture.lastGestureMode != PointerGesture::SWIPE
-                && mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) {
-            *outFinishPreviousGesture = true;
-        } else if (!settled && currentFingerCount > lastFingerCount) {
-            // Additional pointers have gone down but not yet settled.
-            // Reset the gesture.
-#if DEBUG_GESTURES
-            ALOGD("Gestures: Resetting gesture since additional pointers went down for MULTITOUCH, "
-                    "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime
-                            + mConfig.pointerGestureMultitouchSettleInterval - when)
-                            * 0.000001f);
-#endif
-            *outCancelPreviousGesture = true;
-        } else {
-            // Continue previous gesture.
-            mPointerGesture.currentGestureMode = mPointerGesture.lastGestureMode;
-        }
-
-        if (*outFinishPreviousGesture || *outCancelPreviousGesture) {
-            mPointerGesture.currentGestureMode = PointerGesture::PRESS;
-            mPointerGesture.activeGestureId = 0;
-            mPointerGesture.referenceIdBits.clear();
-            mPointerVelocityControl.reset();
-
-            // Use the centroid and pointer location as the reference points for the gesture.
-#if DEBUG_GESTURES
-            ALOGD("Gestures: Using centroid as reference for MULTITOUCH, "
-                    "settle time remaining %0.3fms", (mPointerGesture.firstTouchTime
-                            + mConfig.pointerGestureMultitouchSettleInterval - when)
-                            * 0.000001f);
-#endif
-            mCurrentRawPointerData.getCentroidOfTouchingPointers(
-                    &mPointerGesture.referenceTouchX,
-                    &mPointerGesture.referenceTouchY);
-            mPointerController->getPosition(&mPointerGesture.referenceGestureX,
-                    &mPointerGesture.referenceGestureY);
-        }
-
-        // Clear the reference deltas for fingers not yet included in the reference calculation.
-        for (BitSet32 idBits(mCurrentFingerIdBits.value
-                & ~mPointerGesture.referenceIdBits.value); !idBits.isEmpty(); ) {
-            uint32_t id = idBits.clearFirstMarkedBit();
-            mPointerGesture.referenceDeltas[id].dx = 0;
-            mPointerGesture.referenceDeltas[id].dy = 0;
-        }
-        mPointerGesture.referenceIdBits = mCurrentFingerIdBits;
-
-        // Add delta for all fingers and calculate a common movement delta.
-        float commonDeltaX = 0, commonDeltaY = 0;
-        BitSet32 commonIdBits(mLastFingerIdBits.value
-                & mCurrentFingerIdBits.value);
-        for (BitSet32 idBits(commonIdBits); !idBits.isEmpty(); ) {
-            bool first = (idBits == commonIdBits);
-            uint32_t id = idBits.clearFirstMarkedBit();
-            const RawPointerData::Pointer& cpd = mCurrentRawPointerData.pointerForId(id);
-            const RawPointerData::Pointer& lpd = mLastRawPointerData.pointerForId(id);
-            PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
-            delta.dx += cpd.x - lpd.x;
-            delta.dy += cpd.y - lpd.y;
-
-            if (first) {
-                commonDeltaX = delta.dx;
-                commonDeltaY = delta.dy;
-            } else {
-                commonDeltaX = calculateCommonVector(commonDeltaX, delta.dx);
-                commonDeltaY = calculateCommonVector(commonDeltaY, delta.dy);
-            }
-        }
-
-        // Consider transitions from PRESS to SWIPE or MULTITOUCH.
-        if (mPointerGesture.currentGestureMode == PointerGesture::PRESS) {
-            float dist[MAX_POINTER_ID + 1];
-            int32_t distOverThreshold = 0;
-            for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) {
-                uint32_t id = idBits.clearFirstMarkedBit();
-                PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
-                dist[id] = hypotf(delta.dx * mPointerXZoomScale,
-                        delta.dy * mPointerYZoomScale);
-                if (dist[id] > mConfig.pointerGestureMultitouchMinDistance) {
-                    distOverThreshold += 1;
-                }
-            }
-
-            // Only transition when at least two pointers have moved further than
-            // the minimum distance threshold.
-            if (distOverThreshold >= 2) {
-                if (currentFingerCount > 2) {
-                    // There are more than two pointers, switch to FREEFORM.
-#if DEBUG_GESTURES
-                    ALOGD("Gestures: PRESS transitioned to FREEFORM, number of pointers %d > 2",
-                            currentFingerCount);
-#endif
-                    *outCancelPreviousGesture = true;
-                    mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
-                } else {
-                    // There are exactly two pointers.
-                    BitSet32 idBits(mCurrentFingerIdBits);
-                    uint32_t id1 = idBits.clearFirstMarkedBit();
-                    uint32_t id2 = idBits.firstMarkedBit();
-                    const RawPointerData::Pointer& p1 = mCurrentRawPointerData.pointerForId(id1);
-                    const RawPointerData::Pointer& p2 = mCurrentRawPointerData.pointerForId(id2);
-                    float mutualDistance = distance(p1.x, p1.y, p2.x, p2.y);
-                    if (mutualDistance > mPointerGestureMaxSwipeWidth) {
-                        // There are two pointers but they are too far apart for a SWIPE,
-                        // switch to FREEFORM.
-#if DEBUG_GESTURES
-                        ALOGD("Gestures: PRESS transitioned to FREEFORM, distance %0.3f > %0.3f",
-                                mutualDistance, mPointerGestureMaxSwipeWidth);
-#endif
-                        *outCancelPreviousGesture = true;
-                        mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
-                    } else {
-                        // There are two pointers.  Wait for both pointers to start moving
-                        // before deciding whether this is a SWIPE or FREEFORM gesture.
-                        float dist1 = dist[id1];
-                        float dist2 = dist[id2];
-                        if (dist1 >= mConfig.pointerGestureMultitouchMinDistance
-                                && dist2 >= mConfig.pointerGestureMultitouchMinDistance) {
-                            // Calculate the dot product of the displacement vectors.
-                            // When the vectors are oriented in approximately the same direction,
-                            // the angle betweeen them is near zero and the cosine of the angle
-                            // approches 1.0.  Recall that dot(v1, v2) = cos(angle) * mag(v1) * mag(v2).
-                            PointerGesture::Delta& delta1 = mPointerGesture.referenceDeltas[id1];
-                            PointerGesture::Delta& delta2 = mPointerGesture.referenceDeltas[id2];
-                            float dx1 = delta1.dx * mPointerXZoomScale;
-                            float dy1 = delta1.dy * mPointerYZoomScale;
-                            float dx2 = delta2.dx * mPointerXZoomScale;
-                            float dy2 = delta2.dy * mPointerYZoomScale;
-                            float dot = dx1 * dx2 + dy1 * dy2;
-                            float cosine = dot / (dist1 * dist2); // denominator always > 0
-                            if (cosine >= mConfig.pointerGestureSwipeTransitionAngleCosine) {
-                                // Pointers are moving in the same direction.  Switch to SWIPE.
-#if DEBUG_GESTURES
-                                ALOGD("Gestures: PRESS transitioned to SWIPE, "
-                                        "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, "
-                                        "cosine %0.3f >= %0.3f",
-                                        dist1, mConfig.pointerGestureMultitouchMinDistance,
-                                        dist2, mConfig.pointerGestureMultitouchMinDistance,
-                                        cosine, mConfig.pointerGestureSwipeTransitionAngleCosine);
-#endif
-                                mPointerGesture.currentGestureMode = PointerGesture::SWIPE;
-                            } else {
-                                // Pointers are moving in different directions.  Switch to FREEFORM.
-#if DEBUG_GESTURES
-                                ALOGD("Gestures: PRESS transitioned to FREEFORM, "
-                                        "dist1 %0.3f >= %0.3f, dist2 %0.3f >= %0.3f, "
-                                        "cosine %0.3f < %0.3f",
-                                        dist1, mConfig.pointerGestureMultitouchMinDistance,
-                                        dist2, mConfig.pointerGestureMultitouchMinDistance,
-                                        cosine, mConfig.pointerGestureSwipeTransitionAngleCosine);
-#endif
-                                *outCancelPreviousGesture = true;
-                                mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
-                            }
-                        }
-                    }
-                }
-            }
-        } else if (mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
-            // Switch from SWIPE to FREEFORM if additional pointers go down.
-            // Cancel previous gesture.
-            if (currentFingerCount > 2) {
-#if DEBUG_GESTURES
-                ALOGD("Gestures: SWIPE transitioned to FREEFORM, number of pointers %d > 2",
-                        currentFingerCount);
-#endif
-                *outCancelPreviousGesture = true;
-                mPointerGesture.currentGestureMode = PointerGesture::FREEFORM;
-            }
-        }
-
-        // Move the reference points based on the overall group motion of the fingers
-        // except in PRESS mode while waiting for a transition to occur.
-        if (mPointerGesture.currentGestureMode != PointerGesture::PRESS
-                && (commonDeltaX || commonDeltaY)) {
-            for (BitSet32 idBits(mPointerGesture.referenceIdBits); !idBits.isEmpty(); ) {
-                uint32_t id = idBits.clearFirstMarkedBit();
-                PointerGesture::Delta& delta = mPointerGesture.referenceDeltas[id];
-                delta.dx = 0;
-                delta.dy = 0;
-            }
-
-            mPointerGesture.referenceTouchX += commonDeltaX;
-            mPointerGesture.referenceTouchY += commonDeltaY;
-
-            commonDeltaX *= mPointerXMovementScale;
-            commonDeltaY *= mPointerYMovementScale;
-
-            rotateDelta(mSurfaceOrientation, &commonDeltaX, &commonDeltaY);
-            mPointerVelocityControl.move(when, &commonDeltaX, &commonDeltaY);
-
-            mPointerGesture.referenceGestureX += commonDeltaX;
-            mPointerGesture.referenceGestureY += commonDeltaY;
-        }
-
-        // Report gestures.
-        if (mPointerGesture.currentGestureMode == PointerGesture::PRESS
-                || mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
-            // PRESS or SWIPE mode.
-#if DEBUG_GESTURES
-            ALOGD("Gestures: PRESS or SWIPE activeTouchId=%d,"
-                    "activeGestureId=%d, currentTouchPointerCount=%d",
-                    activeTouchId, mPointerGesture.activeGestureId, currentFingerCount);
-#endif
-            ALOG_ASSERT(mPointerGesture.activeGestureId >= 0);
-
-            mPointerGesture.currentGestureIdBits.clear();
-            mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
-            mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
-            mPointerGesture.currentGestureProperties[0].clear();
-            mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
-            mPointerGesture.currentGestureProperties[0].toolType =
-                    AMOTION_EVENT_TOOL_TYPE_FINGER;
-            mPointerGesture.currentGestureCoords[0].clear();
-            mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X,
-                    mPointerGesture.referenceGestureX);
-            mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y,
-                    mPointerGesture.referenceGestureY);
-            mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-        } else if (mPointerGesture.currentGestureMode == PointerGesture::FREEFORM) {
-            // FREEFORM mode.
-#if DEBUG_GESTURES
-            ALOGD("Gestures: FREEFORM activeTouchId=%d,"
-                    "activeGestureId=%d, currentTouchPointerCount=%d",
-                    activeTouchId, mPointerGesture.activeGestureId, currentFingerCount);
-#endif
-            ALOG_ASSERT(mPointerGesture.activeGestureId >= 0);
-
-            mPointerGesture.currentGestureIdBits.clear();
-
-            BitSet32 mappedTouchIdBits;
-            BitSet32 usedGestureIdBits;
-            if (mPointerGesture.lastGestureMode != PointerGesture::FREEFORM) {
-                // Initially, assign the active gesture id to the active touch point
-                // if there is one.  No other touch id bits are mapped yet.
-                if (!*outCancelPreviousGesture) {
-                    mappedTouchIdBits.markBit(activeTouchId);
-                    usedGestureIdBits.markBit(mPointerGesture.activeGestureId);
-                    mPointerGesture.freeformTouchToGestureIdMap[activeTouchId] =
-                            mPointerGesture.activeGestureId;
-                } else {
-                    mPointerGesture.activeGestureId = -1;
-                }
-            } else {
-                // Otherwise, assume we mapped all touches from the previous frame.
-                // Reuse all mappings that are still applicable.
-                mappedTouchIdBits.value = mLastFingerIdBits.value
-                        & mCurrentFingerIdBits.value;
-                usedGestureIdBits = mPointerGesture.lastGestureIdBits;
-
-                // Check whether we need to choose a new active gesture id because the
-                // current went went up.
-                for (BitSet32 upTouchIdBits(mLastFingerIdBits.value
-                        & ~mCurrentFingerIdBits.value);
-                        !upTouchIdBits.isEmpty(); ) {
-                    uint32_t upTouchId = upTouchIdBits.clearFirstMarkedBit();
-                    uint32_t upGestureId = mPointerGesture.freeformTouchToGestureIdMap[upTouchId];
-                    if (upGestureId == uint32_t(mPointerGesture.activeGestureId)) {
-                        mPointerGesture.activeGestureId = -1;
-                        break;
-                    }
-                }
-            }
-
-#if DEBUG_GESTURES
-            ALOGD("Gestures: FREEFORM follow up "
-                    "mappedTouchIdBits=0x%08x, usedGestureIdBits=0x%08x, "
-                    "activeGestureId=%d",
-                    mappedTouchIdBits.value, usedGestureIdBits.value,
-                    mPointerGesture.activeGestureId);
-#endif
-
-            BitSet32 idBits(mCurrentFingerIdBits);
-            for (uint32_t i = 0; i < currentFingerCount; i++) {
-                uint32_t touchId = idBits.clearFirstMarkedBit();
-                uint32_t gestureId;
-                if (!mappedTouchIdBits.hasBit(touchId)) {
-                    gestureId = usedGestureIdBits.markFirstUnmarkedBit();
-                    mPointerGesture.freeformTouchToGestureIdMap[touchId] = gestureId;
-#if DEBUG_GESTURES
-                    ALOGD("Gestures: FREEFORM "
-                            "new mapping for touch id %d -> gesture id %d",
-                            touchId, gestureId);
-#endif
-                } else {
-                    gestureId = mPointerGesture.freeformTouchToGestureIdMap[touchId];
-#if DEBUG_GESTURES
-                    ALOGD("Gestures: FREEFORM "
-                            "existing mapping for touch id %d -> gesture id %d",
-                            touchId, gestureId);
-#endif
-                }
-                mPointerGesture.currentGestureIdBits.markBit(gestureId);
-                mPointerGesture.currentGestureIdToIndex[gestureId] = i;
-
-                const RawPointerData::Pointer& pointer =
-                        mCurrentRawPointerData.pointerForId(touchId);
-                float deltaX = (pointer.x - mPointerGesture.referenceTouchX)
-                        * mPointerXZoomScale;
-                float deltaY = (pointer.y - mPointerGesture.referenceTouchY)
-                        * mPointerYZoomScale;
-                rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
-
-                mPointerGesture.currentGestureProperties[i].clear();
-                mPointerGesture.currentGestureProperties[i].id = gestureId;
-                mPointerGesture.currentGestureProperties[i].toolType =
-                        AMOTION_EVENT_TOOL_TYPE_FINGER;
-                mPointerGesture.currentGestureCoords[i].clear();
-                mPointerGesture.currentGestureCoords[i].setAxisValue(
-                        AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX + deltaX);
-                mPointerGesture.currentGestureCoords[i].setAxisValue(
-                        AMOTION_EVENT_AXIS_Y, mPointerGesture.referenceGestureY + deltaY);
-                mPointerGesture.currentGestureCoords[i].setAxisValue(
-                        AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
-            }
-
-            if (mPointerGesture.activeGestureId < 0) {
-                mPointerGesture.activeGestureId =
-                        mPointerGesture.currentGestureIdBits.firstMarkedBit();
-#if DEBUG_GESTURES
-                ALOGD("Gestures: FREEFORM new "
-                        "activeGestureId=%d", mPointerGesture.activeGestureId);
-#endif
-            }
-        }
-    }
-
-    mPointerController->setButtonState(mCurrentButtonState);
-
-#if DEBUG_GESTURES
-    ALOGD("Gestures: finishPreviousGesture=%s, cancelPreviousGesture=%s, "
-            "currentGestureMode=%d, currentGestureIdBits=0x%08x, "
-            "lastGestureMode=%d, lastGestureIdBits=0x%08x",
-            toString(*outFinishPreviousGesture), toString(*outCancelPreviousGesture),
-            mPointerGesture.currentGestureMode, mPointerGesture.currentGestureIdBits.value,
-            mPointerGesture.lastGestureMode, mPointerGesture.lastGestureIdBits.value);
-    for (BitSet32 idBits = mPointerGesture.currentGestureIdBits; !idBits.isEmpty(); ) {
-        uint32_t id = idBits.clearFirstMarkedBit();
-        uint32_t index = mPointerGesture.currentGestureIdToIndex[id];
-        const PointerProperties& properties = mPointerGesture.currentGestureProperties[index];
-        const PointerCoords& coords = mPointerGesture.currentGestureCoords[index];
-        ALOGD("  currentGesture[%d]: index=%d, toolType=%d, "
-                "x=%0.3f, y=%0.3f, pressure=%0.3f",
-                id, index, properties.toolType,
-                coords.getAxisValue(AMOTION_EVENT_AXIS_X),
-                coords.getAxisValue(AMOTION_EVENT_AXIS_Y),
-                coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
-    }
-    for (BitSet32 idBits = mPointerGesture.lastGestureIdBits; !idBits.isEmpty(); ) {
-        uint32_t id = idBits.clearFirstMarkedBit();
-        uint32_t index = mPointerGesture.lastGestureIdToIndex[id];
-        const PointerProperties& properties = mPointerGesture.lastGestureProperties[index];
-        const PointerCoords& coords = mPointerGesture.lastGestureCoords[index];
-        ALOGD("  lastGesture[%d]: index=%d, toolType=%d, "
-                "x=%0.3f, y=%0.3f, pressure=%0.3f",
-                id, index, properties.toolType,
-                coords.getAxisValue(AMOTION_EVENT_AXIS_X),
-                coords.getAxisValue(AMOTION_EVENT_AXIS_Y),
-                coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE));
-    }
-#endif
-    return true;
-}
-
-void TouchInputMapper::dispatchPointerStylus(nsecs_t when, uint32_t policyFlags) {
-    mPointerSimple.currentCoords.clear();
-    mPointerSimple.currentProperties.clear();
-
-    bool down, hovering;
-    if (!mCurrentStylusIdBits.isEmpty()) {
-        uint32_t id = mCurrentStylusIdBits.firstMarkedBit();
-        uint32_t index = mCurrentCookedPointerData.idToIndex[id];
-        float x = mCurrentCookedPointerData.pointerCoords[index].getX();
-        float y = mCurrentCookedPointerData.pointerCoords[index].getY();
-        mPointerController->setPosition(x, y);
-
-        hovering = mCurrentCookedPointerData.hoveringIdBits.hasBit(id);
-        down = !hovering;
-
-        mPointerController->getPosition(&x, &y);
-        mPointerSimple.currentCoords.copyFrom(mCurrentCookedPointerData.pointerCoords[index]);
-        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-        mPointerSimple.currentProperties.id = 0;
-        mPointerSimple.currentProperties.toolType =
-                mCurrentCookedPointerData.pointerProperties[index].toolType;
-    } else {
-        down = false;
-        hovering = false;
-    }
-
-    dispatchPointerSimple(when, policyFlags, down, hovering);
-}
-
-void TouchInputMapper::abortPointerStylus(nsecs_t when, uint32_t policyFlags) {
-    abortPointerSimple(when, policyFlags);
-}
-
-void TouchInputMapper::dispatchPointerMouse(nsecs_t when, uint32_t policyFlags) {
-    mPointerSimple.currentCoords.clear();
-    mPointerSimple.currentProperties.clear();
-
-    bool down, hovering;
-    if (!mCurrentMouseIdBits.isEmpty()) {
-        uint32_t id = mCurrentMouseIdBits.firstMarkedBit();
-        uint32_t currentIndex = mCurrentRawPointerData.idToIndex[id];
-        if (mLastMouseIdBits.hasBit(id)) {
-            uint32_t lastIndex = mCurrentRawPointerData.idToIndex[id];
-            float deltaX = (mCurrentRawPointerData.pointers[currentIndex].x
-                    - mLastRawPointerData.pointers[lastIndex].x)
-                    * mPointerXMovementScale;
-            float deltaY = (mCurrentRawPointerData.pointers[currentIndex].y
-                    - mLastRawPointerData.pointers[lastIndex].y)
-                    * mPointerYMovementScale;
-
-            rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
-            mPointerVelocityControl.move(when, &deltaX, &deltaY);
-
-            mPointerController->move(deltaX, deltaY);
-        } else {
-            mPointerVelocityControl.reset();
-        }
-
-        down = isPointerDown(mCurrentButtonState);
-        hovering = !down;
-
-        float x, y;
-        mPointerController->getPosition(&x, &y);
-        mPointerSimple.currentCoords.copyFrom(
-                mCurrentCookedPointerData.pointerCoords[currentIndex]);
-        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
-        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-        mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE,
-                hovering ? 0.0f : 1.0f);
-        mPointerSimple.currentProperties.id = 0;
-        mPointerSimple.currentProperties.toolType =
-                mCurrentCookedPointerData.pointerProperties[currentIndex].toolType;
-    } else {
-        mPointerVelocityControl.reset();
-
-        down = false;
-        hovering = false;
-    }
-
-    dispatchPointerSimple(when, policyFlags, down, hovering);
-}
-
-void TouchInputMapper::abortPointerMouse(nsecs_t when, uint32_t policyFlags) {
-    abortPointerSimple(when, policyFlags);
-
-    mPointerVelocityControl.reset();
-}
-
-void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
-        bool down, bool hovering) {
-    int32_t metaState = getContext()->getGlobalMetaState();
-
-    if (mPointerController != NULL) {
-        if (down || hovering) {
-            mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER);
-            mPointerController->clearSpots();
-            mPointerController->setButtonState(mCurrentButtonState);
-            mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
-        } else if (!down && !hovering && (mPointerSimple.down || mPointerSimple.hovering)) {
-            mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-        }
-    }
-
-    if (mPointerSimple.down && !down) {
-        mPointerSimple.down = false;
-
-        // Send up.
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                 AMOTION_EVENT_ACTION_UP, 0, metaState, mLastButtonState, 0,
-                 mViewport.displayId,
-                 1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
-                 mOrientedXPrecision, mOrientedYPrecision,
-                 mPointerSimple.downTime);
-        getListener()->notifyMotion(&args);
-    }
-
-    if (mPointerSimple.hovering && !hovering) {
-        mPointerSimple.hovering = false;
-
-        // Send hover exit.
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                AMOTION_EVENT_ACTION_HOVER_EXIT, 0, metaState, mLastButtonState, 0,
-                mViewport.displayId,
-                1, &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
-                mOrientedXPrecision, mOrientedYPrecision,
-                mPointerSimple.downTime);
-        getListener()->notifyMotion(&args);
-    }
-
-    if (down) {
-        if (!mPointerSimple.down) {
-            mPointerSimple.down = true;
-            mPointerSimple.downTime = when;
-
-            // Send down.
-            NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                    AMOTION_EVENT_ACTION_DOWN, 0, metaState, mCurrentButtonState, 0,
-                    mViewport.displayId,
-                    1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
-                    mOrientedXPrecision, mOrientedYPrecision,
-                    mPointerSimple.downTime);
-            getListener()->notifyMotion(&args);
-        }
-
-        // Send move.
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                AMOTION_EVENT_ACTION_MOVE, 0, metaState, mCurrentButtonState, 0,
-                mViewport.displayId,
-                1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
-                mOrientedXPrecision, mOrientedYPrecision,
-                mPointerSimple.downTime);
-        getListener()->notifyMotion(&args);
-    }
-
-    if (hovering) {
-        if (!mPointerSimple.hovering) {
-            mPointerSimple.hovering = true;
-
-            // Send hover enter.
-            NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                    AMOTION_EVENT_ACTION_HOVER_ENTER, 0, metaState, mCurrentButtonState, 0,
-                    mViewport.displayId,
-                    1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
-                    mOrientedXPrecision, mOrientedYPrecision,
-                    mPointerSimple.downTime);
-            getListener()->notifyMotion(&args);
-        }
-
-        // Send hover move.
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                AMOTION_EVENT_ACTION_HOVER_MOVE, 0, metaState, mCurrentButtonState, 0,
-                mViewport.displayId,
-                1, &mPointerSimple.currentProperties, &mPointerSimple.currentCoords,
-                mOrientedXPrecision, mOrientedYPrecision,
-                mPointerSimple.downTime);
-        getListener()->notifyMotion(&args);
-    }
-
-    if (mCurrentRawVScroll || mCurrentRawHScroll) {
-        float vscroll = mCurrentRawVScroll;
-        float hscroll = mCurrentRawHScroll;
-        mWheelYVelocityControl.move(when, NULL, &vscroll);
-        mWheelXVelocityControl.move(when, &hscroll, NULL);
-
-        // Send scroll.
-        PointerCoords pointerCoords;
-        pointerCoords.copyFrom(mPointerSimple.currentCoords);
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
-        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);
-
-        NotifyMotionArgs args(when, getDeviceId(), mSource, policyFlags,
-                AMOTION_EVENT_ACTION_SCROLL, 0, metaState, mCurrentButtonState, 0,
-                mViewport.displayId,
-                1, &mPointerSimple.currentProperties, &pointerCoords,
-                mOrientedXPrecision, mOrientedYPrecision,
-                mPointerSimple.downTime);
-        getListener()->notifyMotion(&args);
-    }
-
-    // Save state.
-    if (down || hovering) {
-        mPointerSimple.lastCoords.copyFrom(mPointerSimple.currentCoords);
-        mPointerSimple.lastProperties.copyFrom(mPointerSimple.currentProperties);
-    } else {
-        mPointerSimple.reset();
-    }
-}
-
-void TouchInputMapper::abortPointerSimple(nsecs_t when, uint32_t policyFlags) {
-    mPointerSimple.currentCoords.clear();
-    mPointerSimple.currentProperties.clear();
-
-    dispatchPointerSimple(when, policyFlags, false, false);
-}
-
-void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
-        int32_t action, int32_t flags, int32_t metaState, int32_t buttonState, int32_t edgeFlags,
-        const PointerProperties* properties, const PointerCoords* coords,
-        const uint32_t* idToIndex, BitSet32 idBits,
-        int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime) {
-    PointerCoords pointerCoords[MAX_POINTERS];
-    PointerProperties pointerProperties[MAX_POINTERS];
-    uint32_t pointerCount = 0;
-    while (!idBits.isEmpty()) {
-        uint32_t id = idBits.clearFirstMarkedBit();
-        uint32_t index = idToIndex[id];
-        pointerProperties[pointerCount].copyFrom(properties[index]);
-        pointerCoords[pointerCount].copyFrom(coords[index]);
-
-        if (changedId >= 0 && id == uint32_t(changedId)) {
-            action |= pointerCount << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
-        }
-
-        pointerCount += 1;
-    }
-
-    ALOG_ASSERT(pointerCount != 0);
-
-    if (changedId >= 0 && pointerCount == 1) {
-        // Replace initial down and final up action.
-        // We can compare the action without masking off the changed pointer index
-        // because we know the index is 0.
-        if (action == AMOTION_EVENT_ACTION_POINTER_DOWN) {
-            action = AMOTION_EVENT_ACTION_DOWN;
-        } else if (action == AMOTION_EVENT_ACTION_POINTER_UP) {
-            action = AMOTION_EVENT_ACTION_UP;
-        } else {
-            // Can't happen.
-            ALOG_ASSERT(false);
-        }
-    }
-
-    NotifyMotionArgs args(when, getDeviceId(), source, policyFlags,
-            action, flags, metaState, buttonState, edgeFlags,
-            mViewport.displayId, pointerCount, pointerProperties, pointerCoords,
-            xPrecision, yPrecision, downTime);
-    getListener()->notifyMotion(&args);
-}
-
-bool TouchInputMapper::updateMovedPointers(const PointerProperties* inProperties,
-        const PointerCoords* inCoords, const uint32_t* inIdToIndex,
-        PointerProperties* outProperties, PointerCoords* outCoords, const uint32_t* outIdToIndex,
-        BitSet32 idBits) const {
-    bool changed = false;
-    while (!idBits.isEmpty()) {
-        uint32_t id = idBits.clearFirstMarkedBit();
-        uint32_t inIndex = inIdToIndex[id];
-        uint32_t outIndex = outIdToIndex[id];
-
-        const PointerProperties& curInProperties = inProperties[inIndex];
-        const PointerCoords& curInCoords = inCoords[inIndex];
-        PointerProperties& curOutProperties = outProperties[outIndex];
-        PointerCoords& curOutCoords = outCoords[outIndex];
-
-        if (curInProperties != curOutProperties) {
-            curOutProperties.copyFrom(curInProperties);
-            changed = true;
-        }
-
-        if (curInCoords != curOutCoords) {
-            curOutCoords.copyFrom(curInCoords);
-            changed = true;
-        }
-    }
-    return changed;
-}
-
-void TouchInputMapper::fadePointer() {
-    if (mPointerController != NULL) {
-        mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL);
-    }
-}
-
-bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) {
-    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue
-            && y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue;
-}
-
-const TouchInputMapper::VirtualKey* TouchInputMapper::findVirtualKeyHit(
-        int32_t x, int32_t y) {
-    size_t numVirtualKeys = mVirtualKeys.size();
-    for (size_t i = 0; i < numVirtualKeys; i++) {
-        const VirtualKey& virtualKey = mVirtualKeys[i];
-
-#if DEBUG_VIRTUAL_KEYS
-        ALOGD("VirtualKeys: Hit test (%d, %d): keyCode=%d, scanCode=%d, "
-                "left=%d, top=%d, right=%d, bottom=%d",
-                x, y,
-                virtualKey.keyCode, virtualKey.scanCode,
-                virtualKey.hitLeft, virtualKey.hitTop,
-                virtualKey.hitRight, virtualKey.hitBottom);
-#endif
-
-        if (virtualKey.isHit(x, y)) {
-            return & virtualKey;
-        }
-    }
-
-    return NULL;
-}
-
-void TouchInputMapper::assignPointerIds() {
-    uint32_t currentPointerCount = mCurrentRawPointerData.pointerCount;
-    uint32_t lastPointerCount = mLastRawPointerData.pointerCount;
-
-    mCurrentRawPointerData.clearIdBits();
-
-    if (currentPointerCount == 0) {
-        // No pointers to assign.
-        return;
-    }
-
-    if (lastPointerCount == 0) {
-        // All pointers are new.
-        for (uint32_t i = 0; i < currentPointerCount; i++) {
-            uint32_t id = i;
-            mCurrentRawPointerData.pointers[i].id = id;
-            mCurrentRawPointerData.idToIndex[id] = i;
-            mCurrentRawPointerData.markIdBit(id, mCurrentRawPointerData.isHovering(i));
-        }
-        return;
-    }
-
-    if (currentPointerCount == 1 && lastPointerCount == 1
-            && mCurrentRawPointerData.pointers[0].toolType
-                    == mLastRawPointerData.pointers[0].toolType) {
-        // Only one pointer and no change in count so it must have the same id as before.
-        uint32_t id = mLastRawPointerData.pointers[0].id;
-        mCurrentRawPointerData.pointers[0].id = id;
-        mCurrentRawPointerData.idToIndex[id] = 0;
-        mCurrentRawPointerData.markIdBit(id, mCurrentRawPointerData.isHovering(0));
-        return;
-    }
-
-    // General case.
-    // We build a heap of squared euclidean distances between current and last pointers
-    // associated with the current and last pointer indices.  Then, we find the best
-    // match (by distance) for each current pointer.
-    // The pointers must have the same tool type but it is possible for them to
-    // transition from hovering to touching or vice-versa while retaining the same id.
-    PointerDistanceHeapElement heap[MAX_POINTERS * MAX_POINTERS];
-
-    uint32_t heapSize = 0;
-    for (uint32_t currentPointerIndex = 0; currentPointerIndex < currentPointerCount;
-            currentPointerIndex++) {
-        for (uint32_t lastPointerIndex = 0; lastPointerIndex < lastPointerCount;
-                lastPointerIndex++) {
-            const RawPointerData::Pointer& currentPointer =
-                    mCurrentRawPointerData.pointers[currentPointerIndex];
-            const RawPointerData::Pointer& lastPointer =
-                    mLastRawPointerData.pointers[lastPointerIndex];
-            if (currentPointer.toolType == lastPointer.toolType) {
-                int64_t deltaX = currentPointer.x - lastPointer.x;
-                int64_t deltaY = currentPointer.y - lastPointer.y;
-
-                uint64_t distance = uint64_t(deltaX * deltaX + deltaY * deltaY);
-
-                // Insert new element into the heap (sift up).
-                heap[heapSize].currentPointerIndex = currentPointerIndex;
-                heap[heapSize].lastPointerIndex = lastPointerIndex;
-                heap[heapSize].distance = distance;
-                heapSize += 1;
-            }
-        }
-    }
-
-    // Heapify
-    for (uint32_t startIndex = heapSize / 2; startIndex != 0; ) {
-        startIndex -= 1;
-        for (uint32_t parentIndex = startIndex; ;) {
-            uint32_t childIndex = parentIndex * 2 + 1;
-            if (childIndex >= heapSize) {
-                break;
-            }
-
-            if (childIndex + 1 < heapSize
-                    && heap[childIndex + 1].distance < heap[childIndex].distance) {
-                childIndex += 1;
-            }
-
-            if (heap[parentIndex].distance <= heap[childIndex].distance) {
-                break;
-            }
-
-            swap(heap[parentIndex], heap[childIndex]);
-            parentIndex = childIndex;
-        }
-    }
-
-#if DEBUG_POINTER_ASSIGNMENT
-    ALOGD("assignPointerIds - initial distance min-heap: size=%d", heapSize);
-    for (size_t i = 0; i < heapSize; i++) {
-        ALOGD("  heap[%d]: cur=%d, last=%d, distance=%lld",
-                i, heap[i].currentPointerIndex, heap[i].lastPointerIndex,
-                heap[i].distance);
-    }
-#endif
-
-    // Pull matches out by increasing order of distance.
-    // To avoid reassigning pointers that have already been matched, the loop keeps track
-    // of which last and current pointers have been matched using the matchedXXXBits variables.
-    // It also tracks the used pointer id bits.
-    BitSet32 matchedLastBits(0);
-    BitSet32 matchedCurrentBits(0);
-    BitSet32 usedIdBits(0);
-    bool first = true;
-    for (uint32_t i = min(currentPointerCount, lastPointerCount); heapSize > 0 && i > 0; i--) {
-        while (heapSize > 0) {
-            if (first) {
-                // The first time through the loop, we just consume the root element of
-                // the heap (the one with smallest distance).
-                first = false;
-            } else {
-                // Previous iterations consumed the root element of the heap.
-                // Pop root element off of the heap (sift down).
-                heap[0] = heap[heapSize];
-                for (uint32_t parentIndex = 0; ;) {
-                    uint32_t childIndex = parentIndex * 2 + 1;
-                    if (childIndex >= heapSize) {
-                        break;
-                    }
-
-                    if (childIndex + 1 < heapSize
-                            && heap[childIndex + 1].distance < heap[childIndex].distance) {
-                        childIndex += 1;
-                    }
-
-                    if (heap[parentIndex].distance <= heap[childIndex].distance) {
-                        break;
-                    }
-
-                    swap(heap[parentIndex], heap[childIndex]);
-                    parentIndex = childIndex;
-                }
-
-#if DEBUG_POINTER_ASSIGNMENT
-                ALOGD("assignPointerIds - reduced distance min-heap: size=%d", heapSize);
-                for (size_t i = 0; i < heapSize; i++) {
-                    ALOGD("  heap[%d]: cur=%d, last=%d, distance=%lld",
-                            i, heap[i].currentPointerIndex, heap[i].lastPointerIndex,
-                            heap[i].distance);
-                }
-#endif
-            }
-
-            heapSize -= 1;
-
-            uint32_t currentPointerIndex = heap[0].currentPointerIndex;
-            if (matchedCurrentBits.hasBit(currentPointerIndex)) continue; // already matched
-
-            uint32_t lastPointerIndex = heap[0].lastPointerIndex;
-            if (matchedLastBits.hasBit(lastPointerIndex)) continue; // already matched
-
-            matchedCurrentBits.markBit(currentPointerIndex);
-            matchedLastBits.markBit(lastPointerIndex);
-
-            uint32_t id = mLastRawPointerData.pointers[lastPointerIndex].id;
-            mCurrentRawPointerData.pointers[currentPointerIndex].id = id;
-            mCurrentRawPointerData.idToIndex[id] = currentPointerIndex;
-            mCurrentRawPointerData.markIdBit(id,
-                    mCurrentRawPointerData.isHovering(currentPointerIndex));
-            usedIdBits.markBit(id);
-
-#if DEBUG_POINTER_ASSIGNMENT
-            ALOGD("assignPointerIds - matched: cur=%d, last=%d, id=%d, distance=%lld",
-                    lastPointerIndex, currentPointerIndex, id, heap[0].distance);
-#endif
-            break;
-        }
-    }
-
-    // Assign fresh ids to pointers that were not matched in the process.
-    for (uint32_t i = currentPointerCount - matchedCurrentBits.count(); i != 0; i--) {
-        uint32_t currentPointerIndex = matchedCurrentBits.markFirstUnmarkedBit();
-        uint32_t id = usedIdBits.markFirstUnmarkedBit();
-
-        mCurrentRawPointerData.pointers[currentPointerIndex].id = id;
-        mCurrentRawPointerData.idToIndex[id] = currentPointerIndex;
-        mCurrentRawPointerData.markIdBit(id,
-                mCurrentRawPointerData.isHovering(currentPointerIndex));
-
-#if DEBUG_POINTER_ASSIGNMENT
-        ALOGD("assignPointerIds - assigned: cur=%d, id=%d",
-                currentPointerIndex, id);
-#endif
-    }
-}
-
-int32_t TouchInputMapper::getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
-    if (mCurrentVirtualKey.down && mCurrentVirtualKey.keyCode == keyCode) {
-        return AKEY_STATE_VIRTUAL;
-    }
-
-    size_t numVirtualKeys = mVirtualKeys.size();
-    for (size_t i = 0; i < numVirtualKeys; i++) {
-        const VirtualKey& virtualKey = mVirtualKeys[i];
-        if (virtualKey.keyCode == keyCode) {
-            return AKEY_STATE_UP;
-        }
-    }
-
-    return AKEY_STATE_UNKNOWN;
-}
-
-int32_t TouchInputMapper::getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
-    if (mCurrentVirtualKey.down && mCurrentVirtualKey.scanCode == scanCode) {
-        return AKEY_STATE_VIRTUAL;
-    }
-
-    size_t numVirtualKeys = mVirtualKeys.size();
-    for (size_t i = 0; i < numVirtualKeys; i++) {
-        const VirtualKey& virtualKey = mVirtualKeys[i];
-        if (virtualKey.scanCode == scanCode) {
-            return AKEY_STATE_UP;
-        }
-    }
-
-    return AKEY_STATE_UNKNOWN;
-}
-
-bool TouchInputMapper::markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-        const int32_t* keyCodes, uint8_t* outFlags) {
-    size_t numVirtualKeys = mVirtualKeys.size();
-    for (size_t i = 0; i < numVirtualKeys; i++) {
-        const VirtualKey& virtualKey = mVirtualKeys[i];
-
-        for (size_t i = 0; i < numCodes; i++) {
-            if (virtualKey.keyCode == keyCodes[i]) {
-                outFlags[i] = 1;
-            }
-        }
-    }
-
-    return true;
-}
-
-
-// --- SingleTouchInputMapper ---
-
-SingleTouchInputMapper::SingleTouchInputMapper(InputDevice* device) :
-        TouchInputMapper(device) {
-}
-
-SingleTouchInputMapper::~SingleTouchInputMapper() {
-}
-
-void SingleTouchInputMapper::reset(nsecs_t when) {
-    mSingleTouchMotionAccumulator.reset(getDevice());
-
-    TouchInputMapper::reset(when);
-}
-
-void SingleTouchInputMapper::process(const RawEvent* rawEvent) {
-    TouchInputMapper::process(rawEvent);
-
-    mSingleTouchMotionAccumulator.process(rawEvent);
-}
-
-void SingleTouchInputMapper::syncTouch(nsecs_t when, bool* outHavePointerIds) {
-    if (mTouchButtonAccumulator.isToolActive()) {
-        mCurrentRawPointerData.pointerCount = 1;
-        mCurrentRawPointerData.idToIndex[0] = 0;
-
-        bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE
-                && (mTouchButtonAccumulator.isHovering()
-                        || (mRawPointerAxes.pressure.valid
-                                && mSingleTouchMotionAccumulator.getAbsolutePressure() <= 0));
-        mCurrentRawPointerData.markIdBit(0, isHovering);
-
-        RawPointerData::Pointer& outPointer = mCurrentRawPointerData.pointers[0];
-        outPointer.id = 0;
-        outPointer.x = mSingleTouchMotionAccumulator.getAbsoluteX();
-        outPointer.y = mSingleTouchMotionAccumulator.getAbsoluteY();
-        outPointer.pressure = mSingleTouchMotionAccumulator.getAbsolutePressure();
-        outPointer.touchMajor = 0;
-        outPointer.touchMinor = 0;
-        outPointer.toolMajor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth();
-        outPointer.toolMinor = mSingleTouchMotionAccumulator.getAbsoluteToolWidth();
-        outPointer.orientation = 0;
-        outPointer.distance = mSingleTouchMotionAccumulator.getAbsoluteDistance();
-        outPointer.tiltX = mSingleTouchMotionAccumulator.getAbsoluteTiltX();
-        outPointer.tiltY = mSingleTouchMotionAccumulator.getAbsoluteTiltY();
-        outPointer.toolType = mTouchButtonAccumulator.getToolType();
-        if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
-            outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
-        }
-        outPointer.isHovering = isHovering;
-    }
-}
-
-void SingleTouchInputMapper::configureRawPointerAxes() {
-    TouchInputMapper::configureRawPointerAxes();
-
-    getAbsoluteAxisInfo(ABS_X, &mRawPointerAxes.x);
-    getAbsoluteAxisInfo(ABS_Y, &mRawPointerAxes.y);
-    getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPointerAxes.pressure);
-    getAbsoluteAxisInfo(ABS_TOOL_WIDTH, &mRawPointerAxes.toolMajor);
-    getAbsoluteAxisInfo(ABS_DISTANCE, &mRawPointerAxes.distance);
-    getAbsoluteAxisInfo(ABS_TILT_X, &mRawPointerAxes.tiltX);
-    getAbsoluteAxisInfo(ABS_TILT_Y, &mRawPointerAxes.tiltY);
-}
-
-bool SingleTouchInputMapper::hasStylus() const {
-    return mTouchButtonAccumulator.hasStylus();
-}
-
-
-// --- MultiTouchInputMapper ---
-
-MultiTouchInputMapper::MultiTouchInputMapper(InputDevice* device) :
-        TouchInputMapper(device) {
-}
-
-MultiTouchInputMapper::~MultiTouchInputMapper() {
-}
-
-void MultiTouchInputMapper::reset(nsecs_t when) {
-    mMultiTouchMotionAccumulator.reset(getDevice());
-
-    mPointerIdBits.clear();
-
-    TouchInputMapper::reset(when);
-}
-
-void MultiTouchInputMapper::process(const RawEvent* rawEvent) {
-    TouchInputMapper::process(rawEvent);
-
-    mMultiTouchMotionAccumulator.process(rawEvent);
-}
-
-void MultiTouchInputMapper::syncTouch(nsecs_t when, bool* outHavePointerIds) {
-    size_t inCount = mMultiTouchMotionAccumulator.getSlotCount();
-    size_t outCount = 0;
-    BitSet32 newPointerIdBits;
-
-    for (size_t inIndex = 0; inIndex < inCount; inIndex++) {
-        const MultiTouchMotionAccumulator::Slot* inSlot =
-                mMultiTouchMotionAccumulator.getSlot(inIndex);
-        if (!inSlot->isInUse()) {
-            continue;
-        }
-
-        if (outCount >= MAX_POINTERS) {
-#if DEBUG_POINTERS
-            ALOGD("MultiTouch device %s emitted more than maximum of %d pointers; "
-                    "ignoring the rest.",
-                    getDeviceName().string(), MAX_POINTERS);
-#endif
-            break; // too many fingers!
-        }
-
-        RawPointerData::Pointer& outPointer = mCurrentRawPointerData.pointers[outCount];
-        outPointer.x = inSlot->getX();
-        outPointer.y = inSlot->getY();
-        outPointer.pressure = inSlot->getPressure();
-        outPointer.touchMajor = inSlot->getTouchMajor();
-        outPointer.touchMinor = inSlot->getTouchMinor();
-        outPointer.toolMajor = inSlot->getToolMajor();
-        outPointer.toolMinor = inSlot->getToolMinor();
-        outPointer.orientation = inSlot->getOrientation();
-        outPointer.distance = inSlot->getDistance();
-        outPointer.tiltX = 0;
-        outPointer.tiltY = 0;
-
-        outPointer.toolType = inSlot->getToolType();
-        if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
-            outPointer.toolType = mTouchButtonAccumulator.getToolType();
-            if (outPointer.toolType == AMOTION_EVENT_TOOL_TYPE_UNKNOWN) {
-                outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
-            }
-        }
-
-        bool isHovering = mTouchButtonAccumulator.getToolType() != AMOTION_EVENT_TOOL_TYPE_MOUSE
-                && (mTouchButtonAccumulator.isHovering()
-                        || (mRawPointerAxes.pressure.valid && inSlot->getPressure() <= 0));
-        outPointer.isHovering = isHovering;
-
-        // Assign pointer id using tracking id if available.
-        if (*outHavePointerIds) {
-            int32_t trackingId = inSlot->getTrackingId();
-            int32_t id = -1;
-            if (trackingId >= 0) {
-                for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty(); ) {
-                    uint32_t n = idBits.clearFirstMarkedBit();
-                    if (mPointerTrackingIdMap[n] == trackingId) {
-                        id = n;
-                    }
-                }
-
-                if (id < 0 && !mPointerIdBits.isFull()) {
-                    id = mPointerIdBits.markFirstUnmarkedBit();
-                    mPointerTrackingIdMap[id] = trackingId;
-                }
-            }
-            if (id < 0) {
-                *outHavePointerIds = false;
-                mCurrentRawPointerData.clearIdBits();
-                newPointerIdBits.clear();
-            } else {
-                outPointer.id = id;
-                mCurrentRawPointerData.idToIndex[id] = outCount;
-                mCurrentRawPointerData.markIdBit(id, isHovering);
-                newPointerIdBits.markBit(id);
-            }
-        }
-
-        outCount += 1;
-    }
-
-    mCurrentRawPointerData.pointerCount = outCount;
-    mPointerIdBits = newPointerIdBits;
-
-    mMultiTouchMotionAccumulator.finishSync();
-}
-
-void MultiTouchInputMapper::configureRawPointerAxes() {
-    TouchInputMapper::configureRawPointerAxes();
-
-    getAbsoluteAxisInfo(ABS_MT_POSITION_X, &mRawPointerAxes.x);
-    getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mRawPointerAxes.y);
-    getAbsoluteAxisInfo(ABS_MT_TOUCH_MAJOR, &mRawPointerAxes.touchMajor);
-    getAbsoluteAxisInfo(ABS_MT_TOUCH_MINOR, &mRawPointerAxes.touchMinor);
-    getAbsoluteAxisInfo(ABS_MT_WIDTH_MAJOR, &mRawPointerAxes.toolMajor);
-    getAbsoluteAxisInfo(ABS_MT_WIDTH_MINOR, &mRawPointerAxes.toolMinor);
-    getAbsoluteAxisInfo(ABS_MT_ORIENTATION, &mRawPointerAxes.orientation);
-    getAbsoluteAxisInfo(ABS_MT_PRESSURE, &mRawPointerAxes.pressure);
-    getAbsoluteAxisInfo(ABS_MT_DISTANCE, &mRawPointerAxes.distance);
-    getAbsoluteAxisInfo(ABS_MT_TRACKING_ID, &mRawPointerAxes.trackingId);
-    getAbsoluteAxisInfo(ABS_MT_SLOT, &mRawPointerAxes.slot);
-
-    if (mRawPointerAxes.trackingId.valid
-            && mRawPointerAxes.slot.valid
-            && mRawPointerAxes.slot.minValue == 0 && mRawPointerAxes.slot.maxValue > 0) {
-        size_t slotCount = mRawPointerAxes.slot.maxValue + 1;
-        if (slotCount > MAX_SLOTS) {
-            ALOGW("MultiTouch Device %s reported %d slots but the framework "
-                    "only supports a maximum of %d slots at this time.",
-                    getDeviceName().string(), slotCount, MAX_SLOTS);
-            slotCount = MAX_SLOTS;
-        }
-        mMultiTouchMotionAccumulator.configure(getDevice(),
-                slotCount, true /*usingSlotsProtocol*/);
-    } else {
-        mMultiTouchMotionAccumulator.configure(getDevice(),
-                MAX_POINTERS, false /*usingSlotsProtocol*/);
-    }
-}
-
-bool MultiTouchInputMapper::hasStylus() const {
-    return mMultiTouchMotionAccumulator.hasStylus()
-            || mTouchButtonAccumulator.hasStylus();
-}
-
-
-// --- JoystickInputMapper ---
-
-JoystickInputMapper::JoystickInputMapper(InputDevice* device) :
-        InputMapper(device) {
-}
-
-JoystickInputMapper::~JoystickInputMapper() {
-}
-
-uint32_t JoystickInputMapper::getSources() {
-    return AINPUT_SOURCE_JOYSTICK;
-}
-
-void JoystickInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
-    InputMapper::populateDeviceInfo(info);
-
-    for (size_t i = 0; i < mAxes.size(); i++) {
-        const Axis& axis = mAxes.valueAt(i);
-        addMotionRange(axis.axisInfo.axis, axis, info);
-
-        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
-            addMotionRange(axis.axisInfo.highAxis, axis, info);
-
-        }
-    }
-}
-
-void JoystickInputMapper::addMotionRange(int32_t axisId, const Axis& axis,
-        InputDeviceInfo* info) {
-    info->addMotionRange(axisId, AINPUT_SOURCE_JOYSTICK,
-            axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution);
-    /* In order to ease the transition for developers from using the old axes
-     * to the newer, more semantically correct axes, we'll continue to register
-     * the old axes as duplicates of their corresponding new ones.  */
-    int32_t compatAxis = getCompatAxis(axisId);
-    if (compatAxis >= 0) {
-        info->addMotionRange(compatAxis, AINPUT_SOURCE_JOYSTICK,
-                axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution);
-    }
-}
-
-/* A mapping from axes the joystick actually has to the axes that should be
- * artificially created for compatibility purposes.
- * Returns -1 if no compatibility axis is needed. */
-int32_t JoystickInputMapper::getCompatAxis(int32_t axis) {
-    switch(axis) {
-    case AMOTION_EVENT_AXIS_LTRIGGER:
-        return AMOTION_EVENT_AXIS_BRAKE;
-    case AMOTION_EVENT_AXIS_RTRIGGER:
-        return AMOTION_EVENT_AXIS_GAS;
-    }
-    return -1;
-}
-
-void JoystickInputMapper::dump(String8& dump) {
-    dump.append(INDENT2 "Joystick Input Mapper:\n");
-
-    dump.append(INDENT3 "Axes:\n");
-    size_t numAxes = mAxes.size();
-    for (size_t i = 0; i < numAxes; i++) {
-        const Axis& axis = mAxes.valueAt(i);
-        const char* label = getAxisLabel(axis.axisInfo.axis);
-        if (label) {
-            dump.appendFormat(INDENT4 "%s", label);
-        } else {
-            dump.appendFormat(INDENT4 "%d", axis.axisInfo.axis);
-        }
-        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
-            label = getAxisLabel(axis.axisInfo.highAxis);
-            if (label) {
-                dump.appendFormat(" / %s (split at %d)", label, axis.axisInfo.splitValue);
-            } else {
-                dump.appendFormat(" / %d (split at %d)", axis.axisInfo.highAxis,
-                        axis.axisInfo.splitValue);
-            }
-        } else if (axis.axisInfo.mode == AxisInfo::MODE_INVERT) {
-            dump.append(" (invert)");
-        }
-
-        dump.appendFormat(": min=%0.5f, max=%0.5f, flat=%0.5f, fuzz=%0.5f, resolution=%0.5f\n",
-                axis.min, axis.max, axis.flat, axis.fuzz, axis.resolution);
-        dump.appendFormat(INDENT4 "  scale=%0.5f, offset=%0.5f, "
-                "highScale=%0.5f, highOffset=%0.5f\n",
-                axis.scale, axis.offset, axis.highScale, axis.highOffset);
-        dump.appendFormat(INDENT4 "  rawAxis=%d, rawMin=%d, rawMax=%d, "
-                "rawFlat=%d, rawFuzz=%d, rawResolution=%d\n",
-                mAxes.keyAt(i), axis.rawAxisInfo.minValue, axis.rawAxisInfo.maxValue,
-                axis.rawAxisInfo.flat, axis.rawAxisInfo.fuzz, axis.rawAxisInfo.resolution);
-    }
-}
-
-void JoystickInputMapper::configure(nsecs_t when,
-        const InputReaderConfiguration* config, uint32_t changes) {
-    InputMapper::configure(when, config, changes);
-
-    if (!changes) { // first time only
-        // Collect all axes.
-        for (int32_t abs = 0; abs <= ABS_MAX; abs++) {
-            if (!(getAbsAxisUsage(abs, getDevice()->getClasses())
-                    & INPUT_DEVICE_CLASS_JOYSTICK)) {
-                continue; // axis must be claimed by a different device
-            }
-
-            RawAbsoluteAxisInfo rawAxisInfo;
-            getAbsoluteAxisInfo(abs, &rawAxisInfo);
-            if (rawAxisInfo.valid) {
-                // Map axis.
-                AxisInfo axisInfo;
-                bool explicitlyMapped = !getEventHub()->mapAxis(getDeviceId(), abs, &axisInfo);
-                if (!explicitlyMapped) {
-                    // Axis is not explicitly mapped, will choose a generic axis later.
-                    axisInfo.mode = AxisInfo::MODE_NORMAL;
-                    axisInfo.axis = -1;
-                }
-
-                // Apply flat override.
-                int32_t rawFlat = axisInfo.flatOverride < 0
-                        ? rawAxisInfo.flat : axisInfo.flatOverride;
-
-                // Calculate scaling factors and limits.
-                Axis axis;
-                if (axisInfo.mode == AxisInfo::MODE_SPLIT) {
-                    float scale = 1.0f / (axisInfo.splitValue - rawAxisInfo.minValue);
-                    float highScale = 1.0f / (rawAxisInfo.maxValue - axisInfo.splitValue);
-                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
-                            scale, 0.0f, highScale, 0.0f,
-                            0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale,
-                            rawAxisInfo.resolution * scale);
-                } else if (isCenteredAxis(axisInfo.axis)) {
-                    float scale = 2.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
-                    float offset = avg(rawAxisInfo.minValue, rawAxisInfo.maxValue) * -scale;
-                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
-                            scale, offset, scale, offset,
-                            -1.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale,
-                            rawAxisInfo.resolution * scale);
-                } else {
-                    float scale = 1.0f / (rawAxisInfo.maxValue - rawAxisInfo.minValue);
-                    axis.initialize(rawAxisInfo, axisInfo, explicitlyMapped,
-                            scale, 0.0f, scale, 0.0f,
-                            0.0f, 1.0f, rawFlat * scale, rawAxisInfo.fuzz * scale,
-                            rawAxisInfo.resolution * scale);
-                }
-
-                // To eliminate noise while the joystick is at rest, filter out small variations
-                // in axis values up front.
-                axis.filter = axis.flat * 0.25f;
-
-                mAxes.add(abs, axis);
-            }
-        }
-
-        // If there are too many axes, start dropping them.
-        // Prefer to keep explicitly mapped axes.
-        if (mAxes.size() > PointerCoords::MAX_AXES) {
-            ALOGI("Joystick '%s' has %d axes but the framework only supports a maximum of %d.",
-                    getDeviceName().string(), mAxes.size(), PointerCoords::MAX_AXES);
-            pruneAxes(true);
-            pruneAxes(false);
-        }
-
-        // Assign generic axis ids to remaining axes.
-        int32_t nextGenericAxisId = AMOTION_EVENT_AXIS_GENERIC_1;
-        size_t numAxes = mAxes.size();
-        for (size_t i = 0; i < numAxes; i++) {
-            Axis& axis = mAxes.editValueAt(i);
-            if (axis.axisInfo.axis < 0) {
-                while (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16
-                        && haveAxis(nextGenericAxisId)) {
-                    nextGenericAxisId += 1;
-                }
-
-                if (nextGenericAxisId <= AMOTION_EVENT_AXIS_GENERIC_16) {
-                    axis.axisInfo.axis = nextGenericAxisId;
-                    nextGenericAxisId += 1;
-                } else {
-                    ALOGI("Ignoring joystick '%s' axis %d because all of the generic axis ids "
-                            "have already been assigned to other axes.",
-                            getDeviceName().string(), mAxes.keyAt(i));
-                    mAxes.removeItemsAt(i--);
-                    numAxes -= 1;
-                }
-            }
-        }
-    }
-}
-
-bool JoystickInputMapper::haveAxis(int32_t axisId) {
-    size_t numAxes = mAxes.size();
-    for (size_t i = 0; i < numAxes; i++) {
-        const Axis& axis = mAxes.valueAt(i);
-        if (axis.axisInfo.axis == axisId
-                || (axis.axisInfo.mode == AxisInfo::MODE_SPLIT
-                        && axis.axisInfo.highAxis == axisId)) {
-            return true;
-        }
-    }
-    return false;
-}
-
-void JoystickInputMapper::pruneAxes(bool ignoreExplicitlyMappedAxes) {
-    size_t i = mAxes.size();
-    while (mAxes.size() > PointerCoords::MAX_AXES && i-- > 0) {
-        if (ignoreExplicitlyMappedAxes && mAxes.valueAt(i).explicitlyMapped) {
-            continue;
-        }
-        ALOGI("Discarding joystick '%s' axis %d because there are too many axes.",
-                getDeviceName().string(), mAxes.keyAt(i));
-        mAxes.removeItemsAt(i);
-    }
-}
-
-bool JoystickInputMapper::isCenteredAxis(int32_t axis) {
-    switch (axis) {
-    case AMOTION_EVENT_AXIS_X:
-    case AMOTION_EVENT_AXIS_Y:
-    case AMOTION_EVENT_AXIS_Z:
-    case AMOTION_EVENT_AXIS_RX:
-    case AMOTION_EVENT_AXIS_RY:
-    case AMOTION_EVENT_AXIS_RZ:
-    case AMOTION_EVENT_AXIS_HAT_X:
-    case AMOTION_EVENT_AXIS_HAT_Y:
-    case AMOTION_EVENT_AXIS_ORIENTATION:
-    case AMOTION_EVENT_AXIS_RUDDER:
-    case AMOTION_EVENT_AXIS_WHEEL:
-        return true;
-    default:
-        return false;
-    }
-}
-
-void JoystickInputMapper::reset(nsecs_t when) {
-    // Recenter all axes.
-    size_t numAxes = mAxes.size();
-    for (size_t i = 0; i < numAxes; i++) {
-        Axis& axis = mAxes.editValueAt(i);
-        axis.resetValue();
-    }
-
-    InputMapper::reset(when);
-}
-
-void JoystickInputMapper::process(const RawEvent* rawEvent) {
-    switch (rawEvent->type) {
-    case EV_ABS: {
-        ssize_t index = mAxes.indexOfKey(rawEvent->code);
-        if (index >= 0) {
-            Axis& axis = mAxes.editValueAt(index);
-            float newValue, highNewValue;
-            switch (axis.axisInfo.mode) {
-            case AxisInfo::MODE_INVERT:
-                newValue = (axis.rawAxisInfo.maxValue - rawEvent->value)
-                        * axis.scale + axis.offset;
-                highNewValue = 0.0f;
-                break;
-            case AxisInfo::MODE_SPLIT:
-                if (rawEvent->value < axis.axisInfo.splitValue) {
-                    newValue = (axis.axisInfo.splitValue - rawEvent->value)
-                            * axis.scale + axis.offset;
-                    highNewValue = 0.0f;
-                } else if (rawEvent->value > axis.axisInfo.splitValue) {
-                    newValue = 0.0f;
-                    highNewValue = (rawEvent->value - axis.axisInfo.splitValue)
-                            * axis.highScale + axis.highOffset;
-                } else {
-                    newValue = 0.0f;
-                    highNewValue = 0.0f;
-                }
-                break;
-            default:
-                newValue = rawEvent->value * axis.scale + axis.offset;
-                highNewValue = 0.0f;
-                break;
-            }
-            axis.newValue = newValue;
-            axis.highNewValue = highNewValue;
-        }
-        break;
-    }
-
-    case EV_SYN:
-        switch (rawEvent->code) {
-        case SYN_REPORT:
-            sync(rawEvent->when, false /*force*/);
-            break;
-        }
-        break;
-    }
-}
-
-void JoystickInputMapper::sync(nsecs_t when, bool force) {
-    if (!filterAxes(force)) {
-        return;
-    }
-
-    int32_t metaState = mContext->getGlobalMetaState();
-    int32_t buttonState = 0;
-
-    PointerProperties pointerProperties;
-    pointerProperties.clear();
-    pointerProperties.id = 0;
-    pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
-
-    PointerCoords pointerCoords;
-    pointerCoords.clear();
-
-    size_t numAxes = mAxes.size();
-    for (size_t i = 0; i < numAxes; i++) {
-        const Axis& axis = mAxes.valueAt(i);
-        setPointerCoordsAxisValue(&pointerCoords, axis.axisInfo.axis, axis.currentValue);
-        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
-            setPointerCoordsAxisValue(&pointerCoords, axis.axisInfo.highAxis,
-                    axis.highCurrentValue);
-        }
-    }
-
-    // Moving a joystick axis should not wake the device because joysticks can
-    // be fairly noisy even when not in use.  On the other hand, pushing a gamepad
-    // button will likely wake the device.
-    // TODO: Use the input device configuration to control this behavior more finely.
-    uint32_t policyFlags = 0;
-
-    NotifyMotionArgs args(when, getDeviceId(), AINPUT_SOURCE_JOYSTICK, policyFlags,
-            AMOTION_EVENT_ACTION_MOVE, 0, metaState, buttonState, AMOTION_EVENT_EDGE_FLAG_NONE,
-            ADISPLAY_ID_NONE, 1, &pointerProperties, &pointerCoords, 0, 0, 0);
-    getListener()->notifyMotion(&args);
-}
-
-void JoystickInputMapper::setPointerCoordsAxisValue(PointerCoords* pointerCoords,
-        int32_t axis, float value) {
-    pointerCoords->setAxisValue(axis, value);
-    /* In order to ease the transition for developers from using the old axes
-     * to the newer, more semantically correct axes, we'll continue to produce
-     * values for the old axes as mirrors of the value of their corresponding
-     * new axes. */
-    int32_t compatAxis = getCompatAxis(axis);
-    if (compatAxis >= 0) {
-        pointerCoords->setAxisValue(compatAxis, value);
-    }
-}
-
-bool JoystickInputMapper::filterAxes(bool force) {
-    bool atLeastOneSignificantChange = force;
-    size_t numAxes = mAxes.size();
-    for (size_t i = 0; i < numAxes; i++) {
-        Axis& axis = mAxes.editValueAt(i);
-        if (force || hasValueChangedSignificantly(axis.filter,
-                axis.newValue, axis.currentValue, axis.min, axis.max)) {
-            axis.currentValue = axis.newValue;
-            atLeastOneSignificantChange = true;
-        }
-        if (axis.axisInfo.mode == AxisInfo::MODE_SPLIT) {
-            if (force || hasValueChangedSignificantly(axis.filter,
-                    axis.highNewValue, axis.highCurrentValue, axis.min, axis.max)) {
-                axis.highCurrentValue = axis.highNewValue;
-                atLeastOneSignificantChange = true;
-            }
-        }
-    }
-    return atLeastOneSignificantChange;
-}
-
-bool JoystickInputMapper::hasValueChangedSignificantly(
-        float filter, float newValue, float currentValue, float min, float max) {
-    if (newValue != currentValue) {
-        // Filter out small changes in value unless the value is converging on the axis
-        // bounds or center point.  This is intended to reduce the amount of information
-        // sent to applications by particularly noisy joysticks (such as PS3).
-        if (fabs(newValue - currentValue) > filter
-                || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, min)
-                || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, max)
-                || hasMovedNearerToValueWithinFilteredRange(filter, newValue, currentValue, 0)) {
-            return true;
-        }
-    }
-    return false;
-}
-
-bool JoystickInputMapper::hasMovedNearerToValueWithinFilteredRange(
-        float filter, float newValue, float currentValue, float thresholdValue) {
-    float newDistance = fabs(newValue - thresholdValue);
-    if (newDistance < filter) {
-        float oldDistance = fabs(currentValue - thresholdValue);
-        if (newDistance < oldDistance) {
-            return true;
-        }
-    }
-    return false;
-}
-
-} // namespace android
diff --git a/services/input/InputReader.h b/services/input/InputReader.h
deleted file mode 100644
index a8bb636..0000000
--- a/services/input/InputReader.h
+++ /dev/null
@@ -1,1816 +0,0 @@
-/*
- * Copyright (C) 2010 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 _UI_INPUT_READER_H
-#define _UI_INPUT_READER_H
-
-#include "EventHub.h"
-#include "PointerController.h"
-#include "InputListener.h"
-
-#include <input/Input.h>
-#include <input/VelocityControl.h>
-#include <input/VelocityTracker.h>
-#include <utils/KeyedVector.h>
-#include <utils/threads.h>
-#include <utils/Timers.h>
-#include <utils/RefBase.h>
-#include <utils/String8.h>
-#include <utils/BitSet.h>
-
-#include <stddef.h>
-#include <unistd.h>
-
-// Maximum supported size of a vibration pattern.
-// Must be at least 2.
-#define MAX_VIBRATE_PATTERN_SIZE 100
-
-// Maximum allowable delay value in a vibration pattern before
-// which the delay will be truncated.
-#define MAX_VIBRATE_PATTERN_DELAY_NSECS (1000000 * 1000000000LL)
-
-namespace android {
-
-class InputDevice;
-class InputMapper;
-
-/*
- * Describes how coordinates are mapped on a physical display.
- * See com.android.server.display.DisplayViewport.
- */
-struct DisplayViewport {
-    int32_t displayId; // -1 if invalid
-    int32_t orientation;
-    int32_t logicalLeft;
-    int32_t logicalTop;
-    int32_t logicalRight;
-    int32_t logicalBottom;
-    int32_t physicalLeft;
-    int32_t physicalTop;
-    int32_t physicalRight;
-    int32_t physicalBottom;
-    int32_t deviceWidth;
-    int32_t deviceHeight;
-
-    DisplayViewport() :
-            displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
-            logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
-            physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
-            deviceWidth(0), deviceHeight(0) {
-    }
-
-    bool operator==(const DisplayViewport& other) const {
-        return displayId == other.displayId
-                && orientation == other.orientation
-                && logicalLeft == other.logicalLeft
-                && logicalTop == other.logicalTop
-                && logicalRight == other.logicalRight
-                && logicalBottom == other.logicalBottom
-                && physicalLeft == other.physicalLeft
-                && physicalTop == other.physicalTop
-                && physicalRight == other.physicalRight
-                && physicalBottom == other.physicalBottom
-                && deviceWidth == other.deviceWidth
-                && deviceHeight == other.deviceHeight;
-    }
-
-    bool operator!=(const DisplayViewport& other) const {
-        return !(*this == other);
-    }
-
-    inline bool isValid() const {
-        return displayId >= 0;
-    }
-
-    void setNonDisplayViewport(int32_t width, int32_t height) {
-        displayId = ADISPLAY_ID_NONE;
-        orientation = DISPLAY_ORIENTATION_0;
-        logicalLeft = 0;
-        logicalTop = 0;
-        logicalRight = width;
-        logicalBottom = height;
-        physicalLeft = 0;
-        physicalTop = 0;
-        physicalRight = width;
-        physicalBottom = height;
-        deviceWidth = width;
-        deviceHeight = height;
-    }
-};
-
-/*
- * Input reader configuration.
- *
- * Specifies various options that modify the behavior of the input reader.
- */
-struct InputReaderConfiguration {
-    // Describes changes that have occurred.
-    enum {
-        // The pointer speed changed.
-        CHANGE_POINTER_SPEED = 1 << 0,
-
-        // The pointer gesture control changed.
-        CHANGE_POINTER_GESTURE_ENABLEMENT = 1 << 1,
-
-        // The display size or orientation changed.
-        CHANGE_DISPLAY_INFO = 1 << 2,
-
-        // The visible touches option changed.
-        CHANGE_SHOW_TOUCHES = 1 << 3,
-
-        // The keyboard layouts must be reloaded.
-        CHANGE_KEYBOARD_LAYOUTS = 1 << 4,
-
-        // The device name alias supplied by the may have changed for some devices.
-        CHANGE_DEVICE_ALIAS = 1 << 5,
-
-        // All devices must be reopened.
-        CHANGE_MUST_REOPEN = 1 << 31,
-    };
-
-    // Gets the amount of time to disable virtual keys after the screen is touched
-    // in order to filter out accidental virtual key presses due to swiping gestures
-    // or taps near the edge of the display.  May be 0 to disable the feature.
-    nsecs_t virtualKeyQuietTime;
-
-    // The excluded device names for the platform.
-    // Devices with these names will be ignored.
-    Vector<String8> excludedDeviceNames;
-
-    // Velocity control parameters for mouse pointer movements.
-    VelocityControlParameters pointerVelocityControlParameters;
-
-    // Velocity control parameters for mouse wheel movements.
-    VelocityControlParameters wheelVelocityControlParameters;
-
-    // True if pointer gestures are enabled.
-    bool pointerGesturesEnabled;
-
-    // Quiet time between certain pointer gesture transitions.
-    // Time to allow for all fingers or buttons to settle into a stable state before
-    // starting a new gesture.
-    nsecs_t pointerGestureQuietInterval;
-
-    // The minimum speed that a pointer must travel for us to consider switching the active
-    // touch pointer to it during a drag.  This threshold is set to avoid switching due
-    // to noise from a finger resting on the touch pad (perhaps just pressing it down).
-    float pointerGestureDragMinSwitchSpeed; // in pixels per second
-
-    // Tap gesture delay time.
-    // The time between down and up must be less than this to be considered a tap.
-    nsecs_t pointerGestureTapInterval;
-
-    // Tap drag gesture delay time.
-    // The time between the previous tap's up and the next down must be less than
-    // this to be considered a drag.  Otherwise, the previous tap is finished and a
-    // new tap begins.
-    //
-    // Note that the previous tap will be held down for this entire duration so this
-    // interval must be shorter than the long press timeout.
-    nsecs_t pointerGestureTapDragInterval;
-
-    // The distance in pixels that the pointer is allowed to move from initial down
-    // to up and still be called a tap.
-    float pointerGestureTapSlop; // in pixels
-
-    // Time after the first touch points go down to settle on an initial centroid.
-    // This is intended to be enough time to handle cases where the user puts down two
-    // fingers at almost but not quite exactly the same time.
-    nsecs_t pointerGestureMultitouchSettleInterval;
-
-    // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when
-    // at least two pointers have moved at least this far from their starting place.
-    float pointerGestureMultitouchMinDistance; // in pixels
-
-    // The transition from PRESS to SWIPE gesture mode can only occur when the
-    // cosine of the angle between the two vectors is greater than or equal to than this value
-    // which indicates that the vectors are oriented in the same direction.
-    // When the vectors are oriented in the exactly same direction, the cosine is 1.0.
-    // (In exactly opposite directions, the cosine is -1.0.)
-    float pointerGestureSwipeTransitionAngleCosine;
-
-    // The transition from PRESS to SWIPE gesture mode can only occur when the
-    // fingers are no more than this far apart relative to the diagonal size of
-    // the touch pad.  For example, a ratio of 0.5 means that the fingers must be
-    // no more than half the diagonal size of the touch pad apart.
-    float pointerGestureSwipeMaxWidthRatio;
-
-    // The gesture movement speed factor relative to the size of the display.
-    // Movement speed applies when the fingers are moving in the same direction.
-    // Without acceleration, a full swipe of the touch pad diagonal in movement mode
-    // will cover this portion of the display diagonal.
-    float pointerGestureMovementSpeedRatio;
-
-    // The gesture zoom speed factor relative to the size of the display.
-    // Zoom speed applies when the fingers are mostly moving relative to each other
-    // to execute a scale gesture or similar.
-    // Without acceleration, a full swipe of the touch pad diagonal in zoom mode
-    // will cover this portion of the display diagonal.
-    float pointerGestureZoomSpeedRatio;
-
-    // True to show the location of touches on the touch screen as spots.
-    bool showTouches;
-
-    InputReaderConfiguration() :
-            virtualKeyQuietTime(0),
-            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
-            wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f),
-            pointerGesturesEnabled(true),
-            pointerGestureQuietInterval(100 * 1000000LL), // 100 ms
-            pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second
-            pointerGestureTapInterval(150 * 1000000LL), // 150 ms
-            pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms
-            pointerGestureTapSlop(10.0f), // 10 pixels
-            pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms
-            pointerGestureMultitouchMinDistance(15), // 15 pixels
-            pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees
-            pointerGestureSwipeMaxWidthRatio(0.25f),
-            pointerGestureMovementSpeedRatio(0.8f),
-            pointerGestureZoomSpeedRatio(0.3f),
-            showTouches(false) { }
-
-    bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
-    void setDisplayInfo(bool external, const DisplayViewport& viewport);
-
-private:
-    DisplayViewport mInternalDisplay;
-    DisplayViewport mExternalDisplay;
-};
-
-
-/*
- * Input reader policy interface.
- *
- * The input reader policy is used by the input reader to interact with the Window Manager
- * and other system components.
- *
- * The actual implementation is partially supported by callbacks into the DVM
- * via JNI.  This interface is also mocked in the unit tests.
- *
- * These methods must NOT re-enter the input reader since they may be called while
- * holding the input reader lock.
- */
-class InputReaderPolicyInterface : public virtual RefBase {
-protected:
-    InputReaderPolicyInterface() { }
-    virtual ~InputReaderPolicyInterface() { }
-
-public:
-    /* Gets the input reader configuration. */
-    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0;
-
-    /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */
-    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0;
-
-    /* Notifies the input reader policy that some input devices have changed
-     * and provides information about all current input devices.
-     */
-    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) = 0;
-
-    /* Gets the keyboard layout for a particular input device. */
-    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) = 0;
-
-    /* Gets a user-supplied alias for a particular input device, or an empty string if none. */
-    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) = 0;
-};
-
-
-/* Processes raw input events and sends cooked event data to an input listener. */
-class InputReaderInterface : public virtual RefBase {
-protected:
-    InputReaderInterface() { }
-    virtual ~InputReaderInterface() { }
-
-public:
-    /* Dumps the state of the input reader.
-     *
-     * This method may be called on any thread (usually by the input manager). */
-    virtual void dump(String8& dump) = 0;
-
-    /* Called by the heatbeat to ensures that the reader has not deadlocked. */
-    virtual void monitor() = 0;
-
-    /* Runs a single iteration of the processing loop.
-     * Nominally reads and processes one incoming message from the EventHub.
-     *
-     * This method should be called on the input reader thread.
-     */
-    virtual void loopOnce() = 0;
-
-    /* Gets information about all input devices.
-     *
-     * This method may be called on any thread (usually by the input manager).
-     */
-    virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices) = 0;
-
-    /* Query current input state. */
-    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
-            int32_t scanCode) = 0;
-    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
-            int32_t keyCode) = 0;
-    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
-            int32_t sw) = 0;
-
-    /* Determine whether physical keys exist for the given framework-domain key codes. */
-    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
-            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0;
-
-    /* Requests that a reconfiguration of all input devices.
-     * The changes flag is a bitfield that indicates what has changed and whether
-     * the input devices must all be reopened. */
-    virtual void requestRefreshConfiguration(uint32_t changes) = 0;
-
-    /* Controls the vibrator of a particular input device. */
-    virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
-            ssize_t repeat, int32_t token) = 0;
-    virtual void cancelVibrate(int32_t deviceId, int32_t token) = 0;
-};
-
-
-/* Internal interface used by individual input devices to access global input device state
- * and parameters maintained by the input reader.
- */
-class InputReaderContext {
-public:
-    InputReaderContext() { }
-    virtual ~InputReaderContext() { }
-
-    virtual void updateGlobalMetaState() = 0;
-    virtual int32_t getGlobalMetaState() = 0;
-
-    virtual void disableVirtualKeysUntil(nsecs_t time) = 0;
-    virtual bool shouldDropVirtualKey(nsecs_t now,
-            InputDevice* device, int32_t keyCode, int32_t scanCode) = 0;
-
-    virtual void fadePointer() = 0;
-
-    virtual void requestTimeoutAtTime(nsecs_t when) = 0;
-    virtual int32_t bumpGeneration() = 0;
-
-    virtual InputReaderPolicyInterface* getPolicy() = 0;
-    virtual InputListenerInterface* getListener() = 0;
-    virtual EventHubInterface* getEventHub() = 0;
-};
-
-
-/* The input reader reads raw event data from the event hub and processes it into input events
- * that it sends to the input listener.  Some functions of the input reader, such as early
- * event filtering in low power states, are controlled by a separate policy object.
- *
- * The InputReader owns a collection of InputMappers.  Most of the work it does happens
- * on the input reader thread but the InputReader can receive queries from other system
- * components running on arbitrary threads.  To keep things manageable, the InputReader
- * uses a single Mutex to guard its state.  The Mutex may be held while calling into the
- * EventHub or the InputReaderPolicy but it is never held while calling into the
- * InputListener.
- */
-class InputReader : public InputReaderInterface {
-public:
-    InputReader(const sp<EventHubInterface>& eventHub,
-            const sp<InputReaderPolicyInterface>& policy,
-            const sp<InputListenerInterface>& listener);
-    virtual ~InputReader();
-
-    virtual void dump(String8& dump);
-    virtual void monitor();
-
-    virtual void loopOnce();
-
-    virtual void getInputDevices(Vector<InputDeviceInfo>& outInputDevices);
-
-    virtual int32_t getScanCodeState(int32_t deviceId, uint32_t sourceMask,
-            int32_t scanCode);
-    virtual int32_t getKeyCodeState(int32_t deviceId, uint32_t sourceMask,
-            int32_t keyCode);
-    virtual int32_t getSwitchState(int32_t deviceId, uint32_t sourceMask,
-            int32_t sw);
-
-    virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask,
-            size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags);
-
-    virtual void requestRefreshConfiguration(uint32_t changes);
-
-    virtual void vibrate(int32_t deviceId, const nsecs_t* pattern, size_t patternSize,
-            ssize_t repeat, int32_t token);
-    virtual void cancelVibrate(int32_t deviceId, int32_t token);
-
-protected:
-    // These members are protected so they can be instrumented by test cases.
-    virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
-            const InputDeviceIdentifier& identifier, uint32_t classes);
-
-    class ContextImpl : public InputReaderContext {
-        InputReader* mReader;
-
-    public:
-        ContextImpl(InputReader* reader);
-
-        virtual void updateGlobalMetaState();
-        virtual int32_t getGlobalMetaState();
-        virtual void disableVirtualKeysUntil(nsecs_t time);
-        virtual bool shouldDropVirtualKey(nsecs_t now,
-                InputDevice* device, int32_t keyCode, int32_t scanCode);
-        virtual void fadePointer();
-        virtual void requestTimeoutAtTime(nsecs_t when);
-        virtual int32_t bumpGeneration();
-        virtual InputReaderPolicyInterface* getPolicy();
-        virtual InputListenerInterface* getListener();
-        virtual EventHubInterface* getEventHub();
-    } mContext;
-
-    friend class ContextImpl;
-
-private:
-    Mutex mLock;
-
-    Condition mReaderIsAliveCondition;
-
-    sp<EventHubInterface> mEventHub;
-    sp<InputReaderPolicyInterface> mPolicy;
-    sp<QueuedInputListener> mQueuedListener;
-
-    InputReaderConfiguration mConfig;
-
-    // The event queue.
-    static const int EVENT_BUFFER_SIZE = 256;
-    RawEvent mEventBuffer[EVENT_BUFFER_SIZE];
-
-    KeyedVector<int32_t, InputDevice*> mDevices;
-
-    // low-level input event decoding and device management
-    void processEventsLocked(const RawEvent* rawEvents, size_t count);
-
-    void addDeviceLocked(nsecs_t when, int32_t deviceId);
-    void removeDeviceLocked(nsecs_t when, int32_t deviceId);
-    void processEventsForDeviceLocked(int32_t deviceId, const RawEvent* rawEvents, size_t count);
-    void timeoutExpiredLocked(nsecs_t when);
-
-    void handleConfigurationChangedLocked(nsecs_t when);
-
-    int32_t mGlobalMetaState;
-    void updateGlobalMetaStateLocked();
-    int32_t getGlobalMetaStateLocked();
-
-    void fadePointerLocked();
-
-    int32_t mGeneration;
-    int32_t bumpGenerationLocked();
-
-    void getInputDevicesLocked(Vector<InputDeviceInfo>& outInputDevices);
-
-    nsecs_t mDisableVirtualKeysTimeout;
-    void disableVirtualKeysUntilLocked(nsecs_t time);
-    bool shouldDropVirtualKeyLocked(nsecs_t now,
-            InputDevice* device, int32_t keyCode, int32_t scanCode);
-
-    nsecs_t mNextTimeout;
-    void requestTimeoutAtTimeLocked(nsecs_t when);
-
-    uint32_t mConfigurationChangesToRefresh;
-    void refreshConfigurationLocked(uint32_t changes);
-
-    // state queries
-    typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code);
-    int32_t getStateLocked(int32_t deviceId, uint32_t sourceMask, int32_t code,
-            GetStateFunc getStateFunc);
-    bool markSupportedKeyCodesLocked(int32_t deviceId, uint32_t sourceMask, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags);
-};
-
-
-/* Reads raw events from the event hub and processes them, endlessly. */
-class InputReaderThread : public Thread {
-public:
-    InputReaderThread(const sp<InputReaderInterface>& reader);
-    virtual ~InputReaderThread();
-
-private:
-    sp<InputReaderInterface> mReader;
-
-    virtual bool threadLoop();
-};
-
-
-/* Represents the state of a single input device. */
-class InputDevice {
-public:
-    InputDevice(InputReaderContext* context, int32_t id, int32_t generation, int32_t
-            controllerNumber, const InputDeviceIdentifier& identifier, uint32_t classes);
-    ~InputDevice();
-
-    inline InputReaderContext* getContext() { return mContext; }
-    inline int32_t getId() const { return mId; }
-    inline int32_t getControllerNumber() const { return mControllerNumber; }
-    inline int32_t getGeneration() const { return mGeneration; }
-    inline const String8& getName() const { return mIdentifier.name; }
-    inline uint32_t getClasses() const { return mClasses; }
-    inline uint32_t getSources() const { return mSources; }
-
-    inline bool isExternal() { return mIsExternal; }
-    inline void setExternal(bool external) { mIsExternal = external; }
-
-    inline bool isIgnored() { return mMappers.isEmpty(); }
-
-    void dump(String8& dump);
-    void addMapper(InputMapper* mapper);
-    void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
-    void reset(nsecs_t when);
-    void process(const RawEvent* rawEvents, size_t count);
-    void timeoutExpired(nsecs_t when);
-
-    void getDeviceInfo(InputDeviceInfo* outDeviceInfo);
-    int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
-    int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
-    int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
-    bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags);
-    void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat, int32_t token);
-    void cancelVibrate(int32_t token);
-
-    int32_t getMetaState();
-
-    void fadePointer();
-
-    void bumpGeneration();
-
-    void notifyReset(nsecs_t when);
-
-    inline const PropertyMap& getConfiguration() { return mConfiguration; }
-    inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
-
-    bool hasKey(int32_t code) {
-        return getEventHub()->hasScanCode(mId, code);
-    }
-
-    bool hasAbsoluteAxis(int32_t code) {
-        RawAbsoluteAxisInfo info;
-        getEventHub()->getAbsoluteAxisInfo(mId, code, &info);
-        return info.valid;
-    }
-
-    bool isKeyPressed(int32_t code) {
-        return getEventHub()->getScanCodeState(mId, code) == AKEY_STATE_DOWN;
-    }
-
-    int32_t getAbsoluteAxisValue(int32_t code) {
-        int32_t value;
-        getEventHub()->getAbsoluteAxisValue(mId, code, &value);
-        return value;
-    }
-
-private:
-    InputReaderContext* mContext;
-    int32_t mId;
-    int32_t mControllerNumber;
-    int32_t mGeneration;
-    InputDeviceIdentifier mIdentifier;
-    String8 mAlias;
-    uint32_t mClasses;
-
-    Vector<InputMapper*> mMappers;
-
-    uint32_t mSources;
-    bool mIsExternal;
-    bool mDropUntilNextSync;
-
-    typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
-    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
-
-    PropertyMap mConfiguration;
-};
-
-
-/* Keeps track of the state of mouse or touch pad buttons. */
-class CursorButtonAccumulator {
-public:
-    CursorButtonAccumulator();
-    void reset(InputDevice* device);
-
-    void process(const RawEvent* rawEvent);
-
-    uint32_t getButtonState() const;
-
-private:
-    bool mBtnLeft;
-    bool mBtnRight;
-    bool mBtnMiddle;
-    bool mBtnBack;
-    bool mBtnSide;
-    bool mBtnForward;
-    bool mBtnExtra;
-    bool mBtnTask;
-
-    void clearButtons();
-};
-
-
-/* Keeps track of cursor movements. */
-
-class CursorMotionAccumulator {
-public:
-    CursorMotionAccumulator();
-    void reset(InputDevice* device);
-
-    void process(const RawEvent* rawEvent);
-    void finishSync();
-
-    inline int32_t getRelativeX() const { return mRelX; }
-    inline int32_t getRelativeY() const { return mRelY; }
-
-private:
-    int32_t mRelX;
-    int32_t mRelY;
-
-    void clearRelativeAxes();
-};
-
-
-/* Keeps track of cursor scrolling motions. */
-
-class CursorScrollAccumulator {
-public:
-    CursorScrollAccumulator();
-    void configure(InputDevice* device);
-    void reset(InputDevice* device);
-
-    void process(const RawEvent* rawEvent);
-    void finishSync();
-
-    inline bool haveRelativeVWheel() const { return mHaveRelWheel; }
-    inline bool haveRelativeHWheel() const { return mHaveRelHWheel; }
-
-    inline int32_t getRelativeX() const { return mRelX; }
-    inline int32_t getRelativeY() const { return mRelY; }
-    inline int32_t getRelativeVWheel() const { return mRelWheel; }
-    inline int32_t getRelativeHWheel() const { return mRelHWheel; }
-
-private:
-    bool mHaveRelWheel;
-    bool mHaveRelHWheel;
-
-    int32_t mRelX;
-    int32_t mRelY;
-    int32_t mRelWheel;
-    int32_t mRelHWheel;
-
-    void clearRelativeAxes();
-};
-
-
-/* Keeps track of the state of touch, stylus and tool buttons. */
-class TouchButtonAccumulator {
-public:
-    TouchButtonAccumulator();
-    void configure(InputDevice* device);
-    void reset(InputDevice* device);
-
-    void process(const RawEvent* rawEvent);
-
-    uint32_t getButtonState() const;
-    int32_t getToolType() const;
-    bool isToolActive() const;
-    bool isHovering() const;
-    bool hasStylus() const;
-
-private:
-    bool mHaveBtnTouch;
-    bool mHaveStylus;
-
-    bool mBtnTouch;
-    bool mBtnStylus;
-    bool mBtnStylus2;
-    bool mBtnToolFinger;
-    bool mBtnToolPen;
-    bool mBtnToolRubber;
-    bool mBtnToolBrush;
-    bool mBtnToolPencil;
-    bool mBtnToolAirbrush;
-    bool mBtnToolMouse;
-    bool mBtnToolLens;
-    bool mBtnToolDoubleTap;
-    bool mBtnToolTripleTap;
-    bool mBtnToolQuadTap;
-
-    void clearButtons();
-};
-
-
-/* Raw axis information from the driver. */
-struct RawPointerAxes {
-    RawAbsoluteAxisInfo x;
-    RawAbsoluteAxisInfo y;
-    RawAbsoluteAxisInfo pressure;
-    RawAbsoluteAxisInfo touchMajor;
-    RawAbsoluteAxisInfo touchMinor;
-    RawAbsoluteAxisInfo toolMajor;
-    RawAbsoluteAxisInfo toolMinor;
-    RawAbsoluteAxisInfo orientation;
-    RawAbsoluteAxisInfo distance;
-    RawAbsoluteAxisInfo tiltX;
-    RawAbsoluteAxisInfo tiltY;
-    RawAbsoluteAxisInfo trackingId;
-    RawAbsoluteAxisInfo slot;
-
-    RawPointerAxes();
-    void clear();
-};
-
-
-/* Raw data for a collection of pointers including a pointer id mapping table. */
-struct RawPointerData {
-    struct Pointer {
-        uint32_t id;
-        int32_t x;
-        int32_t y;
-        int32_t pressure;
-        int32_t touchMajor;
-        int32_t touchMinor;
-        int32_t toolMajor;
-        int32_t toolMinor;
-        int32_t orientation;
-        int32_t distance;
-        int32_t tiltX;
-        int32_t tiltY;
-        int32_t toolType; // a fully decoded AMOTION_EVENT_TOOL_TYPE constant
-        bool isHovering;
-    };
-
-    uint32_t pointerCount;
-    Pointer pointers[MAX_POINTERS];
-    BitSet32 hoveringIdBits, touchingIdBits;
-    uint32_t idToIndex[MAX_POINTER_ID + 1];
-
-    RawPointerData();
-    void clear();
-    void copyFrom(const RawPointerData& other);
-    void getCentroidOfTouchingPointers(float* outX, float* outY) const;
-
-    inline void markIdBit(uint32_t id, bool isHovering) {
-        if (isHovering) {
-            hoveringIdBits.markBit(id);
-        } else {
-            touchingIdBits.markBit(id);
-        }
-    }
-
-    inline void clearIdBits() {
-        hoveringIdBits.clear();
-        touchingIdBits.clear();
-    }
-
-    inline const Pointer& pointerForId(uint32_t id) const {
-        return pointers[idToIndex[id]];
-    }
-
-    inline bool isHovering(uint32_t pointerIndex) {
-        return pointers[pointerIndex].isHovering;
-    }
-};
-
-
-/* Cooked data for a collection of pointers including a pointer id mapping table. */
-struct CookedPointerData {
-    uint32_t pointerCount;
-    PointerProperties pointerProperties[MAX_POINTERS];
-    PointerCoords pointerCoords[MAX_POINTERS];
-    BitSet32 hoveringIdBits, touchingIdBits;
-    uint32_t idToIndex[MAX_POINTER_ID + 1];
-
-    CookedPointerData();
-    void clear();
-    void copyFrom(const CookedPointerData& other);
-
-    inline const PointerCoords& pointerCoordsForId(uint32_t id) const {
-        return pointerCoords[idToIndex[id]];
-    }
-
-    inline bool isHovering(uint32_t pointerIndex) {
-        return hoveringIdBits.hasBit(pointerProperties[pointerIndex].id);
-    }
-};
-
-
-/* Keeps track of the state of single-touch protocol. */
-class SingleTouchMotionAccumulator {
-public:
-    SingleTouchMotionAccumulator();
-
-    void process(const RawEvent* rawEvent);
-    void reset(InputDevice* device);
-
-    inline int32_t getAbsoluteX() const { return mAbsX; }
-    inline int32_t getAbsoluteY() const { return mAbsY; }
-    inline int32_t getAbsolutePressure() const { return mAbsPressure; }
-    inline int32_t getAbsoluteToolWidth() const { return mAbsToolWidth; }
-    inline int32_t getAbsoluteDistance() const { return mAbsDistance; }
-    inline int32_t getAbsoluteTiltX() const { return mAbsTiltX; }
-    inline int32_t getAbsoluteTiltY() const { return mAbsTiltY; }
-
-private:
-    int32_t mAbsX;
-    int32_t mAbsY;
-    int32_t mAbsPressure;
-    int32_t mAbsToolWidth;
-    int32_t mAbsDistance;
-    int32_t mAbsTiltX;
-    int32_t mAbsTiltY;
-
-    void clearAbsoluteAxes();
-};
-
-
-/* Keeps track of the state of multi-touch protocol. */
-class MultiTouchMotionAccumulator {
-public:
-    class Slot {
-    public:
-        inline bool isInUse() const { return mInUse; }
-        inline int32_t getX() const { return mAbsMTPositionX; }
-        inline int32_t getY() const { return mAbsMTPositionY; }
-        inline int32_t getTouchMajor() const { return mAbsMTTouchMajor; }
-        inline int32_t getTouchMinor() const {
-            return mHaveAbsMTTouchMinor ? mAbsMTTouchMinor : mAbsMTTouchMajor; }
-        inline int32_t getToolMajor() const { return mAbsMTWidthMajor; }
-        inline int32_t getToolMinor() const {
-            return mHaveAbsMTWidthMinor ? mAbsMTWidthMinor : mAbsMTWidthMajor; }
-        inline int32_t getOrientation() const { return mAbsMTOrientation; }
-        inline int32_t getTrackingId() const { return mAbsMTTrackingId; }
-        inline int32_t getPressure() const { return mAbsMTPressure; }
-        inline int32_t getDistance() const { return mAbsMTDistance; }
-        inline int32_t getToolType() const;
-
-    private:
-        friend class MultiTouchMotionAccumulator;
-
-        bool mInUse;
-        bool mHaveAbsMTTouchMinor;
-        bool mHaveAbsMTWidthMinor;
-        bool mHaveAbsMTToolType;
-
-        int32_t mAbsMTPositionX;
-        int32_t mAbsMTPositionY;
-        int32_t mAbsMTTouchMajor;
-        int32_t mAbsMTTouchMinor;
-        int32_t mAbsMTWidthMajor;
-        int32_t mAbsMTWidthMinor;
-        int32_t mAbsMTOrientation;
-        int32_t mAbsMTTrackingId;
-        int32_t mAbsMTPressure;
-        int32_t mAbsMTDistance;
-        int32_t mAbsMTToolType;
-
-        Slot();
-        void clear();
-    };
-
-    MultiTouchMotionAccumulator();
-    ~MultiTouchMotionAccumulator();
-
-    void configure(InputDevice* device, size_t slotCount, bool usingSlotsProtocol);
-    void reset(InputDevice* device);
-    void process(const RawEvent* rawEvent);
-    void finishSync();
-    bool hasStylus() const;
-
-    inline size_t getSlotCount() const { return mSlotCount; }
-    inline const Slot* getSlot(size_t index) const { return &mSlots[index]; }
-
-private:
-    int32_t mCurrentSlot;
-    Slot* mSlots;
-    size_t mSlotCount;
-    bool mUsingSlotsProtocol;
-    bool mHaveStylus;
-
-    void clearSlots(int32_t initialSlot);
-};
-
-
-/* An input mapper transforms raw input events into cooked event data.
- * A single input device can have multiple associated input mappers in order to interpret
- * different classes of events.
- *
- * InputMapper lifecycle:
- * - create
- * - configure with 0 changes
- * - reset
- * - process, process, process (may occasionally reconfigure with non-zero changes or reset)
- * - reset
- * - destroy
- */
-class InputMapper {
-public:
-    InputMapper(InputDevice* device);
-    virtual ~InputMapper();
-
-    inline InputDevice* getDevice() { return mDevice; }
-    inline int32_t getDeviceId() { return mDevice->getId(); }
-    inline const String8 getDeviceName() { return mDevice->getName(); }
-    inline InputReaderContext* getContext() { return mContext; }
-    inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); }
-    inline InputListenerInterface* getListener() { return mContext->getListener(); }
-    inline EventHubInterface* getEventHub() { return mContext->getEventHub(); }
-
-    virtual uint32_t getSources() = 0;
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
-    virtual void dump(String8& dump);
-    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent) = 0;
-    virtual void timeoutExpired(nsecs_t when);
-
-    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
-    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
-    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
-    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags);
-    virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
-            int32_t token);
-    virtual void cancelVibrate(int32_t token);
-
-    virtual int32_t getMetaState();
-
-    virtual void fadePointer();
-
-protected:
-    InputDevice* mDevice;
-    InputReaderContext* mContext;
-
-    status_t getAbsoluteAxisInfo(int32_t axis, RawAbsoluteAxisInfo* axisInfo);
-    void bumpGeneration();
-
-    static void dumpRawAbsoluteAxisInfo(String8& dump,
-            const RawAbsoluteAxisInfo& axis, const char* name);
-};
-
-
-class SwitchInputMapper : public InputMapper {
-public:
-    SwitchInputMapper(InputDevice* device);
-    virtual ~SwitchInputMapper();
-
-    virtual uint32_t getSources();
-    virtual void process(const RawEvent* rawEvent);
-
-    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode);
-
-private:
-    uint32_t mUpdatedSwitchValues;
-    uint32_t mUpdatedSwitchMask;
-
-    void processSwitch(int32_t switchCode, int32_t switchValue);
-    void sync(nsecs_t when);
-};
-
-
-class VibratorInputMapper : public InputMapper {
-public:
-    VibratorInputMapper(InputDevice* device);
-    virtual ~VibratorInputMapper();
-
-    virtual uint32_t getSources();
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
-    virtual void process(const RawEvent* rawEvent);
-
-    virtual void vibrate(const nsecs_t* pattern, size_t patternSize, ssize_t repeat,
-            int32_t token);
-    virtual void cancelVibrate(int32_t token);
-    virtual void timeoutExpired(nsecs_t when);
-    virtual void dump(String8& dump);
-
-private:
-    bool mVibrating;
-    nsecs_t mPattern[MAX_VIBRATE_PATTERN_SIZE];
-    size_t mPatternSize;
-    ssize_t mRepeat;
-    int32_t mToken;
-    ssize_t mIndex;
-    nsecs_t mNextStepTime;
-
-    void nextStep();
-    void stopVibrating();
-};
-
-
-class KeyboardInputMapper : public InputMapper {
-public:
-    KeyboardInputMapper(InputDevice* device, uint32_t source, int32_t keyboardType);
-    virtual ~KeyboardInputMapper();
-
-    virtual uint32_t getSources();
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
-    virtual void dump(String8& dump);
-    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent);
-
-    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
-    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
-    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags);
-
-    virtual int32_t getMetaState();
-
-private:
-    struct KeyDown {
-        int32_t keyCode;
-        int32_t scanCode;
-    };
-
-    uint32_t mSource;
-    int32_t mKeyboardType;
-
-    int32_t mOrientation; // orientation for dpad keys
-
-    Vector<KeyDown> mKeyDowns; // keys that are down
-    int32_t mMetaState;
-    nsecs_t mDownTime; // time of most recent key down
-
-    int32_t mCurrentHidUsage; // most recent HID usage seen this packet, or 0 if none
-
-    struct LedState {
-        bool avail; // led is available
-        bool on;    // we think the led is currently on
-    };
-    LedState mCapsLockLedState;
-    LedState mNumLockLedState;
-    LedState mScrollLockLedState;
-
-    // Immutable configuration parameters.
-    struct Parameters {
-        bool hasAssociatedDisplay;
-        bool orientationAware;
-    } mParameters;
-
-    void configureParameters();
-    void dumpParameters(String8& dump);
-
-    bool isKeyboardOrGamepadKey(int32_t scanCode);
-
-    void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
-            uint32_t policyFlags);
-
-    ssize_t findKeyDown(int32_t scanCode);
-
-    void resetLedState();
-    void initializeLedState(LedState& ledState, int32_t led);
-    void updateLedState(bool reset);
-    void updateLedStateForModifier(LedState& ledState, int32_t led,
-            int32_t modifier, bool reset);
-};
-
-
-class CursorInputMapper : public InputMapper {
-public:
-    CursorInputMapper(InputDevice* device);
-    virtual ~CursorInputMapper();
-
-    virtual uint32_t getSources();
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
-    virtual void dump(String8& dump);
-    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent);
-
-    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
-
-    virtual void fadePointer();
-
-private:
-    // Amount that trackball needs to move in order to generate a key event.
-    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
-
-    // Immutable configuration parameters.
-    struct Parameters {
-        enum Mode {
-            MODE_POINTER,
-            MODE_NAVIGATION,
-        };
-
-        Mode mode;
-        bool hasAssociatedDisplay;
-        bool orientationAware;
-    } mParameters;
-
-    CursorButtonAccumulator mCursorButtonAccumulator;
-    CursorMotionAccumulator mCursorMotionAccumulator;
-    CursorScrollAccumulator mCursorScrollAccumulator;
-
-    int32_t mSource;
-    float mXScale;
-    float mYScale;
-    float mXPrecision;
-    float mYPrecision;
-
-    float mVWheelScale;
-    float mHWheelScale;
-
-    // Velocity controls for mouse pointer and wheel movements.
-    // The controls for X and Y wheel movements are separate to keep them decoupled.
-    VelocityControl mPointerVelocityControl;
-    VelocityControl mWheelXVelocityControl;
-    VelocityControl mWheelYVelocityControl;
-
-    int32_t mOrientation;
-
-    sp<PointerControllerInterface> mPointerController;
-
-    int32_t mButtonState;
-    nsecs_t mDownTime;
-
-    void configureParameters();
-    void dumpParameters(String8& dump);
-
-    void sync(nsecs_t when);
-};
-
-
-class TouchInputMapper : public InputMapper {
-public:
-    TouchInputMapper(InputDevice* device);
-    virtual ~TouchInputMapper();
-
-    virtual uint32_t getSources();
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
-    virtual void dump(String8& dump);
-    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent);
-
-    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode);
-    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode);
-    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags);
-
-    virtual void fadePointer();
-    virtual void timeoutExpired(nsecs_t when);
-
-protected:
-    CursorButtonAccumulator mCursorButtonAccumulator;
-    CursorScrollAccumulator mCursorScrollAccumulator;
-    TouchButtonAccumulator mTouchButtonAccumulator;
-
-    struct VirtualKey {
-        int32_t keyCode;
-        int32_t scanCode;
-        uint32_t flags;
-
-        // computed hit box, specified in touch screen coords based on known display size
-        int32_t hitLeft;
-        int32_t hitTop;
-        int32_t hitRight;
-        int32_t hitBottom;
-
-        inline bool isHit(int32_t x, int32_t y) const {
-            return x >= hitLeft && x <= hitRight && y >= hitTop && y <= hitBottom;
-        }
-    };
-
-    // Input sources and device mode.
-    uint32_t mSource;
-
-    enum DeviceMode {
-        DEVICE_MODE_DISABLED, // input is disabled
-        DEVICE_MODE_DIRECT, // direct mapping (touchscreen)
-        DEVICE_MODE_UNSCALED, // unscaled mapping (touchpad)
-        DEVICE_MODE_NAVIGATION, // unscaled mapping with assist gesture (touch navigation)
-        DEVICE_MODE_POINTER, // pointer mapping (pointer)
-    };
-    DeviceMode mDeviceMode;
-
-    // The reader's configuration.
-    InputReaderConfiguration mConfig;
-
-    // Immutable configuration parameters.
-    struct Parameters {
-        enum DeviceType {
-            DEVICE_TYPE_TOUCH_SCREEN,
-            DEVICE_TYPE_TOUCH_PAD,
-            DEVICE_TYPE_TOUCH_NAVIGATION,
-            DEVICE_TYPE_POINTER,
-        };
-
-        DeviceType deviceType;
-        bool hasAssociatedDisplay;
-        bool associatedDisplayIsExternal;
-        bool orientationAware;
-        bool hasButtonUnderPad;
-
-        enum GestureMode {
-            GESTURE_MODE_POINTER,
-            GESTURE_MODE_SPOTS,
-        };
-        GestureMode gestureMode;
-    } mParameters;
-
-    // Immutable calibration parameters in parsed form.
-    struct Calibration {
-        // Size
-        enum SizeCalibration {
-            SIZE_CALIBRATION_DEFAULT,
-            SIZE_CALIBRATION_NONE,
-            SIZE_CALIBRATION_GEOMETRIC,
-            SIZE_CALIBRATION_DIAMETER,
-            SIZE_CALIBRATION_BOX,
-            SIZE_CALIBRATION_AREA,
-        };
-
-        SizeCalibration sizeCalibration;
-
-        bool haveSizeScale;
-        float sizeScale;
-        bool haveSizeBias;
-        float sizeBias;
-        bool haveSizeIsSummed;
-        bool sizeIsSummed;
-
-        // Pressure
-        enum PressureCalibration {
-            PRESSURE_CALIBRATION_DEFAULT,
-            PRESSURE_CALIBRATION_NONE,
-            PRESSURE_CALIBRATION_PHYSICAL,
-            PRESSURE_CALIBRATION_AMPLITUDE,
-        };
-
-        PressureCalibration pressureCalibration;
-        bool havePressureScale;
-        float pressureScale;
-
-        // Orientation
-        enum OrientationCalibration {
-            ORIENTATION_CALIBRATION_DEFAULT,
-            ORIENTATION_CALIBRATION_NONE,
-            ORIENTATION_CALIBRATION_INTERPOLATED,
-            ORIENTATION_CALIBRATION_VECTOR,
-        };
-
-        OrientationCalibration orientationCalibration;
-
-        // Distance
-        enum DistanceCalibration {
-            DISTANCE_CALIBRATION_DEFAULT,
-            DISTANCE_CALIBRATION_NONE,
-            DISTANCE_CALIBRATION_SCALED,
-        };
-
-        DistanceCalibration distanceCalibration;
-        bool haveDistanceScale;
-        float distanceScale;
-
-        enum CoverageCalibration {
-            COVERAGE_CALIBRATION_DEFAULT,
-            COVERAGE_CALIBRATION_NONE,
-            COVERAGE_CALIBRATION_BOX,
-        };
-
-        CoverageCalibration coverageCalibration;
-
-        inline void applySizeScaleAndBias(float* outSize) const {
-            if (haveSizeScale) {
-                *outSize *= sizeScale;
-            }
-            if (haveSizeBias) {
-                *outSize += sizeBias;
-            }
-            if (*outSize < 0) {
-                *outSize = 0;
-            }
-        }
-    } mCalibration;
-
-    // Raw pointer axis information from the driver.
-    RawPointerAxes mRawPointerAxes;
-
-    // Raw pointer sample data.
-    RawPointerData mCurrentRawPointerData;
-    RawPointerData mLastRawPointerData;
-
-    // Cooked pointer sample data.
-    CookedPointerData mCurrentCookedPointerData;
-    CookedPointerData mLastCookedPointerData;
-
-    // Button state.
-    int32_t mCurrentButtonState;
-    int32_t mLastButtonState;
-
-    // Scroll state.
-    int32_t mCurrentRawVScroll;
-    int32_t mCurrentRawHScroll;
-
-    // Id bits used to differentiate fingers, stylus and mouse tools.
-    BitSet32 mCurrentFingerIdBits; // finger or unknown
-    BitSet32 mLastFingerIdBits;
-    BitSet32 mCurrentStylusIdBits; // stylus or eraser
-    BitSet32 mLastStylusIdBits;
-    BitSet32 mCurrentMouseIdBits; // mouse or lens
-    BitSet32 mLastMouseIdBits;
-
-    // True if we sent a HOVER_ENTER event.
-    bool mSentHoverEnter;
-
-    // The time the primary pointer last went down.
-    nsecs_t mDownTime;
-
-    // The pointer controller, or null if the device is not a pointer.
-    sp<PointerControllerInterface> mPointerController;
-
-    Vector<VirtualKey> mVirtualKeys;
-
-    virtual void configureParameters();
-    virtual void dumpParameters(String8& dump);
-    virtual void configureRawPointerAxes();
-    virtual void dumpRawPointerAxes(String8& dump);
-    virtual void configureSurface(nsecs_t when, bool* outResetNeeded);
-    virtual void dumpSurface(String8& dump);
-    virtual void configureVirtualKeys();
-    virtual void dumpVirtualKeys(String8& dump);
-    virtual void parseCalibration();
-    virtual void resolveCalibration();
-    virtual void dumpCalibration(String8& dump);
-    virtual bool hasStylus() const = 0;
-
-    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds) = 0;
-
-private:
-    // The current viewport.
-    // The components of the viewport are specified in the display's rotated orientation.
-    DisplayViewport mViewport;
-
-    // The surface orientation, width and height set by configureSurface().
-    // The width and height are derived from the viewport but are specified
-    // in the natural orientation.
-    // The surface origin specifies how the surface coordinates should be translated
-    // to align with the logical display coordinate space.
-    // The orientation may be different from the viewport orientation as it specifies
-    // the rotation of the surface coordinates required to produce the viewport's
-    // requested orientation, so it will depend on whether the device is orientation aware.
-    int32_t mSurfaceWidth;
-    int32_t mSurfaceHeight;
-    int32_t mSurfaceLeft;
-    int32_t mSurfaceTop;
-    int32_t mSurfaceOrientation;
-
-    // Translation and scaling factors, orientation-independent.
-    float mXTranslate;
-    float mXScale;
-    float mXPrecision;
-
-    float mYTranslate;
-    float mYScale;
-    float mYPrecision;
-
-    float mGeometricScale;
-
-    float mPressureScale;
-
-    float mSizeScale;
-
-    float mOrientationScale;
-
-    float mDistanceScale;
-
-    bool mHaveTilt;
-    float mTiltXCenter;
-    float mTiltXScale;
-    float mTiltYCenter;
-    float mTiltYScale;
-
-    // Oriented motion ranges for input device info.
-    struct OrientedRanges {
-        InputDeviceInfo::MotionRange x;
-        InputDeviceInfo::MotionRange y;
-        InputDeviceInfo::MotionRange pressure;
-
-        bool haveSize;
-        InputDeviceInfo::MotionRange size;
-
-        bool haveTouchSize;
-        InputDeviceInfo::MotionRange touchMajor;
-        InputDeviceInfo::MotionRange touchMinor;
-
-        bool haveToolSize;
-        InputDeviceInfo::MotionRange toolMajor;
-        InputDeviceInfo::MotionRange toolMinor;
-
-        bool haveOrientation;
-        InputDeviceInfo::MotionRange orientation;
-
-        bool haveDistance;
-        InputDeviceInfo::MotionRange distance;
-
-        bool haveTilt;
-        InputDeviceInfo::MotionRange tilt;
-
-        OrientedRanges() {
-            clear();
-        }
-
-        void clear() {
-            haveSize = false;
-            haveTouchSize = false;
-            haveToolSize = false;
-            haveOrientation = false;
-            haveDistance = false;
-            haveTilt = false;
-        }
-    } mOrientedRanges;
-
-    // Oriented dimensions and precision.
-    float mOrientedXPrecision;
-    float mOrientedYPrecision;
-
-    struct CurrentVirtualKeyState {
-        bool down;
-        bool ignored;
-        nsecs_t downTime;
-        int32_t keyCode;
-        int32_t scanCode;
-    } mCurrentVirtualKey;
-
-    // Scale factor for gesture or mouse based pointer movements.
-    float mPointerXMovementScale;
-    float mPointerYMovementScale;
-
-    // Scale factor for gesture based zooming and other freeform motions.
-    float mPointerXZoomScale;
-    float mPointerYZoomScale;
-
-    // The maximum swipe width.
-    float mPointerGestureMaxSwipeWidth;
-
-    struct PointerDistanceHeapElement {
-        uint32_t currentPointerIndex : 8;
-        uint32_t lastPointerIndex : 8;
-        uint64_t distance : 48; // squared distance
-    };
-
-    enum PointerUsage {
-        POINTER_USAGE_NONE,
-        POINTER_USAGE_GESTURES,
-        POINTER_USAGE_STYLUS,
-        POINTER_USAGE_MOUSE,
-    };
-    PointerUsage mPointerUsage;
-
-    struct PointerGesture {
-        enum Mode {
-            // No fingers, button is not pressed.
-            // Nothing happening.
-            NEUTRAL,
-
-            // No fingers, button is not pressed.
-            // Tap detected.
-            // Emits DOWN and UP events at the pointer location.
-            TAP,
-
-            // Exactly one finger dragging following a tap.
-            // Pointer follows the active finger.
-            // Emits DOWN, MOVE and UP events at the pointer location.
-            //
-            // Detect double-taps when the finger goes up while in TAP_DRAG mode.
-            TAP_DRAG,
-
-            // Button is pressed.
-            // Pointer follows the active finger if there is one.  Other fingers are ignored.
-            // Emits DOWN, MOVE and UP events at the pointer location.
-            BUTTON_CLICK_OR_DRAG,
-
-            // Exactly one finger, button is not pressed.
-            // Pointer follows the active finger.
-            // Emits HOVER_MOVE events at the pointer location.
-            //
-            // Detect taps when the finger goes up while in HOVER mode.
-            HOVER,
-
-            // Exactly two fingers but neither have moved enough to clearly indicate
-            // whether a swipe or freeform gesture was intended.  We consider the
-            // pointer to be pressed so this enables clicking or long-pressing on buttons.
-            // Pointer does not move.
-            // Emits DOWN, MOVE and UP events with a single stationary pointer coordinate.
-            PRESS,
-
-            // Exactly two fingers moving in the same direction, button is not pressed.
-            // Pointer does not move.
-            // Emits DOWN, MOVE and UP events with a single pointer coordinate that
-            // follows the midpoint between both fingers.
-            SWIPE,
-
-            // Two or more fingers moving in arbitrary directions, button is not pressed.
-            // Pointer does not move.
-            // Emits DOWN, POINTER_DOWN, MOVE, POINTER_UP and UP events that follow
-            // each finger individually relative to the initial centroid of the finger.
-            FREEFORM,
-
-            // Waiting for quiet time to end before starting the next gesture.
-            QUIET,
-        };
-
-        // Time the first finger went down.
-        nsecs_t firstTouchTime;
-
-        // The active pointer id from the raw touch data.
-        int32_t activeTouchId; // -1 if none
-
-        // The active pointer id from the gesture last delivered to the application.
-        int32_t activeGestureId; // -1 if none
-
-        // Pointer coords and ids for the current and previous pointer gesture.
-        Mode currentGestureMode;
-        BitSet32 currentGestureIdBits;
-        uint32_t currentGestureIdToIndex[MAX_POINTER_ID + 1];
-        PointerProperties currentGestureProperties[MAX_POINTERS];
-        PointerCoords currentGestureCoords[MAX_POINTERS];
-
-        Mode lastGestureMode;
-        BitSet32 lastGestureIdBits;
-        uint32_t lastGestureIdToIndex[MAX_POINTER_ID + 1];
-        PointerProperties lastGestureProperties[MAX_POINTERS];
-        PointerCoords lastGestureCoords[MAX_POINTERS];
-
-        // Time the pointer gesture last went down.
-        nsecs_t downTime;
-
-        // Time when the pointer went down for a TAP.
-        nsecs_t tapDownTime;
-
-        // Time when the pointer went up for a TAP.
-        nsecs_t tapUpTime;
-
-        // Location of initial tap.
-        float tapX, tapY;
-
-        // Time we started waiting for quiescence.
-        nsecs_t quietTime;
-
-        // Reference points for multitouch gestures.
-        float referenceTouchX;    // reference touch X/Y coordinates in surface units
-        float referenceTouchY;
-        float referenceGestureX;  // reference gesture X/Y coordinates in pixels
-        float referenceGestureY;
-
-        // Distance that each pointer has traveled which has not yet been
-        // subsumed into the reference gesture position.
-        BitSet32 referenceIdBits;
-        struct Delta {
-            float dx, dy;
-        };
-        Delta referenceDeltas[MAX_POINTER_ID + 1];
-
-        // Describes how touch ids are mapped to gesture ids for freeform gestures.
-        uint32_t freeformTouchToGestureIdMap[MAX_POINTER_ID + 1];
-
-        // A velocity tracker for determining whether to switch active pointers during drags.
-        VelocityTracker velocityTracker;
-
-        void reset() {
-            firstTouchTime = LLONG_MIN;
-            activeTouchId = -1;
-            activeGestureId = -1;
-            currentGestureMode = NEUTRAL;
-            currentGestureIdBits.clear();
-            lastGestureMode = NEUTRAL;
-            lastGestureIdBits.clear();
-            downTime = 0;
-            velocityTracker.clear();
-            resetTap();
-            resetQuietTime();
-        }
-
-        void resetTap() {
-            tapDownTime = LLONG_MIN;
-            tapUpTime = LLONG_MIN;
-        }
-
-        void resetQuietTime() {
-            quietTime = LLONG_MIN;
-        }
-    } mPointerGesture;
-
-    struct PointerSimple {
-        PointerCoords currentCoords;
-        PointerProperties currentProperties;
-        PointerCoords lastCoords;
-        PointerProperties lastProperties;
-
-        // True if the pointer is down.
-        bool down;
-
-        // True if the pointer is hovering.
-        bool hovering;
-
-        // Time the pointer last went down.
-        nsecs_t downTime;
-
-        void reset() {
-            currentCoords.clear();
-            currentProperties.clear();
-            lastCoords.clear();
-            lastProperties.clear();
-            down = false;
-            hovering = false;
-            downTime = 0;
-        }
-    } mPointerSimple;
-
-    // The pointer and scroll velocity controls.
-    VelocityControl mPointerVelocityControl;
-    VelocityControl mWheelXVelocityControl;
-    VelocityControl mWheelYVelocityControl;
-
-    void sync(nsecs_t when);
-
-    bool consumeRawTouches(nsecs_t when, uint32_t policyFlags);
-    void dispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
-            int32_t keyEventAction, int32_t keyEventFlags);
-
-    void dispatchTouches(nsecs_t when, uint32_t policyFlags);
-    void dispatchHoverExit(nsecs_t when, uint32_t policyFlags);
-    void dispatchHoverEnterAndMove(nsecs_t when, uint32_t policyFlags);
-    void cookPointerData();
-
-    void dispatchPointerUsage(nsecs_t when, uint32_t policyFlags, PointerUsage pointerUsage);
-    void abortPointerUsage(nsecs_t when, uint32_t policyFlags);
-
-    void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout);
-    void abortPointerGestures(nsecs_t when, uint32_t policyFlags);
-    bool preparePointerGestures(nsecs_t when,
-            bool* outCancelPreviousGesture, bool* outFinishPreviousGesture,
-            bool isTimeout);
-
-    void dispatchPointerStylus(nsecs_t when, uint32_t policyFlags);
-    void abortPointerStylus(nsecs_t when, uint32_t policyFlags);
-
-    void dispatchPointerMouse(nsecs_t when, uint32_t policyFlags);
-    void abortPointerMouse(nsecs_t when, uint32_t policyFlags);
-
-    void dispatchPointerSimple(nsecs_t when, uint32_t policyFlags,
-            bool down, bool hovering);
-    void abortPointerSimple(nsecs_t when, uint32_t policyFlags);
-
-    // Dispatches a motion event.
-    // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the
-    // method will take care of setting the index and transmuting the action to DOWN or UP
-    // it is the first / last pointer to go down / up.
-    void dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32_t source,
-            int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
-            int32_t edgeFlags,
-            const PointerProperties* properties, const PointerCoords* coords,
-            const uint32_t* idToIndex, BitSet32 idBits,
-            int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime);
-
-    // Updates pointer coords and properties for pointers with specified ids that have moved.
-    // Returns true if any of them changed.
-    bool updateMovedPointers(const PointerProperties* inProperties,
-            const PointerCoords* inCoords, const uint32_t* inIdToIndex,
-            PointerProperties* outProperties, PointerCoords* outCoords,
-            const uint32_t* outIdToIndex, BitSet32 idBits) const;
-
-    bool isPointInsideSurface(int32_t x, int32_t y);
-    const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);
-
-    void assignPointerIds();
-};
-
-
-class SingleTouchInputMapper : public TouchInputMapper {
-public:
-    SingleTouchInputMapper(InputDevice* device);
-    virtual ~SingleTouchInputMapper();
-
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent);
-
-protected:
-    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
-    virtual void configureRawPointerAxes();
-    virtual bool hasStylus() const;
-
-private:
-    SingleTouchMotionAccumulator mSingleTouchMotionAccumulator;
-};
-
-
-class MultiTouchInputMapper : public TouchInputMapper {
-public:
-    MultiTouchInputMapper(InputDevice* device);
-    virtual ~MultiTouchInputMapper();
-
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent);
-
-protected:
-    virtual void syncTouch(nsecs_t when, bool* outHavePointerIds);
-    virtual void configureRawPointerAxes();
-    virtual bool hasStylus() const;
-
-private:
-    MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;
-
-    // Specifies the pointer id bits that are in use, and their associated tracking id.
-    BitSet32 mPointerIdBits;
-    int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
-};
-
-
-class JoystickInputMapper : public InputMapper {
-public:
-    JoystickInputMapper(InputDevice* device);
-    virtual ~JoystickInputMapper();
-
-    virtual uint32_t getSources();
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo);
-    virtual void dump(String8& dump);
-    virtual void configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes);
-    virtual void reset(nsecs_t when);
-    virtual void process(const RawEvent* rawEvent);
-
-private:
-    struct Axis {
-        RawAbsoluteAxisInfo rawAxisInfo;
-        AxisInfo axisInfo;
-
-        bool explicitlyMapped; // true if the axis was explicitly assigned an axis id
-
-        float scale;   // scale factor from raw to normalized values
-        float offset;  // offset to add after scaling for normalization
-        float highScale;  // scale factor from raw to normalized values of high split
-        float highOffset; // offset to add after scaling for normalization of high split
-
-        float min;        // normalized inclusive minimum
-        float max;        // normalized inclusive maximum
-        float flat;       // normalized flat region size
-        float fuzz;       // normalized error tolerance
-        float resolution; // normalized resolution in units/mm
-
-        float filter;  // filter out small variations of this size
-        float currentValue; // current value
-        float newValue; // most recent value
-        float highCurrentValue; // current value of high split
-        float highNewValue; // most recent value of high split
-
-        void initialize(const RawAbsoluteAxisInfo& rawAxisInfo, const AxisInfo& axisInfo,
-                bool explicitlyMapped, float scale, float offset,
-                float highScale, float highOffset,
-                float min, float max, float flat, float fuzz, float resolution) {
-            this->rawAxisInfo = rawAxisInfo;
-            this->axisInfo = axisInfo;
-            this->explicitlyMapped = explicitlyMapped;
-            this->scale = scale;
-            this->offset = offset;
-            this->highScale = highScale;
-            this->highOffset = highOffset;
-            this->min = min;
-            this->max = max;
-            this->flat = flat;
-            this->fuzz = fuzz;
-            this->resolution = resolution;
-            this->filter = 0;
-            resetValue();
-        }
-
-        void resetValue() {
-            this->currentValue = 0;
-            this->newValue = 0;
-            this->highCurrentValue = 0;
-            this->highNewValue = 0;
-        }
-    };
-
-    // Axes indexed by raw ABS_* axis index.
-    KeyedVector<int32_t, Axis> mAxes;
-
-    void sync(nsecs_t when, bool force);
-
-    bool haveAxis(int32_t axisId);
-    void pruneAxes(bool ignoreExplicitlyMappedAxes);
-    bool filterAxes(bool force);
-
-    static bool hasValueChangedSignificantly(float filter,
-            float newValue, float currentValue, float min, float max);
-    static bool hasMovedNearerToValueWithinFilteredRange(float filter,
-            float newValue, float currentValue, float thresholdValue);
-
-    static bool isCenteredAxis(int32_t axis);
-    static int32_t getCompatAxis(int32_t axis);
-
-    static void addMotionRange(int32_t axisId, const Axis& axis, InputDeviceInfo* info);
-    static void setPointerCoordsAxisValue(PointerCoords* pointerCoords, int32_t axis,
-            float value);
-};
-
-} // namespace android
-
-#endif // _UI_INPUT_READER_H
diff --git a/services/input/tests/InputDispatcher_test.cpp b/services/input/tests/InputDispatcher_test.cpp
deleted file mode 100644
index 26b4fab..0000000
--- a/services/input/tests/InputDispatcher_test.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (C) 2010 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 "../InputDispatcher.h"
-
-#include <gtest/gtest.h>
-#include <linux/input.h>
-
-namespace android {
-
-// An arbitrary time value.
-static const nsecs_t ARBITRARY_TIME = 1234;
-
-// An arbitrary device id.
-static const int32_t DEVICE_ID = 1;
-
-// An arbitrary injector pid / uid pair that has permission to inject events.
-static const int32_t INJECTOR_PID = 999;
-static const int32_t INJECTOR_UID = 1001;
-
-
-// --- FakeInputDispatcherPolicy ---
-
-class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface {
-    InputDispatcherConfiguration mConfig;
-
-protected:
-    virtual ~FakeInputDispatcherPolicy() {
-    }
-
-public:
-    FakeInputDispatcherPolicy() {
-    }
-
-private:
-    virtual void notifyConfigurationChanged(nsecs_t when) {
-    }
-
-    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
-            const sp<InputWindowHandle>& inputWindowHandle,
-            const String8& reason) {
-        return 0;
-    }
-
-    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
-    }
-
-    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
-        *outConfig = mConfig;
-    }
-
-    virtual bool isKeyRepeatEnabled() {
-        return true;
-    }
-
-    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
-        return true;
-    }
-
-    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags) {
-    }
-
-    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
-    }
-
-    virtual nsecs_t interceptKeyBeforeDispatching(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags) {
-        return 0;
-    }
-
-    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
-        return false;
-    }
-
-    virtual void notifySwitch(nsecs_t when,
-            uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
-    }
-
-    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
-    }
-
-    virtual bool checkInjectEventsPermissionNonReentrant(
-            int32_t injectorPid, int32_t injectorUid) {
-        return false;
-    }
-};
-
-
-// --- InputDispatcherTest ---
-
-class InputDispatcherTest : public testing::Test {
-protected:
-    sp<FakeInputDispatcherPolicy> mFakePolicy;
-    sp<InputDispatcher> mDispatcher;
-
-    virtual void SetUp() {
-        mFakePolicy = new FakeInputDispatcherPolicy();
-        mDispatcher = new InputDispatcher(mFakePolicy);
-    }
-
-    virtual void TearDown() {
-        mFakePolicy.clear();
-        mDispatcher.clear();
-    }
-};
-
-
-TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) {
-    KeyEvent event;
-
-    // Rejects undefined key actions.
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
-            /*action*/ -1, 0,
-            AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject key events with undefined action.";
-
-    // Rejects ACTION_MULTIPLE since it is not supported despite being defined in the API.
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD,
-            AKEY_EVENT_ACTION_MULTIPLE, 0,
-            AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject key events with ACTION_MULTIPLE.";
-}
-
-TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) {
-    MotionEvent event;
-    PointerProperties pointerProperties[MAX_POINTERS + 1];
-    PointerCoords pointerCoords[MAX_POINTERS + 1];
-    for (int i = 0; i <= MAX_POINTERS; i++) {
-        pointerProperties[i].clear();
-        pointerProperties[i].id = i;
-        pointerCoords[i].clear();
-    }
-
-    // Rejects undefined motion actions.
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            /*action*/ -1, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with undefined action.";
-
-    // Rejects pointer down with invalid index.
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with pointer down index too large.";
-
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_POINTER_DOWN | (-1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with pointer down index too small.";
-
-    // Rejects pointer up with invalid index.
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with pointer up index too large.";
-
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_POINTER_UP | (-1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with pointer up index too small.";
-
-    // Rejects motion events with invalid number of pointers.
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 0, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with 0 pointers.";
-
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ MAX_POINTERS + 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with more than MAX_POINTERS pointers.";
-
-    // Rejects motion events with invalid pointer ids.
-    pointerProperties[0].id = -1;
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with pointer ids less than 0.";
-
-    pointerProperties[0].id = MAX_POINTER_ID + 1;
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 1, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with pointer ids greater than MAX_POINTER_ID.";
-
-    // Rejects motion events with duplicate pointer ids.
-    pointerProperties[0].id = 1;
-    pointerProperties[1].id = 1;
-    event.initialize(DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN,
-            AMOTION_EVENT_ACTION_DOWN, 0, 0, AMETA_NONE, 0, 0, 0, 0, 0,
-            ARBITRARY_TIME, ARBITRARY_TIME,
-            /*pointerCount*/ 2, pointerProperties, pointerCoords);
-    ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent(&event,
-            INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0))
-            << "Should reject motion events with duplicate pointer ids.";
-}
-
-} // namespace android
diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp
deleted file mode 100644
index f068732..0000000
--- a/services/input/tests/InputReader_test.cpp
+++ /dev/null
@@ -1,5099 +0,0 @@
-/*
- * Copyright (C) 2010 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 "../InputReader.h"
-
-#include <utils/List.h>
-#include <gtest/gtest.h>
-#include <math.h>
-
-namespace android {
-
-// An arbitrary time value.
-static const nsecs_t ARBITRARY_TIME = 1234;
-
-// Arbitrary display properties.
-static const int32_t DISPLAY_ID = 0;
-static const int32_t DISPLAY_WIDTH = 480;
-static const int32_t DISPLAY_HEIGHT = 800;
-
-// Error tolerance for floating point assertions.
-static const float EPSILON = 0.001f;
-
-template<typename T>
-static inline T min(T a, T b) {
-    return a < b ? a : b;
-}
-
-static inline float avg(float x, float y) {
-    return (x + y) / 2;
-}
-
-
-// --- FakePointerController ---
-
-class FakePointerController : public PointerControllerInterface {
-    bool mHaveBounds;
-    float mMinX, mMinY, mMaxX, mMaxY;
-    float mX, mY;
-    int32_t mButtonState;
-
-protected:
-    virtual ~FakePointerController() { }
-
-public:
-    FakePointerController() :
-        mHaveBounds(false), mMinX(0), mMinY(0), mMaxX(0), mMaxY(0), mX(0), mY(0),
-        mButtonState(0) {
-    }
-
-    void setBounds(float minX, float minY, float maxX, float maxY) {
-        mHaveBounds = true;
-        mMinX = minX;
-        mMinY = minY;
-        mMaxX = maxX;
-        mMaxY = maxY;
-    }
-
-    virtual void setPosition(float x, float y) {
-        mX = x;
-        mY = y;
-    }
-
-    virtual void setButtonState(int32_t buttonState) {
-        mButtonState = buttonState;
-    }
-
-    virtual int32_t getButtonState() const {
-        return mButtonState;
-    }
-
-    virtual void getPosition(float* outX, float* outY) const {
-        *outX = mX;
-        *outY = mY;
-    }
-
-private:
-    virtual bool getBounds(float* outMinX, float* outMinY, float* outMaxX, float* outMaxY) const {
-        *outMinX = mMinX;
-        *outMinY = mMinY;
-        *outMaxX = mMaxX;
-        *outMaxY = mMaxY;
-        return mHaveBounds;
-    }
-
-    virtual void move(float deltaX, float deltaY) {
-        mX += deltaX;
-        if (mX < mMinX) mX = mMinX;
-        if (mX > mMaxX) mX = mMaxX;
-        mY += deltaY;
-        if (mY < mMinY) mY = mMinY;
-        if (mY > mMaxY) mY = mMaxY;
-    }
-
-    virtual void fade(Transition transition) {
-    }
-
-    virtual void unfade(Transition transition) {
-    }
-
-    virtual void setPresentation(Presentation presentation) {
-    }
-
-    virtual void setSpots(const PointerCoords* spotCoords,
-            const uint32_t* spotIdToIndex, BitSet32 spotIdBits) {
-    }
-
-    virtual void clearSpots() {
-    }
-};
-
-
-// --- FakeInputReaderPolicy ---
-
-class FakeInputReaderPolicy : public InputReaderPolicyInterface {
-    InputReaderConfiguration mConfig;
-    KeyedVector<int32_t, sp<FakePointerController> > mPointerControllers;
-    Vector<InputDeviceInfo> mInputDevices;
-
-protected:
-    virtual ~FakeInputReaderPolicy() { }
-
-public:
-    FakeInputReaderPolicy() {
-    }
-
-    void setDisplayInfo(int32_t displayId, int32_t width, int32_t height, int32_t orientation) {
-        // Set the size of both the internal and external display at the same time.
-        bool isRotated = (orientation == DISPLAY_ORIENTATION_90
-                || orientation == DISPLAY_ORIENTATION_270);
-        DisplayViewport v;
-        v.displayId = displayId;
-        v.orientation = orientation;
-        v.logicalLeft = 0;
-        v.logicalTop = 0;
-        v.logicalRight = isRotated ? height : width;
-        v.logicalBottom = isRotated ? width : height;
-        v.physicalLeft = 0;
-        v.physicalTop = 0;
-        v.physicalRight = isRotated ? height : width;
-        v.physicalBottom = isRotated ? width : height;
-        v.deviceWidth = isRotated ? height : width;
-        v.deviceHeight = isRotated ? width : height;
-        mConfig.setDisplayInfo(false /*external*/, v);
-        mConfig.setDisplayInfo(true /*external*/, v);
-    }
-
-    void addExcludedDeviceName(const String8& deviceName) {
-        mConfig.excludedDeviceNames.push(deviceName);
-    }
-
-    void setPointerController(int32_t deviceId, const sp<FakePointerController>& controller) {
-        mPointerControllers.add(deviceId, controller);
-    }
-
-    const InputReaderConfiguration* getReaderConfiguration() const {
-        return &mConfig;
-    }
-
-    const Vector<InputDeviceInfo>& getInputDevices() const {
-        return mInputDevices;
-    }
-
-private:
-    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) {
-        *outConfig = mConfig;
-    }
-
-    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) {
-        return mPointerControllers.valueFor(deviceId);
-    }
-
-    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
-        mInputDevices = inputDevices;
-    }
-
-    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor) {
-        return NULL;
-    }
-
-    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier) {
-        return String8::empty();
-    }
-};
-
-
-// --- FakeInputListener ---
-
-class FakeInputListener : public InputListenerInterface {
-private:
-    List<NotifyConfigurationChangedArgs> mNotifyConfigurationChangedArgsQueue;
-    List<NotifyDeviceResetArgs> mNotifyDeviceResetArgsQueue;
-    List<NotifyKeyArgs> mNotifyKeyArgsQueue;
-    List<NotifyMotionArgs> mNotifyMotionArgsQueue;
-    List<NotifySwitchArgs> mNotifySwitchArgsQueue;
-
-protected:
-    virtual ~FakeInputListener() { }
-
-public:
-    FakeInputListener() {
-    }
-
-    void assertNotifyConfigurationChangedWasCalled(
-            NotifyConfigurationChangedArgs* outEventArgs = NULL) {
-        ASSERT_FALSE(mNotifyConfigurationChangedArgsQueue.empty())
-                << "Expected notifyConfigurationChanged() to have been called.";
-        if (outEventArgs) {
-            *outEventArgs = *mNotifyConfigurationChangedArgsQueue.begin();
-        }
-        mNotifyConfigurationChangedArgsQueue.erase(mNotifyConfigurationChangedArgsQueue.begin());
-    }
-
-    void assertNotifyDeviceResetWasCalled(
-            NotifyDeviceResetArgs* outEventArgs = NULL) {
-        ASSERT_FALSE(mNotifyDeviceResetArgsQueue.empty())
-                << "Expected notifyDeviceReset() to have been called.";
-        if (outEventArgs) {
-            *outEventArgs = *mNotifyDeviceResetArgsQueue.begin();
-        }
-        mNotifyDeviceResetArgsQueue.erase(mNotifyDeviceResetArgsQueue.begin());
-    }
-
-    void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = NULL) {
-        ASSERT_FALSE(mNotifyKeyArgsQueue.empty())
-                << "Expected notifyKey() to have been called.";
-        if (outEventArgs) {
-            *outEventArgs = *mNotifyKeyArgsQueue.begin();
-        }
-        mNotifyKeyArgsQueue.erase(mNotifyKeyArgsQueue.begin());
-    }
-
-    void assertNotifyKeyWasNotCalled() {
-        ASSERT_TRUE(mNotifyKeyArgsQueue.empty())
-                << "Expected notifyKey() to not have been called.";
-    }
-
-    void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = NULL) {
-        ASSERT_FALSE(mNotifyMotionArgsQueue.empty())
-                << "Expected notifyMotion() to have been called.";
-        if (outEventArgs) {
-            *outEventArgs = *mNotifyMotionArgsQueue.begin();
-        }
-        mNotifyMotionArgsQueue.erase(mNotifyMotionArgsQueue.begin());
-    }
-
-    void assertNotifyMotionWasNotCalled() {
-        ASSERT_TRUE(mNotifyMotionArgsQueue.empty())
-                << "Expected notifyMotion() to not have been called.";
-    }
-
-    void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = NULL) {
-        ASSERT_FALSE(mNotifySwitchArgsQueue.empty())
-                << "Expected notifySwitch() to have been called.";
-        if (outEventArgs) {
-            *outEventArgs = *mNotifySwitchArgsQueue.begin();
-        }
-        mNotifySwitchArgsQueue.erase(mNotifySwitchArgsQueue.begin());
-    }
-
-private:
-    virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
-        mNotifyConfigurationChangedArgsQueue.push_back(*args);
-    }
-
-    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) {
-        mNotifyDeviceResetArgsQueue.push_back(*args);
-    }
-
-    virtual void notifyKey(const NotifyKeyArgs* args) {
-        mNotifyKeyArgsQueue.push_back(*args);
-    }
-
-    virtual void notifyMotion(const NotifyMotionArgs* args) {
-        mNotifyMotionArgsQueue.push_back(*args);
-    }
-
-    virtual void notifySwitch(const NotifySwitchArgs* args) {
-        mNotifySwitchArgsQueue.push_back(*args);
-    }
-};
-
-
-// --- FakeEventHub ---
-
-class FakeEventHub : public EventHubInterface {
-    struct KeyInfo {
-        int32_t keyCode;
-        uint32_t flags;
-    };
-
-    struct Device {
-        InputDeviceIdentifier identifier;
-        uint32_t classes;
-        PropertyMap configuration;
-        KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes;
-        KeyedVector<int, bool> relativeAxes;
-        KeyedVector<int32_t, int32_t> keyCodeStates;
-        KeyedVector<int32_t, int32_t> scanCodeStates;
-        KeyedVector<int32_t, int32_t> switchStates;
-        KeyedVector<int32_t, int32_t> absoluteAxisValue;
-        KeyedVector<int32_t, KeyInfo> keysByScanCode;
-        KeyedVector<int32_t, KeyInfo> keysByUsageCode;
-        KeyedVector<int32_t, bool> leds;
-        Vector<VirtualKeyDefinition> virtualKeys;
-
-        Device(uint32_t classes) :
-                classes(classes) {
-        }
-    };
-
-    KeyedVector<int32_t, Device*> mDevices;
-    Vector<String8> mExcludedDevices;
-    List<RawEvent> mEvents;
-
-protected:
-    virtual ~FakeEventHub() {
-        for (size_t i = 0; i < mDevices.size(); i++) {
-            delete mDevices.valueAt(i);
-        }
-    }
-
-public:
-    FakeEventHub() { }
-
-    void addDevice(int32_t deviceId, const String8& name, uint32_t classes) {
-        Device* device = new Device(classes);
-        device->identifier.name = name;
-        mDevices.add(deviceId, device);
-
-        enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0);
-    }
-
-    void removeDevice(int32_t deviceId) {
-        delete mDevices.valueFor(deviceId);
-        mDevices.removeItem(deviceId);
-
-        enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0);
-    }
-
-    void finishDeviceScan() {
-        enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0);
-    }
-
-    void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) {
-        Device* device = getDevice(deviceId);
-        device->configuration.addProperty(key, value);
-    }
-
-    void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) {
-        Device* device = getDevice(deviceId);
-        device->configuration.addAll(configuration);
-    }
-
-    void addAbsoluteAxis(int32_t deviceId, int axis,
-            int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) {
-        Device* device = getDevice(deviceId);
-
-        RawAbsoluteAxisInfo info;
-        info.valid = true;
-        info.minValue = minValue;
-        info.maxValue = maxValue;
-        info.flat = flat;
-        info.fuzz = fuzz;
-        info.resolution = resolution;
-        device->absoluteAxes.add(axis, info);
-    }
-
-    void addRelativeAxis(int32_t deviceId, int32_t axis) {
-        Device* device = getDevice(deviceId);
-        device->relativeAxes.add(axis, true);
-    }
-
-    void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) {
-        Device* device = getDevice(deviceId);
-        device->keyCodeStates.replaceValueFor(keyCode, state);
-    }
-
-    void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) {
-        Device* device = getDevice(deviceId);
-        device->scanCodeStates.replaceValueFor(scanCode, state);
-    }
-
-    void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) {
-        Device* device = getDevice(deviceId);
-        device->switchStates.replaceValueFor(switchCode, state);
-    }
-
-    void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) {
-        Device* device = getDevice(deviceId);
-        device->absoluteAxisValue.replaceValueFor(axis, value);
-    }
-
-    void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
-            int32_t keyCode, uint32_t flags) {
-        Device* device = getDevice(deviceId);
-        KeyInfo info;
-        info.keyCode = keyCode;
-        info.flags = flags;
-        if (scanCode) {
-            device->keysByScanCode.add(scanCode, info);
-        }
-        if (usageCode) {
-            device->keysByUsageCode.add(usageCode, info);
-        }
-    }
-
-    void addLed(int32_t deviceId, int32_t led, bool initialState) {
-        Device* device = getDevice(deviceId);
-        device->leds.add(led, initialState);
-    }
-
-    bool getLedState(int32_t deviceId, int32_t led) {
-        Device* device = getDevice(deviceId);
-        return device->leds.valueFor(led);
-    }
-
-    Vector<String8>& getExcludedDevices() {
-        return mExcludedDevices;
-    }
-
-    void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) {
-        Device* device = getDevice(deviceId);
-        device->virtualKeys.push(definition);
-    }
-
-    void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type,
-            int32_t code, int32_t value) {
-        RawEvent event;
-        event.when = when;
-        event.deviceId = deviceId;
-        event.type = type;
-        event.code = code;
-        event.value = value;
-        mEvents.push_back(event);
-
-        if (type == EV_ABS) {
-            setAbsoluteAxisValue(deviceId, code, value);
-        }
-    }
-
-    void assertQueueIsEmpty() {
-        ASSERT_EQ(size_t(0), mEvents.size())
-                << "Expected the event queue to be empty (fully consumed).";
-    }
-
-private:
-    Device* getDevice(int32_t deviceId) const {
-        ssize_t index = mDevices.indexOfKey(deviceId);
-        return index >= 0 ? mDevices.valueAt(index) : NULL;
-    }
-
-    virtual uint32_t getDeviceClasses(int32_t deviceId) const {
-        Device* device = getDevice(deviceId);
-        return device ? device->classes : 0;
-    }
-
-    virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const {
-        Device* device = getDevice(deviceId);
-        return device ? device->identifier : InputDeviceIdentifier();
-    }
-
-    virtual int32_t getDeviceControllerNumber(int32_t deviceId) const {
-        return 0;
-    }
-
-    virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            *outConfiguration = device->configuration;
-        }
-    }
-
-    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
-            RawAbsoluteAxisInfo* outAxisInfo) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->absoluteAxes.indexOfKey(axis);
-            if (index >= 0) {
-                *outAxisInfo = device->absoluteAxes.valueAt(index);
-                return OK;
-            }
-        }
-        outAxisInfo->clear();
-        return -1;
-    }
-
-    virtual bool hasRelativeAxis(int32_t deviceId, int axis) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            return device->relativeAxes.indexOfKey(axis) >= 0;
-        }
-        return false;
-    }
-
-    virtual bool hasInputProperty(int32_t deviceId, int property) const {
-        return false;
-    }
-
-    virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
-            int32_t* outKeycode, uint32_t* outFlags) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            const KeyInfo* key = getKey(device, scanCode, usageCode);
-            if (key) {
-                if (outKeycode) {
-                    *outKeycode = key->keyCode;
-                }
-                if (outFlags) {
-                    *outFlags = key->flags;
-                }
-                return OK;
-            }
-        }
-        return NAME_NOT_FOUND;
-    }
-
-    const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const {
-        if (usageCode) {
-            ssize_t index = device->keysByUsageCode.indexOfKey(usageCode);
-            if (index >= 0) {
-                return &device->keysByUsageCode.valueAt(index);
-            }
-        }
-        if (scanCode) {
-            ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
-            if (index >= 0) {
-                return &device->keysByScanCode.valueAt(index);
-            }
-        }
-        return NULL;
-    }
-
-    virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
-            AxisInfo* outAxisInfo) const {
-        return NAME_NOT_FOUND;
-    }
-
-    virtual void setExcludedDevices(const Vector<String8>& devices) {
-        mExcludedDevices = devices;
-    }
-
-    virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) {
-        if (mEvents.empty()) {
-            return 0;
-        }
-
-        *buffer = *mEvents.begin();
-        mEvents.erase(mEvents.begin());
-        return 1;
-    }
-
-    virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->scanCodeStates.indexOfKey(scanCode);
-            if (index >= 0) {
-                return device->scanCodeStates.valueAt(index);
-            }
-        }
-        return AKEY_STATE_UNKNOWN;
-    }
-
-    virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->keyCodeStates.indexOfKey(keyCode);
-            if (index >= 0) {
-                return device->keyCodeStates.valueAt(index);
-            }
-        }
-        return AKEY_STATE_UNKNOWN;
-    }
-
-    virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->switchStates.indexOfKey(sw);
-            if (index >= 0) {
-                return device->switchStates.valueAt(index);
-            }
-        }
-        return AKEY_STATE_UNKNOWN;
-    }
-
-    virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
-            int32_t* outValue) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->absoluteAxisValue.indexOfKey(axis);
-            if (index >= 0) {
-                *outValue = device->absoluteAxisValue.valueAt(index);
-                return OK;
-            }
-        }
-        *outValue = 0;
-        return -1;
-    }
-
-    virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
-            uint8_t* outFlags) const {
-        bool result = false;
-        Device* device = getDevice(deviceId);
-        if (device) {
-            for (size_t i = 0; i < numCodes; i++) {
-                for (size_t j = 0; j < device->keysByScanCode.size(); j++) {
-                    if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) {
-                        outFlags[i] = 1;
-                        result = true;
-                    }
-                }
-                for (size_t j = 0; j < device->keysByUsageCode.size(); j++) {
-                    if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) {
-                        outFlags[i] = 1;
-                        result = true;
-                    }
-                }
-            }
-        }
-        return result;
-    }
-
-    virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->keysByScanCode.indexOfKey(scanCode);
-            return index >= 0;
-        }
-        return false;
-    }
-
-    virtual bool hasLed(int32_t deviceId, int32_t led) const {
-        Device* device = getDevice(deviceId);
-        return device && device->leds.indexOfKey(led) >= 0;
-    }
-
-    virtual void setLedState(int32_t deviceId, int32_t led, bool on) {
-        Device* device = getDevice(deviceId);
-        if (device) {
-            ssize_t index = device->leds.indexOfKey(led);
-            if (index >= 0) {
-                device->leds.replaceValueAt(led, on);
-            } else {
-                ADD_FAILURE()
-                        << "Attempted to set the state of an LED that the EventHub declared "
-                        "was not present.  led=" << led;
-            }
-        }
-    }
-
-    virtual void getVirtualKeyDefinitions(int32_t deviceId,
-            Vector<VirtualKeyDefinition>& outVirtualKeys) const {
-        outVirtualKeys.clear();
-
-        Device* device = getDevice(deviceId);
-        if (device) {
-            outVirtualKeys.appendVector(device->virtualKeys);
-        }
-    }
-
-    virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const {
-        return NULL;
-    }
-
-    virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) {
-        return false;
-    }
-
-    virtual void vibrate(int32_t deviceId, nsecs_t duration) {
-    }
-
-    virtual void cancelVibrate(int32_t deviceId) {
-    }
-
-    virtual bool isExternal(int32_t deviceId) const {
-        return false;
-    }
-
-    virtual void dump(String8& dump) {
-    }
-
-    virtual void monitor() {
-    }
-
-    virtual void requestReopenDevices() {
-    }
-
-    virtual void wake() {
-    }
-};
-
-
-// --- FakeInputReaderContext ---
-
-class FakeInputReaderContext : public InputReaderContext {
-    sp<EventHubInterface> mEventHub;
-    sp<InputReaderPolicyInterface> mPolicy;
-    sp<InputListenerInterface> mListener;
-    int32_t mGlobalMetaState;
-    bool mUpdateGlobalMetaStateWasCalled;
-    int32_t mGeneration;
-
-public:
-    FakeInputReaderContext(const sp<EventHubInterface>& eventHub,
-            const sp<InputReaderPolicyInterface>& policy,
-            const sp<InputListenerInterface>& listener) :
-            mEventHub(eventHub), mPolicy(policy), mListener(listener),
-            mGlobalMetaState(0) {
-    }
-
-    virtual ~FakeInputReaderContext() { }
-
-    void assertUpdateGlobalMetaStateWasCalled() {
-        ASSERT_TRUE(mUpdateGlobalMetaStateWasCalled)
-                << "Expected updateGlobalMetaState() to have been called.";
-        mUpdateGlobalMetaStateWasCalled = false;
-    }
-
-    void setGlobalMetaState(int32_t state) {
-        mGlobalMetaState = state;
-    }
-
-private:
-    virtual void updateGlobalMetaState() {
-        mUpdateGlobalMetaStateWasCalled = true;
-    }
-
-    virtual int32_t getGlobalMetaState() {
-        return mGlobalMetaState;
-    }
-
-    virtual EventHubInterface* getEventHub() {
-        return mEventHub.get();
-    }
-
-    virtual InputReaderPolicyInterface* getPolicy() {
-        return mPolicy.get();
-    }
-
-    virtual InputListenerInterface* getListener() {
-        return mListener.get();
-    }
-
-    virtual void disableVirtualKeysUntil(nsecs_t time) {
-    }
-
-    virtual bool shouldDropVirtualKey(nsecs_t now,
-            InputDevice* device, int32_t keyCode, int32_t scanCode) {
-        return false;
-    }
-
-    virtual void fadePointer() {
-    }
-
-    virtual void requestTimeoutAtTime(nsecs_t when) {
-    }
-
-    virtual int32_t bumpGeneration() {
-        return ++mGeneration;
-    }
-};
-
-
-// --- FakeInputMapper ---
-
-class FakeInputMapper : public InputMapper {
-    uint32_t mSources;
-    int32_t mKeyboardType;
-    int32_t mMetaState;
-    KeyedVector<int32_t, int32_t> mKeyCodeStates;
-    KeyedVector<int32_t, int32_t> mScanCodeStates;
-    KeyedVector<int32_t, int32_t> mSwitchStates;
-    Vector<int32_t> mSupportedKeyCodes;
-    RawEvent mLastEvent;
-
-    bool mConfigureWasCalled;
-    bool mResetWasCalled;
-    bool mProcessWasCalled;
-
-public:
-    FakeInputMapper(InputDevice* device, uint32_t sources) :
-            InputMapper(device),
-            mSources(sources), mKeyboardType(AINPUT_KEYBOARD_TYPE_NONE),
-            mMetaState(0),
-            mConfigureWasCalled(false), mResetWasCalled(false), mProcessWasCalled(false) {
-    }
-
-    virtual ~FakeInputMapper() { }
-
-    void setKeyboardType(int32_t keyboardType) {
-        mKeyboardType = keyboardType;
-    }
-
-    void setMetaState(int32_t metaState) {
-        mMetaState = metaState;
-    }
-
-    void assertConfigureWasCalled() {
-        ASSERT_TRUE(mConfigureWasCalled)
-                << "Expected configure() to have been called.";
-        mConfigureWasCalled = false;
-    }
-
-    void assertResetWasCalled() {
-        ASSERT_TRUE(mResetWasCalled)
-                << "Expected reset() to have been called.";
-        mResetWasCalled = false;
-    }
-
-    void assertProcessWasCalled(RawEvent* outLastEvent = NULL) {
-        ASSERT_TRUE(mProcessWasCalled)
-                << "Expected process() to have been called.";
-        if (outLastEvent) {
-            *outLastEvent = mLastEvent;
-        }
-        mProcessWasCalled = false;
-    }
-
-    void setKeyCodeState(int32_t keyCode, int32_t state) {
-        mKeyCodeStates.replaceValueFor(keyCode, state);
-    }
-
-    void setScanCodeState(int32_t scanCode, int32_t state) {
-        mScanCodeStates.replaceValueFor(scanCode, state);
-    }
-
-    void setSwitchState(int32_t switchCode, int32_t state) {
-        mSwitchStates.replaceValueFor(switchCode, state);
-    }
-
-    void addSupportedKeyCode(int32_t keyCode) {
-        mSupportedKeyCodes.add(keyCode);
-    }
-
-private:
-    virtual uint32_t getSources() {
-        return mSources;
-    }
-
-    virtual void populateDeviceInfo(InputDeviceInfo* deviceInfo) {
-        InputMapper::populateDeviceInfo(deviceInfo);
-
-        if (mKeyboardType != AINPUT_KEYBOARD_TYPE_NONE) {
-            deviceInfo->setKeyboardType(mKeyboardType);
-        }
-    }
-
-    virtual void configure(nsecs_t when,
-            const InputReaderConfiguration* config, uint32_t changes) {
-        mConfigureWasCalled = true;
-    }
-
-    virtual void reset(nsecs_t when) {
-        mResetWasCalled = true;
-    }
-
-    virtual void process(const RawEvent* rawEvent) {
-        mLastEvent = *rawEvent;
-        mProcessWasCalled = true;
-    }
-
-    virtual int32_t getKeyCodeState(uint32_t sourceMask, int32_t keyCode) {
-        ssize_t index = mKeyCodeStates.indexOfKey(keyCode);
-        return index >= 0 ? mKeyCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
-    }
-
-    virtual int32_t getScanCodeState(uint32_t sourceMask, int32_t scanCode) {
-        ssize_t index = mScanCodeStates.indexOfKey(scanCode);
-        return index >= 0 ? mScanCodeStates.valueAt(index) : AKEY_STATE_UNKNOWN;
-    }
-
-    virtual int32_t getSwitchState(uint32_t sourceMask, int32_t switchCode) {
-        ssize_t index = mSwitchStates.indexOfKey(switchCode);
-        return index >= 0 ? mSwitchStates.valueAt(index) : AKEY_STATE_UNKNOWN;
-    }
-
-    virtual bool markSupportedKeyCodes(uint32_t sourceMask, size_t numCodes,
-            const int32_t* keyCodes, uint8_t* outFlags) {
-        bool result = false;
-        for (size_t i = 0; i < numCodes; i++) {
-            for (size_t j = 0; j < mSupportedKeyCodes.size(); j++) {
-                if (keyCodes[i] == mSupportedKeyCodes[j]) {
-                    outFlags[i] = 1;
-                    result = true;
-                }
-            }
-        }
-        return result;
-    }
-
-    virtual int32_t getMetaState() {
-        return mMetaState;
-    }
-
-    virtual void fadePointer() {
-    }
-};
-
-
-// --- InstrumentedInputReader ---
-
-class InstrumentedInputReader : public InputReader {
-    InputDevice* mNextDevice;
-
-public:
-    InstrumentedInputReader(const sp<EventHubInterface>& eventHub,
-            const sp<InputReaderPolicyInterface>& policy,
-            const sp<InputListenerInterface>& listener) :
-            InputReader(eventHub, policy, listener),
-            mNextDevice(NULL) {
-    }
-
-    virtual ~InstrumentedInputReader() {
-        if (mNextDevice) {
-            delete mNextDevice;
-        }
-    }
-
-    void setNextDevice(InputDevice* device) {
-        mNextDevice = device;
-    }
-
-    InputDevice* newDevice(int32_t deviceId, int32_t controllerNumber, const String8& name,
-            uint32_t classes) {
-        InputDeviceIdentifier identifier;
-        identifier.name = name;
-        int32_t generation = deviceId + 1;
-        return new InputDevice(&mContext, deviceId, generation, controllerNumber, identifier,
-                classes);
-    }
-
-protected:
-    virtual InputDevice* createDeviceLocked(int32_t deviceId, int32_t controllerNumber,
-            const InputDeviceIdentifier& identifier, uint32_t classes) {
-        if (mNextDevice) {
-            InputDevice* device = mNextDevice;
-            mNextDevice = NULL;
-            return device;
-        }
-        return InputReader::createDeviceLocked(deviceId, controllerNumber, identifier, classes);
-    }
-
-    friend class InputReaderTest;
-};
-
-
-// --- InputReaderTest ---
-
-class InputReaderTest : public testing::Test {
-protected:
-    sp<FakeInputListener> mFakeListener;
-    sp<FakeInputReaderPolicy> mFakePolicy;
-    sp<FakeEventHub> mFakeEventHub;
-    sp<InstrumentedInputReader> mReader;
-
-    virtual void SetUp() {
-        mFakeEventHub = new FakeEventHub();
-        mFakePolicy = new FakeInputReaderPolicy();
-        mFakeListener = new FakeInputListener();
-
-        mReader = new InstrumentedInputReader(mFakeEventHub, mFakePolicy, mFakeListener);
-    }
-
-    virtual void TearDown() {
-        mReader.clear();
-
-        mFakeListener.clear();
-        mFakePolicy.clear();
-        mFakeEventHub.clear();
-    }
-
-    void addDevice(int32_t deviceId, const String8& name, uint32_t classes,
-            const PropertyMap* configuration) {
-        mFakeEventHub->addDevice(deviceId, name, classes);
-
-        if (configuration) {
-            mFakeEventHub->addConfigurationMap(deviceId, configuration);
-        }
-        mFakeEventHub->finishDeviceScan();
-        mReader->loopOnce();
-        mReader->loopOnce();
-        mFakeEventHub->assertQueueIsEmpty();
-    }
-
-    FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, int32_t controllerNumber,
-            const String8& name, uint32_t classes, uint32_t sources,
-            const PropertyMap* configuration) {
-        InputDevice* device = mReader->newDevice(deviceId, controllerNumber, name, classes);
-        FakeInputMapper* mapper = new FakeInputMapper(device, sources);
-        device->addMapper(mapper);
-        mReader->setNextDevice(device);
-        addDevice(deviceId, name, classes, configuration);
-        return mapper;
-    }
-};
-
-TEST_F(InputReaderTest, GetInputDevices) {
-    ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"),
-            INPUT_DEVICE_CLASS_KEYBOARD, NULL));
-    ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("ignored"),
-            0, NULL)); // no classes so device will be ignored
-
-    Vector<InputDeviceInfo> inputDevices;
-    mReader->getInputDevices(inputDevices);
-
-    ASSERT_EQ(1U, inputDevices.size());
-    ASSERT_EQ(1, inputDevices[0].getId());
-    ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string());
-    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType());
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources());
-    ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size());
-
-    // Should also have received a notification describing the new input devices.
-    inputDevices = mFakePolicy->getInputDevices();
-    ASSERT_EQ(1U, inputDevices.size());
-    ASSERT_EQ(1, inputDevices[0].getId());
-    ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.string());
-    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType());
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources());
-    ASSERT_EQ(size_t(0), inputDevices[0].getMotionRanges().size());
-}
-
-TEST_F(InputReaderTest, GetKeyCodeState_ForwardsRequestsToMappers) {
-    FakeInputMapper* mapper = NULL;
-    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
-            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
-    mapper->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN);
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(0,
-            AINPUT_SOURCE_ANY, AKEYCODE_A))
-            << "Should return unknown when the device id is >= 0 but unknown.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(1,
-            AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return unknown when the device id is valid but the sources are not supported by the device.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(1,
-            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getKeyCodeState(-1,
-            AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return unknown when the device id is < 0 but the sources are not supported by any device.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getKeyCodeState(-1,
-            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
-}
-
-TEST_F(InputReaderTest, GetScanCodeState_ForwardsRequestsToMappers) {
-    FakeInputMapper* mapper = NULL;
-    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
-            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
-    mapper->setScanCodeState(KEY_A, AKEY_STATE_DOWN);
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(0,
-            AINPUT_SOURCE_ANY, KEY_A))
-            << "Should return unknown when the device id is >= 0 but unknown.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(1,
-            AINPUT_SOURCE_TRACKBALL, KEY_A))
-            << "Should return unknown when the device id is valid but the sources are not supported by the device.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(1,
-            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A))
-            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getScanCodeState(-1,
-            AINPUT_SOURCE_TRACKBALL, KEY_A))
-            << "Should return unknown when the device id is < 0 but the sources are not supported by any device.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getScanCodeState(-1,
-            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, KEY_A))
-            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
-}
-
-TEST_F(InputReaderTest, GetSwitchState_ForwardsRequestsToMappers) {
-    FakeInputMapper* mapper = NULL;
-    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
-            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
-    mapper->setSwitchState(SW_LID, AKEY_STATE_DOWN);
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(0,
-            AINPUT_SOURCE_ANY, SW_LID))
-            << "Should return unknown when the device id is >= 0 but unknown.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(1,
-            AINPUT_SOURCE_TRACKBALL, SW_LID))
-            << "Should return unknown when the device id is valid but the sources are not supported by the device.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(1,
-            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID))
-            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mReader->getSwitchState(-1,
-            AINPUT_SOURCE_TRACKBALL, SW_LID))
-            << "Should return unknown when the device id is < 0 but the sources are not supported by any device.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mReader->getSwitchState(-1,
-            AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, SW_LID))
-            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
-}
-
-TEST_F(InputReaderTest, MarkSupportedKeyCodes_ForwardsRequestsToMappers) {
-    FakeInputMapper* mapper = NULL;
-    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
-            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
-    mapper->addSupportedKeyCode(AKEYCODE_A);
-    mapper->addSupportedKeyCode(AKEYCODE_B);
-
-    const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 };
-    uint8_t flags[4] = { 0, 0, 0, 1 };
-
-    ASSERT_FALSE(mReader->hasKeys(0, AINPUT_SOURCE_ANY, 4, keyCodes, flags))
-            << "Should return false when device id is >= 0 but unknown.";
-    ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]);
-
-    flags[3] = 1;
-    ASSERT_FALSE(mReader->hasKeys(1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
-            << "Should return false when device id is valid but the sources are not supported by the device.";
-    ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]);
-
-    flags[3] = 1;
-    ASSERT_TRUE(mReader->hasKeys(1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
-            << "Should return value provided by mapper when device id is valid and the device supports some of the sources.";
-    ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]);
-
-    flags[3] = 1;
-    ASSERT_FALSE(mReader->hasKeys(-1, AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
-            << "Should return false when the device id is < 0 but the sources are not supported by any device.";
-    ASSERT_TRUE(!flags[0] && !flags[1] && !flags[2] && !flags[3]);
-
-    flags[3] = 1;
-    ASSERT_TRUE(mReader->hasKeys(-1, AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
-            << "Should return value provided by mapper when device id is < 0 and one of the devices supports some of the sources.";
-    ASSERT_TRUE(flags[0] && flags[1] && !flags[2] && !flags[3]);
-}
-
-TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) {
-    addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, NULL);
-
-    NotifyConfigurationChangedArgs args;
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyConfigurationChangedWasCalled(&args));
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-}
-
-TEST_F(InputReaderTest, LoopOnce_ForwardsRawEventsToMappers) {
-    FakeInputMapper* mapper = NULL;
-    ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, 0, String8("fake"),
-            INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL));
-
-    mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, 1);
-    mReader->loopOnce();
-    ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty());
-
-    RawEvent event;
-    ASSERT_NO_FATAL_FAILURE(mapper->assertProcessWasCalled(&event));
-    ASSERT_EQ(0, event.when);
-    ASSERT_EQ(1, event.deviceId);
-    ASSERT_EQ(EV_KEY, event.type);
-    ASSERT_EQ(KEY_A, event.code);
-    ASSERT_EQ(1, event.value);
-}
-
-
-// --- InputDeviceTest ---
-
-class InputDeviceTest : public testing::Test {
-protected:
-    static const char* DEVICE_NAME;
-    static const int32_t DEVICE_ID;
-    static const int32_t DEVICE_GENERATION;
-    static const int32_t DEVICE_CONTROLLER_NUMBER;
-    static const uint32_t DEVICE_CLASSES;
-
-    sp<FakeEventHub> mFakeEventHub;
-    sp<FakeInputReaderPolicy> mFakePolicy;
-    sp<FakeInputListener> mFakeListener;
-    FakeInputReaderContext* mFakeContext;
-
-    InputDevice* mDevice;
-
-    virtual void SetUp() {
-        mFakeEventHub = new FakeEventHub();
-        mFakePolicy = new FakeInputReaderPolicy();
-        mFakeListener = new FakeInputListener();
-        mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener);
-
-        mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0);
-        InputDeviceIdentifier identifier;
-        identifier.name = DEVICE_NAME;
-        mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION,
-                DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
-    }
-
-    virtual void TearDown() {
-        delete mDevice;
-
-        delete mFakeContext;
-        mFakeListener.clear();
-        mFakePolicy.clear();
-        mFakeEventHub.clear();
-    }
-};
-
-const char* InputDeviceTest::DEVICE_NAME = "device";
-const int32_t InputDeviceTest::DEVICE_ID = 1;
-const int32_t InputDeviceTest::DEVICE_GENERATION = 2;
-const int32_t InputDeviceTest::DEVICE_CONTROLLER_NUMBER = 0;
-const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD
-        | INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_JOYSTICK;
-
-TEST_F(InputDeviceTest, ImmutableProperties) {
-    ASSERT_EQ(DEVICE_ID, mDevice->getId());
-    ASSERT_STREQ(DEVICE_NAME, mDevice->getName());
-    ASSERT_EQ(DEVICE_CLASSES, mDevice->getClasses());
-}
-
-TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) {
-    // Configuration.
-    InputReaderConfiguration config;
-    mDevice->configure(ARBITRARY_TIME, &config, 0);
-
-    // Reset.
-    mDevice->reset(ARBITRARY_TIME);
-
-    NotifyDeviceResetArgs resetArgs;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
-    ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
-
-    // Metadata.
-    ASSERT_TRUE(mDevice->isIgnored());
-    ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, mDevice->getSources());
-
-    InputDeviceInfo info;
-    mDevice->getDeviceInfo(&info);
-    ASSERT_EQ(DEVICE_ID, info.getId());
-    ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string());
-    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NONE, info.getKeyboardType());
-    ASSERT_EQ(AINPUT_SOURCE_UNKNOWN, info.getSources());
-
-    // State queries.
-    ASSERT_EQ(0, mDevice->getMetaState());
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, 0))
-            << "Ignored device should return unknown key code state.";
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 0))
-            << "Ignored device should return unknown scan code state.";
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 0))
-            << "Ignored device should return unknown switch state.";
-
-    const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B };
-    uint8_t flags[2] = { 0, 1 };
-    ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 2, keyCodes, flags))
-            << "Ignored device should never mark any key codes.";
-    ASSERT_EQ(0, flags[0]) << "Flag for unsupported key should be unchanged.";
-    ASSERT_EQ(1, flags[1]) << "Flag for unsupported key should be unchanged.";
-}
-
-TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRequestsToMappers) {
-    // Configuration.
-    mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8("key"), String8("value"));
-
-    FakeInputMapper* mapper1 = new FakeInputMapper(mDevice, AINPUT_SOURCE_KEYBOARD);
-    mapper1->setKeyboardType(AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    mapper1->setMetaState(AMETA_ALT_ON);
-    mapper1->addSupportedKeyCode(AKEYCODE_A);
-    mapper1->addSupportedKeyCode(AKEYCODE_B);
-    mapper1->setKeyCodeState(AKEYCODE_A, AKEY_STATE_DOWN);
-    mapper1->setKeyCodeState(AKEYCODE_B, AKEY_STATE_UP);
-    mapper1->setScanCodeState(2, AKEY_STATE_DOWN);
-    mapper1->setScanCodeState(3, AKEY_STATE_UP);
-    mapper1->setSwitchState(4, AKEY_STATE_DOWN);
-    mDevice->addMapper(mapper1);
-
-    FakeInputMapper* mapper2 = new FakeInputMapper(mDevice, AINPUT_SOURCE_TOUCHSCREEN);
-    mapper2->setMetaState(AMETA_SHIFT_ON);
-    mDevice->addMapper(mapper2);
-
-    InputReaderConfiguration config;
-    mDevice->configure(ARBITRARY_TIME, &config, 0);
-
-    String8 propertyValue;
-    ASSERT_TRUE(mDevice->getConfiguration().tryGetProperty(String8("key"), propertyValue))
-            << "Device should have read configuration during configuration phase.";
-    ASSERT_STREQ("value", propertyValue.string());
-
-    ASSERT_NO_FATAL_FAILURE(mapper1->assertConfigureWasCalled());
-    ASSERT_NO_FATAL_FAILURE(mapper2->assertConfigureWasCalled());
-
-    // Reset
-    mDevice->reset(ARBITRARY_TIME);
-    ASSERT_NO_FATAL_FAILURE(mapper1->assertResetWasCalled());
-    ASSERT_NO_FATAL_FAILURE(mapper2->assertResetWasCalled());
-
-    NotifyDeviceResetArgs resetArgs;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled(&resetArgs));
-    ASSERT_EQ(ARBITRARY_TIME, resetArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, resetArgs.deviceId);
-
-    // Metadata.
-    ASSERT_FALSE(mDevice->isIgnored());
-    ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), mDevice->getSources());
-
-    InputDeviceInfo info;
-    mDevice->getDeviceInfo(&info);
-    ASSERT_EQ(DEVICE_ID, info.getId());
-    ASSERT_STREQ(DEVICE_NAME, info.getIdentifier().name.string());
-    ASSERT_EQ(AINPUT_KEYBOARD_TYPE_ALPHABETIC, info.getKeyboardType());
-    ASSERT_EQ(uint32_t(AINPUT_SOURCE_KEYBOARD | AINPUT_SOURCE_TOUCHSCREEN), info.getSources());
-
-    // State queries.
-    ASSERT_EQ(AMETA_ALT_ON | AMETA_SHIFT_ON, mDevice->getMetaState())
-            << "Should query mappers and combine meta states.";
-
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return unknown key code state when source not supported.";
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getScanCodeState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return unknown scan code state when source not supported.";
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mDevice->getSwitchState(AINPUT_SOURCE_TRACKBALL, AKEYCODE_A))
-            << "Should return unknown switch state when source not supported.";
-
-    ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getKeyCodeState(AINPUT_SOURCE_KEYBOARD, AKEYCODE_A))
-            << "Should query mapper when source is supported.";
-    ASSERT_EQ(AKEY_STATE_UP, mDevice->getScanCodeState(AINPUT_SOURCE_KEYBOARD, 3))
-            << "Should query mapper when source is supported.";
-    ASSERT_EQ(AKEY_STATE_DOWN, mDevice->getSwitchState(AINPUT_SOURCE_KEYBOARD, 4))
-            << "Should query mapper when source is supported.";
-
-    const int32_t keyCodes[4] = { AKEYCODE_A, AKEYCODE_B, AKEYCODE_1, AKEYCODE_2 };
-    uint8_t flags[4] = { 0, 0, 0, 1 };
-    ASSERT_FALSE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_TRACKBALL, 4, keyCodes, flags))
-            << "Should do nothing when source is unsupported.";
-    ASSERT_EQ(0, flags[0]) << "Flag should be unchanged when source is unsupported.";
-    ASSERT_EQ(0, flags[1]) << "Flag should be unchanged when source is unsupported.";
-    ASSERT_EQ(0, flags[2]) << "Flag should be unchanged when source is unsupported.";
-    ASSERT_EQ(1, flags[3]) << "Flag should be unchanged when source is unsupported.";
-
-    ASSERT_TRUE(mDevice->markSupportedKeyCodes(AINPUT_SOURCE_KEYBOARD, 4, keyCodes, flags))
-            << "Should query mapper when source is supported.";
-    ASSERT_EQ(1, flags[0]) << "Flag for supported key should be set.";
-    ASSERT_EQ(1, flags[1]) << "Flag for supported key should be set.";
-    ASSERT_EQ(0, flags[2]) << "Flag for unsupported key should be unchanged.";
-    ASSERT_EQ(1, flags[3]) << "Flag for unsupported key should be unchanged.";
-
-    // Event handling.
-    RawEvent event;
-    mDevice->process(&event, 1);
-
-    ASSERT_NO_FATAL_FAILURE(mapper1->assertProcessWasCalled());
-    ASSERT_NO_FATAL_FAILURE(mapper2->assertProcessWasCalled());
-}
-
-
-// --- InputMapperTest ---
-
-class InputMapperTest : public testing::Test {
-protected:
-    static const char* DEVICE_NAME;
-    static const int32_t DEVICE_ID;
-    static const int32_t DEVICE_GENERATION;
-    static const int32_t DEVICE_CONTROLLER_NUMBER;
-    static const uint32_t DEVICE_CLASSES;
-
-    sp<FakeEventHub> mFakeEventHub;
-    sp<FakeInputReaderPolicy> mFakePolicy;
-    sp<FakeInputListener> mFakeListener;
-    FakeInputReaderContext* mFakeContext;
-    InputDevice* mDevice;
-
-    virtual void SetUp() {
-        mFakeEventHub = new FakeEventHub();
-        mFakePolicy = new FakeInputReaderPolicy();
-        mFakeListener = new FakeInputListener();
-        mFakeContext = new FakeInputReaderContext(mFakeEventHub, mFakePolicy, mFakeListener);
-        InputDeviceIdentifier identifier;
-        identifier.name = DEVICE_NAME;
-        mDevice = new InputDevice(mFakeContext, DEVICE_ID, DEVICE_GENERATION,
-                DEVICE_CONTROLLER_NUMBER, identifier, DEVICE_CLASSES);
-
-        mFakeEventHub->addDevice(DEVICE_ID, String8(DEVICE_NAME), 0);
-    }
-
-    virtual void TearDown() {
-        delete mDevice;
-        delete mFakeContext;
-        mFakeListener.clear();
-        mFakePolicy.clear();
-        mFakeEventHub.clear();
-    }
-
-    void addConfigurationProperty(const char* key, const char* value) {
-        mFakeEventHub->addConfigurationProperty(DEVICE_ID, String8(key), String8(value));
-    }
-
-    void addMapperAndConfigure(InputMapper* mapper) {
-        mDevice->addMapper(mapper);
-        mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
-        mDevice->reset(ARBITRARY_TIME);
-    }
-
-    void setDisplayInfoAndReconfigure(int32_t displayId, int32_t width, int32_t height,
-            int32_t orientation) {
-        mFakePolicy->setDisplayInfo(displayId, width, height, orientation);
-        mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
-                InputReaderConfiguration::CHANGE_DISPLAY_INFO);
-    }
-
-    static void process(InputMapper* mapper, nsecs_t when, int32_t deviceId, int32_t type,
-            int32_t code, int32_t value) {
-        RawEvent event;
-        event.when = when;
-        event.deviceId = deviceId;
-        event.type = type;
-        event.code = code;
-        event.value = value;
-        mapper->process(&event);
-    }
-
-    static void assertMotionRange(const InputDeviceInfo& info,
-            int32_t axis, uint32_t source, float min, float max, float flat, float fuzz) {
-        const InputDeviceInfo::MotionRange* range = info.getMotionRange(axis, source);
-        ASSERT_TRUE(range != NULL) << "Axis: " << axis << " Source: " << source;
-        ASSERT_EQ(axis, range->axis) << "Axis: " << axis << " Source: " << source;
-        ASSERT_EQ(source, range->source) << "Axis: " << axis << " Source: " << source;
-        ASSERT_NEAR(min, range->min, EPSILON) << "Axis: " << axis << " Source: " << source;
-        ASSERT_NEAR(max, range->max, EPSILON) << "Axis: " << axis << " Source: " << source;
-        ASSERT_NEAR(flat, range->flat, EPSILON) << "Axis: " << axis << " Source: " << source;
-        ASSERT_NEAR(fuzz, range->fuzz, EPSILON) << "Axis: " << axis << " Source: " << source;
-    }
-
-    static void assertPointerCoords(const PointerCoords& coords,
-            float x, float y, float pressure, float size,
-            float touchMajor, float touchMinor, float toolMajor, float toolMinor,
-            float orientation, float distance) {
-        ASSERT_NEAR(x, coords.getAxisValue(AMOTION_EVENT_AXIS_X), 1);
-        ASSERT_NEAR(y, coords.getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
-        ASSERT_NEAR(pressure, coords.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), EPSILON);
-        ASSERT_NEAR(size, coords.getAxisValue(AMOTION_EVENT_AXIS_SIZE), EPSILON);
-        ASSERT_NEAR(touchMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), 1);
-        ASSERT_NEAR(touchMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), 1);
-        ASSERT_NEAR(toolMajor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), 1);
-        ASSERT_NEAR(toolMinor, coords.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), 1);
-        ASSERT_NEAR(orientation, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION), EPSILON);
-        ASSERT_NEAR(distance, coords.getAxisValue(AMOTION_EVENT_AXIS_DISTANCE), EPSILON);
-    }
-
-    static void assertPosition(const sp<FakePointerController>& controller, float x, float y) {
-        float actualX, actualY;
-        controller->getPosition(&actualX, &actualY);
-        ASSERT_NEAR(x, actualX, 1);
-        ASSERT_NEAR(y, actualY, 1);
-    }
-};
-
-const char* InputMapperTest::DEVICE_NAME = "device";
-const int32_t InputMapperTest::DEVICE_ID = 1;
-const int32_t InputMapperTest::DEVICE_GENERATION = 2;
-const int32_t InputMapperTest::DEVICE_CONTROLLER_NUMBER = 0;
-const uint32_t InputMapperTest::DEVICE_CLASSES = 0; // not needed for current tests
-
-
-// --- SwitchInputMapperTest ---
-
-class SwitchInputMapperTest : public InputMapperTest {
-protected:
-};
-
-TEST_F(SwitchInputMapperTest, GetSources) {
-    SwitchInputMapper* mapper = new SwitchInputMapper(mDevice);
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(uint32_t(AINPUT_SOURCE_SWITCH), mapper->getSources());
-}
-
-TEST_F(SwitchInputMapperTest, GetSwitchState) {
-    SwitchInputMapper* mapper = new SwitchInputMapper(mDevice);
-    addMapperAndConfigure(mapper);
-
-    mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 1);
-    ASSERT_EQ(1, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
-
-    mFakeEventHub->setSwitchState(DEVICE_ID, SW_LID, 0);
-    ASSERT_EQ(0, mapper->getSwitchState(AINPUT_SOURCE_ANY, SW_LID));
-}
-
-TEST_F(SwitchInputMapperTest, Process) {
-    SwitchInputMapper* mapper = new SwitchInputMapper(mDevice);
-    addMapperAndConfigure(mapper);
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_LID, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_JACK_PHYSICAL_INSERT, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SW, SW_HEADPHONE_INSERT, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-
-    NotifySwitchArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifySwitchWasCalled(&args));
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT), args.switchValues);
-    ASSERT_EQ((1 << SW_LID) | (1 << SW_JACK_PHYSICAL_INSERT) | (1 << SW_HEADPHONE_INSERT),
-            args.switchMask);
-    ASSERT_EQ(uint32_t(0), args.policyFlags);
-}
-
-
-// --- KeyboardInputMapperTest ---
-
-class KeyboardInputMapperTest : public InputMapperTest {
-protected:
-    void testDPadKeyRotation(KeyboardInputMapper* mapper,
-            int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode);
-};
-
-void KeyboardInputMapperTest::testDPadKeyRotation(KeyboardInputMapper* mapper,
-        int32_t originalScanCode, int32_t originalKeyCode, int32_t rotatedKeyCode) {
-    NotifyKeyArgs args;
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 1);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(originalScanCode, args.scanCode);
-    ASSERT_EQ(rotatedKeyCode, args.keyCode);
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, originalScanCode, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(originalScanCode, args.scanCode);
-    ASSERT_EQ(rotatedKeyCode, args.keyCode);
-}
-
-
-TEST_F(KeyboardInputMapperTest, GetSources) {
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, mapper->getSources());
-}
-
-TEST_F(KeyboardInputMapperTest, Process_SimpleKeyPress) {
-    const int32_t USAGE_A = 0x070004;
-    const int32_t USAGE_UNKNOWN = 0x07ffff;
-    mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE);
-    mFakeEventHub->addKey(DEVICE_ID, 0, USAGE_A, AKEYCODE_A, POLICY_FLAG_WAKE);
-
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    // Key down by scan code.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_HOME, 1);
-    NotifyKeyArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
-    ASSERT_EQ(KEY_HOME, args.scanCode);
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
-    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Key up by scan code.
-    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
-            EV_KEY, KEY_HOME, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
-    ASSERT_EQ(KEY_HOME, args.scanCode);
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
-    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Key down by usage code.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_MSC, MSC_SCAN, USAGE_A);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, 0, 1);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(AKEYCODE_A, args.keyCode);
-    ASSERT_EQ(0, args.scanCode);
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
-    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Key up by usage code.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_MSC, MSC_SCAN, USAGE_A);
-    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
-            EV_KEY, 0, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(AKEYCODE_A, args.keyCode);
-    ASSERT_EQ(0, args.scanCode);
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
-    ASSERT_EQ(POLICY_FLAG_WAKE, args.policyFlags);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Key down with unknown scan code or usage code.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_UNKNOWN, 1);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(0, args.keyCode);
-    ASSERT_EQ(KEY_UNKNOWN, args.scanCode);
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
-    ASSERT_EQ(0U, args.policyFlags);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Key up with unknown scan code or usage code.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_MSC, MSC_SCAN, USAGE_UNKNOWN);
-    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
-            EV_KEY, KEY_UNKNOWN, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(0, args.keyCode);
-    ASSERT_EQ(KEY_UNKNOWN, args.scanCode);
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM, args.flags);
-    ASSERT_EQ(0U, args.policyFlags);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-}
-
-TEST_F(KeyboardInputMapperTest, Process_ShouldUpdateMetaState) {
-    mFakeEventHub->addKey(DEVICE_ID, KEY_LEFTSHIFT, 0, AKEYCODE_SHIFT_LEFT, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0);
-
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    // Initial metastate.
-    ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
-
-    // Metakey down.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_LEFTSHIFT, 1);
-    NotifyKeyArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState());
-    ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled());
-
-    // Key down.
-    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID,
-            EV_KEY, KEY_A, 1);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState());
-
-    // Key up.
-    process(mapper, ARBITRARY_TIME + 2, DEVICE_ID,
-            EV_KEY, KEY_A, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, mapper->getMetaState());
-
-    // Metakey up.
-    process(mapper, ARBITRARY_TIME + 3, DEVICE_ID,
-            EV_KEY, KEY_LEFTSHIFT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AMETA_NONE, args.metaState);
-    ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
-    ASSERT_NO_FATAL_FAILURE(mFakeContext->assertUpdateGlobalMetaStateWasCalled());
-}
-
-TEST_F(KeyboardInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateDPad) {
-    mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0);
-
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_90);
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT));
-}
-
-TEST_F(KeyboardInputMapperTest, Process_WhenOrientationAware_ShouldRotateDPad) {
-    mFakeEventHub->addKey(DEVICE_ID, KEY_UP, 0, AKEYCODE_DPAD_UP, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_RIGHT, 0, AKEYCODE_DPAD_RIGHT, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_DOWN, 0, AKEYCODE_DPAD_DOWN, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_LEFT, 0, AKEYCODE_DPAD_LEFT, 0);
-
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addConfigurationProperty("keyboard.orientationAware", "1");
-    addMapperAndConfigure(mapper);
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_0);
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_UP));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_RIGHT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_DOWN));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_LEFT));
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_90);
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN));
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_180);
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_DOWN));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_LEFT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_UP));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_RIGHT));
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_270);
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_UP, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_RIGHT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_RIGHT, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_DOWN));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_DOWN, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_LEFT));
-    ASSERT_NO_FATAL_FAILURE(testDPadKeyRotation(mapper,
-            KEY_LEFT, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_UP));
-
-    // Special case: if orientation changes while key is down, we still emit the same keycode
-    // in the key up as we did in the key down.
-    NotifyKeyArgs args;
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_270);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 1);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(KEY_UP, args.scanCode);
-    ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode);
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_180);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, KEY_UP, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(KEY_UP, args.scanCode);
-    ASSERT_EQ(AKEYCODE_DPAD_RIGHT, args.keyCode);
-}
-
-TEST_F(KeyboardInputMapperTest, GetKeyCodeState) {
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 1);
-    ASSERT_EQ(1, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A));
-
-    mFakeEventHub->setKeyCodeState(DEVICE_ID, AKEYCODE_A, 0);
-    ASSERT_EQ(0, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A));
-}
-
-TEST_F(KeyboardInputMapperTest, GetScanCodeState) {
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 1);
-    ASSERT_EQ(1, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A));
-
-    mFakeEventHub->setScanCodeState(DEVICE_ID, KEY_A, 0);
-    ASSERT_EQ(0, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A));
-}
-
-TEST_F(KeyboardInputMapperTest, MarkSupportedKeyCodes) {
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    mFakeEventHub->addKey(DEVICE_ID, KEY_A, 0, AKEYCODE_A, 0);
-
-    const int32_t keyCodes[2] = { AKEYCODE_A, AKEYCODE_B };
-    uint8_t flags[2] = { 0, 0 };
-    ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 1, keyCodes, flags));
-    ASSERT_TRUE(flags[0]);
-    ASSERT_FALSE(flags[1]);
-}
-
-TEST_F(KeyboardInputMapperTest, Process_LockedKeysShouldToggleMetaStateAndLeds) {
-    mFakeEventHub->addLed(DEVICE_ID, LED_CAPSL, true /*initially on*/);
-    mFakeEventHub->addLed(DEVICE_ID, LED_NUML, false /*initially off*/);
-    mFakeEventHub->addLed(DEVICE_ID, LED_SCROLLL, false /*initially off*/);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_CAPSLOCK, 0, AKEYCODE_CAPS_LOCK, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_NUMLOCK, 0, AKEYCODE_NUM_LOCK, 0);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_SCROLLLOCK, 0, AKEYCODE_SCROLL_LOCK, 0);
-
-    KeyboardInputMapper* mapper = new KeyboardInputMapper(mDevice,
-            AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC);
-    addMapperAndConfigure(mapper);
-
-    // Initialization should have turned all of the lights off.
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-
-    // Toggle caps lock on.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_CAPSLOCK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_CAPSLOCK, 0);
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-    ASSERT_EQ(AMETA_CAPS_LOCK_ON, mapper->getMetaState());
-
-    // Toggle num lock on.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_NUMLOCK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_NUMLOCK, 0);
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-    ASSERT_EQ(AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON, mapper->getMetaState());
-
-    // Toggle caps lock off.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_CAPSLOCK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_CAPSLOCK, 0);
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-    ASSERT_EQ(AMETA_NUM_LOCK_ON, mapper->getMetaState());
-
-    // Toggle scroll lock on.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_SCROLLLOCK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_SCROLLLOCK, 0);
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-    ASSERT_EQ(AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON, mapper->getMetaState());
-
-    // Toggle num lock off.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_NUMLOCK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_NUMLOCK, 0);
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_TRUE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-    ASSERT_EQ(AMETA_SCROLL_LOCK_ON, mapper->getMetaState());
-
-    // Toggle scroll lock off.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_SCROLLLOCK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID,
-            EV_KEY, KEY_SCROLLLOCK, 0);
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_CAPSL));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_NUML));
-    ASSERT_FALSE(mFakeEventHub->getLedState(DEVICE_ID, LED_SCROLLL));
-    ASSERT_EQ(AMETA_NONE, mapper->getMetaState());
-}
-
-
-// --- CursorInputMapperTest ---
-
-class CursorInputMapperTest : public InputMapperTest {
-protected:
-    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD;
-
-    sp<FakePointerController> mFakePointerController;
-
-    virtual void SetUp() {
-        InputMapperTest::SetUp();
-
-        mFakePointerController = new FakePointerController();
-        mFakePolicy->setPointerController(DEVICE_ID, mFakePointerController);
-    }
-
-    void testMotionRotation(CursorInputMapper* mapper,
-            int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY);
-};
-
-const int32_t CursorInputMapperTest::TRACKBALL_MOVEMENT_THRESHOLD = 6;
-
-void CursorInputMapperTest::testMotionRotation(CursorInputMapper* mapper,
-        int32_t originalX, int32_t originalY, int32_t rotatedX, int32_t rotatedY) {
-    NotifyMotionArgs args;
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, originalX);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, originalY);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            float(rotatedX) / TRACKBALL_MOVEMENT_THRESHOLD,
-            float(rotatedY) / TRACKBALL_MOVEMENT_THRESHOLD,
-            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-}
-
-TEST_F(CursorInputMapperTest, WhenModeIsPointer_GetSources_ReturnsMouse) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "pointer");
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources());
-}
-
-TEST_F(CursorInputMapperTest, WhenModeIsNavigation_GetSources_ReturnsTrackball) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, mapper->getSources());
-}
-
-TEST_F(CursorInputMapperTest, WhenModeIsPointer_PopulateDeviceInfo_ReturnsRangeFromPointerController) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "pointer");
-    addMapperAndConfigure(mapper);
-
-    InputDeviceInfo info;
-    mapper->populateDeviceInfo(&info);
-
-    // Initially there may not be a valid motion range.
-    ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE));
-    ASSERT_EQ(NULL, info.getMotionRange(AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE));
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
-            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE, 0.0f, 1.0f, 0.0f, 0.0f));
-
-    // When the bounds are set, then there should be a valid motion range.
-    mFakePointerController->setBounds(1, 2, 800 - 1, 480 - 1);
-
-    InputDeviceInfo info2;
-    mapper->populateDeviceInfo(&info2);
-
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2,
-            AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_MOUSE,
-            1, 800 - 1, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2,
-            AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_MOUSE,
-            2, 480 - 1, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info2,
-            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_MOUSE,
-            0.0f, 1.0f, 0.0f, 0.0f));
-}
-
-TEST_F(CursorInputMapperTest, WhenModeIsNavigation_PopulateDeviceInfo_ReturnsScaledRange) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    InputDeviceInfo info;
-    mapper->populateDeviceInfo(&info);
-
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
-            AINPUT_MOTION_RANGE_X, AINPUT_SOURCE_TRACKBALL,
-            -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD));
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
-            AINPUT_MOTION_RANGE_Y, AINPUT_SOURCE_TRACKBALL,
-            -1.0f, 1.0f, 0.0f, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD));
-    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
-            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TRACKBALL,
-            0.0f, 1.0f, 0.0f, 0.0f));
-}
-
-TEST_F(CursorInputMapperTest, Process_ShouldSetAllFieldsAndIncludeGlobalMetaState) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyMotionArgs args;
-
-    // Button press.
-    // Mostly testing non x/y behavior here so we don't need to check again elsewhere.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source);
-    ASSERT_EQ(uint32_t(0), args.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(0, args.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, args.buttonState);
-    ASSERT_EQ(0, args.edgeFlags);
-    ASSERT_EQ(uint32_t(1), args.pointerCount);
-    ASSERT_EQ(0, args.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
-    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Button release.  Should have same down time.
-    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_KEY, BTN_MOUSE, 0);
-    process(mapper, ARBITRARY_TIME + 1, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(ARBITRARY_TIME + 1, args.eventTime);
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TRACKBALL, args.source);
-    ASSERT_EQ(uint32_t(0), args.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(0, args.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(0, args.buttonState);
-    ASSERT_EQ(0, args.edgeFlags);
-    ASSERT_EQ(uint32_t(1), args.pointerCount);
-    ASSERT_EQ(0, args.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, args.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.xPrecision);
-    ASSERT_EQ(TRACKBALL_MOVEMENT_THRESHOLD, args.yPrecision);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-}
-
-TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentXYUpdates) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs args;
-
-    // Motion in X but not Y.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            1.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    // Motion in Y but not X.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            0.0f, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-}
-
-TEST_F(CursorInputMapperTest, Process_ShouldHandleIndependentButtonUpdates) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs args;
-
-    // Button press.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    // Button release.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-}
-
-TEST_F(CursorInputMapperTest, Process_ShouldHandleCombinedXYAndButtonUpdates) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs args;
-
-    // Combined X, Y and Button.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, -2);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            1.0f / TRACKBALL_MOVEMENT_THRESHOLD, -2.0f / TRACKBALL_MOVEMENT_THRESHOLD,
-            1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    // Move X, Y a bit while pressed.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 2);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            2.0f / TRACKBALL_MOVEMENT_THRESHOLD, 1.0f / TRACKBALL_MOVEMENT_THRESHOLD,
-            1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    // Release Button.
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MOUSE, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-}
-
-TEST_F(CursorInputMapperTest, Process_WhenNotOrientationAware_ShouldNotRotateMotions) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addMapperAndConfigure(mapper);
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT,
-            DISPLAY_ORIENTATION_90);
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0, -1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1,  1));
-}
-
-TEST_F(CursorInputMapperTest, Process_WhenOrientationAware_ShouldRotateMotions) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "navigation");
-    addConfigurationProperty("cursor.orientationAware", "1");
-    addMapperAndConfigure(mapper);
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_0);
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0, -1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1,  1));
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_90);
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1,  1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  0, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1, -1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1, -1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1, -1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  0,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1,  1,  1));
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_180);
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1,  0, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1, -1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0, -1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1, -1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  0,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1,  1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1,  1, -1));
-
-    setDisplayInfoAndReconfigure(DISPLAY_ID,
-            DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_ORIENTATION_270);
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0,  1, -1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  1, -1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1,  0,  0,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  1, -1,  1,  1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper,  0, -1,  1,  0));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1, -1,  1, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  0,  0, -1));
-    ASSERT_NO_FATAL_FAILURE(testMotionRotation(mapper, -1,  1, -1, -1));
-}
-
-TEST_F(CursorInputMapperTest, Process_ShouldHandleAllButtons) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "pointer");
-    addMapperAndConfigure(mapper);
-
-    mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
-    mFakePointerController->setPosition(100, 200);
-    mFakePointerController->setButtonState(0);
-
-    NotifyMotionArgs motionArgs;
-    NotifyKeyArgs keyArgs;
-
-    // press BTN_LEFT, release BTN_LEFT
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, mFakePointerController->getButtonState());
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_LEFT, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
-            motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
-            mFakePointerController->getButtonState());
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_RIGHT, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_MIDDLE, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    // press BTN_BACK, release BTN_BACK
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_BACK, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-
-    // press BTN_SIDE, release BTN_SIDE
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_SIDE, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-
-    // press BTN_FORWARD, release BTN_FORWARD
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_FORWARD, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-
-    // press BTN_EXTRA, release BTN_EXTRA
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_EXTRA, 0);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, mFakePointerController->getButtonState());
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            100.0f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-}
-
-TEST_F(CursorInputMapperTest, Process_WhenModeIsPointer_ShouldMoveThePointerAround) {
-    CursorInputMapper* mapper = new CursorInputMapper(mDevice);
-    addConfigurationProperty("cursor.mode", "pointer");
-    addMapperAndConfigure(mapper);
-
-    mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
-    mFakePointerController->setPosition(100, 200);
-    mFakePointerController->setButtonState(0);
-
-    NotifyMotionArgs args;
-
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_X, 10);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_REL, REL_Y, 20);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, args.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            110.0f, 220.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f));
-    ASSERT_NO_FATAL_FAILURE(assertPosition(mFakePointerController, 110.0f, 220.0f));
-}
-
-
-// --- TouchInputMapperTest ---
-
-class TouchInputMapperTest : public InputMapperTest {
-protected:
-    static const int32_t RAW_X_MIN;
-    static const int32_t RAW_X_MAX;
-    static const int32_t RAW_Y_MIN;
-    static const int32_t RAW_Y_MAX;
-    static const int32_t RAW_TOUCH_MIN;
-    static const int32_t RAW_TOUCH_MAX;
-    static const int32_t RAW_TOOL_MIN;
-    static const int32_t RAW_TOOL_MAX;
-    static const int32_t RAW_PRESSURE_MIN;
-    static const int32_t RAW_PRESSURE_MAX;
-    static const int32_t RAW_ORIENTATION_MIN;
-    static const int32_t RAW_ORIENTATION_MAX;
-    static const int32_t RAW_DISTANCE_MIN;
-    static const int32_t RAW_DISTANCE_MAX;
-    static const int32_t RAW_TILT_MIN;
-    static const int32_t RAW_TILT_MAX;
-    static const int32_t RAW_ID_MIN;
-    static const int32_t RAW_ID_MAX;
-    static const int32_t RAW_SLOT_MIN;
-    static const int32_t RAW_SLOT_MAX;
-    static const float X_PRECISION;
-    static const float Y_PRECISION;
-
-    static const float GEOMETRIC_SCALE;
-
-    static const VirtualKeyDefinition VIRTUAL_KEYS[2];
-
-    enum Axes {
-        POSITION = 1 << 0,
-        TOUCH = 1 << 1,
-        TOOL = 1 << 2,
-        PRESSURE = 1 << 3,
-        ORIENTATION = 1 << 4,
-        MINOR = 1 << 5,
-        ID = 1 << 6,
-        DISTANCE = 1 << 7,
-        TILT = 1 << 8,
-        SLOT = 1 << 9,
-        TOOL_TYPE = 1 << 10,
-    };
-
-    void prepareDisplay(int32_t orientation);
-    void prepareVirtualKeys();
-    int32_t toRawX(float displayX);
-    int32_t toRawY(float displayY);
-    float toDisplayX(int32_t rawX);
-    float toDisplayY(int32_t rawY);
-};
-
-const int32_t TouchInputMapperTest::RAW_X_MIN = 25;
-const int32_t TouchInputMapperTest::RAW_X_MAX = 1019;
-const int32_t TouchInputMapperTest::RAW_Y_MIN = 30;
-const int32_t TouchInputMapperTest::RAW_Y_MAX = 1009;
-const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0;
-const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31;
-const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0;
-const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15;
-const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = RAW_TOUCH_MIN;
-const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = RAW_TOUCH_MAX;
-const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7;
-const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7;
-const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0;
-const int32_t TouchInputMapperTest::RAW_DISTANCE_MAX = 7;
-const int32_t TouchInputMapperTest::RAW_TILT_MIN = 0;
-const int32_t TouchInputMapperTest::RAW_TILT_MAX = 150;
-const int32_t TouchInputMapperTest::RAW_ID_MIN = 0;
-const int32_t TouchInputMapperTest::RAW_ID_MAX = 9;
-const int32_t TouchInputMapperTest::RAW_SLOT_MIN = 0;
-const int32_t TouchInputMapperTest::RAW_SLOT_MAX = 9;
-const float TouchInputMapperTest::X_PRECISION = float(RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH;
-const float TouchInputMapperTest::Y_PRECISION = float(RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT;
-
-const float TouchInputMapperTest::GEOMETRIC_SCALE =
-        avg(float(DISPLAY_WIDTH) / (RAW_X_MAX - RAW_X_MIN + 1),
-                float(DISPLAY_HEIGHT) / (RAW_Y_MAX - RAW_Y_MIN + 1));
-
-const VirtualKeyDefinition TouchInputMapperTest::VIRTUAL_KEYS[2] = {
-        { KEY_HOME, 60, DISPLAY_HEIGHT + 15, 20, 20 },
-        { KEY_MENU, DISPLAY_HEIGHT - 60, DISPLAY_WIDTH + 15, 20, 20 },
-};
-
-void TouchInputMapperTest::prepareDisplay(int32_t orientation) {
-    setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, orientation);
-}
-
-void TouchInputMapperTest::prepareVirtualKeys() {
-    mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[0]);
-    mFakeEventHub->addVirtualKeyDefinition(DEVICE_ID, VIRTUAL_KEYS[1]);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_HOME, 0, AKEYCODE_HOME, POLICY_FLAG_WAKE);
-    mFakeEventHub->addKey(DEVICE_ID, KEY_MENU, 0, AKEYCODE_MENU, POLICY_FLAG_WAKE);
-}
-
-int32_t TouchInputMapperTest::toRawX(float displayX) {
-    return int32_t(displayX * (RAW_X_MAX - RAW_X_MIN + 1) / DISPLAY_WIDTH + RAW_X_MIN);
-}
-
-int32_t TouchInputMapperTest::toRawY(float displayY) {
-    return int32_t(displayY * (RAW_Y_MAX - RAW_Y_MIN + 1) / DISPLAY_HEIGHT + RAW_Y_MIN);
-}
-
-float TouchInputMapperTest::toDisplayX(int32_t rawX) {
-    return float(rawX - RAW_X_MIN) * DISPLAY_WIDTH / (RAW_X_MAX - RAW_X_MIN + 1);
-}
-
-float TouchInputMapperTest::toDisplayY(int32_t rawY) {
-    return float(rawY - RAW_Y_MIN) * DISPLAY_HEIGHT / (RAW_Y_MAX - RAW_Y_MIN + 1);
-}
-
-
-// --- SingleTouchInputMapperTest ---
-
-class SingleTouchInputMapperTest : public TouchInputMapperTest {
-protected:
-    void prepareButtons();
-    void prepareAxes(int axes);
-
-    void processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y);
-    void processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y);
-    void processUp(SingleTouchInputMapper* mappery);
-    void processPressure(SingleTouchInputMapper* mapper, int32_t pressure);
-    void processToolMajor(SingleTouchInputMapper* mapper, int32_t toolMajor);
-    void processDistance(SingleTouchInputMapper* mapper, int32_t distance);
-    void processTilt(SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY);
-    void processKey(SingleTouchInputMapper* mapper, int32_t code, int32_t value);
-    void processSync(SingleTouchInputMapper* mapper);
-};
-
-void SingleTouchInputMapperTest::prepareButtons() {
-    mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0);
-}
-
-void SingleTouchInputMapperTest::prepareAxes(int axes) {
-    if (axes & POSITION) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_X,
-                RAW_X_MIN, RAW_X_MAX, 0, 0);
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_Y,
-                RAW_Y_MIN, RAW_Y_MAX, 0, 0);
-    }
-    if (axes & PRESSURE) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_PRESSURE,
-                RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0);
-    }
-    if (axes & TOOL) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TOOL_WIDTH,
-                RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0);
-    }
-    if (axes & DISTANCE) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_DISTANCE,
-                RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0);
-    }
-    if (axes & TILT) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_X,
-                RAW_TILT_MIN, RAW_TILT_MAX, 0, 0);
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_TILT_Y,
-                RAW_TILT_MIN, RAW_TILT_MAX, 0, 0);
-    }
-}
-
-void SingleTouchInputMapperTest::processDown(SingleTouchInputMapper* mapper, int32_t x, int32_t y) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 1);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y);
-}
-
-void SingleTouchInputMapperTest::processMove(SingleTouchInputMapper* mapper, int32_t x, int32_t y) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_X, x);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_Y, y);
-}
-
-void SingleTouchInputMapperTest::processUp(SingleTouchInputMapper* mapper) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, BTN_TOUCH, 0);
-}
-
-void SingleTouchInputMapperTest::processPressure(
-        SingleTouchInputMapper* mapper, int32_t pressure) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_PRESSURE, pressure);
-}
-
-void SingleTouchInputMapperTest::processToolMajor(
-        SingleTouchInputMapper* mapper, int32_t toolMajor) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TOOL_WIDTH, toolMajor);
-}
-
-void SingleTouchInputMapperTest::processDistance(
-        SingleTouchInputMapper* mapper, int32_t distance) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_DISTANCE, distance);
-}
-
-void SingleTouchInputMapperTest::processTilt(
-        SingleTouchInputMapper* mapper, int32_t tiltX, int32_t tiltY) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_X, tiltX);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_TILT_Y, tiltY);
-}
-
-void SingleTouchInputMapperTest::processKey(
-        SingleTouchInputMapper* mapper, int32_t code, int32_t value) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value);
-}
-
-void SingleTouchInputMapperTest::processSync(SingleTouchInputMapper* mapper) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-}
-
-
-TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndNotACursor_ReturnsPointer) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    prepareButtons();
-    prepareAxes(POSITION);
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_MOUSE, mapper->getSources());
-}
-
-TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsNotSpecifiedAndIsACursor_ReturnsTouchPad) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_X);
-    mFakeEventHub->addRelativeAxis(DEVICE_ID, REL_Y);
-    prepareButtons();
-    prepareAxes(POSITION);
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources());
-}
-
-TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchPad_ReturnsTouchPad) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    prepareButtons();
-    prepareAxes(POSITION);
-    addConfigurationProperty("touch.deviceType", "touchPad");
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHPAD, mapper->getSources());
-}
-
-TEST_F(SingleTouchInputMapperTest, GetSources_WhenDeviceTypeIsTouchScreen_ReturnsTouchScreen) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    prepareButtons();
-    prepareAxes(POSITION);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    addMapperAndConfigure(mapper);
-
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, mapper->getSources());
-}
-
-TEST_F(SingleTouchInputMapperTest, GetKeyCodeState) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    // Unknown key.
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_A));
-
-    // Virtual key is down.
-    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
-    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
-    processDown(mapper, x, y);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
-
-    ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME));
-
-    // Virtual key is up.
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
-
-    ASSERT_EQ(AKEY_STATE_UP, mapper->getKeyCodeState(AINPUT_SOURCE_ANY, AKEYCODE_HOME));
-}
-
-TEST_F(SingleTouchInputMapperTest, GetScanCodeState) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    // Unknown key.
-    ASSERT_EQ(AKEY_STATE_UNKNOWN, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_A));
-
-    // Virtual key is down.
-    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
-    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
-    processDown(mapper, x, y);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
-
-    ASSERT_EQ(AKEY_STATE_VIRTUAL, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME));
-
-    // Virtual key is up.
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled());
-
-    ASSERT_EQ(AKEY_STATE_UP, mapper->getScanCodeState(AINPUT_SOURCE_ANY, KEY_HOME));
-}
-
-TEST_F(SingleTouchInputMapperTest, MarkSupportedKeyCodes) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    const int32_t keys[2] = { AKEYCODE_HOME, AKEYCODE_A };
-    uint8_t flags[2] = { 0, 0 };
-    ASSERT_TRUE(mapper->markSupportedKeyCodes(AINPUT_SOURCE_ANY, 2, keys, flags));
-    ASSERT_TRUE(flags[0]);
-    ASSERT_FALSE(flags[1]);
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndReleasedNormally_SendsKeyDownAndKeyUp) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyKeyArgs args;
-
-    // Press virtual key.
-    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
-    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
-    processDown(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags);
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, args.action);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags);
-    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
-    ASSERT_EQ(KEY_HOME, args.scanCode);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Release virtual key.
-    processUp(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&args));
-    ASSERT_EQ(ARBITRARY_TIME, args.eventTime);
-    ASSERT_EQ(DEVICE_ID, args.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, args.source);
-    ASSERT_EQ(POLICY_FLAG_VIRTUAL, args.policyFlags);
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, args.action);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, args.flags);
-    ASSERT_EQ(AKEYCODE_HOME, args.keyCode);
-    ASSERT_EQ(KEY_HOME, args.scanCode);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, args.metaState);
-    ASSERT_EQ(ARBITRARY_TIME, args.downTime);
-
-    // Should not have sent any motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenVirtualKeyIsPressedAndMovedOutOfBounds_SendsKeyDownAndKeyCancel) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyKeyArgs keyArgs;
-
-    // Press virtual key.
-    int32_t x = toRawX(VIRTUAL_KEYS[0].centerX);
-    int32_t y = toRawY(VIRTUAL_KEYS[0].centerY);
-    processDown(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, keyArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source);
-    ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags);
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY, keyArgs.flags);
-    ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode);
-    ASSERT_EQ(KEY_HOME, keyArgs.scanCode);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState);
-    ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime);
-
-    // Move out of bounds.  This should generate a cancel and a pointer down since we moved
-    // into the display area.
-    y -= 100;
-    processMove(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(ARBITRARY_TIME, keyArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, keyArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, keyArgs.source);
-    ASSERT_EQ(POLICY_FLAG_VIRTUAL, keyArgs.policyFlags);
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEY_EVENT_FLAG_FROM_SYSTEM | AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY
-            | AKEY_EVENT_FLAG_CANCELED, keyArgs.flags);
-    ASSERT_EQ(AKEYCODE_HOME, keyArgs.keyCode);
-    ASSERT_EQ(KEY_HOME, keyArgs.scanCode);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, keyArgs.metaState);
-    ASSERT_EQ(ARBITRARY_TIME, keyArgs.downTime);
-
-    NotifyMotionArgs motionArgs;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Keep moving out of bounds.  Should generate a pointer move.
-    y -= 50;
-    processMove(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Release out of bounds.  Should generate a pointer up.
-    processUp(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Should not have sent any more keys or motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenTouchStartsOutsideDisplayAndMovesIn_SendsDownAsTouchEntersDisplay) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyMotionArgs motionArgs;
-
-    // Initially go down out of bounds.
-    int32_t x = -10;
-    int32_t y = -10;
-    processDown(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-
-    // Move into the display area.  Should generate a pointer down.
-    x = 50;
-    y = 75;
-    processMove(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Release.  Should generate a pointer up.
-    processUp(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Should not have sent any more keys or motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_NormalSingleTouchGesture) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyMotionArgs motionArgs;
-
-    // Down.
-    int32_t x = 100;
-    int32_t y = 125;
-    processDown(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Move.
-    x += 50;
-    y += 75;
-    processMove(mapper, x, y);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Up.
-    processUp(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x), toDisplayY(y), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Should not have sent any more keys or motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenNotOrientationAware_DoesNotRotateMotions) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareButtons();
-    prepareAxes(POSITION);
-    addConfigurationProperty("touch.orientationAware", "0");
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs args;
-
-    // Rotation 90.
-    prepareDisplay(DISPLAY_ORIENTATION_90);
-    processDown(mapper, toRawX(50), toRawY(75));
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
-    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
-
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenOrientationAware_RotatesMotions) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareButtons();
-    prepareAxes(POSITION);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs args;
-
-    // Rotation 0.
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    processDown(mapper, toRawX(50), toRawY(75));
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
-    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
-
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
-
-    // Rotation 90.
-    prepareDisplay(DISPLAY_ORIENTATION_90);
-    processDown(mapper, RAW_X_MAX - toRawX(75) + RAW_X_MIN, toRawY(50));
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
-    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
-
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
-
-    // Rotation 180.
-    prepareDisplay(DISPLAY_ORIENTATION_180);
-    processDown(mapper, RAW_X_MAX - toRawX(50) + RAW_X_MIN, RAW_Y_MAX - toRawY(75) + RAW_Y_MIN);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
-    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
-
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
-
-    // Rotation 270.
-    prepareDisplay(DISPLAY_ORIENTATION_270);
-    processDown(mapper, toRawX(75), RAW_Y_MAX - toRawY(50) + RAW_Y_MIN);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NEAR(50, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X), 1);
-    ASSERT_NEAR(75, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y), 1);
-
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled());
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_AllAxes_DefaultCalibration) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION | PRESSURE | TOOL | DISTANCE | TILT);
-    addMapperAndConfigure(mapper);
-
-    // These calculations are based on the input device calibration documentation.
-    int32_t rawX = 100;
-    int32_t rawY = 200;
-    int32_t rawPressure = 10;
-    int32_t rawToolMajor = 12;
-    int32_t rawDistance = 2;
-    int32_t rawTiltX = 30;
-    int32_t rawTiltY = 110;
-
-    float x = toDisplayX(rawX);
-    float y = toDisplayY(rawY);
-    float pressure = float(rawPressure) / RAW_PRESSURE_MAX;
-    float size = float(rawToolMajor) / RAW_TOOL_MAX;
-    float tool = float(rawToolMajor) * GEOMETRIC_SCALE;
-    float distance = float(rawDistance);
-
-    float tiltCenter = (RAW_TILT_MAX + RAW_TILT_MIN) * 0.5f;
-    float tiltScale = M_PI / 180;
-    float tiltXAngle = (rawTiltX - tiltCenter) * tiltScale;
-    float tiltYAngle = (rawTiltY - tiltCenter) * tiltScale;
-    float orientation = atan2f(-sinf(tiltXAngle), sinf(tiltYAngle));
-    float tilt = acosf(cosf(tiltXAngle) * cosf(tiltYAngle));
-
-    processDown(mapper, rawX, rawY);
-    processPressure(mapper, rawPressure);
-    processToolMajor(mapper, rawToolMajor);
-    processDistance(mapper, rawDistance);
-    processTilt(mapper, rawTiltX, rawTiltY);
-    processSync(mapper);
-
-    NotifyMotionArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            x, y, pressure, size, tool, tool, tool, tool, orientation, distance));
-    ASSERT_EQ(tilt, args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_TILT));
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllButtons) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-    NotifyKeyArgs keyArgs;
-
-    processDown(mapper, 100, 200);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.buttonState);
-
-    // press BTN_LEFT, release BTN_LEFT
-    processKey(mapper, BTN_LEFT, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
-
-    processKey(mapper, BTN_LEFT, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
-    processKey(mapper, BTN_RIGHT, 1);
-    processKey(mapper, BTN_MIDDLE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
-            motionArgs.buttonState);
-
-    processKey(mapper, BTN_RIGHT, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_MIDDLE, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // press BTN_BACK, release BTN_BACK
-    processKey(mapper, BTN_BACK, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_BACK, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-
-    // press BTN_SIDE, release BTN_SIDE
-    processKey(mapper, BTN_SIDE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_SIDE, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-
-    // press BTN_FORWARD, release BTN_FORWARD
-    processKey(mapper, BTN_FORWARD, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_FORWARD, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-
-    // press BTN_EXTRA, release BTN_EXTRA
-    processKey(mapper, BTN_EXTRA, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_EXTRA, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-
-    // press BTN_STYLUS, release BTN_STYLUS
-    processKey(mapper, BTN_STYLUS, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY, motionArgs.buttonState);
-
-    processKey(mapper, BTN_STYLUS, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // press BTN_STYLUS2, release BTN_STYLUS2
-    processKey(mapper, BTN_STYLUS2, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
-
-    processKey(mapper, BTN_STYLUS2, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // release touch
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.buttonState);
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-
-    // default tool type is finger
-    processDown(mapper, 100, 200);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // eraser
-    processKey(mapper, BTN_TOOL_RUBBER, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
-
-    // stylus
-    processKey(mapper, BTN_TOOL_RUBBER, 0);
-    processKey(mapper, BTN_TOOL_PEN, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // brush
-    processKey(mapper, BTN_TOOL_PEN, 0);
-    processKey(mapper, BTN_TOOL_BRUSH, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // pencil
-    processKey(mapper, BTN_TOOL_BRUSH, 0);
-    processKey(mapper, BTN_TOOL_PENCIL, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // airbrush
-    processKey(mapper, BTN_TOOL_PENCIL, 0);
-    processKey(mapper, BTN_TOOL_AIRBRUSH, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // mouse
-    processKey(mapper, BTN_TOOL_AIRBRUSH, 0);
-    processKey(mapper, BTN_TOOL_MOUSE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
-
-    // lens
-    processKey(mapper, BTN_TOOL_MOUSE, 0);
-    processKey(mapper, BTN_TOOL_LENS, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
-
-    // double-tap
-    processKey(mapper, BTN_TOOL_LENS, 0);
-    processKey(mapper, BTN_TOOL_DOUBLETAP, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // triple-tap
-    processKey(mapper, BTN_TOOL_DOUBLETAP, 0);
-    processKey(mapper, BTN_TOOL_TRIPLETAP, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // quad-tap
-    processKey(mapper, BTN_TOOL_TRIPLETAP, 0);
-    processKey(mapper, BTN_TOOL_QUADTAP, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // finger
-    processKey(mapper, BTN_TOOL_QUADTAP, 0);
-    processKey(mapper, BTN_TOOL_FINGER, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // stylus trumps finger
-    processKey(mapper, BTN_TOOL_PEN, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // eraser trumps stylus
-    processKey(mapper, BTN_TOOL_RUBBER, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
-
-    // mouse trumps eraser
-    processKey(mapper, BTN_TOOL_MOUSE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
-
-    // back to default tool type
-    processKey(mapper, BTN_TOOL_MOUSE, 0);
-    processKey(mapper, BTN_TOOL_RUBBER, 0);
-    processKey(mapper, BTN_TOOL_PEN, 0);
-    processKey(mapper, BTN_TOOL_FINGER, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION);
-    mFakeEventHub->addKey(DEVICE_ID, BTN_TOOL_FINGER, 0, AKEYCODE_UNKNOWN, 0);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-
-    // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0
-    processKey(mapper, BTN_TOOL_FINGER, 1);
-    processMove(mapper, 100, 200);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // move a little
-    processMove(mapper, 150, 250);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // down when BTN_TOUCH is pressed, pressure defaults to 1
-    processKey(mapper, BTN_TOUCH, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // up when BTN_TOUCH is released, hover restored
-    processKey(mapper, BTN_TOUCH, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // exit hover when pointer goes away
-    processKey(mapper, BTN_TOOL_FINGER, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-}
-
-TEST_F(SingleTouchInputMapperTest, Process_WhenAbsPressureIsPresent_HoversIfItsValueIsZero) {
-    SingleTouchInputMapper* mapper = new SingleTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareButtons();
-    prepareAxes(POSITION | PRESSURE);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-
-    // initially hovering because pressure is 0
-    processDown(mapper, 100, 200);
-    processPressure(mapper, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // move a little
-    processMove(mapper, 150, 250);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // down when pressure is non-zero
-    processPressure(mapper, RAW_PRESSURE_MAX);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // up when pressure becomes 0, hover restored
-    processPressure(mapper, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // exit hover when pointer goes away
-    processUp(mapper);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-}
-
-
-// --- MultiTouchInputMapperTest ---
-
-class MultiTouchInputMapperTest : public TouchInputMapperTest {
-protected:
-    void prepareAxes(int axes);
-
-    void processPosition(MultiTouchInputMapper* mapper, int32_t x, int32_t y);
-    void processTouchMajor(MultiTouchInputMapper* mapper, int32_t touchMajor);
-    void processTouchMinor(MultiTouchInputMapper* mapper, int32_t touchMinor);
-    void processToolMajor(MultiTouchInputMapper* mapper, int32_t toolMajor);
-    void processToolMinor(MultiTouchInputMapper* mapper, int32_t toolMinor);
-    void processOrientation(MultiTouchInputMapper* mapper, int32_t orientation);
-    void processPressure(MultiTouchInputMapper* mapper, int32_t pressure);
-    void processDistance(MultiTouchInputMapper* mapper, int32_t distance);
-    void processId(MultiTouchInputMapper* mapper, int32_t id);
-    void processSlot(MultiTouchInputMapper* mapper, int32_t slot);
-    void processToolType(MultiTouchInputMapper* mapper, int32_t toolType);
-    void processKey(MultiTouchInputMapper* mapper, int32_t code, int32_t value);
-    void processMTSync(MultiTouchInputMapper* mapper);
-    void processSync(MultiTouchInputMapper* mapper);
-};
-
-void MultiTouchInputMapperTest::prepareAxes(int axes) {
-    if (axes & POSITION) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_X,
-                RAW_X_MIN, RAW_X_MAX, 0, 0);
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_POSITION_Y,
-                RAW_Y_MIN, RAW_Y_MAX, 0, 0);
-    }
-    if (axes & TOUCH) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MAJOR,
-                RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0);
-        if (axes & MINOR) {
-            mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOUCH_MINOR,
-                    RAW_TOUCH_MIN, RAW_TOUCH_MAX, 0, 0);
-        }
-    }
-    if (axes & TOOL) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MAJOR,
-                RAW_TOOL_MIN, RAW_TOOL_MAX, 0, 0);
-        if (axes & MINOR) {
-            mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_WIDTH_MINOR,
-                    RAW_TOOL_MAX, RAW_TOOL_MAX, 0, 0);
-        }
-    }
-    if (axes & ORIENTATION) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_ORIENTATION,
-                RAW_ORIENTATION_MIN, RAW_ORIENTATION_MAX, 0, 0);
-    }
-    if (axes & PRESSURE) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_PRESSURE,
-                RAW_PRESSURE_MIN, RAW_PRESSURE_MAX, 0, 0);
-    }
-    if (axes & DISTANCE) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_DISTANCE,
-                RAW_DISTANCE_MIN, RAW_DISTANCE_MAX, 0, 0);
-    }
-    if (axes & ID) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TRACKING_ID,
-                RAW_ID_MIN, RAW_ID_MAX, 0, 0);
-    }
-    if (axes & SLOT) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_SLOT,
-                RAW_SLOT_MIN, RAW_SLOT_MAX, 0, 0);
-        mFakeEventHub->setAbsoluteAxisValue(DEVICE_ID, ABS_MT_SLOT, 0);
-    }
-    if (axes & TOOL_TYPE) {
-        mFakeEventHub->addAbsoluteAxis(DEVICE_ID, ABS_MT_TOOL_TYPE,
-                0, MT_TOOL_MAX, 0, 0);
-    }
-}
-
-void MultiTouchInputMapperTest::processPosition(
-        MultiTouchInputMapper* mapper, int32_t x, int32_t y) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_X, x);
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_POSITION_Y, y);
-}
-
-void MultiTouchInputMapperTest::processTouchMajor(
-        MultiTouchInputMapper* mapper, int32_t touchMajor) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MAJOR, touchMajor);
-}
-
-void MultiTouchInputMapperTest::processTouchMinor(
-        MultiTouchInputMapper* mapper, int32_t touchMinor) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOUCH_MINOR, touchMinor);
-}
-
-void MultiTouchInputMapperTest::processToolMajor(
-        MultiTouchInputMapper* mapper, int32_t toolMajor) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MAJOR, toolMajor);
-}
-
-void MultiTouchInputMapperTest::processToolMinor(
-        MultiTouchInputMapper* mapper, int32_t toolMinor) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_WIDTH_MINOR, toolMinor);
-}
-
-void MultiTouchInputMapperTest::processOrientation(
-        MultiTouchInputMapper* mapper, int32_t orientation) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_ORIENTATION, orientation);
-}
-
-void MultiTouchInputMapperTest::processPressure(
-        MultiTouchInputMapper* mapper, int32_t pressure) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_PRESSURE, pressure);
-}
-
-void MultiTouchInputMapperTest::processDistance(
-        MultiTouchInputMapper* mapper, int32_t distance) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_DISTANCE, distance);
-}
-
-void MultiTouchInputMapperTest::processId(
-        MultiTouchInputMapper* mapper, int32_t id) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TRACKING_ID, id);
-}
-
-void MultiTouchInputMapperTest::processSlot(
-        MultiTouchInputMapper* mapper, int32_t slot) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_SLOT, slot);
-}
-
-void MultiTouchInputMapperTest::processToolType(
-        MultiTouchInputMapper* mapper, int32_t toolType) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_ABS, ABS_MT_TOOL_TYPE, toolType);
-}
-
-void MultiTouchInputMapperTest::processKey(
-        MultiTouchInputMapper* mapper, int32_t code, int32_t value) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_KEY, code, value);
-}
-
-void MultiTouchInputMapperTest::processMTSync(MultiTouchInputMapper* mapper) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_MT_REPORT, 0);
-}
-
-void MultiTouchInputMapperTest::processSync(MultiTouchInputMapper* mapper) {
-    process(mapper, ARBITRARY_TIME, DEVICE_ID, EV_SYN, SYN_REPORT, 0);
-}
-
-
-TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithoutTrackingIds) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyMotionArgs motionArgs;
-
-    // Two fingers down at once.
-    int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
-    processPosition(mapper, x1, y1);
-    processMTSync(mapper);
-    processPosition(mapper, x2, y2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Move.
-    x1 += 10; y1 += 15; x2 += 5; y2 -= 10;
-    processPosition(mapper, x1, y1);
-    processMTSync(mapper);
-    processPosition(mapper, x2, y2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // First finger up.
-    x2 += 15; y2 -= 20;
-    processPosition(mapper, x2, y2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Move.
-    x2 += 20; y2 -= 25;
-    processPosition(mapper, x2, y2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // New finger down.
-    int32_t x3 = 700, y3 = 300;
-    processPosition(mapper, x2, y2);
-    processMTSync(mapper);
-    processPosition(mapper, x3, y3);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Second finger up.
-    x3 += 30; y3 -= 20;
-    processPosition(mapper, x3, y3);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Last finger up.
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.eventTime);
-    ASSERT_EQ(DEVICE_ID, motionArgs.deviceId);
-    ASSERT_EQ(AINPUT_SOURCE_TOUCHSCREEN, motionArgs.source);
-    ASSERT_EQ(uint32_t(0), motionArgs.policyFlags);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.flags);
-    ASSERT_EQ(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON, motionArgs.metaState);
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(0, motionArgs.edgeFlags);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NEAR(X_PRECISION, motionArgs.xPrecision, EPSILON);
-    ASSERT_NEAR(Y_PRECISION, motionArgs.yPrecision, EPSILON);
-    ASSERT_EQ(ARBITRARY_TIME, motionArgs.downTime);
-
-    // Should not have sent any more keys or motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithTrackingIds) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | ID);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyMotionArgs motionArgs;
-
-    // Two fingers down at once.
-    int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
-    processPosition(mapper, x1, y1);
-    processId(mapper, 1);
-    processMTSync(mapper);
-    processPosition(mapper, x2, y2);
-    processId(mapper, 2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Move.
-    x1 += 10; y1 += 15; x2 += 5; y2 -= 10;
-    processPosition(mapper, x1, y1);
-    processId(mapper, 1);
-    processMTSync(mapper);
-    processPosition(mapper, x2, y2);
-    processId(mapper, 2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // First finger up.
-    x2 += 15; y2 -= 20;
-    processPosition(mapper, x2, y2);
-    processId(mapper, 2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Move.
-    x2 += 20; y2 -= 25;
-    processPosition(mapper, x2, y2);
-    processId(mapper, 2);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // New finger down.
-    int32_t x3 = 700, y3 = 300;
-    processPosition(mapper, x2, y2);
-    processId(mapper, 2);
-    processMTSync(mapper);
-    processPosition(mapper, x3, y3);
-    processId(mapper, 3);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Second finger up.
-    x3 += 30; y3 -= 20;
-    processPosition(mapper, x3, y3);
-    processId(mapper, 3);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Last finger up.
-    processMTSync(mapper);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Should not have sent any more keys or motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_NormalMultiTouchGesture_WithSlots) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | ID | SLOT);
-    prepareVirtualKeys();
-    addMapperAndConfigure(mapper);
-
-    mFakeContext->setGlobalMetaState(AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_ON);
-
-    NotifyMotionArgs motionArgs;
-
-    // Two fingers down at once.
-    int32_t x1 = 100, y1 = 125, x2 = 300, y2 = 500;
-    processPosition(mapper, x1, y1);
-    processId(mapper, 1);
-    processSlot(mapper, 1);
-    processPosition(mapper, x2, y2);
-    processId(mapper, 2);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Move.
-    x1 += 10; y1 += 15; x2 += 5; y2 -= 10;
-    processSlot(mapper, 0);
-    processPosition(mapper, x1, y1);
-    processSlot(mapper, 1);
-    processPosition(mapper, x2, y2);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // First finger up.
-    x2 += 15; y2 -= 20;
-    processSlot(mapper, 0);
-    processId(mapper, -1);
-    processSlot(mapper, 1);
-    processPosition(mapper, x2, y2);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x1), toDisplayY(y1), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Move.
-    x2 += 20; y2 -= 25;
-    processPosition(mapper, x2, y2);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(1, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // New finger down.
-    int32_t x3 = 700, y3 = 300;
-    processPosition(mapper, x2, y2);
-    processSlot(mapper, 0);
-    processId(mapper, 3);
-    processPosition(mapper, x3, y3);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Second finger up.
-    x3 += 30; y3 -= 20;
-    processSlot(mapper, 1);
-    processId(mapper, -1);
-    processSlot(mapper, 0);
-    processPosition(mapper, x3, y3);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            motionArgs.action);
-    ASSERT_EQ(size_t(2), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_EQ(1, motionArgs.pointerProperties[1].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[1].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[1],
-            toDisplayX(x2), toDisplayY(y2), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Last finger up.
-    processId(mapper, -1);
-    processSync(mapper);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(size_t(1), motionArgs.pointerCount);
-    ASSERT_EQ(0, motionArgs.pointerProperties[0].id);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(x3), toDisplayY(y3), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // Should not have sent any more keys or motions.
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasNotCalled());
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_AllAxes_WithDefaultCalibration) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | TOUCH | TOOL | PRESSURE | ORIENTATION | ID | MINOR | DISTANCE);
-    addMapperAndConfigure(mapper);
-
-    // These calculations are based on the input device calibration documentation.
-    int32_t rawX = 100;
-    int32_t rawY = 200;
-    int32_t rawTouchMajor = 7;
-    int32_t rawTouchMinor = 6;
-    int32_t rawToolMajor = 9;
-    int32_t rawToolMinor = 8;
-    int32_t rawPressure = 11;
-    int32_t rawDistance = 0;
-    int32_t rawOrientation = 3;
-    int32_t id = 5;
-
-    float x = toDisplayX(rawX);
-    float y = toDisplayY(rawY);
-    float pressure = float(rawPressure) / RAW_PRESSURE_MAX;
-    float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX;
-    float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE;
-    float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE;
-    float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE;
-    float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE;
-    float orientation = float(rawOrientation) / RAW_ORIENTATION_MAX * M_PI_2;
-    float distance = float(rawDistance);
-
-    processPosition(mapper, rawX, rawY);
-    processTouchMajor(mapper, rawTouchMajor);
-    processTouchMinor(mapper, rawTouchMinor);
-    processToolMajor(mapper, rawToolMajor);
-    processToolMinor(mapper, rawToolMinor);
-    processPressure(mapper, rawPressure);
-    processOrientation(mapper, rawOrientation);
-    processDistance(mapper, rawDistance);
-    processId(mapper, id);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    NotifyMotionArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(0, args.pointerProperties[0].id);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            x, y, pressure, size, touchMajor, touchMinor, toolMajor, toolMinor,
-            orientation, distance));
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_GeometricCalibration) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | TOUCH | TOOL | MINOR);
-    addConfigurationProperty("touch.size.calibration", "geometric");
-    addMapperAndConfigure(mapper);
-
-    // These calculations are based on the input device calibration documentation.
-    int32_t rawX = 100;
-    int32_t rawY = 200;
-    int32_t rawTouchMajor = 140;
-    int32_t rawTouchMinor = 120;
-    int32_t rawToolMajor = 180;
-    int32_t rawToolMinor = 160;
-
-    float x = toDisplayX(rawX);
-    float y = toDisplayY(rawY);
-    float size = avg(rawTouchMajor, rawTouchMinor) / RAW_TOUCH_MAX;
-    float toolMajor = float(rawToolMajor) * GEOMETRIC_SCALE;
-    float toolMinor = float(rawToolMinor) * GEOMETRIC_SCALE;
-    float touchMajor = float(rawTouchMajor) * GEOMETRIC_SCALE;
-    float touchMinor = float(rawTouchMinor) * GEOMETRIC_SCALE;
-
-    processPosition(mapper, rawX, rawY);
-    processTouchMajor(mapper, rawTouchMajor);
-    processTouchMinor(mapper, rawTouchMinor);
-    processToolMajor(mapper, rawToolMajor);
-    processToolMinor(mapper, rawToolMinor);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    NotifyMotionArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            x, y, 1.0f, size, touchMajor, touchMinor, toolMajor, toolMinor, 0, 0));
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_SummedLinearCalibration) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | TOUCH | TOOL);
-    addConfigurationProperty("touch.size.calibration", "diameter");
-    addConfigurationProperty("touch.size.scale", "10");
-    addConfigurationProperty("touch.size.bias", "160");
-    addConfigurationProperty("touch.size.isSummed", "1");
-    addMapperAndConfigure(mapper);
-
-    // These calculations are based on the input device calibration documentation.
-    // Note: We only provide a single common touch/tool value because the device is assumed
-    //       not to emit separate values for each pointer (isSummed = 1).
-    int32_t rawX = 100;
-    int32_t rawY = 200;
-    int32_t rawX2 = 150;
-    int32_t rawY2 = 250;
-    int32_t rawTouchMajor = 5;
-    int32_t rawToolMajor = 8;
-
-    float x = toDisplayX(rawX);
-    float y = toDisplayY(rawY);
-    float x2 = toDisplayX(rawX2);
-    float y2 = toDisplayY(rawY2);
-    float size = float(rawTouchMajor) / 2 / RAW_TOUCH_MAX;
-    float touch = float(rawTouchMajor) / 2 * 10.0f + 160.0f;
-    float tool = float(rawToolMajor) / 2 * 10.0f + 160.0f;
-
-    processPosition(mapper, rawX, rawY);
-    processTouchMajor(mapper, rawTouchMajor);
-    processToolMajor(mapper, rawToolMajor);
-    processMTSync(mapper);
-    processPosition(mapper, rawX2, rawY2);
-    processTouchMajor(mapper, rawTouchMajor);
-    processToolMajor(mapper, rawToolMajor);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    NotifyMotionArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, args.action);
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
-            args.action);
-    ASSERT_EQ(size_t(2), args.pointerCount);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            x, y, 1.0f, size, touch, touch, tool, tool, 0, 0));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[1],
-            x2, y2, 1.0f, size, touch, touch, tool, tool, 0, 0));
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_TouchAndToolAxes_AreaCalibration) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | TOUCH | TOOL);
-    addConfigurationProperty("touch.size.calibration", "area");
-    addConfigurationProperty("touch.size.scale", "43");
-    addConfigurationProperty("touch.size.bias", "3");
-    addMapperAndConfigure(mapper);
-
-    // These calculations are based on the input device calibration documentation.
-    int32_t rawX = 100;
-    int32_t rawY = 200;
-    int32_t rawTouchMajor = 5;
-    int32_t rawToolMajor = 8;
-
-    float x = toDisplayX(rawX);
-    float y = toDisplayY(rawY);
-    float size = float(rawTouchMajor) / RAW_TOUCH_MAX;
-    float touch = sqrtf(rawTouchMajor) * 43.0f + 3.0f;
-    float tool = sqrtf(rawToolMajor) * 43.0f + 3.0f;
-
-    processPosition(mapper, rawX, rawY);
-    processTouchMajor(mapper, rawTouchMajor);
-    processToolMajor(mapper, rawToolMajor);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    NotifyMotionArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            x, y, 1.0f, size, touch, touch, tool, tool, 0, 0));
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | PRESSURE);
-    addConfigurationProperty("touch.pressure.calibration", "amplitude");
-    addConfigurationProperty("touch.pressure.scale", "0.01");
-    addMapperAndConfigure(mapper);
-
-    // These calculations are based on the input device calibration documentation.
-    int32_t rawX = 100;
-    int32_t rawY = 200;
-    int32_t rawPressure = 60;
-
-    float x = toDisplayX(rawX);
-    float y = toDisplayY(rawY);
-    float pressure = float(rawPressure) * 0.01f;
-
-    processPosition(mapper, rawX, rawY);
-    processPressure(mapper, rawPressure);
-    processMTSync(mapper);
-    processSync(mapper);
-
-    NotifyMotionArgs args;
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(args.pointerCoords[0],
-            x, y, pressure, 0, 0, 0, 0, 0, 0, 0));
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllButtons) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | ID | SLOT);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-    NotifyKeyArgs keyArgs;
-
-    processId(mapper, 1);
-    processPosition(mapper, 100, 200);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.buttonState);
-
-    // press BTN_LEFT, release BTN_LEFT
-    processKey(mapper, BTN_LEFT, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_PRIMARY, motionArgs.buttonState);
-
-    processKey(mapper, BTN_LEFT, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // press BTN_RIGHT + BTN_MIDDLE, release BTN_RIGHT, release BTN_MIDDLE
-    processKey(mapper, BTN_RIGHT, 1);
-    processKey(mapper, BTN_MIDDLE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY | AMOTION_EVENT_BUTTON_TERTIARY,
-            motionArgs.buttonState);
-
-    processKey(mapper, BTN_RIGHT, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_MIDDLE, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // press BTN_BACK, release BTN_BACK
-    processKey(mapper, BTN_BACK, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_BACK, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-
-    // press BTN_SIDE, release BTN_SIDE
-    processKey(mapper, BTN_SIDE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_BACK, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_SIDE, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_BACK, keyArgs.keyCode);
-
-    // press BTN_FORWARD, release BTN_FORWARD
-    processKey(mapper, BTN_FORWARD, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_FORWARD, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-
-    // press BTN_EXTRA, release BTN_EXTRA
-    processKey(mapper, BTN_EXTRA, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_DOWN, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_FORWARD, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    processKey(mapper, BTN_EXTRA, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyKeyWasCalled(&keyArgs));
-    ASSERT_EQ(AKEY_EVENT_ACTION_UP, keyArgs.action);
-    ASSERT_EQ(AKEYCODE_FORWARD, keyArgs.keyCode);
-
-    // press BTN_STYLUS, release BTN_STYLUS
-    processKey(mapper, BTN_STYLUS, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_SECONDARY, motionArgs.buttonState);
-
-    processKey(mapper, BTN_STYLUS, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // press BTN_STYLUS2, release BTN_STYLUS2
-    processKey(mapper, BTN_STYLUS2, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_BUTTON_TERTIARY, motionArgs.buttonState);
-
-    processKey(mapper, BTN_STYLUS2, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(0, motionArgs.buttonState);
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-
-    // release touch
-    processId(mapper, -1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_EQ(0, motionArgs.buttonState);
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_ShouldHandleAllToolTypes) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | ID | SLOT | TOOL_TYPE);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-
-    // default tool type is finger
-    processId(mapper, 1);
-    processPosition(mapper, 100, 200);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // eraser
-    processKey(mapper, BTN_TOOL_RUBBER, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
-
-    // stylus
-    processKey(mapper, BTN_TOOL_RUBBER, 0);
-    processKey(mapper, BTN_TOOL_PEN, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // brush
-    processKey(mapper, BTN_TOOL_PEN, 0);
-    processKey(mapper, BTN_TOOL_BRUSH, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // pencil
-    processKey(mapper, BTN_TOOL_BRUSH, 0);
-    processKey(mapper, BTN_TOOL_PENCIL, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // airbrush
-    processKey(mapper, BTN_TOOL_PENCIL, 0);
-    processKey(mapper, BTN_TOOL_AIRBRUSH, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // mouse
-    processKey(mapper, BTN_TOOL_AIRBRUSH, 0);
-    processKey(mapper, BTN_TOOL_MOUSE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
-
-    // lens
-    processKey(mapper, BTN_TOOL_MOUSE, 0);
-    processKey(mapper, BTN_TOOL_LENS, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
-
-    // double-tap
-    processKey(mapper, BTN_TOOL_LENS, 0);
-    processKey(mapper, BTN_TOOL_DOUBLETAP, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // triple-tap
-    processKey(mapper, BTN_TOOL_DOUBLETAP, 0);
-    processKey(mapper, BTN_TOOL_TRIPLETAP, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // quad-tap
-    processKey(mapper, BTN_TOOL_TRIPLETAP, 0);
-    processKey(mapper, BTN_TOOL_QUADTAP, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // finger
-    processKey(mapper, BTN_TOOL_QUADTAP, 0);
-    processKey(mapper, BTN_TOOL_FINGER, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // stylus trumps finger
-    processKey(mapper, BTN_TOOL_PEN, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // eraser trumps stylus
-    processKey(mapper, BTN_TOOL_RUBBER, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_ERASER, motionArgs.pointerProperties[0].toolType);
-
-    // mouse trumps eraser
-    processKey(mapper, BTN_TOOL_MOUSE, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_MOUSE, motionArgs.pointerProperties[0].toolType);
-
-    // MT tool type trumps BTN tool types: MT_TOOL_FINGER
-    processToolType(mapper, MT_TOOL_FINGER); // this is the first time we send MT_TOOL_TYPE
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-
-    // MT tool type trumps BTN tool types: MT_TOOL_PEN
-    processToolType(mapper, MT_TOOL_PEN);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_STYLUS, motionArgs.pointerProperties[0].toolType);
-
-    // back to default tool type
-    processToolType(mapper, -1); // use a deliberately undefined tool type, for testing
-    processKey(mapper, BTN_TOOL_MOUSE, 0);
-    processKey(mapper, BTN_TOOL_RUBBER, 0);
-    processKey(mapper, BTN_TOOL_PEN, 0);
-    processKey(mapper, BTN_TOOL_FINGER, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, motionArgs.action);
-    ASSERT_EQ(AMOTION_EVENT_TOOL_TYPE_FINGER, motionArgs.pointerProperties[0].toolType);
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_WhenBtnTouchPresent_HoversIfItsValueIsZero) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | ID | SLOT);
-    mFakeEventHub->addKey(DEVICE_ID, BTN_TOUCH, 0, AKEYCODE_UNKNOWN, 0);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-
-    // initially hovering because BTN_TOUCH not sent yet, pressure defaults to 0
-    processId(mapper, 1);
-    processPosition(mapper, 100, 200);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // move a little
-    processPosition(mapper, 150, 250);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // down when BTN_TOUCH is pressed, pressure defaults to 1
-    processKey(mapper, BTN_TOUCH, 1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // up when BTN_TOUCH is released, hover restored
-    processKey(mapper, BTN_TOUCH, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // exit hover when pointer goes away
-    processId(mapper, -1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-}
-
-TEST_F(MultiTouchInputMapperTest, Process_WhenAbsMTPressureIsPresent_HoversIfItsValueIsZero) {
-    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
-    addConfigurationProperty("touch.deviceType", "touchScreen");
-    prepareDisplay(DISPLAY_ORIENTATION_0);
-    prepareAxes(POSITION | ID | SLOT | PRESSURE);
-    addMapperAndConfigure(mapper);
-
-    NotifyMotionArgs motionArgs;
-
-    // initially hovering because pressure is 0
-    processId(mapper, 1);
-    processPosition(mapper, 100, 200);
-    processPressure(mapper, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(100), toDisplayY(200), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // move a little
-    processPosition(mapper, 150, 250);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // down when pressure becomes non-zero
-    processPressure(mapper, RAW_PRESSURE_MAX);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_DOWN, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    // up when pressure becomes 0, hover restored
-    processPressure(mapper, 0);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_UP, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 1, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_ENTER, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_MOVE, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-
-    // exit hover when pointer goes away
-    processId(mapper, -1);
-    processSync(mapper);
-    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&motionArgs));
-    ASSERT_EQ(AMOTION_EVENT_ACTION_HOVER_EXIT, motionArgs.action);
-    ASSERT_NO_FATAL_FAILURE(assertPointerCoords(motionArgs.pointerCoords[0],
-            toDisplayX(150), toDisplayY(250), 0, 0, 0, 0, 0, 0, 0, 0));
-}
-
-
-} // namespace android
diff --git a/services/java/Android.mk b/services/java/Android.mk
deleted file mode 100644
index 8c3d0f0..0000000
--- a/services/java/Android.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-# the library
-# ============================================================
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-            $(call all-subdir-java-files) \
-	    com/android/server/EventLogTags.logtags \
-	    com/android/server/am/EventLogTags.logtags
-
-LOCAL_MODULE:= services
-
-LOCAL_JAVA_LIBRARIES := android.policy conscrypt telephony-common
-
-include $(BUILD_JAVA_LIBRARY)
-
-include $(BUILD_DROIDDOC)
diff --git a/services/java/com/android/server/AlarmManagerService.java b/services/java/com/android/server/AlarmManagerService.java
deleted file mode 100644
index 5ae9a6d..0000000
--- a/services/java/com/android/server/AlarmManagerService.java
+++ /dev/null
@@ -1,1498 +0,0 @@
-/*
- * Copyright (C) 2006 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;
-
-import android.app.Activity;
-import android.app.ActivityManagerNative;
-import android.app.AlarmManager;
-import android.app.IAlarmManager;
-import android.app.PendingIntent;
-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.net.Uri;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.PowerManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.os.WorkSource;
-import android.text.TextUtils;
-import android.util.Pair;
-import android.util.Slog;
-import android.util.TimeUtils;
-
-import java.io.ByteArrayOutputStream;
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.TimeZone;
-
-import static android.app.AlarmManager.RTC_WAKEUP;
-import static android.app.AlarmManager.RTC;
-import static android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP;
-import static android.app.AlarmManager.ELAPSED_REALTIME;
-
-import com.android.internal.util.LocalLog;
-
-class AlarmManagerService extends IAlarmManager.Stub {
-    // The threshold for how long an alarm can be late before we print a
-    // warning message.  The time duration is in milliseconds.
-    private static final long LATE_ALARM_THRESHOLD = 10 * 1000;
-
-    private static final int RTC_WAKEUP_MASK = 1 << RTC_WAKEUP;
-    private static final int RTC_MASK = 1 << RTC;
-    private static final int ELAPSED_REALTIME_WAKEUP_MASK = 1 << ELAPSED_REALTIME_WAKEUP; 
-    private static final int ELAPSED_REALTIME_MASK = 1 << ELAPSED_REALTIME;
-    private static final int TIME_CHANGED_MASK = 1 << 16;
-    private static final int IS_WAKEUP_MASK = RTC_WAKEUP_MASK|ELAPSED_REALTIME_WAKEUP_MASK;
-
-    // Mask for testing whether a given alarm type is wakeup vs non-wakeup
-    private static final int TYPE_NONWAKEUP_MASK = 0x1; // low bit => non-wakeup
-
-    private static final String TAG = "AlarmManager";
-    private static final String ClockReceiver_TAG = "ClockReceiver";
-    private static final boolean localLOGV = false;
-    private static final boolean DEBUG_BATCH = localLOGV || false;
-    private static final boolean DEBUG_VALIDATE = localLOGV || false;
-    private static final int ALARM_EVENT = 1;
-    private static final String TIMEZONE_PROPERTY = "persist.sys.timezone";
-    
-    private static final Intent mBackgroundIntent
-            = new Intent().addFlags(Intent.FLAG_FROM_BACKGROUND);
-    private static final IncreasingTimeOrder sIncreasingTimeOrder = new IncreasingTimeOrder();
-    
-    private static final boolean WAKEUP_STATS = false;
-
-    private final Context mContext;
-
-    private final LocalLog mLog = new LocalLog(TAG);
-
-    private Object mLock = new Object();
-
-    private int mDescriptor;
-    private long mNextWakeup;
-    private long mNextNonWakeup;
-    private int mBroadcastRefCount = 0;
-    private PowerManager.WakeLock mWakeLock;
-    private ArrayList<InFlight> mInFlight = new ArrayList<InFlight>();
-    private final AlarmThread mWaitThread = new AlarmThread();
-    private final AlarmHandler mHandler = new AlarmHandler();
-    private ClockReceiver mClockReceiver;
-    private UninstallReceiver mUninstallReceiver;
-    private final ResultReceiver mResultReceiver = new ResultReceiver();
-    private final PendingIntent mTimeTickSender;
-    private final PendingIntent mDateChangeSender;
-
-    class WakeupEvent {
-        public long when;
-        public int uid;
-        public String action;
-
-        public WakeupEvent(long theTime, int theUid, String theAction) {
-            when = theTime;
-            uid = theUid;
-            action = theAction;
-        }
-    }
-
-    private final LinkedList<WakeupEvent> mRecentWakeups = new LinkedList<WakeupEvent>();
-    private final long RECENT_WAKEUP_PERIOD = 1000L * 60 * 60 * 24; // one day
-
-    static final class Batch {
-        long start;     // These endpoints are always in ELAPSED
-        long end;
-        boolean standalone; // certain "batches" don't participate in coalescing
-
-        final ArrayList<Alarm> alarms = new ArrayList<Alarm>();
-
-        Batch() {
-            start = 0;
-            end = Long.MAX_VALUE;
-        }
-
-        Batch(Alarm seed) {
-            start = seed.whenElapsed;
-            end = seed.maxWhen;
-            alarms.add(seed);
-        }
-
-        int size() {
-            return alarms.size();
-        }
-
-        Alarm get(int index) {
-            return alarms.get(index);
-        }
-
-        boolean canHold(long whenElapsed, long maxWhen) {
-            return (end >= whenElapsed) && (start <= maxWhen);
-        }
-
-        boolean add(Alarm alarm) {
-            boolean newStart = false;
-            // narrows the batch if necessary; presumes that canHold(alarm) is true
-            int index = Collections.binarySearch(alarms, alarm, sIncreasingTimeOrder);
-            if (index < 0) {
-                index = 0 - index - 1;
-            }
-            alarms.add(index, alarm);
-            if (DEBUG_BATCH) {
-                Slog.v(TAG, "Adding " + alarm + " to " + this);
-            }
-            if (alarm.whenElapsed > start) {
-                start = alarm.whenElapsed;
-                newStart = true;
-            }
-            if (alarm.maxWhen < end) {
-                end = alarm.maxWhen;
-            }
-
-            if (DEBUG_BATCH) {
-                Slog.v(TAG, "    => now " + this);
-            }
-            return newStart;
-        }
-
-        boolean remove(final PendingIntent operation) {
-            boolean didRemove = false;
-            long newStart = 0;  // recalculate endpoints as we go
-            long newEnd = Long.MAX_VALUE;
-            for (int i = 0; i < alarms.size(); ) {
-                Alarm alarm = alarms.get(i);
-                if (alarm.operation.equals(operation)) {
-                    alarms.remove(i);
-                    didRemove = true;
-                } else {
-                    if (alarm.whenElapsed > newStart) {
-                        newStart = alarm.whenElapsed;
-                    }
-                    if (alarm.maxWhen < newEnd) {
-                        newEnd = alarm.maxWhen;
-                    }
-                    i++;
-                }
-            }
-            if (didRemove) {
-                // commit the new batch bounds
-                start = newStart;
-                end = newEnd;
-            }
-            return didRemove;
-        }
-
-        boolean remove(final String packageName) {
-            boolean didRemove = false;
-            long newStart = 0;  // recalculate endpoints as we go
-            long newEnd = Long.MAX_VALUE;
-            for (int i = 0; i < alarms.size(); ) {
-                Alarm alarm = alarms.get(i);
-                if (alarm.operation.getTargetPackage().equals(packageName)) {
-                    alarms.remove(i);
-                    didRemove = true;
-                } else {
-                    if (alarm.whenElapsed > newStart) {
-                        newStart = alarm.whenElapsed;
-                    }
-                    if (alarm.maxWhen < newEnd) {
-                        newEnd = alarm.maxWhen;
-                    }
-                    i++;
-                }
-            }
-            if (didRemove) {
-                // commit the new batch bounds
-                start = newStart;
-                end = newEnd;
-            }
-            return didRemove;
-        }
-
-        boolean remove(final int userHandle) {
-            boolean didRemove = false;
-            long newStart = 0;  // recalculate endpoints as we go
-            long newEnd = Long.MAX_VALUE;
-            for (int i = 0; i < alarms.size(); ) {
-                Alarm alarm = alarms.get(i);
-                if (UserHandle.getUserId(alarm.operation.getCreatorUid()) == userHandle) {
-                    alarms.remove(i);
-                    didRemove = true;
-                } else {
-                    if (alarm.whenElapsed > newStart) {
-                        newStart = alarm.whenElapsed;
-                    }
-                    if (alarm.maxWhen < newEnd) {
-                        newEnd = alarm.maxWhen;
-                    }
-                    i++;
-                }
-            }
-            if (didRemove) {
-                // commit the new batch bounds
-                start = newStart;
-                end = newEnd;
-            }
-            return didRemove;
-        }
-
-        boolean hasPackage(final String packageName) {
-            final int N = alarms.size();
-            for (int i = 0; i < N; i++) {
-                Alarm a = alarms.get(i);
-                if (a.operation.getTargetPackage().equals(packageName)) {
-                    return true;
-                }
-            }
-            return false;
-        }
-
-        boolean hasWakeups() {
-            final int N = alarms.size();
-            for (int i = 0; i < N; i++) {
-                Alarm a = alarms.get(i);
-                // non-wakeup alarms are types 1 and 3, i.e. have the low bit set
-                if ((a.type & TYPE_NONWAKEUP_MASK) == 0) {
-                    return true;
-                }
-            }
-            return false;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder b = new StringBuilder(40);
-            b.append("Batch{"); b.append(Integer.toHexString(this.hashCode()));
-            b.append(" num="); b.append(size());
-            b.append(" start="); b.append(start);
-            b.append(" end="); b.append(end);
-            if (standalone) {
-                b.append(" STANDALONE");
-            }
-            b.append('}');
-            return b.toString();
-        }
-    }
-
-    static class BatchTimeOrder implements Comparator<Batch> {
-        public int compare(Batch b1, Batch b2) {
-            long when1 = b1.start;
-            long when2 = b2.start;
-            if (when1 - when2 > 0) {
-                return 1;
-            }
-            if (when1 - when2 < 0) {
-                return -1;
-            }
-            return 0;
-        }
-    }
-    
-    // minimum recurrence period or alarm futurity for us to be able to fuzz it
-    private static final long MIN_FUZZABLE_INTERVAL = 10000;
-    private static final BatchTimeOrder sBatchOrder = new BatchTimeOrder();
-    private final ArrayList<Batch> mAlarmBatches = new ArrayList<Batch>();
-
-    static long convertToElapsed(long when, int type) {
-        final boolean isRtc = (type == RTC || type == RTC_WAKEUP);
-        if (isRtc) {
-            when -= System.currentTimeMillis() - SystemClock.elapsedRealtime();
-        }
-        return when;
-    }
-
-    // Apply a heuristic to { recurrence interval, futurity of the trigger time } to
-    // calculate the end of our nominal delivery window for the alarm.
-    static long maxTriggerTime(long now, long triggerAtTime, long interval) {
-        // Current heuristic: batchable window is 75% of either the recurrence interval
-        // [for a periodic alarm] or of the time from now to the desired delivery time,
-        // with a minimum delay/interval of 10 seconds, under which we will simply not
-        // defer the alarm.
-        long futurity = (interval == 0)
-                ? (triggerAtTime - now)
-                : interval;
-        if (futurity < MIN_FUZZABLE_INTERVAL) {
-            futurity = 0;
-        }
-        return triggerAtTime + (long)(.75 * futurity);
-    }
-
-    // returns true if the batch was added at the head
-    static boolean addBatchLocked(ArrayList<Batch> list, Batch newBatch) {
-        int index = Collections.binarySearch(list, newBatch, sBatchOrder);
-        if (index < 0) {
-            index = 0 - index - 1;
-        }
-        list.add(index, newBatch);
-        return (index == 0);
-    }
-
-    // Return the index of the matching batch, or -1 if none found.
-    int attemptCoalesceLocked(long whenElapsed, long maxWhen) {
-        final int N = mAlarmBatches.size();
-        for (int i = 0; i < N; i++) {
-            Batch b = mAlarmBatches.get(i);
-            if (!b.standalone && b.canHold(whenElapsed, maxWhen)) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    // The RTC clock has moved arbitrarily, so we need to recalculate all the batching
-    void rebatchAllAlarms() {
-        synchronized (mLock) {
-            rebatchAllAlarmsLocked(true);
-        }
-    }
-
-    void rebatchAllAlarmsLocked(boolean doValidate) {
-        ArrayList<Batch> oldSet = (ArrayList<Batch>) mAlarmBatches.clone();
-        mAlarmBatches.clear();
-        final long nowElapsed = SystemClock.elapsedRealtime();
-        final int oldBatches = oldSet.size();
-        for (int batchNum = 0; batchNum < oldBatches; batchNum++) {
-            Batch batch = oldSet.get(batchNum);
-            final int N = batch.size();
-            for (int i = 0; i < N; i++) {
-                Alarm a = batch.get(i);
-                long whenElapsed = convertToElapsed(a.when, a.type);
-                final long maxElapsed;
-                if (a.whenElapsed == a.maxWhen) {
-                    // Exact
-                    maxElapsed = whenElapsed;
-                } else {
-                    // Not exact.  Preserve any explicit window, otherwise recalculate
-                    // the window based on the alarm's new futurity.  Note that this
-                    // reflects a policy of preferring timely to deferred delivery.
-                    maxElapsed = (a.windowLength > 0)
-                            ? (whenElapsed + a.windowLength)
-                            : maxTriggerTime(nowElapsed, whenElapsed, a.repeatInterval);
-                }
-                setImplLocked(a.type, a.when, whenElapsed, a.windowLength, maxElapsed,
-                        a.repeatInterval, a.operation, batch.standalone, doValidate, a.workSource);
-            }
-        }
-    }
-
-    private static final class InFlight extends Intent {
-        final PendingIntent mPendingIntent;
-        final WorkSource mWorkSource;
-        final Pair<String, ComponentName> mTarget;
-        final BroadcastStats mBroadcastStats;
-        final FilterStats mFilterStats;
-
-        InFlight(AlarmManagerService service, PendingIntent pendingIntent, WorkSource workSource) {
-            mPendingIntent = pendingIntent;
-            mWorkSource = workSource;
-            Intent intent = pendingIntent.getIntent();
-            mTarget = intent != null
-                    ? new Pair<String, ComponentName>(intent.getAction(), intent.getComponent())
-                    : null;
-            mBroadcastStats = service.getStatsLocked(pendingIntent);
-            FilterStats fs = mBroadcastStats.filterStats.get(mTarget);
-            if (fs == null) {
-                fs = new FilterStats(mBroadcastStats, mTarget);
-                mBroadcastStats.filterStats.put(mTarget, fs);
-            }
-            mFilterStats = fs;
-        }
-    }
-
-    private static final class FilterStats {
-        final BroadcastStats mBroadcastStats;
-        final Pair<String, ComponentName> mTarget;
-
-        long aggregateTime;
-        int count;
-        int numWakeup;
-        long startTime;
-        int nesting;
-
-        FilterStats(BroadcastStats broadcastStats, Pair<String, ComponentName> target) {
-            mBroadcastStats = broadcastStats;
-            mTarget = target;
-        }
-    }
-    
-    private static final class BroadcastStats {
-        final String mPackageName;
-
-        long aggregateTime;
-        int count;
-        int numWakeup;
-        long startTime;
-        int nesting;
-        final HashMap<Pair<String, ComponentName>, FilterStats> filterStats
-                = new HashMap<Pair<String, ComponentName>, FilterStats>();
-
-        BroadcastStats(String packageName) {
-            mPackageName = packageName;
-        }
-    }
-    
-    private final HashMap<String, BroadcastStats> mBroadcastStats
-            = new HashMap<String, BroadcastStats>();
-    
-    public AlarmManagerService(Context context) {
-        mContext = context;
-        mDescriptor = init();
-        mNextWakeup = mNextNonWakeup = 0;
-
-        // We have to set current TimeZone info to kernel
-        // because kernel doesn't keep this after reboot
-        String tz = SystemProperties.get(TIMEZONE_PROPERTY);
-        if (tz != null) {
-            setTimeZone(tz);
-        }
-
-        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
-        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
-        
-        mTimeTickSender = PendingIntent.getBroadcastAsUser(context, 0,
-                new Intent(Intent.ACTION_TIME_TICK).addFlags(
-                        Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                        | Intent.FLAG_RECEIVER_FOREGROUND), 0,
-                        UserHandle.ALL);
-        Intent intent = new Intent(Intent.ACTION_DATE_CHANGED);
-        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-        mDateChangeSender = PendingIntent.getBroadcastAsUser(context, 0, intent,
-                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, UserHandle.ALL);
-        
-        // now that we have initied the driver schedule the alarm
-        mClockReceiver= new ClockReceiver();
-        mClockReceiver.scheduleTimeTickEvent();
-        mClockReceiver.scheduleDateChangedEvent();
-        mUninstallReceiver = new UninstallReceiver();
-        
-        if (mDescriptor != -1) {
-            mWaitThread.start();
-        } else {
-            Slog.w(TAG, "Failed to open alarm driver. Falling back to a handler.");
-        }
-    }
-    
-    protected void finalize() throws Throwable {
-        try {
-            close(mDescriptor);
-        } finally {
-            super.finalize();
-        }
-    }
-
-    @Override
-    public void set(int type, long triggerAtTime, long windowLength, long interval,
-            PendingIntent operation, WorkSource workSource) {
-        if (workSource != null) {
-            mContext.enforceCallingPermission(
-                    android.Manifest.permission.UPDATE_DEVICE_STATS,
-                    "AlarmManager.set");
-        }
-
-        set(type, triggerAtTime, windowLength, interval, operation, false, workSource);
-    }
-
-    public void set(int type, long triggerAtTime, long windowLength, long interval,
-            PendingIntent operation, boolean isStandalone, WorkSource workSource) {
-        if (operation == null) {
-            Slog.w(TAG, "set/setRepeating ignored because there is no intent");
-            return;
-        }
-
-        // Sanity check the window length.  This will catch people mistakenly
-        // trying to pass an end-of-window timestamp rather than a duration.
-        if (windowLength > AlarmManager.INTERVAL_HALF_DAY) {
-            Slog.w(TAG, "Window length " + windowLength
-                    + "ms suspiciously long; limiting to 1 hour");
-            windowLength = AlarmManager.INTERVAL_HOUR;
-        }
-
-        if (type < RTC_WAKEUP || type > ELAPSED_REALTIME) {
-            throw new IllegalArgumentException("Invalid alarm type " + type);
-        }
-
-        if (triggerAtTime < 0) {
-            final long who = Binder.getCallingUid();
-            final long what = Binder.getCallingPid();
-            Slog.w(TAG, "Invalid alarm trigger time! " + triggerAtTime + " from uid=" + who
-                    + " pid=" + what);
-            triggerAtTime = 0;
-        }
-
-        final long nowElapsed = SystemClock.elapsedRealtime();
-        final long triggerElapsed = convertToElapsed(triggerAtTime, type);
-        final long maxElapsed;
-        if (windowLength == AlarmManager.WINDOW_EXACT) {
-            maxElapsed = triggerElapsed;
-        } else if (windowLength < 0) {
-            maxElapsed = maxTriggerTime(nowElapsed, triggerElapsed, interval);
-        } else {
-            maxElapsed = triggerElapsed + windowLength;
-        }
-
-        synchronized (mLock) {
-            if (DEBUG_BATCH) {
-                Slog.v(TAG, "set(" + operation + ") : type=" + type
-                        + " triggerAtTime=" + triggerAtTime + " win=" + windowLength
-                        + " tElapsed=" + triggerElapsed + " maxElapsed=" + maxElapsed
-                        + " interval=" + interval + " standalone=" + isStandalone);
-            }
-            setImplLocked(type, triggerAtTime, triggerElapsed, windowLength, maxElapsed,
-                    interval, operation, isStandalone, true, workSource);
-        }
-    }
-
-    private void setImplLocked(int type, long when, long whenElapsed, long windowLength,
-            long maxWhen, long interval, PendingIntent operation, boolean isStandalone,
-            boolean doValidate, WorkSource workSource) {
-        Alarm a = new Alarm(type, when, whenElapsed, windowLength, maxWhen, interval,
-                operation, workSource);
-        removeLocked(operation);
-
-        int whichBatch = (isStandalone) ? -1 : attemptCoalesceLocked(whenElapsed, maxWhen);
-        if (whichBatch < 0) {
-            Batch batch = new Batch(a);
-            batch.standalone = isStandalone;
-            addBatchLocked(mAlarmBatches, batch);
-        } else {
-            Batch batch = mAlarmBatches.get(whichBatch);
-            if (batch.add(a)) {
-                // The start time of this batch advanced, so batch ordering may
-                // have just been broken.  Move it to where it now belongs.
-                mAlarmBatches.remove(whichBatch);
-                addBatchLocked(mAlarmBatches, batch);
-            }
-        }
-
-        if (DEBUG_VALIDATE) {
-            if (doValidate && !validateConsistencyLocked()) {
-                Slog.v(TAG, "Tipping-point operation: type=" + type + " when=" + when
-                        + " when(hex)=" + Long.toHexString(when)
-                        + " whenElapsed=" + whenElapsed + " maxWhen=" + maxWhen
-                        + " interval=" + interval + " op=" + operation
-                        + " standalone=" + isStandalone);
-                rebatchAllAlarmsLocked(false);
-            }
-        }
-
-        rescheduleKernelAlarmsLocked();
-    }
-
-    private void logBatchesLocked() {
-        ByteArrayOutputStream bs = new ByteArrayOutputStream(2048);
-        PrintWriter pw = new PrintWriter(bs);
-        final long nowRTC = System.currentTimeMillis();
-        final long nowELAPSED = SystemClock.elapsedRealtime();
-        final int NZ = mAlarmBatches.size();
-        for (int iz = 0; iz < NZ; iz++) {
-            Batch bz = mAlarmBatches.get(iz);
-            pw.append("Batch "); pw.print(iz); pw.append(": "); pw.println(bz);
-            dumpAlarmList(pw, bz.alarms, "  ", nowELAPSED, nowRTC);
-            pw.flush();
-            Slog.v(TAG, bs.toString());
-            bs.reset();
-        }
-    }
-
-    private boolean validateConsistencyLocked() {
-        if (DEBUG_VALIDATE) {
-            long lastTime = Long.MIN_VALUE;
-            final int N = mAlarmBatches.size();
-            for (int i = 0; i < N; i++) {
-                Batch b = mAlarmBatches.get(i);
-                if (b.start >= lastTime) {
-                    // duplicate start times are okay because of standalone batches
-                    lastTime = b.start;
-                } else {
-                    Slog.e(TAG, "CONSISTENCY FAILURE: Batch " + i + " is out of order");
-                    logBatchesLocked();
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-    private Batch findFirstWakeupBatchLocked() {
-        final int N = mAlarmBatches.size();
-        for (int i = 0; i < N; i++) {
-            Batch b = mAlarmBatches.get(i);
-            if (b.hasWakeups()) {
-                return b;
-            }
-        }
-        return null;
-    }
-
-    private void rescheduleKernelAlarmsLocked() {
-        // Schedule the next upcoming wakeup alarm.  If there is a deliverable batch
-        // prior to that which contains no wakeups, we schedule that as well.
-        if (mAlarmBatches.size() > 0) {
-            final Batch firstWakeup = findFirstWakeupBatchLocked();
-            final Batch firstBatch = mAlarmBatches.get(0);
-            if (firstWakeup != null && mNextWakeup != firstWakeup.start) {
-                mNextWakeup = firstWakeup.start;
-                setLocked(ELAPSED_REALTIME_WAKEUP, firstWakeup.start);
-            }
-            if (firstBatch != firstWakeup && mNextNonWakeup != firstBatch.start) {
-                mNextNonWakeup = firstBatch.start;
-                setLocked(ELAPSED_REALTIME, firstBatch.start);
-            }
-        }
-    }
-
-    public void setTime(long millis) {
-        mContext.enforceCallingOrSelfPermission(
-                "android.permission.SET_TIME",
-                "setTime");
-
-        SystemClock.setCurrentTimeMillis(millis);
-    }
-
-    public void setTimeZone(String tz) {
-        mContext.enforceCallingOrSelfPermission(
-                "android.permission.SET_TIME_ZONE",
-                "setTimeZone");
-
-        long oldId = Binder.clearCallingIdentity();
-        try {
-            if (TextUtils.isEmpty(tz)) return;
-            TimeZone zone = TimeZone.getTimeZone(tz);
-            // Prevent reentrant calls from stepping on each other when writing
-            // the time zone property
-            boolean timeZoneWasChanged = false;
-            synchronized (this) {
-                String current = SystemProperties.get(TIMEZONE_PROPERTY);
-                if (current == null || !current.equals(zone.getID())) {
-                    if (localLOGV) {
-                        Slog.v(TAG, "timezone changed: " + current + ", new=" + zone.getID());
-                    }
-                    timeZoneWasChanged = true;
-                    SystemProperties.set(TIMEZONE_PROPERTY, zone.getID());
-                }
-
-                // Update the kernel timezone information
-                // Kernel tracks time offsets as 'minutes west of GMT'
-                int gmtOffset = zone.getOffset(System.currentTimeMillis());
-                setKernelTimezone(mDescriptor, -(gmtOffset / 60000));
-            }
-
-            TimeZone.setDefault(null);
-
-            if (timeZoneWasChanged) {
-                Intent intent = new Intent(Intent.ACTION_TIMEZONE_CHANGED);
-                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-                intent.putExtra("time-zone", zone.getID());
-                mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(oldId);
-        }
-    }
-    
-    public void remove(PendingIntent operation) {
-        if (operation == null) {
-            return;
-        }
-        synchronized (mLock) {
-            removeLocked(operation);
-        }
-    }
-    
-    public void removeLocked(PendingIntent operation) {
-        boolean didRemove = false;
-        for (int i = mAlarmBatches.size() - 1; i >= 0; i--) {
-            Batch b = mAlarmBatches.get(i);
-            didRemove |= b.remove(operation);
-            if (b.size() == 0) {
-                mAlarmBatches.remove(i);
-            }
-        }
-
-        if (didRemove) {
-            if (DEBUG_BATCH) {
-                Slog.v(TAG, "remove(operation) changed bounds; rebatching");
-            }
-            rebatchAllAlarmsLocked(true);
-            rescheduleKernelAlarmsLocked();
-        }
-    }
-
-    public void removeLocked(String packageName) {
-        boolean didRemove = false;
-        for (int i = mAlarmBatches.size() - 1; i >= 0; i--) {
-            Batch b = mAlarmBatches.get(i);
-            didRemove |= b.remove(packageName);
-            if (b.size() == 0) {
-                mAlarmBatches.remove(i);
-            }
-        }
-
-        if (didRemove) {
-            if (DEBUG_BATCH) {
-                Slog.v(TAG, "remove(package) changed bounds; rebatching");
-            }
-            rebatchAllAlarmsLocked(true);
-            rescheduleKernelAlarmsLocked();
-        }
-    }
-
-    public void removeUserLocked(int userHandle) {
-        boolean didRemove = false;
-        for (int i = mAlarmBatches.size() - 1; i >= 0; i--) {
-            Batch b = mAlarmBatches.get(i);
-            didRemove |= b.remove(userHandle);
-            if (b.size() == 0) {
-                mAlarmBatches.remove(i);
-            }
-        }
-
-        if (didRemove) {
-            if (DEBUG_BATCH) {
-                Slog.v(TAG, "remove(user) changed bounds; rebatching");
-            }
-            rebatchAllAlarmsLocked(true);
-            rescheduleKernelAlarmsLocked();
-        }
-    }
-
-    public boolean lookForPackageLocked(String packageName) {
-        for (int i = 0; i < mAlarmBatches.size(); i++) {
-            Batch b = mAlarmBatches.get(i);
-            if (b.hasPackage(packageName)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private void setLocked(int type, long when)
-    {
-        if (mDescriptor != -1)
-        {
-            // The kernel never triggers alarms with negative wakeup times
-            // so we ensure they are positive.
-            long alarmSeconds, alarmNanoseconds;
-            if (when < 0) {
-                alarmSeconds = 0;
-                alarmNanoseconds = 0;
-            } else {
-                alarmSeconds = when / 1000;
-                alarmNanoseconds = (when % 1000) * 1000 * 1000;
-            }
-            
-            set(mDescriptor, type, alarmSeconds, alarmNanoseconds);
-        }
-        else
-        {
-            Message msg = Message.obtain();
-            msg.what = ALARM_EVENT;
-            
-            mHandler.removeMessages(ALARM_EVENT);
-            mHandler.sendMessageAtTime(msg, when);
-        }
-    }
-    
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump AlarmManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-        
-        synchronized (mLock) {
-            pw.println("Current Alarm Manager state:");
-            final long nowRTC = System.currentTimeMillis();
-            final long nowELAPSED = SystemClock.elapsedRealtime();
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
-            pw.print("nowRTC="); pw.print(nowRTC);
-            pw.print("="); pw.print(sdf.format(new Date(nowRTC)));
-            pw.print(" nowELAPSED="); pw.println(nowELAPSED);
-
-            long nextWakeupRTC = mNextWakeup + (nowRTC - nowELAPSED);
-            long nextNonWakeupRTC = mNextNonWakeup + (nowRTC - nowELAPSED);
-            pw.print("Next alarm: "); pw.print(mNextNonWakeup);
-                    pw.print(" = "); pw.println(sdf.format(new Date(nextNonWakeupRTC)));
-            pw.print("Next wakeup: "); pw.print(mNextWakeup);
-                    pw.print(" = "); pw.println(sdf.format(new Date(nextWakeupRTC)));
-
-            if (mAlarmBatches.size() > 0) {
-                pw.println();
-                pw.print("Pending alarm batches: ");
-                pw.println(mAlarmBatches.size());
-                for (Batch b : mAlarmBatches) {
-                    pw.print(b); pw.println(':');
-                    dumpAlarmList(pw, b.alarms, "  ", nowELAPSED, nowRTC);
-                }
-            }
-
-            pw.println();
-            pw.print("  Broadcast ref count: "); pw.println(mBroadcastRefCount);
-            pw.println();
-
-            if (mLog.dump(pw, "  Recent problems", "    ")) {
-                pw.println();
-            }
-
-            final FilterStats[] topFilters = new FilterStats[10];
-            final Comparator<FilterStats> comparator = new Comparator<FilterStats>() {
-                @Override
-                public int compare(FilterStats lhs, FilterStats rhs) {
-                    if (lhs.aggregateTime < rhs.aggregateTime) {
-                        return 1;
-                    } else if (lhs.aggregateTime > rhs.aggregateTime) {
-                        return -1;
-                    }
-                    return 0;
-                }
-            };
-            int len = 0;
-            for (Map.Entry<String, BroadcastStats> be : mBroadcastStats.entrySet()) {
-                BroadcastStats bs = be.getValue();
-                for (Map.Entry<Pair<String, ComponentName>, FilterStats> fe
-                        : bs.filterStats.entrySet()) {
-                    FilterStats fs = fe.getValue();
-                    int pos = len > 0
-                            ? Arrays.binarySearch(topFilters, 0, len, fs, comparator) : 0;
-                    if (pos < 0) {
-                        pos = -pos - 1;
-                    }
-                    if (pos < topFilters.length) {
-                        int copylen = topFilters.length - pos - 1;
-                        if (copylen > 0) {
-                            System.arraycopy(topFilters, pos, topFilters, pos+1, copylen);
-                        }
-                        topFilters[pos] = fs;
-                        if (len < topFilters.length) {
-                            len++;
-                        }
-                    }
-                }
-            }
-            if (len > 0) {
-                pw.println("  Top Alarms:");
-                for (int i=0; i<len; i++) {
-                    FilterStats fs = topFilters[i];
-                    pw.print("    ");
-                    if (fs.nesting > 0) pw.print("*ACTIVE* ");
-                    TimeUtils.formatDuration(fs.aggregateTime, pw);
-                    pw.print(" running, "); pw.print(fs.numWakeup);
-                    pw.print(" wakeups, "); pw.print(fs.count);
-                    pw.print(" alarms: "); pw.print(fs.mBroadcastStats.mPackageName);
-                    pw.println();
-                    pw.print("      ");
-                    if (fs.mTarget.first != null) {
-                        pw.print(" act="); pw.print(fs.mTarget.first);
-                    }
-                    if (fs.mTarget.second != null) {
-                        pw.print(" cmp="); pw.print(fs.mTarget.second.toShortString());
-                    }
-                    pw.println();
-                }
-            }
-
-            pw.println(" ");
-            pw.println("  Alarm Stats:");
-            final ArrayList<FilterStats> tmpFilters = new ArrayList<FilterStats>();
-            for (Map.Entry<String, BroadcastStats> be : mBroadcastStats.entrySet()) {
-                BroadcastStats bs = be.getValue();
-                pw.print("  ");
-                if (bs.nesting > 0) pw.print("*ACTIVE* ");
-                pw.print(be.getKey());
-                pw.print(" "); TimeUtils.formatDuration(bs.aggregateTime, pw);
-                        pw.print(" running, "); pw.print(bs.numWakeup);
-                        pw.println(" wakeups:");
-                tmpFilters.clear();
-                for (Map.Entry<Pair<String, ComponentName>, FilterStats> fe
-                        : bs.filterStats.entrySet()) {
-                    tmpFilters.add(fe.getValue());
-                }
-                Collections.sort(tmpFilters, comparator);
-                for (int i=0; i<tmpFilters.size(); i++) {
-                    FilterStats fs = tmpFilters.get(i);
-                    pw.print("    ");
-                            if (fs.nesting > 0) pw.print("*ACTIVE* ");
-                            TimeUtils.formatDuration(fs.aggregateTime, pw);
-                            pw.print(" "); pw.print(fs.numWakeup);
-                            pw.print(" wakes " ); pw.print(fs.count);
-                            pw.print(" alarms:");
-                            if (fs.mTarget.first != null) {
-                                pw.print(" act="); pw.print(fs.mTarget.first);
-                            }
-                            if (fs.mTarget.second != null) {
-                                pw.print(" cmp="); pw.print(fs.mTarget.second.toShortString());
-                            }
-                            pw.println();
-                }
-            }
-
-            if (WAKEUP_STATS) {
-                pw.println();
-                pw.println("  Recent Wakeup History:");
-                long last = -1;
-                for (WakeupEvent event : mRecentWakeups) {
-                    pw.print("    "); pw.print(sdf.format(new Date(event.when)));
-                    pw.print('|');
-                    if (last < 0) {
-                        pw.print('0');
-                    } else {
-                        pw.print(event.when - last);
-                    }
-                    last = event.when;
-                    pw.print('|'); pw.print(event.uid);
-                    pw.print('|'); pw.print(event.action);
-                    pw.println();
-                }
-                pw.println();
-            }
-        }
-    }
-
-    private static final void dumpAlarmList(PrintWriter pw, ArrayList<Alarm> list,
-            String prefix, String label, long now) {
-        for (int i=list.size()-1; i>=0; i--) {
-            Alarm a = list.get(i);
-            pw.print(prefix); pw.print(label); pw.print(" #"); pw.print(i);
-                    pw.print(": "); pw.println(a);
-            a.dump(pw, prefix + "  ", now);
-        }
-    }
-
-    private static final String labelForType(int type) {
-        switch (type) {
-        case RTC: return "RTC";
-        case RTC_WAKEUP : return "RTC_WAKEUP";
-        case ELAPSED_REALTIME : return "ELAPSED";
-        case ELAPSED_REALTIME_WAKEUP: return "ELAPSED_WAKEUP";
-        default:
-            break;
-        }
-        return "--unknown--";
-    }
-
-    private static final void dumpAlarmList(PrintWriter pw, ArrayList<Alarm> list,
-            String prefix, long nowELAPSED, long nowRTC) {
-        for (int i=list.size()-1; i>=0; i--) {
-            Alarm a = list.get(i);
-            final String label = labelForType(a.type);
-            long now = (a.type <= RTC) ? nowRTC : nowELAPSED;
-            pw.print(prefix); pw.print(label); pw.print(" #"); pw.print(i);
-                    pw.print(": "); pw.println(a);
-            a.dump(pw, prefix + "  ", now);
-        }
-    }
-
-    private native int init();
-    private native void close(int fd);
-    private native void set(int fd, int type, long seconds, long nanoseconds);
-    private native int waitForAlarm(int fd);
-    private native int setKernelTimezone(int fd, int minuteswest);
-
-    private void triggerAlarmsLocked(ArrayList<Alarm> triggerList, long nowELAPSED, long nowRTC) {
-        // batches are temporally sorted, so we need only pull from the
-        // start of the list until we either empty it or hit a batch
-        // that is not yet deliverable
-        while (mAlarmBatches.size() > 0) {
-            Batch batch = mAlarmBatches.get(0);
-            if (batch.start > nowELAPSED) {
-                // Everything else is scheduled for the future
-                break;
-            }
-
-            // We will (re)schedule some alarms now; don't let that interfere
-            // with delivery of this current batch
-            mAlarmBatches.remove(0);
-
-            final int N = batch.size();
-            for (int i = 0; i < N; i++) {
-                Alarm alarm = batch.get(i);
-                alarm.count = 1;
-                triggerList.add(alarm);
-
-                // Recurring alarms may have passed several alarm intervals while the
-                // phone was asleep or off, so pass a trigger count when sending them.
-                if (alarm.repeatInterval > 0) {
-                    // this adjustment will be zero if we're late by
-                    // less than one full repeat interval
-                    alarm.count += (nowELAPSED - alarm.whenElapsed) / alarm.repeatInterval;
-
-                    // Also schedule its next recurrence
-                    final long delta = alarm.count * alarm.repeatInterval;
-                    final long nextElapsed = alarm.whenElapsed + delta;
-                    setImplLocked(alarm.type, alarm.when + delta, nextElapsed, alarm.windowLength,
-                            maxTriggerTime(nowELAPSED, nextElapsed, alarm.repeatInterval),
-                            alarm.repeatInterval, alarm.operation, batch.standalone, true,
-                            alarm.workSource);
-                }
-
-            }
-        }
-    }
-
-    /**
-     * This Comparator sorts Alarms into increasing time order.
-     */
-    public static class IncreasingTimeOrder implements Comparator<Alarm> {
-        public int compare(Alarm a1, Alarm a2) {
-            long when1 = a1.when;
-            long when2 = a2.when;
-            if (when1 - when2 > 0) {
-                return 1;
-            }
-            if (when1 - when2 < 0) {
-                return -1;
-            }
-            return 0;
-        }
-    }
-    
-    private static class Alarm {
-        public int type;
-        public int count;
-        public long when;
-        public long windowLength;
-        public long whenElapsed;    // 'when' in the elapsed time base
-        public long maxWhen;        // also in the elapsed time base
-        public long repeatInterval;
-        public PendingIntent operation;
-        public WorkSource workSource;
-        
-        public Alarm(int _type, long _when, long _whenElapsed, long _windowLength, long _maxWhen,
-                long _interval, PendingIntent _op, WorkSource _ws) {
-            type = _type;
-            when = _when;
-            whenElapsed = _whenElapsed;
-            windowLength = _windowLength;
-            maxWhen = _maxWhen;
-            repeatInterval = _interval;
-            operation = _op;
-            workSource = _ws;
-        }
-
-        @Override
-        public String toString()
-        {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("Alarm{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(" type ");
-            sb.append(type);
-            sb.append(" ");
-            sb.append(operation.getTargetPackage());
-            sb.append('}');
-            return sb.toString();
-        }
-
-        public void dump(PrintWriter pw, String prefix, long now) {
-            pw.print(prefix); pw.print("type="); pw.print(type);
-                    pw.print(" whenElapsed="); pw.print(whenElapsed);
-                    pw.print(" when="); TimeUtils.formatDuration(when, now, pw);
-                    pw.print(" window="); pw.print(windowLength);
-                    pw.print(" repeatInterval="); pw.print(repeatInterval);
-                    pw.print(" count="); pw.println(count);
-            pw.print(prefix); pw.print("operation="); pw.println(operation);
-        }
-    }
-
-    void recordWakeupAlarms(ArrayList<Batch> batches, long nowELAPSED, long nowRTC) {
-        final int numBatches = batches.size();
-        for (int nextBatch = 0; nextBatch < numBatches; nextBatch++) {
-            Batch b = batches.get(nextBatch);
-            if (b.start > nowELAPSED) {
-                break;
-            }
-
-            final int numAlarms = b.alarms.size();
-            for (int nextAlarm = 0; nextAlarm < numAlarms; nextAlarm++) {
-                Alarm a = b.alarms.get(nextAlarm);
-                WakeupEvent e = new WakeupEvent(nowRTC,
-                        a.operation.getCreatorUid(),
-                        a.operation.getIntent().getAction());
-                mRecentWakeups.add(e);
-            }
-        }
-    }
-
-    private class AlarmThread extends Thread
-    {
-        public AlarmThread()
-        {
-            super("AlarmManager");
-        }
-        
-        public void run()
-        {
-            ArrayList<Alarm> triggerList = new ArrayList<Alarm>();
-
-            while (true)
-            {
-                int result = waitForAlarm(mDescriptor);
-
-                triggerList.clear();
-
-                if ((result & TIME_CHANGED_MASK) != 0) {
-                    if (DEBUG_BATCH) {
-                        Slog.v(TAG, "Time changed notification from kernel; rebatching");
-                    }
-                    remove(mTimeTickSender);
-                    rebatchAllAlarms();
-                    mClockReceiver.scheduleTimeTickEvent();
-                    Intent intent = new Intent(Intent.ACTION_TIME_CHANGED);
-                    intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
-                            | Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                    mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
-                }
-                
-                synchronized (mLock) {
-                    final long nowRTC = System.currentTimeMillis();
-                    final long nowELAPSED = SystemClock.elapsedRealtime();
-                    if (localLOGV) Slog.v(
-                        TAG, "Checking for alarms... rtc=" + nowRTC
-                        + ", elapsed=" + nowELAPSED);
-
-                    if (WAKEUP_STATS) {
-                        if ((result & IS_WAKEUP_MASK) != 0) {
-                            long newEarliest = nowRTC - RECENT_WAKEUP_PERIOD;
-                            int n = 0;
-                            for (WakeupEvent event : mRecentWakeups) {
-                                if (event.when > newEarliest) break;
-                                n++; // number of now-stale entries at the list head
-                            }
-                            for (int i = 0; i < n; i++) {
-                                mRecentWakeups.remove();
-                            }
-
-                            recordWakeupAlarms(mAlarmBatches, nowELAPSED, nowRTC);
-                        }
-                    }
-
-                    triggerAlarmsLocked(triggerList, nowELAPSED, nowRTC);
-                    rescheduleKernelAlarmsLocked();
-
-                    // now deliver the alarm intents
-                    for (int i=0; i<triggerList.size(); i++) {
-                        Alarm alarm = triggerList.get(i);
-                        try {
-                            if (localLOGV) Slog.v(TAG, "sending alarm " + alarm);
-                            alarm.operation.send(mContext, 0,
-                                    mBackgroundIntent.putExtra(
-                                            Intent.EXTRA_ALARM_COUNT, alarm.count),
-                                    mResultReceiver, mHandler);
-                            
-                            // we have an active broadcast so stay awake.
-                            if (mBroadcastRefCount == 0) {
-                                setWakelockWorkSource(alarm.operation, alarm.workSource);
-                                mWakeLock.acquire();
-                            }
-                            final InFlight inflight = new InFlight(AlarmManagerService.this,
-                                    alarm.operation, alarm.workSource);
-                            mInFlight.add(inflight);
-                            mBroadcastRefCount++;
-
-                            final BroadcastStats bs = inflight.mBroadcastStats;
-                            bs.count++;
-                            if (bs.nesting == 0) {
-                                bs.nesting = 1;
-                                bs.startTime = nowELAPSED;
-                            } else {
-                                bs.nesting++;
-                            }
-                            final FilterStats fs = inflight.mFilterStats;
-                            fs.count++;
-                            if (fs.nesting == 0) {
-                                fs.nesting = 1;
-                                fs.startTime = nowELAPSED;
-                            } else {
-                                fs.nesting++;
-                            }
-                            if (alarm.type == ELAPSED_REALTIME_WAKEUP
-                                    || alarm.type == RTC_WAKEUP) {
-                                bs.numWakeup++;
-                                fs.numWakeup++;
-                                ActivityManagerNative.noteWakeupAlarm(
-                                        alarm.operation);
-                            }
-                        } catch (PendingIntent.CanceledException e) {
-                            if (alarm.repeatInterval > 0) {
-                                // This IntentSender is no longer valid, but this
-                                // is a repeating alarm, so toss the hoser.
-                                remove(alarm.operation);
-                            }
-                        } catch (RuntimeException e) {
-                            Slog.w(TAG, "Failure sending alarm.", e);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Attribute blame for a WakeLock.
-     * @param pi PendingIntent to attribute blame to if ws is null.
-     * @param ws WorkSource to attribute blame.
-     */
-    void setWakelockWorkSource(PendingIntent pi, WorkSource ws) {
-        try {
-            if (ws != null) {
-                mWakeLock.setWorkSource(ws);
-                return;
-            }
-
-            final int uid = ActivityManagerNative.getDefault()
-                    .getUidForIntentSender(pi.getTarget());
-            if (uid >= 0) {
-                mWakeLock.setWorkSource(new WorkSource(uid));
-                return;
-            }
-        } catch (Exception e) {
-        }
-
-        // Something went wrong; fall back to attributing the lock to the OS
-        mWakeLock.setWorkSource(null);
-    }
-
-    private class AlarmHandler extends Handler {
-        public static final int ALARM_EVENT = 1;
-        public static final int MINUTE_CHANGE_EVENT = 2;
-        public static final int DATE_CHANGE_EVENT = 3;
-        
-        public AlarmHandler() {
-        }
-        
-        public void handleMessage(Message msg) {
-            if (msg.what == ALARM_EVENT) {
-                ArrayList<Alarm> triggerList = new ArrayList<Alarm>();
-                synchronized (mLock) {
-                    final long nowRTC = System.currentTimeMillis();
-                    final long nowELAPSED = SystemClock.elapsedRealtime();
-                    triggerAlarmsLocked(triggerList, nowELAPSED, nowRTC);
-                }
-                
-                // now trigger the alarms without the lock held
-                for (int i=0; i<triggerList.size(); i++) {
-                    Alarm alarm = triggerList.get(i);
-                    try {
-                        alarm.operation.send();
-                    } catch (PendingIntent.CanceledException e) {
-                        if (alarm.repeatInterval > 0) {
-                            // This IntentSender is no longer valid, but this
-                            // is a repeating alarm, so toss the hoser.
-                            remove(alarm.operation);
-                        }
-                    }
-                }
-            }
-        }
-    }
-    
-    class ClockReceiver extends BroadcastReceiver {
-        public ClockReceiver() {
-            IntentFilter filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_TIME_TICK);
-            filter.addAction(Intent.ACTION_DATE_CHANGED);
-            mContext.registerReceiver(this, filter);
-        }
-        
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(Intent.ACTION_TIME_TICK)) {
-                if (DEBUG_BATCH) {
-                    Slog.v(TAG, "Received TIME_TICK alarm; rescheduling");
-                }
-                scheduleTimeTickEvent();
-            } else if (intent.getAction().equals(Intent.ACTION_DATE_CHANGED)) {
-                // Since the kernel does not keep track of DST, we need to
-                // reset the TZ information at the beginning of each day
-                // based off of the current Zone gmt offset + userspace tracked
-                // daylight savings information.
-                TimeZone zone = TimeZone.getTimeZone(SystemProperties.get(TIMEZONE_PROPERTY));
-                int gmtOffset = zone.getOffset(System.currentTimeMillis());
-                setKernelTimezone(mDescriptor, -(gmtOffset / 60000));
-                scheduleDateChangedEvent();
-            }
-        }
-        
-        public void scheduleTimeTickEvent() {
-            final long currentTime = System.currentTimeMillis();
-            final long nextTime = 60000 * ((currentTime / 60000) + 1);
-
-            // Schedule this event for the amount of time that it would take to get to
-            // the top of the next minute.
-            final long tickEventDelay = nextTime - currentTime;
-
-            final WorkSource workSource = null; // Let system take blame for time tick events.
-            set(ELAPSED_REALTIME, SystemClock.elapsedRealtime() + tickEventDelay, 0,
-                    0, mTimeTickSender, true, workSource);
-        }
-
-        public void scheduleDateChangedEvent() {
-            Calendar calendar = Calendar.getInstance();
-            calendar.setTimeInMillis(System.currentTimeMillis());
-            calendar.set(Calendar.HOUR, 0);
-            calendar.set(Calendar.MINUTE, 0);
-            calendar.set(Calendar.SECOND, 0);
-            calendar.set(Calendar.MILLISECOND, 0);
-            calendar.add(Calendar.DAY_OF_MONTH, 1);
-
-            final WorkSource workSource = null; // Let system take blame for date change events.
-            set(RTC, calendar.getTimeInMillis(), 0, 0, mDateChangeSender, true, workSource);
-        }
-    }
-    
-    class UninstallReceiver extends BroadcastReceiver {
-        public UninstallReceiver() {
-            IntentFilter filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-            filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
-            filter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
-            filter.addDataScheme("package");
-            mContext.registerReceiver(this, filter);
-             // Register for events related to sdcard installation.
-            IntentFilter sdFilter = new IntentFilter();
-            sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
-            sdFilter.addAction(Intent.ACTION_USER_STOPPED);
-            mContext.registerReceiver(this, sdFilter);
-        }
-        
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            synchronized (mLock) {
-                String action = intent.getAction();
-                String pkgList[] = null;
-                if (Intent.ACTION_QUERY_PACKAGE_RESTART.equals(action)) {
-                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
-                    for (String packageName : pkgList) {
-                        if (lookForPackageLocked(packageName)) {
-                            setResultCode(Activity.RESULT_OK);
-                            return;
-                        }
-                    }
-                    return;
-                } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
-                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-                } else if (Intent.ACTION_USER_STOPPED.equals(action)) {
-                    int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
-                    if (userHandle >= 0) {
-                        removeUserLocked(userHandle);
-                    }
-                } else {
-                    if (Intent.ACTION_PACKAGE_REMOVED.equals(action)
-                            && intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
-                        // This package is being updated; don't kill its alarms.
-                        return;
-                    }
-                    Uri data = intent.getData();
-                    if (data != null) {
-                        String pkg = data.getSchemeSpecificPart();
-                        if (pkg != null) {
-                            pkgList = new String[]{pkg};
-                        }
-                    }
-                }
-                if (pkgList != null && (pkgList.length > 0)) {
-                    for (String pkg : pkgList) {
-                        removeLocked(pkg);
-                        mBroadcastStats.remove(pkg);
-                    }
-                }
-            }
-        }
-    }
-    
-    private final BroadcastStats getStatsLocked(PendingIntent pi) {
-        String pkg = pi.getTargetPackage();
-        BroadcastStats bs = mBroadcastStats.get(pkg);
-        if (bs == null) {
-            bs = new BroadcastStats(pkg);
-            mBroadcastStats.put(pkg, bs);
-        }
-        return bs;
-    }
-
-    class ResultReceiver implements PendingIntent.OnFinished {
-        public void onSendFinished(PendingIntent pi, Intent intent, int resultCode,
-                String resultData, Bundle resultExtras) {
-            synchronized (mLock) {
-                InFlight inflight = null;
-                for (int i=0; i<mInFlight.size(); i++) {
-                    if (mInFlight.get(i).mPendingIntent == pi) {
-                        inflight = mInFlight.remove(i);
-                        break;
-                    }
-                }
-                if (inflight != null) {
-                    final long nowELAPSED = SystemClock.elapsedRealtime();
-                    BroadcastStats bs = inflight.mBroadcastStats;
-                    bs.nesting--;
-                    if (bs.nesting <= 0) {
-                        bs.nesting = 0;
-                        bs.aggregateTime += nowELAPSED - bs.startTime;
-                    }
-                    FilterStats fs = inflight.mFilterStats;
-                    fs.nesting--;
-                    if (fs.nesting <= 0) {
-                        fs.nesting = 0;
-                        fs.aggregateTime += nowELAPSED - fs.startTime;
-                    }
-                } else {
-                    mLog.w("No in-flight alarm for " + pi + " " + intent);
-                }
-                mBroadcastRefCount--;
-                if (mBroadcastRefCount == 0) {
-                    mWakeLock.release();
-                    if (mInFlight.size() > 0) {
-                        mLog.w("Finished all broadcasts with " + mInFlight.size()
-                                + " remaining inflights");
-                        for (int i=0; i<mInFlight.size(); i++) {
-                            mLog.w("  Remaining #" + i + ": " + mInFlight.get(i));
-                        }
-                        mInFlight.clear();
-                    }
-                } else {
-                    // the next of our alarms is now in flight.  reattribute the wakelock.
-                    if (mInFlight.size() > 0) {
-                        InFlight inFlight = mInFlight.get(0);
-                        setWakelockWorkSource(inFlight.mPendingIntent, inFlight.mWorkSource);
-                    } else {
-                        // should never happen
-                        mLog.w("Alarm wakelock still held but sent queue empty");
-                        mWakeLock.setWorkSource(null);
-                    }
-                }
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/AppOpsService.java b/services/java/com/android/server/AppOpsService.java
deleted file mode 100644
index a1a0d47..0000000
--- a/services/java/com/android/server/AppOpsService.java
+++ /dev/null
@@ -1,1083 +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.server;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import android.app.AppOpsManager;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.os.AsyncTask;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.util.ArrayMap;
-import android.util.AtomicFile;
-import android.util.Log;
-import android.util.Pair;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.TimeUtils;
-import android.util.Xml;
-
-import com.android.internal.app.IAppOpsService;
-import com.android.internal.app.IAppOpsCallback;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.XmlUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-public class AppOpsService extends IAppOpsService.Stub {
-    static final String TAG = "AppOps";
-    static final boolean DEBUG = false;
-
-    // Write at most every 30 minutes.
-    static final long WRITE_DELAY = DEBUG ? 1000 : 30*60*1000;
-
-    Context mContext;
-    final AtomicFile mFile;
-    final Handler mHandler;
-
-    boolean mWriteScheduled;
-    final Runnable mWriteRunner = new Runnable() {
-        public void run() {
-            synchronized (AppOpsService.this) {
-                mWriteScheduled = false;
-                AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
-                    @Override protected Void doInBackground(Void... params) {
-                        writeState();
-                        return null;
-                    }
-                };
-                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);
-            }
-        }
-    };
-
-    final SparseArray<HashMap<String, Ops>> mUidOps
-            = new SparseArray<HashMap<String, Ops>>();
-
-    public final static class Ops extends SparseArray<Op> {
-        public final String packageName;
-        public final int uid;
-
-        public Ops(String _packageName, int _uid) {
-            packageName = _packageName;
-            uid = _uid;
-        }
-    }
-
-    public final static class Op {
-        public final int uid;
-        public final String packageName;
-        public final int op;
-        public int mode;
-        public int duration;
-        public long time;
-        public long rejectTime;
-        public int nesting;
-
-        public Op(int _uid, String _packageName, int _op) {
-            uid = _uid;
-            packageName = _packageName;
-            op = _op;
-            mode = AppOpsManager.opToDefaultMode(op);
-        }
-    }
-
-    final SparseArray<ArrayList<Callback>> mOpModeWatchers
-            = new SparseArray<ArrayList<Callback>>();
-    final ArrayMap<String, ArrayList<Callback>> mPackageModeWatchers
-            = new ArrayMap<String, ArrayList<Callback>>();
-    final ArrayMap<IBinder, Callback> mModeWatchers
-            = new ArrayMap<IBinder, Callback>();
-
-    public final class Callback implements DeathRecipient {
-        final IAppOpsCallback mCallback;
-
-        public Callback(IAppOpsCallback callback) {
-            mCallback = callback;
-            try {
-                mCallback.asBinder().linkToDeath(this, 0);
-            } catch (RemoteException e) {
-            }
-        }
-
-        public void unlinkToDeath() {
-            mCallback.asBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public void binderDied() {
-            stopWatchingMode(mCallback);
-        }
-    }
-
-    final ArrayMap<IBinder, ClientState> mClients = new ArrayMap<IBinder, ClientState>();
-
-    public final class ClientState extends Binder implements DeathRecipient {
-        final IBinder mAppToken;
-        final int mPid;
-        final ArrayList<Op> mStartedOps;
-
-        public ClientState(IBinder appToken) {
-            mAppToken = appToken;
-            mPid = Binder.getCallingPid();
-            if (appToken instanceof Binder) {
-                // For local clients, there is no reason to track them.
-                mStartedOps = null;
-            } else {
-                mStartedOps = new ArrayList<Op>();
-                try {
-                    mAppToken.linkToDeath(this, 0);
-                } catch (RemoteException e) {
-                }
-            }
-        }
-
-        @Override
-        public String toString() {
-            return "ClientState{" +
-                    "mAppToken=" + mAppToken +
-                    ", " + (mStartedOps != null ? ("pid=" + mPid) : "local") +
-                    '}';
-        }
-
-        @Override
-        public void binderDied() {
-            synchronized (AppOpsService.this) {
-                for (int i=mStartedOps.size()-1; i>=0; i--) {
-                    finishOperationLocked(mStartedOps.get(i));
-                }
-                mClients.remove(mAppToken);
-            }
-        }
-    }
-
-    public AppOpsService(File storagePath) {
-        mFile = new AtomicFile(storagePath);
-        mHandler = new Handler();
-        readState();
-    }
-
-    public void publish(Context context) {
-        mContext = context;
-        ServiceManager.addService(Context.APP_OPS_SERVICE, asBinder());
-    }
-
-    public void systemReady() {
-        synchronized (this) {
-            boolean changed = false;
-            for (int i=0; i<mUidOps.size(); i++) {
-                HashMap<String, Ops> pkgs = mUidOps.valueAt(i);
-                Iterator<Ops> it = pkgs.values().iterator();
-                while (it.hasNext()) {
-                    Ops ops = it.next();
-                    int curUid;
-                    try {
-                        curUid = mContext.getPackageManager().getPackageUid(ops.packageName,
-                                UserHandle.getUserId(ops.uid));
-                    } catch (NameNotFoundException e) {
-                        curUid = -1;
-                    }
-                    if (curUid != ops.uid) {
-                        Slog.i(TAG, "Pruning old package " + ops.packageName
-                                + "/" + ops.uid + ": new uid=" + curUid);
-                        it.remove();
-                        changed = true;
-                    }
-                }
-                if (pkgs.size() <= 0) {
-                    mUidOps.removeAt(i);
-                }
-            }
-            if (changed) {
-                scheduleWriteLocked();
-            }
-        }
-    }
-
-    public void packageRemoved(int uid, String packageName) {
-        synchronized (this) {
-            HashMap<String, Ops> pkgs = mUidOps.get(uid);
-            if (pkgs != null) {
-                if (pkgs.remove(packageName) != null) {
-                    if (pkgs.size() <= 0) {
-                        mUidOps.remove(uid);
-                    }
-                    scheduleWriteLocked();
-                }
-            }
-        }
-    }
-
-    public void uidRemoved(int uid) {
-        synchronized (this) {
-            if (mUidOps.indexOfKey(uid) >= 0) {
-                mUidOps.remove(uid);
-                scheduleWriteLocked();
-            }
-        }
-    }
-
-    public void shutdown() {
-        Slog.w(TAG, "Writing app ops before shutdown...");
-        boolean doWrite = false;
-        synchronized (this) {
-            if (mWriteScheduled) {
-                mWriteScheduled = false;
-                doWrite = true;
-            }
-        }
-        if (doWrite) {
-            writeState();
-        }
-    }
-
-    private ArrayList<AppOpsManager.OpEntry> collectOps(Ops pkgOps, int[] ops) {
-        ArrayList<AppOpsManager.OpEntry> resOps = null;
-        if (ops == null) {
-            resOps = new ArrayList<AppOpsManager.OpEntry>();
-            for (int j=0; j<pkgOps.size(); j++) {
-                Op curOp = pkgOps.valueAt(j);
-                resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.mode, curOp.time,
-                        curOp.rejectTime, curOp.duration));
-            }
-        } else {
-            for (int j=0; j<ops.length; j++) {
-                Op curOp = pkgOps.get(ops[j]);
-                if (curOp != null) {
-                    if (resOps == null) {
-                        resOps = new ArrayList<AppOpsManager.OpEntry>();
-                    }
-                    resOps.add(new AppOpsManager.OpEntry(curOp.op, curOp.mode, curOp.time,
-                            curOp.rejectTime, curOp.duration));
-                }
-            }
-        }
-        return resOps;
-    }
-
-    @Override
-    public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
-        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-        ArrayList<AppOpsManager.PackageOps> res = null;
-        synchronized (this) {
-            for (int i=0; i<mUidOps.size(); i++) {
-                HashMap<String, Ops> packages = mUidOps.valueAt(i);
-                for (Ops pkgOps : packages.values()) {
-                    ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
-                    if (resOps != null) {
-                        if (res == null) {
-                            res = new ArrayList<AppOpsManager.PackageOps>();
-                        }
-                        AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
-                                pkgOps.packageName, pkgOps.uid, resOps);
-                        res.add(resPackage);
-                    }
-                }
-            }
-        }
-        return res;
-    }
-
-    @Override
-    public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName,
-            int[] ops) {
-        mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-        synchronized (this) {
-            Ops pkgOps = getOpsLocked(uid, packageName, false);
-            if (pkgOps == null) {
-                return null;
-            }
-            ArrayList<AppOpsManager.OpEntry> resOps = collectOps(pkgOps, ops);
-            if (resOps == null) {
-                return null;
-            }
-            ArrayList<AppOpsManager.PackageOps> res = new ArrayList<AppOpsManager.PackageOps>();
-            AppOpsManager.PackageOps resPackage = new AppOpsManager.PackageOps(
-                    pkgOps.packageName, pkgOps.uid, resOps);
-            res.add(resPackage);
-            return res;
-        }
-    }
-
-    private void pruneOp(Op op, int uid, String packageName) {
-        if (op.time == 0 && op.rejectTime == 0) {
-            Ops ops = getOpsLocked(uid, packageName, false);
-            if (ops != null) {
-                ops.remove(op.op);
-                if (ops.size() <= 0) {
-                    HashMap<String, Ops> pkgOps = mUidOps.get(uid);
-                    if (pkgOps != null) {
-                        pkgOps.remove(ops.packageName);
-                        if (pkgOps.size() <= 0) {
-                            mUidOps.remove(uid);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void setMode(int code, int uid, String packageName, int mode) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        ArrayList<Callback> repCbs = null;
-        code = AppOpsManager.opToSwitch(code);
-        synchronized (this) {
-            Op op = getOpLocked(code, uid, packageName, true);
-            if (op != null) {
-                if (op.mode != mode) {
-                    op.mode = mode;
-                    ArrayList<Callback> cbs = mOpModeWatchers.get(code);
-                    if (cbs != null) {
-                        if (repCbs == null) {
-                            repCbs = new ArrayList<Callback>();
-                        }
-                        repCbs.addAll(cbs);
-                    }
-                    cbs = mPackageModeWatchers.get(packageName);
-                    if (cbs != null) {
-                        if (repCbs == null) {
-                            repCbs = new ArrayList<Callback>();
-                        }
-                        repCbs.addAll(cbs);
-                    }
-                    if (mode == AppOpsManager.opToDefaultMode(op.op)) {
-                        // If going into the default mode, prune this op
-                        // if there is nothing else interesting in it.
-                        pruneOp(op, uid, packageName);
-                    }
-                    scheduleWriteNowLocked();
-                }
-            }
-        }
-        if (repCbs != null) {
-            for (int i=0; i<repCbs.size(); i++) {
-                try {
-                    repCbs.get(i).mCallback.opChanged(code, packageName);
-                } catch (RemoteException e) {
-                }
-            }
-        }
-    }
-
-    private static HashMap<Callback, ArrayList<Pair<String, Integer>>> addCallbacks(
-            HashMap<Callback, ArrayList<Pair<String, Integer>>> callbacks,
-            String packageName, int op, ArrayList<Callback> cbs) {
-        if (cbs == null) {
-            return callbacks;
-        }
-        if (callbacks == null) {
-            callbacks = new HashMap<Callback, ArrayList<Pair<String, Integer>>>();
-        }
-        for (int i=0; i<cbs.size(); i++) {
-            Callback cb = cbs.get(i);
-            ArrayList<Pair<String, Integer>> reports = callbacks.get(cb);
-            if (reports == null) {
-                reports = new ArrayList<Pair<String, Integer>>();
-                callbacks.put(cb, reports);
-            }
-            reports.add(new Pair<String, Integer>(packageName, op));
-        }
-        return callbacks;
-    }
-
-    @Override
-    public void resetAllModes() {
-        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-        HashMap<Callback, ArrayList<Pair<String, Integer>>> callbacks = null;
-        synchronized (this) {
-            boolean changed = false;
-            for (int i=mUidOps.size()-1; i>=0; i--) {
-                HashMap<String, Ops> packages = mUidOps.valueAt(i);
-                Iterator<Map.Entry<String, Ops>> it = packages.entrySet().iterator();
-                while (it.hasNext()) {
-                    Map.Entry<String, Ops> ent = it.next();
-                    String packageName = ent.getKey();
-                    Ops pkgOps = ent.getValue();
-                    for (int j=pkgOps.size()-1; j>=0; j--) {
-                        Op curOp = pkgOps.valueAt(j);
-                        if (AppOpsManager.opAllowsReset(curOp.op)
-                                && curOp.mode != AppOpsManager.opToDefaultMode(curOp.op)) {
-                            curOp.mode = AppOpsManager.opToDefaultMode(curOp.op);
-                            changed = true;
-                            callbacks = addCallbacks(callbacks, packageName, curOp.op,
-                                    mOpModeWatchers.get(curOp.op));
-                            callbacks = addCallbacks(callbacks, packageName, curOp.op,
-                                    mPackageModeWatchers.get(packageName));
-                            if (curOp.time == 0 && curOp.rejectTime == 0) {
-                                pkgOps.removeAt(j);
-                            }
-                        }
-                    }
-                    if (pkgOps.size() == 0) {
-                        it.remove();
-                    }
-                }
-                if (packages.size() == 0) {
-                    mUidOps.removeAt(i);
-                }
-            }
-            if (changed) {
-                scheduleWriteNowLocked();
-            }
-        }
-        if (callbacks != null) {
-            for (Map.Entry<Callback, ArrayList<Pair<String, Integer>>> ent : callbacks.entrySet()) {
-                Callback cb = ent.getKey();
-                ArrayList<Pair<String, Integer>> reports = ent.getValue();
-                for (int i=0; i<reports.size(); i++) {
-                    Pair<String, Integer> rep = reports.get(i);
-                    try {
-                        cb.mCallback.opChanged(rep.second, rep.first);
-                    } catch (RemoteException e) {
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public void startWatchingMode(int op, String packageName, IAppOpsCallback callback) {
-        synchronized (this) {
-            op = AppOpsManager.opToSwitch(op);
-            Callback cb = mModeWatchers.get(callback.asBinder());
-            if (cb == null) {
-                cb = new Callback(callback);
-                mModeWatchers.put(callback.asBinder(), cb);
-            }
-            if (op != AppOpsManager.OP_NONE) {
-                ArrayList<Callback> cbs = mOpModeWatchers.get(op);
-                if (cbs == null) {
-                    cbs = new ArrayList<Callback>();
-                    mOpModeWatchers.put(op, cbs);
-                }
-                cbs.add(cb);
-            }
-            if (packageName != null) {
-                ArrayList<Callback> cbs = mPackageModeWatchers.get(packageName);
-                if (cbs == null) {
-                    cbs = new ArrayList<Callback>();
-                    mPackageModeWatchers.put(packageName, cbs);
-                }
-                cbs.add(cb);
-            }
-        }
-    }
-
-    @Override
-    public void stopWatchingMode(IAppOpsCallback callback) {
-        synchronized (this) {
-            Callback cb = mModeWatchers.remove(callback.asBinder());
-            if (cb != null) {
-                cb.unlinkToDeath();
-                for (int i=mOpModeWatchers.size()-1; i>=0; i--) {
-                    ArrayList<Callback> cbs = mOpModeWatchers.valueAt(i);
-                    cbs.remove(cb);
-                    if (cbs.size() <= 0) {
-                        mOpModeWatchers.removeAt(i);
-                    }
-                }
-                for (int i=mPackageModeWatchers.size()-1; i>=0; i--) {
-                    ArrayList<Callback> cbs = mPackageModeWatchers.valueAt(i);
-                    cbs.remove(cb);
-                    if (cbs.size() <= 0) {
-                        mPackageModeWatchers.removeAt(i);
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    public IBinder getToken(IBinder clientToken) {
-        synchronized (this) {
-            ClientState cs = mClients.get(clientToken);
-            if (cs == null) {
-                cs = new ClientState(clientToken);
-                mClients.put(clientToken, cs);
-            }
-            return cs;
-        }
-    }
-
-    @Override
-    public int checkOperation(int code, int uid, String packageName) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        synchronized (this) {
-            Op op = getOpLocked(AppOpsManager.opToSwitch(code), uid, packageName, false);
-            if (op == null) {
-                return AppOpsManager.opToDefaultMode(code);
-            }
-            return op.mode;
-        }
-    }
-
-    @Override
-    public int checkPackage(int uid, String packageName) {
-        synchronized (this) {
-            if (getOpsLocked(uid, packageName, true) != null) {
-                return AppOpsManager.MODE_ALLOWED;
-            } else {
-                return AppOpsManager.MODE_ERRORED;
-            }
-        }
-    }
-
-    @Override
-    public int noteOperation(int code, int uid, String packageName) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        synchronized (this) {
-            Ops ops = getOpsLocked(uid, packageName, true);
-            if (ops == null) {
-                if (DEBUG) Log.d(TAG, "noteOperation: no op for code " + code + " uid " + uid
-                        + " package " + packageName);
-                return AppOpsManager.MODE_ERRORED;
-            }
-            Op op = getOpLocked(ops, code, true);
-            if (op.duration == -1) {
-                Slog.w(TAG, "Noting op not finished: uid " + uid + " pkg " + packageName
-                        + " code " + code + " time=" + op.time + " duration=" + op.duration);
-            }
-            op.duration = 0;
-            final int switchCode = AppOpsManager.opToSwitch(code);
-            final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op;
-            if (switchOp.mode != AppOpsManager.MODE_ALLOWED) {
-                if (DEBUG) Log.d(TAG, "noteOperation: reject #" + op.mode + " for code "
-                        + switchCode + " (" + code + ") uid " + uid + " package " + packageName);
-                op.rejectTime = System.currentTimeMillis();
-                return switchOp.mode;
-            }
-            if (DEBUG) Log.d(TAG, "noteOperation: allowing code " + code + " uid " + uid
-                    + " package " + packageName);
-            op.time = System.currentTimeMillis();
-            op.rejectTime = 0;
-            return AppOpsManager.MODE_ALLOWED;
-        }
-    }
-
-    @Override
-    public int startOperation(IBinder token, int code, int uid, String packageName) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        ClientState client = (ClientState)token;
-        synchronized (this) {
-            Ops ops = getOpsLocked(uid, packageName, true);
-            if (ops == null) {
-                if (DEBUG) Log.d(TAG, "startOperation: no op for code " + code + " uid " + uid
-                        + " package " + packageName);
-                return AppOpsManager.MODE_ERRORED;
-            }
-            Op op = getOpLocked(ops, code, true);
-            final int switchCode = AppOpsManager.opToSwitch(code);
-            final Op switchOp = switchCode != code ? getOpLocked(ops, switchCode, true) : op;
-            if (switchOp.mode != AppOpsManager.MODE_ALLOWED) {
-                if (DEBUG) Log.d(TAG, "startOperation: reject #" + op.mode + " for code "
-                        + switchCode + " (" + code + ") uid " + uid + " package " + packageName);
-                op.rejectTime = System.currentTimeMillis();
-                return switchOp.mode;
-            }
-            if (DEBUG) Log.d(TAG, "startOperation: allowing code " + code + " uid " + uid
-                    + " package " + packageName);
-            if (op.nesting == 0) {
-                op.time = System.currentTimeMillis();
-                op.rejectTime = 0;
-                op.duration = -1;
-            }
-            op.nesting++;
-            if (client.mStartedOps != null) {
-                client.mStartedOps.add(op);
-            }
-            return AppOpsManager.MODE_ALLOWED;
-        }
-    }
-
-    @Override
-    public void finishOperation(IBinder token, int code, int uid, String packageName) {
-        verifyIncomingUid(uid);
-        verifyIncomingOp(code);
-        ClientState client = (ClientState)token;
-        synchronized (this) {
-            Op op = getOpLocked(code, uid, packageName, true);
-            if (op == null) {
-                return;
-            }
-            if (client.mStartedOps != null) {
-                if (!client.mStartedOps.remove(op)) {
-                    throw new IllegalStateException("Operation not started: uid" + op.uid
-                            + " pkg=" + op.packageName + " op=" + op.op);
-                }
-            }
-            finishOperationLocked(op);
-        }
-    }
-
-    void finishOperationLocked(Op op) {
-        if (op.nesting <= 1) {
-            if (op.nesting == 1) {
-                op.duration = (int)(System.currentTimeMillis() - op.time);
-                op.time += op.duration;
-            } else {
-                Slog.w(TAG, "Finishing op nesting under-run: uid " + op.uid + " pkg "
-                        + op.packageName + " code " + op.op + " time=" + op.time
-                        + " duration=" + op.duration + " nesting=" + op.nesting);
-            }
-            op.nesting = 0;
-        } else {
-            op.nesting--;
-        }
-    }
-
-    private void verifyIncomingUid(int uid) {
-        if (uid == Binder.getCallingUid()) {
-            return;
-        }
-        if (Binder.getCallingPid() == Process.myPid()) {
-            return;
-        }
-        mContext.enforcePermission(android.Manifest.permission.UPDATE_APP_OPS_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-    }
-
-    private void verifyIncomingOp(int op) {
-        if (op >= 0 && op < AppOpsManager._NUM_OP) {
-            return;
-        }
-        throw new IllegalArgumentException("Bad operation #" + op);
-    }
-
-    private Ops getOpsLocked(int uid, String packageName, boolean edit) {
-        HashMap<String, Ops> pkgOps = mUidOps.get(uid);
-        if (pkgOps == null) {
-            if (!edit) {
-                return null;
-            }
-            pkgOps = new HashMap<String, Ops>();
-            mUidOps.put(uid, pkgOps);
-        }
-        if (uid == 0) {
-            packageName = "root";
-        } else if (uid == Process.SHELL_UID) {
-            packageName = "com.android.shell";
-        }
-        Ops ops = pkgOps.get(packageName);
-        if (ops == null) {
-            if (!edit) {
-                return null;
-            }
-            // This is the first time we have seen this package name under this uid,
-            // so let's make sure it is valid.
-            if (uid != 0) {
-                final long ident = Binder.clearCallingIdentity();
-                try {
-                    int pkgUid = -1;
-                    try {
-                        pkgUid = mContext.getPackageManager().getPackageUid(packageName,
-                                UserHandle.getUserId(uid));
-                    } catch (NameNotFoundException e) {
-                        if ("media".equals(packageName)) {
-                            pkgUid = Process.MEDIA_UID;
-                        }
-                    }
-                    if (pkgUid != uid) {
-                        // Oops!  The package name is not valid for the uid they are calling
-                        // under.  Abort.
-                        Slog.w(TAG, "Bad call: specified package " + packageName
-                                + " under uid " + uid + " but it is really " + pkgUid);
-                        return null;
-                    }
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
-                }
-            }
-            ops = new Ops(packageName, uid);
-            pkgOps.put(packageName, ops);
-        }
-        return ops;
-    }
-
-    private void scheduleWriteLocked() {
-        if (!mWriteScheduled) {
-            mWriteScheduled = true;
-            mHandler.postDelayed(mWriteRunner, WRITE_DELAY);
-        }
-    }
-
-    private void scheduleWriteNowLocked() {
-        if (!mWriteScheduled) {
-            mWriteScheduled = true;
-        }
-        mHandler.removeCallbacks(mWriteRunner);
-        mHandler.post(mWriteRunner);
-    }
-
-    private Op getOpLocked(int code, int uid, String packageName, boolean edit) {
-        Ops ops = getOpsLocked(uid, packageName, edit);
-        if (ops == null) {
-            return null;
-        }
-        return getOpLocked(ops, code, edit);
-    }
-
-    private Op getOpLocked(Ops ops, int code, boolean edit) {
-        Op op = ops.get(code);
-        if (op == null) {
-            if (!edit) {
-                return null;
-            }
-            op = new Op(ops.uid, ops.packageName, code);
-            ops.put(code, op);
-        }
-        if (edit) {
-            scheduleWriteLocked();
-        }
-        return op;
-    }
-
-    void readState() {
-        synchronized (mFile) {
-            synchronized (this) {
-                FileInputStream stream;
-                try {
-                    stream = mFile.openRead();
-                } catch (FileNotFoundException e) {
-                    Slog.i(TAG, "No existing app ops " + mFile.getBaseFile() + "; starting empty");
-                    return;
-                }
-                boolean success = false;
-                try {
-                    XmlPullParser parser = Xml.newPullParser();
-                    parser.setInput(stream, null);
-                    int type;
-                    while ((type = parser.next()) != XmlPullParser.START_TAG
-                            && type != XmlPullParser.END_DOCUMENT) {
-                        ;
-                    }
-
-                    if (type != XmlPullParser.START_TAG) {
-                        throw new IllegalStateException("no start tag found");
-                    }
-
-                    int outerDepth = parser.getDepth();
-                    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                            continue;
-                        }
-
-                        String tagName = parser.getName();
-                        if (tagName.equals("pkg")) {
-                            readPackage(parser);
-                        } else {
-                            Slog.w(TAG, "Unknown element under <app-ops>: "
-                                    + parser.getName());
-                            XmlUtils.skipCurrentTag(parser);
-                        }
-                    }
-                    success = true;
-                } catch (IllegalStateException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (NullPointerException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (NumberFormatException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (XmlPullParserException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (IOException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } catch (IndexOutOfBoundsException e) {
-                    Slog.w(TAG, "Failed parsing " + e);
-                } finally {
-                    if (!success) {
-                        mUidOps.clear();
-                    }
-                    try {
-                        stream.close();
-                    } catch (IOException e) {
-                    }
-                }
-            }
-        }
-    }
-
-    void readPackage(XmlPullParser parser) throws NumberFormatException,
-            XmlPullParserException, IOException {
-        String pkgName = parser.getAttributeValue(null, "n");
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals("uid")) {
-                readUid(parser, pkgName);
-            } else {
-                Slog.w(TAG, "Unknown element under <pkg>: "
-                        + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-    }
-
-    void readUid(XmlPullParser parser, String pkgName) throws NumberFormatException,
-            XmlPullParserException, IOException {
-        int uid = Integer.parseInt(parser.getAttributeValue(null, "n"));
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals("op")) {
-                Op op = new Op(uid, pkgName, Integer.parseInt(parser.getAttributeValue(null, "n")));
-                String mode = parser.getAttributeValue(null, "m");
-                if (mode != null) {
-                    op.mode = Integer.parseInt(mode);
-                }
-                String time = parser.getAttributeValue(null, "t");
-                if (time != null) {
-                    op.time = Long.parseLong(time);
-                }
-                time = parser.getAttributeValue(null, "r");
-                if (time != null) {
-                    op.rejectTime = Long.parseLong(time);
-                }
-                String dur = parser.getAttributeValue(null, "d");
-                if (dur != null) {
-                    op.duration = Integer.parseInt(dur);
-                }
-                HashMap<String, Ops> pkgOps = mUidOps.get(uid);
-                if (pkgOps == null) {
-                    pkgOps = new HashMap<String, Ops>();
-                    mUidOps.put(uid, pkgOps);
-                }
-                Ops ops = pkgOps.get(pkgName);
-                if (ops == null) {
-                    ops = new Ops(pkgName, uid);
-                    pkgOps.put(pkgName, ops);
-                }
-                ops.put(op.op, op);
-            } else {
-                Slog.w(TAG, "Unknown element under <pkg>: "
-                        + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-    }
-
-    void writeState() {
-        synchronized (mFile) {
-            List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
-
-            FileOutputStream stream;
-            try {
-                stream = mFile.startWrite();
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed to write state: " + e);
-                return;
-            }
-
-            try {
-                XmlSerializer out = new FastXmlSerializer();
-                out.setOutput(stream, "utf-8");
-                out.startDocument(null, true);
-                out.startTag(null, "app-ops");
-
-                if (allOps != null) {
-                    String lastPkg = null;
-                    for (int i=0; i<allOps.size(); i++) {
-                        AppOpsManager.PackageOps pkg = allOps.get(i);
-                        if (!pkg.getPackageName().equals(lastPkg)) {
-                            if (lastPkg != null) {
-                                out.endTag(null, "pkg");
-                            }
-                            lastPkg = pkg.getPackageName();
-                            out.startTag(null, "pkg");
-                            out.attribute(null, "n", lastPkg);
-                        }
-                        out.startTag(null, "uid");
-                        out.attribute(null, "n", Integer.toString(pkg.getUid()));
-                        List<AppOpsManager.OpEntry> ops = pkg.getOps();
-                        for (int j=0; j<ops.size(); j++) {
-                            AppOpsManager.OpEntry op = ops.get(j);
-                            out.startTag(null, "op");
-                            out.attribute(null, "n", Integer.toString(op.getOp()));
-                            if (op.getMode() != AppOpsManager.opToDefaultMode(op.getOp())) {
-                                out.attribute(null, "m", Integer.toString(op.getMode()));
-                            }
-                            long time = op.getTime();
-                            if (time != 0) {
-                                out.attribute(null, "t", Long.toString(time));
-                            }
-                            time = op.getRejectTime();
-                            if (time != 0) {
-                                out.attribute(null, "r", Long.toString(time));
-                            }
-                            int dur = op.getDuration();
-                            if (dur != 0) {
-                                out.attribute(null, "d", Integer.toString(dur));
-                            }
-                            out.endTag(null, "op");
-                        }
-                        out.endTag(null, "uid");
-                    }
-                    if (lastPkg != null) {
-                        out.endTag(null, "pkg");
-                    }
-                }
-
-                out.endTag(null, "app-ops");
-                out.endDocument();
-                mFile.finishWrite(stream);
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed to write state, restoring backup.", e);
-                mFile.failWrite(stream);
-            }
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump ApOps service from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (this) {
-            pw.println("Current AppOps Service state:");
-            final long now = System.currentTimeMillis();
-            boolean needSep = false;
-            if (mOpModeWatchers.size() > 0) {
-                needSep = true;
-                pw.println("  Op mode watchers:");
-                for (int i=0; i<mOpModeWatchers.size(); i++) {
-                    pw.print("    Op "); pw.print(AppOpsManager.opToName(mOpModeWatchers.keyAt(i)));
-                    pw.println(":");
-                    ArrayList<Callback> callbacks = mOpModeWatchers.valueAt(i);
-                    for (int j=0; j<callbacks.size(); j++) {
-                        pw.print("      #"); pw.print(j); pw.print(": ");
-                        pw.println(callbacks.get(j));
-                    }
-                }
-            }
-            if (mPackageModeWatchers.size() > 0) {
-                needSep = true;
-                pw.println("  Package mode watchers:");
-                for (int i=0; i<mPackageModeWatchers.size(); i++) {
-                    pw.print("    Pkg "); pw.print(mPackageModeWatchers.keyAt(i));
-                    pw.println(":");
-                    ArrayList<Callback> callbacks = mPackageModeWatchers.valueAt(i);
-                    for (int j=0; j<callbacks.size(); j++) {
-                        pw.print("      #"); pw.print(j); pw.print(": ");
-                        pw.println(callbacks.get(j));
-                    }
-                }
-            }
-            if (mModeWatchers.size() > 0) {
-                needSep = true;
-                pw.println("  All mode watchers:");
-                for (int i=0; i<mModeWatchers.size(); i++) {
-                    pw.print("    "); pw.print(mModeWatchers.keyAt(i));
-                    pw.print(" -> "); pw.println(mModeWatchers.valueAt(i));
-                }
-            }
-            if (mClients.size() > 0) {
-                needSep = true;
-                pw.println("  Clients:");
-                for (int i=0; i<mClients.size(); i++) {
-                    pw.print("    "); pw.print(mClients.keyAt(i)); pw.println(":");
-                    ClientState cs = mClients.valueAt(i);
-                    pw.print("      "); pw.println(cs);
-                    if (cs.mStartedOps != null && cs.mStartedOps.size() > 0) {
-                        pw.println("      Started ops:");
-                        for (int j=0; j<cs.mStartedOps.size(); j++) {
-                            Op op = cs.mStartedOps.get(j);
-                            pw.print("        "); pw.print("uid="); pw.print(op.uid);
-                            pw.print(" pkg="); pw.print(op.packageName);
-                            pw.print(" op="); pw.println(AppOpsManager.opToName(op.op));
-                        }
-                    }
-                }
-            }
-            if (needSep) {
-                pw.println();
-            }
-            for (int i=0; i<mUidOps.size(); i++) {
-                pw.print("  Uid "); UserHandle.formatUid(pw, mUidOps.keyAt(i)); pw.println(":");
-                HashMap<String, Ops> pkgOps = mUidOps.valueAt(i);
-                for (Ops ops : pkgOps.values()) {
-                    pw.print("    Package "); pw.print(ops.packageName); pw.println(":");
-                    for (int j=0; j<ops.size(); j++) {
-                        Op op = ops.valueAt(j);
-                        pw.print("      "); pw.print(AppOpsManager.opToName(op.op));
-                        pw.print(": mode="); pw.print(op.mode);
-                        if (op.time != 0) {
-                            pw.print("; time="); TimeUtils.formatDuration(now-op.time, pw);
-                            pw.print(" ago");
-                        }
-                        if (op.rejectTime != 0) {
-                            pw.print("; rejectTime="); TimeUtils.formatDuration(now-op.rejectTime, pw);
-                            pw.print(" ago");
-                        }
-                        if (op.duration == -1) {
-                            pw.println(" (running)");
-                        } else {
-                            pw.print("; duration=");
-                                    TimeUtils.formatDuration(op.duration, pw);
-                                    pw.println();
-                        }
-                    }
-                }
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java
deleted file mode 100644
index 203cca6..0000000
--- a/services/java/com/android/server/AppWidgetService.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Copyright (C) 2007 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;
-
-import android.app.ActivityManager;
-import android.appwidget.AppWidgetProviderInfo;
-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.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.widget.RemoteViews;
-
-import com.android.internal.appwidget.IAppWidgetHost;
-import com.android.internal.appwidget.IAppWidgetService;
-import com.android.internal.os.BackgroundThread;
-import com.android.internal.util.IndentingPrintWriter;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.List;
-import java.util.Locale;
-
-
-/**
- * Redirects calls to this service to the instance of the service for the appropriate user.
- */
-class AppWidgetService extends IAppWidgetService.Stub
-{
-    private static final String TAG = "AppWidgetService";
-
-    Context mContext;
-    Locale mLocale;
-    PackageManager mPackageManager;
-    boolean mSafeMode;
-    private final Handler mSaveStateHandler;
-
-    private final SparseArray<AppWidgetServiceImpl> mAppWidgetServices;
-
-    AppWidgetService(Context context) {
-        mContext = context;
-
-        mSaveStateHandler = BackgroundThread.getHandler();
-
-        mAppWidgetServices = new SparseArray<AppWidgetServiceImpl>(5);
-        AppWidgetServiceImpl primary = new AppWidgetServiceImpl(context, 0, mSaveStateHandler);
-        mAppWidgetServices.append(0, primary);
-    }
-
-    public void systemRunning(boolean safeMode) {
-        mSafeMode = safeMode;
-
-        mAppWidgetServices.get(0).systemReady(safeMode);
-
-        // Register for the boot completed broadcast, so we can send the
-        // ENABLE broacasts. If we try to send them now, they time out,
-        // because the system isn't ready to handle them yet.
-        mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
-                new IntentFilter(Intent.ACTION_BOOT_COMPLETED), null, null);
-
-        // Register for configuration changes so we can update the names
-        // of the widgets when the locale changes.
-        mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
-                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED), null, null);
-
-        // Register for broadcasts about package install, etc., so we can
-        // update the provider list.
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
-        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
-        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        filter.addDataScheme("package");
-        mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
-                filter, null, null);
-        // Register for events related to sdcard installation.
-        IntentFilter sdFilter = new IntentFilter();
-        sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
-        sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
-        mContext.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL,
-                sdFilter, null, null);
-
-        IntentFilter userFilter = new IntentFilter();
-        userFilter.addAction(Intent.ACTION_USER_REMOVED);
-        userFilter.addAction(Intent.ACTION_USER_STOPPING);
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) {
-                    onUserRemoved(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
-                            UserHandle.USER_NULL));
-                } else if (Intent.ACTION_USER_STOPPING.equals(intent.getAction())) {
-                    onUserStopping(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
-                            UserHandle.USER_NULL));
-                }
-            }
-        }, userFilter);
-    }
-
-    @Override
-    public int allocateAppWidgetId(String packageName, int hostId, int userId)
-            throws RemoteException {
-        return getImplForUser(userId).allocateAppWidgetId(packageName, hostId);
-    }
-
-    @Override
-    public int[] getAppWidgetIdsForHost(int hostId, int userId) throws RemoteException {
-        return getImplForUser(userId).getAppWidgetIdsForHost(hostId);
-    }
-
-    @Override
-    public void deleteAppWidgetId(int appWidgetId, int userId) throws RemoteException {
-        getImplForUser(userId).deleteAppWidgetId(appWidgetId);
-    }
-
-    @Override
-    public void deleteHost(int hostId, int userId) throws RemoteException {
-        getImplForUser(userId).deleteHost(hostId);
-    }
-
-    @Override
-    public void deleteAllHosts(int userId) throws RemoteException {
-        getImplForUser(userId).deleteAllHosts();
-    }
-
-    @Override
-    public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options, int userId)
-            throws RemoteException {
-        getImplForUser(userId).bindAppWidgetId(appWidgetId, provider, options);
-    }
-
-    @Override
-    public boolean bindAppWidgetIdIfAllowed(
-            String packageName, int appWidgetId, ComponentName provider, Bundle options, int userId)
-                    throws RemoteException {
-        return getImplForUser(userId).bindAppWidgetIdIfAllowed(
-                packageName, appWidgetId, provider, options);
-    }
-
-    @Override
-    public boolean hasBindAppWidgetPermission(String packageName, int userId)
-            throws RemoteException {
-        return getImplForUser(userId).hasBindAppWidgetPermission(packageName);
-    }
-
-    @Override
-    public void setBindAppWidgetPermission(String packageName, boolean permission, int userId)
-            throws RemoteException {
-        getImplForUser(userId).setBindAppWidgetPermission(packageName, permission);
-    }
-
-    @Override
-    public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection,
-            int userId) throws RemoteException {
-        getImplForUser(userId).bindRemoteViewsService(appWidgetId, intent, connection);
-    }
-
-    @Override
-    public int[] startListening(IAppWidgetHost host, String packageName, int hostId,
-            List<RemoteViews> updatedViews, int userId) throws RemoteException {
-        return getImplForUser(userId).startListening(host, packageName, hostId, updatedViews);
-    }
-
-    public void onUserRemoved(int userId) {
-        if (userId < 1) return;
-        synchronized (mAppWidgetServices) {
-            AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
-            mAppWidgetServices.remove(userId);
-
-            if (impl == null) {
-                AppWidgetServiceImpl.getSettingsFile(userId).delete();
-            } else {
-                impl.onUserRemoved();
-            }
-        }
-    }
-
-    public void onUserStopping(int userId) {
-        if (userId < 1) return;
-        synchronized (mAppWidgetServices) {
-            AppWidgetServiceImpl impl = mAppWidgetServices.get(userId);
-            if (impl != null) {
-                mAppWidgetServices.remove(userId);
-                impl.onUserStopping();
-            }
-        }
-    }
-
-    private void checkPermission(int userId) {
-        int realUserId = ActivityManager.handleIncomingUser(
-                Binder.getCallingPid(),
-                Binder.getCallingUid(),
-                userId,
-                false, /* allowAll */
-                true, /* requireFull */
-                this.getClass().getSimpleName(),
-                this.getClass().getPackage().getName());
-    }
-
-    private AppWidgetServiceImpl getImplForUser(int userId) {
-        checkPermission(userId);
-        boolean sendInitial = false;
-        AppWidgetServiceImpl service;
-        synchronized (mAppWidgetServices) {
-            service = mAppWidgetServices.get(userId);
-            if (service == null) {
-                Slog.i(TAG, "Unable to find AppWidgetServiceImpl for user " + userId + ", adding");
-                // TODO: Verify that it's a valid user
-                service = new AppWidgetServiceImpl(mContext, userId, mSaveStateHandler);
-                service.systemReady(mSafeMode);
-                // Assume that BOOT_COMPLETED was received, as this is a non-primary user.
-                mAppWidgetServices.append(userId, service);
-                sendInitial = true;
-            }
-        }
-        if (sendInitial) {
-            service.sendInitialBroadcasts();
-        }
-        return service;
-    }
-
-    @Override
-    public int[] getAppWidgetIds(ComponentName provider, int userId) throws RemoteException {
-        return getImplForUser(userId).getAppWidgetIds(provider);
-    }
-
-    @Override
-    public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId, int userId)
-            throws RemoteException {
-        return getImplForUser(userId).getAppWidgetInfo(appWidgetId);
-    }
-
-    @Override
-    public RemoteViews getAppWidgetViews(int appWidgetId, int userId) throws RemoteException {
-        return getImplForUser(userId).getAppWidgetViews(appWidgetId);
-    }
-
-    @Override
-    public void updateAppWidgetOptions(int appWidgetId, Bundle options, int userId) {
-        getImplForUser(userId).updateAppWidgetOptions(appWidgetId, options);
-    }
-
-    @Override
-    public Bundle getAppWidgetOptions(int appWidgetId, int userId) {
-        return getImplForUser(userId).getAppWidgetOptions(appWidgetId);
-    }
-
-    @Override
-    public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter, int userId)
-            throws RemoteException {
-        return getImplForUser(userId).getInstalledProviders(categoryFilter);
-    }
-
-    @Override
-    public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId, int userId)
-            throws RemoteException {
-        getImplForUser(userId).notifyAppWidgetViewDataChanged(
-                appWidgetIds, viewId);
-    }
-
-    @Override
-    public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views, int userId)
-            throws RemoteException {
-        getImplForUser(userId).partiallyUpdateAppWidgetIds(
-                appWidgetIds, views);
-    }
-
-    @Override
-    public void stopListening(int hostId, int userId) throws RemoteException {
-        getImplForUser(userId).stopListening(hostId);
-    }
-
-    @Override
-    public void unbindRemoteViewsService(int appWidgetId, Intent intent, int userId)
-            throws RemoteException {
-        getImplForUser(userId).unbindRemoteViewsService(
-                appWidgetId, intent);
-    }
-
-    @Override
-    public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views, int userId)
-            throws RemoteException {
-        getImplForUser(userId).updateAppWidgetIds(appWidgetIds, views);
-    }
-
-    @Override
-    public void updateAppWidgetProvider(ComponentName provider, RemoteViews views, int userId)
-            throws RemoteException {
-        getImplForUser(userId).updateAppWidgetProvider(provider, views);
-    }
-
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
-
-        // Dump the state of all the app widget providers
-        synchronized (mAppWidgetServices) {
-            IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ");
-            for (int i = 0; i < mAppWidgetServices.size(); i++) {
-                pw.println("User: " + mAppWidgetServices.keyAt(i));
-                ipw.increaseIndent();
-                AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
-                service.dump(fd, ipw, args);
-                ipw.decreaseIndent();
-            }
-        }
-    }
-
-    BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-            // Slog.d(TAG, "received " + action);
-            if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
-                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
-                if (userId >= 0) {
-                    getImplForUser(userId).sendInitialBroadcasts();
-                } else {
-                    Slog.w(TAG, "Incorrect user handle supplied in " + intent);
-                }
-            } else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
-                for (int i = 0; i < mAppWidgetServices.size(); i++) {
-                    AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
-                    service.onConfigurationChanged();
-                }
-            } else {
-                int sendingUser = getSendingUserId();
-                if (sendingUser == UserHandle.USER_ALL) {
-                    for (int i = 0; i < mAppWidgetServices.size(); i++) {
-                        AppWidgetServiceImpl service = mAppWidgetServices.valueAt(i);
-                        service.onBroadcastReceived(intent);
-                    }
-                } else {
-                    AppWidgetServiceImpl service = mAppWidgetServices.get(sendingUser);
-                    if (service != null) {
-                        service.onBroadcastReceived(intent);
-                    }
-                }
-            }
-        }
-    };
-}
diff --git a/services/java/com/android/server/AppWidgetServiceImpl.java b/services/java/com/android/server/AppWidgetServiceImpl.java
deleted file mode 100644
index 69ae846..0000000
--- a/services/java/com/android/server/AppWidgetServiceImpl.java
+++ /dev/null
@@ -1,2126 +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.server;
-
-import android.app.AlarmManager;
-import android.app.AppGlobals;
-import android.app.PendingIntent;
-import android.appwidget.AppWidgetManager;
-import android.appwidget.AppWidgetProviderInfo;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.Intent.FilterComparison;
-import android.content.ServiceConnection;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
-import android.graphics.Point;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.util.AtomicFile;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Pair;
-import android.util.Slog;
-import android.util.TypedValue;
-import android.util.Xml;
-import android.view.Display;
-import android.view.WindowManager;
-import android.widget.RemoteViews;
-
-import com.android.internal.appwidget.IAppWidgetHost;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.widget.IRemoteViewsAdapterConnection;
-import com.android.internal.widget.IRemoteViewsFactory;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-
-class AppWidgetServiceImpl {
-
-    private static final String KEYGUARD_HOST_PACKAGE = "com.android.keyguard";
-    private static final int KEYGUARD_HOST_ID = 0x4b455947;
-    private static final String TAG = "AppWidgetServiceImpl";
-    private static final String SETTINGS_FILENAME = "appwidgets.xml";
-    private static final int MIN_UPDATE_PERIOD = 30 * 60 * 1000; // 30 minutes
-    private static final int CURRENT_VERSION = 1; // Bump if the stored widgets need to be upgraded.
-
-    private static boolean DBG = false;
-
-    /*
-     * When identifying a Host or Provider based on the calling process, use the uid field. When
-     * identifying a Host or Provider based on a package manager broadcast, use the package given.
-     */
-
-    static class Provider {
-        int uid;
-        AppWidgetProviderInfo info;
-        ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
-        PendingIntent broadcast;
-        boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
-
-        int tag; // for use while saving state (the index)
-    }
-
-    static class Host {
-        int uid;
-        int hostId;
-        String packageName;
-        ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
-        IAppWidgetHost callbacks;
-        boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
-
-        int tag; // for use while saving state (the index)
-
-        boolean uidMatches(int callingUid) {
-            if (UserHandle.getAppId(callingUid) == Process.myUid()) {
-                // For a host that's in the system process, ignore the user id
-                return UserHandle.isSameApp(this.uid, callingUid);
-            } else {
-                return this.uid == callingUid;
-            }
-        }
-    }
-
-    static class AppWidgetId {
-        int appWidgetId;
-        Provider provider;
-        RemoteViews views;
-        Bundle options;
-        Host host;
-    }
-
-    /**
-     * Acts as a proxy between the ServiceConnection and the RemoteViewsAdapterConnection. This
-     * needs to be a static inner class since a reference to the ServiceConnection is held globally
-     * and may lead us to leak AppWidgetService instances (if there were more than one).
-     */
-    static class ServiceConnectionProxy implements ServiceConnection {
-        private final IBinder mConnectionCb;
-
-        ServiceConnectionProxy(Pair<Integer, Intent.FilterComparison> key, IBinder connectionCb) {
-            mConnectionCb = connectionCb;
-        }
-
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            final IRemoteViewsAdapterConnection cb = IRemoteViewsAdapterConnection.Stub
-                    .asInterface(mConnectionCb);
-            try {
-                cb.onServiceConnected(service);
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-
-        public void onServiceDisconnected(ComponentName name) {
-            disconnect();
-        }
-
-        public void disconnect() {
-            final IRemoteViewsAdapterConnection cb = IRemoteViewsAdapterConnection.Stub
-                    .asInterface(mConnectionCb);
-            try {
-                cb.onServiceDisconnected();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
-    // Manages active connections to RemoteViewsServices
-    private final HashMap<Pair<Integer, FilterComparison>, ServiceConnection> mBoundRemoteViewsServices = new HashMap<Pair<Integer, FilterComparison>, ServiceConnection>();
-    // Manages persistent references to RemoteViewsServices from different App Widgets
-    private final HashMap<FilterComparison, HashSet<Integer>> mRemoteViewsServicesAppWidgets = new HashMap<FilterComparison, HashSet<Integer>>();
-
-    final Context mContext;
-    final IPackageManager mPm;
-    final AlarmManager mAlarmManager;
-    final ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
-    final int mUserId;
-    final boolean mHasFeature;
-
-    Locale mLocale;
-    int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
-    final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
-    final ArrayList<Host> mHosts = new ArrayList<Host>();
-    // set of package names
-    final HashSet<String> mPackagesWithBindWidgetPermission = new HashSet<String>();
-    boolean mSafeMode;
-    boolean mStateLoaded;
-    int mMaxWidgetBitmapMemory;
-
-    private final Handler mSaveStateHandler;
-
-    // These are for debugging only -- widgets are going missing in some rare instances
-    ArrayList<Provider> mDeletedProviders = new ArrayList<Provider>();
-    ArrayList<Host> mDeletedHosts = new ArrayList<Host>();
-
-    AppWidgetServiceImpl(Context context, int userId, Handler saveStateHandler) {
-        mContext = context;
-        mPm = AppGlobals.getPackageManager();
-        mAlarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
-        mUserId = userId;
-        mSaveStateHandler = saveStateHandler;
-        mHasFeature = context.getPackageManager().hasSystemFeature(
-                PackageManager.FEATURE_APP_WIDGETS);
-        computeMaximumWidgetBitmapMemory();
-    }
-
-    void computeMaximumWidgetBitmapMemory() {
-        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
-        Display display = wm.getDefaultDisplay();
-        Point size = new Point();
-        display.getRealSize(size);
-        // Cap memory usage at 1.5 times the size of the display
-        // 1.5 * 4 bytes/pixel * w * h ==> 6 * w * h
-        mMaxWidgetBitmapMemory = 6 * size.x * size.y;
-    }
-
-    public void systemReady(boolean safeMode) {
-        mSafeMode = safeMode;
-
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-        }
-    }
-
-    private void log(String msg) {
-        Slog.i(TAG, "u=" + mUserId + ": " + msg);
-    }
-
-    void onConfigurationChanged() {
-        if (DBG) log("Got onConfigurationChanged()");
-        Locale revised = Locale.getDefault();
-        if (revised == null || mLocale == null || !(revised.equals(mLocale))) {
-            mLocale = revised;
-
-            synchronized (mAppWidgetIds) {
-                ensureStateLoadedLocked();
-                // Note: updateProvidersForPackageLocked() may remove providers, so we must copy the
-                // list of installed providers and skip providers that we don't need to update.
-                // Also note that remove the provider does not clear the Provider component data.
-                ArrayList<Provider> installedProviders =
-                        new ArrayList<Provider>(mInstalledProviders);
-                HashSet<ComponentName> removedProviders = new HashSet<ComponentName>();
-                int N = installedProviders.size();
-                for (int i = N - 1; i >= 0; i--) {
-                    Provider p = installedProviders.get(i);
-                    ComponentName cn = p.info.provider;
-                    if (!removedProviders.contains(cn)) {
-                        updateProvidersForPackageLocked(cn.getPackageName(), removedProviders);
-                    }
-                }
-                saveStateAsync();
-            }
-        }
-    }
-
-    void onBroadcastReceived(Intent intent) {
-        if (DBG) log("onBroadcast " + intent);
-        final String action = intent.getAction();
-        boolean added = false;
-        boolean changed = false;
-        boolean providersModified = false;
-        String pkgList[] = null;
-        if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
-            pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-            added = true;
-        } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
-            pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-            added = false;
-        } else {
-            Uri uri = intent.getData();
-            if (uri == null) {
-                return;
-            }
-            String pkgName = uri.getSchemeSpecificPart();
-            if (pkgName == null) {
-                return;
-            }
-            pkgList = new String[] { pkgName };
-            added = Intent.ACTION_PACKAGE_ADDED.equals(action);
-            changed = Intent.ACTION_PACKAGE_CHANGED.equals(action);
-        }
-        if (pkgList == null || pkgList.length == 0) {
-            return;
-        }
-        if (added || changed) {
-            synchronized (mAppWidgetIds) {
-                ensureStateLoadedLocked();
-                Bundle extras = intent.getExtras();
-                if (changed
-                        || (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false))) {
-                    for (String pkgName : pkgList) {
-                        // The package was just upgraded
-                        providersModified |= updateProvidersForPackageLocked(pkgName, null);
-                    }
-                } else {
-                    // The package was just added
-                    for (String pkgName : pkgList) {
-                        providersModified |= addProvidersForPackageLocked(pkgName);
-                    }
-                }
-                saveStateAsync();
-            }
-        } else {
-            Bundle extras = intent.getExtras();
-            if (extras != null && extras.getBoolean(Intent.EXTRA_REPLACING, false)) {
-                // The package is being updated. We'll receive a PACKAGE_ADDED shortly.
-            } else {
-                synchronized (mAppWidgetIds) {
-                    ensureStateLoadedLocked();
-                    for (String pkgName : pkgList) {
-                        providersModified |= removeProvidersForPackageLocked(pkgName);
-                        saveStateAsync();
-                    }
-                }
-            }
-        }
-
-        if (providersModified) {
-            // If the set of providers has been modified, notify each active AppWidgetHost
-            synchronized (mAppWidgetIds) {
-                ensureStateLoadedLocked();
-                notifyHostsForProvidersChangedLocked();
-            }
-        }
-    }
-
-    private void dumpProvider(Provider p, int index, PrintWriter pw) {
-        AppWidgetProviderInfo info = p.info;
-        pw.print("  ["); pw.print(index); pw.print("] provider ");
-                pw.print(info.provider.flattenToShortString());
-                pw.println(':');
-        pw.print("    min=("); pw.print(info.minWidth);
-                pw.print("x"); pw.print(info.minHeight);
-        pw.print(")   minResize=("); pw.print(info.minResizeWidth);
-                pw.print("x"); pw.print(info.minResizeHeight);
-                pw.print(") updatePeriodMillis=");
-                pw.print(info.updatePeriodMillis);
-                pw.print(" resizeMode=");
-                pw.print(info.resizeMode);
-                pw.print(info.widgetCategory);
-                pw.print(" autoAdvanceViewId=");
-                pw.print(info.autoAdvanceViewId);
-                pw.print(" initialLayout=#");
-                pw.print(Integer.toHexString(info.initialLayout));
-                pw.print(" uid="); pw.print(p.uid);
-                pw.print(" zombie="); pw.println(p.zombie);
-    }
-
-    private void dumpHost(Host host, int index, PrintWriter pw) {
-        pw.print("  ["); pw.print(index); pw.print("] hostId=");
-                pw.print(host.hostId); pw.print(' ');
-                pw.print(host.packageName); pw.print('/');
-        pw.print(host.uid); pw.println(':');
-        pw.print("    callbacks="); pw.println(host.callbacks);
-        pw.print("    instances.size="); pw.print(host.instances.size());
-                pw.print(" zombie="); pw.println(host.zombie);
-    }
-
-    private void dumpAppWidgetId(AppWidgetId id, int index, PrintWriter pw) {
-        pw.print("  ["); pw.print(index); pw.print("] id=");
-                pw.println(id.appWidgetId);
-        pw.print("    hostId=");
-                pw.print(id.host.hostId); pw.print(' ');
-                pw.print(id.host.packageName); pw.print('/');
-                pw.println(id.host.uid);
-        if (id.provider != null) {
-            pw.print("    provider=");
-                    pw.println(id.provider.info.provider.flattenToShortString());
-        }
-        if (id.host != null) {
-            pw.print("    host.callbacks="); pw.println(id.host.callbacks);
-        }
-        if (id.views != null) {
-            pw.print("    views="); pw.println(id.views);
-        }
-    }
-
-    void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mAppWidgetIds) {
-            int N = mInstalledProviders.size();
-            pw.println("Providers:");
-            for (int i=0; i<N; i++) {
-                dumpProvider(mInstalledProviders.get(i), i, pw);
-            }
-
-            N = mAppWidgetIds.size();
-            pw.println(" ");
-            pw.println("AppWidgetIds:");
-            for (int i=0; i<N; i++) {
-                dumpAppWidgetId(mAppWidgetIds.get(i), i, pw);
-            }
-
-            N = mHosts.size();
-            pw.println(" ");
-            pw.println("Hosts:");
-            for (int i=0; i<N; i++) {
-                dumpHost(mHosts.get(i), i, pw);
-            }
-
-            N = mDeletedProviders.size();
-            pw.println(" ");
-            pw.println("Deleted Providers:");
-            for (int i=0; i<N; i++) {
-                dumpProvider(mDeletedProviders.get(i), i, pw);
-            }
-
-            N = mDeletedHosts.size();
-            pw.println(" ");
-            pw.println("Deleted Hosts:");
-            for (int i=0; i<N; i++) {
-                dumpHost(mDeletedHosts.get(i), i, pw);
-            }
-        }
-    }
-
-    private void ensureStateLoadedLocked() {
-        if (!mStateLoaded) {
-            if (!mHasFeature) {
-                return;
-            }
-            loadAppWidgetListLocked();
-            loadStateLocked();
-            mStateLoaded = true;
-        }
-    }
-
-    public int allocateAppWidgetId(String packageName, int hostId) {
-        int callingUid = enforceSystemOrCallingUid(packageName);
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return -1;
-            }
-            ensureStateLoadedLocked();
-            int appWidgetId = mNextAppWidgetId++;
-
-            Host host = lookupOrAddHostLocked(callingUid, packageName, hostId);
-
-            AppWidgetId id = new AppWidgetId();
-            id.appWidgetId = appWidgetId;
-            id.host = host;
-
-            host.instances.add(id);
-            mAppWidgetIds.add(id);
-
-            saveStateAsync();
-            if (DBG) log("Allocating AppWidgetId for " + packageName + " host=" + hostId
-                    + " id=" + appWidgetId);
-            return appWidgetId;
-        }
-    }
-
-    public void deleteAppWidgetId(int appWidgetId) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            ensureStateLoadedLocked();
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-            if (id != null) {
-                deleteAppWidgetLocked(id);
-                saveStateAsync();
-            }
-        }
-    }
-
-    public void deleteHost(int hostId) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            ensureStateLoadedLocked();
-            int callingUid = Binder.getCallingUid();
-            Host host = lookupHostLocked(callingUid, hostId);
-            if (host != null) {
-                deleteHostLocked(host);
-                saveStateAsync();
-            }
-        }
-    }
-
-    public void deleteAllHosts() {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            ensureStateLoadedLocked();
-            int callingUid = Binder.getCallingUid();
-            final int N = mHosts.size();
-            boolean changed = false;
-            for (int i = N - 1; i >= 0; i--) {
-                Host host = mHosts.get(i);
-                if (host.uidMatches(callingUid)) {
-                    deleteHostLocked(host);
-                    changed = true;
-                }
-            }
-            if (changed) {
-                saveStateAsync();
-            }
-        }
-    }
-
-    void deleteHostLocked(Host host) {
-        final int N = host.instances.size();
-        for (int i = N - 1; i >= 0; i--) {
-            AppWidgetId id = host.instances.get(i);
-            deleteAppWidgetLocked(id);
-        }
-        host.instances.clear();
-        mHosts.remove(host);
-        mDeletedHosts.add(host);
-        // it's gone or going away, abruptly drop the callback connection
-        host.callbacks = null;
-    }
-
-    void deleteAppWidgetLocked(AppWidgetId id) {
-        // We first unbind all services that are bound to this id
-        unbindAppWidgetRemoteViewsServicesLocked(id);
-
-        Host host = id.host;
-        host.instances.remove(id);
-        pruneHostLocked(host);
-
-        mAppWidgetIds.remove(id);
-
-        Provider p = id.provider;
-        if (p != null) {
-            p.instances.remove(id);
-            if (!p.zombie) {
-                // send the broacast saying that this appWidgetId has been deleted
-                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DELETED);
-                intent.setComponent(p.info.provider);
-                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
-                mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
-                if (p.instances.size() == 0) {
-                    // cancel the future updates
-                    cancelBroadcasts(p);
-
-                    // send the broacast saying that the provider is not in use any more
-                    intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_DISABLED);
-                    intent.setComponent(p.info.provider);
-                    mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
-                }
-            }
-        }
-    }
-
-    void cancelBroadcasts(Provider p) {
-        if (DBG) log("cancelBroadcasts for " + p);
-        if (p.broadcast != null) {
-            mAlarmManager.cancel(p.broadcast);
-            long token = Binder.clearCallingIdentity();
-            try {
-                p.broadcast.cancel();
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-            p.broadcast = null;
-        }
-    }
-
-    private void bindAppWidgetIdImpl(int appWidgetId, ComponentName provider, Bundle options) {
-        if (DBG) log("bindAppWidgetIdImpl appwid=" + appWidgetId
-                + " provider=" + provider);
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mAppWidgetIds) {
-                if (!mHasFeature) {
-                    return;
-                }
-                options = cloneIfLocalBinder(options);
-                ensureStateLoadedLocked();
-                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-                if (id == null) {
-                    throw new IllegalArgumentException("bad appWidgetId");
-                }
-                if (id.provider != null) {
-                    throw new IllegalArgumentException("appWidgetId " + appWidgetId
-                            + " already bound to " + id.provider.info.provider);
-                }
-                Provider p = lookupProviderLocked(provider);
-                if (p == null) {
-                    throw new IllegalArgumentException("not a appwidget provider: " + provider);
-                }
-                if (p.zombie) {
-                    throw new IllegalArgumentException("can't bind to a 3rd party provider in"
-                            + " safe mode: " + provider);
-                }
-
-                id.provider = p;
-                if (options == null) {
-                    options = new Bundle();
-                }
-                id.options = options;
-
-                // We need to provide a default value for the widget category if it is not specified
-                if (!options.containsKey(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)) {
-                    options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
-                            AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
-                }
-
-                p.instances.add(id);
-                int instancesSize = p.instances.size();
-                if (instancesSize == 1) {
-                    // tell the provider that it's ready
-                    sendEnableIntentLocked(p);
-                }
-
-                // send an update now -- We need this update now, and just for this appWidgetId.
-                // It's less critical when the next one happens, so when we schedule the next one,
-                // we add updatePeriodMillis to its start time. That time will have some slop,
-                // but that's okay.
-                sendUpdateIntentLocked(p, new int[] { appWidgetId });
-
-                // schedule the future updates
-                registerForBroadcastsLocked(p, getAppWidgetIds(p));
-                saveStateAsync();
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    public void bindAppWidgetId(int appWidgetId, ComponentName provider, Bundle options) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET,
-            "bindAppWidgetId appWidgetId=" + appWidgetId + " provider=" + provider);
-        bindAppWidgetIdImpl(appWidgetId, provider, options);
-    }
-
-    public boolean bindAppWidgetIdIfAllowed(
-            String packageName, int appWidgetId, ComponentName provider, Bundle options) {
-        if (!mHasFeature) {
-            return false;
-        }
-        try {
-            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET, null);
-        } catch (SecurityException se) {
-            if (!callerHasBindAppWidgetPermission(packageName)) {
-                return false;
-            }
-        }
-        bindAppWidgetIdImpl(appWidgetId, provider, options);
-        return true;
-    }
-
-    private boolean callerHasBindAppWidgetPermission(String packageName) {
-        int callingUid = Binder.getCallingUid();
-        try {
-            if (!UserHandle.isSameApp(callingUid, getUidForPackage(packageName))) {
-                return false;
-            }
-        } catch (Exception e) {
-            return false;
-        }
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            return mPackagesWithBindWidgetPermission.contains(packageName);
-        }
-    }
-
-    public boolean hasBindAppWidgetPermission(String packageName) {
-        if (!mHasFeature) {
-            return false;
-        }
-        mContext.enforceCallingPermission(
-                android.Manifest.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS,
-                "hasBindAppWidgetPermission packageName=" + packageName);
-
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            return mPackagesWithBindWidgetPermission.contains(packageName);
-        }
-    }
-
-    public void setBindAppWidgetPermission(String packageName, boolean permission) {
-        if (!mHasFeature) {
-            return;
-        }
-        mContext.enforceCallingPermission(
-                android.Manifest.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS,
-                "setBindAppWidgetPermission packageName=" + packageName);
-
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            if (permission) {
-                mPackagesWithBindWidgetPermission.add(packageName);
-            } else {
-                mPackagesWithBindWidgetPermission.remove(packageName);
-            }
-            saveStateAsync();
-        }
-    }
-
-    // Binds to a specific RemoteViewsService
-    public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder connection) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            ensureStateLoadedLocked();
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-            if (id == null) {
-                throw new IllegalArgumentException("bad appWidgetId");
-            }
-            final ComponentName componentName = intent.getComponent();
-            try {
-                final ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(componentName,
-                        PackageManager.GET_PERMISSIONS, mUserId);
-                if (!android.Manifest.permission.BIND_REMOTEVIEWS.equals(si.permission)) {
-                    throw new SecurityException("Selected service does not require "
-                            + android.Manifest.permission.BIND_REMOTEVIEWS + ": " + componentName);
-                }
-            } catch (RemoteException e) {
-                throw new IllegalArgumentException("Unknown component " + componentName);
-            }
-
-            // If there is already a connection made for this service intent, then disconnect from
-            // that first. (This does not allow multiple connections to the same service under
-            // the same key)
-            ServiceConnectionProxy conn = null;
-            FilterComparison fc = new FilterComparison(intent);
-            Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, fc);
-            if (mBoundRemoteViewsServices.containsKey(key)) {
-                conn = (ServiceConnectionProxy) mBoundRemoteViewsServices.get(key);
-                conn.disconnect();
-                mContext.unbindService(conn);
-                mBoundRemoteViewsServices.remove(key);
-            }
-
-            int userId = UserHandle.getUserId(id.provider.uid);
-            if (userId != mUserId) {
-                Slog.w(TAG, "AppWidgetServiceImpl of user " + mUserId
-                        + " binding to provider on user " + userId);
-            }
-            // Bind to the RemoteViewsService (which will trigger a callback to the
-            // RemoteViewsAdapter.onServiceConnected())
-            final long token = Binder.clearCallingIdentity();
-            try {
-                conn = new ServiceConnectionProxy(key, connection);
-                mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
-                        new UserHandle(userId));
-                mBoundRemoteViewsServices.put(key, conn);
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-
-            // Add it to the mapping of RemoteViewsService to appWidgetIds so that we can determine
-            // when we can call back to the RemoteViewsService later to destroy associated
-            // factories.
-            incrementAppWidgetServiceRefCount(appWidgetId, fc);
-        }
-    }
-
-    // Unbinds from a specific RemoteViewsService
-    public void unbindRemoteViewsService(int appWidgetId, Intent intent) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            ensureStateLoadedLocked();
-            // Unbind from the RemoteViewsService (which will trigger a callback to the bound
-            // RemoteViewsAdapter)
-            Pair<Integer, FilterComparison> key = Pair.create(appWidgetId, new FilterComparison(
-                    intent));
-            if (mBoundRemoteViewsServices.containsKey(key)) {
-                // We don't need to use the appWidgetId until after we are sure there is something
-                // to unbind. Note that this may mask certain issues with apps calling unbind()
-                // more than necessary.
-                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-                if (id == null) {
-                    throw new IllegalArgumentException("bad appWidgetId");
-                }
-
-                ServiceConnectionProxy conn = (ServiceConnectionProxy) mBoundRemoteViewsServices
-                        .get(key);
-                conn.disconnect();
-                mContext.unbindService(conn);
-                mBoundRemoteViewsServices.remove(key);
-            }
-        }
-    }
-
-    // Unbinds from a RemoteViewsService when we delete an app widget
-    private void unbindAppWidgetRemoteViewsServicesLocked(AppWidgetId id) {
-        int appWidgetId = id.appWidgetId;
-        // Unbind all connections to Services bound to this AppWidgetId
-        Iterator<Pair<Integer, Intent.FilterComparison>> it = mBoundRemoteViewsServices.keySet()
-                .iterator();
-        while (it.hasNext()) {
-            final Pair<Integer, Intent.FilterComparison> key = it.next();
-            if (key.first.intValue() == appWidgetId) {
-                final ServiceConnectionProxy conn = (ServiceConnectionProxy) mBoundRemoteViewsServices
-                        .get(key);
-                conn.disconnect();
-                mContext.unbindService(conn);
-                it.remove();
-            }
-        }
-
-        // Check if we need to destroy any services (if no other app widgets are
-        // referencing the same service)
-        decrementAppWidgetServiceRefCount(id);
-    }
-
-    // Destroys the cached factory on the RemoteViewsService's side related to the specified intent
-    private void destroyRemoteViewsService(final Intent intent, AppWidgetId id) {
-        final ServiceConnection conn = new ServiceConnection() {
-            @Override
-            public void onServiceConnected(ComponentName name, IBinder service) {
-                final IRemoteViewsFactory cb = IRemoteViewsFactory.Stub.asInterface(service);
-                try {
-                    cb.onDestroy(intent);
-                } catch (RemoteException e) {
-                    e.printStackTrace();
-                } catch (RuntimeException e) {
-                    e.printStackTrace();
-                }
-                mContext.unbindService(this);
-            }
-
-            @Override
-            public void onServiceDisconnected(android.content.ComponentName name) {
-                // Do nothing
-            }
-        };
-
-        int userId = UserHandle.getUserId(id.provider.uid);
-        // Bind to the service and remove the static intent->factory mapping in the
-        // RemoteViewsService.
-        final long token = Binder.clearCallingIdentity();
-        try {
-            mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
-                    new UserHandle(userId));
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Adds to the ref-count for a given RemoteViewsService intent
-    private void incrementAppWidgetServiceRefCount(int appWidgetId, FilterComparison fc) {
-        HashSet<Integer> appWidgetIds = null;
-        if (mRemoteViewsServicesAppWidgets.containsKey(fc)) {
-            appWidgetIds = mRemoteViewsServicesAppWidgets.get(fc);
-        } else {
-            appWidgetIds = new HashSet<Integer>();
-            mRemoteViewsServicesAppWidgets.put(fc, appWidgetIds);
-        }
-        appWidgetIds.add(appWidgetId);
-    }
-
-    // Subtracts from the ref-count for a given RemoteViewsService intent, prompting a delete if
-    // the ref-count reaches zero.
-    private void decrementAppWidgetServiceRefCount(AppWidgetId id) {
-        Iterator<FilterComparison> it = mRemoteViewsServicesAppWidgets.keySet().iterator();
-        while (it.hasNext()) {
-            final FilterComparison key = it.next();
-            final HashSet<Integer> ids = mRemoteViewsServicesAppWidgets.get(key);
-            if (ids.remove(id.appWidgetId)) {
-                // If we have removed the last app widget referencing this service, then we
-                // should destroy it and remove it from this set
-                if (ids.isEmpty()) {
-                    destroyRemoteViewsService(key.getIntent(), id);
-                    it.remove();
-                }
-            }
-        }
-    }
-
-    public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return null;
-            }
-            ensureStateLoadedLocked();
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-            if (id != null && id.provider != null && !id.provider.zombie) {
-                return cloneIfLocalBinder(id.provider.info);
-            }
-            return null;
-        }
-    }
-
-    public RemoteViews getAppWidgetViews(int appWidgetId) {
-        if (DBG) log("getAppWidgetViews id=" + appWidgetId);
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return null;
-            }
-            ensureStateLoadedLocked();
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-            if (id != null) {
-                return cloneIfLocalBinder(id.views);
-            }
-            if (DBG) log("   couldn't find appwidgetid");
-            return null;
-        }
-    }
-
-    public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return new ArrayList<AppWidgetProviderInfo>(0);
-            }
-            ensureStateLoadedLocked();
-            final int N = mInstalledProviders.size();
-            ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>(N);
-            for (int i = 0; i < N; i++) {
-                Provider p = mInstalledProviders.get(i);
-                if (!p.zombie && (p.info.widgetCategory & categoryFilter) != 0) {
-                    result.add(cloneIfLocalBinder(p.info));
-                }
-            }
-            return result;
-        }
-    }
-
-    public void updateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
-        if (!mHasFeature) {
-            return;
-        }
-        if (appWidgetIds == null) {
-            return;
-        }
-        if (DBG) log("updateAppWidgetIds views: " + views);
-        int bitmapMemoryUsage = 0;
-        if (views != null) {
-            bitmapMemoryUsage = views.estimateMemoryUsage();
-        }
-        if (bitmapMemoryUsage > mMaxWidgetBitmapMemory) {
-            throw new IllegalArgumentException("RemoteViews for widget update exceeds maximum" +
-                    " bitmap memory usage (used: " + bitmapMemoryUsage + ", max: " +
-                    mMaxWidgetBitmapMemory + ") The total memory cannot exceed that required to" +
-                    " fill the device's screen once.");
-        }
-
-        if (appWidgetIds.length == 0) {
-            return;
-        }
-        final int N = appWidgetIds.length;
-
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            for (int i = 0; i < N; i++) {
-                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
-                updateAppWidgetInstanceLocked(id, views);
-            }
-        }
-    }
-
-    private void saveStateAsync() {
-        mSaveStateHandler.post(mSaveStateRunnable);
-    }
-
-    private final Runnable mSaveStateRunnable = new Runnable() {
-        @Override
-        public void run() {
-            synchronized (mAppWidgetIds) {
-                ensureStateLoadedLocked();
-                saveStateLocked();
-            }
-        }
-    };
-
-    public void updateAppWidgetOptions(int appWidgetId, Bundle options) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            options = cloneIfLocalBinder(options);
-            ensureStateLoadedLocked();
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-
-            if (id == null) {
-                return;
-            }
-
-            Provider p = id.provider;
-            // Merge the options
-            id.options.putAll(options);
-
-            // send the broacast saying that this appWidgetId has been deleted
-            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED);
-            intent.setComponent(p.info.provider);
-            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id.appWidgetId);
-            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, id.options);
-            mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
-            saveStateAsync();
-        }
-    }
-
-    public Bundle getAppWidgetOptions(int appWidgetId) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return Bundle.EMPTY;
-            }
-            ensureStateLoadedLocked();
-            AppWidgetId id = lookupAppWidgetIdLocked(appWidgetId);
-            if (id != null && id.options != null) {
-                return cloneIfLocalBinder(id.options);
-            } else {
-                return Bundle.EMPTY;
-            }
-        }
-    }
-
-    public void partiallyUpdateAppWidgetIds(int[] appWidgetIds, RemoteViews views) {
-        if (!mHasFeature) {
-            return;
-        }
-        if (appWidgetIds == null) {
-            return;
-        }
-        if (appWidgetIds.length == 0) {
-            return;
-        }
-        final int N = appWidgetIds.length;
-
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            for (int i = 0; i < N; i++) {
-                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
-                if (id == null) {
-                    Slog.w(TAG, "widget id " + appWidgetIds[i] + " not found!");
-                } else if (id.views != null) {
-                    // Only trigger a partial update for a widget if it has received a full update
-                    updateAppWidgetInstanceLocked(id, views, true);
-                }
-            }
-        }
-    }
-
-    public void notifyAppWidgetViewDataChanged(int[] appWidgetIds, int viewId) {
-        if (!mHasFeature) {
-            return;
-        }
-        if (appWidgetIds == null) {
-            return;
-        }
-        if (appWidgetIds.length == 0) {
-            return;
-        }
-        final int N = appWidgetIds.length;
-
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            for (int i = 0; i < N; i++) {
-                AppWidgetId id = lookupAppWidgetIdLocked(appWidgetIds[i]);
-                notifyAppWidgetViewDataChangedInstanceLocked(id, viewId);
-            }
-        }
-    }
-
-    public void updateAppWidgetProvider(ComponentName provider, RemoteViews views) {
-        if (!mHasFeature) {
-            return;
-        }
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            Provider p = lookupProviderLocked(provider);
-            if (p == null) {
-                Slog.w(TAG, "updateAppWidgetProvider: provider doesn't exist: " + provider);
-                return;
-            }
-            ArrayList<AppWidgetId> instances = p.instances;
-            final int callingUid = Binder.getCallingUid();
-            final int N = instances.size();
-            for (int i = 0; i < N; i++) {
-                AppWidgetId id = instances.get(i);
-                if (canAccessAppWidgetId(id, callingUid)) {
-                    updateAppWidgetInstanceLocked(id, views);
-                }
-            }
-        }
-    }
-
-    void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views) {
-        updateAppWidgetInstanceLocked(id, views, false);
-    }
-
-    void updateAppWidgetInstanceLocked(AppWidgetId id, RemoteViews views, boolean isPartialUpdate) {
-        // allow for stale appWidgetIds and other badness
-        // lookup also checks that the calling process can access the appWidgetId
-        // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
-        if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
-
-            if (!isPartialUpdate) {
-                // For a full update we replace the RemoteViews completely.
-                id.views = views;
-            } else {
-                // For a partial update, we merge the new RemoteViews with the old.
-                id.views.mergeRemoteViews(views);
-            }
-
-            // is anyone listening?
-            if (id.host.callbacks != null) {
-                try {
-                    // the lock is held, but this is a oneway call
-                    id.host.callbacks.updateAppWidget(id.appWidgetId, views, mUserId);
-                } catch (RemoteException e) {
-                    // It failed; remove the callback. No need to prune because
-                    // we know that this host is still referenced by this instance.
-                    id.host.callbacks = null;
-                }
-            }
-        }
-    }
-
-    void notifyAppWidgetViewDataChangedInstanceLocked(AppWidgetId id, int viewId) {
-        // allow for stale appWidgetIds and other badness
-        // lookup also checks that the calling process can access the appWidgetId
-        // drop unbound appWidgetIds (shouldn't be possible under normal circumstances)
-        if (id != null && id.provider != null && !id.provider.zombie && !id.host.zombie) {
-            // is anyone listening?
-            if (id.host.callbacks != null) {
-                try {
-                    // the lock is held, but this is a oneway call
-                    id.host.callbacks.viewDataChanged(id.appWidgetId, viewId, mUserId);
-                } catch (RemoteException e) {
-                    // It failed; remove the callback. No need to prune because
-                    // we know that this host is still referenced by this instance.
-                    id.host.callbacks = null;
-                }
-            }
-
-            // If the host is unavailable, then we call the associated
-            // RemoteViewsFactory.onDataSetChanged() directly
-            if (id.host.callbacks == null) {
-                Set<FilterComparison> keys = mRemoteViewsServicesAppWidgets.keySet();
-                for (FilterComparison key : keys) {
-                    if (mRemoteViewsServicesAppWidgets.get(key).contains(id.appWidgetId)) {
-                        Intent intent = key.getIntent();
-
-                        final ServiceConnection conn = new ServiceConnection() {
-                            @Override
-                            public void onServiceConnected(ComponentName name, IBinder service) {
-                                IRemoteViewsFactory cb = IRemoteViewsFactory.Stub
-                                        .asInterface(service);
-                                try {
-                                    cb.onDataSetChangedAsync();
-                                } catch (RemoteException e) {
-                                    e.printStackTrace();
-                                } catch (RuntimeException e) {
-                                    e.printStackTrace();
-                                }
-                                mContext.unbindService(this);
-                            }
-
-                            @Override
-                            public void onServiceDisconnected(android.content.ComponentName name) {
-                                // Do nothing
-                            }
-                        };
-
-                        int userId = UserHandle.getUserId(id.provider.uid);
-                        // Bind to the service and call onDataSetChanged()
-                        final long token = Binder.clearCallingIdentity();
-                        try {
-                            mContext.bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE,
-                                    new UserHandle(userId));
-                        } finally {
-                            Binder.restoreCallingIdentity(token);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    private boolean isLocalBinder() {
-        return Process.myPid() == Binder.getCallingPid();
-    }
-
-    private RemoteViews cloneIfLocalBinder(RemoteViews rv) {
-        if (isLocalBinder() && rv != null) {
-            return rv.clone();
-        }
-        return rv;
-    }
-
-    private AppWidgetProviderInfo cloneIfLocalBinder(AppWidgetProviderInfo info) {
-        if (isLocalBinder() && info != null) {
-            return info.clone();
-        }
-        return info;
-    }
-
-    private Bundle cloneIfLocalBinder(Bundle bundle) {
-        // Note: this is only a shallow copy. For now this will be fine, but it could be problematic
-        // if we start adding objects to the options. Further, it would only be an issue if keyguard
-        // used such options.
-        if (isLocalBinder() && bundle != null) {
-            return (Bundle) bundle.clone();
-        }
-        return bundle;
-    }
-
-    public int[] startListening(IAppWidgetHost callbacks, String packageName, int hostId,
-            List<RemoteViews> updatedViews) {
-        if (!mHasFeature) {
-            return new int[0];
-        }
-        int callingUid = enforceCallingUid(packageName);
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            Host host = lookupOrAddHostLocked(callingUid, packageName, hostId);
-            host.callbacks = callbacks;
-
-            updatedViews.clear();
-
-            ArrayList<AppWidgetId> instances = host.instances;
-            int N = instances.size();
-            int[] updatedIds = new int[N];
-            for (int i = 0; i < N; i++) {
-                AppWidgetId id = instances.get(i);
-                updatedIds[i] = id.appWidgetId;
-                updatedViews.add(cloneIfLocalBinder(id.views));
-            }
-            return updatedIds;
-        }
-    }
-
-    public void stopListening(int hostId) {
-        synchronized (mAppWidgetIds) {
-            if (!mHasFeature) {
-                return;
-            }
-            ensureStateLoadedLocked();
-            Host host = lookupHostLocked(Binder.getCallingUid(), hostId);
-            if (host != null) {
-                host.callbacks = null;
-                pruneHostLocked(host);
-            }
-        }
-    }
-
-    boolean canAccessAppWidgetId(AppWidgetId id, int callingUid) {
-        if (id.host.uidMatches(callingUid)) {
-            // Apps hosting the AppWidget have access to it.
-            return true;
-        }
-        if (id.provider != null && id.provider.uid == callingUid) {
-            // Apps providing the AppWidget have access to it (if the appWidgetId has been bound)
-            return true;
-        }
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.BIND_APPWIDGET) == PackageManager.PERMISSION_GRANTED) {
-            // Apps that can bind have access to all appWidgetIds.
-            return true;
-        }
-        // Nobody else can access it.
-        return false;
-    }
-
-    AppWidgetId lookupAppWidgetIdLocked(int appWidgetId) {
-        int callingUid = Binder.getCallingUid();
-        final int N = mAppWidgetIds.size();
-        for (int i = 0; i < N; i++) {
-            AppWidgetId id = mAppWidgetIds.get(i);
-            if (id.appWidgetId == appWidgetId && canAccessAppWidgetId(id, callingUid)) {
-                return id;
-            }
-        }
-        return null;
-    }
-
-    Provider lookupProviderLocked(ComponentName provider) {
-        final int N = mInstalledProviders.size();
-        for (int i = 0; i < N; i++) {
-            Provider p = mInstalledProviders.get(i);
-            if (p.info.provider.equals(provider)) {
-                return p;
-            }
-        }
-        return null;
-    }
-
-    Host lookupHostLocked(int uid, int hostId) {
-        final int N = mHosts.size();
-        for (int i = 0; i < N; i++) {
-            Host h = mHosts.get(i);
-            if (h.uidMatches(uid) && h.hostId == hostId) {
-                return h;
-            }
-        }
-        return null;
-    }
-
-    Host lookupOrAddHostLocked(int uid, String packageName, int hostId) {
-        final int N = mHosts.size();
-        for (int i = 0; i < N; i++) {
-            Host h = mHosts.get(i);
-            if (h.hostId == hostId && h.packageName.equals(packageName)) {
-                return h;
-            }
-        }
-        Host host = new Host();
-        host.packageName = packageName;
-        host.uid = uid;
-        host.hostId = hostId;
-        mHosts.add(host);
-        return host;
-    }
-
-    void pruneHostLocked(Host host) {
-        if (host.instances.size() == 0 && host.callbacks == null) {
-            mHosts.remove(host);
-        }
-    }
-
-    void loadAppWidgetListLocked() {
-        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
-        try {
-            List<ResolveInfo> broadcastReceivers = mPm.queryIntentReceivers(intent,
-                    intent.resolveTypeIfNeeded(mContext.getContentResolver()),
-                    PackageManager.GET_META_DATA, mUserId);
-
-            final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
-            for (int i = 0; i < N; i++) {
-                ResolveInfo ri = broadcastReceivers.get(i);
-                addProviderLocked(ri);
-            }
-        } catch (RemoteException re) {
-            // Shouldn't happen, local call
-        }
-    }
-
-    boolean addProviderLocked(ResolveInfo ri) {
-        if ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
-            return false;
-        }
-        if (!ri.activityInfo.isEnabled()) {
-            return false;
-        }
-        Provider p = parseProviderInfoXml(new ComponentName(ri.activityInfo.packageName,
-                ri.activityInfo.name), ri);
-        if (p != null) {
-            mInstalledProviders.add(p);
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    void removeProviderLocked(int index, Provider p) {
-        int N = p.instances.size();
-        for (int i = 0; i < N; i++) {
-            AppWidgetId id = p.instances.get(i);
-            // Call back with empty RemoteViews
-            updateAppWidgetInstanceLocked(id, null);
-            // Stop telling the host about updates for this from now on
-            cancelBroadcasts(p);
-            // clear out references to this appWidgetId
-            id.host.instances.remove(id);
-            mAppWidgetIds.remove(id);
-            id.provider = null;
-            pruneHostLocked(id.host);
-            id.host = null;
-        }
-        p.instances.clear();
-        mInstalledProviders.remove(index);
-        mDeletedProviders.add(p);
-        // no need to send the DISABLE broadcast, since the receiver is gone anyway
-        cancelBroadcasts(p);
-    }
-
-    void sendEnableIntentLocked(Provider p) {
-        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_ENABLED);
-        intent.setComponent(p.info.provider);
-        mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
-    }
-
-    void sendUpdateIntentLocked(Provider p, int[] appWidgetIds) {
-        if (appWidgetIds != null && appWidgetIds.length > 0) {
-            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
-            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
-            intent.setComponent(p.info.provider);
-            mContext.sendBroadcastAsUser(intent, new UserHandle(mUserId));
-        }
-    }
-
-    void registerForBroadcastsLocked(Provider p, int[] appWidgetIds) {
-        if (p.info.updatePeriodMillis > 0) {
-            // if this is the first instance, set the alarm. otherwise,
-            // rely on the fact that we've already set it and that
-            // PendingIntent.getBroadcast will update the extras.
-            boolean alreadyRegistered = p.broadcast != null;
-            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
-            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
-            intent.setComponent(p.info.provider);
-            long token = Binder.clearCallingIdentity();
-            try {
-                p.broadcast = PendingIntent.getBroadcastAsUser(mContext, 1, intent,
-                        PendingIntent.FLAG_UPDATE_CURRENT, new UserHandle(mUserId));
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-            if (!alreadyRegistered) {
-                long period = p.info.updatePeriodMillis;
-                if (period < MIN_UPDATE_PERIOD) {
-                    period = MIN_UPDATE_PERIOD;
-                }
-                mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock
-                        .elapsedRealtime()
-                        + period, period, p.broadcast);
-            }
-        }
-    }
-
-    static int[] getAppWidgetIds(Provider p) {
-        int instancesSize = p.instances.size();
-        int appWidgetIds[] = new int[instancesSize];
-        for (int i = 0; i < instancesSize; i++) {
-            appWidgetIds[i] = p.instances.get(i).appWidgetId;
-        }
-        return appWidgetIds;
-    }
-
-    public int[] getAppWidgetIds(ComponentName provider) {
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            Provider p = lookupProviderLocked(provider);
-            if (p != null && Binder.getCallingUid() == p.uid) {
-                return getAppWidgetIds(p);
-            } else {
-                return new int[0];
-            }
-        }
-    }
-
-    static int[] getAppWidgetIds(Host h) {
-        int instancesSize = h.instances.size();
-        int appWidgetIds[] = new int[instancesSize];
-        for (int i = 0; i < instancesSize; i++) {
-            appWidgetIds[i] = h.instances.get(i).appWidgetId;
-        }
-        return appWidgetIds;
-    }
-
-    public int[] getAppWidgetIdsForHost(int hostId) {
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            int callingUid = Binder.getCallingUid();
-            Host host = lookupHostLocked(callingUid, hostId);
-            if (host != null) {
-                return getAppWidgetIds(host);
-            } else {
-                return new int[0];
-            }
-        }
-    }
-
-    private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) {
-        Provider p = null;
-
-        ActivityInfo activityInfo = ri.activityInfo;
-        XmlResourceParser parser = null;
-        try {
-            parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(),
-                    AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
-            if (parser == null) {
-                Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER
-                        + " meta-data for " + "AppWidget provider '" + component + '\'');
-                return null;
-            }
-
-            AttributeSet attrs = Xml.asAttributeSet(parser);
-
-            int type;
-            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                    && type != XmlPullParser.START_TAG) {
-                // drain whitespace, comments, etc.
-            }
-
-            String nodeName = parser.getName();
-            if (!"appwidget-provider".equals(nodeName)) {
-                Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for"
-                        + " AppWidget provider '" + component + '\'');
-                return null;
-            }
-
-            p = new Provider();
-            AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo();
-            info.provider = component;
-            p.uid = activityInfo.applicationInfo.uid;
-
-            Resources res = mContext.getPackageManager()
-                    .getResourcesForApplicationAsUser(activityInfo.packageName, mUserId);
-
-            TypedArray sa = res.obtainAttributes(attrs,
-                    com.android.internal.R.styleable.AppWidgetProviderInfo);
-
-            // These dimensions has to be resolved in the application's context.
-            // We simply send back the raw complex data, which will be
-            // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
-            TypedValue value = sa
-                    .peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
-            info.minWidth = value != null ? value.data : 0;
-            value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
-            info.minHeight = value != null ? value.data : 0;
-            value = sa.peekValue(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
-            info.minResizeWidth = value != null ? value.data : info.minWidth;
-            value = sa.peekValue(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
-            info.minResizeHeight = value != null ? value.data : info.minHeight;
-            info.updatePeriodMillis = sa.getInt(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
-            info.initialLayout = sa.getResourceId(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
-            info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.
-                    AppWidgetProviderInfo_initialKeyguardLayout, 0);
-            String className = sa
-                    .getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
-            if (className != null) {
-                info.configure = new ComponentName(component.getPackageName(), className);
-            }
-            info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
-            info.icon = ri.getIconResource();
-            info.previewImage = sa.getResourceId(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
-            info.autoAdvanceViewId = sa.getResourceId(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
-            info.resizeMode = sa.getInt(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode,
-                    AppWidgetProviderInfo.RESIZE_NONE);
-            info.widgetCategory = sa.getInt(
-                    com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory,
-                    AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
-
-            sa.recycle();
-        } catch (Exception e) {
-            // Ok to catch Exception here, because anything going wrong because
-            // of what a client process passes to us should not be fatal for the
-            // system process.
-            Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e);
-            return null;
-        } finally {
-            if (parser != null)
-                parser.close();
-        }
-        return p;
-    }
-
-    int getUidForPackage(String packageName) throws PackageManager.NameNotFoundException {
-        PackageInfo pkgInfo = null;
-        try {
-            pkgInfo = mPm.getPackageInfo(packageName, 0, mUserId);
-        } catch (RemoteException re) {
-            // Shouldn't happen, local call
-        }
-        if (pkgInfo == null || pkgInfo.applicationInfo == null) {
-            throw new PackageManager.NameNotFoundException();
-        }
-        return pkgInfo.applicationInfo.uid;
-    }
-
-    int enforceSystemOrCallingUid(String packageName) throws IllegalArgumentException {
-        int callingUid = Binder.getCallingUid();
-        if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID || callingUid == 0) {
-            return callingUid;
-        }
-        return enforceCallingUid(packageName);
-    }
-
-    int enforceCallingUid(String packageName) throws IllegalArgumentException {
-        int callingUid = Binder.getCallingUid();
-        int packageUid;
-        try {
-            packageUid = getUidForPackage(packageName);
-        } catch (PackageManager.NameNotFoundException ex) {
-            throw new IllegalArgumentException("packageName and uid don't match packageName="
-                    + packageName);
-        }
-        if (!UserHandle.isSameApp(callingUid, packageUid)) {
-            throw new IllegalArgumentException("packageName and uid don't match packageName="
-                    + packageName);
-        }
-        return callingUid;
-    }
-
-    void sendInitialBroadcasts() {
-        synchronized (mAppWidgetIds) {
-            ensureStateLoadedLocked();
-            final int N = mInstalledProviders.size();
-            for (int i = 0; i < N; i++) {
-                Provider p = mInstalledProviders.get(i);
-                if (p.instances.size() > 0) {
-                    sendEnableIntentLocked(p);
-                    int[] appWidgetIds = getAppWidgetIds(p);
-                    sendUpdateIntentLocked(p, appWidgetIds);
-                    registerForBroadcastsLocked(p, appWidgetIds);
-                }
-            }
-        }
-    }
-
-    // only call from initialization -- it assumes that the data structures are all empty
-    void loadStateLocked() {
-        AtomicFile file = savedStateFile();
-        try {
-            FileInputStream stream = file.openRead();
-            readStateFromFileLocked(stream);
-
-            if (stream != null) {
-                try {
-                    stream.close();
-                } catch (IOException e) {
-                    Slog.w(TAG, "Failed to close state FileInputStream " + e);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "Failed to read state: " + e);
-        }
-    }
-
-    void saveStateLocked() {
-        if (!mHasFeature) {
-            return;
-        }
-        AtomicFile file = savedStateFile();
-        FileOutputStream stream;
-        try {
-            stream = file.startWrite();
-            if (writeStateToFileLocked(stream)) {
-                file.finishWrite(stream);
-            } else {
-                file.failWrite(stream);
-                Slog.w(TAG, "Failed to save state, restoring backup.");
-            }
-        } catch (IOException e) {
-            Slog.w(TAG, "Failed open state file for write: " + e);
-        }
-    }
-
-    boolean writeStateToFileLocked(FileOutputStream stream) {
-        int N;
-
-        try {
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(stream, "utf-8");
-            out.startDocument(null, true);
-            out.startTag(null, "gs");
-            out.attribute(null, "version", String.valueOf(CURRENT_VERSION));
-            int providerIndex = 0;
-            N = mInstalledProviders.size();
-            for (int i = 0; i < N; i++) {
-                Provider p = mInstalledProviders.get(i);
-                if (p.instances.size() > 0) {
-                    out.startTag(null, "p");
-                    out.attribute(null, "pkg", p.info.provider.getPackageName());
-                    out.attribute(null, "cl", p.info.provider.getClassName());
-                    out.endTag(null, "p");
-                    p.tag = providerIndex;
-                    providerIndex++;
-                }
-            }
-
-            N = mHosts.size();
-            for (int i = 0; i < N; i++) {
-                Host host = mHosts.get(i);
-                out.startTag(null, "h");
-                out.attribute(null, "pkg", host.packageName);
-                out.attribute(null, "id", Integer.toHexString(host.hostId));
-                out.endTag(null, "h");
-                host.tag = i;
-            }
-
-            N = mAppWidgetIds.size();
-            for (int i = 0; i < N; i++) {
-                AppWidgetId id = mAppWidgetIds.get(i);
-                out.startTag(null, "g");
-                out.attribute(null, "id", Integer.toHexString(id.appWidgetId));
-                out.attribute(null, "h", Integer.toHexString(id.host.tag));
-                if (id.provider != null) {
-                    out.attribute(null, "p", Integer.toHexString(id.provider.tag));
-                }
-                if (id.options != null) {
-                    out.attribute(null, "min_width", Integer.toHexString(id.options.getInt(
-                            AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH)));
-                    out.attribute(null, "min_height", Integer.toHexString(id.options.getInt(
-                            AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT)));
-                    out.attribute(null, "max_width", Integer.toHexString(id.options.getInt(
-                            AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)));
-                    out.attribute(null, "max_height", Integer.toHexString(id.options.getInt(
-                            AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)));
-                    out.attribute(null, "host_category", Integer.toHexString(id.options.getInt(
-                            AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY)));
-                }
-                out.endTag(null, "g");
-            }
-
-            Iterator<String> it = mPackagesWithBindWidgetPermission.iterator();
-            while (it.hasNext()) {
-                out.startTag(null, "b");
-                out.attribute(null, "packageName", it.next());
-                out.endTag(null, "b");
-            }
-
-            out.endTag(null, "gs");
-
-            out.endDocument();
-            return true;
-        } catch (IOException e) {
-            Slog.w(TAG, "Failed to write state: " + e);
-            return false;
-        }
-    }
-
-    @SuppressWarnings("unused")
-    void readStateFromFileLocked(FileInputStream stream) {
-        boolean success = false;
-        int version = 0;
-        try {
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(stream, null);
-
-            int type;
-            int providerIndex = 0;
-            HashMap<Integer, Provider> loadedProviders = new HashMap<Integer, Provider>();
-            do {
-                type = parser.next();
-                if (type == XmlPullParser.START_TAG) {
-                    String tag = parser.getName();
-                    if ("gs".equals(tag)) {
-                        String attributeValue = parser.getAttributeValue(null, "version");
-                        try {
-                            version = Integer.parseInt(attributeValue);
-                        } catch (NumberFormatException e) {
-                            version = 0;
-                        }
-                    } else if ("p".equals(tag)) {
-                        // TODO: do we need to check that this package has the same signature
-                        // as before?
-                        String pkg = parser.getAttributeValue(null, "pkg");
-                        String cl = parser.getAttributeValue(null, "cl");
-
-                        final IPackageManager packageManager = AppGlobals.getPackageManager();
-                        try {
-                            packageManager.getReceiverInfo(new ComponentName(pkg, cl), 0, mUserId);
-                        } catch (RemoteException e) {
-                            String[] pkgs = mContext.getPackageManager()
-                                    .currentToCanonicalPackageNames(new String[] { pkg });
-                            pkg = pkgs[0];
-                        }
-
-                        Provider p = lookupProviderLocked(new ComponentName(pkg, cl));
-                        if (p == null && mSafeMode) {
-                            // if we're in safe mode, make a temporary one
-                            p = new Provider();
-                            p.info = new AppWidgetProviderInfo();
-                            p.info.provider = new ComponentName(pkg, cl);
-                            p.zombie = true;
-                            mInstalledProviders.add(p);
-                        }
-                        if (p != null) {
-                            // if it wasn't uninstalled or something
-                            loadedProviders.put(providerIndex, p);
-                        }
-                        providerIndex++;
-                    } else if ("h".equals(tag)) {
-                        Host host = new Host();
-
-                        // TODO: do we need to check that this package has the same signature
-                        // as before?
-                        host.packageName = parser.getAttributeValue(null, "pkg");
-                        try {
-                            host.uid = getUidForPackage(host.packageName);
-                        } catch (PackageManager.NameNotFoundException ex) {
-                            host.zombie = true;
-                        }
-                        if (!host.zombie || mSafeMode) {
-                            // In safe mode, we don't discard the hosts we don't recognize
-                            // so that they're not pruned from our list. Otherwise, we do.
-                            host.hostId = Integer
-                                    .parseInt(parser.getAttributeValue(null, "id"), 16);
-                            mHosts.add(host);
-                        }
-                    } else if ("b".equals(tag)) {
-                        String packageName = parser.getAttributeValue(null, "packageName");
-                        if (packageName != null) {
-                            mPackagesWithBindWidgetPermission.add(packageName);
-                        }
-                    } else if ("g".equals(tag)) {
-                        AppWidgetId id = new AppWidgetId();
-                        id.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
-                        if (id.appWidgetId >= mNextAppWidgetId) {
-                            mNextAppWidgetId = id.appWidgetId + 1;
-                        }
-
-                        Bundle options = new Bundle();
-                        String minWidthString = parser.getAttributeValue(null, "min_width");
-                        if (minWidthString != null) {
-                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH,
-                                    Integer.parseInt(minWidthString, 16));
-                        }
-                        String minHeightString = parser.getAttributeValue(null, "min_height");
-                        if (minHeightString != null) {
-                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT,
-                                    Integer.parseInt(minHeightString, 16));
-                        }
-                        String maxWidthString = parser.getAttributeValue(null, "max_width");
-                        if (maxWidthString != null) {
-                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH,
-                                    Integer.parseInt(maxWidthString, 16));
-                        }
-                        String maxHeightString = parser.getAttributeValue(null, "max_height");
-                        if (maxHeightString != null) {
-                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT,
-                                    Integer.parseInt(maxHeightString, 16));
-                        }
-                        String categoryString = parser.getAttributeValue(null, "host_category");
-                        if (categoryString != null) {
-                            options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
-                                    Integer.parseInt(categoryString, 16));
-                        }
-                        id.options = options;
-
-                        String providerString = parser.getAttributeValue(null, "p");
-                        if (providerString != null) {
-                            // there's no provider if it hasn't been bound yet.
-                            // maybe we don't have to save this, but it brings the system
-                            // to the state it was in.
-                            int pIndex = Integer.parseInt(providerString, 16);
-                            id.provider = loadedProviders.get(pIndex);
-                            if (false) {
-                                Slog.d(TAG, "bound appWidgetId=" + id.appWidgetId + " to provider "
-                                        + pIndex + " which is " + id.provider);
-                            }
-                            if (id.provider == null) {
-                                // This provider is gone. We just let the host figure out
-                                // that this happened when it fails to load it.
-                                continue;
-                            }
-                        }
-
-                        int hIndex = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
-                        id.host = mHosts.get(hIndex);
-                        if (id.host == null) {
-                            // This host is gone.
-                            continue;
-                        }
-
-                        if (id.provider != null) {
-                            id.provider.instances.add(id);
-                        }
-                        id.host.instances.add(id);
-                        mAppWidgetIds.add(id);
-                    }
-                }
-            } while (type != XmlPullParser.END_DOCUMENT);
-            success = true;
-        } catch (NullPointerException e) {
-            Slog.w(TAG, "failed parsing " + e);
-        } catch (NumberFormatException e) {
-            Slog.w(TAG, "failed parsing " + e);
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "failed parsing " + e);
-        } catch (IOException e) {
-            Slog.w(TAG, "failed parsing " + e);
-        } catch (IndexOutOfBoundsException e) {
-            Slog.w(TAG, "failed parsing " + e);
-        }
-
-        if (success) {
-            // delete any hosts that didn't manage to get connected (should happen)
-            // if it matters, they'll be reconnected.
-            for (int i = mHosts.size() - 1; i >= 0; i--) {
-                pruneHostLocked(mHosts.get(i));
-            }
-            // upgrade the database if needed
-            performUpgrade(version);
-        } else {
-            // failed reading, clean up
-            Slog.w(TAG, "Failed to read state, clearing widgets and hosts.");
-
-            mAppWidgetIds.clear();
-            mHosts.clear();
-            final int N = mInstalledProviders.size();
-            for (int i = 0; i < N; i++) {
-                mInstalledProviders.get(i).instances.clear();
-            }
-        }
-    }
-
-    private void performUpgrade(int fromVersion) {
-        if (fromVersion < CURRENT_VERSION) {
-            Slog.v(TAG, "Upgrading widget database from " + fromVersion + " to " + CURRENT_VERSION
-                    + " for user " + mUserId);
-        }
-
-        int version = fromVersion;
-
-        // Update 1: keyguard moved from package "android" to "com.android.keyguard"
-        if (version == 0) {
-            for (int i = 0; i < mHosts.size(); i++) {
-                Host host = mHosts.get(i);
-                if (host != null && "android".equals(host.packageName)
-                        && host.hostId == KEYGUARD_HOST_ID) {
-                    host.packageName = KEYGUARD_HOST_PACKAGE;
-                }
-            }
-            version = 1;
-        }
-
-        if (version != CURRENT_VERSION) {
-            throw new IllegalStateException("Failed to upgrade widget database");
-        }
-    }
-
-    static File getSettingsFile(int userId) {
-        return new File(Environment.getUserSystemDirectory(userId), SETTINGS_FILENAME);
-    }
-
-    AtomicFile savedStateFile() {
-        File dir = Environment.getUserSystemDirectory(mUserId);
-        File settingsFile = getSettingsFile(mUserId);
-        if (!settingsFile.exists() && mUserId == 0) {
-            if (!dir.exists()) {
-                dir.mkdirs();
-            }
-            // Migrate old data
-            File oldFile = new File("/data/system/" + SETTINGS_FILENAME);
-            // Method doesn't throw an exception on failure. Ignore any errors
-            // in moving the file (like non-existence)
-            oldFile.renameTo(settingsFile);
-        }
-        return new AtomicFile(settingsFile);
-    }
-
-    void onUserStopping() {
-        // prune the ones we don't want to keep
-        int N = mInstalledProviders.size();
-        for (int i = N - 1; i >= 0; i--) {
-            Provider p = mInstalledProviders.get(i);
-            cancelBroadcasts(p);
-        }
-    }
-
-    void onUserRemoved() {
-        getSettingsFile(mUserId).delete();
-    }
-
-    boolean addProvidersForPackageLocked(String pkgName) {
-        boolean providersAdded = false;
-        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
-        intent.setPackage(pkgName);
-        List<ResolveInfo> broadcastReceivers;
-        try {
-            broadcastReceivers = mPm.queryIntentReceivers(intent,
-                    intent.resolveTypeIfNeeded(mContext.getContentResolver()),
-                    PackageManager.GET_META_DATA, mUserId);
-        } catch (RemoteException re) {
-            // Shouldn't happen, local call
-            return false;
-        }
-        final int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
-        for (int i = 0; i < N; i++) {
-            ResolveInfo ri = broadcastReceivers.get(i);
-            ActivityInfo ai = ri.activityInfo;
-            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
-                continue;
-            }
-            if (pkgName.equals(ai.packageName)) {
-                addProviderLocked(ri);
-                providersAdded = true;
-            }
-        }
-
-        return providersAdded;
-    }
-
-    /**
-     * Updates all providers with the specified package names, and records any providers that were
-     * pruned.
-     *
-     * @return whether any providers were updated
-     */
-    boolean updateProvidersForPackageLocked(String pkgName, Set<ComponentName> removedProviders) {
-        boolean providersUpdated = false;
-        HashSet<String> keep = new HashSet<String>();
-        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
-        intent.setPackage(pkgName);
-        List<ResolveInfo> broadcastReceivers;
-        try {
-            broadcastReceivers = mPm.queryIntentReceivers(intent,
-                intent.resolveTypeIfNeeded(mContext.getContentResolver()),
-                PackageManager.GET_META_DATA, mUserId);
-        } catch (RemoteException re) {
-            // Shouldn't happen, local call
-            return false;
-        }
-
-        // add the missing ones and collect which ones to keep
-        int N = broadcastReceivers == null ? 0 : broadcastReceivers.size();
-        for (int i = 0; i < N; i++) {
-            ResolveInfo ri = broadcastReceivers.get(i);
-            ActivityInfo ai = ri.activityInfo;
-            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
-                continue;
-            }
-            if (pkgName.equals(ai.packageName)) {
-                ComponentName component = new ComponentName(ai.packageName, ai.name);
-                Provider p = lookupProviderLocked(component);
-                if (p == null) {
-                    if (addProviderLocked(ri)) {
-                        keep.add(ai.name);
-                        providersUpdated = true;
-                    }
-                } else {
-                    Provider parsed = parseProviderInfoXml(component, ri);
-                    if (parsed != null) {
-                        keep.add(ai.name);
-                        // Use the new AppWidgetProviderInfo.
-                        p.info = parsed.info;
-                        // If it's enabled
-                        final int M = p.instances.size();
-                        if (M > 0) {
-                            int[] appWidgetIds = getAppWidgetIds(p);
-                            // Reschedule for the new updatePeriodMillis (don't worry about handling
-                            // it specially if updatePeriodMillis didn't change because we just sent
-                            // an update, and the next one will be updatePeriodMillis from now).
-                            cancelBroadcasts(p);
-                            registerForBroadcastsLocked(p, appWidgetIds);
-                            // If it's currently showing, call back with the new
-                            // AppWidgetProviderInfo.
-                            for (int j = 0; j < M; j++) {
-                                AppWidgetId id = p.instances.get(j);
-                                id.views = null;
-                                if (id.host != null && id.host.callbacks != null) {
-                                    try {
-                                        id.host.callbacks.providerChanged(id.appWidgetId, p.info,
-                                                mUserId);
-                                    } catch (RemoteException ex) {
-                                        // It failed; remove the callback. No need to prune because
-                                        // we know that this host is still referenced by this
-                                        // instance.
-                                        id.host.callbacks = null;
-                                    }
-                                }
-                            }
-                            // Now that we've told the host, push out an update.
-                            sendUpdateIntentLocked(p, appWidgetIds);
-                            providersUpdated = true;
-                        }
-                    }
-                }
-            }
-        }
-
-        // prune the ones we don't want to keep
-        N = mInstalledProviders.size();
-        for (int i = N - 1; i >= 0; i--) {
-            Provider p = mInstalledProviders.get(i);
-            if (pkgName.equals(p.info.provider.getPackageName())
-                    && !keep.contains(p.info.provider.getClassName())) {
-                if (removedProviders != null) {
-                    removedProviders.add(p.info.provider);
-                }
-                removeProviderLocked(i, p);
-                providersUpdated = true;
-            }
-        }
-
-        return providersUpdated;
-    }
-
-    boolean removeProvidersForPackageLocked(String pkgName) {
-        boolean providersRemoved = false;
-        int N = mInstalledProviders.size();
-        for (int i = N - 1; i >= 0; i--) {
-            Provider p = mInstalledProviders.get(i);
-            if (pkgName.equals(p.info.provider.getPackageName())) {
-                removeProviderLocked(i, p);
-                providersRemoved = true;
-            }
-        }
-
-        // Delete the hosts for this package too
-        //
-        // By now, we have removed any AppWidgets that were in any hosts here,
-        // so we don't need to worry about sending DISABLE broadcasts to them.
-        N = mHosts.size();
-        for (int i = N - 1; i >= 0; i--) {
-            Host host = mHosts.get(i);
-            if (pkgName.equals(host.packageName)) {
-                deleteHostLocked(host);
-            }
-        }
-
-        return providersRemoved;
-    }
-
-    void notifyHostsForProvidersChangedLocked() {
-        final int N = mHosts.size();
-        for (int i = N - 1; i >= 0; i--) {
-            Host host = mHosts.get(i);
-            try {
-                if (host.callbacks != null) {
-                    host.callbacks.providersChanged(mUserId);
-                }
-            } catch (RemoteException ex) {
-                // It failed; remove the callback. No need to prune because
-                // we know that this host is still referenced by this
-                // instance.
-                host.callbacks = null;
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/AssetAtlasService.java b/services/java/com/android/server/AssetAtlasService.java
deleted file mode 100644
index 26b4652..0000000
--- a/services/java/com/android/server/AssetAtlasService.java
+++ /dev/null
@@ -1,735 +0,0 @@
-/*
- * Copyright (C) 2013 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;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.graphics.Atlas;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PixelFormat;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.drawable.Drawable;
-import android.os.Environment;
-import android.os.RemoteException;
-import android.os.SystemProperties;
-import android.util.Log;
-import android.util.LongSparseArray;
-import android.view.GraphicBuffer;
-import android.view.IAssetAtlas;
-
-import java.io.BufferedReader;
-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.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * This service is responsible for packing preloaded bitmaps into a single
- * atlas texture. The resulting texture can be shared across processes to
- * reduce overall memory usage.
- *
- * @hide
- */
-public class AssetAtlasService extends IAssetAtlas.Stub {
-    /**
-     * Name of the <code>AssetAtlasService</code>.
-     */
-    public static final String ASSET_ATLAS_SERVICE = "assetatlas";
-
-    private static final String LOG_TAG = "Atlas";
-
-    // Turns debug logs on/off. Debug logs are kept to a minimum and should
-    // remain on to diagnose issues
-    private static final boolean DEBUG_ATLAS = true;
-
-    // When set to true the content of the atlas will be saved to disk
-    // in /data/system/atlas.png. The shared GraphicBuffer may be empty
-    private static final boolean DEBUG_ATLAS_TEXTURE = false;
-
-    // Minimum size in pixels to consider for the resulting texture
-    private static final int MIN_SIZE = 768;
-    // Maximum size in pixels to consider for the resulting texture
-    private static final int MAX_SIZE = 2048;
-    // Increment in number of pixels between size variants when looking
-    // for the best texture dimensions
-    private static final int STEP = 64;
-
-    // This percentage of the total number of pixels represents the minimum
-    // number of pixels we want to be able to pack in the atlas
-    private static final float PACKING_THRESHOLD = 0.8f;
-
-    // Defines the number of int fields used to represent a single entry
-    // in the atlas map. This number defines the size of the array returned
-    // by the getMap(). See the mAtlasMap field for more information
-    private static final int ATLAS_MAP_ENTRY_FIELD_COUNT = 4;
-
-    // Specifies how our GraphicBuffer will be used. To get proper swizzling
-    // the buffer will be written to using OpenGL (from JNI) so we can leave
-    // the software flag set to "never"
-    private static final int GRAPHIC_BUFFER_USAGE = GraphicBuffer.USAGE_SW_READ_NEVER |
-            GraphicBuffer.USAGE_SW_WRITE_NEVER | GraphicBuffer.USAGE_HW_TEXTURE;
-
-    // This boolean is set to true if an atlas was successfully
-    // computed and rendered
-    private final AtomicBoolean mAtlasReady = new AtomicBoolean(false);
-
-    private final Context mContext;
-
-    // Version name of the current build, used to identify changes to assets list
-    private final String mVersionName;
-
-    // Holds the atlas' data. This buffer can be mapped to
-    // OpenGL using an EGLImage
-    private GraphicBuffer mBuffer;
-
-    // Describes how bitmaps are placed in the atlas. Each bitmap is
-    // represented by several entries in the array:
-    // int0: SkBitmap*, the native bitmap object
-    // int1: x position
-    // int2: y position
-    // int3: rotated, 1 if the bitmap must be rotated, 0 otherwise
-    // NOTE: This will need to be handled differently to support 64 bit pointers
-    private int[] mAtlasMap;
-
-    /**
-     * Creates a new service. Upon creating, the service will gather the list of
-     * assets to consider for packing into the atlas and spawn a new thread to
-     * start the packing work.
-     *
-     * @param context The context giving access to preloaded resources
-     */
-    public AssetAtlasService(Context context) {
-        mContext = context;
-        mVersionName = queryVersionName(context);
-
-        ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(300);
-        int totalPixelCount = 0;
-
-        // We only care about drawables that hold bitmaps
-        final Resources resources = context.getResources();
-        final LongSparseArray<Drawable.ConstantState> drawables = resources.getPreloadedDrawables();
-
-        final int count = drawables.size();
-        for (int i = 0; i < count; i++) {
-            final Bitmap bitmap = drawables.valueAt(i).getBitmap();
-            if (bitmap != null && bitmap.getConfig() == Bitmap.Config.ARGB_8888) {
-                bitmaps.add(bitmap);
-                totalPixelCount += bitmap.getWidth() * bitmap.getHeight();
-            }
-        }
-
-        // Our algorithms perform better when the bitmaps are first sorted
-        // The comparator will sort the bitmap by width first, then by height
-        Collections.sort(bitmaps, new Comparator<Bitmap>() {
-            @Override
-            public int compare(Bitmap b1, Bitmap b2) {
-                if (b1.getWidth() == b2.getWidth()) {
-                    return b2.getHeight() - b1.getHeight();
-                }
-                return b2.getWidth() - b1.getWidth();
-            }
-        });
-
-        // Kick off the packing work on a worker thread
-        new Thread(new Renderer(bitmaps, totalPixelCount)).start();
-    }
-
-    /**
-     * Queries the version name stored in framework's AndroidManifest.
-     * The version name can be used to identify possible changes to
-     * framework resources.
-     *
-     * @see #getBuildIdentifier(String)
-     */
-    private static String queryVersionName(Context context) {
-        try {
-            String packageName = context.getPackageName();
-            PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
-            return info.versionName;
-        } catch (PackageManager.NameNotFoundException e) {
-            Log.w(LOG_TAG, "Could not get package info", e);
-        }
-        return null;
-    }
-
-    /**
-     * Callback invoked by the server thread to indicate we can now run
-     * 3rd party code.
-     */
-    public void systemRunning() {
-    }
-
-    /**
-     * The renderer does all the work:
-     */
-    private class Renderer implements Runnable {
-        private final ArrayList<Bitmap> mBitmaps;
-        private final int mPixelCount;
-
-        private int mNativeBitmap;
-
-        // Used for debugging only
-        private Bitmap mAtlasBitmap;
-
-        Renderer(ArrayList<Bitmap> bitmaps, int pixelCount) {
-            mBitmaps = bitmaps;
-            mPixelCount = pixelCount;
-        }
-
-        /**
-         * 1. On first boot or after every update, brute-force through all the
-         *    possible atlas configurations and look for the best one (maximimize
-         *    number of packed assets and minimize texture size)
-         *    a. If a best configuration was computed, write it out to disk for
-         *       future use
-         * 2. Read best configuration from disk
-         * 3. Compute the packing using the best configuration
-         * 4. Allocate a GraphicBuffer
-         * 5. Render assets in the buffer
-         */
-        @Override
-        public void run() {
-            Configuration config = chooseConfiguration(mBitmaps, mPixelCount, mVersionName);
-            if (DEBUG_ATLAS) Log.d(LOG_TAG, "Loaded configuration: " + config);
-
-            if (config != null) {
-                mBuffer = GraphicBuffer.create(config.width, config.height,
-                        PixelFormat.RGBA_8888, GRAPHIC_BUFFER_USAGE);
-
-                if (mBuffer != null) {
-                    Atlas atlas = new Atlas(config.type, config.width, config.height, config.flags);
-                    if (renderAtlas(mBuffer, atlas, config.count)) {
-                        mAtlasReady.set(true);
-                    }
-                }
-            }
-        }
-
-        /**
-         * Renders a list of bitmaps into the atlas. The position of each bitmap
-         * was decided by the packing algorithm and will be honored by this
-         * method. If need be this method will also rotate bitmaps.
-         *
-         * @param buffer The buffer to render the atlas entries into
-         * @param atlas The atlas to pack the bitmaps into
-         * @param packCount The number of bitmaps that will be packed in the atlas
-         *
-         * @return true if the atlas was rendered, false otherwise
-         */
-        @SuppressWarnings("MismatchedReadAndWriteOfArray")
-        private boolean renderAtlas(GraphicBuffer buffer, Atlas atlas, int packCount) {
-            // Use a Source blend mode to improve performance, the target bitmap
-            // will be zero'd out so there's no need to waste time applying blending
-            final Paint paint = new Paint();
-            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
-
-            // We always render the atlas into a bitmap. This bitmap is then
-            // uploaded into the GraphicBuffer using OpenGL to swizzle the content
-            final Canvas canvas = acquireCanvas(buffer.getWidth(), buffer.getHeight());
-            if (canvas == null) return false;
-
-            final Atlas.Entry entry = new Atlas.Entry();
-
-            mAtlasMap = new int[packCount * ATLAS_MAP_ENTRY_FIELD_COUNT];
-            int[] atlasMap = mAtlasMap;
-            int mapIndex = 0;
-
-            boolean result = false;
-            try {
-                final long startRender = System.nanoTime();
-                final int count = mBitmaps.size();
-
-                for (int i = 0; i < count; i++) {
-                    final Bitmap bitmap = mBitmaps.get(i);
-                    if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) {
-                        // We have more bitmaps to pack than the current configuration
-                        // says, we were most likely not able to detect a change in the
-                        // list of preloaded drawables, abort and delete the configuration
-                        if (mapIndex >= mAtlasMap.length) {
-                            deleteDataFile();
-                            break;
-                        }
-
-                        canvas.save();
-                        canvas.translate(entry.x, entry.y);
-                        if (entry.rotated) {
-                            canvas.translate(bitmap.getHeight(), 0.0f);
-                            canvas.rotate(90.0f);
-                        }
-                        canvas.drawBitmap(bitmap, 0.0f, 0.0f, null);
-                        canvas.restore();
-
-                        atlasMap[mapIndex++] = bitmap.mNativeBitmap;
-                        atlasMap[mapIndex++] = entry.x;
-                        atlasMap[mapIndex++] = entry.y;
-                        atlasMap[mapIndex++] = entry.rotated ? 1 : 0;
-                    }
-                }
-
-                final long endRender = System.nanoTime();
-                if (mNativeBitmap != 0) {
-                    result = nUploadAtlas(buffer, mNativeBitmap);
-                }
-
-                final long endUpload = System.nanoTime();
-                if (DEBUG_ATLAS) {
-                    float renderDuration = (endRender - startRender) / 1000.0f / 1000.0f;
-                    float uploadDuration = (endUpload - endRender) / 1000.0f / 1000.0f;
-                    Log.d(LOG_TAG, String.format("Rendered atlas in %.2fms (%.2f+%.2fms)",
-                            renderDuration + uploadDuration, renderDuration, uploadDuration));
-                }
-
-            } finally {
-                releaseCanvas(canvas);
-            }
-
-            return result;
-        }
-
-        /**
-         * Returns a Canvas for the specified buffer. If {@link #DEBUG_ATLAS_TEXTURE}
-         * is turned on, the returned Canvas will render into a local bitmap that
-         * will then be saved out to disk for debugging purposes.
-         * @param width
-         * @param height
-         */
-        private Canvas acquireCanvas(int width, int height) {
-            if (DEBUG_ATLAS_TEXTURE) {
-                mAtlasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
-                return new Canvas(mAtlasBitmap);
-            } else {
-                Canvas canvas = new Canvas();
-                mNativeBitmap = nAcquireAtlasCanvas(canvas, width, height);
-                return canvas;
-            }
-        }
-
-        /**
-         * Releases the canvas used to render into the buffer. Calling this method
-         * will release any resource previously acquired. If {@link #DEBUG_ATLAS_TEXTURE}
-         * is turend on, calling this method will write the content of the atlas
-         * to disk in /data/system/atlas.png for debugging.
-         */
-        private void releaseCanvas(Canvas canvas) {
-            if (DEBUG_ATLAS_TEXTURE) {
-                canvas.setBitmap(null);
-
-                File systemDirectory = new File(Environment.getDataDirectory(), "system");
-                File dataFile = new File(systemDirectory, "atlas.png");
-
-                try {
-                    FileOutputStream out = new FileOutputStream(dataFile);
-                    mAtlasBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
-                    out.close();
-                } catch (FileNotFoundException e) {
-                    // Ignore
-                } catch (IOException e) {
-                    // Ignore
-                }
-
-                mAtlasBitmap.recycle();
-                mAtlasBitmap = null;
-            } else {
-                nReleaseAtlasCanvas(canvas, mNativeBitmap);
-            }
-        }
-    }
-
-    private static native int nAcquireAtlasCanvas(Canvas canvas, int width, int height);
-    private static native void nReleaseAtlasCanvas(Canvas canvas, int bitmap);
-    private static native boolean nUploadAtlas(GraphicBuffer buffer, int bitmap);
-
-    @Override
-    public boolean isCompatible(int ppid) {
-        return ppid == android.os.Process.myPpid();
-    }
-
-    @Override
-    public GraphicBuffer getBuffer() throws RemoteException {
-        return mAtlasReady.get() ? mBuffer : null;
-    }
-
-    @Override
-    public int[] getMap() throws RemoteException {
-        return mAtlasReady.get() ? mAtlasMap : null;
-    }
-
-    /**
-     * Finds the best atlas configuration to pack the list of supplied bitmaps.
-     * This method takes advantage of multi-core systems by spawning a number
-     * of threads equal to the number of available cores.
-     */
-    private static Configuration computeBestConfiguration(
-            ArrayList<Bitmap> bitmaps, int pixelCount) {
-        if (DEBUG_ATLAS) Log.d(LOG_TAG, "Computing best atlas configuration...");
-
-        long begin = System.nanoTime();
-        List<WorkerResult> results = Collections.synchronizedList(new ArrayList<WorkerResult>());
-
-        // Don't bother with an extra thread if there's only one processor
-        int cpuCount = Runtime.getRuntime().availableProcessors();
-        if (cpuCount == 1) {
-            new ComputeWorker(MIN_SIZE, MAX_SIZE, STEP, bitmaps, pixelCount, results, null).run();
-        } else {
-            int start = MIN_SIZE;
-            int end = MAX_SIZE - (cpuCount - 1) * STEP;
-            int step = STEP * cpuCount;
-
-            final CountDownLatch signal = new CountDownLatch(cpuCount);
-
-            for (int i = 0; i < cpuCount; i++, start += STEP, end += STEP) {
-                ComputeWorker worker = new ComputeWorker(start, end, step,
-                        bitmaps, pixelCount, results, signal);
-                new Thread(worker, "Atlas Worker #" + (i + 1)).start();
-            }
-
-            try {
-                signal.await(10, TimeUnit.SECONDS);
-            } catch (InterruptedException e) {
-                Log.w(LOG_TAG, "Could not complete configuration computation");
-                return null;
-            }
-        }
-
-        // Maximize the number of packed bitmaps, minimize the texture size
-        Collections.sort(results, new Comparator<WorkerResult>() {
-            @Override
-            public int compare(WorkerResult r1, WorkerResult r2) {
-                int delta = r2.count - r1.count;
-                if (delta != 0) return delta;
-                return r1.width * r1.height - r2.width * r2.height;
-            }
-        });
-
-        if (DEBUG_ATLAS) {
-            float delay = (System.nanoTime() - begin) / 1000.0f / 1000.0f / 1000.0f;
-            Log.d(LOG_TAG, String.format("Found best atlas configuration in %.2fs", delay));
-        }
-
-        WorkerResult result = results.get(0);
-        return new Configuration(result.type, result.width, result.height, result.count);
-    }
-
-    /**
-     * Returns the path to the file containing the best computed
-     * atlas configuration.
-     */
-    private static File getDataFile() {
-        File systemDirectory = new File(Environment.getDataDirectory(), "system");
-        return new File(systemDirectory, "framework_atlas.config");
-    }
-
-    private static void deleteDataFile() {
-        Log.w(LOG_TAG, "Current configuration inconsistent with assets list");
-        if (!getDataFile().delete()) {
-            Log.w(LOG_TAG, "Could not delete the current configuration");
-        }
-    }
-
-    private File getFrameworkResourcesFile() {
-        return new File(mContext.getApplicationInfo().sourceDir);
-    }
-
-    /**
-     * Returns the best known atlas configuration. This method will either
-     * read the configuration from disk or start a brute-force search
-     * and save the result out to disk.
-     */
-    private Configuration chooseConfiguration(ArrayList<Bitmap> bitmaps, int pixelCount,
-            String versionName) {
-        Configuration config = null;
-
-        final File dataFile = getDataFile();
-        if (dataFile.exists()) {
-            config = readConfiguration(dataFile, versionName);
-        }
-
-        if (config == null) {
-            config = computeBestConfiguration(bitmaps, pixelCount);
-            if (config != null) writeConfiguration(config, dataFile, versionName);
-        }
-
-        return config;
-    }
-
-    /**
-     * Writes the specified atlas configuration to the specified file.
-     */
-    private void writeConfiguration(Configuration config, File file, String versionName) {
-        BufferedWriter writer = null;
-        try {
-            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
-            writer.write(getBuildIdentifier(versionName));
-            writer.newLine();
-            writer.write(config.type.toString());
-            writer.newLine();
-            writer.write(String.valueOf(config.width));
-            writer.newLine();
-            writer.write(String.valueOf(config.height));
-            writer.newLine();
-            writer.write(String.valueOf(config.count));
-            writer.newLine();
-            writer.write(String.valueOf(config.flags));
-            writer.newLine();
-        } catch (FileNotFoundException e) {
-            Log.w(LOG_TAG, "Could not write " + file, e);
-        } catch (IOException e) {
-            Log.w(LOG_TAG, "Could not write " + file, e);
-        } finally {
-            if (writer != null) {
-                try {
-                    writer.close();
-                } catch (IOException e) {
-                    // Ignore
-                }
-            }
-        }
-    }
-
-    /**
-     * Reads an atlas configuration from the specified file. This method
-     * returns null if an error occurs or if the configuration is invalid.
-     */
-    private Configuration readConfiguration(File file, String versionName) {
-        BufferedReader reader = null;
-        Configuration config = null;
-        try {
-            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
-
-            if (checkBuildIdentifier(reader, versionName)) {
-                Atlas.Type type = Atlas.Type.valueOf(reader.readLine());
-                int width = readInt(reader, MIN_SIZE, MAX_SIZE);
-                int height = readInt(reader, MIN_SIZE, MAX_SIZE);
-                int count = readInt(reader, 0, Integer.MAX_VALUE);
-                int flags = readInt(reader, Integer.MIN_VALUE, Integer.MAX_VALUE);
-
-                config = new Configuration(type, width, height, count, flags);
-            }
-        } catch (IllegalArgumentException e) {
-            Log.w(LOG_TAG, "Invalid parameter value in " + file, e);
-        } catch (FileNotFoundException e) {
-            Log.w(LOG_TAG, "Could not read " + file, e);
-        } catch (IOException e) {
-            Log.w(LOG_TAG, "Could not read " + file, e);
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                    // Ignore
-                }
-            }
-        }
-        return config;
-    }
-
-    private static int readInt(BufferedReader reader, int min, int max) throws IOException {
-        return Math.max(min, Math.min(max, Integer.parseInt(reader.readLine())));
-    }
-
-    /**
-     * Compares the next line in the specified buffered reader to the current
-     * build identifier. Returns whether the two values are equal.
-     *
-     * @see #getBuildIdentifier(String)
-     */
-    private boolean checkBuildIdentifier(BufferedReader reader, String versionName)
-            throws IOException {
-        String deviceBuildId = getBuildIdentifier(versionName);
-        String buildId = reader.readLine();
-        return deviceBuildId.equals(buildId);
-    }
-
-    /**
-     * Returns an identifier for the current build that can be used to detect
-     * likely changes to framework resources. The build identifier is made of
-     * several distinct values:
-     *
-     * build fingerprint/framework version name/file size of framework resources apk
-     *
-     * Only the build fingerprint should be necessary on user builds but
-     * the other values are useful to detect changes on eng builds during
-     * development.
-     *
-     * This identifier does not attempt to be exact: a new identifier does not
-     * necessarily mean the preloaded drawables have changed. It is important
-     * however that whenever the list of preloaded drawables changes, this
-     * identifier changes as well.
-     *
-     * @see #checkBuildIdentifier(java.io.BufferedReader, String)
-     */
-    private String getBuildIdentifier(String versionName) {
-        return SystemProperties.get("ro.build.fingerprint", "") + '/' + versionName + '/' +
-                String.valueOf(getFrameworkResourcesFile().length());
-    }
-
-    /**
-     * Atlas configuration. Specifies the algorithm, dimensions and flags to use.
-     */
-    private static class Configuration {
-        final Atlas.Type type;
-        final int width;
-        final int height;
-        final int count;
-        final int flags;
-
-        Configuration(Atlas.Type type, int width, int height, int count) {
-            this(type, width, height, count, Atlas.FLAG_DEFAULTS);
-        }
-
-        Configuration(Atlas.Type type, int width, int height, int count, int flags) {
-            this.type = type;
-            this.width = width;
-            this.height = height;
-            this.count = count;
-            this.flags = flags;
-        }
-
-        @Override
-        public String toString() {
-            return type.toString() + " (" + width + "x" + height + ") flags=0x" +
-                    Integer.toHexString(flags) + " count=" + count;
-        }
-    }
-
-    /**
-     * Used during the brute-force search to gather information about each
-     * variant of the packing algorithm.
-     */
-    private static class WorkerResult {
-        Atlas.Type type;
-        int width;
-        int height;
-        int count;
-
-        WorkerResult(Atlas.Type type, int width, int height, int count) {
-            this.type = type;
-            this.width = width;
-            this.height = height;
-            this.count = count;
-        }
-
-        @Override
-        public String toString() {
-            return String.format("%s %dx%d", type.toString(), width, height);
-        }
-    }
-
-    /**
-     * A compute worker will try a finite number of variations of the packing
-     * algorithms and save the results in a supplied list.
-     */
-    private static class ComputeWorker implements Runnable {
-        private final int mStart;
-        private final int mEnd;
-        private final int mStep;
-        private final List<Bitmap> mBitmaps;
-        private final List<WorkerResult> mResults;
-        private final CountDownLatch mSignal;
-        private final int mThreshold;
-
-        /**
-         * Creates a new compute worker to brute-force through a range of
-         * packing algorithms variants.
-         *
-         * @param start The minimum texture width to try
-         * @param end The maximum texture width to try
-         * @param step The number of pixels to increment the texture width by at each step
-         * @param bitmaps The list of bitmaps to pack in the atlas
-         * @param pixelCount The total number of pixels occupied by the list of bitmaps
-         * @param results The list of results in which to save the brute-force search results
-         * @param signal Latch to decrement when this worker is done, may be null
-         */
-        ComputeWorker(int start, int end, int step, List<Bitmap> bitmaps, int pixelCount,
-                List<WorkerResult> results, CountDownLatch signal) {
-            mStart = start;
-            mEnd = end;
-            mStep = step;
-            mBitmaps = bitmaps;
-            mResults = results;
-            mSignal = signal;
-
-            // Minimum number of pixels we want to be able to pack
-            int threshold = (int) (pixelCount * PACKING_THRESHOLD);
-            // Make sure we can find at least one configuration
-            while (threshold > MAX_SIZE * MAX_SIZE) {
-                threshold >>= 1;
-            }
-            mThreshold = threshold;
-        }
-
-        @Override
-        public void run() {
-            if (DEBUG_ATLAS) Log.d(LOG_TAG, "Running " + Thread.currentThread().getName());
-
-            Atlas.Entry entry = new Atlas.Entry();
-            for (Atlas.Type type : Atlas.Type.values()) {
-                for (int width = mStart; width < mEnd; width += mStep) {
-                    for (int height = MIN_SIZE; height < MAX_SIZE; height += STEP) {
-                        // If the atlas is not big enough, skip it
-                        if (width * height <= mThreshold) continue;
-
-                        final int count = packBitmaps(type, width, height, entry);
-                        if (count > 0) {
-                            mResults.add(new WorkerResult(type, width, height, count));
-                            // If we were able to pack everything let's stop here
-                            // Increasing the height further won't make things better
-                            if (count == mBitmaps.size()) {
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
-
-            if (mSignal != null) {
-                mSignal.countDown();
-            }
-        }
-
-        private int packBitmaps(Atlas.Type type, int width, int height, Atlas.Entry entry) {
-            int total = 0;
-            Atlas atlas = new Atlas(type, width, height);
-
-            final int count = mBitmaps.size();
-            for (int i = 0; i < count; i++) {
-                final Bitmap bitmap = mBitmaps.get(i);
-                if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) {
-                    total++;
-                }
-            }
-
-            return total;
-        }
-    }
-}
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
deleted file mode 100644
index 6d65a70..0000000
--- a/services/java/com/android/server/BackupManagerService.java
+++ /dev/null
@@ -1,6288 +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.
- */
-
-package com.android.server;
-
-import android.app.ActivityManagerNative;
-import android.app.AlarmManager;
-import android.app.AppGlobals;
-import android.app.IActivityManager;
-import android.app.IApplicationThread;
-import android.app.IBackupAgent;
-import android.app.PendingIntent;
-import android.app.backup.BackupAgent;
-import android.app.backup.BackupDataOutput;
-import android.app.backup.FullBackup;
-import android.app.backup.RestoreSet;
-import android.app.backup.IBackupManager;
-import android.app.backup.IFullBackupRestoreObserver;
-import android.app.backup.IRestoreObserver;
-import android.app.backup.IRestoreSession;
-import android.content.ActivityNotFoundException;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageDataObserver;
-import android.content.pm.IPackageDeleteObserver;
-import android.content.pm.IPackageInstallObserver;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.pm.Signature;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.ParcelFileDescriptor;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SELinux;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.os.WorkSource;
-import android.os.Environment.UserEnvironment;
-import android.os.storage.IMountService;
-import android.provider.Settings;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.StringBuilderPrinter;
-
-import com.android.internal.backup.BackupConstants;
-import com.android.internal.backup.IBackupTransport;
-import com.android.internal.backup.IObbBackupService;
-import com.android.server.EventLogTags;
-import com.android.server.PackageManagerBackupAgent.Metadata;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.RandomAccessFile;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.InflaterInputStream;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.CipherInputStream;
-import javax.crypto.CipherOutputStream;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.SecretKey;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.PBEKeySpec;
-import javax.crypto.spec.SecretKeySpec;
-
-class BackupManagerService extends IBackupManager.Stub {
-    private static final String TAG = "BackupManagerService";
-    private static final boolean DEBUG = true;
-    private static final boolean MORE_DEBUG = false;
-
-    // Historical and current algorithm names
-    static final String PBKDF_CURRENT = "PBKDF2WithHmacSHA1";
-    static final String PBKDF_FALLBACK = "PBKDF2WithHmacSHA1And8bit";
-
-    // Name and current contents version of the full-backup manifest file
-    static final String BACKUP_MANIFEST_FILENAME = "_manifest";
-    static final int BACKUP_MANIFEST_VERSION = 1;
-    static final String BACKUP_FILE_HEADER_MAGIC = "ANDROID BACKUP\n";
-    static final int BACKUP_FILE_VERSION = 2;
-    static final int BACKUP_PW_FILE_VERSION = 2;
-    static final boolean COMPRESS_FULL_BACKUPS = true; // should be true in production
-
-    static final String SHARED_BACKUP_AGENT_PACKAGE = "com.android.sharedstoragebackup";
-    static final String SERVICE_ACTION_TRANSPORT_HOST = "android.backup.TRANSPORT_HOST";
-
-    // How often we perform a backup pass.  Privileged external callers can
-    // trigger an immediate pass.
-    private static final long BACKUP_INTERVAL = AlarmManager.INTERVAL_HOUR;
-
-    // Random variation in backup scheduling time to avoid server load spikes
-    private static final int FUZZ_MILLIS = 5 * 60 * 1000;
-
-    // The amount of time between the initial provisioning of the device and
-    // the first backup pass.
-    private static final long FIRST_BACKUP_INTERVAL = 12 * AlarmManager.INTERVAL_HOUR;
-
-    // Retry interval for clear/init when the transport is unavailable
-    private static final long TRANSPORT_RETRY_INTERVAL = 1 * AlarmManager.INTERVAL_HOUR;
-
-    private static final String RUN_BACKUP_ACTION = "android.app.backup.intent.RUN";
-    private static final String RUN_INITIALIZE_ACTION = "android.app.backup.intent.INIT";
-    private static final String RUN_CLEAR_ACTION = "android.app.backup.intent.CLEAR";
-    private static final int MSG_RUN_BACKUP = 1;
-    private static final int MSG_RUN_FULL_BACKUP = 2;
-    private static final int MSG_RUN_RESTORE = 3;
-    private static final int MSG_RUN_CLEAR = 4;
-    private static final int MSG_RUN_INITIALIZE = 5;
-    private static final int MSG_RUN_GET_RESTORE_SETS = 6;
-    private static final int MSG_TIMEOUT = 7;
-    private static final int MSG_RESTORE_TIMEOUT = 8;
-    private static final int MSG_FULL_CONFIRMATION_TIMEOUT = 9;
-    private static final int MSG_RUN_FULL_RESTORE = 10;
-    private static final int MSG_RETRY_INIT = 11;
-    private static final int MSG_RETRY_CLEAR = 12;
-
-    // backup task state machine tick
-    static final int MSG_BACKUP_RESTORE_STEP = 20;
-    static final int MSG_OP_COMPLETE = 21;
-
-    // Timeout interval for deciding that a bind or clear-data has taken too long
-    static final long TIMEOUT_INTERVAL = 10 * 1000;
-
-    // Timeout intervals for agent backup & restore operations
-    static final long TIMEOUT_BACKUP_INTERVAL = 30 * 1000;
-    static final long TIMEOUT_FULL_BACKUP_INTERVAL = 5 * 60 * 1000;
-    static final long TIMEOUT_SHARED_BACKUP_INTERVAL = 30 * 60 * 1000;
-    static final long TIMEOUT_RESTORE_INTERVAL = 60 * 1000;
-
-    // User confirmation timeout for a full backup/restore operation.  It's this long in
-    // order to give them time to enter the backup password.
-    static final long TIMEOUT_FULL_CONFIRMATION = 60 * 1000;
-
-    private Context mContext;
-    private PackageManager mPackageManager;
-    IPackageManager mPackageManagerBinder;
-    private IActivityManager mActivityManager;
-    private PowerManager mPowerManager;
-    private AlarmManager mAlarmManager;
-    private IMountService mMountService;
-    IBackupManager mBackupManagerBinder;
-
-    boolean mEnabled;   // access to this is synchronized on 'this'
-    boolean mProvisioned;
-    boolean mAutoRestore;
-    PowerManager.WakeLock mWakelock;
-    HandlerThread mHandlerThread;
-    BackupHandler mBackupHandler;
-    PendingIntent mRunBackupIntent, mRunInitIntent;
-    BroadcastReceiver mRunBackupReceiver, mRunInitReceiver;
-    // map UIDs to the set of participating packages under that UID
-    final SparseArray<HashSet<String>> mBackupParticipants
-            = new SparseArray<HashSet<String>>();
-    // set of backup services that have pending changes
-    class BackupRequest {
-        public String packageName;
-
-        BackupRequest(String pkgName) {
-            packageName = pkgName;
-        }
-
-        public String toString() {
-            return "BackupRequest{pkg=" + packageName + "}";
-        }
-    }
-    // Backups that we haven't started yet.  Keys are package names.
-    HashMap<String,BackupRequest> mPendingBackups
-            = new HashMap<String,BackupRequest>();
-
-    // Pseudoname that we use for the Package Manager metadata "package"
-    static final String PACKAGE_MANAGER_SENTINEL = "@pm@";
-
-    // locking around the pending-backup management
-    final Object mQueueLock = new Object();
-
-    // The thread performing the sequence of queued backups binds to each app's agent
-    // in succession.  Bind notifications are asynchronously delivered through the
-    // Activity Manager; use this lock object to signal when a requested binding has
-    // completed.
-    final Object mAgentConnectLock = new Object();
-    IBackupAgent mConnectedAgent;
-    volatile boolean mBackupRunning;
-    volatile boolean mConnecting;
-    volatile long mLastBackupPass;
-    volatile long mNextBackupPass;
-
-    // For debugging, we maintain a progress trace of operations during backup
-    static final boolean DEBUG_BACKUP_TRACE = true;
-    final List<String> mBackupTrace = new ArrayList<String>();
-
-    // A similar synchronization mechanism around clearing apps' data for restore
-    final Object mClearDataLock = new Object();
-    volatile boolean mClearingData;
-
-    // Transport bookkeeping
-    final HashMap<String,String> mTransportNames
-            = new HashMap<String,String>();             // component name -> registration name
-    final HashMap<String,IBackupTransport> mTransports
-            = new HashMap<String,IBackupTransport>();   // registration name -> binder
-    final ArrayList<TransportConnection> mTransportConnections
-            = new ArrayList<TransportConnection>();
-    String mCurrentTransport;
-    ActiveRestoreSession mActiveRestoreSession;
-
-    // Watch the device provisioning operation during setup
-    ContentObserver mProvisionedObserver;
-
-    class ProvisionedObserver extends ContentObserver {
-        public ProvisionedObserver(Handler handler) {
-            super(handler);
-        }
-
-        public void onChange(boolean selfChange) {
-            final boolean wasProvisioned = mProvisioned;
-            final boolean isProvisioned = deviceIsProvisioned();
-            // latch: never unprovision
-            mProvisioned = wasProvisioned || isProvisioned;
-            if (MORE_DEBUG) {
-                Slog.d(TAG, "Provisioning change: was=" + wasProvisioned
-                        + " is=" + isProvisioned + " now=" + mProvisioned);
-            }
-
-            synchronized (mQueueLock) {
-                if (mProvisioned && !wasProvisioned && mEnabled) {
-                    // we're now good to go, so start the backup alarms
-                    if (MORE_DEBUG) Slog.d(TAG, "Now provisioned, so starting backups");
-                    startBackupAlarmsLocked(FIRST_BACKUP_INTERVAL);
-                }
-            }
-        }
-    }
-
-    class RestoreGetSetsParams {
-        public IBackupTransport transport;
-        public ActiveRestoreSession session;
-        public IRestoreObserver observer;
-
-        RestoreGetSetsParams(IBackupTransport _transport, ActiveRestoreSession _session,
-                IRestoreObserver _observer) {
-            transport = _transport;
-            session = _session;
-            observer = _observer;
-        }
-    }
-
-    class RestoreParams {
-        public IBackupTransport transport;
-        public String dirName;
-        public IRestoreObserver observer;
-        public long token;
-        public PackageInfo pkgInfo;
-        public int pmToken; // in post-install restore, the PM's token for this transaction
-        public boolean needFullBackup;
-        public String[] filterSet;
-
-        RestoreParams(IBackupTransport _transport, String _dirName, IRestoreObserver _obs,
-                long _token, PackageInfo _pkg, int _pmToken, boolean _needFullBackup) {
-            transport = _transport;
-            dirName = _dirName;
-            observer = _obs;
-            token = _token;
-            pkgInfo = _pkg;
-            pmToken = _pmToken;
-            needFullBackup = _needFullBackup;
-            filterSet = null;
-        }
-
-        RestoreParams(IBackupTransport _transport, String _dirName, IRestoreObserver _obs,
-                long _token, boolean _needFullBackup) {
-            transport = _transport;
-            dirName = _dirName;
-            observer = _obs;
-            token = _token;
-            pkgInfo = null;
-            pmToken = 0;
-            needFullBackup = _needFullBackup;
-            filterSet = null;
-        }
-
-        RestoreParams(IBackupTransport _transport, String _dirName, IRestoreObserver _obs,
-                long _token, String[] _filterSet, boolean _needFullBackup) {
-            transport = _transport;
-            dirName = _dirName;
-            observer = _obs;
-            token = _token;
-            pkgInfo = null;
-            pmToken = 0;
-            needFullBackup = _needFullBackup;
-            filterSet = _filterSet;
-        }
-    }
-
-    class ClearParams {
-        public IBackupTransport transport;
-        public PackageInfo packageInfo;
-
-        ClearParams(IBackupTransport _transport, PackageInfo _info) {
-            transport = _transport;
-            packageInfo = _info;
-        }
-    }
-
-    class ClearRetryParams {
-        public String transportName;
-        public String packageName;
-
-        ClearRetryParams(String transport, String pkg) {
-            transportName = transport;
-            packageName = pkg;
-        }
-    }
-
-    class FullParams {
-        public ParcelFileDescriptor fd;
-        public final AtomicBoolean latch;
-        public IFullBackupRestoreObserver observer;
-        public String curPassword;     // filled in by the confirmation step
-        public String encryptPassword;
-
-        FullParams() {
-            latch = new AtomicBoolean(false);
-        }
-    }
-
-    class FullBackupParams extends FullParams {
-        public boolean includeApks;
-        public boolean includeObbs;
-        public boolean includeShared;
-        public boolean allApps;
-        public boolean includeSystem;
-        public String[] packages;
-
-        FullBackupParams(ParcelFileDescriptor output, boolean saveApks, boolean saveObbs,
-                boolean saveShared, boolean doAllApps, boolean doSystem, String[] pkgList) {
-            fd = output;
-            includeApks = saveApks;
-            includeObbs = saveObbs;
-            includeShared = saveShared;
-            allApps = doAllApps;
-            includeSystem = doSystem;
-            packages = pkgList;
-        }
-    }
-
-    class FullRestoreParams extends FullParams {
-        FullRestoreParams(ParcelFileDescriptor input) {
-            fd = input;
-        }
-    }
-
-    // Bookkeeping of in-flight operations for timeout etc. purposes.  The operation
-    // token is the index of the entry in the pending-operations list.
-    static final int OP_PENDING = 0;
-    static final int OP_ACKNOWLEDGED = 1;
-    static final int OP_TIMEOUT = -1;
-
-    class Operation {
-        public int state;
-        public BackupRestoreTask callback;
-
-        Operation(int initialState, BackupRestoreTask callbackObj) {
-            state = initialState;
-            callback = callbackObj;
-        }
-    }
-    final SparseArray<Operation> mCurrentOperations = new SparseArray<Operation>();
-    final Object mCurrentOpLock = new Object();
-    final Random mTokenGenerator = new Random();
-
-    final SparseArray<FullParams> mFullConfirmations = new SparseArray<FullParams>();
-
-    // Where we keep our journal files and other bookkeeping
-    File mBaseStateDir;
-    File mDataDir;
-    File mJournalDir;
-    File mJournal;
-
-    // Backup password, if any, and the file where it's saved.  What is stored is not the
-    // password text itself; it's the result of a PBKDF2 hash with a randomly chosen (but
-    // persisted) salt.  Validation is performed by running the challenge text through the
-    // same PBKDF2 cycle with the persisted salt; if the resulting derived key string matches
-    // the saved hash string, then the challenge text matches the originally supplied
-    // password text.
-    private final SecureRandom mRng = new SecureRandom();
-    private String mPasswordHash;
-    private File mPasswordHashFile;
-    private int mPasswordVersion;
-    private File mPasswordVersionFile;
-    private byte[] mPasswordSalt;
-
-    // Configuration of PBKDF2 that we use for generating pw hashes and intermediate keys
-    static final int PBKDF2_HASH_ROUNDS = 10000;
-    static final int PBKDF2_KEY_SIZE = 256;     // bits
-    static final int PBKDF2_SALT_SIZE = 512;    // bits
-    static final String ENCRYPTION_ALGORITHM_NAME = "AES-256";
-
-    // Keep a log of all the apps we've ever backed up, and what the
-    // dataset tokens are for both the current backup dataset and
-    // the ancestral dataset.
-    private File mEverStored;
-    HashSet<String> mEverStoredApps = new HashSet<String>();
-
-    static final int CURRENT_ANCESTRAL_RECORD_VERSION = 1;  // increment when the schema changes
-    File mTokenFile;
-    Set<String> mAncestralPackages = null;
-    long mAncestralToken = 0;
-    long mCurrentToken = 0;
-
-    // Persistently track the need to do a full init
-    static final String INIT_SENTINEL_FILE_NAME = "_need_init_";
-    HashSet<String> mPendingInits = new HashSet<String>();  // transport names
-
-    // Utility: build a new random integer token
-    int generateToken() {
-        int token;
-        do {
-            synchronized (mTokenGenerator) {
-                token = mTokenGenerator.nextInt();
-            }
-        } while (token < 0);
-        return token;
-    }
-
-    // ----- Asynchronous backup/restore handler thread -----
-
-    private class BackupHandler extends Handler {
-        public BackupHandler(Looper looper) {
-            super(looper);
-        }
-
-        public void handleMessage(Message msg) {
-
-            switch (msg.what) {
-            case MSG_RUN_BACKUP:
-            {
-                mLastBackupPass = System.currentTimeMillis();
-                mNextBackupPass = mLastBackupPass + BACKUP_INTERVAL;
-
-                IBackupTransport transport = getTransport(mCurrentTransport);
-                if (transport == null) {
-                    Slog.v(TAG, "Backup requested but no transport available");
-                    synchronized (mQueueLock) {
-                        mBackupRunning = false;
-                    }
-                    mWakelock.release();
-                    break;
-                }
-
-                // snapshot the pending-backup set and work on that
-                ArrayList<BackupRequest> queue = new ArrayList<BackupRequest>();
-                File oldJournal = mJournal;
-                synchronized (mQueueLock) {
-                    // Do we have any work to do?  Construct the work queue
-                    // then release the synchronization lock to actually run
-                    // the backup.
-                    if (mPendingBackups.size() > 0) {
-                        for (BackupRequest b: mPendingBackups.values()) {
-                            queue.add(b);
-                        }
-                        if (DEBUG) Slog.v(TAG, "clearing pending backups");
-                        mPendingBackups.clear();
-
-                        // Start a new backup-queue journal file too
-                        mJournal = null;
-
-                    }
-                }
-
-                // At this point, we have started a new journal file, and the old
-                // file identity is being passed to the backup processing task.
-                // When it completes successfully, that old journal file will be
-                // deleted.  If we crash prior to that, the old journal is parsed
-                // at next boot and the journaled requests fulfilled.
-                boolean staged = true;
-                if (queue.size() > 0) {
-                    // Spin up a backup state sequence and set it running
-                    try {
-                        String dirName = transport.transportDirName();
-                        PerformBackupTask pbt = new PerformBackupTask(transport, dirName,
-                                queue, oldJournal);
-                        Message pbtMessage = obtainMessage(MSG_BACKUP_RESTORE_STEP, pbt);
-                        sendMessage(pbtMessage);
-                    } catch (RemoteException e) {
-                        // unable to ask the transport its dir name -- transient failure, since
-                        // the above check succeeded.  Try again next time.
-                        Slog.e(TAG, "Transport became unavailable attempting backup");
-                        staged = false;
-                    }
-                } else {
-                    Slog.v(TAG, "Backup requested but nothing pending");
-                    staged = false;
-                }
-
-                if (!staged) {
-                    // if we didn't actually hand off the wakelock, rewind until next time
-                    synchronized (mQueueLock) {
-                        mBackupRunning = false;
-                    }
-                    mWakelock.release();
-                }
-                break;
-            }
-
-            case MSG_BACKUP_RESTORE_STEP:
-            {
-                try {
-                    BackupRestoreTask task = (BackupRestoreTask) msg.obj;
-                    if (MORE_DEBUG) Slog.v(TAG, "Got next step for " + task + ", executing");
-                    task.execute();
-                } catch (ClassCastException e) {
-                    Slog.e(TAG, "Invalid backup task in flight, obj=" + msg.obj);
-                }
-                break;
-            }
-
-            case MSG_OP_COMPLETE:
-            {
-                try {
-                    BackupRestoreTask task = (BackupRestoreTask) msg.obj;
-                    task.operationComplete();
-                } catch (ClassCastException e) {
-                    Slog.e(TAG, "Invalid completion in flight, obj=" + msg.obj);
-                }
-                break;
-            }
-
-            case MSG_RUN_FULL_BACKUP:
-            {
-                // TODO: refactor full backup to be a looper-based state machine
-                // similar to normal backup/restore.
-                FullBackupParams params = (FullBackupParams)msg.obj;
-                PerformFullBackupTask task = new PerformFullBackupTask(params.fd,
-                        params.observer, params.includeApks, params.includeObbs,
-                        params.includeShared, params.curPassword, params.encryptPassword,
-                        params.allApps, params.includeSystem, params.packages, params.latch);
-                (new Thread(task)).start();
-                break;
-            }
-
-            case MSG_RUN_RESTORE:
-            {
-                RestoreParams params = (RestoreParams)msg.obj;
-                Slog.d(TAG, "MSG_RUN_RESTORE observer=" + params.observer);
-                PerformRestoreTask task = new PerformRestoreTask(
-                        params.transport, params.dirName, params.observer,
-                        params.token, params.pkgInfo, params.pmToken,
-                        params.needFullBackup, params.filterSet);
-                Message restoreMsg = obtainMessage(MSG_BACKUP_RESTORE_STEP, task);
-                sendMessage(restoreMsg);
-                break;
-            }
-
-            case MSG_RUN_FULL_RESTORE:
-            {
-                // TODO: refactor full restore to be a looper-based state machine
-                // similar to normal backup/restore.
-                FullRestoreParams params = (FullRestoreParams)msg.obj;
-                PerformFullRestoreTask task = new PerformFullRestoreTask(params.fd,
-                        params.curPassword, params.encryptPassword,
-                        params.observer, params.latch);
-                (new Thread(task)).start();
-                break;
-            }
-
-            case MSG_RUN_CLEAR:
-            {
-                ClearParams params = (ClearParams)msg.obj;
-                (new PerformClearTask(params.transport, params.packageInfo)).run();
-                break;
-            }
-
-            case MSG_RETRY_CLEAR:
-            {
-                // reenqueues if the transport remains unavailable
-                ClearRetryParams params = (ClearRetryParams)msg.obj;
-                clearBackupData(params.transportName, params.packageName);
-                break;
-            }
-
-            case MSG_RUN_INITIALIZE:
-            {
-                HashSet<String> queue;
-
-                // Snapshot the pending-init queue and work on that
-                synchronized (mQueueLock) {
-                    queue = new HashSet<String>(mPendingInits);
-                    mPendingInits.clear();
-                }
-
-                (new PerformInitializeTask(queue)).run();
-                break;
-            }
-
-            case MSG_RETRY_INIT:
-            {
-                synchronized (mQueueLock) {
-                    recordInitPendingLocked(msg.arg1 != 0, (String)msg.obj);
-                    mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
-                            mRunInitIntent);
-                }
-                break;
-            }
-
-            case MSG_RUN_GET_RESTORE_SETS:
-            {
-                // Like other async operations, this is entered with the wakelock held
-                RestoreSet[] sets = null;
-                RestoreGetSetsParams params = (RestoreGetSetsParams)msg.obj;
-                try {
-                    sets = params.transport.getAvailableRestoreSets();
-                    // cache the result in the active session
-                    synchronized (params.session) {
-                        params.session.mRestoreSets = sets;
-                    }
-                    if (sets == null) EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                } catch (Exception e) {
-                    Slog.e(TAG, "Error from transport getting set list");
-                } finally {
-                    if (params.observer != null) {
-                        try {
-                            params.observer.restoreSetsAvailable(sets);
-                        } catch (RemoteException re) {
-                            Slog.e(TAG, "Unable to report listing to observer");
-                        } catch (Exception e) {
-                            Slog.e(TAG, "Restore observer threw", e);
-                        }
-                    }
-
-                    // Done: reset the session timeout clock
-                    removeMessages(MSG_RESTORE_TIMEOUT);
-                    sendEmptyMessageDelayed(MSG_RESTORE_TIMEOUT, TIMEOUT_RESTORE_INTERVAL);
-
-                    mWakelock.release();
-                }
-                break;
-            }
-
-            case MSG_TIMEOUT:
-            {
-                handleTimeout(msg.arg1, msg.obj);
-                break;
-            }
-
-            case MSG_RESTORE_TIMEOUT:
-            {
-                synchronized (BackupManagerService.this) {
-                    if (mActiveRestoreSession != null) {
-                        // Client app left the restore session dangling.  We know that it
-                        // can't be in the middle of an actual restore operation because
-                        // the timeout is suspended while a restore is in progress.  Clean
-                        // up now.
-                        Slog.w(TAG, "Restore session timed out; aborting");
-                        post(mActiveRestoreSession.new EndRestoreRunnable(
-                                BackupManagerService.this, mActiveRestoreSession));
-                    }
-                }
-            }
-
-            case MSG_FULL_CONFIRMATION_TIMEOUT:
-            {
-                synchronized (mFullConfirmations) {
-                    FullParams params = mFullConfirmations.get(msg.arg1);
-                    if (params != null) {
-                        Slog.i(TAG, "Full backup/restore timed out waiting for user confirmation");
-
-                        // Release the waiter; timeout == completion
-                        signalFullBackupRestoreCompletion(params);
-
-                        // Remove the token from the set
-                        mFullConfirmations.delete(msg.arg1);
-
-                        // Report a timeout to the observer, if any
-                        if (params.observer != null) {
-                            try {
-                                params.observer.onTimeout();
-                            } catch (RemoteException e) {
-                                /* don't care if the app has gone away */
-                            }
-                        }
-                    } else {
-                        Slog.d(TAG, "couldn't find params for token " + msg.arg1);
-                    }
-                }
-                break;
-            }
-            }
-        }
-    }
-
-    // ----- Debug-only backup operation trace -----
-    void addBackupTrace(String s) {
-        if (DEBUG_BACKUP_TRACE) {
-            synchronized (mBackupTrace) {
-                mBackupTrace.add(s);
-            }
-        }
-    }
-
-    void clearBackupTrace() {
-        if (DEBUG_BACKUP_TRACE) {
-            synchronized (mBackupTrace) {
-                mBackupTrace.clear();
-            }
-        }
-    }
-
-    // ----- Main service implementation -----
-
-    public BackupManagerService(Context context) {
-        mContext = context;
-        mPackageManager = context.getPackageManager();
-        mPackageManagerBinder = AppGlobals.getPackageManager();
-        mActivityManager = ActivityManagerNative.getDefault();
-
-        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
-        mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
-        mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount"));
-
-        mBackupManagerBinder = asInterface(asBinder());
-
-        // spin up the backup/restore handler thread
-        mHandlerThread = new HandlerThread("backup", Process.THREAD_PRIORITY_BACKGROUND);
-        mHandlerThread.start();
-        mBackupHandler = new BackupHandler(mHandlerThread.getLooper());
-
-        // Set up our bookkeeping
-        final ContentResolver resolver = context.getContentResolver();
-        boolean areEnabled = Settings.Secure.getInt(resolver,
-                Settings.Secure.BACKUP_ENABLED, 0) != 0;
-        mProvisioned = Settings.Global.getInt(resolver,
-                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
-        mAutoRestore = Settings.Secure.getInt(resolver,
-                Settings.Secure.BACKUP_AUTO_RESTORE, 1) != 0;
-
-        mProvisionedObserver = new ProvisionedObserver(mBackupHandler);
-        resolver.registerContentObserver(
-                Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED),
-                false, mProvisionedObserver);
-
-        // If Encrypted file systems is enabled or disabled, this call will return the
-        // correct directory.
-        mBaseStateDir = new File(Environment.getSecureDataDirectory(), "backup");
-        mBaseStateDir.mkdirs();
-        if (!SELinux.restorecon(mBaseStateDir)) {
-            Slog.e(TAG, "SELinux restorecon failed on " + mBaseStateDir);
-        }
-        mDataDir = Environment.getDownloadCacheDirectory();
-
-        mPasswordVersion = 1;       // unless we hear otherwise
-        mPasswordVersionFile = new File(mBaseStateDir, "pwversion");
-        if (mPasswordVersionFile.exists()) {
-            FileInputStream fin = null;
-            DataInputStream in = null;
-            try {
-                fin = new FileInputStream(mPasswordVersionFile);
-                in = new DataInputStream(fin);
-                mPasswordVersion = in.readInt();
-            } catch (IOException e) {
-                Slog.e(TAG, "Unable to read backup pw version");
-            } finally {
-                try {
-                    if (in != null) in.close();
-                    if (fin != null) fin.close();
-                } catch (IOException e) {
-                    Slog.w(TAG, "Error closing pw version files");
-                }
-            }
-        }
-
-        mPasswordHashFile = new File(mBaseStateDir, "pwhash");
-        if (mPasswordHashFile.exists()) {
-            FileInputStream fin = null;
-            DataInputStream in = null;
-            try {
-                fin = new FileInputStream(mPasswordHashFile);
-                in = new DataInputStream(new BufferedInputStream(fin));
-                // integer length of the salt array, followed by the salt,
-                // then the hex pw hash string
-                int saltLen = in.readInt();
-                byte[] salt = new byte[saltLen];
-                in.readFully(salt);
-                mPasswordHash = in.readUTF();
-                mPasswordSalt = salt;
-            } catch (IOException e) {
-                Slog.e(TAG, "Unable to read saved backup pw hash");
-            } finally {
-                try {
-                    if (in != null) in.close();
-                    if (fin != null) fin.close();
-                } catch (IOException e) {
-                    Slog.w(TAG, "Unable to close streams");
-                }
-            }
-        }
-
-        // Alarm receivers for scheduled backups & initialization operations
-        mRunBackupReceiver = new RunBackupReceiver();
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(RUN_BACKUP_ACTION);
-        context.registerReceiver(mRunBackupReceiver, filter,
-                android.Manifest.permission.BACKUP, null);
-
-        mRunInitReceiver = new RunInitializeReceiver();
-        filter = new IntentFilter();
-        filter.addAction(RUN_INITIALIZE_ACTION);
-        context.registerReceiver(mRunInitReceiver, filter,
-                android.Manifest.permission.BACKUP, null);
-
-        Intent backupIntent = new Intent(RUN_BACKUP_ACTION);
-        backupIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-        mRunBackupIntent = PendingIntent.getBroadcast(context, MSG_RUN_BACKUP, backupIntent, 0);
-
-        Intent initIntent = new Intent(RUN_INITIALIZE_ACTION);
-        backupIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-        mRunInitIntent = PendingIntent.getBroadcast(context, MSG_RUN_INITIALIZE, initIntent, 0);
-
-        // Set up the backup-request journaling
-        mJournalDir = new File(mBaseStateDir, "pending");
-        mJournalDir.mkdirs();   // creates mBaseStateDir along the way
-        mJournal = null;        // will be created on first use
-
-        // Set up the various sorts of package tracking we do
-        initPackageTracking();
-
-        // Build our mapping of uid to backup client services.  This implicitly
-        // schedules a backup pass on the Package Manager metadata the first
-        // time anything needs to be backed up.
-        synchronized (mBackupParticipants) {
-            addPackageParticipantsLocked(null);
-        }
-
-        // Set up our transport options and initialize the default transport
-        // TODO: Don't create transports that we don't need to?
-        mCurrentTransport = Settings.Secure.getString(context.getContentResolver(),
-                Settings.Secure.BACKUP_TRANSPORT);
-        if ("".equals(mCurrentTransport)) {
-            mCurrentTransport = null;
-        }
-        if (DEBUG) Slog.v(TAG, "Starting with transport " + mCurrentTransport);
-
-        // Find transport hosts and bind to their services
-        Intent transportServiceIntent = new Intent(SERVICE_ACTION_TRANSPORT_HOST);
-        List<ResolveInfo> hosts = mPackageManager.queryIntentServicesAsUser(
-                transportServiceIntent, 0, UserHandle.USER_OWNER);
-        if (DEBUG) {
-            Slog.v(TAG, "Found transports: " + ((hosts == null) ? "null" : hosts.size()));
-        }
-        if (hosts != null) {
-            if (MORE_DEBUG) {
-                for (int i = 0; i < hosts.size(); i++) {
-                    ServiceInfo info = hosts.get(i).serviceInfo;
-                    Slog.v(TAG, "   " + info.packageName + "/" + info.name);
-                }
-            }
-            for (int i = 0; i < hosts.size(); i++) {
-                try {
-                    ServiceInfo info = hosts.get(i).serviceInfo;
-                    PackageInfo packInfo = mPackageManager.getPackageInfo(info.packageName, 0);
-                    if ((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_PRIVILEGED) != 0) {
-                        ComponentName svcName = new ComponentName(info.packageName, info.name);
-                        if (DEBUG) {
-                            Slog.i(TAG, "Binding to transport host " + svcName);
-                        }
-                        Intent intent = new Intent(transportServiceIntent);
-                        intent.setComponent(svcName);
-                        TransportConnection connection = new TransportConnection();
-                        mTransportConnections.add(connection);
-                        context.bindServiceAsUser(intent,
-                                connection, Context.BIND_AUTO_CREATE,
-                                UserHandle.OWNER);
-                    } else {
-                        Slog.w(TAG, "Transport package not privileged: " + info.packageName);
-                    }
-                } catch (Exception e) {
-                    Slog.e(TAG, "Problem resolving transport service: " + e.getMessage());
-                }
-            }
-        }
-
-        // Now that we know about valid backup participants, parse any
-        // leftover journal files into the pending backup set
-        parseLeftoverJournals();
-
-        // Power management
-        mWakelock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "*backup*");
-
-        // Start the backup passes going
-        setBackupEnabled(areEnabled);
-    }
-
-    private class RunBackupReceiver extends BroadcastReceiver {
-        public void onReceive(Context context, Intent intent) {
-            if (RUN_BACKUP_ACTION.equals(intent.getAction())) {
-                synchronized (mQueueLock) {
-                    if (mPendingInits.size() > 0) {
-                        // If there are pending init operations, we process those
-                        // and then settle into the usual periodic backup schedule.
-                        if (DEBUG) Slog.v(TAG, "Init pending at scheduled backup");
-                        try {
-                            mAlarmManager.cancel(mRunInitIntent);
-                            mRunInitIntent.send();
-                        } catch (PendingIntent.CanceledException ce) {
-                            Slog.e(TAG, "Run init intent cancelled");
-                            // can't really do more than bail here
-                        }
-                    } else {
-                        // Don't run backups now if we're disabled or not yet
-                        // fully set up.
-                        if (mEnabled && mProvisioned) {
-                            if (!mBackupRunning) {
-                                if (DEBUG) Slog.v(TAG, "Running a backup pass");
-
-                                // Acquire the wakelock and pass it to the backup thread.  it will
-                                // be released once backup concludes.
-                                mBackupRunning = true;
-                                mWakelock.acquire();
-
-                                Message msg = mBackupHandler.obtainMessage(MSG_RUN_BACKUP);
-                                mBackupHandler.sendMessage(msg);
-                            } else {
-                                Slog.i(TAG, "Backup time but one already running");
-                            }
-                        } else {
-                            Slog.w(TAG, "Backup pass but e=" + mEnabled + " p=" + mProvisioned);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    private class RunInitializeReceiver extends BroadcastReceiver {
-        public void onReceive(Context context, Intent intent) {
-            if (RUN_INITIALIZE_ACTION.equals(intent.getAction())) {
-                synchronized (mQueueLock) {
-                    if (DEBUG) Slog.v(TAG, "Running a device init");
-
-                    // Acquire the wakelock and pass it to the init thread.  it will
-                    // be released once init concludes.
-                    mWakelock.acquire();
-
-                    Message msg = mBackupHandler.obtainMessage(MSG_RUN_INITIALIZE);
-                    mBackupHandler.sendMessage(msg);
-                }
-            }
-        }
-    }
-
-    private void initPackageTracking() {
-        if (DEBUG) Slog.v(TAG, "Initializing package tracking");
-
-        // Remember our ancestral dataset
-        mTokenFile = new File(mBaseStateDir, "ancestral");
-        try {
-            RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r");
-            int version = tf.readInt();
-            if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
-                mAncestralToken = tf.readLong();
-                mCurrentToken = tf.readLong();
-
-                int numPackages = tf.readInt();
-                if (numPackages >= 0) {
-                    mAncestralPackages = new HashSet<String>();
-                    for (int i = 0; i < numPackages; i++) {
-                        String pkgName = tf.readUTF();
-                        mAncestralPackages.add(pkgName);
-                    }
-                }
-            }
-            tf.close();
-        } catch (FileNotFoundException fnf) {
-            // Probably innocuous
-            Slog.v(TAG, "No ancestral data");
-        } catch (IOException e) {
-            Slog.w(TAG, "Unable to read token file", e);
-        }
-
-        // Keep a log of what apps we've ever backed up.  Because we might have
-        // rebooted in the middle of an operation that was removing something from
-        // this log, we sanity-check its contents here and reconstruct it.
-        mEverStored = new File(mBaseStateDir, "processed");
-        File tempProcessedFile = new File(mBaseStateDir, "processed.new");
-
-        // If we were in the middle of removing something from the ever-backed-up
-        // file, there might be a transient "processed.new" file still present.
-        // Ignore it -- we'll validate "processed" against the current package set.
-        if (tempProcessedFile.exists()) {
-            tempProcessedFile.delete();
-        }
-
-        // If there are previous contents, parse them out then start a new
-        // file to continue the recordkeeping.
-        if (mEverStored.exists()) {
-            RandomAccessFile temp = null;
-            RandomAccessFile in = null;
-
-            try {
-                temp = new RandomAccessFile(tempProcessedFile, "rws");
-                in = new RandomAccessFile(mEverStored, "r");
-
-                while (true) {
-                    PackageInfo info;
-                    String pkg = in.readUTF();
-                    try {
-                        info = mPackageManager.getPackageInfo(pkg, 0);
-                        mEverStoredApps.add(pkg);
-                        temp.writeUTF(pkg);
-                        if (MORE_DEBUG) Slog.v(TAG, "   + " + pkg);
-                    } catch (NameNotFoundException e) {
-                        // nope, this package was uninstalled; don't include it
-                        if (MORE_DEBUG) Slog.v(TAG, "   - " + pkg);
-                    }
-                }
-            } catch (EOFException e) {
-                // Once we've rewritten the backup history log, atomically replace the
-                // old one with the new one then reopen the file for continuing use.
-                if (!tempProcessedFile.renameTo(mEverStored)) {
-                    Slog.e(TAG, "Error renaming " + tempProcessedFile + " to " + mEverStored);
-                }
-            } catch (IOException e) {
-                Slog.e(TAG, "Error in processed file", e);
-            } finally {
-                try { if (temp != null) temp.close(); } catch (IOException e) {}
-                try { if (in != null) in.close(); } catch (IOException e) {}
-            }
-        }
-
-        // Register for broadcasts about package install, etc., so we can
-        // update the provider list.
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
-        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        filter.addDataScheme("package");
-        mContext.registerReceiver(mBroadcastReceiver, filter);
-        // Register for events related to sdcard installation.
-        IntentFilter sdFilter = new IntentFilter();
-        sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
-        sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
-        mContext.registerReceiver(mBroadcastReceiver, sdFilter);
-    }
-
-    private void parseLeftoverJournals() {
-        for (File f : mJournalDir.listFiles()) {
-            if (mJournal == null || f.compareTo(mJournal) != 0) {
-                // This isn't the current journal, so it must be a leftover.  Read
-                // out the package names mentioned there and schedule them for
-                // backup.
-                RandomAccessFile in = null;
-                try {
-                    Slog.i(TAG, "Found stale backup journal, scheduling");
-                    in = new RandomAccessFile(f, "r");
-                    while (true) {
-                        String packageName = in.readUTF();
-                        Slog.i(TAG, "  " + packageName);
-                        dataChangedImpl(packageName);
-                    }
-                } catch (EOFException e) {
-                    // no more data; we're done
-                } catch (Exception e) {
-                    Slog.e(TAG, "Can't read " + f, e);
-                } finally {
-                    // close/delete the file
-                    try { if (in != null) in.close(); } catch (IOException e) {}
-                    f.delete();
-                }
-            }
-        }
-    }
-
-    private SecretKey buildPasswordKey(String algorithm, String pw, byte[] salt, int rounds) {
-        return buildCharArrayKey(algorithm, pw.toCharArray(), salt, rounds);
-    }
-
-    private SecretKey buildCharArrayKey(String algorithm, char[] pwArray, byte[] salt, int rounds) {
-        try {
-            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
-            KeySpec ks = new PBEKeySpec(pwArray, salt, rounds, PBKDF2_KEY_SIZE);
-            return keyFactory.generateSecret(ks);
-        } catch (InvalidKeySpecException e) {
-            Slog.e(TAG, "Invalid key spec for PBKDF2!");
-        } catch (NoSuchAlgorithmException e) {
-            Slog.e(TAG, "PBKDF2 unavailable!");
-        }
-        return null;
-    }
-
-    private String buildPasswordHash(String algorithm, String pw, byte[] salt, int rounds) {
-        SecretKey key = buildPasswordKey(algorithm, pw, salt, rounds);
-        if (key != null) {
-            return byteArrayToHex(key.getEncoded());
-        }
-        return null;
-    }
-
-    private String byteArrayToHex(byte[] data) {
-        StringBuilder buf = new StringBuilder(data.length * 2);
-        for (int i = 0; i < data.length; i++) {
-            buf.append(Byte.toHexString(data[i], true));
-        }
-        return buf.toString();
-    }
-
-    private byte[] hexToByteArray(String digits) {
-        final int bytes = digits.length() / 2;
-        if (2*bytes != digits.length()) {
-            throw new IllegalArgumentException("Hex string must have an even number of digits");
-        }
-
-        byte[] result = new byte[bytes];
-        for (int i = 0; i < digits.length(); i += 2) {
-            result[i/2] = (byte) Integer.parseInt(digits.substring(i, i+2), 16);
-        }
-        return result;
-    }
-
-    private byte[] makeKeyChecksum(String algorithm, byte[] pwBytes, byte[] salt, int rounds) {
-        char[] mkAsChar = new char[pwBytes.length];
-        for (int i = 0; i < pwBytes.length; i++) {
-            mkAsChar[i] = (char) pwBytes[i];
-        }
-
-        Key checksum = buildCharArrayKey(algorithm, mkAsChar, salt, rounds);
-        return checksum.getEncoded();
-    }
-
-    // Used for generating random salts or passwords
-    private byte[] randomBytes(int bits) {
-        byte[] array = new byte[bits / 8];
-        mRng.nextBytes(array);
-        return array;
-    }
-
-    // Backup password management
-    boolean passwordMatchesSaved(String algorithm, String candidatePw, int rounds) {
-        // First, on an encrypted device we require matching the device pw
-        final boolean isEncrypted;
-        try {
-            isEncrypted = (mMountService.getEncryptionState() != MountService.ENCRYPTION_STATE_NONE);
-            if (isEncrypted) {
-                if (DEBUG) {
-                    Slog.i(TAG, "Device encrypted; verifying against device data pw");
-                }
-                // 0 means the password validated
-                // -2 means device not encrypted
-                // Any other result is either password failure or an error condition,
-                // so we refuse the match
-                final int result = mMountService.verifyEncryptionPassword(candidatePw);
-                if (result == 0) {
-                    if (MORE_DEBUG) Slog.d(TAG, "Pw verifies");
-                    return true;
-                } else if (result != -2) {
-                    if (MORE_DEBUG) Slog.d(TAG, "Pw mismatch");
-                    return false;
-                } else {
-                    // ...else the device is supposedly not encrypted.  HOWEVER, the
-                    // query about the encryption state said that the device *is*
-                    // encrypted, so ... we may have a problem.  Log it and refuse
-                    // the backup.
-                    Slog.e(TAG, "verified encryption state mismatch against query; no match allowed");
-                    return false;
-                }
-            }
-        } catch (Exception e) {
-            // Something went wrong talking to the mount service.  This is very bad;
-            // assume that we fail password validation.
-            return false;
-        }
-
-        if (mPasswordHash == null) {
-            // no current password case -- require that 'currentPw' be null or empty
-            if (candidatePw == null || "".equals(candidatePw)) {
-                return true;
-            } // else the non-empty candidate does not match the empty stored pw
-        } else {
-            // hash the stated current pw and compare to the stored one
-            if (candidatePw != null && candidatePw.length() > 0) {
-                String currentPwHash = buildPasswordHash(algorithm, candidatePw, mPasswordSalt, rounds);
-                if (mPasswordHash.equalsIgnoreCase(currentPwHash)) {
-                    // candidate hash matches the stored hash -- the password matches
-                    return true;
-                }
-            } // else the stored pw is nonempty but the candidate is empty; no match
-        }
-        return false;
-    }
-
-    @Override
-    public boolean setBackupPassword(String currentPw, String newPw) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "setBackupPassword");
-
-        // When processing v1 passwords we may need to try two different PBKDF2 checksum regimes
-        final boolean pbkdf2Fallback = (mPasswordVersion < BACKUP_PW_FILE_VERSION);
-
-        // If the supplied pw doesn't hash to the the saved one, fail.  The password
-        // might be caught in the legacy crypto mismatch; verify that too.
-        if (!passwordMatchesSaved(PBKDF_CURRENT, currentPw, PBKDF2_HASH_ROUNDS)
-                && !(pbkdf2Fallback && passwordMatchesSaved(PBKDF_FALLBACK,
-                        currentPw, PBKDF2_HASH_ROUNDS))) {
-            return false;
-        }
-
-        // Snap up to current on the pw file version
-        mPasswordVersion = BACKUP_PW_FILE_VERSION;
-        FileOutputStream pwFout = null;
-        DataOutputStream pwOut = null;
-        try {
-            pwFout = new FileOutputStream(mPasswordVersionFile);
-            pwOut = new DataOutputStream(pwFout);
-            pwOut.writeInt(mPasswordVersion);
-        } catch (IOException e) {
-            Slog.e(TAG, "Unable to write backup pw version; password not changed");
-            return false;
-        } finally {
-            try {
-                if (pwOut != null) pwOut.close();
-                if (pwFout != null) pwFout.close();
-            } catch (IOException e) {
-                Slog.w(TAG, "Unable to close pw version record");
-            }
-        }
-
-        // Clearing the password is okay
-        if (newPw == null || newPw.isEmpty()) {
-            if (mPasswordHashFile.exists()) {
-                if (!mPasswordHashFile.delete()) {
-                    // Unable to delete the old pw file, so fail
-                    Slog.e(TAG, "Unable to clear backup password");
-                    return false;
-                }
-            }
-            mPasswordHash = null;
-            mPasswordSalt = null;
-            return true;
-        }
-
-        try {
-            // Okay, build the hash of the new backup password
-            byte[] salt = randomBytes(PBKDF2_SALT_SIZE);
-            String newPwHash = buildPasswordHash(PBKDF_CURRENT, newPw, salt, PBKDF2_HASH_ROUNDS);
-
-            OutputStream pwf = null, buffer = null;
-            DataOutputStream out = null;
-            try {
-                pwf = new FileOutputStream(mPasswordHashFile);
-                buffer = new BufferedOutputStream(pwf);
-                out = new DataOutputStream(buffer);
-                // integer length of the salt array, followed by the salt,
-                // then the hex pw hash string
-                out.writeInt(salt.length);
-                out.write(salt);
-                out.writeUTF(newPwHash);
-                out.flush();
-                mPasswordHash = newPwHash;
-                mPasswordSalt = salt;
-                return true;
-            } finally {
-                if (out != null) out.close();
-                if (buffer != null) buffer.close();
-                if (pwf != null) pwf.close();
-            }
-        } catch (IOException e) {
-            Slog.e(TAG, "Unable to set backup password");
-        }
-        return false;
-    }
-
-    @Override
-    public boolean hasBackupPassword() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "hasBackupPassword");
-
-        try {
-            return (mMountService.getEncryptionState() != IMountService.ENCRYPTION_STATE_NONE)
-                || (mPasswordHash != null && mPasswordHash.length() > 0);
-        } catch (Exception e) {
-            // If we can't talk to the mount service we have a serious problem; fail
-            // "secure" i.e. assuming that we require a password
-            return true;
-        }
-    }
-
-    private boolean backupPasswordMatches(String currentPw) {
-        if (hasBackupPassword()) {
-            final boolean pbkdf2Fallback = (mPasswordVersion < BACKUP_PW_FILE_VERSION);
-            if (!passwordMatchesSaved(PBKDF_CURRENT, currentPw, PBKDF2_HASH_ROUNDS)
-                    && !(pbkdf2Fallback && passwordMatchesSaved(PBKDF_FALLBACK,
-                            currentPw, PBKDF2_HASH_ROUNDS))) {
-                if (DEBUG) Slog.w(TAG, "Backup password mismatch; aborting");
-                return false;
-            }
-        }
-        return true;
-    }
-
-    // Maintain persistent state around whether need to do an initialize operation.
-    // Must be called with the queue lock held.
-    void recordInitPendingLocked(boolean isPending, String transportName) {
-        if (DEBUG) Slog.i(TAG, "recordInitPendingLocked: " + isPending
-                + " on transport " + transportName);
-        mBackupHandler.removeMessages(MSG_RETRY_INIT);
-
-        try {
-            IBackupTransport transport = getTransport(transportName);
-            if (transport != null) {
-                String transportDirName = transport.transportDirName();
-                File stateDir = new File(mBaseStateDir, transportDirName);
-                File initPendingFile = new File(stateDir, INIT_SENTINEL_FILE_NAME);
-
-                if (isPending) {
-                    // We need an init before we can proceed with sending backup data.
-                    // Record that with an entry in our set of pending inits, as well as
-                    // journaling it via creation of a sentinel file.
-                    mPendingInits.add(transportName);
-                    try {
-                        (new FileOutputStream(initPendingFile)).close();
-                    } catch (IOException ioe) {
-                        // Something is badly wrong with our permissions; just try to move on
-                    }
-                } else {
-                    // No more initialization needed; wipe the journal and reset our state.
-                    initPendingFile.delete();
-                    mPendingInits.remove(transportName);
-                }
-                return; // done; don't fall through to the error case
-            }
-        } catch (RemoteException e) {
-            // transport threw when asked its name; fall through to the lookup-failed case
-        }
-
-        // The named transport doesn't exist or threw.  This operation is
-        // important, so we record the need for a an init and post a message
-        // to retry the init later.
-        if (isPending) {
-            mPendingInits.add(transportName);
-            mBackupHandler.sendMessageDelayed(
-                    mBackupHandler.obtainMessage(MSG_RETRY_INIT,
-                            (isPending ? 1 : 0),
-                            0,
-                            transportName),
-                    TRANSPORT_RETRY_INTERVAL);
-        }
-    }
-
-    // Reset all of our bookkeeping, in response to having been told that
-    // the backend data has been wiped [due to idle expiry, for example],
-    // so we must re-upload all saved settings.
-    void resetBackupState(File stateFileDir) {
-        synchronized (mQueueLock) {
-            // Wipe the "what we've ever backed up" tracking
-            mEverStoredApps.clear();
-            mEverStored.delete();
-
-            mCurrentToken = 0;
-            writeRestoreTokens();
-
-            // Remove all the state files
-            for (File sf : stateFileDir.listFiles()) {
-                // ... but don't touch the needs-init sentinel
-                if (!sf.getName().equals(INIT_SENTINEL_FILE_NAME)) {
-                    sf.delete();
-                }
-            }
-        }
-
-        // Enqueue a new backup of every participant
-        synchronized (mBackupParticipants) {
-            final int N = mBackupParticipants.size();
-            for (int i=0; i<N; i++) {
-                HashSet<String> participants = mBackupParticipants.valueAt(i);
-                if (participants != null) {
-                    for (String packageName : participants) {
-                        dataChangedImpl(packageName);
-                    }
-                }
-            }
-        }
-    }
-
-    // Add a transport to our set of available backends.  If 'transport' is null, this
-    // is an unregistration, and the transport's entry is removed from our bookkeeping.
-    private void registerTransport(String name, String component, IBackupTransport transport) {
-        synchronized (mTransports) {
-            if (DEBUG) Slog.v(TAG, "Registering transport "
-                    + component + "::" + name + " = " + transport);
-            if (transport != null) {
-                mTransports.put(name, transport);
-                mTransportNames.put(component, name);
-            } else {
-                mTransports.remove(mTransportNames.get(component));
-                mTransportNames.remove(component);
-                // Nothing further to do in the unregistration case
-                return;
-            }
-        }
-
-        // If the init sentinel file exists, we need to be sure to perform the init
-        // as soon as practical.  We also create the state directory at registration
-        // time to ensure it's present from the outset.
-        try {
-            String transportName = transport.transportDirName();
-            File stateDir = new File(mBaseStateDir, transportName);
-            stateDir.mkdirs();
-
-            File initSentinel = new File(stateDir, INIT_SENTINEL_FILE_NAME);
-            if (initSentinel.exists()) {
-                synchronized (mQueueLock) {
-                    mPendingInits.add(transportName);
-
-                    // TODO: pick a better starting time than now + 1 minute
-                    long delay = 1000 * 60; // one minute, in milliseconds
-                    mAlarmManager.set(AlarmManager.RTC_WAKEUP,
-                            System.currentTimeMillis() + delay, mRunInitIntent);
-                }
-            }
-        } catch (RemoteException e) {
-            // the transport threw when asked its file naming prefs; declare it invalid
-            Slog.e(TAG, "Unable to register transport as " + name);
-            mTransportNames.remove(component);
-            mTransports.remove(name);
-        }
-    }
-
-    // ----- Track installation/removal of packages -----
-    BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            if (DEBUG) Slog.d(TAG, "Received broadcast " + intent);
-
-            String action = intent.getAction();
-            boolean replacing = false;
-            boolean added = false;
-            Bundle extras = intent.getExtras();
-            String pkgList[] = null;
-            if (Intent.ACTION_PACKAGE_ADDED.equals(action) ||
-                    Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
-                Uri uri = intent.getData();
-                if (uri == null) {
-                    return;
-                }
-                String pkgName = uri.getSchemeSpecificPart();
-                if (pkgName != null) {
-                    pkgList = new String[] { pkgName };
-                }
-                added = Intent.ACTION_PACKAGE_ADDED.equals(action);
-                replacing = extras.getBoolean(Intent.EXTRA_REPLACING, false);
-            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) {
-                added = true;
-                pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
-                added = false;
-                pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-            }
-
-            if (pkgList == null || pkgList.length == 0) {
-                return;
-            }
-
-            final int uid = extras.getInt(Intent.EXTRA_UID);
-            if (added) {
-                synchronized (mBackupParticipants) {
-                    if (replacing) {
-                        // This is the package-replaced case; we just remove the entry
-                        // under the old uid and fall through to re-add.
-                        removePackageParticipantsLocked(pkgList, uid);
-                    }
-                    addPackageParticipantsLocked(pkgList);
-                }
-            } else {
-                if (replacing) {
-                    // The package is being updated.  We'll receive a PACKAGE_ADDED shortly.
-                } else {
-                    synchronized (mBackupParticipants) {
-                        removePackageParticipantsLocked(pkgList, uid);
-                    }
-                }
-            }
-        }
-    };
-
-    // ----- Track connection to transports service -----
-    class TransportConnection implements ServiceConnection {
-        @Override
-        public void onServiceConnected(ComponentName component, IBinder service) {
-            if (DEBUG) Slog.v(TAG, "Connected to transport " + component);
-            try {
-                IBackupTransport transport = IBackupTransport.Stub.asInterface(service);
-                registerTransport(transport.name(), component.flattenToShortString(), transport);
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Unable to register transport " + component);
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName component) {
-            if (DEBUG) Slog.v(TAG, "Disconnected from transport " + component);
-            registerTransport(null, component.flattenToShortString(), null);
-        }
-    };
-
-    // Add the backup agents in the given packages to our set of known backup participants.
-    // If 'packageNames' is null, adds all backup agents in the whole system.
-    void addPackageParticipantsLocked(String[] packageNames) {
-        // Look for apps that define the android:backupAgent attribute
-        List<PackageInfo> targetApps = allAgentPackages();
-        if (packageNames != null) {
-            if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: #" + packageNames.length);
-            for (String packageName : packageNames) {
-                addPackageParticipantsLockedInner(packageName, targetApps);
-            }
-        } else {
-            if (DEBUG) Slog.v(TAG, "addPackageParticipantsLocked: all");
-            addPackageParticipantsLockedInner(null, targetApps);
-        }
-    }
-
-    private void addPackageParticipantsLockedInner(String packageName,
-            List<PackageInfo> targetPkgs) {
-        if (MORE_DEBUG) {
-            Slog.v(TAG, "Examining " + packageName + " for backup agent");
-        }
-
-        for (PackageInfo pkg : targetPkgs) {
-            if (packageName == null || pkg.packageName.equals(packageName)) {
-                int uid = pkg.applicationInfo.uid;
-                HashSet<String> set = mBackupParticipants.get(uid);
-                if (set == null) {
-                    set = new HashSet<String>();
-                    mBackupParticipants.put(uid, set);
-                }
-                set.add(pkg.packageName);
-                if (MORE_DEBUG) Slog.v(TAG, "Agent found; added");
-
-                // Schedule a backup for it on general principles
-                if (DEBUG) Slog.i(TAG, "Scheduling backup for new app " + pkg.packageName);
-                dataChangedImpl(pkg.packageName);
-            }
-        }
-    }
-
-    // Remove the given packages' entries from our known active set.
-    void removePackageParticipantsLocked(String[] packageNames, int oldUid) {
-        if (packageNames == null) {
-            Slog.w(TAG, "removePackageParticipants with null list");
-            return;
-        }
-
-        if (DEBUG) Slog.v(TAG, "removePackageParticipantsLocked: uid=" + oldUid
-                + " #" + packageNames.length);
-        for (String pkg : packageNames) {
-            // Known previous UID, so we know which package set to check
-            HashSet<String> set = mBackupParticipants.get(oldUid);
-            if (set != null && set.contains(pkg)) {
-                removePackageFromSetLocked(set, pkg);
-                if (set.isEmpty()) {
-                    if (MORE_DEBUG) Slog.v(TAG, "  last one of this uid; purging set");
-                    mBackupParticipants.remove(oldUid);
-                }
-            }
-        }
-    }
-
-    private void removePackageFromSetLocked(final HashSet<String> set,
-            final String packageName) {
-        if (set.contains(packageName)) {
-            // Found it.  Remove this one package from the bookkeeping, and
-            // if it's the last participating app under this uid we drop the
-            // (now-empty) set as well.
-            // Note that we deliberately leave it 'known' in the "ever backed up"
-            // bookkeeping so that its current-dataset data will be retrieved
-            // if the app is subsequently reinstalled
-            if (MORE_DEBUG) Slog.v(TAG, "  removing participant " + packageName);
-            set.remove(packageName);
-            mPendingBackups.remove(packageName);
-        }
-    }
-
-    // Returns the set of all applications that define an android:backupAgent attribute
-    List<PackageInfo> allAgentPackages() {
-        // !!! TODO: cache this and regenerate only when necessary
-        int flags = PackageManager.GET_SIGNATURES;
-        List<PackageInfo> packages = mPackageManager.getInstalledPackages(flags);
-        int N = packages.size();
-        for (int a = N-1; a >= 0; a--) {
-            PackageInfo pkg = packages.get(a);
-            try {
-                ApplicationInfo app = pkg.applicationInfo;
-                if (((app.flags&ApplicationInfo.FLAG_ALLOW_BACKUP) == 0)
-                        || app.backupAgentName == null) {
-                    packages.remove(a);
-                }
-                else {
-                    // we will need the shared library path, so look that up and store it here
-                    app = mPackageManager.getApplicationInfo(pkg.packageName,
-                            PackageManager.GET_SHARED_LIBRARY_FILES);
-                    pkg.applicationInfo.sharedLibraryFiles = app.sharedLibraryFiles;
-                }
-            } catch (NameNotFoundException e) {
-                packages.remove(a);
-            }
-        }
-        return packages;
-    }
-
-    // Called from the backup task: record that the given app has been successfully
-    // backed up at least once
-    void logBackupComplete(String packageName) {
-        if (packageName.equals(PACKAGE_MANAGER_SENTINEL)) return;
-
-        synchronized (mEverStoredApps) {
-            if (!mEverStoredApps.add(packageName)) return;
-
-            RandomAccessFile out = null;
-            try {
-                out = new RandomAccessFile(mEverStored, "rws");
-                out.seek(out.length());
-                out.writeUTF(packageName);
-            } catch (IOException e) {
-                Slog.e(TAG, "Can't log backup of " + packageName + " to " + mEverStored);
-            } finally {
-                try { if (out != null) out.close(); } catch (IOException e) {}
-            }
-        }
-    }
-
-    // Remove our awareness of having ever backed up the given package
-    void removeEverBackedUp(String packageName) {
-        if (DEBUG) Slog.v(TAG, "Removing backed-up knowledge of " + packageName);
-        if (MORE_DEBUG) Slog.v(TAG, "New set:");
-
-        synchronized (mEverStoredApps) {
-            // Rewrite the file and rename to overwrite.  If we reboot in the middle,
-            // we'll recognize on initialization time that the package no longer
-            // exists and fix it up then.
-            File tempKnownFile = new File(mBaseStateDir, "processed.new");
-            RandomAccessFile known = null;
-            try {
-                known = new RandomAccessFile(tempKnownFile, "rws");
-                mEverStoredApps.remove(packageName);
-                for (String s : mEverStoredApps) {
-                    known.writeUTF(s);
-                    if (MORE_DEBUG) Slog.v(TAG, "    " + s);
-                }
-                known.close();
-                known = null;
-                if (!tempKnownFile.renameTo(mEverStored)) {
-                    throw new IOException("Can't rename " + tempKnownFile + " to " + mEverStored);
-                }
-            } catch (IOException e) {
-                // Bad: we couldn't create the new copy.  For safety's sake we
-                // abandon the whole process and remove all what's-backed-up
-                // state entirely, meaning we'll force a backup pass for every
-                // participant on the next boot or [re]install.
-                Slog.w(TAG, "Error rewriting " + mEverStored, e);
-                mEverStoredApps.clear();
-                tempKnownFile.delete();
-                mEverStored.delete();
-            } finally {
-                try { if (known != null) known.close(); } catch (IOException e) {}
-            }
-        }
-    }
-
-    // Persistently record the current and ancestral backup tokens as well
-    // as the set of packages with data [supposedly] available in the
-    // ancestral dataset.
-    void writeRestoreTokens() {
-        try {
-            RandomAccessFile af = new RandomAccessFile(mTokenFile, "rwd");
-
-            // First, the version number of this record, for futureproofing
-            af.writeInt(CURRENT_ANCESTRAL_RECORD_VERSION);
-
-            // Write the ancestral and current tokens
-            af.writeLong(mAncestralToken);
-            af.writeLong(mCurrentToken);
-
-            // Now write the set of ancestral packages
-            if (mAncestralPackages == null) {
-                af.writeInt(-1);
-            } else {
-                af.writeInt(mAncestralPackages.size());
-                if (DEBUG) Slog.v(TAG, "Ancestral packages:  " + mAncestralPackages.size());
-                for (String pkgName : mAncestralPackages) {
-                    af.writeUTF(pkgName);
-                    if (MORE_DEBUG) Slog.v(TAG, "   " + pkgName);
-                }
-            }
-            af.close();
-        } catch (IOException e) {
-            Slog.w(TAG, "Unable to write token file:", e);
-        }
-    }
-
-    // Return the given transport
-    private IBackupTransport getTransport(String transportName) {
-        synchronized (mTransports) {
-            IBackupTransport transport = mTransports.get(transportName);
-            if (transport == null) {
-                Slog.w(TAG, "Requested unavailable transport: " + transportName);
-            }
-            return transport;
-        }
-    }
-
-    // fire off a backup agent, blocking until it attaches or times out
-    IBackupAgent bindToAgentSynchronous(ApplicationInfo app, int mode) {
-        IBackupAgent agent = null;
-        synchronized(mAgentConnectLock) {
-            mConnecting = true;
-            mConnectedAgent = null;
-            try {
-                if (mActivityManager.bindBackupAgent(app, mode)) {
-                    Slog.d(TAG, "awaiting agent for " + app);
-
-                    // success; wait for the agent to arrive
-                    // only wait 10 seconds for the bind to happen
-                    long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
-                    while (mConnecting && mConnectedAgent == null
-                            && (System.currentTimeMillis() < timeoutMark)) {
-                        try {
-                            mAgentConnectLock.wait(5000);
-                        } catch (InterruptedException e) {
-                            // just bail
-                            if (DEBUG) Slog.w(TAG, "Interrupted: " + e);
-                            mActivityManager.clearPendingBackup();
-                            return null;
-                        }
-                    }
-
-                    // if we timed out with no connect, abort and move on
-                    if (mConnecting == true) {
-                        Slog.w(TAG, "Timeout waiting for agent " + app);
-                        mActivityManager.clearPendingBackup();
-                        return null;
-                    }
-                    if (DEBUG) Slog.i(TAG, "got agent " + mConnectedAgent);
-                    agent = mConnectedAgent;
-                }
-            } catch (RemoteException e) {
-                // can't happen - ActivityManager is local
-            }
-        }
-        return agent;
-    }
-
-    // clear an application's data, blocking until the operation completes or times out
-    void clearApplicationDataSynchronous(String packageName) {
-        // Don't wipe packages marked allowClearUserData=false
-        try {
-            PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
-            if ((info.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) == 0) {
-                if (MORE_DEBUG) Slog.i(TAG, "allowClearUserData=false so not wiping "
-                        + packageName);
-                return;
-            }
-        } catch (NameNotFoundException e) {
-            Slog.w(TAG, "Tried to clear data for " + packageName + " but not found");
-            return;
-        }
-
-        ClearDataObserver observer = new ClearDataObserver();
-
-        synchronized(mClearDataLock) {
-            mClearingData = true;
-            try {
-                mActivityManager.clearApplicationUserData(packageName, observer, 0);
-            } catch (RemoteException e) {
-                // can't happen because the activity manager is in this process
-            }
-
-            // only wait 10 seconds for the clear data to happen
-            long timeoutMark = System.currentTimeMillis() + TIMEOUT_INTERVAL;
-            while (mClearingData && (System.currentTimeMillis() < timeoutMark)) {
-                try {
-                    mClearDataLock.wait(5000);
-                } catch (InterruptedException e) {
-                    // won't happen, but still.
-                    mClearingData = false;
-                }
-            }
-        }
-    }
-
-    class ClearDataObserver extends IPackageDataObserver.Stub {
-        public void onRemoveCompleted(String packageName, boolean succeeded) {
-            synchronized(mClearDataLock) {
-                mClearingData = false;
-                mClearDataLock.notifyAll();
-            }
-        }
-    }
-
-    // Get the restore-set token for the best-available restore set for this package:
-    // the active set if possible, else the ancestral one.  Returns zero if none available.
-    long getAvailableRestoreToken(String packageName) {
-        long token = mAncestralToken;
-        synchronized (mQueueLock) {
-            if (mEverStoredApps.contains(packageName)) {
-                token = mCurrentToken;
-            }
-        }
-        return token;
-    }
-
-    // -----
-    // Interface and methods used by the asynchronous-with-timeout backup/restore operations
-
-    interface BackupRestoreTask {
-        // Execute one tick of whatever state machine the task implements
-        void execute();
-
-        // An operation that wanted a callback has completed
-        void operationComplete();
-
-        // An operation that wanted a callback has timed out
-        void handleTimeout();
-    }
-
-    void prepareOperationTimeout(int token, long interval, BackupRestoreTask callback) {
-        if (MORE_DEBUG) Slog.v(TAG, "starting timeout: token=" + Integer.toHexString(token)
-                + " interval=" + interval);
-        synchronized (mCurrentOpLock) {
-            mCurrentOperations.put(token, new Operation(OP_PENDING, callback));
-
-            Message msg = mBackupHandler.obtainMessage(MSG_TIMEOUT, token, 0, callback);
-            mBackupHandler.sendMessageDelayed(msg, interval);
-        }
-    }
-
-    // synchronous waiter case
-    boolean waitUntilOperationComplete(int token) {
-        if (MORE_DEBUG) Slog.i(TAG, "Blocking until operation complete for "
-                + Integer.toHexString(token));
-        int finalState = OP_PENDING;
-        Operation op = null;
-        synchronized (mCurrentOpLock) {
-            while (true) {
-                op = mCurrentOperations.get(token);
-                if (op == null) {
-                    // mysterious disappearance: treat as success with no callback
-                    break;
-                } else {
-                    if (op.state == OP_PENDING) {
-                        try {
-                            mCurrentOpLock.wait();
-                        } catch (InterruptedException e) {}
-                        // When the wait is notified we loop around and recheck the current state
-                    } else {
-                        // No longer pending; we're done
-                        finalState = op.state;
-                        break;
-                    }
-                }
-            }
-        }
-
-        mBackupHandler.removeMessages(MSG_TIMEOUT);
-        if (MORE_DEBUG) Slog.v(TAG, "operation " + Integer.toHexString(token)
-                + " complete: finalState=" + finalState);
-        return finalState == OP_ACKNOWLEDGED;
-    }
-
-    void handleTimeout(int token, Object obj) {
-        // Notify any synchronous waiters
-        Operation op = null;
-        synchronized (mCurrentOpLock) {
-            op = mCurrentOperations.get(token);
-            if (MORE_DEBUG) {
-                if (op == null) Slog.w(TAG, "Timeout of token " + Integer.toHexString(token)
-                        + " but no op found");
-            }
-            int state = (op != null) ? op.state : OP_TIMEOUT;
-            if (state == OP_PENDING) {
-                if (DEBUG) Slog.v(TAG, "TIMEOUT: token=" + Integer.toHexString(token));
-                op.state = OP_TIMEOUT;
-                mCurrentOperations.put(token, op);
-            }
-            mCurrentOpLock.notifyAll();
-        }
-
-        // If there's a TimeoutHandler for this event, call it
-        if (op != null && op.callback != null) {
-            op.callback.handleTimeout();
-        }
-    }
-
-    // ----- Back up a set of applications via a worker thread -----
-
-    enum BackupState {
-        INITIAL,
-        RUNNING_QUEUE,
-        FINAL
-    }
-
-    class PerformBackupTask implements BackupRestoreTask {
-        private static final String TAG = "PerformBackupTask";
-
-        IBackupTransport mTransport;
-        ArrayList<BackupRequest> mQueue;
-        ArrayList<BackupRequest> mOriginalQueue;
-        File mStateDir;
-        File mJournal;
-        BackupState mCurrentState;
-
-        // carried information about the current in-flight operation
-        PackageInfo mCurrentPackage;
-        File mSavedStateName;
-        File mBackupDataName;
-        File mNewStateName;
-        ParcelFileDescriptor mSavedState;
-        ParcelFileDescriptor mBackupData;
-        ParcelFileDescriptor mNewState;
-        int mStatus;
-        boolean mFinished;
-
-        public PerformBackupTask(IBackupTransport transport, String dirName,
-                ArrayList<BackupRequest> queue, File journal) {
-            mTransport = transport;
-            mOriginalQueue = queue;
-            mJournal = journal;
-
-            mStateDir = new File(mBaseStateDir, dirName);
-
-            mCurrentState = BackupState.INITIAL;
-            mFinished = false;
-
-            addBackupTrace("STATE => INITIAL");
-        }
-
-        // Main entry point: perform one chunk of work, updating the state as appropriate
-        // and reposting the next chunk to the primary backup handler thread.
-        @Override
-        public void execute() {
-            switch (mCurrentState) {
-                case INITIAL:
-                    beginBackup();
-                    break;
-
-                case RUNNING_QUEUE:
-                    invokeNextAgent();
-                    break;
-
-                case FINAL:
-                    if (!mFinished) finalizeBackup();
-                    else {
-                        Slog.e(TAG, "Duplicate finish");
-                    }
-                    mFinished = true;
-                    break;
-            }
-        }
-
-        // We're starting a backup pass.  Initialize the transport and send
-        // the PM metadata blob if we haven't already.
-        void beginBackup() {
-            if (DEBUG_BACKUP_TRACE) {
-                clearBackupTrace();
-                StringBuilder b = new StringBuilder(256);
-                b.append("beginBackup: [");
-                for (BackupRequest req : mOriginalQueue) {
-                    b.append(' ');
-                    b.append(req.packageName);
-                }
-                b.append(" ]");
-                addBackupTrace(b.toString());
-            }
-
-            mStatus = BackupConstants.TRANSPORT_OK;
-
-            // Sanity check: if the queue is empty we have no work to do.
-            if (mOriginalQueue.isEmpty()) {
-                Slog.w(TAG, "Backup begun with an empty queue - nothing to do.");
-                addBackupTrace("queue empty at begin");
-                executeNextState(BackupState.FINAL);
-                return;
-            }
-
-            // We need to retain the original queue contents in case of transport
-            // failure, but we want a working copy that we can manipulate along
-            // the way.
-            mQueue = (ArrayList<BackupRequest>) mOriginalQueue.clone();
-
-            if (DEBUG) Slog.v(TAG, "Beginning backup of " + mQueue.size() + " targets");
-
-            File pmState = new File(mStateDir, PACKAGE_MANAGER_SENTINEL);
-            try {
-                final String transportName = mTransport.transportDirName();
-                EventLog.writeEvent(EventLogTags.BACKUP_START, transportName);
-
-                // If we haven't stored package manager metadata yet, we must init the transport.
-                if (mStatus == BackupConstants.TRANSPORT_OK && pmState.length() <= 0) {
-                    Slog.i(TAG, "Initializing (wiping) backup state and transport storage");
-                    addBackupTrace("initializing transport " + transportName);
-                    resetBackupState(mStateDir);  // Just to make sure.
-                    mStatus = mTransport.initializeDevice();
-
-                    addBackupTrace("transport.initializeDevice() == " + mStatus);
-                    if (mStatus == BackupConstants.TRANSPORT_OK) {
-                        EventLog.writeEvent(EventLogTags.BACKUP_INITIALIZE);
-                    } else {
-                        EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE, "(initialize)");
-                        Slog.e(TAG, "Transport error in initializeDevice()");
-                    }
-                }
-
-                // The package manager doesn't have a proper <application> etc, but since
-                // it's running here in the system process we can just set up its agent
-                // directly and use a synthetic BackupRequest.  We always run this pass
-                // because it's cheap and this way we guarantee that we don't get out of
-                // step even if we're selecting among various transports at run time.
-                if (mStatus == BackupConstants.TRANSPORT_OK) {
-                    PackageManagerBackupAgent pmAgent = new PackageManagerBackupAgent(
-                            mPackageManager, allAgentPackages());
-                    mStatus = invokeAgentForBackup(PACKAGE_MANAGER_SENTINEL,
-                            IBackupAgent.Stub.asInterface(pmAgent.onBind()), mTransport);
-                    addBackupTrace("PMBA invoke: " + mStatus);
-                }
-
-                if (mStatus == BackupConstants.TRANSPORT_NOT_INITIALIZED) {
-                    // The backend reports that our dataset has been wiped.  Note this in
-                    // the event log; the no-success code below will reset the backup
-                    // state as well.
-                    EventLog.writeEvent(EventLogTags.BACKUP_RESET, mTransport.transportDirName());
-                }
-            } catch (Exception e) {
-                Slog.e(TAG, "Error in backup thread", e);
-                addBackupTrace("Exception in backup thread: " + e);
-                mStatus = BackupConstants.TRANSPORT_ERROR;
-            } finally {
-                // If we've succeeded so far, invokeAgentForBackup() will have run the PM
-                // metadata and its completion/timeout callback will continue the state
-                // machine chain.  If it failed that won't happen; we handle that now.
-                addBackupTrace("exiting prelim: " + mStatus);
-                if (mStatus != BackupConstants.TRANSPORT_OK) {
-                    // if things went wrong at this point, we need to
-                    // restage everything and try again later.
-                    resetBackupState(mStateDir);  // Just to make sure.
-                    executeNextState(BackupState.FINAL);
-                }
-            }
-        }
-
-        // Transport has been initialized and the PM metadata submitted successfully
-        // if that was warranted.  Now we process the single next thing in the queue.
-        void invokeNextAgent() {
-            mStatus = BackupConstants.TRANSPORT_OK;
-            addBackupTrace("invoke q=" + mQueue.size());
-
-            // Sanity check that we have work to do.  If not, skip to the end where
-            // we reestablish the wakelock invariants etc.
-            if (mQueue.isEmpty()) {
-                if (DEBUG) Slog.i(TAG, "queue now empty");
-                executeNextState(BackupState.FINAL);
-                return;
-            }
-
-            // pop the entry we're going to process on this step
-            BackupRequest request = mQueue.get(0);
-            mQueue.remove(0);
-
-            Slog.d(TAG, "starting agent for backup of " + request);
-            addBackupTrace("launch agent for " + request.packageName);
-
-            // Verify that the requested app exists; it might be something that
-            // requested a backup but was then uninstalled.  The request was
-            // journalled and rather than tamper with the journal it's safer
-            // to sanity-check here.  This also gives us the classname of the
-            // package's backup agent.
-            try {
-                mCurrentPackage = mPackageManager.getPackageInfo(request.packageName,
-                        PackageManager.GET_SIGNATURES);
-                if (mCurrentPackage.applicationInfo.backupAgentName == null) {
-                    // The manifest has changed but we had a stale backup request pending.
-                    // This won't happen again because the app won't be requesting further
-                    // backups.
-                    Slog.i(TAG, "Package " + request.packageName
-                            + " no longer supports backup; skipping");
-                    addBackupTrace("skipping - no agent, completion is noop");
-                    executeNextState(BackupState.RUNNING_QUEUE);
-                    return;
-                }
-
-                if ((mCurrentPackage.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
-                    // The app has been force-stopped or cleared or just installed,
-                    // and not yet launched out of that state, so just as it won't
-                    // receive broadcasts, we won't run it for backup.
-                    addBackupTrace("skipping - stopped");
-                    executeNextState(BackupState.RUNNING_QUEUE);
-                    return;
-                }
-
-                IBackupAgent agent = null;
-                try {
-                    mWakelock.setWorkSource(new WorkSource(mCurrentPackage.applicationInfo.uid));
-                    agent = bindToAgentSynchronous(mCurrentPackage.applicationInfo,
-                            IApplicationThread.BACKUP_MODE_INCREMENTAL);
-                    addBackupTrace("agent bound; a? = " + (agent != null));
-                    if (agent != null) {
-                        mStatus = invokeAgentForBackup(request.packageName, agent, mTransport);
-                        // at this point we'll either get a completion callback from the
-                        // agent, or a timeout message on the main handler.  either way, we're
-                        // done here as long as we're successful so far.
-                    } else {
-                        // Timeout waiting for the agent
-                        mStatus = BackupConstants.AGENT_ERROR;
-                    }
-                } catch (SecurityException ex) {
-                    // Try for the next one.
-                    Slog.d(TAG, "error in bind/backup", ex);
-                    mStatus = BackupConstants.AGENT_ERROR;
-                            addBackupTrace("agent SE");
-                }
-            } catch (NameNotFoundException e) {
-                Slog.d(TAG, "Package does not exist; skipping");
-                addBackupTrace("no such package");
-                mStatus = BackupConstants.AGENT_UNKNOWN;
-            } finally {
-                mWakelock.setWorkSource(null);
-
-                // If there was an agent error, no timeout/completion handling will occur.
-                // That means we need to direct to the next state ourselves.
-                if (mStatus != BackupConstants.TRANSPORT_OK) {
-                    BackupState nextState = BackupState.RUNNING_QUEUE;
-
-                    // An agent-level failure means we reenqueue this one agent for
-                    // a later retry, but otherwise proceed normally.
-                    if (mStatus == BackupConstants.AGENT_ERROR) {
-                        if (MORE_DEBUG) Slog.i(TAG, "Agent failure for " + request.packageName
-                                + " - restaging");
-                        dataChangedImpl(request.packageName);
-                        mStatus = BackupConstants.TRANSPORT_OK;
-                        if (mQueue.isEmpty()) nextState = BackupState.FINAL;
-                    } else if (mStatus == BackupConstants.AGENT_UNKNOWN) {
-                        // Failed lookup of the app, so we couldn't bring up an agent, but
-                        // we're otherwise fine.  Just drop it and go on to the next as usual.
-                        mStatus = BackupConstants.TRANSPORT_OK;
-                    } else {
-                        // Transport-level failure means we reenqueue everything
-                        revertAndEndBackup();
-                        nextState = BackupState.FINAL;
-                    }
-
-                    executeNextState(nextState);
-                } else {
-                    addBackupTrace("expecting completion/timeout callback");
-                }
-            }
-        }
-
-        void finalizeBackup() {
-            addBackupTrace("finishing");
-
-            // Either backup was successful, in which case we of course do not need
-            // this pass's journal any more; or it failed, in which case we just
-            // re-enqueued all of these packages in the current active journal.
-            // Either way, we no longer need this pass's journal.
-            if (mJournal != null && !mJournal.delete()) {
-                Slog.e(TAG, "Unable to remove backup journal file " + mJournal);
-            }
-
-            // If everything actually went through and this is the first time we've
-            // done a backup, we can now record what the current backup dataset token
-            // is.
-            if ((mCurrentToken == 0) && (mStatus == BackupConstants.TRANSPORT_OK)) {
-                addBackupTrace("success; recording token");
-                try {
-                    mCurrentToken = mTransport.getCurrentRestoreSet();
-                    writeRestoreTokens();
-                } catch (RemoteException e) {
-                    // nothing for it at this point, unfortunately, but this will be
-                    // recorded the next time we fully succeed.
-                    addBackupTrace("transport threw returning token");
-                }
-            }
-
-            // Set up the next backup pass - at this point we can set mBackupRunning
-            // to false to allow another pass to fire, because we're done with the
-            // state machine sequence and the wakelock is refcounted.
-            synchronized (mQueueLock) {
-                mBackupRunning = false;
-                if (mStatus == BackupConstants.TRANSPORT_NOT_INITIALIZED) {
-                    // Make sure we back up everything and perform the one-time init
-                    clearMetadata();
-                    if (DEBUG) Slog.d(TAG, "Server requires init; rerunning");
-                    addBackupTrace("init required; rerunning");
-                    backupNow();
-                }
-            }
-
-            // Only once we're entirely finished do we release the wakelock
-            clearBackupTrace();
-            Slog.i(TAG, "Backup pass finished.");
-            mWakelock.release();
-        }
-
-        // Remove the PM metadata state. This will generate an init on the next pass.
-        void clearMetadata() {
-            final File pmState = new File(mStateDir, PACKAGE_MANAGER_SENTINEL);
-            if (pmState.exists()) pmState.delete();
-        }
-
-        // Invoke an agent's doBackup() and start a timeout message spinning on the main
-        // handler in case it doesn't get back to us.
-        int invokeAgentForBackup(String packageName, IBackupAgent agent,
-                IBackupTransport transport) {
-            if (DEBUG) Slog.d(TAG, "invokeAgentForBackup on " + packageName);
-            addBackupTrace("invoking " + packageName);
-
-            mSavedStateName = new File(mStateDir, packageName);
-            mBackupDataName = new File(mDataDir, packageName + ".data");
-            mNewStateName = new File(mStateDir, packageName + ".new");
-
-            mSavedState = null;
-            mBackupData = null;
-            mNewState = null;
-
-            final int token = generateToken();
-            try {
-                // Look up the package info & signatures.  This is first so that if it
-                // throws an exception, there's no file setup yet that would need to
-                // be unraveled.
-                if (packageName.equals(PACKAGE_MANAGER_SENTINEL)) {
-                    // The metadata 'package' is synthetic; construct one and make
-                    // sure our global state is pointed at it
-                    mCurrentPackage = new PackageInfo();
-                    mCurrentPackage.packageName = packageName;
-                }
-
-                // In a full backup, we pass a null ParcelFileDescriptor as
-                // the saved-state "file". This is by definition an incremental,
-                // so we build a saved state file to pass.
-                mSavedState = ParcelFileDescriptor.open(mSavedStateName,
-                        ParcelFileDescriptor.MODE_READ_ONLY |
-                        ParcelFileDescriptor.MODE_CREATE);  // Make an empty file if necessary
-
-                mBackupData = ParcelFileDescriptor.open(mBackupDataName,
-                        ParcelFileDescriptor.MODE_READ_WRITE |
-                        ParcelFileDescriptor.MODE_CREATE |
-                        ParcelFileDescriptor.MODE_TRUNCATE);
-
-                if (!SELinux.restorecon(mBackupDataName)) {
-                    Slog.e(TAG, "SELinux restorecon failed on " + mBackupDataName);
-                }
-
-                mNewState = ParcelFileDescriptor.open(mNewStateName,
-                        ParcelFileDescriptor.MODE_READ_WRITE |
-                        ParcelFileDescriptor.MODE_CREATE |
-                        ParcelFileDescriptor.MODE_TRUNCATE);
-
-                // Initiate the target's backup pass
-                addBackupTrace("setting timeout");
-                prepareOperationTimeout(token, TIMEOUT_BACKUP_INTERVAL, this);
-                addBackupTrace("calling agent doBackup()");
-                agent.doBackup(mSavedState, mBackupData, mNewState, token, mBackupManagerBinder);
-            } catch (Exception e) {
-                Slog.e(TAG, "Error invoking for backup on " + packageName);
-                addBackupTrace("exception: " + e);
-                EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, packageName,
-                        e.toString());
-                agentErrorCleanup();
-                return BackupConstants.AGENT_ERROR;
-            }
-
-            // At this point the agent is off and running.  The next thing to happen will
-            // either be a callback from the agent, at which point we'll process its data
-            // for transport, or a timeout.  Either way the next phase will happen in
-            // response to the TimeoutHandler interface callbacks.
-            addBackupTrace("invoke success");
-            return BackupConstants.TRANSPORT_OK;
-        }
-
-        @Override
-        public void operationComplete() {
-            // Okay, the agent successfully reported back to us.  Spin the data off to the
-            // transport and proceed with the next stage.
-            if (MORE_DEBUG) Slog.v(TAG, "operationComplete(): sending data to transport for "
-                    + mCurrentPackage.packageName);
-            mBackupHandler.removeMessages(MSG_TIMEOUT);
-            clearAgentState();
-            addBackupTrace("operation complete");
-
-            ParcelFileDescriptor backupData = null;
-            mStatus = BackupConstants.TRANSPORT_OK;
-            try {
-                int size = (int) mBackupDataName.length();
-                if (size > 0) {
-                    if (mStatus == BackupConstants.TRANSPORT_OK) {
-                        backupData = ParcelFileDescriptor.open(mBackupDataName,
-                                ParcelFileDescriptor.MODE_READ_ONLY);
-                        addBackupTrace("sending data to transport");
-                        mStatus = mTransport.performBackup(mCurrentPackage, backupData);
-                    }
-
-                    // TODO - We call finishBackup() for each application backed up, because
-                    // we need to know now whether it succeeded or failed.  Instead, we should
-                    // hold off on finishBackup() until the end, which implies holding off on
-                    // renaming *all* the output state files (see below) until that happens.
-
-                    addBackupTrace("data delivered: " + mStatus);
-                    if (mStatus == BackupConstants.TRANSPORT_OK) {
-                        addBackupTrace("finishing op on transport");
-                        mStatus = mTransport.finishBackup();
-                        addBackupTrace("finished: " + mStatus);
-                    }
-                } else {
-                    if (DEBUG) Slog.i(TAG, "no backup data written; not calling transport");
-                    addBackupTrace("no data to send");
-                }
-
-                // After successful transport, delete the now-stale data
-                // and juggle the files so that next time we supply the agent
-                // with the new state file it just created.
-                if (mStatus == BackupConstants.TRANSPORT_OK) {
-                    mBackupDataName.delete();
-                    mNewStateName.renameTo(mSavedStateName);
-                    EventLog.writeEvent(EventLogTags.BACKUP_PACKAGE,
-                            mCurrentPackage.packageName, size);
-                    logBackupComplete(mCurrentPackage.packageName);
-                } else {
-                    EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE,
-                            mCurrentPackage.packageName);
-                }
-            } catch (Exception e) {
-                Slog.e(TAG, "Transport error backing up " + mCurrentPackage.packageName, e);
-                EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE,
-                        mCurrentPackage.packageName);
-                mStatus = BackupConstants.TRANSPORT_ERROR;
-            } finally {
-                try { if (backupData != null) backupData.close(); } catch (IOException e) {}
-            }
-
-            // If we encountered an error here it's a transport-level failure.  That
-            // means we need to halt everything and reschedule everything for next time.
-            final BackupState nextState;
-            if (mStatus != BackupConstants.TRANSPORT_OK) {
-                revertAndEndBackup();
-                nextState = BackupState.FINAL;
-            } else {
-                // Success!  Proceed with the next app if any, otherwise we're done.
-                nextState = (mQueue.isEmpty()) ? BackupState.FINAL : BackupState.RUNNING_QUEUE;
-            }
-
-            executeNextState(nextState);
-        }
-
-        @Override
-        public void handleTimeout() {
-            // Whoops, the current agent timed out running doBackup().  Tidy up and restage
-            // it for the next time we run a backup pass.
-            // !!! TODO: keep track of failure counts per agent, and blacklist those which
-            // fail repeatedly (i.e. have proved themselves to be buggy).
-            Slog.e(TAG, "Timeout backing up " + mCurrentPackage.packageName);
-            EventLog.writeEvent(EventLogTags.BACKUP_AGENT_FAILURE, mCurrentPackage.packageName,
-                    "timeout");
-            addBackupTrace("timeout of " + mCurrentPackage.packageName);
-            agentErrorCleanup();
-            dataChangedImpl(mCurrentPackage.packageName);
-        }
-
-        void revertAndEndBackup() {
-            if (MORE_DEBUG) Slog.i(TAG, "Reverting backup queue - restaging everything");
-            addBackupTrace("transport error; reverting");
-            for (BackupRequest request : mOriginalQueue) {
-                dataChangedImpl(request.packageName);
-            }
-            // We also want to reset the backup schedule based on whatever
-            // the transport suggests by way of retry/backoff time.
-            restartBackupAlarm();
-        }
-
-        void agentErrorCleanup() {
-            mBackupDataName.delete();
-            mNewStateName.delete();
-            clearAgentState();
-
-            executeNextState(mQueue.isEmpty() ? BackupState.FINAL : BackupState.RUNNING_QUEUE);
-        }
-
-        // Cleanup common to both success and failure cases
-        void clearAgentState() {
-            try { if (mSavedState != null) mSavedState.close(); } catch (IOException e) {}
-            try { if (mBackupData != null) mBackupData.close(); } catch (IOException e) {}
-            try { if (mNewState != null) mNewState.close(); } catch (IOException e) {}
-            mSavedState = mBackupData = mNewState = null;
-            synchronized (mCurrentOpLock) {
-                mCurrentOperations.clear();
-            }
-
-            // If this was a pseudopackage there's no associated Activity Manager state
-            if (mCurrentPackage.applicationInfo != null) {
-                addBackupTrace("unbinding " + mCurrentPackage.packageName);
-                try {  // unbind even on timeout, just in case
-                    mActivityManager.unbindBackupAgent(mCurrentPackage.applicationInfo);
-                } catch (RemoteException e) { /* can't happen; activity manager is local */ }
-            }
-        }
-
-        void restartBackupAlarm() {
-            addBackupTrace("setting backup trigger");
-            synchronized (mQueueLock) {
-                try {
-                    startBackupAlarmsLocked(mTransport.requestBackupTime());
-                } catch (RemoteException e) { /* cannot happen */ }
-            }
-        }
-
-        void executeNextState(BackupState nextState) {
-            if (MORE_DEBUG) Slog.i(TAG, " => executing next step on "
-                    + this + " nextState=" + nextState);
-            addBackupTrace("executeNextState => " + nextState);
-            mCurrentState = nextState;
-            Message msg = mBackupHandler.obtainMessage(MSG_BACKUP_RESTORE_STEP, this);
-            mBackupHandler.sendMessage(msg);
-        }
-    }
-
-
-    // ----- Full backup/restore to a file/socket -----
-
-    abstract class ObbServiceClient {
-        public IObbBackupService mObbService;
-        public void setObbBinder(IObbBackupService binder) {
-            mObbService = binder;
-        }
-    }
-
-    class FullBackupObbConnection implements ServiceConnection {
-        volatile IObbBackupService mService;
-
-        FullBackupObbConnection() {
-            mService = null;
-        }
-
-        public void establish() {
-            if (DEBUG) Slog.i(TAG, "Initiating bind of OBB service on " + this);
-            Intent obbIntent = new Intent().setComponent(new ComponentName(
-                    "com.android.sharedstoragebackup",
-                    "com.android.sharedstoragebackup.ObbBackupService"));
-            BackupManagerService.this.mContext.bindService(
-                    obbIntent, this, Context.BIND_AUTO_CREATE);
-        }
-
-        public void tearDown() {
-            BackupManagerService.this.mContext.unbindService(this);
-        }
-
-        public boolean backupObbs(PackageInfo pkg, OutputStream out) {
-            boolean success = false;
-            waitForConnection();
-
-            ParcelFileDescriptor[] pipes = null;
-            try {
-                pipes = ParcelFileDescriptor.createPipe();
-                int token = generateToken();
-                prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL, null);
-                mService.backupObbs(pkg.packageName, pipes[1], token, mBackupManagerBinder);
-                routeSocketDataToOutput(pipes[0], out);
-                success = waitUntilOperationComplete(token);
-            } catch (Exception e) {
-                Slog.w(TAG, "Unable to back up OBBs for " + pkg, e);
-            } finally {
-                try {
-                    out.flush();
-                    if (pipes != null) {
-                        if (pipes[0] != null) pipes[0].close();
-                        if (pipes[1] != null) pipes[1].close();
-                    }
-                } catch (IOException e) {
-                    Slog.w(TAG, "I/O error closing down OBB backup", e);
-                }
-            }
-            return success;
-        }
-
-        public void restoreObbFile(String pkgName, ParcelFileDescriptor data,
-                long fileSize, int type, String path, long mode, long mtime,
-                int token, IBackupManager callbackBinder) {
-            waitForConnection();
-
-            try {
-                mService.restoreObbFile(pkgName, data, fileSize, type, path, mode, mtime,
-                        token, callbackBinder);
-            } catch (Exception e) {
-                Slog.w(TAG, "Unable to restore OBBs for " + pkgName, e);
-            }
-        }
-
-        private void waitForConnection() {
-            synchronized (this) {
-                while (mService == null) {
-                    if (DEBUG) Slog.i(TAG, "...waiting for OBB service binding...");
-                    try {
-                        this.wait();
-                    } catch (InterruptedException e) { /* never interrupted */ }
-                }
-                if (DEBUG) Slog.i(TAG, "Connected to OBB service; continuing");
-            }
-        }
-
-        @Override
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            synchronized (this) {
-                mService = IObbBackupService.Stub.asInterface(service);
-                if (DEBUG) Slog.i(TAG, "OBB service connection " + mService
-                        + " connected on " + this);
-                this.notifyAll();
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName name) {
-            synchronized (this) {
-                mService = null;
-                if (DEBUG) Slog.i(TAG, "OBB service connection disconnected on " + this);
-                this.notifyAll();
-            }
-        }
-        
-    }
-
-    private void routeSocketDataToOutput(ParcelFileDescriptor inPipe, OutputStream out)
-            throws IOException {
-        FileInputStream raw = new FileInputStream(inPipe.getFileDescriptor());
-        DataInputStream in = new DataInputStream(raw);
-
-        byte[] buffer = new byte[32 * 1024];
-        int chunkTotal;
-        while ((chunkTotal = in.readInt()) > 0) {
-            while (chunkTotal > 0) {
-                int toRead = (chunkTotal > buffer.length) ? buffer.length : chunkTotal;
-                int nRead = in.read(buffer, 0, toRead);
-                out.write(buffer, 0, nRead);
-                chunkTotal -= nRead;
-            }
-        }
-    }
-
-    class PerformFullBackupTask extends ObbServiceClient implements Runnable {
-        ParcelFileDescriptor mOutputFile;
-        DeflaterOutputStream mDeflater;
-        IFullBackupRestoreObserver mObserver;
-        boolean mIncludeApks;
-        boolean mIncludeObbs;
-        boolean mIncludeShared;
-        boolean mAllApps;
-        final boolean mIncludeSystem;
-        String[] mPackages;
-        String mCurrentPassword;
-        String mEncryptPassword;
-        AtomicBoolean mLatchObject;
-        File mFilesDir;
-        File mManifestFile;
-        
-
-        class FullBackupRunner implements Runnable {
-            PackageInfo mPackage;
-            IBackupAgent mAgent;
-            ParcelFileDescriptor mPipe;
-            int mToken;
-            boolean mSendApk;
-            boolean mWriteManifest;
-
-            FullBackupRunner(PackageInfo pack, IBackupAgent agent, ParcelFileDescriptor pipe,
-                    int token, boolean sendApk, boolean writeManifest)  throws IOException {
-                mPackage = pack;
-                mAgent = agent;
-                mPipe = ParcelFileDescriptor.dup(pipe.getFileDescriptor());
-                mToken = token;
-                mSendApk = sendApk;
-                mWriteManifest = writeManifest;
-            }
-
-            @Override
-            public void run() {
-                try {
-                    BackupDataOutput output = new BackupDataOutput(
-                            mPipe.getFileDescriptor());
-
-                    if (mWriteManifest) {
-                        if (MORE_DEBUG) Slog.d(TAG, "Writing manifest for " + mPackage.packageName);
-                        writeAppManifest(mPackage, mManifestFile, mSendApk);
-                        FullBackup.backupToTar(mPackage.packageName, null, null,
-                                mFilesDir.getAbsolutePath(),
-                                mManifestFile.getAbsolutePath(),
-                                output);
-                    }
-
-                    if (mSendApk) {
-                        writeApkToBackup(mPackage, output);
-                    }
-
-                    if (DEBUG) Slog.d(TAG, "Calling doFullBackup() on " + mPackage.packageName);
-                    prepareOperationTimeout(mToken, TIMEOUT_FULL_BACKUP_INTERVAL, null);
-                    mAgent.doFullBackup(mPipe, mToken, mBackupManagerBinder);
-                } catch (IOException e) {
-                    Slog.e(TAG, "Error running full backup for " + mPackage.packageName);
-                } catch (RemoteException e) {
-                    Slog.e(TAG, "Remote agent vanished during full backup of "
-                            + mPackage.packageName);
-                } finally {
-                    try {
-                        mPipe.close();
-                    } catch (IOException e) {}
-                }
-            }
-        }
-
-        PerformFullBackupTask(ParcelFileDescriptor fd, IFullBackupRestoreObserver observer, 
-                boolean includeApks, boolean includeObbs, boolean includeShared,
-                String curPassword, String encryptPassword, boolean doAllApps,
-                boolean doSystem, String[] packages, AtomicBoolean latch) {
-            mOutputFile = fd;
-            mObserver = observer;
-            mIncludeApks = includeApks;
-            mIncludeObbs = includeObbs;
-            mIncludeShared = includeShared;
-            mAllApps = doAllApps;
-            mIncludeSystem = doSystem;
-            mPackages = packages;
-            mCurrentPassword = curPassword;
-            // when backing up, if there is a current backup password, we require that
-            // the user use a nonempty encryption password as well.  if one is supplied
-            // in the UI we use that, but if the UI was left empty we fall back to the
-            // current backup password (which was supplied by the user as well).
-            if (encryptPassword == null || "".equals(encryptPassword)) {
-                mEncryptPassword = curPassword;
-            } else {
-                mEncryptPassword = encryptPassword;
-            }
-            mLatchObject = latch;
-
-            mFilesDir = new File("/data/system");
-            mManifestFile = new File(mFilesDir, BACKUP_MANIFEST_FILENAME);
-        }
-
-        @Override
-        public void run() {
-            Slog.i(TAG, "--- Performing full-dataset backup ---");
-
-            List<PackageInfo> packagesToBackup = new ArrayList<PackageInfo>();
-            FullBackupObbConnection obbConnection = new FullBackupObbConnection();
-            obbConnection.establish();  // we'll want this later
-
-            sendStartBackup();
-
-            // doAllApps supersedes the package set if any
-            if (mAllApps) {
-                packagesToBackup = mPackageManager.getInstalledPackages(
-                        PackageManager.GET_SIGNATURES);
-                // Exclude system apps if we've been asked to do so
-                if (mIncludeSystem == false) {
-                    for (int i = 0; i < packagesToBackup.size(); ) {
-                        PackageInfo pkg = packagesToBackup.get(i);
-                        if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                            packagesToBackup.remove(i);
-                        } else {
-                            i++;
-                        }
-                    }
-                }
-            }
-
-            // Now process the command line argument packages, if any. Note that explicitly-
-            // named system-partition packages will be included even if includeSystem was
-            // set to false.
-            if (mPackages != null) {
-                for (String pkgName : mPackages) {
-                    try {
-                        packagesToBackup.add(mPackageManager.getPackageInfo(pkgName,
-                                PackageManager.GET_SIGNATURES));
-                    } catch (NameNotFoundException e) {
-                        Slog.w(TAG, "Unknown package " + pkgName + ", skipping");
-                    }
-                }
-            }
-
-            // Cull any packages that have indicated that backups are not permitted, as well
-            // as any explicit mention of the 'special' shared-storage agent package (we
-            // handle that one at the end).
-            for (int i = 0; i < packagesToBackup.size(); ) {
-                PackageInfo pkg = packagesToBackup.get(i);
-                if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0
-                        || pkg.packageName.equals(SHARED_BACKUP_AGENT_PACKAGE)) {
-                    packagesToBackup.remove(i);
-                } else {
-                    i++;
-                }
-            }
-
-            // Cull any packages that run as system-domain uids but do not define their
-            // own backup agents
-            for (int i = 0; i < packagesToBackup.size(); ) {
-                PackageInfo pkg = packagesToBackup.get(i);
-                if ((pkg.applicationInfo.uid < Process.FIRST_APPLICATION_UID)
-                        && (pkg.applicationInfo.backupAgentName == null)) {
-                    if (MORE_DEBUG) {
-                        Slog.i(TAG, "... ignoring non-agent system package " + pkg.packageName);
-                    }
-                    packagesToBackup.remove(i);
-                } else {
-                    i++;
-                }
-            }
-
-            FileOutputStream ofstream = new FileOutputStream(mOutputFile.getFileDescriptor());
-            OutputStream out = null;
-
-            PackageInfo pkg = null;
-            try {
-                boolean encrypting = (mEncryptPassword != null && mEncryptPassword.length() > 0);
-                boolean compressing = COMPRESS_FULL_BACKUPS;
-                OutputStream finalOutput = ofstream;
-
-                // Verify that the given password matches the currently-active
-                // backup password, if any
-                if (!backupPasswordMatches(mCurrentPassword)) {
-                    if (DEBUG) Slog.w(TAG, "Backup password mismatch; aborting");
-                    return;
-                }
-
-                // Write the global file header.  All strings are UTF-8 encoded; lines end
-                // with a '\n' byte.  Actual backup data begins immediately following the
-                // final '\n'.
-                //
-                // line 1: "ANDROID BACKUP"
-                // line 2: backup file format version, currently "2"
-                // line 3: compressed?  "0" if not compressed, "1" if compressed.
-                // line 4: name of encryption algorithm [currently only "none" or "AES-256"]
-                //
-                // When line 4 is not "none", then additional header data follows:
-                //
-                // line 5: user password salt [hex]
-                // line 6: master key checksum salt [hex]
-                // line 7: number of PBKDF2 rounds to use (same for user & master) [decimal]
-                // line 8: IV of the user key [hex]
-                // line 9: master key blob [hex]
-                //     IV of the master key, master key itself, master key checksum hash
-                //
-                // The master key checksum is the master key plus its checksum salt, run through
-                // 10k rounds of PBKDF2.  This is used to verify that the user has supplied the
-                // correct password for decrypting the archive:  the master key decrypted from
-                // the archive using the user-supplied password is also run through PBKDF2 in
-                // this way, and if the result does not match the checksum as stored in the
-                // archive, then we know that the user-supplied password does not match the
-                // archive's.
-                StringBuilder headerbuf = new StringBuilder(1024);
-
-                headerbuf.append(BACKUP_FILE_HEADER_MAGIC);
-                headerbuf.append(BACKUP_FILE_VERSION); // integer, no trailing \n
-                headerbuf.append(compressing ? "\n1\n" : "\n0\n");
-
-                try {
-                    // Set up the encryption stage if appropriate, and emit the correct header
-                    if (encrypting) {
-                        finalOutput = emitAesBackupHeader(headerbuf, finalOutput);
-                    } else {
-                        headerbuf.append("none\n");
-                    }
-
-                    byte[] header = headerbuf.toString().getBytes("UTF-8");
-                    ofstream.write(header);
-
-                    // Set up the compression stage feeding into the encryption stage (if any)
-                    if (compressing) {
-                        Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
-                        finalOutput = new DeflaterOutputStream(finalOutput, deflater, true);
-                    }
-
-                    out = finalOutput;
-                } catch (Exception e) {
-                    // Should never happen!
-                    Slog.e(TAG, "Unable to emit archive header", e);
-                    return;
-                }
-
-                // Shared storage if requested
-                if (mIncludeShared) {
-                    try {
-                        pkg = mPackageManager.getPackageInfo(SHARED_BACKUP_AGENT_PACKAGE, 0);
-                        packagesToBackup.add(pkg);
-                    } catch (NameNotFoundException e) {
-                        Slog.e(TAG, "Unable to find shared-storage backup handler");
-                    }
-                }
-
-                // Now back up the app data via the agent mechanism
-                int N = packagesToBackup.size();
-                for (int i = 0; i < N; i++) {
-                    pkg = packagesToBackup.get(i);
-                    backupOnePackage(pkg, out);
-
-                    // after the app's agent runs to handle its private filesystem
-                    // contents, back up any OBB content it has on its behalf.
-                    if (mIncludeObbs) {
-                        boolean obbOkay = obbConnection.backupObbs(pkg, out);
-                        if (!obbOkay) {
-                            throw new RuntimeException("Failure writing OBB stack for " + pkg);
-                        }
-                    }
-                }
-
-                // Done!
-                finalizeBackup(out);
-            } catch (RemoteException e) {
-                Slog.e(TAG, "App died during full backup");
-            } catch (Exception e) {
-                Slog.e(TAG, "Internal exception during full backup", e);
-            } finally {
-                tearDown(pkg);
-                try {
-                    if (out != null) out.close();
-                    mOutputFile.close();
-                } catch (IOException e) {
-                    /* nothing we can do about this */
-                }
-                synchronized (mCurrentOpLock) {
-                    mCurrentOperations.clear();
-                }
-                synchronized (mLatchObject) {
-                    mLatchObject.set(true);
-                    mLatchObject.notifyAll();
-                }
-                sendEndBackup();
-                obbConnection.tearDown();
-                if (DEBUG) Slog.d(TAG, "Full backup pass complete.");
-                mWakelock.release();
-            }
-        }
-
-        private OutputStream emitAesBackupHeader(StringBuilder headerbuf,
-                OutputStream ofstream) throws Exception {
-            // User key will be used to encrypt the master key.
-            byte[] newUserSalt = randomBytes(PBKDF2_SALT_SIZE);
-            SecretKey userKey = buildPasswordKey(PBKDF_CURRENT, mEncryptPassword, newUserSalt,
-                    PBKDF2_HASH_ROUNDS);
-
-            // the master key is random for each backup
-            byte[] masterPw = new byte[256 / 8];
-            mRng.nextBytes(masterPw);
-            byte[] checksumSalt = randomBytes(PBKDF2_SALT_SIZE);
-
-            // primary encryption of the datastream with the random key
-            Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
-            SecretKeySpec masterKeySpec = new SecretKeySpec(masterPw, "AES");
-            c.init(Cipher.ENCRYPT_MODE, masterKeySpec);
-            OutputStream finalOutput = new CipherOutputStream(ofstream, c);
-
-            // line 4: name of encryption algorithm
-            headerbuf.append(ENCRYPTION_ALGORITHM_NAME);
-            headerbuf.append('\n');
-            // line 5: user password salt [hex]
-            headerbuf.append(byteArrayToHex(newUserSalt));
-            headerbuf.append('\n');
-            // line 6: master key checksum salt [hex]
-            headerbuf.append(byteArrayToHex(checksumSalt));
-            headerbuf.append('\n');
-            // line 7: number of PBKDF2 rounds used [decimal]
-            headerbuf.append(PBKDF2_HASH_ROUNDS);
-            headerbuf.append('\n');
-
-            // line 8: IV of the user key [hex]
-            Cipher mkC = Cipher.getInstance("AES/CBC/PKCS5Padding");
-            mkC.init(Cipher.ENCRYPT_MODE, userKey);
-
-            byte[] IV = mkC.getIV();
-            headerbuf.append(byteArrayToHex(IV));
-            headerbuf.append('\n');
-
-            // line 9: master IV + key blob, encrypted by the user key [hex].  Blob format:
-            //    [byte] IV length = Niv
-            //    [array of Niv bytes] IV itself
-            //    [byte] master key length = Nmk
-            //    [array of Nmk bytes] master key itself
-            //    [byte] MK checksum hash length = Nck
-            //    [array of Nck bytes] master key checksum hash
-            //
-            // The checksum is the (master key + checksum salt), run through the
-            // stated number of PBKDF2 rounds
-            IV = c.getIV();
-            byte[] mk = masterKeySpec.getEncoded();
-            byte[] checksum = makeKeyChecksum(PBKDF_CURRENT, masterKeySpec.getEncoded(),
-                    checksumSalt, PBKDF2_HASH_ROUNDS);
-
-            ByteArrayOutputStream blob = new ByteArrayOutputStream(IV.length + mk.length
-                    + checksum.length + 3);
-            DataOutputStream mkOut = new DataOutputStream(blob);
-            mkOut.writeByte(IV.length);
-            mkOut.write(IV);
-            mkOut.writeByte(mk.length);
-            mkOut.write(mk);
-            mkOut.writeByte(checksum.length);
-            mkOut.write(checksum);
-            mkOut.flush();
-            byte[] encryptedMk = mkC.doFinal(blob.toByteArray());
-            headerbuf.append(byteArrayToHex(encryptedMk));
-            headerbuf.append('\n');
-
-            return finalOutput;
-        }
-
-        private void backupOnePackage(PackageInfo pkg, OutputStream out)
-                throws RemoteException {
-            Slog.d(TAG, "Binding to full backup agent : " + pkg.packageName);
-
-            IBackupAgent agent = bindToAgentSynchronous(pkg.applicationInfo,
-                    IApplicationThread.BACKUP_MODE_FULL);
-            if (agent != null) {
-                ParcelFileDescriptor[] pipes = null;
-                try {
-                    pipes = ParcelFileDescriptor.createPipe();
-
-                    ApplicationInfo app = pkg.applicationInfo;
-                    final boolean isSharedStorage = pkg.packageName.equals(SHARED_BACKUP_AGENT_PACKAGE);
-                    final boolean sendApk = mIncludeApks
-                            && !isSharedStorage
-                            && ((app.flags & ApplicationInfo.FLAG_FORWARD_LOCK) == 0)
-                            && ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0 ||
-                                (app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
-
-                    sendOnBackupPackage(isSharedStorage ? "Shared storage" : pkg.packageName);
-
-                    final int token = generateToken();
-                    FullBackupRunner runner = new FullBackupRunner(pkg, agent, pipes[1],
-                            token, sendApk, !isSharedStorage);
-                    pipes[1].close();   // the runner has dup'd it
-                    pipes[1] = null;
-                    Thread t = new Thread(runner);
-                    t.start();
-
-                    // Now pull data from the app and stuff it into the compressor
-                    try {
-                        routeSocketDataToOutput(pipes[0], out);
-                    } catch (IOException e) {
-                        Slog.i(TAG, "Caught exception reading from agent", e);
-                    }
-
-                    if (!waitUntilOperationComplete(token)) {
-                        Slog.e(TAG, "Full backup failed on package " + pkg.packageName);
-                    } else {
-                        if (DEBUG) Slog.d(TAG, "Full package backup success: " + pkg.packageName);
-                    }
-
-                } catch (IOException e) {
-                    Slog.e(TAG, "Error backing up " + pkg.packageName, e);
-                } finally {
-                    try {
-                        // flush after every package
-                        out.flush();
-                        if (pipes != null) {
-                            if (pipes[0] != null) pipes[0].close();
-                            if (pipes[1] != null) pipes[1].close();
-                        }
-                    } catch (IOException e) {
-                        Slog.w(TAG, "Error bringing down backup stack");
-                    }
-                }
-            } else {
-                Slog.w(TAG, "Unable to bind to full agent for " + pkg.packageName);
-            }
-            tearDown(pkg);
-        }
-
-        private void writeApkToBackup(PackageInfo pkg, BackupDataOutput output) {
-            // Forward-locked apps, system-bundled .apks, etc are filtered out before we get here
-            final String appSourceDir = pkg.applicationInfo.sourceDir;
-            final String apkDir = new File(appSourceDir).getParent();
-            FullBackup.backupToTar(pkg.packageName, FullBackup.APK_TREE_TOKEN, null,
-                    apkDir, appSourceDir, output);
-
-            // TODO: migrate this to SharedStorageBackup, since AID_SYSTEM
-            // doesn't have access to external storage.
-
-            // Save associated .obb content if it exists and we did save the apk
-            // check for .obb and save those too
-            final UserEnvironment userEnv = new UserEnvironment(UserHandle.USER_OWNER);
-            final File obbDir = userEnv.buildExternalStorageAppObbDirs(pkg.packageName)[0];
-            if (obbDir != null) {
-                if (MORE_DEBUG) Log.i(TAG, "obb dir: " + obbDir.getAbsolutePath());
-                File[] obbFiles = obbDir.listFiles();
-                if (obbFiles != null) {
-                    final String obbDirName = obbDir.getAbsolutePath();
-                    for (File obb : obbFiles) {
-                        FullBackup.backupToTar(pkg.packageName, FullBackup.OBB_TREE_TOKEN, null,
-                                obbDirName, obb.getAbsolutePath(), output);
-                    }
-                }
-            }
-        }
-
-        private void finalizeBackup(OutputStream out) {
-            try {
-                // A standard 'tar' EOF sequence: two 512-byte blocks of all zeroes.
-                byte[] eof = new byte[512 * 2]; // newly allocated == zero filled
-                out.write(eof);
-            } catch (IOException e) {
-                Slog.w(TAG, "Error attempting to finalize backup stream");
-            }
-        }
-
-        private void writeAppManifest(PackageInfo pkg, File manifestFile, boolean withApk)
-                throws IOException {
-            // Manifest format. All data are strings ending in LF:
-            //     BACKUP_MANIFEST_VERSION, currently 1
-            //
-            // Version 1:
-            //     package name
-            //     package's versionCode
-            //     platform versionCode
-            //     getInstallerPackageName() for this package (maybe empty)
-            //     boolean: "1" if archive includes .apk; any other string means not
-            //     number of signatures == N
-            // N*:    signature byte array in ascii format per Signature.toCharsString()
-            StringBuilder builder = new StringBuilder(4096);
-            StringBuilderPrinter printer = new StringBuilderPrinter(builder);
-
-            printer.println(Integer.toString(BACKUP_MANIFEST_VERSION));
-            printer.println(pkg.packageName);
-            printer.println(Integer.toString(pkg.versionCode));
-            printer.println(Integer.toString(Build.VERSION.SDK_INT));
-
-            String installerName = mPackageManager.getInstallerPackageName(pkg.packageName);
-            printer.println((installerName != null) ? installerName : "");
-
-            printer.println(withApk ? "1" : "0");
-            if (pkg.signatures == null) {
-                printer.println("0");
-            } else {
-                printer.println(Integer.toString(pkg.signatures.length));
-                for (Signature sig : pkg.signatures) {
-                    printer.println(sig.toCharsString());
-                }
-            }
-
-            FileOutputStream outstream = new FileOutputStream(manifestFile);
-            outstream.write(builder.toString().getBytes());
-            outstream.close();
-        }
-
-        private void tearDown(PackageInfo pkg) {
-            if (pkg != null) {
-                final ApplicationInfo app = pkg.applicationInfo;
-                if (app != null) {
-                    try {
-                        // unbind and tidy up even on timeout or failure, just in case
-                        mActivityManager.unbindBackupAgent(app);
-
-                        // The agent was running with a stub Application object, so shut it down.
-                        if (app.uid != Process.SYSTEM_UID
-                                && app.uid != Process.PHONE_UID) {
-                            if (MORE_DEBUG) Slog.d(TAG, "Backup complete, killing host process");
-                            mActivityManager.killApplicationProcess(app.processName, app.uid);
-                        } else {
-                            if (MORE_DEBUG) Slog.d(TAG, "Not killing after restore: " + app.processName);
-                        }
-                    } catch (RemoteException e) {
-                        Slog.d(TAG, "Lost app trying to shut down");
-                    }
-                }
-            }
-        }
-
-        // wrappers for observer use
-        void sendStartBackup() {
-            if (mObserver != null) {
-                try {
-                    mObserver.onStartBackup();
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "full backup observer went away: startBackup");
-                    mObserver = null;
-                }
-            }
-        }
-
-        void sendOnBackupPackage(String name) {
-            if (mObserver != null) {
-                try {
-                    // TODO: use a more user-friendly name string
-                    mObserver.onBackupPackage(name);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "full backup observer went away: backupPackage");
-                    mObserver = null;
-                }
-            }
-        }
-
-        void sendEndBackup() {
-            if (mObserver != null) {
-                try {
-                    mObserver.onEndBackup();
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "full backup observer went away: endBackup");
-                    mObserver = null;
-                }
-            }
-        }
-    }
-
-
-    // ----- Full restore from a file/socket -----
-
-    // Description of a file in the restore datastream
-    static class FileMetadata {
-        String packageName;             // name of the owning app
-        String installerPackageName;    // name of the market-type app that installed the owner
-        int type;                       // e.g. BackupAgent.TYPE_DIRECTORY
-        String domain;                  // e.g. FullBackup.DATABASE_TREE_TOKEN
-        String path;                    // subpath within the semantic domain
-        long mode;                      // e.g. 0666 (actually int)
-        long mtime;                     // last mod time, UTC time_t (actually int)
-        long size;                      // bytes of content
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("FileMetadata{");
-            sb.append(packageName); sb.append(',');
-            sb.append(type); sb.append(',');
-            sb.append(domain); sb.append(':'); sb.append(path); sb.append(',');
-            sb.append(size);
-            sb.append('}');
-            return sb.toString();
-        }
-    }
-
-    enum RestorePolicy {
-        IGNORE,
-        ACCEPT,
-        ACCEPT_IF_APK
-    }
-
-    class PerformFullRestoreTask extends ObbServiceClient implements Runnable {
-        ParcelFileDescriptor mInputFile;
-        String mCurrentPassword;
-        String mDecryptPassword;
-        IFullBackupRestoreObserver mObserver;
-        AtomicBoolean mLatchObject;
-        IBackupAgent mAgent;
-        String mAgentPackage;
-        ApplicationInfo mTargetApp;
-        FullBackupObbConnection mObbConnection = null;
-        ParcelFileDescriptor[] mPipes = null;
-
-        long mBytes;
-
-        // possible handling states for a given package in the restore dataset
-        final HashMap<String, RestorePolicy> mPackagePolicies
-                = new HashMap<String, RestorePolicy>();
-
-        // installer package names for each encountered app, derived from the manifests
-        final HashMap<String, String> mPackageInstallers = new HashMap<String, String>();
-
-        // Signatures for a given package found in its manifest file
-        final HashMap<String, Signature[]> mManifestSignatures
-                = new HashMap<String, Signature[]>();
-
-        // Packages we've already wiped data on when restoring their first file
-        final HashSet<String> mClearedPackages = new HashSet<String>();
-
-        PerformFullRestoreTask(ParcelFileDescriptor fd, String curPassword, String decryptPassword,
-                IFullBackupRestoreObserver observer, AtomicBoolean latch) {
-            mInputFile = fd;
-            mCurrentPassword = curPassword;
-            mDecryptPassword = decryptPassword;
-            mObserver = observer;
-            mLatchObject = latch;
-            mAgent = null;
-            mAgentPackage = null;
-            mTargetApp = null;
-            mObbConnection = new FullBackupObbConnection();
-
-            // Which packages we've already wiped data on.  We prepopulate this
-            // with a whitelist of packages known to be unclearable.
-            mClearedPackages.add("android");
-            mClearedPackages.add("com.android.providers.settings");
-
-        }
-
-        class RestoreFileRunnable implements Runnable {
-            IBackupAgent mAgent;
-            FileMetadata mInfo;
-            ParcelFileDescriptor mSocket;
-            int mToken;
-
-            RestoreFileRunnable(IBackupAgent agent, FileMetadata info,
-                    ParcelFileDescriptor socket, int token) throws IOException {
-                mAgent = agent;
-                mInfo = info;
-                mToken = token;
-
-                // This class is used strictly for process-local binder invocations.  The
-                // semantics of ParcelFileDescriptor differ in this case; in particular, we
-                // do not automatically get a 'dup'ed descriptor that we can can continue
-                // to use asynchronously from the caller.  So, we make sure to dup it ourselves
-                // before proceeding to do the restore.
-                mSocket = ParcelFileDescriptor.dup(socket.getFileDescriptor());
-            }
-
-            @Override
-            public void run() {
-                try {
-                    mAgent.doRestoreFile(mSocket, mInfo.size, mInfo.type,
-                            mInfo.domain, mInfo.path, mInfo.mode, mInfo.mtime,
-                            mToken, mBackupManagerBinder);
-                } catch (RemoteException e) {
-                    // never happens; this is used strictly for local binder calls
-                }
-            }
-        }
-
-        @Override
-        public void run() {
-            Slog.i(TAG, "--- Performing full-dataset restore ---");
-            mObbConnection.establish();
-            sendStartRestore();
-
-            // Are we able to restore shared-storage data?
-            if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
-                mPackagePolicies.put(SHARED_BACKUP_AGENT_PACKAGE, RestorePolicy.ACCEPT);
-            }
-
-            FileInputStream rawInStream = null;
-            DataInputStream rawDataIn = null;
-            try {
-                if (!backupPasswordMatches(mCurrentPassword)) {
-                    if (DEBUG) Slog.w(TAG, "Backup password mismatch; aborting");
-                    return;
-                }
-
-                mBytes = 0;
-                byte[] buffer = new byte[32 * 1024];
-                rawInStream = new FileInputStream(mInputFile.getFileDescriptor());
-                rawDataIn = new DataInputStream(rawInStream);
-
-                // First, parse out the unencrypted/uncompressed header
-                boolean compressed = false;
-                InputStream preCompressStream = rawInStream;
-                final InputStream in;
-
-                boolean okay = false;
-                final int headerLen = BACKUP_FILE_HEADER_MAGIC.length();
-                byte[] streamHeader = new byte[headerLen];
-                rawDataIn.readFully(streamHeader);
-                byte[] magicBytes = BACKUP_FILE_HEADER_MAGIC.getBytes("UTF-8");
-                if (Arrays.equals(magicBytes, streamHeader)) {
-                    // okay, header looks good.  now parse out the rest of the fields.
-                    String s = readHeaderLine(rawInStream);
-                    final int archiveVersion = Integer.parseInt(s);
-                    if (archiveVersion <= BACKUP_FILE_VERSION) {
-                        // okay, it's a version we recognize.  if it's version 1, we may need
-                        // to try two different PBKDF2 regimes to compare checksums.
-                        final boolean pbkdf2Fallback = (archiveVersion == 1);
-
-                        s = readHeaderLine(rawInStream);
-                        compressed = (Integer.parseInt(s) != 0);
-                        s = readHeaderLine(rawInStream);
-                        if (s.equals("none")) {
-                            // no more header to parse; we're good to go
-                            okay = true;
-                        } else if (mDecryptPassword != null && mDecryptPassword.length() > 0) {
-                            preCompressStream = decodeAesHeaderAndInitialize(s, pbkdf2Fallback,
-                                    rawInStream);
-                            if (preCompressStream != null) {
-                                okay = true;
-                            }
-                        } else Slog.w(TAG, "Archive is encrypted but no password given");
-                    } else Slog.w(TAG, "Wrong header version: " + s);
-                } else Slog.w(TAG, "Didn't read the right header magic");
-
-                if (!okay) {
-                    Slog.w(TAG, "Invalid restore data; aborting.");
-                    return;
-                }
-
-                // okay, use the right stream layer based on compression
-                in = (compressed) ? new InflaterInputStream(preCompressStream) : preCompressStream;
-
-                boolean didRestore;
-                do {
-                    didRestore = restoreOneFile(in, buffer);
-                } while (didRestore);
-
-                if (MORE_DEBUG) Slog.v(TAG, "Done consuming input tarfile, total bytes=" + mBytes);
-            } catch (IOException e) {
-                Slog.e(TAG, "Unable to read restore input");
-            } finally {
-                tearDownPipes();
-                tearDownAgent(mTargetApp);
-
-                try {
-                    if (rawDataIn != null) rawDataIn.close();
-                    if (rawInStream != null) rawInStream.close();
-                    mInputFile.close();
-                } catch (IOException e) {
-                    Slog.w(TAG, "Close of restore data pipe threw", e);
-                    /* nothing we can do about this */
-                }
-                synchronized (mCurrentOpLock) {
-                    mCurrentOperations.clear();
-                }
-                synchronized (mLatchObject) {
-                    mLatchObject.set(true);
-                    mLatchObject.notifyAll();
-                }
-                mObbConnection.tearDown();
-                sendEndRestore();
-                Slog.d(TAG, "Full restore pass complete.");
-                mWakelock.release();
-            }
-        }
-
-        String readHeaderLine(InputStream in) throws IOException {
-            int c;
-            StringBuilder buffer = new StringBuilder(80);
-            while ((c = in.read()) >= 0) {
-                if (c == '\n') break;   // consume and discard the newlines
-                buffer.append((char)c);
-            }
-            return buffer.toString();
-        }
-
-        InputStream attemptMasterKeyDecryption(String algorithm, byte[] userSalt, byte[] ckSalt,
-                int rounds, String userIvHex, String masterKeyBlobHex, InputStream rawInStream,
-                boolean doLog) {
-            InputStream result = null;
-
-            try {
-                Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
-                SecretKey userKey = buildPasswordKey(algorithm, mDecryptPassword, userSalt,
-                        rounds);
-                byte[] IV = hexToByteArray(userIvHex);
-                IvParameterSpec ivSpec = new IvParameterSpec(IV);
-                c.init(Cipher.DECRYPT_MODE,
-                        new SecretKeySpec(userKey.getEncoded(), "AES"),
-                        ivSpec);
-                byte[] mkCipher = hexToByteArray(masterKeyBlobHex);
-                byte[] mkBlob = c.doFinal(mkCipher);
-
-                // first, the master key IV
-                int offset = 0;
-                int len = mkBlob[offset++];
-                IV = Arrays.copyOfRange(mkBlob, offset, offset + len);
-                offset += len;
-                // then the master key itself
-                len = mkBlob[offset++];
-                byte[] mk = Arrays.copyOfRange(mkBlob,
-                        offset, offset + len);
-                offset += len;
-                // and finally the master key checksum hash
-                len = mkBlob[offset++];
-                byte[] mkChecksum = Arrays.copyOfRange(mkBlob,
-                        offset, offset + len);
-
-                // now validate the decrypted master key against the checksum
-                byte[] calculatedCk = makeKeyChecksum(algorithm, mk, ckSalt, rounds);
-                if (Arrays.equals(calculatedCk, mkChecksum)) {
-                    ivSpec = new IvParameterSpec(IV);
-                    c.init(Cipher.DECRYPT_MODE,
-                            new SecretKeySpec(mk, "AES"),
-                            ivSpec);
-                    // Only if all of the above worked properly will 'result' be assigned
-                    result = new CipherInputStream(rawInStream, c);
-                } else if (doLog) Slog.w(TAG, "Incorrect password");
-            } catch (InvalidAlgorithmParameterException e) {
-                if (doLog) Slog.e(TAG, "Needed parameter spec unavailable!", e);
-            } catch (BadPaddingException e) {
-                // This case frequently occurs when the wrong password is used to decrypt
-                // the master key.  Use the identical "incorrect password" log text as is
-                // used in the checksum failure log in order to avoid providing additional
-                // information to an attacker.
-                if (doLog) Slog.w(TAG, "Incorrect password");
-            } catch (IllegalBlockSizeException e) {
-                if (doLog) Slog.w(TAG, "Invalid block size in master key");
-            } catch (NoSuchAlgorithmException e) {
-                if (doLog) Slog.e(TAG, "Needed decryption algorithm unavailable!");
-            } catch (NoSuchPaddingException e) {
-                if (doLog) Slog.e(TAG, "Needed padding mechanism unavailable!");
-            } catch (InvalidKeyException e) {
-                if (doLog) Slog.w(TAG, "Illegal password; aborting");
-            }
-
-            return result;
-        }
-
-        InputStream decodeAesHeaderAndInitialize(String encryptionName, boolean pbkdf2Fallback,
-                InputStream rawInStream) {
-            InputStream result = null;
-            try {
-                if (encryptionName.equals(ENCRYPTION_ALGORITHM_NAME)) {
-
-                    String userSaltHex = readHeaderLine(rawInStream); // 5
-                    byte[] userSalt = hexToByteArray(userSaltHex);
-
-                    String ckSaltHex = readHeaderLine(rawInStream); // 6
-                    byte[] ckSalt = hexToByteArray(ckSaltHex);
-
-                    int rounds = Integer.parseInt(readHeaderLine(rawInStream)); // 7
-                    String userIvHex = readHeaderLine(rawInStream); // 8
-
-                    String masterKeyBlobHex = readHeaderLine(rawInStream); // 9
-
-                    // decrypt the master key blob
-                    result = attemptMasterKeyDecryption(PBKDF_CURRENT, userSalt, ckSalt,
-                            rounds, userIvHex, masterKeyBlobHex, rawInStream, false);
-                    if (result == null && pbkdf2Fallback) {
-                        result = attemptMasterKeyDecryption(PBKDF_FALLBACK, userSalt, ckSalt,
-                                rounds, userIvHex, masterKeyBlobHex, rawInStream, true);
-                    }
-                } else Slog.w(TAG, "Unsupported encryption method: " + encryptionName);
-            } catch (NumberFormatException e) {
-                Slog.w(TAG, "Can't parse restore data header");
-            } catch (IOException e) {
-                Slog.w(TAG, "Can't read input header");
-            }
-
-            return result;
-        }
-
-        boolean restoreOneFile(InputStream instream, byte[] buffer) {
-            FileMetadata info;
-            try {
-                info = readTarHeaders(instream);
-                if (info != null) {
-                    if (MORE_DEBUG) {
-                        dumpFileMetadata(info);
-                    }
-
-                    final String pkg = info.packageName;
-                    if (!pkg.equals(mAgentPackage)) {
-                        // okay, change in package; set up our various
-                        // bookkeeping if we haven't seen it yet
-                        if (!mPackagePolicies.containsKey(pkg)) {
-                            mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
-                        }
-
-                        // Clean up the previous agent relationship if necessary,
-                        // and let the observer know we're considering a new app.
-                        if (mAgent != null) {
-                            if (DEBUG) Slog.d(TAG, "Saw new package; tearing down old one");
-                            tearDownPipes();
-                            tearDownAgent(mTargetApp);
-                            mTargetApp = null;
-                            mAgentPackage = null;
-                        }
-                    }
-
-                    if (info.path.equals(BACKUP_MANIFEST_FILENAME)) {
-                        mPackagePolicies.put(pkg, readAppManifest(info, instream));
-                        mPackageInstallers.put(pkg, info.installerPackageName);
-                        // We've read only the manifest content itself at this point,
-                        // so consume the footer before looping around to the next
-                        // input file
-                        skipTarPadding(info.size, instream);
-                        sendOnRestorePackage(pkg);
-                    } else {
-                        // Non-manifest, so it's actual file data.  Is this a package
-                        // we're ignoring?
-                        boolean okay = true;
-                        RestorePolicy policy = mPackagePolicies.get(pkg);
-                        switch (policy) {
-                            case IGNORE:
-                                okay = false;
-                                break;
-
-                            case ACCEPT_IF_APK:
-                                // If we're in accept-if-apk state, then the first file we
-                                // see MUST be the apk.
-                                if (info.domain.equals(FullBackup.APK_TREE_TOKEN)) {
-                                    if (DEBUG) Slog.d(TAG, "APK file; installing");
-                                    // Try to install the app.
-                                    String installerName = mPackageInstallers.get(pkg);
-                                    okay = installApk(info, installerName, instream);
-                                    // good to go; promote to ACCEPT
-                                    mPackagePolicies.put(pkg, (okay)
-                                            ? RestorePolicy.ACCEPT
-                                            : RestorePolicy.IGNORE);
-                                    // At this point we've consumed this file entry
-                                    // ourselves, so just strip the tar footer and
-                                    // go on to the next file in the input stream
-                                    skipTarPadding(info.size, instream);
-                                    return true;
-                                } else {
-                                    // File data before (or without) the apk.  We can't
-                                    // handle it coherently in this case so ignore it.
-                                    mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
-                                    okay = false;
-                                }
-                                break;
-
-                            case ACCEPT:
-                                if (info.domain.equals(FullBackup.APK_TREE_TOKEN)) {
-                                    if (DEBUG) Slog.d(TAG, "apk present but ACCEPT");
-                                    // we can take the data without the apk, so we
-                                    // *want* to do so.  skip the apk by declaring this
-                                    // one file not-okay without changing the restore
-                                    // policy for the package.
-                                    okay = false;
-                                }
-                                break;
-
-                            default:
-                                // Something has gone dreadfully wrong when determining
-                                // the restore policy from the manifest.  Ignore the
-                                // rest of this package's data.
-                                Slog.e(TAG, "Invalid policy from manifest");
-                                okay = false;
-                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
-                                break;
-                        }
-
-                        // If the policy is satisfied, go ahead and set up to pipe the
-                        // data to the agent.
-                        if (DEBUG && okay && mAgent != null) {
-                            Slog.i(TAG, "Reusing existing agent instance");
-                        }
-                        if (okay && mAgent == null) {
-                            if (DEBUG) Slog.d(TAG, "Need to launch agent for " + pkg);
-
-                            try {
-                                mTargetApp = mPackageManager.getApplicationInfo(pkg, 0);
-
-                                // If we haven't sent any data to this app yet, we probably
-                                // need to clear it first.  Check that.
-                                if (!mClearedPackages.contains(pkg)) {
-                                    // apps with their own backup agents are
-                                    // responsible for coherently managing a full
-                                    // restore.
-                                    if (mTargetApp.backupAgentName == null) {
-                                        if (DEBUG) Slog.d(TAG, "Clearing app data preparatory to full restore");
-                                        clearApplicationDataSynchronous(pkg);
-                                    } else {
-                                        if (DEBUG) Slog.d(TAG, "backup agent ("
-                                                + mTargetApp.backupAgentName + ") => no clear");
-                                    }
-                                    mClearedPackages.add(pkg);
-                                } else {
-                                    if (DEBUG) Slog.d(TAG, "We've initialized this app already; no clear required");
-                                }
-
-                                // All set; now set up the IPC and launch the agent
-                                setUpPipes();
-                                mAgent = bindToAgentSynchronous(mTargetApp,
-                                        IApplicationThread.BACKUP_MODE_RESTORE_FULL);
-                                mAgentPackage = pkg;
-                            } catch (IOException e) {
-                                // fall through to error handling
-                            } catch (NameNotFoundException e) {
-                                // fall through to error handling
-                            }
-
-                            if (mAgent == null) {
-                                if (DEBUG) Slog.d(TAG, "Unable to create agent for " + pkg);
-                                okay = false;
-                                tearDownPipes();
-                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
-                            }
-                        }
-
-                        // Sanity check: make sure we never give data to the wrong app.  This
-                        // should never happen but a little paranoia here won't go amiss.
-                        if (okay && !pkg.equals(mAgentPackage)) {
-                            Slog.e(TAG, "Restoring data for " + pkg
-                                    + " but agent is for " + mAgentPackage);
-                            okay = false;
-                        }
-
-                        // At this point we have an agent ready to handle the full
-                        // restore data as well as a pipe for sending data to
-                        // that agent.  Tell the agent to start reading from the
-                        // pipe.
-                        if (okay) {
-                            boolean agentSuccess = true;
-                            long toCopy = info.size;
-                            final int token = generateToken();
-                            try {
-                                prepareOperationTimeout(token, TIMEOUT_FULL_BACKUP_INTERVAL, null);
-                                if (info.domain.equals(FullBackup.OBB_TREE_TOKEN)) {
-                                    if (DEBUG) Slog.d(TAG, "Restoring OBB file for " + pkg
-                                            + " : " + info.path);
-                                    mObbConnection.restoreObbFile(pkg, mPipes[0],
-                                            info.size, info.type, info.path, info.mode,
-                                            info.mtime, token, mBackupManagerBinder);
-                                } else {
-                                    if (DEBUG) Slog.d(TAG, "Invoking agent to restore file "
-                                            + info.path);
-                                    // fire up the app's agent listening on the socket.  If
-                                    // the agent is running in the system process we can't
-                                    // just invoke it asynchronously, so we provide a thread
-                                    // for it here.
-                                    if (mTargetApp.processName.equals("system")) {
-                                        Slog.d(TAG, "system process agent - spinning a thread");
-                                        RestoreFileRunnable runner = new RestoreFileRunnable(
-                                                mAgent, info, mPipes[0], token);
-                                        new Thread(runner).start();
-                                    } else {
-                                        mAgent.doRestoreFile(mPipes[0], info.size, info.type,
-                                                info.domain, info.path, info.mode, info.mtime,
-                                                token, mBackupManagerBinder);
-                                    }
-                                }
-                            } catch (IOException e) {
-                                // couldn't dup the socket for a process-local restore
-                                Slog.d(TAG, "Couldn't establish restore");
-                                agentSuccess = false;
-                                okay = false;
-                            } catch (RemoteException e) {
-                                // whoops, remote entity went away.  We'll eat the content
-                                // ourselves, then, and not copy it over.
-                                Slog.e(TAG, "Agent crashed during full restore");
-                                agentSuccess = false;
-                                okay = false;
-                            }
-
-                            // Copy over the data if the agent is still good
-                            if (okay) {
-                                boolean pipeOkay = true;
-                                FileOutputStream pipe = new FileOutputStream(
-                                        mPipes[1].getFileDescriptor());
-                                while (toCopy > 0) {
-                                    int toRead = (toCopy > buffer.length)
-                                    ? buffer.length : (int)toCopy;
-                                    int nRead = instream.read(buffer, 0, toRead);
-                                    if (nRead >= 0) mBytes += nRead;
-                                    if (nRead <= 0) break;
-                                    toCopy -= nRead;
-
-                                    // send it to the output pipe as long as things
-                                    // are still good
-                                    if (pipeOkay) {
-                                        try {
-                                            pipe.write(buffer, 0, nRead);
-                                        } catch (IOException e) {
-                                            Slog.e(TAG, "Failed to write to restore pipe", e);
-                                            pipeOkay = false;
-                                        }
-                                    }
-                                }
-
-                                // done sending that file!  Now we just need to consume
-                                // the delta from info.size to the end of block.
-                                skipTarPadding(info.size, instream);
-
-                                // and now that we've sent it all, wait for the remote
-                                // side to acknowledge receipt
-                                agentSuccess = waitUntilOperationComplete(token);
-                            }
-
-                            // okay, if the remote end failed at any point, deal with
-                            // it by ignoring the rest of the restore on it
-                            if (!agentSuccess) {
-                                mBackupHandler.removeMessages(MSG_TIMEOUT);
-                                tearDownPipes();
-                                tearDownAgent(mTargetApp);
-                                mAgent = null;
-                                mPackagePolicies.put(pkg, RestorePolicy.IGNORE);
-                            }
-                        }
-
-                        // Problems setting up the agent communication, or an already-
-                        // ignored package: skip to the next tar stream entry by
-                        // reading and discarding this file.
-                        if (!okay) {
-                            if (DEBUG) Slog.d(TAG, "[discarding file content]");
-                            long bytesToConsume = (info.size + 511) & ~511;
-                            while (bytesToConsume > 0) {
-                                int toRead = (bytesToConsume > buffer.length)
-                                ? buffer.length : (int)bytesToConsume;
-                                long nRead = instream.read(buffer, 0, toRead);
-                                if (nRead >= 0) mBytes += nRead;
-                                if (nRead <= 0) break;
-                                bytesToConsume -= nRead;
-                            }
-                        }
-                    }
-                }
-            } catch (IOException e) {
-                if (DEBUG) Slog.w(TAG, "io exception on restore socket read", e);
-                // treat as EOF
-                info = null;
-            }
-
-            return (info != null);
-        }
-
-        void setUpPipes() throws IOException {
-            mPipes = ParcelFileDescriptor.createPipe();
-        }
-
-        void tearDownPipes() {
-            if (mPipes != null) {
-                try {
-                    mPipes[0].close();
-                    mPipes[0] = null;
-                    mPipes[1].close();
-                    mPipes[1] = null;
-                } catch (IOException e) {
-                    Slog.w(TAG, "Couldn't close agent pipes", e);
-                }
-                mPipes = null;
-            }
-        }
-
-        void tearDownAgent(ApplicationInfo app) {
-            if (mAgent != null) {
-                try {
-                    // unbind and tidy up even on timeout or failure, just in case
-                    mActivityManager.unbindBackupAgent(app);
-
-                    // The agent was running with a stub Application object, so shut it down.
-                    // !!! We hardcode the confirmation UI's package name here rather than use a
-                    //     manifest flag!  TODO something less direct.
-                    if (app.uid != Process.SYSTEM_UID
-                            && !app.packageName.equals("com.android.backupconfirm")) {
-                        if (DEBUG) Slog.d(TAG, "Killing host process");
-                        mActivityManager.killApplicationProcess(app.processName, app.uid);
-                    } else {
-                        if (DEBUG) Slog.d(TAG, "Not killing after full restore");
-                    }
-                } catch (RemoteException e) {
-                    Slog.d(TAG, "Lost app trying to shut down");
-                }
-                mAgent = null;
-            }
-        }
-
-        class RestoreInstallObserver extends IPackageInstallObserver.Stub {
-            final AtomicBoolean mDone = new AtomicBoolean();
-            String mPackageName;
-            int mResult;
-
-            public void reset() {
-                synchronized (mDone) {
-                    mDone.set(false);
-                }
-            }
-
-            public void waitForCompletion() {
-                synchronized (mDone) {
-                    while (mDone.get() == false) {
-                        try {
-                            mDone.wait();
-                        } catch (InterruptedException e) { }
-                    }
-                }
-            }
-
-            int getResult() {
-                return mResult;
-            }
-
-            @Override
-            public void packageInstalled(String packageName, int returnCode)
-                    throws RemoteException {
-                synchronized (mDone) {
-                    mResult = returnCode;
-                    mPackageName = packageName;
-                    mDone.set(true);
-                    mDone.notifyAll();
-                }
-            }
-        }
-
-        class RestoreDeleteObserver extends IPackageDeleteObserver.Stub {
-            final AtomicBoolean mDone = new AtomicBoolean();
-            int mResult;
-
-            public void reset() {
-                synchronized (mDone) {
-                    mDone.set(false);
-                }
-            }
-
-            public void waitForCompletion() {
-                synchronized (mDone) {
-                    while (mDone.get() == false) {
-                        try {
-                            mDone.wait();
-                        } catch (InterruptedException e) { }
-                    }
-                }
-            }
-
-            @Override
-            public void packageDeleted(String packageName, int returnCode) throws RemoteException {
-                synchronized (mDone) {
-                    mResult = returnCode;
-                    mDone.set(true);
-                    mDone.notifyAll();
-                }
-            }
-        }
-
-        final RestoreInstallObserver mInstallObserver = new RestoreInstallObserver();
-        final RestoreDeleteObserver mDeleteObserver = new RestoreDeleteObserver();
-
-        boolean installApk(FileMetadata info, String installerPackage, InputStream instream) {
-            boolean okay = true;
-
-            if (DEBUG) Slog.d(TAG, "Installing from backup: " + info.packageName);
-
-            // The file content is an .apk file.  Copy it out to a staging location and
-            // attempt to install it.
-            File apkFile = new File(mDataDir, info.packageName);
-            try {
-                FileOutputStream apkStream = new FileOutputStream(apkFile);
-                byte[] buffer = new byte[32 * 1024];
-                long size = info.size;
-                while (size > 0) {
-                    long toRead = (buffer.length < size) ? buffer.length : size;
-                    int didRead = instream.read(buffer, 0, (int)toRead);
-                    if (didRead >= 0) mBytes += didRead;
-                    apkStream.write(buffer, 0, didRead);
-                    size -= didRead;
-                }
-                apkStream.close();
-
-                // make sure the installer can read it
-                apkFile.setReadable(true, false);
-
-                // Now install it
-                Uri packageUri = Uri.fromFile(apkFile);
-                mInstallObserver.reset();
-                mPackageManager.installPackage(packageUri, mInstallObserver,
-                        PackageManager.INSTALL_REPLACE_EXISTING | PackageManager.INSTALL_FROM_ADB,
-                        installerPackage);
-                mInstallObserver.waitForCompletion();
-
-                if (mInstallObserver.getResult() != PackageManager.INSTALL_SUCCEEDED) {
-                    // The only time we continue to accept install of data even if the
-                    // apk install failed is if we had already determined that we could
-                    // accept the data regardless.
-                    if (mPackagePolicies.get(info.packageName) != RestorePolicy.ACCEPT) {
-                        okay = false;
-                    }
-                } else {
-                    // Okay, the install succeeded.  Make sure it was the right app.
-                    boolean uninstall = false;
-                    if (!mInstallObserver.mPackageName.equals(info.packageName)) {
-                        Slog.w(TAG, "Restore stream claimed to include apk for "
-                                + info.packageName + " but apk was really "
-                                + mInstallObserver.mPackageName);
-                        // delete the package we just put in place; it might be fraudulent
-                        okay = false;
-                        uninstall = true;
-                    } else {
-                        try {
-                            PackageInfo pkg = mPackageManager.getPackageInfo(info.packageName,
-                                    PackageManager.GET_SIGNATURES);
-                            if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) == 0) {
-                                Slog.w(TAG, "Restore stream contains apk of package "
-                                        + info.packageName + " but it disallows backup/restore");
-                                okay = false;
-                            } else {
-                                // So far so good -- do the signatures match the manifest?
-                                Signature[] sigs = mManifestSignatures.get(info.packageName);
-                                if (signaturesMatch(sigs, pkg)) {
-                                    // If this is a system-uid app without a declared backup agent,
-                                    // don't restore any of the file data.
-                                    if ((pkg.applicationInfo.uid < Process.FIRST_APPLICATION_UID)
-                                            && (pkg.applicationInfo.backupAgentName == null)) {
-                                        Slog.w(TAG, "Installed app " + info.packageName
-                                                + " has restricted uid and no agent");
-                                        okay = false;
-                                    }
-                                } else {
-                                    Slog.w(TAG, "Installed app " + info.packageName
-                                            + " signatures do not match restore manifest");
-                                    okay = false;
-                                    uninstall = true;
-                                }
-                            }
-                        } catch (NameNotFoundException e) {
-                            Slog.w(TAG, "Install of package " + info.packageName
-                                    + " succeeded but now not found");
-                            okay = false;
-                        }
-                    }
-
-                    // If we're not okay at this point, we need to delete the package
-                    // that we just installed.
-                    if (uninstall) {
-                        mDeleteObserver.reset();
-                        mPackageManager.deletePackage(mInstallObserver.mPackageName,
-                                mDeleteObserver, 0);
-                        mDeleteObserver.waitForCompletion();
-                    }
-                }
-            } catch (IOException e) {
-                Slog.e(TAG, "Unable to transcribe restored apk for install");
-                okay = false;
-            } finally {
-                apkFile.delete();
-            }
-
-            return okay;
-        }
-
-        // Given an actual file content size, consume the post-content padding mandated
-        // by the tar format.
-        void skipTarPadding(long size, InputStream instream) throws IOException {
-            long partial = (size + 512) % 512;
-            if (partial > 0) {
-                final int needed = 512 - (int)partial;
-                byte[] buffer = new byte[needed];
-                if (readExactly(instream, buffer, 0, needed) == needed) {
-                    mBytes += needed;
-                } else throw new IOException("Unexpected EOF in padding");
-            }
-        }
-
-        // Returns a policy constant; takes a buffer arg to reduce memory churn
-        RestorePolicy readAppManifest(FileMetadata info, InputStream instream)
-                throws IOException {
-            // Fail on suspiciously large manifest files
-            if (info.size > 64 * 1024) {
-                throw new IOException("Restore manifest too big; corrupt? size=" + info.size);
-            }
-
-            byte[] buffer = new byte[(int) info.size];
-            if (readExactly(instream, buffer, 0, (int)info.size) == info.size) {
-                mBytes += info.size;
-            } else throw new IOException("Unexpected EOF in manifest");
-
-            RestorePolicy policy = RestorePolicy.IGNORE;
-            String[] str = new String[1];
-            int offset = 0;
-
-            try {
-                offset = extractLine(buffer, offset, str);
-                int version = Integer.parseInt(str[0]);
-                if (version == BACKUP_MANIFEST_VERSION) {
-                    offset = extractLine(buffer, offset, str);
-                    String manifestPackage = str[0];
-                    // TODO: handle <original-package>
-                    if (manifestPackage.equals(info.packageName)) {
-                        offset = extractLine(buffer, offset, str);
-                        version = Integer.parseInt(str[0]);  // app version
-                        offset = extractLine(buffer, offset, str);
-                        int platformVersion = Integer.parseInt(str[0]);
-                        offset = extractLine(buffer, offset, str);
-                        info.installerPackageName = (str[0].length() > 0) ? str[0] : null;
-                        offset = extractLine(buffer, offset, str);
-                        boolean hasApk = str[0].equals("1");
-                        offset = extractLine(buffer, offset, str);
-                        int numSigs = Integer.parseInt(str[0]);
-                        if (numSigs > 0) {
-                            Signature[] sigs = new Signature[numSigs];
-                            for (int i = 0; i < numSigs; i++) {
-                                offset = extractLine(buffer, offset, str);
-                                sigs[i] = new Signature(str[0]);
-                            }
-                            mManifestSignatures.put(info.packageName, sigs);
-
-                            // Okay, got the manifest info we need...
-                            try {
-                                PackageInfo pkgInfo = mPackageManager.getPackageInfo(
-                                        info.packageName, PackageManager.GET_SIGNATURES);
-                                // Fall through to IGNORE if the app explicitly disallows backup
-                                final int flags = pkgInfo.applicationInfo.flags;
-                                if ((flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0) {
-                                    // Restore system-uid-space packages only if they have
-                                    // defined a custom backup agent
-                                    if ((pkgInfo.applicationInfo.uid >= Process.FIRST_APPLICATION_UID)
-                                            || (pkgInfo.applicationInfo.backupAgentName != null)) {
-                                        // Verify signatures against any installed version; if they
-                                        // don't match, then we fall though and ignore the data.  The
-                                        // signatureMatch() method explicitly ignores the signature
-                                        // check for packages installed on the system partition, because
-                                        // such packages are signed with the platform cert instead of
-                                        // the app developer's cert, so they're different on every
-                                        // device.
-                                        if (signaturesMatch(sigs, pkgInfo)) {
-                                            if (pkgInfo.versionCode >= version) {
-                                                Slog.i(TAG, "Sig + version match; taking data");
-                                                policy = RestorePolicy.ACCEPT;
-                                            } else {
-                                                // The data is from a newer version of the app than
-                                                // is presently installed.  That means we can only
-                                                // use it if the matching apk is also supplied.
-                                                Slog.d(TAG, "Data version " + version
-                                                        + " is newer than installed version "
-                                                        + pkgInfo.versionCode + " - requiring apk");
-                                                policy = RestorePolicy.ACCEPT_IF_APK;
-                                            }
-                                        } else {
-                                            Slog.w(TAG, "Restore manifest signatures do not match "
-                                                    + "installed application for " + info.packageName);
-                                        }
-                                    } else {
-                                        Slog.w(TAG, "Package " + info.packageName
-                                                + " is system level with no agent");
-                                    }
-                                } else {
-                                    if (DEBUG) Slog.i(TAG, "Restore manifest from "
-                                            + info.packageName + " but allowBackup=false");
-                                }
-                            } catch (NameNotFoundException e) {
-                                // Okay, the target app isn't installed.  We can process
-                                // the restore properly only if the dataset provides the
-                                // apk file and we can successfully install it.
-                                if (DEBUG) Slog.i(TAG, "Package " + info.packageName
-                                        + " not installed; requiring apk in dataset");
-                                policy = RestorePolicy.ACCEPT_IF_APK;
-                            }
-
-                            if (policy == RestorePolicy.ACCEPT_IF_APK && !hasApk) {
-                                Slog.i(TAG, "Cannot restore package " + info.packageName
-                                        + " without the matching .apk");
-                            }
-                        } else {
-                            Slog.i(TAG, "Missing signature on backed-up package "
-                                    + info.packageName);
-                        }
-                    } else {
-                        Slog.i(TAG, "Expected package " + info.packageName
-                                + " but restore manifest claims " + manifestPackage);
-                    }
-                } else {
-                    Slog.i(TAG, "Unknown restore manifest version " + version
-                            + " for package " + info.packageName);
-                }
-            } catch (NumberFormatException e) {
-                Slog.w(TAG, "Corrupt restore manifest for package " + info.packageName);
-            } catch (IllegalArgumentException e) {
-                Slog.w(TAG, e.getMessage());
-            }
-
-            return policy;
-        }
-
-        // Builds a line from a byte buffer starting at 'offset', and returns
-        // the index of the next unconsumed data in the buffer.
-        int extractLine(byte[] buffer, int offset, String[] outStr) throws IOException {
-            final int end = buffer.length;
-            if (offset >= end) throw new IOException("Incomplete data");
-
-            int pos;
-            for (pos = offset; pos < end; pos++) {
-                byte c = buffer[pos];
-                // at LF we declare end of line, and return the next char as the
-                // starting point for the next time through
-                if (c == '\n') {
-                    break;
-                }
-            }
-            outStr[0] = new String(buffer, offset, pos - offset);
-            pos++;  // may be pointing an extra byte past the end but that's okay
-            return pos;
-        }
-
-        void dumpFileMetadata(FileMetadata info) {
-            if (DEBUG) {
-                StringBuilder b = new StringBuilder(128);
-
-                // mode string
-                b.append((info.type == BackupAgent.TYPE_DIRECTORY) ? 'd' : '-');
-                b.append(((info.mode & 0400) != 0) ? 'r' : '-');
-                b.append(((info.mode & 0200) != 0) ? 'w' : '-');
-                b.append(((info.mode & 0100) != 0) ? 'x' : '-');
-                b.append(((info.mode & 0040) != 0) ? 'r' : '-');
-                b.append(((info.mode & 0020) != 0) ? 'w' : '-');
-                b.append(((info.mode & 0010) != 0) ? 'x' : '-');
-                b.append(((info.mode & 0004) != 0) ? 'r' : '-');
-                b.append(((info.mode & 0002) != 0) ? 'w' : '-');
-                b.append(((info.mode & 0001) != 0) ? 'x' : '-');
-                b.append(String.format(" %9d ", info.size));
-
-                Date stamp = new Date(info.mtime);
-                b.append(new SimpleDateFormat("MMM dd HH:mm:ss ").format(stamp));
-
-                b.append(info.packageName);
-                b.append(" :: ");
-                b.append(info.domain);
-                b.append(" :: ");
-                b.append(info.path);
-
-                Slog.i(TAG, b.toString());
-            }
-        }
-        // Consume a tar file header block [sequence] and accumulate the relevant metadata
-        FileMetadata readTarHeaders(InputStream instream) throws IOException {
-            byte[] block = new byte[512];
-            FileMetadata info = null;
-
-            boolean gotHeader = readTarHeader(instream, block);
-            if (gotHeader) {
-                try {
-                    // okay, presume we're okay, and extract the various metadata
-                    info = new FileMetadata();
-                    info.size = extractRadix(block, 124, 12, 8);
-                    info.mtime = extractRadix(block, 136, 12, 8);
-                    info.mode = extractRadix(block, 100, 8, 8);
-
-                    info.path = extractString(block, 345, 155); // prefix
-                    String path = extractString(block, 0, 100);
-                    if (path.length() > 0) {
-                        if (info.path.length() > 0) info.path += '/';
-                        info.path += path;
-                    }
-
-                    // tar link indicator field: 1 byte at offset 156 in the header.
-                    int typeChar = block[156];
-                    if (typeChar == 'x') {
-                        // pax extended header, so we need to read that
-                        gotHeader = readPaxExtendedHeader(instream, info);
-                        if (gotHeader) {
-                            // and after a pax extended header comes another real header -- read
-                            // that to find the real file type
-                            gotHeader = readTarHeader(instream, block);
-                        }
-                        if (!gotHeader) throw new IOException("Bad or missing pax header");
-
-                        typeChar = block[156];
-                    }
-
-                    switch (typeChar) {
-                        case '0': info.type = BackupAgent.TYPE_FILE; break;
-                        case '5': {
-                            info.type = BackupAgent.TYPE_DIRECTORY;
-                            if (info.size != 0) {
-                                Slog.w(TAG, "Directory entry with nonzero size in header");
-                                info.size = 0;
-                            }
-                            break;
-                        }
-                        case 0: {
-                            // presume EOF
-                            if (DEBUG) Slog.w(TAG, "Saw type=0 in tar header block, info=" + info);
-                            return null;
-                        }
-                        default: {
-                            Slog.e(TAG, "Unknown tar entity type: " + typeChar);
-                            throw new IOException("Unknown entity type " + typeChar);
-                        }
-                    }
-
-                    // Parse out the path
-                    //
-                    // first: apps/shared/unrecognized
-                    if (FullBackup.SHARED_PREFIX.regionMatches(0,
-                            info.path, 0, FullBackup.SHARED_PREFIX.length())) {
-                        // File in shared storage.  !!! TODO: implement this.
-                        info.path = info.path.substring(FullBackup.SHARED_PREFIX.length());
-                        info.packageName = SHARED_BACKUP_AGENT_PACKAGE;
-                        info.domain = FullBackup.SHARED_STORAGE_TOKEN;
-                        if (DEBUG) Slog.i(TAG, "File in shared storage: " + info.path);
-                    } else if (FullBackup.APPS_PREFIX.regionMatches(0,
-                            info.path, 0, FullBackup.APPS_PREFIX.length())) {
-                        // App content!  Parse out the package name and domain
-
-                        // strip the apps/ prefix
-                        info.path = info.path.substring(FullBackup.APPS_PREFIX.length());
-
-                        // extract the package name
-                        int slash = info.path.indexOf('/');
-                        if (slash < 0) throw new IOException("Illegal semantic path in " + info.path);
-                        info.packageName = info.path.substring(0, slash);
-                        info.path = info.path.substring(slash+1);
-
-                        // if it's a manifest we're done, otherwise parse out the domains
-                        if (!info.path.equals(BACKUP_MANIFEST_FILENAME)) {
-                            slash = info.path.indexOf('/');
-                            if (slash < 0) throw new IOException("Illegal semantic path in non-manifest " + info.path);
-                            info.domain = info.path.substring(0, slash);
-                            info.path = info.path.substring(slash + 1);
-                        }
-                    }
-                } catch (IOException e) {
-                    if (DEBUG) {
-                        Slog.e(TAG, "Parse error in header: " + e.getMessage());
-                        HEXLOG(block);
-                    }
-                    throw e;
-                }
-            }
-            return info;
-        }
-
-        private void HEXLOG(byte[] block) {
-            int offset = 0;
-            int todo = block.length;
-            StringBuilder buf = new StringBuilder(64);
-            while (todo > 0) {
-                buf.append(String.format("%04x   ", offset));
-                int numThisLine = (todo > 16) ? 16 : todo;
-                for (int i = 0; i < numThisLine; i++) {
-                    buf.append(String.format("%02x ", block[offset+i]));
-                }
-                Slog.i("hexdump", buf.toString());
-                buf.setLength(0);
-                todo -= numThisLine;
-                offset += numThisLine;
-            }
-        }
-
-        // Read exactly the given number of bytes into a buffer at the stated offset.
-        // Returns false if EOF is encountered before the requested number of bytes
-        // could be read.
-        int readExactly(InputStream in, byte[] buffer, int offset, int size)
-                throws IOException {
-            if (size <= 0) throw new IllegalArgumentException("size must be > 0");
-
-            int soFar = 0;
-            while (soFar < size) {
-                int nRead = in.read(buffer, offset + soFar, size - soFar);
-                if (nRead <= 0) {
-                    if (MORE_DEBUG) Slog.w(TAG, "- wanted exactly " + size + " but got only " + soFar);
-                    break;
-                }
-                soFar += nRead;
-            }
-            return soFar;
-        }
-
-        boolean readTarHeader(InputStream instream, byte[] block) throws IOException {
-            final int got = readExactly(instream, block, 0, 512);
-            if (got == 0) return false;     // Clean EOF
-            if (got < 512) throw new IOException("Unable to read full block header");
-            mBytes += 512;
-            return true;
-        }
-
-        // overwrites 'info' fields based on the pax extended header
-        boolean readPaxExtendedHeader(InputStream instream, FileMetadata info)
-                throws IOException {
-            // We should never see a pax extended header larger than this
-            if (info.size > 32*1024) {
-                Slog.w(TAG, "Suspiciously large pax header size " + info.size
-                        + " - aborting");
-                throw new IOException("Sanity failure: pax header size " + info.size);
-            }
-
-            // read whole blocks, not just the content size
-            int numBlocks = (int)((info.size + 511) >> 9);
-            byte[] data = new byte[numBlocks * 512];
-            if (readExactly(instream, data, 0, data.length) < data.length) {
-                throw new IOException("Unable to read full pax header");
-            }
-            mBytes += data.length;
-
-            final int contentSize = (int) info.size;
-            int offset = 0;
-            do {
-                // extract the line at 'offset'
-                int eol = offset+1;
-                while (eol < contentSize && data[eol] != ' ') eol++;
-                if (eol >= contentSize) {
-                    // error: we just hit EOD looking for the end of the size field
-                    throw new IOException("Invalid pax data");
-                }
-                // eol points to the space between the count and the key
-                int linelen = (int) extractRadix(data, offset, eol - offset, 10);
-                int key = eol + 1;  // start of key=value
-                eol = offset + linelen - 1; // trailing LF
-                int value;
-                for (value = key+1; data[value] != '=' && value <= eol; value++);
-                if (value > eol) {
-                    throw new IOException("Invalid pax declaration");
-                }
-
-                // pax requires that key/value strings be in UTF-8
-                String keyStr = new String(data, key, value-key, "UTF-8");
-                // -1 to strip the trailing LF
-                String valStr = new String(data, value+1, eol-value-1, "UTF-8");
-
-                if ("path".equals(keyStr)) {
-                    info.path = valStr;
-                } else if ("size".equals(keyStr)) {
-                    info.size = Long.parseLong(valStr);
-                } else {
-                    if (DEBUG) Slog.i(TAG, "Unhandled pax key: " + key);
-                }
-
-                offset += linelen;
-            } while (offset < contentSize);
-
-            return true;
-        }
-
-        long extractRadix(byte[] data, int offset, int maxChars, int radix)
-                throws IOException {
-            long value = 0;
-            final int end = offset + maxChars;
-            for (int i = offset; i < end; i++) {
-                final byte b = data[i];
-                // Numeric fields in tar can terminate with either NUL or SPC
-                if (b == 0 || b == ' ') break;
-                if (b < '0' || b > ('0' + radix - 1)) {
-                    throw new IOException("Invalid number in header: '" + (char)b + "' for radix " + radix);
-                }
-                value = radix * value + (b - '0');
-            }
-            return value;
-        }
-
-        String extractString(byte[] data, int offset, int maxChars) throws IOException {
-            final int end = offset + maxChars;
-            int eos = offset;
-            // tar string fields terminate early with a NUL
-            while (eos < end && data[eos] != 0) eos++;
-            return new String(data, offset, eos-offset, "US-ASCII");
-        }
-
-        void sendStartRestore() {
-            if (mObserver != null) {
-                try {
-                    mObserver.onStartRestore();
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "full restore observer went away: startRestore");
-                    mObserver = null;
-                }
-            }
-        }
-
-        void sendOnRestorePackage(String name) {
-            if (mObserver != null) {
-                try {
-                    // TODO: use a more user-friendly name string
-                    mObserver.onRestorePackage(name);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "full restore observer went away: restorePackage");
-                    mObserver = null;
-                }
-            }
-        }
-
-        void sendEndRestore() {
-            if (mObserver != null) {
-                try {
-                    mObserver.onEndRestore();
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "full restore observer went away: endRestore");
-                    mObserver = null;
-                }
-            }
-        }
-    }
-
-    // ----- Restore handling -----
-
-    private boolean signaturesMatch(Signature[] storedSigs, PackageInfo target) {
-        // If the target resides on the system partition, we allow it to restore
-        // data from the like-named package in a restore set even if the signatures
-        // do not match.  (Unlike general applications, those flashed to the system
-        // partition will be signed with the device's platform certificate, so on
-        // different phones the same system app will have different signatures.)
-        if ((target.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-            if (DEBUG) Slog.v(TAG, "System app " + target.packageName + " - skipping sig check");
-            return true;
-        }
-
-        // Allow unsigned apps, but not signed on one device and unsigned on the other
-        // !!! TODO: is this the right policy?
-        Signature[] deviceSigs = target.signatures;
-        if (MORE_DEBUG) Slog.v(TAG, "signaturesMatch(): stored=" + storedSigs
-                + " device=" + deviceSigs);
-        if ((storedSigs == null || storedSigs.length == 0)
-                && (deviceSigs == null || deviceSigs.length == 0)) {
-            return true;
-        }
-        if (storedSigs == null || deviceSigs == null) {
-            return false;
-        }
-
-        // !!! TODO: this demands that every stored signature match one
-        // that is present on device, and does not demand the converse.
-        // Is this this right policy?
-        int nStored = storedSigs.length;
-        int nDevice = deviceSigs.length;
-
-        for (int i=0; i < nStored; i++) {
-            boolean match = false;
-            for (int j=0; j < nDevice; j++) {
-                if (storedSigs[i].equals(deviceSigs[j])) {
-                    match = true;
-                    break;
-                }
-            }
-            if (!match) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    enum RestoreState {
-        INITIAL,
-        DOWNLOAD_DATA,
-        PM_METADATA,
-        RUNNING_QUEUE,
-        FINAL
-    }
-
-    class PerformRestoreTask implements BackupRestoreTask {
-        private IBackupTransport mTransport;
-        private IRestoreObserver mObserver;
-        private long mToken;
-        private PackageInfo mTargetPackage;
-        private File mStateDir;
-        private int mPmToken;
-        private boolean mNeedFullBackup;
-        private HashSet<String> mFilterSet;
-        private long mStartRealtime;
-        private PackageManagerBackupAgent mPmAgent;
-        private List<PackageInfo> mAgentPackages;
-        private ArrayList<PackageInfo> mRestorePackages;
-        private RestoreState mCurrentState;
-        private int mCount;
-        private boolean mFinished;
-        private int mStatus;
-        private File mBackupDataName;
-        private File mNewStateName;
-        private File mSavedStateName;
-        private ParcelFileDescriptor mBackupData;
-        private ParcelFileDescriptor mNewState;
-        private PackageInfo mCurrentPackage;
-
-
-        class RestoreRequest {
-            public PackageInfo app;
-            public int storedAppVersion;
-
-            RestoreRequest(PackageInfo _app, int _version) {
-                app = _app;
-                storedAppVersion = _version;
-            }
-        }
-
-        PerformRestoreTask(IBackupTransport transport, String dirName, IRestoreObserver observer,
-                long restoreSetToken, PackageInfo targetPackage, int pmToken,
-                boolean needFullBackup, String[] filterSet) {
-            mCurrentState = RestoreState.INITIAL;
-            mFinished = false;
-            mPmAgent = null;
-
-            mTransport = transport;
-            mObserver = observer;
-            mToken = restoreSetToken;
-            mTargetPackage = targetPackage;
-            mPmToken = pmToken;
-            mNeedFullBackup = needFullBackup;
-
-            if (filterSet != null) {
-                mFilterSet = new HashSet<String>();
-                for (String pkg : filterSet) {
-                    mFilterSet.add(pkg);
-                }
-            } else {
-                mFilterSet = null;
-            }
-
-            mStateDir = new File(mBaseStateDir, dirName);
-        }
-
-        // Execute one tick of whatever state machine the task implements
-        @Override
-        public void execute() {
-            if (MORE_DEBUG) Slog.v(TAG, "*** Executing restore step: " + mCurrentState);
-            switch (mCurrentState) {
-                case INITIAL:
-                    beginRestore();
-                    break;
-
-                case DOWNLOAD_DATA:
-                    downloadRestoreData();
-                    break;
-
-                case PM_METADATA:
-                    restorePmMetadata();
-                    break;
-
-                case RUNNING_QUEUE:
-                    restoreNextAgent();
-                    break;
-
-                case FINAL:
-                    if (!mFinished) finalizeRestore();
-                    else {
-                        Slog.e(TAG, "Duplicate finish");
-                    }
-                    mFinished = true;
-                    break;
-            }
-        }
-
-        // Initialize and set up for the PM metadata restore, which comes first
-        void beginRestore() {
-            // Don't account time doing the restore as inactivity of the app
-            // that has opened a restore session.
-            mBackupHandler.removeMessages(MSG_RESTORE_TIMEOUT);
-
-            // Assume error until we successfully init everything
-            mStatus = BackupConstants.TRANSPORT_ERROR;
-
-            try {
-                // TODO: Log this before getAvailableRestoreSets, somehow
-                EventLog.writeEvent(EventLogTags.RESTORE_START, mTransport.transportDirName(), mToken);
-
-                // Get the list of all packages which have backup enabled.
-                // (Include the Package Manager metadata pseudo-package first.)
-                mRestorePackages = new ArrayList<PackageInfo>();
-                PackageInfo omPackage = new PackageInfo();
-                omPackage.packageName = PACKAGE_MANAGER_SENTINEL;
-                mRestorePackages.add(omPackage);
-
-                mAgentPackages = allAgentPackages();
-                if (mTargetPackage == null) {
-                    // if there's a filter set, strip out anything that isn't
-                    // present before proceeding
-                    if (mFilterSet != null) {
-                        for (int i = mAgentPackages.size() - 1; i >= 0; i--) {
-                            final PackageInfo pkg = mAgentPackages.get(i);
-                            if (! mFilterSet.contains(pkg.packageName)) {
-                                mAgentPackages.remove(i);
-                            }
-                        }
-                        if (MORE_DEBUG) {
-                            Slog.i(TAG, "Post-filter package set for restore:");
-                            for (PackageInfo p : mAgentPackages) {
-                                Slog.i(TAG, "    " + p);
-                            }
-                        }
-                    }
-                    mRestorePackages.addAll(mAgentPackages);
-                } else {
-                    // Just one package to attempt restore of
-                    mRestorePackages.add(mTargetPackage);
-                }
-
-                // let the observer know that we're running
-                if (mObserver != null) {
-                    try {
-                        // !!! TODO: get an actual count from the transport after
-                        // its startRestore() runs?
-                        mObserver.restoreStarting(mRestorePackages.size());
-                    } catch (RemoteException e) {
-                        Slog.d(TAG, "Restore observer died at restoreStarting");
-                        mObserver = null;
-                    }
-                }
-            } catch (RemoteException e) {
-                // Something has gone catastrophically wrong with the transport
-                Slog.e(TAG, "Error communicating with transport for restore");
-                executeNextState(RestoreState.FINAL);
-                return;
-            }
-
-            mStatus = BackupConstants.TRANSPORT_OK;
-            executeNextState(RestoreState.DOWNLOAD_DATA);
-        }
-
-        void downloadRestoreData() {
-            // Note that the download phase can be very time consuming, but we're executing
-            // it inline here on the looper.  This is "okay" because it is not calling out to
-            // third party code; the transport is "trusted," and so we assume it is being a
-            // good citizen and timing out etc when appropriate.
-            //
-            // TODO: when appropriate, move the download off the looper and rearrange the
-            //       error handling around that.
-            try {
-                mStatus = mTransport.startRestore(mToken,
-                        mRestorePackages.toArray(new PackageInfo[0]));
-                if (mStatus != BackupConstants.TRANSPORT_OK) {
-                    Slog.e(TAG, "Error starting restore operation");
-                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                }
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Error communicating with transport for restore");
-                EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                mStatus = BackupConstants.TRANSPORT_ERROR;
-                executeNextState(RestoreState.FINAL);
-                return;
-            }
-
-            // Successful download of the data to be parceled out to the apps, so off we go.
-            executeNextState(RestoreState.PM_METADATA);
-        }
-
-        void restorePmMetadata() {
-            try {
-                String packageName = mTransport.nextRestorePackage();
-                if (packageName == null) {
-                    Slog.e(TAG, "Error getting first restore package");
-                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                    mStatus = BackupConstants.TRANSPORT_ERROR;
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                } else if (packageName.equals("")) {
-                    Slog.i(TAG, "No restore data available");
-                    int millis = (int) (SystemClock.elapsedRealtime() - mStartRealtime);
-                    EventLog.writeEvent(EventLogTags.RESTORE_SUCCESS, 0, millis);
-                    mStatus = BackupConstants.TRANSPORT_OK;
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                } else if (!packageName.equals(PACKAGE_MANAGER_SENTINEL)) {
-                    Slog.e(TAG, "Expected restore data for \"" + PACKAGE_MANAGER_SENTINEL
-                            + "\", found only \"" + packageName + "\"");
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, PACKAGE_MANAGER_SENTINEL,
-                            "Package manager data missing");
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                }
-
-                // Pull the Package Manager metadata from the restore set first
-                PackageInfo omPackage = new PackageInfo();
-                omPackage.packageName = PACKAGE_MANAGER_SENTINEL;
-                mPmAgent = new PackageManagerBackupAgent(
-                        mPackageManager, mAgentPackages);
-                initiateOneRestore(omPackage, 0, IBackupAgent.Stub.asInterface(mPmAgent.onBind()),
-                        mNeedFullBackup);
-                // The PM agent called operationComplete() already, because our invocation
-                // of it is process-local and therefore synchronous.  That means that a
-                // RUNNING_QUEUE message is already enqueued.  Only if we're unable to
-                // proceed with running the queue do we remove that pending message and
-                // jump straight to the FINAL state.
-
-                // Verify that the backup set includes metadata.  If not, we can't do
-                // signature/version verification etc, so we simply do not proceed with
-                // the restore operation.
-                if (!mPmAgent.hasMetadata()) {
-                    Slog.e(TAG, "No restore metadata available, so not restoring settings");
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, PACKAGE_MANAGER_SENTINEL,
-                    "Package manager restore metadata missing");
-                    mStatus = BackupConstants.TRANSPORT_ERROR;
-                    mBackupHandler.removeMessages(MSG_BACKUP_RESTORE_STEP, this);
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                }
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Error communicating with transport for restore");
-                EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                mStatus = BackupConstants.TRANSPORT_ERROR;
-                mBackupHandler.removeMessages(MSG_BACKUP_RESTORE_STEP, this);
-                executeNextState(RestoreState.FINAL);
-                return;
-            }
-
-            // Metadata is intact, so we can now run the restore queue.  If we get here,
-            // we have already enqueued the necessary next-step message on the looper.
-        }
-
-        void restoreNextAgent() {
-            try {
-                String packageName = mTransport.nextRestorePackage();
-
-                if (packageName == null) {
-                    Slog.e(TAG, "Error getting next restore package");
-                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                } else if (packageName.equals("")) {
-                    if (DEBUG) Slog.v(TAG, "No next package, finishing restore");
-                    int millis = (int) (SystemClock.elapsedRealtime() - mStartRealtime);
-                    EventLog.writeEvent(EventLogTags.RESTORE_SUCCESS, mCount, millis);
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                }
-
-                if (mObserver != null) {
-                    try {
-                        mObserver.onUpdate(mCount, packageName);
-                    } catch (RemoteException e) {
-                        Slog.d(TAG, "Restore observer died in onUpdate");
-                        mObserver = null;
-                    }
-                }
-
-                Metadata metaInfo = mPmAgent.getRestoredMetadata(packageName);
-                if (metaInfo == null) {
-                    Slog.e(TAG, "Missing metadata for " + packageName);
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
-                            "Package metadata missing");
-                    executeNextState(RestoreState.RUNNING_QUEUE);
-                    return;
-                }
-
-                PackageInfo packageInfo;
-                try {
-                    int flags = PackageManager.GET_SIGNATURES;
-                    packageInfo = mPackageManager.getPackageInfo(packageName, flags);
-                } catch (NameNotFoundException e) {
-                    Slog.e(TAG, "Invalid package restoring data", e);
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
-                            "Package missing on device");
-                    executeNextState(RestoreState.RUNNING_QUEUE);
-                    return;
-                }
-
-                if (packageInfo.applicationInfo.backupAgentName == null
-                        || "".equals(packageInfo.applicationInfo.backupAgentName)) {
-                    if (DEBUG) {
-                        Slog.i(TAG, "Data exists for package " + packageName
-                                + " but app has no agent; skipping");
-                    }
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
-                            "Package has no agent");
-                    executeNextState(RestoreState.RUNNING_QUEUE);
-                    return;
-                }
-
-                if (metaInfo.versionCode > packageInfo.versionCode) {
-                    // Data is from a "newer" version of the app than we have currently
-                    // installed.  If the app has not declared that it is prepared to
-                    // handle this case, we do not attempt the restore.
-                    if ((packageInfo.applicationInfo.flags
-                            & ApplicationInfo.FLAG_RESTORE_ANY_VERSION) == 0) {
-                        String message = "Version " + metaInfo.versionCode
-                        + " > installed version " + packageInfo.versionCode;
-                        Slog.w(TAG, "Package " + packageName + ": " + message);
-                        EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE,
-                                packageName, message);
-                        executeNextState(RestoreState.RUNNING_QUEUE);
-                        return;
-                    } else {
-                        if (DEBUG) Slog.v(TAG, "Version " + metaInfo.versionCode
-                                + " > installed " + packageInfo.versionCode
-                                + " but restoreAnyVersion");
-                    }
-                }
-
-                if (!signaturesMatch(metaInfo.signatures, packageInfo)) {
-                    Slog.w(TAG, "Signature mismatch restoring " + packageName);
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
-                            "Signature mismatch");
-                    executeNextState(RestoreState.RUNNING_QUEUE);
-                    return;
-                }
-
-                if (DEBUG) Slog.v(TAG, "Package " + packageName
-                        + " restore version [" + metaInfo.versionCode
-                        + "] is compatible with installed version ["
-                        + packageInfo.versionCode + "]");
-
-                // Then set up and bind the agent
-                IBackupAgent agent = bindToAgentSynchronous(
-                        packageInfo.applicationInfo,
-                        IApplicationThread.BACKUP_MODE_INCREMENTAL);
-                if (agent == null) {
-                    Slog.w(TAG, "Can't find backup agent for " + packageName);
-                    EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName,
-                            "Restore agent missing");
-                    executeNextState(RestoreState.RUNNING_QUEUE);
-                    return;
-                }
-
-                // And then finally start the restore on this agent
-                try {
-                    initiateOneRestore(packageInfo, metaInfo.versionCode, agent, mNeedFullBackup);
-                    ++mCount;
-                } catch (Exception e) {
-                    Slog.e(TAG, "Error when attempting restore: " + e.toString());
-                    agentErrorCleanup();
-                    executeNextState(RestoreState.RUNNING_QUEUE);
-                }
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Unable to fetch restore data from transport");
-                mStatus = BackupConstants.TRANSPORT_ERROR;
-                executeNextState(RestoreState.FINAL);
-            }
-        }
-
-        void finalizeRestore() {
-            if (MORE_DEBUG) Slog.d(TAG, "finishing restore mObserver=" + mObserver);
-
-            try {
-                mTransport.finishRestore();
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Error finishing restore", e);
-            }
-
-            if (mObserver != null) {
-                try {
-                    mObserver.restoreFinished(mStatus);
-                } catch (RemoteException e) {
-                    Slog.d(TAG, "Restore observer died at restoreFinished");
-                }
-            }
-
-            // If this was a restoreAll operation, record that this was our
-            // ancestral dataset, as well as the set of apps that are possibly
-            // restoreable from the dataset
-            if (mTargetPackage == null && mPmAgent != null) {
-                mAncestralPackages = mPmAgent.getRestoredPackages();
-                mAncestralToken = mToken;
-                writeRestoreTokens();
-            }
-
-            // We must under all circumstances tell the Package Manager to
-            // proceed with install notifications if it's waiting for us.
-            if (mPmToken > 0) {
-                if (MORE_DEBUG) Slog.v(TAG, "finishing PM token " + mPmToken);
-                try {
-                    mPackageManagerBinder.finishPackageInstall(mPmToken);
-                } catch (RemoteException e) { /* can't happen */ }
-            }
-
-            // Furthermore we need to reset the session timeout clock
-            mBackupHandler.removeMessages(MSG_RESTORE_TIMEOUT);
-            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_TIMEOUT,
-                    TIMEOUT_RESTORE_INTERVAL);
-
-            // done; we can finally release the wakelock
-            Slog.i(TAG, "Restore complete.");
-            mWakelock.release();
-        }
-
-        // Call asynchronously into the app, passing it the restore data.  The next step
-        // after this is always a callback, either operationComplete() or handleTimeout().
-        void initiateOneRestore(PackageInfo app, int appVersionCode, IBackupAgent agent,
-                boolean needFullBackup) {
-            mCurrentPackage = app;
-            final String packageName = app.packageName;
-
-            if (DEBUG) Slog.d(TAG, "initiateOneRestore packageName=" + packageName);
-
-            // !!! TODO: get the dirs from the transport
-            mBackupDataName = new File(mDataDir, packageName + ".restore");
-            mNewStateName = new File(mStateDir, packageName + ".new");
-            mSavedStateName = new File(mStateDir, packageName);
-
-            final int token = generateToken();
-            try {
-                // Run the transport's restore pass
-                mBackupData = ParcelFileDescriptor.open(mBackupDataName,
-                            ParcelFileDescriptor.MODE_READ_WRITE |
-                            ParcelFileDescriptor.MODE_CREATE |
-                            ParcelFileDescriptor.MODE_TRUNCATE);
-
-                if (!SELinux.restorecon(mBackupDataName)) {
-                    Slog.e(TAG, "SElinux restorecon failed for " + mBackupDataName);
-                }
-
-                if (mTransport.getRestoreData(mBackupData) != BackupConstants.TRANSPORT_OK) {
-                    // Transport-level failure, so we wind everything up and
-                    // terminate the restore operation.
-                    Slog.e(TAG, "Error getting restore data for " + packageName);
-                    EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
-                    mBackupData.close();
-                    mBackupDataName.delete();
-                    executeNextState(RestoreState.FINAL);
-                    return;
-                }
-
-                // Okay, we have the data.  Now have the agent do the restore.
-                mBackupData.close();
-                mBackupData = ParcelFileDescriptor.open(mBackupDataName,
-                            ParcelFileDescriptor.MODE_READ_ONLY);
-
-                mNewState = ParcelFileDescriptor.open(mNewStateName,
-                            ParcelFileDescriptor.MODE_READ_WRITE |
-                            ParcelFileDescriptor.MODE_CREATE |
-                            ParcelFileDescriptor.MODE_TRUNCATE);
-
-                // Kick off the restore, checking for hung agents
-                prepareOperationTimeout(token, TIMEOUT_RESTORE_INTERVAL, this);
-                agent.doRestore(mBackupData, appVersionCode, mNewState, token, mBackupManagerBinder);
-            } catch (Exception e) {
-                Slog.e(TAG, "Unable to call app for restore: " + packageName, e);
-                EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, packageName, e.toString());
-                agentErrorCleanup();    // clears any pending timeout messages as well
-
-                // After a restore failure we go back to running the queue.  If there
-                // are no more packages to be restored that will be handled by the
-                // next step.
-                executeNextState(RestoreState.RUNNING_QUEUE);
-            }
-        }
-
-        void agentErrorCleanup() {
-            // If the agent fails restore, it might have put the app's data
-            // into an incoherent state.  For consistency we wipe its data
-            // again in this case before continuing with normal teardown
-            clearApplicationDataSynchronous(mCurrentPackage.packageName);
-            agentCleanup();
-        }
-
-        void agentCleanup() {
-            mBackupDataName.delete();
-            try { if (mBackupData != null) mBackupData.close(); } catch (IOException e) {}
-            try { if (mNewState != null) mNewState.close(); } catch (IOException e) {}
-            mBackupData = mNewState = null;
-
-            // if everything went okay, remember the recorded state now
-            //
-            // !!! TODO: the restored data should be migrated on the server
-            // side into the current dataset.  In that case the new state file
-            // we just created would reflect the data already extant in the
-            // backend, so there'd be nothing more to do.  Until that happens,
-            // however, we need to make sure that we record the data to the
-            // current backend dataset.  (Yes, this means shipping the data over
-            // the wire in both directions.  That's bad, but consistency comes
-            // first, then efficiency.)  Once we introduce server-side data
-            // migration to the newly-restored device's dataset, we will change
-            // the following from a discard of the newly-written state to the
-            // "correct" operation of renaming into the canonical state blob.
-            mNewStateName.delete();                      // TODO: remove; see above comment
-            //mNewStateName.renameTo(mSavedStateName);   // TODO: replace with this
-
-            // If this wasn't the PM pseudopackage, tear down the agent side
-            if (mCurrentPackage.applicationInfo != null) {
-                // unbind and tidy up even on timeout or failure
-                try {
-                    mActivityManager.unbindBackupAgent(mCurrentPackage.applicationInfo);
-
-                    // The agent was probably running with a stub Application object,
-                    // which isn't a valid run mode for the main app logic.  Shut
-                    // down the app so that next time it's launched, it gets the
-                    // usual full initialization.  Note that this is only done for
-                    // full-system restores: when a single app has requested a restore,
-                    // it is explicitly not killed following that operation.
-                    if (mTargetPackage == null && (mCurrentPackage.applicationInfo.flags
-                            & ApplicationInfo.FLAG_KILL_AFTER_RESTORE) != 0) {
-                        if (DEBUG) Slog.d(TAG, "Restore complete, killing host process of "
-                                + mCurrentPackage.applicationInfo.processName);
-                        mActivityManager.killApplicationProcess(
-                                mCurrentPackage.applicationInfo.processName,
-                                mCurrentPackage.applicationInfo.uid);
-                    }
-                } catch (RemoteException e) {
-                    // can't happen; we run in the same process as the activity manager
-                }
-            }
-
-            // The caller is responsible for reestablishing the state machine; our
-            // responsibility here is to clear the decks for whatever comes next.
-            mBackupHandler.removeMessages(MSG_TIMEOUT, this);
-            synchronized (mCurrentOpLock) {
-                mCurrentOperations.clear();
-            }
-        }
-
-        // A call to agent.doRestore() has been positively acknowledged as complete
-        @Override
-        public void operationComplete() {
-            int size = (int) mBackupDataName.length();
-            EventLog.writeEvent(EventLogTags.RESTORE_PACKAGE, mCurrentPackage.packageName, size);
-            // Just go back to running the restore queue
-            agentCleanup();
-
-            executeNextState(RestoreState.RUNNING_QUEUE);
-        }
-
-        // A call to agent.doRestore() has timed out
-        @Override
-        public void handleTimeout() {
-            Slog.e(TAG, "Timeout restoring application " + mCurrentPackage.packageName);
-            EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE,
-                    mCurrentPackage.packageName, "restore timeout");
-            // Handle like an agent that threw on invocation: wipe it and go on to the next
-            agentErrorCleanup();
-            executeNextState(RestoreState.RUNNING_QUEUE);
-        }
-
-        void executeNextState(RestoreState nextState) {
-            if (MORE_DEBUG) Slog.i(TAG, " => executing next step on "
-                    + this + " nextState=" + nextState);
-            mCurrentState = nextState;
-            Message msg = mBackupHandler.obtainMessage(MSG_BACKUP_RESTORE_STEP, this);
-            mBackupHandler.sendMessage(msg);
-        }
-    }
-
-    class PerformClearTask implements Runnable {
-        IBackupTransport mTransport;
-        PackageInfo mPackage;
-
-        PerformClearTask(IBackupTransport transport, PackageInfo packageInfo) {
-            mTransport = transport;
-            mPackage = packageInfo;
-        }
-
-        public void run() {
-            try {
-                // Clear the on-device backup state to ensure a full backup next time
-                File stateDir = new File(mBaseStateDir, mTransport.transportDirName());
-                File stateFile = new File(stateDir, mPackage.packageName);
-                stateFile.delete();
-
-                // Tell the transport to remove all the persistent storage for the app
-                // TODO - need to handle failures
-                mTransport.clearBackupData(mPackage);
-            } catch (RemoteException e) {
-                // can't happen; the transport is local
-            } catch (Exception e) {
-                Slog.e(TAG, "Transport threw attempting to clear data for " + mPackage);
-            } finally {
-                try {
-                    // TODO - need to handle failures
-                    mTransport.finishBackup();
-                } catch (RemoteException e) {
-                    // can't happen; the transport is local
-                }
-
-                // Last but not least, release the cpu
-                mWakelock.release();
-            }
-        }
-    }
-
-    class PerformInitializeTask implements Runnable {
-        HashSet<String> mQueue;
-
-        PerformInitializeTask(HashSet<String> transportNames) {
-            mQueue = transportNames;
-        }
-
-        public void run() {
-            try {
-                for (String transportName : mQueue) {
-                    IBackupTransport transport = getTransport(transportName);
-                    if (transport == null) {
-                        Slog.e(TAG, "Requested init for " + transportName + " but not found");
-                        continue;
-                    }
-
-                    Slog.i(TAG, "Initializing (wiping) backup transport storage: " + transportName);
-                    EventLog.writeEvent(EventLogTags.BACKUP_START, transport.transportDirName());
-                    long startRealtime = SystemClock.elapsedRealtime();
-                    int status = transport.initializeDevice();
-
-                    if (status == BackupConstants.TRANSPORT_OK) {
-                        status = transport.finishBackup();
-                    }
-
-                    // Okay, the wipe really happened.  Clean up our local bookkeeping.
-                    if (status == BackupConstants.TRANSPORT_OK) {
-                        Slog.i(TAG, "Device init successful");
-                        int millis = (int) (SystemClock.elapsedRealtime() - startRealtime);
-                        EventLog.writeEvent(EventLogTags.BACKUP_INITIALIZE);
-                        resetBackupState(new File(mBaseStateDir, transport.transportDirName()));
-                        EventLog.writeEvent(EventLogTags.BACKUP_SUCCESS, 0, millis);
-                        synchronized (mQueueLock) {
-                            recordInitPendingLocked(false, transportName);
-                        }
-                    } else {
-                        // If this didn't work, requeue this one and try again
-                        // after a suitable interval
-                        Slog.e(TAG, "Transport error in initializeDevice()");
-                        EventLog.writeEvent(EventLogTags.BACKUP_TRANSPORT_FAILURE, "(initialize)");
-                        synchronized (mQueueLock) {
-                            recordInitPendingLocked(true, transportName);
-                        }
-                        // do this via another alarm to make sure of the wakelock states
-                        long delay = transport.requestBackupTime();
-                        if (DEBUG) Slog.w(TAG, "init failed on "
-                                + transportName + " resched in " + delay);
-                        mAlarmManager.set(AlarmManager.RTC_WAKEUP,
-                                System.currentTimeMillis() + delay, mRunInitIntent);
-                    }
-                }
-            } catch (RemoteException e) {
-                // can't happen; the transports are local
-            } catch (Exception e) {
-                Slog.e(TAG, "Unexpected error performing init", e);
-            } finally {
-                // Done; release the wakelock
-                mWakelock.release();
-            }
-        }
-    }
-
-    private void dataChangedImpl(String packageName) {
-        HashSet<String> targets = dataChangedTargets(packageName);
-        dataChangedImpl(packageName, targets);
-    }
-
-    private void dataChangedImpl(String packageName, HashSet<String> targets) {
-        // Record that we need a backup pass for the caller.  Since multiple callers
-        // may share a uid, we need to note all candidates within that uid and schedule
-        // a backup pass for each of them.
-        EventLog.writeEvent(EventLogTags.BACKUP_DATA_CHANGED, packageName);
-
-        if (targets == null) {
-            Slog.w(TAG, "dataChanged but no participant pkg='" + packageName + "'"
-                   + " uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mQueueLock) {
-            // Note that this client has made data changes that need to be backed up
-            if (targets.contains(packageName)) {
-                // Add the caller to the set of pending backups.  If there is
-                // one already there, then overwrite it, but no harm done.
-                BackupRequest req = new BackupRequest(packageName);
-                if (mPendingBackups.put(packageName, req) == null) {
-                    if (DEBUG) Slog.d(TAG, "Now staging backup of " + packageName);
-
-                    // Journal this request in case of crash.  The put()
-                    // operation returned null when this package was not already
-                    // in the set; we want to avoid touching the disk redundantly.
-                    writeToJournalLocked(packageName);
-
-                    if (MORE_DEBUG) {
-                        int numKeys = mPendingBackups.size();
-                        Slog.d(TAG, "Now awaiting backup for " + numKeys + " participants:");
-                        for (BackupRequest b : mPendingBackups.values()) {
-                            Slog.d(TAG, "    + " + b);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    // Note: packageName is currently unused, but may be in the future
-    private HashSet<String> dataChangedTargets(String packageName) {
-        // If the caller does not hold the BACKUP permission, it can only request a
-        // backup of its own data.
-        if ((mContext.checkPermission(android.Manifest.permission.BACKUP, Binder.getCallingPid(),
-                Binder.getCallingUid())) == PackageManager.PERMISSION_DENIED) {
-            synchronized (mBackupParticipants) {
-                return mBackupParticipants.get(Binder.getCallingUid());
-            }
-        }
-
-        // a caller with full permission can ask to back up any participating app
-        // !!! TODO: allow backup of ANY app?
-        HashSet<String> targets = new HashSet<String>();
-        synchronized (mBackupParticipants) {
-            int N = mBackupParticipants.size();
-            for (int i = 0; i < N; i++) {
-                HashSet<String> s = mBackupParticipants.valueAt(i);
-                if (s != null) {
-                    targets.addAll(s);
-                }
-            }
-        }
-        return targets;
-    }
-
-    private void writeToJournalLocked(String str) {
-        RandomAccessFile out = null;
-        try {
-            if (mJournal == null) mJournal = File.createTempFile("journal", null, mJournalDir);
-            out = new RandomAccessFile(mJournal, "rws");
-            out.seek(out.length());
-            out.writeUTF(str);
-        } catch (IOException e) {
-            Slog.e(TAG, "Can't write " + str + " to backup journal", e);
-            mJournal = null;
-        } finally {
-            try { if (out != null) out.close(); } catch (IOException e) {}
-        }
-    }
-
-    // ----- IBackupManager binder interface -----
-
-    public void dataChanged(final String packageName) {
-        final int callingUserHandle = UserHandle.getCallingUserId();
-        if (callingUserHandle != UserHandle.USER_OWNER) {
-            // App is running under a non-owner user profile.  For now, we do not back
-            // up data from secondary user profiles.
-            // TODO: backups for all user profiles.
-            if (MORE_DEBUG) {
-                Slog.v(TAG, "dataChanged(" + packageName + ") ignored because it's user "
-                        + callingUserHandle);
-            }
-            return;
-        }
-
-        final HashSet<String> targets = dataChangedTargets(packageName);
-        if (targets == null) {
-            Slog.w(TAG, "dataChanged but no participant pkg='" + packageName + "'"
-                   + " uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        mBackupHandler.post(new Runnable() {
-                public void run() {
-                    dataChangedImpl(packageName, targets);
-                }
-            });
-    }
-
-    // Clear the given package's backup data from the current transport
-    public void clearBackupData(String transportName, String packageName) {
-        if (DEBUG) Slog.v(TAG, "clearBackupData() of " + packageName + " on " + transportName);
-        PackageInfo info;
-        try {
-            info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
-        } catch (NameNotFoundException e) {
-            Slog.d(TAG, "No such package '" + packageName + "' - not clearing backup data");
-            return;
-        }
-
-        // If the caller does not hold the BACKUP permission, it can only request a
-        // wipe of its own backed-up data.
-        HashSet<String> apps;
-        if ((mContext.checkPermission(android.Manifest.permission.BACKUP, Binder.getCallingPid(),
-                Binder.getCallingUid())) == PackageManager.PERMISSION_DENIED) {
-            apps = mBackupParticipants.get(Binder.getCallingUid());
-        } else {
-            // a caller with full permission can ask to back up any participating app
-            // !!! TODO: allow data-clear of ANY app?
-            if (DEBUG) Slog.v(TAG, "Privileged caller, allowing clear of other apps");
-            apps = new HashSet<String>();
-            int N = mBackupParticipants.size();
-            for (int i = 0; i < N; i++) {
-                HashSet<String> s = mBackupParticipants.valueAt(i);
-                if (s != null) {
-                    apps.addAll(s);
-                }
-            }
-        }
-
-        // Is the given app an available participant?
-        if (apps.contains(packageName)) {
-            // found it; fire off the clear request
-            if (DEBUG) Slog.v(TAG, "Found the app - running clear process");
-            mBackupHandler.removeMessages(MSG_RETRY_CLEAR);
-            synchronized (mQueueLock) {
-                final IBackupTransport transport = getTransport(transportName);
-                if (transport == null) {
-                    // transport is currently unavailable -- make sure to retry
-                    Message msg = mBackupHandler.obtainMessage(MSG_RETRY_CLEAR,
-                            new ClearRetryParams(transportName, packageName));
-                    mBackupHandler.sendMessageDelayed(msg, TRANSPORT_RETRY_INTERVAL);
-                    return;
-                }
-                long oldId = Binder.clearCallingIdentity();
-                mWakelock.acquire();
-                Message msg = mBackupHandler.obtainMessage(MSG_RUN_CLEAR,
-                        new ClearParams(transport, info));
-                mBackupHandler.sendMessage(msg);
-                Binder.restoreCallingIdentity(oldId);
-            }
-        }
-    }
-
-    // Run a backup pass immediately for any applications that have declared
-    // that they have pending updates.
-    public void backupNow() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "backupNow");
-
-        if (DEBUG) Slog.v(TAG, "Scheduling immediate backup pass");
-        synchronized (mQueueLock) {
-            // Because the alarms we are using can jitter, and we want an *immediate*
-            // backup pass to happen, we restart the timer beginning with "next time,"
-            // then manually fire the backup trigger intent ourselves.
-            startBackupAlarmsLocked(BACKUP_INTERVAL);
-            try {
-                mRunBackupIntent.send();
-            } catch (PendingIntent.CanceledException e) {
-                // should never happen
-                Slog.e(TAG, "run-backup intent cancelled!");
-            }
-        }
-    }
-
-    boolean deviceIsProvisioned() {
-        final ContentResolver resolver = mContext.getContentResolver();
-        return (Settings.Global.getInt(resolver, Settings.Global.DEVICE_PROVISIONED, 0) != 0);
-    }
-
-    // Run a *full* backup pass for the given package, writing the resulting data stream
-    // to the supplied file descriptor.  This method is synchronous and does not return
-    // to the caller until the backup has been completed.
-    public void fullBackup(ParcelFileDescriptor fd, boolean includeApks,
-            boolean includeObbs, boolean includeShared,
-            boolean doAllApps, boolean includeSystem, String[] pkgList) {
-        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullBackup");
-
-        final int callingUserHandle = UserHandle.getCallingUserId();
-        if (callingUserHandle != UserHandle.USER_OWNER) {
-            throw new IllegalStateException("Backup supported only for the device owner");
-        }
-
-        // Validate
-        if (!doAllApps) {
-            if (!includeShared) {
-                // If we're backing up shared data (sdcard or equivalent), then we can run
-                // without any supplied app names.  Otherwise, we'd be doing no work, so
-                // report the error.
-                if (pkgList == null || pkgList.length == 0) {
-                    throw new IllegalArgumentException(
-                            "Backup requested but neither shared nor any apps named");
-                }
-            }
-        }
-
-        long oldId = Binder.clearCallingIdentity();
-        try {
-            // Doesn't make sense to do a full backup prior to setup
-            if (!deviceIsProvisioned()) {
-                Slog.i(TAG, "Full backup not supported before setup");
-                return;
-            }
-
-            if (DEBUG) Slog.v(TAG, "Requesting full backup: apks=" + includeApks
-                    + " obb=" + includeObbs + " shared=" + includeShared + " all=" + doAllApps
-                    + " pkgs=" + pkgList);
-            Slog.i(TAG, "Beginning full backup...");
-
-            FullBackupParams params = new FullBackupParams(fd, includeApks, includeObbs,
-                    includeShared, doAllApps, includeSystem, pkgList);
-            final int token = generateToken();
-            synchronized (mFullConfirmations) {
-                mFullConfirmations.put(token, params);
-            }
-
-            // start up the confirmation UI
-            if (DEBUG) Slog.d(TAG, "Starting backup confirmation UI, token=" + token);
-            if (!startConfirmationUi(token, FullBackup.FULL_BACKUP_INTENT_ACTION)) {
-                Slog.e(TAG, "Unable to launch full backup confirmation");
-                mFullConfirmations.delete(token);
-                return;
-            }
-
-            // make sure the screen is lit for the user interaction
-            mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
-
-            // start the confirmation countdown
-            startConfirmationTimeout(token, params);
-
-            // wait for the backup to be performed
-            if (DEBUG) Slog.d(TAG, "Waiting for full backup completion...");
-            waitForCompletion(params);
-        } finally {
-            try {
-                fd.close();
-            } catch (IOException e) {
-                // just eat it
-            }
-            Binder.restoreCallingIdentity(oldId);
-            Slog.d(TAG, "Full backup processing complete.");
-        }
-    }
-
-    public void fullRestore(ParcelFileDescriptor fd) {
-        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "fullRestore");
-
-        final int callingUserHandle = UserHandle.getCallingUserId();
-        if (callingUserHandle != UserHandle.USER_OWNER) {
-            throw new IllegalStateException("Restore supported only for the device owner");
-        }
-
-        long oldId = Binder.clearCallingIdentity();
-
-        try {
-            // Check whether the device has been provisioned -- we don't handle
-            // full restores prior to completing the setup process.
-            if (!deviceIsProvisioned()) {
-                Slog.i(TAG, "Full restore not permitted before setup");
-                return;
-            }
-
-            Slog.i(TAG, "Beginning full restore...");
-
-            FullRestoreParams params = new FullRestoreParams(fd);
-            final int token = generateToken();
-            synchronized (mFullConfirmations) {
-                mFullConfirmations.put(token, params);
-            }
-
-            // start up the confirmation UI
-            if (DEBUG) Slog.d(TAG, "Starting restore confirmation UI, token=" + token);
-            if (!startConfirmationUi(token, FullBackup.FULL_RESTORE_INTENT_ACTION)) {
-                Slog.e(TAG, "Unable to launch full restore confirmation");
-                mFullConfirmations.delete(token);
-                return;
-            }
-
-            // make sure the screen is lit for the user interaction
-            mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
-
-            // start the confirmation countdown
-            startConfirmationTimeout(token, params);
-
-            // wait for the restore to be performed
-            if (DEBUG) Slog.d(TAG, "Waiting for full restore completion...");
-            waitForCompletion(params);
-        } finally {
-            try {
-                fd.close();
-            } catch (IOException e) {
-                Slog.w(TAG, "Error trying to close fd after full restore: " + e);
-            }
-            Binder.restoreCallingIdentity(oldId);
-            Slog.i(TAG, "Full restore processing complete.");
-        }
-    }
-
-    boolean startConfirmationUi(int token, String action) {
-        try {
-            Intent confIntent = new Intent(action);
-            confIntent.setClassName("com.android.backupconfirm",
-                    "com.android.backupconfirm.BackupRestoreConfirmation");
-            confIntent.putExtra(FullBackup.CONF_TOKEN_INTENT_EXTRA, token);
-            confIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-            mContext.startActivity(confIntent);
-        } catch (ActivityNotFoundException e) {
-            return false;
-        }
-        return true;
-    }
-
-    void startConfirmationTimeout(int token, FullParams params) {
-        if (MORE_DEBUG) Slog.d(TAG, "Posting conf timeout msg after "
-                + TIMEOUT_FULL_CONFIRMATION + " millis");
-        Message msg = mBackupHandler.obtainMessage(MSG_FULL_CONFIRMATION_TIMEOUT,
-                token, 0, params);
-        mBackupHandler.sendMessageDelayed(msg, TIMEOUT_FULL_CONFIRMATION);
-    }
-
-    void waitForCompletion(FullParams params) {
-        synchronized (params.latch) {
-            while (params.latch.get() == false) {
-                try {
-                    params.latch.wait();
-                } catch (InterruptedException e) { /* never interrupted */ }
-            }
-        }
-    }
-
-    void signalFullBackupRestoreCompletion(FullParams params) {
-        synchronized (params.latch) {
-            params.latch.set(true);
-            params.latch.notifyAll();
-        }
-    }
-
-    // Confirm that the previously-requested full backup/restore operation can proceed.  This
-    // is used to require a user-facing disclosure about the operation.
-    @Override
-    public void acknowledgeFullBackupOrRestore(int token, boolean allow,
-            String curPassword, String encPpassword, IFullBackupRestoreObserver observer) {
-        if (DEBUG) Slog.d(TAG, "acknowledgeFullBackupOrRestore : token=" + token
-                + " allow=" + allow);
-
-        // TODO: possibly require not just this signature-only permission, but even
-        // require that the specific designated confirmation-UI app uid is the caller?
-        mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "acknowledgeFullBackupOrRestore");
-
-        long oldId = Binder.clearCallingIdentity();
-        try {
-
-            FullParams params;
-            synchronized (mFullConfirmations) {
-                params = mFullConfirmations.get(token);
-                if (params != null) {
-                    mBackupHandler.removeMessages(MSG_FULL_CONFIRMATION_TIMEOUT, params);
-                    mFullConfirmations.delete(token);
-
-                    if (allow) {
-                        final int verb = params instanceof FullBackupParams
-                                ? MSG_RUN_FULL_BACKUP
-                                : MSG_RUN_FULL_RESTORE;
-
-                        params.observer = observer;
-                        params.curPassword = curPassword;
-
-                        boolean isEncrypted;
-                        try {
-                            isEncrypted = (mMountService.getEncryptionState() != MountService.ENCRYPTION_STATE_NONE);
-                            if (isEncrypted) Slog.w(TAG, "Device is encrypted; forcing enc password");
-                        } catch (RemoteException e) {
-                            // couldn't contact the mount service; fail "safe" and assume encryption
-                            Slog.e(TAG, "Unable to contact mount service!");
-                            isEncrypted = true;
-                        }
-                        params.encryptPassword = (isEncrypted) ? curPassword : encPpassword;
-
-                        if (DEBUG) Slog.d(TAG, "Sending conf message with verb " + verb);
-                        mWakelock.acquire();
-                        Message msg = mBackupHandler.obtainMessage(verb, params);
-                        mBackupHandler.sendMessage(msg);
-                    } else {
-                        Slog.w(TAG, "User rejected full backup/restore operation");
-                        // indicate completion without having actually transferred any data
-                        signalFullBackupRestoreCompletion(params);
-                    }
-                } else {
-                    Slog.w(TAG, "Attempted to ack full backup/restore with invalid token");
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(oldId);
-        }
-    }
-
-    // Enable/disable the backup service
-    @Override
-    public void setBackupEnabled(boolean enable) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "setBackupEnabled");
-
-        Slog.i(TAG, "Backup enabled => " + enable);
-
-        long oldId = Binder.clearCallingIdentity();
-        try {
-            boolean wasEnabled = mEnabled;
-            synchronized (this) {
-                Settings.Secure.putInt(mContext.getContentResolver(),
-                        Settings.Secure.BACKUP_ENABLED, enable ? 1 : 0);
-                mEnabled = enable;
-            }
-
-            synchronized (mQueueLock) {
-                if (enable && !wasEnabled && mProvisioned) {
-                    // if we've just been enabled, start scheduling backup passes
-                    startBackupAlarmsLocked(BACKUP_INTERVAL);
-                } else if (!enable) {
-                    // No longer enabled, so stop running backups
-                    if (DEBUG) Slog.i(TAG, "Opting out of backup");
-
-                    mAlarmManager.cancel(mRunBackupIntent);
-
-                    // This also constitutes an opt-out, so we wipe any data for
-                    // this device from the backend.  We start that process with
-                    // an alarm in order to guarantee wakelock states.
-                    if (wasEnabled && mProvisioned) {
-                        // NOTE: we currently flush every registered transport, not just
-                        // the currently-active one.
-                        HashSet<String> allTransports;
-                        synchronized (mTransports) {
-                            allTransports = new HashSet<String>(mTransports.keySet());
-                        }
-                        // build the set of transports for which we are posting an init
-                        for (String transport : allTransports) {
-                            recordInitPendingLocked(true, transport);
-                        }
-                        mAlarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
-                                mRunInitIntent);
-                    }
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(oldId);
-        }
-    }
-
-    // Enable/disable automatic restore of app data at install time
-    public void setAutoRestore(boolean doAutoRestore) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "setAutoRestore");
-
-        Slog.i(TAG, "Auto restore => " + doAutoRestore);
-
-        synchronized (this) {
-            Settings.Secure.putInt(mContext.getContentResolver(),
-                    Settings.Secure.BACKUP_AUTO_RESTORE, doAutoRestore ? 1 : 0);
-            mAutoRestore = doAutoRestore;
-        }
-    }
-
-    // Mark the backup service as having been provisioned
-    public void setBackupProvisioned(boolean available) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "setBackupProvisioned");
-        /*
-         * This is now a no-op; provisioning is simply the device's own setup state.
-         */
-    }
-
-    private void startBackupAlarmsLocked(long delayBeforeFirstBackup) {
-        // We used to use setInexactRepeating(), but that may be linked to
-        // backups running at :00 more often than not, creating load spikes.
-        // Schedule at an exact time for now, and also add a bit of "fuzz".
-
-        Random random = new Random();
-        long when = System.currentTimeMillis() + delayBeforeFirstBackup +
-                random.nextInt(FUZZ_MILLIS);
-        mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, when,
-                BACKUP_INTERVAL + random.nextInt(FUZZ_MILLIS), mRunBackupIntent);
-        mNextBackupPass = when;
-    }
-
-    // Report whether the backup mechanism is currently enabled
-    public boolean isBackupEnabled() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "isBackupEnabled");
-        return mEnabled;    // no need to synchronize just to read it
-    }
-
-    // Report the name of the currently active transport
-    public String getCurrentTransport() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "getCurrentTransport");
-        if (MORE_DEBUG) Slog.v(TAG, "... getCurrentTransport() returning " + mCurrentTransport);
-        return mCurrentTransport;
-    }
-
-    // Report all known, available backup transports
-    public String[] listAllTransports() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "listAllTransports");
-
-        String[] list = null;
-        ArrayList<String> known = new ArrayList<String>();
-        for (Map.Entry<String, IBackupTransport> entry : mTransports.entrySet()) {
-            if (entry.getValue() != null) {
-                known.add(entry.getKey());
-            }
-        }
-
-        if (known.size() > 0) {
-            list = new String[known.size()];
-            known.toArray(list);
-        }
-        return list;
-    }
-
-    // Select which transport to use for the next backup operation.  If the given
-    // name is not one of the available transports, no action is taken and the method
-    // returns null.
-    public String selectBackupTransport(String transport) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "selectBackupTransport");
-
-        synchronized (mTransports) {
-            String prevTransport = null;
-            if (mTransports.get(transport) != null) {
-                prevTransport = mCurrentTransport;
-                mCurrentTransport = transport;
-                Settings.Secure.putString(mContext.getContentResolver(),
-                        Settings.Secure.BACKUP_TRANSPORT, transport);
-                Slog.v(TAG, "selectBackupTransport() set " + mCurrentTransport
-                        + " returning " + prevTransport);
-            } else {
-                Slog.w(TAG, "Attempt to select unavailable transport " + transport);
-            }
-            return prevTransport;
-        }
-    }
-
-    // Supply the configuration Intent for the given transport.  If the name is not one
-    // of the available transports, or if the transport does not supply any configuration
-    // UI, the method returns null.
-    public Intent getConfigurationIntent(String transportName) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "getConfigurationIntent");
-
-        synchronized (mTransports) {
-            final IBackupTransport transport = mTransports.get(transportName);
-            if (transport != null) {
-                try {
-                    final Intent intent = transport.configurationIntent();
-                    if (MORE_DEBUG) Slog.d(TAG, "getConfigurationIntent() returning config intent "
-                            + intent);
-                    return intent;
-                } catch (RemoteException e) {
-                    /* fall through to return null */
-                }
-            }
-        }
-
-        return null;
-    }
-
-    // Supply the configuration summary string for the given transport.  If the name is
-    // not one of the available transports, or if the transport does not supply any
-    // summary / destination string, the method can return null.
-    //
-    // This string is used VERBATIM as the summary text of the relevant Settings item!
-    public String getDestinationString(String transportName) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                "getDestinationString");
-
-        synchronized (mTransports) {
-            final IBackupTransport transport = mTransports.get(transportName);
-            if (transport != null) {
-                try {
-                    final String text = transport.currentDestinationString();
-                    if (MORE_DEBUG) Slog.d(TAG, "getDestinationString() returning " + text);
-                    return text;
-                } catch (RemoteException e) {
-                    /* fall through to return null */
-                }
-            }
-        }
-
-        return null;
-    }
-
-    // Callback: a requested backup agent has been instantiated.  This should only
-    // be called from the Activity Manager.
-    public void agentConnected(String packageName, IBinder agentBinder) {
-        synchronized(mAgentConnectLock) {
-            if (Binder.getCallingUid() == Process.SYSTEM_UID) {
-                Slog.d(TAG, "agentConnected pkg=" + packageName + " agent=" + agentBinder);
-                IBackupAgent agent = IBackupAgent.Stub.asInterface(agentBinder);
-                mConnectedAgent = agent;
-                mConnecting = false;
-            } else {
-                Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid()
-                        + " claiming agent connected");
-            }
-            mAgentConnectLock.notifyAll();
-        }
-    }
-
-    // Callback: a backup agent has failed to come up, or has unexpectedly quit.
-    // If the agent failed to come up in the first place, the agentBinder argument
-    // will be null.  This should only be called from the Activity Manager.
-    public void agentDisconnected(String packageName) {
-        // TODO: handle backup being interrupted
-        synchronized(mAgentConnectLock) {
-            if (Binder.getCallingUid() == Process.SYSTEM_UID) {
-                mConnectedAgent = null;
-                mConnecting = false;
-            } else {
-                Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid()
-                        + " claiming agent disconnected");
-            }
-            mAgentConnectLock.notifyAll();
-        }
-    }
-
-    // An application being installed will need a restore pass, then the Package Manager
-    // will need to be told when the restore is finished.
-    public void restoreAtInstall(String packageName, int token) {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-            Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid()
-                    + " attemping install-time restore");
-            return;
-        }
-
-        boolean skip = false;
-
-        long restoreSet = getAvailableRestoreToken(packageName);
-        if (DEBUG) Slog.v(TAG, "restoreAtInstall pkg=" + packageName
-                + " token=" + Integer.toHexString(token)
-                + " restoreSet=" + Long.toHexString(restoreSet));
-        if (restoreSet == 0) {
-            if (MORE_DEBUG) Slog.i(TAG, "No restore set");
-            skip = true;
-        }
-
-        // Do we have a transport to fetch data for us?
-        IBackupTransport transport = getTransport(mCurrentTransport);
-        if (transport == null) {
-            if (DEBUG) Slog.w(TAG, "No transport");
-            skip = true;
-        }
-
-        if (!skip && mAutoRestore && mProvisioned) {
-            try {
-                // okay, we're going to attempt a restore of this package from this restore set.
-                // The eventual message back into the Package Manager to run the post-install
-                // steps for 'token' will be issued from the restore handling code.
-
-                // This can throw and so *must* happen before the wakelock is acquired
-                String dirName = transport.transportDirName();
-
-                // We can use a synthetic PackageInfo here because:
-                //   1. We know it's valid, since the Package Manager supplied the name
-                //   2. Only the packageName field will be used by the restore code
-                PackageInfo pkg = new PackageInfo();
-                pkg.packageName = packageName;
-
-                mWakelock.acquire();
-                Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
-                msg.obj = new RestoreParams(transport, dirName, null,
-                        restoreSet, pkg, token, true);
-                mBackupHandler.sendMessage(msg);
-            } catch (RemoteException e) {
-                // Binding to the transport broke; back off and proceed with the installation.
-                Slog.e(TAG, "Unable to contact transport");
-                skip = true;
-            }
-        }
-
-        if (skip) {
-            // Auto-restore disabled or no way to attempt a restore; just tell the Package
-            // Manager to proceed with the post-install handling for this package.
-            if (DEBUG) Slog.v(TAG, "Skipping");
-            try {
-                mPackageManagerBinder.finishPackageInstall(token);
-            } catch (RemoteException e) { /* can't happen */ }
-        }
-    }
-
-    // Hand off a restore session
-    public IRestoreSession beginRestoreSession(String packageName, String transport) {
-        if (DEBUG) Slog.v(TAG, "beginRestoreSession: pkg=" + packageName
-                + " transport=" + transport);
-
-        boolean needPermission = true;
-        if (transport == null) {
-            transport = mCurrentTransport;
-
-            if (packageName != null) {
-                PackageInfo app = null;
-                try {
-                    app = mPackageManager.getPackageInfo(packageName, 0);
-                } catch (NameNotFoundException nnf) {
-                    Slog.w(TAG, "Asked to restore nonexistent pkg " + packageName);
-                    throw new IllegalArgumentException("Package " + packageName + " not found");
-                }
-
-                if (app.applicationInfo.uid == Binder.getCallingUid()) {
-                    // So: using the current active transport, and the caller has asked
-                    // that its own package will be restored.  In this narrow use case
-                    // we do not require the caller to hold the permission.
-                    needPermission = false;
-                }
-            }
-        }
-
-        if (needPermission) {
-            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                    "beginRestoreSession");
-        } else {
-            if (DEBUG) Slog.d(TAG, "restoring self on current transport; no permission needed");
-        }
-
-        synchronized(this) {
-            if (mActiveRestoreSession != null) {
-                Slog.d(TAG, "Restore session requested but one already active");
-                return null;
-            }
-            mActiveRestoreSession = new ActiveRestoreSession(packageName, transport);
-            mBackupHandler.sendEmptyMessageDelayed(MSG_RESTORE_TIMEOUT, TIMEOUT_RESTORE_INTERVAL);
-        }
-        return mActiveRestoreSession;
-    }
-
-    void clearRestoreSession(ActiveRestoreSession currentSession) {
-        synchronized(this) {
-            if (currentSession != mActiveRestoreSession) {
-                Slog.e(TAG, "ending non-current restore session");
-            } else {
-                if (DEBUG) Slog.v(TAG, "Clearing restore session and halting timeout");
-                mActiveRestoreSession = null;
-                mBackupHandler.removeMessages(MSG_RESTORE_TIMEOUT);
-            }
-        }
-    }
-
-    // Note that a currently-active backup agent has notified us that it has
-    // completed the given outstanding asynchronous backup/restore operation.
-    @Override
-    public void opComplete(int token) {
-        if (MORE_DEBUG) Slog.v(TAG, "opComplete: " + Integer.toHexString(token));
-        Operation op = null;
-        synchronized (mCurrentOpLock) {
-            op = mCurrentOperations.get(token);
-            if (op != null) {
-                op.state = OP_ACKNOWLEDGED;
-            }
-            mCurrentOpLock.notifyAll();
-        }
-
-        // The completion callback, if any, is invoked on the handler
-        if (op != null && op.callback != null) {
-            Message msg = mBackupHandler.obtainMessage(MSG_OP_COMPLETE, op.callback);
-            mBackupHandler.sendMessage(msg);
-        }
-    }
-
-    // ----- Restore session -----
-
-    class ActiveRestoreSession extends IRestoreSession.Stub {
-        private static final String TAG = "RestoreSession";
-
-        private String mPackageName;
-        private IBackupTransport mRestoreTransport = null;
-        RestoreSet[] mRestoreSets = null;
-        boolean mEnded = false;
-
-        ActiveRestoreSession(String packageName, String transport) {
-            mPackageName = packageName;
-            mRestoreTransport = getTransport(transport);
-        }
-
-        // --- Binder interface ---
-        public synchronized int getAvailableRestoreSets(IRestoreObserver observer) {
-            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                    "getAvailableRestoreSets");
-            if (observer == null) {
-                throw new IllegalArgumentException("Observer must not be null");
-            }
-
-            if (mEnded) {
-                throw new IllegalStateException("Restore session already ended");
-            }
-
-            long oldId = Binder.clearCallingIdentity();
-            try {
-                if (mRestoreTransport == null) {
-                    Slog.w(TAG, "Null transport getting restore sets");
-                    return -1;
-                }
-                // spin off the transport request to our service thread
-                mWakelock.acquire();
-                Message msg = mBackupHandler.obtainMessage(MSG_RUN_GET_RESTORE_SETS,
-                        new RestoreGetSetsParams(mRestoreTransport, this, observer));
-                mBackupHandler.sendMessage(msg);
-                return 0;
-            } catch (Exception e) {
-                Slog.e(TAG, "Error in getAvailableRestoreSets", e);
-                return -1;
-            } finally {
-                Binder.restoreCallingIdentity(oldId);
-            }
-        }
-
-        public synchronized int restoreAll(long token, IRestoreObserver observer) {
-            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                    "performRestore");
-
-            if (DEBUG) Slog.d(TAG, "restoreAll token=" + Long.toHexString(token)
-                    + " observer=" + observer);
-
-            if (mEnded) {
-                throw new IllegalStateException("Restore session already ended");
-            }
-
-            if (mRestoreTransport == null || mRestoreSets == null) {
-                Slog.e(TAG, "Ignoring restoreAll() with no restore set");
-                return -1;
-            }
-
-            if (mPackageName != null) {
-                Slog.e(TAG, "Ignoring restoreAll() on single-package session");
-                return -1;
-            }
-
-            String dirName;
-            try {
-                dirName = mRestoreTransport.transportDirName();
-            } catch (RemoteException e) {
-                // Transport went AWOL; fail.
-                Slog.e(TAG, "Unable to contact transport for restore");
-                return -1;
-            }
-
-            synchronized (mQueueLock) {
-                for (int i = 0; i < mRestoreSets.length; i++) {
-                    if (token == mRestoreSets[i].token) {
-                        long oldId = Binder.clearCallingIdentity();
-                        mWakelock.acquire();
-                        Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
-                        msg.obj = new RestoreParams(mRestoreTransport, dirName,
-                                observer, token, true);
-                        mBackupHandler.sendMessage(msg);
-                        Binder.restoreCallingIdentity(oldId);
-                        return 0;
-                    }
-                }
-            }
-
-            Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found");
-            return -1;
-        }
-
-        public synchronized int restoreSome(long token, IRestoreObserver observer,
-                String[] packages) {
-            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP,
-                    "performRestore");
-
-            if (DEBUG) {
-                StringBuilder b = new StringBuilder(128);
-                b.append("restoreSome token=");
-                b.append(Long.toHexString(token));
-                b.append(" observer=");
-                b.append(observer.toString());
-                b.append(" packages=");
-                if (packages == null) {
-                    b.append("null");
-                } else {
-                    b.append('{');
-                    boolean first = true;
-                    for (String s : packages) {
-                        if (!first) {
-                            b.append(", ");
-                        } else first = false;
-                        b.append(s);
-                    }
-                    b.append('}');
-                }
-                Slog.d(TAG, b.toString());
-            }
-
-            if (mEnded) {
-                throw new IllegalStateException("Restore session already ended");
-            }
-
-            if (mRestoreTransport == null || mRestoreSets == null) {
-                Slog.e(TAG, "Ignoring restoreAll() with no restore set");
-                return -1;
-            }
-
-            if (mPackageName != null) {
-                Slog.e(TAG, "Ignoring restoreAll() on single-package session");
-                return -1;
-            }
-
-            String dirName;
-            try {
-                dirName = mRestoreTransport.transportDirName();
-            } catch (RemoteException e) {
-                // Transport went AWOL; fail.
-                Slog.e(TAG, "Unable to contact transport for restore");
-                return -1;
-            }
-
-            synchronized (mQueueLock) {
-                for (int i = 0; i < mRestoreSets.length; i++) {
-                    if (token == mRestoreSets[i].token) {
-                        long oldId = Binder.clearCallingIdentity();
-                        mWakelock.acquire();
-                        Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
-                        msg.obj = new RestoreParams(mRestoreTransport, dirName, observer, token,
-                                packages, true);
-                        mBackupHandler.sendMessage(msg);
-                        Binder.restoreCallingIdentity(oldId);
-                        return 0;
-                    }
-                }
-            }
-
-            Slog.w(TAG, "Restore token " + Long.toHexString(token) + " not found");
-            return -1;
-        }
-
-        public synchronized int restorePackage(String packageName, IRestoreObserver observer) {
-            if (DEBUG) Slog.v(TAG, "restorePackage pkg=" + packageName + " obs=" + observer);
-
-            if (mEnded) {
-                throw new IllegalStateException("Restore session already ended");
-            }
-
-            if (mPackageName != null) {
-                if (! mPackageName.equals(packageName)) {
-                    Slog.e(TAG, "Ignoring attempt to restore pkg=" + packageName
-                            + " on session for package " + mPackageName);
-                    return -1;
-                }
-            }
-
-            PackageInfo app = null;
-            try {
-                app = mPackageManager.getPackageInfo(packageName, 0);
-            } catch (NameNotFoundException nnf) {
-                Slog.w(TAG, "Asked to restore nonexistent pkg " + packageName);
-                return -1;
-            }
-
-            // If the caller is not privileged and is not coming from the target
-            // app's uid, throw a permission exception back to the caller.
-            int perm = mContext.checkPermission(android.Manifest.permission.BACKUP,
-                    Binder.getCallingPid(), Binder.getCallingUid());
-            if ((perm == PackageManager.PERMISSION_DENIED) &&
-                    (app.applicationInfo.uid != Binder.getCallingUid())) {
-                Slog.w(TAG, "restorePackage: bad packageName=" + packageName
-                        + " or calling uid=" + Binder.getCallingUid());
-                throw new SecurityException("No permission to restore other packages");
-            }
-
-            // If the package has no backup agent, we obviously cannot proceed
-            if (app.applicationInfo.backupAgentName == null) {
-                Slog.w(TAG, "Asked to restore package " + packageName + " with no agent");
-                return -1;
-            }
-
-            // So far so good; we're allowed to try to restore this package.  Now
-            // check whether there is data for it in the current dataset, falling back
-            // to the ancestral dataset if not.
-            long token = getAvailableRestoreToken(packageName);
-
-            // If we didn't come up with a place to look -- no ancestral dataset and
-            // the app has never been backed up from this device -- there's nothing
-            // to do but return failure.
-            if (token == 0) {
-                if (DEBUG) Slog.w(TAG, "No data available for this package; not restoring");
-                return -1;
-            }
-
-            String dirName;
-            try {
-                dirName = mRestoreTransport.transportDirName();
-            } catch (RemoteException e) {
-                // Transport went AWOL; fail.
-                Slog.e(TAG, "Unable to contact transport for restore");
-                return -1;
-            }
-
-            // Ready to go:  enqueue the restore request and claim success
-            long oldId = Binder.clearCallingIdentity();
-            mWakelock.acquire();
-            Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
-            msg.obj = new RestoreParams(mRestoreTransport, dirName,
-                    observer, token, app, 0, false);
-            mBackupHandler.sendMessage(msg);
-            Binder.restoreCallingIdentity(oldId);
-            return 0;
-        }
-
-        // Posted to the handler to tear down a restore session in a cleanly synchronized way
-        class EndRestoreRunnable implements Runnable {
-            BackupManagerService mBackupManager;
-            ActiveRestoreSession mSession;
-
-            EndRestoreRunnable(BackupManagerService manager, ActiveRestoreSession session) {
-                mBackupManager = manager;
-                mSession = session;
-            }
-
-            public void run() {
-                // clean up the session's bookkeeping
-                synchronized (mSession) {
-                    try {
-                        if (mSession.mRestoreTransport != null) {
-                            mSession.mRestoreTransport.finishRestore();
-                        }
-                    } catch (Exception e) {
-                        Slog.e(TAG, "Error in finishRestore", e);
-                    } finally {
-                        mSession.mRestoreTransport = null;
-                        mSession.mEnded = true;
-                    }
-                }
-
-                // clean up the BackupManagerService side of the bookkeeping
-                // and cancel any pending timeout message
-                mBackupManager.clearRestoreSession(mSession);
-            }
-        }
-
-        public synchronized void endRestoreSession() {
-            if (DEBUG) Slog.d(TAG, "endRestoreSession");
-
-            if (mEnded) {
-                throw new IllegalStateException("Restore session already ended");
-            }
-
-            mBackupHandler.post(new EndRestoreRunnable(BackupManagerService.this, this));
-        }
-    }
-
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
-
-        long identityToken = Binder.clearCallingIdentity();
-        try {
-            dumpInternal(pw);
-        } finally {
-            Binder.restoreCallingIdentity(identityToken);
-        }
-    }
-
-    private void dumpInternal(PrintWriter pw) {
-        synchronized (mQueueLock) {
-            pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled")
-                    + " / " + (!mProvisioned ? "not " : "") + "provisioned / "
-                    + (this.mPendingInits.size() == 0 ? "not " : "") + "pending init");
-            pw.println("Auto-restore is " + (mAutoRestore ? "enabled" : "disabled"));
-            if (mBackupRunning) pw.println("Backup currently running");
-            pw.println("Last backup pass started: " + mLastBackupPass
-                    + " (now = " + System.currentTimeMillis() + ')');
-            pw.println("  next scheduled: " + mNextBackupPass);
-
-            pw.println("Available transports:");
-            for (String t : listAllTransports()) {
-                pw.println((t.equals(mCurrentTransport) ? "  * " : "    ") + t);
-                try {
-                    IBackupTransport transport = getTransport(t);
-                    File dir = new File(mBaseStateDir, transport.transportDirName());
-                    pw.println("       destination: " + transport.currentDestinationString());
-                    pw.println("       intent: " + transport.configurationIntent());
-                    for (File f : dir.listFiles()) {
-                        pw.println("       " + f.getName() + " - " + f.length() + " state bytes");
-                    }
-                } catch (Exception e) {
-                    Slog.e(TAG, "Error in transport", e);
-                    pw.println("        Error: " + e);
-                }
-            }
-
-            pw.println("Pending init: " + mPendingInits.size());
-            for (String s : mPendingInits) {
-                pw.println("    " + s);
-            }
-
-            if (DEBUG_BACKUP_TRACE) {
-                synchronized (mBackupTrace) {
-                    if (!mBackupTrace.isEmpty()) {
-                        pw.println("Most recent backup trace:");
-                        for (String s : mBackupTrace) {
-                            pw.println("   " + s);
-                        }
-                    }
-                }
-            }
-
-            int N = mBackupParticipants.size();
-            pw.println("Participants:");
-            for (int i=0; i<N; i++) {
-                int uid = mBackupParticipants.keyAt(i);
-                pw.print("  uid: ");
-                pw.println(uid);
-                HashSet<String> participants = mBackupParticipants.valueAt(i);
-                for (String app: participants) {
-                    pw.println("    " + app);
-                }
-            }
-
-            pw.println("Ancestral packages: "
-                    + (mAncestralPackages == null ? "none" : mAncestralPackages.size()));
-            if (mAncestralPackages != null) {
-                for (String pkg : mAncestralPackages) {
-                    pw.println("    " + pkg);
-                }
-            }
-
-            pw.println("Ever backed up: " + mEverStoredApps.size());
-            for (String pkg : mEverStoredApps) {
-                pw.println("    " + pkg);
-            }
-
-            pw.println("Pending backup: " + mPendingBackups.size());
-            for (BackupRequest req : mPendingBackups.values()) {
-                pw.println("    " + req);
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java
deleted file mode 100644
index 5f3f894..0000000
--- a/services/java/com/android/server/BatteryService.java
+++ /dev/null
@@ -1,750 +0,0 @@
-/*
- * Copyright (C) 2006 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;
-
-import android.os.BatteryStats;
-import com.android.internal.app.IBatteryStats;
-import com.android.server.am.BatteryStatsService;
-
-import android.app.ActivityManagerNative;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.os.BatteryManager;
-import android.os.BatteryProperties;
-import android.os.Binder;
-import android.os.FileUtils;
-import android.os.Handler;
-import android.os.IBatteryPropertiesListener;
-import android.os.IBatteryPropertiesRegistrar;
-import android.os.IBinder;
-import android.os.DropBoxManager;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UEventObserver;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.util.EventLog;
-import android.util.Slog;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-
-/**
- * <p>BatteryService monitors the charging status, and charge level of the device
- * battery.  When these values change this service broadcasts the new values
- * to all {@link android.content.BroadcastReceiver IntentReceivers} that are
- * watching the {@link android.content.Intent#ACTION_BATTERY_CHANGED
- * BATTERY_CHANGED} action.</p>
- * <p>The new values are stored in the Intent data and can be retrieved by
- * calling {@link android.content.Intent#getExtra Intent.getExtra} with the
- * following keys:</p>
- * <p>&quot;scale&quot; - int, the maximum value for the charge level</p>
- * <p>&quot;level&quot; - int, charge level, from 0 through &quot;scale&quot; inclusive</p>
- * <p>&quot;status&quot; - String, the current charging status.<br />
- * <p>&quot;health&quot; - String, the current battery health.<br />
- * <p>&quot;present&quot; - boolean, true if the battery is present<br />
- * <p>&quot;icon-small&quot; - int, suggested small icon to use for this state</p>
- * <p>&quot;plugged&quot; - int, 0 if the device is not plugged in; 1 if plugged
- * into an AC power adapter; 2 if plugged in via USB.</p>
- * <p>&quot;voltage&quot; - int, current battery voltage in millivolts</p>
- * <p>&quot;temperature&quot; - int, current battery temperature in tenths of
- * a degree Centigrade</p>
- * <p>&quot;technology&quot; - String, the type of battery installed, e.g. "Li-ion"</p>
- *
- * <p>
- * The battery service may be called by the power manager while holding its locks so
- * we take care to post all outcalls into the activity manager to a handler.
- *
- * FIXME: Ideally the power manager would perform all of its calls into the battery
- * service asynchronously itself.
- * </p>
- */
-public final class BatteryService extends Binder {
-    private static final String TAG = BatteryService.class.getSimpleName();
-
-    private static final boolean DEBUG = false;
-
-    private static final int BATTERY_SCALE = 100;    // battery capacity is a percentage
-
-    // Used locally for determining when to make a last ditch effort to log
-    // discharge stats before the device dies.
-    private int mCriticalBatteryLevel;
-
-    private static final int DUMP_MAX_LENGTH = 24 * 1024;
-    private static final String[] DUMPSYS_ARGS = new String[] { "--checkin", "--unplugged" };
-
-    private static final String DUMPSYS_DATA_PATH = "/data/system/";
-
-    // This should probably be exposed in the API, though it's not critical
-    private static final int BATTERY_PLUGGED_NONE = 0;
-
-    private final Context mContext;
-    private final IBatteryStats mBatteryStats;
-    private final Handler mHandler;
-
-    private final Object mLock = new Object();
-
-    private BatteryProperties mBatteryProps;
-    private boolean mBatteryLevelCritical;
-    private int mLastBatteryStatus;
-    private int mLastBatteryHealth;
-    private boolean mLastBatteryPresent;
-    private int mLastBatteryLevel;
-    private int mLastBatteryVoltage;
-    private int mLastBatteryTemperature;
-    private boolean mLastBatteryLevelCritical;
-
-    private int mInvalidCharger;
-    private int mLastInvalidCharger;
-
-    private int mLowBatteryWarningLevel;
-    private int mLowBatteryCloseWarningLevel;
-    private int mShutdownBatteryTemperature;
-
-    private int mPlugType;
-    private int mLastPlugType = -1; // Extra state so we can detect first run
-
-    private long mDischargeStartTime;
-    private int mDischargeStartLevel;
-
-    private boolean mUpdatesStopped;
-
-    private Led mLed;
-
-    private boolean mSentLowBatteryBroadcast = false;
-
-    private BatteryListener mBatteryPropertiesListener;
-    private IBatteryPropertiesRegistrar mBatteryPropertiesRegistrar;
-
-    public BatteryService(Context context, LightsService lights) {
-        mContext = context;
-        mHandler = new Handler(true /*async*/);
-        mLed = new Led(context, lights);
-        mBatteryStats = BatteryStatsService.getService();
-
-        mCriticalBatteryLevel = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_criticalBatteryWarningLevel);
-        mLowBatteryWarningLevel = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_lowBatteryWarningLevel);
-        mLowBatteryCloseWarningLevel = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_lowBatteryCloseWarningLevel);
-        mShutdownBatteryTemperature = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_shutdownBatteryTemperature);
-
-        // watch for invalid charger messages if the invalid_charger switch exists
-        if (new File("/sys/devices/virtual/switch/invalid_charger/state").exists()) {
-            mInvalidChargerObserver.startObserving(
-                    "DEVPATH=/devices/virtual/switch/invalid_charger");
-        }
-
-        mBatteryPropertiesListener = new BatteryListener();
-
-        IBinder b = ServiceManager.getService("batterypropreg");
-        mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface(b);
-
-        try {
-            mBatteryPropertiesRegistrar.registerListener(mBatteryPropertiesListener);
-        } catch (RemoteException e) {
-            // Should never happen.
-        }
-    }
-
-    void systemReady() {
-        // check our power situation now that it is safe to display the shutdown dialog.
-        synchronized (mLock) {
-            shutdownIfNoPowerLocked();
-            shutdownIfOverTempLocked();
-        }
-    }
-
-    /**
-     * Returns true if the device is plugged into any of the specified plug types.
-     */
-    public boolean isPowered(int plugTypeSet) {
-        synchronized (mLock) {
-            return isPoweredLocked(plugTypeSet);
-        }
-    }
-
-    private boolean isPoweredLocked(int plugTypeSet) {
-        // assume we are powered if battery state is unknown so
-        // the "stay on while plugged in" option will work.
-        if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) {
-            return true;
-        }
-        if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_AC) != 0 && mBatteryProps.chargerAcOnline) {
-            return true;
-        }
-        if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_USB) != 0 && mBatteryProps.chargerUsbOnline) {
-            return true;
-        }
-        if ((plugTypeSet & BatteryManager.BATTERY_PLUGGED_WIRELESS) != 0 && mBatteryProps.chargerWirelessOnline) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Returns the current plug type.
-     */
-    public int getPlugType() {
-        synchronized (mLock) {
-            return mPlugType;
-        }
-    }
-
-    /**
-     * Returns battery level as a percentage.
-     */
-    public int getBatteryLevel() {
-        synchronized (mLock) {
-            return mBatteryProps.batteryLevel;
-        }
-    }
-
-    /**
-     * Returns true if battery level is below the first warning threshold.
-     */
-    public boolean isBatteryLow() {
-        synchronized (mLock) {
-            return mBatteryProps.batteryPresent && mBatteryProps.batteryLevel <= mLowBatteryWarningLevel;
-        }
-    }
-
-    /**
-     * Returns a non-zero value if an  unsupported charger is attached.
-     */
-    public int getInvalidCharger() {
-        synchronized (mLock) {
-            return mInvalidCharger;
-        }
-    }
-
-    private void shutdownIfNoPowerLocked() {
-        // shut down gracefully if our battery is critically low and we are not powered.
-        // wait until the system has booted before attempting to display the shutdown dialog.
-        if (mBatteryProps.batteryLevel == 0 && !isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    if (ActivityManagerNative.isSystemReady()) {
-                        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
-                        intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
-                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
-                    }
-                }
-            });
-        }
-    }
-
-    private void shutdownIfOverTempLocked() {
-        // shut down gracefully if temperature is too high (> 68.0C by default)
-        // wait until the system has booted before attempting to display the
-        // shutdown dialog.
-        if (mBatteryProps.batteryTemperature > mShutdownBatteryTemperature) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    if (ActivityManagerNative.isSystemReady()) {
-                        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
-                        intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
-                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                        mContext.startActivityAsUser(intent, UserHandle.CURRENT);
-                    }
-                }
-            });
-        }
-    }
-
-    private void update(BatteryProperties props) {
-        synchronized (mLock) {
-            if (!mUpdatesStopped) {
-                mBatteryProps = props;
-                // Process the new values.
-                processValuesLocked();
-            }
-        }
-    }
-
-    private void processValuesLocked() {
-        boolean logOutlier = false;
-        long dischargeDuration = 0;
-
-        mBatteryLevelCritical = (mBatteryProps.batteryLevel <= mCriticalBatteryLevel);
-        if (mBatteryProps.chargerAcOnline) {
-            mPlugType = BatteryManager.BATTERY_PLUGGED_AC;
-        } else if (mBatteryProps.chargerUsbOnline) {
-            mPlugType = BatteryManager.BATTERY_PLUGGED_USB;
-        } else if (mBatteryProps.chargerWirelessOnline) {
-            mPlugType = BatteryManager.BATTERY_PLUGGED_WIRELESS;
-        } else {
-            mPlugType = BATTERY_PLUGGED_NONE;
-        }
-
-        if (DEBUG) {
-            Slog.d(TAG, "Processing new values: "
-                    + "chargerAcOnline=" + mBatteryProps.chargerAcOnline
-                    + ", chargerUsbOnline=" + mBatteryProps.chargerUsbOnline
-                    + ", chargerWirelessOnline=" + mBatteryProps.chargerWirelessOnline
-                    + ", batteryStatus=" + mBatteryProps.batteryStatus
-                    + ", batteryHealth=" + mBatteryProps.batteryHealth
-                    + ", batteryPresent=" + mBatteryProps.batteryPresent
-                    + ", batteryLevel=" + mBatteryProps.batteryLevel
-                    + ", batteryTechnology=" + mBatteryProps.batteryTechnology
-                    + ", batteryVoltage=" + mBatteryProps.batteryVoltage
-                    + ", batteryCurrentNow=" + mBatteryProps.batteryCurrentNow
-                    + ", batteryChargeCounter=" + mBatteryProps.batteryChargeCounter
-                    + ", batteryTemperature=" + mBatteryProps.batteryTemperature
-                    + ", mBatteryLevelCritical=" + mBatteryLevelCritical
-                    + ", mPlugType=" + mPlugType);
-        }
-
-        // Let the battery stats keep track of the current level.
-        try {
-            mBatteryStats.setBatteryState(mBatteryProps.batteryStatus, mBatteryProps.batteryHealth,
-                    mPlugType, mBatteryProps.batteryLevel, mBatteryProps.batteryTemperature,
-                    mBatteryProps.batteryVoltage);
-        } catch (RemoteException e) {
-            // Should never happen.
-        }
-
-        shutdownIfNoPowerLocked();
-        shutdownIfOverTempLocked();
-
-        if (mBatteryProps.batteryStatus != mLastBatteryStatus ||
-                mBatteryProps.batteryHealth != mLastBatteryHealth ||
-                mBatteryProps.batteryPresent != mLastBatteryPresent ||
-                mBatteryProps.batteryLevel != mLastBatteryLevel ||
-                mPlugType != mLastPlugType ||
-                mBatteryProps.batteryVoltage != mLastBatteryVoltage ||
-                mBatteryProps.batteryTemperature != mLastBatteryTemperature ||
-                mInvalidCharger != mLastInvalidCharger) {
-
-            if (mPlugType != mLastPlugType) {
-                if (mLastPlugType == BATTERY_PLUGGED_NONE) {
-                    // discharging -> charging
-
-                    // There's no value in this data unless we've discharged at least once and the
-                    // battery level has changed; so don't log until it does.
-                    if (mDischargeStartTime != 0 && mDischargeStartLevel != mBatteryProps.batteryLevel) {
-                        dischargeDuration = SystemClock.elapsedRealtime() - mDischargeStartTime;
-                        logOutlier = true;
-                        EventLog.writeEvent(EventLogTags.BATTERY_DISCHARGE, dischargeDuration,
-                                mDischargeStartLevel, mBatteryProps.batteryLevel);
-                        // make sure we see a discharge event before logging again
-                        mDischargeStartTime = 0;
-                    }
-                } else if (mPlugType == BATTERY_PLUGGED_NONE) {
-                    // charging -> discharging or we just powered up
-                    mDischargeStartTime = SystemClock.elapsedRealtime();
-                    mDischargeStartLevel = mBatteryProps.batteryLevel;
-                }
-            }
-            if (mBatteryProps.batteryStatus != mLastBatteryStatus ||
-                    mBatteryProps.batteryHealth != mLastBatteryHealth ||
-                    mBatteryProps.batteryPresent != mLastBatteryPresent ||
-                    mPlugType != mLastPlugType) {
-                EventLog.writeEvent(EventLogTags.BATTERY_STATUS,
-                        mBatteryProps.batteryStatus, mBatteryProps.batteryHealth, mBatteryProps.batteryPresent ? 1 : 0,
-                        mPlugType, mBatteryProps.batteryTechnology);
-            }
-            if (mBatteryProps.batteryLevel != mLastBatteryLevel) {
-                // Don't do this just from voltage or temperature changes, that is
-                // too noisy.
-                EventLog.writeEvent(EventLogTags.BATTERY_LEVEL,
-                        mBatteryProps.batteryLevel, mBatteryProps.batteryVoltage, mBatteryProps.batteryTemperature);
-            }
-            if (mBatteryLevelCritical && !mLastBatteryLevelCritical &&
-                    mPlugType == BATTERY_PLUGGED_NONE) {
-                // We want to make sure we log discharge cycle outliers
-                // if the battery is about to die.
-                dischargeDuration = SystemClock.elapsedRealtime() - mDischargeStartTime;
-                logOutlier = true;
-            }
-
-            final boolean plugged = mPlugType != BATTERY_PLUGGED_NONE;
-            final boolean oldPlugged = mLastPlugType != BATTERY_PLUGGED_NONE;
-
-            /* The ACTION_BATTERY_LOW broadcast is sent in these situations:
-             * - is just un-plugged (previously was plugged) and battery level is
-             *   less than or equal to WARNING, or
-             * - is not plugged and battery level falls to WARNING boundary
-             *   (becomes <= mLowBatteryWarningLevel).
-             */
-            final boolean sendBatteryLow = !plugged
-                    && mBatteryProps.batteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN
-                    && mBatteryProps.batteryLevel <= mLowBatteryWarningLevel
-                    && (oldPlugged || mLastBatteryLevel > mLowBatteryWarningLevel);
-
-            sendIntentLocked();
-
-            // Separate broadcast is sent for power connected / not connected
-            // since the standard intent will not wake any applications and some
-            // applications may want to have smart behavior based on this.
-            if (mPlugType != 0 && mLastPlugType == 0) {
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        Intent statusIntent = new Intent(Intent.ACTION_POWER_CONNECTED);
-                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
-                    }
-                });
-            }
-            else if (mPlugType == 0 && mLastPlugType != 0) {
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        Intent statusIntent = new Intent(Intent.ACTION_POWER_DISCONNECTED);
-                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
-                    }
-                });
-            }
-
-            if (sendBatteryLow) {
-                mSentLowBatteryBroadcast = true;
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        Intent statusIntent = new Intent(Intent.ACTION_BATTERY_LOW);
-                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
-                    }
-                });
-            } else if (mSentLowBatteryBroadcast && mLastBatteryLevel >= mLowBatteryCloseWarningLevel) {
-                mSentLowBatteryBroadcast = false;
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        Intent statusIntent = new Intent(Intent.ACTION_BATTERY_OKAY);
-                        statusIntent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                        mContext.sendBroadcastAsUser(statusIntent, UserHandle.ALL);
-                    }
-                });
-            }
-
-            // Update the battery LED
-            mLed.updateLightsLocked();
-
-            // This needs to be done after sendIntent() so that we get the lastest battery stats.
-            if (logOutlier && dischargeDuration != 0) {
-                logOutlierLocked(dischargeDuration);
-            }
-
-            mLastBatteryStatus = mBatteryProps.batteryStatus;
-            mLastBatteryHealth = mBatteryProps.batteryHealth;
-            mLastBatteryPresent = mBatteryProps.batteryPresent;
-            mLastBatteryLevel = mBatteryProps.batteryLevel;
-            mLastPlugType = mPlugType;
-            mLastBatteryVoltage = mBatteryProps.batteryVoltage;
-            mLastBatteryTemperature = mBatteryProps.batteryTemperature;
-            mLastBatteryLevelCritical = mBatteryLevelCritical;
-            mLastInvalidCharger = mInvalidCharger;
-        }
-    }
-
-    private void sendIntentLocked() {
-        //  Pack up the values and broadcast them to everyone
-        final Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED);
-        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                | Intent.FLAG_RECEIVER_REPLACE_PENDING);
-
-        int icon = getIconLocked(mBatteryProps.batteryLevel);
-
-        intent.putExtra(BatteryManager.EXTRA_STATUS, mBatteryProps.batteryStatus);
-        intent.putExtra(BatteryManager.EXTRA_HEALTH, mBatteryProps.batteryHealth);
-        intent.putExtra(BatteryManager.EXTRA_PRESENT, mBatteryProps.batteryPresent);
-        intent.putExtra(BatteryManager.EXTRA_LEVEL, mBatteryProps.batteryLevel);
-        intent.putExtra(BatteryManager.EXTRA_SCALE, BATTERY_SCALE);
-        intent.putExtra(BatteryManager.EXTRA_ICON_SMALL, icon);
-        intent.putExtra(BatteryManager.EXTRA_PLUGGED, mPlugType);
-        intent.putExtra(BatteryManager.EXTRA_VOLTAGE, mBatteryProps.batteryVoltage);
-        intent.putExtra(BatteryManager.EXTRA_TEMPERATURE, mBatteryProps.batteryTemperature);
-        intent.putExtra(BatteryManager.EXTRA_TECHNOLOGY, mBatteryProps.batteryTechnology);
-        intent.putExtra(BatteryManager.EXTRA_INVALID_CHARGER, mInvalidCharger);
-
-        if (DEBUG) {
-            Slog.d(TAG, "Sending ACTION_BATTERY_CHANGED.  level:" + mBatteryProps.batteryLevel +
-                    ", scale:" + BATTERY_SCALE + ", status:" + mBatteryProps.batteryStatus +
-                    ", health:" + mBatteryProps.batteryHealth +  ", present:" + mBatteryProps.batteryPresent +
-                    ", voltage: " + mBatteryProps.batteryVoltage +
-                    ", temperature: " + mBatteryProps.batteryTemperature +
-                    ", technology: " + mBatteryProps.batteryTechnology +
-                    ", AC powered:" + mBatteryProps.chargerAcOnline + ", USB powered:" + mBatteryProps.chargerUsbOnline +
-                    ", Wireless powered:" + mBatteryProps.chargerWirelessOnline +
-                    ", icon:" + icon  + ", invalid charger:" + mInvalidCharger);
-        }
-
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                ActivityManagerNative.broadcastStickyIntent(intent, null, UserHandle.USER_ALL);
-            }
-        });
-    }
-
-    private void logBatteryStatsLocked() {
-        IBinder batteryInfoService = ServiceManager.getService(BatteryStats.SERVICE_NAME);
-        if (batteryInfoService == null) return;
-
-        DropBoxManager db = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
-        if (db == null || !db.isTagEnabled("BATTERY_DISCHARGE_INFO")) return;
-
-        File dumpFile = null;
-        FileOutputStream dumpStream = null;
-        try {
-            // dump the service to a file
-            dumpFile = new File(DUMPSYS_DATA_PATH + BatteryStats.SERVICE_NAME + ".dump");
-            dumpStream = new FileOutputStream(dumpFile);
-            batteryInfoService.dump(dumpStream.getFD(), DUMPSYS_ARGS);
-            FileUtils.sync(dumpStream);
-
-            // add dump file to drop box
-            db.addFile("BATTERY_DISCHARGE_INFO", dumpFile, DropBoxManager.IS_TEXT);
-        } catch (RemoteException e) {
-            Slog.e(TAG, "failed to dump battery service", e);
-        } catch (IOException e) {
-            Slog.e(TAG, "failed to write dumpsys file", e);
-        } finally {
-            // make sure we clean up
-            if (dumpStream != null) {
-                try {
-                    dumpStream.close();
-                } catch (IOException e) {
-                    Slog.e(TAG, "failed to close dumpsys output stream");
-                }
-            }
-            if (dumpFile != null && !dumpFile.delete()) {
-                Slog.e(TAG, "failed to delete temporary dumpsys file: "
-                        + dumpFile.getAbsolutePath());
-            }
-        }
-    }
-
-    private void logOutlierLocked(long duration) {
-        ContentResolver cr = mContext.getContentResolver();
-        String dischargeThresholdString = Settings.Global.getString(cr,
-                Settings.Global.BATTERY_DISCHARGE_THRESHOLD);
-        String durationThresholdString = Settings.Global.getString(cr,
-                Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD);
-
-        if (dischargeThresholdString != null && durationThresholdString != null) {
-            try {
-                long durationThreshold = Long.parseLong(durationThresholdString);
-                int dischargeThreshold = Integer.parseInt(dischargeThresholdString);
-                if (duration <= durationThreshold &&
-                        mDischargeStartLevel - mBatteryProps.batteryLevel >= dischargeThreshold) {
-                    // If the discharge cycle is bad enough we want to know about it.
-                    logBatteryStatsLocked();
-                }
-                if (DEBUG) Slog.v(TAG, "duration threshold: " + durationThreshold +
-                        " discharge threshold: " + dischargeThreshold);
-                if (DEBUG) Slog.v(TAG, "duration: " + duration + " discharge: " +
-                        (mDischargeStartLevel - mBatteryProps.batteryLevel));
-            } catch (NumberFormatException e) {
-                Slog.e(TAG, "Invalid DischargeThresholds GService string: " +
-                        durationThresholdString + " or " + dischargeThresholdString);
-                return;
-            }
-        }
-    }
-
-    private int getIconLocked(int level) {
-        if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_CHARGING) {
-            return com.android.internal.R.drawable.stat_sys_battery_charge;
-        } else if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_DISCHARGING) {
-            return com.android.internal.R.drawable.stat_sys_battery;
-        } else if (mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_NOT_CHARGING
-                || mBatteryProps.batteryStatus == BatteryManager.BATTERY_STATUS_FULL) {
-            if (isPoweredLocked(BatteryManager.BATTERY_PLUGGED_ANY)
-                    && mBatteryProps.batteryLevel >= 100) {
-                return com.android.internal.R.drawable.stat_sys_battery_charge;
-            } else {
-                return com.android.internal.R.drawable.stat_sys_battery;
-            }
-        } else {
-            return com.android.internal.R.drawable.stat_sys_battery_unknown;
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-
-            pw.println("Permission Denial: can't dump Battery service from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mLock) {
-            if (args == null || args.length == 0 || "-a".equals(args[0])) {
-                pw.println("Current Battery Service state:");
-                if (mUpdatesStopped) {
-                    pw.println("  (UPDATES STOPPED -- use 'reset' to restart)");
-                }
-                pw.println("  AC powered: " + mBatteryProps.chargerAcOnline);
-                pw.println("  USB powered: " + mBatteryProps.chargerUsbOnline);
-                pw.println("  Wireless powered: " + mBatteryProps.chargerWirelessOnline);
-                pw.println("  status: " + mBatteryProps.batteryStatus);
-                pw.println("  health: " + mBatteryProps.batteryHealth);
-                pw.println("  present: " + mBatteryProps.batteryPresent);
-                pw.println("  level: " + mBatteryProps.batteryLevel);
-                pw.println("  scale: " + BATTERY_SCALE);
-                pw.println("  voltage: " + mBatteryProps.batteryVoltage);
-
-                if (mBatteryProps.batteryCurrentNow != Integer.MIN_VALUE) {
-                    pw.println("  current now: " + mBatteryProps.batteryCurrentNow);
-                }
-
-                if (mBatteryProps.batteryChargeCounter != Integer.MIN_VALUE) {
-                    pw.println("  charge counter: " + mBatteryProps.batteryChargeCounter);
-                }
-
-                pw.println("  temperature: " + mBatteryProps.batteryTemperature);
-                pw.println("  technology: " + mBatteryProps.batteryTechnology);
-            } else if (args.length == 3 && "set".equals(args[0])) {
-                String key = args[1];
-                String value = args[2];
-                try {
-                    boolean update = true;
-                    if ("ac".equals(key)) {
-                        mBatteryProps.chargerAcOnline = Integer.parseInt(value) != 0;
-                    } else if ("usb".equals(key)) {
-                        mBatteryProps.chargerUsbOnline = Integer.parseInt(value) != 0;
-                    } else if ("wireless".equals(key)) {
-                        mBatteryProps.chargerWirelessOnline = Integer.parseInt(value) != 0;
-                    } else if ("status".equals(key)) {
-                        mBatteryProps.batteryStatus = Integer.parseInt(value);
-                    } else if ("level".equals(key)) {
-                        mBatteryProps.batteryLevel = Integer.parseInt(value);
-                    } else if ("invalid".equals(key)) {
-                        mInvalidCharger = Integer.parseInt(value);
-                    } else {
-                        pw.println("Unknown set option: " + key);
-                        update = false;
-                    }
-                    if (update) {
-                        long ident = Binder.clearCallingIdentity();
-                        try {
-                            mUpdatesStopped = true;
-                            processValuesLocked();
-                        } finally {
-                            Binder.restoreCallingIdentity(ident);
-                        }
-                    }
-                } catch (NumberFormatException ex) {
-                    pw.println("Bad value: " + value);
-                }
-            } else if (args.length == 1 && "reset".equals(args[0])) {
-                long ident = Binder.clearCallingIdentity();
-                try {
-                    mUpdatesStopped = false;
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
-                }
-            } else {
-                pw.println("Dump current battery state, or:");
-                pw.println("  set ac|usb|wireless|status|level|invalid <value>");
-                pw.println("  reset");
-            }
-        }
-    }
-
-    private final UEventObserver mInvalidChargerObserver = new UEventObserver() {
-        @Override
-        public void onUEvent(UEventObserver.UEvent event) {
-            final int invalidCharger = "1".equals(event.get("SWITCH_STATE")) ? 1 : 0;
-            synchronized (mLock) {
-                if (mInvalidCharger != invalidCharger) {
-                    mInvalidCharger = invalidCharger;
-                }
-            }
-        }
-    };
-
-    private final class Led {
-        private final LightsService.Light mBatteryLight;
-
-        private final int mBatteryLowARGB;
-        private final int mBatteryMediumARGB;
-        private final int mBatteryFullARGB;
-        private final int mBatteryLedOn;
-        private final int mBatteryLedOff;
-
-        public Led(Context context, LightsService lights) {
-            mBatteryLight = lights.getLight(LightsService.LIGHT_ID_BATTERY);
-
-            mBatteryLowARGB = context.getResources().getInteger(
-                    com.android.internal.R.integer.config_notificationsBatteryLowARGB);
-            mBatteryMediumARGB = context.getResources().getInteger(
-                    com.android.internal.R.integer.config_notificationsBatteryMediumARGB);
-            mBatteryFullARGB = context.getResources().getInteger(
-                    com.android.internal.R.integer.config_notificationsBatteryFullARGB);
-            mBatteryLedOn = context.getResources().getInteger(
-                    com.android.internal.R.integer.config_notificationsBatteryLedOn);
-            mBatteryLedOff = context.getResources().getInteger(
-                    com.android.internal.R.integer.config_notificationsBatteryLedOff);
-        }
-
-        /**
-         * Synchronize on BatteryService.
-         */
-        public void updateLightsLocked() {
-            final int level = mBatteryProps.batteryLevel;
-            final int status = mBatteryProps.batteryStatus;
-            if (level < mLowBatteryWarningLevel) {
-                if (status == BatteryManager.BATTERY_STATUS_CHARGING) {
-                    // Solid red when battery is charging
-                    mBatteryLight.setColor(mBatteryLowARGB);
-                } else {
-                    // Flash red when battery is low and not charging
-                    mBatteryLight.setFlashing(mBatteryLowARGB, LightsService.LIGHT_FLASH_TIMED,
-                            mBatteryLedOn, mBatteryLedOff);
-                }
-            } else if (status == BatteryManager.BATTERY_STATUS_CHARGING
-                    || status == BatteryManager.BATTERY_STATUS_FULL) {
-                if (status == BatteryManager.BATTERY_STATUS_FULL || level >= 90) {
-                    // Solid green when full or charging and nearly full
-                    mBatteryLight.setColor(mBatteryFullARGB);
-                } else {
-                    // Solid orange when charging and halfway full
-                    mBatteryLight.setColor(mBatteryMediumARGB);
-                }
-            } else {
-                // No lights if not charging and not low
-                mBatteryLight.turnOff();
-            }
-        }
-    }
-
-    private final class BatteryListener extends IBatteryPropertiesListener.Stub {
-        public void batteryPropertiesChanged(BatteryProperties props) {
-            BatteryService.this.update(props);
-       }
-    }
-}
diff --git a/services/java/com/android/server/BootReceiver.java b/services/java/com/android/server/BootReceiver.java
deleted file mode 100644
index da1b254..0000000
--- a/services/java/com/android/server/BootReceiver.java
+++ /dev/null
@@ -1,234 +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.
- */
-
-package com.android.server;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.pm.IPackageManager;
-import android.os.Build;
-import android.os.DropBoxManager;
-import android.os.FileObserver;
-import android.os.FileUtils;
-import android.os.RecoverySystem;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemProperties;
-import android.provider.Downloads;
-import android.util.Slog;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Performs a number of miscellaneous, non-system-critical actions
- * after the system has finished booting.
- */
-public class BootReceiver extends BroadcastReceiver {
-    private static final String TAG = "BootReceiver";
-
-    // Maximum size of a logged event (files get truncated if they're longer).
-    // Give userdebug builds a larger max to capture extra debug, esp. for last_kmsg.
-    private static final int LOG_SIZE =
-        SystemProperties.getInt("ro.debuggable", 0) == 1 ? 98304 : 65536;
-
-    private static final File TOMBSTONE_DIR = new File("/data/tombstones");
-
-    // The pre-froyo package and class of the system updater, which
-    // ran in the system process.  We need to remove its packages here
-    // in order to clean up after a pre-froyo-to-froyo update.
-    private static final String OLD_UPDATER_PACKAGE =
-        "com.google.android.systemupdater";
-    private static final String OLD_UPDATER_CLASS =
-        "com.google.android.systemupdater.SystemUpdateReceiver";
-
-    // Keep a reference to the observer so the finalizer doesn't disable it.
-    private static FileObserver sTombstoneObserver = null;
-
-    @Override
-    public void onReceive(final Context context, Intent intent) {
-        // Log boot events in the background to avoid blocking the main thread with I/O
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    logBootEvents(context);
-                } catch (Exception e) {
-                    Slog.e(TAG, "Can't log boot events", e);
-                }
-                try {
-                    boolean onlyCore = false;
-                    try {
-                        onlyCore = IPackageManager.Stub.asInterface(ServiceManager.getService(
-                                "package")).isOnlyCoreApps();
-                    } catch (RemoteException e) {
-                    }
-                    if (!onlyCore) {
-                        removeOldUpdatePackages(context);
-                    }
-                } catch (Exception e) {
-                    Slog.e(TAG, "Can't remove old update packages", e);
-                }
-
-            }
-        }.start();
-    }
-
-    private void removeOldUpdatePackages(Context context) {
-        Downloads.removeAllDownloadsByPackage(context, OLD_UPDATER_PACKAGE, OLD_UPDATER_CLASS);
-    }
-
-    private void logBootEvents(Context ctx) throws IOException {
-        final DropBoxManager db = (DropBoxManager) ctx.getSystemService(Context.DROPBOX_SERVICE);
-        final SharedPreferences prefs = ctx.getSharedPreferences("log_files", Context.MODE_PRIVATE);
-        final String headers = new StringBuilder(512)
-            .append("Build: ").append(Build.FINGERPRINT).append("\n")
-            .append("Hardware: ").append(Build.BOARD).append("\n")
-            .append("Revision: ")
-            .append(SystemProperties.get("ro.revision", "")).append("\n")
-            .append("Bootloader: ").append(Build.BOOTLOADER).append("\n")
-            .append("Radio: ").append(Build.RADIO).append("\n")
-            .append("Kernel: ")
-            .append(FileUtils.readTextFile(new File("/proc/version"), 1024, "...\n"))
-            .append("\n").toString();
-
-        String recovery = RecoverySystem.handleAftermath();
-        if (recovery != null && db != null) {
-            db.addText("SYSTEM_RECOVERY_LOG", headers + recovery);
-        }
-
-        if (SystemProperties.getLong("ro.runtime.firstboot", 0) == 0) {
-            String now = Long.toString(System.currentTimeMillis());
-            SystemProperties.set("ro.runtime.firstboot", now);
-            if (db != null) db.addText("SYSTEM_BOOT", headers);
-
-            // Negative sizes mean to take the *tail* of the file (see FileUtils.readTextFile())
-            addFileToDropBox(db, prefs, headers, "/proc/last_kmsg",
-                    -LOG_SIZE, "SYSTEM_LAST_KMSG");
-            addFileToDropBox(db, prefs, headers, "/cache/recovery/log",
-                    -LOG_SIZE, "SYSTEM_RECOVERY_LOG");
-            addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_console",
-                    -LOG_SIZE, "APANIC_CONSOLE");
-            addFileToDropBox(db, prefs, headers, "/data/dontpanic/apanic_threads",
-                    -LOG_SIZE, "APANIC_THREADS");
-            addAuditErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_AUDIT");
-            addFsckErrorsToDropBox(db, prefs, headers, -LOG_SIZE, "SYSTEM_FSCK");
-        } else {
-            if (db != null) db.addText("SYSTEM_RESTART", headers);
-        }
-
-        // Scan existing tombstones (in case any new ones appeared)
-        File[] tombstoneFiles = TOMBSTONE_DIR.listFiles();
-        for (int i = 0; tombstoneFiles != null && i < tombstoneFiles.length; i++) {
-            addFileToDropBox(db, prefs, headers, tombstoneFiles[i].getPath(),
-                    LOG_SIZE, "SYSTEM_TOMBSTONE");
-        }
-
-        // Start watching for new tombstone files; will record them as they occur.
-        // This gets registered with the singleton file observer thread.
-        sTombstoneObserver = new FileObserver(TOMBSTONE_DIR.getPath(), FileObserver.CLOSE_WRITE) {
-            @Override
-            public void onEvent(int event, String path) {
-                try {
-                    String filename = new File(TOMBSTONE_DIR, path).getPath();
-                    addFileToDropBox(db, prefs, headers, filename, LOG_SIZE, "SYSTEM_TOMBSTONE");
-                } catch (IOException e) {
-                    Slog.e(TAG, "Can't log tombstone", e);
-                }
-            }
-        };
-
-        sTombstoneObserver.startWatching();
-    }
-
-    private static void addFileToDropBox(
-            DropBoxManager db, SharedPreferences prefs,
-            String headers, String filename, int maxSize, String tag) throws IOException {
-        if (db == null || !db.isTagEnabled(tag)) return;  // Logging disabled
-
-        File file = new File(filename);
-        long fileTime = file.lastModified();
-        if (fileTime <= 0) return;  // File does not exist
-
-        if (prefs != null) {
-            long lastTime = prefs.getLong(filename, 0);
-            if (lastTime == fileTime) return;  // Already logged this particular file
-            // TODO: move all these SharedPreferences Editor commits
-            // outside this function to the end of logBootEvents
-            prefs.edit().putLong(filename, fileTime).apply();
-        }
-
-        Slog.i(TAG, "Copying " + filename + " to DropBox (" + tag + ")");
-        db.addText(tag, headers + FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n"));
-    }
-
-    private static void addAuditErrorsToDropBox(DropBoxManager db,  SharedPreferences prefs,
-            String headers, int maxSize, String tag) throws IOException {
-        if (db == null || !db.isTagEnabled(tag)) return;  // Logging disabled
-        Slog.i(TAG, "Copying audit failures to DropBox");
-
-        File file = new File("/proc/last_kmsg");
-        long fileTime = file.lastModified();
-        if (fileTime <= 0) return;  // File does not exist
-
-        if (prefs != null) {
-            long lastTime = prefs.getLong(tag, 0);
-            if (lastTime == fileTime) return;  // Already logged this particular file
-            // TODO: move all these SharedPreferences Editor commits
-            // outside this function to the end of logBootEvents
-            prefs.edit().putLong(tag, fileTime).apply();
-        }
-
-        String log = FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n");
-        StringBuilder sb = new StringBuilder();
-        for (String line : log.split("\n")) {
-            if (line.contains("audit")) {
-                sb.append(line + "\n");
-            }
-        }
-        Slog.i(TAG, "Copied " + sb.toString().length() + " worth of audits to DropBox");
-        db.addText(tag, headers + sb.toString());
-    }
-
-    private static void addFsckErrorsToDropBox(DropBoxManager db,  SharedPreferences prefs,
-            String headers, int maxSize, String tag) throws IOException {
-        boolean upload_needed = false;
-        if (db == null || !db.isTagEnabled(tag)) return;  // Logging disabled
-        Slog.i(TAG, "Checking for fsck errors");
-
-        File file = new File("/dev/fscklogs/log");
-        long fileTime = file.lastModified();
-        if (fileTime <= 0) return;  // File does not exist
-
-        String log = FileUtils.readTextFile(file, maxSize, "[[TRUNCATED]]\n");
-        StringBuilder sb = new StringBuilder();
-        for (String line : log.split("\n")) {
-            if (line.contains("FILE SYSTEM WAS MODIFIED")) {
-                upload_needed = true;
-                break;
-            }
-        }
-
-        if (upload_needed) {
-            addFileToDropBox(db, prefs, headers, "/dev/fscklogs/log", maxSize, tag);
-        }
-
-        // Remove the file so we don't re-upload if the runtime restarts.
-        file.delete();
-    }
-}
diff --git a/services/java/com/android/server/ClipboardService.java b/services/java/com/android/server/ClipboardService.java
deleted file mode 100644
index 069ae23..0000000
--- a/services/java/com/android/server/ClipboardService.java
+++ /dev/null
@@ -1,366 +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.server;
-
-import android.app.ActivityManagerNative;
-import android.app.AppGlobals;
-import android.app.AppOpsManager;
-import android.app.IActivityManager;
-import android.content.BroadcastReceiver;
-import android.content.ClipData;
-import android.content.ClipDescription;
-import android.content.IClipboard;
-import android.content.IOnPrimaryClipChangedListener;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.Process;
-import android.os.RemoteCallbackList;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.util.Pair;
-import android.util.Slog;
-import android.util.SparseArray;
-
-import java.util.HashSet;
-
-/**
- * Implementation of the clipboard for copy and paste.
- */
-public class ClipboardService extends IClipboard.Stub {
-
-    private static final String TAG = "ClipboardService";
-
-    private final Context mContext;
-    private final IActivityManager mAm;
-    private final PackageManager mPm;
-    private final AppOpsManager mAppOps;
-    private final IBinder mPermissionOwner;
-
-    private class ListenerInfo {
-        final int mUid;
-        final String mPackageName;
-        ListenerInfo(int uid, String packageName) {
-            mUid = uid;
-            mPackageName = packageName;
-        }
-    }
-
-    private class PerUserClipboard {
-        final int userId;
-
-        final RemoteCallbackList<IOnPrimaryClipChangedListener> primaryClipListeners
-                = new RemoteCallbackList<IOnPrimaryClipChangedListener>();
-
-        ClipData primaryClip;
-
-        final HashSet<String> activePermissionOwners
-                = new HashSet<String>();
-
-        PerUserClipboard(int userId) {
-            this.userId = userId;
-        }
-    }
-
-    private SparseArray<PerUserClipboard> mClipboards = new SparseArray<PerUserClipboard>();
-
-    /**
-     * Instantiates the clipboard.
-     */
-    public ClipboardService(Context context) {
-        mContext = context;
-        mAm = ActivityManagerNative.getDefault();
-        mPm = context.getPackageManager();
-        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
-        IBinder permOwner = null;
-        try {
-            permOwner = mAm.newUriPermissionOwner("clipboard");
-        } catch (RemoteException e) {
-            Slog.w("clipboard", "AM dead", e);
-        }
-        mPermissionOwner = permOwner;
-
-        // Remove the clipboard if a user is removed
-        IntentFilter userFilter = new IntentFilter();
-        userFilter.addAction(Intent.ACTION_USER_REMOVED);
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                String action = intent.getAction();
-                if (Intent.ACTION_USER_REMOVED.equals(action)) {
-                    removeClipboard(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
-                }
-            }
-        }, userFilter);
-    }
-
-    @Override
-    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
-            throws RemoteException {
-        try {
-            return super.onTransact(code, data, reply, flags);
-        } catch (RuntimeException e) {
-            if (!(e instanceof SecurityException)) {
-                Slog.wtf("clipboard", "Exception: ", e);
-            }
-            throw e;
-        }
-        
-    }
-
-    private PerUserClipboard getClipboard() {
-        return getClipboard(UserHandle.getCallingUserId());
-    }
-
-    private PerUserClipboard getClipboard(int userId) {
-        synchronized (mClipboards) {
-            PerUserClipboard puc = mClipboards.get(userId);
-            if (puc == null) {
-                puc = new PerUserClipboard(userId);
-                mClipboards.put(userId, puc);
-            }
-            return puc;
-        }
-    }
-
-    private void removeClipboard(int userId) {
-        synchronized (mClipboards) {
-            mClipboards.remove(userId);
-        }
-    }
-
-    public void setPrimaryClip(ClipData clip, String callingPackage) {
-        synchronized (this) {
-            if (clip != null && clip.getItemCount() <= 0) {
-                throw new IllegalArgumentException("No items");
-            }
-            final int callingUid = Binder.getCallingUid();
-            if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, callingUid,
-                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
-                return;
-            }
-            checkDataOwnerLocked(clip, callingUid);
-            clearActiveOwnersLocked();
-            PerUserClipboard clipboard = getClipboard();
-            clipboard.primaryClip = clip;
-            final long ident = Binder.clearCallingIdentity();
-            final int n = clipboard.primaryClipListeners.beginBroadcast();
-            try {
-                for (int i = 0; i < n; i++) {
-                    try {
-                        ListenerInfo li = (ListenerInfo)
-                                clipboard.primaryClipListeners.getBroadcastCookie(i);
-                        if (mAppOps.checkOpNoThrow(AppOpsManager.OP_READ_CLIPBOARD, li.mUid,
-                                li.mPackageName) == AppOpsManager.MODE_ALLOWED) {
-                            clipboard.primaryClipListeners.getBroadcastItem(i)
-                                    .dispatchPrimaryClipChanged();
-                        }
-                    } catch (RemoteException e) {
-                        // The RemoteCallbackList will take care of removing
-                        // the dead object for us.
-                    }
-                }
-            } finally {
-                clipboard.primaryClipListeners.finishBroadcast();
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-    
-    public ClipData getPrimaryClip(String pkg) {
-        synchronized (this) {
-            if (mAppOps.noteOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
-                    pkg) != AppOpsManager.MODE_ALLOWED) {
-                return null;
-            }
-            addActiveOwnerLocked(Binder.getCallingUid(), pkg);
-            return getClipboard().primaryClip;
-        }
-    }
-
-    public ClipDescription getPrimaryClipDescription(String callingPackage) {
-        synchronized (this) {
-            if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
-                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
-                return null;
-            }
-            PerUserClipboard clipboard = getClipboard();
-            return clipboard.primaryClip != null ? clipboard.primaryClip.getDescription() : null;
-        }
-    }
-
-    public boolean hasPrimaryClip(String callingPackage) {
-        synchronized (this) {
-            if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
-                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
-                return false;
-            }
-            return getClipboard().primaryClip != null;
-        }
-    }
-
-    public void addPrimaryClipChangedListener(IOnPrimaryClipChangedListener listener,
-            String callingPackage) {
-        synchronized (this) {
-            getClipboard().primaryClipListeners.register(listener,
-                    new ListenerInfo(Binder.getCallingUid(), callingPackage));
-        }
-    }
-
-    public void removePrimaryClipChangedListener(IOnPrimaryClipChangedListener listener) {
-        synchronized (this) {
-            getClipboard().primaryClipListeners.unregister(listener);
-        }
-    }
-
-    public boolean hasClipboardText(String callingPackage) {
-        synchronized (this) {
-            if (mAppOps.checkOp(AppOpsManager.OP_READ_CLIPBOARD, Binder.getCallingUid(),
-                    callingPackage) != AppOpsManager.MODE_ALLOWED) {
-                return false;
-            }
-            PerUserClipboard clipboard = getClipboard();
-            if (clipboard.primaryClip != null) {
-                CharSequence text = clipboard.primaryClip.getItemAt(0).getText();
-                return text != null && text.length() > 0;
-            }
-            return false;
-        }
-    }
-
-    private final void checkUriOwnerLocked(Uri uri, int uid) {
-        if (!"content".equals(uri.getScheme())) {
-            return;
-        }
-        long ident = Binder.clearCallingIdentity();
-        try {
-            // This will throw SecurityException for us.
-            mAm.checkGrantUriPermission(uid, null, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-        } catch (RemoteException e) {
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private final void checkItemOwnerLocked(ClipData.Item item, int uid) {
-        if (item.getUri() != null) {
-            checkUriOwnerLocked(item.getUri(), uid);
-        }
-        Intent intent = item.getIntent();
-        if (intent != null && intent.getData() != null) {
-            checkUriOwnerLocked(intent.getData(), uid);
-        }
-    }
-
-    private final void checkDataOwnerLocked(ClipData data, int uid) {
-        final int N = data.getItemCount();
-        for (int i=0; i<N; i++) {
-            checkItemOwnerLocked(data.getItemAt(i), uid);
-        }
-    }
-
-    private final void grantUriLocked(Uri uri, String pkg) {
-        long ident = Binder.clearCallingIdentity();
-        try {
-            mAm.grantUriPermissionFromOwner(mPermissionOwner, Process.myUid(), pkg, uri,
-                    Intent.FLAG_GRANT_READ_URI_PERMISSION);
-        } catch (RemoteException e) {
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private final void grantItemLocked(ClipData.Item item, String pkg) {
-        if (item.getUri() != null) {
-            grantUriLocked(item.getUri(), pkg);
-        }
-        Intent intent = item.getIntent();
-        if (intent != null && intent.getData() != null) {
-            grantUriLocked(intent.getData(), pkg);
-        }
-    }
-
-    private final void addActiveOwnerLocked(int uid, String pkg) {
-        final IPackageManager pm = AppGlobals.getPackageManager();
-        final int targetUserHandle = UserHandle.getCallingUserId();
-        final long oldIdentity = Binder.clearCallingIdentity();
-        try {
-            PackageInfo pi = pm.getPackageInfo(pkg, 0, targetUserHandle);
-            if (pi == null) {
-                throw new IllegalArgumentException("Unknown package " + pkg);
-            }
-            if (!UserHandle.isSameApp(pi.applicationInfo.uid, uid)) {
-                throw new SecurityException("Calling uid " + uid
-                        + " does not own package " + pkg);
-            }
-        } catch (RemoteException e) {
-            // Can't happen; the package manager is in the same process
-        } finally {
-            Binder.restoreCallingIdentity(oldIdentity);
-        }
-        PerUserClipboard clipboard = getClipboard();
-        if (clipboard.primaryClip != null && !clipboard.activePermissionOwners.contains(pkg)) {
-            final int N = clipboard.primaryClip.getItemCount();
-            for (int i=0; i<N; i++) {
-                grantItemLocked(clipboard.primaryClip.getItemAt(i), pkg);
-            }
-            clipboard.activePermissionOwners.add(pkg);
-        }
-    }
-
-    private final void revokeUriLocked(Uri uri) {
-        long ident = Binder.clearCallingIdentity();
-        try {
-            mAm.revokeUriPermissionFromOwner(mPermissionOwner, uri,
-                    Intent.FLAG_GRANT_READ_URI_PERMISSION
-                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-        } catch (RemoteException e) {
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private final void revokeItemLocked(ClipData.Item item) {
-        if (item.getUri() != null) {
-            revokeUriLocked(item.getUri());
-        }
-        Intent intent = item.getIntent();
-        if (intent != null && intent.getData() != null) {
-            revokeUriLocked(intent.getData());
-        }
-    }
-
-    private final void clearActiveOwnersLocked() {
-        PerUserClipboard clipboard = getClipboard();
-        clipboard.activePermissionOwners.clear();
-        if (clipboard.primaryClip == null) {
-            return;
-        }
-        final int N = clipboard.primaryClip.getItemCount();
-        for (int i=0; i<N; i++) {
-            revokeItemLocked(clipboard.primaryClip.getItemAt(i));
-        }
-    }
-}
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
deleted file mode 100644
index e283da9..0000000
--- a/services/java/com/android/server/ConnectivityService.java
+++ /dev/null
@@ -1,5000 +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.server;
-
-import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
-import static android.Manifest.permission.RECEIVE_DATA_ACTIVITY_CHANGE;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
-import static android.net.ConnectivityManager.TYPE_BLUETOOTH;
-import static android.net.ConnectivityManager.TYPE_DUMMY;
-import static android.net.ConnectivityManager.TYPE_ETHERNET;
-import static android.net.ConnectivityManager.TYPE_MOBILE;
-import static android.net.ConnectivityManager.TYPE_WIFI;
-import static android.net.ConnectivityManager.TYPE_WIMAX;
-import static android.net.ConnectivityManager.getNetworkTypeName;
-import static android.net.ConnectivityManager.isNetworkTypeValid;
-import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
-import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
-
-import android.app.AlarmManager;
-import android.app.AppOpsManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.bluetooth.BluetoothTetheringDataTracker;
-import android.content.ActivityNotFoundException;
-import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.database.ContentObserver;
-import android.net.CaptivePortalTracker;
-import android.net.ConnectivityManager;
-import android.net.DummyDataStateTracker;
-import android.net.EthernetDataTracker;
-import android.net.IConnectivityManager;
-import android.net.INetworkManagementEventObserver;
-import android.net.INetworkPolicyListener;
-import android.net.INetworkPolicyManager;
-import android.net.INetworkStatsService;
-import android.net.LinkAddress;
-import android.net.LinkProperties;
-import android.net.LinkProperties.CompareResult;
-import android.net.LinkQualityInfo;
-import android.net.MobileDataStateTracker;
-import android.net.NetworkConfig;
-import android.net.NetworkInfo;
-import android.net.NetworkInfo.DetailedState;
-import android.net.NetworkQuotaInfo;
-import android.net.NetworkState;
-import android.net.NetworkStateTracker;
-import android.net.NetworkUtils;
-import android.net.Proxy;
-import android.net.ProxyProperties;
-import android.net.RouteInfo;
-import android.net.SamplingDataTracker;
-import android.net.Uri;
-import android.net.wifi.WifiStateTracker;
-import android.net.wimax.WimaxManagerConstants;
-import android.os.AsyncTask;
-import android.os.Binder;
-import android.os.Build;
-import android.os.FileUtils;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.INetworkManagementService;
-import android.os.Looper;
-import android.os.Message;
-import android.os.Messenger;
-import android.os.ParcelFileDescriptor;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.security.Credentials;
-import android.security.KeyStore;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-import android.util.Xml;
-
-import com.android.internal.R;
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.net.LegacyVpnInfo;
-import com.android.internal.net.VpnConfig;
-import com.android.internal.net.VpnProfile;
-import com.android.internal.telephony.DctConstants;
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.XmlUtils;
-import com.android.server.am.BatteryStatsService;
-import com.android.server.connectivity.DataConnectionStats;
-import com.android.server.connectivity.Nat464Xlat;
-import com.android.server.connectivity.PacManager;
-import com.android.server.connectivity.Tethering;
-import com.android.server.connectivity.Vpn;
-import com.android.server.net.BaseNetworkObserver;
-import com.android.server.net.LockdownVpnTracker;
-import com.google.android.collect.Lists;
-import com.google.android.collect.Sets;
-
-import dalvik.system.DexClassLoader;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.lang.reflect.Constructor;
-import java.net.HttpURLConnection;
-import java.net.Inet4Address;
-import java.net.Inet6Address;
-import java.net.InetAddress;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSession;
-
-/**
- * @hide
- */
-public class ConnectivityService extends IConnectivityManager.Stub {
-    private static final String TAG = "ConnectivityService";
-
-    private static final boolean DBG = true;
-    private static final boolean VDBG = false;
-
-    private static final boolean LOGD_RULES = false;
-
-    // TODO: create better separation between radio types and network types
-
-    // how long to wait before switching back to a radio's default network
-    private static final int RESTORE_DEFAULT_NETWORK_DELAY = 1 * 60 * 1000;
-    // system property that can override the above value
-    private static final String NETWORK_RESTORE_DELAY_PROP_NAME =
-            "android.telephony.apn-restore";
-
-    // Default value if FAIL_FAST_TIME_MS is not set
-    private static final int DEFAULT_FAIL_FAST_TIME_MS = 1 * 60 * 1000;
-    // system property that can override DEFAULT_FAIL_FAST_TIME_MS
-    private static final String FAIL_FAST_TIME_MS =
-            "persist.radio.fail_fast_time_ms";
-
-    private static final String ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED =
-            "android.net.ConnectivityService.action.PKT_CNT_SAMPLE_INTERVAL_ELAPSED";
-
-    private static final int SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE = 0;
-
-    private PendingIntent mSampleIntervalElapsedIntent;
-
-    // Set network sampling interval at 12 minutes, this way, even if the timers get
-    // aggregated, it will fire at around 15 minutes, which should allow us to
-    // aggregate this timer with other timers (specially the socket keep alive timers)
-    private static final int DEFAULT_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 12 * 60);
-
-    // start network sampling a minute after booting ...
-    private static final int DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS = (VDBG ? 30 : 60);
-
-    AlarmManager mAlarmManager;
-
-    // used in recursive route setting to add gateways for the host for which
-    // a host route was requested.
-    private static final int MAX_HOSTROUTE_CYCLE_COUNT = 10;
-
-    private Tethering mTethering;
-
-    private KeyStore mKeyStore;
-
-    @GuardedBy("mVpns")
-    private final SparseArray<Vpn> mVpns = new SparseArray<Vpn>();
-    private VpnCallback mVpnCallback = new VpnCallback();
-
-    private boolean mLockdownEnabled;
-    private LockdownVpnTracker mLockdownTracker;
-
-    private Nat464Xlat mClat;
-
-    /** Lock around {@link #mUidRules} and {@link #mMeteredIfaces}. */
-    private Object mRulesLock = new Object();
-    /** Currently active network rules by UID. */
-    private SparseIntArray mUidRules = new SparseIntArray();
-    /** Set of ifaces that are costly. */
-    private HashSet<String> mMeteredIfaces = Sets.newHashSet();
-
-    /**
-     * Sometimes we want to refer to the individual network state
-     * trackers separately, and sometimes we just want to treat them
-     * abstractly.
-     */
-    private NetworkStateTracker mNetTrackers[];
-
-    /* Handles captive portal check on a network */
-    private CaptivePortalTracker mCaptivePortalTracker;
-
-    /**
-     * The link properties that define the current links
-     */
-    private LinkProperties mCurrentLinkProperties[];
-
-    /**
-     * A per Net list of the PID's that requested access to the net
-     * used both as a refcount and for per-PID DNS selection
-     */
-    private List<Integer> mNetRequestersPids[];
-
-    // priority order of the nettrackers
-    // (excluding dynamically set mNetworkPreference)
-    // TODO - move mNetworkTypePreference into this
-    private int[] mPriorityList;
-
-    private Context mContext;
-    private int mNetworkPreference;
-    private int mActiveDefaultNetwork = -1;
-    // 0 is full bad, 100 is full good
-    private int mDefaultInetCondition = 0;
-    private int mDefaultInetConditionPublished = 0;
-    private boolean mInetConditionChangeInFlight = false;
-    private int mDefaultConnectionSequence = 0;
-
-    private Object mDnsLock = new Object();
-    private int mNumDnsEntries;
-
-    private boolean mTestMode;
-    private static ConnectivityService sServiceInstance;
-
-    private INetworkManagementService mNetd;
-    private INetworkPolicyManager mPolicyManager;
-
-    private static final int ENABLED  = 1;
-    private static final int DISABLED = 0;
-
-    private static final boolean ADD = true;
-    private static final boolean REMOVE = false;
-
-    private static final boolean TO_DEFAULT_TABLE = true;
-    private static final boolean TO_SECONDARY_TABLE = false;
-
-    private static final boolean EXEMPT = true;
-    private static final boolean UNEXEMPT = false;
-
-    /**
-     * used internally as a delayed event to make us switch back to the
-     * default network
-     */
-    private static final int EVENT_RESTORE_DEFAULT_NETWORK = 1;
-
-    /**
-     * used internally to change our mobile data enabled flag
-     */
-    private static final int EVENT_CHANGE_MOBILE_DATA_ENABLED = 2;
-
-    /**
-     * used internally to change our network preference setting
-     * arg1 = networkType to prefer
-     */
-    private static final int EVENT_SET_NETWORK_PREFERENCE = 3;
-
-    /**
-     * used internally to synchronize inet condition reports
-     * arg1 = networkType
-     * arg2 = condition (0 bad, 100 good)
-     */
-    private static final int EVENT_INET_CONDITION_CHANGE = 4;
-
-    /**
-     * used internally to mark the end of inet condition hold periods
-     * arg1 = networkType
-     */
-    private static final int EVENT_INET_CONDITION_HOLD_END = 5;
-
-    /**
-     * used internally to set enable/disable cellular data
-     * arg1 = ENBALED or DISABLED
-     */
-    private static final int EVENT_SET_MOBILE_DATA = 7;
-
-    /**
-     * used internally to clear a wakelock when transitioning
-     * from one net to another
-     */
-    private static final int EVENT_CLEAR_NET_TRANSITION_WAKELOCK = 8;
-
-    /**
-     * used internally to reload global proxy settings
-     */
-    private static final int EVENT_APPLY_GLOBAL_HTTP_PROXY = 9;
-
-    /**
-     * used internally to set external dependency met/unmet
-     * arg1 = ENABLED (met) or DISABLED (unmet)
-     * arg2 = NetworkType
-     */
-    private static final int EVENT_SET_DEPENDENCY_MET = 10;
-
-    /**
-     * used internally to send a sticky broadcast delayed.
-     */
-    private static final int EVENT_SEND_STICKY_BROADCAST_INTENT = 11;
-
-    /**
-     * Used internally to
-     * {@link NetworkStateTracker#setPolicyDataEnable(boolean)}.
-     */
-    private static final int EVENT_SET_POLICY_DATA_ENABLE = 12;
-
-    private static final int EVENT_VPN_STATE_CHANGED = 13;
-
-    /**
-     * Used internally to disable fail fast of mobile data
-     */
-    private static final int EVENT_ENABLE_FAIL_FAST_MOBILE_DATA = 14;
-
-    /**
-     * user internally to indicate that data sampling interval is up
-     */
-    private static final int EVENT_SAMPLE_INTERVAL_ELAPSED = 15;
-
-    /**
-     * PAC manager has received new port.
-     */
-    private static final int EVENT_PROXY_HAS_CHANGED = 16;
-
-    /** Handler used for internal events. */
-    private InternalHandler mHandler;
-    /** Handler used for incoming {@link NetworkStateTracker} events. */
-    private NetworkStateTrackerHandler mTrackerHandler;
-
-    // list of DeathRecipients used to make sure features are turned off when
-    // a process dies
-    private List<FeatureUser> mFeatureUsers;
-
-    private boolean mSystemReady;
-    private Intent mInitialBroadcast;
-
-    private PowerManager.WakeLock mNetTransitionWakeLock;
-    private String mNetTransitionWakeLockCausedBy = "";
-    private int mNetTransitionWakeLockSerialNumber;
-    private int mNetTransitionWakeLockTimeout;
-
-    private InetAddress mDefaultDns;
-
-    // Lock for protecting access to mAddedRoutes and mExemptAddresses
-    private final Object mRoutesLock = new Object();
-
-    // this collection is used to refcount the added routes - if there are none left
-    // it's time to remove the route from the route table
-    @GuardedBy("mRoutesLock")
-    private Collection<RouteInfo> mAddedRoutes = new ArrayList<RouteInfo>();
-
-    // this collection corresponds to the entries of mAddedRoutes that have routing exemptions
-    // used to handle cleanup of exempt rules
-    @GuardedBy("mRoutesLock")
-    private Collection<LinkAddress> mExemptAddresses = new ArrayList<LinkAddress>();
-
-    // used in DBG mode to track inet condition reports
-    private static final int INET_CONDITION_LOG_MAX_SIZE = 15;
-    private ArrayList mInetLog;
-
-    // track the current default http proxy - tell the world if we get a new one (real change)
-    private ProxyProperties mDefaultProxy = null;
-    private Object mProxyLock = new Object();
-    private boolean mDefaultProxyDisabled = false;
-
-    // track the global proxy.
-    private ProxyProperties mGlobalProxy = null;
-
-    private PacManager mPacManager = null;
-
-    private SettingsObserver mSettingsObserver;
-
-    private AppOpsManager mAppOpsManager;
-
-    NetworkConfig[] mNetConfigs;
-    int mNetworksDefined;
-
-    private static class RadioAttributes {
-        public int mSimultaneity;
-        public int mType;
-        public RadioAttributes(String init) {
-            String fragments[] = init.split(",");
-            mType = Integer.parseInt(fragments[0]);
-            mSimultaneity = Integer.parseInt(fragments[1]);
-        }
-    }
-    RadioAttributes[] mRadioAttributes;
-
-    // the set of network types that can only be enabled by system/sig apps
-    List mProtectedNetworks;
-
-    private DataConnectionStats mDataConnectionStats;
-
-    private AtomicInteger mEnableFailFastMobileDataTag = new AtomicInteger(0);
-
-    TelephonyManager mTelephonyManager;
-
-    public ConnectivityService(Context context, INetworkManagementService netd,
-            INetworkStatsService statsService, INetworkPolicyManager policyManager) {
-        // Currently, omitting a NetworkFactory will create one internally
-        // TODO: create here when we have cleaner WiMAX support
-        this(context, netd, statsService, policyManager, null);
-    }
-
-    public ConnectivityService(Context context, INetworkManagementService netManager,
-            INetworkStatsService statsService, INetworkPolicyManager policyManager,
-            NetworkFactory netFactory) {
-        if (DBG) log("ConnectivityService starting up");
-
-        HandlerThread handlerThread = new HandlerThread("ConnectivityServiceThread");
-        handlerThread.start();
-        mHandler = new InternalHandler(handlerThread.getLooper());
-        mTrackerHandler = new NetworkStateTrackerHandler(handlerThread.getLooper());
-
-        if (netFactory == null) {
-            netFactory = new DefaultNetworkFactory(context, mTrackerHandler);
-        }
-
-        // setup our unique device name
-        if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
-            String id = Settings.Secure.getString(context.getContentResolver(),
-                    Settings.Secure.ANDROID_ID);
-            if (id != null && id.length() > 0) {
-                String name = new String("android-").concat(id);
-                SystemProperties.set("net.hostname", name);
-            }
-        }
-
-        // read our default dns server ip
-        String dns = Settings.Global.getString(context.getContentResolver(),
-                Settings.Global.DEFAULT_DNS_SERVER);
-        if (dns == null || dns.length() == 0) {
-            dns = context.getResources().getString(
-                    com.android.internal.R.string.config_default_dns_server);
-        }
-        try {
-            mDefaultDns = NetworkUtils.numericToInetAddress(dns);
-        } catch (IllegalArgumentException e) {
-            loge("Error setting defaultDns using " + dns);
-        }
-
-        mContext = checkNotNull(context, "missing Context");
-        mNetd = checkNotNull(netManager, "missing INetworkManagementService");
-        mPolicyManager = checkNotNull(policyManager, "missing INetworkPolicyManager");
-        mKeyStore = KeyStore.getInstance();
-        mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
-
-        try {
-            mPolicyManager.registerListener(mPolicyListener);
-        } catch (RemoteException e) {
-            // ouch, no rules updates means some processes may never get network
-            loge("unable to register INetworkPolicyListener" + e.toString());
-        }
-
-        final PowerManager powerManager = (PowerManager) context.getSystemService(
-                Context.POWER_SERVICE);
-        mNetTransitionWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
-        mNetTransitionWakeLockTimeout = mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_networkTransitionTimeout);
-
-        mNetTrackers = new NetworkStateTracker[
-                ConnectivityManager.MAX_NETWORK_TYPE+1];
-        mCurrentLinkProperties = new LinkProperties[ConnectivityManager.MAX_NETWORK_TYPE+1];
-
-        mRadioAttributes = new RadioAttributes[ConnectivityManager.MAX_RADIO_TYPE+1];
-        mNetConfigs = new NetworkConfig[ConnectivityManager.MAX_NETWORK_TYPE+1];
-
-        // Load device network attributes from resources
-        String[] raStrings = context.getResources().getStringArray(
-                com.android.internal.R.array.radioAttributes);
-        for (String raString : raStrings) {
-            RadioAttributes r = new RadioAttributes(raString);
-            if (VDBG) log("raString=" + raString + " r=" + r);
-            if (r.mType > ConnectivityManager.MAX_RADIO_TYPE) {
-                loge("Error in radioAttributes - ignoring attempt to define type " + r.mType);
-                continue;
-            }
-            if (mRadioAttributes[r.mType] != null) {
-                loge("Error in radioAttributes - ignoring attempt to redefine type " +
-                        r.mType);
-                continue;
-            }
-            mRadioAttributes[r.mType] = r;
-        }
-
-        // TODO: What is the "correct" way to do determine if this is a wifi only device?
-        boolean wifiOnly = SystemProperties.getBoolean("ro.radio.noril", false);
-        log("wifiOnly=" + wifiOnly);
-        String[] naStrings = context.getResources().getStringArray(
-                com.android.internal.R.array.networkAttributes);
-        for (String naString : naStrings) {
-            try {
-                NetworkConfig n = new NetworkConfig(naString);
-                if (VDBG) log("naString=" + naString + " config=" + n);
-                if (n.type > ConnectivityManager.MAX_NETWORK_TYPE) {
-                    loge("Error in networkAttributes - ignoring attempt to define type " +
-                            n.type);
-                    continue;
-                }
-                if (wifiOnly && ConnectivityManager.isNetworkTypeMobile(n.type)) {
-                    log("networkAttributes - ignoring mobile as this dev is wifiOnly " +
-                            n.type);
-                    continue;
-                }
-                if (mNetConfigs[n.type] != null) {
-                    loge("Error in networkAttributes - ignoring attempt to redefine type " +
-                            n.type);
-                    continue;
-                }
-                if (mRadioAttributes[n.radio] == null) {
-                    loge("Error in networkAttributes - ignoring attempt to use undefined " +
-                            "radio " + n.radio + " in network type " + n.type);
-                    continue;
-                }
-                mNetConfigs[n.type] = n;
-                mNetworksDefined++;
-            } catch(Exception e) {
-                // ignore it - leave the entry null
-            }
-        }
-        if (VDBG) log("mNetworksDefined=" + mNetworksDefined);
-
-        mProtectedNetworks = new ArrayList<Integer>();
-        int[] protectedNetworks = context.getResources().getIntArray(
-                com.android.internal.R.array.config_protectedNetworks);
-        for (int p : protectedNetworks) {
-            if ((mNetConfigs[p] != null) && (mProtectedNetworks.contains(p) == false)) {
-                mProtectedNetworks.add(p);
-            } else {
-                if (DBG) loge("Ignoring protectedNetwork " + p);
-            }
-        }
-
-        // high priority first
-        mPriorityList = new int[mNetworksDefined];
-        {
-            int insertionPoint = mNetworksDefined-1;
-            int currentLowest = 0;
-            int nextLowest = 0;
-            while (insertionPoint > -1) {
-                for (NetworkConfig na : mNetConfigs) {
-                    if (na == null) continue;
-                    if (na.priority < currentLowest) continue;
-                    if (na.priority > currentLowest) {
-                        if (na.priority < nextLowest || nextLowest == 0) {
-                            nextLowest = na.priority;
-                        }
-                        continue;
-                    }
-                    mPriorityList[insertionPoint--] = na.type;
-                }
-                currentLowest = nextLowest;
-                nextLowest = 0;
-            }
-        }
-
-        // Update mNetworkPreference according to user mannually first then overlay config.xml
-        mNetworkPreference = getPersistedNetworkPreference();
-        if (mNetworkPreference == -1) {
-            for (int n : mPriorityList) {
-                if (mNetConfigs[n].isDefault() && ConnectivityManager.isNetworkTypeValid(n)) {
-                    mNetworkPreference = n;
-                    break;
-                }
-            }
-            if (mNetworkPreference == -1) {
-                throw new IllegalStateException(
-                        "You should set at least one default Network in config.xml!");
-            }
-        }
-
-        mNetRequestersPids =
-                (List<Integer> [])new ArrayList[ConnectivityManager.MAX_NETWORK_TYPE+1];
-        for (int i : mPriorityList) {
-            mNetRequestersPids[i] = new ArrayList<Integer>();
-        }
-
-        mFeatureUsers = new ArrayList<FeatureUser>();
-
-        mTestMode = SystemProperties.get("cm.test.mode").equals("true")
-                && SystemProperties.get("ro.build.type").equals("eng");
-
-        // Create and start trackers for hard-coded networks
-        for (int targetNetworkType : mPriorityList) {
-            final NetworkConfig config = mNetConfigs[targetNetworkType];
-            final NetworkStateTracker tracker;
-            try {
-                tracker = netFactory.createTracker(targetNetworkType, config);
-                mNetTrackers[targetNetworkType] = tracker;
-            } catch (IllegalArgumentException e) {
-                Slog.e(TAG, "Problem creating " + getNetworkTypeName(targetNetworkType)
-                        + " tracker: " + e);
-                continue;
-            }
-
-            tracker.startMonitoring(context, mTrackerHandler);
-            if (config.isDefault()) {
-                tracker.reconnect();
-            }
-        }
-
-        mTethering = new Tethering(mContext, mNetd, statsService, this, mHandler.getLooper());
-
-        //set up the listener for user state for creating user VPNs
-        IntentFilter intentFilter = new IntentFilter();
-        intentFilter.addAction(Intent.ACTION_USER_STARTING);
-        intentFilter.addAction(Intent.ACTION_USER_STOPPING);
-        mContext.registerReceiverAsUser(
-                mUserIntentReceiver, UserHandle.ALL, intentFilter, null, null);
-        mClat = new Nat464Xlat(mContext, mNetd, this, mTrackerHandler);
-
-        try {
-            mNetd.registerObserver(mTethering);
-            mNetd.registerObserver(mDataActivityObserver);
-            mNetd.registerObserver(mClat);
-        } catch (RemoteException e) {
-            loge("Error registering observer :" + e);
-        }
-
-        if (DBG) {
-            mInetLog = new ArrayList();
-        }
-
-        mSettingsObserver = new SettingsObserver(mHandler, EVENT_APPLY_GLOBAL_HTTP_PROXY);
-        mSettingsObserver.observe(mContext);
-
-        mDataConnectionStats = new DataConnectionStats(mContext);
-        mDataConnectionStats.startMonitoring();
-
-        // start network sampling ..
-        Intent intent = new Intent(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED, null);
-        mSampleIntervalElapsedIntent = PendingIntent.getBroadcast(mContext,
-                SAMPLE_INTERVAL_ELAPSED_REQUEST_CODE, intent, 0);
-
-        mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
-        setAlarm(DEFAULT_START_SAMPLING_INTERVAL_IN_SECONDS * 1000, mSampleIntervalElapsedIntent);
-
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED);
-        mContext.registerReceiver(
-                new BroadcastReceiver() {
-                    @Override
-                    public void onReceive(Context context, Intent intent) {
-                        String action = intent.getAction();
-                        if (action.equals(ACTION_PKT_CNT_SAMPLE_INTERVAL_ELAPSED)) {
-                            mHandler.sendMessage(mHandler.obtainMessage
-                                    (EVENT_SAMPLE_INTERVAL_ELAPSED));
-                        }
-                    }
-                },
-                new IntentFilter(filter));
-
-        mPacManager = new PacManager(mContext, mHandler, EVENT_PROXY_HAS_CHANGED);
-
-        filter = new IntentFilter();
-        filter.addAction(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
-        mContext.registerReceiver(mProvisioningReceiver, filter);
-
-        mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
-    }
-
-    /**
-     * Factory that creates {@link NetworkStateTracker} instances using given
-     * {@link NetworkConfig}.
-     */
-    public interface NetworkFactory {
-        public NetworkStateTracker createTracker(int targetNetworkType, NetworkConfig config);
-    }
-
-    private static class DefaultNetworkFactory implements NetworkFactory {
-        private final Context mContext;
-        private final Handler mTrackerHandler;
-
-        public DefaultNetworkFactory(Context context, Handler trackerHandler) {
-            mContext = context;
-            mTrackerHandler = trackerHandler;
-        }
-
-        @Override
-        public NetworkStateTracker createTracker(int targetNetworkType, NetworkConfig config) {
-            switch (config.radio) {
-                case TYPE_WIFI:
-                    return new WifiStateTracker(targetNetworkType, config.name);
-                case TYPE_MOBILE:
-                    return new MobileDataStateTracker(targetNetworkType, config.name);
-                case TYPE_DUMMY:
-                    return new DummyDataStateTracker(targetNetworkType, config.name);
-                case TYPE_BLUETOOTH:
-                    return BluetoothTetheringDataTracker.getInstance();
-                case TYPE_WIMAX:
-                    return makeWimaxStateTracker(mContext, mTrackerHandler);
-                case TYPE_ETHERNET:
-                    return EthernetDataTracker.getInstance();
-                default:
-                    throw new IllegalArgumentException(
-                            "Trying to create a NetworkStateTracker for an unknown radio type: "
-                            + config.radio);
-            }
-        }
-    }
-
-    /**
-     * Loads external WiMAX library and registers as system service, returning a
-     * {@link NetworkStateTracker} for WiMAX. Caller is still responsible for
-     * invoking {@link NetworkStateTracker#startMonitoring(Context, Handler)}.
-     */
-    private static NetworkStateTracker makeWimaxStateTracker(
-            Context context, Handler trackerHandler) {
-        // Initialize Wimax
-        DexClassLoader wimaxClassLoader;
-        Class wimaxStateTrackerClass = null;
-        Class wimaxServiceClass = null;
-        Class wimaxManagerClass;
-        String wimaxJarLocation;
-        String wimaxLibLocation;
-        String wimaxManagerClassName;
-        String wimaxServiceClassName;
-        String wimaxStateTrackerClassName;
-
-        NetworkStateTracker wimaxStateTracker = null;
-
-        boolean isWimaxEnabled = context.getResources().getBoolean(
-                com.android.internal.R.bool.config_wimaxEnabled);
-
-        if (isWimaxEnabled) {
-            try {
-                wimaxJarLocation = context.getResources().getString(
-                        com.android.internal.R.string.config_wimaxServiceJarLocation);
-                wimaxLibLocation = context.getResources().getString(
-                        com.android.internal.R.string.config_wimaxNativeLibLocation);
-                wimaxManagerClassName = context.getResources().getString(
-                        com.android.internal.R.string.config_wimaxManagerClassname);
-                wimaxServiceClassName = context.getResources().getString(
-                        com.android.internal.R.string.config_wimaxServiceClassname);
-                wimaxStateTrackerClassName = context.getResources().getString(
-                        com.android.internal.R.string.config_wimaxStateTrackerClassname);
-
-                if (DBG) log("wimaxJarLocation: " + wimaxJarLocation);
-                wimaxClassLoader =  new DexClassLoader(wimaxJarLocation,
-                        new ContextWrapper(context).getCacheDir().getAbsolutePath(),
-                        wimaxLibLocation, ClassLoader.getSystemClassLoader());
-
-                try {
-                    wimaxManagerClass = wimaxClassLoader.loadClass(wimaxManagerClassName);
-                    wimaxStateTrackerClass = wimaxClassLoader.loadClass(wimaxStateTrackerClassName);
-                    wimaxServiceClass = wimaxClassLoader.loadClass(wimaxServiceClassName);
-                } catch (ClassNotFoundException ex) {
-                    loge("Exception finding Wimax classes: " + ex.toString());
-                    return null;
-                }
-            } catch(Resources.NotFoundException ex) {
-                loge("Wimax Resources does not exist!!! ");
-                return null;
-            }
-
-            try {
-                if (DBG) log("Starting Wimax Service... ");
-
-                Constructor wmxStTrkrConst = wimaxStateTrackerClass.getConstructor
-                        (new Class[] {Context.class, Handler.class});
-                wimaxStateTracker = (NetworkStateTracker) wmxStTrkrConst.newInstance(
-                        context, trackerHandler);
-
-                Constructor wmxSrvConst = wimaxServiceClass.getDeclaredConstructor
-                        (new Class[] {Context.class, wimaxStateTrackerClass});
-                wmxSrvConst.setAccessible(true);
-                IBinder svcInvoker = (IBinder)wmxSrvConst.newInstance(context, wimaxStateTracker);
-                wmxSrvConst.setAccessible(false);
-
-                ServiceManager.addService(WimaxManagerConstants.WIMAX_SERVICE, svcInvoker);
-
-            } catch(Exception ex) {
-                loge("Exception creating Wimax classes: " + ex.toString());
-                return null;
-            }
-        } else {
-            loge("Wimax is not enabled or not added to the network attributes!!! ");
-            return null;
-        }
-
-        return wimaxStateTracker;
-    }
-
-    /**
-     * Sets the preferred network.
-     * @param preference the new preference
-     */
-    public void setNetworkPreference(int preference) {
-        enforceChangePermission();
-
-        mHandler.sendMessage(
-                mHandler.obtainMessage(EVENT_SET_NETWORK_PREFERENCE, preference, 0));
-    }
-
-    public int getNetworkPreference() {
-        enforceAccessPermission();
-        int preference;
-        synchronized(this) {
-            preference = mNetworkPreference;
-        }
-        return preference;
-    }
-
-    private void handleSetNetworkPreference(int preference) {
-        if (ConnectivityManager.isNetworkTypeValid(preference) &&
-                mNetConfigs[preference] != null &&
-                mNetConfigs[preference].isDefault()) {
-            if (mNetworkPreference != preference) {
-                final ContentResolver cr = mContext.getContentResolver();
-                Settings.Global.putInt(cr, Settings.Global.NETWORK_PREFERENCE, preference);
-                synchronized(this) {
-                    mNetworkPreference = preference;
-                }
-                enforcePreference();
-            }
-        }
-    }
-
-    private int getConnectivityChangeDelay() {
-        final ContentResolver cr = mContext.getContentResolver();
-
-        /** Check system properties for the default value then use secure settings value, if any. */
-        int defaultDelay = SystemProperties.getInt(
-                "conn." + Settings.Global.CONNECTIVITY_CHANGE_DELAY,
-                ConnectivityManager.CONNECTIVITY_CHANGE_DELAY_DEFAULT);
-        return Settings.Global.getInt(cr, Settings.Global.CONNECTIVITY_CHANGE_DELAY,
-                defaultDelay);
-    }
-
-    private int getPersistedNetworkPreference() {
-        final ContentResolver cr = mContext.getContentResolver();
-
-        final int networkPrefSetting = Settings.Global
-                .getInt(cr, Settings.Global.NETWORK_PREFERENCE, -1);
-
-        return networkPrefSetting;
-    }
-
-    /**
-     * Make the state of network connectivity conform to the preference settings
-     * In this method, we only tear down a non-preferred network. Establishing
-     * a connection to the preferred network is taken care of when we handle
-     * the disconnect event from the non-preferred network
-     * (see {@link #handleDisconnect(NetworkInfo)}).
-     */
-    private void enforcePreference() {
-        if (mNetTrackers[mNetworkPreference].getNetworkInfo().isConnected())
-            return;
-
-        if (!mNetTrackers[mNetworkPreference].isAvailable())
-            return;
-
-        for (int t=0; t <= ConnectivityManager.MAX_RADIO_TYPE; t++) {
-            if (t != mNetworkPreference && mNetTrackers[t] != null &&
-                    mNetTrackers[t].getNetworkInfo().isConnected()) {
-                if (DBG) {
-                    log("tearing down " + mNetTrackers[t].getNetworkInfo() +
-                            " in enforcePreference");
-                }
-                teardown(mNetTrackers[t]);
-            }
-        }
-    }
-
-    private boolean teardown(NetworkStateTracker netTracker) {
-        if (netTracker.teardown()) {
-            netTracker.setTeardownRequested(true);
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Check if UID should be blocked from using the network represented by the
-     * given {@link NetworkStateTracker}.
-     */
-    private boolean isNetworkBlocked(NetworkStateTracker tracker, int uid) {
-        final String iface = tracker.getLinkProperties().getInterfaceName();
-
-        final boolean networkCostly;
-        final int uidRules;
-        synchronized (mRulesLock) {
-            networkCostly = mMeteredIfaces.contains(iface);
-            uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
-        }
-
-        if (networkCostly && (uidRules & RULE_REJECT_METERED) != 0) {
-            return true;
-        }
-
-        // no restrictive rules; network is visible
-        return false;
-    }
-
-    /**
-     * Return a filtered {@link NetworkInfo}, potentially marked
-     * {@link DetailedState#BLOCKED} based on
-     * {@link #isNetworkBlocked(NetworkStateTracker, int)}.
-     */
-    private NetworkInfo getFilteredNetworkInfo(NetworkStateTracker tracker, int uid) {
-        NetworkInfo info = tracker.getNetworkInfo();
-        if (isNetworkBlocked(tracker, uid)) {
-            // network is blocked; clone and override state
-            info = new NetworkInfo(info);
-            info.setDetailedState(DetailedState.BLOCKED, null, null);
-        }
-        if (mLockdownTracker != null) {
-            info = mLockdownTracker.augmentNetworkInfo(info);
-        }
-        return info;
-    }
-
-    /**
-     * Return NetworkInfo for the active (i.e., connected) network interface.
-     * It is assumed that at most one network is active at a time. If more
-     * than one is active, it is indeterminate which will be returned.
-     * @return the info for the active network, or {@code null} if none is
-     * active
-     */
-    @Override
-    public NetworkInfo getActiveNetworkInfo() {
-        enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
-        return getNetworkInfo(mActiveDefaultNetwork, uid);
-    }
-
-    /**
-     * Find the first Provisioning network.
-     *
-     * @return NetworkInfo or null if none.
-     */
-    private NetworkInfo getProvisioningNetworkInfo() {
-        enforceAccessPermission();
-
-        // Find the first Provisioning Network
-        NetworkInfo provNi = null;
-        for (NetworkInfo ni : getAllNetworkInfo()) {
-            if (ni.isConnectedToProvisioningNetwork()) {
-                provNi = ni;
-                break;
-            }
-        }
-        if (DBG) log("getProvisioningNetworkInfo: X provNi=" + provNi);
-        return provNi;
-    }
-
-    /**
-     * Find the first Provisioning network or the ActiveDefaultNetwork
-     * if there is no Provisioning network
-     *
-     * @return NetworkInfo or null if none.
-     */
-    @Override
-    public NetworkInfo getProvisioningOrActiveNetworkInfo() {
-        enforceAccessPermission();
-
-        NetworkInfo provNi = getProvisioningNetworkInfo();
-        if (provNi == null) {
-            final int uid = Binder.getCallingUid();
-            provNi = getNetworkInfo(mActiveDefaultNetwork, uid);
-        }
-        if (DBG) log("getProvisioningOrActiveNetworkInfo: X provNi=" + provNi);
-        return provNi;
-    }
-
-    public NetworkInfo getActiveNetworkInfoUnfiltered() {
-        enforceAccessPermission();
-        if (isNetworkTypeValid(mActiveDefaultNetwork)) {
-            final NetworkStateTracker tracker = mNetTrackers[mActiveDefaultNetwork];
-            if (tracker != null) {
-                return tracker.getNetworkInfo();
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public NetworkInfo getActiveNetworkInfoForUid(int uid) {
-        enforceConnectivityInternalPermission();
-        return getNetworkInfo(mActiveDefaultNetwork, uid);
-    }
-
-    @Override
-    public NetworkInfo getNetworkInfo(int networkType) {
-        enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
-        return getNetworkInfo(networkType, uid);
-    }
-
-    private NetworkInfo getNetworkInfo(int networkType, int uid) {
-        NetworkInfo info = null;
-        if (isNetworkTypeValid(networkType)) {
-            final NetworkStateTracker tracker = mNetTrackers[networkType];
-            if (tracker != null) {
-                info = getFilteredNetworkInfo(tracker, uid);
-            }
-        }
-        return info;
-    }
-
-    @Override
-    public NetworkInfo[] getAllNetworkInfo() {
-        enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
-        final ArrayList<NetworkInfo> result = Lists.newArrayList();
-        synchronized (mRulesLock) {
-            for (NetworkStateTracker tracker : mNetTrackers) {
-                if (tracker != null) {
-                    result.add(getFilteredNetworkInfo(tracker, uid));
-                }
-            }
-        }
-        return result.toArray(new NetworkInfo[result.size()]);
-    }
-
-    @Override
-    public boolean isNetworkSupported(int networkType) {
-        enforceAccessPermission();
-        return (isNetworkTypeValid(networkType) && (mNetTrackers[networkType] != null));
-    }
-
-    /**
-     * Return LinkProperties for the active (i.e., connected) default
-     * network interface.  It is assumed that at most one default network
-     * is active at a time. If more than one is active, it is indeterminate
-     * which will be returned.
-     * @return the ip properties for the active network, or {@code null} if
-     * none is active
-     */
-    @Override
-    public LinkProperties getActiveLinkProperties() {
-        return getLinkProperties(mActiveDefaultNetwork);
-    }
-
-    @Override
-    public LinkProperties getLinkProperties(int networkType) {
-        enforceAccessPermission();
-        if (isNetworkTypeValid(networkType)) {
-            final NetworkStateTracker tracker = mNetTrackers[networkType];
-            if (tracker != null) {
-                return tracker.getLinkProperties();
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public NetworkState[] getAllNetworkState() {
-        enforceAccessPermission();
-        final int uid = Binder.getCallingUid();
-        final ArrayList<NetworkState> result = Lists.newArrayList();
-        synchronized (mRulesLock) {
-            for (NetworkStateTracker tracker : mNetTrackers) {
-                if (tracker != null) {
-                    final NetworkInfo info = getFilteredNetworkInfo(tracker, uid);
-                    result.add(new NetworkState(
-                            info, tracker.getLinkProperties(), tracker.getLinkCapabilities()));
-                }
-            }
-        }
-        return result.toArray(new NetworkState[result.size()]);
-    }
-
-    private NetworkState getNetworkStateUnchecked(int networkType) {
-        if (isNetworkTypeValid(networkType)) {
-            final NetworkStateTracker tracker = mNetTrackers[networkType];
-            if (tracker != null) {
-                return new NetworkState(tracker.getNetworkInfo(), tracker.getLinkProperties(),
-                        tracker.getLinkCapabilities());
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public NetworkQuotaInfo getActiveNetworkQuotaInfo() {
-        enforceAccessPermission();
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            final NetworkState state = getNetworkStateUnchecked(mActiveDefaultNetwork);
-            if (state != null) {
-                try {
-                    return mPolicyManager.getNetworkQuotaInfo(state);
-                } catch (RemoteException e) {
-                }
-            }
-            return null;
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override
-    public boolean isActiveNetworkMetered() {
-        enforceAccessPermission();
-        final long token = Binder.clearCallingIdentity();
-        try {
-            return isNetworkMeteredUnchecked(mActiveDefaultNetwork);
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private boolean isNetworkMeteredUnchecked(int networkType) {
-        final NetworkState state = getNetworkStateUnchecked(networkType);
-        if (state != null) {
-            try {
-                return mPolicyManager.isNetworkMetered(state);
-            } catch (RemoteException e) {
-            }
-        }
-        return false;
-    }
-
-    public boolean setRadios(boolean turnOn) {
-        boolean result = true;
-        enforceChangePermission();
-        for (NetworkStateTracker t : mNetTrackers) {
-            if (t != null) result = t.setRadio(turnOn) && result;
-        }
-        return result;
-    }
-
-    public boolean setRadio(int netType, boolean turnOn) {
-        enforceChangePermission();
-        if (!ConnectivityManager.isNetworkTypeValid(netType)) {
-            return false;
-        }
-        NetworkStateTracker tracker = mNetTrackers[netType];
-        return tracker != null && tracker.setRadio(turnOn);
-    }
-
-    private INetworkManagementEventObserver mDataActivityObserver = new BaseNetworkObserver() {
-        @Override
-        public void interfaceClassDataActivityChanged(String label, boolean active) {
-            int deviceType = Integer.parseInt(label);
-            sendDataActivityBroadcast(deviceType, active);
-        }
-    };
-
-    /**
-     * Used to notice when the calling process dies so we can self-expire
-     *
-     * Also used to know if the process has cleaned up after itself when
-     * our auto-expire timer goes off.  The timer has a link to an object.
-     *
-     */
-    private class FeatureUser implements IBinder.DeathRecipient {
-        int mNetworkType;
-        String mFeature;
-        IBinder mBinder;
-        int mPid;
-        int mUid;
-        long mCreateTime;
-
-        FeatureUser(int type, String feature, IBinder binder) {
-            super();
-            mNetworkType = type;
-            mFeature = feature;
-            mBinder = binder;
-            mPid = getCallingPid();
-            mUid = getCallingUid();
-            mCreateTime = System.currentTimeMillis();
-
-            try {
-                mBinder.linkToDeath(this, 0);
-            } catch (RemoteException e) {
-                binderDied();
-            }
-        }
-
-        void unlinkDeathRecipient() {
-            mBinder.unlinkToDeath(this, 0);
-        }
-
-        public void binderDied() {
-            log("ConnectivityService FeatureUser binderDied(" +
-                    mNetworkType + ", " + mFeature + ", " + mBinder + "), created " +
-                    (System.currentTimeMillis() - mCreateTime) + " mSec ago");
-            stopUsingNetworkFeature(this, false);
-        }
-
-        public void expire() {
-            if (VDBG) {
-                log("ConnectivityService FeatureUser expire(" +
-                        mNetworkType + ", " + mFeature + ", " + mBinder +"), created " +
-                        (System.currentTimeMillis() - mCreateTime) + " mSec ago");
-            }
-            stopUsingNetworkFeature(this, false);
-        }
-
-        public boolean isSameUser(FeatureUser u) {
-            if (u == null) return false;
-
-            return isSameUser(u.mPid, u.mUid, u.mNetworkType, u.mFeature);
-        }
-
-        public boolean isSameUser(int pid, int uid, int networkType, String feature) {
-            if ((mPid == pid) && (mUid == uid) && (mNetworkType == networkType) &&
-                TextUtils.equals(mFeature, feature)) {
-                return true;
-            }
-            return false;
-        }
-
-        public String toString() {
-            return "FeatureUser("+mNetworkType+","+mFeature+","+mPid+","+mUid+"), created " +
-                    (System.currentTimeMillis() - mCreateTime) + " mSec ago";
-        }
-    }
-
-    // javadoc from interface
-    public int startUsingNetworkFeature(int networkType, String feature,
-            IBinder binder) {
-        long startTime = 0;
-        if (DBG) {
-            startTime = SystemClock.elapsedRealtime();
-        }
-        if (VDBG) {
-            log("startUsingNetworkFeature for net " + networkType + ": " + feature + ", uid="
-                    + Binder.getCallingUid());
-        }
-        enforceChangePermission();
-        try {
-            if (!ConnectivityManager.isNetworkTypeValid(networkType) ||
-                    mNetConfigs[networkType] == null) {
-                return PhoneConstants.APN_REQUEST_FAILED;
-            }
-
-            FeatureUser f = new FeatureUser(networkType, feature, binder);
-
-            // TODO - move this into individual networktrackers
-            int usedNetworkType = convertFeatureToNetworkType(networkType, feature);
-
-            if (mLockdownEnabled) {
-                // Since carrier APNs usually aren't available from VPN
-                // endpoint, mark them as unavailable.
-                return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
-            }
-
-            if (mProtectedNetworks.contains(usedNetworkType)) {
-                enforceConnectivityInternalPermission();
-            }
-
-            // if UID is restricted, don't allow them to bring up metered APNs
-            final boolean networkMetered = isNetworkMeteredUnchecked(usedNetworkType);
-            final int uidRules;
-            synchronized (mRulesLock) {
-                uidRules = mUidRules.get(Binder.getCallingUid(), RULE_ALLOW_ALL);
-            }
-            if (networkMetered && (uidRules & RULE_REJECT_METERED) != 0) {
-                return PhoneConstants.APN_REQUEST_FAILED;
-            }
-
-            NetworkStateTracker network = mNetTrackers[usedNetworkType];
-            if (network != null) {
-                Integer currentPid = new Integer(getCallingPid());
-                if (usedNetworkType != networkType) {
-                    NetworkInfo ni = network.getNetworkInfo();
-
-                    if (ni.isAvailable() == false) {
-                        if (!TextUtils.equals(feature,Phone.FEATURE_ENABLE_DUN_ALWAYS)) {
-                            if (DBG) log("special network not available ni=" + ni.getTypeName());
-                            return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
-                        } else {
-                            // else make the attempt anyway - probably giving REQUEST_STARTED below
-                            if (DBG) {
-                                log("special network not available, but try anyway ni=" +
-                                        ni.getTypeName());
-                            }
-                        }
-                    }
-
-                    int restoreTimer = getRestoreDefaultNetworkDelay(usedNetworkType);
-
-                    synchronized(this) {
-                        boolean addToList = true;
-                        if (restoreTimer < 0) {
-                            // In case there is no timer is specified for the feature,
-                            // make sure we don't add duplicate entry with the same request.
-                            for (FeatureUser u : mFeatureUsers) {
-                                if (u.isSameUser(f)) {
-                                    // Duplicate user is found. Do not add.
-                                    addToList = false;
-                                    break;
-                                }
-                            }
-                        }
-
-                        if (addToList) mFeatureUsers.add(f);
-                        if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
-                            // this gets used for per-pid dns when connected
-                            mNetRequestersPids[usedNetworkType].add(currentPid);
-                        }
-                    }
-
-                    if (restoreTimer >= 0) {
-                        mHandler.sendMessageDelayed(mHandler.obtainMessage(
-                                EVENT_RESTORE_DEFAULT_NETWORK, f), restoreTimer);
-                    }
-
-                    if ((ni.isConnectedOrConnecting() == true) &&
-                            !network.isTeardownRequested()) {
-                        if (ni.isConnected() == true) {
-                            final long token = Binder.clearCallingIdentity();
-                            try {
-                                // add the pid-specific dns
-                                handleDnsConfigurationChange(usedNetworkType);
-                                if (VDBG) log("special network already active");
-                            } finally {
-                                Binder.restoreCallingIdentity(token);
-                            }
-                            return PhoneConstants.APN_ALREADY_ACTIVE;
-                        }
-                        if (VDBG) log("special network already connecting");
-                        return PhoneConstants.APN_REQUEST_STARTED;
-                    }
-
-                    // check if the radio in play can make another contact
-                    // assume if cannot for now
-
-                    if (DBG) {
-                        log("startUsingNetworkFeature reconnecting to " + networkType + ": " +
-                                feature);
-                    }
-                    if (network.reconnect()) {
-                        if (DBG) log("startUsingNetworkFeature X: return APN_REQUEST_STARTED");
-                        return PhoneConstants.APN_REQUEST_STARTED;
-                    } else {
-                        if (DBG) log("startUsingNetworkFeature X: return APN_REQUEST_FAILED");
-                        return PhoneConstants.APN_REQUEST_FAILED;
-                    }
-                } else {
-                    // need to remember this unsupported request so we respond appropriately on stop
-                    synchronized(this) {
-                        mFeatureUsers.add(f);
-                        if (!mNetRequestersPids[usedNetworkType].contains(currentPid)) {
-                            // this gets used for per-pid dns when connected
-                            mNetRequestersPids[usedNetworkType].add(currentPid);
-                        }
-                    }
-                    if (DBG) log("startUsingNetworkFeature X: return -1 unsupported feature.");
-                    return -1;
-                }
-            }
-            if (DBG) log("startUsingNetworkFeature X: return APN_TYPE_NOT_AVAILABLE");
-            return PhoneConstants.APN_TYPE_NOT_AVAILABLE;
-         } finally {
-            if (DBG) {
-                final long execTime = SystemClock.elapsedRealtime() - startTime;
-                if (execTime > 250) {
-                    loge("startUsingNetworkFeature took too long: " + execTime + "ms");
-                } else {
-                    if (VDBG) log("startUsingNetworkFeature took " + execTime + "ms");
-                }
-            }
-         }
-    }
-
-    // javadoc from interface
-    public int stopUsingNetworkFeature(int networkType, String feature) {
-        enforceChangePermission();
-
-        int pid = getCallingPid();
-        int uid = getCallingUid();
-
-        FeatureUser u = null;
-        boolean found = false;
-
-        synchronized(this) {
-            for (FeatureUser x : mFeatureUsers) {
-                if (x.isSameUser(pid, uid, networkType, feature)) {
-                    u = x;
-                    found = true;
-                    break;
-                }
-            }
-        }
-        if (found && u != null) {
-            if (VDBG) log("stopUsingNetworkFeature: X");
-            // stop regardless of how many other time this proc had called start
-            return stopUsingNetworkFeature(u, true);
-        } else {
-            // none found!
-            if (VDBG) log("stopUsingNetworkFeature: X not a live request, ignoring");
-            return 1;
-        }
-    }
-
-    private int stopUsingNetworkFeature(FeatureUser u, boolean ignoreDups) {
-        int networkType = u.mNetworkType;
-        String feature = u.mFeature;
-        int pid = u.mPid;
-        int uid = u.mUid;
-
-        NetworkStateTracker tracker = null;
-        boolean callTeardown = false;  // used to carry our decision outside of sync block
-
-        if (VDBG) {
-            log("stopUsingNetworkFeature: net " + networkType + ": " + feature);
-        }
-
-        if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
-            if (DBG) {
-                log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
-                        ", net is invalid");
-            }
-            return -1;
-        }
-
-        // need to link the mFeatureUsers list with the mNetRequestersPids state in this
-        // sync block
-        synchronized(this) {
-            // check if this process still has an outstanding start request
-            if (!mFeatureUsers.contains(u)) {
-                if (VDBG) {
-                    log("stopUsingNetworkFeature: this process has no outstanding requests" +
-                        ", ignoring");
-                }
-                return 1;
-            }
-            u.unlinkDeathRecipient();
-            mFeatureUsers.remove(mFeatureUsers.indexOf(u));
-            // If we care about duplicate requests, check for that here.
-            //
-            // This is done to support the extension of a request - the app
-            // can request we start the network feature again and renew the
-            // auto-shutoff delay.  Normal "stop" calls from the app though
-            // do not pay attention to duplicate requests - in effect the
-            // API does not refcount and a single stop will counter multiple starts.
-            if (ignoreDups == false) {
-                for (FeatureUser x : mFeatureUsers) {
-                    if (x.isSameUser(u)) {
-                        if (VDBG) log("stopUsingNetworkFeature: dup is found, ignoring");
-                        return 1;
-                    }
-                }
-            }
-
-            // TODO - move to individual network trackers
-            int usedNetworkType = convertFeatureToNetworkType(networkType, feature);
-
-            tracker =  mNetTrackers[usedNetworkType];
-            if (tracker == null) {
-                if (DBG) {
-                    log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
-                            " no known tracker for used net type " + usedNetworkType);
-                }
-                return -1;
-            }
-            if (usedNetworkType != networkType) {
-                Integer currentPid = new Integer(pid);
-                mNetRequestersPids[usedNetworkType].remove(currentPid);
-
-                final long token = Binder.clearCallingIdentity();
-                try {
-                    reassessPidDns(pid, true);
-                } finally {
-                    Binder.restoreCallingIdentity(token);
-                }
-                flushVmDnsCache();
-                if (mNetRequestersPids[usedNetworkType].size() != 0) {
-                    if (VDBG) {
-                        log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
-                                " others still using it");
-                    }
-                    return 1;
-                }
-                callTeardown = true;
-            } else {
-                if (DBG) {
-                    log("stopUsingNetworkFeature: net " + networkType + ": " + feature +
-                            " not a known feature - dropping");
-                }
-            }
-        }
-
-        if (callTeardown) {
-            if (DBG) {
-                log("stopUsingNetworkFeature: teardown net " + networkType + ": " + feature);
-            }
-            tracker.teardown();
-            return 1;
-        } else {
-            return -1;
-        }
-    }
-
-    /**
-     * Check if the address falls into any of currently running VPN's route's.
-     */
-    private boolean isAddressUnderVpn(InetAddress address) {
-        synchronized (mVpns) {
-            synchronized (mRoutesLock) {
-                int uid = UserHandle.getCallingUserId();
-                Vpn vpn = mVpns.get(uid);
-                if (vpn == null) {
-                    return false;
-                }
-
-                // Check if an exemption exists for this address.
-                for (LinkAddress destination : mExemptAddresses) {
-                    if (!NetworkUtils.addressTypeMatches(address, destination.getAddress())) {
-                        continue;
-                    }
-
-                    int prefix = destination.getNetworkPrefixLength();
-                    InetAddress addrMasked = NetworkUtils.getNetworkPart(address, prefix);
-                    InetAddress destMasked = NetworkUtils.getNetworkPart(destination.getAddress(),
-                            prefix);
-
-                    if (addrMasked.equals(destMasked)) {
-                        return false;
-                    }
-                }
-
-                // Finally check if the address is covered by the VPN.
-                return vpn.isAddressCovered(address);
-            }
-        }
-    }
-
-    /**
-     * @deprecated use requestRouteToHostAddress instead
-     *
-     * Ensure that a network route exists to deliver traffic to the specified
-     * host via the specified network interface.
-     * @param networkType the type of the network over which traffic to the
-     * specified host is to be routed
-     * @param hostAddress the IP address of the host to which the route is
-     * desired
-     * @return {@code true} on success, {@code false} on failure
-     */
-    public boolean requestRouteToHost(int networkType, int hostAddress, String packageName) {
-        InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress);
-
-        if (inetAddress == null) {
-            return false;
-        }
-
-        return requestRouteToHostAddress(networkType, inetAddress.getAddress(), packageName);
-    }
-
-    /**
-     * Ensure that a network route exists to deliver traffic to the specified
-     * host via the specified network interface.
-     * @param networkType the type of the network over which traffic to the
-     * specified host is to be routed
-     * @param hostAddress the IP address of the host to which the route is
-     * desired
-     * @return {@code true} on success, {@code false} on failure
-     */
-    public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress,
-            String packageName) {
-        enforceChangePermission();
-        if (mProtectedNetworks.contains(networkType)) {
-            enforceConnectivityInternalPermission();
-        }
-        boolean exempt;
-        InetAddress addr;
-        try {
-            addr = InetAddress.getByAddress(hostAddress);
-        } catch (UnknownHostException e) {
-            if (DBG) log("requestRouteToHostAddress got " + e.toString());
-            return false;
-        }
-        // System apps may request routes bypassing the VPN to keep other networks working.
-        if (Binder.getCallingUid() == Process.SYSTEM_UID) {
-            exempt = true;
-        } else {
-            mAppOpsManager.checkPackage(Binder.getCallingUid(), packageName);
-            try {
-                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(packageName,
-                        0);
-                exempt = (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-            } catch (NameNotFoundException e) {
-                throw new IllegalArgumentException("Failed to find calling package details", e);
-            }
-        }
-
-        // Non-exempt routeToHost's can only be added if the host is not covered by the VPN.
-        // This can be either because the VPN's routes do not cover the destination or a
-        // system application added an exemption that covers this destination.
-        if (!exempt && isAddressUnderVpn(addr)) {
-            return false;
-        }
-
-        if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
-            if (DBG) log("requestRouteToHostAddress on invalid network: " + networkType);
-            return false;
-        }
-        NetworkStateTracker tracker = mNetTrackers[networkType];
-        DetailedState netState = tracker.getNetworkInfo().getDetailedState();
-
-        if (tracker == null || (netState != DetailedState.CONNECTED &&
-                netState != DetailedState.CAPTIVE_PORTAL_CHECK) ||
-                tracker.isTeardownRequested()) {
-            if (VDBG) {
-                log("requestRouteToHostAddress on down network "
-                        + "(" + networkType + ") - dropped"
-                        + " tracker=" + tracker
-                        + " netState=" + netState
-                        + " isTeardownRequested="
-                            + ((tracker != null) ? tracker.isTeardownRequested() : "tracker:null"));
-            }
-            return false;
-        }
-        final long token = Binder.clearCallingIdentity();
-        try {
-            LinkProperties lp = tracker.getLinkProperties();
-            boolean ok = addRouteToAddress(lp, addr, exempt);
-            if (DBG) log("requestRouteToHostAddress ok=" + ok);
-            return ok;
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private boolean addRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable,
-            boolean exempt) {
-        return modifyRoute(p, r, 0, ADD, toDefaultTable, exempt);
-    }
-
-    private boolean removeRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable) {
-        return modifyRoute(p, r, 0, REMOVE, toDefaultTable, UNEXEMPT);
-    }
-
-    private boolean addRouteToAddress(LinkProperties lp, InetAddress addr, boolean exempt) {
-        return modifyRouteToAddress(lp, addr, ADD, TO_DEFAULT_TABLE, exempt);
-    }
-
-    private boolean removeRouteToAddress(LinkProperties lp, InetAddress addr) {
-        return modifyRouteToAddress(lp, addr, REMOVE, TO_DEFAULT_TABLE, UNEXEMPT);
-    }
-
-    private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd,
-            boolean toDefaultTable, boolean exempt) {
-        RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getAllRoutes(), addr);
-        if (bestRoute == null) {
-            bestRoute = RouteInfo.makeHostRoute(addr, lp.getInterfaceName());
-        } else {
-            String iface = bestRoute.getInterface();
-            if (bestRoute.getGateway().equals(addr)) {
-                // if there is no better route, add the implied hostroute for our gateway
-                bestRoute = RouteInfo.makeHostRoute(addr, iface);
-            } else {
-                // if we will connect to this through another route, add a direct route
-                // to it's gateway
-                bestRoute = RouteInfo.makeHostRoute(addr, bestRoute.getGateway(), iface);
-            }
-        }
-        return modifyRoute(lp, bestRoute, 0, doAdd, toDefaultTable, exempt);
-    }
-
-    private boolean modifyRoute(LinkProperties lp, RouteInfo r, int cycleCount, boolean doAdd,
-            boolean toDefaultTable, boolean exempt) {
-        if ((lp == null) || (r == null)) {
-            if (DBG) log("modifyRoute got unexpected null: " + lp + ", " + r);
-            return false;
-        }
-
-        if (cycleCount > MAX_HOSTROUTE_CYCLE_COUNT) {
-            loge("Error modifying route - too much recursion");
-            return false;
-        }
-
-        String ifaceName = r.getInterface();
-        if(ifaceName == null) {
-            loge("Error modifying route - no interface name");
-            return false;
-        }
-        if (r.hasGateway()) {
-            RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getAllRoutes(), r.getGateway());
-            if (bestRoute != null) {
-                if (bestRoute.getGateway().equals(r.getGateway())) {
-                    // if there is no better route, add the implied hostroute for our gateway
-                    bestRoute = RouteInfo.makeHostRoute(r.getGateway(), ifaceName);
-                } else {
-                    // if we will connect to our gateway through another route, add a direct
-                    // route to it's gateway
-                    bestRoute = RouteInfo.makeHostRoute(r.getGateway(),
-                                                        bestRoute.getGateway(),
-                                                        ifaceName);
-                }
-                modifyRoute(lp, bestRoute, cycleCount+1, doAdd, toDefaultTable, exempt);
-            }
-        }
-        if (doAdd) {
-            if (VDBG) log("Adding " + r + " for interface " + ifaceName);
-            try {
-                if (toDefaultTable) {
-                    synchronized (mRoutesLock) {
-                        // only track default table - only one apps can effect
-                        mAddedRoutes.add(r);
-                        mNetd.addRoute(ifaceName, r);
-                        if (exempt) {
-                            LinkAddress dest = r.getDestination();
-                            if (!mExemptAddresses.contains(dest)) {
-                                mNetd.setHostExemption(dest);
-                                mExemptAddresses.add(dest);
-                            }
-                        }
-                    }
-                } else {
-                    mNetd.addSecondaryRoute(ifaceName, r);
-                }
-            } catch (Exception e) {
-                // never crash - catch them all
-                if (DBG) loge("Exception trying to add a route: " + e);
-                return false;
-            }
-        } else {
-            // if we remove this one and there are no more like it, then refcount==0 and
-            // we can remove it from the table
-            if (toDefaultTable) {
-                synchronized (mRoutesLock) {
-                    mAddedRoutes.remove(r);
-                    if (mAddedRoutes.contains(r) == false) {
-                        if (VDBG) log("Removing " + r + " for interface " + ifaceName);
-                        try {
-                            mNetd.removeRoute(ifaceName, r);
-                            LinkAddress dest = r.getDestination();
-                            if (mExemptAddresses.contains(dest)) {
-                                mNetd.clearHostExemption(dest);
-                                mExemptAddresses.remove(dest);
-                            }
-                        } catch (Exception e) {
-                            // never crash - catch them all
-                            if (VDBG) loge("Exception trying to remove a route: " + e);
-                            return false;
-                        }
-                    } else {
-                        if (VDBG) log("not removing " + r + " as it's still in use");
-                    }
-                }
-            } else {
-                if (VDBG) log("Removing " + r + " for interface " + ifaceName);
-                try {
-                    mNetd.removeSecondaryRoute(ifaceName, r);
-                } catch (Exception e) {
-                    // never crash - catch them all
-                    if (VDBG) loge("Exception trying to remove a route: " + e);
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-    /**
-     * @see ConnectivityManager#getMobileDataEnabled()
-     */
-    public boolean getMobileDataEnabled() {
-        // TODO: This detail should probably be in DataConnectionTracker's
-        //       which is where we store the value and maybe make this
-        //       asynchronous.
-        enforceAccessPermission();
-        boolean retVal = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.MOBILE_DATA, 1) == 1;
-        if (VDBG) log("getMobileDataEnabled returning " + retVal);
-        return retVal;
-    }
-
-    public void setDataDependency(int networkType, boolean met) {
-        enforceConnectivityInternalPermission();
-
-        mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_DEPENDENCY_MET,
-                (met ? ENABLED : DISABLED), networkType));
-    }
-
-    private void handleSetDependencyMet(int networkType, boolean met) {
-        if (mNetTrackers[networkType] != null) {
-            if (DBG) {
-                log("handleSetDependencyMet(" + networkType + ", " + met + ")");
-            }
-            mNetTrackers[networkType].setDependencyMet(met);
-        }
-    }
-
-    private INetworkPolicyListener mPolicyListener = new INetworkPolicyListener.Stub() {
-        @Override
-        public void onUidRulesChanged(int uid, int uidRules) {
-            // caller is NPMS, since we only register with them
-            if (LOGD_RULES) {
-                log("onUidRulesChanged(uid=" + uid + ", uidRules=" + uidRules + ")");
-            }
-
-            synchronized (mRulesLock) {
-                // skip update when we've already applied rules
-                final int oldRules = mUidRules.get(uid, RULE_ALLOW_ALL);
-                if (oldRules == uidRules) return;
-
-                mUidRules.put(uid, uidRules);
-            }
-
-            // TODO: notify UID when it has requested targeted updates
-        }
-
-        @Override
-        public void onMeteredIfacesChanged(String[] meteredIfaces) {
-            // caller is NPMS, since we only register with them
-            if (LOGD_RULES) {
-                log("onMeteredIfacesChanged(ifaces=" + Arrays.toString(meteredIfaces) + ")");
-            }
-
-            synchronized (mRulesLock) {
-                mMeteredIfaces.clear();
-                for (String iface : meteredIfaces) {
-                    mMeteredIfaces.add(iface);
-                }
-            }
-        }
-
-        @Override
-        public void onRestrictBackgroundChanged(boolean restrictBackground) {
-            // caller is NPMS, since we only register with them
-            if (LOGD_RULES) {
-                log("onRestrictBackgroundChanged(restrictBackground=" + restrictBackground + ")");
-            }
-
-            // kick off connectivity change broadcast for active network, since
-            // global background policy change is radical.
-            final int networkType = mActiveDefaultNetwork;
-            if (isNetworkTypeValid(networkType)) {
-                final NetworkStateTracker tracker = mNetTrackers[networkType];
-                if (tracker != null) {
-                    final NetworkInfo info = tracker.getNetworkInfo();
-                    if (info != null && info.isConnected()) {
-                        sendConnectedBroadcast(info);
-                    }
-                }
-            }
-        }
-    };
-
-    /**
-     * @see ConnectivityManager#setMobileDataEnabled(boolean)
-     */
-    public void setMobileDataEnabled(boolean enabled) {
-        enforceChangePermission();
-        if (DBG) log("setMobileDataEnabled(" + enabled + ")");
-
-        mHandler.sendMessage(mHandler.obtainMessage(EVENT_SET_MOBILE_DATA,
-                (enabled ? ENABLED : DISABLED), 0));
-    }
-
-    private void handleSetMobileData(boolean enabled) {
-        if (mNetTrackers[ConnectivityManager.TYPE_MOBILE] != null) {
-            if (VDBG) {
-                log(mNetTrackers[ConnectivityManager.TYPE_MOBILE].toString() + enabled);
-            }
-            mNetTrackers[ConnectivityManager.TYPE_MOBILE].setUserDataEnable(enabled);
-        }
-        if (mNetTrackers[ConnectivityManager.TYPE_WIMAX] != null) {
-            if (VDBG) {
-                log(mNetTrackers[ConnectivityManager.TYPE_WIMAX].toString() + enabled);
-            }
-            mNetTrackers[ConnectivityManager.TYPE_WIMAX].setUserDataEnable(enabled);
-        }
-    }
-
-    @Override
-    public void setPolicyDataEnable(int networkType, boolean enabled) {
-        // only someone like NPMS should only be calling us
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        mHandler.sendMessage(mHandler.obtainMessage(
-                EVENT_SET_POLICY_DATA_ENABLE, networkType, (enabled ? ENABLED : DISABLED)));
-    }
-
-    private void handleSetPolicyDataEnable(int networkType, boolean enabled) {
-        if (isNetworkTypeValid(networkType)) {
-            final NetworkStateTracker tracker = mNetTrackers[networkType];
-            if (tracker != null) {
-                tracker.setPolicyDataEnable(enabled);
-            }
-        }
-    }
-
-    private void enforceAccessPermission() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.ACCESS_NETWORK_STATE,
-                "ConnectivityService");
-    }
-
-    private void enforceChangePermission() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.CHANGE_NETWORK_STATE,
-                "ConnectivityService");
-    }
-
-    // TODO Make this a special check when it goes public
-    private void enforceTetherChangePermission() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.CHANGE_NETWORK_STATE,
-                "ConnectivityService");
-    }
-
-    private void enforceTetherAccessPermission() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.ACCESS_NETWORK_STATE,
-                "ConnectivityService");
-    }
-
-    private void enforceConnectivityInternalPermission() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.CONNECTIVITY_INTERNAL,
-                "ConnectivityService");
-    }
-
-    private void enforceMarkNetworkSocketPermission() {
-        //Media server special case
-        if (Binder.getCallingUid() == Process.MEDIA_UID) {
-            return;
-        }
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.MARK_NETWORK_SOCKET,
-                "ConnectivityService");
-    }
-
-    /**
-     * Handle a {@code DISCONNECTED} event. If this pertains to the non-active
-     * network, we ignore it. If it is for the active network, we send out a
-     * broadcast. But first, we check whether it might be possible to connect
-     * to a different network.
-     * @param info the {@code NetworkInfo} for the network
-     */
-    private void handleDisconnect(NetworkInfo info) {
-
-        int prevNetType = info.getType();
-
-        mNetTrackers[prevNetType].setTeardownRequested(false);
-
-        // Remove idletimer previously setup in {@code handleConnect}
-        removeDataActivityTracking(prevNetType);
-
-        /*
-         * If the disconnected network is not the active one, then don't report
-         * this as a loss of connectivity. What probably happened is that we're
-         * getting the disconnect for a network that we explicitly disabled
-         * in accordance with network preference policies.
-         */
-        if (!mNetConfigs[prevNetType].isDefault()) {
-            List<Integer> pids = mNetRequestersPids[prevNetType];
-            for (Integer pid : pids) {
-                // will remove them because the net's no longer connected
-                // need to do this now as only now do we know the pids and
-                // can properly null things that are no longer referenced.
-                reassessPidDns(pid.intValue(), false);
-            }
-        }
-
-        Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
-        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
-        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
-        if (info.isFailover()) {
-            intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
-            info.setFailover(false);
-        }
-        if (info.getReason() != null) {
-            intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
-        }
-        if (info.getExtraInfo() != null) {
-            intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
-                    info.getExtraInfo());
-        }
-
-        if (mNetConfigs[prevNetType].isDefault()) {
-            tryFailover(prevNetType);
-            if (mActiveDefaultNetwork != -1) {
-                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
-                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
-            } else {
-                mDefaultInetConditionPublished = 0; // we're not connected anymore
-                intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
-            }
-        }
-        intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
-
-        // Reset interface if no other connections are using the same interface
-        boolean doReset = true;
-        LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties();
-        if (linkProperties != null) {
-            String oldIface = linkProperties.getInterfaceName();
-            if (TextUtils.isEmpty(oldIface) == false) {
-                for (NetworkStateTracker networkStateTracker : mNetTrackers) {
-                    if (networkStateTracker == null) continue;
-                    NetworkInfo networkInfo = networkStateTracker.getNetworkInfo();
-                    if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) {
-                        LinkProperties l = networkStateTracker.getLinkProperties();
-                        if (l == null) continue;
-                        if (oldIface.equals(l.getInterfaceName())) {
-                            doReset = false;
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-
-        // do this before we broadcast the change
-        handleConnectivityChange(prevNetType, doReset);
-
-        final Intent immediateIntent = new Intent(intent);
-        immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
-        sendStickyBroadcast(immediateIntent);
-        sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
-        /*
-         * If the failover network is already connected, then immediately send
-         * out a followup broadcast indicating successful failover
-         */
-        if (mActiveDefaultNetwork != -1) {
-            sendConnectedBroadcastDelayed(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo(),
-                    getConnectivityChangeDelay());
-        }
-    }
-
-    private void tryFailover(int prevNetType) {
-        /*
-         * If this is a default network, check if other defaults are available.
-         * Try to reconnect on all available and let them hash it out when
-         * more than one connects.
-         */
-        if (mNetConfigs[prevNetType].isDefault()) {
-            if (mActiveDefaultNetwork == prevNetType) {
-                if (DBG) {
-                    log("tryFailover: set mActiveDefaultNetwork=-1, prevNetType=" + prevNetType);
-                }
-                mActiveDefaultNetwork = -1;
-            }
-
-            // don't signal a reconnect for anything lower or equal priority than our
-            // current connected default
-            // TODO - don't filter by priority now - nice optimization but risky
-//            int currentPriority = -1;
-//            if (mActiveDefaultNetwork != -1) {
-//                currentPriority = mNetConfigs[mActiveDefaultNetwork].mPriority;
-//            }
-
-            for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
-                if (checkType == prevNetType) continue;
-                if (mNetConfigs[checkType] == null) continue;
-                if (!mNetConfigs[checkType].isDefault()) continue;
-                if (mNetTrackers[checkType] == null) continue;
-
-// Enabling the isAvailable() optimization caused mobile to not get
-// selected if it was in the middle of error handling. Specifically
-// a moble connection that took 30 seconds to complete the DEACTIVATE_DATA_CALL
-// would not be available and we wouldn't get connected to anything.
-// So removing the isAvailable() optimization below for now. TODO: This
-// optimization should work and we need to investigate why it doesn't work.
-// This could be related to how DEACTIVATE_DATA_CALL is reporting its
-// complete before it is really complete.
-
-//                if (!mNetTrackers[checkType].isAvailable()) continue;
-
-//                if (currentPriority >= mNetConfigs[checkType].mPriority) continue;
-
-                NetworkStateTracker checkTracker = mNetTrackers[checkType];
-                NetworkInfo checkInfo = checkTracker.getNetworkInfo();
-                if (!checkInfo.isConnectedOrConnecting() || checkTracker.isTeardownRequested()) {
-                    checkInfo.setFailover(true);
-                    checkTracker.reconnect();
-                }
-                if (DBG) log("Attempting to switch to " + checkInfo.getTypeName());
-            }
-        }
-    }
-
-    public void sendConnectedBroadcast(NetworkInfo info) {
-        enforceConnectivityInternalPermission();
-        sendGeneralBroadcast(info, CONNECTIVITY_ACTION_IMMEDIATE);
-        sendGeneralBroadcast(info, CONNECTIVITY_ACTION);
-    }
-
-    private void sendConnectedBroadcastDelayed(NetworkInfo info, int delayMs) {
-        sendGeneralBroadcast(info, CONNECTIVITY_ACTION_IMMEDIATE);
-        sendGeneralBroadcastDelayed(info, CONNECTIVITY_ACTION, delayMs);
-    }
-
-    private void sendInetConditionBroadcast(NetworkInfo info) {
-        sendGeneralBroadcast(info, ConnectivityManager.INET_CONDITION_ACTION);
-    }
-
-    private Intent makeGeneralIntent(NetworkInfo info, String bcastType) {
-        if (mLockdownTracker != null) {
-            info = mLockdownTracker.augmentNetworkInfo(info);
-        }
-
-        Intent intent = new Intent(bcastType);
-        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
-        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
-        if (info.isFailover()) {
-            intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
-            info.setFailover(false);
-        }
-        if (info.getReason() != null) {
-            intent.putExtra(ConnectivityManager.EXTRA_REASON, info.getReason());
-        }
-        if (info.getExtraInfo() != null) {
-            intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO,
-                    info.getExtraInfo());
-        }
-        intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
-        return intent;
-    }
-
-    private void sendGeneralBroadcast(NetworkInfo info, String bcastType) {
-        sendStickyBroadcast(makeGeneralIntent(info, bcastType));
-    }
-
-    private void sendGeneralBroadcastDelayed(NetworkInfo info, String bcastType, int delayMs) {
-        sendStickyBroadcastDelayed(makeGeneralIntent(info, bcastType), delayMs);
-    }
-
-    private void sendDataActivityBroadcast(int deviceType, boolean active) {
-        Intent intent = new Intent(ConnectivityManager.ACTION_DATA_ACTIVITY_CHANGE);
-        intent.putExtra(ConnectivityManager.EXTRA_DEVICE_TYPE, deviceType);
-        intent.putExtra(ConnectivityManager.EXTRA_IS_ACTIVE, active);
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL,
-                    RECEIVE_DATA_ACTIVITY_CHANGE, null, null, 0, null, null);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    /**
-     * Called when an attempt to fail over to another network has failed.
-     * @param info the {@link NetworkInfo} for the failed network
-     */
-    private void handleConnectionFailure(NetworkInfo info) {
-        mNetTrackers[info.getType()].setTeardownRequested(false);
-
-        String reason = info.getReason();
-        String extraInfo = info.getExtraInfo();
-
-        String reasonText;
-        if (reason == null) {
-            reasonText = ".";
-        } else {
-            reasonText = " (" + reason + ").";
-        }
-        loge("Attempt to connect to " + info.getTypeName() + " failed" + reasonText);
-
-        Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
-        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_INFO, new NetworkInfo(info));
-        intent.putExtra(ConnectivityManager.EXTRA_NETWORK_TYPE, info.getType());
-        if (getActiveNetworkInfo() == null) {
-            intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
-        }
-        if (reason != null) {
-            intent.putExtra(ConnectivityManager.EXTRA_REASON, reason);
-        }
-        if (extraInfo != null) {
-            intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, extraInfo);
-        }
-        if (info.isFailover()) {
-            intent.putExtra(ConnectivityManager.EXTRA_IS_FAILOVER, true);
-            info.setFailover(false);
-        }
-
-        if (mNetConfigs[info.getType()].isDefault()) {
-            tryFailover(info.getType());
-            if (mActiveDefaultNetwork != -1) {
-                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
-                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
-            } else {
-                mDefaultInetConditionPublished = 0;
-                intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
-            }
-        }
-
-        intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
-
-        final Intent immediateIntent = new Intent(intent);
-        immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
-        sendStickyBroadcast(immediateIntent);
-        sendStickyBroadcast(intent);
-        /*
-         * If the failover network is already connected, then immediately send
-         * out a followup broadcast indicating successful failover
-         */
-        if (mActiveDefaultNetwork != -1) {
-            sendConnectedBroadcast(mNetTrackers[mActiveDefaultNetwork].getNetworkInfo());
-        }
-    }
-
-    private void sendStickyBroadcast(Intent intent) {
-        synchronized(this) {
-            if (!mSystemReady) {
-                mInitialBroadcast = new Intent(intent);
-            }
-            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-            if (VDBG) {
-                log("sendStickyBroadcast: action=" + intent.getAction());
-            }
-
-            final long ident = Binder.clearCallingIdentity();
-            try {
-                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    private void sendStickyBroadcastDelayed(Intent intent, int delayMs) {
-        if (delayMs <= 0) {
-            sendStickyBroadcast(intent);
-        } else {
-            if (VDBG) {
-                log("sendStickyBroadcastDelayed: delayMs=" + delayMs + ", action="
-                        + intent.getAction());
-            }
-            mHandler.sendMessageDelayed(mHandler.obtainMessage(
-                    EVENT_SEND_STICKY_BROADCAST_INTENT, intent), delayMs);
-        }
-    }
-
-    void systemReady() {
-        mCaptivePortalTracker = CaptivePortalTracker.makeCaptivePortalTracker(mContext, this);
-        loadGlobalProxy();
-
-        synchronized(this) {
-            mSystemReady = true;
-            if (mInitialBroadcast != null) {
-                mContext.sendStickyBroadcastAsUser(mInitialBroadcast, UserHandle.ALL);
-                mInitialBroadcast = null;
-            }
-        }
-        // load the global proxy at startup
-        mHandler.sendMessage(mHandler.obtainMessage(EVENT_APPLY_GLOBAL_HTTP_PROXY));
-
-        // Try bringing up tracker, but if KeyStore isn't ready yet, wait
-        // for user to unlock device.
-        if (!updateLockdownVpn()) {
-            final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT);
-            mContext.registerReceiver(mUserPresentReceiver, filter);
-        }
-    }
-
-    private BroadcastReceiver mUserPresentReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // Try creating lockdown tracker, since user present usually means
-            // unlocked keystore.
-            if (updateLockdownVpn()) {
-                mContext.unregisterReceiver(this);
-            }
-        }
-    };
-
-    private boolean isNewNetTypePreferredOverCurrentNetType(int type) {
-        if (((type != mNetworkPreference)
-                      && (mNetConfigs[mActiveDefaultNetwork].priority > mNetConfigs[type].priority))
-                   || (mNetworkPreference == mActiveDefaultNetwork)) {
-            return false;
-        }
-        return true;
-    }
-
-    private void handleConnect(NetworkInfo info) {
-        final int newNetType = info.getType();
-
-        setupDataActivityTracking(newNetType);
-
-        // snapshot isFailover, because sendConnectedBroadcast() resets it
-        boolean isFailover = info.isFailover();
-        final NetworkStateTracker thisNet = mNetTrackers[newNetType];
-        final String thisIface = thisNet.getLinkProperties().getInterfaceName();
-
-        if (VDBG) {
-            log("handleConnect: E newNetType=" + newNetType + " thisIface=" + thisIface
-                    + " isFailover" + isFailover);
-        }
-
-        // if this is a default net and other default is running
-        // kill the one not preferred
-        if (mNetConfigs[newNetType].isDefault()) {
-            if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != newNetType) {
-                if (isNewNetTypePreferredOverCurrentNetType(newNetType)) {
-                    // tear down the other
-                    NetworkStateTracker otherNet =
-                            mNetTrackers[mActiveDefaultNetwork];
-                    if (DBG) {
-                        log("Policy requires " + otherNet.getNetworkInfo().getTypeName() +
-                            " teardown");
-                    }
-                    if (!teardown(otherNet)) {
-                        loge("Network declined teardown request");
-                        teardown(thisNet);
-                        return;
-                    }
-                } else {
-                       // don't accept this one
-                        if (VDBG) {
-                            log("Not broadcasting CONNECT_ACTION " +
-                                "to torn down network " + info.getTypeName());
-                        }
-                        teardown(thisNet);
-                        return;
-                }
-            }
-            synchronized (ConnectivityService.this) {
-                // have a new default network, release the transition wakelock in a second
-                // if it's held.  The second pause is to allow apps to reconnect over the
-                // new network
-                if (mNetTransitionWakeLock.isHeld()) {
-                    mHandler.sendMessageDelayed(mHandler.obtainMessage(
-                            EVENT_CLEAR_NET_TRANSITION_WAKELOCK,
-                            mNetTransitionWakeLockSerialNumber, 0),
-                            1000);
-                }
-            }
-            mActiveDefaultNetwork = newNetType;
-            // this will cause us to come up initially as unconnected and switching
-            // to connected after our normal pause unless somebody reports us as reall
-            // disconnected
-            mDefaultInetConditionPublished = 0;
-            mDefaultConnectionSequence++;
-            mInetConditionChangeInFlight = false;
-            // Don't do this - if we never sign in stay, grey
-            //reportNetworkCondition(mActiveDefaultNetwork, 100);
-            updateNetworkSettings(thisNet);
-        }
-        thisNet.setTeardownRequested(false);
-        updateMtuSizeSettings(thisNet);
-        handleConnectivityChange(newNetType, false);
-        sendConnectedBroadcastDelayed(info, getConnectivityChangeDelay());
-
-        // notify battery stats service about this network
-        if (thisIface != null) {
-            try {
-                BatteryStatsService.getService().noteNetworkInterfaceType(thisIface, newNetType);
-            } catch (RemoteException e) {
-                // ignored; service lives in system_server
-            }
-        }
-    }
-
-    private void handleCaptivePortalTrackerCheck(NetworkInfo info) {
-        if (DBG) log("Captive portal check " + info);
-        int type = info.getType();
-        final NetworkStateTracker thisNet = mNetTrackers[type];
-        if (mNetConfigs[type].isDefault()) {
-            if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
-                if (isNewNetTypePreferredOverCurrentNetType(type)) {
-                    if (DBG) log("Captive check on " + info.getTypeName());
-                    mCaptivePortalTracker.detectCaptivePortal(new NetworkInfo(info));
-                    return;
-                } else {
-                    if (DBG) log("Tear down low priority net " + info.getTypeName());
-                    teardown(thisNet);
-                    return;
-                }
-            }
-        }
-
-        if (DBG) log("handleCaptivePortalTrackerCheck: call captivePortalCheckComplete ni=" + info);
-        thisNet.captivePortalCheckComplete();
-    }
-
-    /** @hide */
-    @Override
-    public void captivePortalCheckComplete(NetworkInfo info) {
-        enforceConnectivityInternalPermission();
-        if (DBG) log("captivePortalCheckComplete: ni=" + info);
-        mNetTrackers[info.getType()].captivePortalCheckComplete();
-    }
-
-    /** @hide */
-    @Override
-    public void captivePortalCheckCompleted(NetworkInfo info, boolean isCaptivePortal) {
-        enforceConnectivityInternalPermission();
-        if (DBG) log("captivePortalCheckCompleted: ni=" + info + " captive=" + isCaptivePortal);
-        mNetTrackers[info.getType()].captivePortalCheckCompleted(isCaptivePortal);
-    }
-
-    /**
-     * Setup data activity tracking for the given network interface.
-     *
-     * Every {@code setupDataActivityTracking} should be paired with a
-     * {@link removeDataActivityTracking} for cleanup.
-     */
-    private void setupDataActivityTracking(int type) {
-        final NetworkStateTracker thisNet = mNetTrackers[type];
-        final String iface = thisNet.getLinkProperties().getInterfaceName();
-
-        final int timeout;
-
-        if (ConnectivityManager.isNetworkTypeMobile(type)) {
-            timeout = Settings.Global.getInt(mContext.getContentResolver(),
-                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE,
-                                             0);
-            // Canonicalize mobile network type
-            type = ConnectivityManager.TYPE_MOBILE;
-        } else if (ConnectivityManager.TYPE_WIFI == type) {
-            timeout = Settings.Global.getInt(mContext.getContentResolver(),
-                                             Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI,
-                                             0);
-        } else {
-            // do not track any other networks
-            timeout = 0;
-        }
-
-        if (timeout > 0 && iface != null) {
-            try {
-                mNetd.addIdleTimer(iface, timeout, Integer.toString(type));
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    /**
-     * Remove data activity tracking when network disconnects.
-     */
-    private void removeDataActivityTracking(int type) {
-        final NetworkStateTracker net = mNetTrackers[type];
-        final String iface = net.getLinkProperties().getInterfaceName();
-
-        if (iface != null && (ConnectivityManager.isNetworkTypeMobile(type) ||
-                              ConnectivityManager.TYPE_WIFI == type)) {
-            try {
-                // the call fails silently if no idletimer setup for this interface
-                mNetd.removeIdleTimer(iface);
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    /**
-     * After a change in the connectivity state of a network. We're mainly
-     * concerned with making sure that the list of DNS servers is set up
-     * according to which networks are connected, and ensuring that the
-     * right routing table entries exist.
-     */
-    private void handleConnectivityChange(int netType, boolean doReset) {
-        int resetMask = doReset ? NetworkUtils.RESET_ALL_ADDRESSES : 0;
-        boolean exempt = ConnectivityManager.isNetworkTypeExempt(netType);
-        if (VDBG) {
-            log("handleConnectivityChange: netType=" + netType + " doReset=" + doReset
-                    + " resetMask=" + resetMask);
-        }
-
-        /*
-         * If a non-default network is enabled, add the host routes that
-         * will allow it's DNS servers to be accessed.
-         */
-        handleDnsConfigurationChange(netType);
-
-        LinkProperties curLp = mCurrentLinkProperties[netType];
-        LinkProperties newLp = null;
-
-        if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
-            newLp = mNetTrackers[netType].getLinkProperties();
-            if (VDBG) {
-                log("handleConnectivityChange: changed linkProperty[" + netType + "]:" +
-                        " doReset=" + doReset + " resetMask=" + resetMask +
-                        "\n   curLp=" + curLp +
-                        "\n   newLp=" + newLp);
-            }
-
-            if (curLp != null) {
-                if (curLp.isIdenticalInterfaceName(newLp)) {
-                    CompareResult<LinkAddress> car = curLp.compareAddresses(newLp);
-                    if ((car.removed.size() != 0) || (car.added.size() != 0)) {
-                        for (LinkAddress linkAddr : car.removed) {
-                            if (linkAddr.getAddress() instanceof Inet4Address) {
-                                resetMask |= NetworkUtils.RESET_IPV4_ADDRESSES;
-                            }
-                            if (linkAddr.getAddress() instanceof Inet6Address) {
-                                resetMask |= NetworkUtils.RESET_IPV6_ADDRESSES;
-                            }
-                        }
-                        if (DBG) {
-                            log("handleConnectivityChange: addresses changed" +
-                                    " linkProperty[" + netType + "]:" + " resetMask=" + resetMask +
-                                    "\n   car=" + car);
-                        }
-                    } else {
-                        if (DBG) {
-                            log("handleConnectivityChange: address are the same reset per doReset" +
-                                   " linkProperty[" + netType + "]:" +
-                                   " resetMask=" + resetMask);
-                        }
-                    }
-                } else {
-                    resetMask = NetworkUtils.RESET_ALL_ADDRESSES;
-                    if (DBG) {
-                        log("handleConnectivityChange: interface not not equivalent reset both" +
-                                " linkProperty[" + netType + "]:" +
-                                " resetMask=" + resetMask);
-                    }
-                }
-            }
-            if (mNetConfigs[netType].isDefault()) {
-                handleApplyDefaultProxy(newLp.getHttpProxy());
-            }
-        } else {
-            if (VDBG) {
-                log("handleConnectivityChange: changed linkProperty[" + netType + "]:" +
-                        " doReset=" + doReset + " resetMask=" + resetMask +
-                        "\n  curLp=" + curLp +
-                        "\n  newLp= null");
-            }
-        }
-        mCurrentLinkProperties[netType] = newLp;
-        boolean resetDns = updateRoutes(newLp, curLp, mNetConfigs[netType].isDefault(), exempt);
-
-        if (resetMask != 0 || resetDns) {
-            if (VDBG) log("handleConnectivityChange: resetting");
-            if (curLp != null) {
-                if (VDBG) log("handleConnectivityChange: resetting curLp=" + curLp);
-                for (String iface : curLp.getAllInterfaceNames()) {
-                    if (TextUtils.isEmpty(iface) == false) {
-                        if (resetMask != 0) {
-                            if (DBG) log("resetConnections(" + iface + ", " + resetMask + ")");
-                            NetworkUtils.resetConnections(iface, resetMask);
-
-                            // Tell VPN the interface is down. It is a temporary
-                            // but effective fix to make VPN aware of the change.
-                            if ((resetMask & NetworkUtils.RESET_IPV4_ADDRESSES) != 0) {
-                                synchronized(mVpns) {
-                                    for (int i = 0; i < mVpns.size(); i++) {
-                                        mVpns.valueAt(i).interfaceStatusChanged(iface, false);
-                                    }
-                                }
-                            }
-                        }
-                        if (resetDns) {
-                            flushVmDnsCache();
-                            if (VDBG) log("resetting DNS cache for " + iface);
-                            try {
-                                mNetd.flushInterfaceDnsCache(iface);
-                            } catch (Exception e) {
-                                // never crash - catch them all
-                                if (DBG) loge("Exception resetting dns cache: " + e);
-                            }
-                        }
-                    } else {
-                        loge("Can't reset connection for type "+netType);
-                    }
-                }
-            }
-        }
-
-        // Update 464xlat state.
-        NetworkStateTracker tracker = mNetTrackers[netType];
-        if (mClat.requiresClat(netType, tracker)) {
-
-            // If the connection was previously using clat, but is not using it now, stop the clat
-            // daemon. Normally, this happens automatically when the connection disconnects, but if
-            // the disconnect is not reported, or if the connection's LinkProperties changed for
-            // some other reason (e.g., handoff changes the IP addresses on the link), it would
-            // still be running. If it's not running, then stopping it is a no-op.
-            if (Nat464Xlat.isRunningClat(curLp) && !Nat464Xlat.isRunningClat(newLp)) {
-                mClat.stopClat();
-            }
-            // If the link requires clat to be running, then start the daemon now.
-            if (mNetTrackers[netType].getNetworkInfo().isConnected()) {
-                mClat.startClat(tracker);
-            } else {
-                mClat.stopClat();
-            }
-        }
-
-        // TODO: Temporary notifying upstread change to Tethering.
-        //       @see bug/4455071
-        /** Notify TetheringService if interface name has been changed. */
-        if (TextUtils.equals(mNetTrackers[netType].getNetworkInfo().getReason(),
-                             PhoneConstants.REASON_LINK_PROPERTIES_CHANGED)) {
-            if (isTetheringSupported()) {
-                mTethering.handleTetherIfaceChange();
-            }
-        }
-    }
-
-    /**
-     * Add and remove routes using the old properties (null if not previously connected),
-     * new properties (null if becoming disconnected).  May even be double null, which
-     * is a noop.
-     * Uses isLinkDefault to determine if default routes should be set or conversely if
-     * host routes should be set to the dns servers
-     * returns a boolean indicating the routes changed
-     */
-    private boolean updateRoutes(LinkProperties newLp, LinkProperties curLp,
-            boolean isLinkDefault, boolean exempt) {
-        Collection<RouteInfo> routesToAdd = null;
-        CompareResult<InetAddress> dnsDiff = new CompareResult<InetAddress>();
-        CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>();
-        if (curLp != null) {
-            // check for the delta between the current set and the new
-            routeDiff = curLp.compareAllRoutes(newLp);
-            dnsDiff = curLp.compareDnses(newLp);
-        } else if (newLp != null) {
-            routeDiff.added = newLp.getAllRoutes();
-            dnsDiff.added = newLp.getDnses();
-        }
-
-        boolean routesChanged = (routeDiff.removed.size() != 0 || routeDiff.added.size() != 0);
-
-        for (RouteInfo r : routeDiff.removed) {
-            if (isLinkDefault || ! r.isDefaultRoute()) {
-                if (VDBG) log("updateRoutes: default remove route r=" + r);
-                removeRoute(curLp, r, TO_DEFAULT_TABLE);
-            }
-            if (isLinkDefault == false) {
-                // remove from a secondary route table
-                removeRoute(curLp, r, TO_SECONDARY_TABLE);
-            }
-        }
-
-        if (!isLinkDefault) {
-            // handle DNS routes
-            if (routesChanged) {
-                // routes changed - remove all old dns entries and add new
-                if (curLp != null) {
-                    for (InetAddress oldDns : curLp.getDnses()) {
-                        removeRouteToAddress(curLp, oldDns);
-                    }
-                }
-                if (newLp != null) {
-                    for (InetAddress newDns : newLp.getDnses()) {
-                        addRouteToAddress(newLp, newDns, exempt);
-                    }
-                }
-            } else {
-                // no change in routes, check for change in dns themselves
-                for (InetAddress oldDns : dnsDiff.removed) {
-                    removeRouteToAddress(curLp, oldDns);
-                }
-                for (InetAddress newDns : dnsDiff.added) {
-                    addRouteToAddress(newLp, newDns, exempt);
-                }
-            }
-        }
-
-        for (RouteInfo r :  routeDiff.added) {
-            if (isLinkDefault || ! r.isDefaultRoute()) {
-                addRoute(newLp, r, TO_DEFAULT_TABLE, exempt);
-            } else {
-                // add to a secondary route table
-                addRoute(newLp, r, TO_SECONDARY_TABLE, UNEXEMPT);
-
-                // many radios add a default route even when we don't want one.
-                // remove the default route unless somebody else has asked for it
-                String ifaceName = newLp.getInterfaceName();
-                synchronized (mRoutesLock) {
-                    if (!TextUtils.isEmpty(ifaceName) && !mAddedRoutes.contains(r)) {
-                        if (VDBG) log("Removing " + r + " for interface " + ifaceName);
-                        try {
-                            mNetd.removeRoute(ifaceName, r);
-                        } catch (Exception e) {
-                            // never crash - catch them all
-                            if (DBG) loge("Exception trying to remove a route: " + e);
-                        }
-                    }
-                }
-            }
-        }
-
-        return routesChanged;
-    }
-
-   /**
-     * Reads the network specific MTU size from reources.
-     * and set it on it's iface.
-     */
-   private void updateMtuSizeSettings(NetworkStateTracker nt) {
-       final String iface = nt.getLinkProperties().getInterfaceName();
-       final int mtu = nt.getLinkProperties().getMtu();
-
-       if (mtu < 68 || mtu > 10000) {
-           loge("Unexpected mtu value: " + nt);
-           return;
-       }
-
-       try {
-           if (VDBG) log("Setting MTU size: " + iface + ", " + mtu);
-           mNetd.setMtu(iface, mtu);
-       } catch (Exception e) {
-           Slog.e(TAG, "exception in setMtu()" + e);
-       }
-   }
-
-    /**
-     * Reads the network specific TCP buffer sizes from SystemProperties
-     * net.tcp.buffersize.[default|wifi|umts|edge|gprs] and set them for system
-     * wide use
-     */
-    private void updateNetworkSettings(NetworkStateTracker nt) {
-        String key = nt.getTcpBufferSizesPropName();
-        String bufferSizes = key == null ? null : SystemProperties.get(key);
-
-        if (TextUtils.isEmpty(bufferSizes)) {
-            if (VDBG) log(key + " not found in system properties. Using defaults");
-
-            // Setting to default values so we won't be stuck to previous values
-            key = "net.tcp.buffersize.default";
-            bufferSizes = SystemProperties.get(key);
-        }
-
-        // Set values in kernel
-        if (bufferSizes.length() != 0) {
-            if (VDBG) {
-                log("Setting TCP values: [" + bufferSizes
-                        + "] which comes from [" + key + "]");
-            }
-            setBufferSize(bufferSizes);
-        }
-
-        final String defaultRwndKey = "net.tcp.default_init_rwnd";
-        int defaultRwndValue = SystemProperties.getInt(defaultRwndKey, 0);
-        Integer rwndValue = Settings.Global.getInt(mContext.getContentResolver(),
-            Settings.Global.TCP_DEFAULT_INIT_RWND, defaultRwndValue);
-        final String sysctlKey = "sys.sysctl.tcp_def_init_rwnd";
-        if (rwndValue != 0) {
-            SystemProperties.set(sysctlKey, rwndValue.toString());
-        }
-    }
-
-    /**
-     * Writes TCP buffer sizes to /sys/kernel/ipv4/tcp_[r/w]mem_[min/def/max]
-     * which maps to /proc/sys/net/ipv4/tcp_rmem and tcpwmem
-     *
-     * @param bufferSizes in the format of "readMin, readInitial, readMax,
-     *        writeMin, writeInitial, writeMax"
-     */
-    private void setBufferSize(String bufferSizes) {
-        try {
-            String[] values = bufferSizes.split(",");
-
-            if (values.length == 6) {
-              final String prefix = "/sys/kernel/ipv4/tcp_";
-                FileUtils.stringToFile(prefix + "rmem_min", values[0]);
-                FileUtils.stringToFile(prefix + "rmem_def", values[1]);
-                FileUtils.stringToFile(prefix + "rmem_max", values[2]);
-                FileUtils.stringToFile(prefix + "wmem_min", values[3]);
-                FileUtils.stringToFile(prefix + "wmem_def", values[4]);
-                FileUtils.stringToFile(prefix + "wmem_max", values[5]);
-            } else {
-                loge("Invalid buffersize string: " + bufferSizes);
-            }
-        } catch (IOException e) {
-            loge("Can't set tcp buffer sizes:" + e);
-        }
-    }
-
-    /**
-     * Adjust the per-process dns entries (net.dns<x>.<pid>) based
-     * on the highest priority active net which this process requested.
-     * If there aren't any, clear it out
-     */
-    private void reassessPidDns(int pid, boolean doBump)
-    {
-        if (VDBG) log("reassessPidDns for pid " + pid);
-        Integer myPid = new Integer(pid);
-        for(int i : mPriorityList) {
-            if (mNetConfigs[i].isDefault()) {
-                continue;
-            }
-            NetworkStateTracker nt = mNetTrackers[i];
-            if (nt.getNetworkInfo().isConnected() &&
-                    !nt.isTeardownRequested()) {
-                LinkProperties p = nt.getLinkProperties();
-                if (p == null) continue;
-                if (mNetRequestersPids[i].contains(myPid)) {
-                    try {
-                        mNetd.setDnsInterfaceForPid(p.getInterfaceName(), pid);
-                    } catch (Exception e) {
-                        Slog.e(TAG, "exception reasseses pid dns: " + e);
-                    }
-                    return;
-                }
-           }
-        }
-        // nothing found - delete
-        try {
-            mNetd.clearDnsInterfaceForPid(pid);
-        } catch (Exception e) {
-            Slog.e(TAG, "exception clear interface from pid: " + e);
-        }
-    }
-
-    private void flushVmDnsCache() {
-        /*
-         * Tell the VMs to toss their DNS caches
-         */
-        Intent intent = new Intent(Intent.ACTION_CLEAR_DNS_CACHE);
-        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-        /*
-         * Connectivity events can happen before boot has completed ...
-         */
-        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    // Caller must grab mDnsLock.
-    private void updateDnsLocked(String network, String iface,
-            Collection<InetAddress> dnses, String domains, boolean defaultDns) {
-        int last = 0;
-        if (dnses.size() == 0 && mDefaultDns != null) {
-            dnses = new ArrayList();
-            dnses.add(mDefaultDns);
-            if (DBG) {
-                loge("no dns provided for " + network + " - using " + mDefaultDns.getHostAddress());
-            }
-        }
-
-        try {
-            mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses), domains);
-            if (defaultDns) {
-                mNetd.setDefaultInterfaceForDns(iface);
-            }
-
-            for (InetAddress dns : dnses) {
-                ++last;
-                String key = "net.dns" + last;
-                String value = dns.getHostAddress();
-                SystemProperties.set(key, value);
-            }
-            for (int i = last + 1; i <= mNumDnsEntries; ++i) {
-                String key = "net.dns" + i;
-                SystemProperties.set(key, "");
-            }
-            mNumDnsEntries = last;
-        } catch (Exception e) {
-            loge("exception setting default dns interface: " + e);
-        }
-    }
-
-    private void handleDnsConfigurationChange(int netType) {
-        // add default net's dns entries
-        NetworkStateTracker nt = mNetTrackers[netType];
-        if (nt != null && nt.getNetworkInfo().isConnected() && !nt.isTeardownRequested()) {
-            LinkProperties p = nt.getLinkProperties();
-            if (p == null) return;
-            Collection<InetAddress> dnses = p.getDnses();
-            if (mNetConfigs[netType].isDefault()) {
-                String network = nt.getNetworkInfo().getTypeName();
-                synchronized (mDnsLock) {
-                    updateDnsLocked(network, p.getInterfaceName(), dnses, p.getDomains(), true);
-                }
-            } else {
-                try {
-                    mNetd.setDnsServersForInterface(p.getInterfaceName(),
-                            NetworkUtils.makeStrings(dnses), p.getDomains());
-                } catch (Exception e) {
-                    if (DBG) loge("exception setting dns servers: " + e);
-                }
-                // set per-pid dns for attached secondary nets
-                List<Integer> pids = mNetRequestersPids[netType];
-                for (Integer pid : pids) {
-                    try {
-                        mNetd.setDnsInterfaceForPid(p.getInterfaceName(), pid);
-                    } catch (Exception e) {
-                        Slog.e(TAG, "exception setting interface for pid: " + e);
-                    }
-                }
-            }
-            flushVmDnsCache();
-        }
-    }
-
-    private int getRestoreDefaultNetworkDelay(int networkType) {
-        String restoreDefaultNetworkDelayStr = SystemProperties.get(
-                NETWORK_RESTORE_DELAY_PROP_NAME);
-        if(restoreDefaultNetworkDelayStr != null &&
-                restoreDefaultNetworkDelayStr.length() != 0) {
-            try {
-                return Integer.valueOf(restoreDefaultNetworkDelayStr);
-            } catch (NumberFormatException e) {
-            }
-        }
-        // if the system property isn't set, use the value for the apn type
-        int ret = RESTORE_DEFAULT_NETWORK_DELAY;
-
-        if ((networkType <= ConnectivityManager.MAX_NETWORK_TYPE) &&
-                (mNetConfigs[networkType] != null)) {
-            ret = mNetConfigs[networkType].restoreTime;
-        }
-        return ret;
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
-        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump ConnectivityService " +
-                    "from from pid=" + Binder.getCallingPid() + ", uid=" +
-                    Binder.getCallingUid());
-            return;
-        }
-
-        // TODO: add locking to get atomic snapshot
-        pw.println();
-        for (int i = 0; i < mNetTrackers.length; i++) {
-            final NetworkStateTracker nst = mNetTrackers[i];
-            if (nst != null) {
-                pw.println("NetworkStateTracker for " + getNetworkTypeName(i) + ":");
-                pw.increaseIndent();
-                if (nst.getNetworkInfo().isConnected()) {
-                    pw.println("Active network: " + nst.getNetworkInfo().
-                            getTypeName());
-                }
-                pw.println(nst.getNetworkInfo());
-                pw.println(nst.getLinkProperties());
-                pw.println(nst);
-                pw.println();
-                pw.decreaseIndent();
-            }
-        }
-
-        pw.println("Network Requester Pids:");
-        pw.increaseIndent();
-        for (int net : mPriorityList) {
-            String pidString = net + ": ";
-            for (Integer pid : mNetRequestersPids[net]) {
-                pidString = pidString + pid.toString() + ", ";
-            }
-            pw.println(pidString);
-        }
-        pw.println();
-        pw.decreaseIndent();
-
-        pw.println("FeatureUsers:");
-        pw.increaseIndent();
-        for (Object requester : mFeatureUsers) {
-            pw.println(requester.toString());
-        }
-        pw.println();
-        pw.decreaseIndent();
-
-        synchronized (this) {
-            pw.println("NetworkTranstionWakeLock is currently " +
-                    (mNetTransitionWakeLock.isHeld() ? "" : "not ") + "held.");
-            pw.println("It was last requested for "+mNetTransitionWakeLockCausedBy);
-        }
-        pw.println();
-
-        mTethering.dump(fd, pw, args);
-
-        if (mInetLog != null) {
-            pw.println();
-            pw.println("Inet condition reports:");
-            pw.increaseIndent();
-            for(int i = 0; i < mInetLog.size(); i++) {
-                pw.println(mInetLog.get(i));
-            }
-            pw.decreaseIndent();
-        }
-    }
-
-    // must be stateless - things change under us.
-    private class NetworkStateTrackerHandler extends Handler {
-        public NetworkStateTrackerHandler(Looper looper) {
-            super(looper);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            NetworkInfo info;
-            switch (msg.what) {
-                case NetworkStateTracker.EVENT_STATE_CHANGED: {
-                    info = (NetworkInfo) msg.obj;
-                    NetworkInfo.State state = info.getState();
-
-                    if (VDBG || (state == NetworkInfo.State.CONNECTED) ||
-                            (state == NetworkInfo.State.DISCONNECTED) ||
-                            (state == NetworkInfo.State.SUSPENDED)) {
-                        log("ConnectivityChange for " +
-                            info.getTypeName() + ": " +
-                            state + "/" + info.getDetailedState());
-                    }
-
-                    // Since mobile has the notion of a network/apn that can be used for
-                    // provisioning we need to check every time we're connected as
-                    // CaptiveProtalTracker won't detected it because DCT doesn't report it
-                    // as connected as ACTION_ANY_DATA_CONNECTION_STATE_CHANGED instead its
-                    // reported as ACTION_DATA_CONNECTION_CONNECTED_TO_PROVISIONING_APN. Which
-                    // is received by MDST and sent here as EVENT_STATE_CHANGED.
-                    if (ConnectivityManager.isNetworkTypeMobile(info.getType())
-                            && (0 != Settings.Global.getInt(mContext.getContentResolver(),
-                                        Settings.Global.DEVICE_PROVISIONED, 0))
-                            && (((state == NetworkInfo.State.CONNECTED)
-                                    && (info.getType() == ConnectivityManager.TYPE_MOBILE))
-                                || info.isConnectedToProvisioningNetwork())) {
-                        log("ConnectivityChange checkMobileProvisioning for"
-                                + " TYPE_MOBILE or ProvisioningNetwork");
-                        checkMobileProvisioning(CheckMp.MAX_TIMEOUT_MS);
-                    }
-
-                    EventLogTags.writeConnectivityStateChanged(
-                            info.getType(), info.getSubtype(), info.getDetailedState().ordinal());
-
-                    if (info.getDetailedState() ==
-                            NetworkInfo.DetailedState.FAILED) {
-                        handleConnectionFailure(info);
-                    } else if (info.getDetailedState() ==
-                            DetailedState.CAPTIVE_PORTAL_CHECK) {
-                        handleCaptivePortalTrackerCheck(info);
-                    } else if (info.isConnectedToProvisioningNetwork()) {
-                        /**
-                         * TODO: Create ConnectivityManager.TYPE_MOBILE_PROVISIONING
-                         * for now its an in between network, its a network that
-                         * is actually a default network but we don't want it to be
-                         * announced as such to keep background applications from
-                         * trying to use it. It turns out that some still try so we
-                         * take the additional step of clearing any default routes
-                         * to the link that may have incorrectly setup by the lower
-                         * levels.
-                         */
-                        LinkProperties lp = getLinkProperties(info.getType());
-                        if (DBG) {
-                            log("EVENT_STATE_CHANGED: connected to provisioning network, lp=" + lp);
-                        }
-
-                        // Clear any default routes setup by the radio so
-                        // any activity by applications trying to use this
-                        // connection will fail until the provisioning network
-                        // is enabled.
-                        for (RouteInfo r : lp.getRoutes()) {
-                            removeRoute(lp, r, TO_DEFAULT_TABLE);
-                        }
-                    } else if (state == NetworkInfo.State.DISCONNECTED) {
-                        handleDisconnect(info);
-                    } else if (state == NetworkInfo.State.SUSPENDED) {
-                        // TODO: need to think this over.
-                        // the logic here is, handle SUSPENDED the same as
-                        // DISCONNECTED. The only difference being we are
-                        // broadcasting an intent with NetworkInfo that's
-                        // suspended. This allows the applications an
-                        // opportunity to handle DISCONNECTED and SUSPENDED
-                        // differently, or not.
-                        handleDisconnect(info);
-                    } else if (state == NetworkInfo.State.CONNECTED) {
-                        handleConnect(info);
-                    }
-                    if (mLockdownTracker != null) {
-                        mLockdownTracker.onNetworkInfoChanged(info);
-                    }
-                    break;
-                }
-                case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED: {
-                    info = (NetworkInfo) msg.obj;
-                    // TODO: Temporary allowing network configuration
-                    //       change not resetting sockets.
-                    //       @see bug/4455071
-                    handleConnectivityChange(info.getType(), false);
-                    break;
-                }
-                case NetworkStateTracker.EVENT_NETWORK_SUBTYPE_CHANGED: {
-                    info = (NetworkInfo) msg.obj;
-                    int type = info.getType();
-                    if (mNetConfigs[type].isDefault()) updateNetworkSettings(mNetTrackers[type]);
-                    break;
-                }
-            }
-        }
-    }
-
-    private class InternalHandler extends Handler {
-        public InternalHandler(Looper looper) {
-            super(looper);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            NetworkInfo info;
-            switch (msg.what) {
-                case EVENT_CLEAR_NET_TRANSITION_WAKELOCK: {
-                    String causedBy = null;
-                    synchronized (ConnectivityService.this) {
-                        if (msg.arg1 == mNetTransitionWakeLockSerialNumber &&
-                                mNetTransitionWakeLock.isHeld()) {
-                            mNetTransitionWakeLock.release();
-                            causedBy = mNetTransitionWakeLockCausedBy;
-                        }
-                    }
-                    if (causedBy != null) {
-                        log("NetTransition Wakelock for " + causedBy + " released by timeout");
-                    }
-                    break;
-                }
-                case EVENT_RESTORE_DEFAULT_NETWORK: {
-                    FeatureUser u = (FeatureUser)msg.obj;
-                    u.expire();
-                    break;
-                }
-                case EVENT_INET_CONDITION_CHANGE: {
-                    int netType = msg.arg1;
-                    int condition = msg.arg2;
-                    handleInetConditionChange(netType, condition);
-                    break;
-                }
-                case EVENT_INET_CONDITION_HOLD_END: {
-                    int netType = msg.arg1;
-                    int sequence = msg.arg2;
-                    handleInetConditionHoldEnd(netType, sequence);
-                    break;
-                }
-                case EVENT_SET_NETWORK_PREFERENCE: {
-                    int preference = msg.arg1;
-                    handleSetNetworkPreference(preference);
-                    break;
-                }
-                case EVENT_SET_MOBILE_DATA: {
-                    boolean enabled = (msg.arg1 == ENABLED);
-                    handleSetMobileData(enabled);
-                    break;
-                }
-                case EVENT_APPLY_GLOBAL_HTTP_PROXY: {
-                    handleDeprecatedGlobalHttpProxy();
-                    break;
-                }
-                case EVENT_SET_DEPENDENCY_MET: {
-                    boolean met = (msg.arg1 == ENABLED);
-                    handleSetDependencyMet(msg.arg2, met);
-                    break;
-                }
-                case EVENT_SEND_STICKY_BROADCAST_INTENT: {
-                    Intent intent = (Intent)msg.obj;
-                    sendStickyBroadcast(intent);
-                    break;
-                }
-                case EVENT_SET_POLICY_DATA_ENABLE: {
-                    final int networkType = msg.arg1;
-                    final boolean enabled = msg.arg2 == ENABLED;
-                    handleSetPolicyDataEnable(networkType, enabled);
-                    break;
-                }
-                case EVENT_VPN_STATE_CHANGED: {
-                    if (mLockdownTracker != null) {
-                        mLockdownTracker.onVpnStateChanged((NetworkInfo) msg.obj);
-                    }
-                    break;
-                }
-                case EVENT_ENABLE_FAIL_FAST_MOBILE_DATA: {
-                    int tag = mEnableFailFastMobileDataTag.get();
-                    if (msg.arg1 == tag) {
-                        MobileDataStateTracker mobileDst =
-                            (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE];
-                        if (mobileDst != null) {
-                            mobileDst.setEnableFailFastMobileData(msg.arg2);
-                        }
-                    } else {
-                        log("EVENT_ENABLE_FAIL_FAST_MOBILE_DATA: stale arg1:" + msg.arg1
-                                + " != tag:" + tag);
-                    }
-                    break;
-                }
-                case EVENT_SAMPLE_INTERVAL_ELAPSED: {
-                    handleNetworkSamplingTimeout();
-                    break;
-                }
-                case EVENT_PROXY_HAS_CHANGED: {
-                    handleApplyDefaultProxy((ProxyProperties)msg.obj);
-                    break;
-                }
-            }
-        }
-    }
-
-    // javadoc from interface
-    public int tether(String iface) {
-        enforceTetherChangePermission();
-
-        if (isTetheringSupported()) {
-            return mTethering.tether(iface);
-        } else {
-            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
-        }
-    }
-
-    // javadoc from interface
-    public int untether(String iface) {
-        enforceTetherChangePermission();
-
-        if (isTetheringSupported()) {
-            return mTethering.untether(iface);
-        } else {
-            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
-        }
-    }
-
-    // javadoc from interface
-    public int getLastTetherError(String iface) {
-        enforceTetherAccessPermission();
-
-        if (isTetheringSupported()) {
-            return mTethering.getLastTetherError(iface);
-        } else {
-            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
-        }
-    }
-
-    // TODO - proper iface API for selection by property, inspection, etc
-    public String[] getTetherableUsbRegexs() {
-        enforceTetherAccessPermission();
-        if (isTetheringSupported()) {
-            return mTethering.getTetherableUsbRegexs();
-        } else {
-            return new String[0];
-        }
-    }
-
-    public String[] getTetherableWifiRegexs() {
-        enforceTetherAccessPermission();
-        if (isTetheringSupported()) {
-            return mTethering.getTetherableWifiRegexs();
-        } else {
-            return new String[0];
-        }
-    }
-
-    public String[] getTetherableBluetoothRegexs() {
-        enforceTetherAccessPermission();
-        if (isTetheringSupported()) {
-            return mTethering.getTetherableBluetoothRegexs();
-        } else {
-            return new String[0];
-        }
-    }
-
-    public int setUsbTethering(boolean enable) {
-        enforceTetherChangePermission();
-        if (isTetheringSupported()) {
-            return mTethering.setUsbTethering(enable);
-        } else {
-            return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
-        }
-    }
-
-    // TODO - move iface listing, queries, etc to new module
-    // javadoc from interface
-    public String[] getTetherableIfaces() {
-        enforceTetherAccessPermission();
-        return mTethering.getTetherableIfaces();
-    }
-
-    public String[] getTetheredIfaces() {
-        enforceTetherAccessPermission();
-        return mTethering.getTetheredIfaces();
-    }
-
-    public String[] getTetheringErroredIfaces() {
-        enforceTetherAccessPermission();
-        return mTethering.getErroredIfaces();
-    }
-
-    // if ro.tether.denied = true we default to no tethering
-    // gservices could set the secure setting to 1 though to enable it on a build where it
-    // had previously been turned off.
-    public boolean isTetheringSupported() {
-        enforceTetherAccessPermission();
-        int defaultVal = (SystemProperties.get("ro.tether.denied").equals("true") ? 0 : 1);
-        boolean tetherEnabledInSettings = (Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.TETHER_SUPPORTED, defaultVal) != 0);
-        return tetherEnabledInSettings && ((mTethering.getTetherableUsbRegexs().length != 0 ||
-                mTethering.getTetherableWifiRegexs().length != 0 ||
-                mTethering.getTetherableBluetoothRegexs().length != 0) &&
-                mTethering.getUpstreamIfaceTypes().length != 0);
-    }
-
-    // An API NetworkStateTrackers can call when they lose their network.
-    // This will automatically be cleared after X seconds or a network becomes CONNECTED,
-    // whichever happens first.  The timer is started by the first caller and not
-    // restarted by subsequent callers.
-    public void requestNetworkTransitionWakelock(String forWhom) {
-        enforceConnectivityInternalPermission();
-        synchronized (this) {
-            if (mNetTransitionWakeLock.isHeld()) return;
-            mNetTransitionWakeLockSerialNumber++;
-            mNetTransitionWakeLock.acquire();
-            mNetTransitionWakeLockCausedBy = forWhom;
-        }
-        mHandler.sendMessageDelayed(mHandler.obtainMessage(
-                EVENT_CLEAR_NET_TRANSITION_WAKELOCK,
-                mNetTransitionWakeLockSerialNumber, 0),
-                mNetTransitionWakeLockTimeout);
-        return;
-    }
-
-    // 100 percent is full good, 0 is full bad.
-    public void reportInetCondition(int networkType, int percentage) {
-        if (VDBG) log("reportNetworkCondition(" + networkType + ", " + percentage + ")");
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.STATUS_BAR,
-                "ConnectivityService");
-
-        if (DBG) {
-            int pid = getCallingPid();
-            int uid = getCallingUid();
-            String s = pid + "(" + uid + ") reports inet is " +
-                (percentage > 50 ? "connected" : "disconnected") + " (" + percentage + ") on " +
-                "network Type " + networkType + " at " + GregorianCalendar.getInstance().getTime();
-            mInetLog.add(s);
-            while(mInetLog.size() > INET_CONDITION_LOG_MAX_SIZE) {
-                mInetLog.remove(0);
-            }
-        }
-        mHandler.sendMessage(mHandler.obtainMessage(
-            EVENT_INET_CONDITION_CHANGE, networkType, percentage));
-    }
-
-    private void handleInetConditionChange(int netType, int condition) {
-        if (mActiveDefaultNetwork == -1) {
-            if (DBG) log("handleInetConditionChange: no active default network - ignore");
-            return;
-        }
-        if (mActiveDefaultNetwork != netType) {
-            if (DBG) log("handleInetConditionChange: net=" + netType +
-                            " != default=" + mActiveDefaultNetwork + " - ignore");
-            return;
-        }
-        if (VDBG) {
-            log("handleInetConditionChange: net=" +
-                    netType + ", condition=" + condition +
-                    ",mActiveDefaultNetwork=" + mActiveDefaultNetwork);
-        }
-        mDefaultInetCondition = condition;
-        int delay;
-        if (mInetConditionChangeInFlight == false) {
-            if (VDBG) log("handleInetConditionChange: starting a change hold");
-            // setup a new hold to debounce this
-            if (mDefaultInetCondition > 50) {
-                delay = Settings.Global.getInt(mContext.getContentResolver(),
-                        Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, 500);
-            } else {
-                delay = Settings.Global.getInt(mContext.getContentResolver(),
-                        Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, 3000);
-            }
-            mInetConditionChangeInFlight = true;
-            mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_INET_CONDITION_HOLD_END,
-                    mActiveDefaultNetwork, mDefaultConnectionSequence), delay);
-        } else {
-            // we've set the new condition, when this hold ends that will get picked up
-            if (VDBG) log("handleInetConditionChange: currently in hold - not setting new end evt");
-        }
-    }
-
-    private void handleInetConditionHoldEnd(int netType, int sequence) {
-        if (DBG) {
-            log("handleInetConditionHoldEnd: net=" + netType +
-                    ", condition=" + mDefaultInetCondition +
-                    ", published condition=" + mDefaultInetConditionPublished);
-        }
-        mInetConditionChangeInFlight = false;
-
-        if (mActiveDefaultNetwork == -1) {
-            if (DBG) log("handleInetConditionHoldEnd: no active default network - ignoring");
-            return;
-        }
-        if (mDefaultConnectionSequence != sequence) {
-            if (DBG) log("handleInetConditionHoldEnd: event hold for obsolete network - ignoring");
-            return;
-        }
-        // TODO: Figure out why this optimization sometimes causes a
-        //       change in mDefaultInetCondition to be missed and the
-        //       UI to not be updated.
-        //if (mDefaultInetConditionPublished == mDefaultInetCondition) {
-        //    if (DBG) log("no change in condition - aborting");
-        //    return;
-        //}
-        NetworkInfo networkInfo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
-        if (networkInfo.isConnected() == false) {
-            if (DBG) log("handleInetConditionHoldEnd: default network not connected - ignoring");
-            return;
-        }
-        mDefaultInetConditionPublished = mDefaultInetCondition;
-        sendInetConditionBroadcast(networkInfo);
-        return;
-    }
-
-    public ProxyProperties getProxy() {
-        // this information is already available as a world read/writable jvm property
-        // so this API change wouldn't have a benifit.  It also breaks the passing
-        // of proxy info to all the JVMs.
-        // enforceAccessPermission();
-        synchronized (mProxyLock) {
-            ProxyProperties ret = mGlobalProxy;
-            if ((ret == null) && !mDefaultProxyDisabled) ret = mDefaultProxy;
-            return ret;
-        }
-    }
-
-    public void setGlobalProxy(ProxyProperties proxyProperties) {
-        enforceConnectivityInternalPermission();
-
-        synchronized (mProxyLock) {
-            if (proxyProperties == mGlobalProxy) return;
-            if (proxyProperties != null && proxyProperties.equals(mGlobalProxy)) return;
-            if (mGlobalProxy != null && mGlobalProxy.equals(proxyProperties)) return;
-
-            String host = "";
-            int port = 0;
-            String exclList = "";
-            String pacFileUrl = "";
-            if (proxyProperties != null && (!TextUtils.isEmpty(proxyProperties.getHost()) ||
-                    !TextUtils.isEmpty(proxyProperties.getPacFileUrl()))) {
-                if (!proxyProperties.isValid()) {
-                    if (DBG)
-                        log("Invalid proxy properties, ignoring: " + proxyProperties.toString());
-                    return;
-                }
-                mGlobalProxy = new ProxyProperties(proxyProperties);
-                host = mGlobalProxy.getHost();
-                port = mGlobalProxy.getPort();
-                exclList = mGlobalProxy.getExclusionList();
-                if (proxyProperties.getPacFileUrl() != null) {
-                    pacFileUrl = proxyProperties.getPacFileUrl();
-                }
-            } else {
-                mGlobalProxy = null;
-            }
-            ContentResolver res = mContext.getContentResolver();
-            final long token = Binder.clearCallingIdentity();
-            try {
-                Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host);
-                Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port);
-                Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
-                        exclList);
-                Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl);
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-        }
-
-        if (mGlobalProxy == null) {
-            proxyProperties = mDefaultProxy;
-        }
-        sendProxyBroadcast(proxyProperties);
-    }
-
-    private void loadGlobalProxy() {
-        ContentResolver res = mContext.getContentResolver();
-        String host = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST);
-        int port = Settings.Global.getInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, 0);
-        String exclList = Settings.Global.getString(res,
-                Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST);
-        String pacFileUrl = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC);
-        if (!TextUtils.isEmpty(host) || !TextUtils.isEmpty(pacFileUrl)) {
-            ProxyProperties proxyProperties;
-            if (!TextUtils.isEmpty(pacFileUrl)) {
-                proxyProperties = new ProxyProperties(pacFileUrl);
-            } else {
-                proxyProperties = new ProxyProperties(host, port, exclList);
-            }
-            if (!proxyProperties.isValid()) {
-                if (DBG) log("Invalid proxy properties, ignoring: " + proxyProperties.toString());
-                return;
-            }
-
-            synchronized (mProxyLock) {
-                mGlobalProxy = proxyProperties;
-            }
-        }
-    }
-
-    public ProxyProperties getGlobalProxy() {
-        // this information is already available as a world read/writable jvm property
-        // so this API change wouldn't have a benifit.  It also breaks the passing
-        // of proxy info to all the JVMs.
-        // enforceAccessPermission();
-        synchronized (mProxyLock) {
-            return mGlobalProxy;
-        }
-    }
-
-    private void handleApplyDefaultProxy(ProxyProperties proxy) {
-        if (proxy != null && TextUtils.isEmpty(proxy.getHost())
-                && TextUtils.isEmpty(proxy.getPacFileUrl())) {
-            proxy = null;
-        }
-        synchronized (mProxyLock) {
-            if (mDefaultProxy != null && mDefaultProxy.equals(proxy)) return;
-            if (mDefaultProxy == proxy) return; // catches repeated nulls
-            if (proxy != null &&  !proxy.isValid()) {
-                if (DBG) log("Invalid proxy properties, ignoring: " + proxy.toString());
-                return;
-            }
-            mDefaultProxy = proxy;
-
-            if (mGlobalProxy != null) return;
-            if (!mDefaultProxyDisabled) {
-                sendProxyBroadcast(proxy);
-            }
-        }
-    }
-
-    private void handleDeprecatedGlobalHttpProxy() {
-        String proxy = Settings.Global.getString(mContext.getContentResolver(),
-                Settings.Global.HTTP_PROXY);
-        if (!TextUtils.isEmpty(proxy)) {
-            String data[] = proxy.split(":");
-            if (data.length == 0) {
-                return;
-            }
-
-            String proxyHost =  data[0];
-            int proxyPort = 8080;
-            if (data.length > 1) {
-                try {
-                    proxyPort = Integer.parseInt(data[1]);
-                } catch (NumberFormatException e) {
-                    return;
-                }
-            }
-            ProxyProperties p = new ProxyProperties(data[0], proxyPort, "");
-            setGlobalProxy(p);
-        }
-    }
-
-    private void sendProxyBroadcast(ProxyProperties proxy) {
-        if (proxy == null) proxy = new ProxyProperties("", 0, "");
-        if (mPacManager.setCurrentProxyScriptUrl(proxy)) return;
-        if (DBG) log("sending Proxy Broadcast for " + proxy);
-        Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
-        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
-            Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        intent.putExtra(Proxy.EXTRA_PROXY_INFO, proxy);
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private static class SettingsObserver extends ContentObserver {
-        private int mWhat;
-        private Handler mHandler;
-        SettingsObserver(Handler handler, int what) {
-            super(handler);
-            mHandler = handler;
-            mWhat = what;
-        }
-
-        void observe(Context context) {
-            ContentResolver resolver = context.getContentResolver();
-            resolver.registerContentObserver(Settings.Global.getUriFor(
-                    Settings.Global.HTTP_PROXY), false, this);
-        }
-
-        @Override
-        public void onChange(boolean selfChange) {
-            mHandler.obtainMessage(mWhat).sendToTarget();
-        }
-    }
-
-    private static void log(String s) {
-        Slog.d(TAG, s);
-    }
-
-    private static void loge(String s) {
-        Slog.e(TAG, s);
-    }
-
-    int convertFeatureToNetworkType(int networkType, String feature) {
-        int usedNetworkType = networkType;
-
-        if(networkType == ConnectivityManager.TYPE_MOBILE) {
-            if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_MMS)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_MMS;
-            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_SUPL)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_SUPL;
-            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN) ||
-                    TextUtils.equals(feature, Phone.FEATURE_ENABLE_DUN_ALWAYS)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_DUN;
-            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_HIPRI)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_HIPRI;
-            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_FOTA)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_FOTA;
-            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_IMS)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_IMS;
-            } else if (TextUtils.equals(feature, Phone.FEATURE_ENABLE_CBS)) {
-                usedNetworkType = ConnectivityManager.TYPE_MOBILE_CBS;
-            } else {
-                Slog.e(TAG, "Can't match any mobile netTracker!");
-            }
-        } else if (networkType == ConnectivityManager.TYPE_WIFI) {
-            if (TextUtils.equals(feature, "p2p")) {
-                usedNetworkType = ConnectivityManager.TYPE_WIFI_P2P;
-            } else {
-                Slog.e(TAG, "Can't match any wifi netTracker!");
-            }
-        } else {
-            Slog.e(TAG, "Unexpected network type");
-        }
-        return usedNetworkType;
-    }
-
-    private static <T> T checkNotNull(T value, String message) {
-        if (value == null) {
-            throw new NullPointerException(message);
-        }
-        return value;
-    }
-
-    /**
-     * Protect a socket from VPN routing rules. This method is used by
-     * VpnBuilder and not available in ConnectivityManager. Permissions
-     * are checked in Vpn class.
-     * @hide
-     */
-    @Override
-    public boolean protectVpn(ParcelFileDescriptor socket) {
-        throwIfLockdownEnabled();
-        try {
-            int type = mActiveDefaultNetwork;
-            int user = UserHandle.getUserId(Binder.getCallingUid());
-            if (ConnectivityManager.isNetworkTypeValid(type) && mNetTrackers[type] != null) {
-                synchronized(mVpns) {
-                    mVpns.get(user).protect(socket);
-                }
-                return true;
-            }
-        } catch (Exception e) {
-            // ignore
-        } finally {
-            try {
-                socket.close();
-            } catch (Exception e) {
-                // ignore
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Prepare for a VPN application. This method is used by VpnDialogs
-     * and not available in ConnectivityManager. Permissions are checked
-     * in Vpn class.
-     * @hide
-     */
-    @Override
-    public boolean prepareVpn(String oldPackage, String newPackage) {
-        throwIfLockdownEnabled();
-        int user = UserHandle.getUserId(Binder.getCallingUid());
-        synchronized(mVpns) {
-            return mVpns.get(user).prepare(oldPackage, newPackage);
-        }
-    }
-
-    @Override
-    public void markSocketAsUser(ParcelFileDescriptor socket, int uid) {
-        enforceMarkNetworkSocketPermission();
-        final long token = Binder.clearCallingIdentity();
-        try {
-            int mark = mNetd.getMarkForUid(uid);
-            // Clear the mark on the socket if no mark is needed to prevent socket reuse issues
-            if (mark == -1) {
-                mark = 0;
-            }
-            NetworkUtils.markSocket(socket.getFd(), mark);
-        } catch (RemoteException e) {
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    /**
-     * Configure a TUN interface and return its file descriptor. Parameters
-     * are encoded and opaque to this class. This method is used by VpnBuilder
-     * and not available in ConnectivityManager. Permissions are checked in
-     * Vpn class.
-     * @hide
-     */
-    @Override
-    public ParcelFileDescriptor establishVpn(VpnConfig config) {
-        throwIfLockdownEnabled();
-        int user = UserHandle.getUserId(Binder.getCallingUid());
-        synchronized(mVpns) {
-            return mVpns.get(user).establish(config);
-        }
-    }
-
-    /**
-     * Start legacy VPN, controlling native daemons as needed. Creates a
-     * secondary thread to perform connection work, returning quickly.
-     */
-    @Override
-    public void startLegacyVpn(VpnProfile profile) {
-        throwIfLockdownEnabled();
-        final LinkProperties egress = getActiveLinkProperties();
-        if (egress == null) {
-            throw new IllegalStateException("Missing active network connection");
-        }
-        int user = UserHandle.getUserId(Binder.getCallingUid());
-        synchronized(mVpns) {
-            mVpns.get(user).startLegacyVpn(profile, mKeyStore, egress);
-        }
-    }
-
-    /**
-     * Return the information of the ongoing legacy VPN. This method is used
-     * by VpnSettings and not available in ConnectivityManager. Permissions
-     * are checked in Vpn class.
-     * @hide
-     */
-    @Override
-    public LegacyVpnInfo getLegacyVpnInfo() {
-        throwIfLockdownEnabled();
-        int user = UserHandle.getUserId(Binder.getCallingUid());
-        synchronized(mVpns) {
-            return mVpns.get(user).getLegacyVpnInfo();
-        }
-    }
-
-    /**
-     * Returns the information of the ongoing VPN. This method is used by VpnDialogs and
-     * not available in ConnectivityManager.
-     * Permissions are checked in Vpn class.
-     * @hide
-     */
-    @Override
-    public VpnConfig getVpnConfig() {
-        int user = UserHandle.getUserId(Binder.getCallingUid());
-        synchronized(mVpns) {
-            return mVpns.get(user).getVpnConfig();
-        }
-    }
-
-    /**
-     * Callback for VPN subsystem. Currently VPN is not adapted to the service
-     * through NetworkStateTracker since it works differently. For example, it
-     * needs to override DNS servers but never takes the default routes. It
-     * relies on another data network, and it could keep existing connections
-     * alive after reconnecting, switching between networks, or even resuming
-     * from deep sleep. Calls from applications should be done synchronously
-     * to avoid race conditions. As these are all hidden APIs, refactoring can
-     * be done whenever a better abstraction is developed.
-     */
-    public class VpnCallback {
-        private VpnCallback() {
-        }
-
-        public void onStateChanged(NetworkInfo info) {
-            mHandler.obtainMessage(EVENT_VPN_STATE_CHANGED, info).sendToTarget();
-        }
-
-        public void override(String iface, List<String> dnsServers, List<String> searchDomains) {
-            if (dnsServers == null) {
-                restore();
-                return;
-            }
-
-            // Convert DNS servers into addresses.
-            List<InetAddress> addresses = new ArrayList<InetAddress>();
-            for (String address : dnsServers) {
-                // Double check the addresses and remove invalid ones.
-                try {
-                    addresses.add(InetAddress.parseNumericAddress(address));
-                } catch (Exception e) {
-                    // ignore
-                }
-            }
-            if (addresses.isEmpty()) {
-                restore();
-                return;
-            }
-
-            // Concatenate search domains into a string.
-            StringBuilder buffer = new StringBuilder();
-            if (searchDomains != null) {
-                for (String domain : searchDomains) {
-                    buffer.append(domain).append(' ');
-                }
-            }
-            String domains = buffer.toString().trim();
-
-            // Apply DNS changes.
-            synchronized (mDnsLock) {
-                updateDnsLocked("VPN", iface, addresses, domains, false);
-            }
-
-            // Temporarily disable the default proxy (not global).
-            synchronized (mProxyLock) {
-                mDefaultProxyDisabled = true;
-                if (mGlobalProxy == null && mDefaultProxy != null) {
-                    sendProxyBroadcast(null);
-                }
-            }
-
-            // TODO: support proxy per network.
-        }
-
-        public void restore() {
-            synchronized (mProxyLock) {
-                mDefaultProxyDisabled = false;
-                if (mGlobalProxy == null && mDefaultProxy != null) {
-                    sendProxyBroadcast(mDefaultProxy);
-                }
-            }
-        }
-
-        public void protect(ParcelFileDescriptor socket) {
-            try {
-                final int mark = mNetd.getMarkForProtect();
-                NetworkUtils.markSocket(socket.getFd(), mark);
-            } catch (RemoteException e) {
-            }
-        }
-
-        public void setRoutes(String interfaze, List<RouteInfo> routes) {
-            for (RouteInfo route : routes) {
-                try {
-                    mNetd.setMarkedForwardingRoute(interfaze, route);
-                } catch (RemoteException e) {
-                }
-            }
-        }
-
-        public void setMarkedForwarding(String interfaze) {
-            try {
-                mNetd.setMarkedForwarding(interfaze);
-            } catch (RemoteException e) {
-            }
-        }
-
-        public void clearMarkedForwarding(String interfaze) {
-            try {
-                mNetd.clearMarkedForwarding(interfaze);
-            } catch (RemoteException e) {
-            }
-        }
-
-        public void addUserForwarding(String interfaze, int uid, boolean forwardDns) {
-            int uidStart = uid * UserHandle.PER_USER_RANGE;
-            int uidEnd = uidStart + UserHandle.PER_USER_RANGE - 1;
-            addUidForwarding(interfaze, uidStart, uidEnd, forwardDns);
-        }
-
-        public void clearUserForwarding(String interfaze, int uid, boolean forwardDns) {
-            int uidStart = uid * UserHandle.PER_USER_RANGE;
-            int uidEnd = uidStart + UserHandle.PER_USER_RANGE - 1;
-            clearUidForwarding(interfaze, uidStart, uidEnd, forwardDns);
-        }
-
-        public void addUidForwarding(String interfaze, int uidStart, int uidEnd,
-                boolean forwardDns) {
-            try {
-                mNetd.setUidRangeRoute(interfaze,uidStart, uidEnd);
-                if (forwardDns) mNetd.setDnsInterfaceForUidRange(interfaze, uidStart, uidEnd);
-            } catch (RemoteException e) {
-            }
-
-        }
-
-        public void clearUidForwarding(String interfaze, int uidStart, int uidEnd,
-                boolean forwardDns) {
-            try {
-                mNetd.clearUidRangeRoute(interfaze, uidStart, uidEnd);
-                if (forwardDns) mNetd.clearDnsInterfaceForUidRange(uidStart, uidEnd);
-            } catch (RemoteException e) {
-            }
-
-        }
-    }
-
-    @Override
-    public boolean updateLockdownVpn() {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-            Slog.w(TAG, "Lockdown VPN only available to AID_SYSTEM");
-            return false;
-        }
-
-        // Tear down existing lockdown if profile was removed
-        mLockdownEnabled = LockdownVpnTracker.isEnabled();
-        if (mLockdownEnabled) {
-            if (!mKeyStore.isUnlocked()) {
-                Slog.w(TAG, "KeyStore locked; unable to create LockdownTracker");
-                return false;
-            }
-
-            final String profileName = new String(mKeyStore.get(Credentials.LOCKDOWN_VPN));
-            final VpnProfile profile = VpnProfile.decode(
-                    profileName, mKeyStore.get(Credentials.VPN + profileName));
-            int user = UserHandle.getUserId(Binder.getCallingUid());
-            synchronized(mVpns) {
-                setLockdownTracker(new LockdownVpnTracker(mContext, mNetd, this, mVpns.get(user),
-                            profile));
-            }
-        } else {
-            setLockdownTracker(null);
-        }
-
-        return true;
-    }
-
-    /**
-     * Internally set new {@link LockdownVpnTracker}, shutting down any existing
-     * {@link LockdownVpnTracker}. Can be {@code null} to disable lockdown.
-     */
-    private void setLockdownTracker(LockdownVpnTracker tracker) {
-        // Shutdown any existing tracker
-        final LockdownVpnTracker existing = mLockdownTracker;
-        mLockdownTracker = null;
-        if (existing != null) {
-            existing.shutdown();
-        }
-
-        try {
-            if (tracker != null) {
-                mNetd.setFirewallEnabled(true);
-                mNetd.setFirewallInterfaceRule("lo", true);
-                mLockdownTracker = tracker;
-                mLockdownTracker.init();
-            } else {
-                mNetd.setFirewallEnabled(false);
-            }
-        } catch (RemoteException e) {
-            // ignored; NMS lives inside system_server
-        }
-    }
-
-    private void throwIfLockdownEnabled() {
-        if (mLockdownEnabled) {
-            throw new IllegalStateException("Unavailable in lockdown mode");
-        }
-    }
-
-    public void supplyMessenger(int networkType, Messenger messenger) {
-        enforceConnectivityInternalPermission();
-
-        if (isNetworkTypeValid(networkType) && mNetTrackers[networkType] != null) {
-            mNetTrackers[networkType].supplyMessenger(messenger);
-        }
-    }
-
-    public int findConnectionTypeForIface(String iface) {
-        enforceConnectivityInternalPermission();
-
-        if (TextUtils.isEmpty(iface)) return ConnectivityManager.TYPE_NONE;
-        for (NetworkStateTracker tracker : mNetTrackers) {
-            if (tracker != null) {
-                LinkProperties lp = tracker.getLinkProperties();
-                if (lp != null && iface.equals(lp.getInterfaceName())) {
-                    return tracker.getNetworkInfo().getType();
-                }
-            }
-        }
-        return ConnectivityManager.TYPE_NONE;
-    }
-
-    /**
-     * Have mobile data fail fast if enabled.
-     *
-     * @param enabled DctConstants.ENABLED/DISABLED
-     */
-    private void setEnableFailFastMobileData(int enabled) {
-        int tag;
-
-        if (enabled == DctConstants.ENABLED) {
-            tag = mEnableFailFastMobileDataTag.incrementAndGet();
-        } else {
-            tag = mEnableFailFastMobileDataTag.get();
-        }
-        mHandler.sendMessage(mHandler.obtainMessage(EVENT_ENABLE_FAIL_FAST_MOBILE_DATA, tag,
-                         enabled));
-    }
-
-    private boolean isMobileDataStateTrackerReady() {
-        MobileDataStateTracker mdst =
-                (MobileDataStateTracker) mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
-        return (mdst != null) && (mdst.isReady());
-    }
-
-    /**
-     * The ResultReceiver resultCode for checkMobileProvisioning (CMP_RESULT_CODE)
-     */
-
-    /**
-     * No connection was possible to the network.
-     * This is NOT a warm sim.
-     */
-    private static final int CMP_RESULT_CODE_NO_CONNECTION = 0;
-
-    /**
-     * A connection was made to the internet, all is well.
-     * This is NOT a warm sim.
-     */
-    private static final int CMP_RESULT_CODE_CONNECTABLE = 1;
-
-    /**
-     * A connection was made but no dns server was available to resolve a name to address.
-     * This is NOT a warm sim since provisioning network is supported.
-     */
-    private static final int CMP_RESULT_CODE_NO_DNS = 2;
-
-    /**
-     * A connection was made but could not open a TCP connection.
-     * This is NOT a warm sim since provisioning network is supported.
-     */
-    private static final int CMP_RESULT_CODE_NO_TCP_CONNECTION = 3;
-
-    /**
-     * A connection was made but there was a redirection, we appear to be in walled garden.
-     * This is an indication of a warm sim on a mobile network such as T-Mobile.
-     */
-    private static final int CMP_RESULT_CODE_REDIRECTED = 4;
-
-    /**
-     * The mobile network is a provisioning network.
-     * This is an indication of a warm sim on a mobile network such as AT&T.
-     */
-    private static final int CMP_RESULT_CODE_PROVISIONING_NETWORK = 5;
-
-    private AtomicBoolean mIsCheckingMobileProvisioning = new AtomicBoolean(false);
-
-    @Override
-    public int checkMobileProvisioning(int suggestedTimeOutMs) {
-        int timeOutMs = -1;
-        if (DBG) log("checkMobileProvisioning: E suggestedTimeOutMs=" + suggestedTimeOutMs);
-        enforceConnectivityInternalPermission();
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            timeOutMs = suggestedTimeOutMs;
-            if (suggestedTimeOutMs > CheckMp.MAX_TIMEOUT_MS) {
-                timeOutMs = CheckMp.MAX_TIMEOUT_MS;
-            }
-
-            // Check that mobile networks are supported
-            if (!isNetworkSupported(ConnectivityManager.TYPE_MOBILE)
-                    || !isNetworkSupported(ConnectivityManager.TYPE_MOBILE_HIPRI)) {
-                if (DBG) log("checkMobileProvisioning: X no mobile network");
-                return timeOutMs;
-            }
-
-            // If we're already checking don't do it again
-            // TODO: Add a queue of results...
-            if (mIsCheckingMobileProvisioning.getAndSet(true)) {
-                if (DBG) log("checkMobileProvisioning: X already checking ignore for the moment");
-                return timeOutMs;
-            }
-
-            // Start off with mobile notification off
-            setProvNotificationVisible(false, ConnectivityManager.TYPE_MOBILE_HIPRI, null, null);
-
-            CheckMp checkMp = new CheckMp(mContext, this);
-            CheckMp.CallBack cb = new CheckMp.CallBack() {
-                @Override
-                void onComplete(Integer result) {
-                    if (DBG) log("CheckMp.onComplete: result=" + result);
-                    NetworkInfo ni =
-                            mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI].getNetworkInfo();
-                    switch(result) {
-                        case CMP_RESULT_CODE_CONNECTABLE:
-                        case CMP_RESULT_CODE_NO_CONNECTION:
-                        case CMP_RESULT_CODE_NO_DNS:
-                        case CMP_RESULT_CODE_NO_TCP_CONNECTION: {
-                            if (DBG) log("CheckMp.onComplete: ignore, connected or no connection");
-                            break;
-                        }
-                        case CMP_RESULT_CODE_REDIRECTED: {
-                            if (DBG) log("CheckMp.onComplete: warm sim");
-                            String url = getMobileProvisioningUrl();
-                            if (TextUtils.isEmpty(url)) {
-                                url = getMobileRedirectedProvisioningUrl();
-                            }
-                            if (TextUtils.isEmpty(url) == false) {
-                                if (DBG) log("CheckMp.onComplete: warm (redirected), url=" + url);
-                                setProvNotificationVisible(true,
-                                        ConnectivityManager.TYPE_MOBILE_HIPRI, ni.getExtraInfo(),
-                                        url);
-                            } else {
-                                if (DBG) log("CheckMp.onComplete: warm (redirected), no url");
-                            }
-                            break;
-                        }
-                        case CMP_RESULT_CODE_PROVISIONING_NETWORK: {
-                            String url = getMobileProvisioningUrl();
-                            if (TextUtils.isEmpty(url) == false) {
-                                if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), url=" + url);
-                                setProvNotificationVisible(true,
-                                        ConnectivityManager.TYPE_MOBILE_HIPRI, ni.getExtraInfo(),
-                                        url);
-                            } else {
-                                if (DBG) log("CheckMp.onComplete: warm (no dns/tcp), no url");
-                            }
-                            break;
-                        }
-                        default: {
-                            loge("CheckMp.onComplete: ignore unexpected result=" + result);
-                            break;
-                        }
-                    }
-                    mIsCheckingMobileProvisioning.set(false);
-                }
-            };
-            CheckMp.Params params =
-                    new CheckMp.Params(checkMp.getDefaultUrl(), timeOutMs, cb);
-            if (DBG) log("checkMobileProvisioning: params=" + params);
-            checkMp.execute(params);
-        } finally {
-            Binder.restoreCallingIdentity(token);
-            if (DBG) log("checkMobileProvisioning: X");
-        }
-        return timeOutMs;
-    }
-
-    static class CheckMp extends
-            AsyncTask<CheckMp.Params, Void, Integer> {
-        private static final String CHECKMP_TAG = "CheckMp";
-
-        // adb shell setprop persist.checkmp.testfailures 1 to enable testing failures
-        private static boolean mTestingFailures;
-
-        // Choosing 4 loops as half of them will use HTTPS and the other half HTTP
-        private static final int MAX_LOOPS = 4;
-
-        // Number of milli-seconds to complete all of the retires
-        public static final int MAX_TIMEOUT_MS =  60000;
-
-        // The socket should retry only 5 seconds, the default is longer
-        private static final int SOCKET_TIMEOUT_MS = 5000;
-
-        // Sleep time for network errors
-        private static final int NET_ERROR_SLEEP_SEC = 3;
-
-        // Sleep time for network route establishment
-        private static final int NET_ROUTE_ESTABLISHMENT_SLEEP_SEC = 3;
-
-        // Short sleep time for polling :(
-        private static final int POLLING_SLEEP_SEC = 1;
-
-        private Context mContext;
-        private ConnectivityService mCs;
-        private TelephonyManager mTm;
-        private Params mParams;
-
-        /**
-         * Parameters for AsyncTask.execute
-         */
-        static class Params {
-            private String mUrl;
-            private long mTimeOutMs;
-            private CallBack mCb;
-
-            Params(String url, long timeOutMs, CallBack cb) {
-                mUrl = url;
-                mTimeOutMs = timeOutMs;
-                mCb = cb;
-            }
-
-            @Override
-            public String toString() {
-                return "{" + " url=" + mUrl + " mTimeOutMs=" + mTimeOutMs + " mCb=" + mCb + "}";
-            }
-        }
-
-        // As explained to me by Brian Carlstrom and Kenny Root, Certificates can be
-        // issued by name or ip address, for Google its by name so when we construct
-        // this HostnameVerifier we'll pass the original Uri and use it to verify
-        // the host. If the host name in the original uril fails we'll test the
-        // hostname parameter just incase things change.
-        static class CheckMpHostnameVerifier implements HostnameVerifier {
-            Uri mOrgUri;
-
-            CheckMpHostnameVerifier(Uri orgUri) {
-                mOrgUri = orgUri;
-            }
-
-            @Override
-            public boolean verify(String hostname, SSLSession session) {
-                HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
-                String orgUriHost = mOrgUri.getHost();
-                boolean retVal = hv.verify(orgUriHost, session) || hv.verify(hostname, session);
-                if (DBG) {
-                    log("isMobileOk: hostnameVerify retVal=" + retVal + " hostname=" + hostname
-                        + " orgUriHost=" + orgUriHost);
-                }
-                return retVal;
-            }
-        }
-
-        /**
-         * The call back object passed in Params. onComplete will be called
-         * on the main thread.
-         */
-        abstract static class CallBack {
-            // Called on the main thread.
-            abstract void onComplete(Integer result);
-        }
-
-        public CheckMp(Context context, ConnectivityService cs) {
-            if (Build.IS_DEBUGGABLE) {
-                mTestingFailures =
-                        SystemProperties.getInt("persist.checkmp.testfailures", 0) == 1;
-            } else {
-                mTestingFailures = false;
-            }
-
-            mContext = context;
-            mCs = cs;
-
-            // Setup access to TelephonyService we'll be using.
-            mTm = (TelephonyManager) mContext.getSystemService(
-                    Context.TELEPHONY_SERVICE);
-        }
-
-        /**
-         * Get the default url to use for the test.
-         */
-        public String getDefaultUrl() {
-            // See http://go/clientsdns for usage approval
-            String server = Settings.Global.getString(mContext.getContentResolver(),
-                    Settings.Global.CAPTIVE_PORTAL_SERVER);
-            if (server == null) {
-                server = "clients3.google.com";
-            }
-            return "http://" + server + "/generate_204";
-        }
-
-        /**
-         * Detect if its possible to connect to the http url. DNS based detection techniques
-         * do not work at all hotspots. The best way to check is to perform a request to
-         * a known address that fetches the data we expect.
-         */
-        private synchronized Integer isMobileOk(Params params) {
-            Integer result = CMP_RESULT_CODE_NO_CONNECTION;
-            Uri orgUri = Uri.parse(params.mUrl);
-            Random rand = new Random();
-            mParams = params;
-
-            if (mCs.isNetworkSupported(ConnectivityManager.TYPE_MOBILE) == false) {
-                result = CMP_RESULT_CODE_NO_CONNECTION;
-                log("isMobileOk: X not mobile capable result=" + result);
-                return result;
-            }
-
-            // See if we've already determined we've got a provisioning connection,
-            // if so we don't need to do anything active.
-            MobileDataStateTracker mdstDefault = (MobileDataStateTracker)
-                    mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE];
-            boolean isDefaultProvisioning = mdstDefault.isProvisioningNetwork();
-            log("isMobileOk: isDefaultProvisioning=" + isDefaultProvisioning);
-
-            MobileDataStateTracker mdstHipri = (MobileDataStateTracker)
-                    mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
-            boolean isHipriProvisioning = mdstHipri.isProvisioningNetwork();
-            log("isMobileOk: isHipriProvisioning=" + isHipriProvisioning);
-
-            if (isDefaultProvisioning || isHipriProvisioning) {
-                result = CMP_RESULT_CODE_PROVISIONING_NETWORK;
-                log("isMobileOk: X default || hipri is provisioning result=" + result);
-                return result;
-            }
-
-            try {
-                // Continue trying to connect until time has run out
-                long endTime = SystemClock.elapsedRealtime() + params.mTimeOutMs;
-
-                if (!mCs.isMobileDataStateTrackerReady()) {
-                    // Wait for MobileDataStateTracker to be ready.
-                    if (DBG) log("isMobileOk: mdst is not ready");
-                    while(SystemClock.elapsedRealtime() < endTime) {
-                        if (mCs.isMobileDataStateTrackerReady()) {
-                            // Enable fail fast as we'll do retries here and use a
-                            // hipri connection so the default connection stays active.
-                            if (DBG) log("isMobileOk: mdst ready, enable fail fast of mobile data");
-                            mCs.setEnableFailFastMobileData(DctConstants.ENABLED);
-                            break;
-                        }
-                        sleep(POLLING_SLEEP_SEC);
-                    }
-                }
-
-                log("isMobileOk: start hipri url=" + params.mUrl);
-
-                // First wait until we can start using hipri
-                Binder binder = new Binder();
-                while(SystemClock.elapsedRealtime() < endTime) {
-                    int ret = mCs.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                            Phone.FEATURE_ENABLE_HIPRI, binder);
-                    if ((ret == PhoneConstants.APN_ALREADY_ACTIVE)
-                        || (ret == PhoneConstants.APN_REQUEST_STARTED)) {
-                            log("isMobileOk: hipri started");
-                            break;
-                    }
-                    if (VDBG) log("isMobileOk: hipri not started yet");
-                    result = CMP_RESULT_CODE_NO_CONNECTION;
-                    sleep(POLLING_SLEEP_SEC);
-                }
-
-                // Continue trying to connect until time has run out
-                while(SystemClock.elapsedRealtime() < endTime) {
-                    try {
-                        // Wait for hipri to connect.
-                        // TODO: Don't poll and handle situation where hipri fails
-                        // because default is retrying. See b/9569540
-                        NetworkInfo.State state = mCs
-                                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI).getState();
-                        if (state != NetworkInfo.State.CONNECTED) {
-                            if (true/*VDBG*/) {
-                                log("isMobileOk: not connected ni=" +
-                                    mCs.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI));
-                            }
-                            sleep(POLLING_SLEEP_SEC);
-                            result = CMP_RESULT_CODE_NO_CONNECTION;
-                            continue;
-                        }
-
-                        // Hipri has started check if this is a provisioning url
-                        MobileDataStateTracker mdst = (MobileDataStateTracker)
-                                mCs.mNetTrackers[ConnectivityManager.TYPE_MOBILE_HIPRI];
-                        if (mdst.isProvisioningNetwork()) {
-                            result = CMP_RESULT_CODE_PROVISIONING_NETWORK;
-                            if (DBG) log("isMobileOk: X isProvisioningNetwork result=" + result);
-                            return result;
-                        } else {
-                            if (DBG) log("isMobileOk: isProvisioningNetwork is false, continue");
-                        }
-
-                        // Get of the addresses associated with the url host. We need to use the
-                        // address otherwise HttpURLConnection object will use the name to get
-                        // the addresses and will try every address but that will bypass the
-                        // route to host we setup and the connection could succeed as the default
-                        // interface might be connected to the internet via wifi or other interface.
-                        InetAddress[] addresses;
-                        try {
-                            addresses = InetAddress.getAllByName(orgUri.getHost());
-                        } catch (UnknownHostException e) {
-                            result = CMP_RESULT_CODE_NO_DNS;
-                            log("isMobileOk: X UnknownHostException result=" + result);
-                            return result;
-                        }
-                        log("isMobileOk: addresses=" + inetAddressesToString(addresses));
-
-                        // Get the type of addresses supported by this link
-                        LinkProperties lp = mCs.getLinkProperties(
-                                ConnectivityManager.TYPE_MOBILE_HIPRI);
-                        boolean linkHasIpv4 = lp.hasIPv4Address();
-                        boolean linkHasIpv6 = lp.hasIPv6Address();
-                        log("isMobileOk: linkHasIpv4=" + linkHasIpv4
-                                + " linkHasIpv6=" + linkHasIpv6);
-
-                        final ArrayList<InetAddress> validAddresses =
-                                new ArrayList<InetAddress>(addresses.length);
-
-                        for (InetAddress addr : addresses) {
-                            if (((addr instanceof Inet4Address) && linkHasIpv4) ||
-                                    ((addr instanceof Inet6Address) && linkHasIpv6)) {
-                                validAddresses.add(addr);
-                            }
-                        }
-
-                        if (validAddresses.size() == 0) {
-                            return CMP_RESULT_CODE_NO_CONNECTION;
-                        }
-
-                        int addrTried = 0;
-                        while (true) {
-                            // Loop through at most MAX_LOOPS valid addresses or until
-                            // we run out of time
-                            if (addrTried++ >= MAX_LOOPS) {
-                                log("isMobileOk: too many loops tried - giving up");
-                                break;
-                            }
-                            if (SystemClock.elapsedRealtime() >= endTime) {
-                                log("isMobileOk: spend too much time - giving up");
-                                break;
-                            }
-
-                            InetAddress hostAddr = validAddresses.get(rand.nextInt(
-                                    validAddresses.size()));
-
-                            // Make a route to host so we check the specific interface.
-                            if (mCs.requestRouteToHostAddress(ConnectivityManager.TYPE_MOBILE_HIPRI,
-                                    hostAddr.getAddress(), null)) {
-                                // Wait a short time to be sure the route is established ??
-                                log("isMobileOk:"
-                                        + " wait to establish route to hostAddr=" + hostAddr);
-                                sleep(NET_ROUTE_ESTABLISHMENT_SLEEP_SEC);
-                            } else {
-                                log("isMobileOk:"
-                                        + " could not establish route to hostAddr=" + hostAddr);
-                                // Wait a short time before the next attempt
-                                sleep(NET_ERROR_SLEEP_SEC);
-                                continue;
-                            }
-
-                            // Rewrite the url to have numeric address to use the specific route
-                            // using http for half the attempts and https for the other half.
-                            // Doing https first and http second as on a redirected walled garden
-                            // such as t-mobile uses we get a SocketTimeoutException: "SSL
-                            // handshake timed out" which we declare as
-                            // CMP_RESULT_CODE_NO_TCP_CONNECTION. We could change this, but by
-                            // having http second we will be using logic used for some time.
-                            URL newUrl;
-                            String scheme = (addrTried <= (MAX_LOOPS/2)) ? "https" : "http";
-                            newUrl = new URL(scheme, hostAddr.getHostAddress(),
-                                        orgUri.getPath());
-                            log("isMobileOk: newUrl=" + newUrl);
-
-                            HttpURLConnection urlConn = null;
-                            try {
-                                // Open the connection set the request headers and get the response
-                                urlConn = (HttpURLConnection)newUrl.openConnection(
-                                        java.net.Proxy.NO_PROXY);
-                                if (scheme.equals("https")) {
-                                    ((HttpsURLConnection)urlConn).setHostnameVerifier(
-                                            new CheckMpHostnameVerifier(orgUri));
-                                }
-                                urlConn.setInstanceFollowRedirects(false);
-                                urlConn.setConnectTimeout(SOCKET_TIMEOUT_MS);
-                                urlConn.setReadTimeout(SOCKET_TIMEOUT_MS);
-                                urlConn.setUseCaches(false);
-                                urlConn.setAllowUserInteraction(false);
-                                // Set the "Connection" to "Close" as by default "Keep-Alive"
-                                // is used which is useless in this case.
-                                urlConn.setRequestProperty("Connection", "close");
-                                int responseCode = urlConn.getResponseCode();
-
-                                // For debug display the headers
-                                Map<String, List<String>> headers = urlConn.getHeaderFields();
-                                log("isMobileOk: headers=" + headers);
-
-                                // Close the connection
-                                urlConn.disconnect();
-                                urlConn = null;
-
-                                if (mTestingFailures) {
-                                    // Pretend no connection, this tests using http and https
-                                    result = CMP_RESULT_CODE_NO_CONNECTION;
-                                    log("isMobileOk: TESTING_FAILURES, pretend no connction");
-                                    continue;
-                                }
-
-                                if (responseCode == 204) {
-                                    // Return
-                                    result = CMP_RESULT_CODE_CONNECTABLE;
-                                    log("isMobileOk: X got expected responseCode=" + responseCode
-                                            + " result=" + result);
-                                    return result;
-                                } else {
-                                    // Retry to be sure this was redirected, we've gotten
-                                    // occasions where a server returned 200 even though
-                                    // the device didn't have a "warm" sim.
-                                    log("isMobileOk: not expected responseCode=" + responseCode);
-                                    // TODO - it would be nice in the single-address case to do
-                                    // another DNS resolve here, but flushing the cache is a bit
-                                    // heavy-handed.
-                                    result = CMP_RESULT_CODE_REDIRECTED;
-                                }
-                            } catch (Exception e) {
-                                log("isMobileOk: HttpURLConnection Exception" + e);
-                                result = CMP_RESULT_CODE_NO_TCP_CONNECTION;
-                                if (urlConn != null) {
-                                    urlConn.disconnect();
-                                    urlConn = null;
-                                }
-                                sleep(NET_ERROR_SLEEP_SEC);
-                                continue;
-                            }
-                        }
-                        log("isMobileOk: X loops|timed out result=" + result);
-                        return result;
-                    } catch (Exception e) {
-                        log("isMobileOk: Exception e=" + e);
-                        continue;
-                    }
-                }
-                log("isMobileOk: timed out");
-            } finally {
-                log("isMobileOk: F stop hipri");
-                mCs.setEnableFailFastMobileData(DctConstants.DISABLED);
-                mCs.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                        Phone.FEATURE_ENABLE_HIPRI);
-
-                // Wait for hipri to disconnect.
-                long endTime = SystemClock.elapsedRealtime() + 5000;
-
-                while(SystemClock.elapsedRealtime() < endTime) {
-                    NetworkInfo.State state = mCs
-                            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI).getState();
-                    if (state != NetworkInfo.State.DISCONNECTED) {
-                        if (VDBG) {
-                            log("isMobileOk: connected ni=" +
-                                mCs.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_HIPRI));
-                        }
-                        sleep(POLLING_SLEEP_SEC);
-                        continue;
-                    }
-                }
-
-                log("isMobileOk: X result=" + result);
-            }
-            return result;
-        }
-
-        @Override
-        protected Integer doInBackground(Params... params) {
-            return isMobileOk(params[0]);
-        }
-
-        @Override
-        protected void onPostExecute(Integer result) {
-            log("onPostExecute: result=" + result);
-            if ((mParams != null) && (mParams.mCb != null)) {
-                mParams.mCb.onComplete(result);
-            }
-        }
-
-        private String inetAddressesToString(InetAddress[] addresses) {
-            StringBuffer sb = new StringBuffer();
-            boolean firstTime = true;
-            for(InetAddress addr : addresses) {
-                if (firstTime) {
-                    firstTime = false;
-                } else {
-                    sb.append(",");
-                }
-                sb.append(addr);
-            }
-            return sb.toString();
-        }
-
-        private void printNetworkInfo() {
-            boolean hasIccCard = mTm.hasIccCard();
-            int simState = mTm.getSimState();
-            log("hasIccCard=" + hasIccCard
-                    + " simState=" + simState);
-            NetworkInfo[] ni = mCs.getAllNetworkInfo();
-            if (ni != null) {
-                log("ni.length=" + ni.length);
-                for (NetworkInfo netInfo: ni) {
-                    log("netInfo=" + netInfo.toString());
-                }
-            } else {
-                log("no network info ni=null");
-            }
-        }
-
-        /**
-         * Sleep for a few seconds then return.
-         * @param seconds
-         */
-        private static void sleep(int seconds) {
-            try {
-                Thread.sleep(seconds * 1000);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-        }
-
-        private static void log(String s) {
-            Slog.d(ConnectivityService.TAG, "[" + CHECKMP_TAG + "] " + s);
-        }
-    }
-
-    // TODO: Move to ConnectivityManager and make public?
-    private static final String CONNECTED_TO_PROVISIONING_NETWORK_ACTION =
-            "com.android.server.connectivityservice.CONNECTED_TO_PROVISIONING_NETWORK_ACTION";
-
-    private BroadcastReceiver mProvisioningReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(CONNECTED_TO_PROVISIONING_NETWORK_ACTION)) {
-                handleMobileProvisioningAction(intent.getStringExtra("EXTRA_URL"));
-            }
-        }
-    };
-
-    private void handleMobileProvisioningAction(String url) {
-        // Notication mark notification as not visible
-        setProvNotificationVisible(false, ConnectivityManager.TYPE_MOBILE_HIPRI, null, null);
-
-        // If provisioning network handle as a special case,
-        // otherwise launch browser with the intent directly.
-        NetworkInfo ni = getProvisioningNetworkInfo();
-        if ((ni != null) && ni.isConnectedToProvisioningNetwork()) {
-            if (DBG) log("handleMobileProvisioningAction: on provisioning network");
-            MobileDataStateTracker mdst = (MobileDataStateTracker)
-                    mNetTrackers[ConnectivityManager.TYPE_MOBILE];
-            mdst.enableMobileProvisioning(url);
-        } else {
-            if (DBG) log("handleMobileProvisioningAction: on default network");
-            Intent newIntent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
-                    Intent.CATEGORY_APP_BROWSER);
-            newIntent.setData(Uri.parse(url));
-            newIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
-                    Intent.FLAG_ACTIVITY_NEW_TASK);
-            try {
-                mContext.startActivity(newIntent);
-            } catch (ActivityNotFoundException e) {
-                loge("handleMobileProvisioningAction: startActivity failed" + e);
-            }
-        }
-    }
-
-    private static final String NOTIFICATION_ID = "CaptivePortal.Notification";
-    private volatile boolean mIsNotificationVisible = false;
-
-    private void setProvNotificationVisible(boolean visible, int networkType, String extraInfo,
-            String url) {
-        if (DBG) {
-            log("setProvNotificationVisible: E visible=" + visible + " networkType=" + networkType
-                + " extraInfo=" + extraInfo + " url=" + url);
-        }
-
-        Resources r = Resources.getSystem();
-        NotificationManager notificationManager = (NotificationManager) mContext
-            .getSystemService(Context.NOTIFICATION_SERVICE);
-
-        if (visible) {
-            CharSequence title;
-            CharSequence details;
-            int icon;
-            Intent intent;
-            Notification notification = new Notification();
-            switch (networkType) {
-                case ConnectivityManager.TYPE_WIFI:
-                    title = r.getString(R.string.wifi_available_sign_in, 0);
-                    details = r.getString(R.string.network_available_sign_in_detailed,
-                            extraInfo);
-                    icon = R.drawable.stat_notify_wifi_in_range;
-                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
-                    intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
-                            Intent.FLAG_ACTIVITY_NEW_TASK);
-                    notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
-                    break;
-                case ConnectivityManager.TYPE_MOBILE:
-                case ConnectivityManager.TYPE_MOBILE_HIPRI:
-                    title = r.getString(R.string.network_available_sign_in, 0);
-                    // TODO: Change this to pull from NetworkInfo once a printable
-                    // name has been added to it
-                    details = mTelephonyManager.getNetworkOperatorName();
-                    icon = R.drawable.stat_notify_rssi_in_range;
-                    intent = new Intent(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
-                    intent.putExtra("EXTRA_URL", url);
-                    intent.setFlags(0);
-                    notification.contentIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
-                    break;
-                default:
-                    title = r.getString(R.string.network_available_sign_in, 0);
-                    details = r.getString(R.string.network_available_sign_in_detailed,
-                            extraInfo);
-                    icon = R.drawable.stat_notify_rssi_in_range;
-                    intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
-                    intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT |
-                            Intent.FLAG_ACTIVITY_NEW_TASK);
-                    notification.contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
-                    break;
-            }
-
-            notification.when = 0;
-            notification.icon = icon;
-            notification.flags = Notification.FLAG_AUTO_CANCEL;
-            notification.tickerText = title;
-            notification.setLatestEventInfo(mContext, title, details, notification.contentIntent);
-
-            try {
-                notificationManager.notify(NOTIFICATION_ID, networkType, notification);
-            } catch (NullPointerException npe) {
-                loge("setNotificaitionVisible: visible notificationManager npe=" + npe);
-                npe.printStackTrace();
-            }
-        } else {
-            try {
-                notificationManager.cancel(NOTIFICATION_ID, networkType);
-            } catch (NullPointerException npe) {
-                loge("setNotificaitionVisible: cancel notificationManager npe=" + npe);
-                npe.printStackTrace();
-            }
-        }
-        mIsNotificationVisible = visible;
-    }
-
-    /** Location to an updatable file listing carrier provisioning urls.
-     *  An example:
-     *
-     * <?xml version="1.0" encoding="utf-8"?>
-     *  <provisioningUrls>
-     *   <provisioningUrl mcc="310" mnc="4">http://myserver.com/foo?mdn=%3$s&amp;iccid=%1$s&amp;imei=%2$s</provisioningUrl>
-     *   <redirectedUrl mcc="310" mnc="4">http://www.google.com</redirectedUrl>
-     *  </provisioningUrls>
-     */
-    private static final String PROVISIONING_URL_PATH =
-            "/data/misc/radio/provisioning_urls.xml";
-    private final File mProvisioningUrlFile = new File(PROVISIONING_URL_PATH);
-
-    /** XML tag for root element. */
-    private static final String TAG_PROVISIONING_URLS = "provisioningUrls";
-    /** XML tag for individual url */
-    private static final String TAG_PROVISIONING_URL = "provisioningUrl";
-    /** XML tag for redirected url */
-    private static final String TAG_REDIRECTED_URL = "redirectedUrl";
-    /** XML attribute for mcc */
-    private static final String ATTR_MCC = "mcc";
-    /** XML attribute for mnc */
-    private static final String ATTR_MNC = "mnc";
-
-    private static final int REDIRECTED_PROVISIONING = 1;
-    private static final int PROVISIONING = 2;
-
-    private String getProvisioningUrlBaseFromFile(int type) {
-        FileReader fileReader = null;
-        XmlPullParser parser = null;
-        Configuration config = mContext.getResources().getConfiguration();
-        String tagType;
-
-        switch (type) {
-            case PROVISIONING:
-                tagType = TAG_PROVISIONING_URL;
-                break;
-            case REDIRECTED_PROVISIONING:
-                tagType = TAG_REDIRECTED_URL;
-                break;
-            default:
-                throw new RuntimeException("getProvisioningUrlBaseFromFile: Unexpected parameter " +
-                        type);
-        }
-
-        try {
-            fileReader = new FileReader(mProvisioningUrlFile);
-            parser = Xml.newPullParser();
-            parser.setInput(fileReader);
-            XmlUtils.beginDocument(parser, TAG_PROVISIONING_URLS);
-
-            while (true) {
-                XmlUtils.nextElement(parser);
-
-                String element = parser.getName();
-                if (element == null) break;
-
-                if (element.equals(tagType)) {
-                    String mcc = parser.getAttributeValue(null, ATTR_MCC);
-                    try {
-                        if (mcc != null && Integer.parseInt(mcc) == config.mcc) {
-                            String mnc = parser.getAttributeValue(null, ATTR_MNC);
-                            if (mnc != null && Integer.parseInt(mnc) == config.mnc) {
-                                parser.next();
-                                if (parser.getEventType() == XmlPullParser.TEXT) {
-                                    return parser.getText();
-                                }
-                            }
-                        }
-                    } catch (NumberFormatException e) {
-                        loge("NumberFormatException in getProvisioningUrlBaseFromFile: " + e);
-                    }
-                }
-            }
-            return null;
-        } catch (FileNotFoundException e) {
-            loge("Carrier Provisioning Urls file not found");
-        } catch (XmlPullParserException e) {
-            loge("Xml parser exception reading Carrier Provisioning Urls file: " + e);
-        } catch (IOException e) {
-            loge("I/O exception reading Carrier Provisioning Urls file: " + e);
-        } finally {
-            if (fileReader != null) {
-                try {
-                    fileReader.close();
-                } catch (IOException e) {}
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public String getMobileRedirectedProvisioningUrl() {
-        enforceConnectivityInternalPermission();
-        String url = getProvisioningUrlBaseFromFile(REDIRECTED_PROVISIONING);
-        if (TextUtils.isEmpty(url)) {
-            url = mContext.getResources().getString(R.string.mobile_redirected_provisioning_url);
-        }
-        return url;
-    }
-
-    @Override
-    public String getMobileProvisioningUrl() {
-        enforceConnectivityInternalPermission();
-        String url = getProvisioningUrlBaseFromFile(PROVISIONING);
-        if (TextUtils.isEmpty(url)) {
-            url = mContext.getResources().getString(R.string.mobile_provisioning_url);
-            log("getMobileProvisioningUrl: mobile_provisioining_url from resource =" + url);
-        } else {
-            log("getMobileProvisioningUrl: mobile_provisioning_url from File =" + url);
-        }
-        // populate the iccid, imei and phone number in the provisioning url.
-        if (!TextUtils.isEmpty(url)) {
-            String phoneNumber = mTelephonyManager.getLine1Number();
-            if (TextUtils.isEmpty(phoneNumber)) {
-                phoneNumber = "0000000000";
-            }
-            url = String.format(url,
-                    mTelephonyManager.getSimSerialNumber() /* ICCID */,
-                    mTelephonyManager.getDeviceId() /* IMEI */,
-                    phoneNumber /* Phone numer */);
-        }
-
-        return url;
-    }
-
-    @Override
-    public void setProvisioningNotificationVisible(boolean visible, int networkType,
-            String extraInfo, String url) {
-        enforceConnectivityInternalPermission();
-        setProvNotificationVisible(visible, networkType, extraInfo, url);
-    }
-
-    @Override
-    public void setAirplaneMode(boolean enable) {
-        enforceConnectivityInternalPermission();
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            final ContentResolver cr = mContext.getContentResolver();
-            Settings.Global.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, enable ? 1 : 0);
-            Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
-            intent.putExtra("state", enable);
-            mContext.sendBroadcast(intent);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void onUserStart(int userId) {
-        synchronized(mVpns) {
-            Vpn userVpn = mVpns.get(userId);
-            if (userVpn != null) {
-                loge("Starting user already has a VPN");
-                return;
-            }
-            userVpn = new Vpn(mContext, mVpnCallback, mNetd, this, userId);
-            mVpns.put(userId, userVpn);
-            userVpn.startMonitoring(mContext, mTrackerHandler);
-        }
-    }
-
-    private void onUserStop(int userId) {
-        synchronized(mVpns) {
-            Vpn userVpn = mVpns.get(userId);
-            if (userVpn == null) {
-                loge("Stopping user has no VPN");
-                return;
-            }
-            mVpns.delete(userId);
-        }
-    }
-
-    private BroadcastReceiver mUserIntentReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
-            if (userId == UserHandle.USER_NULL) return;
-
-            if (Intent.ACTION_USER_STARTING.equals(action)) {
-                onUserStart(userId);
-            } else if (Intent.ACTION_USER_STOPPING.equals(action)) {
-                onUserStop(userId);
-            }
-        }
-    };
-
-    @Override
-    public LinkQualityInfo getLinkQualityInfo(int networkType) {
-        enforceAccessPermission();
-        if (isNetworkTypeValid(networkType)) {
-            return mNetTrackers[networkType].getLinkQualityInfo();
-        } else {
-            return null;
-        }
-    }
-
-    @Override
-    public LinkQualityInfo getActiveLinkQualityInfo() {
-        enforceAccessPermission();
-        if (isNetworkTypeValid(mActiveDefaultNetwork)) {
-            return mNetTrackers[mActiveDefaultNetwork].getLinkQualityInfo();
-        } else {
-            return null;
-        }
-    }
-
-    @Override
-    public LinkQualityInfo[] getAllLinkQualityInfo() {
-        enforceAccessPermission();
-        final ArrayList<LinkQualityInfo> result = Lists.newArrayList();
-        for (NetworkStateTracker tracker : mNetTrackers) {
-            if (tracker != null) {
-                LinkQualityInfo li = tracker.getLinkQualityInfo();
-                if (li != null) {
-                    result.add(li);
-                }
-            }
-        }
-
-        return result.toArray(new LinkQualityInfo[result.size()]);
-    }
-
-    /* Infrastructure for network sampling */
-
-    private void handleNetworkSamplingTimeout() {
-
-        log("Sampling interval elapsed, updating statistics ..");
-
-        // initialize list of interfaces ..
-        Map<String, SamplingDataTracker.SamplingSnapshot> mapIfaceToSample =
-                new HashMap<String, SamplingDataTracker.SamplingSnapshot>();
-        for (NetworkStateTracker tracker : mNetTrackers) {
-            if (tracker != null) {
-                String ifaceName = tracker.getNetworkInterfaceName();
-                if (ifaceName != null) {
-                    mapIfaceToSample.put(ifaceName, null);
-                }
-            }
-        }
-
-        // Read samples for all interfaces
-        SamplingDataTracker.getSamplingSnapshots(mapIfaceToSample);
-
-        // process samples for all networks
-        for (NetworkStateTracker tracker : mNetTrackers) {
-            if (tracker != null) {
-                String ifaceName = tracker.getNetworkInterfaceName();
-                SamplingDataTracker.SamplingSnapshot ss = mapIfaceToSample.get(ifaceName);
-                if (ss != null) {
-                    // end the previous sampling cycle
-                    tracker.stopSampling(ss);
-                    // start a new sampling cycle ..
-                    tracker.startSampling(ss);
-                }
-            }
-        }
-
-        log("Done.");
-
-        int samplingIntervalInSeconds = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.CONNECTIVITY_SAMPLING_INTERVAL_IN_SECONDS,
-                DEFAULT_SAMPLING_INTERVAL_IN_SECONDS);
-
-        if (DBG) log("Setting timer for " + String.valueOf(samplingIntervalInSeconds) + "seconds");
-
-        setAlarm(samplingIntervalInSeconds * 1000, mSampleIntervalElapsedIntent);
-    }
-
-    void setAlarm(int timeoutInMilliseconds, PendingIntent intent) {
-        long wakeupTime = SystemClock.elapsedRealtime() + timeoutInMilliseconds;
-        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, wakeupTime, intent);
-    }
-}
diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java
deleted file mode 100644
index 2bb99d6..0000000
--- a/services/java/com/android/server/DevicePolicyManagerService.java
+++ /dev/null
@@ -1,2942 +0,0 @@
-/*
- * Copyright (C) 2010 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;
-
-import static android.Manifest.permission.MANAGE_CA_CERTIFICATES;
-
-import com.android.internal.R;
-import com.android.internal.os.storage.ExternalStorageFormatter;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.JournaledFile;
-import com.android.internal.util.XmlUtils;
-import com.android.internal.widget.LockPatternUtils;
-import com.android.org.conscrypt.TrustedCertificateStore;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.app.Activity;
-import android.app.ActivityManagerNative;
-import android.app.AlarmManager;
-import android.app.AppGlobals;
-import android.app.INotificationManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.admin.DeviceAdminInfo;
-import android.app.admin.DeviceAdminReceiver;
-import android.app.admin.DevicePolicyManager;
-import android.app.admin.IDevicePolicyManager;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.Signature;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
-import android.content.pm.UserInfo;
-import android.net.ProxyProperties;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.IPowerManager;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RecoverySystem;
-import android.os.RemoteCallback;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.provider.Settings;
-import android.security.Credentials;
-import android.security.IKeyChainService;
-import android.security.KeyChain;
-import android.security.KeyChain.KeyChainConnection;
-import android.util.AtomicFile;
-import android.util.Log;
-import android.util.PrintWriterPrinter;
-import android.util.Printer;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.Xml;
-import android.view.IWindowManager;
-import android.view.WindowManagerPolicy;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.security.KeyStore.TrustedCertificateEntry;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Implementation of the device policy APIs.
- */
-public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
-
-    private static final String TAG = "DevicePolicyManagerService";
-
-    private static final String DEVICE_POLICIES_XML = "device_policies.xml";
-
-    private static final int REQUEST_EXPIRE_PASSWORD = 5571;
-
-    private static final long MS_PER_DAY = 86400 * 1000;
-
-    private static final long EXPIRATION_GRACE_PERIOD_MS = 5 * MS_PER_DAY; // 5 days, in ms
-
-    protected static final String ACTION_EXPIRED_PASSWORD_NOTIFICATION
-            = "com.android.server.ACTION_EXPIRED_PASSWORD_NOTIFICATION";
-
-    private static final int MONITORING_CERT_NOTIFICATION_ID = R.string.ssl_ca_cert_warning;
-
-    private static final boolean DBG = false;
-
-    final Context mContext;
-    final PowerManager.WakeLock mWakeLock;
-
-    IPowerManager mIPowerManager;
-    IWindowManager mIWindowManager;
-    NotificationManager mNotificationManager;
-
-    private DeviceOwner mDeviceOwner;
-
-    /**
-     * Whether or not device admin feature is supported. If it isn't return defaults for all
-     * public methods.
-     */
-    private boolean mHasFeature;
-
-    public static class DevicePolicyData {
-        int mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
-        int mActivePasswordLength = 0;
-        int mActivePasswordUpperCase = 0;
-        int mActivePasswordLowerCase = 0;
-        int mActivePasswordLetters = 0;
-        int mActivePasswordNumeric = 0;
-        int mActivePasswordSymbols = 0;
-        int mActivePasswordNonLetter = 0;
-        int mFailedPasswordAttempts = 0;
-
-        int mUserHandle;;
-        int mPasswordOwner = -1;
-        long mLastMaximumTimeToLock = -1;
-
-        final HashMap<ComponentName, ActiveAdmin> mAdminMap
-                = new HashMap<ComponentName, ActiveAdmin>();
-        final ArrayList<ActiveAdmin> mAdminList
-                = new ArrayList<ActiveAdmin>();
-
-        public DevicePolicyData(int userHandle) {
-            mUserHandle = userHandle;
-        }
-    }
-
-    final SparseArray<DevicePolicyData> mUserData = new SparseArray<DevicePolicyData>();
-
-    Handler mHandler = new Handler();
-
-    BroadcastReceiver mReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            final int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
-                    getSendingUserId());
-            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
-                    || ACTION_EXPIRED_PASSWORD_NOTIFICATION.equals(action)) {
-                if (DBG) Slog.v(TAG, "Sending password expiration notifications for action "
-                        + action + " for user " + userHandle);
-                mHandler.post(new Runnable() {
-                    public void run() {
-                        handlePasswordExpirationNotification(getUserData(userHandle));
-                    }
-                });
-            }
-            if (Intent.ACTION_BOOT_COMPLETED.equals(action)
-                    || KeyChain.ACTION_STORAGE_CHANGED.equals(action)) {
-                manageMonitoringCertificateNotification(intent);
-            }
-            if (Intent.ACTION_USER_REMOVED.equals(action)) {
-                removeUserData(userHandle);
-            } else if (Intent.ACTION_USER_STARTED.equals(action)
-                    || Intent.ACTION_PACKAGE_CHANGED.equals(action)
-                    || Intent.ACTION_PACKAGE_REMOVED.equals(action)
-                    || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
-
-                if (Intent.ACTION_USER_STARTED.equals(action)) {
-                    // Reset the policy data
-                    synchronized (DevicePolicyManagerService.this) {
-                        mUserData.remove(userHandle);
-                    }
-                }
-
-                handlePackagesChanged(userHandle);
-            }
-        }
-    };
-
-    static class ActiveAdmin {
-        final DeviceAdminInfo info;
-
-        int passwordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
-
-        static final int DEF_MINIMUM_PASSWORD_LENGTH = 0;
-        int minimumPasswordLength = DEF_MINIMUM_PASSWORD_LENGTH;
-
-        static final int DEF_PASSWORD_HISTORY_LENGTH = 0;
-        int passwordHistoryLength = DEF_PASSWORD_HISTORY_LENGTH;
-
-        static final int DEF_MINIMUM_PASSWORD_UPPER_CASE = 0;
-        int minimumPasswordUpperCase = DEF_MINIMUM_PASSWORD_UPPER_CASE;
-
-        static final int DEF_MINIMUM_PASSWORD_LOWER_CASE = 0;
-        int minimumPasswordLowerCase = DEF_MINIMUM_PASSWORD_LOWER_CASE;
-
-        static final int DEF_MINIMUM_PASSWORD_LETTERS = 1;
-        int minimumPasswordLetters = DEF_MINIMUM_PASSWORD_LETTERS;
-
-        static final int DEF_MINIMUM_PASSWORD_NUMERIC = 1;
-        int minimumPasswordNumeric = DEF_MINIMUM_PASSWORD_NUMERIC;
-
-        static final int DEF_MINIMUM_PASSWORD_SYMBOLS = 1;
-        int minimumPasswordSymbols = DEF_MINIMUM_PASSWORD_SYMBOLS;
-
-        static final int DEF_MINIMUM_PASSWORD_NON_LETTER = 0;
-        int minimumPasswordNonLetter = DEF_MINIMUM_PASSWORD_NON_LETTER;
-
-        static final long DEF_MAXIMUM_TIME_TO_UNLOCK = 0;
-        long maximumTimeToUnlock = DEF_MAXIMUM_TIME_TO_UNLOCK;
-
-        static final int DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE = 0;
-        int maximumFailedPasswordsForWipe = DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE;
-
-        static final long DEF_PASSWORD_EXPIRATION_TIMEOUT = 0;
-        long passwordExpirationTimeout = DEF_PASSWORD_EXPIRATION_TIMEOUT;
-
-        static final long DEF_PASSWORD_EXPIRATION_DATE = 0;
-        long passwordExpirationDate = DEF_PASSWORD_EXPIRATION_DATE;
-
-        static final int DEF_KEYGUARD_FEATURES_DISABLED = 0; // none
-        int disabledKeyguardFeatures = DEF_KEYGUARD_FEATURES_DISABLED;
-
-        boolean encryptionRequested = false;
-        boolean disableCamera = false;
-
-        // TODO: review implementation decisions with frameworks team
-        boolean specifiesGlobalProxy = false;
-        String globalProxySpec = null;
-        String globalProxyExclusionList = null;
-
-        ActiveAdmin(DeviceAdminInfo _info) {
-            info = _info;
-        }
-
-        int getUid() { return info.getActivityInfo().applicationInfo.uid; }
-
-        public UserHandle getUserHandle() {
-            return new UserHandle(UserHandle.getUserId(info.getActivityInfo().applicationInfo.uid));
-        }
-
-        void writeToXml(XmlSerializer out)
-                throws IllegalArgumentException, IllegalStateException, IOException {
-            out.startTag(null, "policies");
-            info.writePoliciesToXml(out);
-            out.endTag(null, "policies");
-            if (passwordQuality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
-                out.startTag(null, "password-quality");
-                out.attribute(null, "value", Integer.toString(passwordQuality));
-                out.endTag(null, "password-quality");
-                if (minimumPasswordLength != DEF_MINIMUM_PASSWORD_LENGTH) {
-                    out.startTag(null, "min-password-length");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordLength));
-                    out.endTag(null, "min-password-length");
-                }
-                if(passwordHistoryLength != DEF_PASSWORD_HISTORY_LENGTH) {
-                    out.startTag(null, "password-history-length");
-                    out.attribute(null, "value", Integer.toString(passwordHistoryLength));
-                    out.endTag(null, "password-history-length");
-                }
-                if (minimumPasswordUpperCase != DEF_MINIMUM_PASSWORD_UPPER_CASE) {
-                    out.startTag(null, "min-password-uppercase");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordUpperCase));
-                    out.endTag(null, "min-password-uppercase");
-                }
-                if (minimumPasswordLowerCase != DEF_MINIMUM_PASSWORD_LOWER_CASE) {
-                    out.startTag(null, "min-password-lowercase");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordLowerCase));
-                    out.endTag(null, "min-password-lowercase");
-                }
-                if (minimumPasswordLetters != DEF_MINIMUM_PASSWORD_LETTERS) {
-                    out.startTag(null, "min-password-letters");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordLetters));
-                    out.endTag(null, "min-password-letters");
-                }
-                if (minimumPasswordNumeric != DEF_MINIMUM_PASSWORD_NUMERIC) {
-                    out.startTag(null, "min-password-numeric");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordNumeric));
-                    out.endTag(null, "min-password-numeric");
-                }
-                if (minimumPasswordSymbols != DEF_MINIMUM_PASSWORD_SYMBOLS) {
-                    out.startTag(null, "min-password-symbols");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordSymbols));
-                    out.endTag(null, "min-password-symbols");
-                }
-                if (minimumPasswordNonLetter > DEF_MINIMUM_PASSWORD_NON_LETTER) {
-                    out.startTag(null, "min-password-nonletter");
-                    out.attribute(null, "value", Integer.toString(minimumPasswordNonLetter));
-                    out.endTag(null, "min-password-nonletter");
-                }
-            }
-            if (maximumTimeToUnlock != DEF_MAXIMUM_TIME_TO_UNLOCK) {
-                out.startTag(null, "max-time-to-unlock");
-                out.attribute(null, "value", Long.toString(maximumTimeToUnlock));
-                out.endTag(null, "max-time-to-unlock");
-            }
-            if (maximumFailedPasswordsForWipe != DEF_MAXIMUM_FAILED_PASSWORDS_FOR_WIPE) {
-                out.startTag(null, "max-failed-password-wipe");
-                out.attribute(null, "value", Integer.toString(maximumFailedPasswordsForWipe));
-                out.endTag(null, "max-failed-password-wipe");
-            }
-            if (specifiesGlobalProxy) {
-                out.startTag(null, "specifies-global-proxy");
-                out.attribute(null, "value", Boolean.toString(specifiesGlobalProxy));
-                out.endTag(null, "specifies_global_proxy");
-                if (globalProxySpec != null) {
-                    out.startTag(null, "global-proxy-spec");
-                    out.attribute(null, "value", globalProxySpec);
-                    out.endTag(null, "global-proxy-spec");
-                }
-                if (globalProxyExclusionList != null) {
-                    out.startTag(null, "global-proxy-exclusion-list");
-                    out.attribute(null, "value", globalProxyExclusionList);
-                    out.endTag(null, "global-proxy-exclusion-list");
-                }
-            }
-            if (passwordExpirationTimeout != DEF_PASSWORD_EXPIRATION_TIMEOUT) {
-                out.startTag(null, "password-expiration-timeout");
-                out.attribute(null, "value", Long.toString(passwordExpirationTimeout));
-                out.endTag(null, "password-expiration-timeout");
-            }
-            if (passwordExpirationDate != DEF_PASSWORD_EXPIRATION_DATE) {
-                out.startTag(null, "password-expiration-date");
-                out.attribute(null, "value", Long.toString(passwordExpirationDate));
-                out.endTag(null, "password-expiration-date");
-            }
-            if (encryptionRequested) {
-                out.startTag(null, "encryption-requested");
-                out.attribute(null, "value", Boolean.toString(encryptionRequested));
-                out.endTag(null, "encryption-requested");
-            }
-            if (disableCamera) {
-                out.startTag(null, "disable-camera");
-                out.attribute(null, "value", Boolean.toString(disableCamera));
-                out.endTag(null, "disable-camera");
-            }
-            if (disabledKeyguardFeatures != DEF_KEYGUARD_FEATURES_DISABLED) {
-                out.startTag(null, "disable-keyguard-features");
-                out.attribute(null, "value", Integer.toString(disabledKeyguardFeatures));
-                out.endTag(null, "disable-keyguard-features");
-            }
-        }
-
-        void readFromXml(XmlPullParser parser)
-                throws XmlPullParserException, IOException {
-            int outerDepth = parser.getDepth();
-            int type;
-            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                   && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-                String tag = parser.getName();
-                if ("policies".equals(tag)) {
-                    info.readPoliciesFromXml(parser);
-                } else if ("password-quality".equals(tag)) {
-                    passwordQuality = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-length".equals(tag)) {
-                    minimumPasswordLength = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("password-history-length".equals(tag)) {
-                    passwordHistoryLength = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-uppercase".equals(tag)) {
-                    minimumPasswordUpperCase = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-lowercase".equals(tag)) {
-                    minimumPasswordLowerCase = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-letters".equals(tag)) {
-                    minimumPasswordLetters = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-numeric".equals(tag)) {
-                    minimumPasswordNumeric = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-symbols".equals(tag)) {
-                    minimumPasswordSymbols = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("min-password-nonletter".equals(tag)) {
-                    minimumPasswordNonLetter = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("max-time-to-unlock".equals(tag)) {
-                    maximumTimeToUnlock = Long.parseLong(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("max-failed-password-wipe".equals(tag)) {
-                    maximumFailedPasswordsForWipe = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("specifies-global-proxy".equals(tag)) {
-                    specifiesGlobalProxy = Boolean.parseBoolean(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("global-proxy-spec".equals(tag)) {
-                    globalProxySpec =
-                        parser.getAttributeValue(null, "value");
-                } else if ("global-proxy-exclusion-list".equals(tag)) {
-                    globalProxyExclusionList =
-                        parser.getAttributeValue(null, "value");
-                } else if ("password-expiration-timeout".equals(tag)) {
-                    passwordExpirationTimeout = Long.parseLong(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("password-expiration-date".equals(tag)) {
-                    passwordExpirationDate = Long.parseLong(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("encryption-requested".equals(tag)) {
-                    encryptionRequested = Boolean.parseBoolean(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("disable-camera".equals(tag)) {
-                    disableCamera = Boolean.parseBoolean(
-                            parser.getAttributeValue(null, "value"));
-                } else if ("disable-keyguard-features".equals(tag)) {
-                    disabledKeyguardFeatures = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                } else {
-                    Slog.w(TAG, "Unknown admin tag: " + tag);
-                }
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-
-        void dump(String prefix, PrintWriter pw) {
-            pw.print(prefix); pw.print("uid="); pw.println(getUid());
-            pw.print(prefix); pw.println("policies:");
-            ArrayList<DeviceAdminInfo.PolicyInfo> pols = info.getUsedPolicies();
-            if (pols != null) {
-                for (int i=0; i<pols.size(); i++) {
-                    pw.print(prefix); pw.print("  "); pw.println(pols.get(i).tag);
-                }
-            }
-            pw.print(prefix); pw.print("passwordQuality=0x");
-                    pw.println(Integer.toHexString(passwordQuality));
-            pw.print(prefix); pw.print("minimumPasswordLength=");
-                    pw.println(minimumPasswordLength);
-            pw.print(prefix); pw.print("passwordHistoryLength=");
-                    pw.println(passwordHistoryLength);
-            pw.print(prefix); pw.print("minimumPasswordUpperCase=");
-                    pw.println(minimumPasswordUpperCase);
-            pw.print(prefix); pw.print("minimumPasswordLowerCase=");
-                    pw.println(minimumPasswordLowerCase);
-            pw.print(prefix); pw.print("minimumPasswordLetters=");
-                    pw.println(minimumPasswordLetters);
-            pw.print(prefix); pw.print("minimumPasswordNumeric=");
-                    pw.println(minimumPasswordNumeric);
-            pw.print(prefix); pw.print("minimumPasswordSymbols=");
-                    pw.println(minimumPasswordSymbols);
-            pw.print(prefix); pw.print("minimumPasswordNonLetter=");
-                    pw.println(minimumPasswordNonLetter);
-            pw.print(prefix); pw.print("maximumTimeToUnlock=");
-                    pw.println(maximumTimeToUnlock);
-            pw.print(prefix); pw.print("maximumFailedPasswordsForWipe=");
-                    pw.println(maximumFailedPasswordsForWipe);
-            pw.print(prefix); pw.print("specifiesGlobalProxy=");
-                    pw.println(specifiesGlobalProxy);
-            pw.print(prefix); pw.print("passwordExpirationTimeout=");
-                    pw.println(passwordExpirationTimeout);
-            pw.print(prefix); pw.print("passwordExpirationDate=");
-                    pw.println(passwordExpirationDate);
-            if (globalProxySpec != null) {
-                pw.print(prefix); pw.print("globalProxySpec=");
-                        pw.println(globalProxySpec);
-            }
-            if (globalProxyExclusionList != null) {
-                pw.print(prefix); pw.print("globalProxyEclusionList=");
-                        pw.println(globalProxyExclusionList);
-            }
-            pw.print(prefix); pw.print("encryptionRequested=");
-                    pw.println(encryptionRequested);
-            pw.print(prefix); pw.print("disableCamera=");
-                    pw.println(disableCamera);
-            pw.print(prefix); pw.print("disabledKeyguardFeatures=");
-                    pw.println(disabledKeyguardFeatures);
-        }
-    }
-
-    private void handlePackagesChanged(int userHandle) {
-        boolean removed = false;
-        if (DBG) Slog.d(TAG, "Handling package changes for user " + userHandle);
-        DevicePolicyData policy = getUserData(userHandle);
-        IPackageManager pm = AppGlobals.getPackageManager();
-        for (int i = policy.mAdminList.size() - 1; i >= 0; i--) {
-            ActiveAdmin aa = policy.mAdminList.get(i);
-            try {
-                if (pm.getPackageInfo(aa.info.getPackageName(), 0, userHandle) == null
-                        || pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle) == null) {
-                    removed = true;
-                    policy.mAdminList.remove(i);
-                    policy.mAdminMap.remove(aa.info.getComponent());
-                }
-            } catch (RemoteException re) {
-                // Shouldn't happen
-            }
-        }
-        if (removed) {
-            validatePasswordOwnerLocked(policy);
-            syncDeviceCapabilitiesLocked(policy);
-            saveSettingsLocked(policy.mUserHandle);
-        }
-    }
-
-    /**
-     * Instantiates the service.
-     */
-    public DevicePolicyManagerService(Context context) {
-        mContext = context;
-        mHasFeature = context.getPackageManager().hasSystemFeature(
-                PackageManager.FEATURE_DEVICE_ADMIN);
-        mWakeLock = ((PowerManager)context.getSystemService(Context.POWER_SERVICE))
-                .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DPM");
-        if (!mHasFeature) {
-            // Skip the rest of the initialization
-            return;
-        }
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_BOOT_COMPLETED);
-        filter.addAction(ACTION_EXPIRED_PASSWORD_NOTIFICATION);
-        filter.addAction(Intent.ACTION_USER_REMOVED);
-        filter.addAction(Intent.ACTION_USER_STARTED);
-        filter.addAction(KeyChain.ACTION_STORAGE_CHANGED);
-        context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler);
-        filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
-        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
-        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
-        filter.addDataScheme("package");
-        context.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler);
-    }
-
-    /**
-     * Creates and loads the policy data from xml.
-     * @param userHandle the user for whom to load the policy data
-     * @return
-     */
-    DevicePolicyData getUserData(int userHandle) {
-        synchronized (this) {
-            DevicePolicyData policy = mUserData.get(userHandle);
-            if (policy == null) {
-                policy = new DevicePolicyData(userHandle);
-                mUserData.append(userHandle, policy);
-                loadSettingsLocked(policy, userHandle);
-            }
-            return policy;
-        }
-    }
-
-    void removeUserData(int userHandle) {
-        synchronized (this) {
-            if (userHandle == UserHandle.USER_OWNER) {
-                Slog.w(TAG, "Tried to remove device policy file for user 0! Ignoring.");
-                return;
-            }
-            DevicePolicyData policy = mUserData.get(userHandle);
-            if (policy != null) {
-                mUserData.remove(userHandle);
-            }
-            File policyFile = new File(Environment.getUserSystemDirectory(userHandle),
-                    DEVICE_POLICIES_XML);
-            policyFile.delete();
-            Slog.i(TAG, "Removed device policy file " + policyFile.getAbsolutePath());
-        }
-    }
-
-    void loadDeviceOwner() {
-        synchronized (this) {
-            if (DeviceOwner.isRegistered()) {
-                mDeviceOwner = new DeviceOwner();
-            }
-        }
-    }
-
-    /**
-     * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
-     * reminders.  Clears alarm if no expirations are configured.
-     */
-    protected void setExpirationAlarmCheckLocked(Context context, DevicePolicyData policy) {
-        final long expiration = getPasswordExpirationLocked(null, policy.mUserHandle);
-        final long now = System.currentTimeMillis();
-        final long timeToExpire = expiration - now;
-        final long alarmTime;
-        if (expiration == 0) {
-            // No expirations are currently configured:  Cancel alarm.
-            alarmTime = 0;
-        } else if (timeToExpire <= 0) {
-            // The password has already expired:  Repeat every 24 hours.
-            alarmTime = now + MS_PER_DAY;
-        } else {
-            // Selecting the next alarm time:  Roll forward to the next 24 hour multiple before
-            // the expiration time.
-            long alarmInterval = timeToExpire % MS_PER_DAY;
-            if (alarmInterval == 0) {
-                alarmInterval = MS_PER_DAY;
-            }
-            alarmTime = now + alarmInterval;
-        }
-
-        long token = Binder.clearCallingIdentity();
-        try {
-            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
-            PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD,
-                    new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION),
-                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT,
-                    new UserHandle(policy.mUserHandle));
-            am.cancel(pi);
-            if (alarmTime != 0) {
-                am.set(AlarmManager.RTC, alarmTime, pi);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private IPowerManager getIPowerManager() {
-        if (mIPowerManager == null) {
-            IBinder b = ServiceManager.getService(Context.POWER_SERVICE);
-            mIPowerManager = IPowerManager.Stub.asInterface(b);
-        }
-        return mIPowerManager;
-    }
-
-    private IWindowManager getWindowManager() {
-        if (mIWindowManager == null) {
-            IBinder b = ServiceManager.getService(Context.WINDOW_SERVICE);
-            mIWindowManager = IWindowManager.Stub.asInterface(b);
-        }
-        return mIWindowManager;
-    }
-
-    private NotificationManager getNotificationManager() {
-        if (mNotificationManager == null) {
-            mNotificationManager =
-                    (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-        }
-        return mNotificationManager;
-    }
-
-    ActiveAdmin getActiveAdminUncheckedLocked(ComponentName who, int userHandle) {
-        ActiveAdmin admin = getUserData(userHandle).mAdminMap.get(who);
-        if (admin != null
-                && who.getPackageName().equals(admin.info.getActivityInfo().packageName)
-                && who.getClassName().equals(admin.info.getActivityInfo().name)) {
-            return admin;
-        }
-        return null;
-    }
-
-    ActiveAdmin getActiveAdminForCallerLocked(ComponentName who, int reqPolicy)
-            throws SecurityException {
-        final int callingUid = Binder.getCallingUid();
-        final int userHandle = UserHandle.getUserId(callingUid);
-        final DevicePolicyData policy = getUserData(userHandle);
-        if (who != null) {
-            ActiveAdmin admin = policy.mAdminMap.get(who);
-            if (admin == null) {
-                throw new SecurityException("No active admin " + who);
-            }
-            if (admin.getUid() != callingUid) {
-                throw new SecurityException("Admin " + who + " is not owned by uid "
-                        + Binder.getCallingUid());
-            }
-            if (!admin.info.usesPolicy(reqPolicy)) {
-                throw new SecurityException("Admin " + admin.info.getComponent()
-                        + " did not specify uses-policy for: "
-                        + admin.info.getTagForPolicy(reqPolicy));
-            }
-            return admin;
-        } else {
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (admin.getUid() == callingUid && admin.info.usesPolicy(reqPolicy)) {
-                    return admin;
-                }
-            }
-            throw new SecurityException("No active admin owned by uid "
-                    + Binder.getCallingUid() + " for policy #" + reqPolicy);
-        }
-    }
-
-    void sendAdminCommandLocked(ActiveAdmin admin, String action) {
-        sendAdminCommandLocked(admin, action, null);
-    }
-
-    void sendAdminCommandLocked(ActiveAdmin admin, String action, BroadcastReceiver result) {
-        Intent intent = new Intent(action);
-        intent.setComponent(admin.info.getComponent());
-        if (action.equals(DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING)) {
-            intent.putExtra("expiration", admin.passwordExpirationDate);
-        }
-        if (result != null) {
-            mContext.sendOrderedBroadcastAsUser(intent, admin.getUserHandle(),
-                    null, result, mHandler, Activity.RESULT_OK, null, null);
-        } else {
-            mContext.sendBroadcastAsUser(intent, UserHandle.OWNER);
-        }
-    }
-
-    void sendAdminCommandLocked(String action, int reqPolicy, int userHandle) {
-        final DevicePolicyData policy = getUserData(userHandle);
-        final int count = policy.mAdminList.size();
-        if (count > 0) {
-            for (int i = 0; i < count; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (admin.info.usesPolicy(reqPolicy)) {
-                    sendAdminCommandLocked(admin, action);
-                }
-            }
-        }
-    }
-
-    void removeActiveAdminLocked(final ComponentName adminReceiver, int userHandle) {
-        final ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
-        if (admin != null) {
-            sendAdminCommandLocked(admin,
-                    DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED,
-                    new BroadcastReceiver() {
-                        @Override
-                        public void onReceive(Context context, Intent intent) {
-                            synchronized (DevicePolicyManagerService.this) {
-                                int userHandle = admin.getUserHandle().getIdentifier();
-                                DevicePolicyData policy = getUserData(userHandle);
-                                boolean doProxyCleanup = admin.info.usesPolicy(
-                                        DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY);
-                                policy.mAdminList.remove(admin);
-                                policy.mAdminMap.remove(adminReceiver);
-                                validatePasswordOwnerLocked(policy);
-                                syncDeviceCapabilitiesLocked(policy);
-                                if (doProxyCleanup) {
-                                    resetGlobalProxyLocked(getUserData(userHandle));
-                                }
-                                saveSettingsLocked(userHandle);
-                                updateMaximumTimeToLockLocked(policy);
-                            }
-                        }
-            });
-        }
-    }
-
-    public DeviceAdminInfo findAdmin(ComponentName adminName, int userHandle) {
-        if (!mHasFeature) {
-            return null;
-        }
-        enforceCrossUserPermission(userHandle);
-        Intent resolveIntent = new Intent();
-        resolveIntent.setComponent(adminName);
-        List<ResolveInfo> infos = mContext.getPackageManager().queryBroadcastReceivers(
-                resolveIntent,
-                PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
-                userHandle);
-        if (infos == null || infos.size() <= 0) {
-            throw new IllegalArgumentException("Unknown admin: " + adminName);
-        }
-
-        try {
-            return new DeviceAdminInfo(mContext, infos.get(0));
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e);
-            return null;
-        } catch (IOException e) {
-            Slog.w(TAG, "Bad device admin requested for user=" + userHandle + ": " + adminName, e);
-            return null;
-        }
-    }
-
-    private static JournaledFile makeJournaledFile(int userHandle) {
-        final String base = userHandle == 0
-                ? "/data/system/" + DEVICE_POLICIES_XML
-                : new File(Environment.getUserSystemDirectory(userHandle), DEVICE_POLICIES_XML)
-                        .getAbsolutePath();
-        return new JournaledFile(new File(base), new File(base + ".tmp"));
-    }
-
-    private void saveSettingsLocked(int userHandle) {
-        DevicePolicyData policy = getUserData(userHandle);
-        JournaledFile journal = makeJournaledFile(userHandle);
-        FileOutputStream stream = null;
-        try {
-            stream = new FileOutputStream(journal.chooseForWrite(), false);
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(stream, "utf-8");
-            out.startDocument(null, true);
-
-            out.startTag(null, "policies");
-
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                ActiveAdmin ap = policy.mAdminList.get(i);
-                if (ap != null) {
-                    out.startTag(null, "admin");
-                    out.attribute(null, "name", ap.info.getComponent().flattenToString());
-                    ap.writeToXml(out);
-                    out.endTag(null, "admin");
-                }
-            }
-
-            if (policy.mPasswordOwner >= 0) {
-                out.startTag(null, "password-owner");
-                out.attribute(null, "value", Integer.toString(policy.mPasswordOwner));
-                out.endTag(null, "password-owner");
-            }
-
-            if (policy.mFailedPasswordAttempts != 0) {
-                out.startTag(null, "failed-password-attempts");
-                out.attribute(null, "value", Integer.toString(policy.mFailedPasswordAttempts));
-                out.endTag(null, "failed-password-attempts");
-            }
-
-            if (policy.mActivePasswordQuality != 0 || policy.mActivePasswordLength != 0
-                    || policy.mActivePasswordUpperCase != 0 || policy.mActivePasswordLowerCase != 0
-                    || policy.mActivePasswordLetters != 0 || policy.mActivePasswordNumeric != 0
-                    || policy.mActivePasswordSymbols != 0 || policy.mActivePasswordNonLetter != 0) {
-                out.startTag(null, "active-password");
-                out.attribute(null, "quality", Integer.toString(policy.mActivePasswordQuality));
-                out.attribute(null, "length", Integer.toString(policy.mActivePasswordLength));
-                out.attribute(null, "uppercase", Integer.toString(policy.mActivePasswordUpperCase));
-                out.attribute(null, "lowercase", Integer.toString(policy.mActivePasswordLowerCase));
-                out.attribute(null, "letters", Integer.toString(policy.mActivePasswordLetters));
-                out.attribute(null, "numeric", Integer
-                        .toString(policy.mActivePasswordNumeric));
-                out.attribute(null, "symbols", Integer.toString(policy.mActivePasswordSymbols));
-                out.attribute(null, "nonletter", Integer.toString(policy.mActivePasswordNonLetter));
-                out.endTag(null, "active-password");
-            }
-
-            out.endTag(null, "policies");
-
-            out.endDocument();
-            stream.close();
-            journal.commit();
-            sendChangedNotification(userHandle);
-        } catch (IOException e) {
-            try {
-                if (stream != null) {
-                    stream.close();
-                }
-            } catch (IOException ex) {
-                // Ignore
-            }
-            journal.rollback();
-        }
-    }
-
-    private void sendChangedNotification(int userHandle) {
-        Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
-        intent.setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-        long ident = Binder.clearCallingIdentity();
-        try {
-            mContext.sendBroadcastAsUser(intent, new UserHandle(userHandle));
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void loadSettingsLocked(DevicePolicyData policy, int userHandle) {
-        JournaledFile journal = makeJournaledFile(userHandle);
-        FileInputStream stream = null;
-        File file = journal.chooseForRead();
-        try {
-            stream = new FileInputStream(file);
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(stream, null);
-
-            int type;
-            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                    && type != XmlPullParser.START_TAG) {
-            }
-            String tag = parser.getName();
-            if (!"policies".equals(tag)) {
-                throw new XmlPullParserException(
-                        "Settings do not start with policies tag: found " + tag);
-            }
-            type = parser.next();
-            int outerDepth = parser.getDepth();
-            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                   && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-                tag = parser.getName();
-                if ("admin".equals(tag)) {
-                    String name = parser.getAttributeValue(null, "name");
-                    try {
-                        DeviceAdminInfo dai = findAdmin(
-                                ComponentName.unflattenFromString(name), userHandle);
-                        if (DBG && (UserHandle.getUserId(dai.getActivityInfo().applicationInfo.uid)
-                                != userHandle)) {
-                            Slog.w(TAG, "findAdmin returned an incorrect uid "
-                                    + dai.getActivityInfo().applicationInfo.uid + " for user "
-                                    + userHandle);
-                        }
-                        if (dai != null) {
-                            ActiveAdmin ap = new ActiveAdmin(dai);
-                            ap.readFromXml(parser);
-                            policy.mAdminMap.put(ap.info.getComponent(), ap);
-                            policy.mAdminList.add(ap);
-                        }
-                    } catch (RuntimeException e) {
-                        Slog.w(TAG, "Failed loading admin " + name, e);
-                    }
-                } else if ("failed-password-attempts".equals(tag)) {
-                    policy.mFailedPasswordAttempts = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                    XmlUtils.skipCurrentTag(parser);
-                } else if ("password-owner".equals(tag)) {
-                    policy.mPasswordOwner = Integer.parseInt(
-                            parser.getAttributeValue(null, "value"));
-                    XmlUtils.skipCurrentTag(parser);
-                } else if ("active-password".equals(tag)) {
-                    policy.mActivePasswordQuality = Integer.parseInt(
-                            parser.getAttributeValue(null, "quality"));
-                    policy.mActivePasswordLength = Integer.parseInt(
-                            parser.getAttributeValue(null, "length"));
-                    policy.mActivePasswordUpperCase = Integer.parseInt(
-                            parser.getAttributeValue(null, "uppercase"));
-                    policy.mActivePasswordLowerCase = Integer.parseInt(
-                            parser.getAttributeValue(null, "lowercase"));
-                    policy.mActivePasswordLetters = Integer.parseInt(
-                            parser.getAttributeValue(null, "letters"));
-                    policy.mActivePasswordNumeric = Integer.parseInt(
-                            parser.getAttributeValue(null, "numeric"));
-                    policy.mActivePasswordSymbols = Integer.parseInt(
-                            parser.getAttributeValue(null, "symbols"));
-                    policy.mActivePasswordNonLetter = Integer.parseInt(
-                            parser.getAttributeValue(null, "nonletter"));
-                    XmlUtils.skipCurrentTag(parser);
-                } else {
-                    Slog.w(TAG, "Unknown tag: " + tag);
-                    XmlUtils.skipCurrentTag(parser);
-                }
-            }
-        } catch (NullPointerException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (NumberFormatException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (FileNotFoundException e) {
-            // Don't be noisy, this is normal if we haven't defined any policies.
-        } catch (IOException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (IndexOutOfBoundsException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        }
-        try {
-            if (stream != null) {
-                stream.close();
-            }
-        } catch (IOException e) {
-            // Ignore
-        }
-
-        // Validate that what we stored for the password quality matches
-        // sufficiently what is currently set.  Note that this is only
-        // a sanity check in case the two get out of sync; this should
-        // never normally happen.
-        LockPatternUtils utils = new LockPatternUtils(mContext);
-        if (utils.getActivePasswordQuality() < policy.mActivePasswordQuality) {
-            Slog.w(TAG, "Active password quality 0x"
-                    + Integer.toHexString(policy.mActivePasswordQuality)
-                    + " does not match actual quality 0x"
-                    + Integer.toHexString(utils.getActivePasswordQuality()));
-            policy.mActivePasswordQuality = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
-            policy.mActivePasswordLength = 0;
-            policy.mActivePasswordUpperCase = 0;
-            policy.mActivePasswordLowerCase = 0;
-            policy.mActivePasswordLetters = 0;
-            policy.mActivePasswordNumeric = 0;
-            policy.mActivePasswordSymbols = 0;
-            policy.mActivePasswordNonLetter = 0;
-        }
-
-        validatePasswordOwnerLocked(policy);
-        syncDeviceCapabilitiesLocked(policy);
-        updateMaximumTimeToLockLocked(policy);
-    }
-
-    static void validateQualityConstant(int quality) {
-        switch (quality) {
-            case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
-            case DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK:
-            case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
-            case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
-            case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
-            case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
-            case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
-                return;
-        }
-        throw new IllegalArgumentException("Invalid quality constant: 0x"
-                + Integer.toHexString(quality));
-    }
-
-    void validatePasswordOwnerLocked(DevicePolicyData policy) {
-        if (policy.mPasswordOwner >= 0) {
-            boolean haveOwner = false;
-            for (int i = policy.mAdminList.size() - 1; i >= 0; i--) {
-                if (policy.mAdminList.get(i).getUid() == policy.mPasswordOwner) {
-                    haveOwner = true;
-                    break;
-                }
-            }
-            if (!haveOwner) {
-                Slog.w(TAG, "Previous password owner " + policy.mPasswordOwner
-                        + " no longer active; disabling");
-                policy.mPasswordOwner = -1;
-            }
-        }
-    }
-
-    /**
-     * Pushes down policy information to the system for any policies related to general device
-     * capabilities that need to be enforced by lower level services (e.g. Camera services).
-     */
-    void syncDeviceCapabilitiesLocked(DevicePolicyData policy) {
-        // Ensure the status of the camera is synced down to the system. Interested native services
-        // should monitor this value and act accordingly.
-        boolean systemState = SystemProperties.getBoolean(SYSTEM_PROP_DISABLE_CAMERA, false);
-        boolean cameraDisabled = getCameraDisabled(null, policy.mUserHandle);
-        if (cameraDisabled != systemState) {
-            long token = Binder.clearCallingIdentity();
-            try {
-                String value = cameraDisabled ? "1" : "0";
-                if (DBG) Slog.v(TAG, "Change in camera state ["
-                        + SYSTEM_PROP_DISABLE_CAMERA + "] = " + value);
-                SystemProperties.set(SYSTEM_PROP_DISABLE_CAMERA, value);
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-        }
-    }
-
-    public void systemReady() {
-        if (!mHasFeature) {
-            return;
-        }
-        synchronized (this) {
-            loadSettingsLocked(getUserData(UserHandle.USER_OWNER), UserHandle.USER_OWNER);
-            loadDeviceOwner();
-        }
-    }
-
-    private void handlePasswordExpirationNotification(DevicePolicyData policy) {
-        synchronized (this) {
-            final long now = System.currentTimeMillis();
-            final int N = policy.mAdminList.size();
-            if (N <= 0) {
-                return;
-            }
-            for (int i=0; i < N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD)
-                        && admin.passwordExpirationTimeout > 0L
-                        && admin.passwordExpirationDate > 0L
-                        && now >= admin.passwordExpirationDate - EXPIRATION_GRACE_PERIOD_MS) {
-                    sendAdminCommandLocked(admin, DeviceAdminReceiver.ACTION_PASSWORD_EXPIRING);
-                }
-            }
-            setExpirationAlarmCheckLocked(mContext, policy);
-        }
-    }
-
-    private void manageMonitoringCertificateNotification(Intent intent) {
-        final NotificationManager notificationManager = getNotificationManager();
-
-        final boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled();
-        if (! hasCert) {
-            if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) {
-                UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
-                for (UserInfo user : um.getUsers()) {
-                    notificationManager.cancelAsUser(
-                            null, MONITORING_CERT_NOTIFICATION_ID, user.getUserHandle());
-                }
-            }
-            return;
-        }
-        final boolean isManaged = getDeviceOwner() != null;
-        int smallIconId;
-        String contentText;
-        if (isManaged) {
-            contentText = mContext.getString(R.string.ssl_ca_cert_noti_managed,
-                    getDeviceOwnerName());
-            smallIconId = R.drawable.stat_sys_certificate_info;
-        } else {
-            contentText = mContext.getString(R.string.ssl_ca_cert_noti_by_unknown);
-            smallIconId = android.R.drawable.stat_sys_warning;
-        }
-
-        Intent dialogIntent = new Intent(Settings.ACTION_MONITORING_CERT_INFO);
-        dialogIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
-        dialogIntent.setPackage("com.android.settings");
-        // Notification will be sent individually to all users. The activity should start as
-        // whichever user is current when it starts.
-        PendingIntent notifyIntent = PendingIntent.getActivityAsUser(mContext, 0, dialogIntent,
-                PendingIntent.FLAG_UPDATE_CURRENT, null, UserHandle.CURRENT);
-
-        Notification noti = new Notification.Builder(mContext)
-            .setSmallIcon(smallIconId)
-            .setContentTitle(mContext.getString(R.string.ssl_ca_cert_warning))
-            .setContentText(contentText)
-            .setContentIntent(notifyIntent)
-            .setPriority(Notification.PRIORITY_HIGH)
-            .setShowWhen(false)
-            .build();
-
-        // If this is a boot intent, this will fire for each user. But if this is a storage changed
-        // intent, it will fire once, so we need to notify all users.
-        if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) {
-            UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
-            for (UserInfo user : um.getUsers()) {
-                notificationManager.notifyAsUser(
-                        null, MONITORING_CERT_NOTIFICATION_ID, noti, user.getUserHandle());
-            }
-        } else {
-            notificationManager.notifyAsUser(
-                    null, MONITORING_CERT_NOTIFICATION_ID, noti, UserHandle.CURRENT);
-        }
-    }
-
-    /**
-     * @param adminReceiver The admin to add
-     * @param refreshing true = update an active admin, no error
-     */
-    public void setActiveAdmin(ComponentName adminReceiver, boolean refreshing, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.MANAGE_DEVICE_ADMINS, null);
-        enforceCrossUserPermission(userHandle);
-
-        DevicePolicyData policy = getUserData(userHandle);
-        DeviceAdminInfo info = findAdmin(adminReceiver, userHandle);
-        if (info == null) {
-            throw new IllegalArgumentException("Bad admin: " + adminReceiver);
-        }
-        synchronized (this) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                if (!refreshing && getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null) {
-                    throw new IllegalArgumentException("Admin is already added");
-                }
-                ActiveAdmin newAdmin = new ActiveAdmin(info);
-                policy.mAdminMap.put(adminReceiver, newAdmin);
-                int replaceIndex = -1;
-                if (refreshing) {
-                    final int N = policy.mAdminList.size();
-                    for (int i=0; i < N; i++) {
-                        ActiveAdmin oldAdmin = policy.mAdminList.get(i);
-                        if (oldAdmin.info.getComponent().equals(adminReceiver)) {
-                            replaceIndex = i;
-                            break;
-                        }
-                    }
-                }
-                if (replaceIndex == -1) {
-                    policy.mAdminList.add(newAdmin);
-                    enableIfNecessary(info.getPackageName(), userHandle);
-                } else {
-                    policy.mAdminList.set(replaceIndex, newAdmin);
-                }
-                saveSettingsLocked(userHandle);
-                sendAdminCommandLocked(newAdmin, DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public boolean isAdminActive(ComponentName adminReceiver, int userHandle) {
-        if (!mHasFeature) {
-            return false;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            return getActiveAdminUncheckedLocked(adminReceiver, userHandle) != null;
-        }
-    }
-
-    public boolean hasGrantedPolicy(ComponentName adminReceiver, int policyId, int userHandle) {
-        if (!mHasFeature) {
-            return false;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            ActiveAdmin administrator = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
-            if (administrator == null) {
-                throw new SecurityException("No active admin " + adminReceiver);
-            }
-            return administrator.info.usesPolicy(policyId);
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<ComponentName> getActiveAdmins(int userHandle) {
-        if (!mHasFeature) {
-            return Collections.EMPTY_LIST;
-        }
-
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            if (N <= 0) {
-                return null;
-            }
-            ArrayList<ComponentName> res = new ArrayList<ComponentName>(N);
-            for (int i=0; i<N; i++) {
-                res.add(policy.mAdminList.get(i).info.getComponent());
-            }
-            return res;
-        }
-    }
-
-    public boolean packageHasActiveAdmins(String packageName, int userHandle) {
-        if (!mHasFeature) {
-            return false;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                if (policy.mAdminList.get(i).info.getPackageName().equals(packageName)) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    public void removeActiveAdmin(ComponentName adminReceiver, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
-            if (admin == null) {
-                return;
-            }
-            if (admin.getUid() != Binder.getCallingUid()) {
-                // If trying to remove device owner, refuse when the caller is not the owner.
-                if (mDeviceOwner != null
-                        && adminReceiver.getPackageName().equals(mDeviceOwner.getPackageName())) {
-                    return;
-                }
-                mContext.enforceCallingOrSelfPermission(
-                        android.Manifest.permission.MANAGE_DEVICE_ADMINS, null);
-            }
-            long ident = Binder.clearCallingIdentity();
-            try {
-                removeActiveAdminLocked(adminReceiver, userHandle);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void setPasswordQuality(ComponentName who, int quality, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        validateQualityConstant(quality);
-        enforceCrossUserPermission(userHandle);
-
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.passwordQuality != quality) {
-                ap.passwordQuality = quality;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordQuality(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int mode = DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
-            DevicePolicyData policy = getUserData(userHandle);
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.passwordQuality : mode;
-            }
-
-            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;
-        }
-    }
-
-    public void setPasswordMinimumLength(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordLength != length) {
-                ap.minimumPasswordLength = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumLength(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordLength : length;
-            }
-
-            final int N = policy.mAdminList.size();
-            for  (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordLength) {
-                    length = admin.minimumPasswordLength;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordHistoryLength(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.passwordHistoryLength != length) {
-                ap.passwordHistoryLength = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordHistoryLength(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.passwordHistoryLength : length;
-            }
-
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.passwordHistoryLength) {
-                    length = admin.passwordHistoryLength;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordExpirationTimeout(ComponentName who, long timeout, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            if (timeout < 0) {
-                throw new IllegalArgumentException("Timeout must be >= 0 ms");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD);
-            // Calling this API automatically bumps the expiration date
-            final long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L;
-            ap.passwordExpirationDate = expiration;
-            ap.passwordExpirationTimeout = timeout;
-            if (timeout > 0L) {
-                Slog.w(TAG, "setPasswordExpiration(): password will expire on "
-                        + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT)
-                        .format(new Date(expiration)));
-            }
-            saveSettingsLocked(userHandle);
-            // in case this is the first one
-            setExpirationAlarmCheckLocked(mContext, getUserData(userHandle));
-        }
-    }
-
-    /**
-     * Return a single admin's expiration cycle time, or the min of all cycle times.
-     * Returns 0 if not configured.
-     */
-    public long getPasswordExpirationTimeout(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0L;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.passwordExpirationTimeout : 0L;
-            }
-
-            long timeout = 0L;
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (timeout == 0L || (admin.passwordExpirationTimeout != 0L
-                        && timeout > admin.passwordExpirationTimeout)) {
-                    timeout = admin.passwordExpirationTimeout;
-                }
-            }
-            return timeout;
-        }
-    }
-
-    /**
-     * Return a single admin's expiration date/time, or the min (soonest) for all admins.
-     * Returns 0 if not configured.
-     */
-    private long getPasswordExpirationLocked(ComponentName who, int userHandle) {
-        if (who != null) {
-            ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-            return admin != null ? admin.passwordExpirationDate : 0L;
-        }
-
-        long timeout = 0L;
-        DevicePolicyData policy = getUserData(userHandle);
-        final int N = policy.mAdminList.size();
-        for (int i = 0; i < N; i++) {
-            ActiveAdmin admin = policy.mAdminList.get(i);
-            if (timeout == 0L || (admin.passwordExpirationDate != 0
-                    && timeout > admin.passwordExpirationDate)) {
-                timeout = admin.passwordExpirationDate;
-            }
-        }
-        return timeout;
-    }
-
-    public long getPasswordExpiration(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0L;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            return getPasswordExpirationLocked(who, userHandle);
-        }
-    }
-
-    public void setPasswordMinimumUpperCase(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordUpperCase != length) {
-                ap.minimumPasswordUpperCase = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumUpperCase(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordUpperCase : length;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordUpperCase) {
-                    length = admin.minimumPasswordUpperCase;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordMinimumLowerCase(ComponentName who, int length, int userHandle) {
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordLowerCase != length) {
-                ap.minimumPasswordLowerCase = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumLowerCase(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordLowerCase : length;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordLowerCase) {
-                    length = admin.minimumPasswordLowerCase;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordMinimumLetters(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordLetters != length) {
-                ap.minimumPasswordLetters = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumLetters(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordLetters : length;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordLetters) {
-                    length = admin.minimumPasswordLetters;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordMinimumNumeric(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordNumeric != length) {
-                ap.minimumPasswordNumeric = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumNumeric(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordNumeric : length;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordNumeric) {
-                    length = admin.minimumPasswordNumeric;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordMinimumSymbols(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordSymbols != length) {
-                ap.minimumPasswordSymbols = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumSymbols(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordSymbols : length;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for  (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordSymbols) {
-                    length = admin.minimumPasswordSymbols;
-                }
-            }
-            return length;
-        }
-    }
-
-    public void setPasswordMinimumNonLetter(ComponentName who, int length, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD);
-            if (ap.minimumPasswordNonLetter != length) {
-                ap.minimumPasswordNonLetter = length;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getPasswordMinimumNonLetter(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            int length = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.minimumPasswordNonLetter : length;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (length < admin.minimumPasswordNonLetter) {
-                    length = admin.minimumPasswordNonLetter;
-                }
-            }
-            return length;
-        }
-    }
-
-    public boolean isActivePasswordSufficient(int userHandle) {
-        if (!mHasFeature) {
-            return true;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            // 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)
-                    || policy.mActivePasswordLength < getPasswordMinimumLength(null, userHandle)) {
-                return false;
-            }
-            if (policy.mActivePasswordQuality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
-                return true;
-            }
-            return policy.mActivePasswordUpperCase >= getPasswordMinimumUpperCase(null, userHandle)
-                    && policy.mActivePasswordLowerCase >= getPasswordMinimumLowerCase(null, userHandle)
-                    && policy.mActivePasswordLetters >= getPasswordMinimumLetters(null, userHandle)
-                    && policy.mActivePasswordNumeric >= getPasswordMinimumNumeric(null, userHandle)
-                    && policy.mActivePasswordSymbols >= getPasswordMinimumSymbols(null, userHandle)
-                    && policy.mActivePasswordNonLetter >= getPasswordMinimumNonLetter(null, userHandle);
-        }
-    }
-
-    public int getCurrentFailedPasswordAttempts(int userHandle) {
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            // 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_WATCH_LOGIN);
-            return getUserData(userHandle).mFailedPasswordAttempts;
-        }
-    }
-
-    public void setMaximumFailedPasswordsForWipe(ComponentName who, int num, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            // This API can only be called by an active device admin,
-            // so try to retrieve it to check that the caller is one.
-            getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_WIPE_DATA);
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_WATCH_LOGIN);
-            if (ap.maximumFailedPasswordsForWipe != num) {
-                ap.maximumFailedPasswordsForWipe = num;
-                saveSettingsLocked(userHandle);
-            }
-        }
-    }
-
-    public int getMaximumFailedPasswordsForWipe(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            int count = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.maximumFailedPasswordsForWipe : count;
-            }
-
-            final int N = policy.mAdminList.size();
-            for  (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (count == 0) {
-                    count = admin.maximumFailedPasswordsForWipe;
-                } else if (admin.maximumFailedPasswordsForWipe != 0
-                        && count > admin.maximumFailedPasswordsForWipe) {
-                    count = admin.maximumFailedPasswordsForWipe;
-                }
-            }
-            return count;
-        }
-    }
-
-    public boolean resetPassword(String password, int flags, int userHandle) {
-        if (!mHasFeature) {
-            return false;
-        }
-        enforceCrossUserPermission(userHandle);
-        int quality;
-        synchronized (this) {
-            // 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_RESET_PASSWORD);
-            quality = getPasswordQuality(null, userHandle);
-            if (quality != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) {
-                int realQuality = LockPatternUtils.computePasswordQuality(password);
-                if (realQuality < quality
-                        && quality != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
-                    Slog.w(TAG, "resetPassword: password quality 0x"
-                            + Integer.toHexString(realQuality)
-                            + " does not meet required quality 0x"
-                            + Integer.toHexString(quality));
-                    return false;
-                }
-                quality = Math.max(realQuality, quality);
-            }
-            int length = getPasswordMinimumLength(null, userHandle);
-            if (password.length() < length) {
-                Slog.w(TAG, "resetPassword: password length " + password.length()
-                        + " does not meet required length " + length);
-                return false;
-            }
-            if (quality == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) {
-                int letters = 0;
-                int uppercase = 0;
-                int lowercase = 0;
-                int numbers = 0;
-                int symbols = 0;
-                int nonletter = 0;
-                for (int i = 0; i < password.length(); i++) {
-                    char c = password.charAt(i);
-                    if (c >= 'A' && c <= 'Z') {
-                        letters++;
-                        uppercase++;
-                    } else if (c >= 'a' && c <= 'z') {
-                        letters++;
-                        lowercase++;
-                    } else if (c >= '0' && c <= '9') {
-                        numbers++;
-                        nonletter++;
-                    } else {
-                        symbols++;
-                        nonletter++;
-                    }
-                }
-                int neededLetters = getPasswordMinimumLetters(null, userHandle);
-                if(letters < neededLetters) {
-                    Slog.w(TAG, "resetPassword: number of letters " + letters
-                            + " does not meet required number of letters " + neededLetters);
-                    return false;
-                }
-                int neededNumbers = getPasswordMinimumNumeric(null, userHandle);
-                if (numbers < neededNumbers) {
-                    Slog.w(TAG, "resetPassword: number of numerical digits " + numbers
-                            + " does not meet required number of numerical digits "
-                            + neededNumbers);
-                    return false;
-                }
-                int neededLowerCase = getPasswordMinimumLowerCase(null, userHandle);
-                if (lowercase < neededLowerCase) {
-                    Slog.w(TAG, "resetPassword: number of lowercase letters " + lowercase
-                            + " does not meet required number of lowercase letters "
-                            + neededLowerCase);
-                    return false;
-                }
-                int neededUpperCase = getPasswordMinimumUpperCase(null, userHandle);
-                if (uppercase < neededUpperCase) {
-                    Slog.w(TAG, "resetPassword: number of uppercase letters " + uppercase
-                            + " does not meet required number of uppercase letters "
-                            + neededUpperCase);
-                    return false;
-                }
-                int neededSymbols = getPasswordMinimumSymbols(null, userHandle);
-                if (symbols < neededSymbols) {
-                    Slog.w(TAG, "resetPassword: number of special symbols " + symbols
-                            + " does not meet required number of special symbols " + neededSymbols);
-                    return false;
-                }
-                int neededNonLetter = getPasswordMinimumNonLetter(null, userHandle);
-                if (nonletter < neededNonLetter) {
-                    Slog.w(TAG, "resetPassword: number of non-letter characters " + nonletter
-                            + " does not meet required number of non-letter characters "
-                            + neededNonLetter);
-                    return false;
-                }
-            }
-        }
-
-        int callingUid = Binder.getCallingUid();
-        DevicePolicyData policy = getUserData(userHandle);
-        if (policy.mPasswordOwner >= 0 && policy.mPasswordOwner != callingUid) {
-            Slog.w(TAG, "resetPassword: already set by another uid and not entered by user");
-            return false;
-        }
-
-        // Don't do this with the lock held, because it is going to call
-        // back in to the service.
-        long ident = Binder.clearCallingIdentity();
-        try {
-            LockPatternUtils utils = new LockPatternUtils(mContext);
-            utils.saveLockPassword(password, quality, false, userHandle);
-            synchronized (this) {
-                int newOwner = (flags&DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY)
-                        != 0 ? callingUid : -1;
-                if (policy.mPasswordOwner != newOwner) {
-                    policy.mPasswordOwner = newOwner;
-                    saveSettingsLocked(userHandle);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-
-        return true;
-    }
-
-    public void setMaximumTimeToLock(ComponentName who, long timeMs, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_FORCE_LOCK);
-            if (ap.maximumTimeToUnlock != timeMs) {
-                ap.maximumTimeToUnlock = timeMs;
-                saveSettingsLocked(userHandle);
-                updateMaximumTimeToLockLocked(getUserData(userHandle));
-            }
-        }
-    }
-
-    void updateMaximumTimeToLockLocked(DevicePolicyData policy) {
-        long timeMs = getMaximumTimeToLock(null, policy.mUserHandle);
-        if (policy.mLastMaximumTimeToLock == timeMs) {
-            return;
-        }
-
-        long ident = Binder.clearCallingIdentity();
-        try {
-            if (timeMs <= 0) {
-                timeMs = Integer.MAX_VALUE;
-            } else {
-                // Make sure KEEP_SCREEN_ON is disabled, since that
-                // would allow bypassing of the maximum time to lock.
-                Settings.Global.putInt(mContext.getContentResolver(),
-                        Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0);
-            }
-
-            policy.mLastMaximumTimeToLock = timeMs;
-
-            try {
-                getIPowerManager().setMaximumScreenOffTimeoutFromDeviceAdmin((int)timeMs);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Failure talking with power manager", e);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    public long getMaximumTimeToLock(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            long time = 0;
-
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return admin != null ? admin.maximumTimeToUnlock : time;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for  (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (time == 0) {
-                    time = admin.maximumTimeToUnlock;
-                } else if (admin.maximumTimeToUnlock != 0
-                        && time > admin.maximumTimeToUnlock) {
-                    time = admin.maximumTimeToUnlock;
-                }
-            }
-            return time;
-        }
-    }
-
-    public void lockNow() {
-        if (!mHasFeature) {
-            return;
-        }
-        synchronized (this) {
-            // 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_FORCE_LOCK);
-            lockNowUnchecked();
-        }
-    }
-
-    private void lockNowUnchecked() {
-        long ident = Binder.clearCallingIdentity();
-        try {
-            // Power off the display
-            getIPowerManager().goToSleep(SystemClock.uptimeMillis(),
-                    PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN);
-            // Ensure the device is locked
-            getWindowManager().lockNow(null);
-        } catch (RemoteException e) {
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private boolean isExtStorageEncrypted() {
-        String state = SystemProperties.get("vold.decrypt");
-        return !"".equals(state);
-    }
-
-    public boolean installCaCert(byte[] certBuffer) throws RemoteException {
-        mContext.enforceCallingOrSelfPermission(MANAGE_CA_CERTIFICATES, null);
-        KeyChainConnection keyChainConnection = null;
-        byte[] pemCert;
-        try {
-            X509Certificate cert = parseCert(certBuffer);
-            pemCert =  Credentials.convertToPem(cert);
-        } catch (CertificateException ce) {
-            Log.e(TAG, "Problem converting cert", ce);
-            return false;
-        } catch (IOException ioe) {
-            Log.e(TAG, "Problem reading cert", ioe);
-            return false;
-        }
-        try {
-            keyChainConnection = KeyChain.bind(mContext);
-            try {
-                keyChainConnection.getService().installCaCertificate(pemCert);
-                return true;
-            } finally {
-                if (keyChainConnection != null) {
-                    keyChainConnection.close();
-                    keyChainConnection = null;
-                }
-            }
-        } catch (InterruptedException e1) {
-            Log.w(TAG, "installCaCertsToKeyChain(): ", e1);
-            Thread.currentThread().interrupt();
-        }
-        return false;
-    }
-
-    private static X509Certificate parseCert(byte[] certBuffer)
-            throws CertificateException, IOException {
-        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
-        return (X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(
-                certBuffer));
-    }
-
-    public void uninstallCaCert(final byte[] certBuffer) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_CA_CERTIFICATES, null);
-        TrustedCertificateStore certStore = new TrustedCertificateStore();
-        String alias = null;
-        try {
-            X509Certificate cert = parseCert(certBuffer);
-            alias = certStore.getCertificateAlias(cert);
-        } catch (CertificateException ce) {
-            Log.e(TAG, "Problem creating X509Certificate", ce);
-            return;
-        } catch (IOException ioe) {
-            Log.e(TAG, "Problem reading certificate", ioe);
-            return;
-        }
-        try {
-            KeyChainConnection keyChainConnection = KeyChain.bind(mContext);
-            IKeyChainService service = keyChainConnection.getService();
-            try {
-                service.deleteCaCertificate(alias);
-            } catch (RemoteException e) {
-                Log.e(TAG, "from CaCertUninstaller: ", e);
-            } finally {
-                keyChainConnection.close();
-                keyChainConnection = null;
-            }
-        } catch (InterruptedException ie) {
-            Log.w(TAG, "CaCertUninstaller: ", ie);
-            Thread.currentThread().interrupt();
-        }
-    }
-
-    void wipeDataLocked(int flags) {
-        // If the SD card is encrypted and non-removable, we have to force a wipe.
-        boolean forceExtWipe = !Environment.isExternalStorageRemovable() && isExtStorageEncrypted();
-        boolean wipeExtRequested = (flags&DevicePolicyManager.WIPE_EXTERNAL_STORAGE) != 0;
-
-        // Note: we can only do the wipe via ExternalStorageFormatter if the volume is not emulated.
-        if ((forceExtWipe || wipeExtRequested) && !Environment.isExternalStorageEmulated()) {
-            Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
-            intent.putExtra(ExternalStorageFormatter.EXTRA_ALWAYS_RESET, true);
-            intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
-            mWakeLock.acquire(10000);
-            mContext.startService(intent);
-        } else {
-            try {
-                RecoverySystem.rebootWipeUserData(mContext);
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed requesting data wipe", e);
-            }
-        }
-    }
-
-    public void wipeData(int flags, final int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            // 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_WIPE_DATA);
-            long ident = Binder.clearCallingIdentity();
-            try {
-                wipeDeviceOrUserLocked(flags, userHandle);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    private void wipeDeviceOrUserLocked(int flags, final int userHandle) {
-        if (userHandle == UserHandle.USER_OWNER) {
-            wipeDataLocked(flags);
-        } else {
-            lockNowUnchecked();
-            mHandler.post(new Runnable() {
-                public void run() {
-                    try {
-                        ActivityManagerNative.getDefault().switchUser(UserHandle.USER_OWNER);
-                        ((UserManager) mContext.getSystemService(Context.USER_SERVICE))
-                                .removeUser(userHandle);
-                    } catch (RemoteException re) {
-                        // Shouldn't happen
-                    }
-                }
-            });
-        }
-    }
-
-    public void getRemoveWarning(ComponentName comp, final RemoteCallback result, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
-
-        synchronized (this) {
-            ActiveAdmin admin = getActiveAdminUncheckedLocked(comp, userHandle);
-            if (admin == null) {
-                try {
-                    result.sendResult(null);
-                } catch (RemoteException e) {
-                }
-                return;
-            }
-            Intent intent = new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLE_REQUESTED);
-            intent.setComponent(admin.info.getComponent());
-            mContext.sendOrderedBroadcastAsUser(intent, new UserHandle(userHandle),
-                    null, new BroadcastReceiver() {
-                @Override
-                public void onReceive(Context context, Intent intent) {
-                    try {
-                        result.sendResult(getResultExtras(false));
-                    } catch (RemoteException e) {
-                    }
-                }
-            }, null, Activity.RESULT_OK, null, null);
-        }
-    }
-
-    public void setActivePasswordState(int quality, int length, int letters, int uppercase,
-            int lowercase, int numbers, int symbols, int nonletter, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
-        DevicePolicyData p = getUserData(userHandle);
-
-        validateQualityConstant(quality);
-
-        synchronized (this) {
-            if (p.mActivePasswordQuality != quality || p.mActivePasswordLength != length
-                    || p.mFailedPasswordAttempts != 0 || p.mActivePasswordLetters != letters
-                    || p.mActivePasswordUpperCase != uppercase
-                    || p.mActivePasswordLowerCase != lowercase || p.mActivePasswordNumeric != numbers
-                    || p.mActivePasswordSymbols != symbols || p.mActivePasswordNonLetter != nonletter) {
-                long ident = Binder.clearCallingIdentity();
-                try {
-                    p.mActivePasswordQuality = quality;
-                    p.mActivePasswordLength = length;
-                    p.mActivePasswordLetters = letters;
-                    p.mActivePasswordLowerCase = lowercase;
-                    p.mActivePasswordUpperCase = uppercase;
-                    p.mActivePasswordNumeric = numbers;
-                    p.mActivePasswordSymbols = symbols;
-                    p.mActivePasswordNonLetter = nonletter;
-                    p.mFailedPasswordAttempts = 0;
-                    saveSettingsLocked(userHandle);
-                    updatePasswordExpirationsLocked(userHandle);
-                    setExpirationAlarmCheckLocked(mContext, p);
-                    sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_CHANGED,
-                            DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD, userHandle);
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
-                }
-            }
-        }
-    }
-
-    /**
-     * Called any time the device password is updated.  Resets all password expiration clocks.
-     */
-    private void updatePasswordExpirationsLocked(int userHandle) {
-        DevicePolicyData policy = getUserData(userHandle);
-        final int N = policy.mAdminList.size();
-        if (N > 0) {
-            for (int i=0; i<N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (admin.info.usesPolicy(DeviceAdminInfo.USES_POLICY_EXPIRE_PASSWORD)) {
-                    long timeout = admin.passwordExpirationTimeout;
-                    long expiration = timeout > 0L ? (timeout + System.currentTimeMillis()) : 0L;
-                    admin.passwordExpirationDate = expiration;
-                }
-            }
-            saveSettingsLocked(userHandle);
-        }
-    }
-
-    public void reportFailedPasswordAttempt(int userHandle) {
-        enforceCrossUserPermission(userHandle);
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
-
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            long ident = Binder.clearCallingIdentity();
-            try {
-                policy.mFailedPasswordAttempts++;
-                saveSettingsLocked(userHandle);
-                if (mHasFeature) {
-                    int max = getMaximumFailedPasswordsForWipe(null, userHandle);
-                    if (max > 0 && policy.mFailedPasswordAttempts >= max) {
-                        wipeDeviceOrUserLocked(0, userHandle);
-                    }
-                    sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_FAILED,
-                            DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle);
-                }
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void reportSuccessfulPasswordAttempt(int userHandle) {
-        enforceCrossUserPermission(userHandle);
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.BIND_DEVICE_ADMIN, null);
-
-        synchronized (this) {
-            DevicePolicyData policy = getUserData(userHandle);
-            if (policy.mFailedPasswordAttempts != 0 || policy.mPasswordOwner >= 0) {
-                long ident = Binder.clearCallingIdentity();
-                try {
-                    policy.mFailedPasswordAttempts = 0;
-                    policy.mPasswordOwner = -1;
-                    saveSettingsLocked(userHandle);
-                    if (mHasFeature) {
-                        sendAdminCommandLocked(DeviceAdminReceiver.ACTION_PASSWORD_SUCCEEDED,
-                                DeviceAdminInfo.USES_POLICY_WATCH_LOGIN, userHandle);
-                    }
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
-                }
-            }
-        }
-    }
-
-    public ComponentName setGlobalProxy(ComponentName who, String proxySpec,
-            String exclusionList, int userHandle) {
-        if (!mHasFeature) {
-            return null;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized(this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-
-            // Only check if owner has set global proxy. We don't allow other users to set it.
-            DevicePolicyData policy = getUserData(UserHandle.USER_OWNER);
-            ActiveAdmin admin = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_SETS_GLOBAL_PROXY);
-
-            // Scan through active admins and find if anyone has already
-            // set the global proxy.
-            Set<ComponentName> compSet = policy.mAdminMap.keySet();
-            for  (ComponentName component : compSet) {
-                ActiveAdmin ap = policy.mAdminMap.get(component);
-                if ((ap.specifiesGlobalProxy) && (!component.equals(who))) {
-                    // Another admin already sets the global proxy
-                    // Return it to the caller.
-                    return component;
-                }
-            }
-
-            // If the user is not the owner, don't set the global proxy. Fail silently.
-            if (UserHandle.getCallingUserId() != UserHandle.USER_OWNER) {
-                Slog.w(TAG, "Only the owner is allowed to set the global proxy. User "
-                        + userHandle + " is not permitted.");
-                return null;
-            }
-            if (proxySpec == null) {
-                admin.specifiesGlobalProxy = false;
-                admin.globalProxySpec = null;
-                admin.globalProxyExclusionList = null;
-            } else {
-
-                admin.specifiesGlobalProxy = true;
-                admin.globalProxySpec = proxySpec;
-                admin.globalProxyExclusionList = exclusionList;
-            }
-
-            // Reset the global proxy accordingly
-            // Do this using system permissions, as apps cannot write to secure settings
-            long origId = Binder.clearCallingIdentity();
-            resetGlobalProxyLocked(policy);
-            Binder.restoreCallingIdentity(origId);
-            return null;
-        }
-    }
-
-    public ComponentName getGlobalProxyAdmin(int userHandle) {
-        if (!mHasFeature) {
-            return null;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized(this) {
-            DevicePolicyData policy = getUserData(UserHandle.USER_OWNER);
-            // Scan through active admins and find if anyone has already
-            // set the global proxy.
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                ActiveAdmin ap = policy.mAdminList.get(i);
-                if (ap.specifiesGlobalProxy) {
-                    // Device admin sets the global proxy
-                    // Return it to the caller.
-                    return ap.info.getComponent();
-                }
-            }
-        }
-        // No device admin sets the global proxy.
-        return null;
-    }
-
-    private void resetGlobalProxyLocked(DevicePolicyData policy) {
-        final int N = policy.mAdminList.size();
-        for (int i = 0; i < N; i++) {
-            ActiveAdmin ap = policy.mAdminList.get(i);
-            if (ap.specifiesGlobalProxy) {
-                saveGlobalProxyLocked(ap.globalProxySpec, ap.globalProxyExclusionList);
-                return;
-            }
-        }
-        // No device admins defining global proxies - reset global proxy settings to none
-        saveGlobalProxyLocked(null, null);
-    }
-
-    private void saveGlobalProxyLocked(String proxySpec, String exclusionList) {
-        if (exclusionList == null) {
-            exclusionList = "";
-        }
-        if (proxySpec == null) {
-            proxySpec = "";
-        }
-        // Remove white spaces
-        proxySpec = proxySpec.trim();
-        String data[] = proxySpec.split(":");
-        int proxyPort = 8080;
-        if (data.length > 1) {
-            try {
-                proxyPort = Integer.parseInt(data[1]);
-            } catch (NumberFormatException e) {}
-        }
-        exclusionList = exclusionList.trim();
-        ContentResolver res = mContext.getContentResolver();
-
-        ProxyProperties proxyProperties = new ProxyProperties(data[0], proxyPort, exclusionList);
-        if (!proxyProperties.isValid()) {
-            Slog.e(TAG, "Invalid proxy properties, ignoring: " + proxyProperties.toString());
-            return;
-        }
-        Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, data[0]);
-        Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, proxyPort);
-        Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
-                exclusionList);
-    }
-
-    /**
-     * Set the storage encryption request for a single admin.  Returns the new total request
-     * status (for all admins).
-     */
-    public int setStorageEncryption(ComponentName who, boolean encrypt, int userHandle) {
-        if (!mHasFeature) {
-            return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            // Check for permissions
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            // Only owner can set storage encryption
-            if (userHandle != UserHandle.USER_OWNER
-                    || UserHandle.getCallingUserId() != UserHandle.USER_OWNER) {
-                Slog.w(TAG, "Only owner is allowed to set storage encryption. User "
-                        + UserHandle.getCallingUserId() + " is not permitted.");
-                return 0;
-            }
-
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_ENCRYPTED_STORAGE);
-
-            // Quick exit:  If the filesystem does not support encryption, we can exit early.
-            if (!isEncryptionSupported()) {
-                return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
-            }
-
-            // (1) Record the value for the admin so it's sticky
-            if (ap.encryptionRequested != encrypt) {
-                ap.encryptionRequested = encrypt;
-                saveSettingsLocked(userHandle);
-            }
-
-            DevicePolicyData policy = getUserData(UserHandle.USER_OWNER);
-            // (2) Compute "max" for all admins
-            boolean newRequested = false;
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                newRequested |= policy.mAdminList.get(i).encryptionRequested;
-            }
-
-            // Notify OS of new request
-            setEncryptionRequested(newRequested);
-
-            // Return the new global request status
-            return newRequested
-                    ? DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE
-                    : DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE;
-        }
-    }
-
-    /**
-     * Get the current storage encryption request status for a given admin, or aggregate of all
-     * active admins.
-     */
-    public boolean getStorageEncryption(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return false;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            // Check for permissions if a particular caller is specified
-            if (who != null) {
-                // When checking for a single caller, status is based on caller's request
-                ActiveAdmin ap = getActiveAdminUncheckedLocked(who, userHandle);
-                return ap != null ? ap.encryptionRequested : false;
-            }
-
-            // If no particular caller is specified, return the aggregate set of requests.
-            // This is short circuited by returning true on the first hit.
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                if (policy.mAdminList.get(i).encryptionRequested) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    /**
-     * Get the current encryption status of the device.
-     */
-    public int getStorageEncryptionStatus(int userHandle) {
-        if (!mHasFeature) {
-            // Ok to return current status.
-        }
-        enforceCrossUserPermission(userHandle);
-        return getEncryptionStatus();
-    }
-
-    /**
-     * Hook to low-levels:  This should report if the filesystem supports encrypted storage.
-     */
-    private boolean isEncryptionSupported() {
-        // Note, this can be implemented as
-        //   return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
-        // But is provided as a separate internal method if there's a faster way to do a
-        // simple check for supported-or-not.
-        return getEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
-    }
-
-    /**
-     * Hook to low-levels:  Reporting the current status of encryption.
-     * @return A value such as {@link DevicePolicyManager#ENCRYPTION_STATUS_UNSUPPORTED} or
-     * {@link DevicePolicyManager#ENCRYPTION_STATUS_INACTIVE} or
-     * {@link DevicePolicyManager#ENCRYPTION_STATUS_ACTIVE}.
-     */
-    private int getEncryptionStatus() {
-        String status = SystemProperties.get("ro.crypto.state", "unsupported");
-        if ("encrypted".equalsIgnoreCase(status)) {
-            return DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE;
-        } else if ("unencrypted".equalsIgnoreCase(status)) {
-            return DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE;
-        } else {
-            return DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED;
-        }
-    }
-
-    /**
-     * Hook to low-levels:  If needed, record the new admin setting for encryption.
-     */
-    private void setEncryptionRequested(boolean encrypt) {
-    }
-
-    /**
-     * The system property used to share the state of the camera. The native camera service
-     * is expected to read this property and act accordingly.
-     */
-    public static final String SYSTEM_PROP_DISABLE_CAMERA = "sys.secpolicy.camera.disabled";
-
-    /**
-     * Disables all device cameras according to the specified admin.
-     */
-    public void setCameraDisabled(ComponentName who, boolean disabled, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_DISABLE_CAMERA);
-            if (ap.disableCamera != disabled) {
-                ap.disableCamera = disabled;
-                saveSettingsLocked(userHandle);
-            }
-            syncDeviceCapabilitiesLocked(getUserData(userHandle));
-        }
-    }
-
-    /**
-     * Gets whether or not all device cameras are disabled for a given admin, or disabled for any
-     * active admins.
-     */
-    public boolean getCameraDisabled(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return false;
-        }
-        synchronized (this) {
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return (admin != null) ? admin.disableCamera : false;
-            }
-
-            DevicePolicyData policy = getUserData(userHandle);
-            // Determine whether or not the device camera is disabled for any active admins.
-            final int N = policy.mAdminList.size();
-            for (int i = 0; i < N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                if (admin.disableCamera) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    /**
-     * Selectively disable keyguard features.
-     */
-    public void setKeyguardDisabledFeatures(ComponentName who, int which, int userHandle) {
-        if (!mHasFeature) {
-            return;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who == null) {
-                throw new NullPointerException("ComponentName is null");
-            }
-            ActiveAdmin ap = getActiveAdminForCallerLocked(who,
-                    DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES);
-            if (ap.disabledKeyguardFeatures != which) {
-                ap.disabledKeyguardFeatures = which;
-                saveSettingsLocked(userHandle);
-            }
-            syncDeviceCapabilitiesLocked(getUserData(userHandle));
-        }
-    }
-
-    /**
-     * Gets the disabled state for features in keyguard for the given admin,
-     * or the aggregate of all active admins if who is null.
-     */
-    public int getKeyguardDisabledFeatures(ComponentName who, int userHandle) {
-        if (!mHasFeature) {
-            return 0;
-        }
-        enforceCrossUserPermission(userHandle);
-        synchronized (this) {
-            if (who != null) {
-                ActiveAdmin admin = getActiveAdminUncheckedLocked(who, userHandle);
-                return (admin != null) ? admin.disabledKeyguardFeatures : 0;
-            }
-
-            // Determine which keyguard features are disabled for any active admins.
-            DevicePolicyData policy = getUserData(userHandle);
-            final int N = policy.mAdminList.size();
-            int which = 0;
-            for (int i = 0; i < N; i++) {
-                ActiveAdmin admin = policy.mAdminList.get(i);
-                which |= admin.disabledKeyguardFeatures;
-            }
-            return which;
-        }
-    }
-
-    @Override
-    public boolean setDeviceOwner(String packageName, String ownerName) {
-        if (!mHasFeature) {
-            return false;
-        }
-        if (packageName == null
-                || !DeviceOwner.isInstalled(packageName, mContext.getPackageManager())) {
-            throw new IllegalArgumentException("Invalid package name " + packageName
-                    + " for device owner");
-        }
-        synchronized (this) {
-            if (mDeviceOwner == null && !isDeviceProvisioned()) {
-                mDeviceOwner = new DeviceOwner(packageName, ownerName);
-                mDeviceOwner.writeOwnerFile();
-                return true;
-            } else {
-                throw new IllegalStateException("Trying to set device owner to " + packageName
-                        + ", owner=" + mDeviceOwner.getPackageName()
-                        + ", device_provisioned=" + isDeviceProvisioned());
-            }
-        }
-    }
-
-    @Override
-    public boolean isDeviceOwner(String packageName) {
-        if (!mHasFeature) {
-            return false;
-        }
-        synchronized (this) {
-            return mDeviceOwner != null
-                    && mDeviceOwner.getPackageName().equals(packageName);
-        }
-    }
-
-    @Override
-    public String getDeviceOwner() {
-        if (!mHasFeature) {
-            return null;
-        }
-        synchronized (this) {
-            if (mDeviceOwner != null) {
-                return mDeviceOwner.getPackageName();
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public String getDeviceOwnerName() {
-        if (!mHasFeature) {
-            return null;
-        }
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
-        synchronized (this) {
-            if (mDeviceOwner != null) {
-                return mDeviceOwner.getName();
-            }
-        }
-        return null;
-    }
-
-    private boolean isDeviceProvisioned() {
-        return Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.DEVICE_PROVISIONED, 0) > 0;
-    }
-
-    private void enforceCrossUserPermission(int userHandle) {
-        if (userHandle < 0) {
-            throw new IllegalArgumentException("Invalid userId " + userHandle);
-        }
-        final int callingUid = Binder.getCallingUid();
-        if (userHandle == UserHandle.getUserId(callingUid)) return;
-        if (callingUid != Process.SYSTEM_UID && callingUid != 0) {
-            mContext.enforceCallingOrSelfPermission(
-                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, "Must be system or have"
-                    + " INTERACT_ACROSS_USERS_FULL permission");
-        }
-    }
-
-    private void enableIfNecessary(String packageName, int userId) {
-        try {
-            IPackageManager ipm = AppGlobals.getPackageManager();
-            ApplicationInfo ai = ipm.getApplicationInfo(packageName,
-                    PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
-                    userId);
-            if (ai.enabledSetting
-                    == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
-                ipm.setApplicationEnabledSetting(packageName,
-                        PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
-                        PackageManager.DONT_KILL_APP, userId, "DevicePolicyManager");
-            }
-        } catch (RemoteException e) {
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-
-            pw.println("Permission Denial: can't dump DevicePolicyManagerService from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        final Printer p = new PrintWriterPrinter(pw);
-
-        synchronized (this) {
-            p.println("Current Device Policy Manager state:");
-
-            int userCount = mUserData.size();
-            for (int u = 0; u < userCount; u++) {
-                DevicePolicyData policy = getUserData(mUserData.keyAt(u));
-                p.println("  Enabled Device Admins (User " + policy.mUserHandle + "):");
-                final int N = policy.mAdminList.size();
-                for (int i=0; i<N; i++) {
-                    ActiveAdmin ap = policy.mAdminList.get(i);
-                    if (ap != null) {
-                        pw.print("  "); pw.print(ap.info.getComponent().flattenToShortString());
-                                pw.println(":");
-                        ap.dump("    ", pw);
-                    }
-                }
-
-                pw.println(" ");
-                pw.print("  mPasswordOwner="); pw.println(policy.mPasswordOwner);
-            }
-        }
-    }
-
-    static class DeviceOwner {
-        private static final String DEVICE_OWNER_XML = "device_owner.xml";
-        private static final String TAG_DEVICE_OWNER = "device-owner";
-        private static final String ATTR_NAME = "name";
-        private static final String ATTR_PACKAGE = "package";
-        private String mPackageName;
-        private String mOwnerName;
-
-        DeviceOwner() {
-            readOwnerFile();
-        }
-
-        DeviceOwner(String packageName, String ownerName) {
-            this.mPackageName = packageName;
-            this.mOwnerName = ownerName;
-        }
-
-        static boolean isRegistered() {
-            return new File(Environment.getSystemSecureDirectory(),
-                    DEVICE_OWNER_XML).exists();
-        }
-
-        String getPackageName() {
-            return mPackageName;
-        }
-
-        String getName() {
-            return mOwnerName;
-        }
-
-        static boolean isInstalled(String packageName, PackageManager pm) {
-            try {
-                PackageInfo pi;
-                if ((pi = pm.getPackageInfo(packageName, 0)) != null) {
-                    if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                        return true;
-                    }
-                }
-            } catch (NameNotFoundException nnfe) {
-                Slog.w(TAG, "Device Owner package " + packageName + " not installed.");
-            }
-            return false;
-        }
-
-        void readOwnerFile() {
-            AtomicFile file = new AtomicFile(new File(Environment.getSystemSecureDirectory(),
-                    DEVICE_OWNER_XML));
-            try {
-                FileInputStream input = file.openRead();
-                XmlPullParser parser = Xml.newPullParser();
-                parser.setInput(input, null);
-                int type;
-                while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                        && type != XmlPullParser.START_TAG) {
-                }
-                String tag = parser.getName();
-                if (!TAG_DEVICE_OWNER.equals(tag)) {
-                    throw new XmlPullParserException(
-                            "Device Owner file does not start with device-owner tag: found " + tag);
-                }
-                mPackageName = parser.getAttributeValue(null, ATTR_PACKAGE);
-                mOwnerName = parser.getAttributeValue(null, ATTR_NAME);
-                input.close();
-            } catch (XmlPullParserException xppe) {
-                Slog.e(TAG, "Error parsing device-owner file\n" + xppe);
-            } catch (IOException ioe) {
-                Slog.e(TAG, "IO Exception when reading device-owner file\n" + ioe);
-            }
-        }
-
-        void writeOwnerFile() {
-            synchronized (this) {
-                writeOwnerFileLocked();
-            }
-        }
-
-        private void writeOwnerFileLocked() {
-            AtomicFile file = new AtomicFile(new File(Environment.getSystemSecureDirectory(),
-                    DEVICE_OWNER_XML));
-            try {
-                FileOutputStream output = file.startWrite();
-                XmlSerializer out = new FastXmlSerializer();
-                out.setOutput(output, "utf-8");
-                out.startDocument(null, true);
-                out.startTag(null, TAG_DEVICE_OWNER);
-                out.attribute(null, ATTR_PACKAGE, mPackageName);
-                if (mOwnerName != null) {
-                    out.attribute(null, ATTR_NAME, mOwnerName);
-                }
-                out.endTag(null, TAG_DEVICE_OWNER);
-                out.endDocument();
-                out.flush();
-                file.finishWrite(output);
-            } catch (IOException ioe) {
-                Slog.e(TAG, "IO Exception when writing device-owner file\n" + ioe);
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/DeviceStorageMonitorService.java b/services/java/com/android/server/DeviceStorageMonitorService.java
deleted file mode 100644
index 016c561..0000000
--- a/services/java/com/android/server/DeviceStorageMonitorService.java
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * Copyright (C) 2007-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.server;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.IPackageDataObserver;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageManager;
-import android.os.Binder;
-import android.os.Environment;
-import android.os.FileObserver;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.StatFs;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.os.storage.StorageManager;
-import android.provider.Settings;
-import android.text.format.Formatter;
-import android.util.EventLog;
-import android.util.Slog;
-import android.util.TimeUtils;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-
-/**
- * This class implements a service to monitor the amount of disk
- * storage space on the device.  If the free storage on device is less
- * than a tunable threshold value (a secure settings parameter;
- * default 10%) a low memory notification is displayed to alert the
- * user. If the user clicks on the low memory notification the
- * Application Manager application gets launched to let the user free
- * storage space.
- *
- * Event log events: A low memory event with the free storage on
- * device in bytes is logged to the event log when the device goes low
- * on storage space.  The amount of free storage on the device is
- * periodically logged to the event log. The log interval is a secure
- * settings parameter with a default value of 12 hours.  When the free
- * storage differential goes below a threshold (again a secure
- * settings parameter with a default value of 2MB), the free memory is
- * logged to the event log.
- */
-public class DeviceStorageMonitorService extends Binder {
-    private static final String TAG = "DeviceStorageMonitorService";
-
-    private static final boolean DEBUG = false;
-    private static final boolean localLOGV = false;
-
-    private static final int DEVICE_MEMORY_WHAT = 1;
-    private static final int MONITOR_INTERVAL = 1; //in minutes
-    private static final int LOW_MEMORY_NOTIFICATION_ID = 1;
-
-    private static final int DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES = 12*60; //in minutes
-    private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB
-    private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000;
-
-    private long mFreeMem;  // on /data
-    private long mFreeMemAfterLastCacheClear;  // on /data
-    private long mLastReportedFreeMem;
-    private long mLastReportedFreeMemTime;
-    private boolean mLowMemFlag=false;
-    private boolean mMemFullFlag=false;
-    private Context mContext;
-    private ContentResolver mResolver;
-    private long mTotalMemory;  // on /data
-    private StatFs mDataFileStats;
-    private StatFs mSystemFileStats;
-    private StatFs mCacheFileStats;
-
-    private static final File DATA_PATH = Environment.getDataDirectory();
-    private static final File SYSTEM_PATH = Environment.getRootDirectory();
-    private static final File CACHE_PATH = Environment.getDownloadCacheDirectory();
-
-    private long mThreadStartTime = -1;
-    private boolean mClearSucceeded = false;
-    private boolean mClearingCache;
-    private Intent mStorageLowIntent;
-    private Intent mStorageOkIntent;
-    private Intent mStorageFullIntent;
-    private Intent mStorageNotFullIntent;
-    private CachePackageDataObserver mClearCacheObserver;
-    private final CacheFileDeletedObserver mCacheFileDeletedObserver;
-    private static final int _TRUE = 1;
-    private static final int _FALSE = 0;
-    // This is the raw threshold that has been set at which we consider
-    // storage to be low.
-    private long mMemLowThreshold;
-    // This is the threshold at which we start trying to flush caches
-    // to get below the low threshold limit.  It is less than the low
-    // threshold; we will allow storage to get a bit beyond the limit
-    // before flushing and checking if we are actually low.
-    private long mMemCacheStartTrimThreshold;
-    // This is the threshold that we try to get to when deleting cache
-    // files.  This is greater than the low threshold so that we will flush
-    // more files than absolutely needed, to reduce the frequency that
-    // flushing takes place.
-    private long mMemCacheTrimToThreshold;
-    private long mMemFullThreshold;
-
-    /**
-     * This string is used for ServiceManager access to this class.
-     */
-    public static final String SERVICE = "devicestoragemonitor";
-
-    /**
-    * Handler that checks the amount of disk space on the device and sends a
-    * notification if the device runs low on disk space
-    */
-    Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            //don't handle an invalid message
-            if (msg.what != DEVICE_MEMORY_WHAT) {
-                Slog.e(TAG, "Will not process invalid message");
-                return;
-            }
-            checkMemory(msg.arg1 == _TRUE);
-        }
-    };
-
-    class CachePackageDataObserver extends IPackageDataObserver.Stub {
-        public void onRemoveCompleted(String packageName, boolean succeeded) {
-            mClearSucceeded = succeeded;
-            mClearingCache = false;
-            if(localLOGV) Slog.i(TAG, " Clear succeeded:"+mClearSucceeded
-                    +", mClearingCache:"+mClearingCache+" Forcing memory check");
-            postCheckMemoryMsg(false, 0);
-        }
-    }
-
-    private final void restatDataDir() {
-        try {
-            mDataFileStats.restat(DATA_PATH.getAbsolutePath());
-            mFreeMem = (long) mDataFileStats.getAvailableBlocks() *
-                mDataFileStats.getBlockSize();
-        } catch (IllegalArgumentException e) {
-            // use the old value of mFreeMem
-        }
-        // Allow freemem to be overridden by debug.freemem for testing
-        String debugFreeMem = SystemProperties.get("debug.freemem");
-        if (!"".equals(debugFreeMem)) {
-            mFreeMem = Long.parseLong(debugFreeMem);
-        }
-        // Read the log interval from secure settings
-        long freeMemLogInterval = Settings.Global.getLong(mResolver,
-                Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
-                DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000;
-        //log the amount of free memory in event log
-        long currTime = SystemClock.elapsedRealtime();
-        if((mLastReportedFreeMemTime == 0) ||
-           (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) {
-            mLastReportedFreeMemTime = currTime;
-            long mFreeSystem = -1, mFreeCache = -1;
-            try {
-                mSystemFileStats.restat(SYSTEM_PATH.getAbsolutePath());
-                mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() *
-                    mSystemFileStats.getBlockSize();
-            } catch (IllegalArgumentException e) {
-                // ignore; report -1
-            }
-            try {
-                mCacheFileStats.restat(CACHE_PATH.getAbsolutePath());
-                mFreeCache = (long) mCacheFileStats.getAvailableBlocks() *
-                    mCacheFileStats.getBlockSize();
-            } catch (IllegalArgumentException e) {
-                // ignore; report -1
-            }
-            EventLog.writeEvent(EventLogTags.FREE_STORAGE_LEFT,
-                                mFreeMem, mFreeSystem, mFreeCache);
-        }
-        // Read the reporting threshold from secure settings
-        long threshold = Settings.Global.getLong(mResolver,
-                Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
-                DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD);
-        // If mFree changed significantly log the new value
-        long delta = mFreeMem - mLastReportedFreeMem;
-        if (delta > threshold || delta < -threshold) {
-            mLastReportedFreeMem = mFreeMem;
-            EventLog.writeEvent(EventLogTags.FREE_STORAGE_CHANGED, mFreeMem);
-        }
-    }
-
-    private final void clearCache() {
-        if (mClearCacheObserver == null) {
-            // Lazy instantiation
-            mClearCacheObserver = new CachePackageDataObserver();
-        }
-        mClearingCache = true;
-        try {
-            if (localLOGV) Slog.i(TAG, "Clearing cache");
-            IPackageManager.Stub.asInterface(ServiceManager.getService("package")).
-                    freeStorageAndNotify(mMemCacheTrimToThreshold, mClearCacheObserver);
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Failed to get handle for PackageManger Exception: "+e);
-            mClearingCache = false;
-            mClearSucceeded = false;
-        }
-    }
-
-    private final void checkMemory(boolean checkCache) {
-        //if the thread that was started to clear cache is still running do nothing till its
-        //finished clearing cache. Ideally this flag could be modified by clearCache
-        // and should be accessed via a lock but even if it does this test will fail now and
-        //hopefully the next time this flag will be set to the correct value.
-        if(mClearingCache) {
-            if(localLOGV) Slog.i(TAG, "Thread already running just skip");
-            //make sure the thread is not hung for too long
-            long diffTime = System.currentTimeMillis() - mThreadStartTime;
-            if(diffTime > (10*60*1000)) {
-                Slog.w(TAG, "Thread that clears cache file seems to run for ever");
-            }
-        } else {
-            restatDataDir();
-            if (localLOGV)  Slog.v(TAG, "freeMemory="+mFreeMem);
-
-            //post intent to NotificationManager to display icon if necessary
-            if (mFreeMem < mMemLowThreshold) {
-                if (checkCache) {
-                    // We are allowed to clear cache files at this point to
-                    // try to get down below the limit, because this is not
-                    // the initial call after a cache clear has been attempted.
-                    // In this case we will try a cache clear if our free
-                    // space has gone below the cache clear limit.
-                    if (mFreeMem < mMemCacheStartTrimThreshold) {
-                        // We only clear the cache if the free storage has changed
-                        // a significant amount since the last time.
-                        if ((mFreeMemAfterLastCacheClear-mFreeMem)
-                                >= ((mMemLowThreshold-mMemCacheStartTrimThreshold)/4)) {
-                            // See if clearing cache helps
-                            // Note that clearing cache is asynchronous and so we do a
-                            // memory check again once the cache has been cleared.
-                            mThreadStartTime = System.currentTimeMillis();
-                            mClearSucceeded = false;
-                            clearCache();
-                        }
-                    }
-                } else {
-                    // This is a call from after clearing the cache.  Note
-                    // the amount of free storage at this point.
-                    mFreeMemAfterLastCacheClear = mFreeMem;
-                    if (!mLowMemFlag) {
-                        // We tried to clear the cache, but that didn't get us
-                        // below the low storage limit.  Tell the user.
-                        Slog.i(TAG, "Running low on memory. Sending notification");
-                        sendNotification();
-                        mLowMemFlag = true;
-                    } else {
-                        if (localLOGV) Slog.v(TAG, "Running low on memory " +
-                                "notification already sent. do nothing");
-                    }
-                }
-            } else {
-                mFreeMemAfterLastCacheClear = mFreeMem;
-                if (mLowMemFlag) {
-                    Slog.i(TAG, "Memory available. Cancelling notification");
-                    cancelNotification();
-                    mLowMemFlag = false;
-                }
-            }
-            if (mFreeMem < mMemFullThreshold) {
-                if (!mMemFullFlag) {
-                    sendFullNotification();
-                    mMemFullFlag = true;
-                }
-            } else {
-                if (mMemFullFlag) {
-                    cancelFullNotification();
-                    mMemFullFlag = false;
-                }
-            }
-        }
-        if(localLOGV) Slog.i(TAG, "Posting Message again");
-        //keep posting messages to itself periodically
-        postCheckMemoryMsg(true, DEFAULT_CHECK_INTERVAL);
-    }
-
-    private void postCheckMemoryMsg(boolean clearCache, long delay) {
-        // Remove queued messages
-        mHandler.removeMessages(DEVICE_MEMORY_WHAT);
-        mHandler.sendMessageDelayed(mHandler.obtainMessage(DEVICE_MEMORY_WHAT,
-                clearCache ?_TRUE : _FALSE, 0),
-                delay);
-    }
-
-    /**
-    * Constructor to run service. initializes the disk space threshold value
-    * and posts an empty message to kickstart the process.
-    */
-    public DeviceStorageMonitorService(Context context) {
-        mLastReportedFreeMemTime = 0;
-        mContext = context;
-        mResolver = mContext.getContentResolver();
-        //create StatFs object
-        mDataFileStats = new StatFs(DATA_PATH.getAbsolutePath());
-        mSystemFileStats = new StatFs(SYSTEM_PATH.getAbsolutePath());
-        mCacheFileStats = new StatFs(CACHE_PATH.getAbsolutePath());
-        //initialize total storage on device
-        mTotalMemory = (long)mDataFileStats.getBlockCount() *
-                        mDataFileStats.getBlockSize();
-        mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW);
-        mStorageLowIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK);
-        mStorageOkIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        mStorageFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_FULL);
-        mStorageFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        mStorageNotFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_NOT_FULL);
-        mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-
-        // cache storage thresholds
-        final StorageManager sm = StorageManager.from(context);
-        mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH);
-        mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH);
-
-        mMemCacheStartTrimThreshold = ((mMemLowThreshold*3)+mMemFullThreshold)/4;
-        mMemCacheTrimToThreshold = mMemLowThreshold
-                + ((mMemLowThreshold-mMemCacheStartTrimThreshold)*2);
-        mFreeMemAfterLastCacheClear = mTotalMemory;
-        checkMemory(true);
-
-        mCacheFileDeletedObserver = new CacheFileDeletedObserver();
-        mCacheFileDeletedObserver.startWatching();
-    }
-
-    /**
-    * This method sends a notification to NotificationManager to display
-    * an error dialog indicating low disk space and launch the Installer
-    * application
-    */
-    private final void sendNotification() {
-        if(localLOGV) Slog.i(TAG, "Sending low memory notification");
-        //log the event to event log with the amount of free storage(in bytes) left on the device
-        EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
-        //  Pack up the values and broadcast them to everyone
-        Intent lowMemIntent = new Intent(Environment.isExternalStorageEmulated()
-                ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS
-                : Intent.ACTION_MANAGE_PACKAGE_STORAGE);
-        lowMemIntent.putExtra("memory", mFreeMem);
-        lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        NotificationManager mNotificationMgr =
-                (NotificationManager)mContext.getSystemService(
-                        Context.NOTIFICATION_SERVICE);
-        CharSequence title = mContext.getText(
-                com.android.internal.R.string.low_internal_storage_view_title);
-        CharSequence details = mContext.getText(
-                com.android.internal.R.string.low_internal_storage_view_text);
-        PendingIntent intent = PendingIntent.getActivityAsUser(mContext, 0,  lowMemIntent, 0,
-                null, UserHandle.CURRENT);
-        Notification notification = new Notification();
-        notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
-        notification.tickerText = title;
-        notification.flags |= Notification.FLAG_NO_CLEAR;
-        notification.setLatestEventInfo(mContext, title, details, intent);
-        mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification,
-                UserHandle.ALL);
-        mContext.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
-    }
-
-    /**
-     * Cancels low storage notification and sends OK intent.
-     */
-    private final void cancelNotification() {
-        if(localLOGV) Slog.i(TAG, "Canceling low memory notification");
-        NotificationManager mNotificationMgr =
-                (NotificationManager)mContext.getSystemService(
-                        Context.NOTIFICATION_SERVICE);
-        //cancel notification since memory has been freed
-        mNotificationMgr.cancelAsUser(null, LOW_MEMORY_NOTIFICATION_ID, UserHandle.ALL);
-
-        mContext.removeStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
-        mContext.sendBroadcastAsUser(mStorageOkIntent, UserHandle.ALL);
-    }
-
-    /**
-     * Send a notification when storage is full.
-     */
-    private final void sendFullNotification() {
-        if(localLOGV) Slog.i(TAG, "Sending memory full notification");
-        mContext.sendStickyBroadcastAsUser(mStorageFullIntent, UserHandle.ALL);
-    }
-
-    /**
-     * Cancels memory full notification and sends "not full" intent.
-     */
-    private final void cancelFullNotification() {
-        if(localLOGV) Slog.i(TAG, "Canceling memory full notification");
-        mContext.removeStickyBroadcastAsUser(mStorageFullIntent, UserHandle.ALL);
-        mContext.sendBroadcastAsUser(mStorageNotFullIntent, UserHandle.ALL);
-    }
-
-    public void updateMemory() {
-        int callingUid = getCallingUid();
-        if(callingUid != Process.SYSTEM_UID) {
-            return;
-        }
-        // force an early check
-        postCheckMemoryMsg(true, 0);
-    }
-
-    /**
-     * Callable from other things in the system service to obtain the low memory
-     * threshold.
-     * 
-     * @return low memory threshold in bytes
-     */
-    public long getMemoryLowThreshold() {
-        return mMemLowThreshold;
-    }
-
-    /**
-     * Callable from other things in the system process to check whether memory
-     * is low.
-     * 
-     * @return true is memory is low
-     */
-    public boolean isMemoryLow() {
-        return mLowMemFlag;
-    }
-
-    public static class CacheFileDeletedObserver extends FileObserver {
-        public CacheFileDeletedObserver() {
-            super(Environment.getDownloadCacheDirectory().getAbsolutePath(), FileObserver.DELETE);
-        }
-
-        @Override
-        public void onEvent(int event, String path) {
-            EventLogTags.writeCacheFileDeleted(path);
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-
-            pw.println("Permission Denial: can't dump " + SERVICE + " from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("Current DeviceStorageMonitor state:");
-        pw.print("  mFreeMem="); pw.print(Formatter.formatFileSize(mContext, mFreeMem));
-                pw.print(" mTotalMemory=");
-                pw.println(Formatter.formatFileSize(mContext, mTotalMemory));
-        pw.print("  mFreeMemAfterLastCacheClear=");
-                pw.println(Formatter.formatFileSize(mContext, mFreeMemAfterLastCacheClear));
-        pw.print("  mLastReportedFreeMem=");
-                pw.print(Formatter.formatFileSize(mContext, mLastReportedFreeMem));
-                pw.print(" mLastReportedFreeMemTime=");
-                TimeUtils.formatDuration(mLastReportedFreeMemTime, SystemClock.elapsedRealtime(), pw);
-                pw.println();
-        pw.print("  mLowMemFlag="); pw.print(mLowMemFlag);
-                pw.print(" mMemFullFlag="); pw.println(mMemFullFlag);
-        pw.print("  mClearSucceeded="); pw.print(mClearSucceeded);
-                pw.print(" mClearingCache="); pw.println(mClearingCache);
-        pw.print("  mMemLowThreshold=");
-                pw.print(Formatter.formatFileSize(mContext, mMemLowThreshold));
-                pw.print(" mMemFullThreshold=");
-                pw.println(Formatter.formatFileSize(mContext, mMemFullThreshold));
-        pw.print("  mMemCacheStartTrimThreshold=");
-                pw.print(Formatter.formatFileSize(mContext, mMemCacheStartTrimThreshold));
-                pw.print(" mMemCacheTrimToThreshold=");
-                pw.println(Formatter.formatFileSize(mContext, mMemCacheTrimToThreshold));
-    }
-}
diff --git a/services/java/com/android/server/EntropyMixer.java b/services/java/com/android/server/EntropyMixer.java
deleted file mode 100644
index fbb66f9..0000000
--- a/services/java/com/android/server/EntropyMixer.java
+++ /dev/null
@@ -1,177 +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.
- */
-
-package com.android.server;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Binder;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.Message;
-import android.os.SystemProperties;
-import android.util.Slog;
-
-/**
- * A service designed to load and periodically save &quot;randomness&quot;
- * for the Linux kernel.
- *
- * <p>When a Linux system starts up, the entropy pool associated with
- * {@code /dev/random} may be in a fairly predictable state.  Applications which
- * depend strongly on randomness may find {@code /dev/random} or
- * {@code /dev/urandom} returning predictable data.  In order to counteract
- * this effect, it's helpful to carry the entropy pool information across
- * shutdowns and startups.
- *
- * <p>This class was modeled after the script in
- * <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/random.4.html">man
- * 4 random</a>.
- */
-public class EntropyMixer extends Binder {
-    private static final String TAG = "EntropyMixer";
-    private static final int ENTROPY_WHAT = 1;
-    private static final int ENTROPY_WRITE_PERIOD = 3 * 60 * 60 * 1000;  // 3 hrs
-    private static final long START_TIME = System.currentTimeMillis();
-    private static final long START_NANOTIME = System.nanoTime();
-
-    private final String randomDevice;
-    private final String entropyFile;
-
-    /**
-     * Handler that periodically updates the entropy on disk.
-     */
-    private final Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            if (msg.what != ENTROPY_WHAT) {
-                Slog.e(TAG, "Will not process invalid message");
-                return;
-            }
-            writeEntropy();
-            scheduleEntropyWriter();
-        }
-    };
-
-    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            writeEntropy();
-        }
-    };
-
-    public EntropyMixer(Context context) {
-        this(context, getSystemDir() + "/entropy.dat", "/dev/urandom");
-    }
-
-    /** Test only interface, not for public use */
-    public EntropyMixer(Context context, String entropyFile, String randomDevice) {
-        if (randomDevice == null) { throw new NullPointerException("randomDevice"); }
-        if (entropyFile == null) { throw new NullPointerException("entropyFile"); }
-
-        this.randomDevice = randomDevice;
-        this.entropyFile = entropyFile;
-        loadInitialEntropy();
-        addDeviceSpecificEntropy();
-        writeEntropy();
-        scheduleEntropyWriter();
-        IntentFilter broadcastFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);
-        broadcastFilter.addAction(Intent.ACTION_POWER_CONNECTED);
-        broadcastFilter.addAction(Intent.ACTION_REBOOT);
-        context.registerReceiver(mBroadcastReceiver, broadcastFilter);
-    }
-
-    private void scheduleEntropyWriter() {
-        mHandler.removeMessages(ENTROPY_WHAT);
-        mHandler.sendEmptyMessageDelayed(ENTROPY_WHAT, ENTROPY_WRITE_PERIOD);
-    }
-
-    private void loadInitialEntropy() {
-        try {
-            RandomBlock.fromFile(entropyFile).toFile(randomDevice, false);
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "No existing entropy file -- first boot?");
-        } catch (IOException e) {
-            Slog.w(TAG, "Failure loading existing entropy file", e);
-        }
-    }
-
-    private void writeEntropy() {
-        try {
-            Slog.i(TAG, "Writing entropy...");
-            RandomBlock.fromFile(randomDevice).toFile(entropyFile, true);
-        } catch (IOException e) {
-            Slog.w(TAG, "Unable to write entropy", e);
-        }
-    }
-
-    /**
-     * Add additional information to the kernel entropy pool.  The
-     * information isn't necessarily "random", but that's ok.  Even
-     * sending non-random information to {@code /dev/urandom} is useful
-     * because, while it doesn't increase the "quality" of the entropy pool,
-     * it mixes more bits into the pool, which gives us a higher degree
-     * of uncertainty in the generated randomness.  Like nature, writes to
-     * the random device can only cause the quality of the entropy in the
-     * kernel to stay the same or increase.
-     *
-     * <p>For maximum effect, we try to target information which varies
-     * on a per-device basis, and is not easily observable to an
-     * attacker.
-     */
-    private void addDeviceSpecificEntropy() {
-        PrintWriter out = null;
-        try {
-            out = new PrintWriter(new FileOutputStream(randomDevice));
-            out.println("Copyright (C) 2009 The Android Open Source Project");
-            out.println("All Your Randomness Are Belong To Us");
-            out.println(START_TIME);
-            out.println(START_NANOTIME);
-            out.println(SystemProperties.get("ro.serialno"));
-            out.println(SystemProperties.get("ro.bootmode"));
-            out.println(SystemProperties.get("ro.baseband"));
-            out.println(SystemProperties.get("ro.carrier"));
-            out.println(SystemProperties.get("ro.bootloader"));
-            out.println(SystemProperties.get("ro.hardware"));
-            out.println(SystemProperties.get("ro.revision"));
-            out.println(SystemProperties.get("ro.build.fingerprint"));
-            out.println(new Object().hashCode());
-            out.println(System.currentTimeMillis());
-            out.println(System.nanoTime());
-        } catch (IOException e) {
-            Slog.w(TAG, "Unable to add device specific data to the entropy pool", e);
-        } finally {
-            if (out != null) {
-                out.close();
-            }
-        }
-    }
-
-    private static String getSystemDir() {
-        File dataDir = Environment.getDataDirectory();
-        File systemDir = new File(dataDir, "system");
-        systemDir.mkdirs();
-        return systemDir.toString();
-    }
-}
diff --git a/services/java/com/android/server/FgThread.java b/services/java/com/android/server/FgThread.java
deleted file mode 100644
index 3b655f2..0000000
--- a/services/java/com/android/server/FgThread.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2013 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;
-
-import android.os.Handler;
-import android.os.HandlerThread;
-
-/**
- * Shared singleton foreground thread for the system.  This is a thread for regular
- * foreground service operations, which shouldn't be blocked by anything running in
- * the background.  In particular, the shared background thread could be doing
- * relatively long-running operations like saving state to disk (in addition to
- * simply being a background priority), which can cause operations scheduled on it
- * to be delayed for a user-noticeable amount of time.
- */
-public final class FgThread extends HandlerThread {
-    private static FgThread sInstance;
-    private static Handler sHandler;
-
-    private FgThread() {
-        super("android.fg", android.os.Process.THREAD_PRIORITY_DEFAULT);
-    }
-
-    private static void ensureThreadLocked() {
-        if (sInstance == null) {
-            sInstance = new FgThread();
-            sInstance.start();
-            sHandler = new Handler(sInstance.getLooper());
-            sHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    android.os.Process.setCanSelfBackground(false);
-                }
-            });
-        }
-    }
-
-    public static FgThread get() {
-        synchronized (UiThread.class) {
-            ensureThreadLocked();
-            return sInstance;
-        }
-    }
-
-    public static Handler getHandler() {
-        synchronized (UiThread.class) {
-            ensureThreadLocked();
-            return sHandler;
-        }
-    }
-}
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
deleted file mode 100644
index a996dbd..0000000
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ /dev/null
@@ -1,3574 +0,0 @@
-/*
- *
- * 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;
-
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.inputmethod.InputMethodUtils;
-import com.android.internal.inputmethod.InputMethodUtils.InputMethodSettings;
-import com.android.internal.os.HandlerCaller;
-import com.android.internal.os.SomeArgs;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.view.IInputContext;
-import com.android.internal.view.IInputMethod;
-import com.android.internal.view.IInputSessionCallback;
-import com.android.internal.view.IInputMethodClient;
-import com.android.internal.view.IInputMethodManager;
-import com.android.internal.view.IInputMethodSession;
-import com.android.internal.view.InputBindResult;
-import com.android.server.EventLogTags;
-import com.android.server.wm.WindowManagerService;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.app.ActivityManagerNative;
-import android.app.AppGlobals;
-import android.app.AlertDialog;
-import android.app.IUserSwitchObserver;
-import android.app.KeyguardManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnCancelListener;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.database.ContentObserver;
-import android.inputmethodservice.InputMethodService;
-import android.os.Binder;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.IInterface;
-import android.os.IRemoteCallback;
-import android.os.Message;
-import android.os.Process;
-import android.os.Parcel;
-import android.os.RemoteException;
-import android.os.ResultReceiver;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.text.TextUtils;
-import android.text.style.SuggestionSpan;
-import android.util.AtomicFile;
-import android.util.EventLog;
-import android.util.LruCache;
-import android.util.Pair;
-import android.util.PrintWriterPrinter;
-import android.util.Printer;
-import android.util.Slog;
-import android.util.Xml;
-import android.view.IWindowManager;
-import android.view.InputChannel;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputBinding;
-import android.view.inputmethod.InputMethod;
-import android.view.inputmethod.InputMethodInfo;
-import android.view.inputmethod.InputMethodManager;
-import android.view.inputmethod.InputMethodSubtype;
-import android.widget.ArrayAdapter;
-import android.widget.CompoundButton;
-import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.RadioButton;
-import android.widget.Switch;
-import android.widget.TextView;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.TreeMap;
-
-/**
- * This class provides a system service that manages input methods.
- */
-public class InputMethodManagerService extends IInputMethodManager.Stub
-        implements ServiceConnection, Handler.Callback {
-    static final boolean DEBUG = false;
-    static final String TAG = "InputMethodManagerService";
-
-    static final int MSG_SHOW_IM_PICKER = 1;
-    static final int MSG_SHOW_IM_SUBTYPE_PICKER = 2;
-    static final int MSG_SHOW_IM_SUBTYPE_ENABLER = 3;
-    static final int MSG_SHOW_IM_CONFIG = 4;
-
-    static final int MSG_UNBIND_INPUT = 1000;
-    static final int MSG_BIND_INPUT = 1010;
-    static final int MSG_SHOW_SOFT_INPUT = 1020;
-    static final int MSG_HIDE_SOFT_INPUT = 1030;
-    static final int MSG_ATTACH_TOKEN = 1040;
-    static final int MSG_CREATE_SESSION = 1050;
-
-    static final int MSG_START_INPUT = 2000;
-    static final int MSG_RESTART_INPUT = 2010;
-
-    static final int MSG_UNBIND_METHOD = 3000;
-    static final int MSG_BIND_METHOD = 3010;
-    static final int MSG_SET_ACTIVE = 3020;
-
-    static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
-
-    static final long TIME_TO_RECONNECT = 10*1000;
-
-    static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20;
-
-    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
-    private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";
-
-
-    final Context mContext;
-    final Resources mRes;
-    final Handler mHandler;
-    final InputMethodSettings mSettings;
-    final SettingsObserver mSettingsObserver;
-    final IWindowManager mIWindowManager;
-    final HandlerCaller mCaller;
-    final boolean mHasFeature;
-    private InputMethodFileManager mFileManager;
-    private InputMethodAndSubtypeListManager mImListManager;
-    private final HardKeyboardListener mHardKeyboardListener;
-    private final WindowManagerService mWindowManagerService;
-
-    final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1);
-
-    // All known input methods.  mMethodMap also serves as the global
-    // lock for this class.
-    final ArrayList<InputMethodInfo> mMethodList = new ArrayList<InputMethodInfo>();
-    final HashMap<String, InputMethodInfo> mMethodMap = new HashMap<String, InputMethodInfo>();
-    private final LruCache<SuggestionSpan, InputMethodInfo> mSecureSuggestionSpans =
-            new LruCache<SuggestionSpan, InputMethodInfo>(SECURE_SUGGESTION_SPANS_MAX_SIZE);
-
-    // Used to bring IME service up to visible adjustment while it is being shown.
-    final ServiceConnection mVisibleConnection = new ServiceConnection() {
-        @Override public void onServiceConnected(ComponentName name, IBinder service) {
-        }
-
-        @Override public void onServiceDisconnected(ComponentName name) {
-        }
-    };
-    boolean mVisibleBound = false;
-
-    // Ongoing notification
-    private NotificationManager mNotificationManager;
-    private KeyguardManager mKeyguardManager;
-    private StatusBarManagerService mStatusBar;
-    private Notification mImeSwitcherNotification;
-    private PendingIntent mImeSwitchPendingIntent;
-    private boolean mShowOngoingImeSwitcherForPhones;
-    private boolean mNotificationShown;
-    private final boolean mImeSelectedOnBoot;
-
-    class SessionState {
-        final ClientState client;
-        final IInputMethod method;
-
-        IInputMethodSession session;
-        InputChannel channel;
-
-        @Override
-        public String toString() {
-            return "SessionState{uid " + client.uid + " pid " + client.pid
-                    + " method " + Integer.toHexString(
-                            System.identityHashCode(method))
-                    + " session " + Integer.toHexString(
-                            System.identityHashCode(session))
-                    + " channel " + channel
-                    + "}";
-        }
-
-        SessionState(ClientState _client, IInputMethod _method,
-                IInputMethodSession _session, InputChannel _channel) {
-            client = _client;
-            method = _method;
-            session = _session;
-            channel = _channel;
-        }
-    }
-
-    static final class ClientState {
-        final IInputMethodClient client;
-        final IInputContext inputContext;
-        final int uid;
-        final int pid;
-        final InputBinding binding;
-
-        boolean sessionRequested;
-        SessionState curSession;
-
-        @Override
-        public String toString() {
-            return "ClientState{" + Integer.toHexString(
-                    System.identityHashCode(this)) + " uid " + uid
-                    + " pid " + pid + "}";
-        }
-
-        ClientState(IInputMethodClient _client, IInputContext _inputContext,
-                int _uid, int _pid) {
-            client = _client;
-            inputContext = _inputContext;
-            uid = _uid;
-            pid = _pid;
-            binding = new InputBinding(null, inputContext.asBinder(), uid, pid);
-        }
-    }
-
-    final HashMap<IBinder, ClientState> mClients
-            = new HashMap<IBinder, ClientState>();
-
-    /**
-     * Set once the system is ready to run third party code.
-     */
-    boolean mSystemReady;
-
-    /**
-     * Id of the currently selected input method.
-     */
-    String mCurMethodId;
-
-    /**
-     * The current binding sequence number, incremented every time there is
-     * a new bind performed.
-     */
-    int mCurSeq;
-
-    /**
-     * The client that is currently bound to an input method.
-     */
-    ClientState mCurClient;
-
-    /**
-     * The last window token that gained focus.
-     */
-    IBinder mCurFocusedWindow;
-
-    /**
-     * The input context last provided by the current client.
-     */
-    IInputContext mCurInputContext;
-
-    /**
-     * The attributes last provided by the current client.
-     */
-    EditorInfo mCurAttribute;
-
-    /**
-     * The input method ID of the input method service that we are currently
-     * connected to or in the process of connecting to.
-     */
-    String mCurId;
-
-    /**
-     * The current subtype of the current input method.
-     */
-    private InputMethodSubtype mCurrentSubtype;
-
-    // This list contains the pairs of InputMethodInfo and InputMethodSubtype.
-    private final HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>
-            mShortcutInputMethodsAndSubtypes =
-                new HashMap<InputMethodInfo, ArrayList<InputMethodSubtype>>();
-
-    // Was the keyguard locked when this client became current?
-    private boolean mCurClientInKeyguard;
-
-    /**
-     * Set to true if our ServiceConnection is currently actively bound to
-     * a service (whether or not we have gotten its IBinder back yet).
-     */
-    boolean mHaveConnection;
-
-    /**
-     * Set if the client has asked for the input method to be shown.
-     */
-    boolean mShowRequested;
-
-    /**
-     * Set if we were explicitly told to show the input method.
-     */
-    boolean mShowExplicitlyRequested;
-
-    /**
-     * Set if we were forced to be shown.
-     */
-    boolean mShowForced;
-
-    /**
-     * Set if we last told the input method to show itself.
-     */
-    boolean mInputShown;
-
-    /**
-     * The Intent used to connect to the current input method.
-     */
-    Intent mCurIntent;
-
-    /**
-     * The token we have made for the currently active input method, to
-     * identify it in the future.
-     */
-    IBinder mCurToken;
-
-    /**
-     * If non-null, this is the input method service we are currently connected
-     * to.
-     */
-    IInputMethod mCurMethod;
-
-    /**
-     * Time that we last initiated a bind to the input method, to determine
-     * if we should try to disconnect and reconnect to it.
-     */
-    long mLastBindTime;
-
-    /**
-     * Have we called mCurMethod.bindInput()?
-     */
-    boolean mBoundToMethod;
-
-    /**
-     * Currently enabled session.  Only touched by service thread, not
-     * protected by a lock.
-     */
-    SessionState mEnabledSession;
-
-    /**
-     * True if the screen is on.  The value is true initially.
-     */
-    boolean mScreenOn = true;
-
-    int mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
-    int mImeWindowVis;
-
-    private AlertDialog.Builder mDialogBuilder;
-    private AlertDialog mSwitchingDialog;
-    private View mSwitchingDialogTitleView;
-    private InputMethodInfo[] mIms;
-    private int[] mSubtypeIds;
-    private Locale mLastSystemLocale;
-    private final MyPackageMonitor mMyPackageMonitor = new MyPackageMonitor();
-    private final IPackageManager mIPackageManager;
-
-    class SettingsObserver extends ContentObserver {
-        String mLastEnabled = "";
-
-        SettingsObserver(Handler handler) {
-            super(handler);
-            ContentResolver resolver = mContext.getContentResolver();
-            resolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
-            resolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.ENABLED_INPUT_METHODS), false, this);
-            resolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, this);
-        }
-
-        @Override public void onChange(boolean selfChange) {
-            synchronized (mMethodMap) {
-                boolean enabledChanged = false;
-                String newEnabled = mSettings.getEnabledInputMethodsStr();
-                if (!mLastEnabled.equals(newEnabled)) {
-                    mLastEnabled = newEnabled;
-                    enabledChanged = true;
-                }
-                updateFromSettingsLocked(enabledChanged);
-            }
-        }
-    }
-
-    class ImmsBroadcastReceiver extends android.content.BroadcastReceiver {
-        private void updateActive() {
-            // Inform the current client of the change in active status
-            if (mCurClient != null && mCurClient.client != null) {
-                executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
-                        MSG_SET_ACTIVE, mScreenOn ? 1 : 0, mCurClient));
-            }
-        }
-
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            if (Intent.ACTION_SCREEN_ON.equals(action)) {
-                mScreenOn = true;
-                refreshImeWindowVisibilityLocked();
-                updateActive();
-                return;
-            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
-                mScreenOn = false;
-                setImeWindowVisibilityStatusHiddenLocked();
-                updateActive();
-                return;
-            } else if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
-                hideInputMethodMenu();
-                // No need to updateActive
-                return;
-            } else {
-                Slog.w(TAG, "Unexpected intent " + intent);
-            }
-        }
-    }
-
-    class MyPackageMonitor extends PackageMonitor {
-        private boolean isChangingPackagesOfCurrentUser() {
-            final int userId = getChangingUserId();
-            final boolean retval = userId == mSettings.getCurrentUserId();
-            if (DEBUG) {
-                if (!retval) {
-                    Slog.d(TAG, "--- ignore this call back from a background user: " + userId);
-                }
-            }
-            return retval;
-        }
-
-        @Override
-        public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
-            if (!isChangingPackagesOfCurrentUser()) {
-                return false;
-            }
-            synchronized (mMethodMap) {
-                String curInputMethodId = mSettings.getSelectedInputMethod();
-                final int N = mMethodList.size();
-                if (curInputMethodId != null) {
-                    for (int i=0; i<N; i++) {
-                        InputMethodInfo imi = mMethodList.get(i);
-                        if (imi.getId().equals(curInputMethodId)) {
-                            for (String pkg : packages) {
-                                if (imi.getPackageName().equals(pkg)) {
-                                    if (!doit) {
-                                        return true;
-                                    }
-                                    resetSelectedInputMethodAndSubtypeLocked("");
-                                    chooseNewDefaultIMELocked();
-                                    return true;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            return false;
-        }
-
-        @Override
-        public void onSomePackagesChanged() {
-            if (!isChangingPackagesOfCurrentUser()) {
-                return;
-            }
-            synchronized (mMethodMap) {
-                InputMethodInfo curIm = null;
-                String curInputMethodId = mSettings.getSelectedInputMethod();
-                final int N = mMethodList.size();
-                if (curInputMethodId != null) {
-                    for (int i=0; i<N; i++) {
-                        InputMethodInfo imi = mMethodList.get(i);
-                        final String imiId = imi.getId();
-                        if (imiId.equals(curInputMethodId)) {
-                            curIm = imi;
-                        }
-
-                        int change = isPackageDisappearing(imi.getPackageName());
-                        if (isPackageModified(imi.getPackageName())) {
-                            mFileManager.deleteAllInputMethodSubtypes(imiId);
-                        }
-                        if (change == PACKAGE_TEMPORARY_CHANGE
-                                || change == PACKAGE_PERMANENT_CHANGE) {
-                            Slog.i(TAG, "Input method uninstalled, disabling: "
-                                    + imi.getComponent());
-                            setInputMethodEnabledLocked(imi.getId(), false);
-                        }
-                    }
-                }
-
-                buildInputMethodListLocked(
-                        mMethodList, mMethodMap, false /* resetDefaultEnabledIme */);
-
-                boolean changed = false;
-
-                if (curIm != null) {
-                    int change = isPackageDisappearing(curIm.getPackageName()); 
-                    if (change == PACKAGE_TEMPORARY_CHANGE
-                            || change == PACKAGE_PERMANENT_CHANGE) {
-                        ServiceInfo si = null;
-                        try {
-                            si = mIPackageManager.getServiceInfo(
-                                    curIm.getComponent(), 0, mSettings.getCurrentUserId());
-                        } catch (RemoteException ex) {
-                        }
-                        if (si == null) {
-                            // Uh oh, current input method is no longer around!
-                            // Pick another one...
-                            Slog.i(TAG, "Current input method removed: " + curInputMethodId);
-                            setImeWindowVisibilityStatusHiddenLocked();
-                            if (!chooseNewDefaultIMELocked()) {
-                                changed = true;
-                                curIm = null;
-                                Slog.i(TAG, "Unsetting current input method");
-                                resetSelectedInputMethodAndSubtypeLocked("");
-                            }
-                        }
-                    }
-                }
-
-                if (curIm == null) {
-                    // We currently don't have a default input method... is
-                    // one now available?
-                    changed = chooseNewDefaultIMELocked();
-                }
-
-                if (changed) {
-                    updateFromSettingsLocked(false);
-                }
-            }
-        }
-    }
-
-    private static final class MethodCallback extends IInputSessionCallback.Stub {
-        private final InputMethodManagerService mParentIMMS;
-        private final IInputMethod mMethod;
-        private final InputChannel mChannel;
-
-        MethodCallback(InputMethodManagerService imms, IInputMethod method,
-                InputChannel channel) {
-            mParentIMMS = imms;
-            mMethod = method;
-            mChannel = channel;
-        }
-
-        @Override
-        public void sessionCreated(IInputMethodSession session) {
-            mParentIMMS.onSessionCreated(mMethod, session, mChannel);
-        }
-    }
-
-    private class HardKeyboardListener
-            implements WindowManagerService.OnHardKeyboardStatusChangeListener {
-        @Override
-        public void onHardKeyboardStatusChange(boolean available, boolean enabled) {
-            mHandler.sendMessage(mHandler.obtainMessage(
-                    MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0, enabled ? 1 : 0));
-        }
-
-        public void handleHardKeyboardStatusChange(boolean available, boolean enabled) {
-            if (DEBUG) {
-                Slog.w(TAG, "HardKeyboardStatusChanged: available = " + available + ", enabled = "
-                        + enabled);
-            }
-            synchronized(mMethodMap) {
-                if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
-                        && mSwitchingDialog.isShowing()) {
-                    mSwitchingDialogTitleView.findViewById(
-                            com.android.internal.R.id.hard_keyboard_section).setVisibility(
-                                    available ? View.VISIBLE : View.GONE);
-                }
-            }
-        }
-    }
-
-    public InputMethodManagerService(Context context, WindowManagerService windowManager) {
-        mIPackageManager = AppGlobals.getPackageManager();
-        mContext = context;
-        mRes = context.getResources();
-        mHandler = new Handler(this);
-        mIWindowManager = IWindowManager.Stub.asInterface(
-                ServiceManager.getService(Context.WINDOW_SERVICE));
-        mCaller = new HandlerCaller(context, null, new HandlerCaller.Callback() {
-            @Override
-            public void executeMessage(Message msg) {
-                handleMessage(msg);
-            }
-        }, true /*asyncHandler*/);
-        mWindowManagerService = windowManager;
-        mHardKeyboardListener = new HardKeyboardListener();
-        mHasFeature = context.getPackageManager().hasSystemFeature(
-                PackageManager.FEATURE_INPUT_METHODS);
-
-        mImeSwitcherNotification = new Notification();
-        mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default;
-        mImeSwitcherNotification.when = 0;
-        mImeSwitcherNotification.flags = Notification.FLAG_ONGOING_EVENT;
-        mImeSwitcherNotification.tickerText = null;
-        mImeSwitcherNotification.defaults = 0; // please be quiet
-        mImeSwitcherNotification.sound = null;
-        mImeSwitcherNotification.vibrate = null;
-
-        // Tag this notification specially so SystemUI knows it's important
-        mImeSwitcherNotification.kind = new String[] { "android.system.imeswitcher" };
-
-        Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
-        mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
-
-        mShowOngoingImeSwitcherForPhones = false;
-
-        final IntentFilter broadcastFilter = new IntentFilter();
-        broadcastFilter.addAction(Intent.ACTION_SCREEN_ON);
-        broadcastFilter.addAction(Intent.ACTION_SCREEN_OFF);
-        broadcastFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
-        mContext.registerReceiver(new ImmsBroadcastReceiver(), broadcastFilter);
-
-        mNotificationShown = false;
-        int userId = 0;
-        try {
-            ActivityManagerNative.getDefault().registerUserSwitchObserver(
-                    new IUserSwitchObserver.Stub() {
-                        @Override
-                        public void onUserSwitching(int newUserId, IRemoteCallback reply) {
-                            synchronized(mMethodMap) {
-                                switchUserLocked(newUserId);
-                            }
-                            if (reply != null) {
-                                try {
-                                    reply.sendResult(null);
-                                } catch (RemoteException e) {
-                                }
-                            }
-                        }
-
-                        @Override
-                        public void onUserSwitchComplete(int newUserId) throws RemoteException {
-                        }
-                    });
-            userId = ActivityManagerNative.getDefault().getCurrentUser().id;
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Couldn't get current user ID; guessing it's 0", e);
-        }
-        mMyPackageMonitor.register(mContext, null, UserHandle.ALL, true);
-
-        // mSettings should be created before buildInputMethodListLocked
-        mSettings = new InputMethodSettings(
-                mRes, context.getContentResolver(), mMethodMap, mMethodList, userId);
-        mFileManager = new InputMethodFileManager(mMethodMap, userId);
-        mImListManager = new InputMethodAndSubtypeListManager(context, this);
-
-        // Just checking if defaultImiId is empty or not
-        final String defaultImiId = mSettings.getSelectedInputMethod();
-        if (DEBUG) {
-            Slog.d(TAG, "Initial default ime = " + defaultImiId);
-        }
-        mImeSelectedOnBoot = !TextUtils.isEmpty(defaultImiId);
-
-        buildInputMethodListLocked(mMethodList, mMethodMap,
-                !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
-        mSettings.enableAllIMEsIfThereIsNoEnabledIME();
-
-        if (!mImeSelectedOnBoot) {
-            Slog.w(TAG, "No IME selected. Choose the most applicable IME.");
-            resetDefaultImeLocked(context);
-        }
-
-        mSettingsObserver = new SettingsObserver(mHandler);
-        updateFromSettingsLocked(true);
-
-        // IMMS wants to receive Intent.ACTION_LOCALE_CHANGED in order to update the current IME
-        // according to the new system locale.
-        final IntentFilter filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_LOCALE_CHANGED);
-        mContext.registerReceiver(
-                new BroadcastReceiver() {
-                    @Override
-                    public void onReceive(Context context, Intent intent) {
-                        synchronized(mMethodMap) {
-                            resetStateIfCurrentLocaleChangedLocked();
-                        }
-                    }
-                }, filter);
-    }
-
-    private void resetDefaultImeLocked(Context context) {
-        // Do not reset the default (current) IME when it is a 3rd-party IME
-        if (mCurMethodId != null
-                && !InputMethodUtils.isSystemIme(mMethodMap.get(mCurMethodId))) {
-            return;
-        }
-
-        InputMethodInfo defIm = null;
-        for (InputMethodInfo imi : mMethodList) {
-            if (defIm == null) {
-                if (InputMethodUtils.isValidSystemDefaultIme(
-                        mSystemReady, imi, context)) {
-                    defIm = imi;
-                    Slog.i(TAG, "Selected default: " + imi.getId());
-                }
-            }
-        }
-        if (defIm == null && mMethodList.size() > 0) {
-            defIm = InputMethodUtils.getMostApplicableDefaultIME(
-                    mSettings.getEnabledInputMethodListLocked());
-            Slog.i(TAG, "No default found, using " + defIm.getId());
-        }
-        if (defIm != null) {
-            setSelectedInputMethodAndSubtypeLocked(defIm, NOT_A_SUBTYPE_ID, false);
-        }
-    }
-
-    private void resetAllInternalStateLocked(final boolean updateOnlyWhenLocaleChanged,
-            final boolean resetDefaultEnabledIme) {
-        if (!mSystemReady) {
-            // not system ready
-            return;
-        }
-        final Locale newLocale = mRes.getConfiguration().locale;
-        if (!updateOnlyWhenLocaleChanged
-                || (newLocale != null && !newLocale.equals(mLastSystemLocale))) {
-            if (!updateOnlyWhenLocaleChanged) {
-                hideCurrentInputLocked(0, null);
-                mCurMethodId = null;
-                unbindCurrentMethodLocked(true, false);
-            }
-            if (DEBUG) {
-                Slog.i(TAG, "Locale has been changed to " + newLocale);
-            }
-            // InputMethodAndSubtypeListManager should be reset when the locale is changed.
-            mImListManager = new InputMethodAndSubtypeListManager(mContext, this);
-            buildInputMethodListLocked(mMethodList, mMethodMap, resetDefaultEnabledIme);
-            if (!updateOnlyWhenLocaleChanged) {
-                final String selectedImiId = mSettings.getSelectedInputMethod();
-                if (TextUtils.isEmpty(selectedImiId)) {
-                    // This is the first time of the user switch and
-                    // set the current ime to the proper one.
-                    resetDefaultImeLocked(mContext);
-                }
-            } else {
-                // If the locale is changed, needs to reset the default ime
-                resetDefaultImeLocked(mContext);
-            }
-            updateFromSettingsLocked(true);
-            mLastSystemLocale = newLocale;
-            if (!updateOnlyWhenLocaleChanged) {
-                try {
-                    startInputInnerLocked();
-                } catch (RuntimeException e) {
-                    Slog.w(TAG, "Unexpected exception", e);
-                }
-            }
-        }
-    }
-
-    private void resetStateIfCurrentLocaleChangedLocked() {
-        resetAllInternalStateLocked(true /* updateOnlyWhenLocaleChanged */,
-                true /* resetDefaultImeLocked */);
-    }
-
-    private void switchUserLocked(int newUserId) {
-        mSettings.setCurrentUserId(newUserId);
-        // InputMethodFileManager should be reset when the user is changed
-        mFileManager = new InputMethodFileManager(mMethodMap, newUserId);
-        final String defaultImiId = mSettings.getSelectedInputMethod();
-        // For secondary users, the list of enabled IMEs may not have been updated since the
-        // callbacks to PackageMonitor are ignored for the secondary user. Here, defaultImiId may
-        // not be empty even if the IME has been uninstalled by the primary user.
-        // Even in such cases, IMMS works fine because it will find the most applicable
-        // IME for that user.
-        final boolean initialUserSwitch = TextUtils.isEmpty(defaultImiId);
-        if (DEBUG) {
-            Slog.d(TAG, "Switch user: " + newUserId + " current ime = " + defaultImiId);
-        }
-        resetAllInternalStateLocked(false  /* updateOnlyWhenLocaleChanged */,
-                initialUserSwitch /* needsToResetDefaultIme */);
-        if (initialUserSwitch) {
-            InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(mContext.getPackageManager(),
-                    mSettings.getEnabledInputMethodListLocked());
-        }
-    }
-
-    @Override
-    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
-            throws RemoteException {
-        try {
-            return super.onTransact(code, data, reply, flags);
-        } catch (RuntimeException e) {
-            // The input method manager only throws security exceptions, so let's
-            // log all others.
-            if (!(e instanceof SecurityException)) {
-                Slog.wtf(TAG, "Input Method Manager Crash", e);
-            }
-            throw e;
-        }
-    }
-
-    public void systemRunning(StatusBarManagerService statusBar) {
-        synchronized (mMethodMap) {
-            if (DEBUG) {
-                Slog.d(TAG, "--- systemReady");
-            }
-            if (!mSystemReady) {
-                mSystemReady = true;
-                mKeyguardManager =
-                        (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
-                mNotificationManager = (NotificationManager)
-                        mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-                mStatusBar = statusBar;
-                statusBar.setIconVisibility("ime", false);
-                updateImeWindowStatusLocked();
-                mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
-                        com.android.internal.R.bool.show_ongoing_ime_switcher);
-                if (mShowOngoingImeSwitcherForPhones) {
-                    mWindowManagerService.setOnHardKeyboardStatusChangeListener(
-                            mHardKeyboardListener);
-                }
-                buildInputMethodListLocked(mMethodList, mMethodMap,
-                        !mImeSelectedOnBoot /* resetDefaultEnabledIme */);
-                if (!mImeSelectedOnBoot) {
-                    Slog.w(TAG, "Reset the default IME as \"Resource\" is ready here.");
-                    resetStateIfCurrentLocaleChangedLocked();
-                    InputMethodUtils.setNonSelectedSystemImesDisabledUntilUsed(
-                            mContext.getPackageManager(),
-                            mSettings.getEnabledInputMethodListLocked());
-                }
-                mLastSystemLocale = mRes.getConfiguration().locale;
-                try {
-                    startInputInnerLocked();
-                } catch (RuntimeException e) {
-                    Slog.w(TAG, "Unexpected exception", e);
-                }
-            }
-        }
-    }
-
-    private void setImeWindowVisibilityStatusHiddenLocked() {
-        mImeWindowVis = 0;
-        updateImeWindowStatusLocked();
-    }
-
-    private void refreshImeWindowVisibilityLocked() {
-        final Configuration conf = mRes.getConfiguration();
-        final boolean haveHardKeyboard = conf.keyboard
-                != Configuration.KEYBOARD_NOKEYS;
-        final boolean hardKeyShown = haveHardKeyboard
-                && conf.hardKeyboardHidden
-                        != Configuration.HARDKEYBOARDHIDDEN_YES;
-
-        final boolean isScreenLocked = isKeyguardLocked();
-        final boolean inputActive = !isScreenLocked && (mInputShown || hardKeyShown);
-        // We assume the softkeyboard is shown when the input is active as long as the
-        // hard keyboard is not shown.
-        final boolean inputVisible = inputActive && !hardKeyShown;
-        mImeWindowVis = (inputActive ? InputMethodService.IME_ACTIVE : 0)
-                | (inputVisible ? InputMethodService.IME_VISIBLE : 0);
-        updateImeWindowStatusLocked();
-    }
-
-    private void updateImeWindowStatusLocked() {
-        setImeWindowStatus(mCurToken, mImeWindowVis, mBackDisposition);
-    }
-
-    // ---------------------------------------------------------------------------------------
-    // Check whether or not this is a valid IPC. Assumes an IPC is valid when either
-    // 1) it comes from the system process
-    // 2) the calling process' user id is identical to the current user id IMMS thinks.
-    private boolean calledFromValidUser() {
-        final int uid = Binder.getCallingUid();
-        final int userId = UserHandle.getUserId(uid);
-        if (DEBUG) {
-            Slog.d(TAG, "--- calledFromForegroundUserOrSystemProcess ? "
-                    + "calling uid = " + uid + " system uid = " + Process.SYSTEM_UID
-                    + " calling userId = " + userId + ", foreground user id = "
-                    + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid()
-                    + InputMethodUtils.getApiCallStack());
-        }
-        if (uid == Process.SYSTEM_UID || userId == mSettings.getCurrentUserId()) {
-            return true;
-        }
-
-        // Caveat: A process which has INTERACT_ACROSS_USERS_FULL gets results for the
-        // foreground user, not for the user of that process. Accordingly InputMethodManagerService
-        // must not manage background users' states in any functions.
-        // Note that privacy-sensitive IPCs, such as setInputMethod, are still securely guarded
-        // by a token.
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
-                        == PackageManager.PERMISSION_GRANTED) {
-            if (DEBUG) {
-                Slog.d(TAG, "--- Access granted because the calling process has "
-                        + "the INTERACT_ACROSS_USERS_FULL permission");
-            }
-            return true;
-        }
-        Slog.w(TAG, "--- IPC called from background users. Ignore. \n"
-                + InputMethodUtils.getStackTrace());
-        return false;
-    }
-
-    private boolean bindCurrentInputMethodService(
-            Intent service, ServiceConnection conn, int flags) {
-        if (service == null || conn == null) {
-            Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn);
-            return false;
-        }
-        return mContext.bindServiceAsUser(service, conn, flags,
-                new UserHandle(mSettings.getCurrentUserId()));
-    }
-
-    @Override
-    public List<InputMethodInfo> getInputMethodList() {
-        // TODO: Make this work even for non-current users?
-        if (!calledFromValidUser()) {
-            return Collections.emptyList();
-        }
-        synchronized (mMethodMap) {
-            return new ArrayList<InputMethodInfo>(mMethodList);
-        }
-    }
-
-    @Override
-    public List<InputMethodInfo> getEnabledInputMethodList() {
-        // TODO: Make this work even for non-current users?
-        if (!calledFromValidUser()) {
-            return Collections.emptyList();
-        }
-        synchronized (mMethodMap) {
-            return mSettings.getEnabledInputMethodListLocked();
-        }
-    }
-
-    private HashMap<InputMethodInfo, List<InputMethodSubtype>>
-            getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked() {
-        HashMap<InputMethodInfo, List<InputMethodSubtype>> enabledInputMethodAndSubtypes =
-                new HashMap<InputMethodInfo, List<InputMethodSubtype>>();
-        for (InputMethodInfo imi: mSettings.getEnabledInputMethodListLocked()) {
-            enabledInputMethodAndSubtypes.put(
-                    imi, mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true));
-        }
-        return enabledInputMethodAndSubtypes;
-    }
-
-    /**
-     * @param imiId if null, returns enabled subtypes for the current imi
-     * @return enabled subtypes of the specified imi
-     */
-    @Override
-    public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(String imiId,
-            boolean allowsImplicitlySelectedSubtypes) {
-        // TODO: Make this work even for non-current users?
-        if (!calledFromValidUser()) {
-            return Collections.<InputMethodSubtype>emptyList();
-        }
-        synchronized (mMethodMap) {
-            final InputMethodInfo imi;
-            if (imiId == null && mCurMethodId != null) {
-                imi = mMethodMap.get(mCurMethodId);
-            } else {
-                imi = mMethodMap.get(imiId);
-            }
-            if (imi == null) {
-                return Collections.<InputMethodSubtype>emptyList();
-            }
-            return mSettings.getEnabledInputMethodSubtypeListLocked(
-                    mContext, imi, allowsImplicitlySelectedSubtypes);
-        }
-    }
-
-    @Override
-    public void addClient(IInputMethodClient client,
-            IInputContext inputContext, int uid, int pid) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            mClients.put(client.asBinder(), new ClientState(client,
-                    inputContext, uid, pid));
-        }
-    }
-
-    @Override
-    public void removeClient(IInputMethodClient client) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            ClientState cs = mClients.remove(client.asBinder());
-            if (cs != null) {
-                clearClientSessionLocked(cs);
-            }
-        }
-    }
-
-    void executeOrSendMessage(IInterface target, Message msg) {
-         if (target.asBinder() instanceof Binder) {
-             mCaller.sendMessage(msg);
-         } else {
-             handleMessage(msg);
-             msg.recycle();
-         }
-    }
-
-    void unbindCurrentClientLocked() {
-        if (mCurClient != null) {
-            if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
-                    + mCurClient.client.asBinder());
-            if (mBoundToMethod) {
-                mBoundToMethod = false;
-                if (mCurMethod != null) {
-                    executeOrSendMessage(mCurMethod, mCaller.obtainMessageO(
-                            MSG_UNBIND_INPUT, mCurMethod));
-                }
-            }
-
-            executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
-                    MSG_SET_ACTIVE, 0, mCurClient));
-            executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
-                    MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
-            mCurClient.sessionRequested = false;
-            mCurClient = null;
-
-            hideInputMethodMenuLocked();
-        }
-    }
-
-    private int getImeShowFlags() {
-        int flags = 0;
-        if (mShowForced) {
-            flags |= InputMethod.SHOW_FORCED
-                    | InputMethod.SHOW_EXPLICIT;
-        } else if (mShowExplicitlyRequested) {
-            flags |= InputMethod.SHOW_EXPLICIT;
-        }
-        return flags;
-    }
-
-    private int getAppShowFlags() {
-        int flags = 0;
-        if (mShowForced) {
-            flags |= InputMethodManager.SHOW_FORCED;
-        } else if (!mShowExplicitlyRequested) {
-            flags |= InputMethodManager.SHOW_IMPLICIT;
-        }
-        return flags;
-    }
-
-    InputBindResult attachNewInputLocked(boolean initial) {
-        if (!mBoundToMethod) {
-            executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
-                    MSG_BIND_INPUT, mCurMethod, mCurClient.binding));
-            mBoundToMethod = true;
-        }
-        final SessionState session = mCurClient.curSession;
-        if (initial) {
-            executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
-                    MSG_START_INPUT, session, mCurInputContext, mCurAttribute));
-        } else {
-            executeOrSendMessage(session.method, mCaller.obtainMessageOOO(
-                    MSG_RESTART_INPUT, session, mCurInputContext, mCurAttribute));
-        }
-        if (mShowRequested) {
-            if (DEBUG) Slog.v(TAG, "Attach new input asks to show input");
-            showCurrentInputLocked(getAppShowFlags(), null);
-        }
-        return new InputBindResult(session.session,
-                session.channel != null ? session.channel.dup() : null, mCurId, mCurSeq);
-    }
-
-    InputBindResult startInputLocked(IInputMethodClient client,
-            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
-        // If no method is currently selected, do nothing.
-        if (mCurMethodId == null) {
-            return mNoBinding;
-        }
-
-        ClientState cs = mClients.get(client.asBinder());
-        if (cs == null) {
-            throw new IllegalArgumentException("unknown client "
-                    + client.asBinder());
-        }
-
-        try {
-            if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
-                // Check with the window manager to make sure this client actually
-                // has a window with focus.  If not, reject.  This is thread safe
-                // because if the focus changes some time before or after, the
-                // next client receiving focus that has any interest in input will
-                // be calling through here after that change happens.
-                Slog.w(TAG, "Starting input on non-focused client " + cs.client
-                        + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
-                return null;
-            }
-        } catch (RemoteException e) {
-        }
-
-        return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
-    }
-
-    InputBindResult startInputUncheckedLocked(ClientState cs,
-            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
-        // If no method is currently selected, do nothing.
-        if (mCurMethodId == null) {
-            return mNoBinding;
-        }
-
-        if (mCurClient != cs) {
-            // Was the keyguard locked when switching over to the new client?
-            mCurClientInKeyguard = isKeyguardLocked();
-            // If the client is changing, we need to switch over to the new
-            // one.
-            unbindCurrentClientLocked();
-            if (DEBUG) Slog.v(TAG, "switching to client: client = "
-                    + cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard);
-
-            // If the screen is on, inform the new client it is active
-            if (mScreenOn) {
-                executeOrSendMessage(cs.client, mCaller.obtainMessageIO(
-                        MSG_SET_ACTIVE, mScreenOn ? 1 : 0, cs));
-            }
-        }
-
-        // Bump up the sequence for this client and attach it.
-        mCurSeq++;
-        if (mCurSeq <= 0) mCurSeq = 1;
-        mCurClient = cs;
-        mCurInputContext = inputContext;
-        mCurAttribute = attribute;
-
-        // Check if the input method is changing.
-        if (mCurId != null && mCurId.equals(mCurMethodId)) {
-            if (cs.curSession != null) {
-                // Fast case: if we are already connected to the input method,
-                // then just return it.
-                return attachNewInputLocked(
-                        (controlFlags&InputMethodManager.CONTROL_START_INITIAL) != 0);
-            }
-            if (mHaveConnection) {
-                if (mCurMethod != null) {
-                    // Return to client, and we will get back with it when
-                    // we have had a session made for it.
-                    requestClientSessionLocked(cs);
-                    return new InputBindResult(null, null, mCurId, mCurSeq);
-                } else if (SystemClock.uptimeMillis()
-                        < (mLastBindTime+TIME_TO_RECONNECT)) {
-                    // In this case we have connected to the service, but
-                    // don't yet have its interface.  If it hasn't been too
-                    // long since we did the connection, we'll return to
-                    // the client and wait to get the service interface so
-                    // we can report back.  If it has been too long, we want
-                    // to fall through so we can try a disconnect/reconnect
-                    // to see if we can get back in touch with the service.
-                    return new InputBindResult(null, null, mCurId, mCurSeq);
-                } else {
-                    EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME,
-                            mCurMethodId, SystemClock.uptimeMillis()-mLastBindTime, 0);
-                }
-            }
-        }
-
-        return startInputInnerLocked();
-    }
-
-    InputBindResult startInputInnerLocked() {
-        if (mCurMethodId == null) {
-            return mNoBinding;
-        }
-
-        if (!mSystemReady) {
-            // If the system is not yet ready, we shouldn't be running third
-            // party code.
-            return new InputBindResult(null, null, mCurMethodId, mCurSeq);
-        }
-
-        InputMethodInfo info = mMethodMap.get(mCurMethodId);
-        if (info == null) {
-            throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
-        }
-
-        unbindCurrentMethodLocked(false, true);
-
-        mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
-        mCurIntent.setComponent(info.getComponent());
-        mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
-                com.android.internal.R.string.input_method_binding_label);
-        mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
-                mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
-        if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
-                | Context.BIND_NOT_VISIBLE | Context.BIND_SHOWING_UI)) {
-            mLastBindTime = SystemClock.uptimeMillis();
-            mHaveConnection = true;
-            mCurId = info.getId();
-            mCurToken = new Binder();
-            try {
-                if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
-                mIWindowManager.addWindowToken(mCurToken,
-                        WindowManager.LayoutParams.TYPE_INPUT_METHOD);
-            } catch (RemoteException e) {
-            }
-            return new InputBindResult(null, null, mCurId, mCurSeq);
-        } else {
-            mCurIntent = null;
-            Slog.w(TAG, "Failure connecting to input method service: "
-                    + mCurIntent);
-        }
-        return null;
-    }
-
-    @Override
-    public InputBindResult startInput(IInputMethodClient client,
-            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
-        if (!calledFromValidUser()) {
-            return null;
-        }
-        synchronized (mMethodMap) {
-            final long ident = Binder.clearCallingIdentity();
-            try {
-                return startInputLocked(client, inputContext, attribute, controlFlags);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public void finishInput(IInputMethodClient client) {
-    }
-
-    @Override
-    public void onServiceConnected(ComponentName name, IBinder service) {
-        synchronized (mMethodMap) {
-            if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
-                mCurMethod = IInputMethod.Stub.asInterface(service);
-                if (mCurToken == null) {
-                    Slog.w(TAG, "Service connected without a token!");
-                    unbindCurrentMethodLocked(false, false);
-                    return;
-                }
-                if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
-                executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
-                        MSG_ATTACH_TOKEN, mCurMethod, mCurToken));
-                if (mCurClient != null) {
-                    clearClientSessionLocked(mCurClient);
-                    requestClientSessionLocked(mCurClient);
-                }
-            }
-        }
-    }
-
-    void onSessionCreated(IInputMethod method, IInputMethodSession session,
-            InputChannel channel) {
-        synchronized (mMethodMap) {
-            if (mCurMethod != null && method != null
-                    && mCurMethod.asBinder() == method.asBinder()) {
-                if (mCurClient != null) {
-                    clearClientSessionLocked(mCurClient);
-                    mCurClient.curSession = new SessionState(mCurClient,
-                            method, session, channel);
-                    InputBindResult res = attachNewInputLocked(true);
-                    if (res.method != null) {
-                        executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO(
-                                MSG_BIND_METHOD, mCurClient.client, res));
-                    }
-                    return;
-                }
-            }
-        }
-
-        // Session abandoned.  Close its associated input channel.
-        channel.dispose();
-    }
-
-    void unbindCurrentMethodLocked(boolean reportToClient, boolean savePosition) {
-        if (mVisibleBound) {
-            mContext.unbindService(mVisibleConnection);
-            mVisibleBound = false;
-        }
-
-        if (mHaveConnection) {
-            mContext.unbindService(this);
-            mHaveConnection = false;
-        }
-
-        if (mCurToken != null) {
-            try {
-                if (DEBUG) Slog.v(TAG, "Removing window token: " + mCurToken);
-                if ((mImeWindowVis & InputMethodService.IME_ACTIVE) != 0 && savePosition) {
-                    // The current IME is shown. Hence an IME switch (transition) is happening.
-                    mWindowManagerService.saveLastInputMethodWindowForTransition();
-                }
-                mIWindowManager.removeWindowToken(mCurToken);
-            } catch (RemoteException e) {
-            }
-            mCurToken = null;
-        }
-
-        mCurId = null;
-        clearCurMethodLocked();
-
-        if (reportToClient && mCurClient != null) {
-            executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
-                    MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
-        }
-    }
-
-    void requestClientSessionLocked(ClientState cs) {
-        if (!cs.sessionRequested) {
-            if (DEBUG) Slog.v(TAG, "Creating new session for client " + cs);
-            InputChannel[] channels = InputChannel.openInputChannelPair(cs.toString());
-            cs.sessionRequested = true;
-            executeOrSendMessage(mCurMethod, mCaller.obtainMessageOOO(
-                    MSG_CREATE_SESSION, mCurMethod, channels[1],
-                    new MethodCallback(this, mCurMethod, channels[0])));
-        }
-    }
-
-    void clearClientSessionLocked(ClientState cs) {
-        finishSessionLocked(cs.curSession);
-        cs.curSession = null;
-        cs.sessionRequested = false;
-    }
-
-    private void finishSessionLocked(SessionState sessionState) {
-        if (sessionState != null) {
-            if (sessionState.session != null) {
-                try {
-                    sessionState.session.finishSession();
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Session failed to close due to remote exception", e);
-                    setImeWindowVisibilityStatusHiddenLocked();
-                }
-                sessionState.session = null;
-            }
-            if (sessionState.channel != null) {
-                sessionState.channel.dispose();
-                sessionState.channel = null;
-            }
-        }
-    }
-
-    void clearCurMethodLocked() {
-        if (mCurMethod != null) {
-            for (ClientState cs : mClients.values()) {
-                clearClientSessionLocked(cs);
-            }
-
-            finishSessionLocked(mEnabledSession);
-            mEnabledSession = null;
-            mCurMethod = null;
-        }
-        if (mStatusBar != null) {
-            mStatusBar.setIconVisibility("ime", false);
-        }
-    }
-
-    @Override
-    public void onServiceDisconnected(ComponentName name) {
-        synchronized (mMethodMap) {
-            if (DEBUG) Slog.v(TAG, "Service disconnected: " + name
-                    + " mCurIntent=" + mCurIntent);
-            if (mCurMethod != null && mCurIntent != null
-                    && name.equals(mCurIntent.getComponent())) {
-                clearCurMethodLocked();
-                // We consider this to be a new bind attempt, since the system
-                // should now try to restart the service for us.
-                mLastBindTime = SystemClock.uptimeMillis();
-                mShowRequested = mInputShown;
-                mInputShown = false;
-                if (mCurClient != null) {
-                    executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
-                            MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
-                }
-            }
-        }
-    }
-
-    @Override
-    public void updateStatusIcon(IBinder token, String packageName, int iconId) {
-        int uid = Binder.getCallingUid();
-        long ident = Binder.clearCallingIdentity();
-        try {
-            if (token == null || mCurToken != token) {
-                Slog.w(TAG, "Ignoring setInputMethod of uid " + uid + " token: " + token);
-                return;
-            }
-
-            synchronized (mMethodMap) {
-                if (iconId == 0) {
-                    if (DEBUG) Slog.d(TAG, "hide the small icon for the input method");
-                    if (mStatusBar != null) {
-                        mStatusBar.setIconVisibility("ime", false);
-                    }
-                } else if (packageName != null) {
-                    if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
-                    CharSequence contentDescription = null;
-                    try {
-                        // Use PackageManager to load label
-                        final PackageManager packageManager = mContext.getPackageManager();
-                        contentDescription = packageManager.getApplicationLabel(
-                                mIPackageManager.getApplicationInfo(packageName, 0,
-                                        mSettings.getCurrentUserId()));
-                    } catch (RemoteException e) {
-                        /* ignore */
-                    }
-                    if (mStatusBar != null) {
-                        mStatusBar.setIcon("ime", packageName, iconId, 0,
-                                contentDescription  != null
-                                        ? contentDescription.toString() : null);
-                        mStatusBar.setIconVisibility("ime", true);
-                    }
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private boolean needsToShowImeSwitchOngoingNotification() {
-        if (!mShowOngoingImeSwitcherForPhones) return false;
-        if (isScreenLocked()) return false;
-        synchronized (mMethodMap) {
-            List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
-            final int N = imis.size();
-            if (N > 2) return true;
-            if (N < 1) return false;
-            int nonAuxCount = 0;
-            int auxCount = 0;
-            InputMethodSubtype nonAuxSubtype = null;
-            InputMethodSubtype auxSubtype = null;
-            for(int i = 0; i < N; ++i) {
-                final InputMethodInfo imi = imis.get(i);
-                final List<InputMethodSubtype> subtypes =
-                        mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
-                final int subtypeCount = subtypes.size();
-                if (subtypeCount == 0) {
-                    ++nonAuxCount;
-                } else {
-                    for (int j = 0; j < subtypeCount; ++j) {
-                        final InputMethodSubtype subtype = subtypes.get(j);
-                        if (!subtype.isAuxiliary()) {
-                            ++nonAuxCount;
-                            nonAuxSubtype = subtype;
-                        } else {
-                            ++auxCount;
-                            auxSubtype = subtype;
-                        }
-                    }
-                }
-            }
-            if (nonAuxCount > 1 || auxCount > 1) {
-                return true;
-            } else if (nonAuxCount == 1 && auxCount == 1) {
-                if (nonAuxSubtype != null && auxSubtype != null
-                        && (nonAuxSubtype.getLocale().equals(auxSubtype.getLocale())
-                                || auxSubtype.overridesImplicitlyEnabledSubtype()
-                                || nonAuxSubtype.overridesImplicitlyEnabledSubtype())
-                        && nonAuxSubtype.containsExtraValueKey(TAG_TRY_SUPPRESSING_IME_SWITCHER)) {
-                    return false;
-                }
-                return true;
-            }
-            return false;
-        }
-    }
-
-    private boolean isKeyguardLocked() {
-        return mKeyguardManager != null && mKeyguardManager.isKeyguardLocked();
-    }
-
-    // Caution! This method is called in this class. Handle multi-user carefully
-    @SuppressWarnings("deprecation")
-    @Override
-    public void setImeWindowStatus(IBinder token, int vis, int backDisposition) {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            if (token == null || mCurToken != token) {
-                int uid = Binder.getCallingUid();
-                Slog.w(TAG, "Ignoring setImeWindowStatus of uid " + uid + " token: " + token);
-                return;
-            }
-            synchronized (mMethodMap) {
-                // apply policy for binder calls
-                if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
-                    vis = 0;
-                }
-                mImeWindowVis = vis;
-                mBackDisposition = backDisposition;
-                if (mStatusBar != null) {
-                    mStatusBar.setImeWindowStatus(token, vis, backDisposition);
-                }
-                final boolean iconVisibility = ((vis & (InputMethodService.IME_ACTIVE)) != 0)
-                        && (mWindowManagerService.isHardKeyboardAvailable()
-                                || (vis & (InputMethodService.IME_VISIBLE)) != 0);
-                final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
-                if (imi != null && iconVisibility && needsToShowImeSwitchOngoingNotification()) {
-                    // Used to load label
-                    final CharSequence title = mRes.getText(
-                            com.android.internal.R.string.select_input_method);
-                    final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName(
-                            mContext, imi, mCurrentSubtype);
-
-                    mImeSwitcherNotification.setLatestEventInfo(
-                            mContext, title, summary, mImeSwitchPendingIntent);
-                    if (mNotificationManager != null) {
-                        if (DEBUG) {
-                            Slog.d(TAG, "--- show notification: label =  " + summary);
-                        }
-                        mNotificationManager.notifyAsUser(null,
-                                com.android.internal.R.string.select_input_method,
-                                mImeSwitcherNotification, UserHandle.ALL);
-                        mNotificationShown = true;
-                    }
-                } else {
-                    if (mNotificationShown && mNotificationManager != null) {
-                        if (DEBUG) {
-                            Slog.d(TAG, "--- hide notification");
-                        }
-                        mNotificationManager.cancelAsUser(null,
-                                com.android.internal.R.string.select_input_method, UserHandle.ALL);
-                        mNotificationShown = false;
-                    }
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public void registerSuggestionSpansForNotification(SuggestionSpan[] spans) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
-            for (int i = 0; i < spans.length; ++i) {
-                SuggestionSpan ss = spans[i];
-                if (!TextUtils.isEmpty(ss.getNotificationTargetClassName())) {
-                    mSecureSuggestionSpans.put(ss, currentImi);
-                }
-            }
-        }
-    }
-
-    @Override
-    public boolean notifySuggestionPicked(SuggestionSpan span, String originalString, int index) {
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        synchronized (mMethodMap) {
-            final InputMethodInfo targetImi = mSecureSuggestionSpans.get(span);
-            // TODO: Do not send the intent if the process of the targetImi is already dead.
-            if (targetImi != null) {
-                final String[] suggestions = span.getSuggestions();
-                if (index < 0 || index >= suggestions.length) return false;
-                final String className = span.getNotificationTargetClassName();
-                final Intent intent = new Intent();
-                // Ensures that only a class in the original IME package will receive the
-                // notification.
-                intent.setClassName(targetImi.getPackageName(), className);
-                intent.setAction(SuggestionSpan.ACTION_SUGGESTION_PICKED);
-                intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE, originalString);
-                intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER, suggestions[index]);
-                intent.putExtra(SuggestionSpan.SUGGESTION_SPAN_PICKED_HASHCODE, span.hashCode());
-                final long ident = Binder.clearCallingIdentity();
-                try {
-                    mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
-                }
-                return true;
-            }
-        }
-        return false;
-    }
-
-    void updateFromSettingsLocked(boolean enabledMayChange) {
-        if (enabledMayChange) {
-            List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
-            for (int i=0; i<enabled.size(); i++) {
-                // We allow the user to select "disabled until used" apps, so if they
-                // are enabling one of those here we now need to make it enabled.
-                InputMethodInfo imm = enabled.get(i);
-                try {
-                    ApplicationInfo ai = mIPackageManager.getApplicationInfo(imm.getPackageName(),
-                            PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
-                            mSettings.getCurrentUserId());
-                    if (ai != null && ai.enabledSetting
-                            == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
-                        if (DEBUG) {
-                            Slog.d(TAG, "Update state(" + imm.getId()
-                                    + "): DISABLED_UNTIL_USED -> DEFAULT");
-                        }
-                        mIPackageManager.setApplicationEnabledSetting(imm.getPackageName(),
-                                PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
-                                PackageManager.DONT_KILL_APP, mSettings.getCurrentUserId(),
-                                mContext.getBasePackageName());
-                    }
-                } catch (RemoteException e) {
-                }
-            }
-        }
-        // We are assuming that whoever is changing DEFAULT_INPUT_METHOD and
-        // ENABLED_INPUT_METHODS is taking care of keeping them correctly in
-        // sync, so we will never have a DEFAULT_INPUT_METHOD that is not
-        // enabled.
-        String id = mSettings.getSelectedInputMethod();
-        // There is no input method selected, try to choose new applicable input method.
-        if (TextUtils.isEmpty(id) && chooseNewDefaultIMELocked()) {
-            id = mSettings.getSelectedInputMethod();
-        }
-        if (!TextUtils.isEmpty(id)) {
-            try {
-                setInputMethodLocked(id, mSettings.getSelectedInputMethodSubtypeId(id));
-            } catch (IllegalArgumentException e) {
-                Slog.w(TAG, "Unknown input method from prefs: " + id, e);
-                mCurMethodId = null;
-                unbindCurrentMethodLocked(true, false);
-            }
-            mShortcutInputMethodsAndSubtypes.clear();
-        } else {
-            // There is no longer an input method set, so stop any current one.
-            mCurMethodId = null;
-            unbindCurrentMethodLocked(true, false);
-        }
-    }
-
-    /* package */ void setInputMethodLocked(String id, int subtypeId) {
-        InputMethodInfo info = mMethodMap.get(id);
-        if (info == null) {
-            throw new IllegalArgumentException("Unknown id: " + id);
-        }
-
-        // See if we need to notify a subtype change within the same IME.
-        if (id.equals(mCurMethodId)) {
-            final int subtypeCount = info.getSubtypeCount();
-            if (subtypeCount <= 0) {
-                return;
-            }
-            final InputMethodSubtype oldSubtype = mCurrentSubtype;
-            final InputMethodSubtype newSubtype;
-            if (subtypeId >= 0 && subtypeId < subtypeCount) {
-                newSubtype = info.getSubtypeAt(subtypeId);
-            } else {
-                // If subtype is null, try to find the most applicable one from
-                // getCurrentInputMethodSubtype.
-                newSubtype = getCurrentInputMethodSubtypeLocked();
-            }
-            if (newSubtype == null || oldSubtype == null) {
-                Slog.w(TAG, "Illegal subtype state: old subtype = " + oldSubtype
-                        + ", new subtype = " + newSubtype);
-                return;
-            }
-            if (newSubtype != oldSubtype) {
-                setSelectedInputMethodAndSubtypeLocked(info, subtypeId, true);
-                if (mCurMethod != null) {
-                    try {
-                        refreshImeWindowVisibilityLocked();
-                        mCurMethod.changeInputMethodSubtype(newSubtype);
-                    } catch (RemoteException e) {
-                        Slog.w(TAG, "Failed to call changeInputMethodSubtype");
-                    }
-                }
-            }
-            return;
-        }
-
-        // Changing to a different IME.
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            // Set a subtype to this input method.
-            // subtypeId the name of a subtype which will be set.
-            setSelectedInputMethodAndSubtypeLocked(info, subtypeId, false);
-            // mCurMethodId should be updated after setSelectedInputMethodAndSubtypeLocked()
-            // because mCurMethodId is stored as a history in
-            // setSelectedInputMethodAndSubtypeLocked().
-            mCurMethodId = id;
-
-            if (ActivityManagerNative.isSystemReady()) {
-                Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
-                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-                intent.putExtra("input_method_id", id);
-                mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
-            }
-            unbindCurrentClientLocked();
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public boolean showSoftInput(IInputMethodClient client, int flags,
-            ResultReceiver resultReceiver) {
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        int uid = Binder.getCallingUid();
-        long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mMethodMap) {
-                if (mCurClient == null || client == null
-                        || mCurClient.client.asBinder() != client.asBinder()) {
-                    try {
-                        // We need to check if this is the current client with
-                        // focus in the window manager, to allow this call to
-                        // be made before input is started in it.
-                        if (!mIWindowManager.inputMethodClientHasFocus(client)) {
-                            Slog.w(TAG, "Ignoring showSoftInput of uid " + uid + ": " + client);
-                            return false;
-                        }
-                    } catch (RemoteException e) {
-                        return false;
-                    }
-                }
-
-                if (DEBUG) Slog.v(TAG, "Client requesting input be shown");
-                return showCurrentInputLocked(flags, resultReceiver);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    boolean showCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
-        mShowRequested = true;
-        if ((flags&InputMethodManager.SHOW_IMPLICIT) == 0) {
-            mShowExplicitlyRequested = true;
-        }
-        if ((flags&InputMethodManager.SHOW_FORCED) != 0) {
-            mShowExplicitlyRequested = true;
-            mShowForced = true;
-        }
-
-        if (!mSystemReady) {
-            return false;
-        }
-
-        boolean res = false;
-        if (mCurMethod != null) {
-            if (DEBUG) Slog.d(TAG, "showCurrentInputLocked: mCurToken=" + mCurToken);
-            executeOrSendMessage(mCurMethod, mCaller.obtainMessageIOO(
-                    MSG_SHOW_SOFT_INPUT, getImeShowFlags(), mCurMethod,
-                    resultReceiver));
-            mInputShown = true;
-            if (mHaveConnection && !mVisibleBound) {
-                bindCurrentInputMethodService(
-                        mCurIntent, mVisibleConnection, Context.BIND_AUTO_CREATE);
-                mVisibleBound = true;
-            }
-            res = true;
-        } else if (mHaveConnection && SystemClock.uptimeMillis()
-                >= (mLastBindTime+TIME_TO_RECONNECT)) {
-            // The client has asked to have the input method shown, but
-            // we have been sitting here too long with a connection to the
-            // service and no interface received, so let's disconnect/connect
-            // to try to prod things along.
-            EventLog.writeEvent(EventLogTags.IMF_FORCE_RECONNECT_IME, mCurMethodId,
-                    SystemClock.uptimeMillis()-mLastBindTime,1);
-            Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()");
-            mContext.unbindService(this);
-            bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
-                    | Context.BIND_NOT_VISIBLE);
-        } else {
-            if (DEBUG) {
-                Slog.d(TAG, "Can't show input: connection = " + mHaveConnection + ", time = "
-                        + ((mLastBindTime+TIME_TO_RECONNECT) - SystemClock.uptimeMillis()));
-            }
-        }
-
-        return res;
-    }
-
-    @Override
-    public boolean hideSoftInput(IInputMethodClient client, int flags,
-            ResultReceiver resultReceiver) {
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        int uid = Binder.getCallingUid();
-        long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mMethodMap) {
-                if (mCurClient == null || client == null
-                        || mCurClient.client.asBinder() != client.asBinder()) {
-                    try {
-                        // We need to check if this is the current client with
-                        // focus in the window manager, to allow this call to
-                        // be made before input is started in it.
-                        if (!mIWindowManager.inputMethodClientHasFocus(client)) {
-                            if (DEBUG) Slog.w(TAG, "Ignoring hideSoftInput of uid "
-                                    + uid + ": " + client);
-                            setImeWindowVisibilityStatusHiddenLocked();
-                            return false;
-                        }
-                    } catch (RemoteException e) {
-                        setImeWindowVisibilityStatusHiddenLocked();
-                        return false;
-                    }
-                }
-
-                if (DEBUG) Slog.v(TAG, "Client requesting input be hidden");
-                return hideCurrentInputLocked(flags, resultReceiver);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    boolean hideCurrentInputLocked(int flags, ResultReceiver resultReceiver) {
-        if ((flags&InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
-                && (mShowExplicitlyRequested || mShowForced)) {
-            if (DEBUG) Slog.v(TAG, "Not hiding: explicit show not cancelled by non-explicit hide");
-            return false;
-        }
-        if (mShowForced && (flags&InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
-            if (DEBUG) Slog.v(TAG, "Not hiding: forced show not cancelled by not-always hide");
-            return false;
-        }
-        boolean res;
-        if (mInputShown && mCurMethod != null) {
-            executeOrSendMessage(mCurMethod, mCaller.obtainMessageOO(
-                    MSG_HIDE_SOFT_INPUT, mCurMethod, resultReceiver));
-            res = true;
-        } else {
-            res = false;
-        }
-        if (mHaveConnection && mVisibleBound) {
-            mContext.unbindService(mVisibleConnection);
-            mVisibleBound = false;
-        }
-        mInputShown = false;
-        mShowRequested = false;
-        mShowExplicitlyRequested = false;
-        mShowForced = false;
-        return res;
-    }
-
-    @Override
-    public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken,
-            int controlFlags, int softInputMode, int windowFlags,
-            EditorInfo attribute, IInputContext inputContext) {
-        // Needs to check the validity before clearing calling identity
-        final boolean calledFromValidUser = calledFromValidUser();
-
-        InputBindResult res = null;
-        long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mMethodMap) {
-                if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
-                        + " controlFlags=#" + Integer.toHexString(controlFlags)
-                        + " softInputMode=#" + Integer.toHexString(softInputMode)
-                        + " windowFlags=#" + Integer.toHexString(windowFlags));
-
-                ClientState cs = mClients.get(client.asBinder());
-                if (cs == null) {
-                    throw new IllegalArgumentException("unknown client "
-                            + client.asBinder());
-                }
-
-                try {
-                    if (!mIWindowManager.inputMethodClientHasFocus(cs.client)) {
-                        // Check with the window manager to make sure this client actually
-                        // has a window with focus.  If not, reject.  This is thread safe
-                        // because if the focus changes some time before or after, the
-                        // next client receiving focus that has any interest in input will
-                        // be calling through here after that change happens.
-                        Slog.w(TAG, "Focus gain on non-focused client " + cs.client
-                                + " (uid=" + cs.uid + " pid=" + cs.pid + ")");
-                        return null;
-                    }
-                } catch (RemoteException e) {
-                }
-
-                if (!calledFromValidUser) {
-                    Slog.w(TAG, "A background user is requesting window. Hiding IME.");
-                    Slog.w(TAG, "If you want to interect with IME, you need "
-                            + "android.permission.INTERACT_ACROSS_USERS_FULL");
-                    hideCurrentInputLocked(0, null);
-                    return null;
-                }
-
-                if (mCurFocusedWindow == windowToken) {
-                    Slog.w(TAG, "Window already focused, ignoring focus gain of: " + client
-                            + " attribute=" + attribute + ", token = " + windowToken);
-                    if (attribute != null) {
-                        return startInputUncheckedLocked(cs, inputContext, attribute,
-                                controlFlags);
-                    }
-                    return null;
-                }
-                mCurFocusedWindow = windowToken;
-
-                // Should we auto-show the IME even if the caller has not
-                // specified what should be done with it?
-                // We only do this automatically if the window can resize
-                // to accommodate the IME (so what the user sees will give
-                // them good context without input information being obscured
-                // by the IME) or if running on a large screen where there
-                // is more room for the target window + IME.
-                final boolean doAutoShow =
-                        (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
-                                == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
-                        || mRes.getConfiguration().isLayoutSizeAtLeast(
-                                Configuration.SCREENLAYOUT_SIZE_LARGE);
-                final boolean isTextEditor =
-                        (controlFlags&InputMethodManager.CONTROL_WINDOW_IS_TEXT_EDITOR) != 0;
-
-                // We want to start input before showing the IME, but after closing
-                // it.  We want to do this after closing it to help the IME disappear
-                // more quickly (not get stuck behind it initializing itself for the
-                // new focused input, even if its window wants to hide the IME).
-                boolean didStart = false;
-                        
-                switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
-                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
-                        if (!isTextEditor || !doAutoShow) {
-                            if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
-                                // There is no focus view, and this window will
-                                // be behind any soft input window, so hide the
-                                // soft input window if it is shown.
-                                if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
-                                hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
-                            }
-                        } else if (isTextEditor && doAutoShow && (softInputMode &
-                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
-                            // There is a focus view, and we are navigating forward
-                            // into the window, so show the input window for the user.
-                            // We only do this automatically if the window can resize
-                            // to accommodate the IME (so what the user sees will give
-                            // them good context without input information being obscured
-                            // by the IME) or if running on a large screen where there
-                            // is more room for the target window + IME.
-                            if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
-                            if (attribute != null) {
-                                res = startInputUncheckedLocked(cs, inputContext, attribute,
-                                        controlFlags);
-                                didStart = true;
-                            }
-                            showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
-                        }
-                        break;
-                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
-                        // Do nothing.
-                        break;
-                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
-                        if ((softInputMode &
-                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
-                            if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
-                            hideCurrentInputLocked(0, null);
-                        }
-                        break;
-                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
-                        if (DEBUG) Slog.v(TAG, "Window asks to hide input");
-                        hideCurrentInputLocked(0, null);
-                        break;
-                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
-                        if ((softInputMode &
-                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
-                            if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
-                            if (attribute != null) {
-                                res = startInputUncheckedLocked(cs, inputContext, attribute,
-                                        controlFlags);
-                                didStart = true;
-                            }
-                            showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
-                        }
-                        break;
-                    case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
-                        if (DEBUG) Slog.v(TAG, "Window asks to always show input");
-                        if (attribute != null) {
-                            res = startInputUncheckedLocked(cs, inputContext, attribute,
-                                    controlFlags);
-                            didStart = true;
-                        }
-                        showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
-                        break;
-                }
-
-                if (!didStart && attribute != null) {
-                    res = startInputUncheckedLocked(cs, inputContext, attribute,
-                            controlFlags);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-
-        return res;
-    }
-
-    @Override
-    public void showInputMethodPickerFromClient(IInputMethodClient client) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            if (mCurClient == null || client == null
-                    || mCurClient.client.asBinder() != client.asBinder()) {
-                Slog.w(TAG, "Ignoring showInputMethodPickerFromClient of uid "
-                        + Binder.getCallingUid() + ": " + client);
-            }
-
-            // Always call subtype picker, because subtype picker is a superset of input method
-            // picker.
-            mHandler.sendEmptyMessage(MSG_SHOW_IM_SUBTYPE_PICKER);
-        }
-    }
-
-    @Override
-    public void setInputMethod(IBinder token, String id) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        setInputMethodWithSubtypeId(token, id, NOT_A_SUBTYPE_ID);
-    }
-
-    @Override
-    public void setInputMethodAndSubtype(IBinder token, String id, InputMethodSubtype subtype) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            if (subtype != null) {
-                setInputMethodWithSubtypeId(token, id, InputMethodUtils.getSubtypeIdFromHashCode(
-                        mMethodMap.get(id), subtype.hashCode()));
-            } else {
-                setInputMethod(token, id);
-            }
-        }
-    }
-
-    @Override
-    public void showInputMethodAndSubtypeEnablerFromClient(
-            IInputMethodClient client, String inputMethodId) {
-        if (!calledFromValidUser()) {
-            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));
-        }
-    }
-
-    @Override
-    public boolean switchToLastInputMethod(IBinder token) {
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        synchronized (mMethodMap) {
-            final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
-            final InputMethodInfo lastImi;
-            if (lastIme != null) {
-                lastImi = mMethodMap.get(lastIme.first);
-            } else {
-                lastImi = null;
-            }
-            String targetLastImiId = null;
-            int subtypeId = NOT_A_SUBTYPE_ID;
-            if (lastIme != null && lastImi != null) {
-                final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
-                final int lastSubtypeHash = Integer.valueOf(lastIme.second);
-                final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
-                        : mCurrentSubtype.hashCode();
-                // If the last IME is the same as the current IME and the last subtype is not
-                // defined, there is no need to switch to the last IME.
-                if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
-                    targetLastImiId = lastIme.first;
-                    subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
-                }
-            }
-
-            if (TextUtils.isEmpty(targetLastImiId)
-                    && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
-                // This is a safety net. If the currentSubtype can't be added to the history
-                // and the framework couldn't find the last ime, we will make the last ime be
-                // the most applicable enabled keyboard subtype of the system imes.
-                final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
-                if (enabled != null) {
-                    final int N = enabled.size();
-                    final String locale = mCurrentSubtype == null
-                            ? mRes.getConfiguration().locale.toString()
-                            : mCurrentSubtype.getLocale();
-                    for (int i = 0; i < N; ++i) {
-                        final InputMethodInfo imi = enabled.get(i);
-                        if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
-                            InputMethodSubtype keyboardSubtype =
-                                    InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes,
-                                            InputMethodUtils.getSubtypes(imi),
-                                            InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
-                            if (keyboardSubtype != null) {
-                                targetLastImiId = imi.getId();
-                                subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
-                                        imi, keyboardSubtype.hashCode());
-                                if(keyboardSubtype.getLocale().equals(locale)) {
-                                    break;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-            if (!TextUtils.isEmpty(targetLastImiId)) {
-                if (DEBUG) {
-                    Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second
-                            + ", from: " + mCurMethodId + ", " + subtypeId);
-                }
-                setInputMethodWithSubtypeId(token, targetLastImiId, subtypeId);
-                return true;
-            } else {
-                return false;
-            }
-        }
-    }
-
-    @Override
-    public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        synchronized (mMethodMap) {
-            final ImeSubtypeListItem nextSubtype = mImListManager.getNextInputMethod(
-                    onlyCurrentIme, mMethodMap.get(mCurMethodId), mCurrentSubtype);
-            if (nextSubtype == null) {
-                return false;
-            }
-            setInputMethodWithSubtypeId(token, nextSubtype.mImi.getId(), nextSubtype.mSubtypeId);
-            return true;
-        }
-    }
-
-    @Override
-    public boolean shouldOfferSwitchingToNextInputMethod(IBinder token) {
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        synchronized (mMethodMap) {
-            final ImeSubtypeListItem nextSubtype = mImListManager.getNextInputMethod(
-                    false /* onlyCurrentIme */, mMethodMap.get(mCurMethodId), mCurrentSubtype);
-            if (nextSubtype == null) {
-                return false;
-            }
-            return true;
-        }
-    }
-
-    @Override
-    public InputMethodSubtype getLastInputMethodSubtype() {
-        if (!calledFromValidUser()) {
-            return null;
-        }
-        synchronized (mMethodMap) {
-            final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
-            // TODO: Handle the case of the last IME with no subtypes
-            if (lastIme == null || TextUtils.isEmpty(lastIme.first)
-                    || TextUtils.isEmpty(lastIme.second)) return null;
-            final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
-            if (lastImi == null) return null;
-            try {
-                final int lastSubtypeHash = Integer.valueOf(lastIme.second);
-                final int lastSubtypeId =
-                        InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
-                if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
-                    return null;
-                }
-                return lastImi.getSubtypeAt(lastSubtypeId);
-            } catch (NumberFormatException e) {
-                return null;
-            }
-        }
-    }
-
-    @Override
-    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        // By this IPC call, only a process which shares the same uid with the IME can add
-        // additional input method subtypes to the IME.
-        if (TextUtils.isEmpty(imiId) || subtypes == null || subtypes.length == 0) return;
-        synchronized (mMethodMap) {
-            final InputMethodInfo imi = mMethodMap.get(imiId);
-            if (imi == null) return;
-            final String[] packageInfos;
-            try {
-                packageInfos = mIPackageManager.getPackagesForUid(Binder.getCallingUid());
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Failed to get package infos");
-                return;
-            }
-            if (packageInfos != null) {
-                final int packageNum = packageInfos.length;
-                for (int i = 0; i < packageNum; ++i) {
-                    if (packageInfos[i].equals(imi.getPackageName())) {
-                        mFileManager.addInputMethodSubtypes(imi, subtypes);
-                        final long ident = Binder.clearCallingIdentity();
-                        try {
-                            buildInputMethodListLocked(mMethodList, mMethodMap,
-                                    false /* resetDefaultEnabledIme */);
-                        } finally {
-                            Binder.restoreCallingIdentity(ident);
-                        }
-                        return;
-                    }
-                }
-            }
-        }
-        return;
-    }
-
-    private void setInputMethodWithSubtypeId(IBinder token, String id, int subtypeId) {
-        synchronized (mMethodMap) {
-            if (token == null) {
-                if (mContext.checkCallingOrSelfPermission(
-                        android.Manifest.permission.WRITE_SECURE_SETTINGS)
-                        != PackageManager.PERMISSION_GRANTED) {
-                    throw new SecurityException(
-                            "Using null token requires permission "
-                            + android.Manifest.permission.WRITE_SECURE_SETTINGS);
-                }
-            } else if (mCurToken != token) {
-                Slog.w(TAG, "Ignoring setInputMethod of uid " + Binder.getCallingUid()
-                        + " token: " + token);
-                return;
-            }
-
-            final long ident = Binder.clearCallingIdentity();
-            try {
-                setInputMethodLocked(id, subtypeId);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public void hideMySoftInput(IBinder token, int flags) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            if (token == null || mCurToken != token) {
-                if (DEBUG) Slog.w(TAG, "Ignoring hideInputMethod of uid "
-                        + Binder.getCallingUid() + " token: " + token);
-                return;
-            }
-            long ident = Binder.clearCallingIdentity();
-            try {
-                hideCurrentInputLocked(flags, null);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public void showMySoftInput(IBinder token, int flags) {
-        if (!calledFromValidUser()) {
-            return;
-        }
-        synchronized (mMethodMap) {
-            if (token == null || mCurToken != token) {
-                Slog.w(TAG, "Ignoring showMySoftInput of uid "
-                        + Binder.getCallingUid() + " token: " + token);
-                return;
-            }
-            long ident = Binder.clearCallingIdentity();
-            try {
-                showCurrentInputLocked(flags, null);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    void setEnabledSessionInMainThread(SessionState session) {
-        if (mEnabledSession != session) {
-            if (mEnabledSession != null) {
-                try {
-                    if (DEBUG) Slog.v(TAG, "Disabling: " + mEnabledSession);
-                    mEnabledSession.method.setSessionEnabled(
-                            mEnabledSession.session, false);
-                } catch (RemoteException e) {
-                }
-            }
-            mEnabledSession = session;
-            try {
-                if (DEBUG) Slog.v(TAG, "Enabling: " + mEnabledSession);
-                session.method.setSessionEnabled(
-                        session.session, true);
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    @Override
-    public boolean handleMessage(Message msg) {
-        SomeArgs args;
-        switch (msg.what) {
-            case MSG_SHOW_IM_PICKER:
-                showInputMethodMenu();
-                return true;
-
-            case MSG_SHOW_IM_SUBTYPE_PICKER:
-                showInputMethodSubtypeMenu();
-                return true;
-
-            case MSG_SHOW_IM_SUBTYPE_ENABLER:
-                args = (SomeArgs)msg.obj;
-                showInputMethodAndSubtypeEnabler((String)args.arg1);
-                args.recycle();
-                return true;
-
-            case MSG_SHOW_IM_CONFIG:
-                showConfigureInputMethods();
-                return true;
-
-            // ---------------------------------------------------------
-
-            case MSG_UNBIND_INPUT:
-                try {
-                    ((IInputMethod)msg.obj).unbindInput();
-                } catch (RemoteException e) {
-                    // There is nothing interesting about the method dying.
-                }
-                return true;
-            case MSG_BIND_INPUT:
-                args = (SomeArgs)msg.obj;
-                try {
-                    ((IInputMethod)args.arg1).bindInput((InputBinding)args.arg2);
-                } catch (RemoteException e) {
-                }
-                args.recycle();
-                return true;
-            case MSG_SHOW_SOFT_INPUT:
-                args = (SomeArgs)msg.obj;
-                try {
-                    if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput("
-                            + msg.arg1 + ", " + args.arg2 + ")");
-                    ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2);
-                } catch (RemoteException e) {
-                }
-                args.recycle();
-                return true;
-            case MSG_HIDE_SOFT_INPUT:
-                args = (SomeArgs)msg.obj;
-                try {
-                    if (DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, "
-                            + args.arg2 + ")");
-                    ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2);
-                } catch (RemoteException e) {
-                }
-                args.recycle();
-                return true;
-            case MSG_ATTACH_TOKEN:
-                args = (SomeArgs)msg.obj;
-                try {
-                    if (DEBUG) Slog.v(TAG, "Sending attach of token: " + args.arg2);
-                    ((IInputMethod)args.arg1).attachToken((IBinder)args.arg2);
-                } catch (RemoteException e) {
-                }
-                args.recycle();
-                return true;
-            case MSG_CREATE_SESSION: {
-                args = (SomeArgs)msg.obj;
-                IInputMethod method = (IInputMethod)args.arg1;
-                InputChannel channel = (InputChannel)args.arg2;
-                try {
-                    method.createSession(channel, (IInputSessionCallback)args.arg3);
-                } catch (RemoteException e) {
-                } finally {
-                    // Dispose the channel if the input method is not local to this process
-                    // because the remote proxy will get its own copy when unparceled.
-                    if (channel != null && Binder.isProxy(method)) {
-                        channel.dispose();
-                    }
-                }
-                args.recycle();
-                return true;
-            }
-            // ---------------------------------------------------------
-
-            case MSG_START_INPUT:
-                args = (SomeArgs)msg.obj;
-                try {
-                    SessionState session = (SessionState)args.arg1;
-                    setEnabledSessionInMainThread(session);
-                    session.method.startInput((IInputContext)args.arg2,
-                            (EditorInfo)args.arg3);
-                } catch (RemoteException e) {
-                }
-                args.recycle();
-                return true;
-            case MSG_RESTART_INPUT:
-                args = (SomeArgs)msg.obj;
-                try {
-                    SessionState session = (SessionState)args.arg1;
-                    setEnabledSessionInMainThread(session);
-                    session.method.restartInput((IInputContext)args.arg2,
-                            (EditorInfo)args.arg3);
-                } catch (RemoteException e) {
-                }
-                args.recycle();
-                return true;
-
-            // ---------------------------------------------------------
-
-            case MSG_UNBIND_METHOD:
-                try {
-                    ((IInputMethodClient)msg.obj).onUnbindMethod(msg.arg1);
-                } catch (RemoteException e) {
-                    // There is nothing interesting about the last client dying.
-                }
-                return true;
-            case MSG_BIND_METHOD: {
-                args = (SomeArgs)msg.obj;
-                IInputMethodClient client = (IInputMethodClient)args.arg1;
-                InputBindResult res = (InputBindResult)args.arg2;
-                try {
-                    client.onBindMethod(res);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Client died receiving input method " + args.arg2);
-                } finally {
-                    // Dispose the channel if the input method is not local to this process
-                    // because the remote proxy will get its own copy when unparceled.
-                    if (res.channel != null && Binder.isProxy(client)) {
-                        res.channel.dispose();
-                    }
-                }
-                args.recycle();
-                return true;
-            }
-            case MSG_SET_ACTIVE:
-                try {
-                    ((ClientState)msg.obj).client.setActive(msg.arg1 != 0);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
-                            + ((ClientState)msg.obj).pid + " uid "
-                            + ((ClientState)msg.obj).uid);
-                }
-                return true;
-
-            // --------------------------------------------------------------
-            case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
-                mHardKeyboardListener.handleHardKeyboardStatusChange(
-                        msg.arg1 == 1, msg.arg2 == 1);
-                return true;
-        }
-        return false;
-    }
-
-    private boolean chooseNewDefaultIMELocked() {
-        final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
-                mSettings.getEnabledInputMethodListLocked());
-        if (imi != null) {
-            if (DEBUG) {
-                Slog.d(TAG, "New default IME was selected: " + imi.getId());
-            }
-            resetSelectedInputMethodAndSubtypeLocked(imi.getId());
-            return true;
-        }
-
-        return false;
-    }
-
-    void buildInputMethodListLocked(ArrayList<InputMethodInfo> list,
-            HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
-        if (DEBUG) {
-            Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme
-                    + " \n ------ \n" + InputMethodUtils.getStackTrace());
-        }
-        list.clear();
-        map.clear();
-
-        // Use for queryIntentServicesAsUser
-        final PackageManager pm = mContext.getPackageManager();
-        String disabledSysImes = mSettings.getDisabledSystemInputMethods();
-        if (disabledSysImes == null) disabledSysImes = "";
-
-        final List<ResolveInfo> services = pm.queryIntentServicesAsUser(
-                new Intent(InputMethod.SERVICE_INTERFACE),
-                PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS,
-                mSettings.getCurrentUserId());
-
-        final HashMap<String, List<InputMethodSubtype>> additionalSubtypes =
-                mFileManager.getAllAdditionalInputMethodSubtypes();
-        for (int i = 0; i < services.size(); ++i) {
-            ResolveInfo ri = services.get(i);
-            ServiceInfo si = ri.serviceInfo;
-            ComponentName compName = new ComponentName(si.packageName, si.name);
-            if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(
-                    si.permission)) {
-                Slog.w(TAG, "Skipping input method " + compName
-                        + ": it does not require the permission "
-                        + android.Manifest.permission.BIND_INPUT_METHOD);
-                continue;
-            }
-
-            if (DEBUG) Slog.d(TAG, "Checking " + compName);
-
-            try {
-                InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
-                list.add(p);
-                final String id = p.getId();
-                map.put(id, p);
-
-                if (DEBUG) {
-                    Slog.d(TAG, "Found an input method " + p);
-                }
-
-            } catch (XmlPullParserException e) {
-                Slog.w(TAG, "Unable to load input method " + compName, e);
-            } catch (IOException e) {
-                Slog.w(TAG, "Unable to load input method " + compName, e);
-            }
-        }
-
-        if (resetDefaultEnabledIme) {
-            final ArrayList<InputMethodInfo> defaultEnabledIme =
-                    InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
-            for (int i = 0; i < defaultEnabledIme.size(); ++i) {
-                final InputMethodInfo imi =  defaultEnabledIme.get(i);
-                if (DEBUG) {
-                    Slog.d(TAG, "--- enable ime = " + imi);
-                }
-                setInputMethodEnabledLocked(imi.getId(), true);
-            }
-        }
-
-        final String defaultImiId = mSettings.getSelectedInputMethod();
-        if (!TextUtils.isEmpty(defaultImiId)) {
-            if (!map.containsKey(defaultImiId)) {
-                Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
-                if (chooseNewDefaultIMELocked()) {
-                    updateFromSettingsLocked(true);
-                }
-            } else {
-                // Double check that the default IME is certainly enabled.
-                setInputMethodEnabledLocked(defaultImiId, true);
-            }
-        }
-    }
-
-    // ----------------------------------------------------------------------
-
-    private void showInputMethodMenu() {
-        showInputMethodMenuInternal(false);
-    }
-
-    private void showInputMethodSubtypeMenu() {
-        showInputMethodMenuInternal(true);
-    }
-
-    private void showInputMethodAndSubtypeEnabler(String inputMethodId) {
-        Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
-                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        if (!TextUtils.isEmpty(inputMethodId)) {
-            intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId);
-        }
-        mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
-    }
-
-    private void showConfigureInputMethods() {
-        Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
-                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-        mContext.startActivityAsUser(intent, null, UserHandle.CURRENT);
-    }
-
-    private boolean isScreenLocked() {
-        return mKeyguardManager != null
-                && mKeyguardManager.isKeyguardLocked() && mKeyguardManager.isKeyguardSecure();
-    }
-    private void showInputMethodMenuInternal(boolean showSubtypes) {
-        if (DEBUG) Slog.v(TAG, "Show switching menu");
-
-        final Context context = mContext;
-        final boolean isScreenLocked = isScreenLocked();
-
-        final String lastInputMethodId = mSettings.getSelectedInputMethod();
-        int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
-        if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);
-
-        synchronized (mMethodMap) {
-            final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
-                    getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
-            if (immis == null || immis.size() == 0) {
-                return;
-            }
-
-            hideInputMethodMenuLocked();
-
-            final List<ImeSubtypeListItem> imList =
-                    mImListManager.getSortedInputMethodAndSubtypeList(
-                            showSubtypes, mInputShown, isScreenLocked);
-
-            if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
-                final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
-                if (currentSubtype != null) {
-                    final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
-                    lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
-                            currentImi, currentSubtype.hashCode());
-                }
-            }
-
-            final int N = imList.size();
-            mIms = new InputMethodInfo[N];
-            mSubtypeIds = new int[N];
-            int checkedItem = 0;
-            for (int i = 0; i < N; ++i) {
-                final ImeSubtypeListItem item = imList.get(i);
-                mIms[i] = item.mImi;
-                mSubtypeIds[i] = item.mSubtypeId;
-                if (mIms[i].getId().equals(lastInputMethodId)) {
-                    int subtypeId = mSubtypeIds[i];
-                    if ((subtypeId == NOT_A_SUBTYPE_ID)
-                            || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
-                            || (subtypeId == lastInputMethodSubtypeId)) {
-                        checkedItem = i;
-                    }
-                }
-            }
-            final TypedArray a = context.obtainStyledAttributes(null,
-                    com.android.internal.R.styleable.DialogPreference,
-                    com.android.internal.R.attr.alertDialogStyle, 0);
-            mDialogBuilder = new AlertDialog.Builder(context)
-                    .setOnCancelListener(new OnCancelListener() {
-                        @Override
-                        public void onCancel(DialogInterface dialog) {
-                            hideInputMethodMenu();
-                        }
-                    })
-                    .setIcon(a.getDrawable(
-                            com.android.internal.R.styleable.DialogPreference_dialogTitle));
-            a.recycle();
-            final LayoutInflater inflater =
-                    (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-            final View tv = inflater.inflate(
-                    com.android.internal.R.layout.input_method_switch_dialog_title, null);
-            mDialogBuilder.setCustomTitle(tv);
-
-            // Setup layout for a toggle switch of the hardware keyboard
-            mSwitchingDialogTitleView = tv;
-            mSwitchingDialogTitleView.findViewById(
-                    com.android.internal.R.id.hard_keyboard_section).setVisibility(
-                            mWindowManagerService.isHardKeyboardAvailable() ?
-                                    View.VISIBLE : View.GONE);
-            final Switch hardKeySwitch =  ((Switch)mSwitchingDialogTitleView.findViewById(
-                    com.android.internal.R.id.hard_keyboard_switch));
-            hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
-            hardKeySwitch.setOnCheckedChangeListener(
-                    new OnCheckedChangeListener() {
-                        @Override
-                        public void onCheckedChanged(
-                                CompoundButton buttonView, boolean isChecked) {
-                            mWindowManagerService.setHardKeyboardEnabled(isChecked);
-                            // Ensure that the input method dialog is dismissed when changing
-                            // the hardware keyboard state.
-                            hideInputMethodMenu();
-                        }
-                    });
-
-            final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context,
-                    com.android.internal.R.layout.simple_list_item_2_single_choice, imList,
-                    checkedItem);
-
-            mDialogBuilder.setSingleChoiceItems(adapter, checkedItem,
-                    new AlertDialog.OnClickListener() {
-                        @Override
-                        public void onClick(DialogInterface dialog, int which) {
-                            synchronized (mMethodMap) {
-                                if (mIms == null || mIms.length <= which
-                                        || mSubtypeIds == null || mSubtypeIds.length <= which) {
-                                    return;
-                                }
-                                InputMethodInfo im = mIms[which];
-                                int subtypeId = mSubtypeIds[which];
-                                adapter.mCheckedItem = which;
-                                adapter.notifyDataSetChanged();
-                                hideInputMethodMenu();
-                                if (im != null) {
-                                    if ((subtypeId < 0)
-                                            || (subtypeId >= im.getSubtypeCount())) {
-                                        subtypeId = NOT_A_SUBTYPE_ID;
-                                    }
-                                    setInputMethodLocked(im.getId(), subtypeId);
-                                }
-                            }
-                        }
-                    });
-
-            if (showSubtypes && !isScreenLocked) {
-                mDialogBuilder.setPositiveButton(
-                        com.android.internal.R.string.configure_input_methods,
-                        new DialogInterface.OnClickListener() {
-                            @Override
-                            public void onClick(DialogInterface dialog, int whichButton) {
-                                showConfigureInputMethods();
-                            }
-                        });
-            }
-            mSwitchingDialog = mDialogBuilder.create();
-            mSwitchingDialog.setCanceledOnTouchOutside(true);
-            mSwitchingDialog.getWindow().setType(
-                    WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
-            mSwitchingDialog.getWindow().getAttributes().privateFlags |=
-                    WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
-            mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
-            mSwitchingDialog.show();
-        }
-    }
-
-    private static class ImeSubtypeListItem implements Comparable<ImeSubtypeListItem> {
-        public final CharSequence mImeName;
-        public final CharSequence mSubtypeName;
-        public final InputMethodInfo mImi;
-        public final int mSubtypeId;
-        private final boolean mIsSystemLocale;
-        private final boolean mIsSystemLanguage;
-
-        public ImeSubtypeListItem(CharSequence imeName, CharSequence subtypeName,
-                InputMethodInfo imi, int subtypeId, String subtypeLocale, String systemLocale) {
-            mImeName = imeName;
-            mSubtypeName = subtypeName;
-            mImi = imi;
-            mSubtypeId = subtypeId;
-            if (TextUtils.isEmpty(subtypeLocale)) {
-                mIsSystemLocale = false;
-                mIsSystemLanguage = false;
-            } else {
-                mIsSystemLocale = subtypeLocale.equals(systemLocale);
-                mIsSystemLanguage = mIsSystemLocale
-                        || subtypeLocale.startsWith(systemLocale.substring(0, 2));
-            }
-        }
-
-        @Override
-        public int compareTo(ImeSubtypeListItem other) {
-            if (TextUtils.isEmpty(mImeName)) {
-                return 1;
-            }
-            if (TextUtils.isEmpty(other.mImeName)) {
-                return -1;
-            }
-            if (!TextUtils.equals(mImeName, other.mImeName)) {
-                return mImeName.toString().compareTo(other.mImeName.toString());
-            }
-            if (TextUtils.equals(mSubtypeName, other.mSubtypeName)) {
-                return 0;
-            }
-            if (mIsSystemLocale) {
-                return -1;
-            }
-            if (other.mIsSystemLocale) {
-                return 1;
-            }
-            if (mIsSystemLanguage) {
-                return -1;
-            }
-            if (other.mIsSystemLanguage) {
-                return 1;
-            }
-            if (TextUtils.isEmpty(mSubtypeName)) {
-                return 1;
-            }
-            if (TextUtils.isEmpty(other.mSubtypeName)) {
-                return -1;
-            }
-            return mSubtypeName.toString().compareTo(other.mSubtypeName.toString());
-        }
-    }
-
-    private static class ImeSubtypeListAdapter extends ArrayAdapter<ImeSubtypeListItem> {
-        private final LayoutInflater mInflater;
-        private final int mTextViewResourceId;
-        private final List<ImeSubtypeListItem> mItemsList;
-        public int mCheckedItem;
-        public ImeSubtypeListAdapter(Context context, int textViewResourceId,
-                List<ImeSubtypeListItem> itemsList, int checkedItem) {
-            super(context, textViewResourceId, itemsList);
-            mTextViewResourceId = textViewResourceId;
-            mItemsList = itemsList;
-            mCheckedItem = checkedItem;
-            mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-        }
-
-        @Override
-        public View getView(int position, View convertView, ViewGroup parent) {
-            final View view = convertView != null ? convertView
-                    : mInflater.inflate(mTextViewResourceId, null);
-            if (position < 0 || position >= mItemsList.size()) return view;
-            final ImeSubtypeListItem item = mItemsList.get(position);
-            final CharSequence imeName = item.mImeName;
-            final CharSequence subtypeName = item.mSubtypeName;
-            final TextView firstTextView = (TextView)view.findViewById(android.R.id.text1);
-            final TextView secondTextView = (TextView)view.findViewById(android.R.id.text2);
-            if (TextUtils.isEmpty(subtypeName)) {
-                firstTextView.setText(imeName);
-                secondTextView.setVisibility(View.GONE);
-            } else {
-                firstTextView.setText(subtypeName);
-                secondTextView.setText(imeName);
-                secondTextView.setVisibility(View.VISIBLE);
-            }
-            final RadioButton radioButton =
-                    (RadioButton)view.findViewById(com.android.internal.R.id.radio);
-            radioButton.setChecked(position == mCheckedItem);
-            return view;
-        }
-    }
-
-    void hideInputMethodMenu() {
-        synchronized (mMethodMap) {
-            hideInputMethodMenuLocked();
-        }
-    }
-
-    void hideInputMethodMenuLocked() {
-        if (DEBUG) Slog.v(TAG, "Hide switching menu");
-
-        if (mSwitchingDialog != null) {
-            mSwitchingDialog.dismiss();
-            mSwitchingDialog = null;
-        }
-
-        mDialogBuilder = null;
-        mIms = null;
-    }
-
-    // ----------------------------------------------------------------------
-
-    @Override
-    public boolean setInputMethodEnabled(String id, boolean enabled) {
-        // TODO: Make this work even for non-current users?
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        synchronized (mMethodMap) {
-            if (mContext.checkCallingOrSelfPermission(
-                    android.Manifest.permission.WRITE_SECURE_SETTINGS)
-                    != PackageManager.PERMISSION_GRANTED) {
-                throw new SecurityException(
-                        "Requires permission "
-                        + android.Manifest.permission.WRITE_SECURE_SETTINGS);
-            }
-            
-            long ident = Binder.clearCallingIdentity();
-            try {
-                return setInputMethodEnabledLocked(id, enabled);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    boolean setInputMethodEnabledLocked(String id, boolean enabled) {
-        // Make sure this is a valid input method.
-        InputMethodInfo imm = mMethodMap.get(id);
-        if (imm == null) {
-            throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
-        }
-
-        List<Pair<String, ArrayList<String>>> enabledInputMethodsList = mSettings
-                .getEnabledInputMethodsAndSubtypeListLocked();
-
-        if (enabled) {
-            for (Pair<String, ArrayList<String>> pair: enabledInputMethodsList) {
-                if (pair.first.equals(id)) {
-                    // We are enabling this input method, but it is already enabled.
-                    // Nothing to do. The previous state was enabled.
-                    return true;
-                }
-            }
-            mSettings.appendAndPutEnabledInputMethodLocked(id, false);
-            // Previous state was disabled.
-            return false;
-        } else {
-            StringBuilder builder = new StringBuilder();
-            if (mSettings.buildAndPutEnabledInputMethodsStrRemovingIdLocked(
-                    builder, enabledInputMethodsList, id)) {
-                // Disabled input method is currently selected, switch to another one.
-                final String selId = mSettings.getSelectedInputMethod();
-                if (id.equals(selId) && !chooseNewDefaultIMELocked()) {
-                    Slog.i(TAG, "Can't find new IME, unsetting the current input method.");
-                    resetSelectedInputMethodAndSubtypeLocked("");
-                }
-                // Previous state was enabled.
-                return true;
-            } else {
-                // We are disabling the input method but it is already disabled.
-                // Nothing to do.  The previous state was disabled.
-                return false;
-            }
-        }
-    }
-
-    private void setSelectedInputMethodAndSubtypeLocked(InputMethodInfo imi, int subtypeId,
-            boolean setSubtypeOnly) {
-        // Update the history of InputMethod and Subtype
-        mSettings.saveCurrentInputMethodAndSubtypeToHistory(mCurMethodId, mCurrentSubtype);
-
-        // Set Subtype here
-        if (imi == null || subtypeId < 0) {
-            mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
-            mCurrentSubtype = null;
-        } else {
-            if (subtypeId < imi.getSubtypeCount()) {
-                InputMethodSubtype subtype = imi.getSubtypeAt(subtypeId);
-                mSettings.putSelectedSubtype(subtype.hashCode());
-                mCurrentSubtype = subtype;
-            } else {
-                mSettings.putSelectedSubtype(NOT_A_SUBTYPE_ID);
-                // If the subtype is not specified, choose the most applicable one
-                mCurrentSubtype = getCurrentInputMethodSubtypeLocked();
-            }
-        }
-
-        // Workaround.
-        // ASEC is not ready in the IMMS constructor. Accordingly, forward-locked
-        // IMEs are not recognized and considered uninstalled.
-        // Actually, we can't move everything after SystemReady because
-        // IMMS needs to run in the encryption lock screen. So, we just skip changing
-        // the default IME here and try cheking the default IME again in systemReady().
-        // TODO: Do nothing before system ready and implement a separated logic for
-        // the encryption lock screen.
-        // TODO: ASEC should be ready before IMMS is instantiated.
-        if (mSystemReady && !setSubtypeOnly) {
-            // Set InputMethod here
-            mSettings.putSelectedInputMethod(imi != null ? imi.getId() : "");
-        }
-    }
-
-    private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
-        InputMethodInfo imi = mMethodMap.get(newDefaultIme);
-        int lastSubtypeId = NOT_A_SUBTYPE_ID;
-        // newDefaultIme is empty when there is no candidate for the selected IME.
-        if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
-            String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
-            if (subtypeHashCode != null) {
-                try {
-                    lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
-                            imi, Integer.valueOf(subtypeHashCode));
-                } catch (NumberFormatException e) {
-                    Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
-                }
-            }
-        }
-        setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
-    }
-
-    // If there are no selected shortcuts, tries finding the most applicable ones.
-    private Pair<InputMethodInfo, InputMethodSubtype>
-            findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
-        List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
-        InputMethodInfo mostApplicableIMI = null;
-        InputMethodSubtype mostApplicableSubtype = null;
-        boolean foundInSystemIME = false;
-
-        // Search applicable subtype for each InputMethodInfo
-        for (InputMethodInfo imi: imis) {
-            final String imiId = imi.getId();
-            if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
-                continue;
-            }
-            InputMethodSubtype subtype = null;
-            final List<InputMethodSubtype> enabledSubtypes =
-                    mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
-            // 1. Search by the current subtype's locale from enabledSubtypes.
-            if (mCurrentSubtype != null) {
-                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
-                        mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
-            }
-            // 2. Search by the system locale from enabledSubtypes.
-            // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
-            if (subtype == null) {
-                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
-                        mRes, enabledSubtypes, mode, null, true);
-            }
-            final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
-                    InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
-            final ArrayList<InputMethodSubtype> subtypesForSearch =
-                    overridingImplicitlyEnabledSubtypes.isEmpty()
-                            ? InputMethodUtils.getSubtypes(imi)
-                            : overridingImplicitlyEnabledSubtypes;
-            // 4. Search by the current subtype's locale from all subtypes.
-            if (subtype == null && mCurrentSubtype != null) {
-                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
-                        mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
-            }
-            // 5. Search by the system locale from all subtypes.
-            // 6. Search the first enabled subtype matched with mode from all subtypes.
-            if (subtype == null) {
-                subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
-                        mRes, subtypesForSearch, mode, null, true);
-            }
-            if (subtype != null) {
-                if (imiId.equals(mCurMethodId)) {
-                    // The current input method is the most applicable IME.
-                    mostApplicableIMI = imi;
-                    mostApplicableSubtype = subtype;
-                    break;
-                } else if (!foundInSystemIME) {
-                    // The system input method is 2nd applicable IME.
-                    mostApplicableIMI = imi;
-                    mostApplicableSubtype = subtype;
-                    if ((imi.getServiceInfo().applicationInfo.flags
-                            & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                        foundInSystemIME = true;
-                    }
-                }
-            }
-        }
-        if (DEBUG) {
-            if (mostApplicableIMI != null) {
-                Slog.w(TAG, "Most applicable shortcut input method was:"
-                        + mostApplicableIMI.getId());
-                if (mostApplicableSubtype != null) {
-                    Slog.w(TAG, "Most applicable shortcut input method subtype was:"
-                            + "," + mostApplicableSubtype.getMode() + ","
-                            + mostApplicableSubtype.getLocale());
-                }
-            }
-        }
-        if (mostApplicableIMI != null) {
-            return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI,
-                    mostApplicableSubtype);
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * @return Return the current subtype of this input method.
-     */
-    @Override
-    public InputMethodSubtype getCurrentInputMethodSubtype() {
-        // TODO: Make this work even for non-current users?
-        if (!calledFromValidUser()) {
-            return null;
-        }
-        synchronized (mMethodMap) {
-            return getCurrentInputMethodSubtypeLocked();
-        }
-    }
-
-    private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
-        if (mCurMethodId == null) {
-            return null;
-        }
-        final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
-        final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
-        if (imi == null || imi.getSubtypeCount() == 0) {
-            return null;
-        }
-        if (!subtypeIsSelected || mCurrentSubtype == null
-                || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
-            int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
-            if (subtypeId == NOT_A_SUBTYPE_ID) {
-                // If there are no selected subtypes, the framework will try to find
-                // the most applicable subtype from explicitly or implicitly enabled
-                // subtypes.
-                List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes =
-                        mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
-                // If there is only one explicitly or implicitly enabled subtype,
-                // just returns it.
-                if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
-                    mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
-                } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
-                    mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
-                            mRes, explicitlyOrImplicitlyEnabledSubtypes,
-                            InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
-                    if (mCurrentSubtype == null) {
-                        mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
-                                mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null,
-                                true);
-                    }
-                }
-            } else {
-                mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
-            }
-        }
-        return mCurrentSubtype;
-    }
-
-    private void addShortcutInputMethodAndSubtypes(InputMethodInfo imi,
-            InputMethodSubtype subtype) {
-        if (mShortcutInputMethodsAndSubtypes.containsKey(imi)) {
-            mShortcutInputMethodsAndSubtypes.get(imi).add(subtype);
-        } else {
-            ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
-            subtypes.add(subtype);
-            mShortcutInputMethodsAndSubtypes.put(imi, subtypes);
-        }
-    }
-
-    // TODO: We should change the return type from List to List<Parcelable>
-    @SuppressWarnings("rawtypes")
-    @Override
-    public List getShortcutInputMethodsAndSubtypes() {
-        synchronized (mMethodMap) {
-            ArrayList<Object> ret = new ArrayList<Object>();
-            if (mShortcutInputMethodsAndSubtypes.size() == 0) {
-                // If there are no selected shortcut subtypes, the framework will try to find
-                // the most applicable subtype from all subtypes whose mode is
-                // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode.
-                Pair<InputMethodInfo, InputMethodSubtype> info =
-                    findLastResortApplicableShortcutInputMethodAndSubtypeLocked(
-                            InputMethodUtils.SUBTYPE_MODE_VOICE);
-                if (info != null) {
-                    ret.add(info.first);
-                    ret.add(info.second);
-                }
-                return ret;
-            }
-            for (InputMethodInfo imi: mShortcutInputMethodsAndSubtypes.keySet()) {
-                ret.add(imi);
-                for (InputMethodSubtype subtype: mShortcutInputMethodsAndSubtypes.get(imi)) {
-                    ret.add(subtype);
-                }
-            }
-            return ret;
-        }
-    }
-
-    @Override
-    public boolean setCurrentInputMethodSubtype(InputMethodSubtype subtype) {
-        // TODO: Make this work even for non-current users?
-        if (!calledFromValidUser()) {
-            return false;
-        }
-        synchronized (mMethodMap) {
-            if (subtype != null && mCurMethodId != null) {
-                InputMethodInfo imi = mMethodMap.get(mCurMethodId);
-                int subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode());
-                if (subtypeId != NOT_A_SUBTYPE_ID) {
-                    setInputMethodLocked(mCurMethodId, subtypeId);
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    private static class InputMethodAndSubtypeListManager {
-        private final Context mContext;
-        // Used to load label
-        private final PackageManager mPm;
-        private final InputMethodManagerService mImms;
-        private final String mSystemLocaleStr;
-        public InputMethodAndSubtypeListManager(Context context, InputMethodManagerService imms) {
-            mContext = context;
-            mPm = context.getPackageManager();
-            mImms = imms;
-            final Locale locale = context.getResources().getConfiguration().locale;
-            mSystemLocaleStr = locale != null ? locale.toString() : "";
-        }
-
-        private final TreeMap<InputMethodInfo, List<InputMethodSubtype>> mSortedImmis =
-                new TreeMap<InputMethodInfo, List<InputMethodSubtype>>(
-                        new Comparator<InputMethodInfo>() {
-                            @Override
-                            public int compare(InputMethodInfo imi1, InputMethodInfo imi2) {
-                                if (imi2 == null) return 0;
-                                if (imi1 == null) return 1;
-                                if (mPm == null) {
-                                    return imi1.getId().compareTo(imi2.getId());
-                                }
-                                CharSequence imiId1 = imi1.loadLabel(mPm) + "/" + imi1.getId();
-                                CharSequence imiId2 = imi2.loadLabel(mPm) + "/" + imi2.getId();
-                                return imiId1.toString().compareTo(imiId2.toString());
-                            }
-                        });
-
-        public ImeSubtypeListItem getNextInputMethod(
-                boolean onlyCurrentIme, InputMethodInfo imi, InputMethodSubtype subtype) {
-            if (imi == null) {
-                return null;
-            }
-            final List<ImeSubtypeListItem> imList = getSortedInputMethodAndSubtypeList();
-            if (imList.size() <= 1) {
-                return null;
-            }
-            final int N = imList.size();
-            final int currentSubtypeId = subtype != null
-                    ? InputMethodUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode())
-                    : NOT_A_SUBTYPE_ID;
-            for (int i = 0; i < N; ++i) {
-                final ImeSubtypeListItem isli = imList.get(i);
-                if (isli.mImi.equals(imi) && isli.mSubtypeId == currentSubtypeId) {
-                    if (!onlyCurrentIme) {
-                        return imList.get((i + 1) % N);
-                    }
-                    for (int j = 0; j < N - 1; ++j) {
-                        final ImeSubtypeListItem candidate = imList.get((i + j + 1) % N);
-                        if (candidate.mImi.equals(imi)) {
-                            return candidate;
-                        }
-                    }
-                    return null;
-                }
-            }
-            return null;
-        }
-
-        public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList() {
-            return getSortedInputMethodAndSubtypeList(true, false, false);
-        }
-
-        public List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(boolean showSubtypes,
-                boolean inputShown, boolean isScreenLocked) {
-            final ArrayList<ImeSubtypeListItem> imList = new ArrayList<ImeSubtypeListItem>();
-            final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis =
-                    mImms.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
-            if (immis == null || immis.size() == 0) {
-                return Collections.emptyList();
-            }
-            mSortedImmis.clear();
-            mSortedImmis.putAll(immis);
-            for (InputMethodInfo imi : mSortedImmis.keySet()) {
-                if (imi == null) continue;
-                List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypeList = immis.get(imi);
-                HashSet<String> enabledSubtypeSet = new HashSet<String>();
-                for (InputMethodSubtype subtype: explicitlyOrImplicitlyEnabledSubtypeList) {
-                    enabledSubtypeSet.add(String.valueOf(subtype.hashCode()));
-                }
-                final CharSequence imeLabel = imi.loadLabel(mPm);
-                if (showSubtypes && enabledSubtypeSet.size() > 0) {
-                    final int subtypeCount = imi.getSubtypeCount();
-                    if (DEBUG) {
-                        Slog.v(TAG, "Add subtypes: " + subtypeCount + ", " + imi.getId());
-                    }
-                    for (int j = 0; j < subtypeCount; ++j) {
-                        final InputMethodSubtype subtype = imi.getSubtypeAt(j);
-                        final String subtypeHashCode = String.valueOf(subtype.hashCode());
-                        // We show all enabled IMEs and subtypes when an IME is shown.
-                        if (enabledSubtypeSet.contains(subtypeHashCode)
-                                && ((inputShown && !isScreenLocked) || !subtype.isAuxiliary())) {
-                            final CharSequence subtypeLabel =
-                                    subtype.overridesImplicitlyEnabledSubtype() ? null
-                                            : subtype.getDisplayName(mContext, imi.getPackageName(),
-                                                    imi.getServiceInfo().applicationInfo);
-                            imList.add(new ImeSubtypeListItem(imeLabel, subtypeLabel, imi, j,
-                                    subtype.getLocale(), mSystemLocaleStr));
-
-                            // Removing this subtype from enabledSubtypeSet because we no longer
-                            // need to add an entry of this subtype to imList to avoid duplicated
-                            // entries.
-                            enabledSubtypeSet.remove(subtypeHashCode);
-                        }
-                    }
-                } else {
-                    imList.add(new ImeSubtypeListItem(imeLabel, null, imi, NOT_A_SUBTYPE_ID,
-                            null, mSystemLocaleStr));
-                }
-            }
-            Collections.sort(imList);
-            return imList;
-        }
-    }
-
-    // TODO: Cache the state for each user and reset when the cached user is removed.
-    private static class InputMethodFileManager {
-        private static final String SYSTEM_PATH = "system";
-        private static final String INPUT_METHOD_PATH = "inputmethod";
-        private static final String ADDITIONAL_SUBTYPES_FILE_NAME = "subtypes.xml";
-        private static final String NODE_SUBTYPES = "subtypes";
-        private static final String NODE_SUBTYPE = "subtype";
-        private static final String NODE_IMI = "imi";
-        private static final String ATTR_ID = "id";
-        private static final String ATTR_LABEL = "label";
-        private static final String ATTR_ICON = "icon";
-        private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
-        private static final String ATTR_IME_SUBTYPE_MODE = "imeSubtypeMode";
-        private static final String ATTR_IME_SUBTYPE_EXTRA_VALUE = "imeSubtypeExtraValue";
-        private static final String ATTR_IS_AUXILIARY = "isAuxiliary";
-        private final AtomicFile mAdditionalInputMethodSubtypeFile;
-        private final HashMap<String, InputMethodInfo> mMethodMap;
-        private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap =
-                new HashMap<String, List<InputMethodSubtype>>();
-        public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) {
-            if (methodMap == null) {
-                throw new NullPointerException("methodMap is null");
-            }
-            mMethodMap = methodMap;
-            final File systemDir = userId == UserHandle.USER_OWNER
-                    ? new File(Environment.getDataDirectory(), SYSTEM_PATH)
-                    : Environment.getUserSystemDirectory(userId);
-            final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH);
-            if (!inputMethodDir.mkdirs()) {
-                Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath());
-            }
-            final File subtypeFile = new File(inputMethodDir, ADDITIONAL_SUBTYPES_FILE_NAME);
-            mAdditionalInputMethodSubtypeFile = new AtomicFile(subtypeFile);
-            if (!subtypeFile.exists()) {
-                // If "subtypes.xml" doesn't exist, create a blank file.
-                writeAdditionalInputMethodSubtypes(
-                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, methodMap);
-            } else {
-                readAdditionalInputMethodSubtypes(
-                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile);
-            }
-        }
-
-        private void deleteAllInputMethodSubtypes(String imiId) {
-            synchronized (mMethodMap) {
-                mAdditionalSubtypesMap.remove(imiId);
-                writeAdditionalInputMethodSubtypes(
-                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
-            }
-        }
-
-        public void addInputMethodSubtypes(
-                InputMethodInfo imi, InputMethodSubtype[] additionalSubtypes) {
-            synchronized (mMethodMap) {
-                final ArrayList<InputMethodSubtype> subtypes = new ArrayList<InputMethodSubtype>();
-                final int N = additionalSubtypes.length;
-                for (int i = 0; i < N; ++i) {
-                    final InputMethodSubtype subtype = additionalSubtypes[i];
-                    if (!subtypes.contains(subtype)) {
-                        subtypes.add(subtype);
-                    } else {
-                        Slog.w(TAG, "Duplicated subtype definition found: "
-                                + subtype.getLocale() + ", " + subtype.getMode());
-                    }
-                }
-                mAdditionalSubtypesMap.put(imi.getId(), subtypes);
-                writeAdditionalInputMethodSubtypes(
-                        mAdditionalSubtypesMap, mAdditionalInputMethodSubtypeFile, mMethodMap);
-            }
-        }
-
-        public HashMap<String, List<InputMethodSubtype>> getAllAdditionalInputMethodSubtypes() {
-            synchronized (mMethodMap) {
-                return mAdditionalSubtypesMap;
-            }
-        }
-
-        private static void writeAdditionalInputMethodSubtypes(
-                HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile,
-                HashMap<String, InputMethodInfo> methodMap) {
-            // Safety net for the case that this function is called before methodMap is set.
-            final boolean isSetMethodMap = methodMap != null && methodMap.size() > 0;
-            FileOutputStream fos = null;
-            try {
-                fos = subtypesFile.startWrite();
-                final XmlSerializer out = new FastXmlSerializer();
-                out.setOutput(fos, "utf-8");
-                out.startDocument(null, true);
-                out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-                out.startTag(null, NODE_SUBTYPES);
-                for (String imiId : allSubtypes.keySet()) {
-                    if (isSetMethodMap && !methodMap.containsKey(imiId)) {
-                        Slog.w(TAG, "IME uninstalled or not valid.: " + imiId);
-                        continue;
-                    }
-                    out.startTag(null, NODE_IMI);
-                    out.attribute(null, ATTR_ID, imiId);
-                    final List<InputMethodSubtype> subtypesList = allSubtypes.get(imiId);
-                    final int N = subtypesList.size();
-                    for (int i = 0; i < N; ++i) {
-                        final InputMethodSubtype subtype = subtypesList.get(i);
-                        out.startTag(null, NODE_SUBTYPE);
-                        out.attribute(null, ATTR_ICON, String.valueOf(subtype.getIconResId()));
-                        out.attribute(null, ATTR_LABEL, String.valueOf(subtype.getNameResId()));
-                        out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
-                        out.attribute(null, ATTR_IME_SUBTYPE_MODE, subtype.getMode());
-                        out.attribute(null, ATTR_IME_SUBTYPE_EXTRA_VALUE, subtype.getExtraValue());
-                        out.attribute(null, ATTR_IS_AUXILIARY,
-                                String.valueOf(subtype.isAuxiliary() ? 1 : 0));
-                        out.endTag(null, NODE_SUBTYPE);
-                    }
-                    out.endTag(null, NODE_IMI);
-                }
-                out.endTag(null, NODE_SUBTYPES);
-                out.endDocument();
-                subtypesFile.finishWrite(fos);
-            } catch (java.io.IOException e) {
-                Slog.w(TAG, "Error writing subtypes", e);
-                if (fos != null) {
-                    subtypesFile.failWrite(fos);
-                }
-            }
-        }
-
-        private static void readAdditionalInputMethodSubtypes(
-                HashMap<String, List<InputMethodSubtype>> allSubtypes, AtomicFile subtypesFile) {
-            if (allSubtypes == null || subtypesFile == null) return;
-            allSubtypes.clear();
-            FileInputStream fis = null;
-            try {
-                fis = subtypesFile.openRead();
-                final XmlPullParser parser = Xml.newPullParser();
-                parser.setInput(fis, null);
-                int type = parser.getEventType();
-                // Skip parsing until START_TAG
-                while ((type = parser.next()) != XmlPullParser.START_TAG
-                        && type != XmlPullParser.END_DOCUMENT) {}
-                String firstNodeName = parser.getName();
-                if (!NODE_SUBTYPES.equals(firstNodeName)) {
-                    throw new XmlPullParserException("Xml doesn't start with subtypes");
-                }
-                final int depth =parser.getDepth();
-                String currentImiId = null;
-                ArrayList<InputMethodSubtype> tempSubtypesArray = null;
-                while (((type = parser.next()) != XmlPullParser.END_TAG
-                        || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
-                    if (type != XmlPullParser.START_TAG)
-                        continue;
-                    final String nodeName = parser.getName();
-                    if (NODE_IMI.equals(nodeName)) {
-                        currentImiId = parser.getAttributeValue(null, ATTR_ID);
-                        if (TextUtils.isEmpty(currentImiId)) {
-                            Slog.w(TAG, "Invalid imi id found in subtypes.xml");
-                            continue;
-                        }
-                        tempSubtypesArray = new ArrayList<InputMethodSubtype>();
-                        allSubtypes.put(currentImiId, tempSubtypesArray);
-                    } else if (NODE_SUBTYPE.equals(nodeName)) {
-                        if (TextUtils.isEmpty(currentImiId) || tempSubtypesArray == null) {
-                            Slog.w(TAG, "IME uninstalled or not valid.: " + currentImiId);
-                            continue;
-                        }
-                        final int icon = Integer.valueOf(
-                                parser.getAttributeValue(null, ATTR_ICON));
-                        final int label = Integer.valueOf(
-                                parser.getAttributeValue(null, ATTR_LABEL));
-                        final String imeSubtypeLocale =
-                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
-                        final String imeSubtypeMode =
-                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_MODE);
-                        final String imeSubtypeExtraValue =
-                                parser.getAttributeValue(null, ATTR_IME_SUBTYPE_EXTRA_VALUE);
-                        final boolean isAuxiliary = "1".equals(String.valueOf(
-                                parser.getAttributeValue(null, ATTR_IS_AUXILIARY)));
-                        final InputMethodSubtype subtype =
-                                new InputMethodSubtype(label, icon, imeSubtypeLocale,
-                                        imeSubtypeMode, imeSubtypeExtraValue, isAuxiliary);
-                        tempSubtypesArray.add(subtype);
-                    }
-                }
-            } catch (XmlPullParserException e) {
-                Slog.w(TAG, "Error reading subtypes: " + e);
-                return;
-            } catch (java.io.IOException e) {
-                Slog.w(TAG, "Error reading subtypes: " + e);
-                return;
-            } catch (NumberFormatException e) {
-                Slog.w(TAG, "Error reading subtypes: " + e);
-                return;
-            } finally {
-                if (fis != null) {
-                    try {
-                        fis.close();
-                    } catch (java.io.IOException e1) {
-                        Slog.w(TAG, "Failed to close.");
-                    }
-                }
-            }
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-
-            pw.println("Permission Denial: can't dump InputMethodManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        IInputMethod method;
-        ClientState client;
-
-        final Printer p = new PrintWriterPrinter(pw);
-
-        synchronized (mMethodMap) {
-            p.println("Current Input Method Manager state:");
-            int N = mMethodList.size();
-            p.println("  Input Methods:");
-            for (int i=0; i<N; i++) {
-                InputMethodInfo info = mMethodList.get(i);
-                p.println("  InputMethod #" + i + ":");
-                info.dump(p, "    ");
-            }
-            p.println("  Clients:");
-            for (ClientState ci : mClients.values()) {
-                p.println("  Client " + ci + ":");
-                p.println("    client=" + ci.client);
-                p.println("    inputContext=" + ci.inputContext);
-                p.println("    sessionRequested=" + ci.sessionRequested);
-                p.println("    curSession=" + ci.curSession);
-            }
-            p.println("  mCurMethodId=" + mCurMethodId);
-            client = mCurClient;
-            p.println("  mCurClient=" + client + " mCurSeq=" + mCurSeq);
-            p.println("  mCurFocusedWindow=" + mCurFocusedWindow);
-            p.println("  mCurId=" + mCurId + " mHaveConnect=" + mHaveConnection
-                    + " mBoundToMethod=" + mBoundToMethod);
-            p.println("  mCurToken=" + mCurToken);
-            p.println("  mCurIntent=" + mCurIntent);
-            method = mCurMethod;
-            p.println("  mCurMethod=" + mCurMethod);
-            p.println("  mEnabledSession=" + mEnabledSession);
-            p.println("  mShowRequested=" + mShowRequested
-                    + " mShowExplicitlyRequested=" + mShowExplicitlyRequested
-                    + " mShowForced=" + mShowForced
-                    + " mInputShown=" + mInputShown);
-            p.println("  mSystemReady=" + mSystemReady + " mScreenOn=" + mScreenOn);
-        }
-
-        p.println(" ");
-        if (client != null) {
-            pw.flush();
-            try {
-                client.client.asBinder().dump(fd, args);
-            } catch (RemoteException e) {
-                p.println("Input method client dead: " + e);
-            }
-        } else {
-            p.println("No input method client.");
-        }
-
-        p.println(" ");
-        if (method != null) {
-            pw.flush();
-            try {
-                method.asBinder().dump(fd, args);
-            } catch (RemoteException e) {
-                p.println("Input method service dead: " + e);
-            }
-        } else {
-            p.println("No input method service.");
-        }
-    }
-}
diff --git a/services/java/com/android/server/IoThread.java b/services/java/com/android/server/IoThread.java
deleted file mode 100644
index 09f2af7..0000000
--- a/services/java/com/android/server/IoThread.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (C) 2013 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;
-
-import android.os.Handler;
-import android.os.HandlerThread;
-
-/**
- * Shared singleton I/O thread for the system.  This is a thread for non-background
- * service operations that can potential block briefly on network IO operations
- * (not waiting for data itself, but communicating with network daemons).
- */
-public final class IoThread extends HandlerThread {
-    private static IoThread sInstance;
-    private static Handler sHandler;
-
-    private IoThread() {
-        super("android.io", android.os.Process.THREAD_PRIORITY_DEFAULT);
-    }
-
-    private static void ensureThreadLocked() {
-        if (sInstance == null) {
-            sInstance = new IoThread();
-            sInstance.start();
-            sHandler = new Handler(sInstance.getLooper());
-            sHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    android.os.Process.setCanSelfBackground(false);
-                }
-            });
-        }
-    }
-
-    public static IoThread get() {
-        synchronized (IoThread.class) {
-            ensureThreadLocked();
-            return sInstance;
-        }
-    }
-
-    public static Handler getHandler() {
-        synchronized (IoThread.class) {
-            ensureThreadLocked();
-            return sHandler;
-        }
-    }
-}
diff --git a/services/java/com/android/server/LightsService.java b/services/java/com/android/server/LightsService.java
deleted file mode 100644
index 89bfcac..0000000
--- a/services/java/com/android/server/LightsService.java
+++ /dev/null
@@ -1,213 +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.server;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.os.Handler;
-import android.os.IHardwareService;
-import android.os.ServiceManager;
-import android.os.Message;
-import android.util.Slog;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-
-public class LightsService {
-    private static final String TAG = "LightsService";
-    private static final boolean DEBUG = false;
-
-    public static final int LIGHT_ID_BACKLIGHT = 0;
-    public static final int LIGHT_ID_KEYBOARD = 1;
-    public static final int LIGHT_ID_BUTTONS = 2;
-    public static final int LIGHT_ID_BATTERY = 3;
-    public static final int LIGHT_ID_NOTIFICATIONS = 4;
-    public static final int LIGHT_ID_ATTENTION = 5;
-    public static final int LIGHT_ID_BLUETOOTH = 6;
-    public static final int LIGHT_ID_WIFI = 7;
-    public static final int LIGHT_ID_COUNT = 8;
-
-    public static final int LIGHT_FLASH_NONE = 0;
-    public static final int LIGHT_FLASH_TIMED = 1;
-    public static final int LIGHT_FLASH_HARDWARE = 2;
-
-    /**
-     * Light brightness is managed by a user setting.
-     */
-    public static final int BRIGHTNESS_MODE_USER = 0;
-
-    /**
-     * Light brightness is managed by a light sensor.
-     */
-    public static final int BRIGHTNESS_MODE_SENSOR = 1;
-
-    private final Light mLights[] = new Light[LIGHT_ID_COUNT];
-
-    public final class Light {
-
-        private Light(int id) {
-            mId = id;
-        }
-
-        public void setBrightness(int brightness) {
-            setBrightness(brightness, BRIGHTNESS_MODE_USER);
-        }
-
-        public void setBrightness(int brightness, int brightnessMode) {
-            synchronized (this) {
-                int color = brightness & 0x000000ff;
-                color = 0xff000000 | (color << 16) | (color << 8) | color;
-                setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, brightnessMode);
-            }
-        }
-
-        public void setColor(int color) {
-            synchronized (this) {
-                setLightLocked(color, LIGHT_FLASH_NONE, 0, 0, 0);
-            }
-        }
-
-        public void setFlashing(int color, int mode, int onMS, int offMS) {
-            synchronized (this) {
-                setLightLocked(color, mode, onMS, offMS, BRIGHTNESS_MODE_USER);
-            }
-        }
-
-
-        public void pulse() {
-            pulse(0x00ffffff, 7);
-        }
-
-        public void pulse(int color, int onMS) {
-            synchronized (this) {
-                if (mColor == 0 && !mFlashing) {
-                    setLightLocked(color, LIGHT_FLASH_HARDWARE, onMS, 1000, BRIGHTNESS_MODE_USER);
-                    mH.sendMessageDelayed(Message.obtain(mH, 1, this), onMS);
-                }
-            }
-        }
-
-        public void turnOff() {
-            synchronized (this) {
-                setLightLocked(0, LIGHT_FLASH_NONE, 0, 0, 0);
-            }
-        }
-
-        private void stopFlashing() {
-            synchronized (this) {
-                setLightLocked(mColor, LIGHT_FLASH_NONE, 0, 0, BRIGHTNESS_MODE_USER);
-            }
-        }
-
-        private void setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) {
-            if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) {
-                if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#"
-                        + Integer.toHexString(color));
-                mColor = color;
-                mMode = mode;
-                mOnMS = onMS;
-                mOffMS = offMS;
-                setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode);
-            }
-        }
-
-        private int mId;
-        private int mColor;
-        private int mMode;
-        private int mOnMS;
-        private int mOffMS;
-        private boolean mFlashing;
-    }
-
-    /* This class implements an obsolete API that was removed after eclair and re-added during the
-     * final moments of the froyo release to support flashlight apps that had been using the private
-     * IHardwareService API. This is expected to go away in the next release.
-     */
-    private final IHardwareService.Stub mLegacyFlashlightHack = new IHardwareService.Stub() {
-
-        private static final String FLASHLIGHT_FILE = "/sys/class/leds/spotlight/brightness";
-
-        public boolean getFlashlightEnabled() {
-            try {
-                FileInputStream fis = new FileInputStream(FLASHLIGHT_FILE);
-                int result = fis.read();
-                fis.close();
-                return (result != '0');
-            } catch (Exception e) {
-                return false;
-            }
-        }
-
-        public void setFlashlightEnabled(boolean on) {
-            if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.FLASHLIGHT)
-                    != PackageManager.PERMISSION_GRANTED &&
-                    mContext.checkCallingOrSelfPermission(android.Manifest.permission.HARDWARE_TEST)
-                    != PackageManager.PERMISSION_GRANTED) {
-                throw new SecurityException("Requires FLASHLIGHT or HARDWARE_TEST permission");
-            }
-            try {
-                FileOutputStream fos = new FileOutputStream(FLASHLIGHT_FILE);
-                byte[] bytes = new byte[2];
-                bytes[0] = (byte)(on ? '1' : '0');
-                bytes[1] = '\n';
-                fos.write(bytes);
-                fos.close();
-            } catch (Exception e) {
-                // fail silently
-            }
-        }
-    };
-
-    LightsService(Context context) {
-
-        mNativePointer = init_native();
-        mContext = context;
-
-        ServiceManager.addService("hardware", mLegacyFlashlightHack);
-
-        for (int i = 0; i < LIGHT_ID_COUNT; i++) {
-            mLights[i] = new Light(i);
-        }
-    }
-
-    protected void finalize() throws Throwable {
-        finalize_native(mNativePointer);
-        super.finalize();
-    }
-
-    public Light getLight(int id) {
-        return mLights[id];
-    }
-
-    private Handler mH = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            Light light = (Light)msg.obj;
-            light.stopFlashing();
-        }
-    };
-
-    private static native int init_native();
-    private static native void finalize_native(int ptr);
-
-    private static native void setLight_native(int ptr, int light, int color, int mode,
-            int onMS, int offMS, int brightnessMode);
-
-    private final Context mContext;
-
-    private int mNativePointer;
-}
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
deleted file mode 100644
index e60231a..0000000
--- a/services/java/com/android/server/MountService.java
+++ /dev/null
@@ -1,2833 +0,0 @@
-/*
- * Copyright (C) 2007 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;
-
-import static android.content.pm.PackageManager.PERMISSION_GRANTED;
-
-import android.Manifest;
-import android.app.AppOpsManager;
-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.UserInfo;
-import android.content.res.ObbInfo;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
-import android.hardware.usb.UsbManager;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Environment;
-import android.os.Environment.UserEnvironment;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.os.storage.IMountService;
-import android.os.storage.IMountServiceListener;
-import android.os.storage.IMountShutdownObserver;
-import android.os.storage.IObbActionListener;
-import android.os.storage.OnObbStateChangeListener;
-import android.os.storage.StorageResultCode;
-import android.os.storage.StorageVolume;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-import android.util.Slog;
-import android.util.Xml;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.app.IMediaContainerService;
-import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.Preconditions;
-import com.android.internal.util.XmlUtils;
-import com.android.server.NativeDaemonConnector.Command;
-import com.android.server.NativeDaemonConnector.SensitiveArg;
-import com.android.server.am.ActivityManagerService;
-import com.android.server.pm.PackageManagerService;
-import com.android.server.pm.UserManagerService;
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.math.BigInteger;
-import java.security.NoSuchAlgorithmException;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.crypto.SecretKey;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.PBEKeySpec;
-
-/**
- * MountService implements back-end services for platform storage
- * management.
- * @hide - Applications should use android.os.storage.StorageManager
- * to access the MountService.
- */
-class MountService extends IMountService.Stub
-        implements INativeDaemonConnectorCallbacks, Watchdog.Monitor {
-
-    // TODO: listen for user creation/deletion
-
-    private static final boolean LOCAL_LOGD = false;
-    private static final boolean DEBUG_UNMOUNT = false;
-    private static final boolean DEBUG_EVENTS = false;
-    private static final boolean DEBUG_OBB = false;
-
-    // Disable this since it messes up long-running cryptfs operations.
-    private static final boolean WATCHDOG_ENABLE = false;
-
-    private static final String TAG = "MountService";
-
-    private static final String VOLD_TAG = "VoldConnector";
-
-    /** Maximum number of ASEC containers allowed to be mounted. */
-    private static final int MAX_CONTAINERS = 250;
-
-    /*
-     * Internal vold volume state constants
-     */
-    class VolumeState {
-        public static final int Init       = -1;
-        public static final int NoMedia    = 0;
-        public static final int Idle       = 1;
-        public static final int Pending    = 2;
-        public static final int Checking   = 3;
-        public static final int Mounted    = 4;
-        public static final int Unmounting = 5;
-        public static final int Formatting = 6;
-        public static final int Shared     = 7;
-        public static final int SharedMnt  = 8;
-    }
-
-    /*
-     * Internal vold response code constants
-     */
-    class VoldResponseCode {
-        /*
-         * 100 series - Requestion action was initiated; expect another reply
-         *              before proceeding with a new command.
-         */
-        public static final int VolumeListResult               = 110;
-        public static final int AsecListResult                 = 111;
-        public static final int StorageUsersListResult         = 112;
-
-        /*
-         * 200 series - Requestion action has been successfully completed.
-         */
-        public static final int ShareStatusResult              = 210;
-        public static final int AsecPathResult                 = 211;
-        public static final int ShareEnabledResult             = 212;
-
-        /*
-         * 400 series - Command was accepted, but the requested action
-         *              did not take place.
-         */
-        public static final int OpFailedNoMedia                = 401;
-        public static final int OpFailedMediaBlank             = 402;
-        public static final int OpFailedMediaCorrupt           = 403;
-        public static final int OpFailedVolNotMounted          = 404;
-        public static final int OpFailedStorageBusy            = 405;
-        public static final int OpFailedStorageNotFound        = 406;
-
-        /*
-         * 600 series - Unsolicited broadcasts.
-         */
-        public static final int VolumeStateChange              = 605;
-        public static final int VolumeUuidChange               = 613;
-        public static final int VolumeUserLabelChange          = 614;
-        public static final int VolumeDiskInserted             = 630;
-        public static final int VolumeDiskRemoved              = 631;
-        public static final int VolumeBadRemoval               = 632;
-
-        /*
-         * 700 series - fstrim
-         */
-        public static final int FstrimCompleted                = 700;
-    }
-
-    private Context mContext;
-    private NativeDaemonConnector mConnector;
-
-    private final Object mVolumesLock = new Object();
-
-    /** When defined, base template for user-specific {@link StorageVolume}. */
-    private StorageVolume mEmulatedTemplate;
-
-    // TODO: separate storage volumes on per-user basis
-
-    @GuardedBy("mVolumesLock")
-    private final ArrayList<StorageVolume> mVolumes = Lists.newArrayList();
-    /** Map from path to {@link StorageVolume} */
-    @GuardedBy("mVolumesLock")
-    private final HashMap<String, StorageVolume> mVolumesByPath = Maps.newHashMap();
-    /** Map from path to state */
-    @GuardedBy("mVolumesLock")
-    private final HashMap<String, String> mVolumeStates = Maps.newHashMap();
-
-    private volatile boolean mSystemReady = false;
-
-    private PackageManagerService                 mPms;
-    private boolean                               mUmsEnabling;
-    private boolean                               mUmsAvailable = false;
-    // Used as a lock for methods that register/unregister listeners.
-    final private ArrayList<MountServiceBinderListener> mListeners =
-            new ArrayList<MountServiceBinderListener>();
-    private final CountDownLatch mConnectedSignal = new CountDownLatch(1);
-    private final CountDownLatch mAsecsScanned = new CountDownLatch(1);
-    private boolean                               mSendUmsConnectedOnBoot = false;
-
-    /**
-     * Private hash of currently mounted secure containers.
-     * Used as a lock in methods to manipulate secure containers.
-     */
-    final private HashSet<String> mAsecMountSet = new HashSet<String>();
-
-    /**
-     * The size of the crypto algorithm key in bits for OBB files. Currently
-     * Twofish is used which takes 128-bit keys.
-     */
-    private static final int CRYPTO_ALGORITHM_KEY_SIZE = 128;
-
-    /**
-     * The number of times to run SHA1 in the PBKDF2 function for OBB files.
-     * 1024 is reasonably secure and not too slow.
-     */
-    private static final int PBKDF2_HASH_ROUNDS = 1024;
-
-    /**
-     * Mounted OBB tracking information. Used to track the current state of all
-     * OBBs.
-     */
-    final private Map<IBinder, List<ObbState>> mObbMounts = new HashMap<IBinder, List<ObbState>>();
-
-    /** Map from raw paths to {@link ObbState}. */
-    final private Map<String, ObbState> mObbPathToStateMap = new HashMap<String, ObbState>();
-
-    class ObbState implements IBinder.DeathRecipient {
-        public ObbState(String rawPath, String canonicalPath, int callingUid,
-                IObbActionListener token, int nonce) {
-            this.rawPath = rawPath;
-            this.canonicalPath = canonicalPath.toString();
-
-            final int userId = UserHandle.getUserId(callingUid);
-            this.ownerPath = buildObbPath(canonicalPath, userId, false);
-            this.voldPath = buildObbPath(canonicalPath, userId, true);
-
-            this.ownerGid = UserHandle.getSharedAppGid(callingUid);
-            this.token = token;
-            this.nonce = nonce;
-        }
-
-        final String rawPath;
-        final String canonicalPath;
-        final String ownerPath;
-        final String voldPath;
-
-        final int ownerGid;
-
-        // Token of remote Binder caller
-        final IObbActionListener token;
-
-        // Identifier to pass back to the token
-        final int nonce;
-
-        public IBinder getBinder() {
-            return token.asBinder();
-        }
-
-        @Override
-        public void binderDied() {
-            ObbAction action = new UnmountObbAction(this, true);
-            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));
-        }
-
-        public void link() throws RemoteException {
-            getBinder().linkToDeath(this, 0);
-        }
-
-        public void unlink() {
-            getBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder("ObbState{");
-            sb.append("rawPath=").append(rawPath);
-            sb.append(",canonicalPath=").append(canonicalPath);
-            sb.append(",ownerPath=").append(ownerPath);
-            sb.append(",voldPath=").append(voldPath);
-            sb.append(",ownerGid=").append(ownerGid);
-            sb.append(",token=").append(token);
-            sb.append(",binder=").append(getBinder());
-            sb.append('}');
-            return sb.toString();
-        }
-    }
-
-    // OBB Action Handler
-    final private ObbActionHandler mObbActionHandler;
-
-    // OBB action handler messages
-    private static final int OBB_RUN_ACTION = 1;
-    private static final int OBB_MCS_BOUND = 2;
-    private static final int OBB_MCS_UNBIND = 3;
-    private static final int OBB_MCS_RECONNECT = 4;
-    private static final int OBB_FLUSH_MOUNT_STATE = 5;
-
-    /*
-     * Default Container Service information
-     */
-    static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
-            "com.android.defcontainer", "com.android.defcontainer.DefaultContainerService");
-
-    final private DefaultContainerConnection mDefContainerConn = new DefaultContainerConnection();
-
-    class DefaultContainerConnection implements ServiceConnection {
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            if (DEBUG_OBB)
-                Slog.i(TAG, "onServiceConnected");
-            IMediaContainerService imcs = IMediaContainerService.Stub.asInterface(service);
-            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_MCS_BOUND, imcs));
-        }
-
-        public void onServiceDisconnected(ComponentName name) {
-            if (DEBUG_OBB)
-                Slog.i(TAG, "onServiceDisconnected");
-        }
-    };
-
-    // Used in the ObbActionHandler
-    private IMediaContainerService mContainerService = null;
-
-    // Handler messages
-    private static final int H_UNMOUNT_PM_UPDATE = 1;
-    private static final int H_UNMOUNT_PM_DONE = 2;
-    private static final int H_UNMOUNT_MS = 3;
-    private static final int H_SYSTEM_READY = 4;
-
-    private static final int RETRY_UNMOUNT_DELAY = 30; // in ms
-    private static final int MAX_UNMOUNT_RETRIES = 4;
-
-    class UnmountCallBack {
-        final String path;
-        final boolean force;
-        final boolean removeEncryption;
-        int retries;
-
-        UnmountCallBack(String path, boolean force, boolean removeEncryption) {
-            retries = 0;
-            this.path = path;
-            this.force = force;
-            this.removeEncryption = removeEncryption;
-        }
-
-        void handleFinished() {
-            if (DEBUG_UNMOUNT) Slog.i(TAG, "Unmounting " + path);
-            doUnmountVolume(path, true, removeEncryption);
-        }
-    }
-
-    class UmsEnableCallBack extends UnmountCallBack {
-        final String method;
-
-        UmsEnableCallBack(String path, String method, boolean force) {
-            super(path, force, false);
-            this.method = method;
-        }
-
-        @Override
-        void handleFinished() {
-            super.handleFinished();
-            doShareUnshareVolume(path, method, true);
-        }
-    }
-
-    class ShutdownCallBack extends UnmountCallBack {
-        IMountShutdownObserver observer;
-        ShutdownCallBack(String path, IMountShutdownObserver observer) {
-            super(path, true, false);
-            this.observer = observer;
-        }
-
-        @Override
-        void handleFinished() {
-            int ret = doUnmountVolume(path, true, removeEncryption);
-            if (observer != null) {
-                try {
-                    observer.onShutDownComplete(ret);
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "RemoteException when shutting down");
-                }
-            }
-        }
-    }
-
-    class MountServiceHandler extends Handler {
-        ArrayList<UnmountCallBack> mForceUnmounts = new ArrayList<UnmountCallBack>();
-        boolean mUpdatingStatus = false;
-
-        MountServiceHandler(Looper l) {
-            super(l);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case H_UNMOUNT_PM_UPDATE: {
-                    if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_UPDATE");
-                    UnmountCallBack ucb = (UnmountCallBack) msg.obj;
-                    mForceUnmounts.add(ucb);
-                    if (DEBUG_UNMOUNT) Slog.i(TAG, " registered = " + mUpdatingStatus);
-                    // Register only if needed.
-                    if (!mUpdatingStatus) {
-                        if (DEBUG_UNMOUNT) Slog.i(TAG, "Updating external media status on PackageManager");
-                        mUpdatingStatus = true;
-                        mPms.updateExternalMediaStatus(false, true);
-                    }
-                    break;
-                }
-                case H_UNMOUNT_PM_DONE: {
-                    if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_PM_DONE");
-                    if (DEBUG_UNMOUNT) Slog.i(TAG, "Updated status. Processing requests");
-                    mUpdatingStatus = false;
-                    int size = mForceUnmounts.size();
-                    int sizeArr[] = new int[size];
-                    int sizeArrN = 0;
-                    // Kill processes holding references first
-                    ActivityManagerService ams = (ActivityManagerService)
-                    ServiceManager.getService("activity");
-                    for (int i = 0; i < size; i++) {
-                        UnmountCallBack ucb = mForceUnmounts.get(i);
-                        String path = ucb.path;
-                        boolean done = false;
-                        if (!ucb.force) {
-                            done = true;
-                        } else {
-                            int pids[] = getStorageUsers(path);
-                            if (pids == null || pids.length == 0) {
-                                done = true;
-                            } else {
-                                // Eliminate system process here?
-                                ams.killPids(pids, "unmount media", true);
-                                // Confirm if file references have been freed.
-                                pids = getStorageUsers(path);
-                                if (pids == null || pids.length == 0) {
-                                    done = true;
-                                }
-                            }
-                        }
-                        if (!done && (ucb.retries < MAX_UNMOUNT_RETRIES)) {
-                            // Retry again
-                            Slog.i(TAG, "Retrying to kill storage users again");
-                            mHandler.sendMessageDelayed(
-                                    mHandler.obtainMessage(H_UNMOUNT_PM_DONE,
-                                            ucb.retries++),
-                                    RETRY_UNMOUNT_DELAY);
-                        } else {
-                            if (ucb.retries >= MAX_UNMOUNT_RETRIES) {
-                                Slog.i(TAG, "Failed to unmount media inspite of " +
-                                        MAX_UNMOUNT_RETRIES + " retries. Forcibly killing processes now");
-                            }
-                            sizeArr[sizeArrN++] = i;
-                            mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_MS,
-                                    ucb));
-                        }
-                    }
-                    // Remove already processed elements from list.
-                    for (int i = (sizeArrN-1); i >= 0; i--) {
-                        mForceUnmounts.remove(sizeArr[i]);
-                    }
-                    break;
-                }
-                case H_UNMOUNT_MS: {
-                    if (DEBUG_UNMOUNT) Slog.i(TAG, "H_UNMOUNT_MS");
-                    UnmountCallBack ucb = (UnmountCallBack) msg.obj;
-                    ucb.handleFinished();
-                    break;
-                }
-                case H_SYSTEM_READY: {
-                    try {
-                        handleSystemReady();
-                    } catch (Exception ex) {
-                        Slog.e(TAG, "Boot-time mount exception", ex);
-                    }
-                    break;
-                }
-            }
-        }
-    };
-
-    private final Handler mHandler;
-
-    void waitForAsecScan() {
-        waitForLatch(mAsecsScanned);
-    }
-
-    private void waitForReady() {
-        waitForLatch(mConnectedSignal);
-    }
-
-    private void waitForLatch(CountDownLatch latch) {
-        for (;;) {
-            try {
-                if (latch.await(5000, TimeUnit.MILLISECONDS)) {
-                    return;
-                } else {
-                    Slog.w(TAG, "Thread " + Thread.currentThread().getName()
-                            + " still waiting for MountService ready...");
-                }
-            } catch (InterruptedException e) {
-                Slog.w(TAG, "Interrupt while waiting for MountService to be ready.");
-            }
-        }
-    }
-
-    private void handleSystemReady() {
-        // Snapshot current volume states since it's not safe to call into vold
-        // while holding locks.
-        final HashMap<String, String> snapshot;
-        synchronized (mVolumesLock) {
-            snapshot = new HashMap<String, String>(mVolumeStates);
-        }
-
-        for (Map.Entry<String, String> entry : snapshot.entrySet()) {
-            final String path = entry.getKey();
-            final String state = entry.getValue();
-
-            if (state.equals(Environment.MEDIA_UNMOUNTED)) {
-                int rc = doMountVolume(path);
-                if (rc != StorageResultCode.OperationSucceeded) {
-                    Slog.e(TAG, String.format("Boot-time mount failed (%d)",
-                            rc));
-                }
-            } else if (state.equals(Environment.MEDIA_SHARED)) {
-                /*
-                 * Bootstrap UMS enabled state since vold indicates
-                 * the volume is shared (runtime restart while ums enabled)
-                 */
-                notifyVolumeStateChange(null, path, VolumeState.NoMedia,
-                        VolumeState.Shared);
-            }
-        }
-
-        // Push mounted state for all emulated storage
-        synchronized (mVolumesLock) {
-            for (StorageVolume volume : mVolumes) {
-                if (volume.isEmulated()) {
-                    updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
-                }
-            }
-        }
-
-        /*
-         * If UMS was connected on boot, send the connected event
-         * now that we're up.
-         */
-        if (mSendUmsConnectedOnBoot) {
-            sendUmsIntent(true);
-            mSendUmsConnectedOnBoot = false;
-        }
-    }
-
-    private final BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
-            if (userId == -1) return;
-            final UserHandle user = new UserHandle(userId);
-
-            final String action = intent.getAction();
-            if (Intent.ACTION_USER_ADDED.equals(action)) {
-                synchronized (mVolumesLock) {
-                    createEmulatedVolumeForUserLocked(user);
-                }
-
-            } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
-                synchronized (mVolumesLock) {
-                    final List<StorageVolume> toRemove = Lists.newArrayList();
-                    for (StorageVolume volume : mVolumes) {
-                        if (user.equals(volume.getOwner())) {
-                            toRemove.add(volume);
-                        }
-                    }
-                    for (StorageVolume volume : toRemove) {
-                        removeVolumeLocked(volume);
-                    }
-                }
-            }
-        }
-    };
-
-    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            boolean available = (intent.getBooleanExtra(UsbManager.USB_CONNECTED, false) &&
-                    intent.getBooleanExtra(UsbManager.USB_FUNCTION_MASS_STORAGE, false));
-            notifyShareAvailabilityChange(available);
-        }
-    };
-
-    private final BroadcastReceiver mIdleMaintenanceReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            waitForReady();
-            String action = intent.getAction();
-            // Since fstrim will be run on a daily basis we do not expect
-            // fstrim to be too long, so it is not interruptible. We will
-            // implement interruption only in case we see issues.
-            if (Intent.ACTION_IDLE_MAINTENANCE_START.equals(action)) {
-                try {
-                    // This method runs on the handler thread,
-                    // so it is safe to directly call into vold.
-                    mConnector.execute("fstrim", "dotrim");
-                    EventLogTags.writeFstrimStart(SystemClock.elapsedRealtime());
-                } catch (NativeDaemonConnectorException ndce) {
-                    Slog.e(TAG, "Failed to run fstrim!");
-                }
-            }
-        }
-    };
-
-    private final class MountServiceBinderListener implements IBinder.DeathRecipient {
-        final IMountServiceListener mListener;
-
-        MountServiceBinderListener(IMountServiceListener listener) {
-            mListener = listener;
-
-        }
-
-        public void binderDied() {
-            if (LOCAL_LOGD) Slog.d(TAG, "An IMountServiceListener has died!");
-            synchronized (mListeners) {
-                mListeners.remove(this);
-                mListener.asBinder().unlinkToDeath(this, 0);
-            }
-        }
-    }
-
-    private void doShareUnshareVolume(String path, String method, boolean enable) {
-        // TODO: Add support for multiple share methods
-        if (!method.equals("ums")) {
-            throw new IllegalArgumentException(String.format("Method %s not supported", method));
-        }
-
-        try {
-            mConnector.execute("volume", enable ? "share" : "unshare", path, method);
-        } catch (NativeDaemonConnectorException e) {
-            Slog.e(TAG, "Failed to share/unshare", e);
-        }
-    }
-
-    private void updatePublicVolumeState(StorageVolume volume, String state) {
-        final String path = volume.getPath();
-        final String oldState;
-        synchronized (mVolumesLock) {
-            oldState = mVolumeStates.put(path, state);
-            volume.setState(state);
-        }
-
-        if (state.equals(oldState)) {
-            Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s",
-                    state, state, path));
-            return;
-        }
-
-        Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")");
-
-        // Tell PackageManager about changes to primary volume state, but only
-        // when not emulated.
-        if (volume.isPrimary() && !volume.isEmulated()) {
-            if (Environment.MEDIA_UNMOUNTED.equals(state)) {
-                mPms.updateExternalMediaStatus(false, false);
-
-                /*
-                 * Some OBBs might have been unmounted when this volume was
-                 * unmounted, so send a message to the handler to let it know to
-                 * remove those from the list of mounted OBBS.
-                 */
-                mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(
-                        OBB_FLUSH_MOUNT_STATE, path));
-            } else if (Environment.MEDIA_MOUNTED.equals(state)) {
-                mPms.updateExternalMediaStatus(true, false);
-            }
-        }
-
-        synchronized (mListeners) {
-            for (int i = mListeners.size() -1; i >= 0; i--) {
-                MountServiceBinderListener bl = mListeners.get(i);
-                try {
-                    bl.mListener.onStorageStateChanged(path, oldState, state);
-                } catch (RemoteException rex) {
-                    Slog.e(TAG, "Listener dead");
-                    mListeners.remove(i);
-                } catch (Exception ex) {
-                    Slog.e(TAG, "Listener failed", ex);
-                }
-            }
-        }
-    }
-
-    /**
-     * Callback from NativeDaemonConnector
-     */
-    public void onDaemonConnected() {
-        /*
-         * Since we'll be calling back into the NativeDaemonConnector,
-         * we need to do our work in a new thread.
-         */
-        new Thread("MountService#onDaemonConnected") {
-            @Override
-            public void run() {
-                /**
-                 * Determine media state and UMS detection status
-                 */
-                try {
-                    final String[] vols = NativeDaemonEvent.filterMessageList(
-                            mConnector.executeForList("volume", "list"),
-                            VoldResponseCode.VolumeListResult);
-                    for (String volstr : vols) {
-                        String[] tok = volstr.split(" ");
-                        // FMT: <label> <mountpoint> <state>
-                        String path = tok[1];
-                        String state = Environment.MEDIA_REMOVED;
-
-                        final StorageVolume volume;
-                        synchronized (mVolumesLock) {
-                            volume = mVolumesByPath.get(path);
-                        }
-
-                        int st = Integer.parseInt(tok[2]);
-                        if (st == VolumeState.NoMedia) {
-                            state = Environment.MEDIA_REMOVED;
-                        } else if (st == VolumeState.Idle) {
-                            state = Environment.MEDIA_UNMOUNTED;
-                        } else if (st == VolumeState.Mounted) {
-                            state = Environment.MEDIA_MOUNTED;
-                            Slog.i(TAG, "Media already mounted on daemon connection");
-                        } else if (st == VolumeState.Shared) {
-                            state = Environment.MEDIA_SHARED;
-                            Slog.i(TAG, "Media shared on daemon connection");
-                        } else {
-                            throw new Exception(String.format("Unexpected state %d", st));
-                        }
-
-                        if (state != null) {
-                            if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state);
-                            updatePublicVolumeState(volume, state);
-                        }
-                    }
-                } catch (Exception e) {
-                    Slog.e(TAG, "Error processing initial volume state", e);
-                    final StorageVolume primary = getPrimaryPhysicalVolume();
-                    if (primary != null) {
-                        updatePublicVolumeState(primary, Environment.MEDIA_REMOVED);
-                    }
-                }
-
-                /*
-                 * Now that we've done our initialization, release
-                 * the hounds!
-                 */
-                mConnectedSignal.countDown();
-
-                // Let package manager load internal ASECs.
-                mPms.scanAvailableAsecs();
-
-                // Notify people waiting for ASECs to be scanned that it's done.
-                mAsecsScanned.countDown();
-            }
-        }.start();
-    }
-
-    /**
-     * Callback from NativeDaemonConnector
-     */
-    public boolean onEvent(int code, String raw, String[] cooked) {
-        if (DEBUG_EVENTS) {
-            StringBuilder builder = new StringBuilder();
-            builder.append("onEvent::");
-            builder.append(" raw= " + raw);
-            if (cooked != null) {
-                builder.append(" cooked = " );
-                for (String str : cooked) {
-                    builder.append(" " + str);
-                }
-            }
-            Slog.i(TAG, builder.toString());
-        }
-        if (code == VoldResponseCode.VolumeStateChange) {
-            /*
-             * One of the volumes we're managing has changed state.
-             * Format: "NNN Volume <label> <path> state changed
-             * from <old_#> (<old_str>) to <new_#> (<new_str>)"
-             */
-            notifyVolumeStateChange(
-                    cooked[2], cooked[3], Integer.parseInt(cooked[7]),
-                            Integer.parseInt(cooked[10]));
-        } else if (code == VoldResponseCode.VolumeUuidChange) {
-            // Format: nnn <label> <path> <uuid>
-            final String path = cooked[2];
-            final String uuid = (cooked.length > 3) ? cooked[3] : null;
-
-            final StorageVolume vol = mVolumesByPath.get(path);
-            if (vol != null) {
-                vol.setUuid(uuid);
-            }
-
-        } else if (code == VoldResponseCode.VolumeUserLabelChange) {
-            // Format: nnn <label> <path> <label>
-            final String path = cooked[2];
-            final String userLabel = (cooked.length > 3) ? cooked[3] : null;
-
-            final StorageVolume vol = mVolumesByPath.get(path);
-            if (vol != null) {
-                vol.setUserLabel(userLabel);
-            }
-
-        } else if ((code == VoldResponseCode.VolumeDiskInserted) ||
-                   (code == VoldResponseCode.VolumeDiskRemoved) ||
-                   (code == VoldResponseCode.VolumeBadRemoval)) {
-            // FMT: NNN Volume <label> <mountpoint> disk inserted (<major>:<minor>)
-            // FMT: NNN Volume <label> <mountpoint> disk removed (<major>:<minor>)
-            // FMT: NNN Volume <label> <mountpoint> bad removal (<major>:<minor>)
-            String action = null;
-            final String label = cooked[2];
-            final String path = cooked[3];
-            int major = -1;
-            int minor = -1;
-
-            try {
-                String devComp = cooked[6].substring(1, cooked[6].length() -1);
-                String[] devTok = devComp.split(":");
-                major = Integer.parseInt(devTok[0]);
-                minor = Integer.parseInt(devTok[1]);
-            } catch (Exception ex) {
-                Slog.e(TAG, "Failed to parse major/minor", ex);
-            }
-
-            final StorageVolume volume;
-            final String state;
-            synchronized (mVolumesLock) {
-                volume = mVolumesByPath.get(path);
-                state = mVolumeStates.get(path);
-            }
-
-            if (code == VoldResponseCode.VolumeDiskInserted) {
-                new Thread("MountService#VolumeDiskInserted") {
-                    @Override
-                    public void run() {
-                        try {
-                            int rc;
-                            if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
-                                Slog.w(TAG, String.format("Insertion mount failed (%d)", rc));
-                            }
-                        } catch (Exception ex) {
-                            Slog.w(TAG, "Failed to mount media on insertion", ex);
-                        }
-                    }
-                }.start();
-            } else if (code == VoldResponseCode.VolumeDiskRemoved) {
-                /*
-                 * This event gets trumped if we're already in BAD_REMOVAL state
-                 */
-                if (getVolumeState(path).equals(Environment.MEDIA_BAD_REMOVAL)) {
-                    return true;
-                }
-                /* Send the media unmounted event first */
-                if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first");
-                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
-                sendStorageIntent(Environment.MEDIA_UNMOUNTED, volume, UserHandle.ALL);
-
-                if (DEBUG_EVENTS) Slog.i(TAG, "Sending media removed");
-                updatePublicVolumeState(volume, Environment.MEDIA_REMOVED);
-                action = Intent.ACTION_MEDIA_REMOVED;
-            } else if (code == VoldResponseCode.VolumeBadRemoval) {
-                if (DEBUG_EVENTS) Slog.i(TAG, "Sending unmounted event first");
-                /* Send the media unmounted event first */
-                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
-                sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);
-
-                if (DEBUG_EVENTS) Slog.i(TAG, "Sending media bad removal");
-                updatePublicVolumeState(volume, Environment.MEDIA_BAD_REMOVAL);
-                action = Intent.ACTION_MEDIA_BAD_REMOVAL;
-            } else if (code == VoldResponseCode.FstrimCompleted) {
-                EventLogTags.writeFstrimFinish(SystemClock.elapsedRealtime());
-            } else {
-                Slog.e(TAG, String.format("Unknown code {%d}", code));
-            }
-
-            if (action != null) {
-                sendStorageIntent(action, volume, UserHandle.ALL);
-            }
-        } else {
-            return false;
-        }
-
-        return true;
-    }
-
-    private void notifyVolumeStateChange(String label, String path, int oldState, int newState) {
-        final StorageVolume volume;
-        final String state;
-        synchronized (mVolumesLock) {
-            volume = mVolumesByPath.get(path);
-            state = getVolumeState(path);
-        }
-
-        if (DEBUG_EVENTS) Slog.i(TAG, "notifyVolumeStateChange::" + state);
-
-        String action = null;
-
-        if (oldState == VolumeState.Shared && newState != oldState) {
-            if (LOCAL_LOGD) Slog.d(TAG, "Sending ACTION_MEDIA_UNSHARED intent");
-            sendStorageIntent(Intent.ACTION_MEDIA_UNSHARED, volume, UserHandle.ALL);
-        }
-
-        if (newState == VolumeState.Init) {
-        } else if (newState == VolumeState.NoMedia) {
-            // NoMedia is handled via Disk Remove events
-        } else if (newState == VolumeState.Idle) {
-            /*
-             * Don't notify if we're in BAD_REMOVAL, NOFS, UNMOUNTABLE, or
-             * if we're in the process of enabling UMS
-             */
-            if (!state.equals(
-                    Environment.MEDIA_BAD_REMOVAL) && !state.equals(
-                            Environment.MEDIA_NOFS) && !state.equals(
-                                    Environment.MEDIA_UNMOUNTABLE) && !getUmsEnabling()) {
-                if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state for media bad removal nofs and unmountable");
-                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
-                action = Intent.ACTION_MEDIA_UNMOUNTED;
-            }
-        } else if (newState == VolumeState.Pending) {
-        } else if (newState == VolumeState.Checking) {
-            if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state checking");
-            updatePublicVolumeState(volume, Environment.MEDIA_CHECKING);
-            action = Intent.ACTION_MEDIA_CHECKING;
-        } else if (newState == VolumeState.Mounted) {
-            if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state mounted");
-            updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
-            action = Intent.ACTION_MEDIA_MOUNTED;
-        } else if (newState == VolumeState.Unmounting) {
-            action = Intent.ACTION_MEDIA_EJECT;
-        } else if (newState == VolumeState.Formatting) {
-        } else if (newState == VolumeState.Shared) {
-            if (DEBUG_EVENTS) Slog.i(TAG, "Updating volume state media mounted");
-            /* Send the media unmounted event first */
-            updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTED);
-            sendStorageIntent(Intent.ACTION_MEDIA_UNMOUNTED, volume, UserHandle.ALL);
-
-            if (DEBUG_EVENTS) Slog.i(TAG, "Updating media shared");
-            updatePublicVolumeState(volume, Environment.MEDIA_SHARED);
-            action = Intent.ACTION_MEDIA_SHARED;
-            if (LOCAL_LOGD) Slog.d(TAG, "Sending ACTION_MEDIA_SHARED intent");
-        } else if (newState == VolumeState.SharedMnt) {
-            Slog.e(TAG, "Live shared mounts not supported yet!");
-            return;
-        } else {
-            Slog.e(TAG, "Unhandled VolumeState {" + newState + "}");
-        }
-
-        if (action != null) {
-            sendStorageIntent(action, volume, UserHandle.ALL);
-        }
-    }
-
-    private int doMountVolume(String path) {
-        int rc = StorageResultCode.OperationSucceeded;
-
-        final StorageVolume volume;
-        synchronized (mVolumesLock) {
-            volume = mVolumesByPath.get(path);
-        }
-
-        if (DEBUG_EVENTS) Slog.i(TAG, "doMountVolume: Mouting " + path);
-        try {
-            mConnector.execute("volume", "mount", path);
-        } catch (NativeDaemonConnectorException e) {
-            /*
-             * Mount failed for some reason
-             */
-            String action = null;
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedNoMedia) {
-                /*
-                 * Attempt to mount but no media inserted
-                 */
-                rc = StorageResultCode.OperationFailedNoMedia;
-            } else if (code == VoldResponseCode.OpFailedMediaBlank) {
-                if (DEBUG_EVENTS) Slog.i(TAG, " updating volume state :: media nofs");
-                /*
-                 * Media is blank or does not contain a supported filesystem
-                 */
-                updatePublicVolumeState(volume, Environment.MEDIA_NOFS);
-                action = Intent.ACTION_MEDIA_NOFS;
-                rc = StorageResultCode.OperationFailedMediaBlank;
-            } else if (code == VoldResponseCode.OpFailedMediaCorrupt) {
-                if (DEBUG_EVENTS) Slog.i(TAG, "updating volume state media corrupt");
-                /*
-                 * Volume consistency check failed
-                 */
-                updatePublicVolumeState(volume, Environment.MEDIA_UNMOUNTABLE);
-                action = Intent.ACTION_MEDIA_UNMOUNTABLE;
-                rc = StorageResultCode.OperationFailedMediaCorrupt;
-            } else {
-                rc = StorageResultCode.OperationFailedInternalError;
-            }
-
-            /*
-             * Send broadcast intent (if required for the failure)
-             */
-            if (action != null) {
-                sendStorageIntent(action, volume, UserHandle.ALL);
-            }
-        }
-
-        return rc;
-    }
-
-    /*
-     * If force is not set, we do not unmount if there are
-     * processes holding references to the volume about to be unmounted.
-     * If force is set, all the processes holding references need to be
-     * killed via the ActivityManager before actually unmounting the volume.
-     * This might even take a while and might be retried after timed delays
-     * to make sure we dont end up in an instable state and kill some core
-     * processes.
-     * If removeEncryption is set, force is implied, and the system will remove any encryption
-     * mapping set on the volume when unmounting.
-     */
-    private int doUnmountVolume(String path, boolean force, boolean removeEncryption) {
-        if (!getVolumeState(path).equals(Environment.MEDIA_MOUNTED)) {
-            return VoldResponseCode.OpFailedVolNotMounted;
-        }
-
-        /*
-         * Force a GC to make sure AssetManagers in other threads of the
-         * system_server are cleaned up. We have to do this since AssetManager
-         * instances are kept as a WeakReference and it's possible we have files
-         * open on the external storage.
-         */
-        Runtime.getRuntime().gc();
-
-        // Redundant probably. But no harm in updating state again.
-        mPms.updateExternalMediaStatus(false, false);
-        try {
-            final Command cmd = new Command("volume", "unmount", path);
-            if (removeEncryption) {
-                cmd.appendArg("force_and_revert");
-            } else if (force) {
-                cmd.appendArg("force");
-            }
-            mConnector.execute(cmd);
-            // We unmounted the volume. None of the asec containers are available now.
-            synchronized (mAsecMountSet) {
-                mAsecMountSet.clear();
-            }
-            return StorageResultCode.OperationSucceeded;
-        } catch (NativeDaemonConnectorException e) {
-            // Don't worry about mismatch in PackageManager since the
-            // call back will handle the status changes any way.
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedVolNotMounted) {
-                return StorageResultCode.OperationFailedStorageNotMounted;
-            } else if (code == VoldResponseCode.OpFailedStorageBusy) {
-                return StorageResultCode.OperationFailedStorageBusy;
-            } else {
-                return StorageResultCode.OperationFailedInternalError;
-            }
-        }
-    }
-
-    private int doFormatVolume(String path) {
-        try {
-            mConnector.execute("volume", "format", path);
-            return StorageResultCode.OperationSucceeded;
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedNoMedia) {
-                return StorageResultCode.OperationFailedNoMedia;
-            } else if (code == VoldResponseCode.OpFailedMediaCorrupt) {
-                return StorageResultCode.OperationFailedMediaCorrupt;
-            } else {
-                return StorageResultCode.OperationFailedInternalError;
-            }
-        }
-    }
-
-    private boolean doGetVolumeShared(String path, String method) {
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("volume", "shared", path, method);
-        } catch (NativeDaemonConnectorException ex) {
-            Slog.e(TAG, "Failed to read response to volume shared " + path + " " + method);
-            return false;
-        }
-
-        if (event.getCode() == VoldResponseCode.ShareEnabledResult) {
-            return event.getMessage().endsWith("enabled");
-        } else {
-            return false;
-        }
-    }
-
-    private void notifyShareAvailabilityChange(final boolean avail) {
-        synchronized (mListeners) {
-            mUmsAvailable = avail;
-            for (int i = mListeners.size() -1; i >= 0; i--) {
-                MountServiceBinderListener bl = mListeners.get(i);
-                try {
-                    bl.mListener.onUsbMassStorageConnectionChanged(avail);
-                } catch (RemoteException rex) {
-                    Slog.e(TAG, "Listener dead");
-                    mListeners.remove(i);
-                } catch (Exception ex) {
-                    Slog.e(TAG, "Listener failed", ex);
-                }
-            }
-        }
-
-        if (mSystemReady == true) {
-            sendUmsIntent(avail);
-        } else {
-            mSendUmsConnectedOnBoot = avail;
-        }
-
-        final StorageVolume primary = getPrimaryPhysicalVolume();
-        if (avail == false && primary != null
-                && Environment.MEDIA_SHARED.equals(getVolumeState(primary.getPath()))) {
-            final String path = primary.getPath();
-            /*
-             * USB mass storage disconnected while enabled
-             */
-            new Thread("MountService#AvailabilityChange") {
-                @Override
-                public void run() {
-                    try {
-                        int rc;
-                        Slog.w(TAG, "Disabling UMS after cable disconnect");
-                        doShareUnshareVolume(path, "ums", false);
-                        if ((rc = doMountVolume(path)) != StorageResultCode.OperationSucceeded) {
-                            Slog.e(TAG, String.format(
-                                    "Failed to remount {%s} on UMS enabled-disconnect (%d)",
-                                            path, rc));
-                        }
-                    } catch (Exception ex) {
-                        Slog.w(TAG, "Failed to mount media on UMS enabled-disconnect", ex);
-                    }
-                }
-            }.start();
-        }
-    }
-
-    private void sendStorageIntent(String action, StorageVolume volume, UserHandle user) {
-        final Intent intent = new Intent(action, Uri.parse("file://" + volume.getPath()));
-        intent.putExtra(StorageVolume.EXTRA_STORAGE_VOLUME, volume);
-        Slog.d(TAG, "sendStorageIntent " + intent + " to " + user);
-        mContext.sendBroadcastAsUser(intent, user);
-    }
-
-    private void sendUmsIntent(boolean c) {
-        mContext.sendBroadcastAsUser(
-                new Intent((c ? Intent.ACTION_UMS_CONNECTED : Intent.ACTION_UMS_DISCONNECTED)),
-                UserHandle.ALL);
-    }
-
-    private void validatePermission(String perm) {
-        if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException(String.format("Requires %s permission", perm));
-        }
-    }
-
-    // Storage list XML tags
-    private static final String TAG_STORAGE_LIST = "StorageList";
-    private static final String TAG_STORAGE = "storage";
-
-    private void readStorageListLocked() {
-        mVolumes.clear();
-        mVolumeStates.clear();
-
-        Resources resources = mContext.getResources();
-
-        int id = com.android.internal.R.xml.storage_list;
-        XmlResourceParser parser = resources.getXml(id);
-        AttributeSet attrs = Xml.asAttributeSet(parser);
-
-        try {
-            XmlUtils.beginDocument(parser, TAG_STORAGE_LIST);
-            while (true) {
-                XmlUtils.nextElement(parser);
-
-                String element = parser.getName();
-                if (element == null) break;
-
-                if (TAG_STORAGE.equals(element)) {
-                    TypedArray a = resources.obtainAttributes(attrs,
-                            com.android.internal.R.styleable.Storage);
-
-                    String path = a.getString(
-                            com.android.internal.R.styleable.Storage_mountPoint);
-                    int descriptionId = a.getResourceId(
-                            com.android.internal.R.styleable.Storage_storageDescription, -1);
-                    CharSequence description = a.getText(
-                            com.android.internal.R.styleable.Storage_storageDescription);
-                    boolean primary = a.getBoolean(
-                            com.android.internal.R.styleable.Storage_primary, false);
-                    boolean removable = a.getBoolean(
-                            com.android.internal.R.styleable.Storage_removable, false);
-                    boolean emulated = a.getBoolean(
-                            com.android.internal.R.styleable.Storage_emulated, false);
-                    int mtpReserve = a.getInt(
-                            com.android.internal.R.styleable.Storage_mtpReserve, 0);
-                    boolean allowMassStorage = a.getBoolean(
-                            com.android.internal.R.styleable.Storage_allowMassStorage, false);
-                    // resource parser does not support longs, so XML value is in megabytes
-                    long maxFileSize = a.getInt(
-                            com.android.internal.R.styleable.Storage_maxFileSize, 0) * 1024L * 1024L;
-
-                    Slog.d(TAG, "got storage path: " + path + " description: " + description +
-                            " primary: " + primary + " removable: " + removable +
-                            " emulated: " + emulated +  " mtpReserve: " + mtpReserve +
-                            " allowMassStorage: " + allowMassStorage +
-                            " maxFileSize: " + maxFileSize);
-
-                    if (emulated) {
-                        // For devices with emulated storage, we create separate
-                        // volumes for each known user.
-                        mEmulatedTemplate = new StorageVolume(null, descriptionId, true, false,
-                                true, mtpReserve, false, maxFileSize, null);
-
-                        final UserManagerService userManager = UserManagerService.getInstance();
-                        for (UserInfo user : userManager.getUsers(false)) {
-                            createEmulatedVolumeForUserLocked(user.getUserHandle());
-                        }
-
-                    } else {
-                        if (path == null || description == null) {
-                            Slog.e(TAG, "Missing storage path or description in readStorageList");
-                        } else {
-                            final StorageVolume volume = new StorageVolume(new File(path),
-                                    descriptionId, primary, removable, emulated, mtpReserve,
-                                    allowMassStorage, maxFileSize, null);
-                            addVolumeLocked(volume);
-
-                            // Until we hear otherwise, treat as unmounted
-                            mVolumeStates.put(volume.getPath(), Environment.MEDIA_UNMOUNTED);
-                            volume.setState(Environment.MEDIA_UNMOUNTED);
-                        }
-                    }
-
-                    a.recycle();
-                }
-            }
-        } catch (XmlPullParserException e) {
-            throw new RuntimeException(e);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        } finally {
-            // Compute storage ID for each physical volume; emulated storage is
-            // always 0 when defined.
-            int index = isExternalStorageEmulated() ? 1 : 0;
-            for (StorageVolume volume : mVolumes) {
-                if (!volume.isEmulated()) {
-                    volume.setStorageId(index++);
-                }
-            }
-            parser.close();
-        }
-    }
-
-    /**
-     * Create and add new {@link StorageVolume} for given {@link UserHandle}
-     * using {@link #mEmulatedTemplate} as template.
-     */
-    private void createEmulatedVolumeForUserLocked(UserHandle user) {
-        if (mEmulatedTemplate == null) {
-            throw new IllegalStateException("Missing emulated volume multi-user template");
-        }
-
-        final UserEnvironment userEnv = new UserEnvironment(user.getIdentifier());
-        final File path = userEnv.getExternalStorageDirectory();
-        final StorageVolume volume = StorageVolume.fromTemplate(mEmulatedTemplate, path, user);
-        volume.setStorageId(0);
-        addVolumeLocked(volume);
-
-        if (mSystemReady) {
-            updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
-        } else {
-            // Place stub status for early callers to find
-            mVolumeStates.put(volume.getPath(), Environment.MEDIA_MOUNTED);
-            volume.setState(Environment.MEDIA_MOUNTED);
-        }
-    }
-
-    private void addVolumeLocked(StorageVolume volume) {
-        Slog.d(TAG, "addVolumeLocked() " + volume);
-        mVolumes.add(volume);
-        final StorageVolume existing = mVolumesByPath.put(volume.getPath(), volume);
-        if (existing != null) {
-            throw new IllegalStateException(
-                    "Volume at " + volume.getPath() + " already exists: " + existing);
-        }
-    }
-
-    private void removeVolumeLocked(StorageVolume volume) {
-        Slog.d(TAG, "removeVolumeLocked() " + volume);
-        mVolumes.remove(volume);
-        mVolumesByPath.remove(volume.getPath());
-        mVolumeStates.remove(volume.getPath());
-    }
-
-    private StorageVolume getPrimaryPhysicalVolume() {
-        synchronized (mVolumesLock) {
-            for (StorageVolume volume : mVolumes) {
-                if (volume.isPrimary() && !volume.isEmulated()) {
-                    return volume;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Constructs a new MountService instance
-     *
-     * @param context  Binder context for this service
-     */
-    public MountService(Context context) {
-        mContext = context;
-
-        synchronized (mVolumesLock) {
-            readStorageListLocked();
-        }
-
-        // XXX: This will go away soon in favor of IMountServiceObserver
-        mPms = (PackageManagerService) ServiceManager.getService("package");
-
-        HandlerThread hthread = new HandlerThread(TAG);
-        hthread.start();
-        mHandler = new MountServiceHandler(hthread.getLooper());
-
-        // Watch for user changes
-        final IntentFilter userFilter = new IntentFilter();
-        userFilter.addAction(Intent.ACTION_USER_ADDED);
-        userFilter.addAction(Intent.ACTION_USER_REMOVED);
-        mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);
-
-        // Watch for USB changes on primary volume
-        final StorageVolume primary = getPrimaryPhysicalVolume();
-        if (primary != null && primary.allowMassStorage()) {
-            mContext.registerReceiver(
-                    mUsbReceiver, new IntentFilter(UsbManager.ACTION_USB_STATE), null, mHandler);
-        }
-
-        // Watch for idle maintenance changes
-        IntentFilter idleMaintenanceFilter = new IntentFilter();
-        idleMaintenanceFilter.addAction(Intent.ACTION_IDLE_MAINTENANCE_START);
-        mContext.registerReceiverAsUser(mIdleMaintenanceReceiver, UserHandle.ALL,
-                idleMaintenanceFilter, null, mHandler);
-
-        // Add OBB Action Handler to MountService thread.
-        mObbActionHandler = new ObbActionHandler(IoThread.get().getLooper());
-
-        /*
-         * Create the connection to vold with a maximum queue of twice the
-         * amount of containers we'd ever expect to have. This keeps an
-         * "asec list" from blocking a thread repeatedly.
-         */
-        mConnector = new NativeDaemonConnector(this, "vold", MAX_CONTAINERS * 2, VOLD_TAG, 25);
-
-        Thread thread = new Thread(mConnector, VOLD_TAG);
-        thread.start();
-
-        // Add ourself to the Watchdog monitors if enabled.
-        if (WATCHDOG_ENABLE) {
-            Watchdog.getInstance().addMonitor(this);
-        }
-    }
-
-    public void systemReady() {
-        mSystemReady = true;
-        mHandler.obtainMessage(H_SYSTEM_READY).sendToTarget();
-    }
-
-    /**
-     * Exposed API calls below here
-     */
-
-    public void registerListener(IMountServiceListener listener) {
-        synchronized (mListeners) {
-            MountServiceBinderListener bl = new MountServiceBinderListener(listener);
-            try {
-                listener.asBinder().linkToDeath(bl, 0);
-                mListeners.add(bl);
-            } catch (RemoteException rex) {
-                Slog.e(TAG, "Failed to link to listener death");
-            }
-        }
-    }
-
-    public void unregisterListener(IMountServiceListener listener) {
-        synchronized (mListeners) {
-            for(MountServiceBinderListener bl : mListeners) {
-                if (bl.mListener == listener) {
-                    mListeners.remove(mListeners.indexOf(bl));
-                    listener.asBinder().unlinkToDeath(bl, 0);
-                    return;
-                }
-            }
-        }
-    }
-
-    public void shutdown(final IMountShutdownObserver observer) {
-        validatePermission(android.Manifest.permission.SHUTDOWN);
-
-        Slog.i(TAG, "Shutting down");
-        synchronized (mVolumesLock) {
-            for (String path : mVolumeStates.keySet()) {
-                String state = mVolumeStates.get(path);
-
-                if (state.equals(Environment.MEDIA_SHARED)) {
-                    /*
-                     * If the media is currently shared, unshare it.
-                     * XXX: This is still dangerous!. We should not
-                     * be rebooting at *all* if UMS is enabled, since
-                     * the UMS host could have dirty FAT cache entries
-                     * yet to flush.
-                     */
-                    setUsbMassStorageEnabled(false);
-                } else if (state.equals(Environment.MEDIA_CHECKING)) {
-                    /*
-                     * If the media is being checked, then we need to wait for
-                     * it to complete before being able to proceed.
-                     */
-                    // XXX: @hackbod - Should we disable the ANR timer here?
-                    int retries = 30;
-                    while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >=0)) {
-                        try {
-                            Thread.sleep(1000);
-                        } catch (InterruptedException iex) {
-                            Slog.e(TAG, "Interrupted while waiting for media", iex);
-                            break;
-                        }
-                        state = Environment.getExternalStorageState();
-                    }
-                    if (retries == 0) {
-                        Slog.e(TAG, "Timed out waiting for media to check");
-                    }
-                }
-
-                if (state.equals(Environment.MEDIA_MOUNTED)) {
-                    // Post a unmount message.
-                    ShutdownCallBack ucb = new ShutdownCallBack(path, observer);
-                    mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
-                } else if (observer != null) {
-                    /*
-                     * Observer is waiting for onShutDownComplete when we are done.
-                     * Since nothing will be done send notification directly so shutdown
-                     * sequence can continue.
-                     */
-                    try {
-                        observer.onShutDownComplete(StorageResultCode.OperationSucceeded);
-                    } catch (RemoteException e) {
-                        Slog.w(TAG, "RemoteException when shutting down");
-                    }
-                }
-            }
-        }
-    }
-
-    private boolean getUmsEnabling() {
-        synchronized (mListeners) {
-            return mUmsEnabling;
-        }
-    }
-
-    private void setUmsEnabling(boolean enable) {
-        synchronized (mListeners) {
-            mUmsEnabling = enable;
-        }
-    }
-
-    public boolean isUsbMassStorageConnected() {
-        waitForReady();
-
-        if (getUmsEnabling()) {
-            return true;
-        }
-        synchronized (mListeners) {
-            return mUmsAvailable;
-        }
-    }
-
-    public void setUsbMassStorageEnabled(boolean enable) {
-        waitForReady();
-        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
-
-        final StorageVolume primary = getPrimaryPhysicalVolume();
-        if (primary == null) return;
-
-        // TODO: Add support for multiple share methods
-
-        /*
-         * If the volume is mounted and we're enabling then unmount it
-         */
-        String path = primary.getPath();
-        String vs = getVolumeState(path);
-        String method = "ums";
-        if (enable && vs.equals(Environment.MEDIA_MOUNTED)) {
-            // Override for isUsbMassStorageEnabled()
-            setUmsEnabling(enable);
-            UmsEnableCallBack umscb = new UmsEnableCallBack(path, method, true);
-            mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, umscb));
-            // Clear override
-            setUmsEnabling(false);
-        }
-        /*
-         * If we disabled UMS then mount the volume
-         */
-        if (!enable) {
-            doShareUnshareVolume(path, method, enable);
-            if (doMountVolume(path) != StorageResultCode.OperationSucceeded) {
-                Slog.e(TAG, "Failed to remount " + path +
-                        " after disabling share method " + method);
-                /*
-                 * Even though the mount failed, the unshare didn't so don't indicate an error.
-                 * The mountVolume() call will have set the storage state and sent the necessary
-                 * broadcasts.
-                 */
-            }
-        }
-    }
-
-    public boolean isUsbMassStorageEnabled() {
-        waitForReady();
-
-        final StorageVolume primary = getPrimaryPhysicalVolume();
-        if (primary != null) {
-            return doGetVolumeShared(primary.getPath(), "ums");
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * @return state of the volume at the specified mount point
-     */
-    public String getVolumeState(String mountPoint) {
-        synchronized (mVolumesLock) {
-            String state = mVolumeStates.get(mountPoint);
-            if (state == null) {
-                Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume");
-                if (SystemProperties.get("vold.encrypt_progress").length() != 0) {
-                    state = Environment.MEDIA_REMOVED;
-                } else {
-                    throw new IllegalArgumentException();
-                }
-            }
-
-            return state;
-        }
-    }
-
-    @Override
-    public boolean isExternalStorageEmulated() {
-        return mEmulatedTemplate != null;
-    }
-
-    public int mountVolume(String path) {
-        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
-
-        waitForReady();
-        return doMountVolume(path);
-    }
-
-    public void unmountVolume(String path, boolean force, boolean removeEncryption) {
-        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
-        waitForReady();
-
-        String volState = getVolumeState(path);
-        if (DEBUG_UNMOUNT) {
-            Slog.i(TAG, "Unmounting " + path
-                    + " force = " + force
-                    + " removeEncryption = " + removeEncryption);
-        }
-        if (Environment.MEDIA_UNMOUNTED.equals(volState) ||
-                Environment.MEDIA_REMOVED.equals(volState) ||
-                Environment.MEDIA_SHARED.equals(volState) ||
-                Environment.MEDIA_UNMOUNTABLE.equals(volState)) {
-            // Media already unmounted or cannot be unmounted.
-            // TODO return valid return code when adding observer call back.
-            return;
-        }
-        UnmountCallBack ucb = new UnmountCallBack(path, force, removeEncryption);
-        mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
-    }
-
-    public int formatVolume(String path) {
-        validatePermission(android.Manifest.permission.MOUNT_FORMAT_FILESYSTEMS);
-        waitForReady();
-
-        return doFormatVolume(path);
-    }
-
-    public int[] getStorageUsers(String path) {
-        validatePermission(android.Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS);
-        waitForReady();
-        try {
-            final String[] r = NativeDaemonEvent.filterMessageList(
-                    mConnector.executeForList("storage", "users", path),
-                    VoldResponseCode.StorageUsersListResult);
-
-            // FMT: <pid> <process name>
-            int[] data = new int[r.length];
-            for (int i = 0; i < r.length; i++) {
-                String[] tok = r[i].split(" ");
-                try {
-                    data[i] = Integer.parseInt(tok[0]);
-                } catch (NumberFormatException nfe) {
-                    Slog.e(TAG, String.format("Error parsing pid %s", tok[0]));
-                    return new int[0];
-                }
-            }
-            return data;
-        } catch (NativeDaemonConnectorException e) {
-            Slog.e(TAG, "Failed to retrieve storage users list", e);
-            return new int[0];
-        }
-    }
-
-    private void warnOnNotMounted() {
-        final StorageVolume primary = getPrimaryPhysicalVolume();
-        if (primary != null) {
-            boolean mounted = false;
-            try {
-                mounted = Environment.MEDIA_MOUNTED.equals(getVolumeState(primary.getPath()));
-            } catch (IllegalArgumentException e) {
-            }
-
-            if (!mounted) {
-                Slog.w(TAG, "getSecureContainerList() called when storage not mounted");
-            }
-        }
-    }
-
-    public String[] getSecureContainerList() {
-        validatePermission(android.Manifest.permission.ASEC_ACCESS);
-        waitForReady();
-        warnOnNotMounted();
-
-        try {
-            return NativeDaemonEvent.filterMessageList(
-                    mConnector.executeForList("asec", "list"), VoldResponseCode.AsecListResult);
-        } catch (NativeDaemonConnectorException e) {
-            return new String[0];
-        }
-    }
-
-    public int createSecureContainer(String id, int sizeMb, String fstype, String key,
-            int ownerUid, boolean external) {
-        validatePermission(android.Manifest.permission.ASEC_CREATE);
-        waitForReady();
-        warnOnNotMounted();
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            mConnector.execute("asec", "create", id, sizeMb, fstype, new SensitiveArg(key),
-                    ownerUid, external ? "1" : "0");
-        } catch (NativeDaemonConnectorException e) {
-            rc = StorageResultCode.OperationFailedInternalError;
-        }
-
-        if (rc == StorageResultCode.OperationSucceeded) {
-            synchronized (mAsecMountSet) {
-                mAsecMountSet.add(id);
-            }
-        }
-        return rc;
-    }
-
-    public int finalizeSecureContainer(String id) {
-        validatePermission(android.Manifest.permission.ASEC_CREATE);
-        warnOnNotMounted();
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            mConnector.execute("asec", "finalize", id);
-            /*
-             * Finalization does a remount, so no need
-             * to update mAsecMountSet
-             */
-        } catch (NativeDaemonConnectorException e) {
-            rc = StorageResultCode.OperationFailedInternalError;
-        }
-        return rc;
-    }
-
-    public int fixPermissionsSecureContainer(String id, int gid, String filename) {
-        validatePermission(android.Manifest.permission.ASEC_CREATE);
-        warnOnNotMounted();
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            mConnector.execute("asec", "fixperms", id, gid, filename);
-            /*
-             * Fix permissions does a remount, so no need to update
-             * mAsecMountSet
-             */
-        } catch (NativeDaemonConnectorException e) {
-            rc = StorageResultCode.OperationFailedInternalError;
-        }
-        return rc;
-    }
-
-    public int destroySecureContainer(String id, boolean force) {
-        validatePermission(android.Manifest.permission.ASEC_DESTROY);
-        waitForReady();
-        warnOnNotMounted();
-
-        /*
-         * Force a GC to make sure AssetManagers in other threads of the
-         * system_server are cleaned up. We have to do this since AssetManager
-         * instances are kept as a WeakReference and it's possible we have files
-         * open on the external storage.
-         */
-        Runtime.getRuntime().gc();
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            final Command cmd = new Command("asec", "destroy", id);
-            if (force) {
-                cmd.appendArg("force");
-            }
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedStorageBusy) {
-                rc = StorageResultCode.OperationFailedStorageBusy;
-            } else {
-                rc = StorageResultCode.OperationFailedInternalError;
-            }
-        }
-
-        if (rc == StorageResultCode.OperationSucceeded) {
-            synchronized (mAsecMountSet) {
-                if (mAsecMountSet.contains(id)) {
-                    mAsecMountSet.remove(id);
-                }
-            }
-        }
-
-        return rc;
-    }
-
-    public int mountSecureContainer(String id, String key, int ownerUid) {
-        validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
-        waitForReady();
-        warnOnNotMounted();
-
-        synchronized (mAsecMountSet) {
-            if (mAsecMountSet.contains(id)) {
-                return StorageResultCode.OperationFailedStorageMounted;
-            }
-        }
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            mConnector.execute("asec", "mount", id, new SensitiveArg(key), ownerUid);
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code != VoldResponseCode.OpFailedStorageBusy) {
-                rc = StorageResultCode.OperationFailedInternalError;
-            }
-        }
-
-        if (rc == StorageResultCode.OperationSucceeded) {
-            synchronized (mAsecMountSet) {
-                mAsecMountSet.add(id);
-            }
-        }
-        return rc;
-    }
-
-    public int unmountSecureContainer(String id, boolean force) {
-        validatePermission(android.Manifest.permission.ASEC_MOUNT_UNMOUNT);
-        waitForReady();
-        warnOnNotMounted();
-
-        synchronized (mAsecMountSet) {
-            if (!mAsecMountSet.contains(id)) {
-                return StorageResultCode.OperationFailedStorageNotMounted;
-            }
-         }
-
-        /*
-         * Force a GC to make sure AssetManagers in other threads of the
-         * system_server are cleaned up. We have to do this since AssetManager
-         * instances are kept as a WeakReference and it's possible we have files
-         * open on the external storage.
-         */
-        Runtime.getRuntime().gc();
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            final Command cmd = new Command("asec", "unmount", id);
-            if (force) {
-                cmd.appendArg("force");
-            }
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedStorageBusy) {
-                rc = StorageResultCode.OperationFailedStorageBusy;
-            } else {
-                rc = StorageResultCode.OperationFailedInternalError;
-            }
-        }
-
-        if (rc == StorageResultCode.OperationSucceeded) {
-            synchronized (mAsecMountSet) {
-                mAsecMountSet.remove(id);
-            }
-        }
-        return rc;
-    }
-
-    public boolean isSecureContainerMounted(String id) {
-        validatePermission(android.Manifest.permission.ASEC_ACCESS);
-        waitForReady();
-        warnOnNotMounted();
-
-        synchronized (mAsecMountSet) {
-            return mAsecMountSet.contains(id);
-        }
-    }
-
-    public int renameSecureContainer(String oldId, String newId) {
-        validatePermission(android.Manifest.permission.ASEC_RENAME);
-        waitForReady();
-        warnOnNotMounted();
-
-        synchronized (mAsecMountSet) {
-            /*
-             * Because a mounted container has active internal state which cannot be
-             * changed while active, we must ensure both ids are not currently mounted.
-             */
-            if (mAsecMountSet.contains(oldId) || mAsecMountSet.contains(newId)) {
-                return StorageResultCode.OperationFailedStorageMounted;
-            }
-        }
-
-        int rc = StorageResultCode.OperationSucceeded;
-        try {
-            mConnector.execute("asec", "rename", oldId, newId);
-        } catch (NativeDaemonConnectorException e) {
-            rc = StorageResultCode.OperationFailedInternalError;
-        }
-
-        return rc;
-    }
-
-    public String getSecureContainerPath(String id) {
-        validatePermission(android.Manifest.permission.ASEC_ACCESS);
-        waitForReady();
-        warnOnNotMounted();
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("asec", "path", id);
-            event.checkCode(VoldResponseCode.AsecPathResult);
-            return event.getMessage();
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedStorageNotFound) {
-                Slog.i(TAG, String.format("Container '%s' not found", id));
-                return null;
-            } else {
-                throw new IllegalStateException(String.format("Unexpected response code %d", code));
-            }
-        }
-    }
-
-    public String getSecureContainerFilesystemPath(String id) {
-        validatePermission(android.Manifest.permission.ASEC_ACCESS);
-        waitForReady();
-        warnOnNotMounted();
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("asec", "fspath", id);
-            event.checkCode(VoldResponseCode.AsecPathResult);
-            return event.getMessage();
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedStorageNotFound) {
-                Slog.i(TAG, String.format("Container '%s' not found", id));
-                return null;
-            } else {
-                throw new IllegalStateException(String.format("Unexpected response code %d", code));
-            }
-        }
-    }
-
-    public void finishMediaUpdate() {
-        mHandler.sendEmptyMessage(H_UNMOUNT_PM_DONE);
-    }
-
-    private boolean isUidOwnerOfPackageOrSystem(String packageName, int callerUid) {
-        if (callerUid == android.os.Process.SYSTEM_UID) {
-            return true;
-        }
-
-        if (packageName == null) {
-            return false;
-        }
-
-        final int packageUid = mPms.getPackageUid(packageName, UserHandle.getUserId(callerUid));
-
-        if (DEBUG_OBB) {
-            Slog.d(TAG, "packageName = " + packageName + ", packageUid = " +
-                    packageUid + ", callerUid = " + callerUid);
-        }
-
-        return callerUid == packageUid;
-    }
-
-    public String getMountedObbPath(String rawPath) {
-        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
-
-        waitForReady();
-        warnOnNotMounted();
-
-        final ObbState state;
-        synchronized (mObbPathToStateMap) {
-            state = mObbPathToStateMap.get(rawPath);
-        }
-        if (state == null) {
-            Slog.w(TAG, "Failed to find OBB mounted at " + rawPath);
-            return null;
-        }
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("obb", "path", state.voldPath);
-            event.checkCode(VoldResponseCode.AsecPathResult);
-            return event.getMessage();
-        } catch (NativeDaemonConnectorException e) {
-            int code = e.getCode();
-            if (code == VoldResponseCode.OpFailedStorageNotFound) {
-                return null;
-            } else {
-                throw new IllegalStateException(String.format("Unexpected response code %d", code));
-            }
-        }
-    }
-
-    @Override
-    public boolean isObbMounted(String rawPath) {
-        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
-        synchronized (mObbMounts) {
-            return mObbPathToStateMap.containsKey(rawPath);
-        }
-    }
-
-    @Override
-    public void mountObb(
-            String rawPath, String canonicalPath, String key, IObbActionListener token, int nonce) {
-        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
-        Preconditions.checkNotNull(canonicalPath, "canonicalPath cannot be null");
-        Preconditions.checkNotNull(token, "token cannot be null");
-
-        final int callingUid = Binder.getCallingUid();
-        final ObbState obbState = new ObbState(rawPath, canonicalPath, callingUid, token, nonce);
-        final ObbAction action = new MountObbAction(obbState, key, callingUid);
-        mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));
-
-        if (DEBUG_OBB)
-            Slog.i(TAG, "Send to OBB handler: " + action.toString());
-    }
-
-    @Override
-    public void unmountObb(String rawPath, boolean force, IObbActionListener token, int nonce) {
-        Preconditions.checkNotNull(rawPath, "rawPath cannot be null");
-
-        final ObbState existingState;
-        synchronized (mObbPathToStateMap) {
-            existingState = mObbPathToStateMap.get(rawPath);
-        }
-
-        if (existingState != null) {
-            // TODO: separate state object from request data
-            final int callingUid = Binder.getCallingUid();
-            final ObbState newState = new ObbState(
-                    rawPath, existingState.canonicalPath, callingUid, token, nonce);
-            final ObbAction action = new UnmountObbAction(newState, force);
-            mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_RUN_ACTION, action));
-
-            if (DEBUG_OBB)
-                Slog.i(TAG, "Send to OBB handler: " + action.toString());
-        } else {
-            Slog.w(TAG, "Unknown OBB mount at " + rawPath);
-        }
-    }
-
-    @Override
-    public int getEncryptionState() {
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
-                "no permission to access the crypt keeper");
-
-        waitForReady();
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("cryptfs", "cryptocomplete");
-            return Integer.parseInt(event.getMessage());
-        } catch (NumberFormatException e) {
-            // Bad result - unexpected.
-            Slog.w(TAG, "Unable to parse result from cryptfs cryptocomplete");
-            return ENCRYPTION_STATE_ERROR_UNKNOWN;
-        } catch (NativeDaemonConnectorException e) {
-            // Something bad happened.
-            Slog.w(TAG, "Error in communicating with cryptfs in validating");
-            return ENCRYPTION_STATE_ERROR_UNKNOWN;
-        }
-    }
-
-    @Override
-    public int decryptStorage(String password) {
-        if (TextUtils.isEmpty(password)) {
-            throw new IllegalArgumentException("password cannot be empty");
-        }
-
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
-                "no permission to access the crypt keeper");
-
-        waitForReady();
-
-        if (DEBUG_EVENTS) {
-            Slog.i(TAG, "decrypting storage...");
-        }
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("cryptfs", "checkpw", new SensitiveArg(password));
-
-            final int code = Integer.parseInt(event.getMessage());
-            if (code == 0) {
-                // Decrypt was successful. Post a delayed message before restarting in order
-                // to let the UI to clear itself
-                mHandler.postDelayed(new Runnable() {
-                    public void run() {
-                        try {
-                            mConnector.execute("cryptfs", "restart");
-                        } catch (NativeDaemonConnectorException e) {
-                            Slog.e(TAG, "problem executing in background", e);
-                        }
-                    }
-                }, 1000); // 1 second
-            }
-
-            return code;
-        } catch (NativeDaemonConnectorException e) {
-            // Decryption failed
-            return e.getCode();
-        }
-    }
-
-    public int encryptStorage(String password) {
-        if (TextUtils.isEmpty(password)) {
-            throw new IllegalArgumentException("password cannot be empty");
-        }
-
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
-            "no permission to access the crypt keeper");
-
-        waitForReady();
-
-        if (DEBUG_EVENTS) {
-            Slog.i(TAG, "encrypting storage...");
-        }
-
-        try {
-            mConnector.execute("cryptfs", "enablecrypto", "inplace", new SensitiveArg(password));
-        } catch (NativeDaemonConnectorException e) {
-            // Encryption failed
-            return e.getCode();
-        }
-
-        return 0;
-    }
-
-    public int changeEncryptionPassword(String password) {
-        if (TextUtils.isEmpty(password)) {
-            throw new IllegalArgumentException("password cannot be empty");
-        }
-
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
-            "no permission to access the crypt keeper");
-
-        waitForReady();
-
-        if (DEBUG_EVENTS) {
-            Slog.i(TAG, "changing encryption password...");
-        }
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("cryptfs", "changepw", new SensitiveArg(password));
-            return Integer.parseInt(event.getMessage());
-        } catch (NativeDaemonConnectorException e) {
-            // Encryption failed
-            return e.getCode();
-        }
-    }
-
-    /**
-     * Validate a user-supplied password string with cryptfs
-     */
-    @Override
-    public int verifyEncryptionPassword(String password) throws RemoteException {
-        // Only the system process is permitted to validate passwords
-        if (Binder.getCallingUid() != android.os.Process.SYSTEM_UID) {
-            throw new SecurityException("no permission to access the crypt keeper");
-        }
-
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CRYPT_KEEPER,
-            "no permission to access the crypt keeper");
-
-        if (TextUtils.isEmpty(password)) {
-            throw new IllegalArgumentException("password cannot be empty");
-        }
-
-        waitForReady();
-
-        if (DEBUG_EVENTS) {
-            Slog.i(TAG, "validating encryption password...");
-        }
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("cryptfs", "verifypw", new SensitiveArg(password));
-            Slog.i(TAG, "cryptfs verifypw => " + event.getMessage());
-            return Integer.parseInt(event.getMessage());
-        } catch (NativeDaemonConnectorException e) {
-            // Encryption failed
-            return e.getCode();
-        }
-    }
-
-    @Override
-    public int mkdirs(String callingPkg, String appPath) {
-        final int userId = UserHandle.getUserId(Binder.getCallingUid());
-        final UserEnvironment userEnv = new UserEnvironment(userId);
-
-        // Validate that reported package name belongs to caller
-        final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(
-                Context.APP_OPS_SERVICE);
-        appOps.checkPackage(Binder.getCallingUid(), callingPkg);
-
-        try {
-            appPath = new File(appPath).getCanonicalPath();
-        } catch (IOException e) {
-            Slog.e(TAG, "Failed to resolve " + appPath + ": " + e);
-            return -1;
-        }
-
-        if (!appPath.endsWith("/")) {
-            appPath = appPath + "/";
-        }
-
-        // Try translating the app path into a vold path, but require that it
-        // belong to the calling package.
-        String voldPath = maybeTranslatePathForVold(appPath,
-                userEnv.buildExternalStorageAppDataDirs(callingPkg),
-                userEnv.buildExternalStorageAppDataDirsForVold(callingPkg));
-        if (voldPath != null) {
-            try {
-                mConnector.execute("volume", "mkdirs", voldPath);
-                return 0;
-            } catch (NativeDaemonConnectorException e) {
-                return e.getCode();
-            }
-        }
-
-        voldPath = maybeTranslatePathForVold(appPath,
-                userEnv.buildExternalStorageAppObbDirs(callingPkg),
-                userEnv.buildExternalStorageAppObbDirsForVold(callingPkg));
-        if (voldPath != null) {
-            try {
-                mConnector.execute("volume", "mkdirs", voldPath);
-                return 0;
-            } catch (NativeDaemonConnectorException e) {
-                return e.getCode();
-            }
-        }
-
-        throw new SecurityException("Invalid mkdirs path: " + appPath);
-    }
-
-    /**
-     * Translate the given path from an app-visible path to a vold-visible path,
-     * but only if it's under the given whitelisted paths.
-     *
-     * @param path a canonicalized app-visible path.
-     * @param appPaths list of app-visible paths that are allowed.
-     * @param voldPaths list of vold-visible paths directly corresponding to the
-     *            allowed app-visible paths argument.
-     * @return a vold-visible path representing the original path, or
-     *         {@code null} if the given path didn't have an app-to-vold
-     *         mapping.
-     */
-    @VisibleForTesting
-    public static String maybeTranslatePathForVold(
-            String path, File[] appPaths, File[] voldPaths) {
-        if (appPaths.length != voldPaths.length) {
-            throw new IllegalStateException("Paths must be 1:1 mapping");
-        }
-
-        for (int i = 0; i < appPaths.length; i++) {
-            final String appPath = appPaths[i].getAbsolutePath() + "/";
-            if (path.startsWith(appPath)) {
-                path = new File(voldPaths[i], path.substring(appPath.length()))
-                        .getAbsolutePath();
-                if (!path.endsWith("/")) {
-                    path = path + "/";
-                }
-                return path;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public StorageVolume[] getVolumeList() {
-        final int callingUserId = UserHandle.getCallingUserId();
-        final boolean accessAll = (mContext.checkPermission(
-                android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
-                Binder.getCallingPid(), Binder.getCallingUid()) == PERMISSION_GRANTED);
-
-        synchronized (mVolumesLock) {
-            final ArrayList<StorageVolume> filtered = Lists.newArrayList();
-            for (StorageVolume volume : mVolumes) {
-                final UserHandle owner = volume.getOwner();
-                final boolean ownerMatch = owner == null || owner.getIdentifier() == callingUserId;
-                if (accessAll || ownerMatch) {
-                    filtered.add(volume);
-                }
-            }
-            return filtered.toArray(new StorageVolume[filtered.size()]);
-        }
-    }
-
-    private void addObbStateLocked(ObbState obbState) throws RemoteException {
-        final IBinder binder = obbState.getBinder();
-        List<ObbState> obbStates = mObbMounts.get(binder);
-
-        if (obbStates == null) {
-            obbStates = new ArrayList<ObbState>();
-            mObbMounts.put(binder, obbStates);
-        } else {
-            for (final ObbState o : obbStates) {
-                if (o.rawPath.equals(obbState.rawPath)) {
-                    throw new IllegalStateException("Attempt to add ObbState twice. "
-                            + "This indicates an error in the MountService logic.");
-                }
-            }
-        }
-
-        obbStates.add(obbState);
-        try {
-            obbState.link();
-        } catch (RemoteException e) {
-            /*
-             * The binder died before we could link it, so clean up our state
-             * and return failure.
-             */
-            obbStates.remove(obbState);
-            if (obbStates.isEmpty()) {
-                mObbMounts.remove(binder);
-            }
-
-            // Rethrow the error so mountObb can get it
-            throw e;
-        }
-
-        mObbPathToStateMap.put(obbState.rawPath, obbState);
-    }
-
-    private void removeObbStateLocked(ObbState obbState) {
-        final IBinder binder = obbState.getBinder();
-        final List<ObbState> obbStates = mObbMounts.get(binder);
-        if (obbStates != null) {
-            if (obbStates.remove(obbState)) {
-                obbState.unlink();
-            }
-            if (obbStates.isEmpty()) {
-                mObbMounts.remove(binder);
-            }
-        }
-
-        mObbPathToStateMap.remove(obbState.rawPath);
-    }
-
-    private class ObbActionHandler extends Handler {
-        private boolean mBound = false;
-        private final List<ObbAction> mActions = new LinkedList<ObbAction>();
-
-        ObbActionHandler(Looper l) {
-            super(l);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case OBB_RUN_ACTION: {
-                    final ObbAction action = (ObbAction) msg.obj;
-
-                    if (DEBUG_OBB)
-                        Slog.i(TAG, "OBB_RUN_ACTION: " + action.toString());
-
-                    // If a bind was already initiated we don't really
-                    // need to do anything. The pending install
-                    // will be processed later on.
-                    if (!mBound) {
-                        // If this is the only one pending we might
-                        // have to bind to the service again.
-                        if (!connectToService()) {
-                            Slog.e(TAG, "Failed to bind to media container service");
-                            action.handleError();
-                            return;
-                        }
-                    }
-
-                    mActions.add(action);
-                    break;
-                }
-                case OBB_MCS_BOUND: {
-                    if (DEBUG_OBB)
-                        Slog.i(TAG, "OBB_MCS_BOUND");
-                    if (msg.obj != null) {
-                        mContainerService = (IMediaContainerService) msg.obj;
-                    }
-                    if (mContainerService == null) {
-                        // Something seriously wrong. Bail out
-                        Slog.e(TAG, "Cannot bind to media container service");
-                        for (ObbAction action : mActions) {
-                            // Indicate service bind error
-                            action.handleError();
-                        }
-                        mActions.clear();
-                    } else if (mActions.size() > 0) {
-                        final ObbAction action = mActions.get(0);
-                        if (action != null) {
-                            action.execute(this);
-                        }
-                    } else {
-                        // Should never happen ideally.
-                        Slog.w(TAG, "Empty queue");
-                    }
-                    break;
-                }
-                case OBB_MCS_RECONNECT: {
-                    if (DEBUG_OBB)
-                        Slog.i(TAG, "OBB_MCS_RECONNECT");
-                    if (mActions.size() > 0) {
-                        if (mBound) {
-                            disconnectService();
-                        }
-                        if (!connectToService()) {
-                            Slog.e(TAG, "Failed to bind to media container service");
-                            for (ObbAction action : mActions) {
-                                // Indicate service bind error
-                                action.handleError();
-                            }
-                            mActions.clear();
-                        }
-                    }
-                    break;
-                }
-                case OBB_MCS_UNBIND: {
-                    if (DEBUG_OBB)
-                        Slog.i(TAG, "OBB_MCS_UNBIND");
-
-                    // Delete pending install
-                    if (mActions.size() > 0) {
-                        mActions.remove(0);
-                    }
-                    if (mActions.size() == 0) {
-                        if (mBound) {
-                            disconnectService();
-                        }
-                    } else {
-                        // There are more pending requests in queue.
-                        // Just post MCS_BOUND message to trigger processing
-                        // of next pending install.
-                        mObbActionHandler.sendEmptyMessage(OBB_MCS_BOUND);
-                    }
-                    break;
-                }
-                case OBB_FLUSH_MOUNT_STATE: {
-                    final String path = (String) msg.obj;
-
-                    if (DEBUG_OBB)
-                        Slog.i(TAG, "Flushing all OBB state for path " + path);
-
-                    synchronized (mObbMounts) {
-                        final List<ObbState> obbStatesToRemove = new LinkedList<ObbState>();
-
-                        final Iterator<ObbState> i = mObbPathToStateMap.values().iterator();
-                        while (i.hasNext()) {
-                            final ObbState state = i.next();
-
-                            /*
-                             * If this entry's source file is in the volume path
-                             * that got unmounted, remove it because it's no
-                             * longer valid.
-                             */
-                            if (state.canonicalPath.startsWith(path)) {
-                                obbStatesToRemove.add(state);
-                            }
-                        }
-
-                        for (final ObbState obbState : obbStatesToRemove) {
-                            if (DEBUG_OBB)
-                                Slog.i(TAG, "Removing state for " + obbState.rawPath);
-
-                            removeObbStateLocked(obbState);
-
-                            try {
-                                obbState.token.onObbResult(obbState.rawPath, obbState.nonce,
-                                        OnObbStateChangeListener.UNMOUNTED);
-                            } catch (RemoteException e) {
-                                Slog.i(TAG, "Couldn't send unmount notification for  OBB: "
-                                        + obbState.rawPath);
-                            }
-                        }
-                    }
-                    break;
-                }
-            }
-        }
-
-        private boolean connectToService() {
-            if (DEBUG_OBB)
-                Slog.i(TAG, "Trying to bind to DefaultContainerService");
-
-            Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
-            if (mContext.bindService(service, mDefContainerConn, Context.BIND_AUTO_CREATE)) {
-                mBound = true;
-                return true;
-            }
-            return false;
-        }
-
-        private void disconnectService() {
-            mContainerService = null;
-            mBound = false;
-            mContext.unbindService(mDefContainerConn);
-        }
-    }
-
-    abstract class ObbAction {
-        private static final int MAX_RETRIES = 3;
-        private int mRetries;
-
-        ObbState mObbState;
-
-        ObbAction(ObbState obbState) {
-            mObbState = obbState;
-        }
-
-        public void execute(ObbActionHandler handler) {
-            try {
-                if (DEBUG_OBB)
-                    Slog.i(TAG, "Starting to execute action: " + toString());
-                mRetries++;
-                if (mRetries > MAX_RETRIES) {
-                    Slog.w(TAG, "Failed to invoke remote methods on default container service. Giving up");
-                    mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND);
-                    handleError();
-                    return;
-                } else {
-                    handleExecute();
-                    if (DEBUG_OBB)
-                        Slog.i(TAG, "Posting install MCS_UNBIND");
-                    mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND);
-                }
-            } catch (RemoteException e) {
-                if (DEBUG_OBB)
-                    Slog.i(TAG, "Posting install MCS_RECONNECT");
-                mObbActionHandler.sendEmptyMessage(OBB_MCS_RECONNECT);
-            } catch (Exception e) {
-                if (DEBUG_OBB)
-                    Slog.d(TAG, "Error handling OBB action", e);
-                handleError();
-                mObbActionHandler.sendEmptyMessage(OBB_MCS_UNBIND);
-            }
-        }
-
-        abstract void handleExecute() throws RemoteException, IOException;
-        abstract void handleError();
-
-        protected ObbInfo getObbInfo() throws IOException {
-            ObbInfo obbInfo;
-            try {
-                obbInfo = mContainerService.getObbInfo(mObbState.ownerPath);
-            } catch (RemoteException e) {
-                Slog.d(TAG, "Couldn't call DefaultContainerService to fetch OBB info for "
-                        + mObbState.ownerPath);
-                obbInfo = null;
-            }
-            if (obbInfo == null) {
-                throw new IOException("Couldn't read OBB file: " + mObbState.ownerPath);
-            }
-            return obbInfo;
-        }
-
-        protected void sendNewStatusOrIgnore(int status) {
-            if (mObbState == null || mObbState.token == null) {
-                return;
-            }
-
-            try {
-                mObbState.token.onObbResult(mObbState.rawPath, mObbState.nonce, status);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "MountServiceListener went away while calling onObbStateChanged");
-            }
-        }
-    }
-
-    class MountObbAction extends ObbAction {
-        private final String mKey;
-        private final int mCallingUid;
-
-        MountObbAction(ObbState obbState, String key, int callingUid) {
-            super(obbState);
-            mKey = key;
-            mCallingUid = callingUid;
-        }
-
-        @Override
-        public void handleExecute() throws IOException, RemoteException {
-            waitForReady();
-            warnOnNotMounted();
-
-            final ObbInfo obbInfo = getObbInfo();
-
-            if (!isUidOwnerOfPackageOrSystem(obbInfo.packageName, mCallingUid)) {
-                Slog.w(TAG, "Denied attempt to mount OBB " + obbInfo.filename
-                        + " which is owned by " + obbInfo.packageName);
-                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
-                return;
-            }
-
-            final boolean isMounted;
-            synchronized (mObbMounts) {
-                isMounted = mObbPathToStateMap.containsKey(mObbState.rawPath);
-            }
-            if (isMounted) {
-                Slog.w(TAG, "Attempt to mount OBB which is already mounted: " + obbInfo.filename);
-                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_ALREADY_MOUNTED);
-                return;
-            }
-
-            final String hashedKey;
-            if (mKey == null) {
-                hashedKey = "none";
-            } else {
-                try {
-                    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
-
-                    KeySpec ks = new PBEKeySpec(mKey.toCharArray(), obbInfo.salt,
-                            PBKDF2_HASH_ROUNDS, CRYPTO_ALGORITHM_KEY_SIZE);
-                    SecretKey key = factory.generateSecret(ks);
-                    BigInteger bi = new BigInteger(key.getEncoded());
-                    hashedKey = bi.toString(16);
-                } catch (NoSuchAlgorithmException e) {
-                    Slog.e(TAG, "Could not load PBKDF2 algorithm", e);
-                    sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
-                    return;
-                } catch (InvalidKeySpecException e) {
-                    Slog.e(TAG, "Invalid key spec when loading PBKDF2 algorithm", e);
-                    sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
-                    return;
-                }
-            }
-
-            int rc = StorageResultCode.OperationSucceeded;
-            try {
-                mConnector.execute("obb", "mount", mObbState.voldPath, new SensitiveArg(hashedKey),
-                        mObbState.ownerGid);
-            } catch (NativeDaemonConnectorException e) {
-                int code = e.getCode();
-                if (code != VoldResponseCode.OpFailedStorageBusy) {
-                    rc = StorageResultCode.OperationFailedInternalError;
-                }
-            }
-
-            if (rc == StorageResultCode.OperationSucceeded) {
-                if (DEBUG_OBB)
-                    Slog.d(TAG, "Successfully mounted OBB " + mObbState.voldPath);
-
-                synchronized (mObbMounts) {
-                    addObbStateLocked(mObbState);
-                }
-
-                sendNewStatusOrIgnore(OnObbStateChangeListener.MOUNTED);
-            } else {
-                Slog.e(TAG, "Couldn't mount OBB file: " + rc);
-
-                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_COULD_NOT_MOUNT);
-            }
-        }
-
-        @Override
-        public void handleError() {
-            sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder();
-            sb.append("MountObbAction{");
-            sb.append(mObbState);
-            sb.append('}');
-            return sb.toString();
-        }
-    }
-
-    class UnmountObbAction extends ObbAction {
-        private final boolean mForceUnmount;
-
-        UnmountObbAction(ObbState obbState, boolean force) {
-            super(obbState);
-            mForceUnmount = force;
-        }
-
-        @Override
-        public void handleExecute() throws IOException {
-            waitForReady();
-            warnOnNotMounted();
-
-            final ObbInfo obbInfo = getObbInfo();
-
-            final ObbState existingState;
-            synchronized (mObbMounts) {
-                existingState = mObbPathToStateMap.get(mObbState.rawPath);
-            }
-
-            if (existingState == null) {
-                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_NOT_MOUNTED);
-                return;
-            }
-
-            if (existingState.ownerGid != mObbState.ownerGid) {
-                Slog.w(TAG, "Permission denied attempting to unmount OBB " + existingState.rawPath
-                        + " (owned by GID " + existingState.ownerGid + ")");
-                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_PERMISSION_DENIED);
-                return;
-            }
-
-            int rc = StorageResultCode.OperationSucceeded;
-            try {
-                final Command cmd = new Command("obb", "unmount", mObbState.voldPath);
-                if (mForceUnmount) {
-                    cmd.appendArg("force");
-                }
-                mConnector.execute(cmd);
-            } catch (NativeDaemonConnectorException e) {
-                int code = e.getCode();
-                if (code == VoldResponseCode.OpFailedStorageBusy) {
-                    rc = StorageResultCode.OperationFailedStorageBusy;
-                } else if (code == VoldResponseCode.OpFailedStorageNotFound) {
-                    // If it's not mounted then we've already won.
-                    rc = StorageResultCode.OperationSucceeded;
-                } else {
-                    rc = StorageResultCode.OperationFailedInternalError;
-                }
-            }
-
-            if (rc == StorageResultCode.OperationSucceeded) {
-                synchronized (mObbMounts) {
-                    removeObbStateLocked(existingState);
-                }
-
-                sendNewStatusOrIgnore(OnObbStateChangeListener.UNMOUNTED);
-            } else {
-                Slog.w(TAG, "Could not unmount OBB: " + existingState);
-                sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_COULD_NOT_UNMOUNT);
-            }
-        }
-
-        @Override
-        public void handleError() {
-            sendNewStatusOrIgnore(OnObbStateChangeListener.ERROR_INTERNAL);
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder();
-            sb.append("UnmountObbAction{");
-            sb.append(mObbState);
-            sb.append(",force=");
-            sb.append(mForceUnmount);
-            sb.append('}');
-            return sb.toString();
-        }
-    }
-
-    @VisibleForTesting
-    public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) {
-        // TODO: allow caller to provide Environment for full testing
-        // TODO: extend to support OBB mounts on secondary external storage
-
-        // Only adjust paths when storage is emulated
-        if (!Environment.isExternalStorageEmulated()) {
-            return canonicalPath;
-        }
-
-        String path = canonicalPath.toString();
-
-        // First trim off any external storage prefix
-        final UserEnvironment userEnv = new UserEnvironment(userId);
-
-        // /storage/emulated/0
-        final String externalPath = userEnv.getExternalStorageDirectory().getAbsolutePath();
-        // /storage/emulated_legacy
-        final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory()
-                .getAbsolutePath();
-
-        if (path.startsWith(externalPath)) {
-            path = path.substring(externalPath.length() + 1);
-        } else if (path.startsWith(legacyExternalPath)) {
-            path = path.substring(legacyExternalPath.length() + 1);
-        } else {
-            return canonicalPath;
-        }
-
-        // Handle special OBB paths on emulated storage
-        final String obbPath = "Android/obb";
-        if (path.startsWith(obbPath)) {
-            path = path.substring(obbPath.length() + 1);
-
-            if (forVold) {
-                return new File(Environment.getEmulatedStorageObbSource(), path).getAbsolutePath();
-            } else {
-                final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER);
-                return new File(ownerEnv.buildExternalStorageAndroidObbDirs()[0], path)
-                        .getAbsolutePath();
-            }
-        }
-
-        // Handle normal external storage paths
-        if (forVold) {
-            return new File(Environment.getEmulatedStorageSource(userId), path).getAbsolutePath();
-        } else {
-            return new File(userEnv.getExternalDirsForApp()[0], path).getAbsolutePath();
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
-
-        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ", 160);
-
-        synchronized (mObbMounts) {
-            pw.println("mObbMounts:");
-            pw.increaseIndent();
-            final Iterator<Entry<IBinder, List<ObbState>>> binders = mObbMounts.entrySet()
-                    .iterator();
-            while (binders.hasNext()) {
-                Entry<IBinder, List<ObbState>> e = binders.next();
-                pw.println(e.getKey() + ":");
-                pw.increaseIndent();
-                final List<ObbState> obbStates = e.getValue();
-                for (final ObbState obbState : obbStates) {
-                    pw.println(obbState);
-                }
-                pw.decreaseIndent();
-            }
-            pw.decreaseIndent();
-
-            pw.println();
-            pw.println("mObbPathToStateMap:");
-            pw.increaseIndent();
-            final Iterator<Entry<String, ObbState>> maps = mObbPathToStateMap.entrySet().iterator();
-            while (maps.hasNext()) {
-                final Entry<String, ObbState> e = maps.next();
-                pw.print(e.getKey());
-                pw.print(" -> ");
-                pw.println(e.getValue());
-            }
-            pw.decreaseIndent();
-        }
-
-        synchronized (mVolumesLock) {
-            pw.println();
-            pw.println("mVolumes:");
-            pw.increaseIndent();
-            for (StorageVolume volume : mVolumes) {
-                pw.println(volume);
-                pw.increaseIndent();
-                pw.println("Current state: " + mVolumeStates.get(volume.getPath()));
-                pw.decreaseIndent();
-            }
-            pw.decreaseIndent();
-        }
-
-        pw.println();
-        pw.println("mConnection:");
-        pw.increaseIndent();
-        mConnector.dump(fd, pw, args);
-        pw.decreaseIndent();
-    }
-
-    /** {@inheritDoc} */
-    public void monitor() {
-        if (mConnector != null) {
-            mConnector.monitor();
-        }
-    }
-}
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
deleted file mode 100644
index 92f99c2..0000000
--- a/services/java/com/android/server/NetworkManagementService.java
+++ /dev/null
@@ -1,1776 +0,0 @@
-/*
- * Copyright (C) 2007 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;
-
-import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
-import static android.Manifest.permission.DUMP;
-import static android.Manifest.permission.SHUTDOWN;
-import static android.net.NetworkStats.SET_DEFAULT;
-import static android.net.NetworkStats.TAG_NONE;
-import static android.net.NetworkStats.UID_ALL;
-import static android.net.TrafficStats.UID_TETHERING;
-import static com.android.server.NetworkManagementService.NetdResponseCode.ClatdStatusResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.GetMarkResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceGetCfgResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.InterfaceListResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.IpFwdStatusResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.TetherDnsFwdTgtListResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.TetherInterfaceListResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.TetherStatusResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.TetheringStatsListResult;
-import static com.android.server.NetworkManagementService.NetdResponseCode.TtyListResult;
-import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED;
-
-import android.content.Context;
-import android.net.INetworkManagementEventObserver;
-import android.net.InterfaceConfiguration;
-import android.net.LinkAddress;
-import android.net.NetworkStats;
-import android.net.NetworkUtils;
-import android.net.RouteInfo;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiConfiguration.KeyMgmt;
-import android.os.BatteryStats;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.INetworkManagementService;
-import android.os.Process;
-import android.os.RemoteCallbackList;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseBooleanArray;
-
-import com.android.internal.app.IBatteryStats;
-import com.android.internal.net.NetworkStatsFactory;
-import com.android.internal.util.Preconditions;
-import com.android.server.NativeDaemonConnector.Command;
-import com.android.server.NativeDaemonConnector.SensitiveArg;
-import com.android.server.net.LockdownVpnTracker;
-import com.google.android.collect.Maps;
-
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.net.InterfaceAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.StringTokenizer;
-import java.util.concurrent.CountDownLatch;
-
-/**
- * @hide
- */
-public class NetworkManagementService extends INetworkManagementService.Stub
-        implements Watchdog.Monitor {
-    private static final String TAG = "NetworkManagementService";
-    private static final boolean DBG = false;
-    private static final String NETD_TAG = "NetdConnector";
-    private static final String NETD_SOCKET_NAME = "netd";
-
-    private static final String ADD = "add";
-    private static final String REMOVE = "remove";
-
-    private static final String ALLOW = "allow";
-    private static final String DENY = "deny";
-
-    private static final String DEFAULT = "default";
-    private static final String SECONDARY = "secondary";
-
-    /**
-     * Name representing {@link #setGlobalAlert(long)} limit when delivered to
-     * {@link INetworkManagementEventObserver#limitReached(String, String)}.
-     */
-    public static final String LIMIT_GLOBAL_ALERT = "globalAlert";
-
-    class NetdResponseCode {
-        /* Keep in sync with system/netd/ResponseCode.h */
-        public static final int InterfaceListResult       = 110;
-        public static final int TetherInterfaceListResult = 111;
-        public static final int TetherDnsFwdTgtListResult = 112;
-        public static final int TtyListResult             = 113;
-        public static final int TetheringStatsListResult  = 114;
-
-        public static final int TetherStatusResult        = 210;
-        public static final int IpFwdStatusResult         = 211;
-        public static final int InterfaceGetCfgResult     = 213;
-        public static final int SoftapStatusResult        = 214;
-        public static final int InterfaceRxCounterResult  = 216;
-        public static final int InterfaceTxCounterResult  = 217;
-        public static final int QuotaCounterResult        = 220;
-        public static final int TetheringStatsResult      = 221;
-        public static final int DnsProxyQueryResult       = 222;
-        public static final int ClatdStatusResult         = 223;
-        public static final int GetMarkResult             = 225;
-
-        public static final int InterfaceChange           = 600;
-        public static final int BandwidthControl          = 601;
-        public static final int InterfaceClassActivity    = 613;
-        public static final int InterfaceAddressChange    = 614;
-    }
-
-    /**
-     * Binder context for this service
-     */
-    private Context mContext;
-
-    /**
-     * connector object for communicating with netd
-     */
-    private NativeDaemonConnector mConnector;
-
-    private final Handler mMainHandler = new Handler();
-
-    private Thread mThread;
-    private CountDownLatch mConnectedSignal = new CountDownLatch(1);
-
-    private final RemoteCallbackList<INetworkManagementEventObserver> mObservers =
-            new RemoteCallbackList<INetworkManagementEventObserver>();
-
-    private final NetworkStatsFactory mStatsFactory = new NetworkStatsFactory();
-
-    private Object mQuotaLock = new Object();
-    /** Set of interfaces with active quotas. */
-    private HashMap<String, Long> mActiveQuotas = Maps.newHashMap();
-    /** Set of interfaces with active alerts. */
-    private HashMap<String, Long> mActiveAlerts = Maps.newHashMap();
-    /** Set of UIDs with active reject rules. */
-    private SparseBooleanArray mUidRejectOnQuota = new SparseBooleanArray();
-
-    private Object mIdleTimerLock = new Object();
-    /** Set of interfaces with active idle timers. */
-    private static class IdleTimerParams {
-        public final int timeout;
-        public final String label;
-        public int networkCount;
-
-        IdleTimerParams(int timeout, String label) {
-            this.timeout = timeout;
-            this.label = label;
-            this.networkCount = 1;
-        }
-    }
-    private HashMap<String, IdleTimerParams> mActiveIdleTimers = Maps.newHashMap();
-
-    private volatile boolean mBandwidthControlEnabled;
-    private volatile boolean mFirewallEnabled;
-
-    /**
-     * Constructs a new NetworkManagementService instance
-     *
-     * @param context  Binder context for this service
-     */
-    private NetworkManagementService(Context context, String socket) {
-        mContext = context;
-
-        if ("simulator".equals(SystemProperties.get("ro.product.device"))) {
-            return;
-        }
-
-        mConnector = new NativeDaemonConnector(
-                new NetdCallbackReceiver(), socket, 10, NETD_TAG, 160);
-        mThread = new Thread(mConnector, NETD_TAG);
-
-        // Add ourself to the Watchdog monitors.
-        Watchdog.getInstance().addMonitor(this);
-    }
-
-    static NetworkManagementService create(Context context,
-            String socket) throws InterruptedException {
-        final NetworkManagementService service = new NetworkManagementService(context, socket);
-        final CountDownLatch connectedSignal = service.mConnectedSignal;
-        if (DBG) Slog.d(TAG, "Creating NetworkManagementService");
-        service.mThread.start();
-        if (DBG) Slog.d(TAG, "Awaiting socket connection");
-        connectedSignal.await();
-        if (DBG) Slog.d(TAG, "Connected");
-        return service;
-    }
-
-    public static NetworkManagementService create(Context context) throws InterruptedException {
-        return create(context, NETD_SOCKET_NAME);
-    }
-
-    public void systemReady() {
-        prepareNativeDaemon();
-        if (DBG) Slog.d(TAG, "Prepared");
-    }
-
-    @Override
-    public void registerObserver(INetworkManagementEventObserver observer) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        mObservers.register(observer);
-    }
-
-    @Override
-    public void unregisterObserver(INetworkManagementEventObserver observer) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        mObservers.unregister(observer);
-    }
-
-    /**
-     * Notify our observers of an interface status change
-     */
-    private void notifyInterfaceStatusChanged(String iface, boolean up) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).interfaceStatusChanged(iface, up);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Notify our observers of an interface link state change
-     * (typically, an Ethernet cable has been plugged-in or unplugged).
-     */
-    private void notifyInterfaceLinkStateChanged(String iface, boolean up) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).interfaceLinkStateChanged(iface, up);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Notify our observers of an interface addition.
-     */
-    private void notifyInterfaceAdded(String iface) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).interfaceAdded(iface);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Notify our observers of an interface removal.
-     */
-    private void notifyInterfaceRemoved(String iface) {
-        // netd already clears out quota and alerts for removed ifaces; update
-        // our sanity-checking state.
-        mActiveAlerts.remove(iface);
-        mActiveQuotas.remove(iface);
-
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).interfaceRemoved(iface);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Notify our observers of a limit reached.
-     */
-    private void notifyLimitReached(String limitName, String iface) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).limitReached(limitName, iface);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Notify our observers of a change in the data activity state of the interface
-     */
-    private void notifyInterfaceClassActivity(String label, boolean active) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).interfaceClassDataActivityChanged(label, active);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Prepare native daemon once connected, enabling modules and pushing any
-     * existing in-memory rules.
-     */
-    private void prepareNativeDaemon() {
-        mBandwidthControlEnabled = false;
-
-        // only enable bandwidth control when support exists
-        final boolean hasKernelSupport = new File("/proc/net/xt_qtaguid/ctrl").exists();
-        if (hasKernelSupport) {
-            Slog.d(TAG, "enabling bandwidth control");
-            try {
-                mConnector.execute("bandwidth", "enable");
-                mBandwidthControlEnabled = true;
-            } catch (NativeDaemonConnectorException e) {
-                Log.wtf(TAG, "problem enabling bandwidth controls", e);
-            }
-        } else {
-            Slog.d(TAG, "not enabling bandwidth control");
-        }
-
-        SystemProperties.set(PROP_QTAGUID_ENABLED, mBandwidthControlEnabled ? "1" : "0");
-
-        if (mBandwidthControlEnabled) {
-            try {
-                IBatteryStats.Stub.asInterface(ServiceManager.getService(BatteryStats.SERVICE_NAME))
-                        .noteNetworkStatsEnabled();
-            } catch (RemoteException e) {
-            }
-        }
-
-        // push any existing quota or UID rules
-        synchronized (mQuotaLock) {
-            int size = mActiveQuotas.size();
-            if (size > 0) {
-                Slog.d(TAG, "pushing " + size + " active quota rules");
-                final HashMap<String, Long> activeQuotas = mActiveQuotas;
-                mActiveQuotas = Maps.newHashMap();
-                for (Map.Entry<String, Long> entry : activeQuotas.entrySet()) {
-                    setInterfaceQuota(entry.getKey(), entry.getValue());
-                }
-            }
-
-            size = mActiveAlerts.size();
-            if (size > 0) {
-                Slog.d(TAG, "pushing " + size + " active alert rules");
-                final HashMap<String, Long> activeAlerts = mActiveAlerts;
-                mActiveAlerts = Maps.newHashMap();
-                for (Map.Entry<String, Long> entry : activeAlerts.entrySet()) {
-                    setInterfaceAlert(entry.getKey(), entry.getValue());
-                }
-            }
-
-            size = mUidRejectOnQuota.size();
-            if (size > 0) {
-                Slog.d(TAG, "pushing " + size + " active uid rules");
-                final SparseBooleanArray uidRejectOnQuota = mUidRejectOnQuota;
-                mUidRejectOnQuota = new SparseBooleanArray();
-                for (int i = 0; i < uidRejectOnQuota.size(); i++) {
-                    setUidNetworkRules(uidRejectOnQuota.keyAt(i), uidRejectOnQuota.valueAt(i));
-                }
-            }
-        }
-
-        // TODO: Push any existing firewall state
-        setFirewallEnabled(mFirewallEnabled || LockdownVpnTracker.isEnabled());
-    }
-
-    /**
-     * Notify our observers of a new or updated interface address.
-     */
-    private void notifyAddressUpdated(String address, String iface, int flags, int scope) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).addressUpdated(address, iface, flags, scope);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    /**
-     * Notify our observers of a deleted interface address.
-     */
-    private void notifyAddressRemoved(String address, String iface, int flags, int scope) {
-        final int length = mObservers.beginBroadcast();
-        for (int i = 0; i < length; i++) {
-            try {
-                mObservers.getBroadcastItem(i).addressRemoved(address, iface, flags, scope);
-            } catch (RemoteException e) {
-            } catch (RuntimeException e) {
-            }
-        }
-        mObservers.finishBroadcast();
-    }
-
-    //
-    // Netd Callback handling
-    //
-
-    private class NetdCallbackReceiver implements INativeDaemonConnectorCallbacks {
-        @Override
-        public void onDaemonConnected() {
-            // event is dispatched from internal NDC thread, so we prepare the
-            // daemon back on main thread.
-            if (mConnectedSignal != null) {
-                mConnectedSignal.countDown();
-                mConnectedSignal = null;
-            } else {
-                mMainHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        prepareNativeDaemon();
-                    }
-                });
-            }
-        }
-
-        @Override
-        public boolean onEvent(int code, String raw, String[] cooked) {
-            switch (code) {
-            case NetdResponseCode.InterfaceChange:
-                    /*
-                     * a network interface change occured
-                     * Format: "NNN Iface added <name>"
-                     *         "NNN Iface removed <name>"
-                     *         "NNN Iface changed <name> <up/down>"
-                     *         "NNN Iface linkstatus <name> <up/down>"
-                     */
-                    if (cooked.length < 4 || !cooked[1].equals("Iface")) {
-                        throw new IllegalStateException(
-                                String.format("Invalid event from daemon (%s)", raw));
-                    }
-                    if (cooked[2].equals("added")) {
-                        notifyInterfaceAdded(cooked[3]);
-                        return true;
-                    } else if (cooked[2].equals("removed")) {
-                        notifyInterfaceRemoved(cooked[3]);
-                        return true;
-                    } else if (cooked[2].equals("changed") && cooked.length == 5) {
-                        notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
-                        return true;
-                    } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
-                        notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
-                        return true;
-                    }
-                    throw new IllegalStateException(
-                            String.format("Invalid event from daemon (%s)", raw));
-                    // break;
-            case NetdResponseCode.BandwidthControl:
-                    /*
-                     * Bandwidth control needs some attention
-                     * Format: "NNN limit alert <alertName> <ifaceName>"
-                     */
-                    if (cooked.length < 5 || !cooked[1].equals("limit")) {
-                        throw new IllegalStateException(
-                                String.format("Invalid event from daemon (%s)", raw));
-                    }
-                    if (cooked[2].equals("alert")) {
-                        notifyLimitReached(cooked[3], cooked[4]);
-                        return true;
-                    }
-                    throw new IllegalStateException(
-                            String.format("Invalid event from daemon (%s)", raw));
-                    // break;
-            case NetdResponseCode.InterfaceClassActivity:
-                    /*
-                     * An network interface class state changed (active/idle)
-                     * Format: "NNN IfaceClass <active/idle> <label>"
-                     */
-                    if (cooked.length < 4 || !cooked[1].equals("IfaceClass")) {
-                        throw new IllegalStateException(
-                                String.format("Invalid event from daemon (%s)", raw));
-                    }
-                    boolean isActive = cooked[2].equals("active");
-                    notifyInterfaceClassActivity(cooked[3], isActive);
-                    return true;
-                    // break;
-            case NetdResponseCode.InterfaceAddressChange:
-                    /*
-                     * A network address change occurred
-                     * Format: "NNN Address updated <addr> <iface> <flags> <scope>"
-                     *         "NNN Address removed <addr> <iface> <flags> <scope>"
-                     */
-                    String msg = String.format("Invalid event from daemon (%s)", raw);
-                    if (cooked.length < 6 || !cooked[1].equals("Address")) {
-                        throw new IllegalStateException(msg);
-                    }
-
-                    int flags;
-                    int scope;
-                    try {
-                        flags = Integer.parseInt(cooked[5]);
-                        scope = Integer.parseInt(cooked[6]);
-                    } catch(NumberFormatException e) {
-                        throw new IllegalStateException(msg);
-                    }
-
-                    if (cooked[2].equals("updated")) {
-                        notifyAddressUpdated(cooked[3], cooked[4], flags, scope);
-                    } else {
-                        notifyAddressRemoved(cooked[3], cooked[4], flags, scope);
-                    }
-                    return true;
-                    // break;
-            default: break;
-            }
-            return false;
-        }
-    }
-
-
-    //
-    // INetworkManagementService members
-    //
-
-    @Override
-    public String[] listInterfaces() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return NativeDaemonEvent.filterMessageList(
-                    mConnector.executeForList("interface", "list"), InterfaceListResult);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public InterfaceConfiguration getInterfaceConfig(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("interface", "getcfg", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-
-        event.checkCode(InterfaceGetCfgResult);
-
-        // Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
-        final StringTokenizer st = new StringTokenizer(event.getMessage());
-
-        InterfaceConfiguration cfg;
-        try {
-            cfg = new InterfaceConfiguration();
-            cfg.setHardwareAddress(st.nextToken(" "));
-            InetAddress addr = null;
-            int prefixLength = 0;
-            try {
-                addr = NetworkUtils.numericToInetAddress(st.nextToken());
-            } catch (IllegalArgumentException iae) {
-                Slog.e(TAG, "Failed to parse ipaddr", iae);
-            }
-
-            try {
-                prefixLength = Integer.parseInt(st.nextToken());
-            } catch (NumberFormatException nfe) {
-                Slog.e(TAG, "Failed to parse prefixLength", nfe);
-            }
-
-            cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
-            while (st.hasMoreTokens()) {
-                cfg.setFlag(st.nextToken());
-            }
-        } catch (NoSuchElementException nsee) {
-            throw new IllegalStateException("Invalid response from daemon: " + event);
-        }
-        return cfg;
-    }
-
-    @Override
-    public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        LinkAddress linkAddr = cfg.getLinkAddress();
-        if (linkAddr == null || linkAddr.getAddress() == null) {
-            throw new IllegalStateException("Null LinkAddress given");
-        }
-
-        final Command cmd = new Command("interface", "setcfg", iface,
-                linkAddr.getAddress().getHostAddress(),
-                linkAddr.getNetworkPrefixLength());
-        for (String flag : cfg.getFlags()) {
-            cmd.appendArg(flag);
-        }
-
-        try {
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setInterfaceDown(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
-        ifcg.setInterfaceDown();
-        setInterfaceConfig(iface, ifcg);
-    }
-
-    @Override
-    public void setInterfaceUp(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        final InterfaceConfiguration ifcg = getInterfaceConfig(iface);
-        ifcg.setInterfaceUp();
-        setInterfaceConfig(iface, ifcg);
-    }
-
-    @Override
-    public void setInterfaceIpv6PrivacyExtensions(String iface, boolean enable) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute(
-                    "interface", "ipv6privacyextensions", iface, enable ? "enable" : "disable");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    /* TODO: This is right now a IPv4 only function. Works for wifi which loses its
-       IPv6 addresses on interface down, but we need to do full clean up here */
-    @Override
-    public void clearInterfaceAddresses(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "clearaddrs", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void enableIpv6(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "ipv6", iface, "enable");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void disableIpv6(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "ipv6", iface, "disable");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void addRoute(String interfaceName, RouteInfo route) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        modifyRoute(interfaceName, ADD, route, DEFAULT);
-    }
-
-    @Override
-    public void removeRoute(String interfaceName, RouteInfo route) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        modifyRoute(interfaceName, REMOVE, route, DEFAULT);
-    }
-
-    @Override
-    public void addSecondaryRoute(String interfaceName, RouteInfo route) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        modifyRoute(interfaceName, ADD, route, SECONDARY);
-    }
-
-    @Override
-    public void removeSecondaryRoute(String interfaceName, RouteInfo route) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        modifyRoute(interfaceName, REMOVE, route, SECONDARY);
-    }
-
-    private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
-        final Command cmd = new Command("interface", "route", action, interfaceName, type);
-
-        // create triplet: dest-ip-addr prefixlength gateway-ip-addr
-        final LinkAddress la = route.getDestination();
-        cmd.appendArg(la.getAddress().getHostAddress());
-        cmd.appendArg(la.getNetworkPrefixLength());
-
-        if (route.getGateway() == null) {
-            if (la.getAddress() instanceof Inet4Address) {
-                cmd.appendArg("0.0.0.0");
-            } else {
-                cmd.appendArg("::0");
-            }
-        } else {
-            cmd.appendArg(route.getGateway().getHostAddress());
-        }
-
-        try {
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    private ArrayList<String> readRouteList(String filename) {
-        FileInputStream fstream = null;
-        ArrayList<String> list = new ArrayList<String>();
-
-        try {
-            fstream = new FileInputStream(filename);
-            DataInputStream in = new DataInputStream(fstream);
-            BufferedReader br = new BufferedReader(new InputStreamReader(in));
-            String s;
-
-            // throw away the title line
-
-            while (((s = br.readLine()) != null) && (s.length() != 0)) {
-                list.add(s);
-            }
-        } catch (IOException ex) {
-            // return current list, possibly empty
-        } finally {
-            if (fstream != null) {
-                try {
-                    fstream.close();
-                } catch (IOException ex) {}
-            }
-        }
-
-        return list;
-    }
-
-    @Override
-    public RouteInfo[] getRoutes(String interfaceName) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        ArrayList<RouteInfo> routes = new ArrayList<RouteInfo>();
-
-        // v4 routes listed as:
-        // iface dest-addr gateway-addr flags refcnt use metric netmask mtu window IRTT
-        for (String s : readRouteList("/proc/net/route")) {
-            String[] fields = s.split("\t");
-
-            if (fields.length > 7) {
-                String iface = fields[0];
-
-                if (interfaceName.equals(iface)) {
-                    String dest = fields[1];
-                    String gate = fields[2];
-                    String flags = fields[3]; // future use?
-                    String mask = fields[7];
-                    try {
-                        // address stored as a hex string, ex: 0014A8C0
-                        InetAddress destAddr =
-                                NetworkUtils.intToInetAddress((int)Long.parseLong(dest, 16));
-                        int prefixLength =
-                                NetworkUtils.netmaskIntToPrefixLength(
-                                (int)Long.parseLong(mask, 16));
-                        LinkAddress linkAddress = new LinkAddress(destAddr, prefixLength);
-
-                        // address stored as a hex string, ex 0014A8C0
-                        InetAddress gatewayAddr =
-                                NetworkUtils.intToInetAddress((int)Long.parseLong(gate, 16));
-
-                        RouteInfo route = new RouteInfo(linkAddress, gatewayAddr);
-                        routes.add(route);
-                    } catch (Exception e) {
-                        Log.e(TAG, "Error parsing route " + s + " : " + e);
-                        continue;
-                    }
-                }
-            }
-        }
-
-        // v6 routes listed as:
-        // dest-addr prefixlength ?? ?? gateway-addr ?? ?? ?? ?? iface
-        for (String s : readRouteList("/proc/net/ipv6_route")) {
-            String[]fields = s.split("\\s+");
-            if (fields.length > 9) {
-                String iface = fields[9].trim();
-                if (interfaceName.equals(iface)) {
-                    String dest = fields[0];
-                    String prefix = fields[1];
-                    String gate = fields[4];
-
-                    try {
-                        // prefix length stored as a hex string, ex 40
-                        int prefixLength = Integer.parseInt(prefix, 16);
-
-                        // address stored as a 32 char hex string
-                        // ex fe800000000000000000000000000000
-                        InetAddress destAddr = NetworkUtils.hexToInet6Address(dest);
-                        LinkAddress linkAddress = new LinkAddress(destAddr, prefixLength);
-
-                        InetAddress gateAddr = NetworkUtils.hexToInet6Address(gate);
-
-                        RouteInfo route = new RouteInfo(linkAddress, gateAddr);
-                        routes.add(route);
-                    } catch (Exception e) {
-                        Log.e(TAG, "Error parsing route " + s + " : " + e);
-                        continue;
-                    }
-                }
-            }
-        }
-        return routes.toArray(new RouteInfo[routes.size()]);
-    }
-
-    @Override
-    public void setMtu(String iface, int mtu) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("interface", "setmtu", iface, mtu);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void shutdown() {
-        // TODO: remove from aidl if nobody calls externally
-        mContext.enforceCallingOrSelfPermission(SHUTDOWN, TAG);
-
-        Slog.d(TAG, "Shutting down");
-    }
-
-    @Override
-    public boolean getIpForwardingEnabled() throws IllegalStateException{
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("ipfwd", "status");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-
-        // 211 Forwarding enabled
-        event.checkCode(IpFwdStatusResult);
-        return event.getMessage().endsWith("enabled");
-    }
-
-    @Override
-    public void setIpForwardingEnabled(boolean enable) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("ipfwd", enable ? "enable" : "disable");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void startTethering(String[] dhcpRange) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        // cmd is "tether start first_start first_stop second_start second_stop ..."
-        // an odd number of addrs will fail
-
-        final Command cmd = new Command("tether", "start");
-        for (String d : dhcpRange) {
-            cmd.appendArg(d);
-        }
-
-        try {
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void stopTethering() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("tether", "stop");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public boolean isTetheringStarted() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("tether", "status");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-
-        // 210 Tethering services started
-        event.checkCode(TetherStatusResult);
-        return event.getMessage().endsWith("started");
-    }
-
-    @Override
-    public void tetherInterface(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("tether", "interface", "add", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void untetherInterface(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("tether", "interface", "remove", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public String[] listTetheredInterfaces() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return NativeDaemonEvent.filterMessageList(
-                    mConnector.executeForList("tether", "interface", "list"),
-                    TetherInterfaceListResult);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setDnsForwarders(String[] dns) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final Command cmd = new Command("tether", "dns", "set");
-        for (String s : dns) {
-            cmd.appendArg(NetworkUtils.numericToInetAddress(s).getHostAddress());
-        }
-
-        try {
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public String[] getDnsForwarders() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return NativeDaemonEvent.filterMessageList(
-                    mConnector.executeForList("tether", "dns", "list"), TetherDnsFwdTgtListResult);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    private void modifyNat(String action, String internalInterface, String externalInterface)
-            throws SocketException {
-        final Command cmd = new Command("nat", action, internalInterface, externalInterface);
-
-        final NetworkInterface internalNetworkInterface = NetworkInterface.getByName(
-                internalInterface);
-        if (internalNetworkInterface == null) {
-            cmd.appendArg("0");
-        } else {
-            Collection<InterfaceAddress> interfaceAddresses = internalNetworkInterface
-                    .getInterfaceAddresses();
-            cmd.appendArg(interfaceAddresses.size());
-            for (InterfaceAddress ia : interfaceAddresses) {
-                InetAddress addr = NetworkUtils.getNetworkPart(
-                        ia.getAddress(), ia.getNetworkPrefixLength());
-                cmd.appendArg(addr.getHostAddress() + "/" + ia.getNetworkPrefixLength());
-            }
-        }
-
-        try {
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void enableNat(String internalInterface, String externalInterface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            modifyNat("enable", internalInterface, externalInterface);
-        } catch (SocketException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public void disableNat(String internalInterface, String externalInterface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            modifyNat("disable", internalInterface, externalInterface);
-        } catch (SocketException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public String[] listTtys() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return NativeDaemonEvent.filterMessageList(
-                    mConnector.executeForList("list_ttys"), TtyListResult);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void attachPppd(
-            String tty, String localAddr, String remoteAddr, String dns1Addr, String dns2Addr) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("pppd", "attach", tty,
-                    NetworkUtils.numericToInetAddress(localAddr).getHostAddress(),
-                    NetworkUtils.numericToInetAddress(remoteAddr).getHostAddress(),
-                    NetworkUtils.numericToInetAddress(dns1Addr).getHostAddress(),
-                    NetworkUtils.numericToInetAddress(dns2Addr).getHostAddress());
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void detachPppd(String tty) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("pppd", "detach", tty);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void startAccessPoint(
-            WifiConfiguration wifiConfig, String wlanIface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            wifiFirmwareReload(wlanIface, "AP");
-            if (wifiConfig == null) {
-                mConnector.execute("softap", "set", wlanIface);
-            } else {
-                mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
-                                   "broadcast", "6", getSecurityType(wifiConfig),
-                                   new SensitiveArg(wifiConfig.preSharedKey));
-            }
-            mConnector.execute("softap", "startap");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    private static String getSecurityType(WifiConfiguration wifiConfig) {
-        switch (wifiConfig.getAuthType()) {
-            case KeyMgmt.WPA_PSK:
-                return "wpa-psk";
-            case KeyMgmt.WPA2_PSK:
-                return "wpa2-psk";
-            default:
-                return "open";
-        }
-    }
-
-    /* @param mode can be "AP", "STA" or "P2P" */
-    @Override
-    public void wifiFirmwareReload(String wlanIface, String mode) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("softap", "fwreload", wlanIface, mode);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void stopAccessPoint(String wlanIface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("softap", "stopap");
-            wifiFirmwareReload(wlanIface, "STA");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setAccessPoint(WifiConfiguration wifiConfig, String wlanIface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            if (wifiConfig == null) {
-                mConnector.execute("softap", "set", wlanIface);
-            } else {
-                mConnector.execute("softap", "set", wlanIface, wifiConfig.SSID,
-                                   "broadcast", "6", getSecurityType(wifiConfig),
-                                   new SensitiveArg(wifiConfig.preSharedKey));
-            }
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void addIdleTimer(String iface, int timeout, String label) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        if (DBG) Slog.d(TAG, "Adding idletimer");
-
-        synchronized (mIdleTimerLock) {
-            IdleTimerParams params = mActiveIdleTimers.get(iface);
-            if (params != null) {
-                // the interface already has idletimer, update network count
-                params.networkCount++;
-                return;
-            }
-
-            try {
-                mConnector.execute("idletimer", "add", iface, Integer.toString(timeout), label);
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-            mActiveIdleTimers.put(iface, new IdleTimerParams(timeout, label));
-        }
-    }
-
-    @Override
-    public void removeIdleTimer(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        if (DBG) Slog.d(TAG, "Removing idletimer");
-
-        synchronized (mIdleTimerLock) {
-            IdleTimerParams params = mActiveIdleTimers.get(iface);
-            if (params == null || --(params.networkCount) > 0) {
-                return;
-            }
-
-            try {
-                mConnector.execute("idletimer", "remove", iface,
-                        Integer.toString(params.timeout), params.label);
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-            mActiveIdleTimers.remove(iface);
-        }
-    }
-
-    @Override
-    public NetworkStats getNetworkStatsSummaryDev() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return mStatsFactory.readNetworkStatsSummaryDev();
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public NetworkStats getNetworkStatsSummaryXt() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return mStatsFactory.readNetworkStatsSummaryXt();
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public NetworkStats getNetworkStatsDetail() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return mStatsFactory.readNetworkStatsDetail(UID_ALL);
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public void setInterfaceQuota(String iface, long quotaBytes) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        // silently discard when control disabled
-        // TODO: eventually migrate to be always enabled
-        if (!mBandwidthControlEnabled) return;
-
-        synchronized (mQuotaLock) {
-            if (mActiveQuotas.containsKey(iface)) {
-                throw new IllegalStateException("iface " + iface + " already has quota");
-            }
-
-            try {
-                // TODO: support quota shared across interfaces
-                mConnector.execute("bandwidth", "setiquota", iface, quotaBytes);
-                mActiveQuotas.put(iface, quotaBytes);
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-        }
-    }
-
-    @Override
-    public void removeInterfaceQuota(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        // silently discard when control disabled
-        // TODO: eventually migrate to be always enabled
-        if (!mBandwidthControlEnabled) return;
-
-        synchronized (mQuotaLock) {
-            if (!mActiveQuotas.containsKey(iface)) {
-                // TODO: eventually consider throwing
-                return;
-            }
-
-            mActiveQuotas.remove(iface);
-            mActiveAlerts.remove(iface);
-
-            try {
-                // TODO: support quota shared across interfaces
-                mConnector.execute("bandwidth", "removeiquota", iface);
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-        }
-    }
-
-    @Override
-    public void setInterfaceAlert(String iface, long alertBytes) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        // silently discard when control disabled
-        // TODO: eventually migrate to be always enabled
-        if (!mBandwidthControlEnabled) return;
-
-        // quick sanity check
-        if (!mActiveQuotas.containsKey(iface)) {
-            throw new IllegalStateException("setting alert requires existing quota on iface");
-        }
-
-        synchronized (mQuotaLock) {
-            if (mActiveAlerts.containsKey(iface)) {
-                throw new IllegalStateException("iface " + iface + " already has alert");
-            }
-
-            try {
-                // TODO: support alert shared across interfaces
-                mConnector.execute("bandwidth", "setinterfacealert", iface, alertBytes);
-                mActiveAlerts.put(iface, alertBytes);
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-        }
-    }
-
-    @Override
-    public void removeInterfaceAlert(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        // silently discard when control disabled
-        // TODO: eventually migrate to be always enabled
-        if (!mBandwidthControlEnabled) return;
-
-        synchronized (mQuotaLock) {
-            if (!mActiveAlerts.containsKey(iface)) {
-                // TODO: eventually consider throwing
-                return;
-            }
-
-            try {
-                // TODO: support alert shared across interfaces
-                mConnector.execute("bandwidth", "removeinterfacealert", iface);
-                mActiveAlerts.remove(iface);
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-        }
-    }
-
-    @Override
-    public void setGlobalAlert(long alertBytes) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        // silently discard when control disabled
-        // TODO: eventually migrate to be always enabled
-        if (!mBandwidthControlEnabled) return;
-
-        try {
-            mConnector.execute("bandwidth", "setglobalalert", alertBytes);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setUidNetworkRules(int uid, boolean rejectOnQuotaInterfaces) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        // silently discard when control disabled
-        // TODO: eventually migrate to be always enabled
-        if (!mBandwidthControlEnabled) return;
-
-        synchronized (mQuotaLock) {
-            final boolean oldRejectOnQuota = mUidRejectOnQuota.get(uid, false);
-            if (oldRejectOnQuota == rejectOnQuotaInterfaces) {
-                // TODO: eventually consider throwing
-                return;
-            }
-
-            try {
-                mConnector.execute("bandwidth",
-                        rejectOnQuotaInterfaces ? "addnaughtyapps" : "removenaughtyapps", uid);
-                if (rejectOnQuotaInterfaces) {
-                    mUidRejectOnQuota.put(uid, true);
-                } else {
-                    mUidRejectOnQuota.delete(uid);
-                }
-            } catch (NativeDaemonConnectorException e) {
-                throw e.rethrowAsParcelableException();
-            }
-        }
-    }
-
-    @Override
-    public boolean isBandwidthControlEnabled() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        return mBandwidthControlEnabled;
-    }
-
-    @Override
-    public NetworkStats getNetworkStatsUidDetail(int uid) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            return mStatsFactory.readNetworkStatsDetail(uid);
-        } catch (IOException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
-    @Override
-    public NetworkStats getNetworkStatsTethering() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 1);
-        try {
-            final NativeDaemonEvent[] events = mConnector.executeForList(
-                    "bandwidth", "gettetherstats");
-            for (NativeDaemonEvent event : events) {
-                if (event.getCode() != TetheringStatsListResult) continue;
-
-                // 114 ifaceIn ifaceOut rx_bytes rx_packets tx_bytes tx_packets
-                final StringTokenizer tok = new StringTokenizer(event.getMessage());
-                try {
-                    final String ifaceIn = tok.nextToken();
-                    final String ifaceOut = tok.nextToken();
-
-                    final NetworkStats.Entry entry = new NetworkStats.Entry();
-                    entry.iface = ifaceOut;
-                    entry.uid = UID_TETHERING;
-                    entry.set = SET_DEFAULT;
-                    entry.tag = TAG_NONE;
-                    entry.rxBytes = Long.parseLong(tok.nextToken());
-                    entry.rxPackets = Long.parseLong(tok.nextToken());
-                    entry.txBytes = Long.parseLong(tok.nextToken());
-                    entry.txPackets = Long.parseLong(tok.nextToken());
-                    stats.combineValues(entry);
-                } catch (NoSuchElementException e) {
-                    throw new IllegalStateException("problem parsing tethering stats: " + event);
-                } catch (NumberFormatException e) {
-                    throw new IllegalStateException("problem parsing tethering stats: " + event);
-                }
-            }
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-        return stats;
-    }
-
-    @Override
-    public void setDefaultInterfaceForDns(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "setdefaultif", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setDnsServersForInterface(String iface, String[] servers, String domains) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final Command cmd = new Command("resolver", "setifdns", iface,
-                (domains == null ? "" : domains));
-
-        for (String s : servers) {
-            InetAddress a = NetworkUtils.numericToInetAddress(s);
-            if (a.isAnyLocalAddress() == false) {
-                cmd.appendArg(a.getHostAddress());
-            }
-        }
-
-        try {
-            mConnector.execute(cmd);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setUidRangeRoute(String iface, int uid_start, int uid_end) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "fwmark",
-                    "uid", "add", iface, uid_start, uid_end);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void clearUidRangeRoute(String iface, int uid_start, int uid_end) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "fwmark",
-                    "uid", "remove", iface, uid_start, uid_end);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setMarkedForwarding(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "fwmark", "rule", "add", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void clearMarkedForwarding(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "fwmark", "rule", "remove", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public int getMarkForUid(int uid) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("interface", "fwmark", "get", "mark", uid);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-        event.checkCode(GetMarkResult);
-        return Integer.parseInt(event.getMessage());
-    }
-
-    @Override
-    public int getMarkForProtect() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("interface", "fwmark", "get", "protect");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-        event.checkCode(GetMarkResult);
-        return Integer.parseInt(event.getMessage());
-    }
-
-    @Override
-    public void setMarkedForwardingRoute(String iface, RouteInfo route) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            LinkAddress dest = route.getDestination();
-            mConnector.execute("interface", "fwmark", "route", "add", iface,
-                    dest.getAddress().getHostAddress(), dest.getNetworkPrefixLength());
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void clearMarkedForwardingRoute(String iface, RouteInfo route) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            LinkAddress dest = route.getDestination();
-            mConnector.execute("interface", "fwmark", "route", "remove", iface,
-                    dest.getAddress().getHostAddress(), dest.getNetworkPrefixLength());
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setHostExemption(LinkAddress host) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "fwmark", "exempt", "add", host);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void clearHostExemption(LinkAddress host) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("interface", "fwmark", "exempt", "remove", host);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setDnsInterfaceForUidRange(String iface, int uid_start, int uid_end) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "setifaceforuidrange", iface, uid_start, uid_end);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void clearDnsInterfaceForUidRange(int uid_start, int uid_end) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "clearifaceforuidrange", uid_start, uid_end);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void clearDnsInterfaceMaps() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "clearifacemapping");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-
-    @Override
-    public void flushDefaultDnsCache() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "flushdefaultif");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void flushInterfaceDnsCache(String iface) {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "flushif", iface);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setFirewallEnabled(boolean enabled) {
-        enforceSystemUid();
-        try {
-            mConnector.execute("firewall", enabled ? "enable" : "disable");
-            mFirewallEnabled = enabled;
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public boolean isFirewallEnabled() {
-        enforceSystemUid();
-        return mFirewallEnabled;
-    }
-
-    @Override
-    public void setFirewallInterfaceRule(String iface, boolean allow) {
-        enforceSystemUid();
-        Preconditions.checkState(mFirewallEnabled);
-        final String rule = allow ? ALLOW : DENY;
-        try {
-            mConnector.execute("firewall", "set_interface_rule", iface, rule);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setFirewallEgressSourceRule(String addr, boolean allow) {
-        enforceSystemUid();
-        Preconditions.checkState(mFirewallEnabled);
-        final String rule = allow ? ALLOW : DENY;
-        try {
-            mConnector.execute("firewall", "set_egress_source_rule", addr, rule);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setFirewallEgressDestRule(String addr, int port, boolean allow) {
-        enforceSystemUid();
-        Preconditions.checkState(mFirewallEnabled);
-        final String rule = allow ? ALLOW : DENY;
-        try {
-            mConnector.execute("firewall", "set_egress_dest_rule", addr, port, rule);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void setFirewallUidRule(int uid, boolean allow) {
-        enforceSystemUid();
-        Preconditions.checkState(mFirewallEnabled);
-        final String rule = allow ? ALLOW : DENY;
-        try {
-            mConnector.execute("firewall", "set_uid_rule", uid, rule);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    private static void enforceSystemUid() {
-        final int uid = Binder.getCallingUid();
-        if (uid != Process.SYSTEM_UID) {
-            throw new SecurityException("Only available to AID_SYSTEM");
-        }
-    }
-
-    @Override
-    public void setDnsInterfaceForPid(String iface, int pid) throws IllegalStateException {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "setifaceforpid", iface, pid);
-        } catch (NativeDaemonConnectorException e) {
-            throw new IllegalStateException(
-                    "Error communicating with native deamon to set interface for pid" + iface, e);
-        }
-    }
-
-    @Override
-    public void clearDnsInterfaceForPid(int pid) throws IllegalStateException {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-        try {
-            mConnector.execute("resolver", "clearifaceforpid", pid);
-        } catch (NativeDaemonConnectorException e) {
-            throw new IllegalStateException(
-                    "Error communicating with native deamon to clear interface for pid " + pid, e);
-        }
-    }
-
-    @Override
-    public void startClatd(String interfaceName) throws IllegalStateException {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        try {
-            mConnector.execute("clatd", "start", interfaceName);
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public void stopClatd() throws IllegalStateException {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        try {
-            mConnector.execute("clatd", "stop");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-    }
-
-    @Override
-    public boolean isClatdStarted() {
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        final NativeDaemonEvent event;
-        try {
-            event = mConnector.execute("clatd", "status");
-        } catch (NativeDaemonConnectorException e) {
-            throw e.rethrowAsParcelableException();
-        }
-
-        event.checkCode(ClatdStatusResult);
-        return event.getMessage().endsWith("started");
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public void monitor() {
-        if (mConnector != null) {
-            mConnector.monitor();
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        mContext.enforceCallingOrSelfPermission(DUMP, TAG);
-
-        pw.println("NetworkManagementService NativeDaemonConnector Log:");
-        mConnector.dump(fd, pw, args);
-        pw.println();
-
-        pw.print("Bandwidth control enabled: "); pw.println(mBandwidthControlEnabled);
-
-        synchronized (mQuotaLock) {
-            pw.print("Active quota ifaces: "); pw.println(mActiveQuotas.toString());
-            pw.print("Active alert ifaces: "); pw.println(mActiveAlerts.toString());
-        }
-
-        synchronized (mUidRejectOnQuota) {
-            pw.print("UID reject on quota ifaces: [");
-            final int size = mUidRejectOnQuota.size();
-            for (int i = 0; i < size; i++) {
-                pw.print(mUidRejectOnQuota.keyAt(i));
-                if (i < size - 1) pw.print(",");
-            }
-            pw.println("]");
-        }
-
-        pw.print("Firewall enabled: "); pw.println(mFirewallEnabled);
-    }
-}
diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
deleted file mode 100644
index 0438675..0000000
--- a/services/java/com/android/server/NotificationManagerService.java
+++ /dev/null
@@ -1,2368 +0,0 @@
-/*
- * Copyright (C) 2007 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;
-
-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.app.ActivityManager;
-import android.app.ActivityManagerNative;
-import android.app.AppGlobals;
-import android.app.AppOpsManager;
-import android.app.IActivityManager;
-import android.app.INotificationManager;
-import android.app.ITransientNotification;
-import android.app.Notification;
-import android.app.PendingIntent;
-import android.app.StatusBarManager;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.ServiceConnection;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.Resources;
-import android.database.ContentObserver;
-import android.graphics.Bitmap;
-import android.media.AudioManager;
-import android.media.IAudioService;
-import android.media.IRingtonePlayer;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.os.Vibrator;
-import android.provider.Settings;
-import android.service.notification.INotificationListener;
-import android.service.notification.NotificationListenerService;
-import android.service.notification.StatusBarNotification;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.AtomicFile;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Slog;
-import android.util.Xml;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityManager;
-import android.widget.Toast;
-
-import com.android.internal.R;
-
-import com.android.internal.notification.NotificationScorer;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.lang.reflect.Array;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import libcore.io.IoUtils;
-
-
-/** {@hide} */
-public class NotificationManagerService extends INotificationManager.Stub
-{
-    private static final String TAG = "NotificationService";
-    private static final boolean DBG = false;
-
-    private static final int MAX_PACKAGE_NOTIFICATIONS = 50;
-
-    // message codes
-    private static final int MESSAGE_TIMEOUT = 2;
-
-    private static final int LONG_DELAY = 3500; // 3.5 seconds
-    private static final int SHORT_DELAY = 2000; // 2 seconds
-
-    private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250};
-    private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps
-
-    private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION;
-    private static final boolean SCORE_ONGOING_HIGHER = false;
-
-    private static final int JUNK_SCORE = -1000;
-    private static final int NOTIFICATION_PRIORITY_MULTIPLIER = 10;
-    private static final int SCORE_DISPLAY_THRESHOLD = Notification.PRIORITY_MIN * NOTIFICATION_PRIORITY_MULTIPLIER;
-
-    // Notifications with scores below this will not interrupt the user, either via LED or
-    // sound or vibration
-    private static final int SCORE_INTERRUPTION_THRESHOLD =
-            Notification.PRIORITY_LOW * NOTIFICATION_PRIORITY_MULTIPLIER;
-
-    private static final boolean ENABLE_BLOCKED_NOTIFICATIONS = true;
-    private static final boolean ENABLE_BLOCKED_TOASTS = true;
-
-    private static final String ENABLED_NOTIFICATION_LISTENERS_SEPARATOR = ":";
-
-    final Context mContext;
-    final IActivityManager mAm;
-    final UserManager mUserManager;
-    final IBinder mForegroundToken = new Binder();
-
-    private WorkerHandler mHandler;
-    private StatusBarManagerService mStatusBar;
-    private LightsService.Light mNotificationLight;
-    private LightsService.Light mAttentionLight;
-
-    private int mDefaultNotificationColor;
-    private int mDefaultNotificationLedOn;
-    private int mDefaultNotificationLedOff;
-
-    private long[] mDefaultVibrationPattern;
-    private long[] mFallbackVibrationPattern;
-
-    private boolean mSystemReady;
-    private int mDisabledNotifications;
-
-    private NotificationRecord mSoundNotification;
-    private NotificationRecord mVibrateNotification;
-
-    private IAudioService mAudioService;
-    private Vibrator mVibrator;
-
-    // for enabling and disabling notification pulse behavior
-    private boolean mScreenOn = true;
-    private boolean mInCall = false;
-    private boolean mNotificationPulseEnabled;
-
-    // used as a mutex for access to all active notifications & listeners
-    private final ArrayList<NotificationRecord> mNotificationList =
-            new ArrayList<NotificationRecord>();
-
-    private ArrayList<ToastRecord> mToastQueue;
-
-    private ArrayList<NotificationRecord> mLights = new ArrayList<NotificationRecord>();
-    private NotificationRecord mLedNotification;
-
-    private final AppOpsManager mAppOps;
-
-    // contains connections to all connected listeners, including app services
-    // and system listeners
-    private ArrayList<NotificationListenerInfo> mListeners
-            = new ArrayList<NotificationListenerInfo>();
-    // things that will be put into mListeners as soon as they're ready
-    private ArrayList<String> mServicesBinding = new ArrayList<String>();
-    // lists the component names of all enabled (and therefore connected) listener
-    // app services for the current user only
-    private HashSet<ComponentName> mEnabledListenersForCurrentUser
-            = new HashSet<ComponentName>();
-    // Just the packages from mEnabledListenersForCurrentUser
-    private HashSet<String> mEnabledListenerPackageNames = new HashSet<String>();
-
-    // Notification control database. For now just contains disabled packages.
-    private AtomicFile mPolicyFile;
-    private HashSet<String> mBlockedPackages = new HashSet<String>();
-
-    private static final int DB_VERSION = 1;
-
-    private static final String TAG_BODY = "notification-policy";
-    private static final String ATTR_VERSION = "version";
-
-    private static final String TAG_BLOCKED_PKGS = "blocked-packages";
-    private static final String TAG_PACKAGE = "package";
-    private static final String ATTR_NAME = "name";
-
-    private final ArrayList<NotificationScorer> mScorers = new ArrayList<NotificationScorer>();
-
-    private class NotificationListenerInfo implements DeathRecipient {
-        INotificationListener listener;
-        ComponentName component;
-        int userid;
-        boolean isSystem;
-        ServiceConnection connection;
-
-        public NotificationListenerInfo(INotificationListener listener, ComponentName component,
-                int userid, boolean isSystem) {
-            this.listener = listener;
-            this.component = component;
-            this.userid = userid;
-            this.isSystem = isSystem;
-            this.connection = null;
-        }
-
-        public NotificationListenerInfo(INotificationListener listener, ComponentName component,
-                int userid, ServiceConnection connection) {
-            this.listener = listener;
-            this.component = component;
-            this.userid = userid;
-            this.isSystem = false;
-            this.connection = connection;
-        }
-
-        boolean enabledAndUserMatches(StatusBarNotification sbn) {
-            final int nid = sbn.getUserId();
-            if (!isEnabledForCurrentUser()) {
-                return false;
-            }
-            if (this.userid == UserHandle.USER_ALL) return true;
-            return (nid == UserHandle.USER_ALL || nid == this.userid);
-        }
-
-        public void notifyPostedIfUserMatch(StatusBarNotification sbn) {
-            if (!enabledAndUserMatches(sbn)) {
-                return;
-            }
-            try {
-                listener.onNotificationPosted(sbn);
-            } catch (RemoteException ex) {
-                Log.e(TAG, "unable to notify listener (posted): " + listener, ex);
-            }
-        }
-
-        public void notifyRemovedIfUserMatch(StatusBarNotification sbn) {
-            if (!enabledAndUserMatches(sbn)) return;
-            try {
-                listener.onNotificationRemoved(sbn);
-            } catch (RemoteException ex) {
-                Log.e(TAG, "unable to notify listener (removed): " + listener, ex);
-            }
-        }
-
-        @Override
-        public void binderDied() {
-            if (connection == null) {
-                // This is not a service; it won't be recreated. We can give up this connection.
-                unregisterListener(this.listener, this.userid);
-            }
-        }
-
-        /** convenience method for looking in mEnabledListenersForCurrentUser */
-        public boolean isEnabledForCurrentUser() {
-            if (this.isSystem) return true;
-            if (this.connection == null) return false;
-            return mEnabledListenersForCurrentUser.contains(this.component);
-        }
-    }
-
-    private static class Archive {
-        static final int BUFFER_SIZE = 250;
-        ArrayDeque<StatusBarNotification> mBuffer = new ArrayDeque<StatusBarNotification>(BUFFER_SIZE);
-
-        public Archive() {
-        }
-
-        public String toString() {
-            final StringBuilder sb = new StringBuilder();
-            final int N = mBuffer.size();
-            sb.append("Archive (");
-            sb.append(N);
-            sb.append(" notification");
-            sb.append((N==1)?")":"s)");
-            return sb.toString();
-        }
-
-        public void record(StatusBarNotification nr) {
-            if (mBuffer.size() == BUFFER_SIZE) {
-                mBuffer.removeFirst();
-            }
-
-            // We don't want to store the heavy bits of the notification in the archive,
-            // but other clients in the system process might be using the object, so we
-            // store a (lightened) copy.
-            mBuffer.addLast(nr.cloneLight());
-        }
-
-
-        public void clear() {
-            mBuffer.clear();
-        }
-
-        public Iterator<StatusBarNotification> descendingIterator() {
-            return mBuffer.descendingIterator();
-        }
-        public Iterator<StatusBarNotification> ascendingIterator() {
-            return mBuffer.iterator();
-        }
-        public Iterator<StatusBarNotification> filter(
-                final Iterator<StatusBarNotification> iter, final String pkg, final int userId) {
-            return new Iterator<StatusBarNotification>() {
-                StatusBarNotification mNext = findNext();
-
-                private StatusBarNotification findNext() {
-                    while (iter.hasNext()) {
-                        StatusBarNotification nr = iter.next();
-                        if ((pkg == null || nr.getPackageName() == pkg)
-                                && (userId == UserHandle.USER_ALL || nr.getUserId() == userId)) {
-                            return nr;
-                        }
-                    }
-                    return null;
-                }
-
-                @Override
-                public boolean hasNext() {
-                    return mNext == null;
-                }
-
-                @Override
-                public StatusBarNotification next() {
-                    StatusBarNotification next = mNext;
-                    if (next == null) {
-                        throw new NoSuchElementException();
-                    }
-                    mNext = findNext();
-                    return next;
-                }
-
-                @Override
-                public void remove() {
-                    iter.remove();
-                }
-            };
-        }
-
-        public StatusBarNotification[] getArray(int count) {
-            if (count == 0) count = Archive.BUFFER_SIZE;
-            final StatusBarNotification[] a
-                    = new StatusBarNotification[Math.min(count, mBuffer.size())];
-            Iterator<StatusBarNotification> iter = descendingIterator();
-            int i=0;
-            while (iter.hasNext() && i < count) {
-                a[i++] = iter.next();
-            }
-            return a;
-        }
-
-        public StatusBarNotification[] getArray(int count, String pkg, int userId) {
-            if (count == 0) count = Archive.BUFFER_SIZE;
-            final StatusBarNotification[] a
-                    = new StatusBarNotification[Math.min(count, mBuffer.size())];
-            Iterator<StatusBarNotification> iter = filter(descendingIterator(), pkg, userId);
-            int i=0;
-            while (iter.hasNext() && i < count) {
-                a[i++] = iter.next();
-            }
-            return a;
-        }
-
-    }
-
-    Archive mArchive = new Archive();
-
-    private void loadBlockDb() {
-        synchronized(mBlockedPackages) {
-            if (mPolicyFile == null) {
-                File dir = new File("/data/system");
-                mPolicyFile = new AtomicFile(new File(dir, "notification_policy.xml"));
-
-                mBlockedPackages.clear();
-
-                FileInputStream infile = null;
-                try {
-                    infile = mPolicyFile.openRead();
-                    final XmlPullParser parser = Xml.newPullParser();
-                    parser.setInput(infile, null);
-
-                    int type;
-                    String tag;
-                    int version = DB_VERSION;
-                    while ((type = parser.next()) != END_DOCUMENT) {
-                        tag = parser.getName();
-                        if (type == START_TAG) {
-                            if (TAG_BODY.equals(tag)) {
-                                version = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERSION));
-                            } else if (TAG_BLOCKED_PKGS.equals(tag)) {
-                                while ((type = parser.next()) != END_DOCUMENT) {
-                                    tag = parser.getName();
-                                    if (TAG_PACKAGE.equals(tag)) {
-                                        mBlockedPackages.add(parser.getAttributeValue(null, ATTR_NAME));
-                                    } else if (TAG_BLOCKED_PKGS.equals(tag) && type == END_TAG) {
-                                        break;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                } catch (FileNotFoundException e) {
-                    // No data yet
-                } catch (IOException e) {
-                    Log.wtf(TAG, "Unable to read blocked notifications database", e);
-                } catch (NumberFormatException e) {
-                    Log.wtf(TAG, "Unable to parse blocked notifications database", e);
-                } catch (XmlPullParserException e) {
-                    Log.wtf(TAG, "Unable to parse blocked notifications database", e);
-                } finally {
-                    IoUtils.closeQuietly(infile);
-                }
-            }
-        }
-    }
-
-    /**
-     * Use this when you just want to know if notifications are OK for this package.
-     */
-    public boolean areNotificationsEnabledForPackage(String pkg, int uid) {
-        checkCallerIsSystem();
-        return (mAppOps.checkOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
-                == AppOpsManager.MODE_ALLOWED);
-    }
-
-    /** Use this when you actually want to post a notification or toast.
-     *
-     * Unchecked. Not exposed via Binder, but can be called in the course of enqueue*().
-     */
-    private boolean noteNotificationOp(String pkg, int uid) {
-        if (mAppOps.noteOpNoThrow(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg)
-                != AppOpsManager.MODE_ALLOWED) {
-            Slog.v(TAG, "notifications are disabled by AppOps for " + pkg);
-            return false;
-        }
-        return true;
-    }
-
-    public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
-        checkCallerIsSystem();
-
-        Slog.v(TAG, (enabled?"en":"dis") + "abling notifications for " + pkg);
-
-        mAppOps.setMode(AppOpsManager.OP_POST_NOTIFICATION, uid, pkg,
-                enabled ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_IGNORED);
-
-        // Now, cancel any outstanding notifications that are part of a just-disabled app
-        if (ENABLE_BLOCKED_NOTIFICATIONS && !enabled) {
-            cancelAllNotificationsInt(pkg, 0, 0, true, UserHandle.getUserId(uid));
-        }
-    }
-
-
-    private static String idDebugString(Context baseContext, String packageName, int id) {
-        Context c = null;
-
-        if (packageName != null) {
-            try {
-                c = baseContext.createPackageContext(packageName, 0);
-            } catch (NameNotFoundException e) {
-                c = baseContext;
-            }
-        } else {
-            c = baseContext;
-        }
-
-        String pkg;
-        String type;
-        String name;
-
-        Resources r = c.getResources();
-        try {
-            return r.getResourceName(id);
-        } catch (Resources.NotFoundException e) {
-            return "<name unknown>";
-        }
-    }
-
-    /**
-     * System-only API for getting a list of current (i.e. not cleared) notifications.
-     *
-     * Requires ACCESS_NOTIFICATIONS which is signature|system.
-     */
-    @Override
-    public StatusBarNotification[] getActiveNotifications(String callingPkg) {
-        // enforce() will ensure the calling uid has the correct permission
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
-                "NotificationManagerService.getActiveNotifications");
-
-        StatusBarNotification[] tmp = null;
-        int uid = Binder.getCallingUid();
-
-        // noteOp will check to make sure the callingPkg matches the uid
-        if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
-                == AppOpsManager.MODE_ALLOWED) {
-            synchronized (mNotificationList) {
-                tmp = new StatusBarNotification[mNotificationList.size()];
-                final int N = mNotificationList.size();
-                for (int i=0; i<N; i++) {
-                    tmp[i] = mNotificationList.get(i).sbn;
-                }
-            }
-        }
-        return tmp;
-    }
-
-    /**
-     * System-only API for getting a list of recent (cleared, no longer shown) notifications.
-     *
-     * Requires ACCESS_NOTIFICATIONS which is signature|system.
-     */
-    @Override
-    public StatusBarNotification[] getHistoricalNotifications(String callingPkg, int count) {
-        // enforce() will ensure the calling uid has the correct permission
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NOTIFICATIONS,
-                "NotificationManagerService.getHistoricalNotifications");
-
-        StatusBarNotification[] tmp = null;
-        int uid = Binder.getCallingUid();
-
-        // noteOp will check to make sure the callingPkg matches the uid
-        if (mAppOps.noteOpNoThrow(AppOpsManager.OP_ACCESS_NOTIFICATIONS, uid, callingPkg)
-                == AppOpsManager.MODE_ALLOWED) {
-            synchronized (mArchive) {
-                tmp = mArchive.getArray(count);
-            }
-        }
-        return tmp;
-    }
-
-    /**
-     * Remove notification access for any services that no longer exist.
-     */
-    void disableNonexistentListeners() {
-        int currentUser = ActivityManager.getCurrentUser();
-        String flatIn = Settings.Secure.getStringForUser(
-                mContext.getContentResolver(),
-                Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
-                currentUser);
-        if (!TextUtils.isEmpty(flatIn)) {
-            if (DBG) Slog.v(TAG, "flat before: " + flatIn);
-            PackageManager pm = mContext.getPackageManager();
-            List<ResolveInfo> installedServices = pm.queryIntentServicesAsUser(
-                    new Intent(NotificationListenerService.SERVICE_INTERFACE),
-                    PackageManager.GET_SERVICES | PackageManager.GET_META_DATA,
-                    currentUser);
-
-            Set<ComponentName> installed = new HashSet<ComponentName>();
-            for (int i = 0, count = installedServices.size(); i < count; i++) {
-                ResolveInfo resolveInfo = installedServices.get(i);
-                ServiceInfo info = resolveInfo.serviceInfo;
-
-                if (!android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE.equals(
-                                info.permission)) {
-                    Slog.w(TAG, "Skipping notification listener service "
-                            + info.packageName + "/" + info.name
-                            + ": it does not require the permission "
-                            + android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);
-                    continue;
-                }
-                installed.add(new ComponentName(info.packageName, info.name));
-            }
-
-            String flatOut = "";
-            if (!installed.isEmpty()) {
-                String[] enabled = flatIn.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
-                ArrayList<String> remaining = new ArrayList<String>(enabled.length);
-                for (int i = 0; i < enabled.length; i++) {
-                    ComponentName enabledComponent = ComponentName.unflattenFromString(enabled[i]);
-                    if (installed.contains(enabledComponent)) {
-                        remaining.add(enabled[i]);
-                    }
-                }
-                flatOut = TextUtils.join(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR, remaining);
-            }
-            if (DBG) Slog.v(TAG, "flat after: " + flatOut);
-            if (!flatIn.equals(flatOut)) {
-                Settings.Secure.putStringForUser(mContext.getContentResolver(),
-                        Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
-                        flatOut, currentUser);
-            }
-        }
-    }
-
-    /**
-     * Called whenever packages change, the user switches, or ENABLED_NOTIFICATION_LISTENERS
-     * is altered. (For example in response to USER_SWITCHED in our broadcast receiver)
-     */
-    void rebindListenerServices() {
-        final int currentUser = ActivityManager.getCurrentUser();
-        String flat = Settings.Secure.getStringForUser(
-                mContext.getContentResolver(),
-                Settings.Secure.ENABLED_NOTIFICATION_LISTENERS,
-                currentUser);
-
-        NotificationListenerInfo[] toRemove = new NotificationListenerInfo[mListeners.size()];
-        final ArrayList<ComponentName> toAdd;
-
-        synchronized (mNotificationList) {
-            // unbind and remove all existing listeners
-            toRemove = mListeners.toArray(toRemove);
-
-            toAdd = new ArrayList<ComponentName>();
-            final HashSet<ComponentName> newEnabled = new HashSet<ComponentName>();
-            final HashSet<String> newPackages = new HashSet<String>();
-
-            // decode the list of components
-            if (flat != null) {
-                String[] components = flat.split(ENABLED_NOTIFICATION_LISTENERS_SEPARATOR);
-                for (int i=0; i<components.length; i++) {
-                    final ComponentName component
-                            = ComponentName.unflattenFromString(components[i]);
-                    if (component != null) {
-                        newEnabled.add(component);
-                        toAdd.add(component);
-                        newPackages.add(component.getPackageName());
-                    }
-                }
-
-                mEnabledListenersForCurrentUser = newEnabled;
-                mEnabledListenerPackageNames = newPackages;
-            }
-        }
-
-        for (NotificationListenerInfo info : toRemove) {
-            final ComponentName component = info.component;
-            final int oldUser = info.userid;
-            Slog.v(TAG, "disabling notification listener for user " + oldUser + ": " + component);
-            unregisterListenerService(component, info.userid);
-        }
-
-        final int N = toAdd.size();
-        for (int i=0; i<N; i++) {
-            final ComponentName component = toAdd.get(i);
-            Slog.v(TAG, "enabling notification listener for user " + currentUser + ": "
-                    + component);
-            registerListenerService(component, currentUser);
-        }
-    }
-
-    /**
-     * Register a listener binder directly with the notification manager.
-     *
-     * Only works with system callers. Apps should extend
-     * {@link android.service.notification.NotificationListenerService}.
-     */
-    @Override
-    public void registerListener(final INotificationListener listener,
-            final ComponentName component, final int userid) {
-        checkCallerIsSystem();
-
-        synchronized (mNotificationList) {
-            try {
-                NotificationListenerInfo info
-                        = new NotificationListenerInfo(listener, component, userid, true);
-                listener.asBinder().linkToDeath(info, 0);
-                mListeners.add(info);
-            } catch (RemoteException e) {
-                // already dead
-            }
-        }
-    }
-
-    /**
-     * Version of registerListener that takes the name of a
-     * {@link android.service.notification.NotificationListenerService} to bind to.
-     *
-     * This is the mechanism by which third parties may subscribe to notifications.
-     */
-    private void registerListenerService(final ComponentName name, final int userid) {
-        checkCallerIsSystem();
-
-        if (DBG) Slog.v(TAG, "registerListenerService: " + name + " u=" + userid);
-
-        synchronized (mNotificationList) {
-            final String servicesBindingTag = name.toString() + "/" + userid;
-            if (mServicesBinding.contains(servicesBindingTag)) {
-                // stop registering this thing already! we're working on it
-                return;
-            }
-            mServicesBinding.add(servicesBindingTag);
-
-            final int N = mListeners.size();
-            for (int i=N-1; i>=0; i--) {
-                final NotificationListenerInfo info = mListeners.get(i);
-                if (name.equals(info.component)
-                        && info.userid == userid) {
-                    // cut old connections
-                    if (DBG) Slog.v(TAG, "    disconnecting old listener: " + info.listener);
-                    mListeners.remove(i);
-                    if (info.connection != null) {
-                        mContext.unbindService(info.connection);
-                    }
-                }
-            }
-
-            Intent intent = new Intent(NotificationListenerService.SERVICE_INTERFACE);
-            intent.setComponent(name);
-
-            intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
-                    R.string.notification_listener_binding_label);
-            intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
-                    mContext, 0, new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS), 0));
-
-            try {
-                if (DBG) Slog.v(TAG, "binding: " + intent);
-                if (!mContext.bindServiceAsUser(intent,
-                        new ServiceConnection() {
-                            INotificationListener mListener;
-                            @Override
-                            public void onServiceConnected(ComponentName name, IBinder service) {
-                                synchronized (mNotificationList) {
-                                    mServicesBinding.remove(servicesBindingTag);
-                                    try {
-                                        mListener = INotificationListener.Stub.asInterface(service);
-                                        NotificationListenerInfo info = new NotificationListenerInfo(
-                                                mListener, name, userid, this);
-                                        service.linkToDeath(info, 0);
-                                        mListeners.add(info);
-                                    } catch (RemoteException e) {
-                                        // already dead
-                                    }
-                                }
-                            }
-
-                            @Override
-                            public void onServiceDisconnected(ComponentName name) {
-                                Slog.v(TAG, "notification listener connection lost: " + name);
-                            }
-                        },
-                        Context.BIND_AUTO_CREATE,
-                        new UserHandle(userid)))
-                {
-                    mServicesBinding.remove(servicesBindingTag);
-                    Slog.w(TAG, "Unable to bind listener service: " + intent);
-                    return;
-                }
-            } catch (SecurityException ex) {
-                Slog.e(TAG, "Unable to bind listener service: " + intent, ex);
-                return;
-            }
-        }
-    }
-
-    /**
-     * Remove a listener binder directly
-     */
-    @Override
-    public void unregisterListener(INotificationListener listener, int userid) {
-        // no need to check permissions; if your listener binder is in the list,
-        // that's proof that you had permission to add it in the first place
-
-        synchronized (mNotificationList) {
-            final int N = mListeners.size();
-            for (int i=N-1; i>=0; i--) {
-                final NotificationListenerInfo info = mListeners.get(i);
-                if (info.listener.asBinder() == listener.asBinder()
-                        && info.userid == userid) {
-                    mListeners.remove(i);
-                    if (info.connection != null) {
-                        mContext.unbindService(info.connection);
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Remove a listener service for the given user by ComponentName
-     */
-    private void unregisterListenerService(ComponentName name, int userid) {
-        checkCallerIsSystem();
-
-        synchronized (mNotificationList) {
-            final int N = mListeners.size();
-            for (int i=N-1; i>=0; i--) {
-                final NotificationListenerInfo info = mListeners.get(i);
-                if (name.equals(info.component)
-                        && info.userid == userid) {
-                    mListeners.remove(i);
-                    if (info.connection != null) {
-                        try {
-                            mContext.unbindService(info.connection);
-                        } catch (IllegalArgumentException ex) {
-                            // something happened to the service: we think we have a connection
-                            // but it's bogus.
-                            Slog.e(TAG, "Listener " + name + " could not be unbound: " + ex);
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * asynchronously notify all listeners about a new notification
-     */
-    private void notifyPostedLocked(NotificationRecord n) {
-        // make a copy in case changes are made to the underlying Notification object
-        final StatusBarNotification sbn = n.sbn.clone();
-        for (final NotificationListenerInfo info : mListeners) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    info.notifyPostedIfUserMatch(sbn);
-                }});
-        }
-    }
-
-    /**
-     * asynchronously notify all listeners about a removed notification
-     */
-    private void notifyRemovedLocked(NotificationRecord n) {
-        // make a copy in case changes are made to the underlying Notification object
-        // NOTE: this copy is lightweight: it doesn't include heavyweight parts of the notification
-        final StatusBarNotification sbn_light = n.sbn.cloneLight();
-
-        for (final NotificationListenerInfo info : mListeners) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    info.notifyRemovedIfUserMatch(sbn_light);
-                }});
-        }
-    }
-
-    // -- APIs to support listeners clicking/clearing notifications --
-
-    private NotificationListenerInfo checkListenerToken(INotificationListener listener) {
-        final IBinder token = listener.asBinder();
-        final int N = mListeners.size();
-        for (int i=0; i<N; i++) {
-            final NotificationListenerInfo info = mListeners.get(i);
-            if (info.listener.asBinder() == token) return info;
-        }
-        throw new SecurityException("Disallowed call from unknown listener: " + listener);
-    }
-
-    /**
-     * Allow an INotificationListener to simulate a "clear all" operation.
-     *
-     * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onClearAllNotifications}
-     *
-     * @param token The binder for the listener, to check that the caller is allowed
-     */
-    public void cancelAllNotificationsFromListener(INotificationListener token) {
-        NotificationListenerInfo info = checkListenerToken(token);
-        long identity = Binder.clearCallingIdentity();
-        try {
-            cancelAll(info.userid);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    /**
-     * Allow an INotificationListener to simulate clearing (dismissing) a single notification.
-     *
-     * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onNotificationClear}
-     *
-     * @param token The binder for the listener, to check that the caller is allowed
-     */
-    public void cancelNotificationFromListener(INotificationListener token, String pkg, String tag, int id) {
-        NotificationListenerInfo info = checkListenerToken(token);
-        long identity = Binder.clearCallingIdentity();
-        try {
-            cancelNotification(pkg, tag, id, 0,
-                    Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
-                    true,
-                    info.userid);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    /**
-     * Allow an INotificationListener to request the list of outstanding notifications seen by
-     * the current user. Useful when starting up, after which point the listener callbacks should
-     * be used.
-     *
-     * @param token The binder for the listener, to check that the caller is allowed
-     */
-    public StatusBarNotification[] getActiveNotificationsFromListener(INotificationListener token) {
-        NotificationListenerInfo info = checkListenerToken(token);
-
-        StatusBarNotification[] result = new StatusBarNotification[0];
-        ArrayList<StatusBarNotification> list = new ArrayList<StatusBarNotification>();
-        synchronized (mNotificationList) {
-            final int N = mNotificationList.size();
-            for (int i=0; i<N; i++) {
-                StatusBarNotification sbn = mNotificationList.get(i).sbn;
-                if (info.enabledAndUserMatches(sbn)) {
-                    list.add(sbn);
-                }
-            }
-        }
-        return list.toArray(result);
-    }
-
-    // -- end of listener APIs --
-
-    public static final class NotificationRecord
-    {
-        final StatusBarNotification sbn;
-        IBinder statusBarKey;
-
-        NotificationRecord(StatusBarNotification sbn)
-        {
-            this.sbn = sbn;
-        }
-
-        public Notification getNotification() { return sbn.getNotification(); }
-        public int getFlags() { return sbn.getNotification().flags; }
-        public int getUserId() { return sbn.getUserId(); }
-
-        void dump(PrintWriter pw, String prefix, Context baseContext) {
-            final Notification notification = sbn.getNotification();
-            pw.println(prefix + this);
-            pw.println(prefix + "  uid=" + sbn.getUid() + " userId=" + sbn.getUserId());
-            pw.println(prefix + "  icon=0x" + Integer.toHexString(notification.icon)
-                    + " / " + idDebugString(baseContext, sbn.getPackageName(), notification.icon));
-            pw.println(prefix + "  pri=" + notification.priority + " score=" + sbn.getScore());
-            pw.println(prefix + "  contentIntent=" + notification.contentIntent);
-            pw.println(prefix + "  deleteIntent=" + notification.deleteIntent);
-            pw.println(prefix + "  tickerText=" + notification.tickerText);
-            pw.println(prefix + "  contentView=" + notification.contentView);
-            pw.println(prefix + String.format("  defaults=0x%08x flags=0x%08x",
-                    notification.defaults, notification.flags));
-            pw.println(prefix + "  sound=" + notification.sound);
-            pw.println(prefix + "  vibrate=" + Arrays.toString(notification.vibrate));
-            pw.println(prefix + String.format("  led=0x%08x onMs=%d offMs=%d",
-                    notification.ledARGB, notification.ledOnMS, notification.ledOffMS));
-            if (notification.actions != null && notification.actions.length > 0) {
-                pw.println(prefix + "  actions={");
-                final int N = notification.actions.length;
-                for (int i=0; i<N; i++) {
-                    final Notification.Action action = notification.actions[i];
-                    pw.println(String.format("%s    [%d] \"%s\" -> %s",
-                            prefix,
-                            i,
-                            action.title,
-                            action.actionIntent.toString()
-                            ));
-                }
-                pw.println(prefix + "  }");
-            }
-            if (notification.extras != null && notification.extras.size() > 0) {
-                pw.println(prefix + "  extras={");
-                for (String key : notification.extras.keySet()) {
-                    pw.print(prefix + "    " + key + "=");
-                    Object val = notification.extras.get(key);
-                    if (val == null) {
-                        pw.println("null");
-                    } else {
-                        pw.print(val.toString());
-                        if (val instanceof Bitmap) {
-                            pw.print(String.format(" (%dx%d)",
-                                    ((Bitmap) val).getWidth(),
-                                    ((Bitmap) val).getHeight()));
-                        } else if (val.getClass().isArray()) {
-                            pw.println(" {");
-                            final int N = Array.getLength(val);
-                            for (int i=0; i<N; i++) {
-                                if (i > 0) pw.println(",");
-                                pw.print(prefix + "      " + Array.get(val, i));
-                            }
-                            pw.print("\n" + prefix + "    }");
-                        }
-                        pw.println();
-                    }
-                }
-                pw.println(prefix + "  }");
-            }
-        }
-
-        @Override
-        public final String toString() {
-            return String.format(
-                    "NotificationRecord(0x%08x: pkg=%s user=%s id=%d tag=%s score=%d: %s)",
-                    System.identityHashCode(this),
-                    this.sbn.getPackageName(), this.sbn.getUser(), this.sbn.getId(), this.sbn.getTag(),
-                    this.sbn.getScore(), this.sbn.getNotification());
-        }
-    }
-
-    private static final class ToastRecord
-    {
-        final int pid;
-        final String pkg;
-        final ITransientNotification callback;
-        int duration;
-
-        ToastRecord(int pid, String pkg, ITransientNotification callback, int duration)
-        {
-            this.pid = pid;
-            this.pkg = pkg;
-            this.callback = callback;
-            this.duration = duration;
-        }
-
-        void update(int duration) {
-            this.duration = duration;
-        }
-
-        void dump(PrintWriter pw, String prefix) {
-            pw.println(prefix + this);
-        }
-
-        @Override
-        public final String toString()
-        {
-            return "ToastRecord{"
-                + Integer.toHexString(System.identityHashCode(this))
-                + " pkg=" + pkg
-                + " callback=" + callback
-                + " duration=" + duration;
-        }
-    }
-
-    private StatusBarManagerService.NotificationCallbacks mNotificationCallbacks
-            = new StatusBarManagerService.NotificationCallbacks() {
-
-        public void onSetDisabled(int status) {
-            synchronized (mNotificationList) {
-                mDisabledNotifications = status;
-                if ((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) {
-                    // cancel whatever's going on
-                    long identity = Binder.clearCallingIdentity();
-                    try {
-                        final IRingtonePlayer player = mAudioService.getRingtonePlayer();
-                        if (player != null) {
-                            player.stopAsync();
-                        }
-                    } catch (RemoteException e) {
-                    } finally {
-                        Binder.restoreCallingIdentity(identity);
-                    }
-
-                    identity = Binder.clearCallingIdentity();
-                    try {
-                        mVibrator.cancel();
-                    } finally {
-                        Binder.restoreCallingIdentity(identity);
-                    }
-                }
-            }
-        }
-
-        public void onClearAll() {
-            // XXX to be totally correct, the caller should tell us which user
-            // this is for.
-            cancelAll(ActivityManager.getCurrentUser());
-        }
-
-        public void onNotificationClick(String pkg, String tag, int id) {
-            // XXX to be totally correct, the caller should tell us which user
-            // this is for.
-            cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
-                    Notification.FLAG_FOREGROUND_SERVICE, false,
-                    ActivityManager.getCurrentUser());
-        }
-
-        public void onNotificationClear(String pkg, String tag, int id) {
-            // XXX to be totally correct, the caller should tell us which user
-            // this is for.
-            cancelNotification(pkg, tag, id, 0,
-                Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE,
-                true, ActivityManager.getCurrentUser());
-        }
-
-        public void onPanelRevealed() {
-            synchronized (mNotificationList) {
-                // sound
-                mSoundNotification = null;
-
-                long identity = Binder.clearCallingIdentity();
-                try {
-                    final IRingtonePlayer player = mAudioService.getRingtonePlayer();
-                    if (player != null) {
-                        player.stopAsync();
-                    }
-                } catch (RemoteException e) {
-                } finally {
-                    Binder.restoreCallingIdentity(identity);
-                }
-
-                // vibrate
-                mVibrateNotification = null;
-                identity = Binder.clearCallingIdentity();
-                try {
-                    mVibrator.cancel();
-                } finally {
-                    Binder.restoreCallingIdentity(identity);
-                }
-
-                // light
-                mLights.clear();
-                mLedNotification = null;
-                updateLightsLocked();
-            }
-        }
-
-        public void onNotificationError(String pkg, String tag, int id,
-                int uid, int initialPid, String message) {
-            Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
-                    + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
-            // XXX to be totally correct, the caller should tell us which user
-            // this is for.
-            cancelNotification(pkg, tag, id, 0, 0, false, UserHandle.getUserId(uid));
-            long ident = Binder.clearCallingIdentity();
-            try {
-                ActivityManagerNative.getDefault().crashApplication(uid, initialPid, pkg,
-                        "Bad notification posted from package " + pkg
-                        + ": " + message);
-            } catch (RemoteException e) {
-            }
-            Binder.restoreCallingIdentity(ident);
-        }
-    };
-
-    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-
-            boolean queryRestart = false;
-            boolean queryRemove = false;
-            boolean packageChanged = false;
-            boolean cancelNotifications = true;
-            
-            if (action.equals(Intent.ACTION_PACKAGE_ADDED)
-                    || (queryRemove=action.equals(Intent.ACTION_PACKAGE_REMOVED))
-                    || action.equals(Intent.ACTION_PACKAGE_RESTARTED)
-                    || (packageChanged=action.equals(Intent.ACTION_PACKAGE_CHANGED))
-                    || (queryRestart=action.equals(Intent.ACTION_QUERY_PACKAGE_RESTART))
-                    || action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
-                String pkgList[] = null;
-                boolean queryReplace = queryRemove &&
-                        intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
-                if (DBG) Slog.i(TAG, "queryReplace=" + queryReplace);
-                if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
-                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-                } else if (queryRestart) {
-                    pkgList = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
-                } else {
-                    Uri uri = intent.getData();
-                    if (uri == null) {
-                        return;
-                    }
-                    String pkgName = uri.getSchemeSpecificPart();
-                    if (pkgName == null) {
-                        return;
-                    }
-                    if (packageChanged) {
-                        // We cancel notifications for packages which have just been disabled
-                        try {
-                            final int enabled = mContext.getPackageManager()
-                                    .getApplicationEnabledSetting(pkgName);
-                            if (enabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED
-                                    || enabled == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
-                                cancelNotifications = false;
-                            }
-                        } catch (IllegalArgumentException e) {
-                            // Package doesn't exist; probably racing with uninstall.
-                            // cancelNotifications is already true, so nothing to do here.
-                            if (DBG) {
-                                Slog.i(TAG, "Exception trying to look up app enabled setting", e);
-                            }
-                        }
-                    }
-                    pkgList = new String[]{pkgName};
-                }
-
-                boolean anyListenersInvolved = false;
-                if (pkgList != null && (pkgList.length > 0)) {
-                    for (String pkgName : pkgList) {
-                        if (cancelNotifications) {
-                            cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart,
-                                    UserHandle.USER_ALL);
-                        }
-                        if (mEnabledListenerPackageNames.contains(pkgName)) {
-                            anyListenersInvolved = true;
-                        }
-                    }
-                }
-
-                if (anyListenersInvolved) {
-                    // if we're not replacing a package, clean up orphaned bits
-                    if (!queryReplace) {
-                        disableNonexistentListeners();
-                    }
-                    // make sure we're still bound to any of our
-                    // listeners who may have just upgraded
-                    rebindListenerServices();
-                }
-            } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
-                // Keep track of screen on/off state, but do not turn off the notification light
-                // until user passes through the lock screen or views the notification.
-                mScreenOn = true;
-            } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
-                mScreenOn = false;
-            } else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
-                mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
-                        TelephonyManager.EXTRA_STATE_OFFHOOK));
-                updateNotificationPulse();
-            } else if (action.equals(Intent.ACTION_USER_STOPPED)) {
-                int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
-                if (userHandle >= 0) {
-                    cancelAllNotificationsInt(null, 0, 0, true, userHandle);
-                }
-            } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
-                // turn off LED when user passes through lock screen
-                mNotificationLight.turnOff();
-            } else if (action.equals(Intent.ACTION_USER_SWITCHED)) {
-                // reload per-user settings
-                mSettingsObserver.update(null);
-            }
-        }
-    };
-
-    class SettingsObserver extends ContentObserver {
-        private final Uri NOTIFICATION_LIGHT_PULSE_URI
-                = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
-
-        private final Uri ENABLED_NOTIFICATION_LISTENERS_URI
-                = Settings.Secure.getUriFor(Settings.Secure.ENABLED_NOTIFICATION_LISTENERS);
-
-        SettingsObserver(Handler handler) {
-            super(handler);
-        }
-
-        void observe() {
-            ContentResolver resolver = mContext.getContentResolver();
-            resolver.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI,
-                    false, this, UserHandle.USER_ALL);
-            resolver.registerContentObserver(ENABLED_NOTIFICATION_LISTENERS_URI,
-                    false, this, UserHandle.USER_ALL);
-            update(null);
-        }
-
-        @Override public void onChange(boolean selfChange, Uri uri) {
-            update(uri);
-        }
-
-        public void update(Uri uri) {
-            ContentResolver resolver = mContext.getContentResolver();
-            if (uri == null || NOTIFICATION_LIGHT_PULSE_URI.equals(uri)) {
-                boolean pulseEnabled = Settings.System.getInt(resolver,
-                            Settings.System.NOTIFICATION_LIGHT_PULSE, 0) != 0;
-                if (mNotificationPulseEnabled != pulseEnabled) {
-                    mNotificationPulseEnabled = pulseEnabled;
-                    updateNotificationPulse();
-                }
-            }
-            if (uri == null || ENABLED_NOTIFICATION_LISTENERS_URI.equals(uri)) {
-                rebindListenerServices();
-            }
-        }
-    }
-
-    private SettingsObserver mSettingsObserver;
-
-    static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) {
-        int[] ar = r.getIntArray(resid);
-        if (ar == null) {
-            return def;
-        }
-        final int len = ar.length > maxlen ? maxlen : ar.length;
-        long[] out = new long[len];
-        for (int i=0; i<len; i++) {
-            out[i] = ar[i];
-        }
-        return out;
-    }
-
-    NotificationManagerService(Context context, StatusBarManagerService statusBar,
-            LightsService lights)
-    {
-        super();
-        mContext = context;
-        mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
-        mAm = ActivityManagerNative.getDefault();
-        mUserManager = (UserManager)context.getSystemService(Context.USER_SERVICE);
-        mToastQueue = new ArrayList<ToastRecord>();
-        mHandler = new WorkerHandler();
-
-        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
-
-        importOldBlockDb();
-
-        mStatusBar = statusBar;
-        statusBar.setNotificationCallbacks(mNotificationCallbacks);
-
-        mNotificationLight = lights.getLight(LightsService.LIGHT_ID_NOTIFICATIONS);
-        mAttentionLight = lights.getLight(LightsService.LIGHT_ID_ATTENTION);
-
-        Resources resources = mContext.getResources();
-        mDefaultNotificationColor = resources.getColor(
-                R.color.config_defaultNotificationColor);
-        mDefaultNotificationLedOn = resources.getInteger(
-                R.integer.config_defaultNotificationLedOn);
-        mDefaultNotificationLedOff = resources.getInteger(
-                R.integer.config_defaultNotificationLedOff);
-
-        mDefaultVibrationPattern = getLongArray(resources,
-                R.array.config_defaultNotificationVibePattern,
-                VIBRATE_PATTERN_MAXLEN,
-                DEFAULT_VIBRATE_PATTERN);
-
-        mFallbackVibrationPattern = getLongArray(resources,
-                R.array.config_notificationFallbackVibePattern,
-                VIBRATE_PATTERN_MAXLEN,
-                DEFAULT_VIBRATE_PATTERN);
-
-        // Don't start allowing notifications until the setup wizard has run once.
-        // After that, including subsequent boots, init with notifications turned on.
-        // This works on the first boot because the setup wizard will toggle this
-        // flag at least once and we'll go back to 0 after that.
-        if (0 == Settings.Global.getInt(mContext.getContentResolver(),
-                    Settings.Global.DEVICE_PROVISIONED, 0)) {
-            mDisabledNotifications = StatusBarManager.DISABLE_NOTIFICATION_ALERTS;
-        }
-
-        // register for various Intents
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_SCREEN_ON);
-        filter.addAction(Intent.ACTION_SCREEN_OFF);
-        filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
-        filter.addAction(Intent.ACTION_USER_PRESENT);
-        filter.addAction(Intent.ACTION_USER_STOPPED);
-        filter.addAction(Intent.ACTION_USER_SWITCHED);
-        mContext.registerReceiver(mIntentReceiver, filter);
-        IntentFilter pkgFilter = new IntentFilter();
-        pkgFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
-        pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        pkgFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
-        pkgFilter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
-        pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
-        pkgFilter.addDataScheme("package");
-        mContext.registerReceiver(mIntentReceiver, pkgFilter);
-        IntentFilter sdFilter = new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
-        mContext.registerReceiver(mIntentReceiver, sdFilter);
-
-        mSettingsObserver = new SettingsObserver(mHandler);
-        mSettingsObserver.observe();
-
-        // spin up NotificationScorers
-        String[] notificationScorerNames = resources.getStringArray(
-                R.array.config_notificationScorers);
-        for (String scorerName : notificationScorerNames) {
-            try {
-                Class<?> scorerClass = mContext.getClassLoader().loadClass(scorerName);
-                NotificationScorer scorer = (NotificationScorer) scorerClass.newInstance();
-                scorer.initialize(mContext);
-                mScorers.add(scorer);
-            } catch (ClassNotFoundException e) {
-                Slog.w(TAG, "Couldn't find scorer " + scorerName + ".", e);
-            } catch (InstantiationException e) {
-                Slog.w(TAG, "Couldn't instantiate scorer " + scorerName + ".", e);
-            } catch (IllegalAccessException e) {
-                Slog.w(TAG, "Problem accessing scorer " + scorerName + ".", e);
-            }
-        }
-    }
-
-    /**
-     * Read the old XML-based app block database and import those blockages into the AppOps system.
-     */
-    private void importOldBlockDb() {
-        loadBlockDb();
-
-        PackageManager pm = mContext.getPackageManager();
-        for (String pkg : mBlockedPackages) {
-            PackageInfo info = null;
-            try {
-                info = pm.getPackageInfo(pkg, 0);
-                setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false);
-            } catch (NameNotFoundException e) {
-                // forget you
-            }
-        }
-        mBlockedPackages.clear();
-        if (mPolicyFile != null) {
-            mPolicyFile.delete();
-        }
-    }
-
-    void systemReady() {
-        mAudioService = IAudioService.Stub.asInterface(
-                ServiceManager.getService(Context.AUDIO_SERVICE));
-
-        // no beeping until we're basically done booting
-        mSystemReady = true;
-
-        // make sure our listener services are properly bound
-        rebindListenerServices();
-    }
-
-    // Toasts
-    // ============================================================================
-    public void enqueueToast(String pkg, ITransientNotification callback, int duration)
-    {
-        if (DBG) Slog.i(TAG, "enqueueToast pkg=" + pkg + " callback=" + callback + " duration=" + duration);
-
-        if (pkg == null || callback == null) {
-            Slog.e(TAG, "Not doing toast. pkg=" + pkg + " callback=" + callback);
-            return ;
-        }
-
-        final boolean isSystemToast = isCallerSystem() || ("android".equals(pkg));
-
-        if (ENABLE_BLOCKED_TOASTS && !noteNotificationOp(pkg, Binder.getCallingUid())) {
-            if (!isSystemToast) {
-                Slog.e(TAG, "Suppressing toast from package " + pkg + " by user request.");
-                return;
-            }
-        }
-
-        synchronized (mToastQueue) {
-            int callingPid = Binder.getCallingPid();
-            long callingId = Binder.clearCallingIdentity();
-            try {
-                ToastRecord record;
-                int index = indexOfToastLocked(pkg, callback);
-                // If it's already in the queue, we update it in place, we don't
-                // move it to the end of the queue.
-                if (index >= 0) {
-                    record = mToastQueue.get(index);
-                    record.update(duration);
-                } else {
-                    // Limit the number of toasts that any given package except the android
-                    // package can enqueue.  Prevents DOS attacks and deals with leaks.
-                    if (!isSystemToast) {
-                        int count = 0;
-                        final int N = mToastQueue.size();
-                        for (int i=0; i<N; i++) {
-                             final ToastRecord r = mToastQueue.get(i);
-                             if (r.pkg.equals(pkg)) {
-                                 count++;
-                                 if (count >= MAX_PACKAGE_NOTIFICATIONS) {
-                                     Slog.e(TAG, "Package has already posted " + count
-                                            + " toasts. Not showing more. Package=" + pkg);
-                                     return;
-                                 }
-                             }
-                        }
-                    }
-
-                    record = new ToastRecord(callingPid, pkg, callback, duration);
-                    mToastQueue.add(record);
-                    index = mToastQueue.size() - 1;
-                    keepProcessAliveLocked(callingPid);
-                }
-                // If it's at index 0, it's the current toast.  It doesn't matter if it's
-                // new or just been updated.  Call back and tell it to show itself.
-                // If the callback fails, this will remove it from the list, so don't
-                // assume that it's valid after this.
-                if (index == 0) {
-                    showNextToastLocked();
-                }
-            } finally {
-                Binder.restoreCallingIdentity(callingId);
-            }
-        }
-    }
-
-    public void cancelToast(String pkg, ITransientNotification callback) {
-        Slog.i(TAG, "cancelToast pkg=" + pkg + " callback=" + callback);
-
-        if (pkg == null || callback == null) {
-            Slog.e(TAG, "Not cancelling notification. pkg=" + pkg + " callback=" + callback);
-            return ;
-        }
-
-        synchronized (mToastQueue) {
-            long callingId = Binder.clearCallingIdentity();
-            try {
-                int index = indexOfToastLocked(pkg, callback);
-                if (index >= 0) {
-                    cancelToastLocked(index);
-                } else {
-                    Slog.w(TAG, "Toast already cancelled. pkg=" + pkg + " callback=" + callback);
-                }
-            } finally {
-                Binder.restoreCallingIdentity(callingId);
-            }
-        }
-    }
-
-    private void showNextToastLocked() {
-        ToastRecord record = mToastQueue.get(0);
-        while (record != null) {
-            if (DBG) Slog.d(TAG, "Show pkg=" + record.pkg + " callback=" + record.callback);
-            try {
-                record.callback.show();
-                scheduleTimeoutLocked(record);
-                return;
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Object died trying to show notification " + record.callback
-                        + " in package " + record.pkg);
-                // remove it from the list and let the process die
-                int index = mToastQueue.indexOf(record);
-                if (index >= 0) {
-                    mToastQueue.remove(index);
-                }
-                keepProcessAliveLocked(record.pid);
-                if (mToastQueue.size() > 0) {
-                    record = mToastQueue.get(0);
-                } else {
-                    record = null;
-                }
-            }
-        }
-    }
-
-    private void cancelToastLocked(int index) {
-        ToastRecord record = mToastQueue.get(index);
-        try {
-            record.callback.hide();
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Object died trying to hide notification " + record.callback
-                    + " in package " + record.pkg);
-            // don't worry about this, we're about to remove it from
-            // the list anyway
-        }
-        mToastQueue.remove(index);
-        keepProcessAliveLocked(record.pid);
-        if (mToastQueue.size() > 0) {
-            // Show the next one. If the callback fails, this will remove
-            // it from the list, so don't assume that the list hasn't changed
-            // after this point.
-            showNextToastLocked();
-        }
-    }
-
-    private void scheduleTimeoutLocked(ToastRecord r)
-    {
-        mHandler.removeCallbacksAndMessages(r);
-        Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
-        long delay = r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY;
-        mHandler.sendMessageDelayed(m, delay);
-    }
-
-    private void handleTimeout(ToastRecord record)
-    {
-        if (DBG) Slog.d(TAG, "Timeout pkg=" + record.pkg + " callback=" + record.callback);
-        synchronized (mToastQueue) {
-            int index = indexOfToastLocked(record.pkg, record.callback);
-            if (index >= 0) {
-                cancelToastLocked(index);
-            }
-        }
-    }
-
-    // lock on mToastQueue
-    private int indexOfToastLocked(String pkg, ITransientNotification callback)
-    {
-        IBinder cbak = callback.asBinder();
-        ArrayList<ToastRecord> list = mToastQueue;
-        int len = list.size();
-        for (int i=0; i<len; i++) {
-            ToastRecord r = list.get(i);
-            if (r.pkg.equals(pkg) && r.callback.asBinder() == cbak) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    // lock on mToastQueue
-    private void keepProcessAliveLocked(int pid)
-    {
-        int toastCount = 0; // toasts from this pid
-        ArrayList<ToastRecord> list = mToastQueue;
-        int N = list.size();
-        for (int i=0; i<N; i++) {
-            ToastRecord r = list.get(i);
-            if (r.pid == pid) {
-                toastCount++;
-            }
-        }
-        try {
-            mAm.setProcessForeground(mForegroundToken, pid, toastCount > 0);
-        } catch (RemoteException e) {
-            // Shouldn't happen.
-        }
-    }
-
-    private final class WorkerHandler extends Handler
-    {
-        @Override
-        public void handleMessage(Message msg)
-        {
-            switch (msg.what)
-            {
-                case MESSAGE_TIMEOUT:
-                    handleTimeout((ToastRecord)msg.obj);
-                    break;
-            }
-        }
-    }
-
-
-    // Notifications
-    // ============================================================================
-    public void enqueueNotificationWithTag(String pkg, String basePkg, String tag, int id,
-            Notification notification, int[] idOut, int userId)
-    {
-        enqueueNotificationInternal(pkg, basePkg, Binder.getCallingUid(), Binder.getCallingPid(),
-                tag, id, notification, idOut, userId);
-    }
-    
-    private final static int clamp(int x, int low, int high) {
-        return (x < low) ? low : ((x > high) ? high : x);
-    }
-
-    // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
-    // uid/pid of another application)
-
-    public void enqueueNotificationInternal(final String pkg, String basePkg, final int callingUid,
-            final int callingPid, final String tag, final int id, final Notification notification,
-            int[] idOut, int incomingUserId)
-    {
-        if (DBG) {
-            Slog.v(TAG, "enqueueNotificationInternal: pkg=" + pkg + " id=" + id + " notification=" + notification);
-        }
-        checkCallerIsSystemOrSameApp(pkg);
-        final boolean isSystemNotification = isUidSystem(callingUid) || ("android".equals(pkg));
-
-        final int userId = ActivityManager.handleIncomingUser(callingPid,
-                callingUid, incomingUserId, true, false, "enqueueNotification", pkg);
-        final UserHandle user = new UserHandle(userId);
-
-        // Limit the number of notifications that any given package except the android
-        // package can enqueue.  Prevents DOS attacks and deals with leaks.
-        if (!isSystemNotification) {
-            synchronized (mNotificationList) {
-                int count = 0;
-                final int N = mNotificationList.size();
-                for (int i=0; i<N; i++) {
-                    final NotificationRecord r = mNotificationList.get(i);
-                    if (r.sbn.getPackageName().equals(pkg) && r.sbn.getUserId() == userId) {
-                        count++;
-                        if (count >= MAX_PACKAGE_NOTIFICATIONS) {
-                            Slog.e(TAG, "Package has already posted " + count
-                                    + " notifications.  Not showing more.  package=" + pkg);
-                            return;
-                        }
-                    }
-                }
-            }
-        }
-
-        // This conditional is a dirty hack to limit the logging done on
-        //     behalf of the download manager without affecting other apps.
-        if (!pkg.equals("com.android.providers.downloads")
-                || Log.isLoggable("DownloadManager", Log.VERBOSE)) {
-            EventLog.writeEvent(EventLogTags.NOTIFICATION_ENQUEUE, pkg, id, tag, userId,
-                    notification.toString());
-        }
-
-        if (pkg == null || notification == null) {
-            throw new IllegalArgumentException("null not allowed: pkg=" + pkg
-                    + " id=" + id + " notification=" + notification);
-        }
-        if (notification.icon != 0) {
-            if (notification.contentView == null) {
-                throw new IllegalArgumentException("contentView required: pkg=" + pkg
-                        + " id=" + id + " notification=" + notification);
-            }
-        }
-
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-
-                // === Scoring ===
-
-                // 0. Sanitize inputs
-                notification.priority = clamp(notification.priority, Notification.PRIORITY_MIN,
-                        Notification.PRIORITY_MAX);
-                // Migrate notification flags to scores
-                if (0 != (notification.flags & Notification.FLAG_HIGH_PRIORITY)) {
-                    if (notification.priority < Notification.PRIORITY_MAX) {
-                        notification.priority = Notification.PRIORITY_MAX;
-                    }
-                } else if (SCORE_ONGOING_HIGHER &&
-                        0 != (notification.flags & Notification.FLAG_ONGOING_EVENT)) {
-                    if (notification.priority < Notification.PRIORITY_HIGH) {
-                        notification.priority = Notification.PRIORITY_HIGH;
-                    }
-                }
-
-                // 1. initial score: buckets of 10, around the app
-                int score = notification.priority * NOTIFICATION_PRIORITY_MULTIPLIER; //[-20..20]
-
-                // 2. Consult external heuristics (TBD)
-
-                // 3. Apply local rules
-
-                int initialScore = score;
-                if (!mScorers.isEmpty()) {
-                    if (DBG) Slog.v(TAG, "Initial score is " + score + ".");
-                    for (NotificationScorer scorer : mScorers) {
-                        try {
-                            score = scorer.getScore(notification, score);
-                        } catch (Throwable t) {
-                            Slog.w(TAG, "Scorer threw on .getScore.", t);
-                        }
-                    }
-                    if (DBG) Slog.v(TAG, "Final score is " + score + ".");
-                }
-
-                // add extra to indicate score modified by NotificationScorer
-                notification.extras.putBoolean(Notification.EXTRA_SCORE_MODIFIED,
-                        score != initialScore);
-
-                // blocked apps
-                if (ENABLE_BLOCKED_NOTIFICATIONS && !noteNotificationOp(pkg, callingUid)) {
-                    if (!isSystemNotification) {
-                        score = JUNK_SCORE;
-                        Slog.e(TAG, "Suppressing notification from package " + pkg
-                                + " by user request.");
-                    }
-                }
-
-                if (DBG) {
-                    Slog.v(TAG, "Assigned score=" + score + " to " + notification);
-                }
-
-                if (score < SCORE_DISPLAY_THRESHOLD) {
-                    // Notification will be blocked because the score is too low.
-                    return;
-                }
-
-                // Should this notification make noise, vibe, or use the LED?
-                final boolean canInterrupt = (score >= SCORE_INTERRUPTION_THRESHOLD);
-
-                synchronized (mNotificationList) {
-                    final StatusBarNotification n = new StatusBarNotification(
-                            pkg, id, tag, callingUid, callingPid, score, notification, user);
-                    NotificationRecord r = new NotificationRecord(n);
-                    NotificationRecord old = null;
-
-                    int index = indexOfNotificationLocked(pkg, tag, id, userId);
-                    if (index < 0) {
-                        mNotificationList.add(r);
-                    } else {
-                        old = mNotificationList.remove(index);
-                        mNotificationList.add(index, r);
-                        // Make sure we don't lose the foreground service state.
-                        if (old != null) {
-                            notification.flags |=
-                                old.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE;
-                        }
-                    }
-
-                    // Ensure if this is a foreground service that the proper additional
-                    // flags are set.
-                    if ((notification.flags&Notification.FLAG_FOREGROUND_SERVICE) != 0) {
-                        notification.flags |= Notification.FLAG_ONGOING_EVENT
-                                | Notification.FLAG_NO_CLEAR;
-                    }
-
-                    final int currentUser;
-                    final long token = Binder.clearCallingIdentity();
-                    try {
-                        currentUser = ActivityManager.getCurrentUser();
-                    } finally {
-                        Binder.restoreCallingIdentity(token);
-                    }
-
-                    if (notification.icon != 0) {
-                        if (old != null && old.statusBarKey != null) {
-                            r.statusBarKey = old.statusBarKey;
-                            long identity = Binder.clearCallingIdentity();
-                            try {
-                                mStatusBar.updateNotification(r.statusBarKey, n);
-                            }
-                            finally {
-                                Binder.restoreCallingIdentity(identity);
-                            }
-                        } else {
-                            long identity = Binder.clearCallingIdentity();
-                            try {
-                                r.statusBarKey = mStatusBar.addNotification(n);
-                                if ((n.getNotification().flags & Notification.FLAG_SHOW_LIGHTS) != 0
-                                        && canInterrupt) {
-                                    mAttentionLight.pulse();
-                                }
-                            }
-                            finally {
-                                Binder.restoreCallingIdentity(identity);
-                            }
-                        }
-                        // Send accessibility events only for the current user.
-                        if (currentUser == userId) {
-                            sendAccessibilityEvent(notification, pkg);
-                        }
-
-                        notifyPostedLocked(r);
-                    } else {
-                        Slog.e(TAG, "Not posting notification with icon==0: " + notification);
-                        if (old != null && old.statusBarKey != null) {
-                            long identity = Binder.clearCallingIdentity();
-                            try {
-                                mStatusBar.removeNotification(old.statusBarKey);
-                            }
-                            finally {
-                                Binder.restoreCallingIdentity(identity);
-                            }
-
-                            notifyRemovedLocked(r);
-                        }
-                        // ATTENTION: in a future release we will bail out here
-                        // so that we do not play sounds, show lights, etc. for invalid notifications
-                        Slog.e(TAG, "WARNING: In a future release this will crash the app: "
-                                + n.getPackageName());
-                    }
-
-                    // If we're not supposed to beep, vibrate, etc. then don't.
-                    if (((mDisabledNotifications & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) == 0)
-                            && (!(old != null
-                                && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
-                            && (r.getUserId() == UserHandle.USER_ALL ||
-                                (r.getUserId() == userId && r.getUserId() == currentUser))
-                            && canInterrupt
-                            && mSystemReady) {
-
-                        final AudioManager audioManager = (AudioManager) mContext
-                        .getSystemService(Context.AUDIO_SERVICE);
-
-                        // sound
-
-                        // should we use the default notification sound? (indicated either by
-                        // DEFAULT_SOUND or because notification.sound is pointing at
-                        // Settings.System.NOTIFICATION_SOUND)
-                        final boolean useDefaultSound =
-                               (notification.defaults & Notification.DEFAULT_SOUND) != 0 ||
-                                       Settings.System.DEFAULT_NOTIFICATION_URI
-                                               .equals(notification.sound);
-
-                        Uri soundUri = null;
-                        boolean hasValidSound = false;
-
-                        if (useDefaultSound) {
-                            soundUri = Settings.System.DEFAULT_NOTIFICATION_URI;
-
-                            // check to see if the default notification sound is silent
-                            ContentResolver resolver = mContext.getContentResolver();
-                            hasValidSound = Settings.System.getString(resolver,
-                                   Settings.System.NOTIFICATION_SOUND) != null;
-                        } else if (notification.sound != null) {
-                            soundUri = notification.sound;
-                            hasValidSound = (soundUri != null);
-                        }
-
-                        if (hasValidSound) {
-                            boolean looping = (notification.flags & Notification.FLAG_INSISTENT) != 0;
-                            int audioStreamType;
-                            if (notification.audioStreamType >= 0) {
-                                audioStreamType = notification.audioStreamType;
-                            } else {
-                                audioStreamType = DEFAULT_STREAM_TYPE;
-                            }
-                            mSoundNotification = r;
-                            // do not play notifications if stream volume is 0 (typically because
-                            // ringer mode is silent) or if there is a user of exclusive audio focus
-                            if ((audioManager.getStreamVolume(audioStreamType) != 0)
-                                    && !audioManager.isAudioFocusExclusive()) {
-                                final long identity = Binder.clearCallingIdentity();
-                                try {
-                                    final IRingtonePlayer player = mAudioService.getRingtonePlayer();
-                                    if (player != null) {
-                                        player.playAsync(soundUri, user, looping, audioStreamType);
-                                    }
-                                } catch (RemoteException e) {
-                                } finally {
-                                    Binder.restoreCallingIdentity(identity);
-                                }
-                            }
-                        }
-
-                        // vibrate
-                        // Does the notification want to specify its own vibration?
-                        final boolean hasCustomVibrate = notification.vibrate != null;
-
-                        // new in 4.2: if there was supposed to be a sound and we're in vibrate
-                        // mode, and no other vibration is specified, we fall back to vibration
-                        final boolean convertSoundToVibration =
-                                   !hasCustomVibrate
-                                && hasValidSound
-                                && (audioManager.getRingerMode()
-                                           == AudioManager.RINGER_MODE_VIBRATE);
-
-                        // The DEFAULT_VIBRATE flag trumps any custom vibration AND the fallback.
-                        final boolean useDefaultVibrate =
-                                (notification.defaults & Notification.DEFAULT_VIBRATE) != 0;
-
-                        if ((useDefaultVibrate || convertSoundToVibration || hasCustomVibrate)
-                                && !(audioManager.getRingerMode()
-                                        == AudioManager.RINGER_MODE_SILENT)) {
-                            mVibrateNotification = r;
-
-                            if (useDefaultVibrate || convertSoundToVibration) {
-                                // Escalate privileges so we can use the vibrator even if the
-                                // notifying app does not have the VIBRATE permission.
-                                long identity = Binder.clearCallingIdentity();
-                                try {
-                                    mVibrator.vibrate(r.sbn.getUid(), r.sbn.getBasePkg(),
-                                        useDefaultVibrate ? mDefaultVibrationPattern
-                                            : mFallbackVibrationPattern,
-                                        ((notification.flags & Notification.FLAG_INSISTENT) != 0)
-                                                ? 0: -1);
-                                } finally {
-                                    Binder.restoreCallingIdentity(identity);
-                                }
-                            } else if (notification.vibrate.length > 1) {
-                                // If you want your own vibration pattern, you need the VIBRATE
-                                // permission
-                                mVibrator.vibrate(r.sbn.getUid(), r.sbn.getBasePkg(),
-                                        notification.vibrate,
-                                    ((notification.flags & Notification.FLAG_INSISTENT) != 0)
-                                            ? 0: -1);
-                            }
-                        }
-                    }
-
-                    // light
-                    // the most recent thing gets the light
-                    mLights.remove(old);
-                    if (mLedNotification == old) {
-                        mLedNotification = null;
-                    }
-                    //Slog.i(TAG, "notification.lights="
-                    //        + ((old.notification.lights.flags & Notification.FLAG_SHOW_LIGHTS)
-                    //                  != 0));
-                    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) != 0
-                            && canInterrupt) {
-                        mLights.add(r);
-                        updateLightsLocked();
-                    } else {
-                        if (old != null
-                                && ((old.getFlags() & Notification.FLAG_SHOW_LIGHTS) != 0)) {
-                            updateLightsLocked();
-                        }
-                    }
-                }
-            }
-        });
-
-        idOut[0] = id;
-    }
-
-    private void sendAccessibilityEvent(Notification notification, CharSequence packageName) {
-        AccessibilityManager manager = AccessibilityManager.getInstance(mContext);
-        if (!manager.isEnabled()) {
-            return;
-        }
-
-        AccessibilityEvent event =
-            AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
-        event.setPackageName(packageName);
-        event.setClassName(Notification.class.getName());
-        event.setParcelableData(notification);
-        CharSequence tickerText = notification.tickerText;
-        if (!TextUtils.isEmpty(tickerText)) {
-            event.getText().add(tickerText);
-        }
-
-        manager.sendAccessibilityEvent(event);
-    }
-
-    private void cancelNotificationLocked(NotificationRecord r, boolean sendDelete) {
-        // tell the app
-        if (sendDelete) {
-            if (r.getNotification().deleteIntent != null) {
-                try {
-                    r.getNotification().deleteIntent.send();
-                } catch (PendingIntent.CanceledException ex) {
-                    // do nothing - there's no relevant way to recover, and
-                    //     no reason to let this propagate
-                    Slog.w(TAG, "canceled PendingIntent for " + r.sbn.getPackageName(), ex);
-                }
-            }
-        }
-
-        // status bar
-        if (r.getNotification().icon != 0) {
-            long identity = Binder.clearCallingIdentity();
-            try {
-                mStatusBar.removeNotification(r.statusBarKey);
-            }
-            finally {
-                Binder.restoreCallingIdentity(identity);
-            }
-            r.statusBarKey = null;
-            notifyRemovedLocked(r);
-        }
-
-        // sound
-        if (mSoundNotification == r) {
-            mSoundNotification = null;
-            final long identity = Binder.clearCallingIdentity();
-            try {
-                final IRingtonePlayer player = mAudioService.getRingtonePlayer();
-                if (player != null) {
-                    player.stopAsync();
-                }
-            } catch (RemoteException e) {
-            } finally {
-                Binder.restoreCallingIdentity(identity);
-            }
-        }
-
-        // vibrate
-        if (mVibrateNotification == r) {
-            mVibrateNotification = null;
-            long identity = Binder.clearCallingIdentity();
-            try {
-                mVibrator.cancel();
-            }
-            finally {
-                Binder.restoreCallingIdentity(identity);
-            }
-        }
-
-        // light
-        mLights.remove(r);
-        if (mLedNotification == r) {
-            mLedNotification = null;
-        }
-
-        // Save it for users of getHistoricalNotifications()
-        mArchive.record(r.sbn);
-    }
-
-    /**
-     * Cancels a notification ONLY if it has all of the {@code mustHaveFlags}
-     * and none of the {@code mustNotHaveFlags}.
-     */
-    private void cancelNotification(final String pkg, final String tag, final int id,
-            final int mustHaveFlags, final int mustNotHaveFlags, final boolean sendDelete,
-            final int userId) {
-        // In enqueueNotificationInternal notifications are added by scheduling the
-        // work on the worker handler. Hence, we also schedule the cancel on this
-        // handler to avoid a scenario where an add notification call followed by a
-        // remove notification call ends up in not removing the notification.
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL, pkg, id, tag, userId,
-                        mustHaveFlags, mustNotHaveFlags);
-
-                synchronized (mNotificationList) {
-                    int index = indexOfNotificationLocked(pkg, tag, id, userId);
-                    if (index >= 0) {
-                        NotificationRecord r = mNotificationList.get(index);
-
-                        if ((r.getNotification().flags & mustHaveFlags) != mustHaveFlags) {
-                            return;
-                        }
-                        if ((r.getNotification().flags & mustNotHaveFlags) != 0) {
-                            return;
-                        }
-
-                        mNotificationList.remove(index);
-
-                        cancelNotificationLocked(r, sendDelete);
-                        updateLightsLocked();
-                    }
-                }
-            }
-        });
-    }
-
-    /**
-     * Determine whether the userId applies to the notification in question, either because
-     * they match exactly, or one of them is USER_ALL (which is treated as a wildcard).
-     */
-    private boolean notificationMatchesUserId(NotificationRecord r, int userId) {
-        return
-                // looking for USER_ALL notifications? match everything
-                   userId == UserHandle.USER_ALL
-                // a notification sent to USER_ALL matches any query
-                || r.getUserId() == UserHandle.USER_ALL
-                // an exact user match
-                || r.getUserId() == userId;
-    }
-
-    /**
-     * Cancels all notifications from a given package that have all of the
-     * {@code mustHaveFlags}.
-     */
-    boolean cancelAllNotificationsInt(String pkg, int mustHaveFlags,
-            int mustNotHaveFlags, boolean doit, int userId) {
-        EventLog.writeEvent(EventLogTags.NOTIFICATION_CANCEL_ALL, pkg, userId,
-                mustHaveFlags, mustNotHaveFlags);
-
-        synchronized (mNotificationList) {
-            final int N = mNotificationList.size();
-            boolean canceledSomething = false;
-            for (int i = N-1; i >= 0; --i) {
-                NotificationRecord r = mNotificationList.get(i);
-                if (!notificationMatchesUserId(r, userId)) {
-                    continue;
-                }
-                // Don't remove notifications to all, if there's no package name specified
-                if (r.getUserId() == UserHandle.USER_ALL && pkg == null) {
-                    continue;
-                }
-                if ((r.getFlags() & mustHaveFlags) != mustHaveFlags) {
-                    continue;
-                }
-                if ((r.getFlags() & mustNotHaveFlags) != 0) {
-                    continue;
-                }
-                if (pkg != null && !r.sbn.getPackageName().equals(pkg)) {
-                    continue;
-                }
-                canceledSomething = true;
-                if (!doit) {
-                    return true;
-                }
-                mNotificationList.remove(i);
-                cancelNotificationLocked(r, false);
-            }
-            if (canceledSomething) {
-                updateLightsLocked();
-            }
-            return canceledSomething;
-        }
-    }
-
-    public void cancelNotificationWithTag(String pkg, String tag, int id, int userId) {
-        checkCallerIsSystemOrSameApp(pkg);
-        userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
-                Binder.getCallingUid(), userId, true, false, "cancelNotificationWithTag", pkg);
-        // Don't allow client applications to cancel foreground service notis.
-        cancelNotification(pkg, tag, id, 0,
-                Binder.getCallingUid() == Process.SYSTEM_UID
-                ? 0 : Notification.FLAG_FOREGROUND_SERVICE, false, userId);
-    }
-
-    public void cancelAllNotifications(String pkg, int userId) {
-        checkCallerIsSystemOrSameApp(pkg);
-
-        userId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
-                Binder.getCallingUid(), userId, true, false, "cancelAllNotifications", pkg);
-
-        // Calling from user space, don't allow the canceling of actively
-        // running foreground services.
-        cancelAllNotificationsInt(pkg, 0, Notification.FLAG_FOREGROUND_SERVICE, true, userId);
-    }
-
-    // Return true if the UID is a system or phone UID and therefore should not have
-    // any notifications or toasts blocked.
-    boolean isUidSystem(int uid) {
-        final int appid = UserHandle.getAppId(uid);
-        return (appid == Process.SYSTEM_UID || appid == Process.PHONE_UID || uid == 0);
-    }
-
-    // same as isUidSystem(int, int) for the Binder caller's UID.
-    boolean isCallerSystem() {
-        return isUidSystem(Binder.getCallingUid());
-    }
-
-    void checkCallerIsSystem() {
-        if (isCallerSystem()) {
-            return;
-        }
-        throw new SecurityException("Disallowed call for uid " + Binder.getCallingUid());
-    }
-
-    void checkCallerIsSystemOrSameApp(String pkg) {
-        if (isCallerSystem()) {
-            return;
-        }
-        final int uid = Binder.getCallingUid();
-        try {
-            ApplicationInfo ai = AppGlobals.getPackageManager().getApplicationInfo(
-                    pkg, 0, UserHandle.getCallingUserId());
-            if (!UserHandle.isSameApp(ai.uid, uid)) {
-                throw new SecurityException("Calling uid " + uid + " gave package"
-                        + pkg + " which is owned by uid " + ai.uid);
-            }
-        } catch (RemoteException re) {
-            throw new SecurityException("Unknown package " + pkg + "\n" + re);
-        }
-    }
-
-    void cancelAll(int userId) {
-        synchronized (mNotificationList) {
-            final int N = mNotificationList.size();
-            for (int i=N-1; i>=0; i--) {
-                NotificationRecord r = mNotificationList.get(i);
-
-                if (!notificationMatchesUserId(r, userId)) {
-                    continue;
-                }
-
-                if ((r.getFlags() & (Notification.FLAG_ONGOING_EVENT
-                                | Notification.FLAG_NO_CLEAR)) == 0) {
-                    mNotificationList.remove(i);
-                    cancelNotificationLocked(r, true);
-                }
-            }
-
-            updateLightsLocked();
-        }
-    }
-
-    // lock on mNotificationList
-    private void updateLightsLocked()
-    {
-        // handle notification lights
-        if (mLedNotification == null) {
-            // get next notification, if any
-            int n = mLights.size();
-            if (n > 0) {
-                mLedNotification = mLights.get(n-1);
-            }
-        }
-
-        // Don't flash while we are in a call or screen is on
-        if (mLedNotification == null || mInCall || mScreenOn) {
-            mNotificationLight.turnOff();
-        } else {
-            final Notification ledno = mLedNotification.sbn.getNotification();
-            int ledARGB = ledno.ledARGB;
-            int ledOnMS = ledno.ledOnMS;
-            int ledOffMS = ledno.ledOffMS;
-            if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
-                ledARGB = mDefaultNotificationColor;
-                ledOnMS = mDefaultNotificationLedOn;
-                ledOffMS = mDefaultNotificationLedOff;
-            }
-            if (mNotificationPulseEnabled) {
-                // pulse repeatedly
-                mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED,
-                        ledOnMS, ledOffMS);
-            }
-        }
-    }
-
-    // lock on mNotificationList
-    private int indexOfNotificationLocked(String pkg, String tag, int id, int userId)
-    {
-        ArrayList<NotificationRecord> list = mNotificationList;
-        final int len = list.size();
-        for (int i=0; i<len; i++) {
-            NotificationRecord r = list.get(i);
-            if (!notificationMatchesUserId(r, userId) || r.sbn.getId() != id) {
-                continue;
-            }
-            if (tag == null) {
-                if (r.sbn.getTag() != null) {
-                    continue;
-                }
-            } else {
-                if (!tag.equals(r.sbn.getTag())) {
-                    continue;
-                }
-            }
-            if (r.sbn.getPackageName().equals(pkg)) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    private void updateNotificationPulse() {
-        synchronized (mNotificationList) {
-            updateLightsLocked();
-        }
-    }
-
-    // ======================================================================
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump NotificationManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("Current Notification Manager state:");
-
-        pw.println("  Listeners (" + mEnabledListenersForCurrentUser.size()
-                + ") enabled for current user:");
-        for (ComponentName cmpt : mEnabledListenersForCurrentUser) {
-            pw.println("    " + cmpt);
-        }
-
-        pw.println("  Live listeners (" + mListeners.size() + "):");
-        for (NotificationListenerInfo info : mListeners) {
-            pw.println("    " + info.component
-                    + " (user " + info.userid + "): " + info.listener
-                    + (info.isSystem?" SYSTEM":""));
-        }
-
-        int N;
-
-        synchronized (mToastQueue) {
-            N = mToastQueue.size();
-            if (N > 0) {
-                pw.println("  Toast Queue:");
-                for (int i=0; i<N; i++) {
-                    mToastQueue.get(i).dump(pw, "    ");
-                }
-                pw.println("  ");
-            }
-
-        }
-
-        synchronized (mNotificationList) {
-            N = mNotificationList.size();
-            if (N > 0) {
-                pw.println("  Notification List:");
-                for (int i=0; i<N; i++) {
-                    mNotificationList.get(i).dump(pw, "    ", mContext);
-                }
-                pw.println("  ");
-            }
-
-            N = mLights.size();
-            if (N > 0) {
-                pw.println("  Lights List:");
-                for (int i=0; i<N; i++) {
-                    pw.println("    " + mLights.get(i));
-                }
-                pw.println("  ");
-            }
-
-            pw.println("  mSoundNotification=" + mSoundNotification);
-            pw.println("  mVibrateNotification=" + mVibrateNotification);
-            pw.println("  mDisabledNotifications=0x" + Integer.toHexString(mDisabledNotifications));
-            pw.println("  mSystemReady=" + mSystemReady);
-            pw.println("  mArchive=" + mArchive.toString());
-            Iterator<StatusBarNotification> iter = mArchive.descendingIterator();
-            int i=0;
-            while (iter.hasNext()) {
-                pw.println("    " + iter.next());
-                if (++i >= 5) {
-                    if (iter.hasNext()) pw.println("    ...");
-                    break;
-                }
-            }
-
-        }
-    }
-}
diff --git a/services/java/com/android/server/PackageManagerBackupAgent.java b/services/java/com/android/server/PackageManagerBackupAgent.java
deleted file mode 100644
index 77bddb0..0000000
--- a/services/java/com/android/server/PackageManagerBackupAgent.java
+++ /dev/null
@@ -1,425 +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.
- */
-
-package com.android.server;
-
-import android.app.backup.BackupAgent;
-import android.app.backup.BackupDataInput;
-import android.app.backup.BackupDataOutput;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.Signature;
-import android.os.Build;
-import android.os.ParcelFileDescriptor;
-import android.util.Slog;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.EOFException;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * We back up the signatures of each package so that during a system restore,
- * we can verify that the app whose data we think we have matches the app
- * actually resident on the device.
- *
- * Since the Package Manager isn't a proper "application" we just provide a
- * direct IBackupAgent implementation and hand-construct it at need.
- */
-public class PackageManagerBackupAgent extends BackupAgent {
-    private static final String TAG = "PMBA";
-    private static final boolean DEBUG = false;
-
-    // key under which we store global metadata (individual app metadata
-    // is stored using the package name as a key)
-    private static final String GLOBAL_METADATA_KEY = "@meta@";
-
-    private List<PackageInfo> mAllPackages;
-    private PackageManager mPackageManager;
-    // version & signature info of each app in a restore set
-    private HashMap<String, Metadata> mRestoredSignatures;
-    // The version info of each backed-up app as read from the state file
-    private HashMap<String, Metadata> mStateVersions = new HashMap<String, Metadata>();
-
-    private final HashSet<String> mExisting = new HashSet<String>();
-    private int mStoredSdkVersion;
-    private String mStoredIncrementalVersion;
-    private boolean mHasMetadata;
-
-    public class Metadata {
-        public int versionCode;
-        public Signature[] signatures;
-
-        Metadata(int version, Signature[] sigs) {
-            versionCode = version;
-            signatures = sigs;
-        }
-    }
-
-    // We're constructed with the set of applications that are participating
-    // in backup.  This set changes as apps are installed & removed.
-    PackageManagerBackupAgent(PackageManager packageMgr, List<PackageInfo> packages) {
-        mPackageManager = packageMgr;
-        mAllPackages = packages;
-        mRestoredSignatures = null;
-        mHasMetadata = false;
-    }
-
-    public boolean hasMetadata() {
-        return mHasMetadata;
-    }
-
-    public Metadata getRestoredMetadata(String packageName) {
-        if (mRestoredSignatures == null) {
-            Slog.w(TAG, "getRestoredMetadata() before metadata read!");
-            return null;
-        }
-
-        return mRestoredSignatures.get(packageName);
-    }
-
-    public Set<String> getRestoredPackages() {
-        if (mRestoredSignatures == null) {
-            Slog.w(TAG, "getRestoredPackages() before metadata read!");
-            return null;
-        }
-
-        // This is technically the set of packages on the originating handset
-        // that had backup agents at all, not limited to the set of packages
-        // that had actually contributed a restore dataset, but it's a
-        // close enough approximation for our purposes and does not require any
-        // additional involvement by the transport to obtain.
-        return mRestoredSignatures.keySet();
-    }
-    
-    // The backed up data is the signature block for each app, keyed by
-    // the package name.
-    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
-            ParcelFileDescriptor newState) {
-        if (DEBUG) Slog.v(TAG, "onBackup()");
-
-        ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();  // we'll reuse these
-        DataOutputStream outputBufferStream = new DataOutputStream(outputBuffer);
-        parseStateFile(oldState);
-
-        // If the stored version string differs, we need to re-backup all
-        // of the metadata.  We force this by removing everything from the
-        // "already backed up" map built by parseStateFile().
-        if (mStoredIncrementalVersion == null
-                || !mStoredIncrementalVersion.equals(Build.VERSION.INCREMENTAL)) {
-            Slog.i(TAG, "Previous metadata " + mStoredIncrementalVersion + " mismatch vs "
-                    + Build.VERSION.INCREMENTAL + " - rewriting");
-            mExisting.clear();
-        }
-
-        try {
-            /*
-             * Global metadata:
-             *
-             * int SDKversion -- the SDK version of the OS itself on the device
-             *                   that produced this backup set.  Used to reject
-             *                   backups from later OSes onto earlier ones.
-             * String incremental -- the incremental release name of the OS stored in
-             *                       the backup set.
-             */
-            if (!mExisting.contains(GLOBAL_METADATA_KEY)) {
-                if (DEBUG) Slog.v(TAG, "Storing global metadata key");
-                outputBufferStream.writeInt(Build.VERSION.SDK_INT);
-                outputBufferStream.writeUTF(Build.VERSION.INCREMENTAL);
-                writeEntity(data, GLOBAL_METADATA_KEY, outputBuffer.toByteArray());
-            } else {
-                if (DEBUG) Slog.v(TAG, "Global metadata key already stored");
-                // don't consider it to have been skipped/deleted
-                mExisting.remove(GLOBAL_METADATA_KEY);
-            }
-
-            // For each app we have on device, see if we've backed it up yet.  If not,
-            // write its signature block to the output, keyed on the package name.
-            for (PackageInfo pkg : mAllPackages) {
-                String packName = pkg.packageName;
-                if (packName.equals(GLOBAL_METADATA_KEY)) {
-                    // We've already handled the metadata key; skip it here
-                    continue;
-                } else {
-                    PackageInfo info = null;
-                    try {
-                        info = mPackageManager.getPackageInfo(packName,
-                                PackageManager.GET_SIGNATURES);
-                    } catch (NameNotFoundException e) {
-                        // Weird; we just found it, and now are told it doesn't exist.
-                        // Treat it as having been removed from the device.
-                        mExisting.add(packName);
-                        continue;
-                    }
-
-                    if (mExisting.contains(packName)) {
-                        // We have backed up this app before.  Check whether the version
-                        // of the backup matches the version of the current app; if they
-                        // don't match, the app has been updated and we need to store its
-                        // metadata again.  In either case, take it out of mExisting so that
-                        // we don't consider it deleted later.
-                        mExisting.remove(packName);
-                        if (info.versionCode == mStateVersions.get(packName).versionCode) {
-                            continue;
-                        }
-                    }
-                    
-                    if (info.signatures == null || info.signatures.length == 0)
-                    {
-                        Slog.w(TAG, "Not backing up package " + packName
-                                + " since it appears to have no signatures.");
-                        continue;
-                    }
-
-                    // We need to store this app's metadata
-                    /*
-                     * Metadata for each package:
-                     *
-                     * int version       -- [4] the package's versionCode
-                     * byte[] signatures -- [len] flattened Signature[] of the package
-                     */
-
-                    // marshal the version code in a canonical form
-                    outputBuffer.reset();
-                    outputBufferStream.writeInt(info.versionCode);
-                    writeSignatureArray(outputBufferStream, info.signatures);
-
-                    if (DEBUG) {
-                        Slog.v(TAG, "+ writing metadata for " + packName
-                                + " version=" + info.versionCode
-                                + " entityLen=" + outputBuffer.size());
-                    }
-                    
-                    // Now we can write the backup entity for this package
-                    writeEntity(data, packName, outputBuffer.toByteArray());
-                }
-            }
-
-            // At this point, the only entries in 'existing' are apps that were
-            // mentioned in the saved state file, but appear to no longer be present
-            // on the device.  Write a deletion entity for them.
-            for (String app : mExisting) {
-                if (DEBUG) Slog.v(TAG, "- removing metadata for deleted pkg " + app);
-                try {
-                    data.writeEntityHeader(app, -1);
-                } catch (IOException e) {
-                    Slog.e(TAG, "Unable to write package deletions!");
-                    return;
-                }
-            }
-        } catch (IOException e) {
-            // Real error writing data
-            Slog.e(TAG, "Unable to write package backup data file!");
-            return;
-        }
-
-        // Finally, write the new state blob -- just the list of all apps we handled
-        writeStateFile(mAllPackages, newState);
-    }
-    
-    private static void writeEntity(BackupDataOutput data, String key, byte[] bytes)
-            throws IOException {
-        data.writeEntityHeader(key, bytes.length);
-        data.writeEntityData(bytes, bytes.length);
-    }
-
-    // "Restore" here is a misnomer.  What we're really doing is reading back the
-    // set of app signatures associated with each backed-up app in this restore
-    // image.  We'll use those later to determine what we can legitimately restore.
-    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
-            throws IOException {
-        List<ApplicationInfo> restoredApps = new ArrayList<ApplicationInfo>();
-        HashMap<String, Metadata> sigMap = new HashMap<String, Metadata>();
-        if (DEBUG) Slog.v(TAG, "onRestore()");
-        int storedSystemVersion = -1;
-
-        while (data.readNextHeader()) {
-            String key = data.getKey();
-            int dataSize = data.getDataSize();
-
-            if (DEBUG) Slog.v(TAG, "   got key=" + key + " dataSize=" + dataSize);
-
-            // generic setup to parse any entity data
-            byte[] inputBytes = new byte[dataSize];
-            data.readEntityData(inputBytes, 0, dataSize);
-            ByteArrayInputStream inputBuffer = new ByteArrayInputStream(inputBytes);
-            DataInputStream inputBufferStream = new DataInputStream(inputBuffer);
-
-            if (key.equals(GLOBAL_METADATA_KEY)) {
-                int storedSdkVersion = inputBufferStream.readInt();
-                if (DEBUG) Slog.v(TAG, "   storedSystemVersion = " + storedSystemVersion);
-                if (storedSystemVersion > Build.VERSION.SDK_INT) {
-                    // returning before setting the sig map means we rejected the restore set
-                    Slog.w(TAG, "Restore set was from a later version of Android; not restoring");
-                    return;
-                }
-                mStoredSdkVersion = storedSdkVersion;
-                mStoredIncrementalVersion = inputBufferStream.readUTF();
-                mHasMetadata = true;
-                if (DEBUG) {
-                    Slog.i(TAG, "Restore set version " + storedSystemVersion
-                            + " is compatible with OS version " + Build.VERSION.SDK_INT
-                            + " (" + mStoredIncrementalVersion + " vs "
-                            + Build.VERSION.INCREMENTAL + ")");
-                }
-            } else {
-                // it's a file metadata record
-                int versionCode = inputBufferStream.readInt();
-                Signature[] sigs = readSignatureArray(inputBufferStream);
-                if (DEBUG) {
-                    Slog.i(TAG, "   read metadata for " + key
-                            + " dataSize=" + dataSize
-                            + " versionCode=" + versionCode + " sigs=" + sigs);
-                }
-                
-                if (sigs == null || sigs.length == 0) {
-                    Slog.w(TAG, "Not restoring package " + key
-                            + " since it appears to have no signatures.");
-                    continue;
-                }
-
-                ApplicationInfo app = new ApplicationInfo();
-                app.packageName = key;
-                restoredApps.add(app);
-                sigMap.put(key, new Metadata(versionCode, sigs));
-            }
-        }
-
-        // On successful completion, cache the signature map for the Backup Manager to use
-        mRestoredSignatures = sigMap;
-    }
-
-    private static void writeSignatureArray(DataOutputStream out, Signature[] sigs)
-            throws IOException {
-        // write the number of signatures in the array
-        out.writeInt(sigs.length);
-
-        // write the signatures themselves, length + flattened buffer
-        for (Signature sig : sigs) {
-            byte[] flat = sig.toByteArray();
-            out.writeInt(flat.length);
-            out.write(flat);
-        }
-    }
-
-    private static Signature[] readSignatureArray(DataInputStream in) {
-        try {
-            int num;
-            try {
-                num = in.readInt();
-            } catch (EOFException e) {
-                // clean termination
-                Slog.w(TAG, "Read empty signature block");
-                return null;
-            }
-            
-            if (DEBUG) Slog.v(TAG, " ... unflatten read " + num);
-            
-            // Sensical?
-            if (num > 20) {
-                Slog.e(TAG, "Suspiciously large sig count in restore data; aborting");
-                throw new IllegalStateException("Bad restore state");
-            }
-            
-            Signature[] sigs = new Signature[num];
-            for (int i = 0; i < num; i++) {
-                int len = in.readInt();
-                byte[] flatSig = new byte[len];
-                in.read(flatSig);
-                sigs[i] = new Signature(flatSig);
-            }
-            return sigs;
-        } catch (IOException e) {
-            Slog.e(TAG, "Unable to read signatures");
-            return null;
-        }
-    }
-
-    // Util: parse out an existing state file into a usable structure
-    private void parseStateFile(ParcelFileDescriptor stateFile) {
-        mExisting.clear();
-        mStateVersions.clear();
-        mStoredSdkVersion = 0;
-        mStoredIncrementalVersion = null;
-
-        // The state file is just the list of app names we have stored signatures for
-        // with the exception of the metadata block, to which is also appended the
-        // version numbers corresponding with the last time we wrote this PM block.
-        // If they mismatch the current system, we'll re-store the metadata key.
-        FileInputStream instream = new FileInputStream(stateFile.getFileDescriptor());
-        DataInputStream in = new DataInputStream(instream);
-
-        int bufSize = 256;
-        byte[] buf = new byte[bufSize];
-        try {
-            String pkg = in.readUTF();
-            if (pkg.equals(GLOBAL_METADATA_KEY)) {
-                mStoredSdkVersion = in.readInt();
-                mStoredIncrementalVersion = in.readUTF();
-                mExisting.add(GLOBAL_METADATA_KEY);
-            } else {
-                Slog.e(TAG, "No global metadata in state file!");
-                return;
-            }
-
-            // The global metadata was first; now read all the apps
-            while (true) {
-                pkg = in.readUTF();
-                int versionCode = in.readInt();
-                mExisting.add(pkg);
-                mStateVersions.put(pkg, new Metadata(versionCode, null));
-            }
-        } catch (EOFException eof) {
-            // safe; we're done
-        } catch (IOException e) {
-            // whoops, bad state file.  abort.
-            Slog.e(TAG, "Unable to read Package Manager state file: " + e);
-        }
-    }
-
-    // Util: write out our new backup state file
-    private void writeStateFile(List<PackageInfo> pkgs, ParcelFileDescriptor stateFile) {
-        FileOutputStream outstream = new FileOutputStream(stateFile.getFileDescriptor());
-        DataOutputStream out = new DataOutputStream(outstream);
-
-        try {
-            // by the time we get here we know we've stored the global metadata record
-            out.writeUTF(GLOBAL_METADATA_KEY);
-            out.writeInt(Build.VERSION.SDK_INT);
-            out.writeUTF(Build.VERSION.INCREMENTAL);
-
-            // now write all the app names too
-            for (PackageInfo pkg : pkgs) {
-                out.writeUTF(pkg.packageName);
-                out.writeInt(pkg.versionCode);
-            }
-        } catch (IOException e) {
-            Slog.e(TAG, "Unable to write package manager state file!");
-            return;
-        }
-    }
-}
diff --git a/services/java/com/android/server/PreferredComponent.java b/services/java/com/android/server/PreferredComponent.java
deleted file mode 100644
index a7af252..0000000
--- a/services/java/com/android/server/PreferredComponent.java
+++ /dev/null
@@ -1,234 +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.server;
-
-import com.android.internal.util.XmlUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.content.ComponentName;
-import android.content.IntentFilter;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ResolveInfo;
-import android.util.Slog;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.List;
-
-public class PreferredComponent {
-    private static final String TAG_SET = "set";
-    private static final String ATTR_ALWAYS = "always"; // boolean
-    private static final String ATTR_MATCH = "match"; // number
-    private static final String ATTR_NAME = "name"; // component name
-    private static final String ATTR_SET = "set"; // number
-
-    public final int mMatch;
-    public final ComponentName mComponent;
-    // Whether this is to be the one that's always chosen. If false, it's the most recently chosen.
-    public boolean mAlways;
-
-    private final String[] mSetPackages;
-    private final String[] mSetClasses;
-    private final String[] mSetComponents;
-    private final String mShortComponent;
-    private String mParseError;
-
-    private final Callbacks mCallbacks;
-
-    public interface Callbacks {
-        public boolean onReadTag(String tagName, XmlPullParser parser)
-                throws XmlPullParserException, IOException;
-    }
-
-    public PreferredComponent(Callbacks callbacks, int match, ComponentName[] set,
-            ComponentName component, boolean always) {
-        mCallbacks = callbacks;
-        mMatch = match&IntentFilter.MATCH_CATEGORY_MASK;
-        mComponent = component;
-        mAlways = always;
-        mShortComponent = component.flattenToShortString();
-        mParseError = null;
-        if (set != null) {
-            final int N = set.length;
-            String[] myPackages = new String[N];
-            String[] myClasses = new String[N];
-            String[] myComponents = new String[N];
-            for (int i=0; i<N; i++) {
-                ComponentName cn = set[i];
-                if (cn == null) {
-                    mSetPackages = null;
-                    mSetClasses = null;
-                    mSetComponents = null;
-                    return;
-                }
-                myPackages[i] = cn.getPackageName().intern();
-                myClasses[i] = cn.getClassName().intern();
-                myComponents[i] = cn.flattenToShortString();
-            }
-            mSetPackages = myPackages;
-            mSetClasses = myClasses;
-            mSetComponents = myComponents;
-        } else {
-            mSetPackages = null;
-            mSetClasses = null;
-            mSetComponents = null;
-        }
-    }
-
-    public PreferredComponent(Callbacks callbacks, XmlPullParser parser)
-            throws XmlPullParserException, IOException {
-        mCallbacks = callbacks;
-        mShortComponent = parser.getAttributeValue(null, ATTR_NAME);
-        mComponent = ComponentName.unflattenFromString(mShortComponent);
-        if (mComponent == null) {
-            mParseError = "Bad activity name " + mShortComponent;
-        }
-        String matchStr = parser.getAttributeValue(null, ATTR_MATCH);
-        mMatch = matchStr != null ? Integer.parseInt(matchStr, 16) : 0;
-        String setCountStr = parser.getAttributeValue(null, ATTR_SET);
-        int setCount = setCountStr != null ? Integer.parseInt(setCountStr) : 0;
-        String alwaysStr = parser.getAttributeValue(null, ATTR_ALWAYS);
-        mAlways = alwaysStr != null ? Boolean.parseBoolean(alwaysStr) : true;
-
-        String[] myPackages = setCount > 0 ? new String[setCount] : null;
-        String[] myClasses = setCount > 0 ? new String[setCount] : null;
-        String[] myComponents = setCount > 0 ? new String[setCount] : null;
-
-        int setPos = 0;
-
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-               && (type != XmlPullParser.END_TAG
-                       || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG
-                    || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            //Log.i(TAG, "Parse outerDepth=" + outerDepth + " depth="
-            //        + parser.getDepth() + " tag=" + tagName);
-            if (tagName.equals(TAG_SET)) {
-                String name = parser.getAttributeValue(null, ATTR_NAME);
-                if (name == null) {
-                    if (mParseError == null) {
-                        mParseError = "No name in set tag in preferred activity "
-                            + mShortComponent;
-                    }
-                } else if (setPos >= setCount) {
-                    if (mParseError == null) {
-                        mParseError = "Too many set tags in preferred activity "
-                            + mShortComponent;
-                    }
-                } else {
-                    ComponentName cn = ComponentName.unflattenFromString(name);
-                    if (cn == null) {
-                        if (mParseError == null) {
-                            mParseError = "Bad set name " + name + " in preferred activity "
-                                + mShortComponent;
-                        }
-                    } else {
-                        myPackages[setPos] = cn.getPackageName();
-                        myClasses[setPos] = cn.getClassName();
-                        myComponents[setPos] = name;
-                        setPos++;
-                    }
-                }
-                XmlUtils.skipCurrentTag(parser);
-            } else if (!mCallbacks.onReadTag(tagName, parser)) {
-                Slog.w("PreferredComponent", "Unknown element: " + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-
-        if (setPos != setCount) {
-            if (mParseError == null) {
-                mParseError = "Not enough set tags (expected " + setCount
-                    + " but found " + setPos + ") in " + mShortComponent;
-            }
-        }
-
-        mSetPackages = myPackages;
-        mSetClasses = myClasses;
-        mSetComponents = myComponents;
-    }
-
-    public String getParseError() {
-        return mParseError;
-    }
-
-    public void writeToXml(XmlSerializer serializer, boolean full) throws IOException {
-        final int NS = mSetClasses != null ? mSetClasses.length : 0;
-        serializer.attribute(null, ATTR_NAME, mShortComponent);
-        if (full) {
-            if (mMatch != 0) {
-                serializer.attribute(null, ATTR_MATCH, Integer.toHexString(mMatch));
-            }
-            serializer.attribute(null, ATTR_ALWAYS, Boolean.toString(mAlways));
-            serializer.attribute(null, ATTR_SET, Integer.toString(NS));
-            for (int s=0; s<NS; s++) {
-                serializer.startTag(null, TAG_SET);
-                serializer.attribute(null, ATTR_NAME, mSetComponents[s]);
-                serializer.endTag(null, TAG_SET);
-            }
-        }
-    }
-
-    public boolean sameSet(List<ResolveInfo> query, int priority) {
-        if (mSetPackages == null) return false;
-        final int NQ = query.size();
-        final int NS = mSetPackages.length;
-        int numMatch = 0;
-        for (int i=0; i<NQ; i++) {
-            ResolveInfo ri = query.get(i);
-            if (ri.priority != priority) continue;
-            ActivityInfo ai = ri.activityInfo;
-            boolean good = false;
-            for (int j=0; j<NS; j++) {
-                if (mSetPackages[j].equals(ai.packageName)
-                        && mSetClasses[j].equals(ai.name)) {
-                    numMatch++;
-                    good = true;
-                    break;
-                }
-            }
-            if (!good) return false;
-        }
-        return numMatch == NS;
-    }
-
-    public void dump(PrintWriter out, String prefix, Object ident) {
-        out.print(prefix); out.print(
-                Integer.toHexString(System.identityHashCode(ident)));
-                out.print(' ');
-                out.println(mShortComponent);
-        out.print(prefix); out.print(" mMatch=0x");
-                out.print(Integer.toHexString(mMatch));
-                out.print(" mAlways="); out.println(mAlways);
-        if (mSetComponents != null) {
-            out.print(prefix); out.println("  Selected from:");
-            for (int i=0; i<mSetComponents.length; i++) {
-                out.print(prefix); out.print("    ");
-                        out.println(mSetComponents[i]);
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/RandomBlock.java b/services/java/com/android/server/RandomBlock.java
deleted file mode 100644
index e5d7301..0000000
--- a/services/java/com/android/server/RandomBlock.java
+++ /dev/null
@@ -1,101 +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.
- */
-
-package com.android.server;
-
-import android.util.Slog;
-
-import java.io.Closeable;
-import java.io.DataOutput;
-import java.io.EOFException;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
-
-/**
- * A 4k block of random {@code byte}s.
- */
-class RandomBlock {
-
-    private static final String TAG = "RandomBlock";
-    private static final boolean DEBUG = false;
-    private static final int BLOCK_SIZE = 4096;
-    private byte[] block = new byte[BLOCK_SIZE];
-
-    private RandomBlock() { }
-
-    static RandomBlock fromFile(String filename) throws IOException {
-        if (DEBUG) Slog.v(TAG, "reading from file " + filename);
-        InputStream stream = null;
-        try {
-            stream = new FileInputStream(filename);
-            return fromStream(stream);
-        } finally {
-            close(stream);
-        }
-    }
-
-    private static RandomBlock fromStream(InputStream in) throws IOException {
-        RandomBlock retval = new RandomBlock();
-        int total = 0;
-        while(total < BLOCK_SIZE) {
-            int result = in.read(retval.block, total, BLOCK_SIZE - total);
-            if (result == -1) {
-                throw new EOFException();
-            }
-            total += result;
-        }
-        return retval;
-    }
-
-    void toFile(String filename, boolean sync) throws IOException {
-        if (DEBUG) Slog.v(TAG, "writing to file " + filename);
-        RandomAccessFile out = null;
-        try {
-            out = new RandomAccessFile(filename, sync ? "rws" : "rw");
-            toDataOut(out);
-            truncateIfPossible(out);
-        } finally {
-            close(out);
-        }
-    }
-
-    private static void truncateIfPossible(RandomAccessFile f) {
-        try {
-            f.setLength(BLOCK_SIZE);
-        } catch (IOException e) {
-            // ignore this exception.  Sometimes, the file we're trying to
-            // write is a character device, such as /dev/urandom, and
-            // these character devices do not support setting the length.
-        }
-    }
-
-    private void toDataOut(DataOutput out) throws IOException {
-        out.write(block);
-    }
-
-    private static void close(Closeable c) {
-        try {
-            if (c == null) {
-                return;
-            }
-            c.close();
-        } catch (IOException e) {
-            Slog.w(TAG, "IOException thrown while closing Closeable", e);
-        }
-    }
-}
diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java
deleted file mode 100644
index f207c08..0000000
--- a/services/java/com/android/server/StatusBarManagerService.java
+++ /dev/null
@@ -1,661 +0,0 @@
-/*
- * Copyright (C) 2007 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;
-
-import android.app.StatusBarManager;
-import android.service.notification.StatusBarNotification;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.util.Slog;
-
-import com.android.internal.statusbar.IStatusBar;
-import com.android.internal.statusbar.IStatusBarService;
-import com.android.internal.statusbar.StatusBarIcon;
-import com.android.internal.statusbar.StatusBarIconList;
-import com.android.server.wm.WindowManagerService;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-
-/**
- * A note on locking:  We rely on the fact that calls onto mBar are oneway or
- * if they are local, that they just enqueue messages to not deadlock.
- */
-public class StatusBarManagerService extends IStatusBarService.Stub
-    implements WindowManagerService.OnHardKeyboardStatusChangeListener
-{
-    static final String TAG = "StatusBarManagerService";
-    static final boolean SPEW = false;
-
-    final Context mContext;
-    final WindowManagerService mWindowManager;
-    Handler mHandler = new Handler();
-    NotificationCallbacks mNotificationCallbacks;
-    volatile IStatusBar mBar;
-    StatusBarIconList mIcons = new StatusBarIconList();
-    HashMap<IBinder,StatusBarNotification> mNotifications
-            = new HashMap<IBinder,StatusBarNotification>();
-
-    // for disabling the status bar
-    final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
-    IBinder mSysUiVisToken = new Binder();
-    int mDisabled = 0;
-
-    Object mLock = new Object();
-    // encompasses lights-out mode and other flags defined on View
-    int mSystemUiVisibility = 0;
-    boolean mMenuVisible = false;
-    int mImeWindowVis = 0;
-    int mImeBackDisposition;
-    IBinder mImeToken = null;
-    int mCurrentUserId;
-
-    private class DisableRecord implements IBinder.DeathRecipient {
-        int userId;
-        String pkg;
-        int what;
-        IBinder token;
-
-        public void binderDied() {
-            Slog.i(TAG, "binder died for pkg=" + pkg);
-            disableInternal(userId, 0, token, pkg);
-            token.unlinkToDeath(this, 0);
-        }
-    }
-
-    public interface NotificationCallbacks {
-        void onSetDisabled(int status);
-        void onClearAll();
-        void onNotificationClick(String pkg, String tag, int id);
-        void onNotificationClear(String pkg, String tag, int id);
-        void onPanelRevealed();
-        void onNotificationError(String pkg, String tag, int id,
-                int uid, int initialPid, String message);
-    }
-
-    /**
-     * Construct the service, add the status bar view to the window manager
-     */
-    public StatusBarManagerService(Context context, WindowManagerService windowManager) {
-        mContext = context;
-        mWindowManager = windowManager;
-        mWindowManager.setOnHardKeyboardStatusChangeListener(this);
-
-        final Resources res = context.getResources();
-        mIcons.defineSlots(res.getStringArray(com.android.internal.R.array.config_statusBarIcons));
-    }
-
-    public void setNotificationCallbacks(NotificationCallbacks listener) {
-        mNotificationCallbacks = listener;
-    }
-
-    // ================================================================================
-    // From IStatusBarService
-    // ================================================================================
-    public void expandNotificationsPanel() {
-        enforceExpandStatusBar();
-
-        if (mBar != null) {
-            try {
-                mBar.animateExpandNotificationsPanel();
-            } catch (RemoteException ex) {
-            }
-        }
-    }
-
-    public void collapsePanels() {
-        enforceExpandStatusBar();
-
-        if (mBar != null) {
-            try {
-                mBar.animateCollapsePanels();
-            } catch (RemoteException ex) {
-            }
-        }
-    }
-
-    public void expandSettingsPanel() {
-        enforceExpandStatusBar();
-
-        if (mBar != null) {
-            try {
-                mBar.animateExpandSettingsPanel();
-            } catch (RemoteException ex) {
-            }
-        }
-    }
-
-    public void disable(int what, IBinder token, String pkg) {
-        disableInternal(mCurrentUserId, what, token, pkg);
-    }
-
-    private void disableInternal(int userId, int what, IBinder token, String pkg) {
-        enforceStatusBar();
-
-        synchronized (mLock) {
-            disableLocked(userId, what, token, pkg);
-        }
-    }
-
-    private void disableLocked(int userId, int what, IBinder token, String pkg) {
-        // It's important that the the callback and the call to mBar get done
-        // in the same order when multiple threads are calling this function
-        // so they are paired correctly.  The messages on the handler will be
-        // handled in the order they were enqueued, but will be outside the lock.
-        manageDisableListLocked(userId, what, token, pkg);
-
-        // Ensure state for the current user is applied, even if passed a non-current user.
-        final int net = gatherDisableActionsLocked(mCurrentUserId);
-        if (net != mDisabled) {
-            mDisabled = net;
-            mHandler.post(new Runnable() {
-                    public void run() {
-                        mNotificationCallbacks.onSetDisabled(net);
-                    }
-                });
-            if (mBar != null) {
-                try {
-                    mBar.disable(net);
-                } catch (RemoteException ex) {
-                }
-            }
-        }
-    }
-
-    public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
-            String contentDescription) {
-        enforceStatusBar();
-
-        synchronized (mIcons) {
-            int index = mIcons.getSlotIndex(slot);
-            if (index < 0) {
-                throw new SecurityException("invalid status bar icon slot: " + slot);
-            }
-
-            StatusBarIcon icon = new StatusBarIcon(iconPackage, UserHandle.OWNER, iconId,
-                    iconLevel, 0,
-                    contentDescription);
-            //Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
-            mIcons.setIcon(index, icon);
-
-            if (mBar != null) {
-                try {
-                    mBar.setIcon(index, icon);
-                } catch (RemoteException ex) {
-                }
-            }
-        }
-    }
-
-    public void setIconVisibility(String slot, boolean visible) {
-        enforceStatusBar();
-
-        synchronized (mIcons) {
-            int index = mIcons.getSlotIndex(slot);
-            if (index < 0) {
-                throw new SecurityException("invalid status bar icon slot: " + slot);
-            }
-
-            StatusBarIcon icon = mIcons.getIcon(index);
-            if (icon == null) {
-                return;
-            }
-
-            if (icon.visible != visible) {
-                icon.visible = visible;
-
-                if (mBar != null) {
-                    try {
-                        mBar.setIcon(index, icon);
-                    } catch (RemoteException ex) {
-                    }
-                }
-            }
-        }
-    }
-
-    public void removeIcon(String slot) {
-        enforceStatusBar();
-
-        synchronized (mIcons) {
-            int index = mIcons.getSlotIndex(slot);
-            if (index < 0) {
-                throw new SecurityException("invalid status bar icon slot: " + slot);
-            }
-
-            mIcons.removeIcon(index);
-
-            if (mBar != null) {
-                try {
-                    mBar.removeIcon(index);
-                } catch (RemoteException ex) {
-                }
-            }
-        }
-    }
-
-    /** 
-     * Hide or show the on-screen Menu key. Only call this from the window manager, typically in
-     * response to a window with FLAG_NEEDS_MENU_KEY set.
-     */
-    public void topAppWindowChanged(final boolean menuVisible) {
-        enforceStatusBar();
-
-        if (SPEW) Slog.d(TAG, (menuVisible?"showing":"hiding") + " MENU key");
-
-        synchronized(mLock) {
-            mMenuVisible = menuVisible;
-            mHandler.post(new Runnable() {
-                    public void run() {
-                        if (mBar != null) {
-                            try {
-                                mBar.topAppWindowChanged(menuVisible);
-                            } catch (RemoteException ex) {
-                            }
-                        }
-                    }
-                });
-        }
-    }
-
-    public void setImeWindowStatus(final IBinder token, final int vis, final int backDisposition) {
-        enforceStatusBar();
-
-        if (SPEW) {
-            Slog.d(TAG, "swetImeWindowStatus vis=" + vis + " backDisposition=" + backDisposition);
-        }
-
-        synchronized(mLock) {
-            // In case of IME change, we need to call up setImeWindowStatus() regardless of
-            // mImeWindowVis because mImeWindowVis may not have been set to false when the
-            // previous IME was destroyed.
-            mImeWindowVis = vis;
-            mImeBackDisposition = backDisposition;
-            mImeToken = token;
-            mHandler.post(new Runnable() {
-                public void run() {
-                    if (mBar != null) {
-                        try {
-                            mBar.setImeWindowStatus(token, vis, backDisposition);
-                        } catch (RemoteException ex) {
-                        }
-                    }
-                }
-            });
-        }
-    }
-
-    public void setSystemUiVisibility(int vis, int mask) {
-        // also allows calls from window manager which is in this process.
-        enforceStatusBarService();
-
-        if (SPEW) Slog.d(TAG, "setSystemUiVisibility(0x" + Integer.toHexString(vis) + ")");
-
-        synchronized (mLock) {
-            updateUiVisibilityLocked(vis, mask);
-            disableLocked(
-                    mCurrentUserId,
-                    vis & StatusBarManager.DISABLE_MASK,
-                    mSysUiVisToken,
-                    "WindowManager.LayoutParams");
-        }
-    }
-
-    private void updateUiVisibilityLocked(final int vis, final int mask) {
-        if (mSystemUiVisibility != vis) {
-            mSystemUiVisibility = vis;
-            mHandler.post(new Runnable() {
-                    public void run() {
-                        if (mBar != null) {
-                            try {
-                                mBar.setSystemUiVisibility(vis, mask);
-                            } catch (RemoteException ex) {
-                            }
-                        }
-                    }
-                });
-        }
-    }
-
-    public void setHardKeyboardEnabled(final boolean enabled) {
-        mHandler.post(new Runnable() {
-            public void run() {
-                mWindowManager.setHardKeyboardEnabled(enabled);
-            }
-        });
-    }
-
-    @Override
-    public void onHardKeyboardStatusChange(final boolean available, final boolean enabled) {
-        mHandler.post(new Runnable() {
-            public void run() {
-                if (mBar != null) {
-                    try {
-                        mBar.setHardKeyboardStatus(available, enabled);
-                    } catch (RemoteException ex) {
-                    }
-                }
-            }
-        });
-    }
-
-    @Override
-    public void toggleRecentApps() {
-        if (mBar != null) {
-            try {
-                mBar.toggleRecentApps();
-            } catch (RemoteException ex) {}
-        }
-    }
-
-    @Override
-    public void preloadRecentApps() {
-        if (mBar != null) {
-            try {
-                mBar.preloadRecentApps();
-            } catch (RemoteException ex) {}
-        }
-    }
-
-    @Override
-    public void cancelPreloadRecentApps() {
-        if (mBar != null) {
-            try {
-                mBar.cancelPreloadRecentApps();
-            } catch (RemoteException ex) {}
-        }
-    }
-
-    @Override
-    public void setCurrentUser(int newUserId) {
-        if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
-        mCurrentUserId = newUserId;
-    }
-
-    @Override
-    public void setWindowState(int window, int state) {
-        if (mBar != null) {
-            try {
-                mBar.setWindowState(window, state);
-            } catch (RemoteException ex) {}
-        }
-    }
-
-    private void enforceStatusBar() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
-                "StatusBarManagerService");
-    }
-
-    private void enforceExpandStatusBar() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.EXPAND_STATUS_BAR,
-                "StatusBarManagerService");
-    }
-
-    private void enforceStatusBarService() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR_SERVICE,
-                "StatusBarManagerService");
-    }
-
-    // ================================================================================
-    // Callbacks from the status bar service.
-    // ================================================================================
-    public void registerStatusBar(IStatusBar bar, StatusBarIconList iconList,
-            List<IBinder> notificationKeys, List<StatusBarNotification> notifications,
-            int switches[], List<IBinder> binders) {
-        enforceStatusBarService();
-
-        Slog.i(TAG, "registerStatusBar bar=" + bar);
-        mBar = bar;
-        synchronized (mIcons) {
-            iconList.copyFrom(mIcons);
-        }
-        synchronized (mNotifications) {
-            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
-                notificationKeys.add(e.getKey());
-                notifications.add(e.getValue());
-            }
-        }
-        synchronized (mLock) {
-            switches[0] = gatherDisableActionsLocked(mCurrentUserId);
-            switches[1] = mSystemUiVisibility;
-            switches[2] = mMenuVisible ? 1 : 0;
-            switches[3] = mImeWindowVis;
-            switches[4] = mImeBackDisposition;
-            binders.add(mImeToken);
-        }
-        switches[5] = mWindowManager.isHardKeyboardAvailable() ? 1 : 0;
-        switches[6] = mWindowManager.isHardKeyboardEnabled() ? 1 : 0;
-    }
-
-    /**
-     * The status bar service should call this each time the user brings the panel from
-     * invisible to visible in order to clear the notification light.
-     */
-    public void onPanelRevealed() {
-        enforceStatusBarService();
-
-        // tell the notification manager to turn off the lights.
-        mNotificationCallbacks.onPanelRevealed();
-    }
-
-    public void onNotificationClick(String pkg, String tag, int id) {
-        enforceStatusBarService();
-
-        mNotificationCallbacks.onNotificationClick(pkg, tag, id);
-    }
-
-    public void onNotificationError(String pkg, String tag, int id,
-            int uid, int initialPid, String message) {
-        enforceStatusBarService();
-
-        // WARNING: this will call back into us to do the remove.  Don't hold any locks.
-        mNotificationCallbacks.onNotificationError(pkg, tag, id, uid, initialPid, message);
-    }
-
-    public void onNotificationClear(String pkg, String tag, int id) {
-        enforceStatusBarService();
-
-        mNotificationCallbacks.onNotificationClear(pkg, tag, id);
-    }
-
-    public void onClearAllNotifications() {
-        enforceStatusBarService();
-
-        mNotificationCallbacks.onClearAll();
-    }
-
-    // ================================================================================
-    // Callbacks for NotificationManagerService.
-    // ================================================================================
-    public IBinder addNotification(StatusBarNotification notification) {
-        synchronized (mNotifications) {
-            IBinder key = new Binder();
-            mNotifications.put(key, notification);
-            if (mBar != null) {
-                try {
-                    mBar.addNotification(key, notification);
-                } catch (RemoteException ex) {
-                }
-            }
-            return key;
-        }
-    }
-
-    public void updateNotification(IBinder key, StatusBarNotification notification) {
-        synchronized (mNotifications) {
-            if (!mNotifications.containsKey(key)) {
-                throw new IllegalArgumentException("updateNotification key not found: " + key);
-            }
-            mNotifications.put(key, notification);
-            if (mBar != null) {
-                try {
-                    mBar.updateNotification(key, notification);
-                } catch (RemoteException ex) {
-                }
-            }
-        }
-    }
-
-    public void removeNotification(IBinder key) {
-        synchronized (mNotifications) {
-            final StatusBarNotification n = mNotifications.remove(key);
-            if (n == null) {
-                Slog.e(TAG, "removeNotification key not found: " + key);
-                return;
-            }
-            if (mBar != null) {
-                try {
-                    mBar.removeNotification(key);
-                } catch (RemoteException ex) {
-                }
-            }
-        }
-    }
-
-    // ================================================================================
-    // Can be called from any thread
-    // ================================================================================
-
-    // lock on mDisableRecords
-    void manageDisableListLocked(int userId, int what, IBinder token, String pkg) {
-        if (SPEW) {
-            Slog.d(TAG, "manageDisableList userId=" + userId
-                    + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
-        }
-        // update the list
-        final int N = mDisableRecords.size();
-        DisableRecord tok = null;
-        int i;
-        for (i=0; i<N; i++) {
-            DisableRecord t = mDisableRecords.get(i);
-            if (t.token == token && t.userId == userId) {
-                tok = t;
-                break;
-            }
-        }
-        if (what == 0 || !token.isBinderAlive()) {
-            if (tok != null) {
-                mDisableRecords.remove(i);
-                tok.token.unlinkToDeath(tok, 0);
-            }
-        } else {
-            if (tok == null) {
-                tok = new DisableRecord();
-                tok.userId = userId;
-                try {
-                    token.linkToDeath(tok, 0);
-                }
-                catch (RemoteException ex) {
-                    return; // give up
-                }
-                mDisableRecords.add(tok);
-            }
-            tok.what = what;
-            tok.token = token;
-            tok.pkg = pkg;
-        }
-    }
-
-    // lock on mDisableRecords
-    int gatherDisableActionsLocked(int userId) {
-        final int N = mDisableRecords.size();
-        // gather the new net flags
-        int net = 0;
-        for (int i=0; i<N; i++) {
-            final DisableRecord rec = mDisableRecords.get(i);
-            if (rec.userId == userId) {
-                net |= rec.what;
-            }
-        }
-        return net;
-    }
-
-    // ================================================================================
-    // Always called from UI thread
-    // ================================================================================
-
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump StatusBar from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mIcons) {
-            mIcons.dump(pw);
-        }
-
-        synchronized (mNotifications) {
-            int i=0;
-            pw.println("Notification list:");
-            for (Map.Entry<IBinder,StatusBarNotification> e: mNotifications.entrySet()) {
-                pw.printf("  %2d: %s\n", i, e.getValue().toString());
-                i++;
-            }
-        }
-
-        synchronized (mLock) {
-            pw.println("  mDisabled=0x" + Integer.toHexString(mDisabled));
-            final int N = mDisableRecords.size();
-            pw.println("  mDisableRecords.size=" + N);
-            for (int i=0; i<N; i++) {
-                DisableRecord tok = mDisableRecords.get(i);
-                pw.println("    [" + i + "] userId=" + tok.userId
-                                + " what=0x" + Integer.toHexString(tok.what)
-                                + " pkg=" + tok.pkg
-                                + " token=" + tok.token);
-            }
-        }
-    }
-
-    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        public void onReceive(Context context, Intent intent) {
-            String action = intent.getAction();
-            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)
-                    || Intent.ACTION_SCREEN_OFF.equals(action)) {
-                collapsePanels();
-            }
-            /*
-            else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) {
-                updateNetworkName(intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_SPN, false),
-                        intent.getStringExtra(Telephony.Intents.EXTRA_SPN),
-                        intent.getBooleanExtra(Telephony.Intents.EXTRA_SHOW_PLMN, false),
-                        intent.getStringExtra(Telephony.Intents.EXTRA_PLMN));
-            }
-            else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
-                updateResources();
-            }
-            */
-        }
-    };
-
-}
diff --git a/services/java/com/android/server/SystemBackupAgent.java b/services/java/com/android/server/SystemBackupAgent.java
deleted file mode 100644
index 8cf273d..0000000
--- a/services/java/com/android/server/SystemBackupAgent.java
+++ /dev/null
@@ -1,165 +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.
- */
-
-package com.android.server;
-
-
-import android.app.backup.BackupDataInput;
-import android.app.backup.BackupDataOutput;
-import android.app.backup.BackupAgentHelper;
-import android.app.backup.FullBackup;
-import android.app.backup.FullBackupDataOutput;
-import android.app.backup.WallpaperBackupHelper;
-import android.content.Context;
-import android.os.Environment;
-import android.os.ParcelFileDescriptor;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.util.Slog;
-
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Backup agent for various system-managed data, currently just the system wallpaper
- */
-public class SystemBackupAgent extends BackupAgentHelper {
-    private static final String TAG = "SystemBackupAgent";
-
-    // These paths must match what the WallpaperManagerService uses.  The leaf *_FILENAME
-    // are also used in the full-backup file format, so must not change unless steps are
-    // taken to support the legacy backed-up datasets.
-    private static final String WALLPAPER_IMAGE_FILENAME = "wallpaper";
-    private static final String WALLPAPER_INFO_FILENAME = "wallpaper_info.xml";
-
-    // TODO: Will need to change if backing up non-primary user's wallpaper
-    private static final String WALLPAPER_IMAGE_DIR =
-            Environment.getUserSystemDirectory(UserHandle.USER_OWNER).getAbsolutePath();
-    private static final String WALLPAPER_IMAGE = WallpaperBackupHelper.WALLPAPER_IMAGE;
-
-    // TODO: Will need to change if backing up non-primary user's wallpaper
-    private static final String WALLPAPER_INFO_DIR =
-            Environment.getUserSystemDirectory(UserHandle.USER_OWNER).getAbsolutePath();
-    private static final String WALLPAPER_INFO = WallpaperBackupHelper.WALLPAPER_INFO;
-    // Use old keys to keep legacy data compatibility and avoid writing two wallpapers
-    private static final String WALLPAPER_IMAGE_KEY = WallpaperBackupHelper.WALLPAPER_IMAGE_KEY;
-    private static final String WALLPAPER_INFO_KEY = WallpaperBackupHelper.WALLPAPER_INFO_KEY;
-
-    @Override
-    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
-            ParcelFileDescriptor newState) throws IOException {
-        // We only back up the data under the current "wallpaper" schema with metadata
-        WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
-                Context.WALLPAPER_SERVICE);
-        String[] files = new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO };
-        String[] keys = new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY };
-        if (wallpaper != null && wallpaper.getName() != null && wallpaper.getName().length() > 0) {
-            // When the wallpaper has a name, back up the info by itself.
-            // TODO: Don't rely on the innards of the service object like this!
-            // TODO: Send a delete for any stored wallpaper image in this case?
-            files = new String[] { WALLPAPER_INFO };
-            keys = new String[] { WALLPAPER_INFO_KEY };
-        }
-        addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this, files, keys));
-        super.onBackup(oldState, data, newState);
-    }
-
-    @Override
-    public void onFullBackup(FullBackupDataOutput data) throws IOException {
-        // At present we back up only the wallpaper
-        fullWallpaperBackup(data);
-    }
-
-    private void fullWallpaperBackup(FullBackupDataOutput output) {
-        // Back up the data files directly.  We do them in this specific order --
-        // info file followed by image -- because then we need take no special
-        // steps during restore; the restore will happen properly when the individual
-        // files are restored piecemeal.
-        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
-                WALLPAPER_INFO_DIR, WALLPAPER_INFO, output.getData());
-        FullBackup.backupToTar(getPackageName(), FullBackup.ROOT_TREE_TOKEN, null,
-                WALLPAPER_IMAGE_DIR, WALLPAPER_IMAGE, output.getData());
-    }
-
-    @Override
-    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
-            throws IOException {
-        // On restore, we also support a previous data schema "system_files"
-        addHelper("wallpaper", new WallpaperBackupHelper(SystemBackupAgent.this,
-                new String[] { WALLPAPER_IMAGE, WALLPAPER_INFO },
-                new String[] { WALLPAPER_IMAGE_KEY, WALLPAPER_INFO_KEY} ));
-        addHelper("system_files", new WallpaperBackupHelper(SystemBackupAgent.this,
-                new String[] { WALLPAPER_IMAGE },
-                new String[] { WALLPAPER_IMAGE_KEY} ));
-
-        try {
-            super.onRestore(data, appVersionCode, newState);
-
-            WallpaperManagerService wallpaper = (WallpaperManagerService)ServiceManager.getService(
-                    Context.WALLPAPER_SERVICE);
-            wallpaper.settingsRestored();
-        } catch (IOException ex) {
-            // If there was a failure, delete everything for the wallpaper, this is too aggressive,
-            // but this is hopefully a rare failure.
-            Slog.d(TAG, "restore failed", ex);
-            (new File(WALLPAPER_IMAGE)).delete();
-            (new File(WALLPAPER_INFO)).delete();
-        }
-    }
-
-    @Override
-    public void onRestoreFile(ParcelFileDescriptor data, long size,
-            int type, String domain, String path, long mode, long mtime)
-            throws IOException {
-        Slog.i(TAG, "Restoring file domain=" + domain + " path=" + path);
-
-        // Bits to indicate postprocessing we may need to perform
-        boolean restoredWallpaper = false;
-
-        File outFile = null;
-        // Various domain+files we understand a priori
-        if (domain.equals(FullBackup.ROOT_TREE_TOKEN)) {
-            if (path.equals(WALLPAPER_INFO_FILENAME)) {
-                outFile = new File(WALLPAPER_INFO);
-                restoredWallpaper = true;
-            } else if (path.equals(WALLPAPER_IMAGE_FILENAME)) {
-                outFile = new File(WALLPAPER_IMAGE);
-                restoredWallpaper = true;
-            }
-        }
-
-        try {
-            if (outFile == null) {
-                Slog.w(TAG, "Skipping unrecognized system file: [ " + domain + " : " + path + " ]");
-            }
-            FullBackup.restoreFile(data, size, type, mode, mtime, outFile);
-
-            if (restoredWallpaper) {
-                WallpaperManagerService wallpaper =
-                        (WallpaperManagerService)ServiceManager.getService(
-                        Context.WALLPAPER_SERVICE);
-                wallpaper.settingsRestored();
-            }
-        } catch (IOException e) {
-            if (restoredWallpaper) {
-                // Make sure we wind up in a good state
-                (new File(WALLPAPER_IMAGE)).delete();
-                (new File(WALLPAPER_INFO)).delete();
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index a42cbcf..db40cbe 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -17,6 +17,9 @@
 package com.android.server;
 
 import android.app.ActivityManagerNative;
+import android.app.ActivityThread;
+import android.app.IAlarmManager;
+import android.app.INotificationManager;
 import android.bluetooth.BluetoothAdapter;
 import android.content.ComponentName;
 import android.content.ContentResolver;
@@ -28,8 +31,10 @@
 import android.media.AudioService;
 import android.net.wifi.p2p.WifiP2pService;
 import android.os.Environment;
+import android.os.FactoryTest;
 import android.os.Handler;
-import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.IPowerManager;
 import android.os.Looper;
 import android.os.RemoteException;
 import android.os.ServiceManager;
@@ -47,26 +52,32 @@
 import com.android.internal.R;
 import com.android.internal.os.BinderInternal;
 import com.android.internal.os.SamplingProfilerIntegration;
-import com.android.server.accessibility.AccessibilityManagerService;
 import com.android.server.accounts.AccountManagerService;
 import com.android.server.am.ActivityManagerService;
 import com.android.server.am.BatteryStatsService;
+import com.android.server.clipboard.ClipboardService;
 import com.android.server.content.ContentService;
 import com.android.server.display.DisplayManagerService;
 import com.android.server.dreams.DreamManagerService;
 import com.android.server.input.InputManagerService;
+import com.android.server.lights.LightsManager;
+import com.android.server.lights.LightsService;
 import com.android.server.media.MediaRouterService;
 import com.android.server.net.NetworkPolicyManagerService;
 import com.android.server.net.NetworkStatsService;
+import com.android.server.notification.NotificationManagerService;
 import com.android.server.os.SchedulingPolicyService;
 import com.android.server.pm.Installer;
 import com.android.server.pm.PackageManagerService;
 import com.android.server.pm.UserManagerService;
 import com.android.server.power.PowerManagerService;
 import com.android.server.power.ShutdownThread;
-import com.android.server.print.PrintManagerService;
 import com.android.server.search.SearchManagerService;
+import com.android.server.statusbar.StatusBarManagerService;
+import com.android.server.storage.DeviceStorageMonitorService;
+import com.android.server.twilight.TwilightService;
 import com.android.server.usb.UsbService;
+import com.android.server.wallpaper.WallpaperManagerService;
 import com.android.server.wifi.WifiService;
 import com.android.server.wm.WindowManagerService;
 
@@ -77,62 +88,212 @@
 import java.util.Timer;
 import java.util.TimerTask;
 
-class ServerThread {
+public final class SystemServer {
     private static final String TAG = "SystemServer";
+
     private static final String ENCRYPTING_STATE = "trigger_restart_min_framework";
     private static final String ENCRYPTED_STATE = "1";
 
-    ContentResolver mContentResolver;
+    private static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
 
-    void reportWtf(String msg, Throwable e) {
+    // The earliest supported time.  We pick one day into 1970, to
+    // give any timezone code room without going into negative time.
+    private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
+
+    /*
+     * Implementation class names. TODO: Move them to a codegen class or load
+     * them from the build system somehow.
+     */
+    private static final String BACKUP_MANAGER_SERVICE_CLASS =
+            "com.android.server.backup.BackupManagerService$Lifecycle";
+    private static final String DEVICE_POLICY_MANAGER_SERVICE_CLASS =
+            "com.android.server.devicepolicy.DevicePolicyManagerService$Lifecycle";
+    private static final String APPWIDGET_SERVICE_CLASS =
+            "com.android.server.appwidget.AppWidgetService";
+    private static final String PRINT_MANAGER_SERVICE_CLASS =
+            "com.android.server.print.PrintManagerService";
+    private static final String USB_SERVICE_CLASS =
+            "com.android.server.usb.UsbService$Lifecycle";
+
+    private final int mFactoryTestMode;
+    private Timer mProfilerSnapshotTimer;
+
+    private Context mSystemContext;
+    private SystemServiceManager mSystemServiceManager;
+
+    // TODO: remove all of these references by improving dependency resolution and boot phases
+    private Installer mInstaller;
+    private PowerManagerService mPowerManagerService;
+    private ActivityManagerService mActivityManagerService;
+    private DisplayManagerService mDisplayManagerService;
+    private ContentResolver mContentResolver;
+
+    /**
+     * Called to initialize native system services.
+     */
+    private static native void nativeInit();
+
+    /**
+     * The main entry point from zygote.
+     */
+    public static void main(String[] args) {
+        new SystemServer().run();
+    }
+
+    public SystemServer() {
+        mFactoryTestMode = FactoryTest.getMode();
+    }
+
+    private void run() {
+        // If a device's clock is before 1970 (before 0), a lot of
+        // APIs crash dealing with negative numbers, notably
+        // java.io.File#setLastModified, so instead we fake it and
+        // hope that time from cell towers or NTP fixes it shortly.
+        if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
+            Slog.w(TAG, "System clock is before 1970; setting to 1970.");
+            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
+        }
+
+        // Here we go!
+        Slog.i(TAG, "Entered the Android system server!");
+        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis());
+
+        // In case the runtime switched since last boot (such as when
+        // the old runtime was removed in an OTA), set the system
+        // property so that it is in sync. We can't do this in
+        // libnativehelper's JniInvocation::Init code where we already
+        // had to fallback to a different runtime because it is
+        // running as root and we need to be the system user to set
+        // the property. http://b/11463182
+        SystemProperties.set("persist.sys.dalvik.vm.lib", VMRuntime.getRuntime().vmLibrary());
+
+        // Enable the sampling profiler.
+        if (SamplingProfilerIntegration.isEnabled()) {
+            SamplingProfilerIntegration.start();
+            mProfilerSnapshotTimer = new Timer();
+            mProfilerSnapshotTimer.schedule(new TimerTask() {
+                @Override
+                public void run() {
+                    SamplingProfilerIntegration.writeSnapshot("system_server", null);
+                }
+            }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
+        }
+
+        // Mmmmmm... more memory!
+        VMRuntime.getRuntime().clearGrowthLimit();
+
+        // The system server has to run all of the time, so it needs to be
+        // as efficient as possible with its memory usage.
+        VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
+
+        // Within the system server, it is an error to access Environment paths without
+        // explicitly specifying a user.
+        Environment.setUserRequired(true);
+
+        // Ensure binder calls into the system always run at foreground priority.
+        BinderInternal.disableBackgroundScheduling(true);
+
+        // Prepare the main looper thread (this thread).
+        android.os.Process.setThreadPriority(
+                android.os.Process.THREAD_PRIORITY_FOREGROUND);
+        android.os.Process.setCanSelfBackground(false);
+        Looper.prepareMainLooper();
+
+        // Initialize native services.
+        System.loadLibrary("android_servers");
+        nativeInit();
+
+        // Check whether we failed to shut down last time we tried.
+        // This call may not return.
+        performPendingShutdown();
+
+        // Initialize the system context.
+        createSystemContext();
+
+        // Create the system service manager.
+        mSystemServiceManager = new SystemServiceManager(mSystemContext);
+        LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
+
+        // Start services.
+        try {
+            startBootstrapServices();
+            startCoreServices();
+            startOtherServices();
+        } catch (RuntimeException ex) {
+            Slog.e("System", "******************************************");
+            Slog.e("System", "************ Failure starting system services", ex);
+            throw ex;
+        }
+
+        // For debug builds, log event loop stalls to dropbox for analysis.
+        if (StrictMode.conditionallyEnableDebugLogging()) {
+            Slog.i(TAG, "Enabled StrictMode for system server main thread.");
+        }
+
+        // Loop forever.
+        Looper.loop();
+        throw new RuntimeException("Main thread loop unexpectedly exited");
+    }
+
+    private void reportWtf(String msg, Throwable e) {
         Slog.w(TAG, "***********************************************");
         Log.wtf(TAG, "BOOT FAILURE " + msg, e);
     }
 
-    public void initAndLoop() {
-        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN,
-            SystemClock.uptimeMillis());
+    private void performPendingShutdown() {
+        final String shutdownAction = SystemProperties.get(
+                ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
+        if (shutdownAction != null && shutdownAction.length() > 0) {
+            boolean reboot = (shutdownAction.charAt(0) == '1');
 
-        Looper.prepareMainLooper();
-
-        android.os.Process.setThreadPriority(
-                android.os.Process.THREAD_PRIORITY_FOREGROUND);
-
-        BinderInternal.disableBackgroundScheduling(true);
-        android.os.Process.setCanSelfBackground(false);
-
-        // Check whether we failed to shut down last time we tried.
-        {
-            final String shutdownAction = SystemProperties.get(
-                    ShutdownThread.SHUTDOWN_ACTION_PROPERTY, "");
-            if (shutdownAction != null && shutdownAction.length() > 0) {
-                boolean reboot = (shutdownAction.charAt(0) == '1');
-
-                final String reason;
-                if (shutdownAction.length() > 1) {
-                    reason = shutdownAction.substring(1, shutdownAction.length());
-                } else {
-                    reason = null;
-                }
-
-                ShutdownThread.rebootOrShutdown(reboot, reason);
+            final String reason;
+            if (shutdownAction.length() > 1) {
+                reason = shutdownAction.substring(1, shutdownAction.length());
+            } else {
+                reason = null;
             }
+
+            ShutdownThread.rebootOrShutdown(reboot, reason);
         }
+    }
 
-        String factoryTestStr = SystemProperties.get("ro.factorytest");
-        int factoryTest = "".equals(factoryTestStr) ? SystemServer.FACTORY_TEST_OFF
-                : Integer.parseInt(factoryTestStr);
-        final boolean headless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
+    private void createSystemContext() {
+        ActivityThread activityThread = ActivityThread.systemMain();
+        mSystemContext = activityThread.getSystemContext();
+        mSystemContext.setTheme(android.R.style.Theme_Holo);
+    }
 
-        Installer installer = null;
+    private void startBootstrapServices() {
+        // Wait for installd to finish starting up so that it has a chance to
+        // create critical directories such as /data/user with the appropriate
+        // permissions.  We need this to complete before we initialize other services.
+        mInstaller = mSystemServiceManager.startService(Installer.class);
+
+        // Power manager needs to be started early because other services need it.
+        // TODO: The conversion to the new pattern is incomplete.  We need to switch
+        // the power manager's dependencies over then we can use boot phases to arrange
+        // initialization order and remove the mPowerManagerService field.
+        mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
+
+        // Activity manager runs the show.
+        mActivityManagerService = mSystemServiceManager.startService(
+                ActivityManagerService.Lifecycle.class).getService();
+    }
+
+    private void startCoreServices() {
+        // Display manager is needed to provide display metrics before package manager
+        // starts up.
+        mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);
+    }
+
+    private void startOtherServices() {
+        final Context context = mSystemContext;
         AccountManagerService accountManager = null;
         ContentService contentService = null;
-        LightsService lights = null;
-        PowerManagerService power = null;
-        DisplayManagerService display = null;
+        LightsManager lights = null;
         BatteryService battery = null;
         VibratorService vibrator = null;
-        AlarmManagerService alarm = null;
+        IAlarmManager alarm = null;
         MountService mountService = null;
         NetworkManagementService networkManagement = null;
         NetworkStatsService networkStats = null;
@@ -142,14 +303,11 @@
         WifiService wifi = null;
         NsdService serviceDiscovery= null;
         IPackageManager pm = null;
-        Context context = null;
         WindowManagerService wm = null;
         BluetoothManagerService bluetooth = null;
         DockObserver dock = null;
         UsbService usb = null;
         SerialService serial = null;
-        TwilightService twilight = null;
-        UiModeManagerService uiMode = null;
         RecognitionManagerService recognition = null;
         NetworkTimeUpdateService networkTimeUpdater = null;
         CommonTimeManagementService commonTimeMgmtService = null;
@@ -157,48 +315,8 @@
         TelephonyRegistry telephonyRegistry = null;
         ConsumerIrService consumerIr = null;
 
-        // Create a handler thread just for the window manager to enjoy.
-        HandlerThread wmHandlerThread = new HandlerThread("WindowManager");
-        wmHandlerThread.start();
-        Handler wmHandler = new Handler(wmHandlerThread.getLooper());
-        wmHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                //Looper.myLooper().setMessageLogging(new LogPrinter(
-                //        android.util.Log.DEBUG, TAG, android.util.Log.LOG_ID_SYSTEM));
-                android.os.Process.setThreadPriority(
-                        android.os.Process.THREAD_PRIORITY_DISPLAY);
-                android.os.Process.setCanSelfBackground(false);
-
-                // For debug builds, log event loop stalls to dropbox for analysis.
-                if (StrictMode.conditionallyEnableDebugLogging()) {
-                    Slog.i(TAG, "Enabled StrictMode logging for WM Looper");
-                }
-            }
-        });
-
-        // bootstrap services
         boolean onlyCore = false;
         boolean firstBoot = false;
-        try {
-            // Wait for installd to finished starting up so that it has a chance to
-            // create critical directories such as /data/user with the appropriate
-            // permissions.  We need this to complete before we initialize other services.
-            Slog.i(TAG, "Waiting for installd to be ready.");
-            installer = new Installer();
-            installer.ping();
-
-            Slog.i(TAG, "Power Manager");
-            power = new PowerManagerService();
-            ServiceManager.addService(Context.POWER_SERVICE, power);
-
-            Slog.i(TAG, "Activity Manager");
-            context = ActivityManagerService.main(factoryTest);
-        } catch (RuntimeException e) {
-            Slog.e("System", "******************************************");
-            Slog.e("System", "************ Failure starting bootstrap service", e);
-        }
-
         boolean disableStorage = SystemProperties.getBoolean("config.disable_storage", false);
         boolean disableMedia = SystemProperties.getBoolean("config.disable_media", false);
         boolean disableBluetooth = SystemProperties.getBoolean("config.disable_bluetooth", false);
@@ -209,10 +327,6 @@
         boolean disableNetwork = SystemProperties.getBoolean("config.disable_network", false);
 
         try {
-            Slog.i(TAG, "Display Manager");
-            display = new DisplayManagerService(context, wmHandler);
-            ServiceManager.addService(Context.DISPLAY_SERVICE, display, true);
-
             Slog.i(TAG, "Telephony Registry");
             telephonyRegistry = new TelephonyRegistry(context);
             ServiceManager.addService("telephony.registry", telephonyRegistry);
@@ -222,10 +336,8 @@
 
             AttributeCache.init(context);
 
-            if (!display.waitForDefaultDisplay()) {
-                reportWtf("Timeout waiting for default display to be initialized.",
-                        new Throwable());
-            }
+            // We need the default display before we can initialize the package manager.
+            mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
 
             Slog.i(TAG, "Package Manager");
             // Only run "core" apps if we're encrypting the device.
@@ -238,15 +350,15 @@
                 onlyCore = true;
             }
 
-            pm = PackageManagerService.main(context, installer,
-                    factoryTest != SystemServer.FACTORY_TEST_OFF,
+            pm = PackageManagerService.main(context, mInstaller,
+                    mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF,
                     onlyCore);
             try {
                 firstBoot = pm.isFirstBoot();
             } catch (RemoteException e) {
             }
 
-            ActivityManagerService.setSystemProcess();
+            mActivityManagerService.setSystemProcess();
 
             Slog.i(TAG, "Entropy Mixer");
             ServiceManager.addService("entropy", new EntropyMixer(context));
@@ -269,13 +381,13 @@
 
             Slog.i(TAG, "Content Manager");
             contentService = ContentService.main(context,
-                    factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL);
+                    mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL);
 
             Slog.i(TAG, "System Content Providers");
-            ActivityManagerService.installSystemProviders();
+            mActivityManagerService.installSystemProviders();
 
-            Slog.i(TAG, "Lights Service");
-            lights = new LightsService(context);
+            mSystemServiceManager.startService(LightsService.class);
+            lights = LocalServices.getService(LightsManager.class);
 
             Slog.i(TAG, "Battery Service");
             battery = new BatteryService(context, lights);
@@ -285,49 +397,49 @@
             vibrator = new VibratorService(context);
             ServiceManager.addService("vibrator", vibrator);
 
+            // TODO: use boot phase
+            // only initialize the power service after we have started the
+            // lights service, content providers and the battery service.
+            mPowerManagerService.init(lights, battery,
+                    BatteryStatsService.getService(),
+                    mActivityManagerService.getAppOpsService());
+
             Slog.i(TAG, "Consumer IR Service");
             consumerIr = new ConsumerIrService(context);
             ServiceManager.addService(Context.CONSUMER_IR_SERVICE, consumerIr);
 
-            // only initialize the power service after we have started the
-            // lights service, content providers and the battery service.
-            power.init(context, lights, ActivityManagerService.self(), battery,
-                    BatteryStatsService.getService(),
-                    ActivityManagerService.self().getAppOpsService(), display);
-
-            Slog.i(TAG, "Alarm Manager");
-            alarm = new AlarmManagerService(context);
-            ServiceManager.addService(Context.ALARM_SERVICE, alarm);
+            mSystemServiceManager.startService(AlarmManagerService.class);
+            alarm = IAlarmManager.Stub.asInterface(
+                    ServiceManager.getService(Context.ALARM_SERVICE));
 
             Slog.i(TAG, "Init Watchdog");
-            Watchdog.getInstance().init(context, battery, power, alarm,
-                    ActivityManagerService.self());
-            Watchdog.getInstance().addThread(wmHandler, "WindowManager thread");
+            final Watchdog watchdog = Watchdog.getInstance();
+            watchdog.init(context, mActivityManagerService);
 
             Slog.i(TAG, "Input Manager");
-            inputManager = new InputManagerService(context, wmHandler);
+            inputManager = new InputManagerService(context);
 
             Slog.i(TAG, "Window Manager");
-            wm = WindowManagerService.main(context, power, display, inputManager,
-                    wmHandler, factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
+            wm = WindowManagerService.main(context, inputManager,
+                    mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL,
                     !firstBoot, onlyCore);
             ServiceManager.addService(Context.WINDOW_SERVICE, wm);
             ServiceManager.addService(Context.INPUT_SERVICE, inputManager);
 
-            ActivityManagerService.self().setWindowManager(wm);
+            mActivityManagerService.setWindowManager(wm);
 
             inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
             inputManager.start();
 
-            display.setWindowManager(wm);
-            display.setInputManager(inputManager);
+            // TODO: Use service dependencies instead.
+            mDisplayManagerService.windowManagerAndInputReady();
 
             // Skip Bluetooth if we have an emulator kernel
             // TODO: Use a more reliable check to see if this product should
             // support Bluetooth - see bug 988521
             if (SystemProperties.get("ro.kernel.qemu").equals("1")) {
                 Slog.i(TAG, "No Bluetooh Service (emulator)");
-            } else if (factoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
+            } else if (mFactoryTestMode == FactoryTest.FACTORY_TEST_LOW_LEVEL) {
                 Slog.i(TAG, "No Bluetooth Service (factory test)");
             } else if (!context.getPackageManager().hasSystemFeature
                        (PackageManager.FEATURE_BLUETOOTH)) {
@@ -344,23 +456,19 @@
             Slog.e("System", "************ Failure starting core service", e);
         }
 
-        DevicePolicyManagerService devicePolicy = null;
         StatusBarManagerService statusBar = null;
+        INotificationManager notification = null;
         InputMethodManagerService imm = null;
-        AppWidgetService appWidget = null;
-        NotificationManagerService notification = null;
         WallpaperManagerService wallpaper = null;
         LocationManagerService location = null;
         CountryDetectorService countryDetector = null;
         TextServicesManagerService tsms = null;
         LockSettingsService lockSettings = null;
-        DreamManagerService dreamy = null;
         AssetAtlasService atlas = null;
-        PrintManagerService printManager = null;
         MediaRouterService mediaRouter = null;
 
         // Bring up services needed for UI.
-        if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
+        if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
             //if (!disableNonCoreServices) { // TODO: View depends on these; mock them?
             if (true) {
                 try {
@@ -373,8 +481,8 @@
 
                 try {
                     Slog.i(TAG, "Accessibility Manager");
-                    ServiceManager.addService(Context.ACCESSIBILITY_SERVICE,
-                            new AccessibilityManagerService(context));
+                    ServiceManager.addService(Context.ACCESSIBILITY_SERVICE, (IBinder)
+                            getClass().getClassLoader().loadClass("com.android.server.accessibility.AccessibilityManagerService").getConstructor(Context.class).newInstance(context));
                 } catch (Throwable e) {
                     reportWtf("starting Accessibility Manager", e);
                 }
@@ -397,11 +505,11 @@
             ActivityManagerNative.getDefault().showBootMessage(
                     context.getResources().getText(
                             com.android.internal.R.string.android_upgrading_starting_apps),
-                            false);
+                    false);
         } catch (RemoteException e) {
         }
 
-        if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
+        if (mFactoryTestMode != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
             if (!disableStorage &&
                 !"0".equals(SystemProperties.get("system_init.startmountservice"))) {
                 try {
@@ -427,9 +535,9 @@
                 }
 
                 try {
-                    Slog.i(TAG, "Device Policy");
-                    devicePolicy = new DevicePolicyManagerService(context);
-                    ServiceManager.addService(Context.DEVICE_POLICY_SERVICE, devicePolicy);
+                    if (pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) {
+                        mSystemServiceManager.startService(DEVICE_POLICY_MANAGER_SERVICE_CLASS);
+                    }
                 } catch (Throwable e) {
                     reportWtf("starting DevicePolicyService", e);
                 }
@@ -487,7 +595,8 @@
                 try {
                     Slog.i(TAG, "NetworkPolicy Service");
                     networkPolicy = new NetworkPolicyManagerService(
-                            context, ActivityManagerService.self(), power,
+                            context, mActivityManagerService,
+                            (IPowerManager)ServiceManager.getService(Context.POWER_SERVICE),
                             networkStats, networkManagement);
                     ServiceManager.addService(Context.NETWORK_POLICY_SERVICE, networkPolicy);
                 } catch (Throwable e) {
@@ -567,22 +676,12 @@
                 reportWtf("making Content Service ready", e);
             }
 
-            try {
-                Slog.i(TAG, "Notification Manager");
-                notification = new NotificationManagerService(context, statusBar, lights);
-                ServiceManager.addService(Context.NOTIFICATION_SERVICE, notification);
-                networkPolicy.bindNotificationManager(notification);
-            } catch (Throwable e) {
-                reportWtf("starting Notification Manager", e);
-            }
+            mSystemServiceManager.startService(NotificationManagerService.class);
+            notification = INotificationManager.Stub.asInterface(
+                    ServiceManager.getService(Context.NOTIFICATION_SERVICE));
+            networkPolicy.bindNotificationManager(notification);
 
-            try {
-                Slog.i(TAG, "Device Storage Monitor");
-                ServiceManager.addService(DeviceStorageMonitorService.SERVICE,
-                        new DeviceStorageMonitorService(context));
-            } catch (Throwable e) {
-                reportWtf("starting DeviceStorageMonitor service", e);
-            }
+            mSystemServiceManager.startService(DeviceStorageMonitorService.class);
 
             if (!disableLocation) {
                 try {
@@ -624,10 +723,8 @@
                         R.bool.config_enableWallpaperService)) {
                 try {
                     Slog.i(TAG, "Wallpaper Service");
-                    if (!headless) {
-                        wallpaper = new WallpaperManagerService(context);
-                        ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
-                    }
+                    wallpaper = new WallpaperManagerService(context);
+                    ServiceManager.addService(Context.WALLPAPER_SERVICE, wallpaper);
                 } catch (Throwable e) {
                     reportWtf("starting Wallpaper Service", e);
                 }
@@ -665,10 +762,11 @@
 
             if (!disableNonCoreServices) {
                 try {
-                    Slog.i(TAG, "USB Service");
-                    // Manage USB host and device support
-                    usb = new UsbService(context);
-                    ServiceManager.addService(Context.USB_SERVICE, usb);
+                    if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST) ||
+                            pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)) {
+                        // Manage USB host and device support
+                        mSystemServiceManager.startService(USB_SERVICE_CLASS);
+                    }
                 } catch (Throwable e) {
                     reportWtf("starting UsbService", e);
                 }
@@ -683,34 +781,23 @@
                 }
             }
 
-            try {
-                Slog.i(TAG, "Twilight Service");
-                twilight = new TwilightService(context);
-            } catch (Throwable e) {
-                reportWtf("starting TwilightService", e);
-            }
+            mSystemServiceManager.startService(TwilightService.class);
 
-            try {
-                Slog.i(TAG, "UI Mode Manager Service");
-                // Listen for UI mode changes
-                uiMode = new UiModeManagerService(context, twilight);
-            } catch (Throwable e) {
-                reportWtf("starting UiModeManagerService", e);
-            }
+            mSystemServiceManager.startService(UiModeManagerService.class);
 
             if (!disableNonCoreServices) {
                 try {
-                    Slog.i(TAG, "Backup Service");
-                    ServiceManager.addService(Context.BACKUP_SERVICE,
-                            new BackupManagerService(context));
+                    if (pm.hasSystemFeature(PackageManager.FEATURE_BACKUP)) {
+                        mSystemServiceManager.startService(BACKUP_MANAGER_SERVICE_CLASS);
+                    }
                 } catch (Throwable e) {
                     Slog.e(TAG, "Failure starting Backup Service", e);
                 }
 
                 try {
-                    Slog.i(TAG, "AppWidget Service");
-                    appWidget = new AppWidgetService(context);
-                    ServiceManager.addService(Context.APPWIDGET_SERVICE, appWidget);
+                    if (pm.hasSystemFeature(PackageManager.FEATURE_APP_WIDGETS)) {
+                        mSystemServiceManager.startService(APPWIDGET_SERVICE_CLASS);
+                    }
                 } catch (Throwable e) {
                     reportWtf("starting AppWidget Service", e);
                 }
@@ -770,16 +857,9 @@
                 }
             }
 
-            if (!disableNonCoreServices && 
-                context.getResources().getBoolean(R.bool.config_dreamsSupported)) {
-                try {
-                    Slog.i(TAG, "Dreams Service");
-                    // Dreams (interactive idle-time views, a/k/a screen savers)
-                    dreamy = new DreamManagerService(context, wmHandler);
-                    ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy);
-                } catch (Throwable e) {
-                    reportWtf("starting DreamManagerService", e);
-                }
+            if (!disableNonCoreServices) {
+                // Dreams (interactive idle-time views, a/k/a screen savers, and doze mode)
+                mSystemServiceManager.startService(DreamManagerService.class);
             }
 
             if (!disableNonCoreServices) {
@@ -800,9 +880,9 @@
             }
 
             try {
-                Slog.i(TAG, "Print Service");
-                printManager = new PrintManagerService(context);
-                ServiceManager.addService(Context.PRINT_SERVICE, printManager);
+                if (pm.hasSystemFeature(PackageManager.FEATURE_PRINTING)) {
+                    mSystemServiceManager.startService(PRINT_MANAGER_SERVICE_CLASS);
+                }
             } catch (Throwable e) {
                 reportWtf("starting Print Service", e);
             }
@@ -822,7 +902,7 @@
         // we are in safe mode.
         final boolean safeMode = wm.detectSafeMode();
         if (safeMode) {
-            ActivityManagerService.self().enterSafeMode();
+            mActivityManagerService.enterSafeMode();
             // Post the safe mode state in the Zygote class
             Zygote.systemInSafeMode = true;
             // Disable the JIT for the system_server process
@@ -848,21 +928,10 @@
             }
         }
 
-        if (devicePolicy != null) {
-            try {
-                devicePolicy.systemReady();
-            } catch (Throwable e) {
-                reportWtf("making Device Policy Service ready", e);
-            }
-        }
+        // Needed by DevicePolicyManager for initialization
+        mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
 
-        if (notification != null) {
-            try {
-                notification.systemReady();
-            } catch (Throwable e) {
-                reportWtf("making Notification Service ready", e);
-            }
-        }
+        mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
 
         try {
             wm.systemReady();
@@ -871,7 +940,7 @@
         }
 
         if (safeMode) {
-            ActivityManagerService.self().showSafeModeOverlay();
+            mActivityManagerService.showSafeModeOverlay();
         }
 
         // Update the configuration for this context by hand, because we're going
@@ -884,7 +953,8 @@
         context.getResources().updateConfiguration(config, metrics);
 
         try {
-            power.systemReady(twilight, dreamy);
+            // TODO: use boot phase
+            mPowerManagerService.systemReady();
         } catch (Throwable e) {
             reportWtf("making Power Manager Service ready", e);
         }
@@ -896,13 +966,13 @@
         }
 
         try {
-            display.systemReady(safeMode, onlyCore);
+            // TODO: use boot phase and communicate these flags some other way
+            mDisplayManagerService.systemReady(safeMode, onlyCore);
         } catch (Throwable e) {
             reportWtf("making Display Manager Service ready", e);
         }
 
         // These are needed to propagate to the runnable below.
-        final Context contextF = context;
         final MountService mountServiceF = mountService;
         final BatteryService batteryF = battery;
         final NetworkManagementService networkManagementF = networkManagement;
@@ -910,10 +980,6 @@
         final NetworkPolicyManagerService networkPolicyF = networkPolicy;
         final ConnectivityService connectivityF = connectivity;
         final DockObserver dockF = dock;
-        final UsbService usbF = usb;
-        final TwilightService twilightF = twilight;
-        final UiModeManagerService uiModeF = uiMode;
-        final AppWidgetService appWidgetF = appWidget;
         final WallpaperManagerService wallpaperF = wallpaper;
         final InputMethodManagerService immF = imm;
         final RecognitionManagerService recognitionF = recognition;
@@ -923,11 +989,9 @@
         final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
         final TextServicesManagerService textServiceManagerServiceF = tsms;
         final StatusBarManagerService statusBarF = statusBar;
-        final DreamManagerService dreamyF = dreamy;
         final AssetAtlasService atlasF = atlas;
         final InputManagerService inputManagerF = inputManager;
         final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
-        final PrintManagerService printManagerF = printManager;
         final MediaRouterService mediaRouterF = mediaRouter;
 
         // We now tell the activity manager it is okay to run third party
@@ -935,17 +999,22 @@
         // where third party code can really run (but before it has actually
         // started launching the initial applications), for us to complete our
         // initialization.
-        ActivityManagerService.self().systemReady(new Runnable() {
+        mActivityManagerService.systemReady(new Runnable() {
+            @Override
             public void run() {
                 Slog.i(TAG, "Making services ready");
+                mSystemServiceManager.startBootPhase(
+                        SystemService.PHASE_ACTIVITY_MANAGER_READY);
 
                 try {
-                    ActivityManagerService.self().startObservingNativeCrashes();
+                    mActivityManagerService.startObservingNativeCrashes();
                 } catch (Throwable e) {
                     reportWtf("observing native crashes", e);
                 }
-                if (!headless) {
-                    startSystemUi(contextF);
+                try {
+                    startSystemUi(context);
+                } catch (Throwable e) {
+                    reportWtf("starting System UI", e);
                 }
                 try {
                     if (mountServiceF != null) mountServiceF.systemReady();
@@ -983,21 +1052,6 @@
                     reportWtf("making Dock Service ready", e);
                 }
                 try {
-                    if (usbF != null) usbF.systemReady();
-                } catch (Throwable e) {
-                    reportWtf("making USB Service ready", e);
-                }
-                try {
-                    if (twilightF != null) twilightF.systemReady();
-                } catch (Throwable e) {
-                    reportWtf("makin Twilight Service ready", e);
-                }
-                try {
-                    if (uiModeF != null) uiModeF.systemReady();
-                } catch (Throwable e) {
-                    reportWtf("making UI Mode Service ready", e);
-                }
-                try {
                     if (recognitionF != null) recognitionF.systemReady();
                 } catch (Throwable e) {
                     reportWtf("making Recognition Service ready", e);
@@ -1006,13 +1060,10 @@
 
                 // It is now okay to let the various system services start their
                 // third party code...
+                mSystemServiceManager.startBootPhase(
+                        SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
 
                 try {
-                    if (appWidgetF != null) appWidgetF.systemRunning(safeMode);
-                } catch (Throwable e) {
-                    reportWtf("Notifying AppWidgetService running", e);
-                }
-                try {
                     if (wallpaperF != null) wallpaperF.systemRunning();
                 } catch (Throwable e) {
                     reportWtf("Notifying WallpaperService running", e);
@@ -1038,7 +1089,9 @@
                     reportWtf("Notifying NetworkTimeService running", e);
                 }
                 try {
-                    if (commonTimeMgmtServiceF != null) commonTimeMgmtServiceF.systemRunning();
+                    if (commonTimeMgmtServiceF != null) {
+                        commonTimeMgmtServiceF.systemRunning();
+                    }
                 } catch (Throwable e) {
                     reportWtf("Notifying CommonTimeManagementService running", e);
                 }
@@ -1049,11 +1102,6 @@
                     reportWtf("Notifying TextServicesManagerService running", e);
                 }
                 try {
-                    if (dreamyF != null) dreamyF.systemRunning();
-                } catch (Throwable e) {
-                    reportWtf("Notifying DreamManagerService running", e);
-                }
-                try {
                     if (atlasF != null) atlasF.systemRunning();
                 } catch (Throwable e) {
                     reportWtf("Notifying AssetAtlasService running", e);
@@ -1064,34 +1112,20 @@
                 } catch (Throwable e) {
                     reportWtf("Notifying InputManagerService running", e);
                 }
-
                 try {
                     if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
                 } catch (Throwable e) {
                     reportWtf("Notifying TelephonyRegistry running", e);
                 }
-
-                try {
-                    if (printManagerF != null) printManagerF.systemRuning();
-                } catch (Throwable e) {
-                    reportWtf("Notifying PrintManagerService running", e);
-                }
-
                 try {
                     if (mediaRouterF != null) mediaRouterF.systemRunning();
                 } catch (Throwable e) {
                     reportWtf("Notifying MediaRouterService running", e);
                 }
+
+                mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETE);
             }
         });
-
-        // For debug builds, log event loop stalls to dropbox for analysis.
-        if (StrictMode.conditionallyEnableDebugLogging()) {
-            Slog.i(TAG, "Enabled StrictMode for system server main thread.");
-        }
-
-        Looper.loop();
-        Slog.d(TAG, "System ServerThread is exiting!");
     }
 
     static final void startSystemUi(Context context) {
@@ -1102,80 +1136,3 @@
         context.startServiceAsUser(intent, UserHandle.OWNER);
     }
 }
-
-public class SystemServer {
-    private static final String TAG = "SystemServer";
-
-    public static final int FACTORY_TEST_OFF = 0;
-    public static final int FACTORY_TEST_LOW_LEVEL = 1;
-    public static final int FACTORY_TEST_HIGH_LEVEL = 2;
-
-    static Timer timer;
-    static final long SNAPSHOT_INTERVAL = 60 * 60 * 1000; // 1hr
-
-    // The earliest supported time.  We pick one day into 1970, to
-    // give any timezone code room without going into negative time.
-    private static final long EARLIEST_SUPPORTED_TIME = 86400 * 1000;
-
-    /**
-     * Called to initialize native system services.
-     */
-    private static native void nativeInit();
-
-    public static void main(String[] args) {
-
-        /*
-         * In case the runtime switched since last boot (such as when
-         * the old runtime was removed in an OTA), set the system
-         * property so that it is in sync. We can't do this in
-         * libnativehelper's JniInvocation::Init code where we already
-         * had to fallback to a different runtime because it is
-         * running as root and we need to be the system user to set
-         * the property. http://b/11463182
-         */
-        SystemProperties.set("persist.sys.dalvik.vm.lib",
-                             VMRuntime.getRuntime().vmLibrary());
-
-        if (System.currentTimeMillis() < EARLIEST_SUPPORTED_TIME) {
-            // If a device's clock is before 1970 (before 0), a lot of
-            // APIs crash dealing with negative numbers, notably
-            // java.io.File#setLastModified, so instead we fake it and
-            // hope that time from cell towers or NTP fixes it
-            // shortly.
-            Slog.w(TAG, "System clock is before 1970; setting to 1970.");
-            SystemClock.setCurrentTimeMillis(EARLIEST_SUPPORTED_TIME);
-        }
-
-        if (SamplingProfilerIntegration.isEnabled()) {
-            SamplingProfilerIntegration.start();
-            timer = new Timer();
-            timer.schedule(new TimerTask() {
-                @Override
-                public void run() {
-                    SamplingProfilerIntegration.writeSnapshot("system_server", null);
-                }
-            }, SNAPSHOT_INTERVAL, SNAPSHOT_INTERVAL);
-        }
-
-        // Mmmmmm... more memory!
-        dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
-
-        // The system server has to run all of the time, so it needs to be
-        // as efficient as possible with its memory usage.
-        VMRuntime.getRuntime().setTargetHeapUtilization(0.8f);
-
-        Environment.setUserRequired(true);
-
-        System.loadLibrary("android_servers");
-
-        Slog.i(TAG, "Entered the Android system server!");
-
-        // Initialize native services.
-        nativeInit();
-
-        // This used to be its own separate thread, but now it is
-        // just the loop we run on the main thread.
-        ServerThread thr = new ServerThread();
-        thr.initAndLoop();
-    }
-}
diff --git a/services/java/com/android/server/TwilightService.java b/services/java/com/android/server/TwilightService.java
deleted file mode 100644
index 0356faa..0000000
--- a/services/java/com/android/server/TwilightService.java
+++ /dev/null
@@ -1,572 +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.server;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.location.Criteria;
-import android.location.Location;
-import android.location.LocationListener;
-import android.location.LocationManager;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.SystemClock;
-import android.text.format.DateUtils;
-import android.text.format.Time;
-import android.util.Slog;
-
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-
-import libcore.util.Objects;
-
-/**
- * Figures out whether it's twilight time based on the user's location.
- *
- * Used by the UI mode manager and other components to adjust night mode
- * effects based on sunrise and sunset.
- */
-public final class TwilightService {
-    private static final String TAG = "TwilightService";
-
-    private static final boolean DEBUG = false;
-
-    private static final String ACTION_UPDATE_TWILIGHT_STATE =
-            "com.android.server.action.UPDATE_TWILIGHT_STATE";
-
-    private final Context mContext;
-    private final AlarmManager mAlarmManager;
-    private final LocationManager mLocationManager;
-    private final LocationHandler mLocationHandler;
-
-    private final Object mLock = new Object();
-
-    private final ArrayList<TwilightListenerRecord> mListeners =
-            new ArrayList<TwilightListenerRecord>();
-
-    private boolean mSystemReady;
-
-    private TwilightState mTwilightState;
-
-    public TwilightService(Context context) {
-        mContext = context;
-
-        mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
-        mLocationManager = (LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
-        mLocationHandler = new LocationHandler();
-    }
-
-    void systemReady() {
-        synchronized (mLock) {
-            mSystemReady = true;
-
-            IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
-            filter.addAction(Intent.ACTION_TIME_CHANGED);
-            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
-            filter.addAction(ACTION_UPDATE_TWILIGHT_STATE);
-            mContext.registerReceiver(mUpdateLocationReceiver, filter);
-
-            if (!mListeners.isEmpty()) {
-                mLocationHandler.enableLocationUpdates();
-            }
-        }
-    }
-
-    /**
-     * Gets the current twilight state.
-     *
-     * @return The current twilight state, or null if no information is available.
-     */
-    public TwilightState getCurrentState() {
-        synchronized (mLock) {
-            return mTwilightState;
-        }
-    }
-
-    /**
-     * Listens for twilight time.
-     *
-     * @param listener The listener.
-     * @param handler The handler on which to post calls into the listener.
-     */
-    public void registerListener(TwilightListener listener, Handler handler) {
-        synchronized (mLock) {
-            mListeners.add(new TwilightListenerRecord(listener, handler));
-
-            if (mSystemReady && mListeners.size() == 1) {
-                mLocationHandler.enableLocationUpdates();
-            }
-        }
-    }
-
-    private void setTwilightState(TwilightState state) {
-        synchronized (mLock) {
-            if (!Objects.equal(mTwilightState, state)) {
-                if (DEBUG) {
-                    Slog.d(TAG, "Twilight state changed: " + state);
-                }
-
-                mTwilightState = state;
-                int count = mListeners.size();
-                for (int i = 0; i < count; i++) {
-                    mListeners.get(i).post();
-                }
-            }
-        }
-    }
-
-    // The user has moved if the accuracy circles of the two locations don't overlap.
-    private static boolean hasMoved(Location from, Location to) {
-        if (to == null) {
-            return false;
-        }
-
-        if (from == null) {
-            return true;
-        }
-
-        // if new location is older than the current one, the device hasn't moved.
-        if (to.getElapsedRealtimeNanos() < from.getElapsedRealtimeNanos()) {
-            return false;
-        }
-
-        // Get the distance between the two points.
-        float distance = from.distanceTo(to);
-
-        // Get the total accuracy radius for both locations.
-        float totalAccuracy = from.getAccuracy() + to.getAccuracy();
-
-        // If the distance is greater than the combined accuracy of the two
-        // points then they can't overlap and hence the user has moved.
-        return distance >= totalAccuracy;
-    }
-
-    /**
-     * Describes whether it is day or night.
-     * This object is immutable.
-     */
-    public static final class TwilightState {
-        private final boolean mIsNight;
-        private final long mYesterdaySunset;
-        private final long mTodaySunrise;
-        private final long mTodaySunset;
-        private final long mTomorrowSunrise;
-
-        TwilightState(boolean isNight,
-                long yesterdaySunset,
-                long todaySunrise, long todaySunset,
-                long tomorrowSunrise) {
-            mIsNight = isNight;
-            mYesterdaySunset = yesterdaySunset;
-            mTodaySunrise = todaySunrise;
-            mTodaySunset = todaySunset;
-            mTomorrowSunrise = tomorrowSunrise;
-        }
-
-        /**
-         * Returns true if it is currently night time.
-         */
-        public boolean isNight() {
-            return mIsNight;
-        }
-
-        /**
-         * Returns the time of yesterday's sunset in the System.currentTimeMillis() timebase,
-         * or -1 if the sun never sets.
-         */
-        public long getYesterdaySunset() {
-            return mYesterdaySunset;
-        }
-
-        /**
-         * Returns the time of today's sunrise in the System.currentTimeMillis() timebase,
-         * or -1 if the sun never rises.
-         */
-        public long getTodaySunrise() {
-            return mTodaySunrise;
-        }
-
-        /**
-         * Returns the time of today's sunset in the System.currentTimeMillis() timebase,
-         * or -1 if the sun never sets.
-         */
-        public long getTodaySunset() {
-            return mTodaySunset;
-        }
-
-        /**
-         * Returns the time of tomorrow's sunrise in the System.currentTimeMillis() timebase,
-         * or -1 if the sun never rises.
-         */
-        public long getTomorrowSunrise() {
-            return mTomorrowSunrise;
-        }
-
-        @Override
-        public boolean equals(Object o) {
-            return o instanceof TwilightState && equals((TwilightState)o);
-        }
-
-        public boolean equals(TwilightState other) {
-            return other != null
-                    && mIsNight == other.mIsNight
-                    && mYesterdaySunset == other.mYesterdaySunset
-                    && mTodaySunrise == other.mTodaySunrise
-                    && mTodaySunset == other.mTodaySunset
-                    && mTomorrowSunrise == other.mTomorrowSunrise;
-        }
-
-        @Override
-        public int hashCode() {
-            return 0; // don't care
-        }
-
-        @Override
-        public String toString() {
-            DateFormat f = DateFormat.getDateTimeInstance();
-            return "{TwilightState: isNight=" + mIsNight
-                    + ", mYesterdaySunset=" + f.format(new Date(mYesterdaySunset))
-                    + ", mTodaySunrise=" + f.format(new Date(mTodaySunrise))
-                    + ", mTodaySunset=" + f.format(new Date(mTodaySunset))
-                    + ", mTomorrowSunrise=" + f.format(new Date(mTomorrowSunrise))
-                    + "}";
-        }
-    }
-
-    /**
-     * Listener for changes in twilight state.
-     */
-    public interface TwilightListener {
-        public void onTwilightStateChanged();
-    }
-
-    private static final class TwilightListenerRecord implements Runnable {
-        private final TwilightListener mListener;
-        private final Handler mHandler;
-
-        public TwilightListenerRecord(TwilightListener listener, Handler handler) {
-            mListener = listener;
-            mHandler = handler;
-        }
-
-        public void post() {
-            mHandler.post(this);
-        }
-
-        @Override
-        public void run() {
-            mListener.onTwilightStateChanged();
-        }
-    }
-
-    private final class LocationHandler extends Handler {
-        private static final int MSG_ENABLE_LOCATION_UPDATES = 1;
-        private static final int MSG_GET_NEW_LOCATION_UPDATE = 2;
-        private static final int MSG_PROCESS_NEW_LOCATION = 3;
-        private static final int MSG_DO_TWILIGHT_UPDATE = 4;
-
-        private static final long LOCATION_UPDATE_MS = 24 * DateUtils.HOUR_IN_MILLIS;
-        private static final long MIN_LOCATION_UPDATE_MS = 30 * DateUtils.MINUTE_IN_MILLIS;
-        private static final float LOCATION_UPDATE_DISTANCE_METER = 1000 * 20;
-        private static final long LOCATION_UPDATE_ENABLE_INTERVAL_MIN = 5000;
-        private static final long LOCATION_UPDATE_ENABLE_INTERVAL_MAX =
-                15 * DateUtils.MINUTE_IN_MILLIS;
-        private static final double FACTOR_GMT_OFFSET_LONGITUDE =
-                1000.0 * 360.0 / DateUtils.DAY_IN_MILLIS;
-
-        private boolean mPassiveListenerEnabled;
-        private boolean mNetworkListenerEnabled;
-        private boolean mDidFirstInit;
-        private long mLastNetworkRegisterTime = -MIN_LOCATION_UPDATE_MS;
-        private long mLastUpdateInterval;
-        private Location mLocation;
-        private final TwilightCalculator mTwilightCalculator = new TwilightCalculator();
-
-        public void processNewLocation(Location location) {
-            Message msg = obtainMessage(MSG_PROCESS_NEW_LOCATION, location);
-            sendMessage(msg);
-        }
-
-        public void enableLocationUpdates() {
-            sendEmptyMessage(MSG_ENABLE_LOCATION_UPDATES);
-        }
-
-        public void requestLocationUpdate() {
-            sendEmptyMessage(MSG_GET_NEW_LOCATION_UPDATE);
-        }
-
-        public void requestTwilightUpdate() {
-            sendEmptyMessage(MSG_DO_TWILIGHT_UPDATE);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_PROCESS_NEW_LOCATION: {
-                    final Location location = (Location)msg.obj;
-                    final boolean hasMoved = hasMoved(mLocation, location);
-                    final boolean hasBetterAccuracy = mLocation == null
-                            || location.getAccuracy() < mLocation.getAccuracy();
-                    if (DEBUG) {
-                        Slog.d(TAG, "Processing new location: " + location
-                               + ", hasMoved=" + hasMoved
-                               + ", hasBetterAccuracy=" + hasBetterAccuracy);
-                    }
-                    if (hasMoved || hasBetterAccuracy) {
-                        setLocation(location);
-                    }
-                    break;
-                }
-
-                case MSG_GET_NEW_LOCATION_UPDATE:
-                    if (!mNetworkListenerEnabled) {
-                        // Don't do anything -- we are still trying to get a
-                        // location.
-                        return;
-                    }
-                    if ((mLastNetworkRegisterTime + MIN_LOCATION_UPDATE_MS) >=
-                            SystemClock.elapsedRealtime()) {
-                        // Don't do anything -- it hasn't been long enough
-                        // since we last requested an update.
-                        return;
-                    }
-
-                    // Unregister the current location monitor, so we can
-                    // register a new one for it to get an immediate update.
-                    mNetworkListenerEnabled = false;
-                    mLocationManager.removeUpdates(mEmptyLocationListener);
-
-                    // Fall through to re-register listener.
-                case MSG_ENABLE_LOCATION_UPDATES:
-                    // enable network provider to receive at least location updates for a given
-                    // distance.
-                    boolean networkLocationEnabled;
-                    try {
-                        networkLocationEnabled =
-                            mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
-                    } catch (Exception e) {
-                        // we may get IllegalArgumentException if network location provider
-                        // does not exist or is not yet installed.
-                        networkLocationEnabled = false;
-                    }
-                    if (!mNetworkListenerEnabled && networkLocationEnabled) {
-                        mNetworkListenerEnabled = true;
-                        mLastNetworkRegisterTime = SystemClock.elapsedRealtime();
-                        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
-                                LOCATION_UPDATE_MS, 0, mEmptyLocationListener);
-
-                        if (!mDidFirstInit) {
-                            mDidFirstInit = true;
-                            if (mLocation == null) {
-                                retrieveLocation();
-                            }
-                        }
-                    }
-
-                    // enable passive provider to receive updates from location fixes (gps
-                    // and network).
-                    boolean passiveLocationEnabled;
-                    try {
-                        passiveLocationEnabled =
-                            mLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER);
-                    } catch (Exception e) {
-                        // we may get IllegalArgumentException if passive location provider
-                        // does not exist or is not yet installed.
-                        passiveLocationEnabled = false;
-                    }
-
-                    if (!mPassiveListenerEnabled && passiveLocationEnabled) {
-                        mPassiveListenerEnabled = true;
-                        mLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER,
-                                0, LOCATION_UPDATE_DISTANCE_METER , mLocationListener);
-                    }
-
-                    if (!(mNetworkListenerEnabled && mPassiveListenerEnabled)) {
-                        mLastUpdateInterval *= 1.5;
-                        if (mLastUpdateInterval == 0) {
-                            mLastUpdateInterval = LOCATION_UPDATE_ENABLE_INTERVAL_MIN;
-                        } else if (mLastUpdateInterval > LOCATION_UPDATE_ENABLE_INTERVAL_MAX) {
-                            mLastUpdateInterval = LOCATION_UPDATE_ENABLE_INTERVAL_MAX;
-                        }
-                        sendEmptyMessageDelayed(MSG_ENABLE_LOCATION_UPDATES, mLastUpdateInterval);
-                    }
-                    break;
-
-                case MSG_DO_TWILIGHT_UPDATE:
-                    updateTwilightState();
-                    break;
-            }
-        }
-
-        private void retrieveLocation() {
-            Location location = null;
-            final Iterator<String> providers =
-                    mLocationManager.getProviders(new Criteria(), true).iterator();
-            while (providers.hasNext()) {
-                final Location lastKnownLocation =
-                        mLocationManager.getLastKnownLocation(providers.next());
-                // pick the most recent location
-                if (location == null || (lastKnownLocation != null &&
-                        location.getElapsedRealtimeNanos() <
-                        lastKnownLocation.getElapsedRealtimeNanos())) {
-                    location = lastKnownLocation;
-                }
-            }
-
-            // In the case there is no location available (e.g. GPS fix or network location
-            // is not available yet), the longitude of the location is estimated using the timezone,
-            // latitude and accuracy are set to get a good average.
-            if (location == null) {
-                Time currentTime = new Time();
-                currentTime.set(System.currentTimeMillis());
-                double lngOffset = FACTOR_GMT_OFFSET_LONGITUDE *
-                        (currentTime.gmtoff - (currentTime.isDst > 0 ? 3600 : 0));
-                location = new Location("fake");
-                location.setLongitude(lngOffset);
-                location.setLatitude(0);
-                location.setAccuracy(417000.0f);
-                location.setTime(System.currentTimeMillis());
-                location.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
-
-                if (DEBUG) {
-                    Slog.d(TAG, "Estimated location from timezone: " + location);
-                }
-            }
-
-            setLocation(location);
-        }
-
-        private void setLocation(Location location) {
-            mLocation = location;
-            updateTwilightState();
-        }
-
-        private void updateTwilightState() {
-            if (mLocation == null) {
-                setTwilightState(null);
-                return;
-            }
-
-            final long now = System.currentTimeMillis();
-
-            // calculate yesterday's twilight
-            mTwilightCalculator.calculateTwilight(now - DateUtils.DAY_IN_MILLIS,
-                    mLocation.getLatitude(), mLocation.getLongitude());
-            final long yesterdaySunset = mTwilightCalculator.mSunset;
-
-            // calculate today's twilight
-            mTwilightCalculator.calculateTwilight(now,
-                    mLocation.getLatitude(), mLocation.getLongitude());
-            final boolean isNight = (mTwilightCalculator.mState == TwilightCalculator.NIGHT);
-            final long todaySunrise = mTwilightCalculator.mSunrise;
-            final long todaySunset = mTwilightCalculator.mSunset;
-
-            // calculate tomorrow's twilight
-            mTwilightCalculator.calculateTwilight(now + DateUtils.DAY_IN_MILLIS,
-                    mLocation.getLatitude(), mLocation.getLongitude());
-            final long tomorrowSunrise = mTwilightCalculator.mSunrise;
-
-            // set twilight state
-            TwilightState state = new TwilightState(isNight, yesterdaySunset,
-                    todaySunrise, todaySunset, tomorrowSunrise);
-            if (DEBUG) {
-                Slog.d(TAG, "Updating twilight state: " + state);
-            }
-            setTwilightState(state);
-
-            // schedule next update
-            long nextUpdate = 0;
-            if (todaySunrise == -1 || todaySunset == -1) {
-                // In the case the day or night never ends the update is scheduled 12 hours later.
-                nextUpdate = now + 12 * DateUtils.HOUR_IN_MILLIS;
-            } else {
-                // add some extra time to be on the safe side.
-                nextUpdate += DateUtils.MINUTE_IN_MILLIS;
-
-                if (now > todaySunset) {
-                    nextUpdate += tomorrowSunrise;
-                } else if (now > todaySunrise) {
-                    nextUpdate += todaySunset;
-                } else {
-                    nextUpdate += todaySunrise;
-                }
-            }
-
-            if (DEBUG) {
-                Slog.d(TAG, "Next update in " + (nextUpdate - now) + " ms");
-            }
-
-            Intent updateIntent = new Intent(ACTION_UPDATE_TWILIGHT_STATE);
-            PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, updateIntent, 0);
-            mAlarmManager.cancel(pendingIntent);
-            mAlarmManager.setExact(AlarmManager.RTC, nextUpdate, pendingIntent);
-        }
-    };
-
-    private final BroadcastReceiver mUpdateLocationReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())
-                    && !intent.getBooleanExtra("state", false)) {
-                // Airplane mode is now off!
-                mLocationHandler.requestLocationUpdate();
-                return;
-            }
-
-            // Time zone has changed or alarm expired.
-            mLocationHandler.requestTwilightUpdate();
-        }
-    };
-
-    // A LocationListener to initialize the network location provider. The location updates
-    // are handled through the passive location provider.
-    private final LocationListener mEmptyLocationListener =  new LocationListener() {
-        public void onLocationChanged(Location location) {
-        }
-
-        public void onProviderDisabled(String provider) {
-        }
-
-        public void onProviderEnabled(String provider) {
-        }
-
-        public void onStatusChanged(String provider, int status, Bundle extras) {
-        }
-    };
-
-    private final LocationListener mLocationListener = new LocationListener() {
-        public void onLocationChanged(Location location) {
-            mLocationHandler.processNewLocation(location);
-        }
-
-        public void onProviderDisabled(String provider) {
-        }
-
-        public void onProviderEnabled(String provider) {
-        }
-
-        public void onStatusChanged(String provider, int status, Bundle extras) {
-        }
-    };
-}
diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java
deleted file mode 100644
index 062be01..0000000
--- a/services/java/com/android/server/UiModeManagerService.java
+++ /dev/null
@@ -1,608 +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.server;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.ActivityManagerNative;
-import android.app.IUiModeManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.StatusBarManager;
-import android.app.UiModeManager;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.content.res.Configuration;
-import android.os.BatteryManager;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.PowerManager;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.service.dreams.Sandman;
-import android.util.Slog;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-
-import com.android.internal.R;
-import com.android.internal.app.DisableCarModeActivity;
-import com.android.server.TwilightService.TwilightState;
-
-final class UiModeManagerService extends IUiModeManager.Stub {
-    private static final String TAG = UiModeManager.class.getSimpleName();
-    private static final boolean LOG = false;
-
-    // Enable launching of applications when entering the dock.
-    private static final boolean ENABLE_LAUNCH_CAR_DOCK_APP = true;
-    private static final boolean ENABLE_LAUNCH_DESK_DOCK_APP = true;
-
-    private final Context mContext;
-    private final TwilightService mTwilightService;
-    private final Handler mHandler = new Handler();
-
-    final Object mLock = new Object();
-
-    private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
-    private int mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
-
-    private int mNightMode = UiModeManager.MODE_NIGHT_NO;
-    private boolean mCarModeEnabled = false;
-    private boolean mCharging = false;
-    private final int mDefaultUiModeType;
-    private final boolean mCarModeKeepsScreenOn;
-    private final boolean mDeskModeKeepsScreenOn;
-    private final boolean mTelevision;
-
-    private boolean mComputedNightMode;
-    private int mCurUiMode = 0;
-    private int mSetUiMode = 0;
-
-    private boolean mHoldingConfiguration = false;
-    private Configuration mConfiguration = new Configuration();
-
-    private boolean mSystemReady;
-
-    private NotificationManager mNotificationManager;
-
-    private StatusBarManager mStatusBarManager;
-
-    private final PowerManager mPowerManager;
-    private final PowerManager.WakeLock mWakeLock;
-
-    static Intent buildHomeIntent(String category) {
-        Intent intent = new Intent(Intent.ACTION_MAIN);
-        intent.addCategory(category);
-        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
-        return intent;
-    }
-
-    // The broadcast receiver which receives the result of the ordered broadcast sent when
-    // the dock state changes. The original ordered broadcast is sent with an initial result
-    // code of RESULT_OK. If any of the registered broadcast receivers changes this value, e.g.,
-    // to RESULT_CANCELED, then the intent to start a dock app will not be sent.
-    private final BroadcastReceiver mResultReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            if (getResultCode() != Activity.RESULT_OK) {
-                if (LOG) {
-                    Slog.v(TAG, "Handling broadcast result for action " + intent.getAction()
-                            + ": canceled: " + getResultCode());
-                }
-                return;
-            }
-
-            final int enableFlags = intent.getIntExtra("enableFlags", 0);
-            final int disableFlags = intent.getIntExtra("disableFlags", 0);
-            synchronized (mLock) {
-                updateAfterBroadcastLocked(intent.getAction(), enableFlags, disableFlags);
-            }
-        }
-    };
-
-    private final BroadcastReceiver mDockModeReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
-                    Intent.EXTRA_DOCK_STATE_UNDOCKED);
-            updateDockState(state);
-        }
-    };
-
-    private final BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            mCharging = (intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0);
-            synchronized (mLock) {
-                if (mSystemReady) {
-                    updateLocked(0, 0);
-                }
-            }
-        }
-    };
-
-    private final TwilightService.TwilightListener mTwilightListener =
-            new TwilightService.TwilightListener() {
-        @Override
-        public void onTwilightStateChanged() {
-            updateTwilight();
-        }
-    };
-
-    public UiModeManagerService(Context context, TwilightService twilight) {
-        mContext = context;
-        mTwilightService = twilight;
-
-        ServiceManager.addService(Context.UI_MODE_SERVICE, this);
-
-        mContext.registerReceiver(mDockModeReceiver,
-                new IntentFilter(Intent.ACTION_DOCK_EVENT));
-        mContext.registerReceiver(mBatteryReceiver,
-                new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
-
-        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
-        mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, TAG);
-
-        mConfiguration.setToDefaults();
-
-        mDefaultUiModeType = context.getResources().getInteger(
-                com.android.internal.R.integer.config_defaultUiModeType);
-        mCarModeKeepsScreenOn = (context.getResources().getInteger(
-                com.android.internal.R.integer.config_carDockKeepsScreenOn) == 1);
-        mDeskModeKeepsScreenOn = (context.getResources().getInteger(
-                com.android.internal.R.integer.config_deskDockKeepsScreenOn) == 1);
-        mTelevision = context.getPackageManager().hasSystemFeature(
-                PackageManager.FEATURE_TELEVISION);
-
-        mNightMode = Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.UI_NIGHT_MODE, UiModeManager.MODE_NIGHT_AUTO);
-
-        mTwilightService.registerListener(mTwilightListener, mHandler);
-    }
-
-    @Override // Binder call
-    public void disableCarMode(int flags) {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                setCarModeLocked(false);
-                if (mSystemReady) {
-                    updateLocked(0, flags);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public void enableCarMode(int flags) {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                setCarModeLocked(true);
-                if (mSystemReady) {
-                    updateLocked(flags, 0);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public int getCurrentModeType() {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                return mCurUiMode & Configuration.UI_MODE_TYPE_MASK;
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public void setNightMode(int mode) {
-        switch (mode) {
-            case UiModeManager.MODE_NIGHT_NO:
-            case UiModeManager.MODE_NIGHT_YES:
-            case UiModeManager.MODE_NIGHT_AUTO:
-                break;
-            default:
-                throw new IllegalArgumentException("Unknown mode: " + mode);
-        }
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                if (isDoingNightModeLocked() && mNightMode != mode) {
-                    Settings.Secure.putInt(mContext.getContentResolver(),
-                            Settings.Secure.UI_NIGHT_MODE, mode);
-                    mNightMode = mode;
-                    updateLocked(0, 0);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public int getNightMode() {
-        synchronized (mLock) {
-            return mNightMode;
-        }
-    }
-
-    void systemReady() {
-        synchronized (mLock) {
-            mSystemReady = true;
-            mCarModeEnabled = mDockState == Intent.EXTRA_DOCK_STATE_CAR;
-            updateComputedNightModeLocked();
-            updateLocked(0, 0);
-        }
-    }
-
-    private boolean isDoingNightModeLocked() {
-        return mCarModeEnabled || mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;
-    }
-
-    private void setCarModeLocked(boolean enabled) {
-        if (mCarModeEnabled != enabled) {
-            mCarModeEnabled = enabled;
-        }
-    }
-
-    private void updateDockState(int newState) {
-        synchronized (mLock) {
-            if (newState != mDockState) {
-                mDockState = newState;
-                setCarModeLocked(mDockState == Intent.EXTRA_DOCK_STATE_CAR);
-                if (mSystemReady) {
-                    updateLocked(UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME, 0);
-                }
-            }
-        }
-    }
-
-    private static boolean isDeskDockState(int state) {
-        switch (state) {
-            case Intent.EXTRA_DOCK_STATE_DESK:
-            case Intent.EXTRA_DOCK_STATE_LE_DESK:
-            case Intent.EXTRA_DOCK_STATE_HE_DESK:
-                return true;
-            default:
-                return false;
-        }
-    }
-
-    private void updateConfigurationLocked() {
-        int uiMode = mTelevision ? Configuration.UI_MODE_TYPE_TELEVISION : mDefaultUiModeType;
-        if (mCarModeEnabled) {
-            uiMode = Configuration.UI_MODE_TYPE_CAR;
-        } else if (isDeskDockState(mDockState)) {
-            uiMode = Configuration.UI_MODE_TYPE_DESK;
-        }
-        if (mCarModeEnabled) {
-            if (mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
-                updateComputedNightModeLocked();
-                uiMode |= mComputedNightMode ? Configuration.UI_MODE_NIGHT_YES
-                        : Configuration.UI_MODE_NIGHT_NO;
-            } else {
-                uiMode |= mNightMode << 4;
-            }
-        } else {
-            // Disabling the car mode clears the night mode.
-            uiMode = (uiMode & ~Configuration.UI_MODE_NIGHT_MASK) | Configuration.UI_MODE_NIGHT_NO;
-        }
-
-        if (LOG) {
-            Slog.d(TAG,
-                "updateConfigurationLocked: mDockState=" + mDockState
-                + "; mCarMode=" + mCarModeEnabled
-                + "; mNightMode=" + mNightMode
-                + "; uiMode=" + uiMode);
-        }
-
-        mCurUiMode = uiMode;
-        if (!mHoldingConfiguration) {
-            mConfiguration.uiMode = uiMode;
-        }
-    }
-
-    private void sendConfigurationLocked() {
-        if (mSetUiMode != mConfiguration.uiMode) {
-            mSetUiMode = mConfiguration.uiMode;
-
-            try {
-                ActivityManagerNative.getDefault().updateConfiguration(mConfiguration);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Failure communicating with activity manager", e);
-            }
-        }
-    }
-
-    private void updateLocked(int enableFlags, int disableFlags) {
-        String action = null;
-        String oldAction = null;
-        if (mLastBroadcastState == Intent.EXTRA_DOCK_STATE_CAR) {
-            adjustStatusBarCarModeLocked();
-            oldAction = UiModeManager.ACTION_EXIT_CAR_MODE;
-        } else if (isDeskDockState(mLastBroadcastState)) {
-            oldAction = UiModeManager.ACTION_EXIT_DESK_MODE;
-        }
-
-        if (mCarModeEnabled) {
-            if (mLastBroadcastState != Intent.EXTRA_DOCK_STATE_CAR) {
-                adjustStatusBarCarModeLocked();
-
-                if (oldAction != null) {
-                    mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
-                }
-                mLastBroadcastState = Intent.EXTRA_DOCK_STATE_CAR;
-                action = UiModeManager.ACTION_ENTER_CAR_MODE;
-            }
-        } else if (isDeskDockState(mDockState)) {
-            if (!isDeskDockState(mLastBroadcastState)) {
-                if (oldAction != null) {
-                    mContext.sendBroadcastAsUser(new Intent(oldAction), UserHandle.ALL);
-                }
-                mLastBroadcastState = mDockState;
-                action = UiModeManager.ACTION_ENTER_DESK_MODE;
-            }
-        } else {
-            mLastBroadcastState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
-            action = oldAction;
-        }
-
-        if (action != null) {
-            if (LOG) {
-                Slog.v(TAG, String.format(
-                    "updateLocked: preparing broadcast: action=%s enable=0x%08x disable=0x%08x",
-                    action, enableFlags, disableFlags));
-            }
-
-            // Send the ordered broadcast; the result receiver will receive after all
-            // broadcasts have been sent. If any broadcast receiver changes the result
-            // code from the initial value of RESULT_OK, then the result receiver will
-            // not launch the corresponding dock application. This gives apps a chance
-            // to override the behavior and stay in their app even when the device is
-            // placed into a dock.
-            Intent intent = new Intent(action);
-            intent.putExtra("enableFlags", enableFlags);
-            intent.putExtra("disableFlags", disableFlags);
-            mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
-                    mResultReceiver, null, Activity.RESULT_OK, null, null);
-
-            // Attempting to make this transition a little more clean, we are going
-            // to hold off on doing a configuration change until we have finished
-            // the broadcast and started the home activity.
-            mHoldingConfiguration = true;
-            updateConfigurationLocked();
-        } else {
-            String category = null;
-            if (mCarModeEnabled) {
-                if (ENABLE_LAUNCH_CAR_DOCK_APP
-                        && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
-                    category = Intent.CATEGORY_CAR_DOCK;
-                }
-            } else if (isDeskDockState(mDockState)) {
-                if (ENABLE_LAUNCH_DESK_DOCK_APP
-                        && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
-                    category = Intent.CATEGORY_DESK_DOCK;
-                }
-            } else {
-                if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
-                    category = Intent.CATEGORY_HOME;
-                }
-            }
-
-            if (LOG) {
-                Slog.v(TAG, "updateLocked: null action, mDockState="
-                        + mDockState +", category=" + category);
-            }
-
-            sendConfigurationAndStartDreamOrDockAppLocked(category);
-        }
-
-        // keep screen on when charging and in car mode
-        boolean keepScreenOn = mCharging &&
-                ((mCarModeEnabled && mCarModeKeepsScreenOn) ||
-                 (mCurUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskModeKeepsScreenOn));
-        if (keepScreenOn != mWakeLock.isHeld()) {
-            if (keepScreenOn) {
-                mWakeLock.acquire();
-            } else {
-                mWakeLock.release();
-            }
-        }
-    }
-
-    private void updateAfterBroadcastLocked(String action, int enableFlags, int disableFlags) {
-        // Launch a dock activity
-        String category = null;
-        if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(action)) {
-            // Only launch car home when car mode is enabled and the caller
-            // has asked us to switch to it.
-            if (ENABLE_LAUNCH_CAR_DOCK_APP
-                    && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
-                category = Intent.CATEGORY_CAR_DOCK;
-            }
-        } else if (UiModeManager.ACTION_ENTER_DESK_MODE.equals(action)) {
-            // Only launch car home when desk mode is enabled and the caller
-            // has asked us to switch to it.  Currently re-using the car
-            // mode flag since we don't have a formal API for "desk mode".
-            if (ENABLE_LAUNCH_DESK_DOCK_APP
-                    && (enableFlags & UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME) != 0) {
-                category = Intent.CATEGORY_DESK_DOCK;
-            }
-        } else {
-            // Launch the standard home app if requested.
-            if ((disableFlags & UiModeManager.DISABLE_CAR_MODE_GO_HOME) != 0) {
-                category = Intent.CATEGORY_HOME;
-            }
-        }
-
-        if (LOG) {
-            Slog.v(TAG, String.format(
-                "Handling broadcast result for action %s: enable=0x%08x, disable=0x%08x, "
-                    + "category=%s",
-                action, enableFlags, disableFlags, category));
-        }
-
-        sendConfigurationAndStartDreamOrDockAppLocked(category);
-    }
-
-    private void sendConfigurationAndStartDreamOrDockAppLocked(String category) {
-        // Update the configuration but don't send it yet.
-        mHoldingConfiguration = false;
-        updateConfigurationLocked();
-
-        // Start the dock app, if there is one.
-        boolean dockAppStarted = false;
-        if (category != null) {
-            // Now we are going to be careful about switching the
-            // configuration and starting the activity -- we need to
-            // do this in a specific order under control of the
-            // activity manager, to do it cleanly.  So compute the
-            // new config, but don't set it yet, and let the
-            // activity manager take care of both the start and config
-            // change.
-            Intent homeIntent = buildHomeIntent(category);
-            if (Sandman.shouldStartDockApp(mContext, homeIntent)) {
-                try {
-                    int result = ActivityManagerNative.getDefault().startActivityWithConfig(
-                            null, null, homeIntent, null, null, null, 0, 0,
-                            mConfiguration, null, UserHandle.USER_CURRENT);
-                    if (result >= ActivityManager.START_SUCCESS) {
-                        dockAppStarted = true;
-                    } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) {
-                        Slog.e(TAG, "Could not start dock app: " + homeIntent
-                                + ", startActivityWithConfig result " + result);
-                    }
-                } catch (RemoteException ex) {
-                    Slog.e(TAG, "Could not start dock app: " + homeIntent, ex);
-                }
-            }
-        }
-
-        // Send the new configuration.
-        sendConfigurationLocked();
-
-        // If we did not start a dock app, then start dreaming if supported.
-        if (category != null && !dockAppStarted) {
-            Sandman.startDreamWhenDockedIfAppropriate(mContext);
-        }
-    }
-
-    private void adjustStatusBarCarModeLocked() {
-        if (mStatusBarManager == null) {
-            mStatusBarManager = (StatusBarManager)
-                    mContext.getSystemService(Context.STATUS_BAR_SERVICE);
-        }
-
-        // Fear not: StatusBarManagerService manages a list of requests to disable
-        // features of the status bar; these are ORed together to form the
-        // active disabled list. So if (for example) the device is locked and
-        // the status bar should be totally disabled, the calls below will
-        // have no effect until the device is unlocked.
-        if (mStatusBarManager != null) {
-            mStatusBarManager.disable(mCarModeEnabled
-                ? StatusBarManager.DISABLE_NOTIFICATION_TICKER
-                : StatusBarManager.DISABLE_NONE);
-        }
-
-        if (mNotificationManager == null) {
-            mNotificationManager = (NotificationManager)
-                    mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-        }
-
-        if (mNotificationManager != null) {
-            if (mCarModeEnabled) {
-                Intent carModeOffIntent = new Intent(mContext, DisableCarModeActivity.class);
-
-                Notification n = new Notification();
-                n.icon = R.drawable.stat_notify_car_mode;
-                n.defaults = Notification.DEFAULT_LIGHTS;
-                n.flags = Notification.FLAG_ONGOING_EVENT;
-                n.when = 0;
-                n.setLatestEventInfo(
-                        mContext,
-                        mContext.getString(R.string.car_mode_disable_notification_title),
-                        mContext.getString(R.string.car_mode_disable_notification_message),
-                        PendingIntent.getActivityAsUser(mContext, 0, carModeOffIntent, 0,
-                                null, UserHandle.CURRENT));
-                mNotificationManager.notifyAsUser(null,
-                        R.string.car_mode_disable_notification_title, n, UserHandle.ALL);
-            } else {
-                mNotificationManager.cancelAsUser(null,
-                        R.string.car_mode_disable_notification_title, UserHandle.ALL);
-            }
-        }
-    }
-
-    private void updateTwilight() {
-        synchronized (mLock) {
-            if (isDoingNightModeLocked() && mNightMode == UiModeManager.MODE_NIGHT_AUTO) {
-                updateComputedNightModeLocked();
-                updateLocked(0, 0);
-            }
-        }
-    }
-
-    private void updateComputedNightModeLocked() {
-        TwilightState state = mTwilightService.getCurrentState();
-        if (state != null) {
-            mComputedNightMode = state.isNight();
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-
-            pw.println("Permission Denial: can't dump uimode service from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mLock) {
-            pw.println("Current UI Mode Service state:");
-            pw.print("  mDockState="); pw.print(mDockState);
-                    pw.print(" mLastBroadcastState="); pw.println(mLastBroadcastState);
-            pw.print("  mNightMode="); pw.print(mNightMode);
-                    pw.print(" mCarModeEnabled="); pw.print(mCarModeEnabled);
-                    pw.print(" mComputedNightMode="); pw.println(mComputedNightMode);
-            pw.print("  mCurUiMode=0x"); pw.print(Integer.toHexString(mCurUiMode));
-                    pw.print(" mSetUiMode=0x"); pw.println(Integer.toHexString(mSetUiMode));
-            pw.print("  mHoldingConfiguration="); pw.print(mHoldingConfiguration);
-                    pw.print(" mSystemReady="); pw.println(mSystemReady);
-            pw.print("  mTwilightService.getCurrentState()=");
-                    pw.println(mTwilightService.getCurrentState());
-        }
-    }
-}
diff --git a/services/java/com/android/server/UiThread.java b/services/java/com/android/server/UiThread.java
deleted file mode 100644
index 60d73aa..0000000
--- a/services/java/com/android/server/UiThread.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2013 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;
-
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.StrictMode;
-import android.util.Slog;
-
-/**
- * Shared singleton thread for showing UI.  This is a foreground thread, and in
- * additional should not have operations that can take more than a few ms scheduled
- * on it to avoid UI jank.
- */
-public final class UiThread extends HandlerThread {
-    private static UiThread sInstance;
-    private static Handler sHandler;
-
-    private UiThread() {
-        super("android.ui", android.os.Process.THREAD_PRIORITY_FOREGROUND);
-    }
-
-    private static void ensureThreadLocked() {
-        if (sInstance == null) {
-            sInstance = new UiThread();
-            sInstance.start();
-            sHandler = new Handler(sInstance.getLooper());
-            sHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    //Looper.myLooper().setMessageLogging(new LogPrinter(
-                    //        Log.VERBOSE, "WindowManagerPolicy", Log.LOG_ID_SYSTEM));
-                    android.os.Process.setCanSelfBackground(false);
-
-                    // For debug builds, log event loop stalls to dropbox for analysis.
-                    if (StrictMode.conditionallyEnableDebugLogging()) {
-                        Slog.i("UiThread", "Enabled StrictMode logging for UI thread");
-                    }
-                }
-            });
-        }
-    }
-
-    public static UiThread get() {
-        synchronized (UiThread.class) {
-            ensureThreadLocked();
-            return sInstance;
-        }
-    }
-
-    public static Handler getHandler() {
-        synchronized (UiThread.class) {
-            ensureThreadLocked();
-            return sHandler;
-        }
-    }
-}
diff --git a/services/java/com/android/server/WallpaperManagerService.java b/services/java/com/android/server/WallpaperManagerService.java
deleted file mode 100644
index e6b6b93..0000000
--- a/services/java/com/android/server/WallpaperManagerService.java
+++ /dev/null
@@ -1,1345 +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.server;
-
-import static android.os.ParcelFileDescriptor.*;
-
-import android.app.ActivityManagerNative;
-import android.app.AppGlobals;
-import android.app.IUserSwitchObserver;
-import android.app.IWallpaperManager;
-import android.app.IWallpaperManagerCallback;
-import android.app.PendingIntent;
-import android.app.WallpaperInfo;
-import android.app.backup.BackupManager;
-import android.app.backup.WallpaperBackupHelper;
-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.IPackageManager;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.UserInfo;
-import android.content.res.Resources;
-import android.graphics.Point;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.FileUtils;
-import android.os.IBinder;
-import android.os.IRemoteCallback;
-import android.os.RemoteException;
-import android.os.FileObserver;
-import android.os.ParcelFileDescriptor;
-import android.os.RemoteCallbackList;
-import android.os.SELinux;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.service.wallpaper.IWallpaperConnection;
-import android.service.wallpaper.IWallpaperEngine;
-import android.service.wallpaper.IWallpaperService;
-import android.service.wallpaper.WallpaperService;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.Xml;
-import android.view.Display;
-import android.view.IWindowManager;
-import android.view.WindowManager;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.util.List;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.JournaledFile;
-
-class WallpaperManagerService extends IWallpaperManager.Stub {
-    static final String TAG = "WallpaperService";
-    static final boolean DEBUG = false;
-
-    final Object mLock = new Object[0];
-
-    /**
-     * Minimum time between crashes of a wallpaper service for us to consider
-     * restarting it vs. just reverting to the static wallpaper.
-     */
-    static final long MIN_WALLPAPER_CRASH_TIME = 10000;
-    static final String WALLPAPER = "wallpaper";
-    static final String WALLPAPER_INFO = "wallpaper_info.xml";
-
-    /**
-     * Name of the component used to display bitmap wallpapers from either the gallery or
-     * built-in wallpapers.
-     */
-    static final ComponentName IMAGE_WALLPAPER = new ComponentName("com.android.systemui",
-            "com.android.systemui.ImageWallpaper");
-
-    /**
-     * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
-     * that the wallpaper has changed. The CREATE is triggered when there is no
-     * wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
-     * everytime the wallpaper is changed.
-     */
-    private class WallpaperObserver extends FileObserver {
-
-        final WallpaperData mWallpaper;
-        final File mWallpaperDir;
-        final File mWallpaperFile;
-
-        public WallpaperObserver(WallpaperData wallpaper) {
-            super(getWallpaperDir(wallpaper.userId).getAbsolutePath(),
-                    CLOSE_WRITE | DELETE | DELETE_SELF);
-            mWallpaperDir = getWallpaperDir(wallpaper.userId);
-            mWallpaper = wallpaper;
-            mWallpaperFile = new File(mWallpaperDir, WALLPAPER);
-        }
-
-        @Override
-        public void onEvent(int event, String path) {
-            if (path == null) {
-                return;
-            }
-            synchronized (mLock) {
-                // changing the wallpaper means we'll need to back up the new one
-                long origId = Binder.clearCallingIdentity();
-                BackupManager bm = new BackupManager(mContext);
-                bm.dataChanged();
-                Binder.restoreCallingIdentity(origId);
-
-                File changedFile = new File(mWallpaperDir, path);
-                if (mWallpaperFile.equals(changedFile)) {
-                    notifyCallbacksLocked(mWallpaper);
-                    if (mWallpaper.wallpaperComponent == null || event != CLOSE_WRITE
-                            || mWallpaper.imageWallpaperPending) {
-                        if (event == CLOSE_WRITE) {
-                            mWallpaper.imageWallpaperPending = false;
-                        }
-                        bindWallpaperComponentLocked(IMAGE_WALLPAPER, true,
-                                false, mWallpaper, null);
-                        saveSettingsLocked(mWallpaper);
-                    }
-                }
-            }
-        }
-    }
-
-    final Context mContext;
-    final IWindowManager mIWindowManager;
-    final IPackageManager mIPackageManager;
-    final MyPackageMonitor mMonitor;
-    WallpaperData mLastWallpaper;
-
-    SparseArray<WallpaperData> mWallpaperMap = new SparseArray<WallpaperData>();
-
-    int mCurrentUserId;
-
-    static class WallpaperData {
-
-        int userId;
-
-        File wallpaperFile;
-
-        /**
-         * Client is currently writing a new image wallpaper.
-         */
-        boolean imageWallpaperPending;
-
-        /**
-         * Resource name if using a picture from the wallpaper gallery
-         */
-        String name = "";
-
-        /**
-         * The component name of the currently set live wallpaper.
-         */
-        ComponentName wallpaperComponent;
-
-        /**
-         * The component name of the wallpaper that should be set next.
-         */
-        ComponentName nextWallpaperComponent;
-
-        WallpaperConnection connection;
-        long lastDiedTime;
-        boolean wallpaperUpdating;
-        WallpaperObserver wallpaperObserver;
-
-        /**
-         * List of callbacks registered they should each be notified when the wallpaper is changed.
-         */
-        private RemoteCallbackList<IWallpaperManagerCallback> callbacks
-                = new RemoteCallbackList<IWallpaperManagerCallback>();
-
-        int width = -1;
-        int height = -1;
-
-        WallpaperData(int userId) {
-            this.userId = userId;
-            wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
-        }
-    }
-
-    class WallpaperConnection extends IWallpaperConnection.Stub
-            implements ServiceConnection {
-        final WallpaperInfo mInfo;
-        final Binder mToken = new Binder();
-        IWallpaperService mService;
-        IWallpaperEngine mEngine;
-        WallpaperData mWallpaper;
-        IRemoteCallback mReply;
-
-        boolean mDimensionsChanged = false;
-
-        public WallpaperConnection(WallpaperInfo info, WallpaperData wallpaper) {
-            mInfo = info;
-            mWallpaper = wallpaper;
-        }
-
-        @Override
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            synchronized (mLock) {
-                if (mWallpaper.connection == this) {
-                    mWallpaper.lastDiedTime = SystemClock.uptimeMillis();
-                    mService = IWallpaperService.Stub.asInterface(service);
-                    attachServiceLocked(this, mWallpaper);
-                    // XXX should probably do saveSettingsLocked() later
-                    // when we have an engine, but I'm not sure about
-                    // locking there and anyway we always need to be able to
-                    // recover if there is something wrong.
-                    saveSettingsLocked(mWallpaper);
-                }
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName name) {
-            synchronized (mLock) {
-                mService = null;
-                mEngine = null;
-                if (mWallpaper.connection == this) {
-                    Slog.w(TAG, "Wallpaper service gone: " + mWallpaper.wallpaperComponent);
-                    if (!mWallpaper.wallpaperUpdating
-                            && (mWallpaper.lastDiedTime + MIN_WALLPAPER_CRASH_TIME)
-                                > SystemClock.uptimeMillis()
-                            && mWallpaper.userId == mCurrentUserId) {
-                        Slog.w(TAG, "Reverting to built-in wallpaper!");
-                        clearWallpaperLocked(true, mWallpaper.userId, null);
-                    }
-                }
-            }
-        }
-
-        @Override
-        public void attachEngine(IWallpaperEngine engine) {
-            synchronized (mLock) {
-                mEngine = engine;
-                if (mDimensionsChanged) {
-                    try {
-                        mEngine.setDesiredSize(mWallpaper.width, mWallpaper.height);
-                    } catch (RemoteException e) {
-                        Slog.w(TAG, "Failed to set wallpaper dimensions", e);
-                    }
-                    mDimensionsChanged = false;
-                }
-            }
-        }
-
-        @Override
-        public void engineShown(IWallpaperEngine engine) {
-            synchronized (mLock) {
-                if (mReply != null) {
-                    long ident = Binder.clearCallingIdentity();
-                    try {
-                        mReply.sendResult(null);
-                    } catch (RemoteException e) {
-                        Binder.restoreCallingIdentity(ident);
-                    }
-                    mReply = null;
-                }
-            }
-        }
-
-        @Override
-        public ParcelFileDescriptor setWallpaper(String name) {
-            synchronized (mLock) {
-                if (mWallpaper.connection == this) {
-                    return updateWallpaperBitmapLocked(name, mWallpaper);
-                }
-                return null;
-            }
-        }
-    }
-
-    class MyPackageMonitor extends PackageMonitor {
-        @Override
-        public void onPackageUpdateFinished(String packageName, int uid) {
-            synchronized (mLock) {
-                if (mCurrentUserId != getChangingUserId()) {
-                    return;
-                }
-                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
-                if (wallpaper != null) {
-                    if (wallpaper.wallpaperComponent != null
-                            && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
-                        wallpaper.wallpaperUpdating = false;
-                        ComponentName comp = wallpaper.wallpaperComponent;
-                        clearWallpaperComponentLocked(wallpaper);
-                        if (!bindWallpaperComponentLocked(comp, false, false,
-                                wallpaper, null)) {
-                            Slog.w(TAG, "Wallpaper no longer available; reverting to default");
-                            clearWallpaperLocked(false, wallpaper.userId, null);
-                        }
-                    }
-                }
-            }
-        }
-
-        @Override
-        public void onPackageModified(String packageName) {
-            synchronized (mLock) {
-                if (mCurrentUserId != getChangingUserId()) {
-                    return;
-                }
-                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
-                if (wallpaper != null) {
-                    if (wallpaper.wallpaperComponent == null
-                            || !wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
-                        return;
-                    }
-                    doPackagesChangedLocked(true, wallpaper);
-                }
-            }
-        }
-
-        @Override
-        public void onPackageUpdateStarted(String packageName, int uid) {
-            synchronized (mLock) {
-                if (mCurrentUserId != getChangingUserId()) {
-                    return;
-                }
-                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
-                if (wallpaper != null) {
-                    if (wallpaper.wallpaperComponent != null
-                            && wallpaper.wallpaperComponent.getPackageName().equals(packageName)) {
-                        wallpaper.wallpaperUpdating = true;
-                    }
-                }
-            }
-        }
-
-        @Override
-        public boolean onHandleForceStop(Intent intent, String[] packages, int uid, boolean doit) {
-            synchronized (mLock) {
-                boolean changed = false;
-                if (mCurrentUserId != getChangingUserId()) {
-                    return false;
-                }
-                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
-                if (wallpaper != null) {
-                    boolean res = doPackagesChangedLocked(doit, wallpaper);
-                    changed |= res;
-                }
-                return changed;
-            }
-        }
-
-        @Override
-        public void onSomePackagesChanged() {
-            synchronized (mLock) {
-                if (mCurrentUserId != getChangingUserId()) {
-                    return;
-                }
-                WallpaperData wallpaper = mWallpaperMap.get(mCurrentUserId);
-                if (wallpaper != null) {
-                    doPackagesChangedLocked(true, wallpaper);
-                }
-            }
-        }
-
-        boolean doPackagesChangedLocked(boolean doit, WallpaperData wallpaper) {
-            boolean changed = false;
-            if (wallpaper.wallpaperComponent != null) {
-                int change = isPackageDisappearing(wallpaper.wallpaperComponent
-                        .getPackageName());
-                if (change == PACKAGE_PERMANENT_CHANGE
-                        || change == PACKAGE_TEMPORARY_CHANGE) {
-                    changed = true;
-                    if (doit) {
-                        Slog.w(TAG, "Wallpaper uninstalled, removing: "
-                                + wallpaper.wallpaperComponent);
-                        clearWallpaperLocked(false, wallpaper.userId, null);
-                    }
-                }
-            }
-            if (wallpaper.nextWallpaperComponent != null) {
-                int change = isPackageDisappearing(wallpaper.nextWallpaperComponent
-                        .getPackageName());
-                if (change == PACKAGE_PERMANENT_CHANGE
-                        || change == PACKAGE_TEMPORARY_CHANGE) {
-                    wallpaper.nextWallpaperComponent = null;
-                }
-            }
-            if (wallpaper.wallpaperComponent != null
-                    && isPackageModified(wallpaper.wallpaperComponent.getPackageName())) {
-                try {
-                    mContext.getPackageManager().getServiceInfo(
-                            wallpaper.wallpaperComponent, 0);
-                } catch (NameNotFoundException e) {
-                    Slog.w(TAG, "Wallpaper component gone, removing: "
-                            + wallpaper.wallpaperComponent);
-                    clearWallpaperLocked(false, wallpaper.userId, null);
-                }
-            }
-            if (wallpaper.nextWallpaperComponent != null
-                    && isPackageModified(wallpaper.nextWallpaperComponent.getPackageName())) {
-                try {
-                    mContext.getPackageManager().getServiceInfo(
-                            wallpaper.nextWallpaperComponent, 0);
-                } catch (NameNotFoundException e) {
-                    wallpaper.nextWallpaperComponent = null;
-                }
-            }
-            return changed;
-        }
-    }
-    
-    public WallpaperManagerService(Context context) {
-        if (DEBUG) Slog.v(TAG, "WallpaperService startup");
-        mContext = context;
-        mIWindowManager = IWindowManager.Stub.asInterface(
-                ServiceManager.getService(Context.WINDOW_SERVICE));
-        mIPackageManager = AppGlobals.getPackageManager();
-        mMonitor = new MyPackageMonitor();
-        mMonitor.register(context, null, UserHandle.ALL, true);
-        getWallpaperDir(UserHandle.USER_OWNER).mkdirs();
-        loadSettingsLocked(UserHandle.USER_OWNER);
-    }
-    
-    private static File getWallpaperDir(int userId) {
-        return Environment.getUserSystemDirectory(userId);
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        super.finalize();
-        for (int i = 0; i < mWallpaperMap.size(); i++) {
-            WallpaperData wallpaper = mWallpaperMap.valueAt(i);
-            wallpaper.wallpaperObserver.stopWatching();
-        }
-    }
-
-    public void systemRunning() {
-        if (DEBUG) Slog.v(TAG, "systemReady");
-        WallpaperData wallpaper = mWallpaperMap.get(UserHandle.USER_OWNER);
-        switchWallpaper(wallpaper, null);
-        wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
-        wallpaper.wallpaperObserver.startWatching();
-
-        IntentFilter userFilter = new IntentFilter();
-        userFilter.addAction(Intent.ACTION_USER_REMOVED);
-        userFilter.addAction(Intent.ACTION_USER_STOPPING);
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                String action = intent.getAction();
-                if (Intent.ACTION_USER_REMOVED.equals(action)) {
-                    onRemoveUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
-                            UserHandle.USER_NULL));
-                }
-                // TODO: Race condition causing problems when cleaning up on stopping a user.
-                // Comment this out for now.
-                // else if (Intent.ACTION_USER_STOPPING.equals(action)) {
-                //     onStoppingUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
-                //             UserHandle.USER_NULL));
-                // }
-            }
-        }, userFilter);
-
-        try {
-            ActivityManagerNative.getDefault().registerUserSwitchObserver(
-                    new IUserSwitchObserver.Stub() {
-                        @Override
-                        public void onUserSwitching(int newUserId, IRemoteCallback reply) {
-                            switchUser(newUserId, reply);
-                        }
-
-                        @Override
-                        public void onUserSwitchComplete(int newUserId) throws RemoteException {
-                        }
-                    });
-        } catch (RemoteException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-    }
-
-    String getName() {
-        synchronized (mLock) {
-            return mWallpaperMap.get(0).name;
-        }
-    }
-
-    void onStoppingUser(int userId) {
-        if (userId < 1) return;
-        synchronized (mLock) {
-            WallpaperData wallpaper = mWallpaperMap.get(userId);
-            if (wallpaper != null) {
-                if (wallpaper.wallpaperObserver != null) {
-                    wallpaper.wallpaperObserver.stopWatching();
-                    wallpaper.wallpaperObserver = null;
-                }
-                mWallpaperMap.remove(userId);
-            }
-        }
-    }
-
-    void onRemoveUser(int userId) {
-        if (userId < 1) return;
-        synchronized (mLock) {
-            onStoppingUser(userId);
-            File wallpaperFile = new File(getWallpaperDir(userId), WALLPAPER);
-            wallpaperFile.delete();
-            File wallpaperInfoFile = new File(getWallpaperDir(userId), WALLPAPER_INFO);
-            wallpaperInfoFile.delete();
-        }
-    }
-
-    void switchUser(int userId, IRemoteCallback reply) {
-        synchronized (mLock) {
-            mCurrentUserId = userId;
-            WallpaperData wallpaper = mWallpaperMap.get(userId);
-            if (wallpaper == null) {
-                wallpaper = new WallpaperData(userId);
-                mWallpaperMap.put(userId, wallpaper);
-                loadSettingsLocked(userId);
-            }
-            // Not started watching yet, in case wallpaper data was loaded for other reasons.
-            if (wallpaper.wallpaperObserver == null) {
-                wallpaper.wallpaperObserver = new WallpaperObserver(wallpaper);
-                wallpaper.wallpaperObserver.startWatching();
-            }
-            switchWallpaper(wallpaper, reply);
-        }
-    }
-
-    void switchWallpaper(WallpaperData wallpaper, IRemoteCallback reply) {
-        synchronized (mLock) {
-            RuntimeException e = null;
-            try {
-                ComponentName cname = wallpaper.wallpaperComponent != null ?
-                        wallpaper.wallpaperComponent : wallpaper.nextWallpaperComponent;
-                if (bindWallpaperComponentLocked(cname, true, false, wallpaper, reply)) {
-                    return;
-                }
-            } catch (RuntimeException e1) {
-                e = e1;
-            }
-            Slog.w(TAG, "Failure starting previous wallpaper", e);
-            clearWallpaperLocked(false, wallpaper.userId, reply);
-        }
-    }
-
-    public void clearWallpaper() {
-        if (DEBUG) Slog.v(TAG, "clearWallpaper");
-        synchronized (mLock) {
-            clearWallpaperLocked(false, UserHandle.getCallingUserId(), null);
-        }
-    }
-
-    void clearWallpaperLocked(boolean defaultFailed, int userId, IRemoteCallback reply) {
-        WallpaperData wallpaper = mWallpaperMap.get(userId);
-        File f = new File(getWallpaperDir(userId), WALLPAPER);
-        if (f.exists()) {
-            f.delete();
-        }
-        final long ident = Binder.clearCallingIdentity();
-        RuntimeException e = null;
-        try {
-            wallpaper.imageWallpaperPending = false;
-            if (userId != mCurrentUserId) return;
-            if (bindWallpaperComponentLocked(defaultFailed
-                    ? IMAGE_WALLPAPER
-                    : null, true, false, wallpaper, reply)) {
-                return;
-            }
-        } catch (IllegalArgumentException e1) {
-            e = e1;
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-        
-        // This can happen if the default wallpaper component doesn't
-        // exist.  This should be a system configuration problem, but
-        // let's not let it crash the system and just live with no
-        // wallpaper.
-        Slog.e(TAG, "Default wallpaper component not found!", e);
-        clearWallpaperComponentLocked(wallpaper);
-        if (reply != null) {
-            try {
-                reply.sendResult(null);
-            } catch (RemoteException e1) {
-            }
-        }
-    }
-
-    public boolean hasNamedWallpaper(String name) {
-        synchronized (mLock) {
-            List<UserInfo> users;
-            long ident = Binder.clearCallingIdentity();
-            try {
-                users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers();
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-            for (UserInfo user: users) {
-                WallpaperData wd = mWallpaperMap.get(user.id);
-                if (wd == null) {
-                    // User hasn't started yet, so load her settings to peek at the wallpaper
-                    loadSettingsLocked(user.id);
-                    wd = mWallpaperMap.get(user.id);
-                }
-                if (wd != null && name.equals(wd.name)) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    private Point getDefaultDisplaySize() {
-        Point p = new Point();
-        WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
-        Display d = wm.getDefaultDisplay();
-        d.getRealSize(p);
-        return p;
-    }
-
-    public void setDimensionHints(int width, int height) throws RemoteException {
-        checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
-        synchronized (mLock) {
-            int userId = UserHandle.getCallingUserId();
-            WallpaperData wallpaper = mWallpaperMap.get(userId);
-            if (wallpaper == null) {
-                throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
-            }
-            if (width <= 0 || height <= 0) {
-                throw new IllegalArgumentException("width and height must be > 0");
-            }
-            // Make sure it is at least as large as the display.
-            Point displaySize = getDefaultDisplaySize();
-            width = Math.max(width, displaySize.x);
-            height = Math.max(height, displaySize.y);
-
-            if (width != wallpaper.width || height != wallpaper.height) {
-                wallpaper.width = width;
-                wallpaper.height = height;
-                saveSettingsLocked(wallpaper);
-                if (mCurrentUserId != userId) return; // Don't change the properties now
-                if (wallpaper.connection != null) {
-                    if (wallpaper.connection.mEngine != null) {
-                        try {
-                            wallpaper.connection.mEngine.setDesiredSize(
-                                    width, height);
-                        } catch (RemoteException e) {
-                        }
-                        notifyCallbacksLocked(wallpaper);
-                    } else if (wallpaper.connection.mService != null) {
-                        // We've attached to the service but the engine hasn't attached back to us
-                        // yet. This means it will be created with the previous dimensions, so we
-                        // need to update it to the new dimensions once it attaches.
-                        wallpaper.connection.mDimensionsChanged = true;
-                    }
-                }
-            }
-        }
-    }
-
-    public int getWidthHint() throws RemoteException {
-        synchronized (mLock) {
-            WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
-            return wallpaper.width;
-        }
-    }
-
-    public int getHeightHint() throws RemoteException {
-        synchronized (mLock) {
-            WallpaperData wallpaper = mWallpaperMap.get(UserHandle.getCallingUserId());
-            return wallpaper.height;
-        }
-    }
-
-    public ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
-            Bundle outParams) {
-        synchronized (mLock) {
-            // This returns the current user's wallpaper, if called by a system service. Else it
-            // returns the wallpaper for the calling user.
-            int callingUid = Binder.getCallingUid();
-            int wallpaperUserId = 0;
-            if (callingUid == android.os.Process.SYSTEM_UID) {
-                wallpaperUserId = mCurrentUserId;
-            } else {
-                wallpaperUserId = UserHandle.getUserId(callingUid);
-            }
-            WallpaperData wallpaper = mWallpaperMap.get(wallpaperUserId);
-            try {
-                if (outParams != null) {
-                    outParams.putInt("width", wallpaper.width);
-                    outParams.putInt("height", wallpaper.height);
-                }
-                wallpaper.callbacks.register(cb);
-                File f = new File(getWallpaperDir(wallpaperUserId), WALLPAPER);
-                if (!f.exists()) {
-                    return null;
-                }
-                return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
-            } catch (FileNotFoundException e) {
-                /* Shouldn't happen as we check to see if the file exists */
-                Slog.w(TAG, "Error getting wallpaper", e);
-            }
-            return null;
-        }
-    }
-
-    public WallpaperInfo getWallpaperInfo() {
-        int userId = UserHandle.getCallingUserId();
-        synchronized (mLock) {
-            WallpaperData wallpaper = mWallpaperMap.get(userId);
-            if (wallpaper.connection != null) {
-                return wallpaper.connection.mInfo;
-            }
-            return null;
-        }
-    }
-
-    public ParcelFileDescriptor setWallpaper(String name) {
-        checkPermission(android.Manifest.permission.SET_WALLPAPER);
-        synchronized (mLock) {
-            if (DEBUG) Slog.v(TAG, "setWallpaper");
-            int userId = UserHandle.getCallingUserId();
-            WallpaperData wallpaper = mWallpaperMap.get(userId);
-            if (wallpaper == null) {
-                throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
-            }
-            final long ident = Binder.clearCallingIdentity();
-            try {
-                ParcelFileDescriptor pfd = updateWallpaperBitmapLocked(name, wallpaper);
-                if (pfd != null) {
-                    wallpaper.imageWallpaperPending = true;
-                }
-                return pfd;
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    ParcelFileDescriptor updateWallpaperBitmapLocked(String name, WallpaperData wallpaper) {
-        if (name == null) name = "";
-        try {
-            File dir = getWallpaperDir(wallpaper.userId);
-            if (!dir.exists()) {
-                dir.mkdir();
-                FileUtils.setPermissions(
-                        dir.getPath(),
-                        FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IXOTH,
-                        -1, -1);
-            }
-            File file = new File(dir, WALLPAPER);
-            ParcelFileDescriptor fd = ParcelFileDescriptor.open(file,
-                    MODE_CREATE|MODE_READ_WRITE);
-            if (!SELinux.restorecon(file)) {
-                return null;
-            }
-            wallpaper.name = name;
-            return fd;
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "Error setting wallpaper", e);
-        }
-        return null;
-    }
-
-    public void setWallpaperComponent(ComponentName name) {
-        checkPermission(android.Manifest.permission.SET_WALLPAPER_COMPONENT);
-        synchronized (mLock) {
-            if (DEBUG) Slog.v(TAG, "setWallpaperComponent name=" + name);
-            int userId = UserHandle.getCallingUserId();
-            WallpaperData wallpaper = mWallpaperMap.get(userId);
-            if (wallpaper == null) {
-                throw new IllegalStateException("Wallpaper not yet initialized for user " + userId);
-            }
-            final long ident = Binder.clearCallingIdentity();
-            try {
-                wallpaper.imageWallpaperPending = false;
-                bindWallpaperComponentLocked(name, false, true, wallpaper, null);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-    
-    boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force,
-            boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
-        if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
-        // Has the component changed?
-        if (!force) {
-            if (wallpaper.connection != null) {
-                if (wallpaper.wallpaperComponent == null) {
-                    if (componentName == null) {
-                        if (DEBUG) Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
-                        // Still using default wallpaper.
-                        return true;
-                    }
-                } else if (wallpaper.wallpaperComponent.equals(componentName)) {
-                    // Changing to same wallpaper.
-                    if (DEBUG) Slog.v(TAG, "same wallpaper");
-                    return true;
-                }
-            }
-        }
-        
-        try {
-            if (componentName == null) {
-                String defaultComponent = 
-                    mContext.getString(com.android.internal.R.string.default_wallpaper_component);
-                if (defaultComponent != null) {
-                    // See if there is a default wallpaper component specified
-                    componentName = ComponentName.unflattenFromString(defaultComponent);
-                    if (DEBUG) Slog.v(TAG, "Use default component wallpaper:" + componentName);
-                }
-                if (componentName == null) {
-                    // Fall back to static image wallpaper
-                    componentName = IMAGE_WALLPAPER;
-                    //clearWallpaperComponentLocked();
-                    //return;
-                    if (DEBUG) Slog.v(TAG, "Using image wallpaper");
-                }
-            }
-            int serviceUserId = wallpaper.userId;
-            ServiceInfo si = mIPackageManager.getServiceInfo(componentName,
-                    PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
-            if (si == null) {
-                // The wallpaper component we're trying to use doesn't exist
-                Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
-                return false;
-            }
-            if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
-                String msg = "Selected service does not require "
-                        + android.Manifest.permission.BIND_WALLPAPER
-                        + ": " + componentName;
-                if (fromUser) {
-                    throw new SecurityException(msg);
-                }
-                Slog.w(TAG, msg);
-                return false;
-            }
-            
-            WallpaperInfo wi = null;
-            
-            Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
-            if (componentName != null && !componentName.equals(IMAGE_WALLPAPER)) {
-                // Make sure the selected service is actually a wallpaper service.
-                List<ResolveInfo> ris =
-                        mIPackageManager.queryIntentServices(intent,
-                                intent.resolveTypeIfNeeded(mContext.getContentResolver()),
-                                PackageManager.GET_META_DATA, serviceUserId);
-                for (int i=0; i<ris.size(); i++) {
-                    ServiceInfo rsi = ris.get(i).serviceInfo;
-                    if (rsi.name.equals(si.name) &&
-                            rsi.packageName.equals(si.packageName)) {
-                        try {
-                            wi = new WallpaperInfo(mContext, ris.get(i));
-                        } catch (XmlPullParserException e) {
-                            if (fromUser) {
-                                throw new IllegalArgumentException(e);
-                            }
-                            Slog.w(TAG, e);
-                            return false;
-                        } catch (IOException e) {
-                            if (fromUser) {
-                                throw new IllegalArgumentException(e);
-                            }
-                            Slog.w(TAG, e);
-                            return false;
-                        }
-                        break;
-                    }
-                }
-                if (wi == null) {
-                    String msg = "Selected service is not a wallpaper: "
-                            + componentName;
-                    if (fromUser) {
-                        throw new SecurityException(msg);
-                    }
-                    Slog.w(TAG, msg);
-                    return false;
-                }
-            }
-            
-            // Bind the service!
-            if (DEBUG) Slog.v(TAG, "Binding to:" + componentName);
-            WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
-            intent.setComponent(componentName);
-            intent.putExtra(Intent.EXTRA_CLIENT_LABEL,
-                    com.android.internal.R.string.wallpaper_binding_label);
-            intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(
-                    mContext, 0,
-                    Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER),
-                            mContext.getText(com.android.internal.R.string.chooser_wallpaper)),
-                    0, null, new UserHandle(serviceUserId)));
-            if (!mContext.bindServiceAsUser(intent, newConn,
-                    Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI,
-                    new UserHandle(serviceUserId))) {
-                String msg = "Unable to bind service: "
-                        + componentName;
-                if (fromUser) {
-                    throw new IllegalArgumentException(msg);
-                }
-                Slog.w(TAG, msg);
-                return false;
-            }
-            if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
-                detachWallpaperLocked(mLastWallpaper);
-            }
-            wallpaper.wallpaperComponent = componentName;
-            wallpaper.connection = newConn;
-            wallpaper.lastDiedTime = SystemClock.uptimeMillis();
-            newConn.mReply = reply;
-            try {
-                if (wallpaper.userId == mCurrentUserId) {
-                    if (DEBUG)
-                        Slog.v(TAG, "Adding window token: " + newConn.mToken);
-                    mIWindowManager.addWindowToken(newConn.mToken,
-                            WindowManager.LayoutParams.TYPE_WALLPAPER);
-                    mLastWallpaper = wallpaper;
-                }
-            } catch (RemoteException e) {
-            }
-        } catch (RemoteException e) {
-            String msg = "Remote exception for " + componentName + "\n" + e;
-            if (fromUser) {
-                throw new IllegalArgumentException(msg);
-            }
-            Slog.w(TAG, msg);
-            return false;
-        }
-        return true;
-    }
-
-    void detachWallpaperLocked(WallpaperData wallpaper) {
-        if (wallpaper.connection != null) {
-            if (wallpaper.connection.mReply != null) {
-                try {
-                    wallpaper.connection.mReply.sendResult(null);
-                } catch (RemoteException e) {
-                }
-                wallpaper.connection.mReply = null;
-            }
-            if (wallpaper.connection.mEngine != null) {
-                try {
-                    wallpaper.connection.mEngine.destroy();
-                } catch (RemoteException e) {
-                }
-            }
-            mContext.unbindService(wallpaper.connection);
-            try {
-                if (DEBUG)
-                    Slog.v(TAG, "Removing window token: " + wallpaper.connection.mToken);
-                mIWindowManager.removeWindowToken(wallpaper.connection.mToken);
-            } catch (RemoteException e) {
-            }
-            wallpaper.connection.mService = null;
-            wallpaper.connection.mEngine = null;
-            wallpaper.connection = null;
-        }
-    }
-
-    void clearWallpaperComponentLocked(WallpaperData wallpaper) {
-        wallpaper.wallpaperComponent = null;
-        detachWallpaperLocked(wallpaper);
-    }
-
-    void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
-        try {
-            conn.mService.attach(conn, conn.mToken,
-                    WindowManager.LayoutParams.TYPE_WALLPAPER, false,
-                    wallpaper.width, wallpaper.height);
-        } catch (RemoteException e) {
-            Slog.w(TAG, "Failed attaching wallpaper; clearing", e);
-            if (!wallpaper.wallpaperUpdating) {
-                bindWallpaperComponentLocked(null, false, false, wallpaper, null);
-            }
-        }
-    }
-
-    private void notifyCallbacksLocked(WallpaperData wallpaper) {
-        final int n = wallpaper.callbacks.beginBroadcast();
-        for (int i = 0; i < n; i++) {
-            try {
-                wallpaper.callbacks.getBroadcastItem(i).onWallpaperChanged();
-            } catch (RemoteException e) {
-
-                // The RemoteCallbackList will take care of removing
-                // the dead object for us.
-            }
-        }
-        wallpaper.callbacks.finishBroadcast();
-        final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
-        mContext.sendBroadcastAsUser(intent, new UserHandle(mCurrentUserId));
-    }
-
-    private void checkPermission(String permission) {
-        if (PackageManager.PERMISSION_GRANTED!= mContext.checkCallingOrSelfPermission(permission)) {
-            throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
-                    + ", must have permission " + permission);
-        }
-    }
-
-    private static JournaledFile makeJournaledFile(int userId) {
-        final String base = new File(getWallpaperDir(userId), WALLPAPER_INFO).getAbsolutePath();
-        return new JournaledFile(new File(base), new File(base + ".tmp"));
-    }
-
-    private void saveSettingsLocked(WallpaperData wallpaper) {
-        JournaledFile journal = makeJournaledFile(wallpaper.userId);
-        FileOutputStream stream = null;
-        try {
-            stream = new FileOutputStream(journal.chooseForWrite(), false);
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(stream, "utf-8");
-            out.startDocument(null, true);
-
-            out.startTag(null, "wp");
-            out.attribute(null, "width", Integer.toString(wallpaper.width));
-            out.attribute(null, "height", Integer.toString(wallpaper.height));
-            out.attribute(null, "name", wallpaper.name);
-            if (wallpaper.wallpaperComponent != null
-                    && !wallpaper.wallpaperComponent.equals(IMAGE_WALLPAPER)) {
-                out.attribute(null, "component",
-                        wallpaper.wallpaperComponent.flattenToShortString());
-            }
-            out.endTag(null, "wp");
-
-            out.endDocument();
-            stream.close();
-            journal.commit();
-        } catch (IOException e) {
-            try {
-                if (stream != null) {
-                    stream.close();
-                }
-            } catch (IOException ex) {
-                // Ignore
-            }
-            journal.rollback();
-        }
-    }
-
-    private void migrateFromOld() {
-        File oldWallpaper = new File(WallpaperBackupHelper.WALLPAPER_IMAGE_KEY);
-        File oldInfo = new File(WallpaperBackupHelper.WALLPAPER_INFO_KEY);
-        if (oldWallpaper.exists()) {
-            File newWallpaper = new File(getWallpaperDir(0), WALLPAPER);
-            oldWallpaper.renameTo(newWallpaper);
-        }
-        if (oldInfo.exists()) {
-            File newInfo = new File(getWallpaperDir(0), WALLPAPER_INFO);
-            oldInfo.renameTo(newInfo);
-        }
-    }
-
-    private void loadSettingsLocked(int userId) {
-        if (DEBUG) Slog.v(TAG, "loadSettingsLocked");
-        
-        JournaledFile journal = makeJournaledFile(userId);
-        FileInputStream stream = null;
-        File file = journal.chooseForRead();
-        if (!file.exists()) {
-            // This should only happen one time, when upgrading from a legacy system
-            migrateFromOld();
-        }
-        WallpaperData wallpaper = mWallpaperMap.get(userId);
-        if (wallpaper == null) {
-            wallpaper = new WallpaperData(userId);
-            mWallpaperMap.put(userId, wallpaper);
-        }
-        boolean success = false;
-        try {
-            stream = new FileInputStream(file);
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(stream, null);
-
-            int type;
-            do {
-                type = parser.next();
-                if (type == XmlPullParser.START_TAG) {
-                    String tag = parser.getName();
-                    if ("wp".equals(tag)) {
-                        wallpaper.width = Integer.parseInt(parser.getAttributeValue(null, "width"));
-                        wallpaper.height = Integer.parseInt(parser
-                                .getAttributeValue(null, "height"));
-                        wallpaper.name = parser.getAttributeValue(null, "name");
-                        String comp = parser.getAttributeValue(null, "component");
-                        wallpaper.nextWallpaperComponent = comp != null
-                                ? ComponentName.unflattenFromString(comp)
-                                : null;
-                        if (wallpaper.nextWallpaperComponent == null
-                                || "android".equals(wallpaper.nextWallpaperComponent
-                                        .getPackageName())) {
-                            wallpaper.nextWallpaperComponent = IMAGE_WALLPAPER;
-                        }
-                          
-                        if (DEBUG) {
-                            Slog.v(TAG, "mWidth:" + wallpaper.width);
-                            Slog.v(TAG, "mHeight:" + wallpaper.height);
-                            Slog.v(TAG, "mName:" + wallpaper.name);
-                            Slog.v(TAG, "mNextWallpaperComponent:"
-                                    + wallpaper.nextWallpaperComponent);
-                        }
-                    }
-                }
-            } while (type != XmlPullParser.END_DOCUMENT);
-            success = true;
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "no current wallpaper -- first boot?");
-        } catch (NullPointerException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (NumberFormatException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (IOException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        } catch (IndexOutOfBoundsException e) {
-            Slog.w(TAG, "failed parsing " + file + " " + e);
-        }
-        try {
-            if (stream != null) {
-                stream.close();
-            }
-        } catch (IOException e) {
-            // Ignore
-        }
-
-        if (!success) {
-            wallpaper.width = -1;
-            wallpaper.height = -1;
-            wallpaper.name = "";
-        }
-
-        // We always want to have some reasonable width hint.
-        int baseSize = getMaximumSizeDimension();
-        if (wallpaper.width < baseSize) {
-            wallpaper.width = baseSize;
-        }
-        if (wallpaper.height < baseSize) {
-            wallpaper.height = baseSize;
-        }
-    }
-
-    private int getMaximumSizeDimension() {
-        WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
-        Display d = wm.getDefaultDisplay();
-        return d.getMaximumSizeDimension();
-    }
-
-    // Called by SystemBackupAgent after files are restored to disk.
-    void settingsRestored() {
-        // TODO: If necessary, make it work for secondary users as well. This currently assumes
-        // restores only to the primary user
-        if (DEBUG) Slog.v(TAG, "settingsRestored");
-        WallpaperData wallpaper = null;
-        boolean success = false;
-        synchronized (mLock) {
-            loadSettingsLocked(0);
-            wallpaper = mWallpaperMap.get(0);
-            if (wallpaper.nextWallpaperComponent != null
-                    && !wallpaper.nextWallpaperComponent.equals(IMAGE_WALLPAPER)) {
-                if (!bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
-                        wallpaper, null)) {
-                    // No such live wallpaper or other failure; fall back to the default
-                    // live wallpaper (since the profile being restored indicated that the
-                    // user had selected a live rather than static one).
-                    bindWallpaperComponentLocked(null, false, false, wallpaper, null);
-                }
-                success = true;
-            } else {
-                // If there's a wallpaper name, we use that.  If that can't be loaded, then we
-                // use the default.
-                if ("".equals(wallpaper.name)) {
-                    if (DEBUG) Slog.v(TAG, "settingsRestored: name is empty");
-                    success = true;
-                } else {
-                    if (DEBUG) Slog.v(TAG, "settingsRestored: attempting to restore named resource");
-                    success = restoreNamedResourceLocked(wallpaper);
-                }
-                if (DEBUG) Slog.v(TAG, "settingsRestored: success=" + success);
-                if (success) {
-                    bindWallpaperComponentLocked(wallpaper.nextWallpaperComponent, false, false,
-                            wallpaper, null);
-                }
-            }
-        }
-
-        if (!success) {
-            Slog.e(TAG, "Failed to restore wallpaper: '" + wallpaper.name + "'");
-            wallpaper.name = "";
-            getWallpaperDir(0).delete();
-        }
-
-        synchronized (mLock) {
-            saveSettingsLocked(wallpaper);
-        }
-    }
-
-    boolean restoreNamedResourceLocked(WallpaperData wallpaper) {
-        if (wallpaper.name.length() > 4 && "res:".equals(wallpaper.name.substring(0, 4))) {
-            String resName = wallpaper.name.substring(4);
-
-            String pkg = null;
-            int colon = resName.indexOf(':');
-            if (colon > 0) {
-                pkg = resName.substring(0, colon);
-            }
-
-            String ident = null;
-            int slash = resName.lastIndexOf('/');
-            if (slash > 0) {
-                ident = resName.substring(slash+1);
-            }
-
-            String type = null;
-            if (colon > 0 && slash > 0 && (slash-colon) > 1) {
-                type = resName.substring(colon+1, slash);
-            }
-
-            if (pkg != null && ident != null && type != null) {
-                int resId = -1;
-                InputStream res = null;
-                FileOutputStream fos = null;
-                try {
-                    Context c = mContext.createPackageContext(pkg, Context.CONTEXT_RESTRICTED);
-                    Resources r = c.getResources();
-                    resId = r.getIdentifier(resName, null, null);
-                    if (resId == 0) {
-                        Slog.e(TAG, "couldn't resolve identifier pkg=" + pkg + " type=" + type
-                                + " ident=" + ident);
-                        return false;
-                    }
-
-                    res = r.openRawResource(resId);
-                    if (wallpaper.wallpaperFile.exists()) {
-                        wallpaper.wallpaperFile.delete();
-                    }
-                    fos = new FileOutputStream(wallpaper.wallpaperFile);
-
-                    byte[] buffer = new byte[32768];
-                    int amt;
-                    while ((amt=res.read(buffer)) > 0) {
-                        fos.write(buffer, 0, amt);
-                    }
-                    // mWallpaperObserver will notice the close and send the change broadcast
-
-                    Slog.v(TAG, "Restored wallpaper: " + resName);
-                    return true;
-                } catch (NameNotFoundException e) {
-                    Slog.e(TAG, "Package name " + pkg + " not found");
-                } catch (Resources.NotFoundException e) {
-                    Slog.e(TAG, "Resource not found: " + resId);
-                } catch (IOException e) {
-                    Slog.e(TAG, "IOException while restoring wallpaper ", e);
-                } finally {
-                    if (res != null) {
-                        try {
-                            res.close();
-                        } catch (IOException ex) {}
-                    }
-                    if (fos != null) {
-                        FileUtils.sync(fos);
-                        try {
-                            fos.close();
-                        } catch (IOException ex) {}
-                    }
-                }
-            }
-        }
-        return false;
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            
-            pw.println("Permission Denial: can't dump wallpaper service from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mLock) {
-            pw.println("Current Wallpaper Service state:");
-            for (int i = 0; i < mWallpaperMap.size(); i++) {
-                WallpaperData wallpaper = mWallpaperMap.valueAt(i);
-                pw.println(" User " + wallpaper.userId + ":");
-                pw.print("  mWidth=");
-                pw.print(wallpaper.width);
-                pw.print(" mHeight=");
-                pw.println(wallpaper.height);
-                pw.print("  mName=");
-                pw.println(wallpaper.name);
-                pw.print("  mWallpaperComponent=");
-                pw.println(wallpaper.wallpaperComponent);
-                if (wallpaper.connection != null) {
-                    WallpaperConnection conn = wallpaper.connection;
-                    pw.print("  Wallpaper connection ");
-                    pw.print(conn);
-                    pw.println(":");
-                    if (conn.mInfo != null) {
-                        pw.print("    mInfo.component=");
-                        pw.println(conn.mInfo.getComponent());
-                    }
-                    pw.print("    mToken=");
-                    pw.println(conn.mToken);
-                    pw.print("    mService=");
-                    pw.println(conn.mService);
-                    pw.print("    mEngine=");
-                    pw.println(conn.mEngine);
-                    pw.print("    mLastDiedTime=");
-                    pw.println(wallpaper.lastDiedTime - SystemClock.uptimeMillis());
-                }
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/Watchdog.java b/services/java/com/android/server/Watchdog.java
deleted file mode 100644
index e17f42d..0000000
--- a/services/java/com/android/server/Watchdog.java
+++ /dev/null
@@ -1,491 +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.server;
-
-import android.app.IActivityController;
-import android.os.Binder;
-import android.os.RemoteException;
-import com.android.server.am.ActivityManagerService;
-import com.android.server.power.PowerManagerService;
-
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.BatteryManager;
-import android.os.Debug;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Process;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Slog;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-
-/** This class calls its monitor every minute. Killing this process if they don't return **/
-public class Watchdog extends Thread {
-    static final String TAG = "Watchdog";
-    static final boolean localLOGV = false || false;
-
-    // Set this to true to use debug default values.
-    static final boolean DB = false;
-
-    // Set this to true to have the watchdog record kernel thread stacks when it fires
-    static final boolean RECORD_KERNEL_THREADS = true;
-
-    static final long DEFAULT_TIMEOUT = DB ? 10*1000 : 60*1000;
-    static final long CHECK_INTERVAL = DEFAULT_TIMEOUT / 2;
-
-    // These are temporally ordered: larger values as lateness increases
-    static final int COMPLETED = 0;
-    static final int WAITING = 1;
-    static final int WAITED_HALF = 2;
-    static final int OVERDUE = 3;
-
-    // Which native processes to dump into dropbox's stack traces
-    public static final String[] NATIVE_STACKS_OF_INTEREST = new String[] {
-        "/system/bin/mediaserver",
-        "/system/bin/sdcard",
-        "/system/bin/surfaceflinger"
-    };
-
-    static Watchdog sWatchdog;
-
-    /* This handler will be used to post message back onto the main thread */
-    final ArrayList<HandlerChecker> mHandlerCheckers = new ArrayList<HandlerChecker>();
-    final HandlerChecker mMonitorChecker;
-    ContentResolver mResolver;
-    BatteryService mBattery;
-    PowerManagerService mPower;
-    AlarmManagerService mAlarm;
-    ActivityManagerService mActivity;
-
-    int mPhonePid;
-    IActivityController mController;
-    boolean mAllowRestart = true;
-
-    /**
-     * Used for checking status of handle threads and scheduling monitor callbacks.
-     */
-    public final class HandlerChecker implements Runnable {
-        private final Handler mHandler;
-        private final String mName;
-        private final long mWaitMax;
-        private final ArrayList<Monitor> mMonitors = new ArrayList<Monitor>();
-        private boolean mCompleted;
-        private Monitor mCurrentMonitor;
-        private long mStartTime;
-
-        HandlerChecker(Handler handler, String name, long waitMaxMillis) {
-            mHandler = handler;
-            mName = name;
-            mWaitMax = waitMaxMillis;
-            mCompleted = true;
-        }
-
-        public void addMonitor(Monitor monitor) {
-            mMonitors.add(monitor);
-        }
-
-        public void scheduleCheckLocked() {
-            if (mMonitors.size() == 0 && mHandler.getLooper().isIdling()) {
-                // If the target looper is or just recently was idling, then
-                // there is no reason to enqueue our checker on it since that
-                // is as good as it not being deadlocked.  This avoid having
-                // to do a context switch to check the thread.  Note that we
-                // only do this if mCheckReboot is false and we have no
-                // monitors, since those would need to be executed at this point.
-                mCompleted = true;
-                return;
-            }
-
-            if (!mCompleted) {
-                // we already have a check in flight, so no need
-                return;
-            }
-
-            mCompleted = false;
-            mCurrentMonitor = null;
-            mStartTime = SystemClock.uptimeMillis();
-            mHandler.postAtFrontOfQueue(this);
-        }
-
-        public boolean isOverdueLocked() {
-            return (!mCompleted) && (SystemClock.uptimeMillis() > mStartTime + mWaitMax);
-        }
-
-        public int getCompletionStateLocked() {
-            if (mCompleted) {
-                return COMPLETED;
-            } else {
-                long latency = SystemClock.uptimeMillis() - mStartTime;
-                if (latency < mWaitMax/2) {
-                    return WAITING;
-                } else if (latency < mWaitMax) {
-                    return WAITED_HALF;
-                }
-            }
-            return OVERDUE;
-        }
-
-        public Thread getThread() {
-            return mHandler.getLooper().getThread();
-        }
-
-        public String getName() {
-            return mName;
-        }
-
-        public String describeBlockedStateLocked() {
-            if (mCurrentMonitor == null) {
-                return "Blocked in handler on " + mName + " (" + getThread().getName() + ")";
-            } else {
-                return "Blocked in monitor " + mCurrentMonitor.getClass().getName()
-                        + " on " + mName + " (" + getThread().getName() + ")";
-            }
-        }
-
-        @Override
-        public void run() {
-            final int size = mMonitors.size();
-            for (int i = 0 ; i < size ; i++) {
-                synchronized (Watchdog.this) {
-                    mCurrentMonitor = mMonitors.get(i);
-                }
-                mCurrentMonitor.monitor();
-            }
-
-            synchronized (Watchdog.this) {
-                mCompleted = true;
-                mCurrentMonitor = null;
-            }
-        }
-    }
-
-    final class RebootRequestReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context c, Intent intent) {
-            if (intent.getIntExtra("nowait", 0) != 0) {
-                rebootSystem("Received ACTION_REBOOT broadcast");
-                return;
-            }
-            Slog.w(TAG, "Unsupported ACTION_REBOOT broadcast: " + intent);
-        }
-    }
-
-    public interface Monitor {
-        void monitor();
-    }
-
-    public static Watchdog getInstance() {
-        if (sWatchdog == null) {
-            sWatchdog = new Watchdog();
-        }
-
-        return sWatchdog;
-    }
-
-    private Watchdog() {
-        super("watchdog");
-        // Initialize handler checkers for each common thread we want to check.  Note
-        // that we are not currently checking the background thread, since it can
-        // potentially hold longer running operations with no guarantees about the timeliness
-        // of operations there.
-
-        // The shared foreground thread is the main checker.  It is where we
-        // will also dispatch monitor checks and do other work.
-        mMonitorChecker = new HandlerChecker(FgThread.getHandler(),
-                "foreground thread", DEFAULT_TIMEOUT);
-        mHandlerCheckers.add(mMonitorChecker);
-        // Add checker for main thread.  We only do a quick check since there
-        // can be UI running on the thread.
-        mHandlerCheckers.add(new HandlerChecker(new Handler(Looper.getMainLooper()),
-                "main thread", DEFAULT_TIMEOUT));
-        // Add checker for shared UI thread.
-        mHandlerCheckers.add(new HandlerChecker(UiThread.getHandler(),
-                "ui thread", DEFAULT_TIMEOUT));
-        // And also check IO thread.
-        mHandlerCheckers.add(new HandlerChecker(IoThread.getHandler(),
-                "i/o thread", DEFAULT_TIMEOUT));
-    }
-
-    public void init(Context context, BatteryService battery,
-            PowerManagerService power, AlarmManagerService alarm,
-            ActivityManagerService activity) {
-        mResolver = context.getContentResolver();
-        mBattery = battery;
-        mPower = power;
-        mAlarm = alarm;
-        mActivity = activity;
-
-        context.registerReceiver(new RebootRequestReceiver(),
-                new IntentFilter(Intent.ACTION_REBOOT),
-                android.Manifest.permission.REBOOT, null);
-    }
-
-    public void processStarted(String name, int pid) {
-        synchronized (this) {
-            if ("com.android.phone".equals(name)) {
-                mPhonePid = pid;
-            }
-        }
-    }
-
-    public void setActivityController(IActivityController controller) {
-        synchronized (this) {
-            mController = controller;
-        }
-    }
-
-    public void setAllowRestart(boolean allowRestart) {
-        synchronized (this) {
-            mAllowRestart = allowRestart;
-        }
-    }
-
-    public void addMonitor(Monitor monitor) {
-        synchronized (this) {
-            if (isAlive()) {
-                throw new RuntimeException("Monitors can't be added once the Watchdog is running");
-            }
-            mMonitorChecker.addMonitor(monitor);
-        }
-    }
-
-    public void addThread(Handler thread, String name) {
-        addThread(thread, name, DEFAULT_TIMEOUT);
-    }
-
-    public void addThread(Handler thread, String name, long timeoutMillis) {
-        synchronized (this) {
-            if (isAlive()) {
-                throw new RuntimeException("Threads can't be added once the Watchdog is running");
-            }
-            mHandlerCheckers.add(new HandlerChecker(thread, name, timeoutMillis));
-        }
-    }
-
-    /**
-     * Perform a full reboot of the system.
-     */
-    void rebootSystem(String reason) {
-        Slog.i(TAG, "Rebooting system because: " + reason);
-        PowerManagerService pms = (PowerManagerService) ServiceManager.getService("power");
-        pms.reboot(false, reason, false);
-    }
-
-    private int evaluateCheckerCompletionLocked() {
-        int state = COMPLETED;
-        for (int i=0; i<mHandlerCheckers.size(); i++) {
-            HandlerChecker hc = mHandlerCheckers.get(i);
-            state = Math.max(state, hc.getCompletionStateLocked());
-        }
-        return state;
-    }
-
-    private ArrayList<HandlerChecker> getBlockedCheckersLocked() {
-        ArrayList<HandlerChecker> checkers = new ArrayList<HandlerChecker>();
-        for (int i=0; i<mHandlerCheckers.size(); i++) {
-            HandlerChecker hc = mHandlerCheckers.get(i);
-            if (hc.isOverdueLocked()) {
-                checkers.add(hc);
-            }
-        }
-        return checkers;
-    }
-
-    private String describeCheckersLocked(ArrayList<HandlerChecker> checkers) {
-        StringBuilder builder = new StringBuilder(128);
-        for (int i=0; i<checkers.size(); i++) {
-            if (builder.length() > 0) {
-                builder.append(", ");
-            }
-            builder.append(checkers.get(i).describeBlockedStateLocked());
-        }
-        return builder.toString();
-    }
-
-    @Override
-    public void run() {
-        boolean waitedHalf = false;
-        while (true) {
-            final ArrayList<HandlerChecker> blockedCheckers;
-            final String subject;
-            final boolean allowRestart;
-            synchronized (this) {
-                long timeout = CHECK_INTERVAL;
-                // Make sure we (re)spin the checkers that have become idle within
-                // this wait-and-check interval
-                for (int i=0; i<mHandlerCheckers.size(); i++) {
-                    HandlerChecker hc = mHandlerCheckers.get(i);
-                    hc.scheduleCheckLocked();
-                }
-
-                // NOTE: We use uptimeMillis() here because we do not want to increment the time we
-                // wait while asleep. If the device is asleep then the thing that we are waiting
-                // to timeout on is asleep as well and won't have a chance to run, causing a false
-                // positive on when to kill things.
-                long start = SystemClock.uptimeMillis();
-                while (timeout > 0) {
-                    try {
-                        wait(timeout);
-                    } catch (InterruptedException e) {
-                        Log.wtf(TAG, e);
-                    }
-                    timeout = CHECK_INTERVAL - (SystemClock.uptimeMillis() - start);
-                }
-
-                final int waitState = evaluateCheckerCompletionLocked();
-                if (waitState == COMPLETED) {
-                    // The monitors have returned; reset
-                    waitedHalf = false;
-                    continue;
-                } else if (waitState == WAITING) {
-                    // still waiting but within their configured intervals; back off and recheck
-                    continue;
-                } else if (waitState == WAITED_HALF) {
-                    if (!waitedHalf) {
-                        // We've waited half the deadlock-detection interval.  Pull a stack
-                        // trace and wait another half.
-                        ArrayList<Integer> pids = new ArrayList<Integer>();
-                        pids.add(Process.myPid());
-                        ActivityManagerService.dumpStackTraces(true, pids, null, null,
-                                NATIVE_STACKS_OF_INTEREST);
-                        waitedHalf = true;
-                    }
-                    continue;
-                }
-
-                // something is overdue!
-                blockedCheckers = getBlockedCheckersLocked();
-                subject = describeCheckersLocked(blockedCheckers);
-                allowRestart = mAllowRestart;
-            }
-
-            // If we got here, that means that the system is most likely hung.
-            // First collect stack traces from all threads of the system process.
-            // Then kill this process so that the system will restart.
-            EventLog.writeEvent(EventLogTags.WATCHDOG, subject);
-
-            ArrayList<Integer> pids = new ArrayList<Integer>();
-            pids.add(Process.myPid());
-            if (mPhonePid > 0) pids.add(mPhonePid);
-            // Pass !waitedHalf so that just in case we somehow wind up here without having
-            // dumped the halfway stacks, we properly re-initialize the trace file.
-            final File stack = ActivityManagerService.dumpStackTraces(
-                    !waitedHalf, pids, null, null, NATIVE_STACKS_OF_INTEREST);
-
-            // Give some extra time to make sure the stack traces get written.
-            // The system's been hanging for a minute, another second or two won't hurt much.
-            SystemClock.sleep(2000);
-
-            // Pull our own kernel thread stacks as well if we're configured for that
-            if (RECORD_KERNEL_THREADS) {
-                dumpKernelStackTraces();
-            }
-
-            // Trigger the kernel to dump all blocked threads to the kernel log
-            try {
-                FileWriter sysrq_trigger = new FileWriter("/proc/sysrq-trigger");
-                sysrq_trigger.write("w");
-                sysrq_trigger.close();
-            } catch (IOException e) {
-                Slog.e(TAG, "Failed to write to /proc/sysrq-trigger");
-                Slog.e(TAG, e.getMessage());
-            }
-
-            // Try to add the error to the dropbox, but assuming that the ActivityManager
-            // itself may be deadlocked.  (which has happened, causing this statement to
-            // deadlock and the watchdog as a whole to be ineffective)
-            Thread dropboxThread = new Thread("watchdogWriteToDropbox") {
-                    public void run() {
-                        mActivity.addErrorToDropBox(
-                                "watchdog", null, "system_server", null, null,
-                                subject, null, stack, null);
-                    }
-                };
-            dropboxThread.start();
-            try {
-                dropboxThread.join(2000);  // wait up to 2 seconds for it to return.
-            } catch (InterruptedException ignored) {}
-
-            IActivityController controller;
-            synchronized (this) {
-                controller = mController;
-            }
-            if (controller != null) {
-                Slog.i(TAG, "Reporting stuck state to activity controller");
-                try {
-                    Binder.setDumpDisabled("Service dumps disabled due to hung system process.");
-                    // 1 = keep waiting, -1 = kill system
-                    int res = controller.systemNotResponding(subject);
-                    if (res >= 0) {
-                        Slog.i(TAG, "Activity controller requested to coninue to wait");
-                        waitedHalf = false;
-                        continue;
-                    }
-                } catch (RemoteException e) {
-                }
-            }
-
-            // Only kill the process if the debugger is not attached.
-            if (Debug.isDebuggerConnected()) {
-                Slog.w(TAG, "Debugger connected: Watchdog is *not* killing the system process");
-            } else if (!allowRestart) {
-                Slog.w(TAG, "Restart not allowed: Watchdog is *not* killing the system process");
-            } else {
-                Slog.w(TAG, "*** WATCHDOG KILLING SYSTEM PROCESS: " + subject);
-                for (int i=0; i<blockedCheckers.size(); i++) {
-                    Slog.w(TAG, blockedCheckers.get(i).getName() + " stack trace:");
-                    StackTraceElement[] stackTrace
-                            = blockedCheckers.get(i).getThread().getStackTrace();
-                    for (StackTraceElement element: stackTrace) {
-                        Slog.w(TAG, "    at " + element);
-                    }
-                }
-                Slog.w(TAG, "*** GOODBYE!");
-                Process.killProcess(Process.myPid());
-                System.exit(10);
-            }
-
-            waitedHalf = false;
-        }
-    }
-
-    private File dumpKernelStackTraces() {
-        String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
-        if (tracesPath == null || tracesPath.length() == 0) {
-            return null;
-        }
-
-        native_dumpKernelStacks(tracesPath);
-        return new File(tracesPath);
-    }
-
-    private native void native_dumpKernelStacks(String tracesPath);
-}
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
deleted file mode 100644
index e2050fc..0000000
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ /dev/null
@@ -1,16625 +0,0 @@
-/*
- * Copyright (C) 2006-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.server.am;
-
-import static android.content.pm.PackageManager.PERMISSION_GRANTED;
-import static com.android.internal.util.XmlUtils.readIntAttribute;
-import static com.android.internal.util.XmlUtils.readLongAttribute;
-import static com.android.internal.util.XmlUtils.writeIntAttribute;
-import static com.android.internal.util.XmlUtils.writeLongAttribute;
-import static com.android.server.Watchdog.NATIVE_STACKS_OF_INTEREST;
-import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
-import static org.xmlpull.v1.XmlPullParser.START_TAG;
-
-import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
-
-import android.app.AppOpsManager;
-import android.appwidget.AppWidgetManager;
-import android.util.ArrayMap;
-import com.android.internal.R;
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.app.IAppOpsService;
-import com.android.internal.app.ProcessStats;
-import com.android.internal.os.BackgroundThread;
-import com.android.internal.os.BatteryStatsImpl;
-import com.android.internal.os.ProcessCpuTracker;
-import com.android.internal.os.TransferPipe;
-import com.android.internal.util.FastPrintWriter;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.MemInfoReader;
-import com.android.internal.util.Preconditions;
-import com.android.server.AppOpsService;
-import com.android.server.AttributeCache;
-import com.android.server.IntentResolver;
-import com.android.internal.app.ProcessMap;
-import com.android.server.SystemServer;
-import com.android.server.Watchdog;
-import com.android.server.am.ActivityStack.ActivityState;
-import com.android.server.firewall.IntentFirewall;
-import com.android.server.pm.UserManagerService;
-import com.android.server.wm.AppTransition;
-import com.android.server.wm.StackBox;
-import com.android.server.wm.WindowManagerService;
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
-
-import dalvik.system.Zygote;
-
-import libcore.io.IoUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningTaskInfo;
-import android.app.ActivityManager.StackBoxInfo;
-import android.app.ActivityManager.StackInfo;
-import android.app.ActivityManagerNative;
-import android.app.ActivityOptions;
-import android.app.ActivityThread;
-import android.app.AlertDialog;
-import android.app.AppGlobals;
-import android.app.ApplicationErrorReport;
-import android.app.Dialog;
-import android.app.IActivityController;
-import android.app.IApplicationThread;
-import android.app.IInstrumentationWatcher;
-import android.app.INotificationManager;
-import android.app.IProcessObserver;
-import android.app.IServiceConnection;
-import android.app.IStopUserCallback;
-import android.app.IThumbnailReceiver;
-import android.app.IUiAutomationConnection;
-import android.app.IUserSwitchObserver;
-import android.app.Instrumentation;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.backup.IBackupManager;
-import android.content.ActivityNotFoundException;
-import android.content.BroadcastReceiver;
-import android.content.ClipData;
-import android.content.ComponentCallbacks2;
-import android.content.ComponentName;
-import android.content.ContentProvider;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.IContentProvider;
-import android.content.IIntentReceiver;
-import android.content.IIntentSender;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.IntentSender;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.ConfigurationInfo;
-import android.content.pm.IPackageDataObserver;
-import android.content.pm.IPackageManager;
-import android.content.pm.InstrumentationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ParceledListSlice;
-import android.content.pm.UserInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.PathPermission;
-import android.content.pm.ProviderInfo;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.res.CompatibilityInfo;
-import android.content.res.Configuration;
-import android.graphics.Bitmap;
-import android.net.Proxy;
-import android.net.ProxyProperties;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Debug;
-import android.os.DropBoxManager;
-import android.os.Environment;
-import android.os.FileObserver;
-import android.os.FileUtils;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.IPermissionController;
-import android.os.IRemoteCallback;
-import android.os.IUserManager;
-import android.os.Looper;
-import android.os.Message;
-import android.os.Parcel;
-import android.os.ParcelFileDescriptor;
-import android.os.Process;
-import android.os.RemoteCallbackList;
-import android.os.RemoteException;
-import android.os.SELinux;
-import android.os.ServiceManager;
-import android.os.StrictMode;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UpdateLock;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.text.format.DateUtils;
-import android.text.format.Time;
-import android.util.AtomicFile;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Pair;
-import android.util.PrintWriterPrinter;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.TimeUtils;
-import android.util.Xml;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.WindowManager;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicLong;
-
-public final class ActivityManagerService extends ActivityManagerNative
-        implements Watchdog.Monitor, BatteryStatsImpl.BatteryCallback {
-    private static final String USER_DATA_DIR = "/data/user/";
-    static final String TAG = "ActivityManager";
-    static final String TAG_MU = "ActivityManagerServiceMU";
-    static final boolean DEBUG = false;
-    static final boolean localLOGV = DEBUG;
-    static final boolean DEBUG_BACKUP = localLOGV || false;
-    static final boolean DEBUG_BROADCAST = localLOGV || false;
-    static final boolean DEBUG_BROADCAST_LIGHT = DEBUG_BROADCAST || false;
-    static final boolean DEBUG_BACKGROUND_BROADCAST = DEBUG_BROADCAST || false;
-    static final boolean DEBUG_CLEANUP = localLOGV || false;
-    static final boolean DEBUG_CONFIGURATION = localLOGV || false;
-    static final boolean DEBUG_FOCUS = false;
-    static final boolean DEBUG_IMMERSIVE = localLOGV || false;
-    static final boolean DEBUG_MU = localLOGV || false;
-    static final boolean DEBUG_OOM_ADJ = localLOGV || false;
-    static final boolean DEBUG_LRU = localLOGV || false;
-    static final boolean DEBUG_PAUSE = localLOGV || false;
-    static final boolean DEBUG_POWER = localLOGV || false;
-    static final boolean DEBUG_POWER_QUICK = DEBUG_POWER || false;
-    static final boolean DEBUG_PROCESS_OBSERVERS = localLOGV || false;
-    static final boolean DEBUG_PROCESSES = localLOGV || false;
-    static final boolean DEBUG_PROVIDER = localLOGV || false;
-    static final boolean DEBUG_RESULTS = localLOGV || false;
-    static final boolean DEBUG_SERVICE = localLOGV || false;
-    static final boolean DEBUG_SERVICE_EXECUTING = localLOGV || false;
-    static final boolean DEBUG_STACK = localLOGV || false;
-    static final boolean DEBUG_SWITCH = localLOGV || false;
-    static final boolean DEBUG_TASKS = localLOGV || false;
-    static final boolean DEBUG_THUMBNAILS = localLOGV || false;
-    static final boolean DEBUG_TRANSITION = localLOGV || false;
-    static final boolean DEBUG_URI_PERMISSION = localLOGV || false;
-    static final boolean DEBUG_USER_LEAVING = localLOGV || false;
-    static final boolean DEBUG_VISBILITY = localLOGV || false;
-    static final boolean DEBUG_PSS = localLOGV || false;
-    static final boolean DEBUG_LOCKSCREEN = localLOGV || false;
-    static final boolean VALIDATE_TOKENS = false;
-    static final boolean SHOW_ACTIVITY_START_TIME = true;
-
-    // Control over CPU and battery monitoring.
-    static final long BATTERY_STATS_TIME = 30*60*1000;      // write battery stats every 30 minutes.
-    static final boolean MONITOR_CPU_USAGE = true;
-    static final long MONITOR_CPU_MIN_TIME = 5*1000;        // don't sample cpu less than every 5 seconds.
-    static final long MONITOR_CPU_MAX_TIME = 0x0fffffff;    // wait possibly forever for next cpu sample.
-    static final boolean MONITOR_THREAD_CPU_USAGE = false;
-
-    // The flags that are set for all calls we make to the package manager.
-    static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES;
-
-    private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
-
-    static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
-
-    // Maximum number of recent tasks that we can remember.
-    static final int MAX_RECENT_TASKS = ActivityManager.isLowRamDeviceStatic() ? 10 : 20;
-
-    // Amount of time after a call to stopAppSwitches() during which we will
-    // prevent further untrusted switches from happening.
-    static final long APP_SWITCH_DELAY_TIME = 5*1000;
-
-    // How long we wait for a launched process to attach to the activity manager
-    // before we decide it's never going to come up for real.
-    static final int PROC_START_TIMEOUT = 10*1000;
-
-    // How long we wait for a launched process to attach to the activity manager
-    // before we decide it's never going to come up for real, when the process was
-    // started with a wrapper for instrumentation (such as Valgrind) because it
-    // could take much longer than usual.
-    static final int PROC_START_TIMEOUT_WITH_WRAPPER = 300*1000;
-
-    // How long to wait after going idle before forcing apps to GC.
-    static final int GC_TIMEOUT = 5*1000;
-
-    // The minimum amount of time between successive GC requests for a process.
-    static final int GC_MIN_INTERVAL = 60*1000;
-
-    // The minimum amount of time between successive PSS requests for a process.
-    static final int FULL_PSS_MIN_INTERVAL = 10*60*1000;
-
-    // The minimum amount of time between successive PSS requests for a process
-    // when the request is due to the memory state being lowered.
-    static final int FULL_PSS_LOWERED_INTERVAL = 2*60*1000;
-
-    // The rate at which we check for apps using excessive power -- 15 mins.
-    static final int POWER_CHECK_DELAY = (DEBUG_POWER_QUICK ? 2 : 15) * 60*1000;
-
-    // The minimum sample duration we will allow before deciding we have
-    // enough data on wake locks to start killing things.
-    static final int WAKE_LOCK_MIN_CHECK_DURATION = (DEBUG_POWER_QUICK ? 1 : 5) * 60*1000;
-
-    // The minimum sample duration we will allow before deciding we have
-    // enough data on CPU usage to start killing things.
-    static final int CPU_MIN_CHECK_DURATION = (DEBUG_POWER_QUICK ? 1 : 5) * 60*1000;
-
-    // How long we allow a receiver to run before giving up on it.
-    static final int BROADCAST_FG_TIMEOUT = 10*1000;
-    static final int BROADCAST_BG_TIMEOUT = 60*1000;
-
-    // How long we wait until we timeout on key dispatching.
-    static final int KEY_DISPATCHING_TIMEOUT = 5*1000;
-
-    // How long we wait until we timeout on key dispatching during instrumentation.
-    static final int INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT = 60*1000;
-
-    // Amount of time we wait for observers to handle a user switch before
-    // giving up on them and unfreezing the screen.
-    static final int USER_SWITCH_TIMEOUT = 2*1000;
-
-    // Maximum number of users we allow to be running at a time.
-    static final int MAX_RUNNING_USERS = 3;
-
-    // How long to wait in getAssistContextExtras for the activity and foreground services
-    // to respond with the result.
-    static final int PENDING_ASSIST_EXTRAS_TIMEOUT = 500;
-
-    // Maximum number of persisted Uri grants a package is allowed
-    static final int MAX_PERSISTED_URI_GRANTS = 128;
-
-    static final int MY_PID = Process.myPid();
-
-    static final String[] EMPTY_STRING_ARRAY = new String[0];
-
-    // How many bytes to write into the dropbox log before truncating
-    static final int DROPBOX_MAX_SIZE = 256 * 1024;
-
-    /** Run all ActivityStacks through this */
-    ActivityStackSupervisor mStackSupervisor;
-
-    public IntentFirewall mIntentFirewall;
-
-    private final boolean mHeadless;
-
-    // Whether we should show our dialogs (ANR, crash, etc) or just perform their
-    // default actuion automatically.  Important for devices without direct input
-    // devices.
-    private boolean mShowDialogs = true;
-
-    /**
-     * Description of a request to start a new activity, which has been held
-     * due to app switches being disabled.
-     */
-    static class PendingActivityLaunch {
-        final ActivityRecord r;
-        final ActivityRecord sourceRecord;
-        final int startFlags;
-        final ActivityStack stack;
-
-        PendingActivityLaunch(ActivityRecord _r, ActivityRecord _sourceRecord,
-                int _startFlags, ActivityStack _stack) {
-            r = _r;
-            sourceRecord = _sourceRecord;
-            startFlags = _startFlags;
-            stack = _stack;
-        }
-    }
-
-    final ArrayList<PendingActivityLaunch> mPendingActivityLaunches
-            = new ArrayList<PendingActivityLaunch>();
-
-    BroadcastQueue mFgBroadcastQueue;
-    BroadcastQueue mBgBroadcastQueue;
-    // Convenient for easy iteration over the queues. Foreground is first
-    // so that dispatch of foreground broadcasts gets precedence.
-    final BroadcastQueue[] mBroadcastQueues = new BroadcastQueue[2];
-
-    BroadcastQueue broadcastQueueForIntent(Intent intent) {
-        final boolean isFg = (intent.getFlags() & Intent.FLAG_RECEIVER_FOREGROUND) != 0;
-        if (DEBUG_BACKGROUND_BROADCAST) {
-            Slog.i(TAG, "Broadcast intent " + intent + " on "
-                    + (isFg ? "foreground" : "background")
-                    + " queue");
-        }
-        return (isFg) ? mFgBroadcastQueue : mBgBroadcastQueue;
-    }
-
-    BroadcastRecord broadcastRecordForReceiverLocked(IBinder receiver) {
-        for (BroadcastQueue queue : mBroadcastQueues) {
-            BroadcastRecord r = queue.getMatchingOrderedReceiver(receiver);
-            if (r != null) {
-                return r;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Activity we have told the window manager to have key focus.
-     */
-    ActivityRecord mFocusedActivity = null;
-
-    /**
-     * List of intents that were used to start the most recent tasks.
-     */
-    private final ArrayList<TaskRecord> mRecentTasks = new ArrayList<TaskRecord>();
-
-    public class PendingAssistExtras extends Binder implements Runnable {
-        public final ActivityRecord activity;
-        public boolean haveResult = false;
-        public Bundle result = null;
-        public PendingAssistExtras(ActivityRecord _activity) {
-            activity = _activity;
-        }
-        @Override
-        public void run() {
-            Slog.w(TAG, "getAssistContextExtras failed: timeout retrieving from " + activity);
-            synchronized (this) {
-                haveResult = true;
-                notifyAll();
-            }
-        }
-    }
-
-    final ArrayList<PendingAssistExtras> mPendingAssistExtras
-            = new ArrayList<PendingAssistExtras>();
-
-    /**
-     * Process management.
-     */
-    final ProcessList mProcessList = new ProcessList();
-
-    /**
-     * All of the applications we currently have running organized by name.
-     * The keys are strings of the application package name (as
-     * returned by the package manager), and the keys are ApplicationRecord
-     * objects.
-     */
-    final ProcessMap<ProcessRecord> mProcessNames = new ProcessMap<ProcessRecord>();
-
-    /**
-     * Tracking long-term execution of processes to look for abuse and other
-     * bad app behavior.
-     */
-    final ProcessStatsService mProcessStats;
-
-    /**
-     * The currently running isolated processes.
-     */
-    final SparseArray<ProcessRecord> mIsolatedProcesses = new SparseArray<ProcessRecord>();
-
-    /**
-     * Counter for assigning isolated process uids, to avoid frequently reusing the
-     * same ones.
-     */
-    int mNextIsolatedProcessUid = 0;
-
-    /**
-     * The currently running heavy-weight process, if any.
-     */
-    ProcessRecord mHeavyWeightProcess = null;
-
-    /**
-     * The last time that various processes have crashed.
-     */
-    final ProcessMap<Long> mProcessCrashTimes = new ProcessMap<Long>();
-
-    /**
-     * Information about a process that is currently marked as bad.
-     */
-    static final class BadProcessInfo {
-        BadProcessInfo(long time, String shortMsg, String longMsg, String stack) {
-            this.time = time;
-            this.shortMsg = shortMsg;
-            this.longMsg = longMsg;
-            this.stack = stack;
-        }
-
-        final long time;
-        final String shortMsg;
-        final String longMsg;
-        final String stack;
-    }
-
-    /**
-     * Set of applications that we consider to be bad, and will reject
-     * incoming broadcasts from (which the user has no control over).
-     * Processes are added to this set when they have crashed twice within
-     * a minimum amount of time; they are removed from it when they are
-     * later restarted (hopefully due to some user action).  The value is the
-     * time it was added to the list.
-     */
-    final ProcessMap<BadProcessInfo> mBadProcesses = new ProcessMap<BadProcessInfo>();
-
-    /**
-     * All of the processes we currently have running organized by pid.
-     * The keys are the pid running the application.
-     *
-     * <p>NOTE: This object is protected by its own lock, NOT the global
-     * activity manager lock!
-     */
-    final SparseArray<ProcessRecord> mPidsSelfLocked = new SparseArray<ProcessRecord>();
-
-    /**
-     * All of the processes that have been forced to be foreground.  The key
-     * is the pid of the caller who requested it (we hold a death
-     * link on it).
-     */
-    abstract class ForegroundToken implements IBinder.DeathRecipient {
-        int pid;
-        IBinder token;
-    }
-    final SparseArray<ForegroundToken> mForegroundProcesses = new SparseArray<ForegroundToken>();
-
-    /**
-     * List of records for processes that someone had tried to start before the
-     * system was ready.  We don't start them at that point, but ensure they
-     * are started by the time booting is complete.
-     */
-    final ArrayList<ProcessRecord> mProcessesOnHold = new ArrayList<ProcessRecord>();
-
-    /**
-     * List of persistent applications that are in the process
-     * of being started.
-     */
-    final ArrayList<ProcessRecord> mPersistentStartingProcesses = new ArrayList<ProcessRecord>();
-
-    /**
-     * Processes that are being forcibly torn down.
-     */
-    final ArrayList<ProcessRecord> mRemovedProcesses = new ArrayList<ProcessRecord>();
-
-    /**
-     * List of running applications, sorted by recent usage.
-     * The first entry in the list is the least recently used.
-     */
-    final ArrayList<ProcessRecord> mLruProcesses = new ArrayList<ProcessRecord>();
-
-    /**
-     * Where in mLruProcesses that the processes hosting activities start.
-     */
-    int mLruProcessActivityStart = 0;
-
-    /**
-     * Where in mLruProcesses that the processes hosting services start.
-     * This is after (lower index) than mLruProcessesActivityStart.
-     */
-    int mLruProcessServiceStart = 0;
-
-    /**
-     * List of processes that should gc as soon as things are idle.
-     */
-    final ArrayList<ProcessRecord> mProcessesToGc = new ArrayList<ProcessRecord>();
-
-    /**
-     * Processes we want to collect PSS data from.
-     */
-    final ArrayList<ProcessRecord> mPendingPssProcesses = new ArrayList<ProcessRecord>();
-
-    /**
-     * Last time we requested PSS data of all processes.
-     */
-    long mLastFullPssTime = SystemClock.uptimeMillis();
-
-    /**
-     * This is the process holding what we currently consider to be
-     * the "home" activity.
-     */
-    ProcessRecord mHomeProcess;
-
-    /**
-     * This is the process holding the activity the user last visited that
-     * is in a different process from the one they are currently in.
-     */
-    ProcessRecord mPreviousProcess;
-
-    /**
-     * The time at which the previous process was last visible.
-     */
-    long mPreviousProcessVisibleTime;
-
-    /**
-     * Which uses have been started, so are allowed to run code.
-     */
-    final SparseArray<UserStartedState> mStartedUsers = new SparseArray<UserStartedState>();
-
-    /**
-     * LRU list of history of current users.  Most recently current is at the end.
-     */
-    final ArrayList<Integer> mUserLru = new ArrayList<Integer>();
-
-    /**
-     * Constant array of the users that are currently started.
-     */
-    int[] mStartedUserArray = new int[] { 0 };
-
-    /**
-     * Registered observers of the user switching mechanics.
-     */
-    final RemoteCallbackList<IUserSwitchObserver> mUserSwitchObservers
-            = new RemoteCallbackList<IUserSwitchObserver>();
-
-    /**
-     * Currently active user switch.
-     */
-    Object mCurUserSwitchCallback;
-
-    /**
-     * Packages that the user has asked to have run in screen size
-     * compatibility mode instead of filling the screen.
-     */
-    final CompatModePackages mCompatModePackages;
-
-    /**
-     * Set of IntentSenderRecord objects that are currently active.
-     */
-    final HashMap<PendingIntentRecord.Key, WeakReference<PendingIntentRecord>> mIntentSenderRecords
-            = new HashMap<PendingIntentRecord.Key, WeakReference<PendingIntentRecord>>();
-
-    /**
-     * Fingerprints (hashCode()) of stack traces that we've
-     * already logged DropBox entries for.  Guarded by itself.  If
-     * something (rogue user app) forces this over
-     * MAX_DUP_SUPPRESSED_STACKS entries, the contents are cleared.
-     */
-    private final HashSet<Integer> mAlreadyLoggedViolatedStacks = new HashSet<Integer>();
-    private static final int MAX_DUP_SUPPRESSED_STACKS = 5000;
-
-    /**
-     * Strict Mode background batched logging state.
-     *
-     * The string buffer is guarded by itself, and its lock is also
-     * used to determine if another batched write is already
-     * in-flight.
-     */
-    private final StringBuilder mStrictModeBuffer = new StringBuilder();
-
-    /**
-     * Keeps track of all IIntentReceivers that have been registered for
-     * broadcasts.  Hash keys are the receiver IBinder, hash value is
-     * a ReceiverList.
-     */
-    final HashMap<IBinder, ReceiverList> mRegisteredReceivers =
-            new HashMap<IBinder, ReceiverList>();
-
-    /**
-     * Resolver for broadcast intents to registered receivers.
-     * Holds BroadcastFilter (subclass of IntentFilter).
-     */
-    final IntentResolver<BroadcastFilter, BroadcastFilter> mReceiverResolver
-            = new IntentResolver<BroadcastFilter, BroadcastFilter>() {
-        @Override
-        protected boolean allowFilterResult(
-                BroadcastFilter filter, List<BroadcastFilter> dest) {
-            IBinder target = filter.receiverList.receiver.asBinder();
-            for (int i=dest.size()-1; i>=0; i--) {
-                if (dest.get(i).receiverList.receiver.asBinder() == target) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        @Override
-        protected BroadcastFilter newResult(BroadcastFilter filter, int match, int userId) {
-            if (userId == UserHandle.USER_ALL || filter.owningUserId == UserHandle.USER_ALL
-                    || userId == filter.owningUserId) {
-                return super.newResult(filter, match, userId);
-            }
-            return null;
-        }
-
-        @Override
-        protected BroadcastFilter[] newArray(int size) {
-            return new BroadcastFilter[size];
-        }
-
-        @Override
-        protected boolean isPackageForFilter(String packageName, BroadcastFilter filter) {
-            return packageName.equals(filter.packageName);
-        }
-    };
-
-    /**
-     * State of all active sticky broadcasts per user.  Keys are the action of the
-     * sticky Intent, values are an ArrayList of all broadcasted intents with
-     * that action (which should usually be one).  The SparseArray is keyed
-     * by the user ID the sticky is for, and can include UserHandle.USER_ALL
-     * for stickies that are sent to all users.
-     */
-    final SparseArray<ArrayMap<String, ArrayList<Intent>>> mStickyBroadcasts =
-            new SparseArray<ArrayMap<String, ArrayList<Intent>>>();
-
-    final ActiveServices mServices;
-
-    /**
-     * Backup/restore process management
-     */
-    String mBackupAppName = null;
-    BackupRecord mBackupTarget = null;
-
-    /**
-     * List of PendingThumbnailsRecord objects of clients who are still
-     * waiting to receive all of the thumbnails for a task.
-     */
-    final ArrayList<PendingThumbnailsRecord> mPendingThumbnails =
-            new ArrayList<PendingThumbnailsRecord>();
-
-    final ProviderMap mProviderMap;
-
-    /**
-     * List of content providers who have clients waiting for them.  The
-     * application is currently being launched and the provider will be
-     * removed from this list once it is published.
-     */
-    final ArrayList<ContentProviderRecord> mLaunchingProviders
-            = new ArrayList<ContentProviderRecord>();
-
-    /**
-     * File storing persisted {@link #mGrantedUriPermissions}.
-     */
-    private final AtomicFile mGrantFile;
-
-    /** XML constants used in {@link #mGrantFile} */
-    private static final String TAG_URI_GRANTS = "uri-grants";
-    private static final String TAG_URI_GRANT = "uri-grant";
-    private static final String ATTR_USER_HANDLE = "userHandle";
-    private static final String ATTR_SOURCE_PKG = "sourcePkg";
-    private static final String ATTR_TARGET_PKG = "targetPkg";
-    private static final String ATTR_URI = "uri";
-    private static final String ATTR_MODE_FLAGS = "modeFlags";
-    private static final String ATTR_CREATED_TIME = "createdTime";
-
-    /**
-     * Global set of specific {@link Uri} permissions that have been granted.
-     * This optimized lookup structure maps from {@link UriPermission#targetUid}
-     * to {@link UriPermission#uri} to {@link UriPermission}.
-     */
-    @GuardedBy("this")
-    private final SparseArray<ArrayMap<Uri, UriPermission>>
-            mGrantedUriPermissions = new SparseArray<ArrayMap<Uri, UriPermission>>();
-
-    CoreSettingsObserver mCoreSettingsObserver;
-
-    /**
-     * Thread-local storage used to carry caller permissions over through
-     * indirect content-provider access.
-     */
-    private class Identity {
-        public int pid;
-        public int uid;
-
-        Identity(int _pid, int _uid) {
-            pid = _pid;
-            uid = _uid;
-        }
-    }
-
-    private static ThreadLocal<Identity> sCallerIdentity = new ThreadLocal<Identity>();
-
-    /**
-     * All information we have collected about the runtime performance of
-     * any user id that can impact battery performance.
-     */
-    final BatteryStatsService mBatteryStatsService;
-
-    /**
-     * Information about component usage
-     */
-    final UsageStatsService mUsageStatsService;
-
-    /**
-     * Information about and control over application operations
-     */
-    final AppOpsService mAppOpsService;
-
-    /**
-     * Current configuration information.  HistoryRecord objects are given
-     * a reference to this object to indicate which configuration they are
-     * currently running in, so this object must be kept immutable.
-     */
-    Configuration mConfiguration = new Configuration();
-
-    /**
-     * Current sequencing integer of the configuration, for skipping old
-     * configurations.
-     */
-    int mConfigurationSeq = 0;
-
-    /**
-     * Hardware-reported OpenGLES version.
-     */
-    final int GL_ES_VERSION;
-
-    /**
-     * List of initialization arguments to pass to all processes when binding applications to them.
-     * For example, references to the commonly used services.
-     */
-    HashMap<String, IBinder> mAppBindArgs;
-
-    /**
-     * Temporary to avoid allocations.  Protected by main lock.
-     */
-    final StringBuilder mStringBuilder = new StringBuilder(256);
-
-    /**
-     * Used to control how we initialize the service.
-     */
-    boolean mStartRunning = false;
-    ComponentName mTopComponent;
-    String mTopAction;
-    String mTopData;
-    boolean mProcessesReady = false;
-    boolean mSystemReady = false;
-    boolean mBooting = false;
-    boolean mWaitingUpdate = false;
-    boolean mDidUpdate = false;
-    boolean mOnBattery = false;
-    boolean mLaunchWarningShown = false;
-
-    Context mContext;
-
-    int mFactoryTest;
-
-    boolean mCheckedForSetup;
-
-    /**
-     * The time at which we will allow normal application switches again,
-     * after a call to {@link #stopAppSwitches()}.
-     */
-    long mAppSwitchesAllowedTime;
-
-    /**
-     * This is set to true after the first switch after mAppSwitchesAllowedTime
-     * is set; any switches after that will clear the time.
-     */
-    boolean mDidAppSwitch;
-
-    /**
-     * Last time (in realtime) at which we checked for power usage.
-     */
-    long mLastPowerCheckRealtime;
-
-    /**
-     * Last time (in uptime) at which we checked for power usage.
-     */
-    long mLastPowerCheckUptime;
-
-    /**
-     * Set while we are wanting to sleep, to prevent any
-     * activities from being started/resumed.
-     */
-    boolean mSleeping = false;
-
-    /**
-     * State of external calls telling us if the device is asleep.
-     */
-    boolean mWentToSleep = false;
-
-    /**
-     * State of external call telling us if the lock screen is shown.
-     */
-    boolean mLockScreenShown = false;
-
-    /**
-     * Set if we are shutting down the system, similar to sleeping.
-     */
-    boolean mShuttingDown = false;
-
-    /**
-     * Current sequence id for oom_adj computation traversal.
-     */
-    int mAdjSeq = 0;
-
-    /**
-     * Current sequence id for process LRU updating.
-     */
-    int mLruSeq = 0;
-
-    /**
-     * Keep track of the non-cached/empty process we last found, to help
-     * determine how to distribute cached/empty processes next time.
-     */
-    int mNumNonCachedProcs = 0;
-
-    /**
-     * Keep track of the number of cached hidden procs, to balance oom adj
-     * distribution between those and empty procs.
-     */
-    int mNumCachedHiddenProcs = 0;
-
-    /**
-     * Keep track of the number of service processes we last found, to
-     * determine on the next iteration which should be B services.
-     */
-    int mNumServiceProcs = 0;
-    int mNewNumAServiceProcs = 0;
-    int mNewNumServiceProcs = 0;
-
-    /**
-     * Allow the current computed overall memory level of the system to go down?
-     * This is set to false when we are killing processes for reasons other than
-     * memory management, so that the now smaller process list will not be taken as
-     * an indication that memory is tighter.
-     */
-    boolean mAllowLowerMemLevel = false;
-
-    /**
-     * The last computed memory level, for holding when we are in a state that
-     * processes are going away for other reasons.
-     */
-    int mLastMemoryLevel = ProcessStats.ADJ_MEM_FACTOR_NORMAL;
-
-    /**
-     * The last total number of process we have, to determine if changes actually look
-     * like a shrinking number of process due to lower RAM.
-     */
-    int mLastNumProcesses;
-
-    /**
-     * The uptime of the last time we performed idle maintenance.
-     */
-    long mLastIdleTime = SystemClock.uptimeMillis();
-
-    /**
-     * Total time spent with RAM that has been added in the past since the last idle time.
-     */
-    long mLowRamTimeSinceLastIdle = 0;
-
-    /**
-     * If RAM is currently low, when that horrible situatin started.
-     */
-    long mLowRamStartTime = 0;
-
-    /**
-     * This is set if we had to do a delayed dexopt of an app before launching
-     * it, to increasing the ANR timeouts in that case.
-     */
-    boolean mDidDexOpt;
-
-    String mDebugApp = null;
-    boolean mWaitForDebugger = false;
-    boolean mDebugTransient = false;
-    String mOrigDebugApp = null;
-    boolean mOrigWaitForDebugger = false;
-    boolean mAlwaysFinishActivities = false;
-    IActivityController mController = null;
-    String mProfileApp = null;
-    ProcessRecord mProfileProc = null;
-    String mProfileFile;
-    ParcelFileDescriptor mProfileFd;
-    int mProfileType = 0;
-    boolean mAutoStopProfiler = false;
-    String mOpenGlTraceApp = null;
-
-    static class ProcessChangeItem {
-        static final int CHANGE_ACTIVITIES = 1<<0;
-        static final int CHANGE_IMPORTANCE= 1<<1;
-        int changes;
-        int uid;
-        int pid;
-        int importance;
-        boolean foregroundActivities;
-    }
-
-    final RemoteCallbackList<IProcessObserver> mProcessObservers
-            = new RemoteCallbackList<IProcessObserver>();
-    ProcessChangeItem[] mActiveProcessChanges = new ProcessChangeItem[5];
-
-    final ArrayList<ProcessChangeItem> mPendingProcessChanges
-            = new ArrayList<ProcessChangeItem>();
-    final ArrayList<ProcessChangeItem> mAvailProcessChanges
-            = new ArrayList<ProcessChangeItem>();
-
-    /**
-     * Runtime CPU use collection thread.  This object's lock is used to
-     * protect all related state.
-     */
-    final Thread mProcessCpuThread;
-
-    /**
-     * Used to collect process stats when showing not responding dialog.
-     * Protected by mProcessCpuThread.
-     */
-    final ProcessCpuTracker mProcessCpuTracker = new ProcessCpuTracker(
-            MONITOR_THREAD_CPU_USAGE);
-    final AtomicLong mLastCpuTime = new AtomicLong(0);
-    final AtomicBoolean mProcessCpuMutexFree = new AtomicBoolean(true);
-
-    long mLastWriteTime = 0;
-
-    /**
-     * Used to retain an update lock when the foreground activity is in
-     * immersive mode.
-     */
-    final UpdateLock mUpdateLock = new UpdateLock("immersive");
-
-    /**
-     * Set to true after the system has finished booting.
-     */
-    boolean mBooted = false;
-
-    int mProcessLimit = ProcessList.MAX_CACHED_APPS;
-    int mProcessLimitOverride = -1;
-
-    WindowManagerService mWindowManager;
-
-    static ActivityManagerService mSelf;
-    static ActivityThread mSystemThread;
-
-    int mCurrentUserId = 0;
-    private UserManagerService mUserManager;
-
-    private final class AppDeathRecipient implements IBinder.DeathRecipient {
-        final ProcessRecord mApp;
-        final int mPid;
-        final IApplicationThread mAppThread;
-
-        AppDeathRecipient(ProcessRecord app, int pid,
-                IApplicationThread thread) {
-            if (localLOGV) Slog.v(
-                TAG, "New death recipient " + this
-                + " for thread " + thread.asBinder());
-            mApp = app;
-            mPid = pid;
-            mAppThread = thread;
-        }
-
-        @Override
-        public void binderDied() {
-            if (localLOGV) Slog.v(
-                TAG, "Death received in " + this
-                + " for thread " + mAppThread.asBinder());
-            synchronized(ActivityManagerService.this) {
-                appDiedLocked(mApp, mPid, mAppThread);
-            }
-        }
-    }
-
-    static final int SHOW_ERROR_MSG = 1;
-    static final int SHOW_NOT_RESPONDING_MSG = 2;
-    static final int SHOW_FACTORY_ERROR_MSG = 3;
-    static final int UPDATE_CONFIGURATION_MSG = 4;
-    static final int GC_BACKGROUND_PROCESSES_MSG = 5;
-    static final int WAIT_FOR_DEBUGGER_MSG = 6;
-    static final int SERVICE_TIMEOUT_MSG = 12;
-    static final int UPDATE_TIME_ZONE = 13;
-    static final int SHOW_UID_ERROR_MSG = 14;
-    static final int IM_FEELING_LUCKY_MSG = 15;
-    static final int PROC_START_TIMEOUT_MSG = 20;
-    static final int DO_PENDING_ACTIVITY_LAUNCHES_MSG = 21;
-    static final int KILL_APPLICATION_MSG = 22;
-    static final int FINALIZE_PENDING_INTENT_MSG = 23;
-    static final int POST_HEAVY_NOTIFICATION_MSG = 24;
-    static final int CANCEL_HEAVY_NOTIFICATION_MSG = 25;
-    static final int SHOW_STRICT_MODE_VIOLATION_MSG = 26;
-    static final int CHECK_EXCESSIVE_WAKE_LOCKS_MSG = 27;
-    static final int CLEAR_DNS_CACHE_MSG = 28;
-    static final int UPDATE_HTTP_PROXY_MSG = 29;
-    static final int SHOW_COMPAT_MODE_DIALOG_MSG = 30;
-    static final int DISPATCH_PROCESSES_CHANGED = 31;
-    static final int DISPATCH_PROCESS_DIED = 32;
-    static final int REPORT_MEM_USAGE_MSG = 33;
-    static final int REPORT_USER_SWITCH_MSG = 34;
-    static final int CONTINUE_USER_SWITCH_MSG = 35;
-    static final int USER_SWITCH_TIMEOUT_MSG = 36;
-    static final int IMMERSIVE_MODE_LOCK_MSG = 37;
-    static final int PERSIST_URI_GRANTS_MSG = 38;
-    static final int REQUEST_ALL_PSS_MSG = 39;
-
-    static final int FIRST_ACTIVITY_STACK_MSG = 100;
-    static final int FIRST_BROADCAST_QUEUE_MSG = 200;
-    static final int FIRST_COMPAT_MODE_MSG = 300;
-    static final int FIRST_SUPERVISOR_STACK_MSG = 100;
-
-    AlertDialog mUidAlert;
-    CompatModeDialog mCompatModeDialog;
-    long mLastMemUsageReportTime = 0;
-
-    /**
-     * Flag whether the current user is a "monkey", i.e. whether
-     * the UI is driven by a UI automation tool.
-     */
-    private boolean mUserIsMonkey;
-
-    final Handler mHandler = new Handler() {
-        //public Handler() {
-        //    if (localLOGV) Slog.v(TAG, "Handler started!");
-        //}
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-            case SHOW_ERROR_MSG: {
-                HashMap<String, Object> data = (HashMap<String, Object>) msg.obj;
-                boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
-                        Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
-                synchronized (ActivityManagerService.this) {
-                    ProcessRecord proc = (ProcessRecord)data.get("app");
-                    AppErrorResult res = (AppErrorResult) data.get("result");
-                    if (proc != null && proc.crashDialog != null) {
-                        Slog.e(TAG, "App already has crash dialog: " + proc);
-                        if (res != null) {
-                            res.set(0);
-                        }
-                        return;
-                    }
-                    if (!showBackground && UserHandle.getAppId(proc.uid)
-                            >= Process.FIRST_APPLICATION_UID && proc.userId != mCurrentUserId
-                            && proc.pid != MY_PID) {
-                        Slog.w(TAG, "Skipping crash dialog of " + proc + ": background");
-                        if (res != null) {
-                            res.set(0);
-                        }
-                        return;
-                    }
-                    if (mShowDialogs && !mSleeping && !mShuttingDown) {
-                        Dialog d = new AppErrorDialog(mContext,
-                                ActivityManagerService.this, res, proc);
-                        d.show();
-                        proc.crashDialog = d;
-                    } else {
-                        // The device is asleep, so just pretend that the user
-                        // saw a crash dialog and hit "force quit".
-                        if (res != null) {
-                            res.set(0);
-                        }
-                    }
-                }
-
-                ensureBootCompleted();
-            } break;
-            case SHOW_NOT_RESPONDING_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    HashMap<String, Object> data = (HashMap<String, Object>) msg.obj;
-                    ProcessRecord proc = (ProcessRecord)data.get("app");
-                    if (proc != null && proc.anrDialog != null) {
-                        Slog.e(TAG, "App already has anr dialog: " + proc);
-                        return;
-                    }
-
-                    Intent intent = new Intent("android.intent.action.ANR");
-                    if (!mProcessesReady) {
-                        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                                | Intent.FLAG_RECEIVER_FOREGROUND);
-                    }
-                    broadcastIntentLocked(null, null, intent,
-                            null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                            false, false, MY_PID, Process.SYSTEM_UID, 0 /* TODO: Verify */);
-
-                    if (mShowDialogs) {
-                        Dialog d = new AppNotRespondingDialog(ActivityManagerService.this,
-                                mContext, proc, (ActivityRecord)data.get("activity"),
-                                msg.arg1 != 0);
-                        d.show();
-                        proc.anrDialog = d;
-                    } else {
-                        // Just kill the app if there is no dialog to be shown.
-                        killAppAtUsersRequest(proc, null);
-                    }
-                }
-
-                ensureBootCompleted();
-            } break;
-            case SHOW_STRICT_MODE_VIOLATION_MSG: {
-                HashMap<String, Object> data = (HashMap<String, Object>) msg.obj;
-                synchronized (ActivityManagerService.this) {
-                    ProcessRecord proc = (ProcessRecord) data.get("app");
-                    if (proc == null) {
-                        Slog.e(TAG, "App not found when showing strict mode dialog.");
-                        break;
-                    }
-                    if (proc.crashDialog != null) {
-                        Slog.e(TAG, "App already has strict mode dialog: " + proc);
-                        return;
-                    }
-                    AppErrorResult res = (AppErrorResult) data.get("result");
-                    if (mShowDialogs && !mSleeping && !mShuttingDown) {
-                        Dialog d = new StrictModeViolationDialog(mContext,
-                                ActivityManagerService.this, res, proc);
-                        d.show();
-                        proc.crashDialog = d;
-                    } else {
-                        // The device is asleep, so just pretend that the user
-                        // saw a crash dialog and hit "force quit".
-                        res.set(0);
-                    }
-                }
-                ensureBootCompleted();
-            } break;
-            case SHOW_FACTORY_ERROR_MSG: {
-                Dialog d = new FactoryErrorDialog(
-                    mContext, msg.getData().getCharSequence("msg"));
-                d.show();
-                ensureBootCompleted();
-            } break;
-            case UPDATE_CONFIGURATION_MSG: {
-                final ContentResolver resolver = mContext.getContentResolver();
-                Settings.System.putConfiguration(resolver, (Configuration)msg.obj);
-            } break;
-            case GC_BACKGROUND_PROCESSES_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    performAppGcsIfAppropriateLocked();
-                }
-            } break;
-            case WAIT_FOR_DEBUGGER_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    ProcessRecord app = (ProcessRecord)msg.obj;
-                    if (msg.arg1 != 0) {
-                        if (!app.waitedForDebugger) {
-                            Dialog d = new AppWaitingForDebuggerDialog(
-                                    ActivityManagerService.this,
-                                    mContext, app);
-                            app.waitDialog = d;
-                            app.waitedForDebugger = true;
-                            d.show();
-                        }
-                    } else {
-                        if (app.waitDialog != null) {
-                            app.waitDialog.dismiss();
-                            app.waitDialog = null;
-                        }
-                    }
-                }
-            } break;
-            case SERVICE_TIMEOUT_MSG: {
-                if (mDidDexOpt) {
-                    mDidDexOpt = false;
-                    Message nmsg = mHandler.obtainMessage(SERVICE_TIMEOUT_MSG);
-                    nmsg.obj = msg.obj;
-                    mHandler.sendMessageDelayed(nmsg, ActiveServices.SERVICE_TIMEOUT);
-                    return;
-                }
-                mServices.serviceTimeout((ProcessRecord)msg.obj);
-            } break;
-            case UPDATE_TIME_ZONE: {
-                synchronized (ActivityManagerService.this) {
-                    for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
-                        ProcessRecord r = mLruProcesses.get(i);
-                        if (r.thread != null) {
-                            try {
-                                r.thread.updateTimeZone();
-                            } catch (RemoteException ex) {
-                                Slog.w(TAG, "Failed to update time zone for: " + r.info.processName);
-                            }
-                        }
-                    }
-                }
-            } break;
-            case CLEAR_DNS_CACHE_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
-                        ProcessRecord r = mLruProcesses.get(i);
-                        if (r.thread != null) {
-                            try {
-                                r.thread.clearDnsCache();
-                            } catch (RemoteException ex) {
-                                Slog.w(TAG, "Failed to clear dns cache for: " + r.info.processName);
-                            }
-                        }
-                    }
-                }
-            } break;
-            case UPDATE_HTTP_PROXY_MSG: {
-                ProxyProperties proxy = (ProxyProperties)msg.obj;
-                String host = "";
-                String port = "";
-                String exclList = "";
-                String pacFileUrl = null;
-                if (proxy != null) {
-                    host = proxy.getHost();
-                    port = Integer.toString(proxy.getPort());
-                    exclList = proxy.getExclusionList();
-                    pacFileUrl = proxy.getPacFileUrl();
-                }
-                synchronized (ActivityManagerService.this) {
-                    for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
-                        ProcessRecord r = mLruProcesses.get(i);
-                        if (r.thread != null) {
-                            try {
-                                r.thread.setHttpProxy(host, port, exclList, pacFileUrl);
-                            } catch (RemoteException ex) {
-                                Slog.w(TAG, "Failed to update http proxy for: " +
-                                        r.info.processName);
-                            }
-                        }
-                    }
-                }
-            } break;
-            case SHOW_UID_ERROR_MSG: {
-                String title = "System UIDs Inconsistent";
-                String text = "UIDs on the system are inconsistent, you need to wipe your"
-                        + " data partition or your device will be unstable.";
-                Log.e(TAG, title + ": " + text);
-                if (mShowDialogs) {
-                    // XXX This is a temporary dialog, no need to localize.
-                    AlertDialog d = new BaseErrorDialog(mContext);
-                    d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
-                    d.setCancelable(false);
-                    d.setTitle(title);
-                    d.setMessage(text);
-                    d.setButton(DialogInterface.BUTTON_POSITIVE, "I'm Feeling Lucky",
-                            mHandler.obtainMessage(IM_FEELING_LUCKY_MSG));
-                    mUidAlert = d;
-                    d.show();
-                }
-            } break;
-            case IM_FEELING_LUCKY_MSG: {
-                if (mUidAlert != null) {
-                    mUidAlert.dismiss();
-                    mUidAlert = null;
-                }
-            } break;
-            case PROC_START_TIMEOUT_MSG: {
-                if (mDidDexOpt) {
-                    mDidDexOpt = false;
-                    Message nmsg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
-                    nmsg.obj = msg.obj;
-                    mHandler.sendMessageDelayed(nmsg, PROC_START_TIMEOUT);
-                    return;
-                }
-                ProcessRecord app = (ProcessRecord)msg.obj;
-                synchronized (ActivityManagerService.this) {
-                    processStartTimedOutLocked(app);
-                }
-            } break;
-            case DO_PENDING_ACTIVITY_LAUNCHES_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    doPendingActivityLaunchesLocked(true);
-                }
-            } break;
-            case KILL_APPLICATION_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    int appid = msg.arg1;
-                    boolean restart = (msg.arg2 == 1);
-                    Bundle bundle = (Bundle)msg.obj;
-                    String pkg = bundle.getString("pkg");
-                    String reason = bundle.getString("reason");
-                    forceStopPackageLocked(pkg, appid, restart, false, true, false,
-                            false, UserHandle.USER_ALL, reason);
-                }
-            } break;
-            case FINALIZE_PENDING_INTENT_MSG: {
-                ((PendingIntentRecord)msg.obj).completeFinalize();
-            } break;
-            case POST_HEAVY_NOTIFICATION_MSG: {
-                INotificationManager inm = NotificationManager.getService();
-                if (inm == null) {
-                    return;
-                }
-
-                ActivityRecord root = (ActivityRecord)msg.obj;
-                ProcessRecord process = root.app;
-                if (process == null) {
-                    return;
-                }
-
-                try {
-                    Context context = mContext.createPackageContext(process.info.packageName, 0);
-                    String text = mContext.getString(R.string.heavy_weight_notification,
-                            context.getApplicationInfo().loadLabel(context.getPackageManager()));
-                    Notification notification = new Notification();
-                    notification.icon = com.android.internal.R.drawable.stat_sys_adb; //context.getApplicationInfo().icon;
-                    notification.when = 0;
-                    notification.flags = Notification.FLAG_ONGOING_EVENT;
-                    notification.tickerText = text;
-                    notification.defaults = 0; // please be quiet
-                    notification.sound = null;
-                    notification.vibrate = null;
-                    notification.setLatestEventInfo(context, text,
-                            mContext.getText(R.string.heavy_weight_notification_detail),
-                            PendingIntent.getActivityAsUser(mContext, 0, root.intent,
-                                    PendingIntent.FLAG_CANCEL_CURRENT, null,
-                                    new UserHandle(root.userId)));
-
-                    try {
-                        int[] outId = new int[1];
-                        inm.enqueueNotificationWithTag("android", "android", null,
-                                R.string.heavy_weight_notification,
-                                notification, outId, root.userId);
-                    } catch (RuntimeException e) {
-                        Slog.w(ActivityManagerService.TAG,
-                                "Error showing notification for heavy-weight app", e);
-                    } catch (RemoteException e) {
-                    }
-                } catch (NameNotFoundException e) {
-                    Slog.w(TAG, "Unable to create context for heavy notification", e);
-                }
-            } break;
-            case CANCEL_HEAVY_NOTIFICATION_MSG: {
-                INotificationManager inm = NotificationManager.getService();
-                if (inm == null) {
-                    return;
-                }
-                try {
-                    inm.cancelNotificationWithTag("android", null,
-                            R.string.heavy_weight_notification,  msg.arg1);
-                } catch (RuntimeException e) {
-                    Slog.w(ActivityManagerService.TAG,
-                            "Error canceling notification for service", e);
-                } catch (RemoteException e) {
-                }
-            } break;
-            case CHECK_EXCESSIVE_WAKE_LOCKS_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    checkExcessivePowerUsageLocked(true);
-                    removeMessages(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
-                    Message nmsg = obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
-                    sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
-                }
-            } break;
-            case SHOW_COMPAT_MODE_DIALOG_MSG: {
-                synchronized (ActivityManagerService.this) {
-                    ActivityRecord ar = (ActivityRecord)msg.obj;
-                    if (mCompatModeDialog != null) {
-                        if (mCompatModeDialog.mAppInfo.packageName.equals(
-                                ar.info.applicationInfo.packageName)) {
-                            return;
-                        }
-                        mCompatModeDialog.dismiss();
-                        mCompatModeDialog = null;
-                    }
-                    if (ar != null && false) {
-                        if (mCompatModePackages.getPackageAskCompatModeLocked(
-                                ar.packageName)) {
-                            int mode = mCompatModePackages.computeCompatModeLocked(
-                                    ar.info.applicationInfo);
-                            if (mode == ActivityManager.COMPAT_MODE_DISABLED
-                                    || mode == ActivityManager.COMPAT_MODE_ENABLED) {
-                                mCompatModeDialog = new CompatModeDialog(
-                                        ActivityManagerService.this, mContext,
-                                        ar.info.applicationInfo);
-                                mCompatModeDialog.show();
-                            }
-                        }
-                    }
-                }
-                break;
-            }
-            case DISPATCH_PROCESSES_CHANGED: {
-                dispatchProcessesChanged();
-                break;
-            }
-            case DISPATCH_PROCESS_DIED: {
-                final int pid = msg.arg1;
-                final int uid = msg.arg2;
-                dispatchProcessDied(pid, uid);
-                break;
-            }
-            case REPORT_MEM_USAGE_MSG: {
-                final ArrayList<ProcessMemInfo> memInfos = (ArrayList<ProcessMemInfo>)msg.obj;
-                Thread thread = new Thread() {
-                    @Override public void run() {
-                        final SparseArray<ProcessMemInfo> infoMap
-                                = new SparseArray<ProcessMemInfo>(memInfos.size());
-                        for (int i=0, N=memInfos.size(); i<N; i++) {
-                            ProcessMemInfo mi = memInfos.get(i);
-                            infoMap.put(mi.pid, mi);
-                        }
-                        updateCpuStatsNow();
-                        synchronized (mProcessCpuThread) {
-                            final int N = mProcessCpuTracker.countStats();
-                            for (int i=0; i<N; i++) {
-                                ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
-                                if (st.vsize > 0) {
-                                    long pss = Debug.getPss(st.pid, null);
-                                    if (pss > 0) {
-                                        if (infoMap.indexOfKey(st.pid) < 0) {
-                                            ProcessMemInfo mi = new ProcessMemInfo(st.name, st.pid,
-                                                    ProcessList.NATIVE_ADJ, -1, "native", null);
-                                            mi.pss = pss;
-                                            memInfos.add(mi);
-                                        }
-                                    }
-                                }
-                            }
-                        }
-
-                        long totalPss = 0;
-                        for (int i=0, N=memInfos.size(); i<N; i++) {
-                            ProcessMemInfo mi = memInfos.get(i);
-                            if (mi.pss == 0) {
-                                mi.pss = Debug.getPss(mi.pid, null);
-                            }
-                            totalPss += mi.pss;
-                        }
-                        Collections.sort(memInfos, new Comparator<ProcessMemInfo>() {
-                            @Override public int compare(ProcessMemInfo lhs, ProcessMemInfo rhs) {
-                                if (lhs.oomAdj != rhs.oomAdj) {
-                                    return lhs.oomAdj < rhs.oomAdj ? -1 : 1;
-                                }
-                                if (lhs.pss != rhs.pss) {
-                                    return lhs.pss < rhs.pss ? 1 : -1;
-                                }
-                                return 0;
-                            }
-                        });
-
-                        StringBuilder tag = new StringBuilder(128);
-                        StringBuilder stack = new StringBuilder(128);
-                        tag.append("Low on memory -- ");
-                        appendMemBucket(tag, totalPss, "total", false);
-                        appendMemBucket(stack, totalPss, "total", true);
-
-                        StringBuilder logBuilder = new StringBuilder(1024);
-                        logBuilder.append("Low on memory:\n");
-
-                        boolean firstLine = true;
-                        int lastOomAdj = Integer.MIN_VALUE;
-                        for (int i=0, N=memInfos.size(); i<N; i++) {
-                            ProcessMemInfo mi = memInfos.get(i);
-
-                            if (mi.oomAdj != ProcessList.NATIVE_ADJ
-                                    && (mi.oomAdj < ProcessList.SERVICE_ADJ
-                                            || mi.oomAdj == ProcessList.HOME_APP_ADJ
-                                            || mi.oomAdj == ProcessList.PREVIOUS_APP_ADJ)) {
-                                if (lastOomAdj != mi.oomAdj) {
-                                    lastOomAdj = mi.oomAdj;
-                                    if (mi.oomAdj <= ProcessList.FOREGROUND_APP_ADJ) {
-                                        tag.append(" / ");
-                                    }
-                                    if (mi.oomAdj >= ProcessList.FOREGROUND_APP_ADJ) {
-                                        if (firstLine) {
-                                            stack.append(":");
-                                            firstLine = false;
-                                        }
-                                        stack.append("\n\t at ");
-                                    } else {
-                                        stack.append("$");
-                                    }
-                                } else {
-                                    tag.append(" ");
-                                    stack.append("$");
-                                }
-                                if (mi.oomAdj <= ProcessList.FOREGROUND_APP_ADJ) {
-                                    appendMemBucket(tag, mi.pss, mi.name, false);
-                                }
-                                appendMemBucket(stack, mi.pss, mi.name, true);
-                                if (mi.oomAdj >= ProcessList.FOREGROUND_APP_ADJ
-                                        && ((i+1) >= N || memInfos.get(i+1).oomAdj != lastOomAdj)) {
-                                    stack.append("(");
-                                    for (int k=0; k<DUMP_MEM_OOM_ADJ.length; k++) {
-                                        if (DUMP_MEM_OOM_ADJ[k] == mi.oomAdj) {
-                                            stack.append(DUMP_MEM_OOM_LABEL[k]);
-                                            stack.append(":");
-                                            stack.append(DUMP_MEM_OOM_ADJ[k]);
-                                        }
-                                    }
-                                    stack.append(")");
-                                }
-                            }
-
-                            logBuilder.append("  ");
-                            logBuilder.append(ProcessList.makeOomAdjString(mi.oomAdj));
-                            logBuilder.append(' ');
-                            logBuilder.append(ProcessList.makeProcStateString(mi.procState));
-                            logBuilder.append(' ');
-                            ProcessList.appendRamKb(logBuilder, mi.pss);
-                            logBuilder.append(" kB: ");
-                            logBuilder.append(mi.name);
-                            logBuilder.append(" (");
-                            logBuilder.append(mi.pid);
-                            logBuilder.append(") ");
-                            logBuilder.append(mi.adjType);
-                            logBuilder.append('\n');
-                            if (mi.adjReason != null) {
-                                logBuilder.append("                      ");
-                                logBuilder.append(mi.adjReason);
-                                logBuilder.append('\n');
-                            }
-                        }
-
-                        logBuilder.append("           ");
-                        ProcessList.appendRamKb(logBuilder, totalPss);
-                        logBuilder.append(" kB: TOTAL\n");
-
-                        long[] infos = new long[Debug.MEMINFO_COUNT];
-                        Debug.getMemInfo(infos);
-                        logBuilder.append("  MemInfo: ");
-                        logBuilder.append(infos[Debug.MEMINFO_SLAB]).append(" kB slab, ");
-                        logBuilder.append(infos[Debug.MEMINFO_SHMEM]).append(" kB shmem, ");
-                        logBuilder.append(infos[Debug.MEMINFO_BUFFERS]).append(" kB buffers, ");
-                        logBuilder.append(infos[Debug.MEMINFO_CACHED]).append(" kB cached, ");
-                        logBuilder.append(infos[Debug.MEMINFO_FREE]).append(" kB free\n");
-                        if (infos[Debug.MEMINFO_ZRAM_TOTAL] != 0) {
-                            logBuilder.append("  ZRAM: ");
-                            logBuilder.append(infos[Debug.MEMINFO_ZRAM_TOTAL]);
-                            logBuilder.append(" kB RAM, ");
-                            logBuilder.append(infos[Debug.MEMINFO_SWAP_TOTAL]);
-                            logBuilder.append(" kB swap total, ");
-                            logBuilder.append(infos[Debug.MEMINFO_SWAP_FREE]);
-                            logBuilder.append(" kB swap free\n");
-                        }
-                        Slog.i(TAG, logBuilder.toString());
-
-                        StringBuilder dropBuilder = new StringBuilder(1024);
-                        /*
-                        StringWriter oomSw = new StringWriter();
-                        PrintWriter oomPw = new FastPrintWriter(oomSw, false, 256);
-                        StringWriter catSw = new StringWriter();
-                        PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
-                        String[] emptyArgs = new String[] { };
-                        dumpApplicationMemoryUsage(null, oomPw, "  ", emptyArgs, true, catPw);
-                        oomPw.flush();
-                        String oomString = oomSw.toString();
-                        */
-                        dropBuilder.append(stack);
-                        dropBuilder.append('\n');
-                        dropBuilder.append('\n');
-                        dropBuilder.append(logBuilder);
-                        dropBuilder.append('\n');
-                        /*
-                        dropBuilder.append(oomString);
-                        dropBuilder.append('\n');
-                        */
-                        StringWriter catSw = new StringWriter();
-                        synchronized (ActivityManagerService.this) {
-                            PrintWriter catPw = new FastPrintWriter(catSw, false, 256);
-                            String[] emptyArgs = new String[] { };
-                            catPw.println();
-                            dumpProcessesLocked(null, catPw, emptyArgs, 0, false, null);
-                            catPw.println();
-                            mServices.dumpServicesLocked(null, catPw, emptyArgs, 0,
-                                    false, false, null);
-                            catPw.println();
-                            dumpActivitiesLocked(null, catPw, emptyArgs, 0, false, false, null);
-                            catPw.flush();
-                        }
-                        dropBuilder.append(catSw.toString());
-                        addErrorToDropBox("lowmem", null, "system_server", null,
-                                null, tag.toString(), dropBuilder.toString(), null, null);
-                        //Slog.i(TAG, "Sent to dropbox:");
-                        //Slog.i(TAG, dropBuilder.toString());
-                        synchronized (ActivityManagerService.this) {
-                            long now = SystemClock.uptimeMillis();
-                            if (mLastMemUsageReportTime < now) {
-                                mLastMemUsageReportTime = now;
-                            }
-                        }
-                    }
-                };
-                thread.start();
-                break;
-            }
-            case REPORT_USER_SWITCH_MSG: {
-                dispatchUserSwitch((UserStartedState)msg.obj, msg.arg1, msg.arg2);
-                break;
-            }
-            case CONTINUE_USER_SWITCH_MSG: {
-                continueUserSwitch((UserStartedState)msg.obj, msg.arg1, msg.arg2);
-                break;
-            }
-            case USER_SWITCH_TIMEOUT_MSG: {
-                timeoutUserSwitch((UserStartedState)msg.obj, msg.arg1, msg.arg2);
-                break;
-            }
-            case IMMERSIVE_MODE_LOCK_MSG: {
-                final boolean nextState = (msg.arg1 != 0);
-                if (mUpdateLock.isHeld() != nextState) {
-                    if (DEBUG_IMMERSIVE) {
-                        final ActivityRecord r = (ActivityRecord) msg.obj;
-                        Slog.d(TAG, "Applying new update lock state '" + nextState + "' for " + r);
-                    }
-                    if (nextState) {
-                        mUpdateLock.acquire();
-                    } else {
-                        mUpdateLock.release();
-                    }
-                }
-                break;
-            }
-            case PERSIST_URI_GRANTS_MSG: {
-                writeGrantedUriPermissions();
-                break;
-            }
-            case REQUEST_ALL_PSS_MSG: {
-                requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
-                break;
-            }
-            }
-        }
-    };
-
-    static final int COLLECT_PSS_BG_MSG = 1;
-
-    final Handler mBgHandler = new Handler(BackgroundThread.getHandler().getLooper()) {
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-            case COLLECT_PSS_BG_MSG: {
-                int i=0, num=0;
-                long start = SystemClock.uptimeMillis();
-                long[] tmp = new long[1];
-                do {
-                    ProcessRecord proc;
-                    int procState;
-                    int pid;
-                    synchronized (ActivityManagerService.this) {
-                        if (i >= mPendingPssProcesses.size()) {
-                            if (DEBUG_PSS) Slog.d(TAG, "Collected PSS of " + num + " of " + i
-                                    + " processes in " + (SystemClock.uptimeMillis()-start) + "ms");
-                            mPendingPssProcesses.clear();
-                            return;
-                        }
-                        proc = mPendingPssProcesses.get(i);
-                        procState = proc.pssProcState;
-                        if (proc.thread != null && procState == proc.setProcState) {
-                            pid = proc.pid;
-                        } else {
-                            proc = null;
-                            pid = 0;
-                        }
-                        i++;
-                    }
-                    if (proc != null) {
-                        long pss = Debug.getPss(pid, tmp);
-                        synchronized (ActivityManagerService.this) {
-                            if (proc.thread != null && proc.setProcState == procState
-                                    && proc.pid == pid) {
-                                num++;
-                                proc.lastPssTime = SystemClock.uptimeMillis();
-                                proc.baseProcessTracker.addPss(pss, tmp[0], true, proc.pkgList);
-                                if (DEBUG_PSS) Slog.d(TAG, "PSS of " + proc.toShortString()
-                                        + ": " + pss + " lastPss=" + proc.lastPss
-                                        + " state=" + ProcessList.makeProcStateString(procState));
-                                if (proc.initialIdlePss == 0) {
-                                    proc.initialIdlePss = pss;
-                                }
-                                proc.lastPss = pss;
-                                if (procState >= ActivityManager.PROCESS_STATE_HOME) {
-                                    proc.lastCachedPss = pss;
-                                }
-                            }
-                        }
-                    }
-                } while (true);
-            }
-            }
-        }
-    };
-
-    public static void setSystemProcess() {
-        try {
-            ActivityManagerService m = mSelf;
-
-            ServiceManager.addService(Context.ACTIVITY_SERVICE, m, true);
-            ServiceManager.addService(ProcessStats.SERVICE_NAME, m.mProcessStats);
-            ServiceManager.addService("meminfo", new MemBinder(m));
-            ServiceManager.addService("gfxinfo", new GraphicsBinder(m));
-            ServiceManager.addService("dbinfo", new DbBinder(m));
-            if (MONITOR_CPU_USAGE) {
-                ServiceManager.addService("cpuinfo", new CpuBinder(m));
-            }
-            ServiceManager.addService("permission", new PermissionController(m));
-
-            ApplicationInfo info =
-                mSelf.mContext.getPackageManager().getApplicationInfo(
-                            "android", STOCK_PM_FLAGS);
-            mSystemThread.installSystemApplicationInfo(info);
-
-            synchronized (mSelf) {
-                ProcessRecord app = mSelf.newProcessRecordLocked(info,
-                        info.processName, false);
-                app.persistent = true;
-                app.pid = MY_PID;
-                app.maxAdj = ProcessList.SYSTEM_ADJ;
-                app.makeActive(mSystemThread.getApplicationThread(), mSelf.mProcessStats);
-                mSelf.mProcessNames.put(app.processName, app.uid, app);
-                synchronized (mSelf.mPidsSelfLocked) {
-                    mSelf.mPidsSelfLocked.put(app.pid, app);
-                }
-                mSelf.updateLruProcessLocked(app, false, null);
-                mSelf.updateOomAdjLocked();
-            }
-        } catch (PackageManager.NameNotFoundException e) {
-            throw new RuntimeException(
-                    "Unable to find android system package", e);
-        }
-    }
-
-    public void setWindowManager(WindowManagerService wm) {
-        mWindowManager = wm;
-        mStackSupervisor.setWindowManager(wm);
-        wm.createStack(HOME_STACK_ID, -1, StackBox.TASK_STACK_GOES_OVER, 1.0f);
-    }
-
-    public void startObservingNativeCrashes() {
-        final NativeCrashListener ncl = new NativeCrashListener();
-        ncl.start();
-    }
-
-    public static final Context main(int factoryTest) {
-        AThread thr = new AThread();
-        thr.start();
-
-        synchronized (thr) {
-            while (thr.mService == null) {
-                try {
-                    thr.wait();
-                } catch (InterruptedException e) {
-                }
-            }
-        }
-
-        ActivityManagerService m = thr.mService;
-        mSelf = m;
-        ActivityThread at = ActivityThread.systemMain();
-        mSystemThread = at;
-        Context context = at.getSystemContext();
-        context.setTheme(android.R.style.Theme_Holo);
-        m.mContext = context;
-        m.mFactoryTest = factoryTest;
-        m.mIntentFirewall = new IntentFirewall(m.new IntentFirewallInterface());
-
-        m.mStackSupervisor = new ActivityStackSupervisor(m, context, thr.mLooper);
-
-        m.mBatteryStatsService.publish(context);
-        m.mUsageStatsService.publish(context);
-        m.mAppOpsService.publish(context);
-
-        synchronized (thr) {
-            thr.mReady = true;
-            thr.notifyAll();
-        }
-
-        m.startRunning(null, null, null, null);
-
-        return context;
-    }
-
-    public static ActivityManagerService self() {
-        return mSelf;
-    }
-
-    public IAppOpsService getAppOpsService() {
-        return mAppOpsService;
-    }
-
-    static class AThread extends Thread {
-        ActivityManagerService mService;
-        Looper mLooper;
-        boolean mReady = false;
-
-        public AThread() {
-            super("ActivityManager");
-        }
-
-        @Override
-        public void run() {
-            Looper.prepare();
-
-            android.os.Process.setThreadPriority(
-                    android.os.Process.THREAD_PRIORITY_FOREGROUND);
-            android.os.Process.setCanSelfBackground(false);
-
-            ActivityManagerService m = new ActivityManagerService();
-
-            synchronized (this) {
-                mService = m;
-                mLooper = Looper.myLooper();
-                Watchdog.getInstance().addThread(new Handler(mLooper), getName());
-                notifyAll();
-            }
-
-            synchronized (this) {
-                while (!mReady) {
-                    try {
-                        wait();
-                    } catch (InterruptedException e) {
-                    }
-                }
-            }
-
-            // For debug builds, log event loop stalls to dropbox for analysis.
-            if (StrictMode.conditionallyEnableDebugLogging()) {
-                Slog.i(TAG, "Enabled StrictMode logging for AThread's Looper");
-            }
-
-            Looper.loop();
-        }
-    }
-
-    static class MemBinder extends Binder {
-        ActivityManagerService mActivityManagerService;
-        MemBinder(ActivityManagerService activityManagerService) {
-            mActivityManagerService = activityManagerService;
-        }
-
-        @Override
-        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
-                    != PackageManager.PERMISSION_GRANTED) {
-                pw.println("Permission Denial: can't dump meminfo from from pid="
-                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
-                        + " without permission " + android.Manifest.permission.DUMP);
-                return;
-            }
-
-            mActivityManagerService.dumpApplicationMemoryUsage(fd, pw, "  ", args, false, null);
-        }
-    }
-
-    static class GraphicsBinder extends Binder {
-        ActivityManagerService mActivityManagerService;
-        GraphicsBinder(ActivityManagerService activityManagerService) {
-            mActivityManagerService = activityManagerService;
-        }
-
-        @Override
-        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
-                    != PackageManager.PERMISSION_GRANTED) {
-                pw.println("Permission Denial: can't dump gfxinfo from from pid="
-                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
-                        + " without permission " + android.Manifest.permission.DUMP);
-                return;
-            }
-
-            mActivityManagerService.dumpGraphicsHardwareUsage(fd, pw, args);
-        }
-    }
-
-    static class DbBinder extends Binder {
-        ActivityManagerService mActivityManagerService;
-        DbBinder(ActivityManagerService activityManagerService) {
-            mActivityManagerService = activityManagerService;
-        }
-
-        @Override
-        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
-                    != PackageManager.PERMISSION_GRANTED) {
-                pw.println("Permission Denial: can't dump dbinfo from from pid="
-                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
-                        + " without permission " + android.Manifest.permission.DUMP);
-                return;
-            }
-
-            mActivityManagerService.dumpDbInfo(fd, pw, args);
-        }
-    }
-
-    static class CpuBinder extends Binder {
-        ActivityManagerService mActivityManagerService;
-        CpuBinder(ActivityManagerService activityManagerService) {
-            mActivityManagerService = activityManagerService;
-        }
-
-        @Override
-        protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-            if (mActivityManagerService.checkCallingPermission(android.Manifest.permission.DUMP)
-                    != PackageManager.PERMISSION_GRANTED) {
-                pw.println("Permission Denial: can't dump cpuinfo from from pid="
-                        + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
-                        + " without permission " + android.Manifest.permission.DUMP);
-                return;
-            }
-
-            synchronized (mActivityManagerService.mProcessCpuThread) {
-                pw.print(mActivityManagerService.mProcessCpuTracker.printCurrentLoad());
-                pw.print(mActivityManagerService.mProcessCpuTracker.printCurrentState(
-                        SystemClock.uptimeMillis()));
-            }
-        }
-    }
-
-    private ActivityManagerService() {
-        Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());
-
-        mFgBroadcastQueue = new BroadcastQueue(this, "foreground", BROADCAST_FG_TIMEOUT, false);
-        mBgBroadcastQueue = new BroadcastQueue(this, "background", BROADCAST_BG_TIMEOUT, true);
-        mBroadcastQueues[0] = mFgBroadcastQueue;
-        mBroadcastQueues[1] = mBgBroadcastQueue;
-
-        mServices = new ActiveServices(this);
-        mProviderMap = new ProviderMap(this);
-
-        File dataDir = Environment.getDataDirectory();
-        File systemDir = new File(dataDir, "system");
-        systemDir.mkdirs();
-        mBatteryStatsService = new BatteryStatsService(new File(
-                systemDir, "batterystats.bin").toString());
-        mBatteryStatsService.getActiveStatistics().readLocked();
-        mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
-        mOnBattery = DEBUG_POWER ? true
-                : mBatteryStatsService.getActiveStatistics().getIsOnBattery();
-        mBatteryStatsService.getActiveStatistics().setCallback(this);
-
-        mProcessStats = new ProcessStatsService(this, new File(systemDir, "procstats"));
-
-        mUsageStatsService = new UsageStatsService(new File(systemDir, "usagestats").toString());
-        mAppOpsService = new AppOpsService(new File(systemDir, "appops.xml"));
-
-        mGrantFile = new AtomicFile(new File(systemDir, "urigrants.xml"));
-
-        mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
-
-        // User 0 is the first and only user that runs at boot.
-        mStartedUsers.put(0, new UserStartedState(new UserHandle(0), true));
-        mUserLru.add(Integer.valueOf(0));
-        updateStartedUserArrayLocked();
-
-        GL_ES_VERSION = SystemProperties.getInt("ro.opengles.version",
-            ConfigurationInfo.GL_ES_VERSION_UNDEFINED);
-
-        mConfiguration.setToDefaults();
-        mConfiguration.setLocale(Locale.getDefault());
-
-        mConfigurationSeq = mConfiguration.seq = 1;
-        mProcessCpuTracker.init();
-
-        mCompatModePackages = new CompatModePackages(this, systemDir);
-
-        // Add ourself to the Watchdog monitors.
-        Watchdog.getInstance().addMonitor(this);
-
-        mProcessCpuThread = new Thread("CpuTracker") {
-            @Override
-            public void run() {
-                while (true) {
-                    try {
-                        try {
-                            synchronized(this) {
-                                final long now = SystemClock.uptimeMillis();
-                                long nextCpuDelay = (mLastCpuTime.get()+MONITOR_CPU_MAX_TIME)-now;
-                                long nextWriteDelay = (mLastWriteTime+BATTERY_STATS_TIME)-now;
-                                //Slog.i(TAG, "Cpu delay=" + nextCpuDelay
-                                //        + ", write delay=" + nextWriteDelay);
-                                if (nextWriteDelay < nextCpuDelay) {
-                                    nextCpuDelay = nextWriteDelay;
-                                }
-                                if (nextCpuDelay > 0) {
-                                    mProcessCpuMutexFree.set(true);
-                                    this.wait(nextCpuDelay);
-                                }
-                            }
-                        } catch (InterruptedException e) {
-                        }
-                        updateCpuStatsNow();
-                    } catch (Exception e) {
-                        Slog.e(TAG, "Unexpected exception collecting process stats", e);
-                    }
-                }
-            }
-        };
-        mProcessCpuThread.start();
-    }
-
-    @Override
-    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
-            throws RemoteException {
-        if (code == SYSPROPS_TRANSACTION) {
-            // We need to tell all apps about the system property change.
-            ArrayList<IBinder> procs = new ArrayList<IBinder>();
-            synchronized(this) {
-                final int NP = mProcessNames.getMap().size();
-                for (int ip=0; ip<NP; ip++) {
-                    SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
-                    final int NA = apps.size();
-                    for (int ia=0; ia<NA; ia++) {
-                        ProcessRecord app = apps.valueAt(ia);
-                        if (app.thread != null) {
-                            procs.add(app.thread.asBinder());
-                        }
-                    }
-                }
-            }
-
-            int N = procs.size();
-            for (int i=0; i<N; i++) {
-                Parcel data2 = Parcel.obtain();
-                try {
-                    procs.get(i).transact(IBinder.SYSPROPS_TRANSACTION, data2, null, 0);
-                } catch (RemoteException e) {
-                }
-                data2.recycle();
-            }
-        }
-        try {
-            return super.onTransact(code, data, reply, flags);
-        } catch (RuntimeException e) {
-            // The activity manager only throws security exceptions, so let's
-            // log all others.
-            if (!(e instanceof SecurityException)) {
-                Slog.wtf(TAG, "Activity Manager Crash", e);
-            }
-            throw e;
-        }
-    }
-
-    void updateCpuStats() {
-        final long now = SystemClock.uptimeMillis();
-        if (mLastCpuTime.get() >= now - MONITOR_CPU_MIN_TIME) {
-            return;
-        }
-        if (mProcessCpuMutexFree.compareAndSet(true, false)) {
-            synchronized (mProcessCpuThread) {
-                mProcessCpuThread.notify();
-            }
-        }
-    }
-
-    void updateCpuStatsNow() {
-        synchronized (mProcessCpuThread) {
-            mProcessCpuMutexFree.set(false);
-            final long now = SystemClock.uptimeMillis();
-            boolean haveNewCpuStats = false;
-
-            if (MONITOR_CPU_USAGE &&
-                    mLastCpuTime.get() < (now-MONITOR_CPU_MIN_TIME)) {
-                mLastCpuTime.set(now);
-                haveNewCpuStats = true;
-                mProcessCpuTracker.update();
-                //Slog.i(TAG, mProcessCpu.printCurrentState());
-                //Slog.i(TAG, "Total CPU usage: "
-                //        + mProcessCpu.getTotalCpuPercent() + "%");
-
-                // Slog the cpu usage if the property is set.
-                if ("true".equals(SystemProperties.get("events.cpu"))) {
-                    int user = mProcessCpuTracker.getLastUserTime();
-                    int system = mProcessCpuTracker.getLastSystemTime();
-                    int iowait = mProcessCpuTracker.getLastIoWaitTime();
-                    int irq = mProcessCpuTracker.getLastIrqTime();
-                    int softIrq = mProcessCpuTracker.getLastSoftIrqTime();
-                    int idle = mProcessCpuTracker.getLastIdleTime();
-
-                    int total = user + system + iowait + irq + softIrq + idle;
-                    if (total == 0) total = 1;
-
-                    EventLog.writeEvent(EventLogTags.CPU,
-                            ((user+system+iowait+irq+softIrq) * 100) / total,
-                            (user * 100) / total,
-                            (system * 100) / total,
-                            (iowait * 100) / total,
-                            (irq * 100) / total,
-                            (softIrq * 100) / total);
-                }
-            }
-
-            long[] cpuSpeedTimes = mProcessCpuTracker.getLastCpuSpeedTimes();
-            final BatteryStatsImpl bstats = mBatteryStatsService.getActiveStatistics();
-            synchronized(bstats) {
-                synchronized(mPidsSelfLocked) {
-                    if (haveNewCpuStats) {
-                        if (mOnBattery) {
-                            int perc = bstats.startAddingCpuLocked();
-                            int totalUTime = 0;
-                            int totalSTime = 0;
-                            final int N = mProcessCpuTracker.countStats();
-                            for (int i=0; i<N; i++) {
-                                ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
-                                if (!st.working) {
-                                    continue;
-                                }
-                                ProcessRecord pr = mPidsSelfLocked.get(st.pid);
-                                int otherUTime = (st.rel_utime*perc)/100;
-                                int otherSTime = (st.rel_stime*perc)/100;
-                                totalUTime += otherUTime;
-                                totalSTime += otherSTime;
-                                if (pr != null) {
-                                    BatteryStatsImpl.Uid.Proc ps = bstats.getProcessStatsLocked(
-                                            st.name, st.pid);
-                                    ps.addCpuTimeLocked(st.rel_utime-otherUTime,
-                                            st.rel_stime-otherSTime);
-                                    ps.addSpeedStepTimes(cpuSpeedTimes);
-                                    pr.curCpuTime += (st.rel_utime+st.rel_stime) * 10;
-                                } else if (st.uid >= Process.FIRST_APPLICATION_UID) {
-                                    BatteryStatsImpl.Uid.Proc ps = st.batteryStats;
-                                    if (ps == null) {
-                                        st.batteryStats = ps = bstats.getProcessStatsLocked(st.uid,
-                                                "(Unknown)");
-                                    }
-                                    ps.addCpuTimeLocked(st.rel_utime-otherUTime,
-                                            st.rel_stime-otherSTime);
-                                    ps.addSpeedStepTimes(cpuSpeedTimes);
-                                } else {
-                                    BatteryStatsImpl.Uid.Proc ps =
-                                            bstats.getProcessStatsLocked(st.name, st.pid);
-                                    if (ps != null) {
-                                        ps.addCpuTimeLocked(st.rel_utime-otherUTime,
-                                                st.rel_stime-otherSTime);
-                                        ps.addSpeedStepTimes(cpuSpeedTimes);
-                                    }
-                                }
-                            }
-                            bstats.finishAddingCpuLocked(perc, totalUTime,
-                                    totalSTime, cpuSpeedTimes);
-                        }
-                    }
-                }
-
-                if (mLastWriteTime < (now-BATTERY_STATS_TIME)) {
-                    mLastWriteTime = now;
-                    mBatteryStatsService.getActiveStatistics().writeAsyncLocked();
-                }
-            }
-        }
-    }
-
-    @Override
-    public void batteryNeedsCpuUpdate() {
-        updateCpuStatsNow();
-    }
-
-    @Override
-    public void batteryPowerChanged(boolean onBattery) {
-        // When plugging in, update the CPU stats first before changing
-        // the plug state.
-        updateCpuStatsNow();
-        synchronized (this) {
-            synchronized(mPidsSelfLocked) {
-                mOnBattery = DEBUG_POWER ? true : onBattery;
-            }
-        }
-    }
-
-    /**
-     * Initialize the application bind args. These are passed to each
-     * process when the bindApplication() IPC is sent to the process. They're
-     * lazily setup to make sure the services are running when they're asked for.
-     */
-    private HashMap<String, IBinder> getCommonServicesLocked() {
-        if (mAppBindArgs == null) {
-            mAppBindArgs = new HashMap<String, IBinder>();
-
-            // Setup the application init args
-            mAppBindArgs.put("package", ServiceManager.getService("package"));
-            mAppBindArgs.put("window", ServiceManager.getService("window"));
-            mAppBindArgs.put(Context.ALARM_SERVICE,
-                    ServiceManager.getService(Context.ALARM_SERVICE));
-        }
-        return mAppBindArgs;
-    }
-
-    final void setFocusedActivityLocked(ActivityRecord r) {
-        if (mFocusedActivity != r) {
-            if (DEBUG_FOCUS) Slog.d(TAG, "setFocusedActivityLocked: r=" + r);
-            mFocusedActivity = r;
-            mStackSupervisor.setFocusedStack(r);
-            if (r != null) {
-                mWindowManager.setFocusedApp(r.appToken, true);
-            }
-            applyUpdateLockStateLocked(r);
-        }
-    }
-
-    @Override
-    public void setFocusedStack(int stackId) {
-        if (DEBUG_FOCUS) Slog.d(TAG, "setFocusedStack: stackId=" + stackId);
-        synchronized (ActivityManagerService.this) {
-            ActivityStack stack = mStackSupervisor.getStack(stackId);
-            if (stack != null) {
-                ActivityRecord r = stack.topRunningActivityLocked(null);
-                if (r != null) {
-                    setFocusedActivityLocked(r);
-                }
-            }
-        }
-    }
-
-    @Override
-    public void notifyActivityDrawn(IBinder token) {
-        if (DEBUG_VISBILITY) Slog.d(TAG, "notifyActivityDrawn: token=" + token);
-        synchronized (this) {
-            ActivityRecord r= mStackSupervisor.isInAnyStackLocked(token);
-            if (r != null) {
-                r.task.stack.notifyActivityDrawnLocked(r);
-            }
-        }
-    }
-
-    final void applyUpdateLockStateLocked(ActivityRecord r) {
-        // Modifications to the UpdateLock state are done on our handler, outside
-        // the activity manager's locks.  The new state is determined based on the
-        // state *now* of the relevant activity record.  The object is passed to
-        // the handler solely for logging detail, not to be consulted/modified.
-        final boolean nextState = r != null && r.immersive;
-        mHandler.sendMessage(
-                mHandler.obtainMessage(IMMERSIVE_MODE_LOCK_MSG, (nextState) ? 1 : 0, 0, r));
-    }
-
-    final void showAskCompatModeDialogLocked(ActivityRecord r) {
-        Message msg = Message.obtain();
-        msg.what = SHOW_COMPAT_MODE_DIALOG_MSG;
-        msg.obj = r.task.askedCompatMode ? null : r;
-        mHandler.sendMessage(msg);
-    }
-
-    private final int updateLruProcessInternalLocked(ProcessRecord app, long now, int index,
-            String what, Object obj, ProcessRecord srcApp) {
-        app.lastActivityTime = now;
-
-        if (app.activities.size() > 0) {
-            // Don't want to touch dependent processes that are hosting activities.
-            return index;
-        }
-
-        int lrui = mLruProcesses.lastIndexOf(app);
-        if (lrui < 0) {
-            Slog.wtf(TAG, "Adding dependent process " + app + " not on LRU list: "
-                    + what + " " + obj + " from " + srcApp);
-            return index;
-        }
-
-        if (lrui >= index) {
-            // Don't want to cause this to move dependent processes *back* in the
-            // list as if they were less frequently used.
-            return index;
-        }
-
-        if (lrui >= mLruProcessActivityStart) {
-            // Don't want to touch dependent processes that are hosting activities.
-            return index;
-        }
-
-        mLruProcesses.remove(lrui);
-        if (index > 0) {
-            index--;
-        }
-        if (DEBUG_LRU) Slog.d(TAG, "Moving dep from " + lrui + " to " + index
-                + " in LRU list: " + app);
-        mLruProcesses.add(index, app);
-        return index;
-    }
-
-    final void removeLruProcessLocked(ProcessRecord app) {
-        int lrui = mLruProcesses.lastIndexOf(app);
-        if (lrui >= 0) {
-            if (lrui <= mLruProcessActivityStart) {
-                mLruProcessActivityStart--;
-            }
-            if (lrui <= mLruProcessServiceStart) {
-                mLruProcessServiceStart--;
-            }
-            mLruProcesses.remove(lrui);
-        }
-    }
-
-    final void updateLruProcessLocked(ProcessRecord app, boolean activityChange,
-            ProcessRecord client) {
-        final boolean hasActivity = app.activities.size() > 0 || app.hasClientActivities;
-        final boolean hasService = false; // not impl yet. app.services.size() > 0;
-        if (!activityChange && hasActivity) {
-            // The process has activties, so we are only going to allow activity-based
-            // adjustments move it.  It should be kept in the front of the list with other
-            // processes that have activities, and we don't want those to change their
-            // order except due to activity operations.
-            return;
-        }
-
-        mLruSeq++;
-        final long now = SystemClock.uptimeMillis();
-        app.lastActivityTime = now;
-
-        // First a quick reject: if the app is already at the position we will
-        // put it, then there is nothing to do.
-        if (hasActivity) {
-            final int N = mLruProcesses.size();
-            if (N > 0 && mLruProcesses.get(N-1) == app) {
-                if (DEBUG_LRU) Slog.d(TAG, "Not moving, already top activity: " + app);
-                return;
-            }
-        } else {
-            if (mLruProcessServiceStart > 0
-                    && mLruProcesses.get(mLruProcessServiceStart-1) == app) {
-                if (DEBUG_LRU) Slog.d(TAG, "Not moving, already top other: " + app);
-                return;
-            }
-        }
-
-        int lrui = mLruProcesses.lastIndexOf(app);
-
-        if (app.persistent && lrui >= 0) {
-            // We don't care about the position of persistent processes, as long as
-            // they are in the list.
-            if (DEBUG_LRU) Slog.d(TAG, "Not moving, persistent: " + app);
-            return;
-        }
-
-        /* In progress: compute new position first, so we can avoid doing work
-           if the process is not actually going to move.  Not yet working.
-        int addIndex;
-        int nextIndex;
-        boolean inActivity = false, inService = false;
-        if (hasActivity) {
-            // Process has activities, put it at the very tipsy-top.
-            addIndex = mLruProcesses.size();
-            nextIndex = mLruProcessServiceStart;
-            inActivity = true;
-        } else if (hasService) {
-            // Process has services, put it at the top of the service list.
-            addIndex = mLruProcessActivityStart;
-            nextIndex = mLruProcessServiceStart;
-            inActivity = true;
-            inService = true;
-        } else  {
-            // Process not otherwise of interest, it goes to the top of the non-service area.
-            addIndex = mLruProcessServiceStart;
-            if (client != null) {
-                int clientIndex = mLruProcesses.lastIndexOf(client);
-                if (clientIndex < 0) Slog.d(TAG, "Unknown client " + client + " when updating "
-                        + app);
-                if (clientIndex >= 0 && addIndex > clientIndex) {
-                    addIndex = clientIndex;
-                }
-            }
-            nextIndex = addIndex > 0 ? addIndex-1 : addIndex;
-        }
-
-        Slog.d(TAG, "Update LRU at " + lrui + " to " + addIndex + " (act="
-                + mLruProcessActivityStart + "): " + app);
-        */
-
-        if (lrui >= 0) {
-            if (lrui < mLruProcessActivityStart) {
-                mLruProcessActivityStart--;
-            }
-            if (lrui < mLruProcessServiceStart) {
-                mLruProcessServiceStart--;
-            }
-            /*
-            if (addIndex > lrui) {
-                addIndex--;
-            }
-            if (nextIndex > lrui) {
-                nextIndex--;
-            }
-            */
-            mLruProcesses.remove(lrui);
-        }
-
-        /*
-        mLruProcesses.add(addIndex, app);
-        if (inActivity) {
-            mLruProcessActivityStart++;
-        }
-        if (inService) {
-            mLruProcessActivityStart++;
-        }
-        */
-
-        int nextIndex;
-        if (hasActivity) {
-            final int N = mLruProcesses.size();
-            if (app.activities.size() == 0 && mLruProcessActivityStart < (N-1)) {
-                // Process doesn't have activities, but has clients with
-                // activities...  move it up, but one below the top (the top
-                // should always have a real activity).
-                if (DEBUG_LRU) Slog.d(TAG, "Adding to second-top of LRU activity list: " + app);
-                mLruProcesses.add(N-1, app);
-                // To keep it from spamming the LRU list (by making a bunch of clients),
-                // we will push down any other entries owned by the app.
-                final int uid = app.info.uid;
-                for (int i=N-2; i>mLruProcessActivityStart; i--) {
-                    ProcessRecord subProc = mLruProcesses.get(i);
-                    if (subProc.info.uid == uid) {
-                        // We want to push this one down the list.  If the process after
-                        // it is for the same uid, however, don't do so, because we don't
-                        // want them internally to be re-ordered.
-                        if (mLruProcesses.get(i-1).info.uid != uid) {
-                            if (DEBUG_LRU) Slog.d(TAG, "Pushing uid " + uid + " swapping at " + i
-                                    + ": " + mLruProcesses.get(i) + " : " + mLruProcesses.get(i-1));
-                            ProcessRecord tmp = mLruProcesses.get(i);
-                            mLruProcesses.set(i, mLruProcesses.get(i-1));
-                            mLruProcesses.set(i-1, tmp);
-                            i--;
-                        }
-                    } else {
-                        // A gap, we can stop here.
-                        break;
-                    }
-                }
-            } else {
-                // Process has activities, put it at the very tipsy-top.
-                if (DEBUG_LRU) Slog.d(TAG, "Adding to top of LRU activity list: " + app);
-                mLruProcesses.add(app);
-            }
-            nextIndex = mLruProcessServiceStart;
-        } else if (hasService) {
-            // Process has services, put it at the top of the service list.
-            if (DEBUG_LRU) Slog.d(TAG, "Adding to top of LRU service list: " + app);
-            mLruProcesses.add(mLruProcessActivityStart, app);
-            nextIndex = mLruProcessServiceStart;
-            mLruProcessActivityStart++;
-        } else  {
-            // Process not otherwise of interest, it goes to the top of the non-service area.
-            int index = mLruProcessServiceStart;
-            if (client != null) {
-                // If there is a client, don't allow the process to be moved up higher
-                // in the list than that client.
-                int clientIndex = mLruProcesses.lastIndexOf(client);
-                if (DEBUG_LRU && clientIndex < 0) Slog.d(TAG, "Unknown client " + client
-                        + " when updating " + app);
-                if (clientIndex <= lrui) {
-                    // Don't allow the client index restriction to push it down farther in the
-                    // list than it already is.
-                    clientIndex = lrui;
-                }
-                if (clientIndex >= 0 && index > clientIndex) {
-                    index = clientIndex;
-                }
-            }
-            if (DEBUG_LRU) Slog.d(TAG, "Adding at " + index + " of LRU list: " + app);
-            mLruProcesses.add(index, app);
-            nextIndex = index-1;
-            mLruProcessActivityStart++;
-            mLruProcessServiceStart++;
-        }
-
-        // If the app is currently using a content provider or service,
-        // bump those processes as well.
-        for (int j=app.connections.size()-1; j>=0; j--) {
-            ConnectionRecord cr = app.connections.valueAt(j);
-            if (cr.binding != null && !cr.serviceDead && cr.binding.service != null
-                    && cr.binding.service.app != null
-                    && cr.binding.service.app.lruSeq != mLruSeq
-                    && !cr.binding.service.app.persistent) {
-                nextIndex = updateLruProcessInternalLocked(cr.binding.service.app, now, nextIndex,
-                        "service connection", cr, app);
-            }
-        }
-        for (int j=app.conProviders.size()-1; j>=0; j--) {
-            ContentProviderRecord cpr = app.conProviders.get(j).provider;
-            if (cpr.proc != null && cpr.proc.lruSeq != mLruSeq && !cpr.proc.persistent) {
-                nextIndex = updateLruProcessInternalLocked(cpr.proc, now, nextIndex,
-                        "provider reference", cpr, app);
-            }
-        }
-    }
-
-    final ProcessRecord getProcessRecordLocked(String processName, int uid, boolean keepIfLarge) {
-        if (uid == Process.SYSTEM_UID) {
-            // The system gets to run in any process.  If there are multiple
-            // processes with the same uid, just pick the first (this
-            // should never happen).
-            SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(processName);
-            if (procs == null) return null;
-            final int N = procs.size();
-            for (int i = 0; i < N; i++) {
-                if (UserHandle.isSameUser(procs.keyAt(i), uid)) return procs.valueAt(i);
-            }
-        }
-        ProcessRecord proc = mProcessNames.get(processName, uid);
-        if (false && proc != null && !keepIfLarge
-                && proc.setProcState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY
-                && proc.lastCachedPss >= 4000) {
-            // Turn this condition on to cause killing to happen regularly, for testing.
-            if (proc.baseProcessTracker != null) {
-                proc.baseProcessTracker.reportCachedKill(proc.pkgList, proc.lastCachedPss);
-            }
-            killUnneededProcessLocked(proc, Long.toString(proc.lastCachedPss)
-                    + "k from cached");
-        } else if (proc != null && !keepIfLarge
-                && mLastMemoryLevel > ProcessStats.ADJ_MEM_FACTOR_NORMAL
-                && proc.setProcState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY) {
-            if (DEBUG_PSS) Slog.d(TAG, "May not keep " + proc + ": pss=" + proc.lastCachedPss);
-            if (proc.lastCachedPss >= mProcessList.getCachedRestoreThresholdKb()) {
-                if (proc.baseProcessTracker != null) {
-                    proc.baseProcessTracker.reportCachedKill(proc.pkgList, proc.lastCachedPss);
-                }
-                killUnneededProcessLocked(proc, Long.toString(proc.lastCachedPss)
-                        + "k from cached");
-            }
-        }
-        return proc;
-    }
-
-    void ensurePackageDexOpt(String packageName) {
-        IPackageManager pm = AppGlobals.getPackageManager();
-        try {
-            if (pm.performDexOpt(packageName)) {
-                mDidDexOpt = true;
-            }
-        } catch (RemoteException e) {
-        }
-    }
-
-    boolean isNextTransitionForward() {
-        int transit = mWindowManager.getPendingAppTransition();
-        return transit == AppTransition.TRANSIT_ACTIVITY_OPEN
-                || transit == AppTransition.TRANSIT_TASK_OPEN
-                || transit == AppTransition.TRANSIT_TASK_TO_FRONT;
-    }
-
-    final ProcessRecord startProcessLocked(String processName,
-            ApplicationInfo info, boolean knownToBeDead, int intentFlags,
-            String hostingType, ComponentName hostingName, boolean allowWhileBooting,
-            boolean isolated, boolean keepIfLarge) {
-        ProcessRecord app;
-        if (!isolated) {
-            app = getProcessRecordLocked(processName, info.uid, keepIfLarge);
-        } else {
-            // If this is an isolated process, it can't re-use an existing process.
-            app = null;
-        }
-        // We don't have to do anything more if:
-        // (1) There is an existing application record; and
-        // (2) The caller doesn't think it is dead, OR there is no thread
-        //     object attached to it so we know it couldn't have crashed; and
-        // (3) There is a pid assigned to it, so it is either starting or
-        //     already running.
-        if (DEBUG_PROCESSES) Slog.v(TAG, "startProcess: name=" + processName
-                + " app=" + app + " knownToBeDead=" + knownToBeDead
-                + " thread=" + (app != null ? app.thread : null)
-                + " pid=" + (app != null ? app.pid : -1));
-        if (app != null && app.pid > 0) {
-            if (!knownToBeDead || app.thread == null) {
-                // We already have the app running, or are waiting for it to
-                // come up (we have a pid but not yet its thread), so keep it.
-                if (DEBUG_PROCESSES) Slog.v(TAG, "App already running: " + app);
-                // If this is a new package in the process, add the package to the list
-                app.addPackage(info.packageName, mProcessStats);
-                return app;
-            }
-
-            // An application record is attached to a previous process,
-            // clean it up now.
-            if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG, "App died: " + app);
-            handleAppDiedLocked(app, true, true);
-        }
-
-        String hostingNameStr = hostingName != null
-                ? hostingName.flattenToShortString() : null;
-
-        if (!isolated) {
-            if ((intentFlags&Intent.FLAG_FROM_BACKGROUND) != 0) {
-                // If we are in the background, then check to see if this process
-                // is bad.  If so, we will just silently fail.
-                if (mBadProcesses.get(info.processName, info.uid) != null) {
-                    if (DEBUG_PROCESSES) Slog.v(TAG, "Bad process: " + info.uid
-                            + "/" + info.processName);
-                    return null;
-                }
-            } else {
-                // When the user is explicitly starting a process, then clear its
-                // crash count so that we won't make it bad until they see at
-                // least one crash dialog again, and make the process good again
-                // if it had been bad.
-                if (DEBUG_PROCESSES) Slog.v(TAG, "Clearing bad process: " + info.uid
-                        + "/" + info.processName);
-                mProcessCrashTimes.remove(info.processName, info.uid);
-                if (mBadProcesses.get(info.processName, info.uid) != null) {
-                    EventLog.writeEvent(EventLogTags.AM_PROC_GOOD,
-                            UserHandle.getUserId(info.uid), info.uid,
-                            info.processName);
-                    mBadProcesses.remove(info.processName, info.uid);
-                    if (app != null) {
-                        app.bad = false;
-                    }
-                }
-            }
-        }
-
-        if (app == null) {
-            app = newProcessRecordLocked(info, processName, isolated);
-            if (app == null) {
-                Slog.w(TAG, "Failed making new process record for "
-                        + processName + "/" + info.uid + " isolated=" + isolated);
-                return null;
-            }
-            mProcessNames.put(processName, app.uid, app);
-            if (isolated) {
-                mIsolatedProcesses.put(app.uid, app);
-            }
-        } else {
-            // If this is a new package in the process, add the package to the list
-            app.addPackage(info.packageName, mProcessStats);
-        }
-
-        // If the system is not ready yet, then hold off on starting this
-        // process until it is.
-        if (!mProcessesReady
-                && !isAllowedWhileBooting(info)
-                && !allowWhileBooting) {
-            if (!mProcessesOnHold.contains(app)) {
-                mProcessesOnHold.add(app);
-            }
-            if (DEBUG_PROCESSES) Slog.v(TAG, "System not ready, putting on hold: " + app);
-            return app;
-        }
-
-        startProcessLocked(app, hostingType, hostingNameStr);
-        return (app.pid != 0) ? app : null;
-    }
-
-    boolean isAllowedWhileBooting(ApplicationInfo ai) {
-        return (ai.flags&ApplicationInfo.FLAG_PERSISTENT) != 0;
-    }
-
-    private final void startProcessLocked(ProcessRecord app,
-            String hostingType, String hostingNameStr) {
-        if (app.pid > 0 && app.pid != MY_PID) {
-            synchronized (mPidsSelfLocked) {
-                mPidsSelfLocked.remove(app.pid);
-                mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
-            }
-            app.setPid(0);
-        }
-
-        if (DEBUG_PROCESSES && mProcessesOnHold.contains(app)) Slog.v(TAG,
-                "startProcessLocked removing on hold: " + app);
-        mProcessesOnHold.remove(app);
-
-        updateCpuStats();
-
-        try {
-            int uid = app.uid;
-
-            int[] gids = null;
-            int mountExternal = Zygote.MOUNT_EXTERNAL_NONE;
-            if (!app.isolated) {
-                int[] permGids = null;
-                try {
-                    final PackageManager pm = mContext.getPackageManager();
-                    permGids = pm.getPackageGids(app.info.packageName);
-
-                    if (Environment.isExternalStorageEmulated()) {
-                        if (pm.checkPermission(
-                                android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
-                                app.info.packageName) == PERMISSION_GRANTED) {
-                            mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER_ALL;
-                        } else {
-                            mountExternal = Zygote.MOUNT_EXTERNAL_MULTIUSER;
-                        }
-                    }
-                } catch (PackageManager.NameNotFoundException e) {
-                    Slog.w(TAG, "Unable to retrieve gids", e);
-                }
-
-                /*
-                 * Add shared application GID so applications can share some
-                 * resources like shared libraries
-                 */
-                if (permGids == null) {
-                    gids = new int[1];
-                } else {
-                    gids = new int[permGids.length + 1];
-                    System.arraycopy(permGids, 0, gids, 1, permGids.length);
-                }
-                gids[0] = UserHandle.getSharedAppGid(UserHandle.getAppId(uid));
-            }
-            if (mFactoryTest != SystemServer.FACTORY_TEST_OFF) {
-                if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL
-                        && mTopComponent != null
-                        && app.processName.equals(mTopComponent.getPackageName())) {
-                    uid = 0;
-                }
-                if (mFactoryTest == SystemServer.FACTORY_TEST_HIGH_LEVEL
-                        && (app.info.flags&ApplicationInfo.FLAG_FACTORY_TEST) != 0) {
-                    uid = 0;
-                }
-            }
-            int debugFlags = 0;
-            if ((app.info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
-                debugFlags |= Zygote.DEBUG_ENABLE_DEBUGGER;
-                // Also turn on CheckJNI for debuggable apps. It's quite
-                // awkward to turn on otherwise.
-                debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
-            }
-            // Run the app in safe mode if its manifest requests so or the
-            // system is booted in safe mode.
-            if ((app.info.flags & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0 ||
-                Zygote.systemInSafeMode == true) {
-                debugFlags |= Zygote.DEBUG_ENABLE_SAFEMODE;
-            }
-            if ("1".equals(SystemProperties.get("debug.checkjni"))) {
-                debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI;
-            }
-            if ("1".equals(SystemProperties.get("debug.jni.logging"))) {
-                debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING;
-            }
-            if ("1".equals(SystemProperties.get("debug.assert"))) {
-                debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
-            }
-
-            // Start the process.  It will either succeed and return a result containing
-            // the PID of the new process, or else throw a RuntimeException.
-            Process.ProcessStartResult startResult = Process.start("android.app.ActivityThread",
-                    app.processName, uid, uid, gids, debugFlags, mountExternal,
-                    app.info.targetSdkVersion, app.info.seinfo, null);
-
-            BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics();
-            synchronized (bs) {
-                if (bs.isOnBattery()) {
-                    bs.getProcessStatsLocked(app.uid, app.processName).incStartsLocked();
-                }
-            }
-
-            EventLog.writeEvent(EventLogTags.AM_PROC_START,
-                    UserHandle.getUserId(uid), startResult.pid, uid,
-                    app.processName, hostingType,
-                    hostingNameStr != null ? hostingNameStr : "");
-
-            if (app.persistent) {
-                Watchdog.getInstance().processStarted(app.processName, startResult.pid);
-            }
-
-            StringBuilder buf = mStringBuilder;
-            buf.setLength(0);
-            buf.append("Start proc ");
-            buf.append(app.processName);
-            buf.append(" for ");
-            buf.append(hostingType);
-            if (hostingNameStr != null) {
-                buf.append(" ");
-                buf.append(hostingNameStr);
-            }
-            buf.append(": pid=");
-            buf.append(startResult.pid);
-            buf.append(" uid=");
-            buf.append(uid);
-            buf.append(" gids={");
-            if (gids != null) {
-                for (int gi=0; gi<gids.length; gi++) {
-                    if (gi != 0) buf.append(", ");
-                    buf.append(gids[gi]);
-
-                }
-            }
-            buf.append("}");
-            Slog.i(TAG, buf.toString());
-            app.setPid(startResult.pid);
-            app.usingWrapper = startResult.usingWrapper;
-            app.removed = false;
-            synchronized (mPidsSelfLocked) {
-                this.mPidsSelfLocked.put(startResult.pid, app);
-                Message msg = mHandler.obtainMessage(PROC_START_TIMEOUT_MSG);
-                msg.obj = app;
-                mHandler.sendMessageDelayed(msg, startResult.usingWrapper
-                        ? PROC_START_TIMEOUT_WITH_WRAPPER : PROC_START_TIMEOUT);
-            }
-        } catch (RuntimeException e) {
-            // XXX do better error recovery.
-            app.setPid(0);
-            Slog.e(TAG, "Failure starting process " + app.processName, e);
-        }
-    }
-
-    void updateUsageStats(ActivityRecord component, boolean resumed) {
-        if (DEBUG_SWITCH) Slog.d(TAG, "updateUsageStats: comp=" + component + "res=" + resumed);
-        final BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-        if (resumed) {
-            mUsageStatsService.noteResumeComponent(component.realActivity);
-            synchronized (stats) {
-                stats.noteActivityResumedLocked(component.app.uid);
-            }
-        } else {
-            mUsageStatsService.notePauseComponent(component.realActivity);
-            synchronized (stats) {
-                stats.noteActivityPausedLocked(component.app.uid);
-            }
-        }
-    }
-
-    Intent getHomeIntent() {
-        Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null);
-        intent.setComponent(mTopComponent);
-        if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
-            intent.addCategory(Intent.CATEGORY_HOME);
-        }
-        return intent;
-    }
-
-    boolean startHomeActivityLocked(int userId) {
-        if (mHeadless) {
-            // Added because none of the other calls to ensureBootCompleted seem to fire
-            // when running headless.
-            ensureBootCompleted();
-            return false;
-        }
-
-        if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL
-                && mTopAction == null) {
-            // We are running in factory test mode, but unable to find
-            // the factory test app, so just sit around displaying the
-            // error message and don't try to start anything.
-            return false;
-        }
-        Intent intent = getHomeIntent();
-        ActivityInfo aInfo =
-            resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
-        if (aInfo != null) {
-            intent.setComponent(new ComponentName(
-                    aInfo.applicationInfo.packageName, aInfo.name));
-            // Don't do this if the home app is currently being
-            // instrumented.
-            aInfo = new ActivityInfo(aInfo);
-            aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);
-            ProcessRecord app = getProcessRecordLocked(aInfo.processName,
-                    aInfo.applicationInfo.uid, true);
-            if (app == null || app.instrumentationClass == null) {
-                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
-                mStackSupervisor.startHomeActivity(intent, aInfo);
-            }
-        }
-
-        return true;
-    }
-
-    private ActivityInfo resolveActivityInfo(Intent intent, int flags, int userId) {
-        ActivityInfo ai = null;
-        ComponentName comp = intent.getComponent();
-        try {
-            if (comp != null) {
-                ai = AppGlobals.getPackageManager().getActivityInfo(comp, flags, userId);
-            } else {
-                ResolveInfo info = AppGlobals.getPackageManager().resolveIntent(
-                        intent,
-                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),
-                            flags, userId);
-
-                if (info != null) {
-                    ai = info.activityInfo;
-                }
-            }
-        } catch (RemoteException e) {
-            // ignore
-        }
-
-        return ai;
-    }
-
-    /**
-     * Starts the "new version setup screen" if appropriate.
-     */
-    void startSetupActivityLocked() {
-        // Only do this once per boot.
-        if (mCheckedForSetup) {
-            return;
-        }
-
-        // We will show this screen if the current one is a different
-        // version than the last one shown, and we are not running in
-        // low-level factory test mode.
-        final ContentResolver resolver = mContext.getContentResolver();
-        if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL &&
-                Settings.Global.getInt(resolver,
-                        Settings.Global.DEVICE_PROVISIONED, 0) != 0) {
-            mCheckedForSetup = true;
-
-            // See if we should be showing the platform update setup UI.
-            Intent intent = new Intent(Intent.ACTION_UPGRADE_SETUP);
-            List<ResolveInfo> ris = mSelf.mContext.getPackageManager()
-                    .queryIntentActivities(intent, PackageManager.GET_META_DATA);
-
-            // We don't allow third party apps to replace this.
-            ResolveInfo ri = null;
-            for (int i=0; ris != null && i<ris.size(); i++) {
-                if ((ris.get(i).activityInfo.applicationInfo.flags
-                        & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                    ri = ris.get(i);
-                    break;
-                }
-            }
-
-            if (ri != null) {
-                String vers = ri.activityInfo.metaData != null
-                        ? ri.activityInfo.metaData.getString(Intent.METADATA_SETUP_VERSION)
-                        : null;
-                if (vers == null && ri.activityInfo.applicationInfo.metaData != null) {
-                    vers = ri.activityInfo.applicationInfo.metaData.getString(
-                            Intent.METADATA_SETUP_VERSION);
-                }
-                String lastVers = Settings.Secure.getString(
-                        resolver, Settings.Secure.LAST_SETUP_SHOWN);
-                if (vers != null && !vers.equals(lastVers)) {
-                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                    intent.setComponent(new ComponentName(
-                            ri.activityInfo.packageName, ri.activityInfo.name));
-                    mStackSupervisor.startActivityLocked(null, intent, null, ri.activityInfo,
-                            null, null, 0, 0, 0, null, 0, null, false, null);
-                }
-            }
-        }
-    }
-
-    CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
-        return mCompatModePackages.compatibilityInfoForPackageLocked(ai);
-    }
-
-    void enforceNotIsolatedCaller(String caller) {
-        if (UserHandle.isIsolated(Binder.getCallingUid())) {
-            throw new SecurityException("Isolated process not allowed to call " + caller);
-        }
-    }
-
-    @Override
-    public int getFrontActivityScreenCompatMode() {
-        enforceNotIsolatedCaller("getFrontActivityScreenCompatMode");
-        synchronized (this) {
-            return mCompatModePackages.getFrontActivityScreenCompatModeLocked();
-        }
-    }
-
-    @Override
-    public void setFrontActivityScreenCompatMode(int mode) {
-        enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY,
-                "setFrontActivityScreenCompatMode");
-        synchronized (this) {
-            mCompatModePackages.setFrontActivityScreenCompatModeLocked(mode);
-        }
-    }
-
-    @Override
-    public int getPackageScreenCompatMode(String packageName) {
-        enforceNotIsolatedCaller("getPackageScreenCompatMode");
-        synchronized (this) {
-            return mCompatModePackages.getPackageScreenCompatModeLocked(packageName);
-        }
-    }
-
-    @Override
-    public void setPackageScreenCompatMode(String packageName, int mode) {
-        enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY,
-                "setPackageScreenCompatMode");
-        synchronized (this) {
-            mCompatModePackages.setPackageScreenCompatModeLocked(packageName, mode);
-        }
-    }
-
-    @Override
-    public boolean getPackageAskScreenCompat(String packageName) {
-        enforceNotIsolatedCaller("getPackageAskScreenCompat");
-        synchronized (this) {
-            return mCompatModePackages.getPackageAskCompatModeLocked(packageName);
-        }
-    }
-
-    @Override
-    public void setPackageAskScreenCompat(String packageName, boolean ask) {
-        enforceCallingPermission(android.Manifest.permission.SET_SCREEN_COMPATIBILITY,
-                "setPackageAskScreenCompat");
-        synchronized (this) {
-            mCompatModePackages.setPackageAskCompatModeLocked(packageName, ask);
-        }
-    }
-
-    private void dispatchProcessesChanged() {
-        int N;
-        synchronized (this) {
-            N = mPendingProcessChanges.size();
-            if (mActiveProcessChanges.length < N) {
-                mActiveProcessChanges = new ProcessChangeItem[N];
-            }
-            mPendingProcessChanges.toArray(mActiveProcessChanges);
-            mAvailProcessChanges.addAll(mPendingProcessChanges);
-            mPendingProcessChanges.clear();
-            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "*** Delivering " + N + " process changes");
-        }
-
-        int i = mProcessObservers.beginBroadcast();
-        while (i > 0) {
-            i--;
-            final IProcessObserver observer = mProcessObservers.getBroadcastItem(i);
-            if (observer != null) {
-                try {
-                    for (int j=0; j<N; j++) {
-                        ProcessChangeItem item = mActiveProcessChanges[j];
-                        if ((item.changes&ProcessChangeItem.CHANGE_ACTIVITIES) != 0) {
-                            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "ACTIVITIES CHANGED pid="
-                                    + item.pid + " uid=" + item.uid + ": "
-                                    + item.foregroundActivities);
-                            observer.onForegroundActivitiesChanged(item.pid, item.uid,
-                                    item.foregroundActivities);
-                        }
-                        if ((item.changes&ProcessChangeItem.CHANGE_IMPORTANCE) != 0) {
-                            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "IMPORTANCE CHANGED pid="
-                                    + item.pid + " uid=" + item.uid + ": " + item.importance);
-                            observer.onImportanceChanged(item.pid, item.uid,
-                                    item.importance);
-                        }
-                    }
-                } catch (RemoteException e) {
-                }
-            }
-        }
-        mProcessObservers.finishBroadcast();
-    }
-
-    private void dispatchProcessDied(int pid, int uid) {
-        int i = mProcessObservers.beginBroadcast();
-        while (i > 0) {
-            i--;
-            final IProcessObserver observer = mProcessObservers.getBroadcastItem(i);
-            if (observer != null) {
-                try {
-                    observer.onProcessDied(pid, uid);
-                } catch (RemoteException e) {
-                }
-            }
-        }
-        mProcessObservers.finishBroadcast();
-    }
-
-    final void doPendingActivityLaunchesLocked(boolean doResume) {
-        final int N = mPendingActivityLaunches.size();
-        if (N <= 0) {
-            return;
-        }
-        for (int i=0; i<N; i++) {
-            PendingActivityLaunch pal = mPendingActivityLaunches.get(i);
-            mStackSupervisor.startActivityUncheckedLocked(pal.r, pal.sourceRecord, pal.startFlags,
-                    doResume && i == (N-1), null);
-        }
-        mPendingActivityLaunches.clear();
-    }
-
-    @Override
-    public final int startActivity(IApplicationThread caller, String callingPackage,
-            Intent intent, String resolvedType, IBinder resultTo,
-            String resultWho, int requestCode, int startFlags,
-            String profileFile, ParcelFileDescriptor profileFd, Bundle options) {
-        return startActivityAsUser(caller, callingPackage, intent, resolvedType, resultTo,
-                resultWho, requestCode,
-                startFlags, profileFile, profileFd, options, UserHandle.getCallingUserId());
-    }
-
-    @Override
-    public final int startActivityAsUser(IApplicationThread caller, String callingPackage,
-            Intent intent, String resolvedType, IBinder resultTo,
-            String resultWho, int requestCode, int startFlags,
-            String profileFile, ParcelFileDescriptor profileFd, Bundle options, int userId) {
-        enforceNotIsolatedCaller("startActivity");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "startActivity", null);
-        // TODO: Switch to user app stacks here.
-        return mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType,
-                resultTo, resultWho, requestCode, startFlags, profileFile, profileFd,
-                null, null, options, userId);
-    }
-
-    @Override
-    public final WaitResult startActivityAndWait(IApplicationThread caller, String callingPackage,
-            Intent intent, String resolvedType, IBinder resultTo,
-            String resultWho, int requestCode, int startFlags, String profileFile,
-            ParcelFileDescriptor profileFd, Bundle options, int userId) {
-        enforceNotIsolatedCaller("startActivityAndWait");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "startActivityAndWait", null);
-        WaitResult res = new WaitResult();
-        // TODO: Switch to user app stacks here.
-        mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent, resolvedType,
-                resultTo, resultWho, requestCode, startFlags, profileFile, profileFd,
-                res, null, options, UserHandle.getCallingUserId());
-        return res;
-    }
-
-    @Override
-    public final int startActivityWithConfig(IApplicationThread caller, String callingPackage,
-            Intent intent, String resolvedType, IBinder resultTo,
-            String resultWho, int requestCode, int startFlags, Configuration config,
-            Bundle options, int userId) {
-        enforceNotIsolatedCaller("startActivityWithConfig");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "startActivityWithConfig", null);
-        // TODO: Switch to user app stacks here.
-        int ret = mStackSupervisor.startActivityMayWait(caller, -1, callingPackage, intent,
-                resolvedType, resultTo, resultWho, requestCode, startFlags,
-                null, null, null, config, options, userId);
-        return ret;
-    }
-
-    @Override
-    public int startActivityIntentSender(IApplicationThread caller,
-            IntentSender intent, Intent fillInIntent, String resolvedType,
-            IBinder resultTo, String resultWho, int requestCode,
-            int flagsMask, int flagsValues, Bundle options) {
-        enforceNotIsolatedCaller("startActivityIntentSender");
-        // Refuse possible leaked file descriptors
-        if (fillInIntent != null && fillInIntent.hasFileDescriptors()) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        IIntentSender sender = intent.getTarget();
-        if (!(sender instanceof PendingIntentRecord)) {
-            throw new IllegalArgumentException("Bad PendingIntent object");
-        }
-
-        PendingIntentRecord pir = (PendingIntentRecord)sender;
-
-        synchronized (this) {
-            // If this is coming from the currently resumed activity, it is
-            // effectively saying that app switches are allowed at this point.
-            final ActivityStack stack = getFocusedStack();
-            if (stack.mResumedActivity != null &&
-                    stack.mResumedActivity.info.applicationInfo.uid == Binder.getCallingUid()) {
-                mAppSwitchesAllowedTime = 0;
-            }
-        }
-        int ret = pir.sendInner(0, fillInIntent, resolvedType, null, null,
-                resultTo, resultWho, requestCode, flagsMask, flagsValues, options);
-        return ret;
-    }
-
-    @Override
-    public boolean startNextMatchingActivity(IBinder callingActivity,
-            Intent intent, Bundle options) {
-        // Refuse possible leaked file descriptors
-        if (intent != null && intent.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized (this) {
-            final ActivityRecord r = ActivityRecord.isInStackLocked(callingActivity);
-            if (r == null) {
-                ActivityOptions.abort(options);
-                return false;
-            }
-            if (r.app == null || r.app.thread == null) {
-                // The caller is not running...  d'oh!
-                ActivityOptions.abort(options);
-                return false;
-            }
-            intent = new Intent(intent);
-            // The caller is not allowed to change the data.
-            intent.setDataAndType(r.intent.getData(), r.intent.getType());
-            // And we are resetting to find the next component...
-            intent.setComponent(null);
-
-            final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);
-
-            ActivityInfo aInfo = null;
-            try {
-                List<ResolveInfo> resolves =
-                    AppGlobals.getPackageManager().queryIntentActivities(
-                            intent, r.resolvedType,
-                            PackageManager.MATCH_DEFAULT_ONLY | STOCK_PM_FLAGS,
-                            UserHandle.getCallingUserId());
-
-                // Look for the original activity in the list...
-                final int N = resolves != null ? resolves.size() : 0;
-                for (int i=0; i<N; i++) {
-                    ResolveInfo rInfo = resolves.get(i);
-                    if (rInfo.activityInfo.packageName.equals(r.packageName)
-                            && rInfo.activityInfo.name.equals(r.info.name)) {
-                        // We found the current one...  the next matching is
-                        // after it.
-                        i++;
-                        if (i<N) {
-                            aInfo = resolves.get(i).activityInfo;
-                        }
-                        if (debug) {
-                            Slog.v(TAG, "Next matching activity: found current " + r.packageName
-                                    + "/" + r.info.name);
-                            Slog.v(TAG, "Next matching activity: next is " + aInfo.packageName
-                                    + "/" + aInfo.name);
-                        }
-                        break;
-                    }
-                }
-            } catch (RemoteException e) {
-            }
-
-            if (aInfo == null) {
-                // Nobody who is next!
-                ActivityOptions.abort(options);
-                if (debug) Slog.d(TAG, "Next matching activity: nothing found");
-                return false;
-            }
-
-            intent.setComponent(new ComponentName(
-                    aInfo.applicationInfo.packageName, aInfo.name));
-            intent.setFlags(intent.getFlags()&~(
-                    Intent.FLAG_ACTIVITY_FORWARD_RESULT|
-                    Intent.FLAG_ACTIVITY_CLEAR_TOP|
-                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK|
-                    Intent.FLAG_ACTIVITY_NEW_TASK));
-
-            // Okay now we need to start the new activity, replacing the
-            // currently running activity.  This is a little tricky because
-            // we want to start the new one as if the current one is finished,
-            // but not finish the current one first so that there is no flicker.
-            // And thus...
-            final boolean wasFinishing = r.finishing;
-            r.finishing = true;
-
-            // Propagate reply information over to the new activity.
-            final ActivityRecord resultTo = r.resultTo;
-            final String resultWho = r.resultWho;
-            final int requestCode = r.requestCode;
-            r.resultTo = null;
-            if (resultTo != null) {
-                resultTo.removeResultsLocked(r, resultWho, requestCode);
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-            int res = mStackSupervisor.startActivityLocked(r.app.thread, intent,
-                    r.resolvedType, aInfo, resultTo != null ? resultTo.appToken : null,
-                    resultWho, requestCode, -1, r.launchedFromUid, r.launchedFromPackage, 0,
-                    options, false, null);
-            Binder.restoreCallingIdentity(origId);
-
-            r.finishing = wasFinishing;
-            if (res != ActivityManager.START_SUCCESS) {
-                return false;
-            }
-            return true;
-        }
-    }
-
-    final int startActivityInPackage(int uid, String callingPackage,
-            Intent intent, String resolvedType, IBinder resultTo,
-            String resultWho, int requestCode, int startFlags, Bundle options, int userId) {
-
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "startActivityInPackage", null);
-
-        // TODO: Switch to user app stacks here.
-        int ret = mStackSupervisor.startActivityMayWait(null, uid, callingPackage, intent, resolvedType,
-                resultTo, resultWho, requestCode, startFlags,
-                null, null, null, null, options, userId);
-        return ret;
-    }
-
-    @Override
-    public final int startActivities(IApplicationThread caller, String callingPackage,
-            Intent[] intents, String[] resolvedTypes, IBinder resultTo, Bundle options,
-            int userId) {
-        enforceNotIsolatedCaller("startActivities");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "startActivity", null);
-        // TODO: Switch to user app stacks here.
-        int ret = mStackSupervisor.startActivities(caller, -1, callingPackage, intents,
-                resolvedTypes, resultTo, options, userId);
-        return ret;
-    }
-
-    final int startActivitiesInPackage(int uid, String callingPackage,
-            Intent[] intents, String[] resolvedTypes, IBinder resultTo,
-            Bundle options, int userId) {
-
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "startActivityInPackage", null);
-        // TODO: Switch to user app stacks here.
-        int ret = mStackSupervisor.startActivities(null, uid, callingPackage, intents, resolvedTypes,
-                resultTo, options, userId);
-        return ret;
-    }
-
-    final void addRecentTaskLocked(TaskRecord task) {
-        int N = mRecentTasks.size();
-        // Quick case: check if the top-most recent task is the same.
-        if (N > 0 && mRecentTasks.get(0) == task) {
-            return;
-        }
-        // Remove any existing entries that are the same kind of task.
-        for (int i=0; i<N; i++) {
-            TaskRecord tr = mRecentTasks.get(i);
-            if (task.userId == tr.userId
-                    && ((task.affinity != null && task.affinity.equals(tr.affinity))
-                    || (task.intent != null && task.intent.filterEquals(tr.intent)))) {
-                tr.disposeThumbnail();
-                mRecentTasks.remove(i);
-                i--;
-                N--;
-                if (task.intent == null) {
-                    // If the new recent task we are adding is not fully
-                    // specified, then replace it with the existing recent task.
-                    task = tr;
-                }
-            }
-        }
-        if (N >= MAX_RECENT_TASKS) {
-            mRecentTasks.remove(N-1).disposeThumbnail();
-        }
-        mRecentTasks.add(0, task);
-    }
-
-    @Override
-    public void reportActivityFullyDrawn(IBinder token) {
-        synchronized (this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                return;
-            }
-            r.reportFullyDrawnLocked();
-        }
-    }
-
-    @Override
-    public void setRequestedOrientation(IBinder token, int requestedOrientation) {
-        synchronized (this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                return;
-            }
-            final long origId = Binder.clearCallingIdentity();
-            mWindowManager.setAppOrientation(r.appToken, requestedOrientation);
-            Configuration config = mWindowManager.updateOrientationFromAppTokens(
-                    mConfiguration, r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
-            if (config != null) {
-                r.frozenBeforeDestroy = true;
-                if (!updateConfigurationLocked(config, r, false, false)) {
-                    mStackSupervisor.resumeTopActivitiesLocked();
-                }
-            }
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public int getRequestedOrientation(IBinder token) {
-        synchronized (this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-            }
-            return mWindowManager.getAppOrientation(r.appToken);
-        }
-    }
-
-    /**
-     * This is the internal entry point for handling Activity.finish().
-     *
-     * @param token The Binder token referencing the Activity we want to finish.
-     * @param resultCode Result code, if any, from this Activity.
-     * @param resultData Result data (Intent), if any, from this Activity.
-     *
-     * @return Returns true if the activity successfully finished, or false if it is still running.
-     */
-    @Override
-    public final boolean finishActivity(IBinder token, int resultCode, Intent resultData) {
-        // Refuse possible leaked file descriptors
-        if (resultData != null && resultData.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized(this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                return true;
-            }
-            if (mController != null) {
-                // Find the first activity that is not finishing.
-                ActivityRecord next = r.task.stack.topRunningActivityLocked(token, 0);
-                if (next != null) {
-                    // ask watcher if this is allowed
-                    boolean resumeOK = true;
-                    try {
-                        resumeOK = mController.activityResuming(next.packageName);
-                    } catch (RemoteException e) {
-                        mController = null;
-                        Watchdog.getInstance().setActivityController(null);
-                    }
-
-                    if (!resumeOK) {
-                        return false;
-                    }
-                }
-            }
-            final long origId = Binder.clearCallingIdentity();
-            boolean res = r.task.stack.requestFinishActivityLocked(token, resultCode,
-                    resultData, "app-request", true);
-            Binder.restoreCallingIdentity(origId);
-            return res;
-        }
-    }
-
-    @Override
-    public final void finishHeavyWeightApp() {
-        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: finishHeavyWeightApp() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        synchronized(this) {
-            if (mHeavyWeightProcess == null) {
-                return;
-            }
-
-            ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>(
-                    mHeavyWeightProcess.activities);
-            for (int i=0; i<activities.size(); i++) {
-                ActivityRecord r = activities.get(i);
-                if (!r.finishing) {
-                    r.task.stack.finishActivityLocked(r, Activity.RESULT_CANCELED,
-                            null, "finish-heavy", true);
-                }
-            }
-
-            mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
-                    mHeavyWeightProcess.userId, 0));
-            mHeavyWeightProcess = null;
-        }
-    }
-
-    @Override
-    public void crashApplication(int uid, int initialPid, String packageName,
-            String message) {
-        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: crashApplication() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        synchronized(this) {
-            ProcessRecord proc = null;
-
-            // Figure out which process to kill.  We don't trust that initialPid
-            // still has any relation to current pids, so must scan through the
-            // list.
-            synchronized (mPidsSelfLocked) {
-                for (int i=0; i<mPidsSelfLocked.size(); i++) {
-                    ProcessRecord p = mPidsSelfLocked.valueAt(i);
-                    if (p.uid != uid) {
-                        continue;
-                    }
-                    if (p.pid == initialPid) {
-                        proc = p;
-                        break;
-                    }
-                    if (p.pkgList.containsKey(packageName)) {
-                        proc = p;
-                    }
-                }
-            }
-
-            if (proc == null) {
-                Slog.w(TAG, "crashApplication: nothing for uid=" + uid
-                        + " initialPid=" + initialPid
-                        + " packageName=" + packageName);
-                return;
-            }
-
-            if (proc.thread != null) {
-                if (proc.pid == Process.myPid()) {
-                    Log.w(TAG, "crashApplication: trying to crash self!");
-                    return;
-                }
-                long ident = Binder.clearCallingIdentity();
-                try {
-                    proc.thread.scheduleCrash(message);
-                } catch (RemoteException e) {
-                }
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public final void finishSubActivity(IBinder token, String resultWho,
-            int requestCode) {
-        synchronized(this) {
-            final long origId = Binder.clearCallingIdentity();
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r != null) {
-                r.task.stack.finishSubActivityLocked(r, resultWho, requestCode);
-            }
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public boolean finishActivityAffinity(IBinder token) {
-        synchronized(this) {
-            final long origId = Binder.clearCallingIdentity();
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            boolean res = false;
-            if (r != null) {
-                res = r.task.stack.finishActivityAffinityLocked(r);
-            }
-            Binder.restoreCallingIdentity(origId);
-            return res;
-        }
-    }
-
-    @Override
-    public boolean willActivityBeVisible(IBinder token) {
-        synchronized(this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                return stack.willActivityBeVisibleLocked(token);
-            }
-            return false;
-        }
-    }
-
-    @Override
-    public void overridePendingTransition(IBinder token, String packageName,
-            int enterAnim, int exitAnim) {
-        synchronized(this) {
-            ActivityRecord self = ActivityRecord.isInStackLocked(token);
-            if (self == null) {
-                return;
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-
-            if (self.state == ActivityState.RESUMED
-                    || self.state == ActivityState.PAUSING) {
-                mWindowManager.overridePendingAppTransition(packageName,
-                        enterAnim, exitAnim, null);
-            }
-
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    /**
-     * Main function for removing an existing process from the activity manager
-     * as a result of that process going away.  Clears out all connections
-     * to the process.
-     */
-    private final void handleAppDiedLocked(ProcessRecord app,
-            boolean restarting, boolean allowRestart) {
-        cleanUpApplicationRecordLocked(app, restarting, allowRestart, -1);
-        if (!restarting) {
-            removeLruProcessLocked(app);
-        }
-
-        if (mProfileProc == app) {
-            clearProfilerLocked();
-        }
-
-        // Remove this application's activities from active lists.
-        boolean hasVisibleActivities = mStackSupervisor.handleAppDiedLocked(app);
-
-        app.activities.clear();
-
-        if (app.instrumentationClass != null) {
-            Slog.w(TAG, "Crash of app " + app.processName
-                  + " running instrumentation " + app.instrumentationClass);
-            Bundle info = new Bundle();
-            info.putString("shortMsg", "Process crashed.");
-            finishInstrumentationLocked(app, Activity.RESULT_CANCELED, info);
-        }
-
-        if (!restarting) {
-            if (!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 (hasVisibleActivities) {
-                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
-                }
-            }
-        }
-    }
-
-    private final int getLRURecordIndexForAppLocked(IApplicationThread thread) {
-        IBinder threadBinder = thread.asBinder();
-        // Find the application record.
-        for (int i=mLruProcesses.size()-1; i>=0; i--) {
-            ProcessRecord rec = mLruProcesses.get(i);
-            if (rec.thread != null && rec.thread.asBinder() == threadBinder) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    final ProcessRecord getRecordForAppLocked(
-            IApplicationThread thread) {
-        if (thread == null) {
-            return null;
-        }
-
-        int appIndex = getLRURecordIndexForAppLocked(thread);
-        return appIndex >= 0 ? mLruProcesses.get(appIndex) : null;
-    }
-
-    final void doLowMemReportIfNeededLocked(ProcessRecord dyingProc) {
-        // If there are no longer any background processes running,
-        // and the app that died was not running instrumentation,
-        // then tell everyone we are now low on memory.
-        boolean haveBg = false;
-        for (int i=mLruProcesses.size()-1; i>=0; i--) {
-            ProcessRecord rec = mLruProcesses.get(i);
-            if (rec.thread != null
-                    && rec.setProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
-                haveBg = true;
-                break;
-            }
-        }
-
-        if (!haveBg) {
-            boolean doReport = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
-            if (doReport) {
-                long now = SystemClock.uptimeMillis();
-                if (now < (mLastMemUsageReportTime+5*60*1000)) {
-                    doReport = false;
-                } else {
-                    mLastMemUsageReportTime = now;
-                }
-            }
-            final ArrayList<ProcessMemInfo> memInfos
-                    = doReport ? new ArrayList<ProcessMemInfo>(mLruProcesses.size()) : null;
-            EventLog.writeEvent(EventLogTags.AM_LOW_MEMORY, mLruProcesses.size());
-            long now = SystemClock.uptimeMillis();
-            for (int i=mLruProcesses.size()-1; i>=0; i--) {
-                ProcessRecord rec = mLruProcesses.get(i);
-                if (rec == dyingProc || rec.thread == null) {
-                    continue;
-                }
-                if (doReport) {
-                    memInfos.add(new ProcessMemInfo(rec.processName, rec.pid, rec.setAdj,
-                            rec.setProcState, rec.adjType, rec.makeAdjReason()));
-                }
-                if ((rec.lastLowMemory+GC_MIN_INTERVAL) <= now) {
-                    // The low memory report is overriding any current
-                    // state for a GC request.  Make sure to do
-                    // heavy/important/visible/foreground processes first.
-                    if (rec.setAdj <= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
-                        rec.lastRequestedGc = 0;
-                    } else {
-                        rec.lastRequestedGc = rec.lastLowMemory;
-                    }
-                    rec.reportLowMemory = true;
-                    rec.lastLowMemory = now;
-                    mProcessesToGc.remove(rec);
-                    addProcessToGcListLocked(rec);
-                }
-            }
-            if (doReport) {
-                Message msg = mHandler.obtainMessage(REPORT_MEM_USAGE_MSG, memInfos);
-                mHandler.sendMessage(msg);
-            }
-            scheduleAppGcsLocked();
-        }
-    }
-
-    final void appDiedLocked(ProcessRecord app, int pid,
-            IApplicationThread thread) {
-
-        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-        synchronized (stats) {
-            stats.noteProcessDiedLocked(app.info.uid, pid);
-        }
-
-        // Clean up already done if the process has been re-started.
-        if (app.pid == pid && app.thread != null &&
-                app.thread.asBinder() == thread.asBinder()) {
-            boolean doLowMem = app.instrumentationClass == null;
-            boolean doOomAdj = doLowMem;
-            if (!app.killedByAm) {
-                Slog.i(TAG, "Process " + app.processName + " (pid " + pid
-                        + ") has died.");
-                mAllowLowerMemLevel = true;
-            } else {
-                // Note that we always want to do oom adj to update our state with the
-                // new number of procs.
-                mAllowLowerMemLevel = false;
-                doLowMem = false;
-            }
-            EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.userId, app.pid, app.processName);
-            if (DEBUG_CLEANUP) Slog.v(
-                TAG, "Dying app: " + app + ", pid: " + pid
-                + ", thread: " + thread.asBinder());
-            handleAppDiedLocked(app, false, true);
-
-            if (doOomAdj) {
-                updateOomAdjLocked();
-            }
-            if (doLowMem) {
-                doLowMemReportIfNeededLocked(app);
-            }
-        } else if (app.pid != pid) {
-            // A new process has already been started.
-            Slog.i(TAG, "Process " + app.processName + " (pid " + pid
-                    + ") has died and restarted (pid " + app.pid + ").");
-            EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.userId, app.pid, app.processName);
-        } else if (DEBUG_PROCESSES) {
-            Slog.d(TAG, "Received spurious death notification for thread "
-                    + thread.asBinder());
-        }
-    }
-
-    /**
-     * If a stack trace dump file is configured, dump process stack traces.
-     * @param clearTraces causes the dump file to be erased prior to the new
-     *    traces being written, if true; when false, the new traces will be
-     *    appended to any existing file content.
-     * @param firstPids of dalvik VM processes to dump stack traces for first
-     * @param lastPids of dalvik VM processes to dump stack traces for last
-     * @param nativeProcs optional list of native process names to dump stack crawls
-     * @return file containing stack traces, or null if no dump file is configured
-     */
-    public static File dumpStackTraces(boolean clearTraces, ArrayList<Integer> firstPids,
-            ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids, String[] nativeProcs) {
-        String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
-        if (tracesPath == null || tracesPath.length() == 0) {
-            return null;
-        }
-
-        File tracesFile = new File(tracesPath);
-        try {
-            File tracesDir = tracesFile.getParentFile();
-            if (!tracesDir.exists()) {
-                tracesFile.mkdirs();
-                if (!SELinux.restorecon(tracesDir)) {
-                    return null;
-                }
-            }
-            FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);  // drwxrwxr-x
-
-            if (clearTraces && tracesFile.exists()) tracesFile.delete();
-            tracesFile.createNewFile();
-            FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw-
-        } catch (IOException e) {
-            Slog.w(TAG, "Unable to prepare ANR traces file: " + tracesPath, e);
-            return null;
-        }
-
-        dumpStackTraces(tracesPath, firstPids, processCpuTracker, lastPids, nativeProcs);
-        return tracesFile;
-    }
-
-    private static void dumpStackTraces(String tracesPath, ArrayList<Integer> firstPids,
-            ProcessCpuTracker processCpuTracker, SparseArray<Boolean> lastPids, String[] nativeProcs) {
-        // Use a FileObserver to detect when traces finish writing.
-        // The order of traces is considered important to maintain for legibility.
-        FileObserver observer = new FileObserver(tracesPath, FileObserver.CLOSE_WRITE) {
-            @Override
-            public synchronized void onEvent(int event, String path) { notify(); }
-        };
-
-        try {
-            observer.startWatching();
-
-            // First collect all of the stacks of the most important pids.
-            if (firstPids != null) {
-                try {
-                    int num = firstPids.size();
-                    for (int i = 0; i < num; i++) {
-                        synchronized (observer) {
-                            Process.sendSignal(firstPids.get(i), Process.SIGNAL_QUIT);
-                            observer.wait(200);  // Wait for write-close, give up after 200msec
-                        }
-                    }
-                } catch (InterruptedException e) {
-                    Log.wtf(TAG, e);
-                }
-            }
-
-            // Next collect the stacks of the native pids
-            if (nativeProcs != null) {
-                int[] pids = Process.getPidsForCommands(nativeProcs);
-                if (pids != null) {
-                    for (int pid : pids) {
-                        Debug.dumpNativeBacktraceToFile(pid, tracesPath);
-                    }
-                }
-            }
-
-            // Lastly, measure CPU usage.
-            if (processCpuTracker != null) {
-                processCpuTracker.init();
-                System.gc();
-                processCpuTracker.update();
-                try {
-                    synchronized (processCpuTracker) {
-                        processCpuTracker.wait(500); // measure over 1/2 second.
-                    }
-                } catch (InterruptedException e) {
-                }
-                processCpuTracker.update();
-
-                // We'll take the stack crawls of just the top apps using CPU.
-                final int N = processCpuTracker.countWorkingStats();
-                int numProcs = 0;
-                for (int i=0; i<N && numProcs<5; i++) {
-                    ProcessCpuTracker.Stats stats = processCpuTracker.getWorkingStats(i);
-                    if (lastPids.indexOfKey(stats.pid) >= 0) {
-                        numProcs++;
-                        try {
-                            synchronized (observer) {
-                                Process.sendSignal(stats.pid, Process.SIGNAL_QUIT);
-                                observer.wait(200);  // Wait for write-close, give up after 200msec
-                            }
-                        } catch (InterruptedException e) {
-                            Log.wtf(TAG, e);
-                        }
-
-                    }
-                }
-            }
-        } finally {
-            observer.stopWatching();
-        }
-    }
-
-    final void logAppTooSlow(ProcessRecord app, long startTime, String msg) {
-        if (true || IS_USER_BUILD) {
-            return;
-        }
-        String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
-        if (tracesPath == null || tracesPath.length() == 0) {
-            return;
-        }
-
-        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
-        StrictMode.allowThreadDiskWrites();
-        try {
-            final File tracesFile = new File(tracesPath);
-            final File tracesDir = tracesFile.getParentFile();
-            final File tracesTmp = new File(tracesDir, "__tmp__");
-            try {
-                if (!tracesDir.exists()) {
-                    tracesFile.mkdirs();
-                    if (!SELinux.restorecon(tracesDir.getPath())) {
-                        return;
-                    }
-                }
-                FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);  // drwxrwxr-x
-
-                if (tracesFile.exists()) {
-                    tracesTmp.delete();
-                    tracesFile.renameTo(tracesTmp);
-                }
-                StringBuilder sb = new StringBuilder();
-                Time tobj = new Time();
-                tobj.set(System.currentTimeMillis());
-                sb.append(tobj.format("%Y-%m-%d %H:%M:%S"));
-                sb.append(": ");
-                TimeUtils.formatDuration(SystemClock.uptimeMillis()-startTime, sb);
-                sb.append(" since ");
-                sb.append(msg);
-                FileOutputStream fos = new FileOutputStream(tracesFile);
-                fos.write(sb.toString().getBytes());
-                if (app == null) {
-                    fos.write("\n*** No application process!".getBytes());
-                }
-                fos.close();
-                FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1); // -rw-rw-rw-
-            } catch (IOException e) {
-                Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesPath, e);
-                return;
-            }
-
-            if (app != null) {
-                ArrayList<Integer> firstPids = new ArrayList<Integer>();
-                firstPids.add(app.pid);
-                dumpStackTraces(tracesPath, firstPids, null, null, null);
-            }
-
-            File lastTracesFile = null;
-            File curTracesFile = null;
-            for (int i=9; i>=0; i--) {
-                String name = String.format(Locale.US, "slow%02d.txt", i);
-                curTracesFile = new File(tracesDir, name);
-                if (curTracesFile.exists()) {
-                    if (lastTracesFile != null) {
-                        curTracesFile.renameTo(lastTracesFile);
-                    } else {
-                        curTracesFile.delete();
-                    }
-                }
-                lastTracesFile = curTracesFile;
-            }
-            tracesFile.renameTo(curTracesFile);
-            if (tracesTmp.exists()) {
-                tracesTmp.renameTo(tracesFile);
-            }
-        } finally {
-            StrictMode.setThreadPolicy(oldPolicy);
-        }
-    }
-
-    final void appNotResponding(ProcessRecord app, ActivityRecord activity,
-            ActivityRecord parent, boolean aboveSystem, final String annotation) {
-        ArrayList<Integer> firstPids = new ArrayList<Integer>(5);
-        SparseArray<Boolean> lastPids = new SparseArray<Boolean>(20);
-
-        if (mController != null) {
-            try {
-                // 0 == continue, -1 = kill process immediately
-                int res = mController.appEarlyNotResponding(app.processName, app.pid, annotation);
-                if (res < 0 && app.pid != MY_PID) Process.killProcess(app.pid);
-            } catch (RemoteException e) {
-                mController = null;
-                Watchdog.getInstance().setActivityController(null);
-            }
-        }
-
-        long anrTime = SystemClock.uptimeMillis();
-        if (MONITOR_CPU_USAGE) {
-            updateCpuStatsNow();
-        }
-
-        synchronized (this) {
-            // PowerManager.reboot() can block for a long time, so ignore ANRs while shutting down.
-            if (mShuttingDown) {
-                Slog.i(TAG, "During shutdown skipping ANR: " + app + " " + annotation);
-                return;
-            } else if (app.notResponding) {
-                Slog.i(TAG, "Skipping duplicate ANR: " + app + " " + annotation);
-                return;
-            } else if (app.crashing) {
-                Slog.i(TAG, "Crashing app skipping ANR: " + app + " " + annotation);
-                return;
-            }
-
-            // In case we come through here for the same app before completing
-            // this one, mark as anring now so we will bail out.
-            app.notResponding = true;
-
-            // Log the ANR to the event log.
-            EventLog.writeEvent(EventLogTags.AM_ANR, app.userId, app.pid,
-                    app.processName, app.info.flags, annotation);
-
-            // Dump thread traces as quickly as we can, starting with "interesting" processes.
-            firstPids.add(app.pid);
-
-            int parentPid = app.pid;
-            if (parent != null && parent.app != null && parent.app.pid > 0) parentPid = parent.app.pid;
-            if (parentPid != app.pid) firstPids.add(parentPid);
-
-            if (MY_PID != app.pid && MY_PID != parentPid) firstPids.add(MY_PID);
-
-            for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
-                ProcessRecord r = mLruProcesses.get(i);
-                if (r != null && r.thread != null) {
-                    int pid = r.pid;
-                    if (pid > 0 && pid != app.pid && pid != parentPid && pid != MY_PID) {
-                        if (r.persistent) {
-                            firstPids.add(pid);
-                        } else {
-                            lastPids.put(pid, Boolean.TRUE);
-                        }
-                    }
-                }
-            }
-        }
-
-        // Log the ANR to the main log.
-        StringBuilder info = new StringBuilder();
-        info.setLength(0);
-        info.append("ANR in ").append(app.processName);
-        if (activity != null && activity.shortComponentName != null) {
-            info.append(" (").append(activity.shortComponentName).append(")");
-        }
-        info.append("\n");
-        info.append("PID: ").append(app.pid).append("\n");
-        if (annotation != null) {
-            info.append("Reason: ").append(annotation).append("\n");
-        }
-        if (parent != null && parent != activity) {
-            info.append("Parent: ").append(parent.shortComponentName).append("\n");
-        }
-
-        final ProcessCpuTracker processCpuTracker = new ProcessCpuTracker(true);
-
-        File tracesFile = dumpStackTraces(true, firstPids, processCpuTracker, lastPids,
-                NATIVE_STACKS_OF_INTEREST);
-
-        String cpuInfo = null;
-        if (MONITOR_CPU_USAGE) {
-            updateCpuStatsNow();
-            synchronized (mProcessCpuThread) {
-                cpuInfo = mProcessCpuTracker.printCurrentState(anrTime);
-            }
-            info.append(processCpuTracker.printCurrentLoad());
-            info.append(cpuInfo);
-        }
-
-        info.append(processCpuTracker.printCurrentState(anrTime));
-
-        Slog.e(TAG, info.toString());
-        if (tracesFile == null) {
-            // There is no trace file, so dump (only) the alleged culprit's threads to the log
-            Process.sendSignal(app.pid, Process.SIGNAL_QUIT);
-        }
-
-        addErrorToDropBox("anr", app, app.processName, activity, parent, annotation,
-                cpuInfo, tracesFile, null);
-
-        if (mController != null) {
-            try {
-                // 0 == show dialog, 1 = keep waiting, -1 = kill process immediately
-                int res = mController.appNotResponding(app.processName, app.pid, info.toString());
-                if (res != 0) {
-                    if (res < 0 && app.pid != MY_PID) {
-                        Process.killProcess(app.pid);
-                    } else {
-                        synchronized (this) {
-                            mServices.scheduleServiceTimeoutLocked(app);
-                        }
-                    }
-                    return;
-                }
-            } catch (RemoteException e) {
-                mController = null;
-                Watchdog.getInstance().setActivityController(null);
-            }
-        }
-
-        // Unless configured otherwise, swallow ANRs in background processes & kill the process.
-        boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0;
-
-        synchronized (this) {
-            if (!showBackground && !app.isInterestingToUserLocked() && app.pid != MY_PID) {
-                killUnneededProcessLocked(app, "background ANR");
-                return;
-            }
-
-            // Set the app's notResponding state, and look up the errorReportReceiver
-            makeAppNotRespondingLocked(app,
-                    activity != null ? activity.shortComponentName : null,
-                    annotation != null ? "ANR " + annotation : "ANR",
-                    info.toString());
-
-            // Bring up the infamous App Not Responding dialog
-            Message msg = Message.obtain();
-            HashMap<String, Object> map = new HashMap<String, Object>();
-            msg.what = SHOW_NOT_RESPONDING_MSG;
-            msg.obj = map;
-            msg.arg1 = aboveSystem ? 1 : 0;
-            map.put("app", app);
-            if (activity != null) {
-                map.put("activity", activity);
-            }
-
-            mHandler.sendMessage(msg);
-        }
-    }
-
-    final void showLaunchWarningLocked(final ActivityRecord cur, final ActivityRecord next) {
-        if (!mLaunchWarningShown) {
-            mLaunchWarningShown = true;
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    synchronized (ActivityManagerService.this) {
-                        final Dialog d = new LaunchWarningWindow(mContext, cur, next);
-                        d.show();
-                        mHandler.postDelayed(new Runnable() {
-                            @Override
-                            public void run() {
-                                synchronized (ActivityManagerService.this) {
-                                    d.dismiss();
-                                    mLaunchWarningShown = false;
-                                }
-                            }
-                        }, 4000);
-                    }
-                }
-            });
-        }
-    }
-
-    @Override
-    public boolean clearApplicationUserData(final String packageName,
-            final IPackageDataObserver observer, int userId) {
-        enforceNotIsolatedCaller("clearApplicationUserData");
-        int uid = Binder.getCallingUid();
-        int pid = Binder.getCallingPid();
-        userId = handleIncomingUser(pid, uid,
-                userId, false, true, "clearApplicationUserData", null);
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            IPackageManager pm = AppGlobals.getPackageManager();
-            int pkgUid = -1;
-            synchronized(this) {
-                try {
-                    pkgUid = pm.getPackageUid(packageName, userId);
-                } catch (RemoteException e) {
-                }
-                if (pkgUid == -1) {
-                    Slog.w(TAG, "Invalid packageName: " + packageName);
-                    if (observer != null) {
-                        try {
-                            observer.onRemoveCompleted(packageName, false);
-                        } catch (RemoteException e) {
-                            Slog.i(TAG, "Observer no longer exists.");
-                        }
-                    }
-                    return false;
-                }
-                if (uid == pkgUid || checkComponentPermission(
-                        android.Manifest.permission.CLEAR_APP_USER_DATA,
-                        pid, uid, -1, true)
-                        == PackageManager.PERMISSION_GRANTED) {
-                    forceStopPackageLocked(packageName, pkgUid, "clear data");
-                } else {
-                    throw new SecurityException(pid+" does not have permission:"+
-                            android.Manifest.permission.CLEAR_APP_USER_DATA+" to clear data" +
-                                    "for process:"+packageName);
-                }
-            }
-
-            try {
-                // Clear application user data
-                pm.clearApplicationUserData(packageName, observer, userId);
-
-                // Remove all permissions granted from/to this package
-                removeUriPermissionsForPackageLocked(packageName, userId, true);
-
-                Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED,
-                        Uri.fromParts("package", packageName, null));
-                intent.putExtra(Intent.EXTRA_UID, pkgUid);
-                broadcastIntentInPackage("android", Process.SYSTEM_UID, intent,
-                        null, null, 0, null, null, null, false, false, userId);
-            } catch (RemoteException e) {
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-        return true;
-    }
-
-    @Override
-    public void killBackgroundProcesses(final String packageName, int userId) {
-        if (checkCallingPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES)
-                != PackageManager.PERMISSION_GRANTED &&
-                checkCallingPermission(android.Manifest.permission.RESTART_PACKAGES)
-                        != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: killBackgroundProcesses() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.KILL_BACKGROUND_PROCESSES;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
-                userId, true, true, "killBackgroundProcesses", null);
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            IPackageManager pm = AppGlobals.getPackageManager();
-            synchronized(this) {
-                int appId = -1;
-                try {
-                    appId = UserHandle.getAppId(pm.getPackageUid(packageName, 0));
-                } catch (RemoteException e) {
-                }
-                if (appId == -1) {
-                    Slog.w(TAG, "Invalid packageName: " + packageName);
-                    return;
-                }
-                killPackageProcessesLocked(packageName, appId, userId,
-                        ProcessList.SERVICE_ADJ, false, true, true, false, "kill background");
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-    }
-
-    @Override
-    public void killAllBackgroundProcesses() {
-        if (checkCallingPermission(android.Manifest.permission.KILL_BACKGROUND_PROCESSES)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: killAllBackgroundProcesses() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.KILL_BACKGROUND_PROCESSES;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            synchronized(this) {
-                ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
-                final int NP = mProcessNames.getMap().size();
-                for (int ip=0; ip<NP; ip++) {
-                    SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
-                    final int NA = apps.size();
-                    for (int ia=0; ia<NA; ia++) {
-                        ProcessRecord app = apps.valueAt(ia);
-                        if (app.persistent) {
-                            // we don't kill persistent processes
-                            continue;
-                        }
-                        if (app.removed) {
-                            procs.add(app);
-                        } else if (app.setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
-                            app.removed = true;
-                            procs.add(app);
-                        }
-                    }
-                }
-
-                int N = procs.size();
-                for (int i=0; i<N; i++) {
-                    removeProcessLocked(procs.get(i), false, true, "kill all background");
-                }
-                mAllowLowerMemLevel = true;
-                updateOomAdjLocked();
-                doLowMemReportIfNeededLocked(null);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-    }
-
-    @Override
-    public void forceStopPackage(final String packageName, int userId) {
-        if (checkCallingPermission(android.Manifest.permission.FORCE_STOP_PACKAGES)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: forceStopPackage() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.FORCE_STOP_PACKAGES;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-        final int callingPid = Binder.getCallingPid();
-        userId = handleIncomingUser(callingPid, Binder.getCallingUid(),
-                userId, true, true, "forceStopPackage", null);
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            IPackageManager pm = AppGlobals.getPackageManager();
-            synchronized(this) {
-                int[] users = userId == UserHandle.USER_ALL
-                        ? getUsersLocked() : new int[] { userId };
-                for (int user : users) {
-                    int pkgUid = -1;
-                    try {
-                        pkgUid = pm.getPackageUid(packageName, user);
-                    } catch (RemoteException e) {
-                    }
-                    if (pkgUid == -1) {
-                        Slog.w(TAG, "Invalid packageName: " + packageName);
-                        continue;
-                    }
-                    try {
-                        pm.setPackageStoppedState(packageName, true, user);
-                    } catch (RemoteException e) {
-                    } catch (IllegalArgumentException e) {
-                        Slog.w(TAG, "Failed trying to unstop package "
-                                + packageName + ": " + e);
-                    }
-                    if (isUserRunningLocked(user, false)) {
-                        forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid);
-                    }
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-    }
-
-    /*
-     * The pkg name and app id have to be specified.
-     */
-    @Override
-    public void killApplicationWithAppId(String pkg, int appid, String reason) {
-        if (pkg == null) {
-            return;
-        }
-        // Make sure the uid is valid.
-        if (appid < 0) {
-            Slog.w(TAG, "Invalid appid specified for pkg : " + pkg);
-            return;
-        }
-        int callerUid = Binder.getCallingUid();
-        // Only the system server can kill an application
-        if (callerUid == Process.SYSTEM_UID) {
-            // Post an aysnc message to kill the application
-            Message msg = mHandler.obtainMessage(KILL_APPLICATION_MSG);
-            msg.arg1 = appid;
-            msg.arg2 = 0;
-            Bundle bundle = new Bundle();
-            bundle.putString("pkg", pkg);
-            bundle.putString("reason", reason);
-            msg.obj = bundle;
-            mHandler.sendMessage(msg);
-        } else {
-            throw new SecurityException(callerUid + " cannot kill pkg: " +
-                    pkg);
-        }
-    }
-
-    @Override
-    public void closeSystemDialogs(String reason) {
-        enforceNotIsolatedCaller("closeSystemDialogs");
-
-        final int pid = Binder.getCallingPid();
-        final int uid = Binder.getCallingUid();
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (this) {
-                // Only allow this from foreground processes, so that background
-                // applications can't abuse it to prevent system UI from being shown.
-                if (uid >= Process.FIRST_APPLICATION_UID) {
-                    ProcessRecord proc;
-                    synchronized (mPidsSelfLocked) {
-                        proc = mPidsSelfLocked.get(pid);
-                    }
-                    if (proc.curRawAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-                        Slog.w(TAG, "Ignoring closeSystemDialogs " + reason
-                                + " from background process " + proc);
-                        return;
-                    }
-                }
-                closeSystemDialogsLocked(reason);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    void closeSystemDialogsLocked(String reason) {
-        Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
-        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                | Intent.FLAG_RECEIVER_FOREGROUND);
-        if (reason != null) {
-            intent.putExtra("reason", reason);
-        }
-        mWindowManager.closeSystemDialogs(reason);
-
-        mStackSupervisor.closeSystemDialogsLocked();
-
-        broadcastIntentLocked(null, null, intent, null,
-                null, 0, null, null, null, AppOpsManager.OP_NONE, false, false, -1,
-                Process.SYSTEM_UID, UserHandle.USER_ALL);
-    }
-
-    @Override
-    public Debug.MemoryInfo[] getProcessMemoryInfo(int[] pids) {
-        enforceNotIsolatedCaller("getProcessMemoryInfo");
-        Debug.MemoryInfo[] infos = new Debug.MemoryInfo[pids.length];
-        for (int i=pids.length-1; i>=0; i--) {
-            ProcessRecord proc;
-            int oomAdj;
-            synchronized (this) {
-                synchronized (mPidsSelfLocked) {
-                    proc = mPidsSelfLocked.get(pids[i]);
-                    oomAdj = proc != null ? proc.setAdj : 0;
-                }
-            }
-            infos[i] = new Debug.MemoryInfo();
-            Debug.getMemoryInfo(pids[i], infos[i]);
-            if (proc != null) {
-                synchronized (this) {
-                    if (proc.thread != null && proc.setAdj == oomAdj) {
-                        // Record this for posterity if the process has been stable.
-                        proc.baseProcessTracker.addPss(infos[i].getTotalPss(),
-                                infos[i].getTotalUss(), false, proc.pkgList);
-                    }
-                }
-            }
-        }
-        return infos;
-    }
-
-    @Override
-    public long[] getProcessPss(int[] pids) {
-        enforceNotIsolatedCaller("getProcessPss");
-        long[] pss = new long[pids.length];
-        for (int i=pids.length-1; i>=0; i--) {
-            ProcessRecord proc;
-            int oomAdj;
-            synchronized (this) {
-                synchronized (mPidsSelfLocked) {
-                    proc = mPidsSelfLocked.get(pids[i]);
-                    oomAdj = proc != null ? proc.setAdj : 0;
-                }
-            }
-            long[] tmpUss = new long[1];
-            pss[i] = Debug.getPss(pids[i], tmpUss);
-            if (proc != null) {
-                synchronized (this) {
-                    if (proc.thread != null && proc.setAdj == oomAdj) {
-                        // Record this for posterity if the process has been stable.
-                        proc.baseProcessTracker.addPss(pss[i], tmpUss[0], false, proc.pkgList);
-                    }
-                }
-            }
-        }
-        return pss;
-    }
-
-    @Override
-    public void killApplicationProcess(String processName, int uid) {
-        if (processName == null) {
-            return;
-        }
-
-        int callerUid = Binder.getCallingUid();
-        // Only the system server can kill an application
-        if (callerUid == Process.SYSTEM_UID) {
-            synchronized (this) {
-                ProcessRecord app = getProcessRecordLocked(processName, uid, true);
-                if (app != null && app.thread != null) {
-                    try {
-                        app.thread.scheduleSuicide();
-                    } catch (RemoteException e) {
-                        // If the other end already died, then our work here is done.
-                    }
-                } else {
-                    Slog.w(TAG, "Process/uid not found attempting kill of "
-                            + processName + " / " + uid);
-                }
-            }
-        } else {
-            throw new SecurityException(callerUid + " cannot kill app process: " +
-                    processName);
-        }
-    }
-
-    private void forceStopPackageLocked(final String packageName, int uid, String reason) {
-        forceStopPackageLocked(packageName, UserHandle.getAppId(uid), false,
-                false, true, false, false, UserHandle.getUserId(uid), reason);
-        Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED,
-                Uri.fromParts("package", packageName, null));
-        if (!mProcessesReady) {
-            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                    | Intent.FLAG_RECEIVER_FOREGROUND);
-        }
-        intent.putExtra(Intent.EXTRA_UID, uid);
-        intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(uid));
-        broadcastIntentLocked(null, null, intent,
-                null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                false, false,
-                MY_PID, Process.SYSTEM_UID, UserHandle.getUserId(uid));
-    }
-
-    private void forceStopUserLocked(int userId, String reason) {
-        forceStopPackageLocked(null, -1, false, false, true, false, false, userId, reason);
-        Intent intent = new Intent(Intent.ACTION_USER_STOPPED);
-        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                | Intent.FLAG_RECEIVER_FOREGROUND);
-        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
-        broadcastIntentLocked(null, null, intent,
-                null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                false, false,
-                MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
-    }
-
-    private final boolean killPackageProcessesLocked(String packageName, int appId,
-            int userId, int minOomAdj, boolean callerWillRestart, boolean allowRestart,
-            boolean doit, boolean evenPersistent, String reason) {
-        ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
-
-        // Remove all processes this package may have touched: all with the
-        // same UID (except for the system or root user), and all whose name
-        // matches the package name.
-        final String procNamePrefix = packageName != null ? (packageName + ":") : null;
-        final int NP = mProcessNames.getMap().size();
-        for (int ip=0; ip<NP; ip++) {
-            SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
-            final int NA = apps.size();
-            for (int ia=0; ia<NA; ia++) {
-                ProcessRecord app = apps.valueAt(ia);
-                if (app.persistent && !evenPersistent) {
-                    // we don't kill persistent processes
-                    continue;
-                }
-                if (app.removed) {
-                    if (doit) {
-                        procs.add(app);
-                    }
-                    continue;
-                }
-
-                // Skip process if it doesn't meet our oom adj requirement.
-                if (app.setAdj < minOomAdj) {
-                    continue;
-                }
-
-                // If no package is specified, we call all processes under the
-                // give user id.
-                if (packageName == null) {
-                    if (app.userId != userId) {
-                        continue;
-                    }
-                    if (appId >= 0 && UserHandle.getAppId(app.uid) != appId) {
-                        continue;
-                    }
-                // Package has been specified, we want to hit all processes
-                // that match it.  We need to qualify this by the processes
-                // that are running under the specified app and user ID.
-                } else {
-                    if (UserHandle.getAppId(app.uid) != appId) {
-                        continue;
-                    }
-                    if (userId != UserHandle.USER_ALL && app.userId != userId) {
-                        continue;
-                    }
-                    if (!app.pkgList.containsKey(packageName)) {
-                        continue;
-                    }
-                }
-
-                // Process has passed all conditions, kill it!
-                if (!doit) {
-                    return true;
-                }
-                app.removed = true;
-                procs.add(app);
-            }
-        }
-
-        int N = procs.size();
-        for (int i=0; i<N; i++) {
-            removeProcessLocked(procs.get(i), callerWillRestart, allowRestart, reason);
-        }
-        updateOomAdjLocked();
-        return N > 0;
-    }
-
-    private final boolean forceStopPackageLocked(String name, int appId,
-            boolean callerWillRestart, boolean purgeCache, boolean doit,
-            boolean evenPersistent, boolean uninstalling, int userId, String reason) {
-        int i;
-        int N;
-
-        if (userId == UserHandle.USER_ALL && name == null) {
-            Slog.w(TAG, "Can't force stop all processes of all users, that is insane!");
-        }
-
-        if (appId < 0 && name != null) {
-            try {
-                appId = UserHandle.getAppId(
-                        AppGlobals.getPackageManager().getPackageUid(name, 0));
-            } catch (RemoteException e) {
-            }
-        }
-
-        if (doit) {
-            if (name != null) {
-                Slog.i(TAG, "Force stopping " + name + " appid=" + appId
-                        + " user=" + userId + ": " + reason);
-            } else {
-                Slog.i(TAG, "Force stopping u" + userId + ": " + reason);
-            }
-
-            final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
-            for (int ip=pmap.size()-1; ip>=0; ip--) {
-                SparseArray<Long> ba = pmap.valueAt(ip);
-                for (i=ba.size()-1; i>=0; i--) {
-                    boolean remove = false;
-                    final int entUid = ba.keyAt(i);
-                    if (name != null) {
-                        if (userId == UserHandle.USER_ALL) {
-                            if (UserHandle.getAppId(entUid) == appId) {
-                                remove = true;
-                            }
-                        } else {
-                            if (entUid == UserHandle.getUid(userId, appId)) {
-                                remove = true;
-                            }
-                        }
-                    } else if (UserHandle.getUserId(entUid) == userId) {
-                        remove = true;
-                    }
-                    if (remove) {
-                        ba.removeAt(i);
-                    }
-                }
-                if (ba.size() == 0) {
-                    pmap.removeAt(ip);
-                }
-            }
-        }
-
-        boolean didSomething = killPackageProcessesLocked(name, appId, userId,
-                -100, callerWillRestart, true, doit, evenPersistent,
-                name == null ? ("stop user " + userId) : ("stop " + name));
-
-        if (mStackSupervisor.forceStopPackageLocked(name, doit, evenPersistent, userId)) {
-            if (!doit) {
-                return true;
-            }
-            didSomething = true;
-        }
-
-        if (mServices.forceStopLocked(name, userId, evenPersistent, doit)) {
-            if (!doit) {
-                return true;
-            }
-            didSomething = true;
-        }
-
-        if (name == null) {
-            // Remove all sticky broadcasts from this user.
-            mStickyBroadcasts.remove(userId);
-        }
-
-        ArrayList<ContentProviderRecord> providers = new ArrayList<ContentProviderRecord>();
-        if (mProviderMap.collectForceStopProviders(name, appId, doit, evenPersistent,
-                userId, providers)) {
-            if (!doit) {
-                return true;
-            }
-            didSomething = true;
-        }
-        N = providers.size();
-        for (i=0; i<N; i++) {
-            removeDyingProviderLocked(null, providers.get(i), true);
-        }
-
-        // Remove transient permissions granted from/to this package/user
-        removeUriPermissionsForPackageLocked(name, userId, false);
-
-        if (name == null || uninstalling) {
-            // Remove pending intents.  For now we only do this when force
-            // stopping users, because we have some problems when doing this
-            // for packages -- app widgets are not currently cleaned up for
-            // such packages, so they can be left with bad pending intents.
-            if (mIntentSenderRecords.size() > 0) {
-                Iterator<WeakReference<PendingIntentRecord>> it
-                        = mIntentSenderRecords.values().iterator();
-                while (it.hasNext()) {
-                    WeakReference<PendingIntentRecord> wpir = it.next();
-                    if (wpir == null) {
-                        it.remove();
-                        continue;
-                    }
-                    PendingIntentRecord pir = wpir.get();
-                    if (pir == null) {
-                        it.remove();
-                        continue;
-                    }
-                    if (name == null) {
-                        // Stopping user, remove all objects for the user.
-                        if (pir.key.userId != userId) {
-                            // Not the same user, skip it.
-                            continue;
-                        }
-                    } else {
-                        if (UserHandle.getAppId(pir.uid) != appId) {
-                            // Different app id, skip it.
-                            continue;
-                        }
-                        if (userId != UserHandle.USER_ALL && pir.key.userId != userId) {
-                            // Different user, skip it.
-                            continue;
-                        }
-                        if (!pir.key.packageName.equals(name)) {
-                            // Different package, skip it.
-                            continue;
-                        }
-                    }
-                    if (!doit) {
-                        return true;
-                    }
-                    didSomething = true;
-                    it.remove();
-                    pir.canceled = true;
-                    if (pir.key.activity != null) {
-                        pir.key.activity.pendingResults.remove(pir.ref);
-                    }
-                }
-            }
-        }
-
-        if (doit) {
-            if (purgeCache && name != null) {
-                AttributeCache ac = AttributeCache.instance();
-                if (ac != null) {
-                    ac.removePackage(name);
-                }
-            }
-            if (mBooted) {
-                mStackSupervisor.resumeTopActivitiesLocked();
-                mStackSupervisor.scheduleIdleLocked();
-            }
-        }
-
-        return didSomething;
-    }
-
-    private final boolean removeProcessLocked(ProcessRecord app,
-            boolean callerWillRestart, boolean allowRestart, String reason) {
-        final String name = app.processName;
-        final int uid = app.uid;
-        if (DEBUG_PROCESSES) Slog.d(
-            TAG, "Force removing proc " + app.toShortString() + " (" + name
-            + "/" + uid + ")");
-
-        mProcessNames.remove(name, uid);
-        mIsolatedProcesses.remove(app.uid);
-        if (mHeavyWeightProcess == app) {
-            mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
-                    mHeavyWeightProcess.userId, 0));
-            mHeavyWeightProcess = null;
-        }
-        boolean needRestart = false;
-        if (app.pid > 0 && app.pid != MY_PID) {
-            int pid = app.pid;
-            synchronized (mPidsSelfLocked) {
-                mPidsSelfLocked.remove(pid);
-                mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
-            }
-            killUnneededProcessLocked(app, reason);
-            handleAppDiedLocked(app, true, allowRestart);
-            removeLruProcessLocked(app);
-
-            if (app.persistent && !app.isolated) {
-                if (!callerWillRestart) {
-                    addAppLocked(app.info, false);
-                } else {
-                    needRestart = true;
-                }
-            }
-        } else {
-            mRemovedProcesses.add(app);
-        }
-
-        return needRestart;
-    }
-
-    private final void processStartTimedOutLocked(ProcessRecord app) {
-        final int pid = app.pid;
-        boolean gone = false;
-        synchronized (mPidsSelfLocked) {
-            ProcessRecord knownApp = mPidsSelfLocked.get(pid);
-            if (knownApp != null && knownApp.thread == null) {
-                mPidsSelfLocked.remove(pid);
-                gone = true;
-            }
-        }
-
-        if (gone) {
-            Slog.w(TAG, "Process " + app + " failed to attach");
-            EventLog.writeEvent(EventLogTags.AM_PROCESS_START_TIMEOUT, app.userId,
-                    pid, app.uid, app.processName);
-            mProcessNames.remove(app.processName, app.uid);
-            mIsolatedProcesses.remove(app.uid);
-            if (mHeavyWeightProcess == app) {
-                mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
-                        mHeavyWeightProcess.userId, 0));
-                mHeavyWeightProcess = null;
-            }
-            // Take care of any launching providers waiting for this process.
-            checkAppInLaunchingProvidersLocked(app, true);
-            // Take care of any services that are waiting for the process.
-            mServices.processStartTimedOutLocked(app);
-            killUnneededProcessLocked(app, "start timeout");
-            if (mBackupTarget != null && mBackupTarget.app.pid == pid) {
-                Slog.w(TAG, "Unattached app died before backup, skipping");
-                try {
-                    IBackupManager bm = IBackupManager.Stub.asInterface(
-                            ServiceManager.getService(Context.BACKUP_SERVICE));
-                    bm.agentDisconnected(app.info.packageName);
-                } catch (RemoteException e) {
-                    // Can't happen; the backup manager is local
-                }
-            }
-            if (isPendingBroadcastProcessLocked(pid)) {
-                Slog.w(TAG, "Unattached app died before broadcast acknowledged, skipping");
-                skipPendingBroadcastLocked(pid);
-            }
-        } else {
-            Slog.w(TAG, "Spurious process start timeout - pid not known for " + app);
-        }
-    }
-
-    private final boolean attachApplicationLocked(IApplicationThread thread,
-            int pid) {
-
-        // Find the application record that is being attached...  either via
-        // the pid if we are running in multiple processes, or just pull the
-        // next app record if we are emulating process with anonymous threads.
-        ProcessRecord app;
-        if (pid != MY_PID && pid >= 0) {
-            synchronized (mPidsSelfLocked) {
-                app = mPidsSelfLocked.get(pid);
-            }
-        } else {
-            app = null;
-        }
-
-        if (app == null) {
-            Slog.w(TAG, "No pending application record for pid " + pid
-                    + " (IApplicationThread " + thread + "); dropping process");
-            EventLog.writeEvent(EventLogTags.AM_DROP_PROCESS, pid);
-            if (pid > 0 && pid != MY_PID) {
-                Process.killProcessQuiet(pid);
-            } else {
-                try {
-                    thread.scheduleExit();
-                } catch (Exception e) {
-                    // Ignore exceptions.
-                }
-            }
-            return false;
-        }
-
-        // If this application record is still attached to a previous
-        // process, clean it up now.
-        if (app.thread != null) {
-            handleAppDiedLocked(app, true, true);
-        }
-
-        // Tell the process all about itself.
-
-        if (localLOGV) Slog.v(
-                TAG, "Binding process pid " + pid + " to record " + app);
-
-        final String processName = app.processName;
-        try {
-            AppDeathRecipient adr = new AppDeathRecipient(
-                    app, pid, thread);
-            thread.asBinder().linkToDeath(adr, 0);
-            app.deathRecipient = adr;
-        } catch (RemoteException e) {
-            app.resetPackageList(mProcessStats);
-            startProcessLocked(app, "link fail", processName);
-            return false;
-        }
-
-        EventLog.writeEvent(EventLogTags.AM_PROC_BOUND, app.userId, app.pid, app.processName);
-
-        app.makeActive(thread, mProcessStats);
-        app.curAdj = app.setAdj = -100;
-        app.curSchedGroup = app.setSchedGroup = Process.THREAD_GROUP_DEFAULT;
-        app.forcingToForeground = null;
-        app.foregroundServices = false;
-        app.hasShownUi = false;
-        app.debugging = false;
-        app.cached = false;
-
-        mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
-
-        boolean normalMode = mProcessesReady || isAllowedWhileBooting(app.info);
-        List<ProviderInfo> providers = normalMode ? generateApplicationProvidersLocked(app) : null;
-
-        if (!normalMode) {
-            Slog.i(TAG, "Launching preboot mode app: " + app);
-        }
-
-        if (localLOGV) Slog.v(
-            TAG, "New app record " + app
-            + " thread=" + thread.asBinder() + " pid=" + pid);
-        try {
-            int testMode = IApplicationThread.DEBUG_OFF;
-            if (mDebugApp != null && mDebugApp.equals(processName)) {
-                testMode = mWaitForDebugger
-                    ? IApplicationThread.DEBUG_WAIT
-                    : IApplicationThread.DEBUG_ON;
-                app.debugging = true;
-                if (mDebugTransient) {
-                    mDebugApp = mOrigDebugApp;
-                    mWaitForDebugger = mOrigWaitForDebugger;
-                }
-            }
-            String profileFile = app.instrumentationProfileFile;
-            ParcelFileDescriptor profileFd = null;
-            boolean profileAutoStop = false;
-            if (mProfileApp != null && mProfileApp.equals(processName)) {
-                mProfileProc = app;
-                profileFile = mProfileFile;
-                profileFd = mProfileFd;
-                profileAutoStop = mAutoStopProfiler;
-            }
-            boolean enableOpenGlTrace = false;
-            if (mOpenGlTraceApp != null && mOpenGlTraceApp.equals(processName)) {
-                enableOpenGlTrace = true;
-                mOpenGlTraceApp = null;
-            }
-
-            // If the app is being launched for restore or full backup, set it up specially
-            boolean isRestrictedBackupMode = false;
-            if (mBackupTarget != null && mBackupAppName.equals(processName)) {
-                isRestrictedBackupMode = (mBackupTarget.backupMode == BackupRecord.RESTORE)
-                        || (mBackupTarget.backupMode == BackupRecord.RESTORE_FULL)
-                        || (mBackupTarget.backupMode == BackupRecord.BACKUP_FULL);
-            }
-
-            ensurePackageDexOpt(app.instrumentationInfo != null
-                    ? app.instrumentationInfo.packageName
-                    : app.info.packageName);
-            if (app.instrumentationClass != null) {
-                ensurePackageDexOpt(app.instrumentationClass.getPackageName());
-            }
-            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Binding proc "
-                    + processName + " with config " + mConfiguration);
-            ApplicationInfo appInfo = app.instrumentationInfo != null
-                    ? app.instrumentationInfo : app.info;
-            app.compat = compatibilityInfoForPackageLocked(appInfo);
-            if (profileFd != null) {
-                profileFd = profileFd.dup();
-            }
-            thread.bindApplication(processName, appInfo, providers,
-                    app.instrumentationClass, profileFile, profileFd, profileAutoStop,
-                    app.instrumentationArguments, app.instrumentationWatcher,
-                    app.instrumentationUiAutomationConnection, testMode, enableOpenGlTrace,
-                    isRestrictedBackupMode || !normalMode, app.persistent,
-                    new Configuration(mConfiguration), app.compat, getCommonServicesLocked(),
-                    mCoreSettingsObserver.getCoreSettingsLocked());
-            updateLruProcessLocked(app, false, null);
-            app.lastRequestedGc = app.lastLowMemory = SystemClock.uptimeMillis();
-        } catch (Exception e) {
-            // todo: Yikes!  What should we do?  For now we will try to
-            // start another process, but that could easily get us in
-            // an infinite loop of restarting processes...
-            Slog.w(TAG, "Exception thrown during bind!", e);
-
-            app.resetPackageList(mProcessStats);
-            app.unlinkDeathRecipient();
-            startProcessLocked(app, "bind fail", processName);
-            return false;
-        }
-
-        // Remove this record from the list of starting applications.
-        mPersistentStartingProcesses.remove(app);
-        if (DEBUG_PROCESSES && mProcessesOnHold.contains(app)) Slog.v(TAG,
-                "Attach application locked removing on hold: " + app);
-        mProcessesOnHold.remove(app);
-
-        boolean badApp = false;
-        boolean didSomething = false;
-
-        // See if the top visible activity is waiting to run in this process...
-        if (normalMode) {
-            try {
-                if (mStackSupervisor.attachApplicationLocked(app, mHeadless)) {
-                    didSomething = true;
-                }
-            } catch (Exception e) {
-                badApp = true;
-            }
-        }
-
-        // Find any services that should be running in this process...
-        if (!badApp) {
-            try {
-                didSomething |= mServices.attachApplicationLocked(app, processName);
-            } catch (Exception e) {
-                badApp = true;
-            }
-        }
-
-        // Check if a next-broadcast receiver is in this process...
-        if (!badApp && isPendingBroadcastProcessLocked(pid)) {
-            try {
-                didSomething |= sendPendingBroadcastsLocked(app);
-            } catch (Exception e) {
-                // If the app died trying to launch the receiver we declare it 'bad'
-                badApp = true;
-            }
-        }
-
-        // Check whether the next backup agent is in this process...
-        if (!badApp && mBackupTarget != null && mBackupTarget.appInfo.uid == app.uid) {
-            if (DEBUG_BACKUP) Slog.v(TAG, "New app is backup target, launching agent for " + app);
-            ensurePackageDexOpt(mBackupTarget.appInfo.packageName);
-            try {
-                thread.scheduleCreateBackupAgent(mBackupTarget.appInfo,
-                        compatibilityInfoForPackageLocked(mBackupTarget.appInfo),
-                        mBackupTarget.backupMode);
-            } catch (Exception e) {
-                Slog.w(TAG, "Exception scheduling backup agent creation: ");
-                e.printStackTrace();
-            }
-        }
-
-        if (badApp) {
-            // todo: Also need to kill application to deal with all
-            // kinds of exceptions.
-            handleAppDiedLocked(app, false, true);
-            return false;
-        }
-
-        if (!didSomething) {
-            updateOomAdjLocked();
-        }
-
-        return true;
-    }
-
-    @Override
-    public final void attachApplication(IApplicationThread thread) {
-        synchronized (this) {
-            int callingPid = Binder.getCallingPid();
-            final long origId = Binder.clearCallingIdentity();
-            attachApplicationLocked(thread, callingPid);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public final void activityIdle(IBinder token, Configuration config, boolean stopProfiling) {
-        final long origId = Binder.clearCallingIdentity();
-        synchronized (this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                ActivityRecord r =
-                        mStackSupervisor.activityIdleInternalLocked(token, false, config);
-                if (stopProfiling) {
-                    if ((mProfileProc == r.app) && (mProfileFd != null)) {
-                        try {
-                            mProfileFd.close();
-                        } catch (IOException e) {
-                        }
-                        clearProfilerLocked();
-                    }
-                }
-            }
-        }
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    void enableScreenAfterBoot() {
-        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_ENABLE_SCREEN,
-                SystemClock.uptimeMillis());
-        mWindowManager.enableScreenAfterBoot();
-
-        synchronized (this) {
-            updateEventDispatchingLocked();
-        }
-    }
-
-    @Override
-    public void showBootMessage(final CharSequence msg, final boolean always) {
-        enforceNotIsolatedCaller("showBootMessage");
-        mWindowManager.showBootMessage(msg, always);
-    }
-
-    @Override
-    public void dismissKeyguardOnNextActivity() {
-        enforceNotIsolatedCaller("dismissKeyguardOnNextActivity");
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (this) {
-                if (DEBUG_LOCKSCREEN) logLockScreen("");
-                if (mLockScreenShown) {
-                    mLockScreenShown = false;
-                    comeOutOfSleepIfNeededLocked();
-                }
-                mStackSupervisor.setDismissKeyguard(true);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    final void finishBooting() {
-        IntentFilter pkgFilter = new IntentFilter();
-        pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
-        pkgFilter.addDataScheme("package");
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                String[] pkgs = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
-                if (pkgs != null) {
-                    for (String pkg : pkgs) {
-                        synchronized (ActivityManagerService.this) {
-                            if (forceStopPackageLocked(pkg, -1, false, false, false, false, false, 0,
-                                    "finished booting")) {
-                                setResultCode(Activity.RESULT_OK);
-                                return;
-                            }
-                        }
-                    }
-                }
-            }
-        }, pkgFilter);
-
-        synchronized (this) {
-            // Ensure that any processes we had put on hold are now started
-            // up.
-            final int NP = mProcessesOnHold.size();
-            if (NP > 0) {
-                ArrayList<ProcessRecord> procs =
-                    new ArrayList<ProcessRecord>(mProcessesOnHold);
-                for (int ip=0; ip<NP; ip++) {
-                    if (DEBUG_PROCESSES) Slog.v(TAG, "Starting process on hold: "
-                            + procs.get(ip));
-                    startProcessLocked(procs.get(ip), "on-hold", null);
-                }
-            }
-            
-            if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
-                // Start looking for apps that are abusing wake locks.
-                Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
-                mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
-                // Tell anyone interested that we are done booting!
-                SystemProperties.set("sys.boot_completed", "1");
-                SystemProperties.set("dev.bootcomplete", "1");
-                for (int i=0; i<mStartedUsers.size(); i++) {
-                    UserStartedState uss = mStartedUsers.valueAt(i);
-                    if (uss.mState == UserStartedState.STATE_BOOTING) {
-                        uss.mState = UserStartedState.STATE_RUNNING;
-                        final int userId = mStartedUsers.keyAt(i);
-                        Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
-                        intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
-                        intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT);
-                        broadcastIntentLocked(null, null, intent, null,
-                                new IIntentReceiver.Stub() {
-                                    @Override
-                                    public void performReceive(Intent intent, int resultCode,
-                                            String data, Bundle extras, boolean ordered,
-                                            boolean sticky, int sendingUser) {
-                                        synchronized (ActivityManagerService.this) {
-                                            requestPssAllProcsLocked(SystemClock.uptimeMillis(),
-                                                    true, false);
-                                        }
-                                    }
-                                },
-                                0, null, null,
-                                android.Manifest.permission.RECEIVE_BOOT_COMPLETED,
-                                AppOpsManager.OP_NONE, true, false, MY_PID, Process.SYSTEM_UID,
-                                userId);
-                    }
-                }
-            }
-        }
-    }
-    
-    final void ensureBootCompleted() {
-        boolean booting;
-        boolean enableScreen;
-        synchronized (this) {
-            booting = mBooting;
-            mBooting = false;
-            enableScreen = !mBooted;
-            mBooted = true;
-        }
-        
-        if (booting) {
-            finishBooting();
-        }
-
-        if (enableScreen) {
-            enableScreenAfterBoot();
-        }
-    }
-
-    @Override
-    public final void activityResumed(IBinder token) {
-        final long origId = Binder.clearCallingIdentity();
-        synchronized(this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                ActivityRecord.activityResumedLocked(token);
-            }
-        }
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    @Override
-    public final void activityPaused(IBinder token) {
-        final long origId = Binder.clearCallingIdentity();
-        synchronized(this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                stack.activityPausedLocked(token, false);
-            }
-        }
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    @Override
-    public final void activityStopped(IBinder token, Bundle icicle, Bitmap thumbnail,
-            CharSequence description) {
-        if (localLOGV) Slog.v(
-            TAG, "Activity stopped: token=" + token);
-
-        // Refuse possible leaked file descriptors
-        if (icicle != null && icicle.hasFileDescriptors()) {
-            throw new IllegalArgumentException("File descriptors passed in Bundle");
-        }
-
-        ActivityRecord r = null;
-
-        final long origId = Binder.clearCallingIdentity();
-
-        synchronized (this) {
-            r = ActivityRecord.isInStackLocked(token);
-            if (r != null) {
-                r.task.stack.activityStoppedLocked(r, icicle, thumbnail, description);
-            }
-        }
-
-        if (r != null) {
-            sendPendingThumbnail(r, null, null, null, false);
-        }
-
-        trimApplications();
-
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    @Override
-    public final void activityDestroyed(IBinder token) {
-        if (DEBUG_SWITCH) Slog.v(TAG, "ACTIVITY DESTROYED: " + token);
-        synchronized (this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                stack.activityDestroyedLocked(token);
-            }
-        }
-    }
-    
-    @Override
-    public String getCallingPackage(IBinder token) {
-        synchronized (this) {
-            ActivityRecord r = getCallingRecordLocked(token);
-            return r != null ? r.info.packageName : null;
-        }
-    }
-
-    @Override
-    public ComponentName getCallingActivity(IBinder token) {
-        synchronized (this) {
-            ActivityRecord r = getCallingRecordLocked(token);
-            return r != null ? r.intent.getComponent() : null;
-        }
-    }
-
-    private ActivityRecord getCallingRecordLocked(IBinder token) {
-        ActivityRecord r = ActivityRecord.isInStackLocked(token);
-        if (r == null) {
-            return null;
-        }
-        return r.resultTo;
-    }
-
-    @Override
-    public ComponentName getActivityClassForToken(IBinder token) {
-        synchronized(this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                return null;
-            }
-            return r.intent.getComponent();
-        }
-    }
-
-    @Override
-    public String getPackageForToken(IBinder token) {
-        synchronized(this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                return null;
-            }
-            return r.packageName;
-        }
-    }
-
-    @Override
-    public IIntentSender getIntentSender(int type,
-            String packageName, IBinder token, String resultWho,
-            int requestCode, Intent[] intents, String[] resolvedTypes,
-            int flags, Bundle options, int userId) {
-        enforceNotIsolatedCaller("getIntentSender");
-        // Refuse possible leaked file descriptors
-        if (intents != null) {
-            if (intents.length < 1) {
-                throw new IllegalArgumentException("Intents array length must be >= 1");
-            }
-            for (int i=0; i<intents.length; i++) {
-                Intent intent = intents[i];
-                if (intent != null) {
-                    if (intent.hasFileDescriptors()) {
-                        throw new IllegalArgumentException("File descriptors passed in Intent");
-                    }
-                    if (type == ActivityManager.INTENT_SENDER_BROADCAST &&
-                            (intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
-                        throw new IllegalArgumentException(
-                                "Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
-                    }
-                    intents[i] = new Intent(intent);
-                }
-            }
-            if (resolvedTypes != null && resolvedTypes.length != intents.length) {
-                throw new IllegalArgumentException(
-                        "Intent array length does not match resolvedTypes length");
-            }
-        }
-        if (options != null) {
-            if (options.hasFileDescriptors()) {
-                throw new IllegalArgumentException("File descriptors passed in options");
-            }
-        }
-        
-        synchronized(this) {
-            int callingUid = Binder.getCallingUid();
-            int origUserId = userId;
-            userId = handleIncomingUser(Binder.getCallingPid(), callingUid, userId,
-                    type == ActivityManager.INTENT_SENDER_BROADCAST, false,
-                    "getIntentSender", null);
-            if (origUserId == UserHandle.USER_CURRENT) {
-                // We don't want to evaluate this until the pending intent is
-                // actually executed.  However, we do want to always do the
-                // security checking for it above.
-                userId = UserHandle.USER_CURRENT;
-            }
-            try {
-                if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
-                    int uid = AppGlobals.getPackageManager()
-                            .getPackageUid(packageName, UserHandle.getUserId(callingUid));
-                    if (!UserHandle.isSameApp(callingUid, uid)) {
-                        String msg = "Permission Denial: getIntentSender() from pid="
-                            + Binder.getCallingPid()
-                            + ", uid=" + Binder.getCallingUid()
-                            + ", (need uid=" + uid + ")"
-                            + " is not allowed to send as package " + packageName;
-                        Slog.w(TAG, msg);
-                        throw new SecurityException(msg);
-                    }
-                }
-
-                return getIntentSenderLocked(type, packageName, callingUid, userId,
-                        token, resultWho, requestCode, intents, resolvedTypes, flags, options);
-                
-            } catch (RemoteException e) {
-                throw new SecurityException(e);
-            }
-        }
-    }
-
-    IIntentSender getIntentSenderLocked(int type, String packageName,
-            int callingUid, int userId, IBinder token, String resultWho,
-            int requestCode, Intent[] intents, String[] resolvedTypes, int flags,
-            Bundle options) {
-        if (DEBUG_MU)
-            Slog.v(TAG_MU, "getIntentSenderLocked(): uid=" + callingUid);
-        ActivityRecord activity = null;
-        if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) {
-            activity = ActivityRecord.isInStackLocked(token);
-            if (activity == null) {
-                return null;
-            }
-            if (activity.finishing) {
-                return null;
-            }
-        }
-
-        final boolean noCreate = (flags&PendingIntent.FLAG_NO_CREATE) != 0;
-        final boolean cancelCurrent = (flags&PendingIntent.FLAG_CANCEL_CURRENT) != 0;
-        final boolean updateCurrent = (flags&PendingIntent.FLAG_UPDATE_CURRENT) != 0;
-        flags &= ~(PendingIntent.FLAG_NO_CREATE|PendingIntent.FLAG_CANCEL_CURRENT
-                |PendingIntent.FLAG_UPDATE_CURRENT);
-
-        PendingIntentRecord.Key key = new PendingIntentRecord.Key(
-                type, packageName, activity, resultWho,
-                requestCode, intents, resolvedTypes, flags, options, userId);
-        WeakReference<PendingIntentRecord> ref;
-        ref = mIntentSenderRecords.get(key);
-        PendingIntentRecord rec = ref != null ? ref.get() : null;
-        if (rec != null) {
-            if (!cancelCurrent) {
-                if (updateCurrent) {
-                    if (rec.key.requestIntent != null) {
-                        rec.key.requestIntent.replaceExtras(intents != null ?
-                                intents[intents.length - 1] : null);
-                    }
-                    if (intents != null) {
-                        intents[intents.length-1] = rec.key.requestIntent;
-                        rec.key.allIntents = intents;
-                        rec.key.allResolvedTypes = resolvedTypes;
-                    } else {
-                        rec.key.allIntents = null;
-                        rec.key.allResolvedTypes = null;
-                    }
-                }
-                return rec;
-            }
-            rec.canceled = true;
-            mIntentSenderRecords.remove(key);
-        }
-        if (noCreate) {
-            return rec;
-        }
-        rec = new PendingIntentRecord(this, key, callingUid);
-        mIntentSenderRecords.put(key, rec.ref);
-        if (type == ActivityManager.INTENT_SENDER_ACTIVITY_RESULT) {
-            if (activity.pendingResults == null) {
-                activity.pendingResults
-                        = new HashSet<WeakReference<PendingIntentRecord>>();
-            }
-            activity.pendingResults.add(rec.ref);
-        }
-        return rec;
-    }
-
-    @Override
-    public void cancelIntentSender(IIntentSender sender) {
-        if (!(sender instanceof PendingIntentRecord)) {
-            return;
-        }
-        synchronized(this) {
-            PendingIntentRecord rec = (PendingIntentRecord)sender;
-            try {
-                int uid = AppGlobals.getPackageManager()
-                        .getPackageUid(rec.key.packageName, UserHandle.getCallingUserId());
-                if (!UserHandle.isSameApp(uid, Binder.getCallingUid())) {
-                    String msg = "Permission Denial: cancelIntentSender() from pid="
-                        + Binder.getCallingPid()
-                        + ", uid=" + Binder.getCallingUid()
-                        + " is not allowed to cancel packges "
-                        + rec.key.packageName;
-                    Slog.w(TAG, msg);
-                    throw new SecurityException(msg);
-                }
-            } catch (RemoteException e) {
-                throw new SecurityException(e);
-            }
-            cancelIntentSenderLocked(rec, true);
-        }
-    }
-
-    void cancelIntentSenderLocked(PendingIntentRecord rec, boolean cleanActivity) {
-        rec.canceled = true;
-        mIntentSenderRecords.remove(rec.key);
-        if (cleanActivity && rec.key.activity != null) {
-            rec.key.activity.pendingResults.remove(rec.ref);
-        }
-    }
-
-    @Override
-    public String getPackageForIntentSender(IIntentSender pendingResult) {
-        if (!(pendingResult instanceof PendingIntentRecord)) {
-            return null;
-        }
-        try {
-            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
-            return res.key.packageName;
-        } catch (ClassCastException e) {
-        }
-        return null;
-    }
-
-    @Override
-    public int getUidForIntentSender(IIntentSender sender) {
-        if (sender instanceof PendingIntentRecord) {
-            try {
-                PendingIntentRecord res = (PendingIntentRecord)sender;
-                return res.uid;
-            } catch (ClassCastException e) {
-            }
-        }
-        return -1;
-    }
-
-    @Override
-    public boolean isIntentSenderTargetedToPackage(IIntentSender pendingResult) {
-        if (!(pendingResult instanceof PendingIntentRecord)) {
-            return false;
-        }
-        try {
-            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
-            if (res.key.allIntents == null) {
-                return false;
-            }
-            for (int i=0; i<res.key.allIntents.length; i++) {
-                Intent intent = res.key.allIntents[i];
-                if (intent.getPackage() != null && intent.getComponent() != null) {
-                    return false;
-                }
-            }
-            return true;
-        } catch (ClassCastException e) {
-        }
-        return false;
-    }
-
-    @Override
-    public boolean isIntentSenderAnActivity(IIntentSender pendingResult) {
-        if (!(pendingResult instanceof PendingIntentRecord)) {
-            return false;
-        }
-        try {
-            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
-            if (res.key.type == ActivityManager.INTENT_SENDER_ACTIVITY) {
-                return true;
-            }
-            return false;
-        } catch (ClassCastException e) {
-        }
-        return false;
-    }
-
-    @Override
-    public Intent getIntentForIntentSender(IIntentSender pendingResult) {
-        if (!(pendingResult instanceof PendingIntentRecord)) {
-            return null;
-        }
-        try {
-            PendingIntentRecord res = (PendingIntentRecord)pendingResult;
-            return res.key.requestIntent != null ? new Intent(res.key.requestIntent) : null;
-        } catch (ClassCastException e) {
-        }
-        return null;
-    }
-
-    @Override
-    public void setProcessLimit(int max) {
-        enforceCallingPermission(android.Manifest.permission.SET_PROCESS_LIMIT,
-                "setProcessLimit()");
-        synchronized (this) {
-            mProcessLimit = max < 0 ? ProcessList.MAX_CACHED_APPS : max;
-            mProcessLimitOverride = max;
-        }
-        trimApplications();
-    }
-
-    @Override
-    public int getProcessLimit() {
-        synchronized (this) {
-            return mProcessLimitOverride;
-        }
-    }
-
-    void foregroundTokenDied(ForegroundToken token) {
-        synchronized (ActivityManagerService.this) {
-            synchronized (mPidsSelfLocked) {
-                ForegroundToken cur
-                    = mForegroundProcesses.get(token.pid);
-                if (cur != token) {
-                    return;
-                }
-                mForegroundProcesses.remove(token.pid);
-                ProcessRecord pr = mPidsSelfLocked.get(token.pid);
-                if (pr == null) {
-                    return;
-                }
-                pr.forcingToForeground = null;
-                pr.foregroundServices = false;
-            }
-            updateOomAdjLocked();
-        }
-    }
-
-    @Override
-    public void setProcessForeground(IBinder token, int pid, boolean isForeground) {
-        enforceCallingPermission(android.Manifest.permission.SET_PROCESS_LIMIT,
-                "setProcessForeground()");
-        synchronized(this) {
-            boolean changed = false;
-            
-            synchronized (mPidsSelfLocked) {
-                ProcessRecord pr = mPidsSelfLocked.get(pid);
-                if (pr == null && isForeground) {
-                    Slog.w(TAG, "setProcessForeground called on unknown pid: " + pid);
-                    return;
-                }
-                ForegroundToken oldToken = mForegroundProcesses.get(pid);
-                if (oldToken != null) {
-                    oldToken.token.unlinkToDeath(oldToken, 0);
-                    mForegroundProcesses.remove(pid);
-                    if (pr != null) {
-                        pr.forcingToForeground = null;
-                    }
-                    changed = true;
-                }
-                if (isForeground && token != null) {
-                    ForegroundToken newToken = new ForegroundToken() {
-                        @Override
-                        public void binderDied() {
-                            foregroundTokenDied(this);
-                        }
-                    };
-                    newToken.pid = pid;
-                    newToken.token = token;
-                    try {
-                        token.linkToDeath(newToken, 0);
-                        mForegroundProcesses.put(pid, newToken);
-                        pr.forcingToForeground = token;
-                        changed = true;
-                    } catch (RemoteException e) {
-                        // If the process died while doing this, we will later
-                        // do the cleanup with the process death link.
-                    }
-                }
-            }
-            
-            if (changed) {
-                updateOomAdjLocked();
-            }
-        }
-    }
-    
-    // =========================================================
-    // PERMISSIONS
-    // =========================================================
-
-    static class PermissionController extends IPermissionController.Stub {
-        ActivityManagerService mActivityManagerService;
-        PermissionController(ActivityManagerService activityManagerService) {
-            mActivityManagerService = activityManagerService;
-        }
-
-        @Override
-        public boolean checkPermission(String permission, int pid, int uid) {
-            return mActivityManagerService.checkPermission(permission, pid,
-                    uid) == PackageManager.PERMISSION_GRANTED;
-        }
-    }
-
-    class IntentFirewallInterface implements IntentFirewall.AMSInterface {
-        @Override
-        public int checkComponentPermission(String permission, int pid, int uid,
-                int owningUid, boolean exported) {
-            return ActivityManagerService.this.checkComponentPermission(permission, pid, uid,
-                    owningUid, exported);
-        }
-
-        @Override
-        public Object getAMSLock() {
-            return ActivityManagerService.this;
-        }
-    }
-
-    /**
-     * This can be called with or without the global lock held.
-     */
-    int checkComponentPermission(String permission, int pid, int uid,
-            int owningUid, boolean exported) {
-        // We might be performing an operation on behalf of an indirect binder
-        // invocation, e.g. via {@link #openContentUri}.  Check and adjust the
-        // client identity accordingly before proceeding.
-        Identity tlsIdentity = sCallerIdentity.get();
-        if (tlsIdentity != null) {
-            Slog.d(TAG, "checkComponentPermission() adjusting {pid,uid} to {"
-                    + tlsIdentity.pid + "," + tlsIdentity.uid + "}");
-            uid = tlsIdentity.uid;
-            pid = tlsIdentity.pid;
-        }
-
-        if (pid == MY_PID) {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-
-        return ActivityManager.checkComponentPermission(permission, uid,
-                owningUid, exported);
-    }
-
-    /**
-     * As the only public entry point for permissions checking, this method
-     * can enforce the semantic that requesting a check on a null global
-     * permission is automatically denied.  (Internally a null permission
-     * string is used when calling {@link #checkComponentPermission} in cases
-     * when only uid-based security is needed.)
-     * 
-     * This can be called with or without the global lock held.
-     */
-    @Override
-    public int checkPermission(String permission, int pid, int uid) {
-        if (permission == null) {
-            return PackageManager.PERMISSION_DENIED;
-        }
-        return checkComponentPermission(permission, pid, UserHandle.getAppId(uid), -1, true);
-    }
-
-    /**
-     * Binder IPC calls go through the public entry point.
-     * This can be called with or without the global lock held.
-     */
-    int checkCallingPermission(String permission) {
-        return checkPermission(permission,
-                Binder.getCallingPid(),
-                UserHandle.getAppId(Binder.getCallingUid()));
-    }
-
-    /**
-     * This can be called with or without the global lock held.
-     */
-    void enforceCallingPermission(String permission, String func) {
-        if (checkCallingPermission(permission)
-                == PackageManager.PERMISSION_GRANTED) {
-            return;
-        }
-
-        String msg = "Permission Denial: " + func + " from pid="
-                + Binder.getCallingPid()
-                + ", uid=" + Binder.getCallingUid()
-                + " requires " + permission;
-        Slog.w(TAG, msg);
-        throw new SecurityException(msg);
-    }
-
-    /**
-     * Determine if UID is holding permissions required to access {@link Uri} in
-     * the given {@link ProviderInfo}. Final permission checking is always done
-     * in {@link ContentProvider}.
-     */
-    private final boolean checkHoldingPermissionsLocked(
-            IPackageManager pm, ProviderInfo pi, Uri uri, int uid, int modeFlags) {
-        if (DEBUG_URI_PERMISSION) Slog.v(TAG,
-                "checkHoldingPermissionsLocked: uri=" + uri + " uid=" + uid);
-
-        if (pi.applicationInfo.uid == uid) {
-            return true;
-        } else if (!pi.exported) {
-            return false;
-        }
-
-        boolean readMet = (modeFlags & Intent.FLAG_GRANT_READ_URI_PERMISSION) == 0;
-        boolean writeMet = (modeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0;
-        try {
-            // check if target holds top-level <provider> permissions
-            if (!readMet && pi.readPermission != null
-                    && (pm.checkUidPermission(pi.readPermission, uid) == PERMISSION_GRANTED)) {
-                readMet = true;
-            }
-            if (!writeMet && pi.writePermission != null
-                    && (pm.checkUidPermission(pi.writePermission, uid) == PERMISSION_GRANTED)) {
-                writeMet = true;
-            }
-
-            // track if unprotected read/write is allowed; any denied
-            // <path-permission> below removes this ability
-            boolean allowDefaultRead = pi.readPermission == null;
-            boolean allowDefaultWrite = pi.writePermission == null;
-
-            // check if target holds any <path-permission> that match uri
-            final PathPermission[] pps = pi.pathPermissions;
-            if (pps != null) {
-                final String path = uri.getPath();
-                int i = pps.length;
-                while (i > 0 && (!readMet || !writeMet)) {
-                    i--;
-                    PathPermission pp = pps[i];
-                    if (pp.match(path)) {
-                        if (!readMet) {
-                            final String pprperm = pp.getReadPermission();
-                            if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Checking read perm for "
-                                    + pprperm + " for " + pp.getPath()
-                                    + ": match=" + pp.match(path)
-                                    + " check=" + pm.checkUidPermission(pprperm, uid));
-                            if (pprperm != null) {
-                                if (pm.checkUidPermission(pprperm, uid) == PERMISSION_GRANTED) {
-                                    readMet = true;
-                                } else {
-                                    allowDefaultRead = false;
-                                }
-                            }
-                        }
-                        if (!writeMet) {
-                            final String ppwperm = pp.getWritePermission();
-                            if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Checking write perm "
-                                    + ppwperm + " for " + pp.getPath()
-                                    + ": match=" + pp.match(path)
-                                    + " check=" + pm.checkUidPermission(ppwperm, uid));
-                            if (ppwperm != null) {
-                                if (pm.checkUidPermission(ppwperm, uid) == PERMISSION_GRANTED) {
-                                    writeMet = true;
-                                } else {
-                                    allowDefaultWrite = false;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-            // grant unprotected <provider> read/write, if not blocked by
-            // <path-permission> above
-            if (allowDefaultRead) readMet = true;
-            if (allowDefaultWrite) writeMet = true;
-
-        } catch (RemoteException e) {
-            return false;
-        }
-
-        return readMet && writeMet;
-    }
-
-    private ProviderInfo getProviderInfoLocked(String authority, int userHandle) {
-        ProviderInfo pi = null;
-        ContentProviderRecord cpr = mProviderMap.getProviderByName(authority, userHandle);
-        if (cpr != null) {
-            pi = cpr.info;
-        } else {
-            try {
-                pi = AppGlobals.getPackageManager().resolveContentProvider(
-                        authority, PackageManager.GET_URI_PERMISSION_PATTERNS, userHandle);
-            } catch (RemoteException ex) {
-            }
-        }
-        return pi;
-    }
-
-    private UriPermission findUriPermissionLocked(int targetUid, Uri uri) {
-        ArrayMap<Uri, UriPermission> targetUris = mGrantedUriPermissions.get(targetUid);
-        if (targetUris != null) {
-            return targetUris.get(uri);
-        } else {
-            return null;
-        }
-    }
-
-    private UriPermission findOrCreateUriPermissionLocked(
-            String sourcePkg, String targetPkg, int targetUid, Uri uri) {
-        ArrayMap<Uri, UriPermission> targetUris = mGrantedUriPermissions.get(targetUid);
-        if (targetUris == null) {
-            targetUris = Maps.newArrayMap();
-            mGrantedUriPermissions.put(targetUid, targetUris);
-        }
-
-        UriPermission perm = targetUris.get(uri);
-        if (perm == null) {
-            perm = new UriPermission(sourcePkg, targetPkg, targetUid, uri);
-            targetUris.put(uri, perm);
-        }
-
-        return perm;
-    }
-
-    private final boolean checkUriPermissionLocked(
-            Uri uri, int uid, int modeFlags, int minStrength) {
-        // Root gets to do everything.
-        if (uid == 0) {
-            return true;
-        }
-        ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(uid);
-        if (perms == null) return false;
-        UriPermission perm = perms.get(uri);
-        if (perm == null) return false;
-        return perm.getStrength(modeFlags) >= minStrength;
-    }
-
-    @Override
-    public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) {
-        enforceNotIsolatedCaller("checkUriPermission");
-
-        // Another redirected-binder-call permissions check as in
-        // {@link checkComponentPermission}.
-        Identity tlsIdentity = sCallerIdentity.get();
-        if (tlsIdentity != null) {
-            uid = tlsIdentity.uid;
-            pid = tlsIdentity.pid;
-        }
-
-        // Our own process gets to do everything.
-        if (pid == MY_PID) {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-        synchronized(this) {
-            return checkUriPermissionLocked(uri, uid, modeFlags, UriPermission.STRENGTH_OWNED)
-                    ? PackageManager.PERMISSION_GRANTED
-                    : PackageManager.PERMISSION_DENIED;
-        }
-    }
-
-    /**
-     * Check if the targetPkg can be granted permission to access uri by
-     * the callingUid using the given modeFlags.  Throws a security exception
-     * if callingUid is not allowed to do this.  Returns the uid of the target
-     * if the URI permission grant should be performed; returns -1 if it is not
-     * needed (for example targetPkg already has permission to access the URI).
-     * If you already know the uid of the target, you can supply it in
-     * lastTargetUid else set that to -1.
-     */
-    int checkGrantUriPermissionLocked(int callingUid, String targetPkg,
-            Uri uri, int modeFlags, int lastTargetUid) {
-        final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
-        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
-                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-        if (modeFlags == 0) {
-            return -1;
-        }
-
-        if (targetPkg != null) {
-            if (DEBUG_URI_PERMISSION) Slog.v(TAG,
-                    "Checking grant " + targetPkg + " permission to " + uri);
-        }
-        
-        final IPackageManager pm = AppGlobals.getPackageManager();
-
-        // If this is not a content: uri, we can't do anything with it.
-        if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
-            if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
-                    "Can't grant URI permission for non-content URI: " + uri);
-            return -1;
-        }
-
-        final String authority = uri.getAuthority();
-        final ProviderInfo pi = getProviderInfoLocked(authority, UserHandle.getUserId(callingUid));
-        if (pi == null) {
-            Slog.w(TAG, "No content provider found for permission check: " + uri.toSafeString());
-            return -1;
-        }
-
-        int targetUid = lastTargetUid;
-        if (targetUid < 0 && targetPkg != null) {
-            try {
-                targetUid = pm.getPackageUid(targetPkg, UserHandle.getUserId(callingUid));
-                if (targetUid < 0) {
-                    if (DEBUG_URI_PERMISSION) Slog.v(TAG,
-                            "Can't grant URI permission no uid for: " + targetPkg);
-                    return -1;
-                }
-            } catch (RemoteException ex) {
-                return -1;
-            }
-        }
-
-        if (targetUid >= 0) {
-            // First...  does the target actually need this permission?
-            if (checkHoldingPermissionsLocked(pm, pi, uri, targetUid, modeFlags)) {
-                // No need to grant the target this permission.
-                if (DEBUG_URI_PERMISSION) Slog.v(TAG,
-                        "Target " + targetPkg + " already has full permission to " + uri);
-                return -1;
-            }
-        } else {
-            // First...  there is no target package, so can anyone access it?
-            boolean allowed = pi.exported;
-            if ((modeFlags&Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) {
-                if (pi.readPermission != null) {
-                    allowed = false;
-                }
-            }
-            if ((modeFlags&Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
-                if (pi.writePermission != null) {
-                    allowed = false;
-                }
-            }
-            if (allowed) {
-                return -1;
-            }
-        }
-
-        // Second...  is the provider allowing granting of URI permissions?
-        if (!pi.grantUriPermissions) {
-            throw new SecurityException("Provider " + pi.packageName
-                    + "/" + pi.name
-                    + " does not allow granting of Uri permissions (uri "
-                    + uri + ")");
-        }
-        if (pi.uriPermissionPatterns != null) {
-            final int N = pi.uriPermissionPatterns.length;
-            boolean allowed = false;
-            for (int i=0; i<N; i++) {
-                if (pi.uriPermissionPatterns[i] != null
-                        && pi.uriPermissionPatterns[i].match(uri.getPath())) {
-                    allowed = true;
-                    break;
-                }
-            }
-            if (!allowed) {
-                throw new SecurityException("Provider " + pi.packageName
-                        + "/" + pi.name
-                        + " does not allow granting of permission to path of Uri "
-                        + uri);
-            }
-        }
-
-        // Third...  does the caller itself have permission to access
-        // this uri?
-        if (callingUid != Process.myUid()) {
-            if (!checkHoldingPermissionsLocked(pm, pi, uri, callingUid, modeFlags)) {
-                // Require they hold a strong enough Uri permission
-                final int minStrength = persistable ? UriPermission.STRENGTH_PERSISTABLE
-                        : UriPermission.STRENGTH_OWNED;
-                if (!checkUriPermissionLocked(uri, callingUid, modeFlags, minStrength)) {
-                    throw new SecurityException("Uid " + callingUid
-                            + " does not have permission to uri " + uri);
-                }
-            }
-        }
-
-        return targetUid;
-    }
-
-    @Override
-    public int checkGrantUriPermission(int callingUid, String targetPkg,
-            Uri uri, int modeFlags) {
-        enforceNotIsolatedCaller("checkGrantUriPermission");
-        synchronized(this) {
-            return checkGrantUriPermissionLocked(callingUid, targetPkg, uri, modeFlags, -1);
-        }
-    }
-
-    void grantUriPermissionUncheckedLocked(
-            int targetUid, String targetPkg, Uri uri, int modeFlags, UriPermissionOwner owner) {
-        final boolean persistable = (modeFlags & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) != 0;
-        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
-                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-        if (modeFlags == 0) {
-            return;
-        }
-
-        // So here we are: the caller has the assumed permission
-        // to the uri, and the target doesn't.  Let's now give this to
-        // the target.
-
-        if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
-                "Granting " + targetPkg + "/" + targetUid + " permission to " + uri);
-
-        final String authority = uri.getAuthority();
-        final ProviderInfo pi = getProviderInfoLocked(authority, UserHandle.getUserId(targetUid));
-        if (pi == null) {
-            Slog.w(TAG, "No content provider found for grant: " + uri.toSafeString());
-            return;
-        }
-
-        final UriPermission perm = findOrCreateUriPermissionLocked(
-                pi.packageName, targetPkg, targetUid, uri);
-        perm.grantModes(modeFlags, persistable, owner);
-    }
-
-    void grantUriPermissionLocked(int callingUid, String targetPkg, Uri uri,
-            int modeFlags, UriPermissionOwner owner) {
-        if (targetPkg == null) {
-            throw new NullPointerException("targetPkg");
-        }
-
-        int targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, uri, modeFlags, -1);
-        if (targetUid < 0) {
-            return;
-        }
-
-        grantUriPermissionUncheckedLocked(targetUid, targetPkg, uri, modeFlags, owner);
-    }
-
-    static class NeededUriGrants extends ArrayList<Uri> {
-        final String targetPkg;
-        final int targetUid;
-        final int flags;
-
-        NeededUriGrants(String targetPkg, int targetUid, int flags) {
-            this.targetPkg = targetPkg;
-            this.targetUid = targetUid;
-            this.flags = flags;
-        }
-    }
-
-    /**
-     * Like checkGrantUriPermissionLocked, but takes an Intent.
-     */
-    NeededUriGrants checkGrantUriPermissionFromIntentLocked(int callingUid,
-            String targetPkg, Intent intent, int mode, NeededUriGrants needed) {
-        if (DEBUG_URI_PERMISSION) Slog.v(TAG,
-                "Checking URI perm to data=" + (intent != null ? intent.getData() : null)
-                + " clip=" + (intent != null ? intent.getClipData() : null)
-                + " from " + intent + "; flags=0x"
-                + Integer.toHexString(intent != null ? intent.getFlags() : 0));
-
-        if (targetPkg == null) {
-            throw new NullPointerException("targetPkg");
-        }
-
-        if (intent == null) {
-            return null;
-        }
-        Uri data = intent.getData();
-        ClipData clip = intent.getClipData();
-        if (data == null && clip == null) {
-            return null;
-        }
-
-        if (data != null) {
-            int targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, data,
-                mode, needed != null ? needed.targetUid : -1);
-            if (targetUid > 0) {
-                if (needed == null) {
-                    needed = new NeededUriGrants(targetPkg, targetUid, mode);
-                }
-                needed.add(data);
-            }
-        }
-        if (clip != null) {
-            for (int i=0; i<clip.getItemCount(); i++) {
-                Uri uri = clip.getItemAt(i).getUri();
-                if (uri != null) {
-                    int targetUid = -1;
-                    targetUid = checkGrantUriPermissionLocked(callingUid, targetPkg, uri,
-                            mode, needed != null ? needed.targetUid : -1);
-                    if (targetUid > 0) {
-                        if (needed == null) {
-                            needed = new NeededUriGrants(targetPkg, targetUid, mode);
-                        }
-                        needed.add(uri);
-                    }
-                } else {
-                    Intent clipIntent = clip.getItemAt(i).getIntent();
-                    if (clipIntent != null) {
-                        NeededUriGrants newNeeded = checkGrantUriPermissionFromIntentLocked(
-                                callingUid, targetPkg, clipIntent, mode, needed);
-                        if (newNeeded != null) {
-                            needed = newNeeded;
-                        }
-                    }
-                }
-            }
-        }
-
-        return needed;
-    }
-
-    /**
-     * Like grantUriPermissionUncheckedLocked, but takes an Intent.
-     */
-    void grantUriPermissionUncheckedFromIntentLocked(NeededUriGrants needed,
-            UriPermissionOwner owner) {
-        if (needed != null) {
-            for (int i=0; i<needed.size(); i++) {
-                grantUriPermissionUncheckedLocked(needed.targetUid, needed.targetPkg,
-                        needed.get(i), needed.flags, owner);
-            }
-        }
-    }
-
-    void grantUriPermissionFromIntentLocked(int callingUid,
-            String targetPkg, Intent intent, UriPermissionOwner owner) {
-        NeededUriGrants needed = checkGrantUriPermissionFromIntentLocked(callingUid, targetPkg,
-                intent, intent != null ? intent.getFlags() : 0, null);
-        if (needed == null) {
-            return;
-        }
-
-        grantUriPermissionUncheckedFromIntentLocked(needed, owner);
-    }
-
-    @Override
-    public void grantUriPermission(IApplicationThread caller, String targetPkg,
-            Uri uri, int modeFlags) {
-        enforceNotIsolatedCaller("grantUriPermission");
-        synchronized(this) {
-            final ProcessRecord r = getRecordForAppLocked(caller);
-            if (r == null) {
-                throw new SecurityException("Unable to find app for caller "
-                        + caller
-                        + " when granting permission to uri " + uri);
-            }
-            if (targetPkg == null) {
-                throw new IllegalArgumentException("null target");
-            }
-            if (uri == null) {
-                throw new IllegalArgumentException("null uri");
-            }
-
-            // Persistable only supported through Intents
-            Preconditions.checkFlagsArgument(modeFlags,
-                    Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-
-            grantUriPermissionLocked(r.uid, targetPkg, uri, modeFlags,
-                    null);
-        }
-    }
-
-    void removeUriPermissionIfNeededLocked(UriPermission perm) {
-        if ((perm.modeFlags&(Intent.FLAG_GRANT_READ_URI_PERMISSION
-                |Intent.FLAG_GRANT_WRITE_URI_PERMISSION)) == 0) {
-            ArrayMap<Uri, UriPermission> perms
-                    = mGrantedUriPermissions.get(perm.targetUid);
-            if (perms != null) {
-                if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
-                        "Removing " + perm.targetUid + " permission to " + perm.uri);
-                perms.remove(perm.uri);
-                if (perms.size() == 0) {
-                    mGrantedUriPermissions.remove(perm.targetUid);
-                }
-            }
-        }
-    }
-
-    private void revokeUriPermissionLocked(int callingUid, Uri uri, int modeFlags) {
-        if (DEBUG_URI_PERMISSION) Slog.v(TAG, "Revoking all granted permissions to " + uri);
-
-        final IPackageManager pm = AppGlobals.getPackageManager();
-        final String authority = uri.getAuthority();
-        final ProviderInfo pi = getProviderInfoLocked(authority, UserHandle.getUserId(callingUid));
-        if (pi == null) {
-            Slog.w(TAG, "No content provider found for permission revoke: " + uri.toSafeString());
-            return;
-        }
-
-        // Does the caller have this permission on the URI?
-        if (!checkHoldingPermissionsLocked(pm, pi, uri, callingUid, modeFlags)) {
-            // Right now, if you are not the original owner of the permission,
-            // you are not allowed to revoke it.
-            //if (!checkUriPermissionLocked(uri, callingUid, modeFlags)) {
-                throw new SecurityException("Uid " + callingUid
-                        + " does not have permission to uri " + uri);
-            //}
-        }
-
-        boolean persistChanged = false;
-
-        // Go through all of the permissions and remove any that match.
-        final List<String> SEGMENTS = uri.getPathSegments();
-        if (SEGMENTS != null) {
-            final int NS = SEGMENTS.size();
-            int N = mGrantedUriPermissions.size();
-            for (int i=0; i<N; i++) {
-                ArrayMap<Uri, UriPermission> perms
-                        = mGrantedUriPermissions.valueAt(i);
-                Iterator<UriPermission> it = perms.values().iterator();
-            toploop:
-                while (it.hasNext()) {
-                    UriPermission perm = it.next();
-                    Uri targetUri = perm.uri;
-                    if (!authority.equals(targetUri.getAuthority())) {
-                        continue;
-                    }
-                    List<String> targetSegments = targetUri.getPathSegments();
-                    if (targetSegments == null) {
-                        continue;
-                    }
-                    if (targetSegments.size() < NS) {
-                        continue;
-                    }
-                    for (int j=0; j<NS; j++) {
-                        if (!SEGMENTS.get(j).equals(targetSegments.get(j))) {
-                            continue toploop;
-                        }
-                    }
-                    if (DEBUG_URI_PERMISSION) Slog.v(TAG, 
-                            "Revoking " + perm.targetUid + " permission to " + perm.uri);
-                    persistChanged |= perm.clearModes(modeFlags, true);
-                    if (perm.modeFlags == 0) {
-                        it.remove();
-                    }
-                }
-                if (perms.size() == 0) {
-                    mGrantedUriPermissions.remove(
-                            mGrantedUriPermissions.keyAt(i));
-                    N--;
-                    i--;
-                }
-            }
-        }
-
-        if (persistChanged) {
-            schedulePersistUriGrants();
-        }
-    }
-
-    @Override
-    public void revokeUriPermission(IApplicationThread caller, Uri uri,
-            int modeFlags) {
-        enforceNotIsolatedCaller("revokeUriPermission");
-        synchronized(this) {
-            final ProcessRecord r = getRecordForAppLocked(caller);
-            if (r == null) {
-                throw new SecurityException("Unable to find app for caller "
-                        + caller
-                        + " when revoking permission to uri " + uri);
-            }
-            if (uri == null) {
-                Slog.w(TAG, "revokeUriPermission: null uri");
-                return;
-            }
-
-            modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION
-                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-            if (modeFlags == 0) {
-                return;
-            }
-
-            final IPackageManager pm = AppGlobals.getPackageManager();
-            final String authority = uri.getAuthority();
-            final ProviderInfo pi = getProviderInfoLocked(authority, r.userId);
-            if (pi == null) {
-                Slog.w(TAG, "No content provider found for permission revoke: "
-                        + uri.toSafeString());
-                return;
-            }
-
-            revokeUriPermissionLocked(r.uid, uri, modeFlags);
-        }
-    }
-
-    /**
-     * Remove any {@link UriPermission} granted <em>from</em> or <em>to</em> the
-     * given package.
-     *
-     * @param packageName Package name to match, or {@code null} to apply to all
-     *            packages.
-     * @param userHandle User to match, or {@link UserHandle#USER_ALL} to apply
-     *            to all users.
-     * @param persistable If persistable grants should be removed.
-     */
-    private void removeUriPermissionsForPackageLocked(
-            String packageName, int userHandle, boolean persistable) {
-        if (userHandle == UserHandle.USER_ALL && packageName == null) {
-            throw new IllegalArgumentException("Must narrow by either package or user");
-        }
-
-        boolean persistChanged = false;
-
-        final int size = mGrantedUriPermissions.size();
-        for (int i = 0; i < size; i++) {
-            // Only inspect grants matching user
-            if (userHandle == UserHandle.USER_ALL
-                    || userHandle == UserHandle.getUserId(mGrantedUriPermissions.keyAt(i))) {
-                final Iterator<UriPermission> it = mGrantedUriPermissions.valueAt(i)
-                        .values().iterator();
-                while (it.hasNext()) {
-                    final UriPermission perm = it.next();
-
-                    // Only inspect grants matching package
-                    if (packageName == null || perm.sourcePkg.equals(packageName)
-                            || perm.targetPkg.equals(packageName)) {
-                        persistChanged |= perm.clearModes(~0, persistable);
-
-                        // Only remove when no modes remain; any persisted grants
-                        // will keep this alive.
-                        if (perm.modeFlags == 0) {
-                            it.remove();
-                        }
-                    }
-                }
-            }
-        }
-
-        if (persistChanged) {
-            schedulePersistUriGrants();
-        }
-    }
-
-    @Override
-    public IBinder newUriPermissionOwner(String name) {
-        enforceNotIsolatedCaller("newUriPermissionOwner");
-        synchronized(this) {
-            UriPermissionOwner owner = new UriPermissionOwner(this, name);
-            return owner.getExternalTokenLocked();
-        }
-    }
-
-    @Override
-    public void grantUriPermissionFromOwner(IBinder token, int fromUid, String targetPkg,
-            Uri uri, int modeFlags) {
-        synchronized(this) {
-            UriPermissionOwner owner = UriPermissionOwner.fromExternalToken(token);
-            if (owner == null) {
-                throw new IllegalArgumentException("Unknown owner: " + token);
-            }
-            if (fromUid != Binder.getCallingUid()) {
-                if (Binder.getCallingUid() != Process.myUid()) {
-                    // Only system code can grant URI permissions on behalf
-                    // of other users.
-                    throw new SecurityException("nice try");
-                }
-            }
-            if (targetPkg == null) {
-                throw new IllegalArgumentException("null target");
-            }
-            if (uri == null) {
-                throw new IllegalArgumentException("null uri");
-            }
-
-            grantUriPermissionLocked(fromUid, targetPkg, uri, modeFlags, owner);
-        }
-    }
-
-    @Override
-    public void revokeUriPermissionFromOwner(IBinder token, Uri uri, int mode) {
-        synchronized(this) {
-            UriPermissionOwner owner = UriPermissionOwner.fromExternalToken(token);
-            if (owner == null) {
-                throw new IllegalArgumentException("Unknown owner: " + token);
-            }
-
-            if (uri == null) {
-                owner.removeUriPermissionsLocked(mode);
-            } else {
-                owner.removeUriPermissionLocked(uri, mode);
-            }
-        }
-    }
-
-    private void schedulePersistUriGrants() {
-        if (!mHandler.hasMessages(PERSIST_URI_GRANTS_MSG)) {
-            mHandler.sendMessageDelayed(mHandler.obtainMessage(PERSIST_URI_GRANTS_MSG),
-                    10 * DateUtils.SECOND_IN_MILLIS);
-        }
-    }
-
-    private void writeGrantedUriPermissions() {
-        if (DEBUG_URI_PERMISSION) Slog.v(TAG, "writeGrantedUriPermissions()");
-
-        // Snapshot permissions so we can persist without lock
-        ArrayList<UriPermission.Snapshot> persist = Lists.newArrayList();
-        synchronized (this) {
-            final int size = mGrantedUriPermissions.size();
-            for (int i = 0 ; i < size; i++) {
-                for (UriPermission perm : mGrantedUriPermissions.valueAt(i).values()) {
-                    if (perm.persistedModeFlags != 0) {
-                        persist.add(perm.snapshot());
-                    }
-                }
-            }
-        }
-
-        FileOutputStream fos = null;
-        try {
-            fos = mGrantFile.startWrite();
-
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-            out.startDocument(null, true);
-            out.startTag(null, TAG_URI_GRANTS);
-            for (UriPermission.Snapshot perm : persist) {
-                out.startTag(null, TAG_URI_GRANT);
-                writeIntAttribute(out, ATTR_USER_HANDLE, perm.userHandle);
-                out.attribute(null, ATTR_SOURCE_PKG, perm.sourcePkg);
-                out.attribute(null, ATTR_TARGET_PKG, perm.targetPkg);
-                out.attribute(null, ATTR_URI, String.valueOf(perm.uri));
-                writeIntAttribute(out, ATTR_MODE_FLAGS, perm.persistedModeFlags);
-                writeLongAttribute(out, ATTR_CREATED_TIME, perm.persistedCreateTime);
-                out.endTag(null, TAG_URI_GRANT);
-            }
-            out.endTag(null, TAG_URI_GRANTS);
-            out.endDocument();
-
-            mGrantFile.finishWrite(fos);
-        } catch (IOException e) {
-            if (fos != null) {
-                mGrantFile.failWrite(fos);
-            }
-        }
-    }
-
-    private void readGrantedUriPermissionsLocked() {
-        if (DEBUG_URI_PERMISSION) Slog.v(TAG, "readGrantedUriPermissions()");
-
-        final long now = System.currentTimeMillis();
-
-        FileInputStream fis = null;
-        try {
-            fis = mGrantFile.openRead();
-            final XmlPullParser in = Xml.newPullParser();
-            in.setInput(fis, null);
-
-            int type;
-            while ((type = in.next()) != END_DOCUMENT) {
-                final String tag = in.getName();
-                if (type == START_TAG) {
-                    if (TAG_URI_GRANT.equals(tag)) {
-                        final int userHandle = readIntAttribute(in, ATTR_USER_HANDLE);
-                        final String sourcePkg = in.getAttributeValue(null, ATTR_SOURCE_PKG);
-                        final String targetPkg = in.getAttributeValue(null, ATTR_TARGET_PKG);
-                        final Uri uri = Uri.parse(in.getAttributeValue(null, ATTR_URI));
-                        final int modeFlags = readIntAttribute(in, ATTR_MODE_FLAGS);
-                        final long createdTime = readLongAttribute(in, ATTR_CREATED_TIME, now);
-
-                        // Sanity check that provider still belongs to source package
-                        final ProviderInfo pi = getProviderInfoLocked(
-                                uri.getAuthority(), userHandle);
-                        if (pi != null && sourcePkg.equals(pi.packageName)) {
-                            int targetUid = -1;
-                            try {
-                                targetUid = AppGlobals.getPackageManager()
-                                        .getPackageUid(targetPkg, userHandle);
-                            } catch (RemoteException e) {
-                            }
-                            if (targetUid != -1) {
-                                final UriPermission perm = findOrCreateUriPermissionLocked(
-                                        sourcePkg, targetPkg, targetUid, uri);
-                                perm.initPersistedModes(modeFlags, createdTime);
-                            }
-                        } else {
-                            Slog.w(TAG, "Persisted grant for " + uri + " had source " + sourcePkg
-                                    + " but instead found " + pi);
-                        }
-                    }
-                }
-            }
-        } catch (FileNotFoundException e) {
-            // Missing grants is okay
-        } catch (IOException e) {
-            Log.wtf(TAG, "Failed reading Uri grants", e);
-        } catch (XmlPullParserException e) {
-            Log.wtf(TAG, "Failed reading Uri grants", e);
-        } finally {
-            IoUtils.closeQuietly(fis);
-        }
-    }
-
-    @Override
-    public void takePersistableUriPermission(Uri uri, int modeFlags) {
-        enforceNotIsolatedCaller("takePersistableUriPermission");
-
-        Preconditions.checkFlagsArgument(modeFlags,
-                Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-
-        synchronized (this) {
-            final int callingUid = Binder.getCallingUid();
-            final UriPermission perm = findUriPermissionLocked(callingUid, uri);
-            if (perm == null) {
-                throw new SecurityException("No permission grant found for UID " + callingUid
-                        + " and Uri " + uri.toSafeString());
-            }
-
-            boolean persistChanged = perm.takePersistableModes(modeFlags);
-            persistChanged |= maybePrunePersistedUriGrantsLocked(callingUid);
-
-            if (persistChanged) {
-                schedulePersistUriGrants();
-            }
-        }
-    }
-
-    @Override
-    public void releasePersistableUriPermission(Uri uri, int modeFlags) {
-        enforceNotIsolatedCaller("releasePersistableUriPermission");
-
-        Preconditions.checkFlagsArgument(modeFlags,
-                Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-
-        synchronized (this) {
-            final int callingUid = Binder.getCallingUid();
-
-            final UriPermission perm = findUriPermissionLocked(callingUid, uri);
-            if (perm == null) {
-                Slog.w(TAG, "No permission grant found for UID " + callingUid + " and Uri "
-                        + uri.toSafeString());
-                return;
-            }
-
-            final boolean persistChanged = perm.releasePersistableModes(modeFlags);
-            removeUriPermissionIfNeededLocked(perm);
-            if (persistChanged) {
-                schedulePersistUriGrants();
-            }
-        }
-    }
-
-    /**
-     * Prune any older {@link UriPermission} for the given UID until outstanding
-     * persisted grants are below {@link #MAX_PERSISTED_URI_GRANTS}.
-     *
-     * @return if any mutations occured that require persisting.
-     */
-    private boolean maybePrunePersistedUriGrantsLocked(int uid) {
-        final ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(uid);
-        if (perms == null) return false;
-        if (perms.size() < MAX_PERSISTED_URI_GRANTS) return false;
-
-        final ArrayList<UriPermission> persisted = Lists.newArrayList();
-        for (UriPermission perm : perms.values()) {
-            if (perm.persistedModeFlags != 0) {
-                persisted.add(perm);
-            }
-        }
-
-        final int trimCount = persisted.size() - MAX_PERSISTED_URI_GRANTS;
-        if (trimCount <= 0) return false;
-
-        Collections.sort(persisted, new UriPermission.PersistedTimeComparator());
-        for (int i = 0; i < trimCount; i++) {
-            final UriPermission perm = persisted.get(i);
-
-            if (DEBUG_URI_PERMISSION) {
-                Slog.v(TAG, "Trimming grant created at " + perm.persistedCreateTime);
-            }
-
-            perm.releasePersistableModes(~0);
-            removeUriPermissionIfNeededLocked(perm);
-        }
-
-        return true;
-    }
-
-    @Override
-    public ParceledListSlice<android.content.UriPermission> getPersistedUriPermissions(
-            String packageName, boolean incoming) {
-        enforceNotIsolatedCaller("getPersistedUriPermissions");
-        Preconditions.checkNotNull(packageName, "packageName");
-
-        final int callingUid = Binder.getCallingUid();
-        final IPackageManager pm = AppGlobals.getPackageManager();
-        try {
-            final int packageUid = pm.getPackageUid(packageName, UserHandle.getUserId(callingUid));
-            if (packageUid != callingUid) {
-                throw new SecurityException(
-                        "Package " + packageName + " does not belong to calling UID " + callingUid);
-            }
-        } catch (RemoteException e) {
-            throw new SecurityException("Failed to verify package name ownership");
-        }
-
-        final ArrayList<android.content.UriPermission> result = Lists.newArrayList();
-        synchronized (this) {
-            if (incoming) {
-                final ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(callingUid);
-                if (perms == null) {
-                    Slog.w(TAG, "No permission grants found for " + packageName);
-                } else {
-                    final int size = perms.size();
-                    for (int i = 0; i < size; i++) {
-                        final UriPermission perm = perms.valueAt(i);
-                        if (packageName.equals(perm.targetPkg) && perm.persistedModeFlags != 0) {
-                            result.add(perm.buildPersistedPublicApiObject());
-                        }
-                    }
-                }
-            } else {
-                final int size = mGrantedUriPermissions.size();
-                for (int i = 0; i < size; i++) {
-                    final ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.valueAt(i);
-                    final int permsSize = perms.size();
-                    for (int j = 0; j < permsSize; j++) {
-                        final UriPermission perm = perms.valueAt(j);
-                        if (packageName.equals(perm.sourcePkg) && perm.persistedModeFlags != 0) {
-                            result.add(perm.buildPersistedPublicApiObject());
-                        }
-                    }
-                }
-            }
-        }
-        return new ParceledListSlice<android.content.UriPermission>(result);
-    }
-
-    @Override
-    public void showWaitingForDebugger(IApplicationThread who, boolean waiting) {
-        synchronized (this) {
-            ProcessRecord app =
-                who != null ? getRecordForAppLocked(who) : null;
-            if (app == null) return;
-
-            Message msg = Message.obtain();
-            msg.what = WAIT_FOR_DEBUGGER_MSG;
-            msg.obj = app;
-            msg.arg1 = waiting ? 1 : 0;
-            mHandler.sendMessage(msg);
-        }
-    }
-
-    @Override
-    public void getMemoryInfo(ActivityManager.MemoryInfo outInfo) {
-        final long homeAppMem = mProcessList.getMemLevel(ProcessList.HOME_APP_ADJ);
-        final long cachedAppMem = mProcessList.getMemLevel(ProcessList.CACHED_APP_MIN_ADJ);
-        outInfo.availMem = Process.getFreeMemory();
-        outInfo.totalMem = Process.getTotalMemory();
-        outInfo.threshold = homeAppMem;
-        outInfo.lowMemory = outInfo.availMem < (homeAppMem + ((cachedAppMem-homeAppMem)/2));
-        outInfo.hiddenAppThreshold = cachedAppMem;
-        outInfo.secondaryServerThreshold = mProcessList.getMemLevel(
-                ProcessList.SERVICE_ADJ);
-        outInfo.visibleAppThreshold = mProcessList.getMemLevel(
-                ProcessList.VISIBLE_APP_ADJ);
-        outInfo.foregroundAppThreshold = mProcessList.getMemLevel(
-                ProcessList.FOREGROUND_APP_ADJ);
-    }
-    
-    // =========================================================
-    // TASK MANAGEMENT
-    // =========================================================
-
-    @Override
-    public List<RunningTaskInfo> getTasks(int maxNum, int flags,
-                         IThumbnailReceiver receiver) {
-        ArrayList<RunningTaskInfo> list = new ArrayList<RunningTaskInfo>();
-
-        PendingThumbnailsRecord pending = new PendingThumbnailsRecord(receiver);
-        ActivityRecord topRecord = null;
-
-        synchronized(this) {
-            if (localLOGV) Slog.v(
-                TAG, "getTasks: max=" + maxNum + ", flags=" + flags
-                + ", receiver=" + receiver);
-
-            if (checkCallingPermission(android.Manifest.permission.GET_TASKS)
-                    != PackageManager.PERMISSION_GRANTED) {
-                if (receiver != null) {
-                    // If the caller wants to wait for pending thumbnails,
-                    // it ain't gonna get them.
-                    try {
-                        receiver.finished();
-                    } catch (RemoteException ex) {
-                    }
-                }
-                String msg = "Permission Denial: getTasks() from pid="
-                        + Binder.getCallingPid()
-                        + ", uid=" + Binder.getCallingUid()
-                        + " requires " + android.Manifest.permission.GET_TASKS;
-                Slog.w(TAG, msg);
-                throw new SecurityException(msg);
-            }
-
-            // TODO: Improve with MRU list from all ActivityStacks.
-            topRecord = mStackSupervisor.getTasksLocked(maxNum, receiver, pending, list);
-
-            if (!pending.pendingRecords.isEmpty()) {
-                mPendingThumbnails.add(pending);
-            }
-        }
-
-        if (localLOGV) Slog.v(TAG, "We have pending thumbnails: " + pending);
-
-        if (topRecord != null) {
-            if (localLOGV) Slog.v(TAG, "Requesting top thumbnail");
-            try {
-                IApplicationThread topThumbnail = topRecord.app.thread;
-                topThumbnail.requestThumbnail(topRecord.appToken);
-            } catch (Exception e) {
-                Slog.w(TAG, "Exception thrown when requesting thumbnail", e);
-                sendPendingThumbnail(null, topRecord.appToken, null, null, true);
-            }
-        }
-
-        if (pending == null && receiver != null) {
-            // In this case all thumbnails were available and the client
-            // is being asked to be told when the remaining ones come in...
-            // which is unusually, since the top-most currently running
-            // activity should never have a canned thumbnail!  Oh well.
-            try {
-                receiver.finished();
-            } catch (RemoteException ex) {
-            }
-        }
-
-        return list;
-    }
-
-    TaskRecord getMostRecentTask() {
-        return mRecentTasks.get(0);
-    }
-
-    @Override
-    public List<ActivityManager.RecentTaskInfo> getRecentTasks(int maxNum,
-            int flags, int userId) {
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "getRecentTasks", null);
-
-        synchronized (this) {
-            enforceCallingPermission(android.Manifest.permission.GET_TASKS,
-                    "getRecentTasks()");
-            final boolean detailed = checkCallingPermission(
-                    android.Manifest.permission.GET_DETAILED_TASKS)
-                    == PackageManager.PERMISSION_GRANTED;
-
-            IPackageManager pm = AppGlobals.getPackageManager();
-
-            final int N = mRecentTasks.size();
-            ArrayList<ActivityManager.RecentTaskInfo> res
-                    = new ArrayList<ActivityManager.RecentTaskInfo>(
-                            maxNum < N ? maxNum : N);
-            for (int i=0; i<N && maxNum > 0; i++) {
-                TaskRecord tr = mRecentTasks.get(i);
-                // Only add calling user's recent tasks
-                if (tr.userId != userId) continue;
-                // Return the entry if desired by the caller.  We always return
-                // the first entry, because callers always expect this to be the
-                // foreground app.  We may filter others if the caller has
-                // not supplied RECENT_WITH_EXCLUDED and there is some reason
-                // we should exclude the entry.
-
-                if (i == 0
-                        || ((flags&ActivityManager.RECENT_WITH_EXCLUDED) != 0)
-                        || (tr.intent == null)
-                        || ((tr.intent.getFlags()
-                                &Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0)) {
-                    ActivityManager.RecentTaskInfo rti
-                            = new ActivityManager.RecentTaskInfo();
-                    rti.id = tr.numActivities > 0 ? tr.taskId : -1;
-                    rti.persistentId = tr.taskId;
-                    rti.baseIntent = new Intent(
-                            tr.intent != null ? tr.intent : tr.affinityIntent);
-                    if (!detailed) {
-                        rti.baseIntent.replaceExtras((Bundle)null);
-                    }
-                    rti.origActivity = tr.origActivity;
-                    rti.description = tr.lastDescription;
-                    rti.stackId = tr.stack.mStackId;
-
-                    if ((flags&ActivityManager.RECENT_IGNORE_UNAVAILABLE) != 0) {
-                        // Check whether this activity is currently available.
-                        try {
-                            if (rti.origActivity != null) {
-                                if (pm.getActivityInfo(rti.origActivity, 0, userId)
-                                        == null) {
-                                    continue;
-                                }
-                            } else if (rti.baseIntent != null) {
-                                if (pm.queryIntentActivities(rti.baseIntent,
-                                        null, 0, userId) == null) {
-                                    continue;
-                                }
-                            }
-                        } catch (RemoteException e) {
-                            // Will never happen.
-                        }
-                    }
-                    
-                    res.add(rti);
-                    maxNum--;
-                }
-            }
-            return res;
-        }
-    }
-
-    private TaskRecord recentTaskForIdLocked(int id) {
-        final int N = mRecentTasks.size();
-            for (int i=0; i<N; i++) {
-                TaskRecord tr = mRecentTasks.get(i);
-                if (tr.taskId == id) {
-                    return tr;
-                }
-            }
-            return null;
-    }
-
-    @Override
-    public ActivityManager.TaskThumbnails getTaskThumbnails(int id) {
-        synchronized (this) {
-            enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
-                    "getTaskThumbnails()");
-            TaskRecord tr = recentTaskForIdLocked(id);
-            if (tr != null) {
-                return tr.getTaskThumbnailsLocked();
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public Bitmap getTaskTopThumbnail(int id) {
-        synchronized (this) {
-            enforceCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
-                    "getTaskTopThumbnail()");
-            TaskRecord tr = recentTaskForIdLocked(id);
-            if (tr != null) {
-                return tr.getTaskTopThumbnailLocked();
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public boolean removeSubTask(int taskId, int subTaskIndex) {
-        synchronized (this) {
-            enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,
-                    "removeSubTask()");
-            long ident = Binder.clearCallingIdentity();
-            try {
-                TaskRecord tr = recentTaskForIdLocked(taskId);
-                if (tr != null) {
-                    return tr.removeTaskActivitiesLocked(subTaskIndex, true) != null;
-                }
-                return false;
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    private void killUnneededProcessLocked(ProcessRecord pr, String reason) {
-        if (!pr.killedByAm) {
-            Slog.i(TAG, "Killing " + pr.toShortString() + " (adj " + pr.setAdj + "): " + reason);
-            EventLog.writeEvent(EventLogTags.AM_KILL, pr.userId, pr.pid,
-                    pr.processName, pr.setAdj, reason);
-            pr.killedByAm = true;
-            Process.killProcessQuiet(pr.pid);
-        }
-    }
-
-    private void cleanUpRemovedTaskLocked(TaskRecord tr, int flags) {
-        tr.disposeThumbnail();
-        mRecentTasks.remove(tr);
-        final boolean killProcesses = (flags&ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
-        Intent baseIntent = new Intent(
-                tr.intent != null ? tr.intent : tr.affinityIntent);
-        ComponentName component = baseIntent.getComponent();
-        if (component == null) {
-            Slog.w(TAG, "Now component for base intent of task: " + tr);
-            return;
-        }
-
-        // Find any running services associated with this app.
-        mServices.cleanUpRemovedTaskLocked(tr, component, baseIntent);
-
-        if (killProcesses) {
-            // Find any running processes associated with this app.
-            final String pkg = component.getPackageName();
-            ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>();
-            ArrayMap<String, SparseArray<ProcessRecord>> pmap = mProcessNames.getMap();
-            for (int i=0; i<pmap.size(); i++) {
-                SparseArray<ProcessRecord> uids = pmap.valueAt(i);
-                for (int j=0; j<uids.size(); j++) {
-                    ProcessRecord proc = uids.valueAt(j);
-                    if (proc.userId != tr.userId) {
-                        continue;
-                    }
-                    if (!proc.pkgList.containsKey(pkg)) {
-                        continue;
-                    }
-                    procs.add(proc);
-                }
-            }
-
-            // Kill the running processes.
-            for (int i=0; i<procs.size(); i++) {
-                ProcessRecord pr = procs.get(i);
-                if (pr == mHomeProcess) {
-                    // Don't kill the home process along with tasks from the same package.
-                    continue;
-                }
-                if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
-                    killUnneededProcessLocked(pr, "remove task");
-                } else {
-                    pr.waitingToKill = "remove task";
-                }
-            }
-        }
-    }
-
-    @Override
-    public boolean removeTask(int taskId, int flags) {
-        synchronized (this) {
-            enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,
-                    "removeTask()");
-            long ident = Binder.clearCallingIdentity();
-            try {
-                TaskRecord tr = recentTaskForIdLocked(taskId);
-                if (tr != null) {
-                    ActivityRecord r = tr.removeTaskActivitiesLocked(-1, false);
-                    if (r != null) {
-                        cleanUpRemovedTaskLocked(tr, flags);
-                        return true;
-                    }
-                    if (tr.mActivities.size() == 0) {
-                        // Caller is just removing a recent task that is
-                        // not actively running.  That is easy!
-                        cleanUpRemovedTaskLocked(tr, flags);
-                        return true;
-                    }
-                    Slog.w(TAG, "removeTask: task " + taskId
-                            + " does not have activities to remove, "
-                            + " but numActivities=" + tr.numActivities
-                            + ": " + tr);
-                }
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-        return false;
-    }
-    
-    /**
-     * TODO: Add mController hook
-     */
-    @Override
-    public void moveTaskToFront(int task, int flags, Bundle options) {
-        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
-                "moveTaskToFront()");
-
-        if (DEBUG_STACK) Slog.d(TAG, "moveTaskToFront: moving task=" + task);
-        synchronized(this) {
-            if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
-                    Binder.getCallingUid(), "Task to front")) {
-                ActivityOptions.abort(options);
-                return;
-            }
-            final long origId = Binder.clearCallingIdentity();
-            try {
-                mStackSupervisor.findTaskToMoveToFrontLocked(task, flags, options);
-            } finally {
-                Binder.restoreCallingIdentity(origId);
-            }
-            ActivityOptions.abort(options);
-        }
-    }
-
-    @Override
-    public void moveTaskToBack(int taskId) {
-        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
-                "moveTaskToBack()");
-
-        synchronized(this) {
-            TaskRecord tr = recentTaskForIdLocked(taskId);
-            if (tr != null) {
-                if (DEBUG_STACK) Slog.d(TAG, "moveTaskToBack: moving task=" + tr);
-                ActivityStack stack = tr.stack;
-                if (stack.mResumedActivity != null && stack.mResumedActivity.task == tr) {
-                    if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
-                            Binder.getCallingUid(), "Task to back")) {
-                        return;
-                    }
-                }
-                final long origId = Binder.clearCallingIdentity();
-                try {
-                    stack.moveTaskToBackLocked(taskId, null);
-                } finally {
-                    Binder.restoreCallingIdentity(origId);
-                }
-            }
-        }
-    }
-
-    /**
-     * Moves an activity, and all of the other activities within the same task, to the bottom
-     * of the history stack.  The activity's order within the task is unchanged.
-     * 
-     * @param token A reference to the activity we wish to move
-     * @param nonRoot If false then this only works if the activity is the root
-     *                of a task; if true it will work for any activity in a task.
-     * @return Returns true if the move completed, false if not.
-     */
-    @Override
-    public boolean moveActivityTaskToBack(IBinder token, boolean nonRoot) {
-        enforceNotIsolatedCaller("moveActivityTaskToBack");
-        synchronized(this) {
-            final long origId = Binder.clearCallingIdentity();
-            int taskId = ActivityRecord.getTaskForActivityLocked(token, !nonRoot);
-            if (taskId >= 0) {
-                return ActivityRecord.getStackLocked(token).moveTaskToBackLocked(taskId, null);
-            }
-            Binder.restoreCallingIdentity(origId);
-        }
-        return false;
-    }
-
-    @Override
-    public void moveTaskBackwards(int task) {
-        enforceCallingPermission(android.Manifest.permission.REORDER_TASKS,
-                "moveTaskBackwards()");
-
-        synchronized(this) {
-            if (!checkAppSwitchAllowedLocked(Binder.getCallingPid(),
-                    Binder.getCallingUid(), "Task backwards")) {
-                return;
-            }
-            final long origId = Binder.clearCallingIdentity();
-            moveTaskBackwardsLocked(task);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    private final void moveTaskBackwardsLocked(int task) {
-        Slog.e(TAG, "moveTaskBackwards not yet implemented!");
-    }
-
-    @Override
-    public int createStack(int taskId, int relativeStackBoxId, int position, float weight) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "createStack()");
-        if (DEBUG_STACK) Slog.d(TAG, "createStack: taskId=" + taskId + " relStackBoxId=" +
-                relativeStackBoxId + " position=" + position + " weight=" + weight);
-        synchronized (this) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                int stackId = mStackSupervisor.createStack();
-                mWindowManager.createStack(stackId, relativeStackBoxId, position, weight);
-                if (taskId > 0) {
-                    moveTaskToStack(taskId, stackId, true);
-                }
-                return stackId;
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public void moveTaskToStack(int taskId, int stackId, boolean toTop) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "moveTaskToStack()");
-        if (stackId == HOME_STACK_ID) {
-            Slog.e(TAG, "moveTaskToStack: Attempt to move task " + taskId + " to home stack",
-                    new RuntimeException("here").fillInStackTrace());
-        }
-        synchronized (this) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                if (DEBUG_STACK) Slog.d(TAG, "moveTaskToStack: moving task=" + taskId + " to stackId="
-                        + stackId + " toTop=" + toTop);
-                mStackSupervisor.moveTaskToStack(taskId, stackId, toTop);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public void resizeStackBox(int stackBoxId, float weight) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "resizeStackBox()");
-        long ident = Binder.clearCallingIdentity();
-        try {
-            mWindowManager.resizeStackBox(stackBoxId, weight);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private ArrayList<StackInfo> getStacks() {
-        synchronized (this) {
-            ArrayList<ActivityManager.StackInfo> list = new ArrayList<ActivityManager.StackInfo>();
-            ArrayList<ActivityStack> stacks = mStackSupervisor.getStacks();
-            for (ActivityStack stack : stacks) {
-                ActivityManager.StackInfo stackInfo = new ActivityManager.StackInfo();
-                int stackId = stack.mStackId;
-                stackInfo.stackId = stackId;
-                stackInfo.bounds = mWindowManager.getStackBounds(stackId);
-                ArrayList<TaskRecord> tasks = stack.getAllTasks();
-                final int numTasks = tasks.size();
-                int[] taskIds = new int[numTasks];
-                String[] taskNames = new String[numTasks];
-                for (int i = 0; i < numTasks; ++i) {
-                    final TaskRecord task = tasks.get(i);
-                    taskIds[i] = task.taskId;
-                    taskNames[i] = task.origActivity != null ? task.origActivity.flattenToString()
-                            : task.realActivity != null ? task.realActivity.flattenToString()
-                            : task.getTopActivity() != null ? task.getTopActivity().packageName
-                            : "unknown";
-                }
-                stackInfo.taskIds = taskIds;
-                stackInfo.taskNames = taskNames;
-                list.add(stackInfo);
-            }
-            return list;
-        }
-    }
-
-    private void addStackInfoToStackBoxInfo(StackBoxInfo stackBoxInfo, List<StackInfo> stackInfos) {
-        final int stackId = stackBoxInfo.stackId;
-        if (stackId >= 0) {
-            for (StackInfo stackInfo : stackInfos) {
-                if (stackId == stackInfo.stackId) {
-                    stackBoxInfo.stack = stackInfo;
-                    stackInfos.remove(stackInfo);
-                    return;
-                }
-            }
-        } else {
-            addStackInfoToStackBoxInfo(stackBoxInfo.children[0], stackInfos);
-            addStackInfoToStackBoxInfo(stackBoxInfo.children[1], stackInfos);
-        }
-    }
-
-    @Override
-    public List<StackBoxInfo> getStackBoxes() {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "getStackBoxes()");
-        long ident = Binder.clearCallingIdentity();
-        try {
-            List<StackBoxInfo> stackBoxInfos = mWindowManager.getStackBoxInfos();
-            synchronized (this) {
-                List<StackInfo> stackInfos = getStacks();
-                for (StackBoxInfo stackBoxInfo : stackBoxInfos) {
-                    addStackInfoToStackBoxInfo(stackBoxInfo, stackInfos);
-                }
-            }
-            return stackBoxInfos;
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public StackBoxInfo getStackBoxInfo(int stackBoxId) {
-        enforceCallingPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS,
-                "getStackBoxInfo()");
-        long ident = Binder.clearCallingIdentity();
-        try {
-            List<StackBoxInfo> stackBoxInfos = mWindowManager.getStackBoxInfos();
-            StackBoxInfo info = null;
-            synchronized (this) {
-                List<StackInfo> stackInfos = getStacks();
-                for (StackBoxInfo stackBoxInfo : stackBoxInfos) {
-                    addStackInfoToStackBoxInfo(stackBoxInfo, stackInfos);
-                    if (stackBoxInfo.stackBoxId == stackBoxId) {
-                        info = stackBoxInfo;
-                    }
-                }
-            }
-            return info;
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public int getTaskForActivity(IBinder token, boolean onlyRoot) {
-        synchronized(this) {
-            return ActivityRecord.getTaskForActivityLocked(token, onlyRoot);
-        }
-    }
-
-    // =========================================================
-    // THUMBNAILS
-    // =========================================================
-
-    public void reportThumbnail(IBinder token,
-            Bitmap thumbnail, CharSequence description) {
-        //System.out.println("Report thumbnail for " + token + ": " + thumbnail);
-        final long origId = Binder.clearCallingIdentity();
-        sendPendingThumbnail(null, token, thumbnail, description, true);
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    final void sendPendingThumbnail(ActivityRecord r, IBinder token,
-            Bitmap thumbnail, CharSequence description, boolean always) {
-        TaskRecord task;
-        ArrayList<PendingThumbnailsRecord> receivers = null;
-
-        //System.out.println("Send pending thumbnail: " + r);
-
-        synchronized(this) {
-            if (r == null) {
-                r = ActivityRecord.isInStackLocked(token);
-                if (r == null) {
-                    return;
-                }
-            }
-            if (thumbnail == null && r.thumbHolder != null) {
-                thumbnail = r.thumbHolder.lastThumbnail;
-                description = r.thumbHolder.lastDescription;
-            }
-            if (thumbnail == null && !always) {
-                // If there is no thumbnail, and this entry is not actually
-                // going away, then abort for now and pick up the next
-                // thumbnail we get.
-                return;
-            }
-            task = r.task;
-
-            int N = mPendingThumbnails.size();
-            int i=0;
-            while (i<N) {
-                PendingThumbnailsRecord pr = mPendingThumbnails.get(i);
-                //System.out.println("Looking in " + pr.pendingRecords);
-                if (pr.pendingRecords.remove(r)) {
-                    if (receivers == null) {
-                        receivers = new ArrayList<PendingThumbnailsRecord>();
-                    }
-                    receivers.add(pr);
-                    if (pr.pendingRecords.size() == 0) {
-                        pr.finished = true;
-                        mPendingThumbnails.remove(i);
-                        N--;
-                        continue;
-                    }
-                }
-                i++;
-            }
-        }
-
-        if (receivers != null) {
-            final int N = receivers.size();
-            for (int i=0; i<N; i++) {
-                try {
-                    PendingThumbnailsRecord pr = receivers.get(i);
-                    pr.receiver.newThumbnail(
-                        task != null ? task.taskId : -1, thumbnail, description);
-                    if (pr.finished) {
-                        pr.receiver.finished();
-                    }
-                } catch (Exception e) {
-                    Slog.w(TAG, "Exception thrown when sending thumbnail", e);
-                }
-            }
-        }
-    }
-
-    // =========================================================
-    // CONTENT PROVIDERS
-    // =========================================================
-
-    private final List<ProviderInfo> generateApplicationProvidersLocked(ProcessRecord app) {
-        List<ProviderInfo> providers = null;
-        try {
-            providers = AppGlobals.getPackageManager().
-                queryContentProviders(app.processName, app.uid,
-                        STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS);
-        } catch (RemoteException ex) {
-        }
-        if (DEBUG_MU)
-            Slog.v(TAG_MU, "generateApplicationProvidersLocked, app.info.uid = " + app.uid);
-        int userId = app.userId;
-        if (providers != null) {
-            int N = providers.size();
-            app.pubProviders.ensureCapacity(N + app.pubProviders.size());
-            for (int i=0; i<N; i++) {
-                ProviderInfo cpi =
-                    (ProviderInfo)providers.get(i);
-                boolean singleton = isSingleton(cpi.processName, cpi.applicationInfo,
-                        cpi.name, cpi.flags);
-                if (singleton && UserHandle.getUserId(app.uid) != 0) {
-                    // This is a singleton provider, but a user besides the
-                    // default user is asking to initialize a process it runs
-                    // in...  well, no, it doesn't actually run in this process,
-                    // it runs in the process of the default user.  Get rid of it.
-                    providers.remove(i);
-                    N--;
-                    i--;
-                    continue;
-                }
-
-                ComponentName comp = new ComponentName(cpi.packageName, cpi.name);
-                ContentProviderRecord cpr = mProviderMap.getProviderByClass(comp, userId);
-                if (cpr == null) {
-                    cpr = new ContentProviderRecord(this, cpi, app.info, comp, singleton);
-                    mProviderMap.putProviderByClass(comp, cpr);
-                }
-                if (DEBUG_MU)
-                    Slog.v(TAG_MU, "generateApplicationProvidersLocked, cpi.uid = " + cpr.uid);
-                app.pubProviders.put(cpi.name, cpr);
-                if (!cpi.multiprocess || !"android".equals(cpi.packageName)) {
-                    // Don't add this if it is a platform component that is marked
-                    // to run in multiple processes, because this is actually
-                    // part of the framework so doesn't make sense to track as a
-                    // separate apk in the process.
-                    app.addPackage(cpi.applicationInfo.packageName, mProcessStats);
-                }
-                ensurePackageDexOpt(cpi.applicationInfo.packageName);
-            }
-        }
-        return providers;
-    }
-
-    /**
-     * Check if {@link ProcessRecord} has a possible chance at accessing the
-     * given {@link ProviderInfo}. Final permission checking is always done
-     * in {@link ContentProvider}.
-     */
-    private final String checkContentProviderPermissionLocked(
-            ProviderInfo cpi, ProcessRecord r) {
-        final int callingPid = (r != null) ? r.pid : Binder.getCallingPid();
-        final int callingUid = (r != null) ? r.uid : Binder.getCallingUid();
-        if (checkComponentPermission(cpi.readPermission, callingPid, callingUid,
-                cpi.applicationInfo.uid, cpi.exported)
-                == PackageManager.PERMISSION_GRANTED) {
-            return null;
-        }
-        if (checkComponentPermission(cpi.writePermission, callingPid, callingUid,
-                cpi.applicationInfo.uid, cpi.exported)
-                == PackageManager.PERMISSION_GRANTED) {
-            return null;
-        }
-        
-        PathPermission[] pps = cpi.pathPermissions;
-        if (pps != null) {
-            int i = pps.length;
-            while (i > 0) {
-                i--;
-                PathPermission pp = pps[i];
-                if (checkComponentPermission(pp.getReadPermission(), callingPid, callingUid,
-                        cpi.applicationInfo.uid, cpi.exported)
-                        == PackageManager.PERMISSION_GRANTED) {
-                    return null;
-                }
-                if (checkComponentPermission(pp.getWritePermission(), callingPid, callingUid,
-                        cpi.applicationInfo.uid, cpi.exported)
-                        == PackageManager.PERMISSION_GRANTED) {
-                    return null;
-                }
-            }
-        }
-        
-        ArrayMap<Uri, UriPermission> perms = mGrantedUriPermissions.get(callingUid);
-        if (perms != null) {
-            for (Map.Entry<Uri, UriPermission> uri : perms.entrySet()) {
-                if (uri.getKey().getAuthority().equals(cpi.authority)) {
-                    return null;
-                }
-            }
-        }
-
-        String msg;
-        if (!cpi.exported) {
-            msg = "Permission Denial: opening provider " + cpi.name
-                    + " from " + (r != null ? r : "(null)") + " (pid=" + callingPid
-                    + ", uid=" + callingUid + ") that is not exported from uid "
-                    + cpi.applicationInfo.uid;
-        } else {
-            msg = "Permission Denial: opening provider " + cpi.name
-                    + " from " + (r != null ? r : "(null)") + " (pid=" + callingPid
-                    + ", uid=" + callingUid + ") requires "
-                    + cpi.readPermission + " or " + cpi.writePermission;
-        }
-        Slog.w(TAG, msg);
-        return msg;
-    }
-
-    ContentProviderConnection incProviderCountLocked(ProcessRecord r,
-            final ContentProviderRecord cpr, IBinder externalProcessToken, boolean stable) {
-        if (r != null) {
-            for (int i=0; i<r.conProviders.size(); i++) {
-                ContentProviderConnection conn = r.conProviders.get(i);
-                if (conn.provider == cpr) {
-                    if (DEBUG_PROVIDER) Slog.v(TAG,
-                            "Adding provider requested by "
-                            + r.processName + " from process "
-                            + cpr.info.processName + ": " + cpr.name.flattenToShortString()
-                            + " scnt=" + conn.stableCount + " uscnt=" + conn.unstableCount);
-                    if (stable) {
-                        conn.stableCount++;
-                        conn.numStableIncs++;
-                    } else {
-                        conn.unstableCount++;
-                        conn.numUnstableIncs++;
-                    }
-                    return conn;
-                }
-            }
-            ContentProviderConnection conn = new ContentProviderConnection(cpr, r);
-            if (stable) {
-                conn.stableCount = 1;
-                conn.numStableIncs = 1;
-            } else {
-                conn.unstableCount = 1;
-                conn.numUnstableIncs = 1;
-            }
-            cpr.connections.add(conn);
-            r.conProviders.add(conn);
-            return conn;
-        }
-        cpr.addExternalProcessHandleLocked(externalProcessToken);
-        return null;
-    }
-
-    boolean decProviderCountLocked(ContentProviderConnection conn,
-            ContentProviderRecord cpr, IBinder externalProcessToken, boolean stable) {
-        if (conn != null) {
-            cpr = conn.provider;
-            if (DEBUG_PROVIDER) Slog.v(TAG,
-                    "Removing provider requested by "
-                    + conn.client.processName + " from process "
-                    + cpr.info.processName + ": " + cpr.name.flattenToShortString()
-                    + " scnt=" + conn.stableCount + " uscnt=" + conn.unstableCount);
-            if (stable) {
-                conn.stableCount--;
-            } else {
-                conn.unstableCount--;
-            }
-            if (conn.stableCount == 0 && conn.unstableCount == 0) {
-                cpr.connections.remove(conn);
-                conn.client.conProviders.remove(conn);
-                return true;
-            }
-            return false;
-        }
-        cpr.removeExternalProcessHandleLocked(externalProcessToken);
-        return false;
-    }
-
-    private final ContentProviderHolder getContentProviderImpl(IApplicationThread caller,
-            String name, IBinder token, boolean stable, int userId) {
-        ContentProviderRecord cpr;
-        ContentProviderConnection conn = null;
-        ProviderInfo cpi = null;
-
-        synchronized(this) {
-            ProcessRecord r = null;
-            if (caller != null) {
-                r = getRecordForAppLocked(caller);
-                if (r == null) {
-                    throw new SecurityException(
-                            "Unable to find app for caller " + caller
-                          + " (pid=" + Binder.getCallingPid()
-                          + ") when getting content provider " + name);
-                }
-            }
-
-            // First check if this content provider has been published...
-            cpr = mProviderMap.getProviderByName(name, userId);
-            boolean providerRunning = cpr != null;
-            if (providerRunning) {
-                cpi = cpr.info;
-                String msg;
-                if ((msg=checkContentProviderPermissionLocked(cpi, r)) != null) {
-                    throw new SecurityException(msg);
-                }
-
-                if (r != null && cpr.canRunHere(r)) {
-                    // This provider has been published or is in the process
-                    // of being published...  but it is also allowed to run
-                    // in the caller's process, so don't make a connection
-                    // and just let the caller instantiate its own instance.
-                    ContentProviderHolder holder = cpr.newHolder(null);
-                    // don't give caller the provider object, it needs
-                    // to make its own.
-                    holder.provider = null;
-                    return holder;
-                }
-
-                final long origId = Binder.clearCallingIdentity();
-
-                // In this case the provider instance already exists, so we can
-                // return it right away.
-                conn = incProviderCountLocked(r, cpr, token, stable);
-                if (conn != null && (conn.stableCount+conn.unstableCount) == 1) {
-                    if (cpr.proc != null && r.setAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
-                        // If this is a perceptible app accessing the provider,
-                        // make sure to count it as being accessed and thus
-                        // back up on the LRU list.  This is good because
-                        // content providers are often expensive to start.
-                        updateLruProcessLocked(cpr.proc, false, null);
-                    }
-                }
-
-                if (cpr.proc != null) {
-                    if (false) {
-                        if (cpr.name.flattenToShortString().equals(
-                                "com.android.providers.calendar/.CalendarProvider2")) {
-                            Slog.v(TAG, "****************** KILLING "
-                                + cpr.name.flattenToShortString());
-                            Process.killProcess(cpr.proc.pid);
-                        }
-                    }
-                    boolean success = updateOomAdjLocked(cpr.proc);
-                    if (DEBUG_PROVIDER) Slog.i(TAG, "Adjust success: " + success);
-                    // NOTE: there is still a race here where a signal could be
-                    // pending on the process even though we managed to update its
-                    // adj level.  Not sure what to do about this, but at least
-                    // the race is now smaller.
-                    if (!success) {
-                        // Uh oh...  it looks like the provider's process
-                        // has been killed on us.  We need to wait for a new
-                        // process to be started, and make sure its death
-                        // doesn't kill our process.
-                        Slog.i(TAG,
-                                "Existing provider " + cpr.name.flattenToShortString()
-                                + " is crashing; detaching " + r);
-                        boolean lastRef = decProviderCountLocked(conn, cpr, token, stable);
-                        appDiedLocked(cpr.proc, cpr.proc.pid, cpr.proc.thread);
-                        if (!lastRef) {
-                            // This wasn't the last ref our process had on
-                            // the provider...  we have now been killed, bail.
-                            return null;
-                        }
-                        providerRunning = false;
-                        conn = null;
-                    }
-                }
-
-                Binder.restoreCallingIdentity(origId);
-            }
-
-            boolean singleton;
-            if (!providerRunning) {
-                try {
-                    cpi = AppGlobals.getPackageManager().
-                        resolveContentProvider(name,
-                            STOCK_PM_FLAGS | PackageManager.GET_URI_PERMISSION_PATTERNS, userId);
-                } catch (RemoteException ex) {
-                }
-                if (cpi == null) {
-                    return null;
-                }
-                singleton = isSingleton(cpi.processName, cpi.applicationInfo,
-                        cpi.name, cpi.flags); 
-                if (singleton) {
-                    userId = 0;
-                }
-                cpi.applicationInfo = getAppInfoForUser(cpi.applicationInfo, userId);
-
-                String msg;
-                if ((msg=checkContentProviderPermissionLocked(cpi, r)) != null) {
-                    throw new SecurityException(msg);
-                }
-
-                if (!mProcessesReady && !mDidUpdate && !mWaitingUpdate
-                        && !cpi.processName.equals("system")) {
-                    // If this content provider does not run in the system
-                    // process, and the system is not yet ready to run other
-                    // processes, then fail fast instead of hanging.
-                    throw new IllegalArgumentException(
-                            "Attempt to launch content provider before system ready");
-                }
-
-                // Make sure that the user who owns this provider is started.  If not,
-                // we don't want to allow it to run.
-                if (mStartedUsers.get(userId) == null) {
-                    Slog.w(TAG, "Unable to launch app "
-                            + cpi.applicationInfo.packageName + "/"
-                            + cpi.applicationInfo.uid + " for provider "
-                            + name + ": user " + userId + " is stopped");
-                    return null;
-                }
-
-                ComponentName comp = new ComponentName(cpi.packageName, cpi.name);
-                cpr = mProviderMap.getProviderByClass(comp, userId);
-                final boolean firstClass = cpr == null;
-                if (firstClass) {
-                    try {
-                        ApplicationInfo ai =
-                            AppGlobals.getPackageManager().
-                                getApplicationInfo(
-                                        cpi.applicationInfo.packageName,
-                                        STOCK_PM_FLAGS, userId);
-                        if (ai == null) {
-                            Slog.w(TAG, "No package info for content provider "
-                                    + cpi.name);
-                            return null;
-                        }
-                        ai = getAppInfoForUser(ai, userId);
-                        cpr = new ContentProviderRecord(this, cpi, ai, comp, singleton);
-                    } catch (RemoteException ex) {
-                        // pm is in same process, this will never happen.
-                    }
-                }
-
-                if (r != null && cpr.canRunHere(r)) {
-                    // If this is a multiprocess provider, then just return its
-                    // info and allow the caller to instantiate it.  Only do
-                    // this if the provider is the same user as the caller's
-                    // process, or can run as root (so can be in any process).
-                    return cpr.newHolder(null);
-                }
-
-                if (DEBUG_PROVIDER) {
-                    RuntimeException e = new RuntimeException("here");
-                    Slog.w(TAG, "LAUNCHING REMOTE PROVIDER (myuid " + (r != null ? r.uid : null)
-                          + " pruid " + cpr.appInfo.uid + "): " + cpr.info.name, e);
-                }
-
-                // This is single process, and our app is now connecting to it.
-                // See if we are already in the process of launching this
-                // provider.
-                final int N = mLaunchingProviders.size();
-                int i;
-                for (i=0; i<N; i++) {
-                    if (mLaunchingProviders.get(i) == cpr) {
-                        break;
-                    }
-                }
-
-                // If the provider is not already being launched, then get it
-                // started.
-                if (i >= N) {
-                    final long origId = Binder.clearCallingIdentity();
-
-                    try {
-                        // Content provider is now in use, its package can't be stopped.
-                        try {
-                            AppGlobals.getPackageManager().setPackageStoppedState(
-                                    cpr.appInfo.packageName, false, userId);
-                        } catch (RemoteException e) {
-                        } catch (IllegalArgumentException e) {
-                            Slog.w(TAG, "Failed trying to unstop package "
-                                    + cpr.appInfo.packageName + ": " + e);
-                        }
-
-                        // Use existing process if already started
-                        ProcessRecord proc = getProcessRecordLocked(
-                                cpi.processName, cpr.appInfo.uid, false);
-                        if (proc != null && proc.thread != null) {
-                            if (DEBUG_PROVIDER) {
-                                Slog.d(TAG, "Installing in existing process " + proc);
-                            }
-                            proc.pubProviders.put(cpi.name, cpr);
-                            try {
-                                proc.thread.scheduleInstallProvider(cpi);
-                            } catch (RemoteException e) {
-                            }
-                        } else {
-                            proc = startProcessLocked(cpi.processName,
-                                    cpr.appInfo, false, 0, "content provider",
-                                    new ComponentName(cpi.applicationInfo.packageName,
-                                            cpi.name), false, false, false);
-                            if (proc == null) {
-                                Slog.w(TAG, "Unable to launch app "
-                                        + cpi.applicationInfo.packageName + "/"
-                                        + cpi.applicationInfo.uid + " for provider "
-                                        + name + ": process is bad");
-                                return null;
-                            }
-                        }
-                        cpr.launchingApp = proc;
-                        mLaunchingProviders.add(cpr);
-                    } finally {
-                        Binder.restoreCallingIdentity(origId);
-                    }
-                }
-
-                // Make sure the provider is published (the same provider class
-                // may be published under multiple names).
-                if (firstClass) {
-                    mProviderMap.putProviderByClass(comp, cpr);
-                }
-
-                mProviderMap.putProviderByName(name, cpr);
-                conn = incProviderCountLocked(r, cpr, token, stable);
-                if (conn != null) {
-                    conn.waiting = true;
-                }
-            }
-        }
-
-        // Wait for the provider to be published...
-        synchronized (cpr) {
-            while (cpr.provider == null) {
-                if (cpr.launchingApp == null) {
-                    Slog.w(TAG, "Unable to launch app "
-                            + cpi.applicationInfo.packageName + "/"
-                            + cpi.applicationInfo.uid + " for provider "
-                            + name + ": launching app became null");
-                    EventLog.writeEvent(EventLogTags.AM_PROVIDER_LOST_PROCESS,
-                            UserHandle.getUserId(cpi.applicationInfo.uid),
-                            cpi.applicationInfo.packageName,
-                            cpi.applicationInfo.uid, name);
-                    return null;
-                }
-                try {
-                    if (DEBUG_MU) {
-                        Slog.v(TAG_MU, "Waiting to start provider " + cpr + " launchingApp="
-                                + cpr.launchingApp);
-                    }
-                    if (conn != null) {
-                        conn.waiting = true;
-                    }
-                    cpr.wait();
-                } catch (InterruptedException ex) {
-                } finally {
-                    if (conn != null) {
-                        conn.waiting = false;
-                    }
-                }
-            }
-        }
-        return cpr != null ? cpr.newHolder(conn) : null;
-    }
-
-    public final ContentProviderHolder getContentProvider(
-            IApplicationThread caller, String name, int userId, boolean stable) {
-        enforceNotIsolatedCaller("getContentProvider");
-        if (caller == null) {
-            String msg = "null IApplicationThread when getting content provider "
-                    + name;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "getContentProvider", null);
-        return getContentProviderImpl(caller, name, null, stable, userId);
-    }
-
-    public ContentProviderHolder getContentProviderExternal(
-            String name, int userId, IBinder token) {
-        enforceCallingPermission(android.Manifest.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY,
-            "Do not have permission in call getContentProviderExternal()");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId,
-                false, true, "getContentProvider", null);
-        return getContentProviderExternalUnchecked(name, token, userId);
-    }
-
-    private ContentProviderHolder getContentProviderExternalUnchecked(String name,
-            IBinder token, int userId) {
-        return getContentProviderImpl(null, name, token, true, userId);
-    }
-
-    /**
-     * Drop a content provider from a ProcessRecord's bookkeeping
-     */
-    public void removeContentProvider(IBinder connection, boolean stable) {
-        enforceNotIsolatedCaller("removeContentProvider");
-        synchronized (this) {
-            ContentProviderConnection conn;
-            try {
-                conn = (ContentProviderConnection)connection;
-            } catch (ClassCastException e) {
-                String msg ="removeContentProvider: " + connection
-                        + " not a ContentProviderConnection";
-                Slog.w(TAG, msg);
-                throw new IllegalArgumentException(msg);
-            }
-            if (conn == null) {
-                throw new NullPointerException("connection is null");
-            }
-            if (decProviderCountLocked(conn, null, null, stable)) {
-                updateOomAdjLocked();
-            }
-        }
-    }
-
-    public void removeContentProviderExternal(String name, IBinder token) {
-        enforceCallingPermission(android.Manifest.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY,
-            "Do not have permission in call removeContentProviderExternal()");
-        removeContentProviderExternalUnchecked(name, token, UserHandle.getCallingUserId());
-    }
-
-    private void removeContentProviderExternalUnchecked(String name, IBinder token, int userId) {
-        synchronized (this) {
-            ContentProviderRecord cpr = mProviderMap.getProviderByName(name, userId);
-            if(cpr == null) {
-                //remove from mProvidersByClass
-                if(localLOGV) Slog.v(TAG, name+" content provider not found in providers list");
-                return;
-            }
-
-            //update content provider record entry info
-            ComponentName comp = new ComponentName(cpr.info.packageName, cpr.info.name);
-            ContentProviderRecord localCpr = mProviderMap.getProviderByClass(comp, userId);
-            if (localCpr.hasExternalProcessHandles()) {
-                if (localCpr.removeExternalProcessHandleLocked(token)) {
-                    updateOomAdjLocked();
-                } else {
-                    Slog.e(TAG, "Attmpt to remove content provider " + localCpr
-                            + " with no external reference for token: "
-                            + token + ".");
-                }
-            } else {
-                Slog.e(TAG, "Attmpt to remove content provider: " + localCpr
-                        + " with no external references.");
-            }
-        }
-    }
-    
-    public final void publishContentProviders(IApplicationThread caller,
-            List<ContentProviderHolder> providers) {
-        if (providers == null) {
-            return;
-        }
-
-        enforceNotIsolatedCaller("publishContentProviders");
-        synchronized (this) {
-            final ProcessRecord r = getRecordForAppLocked(caller);
-            if (DEBUG_MU)
-                Slog.v(TAG_MU, "ProcessRecord uid = " + r.uid);
-            if (r == null) {
-                throw new SecurityException(
-                        "Unable to find app for caller " + caller
-                      + " (pid=" + Binder.getCallingPid()
-                      + ") when publishing content providers");
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-
-            final int N = providers.size();
-            for (int i=0; i<N; i++) {
-                ContentProviderHolder src = providers.get(i);
-                if (src == null || src.info == null || src.provider == null) {
-                    continue;
-                }
-                ContentProviderRecord dst = r.pubProviders.get(src.info.name);
-                if (DEBUG_MU)
-                    Slog.v(TAG_MU, "ContentProviderRecord uid = " + dst.uid);
-                if (dst != null) {
-                    ComponentName comp = new ComponentName(dst.info.packageName, dst.info.name);
-                    mProviderMap.putProviderByClass(comp, dst);
-                    String names[] = dst.info.authority.split(";");
-                    for (int j = 0; j < names.length; j++) {
-                        mProviderMap.putProviderByName(names[j], dst);
-                    }
-
-                    int NL = mLaunchingProviders.size();
-                    int j;
-                    for (j=0; j<NL; j++) {
-                        if (mLaunchingProviders.get(j) == dst) {
-                            mLaunchingProviders.remove(j);
-                            j--;
-                            NL--;
-                        }
-                    }
-                    synchronized (dst) {
-                        dst.provider = src.provider;
-                        dst.proc = r;
-                        dst.notifyAll();
-                    }
-                    updateOomAdjLocked(r);
-                }
-            }
-
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    public boolean refContentProvider(IBinder connection, int stable, int unstable) {
-        ContentProviderConnection conn;
-        try {
-            conn = (ContentProviderConnection)connection;
-        } catch (ClassCastException e) {
-            String msg ="refContentProvider: " + connection
-                    + " not a ContentProviderConnection";
-            Slog.w(TAG, msg);
-            throw new IllegalArgumentException(msg);
-        }
-        if (conn == null) {
-            throw new NullPointerException("connection is null");
-        }
-
-        synchronized (this) {
-            if (stable > 0) {
-                conn.numStableIncs += stable;
-            }
-            stable = conn.stableCount + stable;
-            if (stable < 0) {
-                throw new IllegalStateException("stableCount < 0: " + stable);
-            }
-
-            if (unstable > 0) {
-                conn.numUnstableIncs += unstable;
-            }
-            unstable = conn.unstableCount + unstable;
-            if (unstable < 0) {
-                throw new IllegalStateException("unstableCount < 0: " + unstable);
-            }
-
-            if ((stable+unstable) <= 0) {
-                throw new IllegalStateException("ref counts can't go to zero here: stable="
-                        + stable + " unstable=" + unstable);
-            }
-            conn.stableCount = stable;
-            conn.unstableCount = unstable;
-            return !conn.dead;
-        }
-    }
-
-    public void unstableProviderDied(IBinder connection) {
-        ContentProviderConnection conn;
-        try {
-            conn = (ContentProviderConnection)connection;
-        } catch (ClassCastException e) {
-            String msg ="refContentProvider: " + connection
-                    + " not a ContentProviderConnection";
-            Slog.w(TAG, msg);
-            throw new IllegalArgumentException(msg);
-        }
-        if (conn == null) {
-            throw new NullPointerException("connection is null");
-        }
-
-        // Safely retrieve the content provider associated with the connection.
-        IContentProvider provider;
-        synchronized (this) {
-            provider = conn.provider.provider;
-        }
-
-        if (provider == null) {
-            // Um, yeah, we're way ahead of you.
-            return;
-        }
-
-        // Make sure the caller is being honest with us.
-        if (provider.asBinder().pingBinder()) {
-            // Er, no, still looks good to us.
-            synchronized (this) {
-                Slog.w(TAG, "unstableProviderDied: caller " + Binder.getCallingUid()
-                        + " says " + conn + " died, but we don't agree");
-                return;
-            }
-        }
-
-        // Well look at that!  It's dead!
-        synchronized (this) {
-            if (conn.provider.provider != provider) {
-                // But something changed...  good enough.
-                return;
-            }
-
-            ProcessRecord proc = conn.provider.proc;
-            if (proc == null || proc.thread == null) {
-                // Seems like the process is already cleaned up.
-                return;
-            }
-
-            // As far as we're concerned, this is just like receiving a
-            // death notification...  just a bit prematurely.
-            Slog.i(TAG, "Process " + proc.processName + " (pid " + proc.pid
-                    + ") early provider death");
-            final long ident = Binder.clearCallingIdentity();
-            try {
-                appDiedLocked(proc, proc.pid, proc.thread);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    @Override
-    public void appNotRespondingViaProvider(IBinder connection) {
-        enforceCallingPermission(
-                android.Manifest.permission.REMOVE_TASKS, "appNotRespondingViaProvider()");
-
-        final ContentProviderConnection conn = (ContentProviderConnection) connection;
-        if (conn == null) {
-            Slog.w(TAG, "ContentProviderConnection is null");
-            return;
-        }
-
-        final ProcessRecord host = conn.provider.proc;
-        if (host == null) {
-            Slog.w(TAG, "Failed to find hosting ProcessRecord");
-            return;
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            appNotResponding(host, null, null, false, "ContentProvider not responding");
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    public static final void installSystemProviders() {
-        List<ProviderInfo> providers;
-        synchronized (mSelf) {
-            ProcessRecord app = mSelf.mProcessNames.get("system", Process.SYSTEM_UID);
-            providers = mSelf.generateApplicationProvidersLocked(app);
-            if (providers != null) {
-                for (int i=providers.size()-1; i>=0; i--) {
-                    ProviderInfo pi = (ProviderInfo)providers.get(i);
-                    if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
-                        Slog.w(TAG, "Not installing system proc provider " + pi.name
-                                + ": not system .apk");
-                        providers.remove(i);
-                    }
-                }
-            }
-        }
-        if (providers != null) {
-            mSystemThread.installSystemProviders(providers);
-        }
-
-        mSelf.mCoreSettingsObserver = new CoreSettingsObserver(mSelf);
-
-        mSelf.mUsageStatsService.monitorPackages();
-    }
-
-    /**
-     * Allows app to retrieve the MIME type of a URI without having permission
-     * to access its content provider.
-     *
-     * CTS tests for this functionality can be run with "runtest cts-appsecurity".
-     *
-     * Test cases are at cts/tests/appsecurity-tests/test-apps/UsePermissionDiffCert/
-     *     src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
-     */
-    public String getProviderMimeType(Uri uri, int userId) {
-        enforceNotIsolatedCaller("getProviderMimeType");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
-                userId, false, true, "getProviderMimeType", null);
-        final String name = uri.getAuthority();
-        final long ident = Binder.clearCallingIdentity();
-        ContentProviderHolder holder = null;
-
-        try {
-            holder = getContentProviderExternalUnchecked(name, null, userId);
-            if (holder != null) {
-                return holder.provider.getType(uri);
-            }
-        } catch (RemoteException e) {
-            Log.w(TAG, "Content provider dead retrieving " + uri, e);
-            return null;
-        } finally {
-            if (holder != null) {
-                removeContentProviderExternalUnchecked(name, null, userId);
-            }
-            Binder.restoreCallingIdentity(ident);
-        }
-
-        return null;
-    }
-
-    // =========================================================
-    // GLOBAL MANAGEMENT
-    // =========================================================
-
-    final ProcessRecord newProcessRecordLocked(ApplicationInfo info, String customProcess,
-            boolean isolated) {
-        String proc = customProcess != null ? customProcess : info.processName;
-        BatteryStatsImpl.Uid.Proc ps = null;
-        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-        int uid = info.uid;
-        if (isolated) {
-            int userId = UserHandle.getUserId(uid);
-            int stepsLeft = Process.LAST_ISOLATED_UID - Process.FIRST_ISOLATED_UID + 1;
-            while (true) {
-                if (mNextIsolatedProcessUid < Process.FIRST_ISOLATED_UID
-                        || mNextIsolatedProcessUid > Process.LAST_ISOLATED_UID) {
-                    mNextIsolatedProcessUid = Process.FIRST_ISOLATED_UID;
-                }
-                uid = UserHandle.getUid(userId, mNextIsolatedProcessUid);
-                mNextIsolatedProcessUid++;
-                if (mIsolatedProcesses.indexOfKey(uid) < 0) {
-                    // No process for this uid, use it.
-                    break;
-                }
-                stepsLeft--;
-                if (stepsLeft <= 0) {
-                    return null;
-                }
-            }
-        }
-        return new ProcessRecord(stats, info, proc, uid);
-    }
-
-    final ProcessRecord addAppLocked(ApplicationInfo info, boolean isolated) {
-        ProcessRecord app;
-        if (!isolated) {
-            app = getProcessRecordLocked(info.processName, info.uid, true);
-        } else {
-            app = null;
-        }
-
-        if (app == null) {
-            app = newProcessRecordLocked(info, null, isolated);
-            mProcessNames.put(info.processName, app.uid, app);
-            if (isolated) {
-                mIsolatedProcesses.put(app.uid, app);
-            }
-            updateLruProcessLocked(app, false, null);
-            updateOomAdjLocked();
-        }
-
-        // This package really, really can not be stopped.
-        try {
-            AppGlobals.getPackageManager().setPackageStoppedState(
-                    info.packageName, false, UserHandle.getUserId(app.uid));
-        } catch (RemoteException e) {
-        } catch (IllegalArgumentException e) {
-            Slog.w(TAG, "Failed trying to unstop package "
-                    + info.packageName + ": " + e);
-        }
-
-        if ((info.flags&(ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT))
-                == (ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT)) {
-            app.persistent = true;
-            app.maxAdj = ProcessList.PERSISTENT_PROC_ADJ;
-        }
-        if (app.thread == null && mPersistentStartingProcesses.indexOf(app) < 0) {
-            mPersistentStartingProcesses.add(app);
-            startProcessLocked(app, "added application", app.processName);
-        }
-
-        return app;
-    }
-
-    public void unhandledBack() {
-        enforceCallingPermission(android.Manifest.permission.FORCE_BACK,
-                "unhandledBack()");
-
-        synchronized(this) {
-            final long origId = Binder.clearCallingIdentity();
-            try {
-                getFocusedStack().unhandledBackLocked();
-            } finally {
-                Binder.restoreCallingIdentity(origId);
-            }
-        }
-    }
-
-    public ParcelFileDescriptor openContentUri(Uri uri) throws RemoteException {
-        enforceNotIsolatedCaller("openContentUri");
-        final int userId = UserHandle.getCallingUserId();
-        String name = uri.getAuthority();
-        ContentProviderHolder cph = getContentProviderExternalUnchecked(name, null, userId);
-        ParcelFileDescriptor pfd = null;
-        if (cph != null) {
-            // We record the binder invoker's uid in thread-local storage before
-            // going to the content provider to open the file.  Later, in the code
-            // that handles all permissions checks, we look for this uid and use
-            // that rather than the Activity Manager's own uid.  The effect is that
-            // we do the check against the caller's permissions even though it looks
-            // to the content provider like the Activity Manager itself is making
-            // the request.
-            sCallerIdentity.set(new Identity(
-                    Binder.getCallingPid(), Binder.getCallingUid()));
-            try {
-                pfd = cph.provider.openFile(null, uri, "r", null);
-            } catch (FileNotFoundException e) {
-                // do nothing; pfd will be returned null
-            } finally {
-                // Ensure that whatever happens, we clean up the identity state
-                sCallerIdentity.remove();
-            }
-
-            // We've got the fd now, so we're done with the provider.
-            removeContentProviderExternalUnchecked(name, null, userId);
-        } else {
-            Slog.d(TAG, "Failed to get provider for authority '" + name + "'");
-        }
-        return pfd;
-    }
-
-    // Actually is sleeping or shutting down or whatever else in the future
-    // is an inactive state.
-    public boolean isSleepingOrShuttingDown() {
-        return mSleeping || mShuttingDown;
-    }
-
-    public void goingToSleep() {
-        if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.DEVICE_POWER);
-        }
-
-        synchronized(this) {
-            mWentToSleep = true;
-            updateEventDispatchingLocked();
-
-            if (!mSleeping) {
-                mSleeping = true;
-                mStackSupervisor.goingToSleepLocked();
-
-                // Initialize the wake times of all processes.
-                checkExcessivePowerUsageLocked(false);
-                mHandler.removeMessages(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
-                Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
-                mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
-            }
-        }
-    }
-
-    @Override
-    public boolean shutdown(int timeout) {
-        if (checkCallingPermission(android.Manifest.permission.SHUTDOWN)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.SHUTDOWN);
-        }
-
-        boolean timedout = false;
-
-        synchronized(this) {
-            mShuttingDown = true;
-            updateEventDispatchingLocked();
-            timedout = mStackSupervisor.shutdownLocked(timeout);
-        }
-
-        mAppOpsService.shutdown();
-        mUsageStatsService.shutdown();
-        mBatteryStatsService.shutdown();
-        synchronized (this) {
-            mProcessStats.shutdownLocked();
-        }
-
-        return timedout;
-    }
-    
-    public final void activitySlept(IBinder token) {
-        if (localLOGV) Slog.v(TAG, "Activity slept: token=" + token);
-
-        final long origId = Binder.clearCallingIdentity();
-
-        synchronized (this) {
-            final ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r != null) {
-                mStackSupervisor.activitySleptLocked(r);
-            }
-        }
-
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    void logLockScreen(String msg) {
-        if (DEBUG_LOCKSCREEN) Slog.d(TAG, Debug.getCallers(2) + ":" + msg +
-                " mLockScreenShown=" + mLockScreenShown + " mWentToSleep=" +
-                mWentToSleep + " mSleeping=" + mSleeping + " mDismissKeyguardOnNextActivity=" +
-                mStackSupervisor.mDismissKeyguardOnNextActivity);
-    }
-
-    private void comeOutOfSleepIfNeededLocked() {
-        if (!mWentToSleep && !mLockScreenShown) {
-            if (mSleeping) {
-                mSleeping = false;
-                mStackSupervisor.comeOutOfSleepIfNeededLocked();
-            }
-        }
-    }
-
-    public void wakingUp() {
-        if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.DEVICE_POWER);
-        }
-
-        synchronized(this) {
-            mWentToSleep = false;
-            updateEventDispatchingLocked();
-            comeOutOfSleepIfNeededLocked();
-        }
-    }
-
-    private void updateEventDispatchingLocked() {
-        mWindowManager.setEventDispatching(mBooted && !mWentToSleep && !mShuttingDown);
-    }
-
-    public void setLockScreenShown(boolean shown) {
-        if (checkCallingPermission(android.Manifest.permission.DEVICE_POWER)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.DEVICE_POWER);
-        }
-
-        synchronized(this) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                if (DEBUG_LOCKSCREEN) logLockScreen(" shown=" + shown);
-                mLockScreenShown = shown;
-                comeOutOfSleepIfNeededLocked();
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void stopAppSwitches() {
-        if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.STOP_APP_SWITCHES);
-        }
-        
-        synchronized(this) {
-            mAppSwitchesAllowedTime = SystemClock.uptimeMillis()
-                    + APP_SWITCH_DELAY_TIME;
-            mDidAppSwitch = false;
-            mHandler.removeMessages(DO_PENDING_ACTIVITY_LAUNCHES_MSG);
-            Message msg = mHandler.obtainMessage(DO_PENDING_ACTIVITY_LAUNCHES_MSG);
-            mHandler.sendMessageDelayed(msg, APP_SWITCH_DELAY_TIME);
-        }
-    }
-    
-    public void resumeAppSwitches() {
-        if (checkCallingPermission(android.Manifest.permission.STOP_APP_SWITCHES)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.STOP_APP_SWITCHES);
-        }
-        
-        synchronized(this) {
-            // Note that we don't execute any pending app switches... we will
-            // let those wait until either the timeout, or the next start
-            // activity request.
-            mAppSwitchesAllowedTime = 0;
-        }
-    }
-    
-    boolean checkAppSwitchAllowedLocked(int callingPid, int callingUid,
-            String name) {
-        if (mAppSwitchesAllowedTime < SystemClock.uptimeMillis()) {
-            return true;
-        }
-            
-        final int perm = checkComponentPermission(
-                android.Manifest.permission.STOP_APP_SWITCHES, callingPid,
-                callingUid, -1, true);
-        if (perm == PackageManager.PERMISSION_GRANTED) {
-            return true;
-        }
-        
-        Slog.w(TAG, name + " request from " + callingUid + " stopped");
-        return false;
-    }
-    
-    public void setDebugApp(String packageName, boolean waitForDebugger,
-            boolean persistent) {
-        enforceCallingPermission(android.Manifest.permission.SET_DEBUG_APP,
-                "setDebugApp()");
-
-        long ident = Binder.clearCallingIdentity();
-        try {
-            // Note that this is not really thread safe if there are multiple
-            // callers into it at the same time, but that's not a situation we
-            // care about.
-            if (persistent) {
-                final ContentResolver resolver = mContext.getContentResolver();
-                Settings.Global.putString(
-                    resolver, Settings.Global.DEBUG_APP,
-                    packageName);
-                Settings.Global.putInt(
-                    resolver, Settings.Global.WAIT_FOR_DEBUGGER,
-                    waitForDebugger ? 1 : 0);
-            }
-
-            synchronized (this) {
-                if (!persistent) {
-                    mOrigDebugApp = mDebugApp;
-                    mOrigWaitForDebugger = mWaitForDebugger;
-                }
-                mDebugApp = packageName;
-                mWaitForDebugger = waitForDebugger;
-                mDebugTransient = !persistent;
-                if (packageName != null) {
-                    forceStopPackageLocked(packageName, -1, false, false, true, true,
-                            false, UserHandle.USER_ALL, "set debug app");
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    void setOpenGlTraceApp(ApplicationInfo app, String processName) {
-        synchronized (this) {
-            boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
-            if (!isDebuggable) {
-                if ((app.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
-                    throw new SecurityException("Process not debuggable: " + app.packageName);
-                }
-            }
-
-            mOpenGlTraceApp = processName;
-        }
-    }
-
-    void setProfileApp(ApplicationInfo app, String processName, String profileFile,
-            ParcelFileDescriptor profileFd, boolean autoStopProfiler) {
-        synchronized (this) {
-            boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
-            if (!isDebuggable) {
-                if ((app.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
-                    throw new SecurityException("Process not debuggable: " + app.packageName);
-                }
-            }
-            mProfileApp = processName;
-            mProfileFile = profileFile;
-            if (mProfileFd != null) {
-                try {
-                    mProfileFd.close();
-                } catch (IOException e) {
-                }
-                mProfileFd = null;
-            }
-            mProfileFd = profileFd;
-            mProfileType = 0;
-            mAutoStopProfiler = autoStopProfiler;
-        }
-    }
-
-    @Override
-    public void setAlwaysFinish(boolean enabled) {
-        enforceCallingPermission(android.Manifest.permission.SET_ALWAYS_FINISH,
-                "setAlwaysFinish()");
-
-        Settings.Global.putInt(
-                mContext.getContentResolver(),
-                Settings.Global.ALWAYS_FINISH_ACTIVITIES, enabled ? 1 : 0);
-        
-        synchronized (this) {
-            mAlwaysFinishActivities = enabled;
-        }
-    }
-
-    @Override
-    public void setActivityController(IActivityController controller) {
-        enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
-                "setActivityController()");
-        synchronized (this) {
-            mController = controller;
-            Watchdog.getInstance().setActivityController(controller);
-        }
-    }
-
-    @Override
-    public void setUserIsMonkey(boolean userIsMonkey) {
-        synchronized (this) {
-            synchronized (mPidsSelfLocked) {
-                final int callingPid = Binder.getCallingPid();
-                ProcessRecord precessRecord = mPidsSelfLocked.get(callingPid);
-                if (precessRecord == null) {
-                    throw new SecurityException("Unknown process: " + callingPid);
-                }
-                if (precessRecord.instrumentationUiAutomationConnection  == null) {
-                    throw new SecurityException("Only an instrumentation process "
-                            + "with a UiAutomation can call setUserIsMonkey");
-                }
-            }
-            mUserIsMonkey = userIsMonkey;
-        }
-    }
-
-    @Override
-    public boolean isUserAMonkey() {
-        synchronized (this) {
-            // If there is a controller also implies the user is a monkey.
-            return (mUserIsMonkey || mController != null);
-        }
-    }
-
-    public void requestBugReport() {
-        enforceCallingPermission(android.Manifest.permission.DUMP, "requestBugReport");
-        SystemProperties.set("ctl.start", "bugreport");
-    }
-
-    public static long getInputDispatchingTimeoutLocked(ActivityRecord r) {
-        return r != null ? getInputDispatchingTimeoutLocked(r.app) : KEY_DISPATCHING_TIMEOUT;
-    }
-
-    public static long getInputDispatchingTimeoutLocked(ProcessRecord r) {
-        if (r != null && (r.instrumentationClass != null || r.usingWrapper)) {
-            return INSTRUMENTATION_KEY_DISPATCHING_TIMEOUT;
-        }
-        return KEY_DISPATCHING_TIMEOUT;
-    }
-
-    @Override
-    public long inputDispatchingTimedOut(int pid, final boolean aboveSystem, String reason) {
-        if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.FILTER_EVENTS);
-        }
-        ProcessRecord proc;
-        long timeout;
-        synchronized (this) {
-            synchronized (mPidsSelfLocked) {
-                proc = mPidsSelfLocked.get(pid);
-            }
-            timeout = getInputDispatchingTimeoutLocked(proc);
-        }
-
-        if (!inputDispatchingTimedOut(proc, null, null, aboveSystem, reason)) {
-            return -1;
-        }
-
-        return timeout;
-    }
-
-    /**
-     * Handle input dispatching timeouts.
-     * Returns whether input dispatching should be aborted or not.
-     */
-    public boolean inputDispatchingTimedOut(final ProcessRecord proc,
-            final ActivityRecord activity, final ActivityRecord parent,
-            final boolean aboveSystem, String reason) {
-        if (checkCallingPermission(android.Manifest.permission.FILTER_EVENTS)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.FILTER_EVENTS);
-        }
-
-        final String annotation;
-        if (reason == null) {
-            annotation = "Input dispatching timed out";
-        } else {
-            annotation = "Input dispatching timed out (" + reason + ")";
-        }
-
-        if (proc != null) {
-            synchronized (this) {
-                if (proc.debugging) {
-                    return false;
-                }
-
-                if (mDidDexOpt) {
-                    // Give more time since we were dexopting.
-                    mDidDexOpt = false;
-                    return false;
-                }
-
-                if (proc.instrumentationClass != null) {
-                    Bundle info = new Bundle();
-                    info.putString("shortMsg", "keyDispatchingTimedOut");
-                    info.putString("longMsg", annotation);
-                    finishInstrumentationLocked(proc, Activity.RESULT_CANCELED, info);
-                    return true;
-                }
-            }
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    appNotResponding(proc, activity, parent, aboveSystem, annotation);
-                }
-            });
-        }
-
-        return true;
-    }
-
-    public Bundle getAssistContextExtras(int requestType) {
-        enforceCallingPermission(android.Manifest.permission.GET_TOP_ACTIVITY_INFO,
-                "getAssistContextExtras()");
-        PendingAssistExtras pae;
-        Bundle extras = new Bundle();
-        synchronized (this) {
-            ActivityRecord activity = getFocusedStack().mResumedActivity;
-            if (activity == null) {
-                Slog.w(TAG, "getAssistContextExtras failed: no resumed activity");
-                return null;
-            }
-            extras.putString(Intent.EXTRA_ASSIST_PACKAGE, activity.packageName);
-            if (activity.app == null || activity.app.thread == null) {
-                Slog.w(TAG, "getAssistContextExtras failed: no process for " + activity);
-                return extras;
-            }
-            if (activity.app.pid == Binder.getCallingPid()) {
-                Slog.w(TAG, "getAssistContextExtras failed: request process same as " + activity);
-                return extras;
-            }
-            pae = new PendingAssistExtras(activity);
-            try {
-                activity.app.thread.requestAssistContextExtras(activity.appToken, pae,
-                        requestType);
-                mPendingAssistExtras.add(pae);
-                mHandler.postDelayed(pae, PENDING_ASSIST_EXTRAS_TIMEOUT);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "getAssistContextExtras failed: crash calling " + activity);
-                return extras;
-            }
-        }
-        synchronized (pae) {
-            while (!pae.haveResult) {
-                try {
-                    pae.wait();
-                } catch (InterruptedException e) {
-                }
-            }
-            if (pae.result != null) {
-                extras.putBundle(Intent.EXTRA_ASSIST_CONTEXT, pae.result);
-            }
-        }
-        synchronized (this) {
-            mPendingAssistExtras.remove(pae);
-            mHandler.removeCallbacks(pae);
-        }
-        return extras;
-    }
-
-    public void reportAssistContextExtras(IBinder token, Bundle extras) {
-        PendingAssistExtras pae = (PendingAssistExtras)token;
-        synchronized (pae) {
-            pae.result = extras;
-            pae.haveResult = true;
-            pae.notifyAll();
-        }
-    }
-
-    public void registerProcessObserver(IProcessObserver observer) {
-        enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
-                "registerProcessObserver()");
-        synchronized (this) {
-            mProcessObservers.register(observer);
-        }
-    }
-
-    @Override
-    public void unregisterProcessObserver(IProcessObserver observer) {
-        synchronized (this) {
-            mProcessObservers.unregister(observer);
-        }
-    }
-
-    @Override
-    public boolean convertFromTranslucent(IBinder token) {
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (this) {
-                final ActivityRecord r = ActivityRecord.isInStackLocked(token);
-                if (r == null) {
-                    return false;
-                }
-                if (r.changeWindowTranslucency(true)) {
-                    mWindowManager.setAppFullscreen(token, true);
-                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
-                    return true;
-                }
-                return false;
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public boolean convertToTranslucent(IBinder token) {
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (this) {
-                final ActivityRecord r = ActivityRecord.isInStackLocked(token);
-                if (r == null) {
-                    return false;
-                }
-                if (r.changeWindowTranslucency(false)) {
-                    r.task.stack.convertToTranslucent(r);
-                    mWindowManager.setAppFullscreen(token, false);
-                    mStackSupervisor.ensureActivitiesVisibleLocked(null, 0);
-                    return true;
-                }
-                return false;
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public void setImmersive(IBinder token, boolean immersive) {
-        synchronized(this) {
-            final ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                throw new IllegalArgumentException();
-            }
-            r.immersive = immersive;
-
-            // update associated state if we're frontmost
-            if (r == mFocusedActivity) {
-                if (DEBUG_IMMERSIVE) {
-                    Slog.d(TAG, "Frontmost changed immersion: "+ r);
-                }
-                applyUpdateLockStateLocked(r);
-            }
-        }
-    }
-
-    @Override
-    public boolean isImmersive(IBinder token) {
-        synchronized (this) {
-            ActivityRecord r = ActivityRecord.isInStackLocked(token);
-            if (r == null) {
-                throw new IllegalArgumentException();
-            }
-            return r.immersive;
-        }
-    }
-
-    public boolean isTopActivityImmersive() {
-        enforceNotIsolatedCaller("startActivity");
-        synchronized (this) {
-            ActivityRecord r = getFocusedStack().topRunningActivityLocked(null);
-            return (r != null) ? r.immersive : false;
-        }
-    }
-
-    public final void enterSafeMode() {
-        synchronized(this) {
-            // It only makes sense to do this before the system is ready
-            // and started launching other packages.
-            if (!mSystemReady) {
-                try {
-                    AppGlobals.getPackageManager().enterSafeMode();
-                } catch (RemoteException e) {
-                }
-            }
-        }
-    }
-
-    public final void showSafeModeOverlay() {
-        View v = LayoutInflater.from(mContext).inflate(
-                com.android.internal.R.layout.safe_mode, null);
-        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
-        lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
-        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
-        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
-        lp.gravity = Gravity.BOTTOM | Gravity.START;
-        lp.format = v.getBackground().getOpacity();
-        lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
-                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
-        lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
-        ((WindowManager)mContext.getSystemService(
-                Context.WINDOW_SERVICE)).addView(v, lp);
-    }
-
-    public void noteWakeupAlarm(IIntentSender sender) {
-        if (!(sender instanceof PendingIntentRecord)) {
-            return;
-        }
-        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-        synchronized (stats) {
-            if (mBatteryStatsService.isOnBattery()) {
-                mBatteryStatsService.enforceCallingPermission();
-                PendingIntentRecord rec = (PendingIntentRecord)sender;
-                int MY_UID = Binder.getCallingUid();
-                int uid = rec.uid == MY_UID ? Process.SYSTEM_UID : rec.uid;
-                BatteryStatsImpl.Uid.Pkg pkg =
-                    stats.getPackageStatsLocked(uid, rec.key.packageName);
-                pkg.incWakeupsLocked();
-            }
-        }
-    }
-
-    public boolean killPids(int[] pids, String pReason, boolean secure) {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-            throw new SecurityException("killPids only available to the system");
-        }
-        String reason = (pReason == null) ? "Unknown" : pReason;
-        // XXX Note: don't acquire main activity lock here, because the window
-        // manager calls in with its locks held.
-
-        boolean killed = false;
-        synchronized (mPidsSelfLocked) {
-            int[] types = new int[pids.length];
-            int worstType = 0;
-            for (int i=0; i<pids.length; i++) {
-                ProcessRecord proc = mPidsSelfLocked.get(pids[i]);
-                if (proc != null) {
-                    int type = proc.setAdj;
-                    types[i] = type;
-                    if (type > worstType) {
-                        worstType = type;
-                    }
-                }
-            }
-
-            // If the worst oom_adj is somewhere in the cached proc LRU range,
-            // then constrain it so we will kill all cached procs.
-            if (worstType < ProcessList.CACHED_APP_MAX_ADJ
-                    && worstType > ProcessList.CACHED_APP_MIN_ADJ) {
-                worstType = ProcessList.CACHED_APP_MIN_ADJ;
-            }
-
-            // If this is not a secure call, don't let it kill processes that
-            // are important.
-            if (!secure && worstType < ProcessList.SERVICE_ADJ) {
-                worstType = ProcessList.SERVICE_ADJ;
-            }
-
-            Slog.w(TAG, "Killing processes " + reason + " at adjustment " + worstType);
-            for (int i=0; i<pids.length; i++) {
-                ProcessRecord proc = mPidsSelfLocked.get(pids[i]);
-                if (proc == null) {
-                    continue;
-                }
-                int adj = proc.setAdj;
-                if (adj >= worstType && !proc.killedByAm) {
-                    killUnneededProcessLocked(proc, reason);
-                    killed = true;
-                }
-            }
-        }
-        return killed;
-    }
-
-    @Override
-    public void killUid(int uid, String reason) {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-            throw new SecurityException("killUid only available to the system");
-        }
-        synchronized (this) {
-            killPackageProcessesLocked(null, UserHandle.getAppId(uid), UserHandle.getUserId(uid),
-                    ProcessList.FOREGROUND_APP_ADJ-1, false, true, true, false,
-                    reason != null ? reason : "kill uid");
-        }
-    }
-
-    @Override
-    public boolean killProcessesBelowForeground(String reason) {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-            throw new SecurityException("killProcessesBelowForeground() only available to system");
-        }
-
-        return killProcessesBelowAdj(ProcessList.FOREGROUND_APP_ADJ, reason);
-    }
-
-    private boolean killProcessesBelowAdj(int belowAdj, String reason) {
-        if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-            throw new SecurityException("killProcessesBelowAdj() only available to system");
-        }
-
-        boolean killed = false;
-        synchronized (mPidsSelfLocked) {
-            final int size = mPidsSelfLocked.size();
-            for (int i = 0; i < size; i++) {
-                final int pid = mPidsSelfLocked.keyAt(i);
-                final ProcessRecord proc = mPidsSelfLocked.valueAt(i);
-                if (proc == null) continue;
-
-                final int adj = proc.setAdj;
-                if (adj > belowAdj && !proc.killedByAm) {
-                    killUnneededProcessLocked(proc, reason);
-                    killed = true;
-                }
-            }
-        }
-        return killed;
-    }
-
-    @Override
-    public void hang(final IBinder who, boolean allowRestart) {
-        if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.SET_ACTIVITY_WATCHER);
-        }
-
-        final IBinder.DeathRecipient death = new DeathRecipient() {
-            @Override
-            public void binderDied() {
-                synchronized (this) {
-                    notifyAll();
-                }
-            }
-        };
-
-        try {
-            who.linkToDeath(death, 0);
-        } catch (RemoteException e) {
-            Slog.w(TAG, "hang: given caller IBinder is already dead.");
-            return;
-        }
-
-        synchronized (this) {
-            Watchdog.getInstance().setAllowRestart(allowRestart);
-            Slog.i(TAG, "Hanging system process at request of pid " + Binder.getCallingPid());
-            synchronized (death) {
-                while (who.isBinderAlive()) {
-                    try {
-                        death.wait();
-                    } catch (InterruptedException e) {
-                    }
-                }
-            }
-            Watchdog.getInstance().setAllowRestart(true);
-        }
-    }
-
-    @Override
-    public void restart() {
-        if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.SET_ACTIVITY_WATCHER);
-        }
-
-        Log.i(TAG, "Sending shutdown broadcast...");
-
-        BroadcastReceiver br = new BroadcastReceiver() {
-            @Override public void onReceive(Context context, Intent intent) {
-                // Now the broadcast is done, finish up the low-level shutdown.
-                Log.i(TAG, "Shutting down activity manager...");
-                shutdown(10000);
-                Log.i(TAG, "Shutdown complete, restarting!");
-                Process.killProcess(Process.myPid());
-                System.exit(10);
-            }
-        };
-
-        // First send the high-level shut down broadcast.
-        Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
-        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
-        intent.putExtra(Intent.EXTRA_SHUTDOWN_USERSPACE_ONLY, true);
-        /* For now we are not doing a clean shutdown, because things seem to get unhappy.
-        mContext.sendOrderedBroadcastAsUser(intent,
-                UserHandle.ALL, null, br, mHandler, 0, null, null);
-        */
-        br.onReceive(mContext, intent);
-    }
-
-    private long getLowRamTimeSinceIdle(long now) {
-        return mLowRamTimeSinceLastIdle + (mLowRamStartTime > 0 ? (now-mLowRamStartTime) : 0);
-    }
-
-    @Override
-    public void performIdleMaintenance() {
-        if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires permission "
-                    + android.Manifest.permission.SET_ACTIVITY_WATCHER);
-        }
-
-        synchronized (this) {
-            final long now = SystemClock.uptimeMillis();
-            final long timeSinceLastIdle = now - mLastIdleTime;
-            final long lowRamSinceLastIdle = getLowRamTimeSinceIdle(now);
-            mLastIdleTime = now;
-            mLowRamTimeSinceLastIdle = 0;
-            if (mLowRamStartTime != 0) {
-                mLowRamStartTime = now;
-            }
-
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("Idle maintenance over ");
-            TimeUtils.formatDuration(timeSinceLastIdle, sb);
-            sb.append(" low RAM for ");
-            TimeUtils.formatDuration(lowRamSinceLastIdle, sb);
-            Slog.i(TAG, sb.toString());
-
-            // If at least 1/3 of our time since the last idle period has been spent
-            // with RAM low, then we want to kill processes.
-            boolean doKilling = lowRamSinceLastIdle > (timeSinceLastIdle/3);
-
-            for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
-                ProcessRecord proc = mLruProcesses.get(i);
-                if (proc.notCachedSinceIdle) {
-                    if (proc.setProcState > ActivityManager.PROCESS_STATE_TOP
-                            && proc.setProcState <= ActivityManager.PROCESS_STATE_SERVICE) {
-                        if (doKilling && proc.initialIdlePss != 0
-                                && proc.lastPss > ((proc.initialIdlePss*3)/2)) {
-                            killUnneededProcessLocked(proc, "idle maint (pss " + proc.lastPss
-                                    + " from " + proc.initialIdlePss + ")");
-                        }
-                    }
-                } else if (proc.setProcState < ActivityManager.PROCESS_STATE_HOME) {
-                    proc.notCachedSinceIdle = true;
-                    proc.initialIdlePss = 0;
-                    proc.nextPssTime = ProcessList.computeNextPssTime(proc.curProcState, true,
-                            mSleeping, now);
-                }
-            }
-
-            mHandler.removeMessages(REQUEST_ALL_PSS_MSG);
-            mHandler.sendEmptyMessageDelayed(REQUEST_ALL_PSS_MSG, 2*60*1000);
-        }
-    }
-
-    public final void startRunning(String pkg, String cls, String action,
-            String data) {
-        synchronized(this) {
-            if (mStartRunning) {
-                return;
-            }
-            mStartRunning = true;
-            mTopComponent = pkg != null && cls != null
-                    ? new ComponentName(pkg, cls) : null;
-            mTopAction = action != null ? action : Intent.ACTION_MAIN;
-            mTopData = data;
-            if (!mSystemReady) {
-                return;
-            }
-        }
-
-        systemReady(null);
-    }
-
-    private void retrieveSettings() {
-        final ContentResolver resolver = mContext.getContentResolver();
-        String debugApp = Settings.Global.getString(
-            resolver, Settings.Global.DEBUG_APP);
-        boolean waitForDebugger = Settings.Global.getInt(
-            resolver, Settings.Global.WAIT_FOR_DEBUGGER, 0) != 0;
-        boolean alwaysFinishActivities = Settings.Global.getInt(
-            resolver, Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0) != 0;
-        boolean forceRtl = Settings.Global.getInt(
-                resolver, Settings.Global.DEVELOPMENT_FORCE_RTL, 0) != 0;
-        // Transfer any global setting for forcing RTL layout, into a System Property
-        SystemProperties.set(Settings.Global.DEVELOPMENT_FORCE_RTL, forceRtl ? "1":"0");
-
-        Configuration configuration = new Configuration();
-        Settings.System.getConfiguration(resolver, configuration);
-        if (forceRtl) {
-            // This will take care of setting the correct layout direction flags
-            configuration.setLayoutDirection(configuration.locale);
-        }
-
-        synchronized (this) {
-            mDebugApp = mOrigDebugApp = debugApp;
-            mWaitForDebugger = mOrigWaitForDebugger = waitForDebugger;
-            mAlwaysFinishActivities = alwaysFinishActivities;
-            // This happens before any activities are started, so we can
-            // change mConfiguration in-place.
-            updateConfigurationLocked(configuration, null, false, true);
-            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Initial config: " + mConfiguration);
-        }
-    }
-
-    public boolean testIsSystemReady() {
-        // no need to synchronize(this) just to read & return the value
-        return mSystemReady;
-    }
-
-    private static File getCalledPreBootReceiversFile() {
-        File dataDir = Environment.getDataDirectory();
-        File systemDir = new File(dataDir, "system");
-        File fname = new File(systemDir, "called_pre_boots.dat");
-        return fname;
-    }
-
-    static final int LAST_DONE_VERSION = 10000;
-
-    private static ArrayList<ComponentName> readLastDonePreBootReceivers() {
-        ArrayList<ComponentName> lastDoneReceivers = new ArrayList<ComponentName>();
-        File file = getCalledPreBootReceiversFile();
-        FileInputStream fis = null;
-        try {
-            fis = new FileInputStream(file);
-            DataInputStream dis = new DataInputStream(new BufferedInputStream(fis, 2048));
-            int fvers = dis.readInt();
-            if (fvers == LAST_DONE_VERSION) {
-                String vers = dis.readUTF();
-                String codename = dis.readUTF();
-                String build = dis.readUTF();
-                if (android.os.Build.VERSION.RELEASE.equals(vers)
-                        && android.os.Build.VERSION.CODENAME.equals(codename)
-                        && android.os.Build.VERSION.INCREMENTAL.equals(build)) {
-                    int num = dis.readInt();
-                    while (num > 0) {
-                        num--;
-                        String pkg = dis.readUTF();
-                        String cls = dis.readUTF();
-                        lastDoneReceivers.add(new ComponentName(pkg, cls));
-                    }
-                }
-            }
-        } catch (FileNotFoundException e) {
-        } catch (IOException e) {
-            Slog.w(TAG, "Failure reading last done pre-boot receivers", e);
-        } finally {
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-        return lastDoneReceivers;
-    }
-    
-    private static void writeLastDonePreBootReceivers(ArrayList<ComponentName> list) {
-        File file = getCalledPreBootReceiversFile();
-        FileOutputStream fos = null;
-        DataOutputStream dos = null;
-        try {
-            Slog.i(TAG, "Writing new set of last done pre-boot receivers...");
-            fos = new FileOutputStream(file);
-            dos = new DataOutputStream(new BufferedOutputStream(fos, 2048));
-            dos.writeInt(LAST_DONE_VERSION);
-            dos.writeUTF(android.os.Build.VERSION.RELEASE);
-            dos.writeUTF(android.os.Build.VERSION.CODENAME);
-            dos.writeUTF(android.os.Build.VERSION.INCREMENTAL);
-            dos.writeInt(list.size());
-            for (int i=0; i<list.size(); i++) {
-                dos.writeUTF(list.get(i).getPackageName());
-                dos.writeUTF(list.get(i).getClassName());
-            }
-        } catch (IOException e) {
-            Slog.w(TAG, "Failure writing last done pre-boot receivers", e);
-            file.delete();
-        } finally {
-            FileUtils.sync(fos);
-            if (dos != null) {
-                try {
-                    dos.close();
-                } catch (IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-    
-    public void systemReady(final Runnable goingCallback) {
-        synchronized(this) {
-            if (mSystemReady) {
-                if (goingCallback != null) goingCallback.run();
-                return;
-            }
-            
-            // Check to see if there are any update receivers to run.
-            if (!mDidUpdate) {
-                if (mWaitingUpdate) {
-                    return;
-                }
-                Intent intent = new Intent(Intent.ACTION_PRE_BOOT_COMPLETED);
-                List<ResolveInfo> ris = null;
-                try {
-                    ris = AppGlobals.getPackageManager().queryIntentReceivers(
-                            intent, null, 0, 0);
-                } catch (RemoteException e) {
-                }
-                if (ris != null) {
-                    for (int i=ris.size()-1; i>=0; i--) {
-                        if ((ris.get(i).activityInfo.applicationInfo.flags
-                                &ApplicationInfo.FLAG_SYSTEM) == 0) {
-                            ris.remove(i);
-                        }
-                    }
-                    intent.addFlags(Intent.FLAG_RECEIVER_BOOT_UPGRADE);
-
-                    ArrayList<ComponentName> lastDoneReceivers = readLastDonePreBootReceivers();
-
-                    final ArrayList<ComponentName> doneReceivers = new ArrayList<ComponentName>();
-                    for (int i=0; i<ris.size(); i++) {
-                        ActivityInfo ai = ris.get(i).activityInfo;
-                        ComponentName comp = new ComponentName(ai.packageName, ai.name);
-                        if (lastDoneReceivers.contains(comp)) {
-                            // We already did the pre boot receiver for this app with the current
-                            // platform version, so don't do it again...
-                            ris.remove(i);
-                            i--;
-                            // ...however, do keep it as one that has been done, so we don't
-                            // forget about it when rewriting the file of last done receivers.
-                            doneReceivers.add(comp);
-                        }
-                    }
-
-                    final int[] users = getUsersLocked();
-                    for (int i=0; i<ris.size(); i++) {
-                        ActivityInfo ai = ris.get(i).activityInfo;
-                        ComponentName comp = new ComponentName(ai.packageName, ai.name);
-                        doneReceivers.add(comp);
-                        intent.setComponent(comp);
-                        for (int j=0; j<users.length; j++) {
-                            IIntentReceiver finisher = null;
-                            if (i == ris.size()-1 && j == users.length-1) {
-                                finisher = new IIntentReceiver.Stub() {
-                                    public void performReceive(Intent intent, int resultCode,
-                                            String data, Bundle extras, boolean ordered,
-                                            boolean sticky, int sendingUser) {
-                                        // The raw IIntentReceiver interface is called
-                                        // with the AM lock held, so redispatch to
-                                        // execute our code without the lock.
-                                        mHandler.post(new Runnable() {
-                                            public void run() {
-                                                synchronized (ActivityManagerService.this) {
-                                                    mDidUpdate = true;
-                                                }
-                                                writeLastDonePreBootReceivers(doneReceivers);
-                                                showBootMessage(mContext.getText(
-                                                        R.string.android_upgrading_complete),
-                                                        false);
-                                                systemReady(goingCallback);
-                                            }
-                                        });
-                                    }
-                                };
-                            }
-                            Slog.i(TAG, "Sending system update to " + intent.getComponent()
-                                    + " for user " + users[j]);
-                            broadcastIntentLocked(null, null, intent, null, finisher,
-                                    0, null, null, null, AppOpsManager.OP_NONE,
-                                    true, false, MY_PID, Process.SYSTEM_UID,
-                                    users[j]);
-                            if (finisher != null) {
-                                mWaitingUpdate = true;
-                            }
-                        }
-                    }
-                }
-                if (mWaitingUpdate) {
-                    return;
-                }
-                mDidUpdate = true;
-            }
-
-            mAppOpsService.systemReady();
-            mSystemReady = true;
-            if (!mStartRunning) {
-                return;
-            }
-        }
-
-        ArrayList<ProcessRecord> procsToKill = null;
-        synchronized(mPidsSelfLocked) {
-            for (int i=mPidsSelfLocked.size()-1; i>=0; i--) {
-                ProcessRecord proc = mPidsSelfLocked.valueAt(i);
-                if (!isAllowedWhileBooting(proc.info)){
-                    if (procsToKill == null) {
-                        procsToKill = new ArrayList<ProcessRecord>();
-                    }
-                    procsToKill.add(proc);
-                }
-            }
-        }
-        
-        synchronized(this) {
-            if (procsToKill != null) {
-                for (int i=procsToKill.size()-1; i>=0; i--) {
-                    ProcessRecord proc = procsToKill.get(i);
-                    Slog.i(TAG, "Removing system update proc: " + proc);
-                    removeProcessLocked(proc, true, false, "system update done");
-                }
-            }
-            
-            // Now that we have cleaned up any update processes, we
-            // are ready to start launching real processes and know that
-            // we won't trample on them any more.
-            mProcessesReady = true;
-        }
-        
-        Slog.i(TAG, "System now ready");
-        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_AMS_READY,
-            SystemClock.uptimeMillis());
-
-        synchronized(this) {
-            // Make sure we have no pre-ready processes sitting around.
-            
-            if (mFactoryTest == SystemServer.FACTORY_TEST_LOW_LEVEL) {
-                ResolveInfo ri = mContext.getPackageManager()
-                        .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST),
-                                STOCK_PM_FLAGS);
-                CharSequence errorMsg = null;
-                if (ri != null) {
-                    ActivityInfo ai = ri.activityInfo;
-                    ApplicationInfo app = ai.applicationInfo;
-                    if ((app.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
-                        mTopAction = Intent.ACTION_FACTORY_TEST;
-                        mTopData = null;
-                        mTopComponent = new ComponentName(app.packageName,
-                                ai.name);
-                    } else {
-                        errorMsg = mContext.getResources().getText(
-                                com.android.internal.R.string.factorytest_not_system);
-                    }
-                } else {
-                    errorMsg = mContext.getResources().getText(
-                            com.android.internal.R.string.factorytest_no_action);
-                }
-                if (errorMsg != null) {
-                    mTopAction = null;
-                    mTopData = null;
-                    mTopComponent = null;
-                    Message msg = Message.obtain();
-                    msg.what = SHOW_FACTORY_ERROR_MSG;
-                    msg.getData().putCharSequence("msg", errorMsg);
-                    mHandler.sendMessage(msg);
-                }
-            }
-        }
-
-        retrieveSettings();
-
-        synchronized (this) {
-            readGrantedUriPermissionsLocked();
-        }
-
-        if (goingCallback != null) goingCallback.run();
-        
-        synchronized (this) {
-            if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
-                try {
-                    List apps = AppGlobals.getPackageManager().
-                        getPersistentApplications(STOCK_PM_FLAGS);
-                    if (apps != null) {
-                        int N = apps.size();
-                        int i;
-                        for (i=0; i<N; i++) {
-                            ApplicationInfo info
-                                = (ApplicationInfo)apps.get(i);
-                            if (info != null &&
-                                    !info.packageName.equals("android")) {
-                                addAppLocked(info, false);
-                            }
-                        }
-                    }
-                } catch (RemoteException ex) {
-                    // pm is in same process, this will never happen.
-                }
-            }
-
-            // Start up initial activity.
-            mBooting = true;
-            
-            try {
-                if (AppGlobals.getPackageManager().hasSystemUidErrors()) {
-                    Message msg = Message.obtain();
-                    msg.what = SHOW_UID_ERROR_MSG;
-                    mHandler.sendMessage(msg);
-                }
-            } catch (RemoteException e) {
-            }
-
-            long ident = Binder.clearCallingIdentity();
-            try {
-                Intent intent = new Intent(Intent.ACTION_USER_STARTED);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                        | Intent.FLAG_RECEIVER_FOREGROUND);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId);
-                broadcastIntentLocked(null, null, intent,
-                        null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                        false, false, MY_PID, Process.SYSTEM_UID, mCurrentUserId);
-                intent = new Intent(Intent.ACTION_USER_STARTING);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId);
-                broadcastIntentLocked(null, null, intent,
-                        null, new IIntentReceiver.Stub() {
-                            @Override
-                            public void performReceive(Intent intent, int resultCode, String data,
-                                    Bundle extras, boolean ordered, boolean sticky, int sendingUser)
-                                    throws RemoteException {
-                            }
-                        }, 0, null, null,
-                        android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
-                        true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-            mStackSupervisor.resumeTopActivitiesLocked();
-            sendUserSwitchBroadcastsLocked(-1, mCurrentUserId);
-        }
-    }
-
-    private boolean makeAppCrashingLocked(ProcessRecord app,
-            String shortMsg, String longMsg, String stackTrace) {
-        app.crashing = true;
-        app.crashingReport = generateProcessError(app,
-                ActivityManager.ProcessErrorStateInfo.CRASHED, null, shortMsg, longMsg, stackTrace);
-        startAppProblemLocked(app);
-        app.stopFreezingAllLocked();
-        return handleAppCrashLocked(app, shortMsg, longMsg, stackTrace);
-    }
-
-    private void makeAppNotRespondingLocked(ProcessRecord app,
-            String activity, String shortMsg, String longMsg) {
-        app.notResponding = true;
-        app.notRespondingReport = generateProcessError(app,
-                ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING,
-                activity, shortMsg, longMsg, null);
-        startAppProblemLocked(app);
-        app.stopFreezingAllLocked();
-    }
-    
-    /**
-     * Generate a process error record, suitable for attachment to a ProcessRecord.
-     * 
-     * @param app The ProcessRecord in which the error occurred.
-     * @param condition Crashing, Application Not Responding, etc.  Values are defined in 
-     *                      ActivityManager.AppErrorStateInfo
-     * @param activity The activity associated with the crash, if known.
-     * @param shortMsg Short message describing the crash.
-     * @param longMsg Long message describing the crash.
-     * @param stackTrace Full crash stack trace, may be null.
-     *
-     * @return Returns a fully-formed AppErrorStateInfo record.
-     */
-    private ActivityManager.ProcessErrorStateInfo generateProcessError(ProcessRecord app, 
-            int condition, String activity, String shortMsg, String longMsg, String stackTrace) {
-        ActivityManager.ProcessErrorStateInfo report = new ActivityManager.ProcessErrorStateInfo();
-
-        report.condition = condition;
-        report.processName = app.processName;
-        report.pid = app.pid;
-        report.uid = app.info.uid;
-        report.tag = activity;
-        report.shortMsg = shortMsg;
-        report.longMsg = longMsg;
-        report.stackTrace = stackTrace;
-
-        return report;
-    }
-
-    void killAppAtUsersRequest(ProcessRecord app, Dialog fromDialog) {
-        synchronized (this) {
-            app.crashing = false;
-            app.crashingReport = null;
-            app.notResponding = false;
-            app.notRespondingReport = null;
-            if (app.anrDialog == fromDialog) {
-                app.anrDialog = null;
-            }
-            if (app.waitDialog == fromDialog) {
-                app.waitDialog = null;
-            }
-            if (app.pid > 0 && app.pid != MY_PID) {
-                handleAppCrashLocked(app, null, null, null);
-                killUnneededProcessLocked(app, "user request after error");
-            }
-        }
-    }
-
-    private boolean handleAppCrashLocked(ProcessRecord app, String shortMsg, String longMsg,
-            String stackTrace) {
-        if (mHeadless) {
-            Log.e(TAG, "handleAppCrashLocked: " + app.processName);
-            return false;
-        }
-        long now = SystemClock.uptimeMillis();
-
-        Long crashTime;
-        if (!app.isolated) {
-            crashTime = mProcessCrashTimes.get(app.info.processName, app.uid);
-        } else {
-            crashTime = null;
-        }
-        if (crashTime != null && now < crashTime+ProcessList.MIN_CRASH_INTERVAL) {
-            // This process loses!
-            Slog.w(TAG, "Process " + app.info.processName
-                    + " has crashed too many times: killing!");
-            EventLog.writeEvent(EventLogTags.AM_PROCESS_CRASHED_TOO_MUCH,
-                    app.userId, app.info.processName, app.uid);
-            mStackSupervisor.handleAppCrashLocked(app);
-            if (!app.persistent) {
-                // We don't want to start this process again until the user
-                // explicitly does so...  but for persistent process, we really
-                // need to keep it running.  If a persistent process is actually
-                // repeatedly crashing, then badness for everyone.
-                EventLog.writeEvent(EventLogTags.AM_PROC_BAD, app.userId, app.uid,
-                        app.info.processName);
-                if (!app.isolated) {
-                    // XXX We don't have a way to mark isolated processes
-                    // as bad, since they don't have a peristent identity.
-                    mBadProcesses.put(app.info.processName, app.uid,
-                            new BadProcessInfo(now, shortMsg, longMsg, stackTrace));
-                    mProcessCrashTimes.remove(app.info.processName, app.uid);
-                }
-                app.bad = true;
-                app.removed = true;
-                // Don't let services in this process be restarted and potentially
-                // annoy the user repeatedly.  Unless it is persistent, since those
-                // processes run critical code.
-                removeProcessLocked(app, false, false, "crash");
-                mStackSupervisor.resumeTopActivitiesLocked();
-                return false;
-            }
-            mStackSupervisor.resumeTopActivitiesLocked();
-        } else {
-            mStackSupervisor.finishTopRunningActivityLocked(app);
-        }
-
-        // Bump up the crash count of any services currently running in the proc.
-        for (int i=app.services.size()-1; i>=0; i--) {
-            // Any services running in the application need to be placed
-            // back in the pending list.
-            ServiceRecord sr = app.services.valueAt(i);
-            sr.crashCount++;
-        }
-
-        // If the crashing process is what we consider to be the "home process" and it has been
-        // replaced by a third-party app, clear the package preferred activities from packages
-        // with a home activity running in the process to prevent a repeatedly crashing app
-        // from blocking the user to manually clear the list.
-        final ArrayList<ActivityRecord> activities = app.activities;
-        if (app == mHomeProcess && activities.size() > 0
-                    && (mHomeProcess.info.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.isHomeActivity()) {
-                    Log.i(TAG, "Clearing package preferred activities from " + r.packageName);
-                    try {
-                        ActivityThread.getPackageManager()
-                                .clearPackagePreferredActivities(r.packageName);
-                    } catch (RemoteException c) {
-                        // pm is in same process, this will never happen.
-                    }
-                }
-            }
-        }
-
-        if (!app.isolated) {
-            // XXX Can't keep track of crash times for isolated processes,
-            // because they don't have a perisistent identity.
-            mProcessCrashTimes.put(app.info.processName, app.uid, now);
-        }
-
-        return true;
-    }
-
-    void startAppProblemLocked(ProcessRecord app) {
-        if (app.userId == mCurrentUserId) {
-            app.errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver(
-                    mContext, app.info.packageName, app.info.flags);
-        } else {
-            // If this app is not running under the current user, then we
-            // can't give it a report button because that would require
-            // launching the report UI under a different user.
-            app.errorReportReceiver = null;
-        }
-        skipCurrentReceiverLocked(app);
-    }
-
-    void skipCurrentReceiverLocked(ProcessRecord app) {
-        for (BroadcastQueue queue : mBroadcastQueues) {
-            queue.skipCurrentReceiverLocked(app);
-        }
-    }
-
-    /**
-     * Used by {@link com.android.internal.os.RuntimeInit} to report when an application crashes.
-     * The application process will exit immediately after this call returns.
-     * @param app object of the crashing app, null for the system server
-     * @param crashInfo describing the exception
-     */
-    public void handleApplicationCrash(IBinder app, ApplicationErrorReport.CrashInfo crashInfo) {
-        ProcessRecord r = findAppProcess(app, "Crash");
-        final String processName = app == null ? "system_server"
-                : (r == null ? "unknown" : r.processName);
-
-        handleApplicationCrashInner("crash", r, processName, crashInfo);
-    }
-
-    /* Native crash reporting uses this inner version because it needs to be somewhat
-     * decoupled from the AM-managed cleanup lifecycle
-     */
-    void handleApplicationCrashInner(String eventType, ProcessRecord r, String processName,
-            ApplicationErrorReport.CrashInfo crashInfo) {
-        EventLog.writeEvent(EventLogTags.AM_CRASH, Binder.getCallingPid(),
-                UserHandle.getUserId(Binder.getCallingUid()), processName,
-                r == null ? -1 : r.info.flags,
-                crashInfo.exceptionClassName,
-                crashInfo.exceptionMessage,
-                crashInfo.throwFileName,
-                crashInfo.throwLineNumber);
-
-        addErrorToDropBox(eventType, r, processName, null, null, null, null, null, crashInfo);
-
-        crashApplication(r, crashInfo);
-    }
-
-    public void handleApplicationStrictModeViolation(
-            IBinder app,
-            int violationMask,
-            StrictMode.ViolationInfo info) {
-        ProcessRecord r = findAppProcess(app, "StrictMode");
-        if (r == null) {
-            return;
-        }
-
-        if ((violationMask & StrictMode.PENALTY_DROPBOX) != 0) {
-            Integer stackFingerprint = info.hashCode();
-            boolean logIt = true;
-            synchronized (mAlreadyLoggedViolatedStacks) {
-                if (mAlreadyLoggedViolatedStacks.contains(stackFingerprint)) {
-                    logIt = false;
-                    // TODO: sub-sample into EventLog for these, with
-                    // the info.durationMillis?  Then we'd get
-                    // the relative pain numbers, without logging all
-                    // the stack traces repeatedly.  We'd want to do
-                    // likewise in the client code, which also does
-                    // dup suppression, before the Binder call.
-                } else {
-                    if (mAlreadyLoggedViolatedStacks.size() >= MAX_DUP_SUPPRESSED_STACKS) {
-                        mAlreadyLoggedViolatedStacks.clear();
-                    }
-                    mAlreadyLoggedViolatedStacks.add(stackFingerprint);
-                }
-            }
-            if (logIt) {
-                logStrictModeViolationToDropBox(r, info);
-            }
-        }
-
-        if ((violationMask & StrictMode.PENALTY_DIALOG) != 0) {
-            AppErrorResult result = new AppErrorResult();
-            synchronized (this) {
-                final long origId = Binder.clearCallingIdentity();
-
-                Message msg = Message.obtain();
-                msg.what = SHOW_STRICT_MODE_VIOLATION_MSG;
-                HashMap<String, Object> data = new HashMap<String, Object>();
-                data.put("result", result);
-                data.put("app", r);
-                data.put("violationMask", violationMask);
-                data.put("info", info);
-                msg.obj = data;
-                mHandler.sendMessage(msg);
-
-                Binder.restoreCallingIdentity(origId);
-            }
-            int res = result.get();
-            Slog.w(TAG, "handleApplicationStrictModeViolation; res=" + res);
-        }
-    }
-
-    // Depending on the policy in effect, there could be a bunch of
-    // these in quick succession so we try to batch these together to
-    // minimize disk writes, number of dropbox entries, and maximize
-    // compression, by having more fewer, larger records.
-    private void logStrictModeViolationToDropBox(
-            ProcessRecord process,
-            StrictMode.ViolationInfo info) {
-        if (info == null) {
-            return;
-        }
-        final boolean isSystemApp = process == null ||
-                (process.info.flags & (ApplicationInfo.FLAG_SYSTEM |
-                                       ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0;
-        final String processName = process == null ? "unknown" : process.processName;
-        final String dropboxTag = isSystemApp ? "system_app_strictmode" : "data_app_strictmode";
-        final DropBoxManager dbox = (DropBoxManager)
-                mContext.getSystemService(Context.DROPBOX_SERVICE);
-
-        // Exit early if the dropbox isn't configured to accept this report type.
-        if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return;
-
-        boolean bufferWasEmpty;
-        boolean needsFlush;
-        final StringBuilder sb = isSystemApp ? mStrictModeBuffer : new StringBuilder(1024);
-        synchronized (sb) {
-            bufferWasEmpty = sb.length() == 0;
-            appendDropBoxProcessHeaders(process, processName, sb);
-            sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
-            sb.append("System-App: ").append(isSystemApp).append("\n");
-            sb.append("Uptime-Millis: ").append(info.violationUptimeMillis).append("\n");
-            if (info.violationNumThisLoop != 0) {
-                sb.append("Loop-Violation-Number: ").append(info.violationNumThisLoop).append("\n");
-            }
-            if (info.numAnimationsRunning != 0) {
-                sb.append("Animations-Running: ").append(info.numAnimationsRunning).append("\n");
-            }
-            if (info.broadcastIntentAction != null) {
-                sb.append("Broadcast-Intent-Action: ").append(info.broadcastIntentAction).append("\n");
-            }
-            if (info.durationMillis != -1) {
-                sb.append("Duration-Millis: ").append(info.durationMillis).append("\n");
-            }
-            if (info.numInstances != -1) {
-                sb.append("Instance-Count: ").append(info.numInstances).append("\n");
-            }
-            if (info.tags != null) {
-                for (String tag : info.tags) {
-                    sb.append("Span-Tag: ").append(tag).append("\n");
-                }
-            }
-            sb.append("\n");
-            if (info.crashInfo != null && info.crashInfo.stackTrace != null) {
-                sb.append(info.crashInfo.stackTrace);
-            }
-            sb.append("\n");
-
-            // Only buffer up to ~64k.  Various logging bits truncate
-            // things at 128k.
-            needsFlush = (sb.length() > 64 * 1024);
-        }
-
-        // Flush immediately if the buffer's grown too large, or this
-        // is a non-system app.  Non-system apps are isolated with a
-        // different tag & policy and not batched.
-        //
-        // Batching is useful during internal testing with
-        // StrictMode settings turned up high.  Without batching,
-        // thousands of separate files could be created on boot.
-        if (!isSystemApp || needsFlush) {
-            new Thread("Error dump: " + dropboxTag) {
-                @Override
-                public void run() {
-                    String report;
-                    synchronized (sb) {
-                        report = sb.toString();
-                        sb.delete(0, sb.length());
-                        sb.trimToSize();
-                    }
-                    if (report.length() != 0) {
-                        dbox.addText(dropboxTag, report);
-                    }
-                }
-            }.start();
-            return;
-        }
-
-        // System app batching:
-        if (!bufferWasEmpty) {
-            // An existing dropbox-writing thread is outstanding, so
-            // we don't need to start it up.  The existing thread will
-            // catch the buffer appends we just did.
-            return;
-        }
-
-        // Worker thread to both batch writes and to avoid blocking the caller on I/O.
-        // (After this point, we shouldn't access AMS internal data structures.)
-        new Thread("Error dump: " + dropboxTag) {
-            @Override
-            public void run() {
-                // 5 second sleep to let stacks arrive and be batched together
-                try {
-                    Thread.sleep(5000);  // 5 seconds
-                } catch (InterruptedException e) {}
-
-                String errorReport;
-                synchronized (mStrictModeBuffer) {
-                    errorReport = mStrictModeBuffer.toString();
-                    if (errorReport.length() == 0) {
-                        return;
-                    }
-                    mStrictModeBuffer.delete(0, mStrictModeBuffer.length());
-                    mStrictModeBuffer.trimToSize();
-                }
-                dbox.addText(dropboxTag, errorReport);
-            }
-        }.start();
-    }
-
-    /**
-     * Used by {@link Log} via {@link com.android.internal.os.RuntimeInit} to report serious errors.
-     * @param app object of the crashing app, null for the system server
-     * @param tag reported by the caller
-     * @param crashInfo describing the context of the error
-     * @return true if the process should exit immediately (WTF is fatal)
-     */
-    public boolean handleApplicationWtf(IBinder app, String tag,
-            ApplicationErrorReport.CrashInfo crashInfo) {
-        ProcessRecord r = findAppProcess(app, "WTF");
-        final String processName = app == null ? "system_server"
-                : (r == null ? "unknown" : r.processName);
-
-        EventLog.writeEvent(EventLogTags.AM_WTF,
-                UserHandle.getUserId(Binder.getCallingUid()), Binder.getCallingPid(),
-                processName,
-                r == null ? -1 : r.info.flags,
-                tag, crashInfo.exceptionMessage);
-
-        addErrorToDropBox("wtf", r, processName, null, null, tag, null, null, crashInfo);
-
-        if (r != null && r.pid != Process.myPid() &&
-                Settings.Global.getInt(mContext.getContentResolver(),
-                        Settings.Global.WTF_IS_FATAL, 0) != 0) {
-            crashApplication(r, crashInfo);
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * @param app object of some object (as stored in {@link com.android.internal.os.RuntimeInit})
-     * @return the corresponding {@link ProcessRecord} object, or null if none could be found
-     */
-    private ProcessRecord findAppProcess(IBinder app, String reason) {
-        if (app == null) {
-            return null;
-        }
-
-        synchronized (this) {
-            final int NP = mProcessNames.getMap().size();
-            for (int ip=0; ip<NP; ip++) {
-                SparseArray<ProcessRecord> apps = mProcessNames.getMap().valueAt(ip);
-                final int NA = apps.size();
-                for (int ia=0; ia<NA; ia++) {
-                    ProcessRecord p = apps.valueAt(ia);
-                    if (p.thread != null && p.thread.asBinder() == app) {
-                        return p;
-                    }
-                }
-            }
-
-            Slog.w(TAG, "Can't find mystery application for " + reason
-                    + " from pid=" + Binder.getCallingPid()
-                    + " uid=" + Binder.getCallingUid() + ": " + app);
-            return null;
-        }
-    }
-
-    /**
-     * Utility function for addErrorToDropBox and handleStrictModeViolation's logging
-     * to append various headers to the dropbox log text.
-     */
-    private void appendDropBoxProcessHeaders(ProcessRecord process, String processName,
-            StringBuilder sb) {
-        // Watchdog thread ends up invoking this function (with
-        // a null ProcessRecord) to add the stack file to dropbox.
-        // Do not acquire a lock on this (am) in such cases, as it
-        // could cause a potential deadlock, if and when watchdog
-        // is invoked due to unavailability of lock on am and it
-        // would prevent watchdog from killing system_server.
-        if (process == null) {
-            sb.append("Process: ").append(processName).append("\n");
-            return;
-        }
-        // Note: ProcessRecord 'process' is guarded by the service
-        // instance.  (notably process.pkgList, which could otherwise change
-        // concurrently during execution of this method)
-        synchronized (this) {
-            sb.append("Process: ").append(processName).append("\n");
-            int flags = process.info.flags;
-            IPackageManager pm = AppGlobals.getPackageManager();
-            sb.append("Flags: 0x").append(Integer.toString(flags, 16)).append("\n");
-            for (int ip=0; ip<process.pkgList.size(); ip++) {
-                String pkg = process.pkgList.keyAt(ip);
-                sb.append("Package: ").append(pkg);
-                try {
-                    PackageInfo pi = pm.getPackageInfo(pkg, 0, UserHandle.getCallingUserId());
-                    if (pi != null) {
-                        sb.append(" v").append(pi.versionCode);
-                        if (pi.versionName != null) {
-                            sb.append(" (").append(pi.versionName).append(")");
-                        }
-                    }
-                } catch (RemoteException e) {
-                    Slog.e(TAG, "Error getting package info: " + pkg, e);
-                }
-                sb.append("\n");
-            }
-        }
-    }
-
-    private static String processClass(ProcessRecord process) {
-        if (process == null || process.pid == MY_PID) {
-            return "system_server";
-        } else if ((process.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-            return "system_app";
-        } else {
-            return "data_app";
-        }
-    }
-
-    /**
-     * Write a description of an error (crash, WTF, ANR) to the drop box.
-     * @param eventType to include in the drop box tag ("crash", "wtf", etc.)
-     * @param process which caused the error, null means the system server
-     * @param activity which triggered the error, null if unknown
-     * @param parent activity related to the error, null if unknown
-     * @param subject line related to the error, null if absent
-     * @param report in long form describing the error, null if absent
-     * @param logFile to include in the report, null if none
-     * @param crashInfo giving an application stack trace, null if absent
-     */
-    public void addErrorToDropBox(String eventType,
-            ProcessRecord process, String processName, ActivityRecord activity,
-            ActivityRecord parent, String subject,
-            final String report, final File logFile,
-            final ApplicationErrorReport.CrashInfo crashInfo) {
-        // NOTE -- this must never acquire the ActivityManagerService lock,
-        // otherwise the watchdog may be prevented from resetting the system.
-
-        final String dropboxTag = processClass(process) + "_" + eventType;
-        final DropBoxManager dbox = (DropBoxManager)
-                mContext.getSystemService(Context.DROPBOX_SERVICE);
-
-        // Exit early if the dropbox isn't configured to accept this report type.
-        if (dbox == null || !dbox.isTagEnabled(dropboxTag)) return;
-
-        final StringBuilder sb = new StringBuilder(1024);
-        appendDropBoxProcessHeaders(process, processName, sb);
-        if (activity != null) {
-            sb.append("Activity: ").append(activity.shortComponentName).append("\n");
-        }
-        if (parent != null && parent.app != null && parent.app.pid != process.pid) {
-            sb.append("Parent-Process: ").append(parent.app.processName).append("\n");
-        }
-        if (parent != null && parent != activity) {
-            sb.append("Parent-Activity: ").append(parent.shortComponentName).append("\n");
-        }
-        if (subject != null) {
-            sb.append("Subject: ").append(subject).append("\n");
-        }
-        sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
-        if (Debug.isDebuggerConnected()) {
-            sb.append("Debugger: Connected\n");
-        }
-        sb.append("\n");
-
-        // Do the rest in a worker thread to avoid blocking the caller on I/O
-        // (After this point, we shouldn't access AMS internal data structures.)
-        Thread worker = new Thread("Error dump: " + dropboxTag) {
-            @Override
-            public void run() {
-                if (report != null) {
-                    sb.append(report);
-                }
-                if (logFile != null) {
-                    try {
-                        sb.append(FileUtils.readTextFile(logFile, DROPBOX_MAX_SIZE,
-                                    "\n\n[[TRUNCATED]]"));
-                    } catch (IOException e) {
-                        Slog.e(TAG, "Error reading " + logFile, e);
-                    }
-                }
-                if (crashInfo != null && crashInfo.stackTrace != null) {
-                    sb.append(crashInfo.stackTrace);
-                }
-
-                String setting = Settings.Global.ERROR_LOGCAT_PREFIX + dropboxTag;
-                int lines = Settings.Global.getInt(mContext.getContentResolver(), setting, 0);
-                if (lines > 0) {
-                    sb.append("\n");
-
-                    // Merge several logcat streams, and take the last N lines
-                    InputStreamReader input = null;
-                    try {
-                        java.lang.Process logcat = new ProcessBuilder("/system/bin/logcat",
-                                "-v", "time", "-b", "events", "-b", "system", "-b", "main",
-                                "-t", String.valueOf(lines)).redirectErrorStream(true).start();
-
-                        try { logcat.getOutputStream().close(); } catch (IOException e) {}
-                        try { logcat.getErrorStream().close(); } catch (IOException e) {}
-                        input = new InputStreamReader(logcat.getInputStream());
-
-                        int num;
-                        char[] buf = new char[8192];
-                        while ((num = input.read(buf)) > 0) sb.append(buf, 0, num);
-                    } catch (IOException e) {
-                        Slog.e(TAG, "Error running logcat", e);
-                    } finally {
-                        if (input != null) try { input.close(); } catch (IOException e) {}
-                    }
-                }
-
-                dbox.addText(dropboxTag, sb.toString());
-            }
-        };
-
-        if (process == null) {
-            // If process is null, we are being called from some internal code
-            // and may be about to die -- run this synchronously.
-            worker.run();
-        } else {
-            worker.start();
-        }
-    }
-
-    /**
-     * Bring up the "unexpected error" dialog box for a crashing app.
-     * Deal with edge cases (intercepts from instrumented applications,
-     * ActivityController, error intent receivers, that sort of thing).
-     * @param r the application crashing
-     * @param crashInfo describing the failure
-     */
-    private void crashApplication(ProcessRecord r, ApplicationErrorReport.CrashInfo crashInfo) {
-        long timeMillis = System.currentTimeMillis();
-        String shortMsg = crashInfo.exceptionClassName;
-        String longMsg = crashInfo.exceptionMessage;
-        String stackTrace = crashInfo.stackTrace;
-        if (shortMsg != null && longMsg != null) {
-            longMsg = shortMsg + ": " + longMsg;
-        } else if (shortMsg != null) {
-            longMsg = shortMsg;
-        }
-
-        AppErrorResult result = new AppErrorResult();
-        synchronized (this) {
-            if (mController != null) {
-                try {
-                    String name = r != null ? r.processName : null;
-                    int pid = r != null ? r.pid : Binder.getCallingPid();
-                    if (!mController.appCrashed(name, pid,
-                            shortMsg, longMsg, timeMillis, crashInfo.stackTrace)) {
-                        Slog.w(TAG, "Force-killing crashed app " + name
-                                + " at watcher's request");
-                        Process.killProcess(pid);
-                        return;
-                    }
-                } catch (RemoteException e) {
-                    mController = null;
-                    Watchdog.getInstance().setActivityController(null);
-                }
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-
-            // If this process is running instrumentation, finish it.
-            if (r != null && r.instrumentationClass != null) {
-                Slog.w(TAG, "Error in app " + r.processName
-                      + " running instrumentation " + r.instrumentationClass + ":");
-                if (shortMsg != null) Slog.w(TAG, "  " + shortMsg);
-                if (longMsg != null) Slog.w(TAG, "  " + longMsg);
-                Bundle info = new Bundle();
-                info.putString("shortMsg", shortMsg);
-                info.putString("longMsg", longMsg);
-                finishInstrumentationLocked(r, Activity.RESULT_CANCELED, info);
-                Binder.restoreCallingIdentity(origId);
-                return;
-            }
-
-            // If we can't identify the process or it's already exceeded its crash quota,
-            // quit right away without showing a crash dialog.
-            if (r == null || !makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace)) {
-                Binder.restoreCallingIdentity(origId);
-                return;
-            }
-
-            Message msg = Message.obtain();
-            msg.what = SHOW_ERROR_MSG;
-            HashMap data = new HashMap();
-            data.put("result", result);
-            data.put("app", r);
-            msg.obj = data;
-            mHandler.sendMessage(msg);
-
-            Binder.restoreCallingIdentity(origId);
-        }
-
-        int res = result.get();
-
-        Intent appErrorIntent = null;
-        synchronized (this) {
-            if (r != null && !r.isolated) {
-                // XXX Can't keep track of crash time for isolated processes,
-                // since they don't have a persistent identity.
-                mProcessCrashTimes.put(r.info.processName, r.uid,
-                        SystemClock.uptimeMillis());
-            }
-            if (res == AppErrorDialog.FORCE_QUIT_AND_REPORT) {
-                appErrorIntent = createAppErrorIntentLocked(r, timeMillis, crashInfo);
-            }
-        }
-
-        if (appErrorIntent != null) {
-            try {
-                mContext.startActivityAsUser(appErrorIntent, new UserHandle(r.userId));
-            } catch (ActivityNotFoundException e) {
-                Slog.w(TAG, "bug report receiver dissappeared", e);
-            }
-        }
-    }
-
-    Intent createAppErrorIntentLocked(ProcessRecord r,
-            long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
-        ApplicationErrorReport report = createAppErrorReportLocked(r, timeMillis, crashInfo);
-        if (report == null) {
-            return null;
-        }
-        Intent result = new Intent(Intent.ACTION_APP_ERROR);
-        result.setComponent(r.errorReportReceiver);
-        result.putExtra(Intent.EXTRA_BUG_REPORT, report);
-        result.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        return result;
-    }
-
-    private ApplicationErrorReport createAppErrorReportLocked(ProcessRecord r,
-            long timeMillis, ApplicationErrorReport.CrashInfo crashInfo) {
-        if (r.errorReportReceiver == null) {
-            return null;
-        }
-
-        if (!r.crashing && !r.notResponding && !r.forceCrashReport) {
-            return null;
-        }
-
-        ApplicationErrorReport report = new ApplicationErrorReport();
-        report.packageName = r.info.packageName;
-        report.installerPackageName = r.errorReportReceiver.getPackageName();
-        report.processName = r.processName;
-        report.time = timeMillis;
-        report.systemApp = (r.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-
-        if (r.crashing || r.forceCrashReport) {
-            report.type = ApplicationErrorReport.TYPE_CRASH;
-            report.crashInfo = crashInfo;
-        } else if (r.notResponding) {
-            report.type = ApplicationErrorReport.TYPE_ANR;
-            report.anrInfo = new ApplicationErrorReport.AnrInfo();
-
-            report.anrInfo.activity = r.notRespondingReport.tag;
-            report.anrInfo.cause = r.notRespondingReport.shortMsg;
-            report.anrInfo.info = r.notRespondingReport.longMsg;
-        }
-
-        return report;
-    }
-
-    public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState() {
-        enforceNotIsolatedCaller("getProcessesInErrorState");
-        // assume our apps are happy - lazy create the list
-        List<ActivityManager.ProcessErrorStateInfo> errList = null;
-
-        final boolean allUsers = ActivityManager.checkUidPermission(
-                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                Binder.getCallingUid()) == PackageManager.PERMISSION_GRANTED;
-        int userId = UserHandle.getUserId(Binder.getCallingUid());
-
-        synchronized (this) {
-
-            // iterate across all processes
-            for (int i=mLruProcesses.size()-1; i>=0; i--) {
-                ProcessRecord app = mLruProcesses.get(i);
-                if (!allUsers && app.userId != userId) {
-                    continue;
-                }
-                if ((app.thread != null) && (app.crashing || app.notResponding)) {
-                    // This one's in trouble, so we'll generate a report for it
-                    // crashes are higher priority (in case there's a crash *and* an anr)
-                    ActivityManager.ProcessErrorStateInfo report = null;
-                    if (app.crashing) {
-                        report = app.crashingReport;
-                    } else if (app.notResponding) {
-                        report = app.notRespondingReport;
-                    }
-                    
-                    if (report != null) {
-                        if (errList == null) {
-                            errList = new ArrayList<ActivityManager.ProcessErrorStateInfo>(1);
-                        }
-                        errList.add(report);
-                    } else {
-                        Slog.w(TAG, "Missing app error report, app = " + app.processName + 
-                                " crashing = " + app.crashing +
-                                " notResponding = " + app.notResponding);
-                    }
-                }
-            }
-        }
-
-        return errList;
-    }
-
-    static int oomAdjToImportance(int adj, ActivityManager.RunningAppProcessInfo currApp) {
-        if (adj >= ProcessList.CACHED_APP_MIN_ADJ) {
-            if (currApp != null) {
-                currApp.lru = adj - ProcessList.CACHED_APP_MIN_ADJ + 1;
-            }
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
-        } else if (adj >= ProcessList.SERVICE_B_ADJ) {
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
-        } else if (adj >= ProcessList.HOME_APP_ADJ) {
-            if (currApp != null) {
-                currApp.lru = 0;
-            }
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
-        } else if (adj >= ProcessList.SERVICE_ADJ) {
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
-        } else if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
-        } else if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
-        } else if (adj >= ProcessList.VISIBLE_APP_ADJ) {
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
-        } else {
-            return ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
-        }
-    }
-
-    private void fillInProcMemInfo(ProcessRecord app,
-            ActivityManager.RunningAppProcessInfo outInfo) {
-        outInfo.pid = app.pid;
-        outInfo.uid = app.info.uid;
-        if (mHeavyWeightProcess == app) {
-            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_CANT_SAVE_STATE;
-        }
-        if (app.persistent) {
-            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_PERSISTENT;
-        }
-        if (app.activities.size() > 0) {
-            outInfo.flags |= ActivityManager.RunningAppProcessInfo.FLAG_HAS_ACTIVITIES;
-        }
-        outInfo.lastTrimLevel = app.trimMemoryLevel;
-        int adj = app.curAdj;
-        outInfo.importance = oomAdjToImportance(adj, outInfo);
-        outInfo.importanceReasonCode = app.adjTypeCode;
-    }
-
-    public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses() {
-        enforceNotIsolatedCaller("getRunningAppProcesses");
-        // Lazy instantiation of list
-        List<ActivityManager.RunningAppProcessInfo> runList = null;
-        final boolean allUsers = ActivityManager.checkUidPermission(
-                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                Binder.getCallingUid()) == PackageManager.PERMISSION_GRANTED;
-        int userId = UserHandle.getUserId(Binder.getCallingUid());
-        synchronized (this) {
-            // Iterate across all processes
-            for (int i=mLruProcesses.size()-1; i>=0; i--) {
-                ProcessRecord app = mLruProcesses.get(i);
-                if (!allUsers && app.userId != userId) {
-                    continue;
-                }
-                if ((app.thread != null) && (!app.crashing && !app.notResponding)) {
-                    // Generate process state info for running application
-                    ActivityManager.RunningAppProcessInfo currApp = 
-                        new ActivityManager.RunningAppProcessInfo(app.processName,
-                                app.pid, app.getPackageList());
-                    fillInProcMemInfo(app, currApp);
-                    if (app.adjSource instanceof ProcessRecord) {
-                        currApp.importanceReasonPid = ((ProcessRecord)app.adjSource).pid;
-                        currApp.importanceReasonImportance = oomAdjToImportance(
-                                app.adjSourceOom, null);
-                    } else if (app.adjSource instanceof ActivityRecord) {
-                        ActivityRecord r = (ActivityRecord)app.adjSource;
-                        if (r.app != null) currApp.importanceReasonPid = r.app.pid;
-                    }
-                    if (app.adjTarget instanceof ComponentName) {
-                        currApp.importanceReasonComponent = (ComponentName)app.adjTarget;
-                    }
-                    //Slog.v(TAG, "Proc " + app.processName + ": imp=" + currApp.importance
-                    //        + " lru=" + currApp.lru);
-                    if (runList == null) {
-                        runList = new ArrayList<ActivityManager.RunningAppProcessInfo>();
-                    }
-                    runList.add(currApp);
-                }
-            }
-        }
-        return runList;
-    }
-
-    public List<ApplicationInfo> getRunningExternalApplications() {
-        enforceNotIsolatedCaller("getRunningExternalApplications");
-        List<ActivityManager.RunningAppProcessInfo> runningApps = getRunningAppProcesses();
-        List<ApplicationInfo> retList = new ArrayList<ApplicationInfo>();
-        if (runningApps != null && runningApps.size() > 0) {
-            Set<String> extList = new HashSet<String>();
-            for (ActivityManager.RunningAppProcessInfo app : runningApps) {
-                if (app.pkgList != null) {
-                    for (String pkg : app.pkgList) {
-                        extList.add(pkg);
-                    }
-                }
-            }
-            IPackageManager pm = AppGlobals.getPackageManager();
-            for (String pkg : extList) {
-                try {
-                    ApplicationInfo info = pm.getApplicationInfo(pkg, 0, UserHandle.getCallingUserId());
-                    if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
-                        retList.add(info);
-                    }
-                } catch (RemoteException e) {
-                }
-            }
-        }
-        return retList;
-    }
-
-    @Override
-    public void getMyMemoryState(ActivityManager.RunningAppProcessInfo outInfo) {
-        enforceNotIsolatedCaller("getMyMemoryState");
-        synchronized (this) {
-            ProcessRecord proc;
-            synchronized (mPidsSelfLocked) {
-                proc = mPidsSelfLocked.get(Binder.getCallingPid());
-            }
-            fillInProcMemInfo(proc, outInfo);
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (checkCallingPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump ActivityManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " without permission "
-                    + android.Manifest.permission.DUMP);
-            return;
-        }
-
-        boolean dumpAll = false;
-        boolean dumpClient = false;
-        String dumpPackage = null;
-        
-        int opti = 0;
-        while (opti < args.length) {
-            String opt = args[opti];
-            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
-                break;
-            }
-            opti++;
-            if ("-a".equals(opt)) {
-                dumpAll = true;
-            } else if ("-c".equals(opt)) {
-                dumpClient = true;
-            } else if ("-h".equals(opt)) {
-                pw.println("Activity manager dump options:");
-                pw.println("  [-a] [-c] [-h] [cmd] ...");
-                pw.println("  cmd may be one of:");
-                pw.println("    a[ctivities]: activity stack state");
-                pw.println("    b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state");
-                pw.println("    i[ntents] [PACKAGE_NAME]: pending intent state");
-                pw.println("    p[rocesses] [PACKAGE_NAME]: process state");
-                pw.println("    o[om]: out of memory management");
-                pw.println("    prov[iders] [COMP_SPEC ...]: content provider state");
-                pw.println("    provider [COMP_SPEC]: provider client-side state");
-                pw.println("    s[ervices] [COMP_SPEC ...]: service state");
-                pw.println("    service [COMP_SPEC]: service client-side state");
-                pw.println("    package [PACKAGE_NAME]: all state related to given package");
-                pw.println("    all: dump all activities");
-                pw.println("    top: dump the top activity");
-                pw.println("  cmd may also be a COMP_SPEC to dump activities.");
-                pw.println("  COMP_SPEC may be a component name (com.foo/.myApp),");
-                pw.println("    a partial substring in a component name, a");
-                pw.println("    hex object identifier.");
-                pw.println("  -a: include all available server state.");
-                pw.println("  -c: include client state.");
-                return;
-            } else {
-                pw.println("Unknown argument: " + opt + "; use -h for help");
-            }
-        }
-
-        long origId = Binder.clearCallingIdentity();
-        boolean more = false;
-        // Is the caller requesting to dump a particular piece of data?
-        if (opti < args.length) {
-            String cmd = args[opti];
-            opti++;
-            if ("activities".equals(cmd) || "a".equals(cmd)) {
-                synchronized (this) {
-                    dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, null);
-                }
-            } else if ("broadcasts".equals(cmd) || "b".equals(cmd)) {
-                String[] newArgs;
-                String name;
-                if (opti >= args.length) {
-                    name = null;
-                    newArgs = EMPTY_STRING_ARRAY;
-                } else {
-                    name = args[opti];
-                    opti++;
-                    newArgs = new String[args.length - opti];
-                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
-                            args.length - opti);
-                }
-                synchronized (this) {
-                    dumpBroadcastsLocked(fd, pw, args, opti, true, name);
-                }
-            } else if ("intents".equals(cmd) || "i".equals(cmd)) {
-                String[] newArgs;
-                String name;
-                if (opti >= args.length) {
-                    name = null;
-                    newArgs = EMPTY_STRING_ARRAY;
-                } else {
-                    name = args[opti];
-                    opti++;
-                    newArgs = new String[args.length - opti];
-                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
-                            args.length - opti);
-                }
-                synchronized (this) {
-                    dumpPendingIntentsLocked(fd, pw, args, opti, true, name);
-                }
-            } else if ("processes".equals(cmd) || "p".equals(cmd)) {
-                String[] newArgs;
-                String name;
-                if (opti >= args.length) {
-                    name = null;
-                    newArgs = EMPTY_STRING_ARRAY;
-                } else {
-                    name = args[opti];
-                    opti++;
-                    newArgs = new String[args.length - opti];
-                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
-                            args.length - opti);
-                }
-                synchronized (this) {
-                    dumpProcessesLocked(fd, pw, args, opti, true, name);
-                }
-            } else if ("oom".equals(cmd) || "o".equals(cmd)) {
-                synchronized (this) {
-                    dumpOomLocked(fd, pw, args, opti, true);
-                }
-            } else if ("provider".equals(cmd)) {
-                String[] newArgs;
-                String name;
-                if (opti >= args.length) {
-                    name = null;
-                    newArgs = EMPTY_STRING_ARRAY;
-                } else {
-                    name = args[opti];
-                    opti++;
-                    newArgs = new String[args.length - opti];
-                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0, args.length - opti);
-                }
-                if (!dumpProvider(fd, pw, name, newArgs, 0, dumpAll)) {
-                    pw.println("No providers match: " + name);
-                    pw.println("Use -h for help.");
-                }
-            } else if ("providers".equals(cmd) || "prov".equals(cmd)) {
-                synchronized (this) {
-                    dumpProvidersLocked(fd, pw, args, opti, true, null);
-                }
-            } else if ("service".equals(cmd)) {
-                String[] newArgs;
-                String name;
-                if (opti >= args.length) {
-                    name = null;
-                    newArgs = EMPTY_STRING_ARRAY;
-                } else {
-                    name = args[opti];
-                    opti++;
-                    newArgs = new String[args.length - opti];
-                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
-                            args.length - opti);
-                }
-                if (!mServices.dumpService(fd, pw, name, newArgs, 0, dumpAll)) {
-                    pw.println("No services match: " + name);
-                    pw.println("Use -h for help.");
-                }
-            } else if ("package".equals(cmd)) {
-                String[] newArgs;
-                if (opti >= args.length) {
-                    pw.println("package: no package name specified");
-                    pw.println("Use -h for help.");
-                } else {
-                    dumpPackage = args[opti];
-                    opti++;
-                    newArgs = new String[args.length - opti];
-                    if (args.length > 2) System.arraycopy(args, opti, newArgs, 0,
-                            args.length - opti);
-                    args = newArgs;
-                    opti = 0;
-                    more = true;
-                }
-            } else if ("services".equals(cmd) || "s".equals(cmd)) {
-                synchronized (this) {
-                    mServices.dumpServicesLocked(fd, pw, args, opti, true, dumpClient, null);
-                }
-            } else {
-                // Dumping a single activity?
-                if (!dumpActivity(fd, pw, cmd, args, opti, dumpAll)) {
-                    pw.println("Bad activity command, or no activities match: " + cmd);
-                    pw.println("Use -h for help.");
-                }
-            }
-            if (!more) {
-                Binder.restoreCallingIdentity(origId);
-                return;
-            }
-        }
-
-        // No piece of data specified, dump everything.
-        synchronized (this) {
-            dumpPendingIntentsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpBroadcastsLocked(fd, pw, args, opti, dumpAll, dumpPackage);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpProvidersLocked(fd, pw, args, opti, dumpAll, dumpPackage);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            mServices.dumpServicesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpActivitiesLocked(fd, pw, args, opti, dumpAll, dumpClient, dumpPackage);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpProcessesLocked(fd, pw, args, opti, dumpAll, dumpPackage);
-        }
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    void dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll, boolean dumpClient, String dumpPackage) {
-        pw.println("ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)");
-
-        boolean printedAnything = mStackSupervisor.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient,
-                dumpPackage);
-        boolean needSep = printedAnything;
-
-        boolean printed = ActivityStackSupervisor.printThisActivity(pw, mFocusedActivity,
-                dumpPackage, needSep, "  mFocusedActivity: ");
-        if (printed) {
-            printedAnything = true;
-            needSep = false;
-        }
-
-        if (dumpPackage == null) {
-            if (needSep) {
-                pw.println();
-            }
-            needSep = true;
-            printedAnything = true;
-            mStackSupervisor.dump(pw, "  ");
-        }
-
-        if (mRecentTasks.size() > 0) {
-            boolean printedHeader = false;
-
-            final int N = mRecentTasks.size();
-            for (int i=0; i<N; i++) {
-                TaskRecord tr = mRecentTasks.get(i);
-                if (dumpPackage != null) {
-                    if (tr.realActivity == null ||
-                            !dumpPackage.equals(tr.realActivity)) {
-                        continue;
-                    }
-                }
-                if (!printedHeader) {
-                    if (needSep) {
-                        pw.println();
-                    }
-                    pw.println("  Recent tasks:");
-                    printedHeader = true;
-                    printedAnything = true;
-                }
-                pw.print("  * Recent #"); pw.print(i); pw.print(": ");
-                        pw.println(tr);
-                if (dumpAll) {
-                    mRecentTasks.get(i).dump(pw, "    ");
-                }
-            }
-        }
-
-        if (!printedAnything) {
-            pw.println("  (nothing)");
-        }
-    }
-
-    void dumpProcessesLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll, String dumpPackage) {
-        boolean needSep = false;
-        boolean printedAnything = false;
-        int numPers = 0;
-
-        pw.println("ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)");
-
-        if (dumpAll) {
-            final int NP = mProcessNames.getMap().size();
-            for (int ip=0; ip<NP; ip++) {
-                SparseArray<ProcessRecord> procs = mProcessNames.getMap().valueAt(ip);
-                final int NA = procs.size();
-                for (int ia=0; ia<NA; ia++) {
-                    ProcessRecord r = procs.valueAt(ia);
-                    if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
-                        continue;
-                    }
-                    if (!needSep) {
-                        pw.println("  All known processes:");
-                        needSep = true;
-                        printedAnything = true;
-                    }
-                    pw.print(r.persistent ? "  *PERS*" : "  *APP*");
-                        pw.print(" UID "); pw.print(procs.keyAt(ia));
-                        pw.print(" "); pw.println(r);
-                    r.dump(pw, "    ");
-                    if (r.persistent) {
-                        numPers++;
-                    }
-                }
-            }
-        }
-
-        if (mIsolatedProcesses.size() > 0) {
-            boolean printed = false;
-            for (int i=0; i<mIsolatedProcesses.size(); i++) {
-                ProcessRecord r = mIsolatedProcesses.valueAt(i);
-                if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
-                    continue;
-                }
-                if (!printed) {
-                    if (needSep) {
-                        pw.println();
-                    }
-                    pw.println("  Isolated process list (sorted by uid):");
-                    printedAnything = true;
-                    printed = true;
-                    needSep = true;
-                }
-                pw.println(String.format("%sIsolated #%2d: %s",
-                        "    ", i, r.toString()));
-            }
-        }
-
-        if (mLruProcesses.size() > 0) {
-            if (needSep) {
-                pw.println();
-            }
-            pw.print("  Process LRU list (sorted by oom_adj, "); pw.print(mLruProcesses.size());
-                    pw.print(" total, non-act at ");
-                    pw.print(mLruProcesses.size()-mLruProcessActivityStart);
-                    pw.print(", non-svc at ");
-                    pw.print(mLruProcesses.size()-mLruProcessServiceStart);
-                    pw.println("):");
-            dumpProcessOomList(pw, this, mLruProcesses, "    ", "Proc", "PERS", false, dumpPackage);
-            needSep = true;
-            printedAnything = true;
-        }
-
-        if (dumpAll || dumpPackage != null) {
-            synchronized (mPidsSelfLocked) {
-                boolean printed = false;
-                for (int i=0; i<mPidsSelfLocked.size(); i++) {
-                    ProcessRecord r = mPidsSelfLocked.valueAt(i);
-                    if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
-                        continue;
-                    }
-                    if (!printed) {
-                        if (needSep) pw.println();
-                        needSep = true;
-                        pw.println("  PID mappings:");
-                        printed = true;
-                        printedAnything = true;
-                    }
-                    pw.print("    PID #"); pw.print(mPidsSelfLocked.keyAt(i));
-                        pw.print(": "); pw.println(mPidsSelfLocked.valueAt(i));
-                }
-            }
-        }
-        
-        if (mForegroundProcesses.size() > 0) {
-            synchronized (mPidsSelfLocked) {
-                boolean printed = false;
-                for (int i=0; i<mForegroundProcesses.size(); i++) {
-                    ProcessRecord r = mPidsSelfLocked.get( 
-                            mForegroundProcesses.valueAt(i).pid);
-                    if (dumpPackage != null && (r == null
-                            || !r.pkgList.containsKey(dumpPackage))) {
-                        continue;
-                    }
-                    if (!printed) {
-                        if (needSep) pw.println();
-                        needSep = true;
-                        pw.println("  Foreground Processes:");
-                        printed = true;
-                        printedAnything = true;
-                    }
-                    pw.print("    PID #"); pw.print(mForegroundProcesses.keyAt(i));
-                            pw.print(": "); pw.println(mForegroundProcesses.valueAt(i));
-                }
-            }
-        }
-        
-        if (mPersistentStartingProcesses.size() > 0) {
-            if (needSep) pw.println();
-            needSep = true;
-            printedAnything = true;
-            pw.println("  Persisent processes that are starting:");
-            dumpProcessList(pw, this, mPersistentStartingProcesses, "    ",
-                    "Starting Norm", "Restarting PERS", dumpPackage);
-        }
-
-        if (mRemovedProcesses.size() > 0) {
-            if (needSep) pw.println();
-            needSep = true;
-            printedAnything = true;
-            pw.println("  Processes that are being removed:");
-            dumpProcessList(pw, this, mRemovedProcesses, "    ",
-                    "Removed Norm", "Removed PERS", dumpPackage);
-        }
-        
-        if (mProcessesOnHold.size() > 0) {
-            if (needSep) pw.println();
-            needSep = true;
-            printedAnything = true;
-            pw.println("  Processes that are on old until the system is ready:");
-            dumpProcessList(pw, this, mProcessesOnHold, "    ",
-                    "OnHold Norm", "OnHold PERS", dumpPackage);
-        }
-
-        needSep = dumpProcessesToGc(fd, pw, args, opti, needSep, dumpAll, dumpPackage);
-        
-        if (mProcessCrashTimes.getMap().size() > 0) {
-            boolean printed = false;
-            long now = SystemClock.uptimeMillis();
-            final ArrayMap<String, SparseArray<Long>> pmap = mProcessCrashTimes.getMap();
-            final int NP = pmap.size();
-            for (int ip=0; ip<NP; ip++) {
-                String pname = pmap.keyAt(ip);
-                SparseArray<Long> uids = pmap.valueAt(ip);
-                final int N = uids.size();
-                for (int i=0; i<N; i++) {
-                    int puid = uids.keyAt(i);
-                    ProcessRecord r = mProcessNames.get(pname, puid);
-                    if (dumpPackage != null && (r == null
-                            || !r.pkgList.containsKey(dumpPackage))) {
-                        continue;
-                    }
-                    if (!printed) {
-                        if (needSep) pw.println();
-                        needSep = true;
-                        pw.println("  Time since processes crashed:");
-                        printed = true;
-                        printedAnything = true;
-                    }
-                    pw.print("    Process "); pw.print(pname);
-                            pw.print(" uid "); pw.print(puid);
-                            pw.print(": last crashed ");
-                            TimeUtils.formatDuration(now-uids.valueAt(i), pw);
-                            pw.println(" ago");
-                }
-            }
-        }
-
-        if (mBadProcesses.getMap().size() > 0) {
-            boolean printed = false;
-            final ArrayMap<String, SparseArray<BadProcessInfo>> pmap = mBadProcesses.getMap();
-            final int NP = pmap.size();
-            for (int ip=0; ip<NP; ip++) {
-                String pname = pmap.keyAt(ip);
-                SparseArray<BadProcessInfo> uids = pmap.valueAt(ip);
-                final int N = uids.size();
-                for (int i=0; i<N; i++) {
-                    int puid = uids.keyAt(i);
-                    ProcessRecord r = mProcessNames.get(pname, puid);
-                    if (dumpPackage != null && (r == null
-                            || !r.pkgList.containsKey(dumpPackage))) {
-                        continue;
-                    }
-                    if (!printed) {
-                        if (needSep) pw.println();
-                        needSep = true;
-                        pw.println("  Bad processes:");
-                        printedAnything = true;
-                    }
-                    BadProcessInfo info = uids.valueAt(i);
-                    pw.print("    Bad process "); pw.print(pname);
-                            pw.print(" uid "); pw.print(puid);
-                            pw.print(": crashed at time "); pw.println(info.time);
-                    if (info.shortMsg != null) {
-                        pw.print("      Short msg: "); pw.println(info.shortMsg);
-                    }
-                    if (info.longMsg != null) {
-                        pw.print("      Long msg: "); pw.println(info.longMsg);
-                    }
-                    if (info.stack != null) {
-                        pw.println("      Stack:");
-                        int lastPos = 0;
-                        for (int pos=0; pos<info.stack.length(); pos++) {
-                            if (info.stack.charAt(pos) == '\n') {
-                                pw.print("        ");
-                                pw.write(info.stack, lastPos, pos-lastPos);
-                                pw.println();
-                                lastPos = pos+1;
-                            }
-                        }
-                        if (lastPos < info.stack.length()) {
-                            pw.print("        ");
-                            pw.write(info.stack, lastPos, info.stack.length()-lastPos);
-                            pw.println();
-                        }
-                    }
-                }
-            }
-        }
-
-        if (dumpPackage == null) {
-            pw.println();
-            needSep = false;
-            pw.println("  mStartedUsers:");
-            for (int i=0; i<mStartedUsers.size(); i++) {
-                UserStartedState uss = mStartedUsers.valueAt(i);
-                pw.print("    User #"); pw.print(uss.mHandle.getIdentifier());
-                        pw.print(": "); uss.dump("", pw);
-            }
-            pw.print("  mStartedUserArray: [");
-            for (int i=0; i<mStartedUserArray.length; i++) {
-                if (i > 0) pw.print(", ");
-                pw.print(mStartedUserArray[i]);
-            }
-            pw.println("]");
-            pw.print("  mUserLru: [");
-            for (int i=0; i<mUserLru.size(); i++) {
-                if (i > 0) pw.print(", ");
-                pw.print(mUserLru.get(i));
-            }
-            pw.println("]");
-            if (dumpAll) {
-                pw.print("  mStartedUserArray: "); pw.println(Arrays.toString(mStartedUserArray));
-            }
-        }
-        if (mHomeProcess != null && (dumpPackage == null
-                || mHomeProcess.pkgList.containsKey(dumpPackage))) {
-            if (needSep) {
-                pw.println();
-                needSep = false;
-            }
-            pw.println("  mHomeProcess: " + mHomeProcess);
-        }
-        if (mPreviousProcess != null && (dumpPackage == null
-                || mPreviousProcess.pkgList.containsKey(dumpPackage))) {
-            if (needSep) {
-                pw.println();
-                needSep = false;
-            }
-            pw.println("  mPreviousProcess: " + mPreviousProcess);
-        }
-        if (dumpAll) {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("  mPreviousProcessVisibleTime: ");
-            TimeUtils.formatDuration(mPreviousProcessVisibleTime, sb);
-            pw.println(sb);
-        }
-        if (mHeavyWeightProcess != null && (dumpPackage == null
-                || mHeavyWeightProcess.pkgList.containsKey(dumpPackage))) {
-            if (needSep) {
-                pw.println();
-                needSep = false;
-            }
-            pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
-        }
-        if (dumpPackage == null) {
-            pw.println("  mConfiguration: " + mConfiguration);
-        }
-        if (dumpAll) {
-            pw.println("  mConfigWillChange: " + getFocusedStack().mConfigWillChange);
-            if (mCompatModePackages.getPackages().size() > 0) {
-                boolean printed = false;
-                for (Map.Entry<String, Integer> entry
-                        : mCompatModePackages.getPackages().entrySet()) {
-                    String pkg = entry.getKey();
-                    int mode = entry.getValue();
-                    if (dumpPackage != null && !dumpPackage.equals(pkg)) {
-                        continue;
-                    }
-                    if (!printed) {
-                        pw.println("  mScreenCompatPackages:");
-                        printed = true;
-                    }
-                    pw.print("    "); pw.print(pkg); pw.print(": ");
-                            pw.print(mode); pw.println();
-                }
-            }
-        }
-        if (dumpPackage == null) {
-            if (mSleeping || mWentToSleep || mLockScreenShown) {
-                pw.println("  mSleeping=" + mSleeping + " mWentToSleep=" + mWentToSleep
-                        + " mLockScreenShown " + mLockScreenShown);
-            }
-            if (mShuttingDown) {
-                pw.println("  mShuttingDown=" + mShuttingDown);
-            }
-        }
-        if (mDebugApp != null || mOrigDebugApp != null || mDebugTransient
-                || mOrigWaitForDebugger) {
-            if (dumpPackage == null || dumpPackage.equals(mDebugApp)
-                    || dumpPackage.equals(mOrigDebugApp)) {
-                if (needSep) {
-                    pw.println();
-                    needSep = false;
-                }
-                pw.println("  mDebugApp=" + mDebugApp + "/orig=" + mOrigDebugApp
-                        + " mDebugTransient=" + mDebugTransient
-                        + " mOrigWaitForDebugger=" + mOrigWaitForDebugger);
-            }
-        }
-        if (mOpenGlTraceApp != null) {
-            if (dumpPackage == null || dumpPackage.equals(mOpenGlTraceApp)) {
-                if (needSep) {
-                    pw.println();
-                    needSep = false;
-                }
-                pw.println("  mOpenGlTraceApp=" + mOpenGlTraceApp);
-            }
-        }
-        if (mProfileApp != null || mProfileProc != null || mProfileFile != null
-                || mProfileFd != null) {
-            if (dumpPackage == null || dumpPackage.equals(mProfileApp)) {
-                if (needSep) {
-                    pw.println();
-                    needSep = false;
-                }
-                pw.println("  mProfileApp=" + mProfileApp + " mProfileProc=" + mProfileProc);
-                pw.println("  mProfileFile=" + mProfileFile + " mProfileFd=" + mProfileFd);
-                pw.println("  mProfileType=" + mProfileType + " mAutoStopProfiler="
-                        + mAutoStopProfiler);
-            }
-        }
-        if (dumpPackage == null) {
-            if (mAlwaysFinishActivities || mController != null) {
-                pw.println("  mAlwaysFinishActivities=" + mAlwaysFinishActivities
-                        + " mController=" + mController);
-            }
-            if (dumpAll) {
-                pw.println("  Total persistent processes: " + numPers);
-                pw.println("  mStartRunning=" + mStartRunning
-                        + " mProcessesReady=" + mProcessesReady
-                        + " mSystemReady=" + mSystemReady);
-                pw.println("  mBooting=" + mBooting
-                        + " mBooted=" + mBooted
-                        + " mFactoryTest=" + mFactoryTest);
-                pw.print("  mLastPowerCheckRealtime=");
-                        TimeUtils.formatDuration(mLastPowerCheckRealtime, pw);
-                        pw.println("");
-                pw.print("  mLastPowerCheckUptime=");
-                        TimeUtils.formatDuration(mLastPowerCheckUptime, pw);
-                        pw.println("");
-                pw.println("  mGoingToSleep=" + mStackSupervisor.mGoingToSleep);
-                pw.println("  mLaunchingActivity=" + mStackSupervisor.mLaunchingActivity);
-                pw.println("  mAdjSeq=" + mAdjSeq + " mLruSeq=" + mLruSeq);
-                pw.println("  mNumNonCachedProcs=" + mNumNonCachedProcs
-                        + " (" + mLruProcesses.size() + " total)"
-                        + " mNumCachedHiddenProcs=" + mNumCachedHiddenProcs
-                        + " mNumServiceProcs=" + mNumServiceProcs
-                        + " mNewNumServiceProcs=" + mNewNumServiceProcs);
-                pw.println("  mAllowLowerMemLevel=" + mAllowLowerMemLevel
-                        + " mLastMemoryLevel" + mLastMemoryLevel
-                        + " mLastNumProcesses" + mLastNumProcesses);
-                long now = SystemClock.uptimeMillis();
-                pw.print("  mLastIdleTime=");
-                        TimeUtils.formatDuration(now, mLastIdleTime, pw);
-                        pw.print(" mLowRamSinceLastIdle=");
-                        TimeUtils.formatDuration(getLowRamTimeSinceIdle(now), pw);
-                        pw.println();
-            }
-        }
-
-        if (!printedAnything) {
-            pw.println("  (nothing)");
-        }
-    }
-
-    boolean dumpProcessesToGc(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean needSep, boolean dumpAll, String dumpPackage) {
-        if (mProcessesToGc.size() > 0) {
-            boolean printed = false;
-            long now = SystemClock.uptimeMillis();
-            for (int i=0; i<mProcessesToGc.size(); i++) {
-                ProcessRecord proc = mProcessesToGc.get(i);
-                if (dumpPackage != null && !dumpPackage.equals(proc.info.packageName)) {
-                    continue;
-                }
-                if (!printed) {
-                    if (needSep) pw.println();
-                    needSep = true;
-                    pw.println("  Processes that are waiting to GC:");
-                    printed = true;
-                }
-                pw.print("    Process "); pw.println(proc);
-                pw.print("      lowMem="); pw.print(proc.reportLowMemory);
-                        pw.print(", last gced=");
-                        pw.print(now-proc.lastRequestedGc);
-                        pw.print(" ms ago, last lowMem=");
-                        pw.print(now-proc.lastLowMemory);
-                        pw.println(" ms ago");
-
-            }
-        }
-        return needSep;
-    }
-
-    void printOomLevel(PrintWriter pw, String name, int adj) {
-        pw.print("    ");
-        if (adj >= 0) {
-            pw.print(' ');
-            if (adj < 10) pw.print(' ');
-        } else {
-            if (adj > -10) pw.print(' ');
-        }
-        pw.print(adj);
-        pw.print(": ");
-        pw.print(name);
-        pw.print(" (");
-        pw.print(mProcessList.getMemLevel(adj)/1024);
-        pw.println(" kB)");
-    }
-
-    boolean dumpOomLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll) {
-        boolean needSep = false;
-
-        if (mLruProcesses.size() > 0) {
-            if (needSep) pw.println();
-            needSep = true;
-            pw.println("  OOM levels:");
-            printOomLevel(pw, "SYSTEM_ADJ", ProcessList.SYSTEM_ADJ);
-            printOomLevel(pw, "PERSISTENT_PROC_ADJ", ProcessList.PERSISTENT_PROC_ADJ);
-            printOomLevel(pw, "FOREGROUND_APP_ADJ", ProcessList.FOREGROUND_APP_ADJ);
-            printOomLevel(pw, "VISIBLE_APP_ADJ", ProcessList.VISIBLE_APP_ADJ);
-            printOomLevel(pw, "PERCEPTIBLE_APP_ADJ", ProcessList.PERCEPTIBLE_APP_ADJ);
-            printOomLevel(pw, "BACKUP_APP_ADJ", ProcessList.BACKUP_APP_ADJ);
-            printOomLevel(pw, "HEAVY_WEIGHT_APP_ADJ", ProcessList.HEAVY_WEIGHT_APP_ADJ);
-            printOomLevel(pw, "SERVICE_ADJ", ProcessList.SERVICE_ADJ);
-            printOomLevel(pw, "HOME_APP_ADJ", ProcessList.HOME_APP_ADJ);
-            printOomLevel(pw, "PREVIOUS_APP_ADJ", ProcessList.PREVIOUS_APP_ADJ);
-            printOomLevel(pw, "SERVICE_B_ADJ", ProcessList.SERVICE_B_ADJ);
-            printOomLevel(pw, "CACHED_APP_MIN_ADJ", ProcessList.CACHED_APP_MIN_ADJ);
-            printOomLevel(pw, "CACHED_APP_MAX_ADJ", ProcessList.CACHED_APP_MAX_ADJ);
-
-            if (needSep) pw.println();
-            pw.print("  Process OOM control ("); pw.print(mLruProcesses.size());
-                    pw.print(" total, non-act at ");
-                    pw.print(mLruProcesses.size()-mLruProcessActivityStart);
-                    pw.print(", non-svc at ");
-                    pw.print(mLruProcesses.size()-mLruProcessServiceStart);
-                    pw.println("):");
-            dumpProcessOomList(pw, this, mLruProcesses, "    ", "Proc", "PERS", true, null);
-            needSep = true;
-        }
-
-        dumpProcessesToGc(fd, pw, args, opti, needSep, dumpAll, null);
-
-        pw.println();
-        pw.println("  mHomeProcess: " + mHomeProcess);
-        pw.println("  mPreviousProcess: " + mPreviousProcess);
-        if (mHeavyWeightProcess != null) {
-            pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
-        }
-
-        return true;
-    }
-
-    /**
-     * There are three ways to call this:
-     *  - no provider specified: dump all the providers
-     *  - a flattened component name that matched an existing provider was specified as the
-     *    first arg: dump that one provider
-     *  - the first arg isn't the flattened component name of an existing provider:
-     *    dump all providers whose component contains the first arg as a substring
-     */
-    protected boolean dumpProvider(FileDescriptor fd, PrintWriter pw, String name, String[] args,
-            int opti, boolean dumpAll) {
-        return mProviderMap.dumpProvider(fd, pw, name, args, opti, dumpAll);
-    }
-
-    static class ItemMatcher {
-        ArrayList<ComponentName> components;
-        ArrayList<String> strings;
-        ArrayList<Integer> objects;
-        boolean all;
-        
-        ItemMatcher() {
-            all = true;
-        }
-
-        void build(String name) {
-            ComponentName componentName = ComponentName.unflattenFromString(name);
-            if (componentName != null) {
-                if (components == null) {
-                    components = new ArrayList<ComponentName>();
-                }
-                components.add(componentName);
-                all = false;
-            } else {
-                int objectId = 0;
-                // Not a '/' separated full component name; maybe an object ID?
-                try {
-                    objectId = Integer.parseInt(name, 16);
-                    if (objects == null) {
-                        objects = new ArrayList<Integer>();
-                    }
-                    objects.add(objectId);
-                    all = false;
-                } catch (RuntimeException e) {
-                    // Not an integer; just do string match.
-                    if (strings == null) {
-                        strings = new ArrayList<String>();
-                    }
-                    strings.add(name);
-                    all = false;
-                }
-            }
-        }
-
-        int build(String[] args, int opti) {
-            for (; opti<args.length; opti++) {
-                String name = args[opti];
-                if ("--".equals(name)) {
-                    return opti+1;
-                }
-                build(name);
-            }
-            return opti;
-        }
-
-        boolean match(Object object, ComponentName comp) {
-            if (all) {
-                return true;
-            }
-            if (components != null) {
-                for (int i=0; i<components.size(); i++) {
-                    if (components.get(i).equals(comp)) {
-                        return true;
-                    }
-                }
-            }
-            if (objects != null) {
-                for (int i=0; i<objects.size(); i++) {
-                    if (System.identityHashCode(object) == objects.get(i)) {
-                        return true;
-                    }
-                }
-            }
-            if (strings != null) {
-                String flat = comp.flattenToString();
-                for (int i=0; i<strings.size(); i++) {
-                    if (flat.contains(strings.get(i))) {
-                        return true;
-                    }
-                }
-            }
-            return false;
-        }
-    }
-
-    /**
-     * There are three things that cmd can be:
-     *  - a flattened component name that matches an existing activity
-     *  - the cmd arg isn't the flattened component name of an existing activity:
-     *    dump all activity whose component contains the cmd as a substring
-     *  - A hex number of the ActivityRecord object instance.
-     */
-    protected boolean dumpActivity(FileDescriptor fd, PrintWriter pw, String name, String[] args,
-            int opti, boolean dumpAll) {
-        ArrayList<ActivityRecord> activities;
-        
-        synchronized (this) {
-            activities = mStackSupervisor.getDumpActivitiesLocked(name);
-        }
-
-        if (activities.size() <= 0) {
-            return false;
-        }
-
-        String[] newArgs = new String[args.length - opti];
-        System.arraycopy(args, opti, newArgs, 0, args.length - opti);
-
-        TaskRecord lastTask = null;
-        boolean needSep = false;
-        for (int i=activities.size()-1; i>=0; i--) {
-            ActivityRecord r = activities.get(i);
-            if (needSep) {
-                pw.println();
-            }
-            needSep = true;
-            synchronized (this) {
-                if (lastTask != r.task) {
-                    lastTask = r.task;
-                    pw.print("TASK "); pw.print(lastTask.affinity);
-                            pw.print(" id="); pw.println(lastTask.taskId);
-                    if (dumpAll) {
-                        lastTask.dump(pw, "  ");
-                    }
-                }
-            }
-            dumpActivity("  ", fd, pw, activities.get(i), newArgs, dumpAll);
-        }
-        return true;
-    }
-
-    /**
-     * Invokes IApplicationThread.dumpActivity() on the thread of the specified activity if
-     * there is a thread associated with the activity.
-     */
-    private void dumpActivity(String prefix, FileDescriptor fd, PrintWriter pw,
-            final ActivityRecord r, String[] args, boolean dumpAll) {
-        String innerPrefix = prefix + "  ";
-        synchronized (this) {
-            pw.print(prefix); pw.print("ACTIVITY "); pw.print(r.shortComponentName);
-                    pw.print(" "); pw.print(Integer.toHexString(System.identityHashCode(r)));
-                    pw.print(" pid=");
-                    if (r.app != null) pw.println(r.app.pid);
-                    else pw.println("(not running)");
-            if (dumpAll) {
-                r.dump(pw, innerPrefix);
-            }
-        }
-        if (r.app != null && r.app.thread != null) {
-            // flush anything that is already in the PrintWriter since the thread is going
-            // to write to the file descriptor directly
-            pw.flush();
-            try {
-                TransferPipe tp = new TransferPipe();
-                try {
-                    r.app.thread.dumpActivity(tp.getWriteFd().getFileDescriptor(),
-                            r.appToken, innerPrefix, args);
-                    tp.go(fd);
-                } finally {
-                    tp.kill();
-                }
-            } catch (IOException e) {
-                pw.println(innerPrefix + "Failure while dumping the activity: " + e);
-            } catch (RemoteException e) {
-                pw.println(innerPrefix + "Got a RemoteException while dumping the activity");
-            }
-        }
-    }
-
-    void dumpBroadcastsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll, String dumpPackage) {
-        boolean needSep = false;
-        boolean onlyHistory = false;
-        boolean printedAnything = false;
-
-        if ("history".equals(dumpPackage)) {
-            if (opti < args.length && "-s".equals(args[opti])) {
-                dumpAll = false;
-            }
-            onlyHistory = true;
-            dumpPackage = null;
-        }
-
-        pw.println("ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)");
-        if (!onlyHistory && dumpAll) {
-            if (mRegisteredReceivers.size() > 0) {
-                boolean printed = false;
-                Iterator it = mRegisteredReceivers.values().iterator();
-                while (it.hasNext()) {
-                    ReceiverList r = (ReceiverList)it.next();
-                    if (dumpPackage != null && (r.app == null ||
-                            !dumpPackage.equals(r.app.info.packageName))) {
-                        continue;
-                    }
-                    if (!printed) {
-                        pw.println("  Registered Receivers:");
-                        needSep = true;
-                        printed = true;
-                        printedAnything = true;
-                    }
-                    pw.print("  * "); pw.println(r);
-                    r.dump(pw, "    ");
-                }
-            }
-
-            if (mReceiverResolver.dump(pw, needSep ?
-                    "\n  Receiver Resolver Table:" : "  Receiver Resolver Table:",
-                    "    ", dumpPackage, false)) {
-                needSep = true;
-                printedAnything = true;
-            }
-        }
-
-        for (BroadcastQueue q : mBroadcastQueues) {
-            needSep = q.dumpLocked(fd, pw, args, opti, dumpAll, dumpPackage, needSep);
-            printedAnything |= needSep;
-        }
-
-        needSep = true;
-        
-        if (!onlyHistory && mStickyBroadcasts != null && dumpPackage == null) {
-            for (int user=0; user<mStickyBroadcasts.size(); user++) {
-                if (needSep) {
-                    pw.println();
-                }
-                needSep = true;
-                printedAnything = true;
-                pw.print("  Sticky broadcasts for user ");
-                        pw.print(mStickyBroadcasts.keyAt(user)); pw.println(":");
-                StringBuilder sb = new StringBuilder(128);
-                for (Map.Entry<String, ArrayList<Intent>> ent
-                        : mStickyBroadcasts.valueAt(user).entrySet()) {
-                    pw.print("  * Sticky action "); pw.print(ent.getKey());
-                    if (dumpAll) {
-                        pw.println(":");
-                        ArrayList<Intent> intents = ent.getValue();
-                        final int N = intents.size();
-                        for (int i=0; i<N; i++) {
-                            sb.setLength(0);
-                            sb.append("    Intent: ");
-                            intents.get(i).toShortString(sb, false, true, false, false);
-                            pw.println(sb.toString());
-                            Bundle bundle = intents.get(i).getExtras();
-                            if (bundle != null) {
-                                pw.print("      ");
-                                pw.println(bundle.toString());
-                            }
-                        }
-                    } else {
-                        pw.println("");
-                    }
-                }
-            }
-        }
-        
-        if (!onlyHistory && dumpAll) {
-            pw.println();
-            for (BroadcastQueue queue : mBroadcastQueues) {
-                pw.println("  mBroadcastsScheduled [" + queue.mQueueName + "]="
-                        + queue.mBroadcastsScheduled);
-            }
-            pw.println("  mHandler:");
-            mHandler.dump(new PrintWriterPrinter(pw), "    ");
-            needSep = true;
-            printedAnything = true;
-        }
-        
-        if (!printedAnything) {
-            pw.println("  (nothing)");
-        }
-    }
-
-    void dumpProvidersLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll, String dumpPackage) {
-        boolean needSep;
-        boolean printedAnything = false;
-
-        ItemMatcher matcher = new ItemMatcher();
-        matcher.build(args, opti);
-
-        pw.println("ACTIVITY MANAGER CONTENT PROVIDERS (dumpsys activity providers)");
-
-        needSep = mProviderMap.dumpProvidersLocked(pw, dumpAll, dumpPackage);
-        printedAnything |= needSep;
-
-        if (mLaunchingProviders.size() > 0) {
-            boolean printed = false;
-            for (int i=mLaunchingProviders.size()-1; i>=0; i--) {
-                ContentProviderRecord r = mLaunchingProviders.get(i);
-                if (dumpPackage != null && !dumpPackage.equals(r.name.getPackageName())) {
-                    continue;
-                }
-                if (!printed) {
-                    if (needSep) pw.println();
-                    needSep = true;
-                    pw.println("  Launching content providers:");
-                    printed = true;
-                    printedAnything = true;
-                }
-                pw.print("  Launching #"); pw.print(i); pw.print(": ");
-                        pw.println(r);
-            }
-        }
-
-        if (mGrantedUriPermissions.size() > 0) {
-            boolean printed = false;
-            int dumpUid = -2;
-            if (dumpPackage != null) {
-                try {
-                    dumpUid = mContext.getPackageManager().getPackageUid(dumpPackage, 0);
-                } catch (NameNotFoundException e) {
-                    dumpUid = -1;
-                }
-            }
-            for (int i=0; i<mGrantedUriPermissions.size(); i++) {
-                int uid = mGrantedUriPermissions.keyAt(i);
-                if (dumpUid >= -1 && UserHandle.getAppId(uid) != dumpUid) {
-                    continue;
-                }
-                ArrayMap<Uri, UriPermission> perms
-                        = mGrantedUriPermissions.valueAt(i);
-                if (!printed) {
-                    if (needSep) pw.println();
-                    needSep = true;
-                    pw.println("  Granted Uri Permissions:");
-                    printed = true;
-                    printedAnything = true;
-                }
-                pw.print("  * UID "); pw.print(uid);
-                        pw.println(" holds:");
-                for (UriPermission perm : perms.values()) {
-                    pw.print("    "); pw.println(perm);
-                    if (dumpAll) {
-                        perm.dump(pw, "      ");
-                    }
-                }
-            }
-        }
-
-        if (!printedAnything) {
-            pw.println("  (nothing)");
-        }
-    }
-
-    void dumpPendingIntentsLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll, String dumpPackage) {
-        boolean printed = false;
-
-        pw.println("ACTIVITY MANAGER PENDING INTENTS (dumpsys activity intents)");
-
-        if (mIntentSenderRecords.size() > 0) {
-            Iterator<WeakReference<PendingIntentRecord>> it
-                    = mIntentSenderRecords.values().iterator();
-            while (it.hasNext()) {
-                WeakReference<PendingIntentRecord> ref = it.next();
-                PendingIntentRecord rec = ref != null ? ref.get(): null;
-                if (dumpPackage != null && (rec == null
-                        || !dumpPackage.equals(rec.key.packageName))) {
-                    continue;
-                }
-                printed = true;
-                if (rec != null) {
-                    pw.print("  * "); pw.println(rec);
-                    if (dumpAll) {
-                        rec.dump(pw, "    ");
-                    }
-                } else {
-                    pw.print("  * "); pw.println(ref);
-                }
-            }
-        }
-
-        if (!printed) {
-            pw.println("  (nothing)");
-        }
-    }
-
-    private static final int dumpProcessList(PrintWriter pw,
-            ActivityManagerService service, List list,
-            String prefix, String normalLabel, String persistentLabel,
-            String dumpPackage) {
-        int numPers = 0;
-        final int N = list.size()-1;
-        for (int i=N; i>=0; i--) {
-            ProcessRecord r = (ProcessRecord)list.get(i);
-            if (dumpPackage != null && !dumpPackage.equals(r.info.packageName)) {
-                continue;
-            }
-            pw.println(String.format("%s%s #%2d: %s",
-                    prefix, (r.persistent ? persistentLabel : normalLabel),
-                    i, r.toString()));
-            if (r.persistent) {
-                numPers++;
-            }
-        }
-        return numPers;
-    }
-
-    private static final boolean dumpProcessOomList(PrintWriter pw,
-            ActivityManagerService service, List<ProcessRecord> origList,
-            String prefix, String normalLabel, String persistentLabel,
-            boolean inclDetails, String dumpPackage) {
-
-        ArrayList<Pair<ProcessRecord, Integer>> list
-                = new ArrayList<Pair<ProcessRecord, Integer>>(origList.size());
-        for (int i=0; i<origList.size(); i++) {
-            ProcessRecord r = origList.get(i);
-            if (dumpPackage != null && !r.pkgList.containsKey(dumpPackage)) {
-                continue;
-            }
-            list.add(new Pair<ProcessRecord, Integer>(origList.get(i), i));
-        }
-
-        if (list.size() <= 0) {
-            return false;
-        }
-
-        Comparator<Pair<ProcessRecord, Integer>> comparator
-                = new Comparator<Pair<ProcessRecord, Integer>>() {
-            @Override
-            public int compare(Pair<ProcessRecord, Integer> object1,
-                    Pair<ProcessRecord, Integer> object2) {
-                if (object1.first.setAdj != object2.first.setAdj) {
-                    return object1.first.setAdj > object2.first.setAdj ? -1 : 1;
-                }
-                if (object1.second.intValue() != object2.second.intValue()) {
-                    return object1.second.intValue() > object2.second.intValue() ? -1 : 1;
-                }
-                return 0;
-            }
-        };
-
-        Collections.sort(list, comparator);
-
-        final long curRealtime = SystemClock.elapsedRealtime();
-        final long realtimeSince = curRealtime - service.mLastPowerCheckRealtime;
-        final long curUptime = SystemClock.uptimeMillis();
-        final long uptimeSince = curUptime - service.mLastPowerCheckUptime;
-
-        for (int i=list.size()-1; i>=0; i--) {
-            ProcessRecord r = list.get(i).first;
-            String oomAdj = ProcessList.makeOomAdjString(r.setAdj);
-            char schedGroup;
-            switch (r.setSchedGroup) {
-                case Process.THREAD_GROUP_BG_NONINTERACTIVE:
-                    schedGroup = 'B';
-                    break;
-                case Process.THREAD_GROUP_DEFAULT:
-                    schedGroup = 'F';
-                    break;
-                default:
-                    schedGroup = '?';
-                    break;
-            }
-            char foreground;
-            if (r.foregroundActivities) {
-                foreground = 'A';
-            } else if (r.foregroundServices) {
-                foreground = 'S';
-            } else {
-                foreground = ' ';
-            }
-            String procState = ProcessList.makeProcStateString(r.curProcState);
-            pw.print(prefix);
-            pw.print(r.persistent ? persistentLabel : normalLabel);
-            pw.print(" #");
-            int num = (origList.size()-1)-list.get(i).second;
-            if (num < 10) pw.print(' ');
-            pw.print(num);
-            pw.print(": ");
-            pw.print(oomAdj);
-            pw.print(' ');
-            pw.print(schedGroup);
-            pw.print('/');
-            pw.print(foreground);
-            pw.print('/');
-            pw.print(procState);
-            pw.print(" trm:");
-            if (r.trimMemoryLevel < 10) pw.print(' ');
-            pw.print(r.trimMemoryLevel);
-            pw.print(' ');
-            pw.print(r.toShortString());
-            pw.print(" (");
-            pw.print(r.adjType);
-            pw.println(')');
-            if (r.adjSource != null || r.adjTarget != null) {
-                pw.print(prefix);
-                pw.print("    ");
-                if (r.adjTarget instanceof ComponentName) {
-                    pw.print(((ComponentName)r.adjTarget).flattenToShortString());
-                } else if (r.adjTarget != null) {
-                    pw.print(r.adjTarget.toString());
-                } else {
-                    pw.print("{null}");
-                }
-                pw.print("<=");
-                if (r.adjSource instanceof ProcessRecord) {
-                    pw.print("Proc{");
-                    pw.print(((ProcessRecord)r.adjSource).toShortString());
-                    pw.println("}");
-                } else if (r.adjSource != null) {
-                    pw.println(r.adjSource.toString());
-                } else {
-                    pw.println("{null}");
-                }
-            }
-            if (inclDetails) {
-                pw.print(prefix);
-                pw.print("    ");
-                pw.print("oom: max="); pw.print(r.maxAdj);
-                pw.print(" curRaw="); pw.print(r.curRawAdj);
-                pw.print(" setRaw="); pw.print(r.setRawAdj);
-                pw.print(" cur="); pw.print(r.curAdj);
-                pw.print(" set="); pw.println(r.setAdj);
-                pw.print(prefix);
-                pw.print("    ");
-                pw.print("state: cur="); pw.print(ProcessList.makeProcStateString(r.curProcState));
-                pw.print(" set="); pw.print(ProcessList.makeProcStateString(r.setProcState));
-                pw.print(" lastPss="); pw.print(r.lastPss);
-                pw.print(" lastCachedPss="); pw.println(r.lastCachedPss);
-                pw.print(prefix);
-                pw.print("    ");
-                pw.print("keeping="); pw.print(r.keeping);
-                pw.print(" cached="); pw.print(r.cached);
-                pw.print(" empty="); pw.print(r.empty);
-                pw.print(" hasAboveClient="); pw.println(r.hasAboveClient);
-
-                if (!r.keeping) {
-                    if (r.lastWakeTime != 0) {
-                        long wtime;
-                        BatteryStatsImpl stats = service.mBatteryStatsService.getActiveStatistics();
-                        synchronized (stats) {
-                            wtime = stats.getProcessWakeTime(r.info.uid,
-                                    r.pid, curRealtime);
-                        }
-                        long timeUsed = wtime - r.lastWakeTime;
-                        pw.print(prefix);
-                        pw.print("    ");
-                        pw.print("keep awake over ");
-                        TimeUtils.formatDuration(realtimeSince, pw);
-                        pw.print(" used ");
-                        TimeUtils.formatDuration(timeUsed, pw);
-                        pw.print(" (");
-                        pw.print((timeUsed*100)/realtimeSince);
-                        pw.println("%)");
-                    }
-                    if (r.lastCpuTime != 0) {
-                        long timeUsed = r.curCpuTime - r.lastCpuTime;
-                        pw.print(prefix);
-                        pw.print("    ");
-                        pw.print("run cpu over ");
-                        TimeUtils.formatDuration(uptimeSince, pw);
-                        pw.print(" used ");
-                        TimeUtils.formatDuration(timeUsed, pw);
-                        pw.print(" (");
-                        pw.print((timeUsed*100)/uptimeSince);
-                        pw.println("%)");
-                    }
-                }
-            }
-        }
-        return true;
-    }
-
-    ArrayList<ProcessRecord> collectProcesses(PrintWriter pw, int start, String[] args) {
-        ArrayList<ProcessRecord> procs;
-        synchronized (this) {
-            if (args != null && args.length > start
-                    && args[start].charAt(0) != '-') {
-                procs = new ArrayList<ProcessRecord>();
-                int pid = -1;
-                try {
-                    pid = Integer.parseInt(args[start]);
-                } catch (NumberFormatException e) {
-                }
-                for (int i=mLruProcesses.size()-1; i>=0; i--) {
-                    ProcessRecord proc = mLruProcesses.get(i);
-                    if (proc.pid == pid) {
-                        procs.add(proc);
-                    } else if (proc.processName.equals(args[start])) {
-                        procs.add(proc);
-                    }
-                }
-                if (procs.size() <= 0) {
-                    return null;
-                }
-            } else {
-                procs = new ArrayList<ProcessRecord>(mLruProcesses);
-            }
-        }
-        return procs;
-    }
-
-    final void dumpGraphicsHardwareUsage(FileDescriptor fd,
-            PrintWriter pw, String[] args) {
-        ArrayList<ProcessRecord> procs = collectProcesses(pw, 0, args);
-        if (procs == null) {
-            pw.println("No process found for: " + args[0]);
-            return;
-        }
-
-        long uptime = SystemClock.uptimeMillis();
-        long realtime = SystemClock.elapsedRealtime();
-        pw.println("Applications Graphics Acceleration Info:");
-        pw.println("Uptime: " + uptime + " Realtime: " + realtime);
-        
-        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
-            ProcessRecord r = procs.get(i);
-            if (r.thread != null) {
-                pw.println("\n** Graphics info for pid " + r.pid + " [" + r.processName + "] **");
-                pw.flush();
-                try {
-                    TransferPipe tp = new TransferPipe();
-                    try {
-                        r.thread.dumpGfxInfo(tp.getWriteFd().getFileDescriptor(), args);
-                        tp.go(fd);
-                    } finally {
-                        tp.kill();
-                    }
-                } catch (IOException e) {
-                    pw.println("Failure while dumping the app: " + r);
-                    pw.flush();
-                } catch (RemoteException e) {
-                    pw.println("Got a RemoteException while dumping the app " + r);
-                    pw.flush();
-                }
-            }
-        }
-    }
-
-    final void dumpDbInfo(FileDescriptor fd, PrintWriter pw, String[] args) {
-        ArrayList<ProcessRecord> procs = collectProcesses(pw, 0, args);
-        if (procs == null) {
-            pw.println("No process found for: " + args[0]);
-            return;
-        }
-
-        pw.println("Applications Database Info:");
-
-        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
-            ProcessRecord r = procs.get(i);
-            if (r.thread != null) {
-                pw.println("\n** Database info for pid " + r.pid + " [" + r.processName + "] **");
-                pw.flush();
-                try {
-                    TransferPipe tp = new TransferPipe();
-                    try {
-                        r.thread.dumpDbInfo(tp.getWriteFd().getFileDescriptor(), args);
-                        tp.go(fd);
-                    } finally {
-                        tp.kill();
-                    }
-                } catch (IOException e) {
-                    pw.println("Failure while dumping the app: " + r);
-                    pw.flush();
-                } catch (RemoteException e) {
-                    pw.println("Got a RemoteException while dumping the app " + r);
-                    pw.flush();
-                }
-            }
-        }
-    }
-
-    final static class MemItem {
-        final boolean isProc;
-        final String label;
-        final String shortLabel;
-        final long pss;
-        final int id;
-        final boolean hasActivities;
-        ArrayList<MemItem> subitems;
-
-        public MemItem(String _label, String _shortLabel, long _pss, int _id,
-                boolean _hasActivities) {
-            isProc = true;
-            label = _label;
-            shortLabel = _shortLabel;
-            pss = _pss;
-            id = _id;
-            hasActivities = _hasActivities;
-        }
-
-        public MemItem(String _label, String _shortLabel, long _pss, int _id) {
-            isProc = false;
-            label = _label;
-            shortLabel = _shortLabel;
-            pss = _pss;
-            id = _id;
-            hasActivities = false;
-        }
-    }
-
-    static final void dumpMemItems(PrintWriter pw, String prefix, String tag,
-            ArrayList<MemItem> items, boolean sort, boolean isCompact) {
-        if (sort && !isCompact) {
-            Collections.sort(items, new Comparator<MemItem>() {
-                @Override
-                public int compare(MemItem lhs, MemItem rhs) {
-                    if (lhs.pss < rhs.pss) {
-                        return 1;
-                    } else if (lhs.pss > rhs.pss) {
-                        return -1;
-                    }
-                    return 0;
-                }
-            });
-        }
-
-        for (int i=0; i<items.size(); i++) {
-            MemItem mi = items.get(i);
-            if (!isCompact) {
-                pw.print(prefix); pw.printf("%7d kB: ", mi.pss); pw.println(mi.label);
-            } else if (mi.isProc) {
-                pw.print("proc,"); pw.print(tag); pw.print(","); pw.print(mi.shortLabel);
-                pw.print(","); pw.print(mi.id); pw.print(","); pw.print(mi.pss);
-                pw.println(mi.hasActivities ? ",a" : ",e");
-            } else {
-                pw.print(tag); pw.print(","); pw.print(mi.shortLabel); pw.print(",");
-                pw.println(mi.pss);
-            }
-            if (mi.subitems != null) {
-                dumpMemItems(pw, prefix + "           ", mi.shortLabel, mi.subitems,
-                        true, isCompact);
-            }
-        }
-    }
-
-    // These are in KB.
-    static final long[] DUMP_MEM_BUCKETS = new long[] {
-        5*1024, 7*1024, 10*1024, 15*1024, 20*1024, 30*1024, 40*1024, 80*1024,
-        120*1024, 160*1024, 200*1024,
-        250*1024, 300*1024, 350*1024, 400*1024, 500*1024, 600*1024, 800*1024,
-        1*1024*1024, 2*1024*1024, 5*1024*1024, 10*1024*1024, 20*1024*1024
-    };
-
-    static final void appendMemBucket(StringBuilder out, long memKB, String label,
-            boolean stackLike) {
-        int start = label.lastIndexOf('.');
-        if (start >= 0) start++;
-        else start = 0;
-        int end = label.length();
-        for (int i=0; i<DUMP_MEM_BUCKETS.length; i++) {
-            if (DUMP_MEM_BUCKETS[i] >= memKB) {
-                long bucket = DUMP_MEM_BUCKETS[i]/1024;
-                out.append(bucket);
-                out.append(stackLike ? "MB." : "MB ");
-                out.append(label, start, end);
-                return;
-            }
-        }
-        out.append(memKB/1024);
-        out.append(stackLike ? "MB." : "MB ");
-        out.append(label, start, end);
-    }
-
-    static final int[] DUMP_MEM_OOM_ADJ = new int[] {
-            ProcessList.NATIVE_ADJ,
-            ProcessList.SYSTEM_ADJ, ProcessList.PERSISTENT_PROC_ADJ, ProcessList.FOREGROUND_APP_ADJ,
-            ProcessList.VISIBLE_APP_ADJ, ProcessList.PERCEPTIBLE_APP_ADJ,
-            ProcessList.BACKUP_APP_ADJ, ProcessList.HEAVY_WEIGHT_APP_ADJ,
-            ProcessList.SERVICE_ADJ, ProcessList.HOME_APP_ADJ,
-            ProcessList.PREVIOUS_APP_ADJ, ProcessList.SERVICE_B_ADJ, ProcessList.CACHED_APP_MAX_ADJ
-    };
-    static final String[] DUMP_MEM_OOM_LABEL = new String[] {
-            "Native",
-            "System", "Persistent", "Foreground",
-            "Visible", "Perceptible",
-            "Heavy Weight", "Backup",
-            "A Services", "Home",
-            "Previous", "B Services", "Cached"
-    };
-    static final String[] DUMP_MEM_OOM_COMPACT_LABEL = new String[] {
-            "native",
-            "sys", "pers", "fore",
-            "vis", "percept",
-            "heavy", "backup",
-            "servicea", "home",
-            "prev", "serviceb", "cached"
-    };
-
-    private final void dumpApplicationMemoryUsageHeader(PrintWriter pw, long uptime,
-            long realtime, boolean isCheckinRequest, boolean isCompact) {
-        if (isCheckinRequest || isCompact) {
-            // short checkin version
-            pw.print("time,"); pw.print(uptime); pw.print(","); pw.println(realtime);
-        } else {
-            pw.println("Applications Memory Usage (kB):");
-            pw.println("Uptime: " + uptime + " Realtime: " + realtime);
-        }
-    }
-
-    final void dumpApplicationMemoryUsage(FileDescriptor fd,
-            PrintWriter pw, String prefix, String[] args, boolean brief, PrintWriter categoryPw) {
-        boolean dumpDetails = false;
-        boolean dumpFullDetails = false;
-        boolean dumpDalvik = false;
-        boolean oomOnly = false;
-        boolean isCompact = false;
-        boolean localOnly = false;
-        
-        int opti = 0;
-        while (opti < args.length) {
-            String opt = args[opti];
-            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
-                break;
-            }
-            opti++;
-            if ("-a".equals(opt)) {
-                dumpDetails = true;
-                dumpFullDetails = true;
-                dumpDalvik = true;
-            } else if ("-d".equals(opt)) {
-                dumpDalvik = true;
-            } else if ("-c".equals(opt)) {
-                isCompact = true;
-            } else if ("--oom".equals(opt)) {
-                oomOnly = true;
-            } else if ("--local".equals(opt)) {
-                localOnly = true;
-            } else if ("-h".equals(opt)) {
-                pw.println("meminfo dump options: [-a] [-d] [-c] [--oom] [process]");
-                pw.println("  -a: include all available information for each process.");
-                pw.println("  -d: include dalvik details when dumping process details.");
-                pw.println("  -c: dump in a compact machine-parseable representation.");
-                pw.println("  --oom: only show processes organized by oom adj.");
-                pw.println("  --local: only collect details locally, don't call process.");
-                pw.println("If [process] is specified it can be the name or ");
-                pw.println("pid of a specific process to dump.");
-                return;
-            } else {
-                pw.println("Unknown argument: " + opt + "; use -h for help");
-            }
-        }
-        
-        final boolean isCheckinRequest = scanArgs(args, "--checkin");
-        long uptime = SystemClock.uptimeMillis();
-        long realtime = SystemClock.elapsedRealtime();
-        final long[] tmpLong = new long[1];
-
-        ArrayList<ProcessRecord> procs = collectProcesses(pw, opti, args);
-        if (procs == null) {
-            // No Java processes.  Maybe they want to print a native process.
-            if (args != null && args.length > opti
-                    && args[opti].charAt(0) != '-') {
-                ArrayList<ProcessCpuTracker.Stats> nativeProcs
-                        = new ArrayList<ProcessCpuTracker.Stats>();
-                updateCpuStatsNow();
-                int findPid = -1;
-                try {
-                    findPid = Integer.parseInt(args[opti]);
-                } catch (NumberFormatException e) {
-                }
-                synchronized (mProcessCpuThread) {
-                    final int N = mProcessCpuTracker.countStats();
-                    for (int i=0; i<N; i++) {
-                        ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
-                        if (st.pid == findPid || (st.baseName != null
-                                && st.baseName.equals(args[opti]))) {
-                            nativeProcs.add(st);
-                        }
-                    }
-                }
-                if (nativeProcs.size() > 0) {
-                    dumpApplicationMemoryUsageHeader(pw, uptime, realtime, isCheckinRequest,
-                            isCompact);
-                    Debug.MemoryInfo mi = null;
-                    for (int i = nativeProcs.size() - 1 ; i >= 0 ; i--) {
-                        final ProcessCpuTracker.Stats r = nativeProcs.get(i);
-                        final int pid = r.pid;
-                        if (!isCheckinRequest && dumpDetails) {
-                            pw.println("\n** MEMINFO in pid " + pid + " [" + r.baseName + "] **");
-                        }
-                        if (mi == null) {
-                            mi = new Debug.MemoryInfo();
-                        }
-                        if (dumpDetails || (!brief && !oomOnly)) {
-                            Debug.getMemoryInfo(pid, mi);
-                        } else {
-                            mi.dalvikPss = (int)Debug.getPss(pid, tmpLong);
-                            mi.dalvikPrivateDirty = (int)tmpLong[0];
-                        }
-                        ActivityThread.dumpMemInfoTable(pw, mi, isCheckinRequest, dumpFullDetails,
-                                dumpDalvik, pid, r.baseName, 0, 0, 0, 0, 0, 0);
-                        if (isCheckinRequest) {
-                            pw.println();
-                        }
-                    }
-                    return;
-                }
-            }
-            pw.println("No process found for: " + args[opti]);
-            return;
-        }
-
-        if (!brief && !oomOnly && (procs.size() == 1 || isCheckinRequest)) {
-            dumpDetails = true;
-        }
-
-        dumpApplicationMemoryUsageHeader(pw, uptime, realtime, isCheckinRequest, isCompact);
-
-        String[] innerArgs = new String[args.length-opti];
-        System.arraycopy(args, opti, innerArgs, 0, args.length-opti);
-
-        ArrayList<MemItem> procMems = new ArrayList<MemItem>();
-        final SparseArray<MemItem> procMemsMap = new SparseArray<MemItem>();
-        long nativePss=0, dalvikPss=0, otherPss=0;
-        long[] miscPss = new long[Debug.MemoryInfo.NUM_OTHER_STATS];
-
-        long oomPss[] = new long[DUMP_MEM_OOM_LABEL.length];
-        ArrayList<MemItem>[] oomProcs = (ArrayList<MemItem>[])
-                new ArrayList[DUMP_MEM_OOM_LABEL.length];
-
-        long totalPss = 0;
-        long cachedPss = 0;
-
-        Debug.MemoryInfo mi = null;
-        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
-            final ProcessRecord r = procs.get(i);
-            final IApplicationThread thread;
-            final int pid;
-            final int oomAdj;
-            final boolean hasActivities;
-            synchronized (this) {
-                thread = r.thread;
-                pid = r.pid;
-                oomAdj = r.getSetAdjWithServices();
-                hasActivities = r.activities.size() > 0;
-            }
-            if (thread != null) {
-                if (!isCheckinRequest && dumpDetails) {
-                    pw.println("\n** MEMINFO in pid " + pid + " [" + r.processName + "] **");
-                }
-                if (mi == null) {
-                    mi = new Debug.MemoryInfo();
-                }
-                if (dumpDetails || (!brief && !oomOnly)) {
-                    Debug.getMemoryInfo(pid, mi);
-                } else {
-                    mi.dalvikPss = (int)Debug.getPss(pid, tmpLong);
-                    mi.dalvikPrivateDirty = (int)tmpLong[0];
-                }
-                if (dumpDetails) {
-                    if (localOnly) {
-                        ActivityThread.dumpMemInfoTable(pw, mi, isCheckinRequest, dumpFullDetails,
-                                dumpDalvik, pid, r.processName, 0, 0, 0, 0, 0, 0);
-                        if (isCheckinRequest) {
-                            pw.println();
-                        }
-                    } else {
-                        try {
-                            pw.flush();
-                            thread.dumpMemInfo(fd, mi, isCheckinRequest, dumpFullDetails,
-                                    dumpDalvik, innerArgs);
-                        } catch (RemoteException e) {
-                            if (!isCheckinRequest) {
-                                pw.println("Got RemoteException!");
-                                pw.flush();
-                            }
-                        }
-                    }
-                }
-
-                final long myTotalPss = mi.getTotalPss();
-                final long myTotalUss = mi.getTotalUss();
-
-                synchronized (this) {
-                    if (r.thread != null && oomAdj == r.getSetAdjWithServices()) {
-                        // Record this for posterity if the process has been stable.
-                        r.baseProcessTracker.addPss(myTotalPss, myTotalUss, true, r.pkgList);
-                    }
-                }
-
-                if (!isCheckinRequest && mi != null) {
-                    totalPss += myTotalPss;
-                    MemItem pssItem = new MemItem(r.processName + " (pid " + pid +
-                            (hasActivities ? " / activities)" : ")"),
-                            r.processName, myTotalPss, pid, hasActivities);
-                    procMems.add(pssItem);
-                    procMemsMap.put(pid, pssItem);
-
-                    nativePss += mi.nativePss;
-                    dalvikPss += mi.dalvikPss;
-                    otherPss += mi.otherPss;
-                    for (int j=0; j<Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
-                        long mem = mi.getOtherPss(j);
-                        miscPss[j] += mem;
-                        otherPss -= mem;
-                    }
-
-                    if (oomAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
-                        cachedPss += myTotalPss;
-                    }
-
-                    for (int oomIndex=0; oomIndex<oomPss.length; oomIndex++) {
-                        if (oomAdj <= DUMP_MEM_OOM_ADJ[oomIndex]
-                                || oomIndex == (oomPss.length-1)) {
-                            oomPss[oomIndex] += myTotalPss;
-                            if (oomProcs[oomIndex] == null) {
-                                oomProcs[oomIndex] = new ArrayList<MemItem>();
-                            }
-                            oomProcs[oomIndex].add(pssItem);
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-
-        if (!isCheckinRequest && procs.size() > 1) {
-            // If we are showing aggregations, also look for native processes to
-            // include so that our aggregations are more accurate.
-            updateCpuStatsNow();
-            synchronized (mProcessCpuThread) {
-                final int N = mProcessCpuTracker.countStats();
-                for (int i=0; i<N; i++) {
-                    ProcessCpuTracker.Stats st = mProcessCpuTracker.getStats(i);
-                    if (st.vsize > 0 && procMemsMap.indexOfKey(st.pid) < 0) {
-                        if (mi == null) {
-                            mi = new Debug.MemoryInfo();
-                        }
-                        if (!brief && !oomOnly) {
-                            Debug.getMemoryInfo(st.pid, mi);
-                        } else {
-                            mi.nativePss = (int)Debug.getPss(st.pid, tmpLong);
-                            mi.nativePrivateDirty = (int)tmpLong[0];
-                        }
-
-                        final long myTotalPss = mi.getTotalPss();
-                        totalPss += myTotalPss;
-
-                        MemItem pssItem = new MemItem(st.name + " (pid " + st.pid + ")",
-                                st.name, myTotalPss, st.pid, false);
-                        procMems.add(pssItem);
-
-                        nativePss += mi.nativePss;
-                        dalvikPss += mi.dalvikPss;
-                        otherPss += mi.otherPss;
-                        for (int j=0; j<Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
-                            long mem = mi.getOtherPss(j);
-                            miscPss[j] += mem;
-                            otherPss -= mem;
-                        }
-                        oomPss[0] += myTotalPss;
-                        if (oomProcs[0] == null) {
-                            oomProcs[0] = new ArrayList<MemItem>();
-                        }
-                        oomProcs[0].add(pssItem);
-                    }
-                }
-            }
-
-            ArrayList<MemItem> catMems = new ArrayList<MemItem>();
-
-            catMems.add(new MemItem("Native", "Native", nativePss, -1));
-            catMems.add(new MemItem("Dalvik", "Dalvik", dalvikPss, -2));
-            catMems.add(new MemItem("Unknown", "Unknown", otherPss, -3));
-            for (int j=0; j<Debug.MemoryInfo.NUM_OTHER_STATS; j++) {
-                String label = Debug.MemoryInfo.getOtherLabel(j);
-                catMems.add(new MemItem(label, label, miscPss[j], j));
-            }
-
-            ArrayList<MemItem> oomMems = new ArrayList<MemItem>();
-            for (int j=0; j<oomPss.length; j++) {
-                if (oomPss[j] != 0) {
-                    String label = isCompact ? DUMP_MEM_OOM_COMPACT_LABEL[j]
-                            : DUMP_MEM_OOM_LABEL[j];
-                    MemItem item = new MemItem(label, label, oomPss[j],
-                            DUMP_MEM_OOM_ADJ[j]);
-                    item.subitems = oomProcs[j];
-                    oomMems.add(item);
-                }
-            }
-
-            if (!brief && !oomOnly && !isCompact) {
-                pw.println();
-                pw.println("Total PSS by process:");
-                dumpMemItems(pw, "  ", "proc", procMems, true, isCompact);
-                pw.println();
-            }
-            if (!isCompact) {
-                pw.println("Total PSS by OOM adjustment:");
-            }
-            dumpMemItems(pw, "  ", "oom", oomMems, false, isCompact);
-            if (!brief && !oomOnly) {
-                PrintWriter out = categoryPw != null ? categoryPw : pw;
-                if (!isCompact) {
-                    out.println();
-                    out.println("Total PSS by category:");
-                }
-                dumpMemItems(out, "  ", "cat", catMems, true, isCompact);
-            }
-            if (!isCompact) {
-                pw.println();
-            }
-            MemInfoReader memInfo = new MemInfoReader();
-            memInfo.readMemInfo();
-            if (!brief) {
-                if (!isCompact) {
-                    pw.print("Total RAM: "); pw.print(memInfo.getTotalSizeKb());
-                    pw.println(" kB");
-                    pw.print(" Free RAM: "); pw.print(cachedPss + memInfo.getCachedSizeKb()
-                            + memInfo.getFreeSizeKb()); pw.print(" kB (");
-                            pw.print(cachedPss); pw.print(" cached pss + ");
-                            pw.print(memInfo.getCachedSizeKb()); pw.print(" cached + ");
-                            pw.print(memInfo.getFreeSizeKb()); pw.println(" free)");
-                } else {
-                    pw.print("ram,"); pw.print(memInfo.getTotalSizeKb()); pw.print(",");
-                    pw.print(cachedPss + memInfo.getCachedSizeKb()
-                            + memInfo.getFreeSizeKb()); pw.print(",");
-                    pw.println(totalPss - cachedPss);
-                }
-            }
-            if (!isCompact) {
-                pw.print(" Used RAM: "); pw.print(totalPss - cachedPss
-                        + memInfo.getBuffersSizeKb() + memInfo.getShmemSizeKb()
-                        + memInfo.getSlabSizeKb()); pw.print(" kB (");
-                        pw.print(totalPss - cachedPss); pw.print(" used pss + ");
-                        pw.print(memInfo.getBuffersSizeKb()); pw.print(" buffers + ");
-                        pw.print(memInfo.getShmemSizeKb()); pw.print(" shmem + ");
-                        pw.print(memInfo.getSlabSizeKb()); pw.println(" slab)");
-                pw.print(" Lost RAM: "); pw.print(memInfo.getTotalSizeKb()
-                        - totalPss - memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
-                        - memInfo.getBuffersSizeKb() - memInfo.getShmemSizeKb()
-                        - memInfo.getSlabSizeKb()); pw.println(" kB");
-            }
-            if (!brief) {
-                if (memInfo.getZramTotalSizeKb() != 0) {
-                    if (!isCompact) {
-                        pw.print("     ZRAM: "); pw.print(memInfo.getZramTotalSizeKb());
-                                pw.print(" kB physical used for ");
-                                pw.print(memInfo.getSwapTotalSizeKb()
-                                        - memInfo.getSwapFreeSizeKb());
-                                pw.print(" kB in swap (");
-                                pw.print(memInfo.getSwapTotalSizeKb());
-                                pw.println(" kB total swap)");
-                    } else {
-                        pw.print("zram,"); pw.print(memInfo.getZramTotalSizeKb()); pw.print(",");
-                                pw.print(memInfo.getSwapTotalSizeKb()); pw.print(",");
-                                pw.println(memInfo.getSwapFreeSizeKb());
-                    }
-                }
-                final int[] SINGLE_LONG_FORMAT = new int[] {
-                    Process.PROC_SPACE_TERM|Process.PROC_OUT_LONG
-                };
-                long[] longOut = new long[1];
-                Process.readProcFile("/sys/kernel/mm/ksm/pages_shared",
-                        SINGLE_LONG_FORMAT, null, longOut, null);
-                long shared = longOut[0] * ProcessList.PAGE_SIZE / 1024;
-                longOut[0] = 0;
-                Process.readProcFile("/sys/kernel/mm/ksm/pages_sharing",
-                        SINGLE_LONG_FORMAT, null, longOut, null);
-                long sharing = longOut[0] * ProcessList.PAGE_SIZE / 1024;
-                longOut[0] = 0;
-                Process.readProcFile("/sys/kernel/mm/ksm/pages_unshared",
-                        SINGLE_LONG_FORMAT, null, longOut, null);
-                long unshared = longOut[0] * ProcessList.PAGE_SIZE / 1024;
-                longOut[0] = 0;
-                Process.readProcFile("/sys/kernel/mm/ksm/pages_volatile",
-                        SINGLE_LONG_FORMAT, null, longOut, null);
-                long voltile = longOut[0] * ProcessList.PAGE_SIZE / 1024;
-                if (!isCompact) {
-                    if (sharing != 0 || shared != 0 || unshared != 0 || voltile != 0) {
-                        pw.print("      KSM: "); pw.print(sharing);
-                                pw.print(" kB saved from shared ");
-                                pw.print(shared); pw.println(" kB");
-                        pw.print("           "); pw.print(unshared); pw.print(" kB unshared; ");
-                                pw.print(voltile); pw.println(" kB volatile");
-                    }
-                    pw.print("   Tuning: ");
-                    pw.print(ActivityManager.staticGetMemoryClass());
-                    pw.print(" (large ");
-                    pw.print(ActivityManager.staticGetLargeMemoryClass());
-                    pw.print("), oom ");
-                    pw.print(mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024);
-                    pw.print(" kB");
-                    pw.print(", restore limit ");
-                    pw.print(mProcessList.getCachedRestoreThresholdKb());
-                    pw.print(" kB");
-                    if (ActivityManager.isLowRamDeviceStatic()) {
-                        pw.print(" (low-ram)");
-                    }
-                    if (ActivityManager.isHighEndGfx()) {
-                        pw.print(" (high-end-gfx)");
-                    }
-                    pw.println();
-                } else {
-                    pw.print("ksm,"); pw.print(sharing); pw.print(",");
-                    pw.print(shared); pw.print(","); pw.print(unshared); pw.print(",");
-                    pw.println(voltile);
-                    pw.print("tuning,");
-                    pw.print(ActivityManager.staticGetMemoryClass());
-                    pw.print(',');
-                    pw.print(ActivityManager.staticGetLargeMemoryClass());
-                    pw.print(',');
-                    pw.print(mProcessList.getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024);
-                    if (ActivityManager.isLowRamDeviceStatic()) {
-                        pw.print(",low-ram");
-                    }
-                    if (ActivityManager.isHighEndGfx()) {
-                        pw.print(",high-end-gfx");
-                    }
-                    pw.println();
-                }
-            }
-        }
-    }
-
-    /**
-     * Searches array of arguments for the specified string
-     * @param args array of argument strings
-     * @param value value to search for
-     * @return true if the value is contained in the array
-     */
-    private static boolean scanArgs(String[] args, String value) {
-        if (args != null) {
-            for (String arg : args) {
-                if (value.equals(arg)) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    private final boolean removeDyingProviderLocked(ProcessRecord proc,
-            ContentProviderRecord cpr, boolean always) {
-        final boolean inLaunching = mLaunchingProviders.contains(cpr);
-
-        if (!inLaunching || always) {
-            synchronized (cpr) {
-                cpr.launchingApp = null;
-                cpr.notifyAll();
-            }
-            mProviderMap.removeProviderByClass(cpr.name, UserHandle.getUserId(cpr.uid));
-            String names[] = cpr.info.authority.split(";");
-            for (int j = 0; j < names.length; j++) {
-                mProviderMap.removeProviderByName(names[j], UserHandle.getUserId(cpr.uid));
-            }
-        }
-
-        for (int i=0; i<cpr.connections.size(); i++) {
-            ContentProviderConnection conn = cpr.connections.get(i);
-            if (conn.waiting) {
-                // If this connection is waiting for the provider, then we don't
-                // need to mess with its process unless we are always removing
-                // or for some reason the provider is not currently launching.
-                if (inLaunching && !always) {
-                    continue;
-                }
-            }
-            ProcessRecord capp = conn.client;
-            conn.dead = true;
-            if (conn.stableCount > 0) {
-                if (!capp.persistent && capp.thread != null
-                        && capp.pid != 0
-                        && capp.pid != MY_PID) {
-                    killUnneededProcessLocked(capp, "depends on provider "
-                            + cpr.name.flattenToShortString()
-                            + " in dying proc " + (proc != null ? proc.processName : "??"));
-                }
-            } else if (capp.thread != null && conn.provider.provider != null) {
-                try {
-                    capp.thread.unstableProviderDied(conn.provider.provider.asBinder());
-                } catch (RemoteException e) {
-                }
-                // In the protocol here, we don't expect the client to correctly
-                // clean up this connection, we'll just remove it.
-                cpr.connections.remove(i);
-                conn.client.conProviders.remove(conn);
-            }
-        }
-
-        if (inLaunching && always) {
-            mLaunchingProviders.remove(cpr);
-        }
-        return inLaunching;
-    }
-
-    /**
-     * Main code for cleaning up a process when it has gone away.  This is
-     * called both as a result of the process dying, or directly when stopping
-     * a process when running in single process mode.
-     */
-    private final void cleanUpApplicationRecordLocked(ProcessRecord app,
-            boolean restarting, boolean allowRestart, int index) {
-        if (index >= 0) {
-            removeLruProcessLocked(app);
-        }
-
-        mProcessesToGc.remove(app);
-        mPendingPssProcesses.remove(app);
-
-        // Dismiss any open dialogs.
-        if (app.crashDialog != null && !app.forceCrashReport) {
-            app.crashDialog.dismiss();
-            app.crashDialog = null;
-        }
-        if (app.anrDialog != null) {
-            app.anrDialog.dismiss();
-            app.anrDialog = null;
-        }
-        if (app.waitDialog != null) {
-            app.waitDialog.dismiss();
-            app.waitDialog = null;
-        }
-
-        app.crashing = false;
-        app.notResponding = false;
-
-        app.resetPackageList(mProcessStats);
-        app.unlinkDeathRecipient();
-        app.makeInactive(mProcessStats);
-        app.forcingToForeground = null;
-        app.foregroundServices = false;
-        app.foregroundActivities = false;
-        app.hasShownUi = false;
-        app.hasAboveClient = false;
-
-        mServices.killServicesLocked(app, allowRestart);
-
-        boolean restart = false;
-
-        // Remove published content providers.
-        for (int i=app.pubProviders.size()-1; i>=0; i--) {
-            ContentProviderRecord cpr = app.pubProviders.valueAt(i);
-            final boolean always = app.bad || !allowRestart;
-            if (removeDyingProviderLocked(app, cpr, always) || always) {
-                // We left the provider in the launching list, need to
-                // restart it.
-                restart = true;
-            }
-
-            cpr.provider = null;
-            cpr.proc = null;
-        }
-        app.pubProviders.clear();
-
-        // Take care of any launching providers waiting for this process.
-        if (checkAppInLaunchingProvidersLocked(app, false)) {
-            restart = true;
-        }
-
-        // Unregister from connected content providers.
-        if (!app.conProviders.isEmpty()) {
-            for (int i=0; i<app.conProviders.size(); i++) {
-                ContentProviderConnection conn = app.conProviders.get(i);
-                conn.provider.connections.remove(conn);
-            }
-            app.conProviders.clear();
-        }
-
-        // At this point there may be remaining entries in mLaunchingProviders
-        // where we were the only one waiting, so they are no longer of use.
-        // Look for these and clean up if found.
-        // XXX Commented out for now.  Trying to figure out a way to reproduce
-        // the actual situation to identify what is actually going on.
-        if (false) {
-            for (int i=0; i<mLaunchingProviders.size(); i++) {
-                ContentProviderRecord cpr = (ContentProviderRecord)
-                        mLaunchingProviders.get(i);
-                if (cpr.connections.size() <= 0 && !cpr.hasExternalProcessHandles()) {
-                    synchronized (cpr) {
-                        cpr.launchingApp = null;
-                        cpr.notifyAll();
-                    }
-                }
-            }
-        }
-
-        skipCurrentReceiverLocked(app);
-
-        // Unregister any receivers.
-        for (int i=app.receivers.size()-1; i>=0; i--) {
-            removeReceiverLocked(app.receivers.valueAt(i));
-        }
-        app.receivers.clear();
-
-        // If the app is undergoing backup, tell the backup manager about it
-        if (mBackupTarget != null && app.pid == mBackupTarget.app.pid) {
-            if (DEBUG_BACKUP || DEBUG_CLEANUP) Slog.d(TAG, "App "
-                    + mBackupTarget.appInfo + " died during backup");
-            try {
-                IBackupManager bm = IBackupManager.Stub.asInterface(
-                        ServiceManager.getService(Context.BACKUP_SERVICE));
-                bm.agentDisconnected(app.info.packageName);
-            } catch (RemoteException e) {
-                // can't happen; backup manager is local
-            }
-        }
-
-        for (int i = mPendingProcessChanges.size()-1; i>=0; i--) {
-            ProcessChangeItem item = mPendingProcessChanges.get(i);
-            if (item.pid == app.pid) {
-                mPendingProcessChanges.remove(i);
-                mAvailProcessChanges.add(item);
-            }
-        }
-        mHandler.obtainMessage(DISPATCH_PROCESS_DIED, app.pid, app.info.uid, null).sendToTarget();
-
-        // If the caller is restarting this app, then leave it in its
-        // current lists and let the caller take care of it.
-        if (restarting) {
-            return;
-        }
-
-        if (!app.persistent || app.isolated) {
-            if (DEBUG_PROCESSES || DEBUG_CLEANUP) Slog.v(TAG,
-                    "Removing non-persistent process during cleanup: " + app);
-            mProcessNames.remove(app.processName, app.uid);
-            mIsolatedProcesses.remove(app.uid);
-            if (mHeavyWeightProcess == app) {
-                mHandler.sendMessage(mHandler.obtainMessage(CANCEL_HEAVY_NOTIFICATION_MSG,
-                        mHeavyWeightProcess.userId, 0));
-                mHeavyWeightProcess = null;
-            }
-        } else if (!app.removed) {
-            // This app is persistent, so we need to keep its record around.
-            // If it is not already on the pending app list, add it there
-            // and start a new process for it.
-            if (mPersistentStartingProcesses.indexOf(app) < 0) {
-                mPersistentStartingProcesses.add(app);
-                restart = true;
-            }
-        }
-        if ((DEBUG_PROCESSES || DEBUG_CLEANUP) && mProcessesOnHold.contains(app)) Slog.v(TAG,
-                "Clean-up removing on hold: " + app);
-        mProcessesOnHold.remove(app);
-
-        if (app == mHomeProcess) {
-            mHomeProcess = null;
-        }
-        if (app == mPreviousProcess) {
-            mPreviousProcess = null;
-        }
-
-        if (restart && !app.isolated) {
-            // We have components that still need to be running in the
-            // process, so re-launch it.
-            mProcessNames.put(app.processName, app.uid, app);
-            startProcessLocked(app, "restart", app.processName);
-        } else if (app.pid > 0 && app.pid != MY_PID) {
-            // Goodbye!
-            synchronized (mPidsSelfLocked) {
-                mPidsSelfLocked.remove(app.pid);
-                mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
-            }
-            app.setPid(0);
-        }
-    }
-
-    boolean checkAppInLaunchingProvidersLocked(ProcessRecord app, boolean alwaysBad) {
-        // Look through the content providers we are waiting to have launched,
-        // and if any run in this process then either schedule a restart of
-        // the process or kill the client waiting for it if this process has
-        // gone bad.
-        int NL = mLaunchingProviders.size();
-        boolean restart = false;
-        for (int i=0; i<NL; i++) {
-            ContentProviderRecord cpr = mLaunchingProviders.get(i);
-            if (cpr.launchingApp == app) {
-                if (!alwaysBad && !app.bad) {
-                    restart = true;
-                } else {
-                    removeDyingProviderLocked(app, cpr, true);
-                    // cpr should have been removed from mLaunchingProviders
-                    NL = mLaunchingProviders.size();
-                    i--;
-                }
-            }
-        }
-        return restart;
-    }
-    
-    // =========================================================
-    // SERVICES
-    // =========================================================
-
-    public List<ActivityManager.RunningServiceInfo> getServices(int maxNum,
-            int flags) {
-        enforceNotIsolatedCaller("getServices");
-        synchronized (this) {
-            return mServices.getRunningServiceInfoLocked(maxNum, flags);
-        }
-    }
-
-    public PendingIntent getRunningServiceControlPanel(ComponentName name) {
-        enforceNotIsolatedCaller("getRunningServiceControlPanel");
-        synchronized (this) {
-            return mServices.getRunningServiceControlPanelLocked(name);
-        }
-    }
-    
-    public ComponentName startService(IApplicationThread caller, Intent service,
-            String resolvedType, int userId) {
-        enforceNotIsolatedCaller("startService");
-        // Refuse possible leaked file descriptors
-        if (service != null && service.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        if (DEBUG_SERVICE)
-            Slog.v(TAG, "startService: " + service + " type=" + resolvedType);
-        synchronized(this) {
-            final int callingPid = Binder.getCallingPid();
-            final int callingUid = Binder.getCallingUid();
-            final long origId = Binder.clearCallingIdentity();
-            ComponentName res = mServices.startServiceLocked(caller, service,
-                    resolvedType, callingPid, callingUid, userId);
-            Binder.restoreCallingIdentity(origId);
-            return res;
-        }
-    }
-
-    ComponentName startServiceInPackage(int uid,
-            Intent service, String resolvedType, int userId) {
-        synchronized(this) {
-            if (DEBUG_SERVICE)
-                Slog.v(TAG, "startServiceInPackage: " + service + " type=" + resolvedType);
-            final long origId = Binder.clearCallingIdentity();
-            ComponentName res = mServices.startServiceLocked(null, service,
-                    resolvedType, -1, uid, userId);
-            Binder.restoreCallingIdentity(origId);
-            return res;
-        }
-    }
-
-    public int stopService(IApplicationThread caller, Intent service,
-            String resolvedType, int userId) {
-        enforceNotIsolatedCaller("stopService");
-        // Refuse possible leaked file descriptors
-        if (service != null && service.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized(this) {
-            return mServices.stopServiceLocked(caller, service, resolvedType, userId);
-        }
-    }
-
-    public IBinder peekService(Intent service, String resolvedType) {
-        enforceNotIsolatedCaller("peekService");
-        // Refuse possible leaked file descriptors
-        if (service != null && service.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-        synchronized(this) {
-            return mServices.peekServiceLocked(service, resolvedType);
-        }
-    }
-    
-    public boolean stopServiceToken(ComponentName className, IBinder token,
-            int startId) {
-        synchronized(this) {
-            return mServices.stopServiceTokenLocked(className, token, startId);
-        }
-    }
-
-    public void setServiceForeground(ComponentName className, IBinder token,
-            int id, Notification notification, boolean removeNotification) {
-        synchronized(this) {
-            mServices.setServiceForegroundLocked(className, token, id, notification,
-                    removeNotification);
-        }
-    }
-
-    public int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll,
-            boolean requireFull, String name, String callerPackage) {
-        final int callingUserId = UserHandle.getUserId(callingUid);
-        if (callingUserId != userId) {
-            if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
-                if ((requireFull || checkComponentPermission(
-                        android.Manifest.permission.INTERACT_ACROSS_USERS,
-                        callingPid, callingUid, -1, true) != PackageManager.PERMISSION_GRANTED)
-                        && checkComponentPermission(
-                                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                                callingPid, callingUid, -1, true)
-                                != PackageManager.PERMISSION_GRANTED) {
-                    if (userId == UserHandle.USER_CURRENT_OR_SELF) {
-                        // In this case, they would like to just execute as their
-                        // owner user instead of failing.
-                        userId = callingUserId;
-                    } else {
-                        StringBuilder builder = new StringBuilder(128);
-                        builder.append("Permission Denial: ");
-                        builder.append(name);
-                        if (callerPackage != null) {
-                            builder.append(" from ");
-                            builder.append(callerPackage);
-                        }
-                        builder.append(" asks to run as user ");
-                        builder.append(userId);
-                        builder.append(" but is calling from user ");
-                        builder.append(UserHandle.getUserId(callingUid));
-                        builder.append("; this requires ");
-                        builder.append(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL);
-                        if (!requireFull) {
-                            builder.append(" or ");
-                            builder.append(android.Manifest.permission.INTERACT_ACROSS_USERS);
-                        }
-                        String msg = builder.toString();
-                        Slog.w(TAG, msg);
-                        throw new SecurityException(msg);
-                    }
-                }
-            }
-            if (userId == UserHandle.USER_CURRENT
-                    || userId == UserHandle.USER_CURRENT_OR_SELF) {
-                // Note that we may be accessing this outside of a lock...
-                // shouldn't be a big deal, if this is being called outside
-                // of a locked context there is intrinsically a race with
-                // the value the caller will receive and someone else changing it.
-                userId = mCurrentUserId;
-            }
-            if (!allowAll && userId < 0) {
-                throw new IllegalArgumentException(
-                        "Call does not support special user #" + userId);
-            }
-        }
-        return userId;
-    }
-
-    boolean isSingleton(String componentProcessName, ApplicationInfo aInfo,
-            String className, int flags) {
-        boolean result = false;
-        if (UserHandle.getAppId(aInfo.uid) >= Process.FIRST_APPLICATION_UID) {
-            if ((flags&ServiceInfo.FLAG_SINGLE_USER) != 0) {
-                if (ActivityManager.checkUidPermission(
-                        android.Manifest.permission.INTERACT_ACROSS_USERS,
-                        aInfo.uid) != PackageManager.PERMISSION_GRANTED) {
-                    ComponentName comp = new ComponentName(aInfo.packageName, className);
-                    String msg = "Permission Denial: Component " + comp.flattenToShortString()
-                            + " requests FLAG_SINGLE_USER, but app does not hold "
-                            + android.Manifest.permission.INTERACT_ACROSS_USERS;
-                    Slog.w(TAG, msg);
-                    throw new SecurityException(msg);
-                }
-                result = true;
-            }
-        } else if (componentProcessName == aInfo.packageName) {
-            result = (aInfo.flags & ApplicationInfo.FLAG_PERSISTENT) != 0;
-        } else if ("system".equals(componentProcessName)) {
-            result = true;
-        }
-        if (DEBUG_MU) {
-            Slog.v(TAG, "isSingleton(" + componentProcessName + ", " + aInfo
-                    + ", " + className + ", 0x" + Integer.toHexString(flags) + ") = " + result);
-        }
-        return result;
-    }
-
-    public int bindService(IApplicationThread caller, IBinder token,
-            Intent service, String resolvedType,
-            IServiceConnection connection, int flags, int userId) {
-        enforceNotIsolatedCaller("bindService");
-        // Refuse possible leaked file descriptors
-        if (service != null && service.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized(this) {
-            return mServices.bindServiceLocked(caller, token, service, resolvedType,
-                    connection, flags, userId);
-        }
-    }
-
-    public boolean unbindService(IServiceConnection connection) {
-        synchronized (this) {
-            return mServices.unbindServiceLocked(connection);
-        }
-    }
-
-    public void publishService(IBinder token, Intent intent, IBinder service) {
-        // Refuse possible leaked file descriptors
-        if (intent != null && intent.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized(this) {
-            if (!(token instanceof ServiceRecord)) {
-                throw new IllegalArgumentException("Invalid service token");
-            }
-            mServices.publishServiceLocked((ServiceRecord)token, intent, service);
-        }
-    }
-
-    public void unbindFinished(IBinder token, Intent intent, boolean doRebind) {
-        // Refuse possible leaked file descriptors
-        if (intent != null && intent.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized(this) {
-            mServices.unbindFinishedLocked((ServiceRecord)token, intent, doRebind);
-        }
-    }
-
-    public void serviceDoneExecuting(IBinder token, int type, int startId, int res) {
-        synchronized(this) {
-            if (!(token instanceof ServiceRecord)) {
-                throw new IllegalArgumentException("Invalid service token");
-            }
-            mServices.serviceDoneExecutingLocked((ServiceRecord)token, type, startId, res);
-        }
-    }
-    
-    // =========================================================
-    // BACKUP AND RESTORE
-    // =========================================================
-    
-    // Cause the target app to be launched if necessary and its backup agent
-    // instantiated.  The backup agent will invoke backupAgentCreated() on the
-    // activity manager to announce its creation.
-    public boolean bindBackupAgent(ApplicationInfo app, int backupMode) {
-        if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent: app=" + app + " mode=" + backupMode);
-        enforceCallingPermission("android.permission.BACKUP", "bindBackupAgent");
-
-        synchronized(this) {
-            // !!! TODO: currently no check here that we're already bound
-            BatteryStatsImpl.Uid.Pkg.Serv ss = null;
-            BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-            synchronized (stats) {
-                ss = stats.getServiceStatsLocked(app.uid, app.packageName, app.name);
-            }
-
-            // Backup agent is now in use, its package can't be stopped.
-            try {
-                AppGlobals.getPackageManager().setPackageStoppedState(
-                        app.packageName, false, UserHandle.getUserId(app.uid));
-            } catch (RemoteException e) {
-            } catch (IllegalArgumentException e) {
-                Slog.w(TAG, "Failed trying to unstop package "
-                        + app.packageName + ": " + e);
-            }
-
-            BackupRecord r = new BackupRecord(ss, app, backupMode);
-            ComponentName hostingName = (backupMode == IApplicationThread.BACKUP_MODE_INCREMENTAL)
-                    ? new ComponentName(app.packageName, app.backupAgentName)
-                    : new ComponentName("android", "FullBackupAgent");
-            // startProcessLocked() returns existing proc's record if it's already running
-            ProcessRecord proc = startProcessLocked(app.processName, app,
-                    false, 0, "backup", hostingName, false, false, false);
-            if (proc == null) {
-                Slog.e(TAG, "Unable to start backup agent process " + r);
-                return false;
-            }
-
-            r.app = proc;
-            mBackupTarget = r;
-            mBackupAppName = app.packageName;
-
-            // Try not to kill the process during backup
-            updateOomAdjLocked(proc);
-
-            // If the process is already attached, schedule the creation of the backup agent now.
-            // If it is not yet live, this will be done when it attaches to the framework.
-            if (proc.thread != null) {
-                if (DEBUG_BACKUP) Slog.v(TAG, "Agent proc already running: " + proc);
-                try {
-                    proc.thread.scheduleCreateBackupAgent(app,
-                            compatibilityInfoForPackageLocked(app), backupMode);
-                } catch (RemoteException e) {
-                    // Will time out on the backup manager side
-                }
-            } else {
-                if (DEBUG_BACKUP) Slog.v(TAG, "Agent proc not running, waiting for attach");
-            }
-            // Invariants: at this point, the target app process exists and the application
-            // is either already running or in the process of coming up.  mBackupTarget and
-            // mBackupAppName describe the app, so that when it binds back to the AM we
-            // know that it's scheduled for a backup-agent operation.
-        }
-        
-        return true;
-    }
-
-    @Override
-    public void clearPendingBackup() {
-        if (DEBUG_BACKUP) Slog.v(TAG, "clearPendingBackup");
-        enforceCallingPermission("android.permission.BACKUP", "clearPendingBackup");
-
-        synchronized (this) {
-            mBackupTarget = null;
-            mBackupAppName = null;
-        }
-    }
-
-    // A backup agent has just come up                    
-    public void backupAgentCreated(String agentPackageName, IBinder agent) {
-        if (DEBUG_BACKUP) Slog.v(TAG, "backupAgentCreated: " + agentPackageName
-                + " = " + agent);
-
-        synchronized(this) {
-            if (!agentPackageName.equals(mBackupAppName)) {
-                Slog.e(TAG, "Backup agent created for " + agentPackageName + " but not requested!");
-                return;
-            }
-        }
-
-        long oldIdent = Binder.clearCallingIdentity();
-        try {
-            IBackupManager bm = IBackupManager.Stub.asInterface(
-                    ServiceManager.getService(Context.BACKUP_SERVICE));
-            bm.agentConnected(agentPackageName, agent);
-        } catch (RemoteException e) {
-            // can't happen; the backup manager service is local
-        } catch (Exception e) {
-            Slog.w(TAG, "Exception trying to deliver BackupAgent binding: ");
-            e.printStackTrace();
-        } finally {
-            Binder.restoreCallingIdentity(oldIdent);
-        }
-    }
-
-    // done with this agent
-    public void unbindBackupAgent(ApplicationInfo appInfo) {
-        if (DEBUG_BACKUP) Slog.v(TAG, "unbindBackupAgent: " + appInfo);
-        if (appInfo == null) {
-            Slog.w(TAG, "unbind backup agent for null app");
-            return;
-        }
-
-        synchronized(this) {
-            try {
-                if (mBackupAppName == null) {
-                    Slog.w(TAG, "Unbinding backup agent with no active backup");
-                    return;
-                }
-
-                if (!mBackupAppName.equals(appInfo.packageName)) {
-                    Slog.e(TAG, "Unbind of " + appInfo + " but is not the current backup target");
-                    return;
-                }
-
-                // Not backing this app up any more; reset its OOM adjustment
-                final ProcessRecord proc = mBackupTarget.app;
-                updateOomAdjLocked(proc);
-
-                // If the app crashed during backup, 'thread' will be null here
-                if (proc.thread != null) {
-                    try {
-                        proc.thread.scheduleDestroyBackupAgent(appInfo,
-                                compatibilityInfoForPackageLocked(appInfo));
-                    } catch (Exception e) {
-                        Slog.e(TAG, "Exception when unbinding backup agent:");
-                        e.printStackTrace();
-                    }
-                }
-            } finally {
-                mBackupTarget = null;
-                mBackupAppName = null;
-            }
-        }
-    }
-    // =========================================================
-    // BROADCASTS
-    // =========================================================
-
-    private final List getStickiesLocked(String action, IntentFilter filter,
-            List cur, int userId) {
-        final ContentResolver resolver = mContext.getContentResolver();
-        ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
-        if (stickies == null) {
-            return cur;
-        }
-        final ArrayList<Intent> list = stickies.get(action);
-        if (list == null) {
-            return cur;
-        }
-        int N = list.size();
-        for (int i=0; i<N; i++) {
-            Intent intent = list.get(i);
-            if (filter.match(resolver, intent, true, TAG) >= 0) {
-                if (cur == null) {
-                    cur = new ArrayList<Intent>();
-                }
-                cur.add(intent);
-            }
-        }
-        return cur;
-    }
-
-    boolean isPendingBroadcastProcessLocked(int pid) {
-        return mFgBroadcastQueue.isPendingBroadcastProcessLocked(pid)
-                || mBgBroadcastQueue.isPendingBroadcastProcessLocked(pid);
-    }
-
-    void skipPendingBroadcastLocked(int pid) {
-            Slog.w(TAG, "Unattached app died before broadcast acknowledged, skipping");
-            for (BroadcastQueue queue : mBroadcastQueues) {
-                queue.skipPendingBroadcastLocked(pid);
-            }
-    }
-
-    // The app just attached; send any pending broadcasts that it should receive
-    boolean sendPendingBroadcastsLocked(ProcessRecord app) {
-        boolean didSomething = false;
-        for (BroadcastQueue queue : mBroadcastQueues) {
-            didSomething |= queue.sendPendingBroadcastsLocked(app);
-        }
-        return didSomething;
-    }
-
-    public Intent registerReceiver(IApplicationThread caller, String callerPackage,
-            IIntentReceiver receiver, IntentFilter filter, String permission, int userId) {
-        enforceNotIsolatedCaller("registerReceiver");
-        int callingUid;
-        int callingPid;
-        synchronized(this) {
-            ProcessRecord callerApp = null;
-            if (caller != null) {
-                callerApp = getRecordForAppLocked(caller);
-                if (callerApp == null) {
-                    throw new SecurityException(
-                            "Unable to find app for caller " + caller
-                            + " (pid=" + Binder.getCallingPid()
-                            + ") when registering receiver " + receiver);
-                }
-                if (callerApp.info.uid != Process.SYSTEM_UID &&
-                        !callerApp.pkgList.containsKey(callerPackage) &&
-                        !"android".equals(callerPackage)) {
-                    throw new SecurityException("Given caller package " + callerPackage
-                            + " is not running in process " + callerApp);
-                }
-                callingUid = callerApp.info.uid;
-                callingPid = callerApp.pid;
-            } else {
-                callerPackage = null;
-                callingUid = Binder.getCallingUid();
-                callingPid = Binder.getCallingPid();
-            }
-
-            userId = this.handleIncomingUser(callingPid, callingUid, userId,
-                    true, true, "registerReceiver", callerPackage);
-
-            List allSticky = null;
-
-            // Look for any matching sticky broadcasts...
-            Iterator actions = filter.actionsIterator();
-            if (actions != null) {
-                while (actions.hasNext()) {
-                    String action = (String)actions.next();
-                    allSticky = getStickiesLocked(action, filter, allSticky,
-                            UserHandle.USER_ALL);
-                    allSticky = getStickiesLocked(action, filter, allSticky,
-                            UserHandle.getUserId(callingUid));
-                }
-            } else {
-                allSticky = getStickiesLocked(null, filter, allSticky,
-                        UserHandle.USER_ALL);
-                allSticky = getStickiesLocked(null, filter, allSticky,
-                        UserHandle.getUserId(callingUid));
-            }
-
-            // The first sticky in the list is returned directly back to
-            // the client.
-            Intent sticky = allSticky != null ? (Intent)allSticky.get(0) : null;
-
-            if (DEBUG_BROADCAST) Slog.v(TAG, "Register receiver " + filter
-                    + ": " + sticky);
-
-            if (receiver == null) {
-                return sticky;
-            }
-
-            ReceiverList rl
-                = (ReceiverList)mRegisteredReceivers.get(receiver.asBinder());
-            if (rl == null) {
-                rl = new ReceiverList(this, callerApp, callingPid, callingUid,
-                        userId, receiver);
-                if (rl.app != null) {
-                    rl.app.receivers.add(rl);
-                } else {
-                    try {
-                        receiver.asBinder().linkToDeath(rl, 0);
-                    } catch (RemoteException e) {
-                        return sticky;
-                    }
-                    rl.linkedToDeath = true;
-                }
-                mRegisteredReceivers.put(receiver.asBinder(), rl);
-            } else if (rl.uid != callingUid) {
-                throw new IllegalArgumentException(
-                        "Receiver requested to register for uid " + callingUid
-                        + " was previously registered for uid " + rl.uid);
-            } else if (rl.pid != callingPid) {
-                throw new IllegalArgumentException(
-                        "Receiver requested to register for pid " + callingPid
-                        + " was previously registered for pid " + rl.pid);
-            } else if (rl.userId != userId) {
-                throw new IllegalArgumentException(
-                        "Receiver requested to register for user " + userId
-                        + " was previously registered for user " + rl.userId);
-            }
-            BroadcastFilter bf = new BroadcastFilter(filter, rl, callerPackage,
-                    permission, callingUid, userId);
-            rl.add(bf);
-            if (!bf.debugCheck()) {
-                Slog.w(TAG, "==> For Dynamic broadast");
-            }
-            mReceiverResolver.addFilter(bf);
-
-            // Enqueue broadcasts for all existing stickies that match
-            // this filter.
-            if (allSticky != null) {
-                ArrayList receivers = new ArrayList();
-                receivers.add(bf);
-
-                int N = allSticky.size();
-                for (int i=0; i<N; i++) {
-                    Intent intent = (Intent)allSticky.get(i);
-                    BroadcastQueue queue = broadcastQueueForIntent(intent);
-                    BroadcastRecord r = new BroadcastRecord(queue, intent, null,
-                            null, -1, -1, null, null, AppOpsManager.OP_NONE, receivers, null, 0,
-                            null, null, false, true, true, -1);
-                    queue.enqueueParallelBroadcastLocked(r);
-                    queue.scheduleBroadcastsLocked();
-                }
-            }
-
-            return sticky;
-        }
-    }
-
-    public void unregisterReceiver(IIntentReceiver receiver) {
-        if (DEBUG_BROADCAST) Slog.v(TAG, "Unregister receiver: " + receiver);
-
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            boolean doTrim = false;
-
-            synchronized(this) {
-                ReceiverList rl = mRegisteredReceivers.get(receiver.asBinder());
-                if (rl != null) {
-                    if (rl.curBroadcast != null) {
-                        BroadcastRecord r = rl.curBroadcast;
-                        final boolean doNext = finishReceiverLocked(
-                                receiver.asBinder(), r.resultCode, r.resultData,
-                                r.resultExtras, r.resultAbort);
-                        if (doNext) {
-                            doTrim = true;
-                            r.queue.processNextBroadcast(false);
-                        }
-                    }
-
-                    if (rl.app != null) {
-                        rl.app.receivers.remove(rl);
-                    }
-                    removeReceiverLocked(rl);
-                    if (rl.linkedToDeath) {
-                        rl.linkedToDeath = false;
-                        rl.receiver.asBinder().unlinkToDeath(rl, 0);
-                    }
-                }
-            }
-
-            // If we actually concluded any broadcasts, we might now be able
-            // to trim the recipients' apps from our working set
-            if (doTrim) {
-                trimApplications();
-                return;
-            }
-
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    void removeReceiverLocked(ReceiverList rl) {
-        mRegisteredReceivers.remove(rl.receiver.asBinder());
-        int N = rl.size();
-        for (int i=0; i<N; i++) {
-            mReceiverResolver.removeFilter(rl.get(i));
-        }
-    }
-    
-    private final void sendPackageBroadcastLocked(int cmd, String[] packages, int userId) {
-        for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
-            ProcessRecord r = mLruProcesses.get(i);
-            if (r.thread != null && (userId == UserHandle.USER_ALL || r.userId == userId)) {
-                try {
-                    r.thread.dispatchPackageBroadcast(cmd, packages);
-                } catch (RemoteException ex) {
-                }
-            }
-        }
-    }
-
-    private List<ResolveInfo> collectReceiverComponents(Intent intent, String resolvedType,
-            int[] users) {
-        List<ResolveInfo> receivers = null;
-        try {
-            HashSet<ComponentName> singleUserReceivers = null;
-            boolean scannedFirstReceivers = false;
-            for (int user : users) {
-                List<ResolveInfo> newReceivers = AppGlobals.getPackageManager()
-                        .queryIntentReceivers(intent, resolvedType, STOCK_PM_FLAGS, user);
-                if (user != 0 && newReceivers != null) {
-                    // If this is not the primary user, we need to check for
-                    // any receivers that should be filtered out.
-                    for (int i=0; i<newReceivers.size(); i++) {
-                        ResolveInfo ri = newReceivers.get(i);
-                        if ((ri.activityInfo.flags&ActivityInfo.FLAG_PRIMARY_USER_ONLY) != 0) {
-                            newReceivers.remove(i);
-                            i--;
-                        }
-                    }
-                }
-                if (newReceivers != null && newReceivers.size() == 0) {
-                    newReceivers = null;
-                }
-                if (receivers == null) {
-                    receivers = newReceivers;
-                } else if (newReceivers != null) {
-                    // We need to concatenate the additional receivers
-                    // found with what we have do far.  This would be easy,
-                    // but we also need to de-dup any receivers that are
-                    // singleUser.
-                    if (!scannedFirstReceivers) {
-                        // Collect any single user receivers we had already retrieved.
-                        scannedFirstReceivers = true;
-                        for (int i=0; i<receivers.size(); i++) {
-                            ResolveInfo ri = receivers.get(i);
-                            if ((ri.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) {
-                                ComponentName cn = new ComponentName(
-                                        ri.activityInfo.packageName, ri.activityInfo.name);
-                                if (singleUserReceivers == null) {
-                                    singleUserReceivers = new HashSet<ComponentName>();
-                                }
-                                singleUserReceivers.add(cn);
-                            }
-                        }
-                    }
-                    // Add the new results to the existing results, tracking
-                    // and de-dupping single user receivers.
-                    for (int i=0; i<newReceivers.size(); i++) {
-                        ResolveInfo ri = newReceivers.get(i);
-                        if ((ri.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) {
-                            ComponentName cn = new ComponentName(
-                                    ri.activityInfo.packageName, ri.activityInfo.name);
-                            if (singleUserReceivers == null) {
-                                singleUserReceivers = new HashSet<ComponentName>();
-                            }
-                            if (!singleUserReceivers.contains(cn)) {
-                                singleUserReceivers.add(cn);
-                                receivers.add(ri);
-                            }
-                        } else {
-                            receivers.add(ri);
-                        }
-                    }
-                }
-            }
-        } catch (RemoteException ex) {
-            // pm is in same process, this will never happen.
-        }
-        return receivers;
-    }
-
-    private final int broadcastIntentLocked(ProcessRecord callerApp,
-            String callerPackage, Intent intent, String resolvedType,
-            IIntentReceiver resultTo, int resultCode, String resultData,
-            Bundle map, String requiredPermission, int appOp,
-            boolean ordered, boolean sticky, int callingPid, int callingUid,
-            int userId) {
-        intent = new Intent(intent);
-
-        // By default broadcasts do not go to stopped apps.
-        intent.addFlags(Intent.FLAG_EXCLUDE_STOPPED_PACKAGES);
-
-        if (DEBUG_BROADCAST_LIGHT) Slog.v(
-            TAG, (sticky ? "Broadcast sticky: ": "Broadcast: ") + intent
-            + " ordered=" + ordered + " userid=" + userId);
-        if ((resultTo != null) && !ordered) {
-            Slog.w(TAG, "Broadcast " + intent + " not ordered but result callback requested!");
-        }
-
-        userId = handleIncomingUser(callingPid, callingUid, userId,
-                true, false, "broadcast", callerPackage);
-
-        // Make sure that the user who is receiving this broadcast is started.
-        // If not, we will just skip it.
-        if (userId != UserHandle.USER_ALL && mStartedUsers.get(userId) == null) {
-            if (callingUid != Process.SYSTEM_UID || (intent.getFlags()
-                    & Intent.FLAG_RECEIVER_BOOT_UPGRADE) == 0) {
-                Slog.w(TAG, "Skipping broadcast of " + intent
-                        + ": user " + userId + " is stopped");
-                return ActivityManager.BROADCAST_SUCCESS;
-            }
-        }
-
-        /*
-         * Prevent non-system code (defined here to be non-persistent
-         * processes) from sending protected broadcasts.
-         */
-        int callingAppId = UserHandle.getAppId(callingUid);
-        if (callingAppId == Process.SYSTEM_UID || callingAppId == Process.PHONE_UID
-            || callingAppId == Process.SHELL_UID || callingAppId == Process.BLUETOOTH_UID ||
-            callingUid == 0) {
-            // Always okay.
-        } else if (callerApp == null || !callerApp.persistent) {
-            try {
-                if (AppGlobals.getPackageManager().isProtectedBroadcast(
-                        intent.getAction())) {
-                    String msg = "Permission Denial: not allowed to send broadcast "
-                            + intent.getAction() + " from pid="
-                            + callingPid + ", uid=" + callingUid;
-                    Slog.w(TAG, msg);
-                    throw new SecurityException(msg);
-                } else if (AppWidgetManager.ACTION_APPWIDGET_CONFIGURE.equals(intent.getAction())) {
-                    // Special case for compatibility: we don't want apps to send this,
-                    // but historically it has not been protected and apps may be using it
-                    // to poke their own app widget.  So, instead of making it protected,
-                    // just limit it to the caller.
-                    if (callerApp == null) {
-                        String msg = "Permission Denial: not allowed to send broadcast "
-                                + intent.getAction() + " from unknown caller.";
-                        Slog.w(TAG, msg);
-                        throw new SecurityException(msg);
-                    } else if (intent.getComponent() != null) {
-                        // They are good enough to send to an explicit component...  verify
-                        // it is being sent to the calling app.
-                        if (!intent.getComponent().getPackageName().equals(
-                                callerApp.info.packageName)) {
-                            String msg = "Permission Denial: not allowed to send broadcast "
-                                    + intent.getAction() + " to "
-                                    + intent.getComponent().getPackageName() + " from "
-                                    + callerApp.info.packageName;
-                            Slog.w(TAG, msg);
-                            throw new SecurityException(msg);
-                        }
-                    } else {
-                        // Limit broadcast to their own package.
-                        intent.setPackage(callerApp.info.packageName);
-                    }
-                }
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Remote exception", e);
-                return ActivityManager.BROADCAST_SUCCESS;
-            }
-        }
-
-        // Handle special intents: if this broadcast is from the package
-        // manager about a package being removed, we need to remove all of
-        // its activities from the history stack.
-        final boolean uidRemoved = Intent.ACTION_UID_REMOVED.equals(
-                intent.getAction());
-        if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())
-                || Intent.ACTION_PACKAGE_CHANGED.equals(intent.getAction())
-                || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(intent.getAction())
-                || uidRemoved) {
-            if (checkComponentPermission(
-                    android.Manifest.permission.BROADCAST_PACKAGE_REMOVED,
-                    callingPid, callingUid, -1, true)
-                    == PackageManager.PERMISSION_GRANTED) {
-                if (uidRemoved) {
-                    final Bundle intentExtras = intent.getExtras();
-                    final int uid = intentExtras != null
-                            ? intentExtras.getInt(Intent.EXTRA_UID) : -1;
-                    if (uid >= 0) {
-                        BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics();
-                        synchronized (bs) {
-                            bs.removeUidStatsLocked(uid);
-                        }
-                        mAppOpsService.uidRemoved(uid);
-                    }
-                } else {
-                    // If resources are unavailable just force stop all
-                    // those packages and flush the attribute cache as well.
-                    if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(intent.getAction())) {
-                        String list[] = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-                        if (list != null && (list.length > 0)) {
-                            for (String pkg : list) {
-                                forceStopPackageLocked(pkg, -1, false, true, true, false, false, userId,
-                                        "storage unmount");
-                            }
-                            sendPackageBroadcastLocked(
-                                    IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE, list, userId);
-                        }
-                    } else {
-                        Uri data = intent.getData();
-                        String ssp;
-                        if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
-                            boolean removed = Intent.ACTION_PACKAGE_REMOVED.equals(
-                                    intent.getAction());
-                            boolean fullUninstall = removed &&
-                                    !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
-                            if (!intent.getBooleanExtra(Intent.EXTRA_DONT_KILL_APP, false)) {
-                                forceStopPackageLocked(ssp, UserHandle.getAppId(
-                                        intent.getIntExtra(Intent.EXTRA_UID, -1)), false, true, true,
-                                        false, fullUninstall, userId,
-                                        removed ? "pkg removed" : "pkg changed");
-                            }
-                            if (removed) {
-                                sendPackageBroadcastLocked(IApplicationThread.PACKAGE_REMOVED,
-                                        new String[] {ssp}, userId);
-                                if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
-                                    mAppOpsService.packageRemoved(
-                                            intent.getIntExtra(Intent.EXTRA_UID, -1), ssp);
-
-                                    // Remove all permissions granted from/to this package
-                                    removeUriPermissionsForPackageLocked(ssp, userId, true);
-                                }
-                            }
-                        }
-                    }
-                }
-            } else {
-                String msg = "Permission Denial: " + intent.getAction()
-                        + " broadcast from " + callerPackage + " (pid=" + callingPid
-                        + ", uid=" + callingUid + ")"
-                        + " requires "
-                        + android.Manifest.permission.BROADCAST_PACKAGE_REMOVED;
-                Slog.w(TAG, msg);
-                throw new SecurityException(msg);
-            }
-
-        // Special case for adding a package: by default turn on compatibility
-        // mode.
-        } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) {
-            Uri data = intent.getData();
-            String ssp;
-            if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
-                mCompatModePackages.handlePackageAddedLocked(ssp,
-                        intent.getBooleanExtra(Intent.EXTRA_REPLACING, false));
-            }
-        }
-
-        /*
-         * If this is the time zone changed action, queue up a message that will reset the timezone
-         * of all currently running processes. This message will get queued up before the broadcast
-         * happens.
-         */
-        if (intent.ACTION_TIMEZONE_CHANGED.equals(intent.getAction())) {
-            mHandler.sendEmptyMessage(UPDATE_TIME_ZONE);
-        }
-
-        if (intent.ACTION_CLEAR_DNS_CACHE.equals(intent.getAction())) {
-            mHandler.sendEmptyMessage(CLEAR_DNS_CACHE_MSG);
-        }
-
-        if (Proxy.PROXY_CHANGE_ACTION.equals(intent.getAction())) {
-            ProxyProperties proxy = intent.getParcelableExtra("proxy");
-            mHandler.sendMessage(mHandler.obtainMessage(UPDATE_HTTP_PROXY_MSG, proxy));
-        }
-
-        // Add to the sticky list if requested.
-        if (sticky) {
-            if (checkPermission(android.Manifest.permission.BROADCAST_STICKY,
-                    callingPid, callingUid)
-                    != PackageManager.PERMISSION_GRANTED) {
-                String msg = "Permission Denial: broadcastIntent() requesting a sticky broadcast from pid="
-                        + callingPid + ", uid=" + callingUid
-                        + " requires " + android.Manifest.permission.BROADCAST_STICKY;
-                Slog.w(TAG, msg);
-                throw new SecurityException(msg);
-            }
-            if (requiredPermission != null) {
-                Slog.w(TAG, "Can't broadcast sticky intent " + intent
-                        + " and enforce permission " + requiredPermission);
-                return ActivityManager.BROADCAST_STICKY_CANT_HAVE_PERMISSION;
-            }
-            if (intent.getComponent() != null) {
-                throw new SecurityException(
-                        "Sticky broadcasts can't target a specific component");
-            }
-            // We use userId directly here, since the "all" target is maintained
-            // as a separate set of sticky broadcasts.
-            if (userId != UserHandle.USER_ALL) {
-                // But first, if this is not a broadcast to all users, then
-                // make sure it doesn't conflict with an existing broadcast to
-                // all users.
-                ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(
-                        UserHandle.USER_ALL);
-                if (stickies != null) {
-                    ArrayList<Intent> list = stickies.get(intent.getAction());
-                    if (list != null) {
-                        int N = list.size();
-                        int i;
-                        for (i=0; i<N; i++) {
-                            if (intent.filterEquals(list.get(i))) {
-                                throw new IllegalArgumentException(
-                                        "Sticky broadcast " + intent + " for user "
-                                        + userId + " conflicts with existing global broadcast");
-                            }
-                        }
-                    }
-                }
-            }
-            ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
-            if (stickies == null) {
-                stickies = new ArrayMap<String, ArrayList<Intent>>();
-                mStickyBroadcasts.put(userId, stickies);
-            }
-            ArrayList<Intent> list = stickies.get(intent.getAction());
-            if (list == null) {
-                list = new ArrayList<Intent>();
-                stickies.put(intent.getAction(), list);
-            }
-            int N = list.size();
-            int i;
-            for (i=0; i<N; i++) {
-                if (intent.filterEquals(list.get(i))) {
-                    // This sticky already exists, replace it.
-                    list.set(i, new Intent(intent));
-                    break;
-                }
-            }
-            if (i >= N) {
-                list.add(new Intent(intent));
-            }
-        }
-
-        int[] users;
-        if (userId == UserHandle.USER_ALL) {
-            // Caller wants broadcast to go to all started users.
-            users = mStartedUserArray;
-        } else {
-            // Caller wants broadcast to go to one specific user.
-            users = new int[] {userId};
-        }
-
-        // Figure out who all will receive this broadcast.
-        List receivers = null;
-        List<BroadcastFilter> registeredReceivers = null;
-        // Need to resolve the intent to interested receivers...
-        if ((intent.getFlags()&Intent.FLAG_RECEIVER_REGISTERED_ONLY)
-                 == 0) {
-            receivers = collectReceiverComponents(intent, resolvedType, users);
-        }
-        if (intent.getComponent() == null) {
-            registeredReceivers = mReceiverResolver.queryIntent(intent,
-                    resolvedType, false, userId);
-        }
-
-        final boolean replacePending =
-                (intent.getFlags()&Intent.FLAG_RECEIVER_REPLACE_PENDING) != 0;
-        
-        if (DEBUG_BROADCAST) Slog.v(TAG, "Enqueing broadcast: " + intent.getAction()
-                + " replacePending=" + replacePending);
-        
-        int NR = registeredReceivers != null ? registeredReceivers.size() : 0;
-        if (!ordered && NR > 0) {
-            // If we are not serializing this broadcast, then send the
-            // registered receivers separately so they don't wait for the
-            // components to be launched.
-            final BroadcastQueue queue = broadcastQueueForIntent(intent);
-            BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
-                    callerPackage, callingPid, callingUid, resolvedType, requiredPermission,
-                    appOp, registeredReceivers, resultTo, resultCode, resultData, map,
-                    ordered, sticky, false, userId);
-            if (DEBUG_BROADCAST) Slog.v(
-                    TAG, "Enqueueing parallel broadcast " + r);
-            final boolean replaced = replacePending && queue.replaceParallelBroadcastLocked(r);
-            if (!replaced) {
-                queue.enqueueParallelBroadcastLocked(r);
-                queue.scheduleBroadcastsLocked();
-            }
-            registeredReceivers = null;
-            NR = 0;
-        }
-
-        // Merge into one list.
-        int ir = 0;
-        if (receivers != null) {
-            // A special case for PACKAGE_ADDED: do not allow the package
-            // being added to see this broadcast.  This prevents them from
-            // using this as a back door to get run as soon as they are
-            // installed.  Maybe in the future we want to have a special install
-            // broadcast or such for apps, but we'd like to deliberately make
-            // this decision.
-            String skipPackages[] = null;
-            if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())
-                    || Intent.ACTION_PACKAGE_RESTARTED.equals(intent.getAction())
-                    || Intent.ACTION_PACKAGE_DATA_CLEARED.equals(intent.getAction())) {
-                Uri data = intent.getData();
-                if (data != null) {
-                    String pkgName = data.getSchemeSpecificPart();
-                    if (pkgName != null) {
-                        skipPackages = new String[] { pkgName };
-                    }
-                }
-            } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(intent.getAction())) {
-                skipPackages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
-            }
-            if (skipPackages != null && (skipPackages.length > 0)) {
-                for (String skipPackage : skipPackages) {
-                    if (skipPackage != null) {
-                        int NT = receivers.size();
-                        for (int it=0; it<NT; it++) {
-                            ResolveInfo curt = (ResolveInfo)receivers.get(it);
-                            if (curt.activityInfo.packageName.equals(skipPackage)) {
-                                receivers.remove(it);
-                                it--;
-                                NT--;
-                            }
-                        }
-                    }
-                }
-            }
-
-            int NT = receivers != null ? receivers.size() : 0;
-            int it = 0;
-            ResolveInfo curt = null;
-            BroadcastFilter curr = null;
-            while (it < NT && ir < NR) {
-                if (curt == null) {
-                    curt = (ResolveInfo)receivers.get(it);
-                }
-                if (curr == null) {
-                    curr = registeredReceivers.get(ir);
-                }
-                if (curr.getPriority() >= curt.priority) {
-                    // Insert this broadcast record into the final list.
-                    receivers.add(it, curr);
-                    ir++;
-                    curr = null;
-                    it++;
-                    NT++;
-                } else {
-                    // Skip to the next ResolveInfo in the final list.
-                    it++;
-                    curt = null;
-                }
-            }
-        }
-        while (ir < NR) {
-            if (receivers == null) {
-                receivers = new ArrayList();
-            }
-            receivers.add(registeredReceivers.get(ir));
-            ir++;
-        }
-
-        if ((receivers != null && receivers.size() > 0)
-                || resultTo != null) {
-            BroadcastQueue queue = broadcastQueueForIntent(intent);
-            BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp,
-                    callerPackage, callingPid, callingUid, resolvedType,
-                    requiredPermission, appOp, receivers, resultTo, resultCode,
-                    resultData, map, ordered, sticky, false, userId);
-            if (DEBUG_BROADCAST) Slog.v(
-                    TAG, "Enqueueing ordered broadcast " + r
-                    + ": prev had " + queue.mOrderedBroadcasts.size());
-            if (DEBUG_BROADCAST) {
-                int seq = r.intent.getIntExtra("seq", -1);
-                Slog.i(TAG, "Enqueueing broadcast " + r.intent.getAction() + " seq=" + seq);
-            }
-            boolean replaced = replacePending && queue.replaceOrderedBroadcastLocked(r); 
-            if (!replaced) {
-                queue.enqueueOrderedBroadcastLocked(r);
-                queue.scheduleBroadcastsLocked();
-            }
-        }
-
-        return ActivityManager.BROADCAST_SUCCESS;
-    }
-
-    final Intent verifyBroadcastLocked(Intent intent) {
-        // Refuse possible leaked file descriptors
-        if (intent != null && intent.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        int flags = intent.getFlags();
-
-        if (!mProcessesReady) {
-            // if the caller really truly claims to know what they're doing, go
-            // ahead and allow the broadcast without launching any receivers
-            if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT) != 0) {
-                intent = new Intent(intent);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-            } else if ((flags&Intent.FLAG_RECEIVER_REGISTERED_ONLY) == 0) {
-                Slog.e(TAG, "Attempt to launch receivers of broadcast intent " + intent
-                        + " before boot completion");
-                throw new IllegalStateException("Cannot broadcast before boot completed");
-            }
-        }
-
-        if ((flags&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0) {
-            throw new IllegalArgumentException(
-                    "Can't use FLAG_RECEIVER_BOOT_UPGRADE here");
-        }
-
-        return intent;
-    }
-
-    public final int broadcastIntent(IApplicationThread caller,
-            Intent intent, String resolvedType, IIntentReceiver resultTo,
-            int resultCode, String resultData, Bundle map,
-            String requiredPermission, int appOp, boolean serialized, boolean sticky, int userId) {
-        enforceNotIsolatedCaller("broadcastIntent");
-        synchronized(this) {
-            intent = verifyBroadcastLocked(intent);
-            
-            final ProcessRecord callerApp = getRecordForAppLocked(caller);
-            final int callingPid = Binder.getCallingPid();
-            final int callingUid = Binder.getCallingUid();
-            final long origId = Binder.clearCallingIdentity();
-            int res = broadcastIntentLocked(callerApp,
-                    callerApp != null ? callerApp.info.packageName : null,
-                    intent, resolvedType, resultTo,
-                    resultCode, resultData, map, requiredPermission, appOp, serialized, sticky,
-                    callingPid, callingUid, userId);
-            Binder.restoreCallingIdentity(origId);
-            return res;
-        }
-    }
-
-    int broadcastIntentInPackage(String packageName, int uid,
-            Intent intent, String resolvedType, IIntentReceiver resultTo,
-            int resultCode, String resultData, Bundle map,
-            String requiredPermission, boolean serialized, boolean sticky, int userId) {
-        synchronized(this) {
-            intent = verifyBroadcastLocked(intent);
-
-            final long origId = Binder.clearCallingIdentity();
-            int res = broadcastIntentLocked(null, packageName, intent, resolvedType,
-                    resultTo, resultCode, resultData, map, requiredPermission,
-                    AppOpsManager.OP_NONE, serialized, sticky, -1, uid, userId);
-            Binder.restoreCallingIdentity(origId);
-            return res;
-        }
-    }
-
-    public final void unbroadcastIntent(IApplicationThread caller, Intent intent, int userId) {
-        // Refuse possible leaked file descriptors
-        if (intent != null && intent.hasFileDescriptors() == true) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        userId = handleIncomingUser(Binder.getCallingPid(),
-                Binder.getCallingUid(), userId, true, false, "removeStickyBroadcast", null);
-
-        synchronized(this) {
-            if (checkCallingPermission(android.Manifest.permission.BROADCAST_STICKY)
-                    != PackageManager.PERMISSION_GRANTED) {
-                String msg = "Permission Denial: unbroadcastIntent() from pid="
-                        + Binder.getCallingPid()
-                        + ", uid=" + Binder.getCallingUid()
-                        + " requires " + android.Manifest.permission.BROADCAST_STICKY;
-                Slog.w(TAG, msg);
-                throw new SecurityException(msg);
-            }
-            ArrayMap<String, ArrayList<Intent>> stickies = mStickyBroadcasts.get(userId);
-            if (stickies != null) {
-                ArrayList<Intent> list = stickies.get(intent.getAction());
-                if (list != null) {
-                    int N = list.size();
-                    int i;
-                    for (i=0; i<N; i++) {
-                        if (intent.filterEquals(list.get(i))) {
-                            list.remove(i);
-                            break;
-                        }
-                    }
-                    if (list.size() <= 0) {
-                        stickies.remove(intent.getAction());
-                    }
-                }
-                if (stickies.size() <= 0) {
-                    mStickyBroadcasts.remove(userId);
-                }
-            }
-        }
-    }
-
-    private final boolean finishReceiverLocked(IBinder receiver, int resultCode,
-            String resultData, Bundle resultExtras, boolean resultAbort) {
-        final BroadcastRecord r = broadcastRecordForReceiverLocked(receiver);
-        if (r == null) {
-            Slog.w(TAG, "finishReceiver called but not found on queue");
-            return false;
-        }
-
-        return r.queue.finishReceiverLocked(r, resultCode, resultData, resultExtras, resultAbort, false);
-    }
-
-    void backgroundServicesFinishedLocked(int userId) {
-        for (BroadcastQueue queue : mBroadcastQueues) {
-            queue.backgroundServicesFinishedLocked(userId);
-        }
-    }
-
-    public void finishReceiver(IBinder who, int resultCode, String resultData,
-            Bundle resultExtras, boolean resultAbort) {
-        if (DEBUG_BROADCAST) Slog.v(TAG, "Finish receiver: " + who);
-
-        // Refuse possible leaked file descriptors
-        if (resultExtras != null && resultExtras.hasFileDescriptors()) {
-            throw new IllegalArgumentException("File descriptors passed in Bundle");
-        }
-
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            boolean doNext = false;
-            BroadcastRecord r;
-
-            synchronized(this) {
-                r = broadcastRecordForReceiverLocked(who);
-                if (r != null) {
-                    doNext = r.queue.finishReceiverLocked(r, resultCode,
-                        resultData, resultExtras, resultAbort, true);
-                }
-            }
-
-            if (doNext) {
-                r.queue.processNextBroadcast(false);
-            }
-            trimApplications();
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-    
-    // =========================================================
-    // INSTRUMENTATION
-    // =========================================================
-
-    public boolean startInstrumentation(ComponentName className,
-            String profileFile, int flags, Bundle arguments,
-            IInstrumentationWatcher watcher, IUiAutomationConnection uiAutomationConnection,
-            int userId) {
-        enforceNotIsolatedCaller("startInstrumentation");
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
-                userId, false, true, "startInstrumentation", null);
-        // Refuse possible leaked file descriptors
-        if (arguments != null && arguments.hasFileDescriptors()) {
-            throw new IllegalArgumentException("File descriptors passed in Bundle");
-        }
-
-        synchronized(this) {
-            InstrumentationInfo ii = null;
-            ApplicationInfo ai = null;
-            try {
-                ii = mContext.getPackageManager().getInstrumentationInfo(
-                    className, STOCK_PM_FLAGS);
-                ai = AppGlobals.getPackageManager().getApplicationInfo(
-                        ii.targetPackage, STOCK_PM_FLAGS, userId);
-            } catch (PackageManager.NameNotFoundException e) {
-            } catch (RemoteException e) {
-            }
-            if (ii == null) {
-                reportStartInstrumentationFailure(watcher, className,
-                        "Unable to find instrumentation info for: " + className);
-                return false;
-            }
-            if (ai == null) {
-                reportStartInstrumentationFailure(watcher, className,
-                        "Unable to find instrumentation target package: " + ii.targetPackage);
-                return false;
-            }
-
-            int match = mContext.getPackageManager().checkSignatures(
-                    ii.targetPackage, ii.packageName);
-            if (match < 0 && match != PackageManager.SIGNATURE_FIRST_NOT_SIGNED) {
-                String msg = "Permission Denial: starting instrumentation "
-                        + className + " from pid="
-                        + Binder.getCallingPid()
-                        + ", uid=" + Binder.getCallingPid()
-                        + " not allowed because package " + ii.packageName
-                        + " does not have a signature matching the target "
-                        + ii.targetPackage;
-                reportStartInstrumentationFailure(watcher, className, msg);
-                throw new SecurityException(msg);
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-            // Instrumentation can kill and relaunch even persistent processes
-            forceStopPackageLocked(ii.targetPackage, -1, true, false, true, true, false, userId,
-                    "start instr");
-            ProcessRecord app = addAppLocked(ai, false);
-            app.instrumentationClass = className;
-            app.instrumentationInfo = ai;
-            app.instrumentationProfileFile = profileFile;
-            app.instrumentationArguments = arguments;
-            app.instrumentationWatcher = watcher;
-            app.instrumentationUiAutomationConnection = uiAutomationConnection;
-            app.instrumentationResultClass = className;
-            Binder.restoreCallingIdentity(origId);
-        }
-
-        return true;
-    }
-    
-    /**
-     * Report errors that occur while attempting to start Instrumentation.  Always writes the 
-     * error to the logs, but if somebody is watching, send the report there too.  This enables
-     * the "am" command to report errors with more information.
-     * 
-     * @param watcher The IInstrumentationWatcher.  Null if there isn't one.
-     * @param cn The component name of the instrumentation.
-     * @param report The error report.
-     */
-    private void reportStartInstrumentationFailure(IInstrumentationWatcher watcher, 
-            ComponentName cn, String report) {
-        Slog.w(TAG, report);
-        try {
-            if (watcher != null) {
-                Bundle results = new Bundle();
-                results.putString(Instrumentation.REPORT_KEY_IDENTIFIER, "ActivityManagerService");
-                results.putString("Error", report);
-                watcher.instrumentationStatus(cn, -1, results);
-            }
-        } catch (RemoteException e) {
-            Slog.w(TAG, e);
-        }
-    }
-
-    void finishInstrumentationLocked(ProcessRecord app, int resultCode, Bundle results) {
-        if (app.instrumentationWatcher != null) {
-            try {
-                // NOTE:  IInstrumentationWatcher *must* be oneway here
-                app.instrumentationWatcher.instrumentationFinished(
-                    app.instrumentationClass,
-                    resultCode,
-                    results);
-            } catch (RemoteException e) {
-            }
-        }
-        if (app.instrumentationUiAutomationConnection != null) {
-            try {
-                app.instrumentationUiAutomationConnection.shutdown();
-            } catch (RemoteException re) {
-                /* ignore */
-            }
-            // Only a UiAutomation can set this flag and now that
-            // it is finished we make sure it is reset to its default.
-            mUserIsMonkey = false;
-        }
-        app.instrumentationWatcher = null;
-        app.instrumentationUiAutomationConnection = null;
-        app.instrumentationClass = null;
-        app.instrumentationInfo = null;
-        app.instrumentationProfileFile = null;
-        app.instrumentationArguments = null;
-
-        forceStopPackageLocked(app.info.packageName, -1, false, false, true, true, false, app.userId,
-                "finished inst");
-    }
-
-    public void finishInstrumentation(IApplicationThread target,
-            int resultCode, Bundle results) {
-        int userId = UserHandle.getCallingUserId();
-        // Refuse possible leaked file descriptors
-        if (results != null && results.hasFileDescriptors()) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-
-        synchronized(this) {
-            ProcessRecord app = getRecordForAppLocked(target);
-            if (app == null) {
-                Slog.w(TAG, "finishInstrumentation: no app for " + target);
-                return;
-            }
-            final long origId = Binder.clearCallingIdentity();
-            finishInstrumentationLocked(app, resultCode, results);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    // =========================================================
-    // CONFIGURATION
-    // =========================================================
-    
-    public ConfigurationInfo getDeviceConfigurationInfo() {
-        ConfigurationInfo config = new ConfigurationInfo();
-        synchronized (this) {
-            config.reqTouchScreen = mConfiguration.touchscreen;
-            config.reqKeyboardType = mConfiguration.keyboard;
-            config.reqNavigation = mConfiguration.navigation;
-            if (mConfiguration.navigation == Configuration.NAVIGATION_DPAD
-                    || mConfiguration.navigation == Configuration.NAVIGATION_TRACKBALL) {
-                config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
-            }
-            if (mConfiguration.keyboard != Configuration.KEYBOARD_UNDEFINED
-                    && mConfiguration.keyboard != Configuration.KEYBOARD_NOKEYS) {
-                config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
-            }
-            config.reqGlEsVersion = GL_ES_VERSION;
-        }
-        return config;
-    }
-
-    ActivityStack getFocusedStack() {
-        return mStackSupervisor.getFocusedStack();
-    }
-
-    public Configuration getConfiguration() {
-        Configuration ci;
-        synchronized(this) {
-            ci = new Configuration(mConfiguration);
-        }
-        return ci;
-    }
-
-    public void updatePersistentConfiguration(Configuration values) {
-        enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
-                "updateConfiguration()");
-        enforceCallingPermission(android.Manifest.permission.WRITE_SETTINGS,
-                "updateConfiguration()");
-        if (values == null) {
-            throw new NullPointerException("Configuration must not be null");
-        }
-
-        synchronized(this) {
-            final long origId = Binder.clearCallingIdentity();
-            updateConfigurationLocked(values, null, true, false);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    public void updateConfiguration(Configuration values) {
-        enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
-                "updateConfiguration()");
-
-        synchronized(this) {
-            if (values == null && mWindowManager != null) {
-                // sentinel: fetch the current configuration from the window manager
-                values = mWindowManager.computeNewConfiguration();
-            }
-
-            if (mWindowManager != null) {
-                mProcessList.applyDisplaySize(mWindowManager);
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-            if (values != null) {
-                Settings.System.clearConfiguration(values);
-            }
-            updateConfigurationLocked(values, null, false, false);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    /**
-     * Do either or both things: (1) change the current configuration, and (2)
-     * make sure the given activity is running with the (now) current
-     * configuration.  Returns true if the activity has been left running, or
-     * false if <var>starting</var> is being destroyed to match the new
-     * configuration.
-     * @param persistent TODO
-     */
-    boolean updateConfigurationLocked(Configuration values,
-            ActivityRecord starting, boolean persistent, boolean initLocale) {
-        // do nothing if we are headless
-        if (mHeadless) return true;
-
-        int changes = 0;
-
-        if (values != null) {
-            Configuration newConfig = new Configuration(mConfiguration);
-            changes = newConfig.updateFrom(values);
-            if (changes != 0) {
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
-                    Slog.i(TAG, "Updating configuration to: " + values);
-                }
-                
-                EventLog.writeEvent(EventLogTags.CONFIGURATION_CHANGED, changes);
-
-                if (values.locale != null && !initLocale) {
-                    saveLocaleLocked(values.locale, 
-                                     !values.locale.equals(mConfiguration.locale),
-                                     values.userSetLocale);
-                }
-
-                mConfigurationSeq++;
-                if (mConfigurationSeq <= 0) {
-                    mConfigurationSeq = 1;
-                }
-                newConfig.seq = mConfigurationSeq;
-                mConfiguration = newConfig;
-                Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + newConfig);
-
-                final Configuration configCopy = new Configuration(mConfiguration);
-                
-                // TODO: If our config changes, should we auto dismiss any currently
-                // showing dialogs?
-                mShowDialogs = shouldShowDialogs(newConfig);
-
-                AttributeCache ac = AttributeCache.instance();
-                if (ac != null) {
-                    ac.updateConfiguration(configCopy);
-                }
-
-                // Make sure all resources in our process are updated
-                // right now, so that anyone who is going to retrieve
-                // resource values after we return will be sure to get
-                // the new ones.  This is especially important during
-                // boot, where the first config change needs to guarantee
-                // all resources have that config before following boot
-                // code is executed.
-                mSystemThread.applyConfigurationToResources(configCopy);
-
-                if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) {
-                    Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
-                    msg.obj = new Configuration(configCopy);
-                    mHandler.sendMessage(msg);
-                }
-        
-                for (int i=mLruProcesses.size()-1; i>=0; i--) {
-                    ProcessRecord app = mLruProcesses.get(i);
-                    try {
-                        if (app.thread != null) {
-                            if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending to proc "
-                                    + app.processName + " new config " + mConfiguration);
-                            app.thread.scheduleConfigurationChanged(configCopy);
-                        }
-                    } catch (Exception e) {
-                    }
-                }
-                Intent intent = new Intent(Intent.ACTION_CONFIGURATION_CHANGED);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                        | Intent.FLAG_RECEIVER_REPLACE_PENDING
-                        | Intent.FLAG_RECEIVER_FOREGROUND);
-                broadcastIntentLocked(null, null, intent, null, null, 0, null, null,
-                        null, AppOpsManager.OP_NONE, false, false, MY_PID,
-                        Process.SYSTEM_UID, UserHandle.USER_ALL);
-                if ((changes&ActivityInfo.CONFIG_LOCALE) != 0) {
-                    intent = new Intent(Intent.ACTION_LOCALE_CHANGED);
-                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
-                    broadcastIntentLocked(null, null, intent,
-                            null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                            false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
-                }
-            }
-        }
-
-        boolean kept = true;
-        final ActivityStack mainStack = mStackSupervisor.getFocusedStack();
-        if (changes != 0 && starting == null) {
-            // If the configuration changed, and the caller is not already
-            // in the process of starting an activity, then find the top
-            // activity to check if its configuration needs to change.
-            starting = mainStack.topRunningActivityLocked(null);
-        }
-
-        if (starting != null) {
-            kept = mainStack.ensureActivityConfigurationLocked(starting, changes);
-            // And we need to make sure at this point that all other activities
-            // are made visible with the correct configuration.
-            mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes);
-        }
-
-        if (values != null && mWindowManager != null) {
-            mWindowManager.setNewConfiguration(mConfiguration);
-        }
-
-        return kept;
-    }
-
-    /**
-     * Decide based on the configuration whether we should shouw the ANR,
-     * crash, etc dialogs.  The idea is that if there is no affordnace to
-     * press the on-screen buttons, we shouldn't show the dialog.
-     *
-     * A thought: SystemUI might also want to get told about this, the Power
-     * dialog / global actions also might want different behaviors.
-     */
-    private static final boolean shouldShowDialogs(Configuration config) {
-        return !(config.keyboard == Configuration.KEYBOARD_NOKEYS
-                && config.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH);
-    }
-
-    /**
-     * Save the locale.  You must be inside a synchronized (this) block.
-     */
-    private void saveLocaleLocked(Locale l, boolean isDiff, boolean isPersist) {
-        if(isDiff) {
-            SystemProperties.set("user.language", l.getLanguage());
-            SystemProperties.set("user.region", l.getCountry());
-        } 
-
-        if(isPersist) {
-            SystemProperties.set("persist.sys.language", l.getLanguage());
-            SystemProperties.set("persist.sys.country", l.getCountry());
-            SystemProperties.set("persist.sys.localevar", l.getVariant());
-        }
-    }
-
-    @Override
-    public boolean targetTaskAffinityMatchesActivity(IBinder token, String destAffinity) {
-        ActivityRecord srec = ActivityRecord.forToken(token);
-        return srec != null && srec.task.affinity != null &&
-                srec.task.affinity.equals(destAffinity);
-    }
-
-    public boolean navigateUpTo(IBinder token, Intent destIntent, int resultCode,
-            Intent resultData) {
-
-        synchronized (this) {
-            final ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                return stack.navigateUpToLocked(token, destIntent, resultCode, resultData);
-            }
-            return false;
-        }
-    }
-
-    public int getLaunchedFromUid(IBinder activityToken) {
-        ActivityRecord srec = ActivityRecord.forToken(activityToken);
-        if (srec == null) {
-            return -1;
-        }
-        return srec.launchedFromUid;
-    }
-
-    public String getLaunchedFromPackage(IBinder activityToken) {
-        ActivityRecord srec = ActivityRecord.forToken(activityToken);
-        if (srec == null) {
-            return null;
-        }
-        return srec.launchedFromPackage;
-    }
-
-    // =========================================================
-    // LIFETIME MANAGEMENT
-    // =========================================================
-
-    // Returns which broadcast queue the app is the current [or imminent] receiver
-    // on, or 'null' if the app is not an active broadcast recipient.
-    private BroadcastQueue isReceivingBroadcast(ProcessRecord app) {
-        BroadcastRecord r = app.curReceiver;
-        if (r != null) {
-            return r.queue;
-        }
-
-        // It's not the current receiver, but it might be starting up to become one
-        synchronized (this) {
-            for (BroadcastQueue queue : mBroadcastQueues) {
-                r = queue.mPendingBroadcast;
-                if (r != null && r.curApp == app) {
-                    // found it; report which queue it's in
-                    return queue;
-                }
-            }
-        }
-
-        return null;
-    }
-
-    private final int computeOomAdjLocked(ProcessRecord app, int cachedAdj, ProcessRecord TOP_APP,
-            boolean doingAll, long now) {
-        if (mAdjSeq == app.adjSeq) {
-            // This adjustment has already been computed.
-            return app.curRawAdj;
-        }
-
-        if (app.thread == null) {
-            app.adjSeq = mAdjSeq;
-            app.curSchedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
-            app.curProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
-            return (app.curAdj=app.curRawAdj=ProcessList.CACHED_APP_MAX_ADJ);
-        }
-
-        app.adjTypeCode = ActivityManager.RunningAppProcessInfo.REASON_UNKNOWN;
-        app.adjSource = null;
-        app.adjTarget = null;
-        app.empty = false;
-        app.cached = false;
-
-        final int activitiesSize = app.activities.size();
-
-        if (app.maxAdj <= ProcessList.FOREGROUND_APP_ADJ) {
-            // The max adjustment doesn't allow this app to be anything
-            // below foreground, so it is not worth doing work for it.
-            app.adjType = "fixed";
-            app.adjSeq = mAdjSeq;
-            app.curRawAdj = app.maxAdj;
-            app.foregroundActivities = false;
-            app.keeping = true;
-            app.curSchedGroup = Process.THREAD_GROUP_DEFAULT;
-            app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT;
-            // System process can do UI, and when they do we want to have
-            // them trim their memory after the user leaves the UI.  To
-            // facilitate this, here we need to determine whether or not it
-            // is currently showing UI.
-            app.systemNoUi = true;
-            if (app == TOP_APP) {
-                app.systemNoUi = false;
-            } else if (activitiesSize > 0) {
-                for (int j = 0; j < activitiesSize; j++) {
-                    final ActivityRecord r = app.activities.get(j);
-                    if (r.visible) {
-                        app.systemNoUi = false;
-                    }
-                }
-            }
-            if (!app.systemNoUi) {
-                app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT_UI;
-            }
-            return (app.curAdj=app.maxAdj);
-        }
-
-        app.keeping = false;
-        app.systemNoUi = false;
-
-        // Determine the importance of the process, starting with most
-        // important to least, and assign an appropriate OOM adjustment.
-        int adj;
-        int schedGroup;
-        int procState;
-        boolean foregroundActivities = false;
-        boolean interesting = false;
-        BroadcastQueue queue;
-        if (app == TOP_APP) {
-            // The last app on the list is the foreground app.
-            adj = ProcessList.FOREGROUND_APP_ADJ;
-            schedGroup = Process.THREAD_GROUP_DEFAULT;
-            app.adjType = "top-activity";
-            foregroundActivities = true;
-            interesting = true;
-            procState = ActivityManager.PROCESS_STATE_TOP;
-        } else if (app.instrumentationClass != null) {
-            // Don't want to kill running instrumentation.
-            adj = ProcessList.FOREGROUND_APP_ADJ;
-            schedGroup = Process.THREAD_GROUP_DEFAULT;
-            app.adjType = "instrumentation";
-            interesting = true;
-            procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-        } else if ((queue = isReceivingBroadcast(app)) != null) {
-            // An app that is currently receiving a broadcast also
-            // counts as being in the foreground for OOM killer purposes.
-            // It's placed in a sched group based on the nature of the
-            // broadcast as reflected by which queue it's active in.
-            adj = ProcessList.FOREGROUND_APP_ADJ;
-            schedGroup = (queue == mFgBroadcastQueue)
-                    ? Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
-            app.adjType = "broadcast";
-            procState = ActivityManager.PROCESS_STATE_RECEIVER;
-        } else if (app.executingServices.size() > 0) {
-            // An app that is currently executing a service callback also
-            // counts as being in the foreground.
-            adj = ProcessList.FOREGROUND_APP_ADJ;
-            schedGroup = app.execServicesFg ?
-                    Process.THREAD_GROUP_DEFAULT : Process.THREAD_GROUP_BG_NONINTERACTIVE;
-            app.adjType = "exec-service";
-            procState = ActivityManager.PROCESS_STATE_SERVICE;
-            //Slog.i(TAG, "EXEC " + (app.execServicesFg ? "FG" : "BG") + ": " + app);
-        } else {
-            // As far as we know the process is empty.  We may change our mind later.
-            schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
-            // At this point we don't actually know the adjustment.  Use the cached adj
-            // value that the caller wants us to.
-            adj = cachedAdj;
-            procState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
-            app.cached = true;
-            app.empty = true;
-            app.adjType = "cch-empty";
-        }
-
-        // Examine all activities if not already foreground.
-        if (!foregroundActivities && activitiesSize > 0) {
-            for (int j = 0; j < activitiesSize; j++) {
-                final ActivityRecord r = app.activities.get(j);
-                if (r.app != app) {
-                    Slog.w(TAG, "Wtf, activity " + r + " in proc activity list not using proc "
-                            + app + "?!?");
-                    continue;
-                }
-                if (r.visible) {
-                    // App has a visible activity; only upgrade adjustment.
-                    if (adj > ProcessList.VISIBLE_APP_ADJ) {
-                        adj = ProcessList.VISIBLE_APP_ADJ;
-                        app.adjType = "visible";
-                    }
-                    if (procState > ActivityManager.PROCESS_STATE_TOP) {
-                        procState = ActivityManager.PROCESS_STATE_TOP;
-                    }
-                    schedGroup = Process.THREAD_GROUP_DEFAULT;
-                    app.cached = false;
-                    app.empty = false;
-                    foregroundActivities = true;
-                    break;
-                } else if (r.state == ActivityState.PAUSING || r.state == ActivityState.PAUSED) {
-                    if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-                        adj = ProcessList.PERCEPTIBLE_APP_ADJ;
-                        app.adjType = "pausing";
-                    }
-                    if (procState > ActivityManager.PROCESS_STATE_TOP) {
-                        procState = ActivityManager.PROCESS_STATE_TOP;
-                    }
-                    schedGroup = Process.THREAD_GROUP_DEFAULT;
-                    app.cached = false;
-                    app.empty = false;
-                    foregroundActivities = true;
-                } else if (r.state == ActivityState.STOPPING) {
-                    if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-                        adj = ProcessList.PERCEPTIBLE_APP_ADJ;
-                        app.adjType = "stopping";
-                    }
-                    // For the process state, we will at this point consider the
-                    // process to be cached.  It will be cached either as an activity
-                    // or empty depending on whether the activity is finishing.  We do
-                    // this so that we can treat the process as cached for purposes of
-                    // memory trimming (determing current memory level, trim command to
-                    // send to process) since there can be an arbitrary number of stopping
-                    // processes and they should soon all go into the cached state.
-                    if (!r.finishing) {
-                        if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
-                            procState = ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
-                        }
-                    }
-                    app.cached = false;
-                    app.empty = false;
-                    foregroundActivities = true;
-                } else {
-                    if (procState > ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
-                        procState = ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
-                        app.adjType = "cch-act";
-                    }
-                }
-            }
-        }
-
-        if (adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-            if (app.foregroundServices) {
-                // The user is aware of this app, so make it visible.
-                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
-                procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-                app.cached = false;
-                app.adjType = "fg-service";
-                schedGroup = Process.THREAD_GROUP_DEFAULT;
-            } else if (app.forcingToForeground != null) {
-                // The user is aware of this app, so make it visible.
-                adj = ProcessList.PERCEPTIBLE_APP_ADJ;
-                procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-                app.cached = false;
-                app.adjType = "force-fg";
-                app.adjSource = app.forcingToForeground;
-                schedGroup = Process.THREAD_GROUP_DEFAULT;
-            }
-        }
-
-        if (app.foregroundServices) {
-            interesting = true;
-        }
-
-        if (app == mHeavyWeightProcess) {
-            if (adj > ProcessList.HEAVY_WEIGHT_APP_ADJ) {
-                // We don't want to kill the current heavy-weight process.
-                adj = ProcessList.HEAVY_WEIGHT_APP_ADJ;
-                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
-                app.cached = false;
-                app.adjType = "heavy";
-            }
-            if (procState > ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
-                procState = ActivityManager.PROCESS_STATE_HEAVY_WEIGHT;
-            }
-        }
-
-        if (app == mHomeProcess) {
-            if (adj > ProcessList.HOME_APP_ADJ) {
-                // This process is hosting what we currently consider to be the
-                // home app, so we don't want to let it go into the background.
-                adj = ProcessList.HOME_APP_ADJ;
-                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
-                app.cached = false;
-                app.adjType = "home";
-            }
-            if (procState > ActivityManager.PROCESS_STATE_HOME) {
-                procState = ActivityManager.PROCESS_STATE_HOME;
-            }
-        }
-
-        if (app == mPreviousProcess && app.activities.size() > 0) {
-            if (adj > ProcessList.PREVIOUS_APP_ADJ) {
-                // This was the previous process that showed UI to the user.
-                // We want to try to keep it around more aggressively, to give
-                // a good experience around switching between two apps.
-                adj = ProcessList.PREVIOUS_APP_ADJ;
-                schedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
-                app.cached = false;
-                app.adjType = "previous";
-            }
-            if (procState > ActivityManager.PROCESS_STATE_LAST_ACTIVITY) {
-                procState = ActivityManager.PROCESS_STATE_LAST_ACTIVITY;
-            }
-        }
-
-        if (false) Slog.i(TAG, "OOM " + app + ": initial adj=" + adj
-                + " reason=" + app.adjType);
-
-        // By default, we use the computed adjustment.  It may be changed if
-        // there are applications dependent on our services or providers, but
-        // this gives us a baseline and makes sure we don't get into an
-        // infinite recursion.
-        app.adjSeq = mAdjSeq;
-        app.curRawAdj = adj;
-        app.hasStartedServices = false;
-
-        if (mBackupTarget != null && app == mBackupTarget.app) {
-            // If possible we want to avoid killing apps while they're being backed up
-            if (adj > ProcessList.BACKUP_APP_ADJ) {
-                if (DEBUG_BACKUP) Slog.v(TAG, "oom BACKUP_APP_ADJ for " + app);
-                adj = ProcessList.BACKUP_APP_ADJ;
-                if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
-                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
-                }
-                app.adjType = "backup";
-                app.cached = false;
-            }
-            if (procState > ActivityManager.PROCESS_STATE_BACKUP) {
-                procState = ActivityManager.PROCESS_STATE_BACKUP;
-            }
-        }
-
-        boolean mayBeTop = false;
-
-        for (int is = app.services.size()-1;
-                is >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
-                        || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
-                        || procState > ActivityManager.PROCESS_STATE_TOP);
-                is--) {
-            ServiceRecord s = app.services.valueAt(is);
-            if (s.startRequested) {
-                app.hasStartedServices = true;
-                if (procState > ActivityManager.PROCESS_STATE_SERVICE) {
-                    procState = ActivityManager.PROCESS_STATE_SERVICE;
-                }
-                if (app.hasShownUi && app != mHomeProcess) {
-                    // If this process has shown some UI, let it immediately
-                    // go to the LRU list because it may be pretty heavy with
-                    // UI stuff.  We'll tag it with a label just to help
-                    // debug and understand what is going on.
-                    if (adj > ProcessList.SERVICE_ADJ) {
-                        app.adjType = "cch-started-ui-services";
-                    }
-                } else {
-                    if (now < (s.lastActivity + ActiveServices.MAX_SERVICE_INACTIVITY)) {
-                        // This service has seen some activity within
-                        // recent memory, so we will keep its process ahead
-                        // of the background processes.
-                        if (adj > ProcessList.SERVICE_ADJ) {
-                            adj = ProcessList.SERVICE_ADJ;
-                            app.adjType = "started-services";
-                            app.cached = false;
-                        }
-                    }
-                    // If we have let the service slide into the background
-                    // state, still have some text describing what it is doing
-                    // even though the service no longer has an impact.
-                    if (adj > ProcessList.SERVICE_ADJ) {
-                        app.adjType = "cch-started-services";
-                    }
-                }
-                // Don't kill this process because it is doing work; it
-                // has said it is doing work.
-                app.keeping = true;
-            }
-            for (int conni = s.connections.size()-1;
-                    conni >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
-                            || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
-                            || procState > ActivityManager.PROCESS_STATE_TOP);
-                    conni--) {
-                ArrayList<ConnectionRecord> clist = s.connections.valueAt(conni);
-                for (int i = 0;
-                        i < clist.size() && (adj > ProcessList.FOREGROUND_APP_ADJ
-                                || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
-                                || procState > ActivityManager.PROCESS_STATE_TOP);
-                        i++) {
-                    // XXX should compute this based on the max of
-                    // all connected clients.
-                    ConnectionRecord cr = clist.get(i);
-                    if (cr.binding.client == app) {
-                        // Binding to ourself is not interesting.
-                        continue;
-                    }
-                    if ((cr.flags&Context.BIND_WAIVE_PRIORITY) == 0) {
-                        ProcessRecord client = cr.binding.client;
-                        int clientAdj = computeOomAdjLocked(client, cachedAdj,
-                                TOP_APP, doingAll, now);
-                        int clientProcState = client.curProcState;
-                        if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
-                            // If the other app is cached for any reason, for purposes here
-                            // we are going to consider it empty.  The specific cached state
-                            // doesn't propagate except under certain conditions.
-                            clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
-                        }
-                        String adjType = null;
-                        if ((cr.flags&Context.BIND_ALLOW_OOM_MANAGEMENT) != 0) {
-                            // Not doing bind OOM management, so treat
-                            // this guy more like a started service.
-                            if (app.hasShownUi && app != mHomeProcess) {
-                                // If this process has shown some UI, let it immediately
-                                // go to the LRU list because it may be pretty heavy with
-                                // UI stuff.  We'll tag it with a label just to help
-                                // debug and understand what is going on.
-                                if (adj > clientAdj) {
-                                    adjType = "cch-bound-ui-services";
-                                }
-                                app.cached = false;
-                                clientAdj = adj;
-                                clientProcState = procState;
-                            } else {
-                                if (now >= (s.lastActivity
-                                        + ActiveServices.MAX_SERVICE_INACTIVITY)) {
-                                    // This service has not seen activity within
-                                    // recent memory, so allow it to drop to the
-                                    // LRU list if there is no other reason to keep
-                                    // it around.  We'll also tag it with a label just
-                                    // to help debug and undertand what is going on.
-                                    if (adj > clientAdj) {
-                                        adjType = "cch-bound-services";
-                                    }
-                                    clientAdj = adj;
-                                }
-                            }
-                        }
-                        if (adj > clientAdj) {
-                            // If this process has recently shown UI, and
-                            // the process that is binding to it is less
-                            // important than being visible, then we don't
-                            // care about the binding as much as we care
-                            // about letting this process get into the LRU
-                            // list to be killed and restarted if needed for
-                            // memory.
-                            if (app.hasShownUi && app != mHomeProcess
-                                    && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-                                adjType = "cch-bound-ui-services";
-                            } else {
-                                if ((cr.flags&(Context.BIND_ABOVE_CLIENT
-                                        |Context.BIND_IMPORTANT)) != 0) {
-                                    adj = clientAdj;
-                                } else if ((cr.flags&Context.BIND_NOT_VISIBLE) != 0
-                                        && clientAdj < ProcessList.PERCEPTIBLE_APP_ADJ
-                                        && adj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-                                    adj = ProcessList.PERCEPTIBLE_APP_ADJ;
-                                } else if (clientAdj > ProcessList.VISIBLE_APP_ADJ) {
-                                    adj = clientAdj;
-                                } else {
-                                    if (adj > ProcessList.VISIBLE_APP_ADJ) {
-                                        adj = ProcessList.VISIBLE_APP_ADJ;
-                                    }
-                                }
-                                if (!client.cached) {
-                                    app.cached = false;
-                                }
-                                if (client.keeping) {
-                                    app.keeping = true;
-                                }
-                                adjType = "service";
-                            }
-                        }
-                        if ((cr.flags&Context.BIND_NOT_FOREGROUND) == 0) {
-                            if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
-                                schedGroup = Process.THREAD_GROUP_DEFAULT;
-                            }
-                            if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
-                                if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
-                                    // Special handling of clients who are in the top state.
-                                    // We *may* want to consider this process to be in the
-                                    // top state as well, but only if there is not another
-                                    // reason for it to be running.  Being on the top is a
-                                    // special state, meaning you are specifically running
-                                    // for the current top app.  If the process is already
-                                    // running in the background for some other reason, it
-                                    // is more important to continue considering it to be
-                                    // in the background state.
-                                    mayBeTop = true;
-                                    clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
-                                } else {
-                                    // Special handling for above-top states (persistent
-                                    // processes).  These should not bring the current process
-                                    // into the top state, since they are not on top.  Instead
-                                    // give them the best state after that.
-                                    clientProcState =
-                                            ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-                                }
-                            }
-                        } else {
-                            if (clientProcState <
-                                    ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) {
-                                clientProcState =
-                                        ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND;
-                            }
-                        }
-                        if (procState > clientProcState) {
-                            procState = clientProcState;
-                        }
-                        if (procState < ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
-                                && (cr.flags&Context.BIND_SHOWING_UI) != 0) {
-                            app.pendingUiClean = true;
-                        }
-                        if (adjType != null) {
-                            app.adjType = adjType;
-                            app.adjTypeCode = ActivityManager.RunningAppProcessInfo
-                                    .REASON_SERVICE_IN_USE;
-                            app.adjSource = cr.binding.client;
-                            app.adjSourceOom = clientAdj;
-                            app.adjTarget = s.name;
-                        }
-                    }
-                    final ActivityRecord a = cr.activity;
-                    if ((cr.flags&Context.BIND_ADJUST_WITH_ACTIVITY) != 0) {
-                        if (a != null && adj > ProcessList.FOREGROUND_APP_ADJ &&
-                                (a.visible || a.state == ActivityState.RESUMED
-                                 || a.state == ActivityState.PAUSING)) {
-                            adj = ProcessList.FOREGROUND_APP_ADJ;
-                            if ((cr.flags&Context.BIND_NOT_FOREGROUND) == 0) {
-                                schedGroup = Process.THREAD_GROUP_DEFAULT;
-                            }
-                            app.cached = false;
-                            app.adjType = "service";
-                            app.adjTypeCode = ActivityManager.RunningAppProcessInfo
-                                    .REASON_SERVICE_IN_USE;
-                            app.adjSource = a;
-                            app.adjSourceOom = adj;
-                            app.adjTarget = s.name;
-                        }
-                    }
-                }
-            }
-        }
-
-        for (int provi = app.pubProviders.size()-1;
-                provi >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
-                        || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
-                        || procState > ActivityManager.PROCESS_STATE_TOP);
-                provi--) {
-            ContentProviderRecord cpr = app.pubProviders.valueAt(provi);
-            for (int i = cpr.connections.size()-1;
-                    i >= 0 && (adj > ProcessList.FOREGROUND_APP_ADJ
-                            || schedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE
-                            || procState > ActivityManager.PROCESS_STATE_TOP);
-                    i--) {
-                ContentProviderConnection conn = cpr.connections.get(i);
-                ProcessRecord client = conn.client;
-                if (client == app) {
-                    // Being our own client is not interesting.
-                    continue;
-                }
-                int clientAdj = computeOomAdjLocked(client, cachedAdj, TOP_APP, doingAll, now);
-                int clientProcState = client.curProcState;
-                if (clientProcState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY) {
-                    // If the other app is cached for any reason, for purposes here
-                    // we are going to consider it empty.
-                    clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
-                }
-                if (adj > clientAdj) {
-                    if (app.hasShownUi && app != mHomeProcess
-                            && clientAdj > ProcessList.PERCEPTIBLE_APP_ADJ) {
-                        app.adjType = "cch-ui-provider";
-                    } else {
-                        adj = clientAdj > ProcessList.FOREGROUND_APP_ADJ
-                                ? clientAdj : ProcessList.FOREGROUND_APP_ADJ;
-                        app.adjType = "provider";
-                    }
-                    app.cached &= client.cached;
-                    app.keeping |= client.keeping;
-                    app.adjTypeCode = ActivityManager.RunningAppProcessInfo
-                            .REASON_PROVIDER_IN_USE;
-                    app.adjSource = client;
-                    app.adjSourceOom = clientAdj;
-                    app.adjTarget = cpr.name;
-                }
-                if (clientProcState <= ActivityManager.PROCESS_STATE_TOP) {
-                    if (clientProcState == ActivityManager.PROCESS_STATE_TOP) {
-                        // Special handling of clients who are in the top state.
-                        // We *may* want to consider this process to be in the
-                        // top state as well, but only if there is not another
-                        // reason for it to be running.  Being on the top is a
-                        // special state, meaning you are specifically running
-                        // for the current top app.  If the process is already
-                        // running in the background for some other reason, it
-                        // is more important to continue considering it to be
-                        // in the background state.
-                        mayBeTop = true;
-                        clientProcState = ActivityManager.PROCESS_STATE_CACHED_EMPTY;
-                    } else {
-                        // Special handling for above-top states (persistent
-                        // processes).  These should not bring the current process
-                        // into the top state, since they are not on top.  Instead
-                        // give them the best state after that.
-                        clientProcState =
-                                ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-                    }
-                }
-                if (procState > clientProcState) {
-                    procState = clientProcState;
-                }
-                if (client.curSchedGroup == Process.THREAD_GROUP_DEFAULT) {
-                    schedGroup = Process.THREAD_GROUP_DEFAULT;
-                }
-            }
-            // If the provider has external (non-framework) process
-            // dependencies, ensure that its adjustment is at least
-            // FOREGROUND_APP_ADJ.
-            if (cpr.hasExternalProcessHandles()) {
-                if (adj > ProcessList.FOREGROUND_APP_ADJ) {
-                    adj = ProcessList.FOREGROUND_APP_ADJ;
-                    schedGroup = Process.THREAD_GROUP_DEFAULT;
-                    app.cached = false;
-                    app.keeping = true;
-                    app.adjType = "provider";
-                    app.adjTarget = cpr.name;
-                }
-                if (procState > ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND) {
-                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-                }
-            }
-        }
-
-        if (mayBeTop && procState > ActivityManager.PROCESS_STATE_TOP) {
-            // A client of one of our services or providers is in the top state.  We
-            // *may* want to be in the top state, but not if we are already running in
-            // the background for some other reason.  For the decision here, we are going
-            // to pick out a few specific states that we want to remain in when a client
-            // is top (states that tend to be longer-term) and otherwise allow it to go
-            // to the top state.
-            switch (procState) {
-                case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
-                case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
-                case ActivityManager.PROCESS_STATE_SERVICE:
-                    // These all are longer-term states, so pull them up to the top
-                    // of the background states, but not all the way to the top state.
-                    procState = ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND;
-                    break;
-                default:
-                    // Otherwise, top is a better choice, so take it.
-                    procState = ActivityManager.PROCESS_STATE_TOP;
-                    break;
-            }
-        }
-
-        if (procState >= ActivityManager.PROCESS_STATE_CACHED_EMPTY && app.hasClientActivities) {
-            // This is a cached process, but with client activities.  Mark it so.
-            procState = ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT;
-            app.adjType = "cch-client-act";
-        }
-
-        if (adj == ProcessList.SERVICE_ADJ) {
-            if (doingAll) {
-                app.serviceb = mNewNumAServiceProcs > (mNumServiceProcs/3);
-                mNewNumServiceProcs++;
-                //Slog.i(TAG, "ADJ " + app + " serviceb=" + app.serviceb);
-                if (!app.serviceb) {
-                    // This service isn't far enough down on the LRU list to
-                    // normally be a B service, but if we are low on RAM and it
-                    // is large we want to force it down since we would prefer to
-                    // keep launcher over it.
-                    if (mLastMemoryLevel > ProcessStats.ADJ_MEM_FACTOR_NORMAL
-                            && app.lastPss >= mProcessList.getCachedRestoreThresholdKb()) {
-                        app.serviceHighRam = true;
-                        app.serviceb = true;
-                        //Slog.i(TAG, "ADJ " + app + " high ram!");
-                    } else {
-                        mNewNumAServiceProcs++;
-                        //Slog.i(TAG, "ADJ " + app + " not high ram!");
-                    }
-                } else {
-                    app.serviceHighRam = false;
-                }
-            }
-            if (app.serviceb) {
-                adj = ProcessList.SERVICE_B_ADJ;
-            }
-        }
-
-        app.curRawAdj = adj;
-        
-        //Slog.i(TAG, "OOM ADJ " + app + ": pid=" + app.pid +
-        //      " adj=" + adj + " curAdj=" + app.curAdj + " maxAdj=" + app.maxAdj);
-        if (adj > app.maxAdj) {
-            adj = app.maxAdj;
-            if (app.maxAdj <= ProcessList.PERCEPTIBLE_APP_ADJ) {
-                schedGroup = Process.THREAD_GROUP_DEFAULT;
-            }
-        }
-        if (adj < ProcessList.CACHED_APP_MIN_ADJ) {
-            app.keeping = true;
-        }
-
-        // Do final modification to adj.  Everything we do between here and applying
-        // the final setAdj must be done in this function, because we will also use
-        // it when computing the final cached adj later.  Note that we don't need to
-        // worry about this for max adj above, since max adj will always be used to
-        // keep it out of the cached vaues.
-        adj = app.modifyRawOomAdj(adj);
-
-        app.curProcState = procState;
-
-        int importance = app.memImportance;
-        if (importance == 0 || adj != app.curAdj || schedGroup != app.curSchedGroup) {
-            app.curAdj = adj;
-            app.curSchedGroup = schedGroup;
-            if (!interesting) {
-                // For this reporting, if there is not something explicitly
-                // interesting in this process then we will push it to the
-                // background importance.
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
-            } else if (adj >= ProcessList.CACHED_APP_MIN_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
-            } else if (adj >= ProcessList.SERVICE_B_ADJ) {
-                importance =  ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
-            } else if (adj >= ProcessList.HOME_APP_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
-            } else if (adj >= ProcessList.SERVICE_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
-            } else if (adj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE;
-            } else if (adj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
-            } else if (adj >= ProcessList.VISIBLE_APP_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE;
-            } else if (adj >= ProcessList.FOREGROUND_APP_ADJ) {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
-            } else {
-                importance = ActivityManager.RunningAppProcessInfo.IMPORTANCE_PERSISTENT;
-            }
-        }
-
-        int changes = importance != app.memImportance ? ProcessChangeItem.CHANGE_IMPORTANCE : 0;
-        if (foregroundActivities != app.foregroundActivities) {
-            changes |= ProcessChangeItem.CHANGE_ACTIVITIES;
-        }
-        if (changes != 0) {
-            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Changes in " + app + ": " + changes);
-            app.memImportance = importance;
-            app.foregroundActivities = foregroundActivities;
-            int i = mPendingProcessChanges.size()-1;
-            ProcessChangeItem item = null;
-            while (i >= 0) {
-                item = mPendingProcessChanges.get(i);
-                if (item.pid == app.pid) {
-                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Re-using existing item: " + item);
-                    break;
-                }
-                i--;
-            }
-            if (i < 0) {
-                // No existing item in pending changes; need a new one.
-                final int NA = mAvailProcessChanges.size();
-                if (NA > 0) {
-                    item = mAvailProcessChanges.remove(NA-1);
-                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Retreiving available item: " + item);
-                } else {
-                    item = new ProcessChangeItem();
-                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Allocating new item: " + item);
-                }
-                item.changes = 0;
-                item.pid = app.pid;
-                item.uid = app.info.uid;
-                if (mPendingProcessChanges.size() == 0) {
-                    if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG,
-                            "*** Enqueueing dispatch processes changed!");
-                    mHandler.obtainMessage(DISPATCH_PROCESSES_CHANGED).sendToTarget();
-                }
-                mPendingProcessChanges.add(item);
-            }
-            item.changes |= changes;
-            item.importance = importance;
-            item.foregroundActivities = foregroundActivities;
-            if (DEBUG_PROCESS_OBSERVERS) Slog.i(TAG, "Item "
-                    + Integer.toHexString(System.identityHashCode(item))
-                    + " " + app.toShortString() + ": changes=" + item.changes
-                    + " importance=" + item.importance
-                    + " foreground=" + item.foregroundActivities
-                    + " type=" + app.adjType + " source=" + app.adjSource
-                    + " target=" + app.adjTarget);
-        }
-
-        return app.curRawAdj;
-    }
-
-    /**
-     * Schedule PSS collection of a process.
-     */
-    void requestPssLocked(ProcessRecord proc, int procState) {
-        if (mPendingPssProcesses.contains(proc)) {
-            return;
-        }
-        if (mPendingPssProcesses.size() == 0) {
-            mBgHandler.sendEmptyMessage(COLLECT_PSS_BG_MSG);
-        }
-        if (DEBUG_PSS) Slog.d(TAG, "Requesting PSS of: " + proc);
-        proc.pssProcState = procState;
-        mPendingPssProcesses.add(proc);
-    }
-
-    /**
-     * Schedule PSS collection of all processes.
-     */
-    void requestPssAllProcsLocked(long now, boolean always, boolean memLowered) {
-        if (!always) {
-            if (now < (mLastFullPssTime +
-                    (memLowered ? FULL_PSS_LOWERED_INTERVAL : FULL_PSS_MIN_INTERVAL))) {
-                return;
-            }
-        }
-        if (DEBUG_PSS) Slog.d(TAG, "Requesting PSS of all procs!  memLowered=" + memLowered);
-        mLastFullPssTime = now;
-        mPendingPssProcesses.ensureCapacity(mLruProcesses.size());
-        mPendingPssProcesses.clear();
-        for (int i=mLruProcesses.size()-1; i>=0; i--) {
-            ProcessRecord app = mLruProcesses.get(i);
-            if (memLowered || now > (app.lastStateTime+ProcessList.PSS_ALL_INTERVAL)) {
-                app.pssProcState = app.setProcState;
-                app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
-                        mSleeping, now);
-                mPendingPssProcesses.add(app);
-            }
-        }
-        mBgHandler.sendEmptyMessage(COLLECT_PSS_BG_MSG);
-    }
-
-    /**
-     * Ask a given process to GC right now.
-     */
-    final void performAppGcLocked(ProcessRecord app) {
-        try {
-            app.lastRequestedGc = SystemClock.uptimeMillis();
-            if (app.thread != null) {
-                if (app.reportLowMemory) {
-                    app.reportLowMemory = false;
-                    app.thread.scheduleLowMemory();
-                } else {
-                    app.thread.processInBackground();
-                }
-            }
-        } catch (Exception e) {
-            // whatever.
-        }
-    }
-    
-    /**
-     * Returns true if things are idle enough to perform GCs.
-     */
-    private final boolean canGcNowLocked() {
-        boolean processingBroadcasts = false;
-        for (BroadcastQueue q : mBroadcastQueues) {
-            if (q.mParallelBroadcasts.size() != 0 || q.mOrderedBroadcasts.size() != 0) {
-                processingBroadcasts = true;
-            }
-        }
-        return !processingBroadcasts
-                && (mSleeping || mStackSupervisor.allResumedActivitiesIdle());
-    }
-    
-    /**
-     * Perform GCs on all processes that are waiting for it, but only
-     * if things are idle.
-     */
-    final void performAppGcsLocked() {
-        final int N = mProcessesToGc.size();
-        if (N <= 0) {
-            return;
-        }
-        if (canGcNowLocked()) {
-            while (mProcessesToGc.size() > 0) {
-                ProcessRecord proc = mProcessesToGc.remove(0);
-                if (proc.curRawAdj > ProcessList.PERCEPTIBLE_APP_ADJ || proc.reportLowMemory) {
-                    if ((proc.lastRequestedGc+GC_MIN_INTERVAL)
-                            <= SystemClock.uptimeMillis()) {
-                        // To avoid spamming the system, we will GC processes one
-                        // at a time, waiting a few seconds between each.
-                        performAppGcLocked(proc);
-                        scheduleAppGcsLocked();
-                        return;
-                    } else {
-                        // It hasn't been long enough since we last GCed this
-                        // process...  put it in the list to wait for its time.
-                        addProcessToGcListLocked(proc);
-                        break;
-                    }
-                }
-            }
-            
-            scheduleAppGcsLocked();
-        }
-    }
-    
-    /**
-     * If all looks good, perform GCs on all processes waiting for them.
-     */
-    final void performAppGcsIfAppropriateLocked() {
-        if (canGcNowLocked()) {
-            performAppGcsLocked();
-            return;
-        }
-        // Still not idle, wait some more.
-        scheduleAppGcsLocked();
-    }
-
-    /**
-     * Schedule the execution of all pending app GCs.
-     */
-    final void scheduleAppGcsLocked() {
-        mHandler.removeMessages(GC_BACKGROUND_PROCESSES_MSG);
-        
-        if (mProcessesToGc.size() > 0) {
-            // Schedule a GC for the time to the next process.
-            ProcessRecord proc = mProcessesToGc.get(0);
-            Message msg = mHandler.obtainMessage(GC_BACKGROUND_PROCESSES_MSG);
-            
-            long when = proc.lastRequestedGc + GC_MIN_INTERVAL;
-            long now = SystemClock.uptimeMillis();
-            if (when < (now+GC_TIMEOUT)) {
-                when = now + GC_TIMEOUT;
-            }
-            mHandler.sendMessageAtTime(msg, when);
-        }
-    }
-    
-    /**
-     * Add a process to the array of processes waiting to be GCed.  Keeps the
-     * list in sorted order by the last GC time.  The process can't already be
-     * on the list.
-     */
-    final void addProcessToGcListLocked(ProcessRecord proc) {
-        boolean added = false;
-        for (int i=mProcessesToGc.size()-1; i>=0; i--) {
-            if (mProcessesToGc.get(i).lastRequestedGc <
-                    proc.lastRequestedGc) {
-                added = true;
-                mProcessesToGc.add(i+1, proc);
-                break;
-            }
-        }
-        if (!added) {
-            mProcessesToGc.add(0, proc);
-        }
-    }
-    
-    /**
-     * Set up to ask a process to GC itself.  This will either do it
-     * immediately, or put it on the list of processes to gc the next
-     * time things are idle.
-     */
-    final void scheduleAppGcLocked(ProcessRecord app) {
-        long now = SystemClock.uptimeMillis();
-        if ((app.lastRequestedGc+GC_MIN_INTERVAL) > now) {
-            return;
-        }
-        if (!mProcessesToGc.contains(app)) {
-            addProcessToGcListLocked(app);
-            scheduleAppGcsLocked();
-        }
-    }
-
-    final void checkExcessivePowerUsageLocked(boolean doKills) {
-        updateCpuStatsNow();
-
-        BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-        boolean doWakeKills = doKills;
-        boolean doCpuKills = doKills;
-        if (mLastPowerCheckRealtime == 0) {
-            doWakeKills = false;
-        }
-        if (mLastPowerCheckUptime == 0) {
-            doCpuKills = false;
-        }
-        if (stats.isScreenOn()) {
-            doWakeKills = false;
-        }
-        final long curRealtime = SystemClock.elapsedRealtime();
-        final long realtimeSince = curRealtime - mLastPowerCheckRealtime;
-        final long curUptime = SystemClock.uptimeMillis();
-        final long uptimeSince = curUptime - mLastPowerCheckUptime;
-        mLastPowerCheckRealtime = curRealtime;
-        mLastPowerCheckUptime = curUptime;
-        if (realtimeSince < WAKE_LOCK_MIN_CHECK_DURATION) {
-            doWakeKills = false;
-        }
-        if (uptimeSince < CPU_MIN_CHECK_DURATION) {
-            doCpuKills = false;
-        }
-        int i = mLruProcesses.size();
-        while (i > 0) {
-            i--;
-            ProcessRecord app = mLruProcesses.get(i);
-            if (!app.keeping) {
-                long wtime;
-                synchronized (stats) {
-                    wtime = stats.getProcessWakeTime(app.info.uid,
-                            app.pid, curRealtime);
-                }
-                long wtimeUsed = wtime - app.lastWakeTime;
-                long cputimeUsed = app.curCpuTime - app.lastCpuTime;
-                if (DEBUG_POWER) {
-                    StringBuilder sb = new StringBuilder(128);
-                    sb.append("Wake for ");
-                    app.toShortString(sb);
-                    sb.append(": over ");
-                    TimeUtils.formatDuration(realtimeSince, sb);
-                    sb.append(" used ");
-                    TimeUtils.formatDuration(wtimeUsed, sb);
-                    sb.append(" (");
-                    sb.append((wtimeUsed*100)/realtimeSince);
-                    sb.append("%)");
-                    Slog.i(TAG, sb.toString());
-                    sb.setLength(0);
-                    sb.append("CPU for ");
-                    app.toShortString(sb);
-                    sb.append(": over ");
-                    TimeUtils.formatDuration(uptimeSince, sb);
-                    sb.append(" used ");
-                    TimeUtils.formatDuration(cputimeUsed, sb);
-                    sb.append(" (");
-                    sb.append((cputimeUsed*100)/uptimeSince);
-                    sb.append("%)");
-                    Slog.i(TAG, sb.toString());
-                }
-                // If a process has held a wake lock for more
-                // than 50% of the time during this period,
-                // that sounds bad.  Kill!
-                if (doWakeKills && realtimeSince > 0
-                        && ((wtimeUsed*100)/realtimeSince) >= 50) {
-                    synchronized (stats) {
-                        stats.reportExcessiveWakeLocked(app.info.uid, app.processName,
-                                realtimeSince, wtimeUsed);
-                    }
-                    killUnneededProcessLocked(app, "excessive wake held " + wtimeUsed
-                            + " during " + realtimeSince);
-                    app.baseProcessTracker.reportExcessiveWake(app.pkgList);
-                } else if (doCpuKills && uptimeSince > 0
-                        && ((cputimeUsed*100)/uptimeSince) >= 50) {
-                    synchronized (stats) {
-                        stats.reportExcessiveCpuLocked(app.info.uid, app.processName,
-                                uptimeSince, cputimeUsed);
-                    }
-                    killUnneededProcessLocked(app, "excessive cpu " + cputimeUsed
-                            + " during " + uptimeSince);
-                    app.baseProcessTracker.reportExcessiveCpu(app.pkgList);
-                } else {
-                    app.lastWakeTime = wtime;
-                    app.lastCpuTime = app.curCpuTime;
-                }
-            }
-        }
-    }
-
-    private final boolean applyOomAdjLocked(ProcessRecord app, boolean wasKeeping,
-            ProcessRecord TOP_APP, boolean doingAll, boolean reportingProcessState, long now) {
-        boolean success = true;
-
-        if (app.curRawAdj != app.setRawAdj) {
-            if (wasKeeping && !app.keeping) {
-                // This app is no longer something we want to keep.  Note
-                // its current wake lock time to later know to kill it if
-                // it is not behaving well.
-                BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
-                synchronized (stats) {
-                    app.lastWakeTime = stats.getProcessWakeTime(app.info.uid,
-                            app.pid, SystemClock.elapsedRealtime());
-                }
-                app.lastCpuTime = app.curCpuTime;
-            }
-
-            app.setRawAdj = app.curRawAdj;
-        }
-
-        if (app.curAdj != app.setAdj) {
-            if (Process.setOomAdj(app.pid, app.curAdj)) {
-                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(
-                    TAG, "Set " + app.pid + " " + app.processName +
-                    " adj " + app.curAdj + ": " + app.adjType);
-                app.setAdj = app.curAdj;
-            } else {
-                success = false;
-                Slog.w(TAG, "Failed setting oom adj of " + app + " to " + app.curAdj);
-            }
-        }
-        if (app.setSchedGroup != app.curSchedGroup) {
-            app.setSchedGroup = app.curSchedGroup;
-            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                    "Setting process group of " + app.processName
-                    + " to " + app.curSchedGroup);
-            if (app.waitingToKill != null &&
-                    app.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
-                killUnneededProcessLocked(app, app.waitingToKill);
-                success = false;
-            } else {
-                if (true) {
-                    long oldId = Binder.clearCallingIdentity();
-                    try {
-                        Process.setProcessGroup(app.pid, app.curSchedGroup);
-                    } catch (Exception e) {
-                        Slog.w(TAG, "Failed setting process group of " + app.pid
-                                + " to " + app.curSchedGroup);
-                        e.printStackTrace();
-                    } finally {
-                        Binder.restoreCallingIdentity(oldId);
-                    }
-                } else {
-                    if (app.thread != null) {
-                        try {
-                            app.thread.setSchedulingGroup(app.curSchedGroup);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                }
-                Process.setSwappiness(app.pid,
-                        app.curSchedGroup <= Process.THREAD_GROUP_BG_NONINTERACTIVE);
-            }
-        }
-        if (app.repProcState != app.curProcState) {
-            app.repProcState = app.curProcState;
-            if (!reportingProcessState && app.thread != null) {
-                try {
-                    if (false) {
-                        //RuntimeException h = new RuntimeException("here");
-                        Slog.i(TAG, "Sending new process state " + app.repProcState
-                                + " to " + app /*, h*/);
-                    }
-                    app.thread.setProcessState(app.repProcState);
-                } catch (RemoteException e) {
-                }
-            }
-        }
-        if (app.setProcState < 0 || ProcessList.procStatesDifferForMem(app.curProcState,
-                app.setProcState)) {
-            app.lastStateTime = now;
-            app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, true,
-                    mSleeping, now);
-            if (DEBUG_PSS) Slog.d(TAG, "Process state change from "
-                    + ProcessList.makeProcStateString(app.setProcState) + " to "
-                    + ProcessList.makeProcStateString(app.curProcState) + " next pss in "
-                    + (app.nextPssTime-now) + ": " + app);
-        } else {
-            if (now > app.nextPssTime || (now > (app.lastPssTime+ProcessList.PSS_MAX_INTERVAL)
-                    && now > (app.lastStateTime+ProcessList.PSS_MIN_TIME_FROM_STATE_CHANGE))) {
-                requestPssLocked(app, app.setProcState);
-                app.nextPssTime = ProcessList.computeNextPssTime(app.curProcState, false,
-                        mSleeping, now);
-            } else if (false && DEBUG_PSS) {
-                Slog.d(TAG, "Not requesting PSS of " + app + ": next=" + (app.nextPssTime-now));
-            }
-        }
-        if (app.setProcState != app.curProcState) {
-            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                    "Proc state change of " + app.processName
-                    + " to " + app.curProcState);
-            app.setProcState = app.curProcState;
-            if (app.setProcState >= ActivityManager.PROCESS_STATE_HOME) {
-                app.notCachedSinceIdle = false;
-            }
-            if (!doingAll) {
-                setProcessTrackerState(app, mProcessStats.getMemFactorLocked(), now);
-            } else {
-                app.procStateChanged = true;
-            }
-        }
-        return success;
-    }
-
-    private final void setProcessTrackerState(ProcessRecord proc, int memFactor, long now) {
-        if (proc.thread != null && proc.baseProcessTracker != null) {
-            proc.baseProcessTracker.setState(proc.repProcState, memFactor, now, proc.pkgList);
-        }
-    }
-
-    private final boolean updateOomAdjLocked(ProcessRecord app, int cachedAdj,
-            ProcessRecord TOP_APP, boolean doingAll, boolean reportingProcessState, long now) {
-        if (app.thread == null) {
-            return false;
-        }
-
-        final boolean wasKeeping = app.keeping;
-
-        computeOomAdjLocked(app, cachedAdj, TOP_APP, doingAll, now);
-
-        return applyOomAdjLocked(app, wasKeeping, TOP_APP, doingAll,
-                reportingProcessState, now);
-    }
-
-    private final ActivityRecord resumedAppLocked() {
-        return mStackSupervisor.resumedAppLocked();
-    }
-
-    final boolean updateOomAdjLocked(ProcessRecord app) {
-        return updateOomAdjLocked(app, false);
-    }
-
-    final boolean updateOomAdjLocked(ProcessRecord app, boolean doingProcessState) {
-        final ActivityRecord TOP_ACT = resumedAppLocked();
-        final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null;
-        final boolean wasCached = app.cached;
-
-        mAdjSeq++;
-
-        // This is the desired cached adjusment we want to tell it to use.
-        // If our app is currently cached, we know it, and that is it.  Otherwise,
-        // we don't know it yet, and it needs to now be cached we will then
-        // need to do a complete oom adj.
-        final int cachedAdj = app.curRawAdj >= ProcessList.CACHED_APP_MIN_ADJ
-                ? app.curRawAdj : ProcessList.UNKNOWN_ADJ;
-        boolean success = updateOomAdjLocked(app, cachedAdj, TOP_APP, false, doingProcessState,
-                SystemClock.uptimeMillis());
-        if (wasCached != app.cached || app.curRawAdj == ProcessList.UNKNOWN_ADJ) {
-            // Changed to/from cached state, so apps after it in the LRU
-            // list may also be changed.
-            updateOomAdjLocked();
-        }
-        return success;
-    }
-
-    final void updateOomAdjLocked() {
-        final ActivityRecord TOP_ACT = resumedAppLocked();
-        final ProcessRecord TOP_APP = TOP_ACT != null ? TOP_ACT.app : null;
-        final long now = SystemClock.uptimeMillis();
-        final long oldTime = now - ProcessList.MAX_EMPTY_TIME;
-        final int N = mLruProcesses.size();
-
-        if (false) {
-            RuntimeException e = new RuntimeException();
-            e.fillInStackTrace();
-            Slog.i(TAG, "updateOomAdj: top=" + TOP_ACT, e);
-        }
-
-        mAdjSeq++;
-        mNewNumServiceProcs = 0;
-        mNewNumAServiceProcs = 0;
-
-        final int emptyProcessLimit;
-        final int cachedProcessLimit;
-        if (mProcessLimit <= 0) {
-            emptyProcessLimit = cachedProcessLimit = 0;
-        } else if (mProcessLimit == 1) {
-            emptyProcessLimit = 1;
-            cachedProcessLimit = 0;
-        } else {
-            emptyProcessLimit = ProcessList.computeEmptyProcessLimit(mProcessLimit);
-            cachedProcessLimit = mProcessLimit - emptyProcessLimit;
-        }
-
-        // Let's determine how many processes we have running vs.
-        // how many slots we have for background processes; we may want
-        // to put multiple processes in a slot of there are enough of
-        // them.
-        int numSlots = (ProcessList.CACHED_APP_MAX_ADJ
-                - ProcessList.CACHED_APP_MIN_ADJ + 1) / 2;
-        int numEmptyProcs = N - mNumNonCachedProcs - mNumCachedHiddenProcs;
-        if (numEmptyProcs > cachedProcessLimit) {
-            // If there are more empty processes than our limit on cached
-            // processes, then use the cached process limit for the factor.
-            // This ensures that the really old empty processes get pushed
-            // down to the bottom, so if we are running low on memory we will
-            // have a better chance at keeping around more cached processes
-            // instead of a gazillion empty processes.
-            numEmptyProcs = cachedProcessLimit;
-        }
-        int emptyFactor = numEmptyProcs/numSlots;
-        if (emptyFactor < 1) emptyFactor = 1;
-        int cachedFactor = (mNumCachedHiddenProcs > 0 ? mNumCachedHiddenProcs : 1)/numSlots;
-        if (cachedFactor < 1) cachedFactor = 1;
-        int stepCached = 0;
-        int stepEmpty = 0;
-        int numCached = 0;
-        int numEmpty = 0;
-        int numTrimming = 0;
-
-        mNumNonCachedProcs = 0;
-        mNumCachedHiddenProcs = 0;
-
-        // First update the OOM adjustment for each of the
-        // application processes based on their current state.
-        int curCachedAdj = ProcessList.CACHED_APP_MIN_ADJ;
-        int nextCachedAdj = curCachedAdj+1;
-        int curEmptyAdj = ProcessList.CACHED_APP_MIN_ADJ;
-        int nextEmptyAdj = curEmptyAdj+2;
-        for (int i=N-1; i>=0; i--) {
-            ProcessRecord app = mLruProcesses.get(i);
-            if (!app.killedByAm && app.thread != null) {
-                app.procStateChanged = false;
-                final boolean wasKeeping = app.keeping;
-                computeOomAdjLocked(app, ProcessList.UNKNOWN_ADJ, TOP_APP, true, now);
-
-                // If we haven't yet assigned the final cached adj
-                // to the process, do that now.
-                if (app.curAdj >= ProcessList.UNKNOWN_ADJ) {
-                    switch (app.curProcState) {
-                        case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY:
-                        case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
-                            // This process is a cached process holding activities...
-                            // assign it the next cached value for that type, and then
-                            // step that cached level.
-                            app.curRawAdj = curCachedAdj;
-                            app.curAdj = app.modifyRawOomAdj(curCachedAdj);
-                            if (DEBUG_LRU && false) Slog.d(TAG, "Assigning activity LRU #" + i
-                                    + " adj: " + app.curAdj + " (curCachedAdj=" + curCachedAdj
-                                    + ")");
-                            if (curCachedAdj != nextCachedAdj) {
-                                stepCached++;
-                                if (stepCached >= cachedFactor) {
-                                    stepCached = 0;
-                                    curCachedAdj = nextCachedAdj;
-                                    nextCachedAdj += 2;
-                                    if (nextCachedAdj > ProcessList.CACHED_APP_MAX_ADJ) {
-                                        nextCachedAdj = ProcessList.CACHED_APP_MAX_ADJ;
-                                    }
-                                }
-                            }
-                            break;
-                        default:
-                            // For everything else, assign next empty cached process
-                            // level and bump that up.  Note that this means that
-                            // long-running services that have dropped down to the
-                            // cached level will be treated as empty (since their process
-                            // state is still as a service), which is what we want.
-                            app.curRawAdj = curEmptyAdj;
-                            app.curAdj = app.modifyRawOomAdj(curEmptyAdj);
-                            if (DEBUG_LRU && false) Slog.d(TAG, "Assigning empty LRU #" + i
-                                    + " adj: " + app.curAdj + " (curEmptyAdj=" + curEmptyAdj
-                                    + ")");
-                            if (curEmptyAdj != nextEmptyAdj) {
-                                stepEmpty++;
-                                if (stepEmpty >= emptyFactor) {
-                                    stepEmpty = 0;
-                                    curEmptyAdj = nextEmptyAdj;
-                                    nextEmptyAdj += 2;
-                                    if (nextEmptyAdj > ProcessList.CACHED_APP_MAX_ADJ) {
-                                        nextEmptyAdj = ProcessList.CACHED_APP_MAX_ADJ;
-                                    }
-                                }
-                            }
-                            break;
-                    }
-                }
-
-                applyOomAdjLocked(app, wasKeeping, TOP_APP, true, false, now);
-
-                // Count the number of process types.
-                switch (app.curProcState) {
-                    case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY:
-                    case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
-                        mNumCachedHiddenProcs++;
-                        numCached++;
-                        if (numCached > cachedProcessLimit) {
-                            killUnneededProcessLocked(app, "cached #" + numCached);
-                        }
-                        break;
-                    case ActivityManager.PROCESS_STATE_CACHED_EMPTY:
-                        if (numEmpty > ProcessList.TRIM_EMPTY_APPS
-                                && app.lastActivityTime < oldTime) {
-                            killUnneededProcessLocked(app, "empty for "
-                                    + ((oldTime + ProcessList.MAX_EMPTY_TIME - app.lastActivityTime)
-                                    / 1000) + "s");
-                        } else {
-                            numEmpty++;
-                            if (numEmpty > emptyProcessLimit) {
-                                killUnneededProcessLocked(app, "empty #" + numEmpty);
-                            }
-                        }
-                        break;
-                    default:
-                        mNumNonCachedProcs++;
-                        break;
-                }
-
-                if (app.isolated && app.services.size() <= 0) {
-                    // If this is an isolated process, and there are no
-                    // services running in it, then the process is no longer
-                    // needed.  We agressively kill these because we can by
-                    // definition not re-use the same process again, and it is
-                    // good to avoid having whatever code was running in them
-                    // left sitting around after no longer needed.
-                    killUnneededProcessLocked(app, "isolated not needed");
-                }
-
-                if (app.curProcState >= ActivityManager.PROCESS_STATE_HOME
-                        && !app.killedByAm) {
-                    numTrimming++;
-                }
-            }
-        }
-
-        mNumServiceProcs = mNewNumServiceProcs;
-
-        // Now determine the memory trimming level of background processes.
-        // Unfortunately we need to start at the back of the list to do this
-        // properly.  We only do this if the number of background apps we
-        // are managing to keep around is less than half the maximum we desire;
-        // if we are keeping a good number around, we'll let them use whatever
-        // memory they want.
-        final int numCachedAndEmpty = numCached + numEmpty;
-        int memFactor;
-        if (numCached <= ProcessList.TRIM_CACHED_APPS
-                && numEmpty <= ProcessList.TRIM_EMPTY_APPS) {
-            if (numCachedAndEmpty <= ProcessList.TRIM_CRITICAL_THRESHOLD) {
-                memFactor = ProcessStats.ADJ_MEM_FACTOR_CRITICAL;
-            } else if (numCachedAndEmpty <= ProcessList.TRIM_LOW_THRESHOLD) {
-                memFactor = ProcessStats.ADJ_MEM_FACTOR_LOW;
-            } else {
-                memFactor = ProcessStats.ADJ_MEM_FACTOR_MODERATE;
-            }
-        } else {
-            memFactor = ProcessStats.ADJ_MEM_FACTOR_NORMAL;
-        }
-        // We always allow the memory level to go up (better).  We only allow it to go
-        // down if we are in a state where that is allowed, *and* the total number of processes
-        // has gone down since last time.
-        if (DEBUG_OOM_ADJ) Slog.d(TAG, "oom: memFactor=" + memFactor + " last=" + mLastMemoryLevel
-                + " allowLow=" + mAllowLowerMemLevel + " numProcs=" + mLruProcesses.size()
-                + " last=" + mLastNumProcesses);
-        if (memFactor > mLastMemoryLevel) {
-            if (!mAllowLowerMemLevel || mLruProcesses.size() >= mLastNumProcesses) {
-                memFactor = mLastMemoryLevel;
-                if (DEBUG_OOM_ADJ) Slog.d(TAG, "Keeping last mem factor!");
-            }
-        }
-        mLastMemoryLevel = memFactor;
-        mLastNumProcesses = mLruProcesses.size();
-        boolean allChanged = mProcessStats.setMemFactorLocked(memFactor, !mSleeping, now);
-        final int trackerMemFactor = mProcessStats.getMemFactorLocked();
-        if (memFactor != ProcessStats.ADJ_MEM_FACTOR_NORMAL) {
-            if (mLowRamStartTime == 0) {
-                mLowRamStartTime = now;
-            }
-            int step = 0;
-            int fgTrimLevel;
-            switch (memFactor) {
-                case ProcessStats.ADJ_MEM_FACTOR_CRITICAL:
-                    fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL;
-                    break;
-                case ProcessStats.ADJ_MEM_FACTOR_LOW:
-                    fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW;
-                    break;
-                default:
-                    fgTrimLevel = ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE;
-                    break;
-            }
-            int factor = numTrimming/3;
-            int minFactor = 2;
-            if (mHomeProcess != null) minFactor++;
-            if (mPreviousProcess != null) minFactor++;
-            if (factor < minFactor) factor = minFactor;
-            int curLevel = ComponentCallbacks2.TRIM_MEMORY_COMPLETE;
-            for (int i=N-1; i>=0; i--) {
-                ProcessRecord app = mLruProcesses.get(i);
-                if (allChanged || app.procStateChanged) {
-                    setProcessTrackerState(app, trackerMemFactor, now);
-                    app.procStateChanged = false;
-                }
-                if (app.curProcState >= ActivityManager.PROCESS_STATE_HOME
-                        && !app.killedByAm) {
-                    if (app.trimMemoryLevel < curLevel && app.thread != null) {
-                        try {
-                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                                    "Trimming memory of " + app.processName
-                                    + " to " + curLevel);
-                            app.thread.scheduleTrimMemory(curLevel);
-                        } catch (RemoteException e) {
-                        }
-                        if (false) {
-                            // For now we won't do this; our memory trimming seems
-                            // to be good enough at this point that destroying
-                            // activities causes more harm than good.
-                            if (curLevel >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE
-                                    && app != mHomeProcess && app != mPreviousProcess) {
-                                // Need to do this on its own message because the stack may not
-                                // be in a consistent state at this point.
-                                // For these apps we will also finish their activities
-                                // to help them free memory.
-                                mStackSupervisor.scheduleDestroyAllActivities(app, "trim");
-                            }
-                        }
-                    }
-                    app.trimMemoryLevel = curLevel;
-                    step++;
-                    if (step >= factor) {
-                        step = 0;
-                        switch (curLevel) {
-                            case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
-                                curLevel = ComponentCallbacks2.TRIM_MEMORY_MODERATE;
-                                break;
-                            case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
-                                curLevel = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND;
-                                break;
-                        }
-                    }
-                } else if (app.curProcState == ActivityManager.PROCESS_STATE_HEAVY_WEIGHT) {
-                    if (app.trimMemoryLevel < ComponentCallbacks2.TRIM_MEMORY_BACKGROUND
-                            && app.thread != null) {
-                        try {
-                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                                    "Trimming memory of heavy-weight " + app.processName
-                                    + " to " + ComponentCallbacks2.TRIM_MEMORY_BACKGROUND);
-                            app.thread.scheduleTrimMemory(
-                                    ComponentCallbacks2.TRIM_MEMORY_BACKGROUND);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                    app.trimMemoryLevel = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND;
-                } else {
-                    if ((app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
-                            || app.systemNoUi) && app.pendingUiClean) {
-                        // If this application is now in the background and it
-                        // had done UI, then give it the special trim level to
-                        // have it free UI resources.
-                        final int level = ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN;
-                        if (app.trimMemoryLevel < level && app.thread != null) {
-                            try {
-                                if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                                        "Trimming memory of bg-ui " + app.processName
-                                        + " to " + level);
-                                app.thread.scheduleTrimMemory(level);
-                            } catch (RemoteException e) {
-                            }
-                        }
-                        app.pendingUiClean = false;
-                    }
-                    if (app.trimMemoryLevel < fgTrimLevel && app.thread != null) {
-                        try {
-                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                                    "Trimming memory of fg " + app.processName
-                                    + " to " + fgTrimLevel);
-                            app.thread.scheduleTrimMemory(fgTrimLevel);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                    app.trimMemoryLevel = fgTrimLevel;
-                }
-            }
-        } else {
-            if (mLowRamStartTime != 0) {
-                mLowRamTimeSinceLastIdle += now - mLowRamStartTime;
-                mLowRamStartTime = 0;
-            }
-            for (int i=N-1; i>=0; i--) {
-                ProcessRecord app = mLruProcesses.get(i);
-                if (allChanged || app.procStateChanged) {
-                    setProcessTrackerState(app, trackerMemFactor, now);
-                    app.procStateChanged = false;
-                }
-                if ((app.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
-                        || app.systemNoUi) && app.pendingUiClean) {
-                    if (app.trimMemoryLevel < ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN
-                            && app.thread != null) {
-                        try {
-                            if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG,
-                                    "Trimming memory of ui hidden " + app.processName
-                                    + " to " + ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
-                            app.thread.scheduleTrimMemory(
-                                    ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                    app.pendingUiClean = false;
-                }
-                app.trimMemoryLevel = 0;
-            }
-        }
-
-        if (mAlwaysFinishActivities) {
-            // Need to do this on its own message because the stack may not
-            // be in a consistent state at this point.
-            mStackSupervisor.scheduleDestroyAllActivities(null, "always-finish");
-        }
-
-        if (allChanged) {
-            requestPssAllProcsLocked(now, false, mProcessStats.isMemFactorLowered());
-        }
-
-        if (mProcessStats.shouldWriteNowLocked(now)) {
-            mHandler.post(new Runnable() {
-                @Override public void run() {
-                    synchronized (ActivityManagerService.this) {
-                        mProcessStats.writeStateAsyncLocked();
-                    }
-                }
-            });
-        }
-
-        if (DEBUG_OOM_ADJ) {
-            Slog.d(TAG, "Did OOM ADJ in " + (SystemClock.uptimeMillis()-now) + "ms");
-        }
-    }
-
-    final void trimApplications() {
-        synchronized (this) {
-            int i;
-
-            // First remove any unused application processes whose package
-            // has been removed.
-            for (i=mRemovedProcesses.size()-1; i>=0; i--) {
-                final ProcessRecord app = mRemovedProcesses.get(i);
-                if (app.activities.size() == 0
-                        && app.curReceiver == null && app.services.size() == 0) {
-                    Slog.i(
-                        TAG, "Exiting empty application process "
-                        + app.processName + " ("
-                        + (app.thread != null ? app.thread.asBinder() : null)
-                        + ")\n");
-                    if (app.pid > 0 && app.pid != MY_PID) {
-                        EventLog.writeEvent(EventLogTags.AM_KILL, app.userId, app.pid,
-                                app.processName, app.setAdj, "empty");
-                        app.killedByAm = true;
-                        Process.killProcessQuiet(app.pid);
-                    } else {
-                        try {
-                            app.thread.scheduleExit();
-                        } catch (Exception e) {
-                            // Ignore exceptions.
-                        }
-                    }
-                    cleanUpApplicationRecordLocked(app, false, true, -1);
-                    mRemovedProcesses.remove(i);
-                    
-                    if (app.persistent) {
-                        if (app.persistent) {
-                            addAppLocked(app.info, false);
-                        }
-                    }
-                }
-            }
-
-            // Now update the oom adj for all processes.
-            updateOomAdjLocked();
-        }
-    }
-
-    /** This method sends the specified signal to each of the persistent apps */
-    public void signalPersistentProcesses(int sig) throws RemoteException {
-        if (sig != Process.SIGNAL_USR1) {
-            throw new SecurityException("Only SIGNAL_USR1 is allowed");
-        }
-
-        synchronized (this) {
-            if (checkCallingPermission(android.Manifest.permission.SIGNAL_PERSISTENT_PROCESSES)
-                    != PackageManager.PERMISSION_GRANTED) {
-                throw new SecurityException("Requires permission "
-                        + android.Manifest.permission.SIGNAL_PERSISTENT_PROCESSES);
-            }
-
-            for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
-                ProcessRecord r = mLruProcesses.get(i);
-                if (r.thread != null && r.persistent) {
-                    Process.sendSignal(r.pid, sig);
-                }
-            }
-        }
-    }
-
-    private void stopProfilerLocked(ProcessRecord proc, String path, int profileType) {
-        if (proc == null || proc == mProfileProc) {
-            proc = mProfileProc;
-            path = mProfileFile;
-            profileType = mProfileType;
-            clearProfilerLocked();
-        }
-        if (proc == null) {
-            return;
-        }
-        try {
-            proc.thread.profilerControl(false, path, null, profileType);
-        } catch (RemoteException e) {
-            throw new IllegalStateException("Process disappeared");
-        }
-    }
-
-    private void clearProfilerLocked() {
-        if (mProfileFd != null) {
-            try {
-                mProfileFd.close();
-            } catch (IOException e) {
-            }
-        }
-        mProfileApp = null;
-        mProfileProc = null;
-        mProfileFile = null;
-        mProfileType = 0;
-        mAutoStopProfiler = false;
-    }
-
-    public boolean profileControl(String process, int userId, boolean start,
-            String path, ParcelFileDescriptor fd, int profileType) throws RemoteException {
-
-        try {
-            synchronized (this) {
-                // note: hijacking SET_ACTIVITY_WATCHER, but should be changed to
-                // its own permission.
-                if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
-                        != PackageManager.PERMISSION_GRANTED) {
-                    throw new SecurityException("Requires permission "
-                            + android.Manifest.permission.SET_ACTIVITY_WATCHER);
-                }
-
-                if (start && fd == null) {
-                    throw new IllegalArgumentException("null fd");
-                }
-
-                ProcessRecord proc = null;
-                if (process != null) {
-                    proc = findProcessLocked(process, userId, "profileControl");
-                }
-
-                if (start && (proc == null || proc.thread == null)) {
-                    throw new IllegalArgumentException("Unknown process: " + process);
-                }
-
-                if (start) {
-                    stopProfilerLocked(null, null, 0);
-                    setProfileApp(proc.info, proc.processName, path, fd, false);
-                    mProfileProc = proc;
-                    mProfileType = profileType;
-                    try {
-                        fd = fd.dup();
-                    } catch (IOException e) {
-                        fd = null;
-                    }
-                    proc.thread.profilerControl(start, path, fd, profileType);
-                    fd = null;
-                    mProfileFd = null;
-                } else {
-                    stopProfilerLocked(proc, path, profileType);
-                    if (fd != null) {
-                        try {
-                            fd.close();
-                        } catch (IOException e) {
-                        }
-                    }
-                }
-
-                return true;
-            }
-        } catch (RemoteException e) {
-            throw new IllegalStateException("Process disappeared");
-        } finally {
-            if (fd != null) {
-                try {
-                    fd.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-    }
-
-    private ProcessRecord findProcessLocked(String process, int userId, String callName) {
-        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
-                userId, true, true, callName, null);
-        ProcessRecord proc = null;
-        try {
-            int pid = Integer.parseInt(process);
-            synchronized (mPidsSelfLocked) {
-                proc = mPidsSelfLocked.get(pid);
-            }
-        } catch (NumberFormatException e) {
-        }
-
-        if (proc == null) {
-            ArrayMap<String, SparseArray<ProcessRecord>> all
-                    = mProcessNames.getMap();
-            SparseArray<ProcessRecord> procs = all.get(process);
-            if (procs != null && procs.size() > 0) {
-                proc = procs.valueAt(0);
-                if (userId != UserHandle.USER_ALL && proc.userId != userId) {
-                    for (int i=1; i<procs.size(); i++) {
-                        ProcessRecord thisProc = procs.valueAt(i);
-                        if (thisProc.userId == userId) {
-                            proc = thisProc;
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-
-        return proc;
-    }
-
-    public boolean dumpHeap(String process, int userId, boolean managed,
-            String path, ParcelFileDescriptor fd) throws RemoteException {
-
-        try {
-            synchronized (this) {
-                // note: hijacking SET_ACTIVITY_WATCHER, but should be changed to
-                // its own permission (same as profileControl).
-                if (checkCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER)
-                        != PackageManager.PERMISSION_GRANTED) {
-                    throw new SecurityException("Requires permission "
-                            + android.Manifest.permission.SET_ACTIVITY_WATCHER);
-                }
-
-                if (fd == null) {
-                    throw new IllegalArgumentException("null fd");
-                }
-
-                ProcessRecord proc = findProcessLocked(process, userId, "dumpHeap");
-                if (proc == null || proc.thread == null) {
-                    throw new IllegalArgumentException("Unknown process: " + process);
-                }
-
-                boolean isDebuggable = "1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
-                if (!isDebuggable) {
-                    if ((proc.info.flags&ApplicationInfo.FLAG_DEBUGGABLE) == 0) {
-                        throw new SecurityException("Process not debuggable: " + proc);
-                    }
-                }
-
-                proc.thread.dumpHeap(managed, path, fd);
-                fd = null;
-                return true;
-            }
-        } catch (RemoteException e) {
-            throw new IllegalStateException("Process disappeared");
-        } finally {
-            if (fd != null) {
-                try {
-                    fd.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-    }
-
-    /** In this method we try to acquire our lock to make sure that we have not deadlocked */
-    public void monitor() {
-        synchronized (this) { }
-    }
-
-    void onCoreSettingsChange(Bundle settings) {
-        for (int i = mLruProcesses.size() - 1; i >= 0; i--) {
-            ProcessRecord processRecord = mLruProcesses.get(i);
-            try {
-                if (processRecord.thread != null) {
-                    processRecord.thread.setCoreSettings(settings);
-                }
-            } catch (RemoteException re) {
-                /* ignore */
-            }
-        }
-    }
-
-    // Multi-user methods
-
-    @Override
-    public boolean switchUser(final int userId) {
-        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: switchUser() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (this) {
-                final int oldUserId = mCurrentUserId;
-                if (oldUserId == userId) {
-                    return true;
-                }
-
-                final UserInfo userInfo = getUserManagerLocked().getUserInfo(userId);
-                if (userInfo == null) {
-                    Slog.w(TAG, "No user info for user #" + userId);
-                    return false;
-                }
-
-                mWindowManager.startFreezingScreen(R.anim.screen_user_exit,
-                        R.anim.screen_user_enter);
-
-                boolean needStart = false;
-
-                // If the user we are switching to is not currently started, then
-                // we need to start it now.
-                if (mStartedUsers.get(userId) == null) {
-                    mStartedUsers.put(userId, new UserStartedState(new UserHandle(userId), false));
-                    updateStartedUserArrayLocked();
-                    needStart = true;
-                }
-
-                mCurrentUserId = userId;
-                final Integer userIdInt = Integer.valueOf(userId);
-                mUserLru.remove(userIdInt);
-                mUserLru.add(userIdInt);
-
-                mWindowManager.setCurrentUser(userId);
-
-                // Once the internal notion of the active user has switched, we lock the device
-                // with the option to show the user switcher on the keyguard.
-                mWindowManager.lockNow(null);
-
-                final UserStartedState uss = mStartedUsers.get(userId);
-
-                // Make sure user is in the started state.  If it is currently
-                // stopping, we need to knock that off.
-                if (uss.mState == UserStartedState.STATE_STOPPING) {
-                    // If we are stopping, we haven't sent ACTION_SHUTDOWN,
-                    // so we can just fairly silently bring the user back from
-                    // the almost-dead.
-                    uss.mState = UserStartedState.STATE_RUNNING;
-                    updateStartedUserArrayLocked();
-                    needStart = true;
-                } else if (uss.mState == UserStartedState.STATE_SHUTDOWN) {
-                    // This means ACTION_SHUTDOWN has been sent, so we will
-                    // need to treat this as a new boot of the user.
-                    uss.mState = UserStartedState.STATE_BOOTING;
-                    updateStartedUserArrayLocked();
-                    needStart = true;
-                }
-
-                mHandler.removeMessages(REPORT_USER_SWITCH_MSG);
-                mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG);
-                mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_MSG,
-                        oldUserId, userId, uss));
-                mHandler.sendMessageDelayed(mHandler.obtainMessage(USER_SWITCH_TIMEOUT_MSG,
-                        oldUserId, userId, uss), USER_SWITCH_TIMEOUT);
-                if (needStart) {
-                    Intent intent = new Intent(Intent.ACTION_USER_STARTED);
-                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                            | Intent.FLAG_RECEIVER_FOREGROUND);
-                    intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
-                    broadcastIntentLocked(null, null, intent,
-                            null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                            false, false, MY_PID, Process.SYSTEM_UID, userId);
-                }
-
-                if ((userInfo.flags&UserInfo.FLAG_INITIALIZED) == 0) {
-                    if (userId != 0) {
-                        Intent intent = new Intent(Intent.ACTION_USER_INITIALIZE);
-                        intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
-                        broadcastIntentLocked(null, null, intent, null,
-                                new IIntentReceiver.Stub() {
-                                    public void performReceive(Intent intent, int resultCode,
-                                            String data, Bundle extras, boolean ordered,
-                                            boolean sticky, int sendingUser) {
-                                        userInitialized(uss, userId);
-                                    }
-                                }, 0, null, null, null, AppOpsManager.OP_NONE,
-                                true, false, MY_PID, Process.SYSTEM_UID,
-                                userId);
-                        uss.initializing = true;
-                    } else {
-                        getUserManagerLocked().makeInitialized(userInfo.id);
-                    }
-                }
-
-                boolean homeInFront = mStackSupervisor.switchUserLocked(userId, uss);
-                if (homeInFront) {
-                    startHomeActivityLocked(userId);
-                } else {
-                    mStackSupervisor.resumeTopActivitiesLocked();
-                }
-
-                EventLogTags.writeAmSwitchUser(userId);
-                getUserManagerLocked().userForeground(userId);
-                sendUserSwitchBroadcastsLocked(oldUserId, userId);
-                if (needStart) {
-                    Intent intent = new Intent(Intent.ACTION_USER_STARTING);
-                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-                    intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
-                    broadcastIntentLocked(null, null, intent,
-                            null, new IIntentReceiver.Stub() {
-                                @Override
-                                public void performReceive(Intent intent, int resultCode, String data,
-                                        Bundle extras, boolean ordered, boolean sticky, int sendingUser)
-                                        throws RemoteException {
-                                }
-                            }, 0, null, null,
-                            android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
-                            true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-
-        return true;
-    }
-
-    void sendUserSwitchBroadcastsLocked(int oldUserId, int newUserId) {
-        long ident = Binder.clearCallingIdentity();
-        try {
-            Intent intent;
-            if (oldUserId >= 0) {
-                intent = new Intent(Intent.ACTION_USER_BACKGROUND);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                        | Intent.FLAG_RECEIVER_FOREGROUND);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, oldUserId);
-                broadcastIntentLocked(null, null, intent,
-                        null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                        false, false, MY_PID, Process.SYSTEM_UID, oldUserId);
-            }
-            if (newUserId >= 0) {
-                intent = new Intent(Intent.ACTION_USER_FOREGROUND);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                        | Intent.FLAG_RECEIVER_FOREGROUND);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId);
-                broadcastIntentLocked(null, null, intent,
-                        null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                        false, false, MY_PID, Process.SYSTEM_UID, newUserId);
-                intent = new Intent(Intent.ACTION_USER_SWITCHED);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
-                        | Intent.FLAG_RECEIVER_FOREGROUND);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId);
-                broadcastIntentLocked(null, null, intent,
-                        null, null, 0, null, null,
-                        android.Manifest.permission.MANAGE_USERS, AppOpsManager.OP_NONE,
-                        false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    void dispatchUserSwitch(final UserStartedState uss, final int oldUserId,
-            final int newUserId) {
-        final int N = mUserSwitchObservers.beginBroadcast();
-        if (N > 0) {
-            final IRemoteCallback callback = new IRemoteCallback.Stub() {
-                int mCount = 0;
-                @Override
-                public void sendResult(Bundle data) throws RemoteException {
-                    synchronized (ActivityManagerService.this) {
-                        if (mCurUserSwitchCallback == this) {
-                            mCount++;
-                            if (mCount == N) {
-                                sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
-                            }
-                        }
-                    }
-                }
-            };
-            synchronized (this) {
-                uss.switching = true;
-                mCurUserSwitchCallback = callback;
-            }
-            for (int i=0; i<N; i++) {
-                try {
-                    mUserSwitchObservers.getBroadcastItem(i).onUserSwitching(
-                            newUserId, callback);
-                } catch (RemoteException e) {
-                }
-            }
-        } else {
-            synchronized (this) {
-                sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
-            }
-        }
-        mUserSwitchObservers.finishBroadcast();
-    }
-
-    void timeoutUserSwitch(UserStartedState uss, int oldUserId, int newUserId) {
-        synchronized (this) {
-            Slog.w(TAG, "User switch timeout: from " + oldUserId + " to " + newUserId);
-            sendContinueUserSwitchLocked(uss, oldUserId, newUserId);
-        }
-    }
-
-    void sendContinueUserSwitchLocked(UserStartedState uss, int oldUserId, int newUserId) {
-        mCurUserSwitchCallback = null;
-        mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG);
-        mHandler.sendMessage(mHandler.obtainMessage(CONTINUE_USER_SWITCH_MSG,
-                oldUserId, newUserId, uss));
-    }
-
-    void userInitialized(UserStartedState uss, int newUserId) {
-        completeSwitchAndInitalize(uss, newUserId, true, false);
-    }
-
-    void continueUserSwitch(UserStartedState uss, int oldUserId, int newUserId) {
-        completeSwitchAndInitalize(uss, newUserId, false, true);
-    }
-
-    void completeSwitchAndInitalize(UserStartedState uss, int newUserId,
-            boolean clearInitializing, boolean clearSwitching) {
-        boolean unfrozen = false;
-        synchronized (this) {
-            if (clearInitializing) {
-                uss.initializing = false;
-                getUserManagerLocked().makeInitialized(uss.mHandle.getIdentifier());
-            }
-            if (clearSwitching) {
-                uss.switching = false;
-            }
-            if (!uss.switching && !uss.initializing) {
-                mWindowManager.stopFreezingScreen();
-                unfrozen = true;
-            }
-        }
-        if (unfrozen) {
-            final int N = mUserSwitchObservers.beginBroadcast();
-            for (int i=0; i<N; i++) {
-                try {
-                    mUserSwitchObservers.getBroadcastItem(i).onUserSwitchComplete(newUserId);
-                } catch (RemoteException e) {
-                }
-            }
-            mUserSwitchObservers.finishBroadcast();
-        }
-    }
-
-    void finishUserSwitch(UserStartedState uss) {
-        synchronized (this) {
-            if (uss.mState == UserStartedState.STATE_BOOTING
-                    && mStartedUsers.get(uss.mHandle.getIdentifier()) == uss) {
-                uss.mState = UserStartedState.STATE_RUNNING;
-                final int userId = uss.mHandle.getIdentifier();
-                Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED, null);
-                intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
-                intent.addFlags(Intent.FLAG_RECEIVER_NO_ABORT);
-                broadcastIntentLocked(null, null, intent,
-                        null, null, 0, null, null,
-                        android.Manifest.permission.RECEIVE_BOOT_COMPLETED, AppOpsManager.OP_NONE,
-                        true, false, MY_PID, Process.SYSTEM_UID, userId);
-            }
-            int num = mUserLru.size();
-            int i = 0;
-            while (num > MAX_RUNNING_USERS && i < mUserLru.size()) {
-                Integer oldUserId = mUserLru.get(i);
-                UserStartedState oldUss = mStartedUsers.get(oldUserId);
-                if (oldUss == null) {
-                    // Shouldn't happen, but be sane if it does.
-                    mUserLru.remove(i);
-                    num--;
-                    continue;
-                }
-                if (oldUss.mState == UserStartedState.STATE_STOPPING
-                        || oldUss.mState == UserStartedState.STATE_SHUTDOWN) {
-                    // This user is already stopping, doesn't count.
-                    num--;
-                    i++;
-                    continue;
-                }
-                if (oldUserId == UserHandle.USER_OWNER || oldUserId == mCurrentUserId) {
-                    // Owner and current can't be stopped, but count as running.
-                    i++;
-                    continue;
-                }
-                // This is a user to be stopped.
-                stopUserLocked(oldUserId, null);
-                num--;
-                i++;
-            }
-        }
-    }
-
-    @Override
-    public int stopUser(final int userId, final IStopUserCallback callback) {
-        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: switchUser() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-        if (userId <= 0) {
-            throw new IllegalArgumentException("Can't stop primary user " + userId);
-        }
-        synchronized (this) {
-            return stopUserLocked(userId, callback);
-        }
-    }
-
-    private int stopUserLocked(final int userId, final IStopUserCallback callback) {
-        if (mCurrentUserId == userId) {
-            return ActivityManager.USER_OP_IS_CURRENT;
-        }
-
-        final UserStartedState uss = mStartedUsers.get(userId);
-        if (uss == null) {
-            // User is not started, nothing to do...  but we do need to
-            // callback if requested.
-            if (callback != null) {
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        try {
-                            callback.userStopped(userId);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                });
-            }
-            return ActivityManager.USER_OP_SUCCESS;
-        }
-
-        if (callback != null) {
-            uss.mStopCallbacks.add(callback);
-        }
-
-        if (uss.mState != UserStartedState.STATE_STOPPING
-                && uss.mState != UserStartedState.STATE_SHUTDOWN) {
-            uss.mState = UserStartedState.STATE_STOPPING;
-            updateStartedUserArrayLocked();
-
-            long ident = Binder.clearCallingIdentity();
-            try {
-                // We are going to broadcast ACTION_USER_STOPPING and then
-                // once that is done send a final ACTION_SHUTDOWN and then
-                // stop the user.
-                final Intent stoppingIntent = new Intent(Intent.ACTION_USER_STOPPING);
-                stoppingIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-                stoppingIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
-                stoppingIntent.putExtra(Intent.EXTRA_SHUTDOWN_USERSPACE_ONLY, true);
-                final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN);
-                // This is the result receiver for the final shutdown broadcast.
-                final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() {
-                    @Override
-                    public void performReceive(Intent intent, int resultCode, String data,
-                            Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
-                        finishUserStop(uss);
-                    }
-                };
-                // This is the result receiver for the initial stopping broadcast.
-                final IIntentReceiver stoppingReceiver = new IIntentReceiver.Stub() {
-                    @Override
-                    public void performReceive(Intent intent, int resultCode, String data,
-                            Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
-                        // On to the next.
-                        synchronized (ActivityManagerService.this) {
-                            if (uss.mState != UserStartedState.STATE_STOPPING) {
-                                // Whoops, we are being started back up.  Abort, abort!
-                                return;
-                            }
-                            uss.mState = UserStartedState.STATE_SHUTDOWN;
-                        }
-                        broadcastIntentLocked(null, null, shutdownIntent,
-                                null, shutdownReceiver, 0, null, null, null, AppOpsManager.OP_NONE,
-                                true, false, MY_PID, Process.SYSTEM_UID, userId);
-                    }
-                };
-                // Kick things off.
-                broadcastIntentLocked(null, null, stoppingIntent,
-                        null, stoppingReceiver, 0, null, null,
-                        android.Manifest.permission.INTERACT_ACROSS_USERS, AppOpsManager.OP_NONE,
-                        true, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-
-        return ActivityManager.USER_OP_SUCCESS;
-    }
-
-    void finishUserStop(UserStartedState uss) {
-        final int userId = uss.mHandle.getIdentifier();
-        boolean stopped;
-        ArrayList<IStopUserCallback> callbacks;
-        synchronized (this) {
-            callbacks = new ArrayList<IStopUserCallback>(uss.mStopCallbacks);
-            if (mStartedUsers.get(userId) != uss) {
-                stopped = false;
-            } else if (uss.mState != UserStartedState.STATE_SHUTDOWN) {
-                stopped = false;
-            } else {
-                stopped = true;
-                // User can no longer run.
-                mStartedUsers.remove(userId);
-                mUserLru.remove(Integer.valueOf(userId));
-                updateStartedUserArrayLocked();
-
-                // Clean up all state and processes associated with the user.
-                // Kill all the processes for the user.
-                forceStopUserLocked(userId, "finish user");
-            }
-        }
-
-        for (int i=0; i<callbacks.size(); i++) {
-            try {
-                if (stopped) callbacks.get(i).userStopped(userId);
-                else callbacks.get(i).userStopAborted(userId);
-            } catch (RemoteException e) {
-            }
-        }
-
-        mStackSupervisor.removeUserLocked(userId);
-    }
-
-    @Override
-    public UserInfo getCurrentUser() {
-        if ((checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
-                != PackageManager.PERMISSION_GRANTED) && (
-                checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
-                != PackageManager.PERMISSION_GRANTED)) {
-            String msg = "Permission Denial: getCurrentUser() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-        synchronized (this) {
-            return getUserManagerLocked().getUserInfo(mCurrentUserId);
-        }
-    }
-
-    int getCurrentUserIdLocked() {
-        return mCurrentUserId;
-    }
-
-    @Override
-    public boolean isUserRunning(int userId, boolean orStopped) {
-        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: isUserRunning() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-        synchronized (this) {
-            return isUserRunningLocked(userId, orStopped);
-        }
-    }
-
-    boolean isUserRunningLocked(int userId, boolean orStopped) {
-        UserStartedState state = mStartedUsers.get(userId);
-        if (state == null) {
-            return false;
-        }
-        if (orStopped) {
-            return true;
-        }
-        return state.mState != UserStartedState.STATE_STOPPING
-                && state.mState != UserStartedState.STATE_SHUTDOWN;
-    }
-
-    @Override
-    public int[] getRunningUserIds() {
-        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: isUserRunning() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-        synchronized (this) {
-            return mStartedUserArray;
-        }
-    }
-
-    private void updateStartedUserArrayLocked() {
-        int num = 0;
-        for (int i=0; i<mStartedUsers.size();  i++) {
-            UserStartedState uss = mStartedUsers.valueAt(i);
-            // This list does not include stopping users.
-            if (uss.mState != UserStartedState.STATE_STOPPING
-                    && uss.mState != UserStartedState.STATE_SHUTDOWN) {
-                num++;
-            }
-        }
-        mStartedUserArray = new int[num];
-        num = 0;
-        for (int i=0; i<mStartedUsers.size();  i++) {
-            UserStartedState uss = mStartedUsers.valueAt(i);
-            if (uss.mState != UserStartedState.STATE_STOPPING
-                    && uss.mState != UserStartedState.STATE_SHUTDOWN) {
-                mStartedUserArray[num] = mStartedUsers.keyAt(i);
-                num++;
-            }
-        }
-    }
-
-    @Override
-    public void registerUserSwitchObserver(IUserSwitchObserver observer) {
-        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
-                != PackageManager.PERMISSION_GRANTED) {
-            String msg = "Permission Denial: registerUserSwitchObserver() from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " requires " + android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        mUserSwitchObservers.register(observer);
-    }
-
-    @Override
-    public void unregisterUserSwitchObserver(IUserSwitchObserver observer) {
-        mUserSwitchObservers.unregister(observer);
-    }
-
-    private boolean userExists(int userId) {
-        if (userId == 0) {
-            return true;
-        }
-        UserManagerService ums = getUserManagerLocked();
-        return ums != null ? (ums.getUserInfo(userId) != null) : false;
-    }
-
-    int[] getUsersLocked() {
-        UserManagerService ums = getUserManagerLocked();
-        return ums != null ? ums.getUserIds() : new int[] { 0 };
-    }
-
-    UserManagerService getUserManagerLocked() {
-        if (mUserManager == null) {
-            IBinder b = ServiceManager.getService(Context.USER_SERVICE);
-            mUserManager = (UserManagerService)IUserManager.Stub.asInterface(b);
-        }
-        return mUserManager;
-    }
-
-    private int applyUserId(int uid, int userId) {
-        return UserHandle.getUid(userId, uid);
-    }
-
-    ApplicationInfo getAppInfoForUser(ApplicationInfo info, int userId) {
-        if (info == null) return null;
-        ApplicationInfo newInfo = new ApplicationInfo(info);
-        newInfo.uid = applyUserId(info.uid, userId);
-        newInfo.dataDir = USER_DATA_DIR + userId + "/"
-                + info.packageName;
-        return newInfo;
-    }
-
-    ActivityInfo getActivityInfoForUser(ActivityInfo aInfo, int userId) {
-        if (aInfo == null
-                || (userId < 1 && aInfo.applicationInfo.uid < UserHandle.PER_USER_RANGE)) {
-            return aInfo;
-        }
-
-        ActivityInfo info = new ActivityInfo(aInfo);
-        info.applicationInfo = getAppInfoForUser(info.applicationInfo, userId);
-        return info;
-    }
-}
diff --git a/services/java/com/android/server/am/ActivityRecord.java b/services/java/com/android/server/am/ActivityRecord.java
deleted file mode 100644
index 49f29fe..0000000
--- a/services/java/com/android/server/am/ActivityRecord.java
+++ /dev/null
@@ -1,1066 +0,0 @@
-/*
- * Copyright (C) 2006 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.os.Trace;
-import com.android.internal.R.styleable;
-import com.android.internal.app.ResolverActivity;
-import com.android.server.AttributeCache;
-import com.android.server.am.ActivityStack.ActivityState;
-
-import android.app.ActivityOptions;
-import android.app.ResultInfo;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.res.CompatibilityInfo;
-import android.content.res.Configuration;
-import android.graphics.Bitmap;
-import android.graphics.Rect;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Slog;
-import android.util.TimeUtils;
-import android.view.IApplicationToken;
-import android.view.WindowManager;
-
-import java.io.PrintWriter;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashSet;
-
-/**
- * An entry in the history stack, representing an activity.
- */
-final class ActivityRecord {
-    static final String TAG = ActivityManagerService.TAG;
-    static final boolean DEBUG_SAVED_STATE = ActivityStackSupervisor.DEBUG_SAVED_STATE;
-    final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recent";
-
-    final ActivityManagerService service; // owner
-    final IApplicationToken.Stub appToken; // window manager token
-    final ActivityInfo info; // all about me
-    final int launchedFromUid; // always the uid who started the activity.
-    final String launchedFromPackage; // always the package who started the activity.
-    final int userId;          // Which user is this running for?
-    final Intent intent;    // the original intent that generated us
-    final ComponentName realActivity;  // the intent component, or target of an alias.
-    final String shortComponentName; // the short component name of the intent
-    final String resolvedType; // as per original caller;
-    final String packageName; // the package implementing intent's component
-    final String processName; // process where this component wants to run
-    final String taskAffinity; // as per ActivityInfo.taskAffinity
-    final boolean stateNotNeeded; // As per ActivityInfo.flags
-    boolean fullscreen; // covers the full screen?
-    final boolean noDisplay;  // activity is not displayed?
-    final boolean componentSpecified;  // did caller specifiy an explicit component?
-
-    static final int APPLICATION_ACTIVITY_TYPE = 0;
-    static final int HOME_ACTIVITY_TYPE = 1;
-    static final int RECENTS_ACTIVITY_TYPE = 2;
-    int mActivityType;
-
-    final String baseDir;   // where activity source (resources etc) located
-    final String resDir;   // where public activity source (public resources etc) located
-    final String dataDir;   // where activity data should go
-    CharSequence nonLocalizedLabel;  // the label information from the package mgr.
-    int labelRes;           // the label information from the package mgr.
-    int icon;               // resource identifier of activity's icon.
-    int logo;               // resource identifier of activity's logo.
-    int theme;              // resource identifier of activity's theme.
-    int realTheme;          // actual theme resource we will use, never 0.
-    int windowFlags;        // custom window flags for preview window.
-    TaskRecord task;        // the task this is in.
-    ThumbnailHolder thumbHolder; // where our thumbnails should go.
-    long displayStartTime;  // when we started launching this activity
-    long fullyDrawnStartTime; // when we started launching this activity
-    long startTime;         // last time this activity was started
-    long lastVisibleTime;   // last time this activity became visible
-    long cpuTimeAtResume;   // the cpu time of host process at the time of resuming activity
-    long pauseTime;         // last time we started pausing the activity
-    long launchTickTime;    // base time for launch tick messages
-    Configuration configuration; // configuration activity was last running in
-    CompatibilityInfo compat;// last used compatibility mode
-    ActivityRecord resultTo; // who started this entry, so will get our reply
-    final String resultWho; // additional identifier for use by resultTo.
-    final int requestCode;  // code given by requester (resultTo)
-    ArrayList<ResultInfo> results; // pending ActivityResult objs we have received
-    HashSet<WeakReference<PendingIntentRecord>> pendingResults; // all pending intents for this act
-    ArrayList<Intent> newIntents; // any pending new intents for single-top mode
-    ActivityOptions pendingOptions; // most recently given options
-    HashSet<ConnectionRecord> connections; // All ConnectionRecord we hold
-    UriPermissionOwner uriPermissions; // current special URI access perms.
-    ProcessRecord app;      // if non-null, hosting application
-    ActivityState state;    // current state we are in
-    Bundle  icicle;         // last saved activity state
-    boolean frontOfTask;    // is this the root activity of its task?
-    boolean launchFailed;   // set if a launched failed, to abort on 2nd try
-    boolean haveState;      // have we gotten the last activity state?
-    boolean stopped;        // is activity pause finished?
-    boolean delayedResume;  // not yet resumed because of stopped app switches?
-    boolean finishing;      // activity in pending finish list?
-    boolean configDestroy;  // need to destroy due to config change?
-    int configChangeFlags;  // which config values have changed
-    boolean keysPaused;     // has key dispatching been paused for it?
-    int launchMode;         // the launch mode activity attribute.
-    boolean visible;        // does this activity's window need to be shown?
-    boolean sleeping;       // have we told the activity to sleep?
-    boolean waitingVisible; // true if waiting for a new act to become vis
-    boolean nowVisible;     // is this activity's window visible?
-    boolean thumbnailNeeded;// has someone requested a thumbnail?
-    boolean idle;           // has the activity gone idle?
-    boolean hasBeenLaunched;// has this activity ever been launched?
-    boolean frozenBeforeDestroy;// has been frozen but not yet destroyed.
-    boolean immersive;      // immersive mode (don't interrupt if possible)
-    boolean forceNewConfig; // force re-create with new config next time
-    int launchCount;        // count of launches since last state
-    long lastLaunchTime;    // time of last lauch of this activity
-
-    String stringName;      // for caching of toString().
-
-    private boolean inHistory;  // are we in the history stack?
-    final ActivityStackSupervisor mStackSupervisor;
-
-    void dump(PrintWriter pw, String prefix) {
-        final long now = SystemClock.uptimeMillis();
-        pw.print(prefix); pw.print("packageName="); pw.print(packageName);
-                pw.print(" processName="); pw.println(processName);
-        pw.print(prefix); pw.print("launchedFromUid="); pw.print(launchedFromUid);
-                pw.print(" launchedFromPackage="); pw.print(launchedFromPackage);
-                pw.print(" userId="); pw.println(userId);
-        pw.print(prefix); pw.print("app="); pw.println(app);
-        pw.print(prefix); pw.println(intent.toInsecureStringWithClip());
-        pw.print(prefix); pw.print("frontOfTask="); pw.print(frontOfTask);
-                pw.print(" task="); pw.println(task);
-        pw.print(prefix); pw.print("taskAffinity="); pw.println(taskAffinity);
-        pw.print(prefix); pw.print("realActivity=");
-                pw.println(realActivity.flattenToShortString());
-        pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
-        if (!resDir.equals(baseDir)) {
-            pw.print(prefix); pw.print("resDir="); pw.println(resDir);
-        }
-        pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
-        pw.print(prefix); pw.print("stateNotNeeded="); pw.print(stateNotNeeded);
-                pw.print(" componentSpecified="); pw.print(componentSpecified);
-                pw.print(" mActivityType="); pw.println(mActivityType);
-        pw.print(prefix); pw.print("compat="); pw.print(compat);
-                pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
-                pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
-                pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
-        pw.print(prefix); pw.print("config="); pw.println(configuration);
-        if (resultTo != null || resultWho != null) {
-            pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
-                    pw.print(" resultWho="); pw.print(resultWho);
-                    pw.print(" resultCode="); pw.println(requestCode);
-        }
-        if (results != null) {
-            pw.print(prefix); pw.print("results="); pw.println(results);
-        }
-        if (pendingResults != null && pendingResults.size() > 0) {
-            pw.print(prefix); pw.println("Pending Results:");
-            for (WeakReference<PendingIntentRecord> wpir : pendingResults) {
-                PendingIntentRecord pir = wpir != null ? wpir.get() : null;
-                pw.print(prefix); pw.print("  - ");
-                if (pir == null) {
-                    pw.println("null");
-                } else {
-                    pw.println(pir);
-                    pir.dump(pw, prefix + "    ");
-                }
-            }
-        }
-        if (newIntents != null && newIntents.size() > 0) {
-            pw.print(prefix); pw.println("Pending New Intents:");
-            for (int i=0; i<newIntents.size(); i++) {
-                Intent intent = newIntents.get(i);
-                pw.print(prefix); pw.print("  - ");
-                if (intent == null) {
-                    pw.println("null");
-                } else {
-                    pw.println(intent.toShortString(false, true, false, true));
-                }
-            }
-        }
-        if (pendingOptions != null) {
-            pw.print(prefix); pw.print("pendingOptions="); pw.println(pendingOptions);
-        }
-        if (uriPermissions != null) {
-            if (uriPermissions.readUriPermissions != null) {
-                pw.print(prefix); pw.print("readUriPermissions=");
-                        pw.println(uriPermissions.readUriPermissions);
-            }
-            if (uriPermissions.writeUriPermissions != null) {
-                pw.print(prefix); pw.print("writeUriPermissions=");
-                        pw.println(uriPermissions.writeUriPermissions);
-            }
-        }
-        pw.print(prefix); pw.print("launchFailed="); pw.print(launchFailed);
-                pw.print(" launchCount="); pw.print(launchCount);
-                pw.print(" lastLaunchTime=");
-                if (lastLaunchTime == 0) pw.print("0");
-                else TimeUtils.formatDuration(lastLaunchTime, now, pw);
-                pw.println();
-        pw.print(prefix); pw.print("haveState="); pw.print(haveState);
-                pw.print(" icicle="); pw.println(icicle);
-        pw.print(prefix); pw.print("state="); pw.print(state);
-                pw.print(" stopped="); pw.print(stopped);
-                pw.print(" delayedResume="); pw.print(delayedResume);
-                pw.print(" finishing="); pw.println(finishing);
-        pw.print(prefix); pw.print("keysPaused="); pw.print(keysPaused);
-                pw.print(" inHistory="); pw.print(inHistory);
-                pw.print(" visible="); pw.print(visible);
-                pw.print(" sleeping="); pw.print(sleeping);
-                pw.print(" idle="); pw.println(idle);
-        pw.print(prefix); pw.print("fullscreen="); pw.print(fullscreen);
-                pw.print(" noDisplay="); pw.print(noDisplay);
-                pw.print(" immersive="); pw.print(immersive);
-                pw.print(" launchMode="); pw.println(launchMode);
-        pw.print(prefix); pw.print("frozenBeforeDestroy="); pw.print(frozenBeforeDestroy);
-                pw.print(" thumbnailNeeded="); pw.print(thumbnailNeeded);
-                pw.print(" forceNewConfig="); pw.println(forceNewConfig);
-        pw.print(prefix); pw.print("mActivityType=");
-                pw.println(activityTypeToString(mActivityType));
-        pw.print(prefix); pw.print("thumbHolder: ");
-                pw.print(Integer.toHexString(System.identityHashCode(thumbHolder)));
-                if (thumbHolder != null) {
-                    pw.print(" bm="); pw.print(thumbHolder.lastThumbnail);
-                    pw.print(" desc="); pw.print(thumbHolder.lastDescription);
-                }
-                pw.println();
-        if (displayStartTime != 0 || startTime != 0) {
-            pw.print(prefix); pw.print("displayStartTime=");
-                    if (displayStartTime == 0) pw.print("0");
-                    else TimeUtils.formatDuration(displayStartTime, now, pw);
-                    pw.print(" startTime=");
-                    if (startTime == 0) pw.print("0");
-                    else TimeUtils.formatDuration(startTime, now, pw);
-                    pw.println();
-        }
-        if (lastVisibleTime != 0 || waitingVisible || nowVisible) {
-            pw.print(prefix); pw.print("waitingVisible="); pw.print(waitingVisible);
-                    pw.print(" nowVisible="); pw.print(nowVisible);
-                    pw.print(" lastVisibleTime=");
-                    if (lastVisibleTime == 0) pw.print("0");
-                    else TimeUtils.formatDuration(lastVisibleTime, now, pw);
-                    pw.println();
-        }
-        if (configDestroy || configChangeFlags != 0) {
-            pw.print(prefix); pw.print("configDestroy="); pw.print(configDestroy);
-                    pw.print(" configChangeFlags=");
-                    pw.println(Integer.toHexString(configChangeFlags));
-        }
-        if (connections != null) {
-            pw.print(prefix); pw.print("connections="); pw.println(connections);
-        }
-    }
-
-    static class Token extends IApplicationToken.Stub {
-        final WeakReference<ActivityRecord> weakActivity;
-
-        Token(ActivityRecord activity) {
-            weakActivity = new WeakReference<ActivityRecord>(activity);
-        }
-
-        @Override public void windowsDrawn() {
-            ActivityRecord activity = weakActivity.get();
-            if (activity != null) {
-                activity.windowsDrawn();
-            }
-        }
-
-        @Override public void windowsVisible() {
-            ActivityRecord activity = weakActivity.get();
-            if (activity != null) {
-                activity.windowsVisible();
-            }
-        }
-
-        @Override public void windowsGone() {
-            ActivityRecord activity = weakActivity.get();
-            if (activity != null) {
-                activity.windowsGone();
-            }
-        }
-
-        @Override public boolean keyDispatchingTimedOut(String reason) {
-            ActivityRecord activity = weakActivity.get();
-            return activity != null && activity.keyDispatchingTimedOut(reason);
-        }
-
-        @Override public long getKeyDispatchingTimeout() {
-            ActivityRecord activity = weakActivity.get();
-            if (activity != null) {
-                return activity.getKeyDispatchingTimeout();
-            }
-            return 0;
-        }
-
-        @Override
-        public String toString() {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("Token{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(' ');
-            sb.append(weakActivity.get());
-            sb.append('}');
-            return sb.toString();
-        }
-    }
-
-    static ActivityRecord forToken(IBinder token) {
-        try {
-            return token != null ? ((Token)token).weakActivity.get() : null;
-        } catch (ClassCastException e) {
-            Slog.w(ActivityManagerService.TAG, "Bad activity token: " + token, e);
-            return null;
-        }
-    }
-
-    boolean isNotResolverActivity() {
-        return !ResolverActivity.class.getName().equals(realActivity.getClassName());
-    }
-
-    ActivityRecord(ActivityManagerService _service, ProcessRecord _caller,
-            int _launchedFromUid, String _launchedFromPackage, Intent _intent, String _resolvedType,
-            ActivityInfo aInfo, Configuration _configuration,
-            ActivityRecord _resultTo, String _resultWho, int _reqCode,
-            boolean _componentSpecified, ActivityStackSupervisor supervisor) {
-        service = _service;
-        appToken = new Token(this);
-        info = aInfo;
-        launchedFromUid = _launchedFromUid;
-        launchedFromPackage = _launchedFromPackage;
-        userId = UserHandle.getUserId(aInfo.applicationInfo.uid);
-        intent = _intent;
-        shortComponentName = _intent.getComponent().flattenToShortString();
-        resolvedType = _resolvedType;
-        componentSpecified = _componentSpecified;
-        configuration = _configuration;
-        resultTo = _resultTo;
-        resultWho = _resultWho;
-        requestCode = _reqCode;
-        state = ActivityState.INITIALIZING;
-        frontOfTask = false;
-        launchFailed = false;
-        stopped = false;
-        delayedResume = false;
-        finishing = false;
-        configDestroy = false;
-        keysPaused = false;
-        inHistory = false;
-        visible = true;
-        waitingVisible = false;
-        nowVisible = false;
-        thumbnailNeeded = false;
-        idle = false;
-        hasBeenLaunched = false;
-        mStackSupervisor = supervisor;
-
-        // This starts out true, since the initial state of an activity
-        // is that we have everything, and we shouldn't never consider it
-        // lacking in state to be removed if it dies.
-        haveState = true;
-
-        if (aInfo != null) {
-            if (aInfo.targetActivity == null
-                    || aInfo.launchMode == ActivityInfo.LAUNCH_MULTIPLE
-                    || aInfo.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
-                realActivity = _intent.getComponent();
-            } else {
-                realActivity = new ComponentName(aInfo.packageName,
-                        aInfo.targetActivity);
-            }
-            taskAffinity = aInfo.taskAffinity;
-            stateNotNeeded = (aInfo.flags&
-                    ActivityInfo.FLAG_STATE_NOT_NEEDED) != 0;
-            baseDir = aInfo.applicationInfo.sourceDir;
-            resDir = aInfo.applicationInfo.publicSourceDir;
-            dataDir = aInfo.applicationInfo.dataDir;
-            nonLocalizedLabel = aInfo.nonLocalizedLabel;
-            labelRes = aInfo.labelRes;
-            if (nonLocalizedLabel == null && labelRes == 0) {
-                ApplicationInfo app = aInfo.applicationInfo;
-                nonLocalizedLabel = app.nonLocalizedLabel;
-                labelRes = app.labelRes;
-            }
-            icon = aInfo.getIconResource();
-            logo = aInfo.getLogoResource();
-            theme = aInfo.getThemeResource();
-            realTheme = theme;
-            if (realTheme == 0) {
-                realTheme = aInfo.applicationInfo.targetSdkVersion
-                        < Build.VERSION_CODES.HONEYCOMB
-                        ? android.R.style.Theme
-                        : android.R.style.Theme_Holo;
-            }
-            if ((aInfo.flags&ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
-                windowFlags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
-            }
-            if ((aInfo.flags&ActivityInfo.FLAG_MULTIPROCESS) != 0
-                    && _caller != null
-                    && (aInfo.applicationInfo.uid == Process.SYSTEM_UID
-                            || aInfo.applicationInfo.uid == _caller.info.uid)) {
-                processName = _caller.processName;
-            } else {
-                processName = aInfo.processName;
-            }
-
-            if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
-                intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-            }
-
-            packageName = aInfo.applicationInfo.packageName;
-            launchMode = aInfo.launchMode;
-
-            AttributeCache.Entry ent = AttributeCache.instance().get(packageName,
-                    realTheme, com.android.internal.R.styleable.Window, userId);
-            fullscreen = ent != null && !ent.array.getBoolean(
-                    com.android.internal.R.styleable.Window_windowIsFloating, false)
-                    && !ent.array.getBoolean(
-                    com.android.internal.R.styleable.Window_windowIsTranslucent, false);
-            noDisplay = ent != null && ent.array.getBoolean(
-                    com.android.internal.R.styleable.Window_windowNoDisplay, false);
-
-            if ((!_componentSpecified || _launchedFromUid == Process.myUid()
-                    || _launchedFromUid == 0) &&
-                    Intent.ACTION_MAIN.equals(_intent.getAction()) &&
-                    _intent.hasCategory(Intent.CATEGORY_HOME) &&
-                    _intent.getCategories().size() == 1 &&
-                    _intent.getData() == null &&
-                    _intent.getType() == null &&
-                    (intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
-                    isNotResolverActivity()) {
-                // This sure looks like a home activity!
-                mActivityType = HOME_ACTIVITY_TYPE;
-            } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
-                mActivityType = RECENTS_ACTIVITY_TYPE;
-            } else {
-                mActivityType = APPLICATION_ACTIVITY_TYPE;
-            }
-
-            immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0;
-        } else {
-            realActivity = null;
-            taskAffinity = null;
-            stateNotNeeded = false;
-            baseDir = null;
-            resDir = null;
-            dataDir = null;
-            processName = null;
-            packageName = null;
-            fullscreen = true;
-            noDisplay = false;
-            mActivityType = APPLICATION_ACTIVITY_TYPE;
-            immersive = false;
-        }
-    }
-
-    void setTask(TaskRecord newTask, ThumbnailHolder newThumbHolder, boolean isRoot) {
-        if (task != null && task.removeActivity(this)) {
-            if (task != newTask) {
-                mStackSupervisor.removeTask(task);
-            } else {
-                Slog.d(TAG, "!!! REMOVE THIS LOG !!! setTask: nearly removed stack=" +
-                        (newTask == null ? null : newTask.stack));
-            }
-        }
-        if (inHistory && !finishing) {
-            if (task != null) {
-                task.numActivities--;
-            }
-            if (newTask != null) {
-                newTask.numActivities++;
-            }
-        }
-        if (newThumbHolder == null) {
-            newThumbHolder = newTask;
-        }
-        task = newTask;
-        if (!isRoot && (intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
-            // This is the start of a new sub-task.
-            if (thumbHolder == null) {
-                thumbHolder = new ThumbnailHolder();
-            }
-        } else {
-            thumbHolder = newThumbHolder;
-        }
-    }
-
-    boolean changeWindowTranslucency(boolean toOpaque) {
-        if (fullscreen == toOpaque) {
-            return false;
-        }
-        AttributeCache.Entry ent =
-                AttributeCache.instance().get(packageName, realTheme, styleable.Window, userId);
-        if (ent == null
-                || !ent.array.getBoolean(styleable.Window_windowIsTranslucent, false)
-                || ent.array.getBoolean(styleable.Window_windowIsFloating, false)) {
-            return false;
-        }
-
-        // Keep track of the number of fullscreen activities in this task.
-        task.numFullscreen += toOpaque ? +1 : -1;
-
-        fullscreen = toOpaque;
-        return true;
-    }
-
-    void putInHistory() {
-        if (!inHistory) {
-            inHistory = true;
-            if (task != null && !finishing) {
-                task.numActivities++;
-            }
-        }
-    }
-
-    void takeFromHistory() {
-        if (inHistory) {
-            inHistory = false;
-            if (task != null && !finishing) {
-                task.numActivities--;
-                task = null;
-            }
-            clearOptionsLocked();
-        }
-    }
-
-    boolean isInHistory() {
-        return inHistory;
-    }
-
-    boolean isHomeActivity() {
-        return mActivityType == HOME_ACTIVITY_TYPE;
-    }
-
-    boolean isRecentsActivity() {
-        return mActivityType == RECENTS_ACTIVITY_TYPE;
-    }
-
-    boolean isApplicationActivity() {
-        return mActivityType == APPLICATION_ACTIVITY_TYPE;
-    }
-
-    void makeFinishing() {
-        if (!finishing) {
-            finishing = true;
-            if (task != null && inHistory) {
-                task.numActivities--;
-            }
-            if (stopped) {
-                clearOptionsLocked();
-            }
-        }
-    }
-
-    boolean isRootActivity() {
-        final ArrayList<ActivityRecord> activities = task.mActivities;
-        return activities.size() == 0 || this == activities.get(0);
-    }
-
-    UriPermissionOwner getUriPermissionsLocked() {
-        if (uriPermissions == null) {
-            uriPermissions = new UriPermissionOwner(service, this);
-        }
-        return uriPermissions;
-    }
-
-    void addResultLocked(ActivityRecord from, String resultWho,
-            int requestCode, int resultCode,
-            Intent resultData) {
-        ActivityResult r = new ActivityResult(from, resultWho,
-        		requestCode, resultCode, resultData);
-        if (results == null) {
-            results = new ArrayList<ResultInfo>();
-        }
-        results.add(r);
-    }
-
-    void removeResultsLocked(ActivityRecord from, String resultWho,
-            int requestCode) {
-        if (results != null) {
-            for (int i=results.size()-1; i>=0; i--) {
-                ActivityResult r = (ActivityResult)results.get(i);
-                if (r.mFrom != from) continue;
-                if (r.mResultWho == null) {
-                    if (resultWho != null) continue;
-                } else {
-                    if (!r.mResultWho.equals(resultWho)) continue;
-                }
-                if (r.mRequestCode != requestCode) continue;
-
-                results.remove(i);
-            }
-        }
-    }
-
-    void addNewIntentLocked(Intent intent) {
-        if (newIntents == null) {
-            newIntents = new ArrayList<Intent>();
-        }
-        newIntents.add(intent);
-    }
-
-    /**
-     * Deliver a new Intent to an existing activity, so that its onNewIntent()
-     * method will be called at the proper time.
-     */
-    final void deliverNewIntentLocked(int callingUid, Intent intent) {
-        // The activity now gets access to the data associated with this Intent.
-        service.grantUriPermissionFromIntentLocked(callingUid, packageName,
-                intent, getUriPermissionsLocked());
-        // We want to immediately deliver the intent to the activity if
-        // it is currently the top resumed activity...  however, if the
-        // device is sleeping, then all activities are stopped, so in that
-        // case we will deliver it if this is the current top activity on its
-        // stack.
-        boolean unsent = true;
-        if ((state == ActivityState.RESUMED || (service.mSleeping
-                        && task.stack.topRunningActivityLocked(null) == this))
-                && app != null && app.thread != null) {
-            try {
-                ArrayList<Intent> ar = new ArrayList<Intent>();
-                intent = new Intent(intent);
-                ar.add(intent);
-                app.thread.scheduleNewIntent(ar, appToken);
-                unsent = false;
-            } catch (RemoteException e) {
-                Slog.w(ActivityManagerService.TAG,
-                        "Exception thrown sending new intent to " + this, e);
-            } catch (NullPointerException e) {
-                Slog.w(ActivityManagerService.TAG,
-                        "Exception thrown sending new intent to " + this, e);
-            }
-        }
-        if (unsent) {
-            addNewIntentLocked(new Intent(intent));
-        }
-    }
-
-    void updateOptionsLocked(Bundle options) {
-        if (options != null) {
-            if (pendingOptions != null) {
-                pendingOptions.abort();
-            }
-            pendingOptions = new ActivityOptions(options);
-        }
-    }
-
-    void updateOptionsLocked(ActivityOptions options) {
-        if (options != null) {
-            if (pendingOptions != null) {
-                pendingOptions.abort();
-            }
-            pendingOptions = options;
-        }
-    }
-
-    void applyOptionsLocked() {
-        if (pendingOptions != null) {
-            final int animationType = pendingOptions.getAnimationType();
-            switch (animationType) {
-                case ActivityOptions.ANIM_CUSTOM:
-                    service.mWindowManager.overridePendingAppTransition(
-                            pendingOptions.getPackageName(),
-                            pendingOptions.getCustomEnterResId(),
-                            pendingOptions.getCustomExitResId(),
-                            pendingOptions.getOnAnimationStartListener());
-                    break;
-                case ActivityOptions.ANIM_SCALE_UP:
-                    service.mWindowManager.overridePendingAppTransitionScaleUp(
-                            pendingOptions.getStartX(), pendingOptions.getStartY(),
-                            pendingOptions.getStartWidth(), pendingOptions.getStartHeight());
-                    if (intent.getSourceBounds() == null) {
-                        intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
-                                pendingOptions.getStartY(),
-                                pendingOptions.getStartX()+pendingOptions.getStartWidth(),
-                                pendingOptions.getStartY()+pendingOptions.getStartHeight()));
-                    }
-                    break;
-                case ActivityOptions.ANIM_THUMBNAIL_SCALE_UP:
-                case ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN:
-                    boolean scaleUp = (animationType == ActivityOptions.ANIM_THUMBNAIL_SCALE_UP);
-                    service.mWindowManager.overridePendingAppTransitionThumb(
-                            pendingOptions.getThumbnail(),
-                            pendingOptions.getStartX(), pendingOptions.getStartY(),
-                            pendingOptions.getOnAnimationStartListener(),
-                            scaleUp);
-                    if (intent.getSourceBounds() == null) {
-                        intent.setSourceBounds(new Rect(pendingOptions.getStartX(),
-                                pendingOptions.getStartY(),
-                                pendingOptions.getStartX()
-                                        + pendingOptions.getThumbnail().getWidth(),
-                                pendingOptions.getStartY()
-                                        + pendingOptions.getThumbnail().getHeight()));
-                    }
-                    break;
-            }
-            pendingOptions = null;
-        }
-    }
-
-    void clearOptionsLocked() {
-        if (pendingOptions != null) {
-            pendingOptions.abort();
-            pendingOptions = null;
-        }
-    }
-
-    ActivityOptions takeOptionsLocked() {
-        ActivityOptions opts = pendingOptions;
-        pendingOptions = null;
-        return opts;
-    }
-
-    void removeUriPermissionsLocked() {
-        if (uriPermissions != null) {
-            uriPermissions.removeUriPermissionsLocked();
-            uriPermissions = null;
-        }
-    }
-
-    void pauseKeyDispatchingLocked() {
-        if (!keysPaused) {
-            keysPaused = true;
-            service.mWindowManager.pauseKeyDispatching(appToken);
-        }
-    }
-
-    void resumeKeyDispatchingLocked() {
-        if (keysPaused) {
-            keysPaused = false;
-            service.mWindowManager.resumeKeyDispatching(appToken);
-        }
-    }
-
-    void updateThumbnail(Bitmap newThumbnail, CharSequence description) {
-        if (thumbHolder != null) {
-            if (newThumbnail != null) {
-                if (ActivityManagerService.DEBUG_THUMBNAILS) Slog.i(ActivityManagerService.TAG,
-                        "Setting thumbnail of " + this + " holder " + thumbHolder
-                        + " to " + newThumbnail);
-                thumbHolder.lastThumbnail = newThumbnail;
-            }
-            thumbHolder.lastDescription = description;
-        }
-    }
-
-    void startLaunchTickingLocked() {
-        if (ActivityManagerService.IS_USER_BUILD) {
-            return;
-        }
-        if (launchTickTime == 0) {
-            launchTickTime = SystemClock.uptimeMillis();
-            continueLaunchTickingLocked();
-        }
-    }
-
-    boolean continueLaunchTickingLocked() {
-        if (launchTickTime != 0) {
-            final ActivityStack stack = task.stack;
-            Message msg = stack.mHandler.obtainMessage(ActivityStack.LAUNCH_TICK_MSG, this);
-            stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
-            stack.mHandler.sendMessageDelayed(msg, ActivityStack.LAUNCH_TICK);
-            return true;
-        }
-        return false;
-    }
-
-    void finishLaunchTickingLocked() {
-        launchTickTime = 0;
-        task.stack.mHandler.removeMessages(ActivityStack.LAUNCH_TICK_MSG);
-    }
-
-    // IApplicationToken
-
-    public boolean mayFreezeScreenLocked(ProcessRecord app) {
-        // Only freeze the screen if this activity is currently attached to
-        // an application, and that application is not blocked or unresponding.
-        // In any other case, we can't count on getting the screen unfrozen,
-        // so it is best to leave as-is.
-        return app != null && !app.crashing && !app.notResponding;
-    }
-
-    public void startFreezingScreenLocked(ProcessRecord app, int configChanges) {
-        if (mayFreezeScreenLocked(app)) {
-            service.mWindowManager.startAppFreezingScreen(appToken, configChanges);
-        }
-    }
-
-    public void stopFreezingScreenLocked(boolean force) {
-        if (force || frozenBeforeDestroy) {
-            frozenBeforeDestroy = false;
-            service.mWindowManager.stopAppFreezingScreen(appToken, force);
-        }
-    }
-
-    public void reportFullyDrawnLocked() {
-        final long curTime = SystemClock.uptimeMillis();
-        if (displayStartTime != 0) {
-            reportLaunchTimeLocked(curTime);
-        }
-        if (fullyDrawnStartTime != 0) {
-            final ActivityStack stack = task.stack;
-            final long thisTime = curTime - fullyDrawnStartTime;
-            final long totalTime = stack.mFullyDrawnStartTime != 0
-                    ? (curTime - stack.mFullyDrawnStartTime) : thisTime;
-            if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
-                Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
-                EventLog.writeEvent(EventLogTags.AM_ACTIVITY_FULLY_DRAWN_TIME,
-                        userId, System.identityHashCode(this), shortComponentName,
-                        thisTime, totalTime);
-                StringBuilder sb = service.mStringBuilder;
-                sb.setLength(0);
-                sb.append("Fully drawn ");
-                sb.append(shortComponentName);
-                sb.append(": ");
-                TimeUtils.formatDuration(thisTime, sb);
-                if (thisTime != totalTime) {
-                    sb.append(" (total ");
-                    TimeUtils.formatDuration(totalTime, sb);
-                    sb.append(")");
-                }
-                Log.i(ActivityManagerService.TAG, sb.toString());
-            }
-            if (totalTime > 0) {
-                service.mUsageStatsService.noteFullyDrawnTime(realActivity, (int) totalTime);
-            }
-            fullyDrawnStartTime = 0;
-            stack.mFullyDrawnStartTime = 0;
-        }
-    }
-
-    private void reportLaunchTimeLocked(final long curTime) {
-        final ActivityStack stack = task.stack;
-        final long thisTime = curTime - displayStartTime;
-        final long totalTime = stack.mLaunchStartTime != 0
-                ? (curTime - stack.mLaunchStartTime) : thisTime;
-        if (ActivityManagerService.SHOW_ACTIVITY_START_TIME) {
-            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
-            EventLog.writeEvent(EventLogTags.AM_ACTIVITY_LAUNCH_TIME,
-                    userId, System.identityHashCode(this), shortComponentName,
-                    thisTime, totalTime);
-            StringBuilder sb = service.mStringBuilder;
-            sb.setLength(0);
-            sb.append("Displayed ");
-            sb.append(shortComponentName);
-            sb.append(": ");
-            TimeUtils.formatDuration(thisTime, sb);
-            if (thisTime != totalTime) {
-                sb.append(" (total ");
-                TimeUtils.formatDuration(totalTime, sb);
-                sb.append(")");
-            }
-            Log.i(ActivityManagerService.TAG, sb.toString());
-        }
-        mStackSupervisor.reportActivityLaunchedLocked(false, this, thisTime, totalTime);
-        if (totalTime > 0) {
-            service.mUsageStatsService.noteLaunchTime(realActivity, (int)totalTime);
-        }
-        displayStartTime = 0;
-        stack.mLaunchStartTime = 0;
-    }
-
-    public void windowsDrawn() {
-        synchronized(service) {
-            if (displayStartTime != 0) {
-                reportLaunchTimeLocked(SystemClock.uptimeMillis());
-            }
-            startTime = 0;
-            finishLaunchTickingLocked();
-        }
-    }
-
-    public void windowsVisible() {
-        synchronized(service) {
-            mStackSupervisor.reportActivityVisibleLocked(this);
-            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
-                    ActivityManagerService.TAG, "windowsVisible(): " + this);
-            if (!nowVisible) {
-                nowVisible = true;
-                lastVisibleTime = SystemClock.uptimeMillis();
-                if (!idle) {
-                    // Instead of doing the full stop routine here, let's just
-                    // hide any activities we now can, and let them stop when
-                    // the normal idle happens.
-                    mStackSupervisor.processStoppingActivitiesLocked(false);
-                } else {
-                    // If this activity was already idle, then we now need to
-                    // make sure we perform the full stop of any activities
-                    // that are waiting to do so.  This is because we won't
-                    // do that while they are still waiting for this one to
-                    // become visible.
-                    final int N = mStackSupervisor.mWaitingVisibleActivities.size();
-                    if (N > 0) {
-                        for (int i=0; i<N; i++) {
-                            ActivityRecord r = mStackSupervisor.mWaitingVisibleActivities.get(i);
-                            r.waitingVisible = false;
-                            if (ActivityManagerService.DEBUG_SWITCH) Log.v(
-                                    ActivityManagerService.TAG,
-                                    "Was waiting for visible: " + r);
-                        }
-                        mStackSupervisor.mWaitingVisibleActivities.clear();
-                        mStackSupervisor.scheduleIdleLocked();
-                    }
-                }
-                service.scheduleAppGcsLocked();
-            }
-        }
-    }
-
-    public void windowsGone() {
-        if (ActivityManagerService.DEBUG_SWITCH) Log.v(
-                ActivityManagerService.TAG, "windowsGone(): " + this);
-        nowVisible = false;
-    }
-
-    private ActivityRecord getWaitingHistoryRecordLocked() {
-        // First find the real culprit...  if we are waiting
-        // for another app to start, then we have paused dispatching
-        // for this activity.
-        ActivityRecord r = this;
-        final ActivityStack stack = task.stack;
-        if (r.waitingVisible) {
-            // Hmmm, who might we be waiting for?
-            r = stack.mResumedActivity;
-            if (r == null) {
-                r = stack.mPausingActivity;
-            }
-            // Both of those null?  Fall back to 'this' again
-            if (r == null) {
-                r = this;
-            }
-        }
-
-        return r;
-    }
-
-    public boolean keyDispatchingTimedOut(String reason) {
-        ActivityRecord r;
-        ProcessRecord anrApp;
-        synchronized(service) {
-            r = getWaitingHistoryRecordLocked();
-            anrApp = r != null ? r.app : null;
-        }
-        return service.inputDispatchingTimedOut(anrApp, r, this, false, reason);
-    }
-
-    /** Returns the key dispatching timeout for this application token. */
-    public long getKeyDispatchingTimeout() {
-        synchronized(service) {
-            ActivityRecord r = getWaitingHistoryRecordLocked();
-            return ActivityManagerService.getInputDispatchingTimeoutLocked(r);
-        }
-    }
-
-    /**
-     * This method will return true if the activity is either visible, is becoming visible, is
-     * currently pausing, or is resumed.
-     */
-    public boolean isInterestingToUserLocked() {
-        return visible || nowVisible || state == ActivityState.PAUSING ||
-                state == ActivityState.RESUMED;
-    }
-
-    public void setSleeping(boolean _sleeping) {
-        if (sleeping == _sleeping) {
-            return;
-        }
-        if (app != null && app.thread != null) {
-            try {
-                app.thread.scheduleSleeping(appToken, _sleeping);
-                if (_sleeping && !mStackSupervisor.mGoingToSleepActivities.contains(this)) {
-                    mStackSupervisor.mGoingToSleepActivities.add(this);
-                }
-                sleeping = _sleeping;
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Exception thrown when sleeping: " + intent.getComponent(), e);
-            }
-        }
-    }
-
-    static void activityResumedLocked(IBinder token) {
-        final ActivityRecord r = ActivityRecord.forToken(token);
-        if (DEBUG_SAVED_STATE) Slog.i(TAG, "Resumed activity; dropping state of: " + r);
-        r.icicle = null;
-        r.haveState = false;
-    }
-
-    static int getTaskForActivityLocked(IBinder token, boolean onlyRoot) {
-        final ActivityRecord r = ActivityRecord.forToken(token);
-        if (r == null) {
-            return -1;
-        }
-        final TaskRecord task = r.task;
-        switch (task.mActivities.indexOf(r)) {
-            case -1: return -1;
-            case 0: return task.taskId;
-            default: return onlyRoot ? -1 : task.taskId;
-        }
-    }
-
-    static ActivityRecord isInStackLocked(IBinder token) {
-        final ActivityRecord r = ActivityRecord.forToken(token);
-        if (r != null) {
-            return r.task.stack.isInStackLocked(token);
-        }
-        return null;
-    }
-
-    static ActivityStack getStackLocked(IBinder token) {
-        final ActivityRecord r = ActivityRecord.isInStackLocked(token);
-        if (r != null) {
-            return r.task.stack;
-        }
-        return null;
-    }
-
-    private String activityTypeToString(int type) {
-        switch (type) {
-            case APPLICATION_ACTIVITY_TYPE: return "APPLICATION_ACTIVITY_TYPE";
-            case HOME_ACTIVITY_TYPE: return "HOME_ACTIVITY_TYPE";
-            case RECENTS_ACTIVITY_TYPE: return "RECENTS_ACTIVITY_TYPE";
-            default: return Integer.toString(type);
-        }
-    }
-
-    @Override
-    public String toString() {
-        if (stringName != null) {
-            return stringName + " t" + (task == null ? -1 : task.taskId) +
-                    (finishing ? " f}" : "}");
-        }
-        StringBuilder sb = new StringBuilder(128);
-        sb.append("ActivityRecord{");
-        sb.append(Integer.toHexString(System.identityHashCode(this)));
-        sb.append(" u");
-        sb.append(userId);
-        sb.append(' ');
-        sb.append(intent.getComponent().flattenToShortString());
-        stringName = sb.toString();
-        return toString();
-    }
-}
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
deleted file mode 100644
index 0e152611..0000000
--- a/services/java/com/android/server/am/ActivityStack.java
+++ /dev/null
@@ -1,3641 +0,0 @@
-/*
- * Copyright (C) 2010 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 static com.android.server.am.ActivityManagerService.TAG;
-import static com.android.server.am.ActivityManagerService.localLOGV;
-import static com.android.server.am.ActivityManagerService.DEBUG_CLEANUP;
-import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION;
-import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE;
-import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS;
-import static com.android.server.am.ActivityManagerService.DEBUG_STACK;
-import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH;
-import static com.android.server.am.ActivityManagerService.DEBUG_TASKS;
-import static com.android.server.am.ActivityManagerService.DEBUG_TRANSITION;
-import static com.android.server.am.ActivityManagerService.DEBUG_USER_LEAVING;
-import static com.android.server.am.ActivityManagerService.DEBUG_VISBILITY;
-import static com.android.server.am.ActivityManagerService.VALIDATE_TOKENS;
-
-import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
-import static com.android.server.am.ActivityStackSupervisor.DEBUG_APP;
-import static com.android.server.am.ActivityStackSupervisor.DEBUG_SAVED_STATE;
-import static com.android.server.am.ActivityStackSupervisor.DEBUG_STATES;
-import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
-
-import com.android.internal.os.BatteryStatsImpl;
-import com.android.internal.util.Objects;
-import com.android.server.Watchdog;
-import com.android.server.am.ActivityManagerService.ItemMatcher;
-import com.android.server.wm.AppTransition;
-import com.android.server.wm.TaskGroup;
-import com.android.server.wm.WindowManagerService;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.ActivityOptions;
-import android.app.AppGlobals;
-import android.app.IActivityController;
-import android.app.IThumbnailReceiver;
-import android.app.ResultInfo;
-import android.app.ActivityManager.RunningTaskInfo;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Debug;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.Trace;
-import android.os.UserHandle;
-import android.util.EventLog;
-import android.util.Slog;
-import android.view.Display;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * State and management of a single stack of activities.
- */
-final class ActivityStack {
-
-    // Ticks during which we check progress while waiting for an app to launch.
-    static final int LAUNCH_TICK = 500;
-
-    // How long we wait until giving up on the last activity to pause.  This
-    // is short because it directly impacts the responsiveness of starting the
-    // next activity.
-    static final int PAUSE_TIMEOUT = 500;
-
-    // How long we wait for the activity to tell us it has stopped before
-    // giving up.  This is a good amount of time because we really need this
-    // from the application in order to get its saved state.
-    static final int STOP_TIMEOUT = 10*1000;
-
-    // How long we wait until giving up on an activity telling us it has
-    // finished destroying itself.
-    static final int DESTROY_TIMEOUT = 10*1000;
-
-    // How long until we reset a task when the user returns to it.  Currently
-    // disabled.
-    static final long ACTIVITY_INACTIVE_RESET_TIME = 0;
-
-    // How long between activity launches that we consider safe to not warn
-    // the user about an unexpected activity being launched on top.
-    static final long START_WARN_TIME = 5*1000;
-
-    // Set to false to disable the preview that is shown while a new activity
-    // is being started.
-    static final boolean SHOW_APP_STARTING_PREVIEW = true;
-
-    // How long to wait for all background Activities to redraw following a call to
-    // convertToTranslucent().
-    static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000;
-
-    static final boolean SCREENSHOT_FORCE_565 = ActivityManager
-            .isLowRamDeviceStatic() ? true : false;
-
-    enum ActivityState {
-        INITIALIZING,
-        RESUMED,
-        PAUSING,
-        PAUSED,
-        STOPPING,
-        STOPPED,
-        FINISHING,
-        DESTROYING,
-        DESTROYED
-    }
-
-    final ActivityManagerService mService;
-    final WindowManagerService mWindowManager;
-
-    final Context mContext;
-
-    /**
-     * The back history of all previous (and possibly still
-     * running) activities.  It contains #TaskRecord objects.
-     */
-    private ArrayList<TaskRecord> mTaskHistory = new ArrayList<TaskRecord>();
-
-    /**
-     * Used for validating app tokens with window manager.
-     */
-    final ArrayList<TaskGroup> mValidateAppTokens = new ArrayList<TaskGroup>();
-
-    /**
-     * List of running activities, sorted by recent usage.
-     * The first entry in the list is the least recently used.
-     * It contains HistoryRecord objects.
-     */
-    final ArrayList<ActivityRecord> mLRUActivities = new ArrayList<ActivityRecord>();
-
-    /**
-     * Animations that for the current transition have requested not to
-     * be considered for the transition animation.
-     */
-    final ArrayList<ActivityRecord> mNoAnimActivities = new ArrayList<ActivityRecord>();
-
-    /**
-     * When we are in the process of pausing an activity, before starting the
-     * next one, this variable holds the activity that is currently being paused.
-     */
-    ActivityRecord mPausingActivity = null;
-
-    /**
-     * This is the last activity that we put into the paused state.  This is
-     * used to determine if we need to do an activity transition while sleeping,
-     * when we normally hold the top activity paused.
-     */
-    ActivityRecord mLastPausedActivity = null;
-
-    /**
-     * Activities that specify No History must be removed once the user navigates away from them.
-     * If the device goes to sleep with such an activity in the paused state then we save it here
-     * and finish it later if another activity replaces it on wakeup.
-     */
-    ActivityRecord mLastNoHistoryActivity = null;
-
-    /**
-     * Current activity that is resumed, or null if there is none.
-     */
-    ActivityRecord mResumedActivity = null;
-
-    /**
-     * This is the last activity that has been started.  It is only used to
-     * identify when multiple activities are started at once so that the user
-     * can be warned they may not be in the activity they think they are.
-     */
-    ActivityRecord mLastStartedActivity = null;
-
-    // The topmost Activity passed to convertToTranslucent(). When non-null it means we are
-    // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they
-    // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the
-    // Activity in mTranslucentActivityWaiting is notified via
-    // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last
-    // background activity being drawn then the same call will be made with a true value.
-    ActivityRecord mTranslucentActivityWaiting = null;
-    ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent =
-            new ArrayList<ActivityRecord>();
-
-    /**
-     * Set when we know we are going to be calling updateConfiguration()
-     * soon, so want to skip intermediate config checks.
-     */
-    boolean mConfigWillChange;
-
-    long mLaunchStartTime = 0;
-    long mFullyDrawnStartTime = 0;
-
-    /**
-     * Save the most recent screenshot for reuse. This keeps Recents from taking two identical
-     * screenshots, one for the Recents thumbnail and one for the pauseActivity thumbnail.
-     */
-    private ActivityRecord mLastScreenshotActivity = null;
-    private Bitmap mLastScreenshotBitmap = null;
-
-    int mThumbnailWidth = -1;
-    int mThumbnailHeight = -1;
-
-    int mCurrentUser;
-
-    final int mStackId;
-
-    /** Run all ActivityStacks through this */
-    final ActivityStackSupervisor mStackSupervisor;
-
-    static final int PAUSE_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 1;
-    static final int DESTROY_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 2;
-    static final int LAUNCH_TICK_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 3;
-    static final int STOP_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 4;
-    static final int DESTROY_ACTIVITIES_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 5;
-    static final int TRANSLUCENT_TIMEOUT_MSG = ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 6;
-
-    static class ScheduleDestroyArgs {
-        final ProcessRecord mOwner;
-        final boolean mOomAdj;
-        final String mReason;
-        ScheduleDestroyArgs(ProcessRecord owner, boolean oomAdj, String reason) {
-            mOwner = owner;
-            mOomAdj = oomAdj;
-            mReason = reason;
-        }
-    }
-
-    final Handler mHandler;
-
-    final class ActivityStackHandler extends Handler {
-        //public Handler() {
-        //    if (localLOGV) Slog.v(TAG, "Handler started!");
-        //}
-        ActivityStackHandler(Looper looper) {
-            super(looper);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case PAUSE_TIMEOUT_MSG: {
-                    ActivityRecord r = (ActivityRecord)msg.obj;
-                    // We don't at this point know if the activity is fullscreen,
-                    // so we need to be conservative and assume it isn't.
-                    Slog.w(TAG, "Activity pause timeout for " + r);
-                    synchronized (mService) {
-                        if (r.app != null) {
-                            mService.logAppTooSlow(r.app, r.pauseTime, "pausing " + r);
-                        }
-                        activityPausedLocked(r.appToken, true);
-                    }
-                } break;
-                case LAUNCH_TICK_MSG: {
-                    ActivityRecord r = (ActivityRecord)msg.obj;
-                    synchronized (mService) {
-                        if (r.continueLaunchTickingLocked()) {
-                            mService.logAppTooSlow(r.app, r.launchTickTime, "launching " + r);
-                        }
-                    }
-                } break;
-                case DESTROY_TIMEOUT_MSG: {
-                    ActivityRecord r = (ActivityRecord)msg.obj;
-                    // We don't at this point know if the activity is fullscreen,
-                    // so we need to be conservative and assume it isn't.
-                    Slog.w(TAG, "Activity destroy timeout for " + r);
-                    synchronized (mService) {
-                        activityDestroyedLocked(r != null ? r.appToken : null);
-                    }
-                } break;
-                case STOP_TIMEOUT_MSG: {
-                    ActivityRecord r = (ActivityRecord)msg.obj;
-                    // We don't at this point know if the activity is fullscreen,
-                    // so we need to be conservative and assume it isn't.
-                    Slog.w(TAG, "Activity stop timeout for " + r);
-                    synchronized (mService) {
-                        if (r.isInHistory()) {
-                            activityStoppedLocked(r, null, null, null);
-                        }
-                    }
-                } break;
-                case DESTROY_ACTIVITIES_MSG: {
-                    ScheduleDestroyArgs args = (ScheduleDestroyArgs)msg.obj;
-                    synchronized (mService) {
-                        destroyActivitiesLocked(args.mOwner, args.mOomAdj, args.mReason);
-                    }
-                } break;
-                case TRANSLUCENT_TIMEOUT_MSG: {
-                    synchronized (mService) {
-                        notifyActivityDrawnLocked(null);
-                    }
-                } break;
-            }
-        }
-    }
-
-    private int numActivities() {
-        int count = 0;
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            count += mTaskHistory.get(taskNdx).mActivities.size();
-        }
-        return count;
-    }
-
-    ActivityStack(ActivityManagerService service, Context context, Looper looper, int stackId) {
-        mHandler = new ActivityStackHandler(looper);
-        mService = service;
-        mWindowManager = service.mWindowManager;
-        mStackSupervisor = service.mStackSupervisor;
-        mContext = context;
-        mStackId = stackId;
-        mCurrentUser = service.mCurrentUserId;
-    }
-
-    boolean okToShow(ActivityRecord r) {
-        return r.userId == mCurrentUser
-                || (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0;
-    }
-
-    final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            ActivityRecord r = mTaskHistory.get(taskNdx).topRunningActivityLocked(notTop);
-            if (r != null) {
-                return r;
-            }
-        }
-        return null;
-    }
-
-    final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            final ArrayList<ActivityRecord> activities = task.mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                ActivityRecord r = activities.get(activityNdx);
-                if (!r.finishing && !r.delayedResume && r != notTop && okToShow(r)) {
-                    return r;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * This is a simplified version of topRunningActivityLocked that provides a number of
-     * optional skip-over modes.  It is intended for use with the ActivityController hook only.
-     *
-     * @param token If non-null, any history records matching this token will be skipped.
-     * @param taskId If non-zero, we'll attempt to skip over records with the same task ID.
-     *
-     * @return Returns the HistoryRecord of the next activity on the stack.
-     */
-    final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            TaskRecord task = mTaskHistory.get(taskNdx);
-            if (task.taskId == taskId) {
-                continue;
-            }
-            ArrayList<ActivityRecord> activities = task.mActivities;
-            for (int i = activities.size() - 1; i >= 0; --i) {
-                final ActivityRecord r = activities.get(i);
-                // Note: the taskId check depends on real taskId fields being non-zero
-                if (!r.finishing && (token != r.appToken) && okToShow(r)) {
-                    return r;
-                }
-            }
-        }
-        return null;
-    }
-
-    final ActivityRecord topActivity() {
-        // Iterate to find the first non-empty task stack. Note that this code can
-        // be simplified once we stop storing tasks with empty mActivities lists.
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                return activities.get(activityNdx);
-            }
-        }
-        return null;
-    }
-
-    final TaskRecord topTask() {
-        final int size = mTaskHistory.size();
-        if (size > 0) {
-            return mTaskHistory.get(size - 1);
-        }
-        return null;
-    }
-
-    TaskRecord taskForIdLocked(int id) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            if (task.taskId == id) {
-                return task;
-            }
-        }
-        return null;
-    }
-
-    ActivityRecord isInStackLocked(IBinder token) {
-        final ActivityRecord r = ActivityRecord.forToken(token);
-        if (r != null) {
-            final TaskRecord task = r.task;
-            if (task.mActivities.contains(r) && mTaskHistory.contains(task)) {
-                if (task.stack != this) Slog.w(TAG,
-                    "Illegal state! task does not point to stack it is in.");
-                return r;
-            }
-        }
-        return null;
-    }
-
-    boolean containsApp(ProcessRecord app) {
-        if (app == null) {
-            return false;
-        }
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.finishing) {
-                    continue;
-                }
-                if (r.app == app) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    final boolean updateLRUListLocked(ActivityRecord r) {
-        final boolean hadit = mLRUActivities.remove(r);
-        mLRUActivities.add(r);
-        return hadit;
-    }
-
-    final boolean isHomeStack() {
-        return mStackId == HOME_STACK_ID;
-    }
-
-    /**
-     * Returns the top activity in any existing task matching the given
-     * Intent.  Returns null if no such task is found.
-     */
-    ActivityRecord findTaskLocked(ActivityRecord target) {
-        Intent intent = target.intent;
-        ActivityInfo info = target.info;
-        ComponentName cls = intent.getComponent();
-        if (info.targetActivity != null) {
-            cls = new ComponentName(info.packageName, info.targetActivity);
-        }
-        final int userId = UserHandle.getUserId(info.applicationInfo.uid);
-
-        if (DEBUG_TASKS) Slog.d(TAG, "Looking for task of " + target + " in " + this);
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            if (task.userId != userId) {
-                // Looking for a different task.
-                if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": different user");
-                continue;
-            }
-            final ActivityRecord r = task.getTopActivity();
-            if (r == null || r.finishing || r.userId != userId ||
-                    r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
-                if (DEBUG_TASKS) Slog.d(TAG, "Skipping " + task + ": mismatch root " + r);
-                continue;
-            }
-
-            if (DEBUG_TASKS) Slog.d(TAG, "Comparing existing cls="
-                    + r.task.intent.getComponent().flattenToShortString()
-                    + "/aff=" + r.task.affinity + " to new cls="
-                    + intent.getComponent().flattenToShortString() + "/aff=" + info.taskAffinity);
-            if (task.affinity != null) {
-                if (task.affinity.equals(info.taskAffinity)) {
-                    if (DEBUG_TASKS) Slog.d(TAG, "Found matching affinity!");
-                    return r;
-                }
-            } else if (task.intent != null && task.intent.getComponent().equals(cls)) {
-                if (DEBUG_TASKS) Slog.d(TAG, "Found matching class!");
-                //dump();
-                if (DEBUG_TASKS) Slog.d(TAG, "For Intent " + intent + " bringing to top: "
-                        + r.intent);
-                return r;
-            } else if (task.affinityIntent != null
-                    && task.affinityIntent.getComponent().equals(cls)) {
-                if (DEBUG_TASKS) Slog.d(TAG, "Found matching class!");
-                //dump();
-                if (DEBUG_TASKS) Slog.d(TAG, "For Intent " + intent + " bringing to top: "
-                        + r.intent);
-                return r;
-            } else if (DEBUG_TASKS) {
-                Slog.d(TAG, "Not a match: " + task);
-            }
-        }
-
-        return null;
-    }
-
-    /**
-     * Returns the first activity (starting from the top of the stack) that
-     * is the same as the given activity.  Returns null if no such activity
-     * is found.
-     */
-    ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) {
-        ComponentName cls = intent.getComponent();
-        if (info.targetActivity != null) {
-            cls = new ComponentName(info.packageName, info.targetActivity);
-        }
-        final int userId = UserHandle.getUserId(info.applicationInfo.uid);
-
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            TaskRecord task = mTaskHistory.get(taskNdx);
-            if (task.userId != mCurrentUser) {
-                return null;
-            }
-            final ArrayList<ActivityRecord> activities = task.mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                ActivityRecord r = activities.get(activityNdx);
-                if (!r.finishing && r.intent.getComponent().equals(cls) && r.userId == userId) {
-                    //Slog.i(TAG, "Found matching class!");
-                    //dump();
-                    //Slog.i(TAG, "For Intent " + intent + " bringing to top: " + r.intent);
-                    return r;
-                }
-            }
-        }
-
-        return null;
-    }
-
-    /*
-     * Move the activities around in the stack to bring a user to the foreground.
-     */
-    final void switchUserLocked(int userId) {
-        if (mCurrentUser == userId) {
-            return;
-        }
-        mCurrentUser = userId;
-
-        // Move userId's tasks to the top.
-        int index = mTaskHistory.size();
-        for (int i = 0; i < index; ) {
-            TaskRecord task = mTaskHistory.get(i);
-            if (task.userId == userId) {
-                if (DEBUG_TASKS) Slog.d(TAG, "switchUserLocked: stack=" + getStackId() +
-                        " moving " + task + " to top");
-                mTaskHistory.remove(i);
-                mTaskHistory.add(task);
-                --index;
-                // Use same value for i.
-            } else {
-                ++i;
-            }
-        }
-        if (VALIDATE_TOKENS) {
-            validateAppTokensLocked();
-        }
-    }
-
-    void minimalResumeActivityLocked(ActivityRecord r) {
-        r.state = ActivityState.RESUMED;
-        if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + r
-                + " (starting new instance)");
-        r.stopped = false;
-        mResumedActivity = r;
-        r.task.touchActiveTime();
-        mService.addRecentTaskLocked(r.task);
-        completeResumeLocked(r);
-        mStackSupervisor.checkReadyForSleepLocked();
-        setLaunchTime(r);
-        if (DEBUG_SAVED_STATE) Slog.i(TAG, "Launch completed; removing icicle of " + r.icicle);
-    }
-
-    private void startLaunchTraces() {
-        if (mFullyDrawnStartTime != 0)  {
-            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
-        }
-        Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "launching", 0);
-        Trace.asyncTraceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
-    }
-
-    private void stopFullyDrawnTraceIfNeeded() {
-        if (mFullyDrawnStartTime != 0 && mLaunchStartTime == 0) {
-            Trace.asyncTraceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER, "drawing", 0);
-            mFullyDrawnStartTime = 0;
-        }
-    }
-
-    void setLaunchTime(ActivityRecord r) {
-        if (r.displayStartTime == 0) {
-            r.fullyDrawnStartTime = r.displayStartTime = SystemClock.uptimeMillis();
-            if (mLaunchStartTime == 0) {
-                startLaunchTraces();
-                mLaunchStartTime = mFullyDrawnStartTime = r.displayStartTime;
-            }
-        } else if (mLaunchStartTime == 0) {
-            startLaunchTraces();
-            mLaunchStartTime = mFullyDrawnStartTime = SystemClock.uptimeMillis();
-        }
-    }
-
-    void clearLaunchTime(ActivityRecord r) {
-        // Make sure that there is no activity waiting for this to launch.
-        if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) {
-            r.displayStartTime = r.fullyDrawnStartTime = 0;
-        } else {
-            mStackSupervisor.removeTimeoutsForActivityLocked(r);
-            mStackSupervisor.scheduleIdleTimeoutLocked(r);
-        }
-    }
-
-    void awakeFromSleepingLocked() {
-        // Ensure activities are no longer sleeping.
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                activities.get(activityNdx).setSleeping(false);
-            }
-        }
-    }
-
-    /**
-     * @return true if something must be done before going to sleep.
-     */
-    boolean checkReadyForSleepLocked() {
-        if (mResumedActivity != null) {
-            // Still have something resumed; can't sleep until it is paused.
-            if (DEBUG_PAUSE) Slog.v(TAG, "Sleep needs to pause " + mResumedActivity);
-            if (DEBUG_USER_LEAVING) Slog.v(TAG, "Sleep => pause with userLeaving=false");
-            startPausingLocked(false, true);
-            return true;
-        }
-        if (mPausingActivity != null) {
-            // Still waiting for something to pause; can't sleep yet.
-            if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still waiting to pause " + mPausingActivity);
-            return true;
-        }
-
-        return false;
-    }
-
-    void goToSleep() {
-        ensureActivitiesVisibleLocked(null, 0);
-
-        // Make sure any stopped but visible activities are now sleeping.
-        // This ensures that the activity's onStop() is called.
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.state == ActivityState.STOPPING || r.state == ActivityState.STOPPED) {
-                    r.setSleeping(true);
-                }
-            }
-        }
-    }
-
-    public final Bitmap screenshotActivities(ActivityRecord who) {
-        if (who.noDisplay) {
-            return null;
-        }
-
-        TaskRecord tr = who.task;
-        if (mService.getMostRecentTask() != tr && tr.intent != null &&
-                (tr.intent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) != 0) {
-            // If this task is being excluded from recents, we don't want to take
-            // the expense of capturing a thumbnail, since we will never show it.
-            return null;
-        }
-
-        Resources res = mService.mContext.getResources();
-        int w = mThumbnailWidth;
-        int h = mThumbnailHeight;
-        if (w < 0) {
-            mThumbnailWidth = w =
-                res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_width);
-            mThumbnailHeight = h =
-                res.getDimensionPixelSize(com.android.internal.R.dimen.thumbnail_height);
-        }
-
-        if (w > 0) {
-            if (who != mLastScreenshotActivity || mLastScreenshotBitmap == null
-                    || mLastScreenshotActivity.state == ActivityState.RESUMED
-                    || mLastScreenshotBitmap.getWidth() != w
-                    || mLastScreenshotBitmap.getHeight() != h) {
-                mLastScreenshotActivity = who;
-                mLastScreenshotBitmap = mWindowManager.screenshotApplications(
-                        who.appToken, Display.DEFAULT_DISPLAY, w, h, SCREENSHOT_FORCE_565);
-            }
-            if (mLastScreenshotBitmap != null) {
-                return mLastScreenshotBitmap.copy(mLastScreenshotBitmap.getConfig(), true);
-            }
-        }
-        return null;
-    }
-
-    final void startPausingLocked(boolean userLeaving, boolean uiSleeping) {
-        if (mPausingActivity != null) {
-            Slog.e(TAG, "Trying to pause when pause is already pending for "
-                  + mPausingActivity, new RuntimeException("here").fillInStackTrace());
-        }
-        ActivityRecord prev = mResumedActivity;
-        if (prev == null) {
-            Slog.e(TAG, "Trying to pause when nothing is resumed",
-                    new RuntimeException("here").fillInStackTrace());
-            mStackSupervisor.resumeTopActivitiesLocked();
-            return;
-        }
-        if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSING: " + prev);
-        else if (DEBUG_PAUSE) Slog.v(TAG, "Start pausing: " + prev);
-        mResumedActivity = null;
-        mPausingActivity = prev;
-        mLastPausedActivity = prev;
-        mLastNoHistoryActivity = (prev.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_HISTORY) != 0
-                || (prev.info.flags & ActivityInfo.FLAG_NO_HISTORY) != 0 ? prev : null;
-        prev.state = ActivityState.PAUSING;
-        prev.task.touchActiveTime();
-        clearLaunchTime(prev);
-        final ActivityRecord next = mStackSupervisor.topRunningActivityLocked();
-        if (next == null || next.task != prev.task) {
-            prev.updateThumbnail(screenshotActivities(prev), null);
-        }
-        stopFullyDrawnTraceIfNeeded();
-
-        mService.updateCpuStats();
-
-        if (prev.app != null && prev.app.thread != null) {
-            if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending pause: " + prev);
-            try {
-                EventLog.writeEvent(EventLogTags.AM_PAUSE_ACTIVITY,
-                        prev.userId, System.identityHashCode(prev),
-                        prev.shortComponentName);
-                mService.updateUsageStats(prev, false);
-                prev.app.thread.schedulePauseActivity(prev.appToken, prev.finishing,
-                        userLeaving, prev.configChangeFlags);
-            } catch (Exception e) {
-                // Ignore exception, if process died other code will cleanup.
-                Slog.w(TAG, "Exception thrown during pause", e);
-                mPausingActivity = null;
-                mLastPausedActivity = null;
-                mLastNoHistoryActivity = null;
-            }
-        } else {
-            mPausingActivity = null;
-            mLastPausedActivity = null;
-            mLastNoHistoryActivity = null;
-        }
-
-        // If we are not going to sleep, we want to ensure the device is
-        // awake until the next activity is started.
-        if (!mService.isSleepingOrShuttingDown()) {
-            mStackSupervisor.acquireLaunchWakelock();
-        }
-
-        if (mPausingActivity != null) {
-            // Have the window manager pause its key dispatching until the new
-            // activity has started.  If we're pausing the activity just because
-            // the screen is being turned off and the UI is sleeping, don't interrupt
-            // key dispatch; the same activity will pick it up again on wakeup.
-            if (!uiSleeping) {
-                prev.pauseKeyDispatchingLocked();
-            } else {
-                if (DEBUG_PAUSE) Slog.v(TAG, "Key dispatch not paused for screen off");
-            }
-
-            // Schedule a pause timeout in case the app doesn't respond.
-            // We don't give it much time because this directly impacts the
-            // responsiveness seen by the user.
-            Message msg = mHandler.obtainMessage(PAUSE_TIMEOUT_MSG);
-            msg.obj = prev;
-            prev.pauseTime = SystemClock.uptimeMillis();
-            mHandler.sendMessageDelayed(msg, PAUSE_TIMEOUT);
-            if (DEBUG_PAUSE) Slog.v(TAG, "Waiting for pause to complete...");
-        } else {
-            // This activity failed to schedule the
-            // pause, so just treat it as being paused now.
-            if (DEBUG_PAUSE) Slog.v(TAG, "Activity not running, resuming next.");
-            mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
-        }
-    }
-
-    final void activityPausedLocked(IBinder token, boolean timeout) {
-        if (DEBUG_PAUSE) Slog.v(
-            TAG, "Activity paused: token=" + token + ", timeout=" + timeout);
-
-        final ActivityRecord r = isInStackLocked(token);
-        if (r != null) {
-            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
-            if (mPausingActivity == r) {
-                if (DEBUG_STATES) Slog.v(TAG, "Moving to PAUSED: " + r
-                        + (timeout ? " (due to timeout)" : " (pause complete)"));
-                r.state = ActivityState.PAUSED;
-                completePauseLocked();
-            } else {
-                EventLog.writeEvent(EventLogTags.AM_FAILED_TO_PAUSE,
-                        r.userId, System.identityHashCode(r), r.shortComponentName,
-                        mPausingActivity != null
-                            ? mPausingActivity.shortComponentName : "(none)");
-            }
-        }
-    }
-
-    final void activityStoppedLocked(ActivityRecord r, Bundle icicle, Bitmap thumbnail,
-            CharSequence description) {
-        if (r.state != ActivityState.STOPPING) {
-            Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r);
-            mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
-            return;
-        }
-        if (DEBUG_SAVED_STATE) Slog.i(TAG, "Saving icicle of " + r + ": " + icicle);
-        if (icicle != null) {
-            // If icicle is null, this is happening due to a timeout, so we
-            // haven't really saved the state.
-            r.icicle = icicle;
-            r.haveState = true;
-            r.launchCount = 0;
-            r.updateThumbnail(thumbnail, description);
-        }
-        if (!r.stopped) {
-            if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r + " (stop complete)");
-            mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
-            r.stopped = true;
-            r.state = ActivityState.STOPPED;
-            if (r.finishing) {
-                r.clearOptionsLocked();
-            } else {
-                if (r.configDestroy) {
-                    destroyActivityLocked(r, true, false, "stop-config");
-                    mStackSupervisor.resumeTopActivitiesLocked();
-                } else {
-                    mStackSupervisor.updatePreviousProcessLocked(r);
-                }
-            }
-        }
-    }
-
-    private void completePauseLocked() {
-        ActivityRecord prev = mPausingActivity;
-        if (DEBUG_PAUSE) Slog.v(TAG, "Complete pause: " + prev);
-
-        if (prev != null) {
-            if (prev.finishing) {
-                if (DEBUG_PAUSE) Slog.v(TAG, "Executing finish of activity: " + prev);
-                prev = finishCurrentActivityLocked(prev, FINISH_AFTER_VISIBLE, false);
-            } else if (prev.app != null) {
-                if (DEBUG_PAUSE) Slog.v(TAG, "Enqueueing pending stop: " + prev);
-                if (prev.waitingVisible) {
-                    prev.waitingVisible = false;
-                    mStackSupervisor.mWaitingVisibleActivities.remove(prev);
-                    if (DEBUG_SWITCH || DEBUG_PAUSE) Slog.v(
-                            TAG, "Complete pause, no longer waiting: " + prev);
-                }
-                if (prev.configDestroy) {
-                    // The previous is being paused because the configuration
-                    // is changing, which means it is actually stopping...
-                    // To juggle the fact that we are also starting a new
-                    // instance right now, we need to first completely stop
-                    // the current instance before starting the new one.
-                    if (DEBUG_PAUSE) Slog.v(TAG, "Destroying after pause: " + prev);
-                    destroyActivityLocked(prev, true, false, "pause-config");
-                } else {
-                    mStackSupervisor.mStoppingActivities.add(prev);
-                    if (mStackSupervisor.mStoppingActivities.size() > 3 ||
-                            prev.frontOfTask && mTaskHistory.size() <= 1) {
-                        // If we already have a few activities waiting to stop,
-                        // then give up on things going idle and start clearing
-                        // them out. Or if r is the last of activity of the last task the stack
-                        // will be empty and must be cleared immediately.
-                        if (DEBUG_PAUSE) Slog.v(TAG, "To many pending stops, forcing idle");
-                        mStackSupervisor.scheduleIdleLocked();
-                    } else {
-                        mStackSupervisor.checkReadyForSleepLocked();
-                    }
-                }
-            } else {
-                if (DEBUG_PAUSE) Slog.v(TAG, "App died during pause, not stopping: " + prev);
-                prev = null;
-            }
-            mPausingActivity = null;
-        }
-
-        final ActivityStack topStack = mStackSupervisor.getFocusedStack();
-        if (!mService.isSleepingOrShuttingDown()) {
-            mStackSupervisor.resumeTopActivitiesLocked(topStack, prev, null);
-        } else {
-            mStackSupervisor.checkReadyForSleepLocked();
-            ActivityRecord top = topStack.topRunningActivityLocked(null);
-            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 (prev != null) {
-            prev.resumeKeyDispatchingLocked();
-
-            if (prev.app != null && prev.cpuTimeAtResume > 0
-                    && mService.mBatteryStatsService.isOnBattery()) {
-                long diff;
-                synchronized (mService.mProcessCpuThread) {
-                    diff = mService.mProcessCpuTracker.getCpuTimeForPid(prev.app.pid)
-                            - prev.cpuTimeAtResume;
-                }
-                if (diff > 0) {
-                    BatteryStatsImpl bsi = mService.mBatteryStatsService.getActiveStatistics();
-                    synchronized (bsi) {
-                        BatteryStatsImpl.Uid.Proc ps =
-                                bsi.getProcessStatsLocked(prev.info.applicationInfo.uid,
-                                        prev.info.packageName);
-                        if (ps != null) {
-                            ps.addForegroundTimeLocked(diff);
-                        }
-                    }
-                }
-            }
-            prev.cpuTimeAtResume = 0; // reset it
-        }
-    }
-
-    /**
-     * Once we know that we have asked an application to put an activity in
-     * the resumed state (either by launching it or explicitly telling it),
-     * this function updates the rest of our state to match that fact.
-     */
-    private void completeResumeLocked(ActivityRecord next) {
-        next.idle = false;
-        next.results = null;
-        next.newIntents = null;
-        if (next.nowVisible) {
-            // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
-            mStackSupervisor.dismissKeyguard();
-        }
-
-        // schedule an idle timeout in case the app doesn't do it for us.
-        mStackSupervisor.scheduleIdleTimeoutLocked(next);
-
-        mStackSupervisor.reportResumedActivityLocked(next);
-
-        next.resumeKeyDispatchingLocked();
-        mNoAnimActivities.clear();
-
-        // Mark the point when the activity is resuming
-        // TODO: To be more accurate, the mark should be before the onCreate,
-        //       not after the onResume. But for subsequent starts, onResume is fine.
-        if (next.app != null) {
-            synchronized (mService.mProcessCpuThread) {
-                next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid);
-            }
-        } else {
-            next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process
-        }
-    }
-
-    /**
-     * Determine if home should be visible below the passed record.
-     * @param record activity we are querying for.
-     * @return true if home is visible below the passed activity, false otherwise.
-     */
-    boolean isActivityOverHome(ActivityRecord record) {
-        // Start at record and go down, look for either home or a visible fullscreen activity.
-        final TaskRecord recordTask = record.task;
-        for (int taskNdx = mTaskHistory.indexOf(recordTask); taskNdx >= 0; --taskNdx) {
-            TaskRecord task = mTaskHistory.get(taskNdx);
-            final ArrayList<ActivityRecord> activities = task.mActivities;
-            final int startNdx =
-                    task == recordTask ? activities.indexOf(record) : activities.size() - 1;
-            for (int activityNdx = startNdx; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.isHomeActivity()) {
-                    return true;
-                }
-                if (!r.finishing && r.fullscreen) {
-                    // Passed activity is over a fullscreen activity.
-                    return false;
-                }
-            }
-            if (task.mOnTopOfHome) {
-                // Got to the bottom of a task on top of home without finding a visible fullscreen
-                // activity. Home is visible.
-                return true;
-            }
-        }
-        // Got to the bottom of this stack and still don't know. If this is over the home stack
-        // then record is over home. May not work if we ever get more than two layers.
-        return mStackSupervisor.isFrontStack(this);
-    }
-
-    /**
-     * Version of ensureActivitiesVisible that can easily be called anywhere.
-     */
-    final boolean ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) {
-        return ensureActivitiesVisibleLocked(starting, configChanges, false);
-    }
-
-    final boolean ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges,
-            boolean forceHomeShown) {
-        ActivityRecord r = topRunningActivityLocked(null);
-        return r != null &&
-                ensureActivitiesVisibleLocked(r, starting, null, configChanges, forceHomeShown);
-    }
-
-    /**
-     * Make sure that all activities that need to be visible (that is, they
-     * currently can be seen by the user) actually are.
-     */
-    final boolean ensureActivitiesVisibleLocked(ActivityRecord top, ActivityRecord starting,
-            String onlyThisProcess, int configChanges, boolean forceHomeShown) {
-        if (DEBUG_VISBILITY) Slog.v(
-                TAG, "ensureActivitiesVisible behind " + top
-                + " configChanges=0x" + Integer.toHexString(configChanges));
-
-        if (mTranslucentActivityWaiting != top) {
-            mUndrawnActivitiesBelowTopTranslucent.clear();
-            if (mTranslucentActivityWaiting != null) {
-                // Call the callback with a timeout indication.
-                notifyActivityDrawnLocked(null);
-                mTranslucentActivityWaiting = null;
-            }
-            mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG);
-        }
-
-        // If the top activity is not fullscreen, then we need to
-        // make sure any activities under it are now visible.
-        boolean aboveTop = true;
-        boolean showHomeBehindStack = false;
-        boolean behindFullscreen = !mStackSupervisor.isFrontStack(this) &&
-                !(forceHomeShown && isHomeStack());
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            final ArrayList<ActivityRecord> activities = task.mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.finishing) {
-                    continue;
-                }
-                if (aboveTop && r != top) {
-                    continue;
-                }
-                aboveTop = false;
-                if (!behindFullscreen) {
-                    if (DEBUG_VISBILITY) Slog.v(
-                            TAG, "Make visible? " + r + " finishing=" + r.finishing
-                            + " state=" + r.state);
-
-                    final boolean doThisProcess = onlyThisProcess == null
-                            || onlyThisProcess.equals(r.processName);
-
-                    // First: if this is not the current activity being started, make
-                    // sure it matches the current configuration.
-                    if (r != starting && doThisProcess) {
-                        ensureActivityConfigurationLocked(r, 0);
-                    }
-
-                    if (r.app == null || r.app.thread == null) {
-                        if (onlyThisProcess == null || onlyThisProcess.equals(r.processName)) {
-                            // This activity needs to be visible, but isn't even
-                            // running...  get it started, but don't resume it
-                            // at this point.
-                            if (DEBUG_VISBILITY) Slog.v(TAG, "Start and freeze screen for " + r);
-                            if (r != starting) {
-                                r.startFreezingScreenLocked(r.app, configChanges);
-                            }
-                            if (!r.visible) {
-                                if (DEBUG_VISBILITY) Slog.v(
-                                        TAG, "Starting and making visible: " + r);
-                                mWindowManager.setAppVisibility(r.appToken, true);
-                            }
-                            if (r != starting) {
-                                mStackSupervisor.startSpecificActivityLocked(r, false, false);
-                            }
-                        }
-
-                    } else if (r.visible) {
-                        // If this activity is already visible, then there is nothing
-                        // else to do here.
-                        if (DEBUG_VISBILITY) Slog.v(TAG, "Skipping: already visible at " + r);
-                        r.stopFreezingScreenLocked(false);
-
-                    } else if (onlyThisProcess == null) {
-                        // This activity is not currently visible, but is running.
-                        // Tell it to become visible.
-                        r.visible = true;
-                        if (r.state != ActivityState.RESUMED && r != starting) {
-                            // If this activity is paused, tell it
-                            // to now show its window.
-                            if (DEBUG_VISBILITY) Slog.v(
-                                    TAG, "Making visible and scheduling visibility: " + r);
-                            try {
-                                if (mTranslucentActivityWaiting != null) {
-                                    mUndrawnActivitiesBelowTopTranslucent.add(r);
-                                }
-                                mWindowManager.setAppVisibility(r.appToken, true);
-                                r.sleeping = false;
-                                r.app.pendingUiClean = true;
-                                r.app.thread.scheduleWindowVisibility(r.appToken, true);
-                                r.stopFreezingScreenLocked(false);
-                            } catch (Exception e) {
-                                // Just skip on any failure; we'll make it
-                                // visible when it next restarts.
-                                Slog.w(TAG, "Exception thrown making visibile: "
-                                        + r.intent.getComponent(), e);
-                            }
-                        }
-                    }
-
-                    // Aggregate current change flags.
-                    configChanges |= r.configChangeFlags;
-
-                    if (r.fullscreen) {
-                        // At this point, nothing else needs to be shown
-                        if (DEBUG_VISBILITY) Slog.v(TAG, "Fullscreen: at " + r);
-                        behindFullscreen = true;
-                    } else if (isActivityOverHome(r)) {
-                        if (DEBUG_VISBILITY) Slog.v(TAG, "Showing home: at " + r);
-                        showHomeBehindStack = true;
-                        behindFullscreen = !isHomeStack();
-                    }
-                } else {
-                    if (DEBUG_VISBILITY) Slog.v(
-                        TAG, "Make invisible? " + r + " finishing=" + r.finishing
-                        + " state=" + r.state
-                        + " behindFullscreen=" + behindFullscreen);
-                    // Now for any activities that aren't visible to the user, make
-                    // sure they no longer are keeping the screen frozen.
-                    if (r.visible) {
-                        if (DEBUG_VISBILITY) Slog.v(TAG, "Making invisible: " + r);
-                        r.visible = false;
-                        try {
-                            mWindowManager.setAppVisibility(r.appToken, false);
-                            switch (r.state) {
-                                case STOPPING:
-                                case STOPPED:
-                                    if (r.app != null && r.app.thread != null) {
-                                        if (DEBUG_VISBILITY) Slog.v(
-                                                TAG, "Scheduling invisibility: " + r);
-                                        r.app.thread.scheduleWindowVisibility(r.appToken, false);
-                                    }
-                                    break;
-
-                                case INITIALIZING:
-                                case RESUMED:
-                                case PAUSING:
-                                case PAUSED:
-                                    // This case created for transitioning activities from
-                                    // translucent to opaque {@link Activity#convertToOpaque}.
-                                    if (!mStackSupervisor.mStoppingActivities.contains(r)) {
-                                        mStackSupervisor.mStoppingActivities.add(r);
-                                    }
-                                    mStackSupervisor.scheduleIdleLocked();
-                                    break;
-
-                                default:
-                                    break;
-                            }
-                        } catch (Exception e) {
-                            // Just skip on any failure; we'll make it
-                            // visible when it next restarts.
-                            Slog.w(TAG, "Exception thrown making hidden: "
-                                    + r.intent.getComponent(), e);
-                        }
-                    } else {
-                        if (DEBUG_VISBILITY) Slog.v(TAG, "Already invisible: " + r);
-                    }
-                }
-            }
-        }
-        return showHomeBehindStack;
-    }
-
-    void convertToTranslucent(ActivityRecord r) {
-        mTranslucentActivityWaiting = r;
-        mUndrawnActivitiesBelowTopTranslucent.clear();
-        mHandler.sendEmptyMessageDelayed(TRANSLUCENT_TIMEOUT_MSG, TRANSLUCENT_CONVERSION_TIMEOUT);
-    }
-
-    /**
-     * Called as activities below the top translucent activity are redrawn. When the last one is
-     * redrawn notify the top activity by calling
-     * {@link Activity#onTranslucentConversionComplete}.
-     *
-     * @param r The most recent background activity to be drawn. Or, if r is null then a timeout
-     * occurred and the activity will be notified immediately.
-     */
-    void notifyActivityDrawnLocked(ActivityRecord r) {
-        if ((r == null)
-                || (mUndrawnActivitiesBelowTopTranslucent.remove(r) &&
-                        mUndrawnActivitiesBelowTopTranslucent.isEmpty())) {
-            // The last undrawn activity below the top has just been drawn. If there is an
-            // opaque activity at the top, notify it that it can become translucent safely now.
-            final ActivityRecord waitingActivity = mTranslucentActivityWaiting;
-            mTranslucentActivityWaiting = null;
-            mUndrawnActivitiesBelowTopTranslucent.clear();
-            mHandler.removeMessages(TRANSLUCENT_TIMEOUT_MSG);
-
-            if (waitingActivity != null && waitingActivity.app != null &&
-                    waitingActivity.app.thread != null) {
-                try {
-                    waitingActivity.app.thread.scheduleTranslucentConversionComplete(
-                            waitingActivity.appToken, r != null);
-                } catch (RemoteException e) {
-                }
-            }
-        }
-    }
-
-    /**
-     * Ensure that the top activity in the stack is resumed.
-     *
-     * @param prev The previously resumed activity, for when in the process
-     * of pausing; can be null to call from elsewhere.
-     *
-     * @return Returns true if something is being resumed, or false if
-     * nothing happened.
-     */
-    final boolean resumeTopActivityLocked(ActivityRecord prev) {
-        return resumeTopActivityLocked(prev, null);
-    }
-
-    final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
-        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
-
-        // Find the first activity that is not finishing.
-        ActivityRecord next = topRunningActivityLocked(null);
-
-        // Remember how we'll process this pause/resume situation, and ensure
-        // that the state is reset however we wind up proceeding.
-        final boolean userLeaving = mStackSupervisor.mUserLeaving;
-        mStackSupervisor.mUserLeaving = false;
-
-        if (next == null) {
-            // There are no more activities!  Let's just start up the
-            // Launcher...
-            ActivityOptions.abort(options);
-            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: No more activities go home");
-            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-            return mStackSupervisor.resumeHomeActivity(prev);
-        }
-
-        next.delayedResume = false;
-
-        // If the top activity is the resumed one, nothing to do.
-        if (mResumedActivity == next && next.state == ActivityState.RESUMED &&
-                    mStackSupervisor.allResumedActivitiesComplete()) {
-            // Make sure we have executed any pending transitions, since there
-            // should be nothing left to do at this point.
-            mWindowManager.executeAppTransition();
-            mNoAnimActivities.clear();
-            ActivityOptions.abort(options);
-            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Top activity resumed " + next);
-            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-            return false;
-        }
-
-        final TaskRecord nextTask = next.task;
-        final TaskRecord prevTask = prev != null ? prev.task : null;
-        if (prevTask != null && prevTask.mOnTopOfHome && prev.finishing && prev.frontOfTask) {
-            if (DEBUG_STACK)  mStackSupervisor.validateTopActivitiesLocked();
-            if (prevTask == nextTask) {
-                ArrayList<ActivityRecord> activities = prevTask.mActivities;
-                final int numActivities = activities.size();
-                for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
-                    final ActivityRecord r = activities.get(activityNdx);
-                    // r is usually the same as next, but what if two activities were launched
-                    // before prev finished?
-                    if (!r.finishing) {
-                        r.frontOfTask = true;
-                        break;
-                    }
-                }
-            } else if (prevTask != topTask()) {
-                // This task is going away but it was supposed to return to the home task.
-                // Now the task above it has to return to the home task instead.
-                final int taskNdx = mTaskHistory.indexOf(prevTask) + 1;
-                mTaskHistory.get(taskNdx).mOnTopOfHome = true;
-            } else {
-                if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Launching home next");
-                return mStackSupervisor.resumeHomeActivity(prev);
-            }
-        }
-
-        // If we are sleeping, and there is no resumed activity, and the top
-        // activity is paused, well that is the state we want.
-        if (mService.isSleepingOrShuttingDown()
-                && mLastPausedActivity == next
-                && mStackSupervisor.allPausedActivitiesComplete()) {
-            // Make sure we have executed any pending transitions, since there
-            // should be nothing left to do at this point.
-            mWindowManager.executeAppTransition();
-            mNoAnimActivities.clear();
-            ActivityOptions.abort(options);
-            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Going to sleep and all paused");
-            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-            return false;
-        }
-
-        // Make sure that the user who owns this activity is started.  If not,
-        // we will just leave it as is because someone should be bringing
-        // another user's activities to the top of the stack.
-        if (mService.mStartedUsers.get(next.userId) == null) {
-            Slog.w(TAG, "Skipping resume of top activity " + next
-                    + ": user " + next.userId + " is stopped");
-            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-            return false;
-        }
-
-        // The activity may be waiting for stop, but that is no longer
-        // appropriate for it.
-        mStackSupervisor.mStoppingActivities.remove(next);
-        mStackSupervisor.mGoingToSleepActivities.remove(next);
-        next.sleeping = false;
-        mStackSupervisor.mWaitingVisibleActivities.remove(next);
-
-        next.updateOptionsLocked(options);
-
-        if (DEBUG_SWITCH) Slog.v(TAG, "Resuming " + next);
-
-        // If we are currently pausing an activity, then don't do anything
-        // until that is done.
-        if (!mStackSupervisor.allPausedActivitiesComplete()) {
-            if (DEBUG_SWITCH || DEBUG_PAUSE || DEBUG_STATES) Slog.v(TAG,
-                    "resumeTopActivityLocked: Skip resume: some activity pausing.");
-            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-            return false;
-        }
-
-        // Okay we are now going to start a switch, to 'next'.  We may first
-        // have to pause the current activity, but this is an important point
-        // where we have decided to go to 'next' so keep track of that.
-        // XXX "App Redirected" dialog is getting too many false positives
-        // at this point, so turn off for now.
-        if (false) {
-            if (mLastStartedActivity != null && !mLastStartedActivity.finishing) {
-                long now = SystemClock.uptimeMillis();
-                final boolean inTime = mLastStartedActivity.startTime != 0
-                        && (mLastStartedActivity.startTime + START_WARN_TIME) >= now;
-                final int lastUid = mLastStartedActivity.info.applicationInfo.uid;
-                final int nextUid = next.info.applicationInfo.uid;
-                if (inTime && lastUid != nextUid
-                        && lastUid != next.launchedFromUid
-                        && mService.checkPermission(
-                                android.Manifest.permission.STOP_APP_SWITCHES,
-                                -1, next.launchedFromUid)
-                        != PackageManager.PERMISSION_GRANTED) {
-                    mService.showLaunchWarningLocked(mLastStartedActivity, next);
-                } else {
-                    next.startTime = now;
-                    mLastStartedActivity = next;
-                }
-            } else {
-                next.startTime = SystemClock.uptimeMillis();
-                mLastStartedActivity = next;
-            }
-        }
-
-        // We need to start pausing the current activity so the top one
-        // can be resumed...
-        boolean pausing = mStackSupervisor.pauseBackStacks(userLeaving);
-        if (mResumedActivity != null) {
-            pausing = true;
-            startPausingLocked(userLeaving, false);
-            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Pausing " + mResumedActivity);
-        }
-        if (pausing) {
-            if (DEBUG_SWITCH || DEBUG_STATES) Slog.v(TAG,
-                    "resumeTopActivityLocked: Skip resume: need to start pausing");
-            // At this point we want to put the upcoming activity's process
-            // at the top of the LRU list, since we know we will be needing it
-            // very soon and it would be a waste to let it get killed if it
-            // happens to be sitting towards the end.
-            if (next.app != null && next.app.thread != null) {
-                // No reason to do full oom adj update here; we'll let that
-                // happen whenever it needs to later.
-                mService.updateLruProcessLocked(next.app, true, null);
-            }
-            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-            return true;
-        }
-
-        // If the most recent activity was noHistory but was only stopped rather
-        // than stopped+finished because the device went to sleep, we need to make
-        // sure to finish it as we're making a new activity topmost.
-        if (mService.mSleeping && mLastNoHistoryActivity != null &&
-                !mLastNoHistoryActivity.finishing) {
-            if (DEBUG_STATES) Slog.d(TAG, "no-history finish of " + mLastNoHistoryActivity +
-                    " on new resume");
-            requestFinishActivityLocked(mLastNoHistoryActivity.appToken, Activity.RESULT_CANCELED,
-                    null, "no-history", false);
-            mLastNoHistoryActivity = null;
-        }
-
-        if (prev != null && prev != next) {
-            if (!prev.waitingVisible && next != null && !next.nowVisible) {
-                prev.waitingVisible = true;
-                mStackSupervisor.mWaitingVisibleActivities.add(prev);
-                if (DEBUG_SWITCH) Slog.v(
-                        TAG, "Resuming top, waiting visible to hide: " + prev);
-            } else {
-                // The next activity is already visible, so hide the previous
-                // activity's windows right now so we can show the new one ASAP.
-                // We only do this if the previous is finishing, which should mean
-                // it is on top of the one being resumed so hiding it quickly
-                // is good.  Otherwise, we want to do the normal route of allowing
-                // the resumed activity to be shown so we can decide if the
-                // previous should actually be hidden depending on whether the
-                // new one is found to be full-screen or not.
-                if (prev.finishing) {
-                    mWindowManager.setAppVisibility(prev.appToken, false);
-                    if (DEBUG_SWITCH) Slog.v(TAG, "Not waiting for visible to hide: "
-                            + prev + ", waitingVisible="
-                            + (prev != null ? prev.waitingVisible : null)
-                            + ", nowVisible=" + next.nowVisible);
-                } else {
-                    if (DEBUG_SWITCH) Slog.v(TAG, "Previous already visible but still waiting to hide: "
-                        + prev + ", waitingVisible="
-                        + (prev != null ? prev.waitingVisible : null)
-                        + ", nowVisible=" + next.nowVisible);
-                }
-            }
-        }
-
-        // Launching this app's activity, make sure the app is no longer
-        // considered stopped.
-        try {
-            AppGlobals.getPackageManager().setPackageStoppedState(
-                    next.packageName, false, next.userId); /* TODO: Verify if correct userid */
-        } catch (RemoteException e1) {
-        } catch (IllegalArgumentException e) {
-            Slog.w(TAG, "Failed trying to unstop package "
-                    + next.packageName + ": " + e);
-        }
-
-        // We are starting up the next activity, so tell the window manager
-        // that the previous one will be hidden soon.  This way it can know
-        // to ignore it when computing the desired screen orientation.
-        boolean anim = true;
-        if (prev != null) {
-            if (prev.finishing) {
-                if (DEBUG_TRANSITION) Slog.v(TAG,
-                        "Prepare close transition: prev=" + prev);
-                if (mNoAnimActivities.contains(prev)) {
-                    anim = false;
-                    mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
-                } else {
-                    mWindowManager.prepareAppTransition(prev.task == next.task
-                            ? AppTransition.TRANSIT_ACTIVITY_CLOSE
-                            : AppTransition.TRANSIT_TASK_CLOSE, false);
-                }
-                mWindowManager.setAppWillBeHidden(prev.appToken);
-                mWindowManager.setAppVisibility(prev.appToken, false);
-            } else {
-                if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: prev=" + prev);
-                if (mNoAnimActivities.contains(next)) {
-                    anim = false;
-                    mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
-                } else {
-                    mWindowManager.prepareAppTransition(prev.task == next.task
-                            ? AppTransition.TRANSIT_ACTIVITY_OPEN
-                            : AppTransition.TRANSIT_TASK_OPEN, false);
-                }
-            }
-            if (false) {
-                mWindowManager.setAppWillBeHidden(prev.appToken);
-                mWindowManager.setAppVisibility(prev.appToken, false);
-            }
-        } else {
-            if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare open transition: no previous");
-            if (mNoAnimActivities.contains(next)) {
-                anim = false;
-                mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
-            } else {
-                mWindowManager.prepareAppTransition(AppTransition.TRANSIT_ACTIVITY_OPEN, false);
-            }
-        }
-        if (anim) {
-            next.applyOptionsLocked();
-        } else {
-            next.clearOptionsLocked();
-        }
-
-        ActivityStack lastStack = mStackSupervisor.getLastStack();
-        if (next.app != null && next.app.thread != null) {
-            if (DEBUG_SWITCH) Slog.v(TAG, "Resume running: " + next);
-
-            // This activity is now becoming visible.
-            mWindowManager.setAppVisibility(next.appToken, true);
-
-            // schedule launch ticks to collect information about slow apps.
-            next.startLaunchTickingLocked();
-
-            ActivityRecord lastResumedActivity =
-                    lastStack == null ? null :lastStack.mResumedActivity;
-            ActivityState lastState = next.state;
-
-            mService.updateCpuStats();
-
-            if (DEBUG_STATES) Slog.v(TAG, "Moving to RESUMED: " + next + " (in existing)");
-            next.state = ActivityState.RESUMED;
-            mResumedActivity = next;
-            next.task.touchActiveTime();
-            mService.addRecentTaskLocked(next.task);
-            mService.updateLruProcessLocked(next.app, true, null);
-            updateLRUListLocked(next);
-            mService.updateOomAdjLocked();
-
-            // Have the window manager re-evaluate the orientation of
-            // the screen based on the new activity order.
-            boolean notUpdated = true;
-            if (mStackSupervisor.isFrontStack(this)) {
-                Configuration config = mWindowManager.updateOrientationFromAppTokens(
-                        mService.mConfiguration,
-                        next.mayFreezeScreenLocked(next.app) ? next.appToken : null);
-                if (config != null) {
-                    next.frozenBeforeDestroy = true;
-                }
-                notUpdated = !mService.updateConfigurationLocked(config, next, false, false);
-            }
-
-            if (notUpdated) {
-                // The configuration update wasn't able to keep the existing
-                // instance of the activity, and instead started a new one.
-                // We should be all done, but let's just make sure our activity
-                // is still at the top and schedule another run if something
-                // weird happened.
-                ActivityRecord nextNext = topRunningActivityLocked(null);
-                if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG,
-                        "Activity config changed during resume: " + next
-                        + ", new next: " + nextNext);
-                if (nextNext != next) {
-                    // Do over!
-                    mStackSupervisor.scheduleResumeTopActivities();
-                }
-                if (mStackSupervisor.reportResumedActivityLocked(next)) {
-                    mNoAnimActivities.clear();
-                    if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-                    return true;
-                }
-                if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-                return false;
-            }
-
-            try {
-                // Deliver all pending results.
-                ArrayList<ResultInfo> a = next.results;
-                if (a != null) {
-                    final int N = a.size();
-                    if (!next.finishing && N > 0) {
-                        if (DEBUG_RESULTS) Slog.v(
-                                TAG, "Delivering results to " + next
-                                + ": " + a);
-                        next.app.thread.scheduleSendResult(next.appToken, a);
-                    }
-                }
-
-                if (next.newIntents != null) {
-                    next.app.thread.scheduleNewIntent(next.newIntents, next.appToken);
-                }
-
-                EventLog.writeEvent(EventLogTags.AM_RESUME_ACTIVITY,
-                        next.userId, System.identityHashCode(next),
-                        next.task.taskId, next.shortComponentName);
-
-                next.sleeping = false;
-                mService.showAskCompatModeDialogLocked(next);
-                next.app.pendingUiClean = true;
-                next.app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP);
-                next.app.thread.scheduleResumeActivity(next.appToken, next.app.repProcState,
-                        mService.isNextTransitionForward());
-
-                mStackSupervisor.checkReadyForSleepLocked();
-
-                if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Resumed " + next);
-            } catch (Exception e) {
-                // Whoops, need to restart this activity!
-                if (DEBUG_STATES) Slog.v(TAG, "Resume failed; resetting state to "
-                        + lastState + ": " + next);
-                next.state = lastState;
-                if (lastStack != null) {
-                    lastStack.mResumedActivity = lastResumedActivity;
-                }
-                Slog.i(TAG, "Restarting because process died: " + next);
-                if (!next.hasBeenLaunched) {
-                    next.hasBeenLaunched = true;
-                } else  if (SHOW_APP_STARTING_PREVIEW && lastStack != null &&
-                        mStackSupervisor.isFrontStack(lastStack)) {
-                    mWindowManager.setAppStartingWindow(
-                            next.appToken, next.packageName, next.theme,
-                            mService.compatibilityInfoForPackageLocked(next.info.applicationInfo),
-                            next.nonLocalizedLabel, next.labelRes, next.icon, next.logo,
-                            next.windowFlags, null, true);
-                }
-                mStackSupervisor.startSpecificActivityLocked(next, true, false);
-                if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-                return true;
-            }
-
-            // From this point on, if something goes wrong there is no way
-            // to recover the activity.
-            try {
-                next.visible = true;
-                completeResumeLocked(next);
-            } catch (Exception e) {
-                // If any exception gets thrown, toss away this
-                // activity and try the next one.
-                Slog.w(TAG, "Exception thrown during resume of " + next, e);
-                requestFinishActivityLocked(next.appToken, Activity.RESULT_CANCELED, null,
-                        "resume-exception", true);
-                if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-                return true;
-            }
-            next.stopped = false;
-
-        } else {
-            // Whoops, need to restart this activity!
-            if (!next.hasBeenLaunched) {
-                next.hasBeenLaunched = true;
-            } else {
-                if (SHOW_APP_STARTING_PREVIEW) {
-                    mWindowManager.setAppStartingWindow(
-                            next.appToken, next.packageName, next.theme,
-                            mService.compatibilityInfoForPackageLocked(
-                                    next.info.applicationInfo),
-                            next.nonLocalizedLabel,
-                            next.labelRes, next.icon, next.logo, next.windowFlags,
-                            null, true);
-                }
-                if (DEBUG_SWITCH) Slog.v(TAG, "Restarting: " + next);
-            }
-            if (DEBUG_STATES) Slog.d(TAG, "resumeTopActivityLocked: Restarting " + next);
-            mStackSupervisor.startSpecificActivityLocked(next, true, true);
-        }
-
-        if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
-        return true;
-    }
-
-    private void insertTaskAtTop(TaskRecord task) {
-        // If this is being moved to the top by another activity or being launched from the home
-        // activity, set mOnTopOfHome accordingly.
-        ActivityStack lastStack = mStackSupervisor.getLastStack();
-        final boolean fromHome = lastStack == null ? true : lastStack.isHomeStack();
-        if (!isHomeStack() && (fromHome || topTask() != task)) {
-            task.mOnTopOfHome = fromHome;
-        }
-
-        mTaskHistory.remove(task);
-        // Now put task at top.
-        int stackNdx = mTaskHistory.size();
-        if (task.userId != mCurrentUser) {
-            // Put non-current user tasks below current user tasks.
-            while (--stackNdx >= 0) {
-                if (mTaskHistory.get(stackNdx).userId != mCurrentUser) {
-                    break;
-                }
-            }
-            ++stackNdx;
-        }
-        mTaskHistory.add(stackNdx, task);
-    }
-
-    final void startActivityLocked(ActivityRecord r, boolean newTask,
-            boolean doResume, boolean keepCurTransition, Bundle options) {
-        TaskRecord rTask = r.task;
-        final int taskId = rTask.taskId;
-        if (taskForIdLocked(taskId) == null || newTask) {
-            // Last activity in task had been removed or ActivityManagerService is reusing task.
-            // Insert or replace.
-            // Might not even be in.
-            insertTaskAtTop(rTask);
-            mWindowManager.moveTaskToTop(taskId);
-        }
-        TaskRecord task = null;
-        if (!newTask) {
-            // If starting in an existing task, find where that is...
-            boolean startIt = true;
-            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-                task = mTaskHistory.get(taskNdx);
-                if (task == r.task) {
-                    // Here it is!  Now, if this is not yet visible to the
-                    // user, then just add it without starting; it will
-                    // get started when the user navigates back to it.
-                    if (!startIt) {
-                        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to task "
-                                + task, new RuntimeException("here").fillInStackTrace());
-                        task.addActivityToTop(r);
-                        r.putInHistory();
-                        mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
-                                r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
-                                (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0,
-                                r.userId, r.info.configChanges);
-                        if (VALIDATE_TOKENS) {
-                            validateAppTokensLocked();
-                        }
-                        ActivityOptions.abort(options);
-                        return;
-                    }
-                    break;
-                } else if (task.numFullscreen > 0) {
-                    startIt = false;
-                }
-            }
-        }
-
-        // Place a new activity at top of stack, so it is next to interact
-        // with the user.
-
-        // If we are not placing the new activity frontmost, we do not want
-        // to deliver the onUserLeaving callback to the actual frontmost
-        // activity
-        if (task == r.task && mTaskHistory.indexOf(task) != (mTaskHistory.size() - 1)) {
-            mStackSupervisor.mUserLeaving = false;
-            if (DEBUG_USER_LEAVING) Slog.v(TAG,
-                    "startActivity() behind front, mUserLeaving=false");
-        }
-
-        task = r.task;
-
-        // Slot the activity into the history stack and proceed
-        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Adding activity " + r + " to stack to task " + task,
-                new RuntimeException("here").fillInStackTrace());
-        task.addActivityToTop(r);
-
-        r.putInHistory();
-        r.frontOfTask = newTask;
-        if (!isHomeStack() || numActivities() > 0) {
-            // We want to show the starting preview window if we are
-            // switching to a new task, or the next activity's process is
-            // not currently running.
-            boolean showStartingIcon = newTask;
-            ProcessRecord proc = r.app;
-            if (proc == null) {
-                proc = mService.mProcessNames.get(r.processName, r.info.applicationInfo.uid);
-            }
-            if (proc == null || proc.thread == null) {
-                showStartingIcon = true;
-            }
-            if (DEBUG_TRANSITION) Slog.v(TAG,
-                    "Prepare open transition: starting " + r);
-            if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
-                mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, keepCurTransition);
-                mNoAnimActivities.add(r);
-            } else {
-                mWindowManager.prepareAppTransition(newTask
-                        ? AppTransition.TRANSIT_TASK_OPEN
-                        : AppTransition.TRANSIT_ACTIVITY_OPEN, keepCurTransition);
-                mNoAnimActivities.remove(r);
-            }
-            r.updateOptionsLocked(options);
-            mWindowManager.addAppToken(task.mActivities.indexOf(r),
-                    r.appToken, r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
-                    (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId,
-                    r.info.configChanges);
-            boolean doShow = true;
-            if (newTask) {
-                // Even though this activity is starting fresh, we still need
-                // to reset it to make sure we apply affinities to move any
-                // existing activities from other tasks in to it.
-                // If the caller has requested that the target task be
-                // reset, then do so.
-                if ((r.intent.getFlags()
-                        &Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
-                    resetTaskIfNeededLocked(r, r);
-                    doShow = topRunningNonDelayedActivityLocked(null) == r;
-                }
-            }
-            if (SHOW_APP_STARTING_PREVIEW && doShow) {
-                // Figure out if we are transitioning from another activity that is
-                // "has the same starting icon" as the next one.  This allows the
-                // window manager to keep the previous window it had previously
-                // created, if it still had one.
-                ActivityRecord prev = mResumedActivity;
-                if (prev != null) {
-                    // We don't want to reuse the previous starting preview if:
-                    // (1) The current activity is in a different task.
-                    if (prev.task != r.task) {
-                        prev = null;
-                    }
-                    // (2) The current activity is already displayed.
-                    else if (prev.nowVisible) {
-                        prev = null;
-                    }
-                }
-                mWindowManager.setAppStartingWindow(
-                        r.appToken, r.packageName, r.theme,
-                        mService.compatibilityInfoForPackageLocked(
-                                r.info.applicationInfo), r.nonLocalizedLabel,
-                        r.labelRes, r.icon, r.logo, r.windowFlags,
-                        prev != null ? prev.appToken : null, showStartingIcon);
-            }
-        } else {
-            // If this is the first activity, don't do any fancy animations,
-            // because there is nothing for it to animate on top of.
-            mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
-                    r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
-                    (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0, r.userId,
-                    r.info.configChanges);
-            ActivityOptions.abort(options);
-        }
-        if (VALIDATE_TOKENS) {
-            validateAppTokensLocked();
-        }
-
-        if (doResume) {
-            mStackSupervisor.resumeTopActivitiesLocked();
-        }
-    }
-
-    final void validateAppTokensLocked() {
-        mValidateAppTokens.clear();
-        mValidateAppTokens.ensureCapacity(numActivities());
-        final int numTasks = mTaskHistory.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            TaskRecord task = mTaskHistory.get(taskNdx);
-            final ArrayList<ActivityRecord> activities = task.mActivities;
-            if (activities.isEmpty()) {
-                continue;
-            }
-            TaskGroup group = new TaskGroup();
-            group.taskId = task.taskId;
-            mValidateAppTokens.add(group);
-            final int numActivities = activities.size();
-            for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                group.tokens.add(r.appToken);
-            }
-        }
-        mWindowManager.validateAppTokens(mStackId, mValidateAppTokens);
-    }
-
-    /**
-     * Perform a reset of the given task, if needed as part of launching it.
-     * Returns the new HistoryRecord at the top of the task.
-     */
-    /**
-     * Helper method for #resetTaskIfNeededLocked.
-     * We are inside of the task being reset...  we'll either finish this activity, push it out
-     * for another task, or leave it as-is.
-     * @param task The task containing the Activity (taskTop) that might be reset.
-     * @param forceReset
-     * @return An ActivityOptions that needs to be processed.
-     */
-    final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) {
-        ActivityOptions topOptions = null;
-
-        int replyChainEnd = -1;
-        boolean canMoveOptions = true;
-
-        // We only do this for activities that are not the root of the task (since if we finish
-        // the root, we may no longer have the task!).
-        final ArrayList<ActivityRecord> activities = task.mActivities;
-        final int numActivities = activities.size();
-        for (int i = numActivities - 1; i > 0; --i ) {
-            ActivityRecord target = activities.get(i);
-
-            final int flags = target.info.flags;
-            final boolean finishOnTaskLaunch =
-                    (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0;
-            final boolean allowTaskReparenting =
-                    (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0;
-            final boolean clearWhenTaskReset =
-                    (target.intent.getFlags() & Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0;
-
-            if (!finishOnTaskLaunch
-                    && !clearWhenTaskReset
-                    && target.resultTo != null) {
-                // If this activity is sending a reply to a previous
-                // activity, we can't do anything with it now until
-                // we reach the start of the reply chain.
-                // XXX note that we are assuming the result is always
-                // to the previous activity, which is almost always
-                // the case but we really shouldn't count on.
-                if (replyChainEnd < 0) {
-                    replyChainEnd = i;
-                }
-            } else if (!finishOnTaskLaunch
-                    && !clearWhenTaskReset
-                    && allowTaskReparenting
-                    && target.taskAffinity != null
-                    && !target.taskAffinity.equals(task.affinity)) {
-                // If this activity has an affinity for another
-                // task, then we need to move it out of here.  We will
-                // move it as far out of the way as possible, to the
-                // bottom of the activity stack.  This also keeps it
-                // correctly ordered with any activities we previously
-                // moved.
-                final ThumbnailHolder newThumbHolder;
-                final TaskRecord targetTask;
-                final ActivityRecord bottom =
-                        !mTaskHistory.isEmpty() && !mTaskHistory.get(0).mActivities.isEmpty() ?
-                                mTaskHistory.get(0).mActivities.get(0) : null;
-                if (bottom != null && target.taskAffinity != null
-                        && target.taskAffinity.equals(bottom.task.affinity)) {
-                    // If the activity currently at the bottom has the
-                    // same task affinity as the one we are moving,
-                    // then merge it into the same task.
-                    targetTask = bottom.task;
-                    newThumbHolder = bottom.thumbHolder == null ? targetTask : bottom.thumbHolder;
-                    if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target
-                            + " out to bottom task " + bottom.task);
-                } else {
-                    targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info,
-                            null, false);
-                    newThumbHolder = targetTask;
-                    targetTask.affinityIntent = target.intent;
-                    if (DEBUG_TASKS) Slog.v(TAG, "Start pushing activity " + target
-                            + " out to new task " + target.task);
-                }
-
-                if (clearWhenTaskReset) {
-                    // This is the start of a new sub-task.
-                    if (target.thumbHolder == null) {
-                        target.thumbHolder = new ThumbnailHolder();
-                    }
-                } else {
-                    target.thumbHolder = newThumbHolder;
-                }
-
-                final int targetTaskId = targetTask.taskId;
-                mWindowManager.setAppGroupId(target.appToken, targetTaskId);
-
-                boolean noOptions = canMoveOptions;
-                final int start = replyChainEnd < 0 ? i : replyChainEnd;
-                for (int srcPos = start; srcPos >= i; --srcPos) {
-                    final ActivityRecord p = activities.get(srcPos);
-                    if (p.finishing) {
-                        continue;
-                    }
-
-                    ThumbnailHolder curThumbHolder = p.thumbHolder;
-                    canMoveOptions = false;
-                    if (noOptions && topOptions == null) {
-                        topOptions = p.takeOptionsLocked();
-                        if (topOptions != null) {
-                            noOptions = false;
-                        }
-                    }
-                    if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing activity " + p + " from task="
-                            + task + " adding to task=" + targetTask
-                            + " Callers=" + Debug.getCallers(4));
-                    if (DEBUG_TASKS) Slog.v(TAG, "Pushing next activity " + p
-                            + " out to target's task " + target.task);
-                    p.setTask(targetTask, curThumbHolder, false);
-                    targetTask.addActivityAtBottom(p);
-
-                    mWindowManager.setAppGroupId(p.appToken, targetTaskId);
-                }
-
-                mWindowManager.moveTaskToBottom(targetTaskId);
-                if (VALIDATE_TOKENS) {
-                    validateAppTokensLocked();
-                }
-
-                replyChainEnd = -1;
-            } else if (forceReset || finishOnTaskLaunch || clearWhenTaskReset) {
-                // If the activity should just be removed -- either
-                // because it asks for it, or the task should be
-                // cleared -- then finish it and anything that is
-                // part of its reply chain.
-                int end;
-                if (clearWhenTaskReset) {
-                    // In this case, we want to finish this activity
-                    // and everything above it, so be sneaky and pretend
-                    // like these are all in the reply chain.
-                    end = numActivities - 1;
-                } else if (replyChainEnd < 0) {
-                    end = i;
-                } else {
-                    end = replyChainEnd;
-                }
-                boolean noOptions = canMoveOptions;
-                for (int srcPos = i; srcPos <= end; srcPos++) {
-                    ActivityRecord p = activities.get(srcPos);
-                    if (p.finishing) {
-                        continue;
-                    }
-                    canMoveOptions = false;
-                    if (noOptions && topOptions == null) {
-                        topOptions = p.takeOptionsLocked();
-                        if (topOptions != null) {
-                            noOptions = false;
-                        }
-                    }
-                    if (DEBUG_TASKS) Slog.w(TAG,
-                            "resetTaskIntendedTask: calling finishActivity on " + p);
-                    if (finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false)) {
-                        end--;
-                        srcPos--;
-                    }
-                }
-                replyChainEnd = -1;
-            } else {
-                // If we were in the middle of a chain, well the
-                // activity that started it all doesn't want anything
-                // special, so leave it all as-is.
-                replyChainEnd = -1;
-            }
-        }
-
-        return topOptions;
-    }
-
-    /**
-     * Helper method for #resetTaskIfNeededLocked. Processes all of the activities in a given
-     * TaskRecord looking for an affinity with the task of resetTaskIfNeededLocked.taskTop.
-     * @param affinityTask The task we are looking for an affinity to.
-     * @param task Task that resetTaskIfNeededLocked.taskTop belongs to.
-     * @param topTaskIsHigher True if #task has already been processed by resetTaskIfNeededLocked.
-     * @param forceReset Flag passed in to resetTaskIfNeededLocked.
-     */
-    private int resetAffinityTaskIfNeededLocked(TaskRecord affinityTask, TaskRecord task,
-            boolean topTaskIsHigher, boolean forceReset, int taskInsertionPoint) {
-        int replyChainEnd = -1;
-        final int taskId = task.taskId;
-        final String taskAffinity = task.affinity;
-
-        final ArrayList<ActivityRecord> activities = affinityTask.mActivities;
-        final int numActivities = activities.size();
-        // Do not operate on the root Activity.
-        for (int i = numActivities - 1; i > 0; --i) {
-            ActivityRecord target = activities.get(i);
-
-            final int flags = target.info.flags;
-            boolean finishOnTaskLaunch = (flags & ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH) != 0;
-            boolean allowTaskReparenting = (flags & ActivityInfo.FLAG_ALLOW_TASK_REPARENTING) != 0;
-
-            if (target.resultTo != null) {
-                // If this activity is sending a reply to a previous
-                // activity, we can't do anything with it now until
-                // we reach the start of the reply chain.
-                // XXX note that we are assuming the result is always
-                // to the previous activity, which is almost always
-                // the case but we really shouldn't count on.
-                if (replyChainEnd < 0) {
-                    replyChainEnd = i;
-                }
-            } else if (topTaskIsHigher
-                    && allowTaskReparenting
-                    && taskAffinity != null
-                    && taskAffinity.equals(target.taskAffinity)) {
-                // This activity has an affinity for our task. Either remove it if we are
-                // clearing or move it over to our task.  Note that
-                // we currently punt on the case where we are resetting a
-                // task that is not at the top but who has activities above
-                // with an affinity to it...  this is really not a normal
-                // case, and we will need to later pull that task to the front
-                // and usually at that point we will do the reset and pick
-                // up those remaining activities.  (This only happens if
-                // someone starts an activity in a new task from an activity
-                // in a task that is not currently on top.)
-                if (forceReset || finishOnTaskLaunch) {
-                    final int start = replyChainEnd >= 0 ? replyChainEnd : i;
-                    if (DEBUG_TASKS) Slog.v(TAG, "Finishing task at index " + start + " to " + i);
-                    for (int srcPos = start; srcPos >= i; --srcPos) {
-                        final ActivityRecord p = activities.get(srcPos);
-                        if (p.finishing) {
-                            continue;
-                        }
-                        finishActivityLocked(p, Activity.RESULT_CANCELED, null, "reset", false);
-                    }
-                } else {
-                    if (taskInsertionPoint < 0) {
-                        taskInsertionPoint = task.mActivities.size();
-
-                    }
-
-                    final int start = replyChainEnd >= 0 ? replyChainEnd : i;
-                    if (DEBUG_TASKS) Slog.v(TAG, "Reparenting from task=" + affinityTask + ":"
-                            + start + "-" + i + " to task=" + task + ":" + taskInsertionPoint);
-                    for (int srcPos = start; srcPos >= i; --srcPos) {
-                        final ActivityRecord p = activities.get(srcPos);
-                        p.setTask(task, null, false);
-                        task.addActivityAtIndex(taskInsertionPoint, p);
-
-                        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + p
-                                + " to stack at " + task,
-                                new RuntimeException("here").fillInStackTrace());
-                        if (DEBUG_TASKS) Slog.v(TAG, "Pulling activity " + p + " from " + srcPos
-                                + " in to resetting task " + task);
-                        mWindowManager.setAppGroupId(p.appToken, taskId);
-                    }
-                    mWindowManager.moveTaskToTop(taskId);
-                    if (VALIDATE_TOKENS) {
-                        validateAppTokensLocked();
-                    }
-
-                    // Now we've moved it in to place...  but what if this is
-                    // a singleTop activity and we have put it on top of another
-                    // instance of the same activity?  Then we drop the instance
-                    // below so it remains singleTop.
-                    if (target.info.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP) {
-                        ArrayList<ActivityRecord> taskActivities = task.mActivities;
-                        int targetNdx = taskActivities.indexOf(target);
-                        if (targetNdx > 0) {
-                            ActivityRecord p = taskActivities.get(targetNdx - 1);
-                            if (p.intent.getComponent().equals(target.intent.getComponent())) {
-                                finishActivityLocked(p, Activity.RESULT_CANCELED, null, "replace",
-                                        false);
-                            }
-                        }
-                    }
-                }
-
-                replyChainEnd = -1;
-            }
-        }
-        return taskInsertionPoint;
-    }
-
-    final ActivityRecord resetTaskIfNeededLocked(ActivityRecord taskTop,
-            ActivityRecord newActivity) {
-        boolean forceReset =
-                (newActivity.info.flags & ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH) != 0;
-        if (ACTIVITY_INACTIVE_RESET_TIME > 0
-                && taskTop.task.getInactiveDuration() > ACTIVITY_INACTIVE_RESET_TIME) {
-            if ((newActivity.info.flags & ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE) == 0) {
-                forceReset = true;
-            }
-        }
-
-        final TaskRecord task = taskTop.task;
-
-        /** False until we evaluate the TaskRecord associated with taskTop. Switches to true
-         * for remaining tasks. Used for later tasks to reparent to task. */
-        boolean taskFound = false;
-
-        /** If ActivityOptions are moved out and need to be aborted or moved to taskTop. */
-        ActivityOptions topOptions = null;
-
-        // Preserve the location for reparenting in the new task.
-        int reparentInsertionPoint = -1;
-
-        for (int i = mTaskHistory.size() - 1; i >= 0; --i) {
-            final TaskRecord targetTask = mTaskHistory.get(i);
-
-            if (targetTask == task) {
-                topOptions = resetTargetTaskIfNeededLocked(task, forceReset);
-                taskFound = true;
-            } else {
-                reparentInsertionPoint = resetAffinityTaskIfNeededLocked(targetTask, task,
-                        taskFound, forceReset, reparentInsertionPoint);
-            }
-        }
-
-        int taskNdx = mTaskHistory.indexOf(task);
-        do {
-            taskTop = mTaskHistory.get(taskNdx--).getTopActivity();
-        } while (taskTop == null && taskNdx >= 0);
-
-        if (topOptions != null) {
-            // If we got some ActivityOptions from an activity on top that
-            // was removed from the task, propagate them to the new real top.
-            if (taskTop != null) {
-                taskTop.updateOptionsLocked(topOptions);
-            } else {
-                topOptions.abort();
-            }
-        }
-
-        return taskTop;
-    }
-
-    void sendActivityResultLocked(int callingUid, ActivityRecord r,
-            String resultWho, int requestCode, int resultCode, Intent data) {
-
-        if (callingUid > 0) {
-            mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
-                    data, r.getUriPermissionsLocked());
-        }
-
-        if (DEBUG_RESULTS) Slog.v(TAG, "Send activity result to " + r
-                + " : who=" + resultWho + " req=" + requestCode
-                + " res=" + resultCode + " data=" + data);
-        if (mResumedActivity == r && r.app != null && r.app.thread != null) {
-            try {
-                ArrayList<ResultInfo> list = new ArrayList<ResultInfo>();
-                list.add(new ResultInfo(resultWho, requestCode,
-                        resultCode, data));
-                r.app.thread.scheduleSendResult(r.appToken, list);
-                return;
-            } catch (Exception e) {
-                Slog.w(TAG, "Exception thrown sending result to " + r, e);
-            }
-        }
-
-        r.addResultLocked(null, resultWho, requestCode, resultCode, data);
-    }
-
-    private void adjustFocusedActivityLocked(ActivityRecord r) {
-        if (mStackSupervisor.isFrontStack(this) && mService.mFocusedActivity == r) {
-            ActivityRecord next = topRunningActivityLocked(null);
-            if (next != r) {
-                final TaskRecord task = r.task;
-                if (r.frontOfTask && task == topTask() && task.mOnTopOfHome) {
-                    mStackSupervisor.moveHomeToTop();
-                }
-            }
-            mService.setFocusedActivityLocked(mStackSupervisor.topRunningActivityLocked());
-        }
-    }
-
-    final void stopActivityLocked(ActivityRecord r) {
-        if (DEBUG_SWITCH) Slog.d(TAG, "Stopping: " + r);
-        if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_HISTORY) != 0
-                || (r.info.flags&ActivityInfo.FLAG_NO_HISTORY) != 0) {
-            if (!r.finishing) {
-                if (!mService.mSleeping) {
-                    if (DEBUG_STATES) {
-                        Slog.d(TAG, "no-history finish of " + r);
-                    }
-                    requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
-                            "no-history", false);
-                } else {
-                    if (DEBUG_STATES) Slog.d(TAG, "Not finishing noHistory " + r
-                            + " on stop because we're just sleeping");
-                }
-            }
-        }
-
-        if (r.app != null && r.app.thread != null) {
-            adjustFocusedActivityLocked(r);
-            r.resumeKeyDispatchingLocked();
-            try {
-                r.stopped = false;
-                if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r
-                        + " (stop requested)");
-                r.state = ActivityState.STOPPING;
-                if (DEBUG_VISBILITY) Slog.v(
-                        TAG, "Stopping visible=" + r.visible + " for " + r);
-                if (!r.visible) {
-                    mWindowManager.setAppVisibility(r.appToken, false);
-                }
-                r.app.thread.scheduleStopActivity(r.appToken, r.visible, r.configChangeFlags);
-                if (mService.isSleepingOrShuttingDown()) {
-                    r.setSleeping(true);
-                }
-                Message msg = mHandler.obtainMessage(STOP_TIMEOUT_MSG, r);
-                mHandler.sendMessageDelayed(msg, STOP_TIMEOUT);
-            } catch (Exception e) {
-                // Maybe just ignore exceptions here...  if the process
-                // has crashed, our death notification will clean things
-                // up.
-                Slog.w(TAG, "Exception thrown during pause", e);
-                // Just in case, assume it to be stopped.
-                r.stopped = true;
-                if (DEBUG_STATES) Slog.v(TAG, "Stop failed; moving to STOPPED: " + r);
-                r.state = ActivityState.STOPPED;
-                if (r.configDestroy) {
-                    destroyActivityLocked(r, true, false, "stop-except");
-                }
-            }
-        }
-    }
-
-    /**
-     * @return Returns true if the activity is being finished, false if for
-     * some reason it is being left as-is.
-     */
-    final boolean requestFinishActivityLocked(IBinder token, int resultCode,
-            Intent resultData, String reason, boolean oomAdj) {
-        ActivityRecord r = isInStackLocked(token);
-        if (DEBUG_RESULTS || DEBUG_STATES) Slog.v(
-                TAG, "Finishing activity token=" + token + " r="
-                + ", result=" + resultCode + ", data=" + resultData
-                + ", reason=" + reason);
-        if (r == null) {
-            return false;
-        }
-
-        finishActivityLocked(r, resultCode, resultData, reason, oomAdj);
-        return true;
-    }
-
-    final void finishSubActivityLocked(ActivityRecord self, String resultWho, int requestCode) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                ActivityRecord r = activities.get(activityNdx);
-                if (r.resultTo == self && r.requestCode == requestCode) {
-                    if ((r.resultWho == null && resultWho == null) ||
-                        (r.resultWho != null && r.resultWho.equals(resultWho))) {
-                        finishActivityLocked(r, Activity.RESULT_CANCELED, null, "request-sub",
-                                false);
-                    }
-                }
-            }
-        }
-        mService.updateOomAdjLocked();
-    }
-
-    final void finishTopRunningActivityLocked(ProcessRecord app) {
-        ActivityRecord r = topRunningActivityLocked(null);
-        if (r != null && r.app == app) {
-            // If the top running activity is from this crashing
-            // process, then terminate it to avoid getting in a loop.
-            Slog.w(TAG, "  Force finishing activity "
-                    + r.intent.getComponent().flattenToShortString());
-            int taskNdx = mTaskHistory.indexOf(r.task);
-            int activityNdx = r.task.mActivities.indexOf(r);
-            finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false);
-            // Also terminate any activities below it that aren't yet
-            // stopped, to avoid a situation where one will get
-            // re-start our crashing activity once it gets resumed again.
-            --activityNdx;
-            if (activityNdx < 0) {
-                do {
-                    --taskNdx;
-                    if (taskNdx < 0) {
-                        break;
-                    }
-                    activityNdx = mTaskHistory.get(taskNdx).mActivities.size() - 1;
-                } while (activityNdx < 0);
-            }
-            if (activityNdx >= 0) {
-                r = mTaskHistory.get(taskNdx).mActivities.get(activityNdx);
-                if (r.state == ActivityState.RESUMED
-                        || r.state == ActivityState.PAUSING
-                        || r.state == ActivityState.PAUSED) {
-                    if (!r.isHomeActivity() || mService.mHomeProcess != r.app) {
-                        Slog.w(TAG, "  Force finishing activity "
-                                + r.intent.getComponent().flattenToShortString());
-                        finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false);
-                    }
-                }
-            }
-        }
-    }
-
-    final boolean finishActivityAffinityLocked(ActivityRecord r) {
-        ArrayList<ActivityRecord> activities = r.task.mActivities;
-        for (int index = activities.indexOf(r); index >= 0; --index) {
-            ActivityRecord cur = activities.get(index);
-            if (!Objects.equal(cur.taskAffinity, r.taskAffinity)) {
-                break;
-            }
-            finishActivityLocked(cur, Activity.RESULT_CANCELED, null, "request-affinity", true);
-        }
-        return true;
-    }
-
-    final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) {
-        // send the result
-        ActivityRecord resultTo = r.resultTo;
-        if (resultTo != null) {
-            if (DEBUG_RESULTS) Slog.v(TAG, "Adding result to " + resultTo
-                    + " who=" + r.resultWho + " req=" + r.requestCode
-                    + " res=" + resultCode + " data=" + resultData);
-            if (r.info.applicationInfo.uid > 0) {
-                mService.grantUriPermissionFromIntentLocked(r.info.applicationInfo.uid,
-                        resultTo.packageName, resultData,
-                        resultTo.getUriPermissionsLocked());
-            }
-            resultTo.addResultLocked(r, r.resultWho, r.requestCode, resultCode,
-                                     resultData);
-            r.resultTo = null;
-        }
-        else if (DEBUG_RESULTS) Slog.v(TAG, "No result destination from " + r);
-
-        // Make sure this HistoryRecord is not holding on to other resources,
-        // because clients have remote IPC references to this object so we
-        // can't assume that will go away and want to avoid circular IPC refs.
-        r.results = null;
-        r.pendingResults = null;
-        r.newIntents = null;
-        r.icicle = null;
-    }
-
-    /**
-     * @return Returns true if this activity has been removed from the history
-     * list, or false if it is still in the list and will be removed later.
-     */
-    final boolean finishActivityLocked(ActivityRecord r, int resultCode, Intent resultData,
-            String reason, boolean oomAdj) {
-        if (r.finishing) {
-            Slog.w(TAG, "Duplicate finish request for " + r);
-            return false;
-        }
-
-        r.makeFinishing();
-        EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,
-                r.userId, System.identityHashCode(r),
-                r.task.taskId, r.shortComponentName, reason);
-        final ArrayList<ActivityRecord> activities = r.task.mActivities;
-        final int index = activities.indexOf(r);
-        if (index < (activities.size() - 1)) {
-            ActivityRecord next = activities.get(index+1);
-            if (r.frontOfTask) {
-                // The next activity is now the front of the task.
-                next.frontOfTask = true;
-            }
-            if ((r.intent.getFlags()&Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) != 0) {
-                // If the caller asked that this activity (and all above it)
-                // be cleared when the task is reset, don't lose that information,
-                // but propagate it up to the next activity.
-                next.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
-            }
-        }
-
-        r.pauseKeyDispatchingLocked();
-
-        adjustFocusedActivityLocked(r);
-
-        finishActivityResultsLocked(r, resultCode, resultData);
-
-        if (!mService.mPendingThumbnails.isEmpty()) {
-            // There are clients waiting to receive thumbnails so, in case
-            // this is an activity that someone is waiting for, add it
-            // to the pending list so we can correctly update the clients.
-            mStackSupervisor.mCancelledThumbnails.add(r);
-        }
-
-        if (mResumedActivity == r) {
-            boolean endTask = index <= 0;
-            if (DEBUG_VISBILITY || DEBUG_TRANSITION) Slog.v(TAG,
-                    "Prepare close transition: finishing " + r);
-            mWindowManager.prepareAppTransition(endTask
-                    ? AppTransition.TRANSIT_TASK_CLOSE
-                    : AppTransition.TRANSIT_ACTIVITY_CLOSE, false);
-
-            // Tell window manager to prepare for this one to be removed.
-            mWindowManager.setAppVisibility(r.appToken, false);
-
-            if (mPausingActivity == null) {
-                if (DEBUG_PAUSE) Slog.v(TAG, "Finish needs to pause: " + r);
-                if (DEBUG_USER_LEAVING) Slog.v(TAG, "finish() => pause with userLeaving=false");
-                startPausingLocked(false, false);
-            }
-
-        } else if (r.state != ActivityState.PAUSING) {
-            // If the activity is PAUSING, we will complete the finish once
-            // it is done pausing; else we can just directly finish it here.
-            if (DEBUG_PAUSE) Slog.v(TAG, "Finish not pausing: " + r);
-            return finishCurrentActivityLocked(r, FINISH_AFTER_PAUSE, oomAdj) == null;
-        } else {
-            if (DEBUG_PAUSE) Slog.v(TAG, "Finish waiting for pause of: " + r);
-        }
-
-        return false;
-    }
-
-    static final int FINISH_IMMEDIATELY = 0;
-    static final int FINISH_AFTER_PAUSE = 1;
-    static final int FINISH_AFTER_VISIBLE = 2;
-
-    final ActivityRecord finishCurrentActivityLocked(ActivityRecord r, int mode, boolean oomAdj) {
-        // First things first: if this activity is currently visible,
-        // and the resumed activity is not yet visible, then hold off on
-        // finishing until the resumed one becomes visible.
-        if (mode == FINISH_AFTER_VISIBLE && r.nowVisible) {
-            if (!mStackSupervisor.mStoppingActivities.contains(r)) {
-                mStackSupervisor.mStoppingActivities.add(r);
-                if (mStackSupervisor.mStoppingActivities.size() > 3
-                        || r.frontOfTask && mTaskHistory.size() <= 1) {
-                    // If we already have a few activities waiting to stop,
-                    // then give up on things going idle and start clearing
-                    // them out. Or if r is the last of activity of the last task the stack
-                    // will be empty and must be cleared immediately.
-                    mStackSupervisor.scheduleIdleLocked();
-                } else {
-                    mStackSupervisor.checkReadyForSleepLocked();
-                }
-            }
-            if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPING: " + r
-                    + " (finish requested)");
-            r.state = ActivityState.STOPPING;
-            if (oomAdj) {
-                mService.updateOomAdjLocked();
-            }
-            return r;
-        }
-
-        // make sure the record is cleaned out of other places.
-        mStackSupervisor.mStoppingActivities.remove(r);
-        mStackSupervisor.mGoingToSleepActivities.remove(r);
-        mStackSupervisor.mWaitingVisibleActivities.remove(r);
-        if (mResumedActivity == r) {
-            mResumedActivity = null;
-        }
-        final ActivityState prevState = r.state;
-        if (DEBUG_STATES) Slog.v(TAG, "Moving to FINISHING: " + r);
-        r.state = ActivityState.FINISHING;
-
-        if (mode == FINISH_IMMEDIATELY
-                || prevState == ActivityState.STOPPED
-                || prevState == ActivityState.INITIALIZING) {
-            // If this activity is already stopped, we can just finish
-            // it right now.
-            boolean activityRemoved = destroyActivityLocked(r, true,
-                    oomAdj, "finish-imm");
-            if (activityRemoved) {
-                mStackSupervisor.resumeTopActivitiesLocked();
-            }
-            return activityRemoved ? null : r;
-        }
-
-        // Need to go through the full pause cycle to get this
-        // activity into the stopped state and then finish it.
-        if (localLOGV) Slog.v(TAG, "Enqueueing pending finish: " + r);
-        mStackSupervisor.mFinishingActivities.add(r);
-        mStackSupervisor.getFocusedStack().resumeTopActivityLocked(null);
-        return r;
-    }
-
-    final boolean navigateUpToLocked(IBinder token, Intent destIntent, int resultCode,
-            Intent resultData) {
-        final ActivityRecord srec = ActivityRecord.forToken(token);
-        final TaskRecord task = srec.task;
-        final ArrayList<ActivityRecord> activities = task.mActivities;
-        final int start = activities.indexOf(srec);
-        if (!mTaskHistory.contains(task) || (start < 0)) {
-            return false;
-        }
-        int finishTo = start - 1;
-        ActivityRecord parent = finishTo < 0 ? null : activities.get(finishTo);
-        boolean foundParentInTask = false;
-        final ComponentName dest = destIntent.getComponent();
-        if (start > 0 && dest != null) {
-            for (int i = finishTo; i >= 0; i--) {
-                ActivityRecord r = activities.get(i);
-                if (r.info.packageName.equals(dest.getPackageName()) &&
-                        r.info.name.equals(dest.getClassName())) {
-                    finishTo = i;
-                    parent = r;
-                    foundParentInTask = true;
-                    break;
-                }
-            }
-        }
-
-        IActivityController controller = mService.mController;
-        if (controller != null) {
-            ActivityRecord next = topRunningActivityLocked(srec.appToken, 0);
-            if (next != null) {
-                // ask watcher if this is allowed
-                boolean resumeOK = true;
-                try {
-                    resumeOK = controller.activityResuming(next.packageName);
-                } catch (RemoteException e) {
-                    mService.mController = null;
-                    Watchdog.getInstance().setActivityController(null);
-                }
-
-                if (!resumeOK) {
-                    return false;
-                }
-            }
-        }
-        final long origId = Binder.clearCallingIdentity();
-        for (int i = start; i > finishTo; i--) {
-            ActivityRecord r = activities.get(i);
-            requestFinishActivityLocked(r.appToken, resultCode, resultData, "navigate-up", true);
-            // Only return the supplied result for the first activity finished
-            resultCode = Activity.RESULT_CANCELED;
-            resultData = null;
-        }
-
-        if (parent != null && foundParentInTask) {
-            final int parentLaunchMode = parent.info.launchMode;
-            final int destIntentFlags = destIntent.getFlags();
-            if (parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE ||
-                    parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TASK ||
-                    parentLaunchMode == ActivityInfo.LAUNCH_SINGLE_TOP ||
-                    (destIntentFlags & Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0) {
-                parent.deliverNewIntentLocked(srec.info.applicationInfo.uid, destIntent);
-            } else {
-                try {
-                    ActivityInfo aInfo = AppGlobals.getPackageManager().getActivityInfo(
-                            destIntent.getComponent(), 0, srec.userId);
-                    int res = mStackSupervisor.startActivityLocked(srec.app.thread, destIntent,
-                            null, aInfo, parent.appToken, null,
-                            0, -1, parent.launchedFromUid, parent.launchedFromPackage,
-                            0, null, true, null);
-                    foundParentInTask = res == ActivityManager.START_SUCCESS;
-                } catch (RemoteException e) {
-                    foundParentInTask = false;
-                }
-                requestFinishActivityLocked(parent.appToken, resultCode,
-                        resultData, "navigate-up", true);
-            }
-        }
-        Binder.restoreCallingIdentity(origId);
-        return foundParentInTask;
-    }
-    /**
-     * Perform the common clean-up of an activity record.  This is called both
-     * as part of destroyActivityLocked() (when destroying the client-side
-     * representation) and cleaning things up as a result of its hosting
-     * processing going away, in which case there is no remaining client-side
-     * state to destroy so only the cleanup here is needed.
-     */
-    final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
-            boolean setState) {
-        if (mResumedActivity == r) {
-            mResumedActivity = null;
-        }
-        if (mService.mFocusedActivity == r) {
-            mService.mFocusedActivity = null;
-        }
-
-        r.configDestroy = false;
-        r.frozenBeforeDestroy = false;
-
-        if (setState) {
-            if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (cleaning up)");
-            r.state = ActivityState.DESTROYED;
-            if (DEBUG_APP) Slog.v(TAG, "Clearing app during cleanUp for activity " + r);
-            r.app = null;
-        }
-
-        // Make sure this record is no longer in the pending finishes list.
-        // This could happen, for example, if we are trimming activities
-        // down to the max limit while they are still waiting to finish.
-        mStackSupervisor.mFinishingActivities.remove(r);
-        mStackSupervisor.mWaitingVisibleActivities.remove(r);
-
-        // Remove any pending results.
-        if (r.finishing && r.pendingResults != null) {
-            for (WeakReference<PendingIntentRecord> apr : r.pendingResults) {
-                PendingIntentRecord rec = apr.get();
-                if (rec != null) {
-                    mService.cancelIntentSenderLocked(rec, false);
-                }
-            }
-            r.pendingResults = null;
-        }
-
-        if (cleanServices) {
-            cleanUpActivityServicesLocked(r);
-        }
-
-        if (!mService.mPendingThumbnails.isEmpty()) {
-            // There are clients waiting to receive thumbnails so, in case
-            // this is an activity that someone is waiting for, add it
-            // to the pending list so we can correctly update the clients.
-            mStackSupervisor.mCancelledThumbnails.add(r);
-        }
-
-        // Get rid of any pending idle timeouts.
-        removeTimeoutsForActivityLocked(r);
-    }
-
-    private void removeTimeoutsForActivityLocked(ActivityRecord r) {
-        mStackSupervisor.removeTimeoutsForActivityLocked(r);
-        mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
-        mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
-        mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
-        r.finishLaunchTickingLocked();
-    }
-
-    final void removeActivityFromHistoryLocked(ActivityRecord r) {
-        finishActivityResultsLocked(r, Activity.RESULT_CANCELED, null);
-        r.makeFinishing();
-        if (DEBUG_ADD_REMOVE) {
-            RuntimeException here = new RuntimeException("here");
-            here.fillInStackTrace();
-            Slog.i(TAG, "Removing activity " + r + " from stack");
-        }
-        final TaskRecord task = r.task;
-        if (task != null && task.removeActivity(r)) {
-            if (DEBUG_STACK) Slog.i(TAG,
-                    "removeActivityFromHistoryLocked: last activity removed from " + this);
-            if (mStackSupervisor.isFrontStack(this) && task == topTask() && task.mOnTopOfHome) {
-                mStackSupervisor.moveHomeToTop();
-            }
-            mStackSupervisor.removeTask(task);
-        }
-        r.takeFromHistory();
-        removeTimeoutsForActivityLocked(r);
-        if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (removed from history)");
-        r.state = ActivityState.DESTROYED;
-        if (DEBUG_APP) Slog.v(TAG, "Clearing app during remove for activity " + r);
-        r.app = null;
-        mWindowManager.removeAppToken(r.appToken);
-        if (VALIDATE_TOKENS) {
-            validateAppTokensLocked();
-        }
-        cleanUpActivityServicesLocked(r);
-        r.removeUriPermissionsLocked();
-    }
-
-    /**
-     * Perform clean-up of service connections in an activity record.
-     */
-    final void cleanUpActivityServicesLocked(ActivityRecord r) {
-        // Throw away any services that have been bound by this activity.
-        if (r.connections != null) {
-            Iterator<ConnectionRecord> it = r.connections.iterator();
-            while (it.hasNext()) {
-                ConnectionRecord c = it.next();
-                mService.mServices.removeConnectionLocked(c, null, r);
-            }
-            r.connections = null;
-        }
-    }
-
-    final void scheduleDestroyActivities(ProcessRecord owner, boolean oomAdj, String reason) {
-        Message msg = mHandler.obtainMessage(DESTROY_ACTIVITIES_MSG);
-        msg.obj = new ScheduleDestroyArgs(owner, oomAdj, reason);
-        mHandler.sendMessage(msg);
-    }
-
-    final void destroyActivitiesLocked(ProcessRecord owner, boolean oomAdj, String reason) {
-        boolean lastIsOpaque = false;
-        boolean activityRemoved = false;
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.finishing) {
-                    continue;
-                }
-                if (r.fullscreen) {
-                    lastIsOpaque = true;
-                }
-                if (owner != null && r.app != owner) {
-                    continue;
-                }
-                if (!lastIsOpaque) {
-                    continue;
-                }
-                // We can destroy this one if we have its icicle saved and
-                // it is not in the process of pausing/stopping/finishing.
-                if (r.app != null && r != mResumedActivity && r != mPausingActivity
-                        && r.haveState && !r.visible && r.stopped
-                        && r.state != ActivityState.DESTROYING
-                        && r.state != ActivityState.DESTROYED) {
-                    if (DEBUG_SWITCH) Slog.v(TAG, "Destroying " + r + " in state " + r.state
-                            + " resumed=" + mResumedActivity
-                            + " pausing=" + mPausingActivity);
-                    if (destroyActivityLocked(r, true, oomAdj, reason)) {
-                        activityRemoved = true;
-                    }
-                }
-            }
-        }
-        if (activityRemoved) {
-            mStackSupervisor.resumeTopActivitiesLocked();
-
-        }
-    }
-
-    /**
-     * Destroy the current CLIENT SIDE instance of an activity.  This may be
-     * called both when actually finishing an activity, or when performing
-     * a configuration switch where we destroy the current client-side object
-     * but then create a new client-side object for this same HistoryRecord.
-     */
-    final boolean destroyActivityLocked(ActivityRecord r,
-            boolean removeFromApp, boolean oomAdj, String reason) {
-        if (DEBUG_SWITCH || DEBUG_CLEANUP) Slog.v(
-            TAG, "Removing activity from " + reason + ": token=" + r
-              + ", app=" + (r.app != null ? r.app.processName : "(null)"));
-        EventLog.writeEvent(EventLogTags.AM_DESTROY_ACTIVITY,
-                r.userId, System.identityHashCode(r),
-                r.task.taskId, r.shortComponentName, reason);
-
-        boolean removedFromHistory = false;
-
-        cleanUpActivityLocked(r, false, false);
-
-        final boolean hadApp = r.app != null;
-
-        if (hadApp) {
-            if (removeFromApp) {
-                r.app.activities.remove(r);
-                if (mService.mHeavyWeightProcess == r.app && r.app.activities.size() <= 0) {
-                    mService.mHeavyWeightProcess = null;
-                    mService.mHandler.sendEmptyMessage(
-                            ActivityManagerService.CANCEL_HEAVY_NOTIFICATION_MSG);
-                }
-                if (r.app.activities.isEmpty()) {
-                    // No longer have activities, so update LRU list and oom adj.
-                    mService.updateLruProcessLocked(r.app, false, null);
-                    mService.updateOomAdjLocked();
-                }
-            }
-
-            boolean skipDestroy = false;
-
-            try {
-                if (DEBUG_SWITCH) Slog.i(TAG, "Destroying: " + r);
-                r.app.thread.scheduleDestroyActivity(r.appToken, r.finishing,
-                        r.configChangeFlags);
-            } catch (Exception e) {
-                // We can just ignore exceptions here...  if the process
-                // has crashed, our death notification will clean things
-                // up.
-                //Slog.w(TAG, "Exception thrown during finish", e);
-                if (r.finishing) {
-                    removeActivityFromHistoryLocked(r);
-                    removedFromHistory = true;
-                    skipDestroy = true;
-                }
-            }
-
-            r.nowVisible = false;
-
-            // If the activity is finishing, we need to wait on removing it
-            // from the list to give it a chance to do its cleanup.  During
-            // that time it may make calls back with its token so we need to
-            // be able to find it on the list and so we don't want to remove
-            // it from the list yet.  Otherwise, we can just immediately put
-            // it in the destroyed state since we are not removing it from the
-            // list.
-            if (r.finishing && !skipDestroy) {
-                if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYING: " + r
-                        + " (destroy requested)");
-                r.state = ActivityState.DESTROYING;
-                Message msg = mHandler.obtainMessage(DESTROY_TIMEOUT_MSG, r);
-                mHandler.sendMessageDelayed(msg, DESTROY_TIMEOUT);
-            } else {
-                if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (destroy skipped)");
-                r.state = ActivityState.DESTROYED;
-                if (DEBUG_APP) Slog.v(TAG, "Clearing app during destroy for activity " + r);
-                r.app = null;
-            }
-        } else {
-            // remove this record from the history.
-            if (r.finishing) {
-                removeActivityFromHistoryLocked(r);
-                removedFromHistory = true;
-            } else {
-                if (DEBUG_STATES) Slog.v(TAG, "Moving to DESTROYED: " + r + " (no app)");
-                r.state = ActivityState.DESTROYED;
-                if (DEBUG_APP) Slog.v(TAG, "Clearing app during destroy for activity " + r);
-                r.app = null;
-            }
-        }
-
-        r.configChangeFlags = 0;
-
-        if (!mLRUActivities.remove(r) && hadApp) {
-            Slog.w(TAG, "Activity " + r + " being finished, but not in LRU list");
-        }
-
-        return removedFromHistory;
-    }
-
-    final void activityDestroyedLocked(IBinder token) {
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            ActivityRecord r = ActivityRecord.forToken(token);
-            if (r != null) {
-                mHandler.removeMessages(DESTROY_TIMEOUT_MSG, r);
-            }
-
-            if (isInStackLocked(token) != null) {
-                if (r.state == ActivityState.DESTROYING) {
-                    cleanUpActivityLocked(r, true, false);
-                    removeActivityFromHistoryLocked(r);
-                }
-            }
-            mStackSupervisor.resumeTopActivitiesLocked();
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    private void removeHistoryRecordsForAppLocked(ArrayList<ActivityRecord> list,
-            ProcessRecord app, String listName) {
-        int i = list.size();
-        if (DEBUG_CLEANUP) Slog.v(
-            TAG, "Removing app " + app + " from list " + listName
-            + " with " + i + " entries");
-        while (i > 0) {
-            i--;
-            ActivityRecord r = list.get(i);
-            if (DEBUG_CLEANUP) Slog.v(TAG, "Record #" + i + " " + r);
-            if (r.app == app) {
-                if (DEBUG_CLEANUP) Slog.v(TAG, "---> REMOVING this entry!");
-                list.remove(i);
-                removeTimeoutsForActivityLocked(r);
-            }
-        }
-    }
-
-    boolean removeHistoryRecordsForAppLocked(ProcessRecord app) {
-        removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities");
-        removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app,
-                "mStoppingActivities");
-        removeHistoryRecordsForAppLocked(mStackSupervisor.mGoingToSleepActivities, app,
-                "mGoingToSleepActivities");
-        removeHistoryRecordsForAppLocked(mStackSupervisor.mWaitingVisibleActivities, app,
-                "mWaitingVisibleActivities");
-        removeHistoryRecordsForAppLocked(mStackSupervisor.mFinishingActivities, app,
-                "mFinishingActivities");
-
-        boolean hasVisibleActivities = false;
-
-        // Clean out the history list.
-        int i = numActivities();
-        if (DEBUG_CLEANUP) Slog.v(
-            TAG, "Removing app " + app + " from history with " + i + " entries");
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                --i;
-                if (DEBUG_CLEANUP) Slog.v(
-                    TAG, "Record #" + i + " " + r + ": app=" + r.app);
-                if (r.app == app) {
-                    boolean remove;
-                    if ((!r.haveState && !r.stateNotNeeded) || r.finishing) {
-                        // Don't currently have state for the activity, or
-                        // it is finishing -- always remove it.
-                        remove = true;
-                    } else if (r.launchCount > 2 &&
-                            r.lastLaunchTime > (SystemClock.uptimeMillis()-60000)) {
-                        // We have launched this activity too many times since it was
-                        // able to run, so give up and remove it.
-                        remove = true;
-                    } else {
-                        // The process may be gone, but the activity lives on!
-                        remove = false;
-                    }
-                    if (remove) {
-                        if (DEBUG_ADD_REMOVE || DEBUG_CLEANUP) {
-                            RuntimeException here = new RuntimeException("here");
-                            here.fillInStackTrace();
-                            Slog.i(TAG, "Removing activity " + r + " from stack at " + i
-                                    + ": haveState=" + r.haveState
-                                    + " stateNotNeeded=" + r.stateNotNeeded
-                                    + " finishing=" + r.finishing
-                                    + " state=" + r.state, here);
-                        }
-                        if (!r.finishing) {
-                            Slog.w(TAG, "Force removing " + r + ": app died, no saved state");
-                            EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,
-                                    r.userId, System.identityHashCode(r),
-                                    r.task.taskId, r.shortComponentName,
-                                    "proc died without state saved");
-                            if (r.state == ActivityState.RESUMED) {
-                                mService.updateUsageStats(r, false);
-                            }
-                        }
-                        removeActivityFromHistoryLocked(r);
-
-                    } else {
-                        // We have the current state for this activity, so
-                        // it can be restarted later when needed.
-                        if (localLOGV) Slog.v(
-                            TAG, "Keeping entry, setting app to null");
-                        if (r.visible) {
-                            hasVisibleActivities = true;
-                        }
-                        if (DEBUG_APP) Slog.v(TAG, "Clearing app during removeHistory for activity "
-                                + r);
-                        r.app = null;
-                        r.nowVisible = false;
-                        if (!r.haveState) {
-                            if (DEBUG_SAVED_STATE) Slog.i(TAG,
-                                    "App died, clearing saved state of " + r);
-                            r.icicle = null;
-                        }
-                    }
-
-                    cleanUpActivityLocked(r, true, true);
-                }
-            }
-        }
-
-        return hasVisibleActivities;
-    }
-
-    final void updateTransitLocked(int transit, Bundle options) {
-        if (options != null) {
-            ActivityRecord r = topRunningActivityLocked(null);
-            if (r != null && r.state != ActivityState.RESUMED) {
-                r.updateOptionsLocked(options);
-            } else {
-                ActivityOptions.abort(options);
-            }
-        }
-        mWindowManager.prepareAppTransition(transit, false);
-    }
-
-    void moveHomeTaskToTop() {
-        final int top = mTaskHistory.size() - 1;
-        for (int taskNdx = top; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            if (task.isHomeTask()) {
-                if (DEBUG_TASKS || DEBUG_STACK) Slog.d(TAG, "moveHomeTaskToTop: moving " + task);
-                mTaskHistory.remove(taskNdx);
-                mTaskHistory.add(top, task);
-                mWindowManager.moveTaskToTop(task.taskId);
-                return;
-            }
-        }
-    }
-
-    final boolean findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) {
-        final TaskRecord task = taskForIdLocked(taskId);
-        if (task != null) {
-            if ((flags & ActivityManager.MOVE_TASK_NO_USER_ACTION) == 0) {
-                mStackSupervisor.mUserLeaving = true;
-            }
-            if ((flags & ActivityManager.MOVE_TASK_WITH_HOME) != 0) {
-                // Caller wants the home activity moved with it.  To accomplish this,
-                // we'll just indicate that this task returns to the home task.
-                task.mOnTopOfHome = true;
-            }
-            moveTaskToFrontLocked(task, null, options);
-            return true;
-        }
-        return false;
-    }
-
-    final void moveTaskToFrontLocked(TaskRecord tr, ActivityRecord reason, Bundle options) {
-        if (DEBUG_SWITCH) Slog.v(TAG, "moveTaskToFront: " + tr);
-
-        final int numTasks = mTaskHistory.size();
-        final int index = mTaskHistory.indexOf(tr);
-        if (numTasks == 0 || index < 0)  {
-            // nothing to do!
-            if (reason != null &&
-                    (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
-                ActivityOptions.abort(options);
-            } else {
-                updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options);
-            }
-            return;
-        }
-
-        mStackSupervisor.moveHomeStack(isHomeStack());
-
-        // Shift all activities with this task up to the top
-        // of the stack, keeping them in the same internal order.
-        insertTaskAtTop(tr);
-
-        if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to front transition: task=" + tr);
-        if (reason != null &&
-                (reason.intent.getFlags()&Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
-            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
-            ActivityRecord r = topRunningActivityLocked(null);
-            if (r != null) {
-                mNoAnimActivities.add(r);
-            }
-            ActivityOptions.abort(options);
-        } else {
-            updateTransitLocked(AppTransition.TRANSIT_TASK_TO_FRONT, options);
-        }
-
-        mWindowManager.moveTaskToTop(tr.taskId);
-
-        mStackSupervisor.resumeTopActivitiesLocked();
-        EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, tr.userId, tr.taskId);
-
-        if (VALIDATE_TOKENS) {
-            validateAppTokensLocked();
-        }
-    }
-
-    /**
-     * Worker method for rearranging history stack. Implements the function of moving all
-     * activities for a specific task (gathering them if disjoint) into a single group at the
-     * bottom of the stack.
-     *
-     * If a watcher is installed, the action is preflighted and the watcher has an opportunity
-     * to premeptively cancel the move.
-     *
-     * @param taskId The taskId to collect and move to the bottom.
-     * @return Returns true if the move completed, false if not.
-     */
-    final boolean moveTaskToBackLocked(int taskId, ActivityRecord reason) {
-        Slog.i(TAG, "moveTaskToBack: " + taskId);
-
-        // If we have a watcher, preflight the move before committing to it.  First check
-        // for *other* available tasks, but if none are available, then try again allowing the
-        // current task to be selected.
-        if (mStackSupervisor.isFrontStack(this) && mService.mController != null) {
-            ActivityRecord next = topRunningActivityLocked(null, taskId);
-            if (next == null) {
-                next = topRunningActivityLocked(null, 0);
-            }
-            if (next != null) {
-                // ask watcher if this is allowed
-                boolean moveOK = true;
-                try {
-                    moveOK = mService.mController.activityResuming(next.packageName);
-                } catch (RemoteException e) {
-                    mService.mController = null;
-                    Watchdog.getInstance().setActivityController(null);
-                }
-                if (!moveOK) {
-                    return false;
-                }
-            }
-        }
-
-        if (DEBUG_TRANSITION) Slog.v(TAG,
-                "Prepare to back transition: task=" + taskId);
-
-        final TaskRecord tr = taskForIdLocked(taskId);
-        if (tr == null) {
-            return false;
-        }
-
-        mTaskHistory.remove(tr);
-        mTaskHistory.add(0, tr);
-
-        // There is an assumption that moving a task to the back moves it behind the home activity.
-        // We make sure here that some activity in the stack will launch home.
-        ActivityRecord lastActivity = null;
-        int numTasks = mTaskHistory.size();
-        for (int taskNdx = numTasks - 1; taskNdx >= 1; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            if (task.mOnTopOfHome) {
-                break;
-            }
-            if (taskNdx == 1) {
-                // Set the last task before tr to go to home.
-                task.mOnTopOfHome = true;
-            }
-        }
-
-        if (reason != null &&
-                (reason.intent.getFlags() & Intent.FLAG_ACTIVITY_NO_ANIMATION) != 0) {
-            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
-            ActivityRecord r = topRunningActivityLocked(null);
-            if (r != null) {
-                mNoAnimActivities.add(r);
-            }
-        } else {
-            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_TASK_TO_BACK, false);
-        }
-        mWindowManager.moveTaskToBottom(taskId);
-
-        if (VALIDATE_TOKENS) {
-            validateAppTokensLocked();
-        }
-
-        final TaskRecord task = mResumedActivity != null ? mResumedActivity.task : null;
-        if (task == tr && task.mOnTopOfHome || numTasks <= 1) {
-            if (task != null) {
-                task.mOnTopOfHome = false;
-            }
-            return mStackSupervisor.resumeHomeActivity(null);
-        }
-
-        mStackSupervisor.resumeTopActivitiesLocked();
-        return true;
-    }
-
-    static final void logStartActivity(int tag, ActivityRecord r,
-            TaskRecord task) {
-        final Uri data = r.intent.getData();
-        final String strData = data != null ? data.toSafeString() : null;
-
-        EventLog.writeEvent(tag,
-                r.userId, System.identityHashCode(r), task.taskId,
-                r.shortComponentName, r.intent.getAction(),
-                r.intent.getType(), strData, r.intent.getFlags());
-    }
-
-    /**
-     * Make sure the given activity matches the current configuration.  Returns
-     * false if the activity had to be destroyed.  Returns true if the
-     * configuration is the same, or the activity will remain running as-is
-     * for whatever reason.  Ensures the HistoryRecord is updated with the
-     * correct configuration and all other bookkeeping is handled.
-     */
-    final boolean ensureActivityConfigurationLocked(ActivityRecord r,
-            int globalChanges) {
-        if (mConfigWillChange) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                    "Skipping config check (will change): " + r);
-            return true;
-        }
-
-        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                "Ensuring correct configuration: " + r);
-
-        // Short circuit: if the two configurations are the exact same
-        // object (the common case), then there is nothing to do.
-        Configuration newConfig = mService.mConfiguration;
-        if (r.configuration == newConfig && !r.forceNewConfig) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                    "Configuration unchanged in " + r);
-            return true;
-        }
-
-        // We don't worry about activities that are finishing.
-        if (r.finishing) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                    "Configuration doesn't matter in finishing " + r);
-            r.stopFreezingScreenLocked(false);
-            return true;
-        }
-
-        // Okay we now are going to make this activity have the new config.
-        // But then we need to figure out how it needs to deal with that.
-        Configuration oldConfig = r.configuration;
-        r.configuration = newConfig;
-
-        // Determine what has changed.  May be nothing, if this is a config
-        // that has come back from the app after going idle.  In that case
-        // we just want to leave the official config object now in the
-        // activity and do nothing else.
-        final int changes = oldConfig.diff(newConfig);
-        if (changes == 0 && !r.forceNewConfig) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                    "Configuration no differences in " + r);
-            return true;
-        }
-
-        // If the activity isn't currently running, just leave the new
-        // configuration and it will pick that up next time it starts.
-        if (r.app == null || r.app.thread == null) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                    "Configuration doesn't matter not running " + r);
-            r.stopFreezingScreenLocked(false);
-            r.forceNewConfig = false;
-            return true;
-        }
-
-        // Figure out how to handle the changes between the configurations.
-        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) {
-            Slog.v(TAG, "Checking to restart " + r.info.name + ": changed=0x"
-                    + Integer.toHexString(changes) + ", handles=0x"
-                    + Integer.toHexString(r.info.getRealConfigChanged())
-                    + ", newConfig=" + newConfig);
-        }
-        if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) {
-            // Aha, the activity isn't handling the change, so DIE DIE DIE.
-            r.configChangeFlags |= changes;
-            r.startFreezingScreenLocked(r.app, globalChanges);
-            r.forceNewConfig = false;
-            if (r.app == null || r.app.thread == null) {
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                        "Config is destroying non-running " + r);
-                destroyActivityLocked(r, true, false, "config");
-            } else if (r.state == ActivityState.PAUSING) {
-                // A little annoying: we are waiting for this activity to
-                // finish pausing.  Let's not do anything now, but just
-                // flag that it needs to be restarted when done pausing.
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                        "Config is skipping already pausing " + r);
-                r.configDestroy = true;
-                return true;
-            } else if (r.state == ActivityState.RESUMED) {
-                // Try to optimize this case: the configuration is changing
-                // and we need to restart the top, resumed activity.
-                // Instead of doing the normal handshaking, just say
-                // "restart!".
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                        "Config is relaunching resumed " + r);
-                relaunchActivityLocked(r, r.configChangeFlags, true);
-                r.configChangeFlags = 0;
-            } else {
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG,
-                        "Config is relaunching non-resumed " + r);
-                relaunchActivityLocked(r, r.configChangeFlags, false);
-                r.configChangeFlags = 0;
-            }
-
-            // All done...  tell the caller we weren't able to keep this
-            // activity around.
-            return false;
-        }
-
-        // Default case: the activity can handle this new configuration, so
-        // hand it over.  Note that we don't need to give it the new
-        // configuration, since we always send configuration changes to all
-        // process when they happen so it can just use whatever configuration
-        // it last got.
-        if (r.app != null && r.app.thread != null) {
-            try {
-                if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + r);
-                r.app.thread.scheduleActivityConfigurationChanged(r.appToken);
-            } catch (RemoteException e) {
-                // If process died, whatever.
-            }
-        }
-        r.stopFreezingScreenLocked(false);
-
-        return true;
-    }
-
-    private boolean relaunchActivityLocked(ActivityRecord r,
-            int changes, boolean andResume) {
-        List<ResultInfo> results = null;
-        List<Intent> newIntents = null;
-        if (andResume) {
-            results = r.results;
-            newIntents = r.newIntents;
-        }
-        if (DEBUG_SWITCH) Slog.v(TAG, "Relaunching: " + r
-                + " with results=" + results + " newIntents=" + newIntents
-                + " andResume=" + andResume);
-        EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
-                : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r),
-                r.task.taskId, r.shortComponentName);
-
-        r.startFreezingScreenLocked(r.app, 0);
-
-        try {
-            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG,
-                    (andResume ? "Relaunching to RESUMED " : "Relaunching to PAUSED ")
-                    + r);
-            r.forceNewConfig = false;
-            r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents,
-                    changes, !andResume, new Configuration(mService.mConfiguration));
-            // 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.
-        } catch (RemoteException e) {
-            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG, "Relaunch failed", e);
-        }
-
-        if (andResume) {
-            r.results = null;
-            r.newIntents = null;
-            r.state = ActivityState.RESUMED;
-        } else {
-            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
-            r.state = ActivityState.PAUSED;
-        }
-
-        return true;
-    }
-
-    boolean willActivityBeVisibleLocked(IBinder token) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.appToken == token) {
-                        return true;
-                }
-                if (r.fullscreen && !r.finishing) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
-
-    void closeSystemDialogsLocked() {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if ((r.info.flags&ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS) != 0) {
-                    finishActivityLocked(r, Activity.RESULT_CANCELED, null, "close-sys", true);
-                }
-            }
-        }
-    }
-
-    boolean forceStopPackageLocked(String name, boolean doit, boolean evenPersistent, int userId) {
-        boolean didSomething = false;
-        TaskRecord lastTask = null;
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            int numActivities = activities.size();
-            for (int activityNdx = 0; activityNdx < numActivities; ++activityNdx) {
-                ActivityRecord r = activities.get(activityNdx);
-                final boolean samePackage = r.packageName.equals(name)
-                        || (name == null && r.userId == userId);
-                if ((userId == UserHandle.USER_ALL || r.userId == userId)
-                        && (samePackage || r.task == lastTask)
-                        && (r.app == null || evenPersistent || !r.app.persistent)) {
-                    if (!doit) {
-                        if (r.finishing) {
-                            // If this activity is just finishing, then it is not
-                            // interesting as far as something to stop.
-                            continue;
-                        }
-                        return true;
-                    }
-                    didSomething = true;
-                    Slog.i(TAG, "  Force finishing activity " + r);
-                    if (samePackage) {
-                        if (r.app != null) {
-                            r.app.removed = true;
-                        }
-                        r.app = null;
-                    }
-                    lastTask = r.task;
-                    if (finishActivityLocked(r, Activity.RESULT_CANCELED, null, "force-stop",
-                            true)) {
-                        // r has been deleted from mActivities, accommodate.
-                        --numActivities;
-                        --activityNdx;
-                    }
-                }
-            }
-        }
-        return didSomething;
-    }
-
-    ActivityRecord getTasksLocked(IThumbnailReceiver receiver,
-            PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
-        ActivityRecord topRecord = null;
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            ActivityRecord r = null;
-            ActivityRecord top = null;
-            int numActivities = 0;
-            int numRunning = 0;
-            final ArrayList<ActivityRecord> activities = task.mActivities;
-            if (activities.isEmpty()) {
-                continue;
-            }
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                r = activities.get(activityNdx);
-
-                // Initialize state for next task if needed.
-                if (top == null || (top.state == ActivityState.INITIALIZING)) {
-                    top = r;
-                    numActivities = numRunning = 0;
-                }
-
-                // Add 'r' into the current task.
-                numActivities++;
-                if (r.app != null && r.app.thread != null) {
-                    numRunning++;
-                }
-
-                if (localLOGV) Slog.v(
-                    TAG, r.intent.getComponent().flattenToShortString()
-                    + ": task=" + r.task);
-            }
-
-            RunningTaskInfo ci = new RunningTaskInfo();
-            ci.id = task.taskId;
-            ci.baseActivity = r.intent.getComponent();
-            ci.topActivity = top.intent.getComponent();
-            ci.lastActiveTime = task.lastActiveTime;
-
-            if (top.thumbHolder != null) {
-                ci.description = top.thumbHolder.lastDescription;
-            }
-            ci.numActivities = numActivities;
-            ci.numRunning = numRunning;
-            //System.out.println(
-            //    "#" + maxNum + ": " + " descr=" + ci.description);
-            if (receiver != null) {
-                if (localLOGV) Slog.v(
-                    TAG, "State=" + top.state + "Idle=" + top.idle
-                    + " app=" + top.app
-                    + " thr=" + (top.app != null ? top.app.thread : null));
-                if (top.state == ActivityState.RESUMED || top.state == ActivityState.PAUSING) {
-                    if (top.idle && top.app != null && top.app.thread != null) {
-                        topRecord = top;
-                    } else {
-                        top.thumbnailNeeded = true;
-                    }
-                }
-                pending.pendingRecords.add(top);
-            }
-            list.add(ci);
-        }
-        return topRecord;
-    }
-
-    public void unhandledBackLocked() {
-        final int top = mTaskHistory.size() - 1;
-        if (DEBUG_SWITCH) Slog.d(
-            TAG, "Performing unhandledBack(): top activity at " + top);
-        if (top >= 0) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(top).mActivities;
-            int activityTop = activities.size() - 1;
-            if (activityTop > 0) {
-                finishActivityLocked(activities.get(activityTop), Activity.RESULT_CANCELED, null,
-                        "unhandled-back", true);
-            }
-        }
-    }
-
-    /**
-     * Reset local parameters because an app's activity died.
-     * @param app The app of the activity that died.
-     * @return result from removeHistoryRecordsForAppLocked.
-     */
-    boolean handleAppDiedLocked(ProcessRecord app) {
-        if (mPausingActivity != null && mPausingActivity.app == app) {
-            if (DEBUG_PAUSE || DEBUG_CLEANUP) Slog.v(TAG,
-                    "App died while pausing: " + mPausingActivity);
-            mPausingActivity = null;
-        }
-        if (mLastPausedActivity != null && mLastPausedActivity.app == app) {
-            mLastPausedActivity = null;
-            mLastNoHistoryActivity = null;
-        }
-
-        return removeHistoryRecordsForAppLocked(app);
-    }
-
-    void handleAppCrashLocked(ProcessRecord app) {
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord r = activities.get(activityNdx);
-                if (r.app == app) {
-                    Slog.w(TAG, "  Force finishing activity "
-                            + r.intent.getComponent().flattenToShortString());
-                    finishActivityLocked(r, Activity.RESULT_CANCELED, null, "crashed", false);
-                }
-            }
-        }
-    }
-
-    boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll,
-            boolean dumpClient, String dumpPackage, boolean needSep, String header) {
-        boolean printed = false;
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final TaskRecord task = mTaskHistory.get(taskNdx);
-            printed |= ActivityStackSupervisor.dumpHistoryList(fd, pw,
-                    mTaskHistory.get(taskNdx).mActivities, "    ", "Hist", true, !dumpAll,
-                    dumpClient, dumpPackage, needSep, header,
-                    "    Task id #" + task.taskId);
-            if (printed) {
-                header = null;
-            }
-        }
-        return printed;
-    }
-
-    ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) {
-        ArrayList<ActivityRecord> activities = new ArrayList<ActivityRecord>();
-
-        if ("all".equals(name)) {
-            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-                activities.addAll(mTaskHistory.get(taskNdx).mActivities);
-            }
-        } else if ("top".equals(name)) {
-            final int top = mTaskHistory.size() - 1;
-            if (top >= 0) {
-                final ArrayList<ActivityRecord> list = mTaskHistory.get(top).mActivities;
-                int listTop = list.size() - 1;
-                if (listTop >= 0) {
-                    activities.add(list.get(listTop));
-                }
-            }
-        } else {
-            ItemMatcher matcher = new ItemMatcher();
-            matcher.build(name);
-
-            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-                for (ActivityRecord r1 : mTaskHistory.get(taskNdx).mActivities) {
-                    if (matcher.match(r1, r1.intent.getComponent())) {
-                        activities.add(r1);
-                    }
-                }
-            }
-        }
-
-        return activities;
-    }
-
-    ActivityRecord restartPackage(String packageName) {
-        ActivityRecord starting = topRunningActivityLocked(null);
-
-        // All activities that came from the package must be
-        // restarted as if there was a config change.
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ActivityRecord a = activities.get(activityNdx);
-                if (a.info.packageName.equals(packageName)) {
-                    a.forceNewConfig = true;
-                    if (starting != null && a == starting && a.visible) {
-                        a.startFreezingScreenLocked(starting.app,
-                                ActivityInfo.CONFIG_SCREEN_LAYOUT);
-                    }
-                }
-            }
-        }
-
-        return starting;
-    }
-
-    boolean removeTask(TaskRecord task) {
-        final int taskNdx = mTaskHistory.indexOf(task);
-        final int topTaskNdx = mTaskHistory.size() - 1;
-        if (task.mOnTopOfHome && taskNdx < topTaskNdx) {
-            mTaskHistory.get(taskNdx + 1).mOnTopOfHome = true;
-        }
-        mTaskHistory.remove(task);
-        return mTaskHistory.isEmpty();
-    }
-
-    TaskRecord createTaskRecord(int taskId, ActivityInfo info, Intent intent, boolean toTop) {
-        TaskRecord task = new TaskRecord(taskId, info, intent);
-        addTask(task, toTop);
-        return task;
-    }
-
-    ArrayList<TaskRecord> getAllTasks() {
-        return new ArrayList<TaskRecord>(mTaskHistory);
-    }
-
-    void addTask(final TaskRecord task, final boolean toTop) {
-        task.stack = this;
-        if (toTop) {
-            insertTaskAtTop(task);
-        } else {
-            mTaskHistory.add(0, task);
-        }
-    }
-
-    public int getStackId() {
-        return mStackId;
-    }
-
-    @Override
-    public String toString() {
-        return "ActivityStack{" + Integer.toHexString(System.identityHashCode(this))
-                + " stackId=" + mStackId + ", " + mTaskHistory.size() + " tasks}";
-    }
-}
diff --git a/services/java/com/android/server/am/ActivityStackSupervisor.java b/services/java/com/android/server/am/ActivityStackSupervisor.java
deleted file mode 100644
index 62e1340..0000000
--- a/services/java/com/android/server/am/ActivityStackSupervisor.java
+++ /dev/null
@@ -1,2663 +0,0 @@
-/*
- * Copyright (C) 2013 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 static android.Manifest.permission.START_ANY_ACTIVITY;
-import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
-import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
-import static android.content.pm.PackageManager.PERMISSION_GRANTED;
-import static com.android.server.am.ActivityManagerService.localLOGV;
-import static com.android.server.am.ActivityManagerService.DEBUG_CONFIGURATION;
-import static com.android.server.am.ActivityManagerService.DEBUG_FOCUS;
-import static com.android.server.am.ActivityManagerService.DEBUG_PAUSE;
-import static com.android.server.am.ActivityManagerService.DEBUG_RESULTS;
-import static com.android.server.am.ActivityManagerService.DEBUG_STACK;
-import static com.android.server.am.ActivityManagerService.DEBUG_SWITCH;
-import static com.android.server.am.ActivityManagerService.DEBUG_TASKS;
-import static com.android.server.am.ActivityManagerService.DEBUG_USER_LEAVING;
-import static com.android.server.am.ActivityManagerService.FIRST_SUPERVISOR_STACK_MSG;
-import static com.android.server.am.ActivityManagerService.TAG;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.ActivityOptions;
-import android.app.AppGlobals;
-import android.app.IActivityManager;
-import android.app.IApplicationThread;
-import android.app.IThumbnailReceiver;
-import android.app.PendingIntent;
-import android.app.ActivityManager.RunningTaskInfo;
-import android.app.IActivityManager.WaitResult;
-import android.app.ResultInfo;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.IIntentSender;
-import android.content.Intent;
-import android.content.IntentSender;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Configuration;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Debug;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.ParcelFileDescriptor;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.util.EventLog;
-import android.util.Slog;
-import android.util.SparseIntArray;
-
-import com.android.internal.app.HeavyWeightSwitcherActivity;
-import com.android.internal.os.TransferPipe;
-import com.android.server.am.ActivityManagerService.PendingActivityLaunch;
-import com.android.server.am.ActivityStack.ActivityState;
-import com.android.server.wm.StackBox;
-import com.android.server.wm.WindowManagerService;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-public final class ActivityStackSupervisor {
-    static final boolean DEBUG = ActivityManagerService.DEBUG || false;
-    static final boolean DEBUG_ADD_REMOVE = DEBUG || false;
-    static final boolean DEBUG_APP = DEBUG || false;
-    static final boolean DEBUG_SAVED_STATE = DEBUG || false;
-    static final boolean DEBUG_STATES = DEBUG || false;
-    static final boolean DEBUG_IDLE = DEBUG || false;
-
-    public static final int HOME_STACK_ID = 0;
-
-    /** How long we wait until giving up on the last activity telling us it is idle. */
-    static final int IDLE_TIMEOUT = 10*1000;
-
-    /** How long we can hold the sleep wake lock before giving up. */
-    static final int SLEEP_TIMEOUT = 5*1000;
-
-    // How long we can hold the launch wake lock before giving up.
-    static final int LAUNCH_TIMEOUT = 10*1000;
-
-    static final int IDLE_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG;
-    static final int IDLE_NOW_MSG = FIRST_SUPERVISOR_STACK_MSG + 1;
-    static final int RESUME_TOP_ACTIVITY_MSG = FIRST_SUPERVISOR_STACK_MSG + 2;
-    static final int SLEEP_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 3;
-    static final int LAUNCH_TIMEOUT_MSG = FIRST_SUPERVISOR_STACK_MSG + 4;
-
-    // For debugging to make sure the caller when acquiring/releasing our
-    // wake lock is the system process.
-    static final boolean VALIDATE_WAKE_LOCK_CALLER = false;
-
-    final ActivityManagerService mService;
-    final Context mContext;
-    final Looper mLooper;
-
-    final ActivityStackSupervisorHandler mHandler;
-
-    /** Short cut */
-    WindowManagerService mWindowManager;
-
-    /** Dismiss the keyguard after the next activity is displayed? */
-    boolean mDismissKeyguardOnNextActivity = false;
-
-    /** Identifier counter for all ActivityStacks */
-    private int mLastStackId = HOME_STACK_ID;
-
-    /** Task identifier that activities are currently being started in.  Incremented each time a
-     * new task is created. */
-    private int mCurTaskId = 0;
-
-    /** The current user */
-    private int mCurrentUser;
-
-    /** The stack containing the launcher app */
-    private ActivityStack mHomeStack;
-
-    /** The non-home stack currently receiving input or launching the next activity. If home is
-     * in front then mHomeStack overrides mFocusedStack.
-     * DO NOT ACCESS DIRECTLY - It may be null, use getFocusedStack() */
-    private ActivityStack mFocusedStack;
-
-    /** All the non-launcher stacks */
-    private ArrayList<ActivityStack> mStacks = new ArrayList<ActivityStack>();
-
-    private static final int STACK_STATE_HOME_IN_FRONT = 0;
-    private static final int STACK_STATE_HOME_TO_BACK = 1;
-    private static final int STACK_STATE_HOME_IN_BACK = 2;
-    private static final int STACK_STATE_HOME_TO_FRONT = 3;
-    private int mStackState = STACK_STATE_HOME_IN_FRONT;
-
-    /** List of activities that are waiting for a new activity to become visible before completing
-     * whatever operation they are supposed to do. */
-    final ArrayList<ActivityRecord> mWaitingVisibleActivities = new ArrayList<ActivityRecord>();
-
-    /** List of processes waiting to find out about the next visible activity. */
-    final ArrayList<IActivityManager.WaitResult> mWaitingActivityVisible =
-            new ArrayList<IActivityManager.WaitResult>();
-
-    /** List of processes waiting to find out about the next launched activity. */
-    final ArrayList<IActivityManager.WaitResult> mWaitingActivityLaunched =
-            new ArrayList<IActivityManager.WaitResult>();
-
-    /** List of activities that are ready to be stopped, but waiting for the next activity to
-     * settle down before doing so. */
-    final ArrayList<ActivityRecord> mStoppingActivities = new ArrayList<ActivityRecord>();
-
-    /** List of activities that are ready to be finished, but waiting for the previous activity to
-     * settle down before doing so.  It contains ActivityRecord objects. */
-    final ArrayList<ActivityRecord> mFinishingActivities = new ArrayList<ActivityRecord>();
-
-    /** List of activities that are in the process of going to sleep. */
-    final ArrayList<ActivityRecord> mGoingToSleepActivities = new ArrayList<ActivityRecord>();
-
-    /** List of ActivityRecord objects that have been finished and must still report back to a
-     * pending thumbnail receiver. */
-    final ArrayList<ActivityRecord> mCancelledThumbnails = new ArrayList<ActivityRecord>();
-
-    /** Used on user changes */
-    final ArrayList<UserStartedState> mStartingUsers = new ArrayList<UserStartedState>();
-
-    /** Set to indicate whether to issue an onUserLeaving callback when a newly launched activity
-     * is being brought in front of us. */
-    boolean mUserLeaving = false;
-
-    /** Set when we have taken too long waiting to go to sleep. */
-    boolean mSleepTimeout = false;
-
-    /**
-     * We don't want to allow the device to go to sleep while in the process
-     * of launching an activity.  This is primarily to allow alarm intent
-     * receivers to launch an activity and get that to run before the device
-     * goes back to sleep.
-     */
-    final PowerManager.WakeLock mLaunchingActivity;
-
-    /**
-     * Set when the system is going to sleep, until we have
-     * successfully paused the current activity and released our wake lock.
-     * At that point the system is allowed to actually sleep.
-     */
-    final PowerManager.WakeLock mGoingToSleep;
-
-    /** Stack id of the front stack when user switched, indexed by userId. */
-    SparseIntArray mUserStackInFront = new SparseIntArray(2);
-
-    public ActivityStackSupervisor(ActivityManagerService service, Context context,
-            Looper looper) {
-        mService = service;
-        mContext = context;
-        mLooper = looper;
-        PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
-        mGoingToSleep = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Sleep");
-        mHandler = new ActivityStackSupervisorHandler(looper);
-        if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
-            throw new IllegalStateException("Calling must be system uid");
-        }
-        mLaunchingActivity =
-                pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityManager-Launch");
-        mLaunchingActivity.setReferenceCounted(false);
-    }
-
-    void setWindowManager(WindowManagerService wm) {
-        mWindowManager = wm;
-        mHomeStack = new ActivityStack(mService, mContext, mLooper, HOME_STACK_ID);
-        mStacks.add(mHomeStack);
-    }
-
-    void dismissKeyguard() {
-        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen("");
-        if (mDismissKeyguardOnNextActivity) {
-            mDismissKeyguardOnNextActivity = false;
-            mWindowManager.dismissKeyguard();
-        }
-    }
-
-    ActivityStack getFocusedStack() {
-        if (mFocusedStack == null) {
-            return mHomeStack;
-        }
-        switch (mStackState) {
-            case STACK_STATE_HOME_IN_FRONT:
-            case STACK_STATE_HOME_TO_FRONT:
-                return mHomeStack;
-            case STACK_STATE_HOME_IN_BACK:
-            case STACK_STATE_HOME_TO_BACK:
-            default:
-                return mFocusedStack;
-        }
-    }
-
-    ActivityStack getLastStack() {
-        switch (mStackState) {
-            case STACK_STATE_HOME_IN_FRONT:
-            case STACK_STATE_HOME_TO_BACK:
-                return mHomeStack;
-            case STACK_STATE_HOME_TO_FRONT:
-            case STACK_STATE_HOME_IN_BACK:
-            default:
-                return mFocusedStack;
-        }
-    }
-
-    boolean isFrontStack(ActivityStack stack) {
-        return !(stack.isHomeStack() ^ getFocusedStack().isHomeStack());
-    }
-
-    void moveHomeStack(boolean toFront) {
-        final boolean homeInFront = isFrontStack(mHomeStack);
-        if (homeInFront ^ toFront) {
-            if (DEBUG_STACK) Slog.d(TAG, "moveHomeTask: mStackState old=" +
-                    stackStateToString(mStackState) + " new=" + stackStateToString(homeInFront ?
-                    STACK_STATE_HOME_TO_BACK : STACK_STATE_HOME_TO_FRONT));
-            mStackState = homeInFront ? STACK_STATE_HOME_TO_BACK : STACK_STATE_HOME_TO_FRONT;
-        }
-    }
-
-    void moveHomeToTop() {
-        moveHomeStack(true);
-        mHomeStack.moveHomeTaskToTop();
-    }
-
-    boolean resumeHomeActivity(ActivityRecord prev) {
-        moveHomeToTop();
-        if (prev != null) {
-            prev.task.mOnTopOfHome = false;
-        }
-        ActivityRecord r = mHomeStack.topRunningActivityLocked(null);
-        if (r != null && r.isHomeActivity()) {
-            mService.setFocusedActivityLocked(r);
-            return resumeTopActivitiesLocked(mHomeStack, prev, null);
-        }
-        return mService.startHomeActivityLocked(mCurrentUser);
-    }
-
-    void setDismissKeyguard(boolean dismiss) {
-        if (ActivityManagerService.DEBUG_LOCKSCREEN) mService.logLockScreen(" dismiss=" + dismiss);
-        mDismissKeyguardOnNextActivity = dismiss;
-    }
-
-    TaskRecord anyTaskForIdLocked(int id) {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            ActivityStack stack = mStacks.get(stackNdx);
-            TaskRecord task = stack.taskForIdLocked(id);
-            if (task != null) {
-                return task;
-            }
-        }
-        return null;
-    }
-
-    ActivityRecord isInAnyStackLocked(IBinder token) {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityRecord r = mStacks.get(stackNdx).isInStackLocked(token);
-            if (r != null) {
-                return r;
-            }
-        }
-        return null;
-    }
-
-    int getNextTaskId() {
-        do {
-            mCurTaskId++;
-            if (mCurTaskId <= 0) {
-                mCurTaskId = 1;
-            }
-        } while (anyTaskForIdLocked(mCurTaskId) != null);
-        return mCurTaskId;
-    }
-
-    void removeTask(TaskRecord task) {
-        mWindowManager.removeTask(task.taskId);
-        final ActivityStack stack = task.stack;
-        final ActivityRecord r = stack.mResumedActivity;
-        if (r != null && r.task == task) {
-            stack.mResumedActivity = null;
-        }
-        if (stack.removeTask(task) && !stack.isHomeStack()) {
-            if (DEBUG_STACK) Slog.i(TAG, "removeTask: removing stack " + stack);
-            mStacks.remove(stack);
-            final int stackId = stack.mStackId;
-            final int nextStackId = mWindowManager.removeStack(stackId);
-            // TODO: Perhaps we need to let the ActivityManager determine the next focus...
-            if (mFocusedStack == null || mFocusedStack.mStackId == stackId) {
-                // If this is the last app stack, set mFocusedStack to null.
-                mFocusedStack = nextStackId == HOME_STACK_ID ? null : getStack(nextStackId);
-            }
-        }
-    }
-
-    ActivityRecord resumedAppLocked() {
-        ActivityStack stack = getFocusedStack();
-        if (stack == null) {
-            return null;
-        }
-        ActivityRecord resumedActivity = stack.mResumedActivity;
-        if (resumedActivity == null || resumedActivity.app == null) {
-            resumedActivity = stack.mPausingActivity;
-            if (resumedActivity == null || resumedActivity.app == null) {
-                resumedActivity = stack.topRunningActivityLocked(null);
-            }
-        }
-        return resumedActivity;
-    }
-
-    boolean attachApplicationLocked(ProcessRecord app, boolean headless) throws Exception {
-        boolean didSomething = false;
-        final String processName = app.processName;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (!isFrontStack(stack)) {
-                continue;
-            }
-            ActivityRecord hr = stack.topRunningActivityLocked(null);
-            if (hr != null) {
-                if (hr.app == null && app.uid == hr.info.applicationInfo.uid
-                        && processName.equals(hr.processName)) {
-                    try {
-                        if (headless) {
-                            Slog.e(TAG, "Starting activities not supported on headless device: "
-                                    + hr);
-                        } else if (realStartActivityLocked(hr, app, true, true)) {
-                            didSomething = true;
-                        }
-                    } catch (Exception e) {
-                        Slog.w(TAG, "Exception in new application when starting activity "
-                              + hr.intent.getComponent().flattenToShortString(), e);
-                        throw e;
-                    }
-                }
-            }
-        }
-        if (!didSomething) {
-            ensureActivitiesVisibleLocked(null, 0);
-        }
-        return didSomething;
-    }
-
-    boolean allResumedActivitiesIdle() {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (!isFrontStack(stack)) {
-                continue;
-            }
-            final ActivityRecord resumedActivity = stack.mResumedActivity;
-            if (resumedActivity == null || !resumedActivity.idle) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    boolean allResumedActivitiesComplete() {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (isFrontStack(stack)) {
-                final ActivityRecord r = stack.mResumedActivity;
-                if (r != null && r.state != ActivityState.RESUMED) {
-                    return false;
-                }
-            }
-        }
-        // TODO: Not sure if this should check if all Paused are complete too.
-        switch (mStackState) {
-            case STACK_STATE_HOME_TO_BACK:
-                if (DEBUG_STACK) Slog.d(TAG, "allResumedActivitiesComplete: mStackState old=" +
-                        stackStateToString(STACK_STATE_HOME_TO_BACK) + " new=" +
-                        stackStateToString(STACK_STATE_HOME_IN_BACK));
-                mStackState = STACK_STATE_HOME_IN_BACK;
-                break;
-            case STACK_STATE_HOME_TO_FRONT:
-                if (DEBUG_STACK) Slog.d(TAG, "allResumedActivitiesComplete: mStackState old=" +
-                        stackStateToString(STACK_STATE_HOME_TO_FRONT) + " new=" +
-                        stackStateToString(STACK_STATE_HOME_IN_FRONT));
-                mStackState = STACK_STATE_HOME_IN_FRONT;
-                break;
-        }
-        return true;
-    }
-
-    boolean allResumedActivitiesVisible() {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            final ActivityRecord r = stack.mResumedActivity;
-            if (r != null && (!r.nowVisible || r.waitingVisible)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Pause all activities in either all of the stacks or just the back stacks.
-     * @param userLeaving Passed to pauseActivity() to indicate whether to call onUserLeaving().
-     * @return true if any activity was paused as a result of this call.
-     */
-    boolean pauseBackStacks(boolean userLeaving) {
-        boolean someActivityPaused = false;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (!isFrontStack(stack) && stack.mResumedActivity != null) {
-                if (DEBUG_STATES) Slog.d(TAG, "pauseBackStacks: stack=" + stack +
-                        " mResumedActivity=" + stack.mResumedActivity);
-                stack.startPausingLocked(userLeaving, false);
-                someActivityPaused = true;
-            }
-        }
-        return someActivityPaused;
-    }
-
-    boolean allPausedActivitiesComplete() {
-        boolean pausing = true;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            final ActivityRecord r = stack.mPausingActivity;
-            if (r != null && r.state != ActivityState.PAUSED
-                    && r.state != ActivityState.STOPPED
-                    && r.state != ActivityState.STOPPING) {
-                if (DEBUG_STATES) {
-                    Slog.d(TAG, "allPausedActivitiesComplete: r=" + r + " state=" + r.state);
-                    pausing = false;
-                } else {
-                    return false;
-                }
-            }
-        }
-        return pausing;
-    }
-
-    void reportActivityVisibleLocked(ActivityRecord r) {
-        for (int i = mWaitingActivityVisible.size()-1; i >= 0; i--) {
-            WaitResult w = mWaitingActivityVisible.get(i);
-            w.timeout = false;
-            if (r != null) {
-                w.who = new ComponentName(r.info.packageName, r.info.name);
-            }
-            w.totalTime = SystemClock.uptimeMillis() - w.thisTime;
-            w.thisTime = w.totalTime;
-        }
-        mService.notifyAll();
-        dismissKeyguard();
-    }
-
-    void reportActivityLaunchedLocked(boolean timeout, ActivityRecord r,
-            long thisTime, long totalTime) {
-        for (int i = mWaitingActivityLaunched.size() - 1; i >= 0; i--) {
-            WaitResult w = mWaitingActivityLaunched.remove(i);
-            w.timeout = timeout;
-            if (r != null) {
-                w.who = new ComponentName(r.info.packageName, r.info.name);
-            }
-            w.thisTime = thisTime;
-            w.totalTime = totalTime;
-        }
-        mService.notifyAll();
-    }
-
-    ActivityRecord topRunningActivityLocked() {
-        final ActivityStack focusedStack = getFocusedStack();
-        ActivityRecord r = focusedStack.topRunningActivityLocked(null);
-        if (r != null) {
-            return r;
-        }
-
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (stack != focusedStack && isFrontStack(stack)) {
-                r = stack.topRunningActivityLocked(null);
-                if (r != null) {
-                    return r;
-                }
-            }
-        }
-        return null;
-    }
-
-    ActivityRecord getTasksLocked(int maxNum, IThumbnailReceiver receiver,
-            PendingThumbnailsRecord pending, List<RunningTaskInfo> list) {
-        ActivityRecord r = null;
-
-        // Gather all of the running tasks for each stack into runningTaskLists.
-        final int numStacks = mStacks.size();
-        ArrayList<RunningTaskInfo>[] runningTaskLists = new ArrayList[numStacks];
-        for (int stackNdx = numStacks - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            ArrayList<RunningTaskInfo> stackTaskList = new ArrayList<RunningTaskInfo>();
-            runningTaskLists[stackNdx] = stackTaskList;
-            final ActivityRecord ar = stack.getTasksLocked(receiver, pending, stackTaskList);
-            if (isFrontStack(stack)) {
-                r = ar;
-            }
-        }
-
-        // The lists are already sorted from most recent to oldest. Just pull the most recent off
-        // each list and add it to list. Stop when all lists are empty or maxNum reached.
-        while (maxNum > 0) {
-            long mostRecentActiveTime = Long.MIN_VALUE;
-            ArrayList<RunningTaskInfo> selectedStackList = null;
-            for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-                ArrayList<RunningTaskInfo> stackTaskList = runningTaskLists[stackNdx];
-                if (!stackTaskList.isEmpty()) {
-                    final long lastActiveTime = stackTaskList.get(0).lastActiveTime;
-                    if (lastActiveTime > mostRecentActiveTime) {
-                        mostRecentActiveTime = lastActiveTime;
-                        selectedStackList = stackTaskList;
-                    }
-                }
-            }
-            if (selectedStackList != null) {
-                list.add(selectedStackList.remove(0));
-                --maxNum;
-            } else {
-                break;
-            }
-        }
-
-        return r;
-    }
-
-    ActivityInfo resolveActivity(Intent intent, String resolvedType, int startFlags,
-            String profileFile, ParcelFileDescriptor profileFd, int userId) {
-        // Collect information about the target of the Intent.
-        ActivityInfo aInfo;
-        try {
-            ResolveInfo rInfo =
-                AppGlobals.getPackageManager().resolveIntent(
-                        intent, resolvedType,
-                        PackageManager.MATCH_DEFAULT_ONLY
-                                    | ActivityManagerService.STOCK_PM_FLAGS, userId);
-            aInfo = rInfo != null ? rInfo.activityInfo : null;
-        } catch (RemoteException e) {
-            aInfo = null;
-        }
-
-        if (aInfo != null) {
-            // Store the found target back into the intent, because now that
-            // we have it we never want to do this again.  For example, if the
-            // user navigates back to this point in the history, we should
-            // always restart the exact same activity.
-            intent.setComponent(new ComponentName(
-                    aInfo.applicationInfo.packageName, aInfo.name));
-
-            // Don't debug things in the system process
-            if ((startFlags&ActivityManager.START_FLAG_DEBUG) != 0) {
-                if (!aInfo.processName.equals("system")) {
-                    mService.setDebugApp(aInfo.processName, true, false);
-                }
-            }
-
-            if ((startFlags&ActivityManager.START_FLAG_OPENGL_TRACES) != 0) {
-                if (!aInfo.processName.equals("system")) {
-                    mService.setOpenGlTraceApp(aInfo.applicationInfo, aInfo.processName);
-                }
-            }
-
-            if (profileFile != null) {
-                if (!aInfo.processName.equals("system")) {
-                    mService.setProfileApp(aInfo.applicationInfo, aInfo.processName,
-                            profileFile, profileFd,
-                            (startFlags&ActivityManager.START_FLAG_AUTO_STOP_PROFILER) != 0);
-                }
-            }
-        }
-        return aInfo;
-    }
-
-    void startHomeActivity(Intent intent, ActivityInfo aInfo) {
-        moveHomeToTop();
-        startActivityLocked(null, intent, null, aInfo, null, null, 0, 0, 0, null, 0,
-                null, false, null);
-    }
-
-    final int startActivityMayWait(IApplicationThread caller, int callingUid,
-            String callingPackage, Intent intent, String resolvedType, IBinder resultTo,
-            String resultWho, int requestCode, int startFlags, String profileFile,
-            ParcelFileDescriptor profileFd, WaitResult outResult, Configuration config,
-            Bundle options, int userId) {
-        // Refuse possible leaked file descriptors
-        if (intent != null && intent.hasFileDescriptors()) {
-            throw new IllegalArgumentException("File descriptors passed in Intent");
-        }
-        boolean componentSpecified = intent.getComponent() != null;
-
-        // Don't modify the client's object!
-        intent = new Intent(intent);
-
-        // Collect information about the target of the Intent.
-        ActivityInfo aInfo = resolveActivity(intent, resolvedType, startFlags,
-                profileFile, profileFd, userId);
-
-        synchronized (mService) {
-            int callingPid;
-            if (callingUid >= 0) {
-                callingPid = -1;
-            } else if (caller == null) {
-                callingPid = Binder.getCallingPid();
-                callingUid = Binder.getCallingUid();
-            } else {
-                callingPid = callingUid = -1;
-            }
-
-            final ActivityStack stack = getFocusedStack();
-            stack.mConfigWillChange = config != null
-                    && mService.mConfiguration.diff(config) != 0;
-            if (DEBUG_CONFIGURATION) Slog.v(TAG,
-                    "Starting activity when config will change = " + stack.mConfigWillChange);
-
-            final long origId = Binder.clearCallingIdentity();
-
-            if (aInfo != null &&
-                    (aInfo.applicationInfo.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
-                // This may be a heavy-weight process!  Check to see if we already
-                // have another, different heavy-weight process running.
-                if (aInfo.processName.equals(aInfo.applicationInfo.packageName)) {
-                    if (mService.mHeavyWeightProcess != null &&
-                            (mService.mHeavyWeightProcess.info.uid != aInfo.applicationInfo.uid ||
-                            !mService.mHeavyWeightProcess.processName.equals(aInfo.processName))) {
-                        int realCallingUid = callingUid;
-                        if (caller != null) {
-                            ProcessRecord callerApp = mService.getRecordForAppLocked(caller);
-                            if (callerApp != null) {
-                                realCallingUid = callerApp.info.uid;
-                            } else {
-                                Slog.w(TAG, "Unable to find app for caller " + caller
-                                      + " (pid=" + callingPid + ") when starting: "
-                                      + intent.toString());
-                                ActivityOptions.abort(options);
-                                return ActivityManager.START_PERMISSION_DENIED;
-                            }
-                        }
-
-                        IIntentSender target = mService.getIntentSenderLocked(
-                                ActivityManager.INTENT_SENDER_ACTIVITY, "android",
-                                realCallingUid, userId, null, null, 0, new Intent[] { intent },
-                                new String[] { resolvedType }, PendingIntent.FLAG_CANCEL_CURRENT
-                                | PendingIntent.FLAG_ONE_SHOT, null);
-
-                        Intent newIntent = new Intent();
-                        if (requestCode >= 0) {
-                            // Caller is requesting a result.
-                            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_HAS_RESULT, true);
-                        }
-                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_INTENT,
-                                new IntentSender(target));
-                        if (mService.mHeavyWeightProcess.activities.size() > 0) {
-                            ActivityRecord hist = mService.mHeavyWeightProcess.activities.get(0);
-                            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_APP,
-                                    hist.packageName);
-                            newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_CUR_TASK,
-                                    hist.task.taskId);
-                        }
-                        newIntent.putExtra(HeavyWeightSwitcherActivity.KEY_NEW_APP,
-                                aInfo.packageName);
-                        newIntent.setFlags(intent.getFlags());
-                        newIntent.setClassName("android",
-                                HeavyWeightSwitcherActivity.class.getName());
-                        intent = newIntent;
-                        resolvedType = null;
-                        caller = null;
-                        callingUid = Binder.getCallingUid();
-                        callingPid = Binder.getCallingPid();
-                        componentSpecified = true;
-                        try {
-                            ResolveInfo rInfo =
-                                AppGlobals.getPackageManager().resolveIntent(
-                                        intent, null,
-                                        PackageManager.MATCH_DEFAULT_ONLY
-                                        | ActivityManagerService.STOCK_PM_FLAGS, userId);
-                            aInfo = rInfo != null ? rInfo.activityInfo : null;
-                            aInfo = mService.getActivityInfoForUser(aInfo, userId);
-                        } catch (RemoteException e) {
-                            aInfo = null;
-                        }
-                    }
-                }
-            }
-
-            int res = startActivityLocked(caller, intent, resolvedType,
-                    aInfo, resultTo, resultWho, requestCode, callingPid, callingUid,
-                    callingPackage, startFlags, options, componentSpecified, null);
-
-            if (stack.mConfigWillChange) {
-                // If the caller also wants to switch to a new configuration,
-                // do so now.  This allows a clean switch, as we are waiting
-                // for the current activity to pause (so we will not destroy
-                // it), and have not yet started the next activity.
-                mService.enforceCallingPermission(android.Manifest.permission.CHANGE_CONFIGURATION,
-                        "updateConfiguration()");
-                stack.mConfigWillChange = false;
-                if (DEBUG_CONFIGURATION) Slog.v(TAG,
-                        "Updating to new configuration after starting activity.");
-                mService.updateConfigurationLocked(config, null, false, false);
-            }
-
-            Binder.restoreCallingIdentity(origId);
-
-            if (outResult != null) {
-                outResult.result = res;
-                if (res == ActivityManager.START_SUCCESS) {
-                    mWaitingActivityLaunched.add(outResult);
-                    do {
-                        try {
-                            mService.wait();
-                        } catch (InterruptedException e) {
-                        }
-                    } while (!outResult.timeout && outResult.who == null);
-                } else if (res == ActivityManager.START_TASK_TO_FRONT) {
-                    ActivityRecord r = stack.topRunningActivityLocked(null);
-                    if (r.nowVisible) {
-                        outResult.timeout = false;
-                        outResult.who = new ComponentName(r.info.packageName, r.info.name);
-                        outResult.totalTime = 0;
-                        outResult.thisTime = 0;
-                    } else {
-                        outResult.thisTime = SystemClock.uptimeMillis();
-                        mWaitingActivityVisible.add(outResult);
-                        do {
-                            try {
-                                mService.wait();
-                            } catch (InterruptedException e) {
-                            }
-                        } while (!outResult.timeout && outResult.who == null);
-                    }
-                }
-            }
-
-            return res;
-        }
-    }
-
-    final int startActivities(IApplicationThread caller, int callingUid, String callingPackage,
-            Intent[] intents, String[] resolvedTypes, IBinder resultTo,
-            Bundle options, int userId) {
-        if (intents == null) {
-            throw new NullPointerException("intents is null");
-        }
-        if (resolvedTypes == null) {
-            throw new NullPointerException("resolvedTypes is null");
-        }
-        if (intents.length != resolvedTypes.length) {
-            throw new IllegalArgumentException("intents are length different than resolvedTypes");
-        }
-
-
-        int callingPid;
-        if (callingUid >= 0) {
-            callingPid = -1;
-        } else if (caller == null) {
-            callingPid = Binder.getCallingPid();
-            callingUid = Binder.getCallingUid();
-        } else {
-            callingPid = callingUid = -1;
-        }
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (mService) {
-                ActivityRecord[] outActivity = new ActivityRecord[1];
-                for (int i=0; i<intents.length; i++) {
-                    Intent intent = intents[i];
-                    if (intent == null) {
-                        continue;
-                    }
-
-                    // Refuse possible leaked file descriptors
-                    if (intent != null && intent.hasFileDescriptors()) {
-                        throw new IllegalArgumentException("File descriptors passed in Intent");
-                    }
-
-                    boolean componentSpecified = intent.getComponent() != null;
-
-                    // Don't modify the client's object!
-                    intent = new Intent(intent);
-
-                    // Collect information about the target of the Intent.
-                    ActivityInfo aInfo = resolveActivity(intent, resolvedTypes[i],
-                            0, null, null, userId);
-                    // TODO: New, check if this is correct
-                    aInfo = mService.getActivityInfoForUser(aInfo, userId);
-
-                    if (aInfo != null &&
-                            (aInfo.applicationInfo.flags & ApplicationInfo.FLAG_CANT_SAVE_STATE)
-                                    != 0) {
-                        throw new IllegalArgumentException(
-                                "FLAG_CANT_SAVE_STATE not supported here");
-                    }
-
-                    Bundle theseOptions;
-                    if (options != null && i == intents.length-1) {
-                        theseOptions = options;
-                    } else {
-                        theseOptions = null;
-                    }
-                    int res = startActivityLocked(caller, intent, resolvedTypes[i],
-                            aInfo, resultTo, null, -1, callingPid, callingUid, callingPackage,
-                            0, theseOptions, componentSpecified, outActivity);
-                    if (res < 0) {
-                        return res;
-                    }
-
-                    resultTo = outActivity[0] != null ? outActivity[0].appToken : null;
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-
-        return ActivityManager.START_SUCCESS;
-    }
-
-    final boolean realStartActivityLocked(ActivityRecord r,
-            ProcessRecord app, boolean andResume, boolean checkConfig)
-            throws RemoteException {
-
-        r.startFreezingScreenLocked(app, 0);
-        if (false) Slog.d(TAG, "realStartActivity: setting app visibility true");
-        mWindowManager.setAppVisibility(r.appToken, true);
-
-        // schedule launch ticks to collect information about slow apps.
-        r.startLaunchTickingLocked();
-
-        // Have the window manager re-evaluate the orientation of
-        // the screen based on the new activity order.  Note that
-        // as a result of this, it can call back into the activity
-        // manager with a new orientation.  We don't care about that,
-        // because the activity is not currently running so we are
-        // just restarting it anyway.
-        if (checkConfig) {
-            Configuration config = mWindowManager.updateOrientationFromAppTokens(
-                    mService.mConfiguration,
-                    r.mayFreezeScreenLocked(app) ? r.appToken : null);
-            mService.updateConfigurationLocked(config, r, false, false);
-        }
-
-        r.app = app;
-        app.waitingToKill = null;
-        r.launchCount++;
-        r.lastLaunchTime = SystemClock.uptimeMillis();
-
-        if (localLOGV) Slog.v(TAG, "Launching: " + r);
-
-        int idx = app.activities.indexOf(r);
-        if (idx < 0) {
-            app.activities.add(r);
-        }
-        mService.updateLruProcessLocked(app, true, null);
-        mService.updateOomAdjLocked();
-
-        final ActivityStack stack = r.task.stack;
-        try {
-            if (app.thread == null) {
-                throw new RemoteException();
-            }
-            List<ResultInfo> results = null;
-            List<Intent> newIntents = null;
-            if (andResume) {
-                results = r.results;
-                newIntents = r.newIntents;
-            }
-            if (DEBUG_SWITCH) Slog.v(TAG, "Launching: " + r
-                    + " icicle=" + r.icicle
-                    + " with results=" + results + " newIntents=" + newIntents
-                    + " andResume=" + andResume);
-            if (andResume) {
-                EventLog.writeEvent(EventLogTags.AM_RESTART_ACTIVITY,
-                        r.userId, System.identityHashCode(r),
-                        r.task.taskId, r.shortComponentName);
-            }
-            if (r.isHomeActivity() && r.isNotResolverActivity()) {
-                // Home process is the root process of the task.
-                mService.mHomeProcess = r.task.mActivities.get(0).app;
-            }
-            mService.ensurePackageDexOpt(r.intent.getComponent().getPackageName());
-            r.sleeping = false;
-            r.forceNewConfig = false;
-            mService.showAskCompatModeDialogLocked(r);
-            r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
-            String profileFile = null;
-            ParcelFileDescriptor profileFd = null;
-            boolean profileAutoStop = false;
-            if (mService.mProfileApp != null && mService.mProfileApp.equals(app.processName)) {
-                if (mService.mProfileProc == null || mService.mProfileProc == app) {
-                    mService.mProfileProc = app;
-                    profileFile = mService.mProfileFile;
-                    profileFd = mService.mProfileFd;
-                    profileAutoStop = mService.mAutoStopProfiler;
-                }
-            }
-            app.hasShownUi = true;
-            app.pendingUiClean = true;
-            if (profileFd != null) {
-                try {
-                    profileFd = profileFd.dup();
-                } catch (IOException e) {
-                    if (profileFd != null) {
-                        try {
-                            profileFd.close();
-                        } catch (IOException o) {
-                        }
-                        profileFd = null;
-                    }
-                }
-            }
-            app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_TOP);
-            app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken,
-                    System.identityHashCode(r), r.info,
-                    new Configuration(mService.mConfiguration), r.compat,
-                    app.repProcState, r.icicle, results, newIntents, !andResume,
-                    mService.isNextTransitionForward(), profileFile, profileFd,
-                    profileAutoStop);
-
-            if ((app.info.flags&ApplicationInfo.FLAG_CANT_SAVE_STATE) != 0) {
-                // This may be a heavy-weight process!  Note that the package
-                // manager will ensure that only activity can run in the main
-                // process of the .apk, which is the only thing that will be
-                // considered heavy-weight.
-                if (app.processName.equals(app.info.packageName)) {
-                    if (mService.mHeavyWeightProcess != null
-                            && mService.mHeavyWeightProcess != app) {
-                        Slog.w(TAG, "Starting new heavy weight process " + app
-                                + " when already running "
-                                + mService.mHeavyWeightProcess);
-                    }
-                    mService.mHeavyWeightProcess = app;
-                    Message msg = mService.mHandler.obtainMessage(
-                            ActivityManagerService.POST_HEAVY_NOTIFICATION_MSG);
-                    msg.obj = r;
-                    mService.mHandler.sendMessage(msg);
-                }
-            }
-
-        } catch (RemoteException e) {
-            if (r.launchFailed) {
-                // This is the second time we failed -- finish activity
-                // and give up.
-                Slog.e(TAG, "Second failure launching "
-                      + r.intent.getComponent().flattenToShortString()
-                      + ", giving up", e);
-                mService.appDiedLocked(app, app.pid, app.thread);
-                stack.requestFinishActivityLocked(r.appToken, Activity.RESULT_CANCELED, null,
-                        "2nd-crash", false);
-                return false;
-            }
-
-            // This is the first time we failed -- restart process and
-            // retry.
-            app.activities.remove(r);
-            throw e;
-        }
-
-        r.launchFailed = false;
-        if (stack.updateLRUListLocked(r)) {
-            Slog.w(TAG, "Activity " + r
-                  + " being launched, but already in LRU list");
-        }
-
-        if (andResume) {
-            // As part of the process of launching, ActivityThread also performs
-            // 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.
-            if (DEBUG_STATES) Slog.v(TAG, "Moving to STOPPED: " + r
-                    + " (starting in stopped state)");
-            r.state = ActivityState.STOPPED;
-            r.stopped = true;
-        }
-
-        // Launch the new version setup screen if needed.  We do this -after-
-        // launching the initial activity (that is, home), so that it can have
-        // a chance to initialize itself while in the background, making the
-        // switch back to it faster and look better.
-        if (isFrontStack(stack)) {
-            mService.startSetupActivityLocked();
-        }
-
-        return true;
-    }
-
-    void startSpecificActivityLocked(ActivityRecord r,
-            boolean andResume, boolean checkConfig) {
-        // Is this activity's application already running?
-        ProcessRecord app = mService.getProcessRecordLocked(r.processName,
-                r.info.applicationInfo.uid, true);
-
-        r.task.stack.setLaunchTime(r);
-
-        if (app != null && app.thread != null) {
-            try {
-                if ((r.info.flags&ActivityInfo.FLAG_MULTIPROCESS) == 0
-                        || !"android".equals(r.info.packageName)) {
-                    // Don't add this if it is a platform component that is marked
-                    // to run in multiple processes, because this is actually
-                    // part of the framework so doesn't make sense to track as a
-                    // separate apk in the process.
-                    app.addPackage(r.info.packageName, mService.mProcessStats);
-                }
-                realStartActivityLocked(r, app, andResume, checkConfig);
-                return;
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Exception when starting activity "
-                        + r.intent.getComponent().flattenToShortString(), e);
-            }
-
-            // If a dead object exception was thrown -- fall through to
-            // restart the application.
-        }
-
-        mService.startProcessLocked(r.processName, r.info.applicationInfo, true, 0,
-                "activity", r.intent.getComponent(), false, false, true);
-    }
-
-    final int startActivityLocked(IApplicationThread caller,
-            Intent intent, String resolvedType, ActivityInfo aInfo, IBinder resultTo,
-            String resultWho, int requestCode,
-            int callingPid, int callingUid, String callingPackage, int startFlags, Bundle options,
-            boolean componentSpecified, ActivityRecord[] outActivity) {
-        int err = ActivityManager.START_SUCCESS;
-
-        ProcessRecord callerApp = null;
-        if (caller != null) {
-            callerApp = mService.getRecordForAppLocked(caller);
-            if (callerApp != null) {
-                callingPid = callerApp.pid;
-                callingUid = callerApp.info.uid;
-            } else {
-                Slog.w(TAG, "Unable to find app for caller " + caller
-                      + " (pid=" + callingPid + ") when starting: "
-                      + intent.toString());
-                err = ActivityManager.START_PERMISSION_DENIED;
-            }
-        }
-
-        if (err == ActivityManager.START_SUCCESS) {
-            final int userId = aInfo != null ? UserHandle.getUserId(aInfo.applicationInfo.uid) : 0;
-            Slog.i(TAG, "START u" + userId + " {" + intent.toShortString(true, true, true, false)
-                    + "} from pid " + (callerApp != null ? callerApp.pid : callingPid));
-        }
-
-        ActivityRecord sourceRecord = null;
-        ActivityRecord resultRecord = null;
-        if (resultTo != null) {
-            sourceRecord = isInAnyStackLocked(resultTo);
-            if (DEBUG_RESULTS) Slog.v(
-                TAG, "Will send result to " + resultTo + " " + sourceRecord);
-            if (sourceRecord != null) {
-                if (requestCode >= 0 && !sourceRecord.finishing) {
-                    resultRecord = sourceRecord;
-                }
-            }
-        }
-        ActivityStack resultStack = resultRecord == null ? null : resultRecord.task.stack;
-
-        int launchFlags = intent.getFlags();
-
-        if ((launchFlags&Intent.FLAG_ACTIVITY_FORWARD_RESULT) != 0
-                && sourceRecord != null) {
-            // Transfer the result target from the source activity to the new
-            // one being started, including any failures.
-            if (requestCode >= 0) {
-                ActivityOptions.abort(options);
-                return ActivityManager.START_FORWARD_AND_REQUEST_CONFLICT;
-            }
-            resultRecord = sourceRecord.resultTo;
-            resultWho = sourceRecord.resultWho;
-            requestCode = sourceRecord.requestCode;
-            sourceRecord.resultTo = null;
-            if (resultRecord != null) {
-                resultRecord.removeResultsLocked(
-                    sourceRecord, resultWho, requestCode);
-            }
-            if (sourceRecord.launchedFromUid == callingUid) {
-                // The new activity is being launched from the same uid as the previous
-                // activity in the flow, and asking to forward its result back to the
-                // previous.  In this case the activity is serving as a trampoline between
-                // the two, so we also want to update its launchedFromPackage to be the
-                // same as the previous activity.  Note that this is safe, since we know
-                // these two packages come from the same uid; the caller could just as
-                // well have supplied that same package name itself.  This specifially
-                // deals with the case of an intent picker/chooser being launched in the app
-                // flow to redirect to an activity picked by the user, where we want the final
-                // activity to consider it to have been launched by the previous app activity.
-                callingPackage = sourceRecord.launchedFromPackage;
-            }
-        }
-
-        if (err == ActivityManager.START_SUCCESS && intent.getComponent() == null) {
-            // We couldn't find a class that can handle the given Intent.
-            // That's the end of that!
-            err = ActivityManager.START_INTENT_NOT_RESOLVED;
-        }
-
-        if (err == ActivityManager.START_SUCCESS && aInfo == null) {
-            // We couldn't find the specific class specified in the Intent.
-            // Also the end of the line.
-            err = ActivityManager.START_CLASS_NOT_FOUND;
-        }
-
-        if (err != ActivityManager.START_SUCCESS) {
-            if (resultRecord != null) {
-                resultStack.sendActivityResultLocked(-1,
-                    resultRecord, resultWho, requestCode,
-                    Activity.RESULT_CANCELED, null);
-            }
-            setDismissKeyguard(false);
-            ActivityOptions.abort(options);
-            return err;
-        }
-
-        final int startAnyPerm = mService.checkPermission(
-                START_ANY_ACTIVITY, callingPid, callingUid);
-        final int componentPerm = mService.checkComponentPermission(aInfo.permission, callingPid,
-                callingUid, aInfo.applicationInfo.uid, aInfo.exported);
-        if (startAnyPerm != PERMISSION_GRANTED && componentPerm != PERMISSION_GRANTED) {
-            if (resultRecord != null) {
-                resultStack.sendActivityResultLocked(-1,
-                    resultRecord, resultWho, requestCode,
-                    Activity.RESULT_CANCELED, null);
-            }
-            setDismissKeyguard(false);
-            String msg;
-            if (!aInfo.exported) {
-                msg = "Permission Denial: starting " + intent.toString()
-                        + " from " + callerApp + " (pid=" + callingPid
-                        + ", uid=" + callingUid + ")"
-                        + " not exported from uid " + aInfo.applicationInfo.uid;
-            } else {
-                msg = "Permission Denial: starting " + intent.toString()
-                        + " from " + callerApp + " (pid=" + callingPid
-                        + ", uid=" + callingUid + ")"
-                        + " requires " + aInfo.permission;
-            }
-            Slog.w(TAG, msg);
-            throw new SecurityException(msg);
-        }
-
-        boolean abort = !mService.mIntentFirewall.checkStartActivity(intent, callingUid,
-                callingPid, resolvedType, aInfo.applicationInfo);
-
-        if (mService.mController != null) {
-            try {
-                // The Intent we give to the watcher has the extra data
-                // stripped off, since it can contain private information.
-                Intent watchIntent = intent.cloneFilter();
-                abort |= !mService.mController.activityStarting(watchIntent,
-                        aInfo.applicationInfo.packageName);
-            } catch (RemoteException e) {
-                mService.mController = null;
-            }
-        }
-
-        if (abort) {
-            if (resultRecord != null) {
-                resultStack.sendActivityResultLocked(-1, resultRecord, resultWho, requestCode,
-                        Activity.RESULT_CANCELED, null);
-            }
-            // We pretend to the caller that it was really started, but
-            // they will just get a cancel result.
-            setDismissKeyguard(false);
-            ActivityOptions.abort(options);
-            return ActivityManager.START_SUCCESS;
-        }
-
-        ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage,
-                intent, resolvedType, aInfo, mService.mConfiguration,
-                resultRecord, resultWho, requestCode, componentSpecified, this);
-        if (outActivity != null) {
-            outActivity[0] = r;
-        }
-
-        final ActivityStack stack = getFocusedStack();
-        if (stack.mResumedActivity == null
-                || stack.mResumedActivity.info.applicationInfo.uid != callingUid) {
-            if (!mService.checkAppSwitchAllowedLocked(callingPid, callingUid, "Activity start")) {
-                PendingActivityLaunch pal =
-                        new PendingActivityLaunch(r, sourceRecord, startFlags, stack);
-                mService.mPendingActivityLaunches.add(pal);
-                setDismissKeyguard(false);
-                ActivityOptions.abort(options);
-                return ActivityManager.START_SWITCHES_CANCELED;
-            }
-        }
-
-        if (mService.mDidAppSwitch) {
-            // This is the second allowed switch since we stopped switches,
-            // so now just generally allow switches.  Use case: user presses
-            // home (switches disabled, switch to home, mDidAppSwitch now true);
-            // user taps a home icon (coming from home so allowed, we hit here
-            // and now allow anyone to switch again).
-            mService.mAppSwitchesAllowedTime = 0;
-        } else {
-            mService.mDidAppSwitch = true;
-        }
-
-        mService.doPendingActivityLaunchesLocked(false);
-
-        err = startActivityUncheckedLocked(r, sourceRecord, startFlags, true, options);
-
-        if (allPausedActivitiesComplete()) {
-            // If someone asked to have the keyguard dismissed on the next
-            // activity start, but we are not actually doing an activity
-            // switch...  just dismiss the keyguard now, because we
-            // probably want to see whatever is behind it.
-            dismissKeyguard();
-        }
-        return err;
-    }
-
-    ActivityStack adjustStackFocus(ActivityRecord r) {
-        final TaskRecord task = r.task;
-        if (r.isApplicationActivity() || (task != null && task.isApplicationTask())) {
-            if (task != null) {
-                final ActivityStack taskStack = task.stack;
-                if (mFocusedStack != taskStack) {
-                    if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
-                            "adjustStackFocus: Setting focused stack to r=" + r + " task=" + task);
-                    mFocusedStack = taskStack.isHomeStack() ? null : taskStack;
-                } else {
-                    if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
-                        "adjustStackFocus: Focused stack already=" + mFocusedStack);
-                }
-                return taskStack;
-            }
-
-            if (mFocusedStack != null) {
-                if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
-                        "adjustStackFocus: Have a focused stack=" + mFocusedStack);
-                return mFocusedStack;
-            }
-
-            for (int stackNdx = mStacks.size() - 1; stackNdx > 0; --stackNdx) {
-                ActivityStack stack = mStacks.get(stackNdx);
-                if (!stack.isHomeStack()) {
-                    if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
-                            "adjustStackFocus: Setting focused stack=" + stack);
-                    mFocusedStack = stack;
-                    return mFocusedStack;
-                }
-            }
-
-            // Time to create the first app stack for this user.
-            int stackId =
-                    mService.createStack(-1, HOME_STACK_ID, StackBox.TASK_STACK_GOES_OVER, 1.0f);
-            if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG, "adjustStackFocus: New stack r=" + r +
-                    " stackId=" + stackId);
-            mFocusedStack = getStack(stackId);
-            return mFocusedStack;
-        }
-        return mHomeStack;
-    }
-
-    void setFocusedStack(ActivityRecord r) {
-        if (r == null) {
-            return;
-        }
-        if (!r.isApplicationActivity() || (r.task != null && !r.task.isApplicationTask())) {
-            if (mStackState != STACK_STATE_HOME_IN_FRONT) {
-                if (DEBUG_STACK || DEBUG_FOCUS) Slog.d(TAG, "setFocusedStack: mStackState old=" +
-                        stackStateToString(mStackState) + " new=" +
-                        stackStateToString(STACK_STATE_HOME_TO_FRONT) +
-                        " Callers=" + Debug.getCallers(3));
-                mStackState = STACK_STATE_HOME_TO_FRONT;
-            }
-        } else {
-            if (DEBUG_FOCUS || DEBUG_STACK) Slog.d(TAG,
-                    "setFocusedStack: Setting focused stack to r=" + r + " task=" + r.task +
-                    " Callers=" + Debug.getCallers(3));
-            final ActivityStack taskStack = r.task.stack;
-            mFocusedStack = taskStack.isHomeStack() ? null : taskStack;
-            if (mStackState != STACK_STATE_HOME_IN_BACK) {
-                if (DEBUG_STACK) Slog.d(TAG, "setFocusedStack: mStackState old=" +
-                        stackStateToString(mStackState) + " new=" +
-                        stackStateToString(STACK_STATE_HOME_TO_BACK) +
-                        " Callers=" + Debug.getCallers(3));
-                mStackState = STACK_STATE_HOME_TO_BACK;
-            }
-        }
-    }
-
-    final int startActivityUncheckedLocked(ActivityRecord r,
-            ActivityRecord sourceRecord, int startFlags, boolean doResume,
-            Bundle options) {
-        final Intent intent = r.intent;
-        final int callingUid = r.launchedFromUid;
-
-        int launchFlags = intent.getFlags();
-
-        // We'll invoke onUserLeaving before onPause only if the launching
-        // activity did not explicitly state that this is an automated launch.
-        mUserLeaving = (launchFlags&Intent.FLAG_ACTIVITY_NO_USER_ACTION) == 0;
-        if (DEBUG_USER_LEAVING) Slog.v(TAG, "startActivity() => mUserLeaving=" + 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) {
-            r.delayedResume = true;
-        }
-
-        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 = getFocusedStack().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;
-            }
-        }
-
-        if (sourceRecord == null) {
-            // This activity is not being started from another...  in this
-            // case we -always- start a new task.
-            if ((launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
-                Slog.w(TAG, "startActivity called from non-Activity context; forcing " +
-                        "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
-                launchFlags |= Intent.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 |= Intent.FLAG_ACTIVITY_NEW_TASK;
-        } else if (r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE
-                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
-            // The activity being started is a single instance...  it always
-            // gets launched into its own task.
-            launchFlags |= Intent.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&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
-                    Slog.w(TAG, "startActivity called from finishing " + sourceRecord
-                            + "; forcing " + "Intent.FLAG_ACTIVITY_NEW_TASK for: " + intent);
-                    launchFlags |= Intent.FLAG_ACTIVITY_NEW_TASK;
-                    newTaskInfo = sourceRecord.info;
-                    newTaskIntent = sourceRecord.task.intent;
-                }
-                sourceRecord = null;
-                sourceStack = null;
-            } else {
-                sourceStack = sourceRecord.task.stack;
-            }
-        } else {
-            sourceStack = null;
-        }
-
-        if (r.resultTo != null && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
-            // 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;
-        }
-
-        boolean addingToTask = false;
-        boolean movedHome = false;
-        TaskRecord reuseTask = null;
-        ActivityStack targetStack;
-        if (((launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0 &&
-                (launchFlags&Intent.FLAG_ACTIVITY_MULTIPLE_TASK) == 0)
-                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK
-                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
-            // If bring to front is requested, and no result is requested, and
-            // we can find a task that was started with this same
-            // component, then instead of launching bring that one to the front.
-            if (r.resultTo == null) {
-                // 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.
-                ActivityRecord intentActivity = r.launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE
-                        ? findTaskLocked(r)
-                        : findActivityLocked(intent, r.info);
-                if (intentActivity != null) {
-                    if (r.task == null) {
-                        r.task = intentActivity.task;
-                    }
-                    targetStack = intentActivity.task.stack;
-                    targetStack.mLastPausedActivity = null;
-                    if (DEBUG_TASKS) Slog.d(TAG, "Bring to front target: " + targetStack
-                            + " from " + intentActivity);
-                    moveHomeStack(targetStack.isHomeStack());
-                    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(intent, r.info);
-                    }
-                    // 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 lastStack = getLastStack();
-                    ActivityRecord curTop = lastStack == null?
-                            null : lastStack.topRunningNonDelayedActivityLocked(notTop);
-                    if (curTop != null && (curTop.task != intentActivity.task ||
-                            curTop.task != lastStack.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.
-                            movedHome = true;
-                            targetStack.moveTaskToFrontLocked(intentActivity.task, r, options);
-                            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.mOnTopOfHome = true;
-                            }
-                            options = null;
-                        }
-                    }
-                    // 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) {
-                            resumeTopActivitiesLocked(targetStack, null, options);
-                        } else {
-                            ActivityOptions.abort(options);
-                        }
-                        if (r.task == null)  Slog.v(TAG,
-                                "startActivityUncheckedLocked: task left null",
-                                new RuntimeException("here").fillInStackTrace());
-                        return ActivityManager.START_RETURN_INTENT_TO_CALLER;
-                    }
-                    if ((launchFlags &
-                            (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK))
-                            == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.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.intent, r.info);
-                    } else if ((launchFlags&Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0
-                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK
-                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
-                        // 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.intent, r.info);
-                            }
-                            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT,
-                                    r, top.task);
-                            top.deliverNewIntentLocked(callingUid, r.intent);
-                        } 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;
-                        }
-                    } 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
-                                || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP)
-                                && intentActivity.realActivity.equals(r.realActivity)) {
-                            ActivityStack.logStartActivity(EventLogTags.AM_NEW_INTENT, r,
-                                    intentActivity.task);
-                            if (intentActivity.frontOfTask) {
-                                intentActivity.task.setIntent(r.intent, r.info);
-                            }
-                            intentActivity.deliverNewIntentLocked(callingUid, r.intent);
-                        } 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.intent, r.info);
-                    }
-                    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);
-                        } else {
-                            ActivityOptions.abort(options);
-                        }
-                        if (r.task == null)  Slog.v(TAG,
-                            "startActivityUncheckedLocked: task left null",
-                            new RuntimeException("here").fillInStackTrace());
-                        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 = getFocusedStack();
-            ActivityRecord top = topStack.topRunningNonDelayedActivityLocked(notTop);
-            if (top != null && r.resultTo == null) {
-                if (top.realActivity.equals(r.realActivity) && top.userId == r.userId) {
-                    if (top.app != null && top.app.thread != null) {
-                        if ((launchFlags&Intent.FLAG_ACTIVITY_SINGLE_TOP) != 0
-                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TOP
-                            || r.launchMode == ActivityInfo.LAUNCH_SINGLE_TASK) {
-                            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) {
-                                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!
-                                if (r.task == null)  Slog.v(TAG,
-                                    "startActivityUncheckedLocked: task left null",
-                                    new RuntimeException("here").fillInStackTrace());
-                                return ActivityManager.START_RETURN_INTENT_TO_CALLER;
-                            }
-                            top.deliverNewIntentLocked(callingUid, r.intent);
-                            if (r.task == null)  Slog.v(TAG,
-                                "startActivityUncheckedLocked: task left null",
-                                new RuntimeException("here").fillInStackTrace());
-                            return ActivityManager.START_DELIVERED_TO_TOP;
-                        }
-                    }
-                }
-            }
-
-        } else {
-            if (r.resultTo != null) {
-                r.resultTo.task.stack.sendActivityResultLocked(-1, r.resultTo, r.resultWho,
-                        r.requestCode, Activity.RESULT_CANCELED, null);
-            }
-            ActivityOptions.abort(options);
-            if (r.task == null)  Slog.v(TAG,
-                "startActivityUncheckedLocked: task left null",
-                new RuntimeException("here").fillInStackTrace());
-            return ActivityManager.START_CLASS_NOT_FOUND;
-        }
-
-        boolean newTask = false;
-        boolean keepCurTransition = false;
-
-        // Should this be considered a new task?
-        if (r.resultTo == null && !addingToTask
-                && (launchFlags&Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
-            targetStack = adjustStackFocus(r);
-            moveHomeStack(targetStack.isHomeStack());
-            if (reuseTask == null) {
-                r.setTask(targetStack.createTaskRecord(getNextTaskId(),
-                        newTaskInfo != null ? newTaskInfo : r.info,
-                        newTaskIntent != null ? newTaskIntent : intent,
-                        true), null, true);
-                if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r + " in new task " +
-                        r.task);
-            } else {
-                r.setTask(reuseTask, reuseTask, true);
-            }
-            newTask = true;
-            if (!movedHome) {
-                if ((launchFlags &
-                        (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME))
-                        == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.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.mOnTopOfHome = true;
-                }
-            }
-        } else if (sourceRecord != null) {
-            TaskRecord sourceTask = sourceRecord.task;
-            targetStack = sourceTask.stack;
-            moveHomeStack(targetStack.isHomeStack());
-            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);
-                    // For paranoia, make sure we have correctly
-                    // resumed the top activity.
-                    targetStack.mLastPausedActivity = null;
-                    if (doResume) {
-                        targetStack.resumeTopActivityLocked(null);
-                    }
-                    ActivityOptions.abort(options);
-                    if (r.task == null)  Slog.w(TAG,
-                        "startActivityUncheckedLocked: task left null",
-                        new RuntimeException("here").fillInStackTrace());
-                    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);
-                    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, sourceRecord.thumbHolder, false);
-            if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r
-                    + " in existing task " + r.task + " from source " + sourceRecord);
-
-        } 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 = adjustStackFocus(r);
-            moveHomeStack(targetStack.isHomeStack());
-            ActivityRecord prev = targetStack.topActivity();
-            r.setTask(prev != null ? prev.task
-                    : targetStack.createTaskRecord(getNextTaskId(), r.info, intent, true),
-                    null, true);
-            if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r
-                    + " in new guessed " + r.task);
-        }
-
-        mService.grantUriPermissionFromIntentLocked(callingUid, r.packageName,
-                intent, r.getUriPermissionsLocked());
-
-        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, doResume, keepCurTransition, options);
-        mService.setFocusedActivityLocked(r);
-        return ActivityManager.START_SUCCESS;
-    }
-
-    void acquireLaunchWakelock() {
-        if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
-            throw new IllegalStateException("Calling must be system uid");
-        }
-        mLaunchingActivity.acquire();
-        if (!mHandler.hasMessages(LAUNCH_TIMEOUT_MSG)) {
-            // To be safe, don't allow the wake lock to be held for too long.
-            mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT);
-        }
-    }
-
-    // Checked.
-    final ActivityRecord activityIdleInternalLocked(final IBinder token, boolean fromTimeout,
-            Configuration config) {
-        if (localLOGV) Slog.v(TAG, "Activity idle: " + token);
-
-        ArrayList<ActivityRecord> stops = null;
-        ArrayList<ActivityRecord> finishes = null;
-        ArrayList<UserStartedState> startingUsers = null;
-        int NS = 0;
-        int NF = 0;
-        IApplicationThread sendThumbnail = null;
-        boolean booting = false;
-        boolean enableScreen = false;
-        boolean activityRemoved = false;
-
-        ActivityRecord r = ActivityRecord.forToken(token);
-        if (r != null) {
-            if (DEBUG_IDLE) Slog.d(TAG, "activityIdleInternalLocked: Callers=" +
-                    Debug.getCallers(4));
-            mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
-            r.finishLaunchTickingLocked();
-            if (fromTimeout) {
-                reportActivityLaunchedLocked(fromTimeout, r, -1, -1);
-            }
-
-            // This is a hack to semi-deal with a race condition
-            // in the client where it can be constructed with a
-            // newer configuration from when we asked it to launch.
-            // We'll update with whatever configuration it now says
-            // it used to launch.
-            if (config != null) {
-                r.configuration = config;
-            }
-
-            // We are now idle.  If someone is waiting for a thumbnail from
-            // us, we can now deliver.
-            r.idle = true;
-
-            if (r.thumbnailNeeded && r.app != null && r.app.thread != null) {
-                sendThumbnail = r.app.thread;
-                r.thumbnailNeeded = false;
-            }
-
-            //Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout);
-            if (!mService.mBooted && isFrontStack(r.task.stack)) {
-                mService.mBooted = true;
-                enableScreen = true;
-            }
-        }
-
-        if (allResumedActivitiesIdle()) {
-            if (r != null) {
-                mService.scheduleAppGcsLocked();
-            }
-
-            if (mLaunchingActivity.isHeld()) {
-                mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
-                if (VALIDATE_WAKE_LOCK_CALLER &&
-                        Binder.getCallingUid() != Process.myUid()) {
-                    throw new IllegalStateException("Calling must be system uid");
-                }
-                mLaunchingActivity.release();
-            }
-            ensureActivitiesVisibleLocked(null, 0);
-        }
-
-        // Atomically retrieve all of the other things to do.
-        stops = processStoppingActivitiesLocked(true);
-        NS = stops != null ? stops.size() : 0;
-        if ((NF=mFinishingActivities.size()) > 0) {
-            finishes = new ArrayList<ActivityRecord>(mFinishingActivities);
-            mFinishingActivities.clear();
-        }
-
-        final ArrayList<ActivityRecord> thumbnails;
-        final int NT = mCancelledThumbnails.size();
-        if (NT > 0) {
-            thumbnails = new ArrayList<ActivityRecord>(mCancelledThumbnails);
-            mCancelledThumbnails.clear();
-        } else {
-            thumbnails = null;
-        }
-
-        if (isFrontStack(mHomeStack)) {
-            booting = mService.mBooting;
-            mService.mBooting = false;
-        }
-
-        if (mStartingUsers.size() > 0) {
-            startingUsers = new ArrayList<UserStartedState>(mStartingUsers);
-            mStartingUsers.clear();
-        }
-
-        // Perform the following actions from unsynchronized state.
-        final IApplicationThread thumbnailThread = sendThumbnail;
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                if (thumbnailThread != null) {
-                    try {
-                        thumbnailThread.requestThumbnail(token);
-                    } catch (Exception e) {
-                        Slog.w(TAG, "Exception thrown when requesting thumbnail", e);
-                        mService.sendPendingThumbnail(null, token, null, null, true);
-                    }
-                }
-
-                // Report back to any thumbnail receivers.
-                for (int i = 0; i < NT; i++) {
-                    ActivityRecord r = thumbnails.get(i);
-                    mService.sendPendingThumbnail(r, null, null, null, true);
-                }
-            }
-        });
-
-        // Stop any activities that are scheduled to do so but have been
-        // waiting for the next one to start.
-        for (int i = 0; i < NS; i++) {
-            r = stops.get(i);
-            final ActivityStack stack = r.task.stack;
-            if (r.finishing) {
-                stack.finishCurrentActivityLocked(r, ActivityStack.FINISH_IMMEDIATELY, false);
-            } else {
-                stack.stopActivityLocked(r);
-            }
-        }
-
-        // Finish any activities that are scheduled to do so but have been
-        // waiting for the next one to start.
-        for (int i = 0; i < NF; i++) {
-            r = finishes.get(i);
-            activityRemoved |= r.task.stack.destroyActivityLocked(r, true, false, "finish-idle");
-        }
-
-        if (booting) {
-            mService.finishBooting();
-        } else if (startingUsers != null) {
-            for (int i = 0; i < startingUsers.size(); i++) {
-                mService.finishUserSwitch(startingUsers.get(i));
-            }
-        }
-
-        mService.trimApplications();
-        //dump();
-        //mWindowManager.dump();
-
-        if (enableScreen) {
-            mService.enableScreenAfterBoot();
-        }
-
-        if (activityRemoved) {
-            resumeTopActivitiesLocked();
-        }
-
-        return r;
-    }
-
-    boolean handleAppDiedLocked(ProcessRecord app) {
-        boolean hasVisibleActivities = false;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            hasVisibleActivities |= mStacks.get(stackNdx).handleAppDiedLocked(app);
-        }
-        return hasVisibleActivities;
-    }
-
-    void closeSystemDialogsLocked() {
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            stack.closeSystemDialogsLocked();
-        }
-    }
-
-    void removeUserLocked(int userId) {
-        mUserStackInFront.delete(userId);
-    }
-
-    /**
-     * @return true if some activity was finished (or would have finished if doit were true).
-     */
-    boolean forceStopPackageLocked(String name, boolean doit, boolean evenPersistent, int userId) {
-        boolean didSomething = false;
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (stack.forceStopPackageLocked(name, doit, evenPersistent, userId)) {
-                didSomething = true;
-            }
-        }
-        return didSomething;
-    }
-
-    void updatePreviousProcessLocked(ActivityRecord r) {
-        // Now that this process has stopped, we may want to consider
-        // it to be the previous app to try to keep around in case
-        // the user wants to return to it.
-
-        // First, found out what is currently the foreground app, so that
-        // we don't blow away the previous app if this activity is being
-        // hosted by the process that is actually still the foreground.
-        ProcessRecord fgApp = null;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (isFrontStack(stack)) {
-                if (stack.mResumedActivity != null) {
-                    fgApp = stack.mResumedActivity.app;
-                } else if (stack.mPausingActivity != null) {
-                    fgApp = stack.mPausingActivity.app;
-                }
-                break;
-            }
-        }
-
-        // Now set this one as the previous process, only if that really
-        // makes sense to.
-        if (r.app != null && fgApp != null && r.app != fgApp
-                && r.lastVisibleTime > mService.mPreviousProcessVisibleTime
-                && r.app != mService.mHomeProcess) {
-            mService.mPreviousProcess = r.app;
-            mService.mPreviousProcessVisibleTime = r.lastVisibleTime;
-        }
-    }
-
-    boolean resumeTopActivitiesLocked() {
-        return resumeTopActivitiesLocked(null, null, null);
-    }
-
-    boolean resumeTopActivitiesLocked(ActivityStack targetStack, ActivityRecord target,
-            Bundle targetOptions) {
-        if (targetStack == null) {
-            targetStack = getFocusedStack();
-        }
-        boolean result = false;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (isFrontStack(stack)) {
-                if (stack == targetStack) {
-                    result = stack.resumeTopActivityLocked(target, targetOptions);
-                } else {
-                    stack.resumeTopActivityLocked(null);
-                }
-            }
-        }
-        return result;
-    }
-
-    void finishTopRunningActivityLocked(ProcessRecord app) {
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            stack.finishTopRunningActivityLocked(app);
-        }
-    }
-
-    void findTaskToMoveToFrontLocked(int taskId, int flags, Bundle options) {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            if (mStacks.get(stackNdx).findTaskToMoveToFrontLocked(taskId, flags, options)) {
-                if (DEBUG_STACK) Slog.d(TAG, "findTaskToMoveToFront: moved to front of stack=" +
-                        mStacks.get(stackNdx));
-                return;
-            }
-        }
-    }
-
-    ActivityStack getStack(int stackId) {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (stack.getStackId() == stackId) {
-                return stack;
-            }
-        }
-        return null;
-    }
-
-    ArrayList<ActivityStack> getStacks() {
-        return new ArrayList<ActivityStack>(mStacks);
-    }
-
-    int createStack() {
-        while (true) {
-            if (++mLastStackId <= HOME_STACK_ID) {
-                mLastStackId = HOME_STACK_ID + 1;
-            }
-            if (getStack(mLastStackId) == null) {
-                break;
-            }
-        }
-        mStacks.add(new ActivityStack(mService, mContext, mLooper, mLastStackId));
-        return mLastStackId;
-    }
-
-    void moveTaskToStack(int taskId, int stackId, boolean toTop) {
-        final TaskRecord task = anyTaskForIdLocked(taskId);
-        if (task == null) {
-            return;
-        }
-        final ActivityStack stack = getStack(stackId);
-        if (stack == null) {
-            Slog.w(TAG, "moveTaskToStack: no stack for id=" + stackId);
-            return;
-        }
-        removeTask(task);
-        stack.addTask(task, toTop);
-        mWindowManager.addTask(taskId, stackId, toTop);
-        resumeTopActivitiesLocked();
-    }
-
-    ActivityRecord findTaskLocked(ActivityRecord r) {
-        if (DEBUG_TASKS) Slog.d(TAG, "Looking for task of " + r);
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (!r.isApplicationActivity() && !stack.isHomeStack()) {
-                if (DEBUG_TASKS) Slog.d(TAG, "Skipping stack: " + stack);
-                continue;
-            }
-            final ActivityRecord ar = stack.findTaskLocked(r);
-            if (ar != null) {
-                return ar;
-            }
-        }
-        if (DEBUG_TASKS) Slog.d(TAG, "No task found");
-        return null;
-    }
-
-    ActivityRecord findActivityLocked(Intent intent, ActivityInfo info) {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityRecord ar = mStacks.get(stackNdx).findActivityLocked(intent, info);
-            if (ar != null) {
-                return ar;
-            }
-        }
-        return null;
-    }
-
-    void goingToSleepLocked() {
-        scheduleSleepTimeout();
-        if (!mGoingToSleep.isHeld()) {
-            mGoingToSleep.acquire();
-            if (mLaunchingActivity.isHeld()) {
-                if (VALIDATE_WAKE_LOCK_CALLER && Binder.getCallingUid() != Process.myUid()) {
-                    throw new IllegalStateException("Calling must be system uid");
-                }
-                mLaunchingActivity.release();
-                mService.mHandler.removeMessages(LAUNCH_TIMEOUT_MSG);
-            }
-        }
-        checkReadyForSleepLocked();
-    }
-
-    boolean shutdownLocked(int timeout) {
-        boolean timedout = false;
-        goingToSleepLocked();
-
-        final long endTime = System.currentTimeMillis() + timeout;
-        while (true) {
-            boolean cantShutdown = false;
-            for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-                cantShutdown |= mStacks.get(stackNdx).checkReadyForSleepLocked();
-            }
-            if (cantShutdown) {
-                long timeRemaining = endTime - System.currentTimeMillis();
-                if (timeRemaining > 0) {
-                    try {
-                        mService.wait(timeRemaining);
-                    } catch (InterruptedException e) {
-                    }
-                } else {
-                    Slog.w(TAG, "Activity manager shutdown timed out");
-                    timedout = true;
-                    break;
-                }
-            } else {
-                break;
-            }
-        }
-
-        // Force checkReadyForSleep to complete.
-        mSleepTimeout = true;
-        checkReadyForSleepLocked();
-
-        return timedout;
-    }
-
-    void comeOutOfSleepIfNeededLocked() {
-        removeSleepTimeouts();
-        if (mGoingToSleep.isHeld()) {
-            mGoingToSleep.release();
-        }
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            stack.awakeFromSleepingLocked();
-            if (isFrontStack(stack)) {
-                resumeTopActivitiesLocked();
-            }
-        }
-        mGoingToSleepActivities.clear();
-    }
-
-    void activitySleptLocked(ActivityRecord r) {
-        mGoingToSleepActivities.remove(r);
-        checkReadyForSleepLocked();
-    }
-
-    void checkReadyForSleepLocked() {
-        if (!mService.isSleepingOrShuttingDown()) {
-            // Do not care.
-            return;
-        }
-
-        if (!mSleepTimeout) {
-            boolean dontSleep = false;
-            for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-                dontSleep |= mStacks.get(stackNdx).checkReadyForSleepLocked();
-            }
-
-            if (mStoppingActivities.size() > 0) {
-                // Still need to tell some activities to stop; can't sleep yet.
-                if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still need to stop "
-                        + mStoppingActivities.size() + " activities");
-                scheduleIdleLocked();
-                dontSleep = true;
-            }
-
-            if (mGoingToSleepActivities.size() > 0) {
-                // Still need to tell some activities to sleep; can't sleep yet.
-                if (DEBUG_PAUSE) Slog.v(TAG, "Sleep still need to sleep "
-                        + mGoingToSleepActivities.size() + " activities");
-                dontSleep = true;
-            }
-
-            if (dontSleep) {
-                return;
-            }
-        }
-
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            mStacks.get(stackNdx).goToSleep();
-        }
-
-        removeSleepTimeouts();
-
-        if (mGoingToSleep.isHeld()) {
-            mGoingToSleep.release();
-        }
-        if (mService.mShuttingDown) {
-            mService.notifyAll();
-        }
-    }
-
-    boolean reportResumedActivityLocked(ActivityRecord r) {
-        final ActivityStack stack = r.task.stack;
-        if (isFrontStack(stack)) {
-            mService.updateUsageStats(r, true);
-        }
-        if (allResumedActivitiesComplete()) {
-            ensureActivitiesVisibleLocked(null, 0);
-            mWindowManager.executeAppTransition();
-            return true;
-        }
-        return false;
-    }
-
-    void handleAppCrashLocked(ProcessRecord app) {
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            stack.handleAppCrashLocked(app);
-        }
-    }
-
-    void ensureActivitiesVisibleLocked(ActivityRecord starting, int configChanges) {
-        // First the front stacks. In case any are not fullscreen and are in front of home.
-        boolean showHomeBehindStack = false;
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (isFrontStack(stack)) {
-                showHomeBehindStack =
-                        stack.ensureActivitiesVisibleLocked(starting, configChanges);
-            }
-        }
-        // Now do back stacks.
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            if (!isFrontStack(stack)) {
-                stack.ensureActivitiesVisibleLocked(starting, configChanges, showHomeBehindStack);
-            }
-        }
-    }
-
-    void scheduleDestroyAllActivities(ProcessRecord app, String reason) {
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            stack.scheduleDestroyActivities(app, false, reason);
-        }
-    }
-
-    boolean switchUserLocked(int userId, UserStartedState uss) {
-        mUserStackInFront.put(mCurrentUser, getFocusedStack().getStackId());
-        final int restoreStackId = mUserStackInFront.get(userId, HOME_STACK_ID);
-        mCurrentUser = userId;
-
-        mStartingUsers.add(uss);
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            mStacks.get(stackNdx).switchUserLocked(userId);
-        }
-
-        ActivityStack stack = getStack(restoreStackId);
-        if (stack == null) {
-            stack = mHomeStack;
-        }
-        final boolean homeInFront = stack.isHomeStack();
-        moveHomeStack(homeInFront);
-        mWindowManager.moveTaskToTop(stack.topTask().taskId);
-        return homeInFront;
-    }
-
-    final ArrayList<ActivityRecord> processStoppingActivitiesLocked(boolean remove) {
-        int N = mStoppingActivities.size();
-        if (N <= 0) return null;
-
-        ArrayList<ActivityRecord> stops = null;
-
-        final boolean nowVisible = allResumedActivitiesVisible();
-        for (int i=0; i<N; i++) {
-            ActivityRecord s = mStoppingActivities.get(i);
-            if (localLOGV) Slog.v(TAG, "Stopping " + s + ": nowVisible="
-                    + nowVisible + " waitingVisible=" + s.waitingVisible
-                    + " finishing=" + s.finishing);
-            if (s.waitingVisible && nowVisible) {
-                mWaitingVisibleActivities.remove(s);
-                s.waitingVisible = false;
-                if (s.finishing) {
-                    // If this activity is finishing, it is sitting on top of
-                    // everyone else but we now know it is no longer needed...
-                    // so get rid of it.  Otherwise, we need to go through the
-                    // normal flow and hide it once we determine that it is
-                    // hidden by the activities in front of it.
-                    if (localLOGV) Slog.v(TAG, "Before stopping, can hide: " + s);
-                    mWindowManager.setAppVisibility(s.appToken, false);
-                }
-            }
-            if ((!s.waitingVisible || mService.isSleepingOrShuttingDown()) && remove) {
-                if (localLOGV) Slog.v(TAG, "Ready to stop: " + s);
-                if (stops == null) {
-                    stops = new ArrayList<ActivityRecord>();
-                }
-                stops.add(s);
-                mStoppingActivities.remove(i);
-                N--;
-                i--;
-            }
-        }
-
-        return stops;
-    }
-
-    void validateTopActivitiesLocked() {
-        for (int stackNdx = mStacks.size() - 1; stackNdx >= 0; --stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            final ActivityRecord r = stack.topRunningActivityLocked(null);
-            final ActivityState state = r == null ? ActivityState.DESTROYED : r.state;
-            if (isFrontStack(stack)) {
-                if (r == null) {
-                    Slog.e(TAG, "validateTop...: null top activity, stack=" + stack);
-                } else {
-                    final ActivityRecord pausing = stack.mPausingActivity;
-                    if (pausing != null && pausing == r) {
-                        Slog.e(TAG, "validateTop...: top stack has pausing activity r=" + r +
-                            " state=" + state);
-                    }
-                    if (state != ActivityState.INITIALIZING && state != ActivityState.RESUMED) {
-                        Slog.e(TAG, "validateTop...: activity in front not resumed r=" + r +
-                                " state=" + state);
-                    }
-                }
-            } else {
-                final ActivityRecord resumed = stack.mResumedActivity;
-                if (resumed != null && resumed == r) {
-                    Slog.e(TAG, "validateTop...: back stack has resumed activity r=" + r +
-                        " state=" + state);
-                }
-                if (r != null && (state == ActivityState.INITIALIZING
-                        || state == ActivityState.RESUMED)) {
-                    Slog.e(TAG, "validateTop...: activity in back resumed r=" + r +
-                            " state=" + state);
-                }
-            }
-        }
-    }
-
-    private static String stackStateToString(int stackState) {
-        switch (stackState) {
-            case STACK_STATE_HOME_IN_FRONT: return "STACK_STATE_HOME_IN_FRONT";
-            case STACK_STATE_HOME_TO_BACK: return "STACK_STATE_HOME_TO_BACK";
-            case STACK_STATE_HOME_IN_BACK: return "STACK_STATE_HOME_IN_BACK";
-            case STACK_STATE_HOME_TO_FRONT: return "STACK_STATE_HOME_TO_FRONT";
-            default: return "Unknown stackState=" + stackState;
-        }
-    }
-
-    public void dump(PrintWriter pw, String prefix) {
-        pw.print(prefix); pw.print("mDismissKeyguardOnNextActivity=");
-                pw.println(mDismissKeyguardOnNextActivity);
-        pw.print(prefix); pw.print("mFocusedStack=" + mFocusedStack);
-                pw.print(" mStackState="); pw.println(stackStateToString(mStackState));
-        pw.print(prefix); pw.println("mSleepTimeout=" + mSleepTimeout);
-        pw.print(prefix); pw.println("mCurTaskId=" + mCurTaskId);
-        pw.print(prefix); pw.println("mUserStackInFront=" + mUserStackInFront);
-    }
-
-    ArrayList<ActivityRecord> getDumpActivitiesLocked(String name) {
-        return getFocusedStack().getDumpActivitiesLocked(name);
-    }
-
-    static boolean printThisActivity(PrintWriter pw, ActivityRecord activity, String dumpPackage,
-            boolean needSep, String prefix) {
-        if (activity != null) {
-            if (dumpPackage == null || dumpPackage.equals(activity.packageName)) {
-                if (needSep) {
-                    pw.println();
-                }
-                pw.print(prefix);
-                pw.println(activity);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    boolean dumpActivitiesLocked(FileDescriptor fd, PrintWriter pw, boolean dumpAll,
-            boolean dumpClient, String dumpPackage) {
-        boolean printed = false;
-        boolean needSep = false;
-        final int numStacks = mStacks.size();
-        for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            final ActivityStack stack = mStacks.get(stackNdx);
-            StringBuilder stackHeader = new StringBuilder(128);
-            stackHeader.append("  Stack #");
-            stackHeader.append(mStacks.indexOf(stack));
-            stackHeader.append(":");
-            printed |= stack.dumpActivitiesLocked(fd, pw, dumpAll, dumpClient, dumpPackage, needSep,
-                    stackHeader.toString());
-            printed |= dumpHistoryList(fd, pw, stack.mLRUActivities, "    ", "Run", false, !dumpAll,
-                    false, dumpPackage, true, "    Running activities (most recent first):", null);
-
-            needSep = printed;
-            boolean pr = printThisActivity(pw, stack.mPausingActivity, dumpPackage, needSep,
-                    "    mPausingActivity: ");
-            if (pr) {
-                printed = true;
-                needSep = false;
-            }
-            pr = printThisActivity(pw, stack.mResumedActivity, dumpPackage, needSep,
-                    "    mResumedActivity: ");
-            if (pr) {
-                printed = true;
-                needSep = false;
-            }
-            if (dumpAll) {
-                pr = printThisActivity(pw, stack.mLastPausedActivity, dumpPackage, needSep,
-                        "    mLastPausedActivity: ");
-                if (pr) {
-                    printed = true;
-                    needSep = true;
-                }
-                printed |= printThisActivity(pw, stack.mLastNoHistoryActivity, dumpPackage,
-                        needSep, "    mLastNoHistoryActivity: ");
-            }
-            needSep = printed;
-        }
-
-        printed |= dumpHistoryList(fd, pw, mFinishingActivities, "  ", "Fin", false, !dumpAll,
-                false, dumpPackage, true, "  Activities waiting to finish:", null);
-        printed |= dumpHistoryList(fd, pw, mStoppingActivities, "  ", "Stop", false, !dumpAll,
-                false, dumpPackage, true, "  Activities waiting to stop:", null);
-        printed |= dumpHistoryList(fd, pw, mWaitingVisibleActivities, "  ", "Wait", false, !dumpAll,
-                false, dumpPackage, true, "  Activities waiting for another to become visible:",
-                null);
-        printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, "  ", "Sleep", false, !dumpAll,
-                false, dumpPackage, true, "  Activities waiting to sleep:", null);
-        printed |= dumpHistoryList(fd, pw, mGoingToSleepActivities, "  ", "Sleep", false, !dumpAll,
-                false, dumpPackage, true, "  Activities waiting to sleep:", null);
-
-        return printed;
-    }
-
-    static boolean dumpHistoryList(FileDescriptor fd, PrintWriter pw, List<ActivityRecord> list,
-            String prefix, String label, boolean complete, boolean brief, boolean client,
-            String dumpPackage, boolean needNL, String header1, String header2) {
-        TaskRecord lastTask = null;
-        String innerPrefix = null;
-        String[] args = null;
-        boolean printed = false;
-        for (int i=list.size()-1; i>=0; i--) {
-            final ActivityRecord r = list.get(i);
-            if (dumpPackage != null && !dumpPackage.equals(r.packageName)) {
-                continue;
-            }
-            if (innerPrefix == null) {
-                innerPrefix = prefix + "      ";
-                args = new String[0];
-            }
-            printed = true;
-            final boolean full = !brief && (complete || !r.isInHistory());
-            if (needNL) {
-                pw.println("");
-                needNL = false;
-            }
-            if (header1 != null) {
-                pw.println(header1);
-                header1 = null;
-            }
-            if (header2 != null) {
-                pw.println(header2);
-                header2 = null;
-            }
-            if (lastTask != r.task) {
-                lastTask = r.task;
-                pw.print(prefix);
-                pw.print(full ? "* " : "  ");
-                pw.println(lastTask);
-                if (full) {
-                    lastTask.dump(pw, prefix + "  ");
-                } else if (complete) {
-                    // Complete + brief == give a summary.  Isn't that obvious?!?
-                    if (lastTask.intent != null) {
-                        pw.print(prefix); pw.print("  ");
-                                pw.println(lastTask.intent.toInsecureStringWithClip());
-                    }
-                }
-            }
-            pw.print(prefix); pw.print(full ? "  * " : "    "); pw.print(label);
-            pw.print(" #"); pw.print(i); pw.print(": ");
-            pw.println(r);
-            if (full) {
-                r.dump(pw, innerPrefix);
-            } else if (complete) {
-                // Complete + brief == give a summary.  Isn't that obvious?!?
-                pw.print(innerPrefix); pw.println(r.intent.toInsecureString());
-                if (r.app != null) {
-                    pw.print(innerPrefix); pw.println(r.app);
-                }
-            }
-            if (client && r.app != null && r.app.thread != null) {
-                // flush anything that is already in the PrintWriter since the thread is going
-                // to write to the file descriptor directly
-                pw.flush();
-                try {
-                    TransferPipe tp = new TransferPipe();
-                    try {
-                        r.app.thread.dumpActivity(tp.getWriteFd().getFileDescriptor(),
-                                r.appToken, innerPrefix, args);
-                        // Short timeout, since blocking here can
-                        // deadlock with the application.
-                        tp.go(fd, 2000);
-                    } finally {
-                        tp.kill();
-                    }
-                } catch (IOException e) {
-                    pw.println(innerPrefix + "Failure while dumping the activity: " + e);
-                } catch (RemoteException e) {
-                    pw.println(innerPrefix + "Got a RemoteException while dumping the activity");
-                }
-                needNL = true;
-            }
-        }
-        return printed;
-    }
-
-    void scheduleIdleTimeoutLocked(ActivityRecord next) {
-        if (DEBUG_IDLE) Slog.d(TAG, "scheduleIdleTimeoutLocked: Callers=" + Debug.getCallers(4));
-        Message msg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG, next);
-        mHandler.sendMessageDelayed(msg, IDLE_TIMEOUT);
-    }
-
-    final void scheduleIdleLocked() {
-        mHandler.sendEmptyMessage(IDLE_NOW_MSG);
-    }
-
-    void removeTimeoutsForActivityLocked(ActivityRecord r) {
-        if (DEBUG_IDLE) Slog.d(TAG, "removeTimeoutsForActivity: Callers=" + Debug.getCallers(4));
-        mHandler.removeMessages(IDLE_TIMEOUT_MSG, r);
-    }
-
-    final void scheduleResumeTopActivities() {
-        mHandler.sendEmptyMessage(RESUME_TOP_ACTIVITY_MSG);
-    }
-
-    void removeSleepTimeouts() {
-        mSleepTimeout = false;
-        mHandler.removeMessages(SLEEP_TIMEOUT_MSG);
-    }
-
-    final void scheduleSleepTimeout() {
-        removeSleepTimeouts();
-        mHandler.sendEmptyMessageDelayed(SLEEP_TIMEOUT_MSG, SLEEP_TIMEOUT);
-    }
-
-    private final class ActivityStackSupervisorHandler extends Handler {
-
-        public ActivityStackSupervisorHandler(Looper looper) {
-            super(looper);
-        }
-
-        void activityIdleInternal(ActivityRecord r) {
-            synchronized (mService) {
-                activityIdleInternalLocked(r != null ? r.appToken : null, true, null);
-            }
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case IDLE_TIMEOUT_MSG: {
-                    if (DEBUG_IDLE) Slog.d(TAG, "handleMessage: IDLE_TIMEOUT_MSG: r=" + msg.obj);
-                    if (mService.mDidDexOpt) {
-                        mService.mDidDexOpt = false;
-                        Message nmsg = mHandler.obtainMessage(IDLE_TIMEOUT_MSG);
-                        nmsg.obj = msg.obj;
-                        mHandler.sendMessageDelayed(nmsg, IDLE_TIMEOUT);
-                        return;
-                    }
-                    // We don't at this point know if the activity is fullscreen,
-                    // so we need to be conservative and assume it isn't.
-                    activityIdleInternal((ActivityRecord)msg.obj);
-                } break;
-                case IDLE_NOW_MSG: {
-                    if (DEBUG_IDLE) Slog.d(TAG, "handleMessage: IDLE_NOW_MSG: r=" + msg.obj);
-                    activityIdleInternal((ActivityRecord)msg.obj);
-                } break;
-                case RESUME_TOP_ACTIVITY_MSG: {
-                    synchronized (mService) {
-                        resumeTopActivitiesLocked();
-                    }
-                } break;
-                case SLEEP_TIMEOUT_MSG: {
-                    synchronized (mService) {
-                        if (mService.isSleepingOrShuttingDown()) {
-                            Slog.w(TAG, "Sleep timeout!  Sleeping now.");
-                            mSleepTimeout = true;
-                            checkReadyForSleepLocked();
-                        }
-                    }
-                } break;
-                case LAUNCH_TIMEOUT_MSG: {
-                    if (mService.mDidDexOpt) {
-                        mService.mDidDexOpt = false;
-                        mHandler.sendEmptyMessageDelayed(LAUNCH_TIMEOUT_MSG, LAUNCH_TIMEOUT);
-                        return;
-                    }
-                    synchronized (mService) {
-                        if (mLaunchingActivity.isHeld()) {
-                            Slog.w(TAG, "Launch timeout has expired, giving up wake lock!");
-                            if (VALIDATE_WAKE_LOCK_CALLER
-                                    && Binder.getCallingUid() != Process.myUid()) {
-                                throw new IllegalStateException("Calling must be system uid");
-                            }
-                            mLaunchingActivity.release();
-                        }
-                    }
-                } break;
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/am/BatteryStatsService.java b/services/java/com/android/server/am/BatteryStatsService.java
deleted file mode 100644
index 2d59678..0000000
--- a/services/java/com/android/server/am/BatteryStatsService.java
+++ /dev/null
@@ -1,579 +0,0 @@
-/*
- * Copyright (C) 2006-2007 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.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothHeadset;
-import android.bluetooth.BluetoothProfile;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.os.BatteryStats;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.Process;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.os.WorkSource;
-import android.telephony.SignalStrength;
-import android.telephony.TelephonyManager;
-import android.util.Slog;
-
-import com.android.internal.app.IBatteryStats;
-import com.android.internal.os.BatteryStatsImpl;
-import com.android.internal.os.PowerProfile;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.List;
-
-/**
- * All information we are collecting about things that can happen that impact
- * battery life.
- */
-public final class BatteryStatsService extends IBatteryStats.Stub {
-    static IBatteryStats sService;
-    
-    final BatteryStatsImpl mStats;
-    Context mContext;
-    private boolean mBluetoothPendingStats;
-    private BluetoothHeadset mBluetoothHeadset;
-
-    BatteryStatsService(String filename) {
-        mStats = new BatteryStatsImpl(filename);
-    }
-    
-    public void publish(Context context) {
-        mContext = context;
-        ServiceManager.addService(BatteryStats.SERVICE_NAME, asBinder());
-        mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
-        mStats.setRadioScanningTimeout(mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_radioScanningTimeout)
-                * 1000L);
-    }
-    
-    public void shutdown() {
-        Slog.w("BatteryStats", "Writing battery stats before shutdown...");
-        synchronized (mStats) {
-            mStats.shutdownLocked();
-        }
-    }
-    
-    public static IBatteryStats getService() {
-        if (sService != null) {
-            return sService;
-        }
-        IBinder b = ServiceManager.getService(BatteryStats.SERVICE_NAME);
-        sService = asInterface(b);
-        return sService;
-    }
-    
-    /**
-     * @return the current statistics object, which may be modified
-     * to reflect events that affect battery usage.  You must lock the
-     * stats object before doing anything with it.
-     */
-    public BatteryStatsImpl getActiveStatistics() {
-        return mStats;
-    }
-    
-    public byte[] getStatistics() {
-        mContext.enforceCallingPermission(
-                android.Manifest.permission.BATTERY_STATS, null);
-        //Slog.i("foo", "SENDING BATTERY INFO:");
-        //mStats.dumpLocked(new LogPrinter(Log.INFO, "foo", Log.LOG_ID_SYSTEM));
-        Parcel out = Parcel.obtain();
-        mStats.writeToParcel(out, 0);
-        byte[] data = out.marshall();
-        out.recycle();
-        return data;
-    }
-    
-    public void noteStartWakelock(int uid, int pid, String name, int type) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStartWakeLocked(uid, pid, name, type);
-        }
-    }
-
-    public void noteStopWakelock(int uid, int pid, String name, int type) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStopWakeLocked(uid, pid, name, type);
-        }
-    }
-
-    public void noteStartWakelockFromSource(WorkSource ws, int pid, String name, int type) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStartWakeFromSourceLocked(ws, pid, name, type);
-        }
-    }
-
-    public void noteStopWakelockFromSource(WorkSource ws, int pid, String name, int type) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStopWakeFromSourceLocked(ws, pid, name, type);
-        }
-    }
-
-    public void noteStartSensor(int uid, int sensor) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStartSensorLocked(uid, sensor);
-        }
-    }
-    
-    public void noteStopSensor(int uid, int sensor) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStopSensorLocked(uid, sensor);
-        }
-    }
-    
-    public void noteVibratorOn(int uid, long durationMillis) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteVibratorOnLocked(uid, durationMillis);
-        }
-    }
-
-    public void noteVibratorOff(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteVibratorOffLocked(uid);
-        }
-    }
-
-    public void noteStartGps(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStartGpsLocked(uid);
-        }
-    }
-    
-    public void noteStopGps(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteStopGpsLocked(uid);
-        }
-    }
-        
-    public void noteScreenOn() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteScreenOnLocked();
-        }
-    }
-    
-    public void noteScreenBrightness(int brightness) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteScreenBrightnessLocked(brightness);
-        }
-    }
-    
-    public void noteScreenOff() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteScreenOffLocked();
-        }
-    }
-
-    public void noteInputEvent() {
-        enforceCallingPermission();
-        mStats.noteInputEventAtomic();
-    }
-    
-    public void noteUserActivity(int uid, int event) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteUserActivityLocked(uid, event);
-        }
-    }
-    
-    public void notePhoneOn() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.notePhoneOnLocked();
-        }
-    }
-    
-    public void notePhoneOff() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.notePhoneOffLocked();
-        }
-    }
-    
-    public void notePhoneSignalStrength(SignalStrength signalStrength) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.notePhoneSignalStrengthLocked(signalStrength);
-        }
-    }
-    
-    public void notePhoneDataConnectionState(int dataType, boolean hasData) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.notePhoneDataConnectionStateLocked(dataType, hasData);
-        }
-    }
-
-    public void notePhoneState(int state) {
-        enforceCallingPermission();
-        int simState = TelephonyManager.getDefault().getSimState();
-        synchronized (mStats) {
-            mStats.notePhoneStateLocked(state, simState);
-        }
-    }
-
-    public void noteWifiOn() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiOnLocked();
-        }
-    }
-    
-    public void noteWifiOff() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiOffLocked();
-        }
-    }
-
-    public void noteStartAudio(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteAudioOnLocked(uid);
-        }
-    }
-
-    public void noteStopAudio(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteAudioOffLocked(uid);
-        }
-    }
-
-    public void noteStartVideo(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteVideoOnLocked(uid);
-        }
-    }
-
-    public void noteStopVideo(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteVideoOffLocked(uid);
-        }
-    }
-
-    public void noteWifiRunning(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiRunningLocked(ws);
-        }
-    }
-
-    public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiRunningChangedLocked(oldWs, newWs);
-        }
-    }
-
-    public void noteWifiStopped(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiStoppedLocked(ws);
-        }
-    }
-
-    public void noteBluetoothOn() {
-        enforceCallingPermission();
-        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
-        if (adapter != null) {
-            adapter.getProfileProxy(mContext, mBluetoothProfileServiceListener,
-                                    BluetoothProfile.HEADSET);
-        }
-        synchronized (mStats) {
-            if (mBluetoothHeadset != null) {
-                mStats.noteBluetoothOnLocked();
-                mStats.setBtHeadset(mBluetoothHeadset);
-            } else {
-                mBluetoothPendingStats = true;
-            }
-        }
-    }
-
-    private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
-        new BluetoothProfile.ServiceListener() {
-        public void onServiceConnected(int profile, BluetoothProfile proxy) {
-            mBluetoothHeadset = (BluetoothHeadset) proxy;
-            synchronized (mStats) {
-                if (mBluetoothPendingStats) {
-                    mStats.noteBluetoothOnLocked();
-                    mStats.setBtHeadset(mBluetoothHeadset);
-                    mBluetoothPendingStats = false;
-                }
-            }
-        }
-
-        public void onServiceDisconnected(int profile) {
-            mBluetoothHeadset = null;
-        }
-    };
-
-    public void noteBluetoothOff() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mBluetoothPendingStats = false;
-            mStats.noteBluetoothOffLocked();
-        }
-    }
-    
-    public void noteFullWifiLockAcquired(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteFullWifiLockAcquiredLocked(uid);
-        }
-    }
-    
-    public void noteFullWifiLockReleased(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteFullWifiLockReleasedLocked(uid);
-        }
-    }
-
-    public void noteWifiScanStarted(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiScanStartedLocked(uid);
-        }
-    }
-
-    public void noteWifiScanStopped(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiScanStoppedLocked(uid);
-        }
-    }
-
-    public void noteWifiMulticastEnabled(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiMulticastEnabledLocked(uid);
-        }
-    }
-
-    public void noteWifiMulticastDisabled(int uid) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiMulticastDisabledLocked(uid);
-        }
-    }
-
-    public void noteFullWifiLockAcquiredFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteFullWifiLockAcquiredFromSourceLocked(ws);
-        }
-    }
-
-    public void noteFullWifiLockReleasedFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteFullWifiLockReleasedFromSourceLocked(ws);
-        }
-    }
-
-    public void noteWifiScanStartedFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiScanStartedFromSourceLocked(ws);
-        }
-    }
-
-    public void noteWifiScanStoppedFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiScanStoppedFromSourceLocked(ws);
-        }
-    }
-
-    public void noteWifiBatchedScanStartedFromSource(WorkSource ws, int csph) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiBatchedScanStartedFromSourceLocked(ws, csph);
-        }
-    }
-
-    public void noteWifiBatchedScanStoppedFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiBatchedScanStoppedFromSourceLocked(ws);
-        }
-    }
-
-    public void noteWifiMulticastEnabledFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiMulticastEnabledFromSourceLocked(ws);
-        }
-    }
-
-    public void noteWifiMulticastDisabledFromSource(WorkSource ws) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteWifiMulticastDisabledFromSourceLocked(ws);
-        }
-    }
-
-    @Override
-    public void noteNetworkInterfaceType(String iface, int type) {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteNetworkInterfaceTypeLocked(iface, type);
-        }
-    }
-
-    @Override
-    public void noteNetworkStatsEnabled() {
-        enforceCallingPermission();
-        synchronized (mStats) {
-            mStats.noteNetworkStatsEnabledLocked();
-        }
-    }
-
-    public boolean isOnBattery() {
-        return mStats.isOnBattery();
-    }
-    
-    public void setBatteryState(int status, int health, int plugType, int level,
-            int temp, int volt) {
-        enforceCallingPermission();
-        mStats.setBatteryState(status, health, plugType, level, temp, volt);
-    }
-    
-    public long getAwakeTimeBattery() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.BATTERY_STATS, null);
-        return mStats.getAwakeTimeBattery();
-    }
-
-    public long getAwakeTimePlugged() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.BATTERY_STATS, null);
-        return mStats.getAwakeTimePlugged();
-    }
-
-    public void enforceCallingPermission() {
-        if (Binder.getCallingPid() == Process.myPid()) {
-            return;
-        }
-        mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-    }
-    
-    private void dumpHelp(PrintWriter pw) {
-        pw.println("Battery stats (batterystats) dump options:");
-        pw.println("  [--checkin] [-c] [--unplugged] [--reset] [--write] [-h] [<package.name>]");
-        pw.println("  --checkin: format output for a checkin report.");
-        pw.println("  --unplugged: only output data since last unplugged.");
-        pw.println("  --reset: reset the stats, clearing all current data.");
-        pw.println("  --write: force write current collected stats to disk.");
-        pw.println("  -h: print this help text.");
-        pw.println("  <package.name>: optional name of package to filter output by.");
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump BatteryStats from from pid="
-                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
-                    + " without permission " + android.Manifest.permission.DUMP);
-            return;
-        }
-
-        boolean isCheckin = false;
-        boolean includeHistory = false;
-        boolean isUnpluggedOnly = false;
-        boolean noOutput = false;
-        int reqUid = -1;
-        if (args != null) {
-            for (String arg : args) {
-                if ("--checkin".equals(arg)) {
-                    isCheckin = true;
-                } else if ("-c".equals(arg)) {
-                    isCheckin = true;
-                    includeHistory = true;
-                } else if ("--unplugged".equals(arg)) {
-                    isUnpluggedOnly = true;
-                } else if ("--reset".equals(arg)) {
-                    synchronized (mStats) {
-                        mStats.resetAllStatsLocked();
-                        pw.println("Battery stats reset.");
-                        noOutput = true;
-                    }
-                } else if ("--write".equals(arg)) {
-                    synchronized (mStats) {
-                        mStats.writeSyncLocked();
-                        pw.println("Battery stats written.");
-                        noOutput = true;
-                    }
-                } else if ("-h".equals(arg)) {
-                    dumpHelp(pw);
-                    return;
-                } else if ("-a".equals(arg)) {
-                    // fall through
-                } else if (arg.length() > 0 && arg.charAt(0) == '-'){
-                    pw.println("Unknown option: " + arg);
-                    dumpHelp(pw);
-                    return;
-                } else {
-                    // Not an option, last argument must be a package name.
-                    try {
-                        reqUid = mContext.getPackageManager().getPackageUid(arg,
-                                UserHandle.getCallingUserId());
-                    } catch (PackageManager.NameNotFoundException e) {
-                        pw.println("Unknown package: " + arg);
-                        dumpHelp(pw);
-                        return;
-                    }
-                }
-            }
-        }
-        if (noOutput) {
-            return;
-        }
-        if (isCheckin) {
-            List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0);
-            synchronized (mStats) {
-                mStats.dumpCheckinLocked(pw, apps, isUnpluggedOnly, includeHistory);
-            }
-        } else {
-            synchronized (mStats) {
-                mStats.dumpLocked(pw, isUnpluggedOnly, reqUid);
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/am/BroadcastQueue.java b/services/java/com/android/server/am/BroadcastQueue.java
deleted file mode 100644
index bfb667f..0000000
--- a/services/java/com/android/server/am/BroadcastQueue.java
+++ /dev/null
@@ -1,1219 +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.server.am;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-import android.app.ActivityManager;
-import android.app.AppGlobals;
-import android.app.AppOpsManager;
-import android.content.ComponentName;
-import android.content.IIntentReceiver;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Slog;
-
-/**
- * BROADCASTS
- *
- * We keep two broadcast queues and associated bookkeeping, one for those at
- * foreground priority, and one for normal (background-priority) broadcasts.
- */
-public final class BroadcastQueue {
-    static final String TAG = "BroadcastQueue";
-    static final String TAG_MU = ActivityManagerService.TAG_MU;
-    static final boolean DEBUG_BROADCAST = ActivityManagerService.DEBUG_BROADCAST;
-    static final boolean DEBUG_BROADCAST_LIGHT = ActivityManagerService.DEBUG_BROADCAST_LIGHT;
-    static final boolean DEBUG_MU = ActivityManagerService.DEBUG_MU;
-
-    static final int MAX_BROADCAST_HISTORY = ActivityManager.isLowRamDeviceStatic() ? 10 : 50;
-    static final int MAX_BROADCAST_SUMMARY_HISTORY
-            = ActivityManager.isLowRamDeviceStatic() ? 25 : 300;
-
-    final ActivityManagerService mService;
-
-    /**
-     * Recognizable moniker for this queue
-     */
-    final String mQueueName;
-
-    /**
-     * Timeout period for this queue's broadcasts
-     */
-    final long mTimeoutPeriod;
-
-    /**
-     * If true, we can delay broadcasts while waiting services to finish in the previous
-     * receiver's process.
-     */
-    final boolean mDelayBehindServices;
-
-    /**
-     * Lists of all active broadcasts that are to be executed immediately
-     * (without waiting for another broadcast to finish).  Currently this only
-     * contains broadcasts to registered receivers, to avoid spinning up
-     * a bunch of processes to execute IntentReceiver components.  Background-
-     * and foreground-priority broadcasts are queued separately.
-     */
-    final ArrayList<BroadcastRecord> mParallelBroadcasts = new ArrayList<BroadcastRecord>();
-
-    /**
-     * List of all active broadcasts that are to be executed one at a time.
-     * The object at the top of the list is the currently activity broadcasts;
-     * those after it are waiting for the top to finish.  As with parallel
-     * broadcasts, separate background- and foreground-priority queues are
-     * maintained.
-     */
-    final ArrayList<BroadcastRecord> mOrderedBroadcasts = new ArrayList<BroadcastRecord>();
-
-    /**
-     * Historical data of past broadcasts, for debugging.
-     */
-    final BroadcastRecord[] mBroadcastHistory = new BroadcastRecord[MAX_BROADCAST_HISTORY];
-
-    /**
-     * Summary of historical data of past broadcasts, for debugging.
-     */
-    final Intent[] mBroadcastSummaryHistory = new Intent[MAX_BROADCAST_SUMMARY_HISTORY];
-
-    /**
-     * Set when we current have a BROADCAST_INTENT_MSG in flight.
-     */
-    boolean mBroadcastsScheduled = false;
-
-    /**
-     * True if we have a pending unexpired BROADCAST_TIMEOUT_MSG posted to our handler.
-     */
-    boolean mPendingBroadcastTimeoutMessage;
-
-    /**
-     * Intent broadcasts that we have tried to start, but are
-     * waiting for the application's process to be created.  We only
-     * need one per scheduling class (instead of a list) because we always
-     * process broadcasts one at a time, so no others can be started while
-     * waiting for this one.
-     */
-    BroadcastRecord mPendingBroadcast = null;
-
-    /**
-     * The receiver index that is pending, to restart the broadcast if needed.
-     */
-    int mPendingBroadcastRecvIndex;
-
-    static final int BROADCAST_INTENT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG;
-    static final int BROADCAST_TIMEOUT_MSG = ActivityManagerService.FIRST_BROADCAST_QUEUE_MSG + 1;
-
-    final Handler mHandler = new Handler() {
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case BROADCAST_INTENT_MSG: {
-                    if (DEBUG_BROADCAST) Slog.v(
-                            TAG, "Received BROADCAST_INTENT_MSG");
-                    processNextBroadcast(true);
-                } break;
-                case BROADCAST_TIMEOUT_MSG: {
-                    synchronized (mService) {
-                        broadcastTimeoutLocked(true);
-                    }
-                } break;
-            }
-        }
-    };
-
-    private final class AppNotResponding implements Runnable {
-        private final ProcessRecord mApp;
-        private final String mAnnotation;
-
-        public AppNotResponding(ProcessRecord app, String annotation) {
-            mApp = app;
-            mAnnotation = annotation;
-        }
-
-        @Override
-        public void run() {
-            mService.appNotResponding(mApp, null, null, false, mAnnotation);
-        }
-    }
-
-    BroadcastQueue(ActivityManagerService service, String name, long timeoutPeriod,
-            boolean allowDelayBehindServices) {
-        mService = service;
-        mQueueName = name;
-        mTimeoutPeriod = timeoutPeriod;
-        mDelayBehindServices = allowDelayBehindServices;
-    }
-
-    public boolean isPendingBroadcastProcessLocked(int pid) {
-        return mPendingBroadcast != null && mPendingBroadcast.curApp.pid == pid;
-    }
-
-    public void enqueueParallelBroadcastLocked(BroadcastRecord r) {
-        mParallelBroadcasts.add(r);
-    }
-
-    public void enqueueOrderedBroadcastLocked(BroadcastRecord r) {
-        mOrderedBroadcasts.add(r);
-    }
-
-    public final boolean replaceParallelBroadcastLocked(BroadcastRecord r) {
-        for (int i=mParallelBroadcasts.size()-1; i>=0; i--) {
-            if (r.intent.filterEquals(mParallelBroadcasts.get(i).intent)) {
-                if (DEBUG_BROADCAST) Slog.v(TAG,
-                        "***** DROPPING PARALLEL ["
-                + mQueueName + "]: " + r.intent);
-                mParallelBroadcasts.set(i, r);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public final boolean replaceOrderedBroadcastLocked(BroadcastRecord r) {
-        for (int i=mOrderedBroadcasts.size()-1; i>0; i--) {
-            if (r.intent.filterEquals(mOrderedBroadcasts.get(i).intent)) {
-                if (DEBUG_BROADCAST) Slog.v(TAG,
-                        "***** DROPPING ORDERED ["
-                        + mQueueName + "]: " + r.intent);
-                mOrderedBroadcasts.set(i, r);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private final void processCurBroadcastLocked(BroadcastRecord r,
-            ProcessRecord app) throws RemoteException {
-        if (DEBUG_BROADCAST)  Slog.v(TAG,
-                "Process cur broadcast " + r + " for app " + app);
-        if (app.thread == null) {
-            throw new RemoteException();
-        }
-        r.receiver = app.thread.asBinder();
-        r.curApp = app;
-        app.curReceiver = r;
-        app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER);
-        mService.updateLruProcessLocked(app, false, null);
-        mService.updateOomAdjLocked();
-
-        // Tell the application to launch this receiver.
-        r.intent.setComponent(r.curComponent);
-
-        boolean started = false;
-        try {
-            if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG,
-                    "Delivering to component " + r.curComponent
-                    + ": " + r);
-            mService.ensurePackageDexOpt(r.intent.getComponent().getPackageName());
-            app.thread.scheduleReceiver(new Intent(r.intent), r.curReceiver,
-                    mService.compatibilityInfoForPackageLocked(r.curReceiver.applicationInfo),
-                    r.resultCode, r.resultData, r.resultExtras, r.ordered, r.userId,
-                    app.repProcState);
-            if (DEBUG_BROADCAST)  Slog.v(TAG,
-                    "Process cur broadcast " + r + " DELIVERED for app " + app);
-            started = true;
-        } finally {
-            if (!started) {
-                if (DEBUG_BROADCAST)  Slog.v(TAG,
-                        "Process cur broadcast " + r + ": NOT STARTED!");
-                r.receiver = null;
-                r.curApp = null;
-                app.curReceiver = null;
-            }
-        }
-    }
-
-    public boolean sendPendingBroadcastsLocked(ProcessRecord app) {
-        boolean didSomething = false;
-        final BroadcastRecord br = mPendingBroadcast;
-        if (br != null && br.curApp.pid == app.pid) {
-            try {
-                mPendingBroadcast = null;
-                processCurBroadcastLocked(br, app);
-                didSomething = true;
-            } catch (Exception e) {
-                Slog.w(TAG, "Exception in new application when starting receiver "
-                        + br.curComponent.flattenToShortString(), e);
-                logBroadcastReceiverDiscardLocked(br);
-                finishReceiverLocked(br, br.resultCode, br.resultData,
-                        br.resultExtras, br.resultAbort, false);
-                scheduleBroadcastsLocked();
-                // We need to reset the state if we failed to start the receiver.
-                br.state = BroadcastRecord.IDLE;
-                throw new RuntimeException(e.getMessage());
-            }
-        }
-        return didSomething;
-    }
-
-    public void skipPendingBroadcastLocked(int pid) {
-        final BroadcastRecord br = mPendingBroadcast;
-        if (br != null && br.curApp.pid == pid) {
-            br.state = BroadcastRecord.IDLE;
-            br.nextReceiver = mPendingBroadcastRecvIndex;
-            mPendingBroadcast = null;
-            scheduleBroadcastsLocked();
-        }
-    }
-
-    public void skipCurrentReceiverLocked(ProcessRecord app) {
-        boolean reschedule = false;
-        BroadcastRecord r = app.curReceiver;
-        if (r != null) {
-            // The current broadcast is waiting for this app's receiver
-            // to be finished.  Looks like that's not going to happen, so
-            // let the broadcast continue.
-            logBroadcastReceiverDiscardLocked(r);
-            finishReceiverLocked(r, r.resultCode, r.resultData,
-                    r.resultExtras, r.resultAbort, false);
-            reschedule = true;
-        }
-
-        r = mPendingBroadcast;
-        if (r != null && r.curApp == app) {
-            if (DEBUG_BROADCAST) Slog.v(TAG,
-                    "[" + mQueueName + "] skip & discard pending app " + r);
-            logBroadcastReceiverDiscardLocked(r);
-            finishReceiverLocked(r, r.resultCode, r.resultData,
-                    r.resultExtras, r.resultAbort, false);
-            reschedule = true;
-        }
-        if (reschedule) {
-            scheduleBroadcastsLocked();
-        }
-    }
-
-    public void scheduleBroadcastsLocked() {
-        if (DEBUG_BROADCAST) Slog.v(TAG, "Schedule broadcasts ["
-                + mQueueName + "]: current="
-                + mBroadcastsScheduled);
-
-        if (mBroadcastsScheduled) {
-            return;
-        }
-        mHandler.sendMessage(mHandler.obtainMessage(BROADCAST_INTENT_MSG, this));
-        mBroadcastsScheduled = true;
-    }
-
-    public BroadcastRecord getMatchingOrderedReceiver(IBinder receiver) {
-        if (mOrderedBroadcasts.size() > 0) {
-            final BroadcastRecord r = mOrderedBroadcasts.get(0);
-            if (r != null && r.receiver == receiver) {
-                return r;
-            }
-        }
-        return null;
-    }
-
-    public boolean finishReceiverLocked(BroadcastRecord r, int resultCode,
-            String resultData, Bundle resultExtras, boolean resultAbort, boolean waitForServices) {
-        final int state = r.state;
-        final ActivityInfo receiver = r.curReceiver;
-        r.state = BroadcastRecord.IDLE;
-        if (state == BroadcastRecord.IDLE) {
-            Slog.w(TAG, "finishReceiver [" + mQueueName + "] called but state is IDLE");
-        }
-        r.receiver = null;
-        r.intent.setComponent(null);
-        if (r.curApp != null) {
-            r.curApp.curReceiver = null;
-        }
-        if (r.curFilter != null) {
-            r.curFilter.receiverList.curBroadcast = null;
-        }
-        r.curFilter = null;
-        r.curReceiver = null;
-        r.curApp = null;
-        mPendingBroadcast = null;
-
-        r.resultCode = resultCode;
-        r.resultData = resultData;
-        r.resultExtras = resultExtras;
-        if (resultAbort && (r.intent.getFlags()&Intent.FLAG_RECEIVER_NO_ABORT) == 0) {
-            r.resultAbort = resultAbort;
-        } else {
-            r.resultAbort = false;
-        }
-
-        if (waitForServices && r.curComponent != null && r.queue.mDelayBehindServices
-                && r.queue.mOrderedBroadcasts.size() > 0
-                && r.queue.mOrderedBroadcasts.get(0) == r) {
-            ActivityInfo nextReceiver;
-            if (r.nextReceiver < r.receivers.size()) {
-                Object obj = r.receivers.get(r.nextReceiver);
-                nextReceiver = (obj instanceof ActivityInfo) ? (ActivityInfo)obj : null;
-            } else {
-                nextReceiver = null;
-            }
-            // Don't do this if the next receive is in the same process as the current one.
-            if (receiver == null || nextReceiver == null
-                    || receiver.applicationInfo.uid != nextReceiver.applicationInfo.uid
-                    || !receiver.processName.equals(nextReceiver.processName)) {
-                // In this case, we are ready to process the next receiver for the current broadcast,
-                // but are on a queue that would like to wait for services to finish before moving
-                // on.  If there are background services currently starting, then we will go into a
-                // special state where we hold off on continuing this broadcast until they are done.
-                if (mService.mServices.hasBackgroundServices(r.userId)) {
-                    Slog.i(ActivityManagerService.TAG, "Delay finish: "
-                            + r.curComponent.flattenToShortString());
-                    r.state = BroadcastRecord.WAITING_SERVICES;
-                    return false;
-                }
-            }
-        }
-
-        r.curComponent = null;
-
-        // We will process the next receiver right now if this is finishing
-        // an app receiver (which is always asynchronous) or after we have
-        // come back from calling a receiver.
-        return state == BroadcastRecord.APP_RECEIVE
-                || state == BroadcastRecord.CALL_DONE_RECEIVE;
-    }
-
-    public void backgroundServicesFinishedLocked(int userId) {
-        if (mOrderedBroadcasts.size() > 0) {
-            BroadcastRecord br = mOrderedBroadcasts.get(0);
-            if (br.userId == userId && br.state == BroadcastRecord.WAITING_SERVICES) {
-                Slog.i(ActivityManagerService.TAG, "Resuming delayed broadcast");
-                br.curComponent = null;
-                br.state = BroadcastRecord.IDLE;
-                processNextBroadcast(false);
-            }
-        }
-    }
-
-    private static void performReceiveLocked(ProcessRecord app, IIntentReceiver receiver,
-            Intent intent, int resultCode, String data, Bundle extras,
-            boolean ordered, boolean sticky, int sendingUser) throws RemoteException {
-        // Send the intent to the receiver asynchronously using one-way binder calls.
-        if (app != null && app.thread != null) {
-            // If we have an app thread, do the call through that so it is
-            // correctly ordered with other one-way calls.
-            app.thread.scheduleRegisteredReceiver(receiver, intent, resultCode,
-                    data, extras, ordered, sticky, sendingUser, app.repProcState);
-        } else {
-            receiver.performReceive(intent, resultCode, data, extras, ordered,
-                    sticky, sendingUser);
-        }
-    }
-
-    private final void deliverToRegisteredReceiverLocked(BroadcastRecord r,
-            BroadcastFilter filter, boolean ordered) {
-        boolean skip = false;
-        if (filter.requiredPermission != null) {
-            int perm = mService.checkComponentPermission(filter.requiredPermission,
-                    r.callingPid, r.callingUid, -1, true);
-            if (perm != PackageManager.PERMISSION_GRANTED) {
-                Slog.w(TAG, "Permission Denial: broadcasting "
-                        + r.intent.toString()
-                        + " from " + r.callerPackage + " (pid="
-                        + r.callingPid + ", uid=" + r.callingUid + ")"
-                        + " requires " + filter.requiredPermission
-                        + " due to registered receiver " + filter);
-                skip = true;
-            }
-        }
-        if (!skip && r.requiredPermission != null) {
-            int perm = mService.checkComponentPermission(r.requiredPermission,
-                    filter.receiverList.pid, filter.receiverList.uid, -1, true);
-            if (perm != PackageManager.PERMISSION_GRANTED) {
-                Slog.w(TAG, "Permission Denial: receiving "
-                        + r.intent.toString()
-                        + " to " + filter.receiverList.app
-                        + " (pid=" + filter.receiverList.pid
-                        + ", uid=" + filter.receiverList.uid + ")"
-                        + " requires " + r.requiredPermission
-                        + " due to sender " + r.callerPackage
-                        + " (uid " + r.callingUid + ")");
-                skip = true;
-            }
-        }
-        if (r.appOp != AppOpsManager.OP_NONE) {
-            int mode = mService.mAppOpsService.noteOperation(r.appOp,
-                    filter.receiverList.uid, filter.packageName);
-            if (mode != AppOpsManager.MODE_ALLOWED) {
-                if (DEBUG_BROADCAST)  Slog.v(TAG,
-                        "App op " + r.appOp + " not allowed for broadcast to uid "
-                        + filter.receiverList.uid + " pkg " + filter.packageName);
-                skip = true;
-            }
-        }
-        if (!skip) {
-            skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid,
-                    r.callingPid, r.resolvedType, filter.receiverList.uid);
-        }
-
-        if (filter.receiverList.app == null || filter.receiverList.app.crashing) {
-            Slog.w(TAG, "Skipping deliver [" + mQueueName + "] " + r
-                    + " to " + filter.receiverList + ": process crashing");
-            skip = true;
-        }
-
-        if (!skip) {
-            // If this is not being sent as an ordered broadcast, then we
-            // don't want to touch the fields that keep track of the current
-            // state of ordered broadcasts.
-            if (ordered) {
-                r.receiver = filter.receiverList.receiver.asBinder();
-                r.curFilter = filter;
-                filter.receiverList.curBroadcast = r;
-                r.state = BroadcastRecord.CALL_IN_RECEIVE;
-                if (filter.receiverList.app != null) {
-                    // Bump hosting application to no longer be in background
-                    // scheduling class.  Note that we can't do that if there
-                    // isn't an app...  but we can only be in that case for
-                    // things that directly call the IActivityManager API, which
-                    // are already core system stuff so don't matter for this.
-                    r.curApp = filter.receiverList.app;
-                    filter.receiverList.app.curReceiver = r;
-                    mService.updateOomAdjLocked(r.curApp, true);
-                }
-            }
-            try {
-                if (DEBUG_BROADCAST_LIGHT) {
-                    int seq = r.intent.getIntExtra("seq", -1);
-                    Slog.i(TAG, "Delivering to " + filter
-                            + " (seq=" + seq + "): " + r);
-                }
-                performReceiveLocked(filter.receiverList.app, filter.receiverList.receiver,
-                    new Intent(r.intent), r.resultCode, r.resultData,
-                    r.resultExtras, r.ordered, r.initialSticky, r.userId);
-                if (ordered) {
-                    r.state = BroadcastRecord.CALL_DONE_RECEIVE;
-                }
-            } catch (RemoteException e) {
-                Slog.w(TAG, "Failure sending broadcast " + r.intent, e);
-                if (ordered) {
-                    r.receiver = null;
-                    r.curFilter = null;
-                    filter.receiverList.curBroadcast = null;
-                    if (filter.receiverList.app != null) {
-                        filter.receiverList.app.curReceiver = null;
-                    }
-                }
-            }
-        }
-    }
-
-    final void processNextBroadcast(boolean fromMsg) {
-        synchronized(mService) {
-            BroadcastRecord r;
-
-            if (DEBUG_BROADCAST) Slog.v(TAG, "processNextBroadcast ["
-                    + mQueueName + "]: "
-                    + mParallelBroadcasts.size() + " broadcasts, "
-                    + mOrderedBroadcasts.size() + " ordered broadcasts");
-
-            mService.updateCpuStats();
-
-            if (fromMsg) {
-                mBroadcastsScheduled = false;
-            }
-
-            // First, deliver any non-serialized broadcasts right away.
-            while (mParallelBroadcasts.size() > 0) {
-                r = mParallelBroadcasts.remove(0);
-                r.dispatchTime = SystemClock.uptimeMillis();
-                r.dispatchClockTime = System.currentTimeMillis();
-                final int N = r.receivers.size();
-                if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing parallel broadcast ["
-                        + mQueueName + "] " + r);
-                for (int i=0; i<N; i++) {
-                    Object target = r.receivers.get(i);
-                    if (DEBUG_BROADCAST)  Slog.v(TAG,
-                            "Delivering non-ordered on [" + mQueueName + "] to registered "
-                            + target + ": " + r);
-                    deliverToRegisteredReceiverLocked(r, (BroadcastFilter)target, false);
-                }
-                addBroadcastToHistoryLocked(r);
-                if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Done with parallel broadcast ["
-                        + mQueueName + "] " + r);
-            }
-
-            // Now take care of the next serialized one...
-
-            // If we are waiting for a process to come up to handle the next
-            // broadcast, then do nothing at this point.  Just in case, we
-            // check that the process we're waiting for still exists.
-            if (mPendingBroadcast != null) {
-                if (DEBUG_BROADCAST_LIGHT) {
-                    Slog.v(TAG, "processNextBroadcast ["
-                            + mQueueName + "]: waiting for "
-                            + mPendingBroadcast.curApp);
-                }
-
-                boolean isDead;
-                synchronized (mService.mPidsSelfLocked) {
-                    ProcessRecord proc = mService.mPidsSelfLocked.get(mPendingBroadcast.curApp.pid);
-                    isDead = proc == null || proc.crashing;
-                }
-                if (!isDead) {
-                    // It's still alive, so keep waiting
-                    return;
-                } else {
-                    Slog.w(TAG, "pending app  ["
-                            + mQueueName + "]" + mPendingBroadcast.curApp
-                            + " died before responding to broadcast");
-                    mPendingBroadcast.state = BroadcastRecord.IDLE;
-                    mPendingBroadcast.nextReceiver = mPendingBroadcastRecvIndex;
-                    mPendingBroadcast = null;
-                }
-            }
-
-            boolean looped = false;
-            
-            do {
-                if (mOrderedBroadcasts.size() == 0) {
-                    // No more broadcasts pending, so all done!
-                    mService.scheduleAppGcsLocked();
-                    if (looped) {
-                        // If we had finished the last ordered broadcast, then
-                        // make sure all processes have correct oom and sched
-                        // adjustments.
-                        mService.updateOomAdjLocked();
-                    }
-                    return;
-                }
-                r = mOrderedBroadcasts.get(0);
-                boolean forceReceive = false;
-
-                // Ensure that even if something goes awry with the timeout
-                // detection, we catch "hung" broadcasts here, discard them,
-                // and continue to make progress.
-                //
-                // This is only done if the system is ready so that PRE_BOOT_COMPLETED
-                // receivers don't get executed with timeouts. They're intended for
-                // one time heavy lifting after system upgrades and can take
-                // significant amounts of time.
-                int numReceivers = (r.receivers != null) ? r.receivers.size() : 0;
-                if (mService.mProcessesReady && r.dispatchTime > 0) {
-                    long now = SystemClock.uptimeMillis();
-                    if ((numReceivers > 0) &&
-                            (now > r.dispatchTime + (2*mTimeoutPeriod*numReceivers))) {
-                        Slog.w(TAG, "Hung broadcast ["
-                                + mQueueName + "] discarded after timeout failure:"
-                                + " now=" + now
-                                + " dispatchTime=" + r.dispatchTime
-                                + " startTime=" + r.receiverTime
-                                + " intent=" + r.intent
-                                + " numReceivers=" + numReceivers
-                                + " nextReceiver=" + r.nextReceiver
-                                + " state=" + r.state);
-                        broadcastTimeoutLocked(false); // forcibly finish this broadcast
-                        forceReceive = true;
-                        r.state = BroadcastRecord.IDLE;
-                    }
-                }
-
-                if (r.state != BroadcastRecord.IDLE) {
-                    if (DEBUG_BROADCAST) Slog.d(TAG,
-                            "processNextBroadcast("
-                            + mQueueName + ") called when not idle (state="
-                            + r.state + ")");
-                    return;
-                }
-
-                if (r.receivers == null || r.nextReceiver >= numReceivers
-                        || r.resultAbort || forceReceive) {
-                    // No more receivers for this broadcast!  Send the final
-                    // result if requested...
-                    if (r.resultTo != null) {
-                        try {
-                            if (DEBUG_BROADCAST) {
-                                int seq = r.intent.getIntExtra("seq", -1);
-                                Slog.i(TAG, "Finishing broadcast ["
-                                        + mQueueName + "] " + r.intent.getAction()
-                                        + " seq=" + seq + " app=" + r.callerApp);
-                            }
-                            performReceiveLocked(r.callerApp, r.resultTo,
-                                new Intent(r.intent), r.resultCode,
-                                r.resultData, r.resultExtras, false, false, r.userId);
-                            // Set this to null so that the reference
-                            // (local and remote) isn't kept in the mBroadcastHistory.
-                            r.resultTo = null;
-                        } catch (RemoteException e) {
-                            Slog.w(TAG, "Failure ["
-                                    + mQueueName + "] sending broadcast result of "
-                                    + r.intent, e);
-                        }
-                    }
-
-                    if (DEBUG_BROADCAST) Slog.v(TAG, "Cancelling BROADCAST_TIMEOUT_MSG");
-                    cancelBroadcastTimeoutLocked();
-
-                    if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Finished with ordered broadcast "
-                            + r);
-
-                    // ... and on to the next...
-                    addBroadcastToHistoryLocked(r);
-                    mOrderedBroadcasts.remove(0);
-                    r = null;
-                    looped = true;
-                    continue;
-                }
-            } while (r == null);
-
-            // Get the next receiver...
-            int recIdx = r.nextReceiver++;
-
-            // Keep track of when this receiver started, and make sure there
-            // is a timeout message pending to kill it if need be.
-            r.receiverTime = SystemClock.uptimeMillis();
-            if (recIdx == 0) {
-                r.dispatchTime = r.receiverTime;
-                r.dispatchClockTime = System.currentTimeMillis();
-                if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG, "Processing ordered broadcast ["
-                        + mQueueName + "] " + r);
-            }
-            if (! mPendingBroadcastTimeoutMessage) {
-                long timeoutTime = r.receiverTime + mTimeoutPeriod;
-                if (DEBUG_BROADCAST) Slog.v(TAG,
-                        "Submitting BROADCAST_TIMEOUT_MSG ["
-                        + mQueueName + "] for " + r + " at " + timeoutTime);
-                setBroadcastTimeoutLocked(timeoutTime);
-            }
-
-            Object nextReceiver = r.receivers.get(recIdx);
-            if (nextReceiver instanceof BroadcastFilter) {
-                // Simple case: this is a registered receiver who gets
-                // a direct call.
-                BroadcastFilter filter = (BroadcastFilter)nextReceiver;
-                if (DEBUG_BROADCAST)  Slog.v(TAG,
-                        "Delivering ordered ["
-                        + mQueueName + "] to registered "
-                        + filter + ": " + r);
-                deliverToRegisteredReceiverLocked(r, filter, r.ordered);
-                if (r.receiver == null || !r.ordered) {
-                    // The receiver has already finished, so schedule to
-                    // process the next one.
-                    if (DEBUG_BROADCAST) Slog.v(TAG, "Quick finishing ["
-                            + mQueueName + "]: ordered="
-                            + r.ordered + " receiver=" + r.receiver);
-                    r.state = BroadcastRecord.IDLE;
-                    scheduleBroadcastsLocked();
-                }
-                return;
-            }
-
-            // Hard case: need to instantiate the receiver, possibly
-            // starting its application process to host it.
-
-            ResolveInfo info =
-                (ResolveInfo)nextReceiver;
-            ComponentName component = new ComponentName(
-                    info.activityInfo.applicationInfo.packageName,
-                    info.activityInfo.name);
-
-            boolean skip = false;
-            int perm = mService.checkComponentPermission(info.activityInfo.permission,
-                    r.callingPid, r.callingUid, info.activityInfo.applicationInfo.uid,
-                    info.activityInfo.exported);
-            if (perm != PackageManager.PERMISSION_GRANTED) {
-                if (!info.activityInfo.exported) {
-                    Slog.w(TAG, "Permission Denial: broadcasting "
-                            + r.intent.toString()
-                            + " from " + r.callerPackage + " (pid=" + r.callingPid
-                            + ", uid=" + r.callingUid + ")"
-                            + " is not exported from uid " + info.activityInfo.applicationInfo.uid
-                            + " due to receiver " + component.flattenToShortString());
-                } else {
-                    Slog.w(TAG, "Permission Denial: broadcasting "
-                            + r.intent.toString()
-                            + " from " + r.callerPackage + " (pid=" + r.callingPid
-                            + ", uid=" + r.callingUid + ")"
-                            + " requires " + info.activityInfo.permission
-                            + " due to receiver " + component.flattenToShortString());
-                }
-                skip = true;
-            }
-            if (info.activityInfo.applicationInfo.uid != Process.SYSTEM_UID &&
-                r.requiredPermission != null) {
-                try {
-                    perm = AppGlobals.getPackageManager().
-                            checkPermission(r.requiredPermission,
-                                    info.activityInfo.applicationInfo.packageName);
-                } catch (RemoteException e) {
-                    perm = PackageManager.PERMISSION_DENIED;
-                }
-                if (perm != PackageManager.PERMISSION_GRANTED) {
-                    Slog.w(TAG, "Permission Denial: receiving "
-                            + r.intent + " to "
-                            + component.flattenToShortString()
-                            + " requires " + r.requiredPermission
-                            + " due to sender " + r.callerPackage
-                            + " (uid " + r.callingUid + ")");
-                    skip = true;
-                }
-            }
-            if (r.appOp != AppOpsManager.OP_NONE) {
-                int mode = mService.mAppOpsService.noteOperation(r.appOp,
-                        info.activityInfo.applicationInfo.uid, info.activityInfo.packageName);
-                if (mode != AppOpsManager.MODE_ALLOWED) {
-                    if (DEBUG_BROADCAST)  Slog.v(TAG,
-                            "App op " + r.appOp + " not allowed for broadcast to uid "
-                            + info.activityInfo.applicationInfo.uid + " pkg "
-                            + info.activityInfo.packageName);
-                    skip = true;
-                }
-            }
-            if (!skip) {
-                skip = !mService.mIntentFirewall.checkBroadcast(r.intent, r.callingUid,
-                        r.callingPid, r.resolvedType, info.activityInfo.applicationInfo.uid);
-            }
-            boolean isSingleton = false;
-            try {
-                isSingleton = mService.isSingleton(info.activityInfo.processName,
-                        info.activityInfo.applicationInfo,
-                        info.activityInfo.name, info.activityInfo.flags);
-            } catch (SecurityException e) {
-                Slog.w(TAG, e.getMessage());
-                skip = true;
-            }
-            if ((info.activityInfo.flags&ActivityInfo.FLAG_SINGLE_USER) != 0) {
-                if (ActivityManager.checkUidPermission(
-                        android.Manifest.permission.INTERACT_ACROSS_USERS,
-                        info.activityInfo.applicationInfo.uid)
-                                != PackageManager.PERMISSION_GRANTED) {
-                    Slog.w(TAG, "Permission Denial: Receiver " + component.flattenToShortString()
-                            + " requests FLAG_SINGLE_USER, but app does not hold "
-                            + android.Manifest.permission.INTERACT_ACROSS_USERS);
-                    skip = true;
-                }
-            }
-            if (r.curApp != null && r.curApp.crashing) {
-                // If the target process is crashing, just skip it.
-                Slog.w(TAG, "Skipping deliver ordered [" + mQueueName + "] " + r
-                        + " to " + r.curApp + ": process crashing");
-                skip = true;
-            }
-            if (!skip) {
-                boolean isAvailable = false;
-                try {
-                    isAvailable = AppGlobals.getPackageManager().isPackageAvailable(
-                            info.activityInfo.packageName,
-                            UserHandle.getUserId(info.activityInfo.applicationInfo.uid));
-                } catch (Exception e) {
-                    // all such failures mean we skip this receiver
-                    Slog.w(TAG, "Exception getting recipient info for "
-                            + info.activityInfo.packageName, e);
-                }
-                if (!isAvailable) {
-                    if (DEBUG_BROADCAST) {
-                        Slog.v(TAG, "Skipping delivery to " + info.activityInfo.packageName
-                                + " / " + info.activityInfo.applicationInfo.uid
-                                + " : package no longer available");
-                    }
-                    skip = true;
-                }
-            }
-
-            if (skip) {
-                if (DEBUG_BROADCAST)  Slog.v(TAG,
-                        "Skipping delivery of ordered ["
-                        + mQueueName + "] " + r + " for whatever reason");
-                r.receiver = null;
-                r.curFilter = null;
-                r.state = BroadcastRecord.IDLE;
-                scheduleBroadcastsLocked();
-                return;
-            }
-
-            r.state = BroadcastRecord.APP_RECEIVE;
-            String targetProcess = info.activityInfo.processName;
-            r.curComponent = component;
-            if (r.callingUid != Process.SYSTEM_UID && isSingleton) {
-                info.activityInfo = mService.getActivityInfoForUser(info.activityInfo, 0);
-            }
-            r.curReceiver = info.activityInfo;
-            if (DEBUG_MU && r.callingUid > UserHandle.PER_USER_RANGE) {
-                Slog.v(TAG_MU, "Updated broadcast record activity info for secondary user, "
-                        + info.activityInfo + ", callingUid = " + r.callingUid + ", uid = "
-                        + info.activityInfo.applicationInfo.uid);
-            }
-
-            // Broadcast is being executed, its package can't be stopped.
-            try {
-                AppGlobals.getPackageManager().setPackageStoppedState(
-                        r.curComponent.getPackageName(), false, UserHandle.getUserId(r.callingUid));
-            } catch (RemoteException e) {
-            } catch (IllegalArgumentException e) {
-                Slog.w(TAG, "Failed trying to unstop package "
-                        + r.curComponent.getPackageName() + ": " + e);
-            }
-
-            // Is this receiver's application already running?
-            ProcessRecord app = mService.getProcessRecordLocked(targetProcess,
-                    info.activityInfo.applicationInfo.uid, false);
-            if (app != null && app.thread != null) {
-                try {
-                    app.addPackage(info.activityInfo.packageName, mService.mProcessStats);
-                    processCurBroadcastLocked(r, app);
-                    return;
-                } catch (RemoteException e) {
-                    Slog.w(TAG, "Exception when sending broadcast to "
-                          + r.curComponent, e);
-                } catch (RuntimeException e) {
-                    Log.wtf(TAG, "Failed sending broadcast to "
-                            + r.curComponent + " with " + r.intent, e);
-                    // If some unexpected exception happened, just skip
-                    // this broadcast.  At this point we are not in the call
-                    // from a client, so throwing an exception out from here
-                    // will crash the entire system instead of just whoever
-                    // sent the broadcast.
-                    logBroadcastReceiverDiscardLocked(r);
-                    finishReceiverLocked(r, r.resultCode, r.resultData,
-                            r.resultExtras, r.resultAbort, false);
-                    scheduleBroadcastsLocked();
-                    // We need to reset the state if we failed to start the receiver.
-                    r.state = BroadcastRecord.IDLE;
-                    return;
-                }
-
-                // If a dead object exception was thrown -- fall through to
-                // restart the application.
-            }
-
-            // Not running -- get it started, to be executed when the app comes up.
-            if (DEBUG_BROADCAST)  Slog.v(TAG,
-                    "Need to start app ["
-                    + mQueueName + "] " + targetProcess + " for broadcast " + r);
-            if ((r.curApp=mService.startProcessLocked(targetProcess,
-                    info.activityInfo.applicationInfo, true,
-                    r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND,
-                    "broadcast", r.curComponent,
-                    (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false))
-                            == null) {
-                // Ah, this recipient is unavailable.  Finish it if necessary,
-                // and mark the broadcast record as ready for the next.
-                Slog.w(TAG, "Unable to launch app "
-                        + info.activityInfo.applicationInfo.packageName + "/"
-                        + info.activityInfo.applicationInfo.uid + " for broadcast "
-                        + r.intent + ": process is bad");
-                logBroadcastReceiverDiscardLocked(r);
-                finishReceiverLocked(r, r.resultCode, r.resultData,
-                        r.resultExtras, r.resultAbort, false);
-                scheduleBroadcastsLocked();
-                r.state = BroadcastRecord.IDLE;
-                return;
-            }
-
-            mPendingBroadcast = r;
-            mPendingBroadcastRecvIndex = recIdx;
-        }
-    }
-
-    final void setBroadcastTimeoutLocked(long timeoutTime) {
-        if (! mPendingBroadcastTimeoutMessage) {
-            Message msg = mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG, this);
-            mHandler.sendMessageAtTime(msg, timeoutTime);
-            mPendingBroadcastTimeoutMessage = true;
-        }
-    }
-
-    final void cancelBroadcastTimeoutLocked() {
-        if (mPendingBroadcastTimeoutMessage) {
-            mHandler.removeMessages(BROADCAST_TIMEOUT_MSG, this);
-            mPendingBroadcastTimeoutMessage = false;
-        }
-    }
-
-    final void broadcastTimeoutLocked(boolean fromMsg) {
-        if (fromMsg) {
-            mPendingBroadcastTimeoutMessage = false;
-        }
-
-        if (mOrderedBroadcasts.size() == 0) {
-            return;
-        }
-
-        long now = SystemClock.uptimeMillis();
-        BroadcastRecord r = mOrderedBroadcasts.get(0);
-        if (fromMsg) {
-            if (mService.mDidDexOpt) {
-                // Delay timeouts until dexopt finishes.
-                mService.mDidDexOpt = false;
-                long timeoutTime = SystemClock.uptimeMillis() + mTimeoutPeriod;
-                setBroadcastTimeoutLocked(timeoutTime);
-                return;
-            }
-            if (!mService.mProcessesReady) {
-                // Only process broadcast timeouts if the system is ready. That way
-                // PRE_BOOT_COMPLETED broadcasts can't timeout as they are intended
-                // to do heavy lifting for system up.
-                return;
-            }
-
-            long timeoutTime = r.receiverTime + mTimeoutPeriod;
-            if (timeoutTime > now) {
-                // We can observe premature timeouts because we do not cancel and reset the
-                // broadcast timeout message after each receiver finishes.  Instead, we set up
-                // an initial timeout then kick it down the road a little further as needed
-                // when it expires.
-                if (DEBUG_BROADCAST) Slog.v(TAG,
-                        "Premature timeout ["
-                        + mQueueName + "] @ " + now + ": resetting BROADCAST_TIMEOUT_MSG for "
-                        + timeoutTime);
-                setBroadcastTimeoutLocked(timeoutTime);
-                return;
-            }
-        }
-
-        BroadcastRecord br = mOrderedBroadcasts.get(0);
-        if (br.state == BroadcastRecord.WAITING_SERVICES) {
-            // In this case the broadcast had already finished, but we had decided to wait
-            // for started services to finish as well before going on.  So if we have actually
-            // waited long enough time timeout the broadcast, let's give up on the whole thing
-            // and just move on to the next.
-            Slog.i(ActivityManagerService.TAG, "Waited long enough for: " + (br.curComponent != null
-                    ? br.curComponent.flattenToShortString() : "(null)"));
-            br.curComponent = null;
-            br.state = BroadcastRecord.IDLE;
-            processNextBroadcast(false);
-            return;
-        }
-
-        Slog.w(TAG, "Timeout of broadcast " + r + " - receiver=" + r. receiver
-                + ", started " + (now - r.receiverTime) + "ms ago");
-        r.receiverTime = now;
-        r.anrCount++;
-
-        // Current receiver has passed its expiration date.
-        if (r.nextReceiver <= 0) {
-            Slog.w(TAG, "Timeout on receiver with nextReceiver <= 0");
-            return;
-        }
-
-        ProcessRecord app = null;
-        String anrMessage = null;
-
-        Object curReceiver = r.receivers.get(r.nextReceiver-1);
-        Slog.w(TAG, "Receiver during timeout: " + curReceiver);
-        logBroadcastReceiverDiscardLocked(r);
-        if (curReceiver instanceof BroadcastFilter) {
-            BroadcastFilter bf = (BroadcastFilter)curReceiver;
-            if (bf.receiverList.pid != 0
-                    && bf.receiverList.pid != ActivityManagerService.MY_PID) {
-                synchronized (mService.mPidsSelfLocked) {
-                    app = mService.mPidsSelfLocked.get(
-                            bf.receiverList.pid);
-                }
-            }
-        } else {
-            app = r.curApp;
-        }
-
-        if (app != null) {
-            anrMessage = "Broadcast of " + r.intent.toString();
-        }
-
-        if (mPendingBroadcast == r) {
-            mPendingBroadcast = null;
-        }
-
-        // Move on to the next receiver.
-        finishReceiverLocked(r, r.resultCode, r.resultData,
-                r.resultExtras, r.resultAbort, false);
-        scheduleBroadcastsLocked();
-
-        if (anrMessage != null) {
-            // Post the ANR to the handler since we do not want to process ANRs while
-            // potentially holding our lock.
-            mHandler.post(new AppNotResponding(app, anrMessage));
-        }
-    }
-
-    private final void addBroadcastToHistoryLocked(BroadcastRecord r) {
-        if (r.callingUid < 0) {
-            // This was from a registerReceiver() call; ignore it.
-            return;
-        }
-        System.arraycopy(mBroadcastHistory, 0, mBroadcastHistory, 1,
-                MAX_BROADCAST_HISTORY-1);
-        r.finishTime = SystemClock.uptimeMillis();
-        mBroadcastHistory[0] = r;
-        System.arraycopy(mBroadcastSummaryHistory, 0, mBroadcastSummaryHistory, 1,
-                MAX_BROADCAST_SUMMARY_HISTORY-1);
-        mBroadcastSummaryHistory[0] = r.intent;
-    }
-
-    final void logBroadcastReceiverDiscardLocked(BroadcastRecord r) {
-        if (r.nextReceiver > 0) {
-            Object curReceiver = r.receivers.get(r.nextReceiver-1);
-            if (curReceiver instanceof BroadcastFilter) {
-                BroadcastFilter bf = (BroadcastFilter) curReceiver;
-                EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_FILTER,
-                        bf.owningUserId, System.identityHashCode(r),
-                        r.intent.getAction(),
-                        r.nextReceiver - 1,
-                        System.identityHashCode(bf));
-            } else {
-                ResolveInfo ri = (ResolveInfo)curReceiver;
-                EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP,
-                        UserHandle.getUserId(ri.activityInfo.applicationInfo.uid),
-                        System.identityHashCode(r), r.intent.getAction(),
-                        r.nextReceiver - 1, ri.toString());
-            }
-        } else {
-            Slog.w(TAG, "Discarding broadcast before first receiver is invoked: "
-                    + r);
-            EventLog.writeEvent(EventLogTags.AM_BROADCAST_DISCARD_APP,
-                    -1, System.identityHashCode(r),
-                    r.intent.getAction(),
-                    r.nextReceiver,
-                    "NONE");
-        }
-    }
-
-    final boolean dumpLocked(FileDescriptor fd, PrintWriter pw, String[] args,
-            int opti, boolean dumpAll, String dumpPackage, boolean needSep) {
-        if (mParallelBroadcasts.size() > 0 || mOrderedBroadcasts.size() > 0
-                || mPendingBroadcast != null) {
-            boolean printed = false;
-            for (int i=mParallelBroadcasts.size()-1; i>=0; i--) {
-                BroadcastRecord br = mParallelBroadcasts.get(i);
-                if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) {
-                    continue;
-                }
-                if (!printed) {
-                    if (needSep) {
-                        pw.println();
-                    }
-                    needSep = true;
-                    printed = true;
-                    pw.println("  Active broadcasts [" + mQueueName + "]:");
-                }
-                pw.println("  Active Broadcast " + mQueueName + " #" + i + ":");
-                br.dump(pw, "    ");
-            }
-            printed = false;
-            needSep = true;
-            for (int i=mOrderedBroadcasts.size()-1; i>=0; i--) {
-                BroadcastRecord br = mOrderedBroadcasts.get(i);
-                if (dumpPackage != null && !dumpPackage.equals(br.callerPackage)) {
-                    continue;
-                }
-                if (!printed) {
-                    if (needSep) {
-                        pw.println();
-                    }
-                    needSep = true;
-                    printed = true;
-                    pw.println("  Active ordered broadcasts [" + mQueueName + "]:");
-                }
-                pw.println("  Active Ordered Broadcast " + mQueueName + " #" + i + ":");
-                mOrderedBroadcasts.get(i).dump(pw, "    ");
-            }
-            if (dumpPackage == null || (mPendingBroadcast != null
-                    && dumpPackage.equals(mPendingBroadcast.callerPackage))) {
-                if (needSep) {
-                    pw.println();
-                }
-                pw.println("  Pending broadcast [" + mQueueName + "]:");
-                if (mPendingBroadcast != null) {
-                    mPendingBroadcast.dump(pw, "    ");
-                } else {
-                    pw.println("    (null)");
-                }
-                needSep = true;
-            }
-        }
-
-        int i;
-        boolean printed = false;
-        for (i=0; i<MAX_BROADCAST_HISTORY; i++) {
-            BroadcastRecord r = mBroadcastHistory[i];
-            if (r == null) {
-                break;
-            }
-            if (dumpPackage != null && !dumpPackage.equals(r.callerPackage)) {
-                continue;
-            }
-            if (!printed) {
-                if (needSep) {
-                    pw.println();
-                }
-                needSep = true;
-                pw.println("  Historical broadcasts [" + mQueueName + "]:");
-                printed = true;
-            }
-            if (dumpAll) {
-                pw.print("  Historical Broadcast " + mQueueName + " #");
-                        pw.print(i); pw.println(":");
-                r.dump(pw, "    ");
-            } else {
-                pw.print("  #"); pw.print(i); pw.print(": "); pw.println(r);
-                pw.print("    ");
-                pw.println(r.intent.toShortString(false, true, true, false));
-                if (r.targetComp != null && r.targetComp != r.intent.getComponent()) {
-                    pw.print("    targetComp: "); pw.println(r.targetComp.toShortString());
-                }
-                Bundle bundle = r.intent.getExtras();
-                if (bundle != null) {
-                    pw.print("    extras: "); pw.println(bundle.toString());
-                }
-            }
-        }
-
-        if (dumpPackage == null) {
-            if (dumpAll) {
-                i = 0;
-                printed = false;
-            }
-            for (; i<MAX_BROADCAST_SUMMARY_HISTORY; i++) {
-                Intent intent = mBroadcastSummaryHistory[i];
-                if (intent == null) {
-                    break;
-                }
-                if (!printed) {
-                    if (needSep) {
-                        pw.println();
-                    }
-                    needSep = true;
-                    pw.println("  Historical broadcasts summary [" + mQueueName + "]:");
-                    printed = true;
-                }
-                if (!dumpAll && i >= 50) {
-                    pw.println("  ...");
-                    break;
-                }
-                pw.print("  #"); pw.print(i); pw.print(": ");
-                pw.println(intent.toShortString(false, true, true, false));
-                Bundle bundle = intent.getExtras();
-                if (bundle != null) {
-                    pw.print("    extras: "); pw.println(bundle.toString());
-                }
-            }
-        }
-
-        return needSep;
-    }
-}
diff --git a/services/java/com/android/server/am/CompatModePackages.java b/services/java/com/android/server/am/CompatModePackages.java
deleted file mode 100644
index 59e6787..0000000
--- a/services/java/com/android/server/am/CompatModePackages.java
+++ /dev/null
@@ -1,385 +0,0 @@
-package com.android.server.am;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import com.android.internal.util.FastXmlSerializer;
-
-import android.app.ActivityManager;
-import android.app.AppGlobals;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageManager;
-import android.content.res.CompatibilityInfo;
-import android.os.Handler;
-import android.os.Message;
-import android.os.RemoteException;
-import android.util.AtomicFile;
-import android.util.Slog;
-import android.util.Xml;
-
-public final class CompatModePackages {
-    private final String TAG = ActivityManagerService.TAG;
-    private final boolean DEBUG_CONFIGURATION = ActivityManagerService.DEBUG_CONFIGURATION;
-
-    private final ActivityManagerService mService;
-    private final AtomicFile mFile;
-
-    // Compatibility state: no longer ask user to select the mode.
-    public static final int COMPAT_FLAG_DONT_ASK = 1<<0;
-    // Compatibility state: compatibility mode is enabled.
-    public static final int COMPAT_FLAG_ENABLED = 1<<1;
-
-    private final HashMap<String, Integer> mPackages = new HashMap<String, Integer>();
-
-    private static final int MSG_WRITE = ActivityManagerService.FIRST_COMPAT_MODE_MSG;
-
-    private final Handler mHandler = new Handler() {
-        @Override public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_WRITE:
-                    saveCompatModes();
-                    break;
-                default:
-                    super.handleMessage(msg);
-                    break;
-            }
-        }
-    };
-
-    public CompatModePackages(ActivityManagerService service, File systemDir) {
-        mService = service;
-        mFile = new AtomicFile(new File(systemDir, "packages-compat.xml"));
-
-        FileInputStream fis = null;
-        try {
-            fis = mFile.openRead();
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(fis, null);
-            int eventType = parser.getEventType();
-            while (eventType != XmlPullParser.START_TAG) {
-                eventType = parser.next();
-            }
-            String tagName = parser.getName();
-            if ("compat-packages".equals(tagName)) {
-                eventType = parser.next();
-                do {
-                    if (eventType == XmlPullParser.START_TAG) {
-                        tagName = parser.getName();
-                        if (parser.getDepth() == 2) {
-                            if ("pkg".equals(tagName)) {
-                                String pkg = parser.getAttributeValue(null, "name");
-                                if (pkg != null) {
-                                    String mode = parser.getAttributeValue(null, "mode");
-                                    int modeInt = 0;
-                                    if (mode != null) {
-                                        try {
-                                            modeInt = Integer.parseInt(mode);
-                                        } catch (NumberFormatException e) {
-                                        }
-                                    }
-                                    mPackages.put(pkg, modeInt);
-                                }
-                            }
-                        }
-                    }
-                    eventType = parser.next();
-                } while (eventType != XmlPullParser.END_DOCUMENT);
-            }
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "Error reading compat-packages", e);
-        } catch (java.io.IOException e) {
-            if (fis != null) Slog.w(TAG, "Error reading compat-packages", e);
-        } finally {
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch (java.io.IOException e1) {
-                }
-            }
-        }
-    }
-
-    public HashMap<String, Integer> getPackages() {
-        return mPackages;
-    }
-
-    private int getPackageFlags(String packageName) {
-        Integer flags = mPackages.get(packageName);
-        return flags != null ? flags : 0;
-    }
-
-    public void handlePackageAddedLocked(String packageName, boolean updated) {
-        ApplicationInfo ai = null;
-        try {
-            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
-        } catch (RemoteException e) {
-        }
-        if (ai == null) {
-            return;
-        }
-        CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
-        final boolean mayCompat = !ci.alwaysSupportsScreen()
-                && !ci.neverSupportsScreen();
-
-        if (updated) {
-            // Update -- if the app no longer can run in compat mode, clear
-            // any current settings for it.
-            if (!mayCompat && mPackages.containsKey(packageName)) {
-                mPackages.remove(packageName);
-                mHandler.removeMessages(MSG_WRITE);
-                Message msg = mHandler.obtainMessage(MSG_WRITE);
-                mHandler.sendMessageDelayed(msg, 10000);
-            }
-        }
-    }
-
-    public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
-        CompatibilityInfo ci = new CompatibilityInfo(ai, mService.mConfiguration.screenLayout,
-                mService.mConfiguration.smallestScreenWidthDp,
-                (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0);
-        //Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci);
-        return ci;
-    }
-
-    public int computeCompatModeLocked(ApplicationInfo ai) {
-        boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0;
-        CompatibilityInfo info = new CompatibilityInfo(ai,
-                mService.mConfiguration.screenLayout,
-                mService.mConfiguration.smallestScreenWidthDp, enabled);
-        if (info.alwaysSupportsScreen()) {
-            return ActivityManager.COMPAT_MODE_NEVER;
-        }
-        if (info.neverSupportsScreen()) {
-            return ActivityManager.COMPAT_MODE_ALWAYS;
-        }
-        return enabled ? ActivityManager.COMPAT_MODE_ENABLED
-                : ActivityManager.COMPAT_MODE_DISABLED;
-    }
-
-    public boolean getFrontActivityAskCompatModeLocked() {
-        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
-        if (r == null) {
-            return false;
-        }
-        return getPackageAskCompatModeLocked(r.packageName);
-    }
-
-    public boolean getPackageAskCompatModeLocked(String packageName) {
-        return (getPackageFlags(packageName)&COMPAT_FLAG_DONT_ASK) == 0;
-    }
-
-    public void setFrontActivityAskCompatModeLocked(boolean ask) {
-        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
-        if (r != null) {
-            setPackageAskCompatModeLocked(r.packageName, ask);
-        }
-    }
-
-    public void setPackageAskCompatModeLocked(String packageName, boolean ask) {
-        int curFlags = getPackageFlags(packageName);
-        int newFlags = ask ? (curFlags&~COMPAT_FLAG_DONT_ASK) : (curFlags|COMPAT_FLAG_DONT_ASK);
-        if (curFlags != newFlags) {
-            if (newFlags != 0) {
-                mPackages.put(packageName, newFlags);
-            } else {
-                mPackages.remove(packageName);
-            }
-            mHandler.removeMessages(MSG_WRITE);
-            Message msg = mHandler.obtainMessage(MSG_WRITE);
-            mHandler.sendMessageDelayed(msg, 10000);
-        }
-    }
-
-    public int getFrontActivityScreenCompatModeLocked() {
-        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
-        if (r == null) {
-            return ActivityManager.COMPAT_MODE_UNKNOWN;
-        }
-        return computeCompatModeLocked(r.info.applicationInfo);
-    }
-
-    public void setFrontActivityScreenCompatModeLocked(int mode) {
-        ActivityRecord r = mService.getFocusedStack().topRunningActivityLocked(null);
-        if (r == null) {
-            Slog.w(TAG, "setFrontActivityScreenCompatMode failed: no top activity");
-            return;
-        }
-        setPackageScreenCompatModeLocked(r.info.applicationInfo, mode);
-    }
-
-    public int getPackageScreenCompatModeLocked(String packageName) {
-        ApplicationInfo ai = null;
-        try {
-            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
-        } catch (RemoteException e) {
-        }
-        if (ai == null) {
-            return ActivityManager.COMPAT_MODE_UNKNOWN;
-        }
-        return computeCompatModeLocked(ai);
-    }
-
-    public void setPackageScreenCompatModeLocked(String packageName, int mode) {
-        ApplicationInfo ai = null;
-        try {
-            ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
-        } catch (RemoteException e) {
-        }
-        if (ai == null) {
-            Slog.w(TAG, "setPackageScreenCompatMode failed: unknown package " + packageName);
-            return;
-        }
-        setPackageScreenCompatModeLocked(ai, mode);
-    }
-
-    private void setPackageScreenCompatModeLocked(ApplicationInfo ai, int mode) {
-        final String packageName = ai.packageName;
-
-        int curFlags = getPackageFlags(packageName);
-
-        boolean enable;
-        switch (mode) {
-            case ActivityManager.COMPAT_MODE_DISABLED:
-                enable = false;
-                break;
-            case ActivityManager.COMPAT_MODE_ENABLED:
-                enable = true;
-                break;
-            case ActivityManager.COMPAT_MODE_TOGGLE:
-                enable = (curFlags&COMPAT_FLAG_ENABLED) == 0;
-                break;
-            default:
-                Slog.w(TAG, "Unknown screen compat mode req #" + mode + "; ignoring");
-                return;
-        }
-
-        int newFlags = curFlags;
-        if (enable) {
-            newFlags |= COMPAT_FLAG_ENABLED;
-        } else {
-            newFlags &= ~COMPAT_FLAG_ENABLED;
-        }
-
-        CompatibilityInfo ci = compatibilityInfoForPackageLocked(ai);
-        if (ci.alwaysSupportsScreen()) {
-            Slog.w(TAG, "Ignoring compat mode change of " + packageName
-                    + "; compatibility never needed");
-            newFlags = 0;
-        }
-        if (ci.neverSupportsScreen()) {
-            Slog.w(TAG, "Ignoring compat mode change of " + packageName
-                    + "; compatibility always needed");
-            newFlags = 0;
-        }
-
-        if (newFlags != curFlags) {
-            if (newFlags != 0) {
-                mPackages.put(packageName, newFlags);
-            } else {
-                mPackages.remove(packageName);
-            }
-
-            // Need to get compatibility info in new state.
-            ci = compatibilityInfoForPackageLocked(ai);
-
-            mHandler.removeMessages(MSG_WRITE);
-            Message msg = mHandler.obtainMessage(MSG_WRITE);
-            mHandler.sendMessageDelayed(msg, 10000);
-
-            final ActivityStack stack = mService.getFocusedStack();
-            ActivityRecord starting = stack.restartPackage(packageName);
-
-            // Tell all processes that loaded this package about the change.
-            for (int i=mService.mLruProcesses.size()-1; i>=0; i--) {
-                ProcessRecord app = mService.mLruProcesses.get(i);
-                if (!app.pkgList.containsKey(packageName)) {
-                    continue;
-                }
-                try {
-                    if (app.thread != null) {
-                        if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending to proc "
-                                + app.processName + " new compat " + ci);
-                        app.thread.updatePackageCompatibilityInfo(packageName, ci);
-                    }
-                } catch (Exception e) {
-                }
-            }
-
-            if (starting != null) {
-                stack.ensureActivityConfigurationLocked(starting, 0);
-                // And we need to make sure at this point that all other activities
-                // are made visible with the correct configuration.
-                stack.ensureActivitiesVisibleLocked(starting, 0);
-            }
-        }
-    }
-
-    void saveCompatModes() {
-        HashMap<String, Integer> pkgs;
-        synchronized (mService) {
-            pkgs = new HashMap<String, Integer>(mPackages);
-        }
-
-        FileOutputStream fos = null;
-
-        try {
-            fos = mFile.startWrite();
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-            out.startDocument(null, true);
-            out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-            out.startTag(null, "compat-packages");
-
-            final IPackageManager pm = AppGlobals.getPackageManager();
-            final int screenLayout = mService.mConfiguration.screenLayout;
-            final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
-            final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
-            while (it.hasNext()) {
-                Map.Entry<String, Integer> entry = it.next();
-                String pkg = entry.getKey();
-                int mode = entry.getValue();
-                if (mode == 0) {
-                    continue;
-                }
-                ApplicationInfo ai = null;
-                try {
-                    ai = pm.getApplicationInfo(pkg, 0, 0);
-                } catch (RemoteException e) {
-                }
-                if (ai == null) {
-                    continue;
-                }
-                CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout,
-                        smallestScreenWidthDp, false);
-                if (info.alwaysSupportsScreen()) {
-                    continue;
-                }
-                if (info.neverSupportsScreen()) {
-                    continue;
-                }
-                out.startTag(null, "pkg");
-                out.attribute(null, "name", pkg);
-                out.attribute(null, "mode", Integer.toString(mode));
-                out.endTag(null, "pkg");
-            }
-
-            out.endTag(null, "compat-packages");
-            out.endDocument();
-
-            mFile.finishWrite(fos);
-        } catch (java.io.IOException e1) {
-            Slog.w(TAG, "Error writing compat packages", e1);
-            if (fos != null) {
-                mFile.failWrite(fos);
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/am/NativeCrashListener.java b/services/java/com/android/server/am/NativeCrashListener.java
deleted file mode 100644
index 2c7f1f1..0000000
--- a/services/java/com/android/server/am/NativeCrashListener.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright (C) 2013 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.app.ApplicationErrorReport.CrashInfo;
-import android.util.Slog;
-
-import libcore.io.ErrnoException;
-import libcore.io.Libcore;
-import libcore.io.StructTimeval;
-import libcore.io.StructUcred;
-
-import static libcore.io.OsConstants.*;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.net.InetSocketAddress;
-import java.net.InetUnixAddress;
-
-/**
- * Set up a Unix domain socket that debuggerd will connect() to in
- * order to write a description of a native crash.  The crash info is
- * then parsed and forwarded to the ActivityManagerService's normal
- * crash handling code.
- *
- * Note that this component runs in a separate thread.
- */
-final class NativeCrashListener extends Thread {
-    static final String TAG = "NativeCrashListener";
-    static final boolean DEBUG = false;
-    static final boolean MORE_DEBUG = DEBUG && false;
-
-    // Must match the path defined in debuggerd.c.
-    static final String DEBUGGERD_SOCKET_PATH = "/data/system/ndebugsocket";
-
-    // Use a short timeout on socket operations and abandon the connection
-    // on hard errors
-    static final long SOCKET_TIMEOUT_MILLIS = 2000;  // 2 seconds
-
-    final ActivityManagerService mAm;
-
-    /*
-     * Spin the actual work of handling a debuggerd crash report into a
-     * separate thread so that the listener can go immediately back to
-     * accepting incoming connections.
-     */
-    class NativeCrashReporter extends Thread {
-        ProcessRecord mApp;
-        int mSignal;
-        String mCrashReport;
-
-        NativeCrashReporter(ProcessRecord app, int signal, String report) {
-            super("NativeCrashReport");
-            mApp = app;
-            mSignal = signal;
-            mCrashReport = report;
-        }
-
-        @Override
-        public void run() {
-            try {
-                CrashInfo ci = new CrashInfo();
-                ci.exceptionClassName = "Native crash";
-                ci.exceptionMessage = Libcore.os.strsignal(mSignal);
-                ci.throwFileName = "unknown";
-                ci.throwClassName = "unknown";
-                ci.throwMethodName = "unknown";
-                ci.stackTrace = mCrashReport;
-
-                if (DEBUG) Slog.v(TAG, "Calling handleApplicationCrash()");
-                mAm.handleApplicationCrashInner("native_crash", mApp, mApp.processName, ci);
-                if (DEBUG) Slog.v(TAG, "<-- handleApplicationCrash() returned");
-            } catch (Exception e) {
-                Slog.e(TAG, "Unable to report native crash", e);
-            }
-        }
-    }
-
-    /*
-     * Daemon thread that accept()s incoming domain socket connections from debuggerd
-     * and processes the crash dump that is passed through.
-     */
-    NativeCrashListener() {
-        mAm = ActivityManagerService.self();
-    }
-
-    @Override
-    public void run() {
-        final byte[] ackSignal = new byte[1];
-
-        if (DEBUG) Slog.i(TAG, "Starting up");
-
-        // The file system entity for this socket is created with 0700 perms, owned
-        // by system:system.  debuggerd runs as root, so is capable of connecting to
-        // it, but 3rd party apps cannot.
-        {
-            File socketFile = new File(DEBUGGERD_SOCKET_PATH);
-            if (socketFile.exists()) {
-                socketFile.delete();
-            }
-        }
-
-        try {
-            FileDescriptor serverFd = Libcore.os.socket(AF_UNIX, SOCK_STREAM, 0);
-            final InetUnixAddress sockAddr = new InetUnixAddress(DEBUGGERD_SOCKET_PATH);
-            Libcore.os.bind(serverFd, sockAddr, 0);
-            Libcore.os.listen(serverFd, 1);
-
-            while (true) {
-                InetSocketAddress peer = new InetSocketAddress();
-                FileDescriptor peerFd = null;
-                try {
-                    if (MORE_DEBUG) Slog.v(TAG, "Waiting for debuggerd connection");
-                    peerFd = Libcore.os.accept(serverFd, peer);
-                    if (MORE_DEBUG) Slog.v(TAG, "Got debuggerd socket " + peerFd);
-                    if (peerFd != null) {
-                        // Only the superuser is allowed to talk to us over this socket
-                        StructUcred credentials =
-                                Libcore.os.getsockoptUcred(peerFd, SOL_SOCKET, SO_PEERCRED);
-                        if (credentials.uid == 0) {
-                            // the reporting thread may take responsibility for
-                            // acking the debugger; make sure we play along.
-                            consumeNativeCrashData(peerFd);
-                        }
-                    }
-                } catch (Exception e) {
-                    Slog.w(TAG, "Error handling connection", e);
-                } finally {
-                    // Always ack debuggerd's connection to us.  The actual
-                    // byte written is irrelevant.
-                    if (peerFd != null) {
-                        try {
-                            Libcore.os.write(peerFd, ackSignal, 0, 1);
-                        } catch (Exception e) {
-                            /* we don't care about failures here */
-                            if (MORE_DEBUG) {
-                                Slog.d(TAG, "Exception writing ack: " + e.getMessage());
-                            }
-                        }
-                        try {
-                            Libcore.os.close(peerFd);
-                        } catch (ErrnoException e) {
-                            if (MORE_DEBUG) {
-                                Slog.d(TAG, "Exception closing socket: " + e.getMessage());
-                            }
-                        }
-                    }
-                }
-            }
-        } catch (Exception e) {
-            Slog.e(TAG, "Unable to init native debug socket!", e);
-        }
-    }
-
-    static int unpackInt(byte[] buf, int offset) {
-        int b0, b1, b2, b3;
-
-        b0 = ((int) buf[offset]) & 0xFF; // mask against sign extension
-        b1 = ((int) buf[offset+1]) & 0xFF;
-        b2 = ((int) buf[offset+2]) & 0xFF;
-        b3 = ((int) buf[offset+3]) & 0xFF;
-        return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
-    }
-
-    static int readExactly(FileDescriptor fd, byte[] buffer, int offset, int numBytes)
-            throws ErrnoException {
-        int totalRead = 0;
-        while (numBytes > 0) {
-            int n = Libcore.os.read(fd, buffer, offset + totalRead, numBytes);
-            if (n <= 0) {
-                if (DEBUG) {
-                    Slog.w(TAG, "Needed " + numBytes + " but saw " + n);
-                }
-                return -1;  // premature EOF or timeout
-            }
-            numBytes -= n;
-            totalRead += n;
-        }
-        return totalRead;
-    }
-
-    // Read the crash report from the debuggerd connection
-    void consumeNativeCrashData(FileDescriptor fd) {
-        if (MORE_DEBUG) Slog.i(TAG, "debuggerd connected");
-        final byte[] buf = new byte[4096];
-        final ByteArrayOutputStream os = new ByteArrayOutputStream(4096);
-
-        try {
-            StructTimeval timeout = StructTimeval.fromMillis(SOCKET_TIMEOUT_MILLIS);
-            Libcore.os.setsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO, timeout);
-            Libcore.os.setsockoptTimeval(fd, SOL_SOCKET, SO_SNDTIMEO, timeout);
-
-            // first, the pid and signal number
-            int headerBytes = readExactly(fd, buf, 0, 8);
-            if (headerBytes != 8) {
-                // protocol failure; give up
-                Slog.e(TAG, "Unable to read from debuggerd");
-                return;
-            }
-
-            int pid = unpackInt(buf, 0);
-            int signal = unpackInt(buf, 4);
-            if (DEBUG) {
-                Slog.v(TAG, "Read pid=" + pid + " signal=" + signal);
-            }
-
-            // now the text of the dump
-            if (pid > 0) {
-                final ProcessRecord pr;
-                synchronized (mAm.mPidsSelfLocked) {
-                    pr = mAm.mPidsSelfLocked.get(pid);
-                }
-                if (pr != null) {
-                    // Don't attempt crash reporting for persistent apps
-                    if (pr.persistent) {
-                        if (DEBUG) {
-                            Slog.v(TAG, "Skipping report for persistent app " + pr);
-                        }
-                        return;
-                    }
-
-                    int bytes;
-                    do {
-                        // get some data
-                        bytes = Libcore.os.read(fd, buf, 0, buf.length);
-                        if (bytes > 0) {
-                            if (MORE_DEBUG) {
-                                String s = new String(buf, 0, bytes, "UTF-8");
-                                Slog.v(TAG, "READ=" + bytes + "> " + s);
-                            }
-                            // did we just get the EOD null byte?
-                            if (buf[bytes-1] == 0) {
-                                os.write(buf, 0, bytes-1);  // exclude the EOD token
-                                break;
-                            }
-                            // no EOD, so collect it and read more
-                            os.write(buf, 0, bytes);
-                        }
-                    } while (bytes > 0);
-
-                    // Okay, we've got the report.
-                    if (DEBUG) Slog.v(TAG, "processing");
-
-                    // Mark the process record as being a native crash so that the
-                    // cleanup mechanism knows we're still submitting the report
-                    // even though the process will vanish as soon as we let
-                    // debuggerd proceed.
-                    synchronized (mAm) {
-                        pr.crashing = true;
-                        pr.forceCrashReport = true;
-                    }
-
-                    // Crash reporting is synchronous but we want to let debuggerd
-                    // go about it business right away, so we spin off the actual
-                    // reporting logic on a thread and let it take it's time.
-                    final String reportString = new String(os.toByteArray(), "UTF-8");
-                    (new NativeCrashReporter(pr, signal, reportString)).start();
-                } else {
-                    Slog.w(TAG, "Couldn't find ProcessRecord for pid " + pid);
-                }
-            } else {
-                Slog.e(TAG, "Bogus pid!");
-            }
-        } catch (Exception e) {
-            Slog.e(TAG, "Exception dealing with report", e);
-            // ugh, fail.
-        }
-    }
-
-}
diff --git a/services/java/com/android/server/am/PendingIntentRecord.java b/services/java/com/android/server/am/PendingIntentRecord.java
deleted file mode 100644
index 17f24a9..0000000
--- a/services/java/com/android/server/am/PendingIntentRecord.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright (C) 2006 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.app.ActivityManager;
-import android.content.IIntentSender;
-import android.content.IIntentReceiver;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.util.Slog;
-
-import java.io.PrintWriter;
-import java.lang.ref.WeakReference;
-
-final class PendingIntentRecord extends IIntentSender.Stub {
-    final ActivityManagerService owner;
-    final Key key;
-    final int uid;
-    final WeakReference<PendingIntentRecord> ref;
-    boolean sent = false;
-    boolean canceled = false;
-
-    String stringName;
-    
-    final static class Key {
-        final int type;
-        final String packageName;
-        final ActivityRecord activity;
-        final String who;
-        final int requestCode;
-        final Intent requestIntent;
-        final String requestResolvedType;
-        final Bundle options;
-        Intent[] allIntents;
-        String[] allResolvedTypes;
-        final int flags;
-        final int hashCode;
-        final int userId;
-        
-        private static final int ODD_PRIME_NUMBER = 37;
-        
-        Key(int _t, String _p, ActivityRecord _a, String _w,
-                int _r, Intent[] _i, String[] _it, int _f, Bundle _o, int _userId) {
-            type = _t;
-            packageName = _p;
-            activity = _a;
-            who = _w;
-            requestCode = _r;
-            requestIntent = _i != null ? _i[_i.length-1] : null;
-            requestResolvedType = _it != null ? _it[_it.length-1] : null;
-            allIntents = _i;
-            allResolvedTypes = _it;
-            flags = _f;
-            options = _o;
-            userId = _userId;
-
-            int hash = 23;
-            hash = (ODD_PRIME_NUMBER*hash) + _f;
-            hash = (ODD_PRIME_NUMBER*hash) + _r;
-            hash = (ODD_PRIME_NUMBER*hash) + _userId;
-            if (_w != null) {
-                hash = (ODD_PRIME_NUMBER*hash) + _w.hashCode();
-            }
-            if (_a != null) {
-                hash = (ODD_PRIME_NUMBER*hash) + _a.hashCode();
-            }
-            if (requestIntent != null) {
-                hash = (ODD_PRIME_NUMBER*hash) + requestIntent.filterHashCode();
-            }
-            if (requestResolvedType != null) {
-                hash = (ODD_PRIME_NUMBER*hash) + requestResolvedType.hashCode();
-            }
-            hash = (ODD_PRIME_NUMBER*hash) + _p.hashCode();
-            hash = (ODD_PRIME_NUMBER*hash) + _t;
-            hashCode = hash;
-            //Slog.i(ActivityManagerService.TAG, this + " hashCode=0x"
-            //        + Integer.toHexString(hashCode));
-        }
-        
-        public boolean equals(Object otherObj) {
-            if (otherObj == null) {
-                return false;
-            }
-            try {
-                Key other = (Key)otherObj;
-                if (type != other.type) {
-                    return false;
-                }
-                if (userId != other.userId){
-                    return false;
-                }
-                if (!packageName.equals(other.packageName)) {
-                    return false;
-                }
-                if (activity != other.activity) {
-                    return false;
-                }
-                if (who != other.who) {
-                    if (who != null) {
-                        if (!who.equals(other.who)) {
-                            return false;
-                        }
-                    } else if (other.who != null) {
-                        return false;
-                    }
-                }
-                if (requestCode != other.requestCode) {
-                    return false;
-                }
-                if (requestIntent != other.requestIntent) {
-                    if (requestIntent != null) {
-                        if (!requestIntent.filterEquals(other.requestIntent)) {
-                            return false;
-                        }
-                    } else if (other.requestIntent != null) {
-                        return false;
-                    }
-                }
-                if (requestResolvedType != other.requestResolvedType) {
-                    if (requestResolvedType != null) {
-                        if (!requestResolvedType.equals(other.requestResolvedType)) {
-                            return false;
-                        }
-                    } else if (other.requestResolvedType != null) {
-                        return false;
-                    }
-                }
-                if (flags != other.flags) {
-                    return false;
-                }
-                return true;
-            } catch (ClassCastException e) {
-            }
-            return false;
-        }
-
-        public int hashCode() {
-            return hashCode;
-        }
-        
-        public String toString() {
-            return "Key{" + typeName() + " pkg=" + packageName
-                + " intent="
-                + (requestIntent != null
-                        ? requestIntent.toShortString(false, true, false, false) : "<null>")
-                + " flags=0x" + Integer.toHexString(flags) + " u=" + userId + "}";
-        }
-        
-        String typeName() {
-            switch (type) {
-                case ActivityManager.INTENT_SENDER_ACTIVITY:
-                    return "startActivity";
-                case ActivityManager.INTENT_SENDER_BROADCAST:
-                    return "broadcastIntent";
-                case ActivityManager.INTENT_SENDER_SERVICE:
-                    return "startService";
-                case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT:
-                    return "activityResult";
-            }
-            return Integer.toString(type);
-        }
-    }
-    
-    PendingIntentRecord(ActivityManagerService _owner, Key _k, int _u) {
-        owner = _owner;
-        key = _k;
-        uid = _u;
-        ref = new WeakReference<PendingIntentRecord>(this);
-    }
-
-    public int send(int code, Intent intent, String resolvedType,
-            IIntentReceiver finishedReceiver, String requiredPermission) {
-        return sendInner(code, intent, resolvedType, finishedReceiver,
-                requiredPermission, null, null, 0, 0, 0, null);
-    }
-    
-    int sendInner(int code, Intent intent, String resolvedType,
-            IIntentReceiver finishedReceiver, String requiredPermission,
-            IBinder resultTo, String resultWho, int requestCode,
-            int flagsMask, int flagsValues, Bundle options) {
-        synchronized(owner) {
-            if (!canceled) {
-                sent = true;
-                if ((key.flags&PendingIntent.FLAG_ONE_SHOT) != 0) {
-                    owner.cancelIntentSenderLocked(this, true);
-                    canceled = true;
-                }
-                Intent finalIntent = key.requestIntent != null
-                        ? new Intent(key.requestIntent) : new Intent();
-                if (intent != null) {
-                    int changes = finalIntent.fillIn(intent, key.flags);
-                    if ((changes&Intent.FILL_IN_DATA) == 0) {
-                        resolvedType = key.requestResolvedType;
-                    }
-                } else {
-                    resolvedType = key.requestResolvedType;
-                }
-                flagsMask &= ~Intent.IMMUTABLE_FLAGS;
-                flagsValues &= flagsMask;
-                finalIntent.setFlags((finalIntent.getFlags()&~flagsMask) | flagsValues);
-                
-                final long origId = Binder.clearCallingIdentity();
-                
-                boolean sendFinish = finishedReceiver != null;
-                int userId = key.userId;
-                if (userId == UserHandle.USER_CURRENT) {
-                    userId = owner.getCurrentUserIdLocked();
-                }
-                switch (key.type) {
-                    case ActivityManager.INTENT_SENDER_ACTIVITY:
-                        if (options == null) {
-                            options = key.options;
-                        } else if (key.options != null) {
-                            Bundle opts = new Bundle(key.options);
-                            opts.putAll(options);
-                            options = opts;
-                        }
-                        try {
-                            if (key.allIntents != null && key.allIntents.length > 1) {
-                                Intent[] allIntents = new Intent[key.allIntents.length];
-                                String[] allResolvedTypes = new String[key.allIntents.length];
-                                System.arraycopy(key.allIntents, 0, allIntents, 0,
-                                        key.allIntents.length);
-                                if (key.allResolvedTypes != null) {
-                                    System.arraycopy(key.allResolvedTypes, 0, allResolvedTypes, 0,
-                                            key.allResolvedTypes.length);
-                                }
-                                allIntents[allIntents.length-1] = finalIntent;
-                                allResolvedTypes[allResolvedTypes.length-1] = resolvedType;
-                                owner.startActivitiesInPackage(uid, key.packageName, allIntents,
-                                        allResolvedTypes, resultTo, options, userId);
-                            } else {
-                                owner.startActivityInPackage(uid, key.packageName, finalIntent,
-                                        resolvedType, resultTo, resultWho, requestCode, 0,
-                                        options, userId);
-                            }
-                        } catch (RuntimeException e) {
-                            Slog.w(ActivityManagerService.TAG,
-                                    "Unable to send startActivity intent", e);
-                        }
-                        break;
-                    case ActivityManager.INTENT_SENDER_ACTIVITY_RESULT:
-                        key.activity.task.stack.sendActivityResultLocked(-1, key.activity,
-                                key.who, key.requestCode, code, finalIntent);
-                        break;
-                    case ActivityManager.INTENT_SENDER_BROADCAST:
-                        try {
-                            // If a completion callback has been requested, require
-                            // that the broadcast be delivered synchronously
-                            owner.broadcastIntentInPackage(key.packageName, uid,
-                                    finalIntent, resolvedType,
-                                    finishedReceiver, code, null, null,
-                                requiredPermission, (finishedReceiver != null), false, userId);
-                            sendFinish = false;
-                        } catch (RuntimeException e) {
-                            Slog.w(ActivityManagerService.TAG,
-                                    "Unable to send startActivity intent", e);
-                        }
-                        break;
-                    case ActivityManager.INTENT_SENDER_SERVICE:
-                        try {
-                            owner.startServiceInPackage(uid,
-                                    finalIntent, resolvedType, userId);
-                        } catch (RuntimeException e) {
-                            Slog.w(ActivityManagerService.TAG,
-                                    "Unable to send startService intent", e);
-                        }
-                        break;
-                }
-                
-                if (sendFinish) {
-                    try {
-                        finishedReceiver.performReceive(new Intent(finalIntent), 0,
-                                null, null, false, false, key.userId);
-                    } catch (RemoteException e) {
-                    }
-                }
-                
-                Binder.restoreCallingIdentity(origId);
-                
-                return 0;
-            }
-        }
-        return ActivityManager.START_CANCELED;
-    }
-    
-    protected void finalize() throws Throwable {
-        try {
-            if (!canceled) {
-                owner.mHandler.sendMessage(owner.mHandler.obtainMessage(
-                        ActivityManagerService.FINALIZE_PENDING_INTENT_MSG, this));
-            }
-        } finally {
-            super.finalize();
-        }
-    }
-
-    public void completeFinalize() {
-        synchronized(owner) {
-            WeakReference<PendingIntentRecord> current =
-                    owner.mIntentSenderRecords.get(key);
-            if (current == ref) {
-                owner.mIntentSenderRecords.remove(key);
-            }
-        }
-    }
-    
-    void dump(PrintWriter pw, String prefix) {
-        pw.print(prefix); pw.print("uid="); pw.print(uid);
-                pw.print(" packageName="); pw.print(key.packageName);
-                pw.print(" type="); pw.print(key.typeName());
-                pw.print(" flags=0x"); pw.println(Integer.toHexString(key.flags));
-        if (key.activity != null || key.who != null) {
-            pw.print(prefix); pw.print("activity="); pw.print(key.activity);
-                    pw.print(" who="); pw.println(key.who);
-        }
-        if (key.requestCode != 0 || key.requestResolvedType != null) {
-            pw.print(prefix); pw.print("requestCode="); pw.print(key.requestCode);
-                    pw.print(" requestResolvedType="); pw.println(key.requestResolvedType);
-        }
-        if (key.requestIntent != null) {
-            pw.print(prefix); pw.print("requestIntent=");
-                    pw.println(key.requestIntent.toShortString(false, true, true, true));
-        }
-        if (sent || canceled) {
-            pw.print(prefix); pw.print("sent="); pw.print(sent);
-                    pw.print(" canceled="); pw.println(canceled);
-        }
-    }
-
-    public String toString() {
-        if (stringName != null) {
-            return stringName;
-        }
-        StringBuilder sb = new StringBuilder(128);
-        sb.append("PendingIntentRecord{");
-        sb.append(Integer.toHexString(System.identityHashCode(this)));
-        sb.append(' ');
-        sb.append(key.packageName);
-        sb.append(' ');
-        sb.append(key.typeName());
-        sb.append('}');
-        return stringName = sb.toString();
-    }
-}
diff --git a/services/java/com/android/server/am/ProcessList.java b/services/java/com/android/server/am/ProcessList.java
deleted file mode 100644
index d3777c7..0000000
--- a/services/java/com/android/server/am/ProcessList.java
+++ /dev/null
@@ -1,525 +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.server.am;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import android.app.ActivityManager;
-import com.android.internal.util.MemInfoReader;
-import com.android.server.wm.WindowManagerService;
-
-import android.content.res.Resources;
-import android.graphics.Point;
-import android.os.SystemProperties;
-import android.util.Slog;
-import android.view.Display;
-
-/**
- * Activity manager code dealing with processes.
- */
-final class ProcessList {
-    // The minimum time we allow between crashes, for us to consider this
-    // application to be bad and stop and its services and reject broadcasts.
-    static final int MIN_CRASH_INTERVAL = 60*1000;
-
-    // OOM adjustments for processes in various states:
-
-    // Adjustment used in certain places where we don't know it yet.
-    // (Generally this is something that is going to be cached, but we
-    // don't know the exact value in the cached range to assign yet.)
-    static final int UNKNOWN_ADJ = 16;
-
-    // This is a process only hosting activities that are not visible,
-    // so it can be killed without any disruption.
-    static final int CACHED_APP_MAX_ADJ = 15;
-    static final int CACHED_APP_MIN_ADJ = 9;
-
-    // The B list of SERVICE_ADJ -- these are the old and decrepit
-    // services that aren't as shiny and interesting as the ones in the A list.
-    static final int SERVICE_B_ADJ = 8;
-
-    // This is the process of the previous application that the user was in.
-    // This process is kept above other things, because it is very common to
-    // switch back to the previous app.  This is important both for recent
-    // task switch (toggling between the two top recent apps) as well as normal
-    // UI flow such as clicking on a URI in the e-mail app to view in the browser,
-    // and then pressing back to return to e-mail.
-    static final int PREVIOUS_APP_ADJ = 7;
-
-    // This is a process holding the home application -- we want to try
-    // avoiding killing it, even if it would normally be in the background,
-    // because the user interacts with it so much.
-    static final int HOME_APP_ADJ = 6;
-
-    // This is a process holding an application service -- killing it will not
-    // have much of an impact as far as the user is concerned.
-    static final int SERVICE_ADJ = 5;
-
-    // This is a process with a heavy-weight application.  It is in the
-    // background, but we want to try to avoid killing it.  Value set in
-    // system/rootdir/init.rc on startup.
-    static final int HEAVY_WEIGHT_APP_ADJ = 4;
-
-    // This is a process currently hosting a backup operation.  Killing it
-    // is not entirely fatal but is generally a bad idea.
-    static final int BACKUP_APP_ADJ = 3;
-
-    // This is a process only hosting components that are perceptible to the
-    // user, and we really want to avoid killing them, but they are not
-    // immediately visible. An example is background music playback.
-    static final int PERCEPTIBLE_APP_ADJ = 2;
-
-    // This is a process only hosting activities that are visible to the
-    // user, so we'd prefer they don't disappear.
-    static final int VISIBLE_APP_ADJ = 1;
-
-    // This is the process running the current foreground app.  We'd really
-    // rather not kill it!
-    static final int FOREGROUND_APP_ADJ = 0;
-
-    // This is a system persistent process, such as telephony.  Definitely
-    // don't want to kill it, but doing so is not completely fatal.
-    static final int PERSISTENT_PROC_ADJ = -12;
-
-    // The system process runs at the default adjustment.
-    static final int SYSTEM_ADJ = -16;
-
-    // Special code for native processes that are not being managed by the system (so
-    // don't have an oom adj assigned by the system).
-    static final int NATIVE_ADJ = -17;
-
-    // Memory pages are 4K.
-    static final int PAGE_SIZE = 4*1024;
-
-    // The minimum number of cached apps we want to be able to keep around,
-    // without empty apps being able to push them out of memory.
-    static final int MIN_CACHED_APPS = 2;
-
-    // The maximum number of cached processes we will keep around before killing them.
-    // NOTE: this constant is *only* a control to not let us go too crazy with
-    // keeping around processes on devices with large amounts of RAM.  For devices that
-    // are tighter on RAM, the out of memory killer is responsible for killing background
-    // processes as RAM is needed, and we should *never* be relying on this limit to
-    // kill them.  Also note that this limit only applies to cached background processes;
-    // we have no limit on the number of service, visible, foreground, or other such
-    // processes and the number of those processes does not count against the cached
-    // process limit.
-    static final int MAX_CACHED_APPS = 24;
-
-    // We allow empty processes to stick around for at most 30 minutes.
-    static final long MAX_EMPTY_TIME = 30*60*1000;
-
-    // The maximum number of empty app processes we will let sit around.
-    private static final int MAX_EMPTY_APPS = computeEmptyProcessLimit(MAX_CACHED_APPS);
-
-    // The number of empty apps at which we don't consider it necessary to do
-    // memory trimming.
-    static final int TRIM_EMPTY_APPS = MAX_EMPTY_APPS/2;
-
-    // The number of cached at which we don't consider it necessary to do
-    // memory trimming.
-    static final int TRIM_CACHED_APPS = ((MAX_CACHED_APPS-MAX_EMPTY_APPS)*2)/3;
-
-    // Threshold of number of cached+empty where we consider memory critical.
-    static final int TRIM_CRITICAL_THRESHOLD = 3;
-
-    // Threshold of number of cached+empty where we consider memory critical.
-    static final int TRIM_LOW_THRESHOLD = 5;
-
-    // These are the various interesting memory levels that we will give to
-    // the OOM killer.  Note that the OOM killer only supports 6 slots, so we
-    // can't give it a different value for every possible kind of process.
-    private final int[] mOomAdj = new int[] {
-            FOREGROUND_APP_ADJ, VISIBLE_APP_ADJ, PERCEPTIBLE_APP_ADJ,
-            BACKUP_APP_ADJ, CACHED_APP_MIN_ADJ, CACHED_APP_MAX_ADJ
-    };
-    // These are the low-end OOM level limits.  This is appropriate for an
-    // HVGA or smaller phone with less than 512MB.  Values are in KB.
-    private final long[] mOomMinFreeLow = new long[] {
-            8192, 12288, 16384,
-            24576, 28672, 32768
-    };
-    // These are the high-end OOM level limits.  This is appropriate for a
-    // 1280x800 or larger screen with around 1GB RAM.  Values are in KB.
-    private final long[] mOomMinFreeHigh = new long[] {
-            49152, 61440, 73728,
-            86016, 98304, 122880
-    };
-    // The actual OOM killer memory levels we are using.
-    private final long[] mOomMinFree = new long[mOomAdj.length];
-
-    private final long mTotalMemMb;
-
-    private long mCachedRestoreLevel;
-
-    private boolean mHaveDisplaySize;
-
-    ProcessList() {
-        MemInfoReader minfo = new MemInfoReader();
-        minfo.readMemInfo();
-        mTotalMemMb = minfo.getTotalSize()/(1024*1024);
-        updateOomLevels(0, 0, false);
-    }
-
-    void applyDisplaySize(WindowManagerService wm) {
-        if (!mHaveDisplaySize) {
-            Point p = new Point();
-            wm.getBaseDisplaySize(Display.DEFAULT_DISPLAY, p);
-            if (p.x != 0 && p.y != 0) {
-                updateOomLevels(p.x, p.y, true);
-                mHaveDisplaySize = true;
-            }
-        }
-    }
-
-    private void updateOomLevels(int displayWidth, int displayHeight, boolean write) {
-        // Scale buckets from avail memory: at 300MB we use the lowest values to
-        // 700MB or more for the top values.
-        float scaleMem = ((float)(mTotalMemMb-300))/(700-300);
-
-        // Scale buckets from screen size.
-        int minSize = 480*800;  //  384000
-        int maxSize = 1280*800; // 1024000  230400 870400  .264
-        float scaleDisp = ((float)(displayWidth*displayHeight)-minSize)/(maxSize-minSize);
-        if (false) {
-            Slog.i("XXXXXX", "scaleMem=" + scaleMem);
-            Slog.i("XXXXXX", "scaleDisp=" + scaleDisp + " dw=" + displayWidth
-                    + " dh=" + displayHeight);
-        }
-
-        StringBuilder adjString = new StringBuilder();
-        StringBuilder memString = new StringBuilder();
-
-        float scale = scaleMem > scaleDisp ? scaleMem : scaleDisp;
-        if (scale < 0) scale = 0;
-        else if (scale > 1) scale = 1;
-        int minfree_adj = Resources.getSystem().getInteger(
-                com.android.internal.R.integer.config_lowMemoryKillerMinFreeKbytesAdjust);
-        int minfree_abs = Resources.getSystem().getInteger(
-                com.android.internal.R.integer.config_lowMemoryKillerMinFreeKbytesAbsolute);
-        if (false) {
-            Slog.i("XXXXXX", "minfree_adj=" + minfree_adj + " minfree_abs=" + minfree_abs);
-        }
-
-        for (int i=0; i<mOomAdj.length; i++) {
-            long low = mOomMinFreeLow[i];
-            long high = mOomMinFreeHigh[i];
-            mOomMinFree[i] = (long)(low + ((high-low)*scale));
-        }
-
-        if (minfree_abs >= 0) {
-            for (int i=0; i<mOomAdj.length; i++) {
-                mOomMinFree[i] = (long)((float)minfree_abs * mOomMinFree[i] / mOomMinFree[mOomAdj.length - 1]);
-            }
-        }
-
-        if (minfree_adj != 0) {
-            for (int i=0; i<mOomAdj.length; i++) {
-                mOomMinFree[i] += (long)((float)minfree_adj * mOomMinFree[i] / mOomMinFree[mOomAdj.length - 1]);
-                if (mOomMinFree[i] < 0) {
-                    mOomMinFree[i] = 0;
-                }
-            }
-        }
-
-        // The maximum size we will restore a process from cached to background, when under
-        // memory duress, is 1/3 the size we have reserved for kernel caches and other overhead
-        // before killing background processes.
-        mCachedRestoreLevel = (getMemLevel(ProcessList.CACHED_APP_MAX_ADJ)/1024) / 3;
-
-        for (int i=0; i<mOomAdj.length; i++) {
-            if (i > 0) {
-                adjString.append(',');
-                memString.append(',');
-            }
-            adjString.append(mOomAdj[i]);
-            memString.append((mOomMinFree[i]*1024)/PAGE_SIZE);
-        }
-
-        // Ask the kernel to try to keep enough memory free to allocate 3 full
-        // screen 32bpp buffers without entering direct reclaim.
-        int reserve = displayWidth * displayHeight * 4 * 3 / 1024;
-        int reserve_adj = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAdjust);
-        int reserve_abs = Resources.getSystem().getInteger(com.android.internal.R.integer.config_extraFreeKbytesAbsolute);
-
-        if (reserve_abs >= 0) {
-            reserve = reserve_abs;
-        }
-
-        if (reserve_adj != 0) {
-            reserve += reserve_adj;
-            if (reserve < 0) {
-                reserve = 0;
-            }
-        }
-
-        //Slog.i("XXXXXXX", "******************************* MINFREE: " + memString);
-        if (write) {
-            writeFile("/sys/module/lowmemorykiller/parameters/adj", adjString.toString());
-            writeFile("/sys/module/lowmemorykiller/parameters/minfree", memString.toString());
-            SystemProperties.set("sys.sysctl.extra_free_kbytes", Integer.toString(reserve));
-        }
-        // GB: 2048,3072,4096,6144,7168,8192
-        // HC: 8192,10240,12288,14336,16384,20480
-    }
-
-    public static int computeEmptyProcessLimit(int totalProcessLimit) {
-        return (totalProcessLimit*2)/3;
-    }
-
-    private static String buildOomTag(String prefix, String space, int val, int base) {
-        if (val == base) {
-            if (space == null) return prefix;
-            return prefix + "  ";
-        }
-        return prefix + "+" + Integer.toString(val-base);
-    }
-
-    public static String makeOomAdjString(int setAdj) {
-        if (setAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
-            return buildOomTag("cch", "  ", setAdj, ProcessList.CACHED_APP_MIN_ADJ);
-        } else if (setAdj >= ProcessList.SERVICE_B_ADJ) {
-            return buildOomTag("svcb ", null, setAdj, ProcessList.SERVICE_B_ADJ);
-        } else if (setAdj >= ProcessList.PREVIOUS_APP_ADJ) {
-            return buildOomTag("prev ", null, setAdj, ProcessList.PREVIOUS_APP_ADJ);
-        } else if (setAdj >= ProcessList.HOME_APP_ADJ) {
-            return buildOomTag("home ", null, setAdj, ProcessList.HOME_APP_ADJ);
-        } else if (setAdj >= ProcessList.SERVICE_ADJ) {
-            return buildOomTag("svc  ", null, setAdj, ProcessList.SERVICE_ADJ);
-        } else if (setAdj >= ProcessList.HEAVY_WEIGHT_APP_ADJ) {
-            return buildOomTag("hvy  ", null, setAdj, ProcessList.HEAVY_WEIGHT_APP_ADJ);
-        } else if (setAdj >= ProcessList.BACKUP_APP_ADJ) {
-            return buildOomTag("bkup ", null, setAdj, ProcessList.BACKUP_APP_ADJ);
-        } else if (setAdj >= ProcessList.PERCEPTIBLE_APP_ADJ) {
-            return buildOomTag("prcp ", null, setAdj, ProcessList.PERCEPTIBLE_APP_ADJ);
-        } else if (setAdj >= ProcessList.VISIBLE_APP_ADJ) {
-            return buildOomTag("vis  ", null, setAdj, ProcessList.VISIBLE_APP_ADJ);
-        } else if (setAdj >= ProcessList.FOREGROUND_APP_ADJ) {
-            return buildOomTag("fore ", null, setAdj, ProcessList.FOREGROUND_APP_ADJ);
-        } else if (setAdj >= ProcessList.PERSISTENT_PROC_ADJ) {
-            return buildOomTag("pers ", null, setAdj, ProcessList.PERSISTENT_PROC_ADJ);
-        } else if (setAdj >= ProcessList.SYSTEM_ADJ) {
-            return buildOomTag("sys  ", null, setAdj, ProcessList.SYSTEM_ADJ);
-        } else if (setAdj >= ProcessList.NATIVE_ADJ) {
-            return buildOomTag("ntv  ", null, setAdj, ProcessList.NATIVE_ADJ);
-        } else {
-            return Integer.toString(setAdj);
-        }
-    }
-
-    public static String makeProcStateString(int curProcState) {
-        String procState;
-        switch (curProcState) {
-            case -1:
-                procState = "N ";
-                break;
-            case ActivityManager.PROCESS_STATE_PERSISTENT:
-                procState = "P ";
-                break;
-            case ActivityManager.PROCESS_STATE_PERSISTENT_UI:
-                procState = "PU";
-                break;
-            case ActivityManager.PROCESS_STATE_TOP:
-                procState = "T ";
-                break;
-            case ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND:
-                procState = "IF";
-                break;
-            case ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND:
-                procState = "IB";
-                break;
-            case ActivityManager.PROCESS_STATE_BACKUP:
-                procState = "BU";
-                break;
-            case ActivityManager.PROCESS_STATE_HEAVY_WEIGHT:
-                procState = "HW";
-                break;
-            case ActivityManager.PROCESS_STATE_SERVICE:
-                procState = "S ";
-                break;
-            case ActivityManager.PROCESS_STATE_RECEIVER:
-                procState = "R ";
-                break;
-            case ActivityManager.PROCESS_STATE_HOME:
-                procState = "HO";
-                break;
-            case ActivityManager.PROCESS_STATE_LAST_ACTIVITY:
-                procState = "LA";
-                break;
-            case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY:
-                procState = "CA";
-                break;
-            case ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT:
-                procState = "Ca";
-                break;
-            case ActivityManager.PROCESS_STATE_CACHED_EMPTY:
-                procState = "CE";
-                break;
-            default:
-                procState = "??";
-                break;
-        }
-        return procState;
-    }
-
-    public static void appendRamKb(StringBuilder sb, long ramKb) {
-        for (int j=0, fact=10; j<6; j++, fact*=10) {
-            if (ramKb < fact) {
-                sb.append(' ');
-            }
-        }
-        sb.append(ramKb);
-    }
-
-    // The minimum amount of time after a state change it is safe ro collect PSS.
-    public static final int PSS_MIN_TIME_FROM_STATE_CHANGE = 15*1000;
-
-    // The maximum amount of time we want to go between PSS collections.
-    public static final int PSS_MAX_INTERVAL = 30*60*1000;
-
-    // The minimum amount of time between successive PSS requests for *all* processes.
-    public static final int PSS_ALL_INTERVAL = 10*60*1000;
-
-    // The minimum amount of time between successive PSS requests for a process.
-    private static final int PSS_SHORT_INTERVAL = 2*60*1000;
-
-    // The amount of time until PSS when a process first becomes top.
-    private static final int PSS_FIRST_TOP_INTERVAL = 10*1000;
-
-    // The amount of time until PSS when a process first goes into the background.
-    private static final int PSS_FIRST_BACKGROUND_INTERVAL = 20*1000;
-
-    // The amount of time until PSS when a process first becomes cached.
-    private static final int PSS_FIRST_CACHED_INTERVAL = 30*1000;
-
-    // The amount of time until PSS when an important process stays in the same state.
-    private static final int PSS_SAME_IMPORTANT_INTERVAL = 15*60*1000;
-
-    // The amount of time until PSS when a service process stays in the same state.
-    private static final int PSS_SAME_SERVICE_INTERVAL = 20*60*1000;
-
-    // The amount of time until PSS when a cached process stays in the same state.
-    private static final int PSS_SAME_CACHED_INTERVAL = 30*60*1000;
-
-    public static final int PROC_MEM_PERSISTENT = 0;
-    public static final int PROC_MEM_TOP = 1;
-    public static final int PROC_MEM_IMPORTANT = 2;
-    public static final int PROC_MEM_SERVICE = 3;
-    public static final int PROC_MEM_CACHED = 4;
-
-    private static final int[] sProcStateToProcMem = new int[] {
-        PROC_MEM_PERSISTENT,            // ActivityManager.PROCESS_STATE_PERSISTENT
-        PROC_MEM_PERSISTENT,            // ActivityManager.PROCESS_STATE_PERSISTENT_UI
-        PROC_MEM_TOP,                   // ActivityManager.PROCESS_STATE_TOP
-        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
-        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
-        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_BACKUP
-        PROC_MEM_IMPORTANT,             // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT
-        PROC_MEM_SERVICE,               // ActivityManager.PROCESS_STATE_SERVICE
-        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_RECEIVER
-        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_HOME
-        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_LAST_ACTIVITY
-        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY
-        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT
-        PROC_MEM_CACHED,                // ActivityManager.PROCESS_STATE_CACHED_EMPTY
-    };
-
-    private static final long[] sFirstAwakePssTimes = new long[] {
-        PSS_SHORT_INTERVAL,             // ActivityManager.PROCESS_STATE_PERSISTENT
-        PSS_SHORT_INTERVAL,             // ActivityManager.PROCESS_STATE_PERSISTENT_UI
-        PSS_FIRST_TOP_INTERVAL,         // ActivityManager.PROCESS_STATE_TOP
-        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
-        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
-        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_BACKUP
-        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT
-        PSS_FIRST_BACKGROUND_INTERVAL,  // ActivityManager.PROCESS_STATE_SERVICE
-        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_RECEIVER
-        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_HOME
-        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_LAST_ACTIVITY
-        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY
-        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT
-        PSS_FIRST_CACHED_INTERVAL,      // ActivityManager.PROCESS_STATE_CACHED_EMPTY
-    };
-
-    private static final long[] sSameAwakePssTimes = new long[] {
-        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_PERSISTENT
-        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_PERSISTENT_UI
-        PSS_SHORT_INTERVAL,             // ActivityManager.PROCESS_STATE_TOP
-        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_IMPORTANT_FOREGROUND
-        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND
-        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_BACKUP
-        PSS_SAME_IMPORTANT_INTERVAL,    // ActivityManager.PROCESS_STATE_HEAVY_WEIGHT
-        PSS_SAME_SERVICE_INTERVAL,      // ActivityManager.PROCESS_STATE_SERVICE
-        PSS_SAME_SERVICE_INTERVAL,      // ActivityManager.PROCESS_STATE_RECEIVER
-        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_HOME
-        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_LAST_ACTIVITY
-        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY
-        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_CACHED_ACTIVITY_CLIENT
-        PSS_SAME_CACHED_INTERVAL,       // ActivityManager.PROCESS_STATE_CACHED_EMPTY
-    };
-
-    public static boolean procStatesDifferForMem(int procState1, int procState2) {
-        return sProcStateToProcMem[procState1] != sProcStateToProcMem[procState2];
-    }
-
-    public static long computeNextPssTime(int procState, boolean first, boolean sleeping,
-            long now) {
-        final long[] table = sleeping
-                ? (first
-                        ? sFirstAwakePssTimes
-                        : sSameAwakePssTimes)
-                : (first
-                        ? sFirstAwakePssTimes
-                        : sSameAwakePssTimes);
-        return now + table[procState];
-    }
-
-    long getMemLevel(int adjustment) {
-        for (int i=0; i<mOomAdj.length; i++) {
-            if (adjustment <= mOomAdj[i]) {
-                return mOomMinFree[i] * 1024;
-            }
-        }
-        return mOomMinFree[mOomAdj.length-1] * 1024;
-    }
-
-    /**
-     * Return the maximum pss size in kb that we consider a process acceptable to
-     * restore from its cached state for running in the background when RAM is low.
-     */
-    long getCachedRestoreThresholdKb() {
-        return mCachedRestoreLevel;
-    }
-
-    private void writeFile(String path, String data) {
-        FileOutputStream fos = null;
-        try {
-            fos = new FileOutputStream(path);
-            fos.write(data.getBytes());
-        } catch (IOException e) {
-            Slog.w(ActivityManagerService.TAG, "Unable to write " + path);
-        } finally {
-            if (fos != null) {
-                try {
-                    fos.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/am/ServiceRecord.java b/services/java/com/android/server/am/ServiceRecord.java
deleted file mode 100644
index 80e6e94..0000000
--- a/services/java/com/android/server/am/ServiceRecord.java
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * Copyright (C) 2006 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 com.android.internal.app.ProcessStats;
-import com.android.internal.os.BatteryStatsImpl;
-import com.android.server.NotificationManagerService;
-
-import android.app.INotificationManager;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ServiceInfo;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.util.ArrayMap;
-import android.util.Slog;
-import android.util.TimeUtils;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A running application service.
- */
-final class ServiceRecord extends Binder {
-    // Maximum number of delivery attempts before giving up.
-    static final int MAX_DELIVERY_COUNT = 3;
-
-    // Maximum number of times it can fail during execution before giving up.
-    static final int MAX_DONE_EXECUTING_COUNT = 6;
-
-    final ActivityManagerService ams;
-    final BatteryStatsImpl.Uid.Pkg.Serv stats;
-    final ComponentName name; // service component.
-    final String shortName; // name.flattenToShortString().
-    final Intent.FilterComparison intent;
-                            // original intent used to find service.
-    final ServiceInfo serviceInfo;
-                            // all information about the service.
-    final ApplicationInfo appInfo;
-                            // information about service's app.
-    final int userId;       // user that this service is running as
-    final String packageName; // the package implementing intent's component
-    final String processName; // process where this component wants to run
-    final String permission;// permission needed to access service
-    final String baseDir;   // where activity source (resources etc) located
-    final String resDir;   // where public activity source (public resources etc) located
-    final String dataDir;   // where activity data should go
-    final boolean exported; // from ServiceInfo.exported
-    final Runnable restarter; // used to schedule retries of starting the service
-    final long createTime;  // when this service was created
-    final ArrayMap<Intent.FilterComparison, IntentBindRecord> bindings
-            = new ArrayMap<Intent.FilterComparison, IntentBindRecord>();
-                            // All active bindings to the service.
-    final ArrayMap<IBinder, ArrayList<ConnectionRecord>> connections
-            = new ArrayMap<IBinder, ArrayList<ConnectionRecord>>();
-                            // IBinder -> ConnectionRecord of all bound clients
-
-    ProcessRecord app;      // where this service is running or null.
-    ProcessRecord isolatedProc; // keep track of isolated process, if requested
-    ProcessStats.ServiceState tracker; // tracking service execution, may be null
-    ProcessStats.ServiceState restartTracker; // tracking service restart
-    boolean delayed;        // are we waiting to start this service in the background?
-    boolean isForeground;   // is service currently in foreground mode?
-    int foregroundId;       // Notification ID of last foreground req.
-    Notification foregroundNoti; // Notification record of foreground state.
-    long lastActivity;      // last time there was some activity on the service.
-    long startingBgTimeout;  // time at which we scheduled this for a delayed start.
-    boolean startRequested; // someone explicitly called start?
-    boolean delayedStop;    // service has been stopped but is in a delayed start?
-    boolean stopIfKilled;   // last onStart() said to stop if service killed?
-    boolean callStart;      // last onStart() has asked to alway be called on restart.
-    int executeNesting;     // number of outstanding operations keeping foreground.
-    boolean executeFg;      // should we be executing in the foreground?
-    long executingStart;    // start time of last execute request.
-    boolean createdFromFg;  // was this service last created due to a foreground process call?
-    int crashCount;         // number of times proc has crashed with service running
-    int totalRestartCount;  // number of times we have had to restart.
-    int restartCount;       // number of restarts performed in a row.
-    long restartDelay;      // delay until next restart attempt.
-    long restartTime;       // time of last restart.
-    long nextRestartTime;   // time when restartDelay will expire.
-
-    String stringName;      // caching of toString
-    
-    private int lastStartId;    // identifier of most recent start request.
-
-    static class StartItem {
-        final ServiceRecord sr;
-        final boolean taskRemoved;
-        final int id;
-        final Intent intent;
-        final ActivityManagerService.NeededUriGrants neededGrants;
-        long deliveredTime;
-        int deliveryCount;
-        int doneExecutingCount;
-        UriPermissionOwner uriPermissions;
-
-        String stringName;      // caching of toString
-
-        StartItem(ServiceRecord _sr, boolean _taskRemoved, int _id, Intent _intent,
-                ActivityManagerService.NeededUriGrants _neededGrants) {
-            sr = _sr;
-            taskRemoved = _taskRemoved;
-            id = _id;
-            intent = _intent;
-            neededGrants = _neededGrants;
-        }
-
-        UriPermissionOwner getUriPermissionsLocked() {
-            if (uriPermissions == null) {
-                uriPermissions = new UriPermissionOwner(sr.ams, this);
-            }
-            return uriPermissions;
-        }
-
-        void removeUriPermissionsLocked() {
-            if (uriPermissions != null) {
-                uriPermissions.removeUriPermissionsLocked();
-                uriPermissions = null;
-            }
-        }
-
-        public String toString() {
-            if (stringName != null) {
-                return stringName;
-            }
-            StringBuilder sb = new StringBuilder(128);
-            sb.append("ServiceRecord{")
-                .append(Integer.toHexString(System.identityHashCode(sr)))
-                .append(' ').append(sr.shortName)
-                .append(" StartItem ")
-                .append(Integer.toHexString(System.identityHashCode(this)))
-                .append(" id=").append(id).append('}');
-            return stringName = sb.toString();
-        }
-    }
-
-    final ArrayList<StartItem> deliveredStarts = new ArrayList<StartItem>();
-                            // start() arguments which been delivered.
-    final ArrayList<StartItem> pendingStarts = new ArrayList<StartItem>();
-                            // start() arguments that haven't yet been delivered.
-
-    void dumpStartList(PrintWriter pw, String prefix, List<StartItem> list, long now) {
-        final int N = list.size();
-        for (int i=0; i<N; i++) {
-            StartItem si = list.get(i);
-            pw.print(prefix); pw.print("#"); pw.print(i);
-                    pw.print(" id="); pw.print(si.id);
-                    if (now != 0) {
-                        pw.print(" dur=");
-                        TimeUtils.formatDuration(si.deliveredTime, now, pw);
-                    }
-                    if (si.deliveryCount != 0) {
-                        pw.print(" dc="); pw.print(si.deliveryCount);
-                    }
-                    if (si.doneExecutingCount != 0) {
-                        pw.print(" dxc="); pw.print(si.doneExecutingCount);
-                    }
-                    pw.println("");
-            pw.print(prefix); pw.print("  intent=");
-                    if (si.intent != null) pw.println(si.intent.toString());
-                    else pw.println("null");
-            if (si.neededGrants != null) {
-                pw.print(prefix); pw.print("  neededGrants=");
-                        pw.println(si.neededGrants);
-            }
-            if (si.uriPermissions != null) {
-                if (si.uriPermissions.readUriPermissions != null) {
-                    pw.print(prefix); pw.print("  readUriPermissions=");
-                            pw.println(si.uriPermissions.readUriPermissions);
-                }
-                if (si.uriPermissions.writeUriPermissions != null) {
-                    pw.print(prefix); pw.print("  writeUriPermissions=");
-                            pw.println(si.uriPermissions.writeUriPermissions);
-                }
-            }
-        }
-    }
-    
-    void dump(PrintWriter pw, String prefix) {
-        pw.print(prefix); pw.print("intent={");
-                pw.print(intent.getIntent().toShortString(false, true, false, true));
-                pw.println('}');
-        pw.print(prefix); pw.print("packageName="); pw.println(packageName);
-        pw.print(prefix); pw.print("processName="); pw.println(processName);
-        if (permission != null) {
-            pw.print(prefix); pw.print("permission="); pw.println(permission);
-        }
-        long now = SystemClock.uptimeMillis();
-        long nowReal = SystemClock.elapsedRealtime();
-        pw.print(prefix); pw.print("baseDir="); pw.println(baseDir);
-        if (!resDir.equals(baseDir)) {
-            pw.print(prefix); pw.print("resDir="); pw.println(resDir);
-        }
-        pw.print(prefix); pw.print("dataDir="); pw.println(dataDir);
-        pw.print(prefix); pw.print("app="); pw.println(app);
-        if (isolatedProc != null) {
-            pw.print(prefix); pw.print("isolatedProc="); pw.println(isolatedProc);
-        }
-        if (delayed) {
-            pw.print(prefix); pw.print("delayed="); pw.println(delayed);
-        }
-        if (isForeground || foregroundId != 0) {
-            pw.print(prefix); pw.print("isForeground="); pw.print(isForeground);
-                    pw.print(" foregroundId="); pw.print(foregroundId);
-                    pw.print(" foregroundNoti="); pw.println(foregroundNoti);
-        }
-        pw.print(prefix); pw.print("createTime=");
-                TimeUtils.formatDuration(createTime, nowReal, pw);
-                pw.print(" startingBgTimeout=");
-                TimeUtils.formatDuration(startingBgTimeout, now, pw);
-                pw.println();
-        pw.print(prefix); pw.print("lastActivity=");
-                TimeUtils.formatDuration(lastActivity, now, pw);
-                pw.print(" restartTime=");
-                TimeUtils.formatDuration(restartTime, now, pw);
-                pw.print(" createdFromFg="); pw.println(createdFromFg);
-        if (startRequested || delayedStop || lastStartId != 0) {
-            pw.print(prefix); pw.print("startRequested="); pw.print(startRequested);
-                    pw.print(" delayedStop="); pw.print(delayedStop);
-                    pw.print(" stopIfKilled="); pw.print(stopIfKilled);
-                    pw.print(" callStart="); pw.print(callStart);
-                    pw.print(" lastStartId="); pw.println(lastStartId);
-        }
-        if (executeNesting != 0) {
-            pw.print(prefix); pw.print("executeNesting="); pw.print(executeNesting);
-                    pw.print(" executeFg="); pw.print(executeFg);
-                    pw.print(" executingStart=");
-                    TimeUtils.formatDuration(executingStart, now, pw);
-                    pw.println();
-        }
-        if (crashCount != 0 || restartCount != 0
-                || restartDelay != 0 || nextRestartTime != 0) {
-            pw.print(prefix); pw.print("restartCount="); pw.print(restartCount);
-                    pw.print(" restartDelay=");
-                    TimeUtils.formatDuration(restartDelay, now, pw);
-                    pw.print(" nextRestartTime=");
-                    TimeUtils.formatDuration(nextRestartTime, now, pw);
-                    pw.print(" crashCount="); pw.println(crashCount);
-        }
-        if (deliveredStarts.size() > 0) {
-            pw.print(prefix); pw.println("Delivered Starts:");
-            dumpStartList(pw, prefix, deliveredStarts, now);
-        }
-        if (pendingStarts.size() > 0) {
-            pw.print(prefix); pw.println("Pending Starts:");
-            dumpStartList(pw, prefix, pendingStarts, 0);
-        }
-        if (bindings.size() > 0) {
-            pw.print(prefix); pw.println("Bindings:");
-            for (int i=0; i<bindings.size(); i++) {
-                IntentBindRecord b = bindings.valueAt(i);
-                pw.print(prefix); pw.print("* IntentBindRecord{");
-                        pw.print(Integer.toHexString(System.identityHashCode(b)));
-                        if ((b.collectFlags()&Context.BIND_AUTO_CREATE) != 0) {
-                            pw.append(" CREATE");
-                        }
-                        pw.println("}:");
-                b.dumpInService(pw, prefix + "  ");
-            }
-        }
-        if (connections.size() > 0) {
-            pw.print(prefix); pw.println("All Connections:");
-            for (int conni=0; conni<connections.size(); conni++) {
-                ArrayList<ConnectionRecord> c = connections.valueAt(conni);
-                for (int i=0; i<c.size(); i++) {
-                    pw.print(prefix); pw.print("  "); pw.println(c.get(i));
-                }
-            }
-        }
-    }
-
-    ServiceRecord(ActivityManagerService ams,
-            BatteryStatsImpl.Uid.Pkg.Serv servStats, ComponentName name,
-            Intent.FilterComparison intent, ServiceInfo sInfo, boolean callerIsFg,
-            Runnable restarter) {
-        this.ams = ams;
-        this.stats = servStats;
-        this.name = name;
-        shortName = name.flattenToShortString();
-        this.intent = intent;
-        serviceInfo = sInfo;
-        appInfo = sInfo.applicationInfo;
-        packageName = sInfo.applicationInfo.packageName;
-        processName = sInfo.processName;
-        permission = sInfo.permission;
-        baseDir = sInfo.applicationInfo.sourceDir;
-        resDir = sInfo.applicationInfo.publicSourceDir;
-        dataDir = sInfo.applicationInfo.dataDir;
-        exported = sInfo.exported;
-        this.restarter = restarter;
-        createTime = SystemClock.elapsedRealtime();
-        lastActivity = SystemClock.uptimeMillis();
-        userId = UserHandle.getUserId(appInfo.uid);
-        createdFromFg = callerIsFg;
-    }
-
-    public ProcessStats.ServiceState getTracker() {
-        if (tracker != null) {
-            return tracker;
-        }
-        if ((serviceInfo.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) == 0) {
-            tracker = ams.mProcessStats.getServiceStateLocked(serviceInfo.packageName,
-                    serviceInfo.applicationInfo.uid, serviceInfo.processName, serviceInfo.name);
-            tracker.applyNewOwner(this);
-        }
-        return tracker;
-    }
-
-    public void forceClearTracker() {
-        if (tracker != null) {
-            tracker.clearCurrentOwner(this, true);
-            tracker = null;
-        }
-    }
-
-    public void makeRestarting(int memFactor, long now) {
-        if (restartTracker == null) {
-            if ((serviceInfo.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) == 0) {
-                restartTracker = ams.mProcessStats.getServiceStateLocked(serviceInfo.packageName,
-                        serviceInfo.applicationInfo.uid, serviceInfo.processName, serviceInfo.name);
-            }
-            if (restartTracker == null) {
-                return;
-            }
-        }
-        restartTracker.setRestarting(true, memFactor, now);
-    }
-
-    public AppBindRecord retrieveAppBindingLocked(Intent intent,
-            ProcessRecord app) {
-        Intent.FilterComparison filter = new Intent.FilterComparison(intent);
-        IntentBindRecord i = bindings.get(filter);
-        if (i == null) {
-            i = new IntentBindRecord(this, filter);
-            bindings.put(filter, i);
-        }
-        AppBindRecord a = i.apps.get(app);
-        if (a != null) {
-            return a;
-        }
-        a = new AppBindRecord(this, i, app);
-        i.apps.put(app, a);
-        return a;
-    }
-
-    public boolean hasAutoCreateConnections() {
-        // XXX should probably keep a count of the number of auto-create
-        // connections directly in the service.
-        for (int conni=connections.size()-1; conni>=0; conni--) {
-            ArrayList<ConnectionRecord> cr = connections.valueAt(conni);
-            for (int i=0; i<cr.size(); i++) {
-                if ((cr.get(i).flags&Context.BIND_AUTO_CREATE) != 0) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    public void resetRestartCounter() {
-        restartCount = 0;
-        restartDelay = 0;
-        restartTime = 0;
-    }
-    
-    public StartItem findDeliveredStart(int id, boolean remove) {
-        final int N = deliveredStarts.size();
-        for (int i=0; i<N; i++) {
-            StartItem si = deliveredStarts.get(i);
-            if (si.id == id) {
-                if (remove) deliveredStarts.remove(i);
-                return si;
-            }
-        }
-        
-        return null;
-    }
-    
-    public int getLastStartId() {
-        return lastStartId;
-    }
-
-    public int makeNextStartId() {
-        lastStartId++;
-        if (lastStartId < 1) {
-            lastStartId = 1;
-        }
-        return lastStartId;
-    }
-
-    public void postNotification() {
-        final int appUid = appInfo.uid;
-        final int appPid = app.pid;
-        if (foregroundId != 0 && foregroundNoti != null) {
-            // Do asynchronous communication with notification manager to
-            // avoid deadlocks.
-            final String localPackageName = packageName;
-            final int localForegroundId = foregroundId;
-            final Notification localForegroundNoti = foregroundNoti;
-            ams.mHandler.post(new Runnable() {
-                public void run() {
-                    NotificationManagerService nm =
-                            (NotificationManagerService) NotificationManager.getService();
-                    if (nm == null) {
-                        return;
-                    }
-                    try {
-                        if (localForegroundNoti.icon == 0) {
-                            // It is not correct for the caller to supply a notification
-                            // icon, but this used to be able to slip through, so for
-                            // those dirty apps give it the app's icon.
-                            localForegroundNoti.icon = appInfo.icon;
-
-                            // Do not allow apps to present a sneaky invisible content view either.
-                            localForegroundNoti.contentView = null;
-                            localForegroundNoti.bigContentView = null;
-                            CharSequence appName = appInfo.loadLabel(
-                                    ams.mContext.getPackageManager());
-                            if (appName == null) {
-                                appName = appInfo.packageName;
-                            }
-                            Context ctx = null;
-                            try {
-                                ctx = ams.mContext.createPackageContext(
-                                        appInfo.packageName, 0);
-                                Intent runningIntent = new Intent(
-                                        Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
-                                runningIntent.setData(Uri.fromParts("package",
-                                        appInfo.packageName, null));
-                                PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0,
-                                        runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-                                localForegroundNoti.setLatestEventInfo(ctx,
-                                        ams.mContext.getString(
-                                                com.android.internal.R.string
-                                                        .app_running_notification_title,
-                                                appName),
-                                        ams.mContext.getString(
-                                                com.android.internal.R.string
-                                                        .app_running_notification_text,
-                                                appName),
-                                        pi);
-                            } catch (PackageManager.NameNotFoundException e) {
-                                localForegroundNoti.icon = 0;
-                            }
-                        }
-                        if (localForegroundNoti.icon == 0) {
-                            // Notifications whose icon is 0 are defined to not show
-                            // a notification, silently ignoring it.  We don't want to
-                            // just ignore it, we want to prevent the service from
-                            // being foreground.
-                            throw new RuntimeException("icon must be non-zero");
-                        }
-                        int[] outId = new int[1];
-                        nm.enqueueNotificationInternal(localPackageName, localPackageName,
-                                appUid, appPid, null, localForegroundId, localForegroundNoti,
-                                outId, userId);
-                    } catch (RuntimeException e) {
-                        Slog.w(ActivityManagerService.TAG,
-                                "Error showing notification for service", e);
-                        // If it gave us a garbage notification, it doesn't
-                        // get to be foreground.
-                        ams.setServiceForeground(name, ServiceRecord.this,
-                                0, null, true);
-                        ams.crashApplication(appUid, appPid, localPackageName,
-                                "Bad notification for startForeground: " + e);
-                    }
-                }
-            });
-        }
-    }
-    
-    public void cancelNotification() {
-        if (foregroundId != 0) {
-            // Do asynchronous communication with notification manager to
-            // avoid deadlocks.
-            final String localPackageName = packageName;
-            final int localForegroundId = foregroundId;
-            ams.mHandler.post(new Runnable() {
-                public void run() {
-                    INotificationManager inm = NotificationManager.getService();
-                    if (inm == null) {
-                        return;
-                    }
-                    try {
-                        inm.cancelNotificationWithTag(localPackageName, null,
-                                localForegroundId, userId);
-                    } catch (RuntimeException e) {
-                        Slog.w(ActivityManagerService.TAG,
-                                "Error canceling notification for service", e);
-                    } catch (RemoteException e) {
-                    }
-                }
-            });
-        }
-    }
-    
-    public void clearDeliveredStartsLocked() {
-        for (int i=deliveredStarts.size()-1; i>=0; i--) {
-            deliveredStarts.get(i).removeUriPermissionsLocked();
-        }
-        deliveredStarts.clear();
-    }
-
-    public String toString() {
-        if (stringName != null) {
-            return stringName;
-        }
-        StringBuilder sb = new StringBuilder(128);
-        sb.append("ServiceRecord{")
-            .append(Integer.toHexString(System.identityHashCode(this)))
-            .append(" u").append(userId)
-            .append(' ').append(shortName).append('}');
-        return stringName = sb.toString();
-    }
-}
diff --git a/services/java/com/android/server/am/TaskRecord.java b/services/java/com/android/server/am/TaskRecord.java
deleted file mode 100644
index 3d568ff..0000000
--- a/services/java/com/android/server/am/TaskRecord.java
+++ /dev/null
@@ -1,512 +0,0 @@
-/*
- * Copyright (C) 2006 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 static com.android.server.am.ActivityManagerService.TAG;
-import static com.android.server.am.ActivityStackSupervisor.DEBUG_ADD_REMOVE;
-
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.ActivityOptions;
-import android.app.IThumbnailRetriever;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.graphics.Bitmap;
-import android.os.UserHandle;
-import android.util.Slog;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-final class TaskRecord extends ThumbnailHolder {
-    final int taskId;       // Unique identifier for this task.
-    final String affinity;  // The affinity name for this task, or null.
-    Intent intent;          // The original intent that started the task.
-    Intent affinityIntent;  // Intent of affinity-moved activity that started this task.
-    ComponentName origActivity; // The non-alias activity component of the intent.
-    ComponentName realActivity; // The actual activity component that started the task.
-    int numActivities;      // Current number of activities in this task.
-    long lastActiveTime;    // Last time this task was active, including sleep.
-    boolean rootWasReset;   // True if the intent at the root of the task had
-                            // the FLAG_ACTIVITY_RESET_TASK_IF_NEEDED flag.
-    boolean askedCompatMode;// Have asked the user about compat mode for this task.
-
-    String stringName;      // caching of toString() result.
-    int userId;             // user for which this task was created
-
-    int numFullscreen;      // Number of fullscreen activities.
-
-    /** List of all activities in the task arranged in history order */
-    final ArrayList<ActivityRecord> mActivities = new ArrayList<ActivityRecord>();
-
-    /** Current stack */
-    ActivityStack stack;
-
-    /** Takes on same set of values as ActivityRecord.mActivityType */
-    private int mTaskType;
-
-    /** Launch the home activity when leaving this task. */
-    boolean mOnTopOfHome = false;
-
-    TaskRecord(int _taskId, ActivityInfo info, Intent _intent) {
-        taskId = _taskId;
-        affinity = info.taskAffinity;
-        setIntent(_intent, info);
-    }
-
-    void touchActiveTime() {
-        lastActiveTime = android.os.SystemClock.elapsedRealtime();
-    }
-
-    long getInactiveDuration() {
-        return android.os.SystemClock.elapsedRealtime() - lastActiveTime;
-    }
-
-    void setIntent(Intent _intent, ActivityInfo info) {
-        stringName = null;
-
-        if (info.targetActivity == null) {
-            if (_intent != null) {
-                // If this Intent has a selector, we want to clear it for the
-                // recent task since it is not relevant if the user later wants
-                // to re-launch the app.
-                if (_intent.getSelector() != null || _intent.getSourceBounds() != null) {
-                    _intent = new Intent(_intent);
-                    _intent.setSelector(null);
-                    _intent.setSourceBounds(null);
-                }
-            }
-            if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
-                    "Setting Intent of " + this + " to " + _intent);
-            intent = _intent;
-            realActivity = _intent != null ? _intent.getComponent() : null;
-            origActivity = null;
-        } else {
-            ComponentName targetComponent = new ComponentName(
-                    info.packageName, info.targetActivity);
-            if (_intent != null) {
-                Intent targetIntent = new Intent(_intent);
-                targetIntent.setComponent(targetComponent);
-                targetIntent.setSelector(null);
-                targetIntent.setSourceBounds(null);
-                if (ActivityManagerService.DEBUG_TASKS) Slog.v(ActivityManagerService.TAG,
-                        "Setting Intent of " + this + " to target " + targetIntent);
-                intent = targetIntent;
-                realActivity = targetComponent;
-                origActivity = _intent.getComponent();
-            } else {
-                intent = null;
-                realActivity = targetComponent;
-                origActivity = new ComponentName(info.packageName, info.name);
-            }
-        }
-
-        if (intent != null &&
-                (intent.getFlags()&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
-            // Once we are set to an Intent with this flag, we count this
-            // task as having a true root activity.
-            rootWasReset = true;
-        }
-
-        if (info.applicationInfo != null) {
-            userId = UserHandle.getUserId(info.applicationInfo.uid);
-        }
-    }
-
-    void disposeThumbnail() {
-        super.disposeThumbnail();
-        for (int i=mActivities.size()-1; i>=0; i--) {
-            ThumbnailHolder thumb = mActivities.get(i).thumbHolder;
-            if (thumb != this) {
-                thumb.disposeThumbnail();
-            }
-        }
-    }
-
-    ActivityRecord getTopActivity() {
-        for (int i = mActivities.size() - 1; i >= 0; --i) {
-            final ActivityRecord r = mActivities.get(i);
-            if (r.finishing) {
-                continue;
-            }
-            return r;
-        }
-        return null;
-    }
-
-    ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
-        for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
-            ActivityRecord r = mActivities.get(activityNdx);
-            if (!r.finishing && r != notTop && stack.okToShow(r)) {
-                return r;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Reorder the history stack so that the activity at the given index is
-     * brought to the front.
-     */
-    final void moveActivityToFrontLocked(ActivityRecord newTop) {
-        if (DEBUG_ADD_REMOVE) Slog.i(TAG, "Removing and adding activity " + newTop
-            + " to stack at top", new RuntimeException("here").fillInStackTrace());
-
-        getTopActivity().frontOfTask = false;
-        mActivities.remove(newTop);
-        mActivities.add(newTop);
-        newTop.frontOfTask = true;
-    }
-
-    void addActivityAtBottom(ActivityRecord r) {
-        addActivityAtIndex(0, r);
-    }
-
-    void addActivityToTop(ActivityRecord r) {
-        addActivityAtIndex(mActivities.size(), r);
-    }
-
-    void addActivityAtIndex(int index, ActivityRecord r) {
-        // Remove r first, and if it wasn't already in the list and it's fullscreen, count it.
-        if (!mActivities.remove(r) && r.fullscreen) {
-            // Was not previously in list.
-            numFullscreen++;
-        }
-        // Only set this based on the first activity
-        if (mActivities.isEmpty()) {
-            mTaskType = r.mActivityType;
-        } else {
-            // Otherwise make all added activities match this one.
-            r.mActivityType = mTaskType;
-        }
-        mActivities.add(index, r);
-    }
-
-    /** @return true if this was the last activity in the task */
-    boolean removeActivity(ActivityRecord r) {
-        if (mActivities.remove(r) && r.fullscreen) {
-            // Was previously in list.
-            numFullscreen--;
-        }
-        return mActivities.size() == 0;
-    }
-
-    /**
-     * Completely remove all activities associated with an existing
-     * task starting at a specified index.
-     */
-    final void performClearTaskAtIndexLocked(int activityNdx) {
-        int numActivities = mActivities.size();
-        for ( ; activityNdx < numActivities; ++activityNdx) {
-            final ActivityRecord r = mActivities.get(activityNdx);
-            if (r.finishing) {
-                continue;
-            }
-            if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear", false)) {
-                --activityNdx;
-                --numActivities;
-            }
-        }
-    }
-
-    /**
-     * Completely remove all activities associated with an existing task.
-     */
-    final void performClearTaskLocked() {
-        performClearTaskAtIndexLocked(0);
-    }
-
-    /**
-     * Perform clear operation as requested by
-     * {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the
-     * stack to the given task, then look for
-     * an instance of that activity in the stack and, if found, finish all
-     * activities on top of it and return the instance.
-     *
-     * @param newR Description of the new activity being started.
-     * @return Returns the old activity that should be continued to be used,
-     * or null if none was found.
-     */
-    final ActivityRecord performClearTaskLocked(ActivityRecord newR, int launchFlags) {
-        int numActivities = mActivities.size();
-        for (int activityNdx = numActivities - 1; activityNdx >= 0; --activityNdx) {
-            ActivityRecord r = mActivities.get(activityNdx);
-            if (r.finishing) {
-                continue;
-            }
-            if (r.realActivity.equals(newR.realActivity)) {
-                // Here it is!  Now finish everything in front...
-                final ActivityRecord ret = r;
-
-                for (++activityNdx; activityNdx < numActivities; ++activityNdx) {
-                    r = mActivities.get(activityNdx);
-                    if (r.finishing) {
-                        continue;
-                    }
-                    ActivityOptions opts = r.takeOptionsLocked();
-                    if (opts != null) {
-                        ret.updateOptionsLocked(opts);
-                    }
-                    if (stack.finishActivityLocked(r, Activity.RESULT_CANCELED, null, "clear",
-                            false)) {
-                        --activityNdx;
-                        --numActivities;
-                    }
-                }
-
-                // Finally, if this is a normal launch mode (that is, not
-                // expecting onNewIntent()), then we will finish the current
-                // instance of the activity so a new fresh one can be started.
-                if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE
-                        && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
-                    if (!ret.finishing) {
-                        stack.finishActivityLocked(ret, Activity.RESULT_CANCELED, null,
-                                "clear", false);
-                        return null;
-                    }
-                }
-
-                return ret;
-            }
-        }
-
-        return null;
-    }
-
-    public ActivityManager.TaskThumbnails getTaskThumbnailsLocked() {
-        TaskAccessInfo info = getTaskAccessInfoLocked(true);
-        final ActivityRecord resumedActivity = stack.mResumedActivity;
-        if (resumedActivity != null && resumedActivity.thumbHolder == this) {
-            info.mainThumbnail = stack.screenshotActivities(resumedActivity);
-        }
-        if (info.mainThumbnail == null) {
-            info.mainThumbnail = lastThumbnail;
-        }
-        return info;
-    }
-
-    public Bitmap getTaskTopThumbnailLocked() {
-        final ActivityRecord resumedActivity = stack.mResumedActivity;
-        if (resumedActivity != null && resumedActivity.task == this) {
-            // This task is the current resumed task, we just need to take
-            // a screenshot of it and return that.
-            return stack.screenshotActivities(resumedActivity);
-        }
-        // Return the information about the task, to figure out the top
-        // thumbnail to return.
-        TaskAccessInfo info = getTaskAccessInfoLocked(true);
-        if (info.numSubThumbbails <= 0) {
-            return info.mainThumbnail != null ? info.mainThumbnail : lastThumbnail;
-        }
-        return info.subtasks.get(info.numSubThumbbails-1).holder.lastThumbnail;
-    }
-
-    public ActivityRecord removeTaskActivitiesLocked(int subTaskIndex,
-            boolean taskRequired) {
-        TaskAccessInfo info = getTaskAccessInfoLocked(false);
-        if (info.root == null) {
-            if (taskRequired) {
-                Slog.w(TAG, "removeTaskLocked: unknown taskId " + taskId);
-            }
-            return null;
-        }
-
-        if (subTaskIndex < 0) {
-            // Just remove the entire task.
-            performClearTaskAtIndexLocked(info.rootIndex);
-            return info.root;
-        }
-
-        if (subTaskIndex >= info.subtasks.size()) {
-            if (taskRequired) {
-                Slog.w(TAG, "removeTaskLocked: unknown subTaskIndex " + subTaskIndex);
-            }
-            return null;
-        }
-
-        // Remove all of this task's activities starting at the sub task.
-        TaskAccessInfo.SubTask subtask = info.subtasks.get(subTaskIndex);
-        performClearTaskAtIndexLocked(subtask.index);
-        return subtask.activity;
-    }
-
-    boolean isHomeTask() {
-        return mTaskType == ActivityRecord.HOME_ACTIVITY_TYPE;
-    }
-
-    boolean isApplicationTask() {
-        return mTaskType == ActivityRecord.APPLICATION_ACTIVITY_TYPE;
-    }
-
-    public TaskAccessInfo getTaskAccessInfoLocked(boolean inclThumbs) {
-        final TaskAccessInfo thumbs = new TaskAccessInfo();
-        // How many different sub-thumbnails?
-        final int NA = mActivities.size();
-        int j = 0;
-        ThumbnailHolder holder = null;
-        while (j < NA) {
-            ActivityRecord ar = mActivities.get(j);
-            if (!ar.finishing) {
-                thumbs.root = ar;
-                thumbs.rootIndex = j;
-                holder = ar.thumbHolder;
-                if (holder != null) {
-                    thumbs.mainThumbnail = holder.lastThumbnail;
-                }
-                j++;
-                break;
-            }
-            j++;
-        }
-
-        if (j >= NA) {
-            return thumbs;
-        }
-
-        ArrayList<TaskAccessInfo.SubTask> subtasks = new ArrayList<TaskAccessInfo.SubTask>();
-        thumbs.subtasks = subtasks;
-        while (j < NA) {
-            ActivityRecord ar = mActivities.get(j);
-            j++;
-            if (ar.finishing) {
-                continue;
-            }
-            if (ar.thumbHolder != holder && holder != null) {
-                thumbs.numSubThumbbails++;
-                holder = ar.thumbHolder;
-                TaskAccessInfo.SubTask sub = new TaskAccessInfo.SubTask();
-                sub.holder = holder;
-                sub.activity = ar;
-                sub.index = j-1;
-                subtasks.add(sub);
-            }
-        }
-        if (thumbs.numSubThumbbails > 0) {
-            thumbs.retriever = new IThumbnailRetriever.Stub() {
-                @Override
-                public Bitmap getThumbnail(int index) {
-                    if (index < 0 || index >= thumbs.subtasks.size()) {
-                        return null;
-                    }
-                    TaskAccessInfo.SubTask sub = thumbs.subtasks.get(index);
-                    ActivityRecord resumedActivity = stack.mResumedActivity;
-                    if (resumedActivity != null && resumedActivity.thumbHolder == sub.holder) {
-                        return stack.screenshotActivities(resumedActivity);
-                    }
-                    return sub.holder.lastThumbnail;
-                }
-            };
-        }
-        return thumbs;
-    }
-
-    /**
-     * Find the activity in the history stack within the given task.  Returns
-     * the index within the history at which it's found, or < 0 if not found.
-     */
-    final ActivityRecord findActivityInHistoryLocked(ActivityRecord r) {
-        final ComponentName realActivity = r.realActivity;
-        for (int activityNdx = mActivities.size() - 1; activityNdx >= 0; --activityNdx) {
-            ActivityRecord candidate = mActivities.get(activityNdx);
-            if (candidate.finishing) {
-                continue;
-            }
-            if (candidate.realActivity.equals(realActivity)) {
-                return candidate;
-            }
-        }
-        return null;
-    }
-
-    void dump(PrintWriter pw, String prefix) {
-        if (numActivities != 0 || rootWasReset || userId != 0 || numFullscreen != 0) {
-            pw.print(prefix); pw.print("numActivities="); pw.print(numActivities);
-                    pw.print(" rootWasReset="); pw.print(rootWasReset);
-                    pw.print(" userId="); pw.print(userId);
-                    pw.print(" mTaskType="); pw.print(mTaskType);
-                    pw.print(" numFullscreen="); pw.print(numFullscreen);
-                    pw.print(" mOnTopOfHome="); pw.println(mOnTopOfHome);
-        }
-        if (affinity != null) {
-            pw.print(prefix); pw.print("affinity="); pw.println(affinity);
-        }
-        if (intent != null) {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append(prefix); sb.append("intent={");
-            intent.toShortString(sb, false, true, false, true);
-            sb.append('}');
-            pw.println(sb.toString());
-        }
-        if (affinityIntent != null) {
-            StringBuilder sb = new StringBuilder(128);
-            sb.append(prefix); sb.append("affinityIntent={");
-            affinityIntent.toShortString(sb, false, true, false, true);
-            sb.append('}');
-            pw.println(sb.toString());
-        }
-        if (origActivity != null) {
-            pw.print(prefix); pw.print("origActivity=");
-            pw.println(origActivity.flattenToShortString());
-        }
-        if (realActivity != null) {
-            pw.print(prefix); pw.print("realActivity=");
-            pw.println(realActivity.flattenToShortString());
-        }
-        pw.print(prefix); pw.print("Activities="); pw.println(mActivities);
-        if (!askedCompatMode) {
-            pw.print(prefix); pw.print("askedCompatMode="); pw.println(askedCompatMode);
-        }
-        pw.print(prefix); pw.print("lastThumbnail="); pw.print(lastThumbnail);
-                pw.print(" lastDescription="); pw.println(lastDescription);
-        pw.print(prefix); pw.print("lastActiveTime="); pw.print(lastActiveTime);
-                pw.print(" (inactive for ");
-                pw.print((getInactiveDuration()/1000)); pw.println("s)");
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder(128);
-        if (stringName != null) {
-            sb.append(stringName);
-            sb.append(" U=");
-            sb.append(userId);
-            sb.append(" sz=");
-            sb.append(mActivities.size());
-            sb.append('}');
-            return sb.toString();
-        }
-        sb.append("TaskRecord{");
-        sb.append(Integer.toHexString(System.identityHashCode(this)));
-        sb.append(" #");
-        sb.append(taskId);
-        if (affinity != null) {
-            sb.append(" A=");
-            sb.append(affinity);
-        } else if (intent != null) {
-            sb.append(" I=");
-            sb.append(intent.getComponent().flattenToShortString());
-        } else if (affinityIntent != null) {
-            sb.append(" aI=");
-            sb.append(affinityIntent.getComponent().flattenToShortString());
-        } else {
-            sb.append(" ??");
-        }
-        stringName = sb.toString();
-        return toString();
-    }
-}
diff --git a/services/java/com/android/server/am/UsageStatsService.java b/services/java/com/android/server/am/UsageStatsService.java
deleted file mode 100644
index e96d8b1..0000000
--- a/services/java/com/android/server/am/UsageStatsService.java
+++ /dev/null
@@ -1,1173 +0,0 @@
-/*
- * Copyright (C) 2006-2007 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.app.AppGlobals;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.os.Binder;
-import android.os.IBinder;
-import android.os.FileUtils;
-import android.os.Parcel;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.util.ArrayMap;
-import android.util.AtomicFile;
-import android.util.Slog;
-import android.util.Xml;
-
-import com.android.internal.app.IUsageStats;
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.os.PkgUsageStats;
-import com.android.internal.util.FastXmlSerializer;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TimeZone;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * This service collects the statistics associated with usage
- * of various components, like when a particular package is launched or
- * paused and aggregates events like number of time a component is launched
- * total duration of a component launch.
- */
-public final class UsageStatsService extends IUsageStats.Stub {
-    public static final String SERVICE_NAME = "usagestats";
-    private static final boolean localLOGV = false;
-    private static final boolean REPORT_UNEXPECTED = false;
-    private static final String TAG = "UsageStats";
-    
-    // Current on-disk Parcel version
-    private static final int VERSION = 1008;
-
-    private static final int CHECKIN_VERSION = 4;
-    
-    private static final String FILE_PREFIX = "usage-";
-
-    private static final String FILE_HISTORY = FILE_PREFIX + "history.xml";
-
-    private static final int FILE_WRITE_INTERVAL = 30*60*1000; //ms
-    
-    private static final int MAX_NUM_FILES = 5;
-    
-    private static final int NUM_LAUNCH_TIME_BINS = 10;
-    private static final int[] LAUNCH_TIME_BINS = {
-        250, 500, 750, 1000, 1500, 2000, 3000, 4000, 5000
-    };
-    
-    static IUsageStats sService;
-    private Context mContext;
-    // structure used to maintain statistics since the last checkin.
-    final private ArrayMap<String, PkgUsageStatsExtended> mStats;
-
-    // Maintains the last time any component was resumed, for all time.
-    final private ArrayMap<String, ArrayMap<String, Long>> mLastResumeTimes;
-
-    // To remove last-resume time stats when a pacakge is removed.
-    private PackageMonitor mPackageMonitor;
-
-    // Lock to update package stats. Methods suffixed by SLOCK should invoked with
-    // this lock held
-    final Object mStatsLock;
-    // Lock to write to file. Methods suffixed by FLOCK should invoked with
-    // this lock held.
-    final Object mFileLock;
-    // Order of locks is mFileLock followed by mStatsLock to avoid deadlocks
-    private String mLastResumedPkg;
-    private String mLastResumedComp;
-    private boolean mIsResumed;
-    private File mFile;
-    private AtomicFile mHistoryFile;
-    private String mFileLeaf;
-    private File mDir;
-
-    private Calendar mCal; // guarded by itself
-
-    private final AtomicInteger mLastWriteDay = new AtomicInteger(-1);
-    private final AtomicLong mLastWriteElapsedTime = new AtomicLong(0);
-    private final AtomicBoolean mUnforcedDiskWriteRunning = new AtomicBoolean(false);
-    
-    static class TimeStats {
-        int count;
-        int[] times = new int[NUM_LAUNCH_TIME_BINS];
-        
-        TimeStats() {
-        }
-        
-        void incCount() {
-            count++;
-        }
-        
-        void add(int val) {
-            final int[] bins = LAUNCH_TIME_BINS;
-            for (int i=0; i<NUM_LAUNCH_TIME_BINS-1; i++) {
-                if (val < bins[i]) {
-                    times[i]++;
-                    return;
-                }
-            }
-            times[NUM_LAUNCH_TIME_BINS-1]++;
-        }
-        
-        TimeStats(Parcel in) {
-            count = in.readInt();
-            final int[] localTimes = times;
-            for (int i=0; i<NUM_LAUNCH_TIME_BINS; i++) {
-                localTimes[i] = in.readInt();
-            }
-        }
-        
-        void writeToParcel(Parcel out) {
-            out.writeInt(count);
-            final int[] localTimes = times;
-            for (int i=0; i<NUM_LAUNCH_TIME_BINS; i++) {
-                out.writeInt(localTimes[i]);
-            }
-        }
-    }
-    
-    private class PkgUsageStatsExtended {
-        final ArrayMap<String, TimeStats> mLaunchTimes
-                = new ArrayMap<String, TimeStats>();
-        final ArrayMap<String, TimeStats> mFullyDrawnTimes
-                = new ArrayMap<String, TimeStats>();
-        int mLaunchCount;
-        long mUsageTime;
-        long mPausedTime;
-        long mResumedTime;
-        
-        PkgUsageStatsExtended() {
-            mLaunchCount = 0;
-            mUsageTime = 0;
-        }
-        
-        PkgUsageStatsExtended(Parcel in) {
-            mLaunchCount = in.readInt();
-            mUsageTime = in.readLong();
-            if (localLOGV) Slog.v(TAG, "Launch count: " + mLaunchCount
-                    + ", Usage time:" + mUsageTime);
-            
-            final int numLaunchTimeStats = in.readInt();
-            if (localLOGV) Slog.v(TAG, "Reading launch times: " + numLaunchTimeStats);
-            mLaunchTimes.ensureCapacity(numLaunchTimeStats);
-            for (int i=0; i<numLaunchTimeStats; i++) {
-                String comp = in.readString();
-                if (localLOGV) Slog.v(TAG, "Component: " + comp);
-                TimeStats times = new TimeStats(in);
-                mLaunchTimes.put(comp, times);
-            }
-
-            final int numFullyDrawnTimeStats = in.readInt();
-            if (localLOGV) Slog.v(TAG, "Reading fully drawn times: " + numFullyDrawnTimeStats);
-            mFullyDrawnTimes.ensureCapacity(numFullyDrawnTimeStats);
-            for (int i=0; i<numFullyDrawnTimeStats; i++) {
-                String comp = in.readString();
-                if (localLOGV) Slog.v(TAG, "Component: " + comp);
-                TimeStats times = new TimeStats(in);
-                mFullyDrawnTimes.put(comp, times);
-            }
-        }
-
-        void updateResume(String comp, boolean launched) {
-            if (launched) {
-                mLaunchCount ++;
-            }
-            mResumedTime = SystemClock.elapsedRealtime();
-        }
-        
-        void updatePause() {
-            mPausedTime =  SystemClock.elapsedRealtime();
-            mUsageTime += (mPausedTime - mResumedTime);
-        }
-        
-        void addLaunchCount(String comp) {
-            TimeStats times = mLaunchTimes.get(comp);
-            if (times == null) {
-                times = new TimeStats();
-                mLaunchTimes.put(comp, times);
-            }
-            times.incCount();
-        }
-        
-        void addLaunchTime(String comp, int millis) {
-            TimeStats times = mLaunchTimes.get(comp);
-            if (times == null) {
-                times = new TimeStats();
-                mLaunchTimes.put(comp, times);
-            }
-            times.add(millis);
-        }
-
-        void addFullyDrawnTime(String comp, int millis) {
-            TimeStats times = mFullyDrawnTimes.get(comp);
-            if (times == null) {
-                times = new TimeStats();
-                mFullyDrawnTimes.put(comp, times);
-            }
-            times.add(millis);
-        }
-
-        void writeToParcel(Parcel out) {
-            out.writeInt(mLaunchCount);
-            out.writeLong(mUsageTime);
-            final int numLaunchTimeStats = mLaunchTimes.size();
-            out.writeInt(numLaunchTimeStats);
-            for (int i=0; i<numLaunchTimeStats; i++) {
-                out.writeString(mLaunchTimes.keyAt(i));
-                mLaunchTimes.valueAt(i).writeToParcel(out);
-            }
-            final int numFullyDrawnTimeStats = mFullyDrawnTimes.size();
-            out.writeInt(numFullyDrawnTimeStats);
-            for (int i=0; i<numFullyDrawnTimeStats; i++) {
-                out.writeString(mFullyDrawnTimes.keyAt(i));
-                mFullyDrawnTimes.valueAt(i).writeToParcel(out);
-            }
-        }
-        
-        void clear() {
-            mLaunchTimes.clear();
-            mFullyDrawnTimes.clear();
-            mLaunchCount = 0;
-            mUsageTime = 0;
-        }
-    }
-    
-    UsageStatsService(String dir) {
-        mStats = new ArrayMap<String, PkgUsageStatsExtended>();
-        mLastResumeTimes = new ArrayMap<String, ArrayMap<String, Long>>();
-        mStatsLock = new Object();
-        mFileLock = new Object();
-        mDir = new File(dir);
-        mCal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0"));
-        
-        mDir.mkdir();
-        
-        // Remove any old usage files from previous versions.
-        File parentDir = mDir.getParentFile();
-        String fList[] = parentDir.list();
-        if (fList != null) {
-            String prefix = mDir.getName() + ".";
-            int i = fList.length;
-            while (i > 0) {
-                i--;
-                if (fList[i].startsWith(prefix)) {
-                    Slog.i(TAG, "Deleting old usage file: " + fList[i]);
-                    (new File(parentDir, fList[i])).delete();
-                }
-            }
-        }
-        
-        // Update current stats which are binned by date
-        mFileLeaf = getCurrentDateStr(FILE_PREFIX);
-        mFile = new File(mDir, mFileLeaf);
-        mHistoryFile = new AtomicFile(new File(mDir, FILE_HISTORY));
-        readStatsFromFile();
-        readHistoryStatsFromFile();
-        mLastWriteElapsedTime.set(SystemClock.elapsedRealtime());
-        // mCal was set by getCurrentDateStr(), want to use that same time.
-        mLastWriteDay.set(mCal.get(Calendar.DAY_OF_YEAR));
-    }
-
-    /*
-     * Utility method to convert date into string.
-     */
-    private String getCurrentDateStr(String prefix) {
-        StringBuilder sb = new StringBuilder();
-        synchronized (mCal) {
-            mCal.setTimeInMillis(System.currentTimeMillis());
-            if (prefix != null) {
-                sb.append(prefix);
-            }
-            sb.append(mCal.get(Calendar.YEAR));
-            int mm = mCal.get(Calendar.MONTH) - Calendar.JANUARY +1;
-            if (mm < 10) {
-                sb.append("0");
-            }
-            sb.append(mm);
-            int dd = mCal.get(Calendar.DAY_OF_MONTH);
-            if (dd < 10) {
-                sb.append("0");
-            }
-            sb.append(dd);
-        }
-        return sb.toString();
-    }
-    
-    private Parcel getParcelForFile(File file) throws IOException {
-        FileInputStream stream = new FileInputStream(file);
-        byte[] raw = readFully(stream);
-        Parcel in = Parcel.obtain();
-        in.unmarshall(raw, 0, raw.length);
-        in.setDataPosition(0);
-        stream.close();
-        return in;
-    }
-    
-    private void readStatsFromFile() {
-        File newFile = mFile;
-        synchronized (mFileLock) {
-            try {
-                if (newFile.exists()) {
-                    readStatsFLOCK(newFile);
-                } else {
-                    // Check for file limit before creating a new file
-                    checkFileLimitFLOCK();
-                    newFile.createNewFile();
-                }
-            } catch (IOException e) {
-                Slog.w(TAG,"Error : " + e + " reading data from file:" + newFile);
-            }
-        }
-    }
-    
-    private void readStatsFLOCK(File file) throws IOException {
-        Parcel in = getParcelForFile(file);
-        int vers = in.readInt();
-        if (vers != VERSION) {
-            Slog.w(TAG, "Usage stats version changed; dropping");
-            return;
-        }
-        int N = in.readInt();
-        while (N > 0) {
-            N--;
-            String pkgName = in.readString();
-            if (pkgName == null) {
-                break;
-            }
-            if (localLOGV) Slog.v(TAG, "Reading package #" + N + ": " + pkgName);
-            PkgUsageStatsExtended pus = new PkgUsageStatsExtended(in);
-            synchronized (mStatsLock) {
-                mStats.put(pkgName, pus);
-            }
-        }
-    }
-
-    private void readHistoryStatsFromFile() {
-        synchronized (mFileLock) {
-            if (mHistoryFile.getBaseFile().exists()) {
-                readHistoryStatsFLOCK(mHistoryFile);
-            }
-        }
-    }
-
-    private void readHistoryStatsFLOCK(AtomicFile file) {
-        FileInputStream fis = null;
-        try {
-            fis = mHistoryFile.openRead();
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(fis, null);
-            int eventType = parser.getEventType();
-            while (eventType != XmlPullParser.START_TAG) {
-                eventType = parser.next();
-            }
-            String tagName = parser.getName();
-            if ("usage-history".equals(tagName)) {
-                String pkg = null;
-                do {
-                    eventType = parser.next();
-                    if (eventType == XmlPullParser.START_TAG) {
-                        tagName = parser.getName();
-                        int depth = parser.getDepth();
-                        if ("pkg".equals(tagName) && depth == 2) {
-                            pkg = parser.getAttributeValue(null, "name");
-                        } else if ("comp".equals(tagName) && depth == 3 && pkg != null) {
-                            String comp = parser.getAttributeValue(null, "name");
-                            String lastResumeTimeStr = parser.getAttributeValue(null, "lrt");
-                            if (comp != null && lastResumeTimeStr != null) {
-                                try {
-                                    long lastResumeTime = Long.parseLong(lastResumeTimeStr);
-                                    synchronized (mStatsLock) {
-                                        ArrayMap<String, Long> lrt = mLastResumeTimes.get(pkg);
-                                        if (lrt == null) {
-                                            lrt = new ArrayMap<String, Long>();
-                                            mLastResumeTimes.put(pkg, lrt);
-                                        }
-                                        lrt.put(comp, lastResumeTime);
-                                    }
-                                } catch (NumberFormatException e) {
-                                }
-                            }
-                        }
-                    } else if (eventType == XmlPullParser.END_TAG) {
-                        if ("pkg".equals(parser.getName())) {
-                            pkg = null;
-                        }
-                    }
-                } while (eventType != XmlPullParser.END_DOCUMENT);
-            }
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG,"Error reading history stats: " + e);
-        } catch (IOException e) {
-            Slog.w(TAG,"Error reading history stats: " + e);
-        } finally {
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-    }
-
-    private ArrayList<String> getUsageStatsFileListFLOCK() {
-        // Check if there are too many files in the system and delete older files
-        String fList[] = mDir.list();
-        if (fList == null) {
-            return null;
-        }
-        ArrayList<String> fileList = new ArrayList<String>();
-        for (String file : fList) {
-            if (!file.startsWith(FILE_PREFIX)) {
-                continue;
-            }
-            if (file.endsWith(".bak")) {
-                (new File(mDir, file)).delete();
-                continue;
-            }
-            fileList.add(file);
-        }
-        return fileList;
-    }
-    
-    private void checkFileLimitFLOCK() {
-        // Get all usage stats output files
-        ArrayList<String> fileList = getUsageStatsFileListFLOCK();
-        if (fileList == null) {
-            // Strange but we dont have to delete any thing
-            return;
-        }
-        int count = fileList.size();
-        if (count <= MAX_NUM_FILES) {
-            return;
-        }
-        // Sort files
-        Collections.sort(fileList);
-        count -= MAX_NUM_FILES;
-        // Delete older files
-        for (int i = 0; i < count; i++) {
-            String fileName = fileList.get(i);
-            File file = new File(mDir, fileName);
-            Slog.i(TAG, "Deleting usage file : " + fileName);
-            file.delete();
-        }
-    }
-
-    /**
-     * Conditionally start up a disk write if it's been awhile, or the
-     * day has rolled over.
-     *
-     * This is called indirectly from user-facing actions (when
-     * 'force' is false) so it tries to be quick, without writing to
-     * disk directly or acquiring heavy locks.
-     *
-     * @params force  do an unconditional, synchronous stats flush
-     *                to disk on the current thread.
-     * @params forceWriteHistoryStats Force writing of historical stats.
-     */
-    private void writeStatsToFile(final boolean force, final boolean forceWriteHistoryStats) {
-        int curDay;
-        synchronized (mCal) {
-            mCal.setTimeInMillis(System.currentTimeMillis());
-            curDay = mCal.get(Calendar.DAY_OF_YEAR);
-        }
-        final boolean dayChanged = curDay != mLastWriteDay.get();
-
-        // Determine if the day changed...  note that this will be wrong
-        // if the year has changed but we are in the same day of year...
-        // we can probably live with this.
-        final long currElapsedTime = SystemClock.elapsedRealtime();
-
-        // Fast common path, without taking the often-contentious
-        // mFileLock.
-        if (!force) {
-            if (!dayChanged &&
-                (currElapsedTime - mLastWriteElapsedTime.get()) < FILE_WRITE_INTERVAL) {
-                // wait till the next update
-                return;
-            }
-            if (mUnforcedDiskWriteRunning.compareAndSet(false, true)) {
-                new Thread("UsageStatsService_DiskWriter") {
-                    public void run() {
-                        try {
-                            if (localLOGV) Slog.d(TAG, "Disk writer thread starting.");
-                            writeStatsToFile(true, false);
-                        } finally {
-                            mUnforcedDiskWriteRunning.set(false);
-                            if (localLOGV) Slog.d(TAG, "Disk writer thread ending.");
-                        }
-                    }
-                }.start();
-            }
-            return;
-        }
-
-        synchronized (mFileLock) {
-            // Get the most recent file
-            mFileLeaf = getCurrentDateStr(FILE_PREFIX);
-            // Copy current file to back up
-            File backupFile = null;
-            if (mFile != null && mFile.exists()) {
-                backupFile = new File(mFile.getPath() + ".bak");
-                if (!backupFile.exists()) {
-                    if (!mFile.renameTo(backupFile)) {
-                        Slog.w(TAG, "Failed to persist new stats");
-                        return;
-                    }
-                } else {
-                    mFile.delete();
-                }
-            }
-
-            try {
-                // Write mStats to file
-                writeStatsFLOCK(mFile);
-                mLastWriteElapsedTime.set(currElapsedTime);
-                if (dayChanged) {
-                    mLastWriteDay.set(curDay);
-                    // clear stats
-                    synchronized (mStats) {
-                        mStats.clear();
-                    }
-                    mFile = new File(mDir, mFileLeaf);
-                    checkFileLimitFLOCK();
-                }
-
-                if (dayChanged || forceWriteHistoryStats) {
-                    // Write history stats daily, or when forced (due to shutdown).
-                    writeHistoryStatsFLOCK(mHistoryFile);
-                }
-
-                // Delete the backup file
-                if (backupFile != null) {
-                    backupFile.delete();
-                }
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed writing stats to file:" + mFile);
-                if (backupFile != null) {
-                    mFile.delete();
-                    backupFile.renameTo(mFile);
-                }
-            }
-        }
-        if (localLOGV) Slog.d(TAG, "Dumped usage stats.");
-    }
-
-    private void writeStatsFLOCK(File file) throws IOException {
-        FileOutputStream stream = new FileOutputStream(file);
-        try {
-            Parcel out = Parcel.obtain();
-            writeStatsToParcelFLOCK(out);
-            stream.write(out.marshall());
-            out.recycle();
-            stream.flush();
-        } finally {
-            FileUtils.sync(stream);
-            stream.close();
-        }
-    }
-
-    private void writeStatsToParcelFLOCK(Parcel out) {
-        synchronized (mStatsLock) {
-            out.writeInt(VERSION);
-            Set<String> keys = mStats.keySet();
-            out.writeInt(keys.size());
-            for (String key : keys) {
-                PkgUsageStatsExtended pus = mStats.get(key);
-                out.writeString(key);
-                pus.writeToParcel(out);
-            }
-        }
-    }
-
-    /** Filter out stats for any packages which aren't present anymore. */
-    private void filterHistoryStats() {
-        synchronized (mStatsLock) {
-            IPackageManager pm = AppGlobals.getPackageManager();
-            for (int i=0; i<mLastResumeTimes.size(); i++) {
-                String pkg = mLastResumeTimes.keyAt(i);
-                try {
-                    if (pm.getPackageUid(pkg, 0) < 0) {
-                        mLastResumeTimes.removeAt(i);
-                        i--;
-                    }
-                } catch (RemoteException e) {
-                }
-            }
-        }
-    }
-
-    private void writeHistoryStatsFLOCK(AtomicFile historyFile) {
-        FileOutputStream fos = null;
-        try {
-            fos = historyFile.startWrite();
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-            out.startDocument(null, true);
-            out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-            out.startTag(null, "usage-history");
-            synchronized (mStatsLock) {
-                for (int i=0; i<mLastResumeTimes.size(); i++) {
-                    out.startTag(null, "pkg");
-                    out.attribute(null, "name", mLastResumeTimes.keyAt(i));
-                    ArrayMap<String, Long> comp = mLastResumeTimes.valueAt(i);
-                    for (int j=0; j<comp.size(); j++) {
-                        out.startTag(null, "comp");
-                        out.attribute(null, "name", comp.keyAt(j));
-                        out.attribute(null, "lrt", comp.valueAt(j).toString());
-                        out.endTag(null, "comp");
-                    }
-                    out.endTag(null, "pkg");
-                }
-            }
-            out.endTag(null, "usage-history");
-            out.endDocument();
-
-            historyFile.finishWrite(fos);
-        } catch (IOException e) {
-            Slog.w(TAG,"Error writing history stats" + e);
-            if (fos != null) {
-                historyFile.failWrite(fos);
-            }
-        }
-    }
-
-    public void publish(Context context) {
-        mContext = context;
-        ServiceManager.addService(SERVICE_NAME, asBinder());
-    }
-
-    /**
-     * Start watching packages to remove stats when a package is uninstalled.
-     * May only be called when the package manager is ready.
-     */
-    public void monitorPackages() {
-        mPackageMonitor = new PackageMonitor() {
-            @Override
-            public void onPackageRemovedAllUsers(String packageName, int uid) {
-                synchronized (mStatsLock) {
-                    mLastResumeTimes.remove(packageName);
-                }
-            }
-        };
-        mPackageMonitor.register(mContext, null, true);
-        filterHistoryStats();
-    }
-
-    public void shutdown() {
-        if (mPackageMonitor != null) {
-            mPackageMonitor.unregister();
-        }
-        Slog.i(TAG, "Writing usage stats before shutdown...");
-        writeStatsToFile(true, true);
-    }
-
-    public static IUsageStats getService() {
-        if (sService != null) {
-            return sService;
-        }
-        IBinder b = ServiceManager.getService(SERVICE_NAME);
-        sService = asInterface(b);
-        return sService;
-    }
-    
-    public void noteResumeComponent(ComponentName componentName) {
-        enforceCallingPermission();
-        String pkgName;
-        synchronized (mStatsLock) {
-            if ((componentName == null) ||
-                    ((pkgName = componentName.getPackageName()) == null)) {
-                return;
-            }
-            
-            final boolean samePackage = pkgName.equals(mLastResumedPkg);
-            if (mIsResumed) {
-                if (mLastResumedPkg != null) {
-                    // We last resumed some other package...  just pause it now
-                    // to recover.
-                    if (REPORT_UNEXPECTED) Slog.i(TAG, "Unexpected resume of " + pkgName
-                            + " while already resumed in " + mLastResumedPkg);
-                    PkgUsageStatsExtended pus = mStats.get(mLastResumedPkg);
-                    if (pus != null) {
-                        pus.updatePause();
-                    }
-                }
-            }
-            
-            final boolean sameComp = samePackage
-                    && componentName.getClassName().equals(mLastResumedComp);
-            
-            mIsResumed = true;
-            mLastResumedPkg = pkgName;
-            mLastResumedComp = componentName.getClassName();
-            
-            if (localLOGV) Slog.i(TAG, "started component:" + pkgName);
-            PkgUsageStatsExtended pus = mStats.get(pkgName);
-            if (pus == null) {
-                pus = new PkgUsageStatsExtended();
-                mStats.put(pkgName, pus);
-            }
-            pus.updateResume(mLastResumedComp, !samePackage);
-            if (!sameComp) {
-                pus.addLaunchCount(mLastResumedComp);
-            }
-
-            ArrayMap<String, Long> componentResumeTimes = mLastResumeTimes.get(pkgName);
-            if (componentResumeTimes == null) {
-                componentResumeTimes = new ArrayMap<String, Long>();
-                mLastResumeTimes.put(pkgName, componentResumeTimes);
-            }
-            componentResumeTimes.put(mLastResumedComp, System.currentTimeMillis());
-        }
-    }
-
-    public void notePauseComponent(ComponentName componentName) {
-        enforceCallingPermission();
-        
-        synchronized (mStatsLock) {
-            String pkgName;
-            if ((componentName == null) ||
-                    ((pkgName = componentName.getPackageName()) == null)) {
-                return;
-            }
-            if (!mIsResumed) {
-                if (REPORT_UNEXPECTED) Slog.i(TAG, "Something wrong here, didn't expect "
-                        + pkgName + " to be paused");
-                return;
-            }
-            mIsResumed = false;
-            
-            if (localLOGV) Slog.i(TAG, "paused component:"+pkgName);
-        
-            PkgUsageStatsExtended pus = mStats.get(pkgName);
-            if (pus == null) {
-                // Weird some error here
-                Slog.i(TAG, "No package stats for pkg:"+pkgName);
-                return;
-            }
-            pus.updatePause();
-        }
-        
-        // Persist current data to file if needed.
-        writeStatsToFile(false, false);
-    }
-    
-    public void noteLaunchTime(ComponentName componentName, int millis) {
-        enforceCallingPermission();
-        String pkgName;
-        if ((componentName == null) ||
-                ((pkgName = componentName.getPackageName()) == null)) {
-            return;
-        }
-        
-        // Persist current data to file if needed.
-        writeStatsToFile(false, false);
-        
-        synchronized (mStatsLock) {
-            PkgUsageStatsExtended pus = mStats.get(pkgName);
-            if (pus != null) {
-                pus.addLaunchTime(componentName.getClassName(), millis);
-            }
-        }
-    }
-    
-    public void noteFullyDrawnTime(ComponentName componentName, int millis) {
-        enforceCallingPermission();
-        String pkgName;
-        if ((componentName == null) ||
-                ((pkgName = componentName.getPackageName()) == null)) {
-            return;
-        }
-
-        // Persist current data to file if needed.
-        writeStatsToFile(false, false);
-
-        synchronized (mStatsLock) {
-            PkgUsageStatsExtended pus = mStats.get(pkgName);
-            if (pus != null) {
-                pus.addFullyDrawnTime(componentName.getClassName(), millis);
-            }
-        }
-    }
-
-    public void enforceCallingPermission() {
-        if (Binder.getCallingPid() == Process.myPid()) {
-            return;
-        }
-        mContext.enforcePermission(android.Manifest.permission.UPDATE_DEVICE_STATS,
-                Binder.getCallingPid(), Binder.getCallingUid(), null);
-    }
-    
-    public PkgUsageStats getPkgUsageStats(ComponentName componentName) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.PACKAGE_USAGE_STATS, null);
-        String pkgName;
-        if ((componentName == null) ||
-                ((pkgName = componentName.getPackageName()) == null)) {
-            return null;
-        }
-        synchronized (mStatsLock) {
-            PkgUsageStatsExtended pus = mStats.get(pkgName);
-            Map<String, Long> lastResumeTimes = mLastResumeTimes.get(pkgName);
-            if (pus == null && lastResumeTimes == null) {
-                return null;
-            }
-            int launchCount = pus != null ? pus.mLaunchCount : 0;
-            long usageTime = pus != null ? pus.mUsageTime : 0;
-            return new PkgUsageStats(pkgName, launchCount, usageTime, lastResumeTimes);
-        }
-    }
-    
-    public PkgUsageStats[] getAllPkgUsageStats() {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.PACKAGE_USAGE_STATS, null);
-        synchronized (mStatsLock) {
-            int size = mLastResumeTimes.size();
-            if (size <= 0) {
-                return null;
-            }
-            PkgUsageStats retArr[] = new PkgUsageStats[size];
-            for (int i=0; i<size; i++) {
-                String pkg = mLastResumeTimes.keyAt(i);
-                long usageTime = 0;
-                int launchCount = 0;
-
-                PkgUsageStatsExtended pus = mStats.get(pkg);
-                if (pus != null) {
-                    usageTime = pus.mUsageTime;
-                    launchCount = pus.mLaunchCount;
-                }
-                retArr[i] = new PkgUsageStats(pkg, launchCount, usageTime,
-                        mLastResumeTimes.valueAt(i));
-            }
-            return retArr;
-        }
-    }
-    
-    static byte[] readFully(FileInputStream stream) throws java.io.IOException {
-        int pos = 0;
-        int avail = stream.available();
-        byte[] data = new byte[avail];
-        while (true) {
-            int amt = stream.read(data, pos, data.length-pos);
-            if (amt <= 0) {
-                return data;
-            }
-            pos += amt;
-            avail = stream.available();
-            if (avail > data.length-pos) {
-                byte[] newData = new byte[pos+avail];
-                System.arraycopy(data, 0, newData, 0, pos);
-                data = newData;
-            }
-        }
-    }
-    
-    private void collectDumpInfoFLOCK(PrintWriter pw, boolean isCompactOutput,
-            boolean deleteAfterPrint, HashSet<String> packages) {
-        List<String> fileList = getUsageStatsFileListFLOCK();
-        if (fileList == null) {
-            return;
-        }
-        Collections.sort(fileList);
-        for (String file : fileList) {
-            if (deleteAfterPrint && file.equalsIgnoreCase(mFileLeaf)) {
-                // In this mode we don't print the current day's stats, since
-                // they are incomplete.
-                continue;
-            }
-            File dFile = new File(mDir, file);
-            String dateStr = file.substring(FILE_PREFIX.length());
-            if (dateStr.length() > 0 && (dateStr.charAt(0) <= '0' || dateStr.charAt(0) >= '9')) {
-                // If the remainder does not start with a number, it is not a date,
-                // so we should ignore it for purposes here.
-                continue;
-            }
-            try {
-                Parcel in = getParcelForFile(dFile);
-                collectDumpInfoFromParcelFLOCK(in, pw, dateStr, isCompactOutput,
-                        packages);
-                if (deleteAfterPrint) {
-                    // Delete old file after collecting info only for checkin requests
-                    dFile.delete();
-                }
-            } catch (FileNotFoundException e) {
-                Slog.w(TAG, "Failed with "+e+" when collecting dump info from file : " + file);
-                return;
-            } catch (IOException e) {
-                Slog.w(TAG, "Failed with "+e+" when collecting dump info from file : "+file);
-            }      
-        }
-    }
-    
-    private void collectDumpInfoFromParcelFLOCK(Parcel in, PrintWriter pw,
-            String date, boolean isCompactOutput, HashSet<String> packages) {
-        StringBuilder sb = new StringBuilder(512);
-        if (isCompactOutput) {
-            sb.append("D:");
-            sb.append(CHECKIN_VERSION);
-            sb.append(',');
-        } else {
-            sb.append("Date: ");
-        }
-        
-        sb.append(date);
-        
-        int vers = in.readInt();
-        if (vers != VERSION) {
-            sb.append(" (old data version)");
-            pw.println(sb.toString());
-            return;
-        }
-        
-        pw.println(sb.toString());
-        int N = in.readInt();
-        
-        while (N > 0) {
-            N--;
-            String pkgName = in.readString();
-            if (pkgName == null) {
-                break;
-            }
-            sb.setLength(0);
-            PkgUsageStatsExtended pus = new PkgUsageStatsExtended(in);
-            if (packages != null && !packages.contains(pkgName)) {
-                // This package has not been requested -- don't print
-                // anything for it.
-            } else if (isCompactOutput) {
-                sb.append("P:");
-                sb.append(pkgName);
-                sb.append(',');
-                sb.append(pus.mLaunchCount);
-                sb.append(',');
-                sb.append(pus.mUsageTime);
-                sb.append('\n');
-                final int NLT = pus.mLaunchTimes.size();
-                for (int i=0; i<NLT; i++) {
-                    sb.append("A:");
-                    String activity = pus.mLaunchTimes.keyAt(i);
-                    sb.append(activity);
-                    TimeStats times = pus.mLaunchTimes.valueAt(i);
-                    sb.append(',');
-                    sb.append(times.count);
-                    for (int j=0; j<NUM_LAUNCH_TIME_BINS; j++) {
-                        sb.append(",");
-                        sb.append(times.times[j]);
-                    }
-                    sb.append('\n');
-                }
-                final int NFDT = pus.mFullyDrawnTimes.size();
-                for (int i=0; i<NFDT; i++) {
-                    sb.append("A:");
-                    String activity = pus.mFullyDrawnTimes.keyAt(i);
-                    sb.append(activity);
-                    TimeStats times = pus.mFullyDrawnTimes.valueAt(i);
-                    for (int j=0; j<NUM_LAUNCH_TIME_BINS; j++) {
-                        sb.append(",");
-                        sb.append(times.times[j]);
-                    }
-                    sb.append('\n');
-                }
-
-            } else {
-                sb.append("  ");
-                sb.append(pkgName);
-                sb.append(": ");
-                sb.append(pus.mLaunchCount);
-                sb.append(" times, ");
-                sb.append(pus.mUsageTime);
-                sb.append(" ms");
-                sb.append('\n');
-                final int NLT = pus.mLaunchTimes.size();
-                for (int i=0; i<NLT; i++) {
-                    sb.append("    ");
-                    sb.append(pus.mLaunchTimes.keyAt(i));
-                    TimeStats times = pus.mLaunchTimes.valueAt(i);
-                    sb.append(": ");
-                    sb.append(times.count);
-                    sb.append(" starts");
-                    int lastBin = 0;
-                    for (int j=0; j<NUM_LAUNCH_TIME_BINS-1; j++) {
-                        if (times.times[j] != 0) {
-                            sb.append(", ");
-                            sb.append(lastBin);
-                            sb.append('-');
-                            sb.append(LAUNCH_TIME_BINS[j]);
-                            sb.append("ms=");
-                            sb.append(times.times[j]);
-                        }
-                        lastBin = LAUNCH_TIME_BINS[j];
-                    }
-                    if (times.times[NUM_LAUNCH_TIME_BINS-1] != 0) {
-                        sb.append(", ");
-                        sb.append(">=");
-                        sb.append(lastBin);
-                        sb.append("ms=");
-                        sb.append(times.times[NUM_LAUNCH_TIME_BINS-1]);
-                    }
-                    sb.append('\n');
-                }
-                final int NFDT = pus.mFullyDrawnTimes.size();
-                for (int i=0; i<NFDT; i++) {
-                    sb.append("    ");
-                    sb.append(pus.mFullyDrawnTimes.keyAt(i));
-                    TimeStats times = pus.mFullyDrawnTimes.valueAt(i);
-                    sb.append(": fully drawn ");
-                    boolean needComma = false;
-                    int lastBin = 0;
-                    for (int j=0; j<NUM_LAUNCH_TIME_BINS-1; j++) {
-                        if (times.times[j] != 0) {
-                            if (needComma) {
-                                sb.append(", ");
-                            } else {
-                                needComma = true;
-                            }
-                            sb.append(lastBin);
-                            sb.append('-');
-                            sb.append(LAUNCH_TIME_BINS[j]);
-                            sb.append("ms=");
-                            sb.append(times.times[j]);
-                        }
-                        lastBin = LAUNCH_TIME_BINS[j];
-                    }
-                    if (times.times[NUM_LAUNCH_TIME_BINS-1] != 0) {
-                        if (needComma) {
-                            sb.append(", ");
-                        }
-                        sb.append(">=");
-                        sb.append(lastBin);
-                        sb.append("ms=");
-                        sb.append(times.times[NUM_LAUNCH_TIME_BINS-1]);
-                    }
-                    sb.append('\n');
-                }
-            }
-            
-            pw.write(sb.toString());
-        }
-    }
-    
-    /**
-     * Searches array of arguments for the specified string
-     * @param args array of argument strings
-     * @param value value to search for
-     * @return true if the value is contained in the array
-     */
-    private static boolean scanArgs(String[] args, String value) {
-        if (args != null) {
-            for (String arg : args) {
-                if (value.equals(arg)) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-    
-    /**
-     * Searches array of arguments for the specified string's data
-     * @param args array of argument strings
-     * @param value value to search for
-     * @return the string of data after the arg, or null if there is none
-     */
-    private static String scanArgsData(String[] args, String value) {
-        if (args != null) {
-            final int N = args.length;
-            for (int i=0; i<N; i++) {
-                if (value.equals(args[i])) {
-                    i++;
-                    return i < N ? args[i] : null;
-                }
-            }
-        }
-        return null;
-    }
-    
-    @Override
-    /*
-     * The data persisted to file is parsed and the stats are computed. 
-     */
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump UsageStats from from pid="
-                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()
-                    + " without permission " + android.Manifest.permission.DUMP);
-            return;
-        }
-
-        final boolean isCheckinRequest = scanArgs(args, "--checkin");
-        final boolean isCompactOutput = isCheckinRequest || scanArgs(args, "-c");
-        final boolean deleteAfterPrint = isCheckinRequest || scanArgs(args, "-d");
-        final String rawPackages = scanArgsData(args, "--packages");
-        
-        // Make sure the current stats are written to the file.  This
-        // doesn't need to be done if we are deleting files after printing,
-        // since it that case we won't print the current stats.
-        if (!deleteAfterPrint) {
-            writeStatsToFile(true, false);
-        }
-        
-        HashSet<String> packages = null;
-        if (rawPackages != null) {
-            if (!"*".equals(rawPackages)) {
-                // A * is a wildcard to show all packages.
-                String[] names = rawPackages.split(",");
-                for (String n : names) {
-                    if (packages == null) {
-                        packages = new HashSet<String>();
-                    }
-                    packages.add(n);
-                }
-            }
-        } else if (isCheckinRequest) {
-            // If checkin doesn't specify any packages, then we simply won't
-            // show anything.
-            Slog.w(TAG, "Checkin without packages");
-            return;
-        }
-        
-        synchronized (mFileLock) {
-            collectDumpInfoFLOCK(pw, isCompactOutput, deleteAfterPrint, packages);
-        }
-    }
-
-}
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
deleted file mode 100644
index 231a40a..0000000
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ /dev/null
@@ -1,1597 +0,0 @@
-/*
- * Copyright (C) 2010 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.connectivity;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.hardware.usb.UsbManager;
-import android.net.ConnectivityManager;
-import android.net.IConnectivityManager;
-import android.net.INetworkManagementEventObserver;
-import android.net.INetworkStatsService;
-import android.net.InterfaceConfiguration;
-import android.net.LinkAddress;
-import android.net.LinkProperties;
-import android.net.NetworkInfo;
-import android.net.NetworkUtils;
-import android.net.RouteInfo;
-import android.os.Binder;
-import android.os.INetworkManagementService;
-import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.util.Log;
-
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.util.IState;
-import com.android.internal.util.State;
-import com.android.internal.util.StateMachine;
-import com.android.server.IoThread;
-import com.google.android.collect.Lists;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.net.InetAddress;
-import java.net.Inet4Address;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @hide
- *
- * Timeout
- *
- * TODO - look for parent classes and code sharing
- */
-public class Tethering extends INetworkManagementEventObserver.Stub {
-
-    private Context mContext;
-    private final static String TAG = "Tethering";
-    private final static boolean DBG = true;
-    private final static boolean VDBG = false;
-
-    // TODO - remove both of these - should be part of interface inspection/selection stuff
-    private String[] mTetherableUsbRegexs;
-    private String[] mTetherableWifiRegexs;
-    private String[] mTetherableBluetoothRegexs;
-    private Collection<Integer> mUpstreamIfaceTypes;
-
-    // used to synchronize public access to members
-    private Object mPublicSync;
-
-    private static final Integer MOBILE_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE);
-    private static final Integer HIPRI_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_HIPRI);
-    private static final Integer DUN_TYPE = new Integer(ConnectivityManager.TYPE_MOBILE_DUN);
-
-    // if we have to connect to mobile, what APN type should we use?  Calculated by examining the
-    // upstream type list and the DUN_REQUIRED secure-setting
-    private int mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_NONE;
-
-    private final INetworkManagementService mNMService;
-    private final INetworkStatsService mStatsService;
-    private final IConnectivityManager mConnService;
-    private Looper mLooper;
-
-    private HashMap<String, TetherInterfaceSM> mIfaces; // all tethered/tetherable ifaces
-
-    private BroadcastReceiver mStateReceiver;
-
-    private static final String USB_NEAR_IFACE_ADDR      = "192.168.42.129";
-    private static final int USB_PREFIX_LENGTH        = 24;
-
-    // USB is  192.168.42.1 and 255.255.255.0
-    // Wifi is 192.168.43.1 and 255.255.255.0
-    // BT is limited to max default of 5 connections. 192.168.44.1 to 192.168.48.1
-    // with 255.255.255.0
-
-    private String[] mDhcpRange;
-    private static final String[] DHCP_DEFAULT_RANGE = {
-        "192.168.42.2", "192.168.42.254", "192.168.43.2", "192.168.43.254",
-        "192.168.44.2", "192.168.44.254", "192.168.45.2", "192.168.45.254",
-        "192.168.46.2", "192.168.46.254", "192.168.47.2", "192.168.47.254",
-        "192.168.48.2", "192.168.48.254",
-    };
-
-    private String[] mDefaultDnsServers;
-    private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8";
-    private static final String DNS_DEFAULT_SERVER2 = "8.8.4.4";
-
-    private StateMachine mTetherMasterSM;
-
-    private Notification mTetheredNotification;
-
-    private boolean mRndisEnabled;       // track the RNDIS function enabled state
-    private boolean mUsbTetherRequested; // true if USB tethering should be started
-                                         // when RNDIS is enabled
-
-    public Tethering(Context context, INetworkManagementService nmService,
-            INetworkStatsService statsService, IConnectivityManager connService, Looper looper) {
-        mContext = context;
-        mNMService = nmService;
-        mStatsService = statsService;
-        mConnService = connService;
-        mLooper = looper;
-
-        mPublicSync = new Object();
-
-        mIfaces = new HashMap<String, TetherInterfaceSM>();
-
-        // make our own thread so we don't anr the system
-        mLooper = IoThread.get().getLooper();
-        mTetherMasterSM = new TetherMasterSM("TetherMaster", mLooper);
-        mTetherMasterSM.start();
-
-        mStateReceiver = new StateReceiver();
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(UsbManager.ACTION_USB_STATE);
-        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
-        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
-        mContext.registerReceiver(mStateReceiver, filter);
-
-        filter = new IntentFilter();
-        filter.addAction(Intent.ACTION_MEDIA_SHARED);
-        filter.addAction(Intent.ACTION_MEDIA_UNSHARED);
-        filter.addDataScheme("file");
-        mContext.registerReceiver(mStateReceiver, filter);
-
-        mDhcpRange = context.getResources().getStringArray(
-                com.android.internal.R.array.config_tether_dhcp_range);
-        if ((mDhcpRange.length == 0) || (mDhcpRange.length % 2 ==1)) {
-            mDhcpRange = DHCP_DEFAULT_RANGE;
-        }
-
-        // load device config info
-        updateConfiguration();
-
-        // TODO - remove and rely on real notifications of the current iface
-        mDefaultDnsServers = new String[2];
-        mDefaultDnsServers[0] = DNS_DEFAULT_SERVER1;
-        mDefaultDnsServers[1] = DNS_DEFAULT_SERVER2;
-    }
-
-    void updateConfiguration() {
-        String[] tetherableUsbRegexs = mContext.getResources().getStringArray(
-                com.android.internal.R.array.config_tether_usb_regexs);
-        String[] tetherableWifiRegexs = mContext.getResources().getStringArray(
-                com.android.internal.R.array.config_tether_wifi_regexs);
-        String[] tetherableBluetoothRegexs = mContext.getResources().getStringArray(
-                com.android.internal.R.array.config_tether_bluetooth_regexs);
-
-        int ifaceTypes[] = mContext.getResources().getIntArray(
-                com.android.internal.R.array.config_tether_upstream_types);
-        Collection<Integer> upstreamIfaceTypes = new ArrayList();
-        for (int i : ifaceTypes) {
-            upstreamIfaceTypes.add(new Integer(i));
-        }
-
-        synchronized (mPublicSync) {
-            mTetherableUsbRegexs = tetherableUsbRegexs;
-            mTetherableWifiRegexs = tetherableWifiRegexs;
-            mTetherableBluetoothRegexs = tetherableBluetoothRegexs;
-            mUpstreamIfaceTypes = upstreamIfaceTypes;
-        }
-
-        // check if the upstream type list needs to be modified due to secure-settings
-        checkDunRequired();
-    }
-
-    public void interfaceStatusChanged(String iface, boolean up) {
-        if (VDBG) Log.d(TAG, "interfaceStatusChanged " + iface + ", " + up);
-        boolean found = false;
-        boolean usb = false;
-        synchronized (mPublicSync) {
-            if (isWifi(iface)) {
-                found = true;
-            } else if (isUsb(iface)) {
-                found = true;
-                usb = true;
-            } else if (isBluetooth(iface)) {
-                found = true;
-            }
-            if (found == false) return;
-
-            TetherInterfaceSM sm = mIfaces.get(iface);
-            if (up) {
-                if (sm == null) {
-                    sm = new TetherInterfaceSM(iface, mLooper, usb);
-                    mIfaces.put(iface, sm);
-                    sm.start();
-                }
-            } else {
-                if (isUsb(iface)) {
-                    // ignore usb0 down after enabling RNDIS
-                    // we will handle disconnect in interfaceRemoved instead
-                    if (VDBG) Log.d(TAG, "ignore interface down for " + iface);
-                } else if (sm != null) {
-                    sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
-                    mIfaces.remove(iface);
-                }
-            }
-        }
-    }
-
-    public void interfaceLinkStateChanged(String iface, boolean up) {
-        if (VDBG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up);
-        interfaceStatusChanged(iface, up);
-    }
-
-    private boolean isUsb(String iface) {
-        synchronized (mPublicSync) {
-            for (String regex : mTetherableUsbRegexs) {
-                if (iface.matches(regex)) return true;
-            }
-            return false;
-        }
-    }
-
-    public boolean isWifi(String iface) {
-        synchronized (mPublicSync) {
-            for (String regex : mTetherableWifiRegexs) {
-                if (iface.matches(regex)) return true;
-            }
-            return false;
-        }
-    }
-
-    public boolean isBluetooth(String iface) {
-        synchronized (mPublicSync) {
-            for (String regex : mTetherableBluetoothRegexs) {
-                if (iface.matches(regex)) return true;
-            }
-            return false;
-        }
-    }
-
-    public void interfaceAdded(String iface) {
-        if (VDBG) Log.d(TAG, "interfaceAdded " + iface);
-        boolean found = false;
-        boolean usb = false;
-        synchronized (mPublicSync) {
-            if (isWifi(iface)) {
-                found = true;
-            }
-            if (isUsb(iface)) {
-                found = true;
-                usb = true;
-            }
-            if (isBluetooth(iface)) {
-                found = true;
-            }
-            if (found == false) {
-                if (VDBG) Log.d(TAG, iface + " is not a tetherable iface, ignoring");
-                return;
-            }
-
-            TetherInterfaceSM sm = mIfaces.get(iface);
-            if (sm != null) {
-                if (VDBG) Log.d(TAG, "active iface (" + iface + ") reported as added, ignoring");
-                return;
-            }
-            sm = new TetherInterfaceSM(iface, mLooper, usb);
-            mIfaces.put(iface, sm);
-            sm.start();
-        }
-    }
-
-    public void interfaceRemoved(String iface) {
-        if (VDBG) Log.d(TAG, "interfaceRemoved " + iface);
-        synchronized (mPublicSync) {
-            TetherInterfaceSM sm = mIfaces.get(iface);
-            if (sm == null) {
-                if (VDBG) {
-                    Log.e(TAG, "attempting to remove unknown iface (" + iface + "), ignoring");
-                }
-                return;
-            }
-            sm.sendMessage(TetherInterfaceSM.CMD_INTERFACE_DOWN);
-            mIfaces.remove(iface);
-        }
-    }
-
-    public void addressUpdated(String address, String iface, int flags, int scope) {}
-
-    public void addressRemoved(String address, String iface, int flags, int scope) {}
-
-    public void limitReached(String limitName, String iface) {}
-
-    public void interfaceClassDataActivityChanged(String label, boolean active) {}
-
-    public int tether(String iface) {
-        if (DBG) Log.d(TAG, "Tethering " + iface);
-        TetherInterfaceSM sm = null;
-        synchronized (mPublicSync) {
-            sm = mIfaces.get(iface);
-        }
-        if (sm == null) {
-            Log.e(TAG, "Tried to Tether an unknown iface :" + iface + ", ignoring");
-            return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
-        }
-        if (!sm.isAvailable() && !sm.isErrored()) {
-            Log.e(TAG, "Tried to Tether an unavailable iface :" + iface + ", ignoring");
-            return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
-        }
-        sm.sendMessage(TetherInterfaceSM.CMD_TETHER_REQUESTED);
-        return ConnectivityManager.TETHER_ERROR_NO_ERROR;
-    }
-
-    public int untether(String iface) {
-        if (DBG) Log.d(TAG, "Untethering " + iface);
-        TetherInterfaceSM sm = null;
-        synchronized (mPublicSync) {
-            sm = mIfaces.get(iface);
-        }
-        if (sm == null) {
-            Log.e(TAG, "Tried to Untether an unknown iface :" + iface + ", ignoring");
-            return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
-        }
-        if (sm.isErrored()) {
-            Log.e(TAG, "Tried to Untethered an errored iface :" + iface + ", ignoring");
-            return ConnectivityManager.TETHER_ERROR_UNAVAIL_IFACE;
-        }
-        sm.sendMessage(TetherInterfaceSM.CMD_TETHER_UNREQUESTED);
-        return ConnectivityManager.TETHER_ERROR_NO_ERROR;
-    }
-
-    public int getLastTetherError(String iface) {
-        TetherInterfaceSM sm = null;
-        synchronized (mPublicSync) {
-            sm = mIfaces.get(iface);
-            if (sm == null) {
-                Log.e(TAG, "Tried to getLastTetherError on an unknown iface :" + iface +
-                        ", ignoring");
-                return ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE;
-            }
-            return sm.getLastError();
-        }
-    }
-
-    // TODO - move all private methods used only by the state machine into the state machine
-    // to clarify what needs synchronized protection.
-    private void sendTetherStateChangedBroadcast() {
-        try {
-            if (!mConnService.isTetheringSupported()) return;
-        } catch (RemoteException e) {
-            return;
-        }
-
-        ArrayList<String> availableList = new ArrayList<String>();
-        ArrayList<String> activeList = new ArrayList<String>();
-        ArrayList<String> erroredList = new ArrayList<String>();
-
-        boolean wifiTethered = false;
-        boolean usbTethered = false;
-        boolean bluetoothTethered = false;
-
-        synchronized (mPublicSync) {
-            Set ifaces = mIfaces.keySet();
-            for (Object iface : ifaces) {
-                TetherInterfaceSM sm = mIfaces.get(iface);
-                if (sm != null) {
-                    if (sm.isErrored()) {
-                        erroredList.add((String)iface);
-                    } else if (sm.isAvailable()) {
-                        availableList.add((String)iface);
-                    } else if (sm.isTethered()) {
-                        if (isUsb((String)iface)) {
-                            usbTethered = true;
-                        } else if (isWifi((String)iface)) {
-                            wifiTethered = true;
-                      } else if (isBluetooth((String)iface)) {
-                            bluetoothTethered = true;
-                        }
-                        activeList.add((String)iface);
-                    }
-                }
-            }
-        }
-        Intent broadcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
-        broadcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
-                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-        broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER,
-                availableList);
-        broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, activeList);
-        broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER,
-                erroredList);
-        mContext.sendStickyBroadcastAsUser(broadcast, UserHandle.ALL);
-        if (DBG) {
-            Log.d(TAG, "sendTetherStateChangedBroadcast " + availableList.size() + ", " +
-                    activeList.size() + ", " + erroredList.size());
-        }
-
-        if (usbTethered) {
-            if (wifiTethered || bluetoothTethered) {
-                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general);
-            } else {
-                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_usb);
-            }
-        } else if (wifiTethered) {
-            if (bluetoothTethered) {
-                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_general);
-            } else {
-                showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_wifi);
-            }
-        } else if (bluetoothTethered) {
-            showTetheredNotification(com.android.internal.R.drawable.stat_sys_tether_bluetooth);
-        } else {
-            clearTetheredNotification();
-        }
-    }
-
-    private void showTetheredNotification(int icon) {
-        NotificationManager notificationManager =
-                (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-        if (notificationManager == null) {
-            return;
-        }
-
-        if (mTetheredNotification != null) {
-            if (mTetheredNotification.icon == icon) {
-                return;
-            }
-            notificationManager.cancelAsUser(null, mTetheredNotification.icon,
-                    UserHandle.ALL);
-        }
-
-        Intent intent = new Intent();
-        intent.setClassName("com.android.settings", "com.android.settings.TetherSettings");
-        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
-
-        PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0, intent, 0,
-                null, UserHandle.CURRENT);
-
-        Resources r = Resources.getSystem();
-        CharSequence title = r.getText(com.android.internal.R.string.tethered_notification_title);
-        CharSequence message = r.getText(com.android.internal.R.string.
-                tethered_notification_message);
-
-        if (mTetheredNotification == null) {
-            mTetheredNotification = new Notification();
-            mTetheredNotification.when = 0;
-        }
-        mTetheredNotification.icon = icon;
-        mTetheredNotification.defaults &= ~Notification.DEFAULT_SOUND;
-        mTetheredNotification.flags = Notification.FLAG_ONGOING_EVENT;
-        mTetheredNotification.tickerText = title;
-        mTetheredNotification.setLatestEventInfo(mContext, title, message, pi);
-
-        notificationManager.notifyAsUser(null, mTetheredNotification.icon,
-                mTetheredNotification, UserHandle.ALL);
-    }
-
-    private void clearTetheredNotification() {
-        NotificationManager notificationManager =
-            (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-        if (notificationManager != null && mTetheredNotification != null) {
-            notificationManager.cancelAsUser(null, mTetheredNotification.icon,
-                    UserHandle.ALL);
-            mTetheredNotification = null;
-        }
-    }
-
-    private class StateReceiver extends BroadcastReceiver {
-        public void onReceive(Context content, Intent intent) {
-            String action = intent.getAction();
-            if (action.equals(UsbManager.ACTION_USB_STATE)) {
-                synchronized (Tethering.this.mPublicSync) {
-                    boolean usbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
-                    mRndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false);
-                    // start tethering if we have a request pending
-                    if (usbConnected && mRndisEnabled && mUsbTetherRequested) {
-                        tetherUsb(true);
-                    }
-                    mUsbTetherRequested = false;
-                }
-            } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
-                NetworkInfo networkInfo = (NetworkInfo)intent.getParcelableExtra(
-                        ConnectivityManager.EXTRA_NETWORK_INFO);
-                if (networkInfo != null &&
-                        networkInfo.getDetailedState() != NetworkInfo.DetailedState.FAILED) {
-                    if (VDBG) Log.d(TAG, "Tethering got CONNECTIVITY_ACTION");
-                    mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED);
-                }
-            } else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
-                updateConfiguration();
-            }
-        }
-    }
-
-    private void tetherUsb(boolean enable) {
-        if (VDBG) Log.d(TAG, "tetherUsb " + enable);
-
-        String[] ifaces = new String[0];
-        try {
-            ifaces = mNMService.listInterfaces();
-        } catch (Exception e) {
-            Log.e(TAG, "Error listing Interfaces", e);
-            return;
-        }
-        for (String iface : ifaces) {
-            if (isUsb(iface)) {
-                int result = (enable ? tether(iface) : untether(iface));
-                if (result == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
-                    return;
-                }
-            }
-        }
-        Log.e(TAG, "unable start or stop USB tethering");
-    }
-
-    // configured when we start tethering and unconfig'd on error or conclusion
-    private boolean configureUsbIface(boolean enabled) {
-        if (VDBG) Log.d(TAG, "configureUsbIface(" + enabled + ")");
-
-        // toggle the USB interfaces
-        String[] ifaces = new String[0];
-        try {
-            ifaces = mNMService.listInterfaces();
-        } catch (Exception e) {
-            Log.e(TAG, "Error listing Interfaces", e);
-            return false;
-        }
-        for (String iface : ifaces) {
-            if (isUsb(iface)) {
-                InterfaceConfiguration ifcg = null;
-                try {
-                    ifcg = mNMService.getInterfaceConfig(iface);
-                    if (ifcg != null) {
-                        InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
-                        ifcg.setLinkAddress(new LinkAddress(addr, USB_PREFIX_LENGTH));
-                        if (enabled) {
-                            ifcg.setInterfaceUp();
-                        } else {
-                            ifcg.setInterfaceDown();
-                        }
-                        ifcg.clearFlag("running");
-                        mNMService.setInterfaceConfig(iface, ifcg);
-                    }
-                } catch (Exception e) {
-                    Log.e(TAG, "Error configuring interface " + iface, e);
-                    return false;
-                }
-            }
-         }
-
-        return true;
-    }
-
-    // TODO - return copies so people can't tamper
-    public String[] getTetherableUsbRegexs() {
-        return mTetherableUsbRegexs;
-    }
-
-    public String[] getTetherableWifiRegexs() {
-        return mTetherableWifiRegexs;
-    }
-
-    public String[] getTetherableBluetoothRegexs() {
-        return mTetherableBluetoothRegexs;
-    }
-
-    public int setUsbTethering(boolean enable) {
-        if (VDBG) Log.d(TAG, "setUsbTethering(" + enable + ")");
-        UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
-
-        synchronized (mPublicSync) {
-            if (enable) {
-                if (mRndisEnabled) {
-                    tetherUsb(true);
-                } else {
-                    mUsbTetherRequested = true;
-                    usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false);
-                }
-            } else {
-                tetherUsb(false);
-                if (mRndisEnabled) {
-                    usbManager.setCurrentFunction(null, false);
-                }
-                mUsbTetherRequested = false;
-            }
-        }
-        return ConnectivityManager.TETHER_ERROR_NO_ERROR;
-    }
-
-    public int[] getUpstreamIfaceTypes() {
-        int values[];
-        synchronized (mPublicSync) {
-            updateConfiguration();  // TODO - remove?
-            values = new int[mUpstreamIfaceTypes.size()];
-            Iterator<Integer> iterator = mUpstreamIfaceTypes.iterator();
-            for (int i=0; i < mUpstreamIfaceTypes.size(); i++) {
-                values[i] = iterator.next();
-            }
-        }
-        return values;
-    }
-
-    public void checkDunRequired() {
-        int secureSetting = Settings.Global.getInt(mContext.getContentResolver(),
-                Settings.Global.TETHER_DUN_REQUIRED, 2);
-        synchronized (mPublicSync) {
-            // 2 = not set, 0 = DUN not required, 1 = DUN required
-            if (secureSetting != 2) {
-                int requiredApn = (secureSetting == 1 ?
-                        ConnectivityManager.TYPE_MOBILE_DUN :
-                        ConnectivityManager.TYPE_MOBILE_HIPRI);
-                if (requiredApn == ConnectivityManager.TYPE_MOBILE_DUN) {
-                    while (mUpstreamIfaceTypes.contains(MOBILE_TYPE)) {
-                        mUpstreamIfaceTypes.remove(MOBILE_TYPE);
-                    }
-                    while (mUpstreamIfaceTypes.contains(HIPRI_TYPE)) {
-                        mUpstreamIfaceTypes.remove(HIPRI_TYPE);
-                    }
-                    if (mUpstreamIfaceTypes.contains(DUN_TYPE) == false) {
-                        mUpstreamIfaceTypes.add(DUN_TYPE);
-                    }
-                } else {
-                    while (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
-                        mUpstreamIfaceTypes.remove(DUN_TYPE);
-                    }
-                    if (mUpstreamIfaceTypes.contains(MOBILE_TYPE) == false) {
-                        mUpstreamIfaceTypes.add(MOBILE_TYPE);
-                    }
-                    if (mUpstreamIfaceTypes.contains(HIPRI_TYPE) == false) {
-                        mUpstreamIfaceTypes.add(HIPRI_TYPE);
-                    }
-                }
-            }
-            if (mUpstreamIfaceTypes.contains(DUN_TYPE)) {
-                mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_DUN;
-            } else {
-                mPreferredUpstreamMobileApn = ConnectivityManager.TYPE_MOBILE_HIPRI;
-            }
-        }
-    }
-
-    // TODO review API - maybe return ArrayList<String> here and below?
-    public String[] getTetheredIfaces() {
-        ArrayList<String> list = new ArrayList<String>();
-        synchronized (mPublicSync) {
-            Set keys = mIfaces.keySet();
-            for (Object key : keys) {
-                TetherInterfaceSM sm = mIfaces.get(key);
-                if (sm.isTethered()) {
-                    list.add((String)key);
-                }
-            }
-        }
-        String[] retVal = new String[list.size()];
-        for (int i=0; i < list.size(); i++) {
-            retVal[i] = list.get(i);
-        }
-        return retVal;
-    }
-
-    public String[] getTetherableIfaces() {
-        ArrayList<String> list = new ArrayList<String>();
-        synchronized (mPublicSync) {
-            Set keys = mIfaces.keySet();
-            for (Object key : keys) {
-                TetherInterfaceSM sm = mIfaces.get(key);
-                if (sm.isAvailable()) {
-                    list.add((String)key);
-                }
-            }
-        }
-        String[] retVal = new String[list.size()];
-        for (int i=0; i < list.size(); i++) {
-            retVal[i] = list.get(i);
-        }
-        return retVal;
-    }
-
-    public String[] getErroredIfaces() {
-        ArrayList<String> list = new ArrayList<String>();
-        synchronized (mPublicSync) {
-            Set keys = mIfaces.keySet();
-            for (Object key : keys) {
-                TetherInterfaceSM sm = mIfaces.get(key);
-                if (sm.isErrored()) {
-                    list.add((String)key);
-                }
-            }
-        }
-        String[] retVal = new String[list.size()];
-        for (int i= 0; i< list.size(); i++) {
-            retVal[i] = list.get(i);
-        }
-        return retVal;
-    }
-
-    //TODO: Temporary handling upstream change triggered without
-    //      CONNECTIVITY_ACTION. Only to accomodate interface
-    //      switch during HO.
-    //      @see bug/4455071
-    public void handleTetherIfaceChange() {
-        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED);
-    }
-
-    class TetherInterfaceSM extends StateMachine {
-        // notification from the master SM that it's not in tether mode
-        static final int CMD_TETHER_MODE_DEAD            =  1;
-        // request from the user that it wants to tether
-        static final int CMD_TETHER_REQUESTED            =  2;
-        // request from the user that it wants to untether
-        static final int CMD_TETHER_UNREQUESTED          =  3;
-        // notification that this interface is down
-        static final int CMD_INTERFACE_DOWN              =  4;
-        // notification that this interface is up
-        static final int CMD_INTERFACE_UP                =  5;
-        // notification from the master SM that it had an error turning on cellular dun
-        static final int CMD_CELL_DUN_ERROR              =  6;
-        // notification from the master SM that it had trouble enabling IP Forwarding
-        static final int CMD_IP_FORWARDING_ENABLE_ERROR  =  7;
-        // notification from the master SM that it had trouble disabling IP Forwarding
-        static final int CMD_IP_FORWARDING_DISABLE_ERROR =  8;
-        // notification from the master SM that it had trouble staring tethering
-        static final int CMD_START_TETHERING_ERROR       =  9;
-        // notification from the master SM that it had trouble stopping tethering
-        static final int CMD_STOP_TETHERING_ERROR        = 10;
-        // notification from the master SM that it had trouble setting the DNS forwarders
-        static final int CMD_SET_DNS_FORWARDERS_ERROR    = 11;
-        // the upstream connection has changed
-        static final int CMD_TETHER_CONNECTION_CHANGED   = 12;
-
-        private State mDefaultState;
-
-        private State mInitialState;
-        private State mStartingState;
-        private State mTetheredState;
-
-        private State mUnavailableState;
-
-        private boolean mAvailable;
-        private boolean mTethered;
-        int mLastError;
-
-        String mIfaceName;
-        String mMyUpstreamIfaceName;  // may change over time
-
-        boolean mUsb;
-
-        TetherInterfaceSM(String name, Looper looper, boolean usb) {
-            super(name, looper);
-            mIfaceName = name;
-            mUsb = usb;
-            setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
-
-            mInitialState = new InitialState();
-            addState(mInitialState);
-            mStartingState = new StartingState();
-            addState(mStartingState);
-            mTetheredState = new TetheredState();
-            addState(mTetheredState);
-            mUnavailableState = new UnavailableState();
-            addState(mUnavailableState);
-
-            setInitialState(mInitialState);
-        }
-
-        public String toString() {
-            String res = new String();
-            res += mIfaceName + " - ";
-            IState current = getCurrentState();
-            if (current == mInitialState) res += "InitialState";
-            if (current == mStartingState) res += "StartingState";
-            if (current == mTetheredState) res += "TetheredState";
-            if (current == mUnavailableState) res += "UnavailableState";
-            if (mAvailable) res += " - Available";
-            if (mTethered) res += " - Tethered";
-            res += " - lastError =" + mLastError;
-            return res;
-        }
-
-        public int getLastError() {
-            synchronized (Tethering.this.mPublicSync) {
-                return mLastError;
-            }
-        }
-
-        private void setLastError(int error) {
-            synchronized (Tethering.this.mPublicSync) {
-                mLastError = error;
-
-                if (isErrored()) {
-                    if (mUsb) {
-                        // note everything's been unwound by this point so nothing to do on
-                        // further error..
-                        Tethering.this.configureUsbIface(false);
-                    }
-                }
-            }
-        }
-
-        public boolean isAvailable() {
-            synchronized (Tethering.this.mPublicSync) {
-                return mAvailable;
-            }
-        }
-
-        private void setAvailable(boolean available) {
-            synchronized (Tethering.this.mPublicSync) {
-                mAvailable = available;
-            }
-        }
-
-        public boolean isTethered() {
-            synchronized (Tethering.this.mPublicSync) {
-                return mTethered;
-            }
-        }
-
-        private void setTethered(boolean tethered) {
-            synchronized (Tethering.this.mPublicSync) {
-                mTethered = tethered;
-            }
-        }
-
-        public boolean isErrored() {
-            synchronized (Tethering.this.mPublicSync) {
-                return (mLastError != ConnectivityManager.TETHER_ERROR_NO_ERROR);
-            }
-        }
-
-        class InitialState extends State {
-            @Override
-            public void enter() {
-                setAvailable(true);
-                setTethered(false);
-                sendTetherStateChangedBroadcast();
-            }
-
-            @Override
-            public boolean processMessage(Message message) {
-                if (DBG) Log.d(TAG, "InitialState.processMessage what=" + message.what);
-                boolean retValue = true;
-                switch (message.what) {
-                    case CMD_TETHER_REQUESTED:
-                        setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
-                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_REQUESTED,
-                                TetherInterfaceSM.this);
-                        transitionTo(mStartingState);
-                        break;
-                    case CMD_INTERFACE_DOWN:
-                        transitionTo(mUnavailableState);
-                        break;
-                    default:
-                        retValue = false;
-                        break;
-                }
-                return retValue;
-            }
-        }
-
-        class StartingState extends State {
-            @Override
-            public void enter() {
-                setAvailable(false);
-                if (mUsb) {
-                    if (!Tethering.this.configureUsbIface(true)) {
-                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
-                                TetherInterfaceSM.this);
-                        setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
-
-                        transitionTo(mInitialState);
-                        return;
-                    }
-                }
-                sendTetherStateChangedBroadcast();
-
-                // Skipping StartingState
-                transitionTo(mTetheredState);
-            }
-            @Override
-            public boolean processMessage(Message message) {
-                if (DBG) Log.d(TAG, "StartingState.processMessage what=" + message.what);
-                boolean retValue = true;
-                switch (message.what) {
-                    // maybe a parent class?
-                    case CMD_TETHER_UNREQUESTED:
-                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
-                                TetherInterfaceSM.this);
-                        if (mUsb) {
-                            if (!Tethering.this.configureUsbIface(false)) {
-                                setLastErrorAndTransitionToInitialState(
-                                    ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
-                                break;
-                            }
-                        }
-                        transitionTo(mInitialState);
-                        break;
-                    case CMD_CELL_DUN_ERROR:
-                    case CMD_IP_FORWARDING_ENABLE_ERROR:
-                    case CMD_IP_FORWARDING_DISABLE_ERROR:
-                    case CMD_START_TETHERING_ERROR:
-                    case CMD_STOP_TETHERING_ERROR:
-                    case CMD_SET_DNS_FORWARDERS_ERROR:
-                        setLastErrorAndTransitionToInitialState(
-                                ConnectivityManager.TETHER_ERROR_MASTER_ERROR);
-                        break;
-                    case CMD_INTERFACE_DOWN:
-                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
-                                TetherInterfaceSM.this);
-                        transitionTo(mUnavailableState);
-                        break;
-                    default:
-                        retValue = false;
-                }
-                return retValue;
-            }
-        }
-
-        class TetheredState extends State {
-            @Override
-            public void enter() {
-                try {
-                    mNMService.tetherInterface(mIfaceName);
-                } catch (Exception e) {
-                    Log.e(TAG, "Error Tethering: " + e.toString());
-                    setLastError(ConnectivityManager.TETHER_ERROR_TETHER_IFACE_ERROR);
-
-                    transitionTo(mInitialState);
-                    return;
-                }
-                if (DBG) Log.d(TAG, "Tethered " + mIfaceName);
-                setAvailable(false);
-                setTethered(true);
-                sendTetherStateChangedBroadcast();
-            }
-
-            private void cleanupUpstream() {
-                if (mMyUpstreamIfaceName != null) {
-                    // note that we don't care about errors here.
-                    // sometimes interfaces are gone before we get
-                    // to remove their rules, which generates errors.
-                    // just do the best we can.
-                    try {
-                        // about to tear down NAT; gather remaining statistics
-                        mStatsService.forceUpdate();
-                    } catch (Exception e) {
-                        if (VDBG) Log.e(TAG, "Exception in forceUpdate: " + e.toString());
-                    }
-                    try {
-                        mNMService.disableNat(mIfaceName, mMyUpstreamIfaceName);
-                    } catch (Exception e) {
-                        if (VDBG) Log.e(TAG, "Exception in disableNat: " + e.toString());
-                    }
-                    mMyUpstreamIfaceName = null;
-                }
-                return;
-            }
-
-            @Override
-            public boolean processMessage(Message message) {
-                if (DBG) Log.d(TAG, "TetheredState.processMessage what=" + message.what);
-                boolean retValue = true;
-                boolean error = false;
-                switch (message.what) {
-                    case CMD_TETHER_UNREQUESTED:
-                    case CMD_INTERFACE_DOWN:
-                        cleanupUpstream();
-                        try {
-                            mNMService.untetherInterface(mIfaceName);
-                        } catch (Exception e) {
-                            setLastErrorAndTransitionToInitialState(
-                                    ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR);
-                            break;
-                        }
-                        mTetherMasterSM.sendMessage(TetherMasterSM.CMD_TETHER_MODE_UNREQUESTED,
-                                TetherInterfaceSM.this);
-                        if (message.what == CMD_TETHER_UNREQUESTED) {
-                            if (mUsb) {
-                                if (!Tethering.this.configureUsbIface(false)) {
-                                    setLastError(
-                                            ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
-                                }
-                            }
-                            transitionTo(mInitialState);
-                        } else if (message.what == CMD_INTERFACE_DOWN) {
-                            transitionTo(mUnavailableState);
-                        }
-                        if (DBG) Log.d(TAG, "Untethered " + mIfaceName);
-                        break;
-                    case CMD_TETHER_CONNECTION_CHANGED:
-                        String newUpstreamIfaceName = (String)(message.obj);
-                        if ((mMyUpstreamIfaceName == null && newUpstreamIfaceName == null) ||
-                                (mMyUpstreamIfaceName != null &&
-                                mMyUpstreamIfaceName.equals(newUpstreamIfaceName))) {
-                            if (VDBG) Log.d(TAG, "Connection changed noop - dropping");
-                            break;
-                        }
-                        cleanupUpstream();
-                        if (newUpstreamIfaceName != null) {
-                            try {
-                                mNMService.enableNat(mIfaceName, newUpstreamIfaceName);
-                            } catch (Exception e) {
-                                Log.e(TAG, "Exception enabling Nat: " + e.toString());
-                                try {
-                                    mNMService.untetherInterface(mIfaceName);
-                                } catch (Exception ee) {}
-
-                                setLastError(ConnectivityManager.TETHER_ERROR_ENABLE_NAT_ERROR);
-                                transitionTo(mInitialState);
-                                return true;
-                            }
-                        }
-                        mMyUpstreamIfaceName = newUpstreamIfaceName;
-                        break;
-                    case CMD_CELL_DUN_ERROR:
-                    case CMD_IP_FORWARDING_ENABLE_ERROR:
-                    case CMD_IP_FORWARDING_DISABLE_ERROR:
-                    case CMD_START_TETHERING_ERROR:
-                    case CMD_STOP_TETHERING_ERROR:
-                    case CMD_SET_DNS_FORWARDERS_ERROR:
-                        error = true;
-                        // fall through
-                    case CMD_TETHER_MODE_DEAD:
-                        cleanupUpstream();
-                        try {
-                            mNMService.untetherInterface(mIfaceName);
-                        } catch (Exception e) {
-                            setLastErrorAndTransitionToInitialState(
-                                    ConnectivityManager.TETHER_ERROR_UNTETHER_IFACE_ERROR);
-                            break;
-                        }
-                        if (error) {
-                            setLastErrorAndTransitionToInitialState(
-                                    ConnectivityManager.TETHER_ERROR_MASTER_ERROR);
-                            break;
-                        }
-                        if (DBG) Log.d(TAG, "Tether lost upstream connection " + mIfaceName);
-                        sendTetherStateChangedBroadcast();
-                        if (mUsb) {
-                            if (!Tethering.this.configureUsbIface(false)) {
-                                setLastError(ConnectivityManager.TETHER_ERROR_IFACE_CFG_ERROR);
-                            }
-                        }
-                        transitionTo(mInitialState);
-                        break;
-                    default:
-                        retValue = false;
-                        break;
-                }
-                return retValue;
-            }
-        }
-
-        class UnavailableState extends State {
-            @Override
-            public void enter() {
-                setAvailable(false);
-                setLastError(ConnectivityManager.TETHER_ERROR_NO_ERROR);
-                setTethered(false);
-                sendTetherStateChangedBroadcast();
-            }
-            @Override
-            public boolean processMessage(Message message) {
-                boolean retValue = true;
-                switch (message.what) {
-                    case CMD_INTERFACE_UP:
-                        transitionTo(mInitialState);
-                        break;
-                    default:
-                        retValue = false;
-                        break;
-                }
-                return retValue;
-            }
-        }
-
-        void setLastErrorAndTransitionToInitialState(int error) {
-            setLastError(error);
-            transitionTo(mInitialState);
-        }
-
-    }
-
-    class TetherMasterSM extends StateMachine {
-        // an interface SM has requested Tethering
-        static final int CMD_TETHER_MODE_REQUESTED   = 1;
-        // an interface SM has unrequested Tethering
-        static final int CMD_TETHER_MODE_UNREQUESTED = 2;
-        // upstream connection change - do the right thing
-        static final int CMD_UPSTREAM_CHANGED        = 3;
-        // we received notice that the cellular DUN connection is up
-        static final int CMD_CELL_CONNECTION_RENEW   = 4;
-        // we don't have a valid upstream conn, check again after a delay
-        static final int CMD_RETRY_UPSTREAM          = 5;
-
-        // This indicates what a timeout event relates to.  A state that
-        // sends itself a delayed timeout event and handles incoming timeout events
-        // should inc this when it is entered and whenever it sends a new timeout event.
-        // We do not flush the old ones.
-        private int mSequenceNumber;
-
-        private State mInitialState;
-        private State mTetherModeAliveState;
-
-        private State mSetIpForwardingEnabledErrorState;
-        private State mSetIpForwardingDisabledErrorState;
-        private State mStartTetheringErrorState;
-        private State mStopTetheringErrorState;
-        private State mSetDnsForwardersErrorState;
-
-        private ArrayList<TetherInterfaceSM> mNotifyList;
-
-        private int mCurrentConnectionSequence;
-        private int mMobileApnReserved = ConnectivityManager.TYPE_NONE;
-
-        private String mUpstreamIfaceName = null;
-
-        private static final int UPSTREAM_SETTLE_TIME_MS     = 10000;
-        private static final int CELL_CONNECTION_RENEW_MS    = 40000;
-
-        TetherMasterSM(String name, Looper looper) {
-            super(name, looper);
-
-            //Add states
-            mInitialState = new InitialState();
-            addState(mInitialState);
-            mTetherModeAliveState = new TetherModeAliveState();
-            addState(mTetherModeAliveState);
-
-            mSetIpForwardingEnabledErrorState = new SetIpForwardingEnabledErrorState();
-            addState(mSetIpForwardingEnabledErrorState);
-            mSetIpForwardingDisabledErrorState = new SetIpForwardingDisabledErrorState();
-            addState(mSetIpForwardingDisabledErrorState);
-            mStartTetheringErrorState = new StartTetheringErrorState();
-            addState(mStartTetheringErrorState);
-            mStopTetheringErrorState = new StopTetheringErrorState();
-            addState(mStopTetheringErrorState);
-            mSetDnsForwardersErrorState = new SetDnsForwardersErrorState();
-            addState(mSetDnsForwardersErrorState);
-
-            mNotifyList = new ArrayList<TetherInterfaceSM>();
-            setInitialState(mInitialState);
-        }
-
-        class TetherMasterUtilState extends State {
-            protected final static boolean TRY_TO_SETUP_MOBILE_CONNECTION = true;
-            protected final static boolean WAIT_FOR_NETWORK_TO_SETTLE     = false;
-
-            @Override
-            public boolean processMessage(Message m) {
-                return false;
-            }
-            protected String enableString(int apnType) {
-                switch (apnType) {
-                case ConnectivityManager.TYPE_MOBILE_DUN:
-                    return Phone.FEATURE_ENABLE_DUN_ALWAYS;
-                case ConnectivityManager.TYPE_MOBILE:
-                case ConnectivityManager.TYPE_MOBILE_HIPRI:
-                    return Phone.FEATURE_ENABLE_HIPRI;
-                }
-                return null;
-            }
-            protected boolean turnOnUpstreamMobileConnection(int apnType) {
-                boolean retValue = true;
-                if (apnType == ConnectivityManager.TYPE_NONE) return false;
-                if (apnType != mMobileApnReserved) turnOffUpstreamMobileConnection();
-                int result = PhoneConstants.APN_REQUEST_FAILED;
-                String enableString = enableString(apnType);
-                if (enableString == null) return false;
-                try {
-                    result = mConnService.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                            enableString, new Binder());
-                } catch (Exception e) {
-                }
-                switch (result) {
-                case PhoneConstants.APN_ALREADY_ACTIVE:
-                case PhoneConstants.APN_REQUEST_STARTED:
-                    mMobileApnReserved = apnType;
-                    Message m = obtainMessage(CMD_CELL_CONNECTION_RENEW);
-                    m.arg1 = ++mCurrentConnectionSequence;
-                    sendMessageDelayed(m, CELL_CONNECTION_RENEW_MS);
-                    break;
-                case PhoneConstants.APN_REQUEST_FAILED:
-                default:
-                    retValue = false;
-                    break;
-                }
-
-                return retValue;
-            }
-            protected boolean turnOffUpstreamMobileConnection() {
-                // ignore pending renewal requests
-                ++mCurrentConnectionSequence;
-                if (mMobileApnReserved != ConnectivityManager.TYPE_NONE) {
-                    try {
-                        mConnService.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                                enableString(mMobileApnReserved));
-                    } catch (Exception e) {
-                        return false;
-                    }
-                    mMobileApnReserved = ConnectivityManager.TYPE_NONE;
-                }
-                return true;
-            }
-            protected boolean turnOnMasterTetherSettings() {
-                try {
-                    mNMService.setIpForwardingEnabled(true);
-                } catch (Exception e) {
-                    transitionTo(mSetIpForwardingEnabledErrorState);
-                    return false;
-                }
-                try {
-                    mNMService.startTethering(mDhcpRange);
-                } catch (Exception e) {
-                    try {
-                        mNMService.stopTethering();
-                        mNMService.startTethering(mDhcpRange);
-                    } catch (Exception ee) {
-                        transitionTo(mStartTetheringErrorState);
-                        return false;
-                    }
-                }
-                try {
-                    mNMService.setDnsForwarders(mDefaultDnsServers);
-                } catch (Exception e) {
-                    transitionTo(mSetDnsForwardersErrorState);
-                    return false;
-                }
-                return true;
-            }
-            protected boolean turnOffMasterTetherSettings() {
-                try {
-                    mNMService.stopTethering();
-                } catch (Exception e) {
-                    transitionTo(mStopTetheringErrorState);
-                    return false;
-                }
-                try {
-                    mNMService.setIpForwardingEnabled(false);
-                } catch (Exception e) {
-                    transitionTo(mSetIpForwardingDisabledErrorState);
-                    return false;
-                }
-                transitionTo(mInitialState);
-                return true;
-            }
-
-            protected void chooseUpstreamType(boolean tryCell) {
-                int upType = ConnectivityManager.TYPE_NONE;
-                String iface = null;
-
-                updateConfiguration(); // TODO - remove?
-
-                synchronized (mPublicSync) {
-                    if (VDBG) {
-                        Log.d(TAG, "chooseUpstreamType has upstream iface types:");
-                        for (Integer netType : mUpstreamIfaceTypes) {
-                            Log.d(TAG, " " + netType);
-                        }
-                    }
-
-                    for (Integer netType : mUpstreamIfaceTypes) {
-                        NetworkInfo info = null;
-                        try {
-                            info = mConnService.getNetworkInfo(netType.intValue());
-                        } catch (RemoteException e) { }
-                        if ((info != null) && info.isConnected()) {
-                            upType = netType.intValue();
-                            break;
-                        }
-                    }
-                }
-
-                if (DBG) {
-                    Log.d(TAG, "chooseUpstreamType(" + tryCell + "), preferredApn ="
-                            + mPreferredUpstreamMobileApn + ", got type=" + upType);
-                }
-
-                // if we're on DUN, put our own grab on it
-                if (upType == ConnectivityManager.TYPE_MOBILE_DUN ||
-                        upType == ConnectivityManager.TYPE_MOBILE_HIPRI) {
-                    turnOnUpstreamMobileConnection(upType);
-                } else if (upType != ConnectivityManager.TYPE_NONE) {
-                    /* If we've found an active upstream connection that's not DUN/HIPRI
-                     * we should stop any outstanding DUN/HIPRI start requests.
-                     *
-                     * If we found NONE we don't want to do this as we want any previous
-                     * requests to keep trying to bring up something we can use.
-                     */
-                    turnOffUpstreamMobileConnection();
-                }
-
-                if (upType == ConnectivityManager.TYPE_NONE) {
-                    boolean tryAgainLater = true;
-                    if ((tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) &&
-                            (turnOnUpstreamMobileConnection(mPreferredUpstreamMobileApn) == true)) {
-                        // we think mobile should be coming up - don't set a retry
-                        tryAgainLater = false;
-                    }
-                    if (tryAgainLater) {
-                        sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
-                    }
-                } else {
-                    LinkProperties linkProperties = null;
-                    try {
-                        linkProperties = mConnService.getLinkProperties(upType);
-                    } catch (RemoteException e) { }
-                    if (linkProperties != null) {
-                        // Find the interface with the default IPv4 route. It may be the
-                        // interface described by linkProperties, or one of the interfaces
-                        // stacked on top of it.
-                        Log.i(TAG, "Finding IPv4 upstream interface on: " + linkProperties);
-                        RouteInfo ipv4Default = RouteInfo.selectBestRoute(
-                            linkProperties.getAllRoutes(), Inet4Address.ANY);
-                        if (ipv4Default != null) {
-                            iface = ipv4Default.getInterface();
-                            Log.i(TAG, "Found interface " + ipv4Default.getInterface());
-                        } else {
-                            Log.i(TAG, "No IPv4 upstream interface, giving up.");
-                        }
-                    }
-
-                    if (iface != null) {
-                        String[] dnsServers = mDefaultDnsServers;
-                        Collection<InetAddress> dnses = linkProperties.getDnses();
-                        if (dnses != null) {
-                            // we currently only handle IPv4
-                            ArrayList<InetAddress> v4Dnses =
-                                    new ArrayList<InetAddress>(dnses.size());
-                            for (InetAddress dnsAddress : dnses) {
-                                if (dnsAddress instanceof Inet4Address) {
-                                    v4Dnses.add(dnsAddress);
-                                }
-                            }
-                            if (v4Dnses.size() > 0) {
-                                dnsServers = NetworkUtils.makeStrings(v4Dnses);
-                            }
-                        }
-                        try {
-                            mNMService.setDnsForwarders(dnsServers);
-                        } catch (Exception e) {
-                            transitionTo(mSetDnsForwardersErrorState);
-                        }
-                    }
-                }
-                notifyTetheredOfNewUpstreamIface(iface);
-            }
-
-            protected void notifyTetheredOfNewUpstreamIface(String ifaceName) {
-                if (DBG) Log.d(TAG, "notifying tethered with iface =" + ifaceName);
-                mUpstreamIfaceName = ifaceName;
-                for (TetherInterfaceSM sm : mNotifyList) {
-                    sm.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED,
-                            ifaceName);
-                }
-            }
-        }
-
-        class InitialState extends TetherMasterUtilState {
-            @Override
-            public void enter() {
-            }
-            @Override
-            public boolean processMessage(Message message) {
-                if (DBG) Log.d(TAG, "MasterInitialState.processMessage what=" + message.what);
-                boolean retValue = true;
-                switch (message.what) {
-                    case CMD_TETHER_MODE_REQUESTED:
-                        TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
-                        if (VDBG) Log.d(TAG, "Tether Mode requested by " + who);
-                        mNotifyList.add(who);
-                        transitionTo(mTetherModeAliveState);
-                        break;
-                    case CMD_TETHER_MODE_UNREQUESTED:
-                        who = (TetherInterfaceSM)message.obj;
-                        if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who);
-                        int index = mNotifyList.indexOf(who);
-                        if (index != -1) {
-                            mNotifyList.remove(who);
-                        }
-                        break;
-                    default:
-                        retValue = false;
-                        break;
-                }
-                return retValue;
-            }
-        }
-
-        class TetherModeAliveState extends TetherMasterUtilState {
-            boolean mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE;
-            @Override
-            public void enter() {
-                turnOnMasterTetherSettings(); // may transition us out
-
-                mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE; // better try something first pass
-                                                        // or crazy tests cases will fail
-                chooseUpstreamType(mTryCell);
-                mTryCell = !mTryCell;
-            }
-            @Override
-            public void exit() {
-                turnOffUpstreamMobileConnection();
-                notifyTetheredOfNewUpstreamIface(null);
-            }
-            @Override
-            public boolean processMessage(Message message) {
-                if (DBG) Log.d(TAG, "TetherModeAliveState.processMessage what=" + message.what);
-                boolean retValue = true;
-                switch (message.what) {
-                    case CMD_TETHER_MODE_REQUESTED:
-                        TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
-                        if (VDBG) Log.d(TAG, "Tether Mode requested by " + who);
-                        mNotifyList.add(who);
-                        who.sendMessage(TetherInterfaceSM.CMD_TETHER_CONNECTION_CHANGED,
-                                mUpstreamIfaceName);
-                        break;
-                    case CMD_TETHER_MODE_UNREQUESTED:
-                        who = (TetherInterfaceSM)message.obj;
-                        if (VDBG) Log.d(TAG, "Tether Mode unrequested by " + who);
-                        int index = mNotifyList.indexOf(who);
-                        if (index != -1) {
-                            if (DBG) Log.d(TAG, "TetherModeAlive removing notifyee " + who);
-                            mNotifyList.remove(index);
-                            if (mNotifyList.isEmpty()) {
-                                turnOffMasterTetherSettings(); // transitions appropriately
-                            } else {
-                                if (DBG) {
-                                    Log.d(TAG, "TetherModeAlive still has " + mNotifyList.size() +
-                                            " live requests:");
-                                    for (Object o : mNotifyList) Log.d(TAG, "  " + o);
-                                }
-                            }
-                        } else {
-                           Log.e(TAG, "TetherModeAliveState UNREQUESTED has unknown who: " + who);
-                        }
-                        break;
-                    case CMD_UPSTREAM_CHANGED:
-                        // need to try DUN immediately if Wifi goes down
-                        mTryCell = !WAIT_FOR_NETWORK_TO_SETTLE;
-                        chooseUpstreamType(mTryCell);
-                        mTryCell = !mTryCell;
-                        break;
-                    case CMD_CELL_CONNECTION_RENEW:
-                        // make sure we're still using a requested connection - may have found
-                        // wifi or something since then.
-                        if (mCurrentConnectionSequence == message.arg1) {
-                            if (VDBG) {
-                                Log.d(TAG, "renewing mobile connection - requeuing for another " +
-                                        CELL_CONNECTION_RENEW_MS + "ms");
-                            }
-                            turnOnUpstreamMobileConnection(mMobileApnReserved);
-                        }
-                        break;
-                    case CMD_RETRY_UPSTREAM:
-                        chooseUpstreamType(mTryCell);
-                        mTryCell = !mTryCell;
-                        break;
-                    default:
-                        retValue = false;
-                        break;
-                }
-                return retValue;
-            }
-        }
-
-        class ErrorState extends State {
-            int mErrorNotification;
-            @Override
-            public boolean processMessage(Message message) {
-                boolean retValue = true;
-                switch (message.what) {
-                    case CMD_TETHER_MODE_REQUESTED:
-                        TetherInterfaceSM who = (TetherInterfaceSM)message.obj;
-                        who.sendMessage(mErrorNotification);
-                        break;
-                    default:
-                       retValue = false;
-                }
-                return retValue;
-            }
-            void notify(int msgType) {
-                mErrorNotification = msgType;
-                for (Object o : mNotifyList) {
-                    TetherInterfaceSM sm = (TetherInterfaceSM)o;
-                    sm.sendMessage(msgType);
-                }
-            }
-
-        }
-        class SetIpForwardingEnabledErrorState extends ErrorState {
-            @Override
-            public void enter() {
-                Log.e(TAG, "Error in setIpForwardingEnabled");
-                notify(TetherInterfaceSM.CMD_IP_FORWARDING_ENABLE_ERROR);
-            }
-        }
-
-        class SetIpForwardingDisabledErrorState extends ErrorState {
-            @Override
-            public void enter() {
-                Log.e(TAG, "Error in setIpForwardingDisabled");
-                notify(TetherInterfaceSM.CMD_IP_FORWARDING_DISABLE_ERROR);
-            }
-        }
-
-        class StartTetheringErrorState extends ErrorState {
-            @Override
-            public void enter() {
-                Log.e(TAG, "Error in startTethering");
-                notify(TetherInterfaceSM.CMD_START_TETHERING_ERROR);
-                try {
-                    mNMService.setIpForwardingEnabled(false);
-                } catch (Exception e) {}
-            }
-        }
-
-        class StopTetheringErrorState extends ErrorState {
-            @Override
-            public void enter() {
-                Log.e(TAG, "Error in stopTethering");
-                notify(TetherInterfaceSM.CMD_STOP_TETHERING_ERROR);
-                try {
-                    mNMService.setIpForwardingEnabled(false);
-                } catch (Exception e) {}
-            }
-        }
-
-        class SetDnsForwardersErrorState extends ErrorState {
-            @Override
-            public void enter() {
-                Log.e(TAG, "Error in setDnsForwarders");
-                notify(TetherInterfaceSM.CMD_SET_DNS_FORWARDERS_ERROR);
-                try {
-                    mNMService.stopTethering();
-                } catch (Exception e) {}
-                try {
-                    mNMService.setIpForwardingEnabled(false);
-                } catch (Exception e) {}
-            }
-        }
-    }
-
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump ConnectivityService.Tether " +
-                    "from from pid=" + Binder.getCallingPid() + ", uid=" +
-                    Binder.getCallingUid());
-                    return;
-        }
-
-        synchronized (mPublicSync) {
-            pw.println("mUpstreamIfaceTypes: ");
-            for (Integer netType : mUpstreamIfaceTypes) {
-                pw.println(" " + netType);
-            }
-
-            pw.println();
-            pw.println("Tether state:");
-            for (Object o : mIfaces.values()) {
-                pw.println(" " + o);
-            }
-        }
-        pw.println();
-        return;
-    }
-}
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
deleted file mode 100644
index 03405e7..0000000
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ /dev/null
@@ -1,1215 +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.server.connectivity;
-
-import static android.Manifest.permission.BIND_VPN_SERVICE;
-
-import android.app.AppGlobals;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-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.ApplicationInfo;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.UserInfo;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-import android.net.BaseNetworkStateTracker;
-import android.net.ConnectivityManager;
-import android.net.IConnectivityManager;
-import android.net.INetworkManagementEventObserver;
-import android.net.LinkAddress;
-import android.net.LinkProperties;
-import android.net.LocalSocket;
-import android.net.LocalSocketAddress;
-import android.net.NetworkInfo;
-import android.net.NetworkUtils;
-import android.net.RouteInfo;
-import android.net.NetworkInfo.DetailedState;
-import android.os.Binder;
-import android.os.FileUtils;
-import android.os.IBinder;
-import android.os.INetworkManagementService;
-import android.os.Parcel;
-import android.os.ParcelFileDescriptor;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.SystemService;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.security.Credentials;
-import android.security.KeyStore;
-import android.util.Log;
-import android.util.SparseBooleanArray;
-import android.widget.Toast;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.R;
-import com.android.internal.net.LegacyVpnInfo;
-import com.android.internal.net.VpnConfig;
-import com.android.internal.net.VpnProfile;
-import com.android.internal.util.Preconditions;
-import com.android.server.ConnectivityService.VpnCallback;
-import com.android.server.net.BaseNetworkObserver;
-
-import java.io.File;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import libcore.io.IoUtils;
-
-/**
- * @hide
- */
-public class Vpn extends BaseNetworkStateTracker {
-    private static final String TAG = "Vpn";
-    private static final boolean LOGD = true;
-    
-    // TODO: create separate trackers for each unique VPN to support
-    // automated reconnection
-
-    private final VpnCallback mCallback;
-
-    private String mPackage = VpnConfig.LEGACY_VPN;
-    private String mInterface;
-    private Connection mConnection;
-    private LegacyVpnRunner mLegacyVpnRunner;
-    private PendingIntent mStatusIntent;
-    private volatile boolean mEnableNotif = true;
-    private volatile boolean mEnableTeardown = true;
-    private final IConnectivityManager mConnService;
-    private VpnConfig mConfig;
-
-    /* list of users using this VPN. */
-    @GuardedBy("this")
-    private SparseBooleanArray mVpnUsers = null;
-    private BroadcastReceiver mUserIntentReceiver = null;
-
-    private final int mUserId;
-
-    public Vpn(Context context, VpnCallback callback, INetworkManagementService netService,
-            IConnectivityManager connService, int userId) {
-        // TODO: create dedicated TYPE_VPN network type
-        super(ConnectivityManager.TYPE_DUMMY);
-        mContext = context;
-        mCallback = callback;
-        mConnService = connService;
-        mUserId = userId;
-
-        try {
-            netService.registerObserver(mObserver);
-        } catch (RemoteException e) {
-            Log.wtf(TAG, "Problem registering observer", e);
-        }
-        if (userId == UserHandle.USER_OWNER) {
-            // Owner's VPN also needs to handle restricted users
-            mUserIntentReceiver = new BroadcastReceiver() {
-                @Override
-                public void onReceive(Context context, Intent intent) {
-                    final String action = intent.getAction();
-                    final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
-                            UserHandle.USER_NULL);
-                    if (userId == UserHandle.USER_NULL) return;
-
-                    if (Intent.ACTION_USER_ADDED.equals(action)) {
-                        onUserAdded(userId);
-                    } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
-                        onUserRemoved(userId);
-                    }
-                }
-            };
-
-            IntentFilter intentFilter = new IntentFilter();
-            intentFilter.addAction(Intent.ACTION_USER_ADDED);
-            intentFilter.addAction(Intent.ACTION_USER_REMOVED);
-            mContext.registerReceiverAsUser(
-                    mUserIntentReceiver, UserHandle.ALL, intentFilter, null, null);
-        }
-    }
-
-    /**
-     * Set if this object is responsible for showing its own notifications. When
-     * {@code false}, notifications are handled externally by someone else.
-     */
-    public void setEnableNotifications(boolean enableNotif) {
-        mEnableNotif = enableNotif;
-    }
-
-    /**
-     * Set if this object is responsible for watching for {@link NetworkInfo}
-     * teardown. When {@code false}, teardown is handled externally by someone
-     * else.
-     */
-    public void setEnableTeardown(boolean enableTeardown) {
-        mEnableTeardown = enableTeardown;
-    }
-
-    @Override
-    protected void startMonitoringInternal() {
-        // Ignored; events are sent through callbacks for now
-    }
-
-    @Override
-    public boolean teardown() {
-        // TODO: finish migration to unique tracker for each VPN
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean reconnect() {
-        // TODO: finish migration to unique tracker for each VPN
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public String getTcpBufferSizesPropName() {
-        return PROP_TCP_BUFFER_UNKNOWN;
-    }
-
-    /**
-     * Update current state, dispaching event to listeners.
-     */
-    private void updateState(DetailedState detailedState, String reason) {
-        if (LOGD) Log.d(TAG, "setting state=" + detailedState + ", reason=" + reason);
-        mNetworkInfo.setDetailedState(detailedState, reason, null);
-        mCallback.onStateChanged(new NetworkInfo(mNetworkInfo));
-    }
-
-    /**
-     * Prepare for a VPN application. This method is designed to solve
-     * race conditions. It first compares the current prepared package
-     * with {@code oldPackage}. If they are the same, the prepared
-     * package is revoked and replaced with {@code newPackage}. If
-     * {@code oldPackage} is {@code null}, the comparison is omitted.
-     * If {@code newPackage} is the same package or {@code null}, the
-     * revocation is omitted. This method returns {@code true} if the
-     * operation is succeeded.
-     *
-     * Legacy VPN is handled specially since it is not a real package.
-     * It uses {@link VpnConfig#LEGACY_VPN} as its package name, and
-     * it can be revoked by itself.
-     *
-     * @param oldPackage The package name of the old VPN application.
-     * @param newPackage The package name of the new VPN application.
-     * @return true if the operation is succeeded.
-     */
-    public synchronized boolean prepare(String oldPackage, String newPackage) {
-        // Return false if the package does not match.
-        if (oldPackage != null && !oldPackage.equals(mPackage)) {
-            return false;
-        }
-
-        // Return true if we do not need to revoke.
-        if (newPackage == null ||
-                (newPackage.equals(mPackage) && !newPackage.equals(VpnConfig.LEGACY_VPN))) {
-            return true;
-        }
-
-        // Check if the caller is authorized.
-        enforceControlPermission();
-
-        // Reset the interface and hide the notification.
-        if (mInterface != null) {
-            final long token = Binder.clearCallingIdentity();
-            try {
-                mCallback.restore();
-                final int size = mVpnUsers.size();
-                final boolean forwardDns = (mConfig.dnsServers != null &&
-                        mConfig.dnsServers.size() != 0);
-                for (int i = 0; i < size; i++) {
-                    int user = mVpnUsers.keyAt(i);
-                    mCallback.clearUserForwarding(mInterface, user, forwardDns);
-                    hideNotification(user);
-                }
-
-                mCallback.clearMarkedForwarding(mInterface);
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-            jniReset(mInterface);
-            mInterface = null;
-            mVpnUsers = null;
-        }
-
-        // Revoke the connection or stop LegacyVpnRunner.
-        if (mConnection != null) {
-            try {
-                mConnection.mService.transact(IBinder.LAST_CALL_TRANSACTION,
-                        Parcel.obtain(), null, IBinder.FLAG_ONEWAY);
-            } catch (Exception e) {
-                // ignore
-            }
-            mContext.unbindService(mConnection);
-            mConnection = null;
-        } else if (mLegacyVpnRunner != null) {
-            mLegacyVpnRunner.exit();
-            mLegacyVpnRunner = null;
-        }
-
-        Log.i(TAG, "Switched from " + mPackage + " to " + newPackage);
-        mPackage = newPackage;
-        mConfig = null;
-        updateState(DetailedState.IDLE, "prepare");
-        return true;
-    }
-
-    /**
-     * Protect a socket from VPN rules by binding it to the main routing table.
-     * The socket is NOT closed by this method.
-     *
-     * @param socket The socket to be bound.
-     */
-    public void protect(ParcelFileDescriptor socket) throws Exception {
-
-        PackageManager pm = mContext.getPackageManager();
-        int appUid = pm.getPackageUid(mPackage, mUserId);
-        if (Binder.getCallingUid() != appUid) {
-            throw new SecurityException("Unauthorized Caller");
-        }
-        // protect the socket from routing rules
-        final long token = Binder.clearCallingIdentity();
-        try {
-            mCallback.protect(socket);
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-
-    }
-
-    /**
-     * Establish a VPN network and return the file descriptor of the VPN
-     * interface. This methods returns {@code null} if the application is
-     * revoked or not prepared.
-     *
-     * @param config The parameters to configure the network.
-     * @return The file descriptor of the VPN interface.
-     */
-    public synchronized ParcelFileDescriptor establish(VpnConfig config) {
-        // Check if the caller is already prepared.
-        UserManager mgr = UserManager.get(mContext);
-        PackageManager pm = mContext.getPackageManager();
-        ApplicationInfo app = null;
-        try {
-            app = AppGlobals.getPackageManager().getApplicationInfo(mPackage, 0, mUserId);
-            if (Binder.getCallingUid() != app.uid) {
-                return null;
-            }
-        } catch (Exception e) {
-            return null;
-        }
-        // Check if the service is properly declared.
-        Intent intent = new Intent(VpnConfig.SERVICE_INTERFACE);
-        intent.setClassName(mPackage, config.user);
-        long token = Binder.clearCallingIdentity();
-        try {
-            // Restricted users are not allowed to create VPNs, they are tied to Owner
-            UserInfo user = mgr.getUserInfo(mUserId);
-            if (user.isRestricted()) {
-                throw new SecurityException("Restricted users cannot establish VPNs");
-            }
-
-            ResolveInfo info = AppGlobals.getPackageManager().resolveService(intent,
-                                                                        null, 0, mUserId);
-            if (info == null) {
-                throw new SecurityException("Cannot find " + config.user);
-            }
-            if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
-                throw new SecurityException(config.user + " does not require " + BIND_VPN_SERVICE);
-            }
-        } catch (RemoteException e) {
-                throw new SecurityException("Cannot find " + config.user);
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-
-        // Configure the interface. Abort if any of these steps fails.
-        ParcelFileDescriptor tun = ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
-        try {
-            updateState(DetailedState.CONNECTING, "establish");
-            String interfaze = jniGetName(tun.getFd());
-
-            // TEMP use the old jni calls until there is support for netd address setting
-            StringBuilder builder = new StringBuilder();
-            for (LinkAddress address : config.addresses) {
-                builder.append(" " + address);
-            }
-            if (jniSetAddresses(interfaze, builder.toString()) < 1) {
-                throw new IllegalArgumentException("At least one address must be specified");
-            }
-            Connection connection = new Connection();
-            if (!mContext.bindServiceAsUser(intent, connection, Context.BIND_AUTO_CREATE,
-                        new UserHandle(mUserId))) {
-                throw new IllegalStateException("Cannot bind " + config.user);
-            }
-            if (mConnection != null) {
-                mContext.unbindService(mConnection);
-            }
-            if (mInterface != null && !mInterface.equals(interfaze)) {
-                jniReset(mInterface);
-            }
-            mConnection = connection;
-            mInterface = interfaze;
-
-            // Fill more values.
-            config.user = mPackage;
-            config.interfaze = mInterface;
-            config.startTime = SystemClock.elapsedRealtime();
-            mConfig = config;
-            // Set up forwarding and DNS rules.
-            mVpnUsers = new SparseBooleanArray();
-            token = Binder.clearCallingIdentity();
-            try {
-                mCallback.setMarkedForwarding(mInterface);
-                mCallback.setRoutes(interfaze, config.routes);
-                mCallback.override(mInterface, config.dnsServers, config.searchDomains);
-                addVpnUserLocked(mUserId);
-
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-
-        } catch (RuntimeException e) {
-            updateState(DetailedState.FAILED, "establish");
-            IoUtils.closeQuietly(tun);
-            // make sure marked forwarding is cleared if it was set
-            try {
-                mCallback.clearMarkedForwarding(mInterface);
-            } catch (Exception ingored) {
-                // ignored
-            }
-            throw e;
-        }
-        Log.i(TAG, "Established by " + config.user + " on " + mInterface);
-
-
-        // If we are owner assign all Restricted Users to this VPN
-        if (mUserId == UserHandle.USER_OWNER) {
-            token = Binder.clearCallingIdentity();
-            try {
-                for (UserInfo user : mgr.getUsers()) {
-                    if (user.isRestricted()) {
-                        try {
-                            addVpnUserLocked(user.id);
-                        } catch (Exception e) {
-                            Log.wtf(TAG, "Failed to add user " + user.id + " to owner's VPN");
-                        }
-                    }
-                }
-            } finally {
-                Binder.restoreCallingIdentity(token);
-            }
-        }
-        // TODO: ensure that contract class eventually marks as connected
-        updateState(DetailedState.AUTHENTICATING, "establish");
-        return tun;
-    }
-
-    /**
-     * Check if a given address is covered by the VPN's routing rules.
-     */
-    public boolean isAddressCovered(InetAddress address) {
-        synchronized (Vpn.this) {
-            if (!isRunningLocked()) {
-                return false;
-            }
-            return RouteInfo.selectBestRoute(mConfig.routes, address) != null;
-        }
-    }
-
-    private boolean isRunningLocked() {
-        return mVpnUsers != null;
-    }
-
-    private void addVpnUserLocked(int user) {
-        enforceControlPermission();
-
-        if (!isRunningLocked()) {
-            throw new IllegalStateException("VPN is not active");
-        }
-
-        final boolean forwardDns = (mConfig.dnsServers != null &&
-                mConfig.dnsServers.size() != 0);
-
-        // add the user
-        mCallback.addUserForwarding(mInterface, user, forwardDns);
-        mVpnUsers.put(user, true);
-
-        // show the notification
-        if (!mPackage.equals(VpnConfig.LEGACY_VPN)) {
-            // Load everything for the user's notification
-            PackageManager pm = mContext.getPackageManager();
-            ApplicationInfo app = null;
-            try {
-                app = AppGlobals.getPackageManager().getApplicationInfo(mPackage, 0, mUserId);
-            } catch (RemoteException e) {
-                throw new IllegalStateException("Invalid application");
-            }
-            String label = app.loadLabel(pm).toString();
-            // Load the icon and convert it into a bitmap.
-            Drawable icon = app.loadIcon(pm);
-            Bitmap bitmap = null;
-            if (icon.getIntrinsicWidth() > 0 && icon.getIntrinsicHeight() > 0) {
-                int width = mContext.getResources().getDimensionPixelSize(
-                        android.R.dimen.notification_large_icon_width);
-                int height = mContext.getResources().getDimensionPixelSize(
-                        android.R.dimen.notification_large_icon_height);
-                icon.setBounds(0, 0, width, height);
-                bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
-                Canvas c = new Canvas(bitmap);
-                icon.draw(c);
-                c.setBitmap(null);
-            }
-            showNotification(label, bitmap, user);
-        } else {
-            showNotification(null, null, user);
-        }
-    }
-
-    private void removeVpnUserLocked(int user) {
-            enforceControlPermission();
-
-            if (!isRunningLocked()) {
-                throw new IllegalStateException("VPN is not active");
-            }
-            final boolean forwardDns = (mConfig.dnsServers != null &&
-                    mConfig.dnsServers.size() != 0);
-            mCallback.clearUserForwarding(mInterface, user, forwardDns);
-            mVpnUsers.delete(user);
-            hideNotification(user);
-    }
-
-    private void onUserAdded(int userId) {
-        // If the user is restricted tie them to the owner's VPN
-        synchronized(Vpn.this) {
-            UserManager mgr = UserManager.get(mContext);
-            UserInfo user = mgr.getUserInfo(userId);
-            if (user.isRestricted()) {
-                try {
-                    addVpnUserLocked(userId);
-                } catch (Exception e) {
-                    Log.wtf(TAG, "Failed to add restricted user to owner", e);
-                }
-            }
-        }
-    }
-
-    private void onUserRemoved(int userId) {
-        // clean up if restricted
-        synchronized(Vpn.this) {
-            UserManager mgr = UserManager.get(mContext);
-            UserInfo user = mgr.getUserInfo(userId);
-            if (user.isRestricted()) {
-                try {
-                    removeVpnUserLocked(userId);
-                } catch (Exception e) {
-                    Log.wtf(TAG, "Failed to remove restricted user to owner", e);
-                }
-            }
-        }
-    }
-
-    /**
-     * Return the configuration of the currently running VPN.
-     */
-    public VpnConfig getVpnConfig() {
-        enforceControlPermission();
-        return mConfig;
-    }
-
-    @Deprecated
-    public synchronized void interfaceStatusChanged(String iface, boolean up) {
-        try {
-            mObserver.interfaceStatusChanged(iface, up);
-        } catch (RemoteException e) {
-            // ignored; target is local
-        }
-    }
-
-    private INetworkManagementEventObserver mObserver = new BaseNetworkObserver() {
-        @Override
-        public void interfaceStatusChanged(String interfaze, boolean up) {
-            synchronized (Vpn.this) {
-                if (!up && mLegacyVpnRunner != null) {
-                    mLegacyVpnRunner.check(interfaze);
-                }
-            }
-        }
-
-        @Override
-        public void interfaceRemoved(String interfaze) {
-            synchronized (Vpn.this) {
-                if (interfaze.equals(mInterface) && jniCheck(interfaze) == 0) {
-                    final long token = Binder.clearCallingIdentity();
-                    try {
-                        final int size = mVpnUsers.size();
-                        final boolean forwardDns = (mConfig.dnsServers != null &&
-                                mConfig.dnsServers.size() != 0);
-                        for (int i = 0; i < size; i++) {
-                            int user = mVpnUsers.keyAt(i);
-                            mCallback.clearUserForwarding(mInterface, user, forwardDns);
-                            hideNotification(user);
-                        }
-                        mVpnUsers = null;
-                        mCallback.clearMarkedForwarding(mInterface);
-
-                        mCallback.restore();
-                    } finally {
-                        Binder.restoreCallingIdentity(token);
-                    }
-                    mInterface = null;
-                    if (mConnection != null) {
-                        mContext.unbindService(mConnection);
-                        mConnection = null;
-                        updateState(DetailedState.DISCONNECTED, "interfaceRemoved");
-                    } else if (mLegacyVpnRunner != null) {
-                        mLegacyVpnRunner.exit();
-                        mLegacyVpnRunner = null;
-                    }
-                }
-            }
-        }
-    };
-
-    private void enforceControlPermission() {
-        // System user is allowed to control VPN.
-        if (Binder.getCallingUid() == Process.SYSTEM_UID) {
-            return;
-        }
-        int appId = UserHandle.getAppId(Binder.getCallingUid());
-        final long token = Binder.clearCallingIdentity();
-        try {
-            // System dialogs are also allowed to control VPN.
-            PackageManager pm = mContext.getPackageManager();
-            ApplicationInfo app = pm.getApplicationInfo(VpnConfig.DIALOGS_PACKAGE, 0);
-            if (appId == app.uid) {
-                return;
-            }
-        } catch (Exception e) {
-            // ignore
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-
-        throw new SecurityException("Unauthorized Caller");
-    }
-
-    private class Connection implements ServiceConnection {
-        private IBinder mService;
-
-        @Override
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            mService = service;
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName name) {
-            mService = null;
-        }
-    }
-
-    private void showNotification(String label, Bitmap icon, int user) {
-        if (!mEnableNotif) return;
-        mStatusIntent = VpnConfig.getIntentForStatusPanel(mContext);
-
-        NotificationManager nm = (NotificationManager)
-                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-
-        if (nm != null) {
-            String title = (label == null) ? mContext.getString(R.string.vpn_title) :
-                    mContext.getString(R.string.vpn_title_long, label);
-            String text = (mConfig.session == null) ? mContext.getString(R.string.vpn_text) :
-                    mContext.getString(R.string.vpn_text_long, mConfig.session);
-
-            Notification notification = new Notification.Builder(mContext)
-                    .setSmallIcon(R.drawable.vpn_connected)
-                    .setLargeIcon(icon)
-                    .setContentTitle(title)
-                    .setContentText(text)
-                    .setContentIntent(mStatusIntent)
-                    .setDefaults(0)
-                    .setOngoing(true)
-                    .build();
-            nm.notifyAsUser(null, R.drawable.vpn_connected, notification, new UserHandle(user));
-        }
-    }
-
-    private void hideNotification(int user) {
-        if (!mEnableNotif) return;
-        mStatusIntent = null;
-
-        NotificationManager nm = (NotificationManager)
-                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-
-        if (nm != null) {
-            nm.cancelAsUser(null, R.drawable.vpn_connected, new UserHandle(user));
-        }
-    }
-
-    private native int jniCreate(int mtu);
-    private native String jniGetName(int tun);
-    private native int jniSetAddresses(String interfaze, String addresses);
-    private native int jniSetRoutes(String interfaze, String routes);
-    private native void jniReset(String interfaze);
-    private native int jniCheck(String interfaze);
-
-    private static RouteInfo findIPv4DefaultRoute(LinkProperties prop) {
-        for (RouteInfo route : prop.getAllRoutes()) {
-            // Currently legacy VPN only works on IPv4.
-            if (route.isDefaultRoute() && route.getGateway() instanceof Inet4Address) {
-                return route;
-            }
-        }
-
-        throw new IllegalStateException("Unable to find IPv4 default gateway");
-    }
-
-    /**
-     * Start legacy VPN, controlling native daemons as needed. Creates a
-     * secondary thread to perform connection work, returning quickly.
-     */
-    public void startLegacyVpn(VpnProfile profile, KeyStore keyStore, LinkProperties egress) {
-        enforceControlPermission();
-        if (!keyStore.isUnlocked()) {
-            throw new IllegalStateException("KeyStore isn't unlocked");
-        }
-
-        final RouteInfo ipv4DefaultRoute = findIPv4DefaultRoute(egress);
-        final String gateway = ipv4DefaultRoute.getGateway().getHostAddress();
-        final String iface = ipv4DefaultRoute.getInterface();
-
-        // Load certificates.
-        String privateKey = "";
-        String userCert = "";
-        String caCert = "";
-        String serverCert = "";
-        if (!profile.ipsecUserCert.isEmpty()) {
-            privateKey = Credentials.USER_PRIVATE_KEY + profile.ipsecUserCert;
-            byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecUserCert);
-            userCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
-        }
-        if (!profile.ipsecCaCert.isEmpty()) {
-            byte[] value = keyStore.get(Credentials.CA_CERTIFICATE + profile.ipsecCaCert);
-            caCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
-        }
-        if (!profile.ipsecServerCert.isEmpty()) {
-            byte[] value = keyStore.get(Credentials.USER_CERTIFICATE + profile.ipsecServerCert);
-            serverCert = (value == null) ? null : new String(value, StandardCharsets.UTF_8);
-        }
-        if (privateKey == null || userCert == null || caCert == null || serverCert == null) {
-            throw new IllegalStateException("Cannot load credentials");
-        }
-
-        // Prepare arguments for racoon.
-        String[] racoon = null;
-        switch (profile.type) {
-            case VpnProfile.TYPE_L2TP_IPSEC_PSK:
-                racoon = new String[] {
-                    iface, profile.server, "udppsk", profile.ipsecIdentifier,
-                    profile.ipsecSecret, "1701",
-                };
-                break;
-            case VpnProfile.TYPE_L2TP_IPSEC_RSA:
-                racoon = new String[] {
-                    iface, profile.server, "udprsa", privateKey, userCert,
-                    caCert, serverCert, "1701",
-                };
-                break;
-            case VpnProfile.TYPE_IPSEC_XAUTH_PSK:
-                racoon = new String[] {
-                    iface, profile.server, "xauthpsk", profile.ipsecIdentifier,
-                    profile.ipsecSecret, profile.username, profile.password, "", gateway,
-                };
-                break;
-            case VpnProfile.TYPE_IPSEC_XAUTH_RSA:
-                racoon = new String[] {
-                    iface, profile.server, "xauthrsa", privateKey, userCert,
-                    caCert, serverCert, profile.username, profile.password, "", gateway,
-                };
-                break;
-            case VpnProfile.TYPE_IPSEC_HYBRID_RSA:
-                racoon = new String[] {
-                    iface, profile.server, "hybridrsa",
-                    caCert, serverCert, profile.username, profile.password, "", gateway,
-                };
-                break;
-        }
-
-        // Prepare arguments for mtpd.
-        String[] mtpd = null;
-        switch (profile.type) {
-            case VpnProfile.TYPE_PPTP:
-                mtpd = new String[] {
-                    iface, "pptp", profile.server, "1723",
-                    "name", profile.username, "password", profile.password,
-                    "linkname", "vpn", "refuse-eap", "nodefaultroute",
-                    "usepeerdns", "idle", "1800", "mtu", "1400", "mru", "1400",
-                    (profile.mppe ? "+mppe" : "nomppe"),
-                };
-                break;
-            case VpnProfile.TYPE_L2TP_IPSEC_PSK:
-            case VpnProfile.TYPE_L2TP_IPSEC_RSA:
-                mtpd = new String[] {
-                    iface, "l2tp", profile.server, "1701", profile.l2tpSecret,
-                    "name", profile.username, "password", profile.password,
-                    "linkname", "vpn", "refuse-eap", "nodefaultroute",
-                    "usepeerdns", "idle", "1800", "mtu", "1400", "mru", "1400",
-                };
-                break;
-        }
-
-        VpnConfig config = new VpnConfig();
-        config.legacy = true;
-        config.user = profile.key;
-        config.interfaze = iface;
-        config.session = profile.name;
-
-        config.addLegacyRoutes(profile.routes);
-        if (!profile.dnsServers.isEmpty()) {
-            config.dnsServers = Arrays.asList(profile.dnsServers.split(" +"));
-        }
-        if (!profile.searchDomains.isEmpty()) {
-            config.searchDomains = Arrays.asList(profile.searchDomains.split(" +"));
-        }
-        startLegacyVpn(config, racoon, mtpd);
-    }
-
-    private synchronized void startLegacyVpn(VpnConfig config, String[] racoon, String[] mtpd) {
-        stopLegacyVpn();
-
-        // Prepare for the new request. This also checks the caller.
-        prepare(null, VpnConfig.LEGACY_VPN);
-        updateState(DetailedState.CONNECTING, "startLegacyVpn");
-
-        // Start a new LegacyVpnRunner and we are done!
-        mLegacyVpnRunner = new LegacyVpnRunner(config, racoon, mtpd);
-        mLegacyVpnRunner.start();
-    }
-
-    public synchronized void stopLegacyVpn() {
-        if (mLegacyVpnRunner != null) {
-            mLegacyVpnRunner.exit();
-            mLegacyVpnRunner = null;
-
-            synchronized (LegacyVpnRunner.TAG) {
-                // wait for old thread to completely finish before spinning up
-                // new instance, otherwise state updates can be out of order.
-            }
-        }
-    }
-
-    /**
-     * Return the information of the current ongoing legacy VPN.
-     */
-    public synchronized LegacyVpnInfo getLegacyVpnInfo() {
-        // Check if the caller is authorized.
-        enforceControlPermission();
-        if (mLegacyVpnRunner == null) return null;
-
-        final LegacyVpnInfo info = new LegacyVpnInfo();
-        info.key = mConfig.user;
-        info.state = LegacyVpnInfo.stateFromNetworkInfo(mNetworkInfo);
-        if (mNetworkInfo.isConnected()) {
-            info.intent = mStatusIntent;
-        }
-        return info;
-    }
-
-    public VpnConfig getLegacyVpnConfig() {
-        if (mLegacyVpnRunner != null) {
-            return mConfig;
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * Bringing up a VPN connection takes time, and that is all this thread
-     * does. Here we have plenty of time. The only thing we need to take
-     * care of is responding to interruptions as soon as possible. Otherwise
-     * requests will be piled up. This can be done in a Handler as a state
-     * machine, but it is much easier to read in the current form.
-     */
-    private class LegacyVpnRunner extends Thread {
-        private static final String TAG = "LegacyVpnRunner";
-
-        private final String[] mDaemons;
-        private final String[][] mArguments;
-        private final LocalSocket[] mSockets;
-        private final String mOuterInterface;
-        private final AtomicInteger mOuterConnection =
-                new AtomicInteger(ConnectivityManager.TYPE_NONE);
-
-        private long mTimer = -1;
-
-        /**
-         * Watch for the outer connection (passing in the constructor) going away.
-         */
-        private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                if (!mEnableTeardown) return;
-
-                if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
-                    if (intent.getIntExtra(ConnectivityManager.EXTRA_NETWORK_TYPE,
-                            ConnectivityManager.TYPE_NONE) == mOuterConnection.get()) {
-                        NetworkInfo info = (NetworkInfo)intent.getExtra(
-                                ConnectivityManager.EXTRA_NETWORK_INFO);
-                        if (info != null && !info.isConnectedOrConnecting()) {
-                            try {
-                                mObserver.interfaceStatusChanged(mOuterInterface, false);
-                            } catch (RemoteException e) {}
-                        }
-                    }
-                }
-            }
-        };
-
-        public LegacyVpnRunner(VpnConfig config, String[] racoon, String[] mtpd) {
-            super(TAG);
-            mConfig = config;
-            mDaemons = new String[] {"racoon", "mtpd"};
-            // TODO: clear arguments from memory once launched
-            mArguments = new String[][] {racoon, mtpd};
-            mSockets = new LocalSocket[mDaemons.length];
-
-            // This is the interface which VPN is running on,
-            // mConfig.interfaze will change to point to OUR
-            // internal interface soon. TODO - add inner/outer to mconfig
-            // TODO - we have a race - if the outer iface goes away/disconnects before we hit this
-            // we will leave the VPN up.  We should check that it's still there/connected after
-            // registering
-            mOuterInterface = mConfig.interfaze;
-
-            try {
-                mOuterConnection.set(
-                        mConnService.findConnectionTypeForIface(mOuterInterface));
-            } catch (Exception e) {
-                mOuterConnection.set(ConnectivityManager.TYPE_NONE);
-            }
-
-            IntentFilter filter = new IntentFilter();
-            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
-            mContext.registerReceiver(mBroadcastReceiver, filter);
-        }
-
-        public void check(String interfaze) {
-            if (interfaze.equals(mOuterInterface)) {
-                Log.i(TAG, "Legacy VPN is going down with " + interfaze);
-                exit();
-            }
-        }
-
-        public void exit() {
-            // We assume that everything is reset after stopping the daemons.
-            interrupt();
-            for (LocalSocket socket : mSockets) {
-                IoUtils.closeQuietly(socket);
-            }
-            updateState(DetailedState.DISCONNECTED, "exit");
-            try {
-                mContext.unregisterReceiver(mBroadcastReceiver);
-            } catch (IllegalArgumentException e) {}
-        }
-
-        @Override
-        public void run() {
-            // Wait for the previous thread since it has been interrupted.
-            Log.v(TAG, "Waiting");
-            synchronized (TAG) {
-                Log.v(TAG, "Executing");
-                execute();
-                monitorDaemons();
-            }
-        }
-
-        private void checkpoint(boolean yield) throws InterruptedException {
-            long now = SystemClock.elapsedRealtime();
-            if (mTimer == -1) {
-                mTimer = now;
-                Thread.sleep(1);
-            } else if (now - mTimer <= 60000) {
-                Thread.sleep(yield ? 200 : 1);
-            } else {
-                updateState(DetailedState.FAILED, "checkpoint");
-                throw new IllegalStateException("Time is up");
-            }
-        }
-
-        private void execute() {
-            // Catch all exceptions so we can clean up few things.
-            boolean initFinished = false;
-            try {
-                // Initialize the timer.
-                checkpoint(false);
-
-                // Wait for the daemons to stop.
-                for (String daemon : mDaemons) {
-                    while (!SystemService.isStopped(daemon)) {
-                        checkpoint(true);
-                    }
-                }
-
-                // Clear the previous state.
-                File state = new File("/data/misc/vpn/state");
-                state.delete();
-                if (state.exists()) {
-                    throw new IllegalStateException("Cannot delete the state");
-                }
-                new File("/data/misc/vpn/abort").delete();
-                initFinished = true;
-
-                // Check if we need to restart any of the daemons.
-                boolean restart = false;
-                for (String[] arguments : mArguments) {
-                    restart = restart || (arguments != null);
-                }
-                if (!restart) {
-                    updateState(DetailedState.DISCONNECTED, "execute");
-                    return;
-                }
-                updateState(DetailedState.CONNECTING, "execute");
-
-                // Start the daemon with arguments.
-                for (int i = 0; i < mDaemons.length; ++i) {
-                    String[] arguments = mArguments[i];
-                    if (arguments == null) {
-                        continue;
-                    }
-
-                    // Start the daemon.
-                    String daemon = mDaemons[i];
-                    SystemService.start(daemon);
-
-                    // Wait for the daemon to start.
-                    while (!SystemService.isRunning(daemon)) {
-                        checkpoint(true);
-                    }
-
-                    // Create the control socket.
-                    mSockets[i] = new LocalSocket();
-                    LocalSocketAddress address = new LocalSocketAddress(
-                            daemon, LocalSocketAddress.Namespace.RESERVED);
-
-                    // Wait for the socket to connect.
-                    while (true) {
-                        try {
-                            mSockets[i].connect(address);
-                            break;
-                        } catch (Exception e) {
-                            // ignore
-                        }
-                        checkpoint(true);
-                    }
-                    mSockets[i].setSoTimeout(500);
-
-                    // Send over the arguments.
-                    OutputStream out = mSockets[i].getOutputStream();
-                    for (String argument : arguments) {
-                        byte[] bytes = argument.getBytes(StandardCharsets.UTF_8);
-                        if (bytes.length >= 0xFFFF) {
-                            throw new IllegalArgumentException("Argument is too large");
-                        }
-                        out.write(bytes.length >> 8);
-                        out.write(bytes.length);
-                        out.write(bytes);
-                        checkpoint(false);
-                    }
-                    out.write(0xFF);
-                    out.write(0xFF);
-                    out.flush();
-
-                    // Wait for End-of-File.
-                    InputStream in = mSockets[i].getInputStream();
-                    while (true) {
-                        try {
-                            if (in.read() == -1) {
-                                break;
-                            }
-                        } catch (Exception e) {
-                            // ignore
-                        }
-                        checkpoint(true);
-                    }
-                }
-
-                // Wait for the daemons to create the new state.
-                while (!state.exists()) {
-                    // Check if a running daemon is dead.
-                    for (int i = 0; i < mDaemons.length; ++i) {
-                        String daemon = mDaemons[i];
-                        if (mArguments[i] != null && !SystemService.isRunning(daemon)) {
-                            throw new IllegalStateException(daemon + " is dead");
-                        }
-                    }
-                    checkpoint(true);
-                }
-
-                // Now we are connected. Read and parse the new state.
-                String[] parameters = FileUtils.readTextFile(state, 0, null).split("\n", -1);
-                if (parameters.length != 6) {
-                    throw new IllegalStateException("Cannot parse the state");
-                }
-
-                // Set the interface and the addresses in the config.
-                mConfig.interfaze = parameters[0].trim();
-
-                mConfig.addLegacyAddresses(parameters[1]);
-                // Set the routes if they are not set in the config.
-                if (mConfig.routes == null || mConfig.routes.isEmpty()) {
-                    mConfig.addLegacyRoutes(parameters[2]);
-                }
-
-                // Set the DNS servers if they are not set in the config.
-                if (mConfig.dnsServers == null || mConfig.dnsServers.size() == 0) {
-                    String dnsServers = parameters[3].trim();
-                    if (!dnsServers.isEmpty()) {
-                        mConfig.dnsServers = Arrays.asList(dnsServers.split(" "));
-                    }
-                }
-
-                // Set the search domains if they are not set in the config.
-                if (mConfig.searchDomains == null || mConfig.searchDomains.size() == 0) {
-                    String searchDomains = parameters[4].trim();
-                    if (!searchDomains.isEmpty()) {
-                        mConfig.searchDomains = Arrays.asList(searchDomains.split(" "));
-                    }
-                }
-
-                // Set the routes.
-                long token = Binder.clearCallingIdentity();
-                try {
-                    mCallback.setMarkedForwarding(mConfig.interfaze);
-                    mCallback.setRoutes(mConfig.interfaze, mConfig.routes);
-                } finally {
-                    Binder.restoreCallingIdentity(token);
-                }
-
-                // Here is the last step and it must be done synchronously.
-                synchronized (Vpn.this) {
-                    // Set the start time
-                    mConfig.startTime = SystemClock.elapsedRealtime();
-
-                    // Check if the thread is interrupted while we are waiting.
-                    checkpoint(false);
-
-                    // Check if the interface is gone while we are waiting.
-                    if (jniCheck(mConfig.interfaze) == 0) {
-                        throw new IllegalStateException(mConfig.interfaze + " is gone");
-                    }
-
-                    // Now INetworkManagementEventObserver is watching our back.
-                    mInterface = mConfig.interfaze;
-                    mVpnUsers = new SparseBooleanArray();
-
-                    token = Binder.clearCallingIdentity();
-                    try {
-                        mCallback.override(mInterface, mConfig.dnsServers, mConfig.searchDomains);
-                        addVpnUserLocked(mUserId);
-                    } finally {
-                        Binder.restoreCallingIdentity(token);
-                    }
-
-                    // Assign all restircted users to this VPN
-                    // (Legacy VPNs are Owner only)
-                    UserManager mgr = UserManager.get(mContext);
-                    token = Binder.clearCallingIdentity();
-                    try {
-                        for (UserInfo user : mgr.getUsers()) {
-                            if (user.isRestricted()) {
-                                try {
-                                    addVpnUserLocked(user.id);
-                                } catch (Exception e) {
-                                    Log.wtf(TAG, "Failed to add user " + user.id
-                                            + " to owner's VPN");
-                                }
-                            }
-                        }
-                    } finally {
-                        Binder.restoreCallingIdentity(token);
-                    }
-                    Log.i(TAG, "Connected!");
-                    updateState(DetailedState.CONNECTED, "execute");
-                }
-            } catch (Exception e) {
-                Log.i(TAG, "Aborting", e);
-                // make sure the routing is cleared
-                try {
-                    mCallback.clearMarkedForwarding(mConfig.interfaze);
-                } catch (Exception ignored) {
-                }
-                exit();
-            } finally {
-                // Kill the daemons if they fail to stop.
-                if (!initFinished) {
-                    for (String daemon : mDaemons) {
-                        SystemService.stop(daemon);
-                    }
-                }
-
-                // Do not leave an unstable state.
-                if (!initFinished || mNetworkInfo.getDetailedState() == DetailedState.CONNECTING) {
-                    updateState(DetailedState.FAILED, "execute");
-                }
-            }
-        }
-
-        /**
-         * Monitor the daemons we started, moving to disconnected state if the
-         * underlying services fail.
-         */
-        private void monitorDaemons() {
-            if (!mNetworkInfo.isConnected()) {
-                return;
-            }
-
-            try {
-                while (true) {
-                    Thread.sleep(2000);
-                    for (int i = 0; i < mDaemons.length; i++) {
-                        if (mArguments[i] != null && SystemService.isStopped(mDaemons[i])) {
-                            return;
-                        }
-                    }
-                }
-            } catch (InterruptedException e) {
-                Log.d(TAG, "interrupted during monitorDaemons(); stopping services");
-            } finally {
-                for (String daemon : mDaemons) {
-                    SystemService.stop(daemon);
-                }
-
-                updateState(DetailedState.DISCONNECTED, "babysit");
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/content/SyncStorageEngine.java b/services/java/com/android/server/content/SyncStorageEngine.java
deleted file mode 100644
index 5ebf9ea..0000000
--- a/services/java/com/android/server/content/SyncStorageEngine.java
+++ /dev/null
@@ -1,2638 +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.
- */
-
-package com.android.server.content;
-
-import android.accounts.Account;
-import android.accounts.AccountAndUser;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.ISyncStatusObserver;
-import android.content.PeriodicSync;
-import android.content.SyncInfo;
-import android.content.SyncStatusInfo;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteException;
-import android.database.sqlite.SQLiteQueryBuilder;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Parcel;
-import android.os.RemoteCallbackList;
-import android.os.RemoteException;
-import android.util.AtomicFile;
-import android.util.Log;
-import android.util.Pair;
-import android.util.SparseArray;
-import android.util.Xml;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.FastXmlSerializer;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.TimeZone;
-
-/**
- * Singleton that tracks the sync data and overall sync
- * history on the device.
- *
- * @hide
- */
-public class SyncStorageEngine extends Handler {
-
-    private static final String TAG = "SyncManager";
-    private static final boolean DEBUG = false;
-    private static final String TAG_FILE = "SyncManagerFile";
-
-    private static final String XML_ATTR_NEXT_AUTHORITY_ID = "nextAuthorityId";
-    private static final String XML_ATTR_LISTEN_FOR_TICKLES = "listen-for-tickles";
-    private static final String XML_ATTR_SYNC_RANDOM_OFFSET = "offsetInSeconds";
-    private static final String XML_ATTR_ENABLED = "enabled";
-    private static final String XML_ATTR_USER = "user";
-    private static final String XML_TAG_LISTEN_FOR_TICKLES = "listenForTickles";
-
-    /** Default time for a periodic sync. */
-    private static final long DEFAULT_POLL_FREQUENCY_SECONDS = 60 * 60 * 24; // One day
-
-    /** Percentage of period that is flex by default, if no flex is set. */
-    private static final double DEFAULT_FLEX_PERCENT_SYNC = 0.04;
-
-    /** Lower bound on sync time from which we assign a default flex time. */
-    private static final long DEFAULT_MIN_FLEX_ALLOWED_SECS = 5;
-
-    @VisibleForTesting
-    static final long MILLIS_IN_4WEEKS = 1000L * 60 * 60 * 24 * 7 * 4;
-
-    /** Enum value for a sync start event. */
-    public static final int EVENT_START = 0;
-
-    /** Enum value for a sync stop event. */
-    public static final int EVENT_STOP = 1;
-
-    // TODO: i18n -- grab these out of resources.
-    /** String names for the sync event types. */
-    public static final String[] EVENTS = { "START", "STOP" };
-
-    /** Enum value for a server-initiated sync. */
-    public static final int SOURCE_SERVER = 0;
-
-    /** Enum value for a local-initiated sync. */
-    public static final int SOURCE_LOCAL = 1;
-    /**
-     * Enum value for a poll-based sync (e.g., upon connection to
-     * network)
-     */
-    public static final int SOURCE_POLL = 2;
-
-    /** Enum value for a user-initiated sync. */
-    public static final int SOURCE_USER = 3;
-
-    /** Enum value for a periodic sync. */
-    public static final int SOURCE_PERIODIC = 4;
-
-    public static final long NOT_IN_BACKOFF_MODE = -1;
-
-    // TODO: i18n -- grab these out of resources.
-    /** String names for the sync source types. */
-    public static final String[] SOURCES = { "SERVER",
-                                             "LOCAL",
-                                             "POLL",
-                                             "USER",
-                                             "PERIODIC" };
-
-    // The MESG column will contain one of these or one of the Error types.
-    public static final String MESG_SUCCESS = "success";
-    public static final String MESG_CANCELED = "canceled";
-
-    public static final int MAX_HISTORY = 100;
-
-    private static final int MSG_WRITE_STATUS = 1;
-    private static final long WRITE_STATUS_DELAY = 1000*60*10; // 10 minutes
-
-    private static final int MSG_WRITE_STATISTICS = 2;
-    private static final long WRITE_STATISTICS_DELAY = 1000*60*30; // 1/2 hour
-
-    private static final boolean SYNC_ENABLED_DEFAULT = false;
-
-    // the version of the accounts xml file format
-    private static final int ACCOUNTS_VERSION = 2;
-
-    private static HashMap<String, String> sAuthorityRenames;
-
-    static {
-        sAuthorityRenames = new HashMap<String, String>();
-        sAuthorityRenames.put("contacts", "com.android.contacts");
-        sAuthorityRenames.put("calendar", "com.android.calendar");
-    }
-
-    public static class PendingOperation {
-        final Account account;
-        final int userId;
-        final int reason;
-        final int syncSource;
-        final String authority;
-        final Bundle extras;        // note: read-only.
-        final ComponentName serviceName;
-        final boolean expedited;
-
-        int authorityId;
-        byte[] flatExtras;
-
-        PendingOperation(Account account, int userId, int reason, int source,
-                String authority, Bundle extras, boolean expedited) {
-            this.account = account;
-            this.userId = userId;
-            this.syncSource = source;
-            this.reason = reason;
-            this.authority = authority;
-            this.extras = extras != null ? new Bundle(extras) : extras;
-            this.expedited = expedited;
-            this.authorityId = -1;
-            this.serviceName = null;
-        }
-
-        PendingOperation(PendingOperation other) {
-            this.account = other.account;
-            this.userId = other.userId;
-            this.reason = other.reason;
-            this.syncSource = other.syncSource;
-            this.authority = other.authority;
-            this.extras = other.extras;
-            this.authorityId = other.authorityId;
-            this.expedited = other.expedited;
-            this.serviceName = other.serviceName;
-        }
-    }
-
-    static class AccountInfo {
-        final AccountAndUser accountAndUser;
-        final HashMap<String, AuthorityInfo> authorities =
-                new HashMap<String, AuthorityInfo>();
-
-        AccountInfo(AccountAndUser accountAndUser) {
-            this.accountAndUser = accountAndUser;
-        }
-    }
-
-    public static class AuthorityInfo {
-        final ComponentName service;
-        final Account account;
-        final int userId;
-        final String authority;
-        final int ident;
-        boolean enabled;
-        int syncable;
-        long backoffTime;
-        long backoffDelay;
-        long delayUntil;
-        final ArrayList<PeriodicSync> periodicSyncs;
-
-        /**
-         * Copy constructor for making deep-ish copies. Only the bundles stored
-         * in periodic syncs can make unexpected changes.
-         *
-         * @param toCopy AuthorityInfo to be copied.
-         */
-        AuthorityInfo(AuthorityInfo toCopy) {
-            account = toCopy.account;
-            userId = toCopy.userId;
-            authority = toCopy.authority;
-            service = toCopy.service;
-            ident = toCopy.ident;
-            enabled = toCopy.enabled;
-            syncable = toCopy.syncable;
-            backoffTime = toCopy.backoffTime;
-            backoffDelay = toCopy.backoffDelay;
-            delayUntil = toCopy.delayUntil;
-            periodicSyncs = new ArrayList<PeriodicSync>();
-            for (PeriodicSync sync : toCopy.periodicSyncs) {
-                // Still not a perfect copy, because we are just copying the mappings.
-                periodicSyncs.add(new PeriodicSync(sync));
-            }
-        }
-
-        /**
-         * Create an authority with one periodic sync scheduled with an empty bundle and syncing
-         * every day. An empty bundle is considered equal to any other bundle see
-         * {@link PeriodicSync.syncExtrasEquals}.
-         * @param account Account that this authority syncs.
-         * @param userId which user this sync is registered for.
-         * @param userId user for which this authority is registered.
-         * @param ident id of this authority.
-         */
-        AuthorityInfo(Account account, int userId, String authority, int ident) {
-            this.account = account;
-            this.userId = userId;
-            this.authority = authority;
-            this.service = null;
-            this.ident = ident;
-            enabled = SYNC_ENABLED_DEFAULT;
-            syncable = -1; // default to "unknown"
-            backoffTime = -1; // if < 0 then we aren't in backoff mode
-            backoffDelay = -1; // if < 0 then we aren't in backoff mode
-            periodicSyncs = new ArrayList<PeriodicSync>();
-            // Old version adds one periodic sync a day.
-            periodicSyncs.add(new PeriodicSync(account, authority,
-                                new Bundle(),
-                                DEFAULT_POLL_FREQUENCY_SECONDS,
-                                calculateDefaultFlexTime(DEFAULT_POLL_FREQUENCY_SECONDS)));
-        }
-
-        /**
-         * Create an authority with one periodic sync scheduled with an empty bundle and syncing
-         * every day using a sync service.
-         * @param cname sync service identifier.
-         * @param userId user for which this authority is registered.
-         * @param ident id of this authority.
-         */
-        AuthorityInfo(ComponentName cname, int userId, int ident) {
-            this.account = null;
-            this.userId = userId;
-            this.authority = null;
-            this.service = cname;
-            this.ident = ident;
-            // Sync service is always enabled.
-            enabled = true;
-            syncable = -1; // default to "unknown"
-            backoffTime = -1; // if < 0 then we aren't in backoff mode
-            backoffDelay = -1; // if < 0 then we aren't in backoff mode
-            periodicSyncs = new ArrayList<PeriodicSync>();
-            periodicSyncs.add(new PeriodicSync(account, authority,
-                                new Bundle(),
-                                DEFAULT_POLL_FREQUENCY_SECONDS,
-                                calculateDefaultFlexTime(DEFAULT_POLL_FREQUENCY_SECONDS)));
-        }
-    }
-
-    public static class SyncHistoryItem {
-        int authorityId;
-        int historyId;
-        long eventTime;
-        long elapsedTime;
-        int source;
-        int event;
-        long upstreamActivity;
-        long downstreamActivity;
-        String mesg;
-        boolean initialization;
-        Bundle extras;
-        int reason;
-    }
-
-    public static class DayStats {
-        public final int day;
-        public int successCount;
-        public long successTime;
-        public int failureCount;
-        public long failureTime;
-
-        public DayStats(int day) {
-            this.day = day;
-        }
-    }
-
-    interface OnSyncRequestListener {
-        /**
-         * Called when a sync is needed on an account(s) due to some change in state.
-         * @param account
-         * @param userId
-         * @param reason
-         * @param authority
-         * @param extras
-         */
-        public void onSyncRequest(Account account, int userId, int reason, String authority,
-                Bundle extras);
-    }
-
-    // Primary list of all syncable authorities.  Also our global lock.
-    private final SparseArray<AuthorityInfo> mAuthorities =
-            new SparseArray<AuthorityInfo>();
-
-    private final HashMap<AccountAndUser, AccountInfo> mAccounts
-            = new HashMap<AccountAndUser, AccountInfo>();
-
-    private final ArrayList<PendingOperation> mPendingOperations =
-            new ArrayList<PendingOperation>();
-
-    private final SparseArray<ArrayList<SyncInfo>> mCurrentSyncs
-            = new SparseArray<ArrayList<SyncInfo>>();
-
-    private final SparseArray<SyncStatusInfo> mSyncStatus =
-            new SparseArray<SyncStatusInfo>();
-
-    private final ArrayList<SyncHistoryItem> mSyncHistory =
-            new ArrayList<SyncHistoryItem>();
-
-    private final RemoteCallbackList<ISyncStatusObserver> mChangeListeners
-            = new RemoteCallbackList<ISyncStatusObserver>();
-
-    /** Reverse mapping for component name -> <userid -> authority id>. */
-    private final HashMap<ComponentName, SparseArray<AuthorityInfo>> mServices =
-            new HashMap<ComponentName, SparseArray<AuthorityInfo>>();
-
-    private int mNextAuthorityId = 0;
-
-    // We keep 4 weeks of stats.
-    private final DayStats[] mDayStats = new DayStats[7*4];
-    private final Calendar mCal;
-    private int mYear;
-    private int mYearInDays;
-
-    private final Context mContext;
-
-    private static volatile SyncStorageEngine sSyncStorageEngine = null;
-
-    private int mSyncRandomOffset;
-
-    /**
-     * This file contains the core engine state: all accounts and the
-     * settings for them.  It must never be lost, and should be changed
-     * infrequently, so it is stored as an XML file.
-     */
-    private final AtomicFile mAccountInfoFile;
-
-    /**
-     * This file contains the current sync status.  We would like to retain
-     * it across boots, but its loss is not the end of the world, so we store
-     * this information as binary data.
-     */
-    private final AtomicFile mStatusFile;
-
-    /**
-     * This file contains sync statistics.  This is purely debugging information
-     * so is written infrequently and can be thrown away at any time.
-     */
-    private final AtomicFile mStatisticsFile;
-
-    /**
-     * This file contains the pending sync operations.  It is a binary file,
-     * which must be updated every time an operation is added or removed,
-     * so we have special handling of it.
-     */
-    private final AtomicFile mPendingFile;
-    private static final int PENDING_FINISH_TO_WRITE = 4;
-    private int mNumPendingFinished = 0;
-
-    private int mNextHistoryId = 0;
-    private SparseArray<Boolean> mMasterSyncAutomatically = new SparseArray<Boolean>();
-    private boolean mDefaultMasterSyncAutomatically;
-
-    private OnSyncRequestListener mSyncRequestListener;
-
-    private SyncStorageEngine(Context context, File dataDir) {
-        mContext = context;
-        sSyncStorageEngine = this;
-
-        mCal = Calendar.getInstance(TimeZone.getTimeZone("GMT+0"));
-
-        mDefaultMasterSyncAutomatically = mContext.getResources().getBoolean(
-               com.android.internal.R.bool.config_syncstorageengine_masterSyncAutomatically);
-
-        File systemDir = new File(dataDir, "system");
-        File syncDir = new File(systemDir, "sync");
-        syncDir.mkdirs();
-
-        maybeDeleteLegacyPendingInfoLocked(syncDir);
-
-        mAccountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml"));
-        mStatusFile = new AtomicFile(new File(syncDir, "status.bin"));
-        mPendingFile = new AtomicFile(new File(syncDir, "pending.xml"));
-        mStatisticsFile = new AtomicFile(new File(syncDir, "stats.bin"));
-
-        readAccountInfoLocked();
-        readStatusLocked();
-        readPendingOperationsLocked();
-        readStatisticsLocked();
-        readAndDeleteLegacyAccountInfoLocked();
-        writeAccountInfoLocked();
-        writeStatusLocked();
-        writePendingOperationsLocked();
-        writeStatisticsLocked();
-    }
-
-    public static SyncStorageEngine newTestInstance(Context context) {
-        return new SyncStorageEngine(context, context.getFilesDir());
-    }
-
-    public static void init(Context context) {
-        if (sSyncStorageEngine != null) {
-            return;
-        }
-        // This call will return the correct directory whether Encrypted File Systems is
-        // enabled or not.
-        File dataDir = Environment.getSecureDataDirectory();
-        sSyncStorageEngine = new SyncStorageEngine(context, dataDir);
-    }
-
-    public static SyncStorageEngine getSingleton() {
-        if (sSyncStorageEngine == null) {
-            throw new IllegalStateException("not initialized");
-        }
-        return sSyncStorageEngine;
-    }
-
-    protected void setOnSyncRequestListener(OnSyncRequestListener listener) {
-        if (mSyncRequestListener == null) {
-            mSyncRequestListener = listener;
-        }
-    }
-
-    @Override public void handleMessage(Message msg) {
-        if (msg.what == MSG_WRITE_STATUS) {
-            synchronized (mAuthorities) {
-                writeStatusLocked();
-            }
-        } else if (msg.what == MSG_WRITE_STATISTICS) {
-            synchronized (mAuthorities) {
-                writeStatisticsLocked();
-            }
-        }
-    }
-
-    public int getSyncRandomOffset() {
-        return mSyncRandomOffset;
-    }
-
-    public void addStatusChangeListener(int mask, ISyncStatusObserver callback) {
-        synchronized (mAuthorities) {
-            mChangeListeners.register(callback, mask);
-        }
-    }
-
-    public void removeStatusChangeListener(ISyncStatusObserver callback) {
-        synchronized (mAuthorities) {
-            mChangeListeners.unregister(callback);
-        }
-    }
-
-    /**
-     * Figure out a reasonable flex time for cases where none is provided (old api calls).
-     * @param syncTimeSeconds requested sync time from now.
-     * @return amount of seconds before syncTimeSeconds that the sync can occur.
-     *      I.e.
-     *      earliest_sync_time = syncTimeSeconds - calculateDefaultFlexTime(syncTimeSeconds)
-     * The flex time is capped at a percentage of the {@link DEFAULT_POLL_FREQUENCY_SECONDS}.
-     */
-    public static long calculateDefaultFlexTime(long syncTimeSeconds) {
-        if (syncTimeSeconds < DEFAULT_MIN_FLEX_ALLOWED_SECS) {
-            // Small enough sync request time that we don't add flex time - developer probably
-            // wants to wait for an operation to occur before syncing so we honour the
-            // request time.
-            return 0L;
-        } else if (syncTimeSeconds < DEFAULT_POLL_FREQUENCY_SECONDS) {
-            return (long) (syncTimeSeconds * DEFAULT_FLEX_PERCENT_SYNC);
-        } else {
-            // Large enough sync request time that we cap the flex time.
-            return (long) (DEFAULT_POLL_FREQUENCY_SECONDS * DEFAULT_FLEX_PERCENT_SYNC);
-        }
-    }
-
-    private void reportChange(int which) {
-        ArrayList<ISyncStatusObserver> reports = null;
-        synchronized (mAuthorities) {
-            int i = mChangeListeners.beginBroadcast();
-            while (i > 0) {
-                i--;
-                Integer mask = (Integer)mChangeListeners.getBroadcastCookie(i);
-                if ((which & mask.intValue()) == 0) {
-                    continue;
-                }
-                if (reports == null) {
-                    reports = new ArrayList<ISyncStatusObserver>(i);
-                }
-                reports.add(mChangeListeners.getBroadcastItem(i));
-            }
-            mChangeListeners.finishBroadcast();
-        }
-
-        if (DEBUG) {
-            Log.v(TAG, "reportChange " + which + " to: " + reports);
-        }
-
-        if (reports != null) {
-            int i = reports.size();
-            while (i > 0) {
-                i--;
-                try {
-                    reports.get(i).onStatusChanged(which);
-                } catch (RemoteException e) {
-                    // The remote callback list will take care of this for us.
-                }
-            }
-        }
-    }
-
-    public boolean getSyncAutomatically(Account account, int userId, String providerName) {
-        synchronized (mAuthorities) {
-            if (account != null) {
-                AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
-                        "getSyncAutomatically");
-                return authority != null && authority.enabled;
-            }
-
-            int i = mAuthorities.size();
-            while (i > 0) {
-                i--;
-                AuthorityInfo authority = mAuthorities.valueAt(i);
-                if (authority.authority.equals(providerName)
-                        && authority.userId == userId
-                        && authority.enabled) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    public void setSyncAutomatically(Account account, int userId, String providerName,
-            boolean sync) {
-        if (DEBUG) {
-            Log.d(TAG, "setSyncAutomatically: " + /* account + */" provider " + providerName
-                    + ", user " + userId + " -> " + sync);
-        }
-        synchronized (mAuthorities) {
-            AuthorityInfo authority = getOrCreateAuthorityLocked(account, userId, providerName, -1,
-                    false);
-            if (authority.enabled == sync) {
-                if (DEBUG) {
-                    Log.d(TAG, "setSyncAutomatically: already set to " + sync + ", doing nothing");
-                }
-                return;
-            }
-            authority.enabled = sync;
-            writeAccountInfoLocked();
-        }
-
-        if (sync) {
-            requestSync(account, userId, SyncOperation.REASON_SYNC_AUTO, providerName,
-                    new Bundle());
-        }
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-    }
-
-    public int getIsSyncable(Account account, int userId, String providerName) {
-        synchronized (mAuthorities) {
-            if (account != null) {
-                AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
-                        "getIsSyncable");
-                if (authority == null) {
-                    return -1;
-                }
-                return authority.syncable;
-            }
-
-            int i = mAuthorities.size();
-            while (i > 0) {
-                i--;
-                AuthorityInfo authority = mAuthorities.valueAt(i);
-                if (authority.authority.equals(providerName)) {
-                    return authority.syncable;
-                }
-            }
-            return -1;
-        }
-    }
-
-    public void setIsSyncable(Account account, int userId, String providerName, int syncable) {
-        if (syncable > 1) {
-            syncable = 1;
-        } else if (syncable < -1) {
-            syncable = -1;
-        }
-        if (DEBUG) {
-            Log.d(TAG, "setIsSyncable: " + account + ", provider " + providerName
-                    + ", user " + userId + " -> " + syncable);
-        }
-        synchronized (mAuthorities) {
-            AuthorityInfo authority =
-                    getOrCreateAuthorityLocked(account, userId, providerName, -1, false);
-            if (authority.syncable == syncable) {
-                if (DEBUG) {
-                    Log.d(TAG, "setIsSyncable: already set to " + syncable + ", doing nothing");
-                }
-                return;
-            }
-            authority.syncable = syncable;
-            writeAccountInfoLocked();
-        }
-
-        if (syncable > 0) {
-            requestSync(account, userId, SyncOperation.REASON_IS_SYNCABLE,  providerName,
-                    new Bundle());
-        }
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-    }
-
-    public Pair<Long, Long> getBackoff(Account account, int userId, String providerName) {
-        synchronized (mAuthorities) {
-            AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
-                    "getBackoff");
-            if (authority == null || authority.backoffTime < 0) {
-                return null;
-            }
-            return Pair.create(authority.backoffTime, authority.backoffDelay);
-        }
-    }
-
-    public void setBackoff(Account account, int userId, String providerName,
-            long nextSyncTime, long nextDelay) {
-        if (DEBUG) {
-            Log.v(TAG, "setBackoff: " + account + ", provider " + providerName
-                    + ", user " + userId
-                    + " -> nextSyncTime " + nextSyncTime + ", nextDelay " + nextDelay);
-        }
-        boolean changed = false;
-        synchronized (mAuthorities) {
-            if (account == null || providerName == null) {
-                for (AccountInfo accountInfo : mAccounts.values()) {
-                    if (account != null && !account.equals(accountInfo.accountAndUser.account)
-                            && userId != accountInfo.accountAndUser.userId) {
-                        continue;
-                    }
-                    for (AuthorityInfo authorityInfo : accountInfo.authorities.values()) {
-                        if (providerName != null
-                                && !providerName.equals(authorityInfo.authority)) {
-                            continue;
-                        }
-                        if (authorityInfo.backoffTime != nextSyncTime
-                                || authorityInfo.backoffDelay != nextDelay) {
-                            authorityInfo.backoffTime = nextSyncTime;
-                            authorityInfo.backoffDelay = nextDelay;
-                            changed = true;
-                        }
-                    }
-                }
-            } else {
-                AuthorityInfo authority =
-                        getOrCreateAuthorityLocked(account, userId, providerName, -1 /* ident */,
-                                true);
-                if (authority.backoffTime == nextSyncTime && authority.backoffDelay == nextDelay) {
-                    return;
-                }
-                authority.backoffTime = nextSyncTime;
-                authority.backoffDelay = nextDelay;
-                changed = true;
-            }
-        }
-
-        if (changed) {
-            reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-        }
-    }
-
-    /**
-     * Callers of this function need to hold a lock for syncQueue object passed in. Bear in mind
-     * this function grabs the lock for {@link #mAuthorities}
-     * @param syncQueue queue containing pending sync operations.
-     */
-    public void clearAllBackoffsLocked(SyncQueue syncQueue) {
-        boolean changed = false;
-        synchronized (mAuthorities) {
-            for (AccountInfo accountInfo : mAccounts.values()) {
-                for (AuthorityInfo authorityInfo : accountInfo.authorities.values()) {
-                    if (authorityInfo.backoffTime != NOT_IN_BACKOFF_MODE
-                            || authorityInfo.backoffDelay != NOT_IN_BACKOFF_MODE) {
-                        if (DEBUG) {
-                            Log.v(TAG, "clearAllBackoffs:"
-                                    + " authority:" + authorityInfo.authority
-                                    + " account:" + accountInfo.accountAndUser.account.name
-                                    + " user:" + accountInfo.accountAndUser.userId
-                                    + " backoffTime was: " + authorityInfo.backoffTime
-                                    + " backoffDelay was: " + authorityInfo.backoffDelay);
-                        }
-                        authorityInfo.backoffTime = NOT_IN_BACKOFF_MODE;
-                        authorityInfo.backoffDelay = NOT_IN_BACKOFF_MODE;
-                        syncQueue.onBackoffChanged(accountInfo.accountAndUser.account,
-                                accountInfo.accountAndUser.userId, authorityInfo.authority, 0);
-                        changed = true;
-                    }
-                }
-            }
-        }
-
-        if (changed) {
-            reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-        }
-    }
-
-    public void setDelayUntilTime(Account account, int userId, String providerName,
-            long delayUntil) {
-        if (DEBUG) {
-            Log.v(TAG, "setDelayUntil: " + account + ", provider " + providerName
-                    + ", user " + userId + " -> delayUntil " + delayUntil);
-        }
-        synchronized (mAuthorities) {
-            AuthorityInfo authority = getOrCreateAuthorityLocked(
-                    account, userId, providerName, -1 /* ident */, true);
-            if (authority.delayUntil == delayUntil) {
-                return;
-            }
-            authority.delayUntil = delayUntil;
-        }
-
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-    }
-
-    public long getDelayUntilTime(Account account, int userId, String providerName) {
-        synchronized (mAuthorities) {
-            AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
-                    "getDelayUntil");
-            if (authority == null) {
-                return 0;
-            }
-            return authority.delayUntil;
-        }
-    }
-
-    private void updateOrRemovePeriodicSync(PeriodicSync toUpdate, int userId, boolean add) {
-        if (DEBUG) {
-            Log.v(TAG, "addOrRemovePeriodicSync: " + toUpdate.account + ", user " + userId
-                    + ", provider " + toUpdate.authority
-                    + " -> period " + toUpdate.period + ", extras " + toUpdate.extras);
-        }
-        synchronized (mAuthorities) {
-            if (toUpdate.period <= 0 && add) {
-                Log.e(TAG, "period < 0, should never happen in updateOrRemovePeriodicSync: add-"
-                        + add);
-            }
-            if (toUpdate.extras == null) {
-                Log.e(TAG, "null extras, should never happen in updateOrRemovePeriodicSync: add-"
-                        + add);
-            }
-            try {
-                AuthorityInfo authority =
-                        getOrCreateAuthorityLocked(toUpdate.account, userId, toUpdate.authority,
-                                -1, false);
-                if (add) {
-                    // add this periodic sync if an equivalent periodic doesn't already exist.
-                    boolean alreadyPresent = false;
-                    for (int i = 0, N = authority.periodicSyncs.size(); i < N; i++) {
-                        PeriodicSync syncInfo = authority.periodicSyncs.get(i);
-                        if (PeriodicSync.syncExtrasEquals(
-                                toUpdate.extras,
-                                syncInfo.extras)) {
-                            if (toUpdate.period == syncInfo.period &&
-                                    toUpdate.flexTime == syncInfo.flexTime) {
-                                // Absolutely the same.
-                                return;
-                            }
-                            authority.periodicSyncs.set(i, new PeriodicSync(toUpdate));
-                            alreadyPresent = true;
-                            break;
-                        }
-                    }
-                    // If we added an entry to the periodicSyncs array also add an entry to
-                    // the periodic syncs status to correspond to it.
-                    if (!alreadyPresent) {
-                        authority.periodicSyncs.add(new PeriodicSync(toUpdate));
-                        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
-                        status.setPeriodicSyncTime(authority.periodicSyncs.size() - 1, 0L);
-                    }
-                } else {
-                    // Remove any periodic syncs that match the authority and extras.
-                    SyncStatusInfo status = mSyncStatus.get(authority.ident);
-                    boolean changed = false;
-                    Iterator<PeriodicSync> iterator = authority.periodicSyncs.iterator();
-                    int i = 0;
-                    while (iterator.hasNext()) {
-                        PeriodicSync syncInfo = iterator.next();
-                        if (PeriodicSync.syncExtrasEquals(syncInfo.extras, toUpdate.extras)) {
-                            iterator.remove();
-                            changed = true;
-                            // If we removed an entry from the periodicSyncs array also
-                            // remove the corresponding entry from the status
-                            if (status != null) {
-                                status.removePeriodicSyncTime(i);
-                            } else {
-                                Log.e(TAG, "Tried removing sync status on remove periodic sync but"
-                                        + "did not find it.");
-                            }
-                        } else {
-                            i++;
-                        }
-                    }
-                    if (!changed) {
-                        return;
-                    }
-                }
-            } finally {
-                writeAccountInfoLocked();
-                writeStatusLocked();
-            }
-        }
-
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-    }
-
-    public void addPeriodicSync(PeriodicSync toAdd, int userId) {
-        updateOrRemovePeriodicSync(toAdd, userId, true /* add */);
-    }
-
-    public void removePeriodicSync(PeriodicSync toRemove, int userId) {
-        updateOrRemovePeriodicSync(toRemove, userId, false /* remove */);
-    }
-
-    public List<PeriodicSync> getPeriodicSyncs(Account account, int userId, String providerName) {
-        ArrayList<PeriodicSync> syncs = new ArrayList<PeriodicSync>();
-        synchronized (mAuthorities) {
-            AuthorityInfo authority = getAuthorityLocked(account, userId, providerName,
-                    "getPeriodicSyncs");
-            if (authority != null) {
-                for (PeriodicSync item : authority.periodicSyncs) {
-                    // Copy and send out. Necessary for thread-safety although it's parceled.
-                    syncs.add(new PeriodicSync(item));
-                }
-            }
-        }
-        return syncs;
-    }
-
-    public void setMasterSyncAutomatically(boolean flag, int userId) {
-        synchronized (mAuthorities) {
-            Boolean auto = mMasterSyncAutomatically.get(userId);
-            if (auto != null && (boolean) auto == flag) {
-                return;
-            }
-            mMasterSyncAutomatically.put(userId, flag);
-            writeAccountInfoLocked();
-        }
-        if (flag) {
-            requestSync(null, userId, SyncOperation.REASON_MASTER_SYNC_AUTO, null,
-                    new Bundle());
-        }
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS);
-        mContext.sendBroadcast(ContentResolver.ACTION_SYNC_CONN_STATUS_CHANGED);
-    }
-
-    public boolean getMasterSyncAutomatically(int userId) {
-        synchronized (mAuthorities) {
-            Boolean auto = mMasterSyncAutomatically.get(userId);
-            return auto == null ? mDefaultMasterSyncAutomatically : auto;
-        }
-    }
-
-    public void removeAuthority(Account account, int userId, String authority) {
-        synchronized (mAuthorities) {
-            removeAuthorityLocked(account, userId, authority, true /* doWrite */);
-        }
-    }
-
-    public AuthorityInfo getAuthority(int authorityId) {
-        synchronized (mAuthorities) {
-            return mAuthorities.get(authorityId);
-        }
-    }
-
-    /**
-     * Returns true if there is currently a sync operation for the given
-     * account or authority actively being processed.
-     */
-    public boolean isSyncActive(Account account, int userId, String authority) {
-        synchronized (mAuthorities) {
-            for (SyncInfo syncInfo : getCurrentSyncs(userId)) {
-                AuthorityInfo ainfo = getAuthority(syncInfo.authorityId);
-                if (ainfo != null && ainfo.account.equals(account)
-                        && ainfo.authority.equals(authority)
-                        && ainfo.userId == userId) {
-                    return true;
-                }
-            }
-        }
-
-        return false;
-    }
-
-    public PendingOperation insertIntoPending(PendingOperation op) {
-        synchronized (mAuthorities) {
-            if (DEBUG) {
-                Log.v(TAG, "insertIntoPending: account=" + op.account
-                        + " user=" + op.userId
-                        + " auth=" + op.authority
-                        + " src=" + op.syncSource
-                        + " extras=" + op.extras);
-            }
-
-            AuthorityInfo authority = getOrCreateAuthorityLocked(op.account, op.userId,
-                    op.authority,
-                    -1 /* desired identifier */,
-                    true /* write accounts to storage */);
-            if (authority == null) {
-                return null;
-            }
-
-            op = new PendingOperation(op);
-            op.authorityId = authority.ident;
-            mPendingOperations.add(op);
-            appendPendingOperationLocked(op);
-
-            SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
-            status.pending = true;
-        }
-
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
-        return op;
-    }
-
-    /**
-     * Remove from list of pending operations. If successful, search through list for matching
-     * authorities. If there are no more pending syncs for the same authority/account/userid,
-     * update the SyncStatusInfo for that authority(authority here is the internal representation
-     * of a 'sync operation'.
-     * @param op
-     * @return
-     */
-    public boolean deleteFromPending(PendingOperation op) {
-        boolean res = false;
-        synchronized (mAuthorities) {
-            if (DEBUG) {
-                Log.v(TAG, "deleteFromPending: account=" + op.account
-                    + " user=" + op.userId
-                    + " auth=" + op.authority
-                    + " src=" + op.syncSource
-                    + " extras=" + op.extras);
-            }
-            if (mPendingOperations.remove(op)) {
-                if (mPendingOperations.size() == 0
-                        || mNumPendingFinished >= PENDING_FINISH_TO_WRITE) {
-                    writePendingOperationsLocked();
-                    mNumPendingFinished = 0;
-                } else {
-                    mNumPendingFinished++;
-                }
-
-                AuthorityInfo authority = getAuthorityLocked(op.account, op.userId, op.authority,
-                        "deleteFromPending");
-                if (authority != null) {
-                    if (DEBUG) Log.v(TAG, "removing - " + authority.toString());
-                    final int N = mPendingOperations.size();
-                    boolean morePending = false;
-                    for (int i=0; i<N; i++) {
-                        PendingOperation cur = mPendingOperations.get(i);
-                        if (cur.account.equals(op.account)
-                                && cur.authority.equals(op.authority)
-                                && cur.userId == op.userId) {
-                            morePending = true;
-                            break;
-                        }
-                    }
-
-                    if (!morePending) {
-                        if (DEBUG) Log.v(TAG, "no more pending!");
-                        SyncStatusInfo status = getOrCreateSyncStatusLocked(authority.ident);
-                        status.pending = false;
-                    }
-                }
-
-                res = true;
-            }
-        }
-
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_PENDING);
-        return res;
-    }
-
-    /**
-     * Return a copy of the current array of pending operations.  The
-     * PendingOperation objects are the real objects stored inside, so that
-     * they can be used with deleteFromPending().
-     */
-    public ArrayList<PendingOperation> getPendingOperations() {
-        synchronized (mAuthorities) {
-            return new ArrayList<PendingOperation>(mPendingOperations);
-        }
-    }
-
-    /**
-     * Return the number of currently pending operations.
-     */
-    public int getPendingOperationCount() {
-        synchronized (mAuthorities) {
-            return mPendingOperations.size();
-        }
-    }
-
-    /**
-     * Called when the set of account has changed, given the new array of
-     * active accounts.
-     */
-    public void doDatabaseCleanup(Account[] accounts, int userId) {
-        synchronized (mAuthorities) {
-            if (DEBUG) Log.v(TAG, "Updating for new accounts...");
-            SparseArray<AuthorityInfo> removing = new SparseArray<AuthorityInfo>();
-            Iterator<AccountInfo> accIt = mAccounts.values().iterator();
-            while (accIt.hasNext()) {
-                AccountInfo acc = accIt.next();
-                if (!ArrayUtils.contains(accounts, acc.accountAndUser.account)
-                        && acc.accountAndUser.userId == userId) {
-                    // This account no longer exists...
-                    if (DEBUG) {
-                        Log.v(TAG, "Account removed: " + acc.accountAndUser);
-                    }
-                    for (AuthorityInfo auth : acc.authorities.values()) {
-                        removing.put(auth.ident, auth);
-                    }
-                    accIt.remove();
-                }
-            }
-
-            // Clean out all data structures.
-            int i = removing.size();
-            if (i > 0) {
-                while (i > 0) {
-                    i--;
-                    int ident = removing.keyAt(i);
-                    mAuthorities.remove(ident);
-                    int j = mSyncStatus.size();
-                    while (j > 0) {
-                        j--;
-                        if (mSyncStatus.keyAt(j) == ident) {
-                            mSyncStatus.remove(mSyncStatus.keyAt(j));
-                        }
-                    }
-                    j = mSyncHistory.size();
-                    while (j > 0) {
-                        j--;
-                        if (mSyncHistory.get(j).authorityId == ident) {
-                            mSyncHistory.remove(j);
-                        }
-                    }
-                }
-                writeAccountInfoLocked();
-                writeStatusLocked();
-                writePendingOperationsLocked();
-                writeStatisticsLocked();
-            }
-        }
-    }
-
-    /**
-     * Called when a sync is starting. Supply a valid ActiveSyncContext with information
-     * about the sync.
-     */
-    public SyncInfo addActiveSync(SyncManager.ActiveSyncContext activeSyncContext) {
-        final SyncInfo syncInfo;
-        synchronized (mAuthorities) {
-            if (DEBUG) {
-                Log.v(TAG, "setActiveSync: account="
-                    + activeSyncContext.mSyncOperation.account
-                    + " auth=" + activeSyncContext.mSyncOperation.authority
-                    + " src=" + activeSyncContext.mSyncOperation.syncSource
-                    + " extras=" + activeSyncContext.mSyncOperation.extras);
-            }
-            AuthorityInfo authority = getOrCreateAuthorityLocked(
-                    activeSyncContext.mSyncOperation.account,
-                    activeSyncContext.mSyncOperation.userId,
-                    activeSyncContext.mSyncOperation.authority,
-                    -1 /* assign a new identifier if creating a new authority */,
-                    true /* write to storage if this results in a change */);
-            syncInfo = new SyncInfo(authority.ident,
-                    authority.account, authority.authority,
-                    activeSyncContext.mStartTime);
-            getCurrentSyncs(authority.userId).add(syncInfo);
-        }
-
-        reportActiveChange();
-        return syncInfo;
-    }
-
-    /**
-     * Called to indicate that a previously active sync is no longer active.
-     */
-    public void removeActiveSync(SyncInfo syncInfo, int userId) {
-        synchronized (mAuthorities) {
-            if (DEBUG) {
-                Log.v(TAG, "removeActiveSync: account=" + syncInfo.account
-                        + " user=" + userId
-                        + " auth=" + syncInfo.authority);
-            }
-            getCurrentSyncs(userId).remove(syncInfo);
-        }
-
-        reportActiveChange();
-    }
-
-    /**
-     * To allow others to send active change reports, to poke clients.
-     */
-    public void reportActiveChange() {
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE);
-    }
-
-    /**
-     * Note that sync has started for the given account and authority.
-     */
-    public long insertStartSyncEvent(Account accountName, int userId, int reason,
-            String authorityName, long now, int source, boolean initialization, Bundle extras) {
-        long id;
-        synchronized (mAuthorities) {
-            if (DEBUG) {
-                Log.v(TAG, "insertStartSyncEvent: account=" + accountName + "user=" + userId
-                    + " auth=" + authorityName + " source=" + source);
-            }
-            AuthorityInfo authority = getAuthorityLocked(accountName, userId, authorityName,
-                    "insertStartSyncEvent");
-            if (authority == null) {
-                return -1;
-            }
-            SyncHistoryItem item = new SyncHistoryItem();
-            item.initialization = initialization;
-            item.authorityId = authority.ident;
-            item.historyId = mNextHistoryId++;
-            if (mNextHistoryId < 0) mNextHistoryId = 0;
-            item.eventTime = now;
-            item.source = source;
-            item.reason = reason;
-            item.extras = extras;
-            item.event = EVENT_START;
-            mSyncHistory.add(0, item);
-            while (mSyncHistory.size() > MAX_HISTORY) {
-                mSyncHistory.remove(mSyncHistory.size()-1);
-            }
-            id = item.historyId;
-            if (DEBUG) Log.v(TAG, "returning historyId " + id);
-        }
-
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
-        return id;
-    }
-
-    public void stopSyncEvent(long historyId, long elapsedTime, String resultMessage,
-            long downstreamActivity, long upstreamActivity) {
-        synchronized (mAuthorities) {
-            if (DEBUG) {
-                Log.v(TAG, "stopSyncEvent: historyId=" + historyId);
-            }
-            SyncHistoryItem item = null;
-            int i = mSyncHistory.size();
-            while (i > 0) {
-                i--;
-                item = mSyncHistory.get(i);
-                if (item.historyId == historyId) {
-                    break;
-                }
-                item = null;
-            }
-
-            if (item == null) {
-                Log.w(TAG, "stopSyncEvent: no history for id " + historyId);
-                return;
-            }
-
-            item.elapsedTime = elapsedTime;
-            item.event = EVENT_STOP;
-            item.mesg = resultMessage;
-            item.downstreamActivity = downstreamActivity;
-            item.upstreamActivity = upstreamActivity;
-
-            SyncStatusInfo status = getOrCreateSyncStatusLocked(item.authorityId);
-
-            status.numSyncs++;
-            status.totalElapsedTime += elapsedTime;
-            switch (item.source) {
-                case SOURCE_LOCAL:
-                    status.numSourceLocal++;
-                    break;
-                case SOURCE_POLL:
-                    status.numSourcePoll++;
-                    break;
-                case SOURCE_USER:
-                    status.numSourceUser++;
-                    break;
-                case SOURCE_SERVER:
-                    status.numSourceServer++;
-                    break;
-                case SOURCE_PERIODIC:
-                    status.numSourcePeriodic++;
-                    break;
-            }
-
-            boolean writeStatisticsNow = false;
-            int day = getCurrentDayLocked();
-            if (mDayStats[0] == null) {
-                mDayStats[0] = new DayStats(day);
-            } else if (day != mDayStats[0].day) {
-                System.arraycopy(mDayStats, 0, mDayStats, 1, mDayStats.length-1);
-                mDayStats[0] = new DayStats(day);
-                writeStatisticsNow = true;
-            } else if (mDayStats[0] == null) {
-            }
-            final DayStats ds = mDayStats[0];
-
-            final long lastSyncTime = (item.eventTime + elapsedTime);
-            boolean writeStatusNow = false;
-            if (MESG_SUCCESS.equals(resultMessage)) {
-                // - if successful, update the successful columns
-                if (status.lastSuccessTime == 0 || status.lastFailureTime != 0) {
-                    writeStatusNow = true;
-                }
-                status.lastSuccessTime = lastSyncTime;
-                status.lastSuccessSource = item.source;
-                status.lastFailureTime = 0;
-                status.lastFailureSource = -1;
-                status.lastFailureMesg = null;
-                status.initialFailureTime = 0;
-                ds.successCount++;
-                ds.successTime += elapsedTime;
-            } else if (!MESG_CANCELED.equals(resultMessage)) {
-                if (status.lastFailureTime == 0) {
-                    writeStatusNow = true;
-                }
-                status.lastFailureTime = lastSyncTime;
-                status.lastFailureSource = item.source;
-                status.lastFailureMesg = resultMessage;
-                if (status.initialFailureTime == 0) {
-                    status.initialFailureTime = lastSyncTime;
-                }
-                ds.failureCount++;
-                ds.failureTime += elapsedTime;
-            }
-
-            if (writeStatusNow) {
-                writeStatusLocked();
-            } else if (!hasMessages(MSG_WRITE_STATUS)) {
-                sendMessageDelayed(obtainMessage(MSG_WRITE_STATUS),
-                        WRITE_STATUS_DELAY);
-            }
-            if (writeStatisticsNow) {
-                writeStatisticsLocked();
-            } else if (!hasMessages(MSG_WRITE_STATISTICS)) {
-                sendMessageDelayed(obtainMessage(MSG_WRITE_STATISTICS),
-                        WRITE_STATISTICS_DELAY);
-            }
-        }
-
-        reportChange(ContentResolver.SYNC_OBSERVER_TYPE_STATUS);
-    }
-
-    /**
-     * Return a list of the currently active syncs. Note that the returned
-     * items are the real, live active sync objects, so be careful what you do
-     * with it.
-     */
-    private List<SyncInfo> getCurrentSyncs(int userId) {
-        synchronized (mAuthorities) {
-            return getCurrentSyncsLocked(userId);
-        }
-    }
-
-    /**
-     * @return a copy of the current syncs data structure. Will not return
-     * null.
-     */
-    public List<SyncInfo> getCurrentSyncsCopy(int userId) {
-        synchronized (mAuthorities) {
-            final List<SyncInfo> syncs = getCurrentSyncsLocked(userId);
-            final List<SyncInfo> syncsCopy = new ArrayList<SyncInfo>();
-            for (SyncInfo sync : syncs) {
-                syncsCopy.add(new SyncInfo(sync));
-            }
-            return syncsCopy;
-        }
-    }
-
-    private List<SyncInfo> getCurrentSyncsLocked(int userId) {
-        ArrayList<SyncInfo> syncs = mCurrentSyncs.get(userId);
-        if (syncs == null) {
-            syncs = new ArrayList<SyncInfo>();
-            mCurrentSyncs.put(userId, syncs);
-        }
-        return syncs;
-    }
-
-    /**
-     * Return an array of the current sync status for all authorities.  Note
-     * that the objects inside the array are the real, live status objects,
-     * so be careful what you do with them.
-     */
-    public ArrayList<SyncStatusInfo> getSyncStatus() {
-        synchronized (mAuthorities) {
-            final int N = mSyncStatus.size();
-            ArrayList<SyncStatusInfo> ops = new ArrayList<SyncStatusInfo>(N);
-            for (int i=0; i<N; i++) {
-                ops.add(mSyncStatus.valueAt(i));
-            }
-            return ops;
-        }
-    }
-
-    /**
-     * Return a copy of the specified authority with the corresponding sync status
-     */
-    public Pair<AuthorityInfo, SyncStatusInfo> getCopyOfAuthorityWithSyncStatus(
-            Account account, int userId, String authority) {
-        synchronized (mAuthorities) {
-            AuthorityInfo authorityInfo = getOrCreateAuthorityLocked(account, userId, authority,
-                    -1 /* assign a new identifier if creating a new authority */,
-                    true /* write to storage if this results in a change */);
-            return createCopyPairOfAuthorityWithSyncStatusLocked(authorityInfo);
-        }
-    }
-
-    /**
-     * Return a copy of all authorities with their corresponding sync status
-     */
-    public ArrayList<Pair<AuthorityInfo, SyncStatusInfo>> getCopyOfAllAuthoritiesWithSyncStatus() {
-        synchronized (mAuthorities) {
-            ArrayList<Pair<AuthorityInfo, SyncStatusInfo>> infos =
-                    new ArrayList<Pair<AuthorityInfo, SyncStatusInfo>>(mAuthorities.size());
-            for (int i = 0; i < mAuthorities.size(); i++) {
-                infos.add(createCopyPairOfAuthorityWithSyncStatusLocked(mAuthorities.valueAt(i)));
-            }
-            return infos;
-        }
-    }
-
-    /**
-     * Returns the status that matches the authority and account.
-     *
-     * @param account the account we want to check
-     * @param authority the authority whose row should be selected
-     * @return the SyncStatusInfo for the authority or null if none found.
-     */
-    public SyncStatusInfo getStatusByAccountAndAuthority(Account account, int userId,
-            String authority) {
-        if (account == null || authority == null) {
-          return null;
-        }
-        synchronized (mAuthorities) {
-            final int N = mSyncStatus.size();
-            for (int i=0; i<N; i++) {
-                SyncStatusInfo cur = mSyncStatus.valueAt(i);
-                AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
-
-                if (ainfo != null && ainfo.authority.equals(authority)
-                        && ainfo.userId == userId
-                        && account.equals(ainfo.account)) {
-                  return cur;
-                }
-            }
-            return null;
-        }
-    }
-
-    /**
-     * Return true if the pending status is true of any matching authorities.
-     */
-    public boolean isSyncPending(Account account, int userId, String authority) {
-        synchronized (mAuthorities) {
-            final int N = mSyncStatus.size();
-            for (int i=0; i<N; i++) {
-                SyncStatusInfo cur = mSyncStatus.valueAt(i);
-                AuthorityInfo ainfo = mAuthorities.get(cur.authorityId);
-                if (ainfo == null) {
-                    continue;
-                }
-                if (userId != ainfo.userId) {
-                    continue;
-                }
-                if (account != null && !ainfo.account.equals(account)) {
-                    continue;
-                }
-                if (ainfo.authority.equals(authority) && cur.pending) {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    /**
-     * Return an array of the current sync status for all authorities.  Note
-     * that the objects inside the array are the real, live status objects,
-     * so be careful what you do with them.
-     */
-    public ArrayList<SyncHistoryItem> getSyncHistory() {
-        synchronized (mAuthorities) {
-            final int N = mSyncHistory.size();
-            ArrayList<SyncHistoryItem> items = new ArrayList<SyncHistoryItem>(N);
-            for (int i=0; i<N; i++) {
-                items.add(mSyncHistory.get(i));
-            }
-            return items;
-        }
-    }
-
-    /**
-     * Return an array of the current per-day statistics.  Note
-     * that the objects inside the array are the real, live status objects,
-     * so be careful what you do with them.
-     */
-    public DayStats[] getDayStatistics() {
-        synchronized (mAuthorities) {
-            DayStats[] ds = new DayStats[mDayStats.length];
-            System.arraycopy(mDayStats, 0, ds, 0, ds.length);
-            return ds;
-        }
-    }
-
-    private Pair<AuthorityInfo, SyncStatusInfo> createCopyPairOfAuthorityWithSyncStatusLocked(
-            AuthorityInfo authorityInfo) {
-        SyncStatusInfo syncStatusInfo = getOrCreateSyncStatusLocked(authorityInfo.ident);
-        return Pair.create(new AuthorityInfo(authorityInfo), new SyncStatusInfo(syncStatusInfo));
-    }
-
-    private int getCurrentDayLocked() {
-        mCal.setTimeInMillis(System.currentTimeMillis());
-        final int dayOfYear = mCal.get(Calendar.DAY_OF_YEAR);
-        if (mYear != mCal.get(Calendar.YEAR)) {
-            mYear = mCal.get(Calendar.YEAR);
-            mCal.clear();
-            mCal.set(Calendar.YEAR, mYear);
-            mYearInDays = (int)(mCal.getTimeInMillis()/86400000);
-        }
-        return dayOfYear + mYearInDays;
-    }
-
-    /**
-     * Retrieve an authority, returning null if one does not exist.
-     *
-     * @param accountName The name of the account for the authority.
-     * @param authorityName The name of the authority itself.
-     * @param tag If non-null, this will be used in a log message if the
-     * requested authority does not exist.
-     */
-    private AuthorityInfo getAuthorityLocked(Account accountName, int userId, String authorityName,
-            String tag) {
-        AccountAndUser au = new AccountAndUser(accountName, userId);
-        AccountInfo accountInfo = mAccounts.get(au);
-        if (accountInfo == null) {
-            if (tag != null) {
-                if (DEBUG) {
-                    Log.v(TAG, tag + ": unknown account " + au);
-                }
-            }
-            return null;
-        }
-        AuthorityInfo authority = accountInfo.authorities.get(authorityName);
-        if (authority == null) {
-            if (tag != null) {
-                if (DEBUG) {
-                    Log.v(TAG, tag + ": unknown authority " + authorityName);
-                }
-            }
-            return null;
-        }
-
-        return authority;
-    }
-
-    /**
-     * Retrieve an authority, returning null if one does not exist.
-     *
-     * @param service The service name used for this sync.
-     * @param userId The user for whom this sync is scheduled.
-     * @param tag If non-null, this will be used in a log message if the
-     * requested authority does not exist.
-     */
-    private AuthorityInfo getAuthorityLocked(ComponentName service, int userId, String tag) {
-        AuthorityInfo authority = mServices.get(service).get(userId);
-        if (authority == null) {
-            if (tag != null) {
-                if (DEBUG) {
-                    Log.v(TAG, tag + " No authority info found for " + service + " for user "
-                            + userId);
-                }
-            }
-            return null;
-        }
-        return authority;
-    }
-
-    /**
-     * @param cname identifier for the service.
-     * @param userId for the syncs corresponding to this authority.
-     * @param ident unique identifier for authority. -1 for none.
-     * @param doWrite if true, update the accounts.xml file on the disk.
-     * @return the authority that corresponds to the provided sync service, creating it if none
-     * exists.
-     */
-    private AuthorityInfo getOrCreateAuthorityLocked(ComponentName cname, int userId, int ident,
-            boolean doWrite) {
-        SparseArray<AuthorityInfo> aInfo = mServices.get(cname);
-        if (aInfo == null) {
-            aInfo = new SparseArray<AuthorityInfo>();
-            mServices.put(cname, aInfo);
-        }
-        AuthorityInfo authority = aInfo.get(userId);
-        if (authority == null) {
-            if (ident < 0) {
-                ident = mNextAuthorityId;
-                mNextAuthorityId++;
-                doWrite = true;
-            }
-            if (DEBUG) {
-                Log.v(TAG, "created a new AuthorityInfo for " + cname.getPackageName()
-                        + ", " + cname.getClassName()
-                        + ", user: " + userId);
-            }
-            authority = new AuthorityInfo(cname, userId, ident);
-            aInfo.put(userId, authority);
-            mAuthorities.put(ident, authority);
-            if (doWrite) {
-                writeAccountInfoLocked();
-            }
-        }
-        return authority;
-    }
-
-    private AuthorityInfo getOrCreateAuthorityLocked(Account accountName, int userId,
-            String authorityName, int ident, boolean doWrite) {
-        AccountAndUser au = new AccountAndUser(accountName, userId);
-        AccountInfo account = mAccounts.get(au);
-        if (account == null) {
-            account = new AccountInfo(au);
-            mAccounts.put(au, account);
-        }
-        AuthorityInfo authority = account.authorities.get(authorityName);
-        if (authority == null) {
-            if (ident < 0) {
-                ident = mNextAuthorityId;
-                mNextAuthorityId++;
-                doWrite = true;
-            }
-            if (DEBUG) {
-                Log.v(TAG, "created a new AuthorityInfo for " + accountName
-                        + ", user " + userId
-                        + ", provider " + authorityName);
-            }
-            authority = new AuthorityInfo(accountName, userId, authorityName, ident);
-            account.authorities.put(authorityName, authority);
-            mAuthorities.put(ident, authority);
-            if (doWrite) {
-                writeAccountInfoLocked();
-            }
-        }
-
-        return authority;
-    }
-
-    private void removeAuthorityLocked(Account account, int userId, String authorityName,
-            boolean doWrite) {
-        AccountInfo accountInfo = mAccounts.get(new AccountAndUser(account, userId));
-        if (accountInfo != null) {
-            final AuthorityInfo authorityInfo = accountInfo.authorities.remove(authorityName);
-            if (authorityInfo != null) {
-                mAuthorities.remove(authorityInfo.ident);
-                if (doWrite) {
-                    writeAccountInfoLocked();
-                }
-            }
-        }
-    }
-
-    /**
-     * Updates (in a synchronized way) the periodic sync time of the specified
-     * authority id and target periodic sync
-     */
-    public void setPeriodicSyncTime(
-            int authorityId, PeriodicSync targetPeriodicSync, long when) {
-        boolean found = false;
-        final AuthorityInfo authorityInfo;
-        synchronized (mAuthorities) {
-            authorityInfo = mAuthorities.get(authorityId);
-            for (int i = 0; i < authorityInfo.periodicSyncs.size(); i++) {
-                PeriodicSync periodicSync = authorityInfo.periodicSyncs.get(i);
-                if (targetPeriodicSync.equals(periodicSync)) {
-                    mSyncStatus.get(authorityId).setPeriodicSyncTime(i, when);
-                    found = true;
-                    break;
-                }
-            }
-        }
-        if (!found) {
-            Log.w(TAG, "Ignoring setPeriodicSyncTime request for a sync that does not exist. " +
-                    "Authority: " + authorityInfo.authority);
-        }
-    }
-
-    private SyncStatusInfo getOrCreateSyncStatusLocked(int authorityId) {
-        SyncStatusInfo status = mSyncStatus.get(authorityId);
-        if (status == null) {
-            status = new SyncStatusInfo(authorityId);
-            mSyncStatus.put(authorityId, status);
-        }
-        return status;
-    }
-
-    public void writeAllState() {
-        synchronized (mAuthorities) {
-            // Account info is always written so no need to do it here.
-
-            if (mNumPendingFinished > 0) {
-                // Only write these if they are out of date.
-                writePendingOperationsLocked();
-            }
-
-            // Just always write these...  they are likely out of date.
-            writeStatusLocked();
-            writeStatisticsLocked();
-        }
-    }
-
-    /**
-     * public for testing
-     */
-    public void clearAndReadState() {
-        synchronized (mAuthorities) {
-            mAuthorities.clear();
-            mAccounts.clear();
-            mServices.clear();
-            mPendingOperations.clear();
-            mSyncStatus.clear();
-            mSyncHistory.clear();
-
-            readAccountInfoLocked();
-            readStatusLocked();
-            readPendingOperationsLocked();
-            readStatisticsLocked();
-            readAndDeleteLegacyAccountInfoLocked();
-            writeAccountInfoLocked();
-            writeStatusLocked();
-            writePendingOperationsLocked();
-            writeStatisticsLocked();
-        }
-    }
-
-    /**
-     * Read all account information back in to the initial engine state.
-     */
-    private void readAccountInfoLocked() {
-        int highestAuthorityId = -1;
-        FileInputStream fis = null;
-        try {
-            fis = mAccountInfoFile.openRead();
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.v(TAG, "Reading " + mAccountInfoFile.getBaseFile());
-            }
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(fis, null);
-            int eventType = parser.getEventType();
-            while (eventType != XmlPullParser.START_TAG) {
-                eventType = parser.next();
-            }
-            String tagName = parser.getName();
-            if ("accounts".equals(tagName)) {
-                String listen = parser.getAttributeValue(null, XML_ATTR_LISTEN_FOR_TICKLES);
-                String versionString = parser.getAttributeValue(null, "version");
-                int version;
-                try {
-                    version = (versionString == null) ? 0 : Integer.parseInt(versionString);
-                } catch (NumberFormatException e) {
-                    version = 0;
-                }
-                String nextIdString = parser.getAttributeValue(null, XML_ATTR_NEXT_AUTHORITY_ID);
-                try {
-                    int id = (nextIdString == null) ? 0 : Integer.parseInt(nextIdString);
-                    mNextAuthorityId = Math.max(mNextAuthorityId, id);
-                } catch (NumberFormatException e) {
-                    // don't care
-                }
-                String offsetString = parser.getAttributeValue(null, XML_ATTR_SYNC_RANDOM_OFFSET);
-                try {
-                    mSyncRandomOffset = (offsetString == null) ? 0 : Integer.parseInt(offsetString);
-                } catch (NumberFormatException e) {
-                    mSyncRandomOffset = 0;
-                }
-                if (mSyncRandomOffset == 0) {
-                    Random random = new Random(System.currentTimeMillis());
-                    mSyncRandomOffset = random.nextInt(86400);
-                }
-                mMasterSyncAutomatically.put(0, listen == null || Boolean.parseBoolean(listen));
-                eventType = parser.next();
-                AuthorityInfo authority = null;
-                PeriodicSync periodicSync = null;
-                do {
-                    if (eventType == XmlPullParser.START_TAG) {
-                        tagName = parser.getName();
-                        if (parser.getDepth() == 2) {
-                            if ("authority".equals(tagName)) {
-                                authority = parseAuthority(parser, version);
-                                periodicSync = null;
-                                if (authority.ident > highestAuthorityId) {
-                                    highestAuthorityId = authority.ident;
-                                }
-                            } else if (XML_TAG_LISTEN_FOR_TICKLES.equals(tagName)) {
-                                parseListenForTickles(parser);
-                            }
-                        } else if (parser.getDepth() == 3) {
-                            if ("periodicSync".equals(tagName) && authority != null) {
-                                periodicSync = parsePeriodicSync(parser, authority);
-                            }
-                        } else if (parser.getDepth() == 4 && periodicSync != null) {
-                            if ("extra".equals(tagName)) {
-                                parseExtra(parser, periodicSync.extras);
-                            }
-                        }
-                    }
-                    eventType = parser.next();
-                } while (eventType != XmlPullParser.END_DOCUMENT);
-            }
-        } catch (XmlPullParserException e) {
-            Log.w(TAG, "Error reading accounts", e);
-            return;
-        } catch (java.io.IOException e) {
-            if (fis == null) Log.i(TAG, "No initial accounts");
-            else Log.w(TAG, "Error reading accounts", e);
-            return;
-        } finally {
-            mNextAuthorityId = Math.max(highestAuthorityId + 1, mNextAuthorityId);
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch (java.io.IOException e1) {
-                }
-            }
-        }
-
-        maybeMigrateSettingsForRenamedAuthorities();
-    }
-
-    /**
-     * Ensure the old pending.bin is deleted, as it has been changed to pending.xml.
-     * pending.xml was used starting in KLP.
-     * @param syncDir directory where the sync files are located.
-     */
-    private void maybeDeleteLegacyPendingInfoLocked(File syncDir) {
-        File file = new File(syncDir, "pending.bin");
-        if (!file.exists()) {
-            return;
-        } else {
-            file.delete();
-        }
-    }
-
-    /**
-     * some authority names have changed. copy over their settings and delete the old ones
-     * @return true if a change was made
-     */
-    private boolean maybeMigrateSettingsForRenamedAuthorities() {
-        boolean writeNeeded = false;
-
-        ArrayList<AuthorityInfo> authoritiesToRemove = new ArrayList<AuthorityInfo>();
-        final int N = mAuthorities.size();
-        for (int i=0; i<N; i++) {
-            AuthorityInfo authority = mAuthorities.valueAt(i);
-            // skip this authority if it isn't one of the renamed ones
-            final String newAuthorityName = sAuthorityRenames.get(authority.authority);
-            if (newAuthorityName == null) {
-                continue;
-            }
-
-            // remember this authority so we can remove it later. we can't remove it
-            // now without messing up this loop iteration
-            authoritiesToRemove.add(authority);
-
-            // this authority isn't enabled, no need to copy it to the new authority name since
-            // the default is "disabled"
-            if (!authority.enabled) {
-                continue;
-            }
-
-            // if we already have a record of this new authority then don't copy over the settings
-            if (getAuthorityLocked(authority.account, authority.userId, newAuthorityName, "cleanup")
-                    != null) {
-                continue;
-            }
-
-            AuthorityInfo newAuthority = getOrCreateAuthorityLocked(authority.account,
-                    authority.userId, newAuthorityName, -1 /* ident */, false /* doWrite */);
-            newAuthority.enabled = true;
-            writeNeeded = true;
-        }
-
-        for (AuthorityInfo authorityInfo : authoritiesToRemove) {
-            removeAuthorityLocked(authorityInfo.account, authorityInfo.userId,
-                    authorityInfo.authority, false /* doWrite */);
-            writeNeeded = true;
-        }
-
-        return writeNeeded;
-    }
-
-    private void parseListenForTickles(XmlPullParser parser) {
-        String user = parser.getAttributeValue(null, XML_ATTR_USER);
-        int userId = 0;
-        try {
-            userId = Integer.parseInt(user);
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "error parsing the user for listen-for-tickles", e);
-        } catch (NullPointerException e) {
-            Log.e(TAG, "the user in listen-for-tickles is null", e);
-        }
-        String enabled = parser.getAttributeValue(null, XML_ATTR_ENABLED);
-        boolean listen = enabled == null || Boolean.parseBoolean(enabled);
-        mMasterSyncAutomatically.put(userId, listen);
-    }
-
-    private AuthorityInfo parseAuthority(XmlPullParser parser, int version) {
-        AuthorityInfo authority = null;
-        int id = -1;
-        try {
-            id = Integer.parseInt(parser.getAttributeValue(null, "id"));
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "error parsing the id of the authority", e);
-        } catch (NullPointerException e) {
-            Log.e(TAG, "the id of the authority is null", e);
-        }
-        if (id >= 0) {
-            String authorityName = parser.getAttributeValue(null, "authority");
-            String enabled = parser.getAttributeValue(null, XML_ATTR_ENABLED);
-            String syncable = parser.getAttributeValue(null, "syncable");
-            String accountName = parser.getAttributeValue(null, "account");
-            String accountType = parser.getAttributeValue(null, "type");
-            String user = parser.getAttributeValue(null, XML_ATTR_USER);
-            String packageName = parser.getAttributeValue(null, "package");
-            String className = parser.getAttributeValue(null, "class");
-            int userId = user == null ? 0 : Integer.parseInt(user);
-            if (accountType == null) {
-                accountType = "com.google";
-                syncable = "unknown";
-            }
-            authority = mAuthorities.get(id);
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.v(TAG, "Adding authority: account="
-                        + accountName + " auth=" + authorityName
-                        + " user=" + userId
-                        + " enabled=" + enabled
-                        + " syncable=" + syncable);
-            }
-            if (authority == null) {
-                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                    Log.v(TAG, "Creating entry");
-                }
-                if (accountName != null && accountType != null) {
-                    authority = getOrCreateAuthorityLocked(
-                            new Account(accountName, accountType), userId, authorityName, id,
-                                false);
-                } else {
-                    authority = getOrCreateAuthorityLocked(
-                            new ComponentName(packageName, className), userId, id, false);
-                }
-                // If the version is 0 then we are upgrading from a file format that did not
-                // know about periodic syncs. In that case don't clear the list since we
-                // want the default, which is a daily periodic sync.
-                // Otherwise clear out this default list since we will populate it later with
-                // the periodic sync descriptions that are read from the configuration file.
-                if (version > 0) {
-                    authority.periodicSyncs.clear();
-                }
-            }
-            if (authority != null) {
-                authority.enabled = enabled == null || Boolean.parseBoolean(enabled);
-                if ("unknown".equals(syncable)) {
-                    authority.syncable = -1;
-                } else {
-                    authority.syncable =
-                            (syncable == null || Boolean.parseBoolean(syncable)) ? 1 : 0;
-                }
-            } else {
-                Log.w(TAG, "Failure adding authority: account="
-                        + accountName + " auth=" + authorityName
-                        + " enabled=" + enabled
-                        + " syncable=" + syncable);
-            }
-        }
-        return authority;
-    }
-
-    /**
-     * Parse a periodic sync from accounts.xml. Sets the bundle to be empty.
-     */
-    private PeriodicSync parsePeriodicSync(XmlPullParser parser, AuthorityInfo authority) {
-        Bundle extras = new Bundle(); // Gets filled in later.
-        String periodValue = parser.getAttributeValue(null, "period");
-        String flexValue = parser.getAttributeValue(null, "flex");
-        final long period;
-        long flextime;
-        try {
-            period = Long.parseLong(periodValue);
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "error parsing the period of a periodic sync", e);
-            return null;
-        } catch (NullPointerException e) {
-            Log.e(TAG, "the period of a periodic sync is null", e);
-            return null;
-        }
-        try {
-            flextime = Long.parseLong(flexValue);
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "Error formatting value parsed for periodic sync flex: " + flexValue);
-            flextime = calculateDefaultFlexTime(period);
-        } catch (NullPointerException expected) {
-            flextime = calculateDefaultFlexTime(period);
-            Log.d(TAG, "No flex time specified for this sync, using a default. period: "
-            + period + " flex: " + flextime);
-        }
-        final PeriodicSync periodicSync =
-                new PeriodicSync(authority.account, authority.authority, extras,
-                        period, flextime);
-        authority.periodicSyncs.add(periodicSync);
-        return periodicSync;
-    }
-
-    private void parseExtra(XmlPullParser parser, Bundle extras) {
-        String name = parser.getAttributeValue(null, "name");
-        String type = parser.getAttributeValue(null, "type");
-        String value1 = parser.getAttributeValue(null, "value1");
-        String value2 = parser.getAttributeValue(null, "value2");
-
-        try {
-            if ("long".equals(type)) {
-                extras.putLong(name, Long.parseLong(value1));
-            } else if ("integer".equals(type)) {
-                extras.putInt(name, Integer.parseInt(value1));
-            } else if ("double".equals(type)) {
-                extras.putDouble(name, Double.parseDouble(value1));
-            } else if ("float".equals(type)) {
-                extras.putFloat(name, Float.parseFloat(value1));
-            } else if ("boolean".equals(type)) {
-                extras.putBoolean(name, Boolean.parseBoolean(value1));
-            } else if ("string".equals(type)) {
-                extras.putString(name, value1);
-            } else if ("account".equals(type)) {
-                extras.putParcelable(name, new Account(value1, value2));
-            }
-        } catch (NumberFormatException e) {
-            Log.e(TAG, "error parsing bundle value", e);
-        } catch (NullPointerException e) {
-            Log.e(TAG, "error parsing bundle value", e);
-        }
-    }
-
-    /**
-     * Write all account information to the account file.
-     */
-    private void writeAccountInfoLocked() {
-        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-            Log.v(TAG, "Writing new " + mAccountInfoFile.getBaseFile());
-        }
-        FileOutputStream fos = null;
-
-        try {
-            fos = mAccountInfoFile.startWrite();
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-            out.startDocument(null, true);
-            out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-
-            out.startTag(null, "accounts");
-            out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
-            out.attribute(null, XML_ATTR_NEXT_AUTHORITY_ID, Integer.toString(mNextAuthorityId));
-            out.attribute(null, XML_ATTR_SYNC_RANDOM_OFFSET, Integer.toString(mSyncRandomOffset));
-
-            // Write the Sync Automatically flags for each user
-            final int M = mMasterSyncAutomatically.size();
-            for (int m = 0; m < M; m++) {
-                int userId = mMasterSyncAutomatically.keyAt(m);
-                Boolean listen = mMasterSyncAutomatically.valueAt(m);
-                out.startTag(null, XML_TAG_LISTEN_FOR_TICKLES);
-                out.attribute(null, XML_ATTR_USER, Integer.toString(userId));
-                out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(listen));
-                out.endTag(null, XML_TAG_LISTEN_FOR_TICKLES);
-            }
-
-            final int N = mAuthorities.size();
-            for (int i = 0; i < N; i++) {
-                AuthorityInfo authority = mAuthorities.valueAt(i);
-                out.startTag(null, "authority");
-                out.attribute(null, "id", Integer.toString(authority.ident));
-                out.attribute(null, XML_ATTR_USER, Integer.toString(authority.userId));
-                out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(authority.enabled));
-                if (authority.service == null) {
-                    out.attribute(null, "account", authority.account.name);
-                    out.attribute(null, "type", authority.account.type);
-                    out.attribute(null, "authority", authority.authority);
-                } else {
-                    out.attribute(null, "package", authority.service.getPackageName());
-                    out.attribute(null, "class", authority.service.getClassName());
-                }
-                if (authority.syncable < 0) {
-                    out.attribute(null, "syncable", "unknown");
-                } else {
-                    out.attribute(null, "syncable", Boolean.toString(authority.syncable != 0));
-                }
-                for (PeriodicSync periodicSync : authority.periodicSyncs) {
-                    out.startTag(null, "periodicSync");
-                    out.attribute(null, "period", Long.toString(periodicSync.period));
-                    out.attribute(null, "flex", Long.toString(periodicSync.flexTime));
-                    final Bundle extras = periodicSync.extras;
-                    extrasToXml(out, extras);
-                    out.endTag(null, "periodicSync");
-                }
-                out.endTag(null, "authority");
-            }
-            out.endTag(null, "accounts");
-            out.endDocument();
-            mAccountInfoFile.finishWrite(fos);
-        } catch (java.io.IOException e1) {
-            Log.w(TAG, "Error writing accounts", e1);
-            if (fos != null) {
-                mAccountInfoFile.failWrite(fos);
-            }
-        }
-    }
-
-    static int getIntColumn(Cursor c, String name) {
-        return c.getInt(c.getColumnIndex(name));
-    }
-
-    static long getLongColumn(Cursor c, String name) {
-        return c.getLong(c.getColumnIndex(name));
-    }
-
-    /**
-     * Load sync engine state from the old syncmanager database, and then
-     * erase it.  Note that we don't deal with pending operations, active
-     * sync, or history.
-     */
-    private void readAndDeleteLegacyAccountInfoLocked() {
-        // Look for old database to initialize from.
-        File file = mContext.getDatabasePath("syncmanager.db");
-        if (!file.exists()) {
-            return;
-        }
-        String path = file.getPath();
-        SQLiteDatabase db = null;
-        try {
-            db = SQLiteDatabase.openDatabase(path, null,
-                    SQLiteDatabase.OPEN_READONLY);
-        } catch (SQLiteException e) {
-        }
-
-        if (db != null) {
-            final boolean hasType = db.getVersion() >= 11;
-
-            // Copy in all of the status information, as well as accounts.
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.v(TAG, "Reading legacy sync accounts db");
-            }
-            SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
-            qb.setTables("stats, status");
-            HashMap<String,String> map = new HashMap<String,String>();
-            map.put("_id", "status._id as _id");
-            map.put("account", "stats.account as account");
-            if (hasType) {
-                map.put("account_type", "stats.account_type as account_type");
-            }
-            map.put("authority", "stats.authority as authority");
-            map.put("totalElapsedTime", "totalElapsedTime");
-            map.put("numSyncs", "numSyncs");
-            map.put("numSourceLocal", "numSourceLocal");
-            map.put("numSourcePoll", "numSourcePoll");
-            map.put("numSourceServer", "numSourceServer");
-            map.put("numSourceUser", "numSourceUser");
-            map.put("lastSuccessSource", "lastSuccessSource");
-            map.put("lastSuccessTime", "lastSuccessTime");
-            map.put("lastFailureSource", "lastFailureSource");
-            map.put("lastFailureTime", "lastFailureTime");
-            map.put("lastFailureMesg", "lastFailureMesg");
-            map.put("pending", "pending");
-            qb.setProjectionMap(map);
-            qb.appendWhere("stats._id = status.stats_id");
-            Cursor c = qb.query(db, null, null, null, null, null, null);
-            while (c.moveToNext()) {
-                String accountName = c.getString(c.getColumnIndex("account"));
-                String accountType = hasType
-                        ? c.getString(c.getColumnIndex("account_type")) : null;
-                if (accountType == null) {
-                    accountType = "com.google";
-                }
-                String authorityName = c.getString(c.getColumnIndex("authority"));
-                AuthorityInfo authority = this.getOrCreateAuthorityLocked(
-                        new Account(accountName, accountType), 0 /* legacy is single-user */,
-                        authorityName, -1, false);
-                if (authority != null) {
-                    int i = mSyncStatus.size();
-                    boolean found = false;
-                    SyncStatusInfo st = null;
-                    while (i > 0) {
-                        i--;
-                        st = mSyncStatus.valueAt(i);
-                        if (st.authorityId == authority.ident) {
-                            found = true;
-                            break;
-                        }
-                    }
-                    if (!found) {
-                        st = new SyncStatusInfo(authority.ident);
-                        mSyncStatus.put(authority.ident, st);
-                    }
-                    st.totalElapsedTime = getLongColumn(c, "totalElapsedTime");
-                    st.numSyncs = getIntColumn(c, "numSyncs");
-                    st.numSourceLocal = getIntColumn(c, "numSourceLocal");
-                    st.numSourcePoll = getIntColumn(c, "numSourcePoll");
-                    st.numSourceServer = getIntColumn(c, "numSourceServer");
-                    st.numSourceUser = getIntColumn(c, "numSourceUser");
-                    st.numSourcePeriodic = 0;
-                    st.lastSuccessSource = getIntColumn(c, "lastSuccessSource");
-                    st.lastSuccessTime = getLongColumn(c, "lastSuccessTime");
-                    st.lastFailureSource = getIntColumn(c, "lastFailureSource");
-                    st.lastFailureTime = getLongColumn(c, "lastFailureTime");
-                    st.lastFailureMesg = c.getString(c.getColumnIndex("lastFailureMesg"));
-                    st.pending = getIntColumn(c, "pending") != 0;
-                }
-            }
-
-            c.close();
-
-            // Retrieve the settings.
-            qb = new SQLiteQueryBuilder();
-            qb.setTables("settings");
-            c = qb.query(db, null, null, null, null, null, null);
-            while (c.moveToNext()) {
-                String name = c.getString(c.getColumnIndex("name"));
-                String value = c.getString(c.getColumnIndex("value"));
-                if (name == null) continue;
-                if (name.equals("listen_for_tickles")) {
-                    setMasterSyncAutomatically(value == null || Boolean.parseBoolean(value), 0);
-                } else if (name.startsWith("sync_provider_")) {
-                    String provider = name.substring("sync_provider_".length(),
-                            name.length());
-                    int i = mAuthorities.size();
-                    while (i > 0) {
-                        i--;
-                        AuthorityInfo authority = mAuthorities.valueAt(i);
-                        if (authority.authority.equals(provider)) {
-                            authority.enabled = value == null || Boolean.parseBoolean(value);
-                            authority.syncable = 1;
-                        }
-                    }
-                }
-            }
-
-            c.close();
-
-            db.close();
-
-            (new File(path)).delete();
-        }
-    }
-
-    public static final int STATUS_FILE_END = 0;
-    public static final int STATUS_FILE_ITEM = 100;
-
-    /**
-     * Read all sync status back in to the initial engine state.
-     */
-    private void readStatusLocked() {
-        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-            Log.v(TAG, "Reading " + mStatusFile.getBaseFile());
-        }
-        try {
-            byte[] data = mStatusFile.readFully();
-            Parcel in = Parcel.obtain();
-            in.unmarshall(data, 0, data.length);
-            in.setDataPosition(0);
-            int token;
-            while ((token=in.readInt()) != STATUS_FILE_END) {
-                if (token == STATUS_FILE_ITEM) {
-                    SyncStatusInfo status = new SyncStatusInfo(in);
-                    if (mAuthorities.indexOfKey(status.authorityId) >= 0) {
-                        status.pending = false;
-                        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                            Log.v(TAG, "Adding status for id "
-                                    + status.authorityId);
-                        }
-                        mSyncStatus.put(status.authorityId, status);
-                    }
-                } else {
-                    // Ooops.
-                    Log.w(TAG, "Unknown status token: " + token);
-                    break;
-                }
-            }
-        } catch (java.io.IOException e) {
-            Log.i(TAG, "No initial status");
-        }
-    }
-
-    /**
-     * Write all sync status to the sync status file.
-     */
-    private void writeStatusLocked() {
-        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-            Log.v(TAG, "Writing new " + mStatusFile.getBaseFile());
-        }
-
-        // The file is being written, so we don't need to have a scheduled
-        // write until the next change.
-        removeMessages(MSG_WRITE_STATUS);
-
-        FileOutputStream fos = null;
-        try {
-            fos = mStatusFile.startWrite();
-            Parcel out = Parcel.obtain();
-            final int N = mSyncStatus.size();
-            for (int i=0; i<N; i++) {
-                SyncStatusInfo status = mSyncStatus.valueAt(i);
-                out.writeInt(STATUS_FILE_ITEM);
-                status.writeToParcel(out, 0);
-            }
-            out.writeInt(STATUS_FILE_END);
-            fos.write(out.marshall());
-            out.recycle();
-
-            mStatusFile.finishWrite(fos);
-        } catch (java.io.IOException e1) {
-            Log.w(TAG, "Error writing status", e1);
-            if (fos != null) {
-                mStatusFile.failWrite(fos);
-            }
-        }
-    }
-
-    public static final int PENDING_OPERATION_VERSION = 3;
-
-    /** Read all pending operations back in to the initial engine state. */
-    private void readPendingOperationsLocked() {
-        FileInputStream fis = null;
-        if (!mPendingFile.getBaseFile().exists()) {
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.v(TAG_FILE, "No pending operation file.");
-                return;
-            }
-        }
-        try {
-            fis = mPendingFile.openRead();
-            XmlPullParser parser;
-            parser = Xml.newPullParser();
-            parser.setInput(fis, null);
-
-            int eventType = parser.getEventType();
-            while (eventType != XmlPullParser.START_TAG &&
-                    eventType != XmlPullParser.END_DOCUMENT) {
-                eventType = parser.next();
-            }
-            if (eventType == XmlPullParser.END_DOCUMENT) return; // Nothing to read.
-
-            String tagName = parser.getName();
-            do {
-                PendingOperation pop = null;
-                if (eventType == XmlPullParser.START_TAG) {
-                    try {
-                        tagName = parser.getName();
-                        if (parser.getDepth() == 1 && "op".equals(tagName)) {
-                            // Verify version.
-                            String versionString =
-                                    parser.getAttributeValue(null, XML_ATTR_VERSION);
-                            if (versionString == null ||
-                                    Integer.parseInt(versionString) != PENDING_OPERATION_VERSION) {
-                                Log.w(TAG, "Unknown pending operation version " + versionString);
-                                throw new java.io.IOException("Unknown version.");
-                            }
-                            int authorityId = Integer.valueOf(parser.getAttributeValue(
-                                    null, XML_ATTR_AUTHORITYID));
-                            boolean expedited = Boolean.valueOf(parser.getAttributeValue(
-                                    null, XML_ATTR_EXPEDITED));
-                            int syncSource = Integer.valueOf(parser.getAttributeValue(
-                                    null, XML_ATTR_SOURCE));
-                            int reason = Integer.valueOf(parser.getAttributeValue(
-                                    null, XML_ATTR_REASON));
-                            AuthorityInfo authority = mAuthorities.get(authorityId);
-                            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                                Log.v(TAG_FILE, authorityId + " " + expedited + " " + syncSource + " "
-                                        + reason);
-                            }
-                            if (authority != null) {
-                                pop = new PendingOperation(
-                                        authority.account, authority.userId, reason,
-                                        syncSource, authority.authority, new Bundle(),
-                                        expedited);
-                                pop.flatExtras = null; // No longer used.
-                                mPendingOperations.add(pop);
-                                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                                    Log.v(TAG_FILE, "Adding pending op: "
-                                            + pop.authority
-                                            + " src=" + pop.syncSource
-                                            + " reason=" + pop.reason
-                                            + " expedited=" + pop.expedited);
-                                }
-                            } else {
-                                // Skip non-existent authority.
-                                pop = null;
-                                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                                    Log.v(TAG_FILE, "No authority found for " + authorityId
-                                            + ", skipping");
-                                }
-                            }
-                        } else if (parser.getDepth() == 2 &&
-                                pop != null &&
-                                "extra".equals(tagName)) {
-                            parseExtra(parser, pop.extras);
-                        }
-                    } catch (NumberFormatException e) {
-                        Log.d(TAG, "Invalid data in xml file.", e);
-                    }
-                }
-                eventType = parser.next();
-            } while(eventType != XmlPullParser.END_DOCUMENT);
-        } catch (java.io.IOException e) {
-            Log.w(TAG_FILE, "Error reading pending data.", e);
-        } catch (XmlPullParserException e) {
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.w(TAG_FILE, "Error parsing pending ops xml.", e);
-            }
-        } finally {
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch (java.io.IOException e1) {}
-            }
-        }
-    }
-
-    private static final String XML_ATTR_AUTHORITYID = "authority_id";
-    private static final String XML_ATTR_SOURCE = "source";
-    private static final String XML_ATTR_EXPEDITED = "expedited";
-    private static final String XML_ATTR_REASON = "reason";
-    private static final String XML_ATTR_VERSION = "version";
-
-    /**
-     * Write all currently pending ops to the pending ops file.
-     */
-    private void writePendingOperationsLocked() {
-        final int N = mPendingOperations.size();
-        FileOutputStream fos = null;
-        try {
-            if (N == 0) {
-                if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                    Log.v(TAG_FILE, "Truncating " + mPendingFile.getBaseFile());
-                }
-                mPendingFile.truncate();
-                return;
-            }
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.v(TAG_FILE, "Writing new " + mPendingFile.getBaseFile());
-            }
-            fos = mPendingFile.startWrite();
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-
-            for (int i = 0; i < N; i++) {
-                PendingOperation pop = mPendingOperations.get(i);
-                writePendingOperationLocked(pop, out);
-            }
-            out.endDocument();
-            mPendingFile.finishWrite(fos);
-        } catch (java.io.IOException e1) {
-            Log.w(TAG, "Error writing pending operations", e1);
-            if (fos != null) {
-                mPendingFile.failWrite(fos);
-            }
-        }
-    }
-
-    /** Write all currently pending ops to the pending ops file. */
-     private void writePendingOperationLocked(PendingOperation pop, XmlSerializer out)
-             throws IOException {
-         // Pending operation.
-         out.startTag(null, "op");
-
-         out.attribute(null, XML_ATTR_VERSION, Integer.toString(PENDING_OPERATION_VERSION));
-         out.attribute(null, XML_ATTR_AUTHORITYID, Integer.toString(pop.authorityId));
-         out.attribute(null, XML_ATTR_SOURCE, Integer.toString(pop.syncSource));
-         out.attribute(null, XML_ATTR_EXPEDITED, Boolean.toString(pop.expedited));
-         out.attribute(null, XML_ATTR_REASON, Integer.toString(pop.reason));
-         extrasToXml(out, pop.extras);
-
-         out.endTag(null, "op");
-     }
-
-    /**
-     * Append the given operation to the pending ops file; if unable to,
-     * write all pending ops.
-     */
-    private void appendPendingOperationLocked(PendingOperation op) {
-        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-            Log.v(TAG, "Appending to " + mPendingFile.getBaseFile());
-        }
-        FileOutputStream fos = null;
-        try {
-            fos = mPendingFile.openAppend();
-        } catch (java.io.IOException e) {
-            if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-                Log.v(TAG, "Failed append; writing full file");
-            }
-            writePendingOperationsLocked();
-            return;
-        }
-
-        try {
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-            writePendingOperationLocked(op, out);
-            out.endDocument();
-            mPendingFile.finishWrite(fos);
-        } catch (java.io.IOException e1) {
-            Log.w(TAG, "Error writing appending operation", e1);
-            mPendingFile.failWrite(fos);
-        } finally {
-            try {
-                fos.close();
-            } catch (IOException e) {}
-        }
-    }
-
-    static private byte[] flattenBundle(Bundle bundle) {
-        byte[] flatData = null;
-        Parcel parcel = Parcel.obtain();
-        try {
-            bundle.writeToParcel(parcel, 0);
-            flatData = parcel.marshall();
-        } finally {
-            parcel.recycle();
-        }
-        return flatData;
-    }
-
-    static private Bundle unflattenBundle(byte[] flatData) {
-        Bundle bundle;
-        Parcel parcel = Parcel.obtain();
-        try {
-            parcel.unmarshall(flatData, 0, flatData.length);
-            parcel.setDataPosition(0);
-            bundle = parcel.readBundle();
-        } catch (RuntimeException e) {
-            // A RuntimeException is thrown if we were unable to parse the parcel.
-            // Create an empty parcel in this case.
-            bundle = new Bundle();
-        } finally {
-            parcel.recycle();
-        }
-        return bundle;
-    }
-
-    private void extrasToXml(XmlSerializer out, Bundle extras) throws java.io.IOException {
-        for (String key : extras.keySet()) {
-            out.startTag(null, "extra");
-            out.attribute(null, "name", key);
-            final Object value = extras.get(key);
-            if (value instanceof Long) {
-                out.attribute(null, "type", "long");
-                out.attribute(null, "value1", value.toString());
-            } else if (value instanceof Integer) {
-                out.attribute(null, "type", "integer");
-                out.attribute(null, "value1", value.toString());
-            } else if (value instanceof Boolean) {
-                out.attribute(null, "type", "boolean");
-                out.attribute(null, "value1", value.toString());
-            } else if (value instanceof Float) {
-                out.attribute(null, "type", "float");
-                out.attribute(null, "value1", value.toString());
-            } else if (value instanceof Double) {
-                out.attribute(null, "type", "double");
-                out.attribute(null, "value1", value.toString());
-            } else if (value instanceof String) {
-                out.attribute(null, "type", "string");
-                out.attribute(null, "value1", value.toString());
-            } else if (value instanceof Account) {
-                out.attribute(null, "type", "account");
-                out.attribute(null, "value1", ((Account)value).name);
-                out.attribute(null, "value2", ((Account)value).type);
-            }
-            out.endTag(null, "extra");
-        }
-    }
-
-    private void requestSync(Account account, int userId, int reason, String authority,
-            Bundle extras) {
-        // If this is happening in the system process, then call the syncrequest listener
-        // to make a request back to the SyncManager directly.
-        // If this is probably a test instance, then call back through the ContentResolver
-        // which will know which userId to apply based on the Binder id.
-        if (android.os.Process.myUid() == android.os.Process.SYSTEM_UID
-                && mSyncRequestListener != null) {
-            mSyncRequestListener.onSyncRequest(account, userId, reason, authority, extras);
-        } else {
-            ContentResolver.requestSync(account, authority, extras);
-        }
-    }
-
-    public static final int STATISTICS_FILE_END = 0;
-    public static final int STATISTICS_FILE_ITEM_OLD = 100;
-    public static final int STATISTICS_FILE_ITEM = 101;
-
-    /**
-     * Read all sync statistics back in to the initial engine state.
-     */
-    private void readStatisticsLocked() {
-        try {
-            byte[] data = mStatisticsFile.readFully();
-            Parcel in = Parcel.obtain();
-            in.unmarshall(data, 0, data.length);
-            in.setDataPosition(0);
-            int token;
-            int index = 0;
-            while ((token=in.readInt()) != STATISTICS_FILE_END) {
-                if (token == STATISTICS_FILE_ITEM
-                        || token == STATISTICS_FILE_ITEM_OLD) {
-                    int day = in.readInt();
-                    if (token == STATISTICS_FILE_ITEM_OLD) {
-                        day = day - 2009 + 14245;  // Magic!
-                    }
-                    DayStats ds = new DayStats(day);
-                    ds.successCount = in.readInt();
-                    ds.successTime = in.readLong();
-                    ds.failureCount = in.readInt();
-                    ds.failureTime = in.readLong();
-                    if (index < mDayStats.length) {
-                        mDayStats[index] = ds;
-                        index++;
-                    }
-                } else {
-                    // Ooops.
-                    Log.w(TAG, "Unknown stats token: " + token);
-                    break;
-                }
-            }
-        } catch (java.io.IOException e) {
-            Log.i(TAG, "No initial statistics");
-        }
-    }
-
-    /**
-     * Write all sync statistics to the sync status file.
-     */
-    private void writeStatisticsLocked() {
-        if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
-            Log.v(TAG, "Writing new " + mStatisticsFile.getBaseFile());
-        }
-
-        // The file is being written, so we don't need to have a scheduled
-        // write until the next change.
-        removeMessages(MSG_WRITE_STATISTICS);
-
-        FileOutputStream fos = null;
-        try {
-            fos = mStatisticsFile.startWrite();
-            Parcel out = Parcel.obtain();
-            final int N = mDayStats.length;
-            for (int i=0; i<N; i++) {
-                DayStats ds = mDayStats[i];
-                if (ds == null) {
-                    break;
-                }
-                out.writeInt(STATISTICS_FILE_ITEM);
-                out.writeInt(ds.day);
-                out.writeInt(ds.successCount);
-                out.writeLong(ds.successTime);
-                out.writeInt(ds.failureCount);
-                out.writeLong(ds.failureTime);
-            }
-            out.writeInt(STATISTICS_FILE_END);
-            fos.write(out.marshall());
-            out.recycle();
-
-            mStatisticsFile.finishWrite(fos);
-        } catch (java.io.IOException e1) {
-            Log.w(TAG, "Error writing stats", e1);
-            if (fos != null) {
-                mStatisticsFile.failWrite(fos);
-            }
-        }
-    }
-
-    /**
-     * Dump state of PendingOperations.
-     */
-    public void dumpPendingOperations(StringBuilder sb) {
-        sb.append("Pending Ops: ").append(mPendingOperations.size()).append(" operation(s)\n");
-        for (PendingOperation pop : mPendingOperations) {
-            sb.append("(" + pop.account)
-                .append(", u" + pop.userId)
-                .append(", " + pop.authority)
-                .append(", " + pop.extras)
-                .append(")\n");
-        }
-    }
-}
diff --git a/services/java/com/android/server/display/DisplayDevice.java b/services/java/com/android/server/display/DisplayDevice.java
deleted file mode 100644
index 4161147..0000000
--- a/services/java/com/android/server/display/DisplayDevice.java
+++ /dev/null
@@ -1,213 +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.server.display;
-
-import android.graphics.Rect;
-import android.os.IBinder;
-import android.view.Surface;
-import android.view.SurfaceControl;
-
-import java.io.PrintWriter;
-
-/**
- * Represents a physical display device such as the built-in display
- * an external monitor, or a WiFi display.
- * <p>
- * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock.
- * </p>
- */
-abstract class DisplayDevice {
-    private final DisplayAdapter mDisplayAdapter;
-    private final IBinder mDisplayToken;
-
-    // The display device does not manage these properties itself, they are set by
-    // the display manager service.  The display device shouldn't really be looking at these.
-    private int mCurrentLayerStack = -1;
-    private int mCurrentOrientation = -1;
-    private Rect mCurrentLayerStackRect;
-    private Rect mCurrentDisplayRect;
-
-    // The display device owns its surface, but it should only set it
-    // within a transaction from performTraversalInTransactionLocked.
-    private Surface mCurrentSurface;
-
-    public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken) {
-        mDisplayAdapter = displayAdapter;
-        mDisplayToken = displayToken;
-    }
-
-    /**
-     * Gets the display adapter that owns the display device.
-     *
-     * @return The display adapter.
-     */
-    public final DisplayAdapter getAdapterLocked() {
-        return mDisplayAdapter;
-    }
-
-    /**
-     * Gets the Surface Flinger display token for this display.
-     *
-     * @return The display token, or null if the display is not being managed
-     * by Surface Flinger.
-     */
-    public final IBinder getDisplayTokenLocked() {
-        return mDisplayToken;
-    }
-
-    /**
-     * Gets the name of the display device.
-     *
-     * @return The display device name.
-     */
-    public final String getNameLocked() {
-        return getDisplayDeviceInfoLocked().name;
-    }
-
-    /**
-     * Gets information about the display device.
-     *
-     * The information returned should not change between calls unless the display
-     * adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event and
-     * {@link #applyPendingDisplayDeviceInfoChangesLocked()} has been called to apply
-     * the pending changes.
-     *
-     * @return The display device info, which should be treated as immutable by the caller.
-     * The display device should allocate a new display device info object whenever
-     * the data changes.
-     */
-    public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked();
-
-    /**
-     * Applies any pending changes to the observable state of the display device
-     * if the display adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event.
-     */
-    public void applyPendingDisplayDeviceInfoChangesLocked() {
-    }
-
-    /**
-     * Gives the display device a chance to update its properties while in a transaction.
-     */
-    public void performTraversalInTransactionLocked() {
-    }
-
-    /**
-     * Blanks the display, if supported.
-     */
-    public void blankLocked() {
-    }
-
-    /**
-     * Unblanks the display, if supported.
-     */
-    public void unblankLocked() {
-    }
-
-    /**
-     * Sets the display layer stack while in a transaction.
-     */
-    public final void setLayerStackInTransactionLocked(int layerStack) {
-        if (mCurrentLayerStack != layerStack) {
-            mCurrentLayerStack = layerStack;
-            SurfaceControl.setDisplayLayerStack(mDisplayToken, layerStack);
-        }
-    }
-
-    /**
-     * Sets the display projection while in a transaction.
-     *
-     * @param orientation defines the display's orientation
-     * @param layerStackRect defines which area of the window manager coordinate
-     *            space will be used
-     * @param displayRect defines where on the display will layerStackRect be
-     *            mapped to. displayRect is specified post-orientation, that is
-     *            it uses the orientation seen by the end-user
-     */
-    public final void setProjectionInTransactionLocked(int orientation,
-            Rect layerStackRect, Rect displayRect) {
-        if (mCurrentOrientation != orientation
-                || mCurrentLayerStackRect == null
-                || !mCurrentLayerStackRect.equals(layerStackRect)
-                || mCurrentDisplayRect == null
-                || !mCurrentDisplayRect.equals(displayRect)) {
-            mCurrentOrientation = orientation;
-
-            if (mCurrentLayerStackRect == null) {
-                mCurrentLayerStackRect = new Rect();
-            }
-            mCurrentLayerStackRect.set(layerStackRect);
-
-            if (mCurrentDisplayRect == null) {
-                mCurrentDisplayRect = new Rect();
-            }
-            mCurrentDisplayRect.set(displayRect);
-
-            SurfaceControl.setDisplayProjection(mDisplayToken,
-                    orientation, layerStackRect, displayRect);
-        }
-    }
-
-    /**
-     * Sets the display surface while in a transaction.
-     */
-    public final void setSurfaceInTransactionLocked(Surface surface) {
-        if (mCurrentSurface != surface) {
-            mCurrentSurface = surface;
-            SurfaceControl.setDisplaySurface(mDisplayToken, surface);
-        }
-    }
-
-    /**
-     * Populates the specified viewport object with orientation,
-     * physical and logical rects based on the display's current projection.
-     */
-    public final void populateViewportLocked(DisplayViewport viewport) {
-        viewport.orientation = mCurrentOrientation;
-
-        if (mCurrentLayerStackRect != null) {
-            viewport.logicalFrame.set(mCurrentLayerStackRect);
-        } else {
-            viewport.logicalFrame.setEmpty();
-        }
-
-        if (mCurrentDisplayRect != null) {
-            viewport.physicalFrame.set(mCurrentDisplayRect);
-        } else {
-            viewport.physicalFrame.setEmpty();
-        }
-
-        boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90
-                || mCurrentOrientation == Surface.ROTATION_270);
-        DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
-        viewport.deviceWidth = isRotated ? info.height : info.width;
-        viewport.deviceHeight = isRotated ? info.width : info.height;
-    }
-
-    /**
-     * Dumps the local state of the display device.
-     * Does not need to dump the display device info because that is already dumped elsewhere.
-     */
-    public void dumpLocked(PrintWriter pw) {
-        pw.println("mAdapter=" + mDisplayAdapter.getName());
-        pw.println("mDisplayToken=" + mDisplayToken);
-        pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
-        pw.println("mCurrentOrientation=" + mCurrentOrientation);
-        pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect);
-        pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect);
-        pw.println("mCurrentSurface=" + mCurrentSurface);
-    }
-}
diff --git a/services/java/com/android/server/display/DisplayDeviceInfo.java b/services/java/com/android/server/display/DisplayDeviceInfo.java
deleted file mode 100644
index 11c5d87..0000000
--- a/services/java/com/android/server/display/DisplayDeviceInfo.java
+++ /dev/null
@@ -1,302 +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.server.display;
-
-import android.util.DisplayMetrics;
-import android.view.Display;
-import android.view.Surface;
-
-import libcore.util.Objects;
-
-/**
- * Describes the characteristics of a physical display device.
- */
-final class DisplayDeviceInfo {
-    /**
-     * Flag: Indicates that this display device should be considered the default display
-     * device of the system.
-     */
-    public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
-
-    /**
-     * Flag: Indicates that the orientation of this display device is coupled to the
-     * rotation of its associated logical display.
-     * <p>
-     * This flag should be applied to the default display to indicate that the user
-     * physically rotates the display when content is presented in a different orientation.
-     * The display manager will apply a coordinate transformation assuming that the
-     * physical orientation of the display matches the logical orientation of its content.
-     * </p><p>
-     * The flag should not be set when the display device is mounted in a fixed orientation
-     * such as on a desk.  The display manager will apply a coordinate transformation
-     * such as a scale and translation to letterbox or pillarbox format under the
-     * assumption that the physical orientation of the display is invariant.
-     * </p>
-     */
-    public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1;
-
-    /**
-     * Flag: Indicates that this display device has secure video output, such as HDCP.
-     */
-    public static final int FLAG_SECURE = 1 << 2;
-
-    /**
-     * Flag: Indicates that this display device supports compositing
-     * from gralloc protected buffers.
-     */
-    public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 3;
-
-    /**
-     * Flag: Indicates that the display device is owned by a particular application
-     * and that no other application should be able to interact with it.
-     */
-    public static final int FLAG_PRIVATE = 1 << 4;
-
-    /**
-     * Flag: Indicates that the display device is not blanked automatically by
-     * the power manager.
-     */
-    public static final int FLAG_NEVER_BLANK = 1 << 5;
-
-    /**
-     * Flag: Indicates that the display is suitable for presentations.
-     */
-    public static final int FLAG_PRESENTATION = 1 << 6;
-
-    /**
-     * Touch attachment: Display does not receive touch.
-     */
-    public static final int TOUCH_NONE = 0;
-
-    /**
-     * Touch attachment: Touch input is via the internal interface.
-     */
-    public static final int TOUCH_INTERNAL = 1;
-
-    /**
-     * Touch attachment: Touch input is via an external interface, such as USB.
-     */
-    public static final int TOUCH_EXTERNAL = 2;
-
-    /**
-     * Gets the name of the display device, which may be derived from
-     * EDID or other sources.  The name may be displayed to the user.
-     */
-    public String name;
-
-    /**
-     * The width of the display in its natural orientation, in pixels.
-     * This value is not affected by display rotation.
-     */
-    public int width;
-
-    /**
-     * The height of the display in its natural orientation, in pixels.
-     * This value is not affected by display rotation.
-     */
-    public int height;
-
-    /**
-     * The refresh rate of the display.
-     */
-    public float refreshRate;
-
-    /**
-     * The nominal apparent density of the display in DPI used for layout calculations.
-     * This density is sensitive to the viewing distance.  A big TV and a tablet may have
-     * the same apparent density even though the pixels on the TV are much bigger than
-     * those on the tablet.
-     */
-    public int densityDpi;
-
-    /**
-     * The physical density of the display in DPI in the X direction.
-     * This density should specify the physical size of each pixel.
-     */
-    public float xDpi;
-
-    /**
-     * The physical density of the display in DPI in the X direction.
-     * This density should specify the physical size of each pixel.
-     */
-    public float yDpi;
-
-    /**
-     * Display flags.
-     */
-    public int flags;
-
-    /**
-     * The touch attachment, per {@link DisplayViewport#touch}.
-     */
-    public int touch;
-
-    /**
-     * The additional rotation to apply to all content presented on the display device
-     * relative to its physical coordinate system.  Default is {@link Surface#ROTATION_0}.
-     * <p>
-     * This field can be used to compensate for the fact that the display has been
-     * physically rotated relative to its natural orientation such as an HDMI monitor
-     * that has been mounted sideways to appear to be portrait rather than landscape.
-     * </p>
-     */
-    public int rotation = Surface.ROTATION_0;
-
-    /**
-     * Display type.
-     */
-    public int type;
-
-    /**
-     * Display address, or null if none.
-     * Interpretation varies by display type.
-     */
-    public String address;
-
-    /**
-     * The UID of the application that owns this display, or zero if it is owned by the system.
-     * <p>
-     * If the display is private, then only the owner can use it.
-     * </p>
-     */
-    public int ownerUid;
-
-    /**
-     * The package name of the application that owns this display, or null if it is
-     * owned by the system.
-     * <p>
-     * If the display is private, then only the owner can use it.
-     * </p>
-     */
-    public String ownerPackageName;
-
-    public void setAssumedDensityForExternalDisplay(int width, int height) {
-        densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
-        // Technically, these values should be smaller than the apparent density
-        // but we don't know the physical size of the display.
-        xDpi = densityDpi;
-        yDpi = densityDpi;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
-    }
-
-    public boolean equals(DisplayDeviceInfo other) {
-        return other != null
-                && Objects.equal(name, other.name)
-                && width == other.width
-                && height == other.height
-                && refreshRate == other.refreshRate
-                && densityDpi == other.densityDpi
-                && xDpi == other.xDpi
-                && yDpi == other.yDpi
-                && flags == other.flags
-                && touch == other.touch
-                && rotation == other.rotation
-                && type == other.type
-                && Objects.equal(address, other.address)
-                && ownerUid == other.ownerUid
-                && Objects.equal(ownerPackageName, other.ownerPackageName);
-    }
-
-    @Override
-    public int hashCode() {
-        return 0; // don't care
-    }
-
-    public void copyFrom(DisplayDeviceInfo other) {
-        name = other.name;
-        width = other.width;
-        height = other.height;
-        refreshRate = other.refreshRate;
-        densityDpi = other.densityDpi;
-        xDpi = other.xDpi;
-        yDpi = other.yDpi;
-        flags = other.flags;
-        touch = other.touch;
-        rotation = other.rotation;
-        type = other.type;
-        address = other.address;
-        ownerUid = other.ownerUid;
-        ownerPackageName = other.ownerPackageName;
-    }
-
-    // For debugging purposes
-    @Override
-    public String toString() {
-        StringBuilder sb = new StringBuilder();
-        sb.append("DisplayDeviceInfo{\"");
-        sb.append(name).append("\": ").append(width).append(" x ").append(height);
-        sb.append(", ").append(refreshRate).append(" fps, ");
-        sb.append("density ").append(densityDpi);
-        sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
-        sb.append(", touch ").append(touchToString(touch));
-        sb.append(", rotation ").append(rotation);
-        sb.append(", type ").append(Display.typeToString(type));
-        if (address != null) {
-            sb.append(", address ").append(address);
-        }
-        if (ownerUid != 0 || ownerPackageName != null) {
-            sb.append(", owner ").append(ownerPackageName);
-            sb.append(" (uid ").append(ownerUid).append(")");
-        }
-        sb.append(flagsToString(flags));
-        sb.append("}");
-        return sb.toString();
-    }
-
-    private static String touchToString(int touch) {
-        switch (touch) {
-            case TOUCH_NONE:
-                return "NONE";
-            case TOUCH_INTERNAL:
-                return "INTERNAL";
-            case TOUCH_EXTERNAL:
-                return "EXTERNAL";
-            default:
-                return Integer.toString(touch);
-        }
-    }
-
-    private static String flagsToString(int flags) {
-        StringBuilder msg = new StringBuilder();
-        if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
-            msg.append(", FLAG_DEFAULT_DISPLAY");
-        }
-        if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
-            msg.append(", FLAG_ROTATES_WITH_CONTENT");
-        }
-        if ((flags & FLAG_SECURE) != 0) {
-            msg.append(", FLAG_SECURE");
-        }
-        if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
-            msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
-        }
-        if ((flags & FLAG_PRIVATE) != 0) {
-            msg.append(", FLAG_PRIVATE");
-        }
-        if ((flags & FLAG_NEVER_BLANK) != 0) {
-            msg.append(", FLAG_NEVER_BLANK");
-        }
-        if ((flags & FLAG_PRESENTATION) != 0) {
-            msg.append(", FLAG_PRESENTATION");
-        }
-        return msg.toString();
-    }
-}
diff --git a/services/java/com/android/server/display/DisplayManagerService.java b/services/java/com/android/server/display/DisplayManagerService.java
deleted file mode 100644
index bcb677f..0000000
--- a/services/java/com/android/server/display/DisplayManagerService.java
+++ /dev/null
@@ -1,1331 +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.server.display;
-
-import com.android.internal.util.IndentingPrintWriter;
-
-import android.Manifest;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.hardware.display.DisplayManager;
-import android.hardware.display.DisplayManagerGlobal;
-import android.hardware.display.IDisplayManager;
-import android.hardware.display.IDisplayManagerCallback;
-import android.hardware.display.WifiDisplayStatus;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.text.TextUtils;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.view.Display;
-import android.view.DisplayInfo;
-import android.view.Surface;
-
-import com.android.server.UiThread;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-/**
- * Manages attached displays.
- * <p>
- * The {@link DisplayManagerService} manages the global lifecycle of displays,
- * decides how to configure logical displays based on the physical display devices currently
- * attached, sends notifications to the system and to applications when the state
- * changes, and so on.
- * </p><p>
- * The display manager service relies on a collection of {@link DisplayAdapter} components,
- * for discovering and configuring physical display devices attached to the system.
- * There are separate display adapters for each manner that devices are attached:
- * one display adapter for built-in local displays, one for simulated non-functional
- * displays when the system is headless, one for simulated overlay displays used for
- * development, one for wifi displays, etc.
- * </p><p>
- * Display adapters are only weakly coupled to the display manager service.
- * Display adapters communicate changes in display device state to the display manager
- * service asynchronously via a {@link DisplayAdapter.Listener} registered
- * by the display manager service.  This separation of concerns is important for
- * two main reasons.  First, it neatly encapsulates the responsibilities of these
- * two classes: display adapters handle individual display devices whereas
- * the display manager service handles the global state.  Second, it eliminates
- * the potential for deadlocks resulting from asynchronous display device discovery.
- * </p>
- *
- * <h3>Synchronization</h3>
- * <p>
- * Because the display manager may be accessed by multiple threads, the synchronization
- * story gets a little complicated.  In particular, the window manager may call into
- * the display manager while holding a surface transaction with the expectation that
- * it can apply changes immediately.  Unfortunately, that means we can't just do
- * everything asynchronously (*grump*).
- * </p><p>
- * To make this work, all of the objects that belong to the display manager must
- * use the same lock.  We call this lock the synchronization root and it has a unique
- * type {@link DisplayManagerService.SyncRoot}.  Methods that require this lock are
- * named with the "Locked" suffix.
- * </p><p>
- * Where things get tricky is that the display manager is not allowed to make
- * any potentially reentrant calls, especially into the window manager.  We generally
- * avoid this by making all potentially reentrant out-calls asynchronous.
- * </p>
- */
-public final class DisplayManagerService extends IDisplayManager.Stub {
-    private static final String TAG = "DisplayManagerService";
-    private static final boolean DEBUG = false;
-
-    // When this system property is set to 0, WFD is forcibly disabled on boot.
-    // When this system property is set to 1, WFD is forcibly enabled on boot.
-    // Otherwise WFD is enabled according to the value of config_enableWifiDisplay.
-    private static final String FORCE_WIFI_DISPLAY_ENABLE = "persist.debug.wfd.enable";
-
-    private static final String SYSTEM_HEADLESS = "ro.config.headless";
-    private static final long WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT = 10000;
-
-    private static final int MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER = 1;
-    private static final int MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS = 2;
-    private static final int MSG_DELIVER_DISPLAY_EVENT = 3;
-    private static final int MSG_REQUEST_TRAVERSAL = 4;
-    private static final int MSG_UPDATE_VIEWPORT = 5;
-
-    private static final int DISPLAY_BLANK_STATE_UNKNOWN = 0;
-    private static final int DISPLAY_BLANK_STATE_BLANKED = 1;
-    private static final int DISPLAY_BLANK_STATE_UNBLANKED = 2;
-
-    private final Context mContext;
-    private final boolean mHeadless;
-    private final DisplayManagerHandler mHandler;
-    private final Handler mUiHandler;
-    private final DisplayAdapterListener mDisplayAdapterListener;
-    private WindowManagerFuncs mWindowManagerFuncs;
-    private InputManagerFuncs mInputManagerFuncs;
-
-    // The synchronization root for the display manager.
-    // This lock guards most of the display manager's state.
-    // NOTE: This is synchronized on while holding WindowManagerService.mWindowMap so never call
-    // into WindowManagerService methods that require mWindowMap while holding this unless you are
-    // very very sure that no deadlock can occur.
-    private final SyncRoot mSyncRoot = new SyncRoot();
-
-    // True if in safe mode.
-    // This option may disable certain display adapters.
-    public boolean mSafeMode;
-
-    // True if we are in a special boot mode where only core applications and
-    // services should be started.  This option may disable certain display adapters.
-    public boolean mOnlyCore;
-
-    // True if the display manager service should pretend there is only one display
-    // and only tell applications about the existence of the default logical display.
-    // The display manager can still mirror content to secondary displays but applications
-    // cannot present unique content on those displays.
-    // Used for demonstration purposes only.
-    private final boolean mSingleDisplayDemoMode;
-
-    // All callback records indexed by calling process id.
-    public final SparseArray<CallbackRecord> mCallbacks =
-            new SparseArray<CallbackRecord>();
-
-    // List of all currently registered display adapters.
-    private final ArrayList<DisplayAdapter> mDisplayAdapters = new ArrayList<DisplayAdapter>();
-
-    // List of all currently connected display devices.
-    private final ArrayList<DisplayDevice> mDisplayDevices = new ArrayList<DisplayDevice>();
-
-    // List of all logical displays indexed by logical display id.
-    private final SparseArray<LogicalDisplay> mLogicalDisplays =
-            new SparseArray<LogicalDisplay>();
-    private int mNextNonDefaultDisplayId = Display.DEFAULT_DISPLAY + 1;
-
-    // List of all display transaction listeners.
-    private final CopyOnWriteArrayList<DisplayTransactionListener> mDisplayTransactionListeners =
-            new CopyOnWriteArrayList<DisplayTransactionListener>();
-
-    // Set to true if all displays have been blanked by the power manager.
-    private int mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNKNOWN;
-
-    // Set to true when there are pending display changes that have yet to be applied
-    // to the surface flinger state.
-    private boolean mPendingTraversal;
-
-    // The Wifi display adapter, or null if not registered.
-    private WifiDisplayAdapter mWifiDisplayAdapter;
-
-    // The number of active wifi display scan requests.
-    private int mWifiDisplayScanRequestCount;
-
-    // The virtual display adapter, or null if not registered.
-    private VirtualDisplayAdapter mVirtualDisplayAdapter;
-
-    // Viewports of the default display and the display that should receive touch
-    // input from an external source.  Used by the input system.
-    private final DisplayViewport mDefaultViewport = new DisplayViewport();
-    private final DisplayViewport mExternalTouchViewport = new DisplayViewport();
-
-    // Persistent data store for all internal settings maintained by the display manager service.
-    private final PersistentDataStore mPersistentDataStore = new PersistentDataStore();
-
-    // Temporary callback list, used when sending display events to applications.
-    // May be used outside of the lock but only on the handler thread.
-    private final ArrayList<CallbackRecord> mTempCallbacks = new ArrayList<CallbackRecord>();
-
-    // Temporary display info, used for comparing display configurations.
-    private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
-
-    // Temporary viewports, used when sending new viewport information to the
-    // input system.  May be used outside of the lock but only on the handler thread.
-    private final DisplayViewport mTempDefaultViewport = new DisplayViewport();
-    private final DisplayViewport mTempExternalTouchViewport = new DisplayViewport();
-
-    public DisplayManagerService(Context context, Handler mainHandler) {
-        mContext = context;
-        mHeadless = SystemProperties.get(SYSTEM_HEADLESS).equals("1");
-
-        mHandler = new DisplayManagerHandler(mainHandler.getLooper());
-        mUiHandler = UiThread.getHandler();
-        mDisplayAdapterListener = new DisplayAdapterListener();
-        mSingleDisplayDemoMode = SystemProperties.getBoolean("persist.demo.singledisplay", false);
-
-        mHandler.sendEmptyMessage(MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER);
-    }
-
-    /**
-     * Pauses the boot process to wait for the first display to be initialized.
-     */
-    public boolean waitForDefaultDisplay() {
-        synchronized (mSyncRoot) {
-            long timeout = SystemClock.uptimeMillis() + WAIT_FOR_DEFAULT_DISPLAY_TIMEOUT;
-            while (mLogicalDisplays.get(Display.DEFAULT_DISPLAY) == null) {
-                long delay = timeout - SystemClock.uptimeMillis();
-                if (delay <= 0) {
-                    return false;
-                }
-                if (DEBUG) {
-                    Slog.d(TAG, "waitForDefaultDisplay: waiting, timeout=" + delay);
-                }
-                try {
-                    mSyncRoot.wait(delay);
-                } catch (InterruptedException ex) {
-                }
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Called during initialization to associate the display manager with the
-     * window manager.
-     */
-    public void setWindowManager(WindowManagerFuncs windowManagerFuncs) {
-        synchronized (mSyncRoot) {
-            mWindowManagerFuncs = windowManagerFuncs;
-            scheduleTraversalLocked(false);
-        }
-    }
-
-    /**
-     * Called during initialization to associate the display manager with the
-     * input manager.
-     */
-    public void setInputManager(InputManagerFuncs inputManagerFuncs) {
-        synchronized (mSyncRoot) {
-            mInputManagerFuncs = inputManagerFuncs;
-            scheduleTraversalLocked(false);
-        }
-    }
-
-    /**
-     * Called when the system is ready to go.
-     */
-    public void systemReady(boolean safeMode, boolean onlyCore) {
-        synchronized (mSyncRoot) {
-            mSafeMode = safeMode;
-            mOnlyCore = onlyCore;
-        }
-
-        mHandler.sendEmptyMessage(MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS);
-    }
-
-    /**
-     * Returns true if the device is headless.
-     *
-     * @return True if the device is headless.
-     */
-    public boolean isHeadless() {
-        return mHeadless;
-    }
-
-    /**
-     * Registers a display transaction listener to provide the client a chance to
-     * update its surfaces within the same transaction as any display layout updates.
-     *
-     * @param listener The listener to register.
-     */
-    public void registerDisplayTransactionListener(DisplayTransactionListener listener) {
-        if (listener == null) {
-            throw new IllegalArgumentException("listener must not be null");
-        }
-
-        // List is self-synchronized copy-on-write.
-        mDisplayTransactionListeners.add(listener);
-    }
-
-    /**
-     * Unregisters a display transaction listener to provide the client a chance to
-     * update its surfaces within the same transaction as any display layout updates.
-     *
-     * @param listener The listener to unregister.
-     */
-    public void unregisterDisplayTransactionListener(DisplayTransactionListener listener) {
-        if (listener == null) {
-            throw new IllegalArgumentException("listener must not be null");
-        }
-
-        // List is self-synchronized copy-on-write.
-        mDisplayTransactionListeners.remove(listener);
-    }
-
-    /**
-     * Overrides the display information of a particular logical display.
-     * This is used by the window manager to control the size and characteristics
-     * of the default display.  It is expected to apply the requested change
-     * to the display information synchronously so that applications will immediately
-     * observe the new state.
-     *
-     * NOTE: This method must be the only entry point by which the window manager
-     * influences the logical configuration of displays.
-     *
-     * @param displayId The logical display id.
-     * @param info The new data to be stored.
-     */
-    public void setDisplayInfoOverrideFromWindowManager(
-            int displayId, DisplayInfo info) {
-        synchronized (mSyncRoot) {
-            LogicalDisplay display = mLogicalDisplays.get(displayId);
-            if (display != null) {
-                if (display.setDisplayInfoOverrideFromWindowManagerLocked(info)) {
-                    sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
-                    scheduleTraversalLocked(false);
-                }
-            }
-        }
-    }
-
-    /**
-     * Called by the window manager to perform traversals while holding a
-     * surface flinger transaction.
-     */
-    public void performTraversalInTransactionFromWindowManager() {
-        synchronized (mSyncRoot) {
-            if (!mPendingTraversal) {
-                return;
-            }
-            mPendingTraversal = false;
-
-            performTraversalInTransactionLocked();
-        }
-
-        // List is self-synchronized copy-on-write.
-        for (DisplayTransactionListener listener : mDisplayTransactionListeners) {
-            listener.onDisplayTransaction();
-        }
-    }
-
-    /**
-     * Called by the power manager to blank all displays.
-     */
-    public void blankAllDisplaysFromPowerManager() {
-        synchronized (mSyncRoot) {
-            if (mAllDisplayBlankStateFromPowerManager != DISPLAY_BLANK_STATE_BLANKED) {
-                mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_BLANKED;
-                updateAllDisplayBlankingLocked();
-                scheduleTraversalLocked(false);
-            }
-        }
-    }
-
-    /**
-     * Called by the power manager to unblank all displays.
-     */
-    public void unblankAllDisplaysFromPowerManager() {
-        synchronized (mSyncRoot) {
-            if (mAllDisplayBlankStateFromPowerManager != DISPLAY_BLANK_STATE_UNBLANKED) {
-                mAllDisplayBlankStateFromPowerManager = DISPLAY_BLANK_STATE_UNBLANKED;
-                updateAllDisplayBlankingLocked();
-                scheduleTraversalLocked(false);
-            }
-        }
-    }
-
-    /**
-     * Returns information about the specified logical display.
-     *
-     * @param displayId The logical display id.
-     * @return The logical display info, or null if the display does not exist.  The
-     * returned object must be treated as immutable.
-     */
-    @Override // Binder call
-    public DisplayInfo getDisplayInfo(int displayId) {
-        final int callingUid = Binder.getCallingUid();
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                LogicalDisplay display = mLogicalDisplays.get(displayId);
-                if (display != null) {
-                    DisplayInfo info = display.getDisplayInfoLocked();
-                    if (info.hasAccess(callingUid)) {
-                        return info;
-                    }
-                }
-                return null;
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    /**
-     * Returns the list of all display ids.
-     */
-    @Override // Binder call
-    public int[] getDisplayIds() {
-        final int callingUid = Binder.getCallingUid();
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                final int count = mLogicalDisplays.size();
-                int[] displayIds = new int[count];
-                int n = 0;
-                for (int i = 0; i < count; i++) {
-                    LogicalDisplay display = mLogicalDisplays.valueAt(i);
-                    DisplayInfo info = display.getDisplayInfoLocked();
-                    if (info.hasAccess(callingUid)) {
-                        displayIds[n++] = mLogicalDisplays.keyAt(i);
-                    }
-                }
-                if (n != count) {
-                    displayIds = Arrays.copyOfRange(displayIds, 0, n);
-                }
-                return displayIds;
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override // Binder call
-    public void registerCallback(IDisplayManagerCallback callback) {
-        if (callback == null) {
-            throw new IllegalArgumentException("listener must not be null");
-        }
-
-        synchronized (mSyncRoot) {
-            int callingPid = Binder.getCallingPid();
-            if (mCallbacks.get(callingPid) != null) {
-                throw new SecurityException("The calling process has already "
-                        + "registered an IDisplayManagerCallback.");
-            }
-
-            CallbackRecord record = new CallbackRecord(callingPid, callback);
-            try {
-                IBinder binder = callback.asBinder();
-                binder.linkToDeath(record, 0);
-            } catch (RemoteException ex) {
-                // give up
-                throw new RuntimeException(ex);
-            }
-
-            mCallbacks.put(callingPid, record);
-        }
-    }
-
-    private void onCallbackDied(CallbackRecord record) {
-        synchronized (mSyncRoot) {
-            mCallbacks.remove(record.mPid);
-            stopWifiDisplayScanLocked(record);
-        }
-    }
-
-    @Override // Binder call
-    public void startWifiDisplayScan() {
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to start wifi display scans");
-
-        final int callingPid = Binder.getCallingPid();
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                CallbackRecord record = mCallbacks.get(callingPid);
-                if (record == null) {
-                    throw new IllegalStateException("The calling process has not "
-                            + "registered an IDisplayManagerCallback.");
-                }
-                startWifiDisplayScanLocked(record);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private void startWifiDisplayScanLocked(CallbackRecord record) {
-        if (!record.mWifiDisplayScanRequested) {
-            record.mWifiDisplayScanRequested = true;
-            if (mWifiDisplayScanRequestCount++ == 0) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestStartScanLocked();
-                }
-            }
-        }
-    }
-
-    @Override // Binder call
-    public void stopWifiDisplayScan() {
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to stop wifi display scans");
-
-        final int callingPid = Binder.getCallingPid();
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                CallbackRecord record = mCallbacks.get(callingPid);
-                if (record == null) {
-                    throw new IllegalStateException("The calling process has not "
-                            + "registered an IDisplayManagerCallback.");
-                }
-                stopWifiDisplayScanLocked(record);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private void stopWifiDisplayScanLocked(CallbackRecord record) {
-        if (record.mWifiDisplayScanRequested) {
-            record.mWifiDisplayScanRequested = false;
-            if (--mWifiDisplayScanRequestCount == 0) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestStopScanLocked();
-                }
-            } else if (mWifiDisplayScanRequestCount < 0) {
-                Log.wtf(TAG, "mWifiDisplayScanRequestCount became negative: "
-                        + mWifiDisplayScanRequestCount);
-                mWifiDisplayScanRequestCount = 0;
-            }
-        }
-    }
-
-    @Override // Binder call
-    public void connectWifiDisplay(String address) {
-        if (address == null) {
-            throw new IllegalArgumentException("address must not be null");
-        }
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to connect to a wifi display");
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestConnectLocked(address);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override
-    public void pauseWifiDisplay() {
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to pause a wifi display session");
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestPauseLocked();
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override
-    public void resumeWifiDisplay() {
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to resume a wifi display session");
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestResumeLocked();
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override // Binder call
-    public void disconnectWifiDisplay() {
-        // This request does not require special permissions.
-        // Any app can request disconnection from the currently active wifi display.
-        // This exception should no longer be needed once wifi display control moves
-        // to the media router service.
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestDisconnectLocked();
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override // Binder call
-    public void renameWifiDisplay(String address, String alias) {
-        if (address == null) {
-            throw new IllegalArgumentException("address must not be null");
-        }
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to rename to a wifi display");
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestRenameLocked(address, alias);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override // Binder call
-    public void forgetWifiDisplay(String address) {
-        if (address == null) {
-            throw new IllegalArgumentException("address must not be null");
-        }
-        mContext.enforceCallingOrSelfPermission(Manifest.permission.CONFIGURE_WIFI_DISPLAY,
-                "Permission required to forget to a wifi display");
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    mWifiDisplayAdapter.requestForgetLocked(address);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override // Binder call
-    public WifiDisplayStatus getWifiDisplayStatus() {
-        // This request does not require special permissions.
-        // Any app can get information about available wifi displays.
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mWifiDisplayAdapter != null) {
-                    return mWifiDisplayAdapter.getWifiDisplayStatusLocked();
-                }
-                return new WifiDisplayStatus();
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    @Override // Binder call
-    public int createVirtualDisplay(IBinder appToken, String packageName,
-            String name, int width, int height, int densityDpi, Surface surface, int flags) {
-        final int callingUid = Binder.getCallingUid();
-        if (!validatePackageName(callingUid, packageName)) {
-            throw new SecurityException("packageName must match the calling uid");
-        }
-        if (appToken == null) {
-            throw new IllegalArgumentException("appToken must not be null");
-        }
-        if (TextUtils.isEmpty(name)) {
-            throw new IllegalArgumentException("name must be non-null and non-empty");
-        }
-        if (width <= 0 || height <= 0 || densityDpi <= 0) {
-            throw new IllegalArgumentException("width, height, and densityDpi must be "
-                    + "greater than 0");
-        }
-        if (surface == null) {
-            throw new IllegalArgumentException("surface must not be null");
-        }
-        if ((flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC) != 0) {
-            if (mContext.checkCallingPermission(android.Manifest.permission.CAPTURE_VIDEO_OUTPUT)
-                    != PackageManager.PERMISSION_GRANTED
-                    && mContext.checkCallingPermission(
-                            android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
-                            != PackageManager.PERMISSION_GRANTED) {
-                throw new SecurityException("Requires CAPTURE_VIDEO_OUTPUT or "
-                        + "CAPTURE_SECURE_VIDEO_OUTPUT permission to create a "
-                        + "public virtual display.");
-            }
-        }
-        if ((flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
-            if (mContext.checkCallingPermission(
-                    android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
-                    != PackageManager.PERMISSION_GRANTED) {
-                throw new SecurityException("Requires CAPTURE_SECURE_VIDEO_OUTPUT "
-                        + "to create a secure virtual display.");
-            }
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mVirtualDisplayAdapter == null) {
-                    Slog.w(TAG, "Rejecting request to create private virtual display "
-                            + "because the virtual display adapter is not available.");
-                    return -1;
-                }
-
-                DisplayDevice device = mVirtualDisplayAdapter.createVirtualDisplayLocked(
-                        appToken, callingUid, packageName, name, width, height, densityDpi,
-                        surface, flags);
-                if (device == null) {
-                    return -1;
-                }
-
-                handleDisplayDeviceAddedLocked(device);
-                LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
-                if (display != null) {
-                    return display.getDisplayIdLocked();
-                }
-
-                // Something weird happened and the logical display was not created.
-                Slog.w(TAG, "Rejecting request to create virtual display "
-                        + "because the logical display was not created.");
-                mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
-                handleDisplayDeviceRemovedLocked(device);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-        return -1;
-    }
-
-    @Override // Binder call
-    public void releaseVirtualDisplay(IBinder appToken) {
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mSyncRoot) {
-                if (mVirtualDisplayAdapter == null) {
-                    return;
-                }
-
-                DisplayDevice device =
-                        mVirtualDisplayAdapter.releaseVirtualDisplayLocked(appToken);
-                if (device != null) {
-                    handleDisplayDeviceRemovedLocked(device);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private boolean validatePackageName(int uid, String packageName) {
-        if (packageName != null) {
-            String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
-            if (packageNames != null) {
-                for (String n : packageNames) {
-                    if (n.equals(packageName)) {
-                        return true;
-                    }
-                }
-            }
-        }
-        return false;
-    }
-
-    private void registerDefaultDisplayAdapter() {
-        // Register default display adapter.
-        synchronized (mSyncRoot) {
-            if (mHeadless) {
-                registerDisplayAdapterLocked(new HeadlessDisplayAdapter(
-                        mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
-            } else {
-                registerDisplayAdapterLocked(new LocalDisplayAdapter(
-                        mSyncRoot, mContext, mHandler, mDisplayAdapterListener));
-            }
-        }
-    }
-
-    private void registerAdditionalDisplayAdapters() {
-        synchronized (mSyncRoot) {
-            if (shouldRegisterNonEssentialDisplayAdaptersLocked()) {
-                registerOverlayDisplayAdapterLocked();
-                registerWifiDisplayAdapterLocked();
-                registerVirtualDisplayAdapterLocked();
-            }
-        }
-    }
-
-    private void registerOverlayDisplayAdapterLocked() {
-        registerDisplayAdapterLocked(new OverlayDisplayAdapter(
-                mSyncRoot, mContext, mHandler, mDisplayAdapterListener, mUiHandler));
-    }
-
-    private void registerWifiDisplayAdapterLocked() {
-        if (mContext.getResources().getBoolean(
-                com.android.internal.R.bool.config_enableWifiDisplay)
-                || SystemProperties.getInt(FORCE_WIFI_DISPLAY_ENABLE, -1) == 1) {
-            mWifiDisplayAdapter = new WifiDisplayAdapter(
-                    mSyncRoot, mContext, mHandler, mDisplayAdapterListener,
-                    mPersistentDataStore);
-            registerDisplayAdapterLocked(mWifiDisplayAdapter);
-        }
-    }
-
-    private void registerVirtualDisplayAdapterLocked() {
-        mVirtualDisplayAdapter = new VirtualDisplayAdapter(
-                mSyncRoot, mContext, mHandler, mDisplayAdapterListener);
-        registerDisplayAdapterLocked(mVirtualDisplayAdapter);
-    }
-
-    private boolean shouldRegisterNonEssentialDisplayAdaptersLocked() {
-        // In safe mode, we disable non-essential display adapters to give the user
-        // an opportunity to fix broken settings or other problems that might affect
-        // system stability.
-        // In only-core mode, we disable non-essential display adapters to minimize
-        // the number of dependencies that are started while in this mode and to
-        // prevent problems that might occur due to the device being encrypted.
-        return !mSafeMode && !mOnlyCore;
-    }
-
-    private void registerDisplayAdapterLocked(DisplayAdapter adapter) {
-        mDisplayAdapters.add(adapter);
-        adapter.registerLocked();
-    }
-
-    private void handleDisplayDeviceAdded(DisplayDevice device) {
-        synchronized (mSyncRoot) {
-            handleDisplayDeviceAddedLocked(device);
-        }
-    }
-
-    private void handleDisplayDeviceAddedLocked(DisplayDevice device) {
-        if (mDisplayDevices.contains(device)) {
-            Slog.w(TAG, "Attempted to add already added display device: "
-                    + device.getDisplayDeviceInfoLocked());
-            return;
-        }
-
-        Slog.i(TAG, "Display device added: " + device.getDisplayDeviceInfoLocked());
-
-        mDisplayDevices.add(device);
-        addLogicalDisplayLocked(device);
-        updateDisplayBlankingLocked(device);
-        scheduleTraversalLocked(false);
-    }
-
-    private void handleDisplayDeviceChanged(DisplayDevice device) {
-        synchronized (mSyncRoot) {
-            if (!mDisplayDevices.contains(device)) {
-                Slog.w(TAG, "Attempted to change non-existent display device: "
-                        + device.getDisplayDeviceInfoLocked());
-                return;
-            }
-
-            Slog.i(TAG, "Display device changed: " + device.getDisplayDeviceInfoLocked());
-
-            device.applyPendingDisplayDeviceInfoChangesLocked();
-            if (updateLogicalDisplaysLocked()) {
-                scheduleTraversalLocked(false);
-            }
-        }
-    }
-
-    private void handleDisplayDeviceRemoved(DisplayDevice device) {
-        synchronized (mSyncRoot) {
-            handleDisplayDeviceRemovedLocked(device);
-        }
-    }
-    private void handleDisplayDeviceRemovedLocked(DisplayDevice device) {
-        if (!mDisplayDevices.remove(device)) {
-            Slog.w(TAG, "Attempted to remove non-existent display device: "
-                    + device.getDisplayDeviceInfoLocked());
-            return;
-        }
-
-        Slog.i(TAG, "Display device removed: " + device.getDisplayDeviceInfoLocked());
-
-        updateLogicalDisplaysLocked();
-        scheduleTraversalLocked(false);
-    }
-
-    private void updateAllDisplayBlankingLocked() {
-        final int count = mDisplayDevices.size();
-        for (int i = 0; i < count; i++) {
-            DisplayDevice device = mDisplayDevices.get(i);
-            updateDisplayBlankingLocked(device);
-        }
-    }
-
-    private void updateDisplayBlankingLocked(DisplayDevice device) {
-        // Blank or unblank the display immediately to match the state requested
-        // by the power manager (if known).
-        DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
-        if ((info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0) {
-            switch (mAllDisplayBlankStateFromPowerManager) {
-                case DISPLAY_BLANK_STATE_BLANKED:
-                    device.blankLocked();
-                    break;
-                case DISPLAY_BLANK_STATE_UNBLANKED:
-                    device.unblankLocked();
-                    break;
-            }
-        }
-    }
-
-    // Adds a new logical display based on the given display device.
-    // Sends notifications if needed.
-    private void addLogicalDisplayLocked(DisplayDevice device) {
-        DisplayDeviceInfo deviceInfo = device.getDisplayDeviceInfoLocked();
-        boolean isDefault = (deviceInfo.flags
-                & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0;
-        if (isDefault && mLogicalDisplays.get(Display.DEFAULT_DISPLAY) != null) {
-            Slog.w(TAG, "Ignoring attempt to add a second default display: " + deviceInfo);
-            isDefault = false;
-        }
-
-        if (!isDefault && mSingleDisplayDemoMode) {
-            Slog.i(TAG, "Not creating a logical display for a secondary display "
-                    + " because single display demo mode is enabled: " + deviceInfo);
-            return;
-        }
-
-        final int displayId = assignDisplayIdLocked(isDefault);
-        final int layerStack = assignLayerStackLocked(displayId);
-
-        LogicalDisplay display = new LogicalDisplay(displayId, layerStack, device);
-        display.updateLocked(mDisplayDevices);
-        if (!display.isValidLocked()) {
-            // This should never happen currently.
-            Slog.w(TAG, "Ignoring display device because the logical display "
-                    + "created from it was not considered valid: " + deviceInfo);
-            return;
-        }
-
-        mLogicalDisplays.put(displayId, display);
-
-        // Wake up waitForDefaultDisplay.
-        if (isDefault) {
-            mSyncRoot.notifyAll();
-        }
-
-        sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_ADDED);
-    }
-
-    private int assignDisplayIdLocked(boolean isDefault) {
-        return isDefault ? Display.DEFAULT_DISPLAY : mNextNonDefaultDisplayId++;
-    }
-
-    private int assignLayerStackLocked(int displayId) {
-        // Currently layer stacks and display ids are the same.
-        // This need not be the case.
-        return displayId;
-    }
-
-    // Updates all existing logical displays given the current set of display devices.
-    // Removes invalid logical displays.
-    // Sends notifications if needed.
-    private boolean updateLogicalDisplaysLocked() {
-        boolean changed = false;
-        for (int i = mLogicalDisplays.size(); i-- > 0; ) {
-            final int displayId = mLogicalDisplays.keyAt(i);
-            LogicalDisplay display = mLogicalDisplays.valueAt(i);
-
-            mTempDisplayInfo.copyFrom(display.getDisplayInfoLocked());
-            display.updateLocked(mDisplayDevices);
-            if (!display.isValidLocked()) {
-                mLogicalDisplays.removeAt(i);
-                sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REMOVED);
-                changed = true;
-            } else if (!mTempDisplayInfo.equals(display.getDisplayInfoLocked())) {
-                sendDisplayEventLocked(displayId, DisplayManagerGlobal.EVENT_DISPLAY_CHANGED);
-                changed = true;
-            }
-        }
-        return changed;
-    }
-
-    private void performTraversalInTransactionLocked() {
-        // Clear all viewports before configuring displays so that we can keep
-        // track of which ones we have configured.
-        clearViewportsLocked();
-
-        // Configure each display device.
-        final int count = mDisplayDevices.size();
-        for (int i = 0; i < count; i++) {
-            DisplayDevice device = mDisplayDevices.get(i);
-            configureDisplayInTransactionLocked(device);
-            device.performTraversalInTransactionLocked();
-        }
-
-        // Tell the input system about these new viewports.
-        if (mInputManagerFuncs != null) {
-            mHandler.sendEmptyMessage(MSG_UPDATE_VIEWPORT);
-        }
-    }
-
-    /**
-     * Tells the display manager whether there is interesting unique content on the
-     * specified logical display.  This is used to control automatic mirroring.
-     * <p>
-     * If the display has unique content, then the display manager arranges for it
-     * to be presented on a physical display if appropriate.  Otherwise, the display manager
-     * may choose to make the physical display mirror some other logical display.
-     * </p>
-     *
-     * @param displayId The logical display id to update.
-     * @param hasContent True if the logical display has content.
-     * @param inTraversal True if called from WindowManagerService during a window traversal prior
-     * to call to performTraversalInTransactionFromWindowManager.
-     */
-    public void setDisplayHasContent(int displayId, boolean hasContent, boolean inTraversal) {
-        synchronized (mSyncRoot) {
-            LogicalDisplay display = mLogicalDisplays.get(displayId);
-            if (display != null && display.hasContentLocked() != hasContent) {
-                if (DEBUG) {
-                    Slog.d(TAG, "Display " + displayId + " hasContent flag changed: "
-                            + "hasContent=" + hasContent + ", inTraversal=" + inTraversal);
-                }
-
-                display.setHasContentLocked(hasContent);
-                scheduleTraversalLocked(inTraversal);
-            }
-        }
-    }
-
-    private void clearViewportsLocked() {
-        mDefaultViewport.valid = false;
-        mExternalTouchViewport.valid = false;
-    }
-
-    private void configureDisplayInTransactionLocked(DisplayDevice device) {
-        DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
-        boolean isPrivate = (info.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0;
-
-        // Find the logical display that the display device is showing.
-        // Private displays never mirror other displays.
-        LogicalDisplay display = findLogicalDisplayForDeviceLocked(device);
-        if (!isPrivate) {
-            if (display != null && !display.hasContentLocked()) {
-                // If the display does not have any content of its own, then
-                // automatically mirror the default logical display contents.
-                display = null;
-            }
-            if (display == null) {
-                display = mLogicalDisplays.get(Display.DEFAULT_DISPLAY);
-            }
-        }
-
-        // Apply the logical display configuration to the display device.
-        if (display == null) {
-            // TODO: no logical display for the device, blank it
-            Slog.w(TAG, "Missing logical display to use for physical display device: "
-                    + device.getDisplayDeviceInfoLocked());
-            return;
-        }
-        boolean isBlanked = (mAllDisplayBlankStateFromPowerManager == DISPLAY_BLANK_STATE_BLANKED)
-                && (info.flags & DisplayDeviceInfo.FLAG_NEVER_BLANK) == 0;
-        display.configureDisplayInTransactionLocked(device, isBlanked);
-
-        // Update the viewports if needed.
-        if (!mDefaultViewport.valid
-                && (info.flags & DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY) != 0) {
-            setViewportLocked(mDefaultViewport, display, device);
-        }
-        if (!mExternalTouchViewport.valid
-                && info.touch == DisplayDeviceInfo.TOUCH_EXTERNAL) {
-            setViewportLocked(mExternalTouchViewport, display, device);
-        }
-    }
-
-    private static void setViewportLocked(DisplayViewport viewport,
-            LogicalDisplay display, DisplayDevice device) {
-        viewport.valid = true;
-        viewport.displayId = display.getDisplayIdLocked();
-        device.populateViewportLocked(viewport);
-    }
-
-    private LogicalDisplay findLogicalDisplayForDeviceLocked(DisplayDevice device) {
-        final int count = mLogicalDisplays.size();
-        for (int i = 0; i < count; i++) {
-            LogicalDisplay display = mLogicalDisplays.valueAt(i);
-            if (display.getPrimaryDisplayDeviceLocked() == device) {
-                return display;
-            }
-        }
-        return null;
-    }
-
-    private void sendDisplayEventLocked(int displayId, int event) {
-        Message msg = mHandler.obtainMessage(MSG_DELIVER_DISPLAY_EVENT, displayId, event);
-        mHandler.sendMessage(msg);
-    }
-
-    // Requests that performTraversalsInTransactionFromWindowManager be called at a
-    // later time to apply changes to surfaces and displays.
-    private void scheduleTraversalLocked(boolean inTraversal) {
-        if (!mPendingTraversal && mWindowManagerFuncs != null) {
-            mPendingTraversal = true;
-            if (!inTraversal) {
-                mHandler.sendEmptyMessage(MSG_REQUEST_TRAVERSAL);
-            }
-        }
-    }
-
-    // Runs on Handler thread.
-    // Delivers display event notifications to callbacks.
-    private void deliverDisplayEvent(int displayId, int event) {
-        if (DEBUG) {
-            Slog.d(TAG, "Delivering display event: displayId="
-                    + displayId + ", event=" + event);
-        }
-
-        // Grab the lock and copy the callbacks.
-        final int count;
-        synchronized (mSyncRoot) {
-            count = mCallbacks.size();
-            mTempCallbacks.clear();
-            for (int i = 0; i < count; i++) {
-                mTempCallbacks.add(mCallbacks.valueAt(i));
-            }
-        }
-
-        // After releasing the lock, send the notifications out.
-        for (int i = 0; i < count; i++) {
-            mTempCallbacks.get(i).notifyDisplayEventAsync(displayId, event);
-        }
-        mTempCallbacks.clear();
-    }
-
-    @Override // Binder call
-    public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
-        if (mContext == null
-                || mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
-                        != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump DisplayManager from from pid="
-                    + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("DISPLAY MANAGER (dumpsys display)");
-
-        synchronized (mSyncRoot) {
-            pw.println("  mHeadless=" + mHeadless);
-            pw.println("  mOnlyCode=" + mOnlyCore);
-            pw.println("  mSafeMode=" + mSafeMode);
-            pw.println("  mPendingTraversal=" + mPendingTraversal);
-            pw.println("  mAllDisplayBlankStateFromPowerManager="
-                    + mAllDisplayBlankStateFromPowerManager);
-            pw.println("  mNextNonDefaultDisplayId=" + mNextNonDefaultDisplayId);
-            pw.println("  mDefaultViewport=" + mDefaultViewport);
-            pw.println("  mExternalTouchViewport=" + mExternalTouchViewport);
-            pw.println("  mSingleDisplayDemoMode=" + mSingleDisplayDemoMode);
-            pw.println("  mWifiDisplayScanRequestCount=" + mWifiDisplayScanRequestCount);
-
-            IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "    ");
-            ipw.increaseIndent();
-
-            pw.println();
-            pw.println("Display Adapters: size=" + mDisplayAdapters.size());
-            for (DisplayAdapter adapter : mDisplayAdapters) {
-                pw.println("  " + adapter.getName());
-                adapter.dumpLocked(ipw);
-            }
-
-            pw.println();
-            pw.println("Display Devices: size=" + mDisplayDevices.size());
-            for (DisplayDevice device : mDisplayDevices) {
-                pw.println("  " + device.getDisplayDeviceInfoLocked());
-                device.dumpLocked(ipw);
-            }
-
-            final int logicalDisplayCount = mLogicalDisplays.size();
-            pw.println();
-            pw.println("Logical Displays: size=" + logicalDisplayCount);
-            for (int i = 0; i < logicalDisplayCount; i++) {
-                int displayId = mLogicalDisplays.keyAt(i);
-                LogicalDisplay display = mLogicalDisplays.valueAt(i);
-                pw.println("  Display " + displayId + ":");
-                display.dumpLocked(ipw);
-            }
-
-            final int callbackCount = mCallbacks.size();
-            pw.println();
-            pw.println("Callbacks: size=" + callbackCount);
-            for (int i = 0; i < callbackCount; i++) {
-                CallbackRecord callback = mCallbacks.valueAt(i);
-                pw.println("  " + i + ": mPid=" + callback.mPid
-                        + ", mWifiDisplayScanRequested=" + callback.mWifiDisplayScanRequested);
-            }
-        }
-    }
-
-    /**
-     * This is the object that everything in the display manager locks on.
-     * We make it an inner class within the {@link DisplayManagerService} to so that it is
-     * clear that the object belongs to the display manager service and that it is
-     * a unique object with a special purpose.
-     */
-    public static final class SyncRoot {
-    }
-
-    /**
-     * Private interface to the window manager.
-     */
-    public interface WindowManagerFuncs {
-        /**
-         * Request that the window manager call
-         * {@link #performTraversalInTransactionFromWindowManager} within a surface
-         * transaction at a later time.
-         */
-        void requestTraversal();
-    }
-
-    /**
-     * Private interface to the input manager.
-     */
-    public interface InputManagerFuncs {
-        /**
-         * Sets information about the displays as needed by the input system.
-         * The input system should copy this information if required.
-         */
-        void setDisplayViewports(DisplayViewport defaultViewport,
-                DisplayViewport externalTouchViewport);
-    }
-
-    private final class DisplayManagerHandler extends Handler {
-        public DisplayManagerHandler(Looper looper) {
-            super(looper, null, true /*async*/);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_REGISTER_DEFAULT_DISPLAY_ADAPTER:
-                    registerDefaultDisplayAdapter();
-                    break;
-
-                case MSG_REGISTER_ADDITIONAL_DISPLAY_ADAPTERS:
-                    registerAdditionalDisplayAdapters();
-                    break;
-
-                case MSG_DELIVER_DISPLAY_EVENT:
-                    deliverDisplayEvent(msg.arg1, msg.arg2);
-                    break;
-
-                case MSG_REQUEST_TRAVERSAL:
-                    mWindowManagerFuncs.requestTraversal();
-                    break;
-
-                case MSG_UPDATE_VIEWPORT: {
-                    synchronized (mSyncRoot) {
-                        mTempDefaultViewport.copyFrom(mDefaultViewport);
-                        mTempExternalTouchViewport.copyFrom(mExternalTouchViewport);
-                    }
-                    mInputManagerFuncs.setDisplayViewports(
-                            mTempDefaultViewport, mTempExternalTouchViewport);
-                    break;
-                }
-            }
-        }
-    }
-
-    private final class DisplayAdapterListener implements DisplayAdapter.Listener {
-        @Override
-        public void onDisplayDeviceEvent(DisplayDevice device, int event) {
-            switch (event) {
-                case DisplayAdapter.DISPLAY_DEVICE_EVENT_ADDED:
-                    handleDisplayDeviceAdded(device);
-                    break;
-
-                case DisplayAdapter.DISPLAY_DEVICE_EVENT_CHANGED:
-                    handleDisplayDeviceChanged(device);
-                    break;
-
-                case DisplayAdapter.DISPLAY_DEVICE_EVENT_REMOVED:
-                    handleDisplayDeviceRemoved(device);
-                    break;
-            }
-        }
-
-        @Override
-        public void onTraversalRequested() {
-            synchronized (mSyncRoot) {
-                scheduleTraversalLocked(false);
-            }
-        }
-    }
-
-    private final class CallbackRecord implements DeathRecipient {
-        public final int mPid;
-        private final IDisplayManagerCallback mCallback;
-
-        public boolean mWifiDisplayScanRequested;
-
-        public CallbackRecord(int pid, IDisplayManagerCallback callback) {
-            mPid = pid;
-            mCallback = callback;
-        }
-
-        @Override
-        public void binderDied() {
-            if (DEBUG) {
-                Slog.d(TAG, "Display listener for pid " + mPid + " died.");
-            }
-            onCallbackDied(this);
-        }
-
-        public void notifyDisplayEventAsync(int displayId, int event) {
-            try {
-                mCallback.onDisplayEvent(displayId, event);
-            } catch (RemoteException ex) {
-                Slog.w(TAG, "Failed to notify process "
-                        + mPid + " that displays changed, assuming it died.", ex);
-                binderDied();
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/display/DisplayTransactionListener.java b/services/java/com/android/server/display/DisplayTransactionListener.java
deleted file mode 100644
index 34eb8f9..0000000
--- a/services/java/com/android/server/display/DisplayTransactionListener.java
+++ /dev/null
@@ -1,26 +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.server.display;
-
-/**
- * Called within a Surface transaction whenever the size or orientation of a
- * display may have changed.  Provides an opportunity for the client to
- * update the position of its surfaces as part of the same transaction.
- */
-public interface DisplayTransactionListener {
-    void onDisplayTransaction();
-}
diff --git a/services/java/com/android/server/display/DisplayViewport.java b/services/java/com/android/server/display/DisplayViewport.java
deleted file mode 100644
index 5080556..0000000
--- a/services/java/com/android/server/display/DisplayViewport.java
+++ /dev/null
@@ -1,75 +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.server.display;
-
-import android.graphics.Rect;
-
-/**
- * Describes how the pixels of physical display device reflects the content of
- * a logical display.
- * <p>
- * This information is used by the input system to translate touch input from
- * physical display coordinates into logical display coordinates.
- * </p>
- */
-public final class DisplayViewport {
-    // True if this viewport is valid.
-    public boolean valid;
-
-    // The logical display id.
-    public int displayId;
-
-    // The rotation applied to the physical coordinate system.
-    public int orientation;
-
-    // The portion of the logical display that are presented on this physical display.
-    public final Rect logicalFrame = new Rect();
-
-    // The portion of the (rotated) physical display that shows the logical display contents.
-    // The relation between logical and physical frame defines how the coordinate system
-    // should be scaled or translated after rotation.
-    public final Rect physicalFrame = new Rect();
-
-    // The full width and height of the display device, rotated in the same
-    // manner as physicalFrame.  This expresses the full native size of the display device.
-    // The physical frame should usually fit within this area.
-    public int deviceWidth;
-    public int deviceHeight;
-
-    public void copyFrom(DisplayViewport viewport) {
-        valid = viewport.valid;
-        displayId = viewport.displayId;
-        orientation = viewport.orientation;
-        logicalFrame.set(viewport.logicalFrame);
-        physicalFrame.set(viewport.physicalFrame);
-        deviceWidth = viewport.deviceWidth;
-        deviceHeight = viewport.deviceHeight;
-    }
-
-    // For debugging purposes.
-    @Override
-    public String toString() {
-        return "DisplayViewport{valid=" + valid
-                + ", displayId=" + displayId
-                + ", orientation=" + orientation
-                + ", logicalFrame=" + logicalFrame
-                + ", physicalFrame=" + physicalFrame
-                + ", deviceWidth=" + deviceWidth
-                + ", deviceHeight=" + deviceHeight
-                + "}";
-    }
-}
diff --git a/services/java/com/android/server/display/HeadlessDisplayAdapter.java b/services/java/com/android/server/display/HeadlessDisplayAdapter.java
deleted file mode 100644
index 7a104d7..0000000
--- a/services/java/com/android/server/display/HeadlessDisplayAdapter.java
+++ /dev/null
@@ -1,73 +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.server.display;
-
-import android.content.Context;
-import android.os.Handler;
-import android.util.DisplayMetrics;
-import android.view.Display;
-
-/**
- * Provides a fake default display for headless systems.
- * <p>
- * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock.
- * </p>
- */
-final class HeadlessDisplayAdapter extends DisplayAdapter {
-    private static final String TAG = "HeadlessDisplayAdapter";
-
-    // Called with SyncRoot lock held.
-    public HeadlessDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
-            Context context, Handler handler, Listener listener) {
-        super(syncRoot, context, handler, listener, TAG);
-    }
-
-    @Override
-    public void registerLocked() {
-        super.registerLocked();
-        sendDisplayDeviceEventLocked(new HeadlessDisplayDevice(), DISPLAY_DEVICE_EVENT_ADDED);
-    }
-
-    private final class HeadlessDisplayDevice extends DisplayDevice {
-        private DisplayDeviceInfo mInfo;
-
-        public HeadlessDisplayDevice() {
-            super(HeadlessDisplayAdapter.this, null);
-        }
-
-        @Override
-        public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
-            if (mInfo == null) {
-                mInfo = new DisplayDeviceInfo();
-                mInfo.name = getContext().getResources().getString(
-                        com.android.internal.R.string.display_manager_built_in_display_name);
-                mInfo.width = 640;
-                mInfo.height = 480;
-                mInfo.refreshRate = 60;
-                mInfo.densityDpi = DisplayMetrics.DENSITY_DEFAULT;
-                mInfo.xDpi = 160;
-                mInfo.yDpi = 160;
-                mInfo.flags = DisplayDeviceInfo.FLAG_DEFAULT_DISPLAY
-                        | DisplayDeviceInfo.FLAG_SECURE
-                        | DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS;
-                mInfo.type = Display.TYPE_BUILT_IN;
-                mInfo.touch = DisplayDeviceInfo.TOUCH_NONE;
-            }
-            return mInfo;
-        }
-    }
-}
diff --git a/services/java/com/android/server/display/VirtualDisplayAdapter.java b/services/java/com/android/server/display/VirtualDisplayAdapter.java
deleted file mode 100644
index 46d473c..0000000
--- a/services/java/com/android/server/display/VirtualDisplayAdapter.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright (C) 2013 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.display;
-
-import android.content.Context;
-import android.hardware.display.DisplayManager;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.IBinder.DeathRecipient;
-import android.os.RemoteException;
-import android.util.ArrayMap;
-import android.util.Slog;
-import android.view.Display;
-import android.view.Surface;
-import android.view.SurfaceControl;
-
-/**
- * A display adapter that provides virtual displays on behalf of applications.
- * <p>
- * Display adapters are guarded by the {@link DisplayManagerService.SyncRoot} lock.
- * </p>
- */
-final class VirtualDisplayAdapter extends DisplayAdapter {
-    static final String TAG = "VirtualDisplayAdapter";
-    static final boolean DEBUG = false;
-
-    private final ArrayMap<IBinder, VirtualDisplayDevice> mVirtualDisplayDevices =
-            new ArrayMap<IBinder, VirtualDisplayDevice>();
-
-    // Called with SyncRoot lock held.
-    public VirtualDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
-            Context context, Handler handler, Listener listener) {
-        super(syncRoot, context, handler, listener, TAG);
-    }
-
-    public DisplayDevice createVirtualDisplayLocked(IBinder appToken,
-            int ownerUid, String ownerPackageName,
-            String name, int width, int height, int densityDpi, Surface surface, int flags) {
-        boolean secure = (flags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0;
-        IBinder displayToken = SurfaceControl.createDisplay(name, secure);
-        VirtualDisplayDevice device = new VirtualDisplayDevice(displayToken, appToken,
-                ownerUid, ownerPackageName, name, width, height, densityDpi, surface, flags);
-
-        try {
-            appToken.linkToDeath(device, 0);
-        } catch (RemoteException ex) {
-            device.destroyLocked();
-            return null;
-        }
-
-        mVirtualDisplayDevices.put(appToken, device);
-
-        // Return the display device without actually sending the event indicating
-        // that it was added.  The caller will handle it.
-        return device;
-    }
-
-    public DisplayDevice releaseVirtualDisplayLocked(IBinder appToken) {
-        VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
-        if (device != null) {
-            device.destroyLocked();
-            appToken.unlinkToDeath(device, 0);
-        }
-
-        // Return the display device that was removed without actually sending the
-        // event indicating that it was removed.  The caller will handle it.
-        return device;
-    }
-
-    private void handleBinderDiedLocked(IBinder appToken) {
-        VirtualDisplayDevice device = mVirtualDisplayDevices.remove(appToken);
-        if (device != null) {
-            Slog.i(TAG, "Virtual display device released because application token died: "
-                    + device.mOwnerPackageName);
-            device.destroyLocked();
-            sendDisplayDeviceEventLocked(device, DISPLAY_DEVICE_EVENT_REMOVED);
-        }
-    }
-
-    private final class VirtualDisplayDevice extends DisplayDevice
-            implements DeathRecipient {
-        private final IBinder mAppToken;
-        private final int mOwnerUid;
-        final String mOwnerPackageName;
-        private final String mName;
-        private final int mWidth;
-        private final int mHeight;
-        private final int mDensityDpi;
-        private final int mFlags;
-
-        private Surface mSurface;
-        private DisplayDeviceInfo mInfo;
-
-        public VirtualDisplayDevice(IBinder displayToken,
-                IBinder appToken, int ownerUid, String ownerPackageName,
-                String name, int width, int height, int densityDpi, Surface surface, int flags) {
-            super(VirtualDisplayAdapter.this, displayToken);
-            mAppToken = appToken;
-            mOwnerUid = ownerUid;
-            mOwnerPackageName = ownerPackageName;
-            mName = name;
-            mWidth = width;
-            mHeight = height;
-            mDensityDpi = densityDpi;
-            mSurface = surface;
-            mFlags = flags;
-        }
-
-        @Override
-        public void binderDied() {
-            synchronized (getSyncRoot()) {
-                if (mSurface != null) {
-                    handleBinderDiedLocked(mAppToken);
-                }
-            }
-        }
-
-        public void destroyLocked() {
-            if (mSurface != null) {
-                mSurface.release();
-                mSurface = null;
-            }
-            SurfaceControl.destroyDisplay(getDisplayTokenLocked());
-        }
-
-        @Override
-        public void performTraversalInTransactionLocked() {
-            if (mSurface != null) {
-                setSurfaceInTransactionLocked(mSurface);
-            }
-        }
-
-        @Override
-        public DisplayDeviceInfo getDisplayDeviceInfoLocked() {
-            if (mInfo == null) {
-                mInfo = new DisplayDeviceInfo();
-                mInfo.name = mName;
-                mInfo.width = mWidth;
-                mInfo.height = mHeight;
-                mInfo.refreshRate = 60;
-                mInfo.densityDpi = mDensityDpi;
-                mInfo.xDpi = mDensityDpi;
-                mInfo.yDpi = mDensityDpi;
-                mInfo.flags = 0;
-                if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC) == 0) {
-                    mInfo.flags |= DisplayDeviceInfo.FLAG_PRIVATE |
-                            DisplayDeviceInfo.FLAG_NEVER_BLANK;
-                }
-                if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE) != 0) {
-                    mInfo.flags |= DisplayDeviceInfo.FLAG_SECURE;
-                }
-                if ((mFlags & DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION) != 0) {
-                    mInfo.flags |= DisplayDeviceInfo.FLAG_PRESENTATION;
-                }
-                mInfo.type = Display.TYPE_VIRTUAL;
-                mInfo.touch = DisplayDeviceInfo.TOUCH_NONE;
-                mInfo.ownerUid = mOwnerUid;
-                mInfo.ownerPackageName = mOwnerPackageName;
-            }
-            return mInfo;
-        }
-    }
-}
diff --git a/services/java/com/android/server/dreams/DreamController.java b/services/java/com/android/server/dreams/DreamController.java
deleted file mode 100644
index 85ef33e..0000000
--- a/services/java/com/android/server/dreams/DreamController.java
+++ /dev/null
@@ -1,273 +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.server.dreams;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.IBinder.DeathRecipient;
-import android.os.UserHandle;
-import android.service.dreams.DreamService;
-import android.service.dreams.IDreamService;
-import android.util.Slog;
-import android.view.IWindowManager;
-import android.view.WindowManager;
-import android.view.WindowManagerGlobal;
-
-import java.io.PrintWriter;
-import java.util.NoSuchElementException;
-
-/**
- * Internal controller for starting and stopping the current dream and managing related state.
- *
- * Assumes all operations are called from the dream handler thread.
- */
-final class DreamController {
-    private static final String TAG = "DreamController";
-
-    // How long we wait for a newly bound dream to create the service connection
-    private static final int DREAM_CONNECTION_TIMEOUT = 5 * 1000;
-
-    private final Context mContext;
-    private final Handler mHandler;
-    private final Listener mListener;
-    private final IWindowManager mIWindowManager;
-
-    private final Intent mDreamingStartedIntent = new Intent(Intent.ACTION_DREAMING_STARTED)
-            .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-    private final Intent mDreamingStoppedIntent = new Intent(Intent.ACTION_DREAMING_STOPPED)
-            .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-
-    private final Intent mCloseNotificationShadeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
-
-    private DreamRecord mCurrentDream;
-
-    private final Runnable mStopUnconnectedDreamRunnable = new Runnable() {
-        @Override
-        public void run() {
-            if (mCurrentDream != null && mCurrentDream.mBound && !mCurrentDream.mConnected) {
-                Slog.w(TAG, "Bound dream did not connect in the time allotted");
-                stopDream();
-            }
-        }
-    };
-
-    public DreamController(Context context, Handler handler, Listener listener) {
-        mContext = context;
-        mHandler = handler;
-        mListener = listener;
-        mIWindowManager = WindowManagerGlobal.getWindowManagerService();
-    }
-
-    public void dump(PrintWriter pw) {
-        pw.println("Dreamland:");
-        if (mCurrentDream != null) {
-            pw.println("  mCurrentDream:");
-            pw.println("    mToken=" + mCurrentDream.mToken);
-            pw.println("    mName=" + mCurrentDream.mName);
-            pw.println("    mIsTest=" + mCurrentDream.mIsTest);
-            pw.println("    mUserId=" + mCurrentDream.mUserId);
-            pw.println("    mBound=" + mCurrentDream.mBound);
-            pw.println("    mService=" + mCurrentDream.mService);
-            pw.println("    mSentStartBroadcast=" + mCurrentDream.mSentStartBroadcast);
-        } else {
-            pw.println("  mCurrentDream: null");
-        }
-    }
-
-    public void startDream(Binder token, ComponentName name, boolean isTest, int userId) {
-        stopDream();
-
-        // Close the notification shade. Don't need to send to all, but better to be explicit.
-        mContext.sendBroadcastAsUser(mCloseNotificationShadeIntent, UserHandle.ALL);
-
-        Slog.i(TAG, "Starting dream: name=" + name + ", isTest=" + isTest + ", userId=" + userId);
-
-        mCurrentDream = new DreamRecord(token, name, isTest, userId);
-
-        try {
-            mIWindowManager.addWindowToken(token, WindowManager.LayoutParams.TYPE_DREAM);
-        } catch (RemoteException ex) {
-            Slog.e(TAG, "Unable to add window token for dream.", ex);
-            stopDream();
-            return;
-        }
-
-        Intent intent = new Intent(DreamService.SERVICE_INTERFACE);
-        intent.setComponent(name);
-        intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-        try {
-            if (!mContext.bindServiceAsUser(intent, mCurrentDream,
-                    Context.BIND_AUTO_CREATE, new UserHandle(userId))) {
-                Slog.e(TAG, "Unable to bind dream service: " + intent);
-                stopDream();
-                return;
-            }
-        } catch (SecurityException ex) {
-            Slog.e(TAG, "Unable to bind dream service: " + intent, ex);
-            stopDream();
-            return;
-        }
-
-        mCurrentDream.mBound = true;
-        mHandler.postDelayed(mStopUnconnectedDreamRunnable, DREAM_CONNECTION_TIMEOUT);
-    }
-
-    public void stopDream() {
-        if (mCurrentDream == null) {
-            return;
-        }
-
-        final DreamRecord oldDream = mCurrentDream;
-        mCurrentDream = null;
-        Slog.i(TAG, "Stopping dream: name=" + oldDream.mName
-                + ", isTest=" + oldDream.mIsTest + ", userId=" + oldDream.mUserId);
-
-        mHandler.removeCallbacks(mStopUnconnectedDreamRunnable);
-
-        if (oldDream.mSentStartBroadcast) {
-            mContext.sendBroadcastAsUser(mDreamingStoppedIntent, UserHandle.ALL);
-        }
-
-        if (oldDream.mService != null) {
-            // Tell the dream that it's being stopped so that
-            // it can shut down nicely before we yank its window token out from
-            // under it.
-            try {
-                oldDream.mService.detach();
-            } catch (RemoteException ex) {
-                // we don't care; this thing is on the way out
-            }
-
-            try {
-                oldDream.mService.asBinder().unlinkToDeath(oldDream, 0);
-            } catch (NoSuchElementException ex) {
-                // don't care
-            }
-            oldDream.mService = null;
-        }
-
-        if (oldDream.mBound) {
-            mContext.unbindService(oldDream);
-        }
-
-        try {
-            mIWindowManager.removeWindowToken(oldDream.mToken);
-        } catch (RemoteException ex) {
-            Slog.w(TAG, "Error removing window token for dream.", ex);
-        }
-
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                mListener.onDreamStopped(oldDream.mToken);
-            }
-        });
-    }
-
-    private void attach(IDreamService service) {
-        try {
-            service.asBinder().linkToDeath(mCurrentDream, 0);
-            service.attach(mCurrentDream.mToken);
-        } catch (RemoteException ex) {
-            Slog.e(TAG, "The dream service died unexpectedly.", ex);
-            stopDream();
-            return;
-        }
-
-        mCurrentDream.mService = service;
-
-        if (!mCurrentDream.mIsTest) {
-            mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL);
-            mCurrentDream.mSentStartBroadcast = true;
-        }
-    }
-
-    /**
-     * Callback interface to be implemented by the {@link DreamManagerService}.
-     */
-    public interface Listener {
-        void onDreamStopped(Binder token);
-    }
-
-    private final class DreamRecord implements DeathRecipient, ServiceConnection {
-        public final Binder mToken;
-        public final ComponentName mName;
-        public final boolean mIsTest;
-        public final int mUserId;
-
-        public boolean mBound;
-        public boolean mConnected;
-        public IDreamService mService;
-        public boolean mSentStartBroadcast;
-
-        public DreamRecord(Binder token, ComponentName name,
-                boolean isTest, int userId) {
-            mToken = token;
-            mName = name;
-            mIsTest = isTest;
-            mUserId  = userId;
-        }
-
-        // May be called on any thread.
-        @Override
-        public void binderDied() {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    mService = null;
-                    if (mCurrentDream == DreamRecord.this) {
-                        stopDream();
-                    }
-                }
-            });
-        }
-
-        // May be called on any thread.
-        @Override
-        public void onServiceConnected(ComponentName name, final IBinder service) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    mConnected = true;
-                    if (mCurrentDream == DreamRecord.this && mService == null) {
-                        attach(IDreamService.Stub.asInterface(service));
-                    }
-                }
-            });
-        }
-
-        // May be called on any thread.
-        @Override
-        public void onServiceDisconnected(ComponentName name) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    mService = null;
-                    if (mCurrentDream == DreamRecord.this) {
-                        stopDream();
-                    }
-                }
-            });
-        }
-    }
-}
\ No newline at end of file
diff --git a/services/java/com/android/server/dreams/DreamManagerService.java b/services/java/com/android/server/dreams/DreamManagerService.java
deleted file mode 100644
index b6e7781..0000000
--- a/services/java/com/android/server/dreams/DreamManagerService.java
+++ /dev/null
@@ -1,425 +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.server.dreams;
-
-import com.android.internal.util.DumpUtils;
-
-import android.app.ActivityManager;
-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.content.pm.PackageManager.NameNotFoundException;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.PowerManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.service.dreams.IDreamManager;
-import android.util.Slog;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-import libcore.util.Objects;
-
-/**
- * Service api for managing dreams.
- *
- * @hide
- */
-public final class DreamManagerService extends IDreamManager.Stub {
-    private static final boolean DEBUG = false;
-    private static final String TAG = "DreamManagerService";
-
-    private final Object mLock = new Object();
-
-    private final Context mContext;
-    private final DreamHandler mHandler;
-    private final DreamController mController;
-    private final PowerManager mPowerManager;
-
-    private Binder mCurrentDreamToken;
-    private ComponentName mCurrentDreamName;
-    private int mCurrentDreamUserId;
-    private boolean mCurrentDreamIsTest;
-
-    public DreamManagerService(Context context, Handler mainHandler) {
-        mContext = context;
-        mHandler = new DreamHandler(mainHandler.getLooper());
-        mController = new DreamController(context, mHandler, mControllerListener);
-
-        mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
-    }
-
-    public void systemRunning() {
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                synchronized (mLock) {
-                    stopDreamLocked();
-                }
-            }
-        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump DreamManager from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("DREAM MANAGER (dumpsys dreams)");
-        pw.println();
-
-        pw.println("mCurrentDreamToken=" + mCurrentDreamToken);
-        pw.println("mCurrentDreamName=" + mCurrentDreamName);
-        pw.println("mCurrentDreamUserId=" + mCurrentDreamUserId);
-        pw.println("mCurrentDreamIsTest=" + mCurrentDreamIsTest);
-        pw.println();
-
-        DumpUtils.dumpAsync(mHandler, new DumpUtils.Dump() {
-            @Override
-            public void dump(PrintWriter pw) {
-                mController.dump(pw);
-            }
-        }, pw, 200);
-    }
-
-    @Override // Binder call
-    public ComponentName[] getDreamComponents() {
-        checkPermission(android.Manifest.permission.READ_DREAM_STATE);
-
-        final int userId = UserHandle.getCallingUserId();
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            return getDreamComponentsForUser(userId);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public void setDreamComponents(ComponentName[] componentNames) {
-        checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
-
-        final int userId = UserHandle.getCallingUserId();
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            Settings.Secure.putStringForUser(mContext.getContentResolver(),
-                    Settings.Secure.SCREENSAVER_COMPONENTS,
-                    componentsToString(componentNames),
-                    userId);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public ComponentName getDefaultDreamComponent() {
-        checkPermission(android.Manifest.permission.READ_DREAM_STATE);
-
-        final int userId = UserHandle.getCallingUserId();
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            String name = Settings.Secure.getStringForUser(mContext.getContentResolver(),
-                    Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT,
-                    userId);
-            return name == null ? null : ComponentName.unflattenFromString(name);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public boolean isDreaming() {
-        checkPermission(android.Manifest.permission.READ_DREAM_STATE);
-
-        synchronized (mLock) {
-            return mCurrentDreamToken != null && !mCurrentDreamIsTest;
-        }
-    }
-
-    @Override // Binder call
-    public void dream() {
-        checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            // Ask the power manager to nap.  It will eventually call back into
-            // startDream() if/when it is appropriate to start dreaming.
-            // Because napping could cause the screen to turn off immediately if the dream
-            // cannot be started, we keep one eye open and gently poke user activity.
-            long time = SystemClock.uptimeMillis();
-            mPowerManager.userActivity(time, true /*noChangeLights*/);
-            mPowerManager.nap(time);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public void testDream(ComponentName dream) {
-        checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
-
-        if (dream == null) {
-            throw new IllegalArgumentException("dream must not be null");
-        }
-
-        final int callingUserId = UserHandle.getCallingUserId();
-        final int currentUserId = ActivityManager.getCurrentUser();
-        if (callingUserId != currentUserId) {
-            // This check is inherently prone to races but at least it's something.
-            Slog.w(TAG, "Aborted attempt to start a test dream while a different "
-                    + " user is active: callingUserId=" + callingUserId
-                    + ", currentUserId=" + currentUserId);
-            return;
-        }
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                startDreamLocked(dream, true /*isTest*/, callingUserId);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public void awaken() {
-        checkPermission(android.Manifest.permission.WRITE_DREAM_STATE);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            // Treat an explicit request to awaken as user activity so that the
-            // device doesn't immediately go to sleep if the timeout expired,
-            // for example when being undocked.
-            long time = SystemClock.uptimeMillis();
-            mPowerManager.userActivity(time, false /*noChangeLights*/);
-            stopDream();
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override // Binder call
-    public void finishSelf(IBinder token) {
-        // Requires no permission, called by Dream from an arbitrary process.
-        if (token == null) {
-            throw new IllegalArgumentException("token must not be null");
-        }
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            if (DEBUG) {
-                Slog.d(TAG, "Dream finished: " + token);
-            }
-
-            // Note that a dream finishing and self-terminating is not
-            // itself considered user activity.  If the dream is ending because
-            // the user interacted with the device then user activity will already
-            // have been poked so the device will stay awake a bit longer.
-            // If the dream is ending on its own for other reasons and no wake
-            // locks are held and the user activity timeout has expired then the
-            // device may simply go to sleep.
-            synchronized (mLock) {
-                if (mCurrentDreamToken == token) {
-                    stopDreamLocked();
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    /**
-     * Called by the power manager to start a dream.
-     */
-    public void startDream() {
-        int userId = ActivityManager.getCurrentUser();
-        ComponentName dream = chooseDreamForUser(userId);
-        if (dream != null) {
-            synchronized (mLock) {
-                startDreamLocked(dream, false /*isTest*/, userId);
-            }
-        }
-    }
-
-    /**
-     * Called by the power manager to stop a dream.
-     */
-    public void stopDream() {
-        synchronized (mLock) {
-            stopDreamLocked();
-        }
-    }
-
-    private ComponentName chooseDreamForUser(int userId) {
-        ComponentName[] dreams = getDreamComponentsForUser(userId);
-        return dreams != null && dreams.length != 0 ? dreams[0] : null;
-    }
-
-    private ComponentName[] getDreamComponentsForUser(int userId) {
-        String names = Settings.Secure.getStringForUser(mContext.getContentResolver(),
-                Settings.Secure.SCREENSAVER_COMPONENTS,
-                userId);
-        ComponentName[] components = componentsFromString(names);
-
-        // first, ensure components point to valid services
-        List<ComponentName> validComponents = new ArrayList<ComponentName>();
-        if (components != null) {
-            for (ComponentName component : components) {
-                if (serviceExists(component)) {
-                    validComponents.add(component);
-                } else {
-                    Slog.w(TAG, "Dream " + component + " does not exist");
-                }
-            }
-        }
-
-        // fallback to the default dream component if necessary
-        if (validComponents.isEmpty()) {
-            ComponentName defaultDream = getDefaultDreamComponent();
-            if (defaultDream != null) {
-                Slog.w(TAG, "Falling back to default dream " + defaultDream);
-                validComponents.add(defaultDream);
-            }
-        }
-        return validComponents.toArray(new ComponentName[validComponents.size()]);
-    }
-
-    private boolean serviceExists(ComponentName name) {
-        try {
-            return name != null && mContext.getPackageManager().getServiceInfo(name, 0) != null;
-        } catch (NameNotFoundException e) {
-            return false;
-        }
-    }
-
-    private void startDreamLocked(final ComponentName name,
-            final boolean isTest, final int userId) {
-        if (Objects.equal(mCurrentDreamName, name)
-                && mCurrentDreamIsTest == isTest
-                && mCurrentDreamUserId == userId) {
-            return;
-        }
-
-        stopDreamLocked();
-
-        if (DEBUG) Slog.i(TAG, "Entering dreamland.");
-
-        final Binder newToken = new Binder();
-        mCurrentDreamToken = newToken;
-        mCurrentDreamName = name;
-        mCurrentDreamIsTest = isTest;
-        mCurrentDreamUserId = userId;
-
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                mController.startDream(newToken, name, isTest, userId);
-            }
-        });
-    }
-
-    private void stopDreamLocked() {
-        if (mCurrentDreamToken != null) {
-            if (DEBUG) Slog.i(TAG, "Leaving dreamland.");
-
-            cleanupDreamLocked();
-
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    mController.stopDream();
-                }
-            });
-        }
-    }
-
-    private void cleanupDreamLocked() {
-        mCurrentDreamToken = null;
-        mCurrentDreamName = null;
-        mCurrentDreamIsTest = false;
-        mCurrentDreamUserId = 0;
-    }
-
-    private void checkPermission(String permission) {
-        if (mContext.checkCallingOrSelfPermission(permission)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
-                    + ", must have permission " + permission);
-        }
-    }
-
-    private static String componentsToString(ComponentName[] componentNames) {
-        StringBuilder names = new StringBuilder();
-        if (componentNames != null) {
-            for (ComponentName componentName : componentNames) {
-                if (names.length() > 0) {
-                    names.append(',');
-                }
-                names.append(componentName.flattenToString());
-            }
-        }
-        return names.toString();
-    }
-
-    private static ComponentName[] componentsFromString(String names) {
-        if (names == null) {
-            return null;
-        }
-        String[] namesArray = names.split(",");
-        ComponentName[] componentNames = new ComponentName[namesArray.length];
-        for (int i = 0; i < namesArray.length; i++) {
-            componentNames[i] = ComponentName.unflattenFromString(namesArray[i]);
-        }
-        return componentNames;
-    }
-
-    private final DreamController.Listener mControllerListener = new DreamController.Listener() {
-        @Override
-        public void onDreamStopped(Binder token) {
-            synchronized (mLock) {
-                if (mCurrentDreamToken == token) {
-                    cleanupDreamLocked();
-                }
-            }
-        }
-    };
-
-    /**
-     * Handler for asynchronous operations performed by the dream manager.
-     * Ensures operations to {@link DreamController} are single-threaded.
-     */
-    private final class DreamHandler extends Handler {
-        public DreamHandler(Looper looper) {
-            super(looper, null, true /*async*/);
-        }
-    }
-}
diff --git a/services/java/com/android/server/firewall/IntentFirewall.java b/services/java/com/android/server/firewall/IntentFirewall.java
deleted file mode 100644
index aaa0b58..0000000
--- a/services/java/com/android/server/firewall/IntentFirewall.java
+++ /dev/null
@@ -1,601 +0,0 @@
-/*
- * Copyright (C) 2013 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.firewall;
-
-import android.app.AppGlobals;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.IPackageManager;
-import android.content.pm.PackageManager;
-import android.os.Environment;
-import android.os.FileObserver;
-import android.os.Handler;
-import android.os.Message;
-import android.os.RemoteException;
-import android.util.ArrayMap;
-import android.util.Slog;
-import android.util.Xml;
-import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.XmlUtils;
-import com.android.server.EventLogTags;
-import com.android.server.IntentResolver;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-public class IntentFirewall {
-    static final String TAG = "IntentFirewall";
-
-    // e.g. /data/system/ifw or /data/secure/system/ifw
-    private static final File RULES_DIR = new File(Environment.getSystemSecureDirectory(), "ifw");
-
-    private static final int LOG_PACKAGES_MAX_LENGTH = 150;
-    private static final int LOG_PACKAGES_SUFFICIENT_LENGTH = 125;
-
-    private static final String TAG_RULES = "rules";
-    private static final String TAG_ACTIVITY = "activity";
-    private static final String TAG_SERVICE = "service";
-    private static final String TAG_BROADCAST = "broadcast";
-
-    private static final int TYPE_ACTIVITY = 0;
-    private static final int TYPE_BROADCAST = 1;
-    private static final int TYPE_SERVICE = 2;
-
-    private static final HashMap<String, FilterFactory> factoryMap;
-
-    private final AMSInterface mAms;
-
-    private final RuleObserver mObserver;
-
-    private FirewallIntentResolver mActivityResolver = new FirewallIntentResolver();
-    private FirewallIntentResolver mBroadcastResolver = new FirewallIntentResolver();
-    private FirewallIntentResolver mServiceResolver = new FirewallIntentResolver();
-
-    static {
-        FilterFactory[] factories = new FilterFactory[] {
-                AndFilter.FACTORY,
-                OrFilter.FACTORY,
-                NotFilter.FACTORY,
-
-                StringFilter.ACTION,
-                StringFilter.COMPONENT,
-                StringFilter.COMPONENT_NAME,
-                StringFilter.COMPONENT_PACKAGE,
-                StringFilter.DATA,
-                StringFilter.HOST,
-                StringFilter.MIME_TYPE,
-                StringFilter.SCHEME,
-                StringFilter.PATH,
-                StringFilter.SSP,
-
-                CategoryFilter.FACTORY,
-                SenderFilter.FACTORY,
-                SenderPermissionFilter.FACTORY,
-                PortFilter.FACTORY
-        };
-
-        // load factor ~= .75
-        factoryMap = new HashMap<String, FilterFactory>(factories.length * 4 / 3);
-        for (int i=0; i<factories.length; i++) {
-            FilterFactory factory = factories[i];
-            factoryMap.put(factory.getTagName(), factory);
-        }
-    }
-
-    public IntentFirewall(AMSInterface ams) {
-        mAms = ams;
-        File rulesDir = getRulesDir();
-        rulesDir.mkdirs();
-
-        readRulesDir(rulesDir);
-
-        mObserver = new RuleObserver(rulesDir);
-        mObserver.startWatching();
-    }
-
-    /**
-     * This is called from ActivityManager to check if a start activity intent should be allowed.
-     * It is assumed the caller is already holding the global ActivityManagerService lock.
-     */
-    public boolean checkStartActivity(Intent intent, int callerUid, int callerPid,
-            String resolvedType, ApplicationInfo resolvedApp) {
-        return checkIntent(mActivityResolver, intent.getComponent(), TYPE_ACTIVITY, intent,
-                callerUid, callerPid, resolvedType, resolvedApp.uid);
-    }
-
-    public boolean checkService(ComponentName resolvedService, Intent intent, int callerUid,
-            int callerPid, String resolvedType, ApplicationInfo resolvedApp) {
-        return checkIntent(mServiceResolver, resolvedService, TYPE_SERVICE, intent, callerUid,
-                callerPid, resolvedType, resolvedApp.uid);
-    }
-
-    public boolean checkBroadcast(Intent intent, int callerUid, int callerPid,
-            String resolvedType, int receivingUid) {
-        return checkIntent(mBroadcastResolver, intent.getComponent(), TYPE_BROADCAST, intent,
-                callerUid, callerPid, resolvedType, receivingUid);
-    }
-
-    public boolean checkIntent(FirewallIntentResolver resolver, ComponentName resolvedComponent,
-            int intentType, Intent intent, int callerUid, int callerPid, String resolvedType,
-            int receivingUid) {
-        boolean log = false;
-        boolean block = false;
-
-        // For the first pass, find all the rules that have at least one intent-filter or
-        // component-filter that matches this intent
-        List<Rule> candidateRules;
-        candidateRules = resolver.queryIntent(intent, resolvedType, false, 0);
-        if (candidateRules == null) {
-            candidateRules = new ArrayList<Rule>();
-        }
-        resolver.queryByComponent(resolvedComponent, candidateRules);
-
-        // For the second pass, try to match the potentially more specific conditions in each
-        // rule against the intent
-        for (int i=0; i<candidateRules.size(); i++) {
-            Rule rule = candidateRules.get(i);
-            if (rule.matches(this, resolvedComponent, intent, callerUid, callerPid, resolvedType,
-                    receivingUid)) {
-                block |= rule.getBlock();
-                log |= rule.getLog();
-
-                // if we've already determined that we should both block and log, there's no need
-                // to continue trying rules
-                if (block && log) {
-                    break;
-                }
-            }
-        }
-
-        if (log) {
-            logIntent(intentType, intent, callerUid, resolvedType);
-        }
-
-        return !block;
-    }
-
-    private static void logIntent(int intentType, Intent intent, int callerUid,
-            String resolvedType) {
-        // The component shouldn't be null, but let's double check just to be safe
-        ComponentName cn = intent.getComponent();
-        String shortComponent = null;
-        if (cn != null) {
-            shortComponent = cn.flattenToShortString();
-        }
-
-        String callerPackages = null;
-        int callerPackageCount = 0;
-        IPackageManager pm = AppGlobals.getPackageManager();
-        if (pm != null) {
-            try {
-                String[] callerPackagesArray = pm.getPackagesForUid(callerUid);
-                if (callerPackagesArray != null) {
-                    callerPackageCount = callerPackagesArray.length;
-                    callerPackages = joinPackages(callerPackagesArray);
-                }
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Remote exception while retrieving packages", ex);
-            }
-        }
-
-        EventLogTags.writeIfwIntentMatched(intentType, shortComponent, callerUid,
-                callerPackageCount, callerPackages, intent.getAction(), resolvedType,
-                intent.getDataString(), intent.getFlags());
-    }
-
-    /**
-     * Joins a list of package names such that the resulting string is no more than
-     * LOG_PACKAGES_MAX_LENGTH.
-     *
-     * Only full package names will be added to the result, unless every package is longer than the
-     * limit, in which case one of the packages will be truncated and added. In this case, an
-     * additional '-' character will be added to the end of the string, to denote the truncation.
-     *
-     * If it encounters a package that won't fit in the remaining space, it will continue on to the
-     * next package, unless the total length of the built string so far is greater than
-     * LOG_PACKAGES_SUFFICIENT_LENGTH, in which case it will stop and return what it has.
-     */
-    private static String joinPackages(String[] packages) {
-        boolean first = true;
-        StringBuilder sb = new StringBuilder();
-        for (int i=0; i<packages.length; i++) {
-            String pkg = packages[i];
-
-            // + 1 length for the comma. This logic technically isn't correct for the first entry,
-            // but it's not critical.
-            if (sb.length() + pkg.length() + 1 < LOG_PACKAGES_MAX_LENGTH) {
-                if (!first) {
-                    sb.append(',');
-                } else {
-                    first = false;
-                }
-                sb.append(pkg);
-            } else if (sb.length() >= LOG_PACKAGES_SUFFICIENT_LENGTH) {
-                return sb.toString();
-            }
-        }
-        if (sb.length() == 0 && packages.length > 0) {
-            String pkg = packages[0];
-            // truncating from the end - the last part of the package name is more likely to be
-            // interesting/unique
-            return pkg.substring(pkg.length() - LOG_PACKAGES_MAX_LENGTH + 1) + '-';
-        }
-        return null;
-    }
-
-    public static File getRulesDir() {
-        return RULES_DIR;
-    }
-
-    /**
-     * Reads rules from all xml files (*.xml) in the given directory, and replaces our set of rules
-     * with the newly read rules.
-     *
-     * We only check for files ending in ".xml", to allow for temporary files that are atomically
-     * renamed to .xml
-     *
-     * All calls to this method from the file observer come through a handler and are inherently
-     * serialized
-     */
-    private void readRulesDir(File rulesDir) {
-        FirewallIntentResolver[] resolvers = new FirewallIntentResolver[3];
-        for (int i=0; i<resolvers.length; i++) {
-            resolvers[i] = new FirewallIntentResolver();
-        }
-
-        File[] files = rulesDir.listFiles();
-        for (int i=0; i<files.length; i++) {
-            File file = files[i];
-
-            if (file.getName().endsWith(".xml")) {
-                readRules(file, resolvers);
-            }
-        }
-
-        Slog.i(TAG, "Read new rules (A:" + resolvers[TYPE_ACTIVITY].filterSet().size() +
-                " B:" + resolvers[TYPE_BROADCAST].filterSet().size() +
-                " S:" + resolvers[TYPE_SERVICE].filterSet().size() + ")");
-
-        synchronized (mAms.getAMSLock()) {
-            mActivityResolver = resolvers[TYPE_ACTIVITY];
-            mBroadcastResolver = resolvers[TYPE_BROADCAST];
-            mServiceResolver = resolvers[TYPE_SERVICE];
-        }
-    }
-
-    /**
-     * Reads rules from the given file and add them to the given resolvers
-     */
-    private void readRules(File rulesFile, FirewallIntentResolver[] resolvers) {
-        // some temporary lists to hold the rules while we parse the xml file, so that we can
-        // add the rules all at once, after we know there weren't any major structural problems
-        // with the xml file
-        List<List<Rule>> rulesByType = new ArrayList<List<Rule>>(3);
-        for (int i=0; i<3; i++) {
-            rulesByType.add(new ArrayList<Rule>());
-        }
-
-        FileInputStream fis;
-        try {
-            fis = new FileInputStream(rulesFile);
-        } catch (FileNotFoundException ex) {
-            // Nope, no rules. Nothing else to do!
-            return;
-        }
-
-        try {
-            XmlPullParser parser = Xml.newPullParser();
-
-            parser.setInput(fis, null);
-
-            XmlUtils.beginDocument(parser, TAG_RULES);
-
-            int outerDepth = parser.getDepth();
-            while (XmlUtils.nextElementWithin(parser, outerDepth)) {
-                int ruleType = -1;
-
-                String tagName = parser.getName();
-                if (tagName.equals(TAG_ACTIVITY)) {
-                    ruleType = TYPE_ACTIVITY;
-                } else if (tagName.equals(TAG_BROADCAST)) {
-                    ruleType = TYPE_BROADCAST;
-                } else if (tagName.equals(TAG_SERVICE)) {
-                    ruleType = TYPE_SERVICE;
-                }
-
-                if (ruleType != -1) {
-                    Rule rule = new Rule();
-
-                    List<Rule> rules = rulesByType.get(ruleType);
-
-                    // if we get an error while parsing a particular rule, we'll just ignore
-                    // that rule and continue on with the next rule
-                    try {
-                        rule.readFromXml(parser);
-                    } catch (XmlPullParserException ex) {
-                        Slog.e(TAG, "Error reading an intent firewall rule from " + rulesFile, ex);
-                        continue;
-                    }
-
-                    rules.add(rule);
-                }
-            }
-        } catch (XmlPullParserException ex) {
-            // if there was an error outside of a specific rule, then there are probably
-            // structural problems with the xml file, and we should completely ignore it
-            Slog.e(TAG, "Error reading intent firewall rules from " + rulesFile, ex);
-            return;
-        } catch (IOException ex) {
-            Slog.e(TAG, "Error reading intent firewall rules from " + rulesFile, ex);
-            return;
-        } finally {
-            try {
-                fis.close();
-            } catch (IOException ex) {
-                Slog.e(TAG, "Error while closing " + rulesFile, ex);
-            }
-        }
-
-        for (int ruleType=0; ruleType<rulesByType.size(); ruleType++) {
-            List<Rule> rules = rulesByType.get(ruleType);
-            FirewallIntentResolver resolver = resolvers[ruleType];
-
-            for (int ruleIndex=0; ruleIndex<rules.size(); ruleIndex++) {
-                Rule rule = rules.get(ruleIndex);
-                for (int i=0; i<rule.getIntentFilterCount(); i++) {
-                    resolver.addFilter(rule.getIntentFilter(i));
-                }
-                for (int i=0; i<rule.getComponentFilterCount(); i++) {
-                    resolver.addComponentFilter(rule.getComponentFilter(i), rule);
-                }
-            }
-        }
-    }
-
-    static Filter parseFilter(XmlPullParser parser) throws IOException, XmlPullParserException {
-        String elementName = parser.getName();
-
-        FilterFactory factory = factoryMap.get(elementName);
-
-        if (factory == null) {
-            throw new XmlPullParserException("Unknown element in filter list: " + elementName);
-        }
-        return factory.newFilter(parser);
-    }
-
-    /**
-     * Represents a single activity/service/broadcast rule within one of the xml files.
-     *
-     * Rules are matched against an incoming intent in two phases. The goal of the first phase
-     * is to select a subset of rules that might match a given intent.
-     *
-     * For the first phase, we use a combination of intent filters (via an IntentResolver)
-     * and component filters to select which rules to check. If a rule has multiple intent or
-     * component filters, only a single filter must match for the rule to be passed on to the
-     * second phase.
-     *
-     * In the second phase, we check the specific conditions in each rule against the values in the
-     * intent. All top level conditions (but not filters) in the rule must match for the rule as a
-     * whole to match.
-     *
-     * If the rule matches, then we block or log the intent, as specified by the rule. If multiple
-     * rules match, we combine the block/log flags from any matching rule.
-     */
-    private static class Rule extends AndFilter {
-        private static final String TAG_INTENT_FILTER = "intent-filter";
-        private static final String TAG_COMPONENT_FILTER = "component-filter";
-        private static final String ATTR_NAME = "name";
-
-        private static final String ATTR_BLOCK = "block";
-        private static final String ATTR_LOG = "log";
-
-        private final ArrayList<FirewallIntentFilter> mIntentFilters =
-                new ArrayList<FirewallIntentFilter>(1);
-        private final ArrayList<ComponentName> mComponentFilters = new ArrayList<ComponentName>(0);
-        private boolean block;
-        private boolean log;
-
-        @Override
-        public Rule readFromXml(XmlPullParser parser) throws IOException, XmlPullParserException {
-            block = Boolean.parseBoolean(parser.getAttributeValue(null, ATTR_BLOCK));
-            log = Boolean.parseBoolean(parser.getAttributeValue(null, ATTR_LOG));
-
-            super.readFromXml(parser);
-            return this;
-        }
-
-        @Override
-        protected void readChild(XmlPullParser parser) throws IOException, XmlPullParserException {
-            String currentTag = parser.getName();
-
-            if (currentTag.equals(TAG_INTENT_FILTER)) {
-                FirewallIntentFilter intentFilter = new FirewallIntentFilter(this);
-                intentFilter.readFromXml(parser);
-                mIntentFilters.add(intentFilter);
-            } else if (currentTag.equals(TAG_COMPONENT_FILTER)) {
-                String componentStr = parser.getAttributeValue(null, ATTR_NAME);
-                if (componentStr == null) {
-                    throw new XmlPullParserException("Component name must be specified.",
-                            parser, null);
-                }
-
-                ComponentName componentName = ComponentName.unflattenFromString(componentStr);
-                if (componentName == null) {
-                    throw new XmlPullParserException("Invalid component name: " + componentStr);
-                }
-
-                mComponentFilters.add(componentName);
-            } else {
-                super.readChild(parser);
-            }
-        }
-
-        public int getIntentFilterCount() {
-            return mIntentFilters.size();
-        }
-
-        public FirewallIntentFilter getIntentFilter(int index) {
-            return mIntentFilters.get(index);
-        }
-
-        public int getComponentFilterCount() {
-            return mComponentFilters.size();
-        }
-
-        public ComponentName getComponentFilter(int index) {
-            return mComponentFilters.get(index);
-        }
-        public boolean getBlock() {
-            return block;
-        }
-
-        public boolean getLog() {
-            return log;
-        }
-    }
-
-    private static class FirewallIntentFilter extends IntentFilter {
-        private final Rule rule;
-
-        public FirewallIntentFilter(Rule rule) {
-            this.rule = rule;
-        }
-    }
-
-    private static class FirewallIntentResolver
-            extends IntentResolver<FirewallIntentFilter, Rule> {
-        @Override
-        protected boolean allowFilterResult(FirewallIntentFilter filter, List<Rule> dest) {
-            return !dest.contains(filter.rule);
-        }
-
-        @Override
-        protected boolean isPackageForFilter(String packageName, FirewallIntentFilter filter) {
-            return true;
-        }
-
-        @Override
-        protected FirewallIntentFilter[] newArray(int size) {
-            return new FirewallIntentFilter[size];
-        }
-
-        @Override
-        protected Rule newResult(FirewallIntentFilter filter, int match, int userId) {
-            return filter.rule;
-        }
-
-        @Override
-        protected void sortResults(List<Rule> results) {
-            // there's no need to sort the results
-            return;
-        }
-
-        public void queryByComponent(ComponentName componentName, List<Rule> candidateRules) {
-            Rule[] rules = mRulesByComponent.get(componentName);
-            if (rules != null) {
-                candidateRules.addAll(Arrays.asList(rules));
-            }
-        }
-
-        public void addComponentFilter(ComponentName componentName, Rule rule) {
-            Rule[] rules = mRulesByComponent.get(componentName);
-            rules = ArrayUtils.appendElement(Rule.class, rules, rule);
-            mRulesByComponent.put(componentName, rules);
-        }
-
-        private final ArrayMap<ComponentName, Rule[]> mRulesByComponent =
-                new ArrayMap<ComponentName, Rule[]>(0);
-    }
-
-    final Handler mHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            readRulesDir(getRulesDir());
-        }
-    };
-
-    /**
-     * Monitors for the creation/deletion/modification of any .xml files in the rule directory
-     */
-    private class RuleObserver extends FileObserver {
-        private static final int MONITORED_EVENTS = FileObserver.CREATE|FileObserver.MOVED_TO|
-                FileObserver.CLOSE_WRITE|FileObserver.DELETE|FileObserver.MOVED_FROM;
-
-        public RuleObserver(File monitoredDir) {
-            super(monitoredDir.getAbsolutePath(), MONITORED_EVENTS);
-        }
-
-        @Override
-        public void onEvent(int event, String path) {
-            if (path.endsWith(".xml")) {
-                // we wait 250ms before taking any action on an event, in order to dedup multiple
-                // events. E.g. a delete event followed by a create event followed by a subsequent
-                // write+close event
-                mHandler.removeMessages(0);
-                mHandler.sendEmptyMessageDelayed(0, 250);
-            }
-        }
-    }
-
-    /**
-     * This interface contains the methods we need from ActivityManagerService. This allows AMS to
-     * export these methods to us without making them public, and also makes it easier to test this
-     * component.
-     */
-    public interface AMSInterface {
-        int checkComponentPermission(String permission, int pid, int uid,
-                int owningUid, boolean exported);
-        Object getAMSLock();
-    }
-
-    /**
-     * Checks if the caller has access to a component
-     *
-     * @param permission If present, the caller must have this permission
-     * @param pid The pid of the caller
-     * @param uid The uid of the caller
-     * @param owningUid The uid of the application that owns the component
-     * @param exported Whether the component is exported
-     * @return True if the caller can access the described component
-     */
-    boolean checkComponentPermission(String permission, int pid, int uid, int owningUid,
-            boolean exported) {
-        return mAms.checkComponentPermission(permission, pid, uid, owningUid, exported) ==
-                PackageManager.PERMISSION_GRANTED;
-    }
-
-    boolean signaturesMatch(int uid1, int uid2) {
-        try {
-            IPackageManager pm = AppGlobals.getPackageManager();
-            return pm.checkUidSignatures(uid1, uid2) == PackageManager.SIGNATURE_MATCH;
-        } catch (RemoteException ex) {
-            Slog.e(TAG, "Remote exception while checking signatures", ex);
-            return false;
-        }
-    }
-
-}
diff --git a/services/java/com/android/server/input/InputApplicationHandle.java b/services/java/com/android/server/input/InputApplicationHandle.java
deleted file mode 100644
index 42c1052..0000000
--- a/services/java/com/android/server/input/InputApplicationHandle.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.android.server.input;
-
-/**
- * Functions as a handle for an application that can receive input.
- * Enables the native input dispatcher to refer indirectly to the window manager's
- * application window token.
- * @hide
- */
-public final class InputApplicationHandle {
-    // Pointer to the native input application handle.
-    // This field is lazily initialized via JNI.
-    @SuppressWarnings("unused")
-    private int ptr;
-
-    // The window manager's application window token.
-    public final Object appWindowToken;
-
-    // Application name.
-    public String name;
-
-    // Dispatching timeout.
-    public long dispatchingTimeoutNanos;
-
-    private native void nativeDispose();
-
-    public InputApplicationHandle(Object appWindowToken) {
-        this.appWindowToken = appWindowToken;
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            nativeDispose();
-        } finally {
-            super.finalize();
-        }
-    }
-}
diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java
deleted file mode 100644
index 3145805..0000000
--- a/services/java/com/android/server/input/InputManagerService.java
+++ /dev/null
@@ -1,1642 +0,0 @@
-/*
- * Copyright (C) 2010 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.input;
-
-import com.android.internal.R;
-import com.android.internal.util.XmlUtils;
-import com.android.server.Watchdog;
-import com.android.server.display.DisplayManagerService;
-import com.android.server.display.DisplayViewport;
-
-import org.xmlpull.v1.XmlPullParser;
-
-import android.Manifest;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.res.Resources;
-import android.content.res.Resources.NotFoundException;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
-import android.database.ContentObserver;
-import android.hardware.input.IInputDevicesChangedListener;
-import android.hardware.input.IInputManager;
-import android.hardware.input.InputManager;
-import android.hardware.input.KeyboardLayout;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.MessageQueue;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.Xml;
-import android.view.IInputFilter;
-import android.view.IInputFilterHost;
-import android.view.InputChannel;
-import android.view.InputDevice;
-import android.view.InputEvent;
-import android.view.KeyEvent;
-import android.view.PointerIcon;
-import android.view.ViewConfiguration;
-import android.view.WindowManagerPolicy;
-import android.widget.Toast;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-
-import libcore.io.Streams;
-import libcore.util.Objects;
-
-/*
- * Wraps the C++ InputManager and provides its callbacks.
- */
-public class InputManagerService extends IInputManager.Stub
-        implements Watchdog.Monitor, DisplayManagerService.InputManagerFuncs {
-    static final String TAG = "InputManager";
-    static final boolean DEBUG = false;
-
-    private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
-
-    private static final int MSG_DELIVER_INPUT_DEVICES_CHANGED = 1;
-    private static final int MSG_SWITCH_KEYBOARD_LAYOUT = 2;
-    private static final int MSG_RELOAD_KEYBOARD_LAYOUTS = 3;
-    private static final int MSG_UPDATE_KEYBOARD_LAYOUTS = 4;
-    private static final int MSG_RELOAD_DEVICE_ALIASES = 5;
-
-    // Pointer to native input manager service object.
-    private final int mPtr;
-
-    private final Context mContext;
-    private final InputManagerHandler mHandler;
-
-    private WindowManagerCallbacks mWindowManagerCallbacks;
-    private WiredAccessoryCallbacks mWiredAccessoryCallbacks;
-    private boolean mSystemReady;
-    private NotificationManager mNotificationManager;
-
-    // Persistent data store.  Must be locked each time during use.
-    private final PersistentDataStore mDataStore = new PersistentDataStore();
-
-    // List of currently registered input devices changed listeners by process id.
-    private Object mInputDevicesLock = new Object();
-    private boolean mInputDevicesChangedPending; // guarded by mInputDevicesLock
-    private InputDevice[] mInputDevices = new InputDevice[0];
-    private final SparseArray<InputDevicesChangedListenerRecord> mInputDevicesChangedListeners =
-            new SparseArray<InputDevicesChangedListenerRecord>(); // guarded by mInputDevicesLock
-    private final ArrayList<InputDevicesChangedListenerRecord>
-            mTempInputDevicesChangedListenersToNotify =
-                    new ArrayList<InputDevicesChangedListenerRecord>(); // handler thread only
-    private final ArrayList<InputDevice>
-            mTempFullKeyboards = new ArrayList<InputDevice>(); // handler thread only
-    private boolean mKeyboardLayoutNotificationShown;
-    private PendingIntent mKeyboardLayoutIntent;
-    private Toast mSwitchedKeyboardLayoutToast;
-
-    // State for vibrator tokens.
-    private Object mVibratorLock = new Object();
-    private HashMap<IBinder, VibratorToken> mVibratorTokens =
-            new HashMap<IBinder, VibratorToken>();
-    private int mNextVibratorTokenValue;
-
-    // State for the currently installed input filter.
-    final Object mInputFilterLock = new Object();
-    IInputFilter mInputFilter; // guarded by mInputFilterLock
-    InputFilterHost mInputFilterHost; // guarded by mInputFilterLock
-
-    private static native int nativeInit(InputManagerService service,
-            Context context, MessageQueue messageQueue);
-    private static native void nativeStart(int ptr);
-    private static native void nativeSetDisplayViewport(int ptr, boolean external,
-            int displayId, int rotation,
-            int logicalLeft, int logicalTop, int logicalRight, int logicalBottom,
-            int physicalLeft, int physicalTop, int physicalRight, int physicalBottom,
-            int deviceWidth, int deviceHeight);
-
-    private static native int nativeGetScanCodeState(int ptr,
-            int deviceId, int sourceMask, int scanCode);
-    private static native int nativeGetKeyCodeState(int ptr,
-            int deviceId, int sourceMask, int keyCode);
-    private static native int nativeGetSwitchState(int ptr,
-            int deviceId, int sourceMask, int sw);
-    private static native boolean nativeHasKeys(int ptr,
-            int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
-    private static native void nativeRegisterInputChannel(int ptr, InputChannel inputChannel,
-            InputWindowHandle inputWindowHandle, boolean monitor);
-    private static native void nativeUnregisterInputChannel(int ptr, InputChannel inputChannel);
-    private static native void nativeSetInputFilterEnabled(int ptr, boolean enable);
-    private static native int nativeInjectInputEvent(int ptr, InputEvent event,
-            int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
-            int policyFlags);
-    private static native void nativeSetInputWindows(int ptr, InputWindowHandle[] windowHandles);
-    private static native void nativeSetInputDispatchMode(int ptr, boolean enabled, boolean frozen);
-    private static native void nativeSetSystemUiVisibility(int ptr, int visibility);
-    private static native void nativeSetFocusedApplication(int ptr,
-            InputApplicationHandle application);
-    private static native boolean nativeTransferTouchFocus(int ptr,
-            InputChannel fromChannel, InputChannel toChannel);
-    private static native void nativeSetPointerSpeed(int ptr, int speed);
-    private static native void nativeSetShowTouches(int ptr, boolean enabled);
-    private static native void nativeVibrate(int ptr, int deviceId, long[] pattern,
-            int repeat, int token);
-    private static native void nativeCancelVibrate(int ptr, int deviceId, int token);
-    private static native void nativeReloadKeyboardLayouts(int ptr);
-    private static native void nativeReloadDeviceAliases(int ptr);
-    private static native String nativeDump(int ptr);
-    private static native void nativeMonitor(int ptr);
-
-    // Input event injection constants defined in InputDispatcher.h.
-    private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
-    private static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
-    private static final int INPUT_EVENT_INJECTION_FAILED = 2;
-    private static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
-
-    // Maximum number of milliseconds to wait for input event injection.
-    private static final int INJECTION_TIMEOUT_MILLIS = 30 * 1000;
-
-    // Key states (may be returned by queries about the current state of a
-    // particular key code, scan code or switch).
-
-    /** The key state is unknown or the requested key itself is not supported. */
-    public static final int KEY_STATE_UNKNOWN = -1;
-
-    /** The key is up. /*/
-    public static final int KEY_STATE_UP = 0;
-
-    /** The key is down. */
-    public static final int KEY_STATE_DOWN = 1;
-
-    /** The key is down but is a virtual key press that is being emulated by the system. */
-    public static final int KEY_STATE_VIRTUAL = 2;
-
-    /** Scan code: Mouse / trackball button. */
-    public static final int BTN_MOUSE = 0x110;
-
-    // Switch code values must match bionic/libc/kernel/common/linux/input.h
-    /** Switch code: Lid switch.  When set, lid is shut. */
-    public static final int SW_LID = 0x00;
-
-    /** Switch code: Keypad slide.  When set, keyboard is exposed. */
-    public static final int SW_KEYPAD_SLIDE = 0x0a;
-
-    /** Switch code: Headphone.  When set, headphone is inserted. */
-    public static final int SW_HEADPHONE_INSERT = 0x02;
-
-    /** Switch code: Microphone.  When set, microphone is inserted. */
-    public static final int SW_MICROPHONE_INSERT = 0x04;
-
-    /** Switch code: Headphone/Microphone Jack.  When set, something is inserted. */
-    public static final int SW_JACK_PHYSICAL_INSERT = 0x07;
-
-    public static final int SW_LID_BIT = 1 << SW_LID;
-    public static final int SW_KEYPAD_SLIDE_BIT = 1 << SW_KEYPAD_SLIDE;
-    public static final int SW_HEADPHONE_INSERT_BIT = 1 << SW_HEADPHONE_INSERT;
-    public static final int SW_MICROPHONE_INSERT_BIT = 1 << SW_MICROPHONE_INSERT;
-    public static final int SW_JACK_PHYSICAL_INSERT_BIT = 1 << SW_JACK_PHYSICAL_INSERT;
-    public static final int SW_JACK_BITS =
-            SW_HEADPHONE_INSERT_BIT | SW_MICROPHONE_INSERT_BIT | SW_JACK_PHYSICAL_INSERT_BIT;
-
-    /** Whether to use the dev/input/event or uevent subsystem for the audio jack. */
-    final boolean mUseDevInputEventForAudioJack;
-
-    public InputManagerService(Context context, Handler handler) {
-        this.mContext = context;
-        this.mHandler = new InputManagerHandler(handler.getLooper());
-
-        mUseDevInputEventForAudioJack =
-                context.getResources().getBoolean(R.bool.config_useDevInputEventForAudioJack);
-        Slog.i(TAG, "Initializing input manager, mUseDevInputEventForAudioJack="
-                + mUseDevInputEventForAudioJack);
-        mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());
-    }
-
-    public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks) {
-        mWindowManagerCallbacks = callbacks;
-    }
-
-    public void setWiredAccessoryCallbacks(WiredAccessoryCallbacks callbacks) {
-        mWiredAccessoryCallbacks = callbacks;
-    }
-
-    public void start() {
-        Slog.i(TAG, "Starting input manager");
-        nativeStart(mPtr);
-
-        // Add ourself to the Watchdog monitors.
-        Watchdog.getInstance().addMonitor(this);
-
-        registerPointerSpeedSettingObserver();
-        registerShowTouchesSettingObserver();
-
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                updatePointerSpeedFromSettings();
-                updateShowTouchesFromSettings();
-            }
-        }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
-
-        updatePointerSpeedFromSettings();
-        updateShowTouchesFromSettings();
-    }
-
-    // TODO(BT) Pass in paramter for bluetooth system
-    public void systemRunning() {
-        if (DEBUG) {
-            Slog.d(TAG, "System ready.");
-        }
-        mNotificationManager = (NotificationManager)mContext.getSystemService(
-                Context.NOTIFICATION_SERVICE);
-        mSystemReady = true;
-
-        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
-        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
-        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
-        filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
-        filter.addDataScheme("package");
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                updateKeyboardLayouts();
-            }
-        }, filter, null, mHandler);
-
-        filter = new IntentFilter(BluetoothDevice.ACTION_ALIAS_CHANGED);
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                reloadDeviceAliases();
-            }
-        }, filter, null, mHandler);
-
-        mHandler.sendEmptyMessage(MSG_RELOAD_DEVICE_ALIASES);
-        mHandler.sendEmptyMessage(MSG_UPDATE_KEYBOARD_LAYOUTS);
-    }
-
-    private void reloadKeyboardLayouts() {
-        if (DEBUG) {
-            Slog.d(TAG, "Reloading keyboard layouts.");
-        }
-        nativeReloadKeyboardLayouts(mPtr);
-    }
-
-    private void reloadDeviceAliases() {
-        if (DEBUG) {
-            Slog.d(TAG, "Reloading device names.");
-        }
-        nativeReloadDeviceAliases(mPtr);
-    }
-
-    @Override
-    public void setDisplayViewports(DisplayViewport defaultViewport,
-            DisplayViewport externalTouchViewport) {
-        if (defaultViewport.valid) {
-            setDisplayViewport(false, defaultViewport);
-        }
-
-        if (externalTouchViewport.valid) {
-            setDisplayViewport(true, externalTouchViewport);
-        } else if (defaultViewport.valid) {
-            setDisplayViewport(true, defaultViewport);
-        }
-    }
-
-    private void setDisplayViewport(boolean external, DisplayViewport viewport) {
-        nativeSetDisplayViewport(mPtr, external,
-                viewport.displayId, viewport.orientation,
-                viewport.logicalFrame.left, viewport.logicalFrame.top,
-                viewport.logicalFrame.right, viewport.logicalFrame.bottom,
-                viewport.physicalFrame.left, viewport.physicalFrame.top,
-                viewport.physicalFrame.right, viewport.physicalFrame.bottom,
-                viewport.deviceWidth, viewport.deviceHeight);
-    }
-
-    /**
-     * Gets the current state of a key or button by key code.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param keyCode The key code to check.
-     * @return The key state.
-     */
-    public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
-        return nativeGetKeyCodeState(mPtr, deviceId, sourceMask, keyCode);
-    }
-
-    /**
-     * Gets the current state of a key or button by scan code.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param scanCode The scan code to check.
-     * @return The key state.
-     */
-    public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
-        return nativeGetScanCodeState(mPtr, deviceId, sourceMask, scanCode);
-    }
-    
-    /**
-     * Gets the current state of a switch by switch code.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param switchCode The switch code to check.
-     * @return The switch state.
-     */
-    public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
-        return nativeGetSwitchState(mPtr, deviceId, sourceMask, switchCode);
-    }
-
-    /**
-     * Determines whether the specified key codes are supported by a particular device.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param keyCodes The array of key codes to check.
-     * @param keyExists An array at least as large as keyCodes whose entries will be set
-     * to true or false based on the presence or absence of support for the corresponding
-     * key codes.
-     * @return True if the lookup was successful, false otherwise.
-     */
-    @Override // Binder call
-    public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
-        if (keyCodes == null) {
-            throw new IllegalArgumentException("keyCodes must not be null.");
-        }
-        if (keyExists == null || keyExists.length < keyCodes.length) {
-            throw new IllegalArgumentException("keyExists must not be null and must be at "
-                    + "least as large as keyCodes.");
-        }
-        
-        return nativeHasKeys(mPtr, deviceId, sourceMask, keyCodes, keyExists);
-    }
-    
-    /**
-     * Creates an input channel that will receive all input from the input dispatcher.
-     * @param inputChannelName The input channel name.
-     * @return The input channel.
-     */
-    public InputChannel monitorInput(String inputChannelName) {
-        if (inputChannelName == null) {
-            throw new IllegalArgumentException("inputChannelName must not be null.");
-        }
-        
-        InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
-        nativeRegisterInputChannel(mPtr, inputChannels[0], null, true);
-        inputChannels[0].dispose(); // don't need to retain the Java object reference
-        return inputChannels[1];
-    }
-
-    /**
-     * Registers an input channel so that it can be used as an input event target.
-     * @param inputChannel The input channel to register.
-     * @param inputWindowHandle The handle of the input window associated with the
-     * input channel, or null if none.
-     */
-    public void registerInputChannel(InputChannel inputChannel,
-            InputWindowHandle inputWindowHandle) {
-        if (inputChannel == null) {
-            throw new IllegalArgumentException("inputChannel must not be null.");
-        }
-        
-        nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, false);
-    }
-    
-    /**
-     * Unregisters an input channel.
-     * @param inputChannel The input channel to unregister.
-     */
-    public void unregisterInputChannel(InputChannel inputChannel) {
-        if (inputChannel == null) {
-            throw new IllegalArgumentException("inputChannel must not be null.");
-        }
-        
-        nativeUnregisterInputChannel(mPtr, inputChannel);
-    }
-
-    /**
-     * Sets an input filter that will receive all input events before they are dispatched.
-     * The input filter may then reinterpret input events or inject new ones.
-     *
-     * To ensure consistency, the input dispatcher automatically drops all events
-     * in progress whenever an input filter is installed or uninstalled.  After an input
-     * filter is uninstalled, it can no longer send input events unless it is reinstalled.
-     * Any events it attempts to send after it has been uninstalled will be dropped.
-     *
-     * @param filter The input filter, or null to remove the current filter.
-     */
-    public void setInputFilter(IInputFilter filter) {
-        synchronized (mInputFilterLock) {
-            final IInputFilter oldFilter = mInputFilter;
-            if (oldFilter == filter) {
-                return; // nothing to do
-            }
-
-            if (oldFilter != null) {
-                mInputFilter = null;
-                mInputFilterHost.disconnectLocked();
-                mInputFilterHost = null;
-                try {
-                    oldFilter.uninstall();
-                } catch (RemoteException re) {
-                    /* ignore */
-                }
-            }
-
-            if (filter != null) {
-                mInputFilter = filter;
-                mInputFilterHost = new InputFilterHost();
-                try {
-                    filter.install(mInputFilterHost);
-                } catch (RemoteException re) {
-                    /* ignore */
-                }
-            }
-
-            nativeSetInputFilterEnabled(mPtr, filter != null);
-        }
-    }
-
-    @Override // Binder call
-    public boolean injectInputEvent(InputEvent event, int mode) {
-        if (event == null) {
-            throw new IllegalArgumentException("event must not be null");
-        }
-        if (mode != InputManager.INJECT_INPUT_EVENT_MODE_ASYNC
-                && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH
-                && mode != InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_RESULT) {
-            throw new IllegalArgumentException("mode is invalid");
-        }
-
-        final int pid = Binder.getCallingPid();
-        final int uid = Binder.getCallingUid();
-        final long ident = Binder.clearCallingIdentity();
-        final int result;
-        try {
-            result = nativeInjectInputEvent(mPtr, event, pid, uid, mode,
-                    INJECTION_TIMEOUT_MILLIS, WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-        switch (result) {
-            case INPUT_EVENT_INJECTION_PERMISSION_DENIED:
-                Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");
-                throw new SecurityException(
-                        "Injecting to another application requires INJECT_EVENTS permission");
-            case INPUT_EVENT_INJECTION_SUCCEEDED:
-                return true;
-            case INPUT_EVENT_INJECTION_TIMED_OUT:
-                Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");
-                return false;
-            case INPUT_EVENT_INJECTION_FAILED:
-            default:
-                Slog.w(TAG, "Input event injection from pid " + pid + " failed.");
-                return false;
-        }
-    }
-
-    /**
-     * Gets information about the input device with the specified id.
-     * @param deviceId The device id.
-     * @return The input device or null if not found.
-     */
-    @Override // Binder call
-    public InputDevice getInputDevice(int deviceId) {
-        synchronized (mInputDevicesLock) {
-            final int count = mInputDevices.length;
-            for (int i = 0; i < count; i++) {
-                final InputDevice inputDevice = mInputDevices[i];
-                if (inputDevice.getId() == deviceId) {
-                    return inputDevice;
-                }
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Gets the ids of all input devices in the system.
-     * @return The input device ids.
-     */
-    @Override // Binder call
-    public int[] getInputDeviceIds() {
-        synchronized (mInputDevicesLock) {
-            final int count = mInputDevices.length;
-            int[] ids = new int[count];
-            for (int i = 0; i < count; i++) {
-                ids[i] = mInputDevices[i].getId();
-            }
-            return ids;
-        }
-    }
-
-    /**
-     * Gets all input devices in the system.
-     * @return The array of input devices.
-     */
-    public InputDevice[] getInputDevices() {
-        synchronized (mInputDevicesLock) {
-            return mInputDevices;
-        }
-    }
-
-    @Override // Binder call
-    public void registerInputDevicesChangedListener(IInputDevicesChangedListener listener) {
-        if (listener == null) {
-            throw new IllegalArgumentException("listener must not be null");
-        }
-
-        synchronized (mInputDevicesLock) {
-            int callingPid = Binder.getCallingPid();
-            if (mInputDevicesChangedListeners.get(callingPid) != null) {
-                throw new SecurityException("The calling process has already "
-                        + "registered an InputDevicesChangedListener.");
-            }
-
-            InputDevicesChangedListenerRecord record =
-                    new InputDevicesChangedListenerRecord(callingPid, listener);
-            try {
-                IBinder binder = listener.asBinder();
-                binder.linkToDeath(record, 0);
-            } catch (RemoteException ex) {
-                // give up
-                throw new RuntimeException(ex);
-            }
-
-            mInputDevicesChangedListeners.put(callingPid, record);
-        }
-    }
-
-    private void onInputDevicesChangedListenerDied(int pid) {
-        synchronized (mInputDevicesLock) {
-            mInputDevicesChangedListeners.remove(pid);
-        }
-    }
-
-    // Must be called on handler.
-    private void deliverInputDevicesChanged(InputDevice[] oldInputDevices) {
-        // Scan for changes.
-        int numFullKeyboardsAdded = 0;
-        mTempInputDevicesChangedListenersToNotify.clear();
-        mTempFullKeyboards.clear();
-        final int numListeners;
-        final int[] deviceIdAndGeneration;
-        synchronized (mInputDevicesLock) {
-            if (!mInputDevicesChangedPending) {
-                return;
-            }
-            mInputDevicesChangedPending = false;
-
-            numListeners = mInputDevicesChangedListeners.size();
-            for (int i = 0; i < numListeners; i++) {
-                mTempInputDevicesChangedListenersToNotify.add(
-                        mInputDevicesChangedListeners.valueAt(i));
-            }
-
-            final int numDevices = mInputDevices.length;
-            deviceIdAndGeneration = new int[numDevices * 2];
-            for (int i = 0; i < numDevices; i++) {
-                final InputDevice inputDevice = mInputDevices[i];
-                deviceIdAndGeneration[i * 2] = inputDevice.getId();
-                deviceIdAndGeneration[i * 2 + 1] = inputDevice.getGeneration();
-
-                if (!inputDevice.isVirtual() && inputDevice.isFullKeyboard()) {
-                    if (!containsInputDeviceWithDescriptor(oldInputDevices,
-                            inputDevice.getDescriptor())) {
-                        mTempFullKeyboards.add(numFullKeyboardsAdded++, inputDevice);
-                    } else {
-                        mTempFullKeyboards.add(inputDevice);
-                    }
-                }
-            }
-        }
-
-        // Notify listeners.
-        for (int i = 0; i < numListeners; i++) {
-            mTempInputDevicesChangedListenersToNotify.get(i).notifyInputDevicesChanged(
-                    deviceIdAndGeneration);
-        }
-        mTempInputDevicesChangedListenersToNotify.clear();
-
-        // Check for missing keyboard layouts.
-        if (mNotificationManager != null) {
-            final int numFullKeyboards = mTempFullKeyboards.size();
-            boolean missingLayoutForExternalKeyboard = false;
-            boolean missingLayoutForExternalKeyboardAdded = false;
-            synchronized (mDataStore) {
-                for (int i = 0; i < numFullKeyboards; i++) {
-                    final InputDevice inputDevice = mTempFullKeyboards.get(i);
-                    if (mDataStore.getCurrentKeyboardLayout(inputDevice.getDescriptor()) == null) {
-                        missingLayoutForExternalKeyboard = true;
-                        if (i < numFullKeyboardsAdded) {
-                            missingLayoutForExternalKeyboardAdded = true;
-                        }
-                    }
-                }
-            }
-            if (missingLayoutForExternalKeyboard) {
-                if (missingLayoutForExternalKeyboardAdded) {
-                    showMissingKeyboardLayoutNotification();
-                }
-            } else if (mKeyboardLayoutNotificationShown) {
-                hideMissingKeyboardLayoutNotification();
-            }
-        }
-        mTempFullKeyboards.clear();
-    }
-
-    // Must be called on handler.
-    private void showMissingKeyboardLayoutNotification() {
-        if (!mKeyboardLayoutNotificationShown) {
-            if (mKeyboardLayoutIntent == null) {
-                final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS");
-                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
-                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                mKeyboardLayoutIntent = PendingIntent.getActivityAsUser(mContext, 0,
-                        intent, 0, null, UserHandle.CURRENT);
-            }
-
-            Resources r = mContext.getResources();
-            Notification notification = new Notification.Builder(mContext)
-                    .setContentTitle(r.getString(
-                            R.string.select_keyboard_layout_notification_title))
-                    .setContentText(r.getString(
-                            R.string.select_keyboard_layout_notification_message))
-                    .setContentIntent(mKeyboardLayoutIntent)
-                    .setSmallIcon(R.drawable.ic_settings_language)
-                    .setPriority(Notification.PRIORITY_LOW)
-                    .build();
-            mNotificationManager.notifyAsUser(null,
-                    R.string.select_keyboard_layout_notification_title,
-                    notification, UserHandle.ALL);
-            mKeyboardLayoutNotificationShown = true;
-        }
-    }
-
-    // Must be called on handler.
-    private void hideMissingKeyboardLayoutNotification() {
-        if (mKeyboardLayoutNotificationShown) {
-            mKeyboardLayoutNotificationShown = false;
-            mNotificationManager.cancelAsUser(null,
-                    R.string.select_keyboard_layout_notification_title,
-                    UserHandle.ALL);
-        }
-    }
-
-    // Must be called on handler.
-    private void updateKeyboardLayouts() {
-        // Scan all input devices state for keyboard layouts that have been uninstalled.
-        final HashSet<String> availableKeyboardLayouts = new HashSet<String>();
-        visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
-            @Override
-            public void visitKeyboardLayout(Resources resources,
-                    String descriptor, String label, String collection, int keyboardLayoutResId) {
-                availableKeyboardLayouts.add(descriptor);
-            }
-        });
-        synchronized (mDataStore) {
-            try {
-                mDataStore.removeUninstalledKeyboardLayouts(availableKeyboardLayouts);
-            } finally {
-                mDataStore.saveIfNeeded();
-            }
-        }
-
-        // Reload keyboard layouts.
-        reloadKeyboardLayouts();
-    }
-
-    private static boolean containsInputDeviceWithDescriptor(InputDevice[] inputDevices,
-            String descriptor) {
-        final int numDevices = inputDevices.length;
-        for (int i = 0; i < numDevices; i++) {
-            final InputDevice inputDevice = inputDevices[i];
-            if (inputDevice.getDescriptor().equals(descriptor)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override // Binder call
-    public KeyboardLayout[] getKeyboardLayouts() {
-        final ArrayList<KeyboardLayout> list = new ArrayList<KeyboardLayout>();
-        visitAllKeyboardLayouts(new KeyboardLayoutVisitor() {
-            @Override
-            public void visitKeyboardLayout(Resources resources,
-                    String descriptor, String label, String collection, int keyboardLayoutResId) {
-                list.add(new KeyboardLayout(descriptor, label, collection));
-            }
-        });
-        return list.toArray(new KeyboardLayout[list.size()]);
-    }
-
-    @Override // Binder call
-    public KeyboardLayout getKeyboardLayout(String keyboardLayoutDescriptor) {
-        if (keyboardLayoutDescriptor == null) {
-            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
-        }
-
-        final KeyboardLayout[] result = new KeyboardLayout[1];
-        visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
-            @Override
-            public void visitKeyboardLayout(Resources resources,
-                    String descriptor, String label, String collection, int keyboardLayoutResId) {
-                result[0] = new KeyboardLayout(descriptor, label, collection);
-            }
-        });
-        if (result[0] == null) {
-            Log.w(TAG, "Could not get keyboard layout with descriptor '"
-                    + keyboardLayoutDescriptor + "'.");
-        }
-        return result[0];
-    }
-
-    private void visitAllKeyboardLayouts(KeyboardLayoutVisitor visitor) {
-        final PackageManager pm = mContext.getPackageManager();
-        Intent intent = new Intent(InputManager.ACTION_QUERY_KEYBOARD_LAYOUTS);
-        for (ResolveInfo resolveInfo : pm.queryBroadcastReceivers(intent,
-                PackageManager.GET_META_DATA)) {
-            visitKeyboardLayoutsInPackage(pm, resolveInfo.activityInfo, null, visitor);
-        }
-    }
-
-    private void visitKeyboardLayout(String keyboardLayoutDescriptor,
-            KeyboardLayoutVisitor visitor) {
-        KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor);
-        if (d != null) {
-            final PackageManager pm = mContext.getPackageManager();
-            try {
-                ActivityInfo receiver = pm.getReceiverInfo(
-                        new ComponentName(d.packageName, d.receiverName),
-                        PackageManager.GET_META_DATA);
-                visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, visitor);
-            } catch (NameNotFoundException ex) {
-            }
-        }
-    }
-
-    private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver,
-            String keyboardName, KeyboardLayoutVisitor visitor) {
-        Bundle metaData = receiver.metaData;
-        if (metaData == null) {
-            return;
-        }
-
-        int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
-        if (configResId == 0) {
-            Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS
-                    + "' on receiver " + receiver.packageName + "/" + receiver.name);
-            return;
-        }
-
-        CharSequence receiverLabel = receiver.loadLabel(pm);
-        String collection = receiverLabel != null ? receiverLabel.toString() : "";
-
-        try {
-            Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
-            XmlResourceParser parser = resources.getXml(configResId);
-            try {
-                XmlUtils.beginDocument(parser, "keyboard-layouts");
-
-                for (;;) {
-                    XmlUtils.nextElement(parser);
-                    String element = parser.getName();
-                    if (element == null) {
-                        break;
-                    }
-                    if (element.equals("keyboard-layout")) {
-                        TypedArray a = resources.obtainAttributes(
-                                parser, com.android.internal.R.styleable.KeyboardLayout);
-                        try {
-                            String name = a.getString(
-                                    com.android.internal.R.styleable.KeyboardLayout_name);
-                            String label = a.getString(
-                                    com.android.internal.R.styleable.KeyboardLayout_label);
-                            int keyboardLayoutResId = a.getResourceId(
-                                    com.android.internal.R.styleable.KeyboardLayout_keyboardLayout,
-                                    0);
-                            if (name == null || label == null || keyboardLayoutResId == 0) {
-                                Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' "
-                                        + "attributes in keyboard layout "
-                                        + "resource from receiver "
-                                        + receiver.packageName + "/" + receiver.name);
-                            } else {
-                                String descriptor = KeyboardLayoutDescriptor.format(
-                                        receiver.packageName, receiver.name, name);
-                                if (keyboardName == null || name.equals(keyboardName)) {
-                                    visitor.visitKeyboardLayout(resources, descriptor,
-                                            label, collection, keyboardLayoutResId);
-                                }
-                            }
-                        } finally {
-                            a.recycle();
-                        }
-                    } else {
-                        Log.w(TAG, "Skipping unrecognized element '" + element
-                                + "' in keyboard layout resource from receiver "
-                                + receiver.packageName + "/" + receiver.name);
-                    }
-                }
-            } finally {
-                parser.close();
-            }
-        } catch (Exception ex) {
-            Log.w(TAG, "Could not parse keyboard layout resource from receiver "
-                    + receiver.packageName + "/" + receiver.name, ex);
-        }
-    }
-
-    @Override // Binder call
-    public String getCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor) {
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
-        }
-
-        synchronized (mDataStore) {
-            return mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
-        }
-    }
-
-    @Override // Binder call
-    public void setCurrentKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
-            String keyboardLayoutDescriptor) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
-                "setCurrentKeyboardLayoutForInputDevice()")) {
-            throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
-        }
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
-        }
-        if (keyboardLayoutDescriptor == null) {
-            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
-        }
-
-        synchronized (mDataStore) {
-            try {
-                if (mDataStore.setCurrentKeyboardLayout(
-                        inputDeviceDescriptor, keyboardLayoutDescriptor)) {
-                    mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
-                }
-            } finally {
-                mDataStore.saveIfNeeded();
-            }
-        }
-    }
-
-    @Override // Binder call
-    public String[] getKeyboardLayoutsForInputDevice(String inputDeviceDescriptor) {
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
-        }
-
-        synchronized (mDataStore) {
-            return mDataStore.getKeyboardLayouts(inputDeviceDescriptor);
-        }
-    }
-
-    @Override // Binder call
-    public void addKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
-            String keyboardLayoutDescriptor) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
-                "addKeyboardLayoutForInputDevice()")) {
-            throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
-        }
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
-        }
-        if (keyboardLayoutDescriptor == null) {
-            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
-        }
-
-        synchronized (mDataStore) {
-            try {
-                String oldLayout = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
-                if (mDataStore.addKeyboardLayout(inputDeviceDescriptor, keyboardLayoutDescriptor)
-                        && !Objects.equal(oldLayout,
-                                mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor))) {
-                    mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
-                }
-            } finally {
-                mDataStore.saveIfNeeded();
-            }
-        }
-    }
-
-    @Override // Binder call
-    public void removeKeyboardLayoutForInputDevice(String inputDeviceDescriptor,
-            String keyboardLayoutDescriptor) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_KEYBOARD_LAYOUT,
-                "removeKeyboardLayoutForInputDevice()")) {
-            throw new SecurityException("Requires SET_KEYBOARD_LAYOUT permission");
-        }
-        if (inputDeviceDescriptor == null) {
-            throw new IllegalArgumentException("inputDeviceDescriptor must not be null");
-        }
-        if (keyboardLayoutDescriptor == null) {
-            throw new IllegalArgumentException("keyboardLayoutDescriptor must not be null");
-        }
-
-        synchronized (mDataStore) {
-            try {
-                String oldLayout = mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor);
-                if (mDataStore.removeKeyboardLayout(inputDeviceDescriptor,
-                        keyboardLayoutDescriptor)
-                        && !Objects.equal(oldLayout,
-                                mDataStore.getCurrentKeyboardLayout(inputDeviceDescriptor))) {
-                    mHandler.sendEmptyMessage(MSG_RELOAD_KEYBOARD_LAYOUTS);
-                }
-            } finally {
-                mDataStore.saveIfNeeded();
-            }
-        }
-    }
-
-    public void switchKeyboardLayout(int deviceId, int direction) {
-        mHandler.obtainMessage(MSG_SWITCH_KEYBOARD_LAYOUT, deviceId, direction).sendToTarget();
-    }
-
-    // Must be called on handler.
-    private void handleSwitchKeyboardLayout(int deviceId, int direction) {
-        final InputDevice device = getInputDevice(deviceId);
-        if (device != null) {
-            final String inputDeviceDescriptor = device.getDescriptor();
-            final boolean changed;
-            final String keyboardLayoutDescriptor;
-            synchronized (mDataStore) {
-                try {
-                    changed = mDataStore.switchKeyboardLayout(inputDeviceDescriptor, direction);
-                    keyboardLayoutDescriptor = mDataStore.getCurrentKeyboardLayout(
-                            inputDeviceDescriptor);
-                } finally {
-                    mDataStore.saveIfNeeded();
-                }
-            }
-
-            if (changed) {
-                if (mSwitchedKeyboardLayoutToast != null) {
-                    mSwitchedKeyboardLayoutToast.cancel();
-                    mSwitchedKeyboardLayoutToast = null;
-                }
-                if (keyboardLayoutDescriptor != null) {
-                    KeyboardLayout keyboardLayout = getKeyboardLayout(keyboardLayoutDescriptor);
-                    if (keyboardLayout != null) {
-                        mSwitchedKeyboardLayoutToast = Toast.makeText(
-                                mContext, keyboardLayout.getLabel(), Toast.LENGTH_SHORT);
-                        mSwitchedKeyboardLayoutToast.show();
-                    }
-                }
-
-                reloadKeyboardLayouts();
-            }
-        }
-    }
-
-    public void setInputWindows(InputWindowHandle[] windowHandles) {
-        nativeSetInputWindows(mPtr, windowHandles);
-    }
-    
-    public void setFocusedApplication(InputApplicationHandle application) {
-        nativeSetFocusedApplication(mPtr, application);
-    }
-    
-    public void setInputDispatchMode(boolean enabled, boolean frozen) {
-        nativeSetInputDispatchMode(mPtr, enabled, frozen);
-    }
-
-    public void setSystemUiVisibility(int visibility) {
-        nativeSetSystemUiVisibility(mPtr, visibility);
-    }
-
-    /**
-     * Atomically transfers touch focus from one window to another as identified by
-     * their input channels.  It is possible for multiple windows to have
-     * touch focus if they support split touch dispatch
-     * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
-     * method only transfers touch focus of the specified window without affecting
-     * other windows that may also have touch focus at the same time.
-     * @param fromChannel The channel of a window that currently has touch focus.
-     * @param toChannel The channel of the window that should receive touch focus in
-     * place of the first.
-     * @return True if the transfer was successful.  False if the window with the
-     * specified channel did not actually have touch focus at the time of the request.
-     */
-    public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
-        if (fromChannel == null) {
-            throw new IllegalArgumentException("fromChannel must not be null.");
-        }
-        if (toChannel == null) {
-            throw new IllegalArgumentException("toChannel must not be null.");
-        }
-        return nativeTransferTouchFocus(mPtr, fromChannel, toChannel);
-    }
-
-    @Override // Binder call
-    public void tryPointerSpeed(int speed) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_POINTER_SPEED,
-                "tryPointerSpeed()")) {
-            throw new SecurityException("Requires SET_POINTER_SPEED permission");
-        }
-
-        if (speed < InputManager.MIN_POINTER_SPEED || speed > InputManager.MAX_POINTER_SPEED) {
-            throw new IllegalArgumentException("speed out of range");
-        }
-
-        setPointerSpeedUnchecked(speed);
-    }
-
-    public void updatePointerSpeedFromSettings() {
-        int speed = getPointerSpeedSetting();
-        setPointerSpeedUnchecked(speed);
-    }
-
-    private void setPointerSpeedUnchecked(int speed) {
-        speed = Math.min(Math.max(speed, InputManager.MIN_POINTER_SPEED),
-                InputManager.MAX_POINTER_SPEED);
-        nativeSetPointerSpeed(mPtr, speed);
-    }
-
-    private void registerPointerSpeedSettingObserver() {
-        mContext.getContentResolver().registerContentObserver(
-                Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
-                new ContentObserver(mHandler) {
-                    @Override
-                    public void onChange(boolean selfChange) {
-                        updatePointerSpeedFromSettings();
-                    }
-                }, UserHandle.USER_ALL);
-    }
-
-    private int getPointerSpeedSetting() {
-        int speed = InputManager.DEFAULT_POINTER_SPEED;
-        try {
-            speed = Settings.System.getIntForUser(mContext.getContentResolver(),
-                    Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT);
-        } catch (SettingNotFoundException snfe) {
-        }
-        return speed;
-    }
-
-    public void updateShowTouchesFromSettings() {
-        int setting = getShowTouchesSetting(0);
-        nativeSetShowTouches(mPtr, setting != 0);
-    }
-
-    private void registerShowTouchesSettingObserver() {
-        mContext.getContentResolver().registerContentObserver(
-                Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true,
-                new ContentObserver(mHandler) {
-                    @Override
-                    public void onChange(boolean selfChange) {
-                        updateShowTouchesFromSettings();
-                    }
-                }, UserHandle.USER_ALL);
-    }
-
-    private int getShowTouchesSetting(int defaultValue) {
-        int result = defaultValue;
-        try {
-            result = Settings.System.getIntForUser(mContext.getContentResolver(),
-                    Settings.System.SHOW_TOUCHES, UserHandle.USER_CURRENT);
-        } catch (SettingNotFoundException snfe) {
-        }
-        return result;
-    }
-
-    // Binder call
-    @Override
-    public void vibrate(int deviceId, long[] pattern, int repeat, IBinder token) {
-        if (repeat >= pattern.length) {
-            throw new ArrayIndexOutOfBoundsException();
-        }
-
-        VibratorToken v;
-        synchronized (mVibratorLock) {
-            v = mVibratorTokens.get(token);
-            if (v == null) {
-                v = new VibratorToken(deviceId, token, mNextVibratorTokenValue++);
-                try {
-                    token.linkToDeath(v, 0);
-                } catch (RemoteException ex) {
-                    // give up
-                    throw new RuntimeException(ex);
-                }
-                mVibratorTokens.put(token, v);
-            }
-        }
-
-        synchronized (v) {
-            v.mVibrating = true;
-            nativeVibrate(mPtr, deviceId, pattern, repeat, v.mTokenValue);
-        }
-    }
-
-    // Binder call
-    @Override
-    public void cancelVibrate(int deviceId, IBinder token) {
-        VibratorToken v;
-        synchronized (mVibratorLock) {
-            v = mVibratorTokens.get(token);
-            if (v == null || v.mDeviceId != deviceId) {
-                return; // nothing to cancel
-            }
-        }
-
-        cancelVibrateIfNeeded(v);
-    }
-
-    void onVibratorTokenDied(VibratorToken v) {
-        synchronized (mVibratorLock) {
-            mVibratorTokens.remove(v.mToken);
-        }
-
-        cancelVibrateIfNeeded(v);
-    }
-
-    private void cancelVibrateIfNeeded(VibratorToken v) {
-        synchronized (v) {
-            if (v.mVibrating) {
-                nativeCancelVibrate(mPtr, v.mDeviceId, v.mTokenValue);
-                v.mVibrating = false;
-            }
-        }
-    }
-
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump InputManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("INPUT MANAGER (dumpsys input)\n");
-        String dumpStr = nativeDump(mPtr);
-        if (dumpStr != null) {
-            pw.println(dumpStr);
-        }
-    }
-
-    private boolean checkCallingPermission(String permission, String func) {
-        // Quick check: if the calling permission is me, it's all okay.
-        if (Binder.getCallingPid() == Process.myPid()) {
-            return true;
-        }
-
-        if (mContext.checkCallingPermission(permission) == PackageManager.PERMISSION_GRANTED) {
-            return true;
-        }
-        String msg = "Permission Denial: " + func + " from pid="
-                + Binder.getCallingPid()
-                + ", uid=" + Binder.getCallingUid()
-                + " requires " + permission;
-        Slog.w(TAG, msg);
-        return false;
-    }
-
-    // Called by the heartbeat to ensure locks are not held indefinitely (for deadlock detection).
-    @Override
-    public void monitor() {
-        synchronized (mInputFilterLock) { }
-        nativeMonitor(mPtr);
-    }
-
-    // Native callback.
-    private void notifyConfigurationChanged(long whenNanos) {
-        mWindowManagerCallbacks.notifyConfigurationChanged();
-    }
-
-    // Native callback.
-    private void notifyInputDevicesChanged(InputDevice[] inputDevices) {
-        synchronized (mInputDevicesLock) {
-            if (!mInputDevicesChangedPending) {
-                mInputDevicesChangedPending = true;
-                mHandler.obtainMessage(MSG_DELIVER_INPUT_DEVICES_CHANGED,
-                        mInputDevices).sendToTarget();
-            }
-
-            mInputDevices = inputDevices;
-        }
-    }
-
-    // Native callback.
-    private void notifySwitch(long whenNanos, int switchValues, int switchMask) {
-        if (DEBUG) {
-            Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues)
-                    + ", mask=" + Integer.toHexString(switchMask));
-        }
-
-        if ((switchMask & SW_LID_BIT) != 0) {
-            final boolean lidOpen = ((switchValues & SW_LID_BIT) == 0);
-            mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen);
-        }
-
-        if (mUseDevInputEventForAudioJack && (switchMask & SW_JACK_BITS) != 0) {
-            mWiredAccessoryCallbacks.notifyWiredAccessoryChanged(whenNanos, switchValues,
-                    switchMask);
-        }
-    }
-
-    // Native callback.
-    private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
-        mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle);
-    }
-
-    // Native callback.
-    private long notifyANR(InputApplicationHandle inputApplicationHandle,
-            InputWindowHandle inputWindowHandle, String reason) {
-        return mWindowManagerCallbacks.notifyANR(
-                inputApplicationHandle, inputWindowHandle, reason);
-    }
-
-    // Native callback.
-    final boolean filterInputEvent(InputEvent event, int policyFlags) {
-        synchronized (mInputFilterLock) {
-            if (mInputFilter != null) {
-                try {
-                    mInputFilter.filterInputEvent(event, policyFlags);
-                } catch (RemoteException e) {
-                    /* ignore */
-                }
-                return false;
-            }
-        }
-        event.recycle();
-        return true;
-    }
-
-    // Native callback.
-    private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
-        return mWindowManagerCallbacks.interceptKeyBeforeQueueing(
-                event, policyFlags, isScreenOn);
-    }
-
-    // Native callback.
-    private int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
-        return mWindowManagerCallbacks.interceptMotionBeforeQueueingWhenScreenOff(policyFlags);
-    }
-
-    // Native callback.
-    private long interceptKeyBeforeDispatching(InputWindowHandle focus,
-            KeyEvent event, int policyFlags) {
-        return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
-    }
-
-    // Native callback.
-    private KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
-            KeyEvent event, int policyFlags) {
-        return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
-    }
-
-    // Native callback.
-    private boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
-        return mContext.checkPermission(android.Manifest.permission.INJECT_EVENTS,
-                injectorPid, injectorUid) == PackageManager.PERMISSION_GRANTED;
-    }
-
-    // Native callback.
-    private int getVirtualKeyQuietTimeMillis() {
-        return mContext.getResources().getInteger(
-                com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
-    }
-
-    // Native callback.
-    private String[] getExcludedDeviceNames() {
-        ArrayList<String> names = new ArrayList<String>();
-
-        // Read partner-provided list of excluded input devices
-        XmlPullParser parser = null;
-        // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
-        File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
-        FileReader confreader = null;
-        try {
-            confreader = new FileReader(confFile);
-            parser = Xml.newPullParser();
-            parser.setInput(confreader);
-            XmlUtils.beginDocument(parser, "devices");
-
-            while (true) {
-                XmlUtils.nextElement(parser);
-                if (!"device".equals(parser.getName())) {
-                    break;
-                }
-                String name = parser.getAttributeValue(null, "name");
-                if (name != null) {
-                    names.add(name);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            // It's ok if the file does not exist.
-        } catch (Exception e) {
-            Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
-        } finally {
-            try { if (confreader != null) confreader.close(); } catch (IOException e) { }
-        }
-
-        return names.toArray(new String[names.size()]);
-    }
-
-    // Native callback.
-    private int getKeyRepeatTimeout() {
-        return ViewConfiguration.getKeyRepeatTimeout();
-    }
-
-    // Native callback.
-    private int getKeyRepeatDelay() {
-        return ViewConfiguration.getKeyRepeatDelay();
-    }
-
-    // Native callback.
-    private int getHoverTapTimeout() {
-        return ViewConfiguration.getHoverTapTimeout();
-    }
-
-    // Native callback.
-    private int getHoverTapSlop() {
-        return ViewConfiguration.getHoverTapSlop();
-    }
-
-    // Native callback.
-    private int getDoubleTapTimeout() {
-        return ViewConfiguration.getDoubleTapTimeout();
-    }
-
-    // Native callback.
-    private int getLongPressTimeout() {
-        return ViewConfiguration.getLongPressTimeout();
-    }
-
-    // Native callback.
-    private int getPointerLayer() {
-        return mWindowManagerCallbacks.getPointerLayer();
-    }
-
-    // Native callback.
-    private PointerIcon getPointerIcon() {
-        return PointerIcon.getDefaultIcon(mContext);
-    }
-
-    // Native callback.
-    private String[] getKeyboardLayoutOverlay(String inputDeviceDescriptor) {
-        if (!mSystemReady) {
-            return null;
-        }
-
-        String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(
-                inputDeviceDescriptor);
-        if (keyboardLayoutDescriptor == null) {
-            return null;
-        }
-
-        final String[] result = new String[2];
-        visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
-            @Override
-            public void visitKeyboardLayout(Resources resources,
-                    String descriptor, String label, String collection, int keyboardLayoutResId) {
-                try {
-                    result[0] = descriptor;
-                    result[1] = Streams.readFully(new InputStreamReader(
-                            resources.openRawResource(keyboardLayoutResId)));
-                } catch (IOException ex) {
-                } catch (NotFoundException ex) {
-                }
-            }
-        });
-        if (result[0] == null) {
-            Log.w(TAG, "Could not get keyboard layout with descriptor '"
-                    + keyboardLayoutDescriptor + "'.");
-            return null;
-        }
-        return result;
-    }
-
-    // Native callback.
-    private String getDeviceAlias(String uniqueId) {
-        if (BluetoothAdapter.checkBluetoothAddress(uniqueId)) {
-            // TODO(BT) mBluetoothService.getRemoteAlias(uniqueId)
-            return null;
-        }
-        return null;
-    }
-
-    /**
-     * Callback interface implemented by the Window Manager.
-     */
-    public interface WindowManagerCallbacks {
-        public void notifyConfigurationChanged();
-
-        public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
-
-        public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle);
-
-        public long notifyANR(InputApplicationHandle inputApplicationHandle,
-                InputWindowHandle inputWindowHandle, String reason);
-
-        public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn);
-
-        public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags);
-
-        public long interceptKeyBeforeDispatching(InputWindowHandle focus,
-                KeyEvent event, int policyFlags);
-
-        public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
-                KeyEvent event, int policyFlags);
-
-        public int getPointerLayer();
-    }
-
-    /**
-     * Callback interface implemented by WiredAccessoryObserver.
-     */
-    public interface WiredAccessoryCallbacks {
-        public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask);
-    }
-
-    /**
-     * Private handler for the input manager.
-     */
-    private final class InputManagerHandler extends Handler {
-        public InputManagerHandler(Looper looper) {
-            super(looper, null, true /*async*/);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_DELIVER_INPUT_DEVICES_CHANGED:
-                    deliverInputDevicesChanged((InputDevice[])msg.obj);
-                    break;
-                case MSG_SWITCH_KEYBOARD_LAYOUT:
-                    handleSwitchKeyboardLayout(msg.arg1, msg.arg2);
-                    break;
-                case MSG_RELOAD_KEYBOARD_LAYOUTS:
-                    reloadKeyboardLayouts();
-                    break;
-                case MSG_UPDATE_KEYBOARD_LAYOUTS:
-                    updateKeyboardLayouts();
-                    break;
-                case MSG_RELOAD_DEVICE_ALIASES:
-                    reloadDeviceAliases();
-                    break;
-            }
-        }
-    }
-
-    /**
-     * Hosting interface for input filters to call back into the input manager.
-     */
-    private final class InputFilterHost extends IInputFilterHost.Stub {
-        private boolean mDisconnected;
-
-        public void disconnectLocked() {
-            mDisconnected = true;
-        }
-
-        @Override
-        public void sendInputEvent(InputEvent event, int policyFlags) {
-            if (event == null) {
-                throw new IllegalArgumentException("event must not be null");
-            }
-
-            synchronized (mInputFilterLock) {
-                if (!mDisconnected) {
-                    nativeInjectInputEvent(mPtr, event, 0, 0,
-                            InputManager.INJECT_INPUT_EVENT_MODE_ASYNC, 0,
-                            policyFlags | WindowManagerPolicy.FLAG_FILTERED);
-                }
-            }
-        }
-    }
-
-    private static final class KeyboardLayoutDescriptor {
-        public String packageName;
-        public String receiverName;
-        public String keyboardLayoutName;
-
-        public static String format(String packageName,
-                String receiverName, String keyboardName) {
-            return packageName + "/" + receiverName + "/" + keyboardName;
-        }
-
-        public static KeyboardLayoutDescriptor parse(String descriptor) {
-            int pos = descriptor.indexOf('/');
-            if (pos < 0 || pos + 1 == descriptor.length()) {
-                return null;
-            }
-            int pos2 = descriptor.indexOf('/', pos + 1);
-            if (pos2 < pos + 2 || pos2 + 1 == descriptor.length()) {
-                return null;
-            }
-
-            KeyboardLayoutDescriptor result = new KeyboardLayoutDescriptor();
-            result.packageName = descriptor.substring(0, pos);
-            result.receiverName = descriptor.substring(pos + 1, pos2);
-            result.keyboardLayoutName = descriptor.substring(pos2 + 1);
-            return result;
-        }
-    }
-
-    private interface KeyboardLayoutVisitor {
-        void visitKeyboardLayout(Resources resources,
-                String descriptor, String label, String collection, int keyboardLayoutResId);
-    }
-
-    private final class InputDevicesChangedListenerRecord implements DeathRecipient {
-        private final int mPid;
-        private final IInputDevicesChangedListener mListener;
-
-        public InputDevicesChangedListenerRecord(int pid, IInputDevicesChangedListener listener) {
-            mPid = pid;
-            mListener = listener;
-        }
-
-        @Override
-        public void binderDied() {
-            if (DEBUG) {
-                Slog.d(TAG, "Input devices changed listener for pid " + mPid + " died.");
-            }
-            onInputDevicesChangedListenerDied(mPid);
-        }
-
-        public void notifyInputDevicesChanged(int[] info) {
-            try {
-                mListener.onInputDevicesChanged(info);
-            } catch (RemoteException ex) {
-                Slog.w(TAG, "Failed to notify process "
-                        + mPid + " that input devices changed, assuming it died.", ex);
-                binderDied();
-            }
-        }
-    }
-
-    private final class VibratorToken implements DeathRecipient {
-        public final int mDeviceId;
-        public final IBinder mToken;
-        public final int mTokenValue;
-
-        public boolean mVibrating;
-
-        public VibratorToken(int deviceId, IBinder token, int tokenValue) {
-            mDeviceId = deviceId;
-            mToken = token;
-            mTokenValue = tokenValue;
-        }
-
-        @Override
-        public void binderDied() {
-            if (DEBUG) {
-                Slog.d(TAG, "Vibrator token died.");
-            }
-            onVibratorTokenDied(this);
-        }
-    }
-}
diff --git a/services/java/com/android/server/input/InputWindowHandle.java b/services/java/com/android/server/input/InputWindowHandle.java
deleted file mode 100644
index 9eb9a33..0000000
--- a/services/java/com/android/server/input/InputWindowHandle.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.server.input;
-
-import android.graphics.Region;
-import android.view.InputChannel;
-
-/**
- * Functions as a handle for a window that can receive input.
- * Enables the native input dispatcher to refer indirectly to the window manager's window state.
- * @hide
- */
-public final class InputWindowHandle {
-    // Pointer to the native input window handle.
-    // This field is lazily initialized via JNI.
-    @SuppressWarnings("unused")
-    private int ptr;
-
-    // The input application handle.
-    public final InputApplicationHandle inputApplicationHandle;
-
-    // The window manager's window state.
-    public final Object windowState;
-
-    // The input channel associated with the window.
-    public InputChannel inputChannel;
-
-    // The window name.
-    public String name;
-
-    // Window layout params attributes.  (WindowManager.LayoutParams)
-    public int layoutParamsFlags;
-    public int layoutParamsPrivateFlags;
-    public int layoutParamsType;
-
-    // Dispatching timeout.
-    public long dispatchingTimeoutNanos;
-
-    // Window frame.
-    public int frameLeft;
-    public int frameTop;
-    public int frameRight;
-    public int frameBottom;
-
-    // Global scaling factor applied to touch events when they are dispatched
-    // to the window
-    public float scaleFactor;
-
-    // Window touchable region.
-    public final Region touchableRegion = new Region();
-
-    // Window is visible.
-    public boolean visible;
-
-    // Window can receive keys.
-    public boolean canReceiveKeys;
-
-    // Window has focus.
-    public boolean hasFocus;
-
-    // Window has wallpaper.  (window is the current wallpaper target)
-    public boolean hasWallpaper;
-
-    // Input event dispatching is paused.
-    public boolean paused;
-
-    // Window layer.
-    public int layer;
-
-    // Id of process and user that owns the window.
-    public int ownerPid;
-    public int ownerUid;
-
-    // Window input features.
-    public int inputFeatures;
-
-    // Display this input is on.
-    public final int displayId;
-
-    private native void nativeDispose();
-
-    public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
-            Object windowState, int displayId) {
-        this.inputApplicationHandle = inputApplicationHandle;
-        this.windowState = windowState;
-        this.displayId = displayId;
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            nativeDispose();
-        } finally {
-            super.finalize();
-        }
-    }
-}
diff --git a/services/java/com/android/server/media/MediaRouterService.java b/services/java/com/android/server/media/MediaRouterService.java
deleted file mode 100644
index a31695b..0000000
--- a/services/java/com/android/server/media/MediaRouterService.java
+++ /dev/null
@@ -1,1423 +0,0 @@
-/*
- * Copyright (C) 2013 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.media;
-
-import com.android.internal.util.Objects;
-import com.android.server.Watchdog;
-
-import android.Manifest;
-import android.app.ActivityManager;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.media.AudioSystem;
-import android.media.IMediaRouterClient;
-import android.media.IMediaRouterService;
-import android.media.MediaRouter;
-import android.media.MediaRouterClientState;
-import android.media.RemoteDisplayState;
-import android.media.RemoteDisplayState.RemoteDisplayInfo;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.text.TextUtils;
-import android.util.ArrayMap;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.TimeUtils;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Provides a mechanism for discovering media routes and manages media playback
- * behalf of applications.
- * <p>
- * Currently supports discovering remote displays via remote display provider
- * services that have been registered by applications.
- * </p>
- */
-public final class MediaRouterService extends IMediaRouterService.Stub
-        implements Watchdog.Monitor {
-    private static final String TAG = "MediaRouterService";
-    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
-
-    /**
-     * Timeout in milliseconds for a selected route to transition from a
-     * disconnected state to a connecting state.  If we don't observe any
-     * progress within this interval, then we will give up and unselect the route.
-     */
-    static final long CONNECTING_TIMEOUT = 5000;
-
-    /**
-     * Timeout in milliseconds for a selected route to transition from a
-     * connecting state to a connected state.  If we don't observe any
-     * progress within this interval, then we will give up and unselect the route.
-     */
-    static final long CONNECTED_TIMEOUT = 60000;
-
-    private final Context mContext;
-
-    // State guarded by mLock.
-    private final Object mLock = new Object();
-    private final SparseArray<UserRecord> mUserRecords = new SparseArray<UserRecord>();
-    private final ArrayMap<IBinder, ClientRecord> mAllClientRecords =
-            new ArrayMap<IBinder, ClientRecord>();
-    private int mCurrentUserId = -1;
-
-    public MediaRouterService(Context context) {
-        mContext = context;
-        Watchdog.getInstance().addMonitor(this);
-    }
-
-    public void systemRunning() {
-        IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
-        mContext.registerReceiver(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                if (intent.getAction().equals(Intent.ACTION_USER_SWITCHED)) {
-                    switchUser();
-                }
-            }
-        }, filter);
-
-        switchUser();
-    }
-
-    @Override
-    public void monitor() {
-        synchronized (mLock) { /* check for deadlock */ }
-    }
-
-    // Binder call
-    @Override
-    public void registerClientAsUser(IMediaRouterClient client, String packageName, int userId) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-
-        final int uid = Binder.getCallingUid();
-        if (!validatePackageName(uid, packageName)) {
-            throw new SecurityException("packageName must match the calling uid");
-        }
-
-        final int pid = Binder.getCallingPid();
-        final int resolvedUserId = ActivityManager.handleIncomingUser(pid, uid, userId,
-                false /*allowAll*/, true /*requireFull*/, "registerClientAsUser", packageName);
-        final boolean trusted = mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.CONFIGURE_WIFI_DISPLAY) ==
-                PackageManager.PERMISSION_GRANTED;
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                registerClientLocked(client, pid, packageName, resolvedUserId, trusted);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    @Override
-    public void unregisterClient(IMediaRouterClient client) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                unregisterClientLocked(client, false);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    @Override
-    public MediaRouterClientState getState(IMediaRouterClient client) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                return getStateLocked(client);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    @Override
-    public void setDiscoveryRequest(IMediaRouterClient client,
-            int routeTypes, boolean activeScan) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                setDiscoveryRequestLocked(client, routeTypes, activeScan);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    // A null routeId means that the client wants to unselect its current route.
-    // The explicit flag indicates whether the change was explicitly requested by the
-    // user or the application which may cause changes to propagate out to the rest
-    // of the system.  Should be false when the change is in response to a new globally
-    // selected route or a default selection.
-    @Override
-    public void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                setSelectedRouteLocked(client, routeId, explicit);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    @Override
-    public void requestSetVolume(IMediaRouterClient client, String routeId, int volume) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-        if (routeId == null) {
-            throw new IllegalArgumentException("routeId must not be null");
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                requestSetVolumeLocked(client, routeId, volume);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    @Override
-    public void requestUpdateVolume(IMediaRouterClient client, String routeId, int direction) {
-        if (client == null) {
-            throw new IllegalArgumentException("client must not be null");
-        }
-        if (routeId == null) {
-            throw new IllegalArgumentException("routeId must not be null");
-        }
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            synchronized (mLock) {
-                requestUpdateVolumeLocked(client, routeId, direction);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    // Binder call
-    @Override
-    public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump MediaRouterService from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("MEDIA ROUTER SERVICE (dumpsys media_router)");
-        pw.println();
-        pw.println("Global state");
-        pw.println("  mCurrentUserId=" + mCurrentUserId);
-
-        synchronized (mLock) {
-            final int count = mUserRecords.size();
-            for (int i = 0; i < count; i++) {
-                UserRecord userRecord = mUserRecords.valueAt(i);
-                pw.println();
-                userRecord.dump(pw, "");
-            }
-        }
-    }
-
-    void switchUser() {
-        synchronized (mLock) {
-            int userId = ActivityManager.getCurrentUser();
-            if (mCurrentUserId != userId) {
-                final int oldUserId = mCurrentUserId;
-                mCurrentUserId = userId; // do this first
-
-                UserRecord oldUser = mUserRecords.get(oldUserId);
-                if (oldUser != null) {
-                    oldUser.mHandler.sendEmptyMessage(UserHandler.MSG_STOP);
-                    disposeUserIfNeededLocked(oldUser); // since no longer current user
-                }
-
-                UserRecord newUser = mUserRecords.get(userId);
-                if (newUser != null) {
-                    newUser.mHandler.sendEmptyMessage(UserHandler.MSG_START);
-                }
-            }
-        }
-    }
-
-    void clientDied(ClientRecord clientRecord) {
-        synchronized (mLock) {
-            unregisterClientLocked(clientRecord.mClient, true);
-        }
-    }
-
-    private void registerClientLocked(IMediaRouterClient client,
-            int pid, String packageName, int userId, boolean trusted) {
-        final IBinder binder = client.asBinder();
-        ClientRecord clientRecord = mAllClientRecords.get(binder);
-        if (clientRecord == null) {
-            boolean newUser = false;
-            UserRecord userRecord = mUserRecords.get(userId);
-            if (userRecord == null) {
-                userRecord = new UserRecord(userId);
-                newUser = true;
-            }
-            clientRecord = new ClientRecord(userRecord, client, pid, packageName, trusted);
-            try {
-                binder.linkToDeath(clientRecord, 0);
-            } catch (RemoteException ex) {
-                throw new RuntimeException("Media router client died prematurely.", ex);
-            }
-
-            if (newUser) {
-                mUserRecords.put(userId, userRecord);
-                initializeUserLocked(userRecord);
-            }
-
-            userRecord.mClientRecords.add(clientRecord);
-            mAllClientRecords.put(binder, clientRecord);
-            initializeClientLocked(clientRecord);
-        }
-    }
-
-    private void unregisterClientLocked(IMediaRouterClient client, boolean died) {
-        ClientRecord clientRecord = mAllClientRecords.remove(client.asBinder());
-        if (clientRecord != null) {
-            UserRecord userRecord = clientRecord.mUserRecord;
-            userRecord.mClientRecords.remove(clientRecord);
-            disposeClientLocked(clientRecord, died);
-            disposeUserIfNeededLocked(userRecord); // since client removed from user
-        }
-    }
-
-    private MediaRouterClientState getStateLocked(IMediaRouterClient client) {
-        ClientRecord clientRecord = mAllClientRecords.get(client.asBinder());
-        if (clientRecord != null) {
-            return clientRecord.getState();
-        }
-        return null;
-    }
-
-    private void setDiscoveryRequestLocked(IMediaRouterClient client,
-            int routeTypes, boolean activeScan) {
-        final IBinder binder = client.asBinder();
-        ClientRecord clientRecord = mAllClientRecords.get(binder);
-        if (clientRecord != null) {
-            // Only let the system discover remote display routes for now.
-            if (!clientRecord.mTrusted) {
-                routeTypes &= ~MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
-            }
-
-            if (clientRecord.mRouteTypes != routeTypes
-                    || clientRecord.mActiveScan != activeScan) {
-                if (DEBUG) {
-                    Slog.d(TAG, clientRecord + ": Set discovery request, routeTypes=0x"
-                            + Integer.toHexString(routeTypes) + ", activeScan=" + activeScan);
-                }
-                clientRecord.mRouteTypes = routeTypes;
-                clientRecord.mActiveScan = activeScan;
-                clientRecord.mUserRecord.mHandler.sendEmptyMessage(
-                        UserHandler.MSG_UPDATE_DISCOVERY_REQUEST);
-            }
-        }
-    }
-
-    private void setSelectedRouteLocked(IMediaRouterClient client,
-            String routeId, boolean explicit) {
-        ClientRecord clientRecord = mAllClientRecords.get(client.asBinder());
-        if (clientRecord != null) {
-            final String oldRouteId = clientRecord.mSelectedRouteId;
-            if (!Objects.equal(routeId, oldRouteId)) {
-                if (DEBUG) {
-                    Slog.d(TAG, clientRecord + ": Set selected route, routeId=" + routeId
-                            + ", oldRouteId=" + oldRouteId
-                            + ", explicit=" + explicit);
-                }
-
-                clientRecord.mSelectedRouteId = routeId;
-                if (explicit) {
-                    // Any app can disconnect from the globally selected route.
-                    if (oldRouteId != null) {
-                        clientRecord.mUserRecord.mHandler.obtainMessage(
-                                UserHandler.MSG_UNSELECT_ROUTE, oldRouteId).sendToTarget();
-                    }
-                    // Only let the system connect to new global routes for now.
-                    // A similar check exists in the display manager for wifi display.
-                    if (routeId != null && clientRecord.mTrusted) {
-                        clientRecord.mUserRecord.mHandler.obtainMessage(
-                                UserHandler.MSG_SELECT_ROUTE, routeId).sendToTarget();
-                    }
-                }
-            }
-        }
-    }
-
-    private void requestSetVolumeLocked(IMediaRouterClient client,
-            String routeId, int volume) {
-        final IBinder binder = client.asBinder();
-        ClientRecord clientRecord = mAllClientRecords.get(binder);
-        if (clientRecord != null) {
-            clientRecord.mUserRecord.mHandler.obtainMessage(
-                    UserHandler.MSG_REQUEST_SET_VOLUME, volume, 0, routeId).sendToTarget();
-        }
-    }
-
-    private void requestUpdateVolumeLocked(IMediaRouterClient client,
-            String routeId, int direction) {
-        final IBinder binder = client.asBinder();
-        ClientRecord clientRecord = mAllClientRecords.get(binder);
-        if (clientRecord != null) {
-            clientRecord.mUserRecord.mHandler.obtainMessage(
-                    UserHandler.MSG_REQUEST_UPDATE_VOLUME, direction, 0, routeId).sendToTarget();
-        }
-    }
-
-    private void initializeUserLocked(UserRecord userRecord) {
-        if (DEBUG) {
-            Slog.d(TAG, userRecord + ": Initialized");
-        }
-        if (userRecord.mUserId == mCurrentUserId) {
-            userRecord.mHandler.sendEmptyMessage(UserHandler.MSG_START);
-        }
-    }
-
-    private void disposeUserIfNeededLocked(UserRecord userRecord) {
-        // If there are no records left and the user is no longer current then go ahead
-        // and purge the user record and all of its associated state.  If the user is current
-        // then leave it alone since we might be connected to a route or want to query
-        // the same route information again soon.
-        if (userRecord.mUserId != mCurrentUserId
-                && userRecord.mClientRecords.isEmpty()) {
-            if (DEBUG) {
-                Slog.d(TAG, userRecord + ": Disposed");
-            }
-            mUserRecords.remove(userRecord.mUserId);
-            // Note: User already stopped (by switchUser) so no need to send stop message here.
-        }
-    }
-
-    private void initializeClientLocked(ClientRecord clientRecord) {
-        if (DEBUG) {
-            Slog.d(TAG, clientRecord + ": Registered");
-        }
-    }
-
-    private void disposeClientLocked(ClientRecord clientRecord, boolean died) {
-        if (DEBUG) {
-            if (died) {
-                Slog.d(TAG, clientRecord + ": Died!");
-            } else {
-                Slog.d(TAG, clientRecord + ": Unregistered");
-            }
-        }
-        if (clientRecord.mRouteTypes != 0 || clientRecord.mActiveScan) {
-            clientRecord.mUserRecord.mHandler.sendEmptyMessage(
-                    UserHandler.MSG_UPDATE_DISCOVERY_REQUEST);
-        }
-        clientRecord.dispose();
-    }
-
-    private boolean validatePackageName(int uid, String packageName) {
-        if (packageName != null) {
-            String[] packageNames = mContext.getPackageManager().getPackagesForUid(uid);
-            if (packageNames != null) {
-                for (String n : packageNames) {
-                    if (n.equals(packageName)) {
-                        return true;
-                    }
-                }
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Information about a particular client of the media router.
-     * The contents of this object is guarded by mLock.
-     */
-    final class ClientRecord implements DeathRecipient {
-        public final UserRecord mUserRecord;
-        public final IMediaRouterClient mClient;
-        public final int mPid;
-        public final String mPackageName;
-        public final boolean mTrusted;
-
-        public int mRouteTypes;
-        public boolean mActiveScan;
-        public String mSelectedRouteId;
-
-        public ClientRecord(UserRecord userRecord, IMediaRouterClient client,
-                int pid, String packageName, boolean trusted) {
-            mUserRecord = userRecord;
-            mClient = client;
-            mPid = pid;
-            mPackageName = packageName;
-            mTrusted = trusted;
-        }
-
-        public void dispose() {
-            mClient.asBinder().unlinkToDeath(this, 0);
-        }
-
-        @Override
-        public void binderDied() {
-            clientDied(this);
-        }
-
-        MediaRouterClientState getState() {
-            return mTrusted ? mUserRecord.mTrustedState : mUserRecord.mUntrustedState;
-        }
-
-        public void dump(PrintWriter pw, String prefix) {
-            pw.println(prefix + this);
-
-            final String indent = prefix + "  ";
-            pw.println(indent + "mTrusted=" + mTrusted);
-            pw.println(indent + "mRouteTypes=0x" + Integer.toHexString(mRouteTypes));
-            pw.println(indent + "mActiveScan=" + mActiveScan);
-            pw.println(indent + "mSelectedRouteId=" + mSelectedRouteId);
-        }
-
-        @Override
-        public String toString() {
-            return "Client " + mPackageName + " (pid " + mPid + ")";
-        }
-    }
-
-    /**
-     * Information about a particular user.
-     * The contents of this object is guarded by mLock.
-     */
-    final class UserRecord {
-        public final int mUserId;
-        public final ArrayList<ClientRecord> mClientRecords = new ArrayList<ClientRecord>();
-        public final UserHandler mHandler;
-        public MediaRouterClientState mTrustedState;
-        public MediaRouterClientState mUntrustedState;
-
-        public UserRecord(int userId) {
-            mUserId = userId;
-            mHandler = new UserHandler(MediaRouterService.this, this);
-        }
-
-        public void dump(final PrintWriter pw, String prefix) {
-            pw.println(prefix + this);
-
-            final String indent = prefix + "  ";
-            final int clientCount = mClientRecords.size();
-            if (clientCount != 0) {
-                for (int i = 0; i < clientCount; i++) {
-                    mClientRecords.get(i).dump(pw, indent);
-                }
-            } else {
-                pw.println(indent + "<no clients>");
-            }
-
-            pw.println(indent + "State");
-            pw.println(indent + "mTrustedState=" + mTrustedState);
-            pw.println(indent + "mUntrustedState=" + mUntrustedState);
-
-            if (!mHandler.runWithScissors(new Runnable() {
-                @Override
-                public void run() {
-                    mHandler.dump(pw, indent);
-                }
-            }, 1000)) {
-                pw.println(indent + "<could not dump handler state>");
-            }
-         }
-
-        @Override
-        public String toString() {
-            return "User " + mUserId;
-        }
-    }
-
-    /**
-     * Media router handler
-     * <p>
-     * Since remote display providers are designed to be single-threaded by nature,
-     * this class encapsulates all of the associated functionality and exports state
-     * to the service as it evolves.
-     * </p><p>
-     * One important task of this class is to keep track of the current globally selected
-     * route id for certain routes that have global effects, such as remote displays.
-     * Global route selections override local selections made within apps.  The change
-     * is propagated to all apps so that they are all in sync.  Synchronization works
-     * both ways.  Whenever the globally selected route is explicitly unselected by any
-     * app, then it becomes unselected globally and all apps are informed.
-     * </p><p>
-     * This class is currently hardcoded to work with remote display providers but
-     * it is intended to be eventually extended to support more general route providers
-     * similar to the support library media router.
-     * </p>
-     */
-    static final class UserHandler extends Handler
-            implements RemoteDisplayProviderWatcher.Callback,
-            RemoteDisplayProviderProxy.Callback {
-        public static final int MSG_START = 1;
-        public static final int MSG_STOP = 2;
-        public static final int MSG_UPDATE_DISCOVERY_REQUEST = 3;
-        public static final int MSG_SELECT_ROUTE = 4;
-        public static final int MSG_UNSELECT_ROUTE = 5;
-        public static final int MSG_REQUEST_SET_VOLUME = 6;
-        public static final int MSG_REQUEST_UPDATE_VOLUME = 7;
-        private static final int MSG_UPDATE_CLIENT_STATE = 8;
-        private static final int MSG_CONNECTION_TIMED_OUT = 9;
-
-        private static final int TIMEOUT_REASON_NOT_AVAILABLE = 1;
-        private static final int TIMEOUT_REASON_CONNECTION_LOST = 2;
-        private static final int TIMEOUT_REASON_WAITING_FOR_CONNECTING = 3;
-        private static final int TIMEOUT_REASON_WAITING_FOR_CONNECTED = 4;
-
-        // The relative order of these constants is important and expresses progress
-        // through the process of connecting to a route.
-        private static final int PHASE_NOT_AVAILABLE = -1;
-        private static final int PHASE_NOT_CONNECTED = 0;
-        private static final int PHASE_CONNECTING = 1;
-        private static final int PHASE_CONNECTED = 2;
-
-        private final MediaRouterService mService;
-        private final UserRecord mUserRecord;
-        private final RemoteDisplayProviderWatcher mWatcher;
-        private final ArrayList<ProviderRecord> mProviderRecords =
-                new ArrayList<ProviderRecord>();
-        private final ArrayList<IMediaRouterClient> mTempClients =
-                new ArrayList<IMediaRouterClient>();
-
-        private boolean mRunning;
-        private int mDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_NONE;
-        private RouteRecord mGloballySelectedRouteRecord;
-        private int mConnectionPhase = PHASE_NOT_AVAILABLE;
-        private int mConnectionTimeoutReason;
-        private long mConnectionTimeoutStartTime;
-        private boolean mClientStateUpdateScheduled;
-
-        public UserHandler(MediaRouterService service, UserRecord userRecord) {
-            super(Looper.getMainLooper(), null, true);
-            mService = service;
-            mUserRecord = userRecord;
-            mWatcher = new RemoteDisplayProviderWatcher(service.mContext, this,
-                    this, mUserRecord.mUserId);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_START: {
-                    start();
-                    break;
-                }
-                case MSG_STOP: {
-                    stop();
-                    break;
-                }
-                case MSG_UPDATE_DISCOVERY_REQUEST: {
-                    updateDiscoveryRequest();
-                    break;
-                }
-                case MSG_SELECT_ROUTE: {
-                    selectRoute((String)msg.obj);
-                    break;
-                }
-                case MSG_UNSELECT_ROUTE: {
-                    unselectRoute((String)msg.obj);
-                    break;
-                }
-                case MSG_REQUEST_SET_VOLUME: {
-                    requestSetVolume((String)msg.obj, msg.arg1);
-                    break;
-                }
-                case MSG_REQUEST_UPDATE_VOLUME: {
-                    requestUpdateVolume((String)msg.obj, msg.arg1);
-                    break;
-                }
-                case MSG_UPDATE_CLIENT_STATE: {
-                    updateClientState();
-                    break;
-                }
-                case MSG_CONNECTION_TIMED_OUT: {
-                    connectionTimedOut();
-                    break;
-                }
-            }
-        }
-
-        public void dump(PrintWriter pw, String prefix) {
-            pw.println(prefix + "Handler");
-
-            final String indent = prefix + "  ";
-            pw.println(indent + "mRunning=" + mRunning);
-            pw.println(indent + "mDiscoveryMode=" + mDiscoveryMode);
-            pw.println(indent + "mGloballySelectedRouteRecord=" + mGloballySelectedRouteRecord);
-            pw.println(indent + "mConnectionPhase=" + mConnectionPhase);
-            pw.println(indent + "mConnectionTimeoutReason=" + mConnectionTimeoutReason);
-            pw.println(indent + "mConnectionTimeoutStartTime=" + (mConnectionTimeoutReason != 0 ?
-                    TimeUtils.formatUptime(mConnectionTimeoutStartTime) : "<n/a>"));
-
-            mWatcher.dump(pw, prefix);
-
-            final int providerCount = mProviderRecords.size();
-            if (providerCount != 0) {
-                for (int i = 0; i < providerCount; i++) {
-                    mProviderRecords.get(i).dump(pw, prefix);
-                }
-            } else {
-                pw.println(indent + "<no providers>");
-            }
-        }
-
-        private void start() {
-            if (!mRunning) {
-                mRunning = true;
-                mWatcher.start(); // also starts all providers
-            }
-        }
-
-        private void stop() {
-            if (mRunning) {
-                mRunning = false;
-                unselectGloballySelectedRoute();
-                mWatcher.stop(); // also stops all providers
-            }
-        }
-
-        private void updateDiscoveryRequest() {
-            int routeTypes = 0;
-            boolean activeScan = false;
-            synchronized (mService.mLock) {
-                final int count = mUserRecord.mClientRecords.size();
-                for (int i = 0; i < count; i++) {
-                    ClientRecord clientRecord = mUserRecord.mClientRecords.get(i);
-                    routeTypes |= clientRecord.mRouteTypes;
-                    activeScan |= clientRecord.mActiveScan;
-                }
-            }
-
-            final int newDiscoveryMode;
-            if ((routeTypes & MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY) != 0) {
-                if (activeScan) {
-                    newDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_ACTIVE;
-                } else {
-                    newDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_PASSIVE;
-                }
-            } else {
-                newDiscoveryMode = RemoteDisplayState.DISCOVERY_MODE_NONE;
-            }
-
-            if (mDiscoveryMode != newDiscoveryMode) {
-                mDiscoveryMode = newDiscoveryMode;
-                final int count = mProviderRecords.size();
-                for (int i = 0; i < count; i++) {
-                    mProviderRecords.get(i).getProvider().setDiscoveryMode(mDiscoveryMode);
-                }
-            }
-        }
-
-        private void selectRoute(String routeId) {
-            if (routeId != null
-                    && (mGloballySelectedRouteRecord == null
-                            || !routeId.equals(mGloballySelectedRouteRecord.getUniqueId()))) {
-                RouteRecord routeRecord = findRouteRecord(routeId);
-                if (routeRecord != null) {
-                    unselectGloballySelectedRoute();
-
-                    Slog.i(TAG, "Selected global route:" + routeRecord);
-                    mGloballySelectedRouteRecord = routeRecord;
-                    checkGloballySelectedRouteState();
-                    routeRecord.getProvider().setSelectedDisplay(routeRecord.getDescriptorId());
-
-                    scheduleUpdateClientState();
-                }
-            }
-        }
-
-        private void unselectRoute(String routeId) {
-            if (routeId != null
-                    && mGloballySelectedRouteRecord != null
-                    && routeId.equals(mGloballySelectedRouteRecord.getUniqueId())) {
-                unselectGloballySelectedRoute();
-            }
-        }
-
-        private void unselectGloballySelectedRoute() {
-            if (mGloballySelectedRouteRecord != null) {
-                Slog.i(TAG, "Unselected global route:" + mGloballySelectedRouteRecord);
-                mGloballySelectedRouteRecord.getProvider().setSelectedDisplay(null);
-                mGloballySelectedRouteRecord = null;
-                checkGloballySelectedRouteState();
-
-                scheduleUpdateClientState();
-            }
-        }
-
-        private void requestSetVolume(String routeId, int volume) {
-            if (mGloballySelectedRouteRecord != null
-                    && routeId.equals(mGloballySelectedRouteRecord.getUniqueId())) {
-                mGloballySelectedRouteRecord.getProvider().setDisplayVolume(volume);
-            }
-        }
-
-        private void requestUpdateVolume(String routeId, int direction) {
-            if (mGloballySelectedRouteRecord != null
-                    && routeId.equals(mGloballySelectedRouteRecord.getUniqueId())) {
-                mGloballySelectedRouteRecord.getProvider().adjustDisplayVolume(direction);
-            }
-        }
-
-        @Override
-        public void addProvider(RemoteDisplayProviderProxy provider) {
-            provider.setCallback(this);
-            provider.setDiscoveryMode(mDiscoveryMode);
-            provider.setSelectedDisplay(null); // just to be safe
-
-            ProviderRecord providerRecord = new ProviderRecord(provider);
-            mProviderRecords.add(providerRecord);
-            providerRecord.updateDescriptor(provider.getDisplayState());
-
-            scheduleUpdateClientState();
-        }
-
-        @Override
-        public void removeProvider(RemoteDisplayProviderProxy provider) {
-            int index = findProviderRecord(provider);
-            if (index >= 0) {
-                ProviderRecord providerRecord = mProviderRecords.remove(index);
-                providerRecord.updateDescriptor(null); // mark routes invalid
-                provider.setCallback(null);
-                provider.setDiscoveryMode(RemoteDisplayState.DISCOVERY_MODE_NONE);
-
-                checkGloballySelectedRouteState();
-                scheduleUpdateClientState();
-            }
-        }
-
-        @Override
-        public void onDisplayStateChanged(RemoteDisplayProviderProxy provider,
-                RemoteDisplayState state) {
-            updateProvider(provider, state);
-        }
-
-        private void updateProvider(RemoteDisplayProviderProxy provider,
-                RemoteDisplayState state) {
-            int index = findProviderRecord(provider);
-            if (index >= 0) {
-                ProviderRecord providerRecord = mProviderRecords.get(index);
-                if (providerRecord.updateDescriptor(state)) {
-                    checkGloballySelectedRouteState();
-                    scheduleUpdateClientState();
-                }
-            }
-        }
-
-        /**
-         * This function is called whenever the state of the globally selected route
-         * may have changed.  It checks the state and updates timeouts or unselects
-         * the route as appropriate.
-         */
-        private void checkGloballySelectedRouteState() {
-            // Unschedule timeouts when the route is unselected.
-            if (mGloballySelectedRouteRecord == null) {
-                mConnectionPhase = PHASE_NOT_AVAILABLE;
-                updateConnectionTimeout(0);
-                return;
-            }
-
-            // Ensure that the route is still present and enabled.
-            if (!mGloballySelectedRouteRecord.isValid()
-                    || !mGloballySelectedRouteRecord.isEnabled()) {
-                updateConnectionTimeout(TIMEOUT_REASON_NOT_AVAILABLE);
-                return;
-            }
-
-            // Make sure we haven't lost our connection.
-            final int oldPhase = mConnectionPhase;
-            mConnectionPhase = getConnectionPhase(mGloballySelectedRouteRecord.getStatus());
-            if (oldPhase >= PHASE_CONNECTING && mConnectionPhase < PHASE_CONNECTING) {
-                updateConnectionTimeout(TIMEOUT_REASON_CONNECTION_LOST);
-                return;
-            }
-
-            // Check the route status.
-            switch (mConnectionPhase) {
-                case PHASE_CONNECTED:
-                    if (oldPhase != PHASE_CONNECTED) {
-                        Slog.i(TAG, "Connected to global route: "
-                                + mGloballySelectedRouteRecord);
-                    }
-                    updateConnectionTimeout(0);
-                    break;
-                case PHASE_CONNECTING:
-                    if (oldPhase != PHASE_CONNECTING) {
-                        Slog.i(TAG, "Connecting to global route: "
-                                + mGloballySelectedRouteRecord);
-                    }
-                    updateConnectionTimeout(TIMEOUT_REASON_WAITING_FOR_CONNECTED);
-                    break;
-                case PHASE_NOT_CONNECTED:
-                    updateConnectionTimeout(TIMEOUT_REASON_WAITING_FOR_CONNECTING);
-                    break;
-                case PHASE_NOT_AVAILABLE:
-                default:
-                    updateConnectionTimeout(TIMEOUT_REASON_NOT_AVAILABLE);
-                    break;
-            }
-        }
-
-        private void updateConnectionTimeout(int reason) {
-            if (reason != mConnectionTimeoutReason) {
-                if (mConnectionTimeoutReason != 0) {
-                    removeMessages(MSG_CONNECTION_TIMED_OUT);
-                }
-                mConnectionTimeoutReason = reason;
-                mConnectionTimeoutStartTime = SystemClock.uptimeMillis();
-                switch (reason) {
-                    case TIMEOUT_REASON_NOT_AVAILABLE:
-                    case TIMEOUT_REASON_CONNECTION_LOST:
-                        // Route became unavailable or connection lost.
-                        // Unselect it immediately.
-                        sendEmptyMessage(MSG_CONNECTION_TIMED_OUT);
-                        break;
-                    case TIMEOUT_REASON_WAITING_FOR_CONNECTING:
-                        // Waiting for route to start connecting.
-                        sendEmptyMessageDelayed(MSG_CONNECTION_TIMED_OUT, CONNECTING_TIMEOUT);
-                        break;
-                    case TIMEOUT_REASON_WAITING_FOR_CONNECTED:
-                        // Waiting for route to complete connection.
-                        sendEmptyMessageDelayed(MSG_CONNECTION_TIMED_OUT, CONNECTED_TIMEOUT);
-                        break;
-                }
-            }
-        }
-
-        private void connectionTimedOut() {
-            if (mConnectionTimeoutReason == 0 || mGloballySelectedRouteRecord == null) {
-                // Shouldn't get here.  There must be a bug somewhere.
-                Log.wtf(TAG, "Handled connection timeout for no reason.");
-                return;
-            }
-
-            switch (mConnectionTimeoutReason) {
-                case TIMEOUT_REASON_NOT_AVAILABLE:
-                    Slog.i(TAG, "Global route no longer available: "
-                            + mGloballySelectedRouteRecord);
-                    break;
-                case TIMEOUT_REASON_CONNECTION_LOST:
-                    Slog.i(TAG, "Global route connection lost: "
-                            + mGloballySelectedRouteRecord);
-                    break;
-                case TIMEOUT_REASON_WAITING_FOR_CONNECTING:
-                    Slog.i(TAG, "Global route timed out while waiting for "
-                            + "connection attempt to begin after "
-                            + (SystemClock.uptimeMillis() - mConnectionTimeoutStartTime)
-                            + " ms: " + mGloballySelectedRouteRecord);
-                    break;
-                case TIMEOUT_REASON_WAITING_FOR_CONNECTED:
-                    Slog.i(TAG, "Global route timed out while connecting after "
-                            + (SystemClock.uptimeMillis() - mConnectionTimeoutStartTime)
-                            + " ms: " + mGloballySelectedRouteRecord);
-                    break;
-            }
-            mConnectionTimeoutReason = 0;
-
-            unselectGloballySelectedRoute();
-        }
-
-        private void scheduleUpdateClientState() {
-            if (!mClientStateUpdateScheduled) {
-                mClientStateUpdateScheduled = true;
-                sendEmptyMessage(MSG_UPDATE_CLIENT_STATE);
-            }
-        }
-
-        private void updateClientState() {
-            mClientStateUpdateScheduled = false;
-
-            final String globallySelectedRouteId = mGloballySelectedRouteRecord != null ?
-                    mGloballySelectedRouteRecord.getUniqueId() : null;
-
-            // Build a new client state for trusted clients.
-            MediaRouterClientState trustedState = new MediaRouterClientState();
-            trustedState.globallySelectedRouteId = globallySelectedRouteId;
-            final int providerCount = mProviderRecords.size();
-            for (int i = 0; i < providerCount; i++) {
-                mProviderRecords.get(i).appendClientState(trustedState);
-            }
-
-            // Build a new client state for untrusted clients that can only see
-            // the currently selected route.
-            MediaRouterClientState untrustedState = new MediaRouterClientState();
-            untrustedState.globallySelectedRouteId = globallySelectedRouteId;
-            if (globallySelectedRouteId != null) {
-                untrustedState.routes.add(trustedState.getRoute(globallySelectedRouteId));
-            }
-
-            try {
-                synchronized (mService.mLock) {
-                    // Update the UserRecord.
-                    mUserRecord.mTrustedState = trustedState;
-                    mUserRecord.mUntrustedState = untrustedState;
-
-                    // Collect all clients.
-                    final int count = mUserRecord.mClientRecords.size();
-                    for (int i = 0; i < count; i++) {
-                        mTempClients.add(mUserRecord.mClientRecords.get(i).mClient);
-                    }
-                }
-
-                // Notify all clients (outside of the lock).
-                final int count = mTempClients.size();
-                for (int i = 0; i < count; i++) {
-                    try {
-                        mTempClients.get(i).onStateChanged();
-                    } catch (RemoteException ex) {
-                        // ignore errors, client probably died
-                    }
-                }
-            } finally {
-                // Clear the list in preparation for the next time.
-                mTempClients.clear();
-            }
-        }
-
-        private int findProviderRecord(RemoteDisplayProviderProxy provider) {
-            final int count = mProviderRecords.size();
-            for (int i = 0; i < count; i++) {
-                ProviderRecord record = mProviderRecords.get(i);
-                if (record.getProvider() == provider) {
-                    return i;
-                }
-            }
-            return -1;
-        }
-
-        private RouteRecord findRouteRecord(String uniqueId) {
-            final int count = mProviderRecords.size();
-            for (int i = 0; i < count; i++) {
-                RouteRecord record = mProviderRecords.get(i).findRouteByUniqueId(uniqueId);
-                if (record != null) {
-                    return record;
-                }
-            }
-            return null;
-        }
-
-        private static int getConnectionPhase(int status) {
-            switch (status) {
-                case MediaRouter.RouteInfo.STATUS_NONE:
-                case MediaRouter.RouteInfo.STATUS_CONNECTED:
-                    return PHASE_CONNECTED;
-                case MediaRouter.RouteInfo.STATUS_CONNECTING:
-                    return PHASE_CONNECTING;
-                case MediaRouter.RouteInfo.STATUS_SCANNING:
-                case MediaRouter.RouteInfo.STATUS_AVAILABLE:
-                    return PHASE_NOT_CONNECTED;
-                case MediaRouter.RouteInfo.STATUS_NOT_AVAILABLE:
-                case MediaRouter.RouteInfo.STATUS_IN_USE:
-                default:
-                    return PHASE_NOT_AVAILABLE;
-            }
-        }
-
-        static final class ProviderRecord {
-            private final RemoteDisplayProviderProxy mProvider;
-            private final String mUniquePrefix;
-            private final ArrayList<RouteRecord> mRoutes = new ArrayList<RouteRecord>();
-            private RemoteDisplayState mDescriptor;
-
-            public ProviderRecord(RemoteDisplayProviderProxy provider) {
-                mProvider = provider;
-                mUniquePrefix = provider.getFlattenedComponentName() + ":";
-            }
-
-            public RemoteDisplayProviderProxy getProvider() {
-                return mProvider;
-            }
-
-            public String getUniquePrefix() {
-                return mUniquePrefix;
-            }
-
-            public boolean updateDescriptor(RemoteDisplayState descriptor) {
-                boolean changed = false;
-                if (mDescriptor != descriptor) {
-                    mDescriptor = descriptor;
-
-                    // Update all existing routes and reorder them to match
-                    // the order of their descriptors.
-                    int targetIndex = 0;
-                    if (descriptor != null) {
-                        if (descriptor.isValid()) {
-                            final List<RemoteDisplayInfo> routeDescriptors = descriptor.displays;
-                            final int routeCount = routeDescriptors.size();
-                            for (int i = 0; i < routeCount; i++) {
-                                final RemoteDisplayInfo routeDescriptor =
-                                        routeDescriptors.get(i);
-                                final String descriptorId = routeDescriptor.id;
-                                final int sourceIndex = findRouteByDescriptorId(descriptorId);
-                                if (sourceIndex < 0) {
-                                    // Add the route to the provider.
-                                    String uniqueId = assignRouteUniqueId(descriptorId);
-                                    RouteRecord route =
-                                            new RouteRecord(this, descriptorId, uniqueId);
-                                    mRoutes.add(targetIndex++, route);
-                                    route.updateDescriptor(routeDescriptor);
-                                    changed = true;
-                                } else if (sourceIndex < targetIndex) {
-                                    // Ignore route with duplicate id.
-                                    Slog.w(TAG, "Ignoring route descriptor with duplicate id: "
-                                            + routeDescriptor);
-                                } else {
-                                    // Reorder existing route within the list.
-                                    RouteRecord route = mRoutes.get(sourceIndex);
-                                    Collections.swap(mRoutes, sourceIndex, targetIndex++);
-                                    changed |= route.updateDescriptor(routeDescriptor);
-                                }
-                            }
-                        } else {
-                            Slog.w(TAG, "Ignoring invalid descriptor from media route provider: "
-                                    + mProvider.getFlattenedComponentName());
-                        }
-                    }
-
-                    // Dispose all remaining routes that do not have matching descriptors.
-                    for (int i = mRoutes.size() - 1; i >= targetIndex; i--) {
-                        RouteRecord route = mRoutes.remove(i);
-                        route.updateDescriptor(null); // mark route invalid
-                        changed = true;
-                    }
-                }
-                return changed;
-            }
-
-            public void appendClientState(MediaRouterClientState state) {
-                final int routeCount = mRoutes.size();
-                for (int i = 0; i < routeCount; i++) {
-                    state.routes.add(mRoutes.get(i).getInfo());
-                }
-            }
-
-            public RouteRecord findRouteByUniqueId(String uniqueId) {
-                final int routeCount = mRoutes.size();
-                for (int i = 0; i < routeCount; i++) {
-                    RouteRecord route = mRoutes.get(i);
-                    if (route.getUniqueId().equals(uniqueId)) {
-                        return route;
-                    }
-                }
-                return null;
-            }
-
-            private int findRouteByDescriptorId(String descriptorId) {
-                final int routeCount = mRoutes.size();
-                for (int i = 0; i < routeCount; i++) {
-                    RouteRecord route = mRoutes.get(i);
-                    if (route.getDescriptorId().equals(descriptorId)) {
-                        return i;
-                    }
-                }
-                return -1;
-            }
-
-            public void dump(PrintWriter pw, String prefix) {
-                pw.println(prefix + this);
-
-                final String indent = prefix + "  ";
-                mProvider.dump(pw, indent);
-
-                final int routeCount = mRoutes.size();
-                if (routeCount != 0) {
-                    for (int i = 0; i < routeCount; i++) {
-                        mRoutes.get(i).dump(pw, indent);
-                    }
-                } else {
-                    pw.println(indent + "<no routes>");
-                }
-            }
-
-            @Override
-            public String toString() {
-                return "Provider " + mProvider.getFlattenedComponentName();
-            }
-
-            private String assignRouteUniqueId(String descriptorId) {
-                return mUniquePrefix + descriptorId;
-            }
-        }
-
-        static final class RouteRecord {
-            private final ProviderRecord mProviderRecord;
-            private final String mDescriptorId;
-            private final MediaRouterClientState.RouteInfo mMutableInfo;
-            private MediaRouterClientState.RouteInfo mImmutableInfo;
-            private RemoteDisplayInfo mDescriptor;
-
-            public RouteRecord(ProviderRecord providerRecord,
-                    String descriptorId, String uniqueId) {
-                mProviderRecord = providerRecord;
-                mDescriptorId = descriptorId;
-                mMutableInfo = new MediaRouterClientState.RouteInfo(uniqueId);
-            }
-
-            public RemoteDisplayProviderProxy getProvider() {
-                return mProviderRecord.getProvider();
-            }
-
-            public ProviderRecord getProviderRecord() {
-                return mProviderRecord;
-            }
-
-            public String getDescriptorId() {
-                return mDescriptorId;
-            }
-
-            public String getUniqueId() {
-                return mMutableInfo.id;
-            }
-
-            public MediaRouterClientState.RouteInfo getInfo() {
-                if (mImmutableInfo == null) {
-                    mImmutableInfo = new MediaRouterClientState.RouteInfo(mMutableInfo);
-                }
-                return mImmutableInfo;
-            }
-
-            public boolean isValid() {
-                return mDescriptor != null;
-            }
-
-            public boolean isEnabled() {
-                return mMutableInfo.enabled;
-            }
-
-            public int getStatus() {
-                return mMutableInfo.statusCode;
-            }
-
-            public boolean updateDescriptor(RemoteDisplayInfo descriptor) {
-                boolean changed = false;
-                if (mDescriptor != descriptor) {
-                    mDescriptor = descriptor;
-                    if (descriptor != null) {
-                        final String name = computeName(descriptor);
-                        if (!Objects.equal(mMutableInfo.name, name)) {
-                            mMutableInfo.name = name;
-                            changed = true;
-                        }
-                        final String description = computeDescription(descriptor);
-                        if (!Objects.equal(mMutableInfo.description, description)) {
-                            mMutableInfo.description = description;
-                            changed = true;
-                        }
-                        final int supportedTypes = computeSupportedTypes(descriptor);
-                        if (mMutableInfo.supportedTypes != supportedTypes) {
-                            mMutableInfo.supportedTypes = supportedTypes;
-                            changed = true;
-                        }
-                        final boolean enabled = computeEnabled(descriptor);
-                        if (mMutableInfo.enabled != enabled) {
-                            mMutableInfo.enabled = enabled;
-                            changed = true;
-                        }
-                        final int statusCode = computeStatusCode(descriptor);
-                        if (mMutableInfo.statusCode != statusCode) {
-                            mMutableInfo.statusCode = statusCode;
-                            changed = true;
-                        }
-                        final int playbackType = computePlaybackType(descriptor);
-                        if (mMutableInfo.playbackType != playbackType) {
-                            mMutableInfo.playbackType = playbackType;
-                            changed = true;
-                        }
-                        final int playbackStream = computePlaybackStream(descriptor);
-                        if (mMutableInfo.playbackStream != playbackStream) {
-                            mMutableInfo.playbackStream = playbackStream;
-                            changed = true;
-                        }
-                        final int volume = computeVolume(descriptor);
-                        if (mMutableInfo.volume != volume) {
-                            mMutableInfo.volume = volume;
-                            changed = true;
-                        }
-                        final int volumeMax = computeVolumeMax(descriptor);
-                        if (mMutableInfo.volumeMax != volumeMax) {
-                            mMutableInfo.volumeMax = volumeMax;
-                            changed = true;
-                        }
-                        final int volumeHandling = computeVolumeHandling(descriptor);
-                        if (mMutableInfo.volumeHandling != volumeHandling) {
-                            mMutableInfo.volumeHandling = volumeHandling;
-                            changed = true;
-                        }
-                        final int presentationDisplayId = computePresentationDisplayId(descriptor);
-                        if (mMutableInfo.presentationDisplayId != presentationDisplayId) {
-                            mMutableInfo.presentationDisplayId = presentationDisplayId;
-                            changed = true;
-                        }
-                    }
-                }
-                if (changed) {
-                    mImmutableInfo = null;
-                }
-                return changed;
-            }
-
-            public void dump(PrintWriter pw, String prefix) {
-                pw.println(prefix + this);
-
-                final String indent = prefix + "  ";
-                pw.println(indent + "mMutableInfo=" + mMutableInfo);
-                pw.println(indent + "mDescriptorId=" + mDescriptorId);
-                pw.println(indent + "mDescriptor=" + mDescriptor);
-            }
-
-            @Override
-            public String toString() {
-                return "Route " + mMutableInfo.name + " (" + mMutableInfo.id + ")";
-            }
-
-            private static String computeName(RemoteDisplayInfo descriptor) {
-                // Note that isValid() already ensures the name is non-empty.
-                return descriptor.name;
-            }
-
-            private static String computeDescription(RemoteDisplayInfo descriptor) {
-                final String description = descriptor.description;
-                return TextUtils.isEmpty(description) ? null : description;
-            }
-
-            private static int computeSupportedTypes(RemoteDisplayInfo descriptor) {
-                return MediaRouter.ROUTE_TYPE_LIVE_AUDIO
-                        | MediaRouter.ROUTE_TYPE_LIVE_VIDEO
-                        | MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY;
-            }
-
-            private static boolean computeEnabled(RemoteDisplayInfo descriptor) {
-                switch (descriptor.status) {
-                    case RemoteDisplayInfo.STATUS_CONNECTED:
-                    case RemoteDisplayInfo.STATUS_CONNECTING:
-                    case RemoteDisplayInfo.STATUS_AVAILABLE:
-                        return true;
-                    default:
-                        return false;
-                }
-            }
-
-            private static int computeStatusCode(RemoteDisplayInfo descriptor) {
-                switch (descriptor.status) {
-                    case RemoteDisplayInfo.STATUS_NOT_AVAILABLE:
-                        return MediaRouter.RouteInfo.STATUS_NOT_AVAILABLE;
-                    case RemoteDisplayInfo.STATUS_AVAILABLE:
-                        return MediaRouter.RouteInfo.STATUS_AVAILABLE;
-                    case RemoteDisplayInfo.STATUS_IN_USE:
-                        return MediaRouter.RouteInfo.STATUS_IN_USE;
-                    case RemoteDisplayInfo.STATUS_CONNECTING:
-                        return MediaRouter.RouteInfo.STATUS_CONNECTING;
-                    case RemoteDisplayInfo.STATUS_CONNECTED:
-                        return MediaRouter.RouteInfo.STATUS_CONNECTED;
-                    default:
-                        return MediaRouter.RouteInfo.STATUS_NONE;
-                }
-            }
-
-            private static int computePlaybackType(RemoteDisplayInfo descriptor) {
-                return MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE;
-            }
-
-            private static int computePlaybackStream(RemoteDisplayInfo descriptor) {
-                return AudioSystem.STREAM_MUSIC;
-            }
-
-            private static int computeVolume(RemoteDisplayInfo descriptor) {
-                final int volume = descriptor.volume;
-                final int volumeMax = descriptor.volumeMax;
-                if (volume < 0) {
-                    return 0;
-                } else if (volume > volumeMax) {
-                    return volumeMax;
-                }
-                return volume;
-            }
-
-            private static int computeVolumeMax(RemoteDisplayInfo descriptor) {
-                final int volumeMax = descriptor.volumeMax;
-                return volumeMax > 0 ? volumeMax : 0;
-            }
-
-            private static int computeVolumeHandling(RemoteDisplayInfo descriptor) {
-                final int volumeHandling = descriptor.volumeHandling;
-                switch (volumeHandling) {
-                    case RemoteDisplayInfo.PLAYBACK_VOLUME_VARIABLE:
-                        return MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE;
-                    case RemoteDisplayInfo.PLAYBACK_VOLUME_FIXED:
-                    default:
-                        return MediaRouter.RouteInfo.PLAYBACK_VOLUME_FIXED;
-                }
-            }
-
-            private static int computePresentationDisplayId(RemoteDisplayInfo descriptor) {
-                // The MediaRouter class validates that the id corresponds to an extant
-                // presentation display.  So all we do here is canonicalize the null case.
-                final int displayId = descriptor.presentationDisplayId;
-                return displayId < 0 ? -1 : displayId;
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/media/RemoteDisplayProviderProxy.java b/services/java/com/android/server/media/RemoteDisplayProviderProxy.java
deleted file mode 100644
index b248ee0..0000000
--- a/services/java/com/android/server/media/RemoteDisplayProviderProxy.java
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Copyright (C) 2013 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.media;
-
-import com.android.internal.util.Objects;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.media.IRemoteDisplayCallback;
-import android.media.IRemoteDisplayProvider;
-import android.media.RemoteDisplayState;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.IBinder.DeathRecipient;
-import android.os.UserHandle;
-import android.util.Log;
-import android.util.Slog;
-
-import java.io.PrintWriter;
-import java.lang.ref.WeakReference;
-
-/**
- * Maintains a connection to a particular remote display provider service.
- */
-final class RemoteDisplayProviderProxy implements ServiceConnection {
-    private static final String TAG = "RemoteDisplayProvider";  // max. 23 chars
-    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
-
-    private final Context mContext;
-    private final ComponentName mComponentName;
-    private final int mUserId;
-    private final Handler mHandler;
-
-    private Callback mDisplayStateCallback;
-
-    // Connection state
-    private boolean mRunning;
-    private boolean mBound;
-    private Connection mActiveConnection;
-    private boolean mConnectionReady;
-
-    // Logical state
-    private int mDiscoveryMode;
-    private String mSelectedDisplayId;
-    private RemoteDisplayState mDisplayState;
-    private boolean mScheduledDisplayStateChangedCallback;
-
-    public RemoteDisplayProviderProxy(Context context, ComponentName componentName,
-            int userId) {
-        mContext = context;
-        mComponentName = componentName;
-        mUserId = userId;
-        mHandler = new Handler();
-    }
-
-    public void dump(PrintWriter pw, String prefix) {
-        pw.println(prefix + "Proxy");
-        pw.println(prefix + "  mUserId=" + mUserId);
-        pw.println(prefix + "  mRunning=" + mRunning);
-        pw.println(prefix + "  mBound=" + mBound);
-        pw.println(prefix + "  mActiveConnection=" + mActiveConnection);
-        pw.println(prefix + "  mConnectionReady=" + mConnectionReady);
-        pw.println(prefix + "  mDiscoveryMode=" + mDiscoveryMode);
-        pw.println(prefix + "  mSelectedDisplayId=" + mSelectedDisplayId);
-        pw.println(prefix + "  mDisplayState=" + mDisplayState);
-    }
-
-    public void setCallback(Callback callback) {
-        mDisplayStateCallback = callback;
-    }
-
-    public RemoteDisplayState getDisplayState() {
-        return mDisplayState;
-    }
-
-    public void setDiscoveryMode(int mode) {
-        if (mDiscoveryMode != mode) {
-            mDiscoveryMode = mode;
-            if (mConnectionReady) {
-                mActiveConnection.setDiscoveryMode(mode);
-            }
-            updateBinding();
-        }
-    }
-
-    public void setSelectedDisplay(String id) {
-        if (!Objects.equal(mSelectedDisplayId, id)) {
-            if (mConnectionReady && mSelectedDisplayId != null) {
-                mActiveConnection.disconnect(mSelectedDisplayId);
-            }
-            mSelectedDisplayId = id;
-            if (mConnectionReady && id != null) {
-                mActiveConnection.connect(id);
-            }
-            updateBinding();
-        }
-    }
-
-    public void setDisplayVolume(int volume) {
-        if (mConnectionReady && mSelectedDisplayId != null) {
-            mActiveConnection.setVolume(mSelectedDisplayId, volume);
-        }
-    }
-
-    public void adjustDisplayVolume(int delta) {
-        if (mConnectionReady && mSelectedDisplayId != null) {
-            mActiveConnection.adjustVolume(mSelectedDisplayId, delta);
-        }
-    }
-
-    public boolean hasComponentName(String packageName, String className) {
-        return mComponentName.getPackageName().equals(packageName)
-                && mComponentName.getClassName().equals(className);
-    }
-
-    public String getFlattenedComponentName() {
-        return mComponentName.flattenToShortString();
-    }
-
-    public void start() {
-        if (!mRunning) {
-            if (DEBUG) {
-                Slog.d(TAG, this + ": Starting");
-            }
-
-            mRunning = true;
-            updateBinding();
-        }
-    }
-
-    public void stop() {
-        if (mRunning) {
-            if (DEBUG) {
-                Slog.d(TAG, this + ": Stopping");
-            }
-
-            mRunning = false;
-            updateBinding();
-        }
-    }
-
-    public void rebindIfDisconnected() {
-        if (mActiveConnection == null && shouldBind()) {
-            unbind();
-            bind();
-        }
-    }
-
-    private void updateBinding() {
-        if (shouldBind()) {
-            bind();
-        } else {
-            unbind();
-        }
-    }
-
-    private boolean shouldBind() {
-        if (mRunning) {
-            // Bind whenever there is a discovery request or selected display.
-            if (mDiscoveryMode != RemoteDisplayState.DISCOVERY_MODE_NONE
-                    || mSelectedDisplayId != null) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private void bind() {
-        if (!mBound) {
-            if (DEBUG) {
-                Slog.d(TAG, this + ": Binding");
-            }
-
-            Intent service = new Intent(RemoteDisplayState.SERVICE_INTERFACE);
-            service.setComponent(mComponentName);
-            try {
-                mBound = mContext.bindServiceAsUser(service, this, Context.BIND_AUTO_CREATE,
-                        new UserHandle(mUserId));
-                if (!mBound && DEBUG) {
-                    Slog.d(TAG, this + ": Bind failed");
-                }
-            } catch (SecurityException ex) {
-                if (DEBUG) {
-                    Slog.d(TAG, this + ": Bind failed", ex);
-                }
-            }
-        }
-    }
-
-    private void unbind() {
-        if (mBound) {
-            if (DEBUG) {
-                Slog.d(TAG, this + ": Unbinding");
-            }
-
-            mBound = false;
-            disconnect();
-            mContext.unbindService(this);
-        }
-    }
-
-    @Override
-    public void onServiceConnected(ComponentName name, IBinder service) {
-        if (DEBUG) {
-            Slog.d(TAG, this + ": Connected");
-        }
-
-        if (mBound) {
-            disconnect();
-
-            IRemoteDisplayProvider provider = IRemoteDisplayProvider.Stub.asInterface(service);
-            if (provider != null) {
-                Connection connection = new Connection(provider);
-                if (connection.register()) {
-                    mActiveConnection = connection;
-                } else {
-                    if (DEBUG) {
-                        Slog.d(TAG, this + ": Registration failed");
-                    }
-                }
-            } else {
-                Slog.e(TAG, this + ": Service returned invalid remote display provider binder");
-            }
-        }
-    }
-
-    @Override
-    public void onServiceDisconnected(ComponentName name) {
-        if (DEBUG) {
-            Slog.d(TAG, this + ": Service disconnected");
-        }
-        disconnect();
-    }
-
-    private void onConnectionReady(Connection connection) {
-        if (mActiveConnection == connection) {
-            mConnectionReady = true;
-
-            if (mDiscoveryMode != RemoteDisplayState.DISCOVERY_MODE_NONE) {
-                mActiveConnection.setDiscoveryMode(mDiscoveryMode);
-            }
-            if (mSelectedDisplayId != null) {
-                mActiveConnection.connect(mSelectedDisplayId);
-            }
-        }
-    }
-
-    private void onConnectionDied(Connection connection) {
-        if (mActiveConnection == connection) {
-            if (DEBUG) {
-                Slog.d(TAG, this + ": Service connection died");
-            }
-            disconnect();
-        }
-    }
-
-    private void onDisplayStateChanged(Connection connection, RemoteDisplayState state) {
-        if (mActiveConnection == connection) {
-            if (DEBUG) {
-                Slog.d(TAG, this + ": State changed, state=" + state);
-            }
-            setDisplayState(state);
-        }
-    }
-
-    private void disconnect() {
-        if (mActiveConnection != null) {
-            if (mSelectedDisplayId != null) {
-                mActiveConnection.disconnect(mSelectedDisplayId);
-            }
-            mConnectionReady = false;
-            mActiveConnection.dispose();
-            mActiveConnection = null;
-            setDisplayState(null);
-        }
-    }
-
-    private void setDisplayState(RemoteDisplayState state) {
-        if (!Objects.equal(mDisplayState, state)) {
-            mDisplayState = state;
-            if (!mScheduledDisplayStateChangedCallback) {
-                mScheduledDisplayStateChangedCallback = true;
-                mHandler.post(mDisplayStateChanged);
-            }
-        }
-    }
-
-    @Override
-    public String toString() {
-        return "Service connection " + mComponentName.flattenToShortString();
-    }
-
-    private final Runnable mDisplayStateChanged = new Runnable() {
-        @Override
-        public void run() {
-            mScheduledDisplayStateChangedCallback = false;
-            if (mDisplayStateCallback != null) {
-                mDisplayStateCallback.onDisplayStateChanged(
-                        RemoteDisplayProviderProxy.this, mDisplayState);
-            }
-        }
-    };
-
-    public interface Callback {
-        void onDisplayStateChanged(RemoteDisplayProviderProxy provider, RemoteDisplayState state);
-    }
-
-    private final class Connection implements DeathRecipient {
-        private final IRemoteDisplayProvider mProvider;
-        private final ProviderCallback mCallback;
-
-        public Connection(IRemoteDisplayProvider provider) {
-            mProvider = provider;
-            mCallback = new ProviderCallback(this);
-        }
-
-        public boolean register() {
-            try {
-                mProvider.asBinder().linkToDeath(this, 0);
-                mProvider.setCallback(mCallback);
-                mHandler.post(new Runnable() {
-                    @Override
-                    public void run() {
-                        onConnectionReady(Connection.this);
-                    }
-                });
-                return true;
-            } catch (RemoteException ex) {
-                binderDied();
-            }
-            return false;
-        }
-
-        public void dispose() {
-            mProvider.asBinder().unlinkToDeath(this, 0);
-            mCallback.dispose();
-        }
-
-        public void setDiscoveryMode(int mode) {
-            try {
-                mProvider.setDiscoveryMode(mode);
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Failed to deliver request to set discovery mode.", ex);
-            }
-        }
-
-        public void connect(String id) {
-            try {
-                mProvider.connect(id);
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Failed to deliver request to connect to display.", ex);
-            }
-        }
-
-        public void disconnect(String id) {
-            try {
-                mProvider.disconnect(id);
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Failed to deliver request to disconnect from display.", ex);
-            }
-        }
-
-        public void setVolume(String id, int volume) {
-            try {
-                mProvider.setVolume(id, volume);
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Failed to deliver request to set display volume.", ex);
-            }
-        }
-
-        public void adjustVolume(String id, int volume) {
-            try {
-                mProvider.adjustVolume(id, volume);
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Failed to deliver request to adjust display volume.", ex);
-            }
-        }
-
-        @Override
-        public void binderDied() {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    onConnectionDied(Connection.this);
-                }
-            });
-        }
-
-        void postStateChanged(final RemoteDisplayState state) {
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    onDisplayStateChanged(Connection.this, state);
-                }
-            });
-        }
-    }
-
-    /**
-     * Receives callbacks from the service.
-     * <p>
-     * This inner class is static and only retains a weak reference to the connection
-     * to prevent the client from being leaked in case the service is holding an
-     * active reference to the client's callback.
-     * </p>
-     */
-    private static final class ProviderCallback extends IRemoteDisplayCallback.Stub {
-        private final WeakReference<Connection> mConnectionRef;
-
-        public ProviderCallback(Connection connection) {
-            mConnectionRef = new WeakReference<Connection>(connection);
-        }
-
-        public void dispose() {
-            mConnectionRef.clear();
-        }
-
-        @Override
-        public void onStateChanged(RemoteDisplayState state) throws RemoteException {
-            Connection connection = mConnectionRef.get();
-            if (connection != null) {
-                connection.postStateChanged(state);
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
deleted file mode 100644
index d568b11..0000000
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ /dev/null
@@ -1,2089 +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.server.net;
-
-import static android.Manifest.permission.ACCESS_NETWORK_STATE;
-import static android.Manifest.permission.CONNECTIVITY_INTERNAL;
-import static android.Manifest.permission.DUMP;
-import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
-import static android.Manifest.permission.READ_NETWORK_USAGE_HISTORY;
-import static android.Manifest.permission.READ_PHONE_STATE;
-import static android.content.Intent.ACTION_PACKAGE_ADDED;
-import static android.content.Intent.ACTION_UID_REMOVED;
-import static android.content.Intent.ACTION_USER_ADDED;
-import static android.content.Intent.ACTION_USER_REMOVED;
-import static android.content.Intent.EXTRA_UID;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
-import static android.net.ConnectivityManager.TYPE_ETHERNET;
-import static android.net.ConnectivityManager.TYPE_MOBILE;
-import static android.net.ConnectivityManager.TYPE_WIFI;
-import static android.net.ConnectivityManager.TYPE_WIMAX;
-import static android.net.ConnectivityManager.isNetworkTypeMobile;
-import static android.net.NetworkPolicy.CYCLE_NONE;
-import static android.net.NetworkPolicy.LIMIT_DISABLED;
-import static android.net.NetworkPolicy.SNOOZE_NEVER;
-import static android.net.NetworkPolicy.WARNING_DISABLED;
-import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE;
-import static android.net.NetworkPolicyManager.POLICY_NONE;
-import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
-import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
-import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
-import static android.net.NetworkPolicyManager.computeLastCycleBoundary;
-import static android.net.NetworkPolicyManager.dumpPolicy;
-import static android.net.NetworkPolicyManager.dumpRules;
-import static android.net.NetworkTemplate.MATCH_ETHERNET;
-import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER;
-import static android.net.NetworkTemplate.MATCH_MOBILE_4G;
-import static android.net.NetworkTemplate.MATCH_MOBILE_ALL;
-import static android.net.NetworkTemplate.MATCH_WIFI;
-import static android.net.NetworkTemplate.buildTemplateMobileAll;
-import static android.net.TrafficStats.MB_IN_BYTES;
-import static android.net.wifi.WifiManager.CHANGE_REASON_ADDED;
-import static android.net.wifi.WifiManager.CHANGE_REASON_REMOVED;
-import static android.net.wifi.WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION;
-import static android.net.wifi.WifiManager.EXTRA_CHANGE_REASON;
-import static android.net.wifi.WifiManager.EXTRA_NETWORK_INFO;
-import static android.net.wifi.WifiManager.EXTRA_WIFI_CONFIGURATION;
-import static android.net.wifi.WifiManager.EXTRA_WIFI_INFO;
-import static android.telephony.TelephonyManager.SIM_STATE_READY;
-import static android.text.format.DateUtils.DAY_IN_MILLIS;
-import static com.android.internal.util.ArrayUtils.appendInt;
-import static com.android.internal.util.Preconditions.checkNotNull;
-import static com.android.internal.util.XmlUtils.readBooleanAttribute;
-import static com.android.internal.util.XmlUtils.readIntAttribute;
-import static com.android.internal.util.XmlUtils.readLongAttribute;
-import static com.android.internal.util.XmlUtils.writeBooleanAttribute;
-import static com.android.internal.util.XmlUtils.writeIntAttribute;
-import static com.android.internal.util.XmlUtils.writeLongAttribute;
-import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT;
-import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_UPDATED;
-import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
-import static org.xmlpull.v1.XmlPullParser.START_TAG;
-
-import android.app.IActivityManager;
-import android.app.INotificationManager;
-import android.app.IProcessObserver;
-import android.app.Notification;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.UserInfo;
-import android.content.res.Resources;
-import android.net.ConnectivityManager;
-import android.net.IConnectivityManager;
-import android.net.INetworkManagementEventObserver;
-import android.net.INetworkPolicyListener;
-import android.net.INetworkPolicyManager;
-import android.net.INetworkStatsService;
-import android.net.NetworkIdentity;
-import android.net.NetworkInfo;
-import android.net.NetworkPolicy;
-import android.net.NetworkQuotaInfo;
-import android.net.NetworkState;
-import android.net.NetworkTemplate;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.Binder;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.INetworkManagementService;
-import android.os.IPowerManager;
-import android.os.Message;
-import android.os.MessageQueue.IdleHandler;
-import android.os.RemoteCallbackList;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.provider.Settings;
-import android.telephony.TelephonyManager;
-import android.text.format.Formatter;
-import android.text.format.Time;
-import android.util.AtomicFile;
-import android.util.Log;
-import android.util.NtpTrustedTime;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.SparseBooleanArray;
-import android.util.SparseIntArray;
-import android.util.TrustedTime;
-import android.util.Xml;
-
-import com.android.internal.R;
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.Objects;
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
-import com.google.android.collect.Sets;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import libcore.io.IoUtils;
-
-/**
- * Service that maintains low-level network policy rules, using
- * {@link NetworkStatsService} statistics to drive those rules.
- * <p>
- * Derives active rules by combining a given policy with other system status,
- * and delivers to listeners, such as {@link ConnectivityManager}, for
- * enforcement.
- */
-public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
-    private static final String TAG = "NetworkPolicy";
-    private static final boolean LOGD = false;
-    private static final boolean LOGV = false;
-
-    private static final int VERSION_INIT = 1;
-    private static final int VERSION_ADDED_SNOOZE = 2;
-    private static final int VERSION_ADDED_RESTRICT_BACKGROUND = 3;
-    private static final int VERSION_ADDED_METERED = 4;
-    private static final int VERSION_SPLIT_SNOOZE = 5;
-    private static final int VERSION_ADDED_TIMEZONE = 6;
-    private static final int VERSION_ADDED_INFERRED = 7;
-    private static final int VERSION_SWITCH_APP_ID = 8;
-    private static final int VERSION_ADDED_NETWORK_ID = 9;
-    private static final int VERSION_SWITCH_UID = 10;
-    private static final int VERSION_LATEST = VERSION_SWITCH_UID;
-
-    @VisibleForTesting
-    public static final int TYPE_WARNING = 0x1;
-    @VisibleForTesting
-    public static final int TYPE_LIMIT = 0x2;
-    @VisibleForTesting
-    public static final int TYPE_LIMIT_SNOOZED = 0x3;
-
-    private static final String TAG_POLICY_LIST = "policy-list";
-    private static final String TAG_NETWORK_POLICY = "network-policy";
-    private static final String TAG_UID_POLICY = "uid-policy";
-    private static final String TAG_APP_POLICY = "app-policy";
-
-    private static final String ATTR_VERSION = "version";
-    private static final String ATTR_RESTRICT_BACKGROUND = "restrictBackground";
-    private static final String ATTR_NETWORK_TEMPLATE = "networkTemplate";
-    private static final String ATTR_SUBSCRIBER_ID = "subscriberId";
-    private static final String ATTR_NETWORK_ID = "networkId";
-    private static final String ATTR_CYCLE_DAY = "cycleDay";
-    private static final String ATTR_CYCLE_TIMEZONE = "cycleTimezone";
-    private static final String ATTR_WARNING_BYTES = "warningBytes";
-    private static final String ATTR_LIMIT_BYTES = "limitBytes";
-    private static final String ATTR_LAST_SNOOZE = "lastSnooze";
-    private static final String ATTR_LAST_WARNING_SNOOZE = "lastWarningSnooze";
-    private static final String ATTR_LAST_LIMIT_SNOOZE = "lastLimitSnooze";
-    private static final String ATTR_METERED = "metered";
-    private static final String ATTR_INFERRED = "inferred";
-    private static final String ATTR_UID = "uid";
-    private static final String ATTR_APP_ID = "appId";
-    private static final String ATTR_POLICY = "policy";
-
-    private static final String TAG_ALLOW_BACKGROUND = TAG + ":allowBackground";
-
-    private static final String ACTION_ALLOW_BACKGROUND =
-            "com.android.server.net.action.ALLOW_BACKGROUND";
-    private static final String ACTION_SNOOZE_WARNING =
-            "com.android.server.net.action.SNOOZE_WARNING";
-
-    private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
-
-    private static final int MSG_RULES_CHANGED = 1;
-    private static final int MSG_METERED_IFACES_CHANGED = 2;
-    private static final int MSG_FOREGROUND_ACTIVITIES_CHANGED = 3;
-    private static final int MSG_PROCESS_DIED = 4;
-    private static final int MSG_LIMIT_REACHED = 5;
-    private static final int MSG_RESTRICT_BACKGROUND_CHANGED = 6;
-    private static final int MSG_ADVISE_PERSIST_THRESHOLD = 7;
-    private static final int MSG_SCREEN_ON_CHANGED = 8;
-
-    private final Context mContext;
-    private final IActivityManager mActivityManager;
-    private final IPowerManager mPowerManager;
-    private final INetworkStatsService mNetworkStats;
-    private final INetworkManagementService mNetworkManager;
-    private final TrustedTime mTime;
-
-    private IConnectivityManager mConnManager;
-    private INotificationManager mNotifManager;
-
-    private final Object mRulesLock = new Object();
-
-    private volatile boolean mScreenOn;
-    private volatile boolean mRestrictBackground;
-
-    private final boolean mSuppressDefaultPolicy;
-
-    /** Defined network policies. */
-    private HashMap<NetworkTemplate, NetworkPolicy> mNetworkPolicy = Maps.newHashMap();
-    /** Currently active network rules for ifaces. */
-    private HashMap<NetworkPolicy, String[]> mNetworkRules = Maps.newHashMap();
-
-    /** Defined UID policies. */
-    private SparseIntArray mUidPolicy = new SparseIntArray();
-    /** Currently derived rules for each UID. */
-    private SparseIntArray mUidRules = new SparseIntArray();
-
-    /** Set of ifaces that are metered. */
-    private HashSet<String> mMeteredIfaces = Sets.newHashSet();
-    /** Set of over-limit templates that have been notified. */
-    private HashSet<NetworkTemplate> mOverLimitNotified = Sets.newHashSet();
-
-    /** Set of currently active {@link Notification} tags. */
-    private HashSet<String> mActiveNotifs = Sets.newHashSet();
-
-    /** Foreground at both UID and PID granularity. */
-    private SparseBooleanArray mUidForeground = new SparseBooleanArray();
-    private SparseArray<SparseBooleanArray> mUidPidForeground = new SparseArray<
-            SparseBooleanArray>();
-
-    private final RemoteCallbackList<INetworkPolicyListener> mListeners = new RemoteCallbackList<
-            INetworkPolicyListener>();
-
-    private final Handler mHandler;
-
-    private final AtomicFile mPolicyFile;
-
-    // TODO: keep whitelist of system-critical services that should never have
-    // rules enforced, such as system, phone, and radio UIDs.
-
-    // TODO: migrate notifications to SystemUI
-
-    public NetworkPolicyManagerService(Context context, IActivityManager activityManager,
-            IPowerManager powerManager, INetworkStatsService networkStats,
-            INetworkManagementService networkManagement) {
-        this(context, activityManager, powerManager, networkStats, networkManagement,
-                NtpTrustedTime.getInstance(context), getSystemDir(), false);
-    }
-
-    private static File getSystemDir() {
-        return new File(Environment.getDataDirectory(), "system");
-    }
-
-    public NetworkPolicyManagerService(Context context, IActivityManager activityManager,
-            IPowerManager powerManager, INetworkStatsService networkStats,
-            INetworkManagementService networkManagement, TrustedTime time, File systemDir,
-            boolean suppressDefaultPolicy) {
-        mContext = checkNotNull(context, "missing context");
-        mActivityManager = checkNotNull(activityManager, "missing activityManager");
-        mPowerManager = checkNotNull(powerManager, "missing powerManager");
-        mNetworkStats = checkNotNull(networkStats, "missing networkStats");
-        mNetworkManager = checkNotNull(networkManagement, "missing networkManagement");
-        mTime = checkNotNull(time, "missing TrustedTime");
-
-        HandlerThread thread = new HandlerThread(TAG);
-        thread.start();
-        mHandler = new Handler(thread.getLooper(), mHandlerCallback);
-
-        mSuppressDefaultPolicy = suppressDefaultPolicy;
-
-        mPolicyFile = new AtomicFile(new File(systemDir, "netpolicy.xml"));
-    }
-
-    public void bindConnectivityManager(IConnectivityManager connManager) {
-        mConnManager = checkNotNull(connManager, "missing IConnectivityManager");
-    }
-
-    public void bindNotificationManager(INotificationManager notifManager) {
-        mNotifManager = checkNotNull(notifManager, "missing INotificationManager");
-    }
-
-    public void systemReady() {
-        if (!isBandwidthControlEnabled()) {
-            Slog.w(TAG, "bandwidth controls disabled, unable to enforce policy");
-            return;
-        }
-
-        synchronized (mRulesLock) {
-            // read policy from disk
-            readPolicyLocked();
-
-            if (mRestrictBackground) {
-                updateRulesForRestrictBackgroundLocked();
-                updateNotificationsLocked();
-            }
-        }
-
-        updateScreenOn();
-
-        try {
-            mActivityManager.registerProcessObserver(mProcessObserver);
-            mNetworkManager.registerObserver(mAlertObserver);
-        } catch (RemoteException e) {
-            // ignored; both services live in system_server
-        }
-
-        // TODO: traverse existing processes to know foreground state, or have
-        // activitymanager dispatch current state when new observer attached.
-
-        final IntentFilter screenFilter = new IntentFilter();
-        screenFilter.addAction(Intent.ACTION_SCREEN_ON);
-        screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
-        mContext.registerReceiver(mScreenReceiver, screenFilter);
-
-        // watch for network interfaces to be claimed
-        final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION_IMMEDIATE);
-        mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
-
-        // listen for package changes to update policy
-        final IntentFilter packageFilter = new IntentFilter();
-        packageFilter.addAction(ACTION_PACKAGE_ADDED);
-        packageFilter.addDataScheme("package");
-        mContext.registerReceiver(mPackageReceiver, packageFilter, null, mHandler);
-
-        // listen for UID changes to update policy
-        mContext.registerReceiver(
-                mUidRemovedReceiver, new IntentFilter(ACTION_UID_REMOVED), null, mHandler);
-
-        // listen for user changes to update policy
-        final IntentFilter userFilter = new IntentFilter();
-        userFilter.addAction(ACTION_USER_ADDED);
-        userFilter.addAction(ACTION_USER_REMOVED);
-        mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);
-
-        // listen for stats update events
-        final IntentFilter statsFilter = new IntentFilter(ACTION_NETWORK_STATS_UPDATED);
-        mContext.registerReceiver(
-                mStatsReceiver, statsFilter, READ_NETWORK_USAGE_HISTORY, mHandler);
-
-        // listen for restrict background changes from notifications
-        final IntentFilter allowFilter = new IntentFilter(ACTION_ALLOW_BACKGROUND);
-        mContext.registerReceiver(mAllowReceiver, allowFilter, MANAGE_NETWORK_POLICY, mHandler);
-
-        // listen for snooze warning from notifications
-        final IntentFilter snoozeWarningFilter = new IntentFilter(ACTION_SNOOZE_WARNING);
-        mContext.registerReceiver(mSnoozeWarningReceiver, snoozeWarningFilter,
-                MANAGE_NETWORK_POLICY, mHandler);
-
-        // listen for configured wifi networks to be removed
-        final IntentFilter wifiConfigFilter = new IntentFilter(CONFIGURED_NETWORKS_CHANGED_ACTION);
-        mContext.registerReceiver(
-                mWifiConfigReceiver, wifiConfigFilter, CONNECTIVITY_INTERNAL, mHandler);
-
-        // listen for wifi state changes to catch metered hint
-        final IntentFilter wifiStateFilter = new IntentFilter(
-                WifiManager.NETWORK_STATE_CHANGED_ACTION);
-        mContext.registerReceiver(
-                mWifiStateReceiver, wifiStateFilter, CONNECTIVITY_INTERNAL, mHandler);
-
-    }
-
-    private IProcessObserver mProcessObserver = new IProcessObserver.Stub() {
-        @Override
-        public void onForegroundActivitiesChanged(int pid, int uid, boolean foregroundActivities) {
-            mHandler.obtainMessage(MSG_FOREGROUND_ACTIVITIES_CHANGED,
-                    pid, uid, foregroundActivities).sendToTarget();
-        }
-
-        @Override
-        public void onImportanceChanged(int pid, int uid, int importance) {
-        }
-
-        @Override
-        public void onProcessDied(int pid, int uid) {
-            mHandler.obtainMessage(MSG_PROCESS_DIED, pid, uid).sendToTarget();
-        }
-    };
-
-    private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // screen-related broadcasts are protected by system, no need
-            // for permissions check.
-            mHandler.obtainMessage(MSG_SCREEN_ON_CHANGED).sendToTarget();
-        }
-    };
-
-    private BroadcastReceiver mPackageReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and PACKAGE_ADDED is protected
-
-            final String action = intent.getAction();
-            final int uid = intent.getIntExtra(EXTRA_UID, -1);
-            if (uid == -1) return;
-
-            if (ACTION_PACKAGE_ADDED.equals(action)) {
-                // update rules for UID, since it might be subject to
-                // global background data policy
-                if (LOGV) Slog.v(TAG, "ACTION_PACKAGE_ADDED for uid=" + uid);
-                synchronized (mRulesLock) {
-                    updateRulesForUidLocked(uid);
-                }
-            }
-        }
-    };
-
-    private BroadcastReceiver mUidRemovedReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and UID_REMOVED is protected
-
-            final int uid = intent.getIntExtra(EXTRA_UID, -1);
-            if (uid == -1) return;
-
-            // remove any policy and update rules to clean up
-            if (LOGV) Slog.v(TAG, "ACTION_UID_REMOVED for uid=" + uid);
-            synchronized (mRulesLock) {
-                mUidPolicy.delete(uid);
-                updateRulesForUidLocked(uid);
-                writePolicyLocked();
-            }
-        }
-    };
-
-    private BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and USER_ADDED and USER_REMOVED
-            // broadcasts are protected
-
-            final String action = intent.getAction();
-            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
-            if (userId == -1) return;
-
-            // Remove any policies for given user; both cleaning up after a
-            // USER_REMOVED, and one last sanity check during USER_ADDED
-            removePoliciesForUserLocked(userId);
-
-            // Update global restrict for new user
-            synchronized (mRulesLock) {
-                updateRulesForRestrictBackgroundLocked();
-            }
-        }
-    };
-
-    /**
-     * Receiver that watches for {@link INetworkStatsService} updates, which we
-     * use to check against {@link NetworkPolicy#warningBytes}.
-     */
-    private BroadcastReceiver mStatsReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and verified
-            // READ_NETWORK_USAGE_HISTORY permission above.
-
-            maybeRefreshTrustedTime();
-            synchronized (mRulesLock) {
-                updateNetworkEnabledLocked();
-                updateNotificationsLocked();
-            }
-        }
-    };
-
-    /**
-     * Receiver that watches for {@link Notification} control of
-     * {@link #mRestrictBackground}.
-     */
-    private BroadcastReceiver mAllowReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and verified MANAGE_NETWORK_POLICY
-            // permission above.
-
-            setRestrictBackground(false);
-        }
-    };
-
-    /**
-     * Receiver that watches for {@link Notification} control of
-     * {@link NetworkPolicy#lastWarningSnooze}.
-     */
-    private BroadcastReceiver mSnoozeWarningReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and verified MANAGE_NETWORK_POLICY
-            // permission above.
-
-            final NetworkTemplate template = intent.getParcelableExtra(EXTRA_NETWORK_TEMPLATE);
-            performSnooze(template, TYPE_WARNING);
-        }
-    };
-
-    /**
-     * Receiver that watches for {@link WifiConfiguration} to be changed.
-     */
-    private BroadcastReceiver mWifiConfigReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and verified CONNECTIVITY_INTERNAL
-            // permission above.
-
-            final int reason = intent.getIntExtra(EXTRA_CHANGE_REASON, CHANGE_REASON_ADDED);
-            if (reason == CHANGE_REASON_REMOVED) {
-                final WifiConfiguration config = intent.getParcelableExtra(
-                        EXTRA_WIFI_CONFIGURATION);
-                if (config.SSID != null) {
-                    final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(config.SSID);
-                    synchronized (mRulesLock) {
-                        if (mNetworkPolicy.containsKey(template)) {
-                            mNetworkPolicy.remove(template);
-                            writePolicyLocked();
-                        }
-                    }
-                }
-            }
-        }
-    };
-
-    /**
-     * Receiver that watches {@link WifiInfo} state changes to infer metered
-     * state. Ignores hints when policy is user-defined.
-     */
-    private BroadcastReceiver mWifiStateReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and verified CONNECTIVITY_INTERNAL
-            // permission above.
-
-            // ignore when not connected
-            final NetworkInfo netInfo = intent.getParcelableExtra(EXTRA_NETWORK_INFO);
-            if (!netInfo.isConnected()) return;
-
-            final WifiInfo info = intent.getParcelableExtra(EXTRA_WIFI_INFO);
-            final boolean meteredHint = info.getMeteredHint();
-
-            final NetworkTemplate template = NetworkTemplate.buildTemplateWifi(info.getSSID());
-            synchronized (mRulesLock) {
-                NetworkPolicy policy = mNetworkPolicy.get(template);
-                if (policy == null && meteredHint) {
-                    // policy doesn't exist, and AP is hinting that it's
-                    // metered: create an inferred policy.
-                    policy = new NetworkPolicy(template, CYCLE_NONE, Time.TIMEZONE_UTC,
-                            WARNING_DISABLED, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER,
-                            meteredHint, true);
-                    addNetworkPolicyLocked(policy);
-
-                } else if (policy != null && policy.inferred) {
-                    // policy exists, and was inferred: update its current
-                    // metered state.
-                    policy.metered = meteredHint;
-
-                    // since this is inferred for each wifi session, just update
-                    // rules without persisting.
-                    updateNetworkRulesLocked();
-                }
-            }
-        }
-    };
-
-    /**
-     * Observer that watches for {@link INetworkManagementService} alerts.
-     */
-    private INetworkManagementEventObserver mAlertObserver = new BaseNetworkObserver() {
-        @Override
-        public void limitReached(String limitName, String iface) {
-            // only someone like NMS should be calling us
-            mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-            if (!LIMIT_GLOBAL_ALERT.equals(limitName)) {
-                mHandler.obtainMessage(MSG_LIMIT_REACHED, iface).sendToTarget();
-            }
-        }
-    };
-
-    /**
-     * Check {@link NetworkPolicy} against current {@link INetworkStatsService}
-     * to show visible notifications as needed.
-     */
-    private void updateNotificationsLocked() {
-        if (LOGV) Slog.v(TAG, "updateNotificationsLocked()");
-
-        // keep track of previously active notifications
-        final HashSet<String> beforeNotifs = Sets.newHashSet();
-        beforeNotifs.addAll(mActiveNotifs);
-        mActiveNotifs.clear();
-
-        // TODO: when switching to kernel notifications, compute next future
-        // cycle boundary to recompute notifications.
-
-        // examine stats for each active policy
-        final long currentTime = currentTimeMillis();
-        for (NetworkPolicy policy : mNetworkPolicy.values()) {
-            // ignore policies that aren't relevant to user
-            if (!isTemplateRelevant(policy.template)) continue;
-            if (!policy.hasCycle()) continue;
-
-            final long start = computeLastCycleBoundary(currentTime, policy);
-            final long end = currentTime;
-            final long totalBytes = getTotalBytes(policy.template, start, end);
-
-            if (policy.isOverLimit(totalBytes)) {
-                if (policy.lastLimitSnooze >= start) {
-                    enqueueNotification(policy, TYPE_LIMIT_SNOOZED, totalBytes);
-                } else {
-                    enqueueNotification(policy, TYPE_LIMIT, totalBytes);
-                    notifyOverLimitLocked(policy.template);
-                }
-
-            } else {
-                notifyUnderLimitLocked(policy.template);
-
-                if (policy.isOverWarning(totalBytes) && policy.lastWarningSnooze < start) {
-                    enqueueNotification(policy, TYPE_WARNING, totalBytes);
-                }
-            }
-        }
-
-        // ongoing notification when restricting background data
-        if (mRestrictBackground) {
-            enqueueRestrictedNotification(TAG_ALLOW_BACKGROUND);
-        }
-
-        // cancel stale notifications that we didn't renew above
-        for (String tag : beforeNotifs) {
-            if (!mActiveNotifs.contains(tag)) {
-                cancelNotification(tag);
-            }
-        }
-    }
-
-    /**
-     * Test if given {@link NetworkTemplate} is relevant to user based on
-     * current device state, such as when
-     * {@link TelephonyManager#getSubscriberId()} matches. This is regardless of
-     * data connection status.
-     */
-    private boolean isTemplateRelevant(NetworkTemplate template) {
-        final TelephonyManager tele = TelephonyManager.from(mContext);
-
-        switch (template.getMatchRule()) {
-            case MATCH_MOBILE_3G_LOWER:
-            case MATCH_MOBILE_4G:
-            case MATCH_MOBILE_ALL:
-                // mobile templates are relevant when SIM is ready and
-                // subscriberId matches.
-                if (tele.getSimState() == SIM_STATE_READY) {
-                    return Objects.equal(tele.getSubscriberId(), template.getSubscriberId());
-                } else {
-                    return false;
-                }
-        }
-        return true;
-    }
-
-    /**
-     * Notify that given {@link NetworkTemplate} is over
-     * {@link NetworkPolicy#limitBytes}, potentially showing dialog to user.
-     */
-    private void notifyOverLimitLocked(NetworkTemplate template) {
-        if (!mOverLimitNotified.contains(template)) {
-            mContext.startActivity(buildNetworkOverLimitIntent(template));
-            mOverLimitNotified.add(template);
-        }
-    }
-
-    private void notifyUnderLimitLocked(NetworkTemplate template) {
-        mOverLimitNotified.remove(template);
-    }
-
-    /**
-     * Build unique tag that identifies an active {@link NetworkPolicy}
-     * notification of a specific type, like {@link #TYPE_LIMIT}.
-     */
-    private String buildNotificationTag(NetworkPolicy policy, int type) {
-        return TAG + ":" + policy.template.hashCode() + ":" + type;
-    }
-
-    /**
-     * Show notification for combined {@link NetworkPolicy} and specific type,
-     * like {@link #TYPE_LIMIT}. Okay to call multiple times.
-     */
-    private void enqueueNotification(NetworkPolicy policy, int type, long totalBytes) {
-        final String tag = buildNotificationTag(policy, type);
-        final Notification.Builder builder = new Notification.Builder(mContext);
-        builder.setOnlyAlertOnce(true);
-        builder.setWhen(0L);
-
-        final Resources res = mContext.getResources();
-        switch (type) {
-            case TYPE_WARNING: {
-                final CharSequence title = res.getText(R.string.data_usage_warning_title);
-                final CharSequence body = res.getString(R.string.data_usage_warning_body);
-
-                builder.setSmallIcon(R.drawable.stat_notify_error);
-                builder.setTicker(title);
-                builder.setContentTitle(title);
-                builder.setContentText(body);
-
-                final Intent snoozeIntent = buildSnoozeWarningIntent(policy.template);
-                builder.setDeleteIntent(PendingIntent.getBroadcast(
-                        mContext, 0, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT));
-
-                final Intent viewIntent = buildViewDataUsageIntent(policy.template);
-                builder.setContentIntent(PendingIntent.getActivity(
-                        mContext, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT));
-
-                break;
-            }
-            case TYPE_LIMIT: {
-                final CharSequence body = res.getText(R.string.data_usage_limit_body);
-
-                final CharSequence title;
-                switch (policy.template.getMatchRule()) {
-                    case MATCH_MOBILE_3G_LOWER:
-                        title = res.getText(R.string.data_usage_3g_limit_title);
-                        break;
-                    case MATCH_MOBILE_4G:
-                        title = res.getText(R.string.data_usage_4g_limit_title);
-                        break;
-                    case MATCH_MOBILE_ALL:
-                        title = res.getText(R.string.data_usage_mobile_limit_title);
-                        break;
-                    case MATCH_WIFI:
-                        title = res.getText(R.string.data_usage_wifi_limit_title);
-                        break;
-                    default:
-                        title = null;
-                        break;
-                }
-
-                builder.setOngoing(true);
-                builder.setSmallIcon(R.drawable.stat_notify_disabled);
-                builder.setTicker(title);
-                builder.setContentTitle(title);
-                builder.setContentText(body);
-
-                final Intent intent = buildNetworkOverLimitIntent(policy.template);
-                builder.setContentIntent(PendingIntent.getActivity(
-                        mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
-                break;
-            }
-            case TYPE_LIMIT_SNOOZED: {
-                final long overBytes = totalBytes - policy.limitBytes;
-                final CharSequence body = res.getString(R.string.data_usage_limit_snoozed_body,
-                        Formatter.formatFileSize(mContext, overBytes));
-
-                final CharSequence title;
-                switch (policy.template.getMatchRule()) {
-                    case MATCH_MOBILE_3G_LOWER:
-                        title = res.getText(R.string.data_usage_3g_limit_snoozed_title);
-                        break;
-                    case MATCH_MOBILE_4G:
-                        title = res.getText(R.string.data_usage_4g_limit_snoozed_title);
-                        break;
-                    case MATCH_MOBILE_ALL:
-                        title = res.getText(R.string.data_usage_mobile_limit_snoozed_title);
-                        break;
-                    case MATCH_WIFI:
-                        title = res.getText(R.string.data_usage_wifi_limit_snoozed_title);
-                        break;
-                    default:
-                        title = null;
-                        break;
-                }
-
-                builder.setOngoing(true);
-                builder.setSmallIcon(R.drawable.stat_notify_error);
-                builder.setTicker(title);
-                builder.setContentTitle(title);
-                builder.setContentText(body);
-
-                final Intent intent = buildViewDataUsageIntent(policy.template);
-                builder.setContentIntent(PendingIntent.getActivity(
-                        mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
-                break;
-            }
-        }
-
-        // TODO: move to NotificationManager once we can mock it
-        // XXX what to do about multi-user?
-        try {
-            final String packageName = mContext.getPackageName();
-            final int[] idReceived = new int[1];
-            mNotifManager.enqueueNotificationWithTag(
-                    packageName, packageName, tag, 0x0, builder.getNotification(), idReceived,
-                    UserHandle.USER_OWNER);
-            mActiveNotifs.add(tag);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    /**
-     * Show ongoing notification to reflect that {@link #mRestrictBackground}
-     * has been enabled.
-     */
-    private void enqueueRestrictedNotification(String tag) {
-        final Resources res = mContext.getResources();
-        final Notification.Builder builder = new Notification.Builder(mContext);
-
-        final CharSequence title = res.getText(R.string.data_usage_restricted_title);
-        final CharSequence body = res.getString(R.string.data_usage_restricted_body);
-
-        builder.setOnlyAlertOnce(true);
-        builder.setOngoing(true);
-        builder.setSmallIcon(R.drawable.stat_notify_error);
-        builder.setTicker(title);
-        builder.setContentTitle(title);
-        builder.setContentText(body);
-
-        final Intent intent = buildAllowBackgroundDataIntent();
-        builder.setContentIntent(
-                PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
-
-        // TODO: move to NotificationManager once we can mock it
-        // XXX what to do about multi-user?
-        try {
-            final String packageName = mContext.getPackageName();
-            final int[] idReceived = new int[1];
-            mNotifManager.enqueueNotificationWithTag(packageName, packageName, tag,
-                    0x0, builder.getNotification(), idReceived, UserHandle.USER_OWNER);
-            mActiveNotifs.add(tag);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    private void cancelNotification(String tag) {
-        // TODO: move to NotificationManager once we can mock it
-        // XXX what to do about multi-user?
-        try {
-            final String packageName = mContext.getPackageName();
-            mNotifManager.cancelNotificationWithTag(
-                    packageName, tag, 0x0, UserHandle.USER_OWNER);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    /**
-     * Receiver that watches for {@link IConnectivityManager} to claim network
-     * interfaces. Used to apply {@link NetworkPolicy} to matching networks.
-     */
-    private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // on background handler thread, and verified CONNECTIVITY_INTERNAL
-            // permission above.
-
-            maybeRefreshTrustedTime();
-            synchronized (mRulesLock) {
-                ensureActiveMobilePolicyLocked();
-                updateNetworkEnabledLocked();
-                updateNetworkRulesLocked();
-                updateNotificationsLocked();
-            }
-        }
-    };
-
-    /**
-     * Proactively control network data connections when they exceed
-     * {@link NetworkPolicy#limitBytes}.
-     */
-    private void updateNetworkEnabledLocked() {
-        if (LOGV) Slog.v(TAG, "updateNetworkEnabledLocked()");
-
-        // TODO: reset any policy-disabled networks when any policy is removed
-        // completely, which is currently rare case.
-
-        final long currentTime = currentTimeMillis();
-        for (NetworkPolicy policy : mNetworkPolicy.values()) {
-            // shortcut when policy has no limit
-            if (policy.limitBytes == LIMIT_DISABLED || !policy.hasCycle()) {
-                setNetworkTemplateEnabled(policy.template, true);
-                continue;
-            }
-
-            final long start = computeLastCycleBoundary(currentTime, policy);
-            final long end = currentTime;
-            final long totalBytes = getTotalBytes(policy.template, start, end);
-
-            // disable data connection when over limit and not snoozed
-            final boolean overLimitWithoutSnooze = policy.isOverLimit(totalBytes)
-                    && policy.lastLimitSnooze < start;
-            final boolean networkEnabled = !overLimitWithoutSnooze;
-
-            setNetworkTemplateEnabled(policy.template, networkEnabled);
-        }
-    }
-
-    /**
-     * Control {@link IConnectivityManager#setPolicyDataEnable(int, boolean)}
-     * for the given {@link NetworkTemplate}.
-     */
-    private void setNetworkTemplateEnabled(NetworkTemplate template, boolean enabled) {
-        final TelephonyManager tele = TelephonyManager.from(mContext);
-
-        switch (template.getMatchRule()) {
-            case MATCH_MOBILE_3G_LOWER:
-            case MATCH_MOBILE_4G:
-            case MATCH_MOBILE_ALL:
-                // TODO: offer more granular control over radio states once
-                // 4965893 is available.
-                if (tele.getSimState() == SIM_STATE_READY
-                        && Objects.equal(tele.getSubscriberId(), template.getSubscriberId())) {
-                    setPolicyDataEnable(TYPE_MOBILE, enabled);
-                    setPolicyDataEnable(TYPE_WIMAX, enabled);
-                }
-                break;
-            case MATCH_WIFI:
-                setPolicyDataEnable(TYPE_WIFI, enabled);
-                break;
-            case MATCH_ETHERNET:
-                setPolicyDataEnable(TYPE_ETHERNET, enabled);
-                break;
-            default:
-                throw new IllegalArgumentException("unexpected template");
-        }
-    }
-
-    /**
-     * Examine all connected {@link NetworkState}, looking for
-     * {@link NetworkPolicy} that need to be enforced. When matches found, set
-     * remaining quota based on usage cycle and historical stats.
-     */
-    private void updateNetworkRulesLocked() {
-        if (LOGV) Slog.v(TAG, "updateIfacesLocked()");
-
-        final NetworkState[] states;
-        try {
-            states = mConnManager.getAllNetworkState();
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-            return;
-        }
-
-        // first, derive identity for all connected networks, which can be used
-        // to match against templates.
-        final HashMap<NetworkIdentity, String> networks = Maps.newHashMap();
-        for (NetworkState state : states) {
-            // stash identity and iface away for later use
-            if (state.networkInfo.isConnected()) {
-                final String iface = state.linkProperties.getInterfaceName();
-                final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
-                networks.put(ident, iface);
-            }
-        }
-
-        // build list of rules and ifaces to enforce them against
-        mNetworkRules.clear();
-        final ArrayList<String> ifaceList = Lists.newArrayList();
-        for (NetworkPolicy policy : mNetworkPolicy.values()) {
-
-            // collect all active ifaces that match this template
-            ifaceList.clear();
-            for (Map.Entry<NetworkIdentity, String> entry : networks.entrySet()) {
-                final NetworkIdentity ident = entry.getKey();
-                if (policy.template.matches(ident)) {
-                    final String iface = entry.getValue();
-                    ifaceList.add(iface);
-                }
-            }
-
-            if (ifaceList.size() > 0) {
-                final String[] ifaces = ifaceList.toArray(new String[ifaceList.size()]);
-                mNetworkRules.put(policy, ifaces);
-            }
-        }
-
-        long lowestRule = Long.MAX_VALUE;
-        final HashSet<String> newMeteredIfaces = Sets.newHashSet();
-
-        // apply each policy that we found ifaces for; compute remaining data
-        // based on current cycle and historical stats, and push to kernel.
-        final long currentTime = currentTimeMillis();
-        for (NetworkPolicy policy : mNetworkRules.keySet()) {
-            final String[] ifaces = mNetworkRules.get(policy);
-
-            final long start;
-            final long totalBytes;
-            if (policy.hasCycle()) {
-                start = computeLastCycleBoundary(currentTime, policy);
-                totalBytes = getTotalBytes(policy.template, start, currentTime);
-            } else {
-                start = Long.MAX_VALUE;
-                totalBytes = 0;
-            }
-
-            if (LOGD) {
-                Slog.d(TAG, "applying policy " + policy.toString() + " to ifaces "
-                        + Arrays.toString(ifaces));
-            }
-
-            final boolean hasWarning = policy.warningBytes != LIMIT_DISABLED;
-            final boolean hasLimit = policy.limitBytes != LIMIT_DISABLED;
-            if (hasLimit || policy.metered) {
-                final long quotaBytes;
-                if (!hasLimit) {
-                    // metered network, but no policy limit; we still need to
-                    // restrict apps, so push really high quota.
-                    quotaBytes = Long.MAX_VALUE;
-                } else if (policy.lastLimitSnooze >= start) {
-                    // snoozing past quota, but we still need to restrict apps,
-                    // so push really high quota.
-                    quotaBytes = Long.MAX_VALUE;
-                } else {
-                    // remaining "quota" bytes are based on total usage in
-                    // current cycle. kernel doesn't like 0-byte rules, so we
-                    // set 1-byte quota and disable the radio later.
-                    quotaBytes = Math.max(1, policy.limitBytes - totalBytes);
-                }
-
-                if (ifaces.length > 1) {
-                    // TODO: switch to shared quota once NMS supports
-                    Slog.w(TAG, "shared quota unsupported; generating rule for each iface");
-                }
-
-                for (String iface : ifaces) {
-                    removeInterfaceQuota(iface);
-                    setInterfaceQuota(iface, quotaBytes);
-                    newMeteredIfaces.add(iface);
-                }
-            }
-
-            // keep track of lowest warning or limit of active policies
-            if (hasWarning && policy.warningBytes < lowestRule) {
-                lowestRule = policy.warningBytes;
-            }
-            if (hasLimit && policy.limitBytes < lowestRule) {
-                lowestRule = policy.limitBytes;
-            }
-        }
-
-        mHandler.obtainMessage(MSG_ADVISE_PERSIST_THRESHOLD, lowestRule).sendToTarget();
-
-        // remove quota on any trailing interfaces
-        for (String iface : mMeteredIfaces) {
-            if (!newMeteredIfaces.contains(iface)) {
-                removeInterfaceQuota(iface);
-            }
-        }
-        mMeteredIfaces = newMeteredIfaces;
-
-        final String[] meteredIfaces = mMeteredIfaces.toArray(new String[mMeteredIfaces.size()]);
-        mHandler.obtainMessage(MSG_METERED_IFACES_CHANGED, meteredIfaces).sendToTarget();
-    }
-
-    /**
-     * Once any {@link #mNetworkPolicy} are loaded from disk, ensure that we
-     * have at least a default mobile policy defined.
-     */
-    private void ensureActiveMobilePolicyLocked() {
-        if (LOGV) Slog.v(TAG, "ensureActiveMobilePolicyLocked()");
-        if (mSuppressDefaultPolicy) return;
-
-        final TelephonyManager tele = TelephonyManager.from(mContext);
-
-        // avoid creating policy when SIM isn't ready
-        if (tele.getSimState() != SIM_STATE_READY) return;
-
-        final String subscriberId = tele.getSubscriberId();
-        final NetworkIdentity probeIdent = new NetworkIdentity(
-                TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, null, false);
-
-        // examine to see if any policy is defined for active mobile
-        boolean mobileDefined = false;
-        for (NetworkPolicy policy : mNetworkPolicy.values()) {
-            if (policy.template.matches(probeIdent)) {
-                mobileDefined = true;
-            }
-        }
-
-        if (!mobileDefined) {
-            Slog.i(TAG, "no policy for active mobile network; generating default policy");
-
-            // build default mobile policy, and assume usage cycle starts today
-            final long warningBytes = mContext.getResources().getInteger(
-                    com.android.internal.R.integer.config_networkPolicyDefaultWarning)
-                    * MB_IN_BYTES;
-
-            final Time time = new Time();
-            time.setToNow();
-
-            final int cycleDay = time.monthDay;
-            final String cycleTimezone = time.timezone;
-
-            final NetworkTemplate template = buildTemplateMobileAll(subscriberId);
-            final NetworkPolicy policy = new NetworkPolicy(template, cycleDay, cycleTimezone,
-                    warningBytes, LIMIT_DISABLED, SNOOZE_NEVER, SNOOZE_NEVER, true, true);
-            addNetworkPolicyLocked(policy);
-        }
-    }
-
-    private void readPolicyLocked() {
-        if (LOGV) Slog.v(TAG, "readPolicyLocked()");
-
-        // clear any existing policy and read from disk
-        mNetworkPolicy.clear();
-        mUidPolicy.clear();
-
-        FileInputStream fis = null;
-        try {
-            fis = mPolicyFile.openRead();
-            final XmlPullParser in = Xml.newPullParser();
-            in.setInput(fis, null);
-
-            int type;
-            int version = VERSION_INIT;
-            while ((type = in.next()) != END_DOCUMENT) {
-                final String tag = in.getName();
-                if (type == START_TAG) {
-                    if (TAG_POLICY_LIST.equals(tag)) {
-                        version = readIntAttribute(in, ATTR_VERSION);
-                        if (version >= VERSION_ADDED_RESTRICT_BACKGROUND) {
-                            mRestrictBackground = readBooleanAttribute(
-                                    in, ATTR_RESTRICT_BACKGROUND);
-                        } else {
-                            mRestrictBackground = false;
-                        }
-
-                    } else if (TAG_NETWORK_POLICY.equals(tag)) {
-                        final int networkTemplate = readIntAttribute(in, ATTR_NETWORK_TEMPLATE);
-                        final String subscriberId = in.getAttributeValue(null, ATTR_SUBSCRIBER_ID);
-                        final String networkId;
-                        if (version >= VERSION_ADDED_NETWORK_ID) {
-                            networkId = in.getAttributeValue(null, ATTR_NETWORK_ID);
-                        } else {
-                            networkId = null;
-                        }
-                        final int cycleDay = readIntAttribute(in, ATTR_CYCLE_DAY);
-                        final String cycleTimezone;
-                        if (version >= VERSION_ADDED_TIMEZONE) {
-                            cycleTimezone = in.getAttributeValue(null, ATTR_CYCLE_TIMEZONE);
-                        } else {
-                            cycleTimezone = Time.TIMEZONE_UTC;
-                        }
-                        final long warningBytes = readLongAttribute(in, ATTR_WARNING_BYTES);
-                        final long limitBytes = readLongAttribute(in, ATTR_LIMIT_BYTES);
-                        final long lastLimitSnooze;
-                        if (version >= VERSION_SPLIT_SNOOZE) {
-                            lastLimitSnooze = readLongAttribute(in, ATTR_LAST_LIMIT_SNOOZE);
-                        } else if (version >= VERSION_ADDED_SNOOZE) {
-                            lastLimitSnooze = readLongAttribute(in, ATTR_LAST_SNOOZE);
-                        } else {
-                            lastLimitSnooze = SNOOZE_NEVER;
-                        }
-                        final boolean metered;
-                        if (version >= VERSION_ADDED_METERED) {
-                            metered = readBooleanAttribute(in, ATTR_METERED);
-                        } else {
-                            switch (networkTemplate) {
-                                case MATCH_MOBILE_3G_LOWER:
-                                case MATCH_MOBILE_4G:
-                                case MATCH_MOBILE_ALL:
-                                    metered = true;
-                                    break;
-                                default:
-                                    metered = false;
-                            }
-                        }
-                        final long lastWarningSnooze;
-                        if (version >= VERSION_SPLIT_SNOOZE) {
-                            lastWarningSnooze = readLongAttribute(in, ATTR_LAST_WARNING_SNOOZE);
-                        } else {
-                            lastWarningSnooze = SNOOZE_NEVER;
-                        }
-                        final boolean inferred;
-                        if (version >= VERSION_ADDED_INFERRED) {
-                            inferred = readBooleanAttribute(in, ATTR_INFERRED);
-                        } else {
-                            inferred = false;
-                        }
-
-                        final NetworkTemplate template = new NetworkTemplate(
-                                networkTemplate, subscriberId, networkId);
-                        mNetworkPolicy.put(template, new NetworkPolicy(template, cycleDay,
-                                cycleTimezone, warningBytes, limitBytes, lastWarningSnooze,
-                                lastLimitSnooze, metered, inferred));
-
-                    } else if (TAG_UID_POLICY.equals(tag)) {
-                        final int uid = readIntAttribute(in, ATTR_UID);
-                        final int policy = readIntAttribute(in, ATTR_POLICY);
-
-                        if (UserHandle.isApp(uid)) {
-                            setUidPolicyUnchecked(uid, policy, false);
-                        } else {
-                            Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
-                        }
-                    } else if (TAG_APP_POLICY.equals(tag)) {
-                        final int appId = readIntAttribute(in, ATTR_APP_ID);
-                        final int policy = readIntAttribute(in, ATTR_POLICY);
-
-                        // TODO: set for other users during upgrade
-                        final int uid = UserHandle.getUid(UserHandle.USER_OWNER, appId);
-                        if (UserHandle.isApp(uid)) {
-                            setUidPolicyUnchecked(uid, policy, false);
-                        } else {
-                            Slog.w(TAG, "unable to apply policy to UID " + uid + "; ignoring");
-                        }
-                    }
-                }
-            }
-
-        } catch (FileNotFoundException e) {
-            // missing policy is okay, probably first boot
-            upgradeLegacyBackgroundData();
-        } catch (IOException e) {
-            Log.wtf(TAG, "problem reading network policy", e);
-        } catch (XmlPullParserException e) {
-            Log.wtf(TAG, "problem reading network policy", e);
-        } finally {
-            IoUtils.closeQuietly(fis);
-        }
-    }
-
-    /**
-     * Upgrade legacy background data flags, notifying listeners of one last
-     * change to always-true.
-     */
-    private void upgradeLegacyBackgroundData() {
-        mRestrictBackground = Settings.Secure.getInt(
-                mContext.getContentResolver(), Settings.Secure.BACKGROUND_DATA, 1) != 1;
-
-        // kick off one last broadcast if restricted
-        if (mRestrictBackground) {
-            final Intent broadcast = new Intent(
-                    ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED);
-            mContext.sendBroadcastAsUser(broadcast, UserHandle.ALL);
-        }
-    }
-
-    private void writePolicyLocked() {
-        if (LOGV) Slog.v(TAG, "writePolicyLocked()");
-
-        FileOutputStream fos = null;
-        try {
-            fos = mPolicyFile.startWrite();
-
-            XmlSerializer out = new FastXmlSerializer();
-            out.setOutput(fos, "utf-8");
-            out.startDocument(null, true);
-
-            out.startTag(null, TAG_POLICY_LIST);
-            writeIntAttribute(out, ATTR_VERSION, VERSION_LATEST);
-            writeBooleanAttribute(out, ATTR_RESTRICT_BACKGROUND, mRestrictBackground);
-
-            // write all known network policies
-            for (NetworkPolicy policy : mNetworkPolicy.values()) {
-                final NetworkTemplate template = policy.template;
-
-                out.startTag(null, TAG_NETWORK_POLICY);
-                writeIntAttribute(out, ATTR_NETWORK_TEMPLATE, template.getMatchRule());
-                final String subscriberId = template.getSubscriberId();
-                if (subscriberId != null) {
-                    out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
-                }
-                final String networkId = template.getNetworkId();
-                if (networkId != null) {
-                    out.attribute(null, ATTR_NETWORK_ID, networkId);
-                }
-                writeIntAttribute(out, ATTR_CYCLE_DAY, policy.cycleDay);
-                out.attribute(null, ATTR_CYCLE_TIMEZONE, policy.cycleTimezone);
-                writeLongAttribute(out, ATTR_WARNING_BYTES, policy.warningBytes);
-                writeLongAttribute(out, ATTR_LIMIT_BYTES, policy.limitBytes);
-                writeLongAttribute(out, ATTR_LAST_WARNING_SNOOZE, policy.lastWarningSnooze);
-                writeLongAttribute(out, ATTR_LAST_LIMIT_SNOOZE, policy.lastLimitSnooze);
-                writeBooleanAttribute(out, ATTR_METERED, policy.metered);
-                writeBooleanAttribute(out, ATTR_INFERRED, policy.inferred);
-                out.endTag(null, TAG_NETWORK_POLICY);
-            }
-
-            // write all known uid policies
-            for (int i = 0; i < mUidPolicy.size(); i++) {
-                final int uid = mUidPolicy.keyAt(i);
-                final int policy = mUidPolicy.valueAt(i);
-
-                // skip writing empty policies
-                if (policy == POLICY_NONE) continue;
-
-                out.startTag(null, TAG_UID_POLICY);
-                writeIntAttribute(out, ATTR_UID, uid);
-                writeIntAttribute(out, ATTR_POLICY, policy);
-                out.endTag(null, TAG_UID_POLICY);
-            }
-
-            out.endTag(null, TAG_POLICY_LIST);
-            out.endDocument();
-
-            mPolicyFile.finishWrite(fos);
-        } catch (IOException e) {
-            if (fos != null) {
-                mPolicyFile.failWrite(fos);
-            }
-        }
-    }
-
-    @Override
-    public void setUidPolicy(int uid, int policy) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        if (!UserHandle.isApp(uid)) {
-            throw new IllegalArgumentException("cannot apply policy to UID " + uid);
-        }
-
-        setUidPolicyUnchecked(uid, policy, true);
-    }
-
-    private void setUidPolicyUnchecked(int uid, int policy, boolean persist) {
-        final int oldPolicy;
-        synchronized (mRulesLock) {
-            oldPolicy = getUidPolicy(uid);
-            mUidPolicy.put(uid, policy);
-
-            // uid policy changed, recompute rules and persist policy.
-            updateRulesForUidLocked(uid);
-            if (persist) {
-                writePolicyLocked();
-            }
-        }
-    }
-
-    @Override
-    public int getUidPolicy(int uid) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        synchronized (mRulesLock) {
-            return mUidPolicy.get(uid, POLICY_NONE);
-        }
-    }
-
-    @Override
-    public int[] getUidsWithPolicy(int policy) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        int[] uids = new int[0];
-        synchronized (mRulesLock) {
-            for (int i = 0; i < mUidPolicy.size(); i++) {
-                final int uid = mUidPolicy.keyAt(i);
-                final int uidPolicy = mUidPolicy.valueAt(i);
-                if (uidPolicy == policy) {
-                    uids = appendInt(uids, uid);
-                }
-            }
-        }
-        return uids;
-    }
-
-    /**
-     * Remove any policies associated with given {@link UserHandle}, persisting
-     * if any changes are made.
-     */
-    private void removePoliciesForUserLocked(int userId) {
-        if (LOGV) Slog.v(TAG, "removePoliciesForUserLocked()");
-
-        int[] uids = new int[0];
-        for (int i = 0; i < mUidPolicy.size(); i++) {
-            final int uid = mUidPolicy.keyAt(i);
-            if (UserHandle.getUserId(uid) == userId) {
-                uids = appendInt(uids, uid);
-            }
-        }
-
-        if (uids.length > 0) {
-            for (int uid : uids) {
-                mUidPolicy.delete(uid);
-                updateRulesForUidLocked(uid);
-            }
-            writePolicyLocked();
-        }
-    }
-
-    @Override
-    public void registerListener(INetworkPolicyListener listener) {
-        // TODO: create permission for observing network policy
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        mListeners.register(listener);
-
-        // TODO: consider dispatching existing rules to new listeners
-    }
-
-    @Override
-    public void unregisterListener(INetworkPolicyListener listener) {
-        // TODO: create permission for observing network policy
-        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
-        mListeners.unregister(listener);
-    }
-
-    @Override
-    public void setNetworkPolicies(NetworkPolicy[] policies) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        maybeRefreshTrustedTime();
-        synchronized (mRulesLock) {
-            mNetworkPolicy.clear();
-            for (NetworkPolicy policy : policies) {
-                mNetworkPolicy.put(policy.template, policy);
-            }
-
-            updateNetworkEnabledLocked();
-            updateNetworkRulesLocked();
-            updateNotificationsLocked();
-            writePolicyLocked();
-        }
-    }
-
-    private void addNetworkPolicyLocked(NetworkPolicy policy) {
-        mNetworkPolicy.put(policy.template, policy);
-
-        updateNetworkEnabledLocked();
-        updateNetworkRulesLocked();
-        updateNotificationsLocked();
-        writePolicyLocked();
-    }
-
-    @Override
-    public NetworkPolicy[] getNetworkPolicies() {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-        mContext.enforceCallingOrSelfPermission(READ_PHONE_STATE, TAG);
-
-        synchronized (mRulesLock) {
-            return mNetworkPolicy.values().toArray(new NetworkPolicy[mNetworkPolicy.size()]);
-        }
-    }
-
-    @Override
-    public void snoozeLimit(NetworkTemplate template) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        final long token = Binder.clearCallingIdentity();
-        try {
-            performSnooze(template, TYPE_LIMIT);
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private void performSnooze(NetworkTemplate template, int type) {
-        maybeRefreshTrustedTime();
-        final long currentTime = currentTimeMillis();
-        synchronized (mRulesLock) {
-            // find and snooze local policy that matches
-            final NetworkPolicy policy = mNetworkPolicy.get(template);
-            if (policy == null) {
-                throw new IllegalArgumentException("unable to find policy for " + template);
-            }
-
-            switch (type) {
-                case TYPE_WARNING:
-                    policy.lastWarningSnooze = currentTime;
-                    break;
-                case TYPE_LIMIT:
-                    policy.lastLimitSnooze = currentTime;
-                    break;
-                default:
-                    throw new IllegalArgumentException("unexpected type");
-            }
-
-            updateNetworkEnabledLocked();
-            updateNetworkRulesLocked();
-            updateNotificationsLocked();
-            writePolicyLocked();
-        }
-    }
-
-    @Override
-    public void setRestrictBackground(boolean restrictBackground) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        maybeRefreshTrustedTime();
-        synchronized (mRulesLock) {
-            mRestrictBackground = restrictBackground;
-            updateRulesForRestrictBackgroundLocked();
-            updateNotificationsLocked();
-            writePolicyLocked();
-        }
-
-        mHandler.obtainMessage(MSG_RESTRICT_BACKGROUND_CHANGED, restrictBackground ? 1 : 0, 0)
-                .sendToTarget();
-    }
-
-    @Override
-    public boolean getRestrictBackground() {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        synchronized (mRulesLock) {
-            return mRestrictBackground;
-        }
-    }
-
-    private NetworkPolicy findPolicyForNetworkLocked(NetworkIdentity ident) {
-        for (NetworkPolicy policy : mNetworkPolicy.values()) {
-            if (policy.template.matches(ident)) {
-                return policy;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public NetworkQuotaInfo getNetworkQuotaInfo(NetworkState state) {
-        mContext.enforceCallingOrSelfPermission(ACCESS_NETWORK_STATE, TAG);
-
-        // only returns usage summary, so we don't require caller to have
-        // READ_NETWORK_USAGE_HISTORY.
-        final long token = Binder.clearCallingIdentity();
-        try {
-            return getNetworkQuotaInfoUnchecked(state);
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    private NetworkQuotaInfo getNetworkQuotaInfoUnchecked(NetworkState state) {
-        final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
-
-        final NetworkPolicy policy;
-        synchronized (mRulesLock) {
-            policy = findPolicyForNetworkLocked(ident);
-        }
-
-        if (policy == null || !policy.hasCycle()) {
-            // missing policy means we can't derive useful quota info
-            return null;
-        }
-
-        final long currentTime = currentTimeMillis();
-
-        // find total bytes used under policy
-        final long start = computeLastCycleBoundary(currentTime, policy);
-        final long end = currentTime;
-        final long totalBytes = getTotalBytes(policy.template, start, end);
-
-        // report soft and hard limits under policy
-        final long softLimitBytes = policy.warningBytes != WARNING_DISABLED ? policy.warningBytes
-                : NetworkQuotaInfo.NO_LIMIT;
-        final long hardLimitBytes = policy.limitBytes != LIMIT_DISABLED ? policy.limitBytes
-                : NetworkQuotaInfo.NO_LIMIT;
-
-        return new NetworkQuotaInfo(totalBytes, softLimitBytes, hardLimitBytes);
-    }
-
-    @Override
-    public boolean isNetworkMetered(NetworkState state) {
-        final NetworkIdentity ident = NetworkIdentity.buildNetworkIdentity(mContext, state);
-
-        // roaming networks are always considered metered
-        if (ident.getRoaming()) {
-            return true;
-        }
-
-        final NetworkPolicy policy;
-        synchronized (mRulesLock) {
-            policy = findPolicyForNetworkLocked(ident);
-        }
-
-        if (policy != null) {
-            return policy.metered;
-        } else {
-            final int type = state.networkInfo.getType();
-            if (isNetworkTypeMobile(type) || type == TYPE_WIMAX) {
-                return true;
-            }
-            return false;
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
-        mContext.enforceCallingOrSelfPermission(DUMP, TAG);
-
-        final IndentingPrintWriter fout = new IndentingPrintWriter(writer, "  ");
-
-        final HashSet<String> argSet = new HashSet<String>();
-        for (String arg : args) {
-            argSet.add(arg);
-        }
-
-        synchronized (mRulesLock) {
-            if (argSet.contains("--unsnooze")) {
-                for (NetworkPolicy policy : mNetworkPolicy.values()) {
-                    policy.clearSnooze();
-                }
-
-                updateNetworkEnabledLocked();
-                updateNetworkRulesLocked();
-                updateNotificationsLocked();
-                writePolicyLocked();
-
-                fout.println("Cleared snooze timestamps");
-                return;
-            }
-
-            fout.print("Restrict background: "); fout.println(mRestrictBackground);
-            fout.println("Network policies:");
-            fout.increaseIndent();
-            for (NetworkPolicy policy : mNetworkPolicy.values()) {
-                fout.println(policy.toString());
-            }
-            fout.decreaseIndent();
-
-            fout.println("Policy for UIDs:");
-            fout.increaseIndent();
-            int size = mUidPolicy.size();
-            for (int i = 0; i < size; i++) {
-                final int uid = mUidPolicy.keyAt(i);
-                final int policy = mUidPolicy.valueAt(i);
-                fout.print("UID=");
-                fout.print(uid);
-                fout.print(" policy=");
-                dumpPolicy(fout, policy);
-                fout.println();
-            }
-            fout.decreaseIndent();
-
-            final SparseBooleanArray knownUids = new SparseBooleanArray();
-            collectKeys(mUidForeground, knownUids);
-            collectKeys(mUidRules, knownUids);
-
-            fout.println("Status for known UIDs:");
-            fout.increaseIndent();
-            size = knownUids.size();
-            for (int i = 0; i < size; i++) {
-                final int uid = knownUids.keyAt(i);
-                fout.print("UID=");
-                fout.print(uid);
-
-                fout.print(" foreground=");
-                final int foregroundIndex = mUidPidForeground.indexOfKey(uid);
-                if (foregroundIndex < 0) {
-                    fout.print("UNKNOWN");
-                } else {
-                    dumpSparseBooleanArray(fout, mUidPidForeground.valueAt(foregroundIndex));
-                }
-
-                fout.print(" rules=");
-                final int rulesIndex = mUidRules.indexOfKey(uid);
-                if (rulesIndex < 0) {
-                    fout.print("UNKNOWN");
-                } else {
-                    dumpRules(fout, mUidRules.valueAt(rulesIndex));
-                }
-
-                fout.println();
-            }
-            fout.decreaseIndent();
-        }
-    }
-
-    @Override
-    public boolean isUidForeground(int uid) {
-        mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG);
-
-        synchronized (mRulesLock) {
-            // only really in foreground when screen is also on
-            return mUidForeground.get(uid, false) && mScreenOn;
-        }
-    }
-
-    /**
-     * Foreground for PID changed; recompute foreground at UID level. If
-     * changed, will trigger {@link #updateRulesForUidLocked(int)}.
-     */
-    private void computeUidForegroundLocked(int uid) {
-        final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
-
-        // current pid is dropping foreground; examine other pids
-        boolean uidForeground = false;
-        final int size = pidForeground.size();
-        for (int i = 0; i < size; i++) {
-            if (pidForeground.valueAt(i)) {
-                uidForeground = true;
-                break;
-            }
-        }
-
-        final boolean oldUidForeground = mUidForeground.get(uid, false);
-        if (oldUidForeground != uidForeground) {
-            // foreground changed, push updated rules
-            mUidForeground.put(uid, uidForeground);
-            updateRulesForUidLocked(uid);
-        }
-    }
-
-    private void updateScreenOn() {
-        synchronized (mRulesLock) {
-            try {
-                mScreenOn = mPowerManager.isScreenOn();
-            } catch (RemoteException e) {
-                // ignored; service lives in system_server
-            }
-            updateRulesForScreenLocked();
-        }
-    }
-
-    /**
-     * Update rules that might be changed by {@link #mScreenOn} value.
-     */
-    private void updateRulesForScreenLocked() {
-        // only update rules for anyone with foreground activities
-        final int size = mUidForeground.size();
-        for (int i = 0; i < size; i++) {
-            if (mUidForeground.valueAt(i)) {
-                final int uid = mUidForeground.keyAt(i);
-                updateRulesForUidLocked(uid);
-            }
-        }
-    }
-
-    /**
-     * Update rules that might be changed by {@link #mRestrictBackground} value.
-     */
-    private void updateRulesForRestrictBackgroundLocked() {
-        final PackageManager pm = mContext.getPackageManager();
-        final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
-
-        // update rules for all installed applications
-        final List<UserInfo> users = um.getUsers();
-        final List<ApplicationInfo> apps = pm.getInstalledApplications(
-                PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
-
-        for (UserInfo user : users) {
-            for (ApplicationInfo app : apps) {
-                final int uid = UserHandle.getUid(user.id, app.uid);
-                updateRulesForUidLocked(uid);
-            }
-        }
-
-        // limit data usage for some internal system services
-        updateRulesForUidLocked(android.os.Process.MEDIA_UID);
-        updateRulesForUidLocked(android.os.Process.DRM_UID);
-    }
-
-    private static boolean isUidValidForRules(int uid) {
-        // allow rules on specific system services, and any apps
-        if (uid == android.os.Process.MEDIA_UID || uid == android.os.Process.DRM_UID
-                || UserHandle.isApp(uid)) {
-            return true;
-        }
-
-        return false;
-    }
-
-    private void updateRulesForUidLocked(int uid) {
-        if (!isUidValidForRules(uid)) return;
-
-        final int uidPolicy = getUidPolicy(uid);
-        final boolean uidForeground = isUidForeground(uid);
-
-        // derive active rules based on policy and active state
-        int uidRules = RULE_ALLOW_ALL;
-        if (!uidForeground && (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
-            // uid in background, and policy says to block metered data
-            uidRules = RULE_REJECT_METERED;
-        }
-        if (!uidForeground && mRestrictBackground) {
-            // uid in background, and global background disabled
-            uidRules = RULE_REJECT_METERED;
-        }
-
-        // TODO: only dispatch when rules actually change
-
-        if (uidRules == RULE_ALLOW_ALL) {
-            mUidRules.delete(uid);
-        } else {
-            mUidRules.put(uid, uidRules);
-        }
-
-        final boolean rejectMetered = (uidRules & RULE_REJECT_METERED) != 0;
-        setUidNetworkRules(uid, rejectMetered);
-
-        // dispatch changed rule to existing listeners
-        mHandler.obtainMessage(MSG_RULES_CHANGED, uid, uidRules).sendToTarget();
-
-        try {
-            // adjust stats accounting based on foreground status
-            mNetworkStats.setUidForeground(uid, uidForeground);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    private Handler.Callback mHandlerCallback = new Handler.Callback() {
-        @Override
-        public boolean handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_RULES_CHANGED: {
-                    final int uid = msg.arg1;
-                    final int uidRules = msg.arg2;
-                    final int length = mListeners.beginBroadcast();
-                    for (int i = 0; i < length; i++) {
-                        final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
-                        if (listener != null) {
-                            try {
-                                listener.onUidRulesChanged(uid, uidRules);
-                            } catch (RemoteException e) {
-                            }
-                        }
-                    }
-                    mListeners.finishBroadcast();
-                    return true;
-                }
-                case MSG_METERED_IFACES_CHANGED: {
-                    final String[] meteredIfaces = (String[]) msg.obj;
-                    final int length = mListeners.beginBroadcast();
-                    for (int i = 0; i < length; i++) {
-                        final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
-                        if (listener != null) {
-                            try {
-                                listener.onMeteredIfacesChanged(meteredIfaces);
-                            } catch (RemoteException e) {
-                            }
-                        }
-                    }
-                    mListeners.finishBroadcast();
-                    return true;
-                }
-                case MSG_FOREGROUND_ACTIVITIES_CHANGED: {
-                    final int pid = msg.arg1;
-                    final int uid = msg.arg2;
-                    final boolean foregroundActivities = (Boolean) msg.obj;
-
-                    synchronized (mRulesLock) {
-                        // because a uid can have multiple pids running inside, we need to
-                        // remember all pid states and summarize foreground at uid level.
-
-                        // record foreground for this specific pid
-                        SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
-                        if (pidForeground == null) {
-                            pidForeground = new SparseBooleanArray(2);
-                            mUidPidForeground.put(uid, pidForeground);
-                        }
-                        pidForeground.put(pid, foregroundActivities);
-                        computeUidForegroundLocked(uid);
-                    }
-                    return true;
-                }
-                case MSG_PROCESS_DIED: {
-                    final int pid = msg.arg1;
-                    final int uid = msg.arg2;
-
-                    synchronized (mRulesLock) {
-                        // clear records and recompute, when they exist
-                        final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
-                        if (pidForeground != null) {
-                            pidForeground.delete(pid);
-                            computeUidForegroundLocked(uid);
-                        }
-                    }
-                    return true;
-                }
-                case MSG_LIMIT_REACHED: {
-                    final String iface = (String) msg.obj;
-
-                    maybeRefreshTrustedTime();
-                    synchronized (mRulesLock) {
-                        if (mMeteredIfaces.contains(iface)) {
-                            try {
-                                // force stats update to make sure we have
-                                // numbers that caused alert to trigger.
-                                mNetworkStats.forceUpdate();
-                            } catch (RemoteException e) {
-                                // ignored; service lives in system_server
-                            }
-
-                            updateNetworkEnabledLocked();
-                            updateNotificationsLocked();
-                        }
-                    }
-                    return true;
-                }
-                case MSG_RESTRICT_BACKGROUND_CHANGED: {
-                    final boolean restrictBackground = msg.arg1 != 0;
-                    final int length = mListeners.beginBroadcast();
-                    for (int i = 0; i < length; i++) {
-                        final INetworkPolicyListener listener = mListeners.getBroadcastItem(i);
-                        if (listener != null) {
-                            try {
-                                listener.onRestrictBackgroundChanged(restrictBackground);
-                            } catch (RemoteException e) {
-                            }
-                        }
-                    }
-                    mListeners.finishBroadcast();
-                    return true;
-                }
-                case MSG_ADVISE_PERSIST_THRESHOLD: {
-                    final long lowestRule = (Long) msg.obj;
-                    try {
-                        // make sure stats are recorded frequently enough; we aim
-                        // for 2MB threshold for 2GB/month rules.
-                        final long persistThreshold = lowestRule / 1000;
-                        mNetworkStats.advisePersistThreshold(persistThreshold);
-                    } catch (RemoteException e) {
-                        // ignored; service lives in system_server
-                    }
-                    return true;
-                }
-                case MSG_SCREEN_ON_CHANGED: {
-                    updateScreenOn();
-                    return true;
-                }
-                default: {
-                    return false;
-                }
-            }
-        }
-    };
-
-    private void setInterfaceQuota(String iface, long quotaBytes) {
-        try {
-            mNetworkManager.setInterfaceQuota(iface, quotaBytes);
-        } catch (IllegalStateException e) {
-            Log.wtf(TAG, "problem setting interface quota", e);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    private void removeInterfaceQuota(String iface) {
-        try {
-            mNetworkManager.removeInterfaceQuota(iface);
-        } catch (IllegalStateException e) {
-            Log.wtf(TAG, "problem removing interface quota", e);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    private void setUidNetworkRules(int uid, boolean rejectOnQuotaInterfaces) {
-        try {
-            mNetworkManager.setUidNetworkRules(uid, rejectOnQuotaInterfaces);
-        } catch (IllegalStateException e) {
-            Log.wtf(TAG, "problem setting uid rules", e);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    /**
-     * Control {@link IConnectivityManager#setPolicyDataEnable(int, boolean)}.
-     */
-    private void setPolicyDataEnable(int networkType, boolean enabled) {
-        try {
-            mConnManager.setPolicyDataEnable(networkType, enabled);
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-        }
-    }
-
-    private long getTotalBytes(NetworkTemplate template, long start, long end) {
-        try {
-            return mNetworkStats.getNetworkTotalBytes(template, start, end);
-        } catch (RuntimeException e) {
-            Slog.w(TAG, "problem reading network stats: " + e);
-            return 0;
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-            return 0;
-        }
-    }
-
-    private boolean isBandwidthControlEnabled() {
-        final long token = Binder.clearCallingIdentity();
-        try {
-            return mNetworkManager.isBandwidthControlEnabled();
-        } catch (RemoteException e) {
-            // ignored; service lives in system_server
-            return false;
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-
-    /**
-     * Try refreshing {@link #mTime} when stale.
-     */
-    private void maybeRefreshTrustedTime() {
-        if (mTime.getCacheAge() > TIME_CACHE_MAX_AGE) {
-            mTime.forceRefresh();
-        }
-    }
-
-    private long currentTimeMillis() {
-        return mTime.hasCache() ? mTime.currentTimeMillis() : System.currentTimeMillis();
-    }
-
-    private static Intent buildAllowBackgroundDataIntent() {
-        return new Intent(ACTION_ALLOW_BACKGROUND);
-    }
-
-    private static Intent buildSnoozeWarningIntent(NetworkTemplate template) {
-        final Intent intent = new Intent(ACTION_SNOOZE_WARNING);
-        intent.putExtra(EXTRA_NETWORK_TEMPLATE, template);
-        return intent;
-    }
-
-    private static Intent buildNetworkOverLimitIntent(NetworkTemplate template) {
-        final Intent intent = new Intent();
-        intent.setComponent(new ComponentName(
-                "com.android.systemui", "com.android.systemui.net.NetworkOverLimitActivity"));
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intent.putExtra(EXTRA_NETWORK_TEMPLATE, template);
-        return intent;
-    }
-
-    private static Intent buildViewDataUsageIntent(NetworkTemplate template) {
-        final Intent intent = new Intent();
-        intent.setComponent(new ComponentName(
-                "com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity"));
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intent.putExtra(EXTRA_NETWORK_TEMPLATE, template);
-        return intent;
-    }
-
-    @VisibleForTesting
-    public void addIdleHandler(IdleHandler handler) {
-        mHandler.getLooper().getQueue().addIdleHandler(handler);
-    }
-
-    private static void collectKeys(SparseIntArray source, SparseBooleanArray target) {
-        final int size = source.size();
-        for (int i = 0; i < size; i++) {
-            target.put(source.keyAt(i), true);
-        }
-    }
-
-    private static void collectKeys(SparseBooleanArray source, SparseBooleanArray target) {
-        final int size = source.size();
-        for (int i = 0; i < size; i++) {
-            target.put(source.keyAt(i), true);
-        }
-    }
-
-    private static void dumpSparseBooleanArray(PrintWriter fout, SparseBooleanArray value) {
-        fout.print("[");
-        final int size = value.size();
-        for (int i = 0; i < size; i++) {
-            fout.print(value.keyAt(i) + "=" + value.valueAt(i));
-            if (i < size - 1) fout.print(",");
-        }
-        fout.print("]");
-    }
-}
diff --git a/services/java/com/android/server/net/NetworkStatsCollection.java b/services/java/com/android/server/net/NetworkStatsCollection.java
deleted file mode 100644
index 3169035..0000000
--- a/services/java/com/android/server/net/NetworkStatsCollection.java
+++ /dev/null
@@ -1,534 +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.server.net;
-
-import static android.net.NetworkStats.IFACE_ALL;
-import static android.net.NetworkStats.SET_ALL;
-import static android.net.NetworkStats.SET_DEFAULT;
-import static android.net.NetworkStats.TAG_NONE;
-import static android.net.NetworkStats.UID_ALL;
-import static android.net.TrafficStats.UID_REMOVED;
-
-import android.net.NetworkIdentity;
-import android.net.NetworkStats;
-import android.net.NetworkStatsHistory;
-import android.net.NetworkTemplate;
-import android.net.TrafficStats;
-import android.text.format.DateUtils;
-import android.util.AtomicFile;
-
-import com.android.internal.util.ArrayUtils;
-import com.android.internal.util.FileRotator;
-import com.android.internal.util.IndentingPrintWriter;
-import com.android.internal.util.Objects;
-import com.google.android.collect.Lists;
-import com.google.android.collect.Maps;
-
-import java.io.BufferedInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.ProtocolException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import libcore.io.IoUtils;
-
-/**
- * Collection of {@link NetworkStatsHistory}, stored based on combined key of
- * {@link NetworkIdentitySet}, UID, set, and tag. Knows how to persist itself.
- */
-public class NetworkStatsCollection implements FileRotator.Reader {
-    /** File header magic number: "ANET" */
-    private static final int FILE_MAGIC = 0x414E4554;
-
-    private static final int VERSION_NETWORK_INIT = 1;
-
-    private static final int VERSION_UID_INIT = 1;
-    private static final int VERSION_UID_WITH_IDENT = 2;
-    private static final int VERSION_UID_WITH_TAG = 3;
-    private static final int VERSION_UID_WITH_SET = 4;
-
-    private static final int VERSION_UNIFIED_INIT = 16;
-
-    private HashMap<Key, NetworkStatsHistory> mStats = Maps.newHashMap();
-
-    private final long mBucketDuration;
-
-    private long mStartMillis;
-    private long mEndMillis;
-    private long mTotalBytes;
-    private boolean mDirty;
-
-    public NetworkStatsCollection(long bucketDuration) {
-        mBucketDuration = bucketDuration;
-        reset();
-    }
-
-    public void reset() {
-        mStats.clear();
-        mStartMillis = Long.MAX_VALUE;
-        mEndMillis = Long.MIN_VALUE;
-        mTotalBytes = 0;
-        mDirty = false;
-    }
-
-    public long getStartMillis() {
-        return mStartMillis;
-    }
-
-    /**
-     * Return first atomic bucket in this collection, which is more conservative
-     * than {@link #mStartMillis}.
-     */
-    public long getFirstAtomicBucketMillis() {
-        if (mStartMillis == Long.MAX_VALUE) {
-            return Long.MAX_VALUE;
-        } else {
-            return mStartMillis + mBucketDuration;
-        }
-    }
-
-    public long getEndMillis() {
-        return mEndMillis;
-    }
-
-    public long getTotalBytes() {
-        return mTotalBytes;
-    }
-
-    public boolean isDirty() {
-        return mDirty;
-    }
-
-    public void clearDirty() {
-        mDirty = false;
-    }
-
-    public boolean isEmpty() {
-        return mStartMillis == Long.MAX_VALUE && mEndMillis == Long.MIN_VALUE;
-    }
-
-    /**
-     * Combine all {@link NetworkStatsHistory} in this collection which match
-     * the requested parameters.
-     */
-    public NetworkStatsHistory getHistory(
-            NetworkTemplate template, int uid, int set, int tag, int fields) {
-        return getHistory(template, uid, set, tag, fields, Long.MIN_VALUE, Long.MAX_VALUE);
-    }
-
-    /**
-     * Combine all {@link NetworkStatsHistory} in this collection which match
-     * the requested parameters.
-     */
-    public NetworkStatsHistory getHistory(
-            NetworkTemplate template, int uid, int set, int tag, int fields, long start, long end) {
-        final NetworkStatsHistory combined = new NetworkStatsHistory(
-                mBucketDuration, estimateBuckets(), fields);
-        for (Map.Entry<Key, NetworkStatsHistory> entry : mStats.entrySet()) {
-            final Key key = entry.getKey();
-            final boolean setMatches = set == SET_ALL || key.set == set;
-            if (key.uid == uid && setMatches && key.tag == tag
-                    && templateMatches(template, key.ident)) {
-                combined.recordHistory(entry.getValue(), start, end);
-            }
-        }
-        return combined;
-    }
-
-    /**
-     * Summarize all {@link NetworkStatsHistory} in this collection which match
-     * the requested parameters.
-     */
-    public NetworkStats getSummary(NetworkTemplate template, long start, long end) {
-        final long now = System.currentTimeMillis();
-
-        final NetworkStats stats = new NetworkStats(end - start, 24);
-        final NetworkStats.Entry entry = new NetworkStats.Entry();
-        NetworkStatsHistory.Entry historyEntry = null;
-
-        // shortcut when we know stats will be empty
-        if (start == end) return stats;
-
-        for (Map.Entry<Key, NetworkStatsHistory> mapEntry : mStats.entrySet()) {
-            final Key key = mapEntry.getKey();
-            if (templateMatches(template, key.ident)) {
-                final NetworkStatsHistory history = mapEntry.getValue();
-                historyEntry = history.getValues(start, end, now, historyEntry);
-
-                entry.iface = IFACE_ALL;
-                entry.uid = key.uid;
-                entry.set = key.set;
-                entry.tag = key.tag;
-                entry.rxBytes = historyEntry.rxBytes;
-                entry.rxPackets = historyEntry.rxPackets;
-                entry.txBytes = historyEntry.txBytes;
-                entry.txPackets = historyEntry.txPackets;
-                entry.operations = historyEntry.operations;
-
-                if (!entry.isEmpty()) {
-                    stats.combineValues(entry);
-                }
-            }
-        }
-
-        return stats;
-    }
-
-    /**
-     * Record given {@link android.net.NetworkStats.Entry} into this collection.
-     */
-    public void recordData(NetworkIdentitySet ident, int uid, int set, int tag, long start,
-            long end, NetworkStats.Entry entry) {
-        final NetworkStatsHistory history = findOrCreateHistory(ident, uid, set, tag);
-        history.recordData(start, end, entry);
-        noteRecordedHistory(history.getStart(), history.getEnd(), entry.rxBytes + entry.txBytes);
-    }
-
-    /**
-     * Record given {@link NetworkStatsHistory} into this collection.
-     */
-    private void recordHistory(Key key, NetworkStatsHistory history) {
-        if (history.size() == 0) return;
-        noteRecordedHistory(history.getStart(), history.getEnd(), history.getTotalBytes());
-
-        NetworkStatsHistory target = mStats.get(key);
-        if (target == null) {
-            target = new NetworkStatsHistory(history.getBucketDuration());
-            mStats.put(key, target);
-        }
-        target.recordEntireHistory(history);
-    }
-
-    /**
-     * Record all {@link NetworkStatsHistory} contained in the given collection
-     * into this collection.
-     */
-    public void recordCollection(NetworkStatsCollection another) {
-        for (Map.Entry<Key, NetworkStatsHistory> entry : another.mStats.entrySet()) {
-            recordHistory(entry.getKey(), entry.getValue());
-        }
-    }
-
-    private NetworkStatsHistory findOrCreateHistory(
-            NetworkIdentitySet ident, int uid, int set, int tag) {
-        final Key key = new Key(ident, uid, set, tag);
-        final NetworkStatsHistory existing = mStats.get(key);
-
-        // update when no existing, or when bucket duration changed
-        NetworkStatsHistory updated = null;
-        if (existing == null) {
-            updated = new NetworkStatsHistory(mBucketDuration, 10);
-        } else if (existing.getBucketDuration() != mBucketDuration) {
-            updated = new NetworkStatsHistory(existing, mBucketDuration);
-        }
-
-        if (updated != null) {
-            mStats.put(key, updated);
-            return updated;
-        } else {
-            return existing;
-        }
-    }
-
-    @Override
-    public void read(InputStream in) throws IOException {
-        read(new DataInputStream(in));
-    }
-
-    public void read(DataInputStream in) throws IOException {
-        // verify file magic header intact
-        final int magic = in.readInt();
-        if (magic != FILE_MAGIC) {
-            throw new ProtocolException("unexpected magic: " + magic);
-        }
-
-        final int version = in.readInt();
-        switch (version) {
-            case VERSION_UNIFIED_INIT: {
-                // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
-                final int identSize = in.readInt();
-                for (int i = 0; i < identSize; i++) {
-                    final NetworkIdentitySet ident = new NetworkIdentitySet(in);
-
-                    final int size = in.readInt();
-                    for (int j = 0; j < size; j++) {
-                        final int uid = in.readInt();
-                        final int set = in.readInt();
-                        final int tag = in.readInt();
-
-                        final Key key = new Key(ident, uid, set, tag);
-                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
-                        recordHistory(key, history);
-                    }
-                }
-                break;
-            }
-            default: {
-                throw new ProtocolException("unexpected version: " + version);
-            }
-        }
-    }
-
-    public void write(DataOutputStream out) throws IOException {
-        // cluster key lists grouped by ident
-        final HashMap<NetworkIdentitySet, ArrayList<Key>> keysByIdent = Maps.newHashMap();
-        for (Key key : mStats.keySet()) {
-            ArrayList<Key> keys = keysByIdent.get(key.ident);
-            if (keys == null) {
-                keys = Lists.newArrayList();
-                keysByIdent.put(key.ident, keys);
-            }
-            keys.add(key);
-        }
-
-        out.writeInt(FILE_MAGIC);
-        out.writeInt(VERSION_UNIFIED_INIT);
-
-        out.writeInt(keysByIdent.size());
-        for (NetworkIdentitySet ident : keysByIdent.keySet()) {
-            final ArrayList<Key> keys = keysByIdent.get(ident);
-            ident.writeToStream(out);
-
-            out.writeInt(keys.size());
-            for (Key key : keys) {
-                final NetworkStatsHistory history = mStats.get(key);
-                out.writeInt(key.uid);
-                out.writeInt(key.set);
-                out.writeInt(key.tag);
-                history.writeToStream(out);
-            }
-        }
-
-        out.flush();
-    }
-
-    @Deprecated
-    public void readLegacyNetwork(File file) throws IOException {
-        final AtomicFile inputFile = new AtomicFile(file);
-
-        DataInputStream in = null;
-        try {
-            in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
-
-            // verify file magic header intact
-            final int magic = in.readInt();
-            if (magic != FILE_MAGIC) {
-                throw new ProtocolException("unexpected magic: " + magic);
-            }
-
-            final int version = in.readInt();
-            switch (version) {
-                case VERSION_NETWORK_INIT: {
-                    // network := size *(NetworkIdentitySet NetworkStatsHistory)
-                    final int size = in.readInt();
-                    for (int i = 0; i < size; i++) {
-                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
-                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
-
-                        final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
-                        recordHistory(key, history);
-                    }
-                    break;
-                }
-                default: {
-                    throw new ProtocolException("unexpected version: " + version);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            // missing stats is okay, probably first boot
-        } finally {
-            IoUtils.closeQuietly(in);
-        }
-    }
-
-    @Deprecated
-    public void readLegacyUid(File file, boolean onlyTags) throws IOException {
-        final AtomicFile inputFile = new AtomicFile(file);
-
-        DataInputStream in = null;
-        try {
-            in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
-
-            // verify file magic header intact
-            final int magic = in.readInt();
-            if (magic != FILE_MAGIC) {
-                throw new ProtocolException("unexpected magic: " + magic);
-            }
-
-            final int version = in.readInt();
-            switch (version) {
-                case VERSION_UID_INIT: {
-                    // uid := size *(UID NetworkStatsHistory)
-
-                    // drop this data version, since we don't have a good
-                    // mapping into NetworkIdentitySet.
-                    break;
-                }
-                case VERSION_UID_WITH_IDENT: {
-                    // uid := size *(NetworkIdentitySet size *(UID NetworkStatsHistory))
-
-                    // drop this data version, since this version only existed
-                    // for a short time.
-                    break;
-                }
-                case VERSION_UID_WITH_TAG:
-                case VERSION_UID_WITH_SET: {
-                    // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
-                    final int identSize = in.readInt();
-                    for (int i = 0; i < identSize; i++) {
-                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
-
-                        final int size = in.readInt();
-                        for (int j = 0; j < size; j++) {
-                            final int uid = in.readInt();
-                            final int set = (version >= VERSION_UID_WITH_SET) ? in.readInt()
-                                    : SET_DEFAULT;
-                            final int tag = in.readInt();
-
-                            final Key key = new Key(ident, uid, set, tag);
-                            final NetworkStatsHistory history = new NetworkStatsHistory(in);
-
-                            if ((tag == TAG_NONE) != onlyTags) {
-                                recordHistory(key, history);
-                            }
-                        }
-                    }
-                    break;
-                }
-                default: {
-                    throw new ProtocolException("unexpected version: " + version);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            // missing stats is okay, probably first boot
-        } finally {
-            IoUtils.closeQuietly(in);
-        }
-    }
-
-    /**
-     * Remove any {@link NetworkStatsHistory} attributed to the requested UID,
-     * moving any {@link NetworkStats#TAG_NONE} series to
-     * {@link TrafficStats#UID_REMOVED}.
-     */
-    public void removeUids(int[] uids) {
-        final ArrayList<Key> knownKeys = Lists.newArrayList();
-        knownKeys.addAll(mStats.keySet());
-
-        // migrate all UID stats into special "removed" bucket
-        for (Key key : knownKeys) {
-            if (ArrayUtils.contains(uids, key.uid)) {
-                // only migrate combined TAG_NONE history
-                if (key.tag == TAG_NONE) {
-                    final NetworkStatsHistory uidHistory = mStats.get(key);
-                    final NetworkStatsHistory removedHistory = findOrCreateHistory(
-                            key.ident, UID_REMOVED, SET_DEFAULT, TAG_NONE);
-                    removedHistory.recordEntireHistory(uidHistory);
-                }
-                mStats.remove(key);
-                mDirty = true;
-            }
-        }
-    }
-
-    private void noteRecordedHistory(long startMillis, long endMillis, long totalBytes) {
-        if (startMillis < mStartMillis) mStartMillis = startMillis;
-        if (endMillis > mEndMillis) mEndMillis = endMillis;
-        mTotalBytes += totalBytes;
-        mDirty = true;
-    }
-
-    private int estimateBuckets() {
-        return (int) (Math.min(mEndMillis - mStartMillis, DateUtils.WEEK_IN_MILLIS * 5)
-                / mBucketDuration);
-    }
-
-    public void dump(IndentingPrintWriter pw) {
-        final ArrayList<Key> keys = Lists.newArrayList();
-        keys.addAll(mStats.keySet());
-        Collections.sort(keys);
-
-        for (Key key : keys) {
-            pw.print("ident="); pw.print(key.ident.toString());
-            pw.print(" uid="); pw.print(key.uid);
-            pw.print(" set="); pw.print(NetworkStats.setToString(key.set));
-            pw.print(" tag="); pw.println(NetworkStats.tagToString(key.tag));
-
-            final NetworkStatsHistory history = mStats.get(key);
-            pw.increaseIndent();
-            history.dump(pw, true);
-            pw.decreaseIndent();
-        }
-    }
-
-    /**
-     * Test if given {@link NetworkTemplate} matches any {@link NetworkIdentity}
-     * in the given {@link NetworkIdentitySet}.
-     */
-    private static boolean templateMatches(NetworkTemplate template, NetworkIdentitySet identSet) {
-        for (NetworkIdentity ident : identSet) {
-            if (template.matches(ident)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private static class Key implements Comparable<Key> {
-        public final NetworkIdentitySet ident;
-        public final int uid;
-        public final int set;
-        public final int tag;
-
-        private final int hashCode;
-
-        public Key(NetworkIdentitySet ident, int uid, int set, int tag) {
-            this.ident = ident;
-            this.uid = uid;
-            this.set = set;
-            this.tag = tag;
-            hashCode = Objects.hashCode(ident, uid, set, tag);
-        }
-
-        @Override
-        public int hashCode() {
-            return hashCode;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (obj instanceof Key) {
-                final Key key = (Key) obj;
-                return uid == key.uid && set == key.set && tag == key.tag
-                        && Objects.equal(ident, key.ident);
-            }
-            return false;
-        }
-
-        @Override
-        public int compareTo(Key another) {
-            return Integer.compare(uid, another.uid);
-        }
-    }
-}
diff --git a/services/java/com/android/server/pm/Installer.java b/services/java/com/android/server/pm/Installer.java
deleted file mode 100644
index 734d071..0000000
--- a/services/java/com/android/server/pm/Installer.java
+++ /dev/null
@@ -1,373 +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.server.pm;
-
-import android.content.pm.PackageStats;
-import android.net.LocalSocket;
-import android.net.LocalSocketAddress;
-import android.util.Slog;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-public final class Installer {
-    private static final String TAG = "Installer";
-
-    private static final boolean LOCAL_DEBUG = false;
-
-    InputStream mIn;
-
-    OutputStream mOut;
-
-    LocalSocket mSocket;
-
-    byte buf[] = new byte[1024];
-
-    int buflen = 0;
-
-    private boolean connect() {
-        if (mSocket != null) {
-            return true;
-        }
-        Slog.i(TAG, "connecting...");
-        try {
-            mSocket = new LocalSocket();
-
-            LocalSocketAddress address = new LocalSocketAddress("installd",
-                    LocalSocketAddress.Namespace.RESERVED);
-
-            mSocket.connect(address);
-
-            mIn = mSocket.getInputStream();
-            mOut = mSocket.getOutputStream();
-        } catch (IOException ex) {
-            disconnect();
-            return false;
-        }
-        return true;
-    }
-
-    private void disconnect() {
-        Slog.i(TAG, "disconnecting...");
-        try {
-            if (mSocket != null)
-                mSocket.close();
-        } catch (IOException ex) {
-        }
-        try {
-            if (mIn != null)
-                mIn.close();
-        } catch (IOException ex) {
-        }
-        try {
-            if (mOut != null)
-                mOut.close();
-        } catch (IOException ex) {
-        }
-        mSocket = null;
-        mIn = null;
-        mOut = null;
-    }
-
-    private boolean readBytes(byte buffer[], int len) {
-        int off = 0, count;
-        if (len < 0)
-            return false;
-        while (off != len) {
-            try {
-                count = mIn.read(buffer, off, len - off);
-                if (count <= 0) {
-                    Slog.e(TAG, "read error " + count);
-                    break;
-                }
-                off += count;
-            } catch (IOException ex) {
-                Slog.e(TAG, "read exception");
-                break;
-            }
-        }
-        if (LOCAL_DEBUG) {
-            Slog.i(TAG, "read " + len + " bytes");
-        }
-        if (off == len)
-            return true;
-        disconnect();
-        return false;
-    }
-
-    private boolean readReply() {
-        int len;
-        buflen = 0;
-        if (!readBytes(buf, 2))
-            return false;
-        len = (((int) buf[0]) & 0xff) | ((((int) buf[1]) & 0xff) << 8);
-        if ((len < 1) || (len > 1024)) {
-            Slog.e(TAG, "invalid reply length (" + len + ")");
-            disconnect();
-            return false;
-        }
-        if (!readBytes(buf, len))
-            return false;
-        buflen = len;
-        return true;
-    }
-
-    private boolean writeCommand(String _cmd) {
-        byte[] cmd = _cmd.getBytes();
-        int len = cmd.length;
-        if ((len < 1) || (len > 1024))
-            return false;
-        buf[0] = (byte) (len & 0xff);
-        buf[1] = (byte) ((len >> 8) & 0xff);
-        try {
-            mOut.write(buf, 0, 2);
-            mOut.write(cmd, 0, len);
-        } catch (IOException ex) {
-            Slog.e(TAG, "write error");
-            disconnect();
-            return false;
-        }
-        return true;
-    }
-
-    private synchronized String transaction(String cmd) {
-        if (!connect()) {
-            Slog.e(TAG, "connection failed");
-            return "-1";
-        }
-
-        if (!writeCommand(cmd)) {
-            /*
-             * If installd died and restarted in the background (unlikely but
-             * possible) we'll fail on the next write (this one). Try to
-             * reconnect and write the command one more time before giving up.
-             */
-            Slog.e(TAG, "write command failed? reconnect!");
-            if (!connect() || !writeCommand(cmd)) {
-                return "-1";
-            }
-        }
-        if (LOCAL_DEBUG) {
-            Slog.i(TAG, "send: '" + cmd + "'");
-        }
-        if (readReply()) {
-            String s = new String(buf, 0, buflen);
-            if (LOCAL_DEBUG) {
-                Slog.i(TAG, "recv: '" + s + "'");
-            }
-            return s;
-        } else {
-            if (LOCAL_DEBUG) {
-                Slog.i(TAG, "fail");
-            }
-            return "-1";
-        }
-    }
-
-    private int execute(String cmd) {
-        String res = transaction(cmd);
-        try {
-            return Integer.parseInt(res);
-        } catch (NumberFormatException ex) {
-            return -1;
-        }
-    }
-
-    public int install(String name, int uid, int gid, String seinfo) {
-        StringBuilder builder = new StringBuilder("install");
-        builder.append(' ');
-        builder.append(name);
-        builder.append(' ');
-        builder.append(uid);
-        builder.append(' ');
-        builder.append(gid);
-        builder.append(' ');
-        builder.append(seinfo != null ? seinfo : "!");
-        return execute(builder.toString());
-    }
-
-    public int dexopt(String apkPath, int uid, boolean isPublic) {
-        StringBuilder builder = new StringBuilder("dexopt");
-        builder.append(' ');
-        builder.append(apkPath);
-        builder.append(' ');
-        builder.append(uid);
-        builder.append(isPublic ? " 1" : " 0");
-        return execute(builder.toString());
-    }
-
-    public int movedex(String srcPath, String dstPath) {
-        StringBuilder builder = new StringBuilder("movedex");
-        builder.append(' ');
-        builder.append(srcPath);
-        builder.append(' ');
-        builder.append(dstPath);
-        return execute(builder.toString());
-    }
-
-    public int rmdex(String codePath) {
-        StringBuilder builder = new StringBuilder("rmdex");
-        builder.append(' ');
-        builder.append(codePath);
-        return execute(builder.toString());
-    }
-
-    public int remove(String name, int userId) {
-        StringBuilder builder = new StringBuilder("remove");
-        builder.append(' ');
-        builder.append(name);
-        builder.append(' ');
-        builder.append(userId);
-        return execute(builder.toString());
-    }
-
-    public int rename(String oldname, String newname) {
-        StringBuilder builder = new StringBuilder("rename");
-        builder.append(' ');
-        builder.append(oldname);
-        builder.append(' ');
-        builder.append(newname);
-        return execute(builder.toString());
-    }
-
-    public int fixUid(String name, int uid, int gid) {
-        StringBuilder builder = new StringBuilder("fixuid");
-        builder.append(' ');
-        builder.append(name);
-        builder.append(' ');
-        builder.append(uid);
-        builder.append(' ');
-        builder.append(gid);
-        return execute(builder.toString());
-    }
-
-    public int deleteCacheFiles(String name, int userId) {
-        StringBuilder builder = new StringBuilder("rmcache");
-        builder.append(' ');
-        builder.append(name);
-        builder.append(' ');
-        builder.append(userId);
-        return execute(builder.toString());
-    }
-
-    public int createUserData(String name, int uid, int userId) {
-        StringBuilder builder = new StringBuilder("mkuserdata");
-        builder.append(' ');
-        builder.append(name);
-        builder.append(' ');
-        builder.append(uid);
-        builder.append(' ');
-        builder.append(userId);
-        return execute(builder.toString());
-    }
-
-    public int removeUserDataDirs(int userId) {
-        StringBuilder builder = new StringBuilder("rmuser");
-        builder.append(' ');
-        builder.append(userId);
-        return execute(builder.toString());
-    }
-
-    public int clearUserData(String name, int userId) {
-        StringBuilder builder = new StringBuilder("rmuserdata");
-        builder.append(' ');
-        builder.append(name);
-        builder.append(' ');
-        builder.append(userId);
-        return execute(builder.toString());
-    }
-
-    public boolean ping() {
-        if (execute("ping") < 0) {
-            return false;
-        } else {
-            return true;
-        }
-    }
-
-    public int freeCache(long freeStorageSize) {
-        StringBuilder builder = new StringBuilder("freecache");
-        builder.append(' ');
-        builder.append(String.valueOf(freeStorageSize));
-        return execute(builder.toString());
-    }
-
-    public int getSizeInfo(String pkgName, int persona, String apkPath, String libDirPath,
-            String fwdLockApkPath, String asecPath, PackageStats pStats) {
-        StringBuilder builder = new StringBuilder("getsize");
-        builder.append(' ');
-        builder.append(pkgName);
-        builder.append(' ');
-        builder.append(persona);
-        builder.append(' ');
-        builder.append(apkPath);
-        builder.append(' ');
-        builder.append(libDirPath != null ? libDirPath : "!");
-        builder.append(' ');
-        builder.append(fwdLockApkPath != null ? fwdLockApkPath : "!");
-        builder.append(' ');
-        builder.append(asecPath != null ? asecPath : "!");
-
-        String s = transaction(builder.toString());
-        String res[] = s.split(" ");
-
-        if ((res == null) || (res.length != 5)) {
-            return -1;
-        }
-        try {
-            pStats.codeSize = Long.parseLong(res[1]);
-            pStats.dataSize = Long.parseLong(res[2]);
-            pStats.cacheSize = Long.parseLong(res[3]);
-            pStats.externalCodeSize = Long.parseLong(res[4]);
-            return Integer.parseInt(res[0]);
-        } catch (NumberFormatException e) {
-            return -1;
-        }
-    }
-
-    public int moveFiles() {
-        return execute("movefiles");
-    }
-
-    /**
-     * Links the native library directory in an application's directory to its
-     * real location.
-     *
-     * @param dataPath data directory where the application is
-     * @param nativeLibPath target native library path
-     * @return -1 on error
-     */
-    public int linkNativeLibraryDirectory(String dataPath, String nativeLibPath, int userId) {
-        if (dataPath == null) {
-            Slog.e(TAG, "linkNativeLibraryDirectory dataPath is null");
-            return -1;
-        } else if (nativeLibPath == null) {
-            Slog.e(TAG, "linkNativeLibraryDirectory nativeLibPath is null");
-            return -1;
-        }
-
-        StringBuilder builder = new StringBuilder("linklib ");
-        builder.append(dataPath);
-        builder.append(' ');
-        builder.append(nativeLibPath);
-        builder.append(' ');
-        builder.append(userId);
-
-        return execute(builder.toString());
-    }
-}
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
deleted file mode 100755
index dc63ca2..0000000
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ /dev/null
@@ -1,11627 +0,0 @@
-/*
- * Copyright (C) 2006 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.pm;
-
-import static android.Manifest.permission.GRANT_REVOKE_PERMISSIONS;
-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 com.android.internal.util.ArrayUtils.appendInt;
-import static com.android.internal.util.ArrayUtils.removeInt;
-import static libcore.io.OsConstants.S_IRWXU;
-import static libcore.io.OsConstants.S_IRGRP;
-import static libcore.io.OsConstants.S_IXGRP;
-import static libcore.io.OsConstants.S_IROTH;
-import static libcore.io.OsConstants.S_IXOTH;
-
-import com.android.internal.app.IMediaContainerService;
-import com.android.internal.app.ResolverActivity;
-import com.android.internal.content.NativeLibraryHelper;
-import com.android.internal.content.PackageHelper;
-import com.android.internal.util.FastPrintWriter;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.XmlUtils;
-import com.android.server.DeviceStorageMonitorService;
-import com.android.server.EventLogTags;
-import com.android.server.IntentResolver;
-
-import com.android.server.Watchdog;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.app.ActivityManager;
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import android.app.admin.IDevicePolicyManager;
-import android.app.backup.IBackupManager;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.IIntentReceiver;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.IntentSender;
-import android.content.ServiceConnection;
-import android.content.IntentSender.SendIntentException;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.ContainerEncryptionParams;
-import android.content.pm.FeatureInfo;
-import android.content.pm.IPackageDataObserver;
-import android.content.pm.IPackageDeleteObserver;
-import android.content.pm.IPackageInstallObserver;
-import android.content.pm.IPackageManager;
-import android.content.pm.IPackageMoveObserver;
-import android.content.pm.IPackageStatsObserver;
-import android.content.pm.InstrumentationInfo;
-import android.content.pm.PackageCleanItem;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageInfoLite;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageParser;
-import android.content.pm.PackageUserState;
-import android.content.pm.PackageParser.ActivityIntentInfo;
-import android.content.pm.PackageStats;
-import android.content.pm.ParceledListSlice;
-import android.content.pm.PermissionGroupInfo;
-import android.content.pm.PermissionInfo;
-import android.content.pm.ProviderInfo;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.content.pm.Signature;
-import android.content.pm.ManifestDigest;
-import android.content.pm.VerificationParams;
-import android.content.pm.VerifierDeviceIdentity;
-import android.content.pm.VerifierInfo;
-import android.content.res.Resources;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.FileObserver;
-import android.os.FileUtils;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.Looper;
-import android.os.Message;
-import android.os.Parcel;
-import android.os.ParcelFileDescriptor;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SELinux;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UserHandle;
-import android.os.Environment.UserEnvironment;
-import android.os.UserManager;
-import android.security.KeyStore;
-import android.security.SystemKeyStore;
-import android.text.TextUtils;
-import android.util.DisplayMetrics;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.LogPrinter;
-import android.util.PrintStreamPrinter;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.Xml;
-import android.view.Display;
-import android.view.WindowManager;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.security.NoSuchAlgorithmException;
-import java.security.PublicKey;
-import java.security.cert.CertificateException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import libcore.io.ErrnoException;
-import libcore.io.IoUtils;
-import libcore.io.Libcore;
-import libcore.io.StructStat;
-
-import com.android.internal.R;
-
-/**
- * Keep track of all those .apks everywhere.
- * 
- * This is very central to the platform's security; please run the unit
- * tests whenever making modifications here:
- * 
-mmm frameworks/base/tests/AndroidTests
-adb install -r -f out/target/product/passion/data/app/AndroidTests.apk
-adb shell am instrument -w -e class com.android.unit_tests.PackageManagerTests com.android.unit_tests/android.test.InstrumentationTestRunner
- * 
- * {@hide}
- */
-public class PackageManagerService extends IPackageManager.Stub {
-    static final String TAG = "PackageManager";
-    static final boolean DEBUG_SETTINGS = false;
-    static final boolean DEBUG_PREFERRED = false;
-    static final boolean DEBUG_UPGRADE = false;
-    private static final boolean DEBUG_INSTALL = false;
-    private static final boolean DEBUG_REMOVE = false;
-    private static final boolean DEBUG_BROADCASTS = false;
-    private static final boolean DEBUG_SHOW_INFO = false;
-    private static final boolean DEBUG_PACKAGE_INFO = false;
-    private static final boolean DEBUG_INTENT_MATCHING = false;
-    private static final boolean DEBUG_PACKAGE_SCANNING = false;
-    private static final boolean DEBUG_APP_DIR_OBSERVER = false;
-    private static final boolean DEBUG_VERIFY = false;
-
-    private static final int RADIO_UID = Process.PHONE_UID;
-    private static final int LOG_UID = Process.LOG_UID;
-    private static final int NFC_UID = Process.NFC_UID;
-    private static final int BLUETOOTH_UID = Process.BLUETOOTH_UID;
-    private static final int SHELL_UID = Process.SHELL_UID;
-
-    private static final boolean GET_CERTIFICATES = true;
-
-    private static final int REMOVE_EVENTS =
-        FileObserver.CLOSE_WRITE | FileObserver.DELETE | FileObserver.MOVED_FROM;
-    private static final int ADD_EVENTS =
-        FileObserver.CLOSE_WRITE /*| FileObserver.CREATE*/ | FileObserver.MOVED_TO;
-
-    private static final int OBSERVER_EVENTS = REMOVE_EVENTS | ADD_EVENTS;
-    // Suffix used during package installation when copying/moving
-    // package apks to install directory.
-    private static final String INSTALL_PACKAGE_SUFFIX = "-";
-
-    static final int SCAN_MONITOR = 1<<0;
-    static final int SCAN_NO_DEX = 1<<1;
-    static final int SCAN_FORCE_DEX = 1<<2;
-    static final int SCAN_UPDATE_SIGNATURE = 1<<3;
-    static final int SCAN_NEW_INSTALL = 1<<4;
-    static final int SCAN_NO_PATHS = 1<<5;
-    static final int SCAN_UPDATE_TIME = 1<<6;
-    static final int SCAN_DEFER_DEX = 1<<7;
-    static final int SCAN_BOOTING = 1<<8;
-    static final int SCAN_DELETE_DATA_ON_FAILURES = 1<<9;
-
-    static final int REMOVE_CHATTY = 1<<16;
-
-    /**
-     * Timeout (in milliseconds) after which the watchdog should declare that
-     * our handler thread is wedged.  The usual default for such things is one
-     * minute but we sometimes do very lengthy I/O operations on this thread,
-     * such as installing multi-gigabyte applications, so ours needs to be longer.
-     */
-    private static final long WATCHDOG_TIMEOUT = 1000*60*10;     // ten minutes
-
-    /**
-     * Whether verification is enabled by default.
-     */
-    private static final boolean DEFAULT_VERIFY_ENABLE = true;
-
-    /**
-     * The default maximum time to wait for the verification agent to return in
-     * milliseconds.
-     */
-    private static final long DEFAULT_VERIFICATION_TIMEOUT = 10 * 1000;
-
-    /**
-     * The default response for package verification timeout.
-     *
-     * This can be either PackageManager.VERIFICATION_ALLOW or
-     * PackageManager.VERIFICATION_REJECT.
-     */
-    private static final int DEFAULT_VERIFICATION_RESPONSE = PackageManager.VERIFICATION_ALLOW;
-
-    static final String DEFAULT_CONTAINER_PACKAGE = "com.android.defcontainer";
-
-    static final ComponentName DEFAULT_CONTAINER_COMPONENT = new ComponentName(
-            DEFAULT_CONTAINER_PACKAGE,
-            "com.android.defcontainer.DefaultContainerService");
-
-    private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
-
-    private static final String LIB_DIR_NAME = "lib";
-
-    static final String mTempContainerPrefix = "smdl2tmp";
-
-    final HandlerThread mHandlerThread = new HandlerThread("PackageManager",
-            Process.THREAD_PRIORITY_BACKGROUND);
-    final PackageHandler mHandler;
-
-    final int mSdkVersion = Build.VERSION.SDK_INT;
-    final String mSdkCodename = "REL".equals(Build.VERSION.CODENAME)
-            ? null : Build.VERSION.CODENAME;
-
-    final Context mContext;
-    final boolean mFactoryTest;
-    final boolean mOnlyCore;
-    final boolean mNoDexOpt;
-    final DisplayMetrics mMetrics;
-    final int mDefParseFlags;
-    final String[] mSeparateProcesses;
-
-    // This is where all application persistent data goes.
-    final File mAppDataDir;
-
-    // This is where all application persistent data goes for secondary users.
-    final File mUserAppDataDir;
-
-    /** The location for ASEC container files on internal storage. */
-    final String mAsecInternalPath;
-
-    // This is the object monitoring the framework dir.
-    final FileObserver mFrameworkInstallObserver;
-
-    // This is the object monitoring the system app dir.
-    final FileObserver mSystemInstallObserver;
-
-    // This is the object monitoring the privileged system app dir.
-    final FileObserver mPrivilegedInstallObserver;
-
-    // This is the object monitoring the system app dir.
-    final FileObserver mVendorInstallObserver;
-
-    // This is the object monitoring mAppInstallDir.
-    final FileObserver mAppInstallObserver;
-
-    // This is the object monitoring mDrmAppPrivateInstallDir.
-    final FileObserver mDrmAppInstallObserver;
-
-    // Used for privilege escalation. MUST NOT BE CALLED WITH mPackages
-    // LOCK HELD.  Can be called with mInstallLock held.
-    final Installer mInstaller;
-
-    final File mAppInstallDir;
-
-    /**
-     * Directory to which applications installed internally have native
-     * libraries copied.
-     */
-    private File mAppLibInstallDir;
-
-    // Directory containing the private parts (e.g. code and non-resource assets) of forward-locked
-    // apps.
-    final File mDrmAppPrivateInstallDir;
-
-    // ----------------------------------------------------------------
-
-    // Lock for state used when installing and doing other long running
-    // operations.  Methods that must be called with this lock held have
-    // the prefix "LI".
-    final Object mInstallLock = new Object();
-
-    // These are the directories in the 3rd party applications installed dir
-    // that we have currently loaded packages from.  Keys are the application's
-    // installed zip file (absolute codePath), and values are Package.
-    final HashMap<String, PackageParser.Package> mAppDirs =
-            new HashMap<String, PackageParser.Package>();
-
-    // Information for the parser to write more useful error messages.
-    int mLastScanError;
-
-    // ----------------------------------------------------------------
-
-    // Keys are String (package name), values are Package.  This also serves
-    // as the lock for the global state.  Methods that must be called with
-    // this lock held have the prefix "LP".
-    final HashMap<String, PackageParser.Package> mPackages =
-            new HashMap<String, PackageParser.Package>();
-
-    final Settings mSettings;
-    boolean mRestoredSettings;
-
-    // Group-ids that are given to all packages as read from etc/permissions/*.xml.
-    int[] mGlobalGids;
-
-    // These are the built-in uid -> permission mappings that were read from the
-    // etc/permissions.xml file.
-    final SparseArray<HashSet<String>> mSystemPermissions =
-            new SparseArray<HashSet<String>>();
-
-    static final class SharedLibraryEntry {
-        final String path;
-        final String apk;
-
-        SharedLibraryEntry(String _path, String _apk) {
-            path = _path;
-            apk = _apk;
-        }
-    }
-
-    // These are the built-in shared libraries that were read from the
-    // etc/permissions.xml file.
-    final HashMap<String, SharedLibraryEntry> mSharedLibraries
-            = new HashMap<String, SharedLibraryEntry>();
-
-    // Temporary for building the final shared libraries for an .apk.
-    String[] mTmpSharedLibraries = null;
-
-    // These are the features this devices supports that were read from the
-    // etc/permissions.xml file.
-    final HashMap<String, FeatureInfo> mAvailableFeatures =
-            new HashMap<String, FeatureInfo>();
-
-    // If mac_permissions.xml was found for seinfo labeling.
-    boolean mFoundPolicyFile;
-
-    // All available activities, for your resolving pleasure.
-    final ActivityIntentResolver mActivities =
-            new ActivityIntentResolver();
-
-    // All available receivers, for your resolving pleasure.
-    final ActivityIntentResolver mReceivers =
-            new ActivityIntentResolver();
-
-    // All available services, for your resolving pleasure.
-    final ServiceIntentResolver mServices = new ServiceIntentResolver();
-
-    // All available providers, for your resolving pleasure.
-    final ProviderIntentResolver mProviders = new ProviderIntentResolver();
-
-    // Mapping from provider base names (first directory in content URI codePath)
-    // to the provider information.
-    final HashMap<String, PackageParser.Provider> mProvidersByAuthority =
-            new HashMap<String, PackageParser.Provider>();
-
-    // Mapping from instrumentation class names to info about them.
-    final HashMap<ComponentName, PackageParser.Instrumentation> mInstrumentation =
-            new HashMap<ComponentName, PackageParser.Instrumentation>();
-
-    // Mapping from permission names to info about them.
-    final HashMap<String, PackageParser.PermissionGroup> mPermissionGroups =
-            new HashMap<String, PackageParser.PermissionGroup>();
-
-    // Packages whose data we have transfered into another package, thus
-    // should no longer exist.
-    final HashSet<String> mTransferedPackages = new HashSet<String>();
-    
-    // Broadcast actions that are only available to the system.
-    final HashSet<String> mProtectedBroadcasts = new HashSet<String>();
-
-    /** List of packages waiting for verification. */
-    final SparseArray<PackageVerificationState> mPendingVerification
-            = new SparseArray<PackageVerificationState>();
-
-    HashSet<PackageParser.Package> mDeferredDexOpt = null;
-
-    /** Token for keys in mPendingVerification. */
-    private int mPendingVerificationToken = 0;
-
-    boolean mSystemReady;
-    boolean mSafeMode;
-    boolean mHasSystemUidErrors;
-
-    ApplicationInfo mAndroidApplication;
-    final ActivityInfo mResolveActivity = new ActivityInfo();
-    final ResolveInfo mResolveInfo = new ResolveInfo();
-    ComponentName mResolveComponentName;
-    PackageParser.Package mPlatformPackage;
-    ComponentName mCustomResolverComponentName;
-
-    boolean mResolverReplaced = false;
-
-    // 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>
-        final SparseArray<HashMap<String, ArrayList<String>>> mUidMap;
-
-        public PendingPackageBroadcasts() {
-            mUidMap = new SparseArray<HashMap<String, ArrayList<String>>>(2);
-        }
-
-        public ArrayList<String> get(int userId, String packageName) {
-            HashMap<String, ArrayList<String>> packages = getOrAllocate(userId);
-            return packages.get(packageName);
-        }
-
-        public void put(int userId, String packageName, ArrayList<String> components) {
-            HashMap<String, ArrayList<String>> packages = getOrAllocate(userId);
-            packages.put(packageName, components);
-        }
-
-        public void remove(int userId, String packageName) {
-            HashMap<String, ArrayList<String>> packages = mUidMap.get(userId);
-            if (packages != null) {
-                packages.remove(packageName);
-            }
-        }
-
-        public void remove(int userId) {
-            mUidMap.remove(userId);
-        }
-
-        public int userIdCount() {
-            return mUidMap.size();
-        }
-
-        public int userIdAt(int n) {
-            return mUidMap.keyAt(n);
-        }
-
-        public HashMap<String, ArrayList<String>> packagesForUserId(int userId) {
-            return mUidMap.get(userId);
-        }
-
-        public int size() {
-            // total number of pending broadcast entries across all userIds
-            int num = 0;
-            for (int i = 0; i< mUidMap.size(); i++) {
-                num += mUidMap.valueAt(i).size();
-            }
-            return num;
-        }
-
-        public void clear() {
-            mUidMap.clear();
-        }
-
-        private HashMap<String, ArrayList<String>> getOrAllocate(int userId) {
-            HashMap<String, ArrayList<String>> map = mUidMap.get(userId);
-            if (map == null) {
-                map = new HashMap<String, ArrayList<String>>();
-                mUidMap.put(userId, map);
-            }
-            return map;
-        }
-    }
-    final PendingPackageBroadcasts mPendingBroadcasts = new PendingPackageBroadcasts();
-
-    // Service Connection to remote media container service to copy
-    // package uri's from external media onto secure containers
-    // or internal storage.
-    private IMediaContainerService mContainerService = null;
-
-    static final int SEND_PENDING_BROADCAST = 1;
-    static final int MCS_BOUND = 3;
-    static final int END_COPY = 4;
-    static final int INIT_COPY = 5;
-    static final int MCS_UNBIND = 6;
-    static final int START_CLEANING_PACKAGE = 7;
-    static final int FIND_INSTALL_LOC = 8;
-    static final int POST_INSTALL = 9;
-    static final int MCS_RECONNECT = 10;
-    static final int MCS_GIVE_UP = 11;
-    static final int UPDATED_MEDIA_STATUS = 12;
-    static final int WRITE_SETTINGS = 13;
-    static final int WRITE_PACKAGE_RESTRICTIONS = 14;
-    static final int PACKAGE_VERIFIED = 15;
-    static final int CHECK_PENDING_VERIFICATION = 16;
-
-    static final int WRITE_SETTINGS_DELAY = 10*1000;  // 10 seconds
-
-    // Delay time in millisecs
-    static final int BROADCAST_DELAY = 10 * 1000;
-
-    static UserManagerService sUserManager;
-
-    // Stores a list of users whose package restrictions file needs to be updated
-    private HashSet<Integer> mDirtyUsers = new HashSet<Integer>();
-
-    final private DefaultContainerConnection mDefContainerConn =
-            new DefaultContainerConnection();
-    class DefaultContainerConnection implements ServiceConnection {
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceConnected");
-            IMediaContainerService imcs =
-                IMediaContainerService.Stub.asInterface(service);
-            mHandler.sendMessage(mHandler.obtainMessage(MCS_BOUND, imcs));
-        }
-
-        public void onServiceDisconnected(ComponentName name) {
-            if (DEBUG_SD_INSTALL) Log.i(TAG, "onServiceDisconnected");
-        }
-    };
-
-    // Recordkeeping of restore-after-install operations that are currently in flight
-    // between the Package Manager and the Backup Manager
-    class PostInstallData {
-        public InstallArgs args;
-        public PackageInstalledInfo res;
-
-        PostInstallData(InstallArgs _a, PackageInstalledInfo _r) {
-            args = _a;
-            res = _r;
-        }
-    };
-    final SparseArray<PostInstallData> mRunningInstalls = new SparseArray<PostInstallData>();
-    int mNextInstallToken = 1;  // nonzero; will be wrapped back to 1 when ++ overflows
-
-    private final String mRequiredVerifierPackage;
-
-    class PackageHandler extends Handler {
-        private boolean mBound = false;
-        final ArrayList<HandlerParams> mPendingInstalls =
-            new ArrayList<HandlerParams>();
-
-        private boolean connectToService() {
-            if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to bind to" +
-                    " DefaultContainerService");
-            Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
-            Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
-            if (mContext.bindServiceAsUser(service, mDefContainerConn,
-                    Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
-                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-                mBound = true;
-                return true;
-            }
-            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-            return false;
-        }
-
-        private void disconnectService() {
-            mContainerService = null;
-            mBound = false;
-            Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
-            mContext.unbindService(mDefContainerConn);
-            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-        }
-
-        PackageHandler(Looper looper) {
-            super(looper);
-        }
-
-        public void handleMessage(Message msg) {
-            try {
-                doHandleMessage(msg);
-            } finally {
-                Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-            }
-        }
-        
-        void doHandleMessage(Message msg) {
-            switch (msg.what) {
-                case INIT_COPY: {
-                    HandlerParams params = (HandlerParams) msg.obj;
-                    int idx = mPendingInstalls.size();
-                    if (DEBUG_INSTALL) Slog.i(TAG, "init_copy idx=" + idx + ": " + params);
-                    // If a bind was already initiated we dont really
-                    // need to do anything. The pending install
-                    // will be processed later on.
-                    if (!mBound) {
-                        // If this is the only one pending we might
-                        // have to bind to the service again.
-                        if (!connectToService()) {
-                            Slog.e(TAG, "Failed to bind to media container service");
-                            params.serviceError();
-                            return;
-                        } else {
-                            // Once we bind to the service, the first
-                            // pending request will be processed.
-                            mPendingInstalls.add(idx, params);
-                        }
-                    } else {
-                        mPendingInstalls.add(idx, params);
-                        // Already bound to the service. Just make
-                        // sure we trigger off processing the first request.
-                        if (idx == 0) {
-                            mHandler.sendEmptyMessage(MCS_BOUND);
-                        }
-                    }
-                    break;
-                }
-                case MCS_BOUND: {
-                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_bound");
-                    if (msg.obj != null) {
-                        mContainerService = (IMediaContainerService) msg.obj;
-                    }
-                    if (mContainerService == null) {
-                        // Something seriously wrong. Bail out
-                        Slog.e(TAG, "Cannot bind to media container service");
-                        for (HandlerParams params : mPendingInstalls) {
-                            // Indicate service bind error
-                            params.serviceError();
-                        }
-                        mPendingInstalls.clear();
-                    } else if (mPendingInstalls.size() > 0) {
-                        HandlerParams params = mPendingInstalls.get(0);
-                        if (params != null) {
-                            if (params.startCopy()) {
-                                // We are done...  look for more work or to
-                                // go idle.
-                                if (DEBUG_SD_INSTALL) Log.i(TAG,
-                                        "Checking for more work or unbind...");
-                                // Delete pending install
-                                if (mPendingInstalls.size() > 0) {
-                                    mPendingInstalls.remove(0);
-                                }
-                                if (mPendingInstalls.size() == 0) {
-                                    if (mBound) {
-                                        if (DEBUG_SD_INSTALL) Log.i(TAG,
-                                                "Posting delayed MCS_UNBIND");
-                                        removeMessages(MCS_UNBIND);
-                                        Message ubmsg = obtainMessage(MCS_UNBIND);
-                                        // Unbind after a little delay, to avoid
-                                        // continual thrashing.
-                                        sendMessageDelayed(ubmsg, 10000);
-                                    }
-                                } else {
-                                    // There are more pending requests in queue.
-                                    // Just post MCS_BOUND message to trigger processing
-                                    // of next pending install.
-                                    if (DEBUG_SD_INSTALL) Log.i(TAG,
-                                            "Posting MCS_BOUND for next woek");
-                                    mHandler.sendEmptyMessage(MCS_BOUND);
-                                }
-                            }
-                        }
-                    } else {
-                        // Should never happen ideally.
-                        Slog.w(TAG, "Empty queue");
-                    }
-                    break;
-                }
-                case MCS_RECONNECT: {
-                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_reconnect");
-                    if (mPendingInstalls.size() > 0) {
-                        if (mBound) {
-                            disconnectService();
-                        }
-                        if (!connectToService()) {
-                            Slog.e(TAG, "Failed to bind to media container service");
-                            for (HandlerParams params : mPendingInstalls) {
-                                // Indicate service bind error
-                                params.serviceError();
-                            }
-                            mPendingInstalls.clear();
-                        }
-                    }
-                    break;
-                }
-                case MCS_UNBIND: {
-                    // If there is no actual work left, then time to unbind.
-                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_unbind");
-
-                    if (mPendingInstalls.size() == 0 && mPendingVerification.size() == 0) {
-                        if (mBound) {
-                            if (DEBUG_INSTALL) Slog.i(TAG, "calling disconnectService()");
-
-                            disconnectService();
-                        }
-                    } else if (mPendingInstalls.size() > 0) {
-                        // There are more pending requests in queue.
-                        // Just post MCS_BOUND message to trigger processing
-                        // of next pending install.
-                        mHandler.sendEmptyMessage(MCS_BOUND);
-                    }
-
-                    break;
-                }
-                case MCS_GIVE_UP: {
-                    if (DEBUG_INSTALL) Slog.i(TAG, "mcs_giveup too many retries");
-                    mPendingInstalls.remove(0);
-                    break;
-                }
-                case SEND_PENDING_BROADCAST: {
-                    String packages[];
-                    ArrayList<String> components[];
-                    int size = 0;
-                    int uids[];
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
-                    synchronized (mPackages) {
-                        if (mPendingBroadcasts == null) {
-                            return;
-                        }
-                        size = mPendingBroadcasts.size();
-                        if (size <= 0) {
-                            // Nothing to be done. Just return
-                            return;
-                        }
-                        packages = new String[size];
-                        components = new ArrayList[size];
-                        uids = new int[size];
-                        int i = 0;  // filling out the above arrays
-
-                        for (int n = 0; n < mPendingBroadcasts.userIdCount(); n++) {
-                            int packageUserId = mPendingBroadcasts.userIdAt(n);
-                            Iterator<Map.Entry<String, ArrayList<String>>> it
-                                    = mPendingBroadcasts.packagesForUserId(packageUserId)
-                                            .entrySet().iterator();
-                            while (it.hasNext() && i < size) {
-                                Map.Entry<String, ArrayList<String>> ent = it.next();
-                                packages[i] = ent.getKey();
-                                components[i] = ent.getValue();
-                                PackageSetting ps = mSettings.mPackages.get(ent.getKey());
-                                uids[i] = (ps != null)
-                                        ? UserHandle.getUid(packageUserId, ps.appId)
-                                        : -1;
-                                i++;
-                            }
-                        }
-                        size = i;
-                        mPendingBroadcasts.clear();
-                    }
-                    // Send broadcasts
-                    for (int i = 0; i < size; i++) {
-                        sendPackageChangedBroadcast(packages[i], true, components[i], uids[i]);
-                    }
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-                    break;
-                }
-                case START_CLEANING_PACKAGE: {
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
-                    final String packageName = (String)msg.obj;
-                    final int userId = msg.arg1;
-                    final boolean andCode = msg.arg2 != 0;
-                    synchronized (mPackages) {
-                        if (userId == UserHandle.USER_ALL) {
-                            int[] users = sUserManager.getUserIds();
-                            for (int user : users) {
-                                mSettings.addPackageToCleanLPw(
-                                        new PackageCleanItem(user, packageName, andCode));
-                            }
-                        } else {
-                            mSettings.addPackageToCleanLPw(
-                                    new PackageCleanItem(userId, packageName, andCode));
-                        }
-                    }
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-                    startCleaningPackages();
-                } break;
-                case POST_INSTALL: {
-                    if (DEBUG_INSTALL) Log.v(TAG, "Handling post-install for " + msg.arg1);
-                    PostInstallData data = mRunningInstalls.get(msg.arg1);
-                    mRunningInstalls.delete(msg.arg1);
-                    boolean deleteOld = false;
-
-                    if (data != null) {
-                        InstallArgs args = data.args;
-                        PackageInstalledInfo res = data.res;
-
-                        if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
-                            res.removedInfo.sendBroadcast(false, true, false);
-                            Bundle extras = new Bundle(1);
-                            extras.putInt(Intent.EXTRA_UID, res.uid);
-                            // Determine the set of users who are adding this
-                            // package for the first time vs. those who are seeing
-                            // an update.
-                            int[] firstUsers;
-                            int[] updateUsers = new int[0];
-                            if (res.origUsers == null || res.origUsers.length == 0) {
-                                firstUsers = res.newUsers;
-                            } else {
-                                firstUsers = new int[0];
-                                for (int i=0; i<res.newUsers.length; i++) {
-                                    int user = res.newUsers[i];
-                                    boolean isNew = true;
-                                    for (int j=0; j<res.origUsers.length; j++) {
-                                        if (res.origUsers[j] == user) {
-                                            isNew = false;
-                                            break;
-                                        }
-                                    }
-                                    if (isNew) {
-                                        int[] newFirst = new int[firstUsers.length+1];
-                                        System.arraycopy(firstUsers, 0, newFirst, 0,
-                                                firstUsers.length);
-                                        newFirst[firstUsers.length] = user;
-                                        firstUsers = newFirst;
-                                    } else {
-                                        int[] newUpdate = new int[updateUsers.length+1];
-                                        System.arraycopy(updateUsers, 0, newUpdate, 0,
-                                                updateUsers.length);
-                                        newUpdate[updateUsers.length] = user;
-                                        updateUsers = newUpdate;
-                                    }
-                                }
-                            }
-                            sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
-                                    res.pkg.applicationInfo.packageName,
-                                    extras, null, null, firstUsers);
-                            final boolean update = res.removedInfo.removedPackage != null;
-                            if (update) {
-                                extras.putBoolean(Intent.EXTRA_REPLACING, true);
-                            }
-                            sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
-                                    res.pkg.applicationInfo.packageName,
-                                    extras, null, null, updateUsers);
-                            if (update) {
-                                sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED,
-                                        res.pkg.applicationInfo.packageName,
-                                        extras, null, null, updateUsers);
-                                sendPackageBroadcast(Intent.ACTION_MY_PACKAGE_REPLACED,
-                                        null, null,
-                                        res.pkg.applicationInfo.packageName, null, updateUsers);
-
-                                // treat asec-hosted packages like removable media on upgrade
-                                if (isForwardLocked(res.pkg) || isExternal(res.pkg)) {
-                                    if (DEBUG_INSTALL) {
-                                        Slog.i(TAG, "upgrading pkg " + res.pkg
-                                                + " is ASEC-hosted -> AVAILABLE");
-                                    }
-                                    int[] uidArray = new int[] { res.pkg.applicationInfo.uid };
-                                    ArrayList<String> pkgList = new ArrayList<String>(1);
-                                    pkgList.add(res.pkg.applicationInfo.packageName);
-                                    sendResourcesChangedBroadcast(true, true,
-                                            pkgList,uidArray, null);
-                                }
-                            }
-                            if (res.removedInfo.args != null) {
-                                // Remove the replaced package's older resources safely now
-                                deleteOld = true;
-                            }
-
-                            // Log current value of "unknown sources" setting
-                            EventLog.writeEvent(EventLogTags.UNKNOWN_SOURCES_ENABLED,
-                                getUnknownSourcesSettings());
-                        }
-                        // Force a gc to clear up things
-                        Runtime.getRuntime().gc();
-                        // We delete after a gc for applications  on sdcard.
-                        if (deleteOld) {
-                            synchronized (mInstallLock) {
-                                res.removedInfo.args.doPostDeleteLI(true);
-                            }
-                        }
-                        if (args.observer != null) {
-                            try {
-                                args.observer.packageInstalled(res.name, res.returnCode);
-                            } catch (RemoteException e) {
-                                Slog.i(TAG, "Observer no longer exists.");
-                            }
-                        }
-                    } else {
-                        Slog.e(TAG, "Bogus post-install token " + msg.arg1);
-                    }
-                } break;
-                case UPDATED_MEDIA_STATUS: {
-                    if (DEBUG_SD_INSTALL) Log.i(TAG, "Got message UPDATED_MEDIA_STATUS");
-                    boolean reportStatus = msg.arg1 == 1;
-                    boolean doGc = msg.arg2 == 1;
-                    if (DEBUG_SD_INSTALL) Log.i(TAG, "reportStatus=" + reportStatus + ", doGc = " + doGc);
-                    if (doGc) {
-                        // Force a gc to clear up stale containers.
-                        Runtime.getRuntime().gc();
-                    }
-                    if (msg.obj != null) {
-                        @SuppressWarnings("unchecked")
-                        Set<AsecInstallArgs> args = (Set<AsecInstallArgs>) msg.obj;
-                        if (DEBUG_SD_INSTALL) Log.i(TAG, "Unloading all containers");
-                        // Unload containers
-                        unloadAllContainers(args);
-                    }
-                    if (reportStatus) {
-                        try {
-                            if (DEBUG_SD_INSTALL) Log.i(TAG, "Invoking MountService call back");
-                            PackageHelper.getMountService().finishMediaUpdate();
-                        } catch (RemoteException e) {
-                            Log.e(TAG, "MountService not running?");
-                        }
-                    }
-                } break;
-                case WRITE_SETTINGS: {
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
-                    synchronized (mPackages) {
-                        removeMessages(WRITE_SETTINGS);
-                        removeMessages(WRITE_PACKAGE_RESTRICTIONS);
-                        mSettings.writeLPr();
-                        mDirtyUsers.clear();
-                    }
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-                } break;
-                case WRITE_PACKAGE_RESTRICTIONS: {
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
-                    synchronized (mPackages) {
-                        removeMessages(WRITE_PACKAGE_RESTRICTIONS);
-                        for (int userId : mDirtyUsers) {
-                            mSettings.writePackageRestrictionsLPr(userId);
-                        }
-                        mDirtyUsers.clear();
-                    }
-                    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
-                } break;
-                case CHECK_PENDING_VERIFICATION: {
-                    final int verificationId = msg.arg1;
-                    final PackageVerificationState state = mPendingVerification.get(verificationId);
-
-                    if ((state != null) && !state.timeoutExtended()) {
-                        final InstallArgs args = state.getInstallArgs();
-                        Slog.i(TAG, "Verification timed out for " + args.packageURI.toString());
-                        mPendingVerification.remove(verificationId);
-
-                        int ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
-
-                        if (getDefaultVerificationResponse() == PackageManager.VERIFICATION_ALLOW) {
-                            Slog.i(TAG, "Continuing with installation of "
-                                    + args.packageURI.toString());
-                            state.setVerifierResponse(Binder.getCallingUid(),
-                                    PackageManager.VERIFICATION_ALLOW_WITHOUT_SUFFICIENT);
-                            broadcastPackageVerified(verificationId, args.packageURI,
-                                    PackageManager.VERIFICATION_ALLOW,
-                                    state.getInstallArgs().getUser());
-                            try {
-                                ret = args.copyApk(mContainerService, true);
-                            } catch (RemoteException e) {
-                                Slog.e(TAG, "Could not contact the ContainerService");
-                            }
-                        } else {
-                            broadcastPackageVerified(verificationId, args.packageURI,
-                                    PackageManager.VERIFICATION_REJECT,
-                                    state.getInstallArgs().getUser());
-                        }
-
-                        processPendingInstall(args, ret);
-                        mHandler.sendEmptyMessage(MCS_UNBIND);
-                    }
-                    break;
-                }
-                case PACKAGE_VERIFIED: {
-                    final int verificationId = msg.arg1;
-
-                    final PackageVerificationState state = mPendingVerification.get(verificationId);
-                    if (state == null) {
-                        Slog.w(TAG, "Invalid verification token " + verificationId + " received");
-                        break;
-                    }
-
-                    final PackageVerificationResponse response = (PackageVerificationResponse) msg.obj;
-
-                    state.setVerifierResponse(response.callerUid, response.code);
-
-                    if (state.isVerificationComplete()) {
-                        mPendingVerification.remove(verificationId);
-
-                        final InstallArgs args = state.getInstallArgs();
-
-                        int ret;
-                        if (state.isInstallAllowed()) {
-                            ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-                            broadcastPackageVerified(verificationId, args.packageURI,
-                                    response.code, state.getInstallArgs().getUser());
-                            try {
-                                ret = args.copyApk(mContainerService, true);
-                            } catch (RemoteException e) {
-                                Slog.e(TAG, "Could not contact the ContainerService");
-                            }
-                        } else {
-                            ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
-                        }
-
-                        processPendingInstall(args, ret);
-
-                        mHandler.sendEmptyMessage(MCS_UNBIND);
-                    }
-
-                    break;
-                }
-            }
-        }
-    }
-
-    void scheduleWriteSettingsLocked() {
-        if (!mHandler.hasMessages(WRITE_SETTINGS)) {
-            mHandler.sendEmptyMessageDelayed(WRITE_SETTINGS, WRITE_SETTINGS_DELAY);
-        }
-    }
-
-    void scheduleWritePackageRestrictionsLocked(int userId) {
-        if (!sUserManager.exists(userId)) return;
-        mDirtyUsers.add(userId);
-        if (!mHandler.hasMessages(WRITE_PACKAGE_RESTRICTIONS)) {
-            mHandler.sendEmptyMessageDelayed(WRITE_PACKAGE_RESTRICTIONS, WRITE_SETTINGS_DELAY);
-        }
-    }
-
-    public static final IPackageManager main(Context context, Installer installer,
-            boolean factoryTest, boolean onlyCore) {
-        PackageManagerService m = new PackageManagerService(context, installer,
-                factoryTest, onlyCore);
-        ServiceManager.addService("package", m);
-        return m;
-    }
-
-    static String[] splitString(String str, char sep) {
-        int count = 1;
-        int i = 0;
-        while ((i=str.indexOf(sep, i)) >= 0) {
-            count++;
-            i++;
-        }
-
-        String[] res = new String[count];
-        i=0;
-        count = 0;
-        int lastI=0;
-        while ((i=str.indexOf(sep, i)) >= 0) {
-            res[count] = str.substring(lastI, i);
-            count++;
-            i++;
-            lastI = i;
-        }
-        res[count] = str.substring(lastI, str.length());
-        return res;
-    }
-
-    public PackageManagerService(Context context, Installer installer,
-            boolean factoryTest, boolean onlyCore) {
-        EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_START,
-                SystemClock.uptimeMillis());
-
-        if (mSdkVersion <= 0) {
-            Slog.w(TAG, "**** ro.build.version.sdk not set!");
-        }
-
-        mContext = context;
-        mFactoryTest = factoryTest;
-        mOnlyCore = onlyCore;
-        mNoDexOpt = "eng".equals(SystemProperties.get("ro.build.type"));
-        mMetrics = new DisplayMetrics();
-        mSettings = new Settings(context);
-        mSettings.addSharedUserLPw("android.uid.system", Process.SYSTEM_UID,
-                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
-        mSettings.addSharedUserLPw("android.uid.phone", RADIO_UID,
-                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
-        mSettings.addSharedUserLPw("android.uid.log", LOG_UID,
-                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
-        mSettings.addSharedUserLPw("android.uid.nfc", NFC_UID,
-                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
-        mSettings.addSharedUserLPw("android.uid.bluetooth", BLUETOOTH_UID,
-                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
-        mSettings.addSharedUserLPw("android.uid.shell", SHELL_UID,
-                ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PRIVILEGED);
-
-        String separateProcesses = SystemProperties.get("debug.separate_processes");
-        if (separateProcesses != null && separateProcesses.length() > 0) {
-            if ("*".equals(separateProcesses)) {
-                mDefParseFlags = PackageParser.PARSE_IGNORE_PROCESSES;
-                mSeparateProcesses = null;
-                Slog.w(TAG, "Running with debug.separate_processes: * (ALL)");
-            } else {
-                mDefParseFlags = 0;
-                mSeparateProcesses = separateProcesses.split(",");
-                Slog.w(TAG, "Running with debug.separate_processes: "
-                        + separateProcesses);
-            }
-        } else {
-            mDefParseFlags = 0;
-            mSeparateProcesses = null;
-        }
-
-        mInstaller = installer;
-
-        WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
-        Display d = wm.getDefaultDisplay();
-        d.getMetrics(mMetrics);
-
-        synchronized (mInstallLock) {
-        // writer
-        synchronized (mPackages) {
-            mHandlerThread.start();
-            mHandler = new PackageHandler(mHandlerThread.getLooper());
-            Watchdog.getInstance().addThread(mHandler, mHandlerThread.getName(),
-                    WATCHDOG_TIMEOUT);
-
-            File dataDir = Environment.getDataDirectory();
-            mAppDataDir = new File(dataDir, "data");
-            mAppInstallDir = new File(dataDir, "app");
-            mAppLibInstallDir = new File(dataDir, "app-lib");
-            mAsecInternalPath = new File(dataDir, "app-asec").getPath();
-            mUserAppDataDir = new File(dataDir, "user");
-            mDrmAppPrivateInstallDir = new File(dataDir, "app-private");
-
-            sUserManager = new UserManagerService(context, this,
-                    mInstallLock, mPackages);
-
-            readPermissions();
-
-            mFoundPolicyFile = SELinuxMMAC.readInstallPolicy();
-
-            mRestoredSettings = mSettings.readLPw(this, sUserManager.getUsers(false),
-                    mSdkVersion, mOnlyCore);
-
-            String customResolverActivity = Resources.getSystem().getString(
-                    R.string.config_customResolverActivity);
-            if (TextUtils.isEmpty(customResolverActivity)) {
-                customResolverActivity = null;
-            } else {
-                mCustomResolverComponentName = ComponentName.unflattenFromString(
-                        customResolverActivity);
-            }
-
-            long startTime = SystemClock.uptimeMillis();
-
-            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SYSTEM_SCAN_START,
-                    startTime);
-
-            // Set flag to monitor and not change apk file paths when
-            // scanning install directories.
-            int scanMode = SCAN_MONITOR | SCAN_NO_PATHS | SCAN_DEFER_DEX | SCAN_BOOTING;
-            if (mNoDexOpt) {
-                Slog.w(TAG, "Running ENG build: no pre-dexopt!");
-                scanMode |= SCAN_NO_DEX;
-            }
-
-            final HashSet<String> alreadyDexOpted = new HashSet<String>();
-
-            /**
-             * Add everything in the in the boot class path to the
-             * list of process files because dexopt will have been run
-             * if necessary during zygote startup.
-             */
-            String bootClassPath = System.getProperty("java.boot.class.path");
-            if (bootClassPath != null) {
-                String[] paths = splitString(bootClassPath, ':');
-                for (int i=0; i<paths.length; i++) {
-                    alreadyDexOpted.add(paths[i]);
-                }
-            } else {
-                Slog.w(TAG, "No BOOTCLASSPATH found!");
-            }
-
-            boolean didDexOpt = false;
-
-            /**
-             * Ensure all external libraries have had dexopt run on them.
-             */
-            if (mSharedLibraries.size() > 0) {
-                Iterator<SharedLibraryEntry> libs = mSharedLibraries.values().iterator();
-                while (libs.hasNext()) {
-                    String lib = libs.next().path;
-                    if (lib == null) {
-                        continue;
-                    }
-                    try {
-                        if (dalvik.system.DexFile.isDexOptNeeded(lib)) {
-                            alreadyDexOpted.add(lib);
-                            mInstaller.dexopt(lib, Process.SYSTEM_UID, true);
-                            didDexOpt = true;
-                        }
-                    } catch (FileNotFoundException e) {
-                        Slog.w(TAG, "Library not found: " + lib);
-                    } catch (IOException e) {
-                        Slog.w(TAG, "Cannot dexopt " + lib + "; is it an APK or JAR? "
-                                + e.getMessage());
-                    }
-                }
-            }
-
-            File frameworkDir = new File(Environment.getRootDirectory(), "framework");
-
-            // Gross hack for now: we know this file doesn't contain any
-            // code, so don't dexopt it to avoid the resulting log spew.
-            alreadyDexOpted.add(frameworkDir.getPath() + "/framework-res.apk");
-
-            // Gross hack for now: we know this file is only part of
-            // the boot class path for art, so don't dexopt it to
-            // avoid the resulting log spew.
-            alreadyDexOpted.add(frameworkDir.getPath() + "/core-libart.jar");
-
-            /**
-             * And there are a number of commands implemented in Java, which
-             * we currently need to do the dexopt on so that they can be
-             * run from a non-root shell.
-             */
-            String[] frameworkFiles = frameworkDir.list();
-            if (frameworkFiles != null) {
-                for (int i=0; i<frameworkFiles.length; i++) {
-                    File libPath = new File(frameworkDir, frameworkFiles[i]);
-                    String path = libPath.getPath();
-                    // Skip the file if we alrady did it.
-                    if (alreadyDexOpted.contains(path)) {
-                        continue;
-                    }
-                    // Skip the file if it is not a type we want to dexopt.
-                    if (!path.endsWith(".apk") && !path.endsWith(".jar")) {
-                        continue;
-                    }
-                    try {
-                        if (dalvik.system.DexFile.isDexOptNeeded(path)) {
-                            mInstaller.dexopt(path, Process.SYSTEM_UID, true);
-                            didDexOpt = true;
-                        }
-                    } catch (FileNotFoundException e) {
-                        Slog.w(TAG, "Jar not found: " + path);
-                    } catch (IOException e) {
-                        Slog.w(TAG, "Exception reading jar: " + path, e);
-                    }
-                }
-            }
-
-            if (didDexOpt) {
-                File dalvikCacheDir = new File(dataDir, "dalvik-cache");
-
-                // If we had to do a dexopt of one of the previous
-                // things, then something on the system has changed.
-                // Consider this significant, and wipe away all other
-                // existing dexopt files to ensure we don't leave any
-                // dangling around.
-                String[] files = dalvikCacheDir.list();
-                if (files != null) {
-                    for (int i=0; i<files.length; i++) {
-                        String fn = files[i];
-                        if (fn.startsWith("data@app@")
-                                || fn.startsWith("data@app-private@")) {
-                            Slog.i(TAG, "Pruning dalvik file: " + fn);
-                            (new File(dalvikCacheDir, fn)).delete();
-                        }
-                    }
-                }
-            }
-
-            // Find base frameworks (resource packages without code).
-            mFrameworkInstallObserver = new AppDirObserver(
-                frameworkDir.getPath(), OBSERVER_EVENTS, true, false);
-            mFrameworkInstallObserver.startWatching();
-            scanDirLI(frameworkDir, PackageParser.PARSE_IS_SYSTEM
-                    | PackageParser.PARSE_IS_SYSTEM_DIR
-                    | PackageParser.PARSE_IS_PRIVILEGED,
-                    scanMode | SCAN_NO_DEX, 0);
-
-            // Collected privileged system packages.
-            File privilegedAppDir = new File(Environment.getRootDirectory(), "priv-app");
-            mPrivilegedInstallObserver = new AppDirObserver(
-                    privilegedAppDir.getPath(), OBSERVER_EVENTS, true, true);
-            mPrivilegedInstallObserver.startWatching();
-                scanDirLI(privilegedAppDir, PackageParser.PARSE_IS_SYSTEM
-                        | PackageParser.PARSE_IS_SYSTEM_DIR
-                        | PackageParser.PARSE_IS_PRIVILEGED, scanMode, 0);
-
-            // Collect ordinary system packages.
-            File systemAppDir = new File(Environment.getRootDirectory(), "app");
-            mSystemInstallObserver = new AppDirObserver(
-                systemAppDir.getPath(), OBSERVER_EVENTS, true, false);
-            mSystemInstallObserver.startWatching();
-            scanDirLI(systemAppDir, PackageParser.PARSE_IS_SYSTEM
-                    | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0);
-
-            // Collect all vendor packages.
-            File vendorAppDir = new File("/vendor/app");
-            mVendorInstallObserver = new AppDirObserver(
-                vendorAppDir.getPath(), OBSERVER_EVENTS, true, false);
-            mVendorInstallObserver.startWatching();
-            scanDirLI(vendorAppDir, PackageParser.PARSE_IS_SYSTEM
-                    | PackageParser.PARSE_IS_SYSTEM_DIR, scanMode, 0);
-
-            if (DEBUG_UPGRADE) Log.v(TAG, "Running installd update commands");
-            mInstaller.moveFiles();
-
-            // Prune any system packages that no longer exist.
-            final List<String> possiblyDeletedUpdatedSystemApps = new ArrayList<String>();
-            if (!mOnlyCore) {
-                Iterator<PackageSetting> psit = mSettings.mPackages.values().iterator();
-                while (psit.hasNext()) {
-                    PackageSetting ps = psit.next();
-
-                    /*
-                     * If this is not a system app, it can't be a
-                     * disable system app.
-                     */
-                    if ((ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
-                        continue;
-                    }
-
-                    /*
-                     * If the package is scanned, it's not erased.
-                     */
-                    final PackageParser.Package scannedPkg = mPackages.get(ps.name);
-                    if (scannedPkg != null) {
-                        /*
-                         * If the system app is both scanned and in the
-                         * disabled packages list, then it must have been
-                         * added via OTA. Remove it from the currently
-                         * scanned package so the previously user-installed
-                         * application can be scanned.
-                         */
-                        if (mSettings.isDisabledSystemPackageLPr(ps.name)) {
-                            Slog.i(TAG, "Expecting better updatd system app for " + ps.name
-                                    + "; removing system app");
-                            removePackageLI(ps, true);
-                        }
-
-                        continue;
-                    }
-
-                    if (!mSettings.isDisabledSystemPackageLPr(ps.name)) {
-                        psit.remove();
-                        String msg = "System package " + ps.name
-                                + " no longer exists; wiping its data";
-                        reportSettingsProblem(Log.WARN, msg);
-                        removeDataDirsLI(ps.name);
-                    } else {
-                        final PackageSetting disabledPs = mSettings.getDisabledSystemPkgLPr(ps.name);
-                        if (disabledPs.codePath == null || !disabledPs.codePath.exists()) {
-                            possiblyDeletedUpdatedSystemApps.add(ps.name);
-                        }
-                    }
-                }
-            }
-
-            //look for any incomplete package installations
-            ArrayList<PackageSetting> deletePkgsList = mSettings.getListOfIncompleteInstallPackagesLPr();
-            //clean up list
-            for(int i = 0; i < deletePkgsList.size(); i++) {
-                //clean up here
-                cleanupInstallFailedPackage(deletePkgsList.get(i));
-            }
-            //delete tmp files
-            deleteTempPackageFiles();
-
-            // Remove any shared userIDs that have no associated packages
-            mSettings.pruneSharedUsersLPw();
-
-            if (!mOnlyCore) {
-                EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_DATA_SCAN_START,
-                        SystemClock.uptimeMillis());
-                mAppInstallObserver = new AppDirObserver(
-                    mAppInstallDir.getPath(), OBSERVER_EVENTS, false, false);
-                mAppInstallObserver.startWatching();
-                scanDirLI(mAppInstallDir, 0, scanMode, 0);
-    
-                mDrmAppInstallObserver = new AppDirObserver(
-                    mDrmAppPrivateInstallDir.getPath(), OBSERVER_EVENTS, false, false);
-                mDrmAppInstallObserver.startWatching();
-                scanDirLI(mDrmAppPrivateInstallDir, PackageParser.PARSE_FORWARD_LOCK,
-                        scanMode, 0);
-
-                /**
-                 * Remove disable package settings for any updated system
-                 * apps that were removed via an OTA. If they're not a
-                 * previously-updated app, remove them completely.
-                 * Otherwise, just revoke their system-level permissions.
-                 */
-                for (String deletedAppName : possiblyDeletedUpdatedSystemApps) {
-                    PackageParser.Package deletedPkg = mPackages.get(deletedAppName);
-                    mSettings.removeDisabledSystemPackageLPw(deletedAppName);
-
-                    String msg;
-                    if (deletedPkg == null) {
-                        msg = "Updated system package " + deletedAppName
-                                + " no longer exists; wiping its data";
-                        removeDataDirsLI(deletedAppName);
-                    } else {
-                        msg = "Updated system app + " + deletedAppName
-                                + " no longer present; removing system privileges for "
-                                + deletedAppName;
-
-                        deletedPkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_SYSTEM;
-
-                        PackageSetting deletedPs = mSettings.mPackages.get(deletedAppName);
-                        deletedPs.pkgFlags &= ~ApplicationInfo.FLAG_SYSTEM;
-                    }
-                    reportSettingsProblem(Log.WARN, msg);
-                }
-            } else {
-                mAppInstallObserver = null;
-                mDrmAppInstallObserver = null;
-            }
-
-            // Now that we know all of the shared libraries, update all clients to have
-            // the correct library paths.
-            updateAllSharedLibrariesLPw();
-
-            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SCAN_END,
-                    SystemClock.uptimeMillis());
-            Slog.i(TAG, "Time to scan packages: "
-                    + ((SystemClock.uptimeMillis()-startTime)/1000f)
-                    + " seconds");
-
-            // If the platform SDK has changed since the last time we booted,
-            // we need to re-grant app permission to catch any new ones that
-            // appear.  This is really a hack, and means that apps can in some
-            // cases get permissions that the user didn't initially explicitly
-            // allow...  it would be nice to have some better way to handle
-            // this situation.
-            final boolean regrantPermissions = mSettings.mInternalSdkPlatform
-                    != mSdkVersion;
-            if (regrantPermissions) Slog.i(TAG, "Platform changed from "
-                    + mSettings.mInternalSdkPlatform + " to " + mSdkVersion
-                    + "; regranting permissions for internal storage");
-            mSettings.mInternalSdkPlatform = mSdkVersion;
-            
-            updatePermissionsLPw(null, null, UPDATE_PERMISSIONS_ALL
-                    | (regrantPermissions
-                            ? (UPDATE_PERMISSIONS_REPLACE_PKG|UPDATE_PERMISSIONS_REPLACE_ALL)
-                            : 0));
-
-            // If this is the first boot, and it is a normal boot, then
-            // we need to initialize the default preferred apps.
-            if (!mRestoredSettings && !onlyCore) {
-                mSettings.readDefaultPreferredAppsLPw(this, 0);
-            }
-
-            // can downgrade to reader
-            mSettings.writeLPr();
-
-            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_READY,
-                    SystemClock.uptimeMillis());
-
-            // Now after opening every single application zip, make sure they
-            // are all flushed.  Not really needed, but keeps things nice and
-            // tidy.
-            Runtime.getRuntime().gc();
-
-            mRequiredVerifierPackage = getRequiredVerifierLPr();
-        } // synchronized (mPackages)
-        } // synchronized (mInstallLock)
-    }
-
-    public boolean isFirstBoot() {
-        return !mRestoredSettings;
-    }
-
-    public boolean isOnlyCoreApps() {
-        return mOnlyCore;
-    }
-
-    private String getRequiredVerifierLPr() {
-        final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
-        final List<ResolveInfo> receivers = queryIntentReceivers(verification, PACKAGE_MIME_TYPE,
-                PackageManager.GET_DISABLED_COMPONENTS, 0 /* TODO: Which userId? */);
-
-        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;
-
-            final PackageSetting ps = mSettings.mPackages.get(packageName);
-            if (ps == null) {
-                continue;
-            }
-
-            final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
-            if (!gp.grantedPermissions
-                    .contains(android.Manifest.permission.PACKAGE_VERIFICATION_AGENT)) {
-                continue;
-            }
-
-            if (requiredVerifier != null) {
-                throw new RuntimeException("There can be only one required verifier");
-            }
-
-            requiredVerifier = packageName;
-        }
-
-        return requiredVerifier;
-    }
-
-    @Override
-    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
-            throws RemoteException {
-        try {
-            return super.onTransact(code, data, reply, flags);
-        } catch (RuntimeException e) {
-            if (!(e instanceof SecurityException) && !(e instanceof IllegalArgumentException)) {
-                Slog.wtf(TAG, "Package Manager Crash", e);
-            }
-            throw e;
-        }
-    }
-
-    void cleanupInstallFailedPackage(PackageSetting ps) {
-        Slog.i(TAG, "Cleaning up incompletely installed app: " + ps.name);
-        removeDataDirsLI(ps.name);
-        if (ps.codePath != null) {
-            if (!ps.codePath.delete()) {
-                Slog.w(TAG, "Unable to remove old code file: " + ps.codePath);
-            }
-        }
-        if (ps.resourcePath != null) {
-            if (!ps.resourcePath.delete() && !ps.resourcePath.equals(ps.codePath)) {
-                Slog.w(TAG, "Unable to remove old code file: " + ps.resourcePath);
-            }
-        }
-        mSettings.removePackageLPw(ps.name);
-    }
-
-    void readPermissions() {
-        // Read permissions from .../etc/permission directory.
-        File libraryDir = new File(Environment.getRootDirectory(), "etc/permissions");
-        if (!libraryDir.exists() || !libraryDir.isDirectory()) {
-            Slog.w(TAG, "No directory " + libraryDir + ", skipping");
-            return;
-        }
-        if (!libraryDir.canRead()) {
-            Slog.w(TAG, "Directory " + libraryDir + " cannot be read");
-            return;
-        }
-
-        // Iterate over the files in the directory and scan .xml files
-        for (File f : libraryDir.listFiles()) {
-            // We'll read platform.xml last
-            if (f.getPath().endsWith("etc/permissions/platform.xml")) {
-                continue;
-            }
-
-            if (!f.getPath().endsWith(".xml")) {
-                Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring");
-                continue;
-            }
-            if (!f.canRead()) {
-                Slog.w(TAG, "Permissions library file " + f + " cannot be read");
-                continue;
-            }
-
-            readPermissionsFromXml(f);
-        }
-
-        // Read permissions from .../etc/permissions/platform.xml last so it will take precedence
-        final File permFile = new File(Environment.getRootDirectory(),
-                "etc/permissions/platform.xml");
-        readPermissionsFromXml(permFile);
-    }
-
-    private void readPermissionsFromXml(File permFile) {
-        FileReader permReader = null;
-        try {
-            permReader = new FileReader(permFile);
-        } catch (FileNotFoundException e) {
-            Slog.w(TAG, "Couldn't find or open permissions file " + permFile);
-            return;
-        }
-
-        try {
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(permReader);
-
-            XmlUtils.beginDocument(parser, "permissions");
-
-            while (true) {
-                XmlUtils.nextElement(parser);
-                if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
-                    break;
-                }
-
-                String name = parser.getName();
-                if ("group".equals(name)) {
-                    String gidStr = parser.getAttributeValue(null, "gid");
-                    if (gidStr != null) {
-                        int gid = Process.getGidForName(gidStr);
-                        mGlobalGids = appendInt(mGlobalGids, gid);
-                    } else {
-                        Slog.w(TAG, "<group> without gid at "
-                                + parser.getPositionDescription());
-                    }
-
-                    XmlUtils.skipCurrentTag(parser);
-                    continue;
-                } else if ("permission".equals(name)) {
-                    String perm = parser.getAttributeValue(null, "name");
-                    if (perm == null) {
-                        Slog.w(TAG, "<permission> without name at "
-                                + parser.getPositionDescription());
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    perm = perm.intern();
-                    readPermission(parser, perm);
-
-                } else if ("assign-permission".equals(name)) {
-                    String perm = parser.getAttributeValue(null, "name");
-                    if (perm == null) {
-                        Slog.w(TAG, "<assign-permission> without name at "
-                                + parser.getPositionDescription());
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    String uidStr = parser.getAttributeValue(null, "uid");
-                    if (uidStr == null) {
-                        Slog.w(TAG, "<assign-permission> without uid at "
-                                + parser.getPositionDescription());
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    int uid = Process.getUidForName(uidStr);
-                    if (uid < 0) {
-                        Slog.w(TAG, "<assign-permission> with unknown uid \""
-                                + uidStr + "\" at "
-                                + parser.getPositionDescription());
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    perm = perm.intern();
-                    HashSet<String> perms = mSystemPermissions.get(uid);
-                    if (perms == null) {
-                        perms = new HashSet<String>();
-                        mSystemPermissions.put(uid, perms);
-                    }
-                    perms.add(perm);
-                    XmlUtils.skipCurrentTag(parser);
-
-                } else if ("library".equals(name)) {
-                    String lname = parser.getAttributeValue(null, "name");
-                    String lfile = parser.getAttributeValue(null, "file");
-                    if (lname == null) {
-                        Slog.w(TAG, "<library> without name at "
-                                + parser.getPositionDescription());
-                    } else if (lfile == null) {
-                        Slog.w(TAG, "<library> without file at "
-                                + parser.getPositionDescription());
-                    } else {
-                        //Log.i(TAG, "Got library " + lname + " in " + lfile);
-                        mSharedLibraries.put(lname, new SharedLibraryEntry(lfile, null));
-                    }
-                    XmlUtils.skipCurrentTag(parser);
-                    continue;
-
-                } else if ("feature".equals(name)) {
-                    String fname = parser.getAttributeValue(null, "name");
-                    if (fname == null) {
-                        Slog.w(TAG, "<feature> without name at "
-                                + parser.getPositionDescription());
-                    } else {
-                        //Log.i(TAG, "Got feature " + fname);
-                        FeatureInfo fi = new FeatureInfo();
-                        fi.name = fname;
-                        mAvailableFeatures.put(fname, fi);
-                    }
-                    XmlUtils.skipCurrentTag(parser);
-                    continue;
-
-                } else {
-                    XmlUtils.skipCurrentTag(parser);
-                    continue;
-                }
-
-            }
-            permReader.close();
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "Got execption parsing permissions.", e);
-        } catch (IOException e) {
-            Slog.w(TAG, "Got execption parsing permissions.", e);
-        }
-    }
-
-    void readPermission(XmlPullParser parser, String name)
-            throws IOException, XmlPullParserException {
-
-        name = name.intern();
-
-        BasePermission bp = mSettings.mPermissions.get(name);
-        if (bp == null) {
-            bp = new BasePermission(name, null, BasePermission.TYPE_BUILTIN);
-            mSettings.mPermissions.put(name, bp);
-        }
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-               && (type != XmlPullParser.END_TAG
-                       || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG
-                    || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if ("group".equals(tagName)) {
-                String gidStr = parser.getAttributeValue(null, "gid");
-                if (gidStr != null) {
-                    int gid = Process.getGidForName(gidStr);
-                    bp.gids = appendInt(bp.gids, gid);
-                } else {
-                    Slog.w(TAG, "<group> without gid at "
-                            + parser.getPositionDescription());
-                }
-            }
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    static int[] appendInts(int[] cur, int[] add) {
-        if (add == null) return cur;
-        if (cur == null) return add;
-        final int N = add.length;
-        for (int i=0; i<N; i++) {
-            cur = appendInt(cur, add[i]);
-        }
-        return cur;
-    }
-
-    static int[] removeInts(int[] cur, int[] rem) {
-        if (rem == null) return cur;
-        if (cur == null) return cur;
-        final int N = rem.length;
-        for (int i=0; i<N; i++) {
-            cur = removeInt(cur, rem[i]);
-        }
-        return cur;
-    }
-
-    PackageInfo generatePackageInfo(PackageParser.Package p, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        PackageInfo pi;
-        final PackageSetting ps = (PackageSetting) p.mExtras;
-        if (ps == null) {
-            return null;
-        }
-        final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
-        final PackageUserState state = ps.readUserState(userId);
-        return PackageParser.generatePackageInfo(p, gp.gids, flags,
-                ps.firstInstallTime, ps.lastUpdateTime, gp.grantedPermissions,
-                state, userId);
-    }
-
-    public boolean isPackageAvailable(String packageName, int userId) {
-        if (!sUserManager.exists(userId)) return false;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "is package available");
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if (p != null) {
-                final PackageSetting ps = (PackageSetting) p.mExtras;
-                if (ps != null) {
-                    final PackageUserState state = ps.readUserState(userId);
-                    if (state != null) {
-                        return PackageParser.isAvailable(state);
-                    }
-                }
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public PackageInfo getPackageInfo(String packageName, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get package info");
-        // reader
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if (DEBUG_PACKAGE_INFO)
-                Log.v(TAG, "getPackageInfo " + packageName + ": " + p);
-            if (p != null) {
-                return generatePackageInfo(p, flags, userId);
-            }
-            if((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
-                return generatePackageInfoFromSettingsLPw(packageName, flags, userId);
-            }
-        }
-        return null;
-    }
-
-    public String[] currentToCanonicalPackageNames(String[] names) {
-        String[] out = new String[names.length];
-        // reader
-        synchronized (mPackages) {
-            for (int i=names.length-1; i>=0; i--) {
-                PackageSetting ps = mSettings.mPackages.get(names[i]);
-                out[i] = ps != null && ps.realName != null ? ps.realName : names[i];
-            }
-        }
-        return out;
-    }
-    
-    public String[] canonicalToCurrentPackageNames(String[] names) {
-        String[] out = new String[names.length];
-        // reader
-        synchronized (mPackages) {
-            for (int i=names.length-1; i>=0; i--) {
-                String cur = mSettings.mRenamedPackages.get(names[i]);
-                out[i] = cur != null ? cur : names[i];
-            }
-        }
-        return out;
-    }
-
-    @Override
-    public int getPackageUid(String packageName, int userId) {
-        if (!sUserManager.exists(userId)) return -1;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get package uid");
-        // reader
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if(p != null) {
-                return UserHandle.getUid(userId, p.applicationInfo.uid);
-            }
-            PackageSetting ps = mSettings.mPackages.get(packageName);
-            if((ps == null) || (ps.pkg == null) || (ps.pkg.applicationInfo == null)) {
-                return -1;
-            }
-            p = ps.pkg;
-            return p != null ? UserHandle.getUid(userId, p.applicationInfo.uid) : -1;
-        }
-    }
-
-    @Override
-    public int[] getPackageGids(String packageName) {
-        // reader
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if (DEBUG_PACKAGE_INFO)
-                Log.v(TAG, "getPackageGids" + packageName + ": " + p);
-            if (p != null) {
-                final PackageSetting ps = (PackageSetting)p.mExtras;
-                return ps.getGids();
-            }
-        }
-        // stupid thing to indicate an error.
-        return new int[0];
-    }
-
-    static final PermissionInfo generatePermissionInfo(
-            BasePermission bp, int flags) {
-        if (bp.perm != null) {
-            return PackageParser.generatePermissionInfo(bp.perm, flags);
-        }
-        PermissionInfo pi = new PermissionInfo();
-        pi.name = bp.name;
-        pi.packageName = bp.sourcePackage;
-        pi.nonLocalizedLabel = bp.name;
-        pi.protectionLevel = bp.protectionLevel;
-        return pi;
-    }
-    
-    public PermissionInfo getPermissionInfo(String name, int flags) {
-        // reader
-        synchronized (mPackages) {
-            final BasePermission p = mSettings.mPermissions.get(name);
-            if (p != null) {
-                return generatePermissionInfo(p, flags);
-            }
-            return null;
-        }
-    }
-
-    public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) {
-        // reader
-        synchronized (mPackages) {
-            ArrayList<PermissionInfo> out = new ArrayList<PermissionInfo>(10);
-            for (BasePermission p : mSettings.mPermissions.values()) {
-                if (group == null) {
-                    if (p.perm == null || p.perm.info.group == null) {
-                        out.add(generatePermissionInfo(p, flags));
-                    }
-                } else {
-                    if (p.perm != null && group.equals(p.perm.info.group)) {
-                        out.add(PackageParser.generatePermissionInfo(p.perm, flags));
-                    }
-                }
-            }
-
-            if (out.size() > 0) {
-                return out;
-            }
-            return mPermissionGroups.containsKey(group) ? out : null;
-        }
-    }
-
-    public PermissionGroupInfo getPermissionGroupInfo(String name, int flags) {
-        // reader
-        synchronized (mPackages) {
-            return PackageParser.generatePermissionGroupInfo(
-                    mPermissionGroups.get(name), flags);
-        }
-    }
-
-    public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
-        // reader
-        synchronized (mPackages) {
-            final int N = mPermissionGroups.size();
-            ArrayList<PermissionGroupInfo> out
-                    = new ArrayList<PermissionGroupInfo>(N);
-            for (PackageParser.PermissionGroup pg : mPermissionGroups.values()) {
-                out.add(PackageParser.generatePermissionGroupInfo(pg, flags));
-            }
-            return out;
-        }
-    }
-
-    private ApplicationInfo generateApplicationInfoFromSettingsLPw(String packageName, int flags,
-            int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        PackageSetting ps = mSettings.mPackages.get(packageName);
-        if (ps != null) {
-            if (ps.pkg == null) {
-                PackageInfo pInfo = generatePackageInfoFromSettingsLPw(packageName,
-                        flags, userId);
-                if (pInfo != null) {
-                    return pInfo.applicationInfo;
-                }
-                return null;
-            }
-            return PackageParser.generateApplicationInfo(ps.pkg, flags,
-                    ps.readUserState(userId), userId);
-        }
-        return null;
-    }
-
-    private PackageInfo generatePackageInfoFromSettingsLPw(String packageName, int flags,
-            int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        PackageSetting ps = mSettings.mPackages.get(packageName);
-        if (ps != null) {
-            PackageParser.Package pkg = ps.pkg;
-            if (pkg == null) {
-                if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) == 0) {
-                    return null;
-                }
-                pkg = new PackageParser.Package(packageName);
-                pkg.applicationInfo.packageName = packageName;
-                pkg.applicationInfo.flags = ps.pkgFlags | ApplicationInfo.FLAG_IS_DATA_ONLY;
-                pkg.applicationInfo.publicSourceDir = ps.resourcePathString;
-                pkg.applicationInfo.sourceDir = ps.codePathString;
-                pkg.applicationInfo.dataDir =
-                        getDataPathForPackage(packageName, 0).getPath();
-                pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString;
-            }
-            return generatePackageInfo(pkg, flags, userId);
-        }
-        return null;
-    }
-
-    @Override
-    public ApplicationInfo getApplicationInfo(String packageName, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get application info");
-        // writer
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if (DEBUG_PACKAGE_INFO) Log.v(
-                    TAG, "getApplicationInfo " + packageName
-                    + ": " + p);
-            if (p != null) {
-                PackageSetting ps = mSettings.mPackages.get(packageName);
-                if (ps == null) return null;
-                // Note: isEnabledLP() does not apply here - always return info
-                return PackageParser.generateApplicationInfo(
-                        p, flags, ps.readUserState(userId), userId);
-            }
-            if ("android".equals(packageName)||"system".equals(packageName)) {
-                return mAndroidApplication;
-            }
-            if ((flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0) {
-                return generateApplicationInfoFromSettingsLPw(packageName, flags, userId);
-            }
-        }
-        return null;
-    }
-
-
-    public void freeStorageAndNotify(final long freeStorageSize, final IPackageDataObserver observer) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.CLEAR_APP_CACHE, null);
-        // Queue up an async operation since clearing cache may take a little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                mHandler.removeCallbacks(this);
-                int retCode = -1;
-                synchronized (mInstallLock) {
-                    retCode = mInstaller.freeCache(freeStorageSize);
-                    if (retCode < 0) {
-                        Slog.w(TAG, "Couldn't clear application caches");
-                    }
-                }
-                if (observer != null) {
-                    try {
-                        observer.onRemoveCompleted(null, (retCode >= 0));
-                    } catch (RemoteException e) {
-                        Slog.w(TAG, "RemoveException when invoking call back");
-                    }
-                }
-            }
-        });
-    }
-
-    public void freeStorage(final long freeStorageSize, final IntentSender pi) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.CLEAR_APP_CACHE, null);
-        // Queue up an async operation since clearing cache may take a little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                mHandler.removeCallbacks(this);
-                int retCode = -1;
-                synchronized (mInstallLock) {
-                    retCode = mInstaller.freeCache(freeStorageSize);
-                    if (retCode < 0) {
-                        Slog.w(TAG, "Couldn't clear application caches");
-                    }
-                }
-                if(pi != null) {
-                    try {
-                        // Callback via pending intent
-                        int code = (retCode >= 0) ? 1 : 0;
-                        pi.sendIntent(null, code, null,
-                                null, null);
-                    } catch (SendIntentException e1) {
-                        Slog.i(TAG, "Failed to send pending intent");
-                    }
-                }
-            }
-        });
-    }
-
-    @Override
-    public ActivityInfo getActivityInfo(ComponentName component, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get activity info");
-        synchronized (mPackages) {
-            PackageParser.Activity a = mActivities.mActivities.get(component);
-
-            if (DEBUG_PACKAGE_INFO) Log.v(TAG, "getActivityInfo " + component + ": " + a);
-            if (a != null && mSettings.isEnabledLPr(a.info, flags, userId)) {
-                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
-                if (ps == null) return null;
-                return PackageParser.generateActivityInfo(a, flags, ps.readUserState(userId),
-                        userId);
-            }
-            if (mResolveComponentName.equals(component)) {
-                return mResolveActivity;
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public ActivityInfo getReceiverInfo(ComponentName component, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get receiver info");
-        synchronized (mPackages) {
-            PackageParser.Activity a = mReceivers.mActivities.get(component);
-            if (DEBUG_PACKAGE_INFO) Log.v(
-                TAG, "getReceiverInfo " + component + ": " + a);
-            if (a != null && mSettings.isEnabledLPr(a.info, flags, userId)) {
-                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
-                if (ps == null) return null;
-                return PackageParser.generateActivityInfo(a, flags, ps.readUserState(userId),
-                        userId);
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public ServiceInfo getServiceInfo(ComponentName component, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get service info");
-        synchronized (mPackages) {
-            PackageParser.Service s = mServices.mServices.get(component);
-            if (DEBUG_PACKAGE_INFO) Log.v(
-                TAG, "getServiceInfo " + component + ": " + s);
-            if (s != null && mSettings.isEnabledLPr(s.info, flags, userId)) {
-                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
-                if (ps == null) return null;
-                return PackageParser.generateServiceInfo(s, flags, ps.readUserState(userId),
-                        userId);
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public ProviderInfo getProviderInfo(ComponentName component, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "get provider info");
-        synchronized (mPackages) {
-            PackageParser.Provider p = mProviders.mProviders.get(component);
-            if (DEBUG_PACKAGE_INFO) Log.v(
-                TAG, "getProviderInfo " + component + ": " + p);
-            if (p != null && mSettings.isEnabledLPr(p.info, flags, userId)) {
-                PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
-                if (ps == null) return null;
-                return PackageParser.generateProviderInfo(p, flags, ps.readUserState(userId),
-                        userId);
-            }
-        }
-        return null;
-    }
-
-    public String[] getSystemSharedLibraryNames() {
-        Set<String> libSet;
-        synchronized (mPackages) {
-            libSet = mSharedLibraries.keySet();
-            int size = libSet.size();
-            if (size > 0) {
-                String[] libs = new String[size];
-                libSet.toArray(libs);
-                return libs;
-            }
-        }
-        return null;
-    }
-
-    public FeatureInfo[] getSystemAvailableFeatures() {
-        Collection<FeatureInfo> featSet;
-        synchronized (mPackages) {
-            featSet = mAvailableFeatures.values();
-            int size = featSet.size();
-            if (size > 0) {
-                FeatureInfo[] features = new FeatureInfo[size+1];
-                featSet.toArray(features);
-                FeatureInfo fi = new FeatureInfo();
-                fi.reqGlEsVersion = SystemProperties.getInt("ro.opengles.version",
-                        FeatureInfo.GL_ES_VERSION_UNDEFINED);
-                features[size] = fi;
-                return features;
-            }
-        }
-        return null;
-    }
-
-    public boolean hasSystemFeature(String name) {
-        synchronized (mPackages) {
-            return mAvailableFeatures.containsKey(name);
-        }
-    }
-
-    private void checkValidCaller(int uid, int userId) {
-        if (UserHandle.getUserId(uid) == userId || uid == Process.SYSTEM_UID || uid == 0)
-            return;
-
-        throw new SecurityException("Caller uid=" + uid
-                + " is not privileged to communicate with user=" + userId);
-    }
-
-    public int checkPermission(String permName, String pkgName) {
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(pkgName);
-            if (p != null && p.mExtras != null) {
-                PackageSetting ps = (PackageSetting)p.mExtras;
-                if (ps.sharedUser != null) {
-                    if (ps.sharedUser.grantedPermissions.contains(permName)) {
-                        return PackageManager.PERMISSION_GRANTED;
-                    }
-                } else if (ps.grantedPermissions.contains(permName)) {
-                    return PackageManager.PERMISSION_GRANTED;
-                }
-            }
-        }
-        return PackageManager.PERMISSION_DENIED;
-    }
-
-    public int checkUidPermission(String permName, int uid) {
-        synchronized (mPackages) {
-            Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
-            if (obj != null) {
-                GrantedPermissions gp = (GrantedPermissions)obj;
-                if (gp.grantedPermissions.contains(permName)) {
-                    return PackageManager.PERMISSION_GRANTED;
-                }
-            } else {
-                HashSet<String> perms = mSystemPermissions.get(uid);
-                if (perms != null && perms.contains(permName)) {
-                    return PackageManager.PERMISSION_GRANTED;
-                }
-            }
-        }
-        return PackageManager.PERMISSION_DENIED;
-    }
-
-    /**
-     * Checks if the request is from the system or an app that has INTERACT_ACROSS_USERS
-     * or INTERACT_ACROSS_USERS_FULL permissions, if the userid is not for the caller.
-     * @param message the message to log on security exception
-     * @return
-     */
-    private void enforceCrossUserPermission(int callingUid, int userId,
-            boolean requireFullPermission, String message) {
-        if (userId < 0) {
-            throw new IllegalArgumentException("Invalid userId " + userId);
-        }
-        if (userId == UserHandle.getUserId(callingUid)) return;
-        if (callingUid != Process.SYSTEM_UID && callingUid != 0) {
-            if (requireFullPermission) {
-                mContext.enforceCallingOrSelfPermission(
-                        android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
-            } else {
-                try {
-                    mContext.enforceCallingOrSelfPermission(
-                            android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, message);
-                } catch (SecurityException se) {
-                    mContext.enforceCallingOrSelfPermission(
-                            android.Manifest.permission.INTERACT_ACROSS_USERS, message);
-                }
-            }
-        }
-    }
-
-    private BasePermission findPermissionTreeLP(String permName) {
-        for(BasePermission bp : mSettings.mPermissionTrees.values()) {
-            if (permName.startsWith(bp.name) &&
-                    permName.length() > bp.name.length() &&
-                    permName.charAt(bp.name.length()) == '.') {
-                return bp;
-            }
-        }
-        return null;
-    }
-
-    private BasePermission checkPermissionTreeLP(String permName) {
-        if (permName != null) {
-            BasePermission bp = findPermissionTreeLP(permName);
-            if (bp != null) {
-                if (bp.uid == UserHandle.getAppId(Binder.getCallingUid())) {
-                    return bp;
-                }
-                throw new SecurityException("Calling uid "
-                        + Binder.getCallingUid()
-                        + " is not allowed to add to permission tree "
-                        + bp.name + " owned by uid " + bp.uid);
-            }
-        }
-        throw new SecurityException("No permission tree found for " + permName);
-    }
-
-    static boolean compareStrings(CharSequence s1, CharSequence s2) {
-        if (s1 == null) {
-            return s2 == null;
-        }
-        if (s2 == null) {
-            return false;
-        }
-        if (s1.getClass() != s2.getClass()) {
-            return false;
-        }
-        return s1.equals(s2);
-    }
-    
-    static boolean comparePermissionInfos(PermissionInfo pi1, PermissionInfo pi2) {
-        if (pi1.icon != pi2.icon) return false;
-        if (pi1.logo != pi2.logo) return false;
-        if (pi1.protectionLevel != pi2.protectionLevel) return false;
-        if (!compareStrings(pi1.name, pi2.name)) return false;
-        if (!compareStrings(pi1.nonLocalizedLabel, pi2.nonLocalizedLabel)) return false;
-        // We'll take care of setting this one.
-        if (!compareStrings(pi1.packageName, pi2.packageName)) return false;
-        // These are not currently stored in settings.
-        //if (!compareStrings(pi1.group, pi2.group)) return false;
-        //if (!compareStrings(pi1.nonLocalizedDescription, pi2.nonLocalizedDescription)) return false;
-        //if (pi1.labelRes != pi2.labelRes) return false;
-        //if (pi1.descriptionRes != pi2.descriptionRes) return false;
-        return true;
-    }
-    
-    boolean addPermissionLocked(PermissionInfo info, boolean async) {
-        if (info.labelRes == 0 && info.nonLocalizedLabel == null) {
-            throw new SecurityException("Label must be specified in permission");
-        }
-        BasePermission tree = checkPermissionTreeLP(info.name);
-        BasePermission bp = mSettings.mPermissions.get(info.name);
-        boolean added = bp == null;
-        boolean changed = true;
-        int fixedLevel = PermissionInfo.fixProtectionLevel(info.protectionLevel);
-        if (added) {
-            bp = new BasePermission(info.name, tree.sourcePackage,
-                    BasePermission.TYPE_DYNAMIC);
-        } else if (bp.type != BasePermission.TYPE_DYNAMIC) {
-            throw new SecurityException(
-                    "Not allowed to modify non-dynamic permission "
-                    + info.name);
-        } else {
-            if (bp.protectionLevel == fixedLevel
-                    && bp.perm.owner.equals(tree.perm.owner)
-                    && bp.uid == tree.uid
-                    && comparePermissionInfos(bp.perm.info, info)) {
-                changed = false;
-            }
-        }
-        bp.protectionLevel = fixedLevel;
-        info = new PermissionInfo(info);
-        info.protectionLevel = fixedLevel;
-        bp.perm = new PackageParser.Permission(tree.perm.owner, info);
-        bp.perm.info.packageName = tree.perm.info.packageName;
-        bp.uid = tree.uid;
-        if (added) {
-            mSettings.mPermissions.put(info.name, bp);
-        }
-        if (changed) {
-            if (!async) {
-                mSettings.writeLPr();
-            } else {
-                scheduleWriteSettingsLocked();
-            }
-        }
-        return added;
-    }
-
-    public boolean addPermission(PermissionInfo info) {
-        synchronized (mPackages) {
-            return addPermissionLocked(info, false);
-        }
-    }
-
-    public boolean addPermissionAsync(PermissionInfo info) {
-        synchronized (mPackages) {
-            return addPermissionLocked(info, true);
-        }
-    }
-
-    public void removePermission(String name) {
-        synchronized (mPackages) {
-            checkPermissionTreeLP(name);
-            BasePermission bp = mSettings.mPermissions.get(name);
-            if (bp != null) {
-                if (bp.type != BasePermission.TYPE_DYNAMIC) {
-                    throw new SecurityException(
-                            "Not allowed to modify non-dynamic permission "
-                            + name);
-                }
-                mSettings.mPermissions.remove(name);
-                mSettings.writeLPr();
-            }
-        }
-    }
-
-    private static void checkGrantRevokePermissions(PackageParser.Package pkg, BasePermission bp) {
-        int index = pkg.requestedPermissions.indexOf(bp.name);
-        if (index == -1) {
-            throw new SecurityException("Package " + pkg.packageName
-                    + " has not requested permission " + bp.name);
-        }
-        boolean isNormal =
-                ((bp.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE)
-                        == PermissionInfo.PROTECTION_NORMAL);
-        boolean isDangerous =
-                ((bp.protectionLevel&PermissionInfo.PROTECTION_MASK_BASE)
-                        == PermissionInfo.PROTECTION_DANGEROUS);
-        boolean isDevelopment =
-                ((bp.protectionLevel&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
-
-        if (!isNormal && !isDangerous && !isDevelopment) {
-            throw new SecurityException("Permission " + bp.name
-                    + " is not a changeable permission type");
-        }
-
-        if (isNormal || isDangerous) {
-            if (pkg.requestedPermissionsRequired.get(index)) {
-                throw new SecurityException("Can't change " + bp.name
-                        + ". It is required by the application");
-            }
-        }
-    }
-
-    public void grantPermission(String packageName, String permissionName) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.GRANT_REVOKE_PERMISSIONS, null);
-        synchronized (mPackages) {
-            final PackageParser.Package pkg = mPackages.get(packageName);
-            if (pkg == null) {
-                throw new IllegalArgumentException("Unknown package: " + packageName);
-            }
-            final BasePermission bp = mSettings.mPermissions.get(permissionName);
-            if (bp == null) {
-                throw new IllegalArgumentException("Unknown permission: " + permissionName);
-            }
-
-            checkGrantRevokePermissions(pkg, bp);
-
-            final PackageSetting ps = (PackageSetting) pkg.mExtras;
-            if (ps == null) {
-                return;
-            }
-            final GrantedPermissions gp = (ps.sharedUser != null) ? ps.sharedUser : ps;
-            if (gp.grantedPermissions.add(permissionName)) {
-                if (ps.haveGids) {
-                    gp.gids = appendInts(gp.gids, bp.gids);
-                }
-                mSettings.writeLPr();
-            }
-        }
-    }
-
-    public void revokePermission(String packageName, String permissionName) {
-        int changedAppId = -1;
-
-        synchronized (mPackages) {
-            final PackageParser.Package pkg = mPackages.get(packageName);
-            if (pkg == null) {
-                throw new IllegalArgumentException("Unknown package: " + packageName);
-            }
-            if (pkg.applicationInfo.uid != Binder.getCallingUid()) {
-                mContext.enforceCallingOrSelfPermission(
-                        android.Manifest.permission.GRANT_REVOKE_PERMISSIONS, null);
-            }
-            final BasePermission bp = mSettings.mPermissions.get(permissionName);
-            if (bp == null) {
-                throw new IllegalArgumentException("Unknown permission: " + permissionName);
-            }
-
-            checkGrantRevokePermissions(pkg, bp);
-
-            final PackageSetting ps = (PackageSetting) pkg.mExtras;
-            if (ps == null) {
-                return;
-            }
-            final GrantedPermissions gp = (ps.sharedUser != null) ? ps.sharedUser : ps;
-            if (gp.grantedPermissions.remove(permissionName)) {
-                gp.grantedPermissions.remove(permissionName);
-                if (ps.haveGids) {
-                    gp.gids = removeInts(gp.gids, bp.gids);
-                }
-                mSettings.writeLPr();
-                changedAppId = ps.appId;
-            }
-        }
-
-        if (changedAppId >= 0) {
-            // We changed the perm on someone, kill its processes.
-            IActivityManager am = ActivityManagerNative.getDefault();
-            if (am != null) {
-                final int callingUserId = UserHandle.getCallingUserId();
-                final long ident = Binder.clearCallingIdentity();
-                try {
-                    //XXX we should only revoke for the calling user's app permissions,
-                    // but for now we impact all users.
-                    //am.killUid(UserHandle.getUid(callingUserId, changedAppId),
-                    //        "revoke " + permissionName);
-                    int[] users = sUserManager.getUserIds();
-                    for (int user : users) {
-                        am.killUid(UserHandle.getUid(user, changedAppId),
-                                "revoke " + permissionName);
-                    }
-                } catch (RemoteException e) {
-                } finally {
-                    Binder.restoreCallingIdentity(ident);
-                }
-            }
-        }
-    }
-
-    public boolean isProtectedBroadcast(String actionName) {
-        synchronized (mPackages) {
-            return mProtectedBroadcasts.contains(actionName);
-        }
-    }
-
-    public int checkSignatures(String pkg1, String pkg2) {
-        synchronized (mPackages) {
-            final PackageParser.Package p1 = mPackages.get(pkg1);
-            final PackageParser.Package p2 = mPackages.get(pkg2);
-            if (p1 == null || p1.mExtras == null
-                    || p2 == null || p2.mExtras == null) {
-                return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
-            }
-            return compareSignatures(p1.mSignatures, p2.mSignatures);
-        }
-    }
-
-    public int checkUidSignatures(int uid1, int uid2) {
-        // Map to base uids.
-        uid1 = UserHandle.getAppId(uid1);
-        uid2 = UserHandle.getAppId(uid2);
-        // reader
-        synchronized (mPackages) {
-            Signature[] s1;
-            Signature[] s2;
-            Object obj = mSettings.getUserIdLPr(uid1);
-            if (obj != null) {
-                if (obj instanceof SharedUserSetting) {
-                    s1 = ((SharedUserSetting)obj).signatures.mSignatures;
-                } else if (obj instanceof PackageSetting) {
-                    s1 = ((PackageSetting)obj).signatures.mSignatures;
-                } else {
-                    return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
-                }
-            } else {
-                return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
-            }
-            obj = mSettings.getUserIdLPr(uid2);
-            if (obj != null) {
-                if (obj instanceof SharedUserSetting) {
-                    s2 = ((SharedUserSetting)obj).signatures.mSignatures;
-                } else if (obj instanceof PackageSetting) {
-                    s2 = ((PackageSetting)obj).signatures.mSignatures;
-                } else {
-                    return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
-                }
-            } else {
-                return PackageManager.SIGNATURE_UNKNOWN_PACKAGE;
-            }
-            return compareSignatures(s1, s2);
-        }
-    }
-
-    static int compareSignatures(Signature[] s1, Signature[] s2) {
-        if (s1 == null) {
-            return s2 == null
-                    ? PackageManager.SIGNATURE_NEITHER_SIGNED
-                    : PackageManager.SIGNATURE_FIRST_NOT_SIGNED;
-        }
-        if (s2 == null) {
-            return PackageManager.SIGNATURE_SECOND_NOT_SIGNED;
-        }
-        HashSet<Signature> set1 = new HashSet<Signature>();
-        for (Signature sig : s1) {
-            set1.add(sig);
-        }
-        HashSet<Signature> set2 = new HashSet<Signature>();
-        for (Signature sig : s2) {
-            set2.add(sig);
-        }
-        // Make sure s2 contains all signatures in s1.
-        if (set1.equals(set2)) {
-            return PackageManager.SIGNATURE_MATCH;
-        }
-        return PackageManager.SIGNATURE_NO_MATCH;
-    }
-
-    public String[] getPackagesForUid(int uid) {
-        uid = UserHandle.getAppId(uid);
-        // reader
-        synchronized (mPackages) {
-            Object obj = mSettings.getUserIdLPr(uid);
-            if (obj instanceof SharedUserSetting) {
-                final SharedUserSetting sus = (SharedUserSetting) obj;
-                final int N = sus.packages.size();
-                final String[] res = new String[N];
-                final Iterator<PackageSetting> it = sus.packages.iterator();
-                int i = 0;
-                while (it.hasNext()) {
-                    res[i++] = it.next().name;
-                }
-                return res;
-            } else if (obj instanceof PackageSetting) {
-                final PackageSetting ps = (PackageSetting) obj;
-                return new String[] { ps.name };
-            }
-        }
-        return null;
-    }
-
-    public String getNameForUid(int uid) {
-        // reader
-        synchronized (mPackages) {
-            Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
-            if (obj instanceof SharedUserSetting) {
-                final SharedUserSetting sus = (SharedUserSetting) obj;
-                return sus.name + ":" + sus.userId;
-            } else if (obj instanceof PackageSetting) {
-                final PackageSetting ps = (PackageSetting) obj;
-                return ps.name;
-            }
-        }
-        return null;
-    }
-
-    public int getUidForSharedUser(String sharedUserName) {
-        if(sharedUserName == null) {
-            return -1;
-        }
-        // reader
-        synchronized (mPackages) {
-            final SharedUserSetting suid = mSettings.getSharedUserLPw(sharedUserName, 0, false);
-            if (suid == null) {
-                return -1;
-            }
-            return suid.userId;
-        }
-    }
-
-    public int getFlagsForUid(int uid) {
-        synchronized (mPackages) {
-            Object obj = mSettings.getUserIdLPr(UserHandle.getAppId(uid));
-            if (obj instanceof SharedUserSetting) {
-                final SharedUserSetting sus = (SharedUserSetting) obj;
-                return sus.pkgFlags;
-            } else if (obj instanceof PackageSetting) {
-                final PackageSetting ps = (PackageSetting) obj;
-                return ps.pkgFlags;
-            }
-        }
-        return 0;
-    }
-
-    @Override
-    public ResolveInfo resolveIntent(Intent intent, String resolvedType,
-            int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "resolve intent");
-        List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
-        return chooseBestActivity(intent, resolvedType, flags, query, userId);
-    }
-
-    @Override
-    public void setLastChosenActivity(Intent intent, String resolvedType, int flags,
-            IntentFilter filter, int match, ComponentName activity) {
-        final int userId = UserHandle.getCallingUserId();
-        if (DEBUG_PREFERRED) {
-            Log.v(TAG, "setLastChosenActivity intent=" + intent
-                + " resolvedType=" + resolvedType
-                + " flags=" + flags
-                + " filter=" + filter
-                + " match=" + match
-                + " activity=" + activity);
-            filter.dump(new PrintStreamPrinter(System.out), "    ");
-        }
-        intent.setComponent(null);
-        List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
-        // Find any earlier preferred or last chosen entries and nuke them
-        findPreferredActivity(intent, resolvedType,
-                flags, query, 0, false, true, false, userId);
-        // Add the new activity as the last chosen for this filter
-        addPreferredActivityInternal(filter, match, null, activity, false, userId);
-    }
-
-    @Override
-    public ResolveInfo getLastChosenActivity(Intent intent, String resolvedType, int flags) {
-        final int userId = UserHandle.getCallingUserId();
-        if (DEBUG_PREFERRED) Log.v(TAG, "Querying last chosen activity for " + intent);
-        List<ResolveInfo> query = queryIntentActivities(intent, resolvedType, flags, userId);
-        return findPreferredActivity(intent, resolvedType, flags, query, 0,
-                false, false, false, userId);
-    }
-
-    private ResolveInfo chooseBestActivity(Intent intent, String resolvedType,
-            int flags, List<ResolveInfo> query, int userId) {
-        if (query != null) {
-            final int N = query.size();
-            if (N == 1) {
-                return query.get(0);
-            } else if (N > 1) {
-                final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0);
-                // If there is more than one activity with the same priority,
-                // then let the user decide between them.
-                ResolveInfo r0 = query.get(0);
-                ResolveInfo r1 = query.get(1);
-                if (DEBUG_INTENT_MATCHING || debug) {
-                    Slog.v(TAG, r0.activityInfo.name + "=" + r0.priority + " vs "
-                            + r1.activityInfo.name + "=" + r1.priority);
-                }
-                // If the first activity has a higher priority, or a different
-                // default, then it is always desireable to pick it.
-                if (r0.priority != r1.priority
-                        || r0.preferredOrder != r1.preferredOrder
-                        || r0.isDefault != r1.isDefault) {
-                    return query.get(0);
-                }
-                // If we have saved a preference for a preferred activity for
-                // this Intent, use that.
-                ResolveInfo ri = findPreferredActivity(intent, resolvedType,
-                        flags, query, r0.priority, true, false, debug, userId);
-                if (ri != null) {
-                    return ri;
-                }
-                if (userId != 0) {
-                    ri = new ResolveInfo(mResolveInfo);
-                    ri.activityInfo = new ActivityInfo(ri.activityInfo);
-                    ri.activityInfo.applicationInfo = new ApplicationInfo(
-                            ri.activityInfo.applicationInfo);
-                    ri.activityInfo.applicationInfo.uid = UserHandle.getUid(userId,
-                            UserHandle.getAppId(ri.activityInfo.applicationInfo.uid));
-                    return ri;
-                }
-                return mResolveInfo;
-            }
-        }
-        return null;
-    }
-
-    ResolveInfo findPreferredActivity(Intent intent, String resolvedType, int flags,
-            List<ResolveInfo> query, int priority, boolean always,
-            boolean removeMatches, boolean debug, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        // writer
-        synchronized (mPackages) {
-            if (intent.getSelector() != null) {
-                intent = intent.getSelector();
-            }
-            if (DEBUG_PREFERRED) intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
-            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
-            // Get the list of preferred activities that handle the intent
-            if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Looking for preferred activities...");
-            List<PreferredActivity> prefs = pir != null
-                    ? pir.queryIntent(intent, resolvedType,
-                            (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId)
-                    : null;
-            if (prefs != null && prefs.size() > 0) {
-                // First figure out how good the original match set is.
-                // We will only allow preferred activities that came
-                // from the same match quality.
-                int match = 0;
-
-                if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Figuring out best match...");
-
-                final int N = query.size();
-                for (int j=0; j<N; j++) {
-                    final ResolveInfo ri = query.get(j);
-                    if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Match for " + ri.activityInfo
-                            + ": 0x" + Integer.toHexString(match));
-                    if (ri.match > match) {
-                        match = ri.match;
-                    }
-                }
-
-                if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Best match: 0x"
-                        + Integer.toHexString(match));
-
-                match &= IntentFilter.MATCH_CATEGORY_MASK;
-                final int M = prefs.size();
-                for (int i=0; i<M; i++) {
-                    final PreferredActivity pa = prefs.get(i);
-                    if (DEBUG_PREFERRED || debug) {
-                        Slog.v(TAG, "Checking PreferredActivity ds="
-                                + (pa.countDataSchemes() > 0 ? pa.getDataScheme(0) : "<none>")
-                                + "\n  component=" + pa.mPref.mComponent);
-                        pa.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
-                    }
-                    if (pa.mPref.mMatch != match) {
-                        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Skipping bad match "
-                                + Integer.toHexString(pa.mPref.mMatch));
-                        continue;
-                    }
-                    // If it's not an "always" type preferred activity and that's what we're
-                    // looking for, skip it.
-                    if (always && !pa.mPref.mAlways) {
-                        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Skipping mAlways=false entry");
-                        continue;
-                    }
-                    final ActivityInfo ai = getActivityInfo(pa.mPref.mComponent,
-                            flags | PackageManager.GET_DISABLED_COMPONENTS, userId);
-                    if (DEBUG_PREFERRED || debug) {
-                        Slog.v(TAG, "Found preferred activity:");
-                        if (ai != null) {
-                            ai.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
-                        } else {
-                            Slog.v(TAG, "  null");
-                        }
-                    }
-                    if (ai == null) {
-                        // This previously registered preferred activity
-                        // component is no longer known.  Most likely an update
-                        // to the app was installed and in the new version this
-                        // component no longer exists.  Clean it up by removing
-                        // it from the preferred activities list, and skip it.
-                        Slog.w(TAG, "Removing dangling preferred activity: "
-                                + pa.mPref.mComponent);
-                        pir.removeFilter(pa);
-                        continue;
-                    }
-                    for (int j=0; j<N; j++) {
-                        final ResolveInfo ri = query.get(j);
-                        if (!ri.activityInfo.applicationInfo.packageName
-                                .equals(ai.applicationInfo.packageName)) {
-                            continue;
-                        }
-                        if (!ri.activityInfo.name.equals(ai.name)) {
-                            continue;
-                        }
-
-                        if (removeMatches) {
-                            pir.removeFilter(pa);
-                            if (DEBUG_PREFERRED) {
-                                Slog.v(TAG, "Removing match " + pa.mPref.mComponent);
-                            }
-                            break;
-                        }
-
-                        // Okay we found a previously set preferred or last chosen app.
-                        // If the result set is different from when this
-                        // was created, we need to clear it and re-ask the
-                        // user their preference, if we're looking for an "always" type entry.
-                        if (always && !pa.mPref.sameSet(query, priority)) {
-                            Slog.i(TAG, "Result set changed, dropping preferred activity for "
-                                    + intent + " type " + resolvedType);
-                            if (DEBUG_PREFERRED) {
-                                Slog.v(TAG, "Removing preferred activity since set changed "
-                                        + pa.mPref.mComponent);
-                            }
-                            pir.removeFilter(pa);
-                            // Re-add the filter as a "last chosen" entry (!always)
-                            PreferredActivity lastChosen = new PreferredActivity(
-                                    pa, pa.mPref.mMatch, null, pa.mPref.mComponent, false);
-                            pir.addFilter(lastChosen);
-                            mSettings.writePackageRestrictionsLPr(userId);
-                            return null;
-                        }
-
-                        // Yay! Either the set matched or we're looking for the last chosen
-                        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "Returning preferred activity: "
-                                + ri.activityInfo.packageName + "/" + ri.activityInfo.name);
-                        mSettings.writePackageRestrictionsLPr(userId);
-                        return ri;
-                    }
-                }
-            }
-            mSettings.writePackageRestrictionsLPr(userId);
-        }
-        if (DEBUG_PREFERRED || debug) Slog.v(TAG, "No preferred activity to return");
-        return null;
-    }
-
-    @Override
-    public List<ResolveInfo> queryIntentActivities(Intent intent,
-            String resolvedType, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return Collections.emptyList();
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false, "query intent activities");
-        ComponentName comp = intent.getComponent();
-        if (comp == null) {
-            if (intent.getSelector() != null) {
-                intent = intent.getSelector(); 
-                comp = intent.getComponent();
-            }
-        }
-
-        if (comp != null) {
-            final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
-            final ActivityInfo ai = getActivityInfo(comp, flags, userId);
-            if (ai != null) {
-                final ResolveInfo ri = new ResolveInfo();
-                ri.activityInfo = ai;
-                list.add(ri);
-            }
-            return list;
-        }
-
-        // reader
-        synchronized (mPackages) {
-            final String pkgName = intent.getPackage();
-            if (pkgName == null) {
-                return mActivities.queryIntent(intent, resolvedType, flags, userId);
-            }
-            final PackageParser.Package pkg = mPackages.get(pkgName);
-            if (pkg != null) {
-                return mActivities.queryIntentForPackage(intent, resolvedType, flags,
-                        pkg.activities, userId);
-            }
-            return new ArrayList<ResolveInfo>();
-        }
-    }
-
-    @Override
-    public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller,
-            Intent[] specifics, String[] specificTypes, Intent intent,
-            String resolvedType, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return Collections.emptyList();
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, false,
-                "query intent activity options");
-        final String resultsAction = intent.getAction();
-
-        List<ResolveInfo> results = queryIntentActivities(intent, resolvedType, flags
-                | PackageManager.GET_RESOLVED_FILTER, userId);
-
-        if (DEBUG_INTENT_MATCHING) {
-            Log.v(TAG, "Query " + intent + ": " + results);
-        }
-
-        int specificsPos = 0;
-        int N;
-
-        // todo: note that the algorithm used here is O(N^2).  This
-        // isn't a problem in our current environment, but if we start running
-        // into situations where we have more than 5 or 10 matches then this
-        // should probably be changed to something smarter...
-
-        // First we go through and resolve each of the specific items
-        // that were supplied, taking care of removing any corresponding
-        // duplicate items in the generic resolve list.
-        if (specifics != null) {
-            for (int i=0; i<specifics.length; i++) {
-                final Intent sintent = specifics[i];
-                if (sintent == null) {
-                    continue;
-                }
-
-                if (DEBUG_INTENT_MATCHING) {
-                    Log.v(TAG, "Specific #" + i + ": " + sintent);
-                }
-
-                String action = sintent.getAction();
-                if (resultsAction != null && resultsAction.equals(action)) {
-                    // If this action was explicitly requested, then don't
-                    // remove things that have it.
-                    action = null;
-                }
-
-                ResolveInfo ri = null;
-                ActivityInfo ai = null;
-
-                ComponentName comp = sintent.getComponent();
-                if (comp == null) {
-                    ri = resolveIntent(
-                        sintent,
-                        specificTypes != null ? specificTypes[i] : null,
-                            flags, userId);
-                    if (ri == null) {
-                        continue;
-                    }
-                    if (ri == mResolveInfo) {
-                        // ACK!  Must do something better with this.
-                    }
-                    ai = ri.activityInfo;
-                    comp = new ComponentName(ai.applicationInfo.packageName,
-                            ai.name);
-                } else {
-                    ai = getActivityInfo(comp, flags, userId);
-                    if (ai == null) {
-                        continue;
-                    }
-                }
-
-                // Look for any generic query activities that are duplicates
-                // of this specific one, and remove them from the results.
-                if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Specific #" + i + ": " + ai);
-                N = results.size();
-                int j;
-                for (j=specificsPos; j<N; j++) {
-                    ResolveInfo sri = results.get(j);
-                    if ((sri.activityInfo.name.equals(comp.getClassName())
-                            && sri.activityInfo.applicationInfo.packageName.equals(
-                                    comp.getPackageName()))
-                        || (action != null && sri.filter.matchAction(action))) {
-                        results.remove(j);
-                        if (DEBUG_INTENT_MATCHING) Log.v(
-                            TAG, "Removing duplicate item from " + j
-                            + " due to specific " + specificsPos);
-                        if (ri == null) {
-                            ri = sri;
-                        }
-                        j--;
-                        N--;
-                    }
-                }
-
-                // Add this specific item to its proper place.
-                if (ri == null) {
-                    ri = new ResolveInfo();
-                    ri.activityInfo = ai;
-                }
-                results.add(specificsPos, ri);
-                ri.specificIndex = i;
-                specificsPos++;
-            }
-        }
-
-        // Now we go through the remaining generic results and remove any
-        // duplicate actions that are found here.
-        N = results.size();
-        for (int i=specificsPos; i<N-1; i++) {
-            final ResolveInfo rii = results.get(i);
-            if (rii.filter == null) {
-                continue;
-            }
-
-            // Iterate over all of the actions of this result's intent
-            // filter...  typically this should be just one.
-            final Iterator<String> it = rii.filter.actionsIterator();
-            if (it == null) {
-                continue;
-            }
-            while (it.hasNext()) {
-                final String action = it.next();
-                if (resultsAction != null && resultsAction.equals(action)) {
-                    // If this action was explicitly requested, then don't
-                    // remove things that have it.
-                    continue;
-                }
-                for (int j=i+1; j<N; j++) {
-                    final ResolveInfo rij = results.get(j);
-                    if (rij.filter != null && rij.filter.hasAction(action)) {
-                        results.remove(j);
-                        if (DEBUG_INTENT_MATCHING) Log.v(
-                            TAG, "Removing duplicate item from " + j
-                            + " due to action " + action + " at " + i);
-                        j--;
-                        N--;
-                    }
-                }
-            }
-
-            // If the caller didn't request filter information, drop it now
-            // so we don't have to marshall/unmarshall it.
-            if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) {
-                rii.filter = null;
-            }
-        }
-
-        // Filter out the caller activity if so requested.
-        if (caller != null) {
-            N = results.size();
-            for (int i=0; i<N; i++) {
-                ActivityInfo ainfo = results.get(i).activityInfo;
-                if (caller.getPackageName().equals(ainfo.applicationInfo.packageName)
-                        && caller.getClassName().equals(ainfo.name)) {
-                    results.remove(i);
-                    break;
-                }
-            }
-        }
-
-        // If the caller didn't request filter information,
-        // drop them now so we don't have to
-        // marshall/unmarshall it.
-        if ((flags&PackageManager.GET_RESOLVED_FILTER) == 0) {
-            N = results.size();
-            for (int i=0; i<N; i++) {
-                results.get(i).filter = null;
-            }
-        }
-
-        if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Result: " + results);
-        return results;
-    }
-
-    @Override
-    public List<ResolveInfo> queryIntentReceivers(Intent intent, String resolvedType, int flags,
-            int userId) {
-        if (!sUserManager.exists(userId)) return Collections.emptyList();
-        ComponentName comp = intent.getComponent();
-        if (comp == null) {
-            if (intent.getSelector() != null) {
-                intent = intent.getSelector(); 
-                comp = intent.getComponent();
-            }
-        }
-        if (comp != null) {
-            List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
-            ActivityInfo ai = getReceiverInfo(comp, flags, userId);
-            if (ai != null) {
-                ResolveInfo ri = new ResolveInfo();
-                ri.activityInfo = ai;
-                list.add(ri);
-            }
-            return list;
-        }
-
-        // reader
-        synchronized (mPackages) {
-            String pkgName = intent.getPackage();
-            if (pkgName == null) {
-                return mReceivers.queryIntent(intent, resolvedType, flags, userId);
-            }
-            final PackageParser.Package pkg = mPackages.get(pkgName);
-            if (pkg != null) {
-                return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers,
-                        userId);
-            }
-            return null;
-        }
-    }
-
-    @Override
-    public ResolveInfo resolveService(Intent intent, String resolvedType, int flags, int userId) {
-        List<ResolveInfo> query = queryIntentServices(intent, resolvedType, flags, userId);
-        if (!sUserManager.exists(userId)) return null;
-        if (query != null) {
-            if (query.size() >= 1) {
-                // If there is more than one service with the same priority,
-                // just arbitrarily pick the first one.
-                return query.get(0);
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public List<ResolveInfo> queryIntentServices(Intent intent, String resolvedType, int flags,
-            int userId) {
-        if (!sUserManager.exists(userId)) return Collections.emptyList();
-        ComponentName comp = intent.getComponent();
-        if (comp == null) {
-            if (intent.getSelector() != null) {
-                intent = intent.getSelector(); 
-                comp = intent.getComponent();
-            }
-        }
-        if (comp != null) {
-            final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
-            final ServiceInfo si = getServiceInfo(comp, flags, userId);
-            if (si != null) {
-                final ResolveInfo ri = new ResolveInfo();
-                ri.serviceInfo = si;
-                list.add(ri);
-            }
-            return list;
-        }
-
-        // reader
-        synchronized (mPackages) {
-            String pkgName = intent.getPackage();
-            if (pkgName == null) {
-                return mServices.queryIntent(intent, resolvedType, flags, userId);
-            }
-            final PackageParser.Package pkg = mPackages.get(pkgName);
-            if (pkg != null) {
-                return mServices.queryIntentForPackage(intent, resolvedType, flags, pkg.services,
-                        userId);
-            }
-            return null;
-        }
-    }
-
-    @Override
-    public List<ResolveInfo> queryIntentContentProviders(
-            Intent intent, String resolvedType, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return Collections.emptyList();
-        ComponentName comp = intent.getComponent();
-        if (comp == null) {
-            if (intent.getSelector() != null) {
-                intent = intent.getSelector();
-                comp = intent.getComponent();
-            }
-        }
-        if (comp != null) {
-            final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
-            final ProviderInfo pi = getProviderInfo(comp, flags, userId);
-            if (pi != null) {
-                final ResolveInfo ri = new ResolveInfo();
-                ri.providerInfo = pi;
-                list.add(ri);
-            }
-            return list;
-        }
-
-        // reader
-        synchronized (mPackages) {
-            String pkgName = intent.getPackage();
-            if (pkgName == null) {
-                return mProviders.queryIntent(intent, resolvedType, flags, userId);
-            }
-            final PackageParser.Package pkg = mPackages.get(pkgName);
-            if (pkg != null) {
-                return mProviders.queryIntentForPackage(
-                        intent, resolvedType, flags, pkg.providers, userId);
-            }
-            return null;
-        }
-    }
-
-    @Override
-    public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, int userId) {
-        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
-
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "get installed packages");
-
-        // writer
-        synchronized (mPackages) {
-            ArrayList<PackageInfo> list;
-            if (listUninstalled) {
-                list = new ArrayList<PackageInfo>(mSettings.mPackages.size());
-                for (PackageSetting ps : mSettings.mPackages.values()) {
-                    PackageInfo pi;
-                    if (ps.pkg != null) {
-                        pi = generatePackageInfo(ps.pkg, flags, userId);
-                    } else {
-                        pi = generatePackageInfoFromSettingsLPw(ps.name, flags, userId);
-                    }
-                    if (pi != null) {
-                        list.add(pi);
-                    }
-                }
-            } else {
-                list = new ArrayList<PackageInfo>(mPackages.size());
-                for (PackageParser.Package p : mPackages.values()) {
-                    PackageInfo pi = generatePackageInfo(p, flags, userId);
-                    if (pi != null) {
-                        list.add(pi);
-                    }
-                }
-            }
-
-            return new ParceledListSlice<PackageInfo>(list);
-        }
-    }
-
-    private void addPackageHoldingPermissions(ArrayList<PackageInfo> list, PackageSetting ps,
-            String[] permissions, boolean[] tmp, int flags, int userId) {
-        int numMatch = 0;
-        final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
-        for (int i=0; i<permissions.length; i++) {
-            if (gp.grantedPermissions.contains(permissions[i])) {
-                tmp[i] = true;
-                numMatch++;
-            } else {
-                tmp[i] = false;
-            }
-        }
-        if (numMatch == 0) {
-            return;
-        }
-        PackageInfo pi;
-        if (ps.pkg != null) {
-            pi = generatePackageInfo(ps.pkg, flags, userId);
-        } else {
-            pi = generatePackageInfoFromSettingsLPw(ps.name, flags, userId);
-        }
-        if ((flags&PackageManager.GET_PERMISSIONS) == 0) {
-            if (numMatch == permissions.length) {
-                pi.requestedPermissions = permissions;
-            } else {
-                pi.requestedPermissions = new String[numMatch];
-                numMatch = 0;
-                for (int i=0; i<permissions.length; i++) {
-                    if (tmp[i]) {
-                        pi.requestedPermissions[numMatch] = permissions[i];
-                        numMatch++;
-                    }
-                }
-            }
-        }
-        list.add(pi);
-    }
-
-    @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;
-
-        // writer
-        synchronized (mPackages) {
-            ArrayList<PackageInfo> list = new ArrayList<PackageInfo>();
-            boolean[] tmpBools = new boolean[permissions.length];
-            if (listUninstalled) {
-                for (PackageSetting ps : mSettings.mPackages.values()) {
-                    addPackageHoldingPermissions(list, ps, permissions, tmpBools, flags, userId);
-                }
-            } else {
-                for (PackageParser.Package pkg : mPackages.values()) {
-                    PackageSetting ps = (PackageSetting)pkg.mExtras;
-                    if (ps != null) {
-                        addPackageHoldingPermissions(list, ps, permissions, tmpBools, flags,
-                                userId);
-                    }
-                }
-            }
-
-            return new ParceledListSlice<PackageInfo>(list);
-        }
-    }
-
-    @Override
-    public ParceledListSlice<ApplicationInfo> getInstalledApplications(int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
-
-        // writer
-        synchronized (mPackages) {
-            ArrayList<ApplicationInfo> list;
-            if (listUninstalled) {
-                list = new ArrayList<ApplicationInfo>(mSettings.mPackages.size());
-                for (PackageSetting ps : mSettings.mPackages.values()) {
-                    ApplicationInfo ai;
-                    if (ps.pkg != null) {
-                        ai = PackageParser.generateApplicationInfo(ps.pkg, flags,
-                                ps.readUserState(userId), userId);
-                    } else {
-                        ai = generateApplicationInfoFromSettingsLPw(ps.name, flags, userId);
-                    }
-                    if (ai != null) {
-                        list.add(ai);
-                    }
-                }
-            } else {
-                list = new ArrayList<ApplicationInfo>(mPackages.size());
-                for (PackageParser.Package p : mPackages.values()) {
-                    if (p.mExtras != null) {
-                        ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags,
-                                ((PackageSetting)p.mExtras).readUserState(userId), userId);
-                        if (ai != null) {
-                            list.add(ai);
-                        }
-                    }
-                }
-            }
-
-            return new ParceledListSlice<ApplicationInfo>(list);
-        }
-    }
-
-    public List<ApplicationInfo> getPersistentApplications(int flags) {
-        final ArrayList<ApplicationInfo> finalList = new ArrayList<ApplicationInfo>();
-
-        // reader
-        synchronized (mPackages) {
-            final Iterator<PackageParser.Package> i = mPackages.values().iterator();
-            final int userId = UserHandle.getCallingUserId();
-            while (i.hasNext()) {
-                final PackageParser.Package p = i.next();
-                if (p.applicationInfo != null
-                        && (p.applicationInfo.flags&ApplicationInfo.FLAG_PERSISTENT) != 0
-                        && (!mSafeMode || isSystemApp(p))) {
-                    PackageSetting ps = mSettings.mPackages.get(p.packageName);
-                    if (ps != null) {
-                        ApplicationInfo ai = PackageParser.generateApplicationInfo(p, flags,
-                                ps.readUserState(userId), userId);
-                        if (ai != null) {
-                            finalList.add(ai);
-                        }
-                    }
-                }
-            }
-        }
-
-        return finalList;
-    }
-
-    @Override
-    public ProviderInfo resolveContentProvider(String name, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return null;
-        // reader
-        synchronized (mPackages) {
-            final PackageParser.Provider provider = mProvidersByAuthority.get(name);
-            PackageSetting ps = provider != null
-                    ? mSettings.mPackages.get(provider.owner.packageName)
-                    : null;
-            return ps != null
-                    && mSettings.isEnabledLPr(provider.info, flags, userId)
-                    && (!mSafeMode || (provider.info.applicationInfo.flags
-                            &ApplicationInfo.FLAG_SYSTEM) != 0)
-                    ? PackageParser.generateProviderInfo(provider, flags,
-                            ps.readUserState(userId), userId)
-                    : null;
-        }
-    }
-
-    /**
-     * @deprecated
-     */
-    @Deprecated
-    public void querySyncProviders(List<String> outNames, List<ProviderInfo> outInfo) {
-        // reader
-        synchronized (mPackages) {
-            final Iterator<Map.Entry<String, PackageParser.Provider>> i = mProvidersByAuthority
-                    .entrySet().iterator();
-            final int userId = UserHandle.getCallingUserId();
-            while (i.hasNext()) {
-                Map.Entry<String, PackageParser.Provider> entry = i.next();
-                PackageParser.Provider p = entry.getValue();
-                PackageSetting ps = mSettings.mPackages.get(p.owner.packageName);
-
-                if (ps != null && p.syncable
-                        && (!mSafeMode || (p.info.applicationInfo.flags
-                                &ApplicationInfo.FLAG_SYSTEM) != 0)) {
-                    ProviderInfo info = PackageParser.generateProviderInfo(p, 0,
-                            ps.readUserState(userId), userId);
-                    if (info != null) {
-                        outNames.add(entry.getKey());
-                        outInfo.add(info);
-                    }
-                }
-            }
-        }
-    }
-
-    public List<ProviderInfo> queryContentProviders(String processName,
-            int uid, int flags) {
-        ArrayList<ProviderInfo> finalList = null;
-        // reader
-        synchronized (mPackages) {
-            final Iterator<PackageParser.Provider> i = mProviders.mProviders.values().iterator();
-            final int userId = processName != null ?
-                    UserHandle.getUserId(uid) : UserHandle.getCallingUserId();
-            while (i.hasNext()) {
-                final PackageParser.Provider p = i.next();
-                PackageSetting ps = mSettings.mPackages.get(p.owner.packageName);
-                if (ps != null && p.info.authority != null
-                        && (processName == null
-                                || (p.info.processName.equals(processName)
-                                        && UserHandle.isSameApp(p.info.applicationInfo.uid, uid)))
-                        && mSettings.isEnabledLPr(p.info, flags, userId)
-                        && (!mSafeMode
-                                || (p.info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)) {
-                    if (finalList == null) {
-                        finalList = new ArrayList<ProviderInfo>(3);
-                    }
-                    ProviderInfo info = PackageParser.generateProviderInfo(p, flags,
-                            ps.readUserState(userId), userId);
-                    if (info != null) {
-                        finalList.add(info);
-                    }
-                }
-            }
-        }
-
-        if (finalList != null) {
-            Collections.sort(finalList, mProviderInitOrderSorter);
-        }
-
-        return finalList;
-    }
-
-    public InstrumentationInfo getInstrumentationInfo(ComponentName name,
-            int flags) {
-        // reader
-        synchronized (mPackages) {
-            final PackageParser.Instrumentation i = mInstrumentation.get(name);
-            return PackageParser.generateInstrumentationInfo(i, flags);
-        }
-    }
-
-    public List<InstrumentationInfo> queryInstrumentation(String targetPackage,
-            int flags) {
-        ArrayList<InstrumentationInfo> finalList =
-            new ArrayList<InstrumentationInfo>();
-
-        // reader
-        synchronized (mPackages) {
-            final Iterator<PackageParser.Instrumentation> i = mInstrumentation.values().iterator();
-            while (i.hasNext()) {
-                final PackageParser.Instrumentation p = i.next();
-                if (targetPackage == null
-                        || targetPackage.equals(p.info.targetPackage)) {
-                    InstrumentationInfo ii = PackageParser.generateInstrumentationInfo(p,
-                            flags);
-                    if (ii != null) {
-                        finalList.add(ii);
-                    }
-                }
-            }
-        }
-
-        return finalList;
-    }
-
-    private void scanDirLI(File dir, int flags, int scanMode, long currentTime) {
-        String[] files = dir.list();
-        if (files == null) {
-            Log.d(TAG, "No files in app dir " + dir);
-            return;
-        }
-
-        if (DEBUG_PACKAGE_SCANNING) {
-            Log.d(TAG, "Scanning app dir " + dir + " scanMode=" + scanMode
-                    + " flags=0x" + Integer.toHexString(flags));
-        }
-
-        int i;
-        for (i=0; i<files.length; i++) {
-            File file = new File(dir, files[i]);
-            if (!isPackageFilename(files[i])) {
-                // Ignore entries which are not apk's
-                continue;
-            }
-            PackageParser.Package pkg = scanPackageLI(file,
-                    flags|PackageParser.PARSE_MUST_BE_APK, scanMode, currentTime, null);
-            // Don't mess around with apps in system partition.
-            if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0 &&
-                    mLastScanError == PackageManager.INSTALL_FAILED_INVALID_APK) {
-                // Delete the apk
-                Slog.w(TAG, "Cleaning up failed install of " + file);
-                file.delete();
-            }
-        }
-    }
-
-    private static File getSettingsProblemFile() {
-        File dataDir = Environment.getDataDirectory();
-        File systemDir = new File(dataDir, "system");
-        File fname = new File(systemDir, "uiderrors.txt");
-        return fname;
-    }
-    
-    static void reportSettingsProblem(int priority, String msg) {
-        try {
-            File fname = getSettingsProblemFile();
-            FileOutputStream out = new FileOutputStream(fname, true);
-            PrintWriter pw = new FastPrintWriter(out);
-            SimpleDateFormat formatter = new SimpleDateFormat();
-            String dateString = formatter.format(new Date(System.currentTimeMillis()));
-            pw.println(dateString + ": " + msg);
-            pw.close();
-            FileUtils.setPermissions(
-                    fname.toString(),
-                    FileUtils.S_IRWXU|FileUtils.S_IRWXG|FileUtils.S_IROTH,
-                    -1, -1);
-        } catch (java.io.IOException e) {
-        }
-        Slog.println(priority, TAG, msg);
-    }
-
-    private boolean collectCertificatesLI(PackageParser pp, PackageSetting ps,
-            PackageParser.Package pkg, File srcFile, int parseFlags) {
-        if (GET_CERTIFICATES) {
-            if (ps != null
-                    && ps.codePath.equals(srcFile)
-                    && ps.timeStamp == srcFile.lastModified()) {
-                if (ps.signatures.mSignatures != null
-                        && ps.signatures.mSignatures.length != 0) {
-                    // Optimization: reuse the existing cached certificates
-                    // if the package appears to be unchanged.
-                    pkg.mSignatures = ps.signatures.mSignatures;
-                    return true;
-                }
-                
-                Slog.w(TAG, "PackageSetting for " + ps.name + " is missing signatures.  Collecting certs again to recover them.");
-            } else {
-                Log.i(TAG, srcFile.toString() + " changed; collecting certs");
-            }
-            
-            if (!pp.collectCertificates(pkg, parseFlags)) {
-                mLastScanError = pp.getParseError();
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /*
-     *  Scan a package and return the newly parsed package.
-     *  Returns null in case of errors and the error code is stored in mLastScanError
-     */
-    private PackageParser.Package scanPackageLI(File scanFile,
-            int parseFlags, int scanMode, long currentTime, UserHandle user) {
-        mLastScanError = PackageManager.INSTALL_SUCCEEDED;
-        String scanPath = scanFile.getPath();
-        if (DEBUG_INSTALL) Slog.d(TAG, "Parsing: " + scanPath);
-        parseFlags |= mDefParseFlags;
-        PackageParser pp = new PackageParser(scanPath);
-        pp.setSeparateProcesses(mSeparateProcesses);
-        pp.setOnlyCoreApps(mOnlyCore);
-        final PackageParser.Package pkg = pp.parsePackage(scanFile,
-                scanPath, mMetrics, parseFlags);
-
-        if (pkg == null) {
-            mLastScanError = pp.getParseError();
-            return null;
-        }
-
-        PackageSetting ps = null;
-        PackageSetting updatedPkg;
-        // reader
-        synchronized (mPackages) {
-            // Look to see if we already know about this package.
-            String oldName = mSettings.mRenamedPackages.get(pkg.packageName);
-            if (pkg.mOriginalPackages != null && pkg.mOriginalPackages.contains(oldName)) {
-                // This package has been renamed to its original name.  Let's
-                // use that.
-                ps = mSettings.peekPackageLPr(oldName);
-            }
-            // If there was no original package, see one for the real package name.
-            if (ps == null) {
-                ps = mSettings.peekPackageLPr(pkg.packageName);
-            }
-            // Check to see if this package could be hiding/updating a system
-            // package.  Must look for it either under the original or real
-            // package name depending on our state.
-            updatedPkg = mSettings.getDisabledSystemPkgLPr(ps != null ? ps.name : pkg.packageName);
-            if (DEBUG_INSTALL && updatedPkg != null) Slog.d(TAG, "updatedPkg = " + updatedPkg);
-        }
-        // First check if this is a system package that may involve an update
-        if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
-            if (ps != null && !ps.codePath.equals(scanFile)) {
-                // The path has changed from what was last scanned...  check the
-                // version of the new path against what we have stored to determine
-                // what to do.
-                if (DEBUG_INSTALL) Slog.d(TAG, "Path changing from " + ps.codePath);
-                if (pkg.mVersionCode < ps.versionCode) {
-                    // The system package has been updated and the code path does not match
-                    // Ignore entry. Skip it.
-                    Log.i(TAG, "Package " + ps.name + " at " + scanFile
-                            + " 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 : "
-                                + ps.name + " changing from " + updatedPkg.codePathString
-                                + " to " + scanFile);
-                        updatedPkg.codePath = scanFile;
-                        updatedPkg.codePathString = scanFile.toString();
-                        // This is the point at which we know that the system-disk APK
-                        // for this package has moved during a reboot (e.g. due to an OTA),
-                        // so we need to reevaluate it for privilege policy.
-                        if (locationIsPrivileged(scanFile)) {
-                            updatedPkg.pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED;
-                        }
-                    }
-                    updatedPkg.pkg = pkg;
-                    mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
-                    return null;
-                } else {
-                    // The current app on the system partion is better than
-                    // what we have updated to on the data partition; switch
-                    // back to the system partition version.
-                    // At this point, its safely assumed that package installation for
-                    // apps in system partition will go through. If not there won't be a working
-                    // version of the app
-                    // writer
-                    synchronized (mPackages) {
-                        // Just remove the loaded entries from package lists.
-                        mPackages.remove(ps.name);
-                    }
-                    Slog.w(TAG, "Package " + ps.name + " at " + scanFile
-                            + "reverting from " + ps.codePathString
-                            + ": new version " + pkg.mVersionCode
-                            + " better than installed " + ps.versionCode);
-
-                    InstallArgs args = createInstallArgs(packageFlagsToInstallFlags(ps),
-                            ps.codePathString, ps.resourcePathString, ps.nativeLibraryPathString);
-                    synchronized (mInstallLock) {
-                        args.cleanUpResourcesLI();
-                    }
-                    synchronized (mPackages) {
-                        mSettings.enableSystemPackageLPw(ps.name);
-                    }
-                }
-            }
-        }
-
-        if (updatedPkg != null) {
-            // An updated system app will not have the PARSE_IS_SYSTEM flag set
-            // initially
-            parseFlags |= PackageParser.PARSE_IS_SYSTEM;
-
-            // An updated privileged app will not have the PARSE_IS_PRIVILEGED
-            // flag set initially
-            if ((updatedPkg.pkgFlags & ApplicationInfo.FLAG_PRIVILEGED) != 0) {
-                parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
-            }
-        }
-        // Verify certificates against what was last scanned
-        if (!collectCertificatesLI(pp, ps, pkg, scanFile, parseFlags)) {
-            Slog.w(TAG, "Failed verifying certificates for package:" + pkg.packageName);
-            return null;
-        }
-
-        /*
-         * A new system app appeared, but we already had a non-system one of the
-         * same name installed earlier.
-         */
-        boolean shouldHideSystemApp = false;
-        if (updatedPkg == null && ps != null
-                && (parseFlags & PackageParser.PARSE_IS_SYSTEM_DIR) != 0 && !isSystemApp(ps)) {
-            /*
-             * Check to make sure the signatures match first. If they don't,
-             * wipe the installed application and its data.
-             */
-            if (compareSignatures(ps.signatures.mSignatures, pkg.mSignatures)
-                    != PackageManager.SIGNATURE_MATCH) {
-                if (DEBUG_INSTALL) Slog.d(TAG, "Signature mismatch!");
-                deletePackageLI(pkg.packageName, null, true, null, null, 0, null, false);
-                ps = null;
-            } else {
-                /*
-                 * If the newly-added system app is an older version than the
-                 * already installed version, hide it. It will be scanned later
-                 * and re-added like an update.
-                 */
-                if (pkg.mVersionCode < ps.versionCode) {
-                    shouldHideSystemApp = true;
-                } else {
-                    /*
-                     * The newly found system app is a newer version that the
-                     * one previously installed. Simply remove the
-                     * already-installed application and replace it with our own
-                     * while keeping the application data.
-                     */
-                    Slog.w(TAG, "Package " + ps.name + " at " + scanFile + "reverting from "
-                            + ps.codePathString + ": new version " + pkg.mVersionCode
-                            + " better than installed " + ps.versionCode);
-                    InstallArgs args = createInstallArgs(packageFlagsToInstallFlags(ps),
-                            ps.codePathString, ps.resourcePathString, ps.nativeLibraryPathString);
-                    synchronized (mInstallLock) {
-                        args.cleanUpResourcesLI();
-                    }
-                }
-            }
-        }
-
-        // The apk is forward locked (not public) if its code and resources
-        // are kept in different files. (except for app in either system or
-        // vendor path).
-        // TODO grab this value from PackageSettings
-        if ((parseFlags & PackageParser.PARSE_IS_SYSTEM_DIR) == 0) {
-            if (ps != null && !ps.codePath.equals(ps.resourcePath)) {
-                parseFlags |= PackageParser.PARSE_FORWARD_LOCK;
-            }
-        }
-
-        String codePath = null;
-        String resPath = null;
-        if ((parseFlags & PackageParser.PARSE_FORWARD_LOCK) != 0) {
-            if (ps != null && ps.resourcePathString != null) {
-                resPath = ps.resourcePathString;
-            } else {
-                // Should not happen at all. Just log an error.
-                Slog.e(TAG, "Resource path not set for pkg : " + pkg.packageName);
-            }
-        } else {
-            resPath = pkg.mScanPath;
-        }
-
-        codePath = pkg.mScanPath;
-        // Set application objects path explicitly.
-        setApplicationInfoPaths(pkg, codePath, resPath);
-        // Note that we invoke the following method only if we are about to unpack an application
-        PackageParser.Package scannedPkg = scanPackageLI(pkg, parseFlags, scanMode
-                | SCAN_UPDATE_SIGNATURE, currentTime, user);
-
-        /*
-         * If the system app should be overridden by a previously installed
-         * data, hide the system app now and let the /data/app scan pick it up
-         * again.
-         */
-        if (shouldHideSystemApp) {
-            synchronized (mPackages) {
-                /*
-                 * We have to grant systems permissions before we hide, because
-                 * grantPermissions will assume the package update is trying to
-                 * expand its permissions.
-                 */
-                grantPermissionsLPw(pkg, true);
-                mSettings.disableSystemPackageLPw(pkg.packageName);
-            }
-        }
-
-        return scannedPkg;
-    }
-
-    private static void setApplicationInfoPaths(PackageParser.Package pkg, String destCodePath,
-            String destResPath) {
-        pkg.mPath = pkg.mScanPath = destCodePath;
-        pkg.applicationInfo.sourceDir = destCodePath;
-        pkg.applicationInfo.publicSourceDir = destResPath;
-    }
-
-    private static String fixProcessName(String defProcessName,
-            String processName, int uid) {
-        if (processName == null) {
-            return defProcessName;
-        }
-        return processName;
-    }
-
-    private boolean verifySignaturesLP(PackageSetting pkgSetting,
-            PackageParser.Package pkg) {
-        if (pkgSetting.signatures.mSignatures != null) {
-            // Already existing package. Make sure signatures match
-            if (compareSignatures(pkgSetting.signatures.mSignatures, pkg.mSignatures) !=
-                PackageManager.SIGNATURE_MATCH) {
-                    Slog.e(TAG, "Package " + pkg.packageName
-                            + " signatures do not match the previously installed version; ignoring!");
-                    mLastScanError = PackageManager.INSTALL_FAILED_UPDATE_INCOMPATIBLE;
-                    return false;
-                }
-        }
-        // Check for shared user signatures
-        if (pkgSetting.sharedUser != null && pkgSetting.sharedUser.signatures.mSignatures != null) {
-            if (compareSignatures(pkgSetting.sharedUser.signatures.mSignatures,
-                    pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
-                Slog.e(TAG, "Package " + pkg.packageName
-                        + " has no signatures that match those in shared user "
-                        + pkgSetting.sharedUser.name + "; ignoring!");
-                mLastScanError = PackageManager.INSTALL_FAILED_SHARED_USER_INCOMPATIBLE;
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Enforces that only the system UID or root's UID can call a method exposed
-     * via Binder.
-     *
-     * @param message used as message if SecurityException is thrown
-     * @throws SecurityException if the caller is not system or root
-     */
-    private static final void enforceSystemOrRoot(String message) {
-        final int uid = Binder.getCallingUid();
-        if (uid != Process.SYSTEM_UID && uid != 0) {
-            throw new SecurityException(message);
-        }
-    }
-
-    public void performBootDexOpt() {
-        HashSet<PackageParser.Package> pkgs = null;
-        synchronized (mPackages) {
-            pkgs = mDeferredDexOpt;
-            mDeferredDexOpt = null;
-        }
-        if (pkgs != null) {
-            int i = 0;
-            for (PackageParser.Package pkg : pkgs) {
-                if (!isFirstBoot()) {
-                    i++;
-                    try {
-                        ActivityManagerNative.getDefault().showBootMessage(
-                                mContext.getResources().getString(
-                                        com.android.internal.R.string.android_upgrading_apk,
-                                        i, pkgs.size()), true);
-                    } catch (RemoteException e) {
-                    }
-                }
-                PackageParser.Package p = pkg;
-                synchronized (mInstallLock) {
-                    if (!p.mDidDexOpt) {
-                        performDexOptLI(p, false, false, true);
-                    }
-                }
-            }
-        }
-    }
-
-    public boolean performDexOpt(String packageName) {
-        enforceSystemOrRoot("Only the system can request dexopt be performed");
-
-        if (!mNoDexOpt) {
-            return false;
-        }
-
-        PackageParser.Package p;
-        synchronized (mPackages) {
-            p = mPackages.get(packageName);
-            if (p == null || p.mDidDexOpt) {
-                return false;
-            }
-        }
-        synchronized (mInstallLock) {
-            return performDexOptLI(p, false, false, true) == DEX_OPT_PERFORMED;
-        }
-    }
-
-    private void performDexOptLibsLI(ArrayList<String> libs, boolean forceDex, boolean defer,
-            HashSet<String> done) {
-        for (int i=0; i<libs.size(); i++) {
-            PackageParser.Package libPkg;
-            String libName;
-            synchronized (mPackages) {
-                libName = libs.get(i);
-                SharedLibraryEntry lib = mSharedLibraries.get(libName);
-                if (lib != null && lib.apk != null) {
-                    libPkg = mPackages.get(lib.apk);
-                } else {
-                    libPkg = null;
-                }
-            }
-            if (libPkg != null && !done.contains(libName)) {
-                performDexOptLI(libPkg, forceDex, defer, done);
-            }
-        }
-    }
-
-    static final int DEX_OPT_SKIPPED = 0;
-    static final int DEX_OPT_PERFORMED = 1;
-    static final int DEX_OPT_DEFERRED = 2;
-    static final int DEX_OPT_FAILED = -1;
-
-    private int performDexOptLI(PackageParser.Package pkg, boolean forceDex, boolean defer,
-            HashSet<String> done) {
-        boolean performed = false;
-        if (done != null) {
-            done.add(pkg.packageName);
-            if (pkg.usesLibraries != null) {
-                performDexOptLibsLI(pkg.usesLibraries, forceDex, defer, done);
-            }
-            if (pkg.usesOptionalLibraries != null) {
-                performDexOptLibsLI(pkg.usesOptionalLibraries, forceDex, defer, done);
-            }
-        }
-        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) {
-            String path = pkg.mScanPath;
-            int ret = 0;
-            try {
-                if (forceDex || dalvik.system.DexFile.isDexOptNeeded(path)) {
-                    if (!forceDex && defer) {
-                        if (mDeferredDexOpt == null) {
-                            mDeferredDexOpt = new HashSet<PackageParser.Package>();
-                        }
-                        mDeferredDexOpt.add(pkg);
-                        return DEX_OPT_DEFERRED;
-                    } else {
-                        Log.i(TAG, "Running dexopt on: " + pkg.applicationInfo.packageName);
-                        final int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
-                        ret = mInstaller.dexopt(path, sharedGid, !isForwardLocked(pkg));
-                        pkg.mDidDexOpt = true;
-                        performed = true;
-                    }
-                }
-            } catch (FileNotFoundException e) {
-                Slog.w(TAG, "Apk not found for dexopt: " + path);
-                ret = -1;
-            } catch (IOException e) {
-                Slog.w(TAG, "IOException reading apk: " + path, e);
-                ret = -1;
-            } catch (dalvik.system.StaleDexCacheError e) {
-                Slog.w(TAG, "StaleDexCacheError when reading apk: " + path, e);
-                ret = -1;
-            } catch (Exception e) {
-                Slog.w(TAG, "Exception when doing dexopt : ", e);
-                ret = -1;
-            }
-            if (ret < 0) {
-                //error from installer
-                return DEX_OPT_FAILED;
-            }
-        }
-
-        return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED;
-    }
-
-    private int performDexOptLI(PackageParser.Package pkg, boolean forceDex, boolean defer,
-            boolean inclDependencies) {
-        HashSet<String> done;
-        boolean performed = false;
-        if (inclDependencies && (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null)) {
-            done = new HashSet<String>();
-            done.add(pkg.packageName);
-        } else {
-            done = null;
-        }
-        return performDexOptLI(pkg, forceDex, defer, done);
-    }
-
-    private boolean verifyPackageUpdateLPr(PackageSetting oldPkg, PackageParser.Package newPkg) {
-        if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
-            Slog.w(TAG, "Unable to update from " + oldPkg.name
-                    + " to " + newPkg.packageName
-                    + ": old package not in system partition");
-            return false;
-        } else if (mPackages.get(oldPkg.name) != null) {
-            Slog.w(TAG, "Unable to update from " + oldPkg.name
-                    + " to " + newPkg.packageName
-                    + ": old package still exists");
-            return false;
-        }
-        return true;
-    }
-
-    File getDataPathForUser(int userId) {
-        return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId);
-    }
-
-    private File getDataPathForPackage(String packageName, int userId) {
-        /*
-         * Until we fully support multiple users, return the directory we
-         * previously would have. The PackageManagerTests will need to be
-         * revised when this is changed back..
-         */
-        if (userId == 0) {
-            return new File(mAppDataDir, packageName);
-        } else {
-            return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId
-                + File.separator + packageName);
-        }
-    }
-
-    private int createDataDirsLI(String packageName, int uid, String seinfo) {
-        int[] users = sUserManager.getUserIds();
-        int res = mInstaller.install(packageName, uid, uid, seinfo);
-        if (res < 0) {
-            return res;
-        }
-        for (int user : users) {
-            if (user != 0) {
-                res = mInstaller.createUserData(packageName,
-                        UserHandle.getUid(user, uid), user);
-                if (res < 0) {
-                    return res;
-                }
-            }
-        }
-        return res;
-    }
-
-    private int removeDataDirsLI(String packageName) {
-        int[] users = sUserManager.getUserIds();
-        int res = 0;
-        for (int user : users) {
-            int resInner = mInstaller.remove(packageName, user);
-            if (resInner < 0) {
-                res = resInner;
-            }
-        }
-
-        final File nativeLibraryFile = new File(mAppLibInstallDir, packageName);
-        NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryFile);
-        if (!nativeLibraryFile.delete()) {
-            Slog.w(TAG, "Couldn't delete native library directory " + nativeLibraryFile.getPath());
-        }
-
-        return res;
-    }
-
-    private int addSharedLibraryLPw(final SharedLibraryEntry file, int num,
-            PackageParser.Package changingLib) {
-        if (file.path != null) {
-            mTmpSharedLibraries[num] = file.path;
-            return num+1;
-        }
-        PackageParser.Package p = mPackages.get(file.apk);
-        if (changingLib != null && changingLib.packageName.equals(file.apk)) {
-            // If we are doing this while in the middle of updating a library apk,
-            // then we need to make sure to use that new apk for determining the
-            // dependencies here.  (We haven't yet finished committing the new apk
-            // to the package manager state.)
-            if (p == null || p.packageName.equals(changingLib.packageName)) {
-                p = changingLib;
-            }
-        }
-        if (p != null) {
-            String path = p.mPath;
-            for (int i=0; i<num; i++) {
-                if (mTmpSharedLibraries[i].equals(path)) {
-                    return num;
-                }
-            }
-            mTmpSharedLibraries[num] = p.mPath;
-            return num+1;
-        }
-        return num;
-    }
-
-    private boolean updateSharedLibrariesLPw(PackageParser.Package pkg,
-            PackageParser.Package changingLib) {
-        if (pkg.usesLibraries != null || pkg.usesOptionalLibraries != null) {
-            if (mTmpSharedLibraries == null ||
-                    mTmpSharedLibraries.length < mSharedLibraries.size()) {
-                mTmpSharedLibraries = new String[mSharedLibraries.size()];
-            }
-            int num = 0;
-            int N = pkg.usesLibraries != null ? pkg.usesLibraries.size() : 0;
-            for (int i=0; i<N; i++) {
-                final SharedLibraryEntry file = mSharedLibraries.get(pkg.usesLibraries.get(i));
-                if (file == null) {
-                    Slog.e(TAG, "Package " + pkg.packageName
-                            + " requires unavailable shared library "
-                            + pkg.usesLibraries.get(i) + "; failing!");
-                    mLastScanError = PackageManager.INSTALL_FAILED_MISSING_SHARED_LIBRARY;
-                    return false;
-                }
-                num = addSharedLibraryLPw(file, num, changingLib);
-            }
-            N = pkg.usesOptionalLibraries != null ? pkg.usesOptionalLibraries.size() : 0;
-            for (int i=0; i<N; i++) {
-                final SharedLibraryEntry file = mSharedLibraries.get(pkg.usesOptionalLibraries.get(i));
-                if (file == null) {
-                    Slog.w(TAG, "Package " + pkg.packageName
-                            + " desires unavailable shared library "
-                            + pkg.usesOptionalLibraries.get(i) + "; ignoring!");
-                } else {
-                    num = addSharedLibraryLPw(file, num, changingLib);
-                }
-            }
-            if (num > 0) {
-                pkg.usesLibraryFiles = new String[num];
-                System.arraycopy(mTmpSharedLibraries, 0,
-                        pkg.usesLibraryFiles, 0, num);
-            } else {
-                pkg.usesLibraryFiles = null;
-            }
-        }
-        return true;
-    }
-
-    private static boolean hasString(List<String> list, List<String> which) {
-        if (list == null) {
-            return false;
-        }
-        for (int i=list.size()-1; i>=0; i--) {
-            for (int j=which.size()-1; j>=0; j--) {
-                if (which.get(j).equals(list.get(i))) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    private void updateAllSharedLibrariesLPw() {
-        for (PackageParser.Package pkg : mPackages.values()) {
-            updateSharedLibrariesLPw(pkg, null);
-        }
-    }
-
-    private ArrayList<PackageParser.Package> updateAllSharedLibrariesLPw(
-            PackageParser.Package changingPkg) {
-        ArrayList<PackageParser.Package> res = null;
-        for (PackageParser.Package pkg : mPackages.values()) {
-            if (hasString(pkg.usesLibraries, changingPkg.libraryNames)
-                    || hasString(pkg.usesOptionalLibraries, changingPkg.libraryNames)) {
-                if (res == null) {
-                    res = new ArrayList<PackageParser.Package>();
-                }
-                res.add(pkg);
-                updateSharedLibrariesLPw(pkg, changingPkg);
-            }
-        }
-        return res;
-    }
-
-    private PackageParser.Package scanPackageLI(PackageParser.Package pkg,
-            int parseFlags, int scanMode, long currentTime, UserHandle user) {
-        File scanFile = new File(pkg.mScanPath);
-        if (scanFile == null || pkg.applicationInfo.sourceDir == null ||
-                pkg.applicationInfo.publicSourceDir == null) {
-            // Bail out. The resource and code paths haven't been set.
-            Slog.w(TAG, " Code and resource paths haven't been set correctly");
-            mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK;
-            return null;
-        }
-
-        if ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
-            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SYSTEM;
-        }
-
-        if ((parseFlags&PackageParser.PARSE_IS_PRIVILEGED) != 0) {
-            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_PRIVILEGED;
-        }
-
-        if (mCustomResolverComponentName != null &&
-                mCustomResolverComponentName.getPackageName().equals(pkg.packageName)) {
-            setUpCustomResolverActivity(pkg);
-        }
-
-        if (pkg.packageName.equals("android")) {
-            synchronized (mPackages) {
-                if (mAndroidApplication != null) {
-                    Slog.w(TAG, "*************************************************");
-                    Slog.w(TAG, "Core android package being redefined.  Skipping.");
-                    Slog.w(TAG, " file=" + scanFile);
-                    Slog.w(TAG, "*************************************************");
-                    mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
-                    return null;
-                }
-
-                // Set up information for our fall-back user intent resolution activity.
-                mPlatformPackage = pkg;
-                pkg.mVersionCode = mSdkVersion;
-                mAndroidApplication = pkg.applicationInfo;
-
-                if (!mResolverReplaced) {
-                    mResolveActivity.applicationInfo = mAndroidApplication;
-                    mResolveActivity.name = ResolverActivity.class.getName();
-                    mResolveActivity.packageName = mAndroidApplication.packageName;
-                    mResolveActivity.processName = "system:ui";
-                    mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
-                    mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
-                    mResolveActivity.theme = com.android.internal.R.style.Theme_Holo_Dialog_Alert;
-                    mResolveActivity.exported = true;
-                    mResolveActivity.enabled = true;
-                    mResolveInfo.activityInfo = mResolveActivity;
-                    mResolveInfo.priority = 0;
-                    mResolveInfo.preferredOrder = 0;
-                    mResolveInfo.match = 0;
-                    mResolveComponentName = new ComponentName(
-                            mAndroidApplication.packageName, mResolveActivity.name);
-                }
-            }
-        }
-
-        if (DEBUG_PACKAGE_SCANNING) {
-            if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
-                Log.d(TAG, "Scanning package " + pkg.packageName);
-        }
-
-        if (mPackages.containsKey(pkg.packageName)
-                || mSharedLibraries.containsKey(pkg.packageName)) {
-            Slog.w(TAG, "Application package " + pkg.packageName
-                    + " already installed.  Skipping duplicate.");
-            mLastScanError = PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
-            return null;
-        }
-
-        // Initialize package source and resource directories
-        File destCodeFile = new File(pkg.applicationInfo.sourceDir);
-        File destResourceFile = new File(pkg.applicationInfo.publicSourceDir);
-
-        SharedUserSetting suid = null;
-        PackageSetting pkgSetting = null;
-
-        if (!isSystemApp(pkg)) {
-            // Only system apps can use these features.
-            pkg.mOriginalPackages = null;
-            pkg.mRealPackage = null;
-            pkg.mAdoptPermissions = null;
-        }
-
-        // writer
-        synchronized (mPackages) {
-            if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) {
-                // Check all shared libraries and map to their actual file path.
-                // We only do this here for apps not on a system dir, because those
-                // are the only ones that can fail an install due to this.  We
-                // will take care of the system apps by updating all of their
-                // library paths after the scan is done.
-                if (!updateSharedLibrariesLPw(pkg, null)) {
-                    return null;
-                }
-            }
-
-            if (pkg.mSharedUserId != null) {
-                suid = mSettings.getSharedUserLPw(pkg.mSharedUserId, 0, true);
-                if (suid == null) {
-                    Slog.w(TAG, "Creating application package " + pkg.packageName
-                            + " for shared user failed");
-                    mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                    return null;
-                }
-                if (DEBUG_PACKAGE_SCANNING) {
-                    if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
-                        Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" + suid.userId
-                                + "): packages=" + suid.packages);
-                }
-            }
-            
-            // Check if we are renaming from an original package name.
-            PackageSetting origPackage = null;
-            String realName = null;
-            if (pkg.mOriginalPackages != null) {
-                // This package may need to be renamed to a previously
-                // installed name.  Let's check on that...
-                final String renamed = mSettings.mRenamedPackages.get(pkg.mRealPackage);
-                if (pkg.mOriginalPackages.contains(renamed)) {
-                    // This package had originally been installed as the
-                    // original name, and we have already taken care of
-                    // transitioning to the new one.  Just update the new
-                    // one to continue using the old name.
-                    realName = pkg.mRealPackage;
-                    if (!pkg.packageName.equals(renamed)) {
-                        // Callers into this function may have already taken
-                        // care of renaming the package; only do it here if
-                        // it is not already done.
-                        pkg.setPackageName(renamed);
-                    }
-                    
-                } else {
-                    for (int i=pkg.mOriginalPackages.size()-1; i>=0; i--) {
-                        if ((origPackage = mSettings.peekPackageLPr(
-                                pkg.mOriginalPackages.get(i))) != null) {
-                            // We do have the package already installed under its
-                            // original name...  should we use it?
-                            if (!verifyPackageUpdateLPr(origPackage, pkg)) {
-                                // New package is not compatible with original.
-                                origPackage = null;
-                                continue;
-                            } else if (origPackage.sharedUser != null) {
-                                // Make sure uid is compatible between packages.
-                                if (!origPackage.sharedUser.name.equals(pkg.mSharedUserId)) {
-                                    Slog.w(TAG, "Unable to migrate data from " + origPackage.name
-                                            + " to " + pkg.packageName + ": old uid "
-                                            + origPackage.sharedUser.name
-                                            + " differs from " + pkg.mSharedUserId);
-                                    origPackage = null;
-                                    continue;
-                                }
-                            } else {
-                                if (DEBUG_UPGRADE) Log.v(TAG, "Renaming new package "
-                                        + pkg.packageName + " to old name " + origPackage.name);
-                            }
-                            break;
-                        }
-                    }
-                }
-            }
-            
-            if (mTransferedPackages.contains(pkg.packageName)) {
-                Slog.w(TAG, "Package " + pkg.packageName
-                        + " was transferred to another, but its .apk remains");
-            }
-            
-            // Just create the setting, don't add it yet. For already existing packages
-            // the PkgSetting exists already and doesn't have to be created.
-            pkgSetting = mSettings.getPackageLPw(pkg, origPackage, realName, suid, destCodeFile,
-                    destResourceFile, pkg.applicationInfo.nativeLibraryDir,
-                    pkg.applicationInfo.flags, user, false);
-            if (pkgSetting == null) {
-                Slog.w(TAG, "Creating application package " + pkg.packageName + " failed");
-                mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                return null;
-            }
-            
-            if (pkgSetting.origPackage != null) {
-                // If we are first transitioning from an original package,
-                // fix up the new package's name now.  We need to do this after
-                // looking up the package under its new name, so getPackageLP
-                // can take care of fiddling things correctly.
-                pkg.setPackageName(origPackage.name);
-                
-                // File a report about this.
-                String msg = "New package " + pkgSetting.realName
-                        + " renamed to replace old package " + pkgSetting.name;
-                reportSettingsProblem(Log.WARN, msg);
-                
-                // Make a note of it.
-                mTransferedPackages.add(origPackage.name);
-                
-                // No longer need to retain this.
-                pkgSetting.origPackage = null;
-            }
-            
-            if (realName != null) {
-                // Make a note of it.
-                mTransferedPackages.add(pkg.packageName);
-            }
-            
-            if (mSettings.isDisabledSystemPackageLPr(pkg.packageName)) {
-                pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
-            }
-
-            if (mFoundPolicyFile) {
-                SELinuxMMAC.assignSeinfoValue(pkg);
-            }
-
-            pkg.applicationInfo.uid = pkgSetting.appId;
-            pkg.mExtras = pkgSetting;
-
-            if (!verifySignaturesLP(pkgSetting, pkg)) {
-                if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) == 0) {
-                    return null;
-                }
-                // The signature has changed, but this package is in the system
-                // image...  let's recover!
-                pkgSetting.signatures.mSignatures = pkg.mSignatures;
-                // However...  if this package is part of a shared user, but it
-                // doesn't match the signature of the shared user, let's fail.
-                // What this means is that you can't change the signatures
-                // associated with an overall shared user, which doesn't seem all
-                // that unreasonable.
-                if (pkgSetting.sharedUser != null) {
-                    if (compareSignatures(pkgSetting.sharedUser.signatures.mSignatures,
-                            pkg.mSignatures) != PackageManager.SIGNATURE_MATCH) {
-                        Log.w(TAG, "Signature mismatch for shared user : " + pkgSetting.sharedUser);
-                        mLastScanError = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
-                        return null;
-                    }
-                }
-                // File a report about this.
-                String msg = "System package " + pkg.packageName
-                        + " signature changed; retaining data.";
-                reportSettingsProblem(Log.WARN, msg);
-            }
-
-            // Verify that this new package doesn't have any content providers
-            // that conflict with existing packages.  Only do this if the
-            // package isn't already installed, since we don't want to break
-            // things that are installed.
-            if ((scanMode&SCAN_NEW_INSTALL) != 0) {
-                final int N = pkg.providers.size();
-                int i;
-                for (i=0; i<N; i++) {
-                    PackageParser.Provider p = pkg.providers.get(i);
-                    if (p.info.authority != null) {
-                        String names[] = p.info.authority.split(";");
-                        for (int j = 0; j < names.length; j++) {
-                            if (mProvidersByAuthority.containsKey(names[j])) {
-                                PackageParser.Provider other = mProvidersByAuthority.get(names[j]);
-                                Slog.w(TAG, "Can't install because provider name " + names[j] +
-                                        " (in package " + pkg.applicationInfo.packageName +
-                                        ") is already used by "
-                                        + ((other != null && other.getComponentName() != null)
-                                                ? other.getComponentName().getPackageName() : "?"));
-                                mLastScanError = PackageManager.INSTALL_FAILED_CONFLICTING_PROVIDER;
-                                return null;
-                            }
-                        }
-                    }
-                }
-            }
-
-            if (pkg.mAdoptPermissions != null) {
-                // This package wants to adopt ownership of permissions from
-                // another package.
-                for (int i = pkg.mAdoptPermissions.size() - 1; i >= 0; i--) {
-                    final String origName = pkg.mAdoptPermissions.get(i);
-                    final PackageSetting orig = mSettings.peekPackageLPr(origName);
-                    if (orig != null) {
-                        if (verifyPackageUpdateLPr(orig, pkg)) {
-                            Slog.i(TAG, "Adopting permissions from " + origName + " to "
-                                    + pkg.packageName);
-                            mSettings.transferPermissionsLPw(origName, pkg.packageName);
-                        }
-                    }
-                }
-            }
-        }
-
-        final String pkgName = pkg.packageName;
-        
-        final long scanFileTime = scanFile.lastModified();
-        final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0;
-        pkg.applicationInfo.processName = fixProcessName(
-                pkg.applicationInfo.packageName,
-                pkg.applicationInfo.processName,
-                pkg.applicationInfo.uid);
-
-        File dataPath;
-        if (mPlatformPackage == pkg) {
-            // The system package is special.
-            dataPath = new File (Environment.getDataDirectory(), "system");
-            pkg.applicationInfo.dataDir = dataPath.getPath();
-        } else {
-            // This is a normal package, need to make its data directory.
-            dataPath = getDataPathForPackage(pkg.packageName, 0);
-
-            boolean uidError = false;
-
-            if (dataPath.exists()) {
-                int currentUid = 0;
-                try {
-                    StructStat stat = Libcore.os.stat(dataPath.getPath());
-                    currentUid = stat.st_uid;
-                } catch (ErrnoException e) {
-                    Slog.e(TAG, "Couldn't stat path " + dataPath.getPath(), e);
-                }
-
-                // If we have mismatched owners for the data path, we have a problem.
-                if (currentUid != pkg.applicationInfo.uid) {
-                    boolean recovered = false;
-                    if (currentUid == 0) {
-                        // The directory somehow became owned by root.  Wow.
-                        // This is probably because the system was stopped while
-                        // installd was in the middle of messing with its libs
-                        // directory.  Ask installd to fix that.
-                        int ret = mInstaller.fixUid(pkgName, pkg.applicationInfo.uid,
-                                pkg.applicationInfo.uid);
-                        if (ret >= 0) {
-                            recovered = true;
-                            String msg = "Package " + pkg.packageName
-                                    + " unexpectedly changed to uid 0; recovered to " +
-                                    + pkg.applicationInfo.uid;
-                            reportSettingsProblem(Log.WARN, msg);
-                        }
-                    }
-                    if (!recovered && ((parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0
-                            || (scanMode&SCAN_BOOTING) != 0)) {
-                        // If this is a system app, we can at least delete its
-                        // current data so the application will still work.
-                        int ret = removeDataDirsLI(pkgName);
-                        if (ret >= 0) {
-                            // TODO: Kill the processes first
-                            // Old data gone!
-                            String prefix = (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0
-                                    ? "System package " : "Third party package ";
-                            String msg = prefix + pkg.packageName
-                                    + " has changed from uid: "
-                                    + currentUid + " to "
-                                    + pkg.applicationInfo.uid + "; old data erased";
-                            reportSettingsProblem(Log.WARN, msg);
-                            recovered = true;
-
-                            // And now re-install the app.
-                            ret = createDataDirsLI(pkgName, pkg.applicationInfo.uid,
-                                                   pkg.applicationInfo.seinfo);
-                            if (ret == -1) {
-                                // Ack should not happen!
-                                msg = prefix + pkg.packageName
-                                        + " could not have data directory re-created after delete.";
-                                reportSettingsProblem(Log.WARN, msg);
-                                mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                                return null;
-                            }
-                        }
-                        if (!recovered) {
-                            mHasSystemUidErrors = true;
-                        }
-                    } else if (!recovered) {
-                        // If we allow this install to proceed, we will be broken.
-                        // Abort, abort!
-                        mLastScanError = PackageManager.INSTALL_FAILED_UID_CHANGED;
-                        return null;
-                    }
-                    if (!recovered) {
-                        pkg.applicationInfo.dataDir = "/mismatched_uid/settings_"
-                            + pkg.applicationInfo.uid + "/fs_"
-                            + currentUid;
-                        pkg.applicationInfo.nativeLibraryDir = pkg.applicationInfo.dataDir;
-                        String msg = "Package " + pkg.packageName
-                                + " has mismatched uid: "
-                                + currentUid + " on disk, "
-                                + pkg.applicationInfo.uid + " in settings";
-                        // writer
-                        synchronized (mPackages) {
-                            mSettings.mReadMessages.append(msg);
-                            mSettings.mReadMessages.append('\n');
-                            uidError = true;
-                            if (!pkgSetting.uidError) {
-                                reportSettingsProblem(Log.ERROR, msg);
-                            }
-                        }
-                    }
-                }
-                pkg.applicationInfo.dataDir = dataPath.getPath();
-            } else {
-                if (DEBUG_PACKAGE_SCANNING) {
-                    if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
-                        Log.v(TAG, "Want this data dir: " + dataPath);
-                }
-                //invoke installer to do the actual installation
-                int ret = createDataDirsLI(pkgName, pkg.applicationInfo.uid,
-                                           pkg.applicationInfo.seinfo);
-                if (ret < 0) {
-                    // Error from installer
-                    mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                    return null;
-                }
-
-                if (dataPath.exists()) {
-                    pkg.applicationInfo.dataDir = dataPath.getPath();
-                } else {
-                    Slog.w(TAG, "Unable to create data directory: " + dataPath);
-                    pkg.applicationInfo.dataDir = null;
-                }
-            }
-
-            /*
-             * Set the data dir to the default "/data/data/<package name>/lib"
-             * if we got here without anyone telling us different (e.g., apps
-             * stored on SD card have their native libraries stored in the ASEC
-             * container with the APK).
-             *
-             * This happens during an upgrade from a package settings file that
-             * doesn't have a native library path attribute at all.
-             */
-            if (pkg.applicationInfo.nativeLibraryDir == null && pkg.applicationInfo.dataDir != null) {
-                if (pkgSetting.nativeLibraryPathString == null) {
-                    setInternalAppNativeLibraryPath(pkg, pkgSetting);
-                } else {
-                    pkg.applicationInfo.nativeLibraryDir = pkgSetting.nativeLibraryPathString;
-                }
-            }
-
-            pkgSetting.uidError = uidError;
-        }
-
-        String path = scanFile.getPath();
-        /* Note: We don't want to unpack the native binaries for
-         *        system applications, unless they have been updated
-         *        (the binaries are already under /system/lib).
-         *        Also, don't unpack libs for apps on the external card
-         *        since they should have their libraries in the ASEC
-         *        container already.
-         *
-         *        In other words, we're going to unpack the binaries
-         *        only for non-system apps and system app upgrades.
-         */
-        if (pkg.applicationInfo.nativeLibraryDir != null) {
-            try {
-                File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
-                final String dataPathString = dataPath.getCanonicalPath();
-
-                if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) {
-                    /*
-                     * Upgrading from a previous version of the OS sometimes
-                     * leaves native libraries in the /data/data/<app>/lib
-                     * directory for system apps even when they shouldn't be.
-                     * Recent changes in the JNI library search path
-                     * necessitates we remove those to match previous behavior.
-                     */
-                    if (NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryDir)) {
-                        Log.i(TAG, "removed obsolete native libraries for system package "
-                                + path);
-                    }
-                } else {
-                    if (!isForwardLocked(pkg) && !isExternal(pkg)) {
-                        /*
-                         * Update native library dir if it starts with
-                         * /data/data
-                         */
-                        if (nativeLibraryDir.getPath().startsWith(dataPathString)) {
-                            setInternalAppNativeLibraryPath(pkg, pkgSetting);
-                            nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
-                        }
-
-                        try {
-                            if (copyNativeLibrariesForInternalApp(scanFile, nativeLibraryDir) != PackageManager.INSTALL_SUCCEEDED) {
-                                Slog.e(TAG, "Unable to copy native libraries");
-                                mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-                                return null;
-                            }
-                        } catch (IOException e) {
-                            Slog.e(TAG, "Unable to copy native libraries", e);
-                            mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-                            return null;
-                        }
-                    }
-
-                    if (DEBUG_INSTALL) Slog.i(TAG, "Linking native library dir for " + path);
-                    final int[] userIds = sUserManager.getUserIds();
-                    synchronized (mInstallLock) {
-                        for (int userId : userIds) {
-                            if (mInstaller.linkNativeLibraryDirectory(pkg.packageName,
-                                    pkg.applicationInfo.nativeLibraryDir, userId) < 0) {
-                                Slog.w(TAG, "Failed linking native library dir (user=" + userId
-                                        + ")");
-                                mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-                                return null;
-                            }
-                        }
-                    }
-                }
-            } catch (IOException ioe) {
-                Slog.e(TAG, "Unable to get canonical file " + ioe.toString());
-            }
-        }
-        pkg.mScanPath = path;
-
-        if ((scanMode&SCAN_NO_DEX) == 0) {
-            if (performDexOptLI(pkg, forceDex, (scanMode&SCAN_DEFER_DEX) != 0, false)
-                    == DEX_OPT_FAILED) {
-                if ((scanMode & SCAN_DELETE_DATA_ON_FAILURES) != 0) {
-                    removeDataDirsLI(pkg.packageName);
-                }
-
-                mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT;
-                return null;
-            }
-        }
-
-        if (mFactoryTest && pkg.requestedPermissions.contains(
-                android.Manifest.permission.FACTORY_TEST)) {
-            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_FACTORY_TEST;
-        }
-
-        ArrayList<PackageParser.Package> clientLibPkgs = null;
-
-        // writer
-        synchronized (mPackages) {
-            if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
-                // Only system apps can add new shared libraries.
-                if (pkg.libraryNames != null) {
-                    for (int i=0; i<pkg.libraryNames.size(); i++) {
-                        String name = pkg.libraryNames.get(i);
-                        boolean allowed = false;
-                        if (isUpdatedSystemApp(pkg)) {
-                            // New library entries can only be added through the
-                            // system image.  This is important to get rid of a lot
-                            // of nasty edge cases: for example if we allowed a non-
-                            // system update of the app to add a library, then uninstalling
-                            // the update would make the library go away, and assumptions
-                            // we made such as through app install filtering would now
-                            // have allowed apps on the device which aren't compatible
-                            // with it.  Better to just have the restriction here, be
-                            // conservative, and create many fewer cases that can negatively
-                            // impact the user experience.
-                            final PackageSetting sysPs = mSettings
-                                    .getDisabledSystemPkgLPr(pkg.packageName);
-                            if (sysPs.pkg != null && sysPs.pkg.libraryNames != null) {
-                                for (int j=0; j<sysPs.pkg.libraryNames.size(); j++) {
-                                    if (name.equals(sysPs.pkg.libraryNames.get(j))) {
-                                        allowed = true;
-                                        allowed = true;
-                                        break;
-                                    }
-                                }
-                            }
-                        } else {
-                            allowed = true;
-                        }
-                        if (allowed) {
-                            if (!mSharedLibraries.containsKey(name)) {
-                                mSharedLibraries.put(name, new SharedLibraryEntry(null,
-                                        pkg.packageName));
-                            } else if (!name.equals(pkg.packageName)) {
-                                Slog.w(TAG, "Package " + pkg.packageName + " library "
-                                        + name + " already exists; skipping");
-                            }
-                        } else {
-                            Slog.w(TAG, "Package " + pkg.packageName + " declares lib "
-                                    + name + " that is not declared on system image; skipping");
-                        }
-                    }
-                    if ((scanMode&SCAN_BOOTING) == 0) {
-                        // If we are not booting, we need to update any applications
-                        // that are clients of our shared library.  If we are booting,
-                        // this will all be done once the scan is complete.
-                        clientLibPkgs = updateAllSharedLibrariesLPw(pkg);
-                    }
-                }
-            }
-        }
-
-        // We also need to dexopt any apps that are dependent on this library.  Note that
-        // if these fail, we should abort the install since installing the library will
-        // result in some apps being broken.
-        if (clientLibPkgs != null) {
-            if ((scanMode&SCAN_NO_DEX) == 0) {
-                for (int i=0; i<clientLibPkgs.size(); i++) {
-                    PackageParser.Package clientPkg = clientLibPkgs.get(i);
-                    if (performDexOptLI(clientPkg, forceDex, (scanMode&SCAN_DEFER_DEX) != 0, false)
-                            == DEX_OPT_FAILED) {
-                        if ((scanMode & SCAN_DELETE_DATA_ON_FAILURES) != 0) {
-                            removeDataDirsLI(pkg.packageName);
-                        }
-
-                        mLastScanError = PackageManager.INSTALL_FAILED_DEXOPT;
-                        return null;
-                    }
-                }
-            }
-        }
-
-        // Request the ActivityManager to kill the process(only for existing packages)
-        // so that we do not end up in a confused state while the user is still using the older
-        // version of the application while the new one gets installed.
-        if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
-            // If the package lives in an asec, tell everyone that the container is going
-            // away so they can clean up any references to its resources (which would prevent
-            // vold from being able to unmount the asec)
-            if (isForwardLocked(pkg) || isExternal(pkg)) {
-                if (DEBUG_INSTALL) {
-                    Slog.i(TAG, "upgrading pkg " + pkg + " is ASEC-hosted -> UNAVAILABLE");
-                }
-                final int[] uidArray = new int[] { pkg.applicationInfo.uid };
-                final ArrayList<String> pkgList = new ArrayList<String>(1);
-                pkgList.add(pkg.applicationInfo.packageName);
-                sendResourcesChangedBroadcast(false, true, pkgList, uidArray, null);
-            }
-
-            // Post the request that it be killed now that the going-away broadcast is en route
-            killApplication(pkg.applicationInfo.packageName,
-                        pkg.applicationInfo.uid, "update pkg");
-        }
-
-        // Also need to kill any apps that are dependent on the library.
-        if (clientLibPkgs != null) {
-            for (int i=0; i<clientLibPkgs.size(); i++) {
-                PackageParser.Package clientPkg = clientLibPkgs.get(i);
-                killApplication(clientPkg.applicationInfo.packageName,
-                        clientPkg.applicationInfo.uid, "update lib");
-            }
-        }
-
-        // writer
-        synchronized (mPackages) {
-            // We don't expect installation to fail beyond this point,
-            if ((scanMode&SCAN_MONITOR) != 0) {
-                mAppDirs.put(pkg.mPath, pkg);
-            }
-            // Add the new setting to mSettings
-            mSettings.insertPackageSettingLPw(pkgSetting, pkg);
-            // Add the new setting to mPackages
-            mPackages.put(pkg.applicationInfo.packageName, pkg);
-            // Make sure we don't accidentally delete its data.
-            final Iterator<PackageCleanItem> iter = mSettings.mPackagesToBeCleaned.iterator();
-            while (iter.hasNext()) {
-                PackageCleanItem item = iter.next();
-                if (pkgName.equals(item.packageName)) {
-                    iter.remove();
-                }
-            }
-
-            // Take care of first install / last update times.
-            if (currentTime != 0) {
-                if (pkgSetting.firstInstallTime == 0) {
-                    pkgSetting.firstInstallTime = pkgSetting.lastUpdateTime = currentTime;
-                } else if ((scanMode&SCAN_UPDATE_TIME) != 0) {
-                    pkgSetting.lastUpdateTime = currentTime;
-                }
-            } else if (pkgSetting.firstInstallTime == 0) {
-                // We need *something*.  Take time time stamp of the file.
-                pkgSetting.firstInstallTime = pkgSetting.lastUpdateTime = scanFileTime;
-            } else if ((parseFlags&PackageParser.PARSE_IS_SYSTEM_DIR) != 0) {
-                if (scanFileTime != pkgSetting.timeStamp) {
-                    // A package on the system image has changed; consider this
-                    // to be an update.
-                    pkgSetting.lastUpdateTime = scanFileTime;
-                }
-            }
-
-            // Add the package's KeySets to the global KeySetManager
-            KeySetManager ksm = mSettings.mKeySetManager;
-            try {
-                ksm.addSigningKeySetToPackage(pkg.packageName, pkg.mSigningKeys);
-                if (pkg.mKeySetMapping != null) {
-                    for (Map.Entry<String, Set<PublicKey>> entry : pkg.mKeySetMapping.entrySet()) {
-                        if (entry.getValue() != null) {
-                            ksm.addDefinedKeySetToPackage(pkg.packageName,
-                                entry.getValue(), entry.getKey());
-                        }
-                    }
-                }
-            } catch (NullPointerException e) {
-                Slog.e(TAG, "Could not add KeySet to " + pkg.packageName, e);
-            } catch (IllegalArgumentException e) {
-                Slog.e(TAG, "Could not add KeySet to malformed package" + pkg.packageName, e);
-            }
-
-            int N = pkg.providers.size();
-            StringBuilder r = null;
-            int i;
-            for (i=0; i<N; i++) {
-                PackageParser.Provider p = pkg.providers.get(i);
-                p.info.processName = fixProcessName(pkg.applicationInfo.processName,
-                        p.info.processName, pkg.applicationInfo.uid);
-                mProviders.addProvider(p);
-                p.syncable = p.info.isSyncable;
-                if (p.info.authority != null) {
-                    String names[] = p.info.authority.split(";");
-                    p.info.authority = null;
-                    for (int j = 0; j < names.length; j++) {
-                        if (j == 1 && p.syncable) {
-                            // We only want the first authority for a provider to possibly be
-                            // syncable, so if we already added this provider using a different
-                            // authority clear the syncable flag. We copy the provider before
-                            // changing it because the mProviders object contains a reference
-                            // to a provider that we don't want to change.
-                            // Only do this for the second authority since the resulting provider
-                            // object can be the same for all future authorities for this provider.
-                            p = new PackageParser.Provider(p);
-                            p.syncable = false;
-                        }
-                        if (!mProvidersByAuthority.containsKey(names[j])) {
-                            mProvidersByAuthority.put(names[j], p);
-                            if (p.info.authority == null) {
-                                p.info.authority = names[j];
-                            } else {
-                                p.info.authority = p.info.authority + ";" + names[j];
-                            }
-                            if (DEBUG_PACKAGE_SCANNING) {
-                                if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
-                                    Log.d(TAG, "Registered content provider: " + names[j]
-                                            + ", className = " + p.info.name + ", isSyncable = "
-                                            + p.info.isSyncable);
-                            }
-                        } else {
-                            PackageParser.Provider other = mProvidersByAuthority.get(names[j]);
-                            Slog.w(TAG, "Skipping provider name " + names[j] +
-                                    " (in package " + pkg.applicationInfo.packageName +
-                                    "): name already used by "
-                                    + ((other != null && other.getComponentName() != null)
-                                            ? other.getComponentName().getPackageName() : "?"));
-                        }
-                    }
-                }
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                    if (r == null) {
-                        r = new StringBuilder(256);
-                    } else {
-                        r.append(' ');
-                    }
-                    r.append(p.info.name);
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Providers: " + r);
-            }
-
-            N = pkg.services.size();
-            r = null;
-            for (i=0; i<N; i++) {
-                PackageParser.Service s = pkg.services.get(i);
-                s.info.processName = fixProcessName(pkg.applicationInfo.processName,
-                        s.info.processName, pkg.applicationInfo.uid);
-                mServices.addService(s);
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                    if (r == null) {
-                        r = new StringBuilder(256);
-                    } else {
-                        r.append(' ');
-                    }
-                    r.append(s.info.name);
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Services: " + r);
-            }
-
-            N = pkg.receivers.size();
-            r = null;
-            for (i=0; i<N; i++) {
-                PackageParser.Activity a = pkg.receivers.get(i);
-                a.info.processName = fixProcessName(pkg.applicationInfo.processName,
-                        a.info.processName, pkg.applicationInfo.uid);
-                mReceivers.addActivity(a, "receiver");
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                    if (r == null) {
-                        r = new StringBuilder(256);
-                    } else {
-                        r.append(' ');
-                    }
-                    r.append(a.info.name);
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Receivers: " + r);
-            }
-
-            N = pkg.activities.size();
-            r = null;
-            for (i=0; i<N; i++) {
-                PackageParser.Activity a = pkg.activities.get(i);
-                a.info.processName = fixProcessName(pkg.applicationInfo.processName,
-                        a.info.processName, pkg.applicationInfo.uid);
-                mActivities.addActivity(a, "activity");
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                    if (r == null) {
-                        r = new StringBuilder(256);
-                    } else {
-                        r.append(' ');
-                    }
-                    r.append(a.info.name);
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Activities: " + r);
-            }
-
-            N = pkg.permissionGroups.size();
-            r = null;
-            for (i=0; i<N; i++) {
-                PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i);
-                PackageParser.PermissionGroup cur = mPermissionGroups.get(pg.info.name);
-                if (cur == null) {
-                    mPermissionGroups.put(pg.info.name, pg);
-                    if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                        if (r == null) {
-                            r = new StringBuilder(256);
-                        } else {
-                            r.append(' ');
-                        }
-                        r.append(pg.info.name);
-                    }
-                } else {
-                    Slog.w(TAG, "Permission group " + pg.info.name + " from package "
-                            + pg.info.packageName + " ignored: original from "
-                            + cur.info.packageName);
-                    if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                        if (r == null) {
-                            r = new StringBuilder(256);
-                        } else {
-                            r.append(' ');
-                        }
-                        r.append("DUP:");
-                        r.append(pg.info.name);
-                    }
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Permission Groups: " + r);
-            }
-
-            N = pkg.permissions.size();
-            r = null;
-            for (i=0; i<N; i++) {
-                PackageParser.Permission p = pkg.permissions.get(i);
-                HashMap<String, BasePermission> permissionMap =
-                        p.tree ? mSettings.mPermissionTrees
-                        : mSettings.mPermissions;
-                p.group = mPermissionGroups.get(p.info.group);
-                if (p.info.group == null || p.group != null) {
-                    BasePermission bp = permissionMap.get(p.info.name);
-                    if (bp == null) {
-                        bp = new BasePermission(p.info.name, p.info.packageName,
-                                BasePermission.TYPE_NORMAL);
-                        permissionMap.put(p.info.name, bp);
-                    }
-                    if (bp.perm == null) {
-                        if (bp.sourcePackage != null
-                                && !bp.sourcePackage.equals(p.info.packageName)) {
-                            // If this is a permission that was formerly defined by a non-system
-                            // app, but is now defined by a system app (following an upgrade),
-                            // discard the previous declaration and consider the system's to be
-                            // canonical.
-                            if (isSystemApp(p.owner)) {
-                                Slog.i(TAG, "New decl " + p.owner + " of permission  "
-                                        + p.info.name + " is system");
-                                bp.sourcePackage = null;
-                            }
-                        }
-                        if (bp.sourcePackage == null
-                                || bp.sourcePackage.equals(p.info.packageName)) {
-                            BasePermission tree = findPermissionTreeLP(p.info.name);
-                            if (tree == null
-                                    || tree.sourcePackage.equals(p.info.packageName)) {
-                                bp.packageSetting = pkgSetting;
-                                bp.perm = p;
-                                bp.uid = pkg.applicationInfo.uid;
-                                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                                    if (r == null) {
-                                        r = new StringBuilder(256);
-                                    } else {
-                                        r.append(' ');
-                                    }
-                                    r.append(p.info.name);
-                                }
-                            } else {
-                                Slog.w(TAG, "Permission " + p.info.name + " from package "
-                                        + p.info.packageName + " ignored: base tree "
-                                        + tree.name + " is from package "
-                                        + tree.sourcePackage);
-                            }
-                        } else {
-                            Slog.w(TAG, "Permission " + p.info.name + " from package "
-                                    + p.info.packageName + " ignored: original from "
-                                    + bp.sourcePackage);
-                        }
-                    } else if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                        if (r == null) {
-                            r = new StringBuilder(256);
-                        } else {
-                            r.append(' ');
-                        }
-                        r.append("DUP:");
-                        r.append(p.info.name);
-                    }
-                    if (bp.perm == p) {
-                        bp.protectionLevel = p.info.protectionLevel;
-                    }
-                } else {
-                    Slog.w(TAG, "Permission " + p.info.name + " from package "
-                            + p.info.packageName + " ignored: no group "
-                            + p.group);
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Permissions: " + r);
-            }
-
-            N = pkg.instrumentation.size();
-            r = null;
-            for (i=0; i<N; i++) {
-                PackageParser.Instrumentation a = pkg.instrumentation.get(i);
-                a.info.packageName = pkg.applicationInfo.packageName;
-                a.info.sourceDir = pkg.applicationInfo.sourceDir;
-                a.info.publicSourceDir = pkg.applicationInfo.publicSourceDir;
-                a.info.dataDir = pkg.applicationInfo.dataDir;
-                a.info.nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir;
-                mInstrumentation.put(a.getComponentName(), a);
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0) {
-                    if (r == null) {
-                        r = new StringBuilder(256);
-                    } else {
-                        r.append(' ');
-                    }
-                    r.append(a.info.name);
-                }
-            }
-            if (r != null) {
-                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Instrumentation: " + r);
-            }
-
-            if (pkg.protectedBroadcasts != null) {
-                N = pkg.protectedBroadcasts.size();
-                for (i=0; i<N; i++) {
-                    mProtectedBroadcasts.add(pkg.protectedBroadcasts.get(i));
-                }
-            }
-
-            pkgSetting.setTimeStamp(scanFileTime);
-        }
-
-        return pkg;
-    }
-
-    private void setUpCustomResolverActivity(PackageParser.Package pkg) {
-        synchronized (mPackages) {
-            mResolverReplaced = true;
-            // Set up information for custom user intent resolution activity.
-            mResolveActivity.applicationInfo = pkg.applicationInfo;
-            mResolveActivity.name = mCustomResolverComponentName.getClassName();
-            mResolveActivity.packageName = pkg.applicationInfo.packageName;
-            mResolveActivity.processName = null;
-            mResolveActivity.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
-            mResolveActivity.flags = ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS |
-                    ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
-            mResolveActivity.theme = 0;
-            mResolveActivity.exported = true;
-            mResolveActivity.enabled = true;
-            mResolveInfo.activityInfo = mResolveActivity;
-            mResolveInfo.priority = 0;
-            mResolveInfo.preferredOrder = 0;
-            mResolveInfo.match = 0;
-            mResolveComponentName = mCustomResolverComponentName;
-            Slog.i(TAG, "Replacing default ResolverActivity with custom activity: " +
-                    mResolveComponentName);
-        }
-    }
-
-    private void setInternalAppNativeLibraryPath(PackageParser.Package pkg,
-            PackageSetting pkgSetting) {
-        final String apkLibPath = getApkName(pkgSetting.codePathString);
-        final String nativeLibraryPath = new File(mAppLibInstallDir, apkLibPath).getPath();
-        pkg.applicationInfo.nativeLibraryDir = nativeLibraryPath;
-        pkgSetting.nativeLibraryPathString = nativeLibraryPath;
-    }
-
-    private static int copyNativeLibrariesForInternalApp(File scanFile, final File nativeLibraryDir)
-            throws IOException {
-        if (!nativeLibraryDir.isDirectory()) {
-            nativeLibraryDir.delete();
-
-            if (!nativeLibraryDir.mkdir()) {
-                throw new IOException("Cannot create " + nativeLibraryDir.getPath());
-            }
-
-            try {
-                Libcore.os.chmod(nativeLibraryDir.getPath(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH
-                        | S_IXOTH);
-            } catch (ErrnoException e) {
-                throw new IOException("Cannot chmod native library directory "
-                        + nativeLibraryDir.getPath(), e);
-            }
-        } else if (!SELinux.restorecon(nativeLibraryDir)) {
-            throw new IOException("Cannot set SELinux context for " + nativeLibraryDir.getPath());
-        }
-
-        /*
-         * If this is an internal application or our nativeLibraryPath points to
-         * the app-lib directory, unpack the libraries if necessary.
-         */
-        return NativeLibraryHelper.copyNativeBinariesIfNeededLI(scanFile, nativeLibraryDir);
-    }
-
-    private void killApplication(String pkgName, int appId, String reason) {
-        // Request the ActivityManager to kill the process(only for existing packages)
-        // so that we do not end up in a confused state while the user is still using the older
-        // version of the application while the new one gets installed.
-        IActivityManager am = ActivityManagerNative.getDefault();
-        if (am != null) {
-            try {
-                am.killApplicationWithAppId(pkgName, appId, reason);
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    void removePackageLI(PackageSetting ps, boolean chatty) {
-        if (DEBUG_INSTALL) {
-            if (chatty)
-                Log.d(TAG, "Removing package " + ps.name);
-        }
-
-        // writer
-        synchronized (mPackages) {
-            mPackages.remove(ps.name);
-            if (ps.codePathString != null) {
-                mAppDirs.remove(ps.codePathString);
-            }
-
-            final PackageParser.Package pkg = ps.pkg;
-            if (pkg != null) {
-                cleanPackageDataStructuresLILPw(pkg, chatty);
-            }
-        }
-    }
-
-    void removeInstalledPackageLI(PackageParser.Package pkg, boolean chatty) {
-        if (DEBUG_INSTALL) {
-            if (chatty)
-                Log.d(TAG, "Removing package " + pkg.applicationInfo.packageName);
-        }
-
-        // writer
-        synchronized (mPackages) {
-            mPackages.remove(pkg.applicationInfo.packageName);
-            if (pkg.mPath != null) {
-                mAppDirs.remove(pkg.mPath);
-            }
-            cleanPackageDataStructuresLILPw(pkg, chatty);
-        }
-    }
-
-    void cleanPackageDataStructuresLILPw(PackageParser.Package pkg, boolean chatty) {
-        int N = pkg.providers.size();
-        StringBuilder r = null;
-        int i;
-        for (i=0; i<N; i++) {
-            PackageParser.Provider p = pkg.providers.get(i);
-            mProviders.removeProvider(p);
-            if (p.info.authority == null) {
-
-                /* There was another ContentProvider with this authority when
-                 * this app was installed so this authority is null,
-                 * Ignore it as we don't have to unregister the provider.
-                 */
-                continue;
-            }
-            String names[] = p.info.authority.split(";");
-            for (int j = 0; j < names.length; j++) {
-                if (mProvidersByAuthority.get(names[j]) == p) {
-                    mProvidersByAuthority.remove(names[j]);
-                    if (DEBUG_REMOVE) {
-                        if (chatty)
-                            Log.d(TAG, "Unregistered content provider: " + names[j]
-                                    + ", className = " + p.info.name + ", isSyncable = "
-                                    + p.info.isSyncable);
-                    }
-                }
-            }
-            if (DEBUG_REMOVE && chatty) {
-                if (r == null) {
-                    r = new StringBuilder(256);
-                } else {
-                    r.append(' ');
-                }
-                r.append(p.info.name);
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Providers: " + r);
-        }
-
-        N = pkg.services.size();
-        r = null;
-        for (i=0; i<N; i++) {
-            PackageParser.Service s = pkg.services.get(i);
-            mServices.removeService(s);
-            if (chatty) {
-                if (r == null) {
-                    r = new StringBuilder(256);
-                } else {
-                    r.append(' ');
-                }
-                r.append(s.info.name);
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Services: " + r);
-        }
-
-        N = pkg.receivers.size();
-        r = null;
-        for (i=0; i<N; i++) {
-            PackageParser.Activity a = pkg.receivers.get(i);
-            mReceivers.removeActivity(a, "receiver");
-            if (DEBUG_REMOVE && chatty) {
-                if (r == null) {
-                    r = new StringBuilder(256);
-                } else {
-                    r.append(' ');
-                }
-                r.append(a.info.name);
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Receivers: " + r);
-        }
-
-        N = pkg.activities.size();
-        r = null;
-        for (i=0; i<N; i++) {
-            PackageParser.Activity a = pkg.activities.get(i);
-            mActivities.removeActivity(a, "activity");
-            if (DEBUG_REMOVE && chatty) {
-                if (r == null) {
-                    r = new StringBuilder(256);
-                } else {
-                    r.append(' ');
-                }
-                r.append(a.info.name);
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Activities: " + r);
-        }
-
-        N = pkg.permissions.size();
-        r = null;
-        for (i=0; i<N; i++) {
-            PackageParser.Permission p = pkg.permissions.get(i);
-            BasePermission bp = mSettings.mPermissions.get(p.info.name);
-            if (bp == null) {
-                bp = mSettings.mPermissionTrees.get(p.info.name);
-            }
-            if (bp != null && bp.perm == p) {
-                bp.perm = null;
-                if (DEBUG_REMOVE && chatty) {
-                    if (r == null) {
-                        r = new StringBuilder(256);
-                    } else {
-                        r.append(' ');
-                    }
-                    r.append(p.info.name);
-                }
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Permissions: " + r);
-        }
-
-        N = pkg.instrumentation.size();
-        r = null;
-        for (i=0; i<N; i++) {
-            PackageParser.Instrumentation a = pkg.instrumentation.get(i);
-            mInstrumentation.remove(a.getComponentName());
-            if (DEBUG_REMOVE && chatty) {
-                if (r == null) {
-                    r = new StringBuilder(256);
-                } else {
-                    r.append(' ');
-                }
-                r.append(a.info.name);
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Instrumentation: " + r);
-        }
-
-        r = null;
-        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) != 0) {
-            // Only system apps can hold shared libraries.
-            if (pkg.libraryNames != null) {
-                for (i=0; i<pkg.libraryNames.size(); i++) {
-                    String name = pkg.libraryNames.get(i);
-                    SharedLibraryEntry cur = mSharedLibraries.get(name);
-                    if (cur != null && cur.apk != null && cur.apk.equals(pkg.packageName)) {
-                        mSharedLibraries.remove(name);
-                        if (DEBUG_REMOVE && chatty) {
-                            if (r == null) {
-                                r = new StringBuilder(256);
-                            } else {
-                                r.append(' ');
-                            }
-                            r.append(name);
-                        }
-                    }
-                }
-            }
-        }
-        if (r != null) {
-            if (DEBUG_REMOVE) Log.d(TAG, "  Libraries: " + r);
-        }
-    }
-
-    private static final boolean isPackageFilename(String name) {
-        return name != null && name.endsWith(".apk");
-    }
-
-    private static boolean hasPermission(PackageParser.Package pkgInfo, String perm) {
-        for (int i=pkgInfo.permissions.size()-1; i>=0; i--) {
-            if (pkgInfo.permissions.get(i).info.name.equals(perm)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    static final int UPDATE_PERMISSIONS_ALL = 1<<0;
-    static final int UPDATE_PERMISSIONS_REPLACE_PKG = 1<<1;
-    static final int UPDATE_PERMISSIONS_REPLACE_ALL = 1<<2;
-
-    private void updatePermissionsLPw(String changingPkg,
-            PackageParser.Package pkgInfo, int flags) {
-        // Make sure there are no dangling permission trees.
-        Iterator<BasePermission> it = mSettings.mPermissionTrees.values().iterator();
-        while (it.hasNext()) {
-            final BasePermission bp = it.next();
-            if (bp.packageSetting == null) {
-                // We may not yet have parsed the package, so just see if
-                // we still know about its settings.
-                bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage);
-            }
-            if (bp.packageSetting == null) {
-                Slog.w(TAG, "Removing dangling permission tree: " + bp.name
-                        + " from package " + bp.sourcePackage);
-                it.remove();
-            } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
-                if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) {
-                    Slog.i(TAG, "Removing old permission tree: " + bp.name
-                            + " from package " + bp.sourcePackage);
-                    flags |= UPDATE_PERMISSIONS_ALL;
-                    it.remove();
-                }
-            }
-        }
-
-        // Make sure all dynamic permissions have been assigned to a package,
-        // and make sure there are no dangling permissions.
-        it = mSettings.mPermissions.values().iterator();
-        while (it.hasNext()) {
-            final BasePermission bp = it.next();
-            if (bp.type == BasePermission.TYPE_DYNAMIC) {
-                if (DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name="
-                        + bp.name + " pkg=" + bp.sourcePackage
-                        + " info=" + bp.pendingInfo);
-                if (bp.packageSetting == null && bp.pendingInfo != null) {
-                    final BasePermission tree = findPermissionTreeLP(bp.name);
-                    if (tree != null && tree.perm != null) {
-                        bp.packageSetting = tree.packageSetting;
-                        bp.perm = new PackageParser.Permission(tree.perm.owner,
-                                new PermissionInfo(bp.pendingInfo));
-                        bp.perm.info.packageName = tree.perm.info.packageName;
-                        bp.perm.info.name = bp.name;
-                        bp.uid = tree.uid;
-                    }
-                }
-            }
-            if (bp.packageSetting == null) {
-                // We may not yet have parsed the package, so just see if
-                // we still know about its settings.
-                bp.packageSetting = mSettings.mPackages.get(bp.sourcePackage);
-            }
-            if (bp.packageSetting == null) {
-                Slog.w(TAG, "Removing dangling permission: " + bp.name
-                        + " from package " + bp.sourcePackage);
-                it.remove();
-            } else if (changingPkg != null && changingPkg.equals(bp.sourcePackage)) {
-                if (pkgInfo == null || !hasPermission(pkgInfo, bp.name)) {
-                    Slog.i(TAG, "Removing old permission: " + bp.name
-                            + " from package " + bp.sourcePackage);
-                    flags |= UPDATE_PERMISSIONS_ALL;
-                    it.remove();
-                }
-            }
-        }
-
-        // Now update the permissions for all packages, in particular
-        // replace the granted permissions of the system packages.
-        if ((flags&UPDATE_PERMISSIONS_ALL) != 0) {
-            for (PackageParser.Package pkg : mPackages.values()) {
-                if (pkg != pkgInfo) {
-                    grantPermissionsLPw(pkg, (flags&UPDATE_PERMISSIONS_REPLACE_ALL) != 0);
-                }
-            }
-        }
-        
-        if (pkgInfo != null) {
-            grantPermissionsLPw(pkgInfo, (flags&UPDATE_PERMISSIONS_REPLACE_PKG) != 0);
-        }
-    }
-
-    private void grantPermissionsLPw(PackageParser.Package pkg, boolean replace) {
-        final PackageSetting ps = (PackageSetting) pkg.mExtras;
-        if (ps == null) {
-            return;
-        }
-        final GrantedPermissions gp = ps.sharedUser != null ? ps.sharedUser : ps;
-        HashSet<String> origPermissions = gp.grantedPermissions;
-        boolean changedPermission = false;
-
-        if (replace) {
-            ps.permissionsFixed = false;
-            if (gp == ps) {
-                origPermissions = new HashSet<String>(gp.grantedPermissions);
-                gp.grantedPermissions.clear();
-                gp.gids = mGlobalGids;
-            }
-        }
-
-        if (gp.gids == null) {
-            gp.gids = mGlobalGids;
-        }
-
-        final int N = pkg.requestedPermissions.size();
-        for (int i=0; i<N; i++) {
-            final String name = pkg.requestedPermissions.get(i);
-            final boolean required = pkg.requestedPermissionsRequired.get(i);
-            final BasePermission bp = mSettings.mPermissions.get(name);
-            if (DEBUG_INSTALL) {
-                if (gp != ps) {
-                    Log.i(TAG, "Package " + pkg.packageName + " checking " + name + ": " + bp);
-                }
-            }
-
-            if (bp == null || bp.packageSetting == null) {
-                Slog.w(TAG, "Unknown permission " + name
-                        + " in package " + pkg.packageName);
-                continue;
-            }
-
-            final String perm = bp.name;
-            boolean allowed;
-            boolean allowedSig = false;
-            final int level = bp.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
-            if (level == PermissionInfo.PROTECTION_NORMAL
-                    || level == PermissionInfo.PROTECTION_DANGEROUS) {
-                // We grant a normal or dangerous permission if any of the following
-                // are true:
-                // 1) The permission is required
-                // 2) The permission is optional, but was granted in the past
-                // 3) The permission is optional, but was requested by an
-                //    app in /system (not /data)
-                //
-                // Otherwise, reject the permission.
-                allowed = (required || origPermissions.contains(perm)
-                        || (isSystemApp(ps) && !isUpdatedSystemApp(ps)));
-            } else if (bp.packageSetting == null) {
-                // This permission is invalid; skip it.
-                allowed = false;
-            } else if (level == PermissionInfo.PROTECTION_SIGNATURE) {
-                allowed = grantSignaturePermission(perm, pkg, bp, origPermissions);
-                if (allowed) {
-                    allowedSig = true;
-                }
-            } else {
-                allowed = false;
-            }
-            if (DEBUG_INSTALL) {
-                if (gp != ps) {
-                    Log.i(TAG, "Package " + pkg.packageName + " granting " + perm);
-                }
-            }
-            if (allowed) {
-                if (!isSystemApp(ps) && ps.permissionsFixed) {
-                    // If this is an existing, non-system package, then
-                    // we can't add any new permissions to it.
-                    if (!allowedSig && !gp.grantedPermissions.contains(perm)) {
-                        // Except...  if this is a permission that was added
-                        // to the platform (note: need to only do this when
-                        // updating the platform).
-                        allowed = isNewPlatformPermissionForPackage(perm, pkg);
-                    }
-                }
-                if (allowed) {
-                    if (!gp.grantedPermissions.contains(perm)) {
-                        changedPermission = true;
-                        gp.grantedPermissions.add(perm);
-                        gp.gids = appendInts(gp.gids, bp.gids);
-                    } else if (!ps.haveGids) {
-                        gp.gids = appendInts(gp.gids, bp.gids);
-                    }
-                } else {
-                    Slog.w(TAG, "Not granting permission " + perm
-                            + " to package " + pkg.packageName
-                            + " because it was previously installed without");
-                }
-            } else {
-                if (gp.grantedPermissions.remove(perm)) {
-                    changedPermission = true;
-                    gp.gids = removeInts(gp.gids, bp.gids);
-                    Slog.i(TAG, "Un-granting permission " + perm
-                            + " from package " + pkg.packageName
-                            + " (protectionLevel=" + bp.protectionLevel
-                            + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags)
-                            + ")");
-                } else {
-                    Slog.w(TAG, "Not granting permission " + perm
-                            + " to package " + pkg.packageName
-                            + " (protectionLevel=" + bp.protectionLevel
-                            + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags)
-                            + ")");
-                }
-            }
-        }
-
-        if ((changedPermission || replace) && !ps.permissionsFixed &&
-                !isSystemApp(ps) || isUpdatedSystemApp(ps)){
-            // This is the first that we have heard about this package, so the
-            // permissions we have now selected are fixed until explicitly
-            // changed.
-            ps.permissionsFixed = true;
-        }
-        ps.haveGids = true;
-    }
-
-    private boolean isNewPlatformPermissionForPackage(String perm, PackageParser.Package pkg) {
-        boolean allowed = false;
-        final int NP = PackageParser.NEW_PERMISSIONS.length;
-        for (int ip=0; ip<NP; ip++) {
-            final PackageParser.NewPermissionInfo npi
-                    = PackageParser.NEW_PERMISSIONS[ip];
-            if (npi.name.equals(perm)
-                    && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) {
-                allowed = true;
-                Log.i(TAG, "Auto-granting " + perm + " to old pkg "
-                        + pkg.packageName);
-                break;
-            }
-        }
-        return allowed;
-    }
-
-    private boolean grantSignaturePermission(String perm, PackageParser.Package pkg,
-                                          BasePermission bp, HashSet<String> origPermissions) {
-        boolean allowed;
-        allowed = (compareSignatures(
-                bp.packageSetting.signatures.mSignatures, pkg.mSignatures)
-                        == PackageManager.SIGNATURE_MATCH)
-                || (compareSignatures(mPlatformPackage.mSignatures, pkg.mSignatures)
-                        == PackageManager.SIGNATURE_MATCH);
-        if (!allowed && (bp.protectionLevel
-                & PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) {
-            if (isSystemApp(pkg)) {
-                // For updated system applications, a system permission
-                // is granted only if it had been defined by the original application.
-                if (isUpdatedSystemApp(pkg)) {
-                    final PackageSetting sysPs = mSettings
-                            .getDisabledSystemPkgLPr(pkg.packageName);
-                    final GrantedPermissions origGp = sysPs.sharedUser != null
-                            ? sysPs.sharedUser : sysPs;
-
-                    if (origGp.grantedPermissions.contains(perm)) {
-                        // If the original was granted this permission, we take
-                        // that grant decision as read and propagate it to the
-                        // update.
-                        allowed = true;
-                    } else {
-                        // The system apk may have been updated with an older
-                        // version of the one on the data partition, but which
-                        // granted a new system permission that it didn't have
-                        // before.  In this case we do want to allow the app to
-                        // now get the new permission if the ancestral apk is
-                        // privileged to get it.
-                        if (sysPs.pkg != null && sysPs.isPrivileged()) {
-                            for (int j=0;
-                                    j<sysPs.pkg.requestedPermissions.size(); j++) {
-                                if (perm.equals(
-                                        sysPs.pkg.requestedPermissions.get(j))) {
-                                    allowed = true;
-                                    break;
-                                }
-                            }
-                        }
-                    }
-                } else {
-                    allowed = isPrivilegedApp(pkg);
-                }
-            }
-        }
-        if (!allowed && (bp.protectionLevel
-                & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
-            // For development permissions, a development permission
-            // is granted only if it was already granted.
-            allowed = origPermissions.contains(perm);
-        }
-        return allowed;
-    }
-
-    final class ActivityIntentResolver
-            extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> {
-        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
-                boolean defaultOnly, int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
-            return super.queryIntent(intent, resolvedType, defaultOnly, userId);
-        }
-
-        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
-                int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            mFlags = flags;
-            return super.queryIntent(intent, resolvedType,
-                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
-        }
-
-        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
-                int flags, ArrayList<PackageParser.Activity> packageActivities, int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            if (packageActivities == null) {
-                return null;
-            }
-            mFlags = flags;
-            final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
-            final int N = packageActivities.size();
-            ArrayList<PackageParser.ActivityIntentInfo[]> listCut =
-                new ArrayList<PackageParser.ActivityIntentInfo[]>(N);
-
-            ArrayList<PackageParser.ActivityIntentInfo> intentFilters;
-            for (int i = 0; i < N; ++i) {
-                intentFilters = packageActivities.get(i).intents;
-                if (intentFilters != null && intentFilters.size() > 0) {
-                    PackageParser.ActivityIntentInfo[] array =
-                            new PackageParser.ActivityIntentInfo[intentFilters.size()];
-                    intentFilters.toArray(array);
-                    listCut.add(array);
-                }
-            }
-            return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
-        }
-
-        public final void addActivity(PackageParser.Activity a, String type) {
-            final boolean systemApp = isSystemApp(a.info.applicationInfo);
-            mActivities.put(a.getComponentName(), a);
-            if (DEBUG_SHOW_INFO)
-                Log.v(
-                TAG, "  " + type + " " +
-                (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
-            if (DEBUG_SHOW_INFO)
-                Log.v(TAG, "    Class=" + a.info.name);
-            final int NI = a.intents.size();
-            for (int j=0; j<NI; j++) {
-                PackageParser.ActivityIntentInfo intent = a.intents.get(j);
-                if (!systemApp && intent.getPriority() > 0 && "activity".equals(type)) {
-                    intent.setPriority(0);
-                    Log.w(TAG, "Package " + a.info.applicationInfo.packageName + " has activity "
-                            + a.className + " with priority > 0, forcing to 0");
-                }
-                if (DEBUG_SHOW_INFO) {
-                    Log.v(TAG, "    IntentFilter:");
-                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
-                }
-                if (!intent.debugCheck()) {
-                    Log.w(TAG, "==> For Activity " + a.info.name);
-                }
-                addFilter(intent);
-            }
-        }
-
-        public final void removeActivity(PackageParser.Activity a, String type) {
-            mActivities.remove(a.getComponentName());
-            if (DEBUG_SHOW_INFO) {
-                Log.v(TAG, "  " + type + " "
-                        + (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel
-                                : a.info.name) + ":");
-                Log.v(TAG, "    Class=" + a.info.name);
-            }
-            final int NI = a.intents.size();
-            for (int j=0; j<NI; j++) {
-                PackageParser.ActivityIntentInfo intent = a.intents.get(j);
-                if (DEBUG_SHOW_INFO) {
-                    Log.v(TAG, "    IntentFilter:");
-                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
-                }
-                removeFilter(intent);
-            }
-        }
-
-        @Override
-        protected boolean allowFilterResult(
-                PackageParser.ActivityIntentInfo filter, List<ResolveInfo> dest) {
-            ActivityInfo filterAi = filter.activity.info;
-            for (int i=dest.size()-1; i>=0; i--) {
-                ActivityInfo destAi = dest.get(i).activityInfo;
-                if (destAi.name == filterAi.name
-                        && destAi.packageName == filterAi.packageName) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        @Override
-        protected ActivityIntentInfo[] newArray(int size) {
-            return new ActivityIntentInfo[size];
-        }
-
-        @Override
-        protected boolean isFilterStopped(PackageParser.ActivityIntentInfo filter, int userId) {
-            if (!sUserManager.exists(userId)) return true;
-            PackageParser.Package p = filter.activity.owner;
-            if (p != null) {
-                PackageSetting ps = (PackageSetting)p.mExtras;
-                if (ps != null) {
-                    // System apps are never considered stopped for purposes of
-                    // filtering, because there may be no way for the user to
-                    // actually re-launch them.
-                    return (ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0
-                            && ps.getStopped(userId);
-                }
-            }
-            return false;
-        }
-
-        @Override
-        protected boolean isPackageForFilter(String packageName,
-                PackageParser.ActivityIntentInfo info) {
-            return packageName.equals(info.activity.owner.packageName);
-        }
-        
-        @Override
-        protected ResolveInfo newResult(PackageParser.ActivityIntentInfo info,
-                int match, int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            if (!mSettings.isEnabledLPr(info.activity.info, mFlags, userId)) {
-                return null;
-            }
-            final PackageParser.Activity activity = info.activity;
-            if (mSafeMode && (activity.info.applicationInfo.flags
-                    &ApplicationInfo.FLAG_SYSTEM) == 0) {
-                return null;
-            }
-            PackageSetting ps = (PackageSetting) activity.owner.mExtras;
-            if (ps == null) {
-                return null;
-            }
-            ActivityInfo ai = PackageParser.generateActivityInfo(activity, mFlags,
-                    ps.readUserState(userId), userId);
-            if (ai == null) {
-                return null;
-            }
-            final ResolveInfo res = new ResolveInfo();
-            res.activityInfo = ai;
-            if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) {
-                res.filter = info;
-            }
-            res.priority = info.getPriority();
-            res.preferredOrder = activity.owner.mPreferredOrder;
-            //System.out.println("Result: " + res.activityInfo.className +
-            //                   " = " + res.priority);
-            res.match = match;
-            res.isDefault = info.hasDefault;
-            res.labelRes = info.labelRes;
-            res.nonLocalizedLabel = info.nonLocalizedLabel;
-            res.icon = info.icon;
-            res.system = isSystemApp(res.activityInfo.applicationInfo);
-            return res;
-        }
-
-        @Override
-        protected void sortResults(List<ResolveInfo> results) {
-            Collections.sort(results, mResolvePrioritySorter);
-        }
-
-        @Override
-        protected void dumpFilter(PrintWriter out, String prefix,
-                PackageParser.ActivityIntentInfo filter) {
-            out.print(prefix); out.print(
-                    Integer.toHexString(System.identityHashCode(filter.activity)));
-                    out.print(' ');
-                    filter.activity.printComponentShortName(out);
-                    out.print(" filter ");
-                    out.println(Integer.toHexString(System.identityHashCode(filter)));
-        }
-
-//        List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) {
-//            final Iterator<ResolveInfo> i = resolveInfoList.iterator();
-//            final List<ResolveInfo> retList = Lists.newArrayList();
-//            while (i.hasNext()) {
-//                final ResolveInfo resolveInfo = i.next();
-//                if (isEnabledLP(resolveInfo.activityInfo)) {
-//                    retList.add(resolveInfo);
-//                }
-//            }
-//            return retList;
-//        }
-
-        // Keys are String (activity class name), values are Activity.
-        private final HashMap<ComponentName, PackageParser.Activity> mActivities
-                = new HashMap<ComponentName, PackageParser.Activity>();
-        private int mFlags;
-    }
-
-    private final class ServiceIntentResolver
-            extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> {
-        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
-                boolean defaultOnly, int userId) {
-            mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
-            return super.queryIntent(intent, resolvedType, defaultOnly, userId);
-        }
-
-        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
-                int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            mFlags = flags;
-            return super.queryIntent(intent, resolvedType,
-                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
-        }
-
-        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
-                int flags, ArrayList<PackageParser.Service> packageServices, int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            if (packageServices == null) {
-                return null;
-            }
-            mFlags = flags;
-            final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
-            final int N = packageServices.size();
-            ArrayList<PackageParser.ServiceIntentInfo[]> listCut =
-                new ArrayList<PackageParser.ServiceIntentInfo[]>(N);
-
-            ArrayList<PackageParser.ServiceIntentInfo> intentFilters;
-            for (int i = 0; i < N; ++i) {
-                intentFilters = packageServices.get(i).intents;
-                if (intentFilters != null && intentFilters.size() > 0) {
-                    PackageParser.ServiceIntentInfo[] array =
-                            new PackageParser.ServiceIntentInfo[intentFilters.size()];
-                    intentFilters.toArray(array);
-                    listCut.add(array);
-                }
-            }
-            return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
-        }
-
-        public final void addService(PackageParser.Service s) {
-            mServices.put(s.getComponentName(), s);
-            if (DEBUG_SHOW_INFO) {
-                Log.v(TAG, "  "
-                        + (s.info.nonLocalizedLabel != null
-                        ? s.info.nonLocalizedLabel : s.info.name) + ":");
-                Log.v(TAG, "    Class=" + s.info.name);
-            }
-            final int NI = s.intents.size();
-            int j;
-            for (j=0; j<NI; j++) {
-                PackageParser.ServiceIntentInfo intent = s.intents.get(j);
-                if (DEBUG_SHOW_INFO) {
-                    Log.v(TAG, "    IntentFilter:");
-                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
-                }
-                if (!intent.debugCheck()) {
-                    Log.w(TAG, "==> For Service " + s.info.name);
-                }
-                addFilter(intent);
-            }
-        }
-
-        public final void removeService(PackageParser.Service s) {
-            mServices.remove(s.getComponentName());
-            if (DEBUG_SHOW_INFO) {
-                Log.v(TAG, "  " + (s.info.nonLocalizedLabel != null
-                        ? s.info.nonLocalizedLabel : s.info.name) + ":");
-                Log.v(TAG, "    Class=" + s.info.name);
-            }
-            final int NI = s.intents.size();
-            int j;
-            for (j=0; j<NI; j++) {
-                PackageParser.ServiceIntentInfo intent = s.intents.get(j);
-                if (DEBUG_SHOW_INFO) {
-                    Log.v(TAG, "    IntentFilter:");
-                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
-                }
-                removeFilter(intent);
-            }
-        }
-
-        @Override
-        protected boolean allowFilterResult(
-                PackageParser.ServiceIntentInfo filter, List<ResolveInfo> dest) {
-            ServiceInfo filterSi = filter.service.info;
-            for (int i=dest.size()-1; i>=0; i--) {
-                ServiceInfo destAi = dest.get(i).serviceInfo;
-                if (destAi.name == filterSi.name
-                        && destAi.packageName == filterSi.packageName) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        @Override
-        protected PackageParser.ServiceIntentInfo[] newArray(int size) {
-            return new PackageParser.ServiceIntentInfo[size];
-        }
-
-        @Override
-        protected boolean isFilterStopped(PackageParser.ServiceIntentInfo filter, int userId) {
-            if (!sUserManager.exists(userId)) return true;
-            PackageParser.Package p = filter.service.owner;
-            if (p != null) {
-                PackageSetting ps = (PackageSetting)p.mExtras;
-                if (ps != null) {
-                    // System apps are never considered stopped for purposes of
-                    // filtering, because there may be no way for the user to
-                    // actually re-launch them.
-                    return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
-                            && ps.getStopped(userId);
-                }
-            }
-            return false;
-        }
-
-        @Override
-        protected boolean isPackageForFilter(String packageName,
-                PackageParser.ServiceIntentInfo info) {
-            return packageName.equals(info.service.owner.packageName);
-        }
-        
-        @Override
-        protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter,
-                int match, int userId) {
-            if (!sUserManager.exists(userId)) return null;
-            final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter;
-            if (!mSettings.isEnabledLPr(info.service.info, mFlags, userId)) {
-                return null;
-            }
-            final PackageParser.Service service = info.service;
-            if (mSafeMode && (service.info.applicationInfo.flags
-                    &ApplicationInfo.FLAG_SYSTEM) == 0) {
-                return null;
-            }
-            PackageSetting ps = (PackageSetting) service.owner.mExtras;
-            if (ps == null) {
-                return null;
-            }
-            ServiceInfo si = PackageParser.generateServiceInfo(service, mFlags,
-                    ps.readUserState(userId), userId);
-            if (si == null) {
-                return null;
-            }
-            final ResolveInfo res = new ResolveInfo();
-            res.serviceInfo = si;
-            if ((mFlags&PackageManager.GET_RESOLVED_FILTER) != 0) {
-                res.filter = filter;
-            }
-            res.priority = info.getPriority();
-            res.preferredOrder = service.owner.mPreferredOrder;
-            //System.out.println("Result: " + res.activityInfo.className +
-            //                   " = " + res.priority);
-            res.match = match;
-            res.isDefault = info.hasDefault;
-            res.labelRes = info.labelRes;
-            res.nonLocalizedLabel = info.nonLocalizedLabel;
-            res.icon = info.icon;
-            res.system = isSystemApp(res.serviceInfo.applicationInfo);
-            return res;
-        }
-
-        @Override
-        protected void sortResults(List<ResolveInfo> results) {
-            Collections.sort(results, mResolvePrioritySorter);
-        }
-
-        @Override
-        protected void dumpFilter(PrintWriter out, String prefix,
-                PackageParser.ServiceIntentInfo filter) {
-            out.print(prefix); out.print(
-                    Integer.toHexString(System.identityHashCode(filter.service)));
-                    out.print(' ');
-                    filter.service.printComponentShortName(out);
-                    out.print(" filter ");
-                    out.println(Integer.toHexString(System.identityHashCode(filter)));
-        }
-
-//        List<ResolveInfo> filterEnabled(List<ResolveInfo> resolveInfoList) {
-//            final Iterator<ResolveInfo> i = resolveInfoList.iterator();
-//            final List<ResolveInfo> retList = Lists.newArrayList();
-//            while (i.hasNext()) {
-//                final ResolveInfo resolveInfo = (ResolveInfo) i;
-//                if (isEnabledLP(resolveInfo.serviceInfo)) {
-//                    retList.add(resolveInfo);
-//                }
-//            }
-//            return retList;
-//        }
-
-        // Keys are String (activity class name), values are Activity.
-        private final HashMap<ComponentName, PackageParser.Service> mServices
-                = new HashMap<ComponentName, PackageParser.Service>();
-        private int mFlags;
-    };
-
-    private final class ProviderIntentResolver
-            extends IntentResolver<PackageParser.ProviderIntentInfo, ResolveInfo> {
-        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
-                boolean defaultOnly, int userId) {
-            mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
-            return super.queryIntent(intent, resolvedType, defaultOnly, userId);
-        }
-
-        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags,
-                int userId) {
-            if (!sUserManager.exists(userId))
-                return null;
-            mFlags = flags;
-            return super.queryIntent(intent, resolvedType,
-                    (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId);
-        }
-
-        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
-                int flags, ArrayList<PackageParser.Provider> packageProviders, int userId) {
-            if (!sUserManager.exists(userId))
-                return null;
-            if (packageProviders == null) {
-                return null;
-            }
-            mFlags = flags;
-            final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
-            final int N = packageProviders.size();
-            ArrayList<PackageParser.ProviderIntentInfo[]> listCut =
-                    new ArrayList<PackageParser.ProviderIntentInfo[]>(N);
-
-            ArrayList<PackageParser.ProviderIntentInfo> intentFilters;
-            for (int i = 0; i < N; ++i) {
-                intentFilters = packageProviders.get(i).intents;
-                if (intentFilters != null && intentFilters.size() > 0) {
-                    PackageParser.ProviderIntentInfo[] array =
-                            new PackageParser.ProviderIntentInfo[intentFilters.size()];
-                    intentFilters.toArray(array);
-                    listCut.add(array);
-                }
-            }
-            return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId);
-        }
-
-        public final void addProvider(PackageParser.Provider p) {
-            mProviders.put(p.getComponentName(), p);
-            if (DEBUG_SHOW_INFO) {
-                Log.v(TAG, "  "
-                        + (p.info.nonLocalizedLabel != null
-                                ? p.info.nonLocalizedLabel : p.info.name) + ":");
-                Log.v(TAG, "    Class=" + p.info.name);
-            }
-            final int NI = p.intents.size();
-            int j;
-            for (j = 0; j < NI; j++) {
-                PackageParser.ProviderIntentInfo intent = p.intents.get(j);
-                if (DEBUG_SHOW_INFO) {
-                    Log.v(TAG, "    IntentFilter:");
-                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
-                }
-                if (!intent.debugCheck()) {
-                    Log.w(TAG, "==> For Provider " + p.info.name);
-                }
-                addFilter(intent);
-            }
-        }
-
-        public final void removeProvider(PackageParser.Provider p) {
-            mProviders.remove(p.getComponentName());
-            if (DEBUG_SHOW_INFO) {
-                Log.v(TAG, "  " + (p.info.nonLocalizedLabel != null
-                        ? p.info.nonLocalizedLabel : p.info.name) + ":");
-                Log.v(TAG, "    Class=" + p.info.name);
-            }
-            final int NI = p.intents.size();
-            int j;
-            for (j = 0; j < NI; j++) {
-                PackageParser.ProviderIntentInfo intent = p.intents.get(j);
-                if (DEBUG_SHOW_INFO) {
-                    Log.v(TAG, "    IntentFilter:");
-                    intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
-                }
-                removeFilter(intent);
-            }
-        }
-
-        @Override
-        protected boolean allowFilterResult(
-                PackageParser.ProviderIntentInfo filter, List<ResolveInfo> dest) {
-            ProviderInfo filterPi = filter.provider.info;
-            for (int i = dest.size() - 1; i >= 0; i--) {
-                ProviderInfo destPi = dest.get(i).providerInfo;
-                if (destPi.name == filterPi.name
-                        && destPi.packageName == filterPi.packageName) {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        @Override
-        protected PackageParser.ProviderIntentInfo[] newArray(int size) {
-            return new PackageParser.ProviderIntentInfo[size];
-        }
-
-        @Override
-        protected boolean isFilterStopped(PackageParser.ProviderIntentInfo filter, int userId) {
-            if (!sUserManager.exists(userId))
-                return true;
-            PackageParser.Package p = filter.provider.owner;
-            if (p != null) {
-                PackageSetting ps = (PackageSetting) p.mExtras;
-                if (ps != null) {
-                    // System apps are never considered stopped for purposes of
-                    // filtering, because there may be no way for the user to
-                    // actually re-launch them.
-                    return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
-                            && ps.getStopped(userId);
-                }
-            }
-            return false;
-        }
-
-        @Override
-        protected boolean isPackageForFilter(String packageName,
-                PackageParser.ProviderIntentInfo info) {
-            return packageName.equals(info.provider.owner.packageName);
-        }
-
-        @Override
-        protected ResolveInfo newResult(PackageParser.ProviderIntentInfo filter,
-                int match, int userId) {
-            if (!sUserManager.exists(userId))
-                return null;
-            final PackageParser.ProviderIntentInfo info = filter;
-            if (!mSettings.isEnabledLPr(info.provider.info, mFlags, userId)) {
-                return null;
-            }
-            final PackageParser.Provider provider = info.provider;
-            if (mSafeMode && (provider.info.applicationInfo.flags
-                    & ApplicationInfo.FLAG_SYSTEM) == 0) {
-                return null;
-            }
-            PackageSetting ps = (PackageSetting) provider.owner.mExtras;
-            if (ps == null) {
-                return null;
-            }
-            ProviderInfo pi = PackageParser.generateProviderInfo(provider, mFlags,
-                    ps.readUserState(userId), userId);
-            if (pi == null) {
-                return null;
-            }
-            final ResolveInfo res = new ResolveInfo();
-            res.providerInfo = pi;
-            if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
-                res.filter = filter;
-            }
-            res.priority = info.getPriority();
-            res.preferredOrder = provider.owner.mPreferredOrder;
-            res.match = match;
-            res.isDefault = info.hasDefault;
-            res.labelRes = info.labelRes;
-            res.nonLocalizedLabel = info.nonLocalizedLabel;
-            res.icon = info.icon;
-            res.system = isSystemApp(res.providerInfo.applicationInfo);
-            return res;
-        }
-
-        @Override
-        protected void sortResults(List<ResolveInfo> results) {
-            Collections.sort(results, mResolvePrioritySorter);
-        }
-
-        @Override
-        protected void dumpFilter(PrintWriter out, String prefix,
-                PackageParser.ProviderIntentInfo filter) {
-            out.print(prefix);
-            out.print(
-                    Integer.toHexString(System.identityHashCode(filter.provider)));
-            out.print(' ');
-            filter.provider.printComponentShortName(out);
-            out.print(" filter ");
-            out.println(Integer.toHexString(System.identityHashCode(filter)));
-        }
-
-        private final HashMap<ComponentName, PackageParser.Provider> mProviders
-                = new HashMap<ComponentName, PackageParser.Provider>();
-        private int mFlags;
-    };
-
-    private static final Comparator<ResolveInfo> mResolvePrioritySorter =
-            new Comparator<ResolveInfo>() {
-        public int compare(ResolveInfo r1, ResolveInfo r2) {
-            int v1 = r1.priority;
-            int v2 = r2.priority;
-            //System.out.println("Comparing: q1=" + q1 + " q2=" + q2);
-            if (v1 != v2) {
-                return (v1 > v2) ? -1 : 1;
-            }
-            v1 = r1.preferredOrder;
-            v2 = r2.preferredOrder;
-            if (v1 != v2) {
-                return (v1 > v2) ? -1 : 1;
-            }
-            if (r1.isDefault != r2.isDefault) {
-                return r1.isDefault ? -1 : 1;
-            }
-            v1 = r1.match;
-            v2 = r2.match;
-            //System.out.println("Comparing: m1=" + m1 + " m2=" + m2);
-            if (v1 != v2) {
-                return (v1 > v2) ? -1 : 1;
-            }
-            if (r1.system != r2.system) {
-                return r1.system ? -1 : 1;
-            }
-            return 0;
-        }
-    };
-
-    private static final Comparator<ProviderInfo> mProviderInitOrderSorter =
-            new Comparator<ProviderInfo>() {
-        public int compare(ProviderInfo p1, ProviderInfo p2) {
-            final int v1 = p1.initOrder;
-            final int v2 = p2.initOrder;
-            return (v1 > v2) ? -1 : ((v1 < v2) ? 1 : 0);
-        }
-    };
-
-    static final void sendPackageBroadcast(String action, String pkg,
-            Bundle extras, String targetPkg, IIntentReceiver finishedReceiver,
-            int[] userIds) {
-        IActivityManager am = ActivityManagerNative.getDefault();
-        if (am != null) {
-            try {
-                if (userIds == null) {
-                    userIds = am.getRunningUserIds();
-                }
-                for (int id : userIds) {
-                    final Intent intent = new Intent(action,
-                            pkg != null ? Uri.fromParts("package", pkg, null) : null);
-                    if (extras != null) {
-                        intent.putExtras(extras);
-                    }
-                    if (targetPkg != null) {
-                        intent.setPackage(targetPkg);
-                    }
-                    // Modify the UID when posting to other users
-                    int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
-                    if (uid > 0 && UserHandle.getUserId(uid) != id) {
-                        uid = UserHandle.getUid(id, UserHandle.getAppId(uid));
-                        intent.putExtra(Intent.EXTRA_UID, uid);
-                    }
-                    intent.putExtra(Intent.EXTRA_USER_HANDLE, id);
-                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-                    if (DEBUG_BROADCASTS) {
-                        RuntimeException here = new RuntimeException("here");
-                        here.fillInStackTrace();
-                        Slog.d(TAG, "Sending to user " + id + ": "
-                                + intent.toShortString(false, true, false, false)
-                                + " " + intent.getExtras(), here);
-                    }
-                    am.broadcastIntent(null, intent, null, finishedReceiver,
-                            0, null, null, null, android.app.AppOpsManager.OP_NONE,
-                            finishedReceiver != null, false, id);
-                }
-            } catch (RemoteException ex) {
-            }
-        }
-    }
-
-    /**
-     * Check if the external storage media is available. This is true if there
-     * is a mounted external storage medium or if the external storage is
-     * emulated.
-     */
-    private boolean isExternalMediaAvailable() {
-        return mMediaMounted || Environment.isExternalStorageEmulated();
-    }
-
-    public PackageCleanItem nextPackageToClean(PackageCleanItem lastPackage) {
-        // writer
-        synchronized (mPackages) {
-            if (!isExternalMediaAvailable()) {
-                // If the external storage is no longer mounted at this point,
-                // the caller may not have been able to delete all of this
-                // packages files and can not delete any more.  Bail.
-                return null;
-            }
-            final ArrayList<PackageCleanItem> pkgs = mSettings.mPackagesToBeCleaned;
-            if (lastPackage != null) {
-                pkgs.remove(lastPackage);
-            }
-            if (pkgs.size() > 0) {
-                return pkgs.get(0);
-            }
-        }
-        return null;
-    }
-
-    void schedulePackageCleaning(String packageName, int userId, boolean andCode) {
-        if (false) {
-            RuntimeException here = new RuntimeException("here");
-            here.fillInStackTrace();
-            Slog.d(TAG, "Schedule cleaning " + packageName + " user=" + userId
-                    + " andCode=" + andCode, here);
-        }
-        mHandler.sendMessage(mHandler.obtainMessage(START_CLEANING_PACKAGE,
-                userId, andCode ? 1 : 0, packageName));
-    }
-    
-    void startCleaningPackages() {
-        // reader
-        synchronized (mPackages) {
-            if (!isExternalMediaAvailable()) {
-                return;
-            }
-            if (mSettings.mPackagesToBeCleaned.isEmpty()) {
-                return;
-            }
-        }
-        Intent intent = new Intent(PackageManager.ACTION_CLEAN_EXTERNAL_STORAGE);
-        intent.setComponent(DEFAULT_CONTAINER_COMPONENT);
-        IActivityManager am = ActivityManagerNative.getDefault();
-        if (am != null) {
-            try {
-                am.startService(null, intent, null, UserHandle.USER_OWNER);
-            } catch (RemoteException e) {
-            }
-        }
-    }
-    
-    private final class AppDirObserver extends FileObserver {
-        public AppDirObserver(String path, int mask, boolean isrom, boolean isPrivileged) {
-            super(path, mask);
-            mRootDir = path;
-            mIsRom = isrom;
-            mIsPrivileged = isPrivileged;
-        }
-
-        public void onEvent(int event, String path) {
-            String removedPackage = null;
-            int removedAppId = -1;
-            int[] removedUsers = null;
-            String addedPackage = null;
-            int addedAppId = -1;
-            int[] addedUsers = null;
-
-            // TODO post a message to the handler to obtain serial ordering
-            synchronized (mInstallLock) {
-                String fullPathStr = null;
-                File fullPath = null;
-                if (path != null) {
-                    fullPath = new File(mRootDir, path);
-                    fullPathStr = fullPath.getPath();
-                }
-
-                if (DEBUG_APP_DIR_OBSERVER)
-                    Log.v(TAG, "File " + fullPathStr + " changed: " + Integer.toHexString(event));
-
-                if (!isPackageFilename(path)) {
-                    if (DEBUG_APP_DIR_OBSERVER)
-                        Log.v(TAG, "Ignoring change of non-package file: " + fullPathStr);
-                    return;
-                }
-
-                // Ignore packages that are being installed or
-                // have just been installed.
-                if (ignoreCodePath(fullPathStr)) {
-                    return;
-                }
-                PackageParser.Package p = null;
-                PackageSetting ps = null;
-                // reader
-                synchronized (mPackages) {
-                    p = mAppDirs.get(fullPathStr);
-                    if (p != null) {
-                        ps = mSettings.mPackages.get(p.applicationInfo.packageName);
-                        if (ps != null) {
-                            removedUsers = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
-                        } else {
-                            removedUsers = sUserManager.getUserIds();
-                        }
-                    }
-                    addedUsers = sUserManager.getUserIds();
-                }
-                if ((event&REMOVE_EVENTS) != 0) {
-                    if (ps != null) {
-                        if (DEBUG_REMOVE) Slog.d(TAG, "Package disappeared: " + ps);
-                        removePackageLI(ps, true);
-                        removedPackage = ps.name;
-                        removedAppId = ps.appId;
-                    }
-                }
-
-                if ((event&ADD_EVENTS) != 0) {
-                    if (p == null) {
-                        if (DEBUG_INSTALL) Slog.d(TAG, "New file appeared: " + fullPath);
-                        int flags = PackageParser.PARSE_CHATTY | PackageParser.PARSE_MUST_BE_APK;
-                        if (mIsRom) {
-                            flags |= PackageParser.PARSE_IS_SYSTEM
-                                    | PackageParser.PARSE_IS_SYSTEM_DIR;
-                            if (mIsPrivileged) {
-                                flags |= PackageParser.PARSE_IS_PRIVILEGED;
-                            }
-                        }
-                        p = scanPackageLI(fullPath, flags,
-                                SCAN_MONITOR | SCAN_NO_PATHS | SCAN_UPDATE_TIME,
-                                System.currentTimeMillis(), UserHandle.ALL);
-                        if (p != null) {
-                            /*
-                             * TODO this seems dangerous as the package may have
-                             * changed since we last acquired the mPackages
-                             * lock.
-                             */
-                            // writer
-                            synchronized (mPackages) {
-                                updatePermissionsLPw(p.packageName, p,
-                                        p.permissions.size() > 0 ? UPDATE_PERMISSIONS_ALL : 0);
-                            }
-                            addedPackage = p.applicationInfo.packageName;
-                            addedAppId = UserHandle.getAppId(p.applicationInfo.uid);
-                        }
-                    }
-                }
-
-                // reader
-                synchronized (mPackages) {
-                    mSettings.writeLPr();
-                }
-            }
-
-            if (removedPackage != null) {
-                Bundle extras = new Bundle(1);
-                extras.putInt(Intent.EXTRA_UID, removedAppId);
-                extras.putBoolean(Intent.EXTRA_DATA_REMOVED, false);
-                sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage,
-                        extras, null, null, removedUsers);
-            }
-            if (addedPackage != null) {
-                Bundle extras = new Bundle(1);
-                extras.putInt(Intent.EXTRA_UID, addedAppId);
-                sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, addedPackage,
-                        extras, null, null, addedUsers);
-            }
-        }
-
-        private final String mRootDir;
-        private final boolean mIsRom;
-        private final boolean mIsPrivileged;
-    }
-
-    /* Called when a downloaded package installation has been confirmed by the user */
-    public void installPackage(
-            final Uri packageURI, final IPackageInstallObserver observer, final int flags) {
-        installPackage(packageURI, observer, flags, null);
-    }
-
-    /* Called when a downloaded package installation has been confirmed by the user */
-    public void installPackage(
-            final Uri packageURI, final IPackageInstallObserver observer, final int flags,
-            final String installerPackageName) {
-        installPackageWithVerification(packageURI, observer, flags, installerPackageName, null,
-                null, null);
-    }
-
-    @Override
-    public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
-            int flags, String installerPackageName, Uri verificationURI,
-            ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
-        VerificationParams verificationParams = new VerificationParams(verificationURI, null, null,
-                VerificationParams.NO_UID, manifestDigest);
-        installPackageWithVerificationAndEncryption(packageURI, observer, flags,
-                installerPackageName, verificationParams, encryptionParams);
-    }
-
-    public void installPackageWithVerificationAndEncryption(Uri packageURI,
-            IPackageInstallObserver observer, int flags, String installerPackageName,
-            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.INSTALL_PACKAGES,
-                null);
-
-        final int uid = Binder.getCallingUid();
-        if (isUserRestricted(UserHandle.getUserId(uid), UserManager.DISALLOW_INSTALL_APPS)) {
-            try {
-                observer.packageInstalled("", PackageManager.INSTALL_FAILED_USER_RESTRICTED);
-            } catch (RemoteException re) {
-            }
-            return;
-        }
-
-        UserHandle user;
-        if ((flags&PackageManager.INSTALL_ALL_USERS) != 0) {
-            user = UserHandle.ALL;
-        } else {
-            user = new UserHandle(UserHandle.getUserId(uid));
-        }
-
-        final int filteredFlags;
-
-        if (uid == Process.SHELL_UID || uid == 0) {
-            if (DEBUG_INSTALL) {
-                Slog.v(TAG, "Install from ADB");
-            }
-            filteredFlags = flags | PackageManager.INSTALL_FROM_ADB;
-        } else {
-            filteredFlags = flags & ~PackageManager.INSTALL_FROM_ADB;
-        }
-
-        verificationParams.setInstallerUid(uid);
-
-        final Message msg = mHandler.obtainMessage(INIT_COPY);
-        msg.obj = new InstallParams(packageURI, observer, filteredFlags, installerPackageName,
-                verificationParams, encryptionParams, user);
-        mHandler.sendMessage(msg);
-    }
-
-    private void sendPackageAddedForUser(String packageName, PackageSetting pkgSetting, int userId) {
-        Bundle extras = new Bundle(1);
-        extras.putInt(Intent.EXTRA_UID, UserHandle.getUid(userId, pkgSetting.appId));
-
-        sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
-                packageName, extras, null, null, new int[] {userId});
-        try {
-            IActivityManager am = ActivityManagerNative.getDefault();
-            final boolean isSystem =
-                    isSystemApp(pkgSetting) || isUpdatedSystemApp(pkgSetting);
-            if (isSystem && am.isUserRunning(userId, false)) {
-                // The just-installed/enabled app is bundled on the system, so presumed
-                // to be able to run automatically without needing an explicit launch.
-                // Send it a BOOT_COMPLETED if it would ordinarily have gotten one.
-                Intent bcIntent = new Intent(Intent.ACTION_BOOT_COMPLETED)
-                        .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
-                        .setPackage(packageName);
-                am.broadcastIntent(null, bcIntent, null, null, 0, null, null, null,
-                        android.app.AppOpsManager.OP_NONE, false, false, userId);
-            }
-        } catch (RemoteException e) {
-            // shouldn't happen
-            Slog.w(TAG, "Unable to bootstrap installed package", e);
-        }
-    }
-
-    @Override
-    public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked,
-            int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
-        PackageSetting pkgSetting;
-        final int uid = Binder.getCallingUid();
-        if (UserHandle.getUserId(uid) != userId) {
-            mContext.enforceCallingOrSelfPermission(
-                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                    "setApplicationBlockedSetting for user " + userId);
-        }
-
-        if (blocked && isPackageDeviceAdmin(packageName, userId)) {
-            Slog.w(TAG, "Not blocking package " + packageName + ": has active device admin");
-            return false;
-        }
-
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            boolean sendAdded = false;
-            boolean sendRemoved = false;
-            // writer
-            synchronized (mPackages) {
-                pkgSetting = mSettings.mPackages.get(packageName);
-                if (pkgSetting == null) {
-                    return false;
-                }
-                if (pkgSetting.getBlocked(userId) != blocked) {
-                    pkgSetting.setBlocked(blocked, userId);
-                    mSettings.writePackageRestrictionsLPr(userId);
-                    if (blocked) {
-                        sendRemoved = true;
-                    } else {
-                        sendAdded = true;
-                    }
-                }
-            }
-            if (sendAdded) {
-                sendPackageAddedForUser(packageName, pkgSetting, userId);
-                return true;
-            }
-            if (sendRemoved) {
-                killApplication(packageName, UserHandle.getUid(userId, pkgSetting.appId),
-                        "blocking pkg");
-                sendPackageBlockedForUser(packageName, pkgSetting, userId);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-        return false;
-    }
-
-    private void sendPackageBlockedForUser(String packageName, PackageSetting pkgSetting,
-            int userId) {
-        final PackageRemovedInfo info = new PackageRemovedInfo();
-        info.removedPackage = packageName;
-        info.removedUsers = new int[] {userId};
-        info.uid = UserHandle.getUid(userId, pkgSetting.appId);
-        info.sendBroadcast(false, false, false);
-    }
-
-    /**
-     * Returns true if application is not found or there was an error. Otherwise it returns
-     * the blocked state of the package for the given user.
-     */
-    @Override
-    public boolean getApplicationBlockedSettingAsUser(String packageName, int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USERS, null);
-        PackageSetting pkgSetting;
-        final int uid = Binder.getCallingUid();
-        if (UserHandle.getUserId(uid) != userId) {
-            mContext.enforceCallingPermission(
-                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                    "getApplicationBlocked for user " + userId);
-        }
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            // writer
-            synchronized (mPackages) {
-                pkgSetting = mSettings.mPackages.get(packageName);
-                if (pkgSetting == null) {
-                    return true;
-                }
-                return pkgSetting.getBlocked(userId);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-    }
-
-    /**
-     * @hide
-     */
-    @Override
-    public int installExistingPackageAsUser(String packageName, int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.INSTALL_PACKAGES,
-                null);
-        PackageSetting pkgSetting;
-        final int uid = Binder.getCallingUid();
-        if (UserHandle.getUserId(uid) != userId) {
-            mContext.enforceCallingPermission(
-                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                    "installExistingPackage for user " + userId);
-        }
-        if (isUserRestricted(userId, UserManager.DISALLOW_INSTALL_APPS)) {
-            return PackageManager.INSTALL_FAILED_USER_RESTRICTED;
-        }
-
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            boolean sendAdded = false;
-            Bundle extras = new Bundle(1);
-
-            // writer
-            synchronized (mPackages) {
-                pkgSetting = mSettings.mPackages.get(packageName);
-                if (pkgSetting == null) {
-                    return PackageManager.INSTALL_FAILED_INVALID_URI;
-                }
-                if (!pkgSetting.getInstalled(userId)) {
-                    pkgSetting.setInstalled(true, userId);
-                    pkgSetting.setBlocked(false, userId);
-                    mSettings.writePackageRestrictionsLPr(userId);
-                    sendAdded = true;
-                }
-            }
-
-            if (sendAdded) {
-                sendPackageAddedForUser(packageName, pkgSetting, userId);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-
-        return PackageManager.INSTALL_SUCCEEDED;
-    }
-
-    private boolean isUserRestricted(int userId, String restrictionKey) {
-        Bundle restrictions = sUserManager.getUserRestrictions(userId);
-        if (restrictions.getBoolean(restrictionKey, false)) {
-            Log.w(TAG, "User is restricted: " + restrictionKey);
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public void verifyPendingInstall(int id, int verificationCode) throws RemoteException {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
-                "Only package verification agents can verify applications");
-
-        final Message msg = mHandler.obtainMessage(PACKAGE_VERIFIED);
-        final PackageVerificationResponse response = new PackageVerificationResponse(
-                verificationCode, Binder.getCallingUid());
-        msg.arg1 = id;
-        msg.obj = response;
-        mHandler.sendMessage(msg);
-    }
-
-    @Override
-    public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
-            long millisecondsToDelay) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
-                "Only package verification agents can extend verification timeouts");
-
-        final PackageVerificationState state = mPendingVerification.get(id);
-        final PackageVerificationResponse response = new PackageVerificationResponse(
-                verificationCodeAtTimeout, Binder.getCallingUid());
-
-        if (millisecondsToDelay > PackageManager.MAXIMUM_VERIFICATION_TIMEOUT) {
-            millisecondsToDelay = PackageManager.MAXIMUM_VERIFICATION_TIMEOUT;
-        }
-        if (millisecondsToDelay < 0) {
-            millisecondsToDelay = 0;
-        }
-        if ((verificationCodeAtTimeout != PackageManager.VERIFICATION_ALLOW)
-                && (verificationCodeAtTimeout != PackageManager.VERIFICATION_REJECT)) {
-            verificationCodeAtTimeout = PackageManager.VERIFICATION_REJECT;
-        }
-
-        if ((state != null) && !state.timeoutExtended()) {
-            state.extendTimeout();
-
-            final Message msg = mHandler.obtainMessage(PACKAGE_VERIFIED);
-            msg.arg1 = id;
-            msg.obj = response;
-            mHandler.sendMessageDelayed(msg, millisecondsToDelay);
-        }
-    }
-
-    private void broadcastPackageVerified(int verificationId, Uri packageUri,
-            int verificationCode, UserHandle user) {
-        final Intent intent = new Intent(Intent.ACTION_PACKAGE_VERIFIED);
-        intent.setDataAndType(packageUri, PACKAGE_MIME_TYPE);
-        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-        intent.putExtra(PackageManager.EXTRA_VERIFICATION_ID, verificationId);
-        intent.putExtra(PackageManager.EXTRA_VERIFICATION_RESULT, verificationCode);
-
-        mContext.sendBroadcastAsUser(intent, user,
-                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT);
-    }
-
-    private ComponentName matchComponentForVerifier(String packageName,
-            List<ResolveInfo> receivers) {
-        ActivityInfo targetReceiver = null;
-
-        final int NR = receivers.size();
-        for (int i = 0; i < NR; i++) {
-            final ResolveInfo info = receivers.get(i);
-            if (info.activityInfo == null) {
-                continue;
-            }
-
-            if (packageName.equals(info.activityInfo.packageName)) {
-                targetReceiver = info.activityInfo;
-                break;
-            }
-        }
-
-        if (targetReceiver == null) {
-            return null;
-        }
-
-        return new ComponentName(targetReceiver.packageName, targetReceiver.name);
-    }
-
-    private List<ComponentName> matchVerifiers(PackageInfoLite pkgInfo,
-            List<ResolveInfo> receivers, final PackageVerificationState verificationState) {
-        if (pkgInfo.verifiers.length == 0) {
-            return null;
-        }
-
-        final int N = pkgInfo.verifiers.length;
-        final List<ComponentName> sufficientVerifiers = new ArrayList<ComponentName>(N + 1);
-        for (int i = 0; i < N; i++) {
-            final VerifierInfo verifierInfo = pkgInfo.verifiers[i];
-
-            final ComponentName comp = matchComponentForVerifier(verifierInfo.packageName,
-                    receivers);
-            if (comp == null) {
-                continue;
-            }
-
-            final int verifierUid = getUidForVerifier(verifierInfo);
-            if (verifierUid == -1) {
-                continue;
-            }
-
-            if (DEBUG_VERIFY) {
-                Slog.d(TAG, "Added sufficient verifier " + verifierInfo.packageName
-                        + " with the correct signature");
-            }
-            sufficientVerifiers.add(comp);
-            verificationState.addSufficientVerifier(verifierUid);
-        }
-
-        return sufficientVerifiers;
-    }
-
-    private int getUidForVerifier(VerifierInfo verifierInfo) {
-        synchronized (mPackages) {
-            final PackageParser.Package pkg = mPackages.get(verifierInfo.packageName);
-            if (pkg == null) {
-                return -1;
-            } else if (pkg.mSignatures.length != 1) {
-                Slog.i(TAG, "Verifier package " + verifierInfo.packageName
-                        + " has more than one signature; ignoring");
-                return -1;
-            }
-
-            /*
-             * If the public key of the package's signature does not match
-             * our expected public key, then this is a different package and
-             * we should skip.
-             */
-
-            final byte[] expectedPublicKey;
-            try {
-                final Signature verifierSig = pkg.mSignatures[0];
-                final PublicKey publicKey = verifierSig.getPublicKey();
-                expectedPublicKey = publicKey.getEncoded();
-            } catch (CertificateException e) {
-                return -1;
-            }
-
-            final byte[] actualPublicKey = verifierInfo.publicKey.getEncoded();
-
-            if (!Arrays.equals(actualPublicKey, expectedPublicKey)) {
-                Slog.i(TAG, "Verifier package " + verifierInfo.packageName
-                        + " does not have the expected public key; ignoring");
-                return -1;
-            }
-
-            return pkg.applicationInfo.uid;
-        }
-    }
-
-    public void finishPackageInstall(int token) {
-        enforceSystemOrRoot("Only the system is allowed to finish installs");
-
-        if (DEBUG_INSTALL) {
-            Slog.v(TAG, "BM finishing package install for " + token);
-        }
-
-        final Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0);
-        mHandler.sendMessage(msg);
-    }
-
-    /**
-     * Get the verification agent timeout.
-     *
-     * @return verification timeout in milliseconds
-     */
-    private long getVerificationTimeout() {
-        return android.provider.Settings.Global.getLong(mContext.getContentResolver(),
-                android.provider.Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
-                DEFAULT_VERIFICATION_TIMEOUT);
-    }
-
-    /**
-     * Get the default verification agent response code.
-     *
-     * @return default verification response code
-     */
-    private int getDefaultVerificationResponse() {
-        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
-                android.provider.Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE,
-                DEFAULT_VERIFICATION_RESPONSE);
-    }
-
-    /**
-     * Check whether or not package verification has been enabled.
-     *
-     * @return true if verification should be performed
-     */
-    private boolean isVerificationEnabled(int flags) {
-        if (!DEFAULT_VERIFY_ENABLE) {
-            return false;
-        }
-
-        // Check if installing from ADB
-        if ((flags & PackageManager.INSTALL_FROM_ADB) != 0) {
-            // Do not run verification in a test harness environment
-            if (ActivityManager.isRunningInTestHarness()) {
-                return false;
-            }
-            // Check if the developer does not want package verification for ADB installs
-            if (android.provider.Settings.Global.getInt(mContext.getContentResolver(),
-                    android.provider.Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) == 0) {
-                return false;
-            }
-        }
-
-        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
-                android.provider.Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 1;
-    }
-
-    /**
-     * Get the "allow unknown sources" setting.
-     *
-     * @return the current "allow unknown sources" setting
-     */
-    private int getUnknownSourcesSettings() {
-        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
-                android.provider.Settings.Global.INSTALL_NON_MARKET_APPS,
-                -1);
-    }
-
-    public void setInstallerPackageName(String targetPackage, String installerPackageName) {
-        final int uid = Binder.getCallingUid();
-        // writer
-        synchronized (mPackages) {
-            PackageSetting targetPackageSetting = mSettings.mPackages.get(targetPackage);
-            if (targetPackageSetting == null) {
-                throw new IllegalArgumentException("Unknown target package: " + targetPackage);
-            }
-
-            PackageSetting installerPackageSetting;
-            if (installerPackageName != null) {
-                installerPackageSetting = mSettings.mPackages.get(installerPackageName);
-                if (installerPackageSetting == null) {
-                    throw new IllegalArgumentException("Unknown installer package: "
-                            + installerPackageName);
-                }
-            } else {
-                installerPackageSetting = null;
-            }
-
-            Signature[] callerSignature;
-            Object obj = mSettings.getUserIdLPr(uid);
-            if (obj != null) {
-                if (obj instanceof SharedUserSetting) {
-                    callerSignature = ((SharedUserSetting)obj).signatures.mSignatures;
-                } else if (obj instanceof PackageSetting) {
-                    callerSignature = ((PackageSetting)obj).signatures.mSignatures;
-                } else {
-                    throw new SecurityException("Bad object " + obj + " for uid " + uid);
-                }
-            } else {
-                throw new SecurityException("Unknown calling uid " + uid);
-            }
-
-            // Verify: can't set installerPackageName to a package that is
-            // not signed with the same cert as the caller.
-            if (installerPackageSetting != null) {
-                if (compareSignatures(callerSignature,
-                        installerPackageSetting.signatures.mSignatures)
-                        != PackageManager.SIGNATURE_MATCH) {
-                    throw new SecurityException(
-                            "Caller does not have same cert as new installer package "
-                            + installerPackageName);
-                }
-            }
-
-            // Verify: if target already has an installer package, it must
-            // be signed with the same cert as the caller.
-            if (targetPackageSetting.installerPackageName != null) {
-                PackageSetting setting = mSettings.mPackages.get(
-                        targetPackageSetting.installerPackageName);
-                // If the currently set package isn't valid, then it's always
-                // okay to change it.
-                if (setting != null) {
-                    if (compareSignatures(callerSignature,
-                            setting.signatures.mSignatures)
-                            != PackageManager.SIGNATURE_MATCH) {
-                        throw new SecurityException(
-                                "Caller does not have same cert as old installer package "
-                                + targetPackageSetting.installerPackageName);
-                    }
-                }
-            }
-
-            // Okay!
-            targetPackageSetting.installerPackageName = installerPackageName;
-            scheduleWriteSettingsLocked();
-        }
-    }
-
-    private void processPendingInstall(final InstallArgs args, final int currentStatus) {
-        // Queue up an async operation since the package installation may take a little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                mHandler.removeCallbacks(this);
-                 // Result object to be returned
-                PackageInstalledInfo res = new PackageInstalledInfo();
-                res.returnCode = currentStatus;
-                res.uid = -1;
-                res.pkg = null;
-                res.removedInfo = new PackageRemovedInfo();
-                if (res.returnCode == PackageManager.INSTALL_SUCCEEDED) {
-                    args.doPreInstall(res.returnCode);
-                    synchronized (mInstallLock) {
-                        installPackageLI(args, true, res);
-                    }
-                    args.doPostInstall(res.returnCode, res.uid);
-                }
-
-                // A restore should be performed at this point if (a) the install
-                // succeeded, (b) the operation is not an update, and (c) the new
-                // package has a backupAgent defined.
-                final boolean update = res.removedInfo.removedPackage != null;
-                boolean doRestore = (!update
-                        && res.pkg != null
-                        && res.pkg.applicationInfo.backupAgentName != null);
-
-                // Set up the post-install work request bookkeeping.  This will be used
-                // and cleaned up by the post-install event handling regardless of whether
-                // there's a restore pass performed.  Token values are >= 1.
-                int token;
-                if (mNextInstallToken < 0) mNextInstallToken = 1;
-                token = mNextInstallToken++;
-
-                PostInstallData data = new PostInstallData(args, res);
-                mRunningInstalls.put(token, data);
-                if (DEBUG_INSTALL) Log.v(TAG, "+ starting restore round-trip " + token);
-
-                if (res.returnCode == PackageManager.INSTALL_SUCCEEDED && doRestore) {
-                    // Pass responsibility to the Backup Manager.  It will perform a
-                    // restore if appropriate, then pass responsibility back to the
-                    // Package Manager to run the post-install observer callbacks
-                    // and broadcasts.
-                    IBackupManager bm = IBackupManager.Stub.asInterface(
-                            ServiceManager.getService(Context.BACKUP_SERVICE));
-                    if (bm != null) {
-                        if (DEBUG_INSTALL) Log.v(TAG, "token " + token
-                                + " to BM for possible restore");
-                        try {
-                            bm.restoreAtInstall(res.pkg.applicationInfo.packageName, token);
-                        } catch (RemoteException e) {
-                            // can't happen; the backup manager is local
-                        } catch (Exception e) {
-                            Slog.e(TAG, "Exception trying to enqueue restore", e);
-                            doRestore = false;
-                        }
-                    } else {
-                        Slog.e(TAG, "Backup Manager not found!");
-                        doRestore = false;
-                    }
-                }
-
-                if (!doRestore) {
-                    // No restore possible, or the Backup Manager was mysteriously not
-                    // available -- just fire the post-install work request directly.
-                    if (DEBUG_INSTALL) Log.v(TAG, "No restore - queue post-install for " + token);
-                    Message msg = mHandler.obtainMessage(POST_INSTALL, token, 0);
-                    mHandler.sendMessage(msg);
-                }
-            }
-        });
-    }
-
-    private abstract class HandlerParams {
-        private static final int MAX_RETRIES = 4;
-
-        /**
-         * Number of times startCopy() has been attempted and had a non-fatal
-         * error.
-         */
-        private int mRetries = 0;
-
-        /** User handle for the user requesting the information or installation. */
-        private final UserHandle mUser;
-
-        HandlerParams(UserHandle user) {
-            mUser = user;
-        }
-
-        UserHandle getUser() {
-            return mUser;
-        }
-
-        final boolean startCopy() {
-            boolean res;
-            try {
-                if (DEBUG_INSTALL) Slog.i(TAG, "startCopy " + mUser + ": " + this);
-
-                if (++mRetries > MAX_RETRIES) {
-                    Slog.w(TAG, "Failed to invoke remote methods on default container service. Giving up");
-                    mHandler.sendEmptyMessage(MCS_GIVE_UP);
-                    handleServiceError();
-                    return false;
-                } else {
-                    handleStartCopy();
-                    res = true;
-                }
-            } catch (RemoteException e) {
-                if (DEBUG_INSTALL) Slog.i(TAG, "Posting install MCS_RECONNECT");
-                mHandler.sendEmptyMessage(MCS_RECONNECT);
-                res = false;
-            }
-            handleReturnCode();
-            return res;
-        }
-
-        final void serviceError() {
-            if (DEBUG_INSTALL) Slog.i(TAG, "serviceError");
-            handleServiceError();
-            handleReturnCode();
-        }
-
-        abstract void handleStartCopy() throws RemoteException;
-        abstract void handleServiceError();
-        abstract void handleReturnCode();
-    }
-
-    class MeasureParams extends HandlerParams {
-        private final PackageStats mStats;
-        private boolean mSuccess;
-
-        private final IPackageStatsObserver mObserver;
-
-        public MeasureParams(PackageStats stats, IPackageStatsObserver observer) {
-            super(new UserHandle(stats.userHandle));
-            mObserver = observer;
-            mStats = stats;
-        }
-
-        @Override
-        public String toString() {
-            return "MeasureParams{"
-                + Integer.toHexString(System.identityHashCode(this))
-                + " " + mStats.packageName + "}";
-        }
-
-        @Override
-        void handleStartCopy() throws RemoteException {
-            synchronized (mInstallLock) {
-                mSuccess = getPackageSizeInfoLI(mStats.packageName, mStats.userHandle, mStats);
-            }
-
-            final boolean mounted;
-            if (Environment.isExternalStorageEmulated()) {
-                mounted = true;
-            } else {
-                final String status = Environment.getExternalStorageState();
-                mounted = (Environment.MEDIA_MOUNTED.equals(status)
-                        || Environment.MEDIA_MOUNTED_READ_ONLY.equals(status));
-            }
-
-            if (mounted) {
-                final UserEnvironment userEnv = new UserEnvironment(mStats.userHandle);
-
-                mStats.externalCacheSize = calculateDirectorySize(mContainerService,
-                        userEnv.buildExternalStorageAppCacheDirs(mStats.packageName));
-
-                mStats.externalDataSize = calculateDirectorySize(mContainerService,
-                        userEnv.buildExternalStorageAppDataDirs(mStats.packageName));
-
-                // Always subtract cache size, since it's a subdirectory
-                mStats.externalDataSize -= mStats.externalCacheSize;
-
-                mStats.externalMediaSize = calculateDirectorySize(mContainerService,
-                        userEnv.buildExternalStorageAppMediaDirs(mStats.packageName));
-
-                mStats.externalObbSize = calculateDirectorySize(mContainerService,
-                        userEnv.buildExternalStorageAppObbDirs(mStats.packageName));
-            }
-        }
-
-        @Override
-        void handleReturnCode() {
-            if (mObserver != null) {
-                try {
-                    mObserver.onGetStatsCompleted(mStats, mSuccess);
-                } catch (RemoteException e) {
-                    Slog.i(TAG, "Observer no longer exists.");
-                }
-            }
-        }
-
-        @Override
-        void handleServiceError() {
-            Slog.e(TAG, "Could not measure application " + mStats.packageName
-                            + " external storage");
-        }
-    }
-
-    private static long calculateDirectorySize(IMediaContainerService mcs, File[] paths)
-            throws RemoteException {
-        long result = 0;
-        for (File path : paths) {
-            result += mcs.calculateDirectorySize(path.getAbsolutePath());
-        }
-        return result;
-    }
-
-    private static void clearDirectory(IMediaContainerService mcs, File[] paths) {
-        for (File path : paths) {
-            try {
-                mcs.clearDirectory(path.getAbsolutePath());
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    class InstallParams extends HandlerParams {
-        final IPackageInstallObserver observer;
-        int flags;
-
-        private final Uri mPackageURI;
-        final String installerPackageName;
-        final VerificationParams verificationParams;
-        private InstallArgs mArgs;
-        private int mRet;
-        private File mTempPackage;
-        final ContainerEncryptionParams encryptionParams;
-
-        InstallParams(Uri packageURI,
-                IPackageInstallObserver observer, int flags,
-                String installerPackageName, VerificationParams verificationParams,
-                ContainerEncryptionParams encryptionParams, UserHandle user) {
-            super(user);
-            this.mPackageURI = packageURI;
-            this.flags = flags;
-            this.observer = observer;
-            this.installerPackageName = installerPackageName;
-            this.verificationParams = verificationParams;
-            this.encryptionParams = encryptionParams;
-        }
-
-        @Override
-        public String toString() {
-            return "InstallParams{"
-                + Integer.toHexString(System.identityHashCode(this))
-                + " " + mPackageURI + "}";
-        }
-
-        public ManifestDigest getManifestDigest() {
-            if (verificationParams == null) {
-                return null;
-            }
-            return verificationParams.getManifestDigest();
-        }
-
-        private int installLocationPolicy(PackageInfoLite pkgLite, int flags) {
-            String packageName = pkgLite.packageName;
-            int installLocation = pkgLite.installLocation;
-            boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0;
-            // reader
-            synchronized (mPackages) {
-                PackageParser.Package pkg = mPackages.get(packageName);
-                if (pkg != null) {
-                    if ((flags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
-                        // Check for downgrading.
-                        if ((flags & PackageManager.INSTALL_ALLOW_DOWNGRADE) == 0) {
-                            if (pkgLite.versionCode < pkg.mVersionCode) {
-                                Slog.w(TAG, "Can't install update of " + packageName
-                                        + " update version " + pkgLite.versionCode
-                                        + " is older than installed version "
-                                        + pkg.mVersionCode);
-                                return PackageHelper.RECOMMEND_FAILED_VERSION_DOWNGRADE;
-                            }
-                        }
-                        // Check for updated system application.
-                        if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                            if (onSd) {
-                                Slog.w(TAG, "Cannot install update to system app on sdcard");
-                                return PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION;
-                            }
-                            return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
-                        } else {
-                            if (onSd) {
-                                // Install flag overrides everything.
-                                return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
-                            }
-                            // If current upgrade specifies particular preference
-                            if (installLocation == PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
-                                // Application explicitly specified internal.
-                                return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
-                            } else if (installLocation == PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL) {
-                                // App explictly prefers external. Let policy decide
-                            } else {
-                                // Prefer previous location
-                                if (isExternal(pkg)) {
-                                    return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
-                                }
-                                return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
-                            }
-                        }
-                    } else {
-                        // Invalid install. Return error code
-                        return PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS;
-                    }
-                }
-            }
-            // All the special cases have been taken care of.
-            // Return result based on recommended install location.
-            if (onSd) {
-                return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
-            }
-            return pkgLite.recommendedInstallLocation;
-        }
-
-        /*
-         * Invoke remote method to get package information and install
-         * location values. Override install location based on default
-         * policy if needed and then create install arguments based
-         * on the install location.
-         */
-        public void handleStartCopy() throws RemoteException {
-            int ret = PackageManager.INSTALL_SUCCEEDED;
-            final boolean onSd = (flags & PackageManager.INSTALL_EXTERNAL) != 0;
-            final boolean onInt = (flags & PackageManager.INSTALL_INTERNAL) != 0;
-            PackageInfoLite pkgLite = null;
-
-            if (onInt && onSd) {
-                // Check if both bits are set.
-                Slog.w(TAG, "Conflicting flags specified for installing on both internal and external");
-                ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
-            } else {
-                final long lowThreshold;
-
-                final DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) ServiceManager
-                        .getService(DeviceStorageMonitorService.SERVICE);
-                if (dsm == null) {
-                    Log.w(TAG, "Couldn't get low memory threshold; no free limit imposed");
-                    lowThreshold = 0L;
-                } else {
-                    lowThreshold = dsm.getMemoryLowThreshold();
-                }
-
-                try {
-                    mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, mPackageURI,
-                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
-
-                    final File packageFile;
-                    if (encryptionParams != null || !"file".equals(mPackageURI.getScheme())) {
-                        mTempPackage = createTempPackageFile(mDrmAppPrivateInstallDir);
-                        if (mTempPackage != null) {
-                            ParcelFileDescriptor out;
-                            try {
-                                out = ParcelFileDescriptor.open(mTempPackage,
-                                        ParcelFileDescriptor.MODE_READ_WRITE);
-                            } catch (FileNotFoundException e) {
-                                out = null;
-                                Slog.e(TAG, "Failed to create temporary file for : " + mPackageURI);
-                            }
-
-                            // Make a temporary file for decryption.
-                            ret = mContainerService
-                                    .copyResource(mPackageURI, encryptionParams, out);
-                            IoUtils.closeQuietly(out);
-
-                            packageFile = mTempPackage;
-
-                            FileUtils.setPermissions(packageFile.getAbsolutePath(),
-                                    FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP
-                                            | FileUtils.S_IROTH,
-                                    -1, -1);
-                        } else {
-                            packageFile = null;
-                        }
-                    } else {
-                        packageFile = new File(mPackageURI.getPath());
-                    }
-
-                    if (packageFile != null) {
-                        // Remote call to find out default install location
-                        final String packageFilePath = packageFile.getAbsolutePath();
-                        pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath, flags,
-                                lowThreshold);
-
-                        /*
-                         * If we have too little free space, try to free cache
-                         * before giving up.
-                         */
-                        if (pkgLite.recommendedInstallLocation
-                                == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE) {
-                            final long size = mContainerService.calculateInstalledSize(
-                                    packageFilePath, isForwardLocked());
-                            if (mInstaller.freeCache(size + lowThreshold) >= 0) {
-                                pkgLite = mContainerService.getMinimalPackageInfo(packageFilePath,
-                                        flags, lowThreshold);
-                            }
-                            /*
-                             * The cache free must have deleted the file we
-                             * downloaded to install.
-                             *
-                             * TODO: fix the "freeCache" call to not delete
-                             *       the file we care about.
-                             */
-                            if (pkgLite.recommendedInstallLocation
-                                    == PackageHelper.RECOMMEND_FAILED_INVALID_URI) {
-                                pkgLite.recommendedInstallLocation
-                                    = PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE;
-                            }
-                        }
-                    }
-                } finally {
-                    mContext.revokeUriPermission(mPackageURI,
-                            Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                }
-            }
-
-            if (ret == PackageManager.INSTALL_SUCCEEDED) {
-                int loc = pkgLite.recommendedInstallLocation;
-                if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_LOCATION) {
-                    ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
-                } else if (loc == PackageHelper.RECOMMEND_FAILED_ALREADY_EXISTS) {
-                    ret = PackageManager.INSTALL_FAILED_ALREADY_EXISTS;
-                } else if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE) {
-                    ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) {
-                    ret = PackageManager.INSTALL_FAILED_INVALID_APK;
-                } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_URI) {
-                    ret = PackageManager.INSTALL_FAILED_INVALID_URI;
-                } else if (loc == PackageHelper.RECOMMEND_MEDIA_UNAVAILABLE) {
-                    ret = PackageManager.INSTALL_FAILED_MEDIA_UNAVAILABLE;
-                } else {
-                    // Override with defaults if needed.
-                    loc = installLocationPolicy(pkgLite, flags);
-                    if (loc == PackageHelper.RECOMMEND_FAILED_VERSION_DOWNGRADE) {
-                        ret = PackageManager.INSTALL_FAILED_VERSION_DOWNGRADE;
-                    } else if (!onSd && !onInt) {
-                        // Override install location with flags
-                        if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) {
-                            // Set the flag to install on external media.
-                            flags |= PackageManager.INSTALL_EXTERNAL;
-                            flags &= ~PackageManager.INSTALL_INTERNAL;
-                        } else {
-                            // Make sure the flag for installing on external
-                            // media is unset
-                            flags |= PackageManager.INSTALL_INTERNAL;
-                            flags &= ~PackageManager.INSTALL_EXTERNAL;
-                        }
-                    }
-                }
-            }
-
-            final InstallArgs args = createInstallArgs(this);
-            mArgs = args;
-
-            if (ret == PackageManager.INSTALL_SUCCEEDED) {
-                 /*
-                 * ADB installs appear as UserHandle.USER_ALL, and can only be performed by
-                 * UserHandle.USER_OWNER, so use the package verifier for UserHandle.USER_OWNER.
-                 */
-                int userIdentifier = getUser().getIdentifier();
-                if (userIdentifier == UserHandle.USER_ALL
-                        && ((flags & PackageManager.INSTALL_FROM_ADB) != 0)) {
-                    userIdentifier = UserHandle.USER_OWNER;
-                }
-
-                /*
-                 * Determine if we have any installed package verifiers. If we
-                 * do, then we'll defer to them to verify the packages.
-                 */
-                final int requiredUid = mRequiredVerifierPackage == null ? -1
-                        : getPackageUid(mRequiredVerifierPackage, userIdentifier);
-                if (requiredUid != -1 && isVerificationEnabled(flags)) {
-                    final Intent verification = new Intent(
-                            Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
-                    verification.setDataAndType(getPackageUri(), PACKAGE_MIME_TYPE);
-                    verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
-
-                    final List<ResolveInfo> receivers = queryIntentReceivers(verification,
-                            PACKAGE_MIME_TYPE, PackageManager.GET_DISABLED_COMPONENTS,
-                            0 /* TODO: Which userId? */);
-
-                    if (DEBUG_VERIFY) {
-                        Slog.d(TAG, "Found " + receivers.size() + " verifiers for intent "
-                                + verification.toString() + " with " + pkgLite.verifiers.length
-                                + " optional verifiers");
-                    }
-
-                    final int verificationId = mPendingVerificationToken++;
-
-                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_ID, verificationId);
-
-                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALLER_PACKAGE,
-                            installerPackageName);
-
-                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALL_FLAGS, flags);
-
-                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_PACKAGE_NAME,
-                            pkgLite.packageName);
-
-                    verification.putExtra(PackageManager.EXTRA_VERIFICATION_VERSION_CODE,
-                            pkgLite.versionCode);
-
-                    if (verificationParams != null) {
-                        if (verificationParams.getVerificationURI() != null) {
-                           verification.putExtra(PackageManager.EXTRA_VERIFICATION_URI,
-                                 verificationParams.getVerificationURI());
-                        }
-                        if (verificationParams.getOriginatingURI() != null) {
-                            verification.putExtra(Intent.EXTRA_ORIGINATING_URI,
-                                  verificationParams.getOriginatingURI());
-                        }
-                        if (verificationParams.getReferrer() != null) {
-                            verification.putExtra(Intent.EXTRA_REFERRER,
-                                  verificationParams.getReferrer());
-                        }
-                        if (verificationParams.getOriginatingUid() >= 0) {
-                            verification.putExtra(Intent.EXTRA_ORIGINATING_UID,
-                                  verificationParams.getOriginatingUid());
-                        }
-                        if (verificationParams.getInstallerUid() >= 0) {
-                            verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALLER_UID,
-                                  verificationParams.getInstallerUid());
-                        }
-                    }
-
-                    final PackageVerificationState verificationState = new PackageVerificationState(
-                            requiredUid, args);
-
-                    mPendingVerification.append(verificationId, verificationState);
-
-                    final List<ComponentName> sufficientVerifiers = matchVerifiers(pkgLite,
-                            receivers, verificationState);
-
-                    /*
-                     * If any sufficient verifiers were listed in the package
-                     * manifest, attempt to ask them.
-                     */
-                    if (sufficientVerifiers != null) {
-                        final int N = sufficientVerifiers.size();
-                        if (N == 0) {
-                            Slog.i(TAG, "Additional verifiers required, but none installed.");
-                            ret = PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE;
-                        } else {
-                            for (int i = 0; i < N; i++) {
-                                final ComponentName verifierComponent = sufficientVerifiers.get(i);
-
-                                final Intent sufficientIntent = new Intent(verification);
-                                sufficientIntent.setComponent(verifierComponent);
-
-                                mContext.sendBroadcastAsUser(sufficientIntent, getUser());
-                            }
-                        }
-                    }
-
-                    final ComponentName requiredVerifierComponent = matchComponentForVerifier(
-                            mRequiredVerifierPackage, receivers);
-                    if (ret == PackageManager.INSTALL_SUCCEEDED
-                            && mRequiredVerifierPackage != null) {
-                        /*
-                         * Send the intent to the required verification agent,
-                         * but only start the verification timeout after the
-                         * target BroadcastReceivers have run.
-                         */
-                        verification.setComponent(requiredVerifierComponent);
-                        mContext.sendOrderedBroadcastAsUser(verification, getUser(),
-                                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
-                                new BroadcastReceiver() {
-                                    @Override
-                                    public void onReceive(Context context, Intent intent) {
-                                        final Message msg = mHandler
-                                                .obtainMessage(CHECK_PENDING_VERIFICATION);
-                                        msg.arg1 = verificationId;
-                                        mHandler.sendMessageDelayed(msg, getVerificationTimeout());
-                                    }
-                                }, null, 0, null, null);
-
-                        /*
-                         * We don't want the copy to proceed until verification
-                         * succeeds, so null out this field.
-                         */
-                        mArgs = null;
-                    }
-                } else {
-                    /*
-                     * No package verification is enabled, so immediately start
-                     * the remote call to initiate copy using temporary file.
-                     */
-                    ret = args.copyApk(mContainerService, true);
-                }
-            }
-
-            mRet = ret;
-        }
-
-        @Override
-        void handleReturnCode() {
-            // If mArgs is null, then MCS couldn't be reached. When it
-            // reconnects, it will try again to install. At that point, this
-            // will succeed.
-            if (mArgs != null) {
-                processPendingInstall(mArgs, mRet);
-
-                if (mTempPackage != null) {
-                    if (!mTempPackage.delete()) {
-                        Slog.w(TAG, "Couldn't delete temporary file: " +
-                                mTempPackage.getAbsolutePath());
-                    }
-                }
-            }
-        }
-
-        @Override
-        void handleServiceError() {
-            mArgs = createInstallArgs(this);
-            mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-        }
-
-        public boolean isForwardLocked() {
-            return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
-        }
-
-        public Uri getPackageUri() {
-            if (mTempPackage != null) {
-                return Uri.fromFile(mTempPackage);
-            } else {
-                return mPackageURI;
-            }
-        }
-    }
-
-    /*
-     * Utility class used in movePackage api.
-     * srcArgs and targetArgs are not set for invalid flags and make
-     * sure to do null checks when invoking methods on them.
-     * We probably want to return ErrorPrams for both failed installs
-     * and moves.
-     */
-    class MoveParams extends HandlerParams {
-        final IPackageMoveObserver observer;
-        final int flags;
-        final String packageName;
-        final InstallArgs srcArgs;
-        final InstallArgs targetArgs;
-        int uid;
-        int mRet;
-
-        MoveParams(InstallArgs srcArgs, IPackageMoveObserver observer, int flags,
-                String packageName, String dataDir, int uid, UserHandle user) {
-            super(user);
-            this.srcArgs = srcArgs;
-            this.observer = observer;
-            this.flags = flags;
-            this.packageName = packageName;
-            this.uid = uid;
-            if (srcArgs != null) {
-                Uri packageUri = Uri.fromFile(new File(srcArgs.getCodePath()));
-                targetArgs = createInstallArgs(packageUri, flags, packageName, dataDir);
-            } else {
-                targetArgs = null;
-            }
-        }
-
-        @Override
-        public String toString() {
-            return "MoveParams{"
-                + Integer.toHexString(System.identityHashCode(this))
-                + " " + packageName + "}";
-        }
-
-        public void handleStartCopy() throws RemoteException {
-            mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-            // Check for storage space on target medium
-            if (!targetArgs.checkFreeStorage(mContainerService)) {
-                Log.w(TAG, "Insufficient storage to install");
-                return;
-            }
-
-            mRet = srcArgs.doPreCopy();
-            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
-                return;
-            }
-
-            mRet = targetArgs.copyApk(mContainerService, false);
-            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
-                srcArgs.doPostCopy(uid);
-                return;
-            }
-
-            mRet = srcArgs.doPostCopy(uid);
-            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
-                return;
-            }
-
-            mRet = targetArgs.doPreInstall(mRet);
-            if (mRet != PackageManager.INSTALL_SUCCEEDED) {
-                return;
-            }
-
-            if (DEBUG_SD_INSTALL) {
-                StringBuilder builder = new StringBuilder();
-                if (srcArgs != null) {
-                    builder.append("src: ");
-                    builder.append(srcArgs.getCodePath());
-                }
-                if (targetArgs != null) {
-                    builder.append(" target : ");
-                    builder.append(targetArgs.getCodePath());
-                }
-                Log.i(TAG, builder.toString());
-            }
-        }
-
-        @Override
-        void handleReturnCode() {
-            targetArgs.doPostInstall(mRet, uid);
-            int currentStatus = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
-            if (mRet == PackageManager.INSTALL_SUCCEEDED) {
-                currentStatus = PackageManager.MOVE_SUCCEEDED;
-            } else if (mRet == PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE){
-                currentStatus = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
-            }
-            processPendingMove(this, currentStatus);
-        }
-
-        @Override
-        void handleServiceError() {
-            mRet = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-        }
-    }
-
-    /**
-     * Used during creation of InstallArgs
-     *
-     * @param flags package installation flags
-     * @return true if should be installed on external storage
-     */
-    private static boolean installOnSd(int flags) {
-        if ((flags & PackageManager.INSTALL_INTERNAL) != 0) {
-            return false;
-        }
-        if ((flags & PackageManager.INSTALL_EXTERNAL) != 0) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * Used during creation of InstallArgs
-     *
-     * @param flags package installation flags
-     * @return true if should be installed as forward locked
-     */
-    private static boolean installForwardLocked(int flags) {
-        return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
-    }
-
-    private InstallArgs createInstallArgs(InstallParams params) {
-        if (installOnSd(params.flags) || params.isForwardLocked()) {
-            return new AsecInstallArgs(params);
-        } else {
-            return new FileInstallArgs(params);
-        }
-    }
-
-    private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath,
-            String nativeLibraryPath) {
-        final boolean isInAsec;
-        if (installOnSd(flags)) {
-            /* Apps on SD card are always in ASEC containers. */
-            isInAsec = true;
-        } else if (installForwardLocked(flags)
-                && !fullCodePath.startsWith(mDrmAppPrivateInstallDir.getAbsolutePath())) {
-            /*
-             * Forward-locked apps are only in ASEC containers if they're the
-             * new style
-             */
-            isInAsec = true;
-        } else {
-            isInAsec = false;
-        }
-
-        if (isInAsec) {
-            return new AsecInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath,
-                    installOnSd(flags), installForwardLocked(flags));
-        } else {
-            return new FileInstallArgs(fullCodePath, fullResourcePath, nativeLibraryPath);
-        }
-    }
-
-    // Used by package mover
-    private InstallArgs createInstallArgs(Uri packageURI, int flags, String pkgName, String dataDir) {
-        if (installOnSd(flags) || installForwardLocked(flags)) {
-            String cid = getNextCodePath(packageURI.getPath(), pkgName, "/"
-                    + AsecInstallArgs.RES_FILE_NAME);
-            return new AsecInstallArgs(packageURI, cid, installOnSd(flags),
-                    installForwardLocked(flags));
-        } else {
-            return new FileInstallArgs(packageURI, pkgName, dataDir);
-        }
-    }
-
-    static abstract class InstallArgs {
-        final IPackageInstallObserver observer;
-        // Always refers to PackageManager flags only
-        final int flags;
-        final Uri packageURI;
-        final String installerPackageName;
-        final ManifestDigest manifestDigest;
-        final UserHandle user;
-
-        InstallArgs(Uri packageURI, IPackageInstallObserver observer, int flags,
-                String installerPackageName, ManifestDigest manifestDigest,
-                UserHandle user) {
-            this.packageURI = packageURI;
-            this.flags = flags;
-            this.observer = observer;
-            this.installerPackageName = installerPackageName;
-            this.manifestDigest = manifestDigest;
-            this.user = user;
-        }
-
-        abstract void createCopyFile();
-        abstract int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException;
-        abstract int doPreInstall(int status);
-        abstract boolean doRename(int status, String pkgName, String oldCodePath);
-
-        abstract int doPostInstall(int status, int uid);
-        abstract String getCodePath();
-        abstract String getResourcePath();
-        abstract String getNativeLibraryPath();
-        // Need installer lock especially for dex file removal.
-        abstract void cleanUpResourcesLI();
-        abstract boolean doPostDeleteLI(boolean delete);
-        abstract boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException;
-
-        /**
-         * Called before the source arguments are copied. This is used mostly
-         * for MoveParams when it needs to read the source file to put it in the
-         * destination.
-         */
-        int doPreCopy() {
-            return PackageManager.INSTALL_SUCCEEDED;
-        }
-
-        /**
-         * Called after the source arguments are copied. This is used mostly for
-         * MoveParams when it needs to read the source file to put it in the
-         * destination.
-         *
-         * @return
-         */
-        int doPostCopy(int uid) {
-            return PackageManager.INSTALL_SUCCEEDED;
-        }
-
-        protected boolean isFwdLocked() {
-            return (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
-        }
-
-        UserHandle getUser() {
-            return user;
-        }
-    }
-
-    class FileInstallArgs extends InstallArgs {
-        File installDir;
-        String codeFileName;
-        String resourceFileName;
-        String libraryPath;
-        boolean created = false;
-
-        FileInstallArgs(InstallParams params) {
-            super(params.getPackageUri(), params.observer, params.flags,
-                    params.installerPackageName, params.getManifestDigest(),
-                    params.getUser());
-        }
-
-        FileInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath) {
-            super(null, null, 0, null, null, null);
-            File codeFile = new File(fullCodePath);
-            installDir = codeFile.getParentFile();
-            codeFileName = fullCodePath;
-            resourceFileName = fullResourcePath;
-            libraryPath = nativeLibraryPath;
-        }
-
-        FileInstallArgs(Uri packageURI, String pkgName, String dataDir) {
-            super(packageURI, null, 0, null, null, null);
-            installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir;
-            String apkName = getNextCodePath(null, pkgName, ".apk");
-            codeFileName = new File(installDir, apkName + ".apk").getPath();
-            resourceFileName = getResourcePathFromCodePath();
-            libraryPath = new File(mAppLibInstallDir, pkgName).getPath();
-        }
-
-        boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException {
-            final long lowThreshold;
-
-            final DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) ServiceManager
-                    .getService(DeviceStorageMonitorService.SERVICE);
-            if (dsm == null) {
-                Log.w(TAG, "Couldn't get low memory threshold; no free limit imposed");
-                lowThreshold = 0L;
-            } else {
-                if (dsm.isMemoryLow()) {
-                    Log.w(TAG, "Memory is reported as being too low; aborting package install");
-                    return false;
-                }
-
-                lowThreshold = dsm.getMemoryLowThreshold();
-            }
-
-            try {
-                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
-                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                return imcs.checkInternalFreeStorage(packageURI, isFwdLocked(), lowThreshold);
-            } finally {
-                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-            }
-        }
-
-        String getCodePath() {
-            return codeFileName;
-        }
-
-        void createCopyFile() {
-            installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir;
-            codeFileName = createTempPackageFile(installDir).getPath();
-            resourceFileName = getResourcePathFromCodePath();
-            libraryPath = getLibraryPathFromCodePath();
-            created = true;
-        }
-
-        int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException {
-            if (temp) {
-                // Generate temp file name
-                createCopyFile();
-            }
-            // Get a ParcelFileDescriptor to write to the output file
-            File codeFile = new File(codeFileName);
-            if (!created) {
-                try {
-                    codeFile.createNewFile();
-                    // Set permissions
-                    if (!setPermissions()) {
-                        // Failed setting permissions.
-                        return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                    }
-                } catch (IOException e) {
-                   Slog.w(TAG, "Failed to create file " + codeFile);
-                   return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                }
-            }
-            ParcelFileDescriptor out = null;
-            try {
-                out = ParcelFileDescriptor.open(codeFile, ParcelFileDescriptor.MODE_READ_WRITE);
-            } catch (FileNotFoundException e) {
-                Slog.e(TAG, "Failed to create file descriptor for : " + codeFileName);
-                return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-            }
-            // Copy the resource now
-            int ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-            try {
-                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
-                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                ret = imcs.copyResource(packageURI, null, out);
-            } finally {
-                IoUtils.closeQuietly(out);
-                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-            }
-
-            if (isFwdLocked()) {
-                final File destResourceFile = new File(getResourcePath());
-
-                // Copy the public files
-                try {
-                    PackageHelper.extractPublicFiles(codeFileName, destResourceFile);
-                } catch (IOException e) {
-                    Slog.e(TAG, "Couldn't create a new zip file for the public parts of a"
-                            + " forward-locked app.");
-                    destResourceFile.delete();
-                    return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                }
-            }
-
-            final File nativeLibraryFile = new File(getNativeLibraryPath());
-            Slog.i(TAG, "Copying native libraries to " + nativeLibraryFile.getPath());
-            if (nativeLibraryFile.exists()) {
-                NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryFile);
-                nativeLibraryFile.delete();
-            }
-            try {
-                int copyRet = copyNativeLibrariesForInternalApp(codeFile, nativeLibraryFile);
-                if (copyRet != PackageManager.INSTALL_SUCCEEDED) {
-                    return copyRet;
-                }
-            } catch (IOException e) {
-                Slog.e(TAG, "Copying native libraries failed", e);
-                ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
-            }
-
-            return ret;
-        }
-
-        int doPreInstall(int status) {
-            if (status != PackageManager.INSTALL_SUCCEEDED) {
-                cleanUp();
-            }
-            return status;
-        }
-
-        boolean doRename(int status, final String pkgName, String oldCodePath) {
-            if (status != PackageManager.INSTALL_SUCCEEDED) {
-                cleanUp();
-                return false;
-            } else {
-                final File oldCodeFile = new File(getCodePath());
-                final File oldResourceFile = new File(getResourcePath());
-                final File oldLibraryFile = new File(getNativeLibraryPath());
-
-                // Rename APK file based on packageName
-                final String apkName = getNextCodePath(oldCodePath, pkgName, ".apk");
-                final File newCodeFile = new File(installDir, apkName + ".apk");
-                if (!oldCodeFile.renameTo(newCodeFile)) {
-                    return false;
-                }
-                codeFileName = newCodeFile.getPath();
-
-                // Rename public resource file if it's forward-locked.
-                final File newResFile = new File(getResourcePathFromCodePath());
-                if (isFwdLocked() && !oldResourceFile.renameTo(newResFile)) {
-                    return false;
-                }
-                resourceFileName = newResFile.getPath();
-
-                // Rename library path
-                final File newLibraryFile = new File(getLibraryPathFromCodePath());
-                if (newLibraryFile.exists()) {
-                    NativeLibraryHelper.removeNativeBinariesFromDirLI(newLibraryFile);
-                    newLibraryFile.delete();
-                }
-                if (!oldLibraryFile.renameTo(newLibraryFile)) {
-                    Slog.e(TAG, "Cannot rename native library directory "
-                            + oldLibraryFile.getPath() + " to " + newLibraryFile.getPath());
-                    return false;
-                }
-                libraryPath = newLibraryFile.getPath();
-
-                // Attempt to set permissions
-                if (!setPermissions()) {
-                    return false;
-                }
-
-                if (!SELinux.restorecon(newCodeFile)) {
-                    return false;
-                }
-
-                return true;
-            }
-        }
-
-        int doPostInstall(int status, int uid) {
-            if (status != PackageManager.INSTALL_SUCCEEDED) {
-                cleanUp();
-            }
-            return status;
-        }
-
-        String getResourcePath() {
-            return resourceFileName;
-        }
-
-        private String getResourcePathFromCodePath() {
-            final String codePath = getCodePath();
-            if (isFwdLocked()) {
-                final StringBuilder sb = new StringBuilder();
-
-                sb.append(mAppInstallDir.getPath());
-                sb.append('/');
-                sb.append(getApkName(codePath));
-                sb.append(".zip");
-
-                /*
-                 * If our APK is a temporary file, mark the resource as a
-                 * temporary file as well so it can be cleaned up after
-                 * catastrophic failure.
-                 */
-                if (codePath.endsWith(".tmp")) {
-                    sb.append(".tmp");
-                }
-
-                return sb.toString();
-            } else {
-                return codePath;
-            }
-        }
-
-        private String getLibraryPathFromCodePath() {
-            return new File(mAppLibInstallDir, getApkName(getCodePath())).getPath();
-        }
-
-        @Override
-        String getNativeLibraryPath() {
-            if (libraryPath == null) {
-                libraryPath = getLibraryPathFromCodePath();
-            }
-            return libraryPath;
-        }
-
-        private boolean cleanUp() {
-            boolean ret = true;
-            String sourceDir = getCodePath();
-            String publicSourceDir = getResourcePath();
-            if (sourceDir != null) {
-                File sourceFile = new File(sourceDir);
-                if (!sourceFile.exists()) {
-                    Slog.w(TAG, "Package source " + sourceDir + " does not exist.");
-                    ret = false;
-                }
-                // Delete application's code and resources
-                sourceFile.delete();
-            }
-            if (publicSourceDir != null && !publicSourceDir.equals(sourceDir)) {
-                final File publicSourceFile = new File(publicSourceDir);
-                if (!publicSourceFile.exists()) {
-                    Slog.w(TAG, "Package public source " + publicSourceFile + " does not exist.");
-                }
-                if (publicSourceFile.exists()) {
-                    publicSourceFile.delete();
-                }
-            }
-
-            if (libraryPath != null) {
-                File nativeLibraryFile = new File(libraryPath);
-                NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryFile);
-                if (!nativeLibraryFile.delete()) {
-                    Slog.w(TAG, "Couldn't delete native library directory " + libraryPath);
-                }
-            }
-
-            return ret;
-        }
-
-        void cleanUpResourcesLI() {
-            String sourceDir = getCodePath();
-            if (cleanUp()) {
-                int retCode = mInstaller.rmdex(sourceDir);
-                if (retCode < 0) {
-                    Slog.w(TAG, "Couldn't remove dex file for package: "
-                            +  " at location "
-                            + sourceDir + ", retcode=" + retCode);
-                    // we don't consider this to be a failure of the core package deletion
-                }
-            }
-        }
-
-        private boolean setPermissions() {
-            // TODO Do this in a more elegant way later on. for now just a hack
-            if (!isFwdLocked()) {
-                final int filePermissions =
-                    FileUtils.S_IRUSR|FileUtils.S_IWUSR|FileUtils.S_IRGRP
-                    |FileUtils.S_IROTH;
-                int retCode = FileUtils.setPermissions(getCodePath(), filePermissions, -1, -1);
-                if (retCode != 0) {
-                    Slog.e(TAG, "Couldn't set new package file permissions for " +
-                            getCodePath()
-                            + ". The return code was: " + retCode);
-                    // TODO Define new internal error
-                    return false;
-                }
-                return true;
-            }
-            return true;
-        }
-
-        boolean doPostDeleteLI(boolean delete) {
-            // XXX err, shouldn't we respect the delete flag?
-            cleanUpResourcesLI();
-            return true;
-        }
-    }
-
-    private boolean isAsecExternal(String cid) {
-        final String asecPath = PackageHelper.getSdFilesystem(cid);
-        return !asecPath.startsWith(mAsecInternalPath);
-    }
-
-    /**
-     * Extract the MountService "container ID" from the full code path of an
-     * .apk.
-     */
-    static String cidFromCodePath(String fullCodePath) {
-        int eidx = fullCodePath.lastIndexOf("/");
-        String subStr1 = fullCodePath.substring(0, eidx);
-        int sidx = subStr1.lastIndexOf("/");
-        return subStr1.substring(sidx+1, eidx);
-    }
-
-    class AsecInstallArgs extends InstallArgs {
-        static final String RES_FILE_NAME = "pkg.apk";
-        static final String PUBLIC_RES_FILE_NAME = "res.zip";
-
-        String cid;
-        String packagePath;
-        String resourcePath;
-        String libraryPath;
-
-        AsecInstallArgs(InstallParams params) {
-            super(params.getPackageUri(), params.observer, params.flags,
-                    params.installerPackageName, params.getManifestDigest(),
-                    params.getUser());
-        }
-
-        AsecInstallArgs(String fullCodePath, String fullResourcePath, String nativeLibraryPath,
-                boolean isExternal, boolean isForwardLocked) {
-            super(null, null, (isExternal ? PackageManager.INSTALL_EXTERNAL : 0)
-                    | (isForwardLocked ? PackageManager.INSTALL_FORWARD_LOCK : 0),
-                    null, null, null);
-            // Extract cid from fullCodePath
-            int eidx = fullCodePath.lastIndexOf("/");
-            String subStr1 = fullCodePath.substring(0, eidx);
-            int sidx = subStr1.lastIndexOf("/");
-            cid = subStr1.substring(sidx+1, eidx);
-            setCachePath(subStr1);
-        }
-
-        AsecInstallArgs(String cid, boolean isForwardLocked) {
-            super(null, null, (isAsecExternal(cid) ? PackageManager.INSTALL_EXTERNAL : 0)
-                    | (isForwardLocked ? PackageManager.INSTALL_FORWARD_LOCK : 0),
-                    null, null, null);
-            this.cid = cid;
-            setCachePath(PackageHelper.getSdDir(cid));
-        }
-
-        AsecInstallArgs(Uri packageURI, String cid, boolean isExternal, boolean isForwardLocked) {
-            super(packageURI, null, (isExternal ? PackageManager.INSTALL_EXTERNAL : 0)
-                    | (isForwardLocked ? PackageManager.INSTALL_FORWARD_LOCK : 0),
-                    null, null, null);
-            this.cid = cid;
-        }
-
-        void createCopyFile() {
-            cid = getTempContainerId();
-        }
-
-        boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException {
-            try {
-                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
-                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                return imcs.checkExternalFreeStorage(packageURI, isFwdLocked());
-            } finally {
-                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-            }
-        }
-
-        private final boolean isExternal() {
-            return (flags & PackageManager.INSTALL_EXTERNAL) != 0;
-        }
-
-        int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException {
-            if (temp) {
-                createCopyFile();
-            } else {
-                /*
-                 * Pre-emptively destroy the container since it's destroyed if
-                 * copying fails due to it existing anyway.
-                 */
-                PackageHelper.destroySdDir(cid);
-            }
-
-            final String newCachePath;
-            try {
-                mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
-                        Intent.FLAG_GRANT_READ_URI_PERMISSION);
-                newCachePath = imcs.copyResourceToContainer(packageURI, cid, getEncryptKey(),
-                        RES_FILE_NAME, PUBLIC_RES_FILE_NAME, isExternal(), isFwdLocked());
-            } finally {
-                mContext.revokeUriPermission(packageURI, Intent.FLAG_GRANT_READ_URI_PERMISSION);
-            }
-
-            if (newCachePath != null) {
-                setCachePath(newCachePath);
-                return PackageManager.INSTALL_SUCCEEDED;
-            } else {
-                return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
-            }
-        }
-
-        @Override
-        String getCodePath() {
-            return packagePath;
-        }
-
-        @Override
-        String getResourcePath() {
-            return resourcePath;
-        }
-
-        @Override
-        String getNativeLibraryPath() {
-            return libraryPath;
-        }
-
-        int doPreInstall(int status) {
-            if (status != PackageManager.INSTALL_SUCCEEDED) {
-                // Destroy container
-                PackageHelper.destroySdDir(cid);
-            } else {
-                boolean mounted = PackageHelper.isContainerMounted(cid);
-                if (!mounted) {
-                    String newCachePath = PackageHelper.mountSdDir(cid, getEncryptKey(),
-                            Process.SYSTEM_UID);
-                    if (newCachePath != null) {
-                        setCachePath(newCachePath);
-                    } else {
-                        return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
-                    }
-                }
-            }
-            return status;
-        }
-
-        boolean doRename(int status, final String pkgName,
-                String oldCodePath) {
-            String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME);
-            String newCachePath = null;
-            if (PackageHelper.isContainerMounted(cid)) {
-                // Unmount the container
-                if (!PackageHelper.unMountSdDir(cid)) {
-                    Slog.i(TAG, "Failed to unmount " + cid + " before renaming");
-                    return false;
-                }
-            }
-            if (!PackageHelper.renameSdDir(cid, newCacheId)) {
-                Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId +
-                        " which might be stale. Will try to clean up.");
-                // Clean up the stale container and proceed to recreate.
-                if (!PackageHelper.destroySdDir(newCacheId)) {
-                    Slog.e(TAG, "Very strange. Cannot clean up stale container " + newCacheId);
-                    return false;
-                }
-                // Successfully cleaned up stale container. Try to rename again.
-                if (!PackageHelper.renameSdDir(cid, newCacheId)) {
-                    Slog.e(TAG, "Failed to rename " + cid + " to " + newCacheId
-                            + " inspite of cleaning it up.");
-                    return false;
-                }
-            }
-            if (!PackageHelper.isContainerMounted(newCacheId)) {
-                Slog.w(TAG, "Mounting container " + newCacheId);
-                newCachePath = PackageHelper.mountSdDir(newCacheId,
-                        getEncryptKey(), Process.SYSTEM_UID);
-            } else {
-                newCachePath = PackageHelper.getSdDir(newCacheId);
-            }
-            if (newCachePath == null) {
-                Slog.w(TAG, "Failed to get cache path for  " + newCacheId);
-                return false;
-            }
-            Log.i(TAG, "Succesfully renamed " + cid +
-                    " to " + newCacheId +
-                    " at new path: " + newCachePath);
-            cid = newCacheId;
-            setCachePath(newCachePath);
-            return true;
-        }
-
-        private void setCachePath(String newCachePath) {
-            File cachePath = new File(newCachePath);
-            libraryPath = new File(cachePath, LIB_DIR_NAME).getPath();
-            packagePath = new File(cachePath, RES_FILE_NAME).getPath();
-
-            if (isFwdLocked()) {
-                resourcePath = new File(cachePath, PUBLIC_RES_FILE_NAME).getPath();
-            } else {
-                resourcePath = packagePath;
-            }
-        }
-
-        int doPostInstall(int status, int uid) {
-            if (status != PackageManager.INSTALL_SUCCEEDED) {
-                cleanUp();
-            } else {
-                final int groupOwner;
-                final String protectedFile;
-                if (isFwdLocked()) {
-                    groupOwner = UserHandle.getSharedAppGid(uid);
-                    protectedFile = RES_FILE_NAME;
-                } else {
-                    groupOwner = -1;
-                    protectedFile = null;
-                }
-
-                if (uid < Process.FIRST_APPLICATION_UID
-                        || !PackageHelper.fixSdPermissions(cid, groupOwner, protectedFile)) {
-                    Slog.e(TAG, "Failed to finalize " + cid);
-                    PackageHelper.destroySdDir(cid);
-                    return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
-                }
-
-                boolean mounted = PackageHelper.isContainerMounted(cid);
-                if (!mounted) {
-                    PackageHelper.mountSdDir(cid, getEncryptKey(), Process.myUid());
-                }
-            }
-            return status;
-        }
-
-        private void cleanUp() {
-            if (DEBUG_SD_INSTALL) Slog.i(TAG, "cleanUp");
-
-            // Destroy secure container
-            PackageHelper.destroySdDir(cid);
-        }
-
-        void cleanUpResourcesLI() {
-            String sourceFile = getCodePath();
-            // Remove dex file
-            int retCode = mInstaller.rmdex(sourceFile);
-            if (retCode < 0) {
-                Slog.w(TAG, "Couldn't remove dex file for package: "
-                        + " at location "
-                        + sourceFile.toString() + ", retcode=" + retCode);
-                // we don't consider this to be a failure of the core package deletion
-            }
-            cleanUp();
-        }
-
-        boolean matchContainer(String app) {
-            if (cid.startsWith(app)) {
-                return true;
-            }
-            return false;
-        }
-
-        String getPackageName() {
-            return getAsecPackageName(cid);
-        }
-
-        boolean doPostDeleteLI(boolean delete) {
-            boolean ret = false;
-            boolean mounted = PackageHelper.isContainerMounted(cid);
-            if (mounted) {
-                // Unmount first
-                ret = PackageHelper.unMountSdDir(cid);
-            }
-            if (ret && delete) {
-                cleanUpResourcesLI();
-            }
-            return ret;
-        }
-
-        @Override
-        int doPreCopy() {
-            if (isFwdLocked()) {
-                if (!PackageHelper.fixSdPermissions(cid,
-                        getPackageUid(DEFAULT_CONTAINER_PACKAGE, 0), RES_FILE_NAME)) {
-                    return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
-                }
-            }
-
-            return PackageManager.INSTALL_SUCCEEDED;
-        }
-
-        @Override
-        int doPostCopy(int uid) {
-            if (isFwdLocked()) {
-                if (uid < Process.FIRST_APPLICATION_UID
-                        || !PackageHelper.fixSdPermissions(cid, UserHandle.getSharedAppGid(uid),
-                                RES_FILE_NAME)) {
-                    Slog.e(TAG, "Failed to finalize " + cid);
-                    PackageHelper.destroySdDir(cid);
-                    return PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
-                }
-            }
-
-            return PackageManager.INSTALL_SUCCEEDED;
-        }
-    };
-
-    static String getAsecPackageName(String packageCid) {
-        int idx = packageCid.lastIndexOf("-");
-        if (idx == -1) {
-            return packageCid;
-        }
-        return packageCid.substring(0, idx);
-    }
-
-    // Utility method used to create code paths based on package name and available index.
-    private static String getNextCodePath(String oldCodePath, String prefix, String suffix) {
-        String idxStr = "";
-        int idx = 1;
-        // Fall back to default value of idx=1 if prefix is not
-        // part of oldCodePath
-        if (oldCodePath != null) {
-            String subStr = oldCodePath;
-            // Drop the suffix right away
-            if (subStr.endsWith(suffix)) {
-                subStr = subStr.substring(0, subStr.length() - suffix.length());
-            }
-            // If oldCodePath already contains prefix find out the
-            // ending index to either increment or decrement.
-            int sidx = subStr.lastIndexOf(prefix);
-            if (sidx != -1) {
-                subStr = subStr.substring(sidx + prefix.length());
-                if (subStr != null) {
-                    if (subStr.startsWith(INSTALL_PACKAGE_SUFFIX)) {
-                        subStr = subStr.substring(INSTALL_PACKAGE_SUFFIX.length());
-                    }
-                    try {
-                        idx = Integer.parseInt(subStr);
-                        if (idx <= 1) {
-                            idx++;
-                        } else {
-                            idx--;
-                        }
-                    } catch(NumberFormatException e) {
-                    }
-                }
-            }
-        }
-        idxStr = INSTALL_PACKAGE_SUFFIX + Integer.toString(idx);
-        return prefix + idxStr;
-    }
-
-    // Utility method used to ignore ADD/REMOVE events
-    // by directory observer.
-    private static boolean ignoreCodePath(String fullPathStr) {
-        String apkName = getApkName(fullPathStr);
-        int idx = apkName.lastIndexOf(INSTALL_PACKAGE_SUFFIX);
-        if (idx != -1 && ((idx+1) < apkName.length())) {
-            // Make sure the package ends with a numeral
-            String version = apkName.substring(idx+1);
-            try {
-                Integer.parseInt(version);
-                return true;
-            } catch (NumberFormatException e) {}
-        }
-        return false;
-    }
-    
-    // Utility method that returns the relative package path with respect
-    // to the installation directory. Like say for /data/data/com.test-1.apk
-    // string com.test-1 is returned.
-    static String getApkName(String codePath) {
-        if (codePath == null) {
-            return null;
-        }
-        int sidx = codePath.lastIndexOf("/");
-        int eidx = codePath.lastIndexOf(".");
-        if (eidx == -1) {
-            eidx = codePath.length();
-        } else if (eidx == 0) {
-            Slog.w(TAG, " Invalid code path, "+ codePath + " Not a valid apk name");
-            return null;
-        }
-        return codePath.substring(sidx+1, eidx);
-    }
-
-    class PackageInstalledInfo {
-        String name;
-        int uid;
-        // The set of users that originally had this package installed.
-        int[] origUsers;
-        // The set of users that now have this package installed.
-        int[] newUsers;
-        PackageParser.Package pkg;
-        int returnCode;
-        PackageRemovedInfo removedInfo;
-    }
-
-    /*
-     * Install a non-existing package.
-     */
-    private void installNewPackageLI(PackageParser.Package pkg,
-            int parseFlags, int scanMode, UserHandle user,
-            String installerPackageName, PackageInstalledInfo res) {
-        // Remember this for later, in case we need to rollback this install
-        String pkgName = pkg.packageName;
-
-        if (DEBUG_INSTALL) Slog.d(TAG, "installNewPackageLI: " + pkg);
-        boolean dataDirExists = getDataPathForPackage(pkg.packageName, 0).exists();
-        synchronized(mPackages) {
-            if (mSettings.mRenamedPackages.containsKey(pkgName)) {
-                // A package with the same name is already installed, though
-                // it has been renamed to an older name.  The package we
-                // are trying to install should be installed as an update to
-                // the existing one, but that has not been requested, so bail.
-                Slog.w(TAG, "Attempt to re-install " + pkgName
-                        + " without first uninstalling package running as "
-                        + mSettings.mRenamedPackages.get(pkgName));
-                res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS;
-                return;
-            }
-            if (mPackages.containsKey(pkgName) || mAppDirs.containsKey(pkg.mPath)) {
-                // Don't allow installation over an existing package with the same name.
-                Slog.w(TAG, "Attempt to re-install " + pkgName
-                        + " without first uninstalling.");
-                res.returnCode = PackageManager.INSTALL_FAILED_ALREADY_EXISTS;
-                return;
-            }
-        }
-        mLastScanError = PackageManager.INSTALL_SUCCEEDED;
-        PackageParser.Package newPackage = scanPackageLI(pkg, parseFlags, scanMode,
-                System.currentTimeMillis(), user);
-        if (newPackage == null) {
-            Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath);
-            if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) {
-                res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK;
-            }
-        } else {
-            updateSettingsLI(newPackage,
-                    installerPackageName,
-                    null, null,
-                    res);
-            // delete the partially installed application. the data directory will have to be
-            // restored if it was already existing
-            if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
-                // remove package from internal structures.  Note that we want deletePackageX to
-                // delete the package data and cache directories that it created in
-                // scanPackageLocked, unless those directories existed before we even tried to
-                // install.
-                deletePackageLI(pkgName, UserHandle.ALL, false, null, null,
-                        dataDirExists ? PackageManager.DELETE_KEEP_DATA : 0,
-                                res.removedInfo, true);
-            }
-        }
-    }
-
-    private void replacePackageLI(PackageParser.Package pkg,
-            int parseFlags, int scanMode, UserHandle user,
-            String installerPackageName, PackageInstalledInfo res) {
-
-        PackageParser.Package oldPackage;
-        String pkgName = pkg.packageName;
-        int[] allUsers;
-        boolean[] perUserInstalled;
-
-        // First find the old package info and check signatures
-        synchronized(mPackages) {
-            oldPackage = mPackages.get(pkgName);
-            if (DEBUG_INSTALL) Slog.d(TAG, "replacePackageLI: new=" + pkg + ", old=" + oldPackage);
-            if (compareSignatures(oldPackage.mSignatures, pkg.mSignatures)
-                    != PackageManager.SIGNATURE_MATCH) {
-                Slog.w(TAG, "New package has a different signature: " + pkgName);
-                res.returnCode = PackageManager.INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES;
-                return;
-            }
-
-            // In case of rollback, remember per-user/profile install state
-            PackageSetting ps = mSettings.mPackages.get(pkgName);
-            allUsers = sUserManager.getUserIds();
-            perUserInstalled = new boolean[allUsers.length];
-            for (int i = 0; i < allUsers.length; i++) {
-                perUserInstalled[i] = ps != null ? ps.getInstalled(allUsers[i]) : false;
-            }
-        }
-        boolean sysPkg = (isSystemApp(oldPackage));
-        if (sysPkg) {
-            replaceSystemPackageLI(oldPackage, pkg, parseFlags, scanMode,
-                    user, allUsers, perUserInstalled, installerPackageName, res);
-        } else {
-            replaceNonSystemPackageLI(oldPackage, pkg, parseFlags, scanMode,
-                    user, allUsers, perUserInstalled, installerPackageName, res);
-        }
-    }
-
-    private void replaceNonSystemPackageLI(PackageParser.Package deletedPackage,
-            PackageParser.Package pkg, int parseFlags, int scanMode, UserHandle user,
-            int[] allUsers, boolean[] perUserInstalled,
-            String installerPackageName, PackageInstalledInfo res) {
-        PackageParser.Package newPackage = null;
-        String pkgName = deletedPackage.packageName;
-        boolean deletedPkg = true;
-        boolean updatedSettings = false;
-
-        if (DEBUG_INSTALL) Slog.d(TAG, "replaceNonSystemPackageLI: new=" + pkg + ", old="
-                + deletedPackage);
-        long origUpdateTime;
-        if (pkg.mExtras != null) {
-            origUpdateTime = ((PackageSetting)pkg.mExtras).lastUpdateTime;
-        } else {
-            origUpdateTime = 0;
-        }
-
-        // First delete the existing package while retaining the data directory
-        if (!deletePackageLI(pkgName, null, true, null, null, PackageManager.DELETE_KEEP_DATA,
-                res.removedInfo, true)) {
-            // If the existing package wasn't successfully deleted
-            res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
-            deletedPkg = false;
-        } else {
-            // Successfully deleted the old package. Now proceed with re-installation
-            mLastScanError = PackageManager.INSTALL_SUCCEEDED;
-            newPackage = scanPackageLI(pkg, parseFlags, scanMode | SCAN_UPDATE_TIME,
-                    System.currentTimeMillis(), user);
-            if (newPackage == null) {
-                Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath);
-                if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) {
-                    res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK;
-                }
-            } else {
-                updateSettingsLI(newPackage,
-                        installerPackageName,
-                        allUsers, perUserInstalled,
-                        res);
-                updatedSettings = true;
-            }
-        }
-
-        if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
-            // remove package from internal structures.  Note that we want deletePackageX to
-            // delete the package data and cache directories that it created in
-            // scanPackageLocked, unless those directories existed before we even tried to
-            // install.
-            if(updatedSettings) {
-                if (DEBUG_INSTALL) Slog.d(TAG, "Install failed, rolling pack: " + pkgName);
-                deletePackageLI(
-                        pkgName, null, true, allUsers, perUserInstalled,
-                        PackageManager.DELETE_KEEP_DATA,
-                                res.removedInfo, true);
-            }
-            // Since we failed to install the new package we need to restore the old
-            // package that we deleted.
-            if(deletedPkg) {
-                if (DEBUG_INSTALL) Slog.d(TAG, "Install failed, reinstalling: " + deletedPackage);
-                File restoreFile = new File(deletedPackage.mPath);
-                // Parse old package
-                boolean oldOnSd = isExternal(deletedPackage);
-                int oldParseFlags  = mDefParseFlags | PackageParser.PARSE_CHATTY |
-                        (isForwardLocked(deletedPackage) ? PackageParser.PARSE_FORWARD_LOCK : 0) |
-                        (oldOnSd ? PackageParser.PARSE_ON_SDCARD : 0);
-                int oldScanMode = (oldOnSd ? 0 : SCAN_MONITOR) | SCAN_UPDATE_SIGNATURE
-                        | SCAN_UPDATE_TIME;
-                if (scanPackageLI(restoreFile, oldParseFlags, oldScanMode,
-                        origUpdateTime, null) == null) {
-                    Slog.e(TAG, "Failed to restore package : " + pkgName + " after failed upgrade");
-                    return;
-                }
-                // Restore of old package succeeded. Update permissions.
-                // writer
-                synchronized (mPackages) {
-                    updatePermissionsLPw(deletedPackage.packageName, deletedPackage,
-                            UPDATE_PERMISSIONS_ALL);
-                    // can downgrade to reader
-                    mSettings.writeLPr();
-                }
-                Slog.i(TAG, "Successfully restored package : " + pkgName + " after failed upgrade");
-            }
-        }
-    }
-
-    private void replaceSystemPackageLI(PackageParser.Package deletedPackage,
-            PackageParser.Package pkg, int parseFlags, int scanMode, UserHandle user,
-            int[] allUsers, boolean[] perUserInstalled,
-            String installerPackageName, PackageInstalledInfo res) {
-        if (DEBUG_INSTALL) Slog.d(TAG, "replaceSystemPackageLI: new=" + pkg
-                + ", old=" + deletedPackage);
-        PackageParser.Package newPackage = null;
-        boolean updatedSettings = false;
-        parseFlags |= PackageManager.INSTALL_REPLACE_EXISTING |
-                PackageParser.PARSE_IS_SYSTEM;
-        if ((deletedPackage.applicationInfo.flags&ApplicationInfo.FLAG_PRIVILEGED) != 0) {
-            parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
-        }
-        String packageName = deletedPackage.packageName;
-        res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
-        if (packageName == null) {
-            Slog.w(TAG, "Attempt to delete null packageName.");
-            return;
-        }
-        PackageParser.Package oldPkg;
-        PackageSetting oldPkgSetting;
-        // reader
-        synchronized (mPackages) {
-            oldPkg = mPackages.get(packageName);
-            oldPkgSetting = mSettings.mPackages.get(packageName);
-            if((oldPkg == null) || (oldPkg.applicationInfo == null) ||
-                    (oldPkgSetting == null)) {
-                Slog.w(TAG, "Couldn't find package:"+packageName+" information");
-                return;
-            }
-        }
-
-        killApplication(packageName, oldPkg.applicationInfo.uid, "replace sys pkg");
-
-        res.removedInfo.uid = oldPkg.applicationInfo.uid;
-        res.removedInfo.removedPackage = packageName;
-        // Remove existing system package
-        removePackageLI(oldPkgSetting, true);
-        // writer
-        synchronized (mPackages) {
-            if (!mSettings.disableSystemPackageLPw(packageName) && deletedPackage != null) {
-                // We didn't need to disable the .apk as a current system package,
-                // which means we are replacing another update that is already
-                // installed.  We need to make sure to delete the older one's .apk.
-                res.removedInfo.args = createInstallArgs(0,
-                        deletedPackage.applicationInfo.sourceDir,
-                        deletedPackage.applicationInfo.publicSourceDir,
-                        deletedPackage.applicationInfo.nativeLibraryDir);
-            } else {
-                res.removedInfo.args = null;
-            }
-        }
-        
-        // Successfully disabled the old package. Now proceed with re-installation
-        mLastScanError = PackageManager.INSTALL_SUCCEEDED;
-        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
-        newPackage = scanPackageLI(pkg, parseFlags, scanMode, 0, user);
-        if (newPackage == null) {
-            Slog.w(TAG, "Package couldn't be installed in " + pkg.mPath);
-            if ((res.returnCode=mLastScanError) == PackageManager.INSTALL_SUCCEEDED) {
-                res.returnCode = PackageManager.INSTALL_FAILED_INVALID_APK;
-            }
-        } else {
-            if (newPackage.mExtras != null) {
-                final PackageSetting newPkgSetting = (PackageSetting)newPackage.mExtras;
-                newPkgSetting.firstInstallTime = oldPkgSetting.firstInstallTime;
-                newPkgSetting.lastUpdateTime = System.currentTimeMillis();
-            }
-            updateSettingsLI(newPackage, installerPackageName, allUsers, perUserInstalled, res);
-            updatedSettings = true;
-        }
-
-        if (res.returnCode != PackageManager.INSTALL_SUCCEEDED) {
-            // Re installation failed. Restore old information
-            // Remove new pkg information
-            if (newPackage != null) {
-                removeInstalledPackageLI(newPackage, true);
-            }
-            // Add back the old system package
-            scanPackageLI(oldPkg, parseFlags, SCAN_MONITOR | SCAN_UPDATE_SIGNATURE, 0, user);
-            // Restore the old system information in Settings
-            synchronized(mPackages) {
-                if (updatedSettings) {
-                    mSettings.enableSystemPackageLPw(packageName);
-                    mSettings.setInstallerPackageName(packageName,
-                            oldPkgSetting.installerPackageName);
-                }
-                mSettings.writeLPr();
-            }
-        }
-    }
-
-    // Utility method used to move dex files during install.
-    private int moveDexFilesLI(PackageParser.Package newPackage) {
-        int retCode;
-        if ((newPackage.applicationInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0) {
-            retCode = mInstaller.movedex(newPackage.mScanPath, newPackage.mPath);
-            if (retCode != 0) {
-                if (mNoDexOpt) {
-                    /*
-                     * If we're in an engineering build, programs are lazily run
-                     * through dexopt. If the .dex file doesn't exist yet, it
-                     * will be created when the program is run next.
-                     */
-                    Slog.i(TAG, "dex file doesn't exist, skipping move: " + newPackage.mPath);
-                } else {
-                    Slog.e(TAG, "Couldn't rename dex file: " + newPackage.mPath);
-                    return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-                }
-            }
-        }
-        return PackageManager.INSTALL_SUCCEEDED;
-    }
-
-    private void updateSettingsLI(PackageParser.Package newPackage, String installerPackageName,
-            int[] allUsers, boolean[] perUserInstalled,
-            PackageInstalledInfo res) {
-        String pkgName = newPackage.packageName;
-        synchronized (mPackages) {
-            //write settings. the installStatus will be incomplete at this stage.
-            //note that the new package setting would have already been
-            //added to mPackages. It hasn't been persisted yet.
-            mSettings.setInstallStatus(pkgName, PackageSettingBase.PKG_INSTALL_INCOMPLETE);
-            mSettings.writeLPr();
-        }
-
-        if ((res.returnCode = moveDexFilesLI(newPackage))
-                != PackageManager.INSTALL_SUCCEEDED) {
-            // Discontinue if moving dex files failed.
-            return;
-        }
-
-        if (DEBUG_INSTALL) Slog.d(TAG, "New package installed in " + newPackage.mPath);
-
-        synchronized (mPackages) {
-            updatePermissionsLPw(newPackage.packageName, newPackage,
-                    UPDATE_PERMISSIONS_REPLACE_PKG | (newPackage.permissions.size() > 0
-                            ? UPDATE_PERMISSIONS_ALL : 0));
-            // For system-bundled packages, we assume that installing an upgraded version
-            // of the package implies that the user actually wants to run that new code,
-            // so we enable the package.
-            if (isSystemApp(newPackage)) {
-                // NB: implicit assumption that system package upgrades apply to all users
-                if (DEBUG_INSTALL) {
-                    Slog.d(TAG, "Implicitly enabling system package on upgrade: " + pkgName);
-                }
-                PackageSetting ps = mSettings.mPackages.get(pkgName);
-                if (ps != null) {
-                    if (res.origUsers != null) {
-                        for (int userHandle : res.origUsers) {
-                            ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT,
-                                    userHandle, installerPackageName);
-                        }
-                    }
-                    // Also convey the prior install/uninstall state
-                    if (allUsers != null && perUserInstalled != null) {
-                        for (int i = 0; i < allUsers.length; i++) {
-                            if (DEBUG_INSTALL) {
-                                Slog.d(TAG, "    user " + allUsers[i]
-                                        + " => " + perUserInstalled[i]);
-                            }
-                            ps.setInstalled(perUserInstalled[i], allUsers[i]);
-                        }
-                        // these install state changes will be persisted in the
-                        // upcoming call to mSettings.writeLPr().
-                    }
-                }
-            }
-            res.name = pkgName;
-            res.uid = newPackage.applicationInfo.uid;
-            res.pkg = newPackage;
-            mSettings.setInstallStatus(pkgName, PackageSettingBase.PKG_INSTALL_COMPLETE);
-            mSettings.setInstallerPackageName(pkgName, installerPackageName);
-            res.returnCode = PackageManager.INSTALL_SUCCEEDED;
-            //to update install status
-            mSettings.writeLPr();
-        }
-    }
-
-    private void installPackageLI(InstallArgs args,
-            boolean newInstall, PackageInstalledInfo res) {
-        int pFlags = args.flags;
-        String installerPackageName = args.installerPackageName;
-        File tmpPackageFile = new File(args.getCodePath());
-        boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0);
-        boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0);
-        boolean replace = false;
-        int scanMode = (onSd ? 0 : SCAN_MONITOR) | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE
-                | (newInstall ? SCAN_NEW_INSTALL : 0);
-        // Result object to be returned
-        res.returnCode = PackageManager.INSTALL_SUCCEEDED;
-
-        if (DEBUG_INSTALL) Slog.d(TAG, "installPackageLI: path=" + tmpPackageFile);
-        // Retrieve PackageSettings and parse package
-        int parseFlags = mDefParseFlags | PackageParser.PARSE_CHATTY
-                | (forwardLocked ? PackageParser.PARSE_FORWARD_LOCK : 0)
-                | (onSd ? PackageParser.PARSE_ON_SDCARD : 0);
-        PackageParser pp = new PackageParser(tmpPackageFile.getPath());
-        pp.setSeparateProcesses(mSeparateProcesses);
-        final PackageParser.Package pkg = pp.parsePackage(tmpPackageFile,
-                null, mMetrics, parseFlags);
-        if (pkg == null) {
-            res.returnCode = pp.getParseError();
-            return;
-        }
-        String pkgName = res.name = pkg.packageName;
-        if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) {
-            if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) {
-                res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY;
-                return;
-            }
-        }
-        if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) {
-            res.returnCode = pp.getParseError();
-            return;
-        }
-
-        /* If the installer passed in a manifest digest, compare it now. */
-        if (args.manifestDigest != null) {
-            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.returnCode = PackageManager.INSTALL_FAILED_PACKAGE_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;
-        boolean systemApp = false;
-        synchronized (mPackages) {
-            // Check if installing already existing package
-            if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
-                String oldName = mSettings.mRenamedPackages.get(pkgName);
-                if (pkg.mOriginalPackages != null
-                        && pkg.mOriginalPackages.contains(oldName)
-                        && mPackages.containsKey(oldName)) {
-                    // This package is derived from an original package,
-                    // and this device has been updating from that original
-                    // name.  We must continue using the original name, so
-                    // rename the new package here.
-                    pkg.setPackageName(oldName);
-                    pkgName = pkg.packageName;
-                    replace = true;
-                    if (DEBUG_INSTALL) Slog.d(TAG, "Replacing existing renamed package: oldName="
-                            + oldName + " pkgName=" + pkgName);
-                } else if (mPackages.containsKey(pkgName)) {
-                    // This package, under its official name, already exists
-                    // on the device; we should replace it.
-                    replace = true;
-                    if (DEBUG_INSTALL) Slog.d(TAG, "Replace existing pacakge: " + pkgName);
-                }
-            }
-            PackageSetting ps = mSettings.mPackages.get(pkgName);
-            if (ps != null) {
-                if (DEBUG_INSTALL) Slog.d(TAG, "Existing package: " + ps);
-                oldCodePath = mSettings.mPackages.get(pkgName).codePathString;
-                if (ps.pkg != null && ps.pkg.applicationInfo != null) {
-                    systemApp = (ps.pkg.applicationInfo.flags &
-                            ApplicationInfo.FLAG_SYSTEM) != 0;
-                }
-                res.origUsers = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
-            }
-        }
-
-        if (systemApp && onSd) {
-            // Disable updates to system apps on sdcard
-            Slog.w(TAG, "Cannot install updates to system apps on sdcard");
-            res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
-            return;
-        }
-
-        if (!args.doRename(res.returnCode, pkgName, oldCodePath)) {
-            res.returnCode = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
-            return;
-        }
-        // Set application objects path explicitly after the rename
-        setApplicationInfoPaths(pkg, args.getCodePath(), args.getResourcePath());
-        pkg.applicationInfo.nativeLibraryDir = args.getNativeLibraryPath();
-        if (replace) {
-            replacePackageLI(pkg, parseFlags, scanMode, args.user,
-                    installerPackageName, res);
-        } else {
-            installNewPackageLI(pkg, parseFlags, scanMode | SCAN_DELETE_DATA_ON_FAILURES, args.user,
-                    installerPackageName, res);
-        }
-        synchronized (mPackages) {
-            final PackageSetting ps = mSettings.mPackages.get(pkgName);
-            if (ps != null) {
-                res.newUsers = ps.queryInstalledUsers(sUserManager.getUserIds(), true);
-            }
-        }
-    }
-
-    private static boolean isForwardLocked(PackageParser.Package pkg) {
-        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0;
-    }
-
-
-    private boolean isForwardLocked(PackageSetting ps) {
-        return (ps.pkgFlags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0;
-    }
-
-    private static boolean isExternal(PackageParser.Package pkg) {
-        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
-    }
-
-    private static boolean isExternal(PackageSetting ps) {
-        return (ps.pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
-    }
-
-    private static boolean isSystemApp(PackageParser.Package pkg) {
-        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-    }
-
-    private static boolean isPrivilegedApp(PackageParser.Package pkg) {
-        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_PRIVILEGED) != 0;
-    }
-
-    private static boolean isSystemApp(ApplicationInfo info) {
-        return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
-    }
-
-    private static boolean isSystemApp(PackageSetting ps) {
-        return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
-    }
-
-    private static boolean isUpdatedSystemApp(PackageSetting ps) {
-        return (ps.pkgFlags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
-    }
-
-    private static boolean isUpdatedSystemApp(PackageParser.Package pkg) {
-        return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
-    }
-
-    private int packageFlagsToInstallFlags(PackageSetting ps) {
-        int installFlags = 0;
-        if (isExternal(ps)) {
-            installFlags |= PackageManager.INSTALL_EXTERNAL;
-        }
-        if (isForwardLocked(ps)) {
-            installFlags |= PackageManager.INSTALL_FORWARD_LOCK;
-        }
-        return installFlags;
-    }
-
-    private void deleteTempPackageFiles() {
-        final FilenameFilter filter = new FilenameFilter() {
-            public boolean accept(File dir, String name) {
-                return name.startsWith("vmdl") && name.endsWith(".tmp");
-            }
-        };
-        deleteTempPackageFilesInDirectory(mAppInstallDir, filter);
-        deleteTempPackageFilesInDirectory(mDrmAppPrivateInstallDir, filter);
-    }
-
-    private static final void deleteTempPackageFilesInDirectory(File directory,
-            FilenameFilter filter) {
-        final String[] tmpFilesList = directory.list(filter);
-        if (tmpFilesList == null) {
-            return;
-        }
-        for (int i = 0; i < tmpFilesList.length; i++) {
-            final File tmpFile = new File(directory, tmpFilesList[i]);
-            tmpFile.delete();
-        }
-    }
-
-    private File createTempPackageFile(File installDir) {
-        File tmpPackageFile;
-        try {
-            tmpPackageFile = File.createTempFile("vmdl", ".tmp", installDir);
-        } catch (IOException e) {
-            Slog.e(TAG, "Couldn't create temp file for downloaded package file.");
-            return null;
-        }
-        try {
-            FileUtils.setPermissions(
-                    tmpPackageFile.getCanonicalPath(), FileUtils.S_IRUSR|FileUtils.S_IWUSR,
-                    -1, -1);
-            if (!SELinux.restorecon(tmpPackageFile)) {
-                return null;
-            }
-        } catch (IOException e) {
-            Slog.e(TAG, "Trouble getting the canoncical path for a temp file.");
-            return null;
-        }
-        return tmpPackageFile;
-    }
-
-    @Override
-    public void deletePackageAsUser(final String packageName,
-                                    final IPackageDeleteObserver observer,
-                                    final int userId, final int flags) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.DELETE_PACKAGES, null);
-        final int uid = Binder.getCallingUid();
-        if (UserHandle.getUserId(uid) != userId) {
-            mContext.enforceCallingPermission(
-                    android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
-                    "deletePackage for user " + userId);
-        }
-        if (isUserRestricted(userId, UserManager.DISALLOW_UNINSTALL_APPS)) {
-            try {
-                observer.packageDeleted(packageName, PackageManager.DELETE_FAILED_USER_RESTRICTED);
-            } catch (RemoteException re) {
-            }
-            return;
-        }
-
-        if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageAsUser: pkg=" + packageName + " user=" + userId);
-        // Queue up an async operation since the package deletion may take a little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                mHandler.removeCallbacks(this);
-                final int returnCode = deletePackageX(packageName, userId, flags);
-                if (observer != null) {
-                    try {
-                        observer.packageDeleted(packageName, returnCode);
-                    } catch (RemoteException e) {
-                        Log.i(TAG, "Observer no longer exists.");
-                    } //end catch
-                } //end if
-            } //end run
-        });
-    }
-
-    private boolean isPackageDeviceAdmin(String packageName, int userId) {
-        IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface(
-                ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
-        try {
-            if (dpm != null && (dpm.packageHasActiveAdmins(packageName, userId)
-                    || dpm.isDeviceOwner(packageName))) {
-                return true;
-            }
-        } catch (RemoteException e) {
-        }
-        return false;
-    }
-
-    /**
-     *  This method is an internal method that could be get invoked either
-     *  to delete an installed package or to clean up a failed installation.
-     *  After deleting an installed package, a broadcast is sent to notify any
-     *  listeners that the package has been installed. For cleaning up a failed
-     *  installation, the broadcast is not necessary since the package's
-     *  installation wouldn't have sent the initial broadcast either
-     *  The key steps in deleting a package are
-     *  deleting the package information in internal structures like mPackages,
-     *  deleting the packages base directories through installd
-     *  updating mSettings to reflect current status
-     *  persisting settings for later use
-     *  sending a broadcast if necessary
-     */
-    private int deletePackageX(String packageName, int userId, int flags) {
-        final PackageRemovedInfo info = new PackageRemovedInfo();
-        final boolean res;
-
-        if (isPackageDeviceAdmin(packageName, userId)) {
-            Slog.w(TAG, "Not removing package " + packageName + ": has active device admin");
-            return PackageManager.DELETE_FAILED_DEVICE_POLICY_MANAGER;
-        }
-
-        boolean removedForAllUsers = false;
-        boolean systemUpdate = false;
-
-        // for the uninstall-updates case and restricted profiles, remember the per-
-        // userhandle installed state
-        int[] allUsers;
-        boolean[] perUserInstalled;
-        synchronized (mPackages) {
-            PackageSetting ps = mSettings.mPackages.get(packageName);
-            allUsers = sUserManager.getUserIds();
-            perUserInstalled = new boolean[allUsers.length];
-            for (int i = 0; i < allUsers.length; i++) {
-                perUserInstalled[i] = ps != null ? ps.getInstalled(allUsers[i]) : false;
-            }
-        }
-
-        synchronized (mInstallLock) {
-            if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageX: pkg=" + packageName + " user=" + userId);
-            res = deletePackageLI(packageName,
-                    (flags & PackageManager.DELETE_ALL_USERS) != 0
-                            ? UserHandle.ALL : new UserHandle(userId),
-                    true, allUsers, perUserInstalled,
-                    flags | REMOVE_CHATTY, info, true);
-            systemUpdate = info.isRemovedPackageSystemUpdate;
-            if (res && !systemUpdate && mPackages.get(packageName) == null) {
-                removedForAllUsers = true;
-            }
-            if (DEBUG_REMOVE) Slog.d(TAG, "delete res: systemUpdate=" + systemUpdate
-                    + " removedForAllUsers=" + removedForAllUsers);
-        }
-
-        if (res) {
-            info.sendBroadcast(true, systemUpdate, removedForAllUsers);
-
-            // If the removed package was a system update, the old system package
-            // was re-enabled; we need to broadcast this information
-            if (systemUpdate) {
-                Bundle extras = new Bundle(1);
-                extras.putInt(Intent.EXTRA_UID, info.removedAppId >= 0
-                        ? info.removedAppId : info.uid);
-                extras.putBoolean(Intent.EXTRA_REPLACING, true);
-
-                sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED, packageName,
-                        extras, null, null, null);
-                sendPackageBroadcast(Intent.ACTION_PACKAGE_REPLACED, packageName,
-                        extras, null, null, null);
-                sendPackageBroadcast(Intent.ACTION_MY_PACKAGE_REPLACED, null,
-                        null, packageName, null, null);
-            }
-        }
-        // Force a gc here.
-        Runtime.getRuntime().gc();
-        // Delete the resources here after sending the broadcast to let
-        // other processes clean up before deleting resources.
-        if (info.args != null) {
-            synchronized (mInstallLock) {
-                info.args.doPostDeleteLI(true);
-            }
-        }
-
-        return res ? PackageManager.DELETE_SUCCEEDED : PackageManager.DELETE_FAILED_INTERNAL_ERROR;
-    }
-
-    static class PackageRemovedInfo {
-        String removedPackage;
-        int uid = -1;
-        int removedAppId = -1;
-        int[] removedUsers = null;
-        boolean isRemovedPackageSystemUpdate = false;
-        // Clean up resources deleted packages.
-        InstallArgs args = null;
-
-        void sendBroadcast(boolean fullRemove, boolean replacing, boolean removedForAllUsers) {
-            Bundle extras = new Bundle(1);
-            extras.putInt(Intent.EXTRA_UID, removedAppId >= 0 ? removedAppId : uid);
-            extras.putBoolean(Intent.EXTRA_DATA_REMOVED, fullRemove);
-            if (replacing) {
-                extras.putBoolean(Intent.EXTRA_REPLACING, true);
-            }
-            extras.putBoolean(Intent.EXTRA_REMOVED_FOR_ALL_USERS, removedForAllUsers);
-            if (removedPackage != null) {
-                sendPackageBroadcast(Intent.ACTION_PACKAGE_REMOVED, removedPackage,
-                        extras, null, null, removedUsers);
-                if (fullRemove && !replacing) {
-                    sendPackageBroadcast(Intent.ACTION_PACKAGE_FULLY_REMOVED, removedPackage,
-                            extras, null, null, removedUsers);
-                }
-            }
-            if (removedAppId >= 0) {
-                sendPackageBroadcast(Intent.ACTION_UID_REMOVED, null, extras, null, null,
-                        removedUsers);
-            }
-        }
-    }
-
-    /*
-     * This method deletes the package from internal data structures. If the DONT_DELETE_DATA
-     * flag is not set, the data directory is removed as well.
-     * make sure this flag is set for partially installed apps. If not its meaningless to
-     * delete a partially installed application.
-     */
-    private void removePackageDataLI(PackageSetting ps,
-            int[] allUserHandles, boolean[] perUserInstalled,
-            PackageRemovedInfo outInfo, int flags, boolean writeSettings) {
-        String packageName = ps.name;
-        if (DEBUG_REMOVE) Slog.d(TAG, "removePackageDataLI: " + ps);
-        removePackageLI(ps, (flags&REMOVE_CHATTY) != 0);
-        // Retrieve object to delete permissions for shared user later on
-        final PackageSetting deletedPs;
-        // reader
-        synchronized (mPackages) {
-            deletedPs = mSettings.mPackages.get(packageName);
-            if (outInfo != null) {
-                outInfo.removedPackage = packageName;
-                outInfo.removedUsers = deletedPs != null
-                        ? deletedPs.queryInstalledUsers(sUserManager.getUserIds(), true)
-                        : null;
-            }
-        }
-        if ((flags&PackageManager.DELETE_KEEP_DATA) == 0) {
-            removeDataDirsLI(packageName);
-            schedulePackageCleaning(packageName, UserHandle.USER_ALL, true);
-        }
-        // writer
-        synchronized (mPackages) {
-            if (deletedPs != null) {
-                if ((flags&PackageManager.DELETE_KEEP_DATA) == 0) {
-                    if (outInfo != null) {
-                        outInfo.removedAppId = mSettings.removePackageLPw(packageName);
-                    }
-                    if (deletedPs != null) {
-                        updatePermissionsLPw(deletedPs.name, null, 0);
-                        if (deletedPs.sharedUser != null) {
-                            // remove permissions associated with package
-                            mSettings.updateSharedUserPermsLPw(deletedPs, mGlobalGids);
-                        }
-                    }
-                    clearPackagePreferredActivitiesLPw(deletedPs.name, UserHandle.USER_ALL);
-                }
-                // make sure to preserve per-user disabled state if this removal was just
-                // a downgrade of a system app to the factory package
-                if (allUserHandles != null && perUserInstalled != null) {
-                    if (DEBUG_REMOVE) {
-                        Slog.d(TAG, "Propagating install state across downgrade");
-                    }
-                    for (int i = 0; i < allUserHandles.length; i++) {
-                        if (DEBUG_REMOVE) {
-                            Slog.d(TAG, "    user " + allUserHandles[i]
-                                    + " => " + perUserInstalled[i]);
-                        }
-                        ps.setInstalled(perUserInstalled[i], allUserHandles[i]);
-                    }
-                }
-            }
-            // can downgrade to reader
-            if (writeSettings) {
-                // Save settings now
-                mSettings.writeLPr();
-            }
-        }
-        if (outInfo != null) {
-            // A user ID was deleted here. Go through all users and remove it
-            // from KeyStore.
-            removeKeystoreDataIfNeeded(UserHandle.USER_ALL, outInfo.removedAppId);
-        }
-    }
-
-    static boolean locationIsPrivileged(File path) {
-        try {
-            final String privilegedAppDir = new File(Environment.getRootDirectory(), "priv-app")
-                    .getCanonicalPath();
-            return path.getCanonicalPath().startsWith(privilegedAppDir);
-        } catch (IOException e) {
-            Slog.e(TAG, "Unable to access code path " + path);
-        }
-        return false;
-    }
-
-    /*
-     * Tries to delete system package.
-     */
-    private boolean deleteSystemPackageLI(PackageSetting newPs,
-            int[] allUserHandles, boolean[] perUserInstalled,
-            int flags, PackageRemovedInfo outInfo, boolean writeSettings) {
-        final boolean applyUserRestrictions
-                = (allUserHandles != null) && (perUserInstalled != null);
-        PackageSetting disabledPs = null;
-        // Confirm if the system package has been updated
-        // An updated system app can be deleted. This will also have to restore
-        // the system pkg from system partition
-        // reader
-        synchronized (mPackages) {
-            disabledPs = mSettings.getDisabledSystemPkgLPr(newPs.name);
-        }
-        if (DEBUG_REMOVE) Slog.d(TAG, "deleteSystemPackageLI: newPs=" + newPs
-                + " disabledPs=" + disabledPs);
-        if (disabledPs == null) {
-            Slog.w(TAG, "Attempt to delete unknown system package "+ newPs.name);
-            return false;
-        } else if (DEBUG_REMOVE) {
-            Slog.d(TAG, "Deleting system pkg from data partition");
-        }
-        if (DEBUG_REMOVE) {
-            if (applyUserRestrictions) {
-                Slog.d(TAG, "Remembering install states:");
-                for (int i = 0; i < allUserHandles.length; i++) {
-                    Slog.d(TAG, "   u=" + allUserHandles[i] + " inst=" + perUserInstalled[i]);
-                }
-            }
-        }
-        // Delete the updated package
-        outInfo.isRemovedPackageSystemUpdate = true;
-        if (disabledPs.versionCode < newPs.versionCode) {
-            // Delete data for downgrades
-            flags &= ~PackageManager.DELETE_KEEP_DATA;
-        } else {
-            // Preserve data by setting flag
-            flags |= PackageManager.DELETE_KEEP_DATA;
-        }
-        boolean ret = deleteInstalledPackageLI(newPs, true, flags,
-                allUserHandles, perUserInstalled, outInfo, writeSettings);
-        if (!ret) {
-            return false;
-        }
-        // writer
-        synchronized (mPackages) {
-            // Reinstate the old system package
-            mSettings.enableSystemPackageLPw(newPs.name);
-            // Remove any native libraries from the upgraded package.
-            NativeLibraryHelper.removeNativeBinariesLI(newPs.nativeLibraryPathString);
-        }
-        // Install the system package
-        if (DEBUG_REMOVE) Slog.d(TAG, "Re-installing system package: " + disabledPs);
-        int parseFlags = PackageParser.PARSE_MUST_BE_APK | PackageParser.PARSE_IS_SYSTEM;
-        if (locationIsPrivileged(disabledPs.codePath)) {
-            parseFlags |= PackageParser.PARSE_IS_PRIVILEGED;
-        }
-        PackageParser.Package newPkg = scanPackageLI(disabledPs.codePath,
-                parseFlags, SCAN_MONITOR | SCAN_NO_PATHS, 0, null);
-
-        if (newPkg == null) {
-            Slog.w(TAG, "Failed to restore system package:" + newPs.name
-                    + " with error:" + mLastScanError);
-            return false;
-        }
-        // writer
-        synchronized (mPackages) {
-            updatePermissionsLPw(newPkg.packageName, newPkg,
-                    UPDATE_PERMISSIONS_ALL | UPDATE_PERMISSIONS_REPLACE_PKG);
-            if (applyUserRestrictions) {
-                if (DEBUG_REMOVE) {
-                    Slog.d(TAG, "Propagating install state across reinstall");
-                }
-                PackageSetting ps = mSettings.mPackages.get(newPkg.packageName);
-                for (int i = 0; i < allUserHandles.length; i++) {
-                    if (DEBUG_REMOVE) {
-                        Slog.d(TAG, "    user " + allUserHandles[i]
-                                + " => " + perUserInstalled[i]);
-                    }
-                    ps.setInstalled(perUserInstalled[i], allUserHandles[i]);
-                }
-                // Regardless of writeSettings we need to ensure that this restriction
-                // state propagation is persisted
-                mSettings.writeAllUsersPackageRestrictionsLPr();
-            }
-            // can downgrade to reader here
-            if (writeSettings) {
-                mSettings.writeLPr();
-            }
-        }
-        return true;
-    }
-
-    private boolean deleteInstalledPackageLI(PackageSetting ps,
-            boolean deleteCodeAndResources, int flags,
-            int[] allUserHandles, boolean[] perUserInstalled,
-            PackageRemovedInfo outInfo, boolean writeSettings) {
-        if (outInfo != null) {
-            outInfo.uid = ps.appId;
-        }
-
-        // Delete package data from internal structures and also remove data if flag is set
-        removePackageDataLI(ps, allUserHandles, perUserInstalled, outInfo, flags, writeSettings);
-
-        // Delete application code and resources
-        if (deleteCodeAndResources && (outInfo != null)) {
-            outInfo.args = createInstallArgs(packageFlagsToInstallFlags(ps), ps.codePathString,
-                    ps.resourcePathString, ps.nativeLibraryPathString);
-        }
-        return true;
-    }
-
-    /*
-     * This method handles package deletion in general
-     */
-    private boolean deletePackageLI(String packageName, UserHandle user,
-            boolean deleteCodeAndResources, int[] allUserHandles, boolean[] perUserInstalled,
-            int flags, PackageRemovedInfo outInfo,
-            boolean writeSettings) {
-        if (packageName == null) {
-            Slog.w(TAG, "Attempt to delete null packageName.");
-            return false;
-        }
-        if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageLI: " + packageName + " user " + user);
-        PackageSetting ps;
-        boolean dataOnly = false;
-        int removeUser = -1;
-        int appId = -1;
-        synchronized (mPackages) {
-            ps = mSettings.mPackages.get(packageName);
-            if (ps == null) {
-                Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
-                return false;
-            }
-            if ((!isSystemApp(ps) || (flags&PackageManager.DELETE_SYSTEM_APP) != 0) && user != null
-                    && user.getIdentifier() != UserHandle.USER_ALL) {
-                // The caller is asking that the package only be deleted for a single
-                // user.  To do this, we just mark its uninstalled state and delete
-                // its data.  If this is a system app, we only allow this to happen if
-                // they have set the special DELETE_SYSTEM_APP which requests different
-                // semantics than normal for uninstalling system apps.
-                if (DEBUG_REMOVE) Slog.d(TAG, "Only deleting for single user");
-                ps.setUserState(user.getIdentifier(),
-                        COMPONENT_ENABLED_STATE_DEFAULT,
-                        false, //installed
-                        true,  //stopped
-                        true,  //notLaunched
-                        false, //blocked
-                        null, null, null);
-                if (!isSystemApp(ps)) {
-                    if (ps.isAnyInstalled(sUserManager.getUserIds())) {
-                        // Other user still have this package installed, so all
-                        // we need to do is clear this user's data and save that
-                        // it is uninstalled.
-                        if (DEBUG_REMOVE) Slog.d(TAG, "Still installed by other users");
-                        removeUser = user.getIdentifier();
-                        appId = ps.appId;
-                        mSettings.writePackageRestrictionsLPr(removeUser);
-                    } else {
-                        // We need to set it back to 'installed' so the uninstall
-                        // broadcasts will be sent correctly.
-                        if (DEBUG_REMOVE) Slog.d(TAG, "Not installed by other users, full delete");
-                        ps.setInstalled(true, user.getIdentifier());
-                    }
-                } else {
-                    // This is a system app, so we assume that the
-                    // other users still have this package installed, so all
-                    // we need to do is clear this user's data and save that
-                    // it is uninstalled.
-                    if (DEBUG_REMOVE) Slog.d(TAG, "Deleting system app");
-                    removeUser = user.getIdentifier();
-                    appId = ps.appId;
-                    mSettings.writePackageRestrictionsLPr(removeUser);
-                }
-            }
-        }
-
-        if (removeUser >= 0) {
-            // From above, we determined that we are deleting this only
-            // for a single user.  Continue the work here.
-            if (DEBUG_REMOVE) Slog.d(TAG, "Updating install state for user: " + removeUser);
-            if (outInfo != null) {
-                outInfo.removedPackage = packageName;
-                outInfo.removedAppId = appId;
-                outInfo.removedUsers = new int[] {removeUser};
-            }
-            mInstaller.clearUserData(packageName, removeUser);
-            removeKeystoreDataIfNeeded(removeUser, appId);
-            schedulePackageCleaning(packageName, removeUser, false);
-            return true;
-        }
-
-        if (dataOnly) {
-            // Delete application data first
-            if (DEBUG_REMOVE) Slog.d(TAG, "Removing package data only");
-            removePackageDataLI(ps, null, null, outInfo, flags, writeSettings);
-            return true;
-        }
-
-        boolean ret = false;
-        mSettings.mKeySetManager.removeAppKeySetData(packageName);
-        if (isSystemApp(ps)) {
-            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);
-            // Kill application pre-emptively especially for apps on sd.
-            killApplication(packageName, ps.appId, "uninstall pkg");
-            ret = deleteInstalledPackageLI(ps, deleteCodeAndResources, flags,
-                    allUserHandles, perUserInstalled,
-                    outInfo, writeSettings);
-        }
-
-        return ret;
-    }
-
-    private final class ClearStorageConnection implements ServiceConnection {
-        IMediaContainerService mContainerService;
-
-        @Override
-        public void onServiceConnected(ComponentName name, IBinder service) {
-            synchronized (this) {
-                mContainerService = IMediaContainerService.Stub.asInterface(service);
-                notifyAll();
-            }
-        }
-
-        @Override
-        public void onServiceDisconnected(ComponentName name) {
-        }
-    }
-
-    private void clearExternalStorageDataSync(String packageName, int userId, boolean allData) {
-        final boolean mounted;
-        if (Environment.isExternalStorageEmulated()) {
-            mounted = true;
-        } else {
-            final String status = Environment.getExternalStorageState();
-
-            mounted = status.equals(Environment.MEDIA_MOUNTED)
-                    || status.equals(Environment.MEDIA_MOUNTED_READ_ONLY);
-        }
-
-        if (!mounted) {
-            return;
-        }
-
-        final Intent containerIntent = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
-        int[] users;
-        if (userId == UserHandle.USER_ALL) {
-            users = sUserManager.getUserIds();
-        } else {
-            users = new int[] { userId };
-        }
-        final ClearStorageConnection conn = new ClearStorageConnection();
-        if (mContext.bindServiceAsUser(
-                containerIntent, conn, Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
-            try {
-                for (int curUser : users) {
-                    long timeout = SystemClock.uptimeMillis() + 5000;
-                    synchronized (conn) {
-                        long now = SystemClock.uptimeMillis();
-                        while (conn.mContainerService == null && now < timeout) {
-                            try {
-                                conn.wait(timeout - now);
-                            } catch (InterruptedException e) {
-                            }
-                        }
-                    }
-                    if (conn.mContainerService == null) {
-                        return;
-                    }
-
-                    final UserEnvironment userEnv = new UserEnvironment(curUser);
-                    clearDirectory(conn.mContainerService,
-                            userEnv.buildExternalStorageAppCacheDirs(packageName));
-                    if (allData) {
-                        clearDirectory(conn.mContainerService,
-                                userEnv.buildExternalStorageAppDataDirs(packageName));
-                        clearDirectory(conn.mContainerService,
-                                userEnv.buildExternalStorageAppMediaDirs(packageName));
-                    }
-                }
-            } finally {
-                mContext.unbindService(conn);
-            }
-        }
-    }
-
-    @Override
-    public void clearApplicationUserData(final String packageName,
-            final IPackageDataObserver observer, final int userId) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.CLEAR_APP_USER_DATA, null);
-        enforceCrossUserPermission(Binder.getCallingUid(), userId, true, "clear application data");
-        // Queue up an async operation since the package deletion may take a little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                mHandler.removeCallbacks(this);
-                final boolean succeeded;
-                synchronized (mInstallLock) {
-                    succeeded = clearApplicationUserDataLI(packageName, userId);
-                }
-                clearExternalStorageDataSync(packageName, userId, true);
-                if (succeeded) {
-                    // invoke DeviceStorageMonitor's update method to clear any notifications
-                    DeviceStorageMonitorService dsm = (DeviceStorageMonitorService)
-                            ServiceManager.getService(DeviceStorageMonitorService.SERVICE);
-                    if (dsm != null) {
-                        dsm.updateMemory();
-                    }
-                }
-                if(observer != null) {
-                    try {
-                        observer.onRemoveCompleted(packageName, succeeded);
-                    } catch (RemoteException e) {
-                        Log.i(TAG, "Observer no longer exists.");
-                    }
-                } //end if observer
-            } //end run
-        });
-    }
-
-    private boolean clearApplicationUserDataLI(String packageName, int userId) {
-        if (packageName == null) {
-            Slog.w(TAG, "Attempt to delete null packageName.");
-            return false;
-        }
-        PackageParser.Package p;
-        boolean dataOnly = false;
-        final int appId;
-        synchronized (mPackages) {
-            p = mPackages.get(packageName);
-            if (p == null) {
-                dataOnly = true;
-                PackageSetting ps = mSettings.mPackages.get(packageName);
-                if ((ps == null) || (ps.pkg == null)) {
-                    Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
-                    return false;
-                }
-                p = ps.pkg;
-            }
-            if (!dataOnly) {
-                // need to check this only for fully installed applications
-                if (p == null) {
-                    Slog.w(TAG, "Package named '" + packageName + "' doesn't exist.");
-                    return false;
-                }
-                final ApplicationInfo applicationInfo = p.applicationInfo;
-                if (applicationInfo == null) {
-                    Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
-                    return false;
-                }
-            }
-            if (p != null && p.applicationInfo != null) {
-                appId = p.applicationInfo.uid;
-            } else {
-                appId = -1;
-            }
-        }
-        int retCode = mInstaller.clearUserData(packageName, userId);
-        if (retCode < 0) {
-            Slog.w(TAG, "Couldn't remove cache files for package: "
-                    + packageName);
-            return false;
-        }
-        removeKeystoreDataIfNeeded(userId, appId);
-        return true;
-    }
-
-    /**
-     * Remove entries from the keystore daemon. Will only remove it if the
-     * {@code appId} is valid.
-     */
-    private static void removeKeystoreDataIfNeeded(int userId, int appId) {
-        if (appId < 0) {
-            return;
-        }
-
-        final KeyStore keyStore = KeyStore.getInstance();
-        if (keyStore != null) {
-            if (userId == UserHandle.USER_ALL) {
-                for (final int individual : sUserManager.getUserIds()) {
-                    keyStore.clearUid(UserHandle.getUid(individual, appId));
-                }
-            } else {
-                keyStore.clearUid(UserHandle.getUid(userId, appId));
-            }
-        } else {
-            Slog.w(TAG, "Could not contact keystore to clear entries for app id " + appId);
-        }
-    }
-
-    public void deleteApplicationCacheFiles(final String packageName,
-            final IPackageDataObserver observer) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.DELETE_CACHE_FILES, null);
-        // Queue up an async operation since the package deletion may take a little while.
-        final int userId = UserHandle.getCallingUserId();
-        mHandler.post(new Runnable() {
-            public void run() {
-                mHandler.removeCallbacks(this);
-                final boolean succeded;
-                synchronized (mInstallLock) {
-                    succeded = deleteApplicationCacheFilesLI(packageName, userId);
-                }
-                clearExternalStorageDataSync(packageName, userId, false);
-                if(observer != null) {
-                    try {
-                        observer.onRemoveCompleted(packageName, succeded);
-                    } catch (RemoteException e) {
-                        Log.i(TAG, "Observer no longer exists.");
-                    }
-                } //end if observer
-            } //end run
-        });
-    }
-
-    private boolean deleteApplicationCacheFilesLI(String packageName, int userId) {
-        if (packageName == null) {
-            Slog.w(TAG, "Attempt to delete null packageName.");
-            return false;
-        }
-        PackageParser.Package p;
-        synchronized (mPackages) {
-            p = mPackages.get(packageName);
-        }
-        if (p == null) {
-            Slog.w(TAG, "Package named '" + packageName +"' doesn't exist.");
-            return false;
-        }
-        final ApplicationInfo applicationInfo = p.applicationInfo;
-        if (applicationInfo == null) {
-            Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
-            return false;
-        }
-        int retCode = mInstaller.deleteCacheFiles(packageName, userId);
-        if (retCode < 0) {
-            Slog.w(TAG, "Couldn't remove cache files for package: "
-                       + packageName + " u" + userId);
-            return false;
-        }
-        return true;
-    }
-
-    public void getPackageSizeInfo(final String packageName, int userHandle,
-            final IPackageStatsObserver observer) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.GET_PACKAGE_SIZE, null);
-
-        PackageStats stats = new PackageStats(packageName, userHandle);
-
-        /*
-         * Queue up an async operation since the package measurement may take a
-         * little while.
-         */
-        Message msg = mHandler.obtainMessage(INIT_COPY);
-        msg.obj = new MeasureParams(stats, observer);
-        mHandler.sendMessage(msg);
-    }
-
-    private boolean getPackageSizeInfoLI(String packageName, int userHandle,
-            PackageStats pStats) {
-        if (packageName == null) {
-            Slog.w(TAG, "Attempt to get size of null packageName.");
-            return false;
-        }
-        PackageParser.Package p;
-        boolean dataOnly = false;
-        String libDirPath = null;
-        String asecPath = null;
-        synchronized (mPackages) {
-            p = mPackages.get(packageName);
-            PackageSetting ps = mSettings.mPackages.get(packageName);
-            if(p == null) {
-                dataOnly = true;
-                if((ps == null) || (ps.pkg == null)) {
-                    Slog.w(TAG, "Package named '" + packageName +"' doesn't exist.");
-                    return false;
-                }
-                p = ps.pkg;
-            }
-            if (ps != null) {
-                libDirPath = ps.nativeLibraryPathString;
-            }
-            if (p != null && (isExternal(p) || isForwardLocked(p))) {
-                String secureContainerId = cidFromCodePath(p.applicationInfo.sourceDir);
-                if (secureContainerId != null) {
-                    asecPath = PackageHelper.getSdFilesystem(secureContainerId);
-                }
-            }
-        }
-        String publicSrcDir = null;
-        if(!dataOnly) {
-            final ApplicationInfo applicationInfo = p.applicationInfo;
-            if (applicationInfo == null) {
-                Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
-                return false;
-            }
-            if (isForwardLocked(p)) {
-                publicSrcDir = applicationInfo.publicSourceDir;
-            }
-        }
-        int res = mInstaller.getSizeInfo(packageName, userHandle, p.mPath, libDirPath,
-                publicSrcDir, asecPath, pStats);
-        if (res < 0) {
-            return false;
-        }
-
-        // Fix-up for forward-locked applications in ASEC containers.
-        if (!isExternal(p)) {
-            pStats.codeSize += pStats.externalCodeSize;
-            pStats.externalCodeSize = 0L;
-        }
-
-        return true;
-    }
-
-
-    public void addPackageToPreferred(String packageName) {
-        Slog.w(TAG, "addPackageToPreferred: this is now a no-op");
-    }
-
-    public void removePackageFromPreferred(String packageName) {
-        Slog.w(TAG, "removePackageFromPreferred: this is now a no-op");
-    }
-
-    public List<PackageInfo> getPreferredPackages(int flags) {
-        return new ArrayList<PackageInfo>();
-    }
-
-    private int getUidTargetSdkVersionLockedLPr(int uid) {
-        Object obj = mSettings.getUserIdLPr(uid);
-        if (obj instanceof SharedUserSetting) {
-            final SharedUserSetting sus = (SharedUserSetting) obj;
-            int vers = Build.VERSION_CODES.CUR_DEVELOPMENT;
-            final Iterator<PackageSetting> it = sus.packages.iterator();
-            while (it.hasNext()) {
-                final PackageSetting ps = it.next();
-                if (ps.pkg != null) {
-                    int v = ps.pkg.applicationInfo.targetSdkVersion;
-                    if (v < vers) vers = v;
-                }
-            }
-            return vers;
-        } else if (obj instanceof PackageSetting) {
-            final PackageSetting ps = (PackageSetting) obj;
-            if (ps.pkg != null) {
-                return ps.pkg.applicationInfo.targetSdkVersion;
-            }
-        }
-        return Build.VERSION_CODES.CUR_DEVELOPMENT;
-    }
-
-    public void addPreferredActivity(IntentFilter filter, int match,
-            ComponentName[] set, ComponentName activity, int userId) {
-        addPreferredActivityInternal(filter, match, set, activity, true, userId);
-    }
-
-    private void addPreferredActivityInternal(IntentFilter filter, int match,
-            ComponentName[] set, ComponentName activity, boolean always, int userId) {
-        // writer
-        int callingUid = Binder.getCallingUid();
-        enforceCrossUserPermission(callingUid, userId, true, "add preferred activity");
-        if (filter.countActions() == 0) {
-            Slog.w(TAG, "Cannot set a preferred activity with no filter actions");
-            return;
-        }
-        synchronized (mPackages) {
-            if (mContext.checkCallingOrSelfPermission(
-                    android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
-                    != PackageManager.PERMISSION_GRANTED) {
-                if (getUidTargetSdkVersionLockedLPr(callingUid)
-                        < Build.VERSION_CODES.FROYO) {
-                    Slog.w(TAG, "Ignoring addPreferredActivity() from uid "
-                            + callingUid);
-                    return;
-                }
-                mContext.enforceCallingOrSelfPermission(
-                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
-            }
-
-            Slog.i(TAG, "Adding preferred activity " + activity + " for user " + userId + " :");
-            filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
-            mSettings.editPreferredActivitiesLPw(userId).addFilter(
-                    new PreferredActivity(filter, match, set, activity, always));
-            mSettings.writePackageRestrictionsLPr(userId);
-        }
-    }
-
-    public void replacePreferredActivity(IntentFilter filter, int match,
-            ComponentName[] set, ComponentName activity) {
-        if (filter.countActions() != 1) {
-            throw new IllegalArgumentException(
-                    "replacePreferredActivity expects filter to have only 1 action.");
-        }
-        if (filter.countDataAuthorities() != 0
-                || filter.countDataPaths() != 0
-                || filter.countDataSchemes() > 1
-                || filter.countDataTypes() != 0) {
-            throw new IllegalArgumentException(
-                    "replacePreferredActivity expects filter to have no data authorities, " +
-                    "paths, or types; and at most one scheme.");
-        }
-        synchronized (mPackages) {
-            if (mContext.checkCallingOrSelfPermission(
-                    android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
-                    != PackageManager.PERMISSION_GRANTED) {
-                if (getUidTargetSdkVersionLockedLPr(Binder.getCallingUid())
-                        < Build.VERSION_CODES.FROYO) {
-                    Slog.w(TAG, "Ignoring replacePreferredActivity() from uid "
-                            + Binder.getCallingUid());
-                    return;
-                }
-                mContext.enforceCallingOrSelfPermission(
-                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
-            }
-
-            final int callingUserId = UserHandle.getCallingUserId();
-            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(callingUserId);
-            if (pir != null) {
-                Intent intent = new Intent(filter.getAction(0)).addCategory(filter.getCategory(0));
-                if (filter.countDataSchemes() == 1) {
-                    Uri.Builder builder = new Uri.Builder();
-                    builder.scheme(filter.getDataScheme(0));
-                    intent.setData(builder.build());
-                }
-                List<PreferredActivity> matches = pir.queryIntent(
-                        intent, null, true, callingUserId);
-                if (DEBUG_PREFERRED) {
-                    Slog.i(TAG, matches.size() + " preferred matches for " + intent);
-                }
-                for (int i = 0; i < matches.size(); i++) {
-                    PreferredActivity pa = matches.get(i);
-                    if (DEBUG_PREFERRED) {
-                        Slog.i(TAG, "Removing preferred activity "
-                                + pa.mPref.mComponent + ":");
-                        filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
-                    }
-                    pir.removeFilter(pa);
-                }
-            }
-            addPreferredActivityInternal(filter, match, set, activity, true, callingUserId);
-        }
-    }
-
-    public void clearPackagePreferredActivities(String packageName) {
-        final int uid = Binder.getCallingUid();
-        // writer
-        synchronized (mPackages) {
-            PackageParser.Package pkg = mPackages.get(packageName);
-            if (pkg == null || pkg.applicationInfo.uid != uid) {
-                if (mContext.checkCallingOrSelfPermission(
-                        android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
-                        != PackageManager.PERMISSION_GRANTED) {
-                    if (getUidTargetSdkVersionLockedLPr(Binder.getCallingUid())
-                            < Build.VERSION_CODES.FROYO) {
-                        Slog.w(TAG, "Ignoring clearPackagePreferredActivities() from uid "
-                                + Binder.getCallingUid());
-                        return;
-                    }
-                    mContext.enforceCallingOrSelfPermission(
-                            android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
-                }
-            }
-
-            int user = UserHandle.getCallingUserId();
-            if (clearPackagePreferredActivitiesLPw(packageName, user)) {
-                mSettings.writePackageRestrictionsLPr(user);
-                scheduleWriteSettingsLocked();
-            }
-        }
-    }
-
-    /** This method takes a specific user id as well as UserHandle.USER_ALL. */
-    boolean clearPackagePreferredActivitiesLPw(String packageName, int userId) {
-        ArrayList<PreferredActivity> removed = null;
-        boolean changed = false;
-        for (int i=0; i<mSettings.mPreferredActivities.size(); i++) {
-            final int thisUserId = mSettings.mPreferredActivities.keyAt(i);
-            PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
-            if (userId != UserHandle.USER_ALL && userId != thisUserId) {
-                continue;
-            }
-            Iterator<PreferredActivity> it = pir.filterIterator();
-            while (it.hasNext()) {
-                PreferredActivity pa = it.next();
-                // Mark entry for removal only if it matches the package name
-                // and the entry is of type "always".
-                if (packageName == null ||
-                        (pa.mPref.mComponent.getPackageName().equals(packageName)
-                                && pa.mPref.mAlways)) {
-                    if (removed == null) {
-                        removed = new ArrayList<PreferredActivity>();
-                    }
-                    removed.add(pa);
-                }
-            }
-            if (removed != null) {
-                for (int j=0; j<removed.size(); j++) {
-                    PreferredActivity pa = removed.get(j);
-                    pir.removeFilter(pa);
-                }
-                changed = true;
-            }
-        }
-        return changed;
-    }
-
-    public void resetPreferredActivities(int userId) {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
-        // writer
-        synchronized (mPackages) {
-            int user = UserHandle.getCallingUserId();
-            clearPackagePreferredActivitiesLPw(null, user);
-            mSettings.readDefaultPreferredAppsLPw(this, user);
-            mSettings.writePackageRestrictionsLPr(user);
-            scheduleWriteSettingsLocked();
-        }
-    }
-
-    public int getPreferredActivities(List<IntentFilter> outFilters,
-            List<ComponentName> outActivities, String packageName) {
-
-        int num = 0;
-        final int userId = UserHandle.getCallingUserId();
-        // reader
-        synchronized (mPackages) {
-            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
-            if (pir != null) {
-                final Iterator<PreferredActivity> it = pir.filterIterator();
-                while (it.hasNext()) {
-                    final PreferredActivity pa = it.next();
-                    if (packageName == null
-                            || (pa.mPref.mComponent.getPackageName().equals(packageName)
-                                    && pa.mPref.mAlways)) {
-                        if (outFilters != null) {
-                            outFilters.add(new IntentFilter(pa));
-                        }
-                        if (outActivities != null) {
-                            outActivities.add(pa.mPref.mComponent);
-                        }
-                    }
-                }
-            }
-        }
-
-        return num;
-    }
-
-    @Override
-    public ComponentName getHomeActivities(List<ResolveInfo> allHomeCandidates) {
-        Intent intent = new Intent(Intent.ACTION_MAIN);
-        intent.addCategory(Intent.CATEGORY_HOME);
-
-        final int callingUserId = UserHandle.getCallingUserId();
-        List<ResolveInfo> list = queryIntentActivities(intent, null,
-                PackageManager.GET_META_DATA, callingUserId);
-        ResolveInfo preferred = findPreferredActivity(intent, null, 0, list, 0,
-                true, false, false, callingUserId);
-
-        allHomeCandidates.clear();
-        if (list != null) {
-            for (ResolveInfo ri : list) {
-                allHomeCandidates.add(ri);
-            }
-        }
-        return (preferred == null || preferred.activityInfo == null)
-                ? null
-                : new ComponentName(preferred.activityInfo.packageName,
-                        preferred.activityInfo.name);
-    }
-
-    @Override
-    public void setApplicationEnabledSetting(String appPackageName,
-            int newState, int flags, int userId, String callingPackage) {
-        if (!sUserManager.exists(userId)) return;
-        if (callingPackage == null) {
-            callingPackage = Integer.toString(Binder.getCallingUid());
-        }
-        setEnabledSetting(appPackageName, null, newState, flags, userId, callingPackage);
-    }
-
-    @Override
-    public void setComponentEnabledSetting(ComponentName componentName,
-            int newState, int flags, int userId) {
-        if (!sUserManager.exists(userId)) return;
-        setEnabledSetting(componentName.getPackageName(),
-                componentName.getClassName(), newState, flags, userId, null);
-    }
-
-    private void setEnabledSetting(final String packageName, String className, int newState,
-            final int flags, int userId, String callingPackage) {
-        if (!(newState == COMPONENT_ENABLED_STATE_DEFAULT
-              || newState == COMPONENT_ENABLED_STATE_ENABLED
-              || newState == COMPONENT_ENABLED_STATE_DISABLED
-              || newState == COMPONENT_ENABLED_STATE_DISABLED_USER
-              || newState == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
-            throw new IllegalArgumentException("Invalid new component state: "
-                    + newState);
-        }
-        PackageSetting pkgSetting;
-        final int uid = Binder.getCallingUid();
-        final int permission = mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);
-        enforceCrossUserPermission(uid, userId, false, "set enabled");
-        final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED);
-        boolean sendNow = false;
-        boolean isApp = (className == null);
-        String componentName = isApp ? packageName : className;
-        int packageUid = -1;
-        ArrayList<String> components;
-
-        // writer
-        synchronized (mPackages) {
-            pkgSetting = mSettings.mPackages.get(packageName);
-            if (pkgSetting == null) {
-                if (className == null) {
-                    throw new IllegalArgumentException(
-                            "Unknown package: " + packageName);
-                }
-                throw new IllegalArgumentException(
-                        "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)) {
-                throw new SecurityException(
-                        "Permission Denial: attempt to change component state from pid="
-                        + Binder.getCallingPid()
-                        + ", uid=" + uid + ", package uid=" + pkgSetting.appId);
-            }
-            if (className == null) {
-                // We're dealing with an application/package level state change
-                if (pkgSetting.getEnabled(userId) == newState) {
-                    // Nothing to do
-                    return;
-                }
-                if (newState == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
-                    || newState == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
-                    // Don't care about who enables an app.
-                    callingPackage = null;
-                }
-                pkgSetting.setEnabled(newState, userId, callingPackage);
-                // pkgSetting.pkg.mSetEnabled = newState;
-            } else {
-                // We're dealing with a component level state change
-                // First, verify that this is a valid class name.
-                PackageParser.Package pkg = pkgSetting.pkg;
-                if (pkg == null || !pkg.hasComponentClassName(className)) {
-                    if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.JELLY_BEAN) {
-                        throw new IllegalArgumentException("Component class " + className
-                                + " does not exist in " + packageName);
-                    } else {
-                        Slog.w(TAG, "Failed setComponentEnabledSetting: component class "
-                                + className + " does not exist in " + packageName);
-                    }
-                }
-                switch (newState) {
-                case COMPONENT_ENABLED_STATE_ENABLED:
-                    if (!pkgSetting.enableComponentLPw(className, userId)) {
-                        return;
-                    }
-                    break;
-                case COMPONENT_ENABLED_STATE_DISABLED:
-                    if (!pkgSetting.disableComponentLPw(className, userId)) {
-                        return;
-                    }
-                    break;
-                case COMPONENT_ENABLED_STATE_DEFAULT:
-                    if (!pkgSetting.restoreComponentLPw(className, userId)) {
-                        return;
-                    }
-                    break;
-                default:
-                    Slog.e(TAG, "Invalid new component state: " + newState);
-                    return;
-                }
-            }
-            mSettings.writePackageRestrictionsLPr(userId);
-            components = mPendingBroadcasts.get(userId, packageName);
-            final boolean newPackage = components == null;
-            if (newPackage) {
-                components = new ArrayList<String>();
-            }
-            if (!components.contains(componentName)) {
-                components.add(componentName);
-            }
-            if ((flags&PackageManager.DONT_KILL_APP) == 0) {
-                sendNow = true;
-                // Purge entry from pending broadcast list if another one exists already
-                // since we are sending one right away.
-                mPendingBroadcasts.remove(userId, packageName);
-            } else {
-                if (newPackage) {
-                    mPendingBroadcasts.put(userId, packageName, components);
-                }
-                if (!mHandler.hasMessages(SEND_PENDING_BROADCAST)) {
-                    // Schedule a message
-                    mHandler.sendEmptyMessageDelayed(SEND_PENDING_BROADCAST, BROADCAST_DELAY);
-                }
-            }
-        }
-
-        long callingId = Binder.clearCallingIdentity();
-        try {
-            if (sendNow) {
-                packageUid = UserHandle.getUid(userId, pkgSetting.appId);
-                sendPackageChangedBroadcast(packageName,
-                        (flags&PackageManager.DONT_KILL_APP) != 0, components, packageUid);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingId);
-        }
-    }
-
-    private void sendPackageChangedBroadcast(String packageName,
-            boolean killFlag, ArrayList<String> componentNames, int packageUid) {
-        if (DEBUG_INSTALL)
-            Log.v(TAG, "Sending package changed: package=" + packageName + " components="
-                    + componentNames);
-        Bundle extras = new Bundle(4);
-        extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0));
-        String nameList[] = new String[componentNames.size()];
-        componentNames.toArray(nameList);
-        extras.putStringArray(Intent.EXTRA_CHANGED_COMPONENT_NAME_LIST, nameList);
-        extras.putBoolean(Intent.EXTRA_DONT_KILL_APP, killFlag);
-        extras.putInt(Intent.EXTRA_UID, packageUid);
-        sendPackageBroadcast(Intent.ACTION_PACKAGE_CHANGED,  packageName, extras, null, null,
-                new int[] {UserHandle.getUserId(packageUid)});
-    }
-
-    public void setPackageStoppedState(String packageName, boolean stopped, int userId) {
-        if (!sUserManager.exists(userId)) return;
-        final int uid = Binder.getCallingUid();
-        final int permission = mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE);
-        final boolean allowedByPermission = (permission == PackageManager.PERMISSION_GRANTED);
-        enforceCrossUserPermission(uid, userId, true, "stop package");
-        // writer
-        synchronized (mPackages) {
-            if (mSettings.setPackageStoppedStateLPw(packageName, stopped, allowedByPermission,
-                    uid, userId)) {
-                scheduleWritePackageRestrictionsLocked(userId);
-            }
-        }
-    }
-
-    public String getInstallerPackageName(String packageName) {
-        // reader
-        synchronized (mPackages) {
-            return mSettings.getInstallerPackageNameLPr(packageName);
-        }
-    }
-
-    @Override
-    public int getApplicationEnabledSetting(String packageName, int userId) {
-        if (!sUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
-        int uid = Binder.getCallingUid();
-        enforceCrossUserPermission(uid, userId, false, "get enabled");
-        // reader
-        synchronized (mPackages) {
-            return mSettings.getApplicationEnabledSettingLPr(packageName, userId);
-        }
-    }
-
-    @Override
-    public int getComponentEnabledSetting(ComponentName componentName, int userId) {
-        if (!sUserManager.exists(userId)) return COMPONENT_ENABLED_STATE_DISABLED;
-        int uid = Binder.getCallingUid();
-        enforceCrossUserPermission(uid, userId, false, "get component enabled");
-        // reader
-        synchronized (mPackages) {
-            return mSettings.getComponentEnabledSettingLPr(componentName, userId);
-        }
-    }
-
-    public void enterSafeMode() {
-        enforceSystemOrRoot("Only the system can request entering safe mode");
-
-        if (!mSystemReady) {
-            mSafeMode = true;
-        }
-    }
-
-    public void systemReady() {
-        mSystemReady = true;
-
-        // Read the compatibilty setting when the system is ready.
-        boolean compatibilityModeEnabled = android.provider.Settings.Global.getInt(
-                mContext.getContentResolver(),
-                android.provider.Settings.Global.COMPATIBILITY_MODE, 1) == 1;
-        PackageParser.setCompatibilityModeEnabled(compatibilityModeEnabled);
-        if (DEBUG_SETTINGS) {
-            Log.d(TAG, "compatibility mode:" + compatibilityModeEnabled);
-        }
-
-        synchronized (mPackages) {
-            // Verify that all of the preferred activity components actually
-            // exist.  It is possible for applications to be updated and at
-            // that point remove a previously declared activity component that
-            // had been set as a preferred activity.  We try to clean this up
-            // the next time we encounter that preferred activity, but it is
-            // possible for the user flow to never be able to return to that
-            // situation so here we do a sanity check to make sure we haven't
-            // left any junk around.
-            ArrayList<PreferredActivity> removed = new ArrayList<PreferredActivity>();
-            for (int i=0; i<mSettings.mPreferredActivities.size(); i++) {
-                PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
-                removed.clear();
-                for (PreferredActivity pa : pir.filterSet()) {
-                    if (mActivities.mActivities.get(pa.mPref.mComponent) == null) {
-                        removed.add(pa);
-                    }
-                }
-                if (removed.size() > 0) {
-                    for (int j=0; j<removed.size(); j++) {
-                        PreferredActivity pa = removed.get(i);
-                        Slog.w(TAG, "Removing dangling preferred activity: "
-                                + pa.mPref.mComponent);
-                        pir.removeFilter(pa);
-                    }
-                    mSettings.writePackageRestrictionsLPr(
-                            mSettings.mPreferredActivities.keyAt(i));
-                }
-            }
-        }
-        sUserManager.systemReady();
-    }
-
-    public boolean isSafeMode() {
-        return mSafeMode;
-    }
-
-    public boolean hasSystemUidErrors() {
-        return mHasSystemUidErrors;
-    }
-
-    static String arrayToString(int[] array) {
-        StringBuffer buf = new StringBuffer(128);
-        buf.append('[');
-        if (array != null) {
-            for (int i=0; i<array.length; i++) {
-                if (i > 0) buf.append(", ");
-                buf.append(array[i]);
-            }
-        }
-        buf.append(']');
-        return buf.toString();
-    }
-
-    static class DumpState {
-        public static final int DUMP_LIBS = 1 << 0;
-
-        public static final int DUMP_FEATURES = 1 << 1;
-
-        public static final int DUMP_RESOLVERS = 1 << 2;
-
-        public static final int DUMP_PERMISSIONS = 1 << 3;
-
-        public static final int DUMP_PACKAGES = 1 << 4;
-
-        public static final int DUMP_SHARED_USERS = 1 << 5;
-
-        public static final int DUMP_MESSAGES = 1 << 6;
-
-        public static final int DUMP_PROVIDERS = 1 << 7;
-
-        public static final int DUMP_VERIFIERS = 1 << 8;
-
-        public static final int DUMP_PREFERRED = 1 << 9;
-
-        public static final int DUMP_PREFERRED_XML = 1 << 10;
-
-        public static final int DUMP_KEYSETS = 1 << 11;
-
-        public static final int OPTION_SHOW_FILTERS = 1 << 0;
-
-        private int mTypes;
-
-        private int mOptions;
-
-        private boolean mTitlePrinted;
-
-        private SharedUserSetting mSharedUser;
-
-        public boolean isDumping(int type) {
-            if (mTypes == 0 && type != DUMP_PREFERRED_XML) {
-                return true;
-            }
-
-            return (mTypes & type) != 0;
-        }
-
-        public void setDump(int type) {
-            mTypes |= type;
-        }
-
-        public boolean isOptionEnabled(int option) {
-            return (mOptions & option) != 0;
-        }
-
-        public void setOptionEnabled(int option) {
-            mOptions |= option;
-        }
-
-        public boolean onTitlePrinted() {
-            final boolean printed = mTitlePrinted;
-            mTitlePrinted = true;
-            return printed;
-        }
-
-        public boolean getTitlePrinted() {
-            return mTitlePrinted;
-        }
-
-        public void setTitlePrinted(boolean enabled) {
-            mTitlePrinted = enabled;
-        }
-
-        public SharedUserSetting getSharedUser() {
-            return mSharedUser;
-        }
-
-        public void setSharedUser(SharedUserSetting user) {
-            mSharedUser = user;
-        }
-    }
-
-    @Override
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump ActivityManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid()
-                    + " without permission "
-                    + android.Manifest.permission.DUMP);
-            return;
-        }
-
-        DumpState dumpState = new DumpState();
-        boolean fullPreferred = false;
-        boolean checkin = false;
-
-        String packageName = null;
-        
-        int opti = 0;
-        while (opti < args.length) {
-            String opt = args[opti];
-            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
-                break;
-            }
-            opti++;
-            if ("-a".equals(opt)) {
-                // Right now we only know how to print all.
-            } else if ("-h".equals(opt)) {
-                pw.println("Package manager dump options:");
-                pw.println("  [-h] [-f] [--checkin] [cmd] ...");
-                pw.println("    --checkin: dump for a checkin");
-                pw.println("    -f: print details of intent filters");
-                pw.println("    -h: print this help");
-                pw.println("  cmd may be one of:");
-                pw.println("    l[ibraries]: list known shared libraries");
-                pw.println("    f[ibraries]: list device features");
-                pw.println("    r[esolvers]: dump intent resolvers");
-                pw.println("    perm[issions]: dump permissions");
-                pw.println("    pref[erred]: print preferred package settings");
-                pw.println("    preferred-xml [--full]: print preferred package settings as xml");
-                pw.println("    prov[iders]: dump content providers");
-                pw.println("    p[ackages]: dump installed packages");
-                pw.println("    s[hared-users]: dump shared user IDs");
-                pw.println("    m[essages]: print collected runtime messages");
-                pw.println("    v[erifiers]: print package verifier info");
-                pw.println("    <package.name>: info about given package");
-                pw.println("    k[eysets]: print known keysets");
-                return;
-            } else if ("--checkin".equals(opt)) {
-                checkin = true;
-            } else if ("-f".equals(opt)) {
-                dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
-            } else {
-                pw.println("Unknown argument: " + opt + "; use -h for help");
-            }
-        }
-
-        // Is the caller requesting to dump a particular piece of data?
-        if (opti < args.length) {
-            String cmd = args[opti];
-            opti++;
-            // Is this a package name?
-            if ("android".equals(cmd) || cmd.contains(".")) {
-                packageName = cmd;
-                // When dumping a single package, we always dump all of its
-                // filter information since the amount of data will be reasonable.
-                dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
-            } else if ("l".equals(cmd) || "libraries".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_LIBS);
-            } else if ("f".equals(cmd) || "features".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_FEATURES);
-            } else if ("r".equals(cmd) || "resolvers".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_RESOLVERS);
-            } else if ("perm".equals(cmd) || "permissions".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_PERMISSIONS);
-            } else if ("pref".equals(cmd) || "preferred".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_PREFERRED);
-            } else if ("preferred-xml".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_PREFERRED_XML);
-                if (opti < args.length && "--full".equals(args[opti])) {
-                    fullPreferred = true;
-                    opti++;
-                }
-            } else if ("p".equals(cmd) || "packages".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_PACKAGES);
-            } else if ("s".equals(cmd) || "shared-users".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_SHARED_USERS);
-            } else if ("prov".equals(cmd) || "providers".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_PROVIDERS);
-            } else if ("m".equals(cmd) || "messages".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_MESSAGES);
-            } else if ("v".equals(cmd) || "verifiers".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_VERIFIERS);
-            } else if ("k".equals(cmd) || "keysets".equals(cmd)) {
-                dumpState.setDump(DumpState.DUMP_KEYSETS);
-            }
-        }
-
-        if (checkin) {
-            pw.println("vers,1");
-        }
-
-        // reader
-        synchronized (mPackages) {
-            if (dumpState.isDumping(DumpState.DUMP_VERIFIERS) && packageName == null) {
-                if (!checkin) {
-                    if (dumpState.onTitlePrinted())
-                        pw.println();
-                    pw.println("Verifiers:");
-                    pw.print("  Required: ");
-                    pw.print(mRequiredVerifierPackage);
-                    pw.print(" (uid=");
-                    pw.print(getPackageUid(mRequiredVerifierPackage, 0));
-                    pw.println(")");
-                } else if (mRequiredVerifierPackage != null) {
-                    pw.print("vrfy,"); pw.print(mRequiredVerifierPackage);
-                    pw.print(","); pw.println(getPackageUid(mRequiredVerifierPackage, 0));
-                }
-            }
-
-            if (dumpState.isDumping(DumpState.DUMP_LIBS) && packageName == null) {
-                boolean printedHeader = false;
-                final Iterator<String> it = mSharedLibraries.keySet().iterator();
-                while (it.hasNext()) {
-                    String name = it.next();
-                    SharedLibraryEntry ent = mSharedLibraries.get(name);
-                    if (!checkin) {
-                        if (!printedHeader) {
-                            if (dumpState.onTitlePrinted())
-                                pw.println();
-                            pw.println("Libraries:");
-                            printedHeader = true;
-                        }
-                        pw.print("  ");
-                    } else {
-                        pw.print("lib,");
-                    }
-                    pw.print(name);
-                    if (!checkin) {
-                        pw.print(" -> ");
-                    }
-                    if (ent.path != null) {
-                        if (!checkin) {
-                            pw.print("(jar) ");
-                            pw.print(ent.path);
-                        } else {
-                            pw.print(",jar,");
-                            pw.print(ent.path);
-                        }
-                    } else {
-                        if (!checkin) {
-                            pw.print("(apk) ");
-                            pw.print(ent.apk);
-                        } else {
-                            pw.print(",apk,");
-                            pw.print(ent.apk);
-                        }
-                    }
-                    pw.println();
-                }
-            }
-
-            if (dumpState.isDumping(DumpState.DUMP_FEATURES) && packageName == null) {
-                if (dumpState.onTitlePrinted())
-                    pw.println();
-                if (!checkin) {
-                    pw.println("Features:");
-                }
-                Iterator<String> it = mAvailableFeatures.keySet().iterator();
-                while (it.hasNext()) {
-                    String name = it.next();
-                    if (!checkin) {
-                        pw.print("  ");
-                    } else {
-                        pw.print("feat,");
-                    }
-                    pw.println(name);
-                }
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_RESOLVERS)) {
-                if (mActivities.dump(pw, dumpState.getTitlePrinted() ? "\nActivity Resolver Table:"
-                        : "Activity Resolver Table:", "  ", packageName,
-                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
-                    dumpState.setTitlePrinted(true);
-                }
-                if (mReceivers.dump(pw, dumpState.getTitlePrinted() ? "\nReceiver Resolver Table:"
-                        : "Receiver Resolver Table:", "  ", packageName,
-                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
-                    dumpState.setTitlePrinted(true);
-                }
-                if (mServices.dump(pw, dumpState.getTitlePrinted() ? "\nService Resolver Table:"
-                        : "Service Resolver Table:", "  ", packageName,
-                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
-                    dumpState.setTitlePrinted(true);
-                }
-                if (mProviders.dump(pw, dumpState.getTitlePrinted() ? "\nProvider Resolver Table:"
-                        : "Provider Resolver Table:", "  ", packageName,
-                        dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) {
-                    dumpState.setTitlePrinted(true);
-                }
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED)) {
-                for (int i=0; i<mSettings.mPreferredActivities.size(); i++) {
-                    PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
-                    int user = mSettings.mPreferredActivities.keyAt(i);
-                    if (pir.dump(pw,
-                            dumpState.getTitlePrinted()
-                                ? "\nPreferred Activities User " + user + ":"
-                                : "Preferred Activities User " + user + ":", "  ",
-                            packageName, true)) {
-                        dumpState.setTitlePrinted(true);
-                    }
-                }
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED_XML)) {
-                pw.flush();
-                FileOutputStream fout = new FileOutputStream(fd);
-                BufferedOutputStream str = new BufferedOutputStream(fout);
-                XmlSerializer serializer = new FastXmlSerializer();
-                try {
-                    serializer.setOutput(str, "utf-8");
-                    serializer.startDocument(null, true);
-                    serializer.setFeature(
-                            "http://xmlpull.org/v1/doc/features.html#indent-output", true);
-                    mSettings.writePreferredActivitiesLPr(serializer, 0, fullPreferred);
-                    serializer.endDocument();
-                    serializer.flush();
-                } catch (IllegalArgumentException e) {
-                    pw.println("Failed writing: " + e);
-                } catch (IllegalStateException e) {
-                    pw.println("Failed writing: " + e);
-                } catch (IOException e) {
-                    pw.println("Failed writing: " + e);
-                }
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_PERMISSIONS)) {
-                mSettings.dumpPermissionsLPr(pw, packageName, dumpState);
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_PROVIDERS)) {
-                boolean printedSomething = false;
-                for (PackageParser.Provider p : mProviders.mProviders.values()) {
-                    if (packageName != null && !packageName.equals(p.info.packageName)) {
-                        continue;
-                    }
-                    if (!printedSomething) {
-                        if (dumpState.onTitlePrinted())
-                            pw.println();
-                        pw.println("Registered ContentProviders:");
-                        printedSomething = true;
-                    }
-                    pw.print("  "); p.printComponentShortName(pw); pw.println(":");
-                    pw.print("    "); pw.println(p.toString());
-                }
-                printedSomething = false;
-                for (Map.Entry<String, PackageParser.Provider> entry :
-                        mProvidersByAuthority.entrySet()) {
-                    PackageParser.Provider p = entry.getValue();
-                    if (packageName != null && !packageName.equals(p.info.packageName)) {
-                        continue;
-                    }
-                    if (!printedSomething) {
-                        if (dumpState.onTitlePrinted())
-                            pw.println();
-                        pw.println("ContentProvider Authorities:");
-                        printedSomething = true;
-                    }
-                    pw.print("  ["); pw.print(entry.getKey()); pw.println("]:");
-                    pw.print("    "); pw.println(p.toString());
-                    if (p.info != null && p.info.applicationInfo != null) {
-                        final String appInfo = p.info.applicationInfo.toString();
-                        pw.print("      applicationInfo="); pw.println(appInfo);
-                    }
-                }
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_KEYSETS)) {
-                mSettings.mKeySetManager.dump(pw, packageName, dumpState);
-            }
-
-            if (dumpState.isDumping(DumpState.DUMP_PACKAGES)) {
-                mSettings.dumpPackagesLPr(pw, packageName, dumpState, checkin);
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_SHARED_USERS)) {
-                mSettings.dumpSharedUsersLPr(pw, packageName, dumpState);
-            }
-
-            if (!checkin && dumpState.isDumping(DumpState.DUMP_MESSAGES) && packageName == null) {
-                if (dumpState.onTitlePrinted())
-                    pw.println();
-                mSettings.dumpReadMessagesLPr(pw, dumpState);
-
-                pw.println();
-                pw.println("Package warning messages:");
-                final File fname = getSettingsProblemFile();
-                FileInputStream in = null;
-                try {
-                    in = new FileInputStream(fname);
-                    final int avail = in.available();
-                    final byte[] data = new byte[avail];
-                    in.read(data);
-                    pw.print(new String(data));
-                } catch (FileNotFoundException e) {
-                } catch (IOException e) {
-                } finally {
-                    if (in != null) {
-                        try {
-                            in.close();
-                        } catch (IOException e) {
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    // ------- apps on sdcard specific code -------
-    static final boolean DEBUG_SD_INSTALL = false;
-
-    private static final String SD_ENCRYPTION_KEYSTORE_NAME = "AppsOnSD";
-
-    private static final String SD_ENCRYPTION_ALGORITHM = "AES";
-
-    private boolean mMediaMounted = false;
-
-    private String getEncryptKey() {
-        try {
-            String sdEncKey = SystemKeyStore.getInstance().retrieveKeyHexString(
-                    SD_ENCRYPTION_KEYSTORE_NAME);
-            if (sdEncKey == null) {
-                sdEncKey = SystemKeyStore.getInstance().generateNewKeyHexString(128,
-                        SD_ENCRYPTION_ALGORITHM, SD_ENCRYPTION_KEYSTORE_NAME);
-                if (sdEncKey == null) {
-                    Slog.e(TAG, "Failed to create encryption keys");
-                    return null;
-                }
-            }
-            return sdEncKey;
-        } catch (NoSuchAlgorithmException nsae) {
-            Slog.e(TAG, "Failed to create encryption keys with exception: " + nsae);
-            return null;
-        } catch (IOException ioe) {
-            Slog.e(TAG, "Failed to retrieve encryption keys with exception: " + ioe);
-            return null;
-        }
-
-    }
-
-    /* package */static String getTempContainerId() {
-        int tmpIdx = 1;
-        String list[] = PackageHelper.getSecureContainerList();
-        if (list != null) {
-            for (final String name : list) {
-                // Ignore null and non-temporary container entries
-                if (name == null || !name.startsWith(mTempContainerPrefix)) {
-                    continue;
-                }
-
-                String subStr = name.substring(mTempContainerPrefix.length());
-                try {
-                    int cid = Integer.parseInt(subStr);
-                    if (cid >= tmpIdx) {
-                        tmpIdx = cid + 1;
-                    }
-                } catch (NumberFormatException e) {
-                }
-            }
-        }
-        return mTempContainerPrefix + tmpIdx;
-    }
-
-    /*
-     * Update media status on PackageManager.
-     */
-    public void updateExternalMediaStatus(final boolean mediaStatus, final boolean reportStatus) {
-        int callingUid = Binder.getCallingUid();
-        if (callingUid != 0 && callingUid != Process.SYSTEM_UID) {
-            throw new SecurityException("Media status can only be updated by the system");
-        }
-        // reader; this apparently protects mMediaMounted, but should probably
-        // be a different lock in that case.
-        synchronized (mPackages) {
-            Log.i(TAG, "Updating external media status from "
-                    + (mMediaMounted ? "mounted" : "unmounted") + " to "
-                    + (mediaStatus ? "mounted" : "unmounted"));
-            if (DEBUG_SD_INSTALL)
-                Log.i(TAG, "updateExternalMediaStatus:: mediaStatus=" + mediaStatus
-                        + ", mMediaMounted=" + mMediaMounted);
-            if (mediaStatus == mMediaMounted) {
-                final Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, reportStatus ? 1
-                        : 0, -1);
-                mHandler.sendMessage(msg);
-                return;
-            }
-            mMediaMounted = mediaStatus;
-        }
-        // Queue up an async operation since the package installation may take a
-        // little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                updateExternalMediaStatusInner(mediaStatus, reportStatus, true);
-            }
-        });
-    }
-
-    /**
-     * Called by MountService when the initial ASECs to scan are available.
-     * Should block until all the ASEC containers are finished being scanned.
-     */
-    public void scanAvailableAsecs() {
-        updateExternalMediaStatusInner(true, false, false);
-    }
-
-    /*
-     * Collect information of applications on external media, map them against
-     * existing containers and update information based on current mount status.
-     * Please note that we always have to report status if reportStatus has been
-     * set to true especially when unloading packages.
-     */
-    private void updateExternalMediaStatusInner(boolean isMounted, boolean reportStatus,
-            boolean externalStorage) {
-        // Collection of uids
-        int uidArr[] = null;
-        // Collection of stale containers
-        HashSet<String> removeCids = new HashSet<String>();
-        // Collection of packages on external media with valid containers.
-        HashMap<AsecInstallArgs, String> processCids = new HashMap<AsecInstallArgs, String>();
-        // Get list of secure containers.
-        final String list[] = PackageHelper.getSecureContainerList();
-        if (list == null || list.length == 0) {
-            Log.i(TAG, "No secure containers on sdcard");
-        } else {
-            // Process list of secure containers and categorize them
-            // as active or stale based on their package internal state.
-            int uidList[] = new int[list.length];
-            int num = 0;
-            // reader
-            synchronized (mPackages) {
-                for (String cid : list) {
-                    if (DEBUG_SD_INSTALL)
-                        Log.i(TAG, "Processing container " + cid);
-                    String pkgName = getAsecPackageName(cid);
-                    if (pkgName == null) {
-                        if (DEBUG_SD_INSTALL)
-                            Log.i(TAG, "Container : " + cid + " stale");
-                        removeCids.add(cid);
-                        continue;
-                    }
-                    if (DEBUG_SD_INSTALL)
-                        Log.i(TAG, "Looking for pkg : " + pkgName);
-
-                    final PackageSetting ps = mSettings.mPackages.get(pkgName);
-                    if (ps == null) {
-                        Log.i(TAG, "Deleting container with no matching settings " + cid);
-                        removeCids.add(cid);
-                        continue;
-                    }
-
-                    /*
-                     * Skip packages that are not external if we're unmounting
-                     * external storage.
-                     */
-                    if (externalStorage && !isMounted && !isExternal(ps)) {
-                        continue;
-                    }
-
-                    final AsecInstallArgs args = new AsecInstallArgs(cid, isForwardLocked(ps));
-                    // The package status is changed only if the code path
-                    // matches between settings and the container id.
-                    if (ps.codePathString != null && ps.codePathString.equals(args.getCodePath())) {
-                        if (DEBUG_SD_INSTALL) {
-                            Log.i(TAG, "Container : " + cid + " corresponds to pkg : " + pkgName
-                                    + " at code path: " + ps.codePathString);
-                        }
-
-                        // We do have a valid package installed on sdcard
-                        processCids.put(args, ps.codePathString);
-                        final int uid = ps.appId;
-                        if (uid != -1) {
-                            uidList[num++] = uid;
-                        }
-                    } else {
-                        Log.i(TAG, "Deleting stale container for " + cid);
-                        removeCids.add(cid);
-                    }
-                }
-            }
-
-            if (num > 0) {
-                // Sort uid list
-                Arrays.sort(uidList, 0, num);
-                // Throw away duplicates
-                uidArr = new int[num];
-                uidArr[0] = uidList[0];
-                int di = 0;
-                for (int i = 1; i < num; i++) {
-                    if (uidList[i - 1] != uidList[i]) {
-                        uidArr[di++] = uidList[i];
-                    }
-                }
-            }
-        }
-        // Process packages with valid entries.
-        if (isMounted) {
-            if (DEBUG_SD_INSTALL)
-                Log.i(TAG, "Loading packages");
-            loadMediaPackages(processCids, uidArr, removeCids);
-            startCleaningPackages();
-        } else {
-            if (DEBUG_SD_INSTALL)
-                Log.i(TAG, "Unloading packages");
-            unloadMediaPackages(processCids, uidArr, reportStatus);
-        }
-    }
-
-   private void sendResourcesChangedBroadcast(boolean mediaStatus, boolean replacing,
-           ArrayList<String> pkgList, int uidArr[], IIntentReceiver finishedReceiver) {
-        int size = pkgList.size();
-        if (size > 0) {
-            // Send broadcasts here
-            Bundle extras = new Bundle();
-            extras.putStringArray(Intent.EXTRA_CHANGED_PACKAGE_LIST, pkgList
-                    .toArray(new String[size]));
-            if (uidArr != null) {
-                extras.putIntArray(Intent.EXTRA_CHANGED_UID_LIST, uidArr);
-            }
-            if (replacing) {
-                extras.putBoolean(Intent.EXTRA_REPLACING, replacing);
-            }
-            String action = mediaStatus ? Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE
-                    : Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE;
-            sendPackageBroadcast(action, null, extras, null, finishedReceiver, null);
-        }
-    }
-
-   /*
-     * Look at potentially valid container ids from processCids If package
-     * information doesn't match the one on record or package scanning fails,
-     * the cid is added to list of removeCids. We currently don't delete stale
-     * containers.
-     */
-   private void loadMediaPackages(HashMap<AsecInstallArgs, String> processCids, int uidArr[],
-            HashSet<String> removeCids) {
-        ArrayList<String> pkgList = new ArrayList<String>();
-        Set<AsecInstallArgs> keys = processCids.keySet();
-        boolean doGc = false;
-        for (AsecInstallArgs args : keys) {
-            String codePath = processCids.get(args);
-            if (DEBUG_SD_INSTALL)
-                Log.i(TAG, "Loading container : " + args.cid);
-            int retCode = PackageManager.INSTALL_FAILED_CONTAINER_ERROR;
-            try {
-                // Make sure there are no container errors first.
-                if (args.doPreInstall(PackageManager.INSTALL_SUCCEEDED) != PackageManager.INSTALL_SUCCEEDED) {
-                    Slog.e(TAG, "Failed to mount cid : " + args.cid
-                            + " when installing from sdcard");
-                    continue;
-                }
-                // Check code path here.
-                if (codePath == null || !codePath.equals(args.getCodePath())) {
-                    Slog.e(TAG, "Container " + args.cid + " cachepath " + args.getCodePath()
-                            + " does not match one in settings " + codePath);
-                    continue;
-                }
-                // Parse package
-                int parseFlags = mDefParseFlags;
-                if (args.isExternal()) {
-                    parseFlags |= PackageParser.PARSE_ON_SDCARD;
-                }
-                if (args.isFwdLocked()) {
-                    parseFlags |= PackageParser.PARSE_FORWARD_LOCK;
-                }
-
-                doGc = true;
-                synchronized (mInstallLock) {
-                    final PackageParser.Package pkg = scanPackageLI(new File(codePath), parseFlags,
-                            0, 0, null);
-                    // Scan the package
-                    if (pkg != null) {
-                        /*
-                         * TODO why is the lock being held? doPostInstall is
-                         * called in other places without the lock. This needs
-                         * to be straightened out.
-                         */
-                        // writer
-                        synchronized (mPackages) {
-                            retCode = PackageManager.INSTALL_SUCCEEDED;
-                            pkgList.add(pkg.packageName);
-                            // Post process args
-                            args.doPostInstall(PackageManager.INSTALL_SUCCEEDED,
-                                    pkg.applicationInfo.uid);
-                        }
-                    } else {
-                        Slog.i(TAG, "Failed to install pkg from  " + codePath + " from sdcard");
-                    }
-                }
-
-            } finally {
-                if (retCode != PackageManager.INSTALL_SUCCEEDED) {
-                    // Don't destroy container here. Wait till gc clears things
-                    // up.
-                    removeCids.add(args.cid);
-                }
-            }
-        }
-        // writer
-        synchronized (mPackages) {
-            // If the platform SDK has changed since the last time we booted,
-            // we need to re-grant app permission to catch any new ones that
-            // appear. This is really a hack, and means that apps can in some
-            // cases get permissions that the user didn't initially explicitly
-            // allow... it would be nice to have some better way to handle
-            // this situation.
-            final boolean regrantPermissions = mSettings.mExternalSdkPlatform != mSdkVersion;
-            if (regrantPermissions)
-                Slog.i(TAG, "Platform changed from " + mSettings.mExternalSdkPlatform + " to "
-                        + mSdkVersion + "; regranting permissions for external storage");
-            mSettings.mExternalSdkPlatform = mSdkVersion;
-
-            // Make sure group IDs have been assigned, and any permission
-            // changes in other apps are accounted for
-            updatePermissionsLPw(null, null, UPDATE_PERMISSIONS_ALL
-                    | (regrantPermissions
-                            ? (UPDATE_PERMISSIONS_REPLACE_PKG|UPDATE_PERMISSIONS_REPLACE_ALL)
-                            : 0));
-            // can downgrade to reader
-            // Persist settings
-            mSettings.writeLPr();
-        }
-        // Send a broadcast to let everyone know we are done processing
-        if (pkgList.size() > 0) {
-            sendResourcesChangedBroadcast(true, false, pkgList, uidArr, null);
-        }
-        // Force gc to avoid any stale parser references that we might have.
-        if (doGc) {
-            Runtime.getRuntime().gc();
-        }
-        // List stale containers and destroy stale temporary containers.
-        if (removeCids != null) {
-            for (String cid : removeCids) {
-                if (cid.startsWith(mTempContainerPrefix)) {
-                    Log.i(TAG, "Destroying stale temporary container " + cid);
-                    PackageHelper.destroySdDir(cid);
-                } else {
-                    Log.w(TAG, "Container " + cid + " is stale");
-               }
-           }
-        }
-    }
-
-   /*
-     * Utility method to unload a list of specified containers
-     */
-    private void unloadAllContainers(Set<AsecInstallArgs> cidArgs) {
-        // Just unmount all valid containers.
-        for (AsecInstallArgs arg : cidArgs) {
-            synchronized (mInstallLock) {
-                arg.doPostDeleteLI(false);
-           }
-       }
-   }
-
-    /*
-     * Unload packages mounted on external media. This involves deleting package
-     * data from internal structures, sending broadcasts about diabled packages,
-     * gc'ing to free up references, unmounting all secure containers
-     * corresponding to packages on external media, and posting a
-     * UPDATED_MEDIA_STATUS message if status has been requested. Please note
-     * that we always have to post this message if status has been requested no
-     * matter what.
-     */
-    private void unloadMediaPackages(HashMap<AsecInstallArgs, String> processCids, int uidArr[],
-            final boolean reportStatus) {
-        if (DEBUG_SD_INSTALL)
-            Log.i(TAG, "unloading media packages");
-        ArrayList<String> pkgList = new ArrayList<String>();
-        ArrayList<AsecInstallArgs> failedList = new ArrayList<AsecInstallArgs>();
-        final Set<AsecInstallArgs> keys = processCids.keySet();
-        for (AsecInstallArgs args : keys) {
-            String pkgName = args.getPackageName();
-            if (DEBUG_SD_INSTALL)
-                Log.i(TAG, "Trying to unload pkg : " + pkgName);
-            // Delete package internally
-            PackageRemovedInfo outInfo = new PackageRemovedInfo();
-            synchronized (mInstallLock) {
-                boolean res = deletePackageLI(pkgName, null, false, null, null,
-                        PackageManager.DELETE_KEEP_DATA, outInfo, false);
-                if (res) {
-                    pkgList.add(pkgName);
-                } else {
-                    Slog.e(TAG, "Failed to delete pkg from sdcard : " + pkgName);
-                    failedList.add(args);
-                }
-            }
-        }
-
-        // reader
-        synchronized (mPackages) {
-            // We didn't update the settings after removing each package;
-            // write them now for all packages.
-            mSettings.writeLPr();
-        }
-
-        // We have to absolutely send UPDATED_MEDIA_STATUS only
-        // after confirming that all the receivers processed the ordered
-        // broadcast when packages get disabled, force a gc to clean things up.
-        // and unload all the containers.
-        if (pkgList.size() > 0) {
-            sendResourcesChangedBroadcast(false, false, pkgList, uidArr,
-                    new IIntentReceiver.Stub() {
-                public void performReceive(Intent intent, int resultCode, String data,
-                        Bundle extras, boolean ordered, boolean sticky,
-                        int sendingUser) throws RemoteException {
-                    Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS,
-                            reportStatus ? 1 : 0, 1, keys);
-                    mHandler.sendMessage(msg);
-                }
-            });
-        } else {
-            Message msg = mHandler.obtainMessage(UPDATED_MEDIA_STATUS, reportStatus ? 1 : 0, -1,
-                    keys);
-            mHandler.sendMessage(msg);
-        }
-    }
-
-    /** Binder call */
-    @Override
-    public void movePackage(final String packageName, final IPackageMoveObserver observer,
-            final int flags) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MOVE_PACKAGE, null);
-        UserHandle user = new UserHandle(UserHandle.getCallingUserId());
-        int returnCode = PackageManager.MOVE_SUCCEEDED;
-        int currFlags = 0;
-        int newFlags = 0;
-        // reader
-        synchronized (mPackages) {
-            PackageParser.Package pkg = mPackages.get(packageName);
-            if (pkg == null) {
-                returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
-            } else {
-                // Disable moving fwd locked apps and system packages
-                if (pkg.applicationInfo != null && isSystemApp(pkg)) {
-                    Slog.w(TAG, "Cannot move system application");
-                    returnCode = PackageManager.MOVE_FAILED_SYSTEM_PACKAGE;
-                } else if (pkg.mOperationPending) {
-                    Slog.w(TAG, "Attempt to move package which has pending operations");
-                    returnCode = PackageManager.MOVE_FAILED_OPERATION_PENDING;
-                } else {
-                    // Find install location first
-                    if ((flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0
-                            && (flags & PackageManager.MOVE_INTERNAL) != 0) {
-                        Slog.w(TAG, "Ambigous flags specified for move location.");
-                        returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION;
-                    } else {
-                        newFlags = (flags & PackageManager.MOVE_EXTERNAL_MEDIA) != 0 ? PackageManager.INSTALL_EXTERNAL
-                                : PackageManager.INSTALL_INTERNAL;
-                        currFlags = isExternal(pkg) ? PackageManager.INSTALL_EXTERNAL
-                                : PackageManager.INSTALL_INTERNAL;
-
-                        if (newFlags == currFlags) {
-                            Slog.w(TAG, "No move required. Trying to move to same location");
-                            returnCode = PackageManager.MOVE_FAILED_INVALID_LOCATION;
-                        } else {
-                            if (isForwardLocked(pkg)) {
-                                currFlags |= PackageManager.INSTALL_FORWARD_LOCK;
-                                newFlags |= PackageManager.INSTALL_FORWARD_LOCK;
-                            }
-                        }
-                    }
-                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
-                        pkg.mOperationPending = true;
-                    }
-                }
-            }
-
-            /*
-             * TODO this next block probably shouldn't be inside the lock. We
-             * can't guarantee these won't change after this is fired off
-             * anyway.
-             */
-            if (returnCode != PackageManager.MOVE_SUCCEEDED) {
-                processPendingMove(new MoveParams(null, observer, 0, packageName,
-                        null, -1, user),
-                        returnCode);
-            } else {
-                Message msg = mHandler.obtainMessage(INIT_COPY);
-                InstallArgs srcArgs = createInstallArgs(currFlags, pkg.applicationInfo.sourceDir,
-                        pkg.applicationInfo.publicSourceDir, pkg.applicationInfo.nativeLibraryDir);
-                MoveParams mp = new MoveParams(srcArgs, observer, newFlags, packageName,
-                        pkg.applicationInfo.dataDir, pkg.applicationInfo.uid, user);
-                msg.obj = mp;
-                mHandler.sendMessage(msg);
-            }
-        }
-    }
-
-    private void processPendingMove(final MoveParams mp, final int currentStatus) {
-        // Queue up an async operation since the package deletion may take a
-        // little while.
-        mHandler.post(new Runnable() {
-            public void run() {
-                // TODO fix this; this does nothing.
-                mHandler.removeCallbacks(this);
-                int returnCode = currentStatus;
-                if (currentStatus == PackageManager.MOVE_SUCCEEDED) {
-                    int uidArr[] = null;
-                    ArrayList<String> pkgList = null;
-                    synchronized (mPackages) {
-                        PackageParser.Package pkg = mPackages.get(mp.packageName);
-                        if (pkg == null) {
-                            Slog.w(TAG, " Package " + mp.packageName
-                                    + " doesn't exist. Aborting move");
-                            returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
-                        } else if (!mp.srcArgs.getCodePath().equals(pkg.applicationInfo.sourceDir)) {
-                            Slog.w(TAG, "Package " + mp.packageName + " code path changed from "
-                                    + mp.srcArgs.getCodePath() + " to "
-                                    + pkg.applicationInfo.sourceDir
-                                    + " Aborting move and returning error");
-                            returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
-                        } else {
-                            uidArr = new int[] {
-                                pkg.applicationInfo.uid
-                            };
-                            pkgList = new ArrayList<String>();
-                            pkgList.add(mp.packageName);
-                        }
-                    }
-                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
-                        // Send resources unavailable broadcast
-                        sendResourcesChangedBroadcast(false, true, pkgList, uidArr, null);
-                        // Update package code and resource paths
-                        synchronized (mInstallLock) {
-                            synchronized (mPackages) {
-                                PackageParser.Package pkg = mPackages.get(mp.packageName);
-                                // Recheck for package again.
-                                if (pkg == null) {
-                                    Slog.w(TAG, " Package " + mp.packageName
-                                            + " doesn't exist. Aborting move");
-                                    returnCode = PackageManager.MOVE_FAILED_DOESNT_EXIST;
-                                } else if (!mp.srcArgs.getCodePath().equals(
-                                        pkg.applicationInfo.sourceDir)) {
-                                    Slog.w(TAG, "Package " + mp.packageName
-                                            + " code path changed from " + mp.srcArgs.getCodePath()
-                                            + " to " + pkg.applicationInfo.sourceDir
-                                            + " Aborting move and returning error");
-                                    returnCode = PackageManager.MOVE_FAILED_INTERNAL_ERROR;
-                                } else {
-                                    final String oldCodePath = pkg.mPath;
-                                    final String newCodePath = mp.targetArgs.getCodePath();
-                                    final String newResPath = mp.targetArgs.getResourcePath();
-                                    final String newNativePath = mp.targetArgs
-                                            .getNativeLibraryPath();
-
-                                    final File newNativeDir = new File(newNativePath);
-
-                                    if (!isForwardLocked(pkg) && !isExternal(pkg)) {
-                                        NativeLibraryHelper.copyNativeBinariesIfNeededLI(
-                                                new File(newCodePath), newNativeDir);
-                                    }
-                                    final int[] users = sUserManager.getUserIds();
-                                    for (int user : users) {
-                                        if (mInstaller.linkNativeLibraryDirectory(pkg.packageName,
-                                                newNativePath, user) < 0) {
-                                            returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
-                                        }
-                                    }
-
-                                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
-                                        pkg.mPath = newCodePath;
-                                        // Move dex files around
-                                        if (moveDexFilesLI(pkg) != PackageManager.INSTALL_SUCCEEDED) {
-                                            // Moving of dex files failed. Set
-                                            // error code and abort move.
-                                            pkg.mPath = pkg.mScanPath;
-                                            returnCode = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
-                                        }
-                                    }
-
-                                    if (returnCode == PackageManager.MOVE_SUCCEEDED) {
-                                        pkg.mScanPath = newCodePath;
-                                        pkg.applicationInfo.sourceDir = newCodePath;
-                                        pkg.applicationInfo.publicSourceDir = newResPath;
-                                        pkg.applicationInfo.nativeLibraryDir = newNativePath;
-                                        PackageSetting ps = (PackageSetting) pkg.mExtras;
-                                        ps.codePath = new File(pkg.applicationInfo.sourceDir);
-                                        ps.codePathString = ps.codePath.getPath();
-                                        ps.resourcePath = new File(
-                                                pkg.applicationInfo.publicSourceDir);
-                                        ps.resourcePathString = ps.resourcePath.getPath();
-                                        ps.nativeLibraryPathString = newNativePath;
-                                        // Set the application info flag
-                                        // correctly.
-                                        if ((mp.flags & PackageManager.INSTALL_EXTERNAL) != 0) {
-                                            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
-                                        } else {
-                                            pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_EXTERNAL_STORAGE;
-                                        }
-                                        ps.setFlags(pkg.applicationInfo.flags);
-                                        mAppDirs.remove(oldCodePath);
-                                        mAppDirs.put(newCodePath, pkg);
-                                        // Persist settings
-                                        mSettings.writeLPr();
-                                    }
-                                }
-                            }
-                        }
-                        // Send resources available broadcast
-                        sendResourcesChangedBroadcast(true, false, pkgList, uidArr, null);
-                    }
-                }
-                if (returnCode != PackageManager.MOVE_SUCCEEDED) {
-                    // Clean up failed installation
-                    if (mp.targetArgs != null) {
-                        mp.targetArgs.doPostInstall(PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
-                                -1);
-                    }
-                } else {
-                    // Force a gc to clear things up.
-                    Runtime.getRuntime().gc();
-                    // Delete older code
-                    synchronized (mInstallLock) {
-                        mp.srcArgs.doPostDeleteLI(true);
-                    }
-                }
-
-                // Allow more operations on this file if we didn't fail because
-                // an operation was already pending for this package.
-                if (returnCode != PackageManager.MOVE_FAILED_OPERATION_PENDING) {
-                    synchronized (mPackages) {
-                        PackageParser.Package pkg = mPackages.get(mp.packageName);
-                        if (pkg != null) {
-                            pkg.mOperationPending = false;
-                       }
-                   }
-                }
-
-                IPackageMoveObserver observer = mp.observer;
-                if (observer != null) {
-                    try {
-                        observer.packageMoved(mp.packageName, returnCode);
-                    } catch (RemoteException e) {
-                        Log.i(TAG, "Observer no longer exists.");
-                    }
-                }
-            }
-        });
-    }
-
-    public boolean setInstallLocation(int loc) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,
-                null);
-        if (getInstallLocation() == loc) {
-            return true;
-        }
-        if (loc == PackageHelper.APP_INSTALL_AUTO || loc == PackageHelper.APP_INSTALL_INTERNAL
-                || loc == PackageHelper.APP_INSTALL_EXTERNAL) {
-            android.provider.Settings.Global.putInt(mContext.getContentResolver(),
-                    android.provider.Settings.Global.DEFAULT_INSTALL_LOCATION, loc);
-            return true;
-        }
-        return false;
-   }
-
-    public int getInstallLocation() {
-        return android.provider.Settings.Global.getInt(mContext.getContentResolver(),
-                android.provider.Settings.Global.DEFAULT_INSTALL_LOCATION,
-                PackageHelper.APP_INSTALL_AUTO);
-    }
-
-    /** Called by UserManagerService */
-    void cleanUpUserLILPw(int userHandle) {
-        mDirtyUsers.remove(userHandle);
-        mSettings.removeUserLPr(userHandle);
-        mPendingBroadcasts.remove(userHandle);
-        if (mInstaller != null) {
-            // Technically, we shouldn't be doing this with the package lock
-            // held.  However, this is very rare, and there is already so much
-            // other disk I/O going on, that we'll let it slide for now.
-            mInstaller.removeUserDataDirs(userHandle);
-        }
-    }
-
-    /** Called by UserManagerService */
-    void createNewUserLILPw(int userHandle, File path) {
-        if (mInstaller != null) {
-            mSettings.createNewUserLILPw(this, mInstaller, userHandle, path);
-        }
-    }
-
-    @Override
-    public VerifierDeviceIdentity getVerifierDeviceIdentity() throws RemoteException {
-        mContext.enforceCallingOrSelfPermission(
-                android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
-                "Only package verification agents can read the verifier device identity");
-
-        synchronized (mPackages) {
-            return mSettings.getVerifierDeviceIdentityLPw();
-        }
-    }
-
-    @Override
-    public void setPermissionEnforced(String permission, boolean enforced) {
-        mContext.enforceCallingOrSelfPermission(GRANT_REVOKE_PERMISSIONS, null);
-        if (READ_EXTERNAL_STORAGE.equals(permission)) {
-            synchronized (mPackages) {
-                if (mSettings.mReadExternalStorageEnforced == null
-                        || mSettings.mReadExternalStorageEnforced != enforced) {
-                    mSettings.mReadExternalStorageEnforced = enforced;
-                    mSettings.writeLPr();
-                }
-            }
-            // kill any non-foreground processes so we restart them and
-            // grant/revoke the GID.
-            final IActivityManager am = ActivityManagerNative.getDefault();
-            if (am != null) {
-                final long token = Binder.clearCallingIdentity();
-                try {
-                    am.killProcessesBelowForeground("setPermissionEnforcement");
-                } catch (RemoteException e) {
-                } finally {
-                    Binder.restoreCallingIdentity(token);
-                }
-            }
-        } else {
-            throw new IllegalArgumentException("No selective enforcement for " + permission);
-        }
-    }
-
-    @Override
-    @Deprecated
-    public boolean isPermissionEnforced(String permission) {
-        return true;
-    }
-
-    public boolean isStorageLow() {
-        final long token = Binder.clearCallingIdentity();
-        try {
-            final DeviceStorageMonitorService dsm = (DeviceStorageMonitorService) ServiceManager
-                    .getService(DeviceStorageMonitorService.SERVICE);
-            return dsm.isMemoryLow();
-        } finally {
-            Binder.restoreCallingIdentity(token);
-        }
-    }
-}
diff --git a/services/java/com/android/server/pm/PreferredActivity.java b/services/java/com/android/server/pm/PreferredActivity.java
deleted file mode 100644
index f93ba2f..0000000
--- a/services/java/com/android/server/pm/PreferredActivity.java
+++ /dev/null
@@ -1,80 +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.server.pm;
-
-import com.android.internal.util.XmlUtils;
-import com.android.server.PreferredComponent;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.content.ComponentName;
-import android.content.IntentFilter;
-import android.util.Log;
-
-import java.io.IOException;
-
-class PreferredActivity extends IntentFilter implements PreferredComponent.Callbacks {
-    private static final String TAG = "PreferredActivity";
-
-    private static final boolean DEBUG_FILTERS = false;
-
-    final PreferredComponent mPref;
-
-    PreferredActivity(IntentFilter filter, int match, ComponentName[] set, ComponentName activity,
-            boolean always) {
-        super(filter);
-        mPref = new PreferredComponent(this, match, set, activity, always);
-    }
-
-    PreferredActivity(XmlPullParser parser) throws XmlPullParserException, IOException {
-        mPref = new PreferredComponent(this, parser);
-    }
-
-    public void writeToXml(XmlSerializer serializer, boolean full) throws IOException {
-        mPref.writeToXml(serializer, full);
-        serializer.startTag(null, "filter");
-            super.writeToXml(serializer);
-        serializer.endTag(null, "filter");
-    }
-
-    public boolean onReadTag(String tagName, XmlPullParser parser) throws XmlPullParserException,
-            IOException {
-        if (tagName.equals("filter")) {
-            if (DEBUG_FILTERS) {
-                Log.i(TAG, "Starting to parse filter...");
-            }
-            readFromXml(parser);
-            if (DEBUG_FILTERS) {
-                Log.i(TAG, "Finished filter: depth=" + parser.getDepth() + " tag="
-                        + parser.getName());
-            }
-        } else {
-            PackageManagerService.reportSettingsProblem(Log.WARN,
-                    "Unknown element under <preferred-activities>: " + parser.getName());
-            XmlUtils.skipCurrentTag(parser);
-        }
-        return true;
-    }
-
-    @Override
-    public String toString() {
-        return "PreferredActivity{0x" + Integer.toHexString(System.identityHashCode(this))
-                + " " + mPref.mComponent.flattenToShortString() + "}";
-    }
-}
diff --git a/services/java/com/android/server/pm/SELinuxMMAC.java b/services/java/com/android/server/pm/SELinuxMMAC.java
deleted file mode 100644
index 04f43d9..0000000
--- a/services/java/com/android/server/pm/SELinuxMMAC.java
+++ /dev/null
@@ -1,294 +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.server.pm;
-
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageParser;
-import android.content.pm.Signature;
-import android.os.Environment;
-import android.util.Slog;
-import android.util.Xml;
-
-import com.android.internal.util.XmlUtils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-
-import java.util.HashMap;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-/**
- * Centralized access to SELinux MMAC (middleware MAC) implementation.
- * {@hide}
- */
-public final class SELinuxMMAC {
-
-    private static final String TAG = "SELinuxMMAC";
-
-    private static final boolean DEBUG_POLICY = false;
-    private static final boolean DEBUG_POLICY_INSTALL = DEBUG_POLICY || false;
-
-    // Signature seinfo values read from policy.
-    private static final HashMap<Signature, String> sSigSeinfo =
-        new HashMap<Signature, String>();
-
-    // Package name seinfo values read from policy.
-    private static final HashMap<String, String> sPackageSeinfo =
-        new HashMap<String, String>();
-
-    // Locations of potential install policy files.
-    private static final File[] INSTALL_POLICY_FILE = {
-        new File(Environment.getDataDirectory(), "security/mac_permissions.xml"),
-        new File(Environment.getRootDirectory(), "etc/security/mac_permissions.xml"),
-        null};
-
-    private static void flushInstallPolicy() {
-        sSigSeinfo.clear();
-        sPackageSeinfo.clear();
-    }
-
-    /**
-     * Parses an MMAC install policy from a predefined list of locations.
-     * @param none
-     * @return boolean indicating whether an install policy was correctly parsed.
-     */
-    public static boolean readInstallPolicy() {
-
-        return readInstallPolicy(INSTALL_POLICY_FILE);
-    }
-
-    /**
-     * Parses an MMAC install policy given as an argument.
-     * @param File object representing the path of the policy.
-     * @return boolean indicating whether the install policy was correctly parsed.
-     */
-    public static boolean readInstallPolicy(File policyFile) {
-
-        return readInstallPolicy(new File[]{policyFile,null});
-    }
-
-    private static boolean readInstallPolicy(File[] policyFiles) {
-
-        FileReader policyFile = null;
-        int i = 0;
-        while (policyFile == null && policyFiles != null && policyFiles[i] != null) {
-            try {
-                policyFile = new FileReader(policyFiles[i]);
-                break;
-            } catch (FileNotFoundException e) {
-                Slog.d(TAG,"Couldn't find install policy " + policyFiles[i].getPath());
-            }
-            i++;
-        }
-
-        if (policyFile == null) {
-            Slog.d(TAG, "No policy file found. All seinfo values will be null.");
-            return false;
-        }
-
-        Slog.d(TAG, "Using install policy file " + policyFiles[i].getPath());
-
-        flushInstallPolicy();
-
-        try {
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(policyFile);
-
-            XmlUtils.beginDocument(parser, "policy");
-            while (true) {
-                XmlUtils.nextElement(parser);
-                if (parser.getEventType() == XmlPullParser.END_DOCUMENT) {
-                    break;
-                }
-
-                String tagName = parser.getName();
-                if ("signer".equals(tagName)) {
-                    String cert = parser.getAttributeValue(null, "signature");
-                    if (cert == null) {
-                        Slog.w(TAG, "<signer> without signature at "
-                               + parser.getPositionDescription());
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    Signature signature;
-                    try {
-                        signature = new Signature(cert);
-                    } catch (IllegalArgumentException e) {
-                        Slog.w(TAG, "<signer> with bad signature at "
-                               + parser.getPositionDescription(), e);
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    String seinfo = readSeinfoTag(parser);
-                    if (seinfo != null) {
-                        if (DEBUG_POLICY_INSTALL)
-                            Slog.i(TAG, "<signer> tag: (" + cert + ") assigned seinfo="
-                                   + seinfo);
-
-                        sSigSeinfo.put(signature, seinfo);
-                    }
-                } else if ("default".equals(tagName)) {
-                    String seinfo = readSeinfoTag(parser);
-                    if (seinfo != null) {
-                        if (DEBUG_POLICY_INSTALL)
-                            Slog.i(TAG, "<default> tag assigned seinfo=" + seinfo);
-
-                        // The 'null' signature is the default seinfo value
-                        sSigSeinfo.put(null, seinfo);
-                    }
-                } else if ("package".equals(tagName)) {
-                    String pkgName = parser.getAttributeValue(null, "name");
-                    if (pkgName == null) {
-                        Slog.w(TAG, "<package> without name at "
-                               + parser.getPositionDescription());
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    String seinfo = readSeinfoTag(parser);
-                    if (seinfo != null) {
-                        if (DEBUG_POLICY_INSTALL)
-                            Slog.i(TAG, "<package> tag: (" + pkgName +
-                                   ") assigned seinfo=" + seinfo);
-
-                        sPackageSeinfo.put(pkgName, seinfo);
-                    }
-                } else {
-                    XmlUtils.skipCurrentTag(parser);
-                    continue;
-                }
-            }
-        } catch (XmlPullParserException e) {
-            Slog.w(TAG, "Got execption parsing ", e);
-        } catch (IOException e) {
-            Slog.w(TAG, "Got execption parsing ", e);
-        }
-        try {
-            policyFile.close();
-        } catch (IOException e) {
-            //omit
-        }
-        return true;
-    }
-
-    private static String readSeinfoTag(XmlPullParser parser) throws
-            IOException, XmlPullParserException {
-
-        int type;
-        int outerDepth = parser.getDepth();
-        String seinfo = null;
-        while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-               && (type != XmlPullParser.END_TAG
-                   || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG
-                || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if ("seinfo".equals(tagName)) {
-                String seinfoValue = parser.getAttributeValue(null, "value");
-                if (validateValue(seinfoValue)) {
-                    seinfo = seinfoValue;
-                } else {
-                    Slog.w(TAG, "<seinfo> without valid value at "
-                           + parser.getPositionDescription());
-                }
-            }
-            XmlUtils.skipCurrentTag(parser);
-        }
-        return seinfo;
-    }
-
-    /**
-     * General validation routine for tag values.
-     * Returns a boolean indicating if the passed string
-     * contains only letters or underscores.
-     */
-    private static boolean validateValue(String name) {
-        if (name == null)
-            return false;
-
-        final int N = name.length();
-        if (N == 0)
-            return false;
-
-        for (int i = 0; i < N; i++) {
-            final char c = name.charAt(i);
-            if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && (c != '_')) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Labels a package based on an seinfo tag from install policy.
-     * The label is attached to the ApplicationInfo instance of the package.
-     * @param PackageParser.Package object representing the package
-     *         to labeled.
-     * @return String holding the value of the seinfo label that was assigned.
-     *         Value may be null which indicates no seinfo label was assigned.
-     */
-    public static void assignSeinfoValue(PackageParser.Package pkg) {
-
-        /*
-         * Non system installed apps should be treated the same. This
-         * means that any post-loaded apk will be assigned the default
-         * tag, if one exists in the policy, else null, without respect
-         * to the signing key.
-         */
-        if (((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ||
-            ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0)) {
-
-            // We just want one of the signatures to match.
-            for (Signature s : pkg.mSignatures) {
-                if (s == null)
-                    continue;
-
-                if (sSigSeinfo.containsKey(s)) {
-                    String seinfo = pkg.applicationInfo.seinfo = sSigSeinfo.get(s);
-                    if (DEBUG_POLICY_INSTALL)
-                        Slog.i(TAG, "package (" + pkg.packageName +
-                               ") labeled with seinfo=" + seinfo);
-
-                    return;
-                }
-            }
-
-            // Check for seinfo labeled by package.
-            if (sPackageSeinfo.containsKey(pkg.packageName)) {
-                String seinfo = pkg.applicationInfo.seinfo = sPackageSeinfo.get(pkg.packageName);
-                if (DEBUG_POLICY_INSTALL)
-                    Slog.i(TAG, "package (" + pkg.packageName +
-                           ") labeled with seinfo=" + seinfo);
-                return;
-            }
-        }
-
-        // If we have a default seinfo value then great, otherwise
-        // we set a null object and that is what we started with.
-        String seinfo = pkg.applicationInfo.seinfo = sSigSeinfo.get(null);
-        if (DEBUG_POLICY_INSTALL)
-            Slog.i(TAG, "package (" + pkg.packageName +
-                   ") labeled with seinfo=" + (seinfo == null ? "null" : seinfo));
-    }
-}
diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java
deleted file mode 100644
index 19bfe01..0000000
--- a/services/java/com/android/server/pm/Settings.java
+++ /dev/null
@@ -1,3226 +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.server.pm;
-
-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.os.Process.SYSTEM_UID;
-import static android.os.Process.PACKAGE_INFO_GID;
-
-import android.content.IntentFilter;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ResolveInfo;
-import android.net.Uri;
-import android.os.PatternMatcher;
-import android.util.LogPrinter;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.JournaledFile;
-import com.android.internal.util.XmlUtils;
-import com.android.server.pm.PackageManagerService.DumpState;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.ComponentInfo;
-import android.content.pm.KeySet;
-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.os.Binder;
-import android.os.Environment;
-import android.os.FileUtils;
-import android.os.Process;
-import android.os.UserHandle;
-import android.util.Log;
-import android.util.LongSparseArray;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.Xml;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.security.PublicKey;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import libcore.io.IoUtils;
-
-/**
- * Holds information about dynamic settings.
- */
-final class Settings {
-    private static final String TAG = "PackageSettings";
-
-    private static final boolean DEBUG_STOPPED = false;
-    private static final boolean DEBUG_MU = false;
-
-    private static final String TAG_READ_EXTERNAL_STORAGE = "read-external-storage";
-    private static final String ATTR_ENFORCEMENT = "enforcement";
-
-    private static final String TAG_ITEM = "item";
-    private static final String TAG_DISABLED_COMPONENTS = "disabled-components";
-    private static final String TAG_ENABLED_COMPONENTS = "enabled-components";
-    private static final String TAG_PACKAGE_RESTRICTIONS = "package-restrictions";
-    private static final String TAG_PACKAGE = "pkg";
-
-    private static final String ATTR_NAME = "name";
-    private static final String ATTR_USER = "user";
-    private static final String ATTR_CODE = "code";
-    private static final String ATTR_NOT_LAUNCHED = "nl";
-    private static final String ATTR_ENABLED = "enabled";
-    private static final String ATTR_ENABLED_CALLER = "enabledCaller";
-    private static final String ATTR_STOPPED = "stopped";
-    private static final String ATTR_BLOCKED = "blocked";
-    private static final String ATTR_INSTALLED = "inst";
-
-    private final File mSettingsFilename;
-    private final File mBackupSettingsFilename;
-    private final File mPackageListFilename;
-    private final File mStoppedPackagesFilename;
-    private final File mBackupStoppedPackagesFilename;
-
-    final HashMap<String, PackageSetting> mPackages =
-            new HashMap<String, PackageSetting>();
-    // List of replaced system applications
-    private final HashMap<String, PackageSetting> mDisabledSysPackages =
-        new HashMap<String, PackageSetting>();
-
-    private static int mFirstAvailableUid = 0;
-
-    // These are the last platform API version we were using for
-    // the apps installed on internal and external storage.  It is
-    // used to grant newer permissions one time during a system upgrade.
-    int mInternalSdkPlatform;
-    int mExternalSdkPlatform;
-
-    Boolean mReadExternalStorageEnforced;
-
-    /** Device identity for the purpose of package verification. */
-    private VerifierDeviceIdentity mVerifierDeviceIdentity;
-
-    // The user's preferred activities associated with particular intent
-    // filters.
-    final SparseArray<PreferredIntentResolver> mPreferredActivities =
-            new SparseArray<PreferredIntentResolver>();
-
-    final HashMap<String, SharedUserSetting> mSharedUsers =
-            new HashMap<String, SharedUserSetting>();
-    private final ArrayList<Object> mUserIds = new ArrayList<Object>();
-    private final SparseArray<Object> mOtherUserIds =
-            new SparseArray<Object>();
-
-    // For reading/writing settings file.
-    private final ArrayList<Signature> mPastSignatures =
-            new ArrayList<Signature>();
-
-    // Mapping from permission names to info about them.
-    final HashMap<String, BasePermission> mPermissions =
-            new HashMap<String, BasePermission>();
-
-    // Mapping from permission tree names to info about them.
-    final HashMap<String, BasePermission> mPermissionTrees =
-            new HashMap<String, BasePermission>();
-
-    // Packages that have been uninstalled and still need their external
-    // storage data deleted.
-    final ArrayList<PackageCleanItem> mPackagesToBeCleaned = new ArrayList<PackageCleanItem>();
-    
-    // Packages that have been renamed since they were first installed.
-    // Keys are the new names of the packages, values are the original
-    // names.  The packages appear everwhere else under their original
-    // names.
-    final HashMap<String, String> mRenamedPackages = new HashMap<String, String>();
-    
-    final StringBuilder mReadMessages = new StringBuilder();
-
-    /**
-     * Used to track packages that have a shared user ID that hasn't been read
-     * in yet.
-     * <p>
-     * TODO: make this just a local variable that is passed in during package
-     * scanning to make it less confusing.
-     */
-    private final ArrayList<PendingPackage> mPendingPackages = new ArrayList<PendingPackage>();
-
-    private final Context mContext;
-
-    private final File mSystemDir;
-
-    public final KeySetManager mKeySetManager = new KeySetManager(mPackages);
-
-    Settings(Context context) {
-        this(context, Environment.getDataDirectory());
-    }
-
-    Settings(Context context, File dataDir) {
-        mContext = context;
-        mSystemDir = new File(dataDir, "system");
-        mSystemDir.mkdirs();
-        FileUtils.setPermissions(mSystemDir.toString(),
-                FileUtils.S_IRWXU|FileUtils.S_IRWXG
-                |FileUtils.S_IROTH|FileUtils.S_IXOTH,
-                -1, -1);
-        mSettingsFilename = new File(mSystemDir, "packages.xml");
-        mBackupSettingsFilename = new File(mSystemDir, "packages-backup.xml");
-        mPackageListFilename = new File(mSystemDir, "packages.list");
-        FileUtils.setPermissions(mPackageListFilename, 0660, SYSTEM_UID, PACKAGE_INFO_GID);
-
-        // Deprecated: Needed for migration
-        mStoppedPackagesFilename = new File(mSystemDir, "packages-stopped.xml");
-        mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml");
-    }
-
-    PackageSetting getPackageLPw(PackageParser.Package pkg, PackageSetting origPackage,
-            String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
-            String nativeLibraryPathString, int pkgFlags, UserHandle user, boolean add) {
-        final String name = pkg.packageName;
-        PackageSetting p = getPackageLPw(name, origPackage, realName, sharedUser, codePath,
-                resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags,
-                user, add, true /* allowInstall */);
-        return p;
-    }
-
-    PackageSetting peekPackageLPr(String name) {
-        return mPackages.get(name);
-    }
-
-    void setInstallStatus(String pkgName, int status) {
-        PackageSetting p = mPackages.get(pkgName);
-        if(p != null) {
-            if(p.getInstallStatus() != status) {
-                p.setInstallStatus(status);
-            }
-        }
-    }
-
-    void setInstallerPackageName(String pkgName,
-            String installerPkgName) {
-        PackageSetting p = mPackages.get(pkgName);
-        if(p != null) {
-            p.setInstallerPackageName(installerPkgName);
-        }
-    }
-
-    SharedUserSetting getSharedUserLPw(String name,
-            int pkgFlags, boolean create) {
-        SharedUserSetting s = mSharedUsers.get(name);
-        if (s == null) {
-            if (!create) {
-                return null;
-            }
-            s = new SharedUserSetting(name, pkgFlags);
-            s.userId = newUserIdLPw(s);
-            Log.i(PackageManagerService.TAG, "New shared user " + name + ": id=" + s.userId);
-            // < 0 means we couldn't assign a userid; fall out and return
-            // s, which is currently null
-            if (s.userId >= 0) {
-                mSharedUsers.put(name, s);
-            }
-        }
-
-        return s;
-    }
-
-    boolean disableSystemPackageLPw(String name) {
-        final PackageSetting p = mPackages.get(name);
-        if(p == null) {
-            Log.w(PackageManagerService.TAG, "Package:"+name+" is not an installed package");
-            return false;
-        }
-        final PackageSetting dp = mDisabledSysPackages.get(name);
-        // always make sure the system package code and resource paths dont change
-        if (dp == null) {
-            if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
-                p.pkg.applicationInfo.flags |= ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
-            }
-            mDisabledSysPackages.put(name, p);
-
-            // a little trick...  when we install the new package, we don't
-            // want to modify the existing PackageSetting for the built-in
-            // version.  so at this point we need a new PackageSetting that
-            // is okay to muck with.
-            PackageSetting newp = new PackageSetting(p);
-            replacePackageLPw(name, newp);
-            return true;
-        }
-        return false;
-    }
-
-    PackageSetting enableSystemPackageLPw(String name) {
-        PackageSetting p = mDisabledSysPackages.get(name);
-        if(p == null) {
-            Log.w(PackageManagerService.TAG, "Package:"+name+" is not disabled");
-            return null;
-        }
-        // Reset flag in ApplicationInfo object
-        if((p.pkg != null) && (p.pkg.applicationInfo != null)) {
-            p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
-        }
-        PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath,
-                p.nativeLibraryPathString, p.appId, p.versionCode, p.pkgFlags);
-        mDisabledSysPackages.remove(name);
-        return ret;
-    }
-
-    boolean isDisabledSystemPackageLPr(String name) {
-        return mDisabledSysPackages.containsKey(name);
-    }
-
-    void removeDisabledSystemPackageLPw(String name) {
-        mDisabledSysPackages.remove(name);
-    }
-
-    PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath,
-            String nativeLibraryPathString, int uid, int vc, int pkgFlags) {
-        PackageSetting p = mPackages.get(name);
-        if (p != null) {
-            if (p.appId == uid) {
-                return p;
-            }
-            PackageManagerService.reportSettingsProblem(Log.ERROR,
-                    "Adding duplicate package, keeping first: " + name);
-            return null;
-        }
-        p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString,
-                vc, pkgFlags);
-        p.appId = uid;
-        if (addUserIdLPw(uid, p, name)) {
-            mPackages.put(name, p);
-            return p;
-        }
-        return null;
-    }
-
-    SharedUserSetting addSharedUserLPw(String name, int uid, int pkgFlags) {
-        SharedUserSetting s = mSharedUsers.get(name);
-        if (s != null) {
-            if (s.userId == uid) {
-                return s;
-            }
-            PackageManagerService.reportSettingsProblem(Log.ERROR,
-                    "Adding duplicate shared user, keeping first: " + name);
-            return null;
-        }
-        s = new SharedUserSetting(name, pkgFlags);
-        s.userId = uid;
-        if (addUserIdLPw(uid, s, name)) {
-            mSharedUsers.put(name, s);
-            return s;
-        }
-        return null;
-    }
-
-    void pruneSharedUsersLPw() {
-        ArrayList<String> removeStage = new ArrayList<String>();
-        for (Map.Entry<String,SharedUserSetting> entry : mSharedUsers.entrySet()) {
-            final SharedUserSetting sus = entry.getValue();
-            if (sus == null || sus.packages.size() == 0) {
-                removeStage.add(entry.getKey());
-            }
-        }
-        for (int i = 0; i < removeStage.size(); i++) {
-            mSharedUsers.remove(removeStage.get(i));
-        }
-    }
-
-    // Transfer ownership of permissions from one package to another.
-    void transferPermissionsLPw(String origPkg, String newPkg) {
-        // Transfer ownership of permissions to the new package.
-        for (int i=0; i<2; i++) {
-            HashMap<String, BasePermission> permissions =
-                    i == 0 ? mPermissionTrees : mPermissions;
-            for (BasePermission bp : permissions.values()) {
-                if (origPkg.equals(bp.sourcePackage)) {
-                    if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG,
-                            "Moving permission " + bp.name
-                            + " from pkg " + bp.sourcePackage
-                            + " to " + newPkg);
-                    bp.sourcePackage = newPkg;
-                    bp.packageSetting = null;
-                    bp.perm = null;
-                    if (bp.pendingInfo != null) {
-                        bp.pendingInfo.packageName = newPkg;
-                    }
-                    bp.uid = 0;
-                    bp.gids = null;
-                }
-            }
-        }
-    }
-
-    private PackageSetting getPackageLPw(String name, PackageSetting origPackage,
-            String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
-            String nativeLibraryPathString, int vc, int pkgFlags,
-            UserHandle installUser, boolean add, boolean allowInstall) {
-        PackageSetting p = mPackages.get(name);
-        if (p != null) {
-            if (!p.codePath.equals(codePath)) {
-                // Check to see if its a disabled system app
-                if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                    // This is an updated system app with versions in both system
-                    // and data partition. Just let the most recent version
-                    // take precedence.
-                    Slog.w(PackageManagerService.TAG, "Trying to update system app code path from "
-                            + p.codePathString + " to " + codePath.toString());
-                } else {
-                    // Just a change in the code path is not an issue, but
-                    // let's log a message about it.
-                    Slog.i(PackageManagerService.TAG, "Package " + name + " codePath changed from "
-                            + p.codePath + " to " + codePath + "; Retaining data and using new");
-                    /*
-                     * Since we've changed paths, we need to prefer the new
-                     * native library path over the one stored in the
-                     * package settings since we might have moved from
-                     * internal to external storage or vice versa.
-                     */
-                    p.nativeLibraryPathString = nativeLibraryPathString;
-                }
-            }
-            if (p.sharedUser != sharedUser) {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Package " + name + " shared user changed from "
-                        + (p.sharedUser != null ? p.sharedUser.name : "<nothing>")
-                        + " to "
-                        + (sharedUser != null ? sharedUser.name : "<nothing>")
-                        + "; replacing with new");
-                p = null;
-            } else {
-                // If what we are scanning is a system (and possibly privileged) package,
-                // then make it so, regardless of whether it was previously installed only
-                // in the data partition.
-                final int sysPrivFlags = pkgFlags
-                        & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_PRIVILEGED);
-                p.pkgFlags |= sysPrivFlags;
-            }
-        }
-        if (p == null) {
-            if (origPackage != null) {
-                // We are consuming the data from an existing package.
-                p = new PackageSetting(origPackage.name, name, codePath, resourcePath,
-                        nativeLibraryPathString, vc, pkgFlags);
-                if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package "
-                        + name + " is adopting original package " + origPackage.name);
-                // Note that we will retain the new package's signature so
-                // that we can keep its data.
-                PackageSignatures s = p.signatures;
-                p.copyFrom(origPackage);
-                p.signatures = s;
-                p.sharedUser = origPackage.sharedUser;
-                p.appId = origPackage.appId;
-                p.origPackage = origPackage;
-                mRenamedPackages.put(name, origPackage.name);
-                name = origPackage.name;
-                // Update new package state.
-                p.setTimeStamp(codePath.lastModified());
-            } else {
-                p = new PackageSetting(name, realName, codePath, resourcePath,
-                        nativeLibraryPathString, vc, pkgFlags);
-                p.setTimeStamp(codePath.lastModified());
-                p.sharedUser = sharedUser;
-                // If this is not a system app, it starts out stopped.
-                if ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
-                    if (DEBUG_STOPPED) {
-                        RuntimeException e = new RuntimeException("here");
-                        e.fillInStackTrace();
-                        Slog.i(PackageManagerService.TAG, "Stopping package " + name, e);
-                    }
-                    List<UserInfo> users = getAllUsers();
-                    if (users != null && allowInstall) {
-                        for (UserInfo user : users) {
-                            // By default we consider this app to be installed
-                            // for the user if no user has been specified (which
-                            // means to leave it at its original value, and the
-                            // original default value is true), or we are being
-                            // asked to install for all users, or this is the
-                            // user we are installing for.
-                            final boolean installed = installUser == null
-                                    || installUser.getIdentifier() == UserHandle.USER_ALL
-                                    || installUser.getIdentifier() == user.id;
-                            p.setUserState(user.id, COMPONENT_ENABLED_STATE_DEFAULT,
-                                    installed,
-                                    true, // stopped,
-                                    true, // notLaunched
-                                    false, // blocked
-                                    null, null, null);
-                            writePackageRestrictionsLPr(user.id);
-                        }
-                    }
-                }
-                if (sharedUser != null) {
-                    p.appId = sharedUser.userId;
-                } else {
-                    // Clone the setting here for disabled system packages
-                    PackageSetting dis = mDisabledSysPackages.get(name);
-                    if (dis != null) {
-                        // For disabled packages a new setting is created
-                        // from the existing user id. This still has to be
-                        // added to list of user id's
-                        // Copy signatures from previous setting
-                        if (dis.signatures.mSignatures != null) {
-                            p.signatures.mSignatures = dis.signatures.mSignatures.clone();
-                        }
-                        p.appId = dis.appId;
-                        // Clone permissions
-                        p.grantedPermissions = new HashSet<String>(dis.grantedPermissions);
-                        // Clone component info
-                        List<UserInfo> users = getAllUsers();
-                        if (users != null) {
-                            for (UserInfo user : users) {
-                                int userId = user.id;
-                                p.setDisabledComponentsCopy(
-                                        dis.getDisabledComponents(userId), userId);
-                                p.setEnabledComponentsCopy(
-                                        dis.getEnabledComponents(userId), userId);
-                            }
-                        }
-                        // Add new setting to list of user ids
-                        addUserIdLPw(p.appId, p, name);
-                    } else {
-                        // Assign new user id
-                        p.appId = newUserIdLPw(p);
-                    }
-                }
-            }
-            if (p.appId < 0) {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Package " + name + " could not be assigned a valid uid");
-                return null;
-            }
-            if (add) {
-                // Finish adding new package by adding it and updating shared
-                // user preferences
-                addPackageSettingLPw(p, name, sharedUser);
-            }
-        } else {
-            if (installUser != null && allowInstall) {
-                // The caller has explicitly specified the user they want this
-                // package installed for, and the package already exists.
-                // Make sure it conforms to the new request.
-                List<UserInfo> users = getAllUsers();
-                if (users != null) {
-                    for (UserInfo user : users) {
-                        if (installUser.getIdentifier() == UserHandle.USER_ALL
-                                || installUser.getIdentifier() == user.id) {
-                            boolean installed = p.getInstalled(user.id);
-                            if (!installed) {
-                                p.setInstalled(true, user.id);
-                                writePackageRestrictionsLPr(user.id);
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        return p;
-    }
-
-    void insertPackageSettingLPw(PackageSetting p, PackageParser.Package pkg) {
-        p.pkg = pkg;
-        // pkg.mSetEnabled = p.getEnabled(userId);
-        // pkg.mSetStopped = p.getStopped(userId);
-        final String codePath = pkg.applicationInfo.sourceDir;
-        final String resourcePath = pkg.applicationInfo.publicSourceDir;
-        // Update code path if needed
-        if (!codePath.equalsIgnoreCase(p.codePathString)) {
-            Slog.w(PackageManagerService.TAG, "Code path for pkg : " + p.pkg.packageName +
-                    " changing from " + p.codePathString + " to " + codePath);
-            p.codePath = new File(codePath);
-            p.codePathString = codePath;
-        }
-        //Update resource path if needed
-        if (!resourcePath.equalsIgnoreCase(p.resourcePathString)) {
-            Slog.w(PackageManagerService.TAG, "Resource path for pkg : " + p.pkg.packageName +
-                    " changing from " + p.resourcePathString + " to " + resourcePath);
-            p.resourcePath = new File(resourcePath);
-            p.resourcePathString = resourcePath;
-        }
-        // Update the native library path if needed
-        final String nativeLibraryPath = pkg.applicationInfo.nativeLibraryDir;
-        if (nativeLibraryPath != null
-                && !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) {
-            p.nativeLibraryPathString = nativeLibraryPath;
-        }
-        // Update version code if needed
-        if (pkg.mVersionCode != p.versionCode) {
-            p.versionCode = pkg.mVersionCode;
-        }
-        // Update signatures if needed.
-        if (p.signatures.mSignatures == null) {
-            p.signatures.assignSignatures(pkg.mSignatures);
-        }
-        // Update flags if needed.
-        if (pkg.applicationInfo.flags != p.pkgFlags) {
-            p.pkgFlags = pkg.applicationInfo.flags;
-        }
-        // If this app defines a shared user id initialize
-        // the shared user signatures as well.
-        if (p.sharedUser != null && p.sharedUser.signatures.mSignatures == null) {
-            p.sharedUser.signatures.assignSignatures(pkg.mSignatures);
-        }
-        addPackageSettingLPw(p, pkg.packageName, p.sharedUser);
-    }
-
-    // Utility method that adds a PackageSetting to mPackages and
-    // completes updating the shared user attributes
-    private void addPackageSettingLPw(PackageSetting p, String name,
-            SharedUserSetting sharedUser) {
-        mPackages.put(name, p);
-        if (sharedUser != null) {
-            if (p.sharedUser != null && p.sharedUser != sharedUser) {
-                PackageManagerService.reportSettingsProblem(Log.ERROR,
-                        "Package " + p.name + " was user "
-                        + p.sharedUser + " but is now " + sharedUser
-                        + "; I am not changing its files so it will probably fail!");
-                p.sharedUser.removePackage(p);
-            } else if (p.appId != sharedUser.userId) {
-                PackageManagerService.reportSettingsProblem(Log.ERROR,
-                    "Package " + p.name + " was user id " + p.appId
-                    + " but is now user " + sharedUser
-                    + " with id " + sharedUser.userId
-                    + "; I am not changing its files so it will probably fail!");
-            }
-
-            sharedUser.addPackage(p);
-            p.sharedUser = sharedUser;
-            p.appId = sharedUser.userId;
-        }
-    }
-
-    /*
-     * Update the shared user setting when a package using
-     * specifying the shared user id is removed. The gids
-     * associated with each permission of the deleted package
-     * are removed from the shared user's gid list only if its
-     * not in use by other permissions of packages in the
-     * shared user setting.
-     */
-    void updateSharedUserPermsLPw(PackageSetting deletedPs, int[] globalGids) {
-        if ((deletedPs == null) || (deletedPs.pkg == null)) {
-            Slog.i(PackageManagerService.TAG,
-                    "Trying to update info for null package. Just ignoring");
-            return;
-        }
-        // No sharedUserId
-        if (deletedPs.sharedUser == null) {
-            return;
-        }
-        SharedUserSetting sus = deletedPs.sharedUser;
-        // Update permissions
-        for (String eachPerm : deletedPs.pkg.requestedPermissions) {
-            boolean used = false;
-            if (!sus.grantedPermissions.contains(eachPerm)) {
-                continue;
-            }
-            for (PackageSetting pkg:sus.packages) {
-                if (pkg.pkg != null &&
-                        !pkg.pkg.packageName.equals(deletedPs.pkg.packageName) &&
-                        pkg.pkg.requestedPermissions.contains(eachPerm)) {
-                    used = true;
-                    break;
-                }
-            }
-            if (!used) {
-                // can safely delete this permission from list
-                sus.grantedPermissions.remove(eachPerm);
-            }
-        }
-        // Update gids
-        int newGids[] = globalGids;
-        for (String eachPerm : sus.grantedPermissions) {
-            BasePermission bp = mPermissions.get(eachPerm);
-            if (bp != null) {
-                newGids = PackageManagerService.appendInts(newGids, bp.gids);
-            }
-        }
-        sus.gids = newGids;
-    }
-
-    int removePackageLPw(String name) {
-        final PackageSetting p = mPackages.get(name);
-        if (p != null) {
-            mPackages.remove(name);
-            if (p.sharedUser != null) {
-                p.sharedUser.removePackage(p);
-                if (p.sharedUser.packages.size() == 0) {
-                    mSharedUsers.remove(p.sharedUser.name);
-                    removeUserIdLPw(p.sharedUser.userId);
-                    return p.sharedUser.userId;
-                }
-            } else {
-                removeUserIdLPw(p.appId);
-                return p.appId;
-            }
-        }
-        return -1;
-    }
-
-    private void replacePackageLPw(String name, PackageSetting newp) {
-        final PackageSetting p = mPackages.get(name);
-        if (p != null) {
-            if (p.sharedUser != null) {
-                p.sharedUser.removePackage(p);
-                p.sharedUser.addPackage(newp);
-            } else {
-                replaceUserIdLPw(p.appId, newp);
-            }
-        }
-        mPackages.put(name, newp);
-    }
-
-    private boolean addUserIdLPw(int uid, Object obj, Object name) {
-        if (uid > Process.LAST_APPLICATION_UID) {
-            return false;
-        }
-
-        if (uid >= Process.FIRST_APPLICATION_UID) {
-            int N = mUserIds.size();
-            final int index = uid - Process.FIRST_APPLICATION_UID;
-            while (index >= N) {
-                mUserIds.add(null);
-                N++;
-            }
-            if (mUserIds.get(index) != null) {
-                PackageManagerService.reportSettingsProblem(Log.ERROR,
-                        "Adding duplicate user id: " + uid
-                        + " name=" + name);
-                return false;
-            }
-            mUserIds.set(index, obj);
-        } else {
-            if (mOtherUserIds.get(uid) != null) {
-                PackageManagerService.reportSettingsProblem(Log.ERROR,
-                        "Adding duplicate shared id: " + uid
-                        + " name=" + name);
-                return false;
-            }
-            mOtherUserIds.put(uid, obj);
-        }
-        return true;
-    }
-
-    public Object getUserIdLPr(int uid) {
-        if (uid >= Process.FIRST_APPLICATION_UID) {
-            final int N = mUserIds.size();
-            final int index = uid - Process.FIRST_APPLICATION_UID;
-            return index < N ? mUserIds.get(index) : null;
-        } else {
-            return mOtherUserIds.get(uid);
-        }
-    }
-
-    private void removeUserIdLPw(int uid) {
-        if (uid >= Process.FIRST_APPLICATION_UID) {
-            final int N = mUserIds.size();
-            final int index = uid - Process.FIRST_APPLICATION_UID;
-            if (index < N) mUserIds.set(index, null);
-        } else {
-            mOtherUserIds.remove(uid);
-        }
-        setFirstAvailableUid(uid+1);
-    }
-
-    private void replaceUserIdLPw(int uid, Object obj) {
-        if (uid >= Process.FIRST_APPLICATION_UID) {
-            final int N = mUserIds.size();
-            final int index = uid - Process.FIRST_APPLICATION_UID;
-            if (index < N) mUserIds.set(index, obj);
-        } else {
-            mOtherUserIds.put(uid, obj);
-        }
-    }
-
-    PreferredIntentResolver editPreferredActivitiesLPw(int userId) {
-        PreferredIntentResolver pir = mPreferredActivities.get(userId);
-        if (pir == null) {
-            pir = new PreferredIntentResolver();
-            mPreferredActivities.put(userId, pir);
-        }
-        return pir;
-    }
-
-    private File getUserPackagesStateFile(int userId) {
-        return new File(Environment.getUserSystemDirectory(userId), "package-restrictions.xml");
-    }
-
-    private File getUserPackagesStateBackupFile(int userId) {
-        return new File(Environment.getUserSystemDirectory(userId),
-                "package-restrictions-backup.xml");
-    }
-
-    void writeAllUsersPackageRestrictionsLPr() {
-        List<UserInfo> users = getAllUsers();
-        if (users == null) return;
-
-        for (UserInfo user : users) {
-            writePackageRestrictionsLPr(user.id);
-        }
-    }
-
-    void readAllUsersPackageRestrictionsLPr() {
-        List<UserInfo> users = getAllUsers();
-        if (users == null) {
-            readPackageRestrictionsLPr(0);
-            return;
-        }
-
-        for (UserInfo user : users) {
-            readPackageRestrictionsLPr(user.id);
-        }
-    }
-
-    private void readPreferredActivitiesLPw(XmlPullParser parser, int userId)
-            throws XmlPullParserException, IOException {
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                PreferredActivity pa = new PreferredActivity(parser);
-                if (pa.mPref.getParseError() == null) {
-                    editPreferredActivitiesLPw(userId).addFilter(pa);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: <preferred-activity> "
-                                    + pa.mPref.getParseError() + " at "
-                                    + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element under <preferred-activities>: " + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-    }
-
-    void readPackageRestrictionsLPr(int userId) {
-        if (DEBUG_MU) {
-            Log.i(TAG, "Reading package restrictions for user=" + userId);
-        }
-        FileInputStream str = null;
-        File userPackagesStateFile = getUserPackagesStateFile(userId);
-        File backupFile = getUserPackagesStateBackupFile(userId);
-        if (backupFile.exists()) {
-            try {
-                str = new FileInputStream(backupFile);
-                mReadMessages.append("Reading from backup stopped packages file\n");
-                PackageManagerService.reportSettingsProblem(Log.INFO,
-                        "Need to read from backup stopped packages file");
-                if (userPackagesStateFile.exists()) {
-                    // If both the backup and normal file exist, we
-                    // ignore the normal one since it might have been
-                    // corrupted.
-                    Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
-                            + userPackagesStateFile);
-                    userPackagesStateFile.delete();
-                }
-            } catch (java.io.IOException e) {
-                // We'll try for the normal settings file.
-            }
-        }
-
-        try {
-            if (str == null) {
-                if (!userPackagesStateFile.exists()) {
-                    mReadMessages.append("No stopped packages file found\n");
-                    PackageManagerService.reportSettingsProblem(Log.INFO,
-                            "No stopped packages file; "
-                            + "assuming all started");
-                    // At first boot, make sure no packages are stopped.
-                    // We usually want to have third party apps initialize
-                    // in the stopped state, but not at first boot.  Also
-                    // consider all applications to be installed.
-                    for (PackageSetting pkg : mPackages.values()) {
-                        pkg.setUserState(userId, COMPONENT_ENABLED_STATE_DEFAULT,
-                                true,   // installed
-                                false,  // stopped
-                                false,  // notLaunched
-                                false,  // blocked
-                                null, null, null);
-                    }
-                    return;
-                }
-                str = new FileInputStream(userPackagesStateFile);
-            }
-            final XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(str, null);
-
-            int type;
-            while ((type=parser.next()) != XmlPullParser.START_TAG
-                       && type != XmlPullParser.END_DOCUMENT) {
-                ;
-            }
-
-            if (type != XmlPullParser.START_TAG) {
-                mReadMessages.append("No start tag found in package restrictions file\n");
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "No start tag found in package manager stopped packages");
-                return;
-            }
-
-            int outerDepth = parser.getDepth();
-            PackageSetting ps = null;
-            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                   && (type != XmlPullParser.END_TAG
-                           || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG
-                        || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-
-                String tagName = parser.getName();
-                if (tagName.equals(TAG_PACKAGE)) {
-                    String name = parser.getAttributeValue(null, ATTR_NAME);
-                    ps = mPackages.get(name);
-                    if (ps == null) {
-                        Slog.w(PackageManagerService.TAG, "No package known for stopped package: "
-                                + name);
-                        XmlUtils.skipCurrentTag(parser);
-                        continue;
-                    }
-                    final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
-                    final int enabled = enabledStr == null
-                            ? COMPONENT_ENABLED_STATE_DEFAULT : Integer.parseInt(enabledStr);
-                    final String enabledCaller = parser.getAttributeValue(null,
-                            ATTR_ENABLED_CALLER);
-                    final String installedStr = parser.getAttributeValue(null, ATTR_INSTALLED);
-                    final boolean installed = installedStr == null
-                            ? true : Boolean.parseBoolean(installedStr);
-                    final String stoppedStr = parser.getAttributeValue(null, ATTR_STOPPED);
-                    final boolean stopped = stoppedStr == null
-                            ? false : Boolean.parseBoolean(stoppedStr);
-                    final String blockedStr = parser.getAttributeValue(null, ATTR_BLOCKED);
-                    final boolean blocked = blockedStr == null
-                            ? false : Boolean.parseBoolean(blockedStr);
-                    final String notLaunchedStr = parser.getAttributeValue(null, ATTR_NOT_LAUNCHED);
-                    final boolean notLaunched = stoppedStr == null
-                            ? false : Boolean.parseBoolean(notLaunchedStr);
-
-                    HashSet<String> enabledComponents = null;
-                    HashSet<String> disabledComponents = null;
-
-                    int packageDepth = parser.getDepth();
-                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                            && (type != XmlPullParser.END_TAG
-                            || parser.getDepth() > packageDepth)) {
-                        if (type == XmlPullParser.END_TAG
-                                || type == XmlPullParser.TEXT) {
-                            continue;
-                        }
-                        tagName = parser.getName();
-                        if (tagName.equals(TAG_ENABLED_COMPONENTS)) {
-                            enabledComponents = readComponentsLPr(parser);
-                        } else if (tagName.equals(TAG_DISABLED_COMPONENTS)) {
-                            disabledComponents = readComponentsLPr(parser);
-                        }
-                    }
-
-                    ps.setUserState(userId, enabled, installed, stopped, notLaunched, blocked,
-                            enabledCaller, enabledComponents, disabledComponents);
-                } else if (tagName.equals("preferred-activities")) {
-                    readPreferredActivitiesLPw(parser, userId);
-                } else {
-                    Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
-                          + parser.getName());
-                    XmlUtils.skipCurrentTag(parser);
-                }
-            }
-
-            str.close();
-
-        } catch (XmlPullParserException e) {
-            mReadMessages.append("Error reading: " + e.toString());
-            PackageManagerService.reportSettingsProblem(Log.ERROR,
-                    "Error reading stopped packages: " + e);
-            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
-
-        } catch (java.io.IOException e) {
-            mReadMessages.append("Error reading: " + e.toString());
-            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
-            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
-        }
-    }
-
-    private HashSet<String> readComponentsLPr(XmlPullParser parser)
-            throws IOException, XmlPullParserException {
-        HashSet<String> components = null;
-        int type;
-        int outerDepth = parser.getDepth();
-        String tagName;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG
-                || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG
-                    || type == XmlPullParser.TEXT) {
-                continue;
-            }
-            tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                String componentName = parser.getAttributeValue(null, ATTR_NAME);
-                if (componentName != null) {
-                    if (components == null) {
-                        components = new HashSet<String>();
-                    }
-                    components.add(componentName);
-                }
-            }
-        }
-        return components;
-    }
-
-    void writePreferredActivitiesLPr(XmlSerializer serializer, int userId, boolean full)
-            throws IllegalArgumentException, IllegalStateException, IOException {
-        serializer.startTag(null, "preferred-activities");
-        PreferredIntentResolver pir = mPreferredActivities.get(userId);
-        if (pir != null) {
-            for (final PreferredActivity pa : pir.filterSet()) {
-                serializer.startTag(null, TAG_ITEM);
-                pa.writeToXml(serializer, full);
-                serializer.endTag(null, TAG_ITEM);
-            }
-        }
-        serializer.endTag(null, "preferred-activities");
-    }
-
-    void writePackageRestrictionsLPr(int userId) {
-        if (DEBUG_MU) {
-            Log.i(TAG, "Writing package restrictions for user=" + userId);
-        }
-        // Keep the old stopped packages around until we know the new ones have
-        // been successfully written.
-        File userPackagesStateFile = getUserPackagesStateFile(userId);
-        File backupFile = getUserPackagesStateBackupFile(userId);
-        new File(userPackagesStateFile.getParent()).mkdirs();
-        if (userPackagesStateFile.exists()) {
-            // Presence of backup settings file indicates that we failed
-            // to persist packages earlier. So preserve the older
-            // backup for future reference since the current packages
-            // might have been corrupted.
-            if (!backupFile.exists()) {
-                if (!userPackagesStateFile.renameTo(backupFile)) {
-                    Log.wtf(PackageManagerService.TAG, "Unable to backup user packages state file, "
-                            + "current changes will be lost at reboot");
-                    return;
-                }
-            } else {
-                userPackagesStateFile.delete();
-                Slog.w(PackageManagerService.TAG, "Preserving older stopped packages backup");
-            }
-        }
-
-        try {
-            final FileOutputStream fstr = new FileOutputStream(userPackagesStateFile);
-            final BufferedOutputStream str = new BufferedOutputStream(fstr);
-
-            final XmlSerializer serializer = new FastXmlSerializer();
-            serializer.setOutput(str, "utf-8");
-            serializer.startDocument(null, true);
-            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-
-            serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS);
-
-            for (final PackageSetting pkg : mPackages.values()) {
-                PackageUserState ustate = pkg.readUserState(userId);
-                if (ustate.stopped || ustate.notLaunched || !ustate.installed
-                        || ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT
-                        || ustate.blocked
-                        || (ustate.enabledComponents != null
-                                && ustate.enabledComponents.size() > 0)
-                        || (ustate.disabledComponents != null
-                                && ustate.disabledComponents.size() > 0)) {
-                    serializer.startTag(null, TAG_PACKAGE);
-                    serializer.attribute(null, ATTR_NAME, pkg.name);
-                    if (DEBUG_MU) Log.i(TAG, "  pkg=" + pkg.name + ", state=" + ustate.enabled);
-
-                    if (!ustate.installed) {
-                        serializer.attribute(null, ATTR_INSTALLED, "false");
-                    }
-                    if (ustate.stopped) {
-                        serializer.attribute(null, ATTR_STOPPED, "true");
-                    }
-                    if (ustate.notLaunched) {
-                        serializer.attribute(null, ATTR_NOT_LAUNCHED, "true");
-                    }
-                    if (ustate.blocked) {
-                        serializer.attribute(null, ATTR_BLOCKED, "true");
-                    }
-                    if (ustate.enabled != COMPONENT_ENABLED_STATE_DEFAULT) {
-                        serializer.attribute(null, ATTR_ENABLED,
-                                Integer.toString(ustate.enabled));
-                        if (ustate.lastDisableAppCaller != null) {
-                            serializer.attribute(null, ATTR_ENABLED_CALLER,
-                                    ustate.lastDisableAppCaller);
-                        }
-                    }
-                    if (ustate.enabledComponents != null
-                            && ustate.enabledComponents.size() > 0) {
-                        serializer.startTag(null, TAG_ENABLED_COMPONENTS);
-                        for (final String name : ustate.enabledComponents) {
-                            serializer.startTag(null, TAG_ITEM);
-                            serializer.attribute(null, ATTR_NAME, name);
-                            serializer.endTag(null, TAG_ITEM);
-                        }
-                        serializer.endTag(null, TAG_ENABLED_COMPONENTS);
-                    }
-                    if (ustate.disabledComponents != null
-                            && ustate.disabledComponents.size() > 0) {
-                        serializer.startTag(null, TAG_DISABLED_COMPONENTS);
-                        for (final String name : ustate.disabledComponents) {
-                            serializer.startTag(null, TAG_ITEM);
-                            serializer.attribute(null, ATTR_NAME, name);
-                            serializer.endTag(null, TAG_ITEM);
-                        }
-                        serializer.endTag(null, TAG_DISABLED_COMPONENTS);
-                    }
-                    serializer.endTag(null, TAG_PACKAGE);
-                }
-            }
-
-            writePreferredActivitiesLPr(serializer, userId, true);
-
-            serializer.endTag(null, TAG_PACKAGE_RESTRICTIONS);
-
-            serializer.endDocument();
-
-            str.flush();
-            FileUtils.sync(fstr);
-            str.close();
-
-            // New settings successfully written, old ones are no longer
-            // needed.
-            backupFile.delete();
-            FileUtils.setPermissions(userPackagesStateFile.toString(),
-                    FileUtils.S_IRUSR|FileUtils.S_IWUSR
-                    |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
-                    -1, -1);
-
-            // Done, all is good!
-            return;
-        } catch(java.io.IOException e) {
-            Log.wtf(PackageManagerService.TAG,
-                    "Unable to write package manager user packages state, "
-                    + " current changes will be lost at reboot", e);
-        }
-
-        // Clean up partially written files
-        if (userPackagesStateFile.exists()) {
-            if (!userPackagesStateFile.delete()) {
-                Log.i(PackageManagerService.TAG, "Failed to clean up mangled file: "
-                        + mStoppedPackagesFilename);
-            }
-        }
-    }
-
-    // Note: assumed "stopped" field is already cleared in all packages.
-    // Legacy reader, used to read in the old file format after an upgrade. Not used after that.
-    void readStoppedLPw() {
-        FileInputStream str = null;
-        if (mBackupStoppedPackagesFilename.exists()) {
-            try {
-                str = new FileInputStream(mBackupStoppedPackagesFilename);
-                mReadMessages.append("Reading from backup stopped packages file\n");
-                PackageManagerService.reportSettingsProblem(Log.INFO,
-                        "Need to read from backup stopped packages file");
-                if (mSettingsFilename.exists()) {
-                    // If both the backup and normal file exist, we
-                    // ignore the normal one since it might have been
-                    // corrupted.
-                    Slog.w(PackageManagerService.TAG, "Cleaning up stopped packages file "
-                            + mStoppedPackagesFilename);
-                    mStoppedPackagesFilename.delete();
-                }
-            } catch (java.io.IOException e) {
-                // We'll try for the normal settings file.
-            }
-        }
-
-        try {
-            if (str == null) {
-                if (!mStoppedPackagesFilename.exists()) {
-                    mReadMessages.append("No stopped packages file found\n");
-                    PackageManagerService.reportSettingsProblem(Log.INFO,
-                            "No stopped packages file file; assuming all started");
-                    // At first boot, make sure no packages are stopped.
-                    // We usually want to have third party apps initialize
-                    // in the stopped state, but not at first boot.
-                    for (PackageSetting pkg : mPackages.values()) {
-                        pkg.setStopped(false, 0);
-                        pkg.setNotLaunched(false, 0);
-                    }
-                    return;
-                }
-                str = new FileInputStream(mStoppedPackagesFilename);
-            }
-            final XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(str, null);
-
-            int type;
-            while ((type=parser.next()) != XmlPullParser.START_TAG
-                       && type != XmlPullParser.END_DOCUMENT) {
-                ;
-            }
-
-            if (type != XmlPullParser.START_TAG) {
-                mReadMessages.append("No start tag found in stopped packages file\n");
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "No start tag found in package manager stopped packages");
-                return;
-            }
-
-            int outerDepth = parser.getDepth();
-            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                   && (type != XmlPullParser.END_TAG
-                           || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG
-                        || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-
-                String tagName = parser.getName();
-                if (tagName.equals(TAG_PACKAGE)) {
-                    String name = parser.getAttributeValue(null, ATTR_NAME);
-                    PackageSetting ps = mPackages.get(name);
-                    if (ps != null) {
-                        ps.setStopped(true, 0);
-                        if ("1".equals(parser.getAttributeValue(null, ATTR_NOT_LAUNCHED))) {
-                            ps.setNotLaunched(true, 0);
-                        }
-                    } else {
-                        Slog.w(PackageManagerService.TAG,
-                                "No package known for stopped package: " + name);
-                    }
-                    XmlUtils.skipCurrentTag(parser);
-                } else {
-                    Slog.w(PackageManagerService.TAG, "Unknown element under <stopped-packages>: "
-                          + parser.getName());
-                    XmlUtils.skipCurrentTag(parser);
-                }
-            }
-
-            str.close();
-
-        } catch (XmlPullParserException e) {
-            mReadMessages.append("Error reading: " + e.toString());
-            PackageManagerService.reportSettingsProblem(Log.ERROR,
-                    "Error reading stopped packages: " + e);
-            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
-
-        } catch (java.io.IOException e) {
-            mReadMessages.append("Error reading: " + e.toString());
-            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
-            Log.wtf(PackageManagerService.TAG, "Error reading package manager stopped packages", e);
-
-        }
-    }
-
-    void writeLPr() {
-        //Debug.startMethodTracing("/data/system/packageprof", 8 * 1024 * 1024);
-
-        // Keep the old settings around until we know the new ones have
-        // been successfully written.
-        if (mSettingsFilename.exists()) {
-            // Presence of backup settings file indicates that we failed
-            // to persist settings earlier. So preserve the older
-            // backup for future reference since the current settings
-            // might have been corrupted.
-            if (!mBackupSettingsFilename.exists()) {
-                if (!mSettingsFilename.renameTo(mBackupSettingsFilename)) {
-                    Log.wtf(PackageManagerService.TAG, "Unable to backup package manager settings, "
-                            + " current changes will be lost at reboot");
-                    return;
-                }
-            } else {
-                mSettingsFilename.delete();
-                Slog.w(PackageManagerService.TAG, "Preserving older settings backup");
-            }
-        }
-
-        mPastSignatures.clear();
-
-        try {
-            FileOutputStream fstr = new FileOutputStream(mSettingsFilename);
-            BufferedOutputStream str = new BufferedOutputStream(fstr);
-
-            //XmlSerializer serializer = XmlUtils.serializerInstance();
-            XmlSerializer serializer = new FastXmlSerializer();
-            serializer.setOutput(str, "utf-8");
-            serializer.startDocument(null, true);
-            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-
-            serializer.startTag(null, "packages");
-
-            serializer.startTag(null, "last-platform-version");
-            serializer.attribute(null, "internal", Integer.toString(mInternalSdkPlatform));
-            serializer.attribute(null, "external", Integer.toString(mExternalSdkPlatform));
-            serializer.endTag(null, "last-platform-version");
-
-            if (mVerifierDeviceIdentity != null) {
-                serializer.startTag(null, "verifier");
-                serializer.attribute(null, "device", mVerifierDeviceIdentity.toString());
-                serializer.endTag(null, "verifier");
-            }
-
-            if (mReadExternalStorageEnforced != null) {
-                serializer.startTag(null, TAG_READ_EXTERNAL_STORAGE);
-                serializer.attribute(
-                        null, ATTR_ENFORCEMENT, mReadExternalStorageEnforced ? "1" : "0");
-                serializer.endTag(null, TAG_READ_EXTERNAL_STORAGE);
-            }
-
-            serializer.startTag(null, "permission-trees");
-            for (BasePermission bp : mPermissionTrees.values()) {
-                writePermissionLPr(serializer, bp);
-            }
-            serializer.endTag(null, "permission-trees");
-
-            serializer.startTag(null, "permissions");
-            for (BasePermission bp : mPermissions.values()) {
-                writePermissionLPr(serializer, bp);
-            }
-            serializer.endTag(null, "permissions");
-
-            for (final PackageSetting pkg : mPackages.values()) {
-                writePackageLPr(serializer, pkg);
-            }
-
-            for (final PackageSetting pkg : mDisabledSysPackages.values()) {
-                writeDisabledSysPackageLPr(serializer, pkg);
-            }
-
-            for (final SharedUserSetting usr : mSharedUsers.values()) {
-                serializer.startTag(null, "shared-user");
-                serializer.attribute(null, ATTR_NAME, usr.name);
-                serializer.attribute(null, "userId",
-                        Integer.toString(usr.userId));
-                usr.signatures.writeXml(serializer, "sigs", mPastSignatures);
-                serializer.startTag(null, "perms");
-                for (String name : usr.grantedPermissions) {
-                    serializer.startTag(null, TAG_ITEM);
-                    serializer.attribute(null, ATTR_NAME, name);
-                    serializer.endTag(null, TAG_ITEM);
-                }
-                serializer.endTag(null, "perms");
-                serializer.endTag(null, "shared-user");
-            }
-
-            if (mPackagesToBeCleaned.size() > 0) {
-                for (PackageCleanItem item : mPackagesToBeCleaned) {
-                    final String userStr = Integer.toString(item.userId);
-                    serializer.startTag(null, "cleaning-package");
-                    serializer.attribute(null, ATTR_NAME, item.packageName);
-                    serializer.attribute(null, ATTR_CODE, item.andCode ? "true" : "false");
-                    serializer.attribute(null, ATTR_USER, userStr);
-                    serializer.endTag(null, "cleaning-package");
-                }
-            }
-            
-            if (mRenamedPackages.size() > 0) {
-                for (Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
-                    serializer.startTag(null, "renamed-package");
-                    serializer.attribute(null, "new", e.getKey());
-                    serializer.attribute(null, "old", e.getValue());
-                    serializer.endTag(null, "renamed-package");
-                }
-            }
-            
-            mKeySetManager.writeKeySetManagerLPr(serializer);
-
-            serializer.endTag(null, "packages");
-
-            serializer.endDocument();
-
-            str.flush();
-            FileUtils.sync(fstr);
-            str.close();
-
-            // New settings successfully written, old ones are no longer
-            // needed.
-            mBackupSettingsFilename.delete();
-            FileUtils.setPermissions(mSettingsFilename.toString(),
-                    FileUtils.S_IRUSR|FileUtils.S_IWUSR
-                    |FileUtils.S_IRGRP|FileUtils.S_IWGRP,
-                    -1, -1);
-
-            // Write package list file now, use a JournaledFile.
-            File tempFile = new File(mPackageListFilename.getAbsolutePath() + ".tmp");
-            JournaledFile journal = new JournaledFile(mPackageListFilename, tempFile);
-
-            final File writeTarget = journal.chooseForWrite();
-            fstr = new FileOutputStream(writeTarget);
-            str = new BufferedOutputStream(fstr);
-            try {
-                FileUtils.setPermissions(fstr.getFD(), 0660, SYSTEM_UID, PACKAGE_INFO_GID);
-
-                StringBuilder sb = new StringBuilder();
-                for (final PackageSetting pkg : mPackages.values()) {
-                    if (pkg.pkg == null || pkg.pkg.applicationInfo == null) {
-                        Slog.w(TAG, "Skipping " + pkg + " due to missing metadata");
-                        continue;
-                    }
-
-                    final ApplicationInfo ai = pkg.pkg.applicationInfo;
-                    final String dataPath = ai.dataDir;
-                    final boolean isDebug = (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
-                    final int[] gids = pkg.getGids();
-
-                    // Avoid any application that has a space in its path.
-                    if (dataPath.indexOf(" ") >= 0)
-                        continue;
-
-                    // we store on each line the following information for now:
-                    //
-                    // pkgName    - package name
-                    // userId     - application-specific user id
-                    // debugFlag  - 0 or 1 if the package is debuggable.
-                    // dataPath   - path to package's data path
-                    // seinfo     - seinfo label for the app (assigned at install time)
-                    // gids       - supplementary gids this app launches with
-                    //
-                    // NOTE: We prefer not to expose all ApplicationInfo flags for now.
-                    //
-                    // DO NOT MODIFY THIS FORMAT UNLESS YOU CAN ALSO MODIFY ITS USERS
-                    // FROM NATIVE CODE. AT THE MOMENT, LOOK AT THE FOLLOWING SOURCES:
-                    //   system/core/run-as/run-as.c
-                    //   system/core/sdcard/sdcard.c
-                    //
-                    sb.setLength(0);
-                    sb.append(ai.packageName);
-                    sb.append(" ");
-                    sb.append((int)ai.uid);
-                    sb.append(isDebug ? " 1 " : " 0 ");
-                    sb.append(dataPath);
-                    sb.append(" ");
-                    sb.append(ai.seinfo);
-                    sb.append(" ");
-                    if (gids != null && gids.length > 0) {
-                        sb.append(gids[0]);
-                        for (int i = 1; i < gids.length; i++) {
-                            sb.append(",");
-                            sb.append(gids[i]);
-                        }
-                    } else {
-                        sb.append("none");
-                    }
-                    sb.append("\n");
-                    str.write(sb.toString().getBytes());
-                }
-                str.flush();
-                FileUtils.sync(fstr);
-                str.close();
-                journal.commit();
-            } catch (Exception e) {
-                Log.wtf(TAG, "Failed to write packages.list", e);
-                IoUtils.closeQuietly(str);
-                journal.rollback();
-            }
-
-            writeAllUsersPackageRestrictionsLPr();
-            return;
-
-        } catch(XmlPullParserException e) {
-            Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
-                    + "current changes will be lost at reboot", e);
-        } catch(java.io.IOException e) {
-            Log.wtf(PackageManagerService.TAG, "Unable to write package manager settings, "
-                    + "current changes will be lost at reboot", e);
-        }
-        // Clean up partially written files
-        if (mSettingsFilename.exists()) {
-            if (!mSettingsFilename.delete()) {
-                Log.wtf(PackageManagerService.TAG, "Failed to clean up mangled file: "
-                        + mSettingsFilename);
-            }
-        }
-        //Debug.stopMethodTracing();
-    }
-
-    void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg)
-            throws java.io.IOException {
-        serializer.startTag(null, "updated-package");
-        serializer.attribute(null, ATTR_NAME, pkg.name);
-        if (pkg.realName != null) {
-            serializer.attribute(null, "realName", pkg.realName);
-        }
-        serializer.attribute(null, "codePath", pkg.codePathString);
-        serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
-        serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
-        serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
-        serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
-        if (!pkg.resourcePathString.equals(pkg.codePathString)) {
-            serializer.attribute(null, "resourcePath", pkg.resourcePathString);
-        }
-        if (pkg.nativeLibraryPathString != null) {
-            serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
-        }
-        if (pkg.sharedUser == null) {
-            serializer.attribute(null, "userId", Integer.toString(pkg.appId));
-        } else {
-            serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId));
-        }
-        serializer.startTag(null, "perms");
-        if (pkg.sharedUser == null) {
-            // If this is a shared user, the permissions will
-            // be written there. We still need to write an
-            // empty permissions list so permissionsFixed will
-            // be set.
-            for (final String name : pkg.grantedPermissions) {
-                BasePermission bp = mPermissions.get(name);
-                if (bp != null) {
-                    // We only need to write signature or system permissions but
-                    // this wont
-                    // match the semantics of grantedPermissions. So write all
-                    // permissions.
-                    serializer.startTag(null, TAG_ITEM);
-                    serializer.attribute(null, ATTR_NAME, name);
-                    serializer.endTag(null, TAG_ITEM);
-                }
-            }
-        }
-        serializer.endTag(null, "perms");
-        serializer.endTag(null, "updated-package");
-    }
-
-    void writePackageLPr(XmlSerializer serializer, final PackageSetting pkg)
-            throws java.io.IOException {
-        serializer.startTag(null, "package");
-        serializer.attribute(null, ATTR_NAME, pkg.name);
-        if (pkg.realName != null) {
-            serializer.attribute(null, "realName", pkg.realName);
-        }
-        serializer.attribute(null, "codePath", pkg.codePathString);
-        if (!pkg.resourcePathString.equals(pkg.codePathString)) {
-            serializer.attribute(null, "resourcePath", pkg.resourcePathString);
-        }
-        if (pkg.nativeLibraryPathString != null) {
-            serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
-        }
-        serializer.attribute(null, "flags", Integer.toString(pkg.pkgFlags));
-        serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
-        serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
-        serializer.attribute(null, "ut", Long.toHexString(pkg.lastUpdateTime));
-        serializer.attribute(null, "version", String.valueOf(pkg.versionCode));
-        if (pkg.sharedUser == null) {
-            serializer.attribute(null, "userId", Integer.toString(pkg.appId));
-        } else {
-            serializer.attribute(null, "sharedUserId", Integer.toString(pkg.appId));
-        }
-        if (pkg.uidError) {
-            serializer.attribute(null, "uidError", "true");
-        }
-        if (pkg.installStatus == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
-            serializer.attribute(null, "installStatus", "false");
-        }
-        if (pkg.installerPackageName != null) {
-            serializer.attribute(null, "installer", pkg.installerPackageName);
-        }
-        pkg.signatures.writeXml(serializer, "sigs", mPastSignatures);
-        if ((pkg.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
-            serializer.startTag(null, "perms");
-            if (pkg.sharedUser == null) {
-                // If this is a shared user, the permissions will
-                // be written there. We still need to write an
-                // empty permissions list so permissionsFixed will
-                // be set.
-                for (final String name : pkg.grantedPermissions) {
-                    serializer.startTag(null, TAG_ITEM);
-                    serializer.attribute(null, ATTR_NAME, name);
-                    serializer.endTag(null, TAG_ITEM);
-                }
-            }
-            serializer.endTag(null, "perms");
-        }
-
-        writeSigningKeySetsLPr(serializer, pkg.keySetData);
-        writeKeySetAliasesLPr(serializer, pkg.keySetData);
-
-        serializer.endTag(null, "package");
-    }
-
-    void writeSigningKeySetsLPr(XmlSerializer serializer,
-            PackageKeySetData data) throws IOException {
-        for (long id : data.getSigningKeySets()) {
-            serializer.startTag(null, "signing-keyset");
-            serializer.attribute(null, "identifier", Long.toString(id));
-            serializer.endTag(null, "signing-keyset");
-        }
-    }
-
-    void writeKeySetAliasesLPr(XmlSerializer serializer,
-            PackageKeySetData data) throws IOException {
-        for (Map.Entry<String, Long> e: data.getAliases().entrySet()) {
-            serializer.startTag(null, "defined-keyset");
-            serializer.attribute(null, "alias", e.getKey());
-            serializer.attribute(null, "identifier", Long.toString(e.getValue()));
-            serializer.endTag(null, "defined-keyset");
-        }
-    }
-
-    void writePermissionLPr(XmlSerializer serializer, BasePermission bp)
-            throws XmlPullParserException, java.io.IOException {
-        if (bp.type != BasePermission.TYPE_BUILTIN && bp.sourcePackage != null) {
-            serializer.startTag(null, TAG_ITEM);
-            serializer.attribute(null, ATTR_NAME, bp.name);
-            serializer.attribute(null, "package", bp.sourcePackage);
-            if (bp.protectionLevel != PermissionInfo.PROTECTION_NORMAL) {
-                serializer.attribute(null, "protection", Integer.toString(bp.protectionLevel));
-            }
-            if (PackageManagerService.DEBUG_SETTINGS)
-                Log.v(PackageManagerService.TAG, "Writing perm: name=" + bp.name + " type="
-                        + bp.type);
-            if (bp.type == BasePermission.TYPE_DYNAMIC) {
-                final PermissionInfo pi = bp.perm != null ? bp.perm.info : bp.pendingInfo;
-                if (pi != null) {
-                    serializer.attribute(null, "type", "dynamic");
-                    if (pi.icon != 0) {
-                        serializer.attribute(null, "icon", Integer.toString(pi.icon));
-                    }
-                    if (pi.nonLocalizedLabel != null) {
-                        serializer.attribute(null, "label", pi.nonLocalizedLabel.toString());
-                    }
-                }
-            }
-            serializer.endTag(null, TAG_ITEM);
-        }
-    }
-
-    ArrayList<PackageSetting> getListOfIncompleteInstallPackagesLPr() {
-        final HashSet<String> kList = new HashSet<String>(mPackages.keySet());
-        final Iterator<String> its = kList.iterator();
-        final ArrayList<PackageSetting> ret = new ArrayList<PackageSetting>();
-        while (its.hasNext()) {
-            final String key = its.next();
-            final PackageSetting ps = mPackages.get(key);
-            if (ps.getInstallStatus() == PackageSettingBase.PKG_INSTALL_INCOMPLETE) {
-                ret.add(ps);
-            }
-        }
-        return ret;
-    }
-
-    void addPackageToCleanLPw(PackageCleanItem pkg) {
-        if (!mPackagesToBeCleaned.contains(pkg)) {
-            mPackagesToBeCleaned.add(pkg);
-        }
-    }
-
-    boolean readLPw(PackageManagerService service, List<UserInfo> users, int sdkVersion,
-            boolean onlyCore) {
-        FileInputStream str = null;
-        if (mBackupSettingsFilename.exists()) {
-            try {
-                str = new FileInputStream(mBackupSettingsFilename);
-                mReadMessages.append("Reading from backup settings file\n");
-                PackageManagerService.reportSettingsProblem(Log.INFO,
-                        "Need to read from backup settings file");
-                if (mSettingsFilename.exists()) {
-                    // If both the backup and settings file exist, we
-                    // ignore the settings since it might have been
-                    // corrupted.
-                    Slog.w(PackageManagerService.TAG, "Cleaning up settings file "
-                            + mSettingsFilename);
-                    mSettingsFilename.delete();
-                }
-            } catch (java.io.IOException e) {
-                // We'll try for the normal settings file.
-            }
-        }
-
-        mPendingPackages.clear();
-        mPastSignatures.clear();
-
-        try {
-            if (str == null) {
-                if (!mSettingsFilename.exists()) {
-                    mReadMessages.append("No settings file found\n");
-                    PackageManagerService.reportSettingsProblem(Log.INFO,
-                            "No settings file; creating initial state");
-                    mInternalSdkPlatform = mExternalSdkPlatform = sdkVersion;
-                    return false;
-                }
-                str = new FileInputStream(mSettingsFilename);
-            }
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(str, null);
-
-            int type;
-            while ((type = parser.next()) != XmlPullParser.START_TAG
-                    && type != XmlPullParser.END_DOCUMENT) {
-                ;
-            }
-
-            if (type != XmlPullParser.START_TAG) {
-                mReadMessages.append("No start tag found in settings file\n");
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "No start tag found in package manager settings");
-                Log.wtf(PackageManagerService.TAG,
-                        "No start tag found in package manager settings");
-                return false;
-            }
-
-            int outerDepth = parser.getDepth();
-            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-
-                String tagName = parser.getName();
-                if (tagName.equals("package")) {
-                    readPackageLPw(parser);
-                } else if (tagName.equals("permissions")) {
-                    readPermissionsLPw(mPermissions, parser);
-                } else if (tagName.equals("permission-trees")) {
-                    readPermissionsLPw(mPermissionTrees, parser);
-                } else if (tagName.equals("shared-user")) {
-                    readSharedUserLPw(parser);
-                } else if (tagName.equals("preferred-packages")) {
-                    // no longer used.
-                } else if (tagName.equals("preferred-activities")) {
-                    // Upgrading from old single-user implementation;
-                    // these are the preferred activities for user 0.
-                    readPreferredActivitiesLPw(parser, 0);
-                } else if (tagName.equals("updated-package")) {
-                    readDisabledSysPackageLPw(parser);
-                } else if (tagName.equals("cleaning-package")) {
-                    String name = parser.getAttributeValue(null, ATTR_NAME);
-                    String userStr = parser.getAttributeValue(null, ATTR_USER);
-                    String codeStr = parser.getAttributeValue(null, ATTR_CODE);
-                    if (name != null) {
-                        int userId = 0;
-                        boolean andCode = true;
-                        try {
-                            if (userStr != null) {
-                                userId = Integer.parseInt(userStr);
-                            }
-                        } catch (NumberFormatException e) {
-                        }
-                        if (codeStr != null) {
-                            andCode = Boolean.parseBoolean(codeStr);
-                        }
-                        addPackageToCleanLPw(new PackageCleanItem(userId, name, andCode));
-                    }
-                } else if (tagName.equals("renamed-package")) {
-                    String nname = parser.getAttributeValue(null, "new");
-                    String oname = parser.getAttributeValue(null, "old");
-                    if (nname != null && oname != null) {
-                        mRenamedPackages.put(nname, oname);
-                    }
-                } else if (tagName.equals("last-platform-version")) {
-                    mInternalSdkPlatform = mExternalSdkPlatform = 0;
-                    try {
-                        String internal = parser.getAttributeValue(null, "internal");
-                        if (internal != null) {
-                            mInternalSdkPlatform = Integer.parseInt(internal);
-                        }
-                        String external = parser.getAttributeValue(null, "external");
-                        if (external != null) {
-                            mExternalSdkPlatform = Integer.parseInt(external);
-                        }
-                    } catch (NumberFormatException e) {
-                    }
-                } else if (tagName.equals("verifier")) {
-                    final String deviceIdentity = parser.getAttributeValue(null, "device");
-                    try {
-                        mVerifierDeviceIdentity = VerifierDeviceIdentity.parse(deviceIdentity);
-                    } catch (IllegalArgumentException e) {
-                        Slog.w(PackageManagerService.TAG, "Discard invalid verifier device id: "
-                                + e.getMessage());
-                    }
-                } else if (TAG_READ_EXTERNAL_STORAGE.equals(tagName)) {
-                    final String enforcement = parser.getAttributeValue(null, ATTR_ENFORCEMENT);
-                    mReadExternalStorageEnforced = "1".equals(enforcement);
-                } else if (tagName.equals("keyset-settings")) {
-                    mKeySetManager.readKeySetsLPw(parser);
-                } else {
-                    Slog.w(PackageManagerService.TAG, "Unknown element under <packages>: "
-                            + parser.getName());
-                    XmlUtils.skipCurrentTag(parser);
-                }
-            }
-
-            str.close();
-
-        } catch (XmlPullParserException e) {
-            mReadMessages.append("Error reading: " + e.toString());
-            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
-            Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
-
-        } catch (java.io.IOException e) {
-            mReadMessages.append("Error reading: " + e.toString());
-            PackageManagerService.reportSettingsProblem(Log.ERROR, "Error reading settings: " + e);
-            Log.wtf(PackageManagerService.TAG, "Error reading package manager settings", e);
-        }
-
-        final int N = mPendingPackages.size();
-        for (int i = 0; i < N; i++) {
-            final PendingPackage pp = mPendingPackages.get(i);
-            Object idObj = getUserIdLPr(pp.sharedId);
-            if (idObj != null && idObj instanceof SharedUserSetting) {
-                PackageSetting p = getPackageLPw(pp.name, null, pp.realName,
-                        (SharedUserSetting) idObj, pp.codePath, pp.resourcePath,
-                        pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags,
-                        null, true /* add */, false /* allowInstall */);
-                if (p == null) {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Unable to create application package for " + pp.name);
-                    continue;
-                }
-                p.copyFrom(pp);
-            } else if (idObj != null) {
-                String msg = "Bad package setting: package " + pp.name + " has shared uid "
-                        + pp.sharedId + " that is not a shared uid\n";
-                mReadMessages.append(msg);
-                PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
-            } else {
-                String msg = "Bad package setting: package " + pp.name + " has shared uid "
-                        + pp.sharedId + " that is not defined\n";
-                mReadMessages.append(msg);
-                PackageManagerService.reportSettingsProblem(Log.ERROR, msg);
-            }
-        }
-        mPendingPackages.clear();
-
-        if (mBackupStoppedPackagesFilename.exists()
-                || mStoppedPackagesFilename.exists()) {
-            // Read old file
-            readStoppedLPw();
-            mBackupStoppedPackagesFilename.delete();
-            mStoppedPackagesFilename.delete();
-            // Migrate to new file format
-            writePackageRestrictionsLPr(0);
-        } else {
-            if (users == null) {
-                readPackageRestrictionsLPr(0);
-            } else {
-                for (UserInfo user : users) {
-                    readPackageRestrictionsLPr(user.id);
-                }
-            }
-        }
-
-        /*
-         * Make sure all the updated system packages have their shared users
-         * associated with them.
-         */
-        final Iterator<PackageSetting> disabledIt = mDisabledSysPackages.values().iterator();
-        while (disabledIt.hasNext()) {
-            final PackageSetting disabledPs = disabledIt.next();
-            final Object id = getUserIdLPr(disabledPs.appId);
-            if (id != null && id instanceof SharedUserSetting) {
-                disabledPs.sharedUser = (SharedUserSetting) id;
-            }
-        }
-
-        mReadMessages.append("Read completed successfully: " + mPackages.size() + " packages, "
-                + mSharedUsers.size() + " shared uids\n");
-
-        return true;
-    }
-
-    void readDefaultPreferredAppsLPw(PackageManagerService service, int userId) {
-        // First pull data from any pre-installed apps.
-        for (PackageSetting ps : mPackages.values()) {
-            if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null
-                    && ps.pkg.preferredActivityFilters != null) {
-                ArrayList<PackageParser.ActivityIntentInfo> intents
-                        = ps.pkg.preferredActivityFilters;
-                for (int i=0; i<intents.size(); i++) {
-                    PackageParser.ActivityIntentInfo aii = intents.get(i);
-                    applyDefaultPreferredActivityLPw(service, aii, new ComponentName(
-                            ps.name, aii.activity.className), userId);
-                }
-            }
-        }
-
-        // Read preferred apps from .../etc/preferred-apps directory.
-        File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
-        if (!preferredDir.exists() || !preferredDir.isDirectory()) {
-            return;
-        }
-        if (!preferredDir.canRead()) {
-            Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
-            return;
-        }
-
-        // Iterate over the files in the directory and scan .xml files
-        for (File f : preferredDir.listFiles()) {
-            if (!f.getPath().endsWith(".xml")) {
-                Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
-                continue;
-            }
-            if (!f.canRead()) {
-                Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
-                continue;
-            }
-
-            if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f);
-            FileInputStream str = null;
-            try {
-                str = new FileInputStream(f);
-                XmlPullParser parser = Xml.newPullParser();
-                parser.setInput(str, null);
-
-                int type;
-                while ((type = parser.next()) != XmlPullParser.START_TAG
-                        && type != XmlPullParser.END_DOCUMENT) {
-                    ;
-                }
-
-                if (type != XmlPullParser.START_TAG) {
-                    Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
-                    continue;
-                }
-                if (!"preferred-activities".equals(parser.getName())) {
-                    Slog.w(TAG, "Preferred apps file " + f
-                            + " does not start with 'preferred-activities'");
-                    continue;
-                }
-                readDefaultPreferredActivitiesLPw(service, parser, userId);
-            } catch (XmlPullParserException e) {
-                Slog.w(TAG, "Error reading apps file " + f, e);
-            } catch (IOException e) {
-                Slog.w(TAG, "Error reading apps file " + f, e);
-            } finally {
-                if (str != null) {
-                    try {
-                        str.close();
-                    } catch (IOException e) {
-                    }
-                }
-            }
-        }
-    }
-
-    private void applyDefaultPreferredActivityLPw(PackageManagerService service,
-            IntentFilter tmpPa, ComponentName cn, int userId) {
-        // The initial preferences only specify the target activity
-        // component and intent-filter, not the set of matches.  So we
-        // now need to query for the matches to build the correct
-        // preferred activity entry.
-        if (PackageManagerService.DEBUG_PREFERRED) {
-            Log.d(TAG, "Processing preferred:");
-            tmpPa.dump(new LogPrinter(Log.DEBUG, TAG), "  ");
-        }
-        Intent intent = new Intent();
-        int flags = 0;
-        intent.setAction(tmpPa.getAction(0));
-        for (int i=0; i<tmpPa.countCategories(); i++) {
-            String cat = tmpPa.getCategory(i);
-            if (cat.equals(Intent.CATEGORY_DEFAULT)) {
-                flags |= PackageManager.MATCH_DEFAULT_ONLY;
-            } else {
-                intent.addCategory(cat);
-            }
-        }
-
-        boolean doNonData = true;
-        boolean hasSchemes = false;
-
-        for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) {
-            boolean doScheme = true;
-            String scheme = tmpPa.getDataScheme(ischeme);
-            if (scheme != null && !scheme.isEmpty()) {
-                hasSchemes = true;
-            }
-            for (int issp=0; issp<tmpPa.countDataSchemeSpecificParts(); issp++) {
-                Uri.Builder builder = new Uri.Builder();
-                builder.scheme(scheme);
-                PatternMatcher ssp = tmpPa.getDataSchemeSpecificPart(issp);
-                builder.opaquePart(ssp.getPath());
-                Intent finalIntent = new Intent(intent);
-                finalIntent.setData(builder.build());
-                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
-                        scheme, ssp, null, null, null, userId);
-                doScheme = false;
-            }
-            for (int iauth=0; iauth<tmpPa.countDataAuthorities(); iauth++) {
-                boolean doAuth = true;
-                IntentFilter.AuthorityEntry auth = tmpPa.getDataAuthority(iauth);
-                for (int ipath=0; ipath<tmpPa.countDataPaths(); ipath++) {
-                    Uri.Builder builder = new Uri.Builder();
-                    builder.scheme(scheme);
-                    if (auth.getHost() != null) {
-                        builder.authority(auth.getHost());
-                    }
-                    PatternMatcher path = tmpPa.getDataPath(ipath);
-                    builder.path(path.getPath());
-                    Intent finalIntent = new Intent(intent);
-                    finalIntent.setData(builder.build());
-                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
-                            scheme, null, auth, path, null, userId);
-                    doAuth = doScheme = false;
-                }
-                if (doAuth) {
-                    Uri.Builder builder = new Uri.Builder();
-                    builder.scheme(scheme);
-                    if (auth.getHost() != null) {
-                        builder.authority(auth.getHost());
-                    }
-                    Intent finalIntent = new Intent(intent);
-                    finalIntent.setData(builder.build());
-                    applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
-                            scheme, null, auth, null, null, userId);
-                    doScheme = false;
-                }
-            }
-            if (doScheme) {
-                Uri.Builder builder = new Uri.Builder();
-                builder.scheme(scheme);
-                Intent finalIntent = new Intent(intent);
-                finalIntent.setData(builder.build());
-                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
-                        scheme, null, null, null, null, userId);
-            }
-            doNonData = false;
-        }
-
-        for (int idata=0; idata<tmpPa.countDataTypes(); idata++) {
-            String mimeType = tmpPa.getDataType(idata);
-            if (hasSchemes) {
-                Uri.Builder builder = new Uri.Builder();
-                for (int ischeme=0; ischeme<tmpPa.countDataSchemes(); ischeme++) {
-                    String scheme = tmpPa.getDataScheme(ischeme);
-                    if (scheme != null && !scheme.isEmpty()) {
-                        Intent finalIntent = new Intent(intent);
-                        builder.scheme(scheme);
-                        finalIntent.setDataAndType(builder.build(), mimeType);
-                        applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
-                                scheme, null, null, null, mimeType, userId);
-                    }
-                }
-            } else {
-                Intent finalIntent = new Intent(intent);
-                finalIntent.setType(mimeType);
-                applyDefaultPreferredActivityLPw(service, finalIntent, flags, cn,
-                        null, null, null, null, mimeType, userId);
-            }
-            doNonData = false;
-        }
-
-        if (doNonData) {
-            applyDefaultPreferredActivityLPw(service, intent, flags, cn,
-                    null, null, null, null, null, userId);
-        }
-    }
-
-    private void applyDefaultPreferredActivityLPw(PackageManagerService service,
-            Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp,
-            IntentFilter.AuthorityEntry auth, PatternMatcher path, String mimeType,
-            int userId) {
-        List<ResolveInfo> ri = service.mActivities.queryIntent(intent,
-                intent.getType(), flags, 0);
-        if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Queried " + intent
-                + " results: " + ri);
-        int match = 0;
-        if (ri != null && ri.size() > 1) {
-            boolean haveAct = false;
-            boolean haveNonSys = false;
-            ComponentName[] set = new ComponentName[ri.size()];
-            for (int i=0; i<ri.size(); i++) {
-                ActivityInfo ai = ri.get(i).activityInfo;
-                set[i] = new ComponentName(ai.packageName, ai.name);
-                if ((ai.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
-                    // If any of the matches are not system apps, then
-                    // there is a third party app that is now an option...
-                    // so don't set a default since we don't want to hide it.
-                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
-                            + ai.packageName + "/" + ai.name + ": non-system!");
-                    haveNonSys = true;
-                    break;
-                } else if (cn.getPackageName().equals(ai.packageName)
-                        && cn.getClassName().equals(ai.name)) {
-                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
-                            + ai.packageName + "/" + ai.name + ": default!");
-                    haveAct = true;
-                    match = ri.get(i).match;
-                } else {
-                    if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Result "
-                            + ai.packageName + "/" + ai.name + ": skipped");
-                }
-            }
-            if (haveAct && !haveNonSys) {
-                IntentFilter filter = new IntentFilter();
-                if (intent.getAction() != null) {
-                    filter.addAction(intent.getAction());
-                }
-                if (intent.getCategories() != null) {
-                    for (String cat : intent.getCategories()) {
-                        filter.addCategory(cat);
-                    }
-                }
-                if ((flags&PackageManager.MATCH_DEFAULT_ONLY) != 0) {
-                    filter.addCategory(Intent.CATEGORY_DEFAULT);
-                }
-                if (scheme != null) {
-                    filter.addDataScheme(scheme);
-                }
-                if (ssp != null) {
-                    filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType());
-                }
-                if (auth != null) {
-                    filter.addDataAuthority(auth);
-                }
-                if (path != null) {
-                    filter.addDataPath(path);
-                }
-                if (intent.getType() != null) {
-                    try {
-                        filter.addDataType(intent.getType());
-                    } catch (IntentFilter.MalformedMimeTypeException ex) {
-                        Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn);
-                    }
-                }
-                PreferredActivity pa = new PreferredActivity(filter, match, set, cn, true);
-                editPreferredActivitiesLPw(userId).addFilter(pa);
-            } else if (!haveNonSys) {
-                Slog.w(TAG, "No component found for default preferred activity " + cn);
-            }
-        }
-    }
-
-    private void readDefaultPreferredActivitiesLPw(PackageManagerService service,
-            XmlPullParser parser, int userId)
-            throws XmlPullParserException, IOException {
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                PreferredActivity tmpPa = new PreferredActivity(parser);
-                if (tmpPa.mPref.getParseError() == null) {
-                    applyDefaultPreferredActivityLPw(service, tmpPa, tmpPa.mPref.mComponent,
-                            userId);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: <preferred-activity> "
-                                    + tmpPa.mPref.getParseError() + " at "
-                                    + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element under <preferred-activities>: " + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-    }
-
-    private int readInt(XmlPullParser parser, String ns, String name, int defValue) {
-        String v = parser.getAttributeValue(ns, name);
-        try {
-            if (v == null) {
-                return defValue;
-            }
-            return Integer.parseInt(v);
-        } catch (NumberFormatException e) {
-            PackageManagerService.reportSettingsProblem(Log.WARN,
-                    "Error in package manager settings: attribute " + name
-                            + " has bad integer value " + v + " at "
-                            + parser.getPositionDescription());
-        }
-        return defValue;
-    }
-
-    private void readPermissionsLPw(HashMap<String, BasePermission> out, XmlPullParser parser)
-            throws IOException, XmlPullParserException {
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            final String tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                final String name = parser.getAttributeValue(null, ATTR_NAME);
-                final String sourcePackage = parser.getAttributeValue(null, "package");
-                final String ptype = parser.getAttributeValue(null, "type");
-                if (name != null && sourcePackage != null) {
-                    final boolean dynamic = "dynamic".equals(ptype);
-                    final BasePermission bp = new BasePermission(name, sourcePackage,
-                            dynamic ? BasePermission.TYPE_DYNAMIC : BasePermission.TYPE_NORMAL);
-                    bp.protectionLevel = readInt(parser, null, "protection",
-                            PermissionInfo.PROTECTION_NORMAL);
-                    bp.protectionLevel = PermissionInfo.fixProtectionLevel(bp.protectionLevel);
-                    if (dynamic) {
-                        PermissionInfo pi = new PermissionInfo();
-                        pi.packageName = sourcePackage.intern();
-                        pi.name = name.intern();
-                        pi.icon = readInt(parser, null, "icon", 0);
-                        pi.nonLocalizedLabel = parser.getAttributeValue(null, "label");
-                        pi.protectionLevel = bp.protectionLevel;
-                        bp.pendingInfo = pi;
-                    }
-                    out.put(bp.name, bp);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: permissions has" + " no name at "
-                                    + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element reading permissions: " + parser.getName() + " at "
-                                + parser.getPositionDescription());
-            }
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    private void readDisabledSysPackageLPw(XmlPullParser parser) throws XmlPullParserException,
-            IOException {
-        String name = parser.getAttributeValue(null, ATTR_NAME);
-        String realName = parser.getAttributeValue(null, "realName");
-        String codePathStr = parser.getAttributeValue(null, "codePath");
-        String resourcePathStr = parser.getAttributeValue(null, "resourcePath");
-        String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
-        if (resourcePathStr == null) {
-            resourcePathStr = codePathStr;
-        }
-        String version = parser.getAttributeValue(null, "version");
-        int versionCode = 0;
-        if (version != null) {
-            try {
-                versionCode = Integer.parseInt(version);
-            } catch (NumberFormatException e) {
-            }
-        }
-
-        int pkgFlags = 0;
-        pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
-        final File codePathFile = new File(codePathStr);
-        if (PackageManagerService.locationIsPrivileged(codePathFile)) {
-            pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED;
-        }
-        PackageSetting ps = new PackageSetting(name, realName, codePathFile,
-                new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags);
-        String timeStampStr = parser.getAttributeValue(null, "ft");
-        if (timeStampStr != null) {
-            try {
-                long timeStamp = Long.parseLong(timeStampStr, 16);
-                ps.setTimeStamp(timeStamp);
-            } catch (NumberFormatException e) {
-            }
-        } else {
-            timeStampStr = parser.getAttributeValue(null, "ts");
-            if (timeStampStr != null) {
-                try {
-                    long timeStamp = Long.parseLong(timeStampStr);
-                    ps.setTimeStamp(timeStamp);
-                } catch (NumberFormatException e) {
-                }
-            }
-        }
-        timeStampStr = parser.getAttributeValue(null, "it");
-        if (timeStampStr != null) {
-            try {
-                ps.firstInstallTime = Long.parseLong(timeStampStr, 16);
-            } catch (NumberFormatException e) {
-            }
-        }
-        timeStampStr = parser.getAttributeValue(null, "ut");
-        if (timeStampStr != null) {
-            try {
-                ps.lastUpdateTime = Long.parseLong(timeStampStr, 16);
-            } catch (NumberFormatException e) {
-            }
-        }
-        String idStr = parser.getAttributeValue(null, "userId");
-        ps.appId = idStr != null ? Integer.parseInt(idStr) : 0;
-        if (ps.appId <= 0) {
-            String sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
-            ps.appId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
-        }
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals("perms")) {
-                readGrantedPermissionsLPw(parser, ps.grantedPermissions);
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element under <updated-package>: " + parser.getName());
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-
-        mDisabledSysPackages.put(name, ps);
-    }
-
-    private void readPackageLPw(XmlPullParser parser) throws XmlPullParserException, IOException {
-        String name = null;
-        String realName = null;
-        String idStr = null;
-        String sharedIdStr = null;
-        String codePathStr = null;
-        String resourcePathStr = null;
-        String nativeLibraryPathStr = null;
-        String systemStr = null;
-        String installerPackageName = null;
-        String uidError = null;
-        int pkgFlags = 0;
-        long timeStamp = 0;
-        long firstInstallTime = 0;
-        long lastUpdateTime = 0;
-        PackageSettingBase packageSetting = null;
-        String version = null;
-        int versionCode = 0;
-        try {
-            name = parser.getAttributeValue(null, ATTR_NAME);
-            realName = parser.getAttributeValue(null, "realName");
-            idStr = parser.getAttributeValue(null, "userId");
-            uidError = parser.getAttributeValue(null, "uidError");
-            sharedIdStr = parser.getAttributeValue(null, "sharedUserId");
-            codePathStr = parser.getAttributeValue(null, "codePath");
-            resourcePathStr = parser.getAttributeValue(null, "resourcePath");
-            nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
-            version = parser.getAttributeValue(null, "version");
-            if (version != null) {
-                try {
-                    versionCode = Integer.parseInt(version);
-                } catch (NumberFormatException e) {
-                }
-            }
-            installerPackageName = parser.getAttributeValue(null, "installer");
-
-            systemStr = parser.getAttributeValue(null, "flags");
-            if (systemStr != null) {
-                try {
-                    pkgFlags = Integer.parseInt(systemStr);
-                } catch (NumberFormatException e) {
-                }
-            } else {
-                // For backward compatibility
-                systemStr = parser.getAttributeValue(null, "system");
-                if (systemStr != null) {
-                    pkgFlags |= ("true".equalsIgnoreCase(systemStr)) ? ApplicationInfo.FLAG_SYSTEM
-                            : 0;
-                } else {
-                    // Old settings that don't specify system... just treat
-                    // them as system, good enough.
-                    pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
-                }
-            }
-            String timeStampStr = parser.getAttributeValue(null, "ft");
-            if (timeStampStr != null) {
-                try {
-                    timeStamp = Long.parseLong(timeStampStr, 16);
-                } catch (NumberFormatException e) {
-                }
-            } else {
-                timeStampStr = parser.getAttributeValue(null, "ts");
-                if (timeStampStr != null) {
-                    try {
-                        timeStamp = Long.parseLong(timeStampStr);
-                    } catch (NumberFormatException e) {
-                    }
-                }
-            }
-            timeStampStr = parser.getAttributeValue(null, "it");
-            if (timeStampStr != null) {
-                try {
-                    firstInstallTime = Long.parseLong(timeStampStr, 16);
-                } catch (NumberFormatException e) {
-                }
-            }
-            timeStampStr = parser.getAttributeValue(null, "ut");
-            if (timeStampStr != null) {
-                try {
-                    lastUpdateTime = Long.parseLong(timeStampStr, 16);
-                } catch (NumberFormatException e) {
-                }
-            }
-            if (PackageManagerService.DEBUG_SETTINGS)
-                Log.v(PackageManagerService.TAG, "Reading package: " + name + " userId=" + idStr
-                        + " sharedUserId=" + sharedIdStr);
-            int userId = idStr != null ? Integer.parseInt(idStr) : 0;
-            if (resourcePathStr == null) {
-                resourcePathStr = codePathStr;
-            }
-            if (realName != null) {
-                realName = realName.intern();
-            }
-            if (name == null) {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Error in package manager settings: <package> has no name at "
-                                + parser.getPositionDescription());
-            } else if (codePathStr == null) {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Error in package manager settings: <package> has no codePath at "
-                                + parser.getPositionDescription());
-            } else if (userId > 0) {
-                packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
-                        new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode,
-                        pkgFlags);
-                if (PackageManagerService.DEBUG_SETTINGS)
-                    Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId="
-                            + userId + " pkg=" + packageSetting);
-                if (packageSetting == null) {
-                    PackageManagerService.reportSettingsProblem(Log.ERROR, "Failure adding uid "
-                            + userId + " while parsing settings at "
-                            + parser.getPositionDescription());
-                } else {
-                    packageSetting.setTimeStamp(timeStamp);
-                    packageSetting.firstInstallTime = firstInstallTime;
-                    packageSetting.lastUpdateTime = lastUpdateTime;
-                }
-            } else if (sharedIdStr != null) {
-                userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
-                if (userId > 0) {
-                    packageSetting = new PendingPackage(name.intern(), realName, new File(
-                            codePathStr), new File(resourcePathStr), nativeLibraryPathStr, userId,
-                            versionCode, pkgFlags);
-                    packageSetting.setTimeStamp(timeStamp);
-                    packageSetting.firstInstallTime = firstInstallTime;
-                    packageSetting.lastUpdateTime = lastUpdateTime;
-                    mPendingPackages.add((PendingPackage) packageSetting);
-                    if (PackageManagerService.DEBUG_SETTINGS)
-                        Log.i(PackageManagerService.TAG, "Reading package " + name
-                                + ": sharedUserId=" + userId + " pkg=" + packageSetting);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: package " + name
-                                    + " has bad sharedId " + sharedIdStr + " at "
-                                    + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Error in package manager settings: package " + name + " has bad userId "
-                                + idStr + " at " + parser.getPositionDescription());
-            }
-        } catch (NumberFormatException e) {
-            PackageManagerService.reportSettingsProblem(Log.WARN,
-                    "Error in package manager settings: package " + name + " has bad userId "
-                            + idStr + " at " + parser.getPositionDescription());
-        }
-        if (packageSetting != null) {
-            packageSetting.uidError = "true".equals(uidError);
-            packageSetting.installerPackageName = installerPackageName;
-            packageSetting.nativeLibraryPathString = nativeLibraryPathStr;
-            // Handle legacy string here for single-user mode
-            final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
-            if (enabledStr != null) {
-                try {
-                    packageSetting.setEnabled(Integer.parseInt(enabledStr), 0 /* userId */, null);
-                } catch (NumberFormatException e) {
-                    if (enabledStr.equalsIgnoreCase("true")) {
-                        packageSetting.setEnabled(COMPONENT_ENABLED_STATE_ENABLED, 0, null);
-                    } else if (enabledStr.equalsIgnoreCase("false")) {
-                        packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DISABLED, 0, null);
-                    } else if (enabledStr.equalsIgnoreCase("default")) {
-                        packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
-                    } else {
-                        PackageManagerService.reportSettingsProblem(Log.WARN,
-                                "Error in package manager settings: package " + name
-                                        + " has bad enabled value: " + idStr + " at "
-                                        + parser.getPositionDescription());
-                    }
-                }
-            } else {
-                packageSetting.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, 0, null);
-            }
-
-            final String installStatusStr = parser.getAttributeValue(null, "installStatus");
-            if (installStatusStr != null) {
-                if (installStatusStr.equalsIgnoreCase("false")) {
-                    packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_INCOMPLETE;
-                } else {
-                    packageSetting.installStatus = PackageSettingBase.PKG_INSTALL_COMPLETE;
-                }
-            }
-
-            int outerDepth = parser.getDepth();
-            int type;
-            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-
-                String tagName = parser.getName();
-                // Legacy 
-                if (tagName.equals(TAG_DISABLED_COMPONENTS)) {
-                    readDisabledComponentsLPw(packageSetting, parser, 0);
-                } else if (tagName.equals(TAG_ENABLED_COMPONENTS)) {
-                    readEnabledComponentsLPw(packageSetting, parser, 0);
-                } else if (tagName.equals("sigs")) {
-                    packageSetting.signatures.readXml(parser, mPastSignatures);
-                } else if (tagName.equals("perms")) {
-                    readGrantedPermissionsLPw(parser, packageSetting.grantedPermissions);
-                    packageSetting.permissionsFixed = true;
-                } else if (tagName.equals("signing-keyset")) {
-                    long id = Long.parseLong(parser.getAttributeValue(null, "identifier"));
-                    packageSetting.keySetData.addSigningKeySet(id);
-                    if (false) Slog.d(TAG, "Adding signing keyset " + Long.toString(id)
-                            + " to " + name);
-                } else if (tagName.equals("defined-keyset")) {
-                    long id = Long.parseLong(parser.getAttributeValue(null, "identifier"));
-                    String alias = parser.getAttributeValue(null, "alias");
-                    packageSetting.keySetData.addDefinedKeySet(id, alias);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Unknown element under <package>: " + parser.getName());
-                    XmlUtils.skipCurrentTag(parser);
-                }
-            }
-
-
-        } else {
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    private void readDisabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
-            int userId) throws IOException, XmlPullParserException {
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                String name = parser.getAttributeValue(null, ATTR_NAME);
-                if (name != null) {
-                    packageSetting.addDisabledComponent(name.intern(), userId);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: <disabled-components> has"
-                                    + " no name at " + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element under <disabled-components>: " + parser.getName());
-            }
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    private void readEnabledComponentsLPw(PackageSettingBase packageSetting, XmlPullParser parser,
-            int userId) throws IOException, XmlPullParserException {
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                String name = parser.getAttributeValue(null, ATTR_NAME);
-                if (name != null) {
-                    packageSetting.addEnabledComponent(name.intern(), userId);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: <enabled-components> has"
-                                    + " no name at " + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element under <enabled-components>: " + parser.getName());
-            }
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    private void readSharedUserLPw(XmlPullParser parser) throws XmlPullParserException,IOException {
-        String name = null;
-        String idStr = null;
-        int pkgFlags = 0;
-        SharedUserSetting su = null;
-        try {
-            name = parser.getAttributeValue(null, ATTR_NAME);
-            idStr = parser.getAttributeValue(null, "userId");
-            int userId = idStr != null ? Integer.parseInt(idStr) : 0;
-            if ("true".equals(parser.getAttributeValue(null, "system"))) {
-                pkgFlags |= ApplicationInfo.FLAG_SYSTEM;
-            }
-            if (name == null) {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Error in package manager settings: <shared-user> has no name at "
-                                + parser.getPositionDescription());
-            } else if (userId == 0) {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Error in package manager settings: shared-user " + name
-                                + " has bad userId " + idStr + " at "
-                                + parser.getPositionDescription());
-            } else {
-                if ((su = addSharedUserLPw(name.intern(), userId, pkgFlags)) == null) {
-                    PackageManagerService
-                            .reportSettingsProblem(Log.ERROR, "Occurred while parsing settings at "
-                                    + parser.getPositionDescription());
-                }
-            }
-        } catch (NumberFormatException e) {
-            PackageManagerService.reportSettingsProblem(Log.WARN,
-                    "Error in package manager settings: package " + name + " has bad userId "
-                            + idStr + " at " + parser.getPositionDescription());
-        }
-        ;
-
-        if (su != null) {
-            int outerDepth = parser.getDepth();
-            int type;
-            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                    && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-
-                String tagName = parser.getName();
-                if (tagName.equals("sigs")) {
-                    su.signatures.readXml(parser, mPastSignatures);
-                } else if (tagName.equals("perms")) {
-                    readGrantedPermissionsLPw(parser, su.grantedPermissions);
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Unknown element under <shared-user>: " + parser.getName());
-                    XmlUtils.skipCurrentTag(parser);
-                }
-            }
-
-        } else {
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    private void readGrantedPermissionsLPw(XmlPullParser parser, HashSet<String> outPerms)
-            throws IOException, XmlPullParserException {
-        int outerDepth = parser.getDepth();
-        int type;
-        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
-                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
-            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
-                continue;
-            }
-
-            String tagName = parser.getName();
-            if (tagName.equals(TAG_ITEM)) {
-                String name = parser.getAttributeValue(null, ATTR_NAME);
-                if (name != null) {
-                    outPerms.add(name.intern());
-                } else {
-                    PackageManagerService.reportSettingsProblem(Log.WARN,
-                            "Error in package manager settings: <perms> has" + " no name at "
-                                    + parser.getPositionDescription());
-                }
-            } else {
-                PackageManagerService.reportSettingsProblem(Log.WARN,
-                        "Unknown element under <perms>: " + parser.getName());
-            }
-            XmlUtils.skipCurrentTag(parser);
-        }
-    }
-
-    void createNewUserLILPw(PackageManagerService service, Installer installer,
-            int userHandle, File path) {
-        path.mkdir();
-        FileUtils.setPermissions(path.toString(), FileUtils.S_IRWXU | FileUtils.S_IRWXG
-                | FileUtils.S_IXOTH, -1, -1);
-        for (PackageSetting ps : mPackages.values()) {
-            // Only system apps are initially installed.
-            ps.setInstalled((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0, userHandle);
-            // Need to create a data directory for all apps under this user.
-            installer.createUserData(ps.name,
-                    UserHandle.getUid(userHandle, ps.appId), userHandle);
-        }
-        readDefaultPreferredAppsLPw(service, userHandle);
-        writePackageRestrictionsLPr(userHandle);
-    }
-
-    void removeUserLPr(int userId) {
-        Set<Entry<String, PackageSetting>> entries = mPackages.entrySet();
-        for (Entry<String, PackageSetting> entry : entries) {
-            entry.getValue().removeUser(userId);
-        }
-        mPreferredActivities.remove(userId);
-        File file = getUserPackagesStateFile(userId);
-        file.delete();
-        file = getUserPackagesStateBackupFile(userId);
-        file.delete();
-    }
-
-    // This should be called (at least) whenever an application is removed
-    private void setFirstAvailableUid(int uid) {
-        if (uid > mFirstAvailableUid) {
-            mFirstAvailableUid = uid;
-        }
-    }
-
-    // Returns -1 if we could not find an available UserId to assign
-    private int newUserIdLPw(Object obj) {
-        // Let's be stupidly inefficient for now...
-        final int N = mUserIds.size();
-        for (int i = mFirstAvailableUid; i < N; i++) {
-            if (mUserIds.get(i) == null) {
-                mUserIds.set(i, obj);
-                return Process.FIRST_APPLICATION_UID + i;
-            }
-        }
-
-        // None left?
-        if (N > (Process.LAST_APPLICATION_UID-Process.FIRST_APPLICATION_UID)) {
-            return -1;
-        }
-
-        mUserIds.add(obj);
-        return Process.FIRST_APPLICATION_UID + N;
-    }
-
-    public VerifierDeviceIdentity getVerifierDeviceIdentityLPw() {
-        if (mVerifierDeviceIdentity == null) {
-            mVerifierDeviceIdentity = VerifierDeviceIdentity.generate();
-
-            writeLPr();
-        }
-
-        return mVerifierDeviceIdentity;
-    }
-
-    public PackageSetting getDisabledSystemPkgLPr(String name) {
-        PackageSetting ps = mDisabledSysPackages.get(name);
-        return ps;
-    }
-
-    private String compToString(HashSet<String> cmp) {
-        return cmp != null ? Arrays.toString(cmp.toArray()) : "[]";
-    }
- 
-    boolean isEnabledLPr(ComponentInfo componentInfo, int flags, int userId) {
-        if ((flags&PackageManager.GET_DISABLED_COMPONENTS) != 0) {
-            return true;
-        }
-        final String pkgName = componentInfo.packageName;
-        final PackageSetting packageSettings = mPackages.get(pkgName);
-        if (PackageManagerService.DEBUG_SETTINGS) {
-            Log.v(PackageManagerService.TAG, "isEnabledLock - packageName = "
-                    + componentInfo.packageName + " componentName = " + componentInfo.name);
-            Log.v(PackageManagerService.TAG, "enabledComponents: "
-                    + compToString(packageSettings.getEnabledComponents(userId)));
-            Log.v(PackageManagerService.TAG, "disabledComponents: "
-                    + compToString(packageSettings.getDisabledComponents(userId)));
-        }
-        if (packageSettings == null) {
-            return false;
-        }
-        PackageUserState ustate = packageSettings.readUserState(userId);
-        if ((flags&PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) != 0) {
-            if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) {
-                return true;
-            }
-        }
-        if (ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED
-                || ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_USER
-                || ustate.enabled == COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
-                || (packageSettings.pkg != null && !packageSettings.pkg.applicationInfo.enabled
-                    && ustate.enabled == COMPONENT_ENABLED_STATE_DEFAULT)) {
-            return false;
-        }
-        if (ustate.enabledComponents != null
-                && ustate.enabledComponents.contains(componentInfo.name)) {
-            return true;
-        }
-        if (ustate.disabledComponents != null
-                && ustate.disabledComponents.contains(componentInfo.name)) {
-            return false;
-        }
-        return componentInfo.enabled;
-    }
-
-    String getInstallerPackageNameLPr(String packageName) {
-        final PackageSetting pkg = mPackages.get(packageName);
-        if (pkg == null) {
-            throw new IllegalArgumentException("Unknown package: " + packageName);
-        }
-        return pkg.installerPackageName;
-    }
-
-    int getApplicationEnabledSettingLPr(String packageName, int userId) {
-        final PackageSetting pkg = mPackages.get(packageName);
-        if (pkg == null) {
-            throw new IllegalArgumentException("Unknown package: " + packageName);
-        }
-        return pkg.getEnabled(userId);
-    }
-
-    int getComponentEnabledSettingLPr(ComponentName componentName, int userId) {
-        final String packageName = componentName.getPackageName();
-        final PackageSetting pkg = mPackages.get(packageName);
-        if (pkg == null) {
-            throw new IllegalArgumentException("Unknown component: " + componentName);
-        }
-        final String classNameStr = componentName.getClassName();
-        return pkg.getCurrentEnabledStateLPr(classNameStr, userId);
-    }
-
-    boolean setPackageStoppedStateLPw(String packageName, boolean stopped,
-            boolean allowedByPermission, int uid, int userId) {
-        int appId = UserHandle.getAppId(uid);
-        final PackageSetting pkgSetting = mPackages.get(packageName);
-        if (pkgSetting == null) {
-            throw new IllegalArgumentException("Unknown package: " + packageName);
-        }
-        if (!allowedByPermission && (appId != pkgSetting.appId)) {
-            throw new SecurityException(
-                    "Permission Denial: attempt to change stopped state from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + uid + ", package uid=" + pkgSetting.appId);
-        }
-        if (DEBUG_STOPPED) {
-            if (stopped) {
-                RuntimeException e = new RuntimeException("here");
-                e.fillInStackTrace();
-                Slog.i(TAG, "Stopping package " + packageName, e);
-            }
-        }
-        if (pkgSetting.getStopped(userId) != stopped) {
-            pkgSetting.setStopped(stopped, userId);
-            // pkgSetting.pkg.mSetStopped = stopped;
-            if (pkgSetting.getNotLaunched(userId)) {
-                if (pkgSetting.installerPackageName != null) {
-                    PackageManagerService.sendPackageBroadcast(Intent.ACTION_PACKAGE_FIRST_LAUNCH,
-                            pkgSetting.name, null,
-                            pkgSetting.installerPackageName, null, new int[] {userId});
-                }
-                pkgSetting.setNotLaunched(false, userId);
-            }
-            return true;
-        }
-        return false;
-    }
-
-    private List<UserInfo> getAllUsers() {
-        long id = Binder.clearCallingIdentity();
-        try {
-            return UserManagerService.getInstance().getUsers(false);
-        } catch (NullPointerException npe) {
-            // packagemanager not yet initialized
-        } finally {
-            Binder.restoreCallingIdentity(id);
-        }
-        return null;
-    }
-
-    static final void printFlags(PrintWriter pw, int val, Object[] spec) {
-        pw.print("[ ");
-        for (int i=0; i<spec.length; i+=2) {
-            int mask = (Integer)spec[i];
-            if ((val & mask) != 0) {
-                pw.print(spec[i+1]);
-                pw.print(" ");
-            }
-        }
-        pw.print("]");
-    }
-
-    static final Object[] FLAG_DUMP_SPEC = new Object[] {
-        ApplicationInfo.FLAG_SYSTEM, "SYSTEM",
-        ApplicationInfo.FLAG_DEBUGGABLE, "DEBUGGABLE",
-        ApplicationInfo.FLAG_HAS_CODE, "HAS_CODE",
-        ApplicationInfo.FLAG_PERSISTENT, "PERSISTENT",
-        ApplicationInfo.FLAG_FACTORY_TEST, "FACTORY_TEST",
-        ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING, "ALLOW_TASK_REPARENTING",
-        ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA, "ALLOW_CLEAR_USER_DATA",
-        ApplicationInfo.FLAG_UPDATED_SYSTEM_APP, "UPDATED_SYSTEM_APP",
-        ApplicationInfo.FLAG_TEST_ONLY, "TEST_ONLY",
-        ApplicationInfo.FLAG_VM_SAFE_MODE, "VM_SAFE_MODE",
-        ApplicationInfo.FLAG_ALLOW_BACKUP, "ALLOW_BACKUP",
-        ApplicationInfo.FLAG_KILL_AFTER_RESTORE, "KILL_AFTER_RESTORE",
-        ApplicationInfo.FLAG_RESTORE_ANY_VERSION, "RESTORE_ANY_VERSION",
-        ApplicationInfo.FLAG_EXTERNAL_STORAGE, "EXTERNAL_STORAGE",
-        ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP",
-        ApplicationInfo.FLAG_PRIVILEGED, "PRIVILEGED",
-        ApplicationInfo.FLAG_FORWARD_LOCK, "FORWARD_LOCK",
-        ApplicationInfo.FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE",
-    };
-
-    void dumpPackageLPr(PrintWriter pw, String prefix, String checkinTag, PackageSetting ps,
-            SimpleDateFormat sdf, Date date, List<UserInfo> users) {
-        if (checkinTag != null) {
-            pw.print(checkinTag);
-            pw.print(",");
-            pw.print(ps.realName != null ? ps.realName : ps.name);
-            pw.print(",");
-            pw.print(ps.appId);
-            pw.print(",");
-            pw.print(ps.versionCode);
-            pw.print(",");
-            pw.print(ps.firstInstallTime);
-            pw.print(",");
-            pw.print(ps.lastUpdateTime);
-            pw.print(",");
-            pw.print(ps.installerPackageName != null ? ps.installerPackageName : "?");
-            pw.println();
-            for (UserInfo user : users) {
-                pw.print(checkinTag);
-                pw.print("-");
-                pw.print("usr");
-                pw.print(",");
-                pw.print(user.id);
-                pw.print(",");
-                pw.print(ps.getInstalled(user.id) ? "I" : "i");
-                pw.print(ps.getBlocked(user.id) ? "B" : "b");
-                pw.print(ps.getStopped(user.id) ? "S" : "s");
-                pw.print(ps.getNotLaunched(user.id) ? "l" : "L");
-                pw.print(",");
-                pw.print(ps.getEnabled(user.id));
-                String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id);
-                pw.print(",");
-                pw.print(lastDisabledAppCaller != null ? lastDisabledAppCaller : "?");
-                pw.println();
-            }
-            return;
-        }
-
-        pw.print(prefix); pw.print("Package [");
-            pw.print(ps.realName != null ? ps.realName : ps.name);
-            pw.print("] (");
-            pw.print(Integer.toHexString(System.identityHashCode(ps)));
-            pw.println("):");
-
-        if (ps.realName != null) {
-            pw.print(prefix); pw.print("  compat name=");
-            pw.println(ps.name);
-        }
-
-        pw.print(prefix); pw.print("  userId="); pw.print(ps.appId);
-                pw.print(" gids="); pw.println(PackageManagerService.arrayToString(ps.gids));
-        if (ps.sharedUser != null) {
-            pw.print(prefix); pw.print("  sharedUser="); pw.println(ps.sharedUser);
-        }
-        pw.print(prefix); pw.print("  pkg="); pw.println(ps.pkg);
-        pw.print(prefix); pw.print("  codePath="); pw.println(ps.codePathString);
-        pw.print(prefix); pw.print("  resourcePath="); pw.println(ps.resourcePathString);
-        pw.print(prefix); pw.print("  nativeLibraryPath="); pw.println(ps.nativeLibraryPathString);
-        pw.print(prefix); pw.print("  versionCode="); pw.print(ps.versionCode);
-        if (ps.pkg != null) {
-            pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion);
-        }
-        pw.println();
-        if (ps.pkg != null) {
-            pw.print(prefix); pw.print("  versionName="); pw.println(ps.pkg.mVersionName);
-            pw.print(prefix); pw.print("  applicationInfo=");
-                pw.println(ps.pkg.applicationInfo.toString());
-            pw.print(prefix); pw.print("  flags="); printFlags(pw, ps.pkg.applicationInfo.flags,
-                    FLAG_DUMP_SPEC); pw.println();
-            pw.print(prefix); pw.print("  dataDir="); pw.println(ps.pkg.applicationInfo.dataDir);
-            if (ps.pkg.mOperationPending) {
-                pw.print(prefix); pw.println("  mOperationPending=true");
-            }
-            pw.print(prefix); pw.print("  supportsScreens=[");
-            boolean first = true;
-            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
-                if (!first)
-                    pw.print(", ");
-                first = false;
-                pw.print("small");
-            }
-            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) {
-                if (!first)
-                    pw.print(", ");
-                first = false;
-                pw.print("medium");
-            }
-            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
-                if (!first)
-                    pw.print(", ");
-                first = false;
-                pw.print("large");
-            }
-            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
-                if (!first)
-                    pw.print(", ");
-                first = false;
-                pw.print("xlarge");
-            }
-            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
-                if (!first)
-                    pw.print(", ");
-                first = false;
-                pw.print("resizeable");
-            }
-            if ((ps.pkg.applicationInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
-                if (!first)
-                    pw.print(", ");
-                first = false;
-                pw.print("anyDensity");
-            }
-            pw.println("]");
-            if (ps.pkg.libraryNames != null && ps.pkg.libraryNames.size() > 0) {
-                pw.print(prefix); pw.println("  libraries:");
-                for (int i=0; i<ps.pkg.libraryNames.size(); i++) {
-                    pw.print(prefix); pw.print("    "); pw.println(ps.pkg.libraryNames.get(i));
-                }
-            }
-            if (ps.pkg.usesLibraries != null && ps.pkg.usesLibraries.size() > 0) {
-                pw.print(prefix); pw.println("  usesLibraries:");
-                for (int i=0; i<ps.pkg.usesLibraries.size(); i++) {
-                    pw.print(prefix); pw.print("    "); pw.println(ps.pkg.usesLibraries.get(i));
-                }
-            }
-            if (ps.pkg.usesOptionalLibraries != null
-                    && ps.pkg.usesOptionalLibraries.size() > 0) {
-                pw.print(prefix); pw.println("  usesOptionalLibraries:");
-                for (int i=0; i<ps.pkg.usesOptionalLibraries.size(); i++) {
-                    pw.print(prefix); pw.print("    ");
-                        pw.println(ps.pkg.usesOptionalLibraries.get(i));
-                }
-            }
-            if (ps.pkg.usesLibraryFiles != null
-                    && ps.pkg.usesLibraryFiles.length > 0) {
-                pw.print(prefix); pw.println("  usesLibraryFiles:");
-                for (int i=0; i<ps.pkg.usesLibraryFiles.length; i++) {
-                    pw.print(prefix); pw.print("    "); pw.println(ps.pkg.usesLibraryFiles[i]);
-                }
-            }
-        }
-        pw.print(prefix); pw.print("  timeStamp=");
-            date.setTime(ps.timeStamp);
-            pw.println(sdf.format(date));
-        pw.print(prefix); pw.print("  firstInstallTime=");
-            date.setTime(ps.firstInstallTime);
-            pw.println(sdf.format(date));
-        pw.print(prefix); pw.print("  lastUpdateTime=");
-            date.setTime(ps.lastUpdateTime);
-            pw.println(sdf.format(date));
-        if (ps.installerPackageName != null) {
-            pw.print(prefix); pw.print("  installerPackageName=");
-                    pw.println(ps.installerPackageName);
-        }
-        pw.print(prefix); pw.print("  signatures="); pw.println(ps.signatures);
-        pw.print(prefix); pw.print("  permissionsFixed="); pw.print(ps.permissionsFixed);
-                pw.print(" haveGids="); pw.print(ps.haveGids);
-                pw.print(" installStatus="); pw.println(ps.installStatus);
-        pw.print(prefix); pw.print("  pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC);
-                pw.println();
-        for (UserInfo user : users) {
-            pw.print(prefix); pw.print("  User "); pw.print(user.id); pw.print(": ");
-            pw.print(" installed=");
-            pw.print(ps.getInstalled(user.id));
-            pw.print(" blocked=");
-            pw.print(ps.getBlocked(user.id));
-            pw.print(" stopped=");
-            pw.print(ps.getStopped(user.id));
-            pw.print(" notLaunched=");
-            pw.print(ps.getNotLaunched(user.id));
-            pw.print(" enabled=");
-            pw.println(ps.getEnabled(user.id));
-            String lastDisabledAppCaller = ps.getLastDisabledAppCaller(user.id);
-            if (lastDisabledAppCaller != null) {
-                pw.print(prefix); pw.print("    lastDisabledCaller: ");
-                        pw.println(lastDisabledAppCaller);
-            }
-            HashSet<String> cmp = ps.getDisabledComponents(user.id);
-            if (cmp != null && cmp.size() > 0) {
-                pw.print(prefix); pw.println("    disabledComponents:");
-                for (String s : cmp) {
-                    pw.print(prefix); pw.print("    "); pw.println(s);
-                }
-            }
-            cmp = ps.getEnabledComponents(user.id);
-            if (cmp != null && cmp.size() > 0) {
-                pw.print(prefix); pw.println("    enabledComponents:");
-                for (String s : cmp) {
-                    pw.print(prefix); pw.print("    "); pw.println(s);
-                }
-            }
-        }
-        if (ps.grantedPermissions.size() > 0) {
-            pw.print(prefix); pw.println("  grantedPermissions:");
-            for (String s : ps.grantedPermissions) {
-                pw.print(prefix); pw.print("    "); pw.println(s);
-            }
-        }
-    }
-
-    void dumpPackagesLPr(PrintWriter pw, String packageName, DumpState dumpState, boolean checkin) {
-        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        final Date date = new Date();
-        boolean printedSomething = false;
-        List<UserInfo> users = getAllUsers();
-        for (final PackageSetting ps : mPackages.values()) {
-            if (packageName != null && !packageName.equals(ps.realName)
-                    && !packageName.equals(ps.name)) {
-                continue;
-            }
-
-            if (!checkin && packageName != null) {
-                dumpState.setSharedUser(ps.sharedUser);
-            }
-
-            if (!checkin && !printedSomething) {
-                if (dumpState.onTitlePrinted())
-                    pw.println();
-                pw.println("Packages:");
-                printedSomething = true;
-            }
-            dumpPackageLPr(pw, "  ", checkin ? "pkg" : null, ps, sdf, date, users);
-        }
-
-        printedSomething = false;
-        if (!checkin && mRenamedPackages.size() > 0) {
-            for (final Map.Entry<String, String> e : mRenamedPackages.entrySet()) {
-                if (packageName != null && !packageName.equals(e.getKey())
-                        && !packageName.equals(e.getValue())) {
-                    continue;
-                }
-                if (!checkin) {
-                    if (!printedSomething) {
-                        if (dumpState.onTitlePrinted())
-                            pw.println();
-                        pw.println("Renamed packages:");
-                        printedSomething = true;
-                    }
-                    pw.print("  ");
-                } else {
-                    pw.print("ren,");
-                }
-                pw.print(e.getKey());
-                pw.print(checkin ? " -> " : ",");
-                pw.println(e.getValue());
-            }
-        }
-
-        printedSomething = false;
-        if (mDisabledSysPackages.size() > 0) {
-            for (final PackageSetting ps : mDisabledSysPackages.values()) {
-                if (packageName != null && !packageName.equals(ps.realName)
-                        && !packageName.equals(ps.name)) {
-                    continue;
-                }
-                if (!checkin && !printedSomething) {
-                    if (dumpState.onTitlePrinted())
-                        pw.println();
-                    pw.println("Hidden system packages:");
-                    printedSomething = true;
-                }
-                dumpPackageLPr(pw, "  ", checkin ? "dis" : null, ps, sdf, date, users);
-            }
-        }
-    }
-
-    void dumpPermissionsLPr(PrintWriter pw, String packageName, DumpState dumpState) {
-        boolean printedSomething = false;
-        for (BasePermission p : mPermissions.values()) {
-            if (packageName != null && !packageName.equals(p.sourcePackage)) {
-                continue;
-            }
-            if (!printedSomething) {
-                if (dumpState.onTitlePrinted())
-                    pw.println();
-                pw.println("Permissions:");
-                printedSomething = true;
-            }
-            pw.print("  Permission ["); pw.print(p.name); pw.print("] (");
-                    pw.print(Integer.toHexString(System.identityHashCode(p)));
-                    pw.println("):");
-            pw.print("    sourcePackage="); pw.println(p.sourcePackage);
-            pw.print("    uid="); pw.print(p.uid);
-                    pw.print(" gids="); pw.print(PackageManagerService.arrayToString(p.gids));
-                    pw.print(" type="); pw.print(p.type);
-                    pw.print(" prot=");
-                    pw.println(PermissionInfo.protectionToString(p.protectionLevel));
-            if (p.packageSetting != null) {
-                pw.print("    packageSetting="); pw.println(p.packageSetting);
-            }
-            if (p.perm != null) {
-                pw.print("    perm="); pw.println(p.perm);
-            }
-            if (READ_EXTERNAL_STORAGE.equals(p.name)) {
-                pw.print("    enforced=");
-                pw.println(mReadExternalStorageEnforced);
-            }
-        }
-    }
-
-    void dumpSharedUsersLPr(PrintWriter pw, String packageName, DumpState dumpState) {
-        boolean printedSomething = false;
-        for (SharedUserSetting su : mSharedUsers.values()) {
-            if (packageName != null && su != dumpState.getSharedUser()) {
-                continue;
-            }
-            if (!printedSomething) {
-                if (dumpState.onTitlePrinted())
-                    pw.println();
-                pw.println("Shared users:");
-                printedSomething = true;
-            }
-            pw.print("  SharedUser [");
-            pw.print(su.name);
-            pw.print("] (");
-            pw.print(Integer.toHexString(System.identityHashCode(su)));
-                    pw.println("):");
-            pw.print("    userId=");
-            pw.print(su.userId);
-            pw.print(" gids=");
-            pw.println(PackageManagerService.arrayToString(su.gids));
-            pw.println("    grantedPermissions:");
-            for (String s : su.grantedPermissions) {
-                pw.print("      ");
-                pw.println(s);
-            }
-        }
-    }
-
-    void dumpReadMessagesLPr(PrintWriter pw, DumpState dumpState) {
-        pw.println("Settings parse messages:");
-        pw.print(mReadMessages.toString());
-    }
-}
diff --git a/services/java/com/android/server/power/DisplayPowerController.java b/services/java/com/android/server/power/DisplayPowerController.java
deleted file mode 100644
index 30bc922..0000000
--- a/services/java/com/android/server/power/DisplayPowerController.java
+++ /dev/null
@@ -1,1381 +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.server.power;
-
-import com.android.server.LightsService;
-import com.android.server.TwilightService;
-import com.android.server.TwilightService.TwilightState;
-import com.android.server.display.DisplayManagerService;
-
-import android.animation.Animator;
-import android.animation.ObjectAnimator;
-import android.content.Context;
-import android.content.res.Resources;
-import android.hardware.Sensor;
-import android.hardware.SensorEvent;
-import android.hardware.SensorEventListener;
-import android.hardware.SensorManager;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.os.PowerManager;
-import android.os.SystemClock;
-import android.text.format.DateUtils;
-import android.util.FloatMath;
-import android.util.Slog;
-import android.util.Spline;
-import android.util.TimeUtils;
-
-import java.io.PrintWriter;
-
-/**
- * Controls the power state of the display.
- *
- * Handles the proximity sensor, light sensor, and animations between states
- * including the screen off animation.
- *
- * This component acts independently of the rest of the power manager service.
- * In particular, it does not share any state and it only communicates
- * via asynchronous callbacks to inform the power manager that something has
- * changed.
- *
- * Everything this class does internally is serialized on its handler although
- * it may be accessed by other threads from the outside.
- *
- * Note that the power manager service guarantees that it will hold a suspend
- * blocker as long as the display is not ready.  So most of the work done here
- * does not need to worry about holding a suspend blocker unless it happens
- * independently of the display ready signal.
- *
- * For debugging, you can make the electron beam and brightness animations run
- * slower by changing the "animator duration scale" option in Development Settings.
- */
-final class DisplayPowerController {
-    private static final String TAG = "DisplayPowerController";
-
-    private static boolean DEBUG = false;
-    private static final boolean DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT = false;
-    private static final boolean DEBUG_PRETEND_LIGHT_SENSOR_ABSENT = false;
-
-    // If true, uses the electron beam on animation.
-    // We might want to turn this off if we cannot get a guarantee that the screen
-    // actually turns on and starts showing new content after the call to set the
-    // screen state returns.  Playing the animation can also be somewhat slow.
-    private static final boolean USE_ELECTRON_BEAM_ON_ANIMATION = false;
-
-    // If true, enables the use of the screen auto-brightness adjustment setting.
-    private static final boolean USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT =
-            PowerManager.useScreenAutoBrightnessAdjustmentFeature();
-
-    // The maximum range of gamma adjustment possible using the screen
-    // auto-brightness adjustment setting.
-    private static final float SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA = 3.0f;
-
-    // The minimum reduction in brightness when dimmed.
-    private static final int SCREEN_DIM_MINIMUM_REDUCTION = 10;
-
-    // If true, enables the use of the current time as an auto-brightness adjustment.
-    // The basic idea here is to expand the dynamic range of auto-brightness
-    // when it is especially dark outside.  The light sensor tends to perform
-    // poorly at low light levels so we compensate for it by making an
-    // assumption about the environment.
-    private static final boolean USE_TWILIGHT_ADJUSTMENT =
-            PowerManager.useTwilightAdjustmentFeature();
-
-    // Specifies the maximum magnitude of the time of day adjustment.
-    private static final float TWILIGHT_ADJUSTMENT_MAX_GAMMA = 1.5f;
-
-    // The amount of time after or before sunrise over which to start adjusting
-    // the gamma.  We want the change to happen gradually so that it is below the
-    // threshold of perceptibility and so that the adjustment has maximum effect
-    // well after dusk.
-    private static final long TWILIGHT_ADJUSTMENT_TIME = DateUtils.HOUR_IN_MILLIS * 2;
-
-    private static final int ELECTRON_BEAM_ON_ANIMATION_DURATION_MILLIS = 250;
-    private static final int ELECTRON_BEAM_OFF_ANIMATION_DURATION_MILLIS = 400;
-
-    private static final int MSG_UPDATE_POWER_STATE = 1;
-    private static final int MSG_PROXIMITY_SENSOR_DEBOUNCED = 2;
-    private static final int MSG_LIGHT_SENSOR_DEBOUNCED = 3;
-
-    private static final int PROXIMITY_UNKNOWN = -1;
-    private static final int PROXIMITY_NEGATIVE = 0;
-    private static final int PROXIMITY_POSITIVE = 1;
-
-    // Proximity sensor debounce delay in milliseconds for positive or negative transitions.
-    private static final int PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY = 0;
-    private static final int PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY = 250;
-
-    // Trigger proximity if distance is less than 5 cm.
-    private static final float TYPICAL_PROXIMITY_THRESHOLD = 5.0f;
-
-    // Light sensor event rate in milliseconds.
-    private static final int LIGHT_SENSOR_RATE_MILLIS = 1000;
-
-    // A rate for generating synthetic light sensor events in the case where the light
-    // sensor hasn't reported any new data in a while and we need it to update the
-    // debounce filter.  We only synthesize light sensor measurements when needed.
-    private static final int SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS =
-            LIGHT_SENSOR_RATE_MILLIS * 2;
-
-    // Brightness animation ramp rate in brightness units per second.
-    private static final int BRIGHTNESS_RAMP_RATE_FAST = 200;
-    private static final int BRIGHTNESS_RAMP_RATE_SLOW = 40;
-
-    // IIR filter time constants in milliseconds for computing two moving averages of
-    // the light samples.  One is a long-term average and the other is a short-term average.
-    // We can use these filters to assess trends in ambient brightness.
-    // The short term average gives us a filtered but relatively low latency measurement.
-    // The long term average informs us about the overall trend.
-    private static final long SHORT_TERM_AVERAGE_LIGHT_TIME_CONSTANT = 1000;
-    private static final long LONG_TERM_AVERAGE_LIGHT_TIME_CONSTANT = 5000;
-
-    // Stability requirements in milliseconds for accepting a new brightness
-    // level.  This is used for debouncing the light sensor.  Different constants
-    // are used to debounce the light sensor when adapting to brighter or darker environments.
-    // This parameter controls how quickly brightness changes occur in response to
-    // an observed change in light level that exceeds the hysteresis threshold.
-    private static final long BRIGHTENING_LIGHT_DEBOUNCE = 4000;
-    private static final long DARKENING_LIGHT_DEBOUNCE = 8000;
-
-    // Hysteresis constraints for brightening or darkening.
-    // The recent lux must have changed by at least this fraction relative to the
-    // current ambient lux before a change will be considered.
-    private static final float BRIGHTENING_LIGHT_HYSTERESIS = 0.10f;
-    private static final float DARKENING_LIGHT_HYSTERESIS = 0.20f;
-
-    private final Object mLock = new Object();
-
-    // Notifier for sending asynchronous notifications.
-    private final Notifier mNotifier;
-
-    // The display suspend blocker.
-    // Held while there are pending state change notifications.
-    private final SuspendBlocker mDisplaySuspendBlocker;
-
-    // The display blanker.
-    private final DisplayBlanker mDisplayBlanker;
-
-    // Our handler.
-    private final DisplayControllerHandler mHandler;
-
-    // Asynchronous callbacks into the power manager service.
-    // Only invoked from the handler thread while no locks are held.
-    private final Callbacks mCallbacks;
-    private Handler mCallbackHandler;
-
-    // The lights service.
-    private final LightsService mLights;
-
-    // The twilight service.
-    private final TwilightService mTwilight;
-
-    // The display manager.
-    private final DisplayManagerService mDisplayManager;
-
-    // The sensor manager.
-    private final SensorManager mSensorManager;
-
-    // The proximity sensor, or null if not available or needed.
-    private Sensor mProximitySensor;
-
-    // The light sensor, or null if not available or needed.
-    private Sensor mLightSensor;
-
-    // The dim screen brightness.
-    private final int mScreenBrightnessDimConfig;
-
-    // The minimum allowed brightness.
-    private final int mScreenBrightnessRangeMinimum;
-
-    // The maximum allowed brightness.
-    private final int mScreenBrightnessRangeMaximum;
-
-    // True if auto-brightness should be used.
-    private boolean mUseSoftwareAutoBrightnessConfig;
-
-    // The auto-brightness spline adjustment.
-    // The brightness values have been scaled to a range of 0..1.
-    private Spline mScreenAutoBrightnessSpline;
-
-    // Amount of time to delay auto-brightness after screen on while waiting for
-    // the light sensor to warm-up in milliseconds.
-    // May be 0 if no warm-up is required.
-    private int mLightSensorWarmUpTimeConfig;
-
-    // True if we should fade the screen while turning it off, false if we should play
-    // a stylish electron beam animation instead.
-    private boolean mElectronBeamFadesConfig;
-
-    // The pending power request.
-    // Initially null until the first call to requestPowerState.
-    // Guarded by mLock.
-    private DisplayPowerRequest mPendingRequestLocked;
-
-    // True if a request has been made to wait for the proximity sensor to go negative.
-    // Guarded by mLock.
-    private boolean mPendingWaitForNegativeProximityLocked;
-
-    // True if the pending power request or wait for negative proximity flag
-    // has been changed since the last update occurred.
-    // Guarded by mLock.
-    private boolean mPendingRequestChangedLocked;
-
-    // Set to true when the important parts of the pending power request have been applied.
-    // The important parts are mainly the screen state.  Brightness changes may occur
-    // concurrently.
-    // Guarded by mLock.
-    private boolean mDisplayReadyLocked;
-
-    // Set to true if a power state update is required.
-    // Guarded by mLock.
-    private boolean mPendingUpdatePowerStateLocked;
-
-    /* The following state must only be accessed by the handler thread. */
-
-    // The currently requested power state.
-    // The power controller will progressively update its internal state to match
-    // the requested power state.  Initially null until the first update.
-    private DisplayPowerRequest mPowerRequest;
-
-    // The current power state.
-    // Must only be accessed on the handler thread.
-    private DisplayPowerState mPowerState;
-
-    // True if the device should wait for negative proximity sensor before
-    // waking up the screen.  This is set to false as soon as a negative
-    // proximity sensor measurement is observed or when the device is forced to
-    // go to sleep by the user.  While true, the screen remains off.
-    private boolean mWaitingForNegativeProximity;
-
-    // The actual proximity sensor threshold value.
-    private float mProximityThreshold;
-
-    // Set to true if the proximity sensor listener has been registered
-    // with the sensor manager.
-    private boolean mProximitySensorEnabled;
-
-    // The debounced proximity sensor state.
-    private int mProximity = PROXIMITY_UNKNOWN;
-
-    // The raw non-debounced proximity sensor state.
-    private int mPendingProximity = PROXIMITY_UNKNOWN;
-    private long mPendingProximityDebounceTime = -1; // -1 if fully debounced
-
-    // True if the screen was turned off because of the proximity sensor.
-    // When the screen turns on again, we report user activity to the power manager.
-    private boolean mScreenOffBecauseOfProximity;
-
-    // True if the screen on is being blocked.
-    private boolean mScreenOnWasBlocked;
-
-    // The elapsed real time when the screen on was blocked.
-    private long mScreenOnBlockStartRealTime;
-
-    // Set to true if the light sensor is enabled.
-    private boolean mLightSensorEnabled;
-
-    // The time when the light sensor was enabled.
-    private long mLightSensorEnableTime;
-
-    // The currently accepted nominal ambient light level.
-    private float mAmbientLux;
-
-    // True if mAmbientLux holds a valid value.
-    private boolean mAmbientLuxValid;
-
-    // The ambient light level threshold at which to brighten or darken the screen.
-    private float mBrighteningLuxThreshold;
-    private float mDarkeningLuxThreshold;
-
-    // The most recent light sample.
-    private float mLastObservedLux;
-
-    // The time of the most light recent sample.
-    private long mLastObservedLuxTime;
-
-    // The number of light samples collected since the light sensor was enabled.
-    private int mRecentLightSamples;
-
-    // The long-term and short-term filtered light measurements.
-    private float mRecentShortTermAverageLux;
-    private float mRecentLongTermAverageLux;
-
-    // The direction in which the average lux is moving relative to the current ambient lux.
-    //    0 if not changing or within hysteresis threshold.
-    //    1 if brightening beyond hysteresis threshold.
-    //   -1 if darkening beyond hysteresis threshold.
-    private int mDebounceLuxDirection;
-
-    // The time when the average lux last changed direction.
-    private long mDebounceLuxTime;
-
-    // The screen brightness level that has been chosen by the auto-brightness
-    // algorithm.  The actual brightness should ramp towards this value.
-    // We preserve this value even when we stop using the light sensor so
-    // that we can quickly revert to the previous auto-brightness level
-    // while the light sensor warms up.
-    // Use -1 if there is no current auto-brightness value available.
-    private int mScreenAutoBrightness = -1;
-
-    // The last screen auto-brightness gamma.  (For printing in dump() only.)
-    private float mLastScreenAutoBrightnessGamma = 1.0f;
-
-    // True if the screen auto-brightness value is actually being used to
-    // set the display brightness.
-    private boolean mUsingScreenAutoBrightness;
-
-    // Animators.
-    private ObjectAnimator mElectronBeamOnAnimator;
-    private ObjectAnimator mElectronBeamOffAnimator;
-    private RampAnimator<DisplayPowerState> mScreenBrightnessRampAnimator;
-
-    // Twilight changed.  We might recalculate auto-brightness values.
-    private boolean mTwilightChanged;
-
-    /**
-     * Creates the display power controller.
-     */
-    public DisplayPowerController(Looper looper, Context context, Notifier notifier,
-            LightsService lights, TwilightService twilight, SensorManager sensorManager,
-            DisplayManagerService displayManager,
-            SuspendBlocker displaySuspendBlocker, DisplayBlanker displayBlanker,
-            Callbacks callbacks, Handler callbackHandler) {
-        mHandler = new DisplayControllerHandler(looper);
-        mNotifier = notifier;
-        mDisplaySuspendBlocker = displaySuspendBlocker;
-        mDisplayBlanker = displayBlanker;
-        mCallbacks = callbacks;
-        mCallbackHandler = callbackHandler;
-
-        mLights = lights;
-        mTwilight = twilight;
-        mSensorManager = sensorManager;
-        mDisplayManager = displayManager;
-
-        final Resources resources = context.getResources();
-
-        mScreenBrightnessDimConfig = clampAbsoluteBrightness(resources.getInteger(
-                com.android.internal.R.integer.config_screenBrightnessDim));
-
-        int screenBrightnessMinimum = Math.min(resources.getInteger(
-                com.android.internal.R.integer.config_screenBrightnessSettingMinimum),
-                mScreenBrightnessDimConfig);
-
-        mUseSoftwareAutoBrightnessConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_automatic_brightness_available);
-        if (mUseSoftwareAutoBrightnessConfig) {
-            int[] lux = resources.getIntArray(
-                    com.android.internal.R.array.config_autoBrightnessLevels);
-            int[] screenBrightness = resources.getIntArray(
-                    com.android.internal.R.array.config_autoBrightnessLcdBacklightValues);
-
-            mScreenAutoBrightnessSpline = createAutoBrightnessSpline(lux, screenBrightness);
-            if (mScreenAutoBrightnessSpline == null) {
-                Slog.e(TAG, "Error in config.xml.  config_autoBrightnessLcdBacklightValues "
-                        + "(size " + screenBrightness.length + ") "
-                        + "must be monotic and have exactly one more entry than "
-                        + "config_autoBrightnessLevels (size " + lux.length + ") "
-                        + "which must be strictly increasing.  "
-                        + "Auto-brightness will be disabled.");
-                mUseSoftwareAutoBrightnessConfig = false;
-            } else {
-                if (screenBrightness[0] < screenBrightnessMinimum) {
-                    screenBrightnessMinimum = screenBrightness[0];
-                }
-            }
-
-            mLightSensorWarmUpTimeConfig = resources.getInteger(
-                    com.android.internal.R.integer.config_lightSensorWarmupTime);
-        }
-
-        mScreenBrightnessRangeMinimum = clampAbsoluteBrightness(screenBrightnessMinimum);
-        mScreenBrightnessRangeMaximum = PowerManager.BRIGHTNESS_ON;
-
-        mElectronBeamFadesConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_animateScreenLights);
-
-        if (!DEBUG_PRETEND_PROXIMITY_SENSOR_ABSENT) {
-            mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
-            if (mProximitySensor != null) {
-                mProximityThreshold = Math.min(mProximitySensor.getMaximumRange(),
-                        TYPICAL_PROXIMITY_THRESHOLD);
-            }
-        }
-
-        if (mUseSoftwareAutoBrightnessConfig
-                && !DEBUG_PRETEND_LIGHT_SENSOR_ABSENT) {
-            mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
-        }
-
-        if (mUseSoftwareAutoBrightnessConfig && USE_TWILIGHT_ADJUSTMENT) {
-            mTwilight.registerListener(mTwilightListener, mHandler);
-        }
-    }
-
-    private static Spline createAutoBrightnessSpline(int[] lux, int[] brightness) {
-        try {
-            final int n = brightness.length;
-            float[] x = new float[n];
-            float[] y = new float[n];
-            y[0] = normalizeAbsoluteBrightness(brightness[0]);
-            for (int i = 1; i < n; i++) {
-                x[i] = lux[i - 1];
-                y[i] = normalizeAbsoluteBrightness(brightness[i]);
-            }
-
-            Spline spline = Spline.createMonotoneCubicSpline(x, y);
-            if (DEBUG) {
-                Slog.d(TAG, "Auto-brightness spline: " + spline);
-                for (float v = 1f; v < lux[lux.length - 1] * 1.25f; v *= 1.25f) {
-                    Slog.d(TAG, String.format("  %7.1f: %7.1f", v, spline.interpolate(v)));
-                }
-            }
-            return spline;
-        } catch (IllegalArgumentException ex) {
-            Slog.e(TAG, "Could not create auto-brightness spline.", ex);
-            return null;
-        }
-    }
-
-    /**
-     * Returns true if the proximity sensor screen-off function is available.
-     */
-    public boolean isProximitySensorAvailable() {
-        return mProximitySensor != null;
-    }
-
-    /**
-     * Requests a new power state.
-     * The controller makes a copy of the provided object and then
-     * begins adjusting the power state to match what was requested.
-     *
-     * @param request The requested power state.
-     * @param waitForNegativeProximity If true, issues a request to wait for
-     * negative proximity before turning the screen back on, assuming the screen
-     * was turned off by the proximity sensor.
-     * @return True if display is ready, false if there are important changes that must
-     * be made asynchronously (such as turning the screen on), in which case the caller
-     * should grab a wake lock, watch for {@link Callbacks#onStateChanged()} then try
-     * the request again later until the state converges.
-     */
-    public boolean requestPowerState(DisplayPowerRequest request,
-            boolean waitForNegativeProximity) {
-        if (DEBUG) {
-            Slog.d(TAG, "requestPowerState: "
-                    + request + ", waitForNegativeProximity=" + waitForNegativeProximity);
-        }
-
-        synchronized (mLock) {
-            boolean changed = false;
-
-            if (waitForNegativeProximity
-                    && !mPendingWaitForNegativeProximityLocked) {
-                mPendingWaitForNegativeProximityLocked = true;
-                changed = true;
-            }
-
-            if (mPendingRequestLocked == null) {
-                mPendingRequestLocked = new DisplayPowerRequest(request);
-                changed = true;
-            } else if (!mPendingRequestLocked.equals(request)) {
-                mPendingRequestLocked.copyFrom(request);
-                changed = true;
-            }
-
-            if (changed) {
-                mDisplayReadyLocked = false;
-            }
-
-            if (changed && !mPendingRequestChangedLocked) {
-                mPendingRequestChangedLocked = true;
-                sendUpdatePowerStateLocked();
-            }
-
-            return mDisplayReadyLocked;
-        }
-    }
-
-    private void sendUpdatePowerState() {
-        synchronized (mLock) {
-            sendUpdatePowerStateLocked();
-        }
-    }
-
-    private void sendUpdatePowerStateLocked() {
-        if (!mPendingUpdatePowerStateLocked) {
-            mPendingUpdatePowerStateLocked = true;
-            Message msg = mHandler.obtainMessage(MSG_UPDATE_POWER_STATE);
-            msg.setAsynchronous(true);
-            mHandler.sendMessage(msg);
-        }
-    }
-
-    private void initialize() {
-        mPowerState = new DisplayPowerState(
-                new ElectronBeam(mDisplayManager), mDisplayBlanker,
-                mLights.getLight(LightsService.LIGHT_ID_BACKLIGHT));
-
-        mElectronBeamOnAnimator = ObjectAnimator.ofFloat(
-                mPowerState, DisplayPowerState.ELECTRON_BEAM_LEVEL, 0.0f, 1.0f);
-        mElectronBeamOnAnimator.setDuration(ELECTRON_BEAM_ON_ANIMATION_DURATION_MILLIS);
-        mElectronBeamOnAnimator.addListener(mAnimatorListener);
-
-        mElectronBeamOffAnimator = ObjectAnimator.ofFloat(
-                mPowerState, DisplayPowerState.ELECTRON_BEAM_LEVEL, 1.0f, 0.0f);
-        mElectronBeamOffAnimator.setDuration(ELECTRON_BEAM_OFF_ANIMATION_DURATION_MILLIS);
-        mElectronBeamOffAnimator.addListener(mAnimatorListener);
-
-        mScreenBrightnessRampAnimator = new RampAnimator<DisplayPowerState>(
-                mPowerState, DisplayPowerState.SCREEN_BRIGHTNESS);
-    }
-
-    private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() {
-        @Override
-        public void onAnimationStart(Animator animation) {
-        }
-        @Override
-        public void onAnimationEnd(Animator animation) {
-            sendUpdatePowerState();
-        }
-        @Override
-        public void onAnimationRepeat(Animator animation) {
-        }
-        @Override
-        public void onAnimationCancel(Animator animation) {
-        }
-    };
-
-    private void updatePowerState() {
-        // Update the power state request.
-        final boolean mustNotify;
-        boolean mustInitialize = false;
-        boolean updateAutoBrightness = mTwilightChanged;
-        boolean wasDim = false;
-        mTwilightChanged = false;
-
-        synchronized (mLock) {
-            mPendingUpdatePowerStateLocked = false;
-            if (mPendingRequestLocked == null) {
-                return; // wait until first actual power request
-            }
-
-            if (mPowerRequest == null) {
-                mPowerRequest = new DisplayPowerRequest(mPendingRequestLocked);
-                mWaitingForNegativeProximity = mPendingWaitForNegativeProximityLocked;
-                mPendingWaitForNegativeProximityLocked = false;
-                mPendingRequestChangedLocked = false;
-                mustInitialize = true;
-            } else if (mPendingRequestChangedLocked) {
-                if (mPowerRequest.screenAutoBrightnessAdjustment
-                        != mPendingRequestLocked.screenAutoBrightnessAdjustment) {
-                    updateAutoBrightness = true;
-                }
-                wasDim = (mPowerRequest.screenState == DisplayPowerRequest.SCREEN_STATE_DIM);
-                mPowerRequest.copyFrom(mPendingRequestLocked);
-                mWaitingForNegativeProximity |= mPendingWaitForNegativeProximityLocked;
-                mPendingWaitForNegativeProximityLocked = false;
-                mPendingRequestChangedLocked = false;
-                mDisplayReadyLocked = false;
-            }
-
-            mustNotify = !mDisplayReadyLocked;
-        }
-
-        // Initialize things the first time the power state is changed.
-        if (mustInitialize) {
-            initialize();
-        }
-
-        // Apply the proximity sensor.
-        if (mProximitySensor != null) {
-            if (mPowerRequest.useProximitySensor
-                    && mPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
-                setProximitySensorEnabled(true);
-                if (!mScreenOffBecauseOfProximity
-                        && mProximity == PROXIMITY_POSITIVE) {
-                    mScreenOffBecauseOfProximity = true;
-                    sendOnProximityPositiveWithWakelock();
-                }
-            } else if (mWaitingForNegativeProximity
-                    && mScreenOffBecauseOfProximity
-                    && mProximity == PROXIMITY_POSITIVE
-                    && mPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
-                setProximitySensorEnabled(true);
-            } else {
-                setProximitySensorEnabled(false);
-                mWaitingForNegativeProximity = false;
-            }
-            if (mScreenOffBecauseOfProximity
-                    && mProximity != PROXIMITY_POSITIVE) {
-                mScreenOffBecauseOfProximity = false;
-                sendOnProximityNegativeWithWakelock();
-            }
-        } else {
-            mWaitingForNegativeProximity = false;
-        }
-
-        // Turn on the light sensor if needed.
-        if (mLightSensor != null) {
-            setLightSensorEnabled(mPowerRequest.useAutoBrightness
-                    && wantScreenOn(mPowerRequest.screenState), updateAutoBrightness);
-        }
-
-        // Set the screen brightness.
-        if (wantScreenOn(mPowerRequest.screenState)) {
-            int target;
-            boolean slow;
-            if (mScreenAutoBrightness >= 0 && mLightSensorEnabled) {
-                // Use current auto-brightness value.
-                target = mScreenAutoBrightness;
-                slow = mUsingScreenAutoBrightness;
-                mUsingScreenAutoBrightness = true;
-            } else {
-                // Light sensor is disabled or not ready yet.
-                // Use the current brightness setting from the request, which is expected
-                // provide a nominal default value for the case where auto-brightness
-                // is not ready yet.
-                target = mPowerRequest.screenBrightness;
-                slow = false;
-                mUsingScreenAutoBrightness = false;
-            }
-            if (mPowerRequest.screenState == DisplayPowerRequest.SCREEN_STATE_DIM) {
-                // Dim quickly by at least some minimum amount.
-                target = Math.min(target - SCREEN_DIM_MINIMUM_REDUCTION,
-                        mScreenBrightnessDimConfig);
-                slow = false;
-            } else if (wasDim) {
-                // Brighten quickly.
-                slow = false;
-            }
-            animateScreenBrightness(clampScreenBrightness(target),
-                    slow ? BRIGHTNESS_RAMP_RATE_SLOW : BRIGHTNESS_RAMP_RATE_FAST);
-        } else {
-            // Screen is off.  Don't bother changing the brightness.
-            mUsingScreenAutoBrightness = false;
-        }
-
-        // Animate the screen on or off unless blocked.
-        if (mScreenOffBecauseOfProximity) {
-            // Screen off due to proximity.
-            setScreenOn(false);
-            unblockScreenOn();
-        } else if (wantScreenOn(mPowerRequest.screenState)) {
-            // Want screen on.
-            // Wait for previous off animation to complete beforehand.
-            // It is relatively short but if we cancel it and switch to the
-            // on animation immediately then the results are pretty ugly.
-            if (!mElectronBeamOffAnimator.isStarted()) {
-                // Turn the screen on.  The contents of the screen may not yet
-                // be visible if the electron beam has not been dismissed because
-                // its last frame of animation is solid black.
-                setScreenOn(true);
-
-                if (mPowerRequest.blockScreenOn
-                        && mPowerState.getElectronBeamLevel() == 0.0f) {
-                    blockScreenOn();
-                } else {
-                    unblockScreenOn();
-                    if (USE_ELECTRON_BEAM_ON_ANIMATION) {
-                        if (!mElectronBeamOnAnimator.isStarted()) {
-                            if (mPowerState.getElectronBeamLevel() == 1.0f) {
-                                mPowerState.dismissElectronBeam();
-                            } else if (mPowerState.prepareElectronBeam(
-                                    mElectronBeamFadesConfig ?
-                                            ElectronBeam.MODE_FADE :
-                                                    ElectronBeam.MODE_WARM_UP)) {
-                                mElectronBeamOnAnimator.start();
-                            } else {
-                                mElectronBeamOnAnimator.end();
-                            }
-                        }
-                    } else {
-                        mPowerState.setElectronBeamLevel(1.0f);
-                        mPowerState.dismissElectronBeam();
-                    }
-                }
-            }
-        } else {
-            // Want screen off.
-            // Wait for previous on animation to complete beforehand.
-            unblockScreenOn();
-            if (!mElectronBeamOnAnimator.isStarted()) {
-                if (!mElectronBeamOffAnimator.isStarted()) {
-                    if (mPowerState.getElectronBeamLevel() == 0.0f) {
-                        setScreenOn(false);
-                    } else if (mPowerState.prepareElectronBeam(
-                            mElectronBeamFadesConfig ?
-                                    ElectronBeam.MODE_FADE :
-                                            ElectronBeam.MODE_COOL_DOWN)
-                            && mPowerState.isScreenOn()) {
-                        mElectronBeamOffAnimator.start();
-                    } else {
-                        mElectronBeamOffAnimator.end();
-                    }
-                }
-            }
-        }
-
-        // Report whether the display is ready for use.
-        // We mostly care about the screen state here, ignoring brightness changes
-        // which will be handled asynchronously.
-        if (mustNotify
-                && !mScreenOnWasBlocked
-                && !mElectronBeamOnAnimator.isStarted()
-                && !mElectronBeamOffAnimator.isStarted()
-                && mPowerState.waitUntilClean(mCleanListener)) {
-            synchronized (mLock) {
-                if (!mPendingRequestChangedLocked) {
-                    mDisplayReadyLocked = true;
-
-                    if (DEBUG) {
-                        Slog.d(TAG, "Display ready!");
-                    }
-                }
-            }
-            sendOnStateChangedWithWakelock();
-        }
-    }
-
-    private void blockScreenOn() {
-        if (!mScreenOnWasBlocked) {
-            mScreenOnWasBlocked = true;
-            if (DEBUG) {
-                Slog.d(TAG, "Blocked screen on.");
-                mScreenOnBlockStartRealTime = SystemClock.elapsedRealtime();
-            }
-        }
-    }
-
-    private void unblockScreenOn() {
-        if (mScreenOnWasBlocked) {
-            mScreenOnWasBlocked = false;
-            long delay = SystemClock.elapsedRealtime() - mScreenOnBlockStartRealTime;
-            if (delay > 1000 || DEBUG) {
-                Slog.d(TAG, "Unblocked screen on after " + delay + " ms");
-            }
-        }
-    }
-
-    private void setScreenOn(boolean on) {
-        if (mPowerState.isScreenOn() != on) {
-            mPowerState.setScreenOn(on);
-            if (on) {
-                mNotifier.onScreenOn();
-            } else {
-                mNotifier.onScreenOff();
-            }
-        }
-    }
-
-    private int clampScreenBrightness(int value) {
-        return clamp(value, mScreenBrightnessRangeMinimum, mScreenBrightnessRangeMaximum);
-    }
-
-    private static int clampAbsoluteBrightness(int value) {
-        return clamp(value, PowerManager.BRIGHTNESS_OFF, PowerManager.BRIGHTNESS_ON);
-    }
-
-    private static int clamp(int value, int min, int max) {
-        if (value <= min) {
-            return min;
-        }
-        if (value >= max) {
-            return max;
-        }
-        return value;
-    }
-
-    private static float normalizeAbsoluteBrightness(int value) {
-        return (float)clampAbsoluteBrightness(value) / PowerManager.BRIGHTNESS_ON;
-    }
-
-    private void animateScreenBrightness(int target, int rate) {
-        if (mScreenBrightnessRampAnimator.animateTo(target, rate)) {
-            mNotifier.onScreenBrightness(target);
-        }
-    }
-
-    private final Runnable mCleanListener = new Runnable() {
-        @Override
-        public void run() {
-            sendUpdatePowerState();
-        }
-    };
-
-    private void setProximitySensorEnabled(boolean enable) {
-        if (enable) {
-            if (!mProximitySensorEnabled) {
-                // Register the listener.
-                // Proximity sensor state already cleared initially.
-                mProximitySensorEnabled = true;
-                mSensorManager.registerListener(mProximitySensorListener, mProximitySensor,
-                        SensorManager.SENSOR_DELAY_NORMAL, mHandler);
-            }
-        } else {
-            if (mProximitySensorEnabled) {
-                // Unregister the listener.
-                // Clear the proximity sensor state for next time.
-                mProximitySensorEnabled = false;
-                mProximity = PROXIMITY_UNKNOWN;
-                mPendingProximity = PROXIMITY_UNKNOWN;
-                mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
-                mSensorManager.unregisterListener(mProximitySensorListener);
-                clearPendingProximityDebounceTime(); // release wake lock (must be last)
-            }
-        }
-    }
-
-    private void handleProximitySensorEvent(long time, boolean positive) {
-        if (mProximitySensorEnabled) {
-            if (mPendingProximity == PROXIMITY_NEGATIVE && !positive) {
-                return; // no change
-            }
-            if (mPendingProximity == PROXIMITY_POSITIVE && positive) {
-                return; // no change
-            }
-
-            // Only accept a proximity sensor reading if it remains
-            // stable for the entire debounce delay.  We hold a wake lock while
-            // debouncing the sensor.
-            mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
-            if (positive) {
-                mPendingProximity = PROXIMITY_POSITIVE;
-                setPendingProximityDebounceTime(
-                        time + PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY); // acquire wake lock
-            } else {
-                mPendingProximity = PROXIMITY_NEGATIVE;
-                setPendingProximityDebounceTime(
-                        time + PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY); // acquire wake lock
-            }
-
-            // Debounce the new sensor reading.
-            debounceProximitySensor();
-        }
-    }
-
-    private void debounceProximitySensor() {
-        if (mProximitySensorEnabled
-                && mPendingProximity != PROXIMITY_UNKNOWN
-                && mPendingProximityDebounceTime >= 0) {
-            final long now = SystemClock.uptimeMillis();
-            if (mPendingProximityDebounceTime <= now) {
-                // Sensor reading accepted.  Apply the change then release the wake lock.
-                mProximity = mPendingProximity;
-                updatePowerState();
-                clearPendingProximityDebounceTime(); // release wake lock (must be last)
-            } else {
-                // Need to wait a little longer.
-                // Debounce again later.  We continue holding a wake lock while waiting.
-                Message msg = mHandler.obtainMessage(MSG_PROXIMITY_SENSOR_DEBOUNCED);
-                msg.setAsynchronous(true);
-                mHandler.sendMessageAtTime(msg, mPendingProximityDebounceTime);
-            }
-        }
-    }
-
-    private void clearPendingProximityDebounceTime() {
-        if (mPendingProximityDebounceTime >= 0) {
-            mPendingProximityDebounceTime = -1;
-            mDisplaySuspendBlocker.release(); // release wake lock
-        }
-    }
-
-    private void setPendingProximityDebounceTime(long debounceTime) {
-        if (mPendingProximityDebounceTime < 0) {
-            mDisplaySuspendBlocker.acquire(); // acquire wake lock
-        }
-        mPendingProximityDebounceTime = debounceTime;
-    }
-
-    private void setLightSensorEnabled(boolean enable, boolean updateAutoBrightness) {
-        if (enable) {
-            if (!mLightSensorEnabled) {
-                updateAutoBrightness = true;
-                mLightSensorEnabled = true;
-                mLightSensorEnableTime = SystemClock.uptimeMillis();
-                mSensorManager.registerListener(mLightSensorListener, mLightSensor,
-                        LIGHT_SENSOR_RATE_MILLIS * 1000, mHandler);
-            }
-        } else {
-            if (mLightSensorEnabled) {
-                mLightSensorEnabled = false;
-                mAmbientLuxValid = false;
-                mRecentLightSamples = 0;
-                mHandler.removeMessages(MSG_LIGHT_SENSOR_DEBOUNCED);
-                mSensorManager.unregisterListener(mLightSensorListener);
-            }
-        }
-        if (updateAutoBrightness) {
-            updateAutoBrightness(false);
-        }
-    }
-
-    private void handleLightSensorEvent(long time, float lux) {
-        mHandler.removeMessages(MSG_LIGHT_SENSOR_DEBOUNCED);
-
-        applyLightSensorMeasurement(time, lux);
-        updateAmbientLux(time);
-    }
-
-    private void applyLightSensorMeasurement(long time, float lux) {
-        // Update our filters.
-        mRecentLightSamples += 1;
-        if (mRecentLightSamples == 1) {
-            mRecentShortTermAverageLux = lux;
-            mRecentLongTermAverageLux = lux;
-        } else {
-            final long timeDelta = time - mLastObservedLuxTime;
-            mRecentShortTermAverageLux += (lux - mRecentShortTermAverageLux)
-                    * timeDelta / (SHORT_TERM_AVERAGE_LIGHT_TIME_CONSTANT + timeDelta);
-            mRecentLongTermAverageLux += (lux - mRecentLongTermAverageLux)
-                    * timeDelta / (LONG_TERM_AVERAGE_LIGHT_TIME_CONSTANT + timeDelta);
-        }
-
-        // Remember this sample value.
-        mLastObservedLux = lux;
-        mLastObservedLuxTime = time;
-    }
-
-    private void setAmbientLux(float lux) {
-        mAmbientLux = lux;
-        mBrighteningLuxThreshold = mAmbientLux * (1.0f + BRIGHTENING_LIGHT_HYSTERESIS);
-        mDarkeningLuxThreshold = mAmbientLux * (1.0f - DARKENING_LIGHT_HYSTERESIS);
-    }
-
-    private void updateAmbientLux(long time) {
-        // If the light sensor was just turned on then immediately update our initial
-        // estimate of the current ambient light level.
-        if (!mAmbientLuxValid) {
-            final long timeWhenSensorWarmedUp =
-                mLightSensorWarmUpTimeConfig + mLightSensorEnableTime;
-            if (time < timeWhenSensorWarmedUp) {
-                mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED,
-                        timeWhenSensorWarmedUp);
-                return;
-            }
-            setAmbientLux(mRecentShortTermAverageLux);
-            mAmbientLuxValid = true;
-            mDebounceLuxDirection = 0;
-            mDebounceLuxTime = time;
-            if (DEBUG) {
-                Slog.d(TAG, "updateAmbientLux: Initializing: "
-                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
-                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
-                        + ", mAmbientLux=" + mAmbientLux);
-            }
-            updateAutoBrightness(true);
-        } else if (mRecentShortTermAverageLux > mBrighteningLuxThreshold
-                && mRecentLongTermAverageLux > mBrighteningLuxThreshold) {
-            // The ambient environment appears to be brightening.
-            if (mDebounceLuxDirection <= 0) {
-                mDebounceLuxDirection = 1;
-                mDebounceLuxTime = time;
-                if (DEBUG) {
-                    Slog.d(TAG, "updateAmbientLux: Possibly brightened, waiting for "
-                            + BRIGHTENING_LIGHT_DEBOUNCE + " ms: "
-                            + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
-                            + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
-                            + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
-                            + ", mAmbientLux=" + mAmbientLux);
-                }
-            }
-            long debounceTime = mDebounceLuxTime + BRIGHTENING_LIGHT_DEBOUNCE;
-            if (time < debounceTime) {
-                mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED, debounceTime);
-                return;
-            }
-            setAmbientLux(mRecentShortTermAverageLux);
-            if (DEBUG) {
-                Slog.d(TAG, "updateAmbientLux: Brightened: "
-                        + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
-                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
-                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
-                        + ", mAmbientLux=" + mAmbientLux);
-            }
-            updateAutoBrightness(true);
-        } else if (mRecentShortTermAverageLux < mDarkeningLuxThreshold
-                && mRecentLongTermAverageLux < mDarkeningLuxThreshold) {
-            // The ambient environment appears to be darkening.
-            if (mDebounceLuxDirection >= 0) {
-                mDebounceLuxDirection = -1;
-                mDebounceLuxTime = time;
-                if (DEBUG) {
-                    Slog.d(TAG, "updateAmbientLux: Possibly darkened, waiting for "
-                            + DARKENING_LIGHT_DEBOUNCE + " ms: "
-                            + "mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
-                            + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
-                            + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
-                            + ", mAmbientLux=" + mAmbientLux);
-                }
-            }
-            long debounceTime = mDebounceLuxTime + DARKENING_LIGHT_DEBOUNCE;
-            if (time < debounceTime) {
-                mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED, debounceTime);
-                return;
-            }
-            // Be conservative about reducing the brightness, only reduce it a little bit
-            // at a time to avoid having to bump it up again soon.
-            setAmbientLux(Math.max(mRecentShortTermAverageLux, mRecentLongTermAverageLux));
-            if (DEBUG) {
-                Slog.d(TAG, "updateAmbientLux: Darkened: "
-                        + "mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
-                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
-                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
-                        + ", mAmbientLux=" + mAmbientLux);
-            }
-            updateAutoBrightness(true);
-        } else if (mDebounceLuxDirection != 0) {
-            // No change or change is within the hysteresis thresholds.
-            mDebounceLuxDirection = 0;
-            mDebounceLuxTime = time;
-            if (DEBUG) {
-                Slog.d(TAG, "updateAmbientLux: Canceled debounce: "
-                        + "mBrighteningLuxThreshold=" + mBrighteningLuxThreshold
-                        + ", mDarkeningLuxThreshold=" + mDarkeningLuxThreshold
-                        + ", mRecentShortTermAverageLux=" + mRecentShortTermAverageLux
-                        + ", mRecentLongTermAverageLux=" + mRecentLongTermAverageLux
-                        + ", mAmbientLux=" + mAmbientLux);
-            }
-        }
-
-        // Now that we've done all of that, we haven't yet posted a debounce
-        // message. So consider the case where current lux is beyond the
-        // threshold. It's possible that the light sensor may not report values
-        // if the light level does not change, so we need to occasionally
-        // synthesize sensor readings in order to make sure the brightness is
-        // adjusted accordingly. Note these thresholds may have changed since
-        // we entered the function because we called setAmbientLux and
-        // updateAutoBrightness along the way.
-        if (mLastObservedLux > mBrighteningLuxThreshold
-                || mLastObservedLux < mDarkeningLuxThreshold) {
-            mHandler.sendEmptyMessageAtTime(MSG_LIGHT_SENSOR_DEBOUNCED,
-                    time + SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS);
-        }
-    }
-
-    private void debounceLightSensor() {
-        if (mLightSensorEnabled) {
-            long time = SystemClock.uptimeMillis();
-            if (time >= mLastObservedLuxTime + SYNTHETIC_LIGHT_SENSOR_RATE_MILLIS) {
-                if (DEBUG) {
-                    Slog.d(TAG, "debounceLightSensor: Synthesizing light sensor measurement "
-                            + "after " + (time - mLastObservedLuxTime) + " ms.");
-                }
-                applyLightSensorMeasurement(time, mLastObservedLux);
-            }
-            updateAmbientLux(time);
-        }
-    }
-
-    private void updateAutoBrightness(boolean sendUpdate) {
-        if (!mAmbientLuxValid) {
-            return;
-        }
-
-        float value = mScreenAutoBrightnessSpline.interpolate(mAmbientLux);
-        float gamma = 1.0f;
-
-        if (USE_SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT
-                && mPowerRequest.screenAutoBrightnessAdjustment != 0.0f) {
-            final float adjGamma = FloatMath.pow(SCREEN_AUTO_BRIGHTNESS_ADJUSTMENT_MAX_GAMMA,
-                    Math.min(1.0f, Math.max(-1.0f,
-                            -mPowerRequest.screenAutoBrightnessAdjustment)));
-            gamma *= adjGamma;
-            if (DEBUG) {
-                Slog.d(TAG, "updateAutoBrightness: adjGamma=" + adjGamma);
-            }
-        }
-
-        if (USE_TWILIGHT_ADJUSTMENT) {
-            TwilightState state = mTwilight.getCurrentState();
-            if (state != null && state.isNight()) {
-                final long now = System.currentTimeMillis();
-                final float earlyGamma =
-                        getTwilightGamma(now, state.getYesterdaySunset(), state.getTodaySunrise());
-                final float lateGamma =
-                        getTwilightGamma(now, state.getTodaySunset(), state.getTomorrowSunrise());
-                gamma *= earlyGamma * lateGamma;
-                if (DEBUG) {
-                    Slog.d(TAG, "updateAutoBrightness: earlyGamma=" + earlyGamma
-                            + ", lateGamma=" + lateGamma);
-                }
-            }
-        }
-
-        if (gamma != 1.0f) {
-            final float in = value;
-            value = FloatMath.pow(value, gamma);
-            if (DEBUG) {
-                Slog.d(TAG, "updateAutoBrightness: gamma=" + gamma
-                        + ", in=" + in + ", out=" + value);
-            }
-        }
-
-        int newScreenAutoBrightness = clampScreenBrightness(
-                Math.round(value * PowerManager.BRIGHTNESS_ON));
-        if (mScreenAutoBrightness != newScreenAutoBrightness) {
-            if (DEBUG) {
-                Slog.d(TAG, "updateAutoBrightness: mScreenAutoBrightness="
-                        + mScreenAutoBrightness + ", newScreenAutoBrightness="
-                        + newScreenAutoBrightness);
-            }
-
-            mScreenAutoBrightness = newScreenAutoBrightness;
-            mLastScreenAutoBrightnessGamma = gamma;
-            if (sendUpdate) {
-                sendUpdatePowerState();
-            }
-        }
-    }
-
-    private static float getTwilightGamma(long now, long lastSunset, long nextSunrise) {
-        if (lastSunset < 0 || nextSunrise < 0
-                || now < lastSunset || now > nextSunrise) {
-            return 1.0f;
-        }
-
-        if (now < lastSunset + TWILIGHT_ADJUSTMENT_TIME) {
-            return lerp(1.0f, TWILIGHT_ADJUSTMENT_MAX_GAMMA,
-                    (float)(now - lastSunset) / TWILIGHT_ADJUSTMENT_TIME);
-        }
-
-        if (now > nextSunrise - TWILIGHT_ADJUSTMENT_TIME) {
-            return lerp(1.0f, TWILIGHT_ADJUSTMENT_MAX_GAMMA,
-                    (float)(nextSunrise - now) / TWILIGHT_ADJUSTMENT_TIME);
-        }
-
-        return TWILIGHT_ADJUSTMENT_MAX_GAMMA;
-    }
-
-    private static float lerp(float x, float y, float alpha) {
-        return x + (y - x) * alpha;
-    }
-
-    private void sendOnStateChangedWithWakelock() {
-        mDisplaySuspendBlocker.acquire();
-        mCallbackHandler.post(mOnStateChangedRunnable);
-    }
-
-    private final Runnable mOnStateChangedRunnable = new Runnable() {
-        @Override
-        public void run() {
-            mCallbacks.onStateChanged();
-            mDisplaySuspendBlocker.release();
-        }
-    };
-
-    private void sendOnProximityPositiveWithWakelock() {
-        mDisplaySuspendBlocker.acquire();
-        mCallbackHandler.post(mOnProximityPositiveRunnable);
-    }
-
-    private final Runnable mOnProximityPositiveRunnable = new Runnable() {
-        @Override
-        public void run() {
-            mCallbacks.onProximityPositive();
-            mDisplaySuspendBlocker.release();
-        }
-    };
-
-    private void sendOnProximityNegativeWithWakelock() {
-        mDisplaySuspendBlocker.acquire();
-        mCallbackHandler.post(mOnProximityNegativeRunnable);
-    }
-
-    private final Runnable mOnProximityNegativeRunnable = new Runnable() {
-        @Override
-        public void run() {
-            mCallbacks.onProximityNegative();
-            mDisplaySuspendBlocker.release();
-        }
-    };
-
-    public void dump(final PrintWriter pw) {
-        synchronized (mLock) {
-            pw.println();
-            pw.println("Display Controller Locked State:");
-            pw.println("  mDisplayReadyLocked=" + mDisplayReadyLocked);
-            pw.println("  mPendingRequestLocked=" + mPendingRequestLocked);
-            pw.println("  mPendingRequestChangedLocked=" + mPendingRequestChangedLocked);
-            pw.println("  mPendingWaitForNegativeProximityLocked="
-                    + mPendingWaitForNegativeProximityLocked);
-            pw.println("  mPendingUpdatePowerStateLocked=" + mPendingUpdatePowerStateLocked);
-        }
-
-        pw.println();
-        pw.println("Display Controller Configuration:");
-        pw.println("  mScreenBrightnessDimConfig=" + mScreenBrightnessDimConfig);
-        pw.println("  mScreenBrightnessRangeMinimum=" + mScreenBrightnessRangeMinimum);
-        pw.println("  mScreenBrightnessRangeMaximum=" + mScreenBrightnessRangeMaximum);
-        pw.println("  mUseSoftwareAutoBrightnessConfig="
-                + mUseSoftwareAutoBrightnessConfig);
-        pw.println("  mScreenAutoBrightnessSpline=" + mScreenAutoBrightnessSpline);
-        pw.println("  mLightSensorWarmUpTimeConfig=" + mLightSensorWarmUpTimeConfig);
-
-        mHandler.runWithScissors(new Runnable() {
-            @Override
-            public void run() {
-                dumpLocal(pw);
-            }
-        }, 1000);
-    }
-
-    private void dumpLocal(PrintWriter pw) {
-        pw.println();
-        pw.println("Display Controller Thread State:");
-        pw.println("  mPowerRequest=" + mPowerRequest);
-        pw.println("  mWaitingForNegativeProximity=" + mWaitingForNegativeProximity);
-
-        pw.println("  mProximitySensor=" + mProximitySensor);
-        pw.println("  mProximitySensorEnabled=" + mProximitySensorEnabled);
-        pw.println("  mProximityThreshold=" + mProximityThreshold);
-        pw.println("  mProximity=" + proximityToString(mProximity));
-        pw.println("  mPendingProximity=" + proximityToString(mPendingProximity));
-        pw.println("  mPendingProximityDebounceTime="
-                + TimeUtils.formatUptime(mPendingProximityDebounceTime));
-        pw.println("  mScreenOffBecauseOfProximity=" + mScreenOffBecauseOfProximity);
-
-        pw.println("  mLightSensor=" + mLightSensor);
-        pw.println("  mLightSensorEnabled=" + mLightSensorEnabled);
-        pw.println("  mLightSensorEnableTime="
-                + TimeUtils.formatUptime(mLightSensorEnableTime));
-        pw.println("  mAmbientLux=" + mAmbientLux);
-        pw.println("  mAmbientLuxValid=" + mAmbientLuxValid);
-        pw.println("  mLastObservedLux=" + mLastObservedLux);
-        pw.println("  mLastObservedLuxTime="
-                + TimeUtils.formatUptime(mLastObservedLuxTime));
-        pw.println("  mRecentLightSamples=" + mRecentLightSamples);
-        pw.println("  mRecentShortTermAverageLux=" + mRecentShortTermAverageLux);
-        pw.println("  mRecentLongTermAverageLux=" + mRecentLongTermAverageLux);
-        pw.println("  mDebounceLuxDirection=" + mDebounceLuxDirection);
-        pw.println("  mDebounceLuxTime=" + TimeUtils.formatUptime(mDebounceLuxTime));
-        pw.println("  mScreenAutoBrightness=" + mScreenAutoBrightness);
-        pw.println("  mUsingScreenAutoBrightness=" + mUsingScreenAutoBrightness);
-        pw.println("  mLastScreenAutoBrightnessGamma=" + mLastScreenAutoBrightnessGamma);
-        pw.println("  mTwilight.getCurrentState()=" + mTwilight.getCurrentState());
-
-        if (mElectronBeamOnAnimator != null) {
-            pw.println("  mElectronBeamOnAnimator.isStarted()=" +
-                    mElectronBeamOnAnimator.isStarted());
-        }
-        if (mElectronBeamOffAnimator != null) {
-            pw.println("  mElectronBeamOffAnimator.isStarted()=" +
-                    mElectronBeamOffAnimator.isStarted());
-        }
-
-        if (mPowerState != null) {
-            mPowerState.dump(pw);
-        }
-    }
-
-    private static String proximityToString(int state) {
-        switch (state) {
-            case PROXIMITY_UNKNOWN:
-                return "Unknown";
-            case PROXIMITY_NEGATIVE:
-                return "Negative";
-            case PROXIMITY_POSITIVE:
-                return "Positive";
-            default:
-                return Integer.toString(state);
-        }
-    }
-
-    private static boolean wantScreenOn(int state) {
-        switch (state) {
-            case DisplayPowerRequest.SCREEN_STATE_BRIGHT:
-            case DisplayPowerRequest.SCREEN_STATE_DIM:
-                return true;
-        }
-        return false;
-    }
-
-    /**
-     * Asynchronous callbacks from the power controller to the power manager service.
-     */
-    public interface Callbacks {
-        void onStateChanged();
-        void onProximityPositive();
-        void onProximityNegative();
-    }
-
-    private final class DisplayControllerHandler extends Handler {
-        public DisplayControllerHandler(Looper looper) {
-            super(looper, null, true /*async*/);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_UPDATE_POWER_STATE:
-                    updatePowerState();
-                    break;
-
-                case MSG_PROXIMITY_SENSOR_DEBOUNCED:
-                    debounceProximitySensor();
-                    break;
-
-                case MSG_LIGHT_SENSOR_DEBOUNCED:
-                    debounceLightSensor();
-                    break;
-            }
-        }
-    }
-
-    private final SensorEventListener mProximitySensorListener = new SensorEventListener() {
-        @Override
-        public void onSensorChanged(SensorEvent event) {
-            if (mProximitySensorEnabled) {
-                final long time = SystemClock.uptimeMillis();
-                final float distance = event.values[0];
-                boolean positive = distance >= 0.0f && distance < mProximityThreshold;
-                handleProximitySensorEvent(time, positive);
-            }
-        }
-
-        @Override
-        public void onAccuracyChanged(Sensor sensor, int accuracy) {
-            // Not used.
-        }
-    };
-
-    private final SensorEventListener mLightSensorListener = new SensorEventListener() {
-        @Override
-        public void onSensorChanged(SensorEvent event) {
-            if (mLightSensorEnabled) {
-                final long time = SystemClock.uptimeMillis();
-                final float lux = event.values[0];
-                handleLightSensorEvent(time, lux);
-            }
-        }
-
-        @Override
-        public void onAccuracyChanged(Sensor sensor, int accuracy) {
-            // Not used.
-        }
-    };
-
-    private final TwilightService.TwilightListener mTwilightListener =
-            new TwilightService.TwilightListener() {
-        @Override
-        public void onTwilightStateChanged() {
-            mTwilightChanged = true;
-            updatePowerState();
-        }
-    };
-}
diff --git a/services/java/com/android/server/power/DisplayPowerRequest.java b/services/java/com/android/server/power/DisplayPowerRequest.java
deleted file mode 100644
index 22f17d7..0000000
--- a/services/java/com/android/server/power/DisplayPowerRequest.java
+++ /dev/null
@@ -1,117 +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.server.power;
-
-import android.os.PowerManager;
-
-/**
- * Describes the requested power state of the display.
- *
- * This object is intended to describe the general characteristics of the
- * power state, such as whether the screen should be on or off and the current
- * brightness controls leaving the {@link DisplayPowerController} to manage the
- * details of how the transitions between states should occur.  The goal is for
- * the {@link PowerManagerService} to focus on the global power state and not
- * have to micro-manage screen off animations, auto-brightness and other effects.
- */
-final class DisplayPowerRequest {
-    public static final int SCREEN_STATE_OFF = 0;
-    public static final int SCREEN_STATE_DIM = 1;
-    public static final int SCREEN_STATE_BRIGHT = 2;
-
-    // The requested minimum screen power state: off, dim or bright.
-    public int screenState;
-
-    // If true, the proximity sensor overrides the screen state when an object is
-    // nearby, turning it off temporarily until the object is moved away.
-    public boolean useProximitySensor;
-
-    // The desired screen brightness in the range 0 (minimum / off) to 255 (brightest).
-    // The display power controller may choose to clamp the brightness.
-    // When auto-brightness is enabled, this field should specify a nominal default
-    // value to use while waiting for the light sensor to report enough data.
-    public int screenBrightness;
-
-    // The screen auto-brightness adjustment factor in the range -1 (dimmer) to 1 (brighter).
-    public float screenAutoBrightnessAdjustment;
-
-    // If true, enables automatic brightness control.
-    public boolean useAutoBrightness;
-
-    // If true, prevents the screen from completely turning on if it is currently off.
-    // The display does not enter a "ready" state if this flag is true and screen on is
-    // blocked.  The window manager policy blocks screen on while it prepares the keyguard to
-    // prevent the user from seeing intermediate updates.
-    //
-    // Technically, we may not block the screen itself from turning on (because that introduces
-    // extra unnecessary latency) but we do prevent content on screen from becoming
-    // visible to the user.
-    public boolean blockScreenOn;
-
-    public DisplayPowerRequest() {
-        screenState = SCREEN_STATE_BRIGHT;
-        useProximitySensor = false;
-        screenBrightness = PowerManager.BRIGHTNESS_ON;
-        screenAutoBrightnessAdjustment = 0.0f;
-        useAutoBrightness = false;
-        blockScreenOn = false;
-    }
-
-    public DisplayPowerRequest(DisplayPowerRequest other) {
-        copyFrom(other);
-    }
-
-    public void copyFrom(DisplayPowerRequest other) {
-        screenState = other.screenState;
-        useProximitySensor = other.useProximitySensor;
-        screenBrightness = other.screenBrightness;
-        screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
-        useAutoBrightness = other.useAutoBrightness;
-        blockScreenOn = other.blockScreenOn;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        return o instanceof DisplayPowerRequest
-                && equals((DisplayPowerRequest)o);
-    }
-
-    public boolean equals(DisplayPowerRequest other) {
-        return other != null
-                && screenState == other.screenState
-                && useProximitySensor == other.useProximitySensor
-                && screenBrightness == other.screenBrightness
-                && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
-                && useAutoBrightness == other.useAutoBrightness
-                && blockScreenOn == other.blockScreenOn;
-    }
-
-    @Override
-    public int hashCode() {
-        return 0; // don't care
-    }
-
-    @Override
-    public String toString() {
-        return "screenState=" + screenState
-                + ", useProximitySensor=" + useProximitySensor
-                + ", screenBrightness=" + screenBrightness
-                + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
-                + ", useAutoBrightness=" + useAutoBrightness
-                + ", blockScreenOn=" + blockScreenOn;
-    }
-}
diff --git a/services/java/com/android/server/power/DisplayPowerState.java b/services/java/com/android/server/power/DisplayPowerState.java
deleted file mode 100644
index 5c048f1..0000000
--- a/services/java/com/android/server/power/DisplayPowerState.java
+++ /dev/null
@@ -1,421 +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.server.power;
-
-import com.android.server.LightsService;
-
-import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.PowerManager;
-import android.util.FloatProperty;
-import android.util.IntProperty;
-import android.util.Slog;
-import android.view.Choreographer;
-
-import java.io.PrintWriter;
-
-/**
- * Controls the display power state.
- * <p>
- * This component is similar in nature to a {@link View} except that it describes
- * the properties of a display.  When properties are changed, the component
- * invalidates itself and posts a callback to apply the changes in a consistent order.
- * This mechanism enables multiple properties of the display power state to be animated
- * together smoothly by the animation framework.  Some of the work to blank or unblank
- * the display is done on a separate thread to avoid blocking the looper.
- * </p><p>
- * This component must only be created or accessed by the {@link Looper} thread
- * that belongs to the {@link DisplayPowerController}.
- * </p><p>
- * We don't need to worry about holding a suspend blocker here because the
- * {@link PowerManagerService} does that for us whenever there is a change
- * in progress.
- * </p>
- */
-final class DisplayPowerState {
-    private static final String TAG = "DisplayPowerState";
-
-    private static boolean DEBUG = false;
-
-    private final Handler mHandler;
-    private final Choreographer mChoreographer;
-    private final ElectronBeam mElectronBeam;
-    private final DisplayBlanker mDisplayBlanker;
-    private final LightsService.Light mBacklight;
-    private final PhotonicModulator mPhotonicModulator;
-
-    private boolean mScreenOn;
-    private int mScreenBrightness;
-    private boolean mScreenReady;
-    private boolean mScreenUpdatePending;
-
-    private boolean mElectronBeamPrepared;
-    private float mElectronBeamLevel;
-    private boolean mElectronBeamReady;
-    private boolean mElectronBeamDrawPending;
-
-    private Runnable mCleanListener;
-
-    public DisplayPowerState(ElectronBeam electronBean,
-            DisplayBlanker displayBlanker, LightsService.Light backlight) {
-        mHandler = new Handler(true /*async*/);
-        mChoreographer = Choreographer.getInstance();
-        mElectronBeam = electronBean;
-        mDisplayBlanker = displayBlanker;
-        mBacklight = backlight;
-        mPhotonicModulator = new PhotonicModulator();
-
-        // At boot time, we know that the screen is on and the electron beam
-        // animation is not playing.  We don't know the screen's brightness though,
-        // so prepare to set it to a known state when the state is next applied.
-        // Although we set the brightness to full on here, the display power controller
-        // will reset the brightness to a new level immediately before the changes
-        // actually have a chance to be applied.
-        mScreenOn = true;
-        mScreenBrightness = PowerManager.BRIGHTNESS_ON;
-        scheduleScreenUpdate();
-
-        mElectronBeamPrepared = false;
-        mElectronBeamLevel = 1.0f;
-        mElectronBeamReady = true;
-    }
-
-    public static final FloatProperty<DisplayPowerState> ELECTRON_BEAM_LEVEL =
-            new FloatProperty<DisplayPowerState>("electronBeamLevel") {
-        @Override
-        public void setValue(DisplayPowerState object, float value) {
-            object.setElectronBeamLevel(value);
-        }
-
-        @Override
-        public Float get(DisplayPowerState object) {
-            return object.getElectronBeamLevel();
-        }
-    };
-
-    public static final IntProperty<DisplayPowerState> SCREEN_BRIGHTNESS =
-            new IntProperty<DisplayPowerState>("screenBrightness") {
-        @Override
-        public void setValue(DisplayPowerState object, int value) {
-            object.setScreenBrightness(value);
-        }
-
-        @Override
-        public Integer get(DisplayPowerState object) {
-            return object.getScreenBrightness();
-        }
-    };
-
-    /**
-     * Sets whether the screen is on or off.
-     */
-    public void setScreenOn(boolean on) {
-        if (mScreenOn != on) {
-            if (DEBUG) {
-                Slog.d(TAG, "setScreenOn: on=" + on);
-            }
-
-            mScreenOn = on;
-            mScreenReady = false;
-            scheduleScreenUpdate();
-        }
-    }
-
-    /**
-     * Returns true if the screen is on.
-     */
-    public boolean isScreenOn() {
-        return mScreenOn;
-    }
-
-    /**
-     * Sets the display brightness.
-     *
-     * @param brightness The brightness, ranges from 0 (minimum / off) to 255 (brightest).
-     */
-    public void setScreenBrightness(int brightness) {
-        if (mScreenBrightness != brightness) {
-            if (DEBUG) {
-                Slog.d(TAG, "setScreenBrightness: brightness=" + brightness);
-            }
-
-            mScreenBrightness = brightness;
-            if (mScreenOn) {
-                mScreenReady = false;
-                scheduleScreenUpdate();
-            }
-        }
-    }
-
-    /**
-     * Gets the screen brightness.
-     */
-    public int getScreenBrightness() {
-        return mScreenBrightness;
-    }
-
-    /**
-     * Prepares the electron beam to turn on or off.
-     * This method should be called before starting an animation because it
-     * can take a fair amount of time to prepare the electron beam surface.
-     *
-     * @param mode The electron beam animation mode to prepare.
-     * @return True if the electron beam was prepared.
-     */
-    public boolean prepareElectronBeam(int mode) {
-        if (!mElectronBeam.prepare(mode)) {
-            mElectronBeamPrepared = false;
-            mElectronBeamReady = true;
-            return false;
-        }
-
-        mElectronBeamPrepared = true;
-        mElectronBeamReady = false;
-        scheduleElectronBeamDraw();
-        return true;
-    }
-
-    /**
-     * Dismisses the electron beam surface.
-     */
-    public void dismissElectronBeam() {
-        mElectronBeam.dismiss();
-        mElectronBeamPrepared = false;
-        mElectronBeamReady = true;
-    }
-
-    /**
-     * Sets the level of the electron beam steering current.
-     *
-     * The display is blanked when the level is 0.0.  In normal use, the electron
-     * beam should have a value of 1.0.  The electron beam is unstable in between
-     * these states and the picture quality may be compromised.  For best effect,
-     * the electron beam should be warmed up or cooled off slowly.
-     *
-     * Warning: Electron beam emits harmful radiation.  Avoid direct exposure to
-     * skin or eyes.
-     *
-     * @param level The level, ranges from 0.0 (full off) to 1.0 (full on).
-     */
-    public void setElectronBeamLevel(float level) {
-        if (mElectronBeamLevel != level) {
-            if (DEBUG) {
-                Slog.d(TAG, "setElectronBeamLevel: level=" + level);
-            }
-
-            mElectronBeamLevel = level;
-            if (mScreenOn) {
-                mScreenReady = false;
-                scheduleScreenUpdate(); // update backlight brightness
-            }
-            if (mElectronBeamPrepared) {
-                mElectronBeamReady = false;
-                scheduleElectronBeamDraw();
-            }
-        }
-    }
-
-    /**
-     * Gets the level of the electron beam steering current.
-     */
-    public float getElectronBeamLevel() {
-        return mElectronBeamLevel;
-    }
-
-    /**
-     * Returns true if no properties have been invalidated.
-     * Otherwise, returns false and promises to invoke the specified listener
-     * when the properties have all been applied.
-     * The listener always overrides any previously set listener.
-     */
-    public boolean waitUntilClean(Runnable listener) {
-        if (!mScreenReady || !mElectronBeamReady) {
-            mCleanListener = listener;
-            return false;
-        } else {
-            mCleanListener = null;
-            return true;
-        }
-    }
-
-    public void dump(PrintWriter pw) {
-        pw.println();
-        pw.println("Display Power State:");
-        pw.println("  mScreenOn=" + mScreenOn);
-        pw.println("  mScreenBrightness=" + mScreenBrightness);
-        pw.println("  mScreenReady=" + mScreenReady);
-        pw.println("  mScreenUpdatePending=" + mScreenUpdatePending);
-        pw.println("  mElectronBeamPrepared=" + mElectronBeamPrepared);
-        pw.println("  mElectronBeamLevel=" + mElectronBeamLevel);
-        pw.println("  mElectronBeamReady=" + mElectronBeamReady);
-        pw.println("  mElectronBeamDrawPending=" + mElectronBeamDrawPending);
-
-        mPhotonicModulator.dump(pw);
-        mElectronBeam.dump(pw);
-    }
-
-    private void scheduleScreenUpdate() {
-        if (!mScreenUpdatePending) {
-            mScreenUpdatePending = true;
-            postScreenUpdateThreadSafe();
-        }
-    }
-
-    private void postScreenUpdateThreadSafe() {
-        mHandler.removeCallbacks(mScreenUpdateRunnable);
-        mHandler.post(mScreenUpdateRunnable);
-    }
-
-    private void scheduleElectronBeamDraw() {
-        if (!mElectronBeamDrawPending) {
-            mElectronBeamDrawPending = true;
-            mChoreographer.postCallback(Choreographer.CALLBACK_TRAVERSAL,
-                    mElectronBeamDrawRunnable, null);
-        }
-    }
-
-    private void invokeCleanListenerIfNeeded() {
-        final Runnable listener = mCleanListener;
-        if (listener != null && mScreenReady && mElectronBeamReady) {
-            mCleanListener = null;
-            listener.run();
-        }
-    }
-
-    private final Runnable mScreenUpdateRunnable = new Runnable() {
-        @Override
-        public void run() {
-            mScreenUpdatePending = false;
-
-            int brightness = mScreenOn && mElectronBeamLevel > 0f ? mScreenBrightness : 0;
-            if (mPhotonicModulator.setState(mScreenOn, brightness)) {
-                if (DEBUG) {
-                    Slog.d(TAG, "Screen ready");
-                }
-                mScreenReady = true;
-                invokeCleanListenerIfNeeded();
-            } else {
-                if (DEBUG) {
-                    Slog.d(TAG, "Screen not ready");
-                }
-            }
-        }
-    };
-
-    private final Runnable mElectronBeamDrawRunnable = new Runnable() {
-        @Override
-        public void run() {
-            mElectronBeamDrawPending = false;
-
-            if (mElectronBeamPrepared) {
-                mElectronBeam.draw(mElectronBeamLevel);
-            }
-
-            mElectronBeamReady = true;
-            invokeCleanListenerIfNeeded();
-        }
-    };
-
-    /**
-     * Updates the state of the screen and backlight asynchronously on a separate thread.
-     */
-    private final class PhotonicModulator {
-        private static final boolean INITIAL_SCREEN_ON = false; // unknown, assume off
-        private static final int INITIAL_BACKLIGHT = -1; // unknown
-
-        private final Object mLock = new Object();
-
-        private boolean mPendingOn = INITIAL_SCREEN_ON;
-        private int mPendingBacklight = INITIAL_BACKLIGHT;
-        private boolean mActualOn = INITIAL_SCREEN_ON;
-        private int mActualBacklight = INITIAL_BACKLIGHT;
-        private boolean mChangeInProgress;
-
-        public boolean setState(boolean on, int backlight) {
-            synchronized (mLock) {
-                if (on != mPendingOn || backlight != mPendingBacklight) {
-                    if (DEBUG) {
-                        Slog.d(TAG, "Requesting new screen state: on=" + on
-                                + ", backlight=" + backlight);
-                    }
-
-                    mPendingOn = on;
-                    mPendingBacklight = backlight;
-
-                    if (!mChangeInProgress) {
-                        mChangeInProgress = true;
-                        AsyncTask.THREAD_POOL_EXECUTOR.execute(mTask);
-                    }
-                }
-                return !mChangeInProgress;
-            }
-        }
-
-        public void dump(PrintWriter pw) {
-            pw.println();
-            pw.println("Photonic Modulator State:");
-            pw.println("  mPendingOn=" + mPendingOn);
-            pw.println("  mPendingBacklight=" + mPendingBacklight);
-            pw.println("  mActualOn=" + mActualOn);
-            pw.println("  mActualBacklight=" + mActualBacklight);
-            pw.println("  mChangeInProgress=" + mChangeInProgress);
-        }
-
-        private final Runnable mTask = new Runnable() {
-            @Override
-            public void run() {
-                // Apply pending changes until done.
-                for (;;) {
-                    final boolean on;
-                    final boolean onChanged;
-                    final int backlight;
-                    final boolean backlightChanged;
-                    synchronized (mLock) {
-                        on = mPendingOn;
-                        onChanged = (on != mActualOn);
-                        backlight = mPendingBacklight;
-                        backlightChanged = (backlight != mActualBacklight);
-                        if (!onChanged && !backlightChanged) {
-                            mChangeInProgress = false;
-                            break;
-                        }
-                        mActualOn = on;
-                        mActualBacklight = backlight;
-                    }
-
-                    if (DEBUG) {
-                        Slog.d(TAG, "Updating screen state: on=" + on
-                                + ", backlight=" + backlight);
-                    }
-                    if (onChanged && on) {
-                        mDisplayBlanker.unblankAllDisplays();
-                    }
-                    if (backlightChanged) {
-                        mBacklight.setBrightness(backlight);
-                    }
-                    if (onChanged && !on) {
-                        mDisplayBlanker.blankAllDisplays();
-                    }
-                }
-
-                // Let the outer class know that all changes have been applied.
-                postScreenUpdateThreadSafe();
-            }
-        };
-    }
-}
diff --git a/services/java/com/android/server/power/ElectronBeam.java b/services/java/com/android/server/power/ElectronBeam.java
deleted file mode 100644
index 729bd16..0000000
--- a/services/java/com/android/server/power/ElectronBeam.java
+++ /dev/null
@@ -1,733 +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.server.power;
-
-import java.io.PrintWriter;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
-
-import android.graphics.PixelFormat;
-import android.graphics.SurfaceTexture;
-import android.opengl.EGL14;
-import android.opengl.EGLConfig;
-import android.opengl.EGLContext;
-import android.opengl.EGLDisplay;
-import android.opengl.EGLSurface;
-import android.opengl.GLES10;
-import android.opengl.GLES11Ext;
-import android.os.Looper;
-import android.util.FloatMath;
-import android.util.Slog;
-import android.view.Display;
-import android.view.DisplayInfo;
-import android.view.Surface.OutOfResourcesException;
-import android.view.Surface;
-import android.view.SurfaceControl;
-import android.view.SurfaceSession;
-
-import com.android.server.display.DisplayManagerService;
-import com.android.server.display.DisplayTransactionListener;
-
-/**
- * Bzzzoooop!  *crackle*
- * <p>
- * Animates a screen transition from on to off or off to on by applying
- * some GL transformations to a screenshot.
- * </p><p>
- * This component must only be created or accessed by the {@link Looper} thread
- * that belongs to the {@link DisplayPowerController}.
- * </p>
- */
-final class ElectronBeam {
-    private static final String TAG = "ElectronBeam";
-
-    private static final boolean DEBUG = false;
-
-    // The layer for the electron beam surface.
-    // This is currently hardcoded to be one layer above the boot animation.
-    private static final int ELECTRON_BEAM_LAYER = 0x40000001;
-
-    // The relative proportion of the animation to spend performing
-    // the horizontal stretch effect.  The remainder is spent performing
-    // the vertical stretch effect.
-    private static final float HSTRETCH_DURATION = 0.5f;
-    private static final float VSTRETCH_DURATION = 1.0f - HSTRETCH_DURATION;
-
-    // The number of frames to draw when preparing the animation so that it will
-    // be ready to run smoothly.  We use 3 frames because we are triple-buffered.
-    // See code for details.
-    private static final int DEJANK_FRAMES = 3;
-
-    // Set to true when the animation context has been fully prepared.
-    private boolean mPrepared;
-    private int mMode;
-
-    private final DisplayManagerService mDisplayManager;
-    private int mDisplayLayerStack; // layer stack associated with primary display
-    private int mDisplayWidth;      // real width, not rotated
-    private int mDisplayHeight;     // real height, not rotated
-    private SurfaceSession mSurfaceSession;
-    private SurfaceControl mSurfaceControl;
-    private Surface mSurface;
-    private NaturalSurfaceLayout mSurfaceLayout;
-    private EGLDisplay mEglDisplay;
-    private EGLConfig mEglConfig;
-    private EGLContext mEglContext;
-    private EGLSurface mEglSurface;
-    private boolean mSurfaceVisible;
-    private float mSurfaceAlpha;
-
-    // Texture names.  We only use one texture, which contains the screenshot.
-    private final int[] mTexNames = new int[1];
-    private boolean mTexNamesGenerated;
-    private final float mTexMatrix[] = new float[16];
-
-    // Vertex and corresponding texture coordinates.
-    // We have 4 2D vertices, so 8 elements.  The vertices form a quad.
-    private final FloatBuffer mVertexBuffer = createNativeFloatBuffer(8);
-    private final FloatBuffer mTexCoordBuffer = createNativeFloatBuffer(8);
-
-    /**
-     * Animates an electron beam warming up.
-     */
-    public static final int MODE_WARM_UP = 0;
-
-    /**
-     * Animates an electron beam shutting off.
-     */
-    public static final int MODE_COOL_DOWN = 1;
-
-    /**
-     * Animates a simple dim layer to fade the contents of the screen in or out progressively.
-     */
-    public static final int MODE_FADE = 2;
-
-
-    public ElectronBeam(DisplayManagerService displayManager) {
-        mDisplayManager = displayManager;
-    }
-
-    /**
-     * Warms up the electron beam in preparation for turning on or off.
-     * This method prepares a GL context, and captures a screen shot.
-     *
-     * @param mode The desired mode for the upcoming animation.
-     * @return True if the electron beam is ready, false if it is uncontrollable.
-     */
-    public boolean prepare(int mode) {
-        if (DEBUG) {
-            Slog.d(TAG, "prepare: mode=" + mode);
-        }
-
-        mMode = mode;
-
-        // Get the display size and layer stack.
-        // This is not expected to change while the electron beam surface is showing.
-        DisplayInfo displayInfo = mDisplayManager.getDisplayInfo(Display.DEFAULT_DISPLAY);
-        mDisplayLayerStack = displayInfo.layerStack;
-        mDisplayWidth = displayInfo.getNaturalWidth();
-        mDisplayHeight = displayInfo.getNaturalHeight();
-
-        // Prepare the surface for drawing.
-        if (!tryPrepare()) {
-            dismiss();
-            return false;
-        }
-
-        // Done.
-        mPrepared = true;
-
-        // Dejanking optimization.
-        // Some GL drivers can introduce a lot of lag in the first few frames as they
-        // initialize their state and allocate graphics buffers for rendering.
-        // Work around this problem by rendering the first frame of the animation a few
-        // times.  The rest of the animation should run smoothly thereafter.
-        // The frames we draw here aren't visible because we are essentially just
-        // painting the screenshot as-is.
-        if (mode == MODE_COOL_DOWN) {
-            for (int i = 0; i < DEJANK_FRAMES; i++) {
-                draw(1.0f);
-            }
-        }
-        return true;
-    }
-
-    private boolean tryPrepare() {
-        if (createSurface()) {
-            if (mMode == MODE_FADE) {
-                return true;
-            }
-            return createEglContext()
-                    && createEglSurface()
-                    && captureScreenshotTextureAndSetViewport();
-        }
-        return false;
-    }
-
-    /**
-     * Dismisses the electron beam animation surface and cleans up.
-     *
-     * To prevent stray photons from leaking out after the electron beam has been
-     * turned off, it is a good idea to defer dismissing the animation until the
-     * electron beam has been turned back on fully.
-     */
-    public void dismiss() {
-        if (DEBUG) {
-            Slog.d(TAG, "dismiss");
-        }
-
-        destroyScreenshotTexture();
-        destroyEglSurface();
-        destroySurface();
-        mPrepared = false;
-    }
-
-    /**
-     * Draws an animation frame showing the electron beam activated at the
-     * specified level.
-     *
-     * @param level The electron beam level.
-     * @return True if successful.
-     */
-    public boolean draw(float level) {
-        if (DEBUG) {
-            Slog.d(TAG, "drawFrame: level=" + level);
-        }
-
-        if (!mPrepared) {
-            return false;
-        }
-
-        if (mMode == MODE_FADE) {
-            return showSurface(1.0f - level);
-        }
-
-        if (!attachEglContext()) {
-            return false;
-        }
-        try {
-            // Clear frame to solid black.
-            GLES10.glClearColor(0f, 0f, 0f, 1f);
-            GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT);
-
-            // Draw the frame.
-            if (level < HSTRETCH_DURATION) {
-                drawHStretch(1.0f - (level / HSTRETCH_DURATION));
-            } else {
-                drawVStretch(1.0f - ((level - HSTRETCH_DURATION) / VSTRETCH_DURATION));
-            }
-            if (checkGlErrors("drawFrame")) {
-                return false;
-            }
-
-            EGL14.eglSwapBuffers(mEglDisplay, mEglSurface);
-        } finally {
-            detachEglContext();
-        }
-        return showSurface(1.0f);
-    }
-
-    /**
-     * Draws a frame where the content of the electron beam is collapsing inwards upon
-     * itself vertically with red / green / blue channels dispersing and eventually
-     * merging down to a single horizontal line.
-     *
-     * @param stretch The stretch factor.  0.0 is no collapse, 1.0 is full collapse.
-     */
-    private void drawVStretch(float stretch) {
-        // compute interpolation scale factors for each color channel
-        final float ar = scurve(stretch, 7.5f);
-        final float ag = scurve(stretch, 8.0f);
-        final float ab = scurve(stretch, 8.5f);
-        if (DEBUG) {
-            Slog.d(TAG, "drawVStretch: stretch=" + stretch
-                    + ", ar=" + ar + ", ag=" + ag + ", ab=" + ab);
-        }
-
-        // set blending
-        GLES10.glBlendFunc(GLES10.GL_ONE, GLES10.GL_ONE);
-        GLES10.glEnable(GLES10.GL_BLEND);
-
-        // bind vertex buffer
-        GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
-        GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
-
-        // set-up texturing
-        GLES10.glDisable(GLES10.GL_TEXTURE_2D);
-        GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
-
-        // bind texture and set blending for drawing planes
-        GLES10.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTexNames[0]);
-        GLES10.glTexEnvx(GLES10.GL_TEXTURE_ENV, GLES10.GL_TEXTURE_ENV_MODE,
-                mMode == MODE_WARM_UP ? GLES10.GL_MODULATE : GLES10.GL_REPLACE);
-        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR);
-        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_LINEAR);
-        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_CLAMP_TO_EDGE);
-        GLES10.glTexParameterx(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_CLAMP_TO_EDGE);
-        GLES10.glEnable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
-        GLES10.glTexCoordPointer(2, GLES10.GL_FLOAT, 0, mTexCoordBuffer);
-        GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
-
-        // draw the red plane
-        setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ar);
-        GLES10.glColorMask(true, false, false, true);
-        GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
-
-        // draw the green plane
-        setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag);
-        GLES10.glColorMask(false, true, false, true);
-        GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
-
-        // draw the blue plane
-        setVStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ab);
-        GLES10.glColorMask(false, false, true, true);
-        GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
-
-        // clean up after drawing planes
-        GLES10.glDisable(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
-        GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
-        GLES10.glColorMask(true, true, true, true);
-
-        // draw the white highlight (we use the last vertices)
-        if (mMode == MODE_COOL_DOWN) {
-            GLES10.glColor4f(ag, ag, ag, 1.0f);
-            GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
-        }
-
-        // clean up
-        GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
-        GLES10.glDisable(GLES10.GL_BLEND);
-    }
-
-    /**
-     * Draws a frame where the electron beam has been stretched out into
-     * a thin white horizontal line that fades as it collapses inwards.
-     *
-     * @param stretch The stretch factor.  0.0 is maximum stretch / no fade,
-     * 1.0 is collapsed / maximum fade.
-     */
-    private void drawHStretch(float stretch) {
-        // compute interpolation scale factor
-        final float ag = scurve(stretch, 8.0f);
-        if (DEBUG) {
-            Slog.d(TAG, "drawHStretch: stretch=" + stretch + ", ag=" + ag);
-        }
-
-        if (stretch < 1.0f) {
-            // bind vertex buffer
-            GLES10.glVertexPointer(2, GLES10.GL_FLOAT, 0, mVertexBuffer);
-            GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
-
-            // draw narrow fading white line
-            setHStretchQuad(mVertexBuffer, mDisplayWidth, mDisplayHeight, ag);
-            GLES10.glColor4f(1.0f - ag*0.75f, 1.0f - ag*0.75f, 1.0f - ag*0.75f, 1.0f);
-            GLES10.glDrawArrays(GLES10.GL_TRIANGLE_FAN, 0, 4);
-
-            // clean up
-            GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
-        }
-    }
-
-    private static void setVStretchQuad(FloatBuffer vtx, float dw, float dh, float a) {
-        final float w = dw + (dw * a);
-        final float h = dh - (dh * a);
-        final float x = (dw - w) * 0.5f;
-        final float y = (dh - h) * 0.5f;
-        setQuad(vtx, x, y, w, h);
-    }
-
-    private static void setHStretchQuad(FloatBuffer vtx, float dw, float dh, float a) {
-        final float w = 2 * dw * (1.0f - a);
-        final float h = 1.0f;
-        final float x = (dw - w) * 0.5f;
-        final float y = (dh - h) * 0.5f;
-        setQuad(vtx, x, y, w, h);
-    }
-
-    private static void setQuad(FloatBuffer vtx, float x, float y, float w, float h) {
-        if (DEBUG) {
-            Slog.d(TAG, "setQuad: x=" + x + ", y=" + y + ", w=" + w + ", h=" + h);
-        }
-        vtx.put(0, x);
-        vtx.put(1, y);
-        vtx.put(2, x);
-        vtx.put(3, y + h);
-        vtx.put(4, x + w);
-        vtx.put(5, y + h);
-        vtx.put(6, x + w);
-        vtx.put(7, y);
-    }
-
-    private boolean captureScreenshotTextureAndSetViewport() {
-        if (!attachEglContext()) {
-            return false;
-        }
-        try {
-            if (!mTexNamesGenerated) {
-                GLES10.glGenTextures(1, mTexNames, 0);
-                if (checkGlErrors("glGenTextures")) {
-                    return false;
-                }
-                mTexNamesGenerated = true;
-            }
-
-            final SurfaceTexture st = new SurfaceTexture(mTexNames[0]);
-            final Surface s = new Surface(st);
-            try {
-                SurfaceControl.screenshot(SurfaceControl.getBuiltInDisplay(
-                        SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN), s);
-            } finally {
-                s.release();
-            }
-
-            st.updateTexImage();
-            st.getTransformMatrix(mTexMatrix);
-
-            // Set up texture coordinates for a quad.
-            // We might need to change this if the texture ends up being
-            // a different size from the display for some reason.
-            mTexCoordBuffer.put(0, 0f); mTexCoordBuffer.put(1, 0f);
-            mTexCoordBuffer.put(2, 0f); mTexCoordBuffer.put(3, 1f);
-            mTexCoordBuffer.put(4, 1f); mTexCoordBuffer.put(5, 1f);
-            mTexCoordBuffer.put(6, 1f); mTexCoordBuffer.put(7, 0f);
-
-            // Set up our viewport.
-            GLES10.glViewport(0, 0, mDisplayWidth, mDisplayHeight);
-            GLES10.glMatrixMode(GLES10.GL_PROJECTION);
-            GLES10.glLoadIdentity();
-            GLES10.glOrthof(0, mDisplayWidth, 0, mDisplayHeight, 0, 1);
-            GLES10.glMatrixMode(GLES10.GL_MODELVIEW);
-            GLES10.glLoadIdentity();
-            GLES10.glMatrixMode(GLES10.GL_TEXTURE);
-            GLES10.glLoadIdentity();
-            GLES10.glLoadMatrixf(mTexMatrix, 0);
-        } finally {
-            detachEglContext();
-        }
-        return true;
-    }
-
-    private void destroyScreenshotTexture() {
-        if (mTexNamesGenerated) {
-            mTexNamesGenerated = false;
-            if (attachEglContext()) {
-                try {
-                    GLES10.glDeleteTextures(1, mTexNames, 0);
-                    checkGlErrors("glDeleteTextures");
-                } finally {
-                    detachEglContext();
-                }
-            }
-        }
-    }
-
-    private boolean createEglContext() {
-        if (mEglDisplay == null) {
-            mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
-            if (mEglDisplay == EGL14.EGL_NO_DISPLAY) {
-                logEglError("eglGetDisplay");
-                return false;
-            }
-
-            int[] version = new int[2];
-            if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) {
-                mEglDisplay = null;
-                logEglError("eglInitialize");
-                return false;
-            }
-        }
-
-        if (mEglConfig == null) {
-            int[] eglConfigAttribList = new int[] {
-                    EGL14.EGL_RED_SIZE, 8,
-                    EGL14.EGL_GREEN_SIZE, 8,
-                    EGL14.EGL_BLUE_SIZE, 8,
-                    EGL14.EGL_ALPHA_SIZE, 8,
-                    EGL14.EGL_NONE
-            };
-            int[] numEglConfigs = new int[1];
-            EGLConfig[] eglConfigs = new EGLConfig[1];
-            if (!EGL14.eglChooseConfig(mEglDisplay, eglConfigAttribList, 0,
-                    eglConfigs, 0, eglConfigs.length, numEglConfigs, 0)) {
-                logEglError("eglChooseConfig");
-                return false;
-            }
-            mEglConfig = eglConfigs[0];
-        }
-
-        if (mEglContext == null) {
-            int[] eglContextAttribList = new int[] {
-                    EGL14.EGL_NONE
-            };
-            mEglContext = EGL14.eglCreateContext(mEglDisplay, mEglConfig,
-                    EGL14.EGL_NO_CONTEXT, eglContextAttribList, 0);
-            if (mEglContext == null) {
-                logEglError("eglCreateContext");
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /* not used because it is too expensive to create / destroy contexts all of the time
-    private void destroyEglContext() {
-        if (mEglContext != null) {
-            if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) {
-                logEglError("eglDestroyContext");
-            }
-            mEglContext = null;
-        }
-    }*/
-
-    private boolean createSurface() {
-        if (mSurfaceSession == null) {
-            mSurfaceSession = new SurfaceSession();
-        }
-
-        SurfaceControl.openTransaction();
-        try {
-            if (mSurfaceControl == null) {
-                try {
-                    int flags;
-                    if (mMode == MODE_FADE) {
-                        flags = SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN;
-                    } else {
-                        flags = SurfaceControl.OPAQUE | SurfaceControl.HIDDEN;
-                    }
-                    mSurfaceControl = new SurfaceControl(mSurfaceSession,
-                            "ElectronBeam", mDisplayWidth, mDisplayHeight,
-                            PixelFormat.OPAQUE, flags);
-                } catch (OutOfResourcesException ex) {
-                    Slog.e(TAG, "Unable to create surface.", ex);
-                    return false;
-                }
-            }
-
-            mSurfaceControl.setLayerStack(mDisplayLayerStack);
-            mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight);
-            mSurface = new Surface();
-            mSurface.copyFrom(mSurfaceControl);
-
-            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManager, mSurfaceControl);
-            mSurfaceLayout.onDisplayTransaction();
-        } finally {
-            SurfaceControl.closeTransaction();
-        }
-        return true;
-    }
-
-    private boolean createEglSurface() {
-        if (mEglSurface == null) {
-            int[] eglSurfaceAttribList = new int[] {
-                    EGL14.EGL_NONE
-            };
-            // turn our SurfaceControl into a Surface
-            mEglSurface = EGL14.eglCreateWindowSurface(mEglDisplay, mEglConfig, mSurface,
-                    eglSurfaceAttribList, 0);
-            if (mEglSurface == null) {
-                logEglError("eglCreateWindowSurface");
-                return false;
-            }
-        }
-        return true;
-    }
-
-    private void destroyEglSurface() {
-        if (mEglSurface != null) {
-            if (!EGL14.eglDestroySurface(mEglDisplay, mEglSurface)) {
-                logEglError("eglDestroySurface");
-            }
-            mEglSurface = null;
-        }
-    }
-
-    private void destroySurface() {
-        if (mSurfaceControl != null) {
-            mSurfaceLayout.dispose();
-            mSurfaceLayout = null;
-            SurfaceControl.openTransaction();
-            try {
-                mSurfaceControl.destroy();
-                mSurface.release();
-            } finally {
-                SurfaceControl.closeTransaction();
-            }
-            mSurfaceControl = null;
-            mSurfaceVisible = false;
-            mSurfaceAlpha = 0f;
-        }
-    }
-
-    private boolean showSurface(float alpha) {
-        if (!mSurfaceVisible || mSurfaceAlpha != alpha) {
-            SurfaceControl.openTransaction();
-            try {
-                mSurfaceControl.setLayer(ELECTRON_BEAM_LAYER);
-                mSurfaceControl.setAlpha(alpha);
-                mSurfaceControl.show();
-            } finally {
-                SurfaceControl.closeTransaction();
-            }
-            mSurfaceVisible = true;
-            mSurfaceAlpha = alpha;
-        }
-        return true;
-    }
-
-    private boolean attachEglContext() {
-        if (mEglSurface == null) {
-            return false;
-        }
-        if (!EGL14.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
-            logEglError("eglMakeCurrent");
-            return false;
-        }
-        return true;
-    }
-
-    private void detachEglContext() {
-        if (mEglDisplay != null) {
-            EGL14.eglMakeCurrent(mEglDisplay,
-                    EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
-        }
-    }
-
-    /**
-     * Interpolates a value in the range 0 .. 1 along a sigmoid curve
-     * yielding a result in the range 0 .. 1 scaled such that:
-     * scurve(0) == 0, scurve(0.5) == 0.5, scurve(1) == 1.
-     */
-    private static float scurve(float value, float s) {
-        // A basic sigmoid has the form y = 1.0f / FloatMap.exp(-x * s).
-        // Here we take the input datum and shift it by 0.5 so that the
-        // domain spans the range -0.5 .. 0.5 instead of 0 .. 1.
-        final float x = value - 0.5f;
-
-        // Next apply the sigmoid function to the scaled value
-        // which produces a value in the range 0 .. 1 so we subtract
-        // 0.5 to get a value in the range -0.5 .. 0.5 instead.
-        final float y = sigmoid(x, s) - 0.5f;
-
-        // To obtain the desired boundary conditions we need to scale
-        // the result so that it fills a range of -1 .. 1.
-        final float v = sigmoid(0.5f, s) - 0.5f;
-
-        // And finally remap the value back to a range of 0 .. 1.
-        return y / v * 0.5f + 0.5f;
-    }
-
-    private static float sigmoid(float x, float s) {
-        return 1.0f / (1.0f + FloatMath.exp(-x * s));
-    }
-
-    private static FloatBuffer createNativeFloatBuffer(int size) {
-        ByteBuffer bb = ByteBuffer.allocateDirect(size * 4);
-        bb.order(ByteOrder.nativeOrder());
-        return bb.asFloatBuffer();
-    }
-
-    private static void logEglError(String func) {
-        Slog.e(TAG, func + " failed: error " + EGL14.eglGetError(), new Throwable());
-    }
-
-    private static boolean checkGlErrors(String func) {
-        return checkGlErrors(func, true);
-    }
-
-    private static boolean checkGlErrors(String func, boolean log) {
-        boolean hadError = false;
-        int error;
-        while ((error = GLES10.glGetError()) != GLES10.GL_NO_ERROR) {
-            if (log) {
-                Slog.e(TAG, func + " failed: error " + error, new Throwable());
-            }
-            hadError = true;
-        }
-        return hadError;
-    }
-
-    public void dump(PrintWriter pw) {
-        pw.println();
-        pw.println("Electron Beam State:");
-        pw.println("  mPrepared=" + mPrepared);
-        pw.println("  mMode=" + mMode);
-        pw.println("  mDisplayLayerStack=" + mDisplayLayerStack);
-        pw.println("  mDisplayWidth=" + mDisplayWidth);
-        pw.println("  mDisplayHeight=" + mDisplayHeight);
-        pw.println("  mSurfaceVisible=" + mSurfaceVisible);
-        pw.println("  mSurfaceAlpha=" + mSurfaceAlpha);
-    }
-
-    /**
-     * Keeps a surface aligned with the natural orientation of the device.
-     * Updates the position and transformation of the matrix whenever the display
-     * is rotated.  This is a little tricky because the display transaction
-     * callback can be invoked on any thread, not necessarily the thread that
-     * owns the electron beam.
-     */
-    private static final class NaturalSurfaceLayout implements DisplayTransactionListener {
-        private final DisplayManagerService mDisplayManager;
-        private SurfaceControl mSurfaceControl;
-
-        public NaturalSurfaceLayout(DisplayManagerService displayManager, SurfaceControl surfaceControl) {
-            mDisplayManager = displayManager;
-            mSurfaceControl = surfaceControl;
-            mDisplayManager.registerDisplayTransactionListener(this);
-        }
-
-        public void dispose() {
-            synchronized (this) {
-                mSurfaceControl = null;
-            }
-            mDisplayManager.unregisterDisplayTransactionListener(this);
-        }
-
-        @Override
-        public void onDisplayTransaction() {
-            synchronized (this) {
-                if (mSurfaceControl == null) {
-                    return;
-                }
-
-                DisplayInfo displayInfo = mDisplayManager.getDisplayInfo(Display.DEFAULT_DISPLAY);
-                switch (displayInfo.rotation) {
-                    case Surface.ROTATION_0:
-                        mSurfaceControl.setPosition(0, 0);
-                        mSurfaceControl.setMatrix(1, 0, 0, 1);
-                        break;
-                    case Surface.ROTATION_90:
-                        mSurfaceControl.setPosition(0, displayInfo.logicalHeight);
-                        mSurfaceControl.setMatrix(0, -1, 1, 0);
-                        break;
-                    case Surface.ROTATION_180:
-                        mSurfaceControl.setPosition(displayInfo.logicalWidth, displayInfo.logicalHeight);
-                        mSurfaceControl.setMatrix(-1, 0, 0, -1);
-                        break;
-                    case Surface.ROTATION_270:
-                        mSurfaceControl.setPosition(displayInfo.logicalWidth, 0);
-                        mSurfaceControl.setMatrix(0, 1, -1, 0);
-                        break;
-                }
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java
deleted file mode 100644
index 134718b..0000000
--- a/services/java/com/android/server/power/PowerManagerService.java
+++ /dev/null
@@ -1,2741 +0,0 @@
-/*
- * Copyright (C) 2007 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.power;
-
-import com.android.internal.app.IAppOpsService;
-import com.android.internal.app.IBatteryStats;
-import com.android.server.BatteryService;
-import com.android.server.EventLogTags;
-import com.android.server.LightsService;
-import com.android.server.TwilightService;
-import com.android.server.Watchdog;
-import com.android.server.am.ActivityManagerService;
-import com.android.server.display.DisplayManagerService;
-import com.android.server.dreams.DreamManagerService;
-
-import android.Manifest;
-import android.content.BroadcastReceiver;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.database.ContentObserver;
-import android.hardware.SensorManager;
-import android.hardware.SystemSensorManager;
-import android.net.Uri;
-import android.os.BatteryManager;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.IBinder;
-import android.os.IPowerManager;
-import android.os.Looper;
-import android.os.Message;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.SystemService;
-import android.os.UserHandle;
-import android.os.WorkSource;
-import android.provider.Settings;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.Slog;
-import android.util.TimeUtils;
-import android.view.WindowManagerPolicy;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-import libcore.util.Objects;
-
-/**
- * The power manager service is responsible for coordinating power management
- * functions on the device.
- */
-public final class PowerManagerService extends IPowerManager.Stub
-        implements Watchdog.Monitor {
-    private static final String TAG = "PowerManagerService";
-
-    private static final boolean DEBUG = false;
-    private static final boolean DEBUG_SPEW = DEBUG && true;
-
-    // Message: Sent when a user activity timeout occurs to update the power state.
-    private static final int MSG_USER_ACTIVITY_TIMEOUT = 1;
-    // Message: Sent when the device enters or exits a napping or dreaming state.
-    private static final int MSG_SANDMAN = 2;
-    // Message: Sent when the screen on blocker is released.
-    private static final int MSG_SCREEN_ON_BLOCKER_RELEASED = 3;
-    // Message: Sent to poll whether the boot animation has terminated.
-    private static final int MSG_CHECK_IF_BOOT_ANIMATION_FINISHED = 4;
-
-    // Dirty bit: mWakeLocks changed
-    private static final int DIRTY_WAKE_LOCKS = 1 << 0;
-    // Dirty bit: mWakefulness changed
-    private static final int DIRTY_WAKEFULNESS = 1 << 1;
-    // Dirty bit: user activity was poked or may have timed out
-    private static final int DIRTY_USER_ACTIVITY = 1 << 2;
-    // Dirty bit: actual display power state was updated asynchronously
-    private static final int DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED = 1 << 3;
-    // Dirty bit: mBootCompleted changed
-    private static final int DIRTY_BOOT_COMPLETED = 1 << 4;
-    // Dirty bit: settings changed
-    private static final int DIRTY_SETTINGS = 1 << 5;
-    // Dirty bit: mIsPowered changed
-    private static final int DIRTY_IS_POWERED = 1 << 6;
-    // Dirty bit: mStayOn changed
-    private static final int DIRTY_STAY_ON = 1 << 7;
-    // Dirty bit: battery state changed
-    private static final int DIRTY_BATTERY_STATE = 1 << 8;
-    // Dirty bit: proximity state changed
-    private static final int DIRTY_PROXIMITY_POSITIVE = 1 << 9;
-    // Dirty bit: screen on blocker state became held or unheld
-    private static final int DIRTY_SCREEN_ON_BLOCKER_RELEASED = 1 << 10;
-    // Dirty bit: dock state changed
-    private static final int DIRTY_DOCK_STATE = 1 << 11;
-
-    // Wakefulness: The device is asleep and can only be awoken by a call to wakeUp().
-    // The screen should be off or in the process of being turned off by the display controller.
-    private static final int WAKEFULNESS_ASLEEP = 0;
-    // Wakefulness: The device is fully awake.  It can be put to sleep by a call to goToSleep().
-    // When the user activity timeout expires, the device may start napping or go to sleep.
-    private static final int WAKEFULNESS_AWAKE = 1;
-    // Wakefulness: The device is napping.  It is deciding whether to dream or go to sleep
-    // but hasn't gotten around to it yet.  It can be awoken by a call to wakeUp(), which
-    // ends the nap. User activity may brighten the screen but does not end the nap.
-    private static final int WAKEFULNESS_NAPPING = 2;
-    // Wakefulness: The device is dreaming.  It can be awoken by a call to wakeUp(),
-    // which ends the dream.  The device goes to sleep when goToSleep() is called, when
-    // the dream ends or when unplugged.
-    // User activity may brighten the screen but does not end the dream.
-    private static final int WAKEFULNESS_DREAMING = 3;
-
-    // Summarizes the state of all active wakelocks.
-    private static final int WAKE_LOCK_CPU = 1 << 0;
-    private static final int WAKE_LOCK_SCREEN_BRIGHT = 1 << 1;
-    private static final int WAKE_LOCK_SCREEN_DIM = 1 << 2;
-    private static final int WAKE_LOCK_BUTTON_BRIGHT = 1 << 3;
-    private static final int WAKE_LOCK_PROXIMITY_SCREEN_OFF = 1 << 4;
-    private static final int WAKE_LOCK_STAY_AWAKE = 1 << 5; // only set if already awake
-
-    // Summarizes the user activity state.
-    private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0;
-    private static final int USER_ACTIVITY_SCREEN_DIM = 1 << 1;
-
-    // Default and minimum screen off timeout in milliseconds.
-    private static final int DEFAULT_SCREEN_OFF_TIMEOUT = 15 * 1000;
-    private static final int MINIMUM_SCREEN_OFF_TIMEOUT = 10 * 1000;
-
-    // The screen dim duration, in milliseconds.
-    // This is subtracted from the end of the screen off timeout so the
-    // minimum screen off timeout should be longer than this.
-    private static final int SCREEN_DIM_DURATION = 7 * 1000;
-
-    // The maximum screen dim time expressed as a ratio relative to the screen
-    // off timeout.  If the screen off timeout is very short then we want the
-    // dim timeout to also be quite short so that most of the time is spent on.
-    // Otherwise the user won't get much screen on time before dimming occurs.
-    private static final float MAXIMUM_SCREEN_DIM_RATIO = 0.2f;
-
-    // The name of the boot animation service in init.rc.
-    private static final String BOOT_ANIMATION_SERVICE = "bootanim";
-
-    // Poll interval in milliseconds for watching boot animation finished.
-    private static final int BOOT_ANIMATION_POLL_INTERVAL = 200;
-
-    // If the battery level drops by this percentage and the user activity timeout
-    // has expired, then assume the device is receiving insufficient current to charge
-    // effectively and terminate the dream.
-    private static final int DREAM_BATTERY_LEVEL_DRAIN_CUTOFF = 5;
-
-    private Context mContext;
-    private LightsService mLightsService;
-    private BatteryService mBatteryService;
-    private DisplayManagerService mDisplayManagerService;
-    private IBatteryStats mBatteryStats;
-    private IAppOpsService mAppOps;
-    private HandlerThread mHandlerThread;
-    private PowerManagerHandler mHandler;
-    private WindowManagerPolicy mPolicy;
-    private Notifier mNotifier;
-    private DisplayPowerController mDisplayPowerController;
-    private WirelessChargerDetector mWirelessChargerDetector;
-    private SettingsObserver mSettingsObserver;
-    private DreamManagerService mDreamManager;
-    private LightsService.Light mAttentionLight;
-
-    private final Object mLock = new Object();
-
-    // A bitfield that indicates what parts of the power state have
-    // changed and need to be recalculated.
-    private int mDirty;
-
-    // Indicates whether the device is awake or asleep or somewhere in between.
-    // This is distinct from the screen power state, which is managed separately.
-    private int mWakefulness;
-
-    // True if MSG_SANDMAN has been scheduled.
-    private boolean mSandmanScheduled;
-
-    // Table of all suspend blockers.
-    // There should only be a few of these.
-    private final ArrayList<SuspendBlocker> mSuspendBlockers = new ArrayList<SuspendBlocker>();
-
-    // Table of all wake locks acquired by applications.
-    private final ArrayList<WakeLock> mWakeLocks = new ArrayList<WakeLock>();
-
-    // A bitfield that summarizes the state of all active wakelocks.
-    private int mWakeLockSummary;
-
-    // If true, instructs the display controller to wait for the proximity sensor to
-    // go negative before turning the screen on.
-    private boolean mRequestWaitForNegativeProximity;
-
-    // Timestamp of the last time the device was awoken or put to sleep.
-    private long mLastWakeTime;
-    private long mLastSleepTime;
-
-    // True if we need to send a wake up or go to sleep finished notification
-    // when the display is ready.
-    private boolean mSendWakeUpFinishedNotificationWhenReady;
-    private boolean mSendGoToSleepFinishedNotificationWhenReady;
-
-    // Timestamp of the last call to user activity.
-    private long mLastUserActivityTime;
-    private long mLastUserActivityTimeNoChangeLights;
-
-    // A bitfield that summarizes the effect of the user activity timer.
-    // A zero value indicates that the user activity timer has expired.
-    private int mUserActivitySummary;
-
-    // The desired display power state.  The actual state may lag behind the
-    // requested because it is updated asynchronously by the display power controller.
-    private final DisplayPowerRequest mDisplayPowerRequest = new DisplayPowerRequest();
-
-    // The time the screen was last turned off, in elapsedRealtime() timebase.
-    private long mLastScreenOffEventElapsedRealTime;
-
-    // True if the display power state has been fully applied, which means the display
-    // is actually on or actually off or whatever was requested.
-    private boolean mDisplayReady;
-
-    // The suspend blocker used to keep the CPU alive when an application has acquired
-    // a wake lock.
-    private final SuspendBlocker mWakeLockSuspendBlocker;
-
-    // True if the wake lock suspend blocker has been acquired.
-    private boolean mHoldingWakeLockSuspendBlocker;
-
-    // The suspend blocker used to keep the CPU alive when the display is on, the
-    // display is getting ready or there is user activity (in which case the display
-    // must be on).
-    private final SuspendBlocker mDisplaySuspendBlocker;
-
-    // True if the display suspend blocker has been acquired.
-    private boolean mHoldingDisplaySuspendBlocker;
-
-    // The screen on blocker used to keep the screen from turning on while the lock
-    // screen is coming up.
-    private final ScreenOnBlockerImpl mScreenOnBlocker;
-
-    // The display blanker used to turn the screen on or off.
-    private final DisplayBlankerImpl mDisplayBlanker;
-
-    // True if systemReady() has been called.
-    private boolean mSystemReady;
-
-    // True if boot completed occurred.  We keep the screen on until this happens.
-    private boolean mBootCompleted;
-
-    // True if the device is plugged into a power source.
-    private boolean mIsPowered;
-
-    // The current plug type, such as BatteryManager.BATTERY_PLUGGED_WIRELESS.
-    private int mPlugType;
-
-    // The current battery level percentage.
-    private int mBatteryLevel;
-
-    // The battery level percentage at the time the dream started.
-    // This is used to terminate a dream and go to sleep if the battery is
-    // draining faster than it is charging and the user activity timeout has expired.
-    private int mBatteryLevelWhenDreamStarted;
-
-    // The current dock state.
-    private int mDockState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
-
-    // True if the device should wake up when plugged or unplugged.
-    private boolean mWakeUpWhenPluggedOrUnpluggedConfig;
-
-    // True if the device should suspend when the screen is off due to proximity.
-    private boolean mSuspendWhenScreenOffDueToProximityConfig;
-
-    // True if dreams are supported on this device.
-    private boolean mDreamsSupportedConfig;
-
-    // Default value for dreams enabled
-    private boolean mDreamsEnabledByDefaultConfig;
-
-    // Default value for dreams activate-on-sleep
-    private boolean mDreamsActivatedOnSleepByDefaultConfig;
-
-    // Default value for dreams activate-on-dock
-    private boolean mDreamsActivatedOnDockByDefaultConfig;
-
-    // True if dreams are enabled by the user.
-    private boolean mDreamsEnabledSetting;
-
-    // True if dreams should be activated on sleep.
-    private boolean mDreamsActivateOnSleepSetting;
-
-    // True if dreams should be activated on dock.
-    private boolean mDreamsActivateOnDockSetting;
-
-    // The screen off timeout setting value in milliseconds.
-    private int mScreenOffTimeoutSetting;
-
-    // The maximum allowable screen off timeout according to the device
-    // administration policy.  Overrides other settings.
-    private int mMaximumScreenOffTimeoutFromDeviceAdmin = Integer.MAX_VALUE;
-
-    // The stay on while plugged in setting.
-    // A bitfield of battery conditions under which to make the screen stay on.
-    private int mStayOnWhilePluggedInSetting;
-
-    // True if the device should stay on.
-    private boolean mStayOn;
-
-    // True if the proximity sensor reads a positive result.
-    private boolean mProximityPositive;
-
-    // Screen brightness setting limits.
-    private int mScreenBrightnessSettingMinimum;
-    private int mScreenBrightnessSettingMaximum;
-    private int mScreenBrightnessSettingDefault;
-
-    // The screen brightness setting, from 0 to 255.
-    // Use -1 if no value has been set.
-    private int mScreenBrightnessSetting;
-
-    // The screen auto-brightness adjustment setting, from -1 to 1.
-    // Use 0 if there is no adjustment.
-    private float mScreenAutoBrightnessAdjustmentSetting;
-
-    // The screen brightness mode.
-    // One of the Settings.System.SCREEN_BRIGHTNESS_MODE_* constants.
-    private int mScreenBrightnessModeSetting;
-
-    // The screen brightness setting override from the window manager
-    // to allow the current foreground activity to override the brightness.
-    // Use -1 to disable.
-    private int mScreenBrightnessOverrideFromWindowManager = -1;
-
-    // The user activity timeout override from the window manager
-    // to allow the current foreground activity to override the user activity timeout.
-    // Use -1 to disable.
-    private long mUserActivityTimeoutOverrideFromWindowManager = -1;
-
-    // The screen brightness setting override from the settings application
-    // to temporarily adjust the brightness until next updated,
-    // Use -1 to disable.
-    private int mTemporaryScreenBrightnessSettingOverride = -1;
-
-    // The screen brightness adjustment setting override from the settings
-    // application to temporarily adjust the auto-brightness adjustment factor
-    // until next updated, in the range -1..1.
-    // Use NaN to disable.
-    private float mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = Float.NaN;
-
-    // Time when we last logged a warning about calling userActivity() without permission.
-    private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE;
-
-    private native void nativeInit();
-
-    private static native void nativeSetPowerState(boolean screenOn, boolean screenBright);
-    private static native void nativeAcquireSuspendBlocker(String name);
-    private static native void nativeReleaseSuspendBlocker(String name);
-    private static native void nativeSetInteractive(boolean enable);
-    private static native void nativeSetAutoSuspend(boolean enable);
-
-    public PowerManagerService() {
-        synchronized (mLock) {
-            mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks");
-            mDisplaySuspendBlocker = createSuspendBlockerLocked("PowerManagerService.Display");
-            mDisplaySuspendBlocker.acquire();
-            mHoldingDisplaySuspendBlocker = true;
-
-            mScreenOnBlocker = new ScreenOnBlockerImpl();
-            mDisplayBlanker = new DisplayBlankerImpl();
-            mWakefulness = WAKEFULNESS_AWAKE;
-        }
-
-        nativeInit();
-        nativeSetPowerState(true, true);
-    }
-
-    /**
-     * Initialize the power manager.
-     * Must be called before any other functions within the power manager are called.
-     */
-    public void init(Context context, LightsService ls,
-            ActivityManagerService am, BatteryService bs, IBatteryStats bss,
-            IAppOpsService appOps, DisplayManagerService dm) {
-        mContext = context;
-        mLightsService = ls;
-        mBatteryService = bs;
-        mBatteryStats = bss;
-        mAppOps = appOps;
-        mDisplayManagerService = dm;
-        mHandlerThread = new HandlerThread(TAG);
-        mHandlerThread.start();
-        mHandler = new PowerManagerHandler(mHandlerThread.getLooper());
-
-        Watchdog.getInstance().addMonitor(this);
-        Watchdog.getInstance().addThread(mHandler, mHandlerThread.getName());
-
-        // Forcibly turn the screen on at boot so that it is in a known power state.
-        // We do this in init() rather than in the constructor because setting the
-        // screen state requires a call into surface flinger which then needs to call back
-        // into the activity manager to check permissions.  Unfortunately the
-        // activity manager is not running when the constructor is called, so we
-        // have to defer setting the screen state until this point.
-        mDisplayBlanker.unblankAllDisplays();
-    }
-
-    public void setPolicy(WindowManagerPolicy policy) {
-        synchronized (mLock) {
-            mPolicy = policy;
-        }
-    }
-
-    public void systemReady(TwilightService twilight, DreamManagerService dreamManager) {
-        synchronized (mLock) {
-            mSystemReady = true;
-            mDreamManager = dreamManager;
-
-            PowerManager pm = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
-            mScreenBrightnessSettingMinimum = pm.getMinimumScreenBrightnessSetting();
-            mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting();
-            mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting();
-
-            SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper());
-
-            // The notifier runs on the system server's main looper so as not to interfere
-            // with the animations and other critical functions of the power manager.
-            mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats,
-                    mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
-                    mScreenOnBlocker, mPolicy);
-
-            // The display power controller runs on the power manager service's
-            // own handler thread to ensure timely operation.
-            mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(),
-                    mContext, mNotifier, mLightsService, twilight, sensorManager,
-                    mDisplayManagerService, mDisplaySuspendBlocker, mDisplayBlanker,
-                    mDisplayPowerControllerCallbacks, mHandler);
-
-            mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
-                    createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"),
-                    mHandler);
-            mSettingsObserver = new SettingsObserver(mHandler);
-            mAttentionLight = mLightsService.getLight(LightsService.LIGHT_ID_ATTENTION);
-
-            // Register for broadcasts from other components of the system.
-            IntentFilter filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_BATTERY_CHANGED);
-            mContext.registerReceiver(new BatteryReceiver(), filter, null, mHandler);
-
-            filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_BOOT_COMPLETED);
-            mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler);
-
-            filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_DREAMING_STARTED);
-            filter.addAction(Intent.ACTION_DREAMING_STOPPED);
-            mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler);
-
-            filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_USER_SWITCHED);
-            mContext.registerReceiver(new UserSwitchedReceiver(), filter, null, mHandler);
-
-            filter = new IntentFilter();
-            filter.addAction(Intent.ACTION_DOCK_EVENT);
-            mContext.registerReceiver(new DockReceiver(), filter, null, mHandler);
-
-            // Register for settings changes.
-            final ContentResolver resolver = mContext.getContentResolver();
-            resolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.SCREENSAVER_ENABLED),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-            resolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-            resolver.registerContentObserver(Settings.Secure.getUriFor(
-                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-            resolver.registerContentObserver(Settings.System.getUriFor(
-                    Settings.System.SCREEN_OFF_TIMEOUT),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-            resolver.registerContentObserver(Settings.Global.getUriFor(
-                    Settings.Global.STAY_ON_WHILE_PLUGGED_IN),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-            resolver.registerContentObserver(Settings.System.getUriFor(
-                    Settings.System.SCREEN_BRIGHTNESS),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-            resolver.registerContentObserver(Settings.System.getUriFor(
-                    Settings.System.SCREEN_BRIGHTNESS_MODE),
-                    false, mSettingsObserver, UserHandle.USER_ALL);
-
-            // Go.
-            readConfigurationLocked();
-            updateSettingsLocked();
-            mDirty |= DIRTY_BATTERY_STATE;
-            updatePowerStateLocked();
-        }
-    }
-
-    private void readConfigurationLocked() {
-        final Resources resources = mContext.getResources();
-
-        mWakeUpWhenPluggedOrUnpluggedConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_unplugTurnsOnScreen);
-        mSuspendWhenScreenOffDueToProximityConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);
-        mDreamsSupportedConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_dreamsSupported);
-        mDreamsEnabledByDefaultConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_dreamsEnabledByDefault);
-        mDreamsActivatedOnSleepByDefaultConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
-        mDreamsActivatedOnDockByDefaultConfig = resources.getBoolean(
-                com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
-    }
-
-    private void updateSettingsLocked() {
-        final ContentResolver resolver = mContext.getContentResolver();
-
-        mDreamsEnabledSetting = (Settings.Secure.getIntForUser(resolver,
-                Settings.Secure.SCREENSAVER_ENABLED,
-                mDreamsEnabledByDefaultConfig ? 1 : 0,
-                UserHandle.USER_CURRENT) != 0);
-        mDreamsActivateOnSleepSetting = (Settings.Secure.getIntForUser(resolver,
-                Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
-                mDreamsActivatedOnSleepByDefaultConfig ? 1 : 0,
-                UserHandle.USER_CURRENT) != 0);
-        mDreamsActivateOnDockSetting = (Settings.Secure.getIntForUser(resolver,
-                Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK,
-                mDreamsActivatedOnDockByDefaultConfig ? 1 : 0,
-                UserHandle.USER_CURRENT) != 0);
-        mScreenOffTimeoutSetting = Settings.System.getIntForUser(resolver,
-                Settings.System.SCREEN_OFF_TIMEOUT, DEFAULT_SCREEN_OFF_TIMEOUT,
-                UserHandle.USER_CURRENT);
-        mStayOnWhilePluggedInSetting = Settings.Global.getInt(resolver,
-                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, BatteryManager.BATTERY_PLUGGED_AC);
-
-        final int oldScreenBrightnessSetting = mScreenBrightnessSetting;
-        mScreenBrightnessSetting = Settings.System.getIntForUser(resolver,
-                Settings.System.SCREEN_BRIGHTNESS, mScreenBrightnessSettingDefault,
-                UserHandle.USER_CURRENT);
-        if (oldScreenBrightnessSetting != mScreenBrightnessSetting) {
-            mTemporaryScreenBrightnessSettingOverride = -1;
-        }
-
-        final float oldScreenAutoBrightnessAdjustmentSetting =
-                mScreenAutoBrightnessAdjustmentSetting;
-        mScreenAutoBrightnessAdjustmentSetting = Settings.System.getFloatForUser(resolver,
-                Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0.0f,
-                UserHandle.USER_CURRENT);
-        if (oldScreenAutoBrightnessAdjustmentSetting != mScreenAutoBrightnessAdjustmentSetting) {
-            mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = Float.NaN;
-        }
-
-        mScreenBrightnessModeSetting = Settings.System.getIntForUser(resolver,
-                Settings.System.SCREEN_BRIGHTNESS_MODE,
-                Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
-
-        mDirty |= DIRTY_SETTINGS;
-    }
-
-    private void handleSettingsChangedLocked() {
-        updateSettingsLocked();
-        updatePowerStateLocked();
-    }
-
-    @Override // Binder call
-    public void acquireWakeLockWithUid(IBinder lock, int flags, String tag, String packageName,
-            int uid) {
-        acquireWakeLock(lock, flags, tag, packageName, new WorkSource(uid));
-    }
-
-    @Override // Binder call
-    public void acquireWakeLock(IBinder lock, int flags, String tag, String packageName,
-            WorkSource ws) {
-        if (lock == null) {
-            throw new IllegalArgumentException("lock must not be null");
-        }
-        if (packageName == null) {
-            throw new IllegalArgumentException("packageName must not be null");
-        }
-        PowerManager.validateWakeLockParameters(flags, tag);
-
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
-        if (ws != null && ws.size() != 0) {
-            mContext.enforceCallingOrSelfPermission(
-                    android.Manifest.permission.UPDATE_DEVICE_STATS, null);
-        } else {
-            ws = null;
-        }
-
-        final int uid = Binder.getCallingUid();
-        final int pid = Binder.getCallingPid();
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            acquireWakeLockInternal(lock, flags, tag, packageName, ws, uid, pid);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void acquireWakeLockInternal(IBinder lock, int flags, String tag, String packageName,
-            WorkSource ws, int uid, int pid) {
-        synchronized (mLock) {
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "acquireWakeLockInternal: lock=" + Objects.hashCode(lock)
-                        + ", flags=0x" + Integer.toHexString(flags)
-                        + ", tag=\"" + tag + "\", ws=" + ws + ", uid=" + uid + ", pid=" + pid);
-            }
-
-            WakeLock wakeLock;
-            int index = findWakeLockIndexLocked(lock);
-            if (index >= 0) {
-                wakeLock = mWakeLocks.get(index);
-                if (!wakeLock.hasSameProperties(flags, tag, ws, uid, pid)) {
-                    // Update existing wake lock.  This shouldn't happen but is harmless.
-                    notifyWakeLockReleasedLocked(wakeLock);
-                    wakeLock.updateProperties(flags, tag, packageName, ws, uid, pid);
-                    notifyWakeLockAcquiredLocked(wakeLock);
-                }
-            } else {
-                wakeLock = new WakeLock(lock, flags, tag, packageName, ws, uid, pid);
-                try {
-                    lock.linkToDeath(wakeLock, 0);
-                } catch (RemoteException ex) {
-                    throw new IllegalArgumentException("Wake lock is already dead.");
-                }
-                notifyWakeLockAcquiredLocked(wakeLock);
-                mWakeLocks.add(wakeLock);
-            }
-
-            applyWakeLockFlagsOnAcquireLocked(wakeLock);
-            mDirty |= DIRTY_WAKE_LOCKS;
-            updatePowerStateLocked();
-        }
-    }
-
-    @SuppressWarnings("deprecation")
-    private static boolean isScreenLock(final WakeLock wakeLock) {
-        switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
-            case PowerManager.FULL_WAKE_LOCK:
-            case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
-            case PowerManager.SCREEN_DIM_WAKE_LOCK:
-                return true;
-        }
-        return false;
-    }
-
-    private void applyWakeLockFlagsOnAcquireLocked(WakeLock wakeLock) {
-        if ((wakeLock.mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0
-                && isScreenLock(wakeLock)) {
-            wakeUpNoUpdateLocked(SystemClock.uptimeMillis());
-        }
-    }
-
-    @Override // Binder call
-    public void releaseWakeLock(IBinder lock, int flags) {
-        if (lock == null) {
-            throw new IllegalArgumentException("lock must not be null");
-        }
-
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            releaseWakeLockInternal(lock, flags);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void releaseWakeLockInternal(IBinder lock, int flags) {
-        synchronized (mLock) {
-            int index = findWakeLockIndexLocked(lock);
-            if (index < 0) {
-                if (DEBUG_SPEW) {
-                    Slog.d(TAG, "releaseWakeLockInternal: lock=" + Objects.hashCode(lock)
-                            + " [not found], flags=0x" + Integer.toHexString(flags));
-                }
-                return;
-            }
-
-            WakeLock wakeLock = mWakeLocks.get(index);
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "releaseWakeLockInternal: lock=" + Objects.hashCode(lock)
-                        + " [" + wakeLock.mTag + "], flags=0x" + Integer.toHexString(flags));
-            }
-
-            mWakeLocks.remove(index);
-            notifyWakeLockReleasedLocked(wakeLock);
-            wakeLock.mLock.unlinkToDeath(wakeLock, 0);
-
-            if ((flags & PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE) != 0) {
-                mRequestWaitForNegativeProximity = true;
-            }
-
-            applyWakeLockFlagsOnReleaseLocked(wakeLock);
-            mDirty |= DIRTY_WAKE_LOCKS;
-            updatePowerStateLocked();
-        }
-    }
-
-    private void handleWakeLockDeath(WakeLock wakeLock) {
-        synchronized (mLock) {
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "handleWakeLockDeath: lock=" + Objects.hashCode(wakeLock.mLock)
-                        + " [" + wakeLock.mTag + "]");
-            }
-
-            int index = mWakeLocks.indexOf(wakeLock);
-            if (index < 0) {
-                return;
-            }
-
-            mWakeLocks.remove(index);
-            notifyWakeLockReleasedLocked(wakeLock);
-
-            applyWakeLockFlagsOnReleaseLocked(wakeLock);
-            mDirty |= DIRTY_WAKE_LOCKS;
-            updatePowerStateLocked();
-        }
-    }
-
-    private void applyWakeLockFlagsOnReleaseLocked(WakeLock wakeLock) {
-        if ((wakeLock.mFlags & PowerManager.ON_AFTER_RELEASE) != 0
-                && isScreenLock(wakeLock)) {
-            userActivityNoUpdateLocked(SystemClock.uptimeMillis(),
-                    PowerManager.USER_ACTIVITY_EVENT_OTHER,
-                    PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS,
-                    wakeLock.mOwnerUid);
-        }
-    }
-
-    @Override // Binder call
-    public void updateWakeLockUids(IBinder lock, int[] uids) {
-        WorkSource ws = null;
-
-        if (uids != null) {
-            ws = new WorkSource();
-            // XXX should WorkSource have a way to set uids as an int[] instead of adding them
-            // one at a time?
-            for (int i = 0; i < uids.length; i++) {
-                ws.add(uids[i]);
-            }
-        }
-        updateWakeLockWorkSource(lock, ws);
-    }
-
-    @Override // Binder call
-    public void updateWakeLockWorkSource(IBinder lock, WorkSource ws) {
-        if (lock == null) {
-            throw new IllegalArgumentException("lock must not be null");
-        }
-
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
-        if (ws != null && ws.size() != 0) {
-            mContext.enforceCallingOrSelfPermission(
-                    android.Manifest.permission.UPDATE_DEVICE_STATS, null);
-        } else {
-            ws = null;
-        }
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            updateWakeLockWorkSourceInternal(lock, ws);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws) {
-        synchronized (mLock) {
-            int index = findWakeLockIndexLocked(lock);
-            if (index < 0) {
-                if (DEBUG_SPEW) {
-                    Slog.d(TAG, "updateWakeLockWorkSourceInternal: lock=" + Objects.hashCode(lock)
-                            + " [not found], ws=" + ws);
-                }
-                throw new IllegalArgumentException("Wake lock not active");
-            }
-
-            WakeLock wakeLock = mWakeLocks.get(index);
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "updateWakeLockWorkSourceInternal: lock=" + Objects.hashCode(lock)
-                        + " [" + wakeLock.mTag + "], ws=" + ws);
-            }
-
-            if (!wakeLock.hasSameWorkSource(ws)) {
-                notifyWakeLockReleasedLocked(wakeLock);
-                wakeLock.updateWorkSource(ws);
-                notifyWakeLockAcquiredLocked(wakeLock);
-            }
-        }
-    }
-
-    private int findWakeLockIndexLocked(IBinder lock) {
-        final int count = mWakeLocks.size();
-        for (int i = 0; i < count; i++) {
-            if (mWakeLocks.get(i).mLock == lock) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    private void notifyWakeLockAcquiredLocked(WakeLock wakeLock) {
-        if (mSystemReady) {
-            wakeLock.mNotifiedAcquired = true;
-            mNotifier.onWakeLockAcquired(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName,
-                    wakeLock.mOwnerUid, wakeLock.mOwnerPid, wakeLock.mWorkSource);
-        }
-    }
-
-    private void notifyWakeLockReleasedLocked(WakeLock wakeLock) {
-        if (mSystemReady && wakeLock.mNotifiedAcquired) {
-            wakeLock.mNotifiedAcquired = false;
-            mNotifier.onWakeLockReleased(wakeLock.mFlags, wakeLock.mTag, wakeLock.mPackageName,
-                    wakeLock.mOwnerUid, wakeLock.mOwnerPid, wakeLock.mWorkSource);
-        }
-    }
-
-    @Override // Binder call
-    public boolean isWakeLockLevelSupported(int level) {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            return isWakeLockLevelSupportedInternal(level);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @SuppressWarnings("deprecation")
-    private boolean isWakeLockLevelSupportedInternal(int level) {
-        synchronized (mLock) {
-            switch (level) {
-                case PowerManager.PARTIAL_WAKE_LOCK:
-                case PowerManager.SCREEN_DIM_WAKE_LOCK:
-                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
-                case PowerManager.FULL_WAKE_LOCK:
-                    return true;
-
-                case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
-                    return mSystemReady && mDisplayPowerController.isProximitySensorAvailable();
-
-                default:
-                    return false;
-            }
-        }
-    }
-
-    @Override // Binder call
-    public void userActivity(long eventTime, int event, int flags) {
-        final long now = SystemClock.uptimeMillis();
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER)
-                != PackageManager.PERMISSION_GRANTED) {
-            // Once upon a time applications could call userActivity().
-            // Now we require the DEVICE_POWER permission.  Log a warning and ignore the
-            // request instead of throwing a SecurityException so we don't break old apps.
-            synchronized (mLock) {
-                if (now >= mLastWarningAboutUserActivityPermission + (5 * 60 * 1000)) {
-                    mLastWarningAboutUserActivityPermission = now;
-                    Slog.w(TAG, "Ignoring call to PowerManager.userActivity() because the "
-                            + "caller does not have DEVICE_POWER permission.  "
-                            + "Please fix your app!  "
-                            + " pid=" + Binder.getCallingPid()
-                            + " uid=" + Binder.getCallingUid());
-                }
-            }
-            return;
-        }
-
-        if (eventTime > SystemClock.uptimeMillis()) {
-            throw new IllegalArgumentException("event time must not be in the future");
-        }
-
-        final int uid = Binder.getCallingUid();
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            userActivityInternal(eventTime, event, flags, uid);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    // Called from native code.
-    private void userActivityFromNative(long eventTime, int event, int flags) {
-        userActivityInternal(eventTime, event, flags, Process.SYSTEM_UID);
-    }
-
-    private void userActivityInternal(long eventTime, int event, int flags, int uid) {
-        synchronized (mLock) {
-            if (userActivityNoUpdateLocked(eventTime, event, flags, uid)) {
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    private boolean userActivityNoUpdateLocked(long eventTime, int event, int flags, int uid) {
-        if (DEBUG_SPEW) {
-            Slog.d(TAG, "userActivityNoUpdateLocked: eventTime=" + eventTime
-                    + ", event=" + event + ", flags=0x" + Integer.toHexString(flags)
-                    + ", uid=" + uid);
-        }
-
-        if (eventTime < mLastSleepTime || eventTime < mLastWakeTime
-                || mWakefulness == WAKEFULNESS_ASLEEP || !mBootCompleted || !mSystemReady) {
-            return false;
-        }
-
-        mNotifier.onUserActivity(event, uid);
-
-        if ((flags & PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS) != 0) {
-            if (eventTime > mLastUserActivityTimeNoChangeLights
-                    && eventTime > mLastUserActivityTime) {
-                mLastUserActivityTimeNoChangeLights = eventTime;
-                mDirty |= DIRTY_USER_ACTIVITY;
-                return true;
-            }
-        } else {
-            if (eventTime > mLastUserActivityTime) {
-                mLastUserActivityTime = eventTime;
-                mDirty |= DIRTY_USER_ACTIVITY;
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override // Binder call
-    public void wakeUp(long eventTime) {
-        if (eventTime > SystemClock.uptimeMillis()) {
-            throw new IllegalArgumentException("event time must not be in the future");
-        }
-
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            wakeUpInternal(eventTime);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    // Called from native code.
-    private void wakeUpFromNative(long eventTime) {
-        wakeUpInternal(eventTime);
-    }
-
-    private void wakeUpInternal(long eventTime) {
-        synchronized (mLock) {
-            if (wakeUpNoUpdateLocked(eventTime)) {
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    private boolean wakeUpNoUpdateLocked(long eventTime) {
-        if (DEBUG_SPEW) {
-            Slog.d(TAG, "wakeUpNoUpdateLocked: eventTime=" + eventTime);
-        }
-
-        if (eventTime < mLastSleepTime || mWakefulness == WAKEFULNESS_AWAKE
-                || !mBootCompleted || !mSystemReady) {
-            return false;
-        }
-
-        switch (mWakefulness) {
-            case WAKEFULNESS_ASLEEP:
-                Slog.i(TAG, "Waking up from sleep...");
-                sendPendingNotificationsLocked();
-                mNotifier.onWakeUpStarted();
-                mSendWakeUpFinishedNotificationWhenReady = true;
-                break;
-            case WAKEFULNESS_DREAMING:
-                Slog.i(TAG, "Waking up from dream...");
-                break;
-            case WAKEFULNESS_NAPPING:
-                Slog.i(TAG, "Waking up from nap...");
-                break;
-        }
-
-        mLastWakeTime = eventTime;
-        mWakefulness = WAKEFULNESS_AWAKE;
-        mDirty |= DIRTY_WAKEFULNESS;
-
-        userActivityNoUpdateLocked(
-                eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
-        return true;
-    }
-
-    @Override // Binder call
-    public void goToSleep(long eventTime, int reason) {
-        if (eventTime > SystemClock.uptimeMillis()) {
-            throw new IllegalArgumentException("event time must not be in the future");
-        }
-
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            goToSleepInternal(eventTime, reason);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    // Called from native code.
-    private void goToSleepFromNative(long eventTime, int reason) {
-        goToSleepInternal(eventTime, reason);
-    }
-
-    private void goToSleepInternal(long eventTime, int reason) {
-        synchronized (mLock) {
-            if (goToSleepNoUpdateLocked(eventTime, reason)) {
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    @SuppressWarnings("deprecation")
-    private boolean goToSleepNoUpdateLocked(long eventTime, int reason) {
-        if (DEBUG_SPEW) {
-            Slog.d(TAG, "goToSleepNoUpdateLocked: eventTime=" + eventTime + ", reason=" + reason);
-        }
-
-        if (eventTime < mLastWakeTime || mWakefulness == WAKEFULNESS_ASLEEP
-                || !mBootCompleted || !mSystemReady) {
-            return false;
-        }
-
-        switch (reason) {
-            case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN:
-                Slog.i(TAG, "Going to sleep due to device administration policy...");
-                break;
-            case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT:
-                Slog.i(TAG, "Going to sleep due to screen timeout...");
-                break;
-            default:
-                Slog.i(TAG, "Going to sleep by user request...");
-                reason = PowerManager.GO_TO_SLEEP_REASON_USER;
-                break;
-        }
-
-        sendPendingNotificationsLocked();
-        mNotifier.onGoToSleepStarted(reason);
-        mSendGoToSleepFinishedNotificationWhenReady = true;
-
-        mLastSleepTime = eventTime;
-        mDirty |= DIRTY_WAKEFULNESS;
-        mWakefulness = WAKEFULNESS_ASLEEP;
-
-        // Report the number of wake locks that will be cleared by going to sleep.
-        int numWakeLocksCleared = 0;
-        final int numWakeLocks = mWakeLocks.size();
-        for (int i = 0; i < numWakeLocks; i++) {
-            final WakeLock wakeLock = mWakeLocks.get(i);
-            switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
-                case PowerManager.FULL_WAKE_LOCK:
-                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
-                case PowerManager.SCREEN_DIM_WAKE_LOCK:
-                    numWakeLocksCleared += 1;
-                    break;
-            }
-        }
-        EventLog.writeEvent(EventLogTags.POWER_SLEEP_REQUESTED, numWakeLocksCleared);
-        return true;
-    }
-
-    @Override // Binder call
-    public void nap(long eventTime) {
-        if (eventTime > SystemClock.uptimeMillis()) {
-            throw new IllegalArgumentException("event time must not be in the future");
-        }
-
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            napInternal(eventTime);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void napInternal(long eventTime) {
-        synchronized (mLock) {
-            if (napNoUpdateLocked(eventTime)) {
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    private boolean napNoUpdateLocked(long eventTime) {
-        if (DEBUG_SPEW) {
-            Slog.d(TAG, "napNoUpdateLocked: eventTime=" + eventTime);
-        }
-
-        if (eventTime < mLastWakeTime || mWakefulness != WAKEFULNESS_AWAKE
-                || !mBootCompleted || !mSystemReady) {
-            return false;
-        }
-
-        Slog.i(TAG, "Nap time...");
-
-        mDirty |= DIRTY_WAKEFULNESS;
-        mWakefulness = WAKEFULNESS_NAPPING;
-        return true;
-    }
-
-    /**
-     * Updates the global power state based on dirty bits recorded in mDirty.
-     *
-     * This is the main function that performs power state transitions.
-     * We centralize them here so that we can recompute the power state completely
-     * each time something important changes, and ensure that we do it the same
-     * way each time.  The point is to gather all of the transition logic here.
-     */
-    private void updatePowerStateLocked() {
-        if (!mSystemReady || mDirty == 0) {
-            return;
-        }
-        if (!Thread.holdsLock(mLock)) {
-            Slog.wtf(TAG, "Power manager lock was not held when calling updatePowerStateLocked");
-        }
-
-        // Phase 0: Basic state updates.
-        updateIsPoweredLocked(mDirty);
-        updateStayOnLocked(mDirty);
-
-        // Phase 1: Update wakefulness.
-        // Loop because the wake lock and user activity computations are influenced
-        // by changes in wakefulness.
-        final long now = SystemClock.uptimeMillis();
-        int dirtyPhase2 = 0;
-        for (;;) {
-            int dirtyPhase1 = mDirty;
-            dirtyPhase2 |= dirtyPhase1;
-            mDirty = 0;
-
-            updateWakeLockSummaryLocked(dirtyPhase1);
-            updateUserActivitySummaryLocked(now, dirtyPhase1);
-            if (!updateWakefulnessLocked(dirtyPhase1)) {
-                break;
-            }
-        }
-
-        // Phase 2: Update dreams and display power state.
-        updateDreamLocked(dirtyPhase2);
-        updateDisplayPowerStateLocked(dirtyPhase2);
-
-        // Phase 3: Send notifications, if needed.
-        if (mDisplayReady) {
-            sendPendingNotificationsLocked();
-        }
-
-        // Phase 4: Update suspend blocker.
-        // Because we might release the last suspend blocker here, we need to make sure
-        // we finished everything else first!
-        updateSuspendBlockerLocked();
-    }
-
-    private void sendPendingNotificationsLocked() {
-        if (mSendWakeUpFinishedNotificationWhenReady) {
-            mSendWakeUpFinishedNotificationWhenReady = false;
-            mNotifier.onWakeUpFinished();
-        }
-        if (mSendGoToSleepFinishedNotificationWhenReady) {
-            mSendGoToSleepFinishedNotificationWhenReady = false;
-            mNotifier.onGoToSleepFinished();
-        }
-    }
-
-    /**
-     * Updates the value of mIsPowered.
-     * Sets DIRTY_IS_POWERED if a change occurred.
-     */
-    private void updateIsPoweredLocked(int dirty) {
-        if ((dirty & DIRTY_BATTERY_STATE) != 0) {
-            final boolean wasPowered = mIsPowered;
-            final int oldPlugType = mPlugType;
-            mIsPowered = mBatteryService.isPowered(BatteryManager.BATTERY_PLUGGED_ANY);
-            mPlugType = mBatteryService.getPlugType();
-            mBatteryLevel = mBatteryService.getBatteryLevel();
-
-            if (DEBUG) {
-                Slog.d(TAG, "updateIsPoweredLocked: wasPowered=" + wasPowered
-                        + ", mIsPowered=" + mIsPowered
-                        + ", oldPlugType=" + oldPlugType
-                        + ", mPlugType=" + mPlugType
-                        + ", mBatteryLevel=" + mBatteryLevel);
-            }
-
-            if (wasPowered != mIsPowered || oldPlugType != mPlugType) {
-                mDirty |= DIRTY_IS_POWERED;
-
-                // Update wireless dock detection state.
-                final boolean dockedOnWirelessCharger = mWirelessChargerDetector.update(
-                        mIsPowered, mPlugType, mBatteryLevel);
-
-                // Treat plugging and unplugging the devices as a user activity.
-                // Users find it disconcerting when they plug or unplug the device
-                // and it shuts off right away.
-                // Some devices also wake the device when plugged or unplugged because
-                // they don't have a charging LED.
-                final long now = SystemClock.uptimeMillis();
-                if (shouldWakeUpWhenPluggedOrUnpluggedLocked(wasPowered, oldPlugType,
-                        dockedOnWirelessCharger)) {
-                    wakeUpNoUpdateLocked(now);
-                }
-                userActivityNoUpdateLocked(
-                        now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
-
-                // Tell the notifier whether wireless charging has started so that
-                // it can provide feedback to the user.
-                if (dockedOnWirelessCharger) {
-                    mNotifier.onWirelessChargingStarted();
-                }
-            }
-        }
-    }
-
-    private boolean shouldWakeUpWhenPluggedOrUnpluggedLocked(
-            boolean wasPowered, int oldPlugType, boolean dockedOnWirelessCharger) {
-        // Don't wake when powered unless configured to do so.
-        if (!mWakeUpWhenPluggedOrUnpluggedConfig) {
-            return false;
-        }
-
-        // Don't wake when undocked from wireless charger.
-        // See WirelessChargerDetector for justification.
-        if (wasPowered && !mIsPowered
-                && oldPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS) {
-            return false;
-        }
-
-        // Don't wake when docked on wireless charger unless we are certain of it.
-        // See WirelessChargerDetector for justification.
-        if (!wasPowered && mIsPowered
-                && mPlugType == BatteryManager.BATTERY_PLUGGED_WIRELESS
-                && !dockedOnWirelessCharger) {
-            return false;
-        }
-
-        // If already dreaming and becoming powered, then don't wake.
-        if (mIsPowered && (mWakefulness == WAKEFULNESS_NAPPING
-                || mWakefulness == WAKEFULNESS_DREAMING)) {
-            return false;
-        }
-
-        // Otherwise wake up!
-        return true;
-    }
-
-    /**
-     * Updates the value of mStayOn.
-     * Sets DIRTY_STAY_ON if a change occurred.
-     */
-    private void updateStayOnLocked(int dirty) {
-        if ((dirty & (DIRTY_BATTERY_STATE | DIRTY_SETTINGS)) != 0) {
-            final boolean wasStayOn = mStayOn;
-            if (mStayOnWhilePluggedInSetting != 0
-                    && !isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
-                mStayOn = mBatteryService.isPowered(mStayOnWhilePluggedInSetting);
-            } else {
-                mStayOn = false;
-            }
-
-            if (mStayOn != wasStayOn) {
-                mDirty |= DIRTY_STAY_ON;
-            }
-        }
-    }
-
-    /**
-     * Updates the value of mWakeLockSummary to summarize the state of all active wake locks.
-     * Note that most wake-locks are ignored when the system is asleep.
-     *
-     * This function must have no other side-effects.
-     */
-    @SuppressWarnings("deprecation")
-    private void updateWakeLockSummaryLocked(int dirty) {
-        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_WAKEFULNESS)) != 0) {
-            mWakeLockSummary = 0;
-
-            final int numWakeLocks = mWakeLocks.size();
-            for (int i = 0; i < numWakeLocks; i++) {
-                final WakeLock wakeLock = mWakeLocks.get(i);
-                switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
-                    case PowerManager.PARTIAL_WAKE_LOCK:
-                        mWakeLockSummary |= WAKE_LOCK_CPU;
-                        break;
-                    case PowerManager.FULL_WAKE_LOCK:
-                        if (mWakefulness != WAKEFULNESS_ASLEEP) {
-                            mWakeLockSummary |= WAKE_LOCK_CPU
-                                    | WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_BUTTON_BRIGHT;
-                            if (mWakefulness == WAKEFULNESS_AWAKE) {
-                                mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
-                            }
-                        }
-                        break;
-                    case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
-                        if (mWakefulness != WAKEFULNESS_ASLEEP) {
-                            mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_SCREEN_BRIGHT;
-                            if (mWakefulness == WAKEFULNESS_AWAKE) {
-                                mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
-                            }
-                        }
-                        break;
-                    case PowerManager.SCREEN_DIM_WAKE_LOCK:
-                        if (mWakefulness != WAKEFULNESS_ASLEEP) {
-                            mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_SCREEN_DIM;
-                            if (mWakefulness == WAKEFULNESS_AWAKE) {
-                                mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
-                            }
-                        }
-                        break;
-                    case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
-                        if (mWakefulness != WAKEFULNESS_ASLEEP) {
-                            mWakeLockSummary |= WAKE_LOCK_PROXIMITY_SCREEN_OFF;
-                        }
-                        break;
-                }
-            }
-
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "updateWakeLockSummaryLocked: mWakefulness="
-                        + wakefulnessToString(mWakefulness)
-                        + ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary));
-            }
-        }
-    }
-
-    /**
-     * Updates the value of mUserActivitySummary to summarize the user requested
-     * state of the system such as whether the screen should be bright or dim.
-     * Note that user activity is ignored when the system is asleep.
-     *
-     * This function must have no other side-effects.
-     */
-    private void updateUserActivitySummaryLocked(long now, int dirty) {
-        // Update the status of the user activity timeout timer.
-        if ((dirty & (DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS | DIRTY_SETTINGS)) != 0) {
-            mHandler.removeMessages(MSG_USER_ACTIVITY_TIMEOUT);
-
-            long nextTimeout = 0;
-            if (mWakefulness != WAKEFULNESS_ASLEEP) {
-                final int screenOffTimeout = getScreenOffTimeoutLocked();
-                final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
-
-                mUserActivitySummary = 0;
-                if (mLastUserActivityTime >= mLastWakeTime) {
-                    nextTimeout = mLastUserActivityTime
-                            + screenOffTimeout - screenDimDuration;
-                    if (now < nextTimeout) {
-                        mUserActivitySummary |= USER_ACTIVITY_SCREEN_BRIGHT;
-                    } else {
-                        nextTimeout = mLastUserActivityTime + screenOffTimeout;
-                        if (now < nextTimeout) {
-                            mUserActivitySummary |= USER_ACTIVITY_SCREEN_DIM;
-                        }
-                    }
-                }
-                if (mUserActivitySummary == 0
-                        && mLastUserActivityTimeNoChangeLights >= mLastWakeTime) {
-                    nextTimeout = mLastUserActivityTimeNoChangeLights + screenOffTimeout;
-                    if (now < nextTimeout
-                            && mDisplayPowerRequest.screenState
-                                    != DisplayPowerRequest.SCREEN_STATE_OFF) {
-                        mUserActivitySummary = mDisplayPowerRequest.screenState
-                                == DisplayPowerRequest.SCREEN_STATE_BRIGHT ?
-                                USER_ACTIVITY_SCREEN_BRIGHT : USER_ACTIVITY_SCREEN_DIM;
-                    }
-                }
-                if (mUserActivitySummary != 0) {
-                    Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
-                    msg.setAsynchronous(true);
-                    mHandler.sendMessageAtTime(msg, nextTimeout);
-                }
-            } else {
-                mUserActivitySummary = 0;
-            }
-
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "updateUserActivitySummaryLocked: mWakefulness="
-                        + wakefulnessToString(mWakefulness)
-                        + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
-                        + ", nextTimeout=" + TimeUtils.formatUptime(nextTimeout));
-            }
-        }
-    }
-
-    /**
-     * Called when a user activity timeout has occurred.
-     * Simply indicates that something about user activity has changed so that the new
-     * state can be recomputed when the power state is updated.
-     *
-     * This function must have no other side-effects besides setting the dirty
-     * bit and calling update power state.  Wakefulness transitions are handled elsewhere.
-     */
-    private void handleUserActivityTimeout() { // runs on handler thread
-        synchronized (mLock) {
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "handleUserActivityTimeout");
-            }
-
-            mDirty |= DIRTY_USER_ACTIVITY;
-            updatePowerStateLocked();
-        }
-    }
-
-    private int getScreenOffTimeoutLocked() {
-        int timeout = mScreenOffTimeoutSetting;
-        if (isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked()) {
-            timeout = Math.min(timeout, mMaximumScreenOffTimeoutFromDeviceAdmin);
-        }
-        if (mUserActivityTimeoutOverrideFromWindowManager >= 0) {
-            timeout = (int)Math.min(timeout, mUserActivityTimeoutOverrideFromWindowManager);
-        }
-        return Math.max(timeout, MINIMUM_SCREEN_OFF_TIMEOUT);
-    }
-
-    private int getScreenDimDurationLocked(int screenOffTimeout) {
-        return Math.min(SCREEN_DIM_DURATION,
-                (int)(screenOffTimeout * MAXIMUM_SCREEN_DIM_RATIO));
-    }
-
-    /**
-     * Updates the wakefulness of the device.
-     *
-     * This is the function that decides whether the device should start napping
-     * based on the current wake locks and user activity state.  It may modify mDirty
-     * if the wakefulness changes.
-     *
-     * Returns true if the wakefulness changed and we need to restart power state calculation.
-     */
-    private boolean updateWakefulnessLocked(int dirty) {
-        boolean changed = false;
-        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_BOOT_COMPLETED
-                | DIRTY_WAKEFULNESS | DIRTY_STAY_ON | DIRTY_PROXIMITY_POSITIVE
-                | DIRTY_DOCK_STATE)) != 0) {
-            if (mWakefulness == WAKEFULNESS_AWAKE && isItBedTimeYetLocked()) {
-                if (DEBUG_SPEW) {
-                    Slog.d(TAG, "updateWakefulnessLocked: Bed time...");
-                }
-                final long time = SystemClock.uptimeMillis();
-                if (shouldNapAtBedTimeLocked()) {
-                    changed = napNoUpdateLocked(time);
-                } else {
-                    changed = goToSleepNoUpdateLocked(time,
-                            PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
-                }
-            }
-        }
-        return changed;
-    }
-
-    /**
-     * Returns true if the device should automatically nap and start dreaming when the user
-     * activity timeout has expired and it's bedtime.
-     */
-    private boolean shouldNapAtBedTimeLocked() {
-        return mDreamsActivateOnSleepSetting
-                || (mDreamsActivateOnDockSetting
-                        && mDockState != Intent.EXTRA_DOCK_STATE_UNDOCKED);
-    }
-
-    /**
-     * Returns true if the device should go to sleep now.
-     * Also used when exiting a dream to determine whether we should go back
-     * to being fully awake or else go to sleep for good.
-     */
-    private boolean isItBedTimeYetLocked() {
-        return mBootCompleted && !isBeingKeptAwakeLocked();
-    }
-
-    /**
-     * Returns true if the device is being kept awake by a wake lock, user activity
-     * or the stay on while powered setting.  We also keep the phone awake when
-     * the proximity sensor returns a positive result so that the device does not
-     * lock while in a phone call.  This function only controls whether the device
-     * will go to sleep or dream which is independent of whether it will be allowed
-     * to suspend.
-     */
-    private boolean isBeingKeptAwakeLocked() {
-        return mStayOn
-                || mProximityPositive
-                || (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) != 0
-                || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT
-                        | USER_ACTIVITY_SCREEN_DIM)) != 0;
-    }
-
-    /**
-     * Determines whether to post a message to the sandman to update the dream state.
-     */
-    private void updateDreamLocked(int dirty) {
-        if ((dirty & (DIRTY_WAKEFULNESS
-                | DIRTY_USER_ACTIVITY
-                | DIRTY_WAKE_LOCKS
-                | DIRTY_BOOT_COMPLETED
-                | DIRTY_SETTINGS
-                | DIRTY_IS_POWERED
-                | DIRTY_STAY_ON
-                | DIRTY_PROXIMITY_POSITIVE
-                | DIRTY_BATTERY_STATE)) != 0) {
-            scheduleSandmanLocked();
-        }
-    }
-
-    private void scheduleSandmanLocked() {
-        if (!mSandmanScheduled) {
-            mSandmanScheduled = true;
-            Message msg = mHandler.obtainMessage(MSG_SANDMAN);
-            msg.setAsynchronous(true);
-            mHandler.sendMessage(msg);
-        }
-    }
-
-    /**
-     * Called when the device enters or exits a napping or dreaming state.
-     *
-     * We do this asynchronously because we must call out of the power manager to start
-     * the dream and we don't want to hold our lock while doing so.  There is a risk that
-     * the device will wake or go to sleep in the meantime so we have to handle that case.
-     */
-    private void handleSandman() { // runs on handler thread
-        // Handle preconditions.
-        boolean startDreaming = false;
-        synchronized (mLock) {
-            mSandmanScheduled = false;
-            boolean canDream = canDreamLocked();
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "handleSandman: canDream=" + canDream
-                        + ", mWakefulness=" + wakefulnessToString(mWakefulness));
-            }
-
-            if (canDream && mWakefulness == WAKEFULNESS_NAPPING) {
-                startDreaming = true;
-            }
-        }
-
-        // Start dreaming if needed.
-        // We only control the dream on the handler thread, so we don't need to worry about
-        // concurrent attempts to start or stop the dream.
-        boolean isDreaming = false;
-        if (mDreamManager != null) {
-            if (startDreaming) {
-                mDreamManager.startDream();
-            }
-            isDreaming = mDreamManager.isDreaming();
-        }
-
-        // Update dream state.
-        // We might need to stop the dream again if the preconditions changed.
-        boolean continueDreaming = false;
-        synchronized (mLock) {
-            if (isDreaming && canDreamLocked()) {
-                if (mWakefulness == WAKEFULNESS_NAPPING) {
-                    mWakefulness = WAKEFULNESS_DREAMING;
-                    mDirty |= DIRTY_WAKEFULNESS;
-                    mBatteryLevelWhenDreamStarted = mBatteryLevel;
-                    updatePowerStateLocked();
-                    continueDreaming = true;
-                } else if (mWakefulness == WAKEFULNESS_DREAMING) {
-                    if (!isBeingKeptAwakeLocked()
-                            && mBatteryLevel < mBatteryLevelWhenDreamStarted
-                                    - DREAM_BATTERY_LEVEL_DRAIN_CUTOFF) {
-                        // If the user activity timeout expired and the battery appears
-                        // to be draining faster than it is charging then stop dreaming
-                        // and go to sleep.
-                        Slog.i(TAG, "Stopping dream because the battery appears to "
-                                + "be draining faster than it is charging.  "
-                                + "Battery level when dream started: "
-                                + mBatteryLevelWhenDreamStarted + "%.  "
-                                + "Battery level now: " + mBatteryLevel + "%.");
-                    } else {
-                        continueDreaming = true;
-                    }
-                }
-            }
-            if (!continueDreaming) {
-                handleDreamFinishedLocked();
-            }
-        }
-
-        // Stop dreaming if needed.
-        // It's possible that something else changed to make us need to start the dream again.
-        // If so, then the power manager will have posted another message to the handler
-        // to take care of it later.
-        if (mDreamManager != null) {
-            if (!continueDreaming) {
-                mDreamManager.stopDream();
-            }
-        }
-    }
-
-    /**
-     * Returns true if the device is allowed to dream in its current state
-     * assuming that it is currently napping or dreaming.
-     */
-    private boolean canDreamLocked() {
-        return mDreamsSupportedConfig
-                && mDreamsEnabledSetting
-                && mDisplayPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF
-                && mBootCompleted
-                && (mIsPowered || isBeingKeptAwakeLocked());
-    }
-
-    /**
-     * Called when a dream is ending to figure out what to do next.
-     */
-    private void handleDreamFinishedLocked() {
-        if (mWakefulness == WAKEFULNESS_NAPPING
-                || mWakefulness == WAKEFULNESS_DREAMING) {
-            if (isItBedTimeYetLocked()) {
-                goToSleepNoUpdateLocked(SystemClock.uptimeMillis(),
-                        PowerManager.GO_TO_SLEEP_REASON_TIMEOUT);
-                updatePowerStateLocked();
-            } else {
-                wakeUpNoUpdateLocked(SystemClock.uptimeMillis());
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    private void handleScreenOnBlockerReleased() {
-        synchronized (mLock) {
-            mDirty |= DIRTY_SCREEN_ON_BLOCKER_RELEASED;
-            updatePowerStateLocked();
-        }
-    }
-
-    /**
-     * Updates the display power state asynchronously.
-     * When the update is finished, mDisplayReady will be set to true.  The display
-     * controller posts a message to tell us when the actual display power state
-     * has been updated so we come back here to double-check and finish up.
-     *
-     * This function recalculates the display power state each time.
-     */
-    private void updateDisplayPowerStateLocked(int dirty) {
-        if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS
-                | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED
-                | DIRTY_SETTINGS | DIRTY_SCREEN_ON_BLOCKER_RELEASED)) != 0) {
-            int newScreenState = getDesiredScreenPowerStateLocked();
-            if (newScreenState != mDisplayPowerRequest.screenState) {
-                if (newScreenState == DisplayPowerRequest.SCREEN_STATE_OFF
-                        && mDisplayPowerRequest.screenState
-                                != DisplayPowerRequest.SCREEN_STATE_OFF) {
-                    mLastScreenOffEventElapsedRealTime = SystemClock.elapsedRealtime();
-                }
-
-                mDisplayPowerRequest.screenState = newScreenState;
-                nativeSetPowerState(
-                        newScreenState != DisplayPowerRequest.SCREEN_STATE_OFF,
-                        newScreenState == DisplayPowerRequest.SCREEN_STATE_BRIGHT);
-            }
-
-            int screenBrightness = mScreenBrightnessSettingDefault;
-            float screenAutoBrightnessAdjustment = 0.0f;
-            boolean autoBrightness = (mScreenBrightnessModeSetting ==
-                    Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
-            if (isValidBrightness(mScreenBrightnessOverrideFromWindowManager)) {
-                screenBrightness = mScreenBrightnessOverrideFromWindowManager;
-                autoBrightness = false;
-            } else if (isValidBrightness(mTemporaryScreenBrightnessSettingOverride)) {
-                screenBrightness = mTemporaryScreenBrightnessSettingOverride;
-            } else if (isValidBrightness(mScreenBrightnessSetting)) {
-                screenBrightness = mScreenBrightnessSetting;
-            }
-            if (autoBrightness) {
-                screenBrightness = mScreenBrightnessSettingDefault;
-                if (isValidAutoBrightnessAdjustment(
-                        mTemporaryScreenAutoBrightnessAdjustmentSettingOverride)) {
-                    screenAutoBrightnessAdjustment =
-                            mTemporaryScreenAutoBrightnessAdjustmentSettingOverride;
-                } else if (isValidAutoBrightnessAdjustment(
-                        mScreenAutoBrightnessAdjustmentSetting)) {
-                    screenAutoBrightnessAdjustment = mScreenAutoBrightnessAdjustmentSetting;
-                }
-            }
-            screenBrightness = Math.max(Math.min(screenBrightness,
-                    mScreenBrightnessSettingMaximum), mScreenBrightnessSettingMinimum);
-            screenAutoBrightnessAdjustment = Math.max(Math.min(
-                    screenAutoBrightnessAdjustment, 1.0f), -1.0f);
-            mDisplayPowerRequest.screenBrightness = screenBrightness;
-            mDisplayPowerRequest.screenAutoBrightnessAdjustment =
-                    screenAutoBrightnessAdjustment;
-            mDisplayPowerRequest.useAutoBrightness = autoBrightness;
-
-            mDisplayPowerRequest.useProximitySensor = shouldUseProximitySensorLocked();
-
-            mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld();
-
-            mDisplayReady = mDisplayPowerController.requestPowerState(mDisplayPowerRequest,
-                    mRequestWaitForNegativeProximity);
-            mRequestWaitForNegativeProximity = false;
-
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "updateScreenStateLocked: mDisplayReady=" + mDisplayReady
-                        + ", newScreenState=" + newScreenState
-                        + ", mWakefulness=" + mWakefulness
-                        + ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary)
-                        + ", mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary)
-                        + ", mBootCompleted=" + mBootCompleted);
-            }
-        }
-    }
-
-    private static boolean isValidBrightness(int value) {
-        return value >= 0 && value <= 255;
-    }
-
-    private static boolean isValidAutoBrightnessAdjustment(float value) {
-        // Handles NaN by always returning false.
-        return value >= -1.0f && value <= 1.0f;
-    }
-
-    private int getDesiredScreenPowerStateLocked() {
-        if (mWakefulness == WAKEFULNESS_ASLEEP) {
-            return DisplayPowerRequest.SCREEN_STATE_OFF;
-        }
-
-        if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0
-                || (mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0
-                || !mBootCompleted) {
-            return DisplayPowerRequest.SCREEN_STATE_BRIGHT;
-        }
-
-        return DisplayPowerRequest.SCREEN_STATE_DIM;
-    }
-
-    private final DisplayPowerController.Callbacks mDisplayPowerControllerCallbacks =
-            new DisplayPowerController.Callbacks() {
-        @Override
-        public void onStateChanged() {
-            synchronized (mLock) {
-                mDirty |= DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED;
-                updatePowerStateLocked();
-            }
-        }
-
-        @Override
-        public void onProximityPositive() {
-            synchronized (mLock) {
-                mProximityPositive = true;
-                mDirty |= DIRTY_PROXIMITY_POSITIVE;
-                updatePowerStateLocked();
-            }
-        }
-
-        @Override
-        public void onProximityNegative() {
-            synchronized (mLock) {
-                mProximityPositive = false;
-                mDirty |= DIRTY_PROXIMITY_POSITIVE;
-                userActivityNoUpdateLocked(SystemClock.uptimeMillis(),
-                        PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
-                updatePowerStateLocked();
-            }
-        }
-    };
-
-    private boolean shouldUseProximitySensorLocked() {
-        return (mWakeLockSummary & WAKE_LOCK_PROXIMITY_SCREEN_OFF) != 0;
-    }
-
-    /**
-     * Updates the suspend blocker that keeps the CPU alive.
-     *
-     * This function must have no other side-effects.
-     */
-    private void updateSuspendBlockerLocked() {
-        final boolean needWakeLockSuspendBlocker = ((mWakeLockSummary & WAKE_LOCK_CPU) != 0);
-        final boolean needDisplaySuspendBlocker = needDisplaySuspendBlocker();
-
-        // First acquire suspend blockers if needed.
-        if (needWakeLockSuspendBlocker && !mHoldingWakeLockSuspendBlocker) {
-            mWakeLockSuspendBlocker.acquire();
-            mHoldingWakeLockSuspendBlocker = true;
-        }
-        if (needDisplaySuspendBlocker && !mHoldingDisplaySuspendBlocker) {
-            mDisplaySuspendBlocker.acquire();
-            mHoldingDisplaySuspendBlocker = true;
-        }
-
-        // Then release suspend blockers if needed.
-        if (!needWakeLockSuspendBlocker && mHoldingWakeLockSuspendBlocker) {
-            mWakeLockSuspendBlocker.release();
-            mHoldingWakeLockSuspendBlocker = false;
-        }
-        if (!needDisplaySuspendBlocker && mHoldingDisplaySuspendBlocker) {
-            mDisplaySuspendBlocker.release();
-            mHoldingDisplaySuspendBlocker = false;
-        }
-    }
-
-    /**
-     * Return true if we must keep a suspend blocker active on behalf of the display.
-     * We do so if the screen is on or is in transition between states.
-     */
-    private boolean needDisplaySuspendBlocker() {
-        if (!mDisplayReady) {
-            return true;
-        }
-        if (mDisplayPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
-            // If we asked for the screen to be on but it is off due to the proximity
-            // sensor then we may suspend but only if the configuration allows it.
-            // On some hardware it may not be safe to suspend because the proximity
-            // sensor may not be correctly configured as a wake-up source.
-            if (!mDisplayPowerRequest.useProximitySensor || !mProximityPositive
-                    || !mSuspendWhenScreenOffDueToProximityConfig) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override // Binder call
-    public boolean isScreenOn() {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            return isScreenOnInternal();
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private boolean isScreenOnInternal() {
-        synchronized (mLock) {
-            return !mSystemReady
-                    || mDisplayPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF;
-        }
-    }
-
-    private void handleBatteryStateChangedLocked() {
-        mDirty |= DIRTY_BATTERY_STATE;
-        updatePowerStateLocked();
-    }
-
-    private void startWatchingForBootAnimationFinished() {
-        mHandler.sendEmptyMessage(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED);
-    }
-
-    private void checkIfBootAnimationFinished() {
-        if (DEBUG) {
-            Slog.d(TAG, "Check if boot animation finished...");
-        }
-
-        if (SystemService.isRunning(BOOT_ANIMATION_SERVICE)) {
-            mHandler.sendEmptyMessageDelayed(MSG_CHECK_IF_BOOT_ANIMATION_FINISHED,
-                    BOOT_ANIMATION_POLL_INTERVAL);
-            return;
-        }
-
-        synchronized (mLock) {
-            if (!mBootCompleted) {
-                Slog.i(TAG, "Boot animation finished.");
-                handleBootCompletedLocked();
-            }
-        }
-    }
-
-    private void handleBootCompletedLocked() {
-        final long now = SystemClock.uptimeMillis();
-        mBootCompleted = true;
-        mDirty |= DIRTY_BOOT_COMPLETED;
-        userActivityNoUpdateLocked(
-                now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
-        updatePowerStateLocked();
-    }
-
-    /**
-     * Reboots the device.
-     *
-     * @param confirm If true, shows a reboot confirmation dialog.
-     * @param reason The reason for the reboot, or null if none.
-     * @param wait If true, this call waits for the reboot to complete and does not return.
-     */
-    @Override // Binder call
-    public void reboot(boolean confirm, String reason, boolean wait) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            shutdownOrRebootInternal(false, confirm, reason, wait);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    /**
-     * Shuts down the device.
-     *
-     * @param confirm If true, shows a shutdown confirmation dialog.
-     * @param wait If true, this call waits for the shutdown to complete and does not return.
-     */
-    @Override // Binder call
-    public void shutdown(boolean confirm, boolean wait) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            shutdownOrRebootInternal(true, confirm, null, wait);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void shutdownOrRebootInternal(final boolean shutdown, final boolean confirm,
-            final String reason, boolean wait) {
-        if (mHandler == null || !mSystemReady) {
-            throw new IllegalStateException("Too early to call shutdown() or reboot()");
-        }
-
-        Runnable runnable = new Runnable() {
-            @Override
-            public void run() {
-                synchronized (this) {
-                    if (shutdown) {
-                        ShutdownThread.shutdown(mContext, confirm);
-                    } else {
-                        ShutdownThread.reboot(mContext, reason, confirm);
-                    }
-                }
-            }
-        };
-
-        // ShutdownThread must run on a looper capable of displaying the UI.
-        Message msg = Message.obtain(mHandler, runnable);
-        msg.setAsynchronous(true);
-        mHandler.sendMessage(msg);
-
-        // PowerManager.reboot() is documented not to return so just wait for the inevitable.
-        if (wait) {
-            synchronized (runnable) {
-                while (true) {
-                    try {
-                        runnable.wait();
-                    } catch (InterruptedException e) {
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Crash the runtime (causing a complete restart of the Android framework).
-     * Requires REBOOT permission.  Mostly for testing.  Should not return.
-     */
-    @Override // Binder call
-    public void crash(String message) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            crashInternal(message);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void crashInternal(final String message) {
-        Thread t = new Thread("PowerManagerService.crash()") {
-            @Override
-            public void run() {
-                throw new RuntimeException(message);
-            }
-        };
-        try {
-            t.start();
-            t.join();
-        } catch (InterruptedException e) {
-            Log.wtf(TAG, e);
-        }
-    }
-
-    /**
-     * Set the setting that determines whether the device stays on when plugged in.
-     * The argument is a bit string, with each bit specifying a power source that,
-     * when the device is connected to that source, causes the device to stay on.
-     * See {@link android.os.BatteryManager} for the list of power sources that
-     * can be specified. Current values include {@link android.os.BatteryManager#BATTERY_PLUGGED_AC}
-     * and {@link android.os.BatteryManager#BATTERY_PLUGGED_USB}
-     *
-     * Used by "adb shell svc power stayon ..."
-     *
-     * @param val an {@code int} containing the bits that specify which power sources
-     * should cause the device to stay on.
-     */
-    @Override // Binder call
-    public void setStayOnSetting(int val) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SETTINGS, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setStayOnSettingInternal(val);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setStayOnSettingInternal(int val) {
-        Settings.Global.putInt(mContext.getContentResolver(),
-                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, val);
-    }
-
-    /**
-     * Used by device administration to set the maximum screen off timeout.
-     *
-     * This method must only be called by the device administration policy manager.
-     */
-    @Override // Binder call
-    public void setMaximumScreenOffTimeoutFromDeviceAdmin(int timeMs) {
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setMaximumScreenOffTimeoutFromDeviceAdminInternal(timeMs);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setMaximumScreenOffTimeoutFromDeviceAdminInternal(int timeMs) {
-        synchronized (mLock) {
-            mMaximumScreenOffTimeoutFromDeviceAdmin = timeMs;
-            mDirty |= DIRTY_SETTINGS;
-            updatePowerStateLocked();
-        }
-    }
-
-    private boolean isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() {
-        return mMaximumScreenOffTimeoutFromDeviceAdmin >= 0
-                && mMaximumScreenOffTimeoutFromDeviceAdmin < Integer.MAX_VALUE;
-    }
-
-    /**
-     * Used by the phone application to make the attention LED flash when ringing.
-     */
-    @Override // Binder call
-    public void setAttentionLight(boolean on, int color) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setAttentionLightInternal(on, color);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setAttentionLightInternal(boolean on, int color) {
-        LightsService.Light light;
-        synchronized (mLock) {
-            if (!mSystemReady) {
-                return;
-            }
-            light = mAttentionLight;
-        }
-
-        // Control light outside of lock.
-        light.setFlashing(color, LightsService.LIGHT_FLASH_HARDWARE, (on ? 3 : 0), 0);
-    }
-
-    /**
-     * Used by the Watchdog.
-     */
-    public long timeSinceScreenWasLastOn() {
-        synchronized (mLock) {
-            if (mDisplayPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
-                return 0;
-            }
-            return SystemClock.elapsedRealtime() - mLastScreenOffEventElapsedRealTime;
-        }
-    }
-
-    /**
-     * Used by the window manager to override the screen brightness based on the
-     * current foreground activity.
-     *
-     * This method must only be called by the window manager.
-     *
-     * @param brightness The overridden brightness, or -1 to disable the override.
-     */
-    public void setScreenBrightnessOverrideFromWindowManager(int brightness) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setScreenBrightnessOverrideFromWindowManagerInternal(brightness);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setScreenBrightnessOverrideFromWindowManagerInternal(int brightness) {
-        synchronized (mLock) {
-            if (mScreenBrightnessOverrideFromWindowManager != brightness) {
-                mScreenBrightnessOverrideFromWindowManager = brightness;
-                mDirty |= DIRTY_SETTINGS;
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    /**
-     * Used by the window manager to override the button brightness based on the
-     * current foreground activity.
-     *
-     * This method must only be called by the window manager.
-     *
-     * @param brightness The overridden brightness, or -1 to disable the override.
-     */
-    public void setButtonBrightnessOverrideFromWindowManager(int brightness) {
-        // Do nothing.
-        // Button lights are not currently supported in the new implementation.
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-    }
-
-    /**
-     * Used by the window manager to override the user activity timeout based on the
-     * current foreground activity.  It can only be used to make the timeout shorter
-     * than usual, not longer.
-     *
-     * This method must only be called by the window manager.
-     *
-     * @param timeoutMillis The overridden timeout, or -1 to disable the override.
-     */
-    public void setUserActivityTimeoutOverrideFromWindowManager(long timeoutMillis) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setUserActivityTimeoutOverrideFromWindowManagerInternal(timeoutMillis);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setUserActivityTimeoutOverrideFromWindowManagerInternal(long timeoutMillis) {
-        synchronized (mLock) {
-            if (mUserActivityTimeoutOverrideFromWindowManager != timeoutMillis) {
-                mUserActivityTimeoutOverrideFromWindowManager = timeoutMillis;
-                mDirty |= DIRTY_SETTINGS;
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    /**
-     * Used by the settings application and brightness control widgets to
-     * temporarily override the current screen brightness setting so that the
-     * user can observe the effect of an intended settings change without applying
-     * it immediately.
-     *
-     * The override will be canceled when the setting value is next updated.
-     *
-     * @param brightness The overridden brightness.
-     *
-     * @see android.provider.Settings.System#SCREEN_BRIGHTNESS
-     */
-    @Override // Binder call
-    public void setTemporaryScreenBrightnessSettingOverride(int brightness) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setTemporaryScreenBrightnessSettingOverrideInternal(brightness);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setTemporaryScreenBrightnessSettingOverrideInternal(int brightness) {
-        synchronized (mLock) {
-            if (mTemporaryScreenBrightnessSettingOverride != brightness) {
-                mTemporaryScreenBrightnessSettingOverride = brightness;
-                mDirty |= DIRTY_SETTINGS;
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    /**
-     * Used by the settings application and brightness control widgets to
-     * temporarily override the current screen auto-brightness adjustment setting so that the
-     * user can observe the effect of an intended settings change without applying
-     * it immediately.
-     *
-     * The override will be canceled when the setting value is next updated.
-     *
-     * @param adj The overridden brightness, or Float.NaN to disable the override.
-     *
-     * @see Settings.System#SCREEN_AUTO_BRIGHTNESS_ADJ
-     */
-    @Override // Binder call
-    public void setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(float adj) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
-
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            setTemporaryScreenAutoBrightnessAdjustmentSettingOverrideInternal(adj);
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setTemporaryScreenAutoBrightnessAdjustmentSettingOverrideInternal(float adj) {
-        synchronized (mLock) {
-            // Note: This condition handles NaN because NaN is not equal to any other
-            // value, including itself.
-            if (mTemporaryScreenAutoBrightnessAdjustmentSettingOverride != adj) {
-                mTemporaryScreenAutoBrightnessAdjustmentSettingOverride = adj;
-                mDirty |= DIRTY_SETTINGS;
-                updatePowerStateLocked();
-            }
-        }
-    }
-
-    /**
-     * Low-level function turn the device off immediately, without trying
-     * to be clean.  Most people should use {@link ShutdownThread} for a clean shutdown.
-     */
-    public static void lowLevelShutdown() {
-        SystemProperties.set("sys.powerctl", "shutdown");
-    }
-
-    /**
-     * Low-level function to reboot the device. On success, this function
-     * doesn't return. If more than 5 seconds passes from the time,
-     * a reboot is requested, this method returns.
-     *
-     * @param reason code to pass to the kernel (e.g. "recovery"), or null.
-     */
-    public static void lowLevelReboot(String reason) {
-        if (reason == null) {
-            reason = "";
-        }
-        SystemProperties.set("sys.powerctl", "reboot," + reason);
-        try {
-            Thread.sleep(20000);
-        } catch (InterruptedException e) {
-            Thread.currentThread().interrupt();
-        }
-    }
-
-    @Override // Watchdog.Monitor implementation
-    public void monitor() {
-        // Grab and release lock for watchdog monitor to detect deadlocks.
-        synchronized (mLock) {
-        }
-    }
-
-    @Override // Binder call
-    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump PowerManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        pw.println("POWER MANAGER (dumpsys power)\n");
-
-        final DisplayPowerController dpc;
-        final WirelessChargerDetector wcd;
-        synchronized (mLock) {
-            pw.println("Power Manager State:");
-            pw.println("  mDirty=0x" + Integer.toHexString(mDirty));
-            pw.println("  mWakefulness=" + wakefulnessToString(mWakefulness));
-            pw.println("  mIsPowered=" + mIsPowered);
-            pw.println("  mPlugType=" + mPlugType);
-            pw.println("  mBatteryLevel=" + mBatteryLevel);
-            pw.println("  mBatteryLevelWhenDreamStarted=" + mBatteryLevelWhenDreamStarted);
-            pw.println("  mDockState=" + mDockState);
-            pw.println("  mStayOn=" + mStayOn);
-            pw.println("  mProximityPositive=" + mProximityPositive);
-            pw.println("  mBootCompleted=" + mBootCompleted);
-            pw.println("  mSystemReady=" + mSystemReady);
-            pw.println("  mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary));
-            pw.println("  mUserActivitySummary=0x" + Integer.toHexString(mUserActivitySummary));
-            pw.println("  mRequestWaitForNegativeProximity=" + mRequestWaitForNegativeProximity);
-            pw.println("  mSandmanScheduled=" + mSandmanScheduled);
-            pw.println("  mLastWakeTime=" + TimeUtils.formatUptime(mLastWakeTime));
-            pw.println("  mLastSleepTime=" + TimeUtils.formatUptime(mLastSleepTime));
-            pw.println("  mSendWakeUpFinishedNotificationWhenReady="
-                    + mSendWakeUpFinishedNotificationWhenReady);
-            pw.println("  mSendGoToSleepFinishedNotificationWhenReady="
-                    + mSendGoToSleepFinishedNotificationWhenReady);
-            pw.println("  mLastUserActivityTime=" + TimeUtils.formatUptime(mLastUserActivityTime));
-            pw.println("  mLastUserActivityTimeNoChangeLights="
-                    + TimeUtils.formatUptime(mLastUserActivityTimeNoChangeLights));
-            pw.println("  mDisplayReady=" + mDisplayReady);
-            pw.println("  mHoldingWakeLockSuspendBlocker=" + mHoldingWakeLockSuspendBlocker);
-            pw.println("  mHoldingDisplaySuspendBlocker=" + mHoldingDisplaySuspendBlocker);
-
-            pw.println();
-            pw.println("Settings and Configuration:");
-            pw.println("  mWakeUpWhenPluggedOrUnpluggedConfig="
-                    + mWakeUpWhenPluggedOrUnpluggedConfig);
-            pw.println("  mSuspendWhenScreenOffDueToProximityConfig="
-                    + mSuspendWhenScreenOffDueToProximityConfig);
-            pw.println("  mDreamsSupportedConfig=" + mDreamsSupportedConfig);
-            pw.println("  mDreamsEnabledByDefaultConfig=" + mDreamsEnabledByDefaultConfig);
-            pw.println("  mDreamsActivatedOnSleepByDefaultConfig="
-                    + mDreamsActivatedOnSleepByDefaultConfig);
-            pw.println("  mDreamsActivatedOnDockByDefaultConfig="
-                    + mDreamsActivatedOnDockByDefaultConfig);
-            pw.println("  mDreamsEnabledSetting=" + mDreamsEnabledSetting);
-            pw.println("  mDreamsActivateOnSleepSetting=" + mDreamsActivateOnSleepSetting);
-            pw.println("  mDreamsActivateOnDockSetting=" + mDreamsActivateOnDockSetting);
-            pw.println("  mScreenOffTimeoutSetting=" + mScreenOffTimeoutSetting);
-            pw.println("  mMaximumScreenOffTimeoutFromDeviceAdmin="
-                    + mMaximumScreenOffTimeoutFromDeviceAdmin + " (enforced="
-                    + isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked() + ")");
-            pw.println("  mStayOnWhilePluggedInSetting=" + mStayOnWhilePluggedInSetting);
-            pw.println("  mScreenBrightnessSetting=" + mScreenBrightnessSetting);
-            pw.println("  mScreenAutoBrightnessAdjustmentSetting="
-                    + mScreenAutoBrightnessAdjustmentSetting);
-            pw.println("  mScreenBrightnessModeSetting=" + mScreenBrightnessModeSetting);
-            pw.println("  mScreenBrightnessOverrideFromWindowManager="
-                    + mScreenBrightnessOverrideFromWindowManager);
-            pw.println("  mUserActivityTimeoutOverrideFromWindowManager="
-                    + mUserActivityTimeoutOverrideFromWindowManager);
-            pw.println("  mTemporaryScreenBrightnessSettingOverride="
-                    + mTemporaryScreenBrightnessSettingOverride);
-            pw.println("  mTemporaryScreenAutoBrightnessAdjustmentSettingOverride="
-                    + mTemporaryScreenAutoBrightnessAdjustmentSettingOverride);
-            pw.println("  mScreenBrightnessSettingMinimum=" + mScreenBrightnessSettingMinimum);
-            pw.println("  mScreenBrightnessSettingMaximum=" + mScreenBrightnessSettingMaximum);
-            pw.println("  mScreenBrightnessSettingDefault=" + mScreenBrightnessSettingDefault);
-
-            final int screenOffTimeout = getScreenOffTimeoutLocked();
-            final int screenDimDuration = getScreenDimDurationLocked(screenOffTimeout);
-            pw.println();
-            pw.println("Screen off timeout: " + screenOffTimeout + " ms");
-            pw.println("Screen dim duration: " + screenDimDuration + " ms");
-
-            pw.println();
-            pw.println("Wake Locks: size=" + mWakeLocks.size());
-            for (WakeLock wl : mWakeLocks) {
-                pw.println("  " + wl);
-            }
-
-            pw.println();
-            pw.println("Suspend Blockers: size=" + mSuspendBlockers.size());
-            for (SuspendBlocker sb : mSuspendBlockers) {
-                pw.println("  " + sb);
-            }
-
-            pw.println();
-            pw.println("Screen On Blocker: " + mScreenOnBlocker);
-
-            pw.println();
-            pw.println("Display Blanker: " + mDisplayBlanker);
-
-            dpc = mDisplayPowerController;
-            wcd = mWirelessChargerDetector;
-        }
-
-        if (dpc != null) {
-            dpc.dump(pw);
-        }
-
-        if (wcd != null) {
-            wcd.dump(pw);
-        }
-    }
-
-    private SuspendBlocker createSuspendBlockerLocked(String name) {
-        SuspendBlocker suspendBlocker = new SuspendBlockerImpl(name);
-        mSuspendBlockers.add(suspendBlocker);
-        return suspendBlocker;
-    }
-
-    private static String wakefulnessToString(int wakefulness) {
-        switch (wakefulness) {
-            case WAKEFULNESS_ASLEEP:
-                return "Asleep";
-            case WAKEFULNESS_AWAKE:
-                return "Awake";
-            case WAKEFULNESS_DREAMING:
-                return "Dreaming";
-            case WAKEFULNESS_NAPPING:
-                return "Napping";
-            default:
-                return Integer.toString(wakefulness);
-        }
-    }
-
-    private static WorkSource copyWorkSource(WorkSource workSource) {
-        return workSource != null ? new WorkSource(workSource) : null;
-    }
-
-    private final class BatteryReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            synchronized (mLock) {
-                handleBatteryStateChangedLocked();
-            }
-        }
-    }
-
-    private final class BootCompletedReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            // This is our early signal that the system thinks it has finished booting.
-            // However, the boot animation may still be running for a few more seconds
-            // since it is ultimately in charge of when it terminates.
-            // Defer transitioning into the boot completed state until the animation exits.
-            // We do this so that the screen does not start to dim prematurely before
-            // the user has actually had a chance to interact with the device.
-            startWatchingForBootAnimationFinished();
-        }
-    }
-
-    private final class DreamReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            synchronized (mLock) {
-                scheduleSandmanLocked();
-            }
-        }
-    }
-
-    private final class UserSwitchedReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            synchronized (mLock) {
-                handleSettingsChangedLocked();
-            }
-        }
-    }
-
-    private final class DockReceiver extends BroadcastReceiver {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            synchronized (mLock) {
-                int dockState = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
-                        Intent.EXTRA_DOCK_STATE_UNDOCKED);
-                if (mDockState != dockState) {
-                    mDockState = dockState;
-                    mDirty |= DIRTY_DOCK_STATE;
-                    updatePowerStateLocked();
-                }
-            }
-        }
-    }
-
-    private final class SettingsObserver extends ContentObserver {
-        public SettingsObserver(Handler handler) {
-            super(handler);
-        }
-
-        @Override
-        public void onChange(boolean selfChange, Uri uri) {
-            synchronized (mLock) {
-                handleSettingsChangedLocked();
-            }
-        }
-    }
-
-    /**
-     * Handler for asynchronous operations performed by the power manager.
-     */
-    private final class PowerManagerHandler extends Handler {
-        public PowerManagerHandler(Looper looper) {
-            super(looper, null, true /*async*/);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_USER_ACTIVITY_TIMEOUT:
-                    handleUserActivityTimeout();
-                    break;
-                case MSG_SANDMAN:
-                    handleSandman();
-                    break;
-                case MSG_SCREEN_ON_BLOCKER_RELEASED:
-                    handleScreenOnBlockerReleased();
-                    break;
-                case MSG_CHECK_IF_BOOT_ANIMATION_FINISHED:
-                    checkIfBootAnimationFinished();
-                    break;
-            }
-        }
-    }
-
-    /**
-     * Represents a wake lock that has been acquired by an application.
-     */
-    private final class WakeLock implements IBinder.DeathRecipient {
-        public final IBinder mLock;
-        public int mFlags;
-        public String mTag;
-        public final String mPackageName;
-        public WorkSource mWorkSource;
-        public final int mOwnerUid;
-        public final int mOwnerPid;
-        public boolean mNotifiedAcquired;
-
-        public WakeLock(IBinder lock, int flags, String tag, String packageName,
-                WorkSource workSource, int ownerUid, int ownerPid) {
-            mLock = lock;
-            mFlags = flags;
-            mTag = tag;
-            mPackageName = packageName;
-            mWorkSource = copyWorkSource(workSource);
-            mOwnerUid = ownerUid;
-            mOwnerPid = ownerPid;
-        }
-
-        @Override
-        public void binderDied() {
-            PowerManagerService.this.handleWakeLockDeath(this);
-        }
-
-        public boolean hasSameProperties(int flags, String tag, WorkSource workSource,
-                int ownerUid, int ownerPid) {
-            return mFlags == flags
-                    && mTag.equals(tag)
-                    && hasSameWorkSource(workSource)
-                    && mOwnerUid == ownerUid
-                    && mOwnerPid == ownerPid;
-        }
-
-        public void updateProperties(int flags, String tag, String packageName,
-                WorkSource workSource, int ownerUid, int ownerPid) {
-            if (!mPackageName.equals(packageName)) {
-                throw new IllegalStateException("Existing wake lock package name changed: "
-                        + mPackageName + " to " + packageName);
-            }
-            if (mOwnerUid != ownerUid) {
-                throw new IllegalStateException("Existing wake lock uid changed: "
-                        + mOwnerUid + " to " + ownerUid);
-            }
-            if (mOwnerPid != ownerPid) {
-                throw new IllegalStateException("Existing wake lock pid changed: "
-                        + mOwnerPid + " to " + ownerPid);
-            }
-            mFlags = flags;
-            mTag = tag;
-            updateWorkSource(workSource);
-        }
-
-        public boolean hasSameWorkSource(WorkSource workSource) {
-            return Objects.equal(mWorkSource, workSource);
-        }
-
-        public void updateWorkSource(WorkSource workSource) {
-            mWorkSource = copyWorkSource(workSource);
-        }
-
-        @Override
-        public String toString() {
-            return getLockLevelString()
-                    + " '" + mTag + "'" + getLockFlagsString()
-                    + " (uid=" + mOwnerUid + ", pid=" + mOwnerPid + ", ws=" + mWorkSource + ")";
-        }
-
-        private String getLockLevelString() {
-            switch (mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
-                case PowerManager.FULL_WAKE_LOCK:
-                    return "FULL_WAKE_LOCK                ";
-                case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
-                    return "SCREEN_BRIGHT_WAKE_LOCK       ";
-                case PowerManager.SCREEN_DIM_WAKE_LOCK:
-                    return "SCREEN_DIM_WAKE_LOCK          ";
-                case PowerManager.PARTIAL_WAKE_LOCK:
-                    return "PARTIAL_WAKE_LOCK             ";
-                case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
-                    return "PROXIMITY_SCREEN_OFF_WAKE_LOCK";
-                default:
-                    return "???                           ";
-            }
-        }
-
-        private String getLockFlagsString() {
-            String result = "";
-            if ((mFlags & PowerManager.ACQUIRE_CAUSES_WAKEUP) != 0) {
-                result += " ACQUIRE_CAUSES_WAKEUP";
-            }
-            if ((mFlags & PowerManager.ON_AFTER_RELEASE) != 0) {
-                result += " ON_AFTER_RELEASE";
-            }
-            return result;
-        }
-    }
-
-    private final class SuspendBlockerImpl implements SuspendBlocker {
-        private final String mName;
-        private int mReferenceCount;
-
-        public SuspendBlockerImpl(String name) {
-            mName = name;
-        }
-
-        @Override
-        protected void finalize() throws Throwable {
-            try {
-                if (mReferenceCount != 0) {
-                    Log.wtf(TAG, "Suspend blocker \"" + mName
-                            + "\" was finalized without being released!");
-                    mReferenceCount = 0;
-                    nativeReleaseSuspendBlocker(mName);
-                }
-            } finally {
-                super.finalize();
-            }
-        }
-
-        @Override
-        public void acquire() {
-            synchronized (this) {
-                mReferenceCount += 1;
-                if (mReferenceCount == 1) {
-                    if (DEBUG_SPEW) {
-                        Slog.d(TAG, "Acquiring suspend blocker \"" + mName + "\".");
-                    }
-                    nativeAcquireSuspendBlocker(mName);
-                }
-            }
-        }
-
-        @Override
-        public void release() {
-            synchronized (this) {
-                mReferenceCount -= 1;
-                if (mReferenceCount == 0) {
-                    if (DEBUG_SPEW) {
-                        Slog.d(TAG, "Releasing suspend blocker \"" + mName + "\".");
-                    }
-                    nativeReleaseSuspendBlocker(mName);
-                } else if (mReferenceCount < 0) {
-                    Log.wtf(TAG, "Suspend blocker \"" + mName
-                            + "\" was released without being acquired!", new Throwable());
-                    mReferenceCount = 0;
-                }
-            }
-        }
-
-        @Override
-        public String toString() {
-            synchronized (this) {
-                return mName + ": ref count=" + mReferenceCount;
-            }
-        }
-    }
-
-    private final class ScreenOnBlockerImpl implements ScreenOnBlocker {
-        private int mNestCount;
-
-        public boolean isHeld() {
-            synchronized (this) {
-                return mNestCount != 0;
-            }
-        }
-
-        @Override
-        public void acquire() {
-            synchronized (this) {
-                mNestCount += 1;
-                if (DEBUG) {
-                    Slog.d(TAG, "Screen on blocked: mNestCount=" + mNestCount);
-                }
-            }
-        }
-
-        @Override
-        public void release() {
-            synchronized (this) {
-                mNestCount -= 1;
-                if (mNestCount < 0) {
-                    Log.wtf(TAG, "Screen on blocker was released without being acquired!",
-                            new Throwable());
-                    mNestCount = 0;
-                }
-                if (mNestCount == 0) {
-                    mHandler.sendEmptyMessage(MSG_SCREEN_ON_BLOCKER_RELEASED);
-                }
-                if (DEBUG) {
-                    Slog.d(TAG, "Screen on unblocked: mNestCount=" + mNestCount);
-                }
-            }
-        }
-
-        @Override
-        public String toString() {
-            synchronized (this) {
-                return "held=" + (mNestCount != 0) + ", mNestCount=" + mNestCount;
-            }
-        }
-    }
-
-    private final class DisplayBlankerImpl implements DisplayBlanker {
-        private boolean mBlanked;
-
-        @Override
-        public void blankAllDisplays() {
-            synchronized (this) {
-                mBlanked = true;
-                mDisplayManagerService.blankAllDisplaysFromPowerManager();
-                nativeSetInteractive(false);
-                nativeSetAutoSuspend(true);
-            }
-        }
-
-        @Override
-        public void unblankAllDisplays() {
-            synchronized (this) {
-                nativeSetAutoSuspend(false);
-                nativeSetInteractive(true);
-                mDisplayManagerService.unblankAllDisplaysFromPowerManager();
-                mBlanked = false;
-            }
-        }
-
-        @Override
-        public String toString() {
-            synchronized (this) {
-                return "blanked=" + mBlanked;
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/print/PrintManagerService.java b/services/java/com/android/server/print/PrintManagerService.java
deleted file mode 100644
index 98acc27..0000000
--- a/services/java/com/android/server/print/PrintManagerService.java
+++ /dev/null
@@ -1,656 +0,0 @@
-/*
- * Copyright (C) 2013 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.print;
-
-import android.Manifest;
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-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.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.print.IPrintDocumentAdapter;
-import android.print.IPrintJobStateChangeListener;
-import android.print.IPrintManager;
-import android.print.IPrinterDiscoveryObserver;
-import android.print.PrintAttributes;
-import android.print.PrintJobId;
-import android.print.PrintJobInfo;
-import android.print.PrinterId;
-import android.printservice.PrintServiceInfo;
-import android.provider.Settings;
-import android.text.TextUtils;
-import android.util.SparseArray;
-
-import com.android.internal.R;
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.os.BackgroundThread;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-public final class PrintManagerService 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 final Object mLock = new Object();
-
-    private final Context mContext;
-
-    private final SparseArray<UserState> mUserStates = new SparseArray<UserState>();
-
-    private int mCurrentUserId = UserHandle.USER_OWNER;
-
-    public PrintManagerService(Context context) {
-        mContext = context;
-        registerContentObservers();
-        registerBoradcastReceivers();
-    }
-
-    public void systemRuning() {
-        BackgroundThread.getHandler().post(new Runnable() {
-            @Override
-            public void run() {
-                final UserState userState;
-                synchronized (mLock) {
-                    userState = getCurrentUserStateLocked();
-                    userState.updateIfNeededLocked();
-                }
-                // This is the first time we switch to this user after boot, so
-                // now is the time to remove obsolete print jobs since they
-                // are from the last boot and no application would query them.
-                userState.removeObsoletePrintJobs();
-            }
-        });
-    }
-
-    @Override
-    public Bundle print(String printJobName, IPrintDocumentAdapter adapter,
-            PrintAttributes attributes, String packageName, int appId, int userId) {
-        final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        String resolvedPackageName = resolveCallingPackageNameEnforcingSecurity(packageName);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return userState.print(printJobName, adapter, attributes,
-                    resolvedPackageName, resolvedAppId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public List<PrintJobInfo> getPrintJobInfos(int appId, int userId) {
-        final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return userState.getPrintJobInfos(resolvedAppId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public PrintJobInfo getPrintJobInfo(PrintJobId printJobId, int appId, int userId) {
-        final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return userState.getPrintJobInfo(printJobId, resolvedAppId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void cancelPrintJob(PrintJobId printJobId, int appId, int userId) {
-        final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.cancelPrintJob(printJobId, resolvedAppId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void restartPrintJob(PrintJobId printJobId, int appId, int userId) {
-        final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.restartPrintJob(printJobId, resolvedAppId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public List<PrintServiceInfo> getEnabledPrintServices(int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return userState.getEnabledPrintServices();
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public List<PrintServiceInfo> getInstalledPrintServices(int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            return userState.getInstalledPrintServices();
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void createPrinterDiscoverySession(IPrinterDiscoveryObserver observer,
-            int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.createPrinterDiscoverySession(observer);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void destroyPrinterDiscoverySession(IPrinterDiscoveryObserver observer,
-            int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.destroyPrinterDiscoverySession(observer);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void startPrinterDiscovery(IPrinterDiscoveryObserver observer,
-            List<PrinterId> priorityList, int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.startPrinterDiscovery(observer, priorityList);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void stopPrinterDiscovery(IPrinterDiscoveryObserver observer, int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.stopPrinterDiscovery(observer);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void validatePrinters(List<PrinterId> printerIds, int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.validatePrinters(printerIds);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void startPrinterStateTracking(PrinterId printerId, int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.startPrinterStateTracking(printerId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void stopPrinterStateTracking(PrinterId printerId, int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.stopPrinterStateTracking(printerId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void addPrintJobStateChangeListener(IPrintJobStateChangeListener listener,
-            int appId, int userId) throws RemoteException {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.addPrintJobStateChangeListener(listener, resolvedAppId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void removePrintJobStateChangeListener(IPrintJobStateChangeListener listener,
-            int userId) {
-        final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
-        final UserState userState;
-        synchronized (mLock) {
-            userState = getOrCreateUserStateLocked(resolvedUserId);
-        }
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            userState.removePrintJobStateChangeListener(listener);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump PrintManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        synchronized (mLock) {
-            final long identity = Binder.clearCallingIdentity();
-            try {
-                pw.println("PRINT MANAGER STATE (dumpsys print)");
-                final int userStateCount = mUserStates.size();
-                for (int i = 0; i < userStateCount; i++) {
-                    UserState userState = mUserStates.valueAt(i);
-                    userState.dump(fd, pw, "");
-                    pw.println();
-                }
-            } finally {
-                Binder.restoreCallingIdentity(identity);
-            }
-        }
-    }
-
-    private void registerContentObservers() {
-        final Uri enabledPrintServicesUri = Settings.Secure.getUriFor(
-                Settings.Secure.ENABLED_PRINT_SERVICES);
-
-        ContentObserver observer = new ContentObserver(BackgroundThread.getHandler()) {
-            @Override
-            public void onChange(boolean selfChange, Uri uri) {
-                if (enabledPrintServicesUri.equals(uri)) {
-                    synchronized (mLock) {
-                        UserState userState = getCurrentUserStateLocked();
-                        userState.updateIfNeededLocked();
-                    }
-                }
-            }
-        };
-
-        mContext.getContentResolver().registerContentObserver(enabledPrintServicesUri,
-                false, observer, UserHandle.USER_ALL);
-    }
-
-    private void registerBoradcastReceivers() {
-        PackageMonitor monitor = new PackageMonitor() {
-            @Override
-            public boolean onPackageChanged(String packageName, int uid, String[] components) {
-                synchronized (mLock) {
-                    UserState userState = getOrCreateUserStateLocked(getChangingUserId());
-                    Iterator<ComponentName> iterator = userState.getEnabledServices().iterator();
-                    while (iterator.hasNext()) {
-                        ComponentName componentName = iterator.next();
-                        if (packageName.equals(componentName.getPackageName())) {
-                            userState.updateIfNeededLocked();
-                            return true;
-                        }
-                    }
-                }
-                return false;
-            }
-
-            @Override
-            public void onPackageRemoved(String packageName, int uid) {
-                synchronized (mLock) {
-                    UserState userState = getOrCreateUserStateLocked(getChangingUserId());
-                    Iterator<ComponentName> iterator = userState.getEnabledServices().iterator();
-                    while (iterator.hasNext()) {
-                        ComponentName componentName = iterator.next();
-                        if (packageName.equals(componentName.getPackageName())) {
-                            iterator.remove();
-                            persistComponentNamesToSettingLocked(
-                                    Settings.Secure.ENABLED_PRINT_SERVICES,
-                                    userState.getEnabledServices(), getChangingUserId());
-                            userState.updateIfNeededLocked();
-                            return;
-                        }
-                    }
-                }
-            }
-
-            @Override
-            public boolean onHandleForceStop(Intent intent, String[] stoppedPackages,
-                    int uid, boolean doit) {
-                synchronized (mLock) {
-                    UserState userState = getOrCreateUserStateLocked(getChangingUserId());
-                    boolean stoppedSomePackages = false;
-                    Iterator<ComponentName> iterator = userState.getEnabledServices().iterator();
-                    while (iterator.hasNext()) {
-                        ComponentName componentName = iterator.next();
-                        String componentPackage = componentName.getPackageName();
-                        for (String stoppedPackage : stoppedPackages) {
-                            if (componentPackage.equals(stoppedPackage)) {
-                                if (!doit) {
-                                    return true;
-                                }
-                                stoppedSomePackages = true;
-                                break;
-                            }
-                        }
-                    }
-                    if (stoppedSomePackages) {
-                        userState.updateIfNeededLocked();
-                    }
-                    return false;
-                }
-            }
-
-            @Override
-            public void onPackageAdded(String packageName, int uid) {
-                Intent intent = new Intent(android.printservice.PrintService.SERVICE_INTERFACE);
-                intent.setPackage(packageName);
-
-                List<ResolveInfo> installedServices = mContext.getPackageManager()
-                        .queryIntentServicesAsUser(intent, PackageManager.GET_SERVICES,
-                                getChangingUserId());
-
-                if (installedServices == null) {
-                    return;
-                }
-
-                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);
-                    String label = serviceInfo.loadLabel(mContext.getPackageManager()).toString();
-                    showEnableInstalledPrintServiceNotification(component, label,
-                            getChangingUserId());
-                }
-            }
-
-            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
-        monitor.register(mContext, BackgroundThread.getHandler().getLooper(),
-                UserHandle.ALL, true);
-
-        // user changes
-        IntentFilter intentFilter = new IntentFilter();
-        intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
-        intentFilter.addAction(Intent.ACTION_USER_REMOVED);
-
-        mContext.registerReceiverAsUser(new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                String action = intent.getAction();
-                if (Intent.ACTION_USER_SWITCHED.equals(action)) {
-                    switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
-                } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
-                    removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
-                }
-            }
-        }, UserHandle.ALL, intentFilter, null, BackgroundThread.getHandler());
-    }
-
-    private UserState getCurrentUserStateLocked() {
-        return getOrCreateUserStateLocked(mCurrentUserId);
-    }
-
-    private UserState getOrCreateUserStateLocked(int userId) {
-        UserState userState = mUserStates.get(userId);
-        if (userState == null) {
-            userState = new UserState(mContext, userId, mLock);
-            mUserStates.put(userId, userState);
-        }
-        return userState;
-    }
-
-    private void switchUser(int newUserId) {
-        UserState userState;
-        synchronized (mLock) {
-            if (newUserId == mCurrentUserId) {
-                return;
-            }
-            mCurrentUserId = newUserId;
-            userState = mUserStates.get(mCurrentUserId);
-            if (userState == null) {
-                userState = getCurrentUserStateLocked();
-                userState.updateIfNeededLocked();
-            } else {
-                userState.updateIfNeededLocked();
-            }
-        }
-        // This is the first time we switch to this user after boot, so
-        // now is the time to remove obsolete print jobs since they
-        // are from the last boot and no application would query them.
-        userState.removeObsoletePrintJobs();
-    }
-
-    private void removeUser(int removedUserId) {
-        synchronized (mLock) {
-            UserState userState = mUserStates.get(removedUserId);
-            if (userState != null) {
-                userState.destroyLocked();
-                mUserStates.remove(removedUserId);
-            }
-        }
-    }
-
-    private int resolveCallingAppEnforcingPermissions(int appId) {
-        final int callingUid = Binder.getCallingUid();
-        if (callingUid == 0 || callingUid == Process.SYSTEM_UID
-                || callingUid == Process.SHELL_UID) {
-            return appId;
-        }
-        final int callingAppId = UserHandle.getAppId(callingUid);
-        if (appId == callingAppId) {
-            return appId;
-        }
-        if (mContext.checkCallingPermission(
-                "com.android.printspooler.permission.ACCESS_ALL_PRINT_JOBS")
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Call from app " + callingAppId + " as app "
-                    + appId + " without com.android.printspooler.permission"
-                    + ".ACCESS_ALL_PRINT_JOBS");
-        }
-        return appId;
-    }
-
-    private int resolveCallingUserEnforcingPermissions(int userId) {
-        final int callingUid = Binder.getCallingUid();
-        if (callingUid == 0 || callingUid == Process.SYSTEM_UID
-                || callingUid == Process.SHELL_UID) {
-            return userId;
-        }
-        final int callingUserId = UserHandle.getUserId(callingUid);
-        if (callingUserId == userId) {
-            return userId;
-        }
-        if (mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)
-                != PackageManager.PERMISSION_GRANTED
-            ||  mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS)
-                != PackageManager.PERMISSION_GRANTED) {
-            if (userId == UserHandle.USER_CURRENT_OR_SELF) {
-                return callingUserId;
-            }
-            throw new SecurityException("Call from user " + callingUserId + " as user "
-                + userId + " without permission INTERACT_ACROSS_USERS or "
-                + "INTERACT_ACROSS_USERS_FULL not allowed.");
-        }
-        if (userId == UserHandle.USER_CURRENT || userId == UserHandle.USER_CURRENT_OR_SELF) {
-            return mCurrentUserId;
-        }
-        throw new IllegalArgumentException("Calling user can be changed to only "
-                + "UserHandle.USER_CURRENT or UserHandle.USER_CURRENT_OR_SELF.");
-    }
-
-    private String resolveCallingPackageNameEnforcingSecurity(String packageName) {
-        if (TextUtils.isEmpty(packageName)) {
-            return null;
-        }
-        String[] packages = mContext.getPackageManager().getPackagesForUid(
-                Binder.getCallingUid());
-        final int packageCount = packages.length;
-        for (int i = 0; i < packageCount; i++) {
-            if (packageName.equals(packages[i])) {
-                return packageName;
-            }
-        }
-        return null;
-    }
-
-    private void showEnableInstalledPrintServiceNotification(ComponentName component,
-            String label, int userId) {
-        UserHandle userHandle = new UserHandle(userId);
-
-        Intent intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
-        intent.putExtra(EXTRA_PRINT_SERVICE_COMPONENT_NAME, component.flattenToString());
-
-        PendingIntent pendingIntent = PendingIntent.getActivityAsUser(mContext, 0, intent,
-                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null, userHandle);
-
-        Notification.Builder builder = new Notification.Builder(mContext)
-                .setSmallIcon(R.drawable.ic_print)
-                .setContentTitle(mContext.getString(R.string.print_service_installed_title, label))
-                .setContentText(mContext.getString(R.string.print_service_installed_message))
-                .setContentIntent(pendingIntent)
-                .setWhen(System.currentTimeMillis())
-                .setAutoCancel(true)
-                .setShowWhen(true);
-
-        NotificationManager notificationManager = (NotificationManager) mContext
-                .getSystemService(Context.NOTIFICATION_SERVICE);
-
-        String notificationTag = getClass().getName() + ":" + component.flattenToString();
-        notificationManager.notifyAsUser(notificationTag, 0, builder.build(),
-                userHandle);
-    }
-}
diff --git a/services/java/com/android/server/updates/SELinuxPolicyInstallReceiver.java b/services/java/com/android/server/updates/SELinuxPolicyInstallReceiver.java
deleted file mode 100644
index 5dd30f1..0000000
--- a/services/java/com/android/server/updates/SELinuxPolicyInstallReceiver.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2013 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.updates;
-
-import android.content.Context;
-import android.content.Intent;
-import android.os.FileUtils;
-import android.os.SELinux;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.util.Base64;
-import android.util.Slog;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import libcore.io.ErrnoException;
-import libcore.io.IoUtils;
-import libcore.io.Libcore;
-
-public class SELinuxPolicyInstallReceiver extends ConfigUpdateInstallReceiver {
-
-    private static final String TAG = "SELinuxPolicyInstallReceiver";
-
-    private static final String sepolicyPath = "sepolicy";
-    private static final String fileContextsPath = "file_contexts";
-    private static final String propertyContextsPath = "property_contexts";
-    private static final String seappContextsPath = "seapp_contexts";
-
-    public SELinuxPolicyInstallReceiver() {
-        super("/data/security/bundle", "sepolicy_bundle", "metadata/", "version");
-    }
-
-    private void backupContexts(File contexts) {
-        new File(contexts, seappContextsPath).renameTo(
-                new File(contexts, seappContextsPath + "_backup"));
-
-        new File(contexts, propertyContextsPath).renameTo(
-                new File(contexts, propertyContextsPath + "_backup"));
-
-        new File(contexts, fileContextsPath).renameTo(
-                new File(contexts, fileContextsPath + "_backup"));
-
-        new File(contexts, sepolicyPath).renameTo(
-                new File(contexts, sepolicyPath + "_backup"));
-    }
-
-    private void copyUpdate(File contexts) {
-        new File(updateDir, seappContextsPath).renameTo(new File(contexts, seappContextsPath));
-        new File(updateDir, propertyContextsPath).renameTo(new File(contexts, propertyContextsPath));
-        new File(updateDir, fileContextsPath).renameTo(new File(contexts, fileContextsPath));
-        new File(updateDir, sepolicyPath).renameTo(new File(contexts, sepolicyPath));
-    }
-
-    private int readInt(BufferedInputStream reader) throws IOException {
-        int value = 0;
-        for (int i=0; i < 4; i++) {
-            value = (value << 8) | reader.read();
-        }
-        return value;
-    }
-
-    private int[] readChunkLengths(BufferedInputStream bundle) throws IOException {
-        int[] chunks = new int[4];
-        chunks[0] = readInt(bundle);
-        chunks[1] = readInt(bundle);
-        chunks[2] = readInt(bundle);
-        chunks[3] = readInt(bundle);
-        return chunks;
-    }
-
-    private void installFile(File destination, BufferedInputStream stream, int length)
-            throws IOException {
-        byte[] chunk = new byte[length];
-        stream.read(chunk, 0, length);
-        writeUpdate(updateDir, destination, Base64.decode(chunk, Base64.DEFAULT));
-    }
-
-    private void unpackBundle() throws IOException {
-        BufferedInputStream stream = new BufferedInputStream(new FileInputStream(updateContent));
-        try {
-            int[] chunkLengths = readChunkLengths(stream);
-            installFile(new File(updateDir, seappContextsPath), stream, chunkLengths[0]);
-            installFile(new File(updateDir, propertyContextsPath), stream, chunkLengths[1]);
-            installFile(new File(updateDir, fileContextsPath), stream, chunkLengths[2]);
-            installFile(new File(updateDir, sepolicyPath), stream, chunkLengths[3]);
-        } finally {
-            IoUtils.closeQuietly(stream);
-        }
-    }
-
-    private void applyUpdate() throws IOException, ErrnoException {
-        Slog.i(TAG, "Applying SELinux policy");
-        File contexts = new File(updateDir.getParentFile(), "contexts");
-        File current = new File(updateDir.getParentFile(), "current");
-        File update = new File(updateDir.getParentFile(), "update");
-        File tmp = new File(updateDir.getParentFile(), "tmp");
-        if (current.exists()) {
-            Libcore.os.symlink(updateDir.getPath(), update.getPath());
-            Libcore.os.rename(update.getPath(), current.getPath());
-        } else {
-            Libcore.os.symlink(updateDir.getPath(), current.getPath());
-        }
-        contexts.mkdirs();
-        backupContexts(contexts);
-        copyUpdate(contexts);
-        Libcore.os.symlink(contexts.getPath(), tmp.getPath());
-        Libcore.os.rename(tmp.getPath(), current.getPath());
-        SystemProperties.set("selinux.reload_policy", "1");
-    }
-
-    private void setEnforcingMode(Context context) {
-        String mode = Settings.Global.getString(context.getContentResolver(),
-            Settings.Global.SELINUX_STATUS);
-        if ("1".equals(mode)) {
-            Slog.i(TAG, "Setting enforcing mode");
-            SystemProperties.set("persist.selinux.enforcing", mode);
-        } else if ("0".equals(mode)) {
-            Slog.i(TAG, "Tried to set permissive mode, ignoring");
-        } else {
-            Slog.e(TAG, "Got invalid enforcing mode: " + mode);
-        }
-    }
-
-    @Override
-    protected void postInstall(Context context, Intent intent) {
-        try {
-            unpackBundle();
-            applyUpdate();
-            setEnforcingMode(context);
-        } catch (IllegalArgumentException e) {
-            Slog.e(TAG, "SELinux policy update malformed: ", e);
-        } catch (IOException e) {
-            Slog.e(TAG, "Could not update selinux policy: ", e);
-        } catch (ErrnoException e) {
-            Slog.e(TAG, "Could not update selinux policy: ", e);
-        }
-    }
-}
diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java
deleted file mode 100644
index 8a5e291..0000000
--- a/services/java/com/android/server/usb/UsbDeviceManager.java
+++ /dev/null
@@ -1,905 +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 an
- * limitations under the License.
- */
-
-package com.android.server.usb;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.database.ContentObserver;
-import android.hardware.usb.UsbAccessory;
-import android.hardware.usb.UsbManager;
-import android.os.FileUtils;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.os.ParcelFileDescriptor;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.UEventObserver;
-import android.os.UserHandle;
-import android.os.storage.StorageManager;
-import android.os.storage.StorageVolume;
-import android.provider.Settings;
-import android.util.Pair;
-import android.util.Slog;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.server.FgThread;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Scanner;
-
-/**
- * UsbDeviceManager manages USB state in device mode.
- */
-public class UsbDeviceManager {
-
-    private static final String TAG = UsbDeviceManager.class.getSimpleName();
-    private static final boolean DEBUG = false;
-
-    private static final String USB_STATE_MATCH =
-            "DEVPATH=/devices/virtual/android_usb/android0";
-    private static final String ACCESSORY_START_MATCH =
-            "DEVPATH=/devices/virtual/misc/usb_accessory";
-    private static final String FUNCTIONS_PATH =
-            "/sys/class/android_usb/android0/functions";
-    private static final String STATE_PATH =
-            "/sys/class/android_usb/android0/state";
-    private static final String MASS_STORAGE_FILE_PATH =
-            "/sys/class/android_usb/android0/f_mass_storage/lun/file";
-    private static final String RNDIS_ETH_ADDR_PATH =
-            "/sys/class/android_usb/android0/f_rndis/ethaddr";
-    private static final String AUDIO_SOURCE_PCM_PATH =
-            "/sys/class/android_usb/android0/f_audio_source/pcm";
-
-    private static final int MSG_UPDATE_STATE = 0;
-    private static final int MSG_ENABLE_ADB = 1;
-    private static final int MSG_SET_CURRENT_FUNCTIONS = 2;
-    private static final int MSG_SYSTEM_READY = 3;
-    private static final int MSG_BOOT_COMPLETED = 4;
-    private static final int MSG_USER_SWITCHED = 5;
-
-    private static final int AUDIO_MODE_NONE = 0;
-    private static final int AUDIO_MODE_SOURCE = 1;
-
-    // Delay for debouncing USB disconnects.
-    // We often get rapid connect/disconnect events when enabling USB functions,
-    // which need debouncing.
-    private static final int UPDATE_DELAY = 1000;
-
-    // Time we received a request to enter USB accessory mode
-    private long mAccessoryModeRequestTime = 0;
-
-    // Timeout for entering USB request mode.
-    // Request is cancelled if host does not configure device within 10 seconds.
-    private static final int ACCESSORY_REQUEST_TIMEOUT = 10 * 1000;
-
-    private static final String BOOT_MODE_PROPERTY = "ro.bootmode";
-
-    private UsbHandler mHandler;
-    private boolean mBootCompleted;
-
-    private final Object mLock = new Object();
-
-    private final Context mContext;
-    private final ContentResolver mContentResolver;
-    @GuardedBy("mLock")
-    private UsbSettingsManager mCurrentSettings;
-    private NotificationManager mNotificationManager;
-    private final boolean mHasUsbAccessory;
-    private boolean mUseUsbNotification;
-    private boolean mAdbEnabled;
-    private boolean mAudioSourceEnabled;
-    private Map<String, List<Pair<String, String>>> mOemModeMap;
-    private String[] mAccessoryStrings;
-    private UsbDebuggingManager mDebuggingManager;
-
-    private class AdbSettingsObserver extends ContentObserver {
-        public AdbSettingsObserver() {
-            super(null);
-        }
-        @Override
-        public void onChange(boolean selfChange) {
-            boolean enable = (Settings.Global.getInt(mContentResolver,
-                    Settings.Global.ADB_ENABLED, 0) > 0);
-            mHandler.sendMessage(MSG_ENABLE_ADB, enable);
-        }
-    }
-
-    /*
-     * Listens for uevent messages from the kernel to monitor the USB state
-     */
-    private final UEventObserver mUEventObserver = new UEventObserver() {
-        @Override
-        public void onUEvent(UEventObserver.UEvent event) {
-            if (DEBUG) Slog.v(TAG, "USB UEVENT: " + event.toString());
-
-            String state = event.get("USB_STATE");
-            String accessory = event.get("ACCESSORY");
-            if (state != null) {
-                mHandler.updateState(state);
-            } else if ("START".equals(accessory)) {
-                if (DEBUG) Slog.d(TAG, "got accessory start");
-                startAccessoryMode();
-            }
-        }
-    };
-
-    public UsbDeviceManager(Context context) {
-        mContext = context;
-        mContentResolver = context.getContentResolver();
-        PackageManager pm = mContext.getPackageManager();
-        mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
-        initRndisAddress();
-
-        readOemUsbOverrideConfig();
-
-        mHandler = new UsbHandler(FgThread.get().getLooper());
-
-        if (nativeIsStartRequested()) {
-            if (DEBUG) Slog.d(TAG, "accessory attached at boot");
-            startAccessoryMode();
-        }
-
-        boolean secureAdbEnabled = SystemProperties.getBoolean("ro.adb.secure", false);
-        boolean dataEncrypted = "1".equals(SystemProperties.get("vold.decrypt"));
-        if (secureAdbEnabled && !dataEncrypted) {
-            mDebuggingManager = new UsbDebuggingManager(context);
-        }
-    }
-
-    public void setCurrentSettings(UsbSettingsManager settings) {
-        synchronized (mLock) {
-            mCurrentSettings = settings;
-        }
-    }
-
-    private UsbSettingsManager getCurrentSettings() {
-        synchronized (mLock) {
-            return mCurrentSettings;
-        }
-    }
-
-    public void systemReady() {
-        if (DEBUG) Slog.d(TAG, "systemReady");
-
-        mNotificationManager = (NotificationManager)
-                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
-
-        // We do not show the USB notification if the primary volume supports mass storage.
-        // The legacy mass storage UI will be used instead.
-        boolean massStorageSupported = false;
-        final StorageManager storageManager = StorageManager.from(mContext);
-        final StorageVolume primary = storageManager.getPrimaryVolume();
-        massStorageSupported = primary != null && primary.allowMassStorage();
-        mUseUsbNotification = !massStorageSupported;
-
-        // make sure the ADB_ENABLED setting value matches the current state
-        Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0);
-
-        mHandler.sendEmptyMessage(MSG_SYSTEM_READY);
-    }
-
-    private void startAccessoryMode() {
-        if (!mHasUsbAccessory) return;
-
-        mAccessoryStrings = nativeGetAccessoryStrings();
-        boolean enableAudio = (nativeGetAudioMode() == AUDIO_MODE_SOURCE);
-        // don't start accessory mode if our mandatory strings have not been set
-        boolean enableAccessory = (mAccessoryStrings != null &&
-                        mAccessoryStrings[UsbAccessory.MANUFACTURER_STRING] != null &&
-                        mAccessoryStrings[UsbAccessory.MODEL_STRING] != null);
-        String functions = null;
-
-        if (enableAccessory && enableAudio) {
-            functions = UsbManager.USB_FUNCTION_ACCESSORY + ","
-                    + UsbManager.USB_FUNCTION_AUDIO_SOURCE;
-        } else if (enableAccessory) {
-            functions = UsbManager.USB_FUNCTION_ACCESSORY;
-        } else if (enableAudio) {
-            functions = UsbManager.USB_FUNCTION_AUDIO_SOURCE;
-        }
-
-        if (functions != null) {
-            mAccessoryModeRequestTime = SystemClock.elapsedRealtime();
-            setCurrentFunctions(functions, false);
-        }
-    }
-
-    private static void initRndisAddress() {
-        // configure RNDIS ethernet address based on our serial number using the same algorithm
-        // we had been previously using in kernel board files
-        final int ETH_ALEN = 6;
-        int address[] = new int[ETH_ALEN];
-        // first byte is 0x02 to signify a locally administered address
-        address[0] = 0x02;
-
-        String serial = SystemProperties.get("ro.serialno", "1234567890ABCDEF");
-        int serialLength = serial.length();
-        // XOR the USB serial across the remaining 5 bytes
-        for (int i = 0; i < serialLength; i++) {
-            address[i % (ETH_ALEN - 1) + 1] ^= (int)serial.charAt(i);
-        }
-        String addrString = String.format(Locale.US, "%02X:%02X:%02X:%02X:%02X:%02X",
-            address[0], address[1], address[2], address[3], address[4], address[5]);
-        try {
-            FileUtils.stringToFile(RNDIS_ETH_ADDR_PATH, addrString);
-        } catch (IOException e) {
-           Slog.e(TAG, "failed to write to " + RNDIS_ETH_ADDR_PATH);
-        }
-    }
-
-     private static String addFunction(String functions, String function) {
-         if ("none".equals(functions)) {
-             return function;
-         }
-        if (!containsFunction(functions, function)) {
-            if (functions.length() > 0) {
-                functions += ",";
-            }
-            functions += function;
-        }
-        return functions;
-    }
-
-    private static String removeFunction(String functions, String function) {
-        String[] split = functions.split(",");
-        for (int i = 0; i < split.length; i++) {
-            if (function.equals(split[i])) {
-                split[i] = null;
-            }
-        }
-        if (split.length == 1 && split[0] == null) {
-            return "none";
-        }
-        StringBuilder builder = new StringBuilder();
-         for (int i = 0; i < split.length; i++) {
-            String s = split[i];
-            if (s != null) {
-                if (builder.length() > 0) {
-                    builder.append(",");
-                }
-                builder.append(s);
-            }
-        }
-        return builder.toString();
-    }
-
-    private static boolean containsFunction(String functions, String function) {
-        int index = functions.indexOf(function);
-        if (index < 0) return false;
-        if (index > 0 && functions.charAt(index - 1) != ',') return false;
-        int charAfter = index + function.length();
-        if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false;
-        return true;
-    }
-
-    private final class UsbHandler extends Handler {
-
-        // current USB state
-        private boolean mConnected;
-        private boolean mConfigured;
-        private String mCurrentFunctions;
-        private String mDefaultFunctions;
-        private UsbAccessory mCurrentAccessory;
-        private int mUsbNotificationId;
-        private boolean mAdbNotificationShown;
-        private int mCurrentUser = UserHandle.USER_NULL;
-
-        private final BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                if (DEBUG) Slog.d(TAG, "boot completed");
-                mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED);
-            }
-        };
-
-        private final BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
-            @Override
-            public void onReceive(Context context, Intent intent) {
-                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
-                mHandler.obtainMessage(MSG_USER_SWITCHED, userId, 0).sendToTarget();
-            }
-        };
-
-        public UsbHandler(Looper looper) {
-            super(looper);
-            try {
-                // persist.sys.usb.config should never be unset.  But if it is, set it to "adb"
-                // so we have a chance of debugging what happened.
-                mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");
-
-                // Check if USB mode needs to be overridden depending on OEM specific bootmode.
-                mDefaultFunctions = processOemUsbOverride(mDefaultFunctions);
-
-                // sanity check the sys.usb.config system property
-                // this may be necessary if we crashed while switching USB configurations
-                String config = SystemProperties.get("sys.usb.config", "none");
-                if (!config.equals(mDefaultFunctions)) {
-                    Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions);
-                    SystemProperties.set("sys.usb.config", mDefaultFunctions);
-                }
-
-                mCurrentFunctions = mDefaultFunctions;
-                String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
-                updateState(state);
-                mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
-
-                // Upgrade step for previous versions that used persist.service.adb.enable
-                String value = SystemProperties.get("persist.service.adb.enable", "");
-                if (value.length() > 0) {
-                    char enable = value.charAt(0);
-                    if (enable == '1') {
-                        setAdbEnabled(true);
-                    } else if (enable == '0') {
-                        setAdbEnabled(false);
-                    }
-                    SystemProperties.set("persist.service.adb.enable", "");
-                }
-
-                // register observer to listen for settings changes
-                mContentResolver.registerContentObserver(
-                        Settings.Global.getUriFor(Settings.Global.ADB_ENABLED),
-                                false, new AdbSettingsObserver());
-
-                // Watch for USB configuration changes
-                mUEventObserver.startObserving(USB_STATE_MATCH);
-                mUEventObserver.startObserving(ACCESSORY_START_MATCH);
-
-                mContext.registerReceiver(
-                        mBootCompletedReceiver, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
-                mContext.registerReceiver(
-                        mUserSwitchedReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED));
-            } catch (Exception e) {
-                Slog.e(TAG, "Error initializing UsbHandler", e);
-            }
-        }
-
-        public void sendMessage(int what, boolean arg) {
-            removeMessages(what);
-            Message m = Message.obtain(this, what);
-            m.arg1 = (arg ? 1 : 0);
-            sendMessage(m);
-        }
-
-        public void sendMessage(int what, Object arg) {
-            removeMessages(what);
-            Message m = Message.obtain(this, what);
-            m.obj = arg;
-            sendMessage(m);
-        }
-
-        public void sendMessage(int what, Object arg0, boolean arg1) {
-            removeMessages(what);
-            Message m = Message.obtain(this, what);
-            m.obj = arg0;
-            m.arg1 = (arg1 ? 1 : 0);
-            sendMessage(m);
-        }
-
-        public void updateState(String state) {
-            int connected, configured;
-
-            if ("DISCONNECTED".equals(state)) {
-                connected = 0;
-                configured = 0;
-            } else if ("CONNECTED".equals(state)) {
-                connected = 1;
-                configured = 0;
-            } else if ("CONFIGURED".equals(state)) {
-                connected = 1;
-                configured = 1;
-            } else {
-                Slog.e(TAG, "unknown state " + state);
-                return;
-            }
-            removeMessages(MSG_UPDATE_STATE);
-            Message msg = Message.obtain(this, MSG_UPDATE_STATE);
-            msg.arg1 = connected;
-            msg.arg2 = configured;
-            // debounce disconnects to avoid problems bringing up USB tethering
-            sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0);
-        }
-
-        private boolean waitForState(String state) {
-            // wait for the transition to complete.
-            // give up after 1 second.
-            for (int i = 0; i < 20; i++) {
-                // State transition is done when sys.usb.state is set to the new configuration
-                if (state.equals(SystemProperties.get("sys.usb.state"))) return true;
-                SystemClock.sleep(50);
-            }
-            Slog.e(TAG, "waitForState(" + state + ") FAILED");
-            return false;
-        }
-
-        private boolean setUsbConfig(String config) {
-            if (DEBUG) Slog.d(TAG, "setUsbConfig(" + config + ")");
-            // set the new configuration
-            SystemProperties.set("sys.usb.config", config);
-            return waitForState(config);
-        }
-
-        private void setAdbEnabled(boolean enable) {
-            if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable);
-            if (enable != mAdbEnabled) {
-                mAdbEnabled = enable;
-                // Due to the persist.sys.usb.config property trigger, changing adb state requires
-                // switching to default function
-                setEnabledFunctions(mDefaultFunctions, true);
-                updateAdbNotification();
-            }
-            if (mDebuggingManager != null) {
-                mDebuggingManager.setAdbEnabled(mAdbEnabled);
-            }
-        }
-
-        private void setEnabledFunctions(String functions, boolean makeDefault) {
-            if (DEBUG) Slog.d(TAG, "setEnabledFunctions " + functions
-                    + " makeDefault: " + makeDefault);
-
-            // Do not update persystent.sys.usb.config if the device is booted up
-            // with OEM specific mode.
-            if (functions != null && makeDefault && !needsOemUsbOverride()) {
-
-                if (mAdbEnabled) {
-                    functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
-                } else {
-                    functions = removeFunction(functions, UsbManager.USB_FUNCTION_ADB);
-                }
-                if (!mDefaultFunctions.equals(functions)) {
-                    if (!setUsbConfig("none")) {
-                        Slog.e(TAG, "Failed to disable USB");
-                        // revert to previous configuration if we fail
-                        setUsbConfig(mCurrentFunctions);
-                        return;
-                    }
-                    // setting this property will also change the current USB state
-                    // via a property trigger
-                    SystemProperties.set("persist.sys.usb.config", functions);
-                    if (waitForState(functions)) {
-                        mCurrentFunctions = functions;
-                        mDefaultFunctions = functions;
-                    } else {
-                        Slog.e(TAG, "Failed to switch persistent USB config to " + functions);
-                        // revert to previous configuration if we fail
-                        SystemProperties.set("persist.sys.usb.config", mDefaultFunctions);
-                    }
-                }
-            } else {
-                if (functions == null) {
-                    functions = mDefaultFunctions;
-                }
-
-                // Override with bootmode specific usb mode if needed
-                functions = processOemUsbOverride(functions);
-
-                if (mAdbEnabled) {
-                    functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
-                } else {
-                    functions = removeFunction(functions, UsbManager.USB_FUNCTION_ADB);
-                }
-                if (!mCurrentFunctions.equals(functions)) {
-                    if (!setUsbConfig("none")) {
-                        Slog.e(TAG, "Failed to disable USB");
-                        // revert to previous configuration if we fail
-                        setUsbConfig(mCurrentFunctions);
-                        return;
-                    }
-                    if (setUsbConfig(functions)) {
-                        mCurrentFunctions = functions;
-                    } else {
-                        Slog.e(TAG, "Failed to switch USB config to " + functions);
-                        // revert to previous configuration if we fail
-                        setUsbConfig(mCurrentFunctions);
-                    }
-                }
-            }
-        }
-
-        private void updateCurrentAccessory() {
-            // We are entering accessory mode if we have received a request from the host
-            // and the request has not timed out yet.
-            boolean enteringAccessoryMode =
-                    mAccessoryModeRequestTime > 0 &&
-                        SystemClock.elapsedRealtime() <
-                            mAccessoryModeRequestTime + ACCESSORY_REQUEST_TIMEOUT;
-
-            if (mConfigured && enteringAccessoryMode) {
-                // successfully entered accessory mode
-                mAccessoryModeRequestTime = 0;
-
-                if (mAccessoryStrings != null) {
-                    mCurrentAccessory = new UsbAccessory(mAccessoryStrings);
-                    Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);
-                    // defer accessoryAttached if system is not ready
-                    if (mBootCompleted) {
-                        getCurrentSettings().accessoryAttached(mCurrentAccessory);
-                    } // else handle in mBootCompletedReceiver
-                } else {
-                    Slog.e(TAG, "nativeGetAccessoryStrings failed");
-                }
-            } else if (!enteringAccessoryMode) {
-                // make sure accessory mode is off
-                // and restore default functions
-                Slog.d(TAG, "exited USB accessory mode");
-                setEnabledFunctions(mDefaultFunctions, false);
-
-                if (mCurrentAccessory != null) {
-                    if (mBootCompleted) {
-                        getCurrentSettings().accessoryDetached(mCurrentAccessory);
-                    }
-                    mCurrentAccessory = null;
-                    mAccessoryStrings = null;
-                }
-            }
-        }
-
-        private void updateUsbState() {
-            // send a sticky broadcast containing current USB state
-            Intent intent = new Intent(UsbManager.ACTION_USB_STATE);
-            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-            intent.putExtra(UsbManager.USB_CONNECTED, mConnected);
-            intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured);
-
-            if (mCurrentFunctions != null) {
-                String[] functions = mCurrentFunctions.split(",");
-                for (int i = 0; i < functions.length; i++) {
-                    intent.putExtra(functions[i], true);
-                }
-            }
-
-            if (DEBUG) Slog.d(TAG, "broadcasting " + intent + " connected: " + mConnected
-                                    + " configured: " + mConfigured);
-            mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
-        }
-
-        private void updateAudioSourceFunction() {
-            boolean enabled = containsFunction(mCurrentFunctions,
-                    UsbManager.USB_FUNCTION_AUDIO_SOURCE);
-            if (enabled != mAudioSourceEnabled) {
-                // send a sticky broadcast containing current USB state
-                Intent intent = new Intent(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG);
-                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
-                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
-                intent.putExtra("state", (enabled ? 1 : 0));
-                if (enabled) {
-                    try {
-                        Scanner scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH));
-                        int card = scanner.nextInt();
-                        int device = scanner.nextInt();
-                        intent.putExtra("card", card);
-                        intent.putExtra("device", device);
-                    } catch (FileNotFoundException e) {
-                        Slog.e(TAG, "could not open audio source PCM file", e);
-                    }
-                }
-                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
-                mAudioSourceEnabled = enabled;
-            }
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_UPDATE_STATE:
-                    mConnected = (msg.arg1 == 1);
-                    mConfigured = (msg.arg2 == 1);
-                    updateUsbNotification();
-                    updateAdbNotification();
-                    if (containsFunction(mCurrentFunctions,
-                            UsbManager.USB_FUNCTION_ACCESSORY)) {
-                        updateCurrentAccessory();
-                    } else if (!mConnected) {
-                        // restore defaults when USB is disconnected
-                        setEnabledFunctions(mDefaultFunctions, false);
-                    }
-                    if (mBootCompleted) {
-                        updateUsbState();
-                        updateAudioSourceFunction();
-                    }
-                    break;
-                case MSG_ENABLE_ADB:
-                    setAdbEnabled(msg.arg1 == 1);
-                    break;
-                case MSG_SET_CURRENT_FUNCTIONS:
-                    String functions = (String)msg.obj;
-                    boolean makeDefault = (msg.arg1 == 1);
-                    setEnabledFunctions(functions, makeDefault);
-                    break;
-                case MSG_SYSTEM_READY:
-                    updateUsbNotification();
-                    updateAdbNotification();
-                    updateUsbState();
-                    updateAudioSourceFunction();
-                    break;
-                case MSG_BOOT_COMPLETED:
-                    mBootCompleted = true;
-                    if (mCurrentAccessory != null) {
-                        getCurrentSettings().accessoryAttached(mCurrentAccessory);
-                    }
-                    if (mDebuggingManager != null) {
-                        mDebuggingManager.setAdbEnabled(mAdbEnabled);
-                    }
-                    break;
-                case MSG_USER_SWITCHED: {
-                    final boolean mtpActive =
-                            containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)
-                            || containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP);
-                    if (mtpActive && mCurrentUser != UserHandle.USER_NULL) {
-                        Slog.v(TAG, "Current user switched; resetting USB host stack for MTP");
-                        setUsbConfig("none");
-                        setUsbConfig(mCurrentFunctions);
-                    }
-                    mCurrentUser = msg.arg1;
-                    break;
-                }
-            }
-        }
-
-        public UsbAccessory getCurrentAccessory() {
-            return mCurrentAccessory;
-        }
-
-        private void updateUsbNotification() {
-            if (mNotificationManager == null || !mUseUsbNotification) return;
-            int id = 0;
-            Resources r = mContext.getResources();
-            if (mConnected) {
-                if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
-                    id = com.android.internal.R.string.usb_mtp_notification_title;
-                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
-                    id = com.android.internal.R.string.usb_ptp_notification_title;
-                } else if (containsFunction(mCurrentFunctions,
-                        UsbManager.USB_FUNCTION_MASS_STORAGE)) {
-                    id = com.android.internal.R.string.usb_cd_installer_notification_title;
-                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
-                    id = com.android.internal.R.string.usb_accessory_notification_title;
-                } else {
-                    // There is a different notification for USB tethering so we don't need one here
-                    //if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
-                    //    Slog.e(TAG, "No known USB function in updateUsbNotification");
-                    //}
-                }
-            }
-            if (id != mUsbNotificationId) {
-                // clear notification if title needs changing
-                if (mUsbNotificationId != 0) {
-                    mNotificationManager.cancelAsUser(null, mUsbNotificationId,
-                            UserHandle.ALL);
-                    mUsbNotificationId = 0;
-                }
-                if (id != 0) {
-                    CharSequence message = r.getText(
-                            com.android.internal.R.string.usb_notification_message);
-                    CharSequence title = r.getText(id);
-
-                    Notification notification = new Notification();
-                    notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
-                    notification.when = 0;
-                    notification.flags = Notification.FLAG_ONGOING_EVENT;
-                    notification.tickerText = title;
-                    notification.defaults = 0; // please be quiet
-                    notification.sound = null;
-                    notification.vibrate = null;
-                    notification.priority = Notification.PRIORITY_MIN;
-
-                    Intent intent = Intent.makeRestartActivityTask(
-                            new ComponentName("com.android.settings",
-                                    "com.android.settings.UsbSettings"));
-                    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
-                            intent, 0, null, UserHandle.CURRENT);
-                    notification.setLatestEventInfo(mContext, title, message, pi);
-                    mNotificationManager.notifyAsUser(null, id, notification,
-                            UserHandle.ALL);
-                    mUsbNotificationId = id;
-                }
-            }
-        }
-
-        private void updateAdbNotification() {
-            if (mNotificationManager == null) return;
-            final int id = com.android.internal.R.string.adb_active_notification_title;
-            if (mAdbEnabled && mConnected) {
-                if ("0".equals(SystemProperties.get("persist.adb.notify"))) return;
-
-                if (!mAdbNotificationShown) {
-                    Resources r = mContext.getResources();
-                    CharSequence title = r.getText(id);
-                    CharSequence message = r.getText(
-                            com.android.internal.R.string.adb_active_notification_message);
-
-                    Notification notification = new Notification();
-                    notification.icon = com.android.internal.R.drawable.stat_sys_adb;
-                    notification.when = 0;
-                    notification.flags = Notification.FLAG_ONGOING_EVENT;
-                    notification.tickerText = title;
-                    notification.defaults = 0; // please be quiet
-                    notification.sound = null;
-                    notification.vibrate = null;
-                    notification.priority = Notification.PRIORITY_LOW;
-
-                    Intent intent = Intent.makeRestartActivityTask(
-                            new ComponentName("com.android.settings",
-                                    "com.android.settings.DevelopmentSettings"));
-                    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
-                            intent, 0, null, UserHandle.CURRENT);
-                    notification.setLatestEventInfo(mContext, title, message, pi);
-                    mAdbNotificationShown = true;
-                    mNotificationManager.notifyAsUser(null, id, notification,
-                            UserHandle.ALL);
-                }
-            } else if (mAdbNotificationShown) {
-                mAdbNotificationShown = false;
-                mNotificationManager.cancelAsUser(null, id, UserHandle.ALL);
-            }
-        }
-
-        public void dump(FileDescriptor fd, PrintWriter pw) {
-            pw.println("  USB Device State:");
-            pw.println("    Current Functions: " + mCurrentFunctions);
-            pw.println("    Default Functions: " + mDefaultFunctions);
-            pw.println("    mConnected: " + mConnected);
-            pw.println("    mConfigured: " + mConfigured);
-            pw.println("    mCurrentAccessory: " + mCurrentAccessory);
-            try {
-                pw.println("    Kernel state: "
-                        + FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim());
-                pw.println("    Kernel function list: "
-                        + FileUtils.readTextFile(new File(FUNCTIONS_PATH), 0, null).trim());
-                pw.println("    Mass storage backing file: "
-                        + FileUtils.readTextFile(new File(MASS_STORAGE_FILE_PATH), 0, null).trim());
-            } catch (IOException e) {
-                pw.println("IOException: " + e);
-            }
-        }
-    }
-
-    /* returns the currently attached USB accessory */
-    public UsbAccessory getCurrentAccessory() {
-        return mHandler.getCurrentAccessory();
-    }
-
-    /* opens the currently attached USB accessory */
-    public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
-        UsbAccessory currentAccessory = mHandler.getCurrentAccessory();
-        if (currentAccessory == null) {
-            throw new IllegalArgumentException("no accessory attached");
-        }
-        if (!currentAccessory.equals(accessory)) {
-            String error = accessory.toString()
-                    + " does not match current accessory "
-                    + currentAccessory;
-            throw new IllegalArgumentException(error);
-        }
-        getCurrentSettings().checkPermission(accessory);
-        return nativeOpenAccessory();
-    }
-
-    public void setCurrentFunctions(String functions, boolean makeDefault) {
-        if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ") default: " + makeDefault);
-        mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, makeDefault);
-    }
-
-    public void setMassStorageBackingFile(String path) {
-        if (path == null) path = "";
-        try {
-            FileUtils.stringToFile(MASS_STORAGE_FILE_PATH, path);
-        } catch (IOException e) {
-           Slog.e(TAG, "failed to write to " + MASS_STORAGE_FILE_PATH);
-        }
-    }
-
-    private void readOemUsbOverrideConfig() {
-        String[] configList = mContext.getResources().getStringArray(
-            com.android.internal.R.array.config_oemUsbModeOverride);
-
-        if (configList != null) {
-            for (String config: configList) {
-                String[] items = config.split(":");
-                if (items.length == 3) {
-                    if (mOemModeMap == null) {
-                        mOemModeMap = new HashMap<String, List<Pair<String, String>>>();
-                    }
-                    List overrideList = mOemModeMap.get(items[0]);
-                    if (overrideList == null) {
-                        overrideList = new LinkedList<Pair<String, String>>();
-                        mOemModeMap.put(items[0], overrideList);
-                    }
-                    overrideList.add(new Pair<String, String>(items[1], items[2]));
-                }
-            }
-        }
-    }
-
-    private boolean needsOemUsbOverride() {
-        if (mOemModeMap == null) return false;
-
-        String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown");
-        return (mOemModeMap.get(bootMode) != null) ? true : false;
-    }
-
-    private String processOemUsbOverride(String usbFunctions) {
-        if ((usbFunctions == null) || (mOemModeMap == null)) return usbFunctions;
-
-        String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown");
-
-        List<Pair<String, String>> overrides = mOemModeMap.get(bootMode);
-        if (overrides != null) {
-            for (Pair<String, String> pair: overrides) {
-                if (pair.first.equals(usbFunctions)) {
-                    Slog.d(TAG, "OEM USB override: " + pair.first + " ==> " + pair.second);
-                    return pair.second;
-                }
-            }
-        }
-        // return passed in functions as is.
-        return usbFunctions;
-    }
-
-    public void allowUsbDebugging(boolean alwaysAllow, String publicKey) {
-        if (mDebuggingManager != null) {
-            mDebuggingManager.allowUsbDebugging(alwaysAllow, publicKey);
-        }
-    }
-
-    public void denyUsbDebugging() {
-        if (mDebuggingManager != null) {
-            mDebuggingManager.denyUsbDebugging();
-        }
-    }
-
-    public void clearUsbDebuggingKeys() {
-        if (mDebuggingManager != null) {
-            mDebuggingManager.clearUsbDebuggingKeys();
-        } else {
-            throw new RuntimeException("Cannot clear Usb Debugging keys, "
-                        + "UsbDebuggingManager not enabled");
-        }
-    }
-
-    public void dump(FileDescriptor fd, PrintWriter pw) {
-        if (mHandler != null) {
-            mHandler.dump(fd, pw);
-        }
-        if (mDebuggingManager != null) {
-            mDebuggingManager.dump(fd, pw);
-        }
-    }
-
-    private native String[] nativeGetAccessoryStrings();
-    private native ParcelFileDescriptor nativeOpenAccessory();
-    private native boolean nativeIsStartRequested();
-    private native int nativeGetAudioMode();
-}
diff --git a/services/java/com/android/server/usb/UsbHostManager.java b/services/java/com/android/server/usb/UsbHostManager.java
deleted file mode 100644
index 10272f2..0000000
--- a/services/java/com/android/server/usb/UsbHostManager.java
+++ /dev/null
@@ -1,220 +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 an
- * limitations under the License.
- */
-
-package com.android.server.usb;
-
-import android.content.Context;
-import android.hardware.usb.UsbConstants;
-import android.hardware.usb.UsbDevice;
-import android.hardware.usb.UsbEndpoint;
-import android.hardware.usb.UsbInterface;
-import android.os.Bundle;
-import android.os.ParcelFileDescriptor;
-import android.os.Parcelable;
-import android.util.Slog;
-
-import com.android.internal.annotations.GuardedBy;
-
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-import java.util.HashMap;
-
-/**
- * UsbHostManager manages USB state in host mode.
- */
-public class UsbHostManager {
-    private static final String TAG = UsbHostManager.class.getSimpleName();
-    private static final boolean LOG = false;
-
-    // contains all connected USB devices
-    private final HashMap<String, UsbDevice> mDevices = new HashMap<String, UsbDevice>();
-
-    // USB busses to exclude from USB host support
-    private final String[] mHostBlacklist;
-
-    private final Context mContext;
-    private final Object mLock = new Object();
-
-    @GuardedBy("mLock")
-    private UsbSettingsManager mCurrentSettings;
-
-    public UsbHostManager(Context context) {
-        mContext = context;
-        mHostBlacklist = context.getResources().getStringArray(
-                com.android.internal.R.array.config_usbHostBlacklist);
-    }
-
-    public void setCurrentSettings(UsbSettingsManager settings) {
-        synchronized (mLock) {
-            mCurrentSettings = settings;
-        }
-    }
-
-    private UsbSettingsManager getCurrentSettings() {
-        synchronized (mLock) {
-            return mCurrentSettings;
-        }
-    }
-
-    private boolean isBlackListed(String deviceName) {
-        int count = mHostBlacklist.length;
-        for (int i = 0; i < count; i++) {
-            if (deviceName.startsWith(mHostBlacklist[i])) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /* returns true if the USB device should not be accessible by applications */
-    private boolean isBlackListed(int clazz, int subClass, int protocol) {
-        // blacklist hubs
-        if (clazz == UsbConstants.USB_CLASS_HUB) return true;
-
-        // blacklist HID boot devices (mouse and keyboard)
-        if (clazz == UsbConstants.USB_CLASS_HID &&
-                subClass == UsbConstants.USB_INTERFACE_SUBCLASS_BOOT) {
-            return true;
-        }
-
-        return false;
-    }
-
-    /* Called from JNI in monitorUsbHostBus() to report new USB devices */
-    private void usbDeviceAdded(String deviceName, int vendorID, int productID,
-            int deviceClass, int deviceSubclass, int deviceProtocol,
-            /* array of quintuples containing id, class, subclass, protocol
-               and number of endpoints for each interface */
-            int[] interfaceValues,
-           /* array of quadruples containing address, attributes, max packet size
-              and interval for each endpoint */
-            int[] endpointValues) {
-
-        if (isBlackListed(deviceName) ||
-                isBlackListed(deviceClass, deviceSubclass, deviceProtocol)) {
-            return;
-        }
-
-        synchronized (mLock) {
-            if (mDevices.get(deviceName) != null) {
-                Slog.w(TAG, "device already on mDevices list: " + deviceName);
-                return;
-            }
-
-            int numInterfaces = interfaceValues.length / 5;
-            Parcelable[] interfaces = new UsbInterface[numInterfaces];
-            try {
-                // repackage interfaceValues as an array of UsbInterface
-                int intf, endp, ival = 0, eval = 0;
-                for (intf = 0; intf < numInterfaces; intf++) {
-                    int interfaceId = interfaceValues[ival++];
-                    int interfaceClass = interfaceValues[ival++];
-                    int interfaceSubclass = interfaceValues[ival++];
-                    int interfaceProtocol = interfaceValues[ival++];
-                    int numEndpoints = interfaceValues[ival++];
-
-                    Parcelable[] endpoints = new UsbEndpoint[numEndpoints];
-                    for (endp = 0; endp < numEndpoints; endp++) {
-                        int address = endpointValues[eval++];
-                        int attributes = endpointValues[eval++];
-                        int maxPacketSize = endpointValues[eval++];
-                        int interval = endpointValues[eval++];
-                        endpoints[endp] = new UsbEndpoint(address, attributes,
-                                maxPacketSize, interval);
-                    }
-
-                    // don't allow if any interfaces are blacklisted
-                    if (isBlackListed(interfaceClass, interfaceSubclass, interfaceProtocol)) {
-                        return;
-                    }
-                    interfaces[intf] = new UsbInterface(interfaceId, interfaceClass,
-                            interfaceSubclass, interfaceProtocol, endpoints);
-                }
-            } catch (Exception e) {
-                // beware of index out of bound exceptions, which might happen if
-                // a device does not set bNumEndpoints correctly
-                Slog.e(TAG, "error parsing USB descriptors", e);
-                return;
-            }
-
-            UsbDevice device = new UsbDevice(deviceName, vendorID, productID,
-                    deviceClass, deviceSubclass, deviceProtocol, interfaces);
-            mDevices.put(deviceName, device);
-            getCurrentSettings().deviceAttached(device);
-        }
-    }
-
-    /* Called from JNI in monitorUsbHostBus to report USB device removal */
-    private void usbDeviceRemoved(String deviceName) {
-        synchronized (mLock) {
-            UsbDevice device = mDevices.remove(deviceName);
-            if (device != null) {
-                getCurrentSettings().deviceDetached(device);
-            }
-        }
-    }
-
-    public void systemReady() {
-        synchronized (mLock) {
-            // Create a thread to call into native code to wait for USB host events.
-            // This thread will call us back on usbDeviceAdded and usbDeviceRemoved.
-            Runnable runnable = new Runnable() {
-                public void run() {
-                    monitorUsbHostBus();
-                }
-            };
-            new Thread(null, runnable, "UsbService host thread").start();
-        }
-    }
-
-    /* Returns a list of all currently attached USB devices */
-    public void getDeviceList(Bundle devices) {
-        synchronized (mLock) {
-            for (String name : mDevices.keySet()) {
-                devices.putParcelable(name, mDevices.get(name));
-            }
-        }
-    }
-
-    /* Opens the specified USB device */
-    public ParcelFileDescriptor openDevice(String deviceName) {
-        synchronized (mLock) {
-            if (isBlackListed(deviceName)) {
-                throw new SecurityException("USB device is on a restricted bus");
-            }
-            UsbDevice device = mDevices.get(deviceName);
-            if (device == null) {
-                // if it is not in mDevices, it either does not exist or is blacklisted
-                throw new IllegalArgumentException(
-                        "device " + deviceName + " does not exist or is restricted");
-            }
-            getCurrentSettings().checkPermission(device);
-            return nativeOpenDevice(deviceName);
-        }
-    }
-
-    public void dump(FileDescriptor fd, PrintWriter pw) {
-        synchronized (mLock) {
-            pw.println("  USB Host State:");
-            for (String name : mDevices.keySet()) {
-                pw.println("    " + name + ": " + mDevices.get(name));
-            }
-        }
-    }
-
-    private native void monitorUsbHostBus();
-    private native ParcelFileDescriptor nativeOpenDevice(String deviceName);
-}
diff --git a/services/java/com/android/server/usb/UsbService.java b/services/java/com/android/server/usb/UsbService.java
deleted file mode 100644
index 36669b1..0000000
--- a/services/java/com/android/server/usb/UsbService.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (C) 2010 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 an
- * limitations under the License.
- */
-
-package com.android.server.usb;
-
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.PackageManager;
-import android.hardware.usb.IUsbManager;
-import android.hardware.usb.UsbAccessory;
-import android.hardware.usb.UsbDevice;
-import android.os.Bundle;
-import android.os.ParcelFileDescriptor;
-import android.os.UserHandle;
-import android.util.SparseArray;
-
-import com.android.internal.annotations.GuardedBy;
-import com.android.internal.util.IndentingPrintWriter;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
-
-/**
- * UsbService manages all USB related state, including both host and device support.
- * Host related events and calls are delegated to UsbHostManager, and device related
- * support is delegated to UsbDeviceManager.
- */
-public class UsbService extends IUsbManager.Stub {
-    private static final String TAG = "UsbService";
-
-    private final Context mContext;
-
-    private UsbDeviceManager mDeviceManager;
-    private UsbHostManager mHostManager;
-
-    private final Object mLock = new Object();
-
-    /** Map from {@link UserHandle} to {@link UsbSettingsManager} */
-    @GuardedBy("mLock")
-    private final SparseArray<UsbSettingsManager>
-            mSettingsByUser = new SparseArray<UsbSettingsManager>();
-
-    private UsbSettingsManager getSettingsForUser(int userId) {
-        synchronized (mLock) {
-            UsbSettingsManager settings = mSettingsByUser.get(userId);
-            if (settings == null) {
-                settings = new UsbSettingsManager(mContext, new UserHandle(userId));
-                mSettingsByUser.put(userId, settings);
-            }
-            return settings;
-        }
-    }
-
-    public UsbService(Context context) {
-        mContext = context;
-
-        final PackageManager pm = mContext.getPackageManager();
-        if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
-            mHostManager = new UsbHostManager(context);
-        }
-        if (new File("/sys/class/android_usb").exists()) {
-            mDeviceManager = new UsbDeviceManager(context);
-        }
-
-        setCurrentUser(UserHandle.USER_OWNER);
-
-        final IntentFilter userFilter = new IntentFilter();
-        userFilter.addAction(Intent.ACTION_USER_SWITCHED);
-        userFilter.addAction(Intent.ACTION_USER_STOPPED);
-        mContext.registerReceiver(mUserReceiver, userFilter, null, null);
-    }
-
-    private BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
-            final String action = intent.getAction();
-            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
-                setCurrentUser(userId);
-            } else if (Intent.ACTION_USER_STOPPED.equals(action)) {
-                synchronized (mLock) {
-                    mSettingsByUser.remove(userId);
-                }
-            }
-        }
-    };
-
-    private void setCurrentUser(int userId) {
-        final UsbSettingsManager userSettings = getSettingsForUser(userId);
-        if (mHostManager != null) {
-            mHostManager.setCurrentSettings(userSettings);
-        }
-        if (mDeviceManager != null) {
-            mDeviceManager.setCurrentSettings(userSettings);
-        }
-    }
-
-    public void systemReady() {
-        if (mDeviceManager != null) {
-            mDeviceManager.systemReady();
-        }
-        if (mHostManager != null) {
-            mHostManager.systemReady();
-        }
-    }
-
-    /* Returns a list of all currently attached USB devices (host mdoe) */
-    @Override
-    public void getDeviceList(Bundle devices) {
-        if (mHostManager != null) {
-            mHostManager.getDeviceList(devices);
-        }
-    }
-
-    /* Opens the specified USB device (host mode) */
-    @Override
-    public ParcelFileDescriptor openDevice(String deviceName) {
-        if (mHostManager != null) {
-            return mHostManager.openDevice(deviceName);
-        } else {
-            return null;
-        }
-    }
-
-    /* returns the currently attached USB accessory (device mode) */
-    @Override
-    public UsbAccessory getCurrentAccessory() {
-        if (mDeviceManager != null) {
-            return mDeviceManager.getCurrentAccessory();
-        } else {
-            return null;
-        }
-    }
-
-    /* opens the currently attached USB accessory (device mode) */
-    @Override
-    public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
-        if (mDeviceManager != null) {
-            return mDeviceManager.openAccessory(accessory);
-        } else {
-            return null;
-        }
-    }
-
-    @Override
-    public void setDevicePackage(UsbDevice device, String packageName, int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        getSettingsForUser(userId).setDevicePackage(device, packageName);
-    }
-
-    @Override
-    public void setAccessoryPackage(UsbAccessory accessory, String packageName, int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        getSettingsForUser(userId).setAccessoryPackage(accessory, packageName);
-    }
-
-    @Override
-    public boolean hasDevicePermission(UsbDevice device) {
-        final int userId = UserHandle.getCallingUserId();
-        return getSettingsForUser(userId).hasPermission(device);
-    }
-
-    @Override
-    public boolean hasAccessoryPermission(UsbAccessory accessory) {
-        final int userId = UserHandle.getCallingUserId();
-        return getSettingsForUser(userId).hasPermission(accessory);
-    }
-
-    @Override
-    public void requestDevicePermission(UsbDevice device, String packageName, PendingIntent pi) {
-        final int userId = UserHandle.getCallingUserId();
-        getSettingsForUser(userId).requestPermission(device, packageName, pi);
-    }
-
-    @Override
-    public void requestAccessoryPermission(
-            UsbAccessory accessory, String packageName, PendingIntent pi) {
-        final int userId = UserHandle.getCallingUserId();
-        getSettingsForUser(userId).requestPermission(accessory, packageName, pi);
-    }
-
-    @Override
-    public void grantDevicePermission(UsbDevice device, int uid) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        final int userId = UserHandle.getUserId(uid);
-        getSettingsForUser(userId).grantDevicePermission(device, uid);
-    }
-
-    @Override
-    public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        final int userId = UserHandle.getUserId(uid);
-        getSettingsForUser(userId).grantAccessoryPermission(accessory, uid);
-    }
-
-    @Override
-    public boolean hasDefaults(String packageName, int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        return getSettingsForUser(userId).hasDefaults(packageName);
-    }
-
-    @Override
-    public void clearDefaults(String packageName, int userId) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        getSettingsForUser(userId).clearDefaults(packageName);
-    }
-
-    @Override
-    public void setCurrentFunction(String function, boolean makeDefault) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        if (mDeviceManager != null) {
-            mDeviceManager.setCurrentFunctions(function, makeDefault);
-        } else {
-            throw new IllegalStateException("USB device mode not supported");
-        }
-    }
-
-    @Override
-    public void setMassStorageBackingFile(String path) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        if (mDeviceManager != null) {
-            mDeviceManager.setMassStorageBackingFile(path);
-        } else {
-            throw new IllegalStateException("USB device mode not supported");
-        }
-    }
-
-    @Override
-    public void allowUsbDebugging(boolean alwaysAllow, String publicKey) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.allowUsbDebugging(alwaysAllow, publicKey);
-    }
-
-    @Override
-    public void denyUsbDebugging() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.denyUsbDebugging();
-    }
-
-    @Override
-    public void clearUsbDebuggingKeys() {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.clearUsbDebuggingKeys();
-    }
-
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
-        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
-
-        pw.println("USB Manager State:");
-        if (mDeviceManager != null) {
-            mDeviceManager.dump(fd, pw);
-        }
-        if (mHostManager != null) {
-            mHostManager.dump(fd, pw);
-        }
-
-        synchronized (mLock) {
-            for (int i = 0; i < mSettingsByUser.size(); i++) {
-                final int userId = mSettingsByUser.keyAt(i);
-                final UsbSettingsManager settings = mSettingsByUser.valueAt(i);
-                pw.increaseIndent();
-                pw.println("Settings for user " + userId + ":");
-                settings.dump(fd, pw);
-                pw.decreaseIndent();
-            }
-        }
-        pw.decreaseIndent();
-    }
-}
diff --git a/services/java/com/android/server/usb/UsbSettingsManager.java b/services/java/com/android/server/usb/UsbSettingsManager.java
deleted file mode 100644
index 9b5b312..0000000
--- a/services/java/com/android/server/usb/UsbSettingsManager.java
+++ /dev/null
@@ -1,1100 +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.server.usb;
-
-import android.app.PendingIntent;
-import android.content.ActivityNotFoundException;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
-import android.content.res.XmlResourceParser;
-import android.hardware.usb.UsbAccessory;
-import android.hardware.usb.UsbDevice;
-import android.hardware.usb.UsbInterface;
-import android.hardware.usb.UsbManager;
-import android.os.Binder;
-import android.os.Environment;
-import android.os.Process;
-import android.os.UserHandle;
-import android.util.AtomicFile;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseBooleanArray;
-import android.util.Xml;
-
-import com.android.internal.content.PackageMonitor;
-import com.android.internal.util.FastXmlSerializer;
-import com.android.internal.util.XmlUtils;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import libcore.io.IoUtils;
-
-class UsbSettingsManager {
-    private static final String TAG = "UsbSettingsManager";
-    private static final boolean DEBUG = false;
-
-    /** Legacy settings file, before multi-user */
-    private static final File sSingleUserSettingsFile = new File(
-            "/data/system/usb_device_manager.xml");
-
-    private final UserHandle mUser;
-    private final AtomicFile mSettingsFile;
-
-    private final Context mContext;
-    private final Context mUserContext;
-    private final PackageManager mPackageManager;
-
-    // Temporary mapping USB device name to list of UIDs with permissions for the device
-    private final HashMap<String, SparseBooleanArray> mDevicePermissionMap =
-            new HashMap<String, SparseBooleanArray>();
-    // Temporary mapping UsbAccessory to list of UIDs with permissions for the accessory
-    private final HashMap<UsbAccessory, SparseBooleanArray> mAccessoryPermissionMap =
-            new HashMap<UsbAccessory, SparseBooleanArray>();
-    // Maps DeviceFilter to user preferred application package
-    private final HashMap<DeviceFilter, String> mDevicePreferenceMap =
-            new HashMap<DeviceFilter, String>();
-    // Maps AccessoryFilter to user preferred application package
-    private final HashMap<AccessoryFilter, String> mAccessoryPreferenceMap =
-            new HashMap<AccessoryFilter, String>();
-
-    private final Object mLock = new Object();
-
-    // This class is used to describe a USB device.
-    // When used in HashMaps all values must be specified,
-    // but wildcards can be used for any of the fields in
-    // the package meta-data.
-    private static class DeviceFilter {
-        // USB Vendor ID (or -1 for unspecified)
-        public final int mVendorId;
-        // USB Product ID (or -1 for unspecified)
-        public final int mProductId;
-        // USB device or interface class (or -1 for unspecified)
-        public final int mClass;
-        // USB device subclass (or -1 for unspecified)
-        public final int mSubclass;
-        // USB device protocol (or -1 for unspecified)
-        public final int mProtocol;
-
-        public DeviceFilter(int vid, int pid, int clasz, int subclass, int protocol) {
-            mVendorId = vid;
-            mProductId = pid;
-            mClass = clasz;
-            mSubclass = subclass;
-            mProtocol = protocol;
-        }
-
-        public DeviceFilter(UsbDevice device) {
-            mVendorId = device.getVendorId();
-            mProductId = device.getProductId();
-            mClass = device.getDeviceClass();
-            mSubclass = device.getDeviceSubclass();
-            mProtocol = device.getDeviceProtocol();
-        }
-
-        public static DeviceFilter read(XmlPullParser parser)
-                throws XmlPullParserException, IOException {
-            int vendorId = -1;
-            int productId = -1;
-            int deviceClass = -1;
-            int deviceSubclass = -1;
-            int deviceProtocol = -1;
-
-            int count = parser.getAttributeCount();
-            for (int i = 0; i < count; i++) {
-                String name = parser.getAttributeName(i);
-                // All attribute values are ints
-                int value = Integer.parseInt(parser.getAttributeValue(i));
-
-                if ("vendor-id".equals(name)) {
-                    vendorId = value;
-                } else if ("product-id".equals(name)) {
-                    productId = value;
-                } else if ("class".equals(name)) {
-                    deviceClass = value;
-                } else if ("subclass".equals(name)) {
-                    deviceSubclass = value;
-                } else if ("protocol".equals(name)) {
-                    deviceProtocol = value;
-                }
-            }
-            return new DeviceFilter(vendorId, productId,
-                    deviceClass, deviceSubclass, deviceProtocol);
-        }
-
-        public void write(XmlSerializer serializer) throws IOException {
-            serializer.startTag(null, "usb-device");
-            if (mVendorId != -1) {
-                serializer.attribute(null, "vendor-id", Integer.toString(mVendorId));
-            }
-            if (mProductId != -1) {
-                serializer.attribute(null, "product-id", Integer.toString(mProductId));
-            }
-            if (mClass != -1) {
-                serializer.attribute(null, "class", Integer.toString(mClass));
-            }
-            if (mSubclass != -1) {
-                serializer.attribute(null, "subclass", Integer.toString(mSubclass));
-            }
-            if (mProtocol != -1) {
-                serializer.attribute(null, "protocol", Integer.toString(mProtocol));
-            }
-            serializer.endTag(null, "usb-device");
-        }
-
-        private boolean matches(int clasz, int subclass, int protocol) {
-            return ((mClass == -1 || clasz == mClass) &&
-                    (mSubclass == -1 || subclass == mSubclass) &&
-                    (mProtocol == -1 || protocol == mProtocol));
-        }
-
-        public boolean matches(UsbDevice device) {
-            if (mVendorId != -1 && device.getVendorId() != mVendorId) return false;
-            if (mProductId != -1 && device.getProductId() != mProductId) return false;
-
-            // check device class/subclass/protocol
-            if (matches(device.getDeviceClass(), device.getDeviceSubclass(),
-                    device.getDeviceProtocol())) return true;
-
-            // if device doesn't match, check the interfaces
-            int count = device.getInterfaceCount();
-            for (int i = 0; i < count; i++) {
-                UsbInterface intf = device.getInterface(i);
-                 if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(),
-                        intf.getInterfaceProtocol())) return true;
-            }
-
-            return false;
-        }
-
-        public boolean matches(DeviceFilter f) {
-            if (mVendorId != -1 && f.mVendorId != mVendorId) return false;
-            if (mProductId != -1 && f.mProductId != mProductId) return false;
-
-            // check device class/subclass/protocol
-            return matches(f.mClass, f.mSubclass, f.mProtocol);
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            // can't compare if we have wildcard strings
-            if (mVendorId == -1 || mProductId == -1 ||
-                    mClass == -1 || mSubclass == -1 || mProtocol == -1) {
-                return false;
-            }
-            if (obj instanceof DeviceFilter) {
-                DeviceFilter filter = (DeviceFilter)obj;
-                return (filter.mVendorId == mVendorId &&
-                        filter.mProductId == mProductId &&
-                        filter.mClass == mClass &&
-                        filter.mSubclass == mSubclass &&
-                        filter.mProtocol == mProtocol);
-            }
-            if (obj instanceof UsbDevice) {
-                UsbDevice device = (UsbDevice)obj;
-                return (device.getVendorId() == mVendorId &&
-                        device.getProductId() == mProductId &&
-                        device.getDeviceClass() == mClass &&
-                        device.getDeviceSubclass() == mSubclass &&
-                        device.getDeviceProtocol() == mProtocol);
-            }
-            return false;
-        }
-
-        @Override
-        public int hashCode() {
-            return (((mVendorId << 16) | mProductId) ^
-                    ((mClass << 16) | (mSubclass << 8) | mProtocol));
-        }
-
-        @Override
-        public String toString() {
-            return "DeviceFilter[mVendorId=" + mVendorId + ",mProductId=" + mProductId +
-                    ",mClass=" + mClass + ",mSubclass=" + mSubclass +
-                    ",mProtocol=" + mProtocol + "]";
-        }
-    }
-
-    // This class is used to describe a USB accessory.
-    // When used in HashMaps all values must be specified,
-    // but wildcards can be used for any of the fields in
-    // the package meta-data.
-    private static class AccessoryFilter {
-        // USB accessory manufacturer (or null for unspecified)
-        public final String mManufacturer;
-        // USB accessory model (or null for unspecified)
-        public final String mModel;
-        // USB accessory version (or null for unspecified)
-        public final String mVersion;
-
-        public AccessoryFilter(String manufacturer, String model, String version) {
-            mManufacturer = manufacturer;
-            mModel = model;
-            mVersion = version;
-        }
-
-        public AccessoryFilter(UsbAccessory accessory) {
-            mManufacturer = accessory.getManufacturer();
-            mModel = accessory.getModel();
-            mVersion = accessory.getVersion();
-        }
-
-        public static AccessoryFilter read(XmlPullParser parser)
-                throws XmlPullParserException, IOException {
-            String manufacturer = null;
-            String model = null;
-            String version = null;
-
-            int count = parser.getAttributeCount();
-            for (int i = 0; i < count; i++) {
-                String name = parser.getAttributeName(i);
-                String value = parser.getAttributeValue(i);
-
-                if ("manufacturer".equals(name)) {
-                    manufacturer = value;
-                } else if ("model".equals(name)) {
-                    model = value;
-                } else if ("version".equals(name)) {
-                    version = value;
-                }
-             }
-             return new AccessoryFilter(manufacturer, model, version);
-        }
-
-        public void write(XmlSerializer serializer)throws IOException {
-            serializer.startTag(null, "usb-accessory");
-            if (mManufacturer != null) {
-                serializer.attribute(null, "manufacturer", mManufacturer);
-            }
-            if (mModel != null) {
-                serializer.attribute(null, "model", mModel);
-            }
-            if (mVersion != null) {
-                serializer.attribute(null, "version", mVersion);
-            }
-            serializer.endTag(null, "usb-accessory");
-        }
-
-        public boolean matches(UsbAccessory acc) {
-            if (mManufacturer != null && !acc.getManufacturer().equals(mManufacturer)) return false;
-            if (mModel != null && !acc.getModel().equals(mModel)) return false;
-            if (mVersion != null && !acc.getVersion().equals(mVersion)) return false;
-            return true;
-        }
-
-        public boolean matches(AccessoryFilter f) {
-            if (mManufacturer != null && !f.mManufacturer.equals(mManufacturer)) return false;
-            if (mModel != null && !f.mModel.equals(mModel)) return false;
-            if (mVersion != null && !f.mVersion.equals(mVersion)) return false;
-            return true;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            // can't compare if we have wildcard strings
-            if (mManufacturer == null || mModel == null || mVersion == null) {
-                return false;
-            }
-            if (obj instanceof AccessoryFilter) {
-                AccessoryFilter filter = (AccessoryFilter)obj;
-                return (mManufacturer.equals(filter.mManufacturer) &&
-                        mModel.equals(filter.mModel) &&
-                        mVersion.equals(filter.mVersion));
-            }
-            if (obj instanceof UsbAccessory) {
-                UsbAccessory accessory = (UsbAccessory)obj;
-                return (mManufacturer.equals(accessory.getManufacturer()) &&
-                        mModel.equals(accessory.getModel()) &&
-                        mVersion.equals(accessory.getVersion()));
-            }
-            return false;
-        }
-
-        @Override
-        public int hashCode() {
-            return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^
-                    (mModel == null ? 0 : mModel.hashCode()) ^
-                    (mVersion == null ? 0 : mVersion.hashCode()));
-        }
-
-        @Override
-        public String toString() {
-            return "AccessoryFilter[mManufacturer=\"" + mManufacturer +
-                                "\", mModel=\"" + mModel +
-                                "\", mVersion=\"" + mVersion + "\"]";
-        }
-    }
-
-    private class MyPackageMonitor extends PackageMonitor {
-        @Override
-        public void onPackageAdded(String packageName, int uid) {
-            handlePackageUpdate(packageName);
-        }
-
-        @Override
-        public boolean onPackageChanged(String packageName, int uid, String[] components) {
-            handlePackageUpdate(packageName);
-            return false;
-        }
-
-        @Override
-        public void onPackageRemoved(String packageName, int uid) {
-            clearDefaults(packageName);
-        }
-    }
-
-    MyPackageMonitor mPackageMonitor = new MyPackageMonitor();
-
-    public UsbSettingsManager(Context context, UserHandle user) {
-        if (DEBUG) Slog.v(TAG, "Creating settings for " + user);
-
-        try {
-            mUserContext = context.createPackageContextAsUser("android", 0, user);
-        } catch (NameNotFoundException e) {
-            throw new RuntimeException("Missing android package");
-        }
-
-        mContext = context;
-        mPackageManager = mUserContext.getPackageManager();
-
-        mUser = user;
-        mSettingsFile = new AtomicFile(new File(
-                Environment.getUserSystemDirectory(user.getIdentifier()),
-                "usb_device_manager.xml"));
-
-        synchronized (mLock) {
-            if (UserHandle.OWNER.equals(user)) {
-                upgradeSingleUserLocked();
-            }
-            readSettingsLocked();
-        }
-
-        mPackageMonitor.register(mUserContext, null, true);
-    }
-
-    private void readPreference(XmlPullParser parser)
-            throws XmlPullParserException, IOException {
-        String packageName = null;
-        int count = parser.getAttributeCount();
-        for (int i = 0; i < count; i++) {
-            if ("package".equals(parser.getAttributeName(i))) {
-                packageName = parser.getAttributeValue(i);
-                break;
-            }
-        }
-        XmlUtils.nextElement(parser);
-        if ("usb-device".equals(parser.getName())) {
-            DeviceFilter filter = DeviceFilter.read(parser);
-            mDevicePreferenceMap.put(filter, packageName);
-        } else if ("usb-accessory".equals(parser.getName())) {
-            AccessoryFilter filter = AccessoryFilter.read(parser);
-            mAccessoryPreferenceMap.put(filter, packageName);
-        }
-        XmlUtils.nextElement(parser);
-    }
-
-    /**
-     * Upgrade any single-user settings from {@link #sSingleUserSettingsFile}.
-     * Should only by called by owner.
-     */
-    private void upgradeSingleUserLocked() {
-        if (sSingleUserSettingsFile.exists()) {
-            mDevicePreferenceMap.clear();
-            mAccessoryPreferenceMap.clear();
-
-            FileInputStream fis = null;
-            try {
-                fis = new FileInputStream(sSingleUserSettingsFile);
-                XmlPullParser parser = Xml.newPullParser();
-                parser.setInput(fis, null);
-
-                XmlUtils.nextElement(parser);
-                while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                    final String tagName = parser.getName();
-                    if ("preference".equals(tagName)) {
-                        readPreference(parser);
-                    } else {
-                        XmlUtils.nextElement(parser);
-                    }
-                }
-            } catch (IOException e) {
-                Log.wtf(TAG, "Failed to read single-user settings", e);
-            } catch (XmlPullParserException e) {
-                Log.wtf(TAG, "Failed to read single-user settings", e);
-            } finally {
-                IoUtils.closeQuietly(fis);
-            }
-
-            writeSettingsLocked();
-
-            // Success or failure, we delete single-user file
-            sSingleUserSettingsFile.delete();
-        }
-    }
-
-    private void readSettingsLocked() {
-        if (DEBUG) Slog.v(TAG, "readSettingsLocked()");
-
-        mDevicePreferenceMap.clear();
-        mAccessoryPreferenceMap.clear();
-
-        FileInputStream stream = null;
-        try {
-            stream = mSettingsFile.openRead();
-            XmlPullParser parser = Xml.newPullParser();
-            parser.setInput(stream, null);
-
-            XmlUtils.nextElement(parser);
-            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                String tagName = parser.getName();
-                if ("preference".equals(tagName)) {
-                    readPreference(parser);
-                } else {
-                    XmlUtils.nextElement(parser);
-                }
-            }
-        } catch (FileNotFoundException e) {
-            if (DEBUG) Slog.d(TAG, "settings file not found");
-        } catch (Exception e) {
-            Slog.e(TAG, "error reading settings file, deleting to start fresh", e);
-            mSettingsFile.delete();
-        } finally {
-            IoUtils.closeQuietly(stream);
-        }
-    }
-
-    private void writeSettingsLocked() {
-        if (DEBUG) Slog.v(TAG, "writeSettingsLocked()");
-
-        FileOutputStream fos = null;
-        try {
-            fos = mSettingsFile.startWrite();
-
-            FastXmlSerializer serializer = new FastXmlSerializer();
-            serializer.setOutput(fos, "utf-8");
-            serializer.startDocument(null, true);
-            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-            serializer.startTag(null, "settings");
-
-            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
-                serializer.startTag(null, "preference");
-                serializer.attribute(null, "package", mDevicePreferenceMap.get(filter));
-                filter.write(serializer);
-                serializer.endTag(null, "preference");
-            }
-
-            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
-                serializer.startTag(null, "preference");
-                serializer.attribute(null, "package", mAccessoryPreferenceMap.get(filter));
-                filter.write(serializer);
-                serializer.endTag(null, "preference");
-            }
-
-            serializer.endTag(null, "settings");
-            serializer.endDocument();
-
-            mSettingsFile.finishWrite(fos);
-        } catch (IOException e) {
-            Slog.e(TAG, "Failed to write settings", e);
-            if (fos != null) {
-                mSettingsFile.failWrite(fos);
-            }
-        }
-    }
-
-    // Checks to see if a package matches a device or accessory.
-    // Only one of device and accessory should be non-null.
-    private boolean packageMatchesLocked(ResolveInfo info, String metaDataName,
-            UsbDevice device, UsbAccessory accessory) {
-        ActivityInfo ai = info.activityInfo;
-
-        XmlResourceParser parser = null;
-        try {
-            parser = ai.loadXmlMetaData(mPackageManager, metaDataName);
-            if (parser == null) {
-                Slog.w(TAG, "no meta-data for " + info);
-                return false;
-            }
-
-            XmlUtils.nextElement(parser);
-            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                String tagName = parser.getName();
-                if (device != null && "usb-device".equals(tagName)) {
-                    DeviceFilter filter = DeviceFilter.read(parser);
-                    if (filter.matches(device)) {
-                        return true;
-                    }
-                }
-                else if (accessory != null && "usb-accessory".equals(tagName)) {
-                    AccessoryFilter filter = AccessoryFilter.read(parser);
-                    if (filter.matches(accessory)) {
-                        return true;
-                    }
-                }
-                XmlUtils.nextElement(parser);
-            }
-        } catch (Exception e) {
-            Slog.w(TAG, "Unable to load component info " + info.toString(), e);
-        } finally {
-            if (parser != null) parser.close();
-        }
-        return false;
-    }
-
-    private final ArrayList<ResolveInfo> getDeviceMatchesLocked(UsbDevice device, Intent intent) {
-        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
-        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
-                PackageManager.GET_META_DATA);
-        int count = resolveInfos.size();
-        for (int i = 0; i < count; i++) {
-            ResolveInfo resolveInfo = resolveInfos.get(i);
-            if (packageMatchesLocked(resolveInfo, intent.getAction(), device, null)) {
-                matches.add(resolveInfo);
-            }
-        }
-        return matches;
-    }
-
-    private final ArrayList<ResolveInfo> getAccessoryMatchesLocked(
-            UsbAccessory accessory, Intent intent) {
-        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
-        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
-                PackageManager.GET_META_DATA);
-        int count = resolveInfos.size();
-        for (int i = 0; i < count; i++) {
-            ResolveInfo resolveInfo = resolveInfos.get(i);
-            if (packageMatchesLocked(resolveInfo, intent.getAction(), null, accessory)) {
-                matches.add(resolveInfo);
-            }
-        }
-        return matches;
-    }
-
-    public void deviceAttached(UsbDevice device) {
-        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
-        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        ArrayList<ResolveInfo> matches;
-        String defaultPackage;
-        synchronized (mLock) {
-            matches = getDeviceMatchesLocked(device, intent);
-            // Launch our default activity directly, if we have one.
-            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
-            defaultPackage = mDevicePreferenceMap.get(new DeviceFilter(device));
-        }
-
-        // Send broadcast to running activity with registered intent
-        mUserContext.sendBroadcast(intent);
-
-        // Start activity with registered intent
-        resolveActivity(intent, matches, defaultPackage, device, null);
-    }
-
-    public void deviceDetached(UsbDevice device) {
-        // clear temporary permissions for the device
-        mDevicePermissionMap.remove(device.getDeviceName());
-
-        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED);
-        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-        if (DEBUG) Slog.d(TAG, "usbDeviceRemoved, sending " + intent);
-        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
-    }
-
-    public void accessoryAttached(UsbAccessory accessory) {
-        Intent intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
-        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-        ArrayList<ResolveInfo> matches;
-        String defaultPackage;
-        synchronized (mLock) {
-            matches = getAccessoryMatchesLocked(accessory, intent);
-            // Launch our default activity directly, if we have one.
-            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
-            defaultPackage = mAccessoryPreferenceMap.get(new AccessoryFilter(accessory));
-        }
-
-        resolveActivity(intent, matches, defaultPackage, null, accessory);
-    }
-
-    public void accessoryDetached(UsbAccessory accessory) {
-        // clear temporary permissions for the accessory
-        mAccessoryPermissionMap.remove(accessory);
-
-        Intent intent = new Intent(
-                UsbManager.ACTION_USB_ACCESSORY_DETACHED);
-        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
-    }
-
-    private void resolveActivity(Intent intent, ArrayList<ResolveInfo> matches,
-            String defaultPackage, UsbDevice device, UsbAccessory accessory) {
-        int count = matches.size();
-
-        // don't show the resolver activity if there are no choices available
-        if (count == 0) {
-            if (accessory != null) {
-                String uri = accessory.getUri();
-                if (uri != null && uri.length() > 0) {
-                    // display URI to user
-                    // start UsbResolverActivity so user can choose an activity
-                    Intent dialogIntent = new Intent();
-                    dialogIntent.setClassName("com.android.systemui",
-                            "com.android.systemui.usb.UsbAccessoryUriActivity");
-                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-                    dialogIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-                    dialogIntent.putExtra("uri", uri);
-                    try {
-                        mUserContext.startActivityAsUser(dialogIntent, mUser);
-                    } catch (ActivityNotFoundException e) {
-                        Slog.e(TAG, "unable to start UsbAccessoryUriActivity");
-                    }
-                }
-            }
-
-            // do nothing
-            return;
-        }
-
-        ResolveInfo defaultRI = null;
-        if (count == 1 && defaultPackage == null) {
-            // Check to see if our single choice is on the system partition.
-            // If so, treat it as our default without calling UsbResolverActivity
-            ResolveInfo rInfo = matches.get(0);
-            if (rInfo.activityInfo != null &&
-                    rInfo.activityInfo.applicationInfo != null &&
-                    (rInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
-                defaultRI = rInfo;
-            }
-        }
-
-        if (defaultRI == null && defaultPackage != null) {
-            // look for default activity
-            for (int i = 0; i < count; i++) {
-                ResolveInfo rInfo = matches.get(i);
-                if (rInfo.activityInfo != null &&
-                        defaultPackage.equals(rInfo.activityInfo.packageName)) {
-                    defaultRI = rInfo;
-                    break;
-                }
-            }
-        }
-
-        if (defaultRI != null) {
-            // grant permission for default activity
-            if (device != null) {
-                grantDevicePermission(device, defaultRI.activityInfo.applicationInfo.uid);
-            } else if (accessory != null) {
-                grantAccessoryPermission(accessory, defaultRI.activityInfo.applicationInfo.uid);
-            }
-
-            // start default activity directly
-            try {
-                intent.setComponent(
-                        new ComponentName(defaultRI.activityInfo.packageName,
-                                defaultRI.activityInfo.name));
-                mUserContext.startActivityAsUser(intent, mUser);
-            } catch (ActivityNotFoundException e) {
-                Slog.e(TAG, "startActivity failed", e);
-            }
-        } else {
-            Intent resolverIntent = new Intent();
-            resolverIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-            if (count == 1) {
-                // start UsbConfirmActivity if there is only one choice
-                resolverIntent.setClassName("com.android.systemui",
-                        "com.android.systemui.usb.UsbConfirmActivity");
-                resolverIntent.putExtra("rinfo", matches.get(0));
-
-                if (device != null) {
-                    resolverIntent.putExtra(UsbManager.EXTRA_DEVICE, device);
-                } else {
-                    resolverIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-                }
-            } else {
-                // start UsbResolverActivity so user can choose an activity
-                resolverIntent.setClassName("com.android.systemui",
-                        "com.android.systemui.usb.UsbResolverActivity");
-                resolverIntent.putParcelableArrayListExtra("rlist", matches);
-                resolverIntent.putExtra(Intent.EXTRA_INTENT, intent);
-            }
-            try {
-                mUserContext.startActivityAsUser(resolverIntent, mUser);
-            } catch (ActivityNotFoundException e) {
-                Slog.e(TAG, "unable to start activity " + resolverIntent);
-            }
-        }
-    }
-
-    private boolean clearCompatibleMatchesLocked(String packageName, DeviceFilter filter) {
-        boolean changed = false;
-        for (DeviceFilter test : mDevicePreferenceMap.keySet()) {
-            if (filter.matches(test)) {
-                mDevicePreferenceMap.remove(test);
-                changed = true;
-            }
-        }
-        return changed;
-    }
-
-    private boolean clearCompatibleMatchesLocked(String packageName, AccessoryFilter filter) {
-        boolean changed = false;
-        for (AccessoryFilter test : mAccessoryPreferenceMap.keySet()) {
-            if (filter.matches(test)) {
-                mAccessoryPreferenceMap.remove(test);
-                changed = true;
-            }
-        }
-        return changed;
-    }
-
-    private boolean handlePackageUpdateLocked(String packageName, ActivityInfo aInfo,
-            String metaDataName) {
-        XmlResourceParser parser = null;
-        boolean changed = false;
-
-        try {
-            parser = aInfo.loadXmlMetaData(mPackageManager, metaDataName);
-            if (parser == null) return false;
-
-            XmlUtils.nextElement(parser);
-            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
-                String tagName = parser.getName();
-                if ("usb-device".equals(tagName)) {
-                    DeviceFilter filter = DeviceFilter.read(parser);
-                    if (clearCompatibleMatchesLocked(packageName, filter)) {
-                        changed = true;
-                    }
-                }
-                else if ("usb-accessory".equals(tagName)) {
-                    AccessoryFilter filter = AccessoryFilter.read(parser);
-                    if (clearCompatibleMatchesLocked(packageName, filter)) {
-                        changed = true;
-                    }
-                }
-                XmlUtils.nextElement(parser);
-            }
-        } catch (Exception e) {
-            Slog.w(TAG, "Unable to load component info " + aInfo.toString(), e);
-        } finally {
-            if (parser != null) parser.close();
-        }
-        return changed;
-    }
-
-    // Check to see if the package supports any USB devices or accessories.
-    // If so, clear any non-matching preferences for matching devices/accessories.
-    private void handlePackageUpdate(String packageName) {
-        synchronized (mLock) {
-            PackageInfo info;
-            boolean changed = false;
-
-            try {
-                info = mPackageManager.getPackageInfo(packageName,
-                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
-            } catch (NameNotFoundException e) {
-                Slog.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
-                return;
-            }
-
-            ActivityInfo[] activities = info.activities;
-            if (activities == null) return;
-            for (int i = 0; i < activities.length; i++) {
-                // check for meta-data, both for devices and accessories
-                if (handlePackageUpdateLocked(packageName, activities[i],
-                        UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
-                    changed = true;
-                }
-                if (handlePackageUpdateLocked(packageName, activities[i],
-                        UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
-                    changed = true;
-                }
-            }
-
-            if (changed) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    public boolean hasPermission(UsbDevice device) {
-        synchronized (mLock) {
-            int uid = Binder.getCallingUid();
-            if (uid == Process.SYSTEM_UID) {
-                return true;
-            }
-            SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName());
-            if (uidList == null) {
-                return false;
-            }
-            return uidList.get(uid);
-        }
-    }
-
-    public boolean hasPermission(UsbAccessory accessory) {
-        synchronized (mLock) {
-            int uid = Binder.getCallingUid();
-            if (uid == Process.SYSTEM_UID) {
-                return true;
-            }
-            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
-            if (uidList == null) {
-                return false;
-            }
-            return uidList.get(uid);
-        }
-    }
-
-    public void checkPermission(UsbDevice device) {
-        if (!hasPermission(device)) {
-            throw new SecurityException("User has not given permission to device " + device);
-        }
-    }
-
-    public void checkPermission(UsbAccessory accessory) {
-        if (!hasPermission(accessory)) {
-            throw new SecurityException("User has not given permission to accessory " + accessory);
-        }
-    }
-
-    private void requestPermissionDialog(Intent intent, String packageName, PendingIntent pi) {
-        final int uid = Binder.getCallingUid();
-
-        // compare uid with packageName to foil apps pretending to be someone else
-        try {
-            ApplicationInfo aInfo = mPackageManager.getApplicationInfo(packageName, 0);
-            if (aInfo.uid != uid) {
-                throw new IllegalArgumentException("package " + packageName +
-                        " does not match caller's uid " + uid);
-            }
-        } catch (PackageManager.NameNotFoundException e) {
-            throw new IllegalArgumentException("package " + packageName + " not found");
-        }
-
-        long identity = Binder.clearCallingIdentity();
-        intent.setClassName("com.android.systemui",
-                "com.android.systemui.usb.UsbPermissionActivity");
-        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-        intent.putExtra(Intent.EXTRA_INTENT, pi);
-        intent.putExtra("package", packageName);
-        intent.putExtra(Intent.EXTRA_UID, uid);
-        try {
-            mUserContext.startActivityAsUser(intent, mUser);
-        } catch (ActivityNotFoundException e) {
-            Slog.e(TAG, "unable to start UsbPermissionActivity");
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
-    }
-
-    public void requestPermission(UsbDevice device, String packageName, PendingIntent pi) {
-      Intent intent = new Intent();
-
-        // respond immediately if permission has already been granted
-      if (hasPermission(device)) {
-            intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
-            try {
-                pi.send(mUserContext, 0, intent);
-            } catch (PendingIntent.CanceledException e) {
-                if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled");
-            }
-            return;
-        }
-
-        // start UsbPermissionActivity so user can choose an activity
-        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
-        requestPermissionDialog(intent, packageName, pi);
-    }
-
-    public void requestPermission(UsbAccessory accessory, String packageName, PendingIntent pi) {
-        Intent intent = new Intent();
-
-        // respond immediately if permission has already been granted
-        if (hasPermission(accessory)) {
-            intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
-            try {
-                pi.send(mUserContext, 0, intent);
-            } catch (PendingIntent.CanceledException e) {
-                if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled");
-            }
-            return;
-        }
-
-        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
-        requestPermissionDialog(intent, packageName, pi);
-    }
-
-    public void setDevicePackage(UsbDevice device, String packageName) {
-        DeviceFilter filter = new DeviceFilter(device);
-        boolean changed = false;
-        synchronized (mLock) {
-            if (packageName == null) {
-                changed = (mDevicePreferenceMap.remove(filter) != null);
-            } else {
-                changed = !packageName.equals(mDevicePreferenceMap.get(filter));
-                if (changed) {
-                    mDevicePreferenceMap.put(filter, packageName);
-                }
-            }
-            if (changed) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    public void setAccessoryPackage(UsbAccessory accessory, String packageName) {
-        AccessoryFilter filter = new AccessoryFilter(accessory);
-        boolean changed = false;
-        synchronized (mLock) {
-            if (packageName == null) {
-                changed = (mAccessoryPreferenceMap.remove(filter) != null);
-            } else {
-                changed = !packageName.equals(mAccessoryPreferenceMap.get(filter));
-                if (changed) {
-                    mAccessoryPreferenceMap.put(filter, packageName);
-                }
-            }
-            if (changed) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    public void grantDevicePermission(UsbDevice device, int uid) {
-        synchronized (mLock) {
-            String deviceName = device.getDeviceName();
-            SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
-            if (uidList == null) {
-                uidList = new SparseBooleanArray(1);
-                mDevicePermissionMap.put(deviceName, uidList);
-            }
-            uidList.put(uid, true);
-        }
-    }
-
-    public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
-        synchronized (mLock) {
-            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
-            if (uidList == null) {
-                uidList = new SparseBooleanArray(1);
-                mAccessoryPermissionMap.put(accessory, uidList);
-            }
-            uidList.put(uid, true);
-        }
-    }
-
-    public boolean hasDefaults(String packageName) {
-        synchronized (mLock) {
-            if (mDevicePreferenceMap.values().contains(packageName)) return true;
-            if (mAccessoryPreferenceMap.values().contains(packageName)) return true;
-            return false;
-        }
-    }
-
-    public void clearDefaults(String packageName) {
-        synchronized (mLock) {
-            if (clearPackageDefaultsLocked(packageName)) {
-                writeSettingsLocked();
-            }
-        }
-    }
-
-    private boolean clearPackageDefaultsLocked(String packageName) {
-        boolean cleared = false;
-        synchronized (mLock) {
-            if (mDevicePreferenceMap.containsValue(packageName)) {
-                // make a copy of the key set to avoid ConcurrentModificationException
-                Object[] keys = mDevicePreferenceMap.keySet().toArray();
-                for (int i = 0; i < keys.length; i++) {
-                    Object key = keys[i];
-                    if (packageName.equals(mDevicePreferenceMap.get(key))) {
-                        mDevicePreferenceMap.remove(key);
-                        cleared = true;
-                    }
-                }
-            }
-            if (mAccessoryPreferenceMap.containsValue(packageName)) {
-                // make a copy of the key set to avoid ConcurrentModificationException
-                Object[] keys = mAccessoryPreferenceMap.keySet().toArray();
-                for (int i = 0; i < keys.length; i++) {
-                    Object key = keys[i];
-                    if (packageName.equals(mAccessoryPreferenceMap.get(key))) {
-                        mAccessoryPreferenceMap.remove(key);
-                        cleared = true;
-                    }
-                }
-            }
-            return cleared;
-        }
-    }
-
-    public void dump(FileDescriptor fd, PrintWriter pw) {
-        synchronized (mLock) {
-            pw.println("  Device permissions:");
-            for (String deviceName : mDevicePermissionMap.keySet()) {
-                pw.print("    " + deviceName + ": ");
-                SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
-                int count = uidList.size();
-                for (int i = 0; i < count; i++) {
-                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
-                }
-                pw.println("");
-            }
-            pw.println("  Accessory permissions:");
-            for (UsbAccessory accessory : mAccessoryPermissionMap.keySet()) {
-                pw.print("    " + accessory + ": ");
-                SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
-                int count = uidList.size();
-                for (int i = 0; i < count; i++) {
-                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
-                }
-                pw.println("");
-            }
-            pw.println("  Device preferences:");
-            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
-                pw.println("    " + filter + ": " + mDevicePreferenceMap.get(filter));
-            }
-            pw.println("  Accessory preferences:");
-            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
-                pw.println("    " + filter + ": " + mAccessoryPreferenceMap.get(filter));
-            }
-        }
-    }
-}
diff --git a/services/java/com/android/server/wm/AppWindowAnimator.java b/services/java/com/android/server/wm/AppWindowAnimator.java
deleted file mode 100644
index 3cccf1d..0000000
--- a/services/java/com/android/server/wm/AppWindowAnimator.java
+++ /dev/null
@@ -1,334 +0,0 @@
-// Copyright 2012 Google Inc. All Rights Reserved.
-
-package com.android.server.wm;
-
-import android.graphics.Matrix;
-import android.util.Slog;
-import android.util.TimeUtils;
-import android.view.Display;
-import android.view.SurfaceControl;
-import android.view.WindowManagerPolicy;
-import android.view.animation.Animation;
-import android.view.animation.Transformation;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-public class AppWindowAnimator {
-    static final String TAG = "AppWindowAnimator";
-
-    final AppWindowToken mAppToken;
-    final WindowManagerService mService;
-    final WindowAnimator mAnimator;
-
-    boolean animating;
-    Animation animation;
-    boolean hasTransformation;
-    final Transformation transformation = new Transformation();
-
-    // Have we been asked to have this token keep the screen frozen?
-    // Protect with mAnimator.
-    boolean freezingScreen;
-
-    /**
-     * How long we last kept the screen frozen.
-     */
-    int lastFreezeDuration;
-
-    // Offset to the window of all layers in the token, for use by
-    // AppWindowToken animations.
-    int animLayerAdjustment;
-
-    // Propagated from AppWindowToken.allDrawn, to determine when
-    // the state changes.
-    boolean allDrawn;
-
-    // Special surface for thumbnail animation.
-    SurfaceControl thumbnail;
-    int thumbnailTransactionSeq;
-    int thumbnailX;
-    int thumbnailY;
-    int thumbnailLayer;
-    Animation thumbnailAnimation;
-    final Transformation thumbnailTransformation = new Transformation();
-
-    /** WindowStateAnimator from mAppAnimator.allAppWindows as of last performLayout */
-    ArrayList<WindowStateAnimator> mAllAppWinAnimators = new ArrayList<WindowStateAnimator>();
-
-    static final Animation sDummyAnimation = new DummyAnimation();
-
-    public AppWindowAnimator(final AppWindowToken atoken) {
-        mAppToken = atoken;
-        mService = atoken.service;
-        mAnimator = atoken.mAnimator;
-    }
-
-    public void setAnimation(Animation anim, int width, int height) {
-        if (WindowManagerService.localLOGV) Slog.v(TAG, "Setting animation in " + mAppToken
-                + ": " + anim + " wxh=" + width + "x" + height
-                + " isVisible=" + mAppToken.isVisible());
-        animation = anim;
-        animating = false;
-        if (!anim.isInitialized()) {
-            anim.initialize(width, height, width, height);
-        }
-        anim.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
-        anim.scaleCurrentDuration(mService.mTransitionAnimationScale);
-        int zorder = anim.getZAdjustment();
-        int adj = 0;
-        if (zorder == Animation.ZORDER_TOP) {
-            adj = WindowManagerService.TYPE_LAYER_OFFSET;
-        } else if (zorder == Animation.ZORDER_BOTTOM) {
-            adj = -WindowManagerService.TYPE_LAYER_OFFSET;
-        }
-
-        if (animLayerAdjustment != adj) {
-            animLayerAdjustment = adj;
-            updateLayers();
-        }
-        // Start out animation gone if window is gone, or visible if window is visible.
-        transformation.clear();
-        transformation.setAlpha(mAppToken.isVisible() ? 1 : 0);
-        hasTransformation = true;
-    }
-
-    public void setDummyAnimation() {
-        if (WindowManagerService.localLOGV) Slog.v(TAG, "Setting dummy animation in " + mAppToken
-                + " isVisible=" + mAppToken.isVisible());
-        animation = sDummyAnimation;
-        hasTransformation = true;
-        transformation.clear();
-        transformation.setAlpha(mAppToken.isVisible() ? 1 : 0);
-    }
-
-    public void clearAnimation() {
-        if (animation != null) {
-            animation = null;
-            animating = true;
-        }
-        clearThumbnail();
-        if (mAppToken.deferClearAllDrawn) {
-            mAppToken.allDrawn = false;
-            mAppToken.deferClearAllDrawn = false;
-        }
-    }
-
-    public void clearThumbnail() {
-        if (thumbnail != null) {
-            thumbnail.destroy();
-            thumbnail = null;
-        }
-    }
-
-    void updateLayers() {
-        final int N = mAppToken.allAppWindows.size();
-        final int adj = animLayerAdjustment;
-        thumbnailLayer = -1;
-        for (int i=0; i<N; i++) {
-            final WindowState w = mAppToken.allAppWindows.get(i);
-            final WindowStateAnimator winAnimator = w.mWinAnimator;
-            winAnimator.mAnimLayer = w.mLayer + adj;
-            if (winAnimator.mAnimLayer > thumbnailLayer) {
-                thumbnailLayer = winAnimator.mAnimLayer;
-            }
-            if (WindowManagerService.DEBUG_LAYERS) Slog.v(TAG, "Updating layer " + w + ": "
-                    + winAnimator.mAnimLayer);
-            if (w == mService.mInputMethodTarget && !mService.mInputMethodTargetWaitingAnim) {
-                mService.setInputMethodAnimLayerAdjustment(adj);
-            }
-            if (w == mService.mWallpaperTarget && mService.mLowerWallpaperTarget == null) {
-                mService.setWallpaperAnimLayerAdjustmentLocked(adj);
-            }
-        }
-    }
-
-    private void stepThumbnailAnimation(long currentTime) {
-        thumbnailTransformation.clear();
-        thumbnailAnimation.getTransformation(currentTime, thumbnailTransformation);
-        thumbnailTransformation.getMatrix().preTranslate(thumbnailX, thumbnailY);
-
-        ScreenRotationAnimation screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
-        final boolean screenAnimation = screenRotationAnimation != null
-                && screenRotationAnimation.isAnimating();
-        if (screenAnimation) {
-            thumbnailTransformation.postCompose(screenRotationAnimation.getEnterTransformation());
-        }
-        // cache often used attributes locally
-        final float tmpFloats[] = mService.mTmpFloats;
-        thumbnailTransformation.getMatrix().getValues(tmpFloats);
-        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail,
-                "thumbnail", "POS " + tmpFloats[Matrix.MTRANS_X]
-                + ", " + tmpFloats[Matrix.MTRANS_Y], null);
-        thumbnail.setPosition(tmpFloats[Matrix.MTRANS_X], tmpFloats[Matrix.MTRANS_Y]);
-        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(thumbnail,
-                "thumbnail", "alpha=" + thumbnailTransformation.getAlpha()
-                + " layer=" + thumbnailLayer
-                + " matrix=[" + tmpFloats[Matrix.MSCALE_X]
-                + "," + tmpFloats[Matrix.MSKEW_Y]
-                + "][" + tmpFloats[Matrix.MSKEW_X]
-                + "," + tmpFloats[Matrix.MSCALE_Y] + "]", null);
-        thumbnail.setAlpha(thumbnailTransformation.getAlpha());
-        // The thumbnail is layered below the window immediately above this
-        // token's anim layer.
-        thumbnail.setLayer(thumbnailLayer + WindowManagerService.WINDOW_LAYER_MULTIPLIER
-                - WindowManagerService.LAYER_OFFSET_THUMBNAIL);
-        thumbnail.setMatrix(tmpFloats[Matrix.MSCALE_X], tmpFloats[Matrix.MSKEW_Y],
-                tmpFloats[Matrix.MSKEW_X], tmpFloats[Matrix.MSCALE_Y]);
-    }
-
-    private boolean stepAnimation(long currentTime) {
-        if (animation == null) {
-            return false;
-        }
-        transformation.clear();
-        final boolean more = animation.getTransformation(currentTime, transformation);
-        if (false && WindowManagerService.DEBUG_ANIM) Slog.v(
-            TAG, "Stepped animation in " + mAppToken + ": more=" + more + ", xform=" + transformation);
-        if (!more) {
-            animation = null;
-            clearThumbnail();
-            if (WindowManagerService.DEBUG_ANIM) Slog.v(
-                TAG, "Finished animation in " + mAppToken + " @ " + currentTime);
-        }
-        hasTransformation = more;
-        return more;
-    }
-
-    // This must be called while inside a transaction.
-    boolean stepAnimationLocked(long currentTime) {
-        if (mService.okToDisplay()) {
-            // We will run animations as long as the display isn't frozen.
-
-            if (animation == sDummyAnimation) {
-                // This guy is going to animate, but not yet.  For now count
-                // it as not animating for purposes of scheduling transactions;
-                // when it is really time to animate, this will be set to
-                // a real animation and the next call will execute normally.
-                return false;
-            }
-
-            if ((mAppToken.allDrawn || animating || mAppToken.startingDisplayed)
-                    && animation != null) {
-                if (!animating) {
-                    if (WindowManagerService.DEBUG_ANIM) Slog.v(
-                        TAG, "Starting animation in " + mAppToken +
-                        " @ " + currentTime + " scale=" + mService.mTransitionAnimationScale
-                        + " allDrawn=" + mAppToken.allDrawn + " animating=" + animating);
-                    animation.setStartTime(currentTime);
-                    animating = true;
-                    if (thumbnail != null) {
-                        thumbnail.show();
-                        thumbnailAnimation.setStartTime(currentTime);
-                    }
-                }
-                if (stepAnimation(currentTime)) {
-                    // animation isn't over, step any thumbnail and that's
-                    // it for now.
-                    if (thumbnail != null) {
-                        stepThumbnailAnimation(currentTime);
-                    }
-                    return true;
-                }
-            }
-        } else if (animation != null) {
-            // If the display is frozen, and there is a pending animation,
-            // clear it and make sure we run the cleanup code.
-            animating = true;
-            animation = null;
-        }
-
-        hasTransformation = false;
-
-        if (!animating && animation == null) {
-            return false;
-        }
-
-        mAnimator.setAppLayoutChanges(this, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM,
-                "AppWindowToken");
-
-        clearAnimation();
-        animating = false;
-        if (animLayerAdjustment != 0) {
-            animLayerAdjustment = 0;
-            updateLayers();
-        }
-        if (mService.mInputMethodTarget != null
-                && mService.mInputMethodTarget.mAppToken == mAppToken) {
-            mService.moveInputMethodWindowsIfNeededLocked(true);
-        }
-
-        if (WindowManagerService.DEBUG_ANIM) Slog.v(
-                TAG, "Animation done in " + mAppToken
-                + ": reportedVisible=" + mAppToken.reportedVisible);
-
-        transformation.clear();
-
-        final int N = mAllAppWinAnimators.size();
-        for (int i=0; i<N; i++) {
-            mAllAppWinAnimators.get(i).finishExit();
-        }
-        mAppToken.updateReportedVisibilityLocked();
-
-        return false;
-    }
-
-    boolean showAllWindowsLocked() {
-        boolean isAnimating = false;
-        final int NW = mAllAppWinAnimators.size();
-        for (int i=0; i<NW; i++) {
-            WindowStateAnimator winAnimator = mAllAppWinAnimators.get(i);
-            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
-                    "performing show on: " + winAnimator);
-            winAnimator.performShowLocked();
-            isAnimating |= winAnimator.isAnimating();
-        }
-        return isAnimating;
-    }
-
-    void dump(PrintWriter pw, String prefix, boolean dumpAll) {
-        pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
-        pw.print(prefix); pw.print("mAnimator="); pw.println(mAnimator);
-        pw.print(prefix); pw.print("freezingScreen="); pw.print(freezingScreen);
-                pw.print(" allDrawn="); pw.print(allDrawn);
-                pw.print(" animLayerAdjustment="); pw.println(animLayerAdjustment);
-        if (lastFreezeDuration != 0) {
-            pw.print(prefix); pw.print("lastFreezeDuration=");
-                    TimeUtils.formatDuration(lastFreezeDuration, pw); pw.println();
-        }
-        if (animating || animation != null) {
-            pw.print(prefix); pw.print("animating="); pw.println(animating);
-            pw.print(prefix); pw.print("animation="); pw.println(animation);
-        }
-        if (hasTransformation) {
-            pw.print(prefix); pw.print("XForm: ");
-                    transformation.printShortString(pw);
-                    pw.println();
-        }
-        if (thumbnail != null) {
-            pw.print(prefix); pw.print("thumbnail="); pw.print(thumbnail);
-                    pw.print(" x="); pw.print(thumbnailX);
-                    pw.print(" y="); pw.print(thumbnailY);
-                    pw.print(" layer="); pw.println(thumbnailLayer);
-            pw.print(prefix); pw.print("thumbnailAnimation="); pw.println(thumbnailAnimation);
-            pw.print(prefix); pw.print("thumbnailTransformation=");
-                    pw.println(thumbnailTransformation.toShortString());
-        }
-        for (int i=0; i<mAllAppWinAnimators.size(); i++) {
-            WindowStateAnimator wanim = mAllAppWinAnimators.get(i);
-            pw.print(prefix); pw.print("App Win Anim #"); pw.print(i);
-                    pw.print(": "); pw.println(wanim);
-        }
-    }
-
-    // This is an animation that does nothing: it just immediately finishes
-    // itself every time it is called.  It is used as a stub animation in cases
-    // where we want to synchronize multiple things that may be animating.
-    static final class DummyAnimation extends Animation {
-        @Override
-        public boolean getTransformation(long currentTime, Transformation outTransformation) {
-            return false;
-        }
-    }
-
-}
diff --git a/services/java/com/android/server/wm/AppWindowToken.java b/services/java/com/android/server/wm/AppWindowToken.java
deleted file mode 100644
index e98014b..0000000
--- a/services/java/com/android/server/wm/AppWindowToken.java
+++ /dev/null
@@ -1,305 +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.server.wm;
-
-import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
-
-import com.android.server.input.InputApplicationHandle;
-import com.android.server.wm.WindowManagerService.H;
-
-import android.content.pm.ActivityInfo;
-import android.os.Message;
-import android.os.RemoteException;
-import android.util.Slog;
-import android.view.IApplicationToken;
-import android.view.View;
-import android.view.WindowManager;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-class AppTokenList extends ArrayList<AppWindowToken> {
-}
-
-/**
- * Version of WindowToken that is specifically for a particular application (or
- * really activity) that is displaying windows.
- */
-class AppWindowToken extends WindowToken {
-    // Non-null only for application tokens.
-    final IApplicationToken appToken;
-
-    // All of the windows and child windows that are included in this
-    // application token.  Note this list is NOT sorted!
-    final WindowList allAppWindows = new WindowList();
-    final AppWindowAnimator mAppAnimator;
-
-    final WindowAnimator mAnimator;
-
-    int groupId = -1;
-    boolean appFullscreen;
-    int requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-    boolean layoutConfigChanges;
-    boolean showWhenLocked;
-
-    // The input dispatching timeout for this application token in nanoseconds.
-    long inputDispatchingTimeoutNanos;
-
-    // These are used for determining when all windows associated with
-    // an activity have been drawn, so they can be made visible together
-    // at the same time.
-    // initialize so that it doesn't match mTransactionSequence which is an int.
-    long lastTransactionSequence = Long.MIN_VALUE;
-    int numInterestingWindows;
-    int numDrawnWindows;
-    boolean inPendingTransaction;
-    boolean allDrawn;
-    // Set to true when this app creates a surface while in the middle of an animation. In that
-    // case do not clear allDrawn until the animation completes.
-    boolean deferClearAllDrawn;
-
-    // Is this token going to be hidden in a little while?  If so, it
-    // won't be taken into account for setting the screen orientation.
-    boolean willBeHidden;
-
-    // Is this window's surface needed?  This is almost like hidden, except
-    // it will sometimes be true a little earlier: when the token has
-    // been shown, but is still waiting for its app transition to execute
-    // before making its windows shown.
-    boolean hiddenRequested;
-
-    // Have we told the window clients to hide themselves?
-    boolean clientHidden;
-
-    // Last visibility state we reported to the app token.
-    boolean reportedVisible;
-
-    // Last drawn state we reported to the app token.
-    boolean reportedDrawn;
-
-    // Set to true when the token has been removed from the window mgr.
-    boolean removed;
-
-    // Information about an application starting window if displayed.
-    StartingData startingData;
-    WindowState startingWindow;
-    View startingView;
-    boolean startingDisplayed;
-    boolean startingMoved;
-    boolean firstWindowDrawn;
-
-    // Input application handle used by the input dispatcher.
-    final InputApplicationHandle mInputApplicationHandle;
-
-    AppWindowToken(WindowManagerService _service, IApplicationToken _token) {
-        super(_service, _token.asBinder(),
-                WindowManager.LayoutParams.TYPE_APPLICATION, true);
-        appWindowToken = this;
-        appToken = _token;
-        mInputApplicationHandle = new InputApplicationHandle(this);
-        mAnimator = service.mAnimator;
-        mAppAnimator = new AppWindowAnimator(this);
-    }
-
-    void sendAppVisibilityToClients() {
-        final int N = allAppWindows.size();
-        for (int i=0; i<N; i++) {
-            WindowState win = allAppWindows.get(i);
-            if (win == startingWindow && clientHidden) {
-                // Don't hide the starting window.
-                continue;
-            }
-            try {
-                if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
-                        "Setting visibility of " + win + ": " + (!clientHidden));
-                win.mClient.dispatchAppVisibility(!clientHidden);
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    void updateReportedVisibilityLocked() {
-        if (appToken == null) {
-            return;
-        }
-
-        int numInteresting = 0;
-        int numVisible = 0;
-        int numDrawn = 0;
-        boolean nowGone = true;
-
-        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG,
-                "Update reported visibility: " + this);
-        final int N = allAppWindows.size();
-        for (int i=0; i<N; i++) {
-            WindowState win = allAppWindows.get(i);
-            if (win == startingWindow || win.mAppFreezing
-                    || win.mViewVisibility != View.VISIBLE
-                    || win.mAttrs.type == TYPE_APPLICATION_STARTING
-                    || win.mDestroying) {
-                continue;
-            }
-            if (WindowManagerService.DEBUG_VISIBILITY) {
-                Slog.v(WindowManagerService.TAG, "Win " + win + ": isDrawn="
-                        + win.isDrawnLw()
-                        + ", isAnimating=" + win.mWinAnimator.isAnimating());
-                if (!win.isDrawnLw()) {
-                    Slog.v(WindowManagerService.TAG, "Not displayed: s=" + win.mWinAnimator.mSurfaceControl
-                            + " pv=" + win.mPolicyVisibility
-                            + " mDrawState=" + win.mWinAnimator.mDrawState
-                            + " ah=" + win.mAttachedHidden
-                            + " th="
-                            + (win.mAppToken != null
-                                    ? win.mAppToken.hiddenRequested : false)
-                            + " a=" + win.mWinAnimator.mAnimating);
-                }
-            }
-            numInteresting++;
-            if (win.isDrawnLw()) {
-                numDrawn++;
-                if (!win.mWinAnimator.isAnimating()) {
-                    numVisible++;
-                }
-                nowGone = false;
-            } else if (win.mWinAnimator.isAnimating()) {
-                nowGone = false;
-            }
-        }
-
-        boolean nowDrawn = numInteresting > 0 && numDrawn >= numInteresting;
-        boolean nowVisible = numInteresting > 0 && numVisible >= numInteresting;
-        if (!nowGone) {
-            // If the app is not yet gone, then it can only become visible/drawn.
-            if (!nowDrawn) {
-                nowDrawn = reportedDrawn;
-            }
-            if (!nowVisible) {
-                nowVisible = reportedVisible;
-            }
-        }
-        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(WindowManagerService.TAG, "VIS " + this + ": interesting="
-                + numInteresting + " visible=" + numVisible);
-        if (nowDrawn != reportedDrawn) {
-            if (nowDrawn) {
-                Message m = service.mH.obtainMessage(
-                        H.REPORT_APPLICATION_TOKEN_DRAWN, this);
-                service.mH.sendMessage(m);
-            }
-            reportedDrawn = nowDrawn;
-        }
-        if (nowVisible != reportedVisible) {
-            if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(
-                    WindowManagerService.TAG, "Visibility changed in " + this
-                    + ": vis=" + nowVisible);
-            reportedVisible = nowVisible;
-            Message m = service.mH.obtainMessage(
-                    H.REPORT_APPLICATION_TOKEN_WINDOWS,
-                    nowVisible ? 1 : 0,
-                    nowGone ? 1 : 0,
-                    this);
-            service.mH.sendMessage(m);
-        }
-    }
-
-    WindowState findMainWindow() {
-        int j = windows.size();
-        while (j > 0) {
-            j--;
-            WindowState win = windows.get(j);
-            if (win.mAttrs.type == WindowManager.LayoutParams.TYPE_BASE_APPLICATION
-                    || win.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
-                return win;
-            }
-        }
-        return null;
-    }
-
-    boolean isVisible() {
-        final int N = allAppWindows.size();
-        for (int i=0; i<N; i++) {
-            WindowState win = allAppWindows.get(i);
-            if (!win.mAppFreezing
-                    && (win.mViewVisibility == View.VISIBLE ||
-                        (win.mWinAnimator.isAnimating() &&
-                                !service.mAppTransition.isTransitionSet()))
-                    && !win.mDestroying && win.isDrawnLw()) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    void dump(PrintWriter pw, String prefix) {
-        super.dump(pw, prefix);
-        if (appToken != null) {
-            pw.print(prefix); pw.println("app=true");
-        }
-        if (allAppWindows.size() > 0) {
-            pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
-        }
-        pw.print(prefix); pw.print("groupId="); pw.print(groupId);
-                pw.print(" appFullscreen="); pw.print(appFullscreen);
-                pw.print(" requestedOrientation="); pw.println(requestedOrientation);
-        pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
-                pw.print(" clientHidden="); pw.print(clientHidden);
-                pw.print(" willBeHidden="); pw.print(willBeHidden);
-                pw.print(" reportedDrawn="); pw.print(reportedDrawn);
-                pw.print(" reportedVisible="); pw.println(reportedVisible);
-        if (paused) {
-            pw.print(prefix); pw.print("paused="); pw.println(paused);
-        }
-        if (numInterestingWindows != 0 || numDrawnWindows != 0
-                || allDrawn || mAppAnimator.allDrawn) {
-            pw.print(prefix); pw.print("numInterestingWindows=");
-                    pw.print(numInterestingWindows);
-                    pw.print(" numDrawnWindows="); pw.print(numDrawnWindows);
-                    pw.print(" inPendingTransaction="); pw.print(inPendingTransaction);
-                    pw.print(" allDrawn="); pw.print(allDrawn);
-                    pw.print(" (animator="); pw.print(mAppAnimator.allDrawn);
-                    pw.println(")");
-        }
-        if (inPendingTransaction) {
-            pw.print(prefix); pw.print("inPendingTransaction=");
-                    pw.println(inPendingTransaction);
-        }
-        if (startingData != null || removed || firstWindowDrawn) {
-            pw.print(prefix); pw.print("startingData="); pw.print(startingData);
-                    pw.print(" removed="); pw.print(removed);
-                    pw.print(" firstWindowDrawn="); pw.println(firstWindowDrawn);
-        }
-        if (startingWindow != null || startingView != null
-                || startingDisplayed || startingMoved) {
-            pw.print(prefix); pw.print("startingWindow="); pw.print(startingWindow);
-                    pw.print(" startingView="); pw.print(startingView);
-                    pw.print(" startingDisplayed="); pw.print(startingDisplayed);
-                    pw.print(" startingMoved"); pw.println(startingMoved);
-        }
-    }
-
-    @Override
-    public String toString() {
-        if (stringName == null) {
-            StringBuilder sb = new StringBuilder();
-            sb.append("AppWindowToken{");
-            sb.append(Integer.toHexString(System.identityHashCode(this)));
-            sb.append(" token="); sb.append(token); sb.append('}');
-            stringName = sb.toString();
-        }
-        return stringName;
-    }
-}
diff --git a/services/java/com/android/server/wm/DimLayer.java b/services/java/com/android/server/wm/DimLayer.java
deleted file mode 100644
index c189ddd..0000000
--- a/services/java/com/android/server/wm/DimLayer.java
+++ /dev/null
@@ -1,290 +0,0 @@
-// Copyright 2012 Google Inc. All Rights Reserved.
-
-package com.android.server.wm;
-
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.os.SystemClock;
-import android.util.Slog;
-import android.view.DisplayInfo;
-import android.view.SurfaceControl;
-
-import java.io.PrintWriter;
-
-public class DimLayer {
-    private static final String TAG = "DimLayer";
-    private static final boolean DEBUG = false;
-
-    /** Reference to the owner of this object. */
-    final DisplayContent mDisplayContent;
-
-    /** Actual surface that dims */
-    SurfaceControl mDimSurface;
-
-    /** Last value passed to mDimSurface.setAlpha() */
-    float mAlpha = 0;
-
-    /** Last value passed to mDimSurface.setLayer() */
-    int mLayer = -1;
-
-    /** Next values to pass to mDimSurface.setPosition() and mDimSurface.setSize() */
-    Rect mBounds = new Rect();
-
-    /** Last values passed to mDimSurface.setPosition() and mDimSurface.setSize() */
-    Rect mLastBounds = new Rect();
-
-    /** True after mDimSurface.show() has been called, false after mDimSurface.hide(). */
-    private boolean mShowing = false;
-
-    /** Value of mAlpha when beginning transition to mTargetAlpha */
-    float mStartAlpha = 0;
-
-    /** Final value of mAlpha following transition */
-    float mTargetAlpha = 0;
-
-    /** Time in units of SystemClock.uptimeMillis() at which the current transition started */
-    long mStartTime;
-
-    /** Time in milliseconds to take to transition from mStartAlpha to mTargetAlpha */
-    long mDuration;
-
-    /** Owning stack */
-    final TaskStack mStack;
-
-    DimLayer(WindowManagerService service, TaskStack stack) {
-        mStack = stack;
-        mDisplayContent = stack.getDisplayContent();
-        final int displayId = mDisplayContent.getDisplayId();
-        if (DEBUG) Slog.v(TAG, "Ctor: displayId=" + displayId);
-        SurfaceControl.openTransaction();
-        try {
-            if (WindowManagerService.DEBUG_SURFACE_TRACE) {
-                mDimSurface = new WindowStateAnimator.SurfaceTrace(service.mFxSession,
-                    "DimSurface",
-                    16, 16, PixelFormat.OPAQUE,
-                    SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN);
-            } else {
-                mDimSurface = new SurfaceControl(service.mFxSession, TAG,
-                    16, 16, PixelFormat.OPAQUE,
-                    SurfaceControl.FX_SURFACE_DIM | SurfaceControl.HIDDEN);
-            }
-            if (WindowManagerService.SHOW_TRANSACTIONS ||
-                    WindowManagerService.SHOW_SURFACE_ALLOC) Slog.i(TAG,
-                            "  DIM " + mDimSurface + ": CREATE");
-            mDimSurface.setLayerStack(displayId);
-        } catch (Exception e) {
-            Slog.e(WindowManagerService.TAG, "Exception creating Dim surface", e);
-        } finally {
-            SurfaceControl.closeTransaction();
-        }
-    }
-
-    /** Return true if dim layer is showing */
-    boolean isDimming() {
-        return mTargetAlpha != 0;
-    }
-
-    /** Return true if in a transition period */
-    boolean isAnimating() {
-        return mTargetAlpha != mAlpha;
-    }
-
-    float getTargetAlpha() {
-        return mTargetAlpha;
-    }
-
-    void setLayer(int layer) {
-        if (mLayer != layer) {
-            mLayer = layer;
-            mDimSurface.setLayer(layer);
-        }
-    }
-
-    int getLayer() {
-        return mLayer;
-    }
-
-    private void setAlpha(float alpha) {
-        if (mAlpha != alpha) {
-            if (DEBUG) Slog.v(TAG, "setAlpha alpha=" + alpha);
-            try {
-                mDimSurface.setAlpha(alpha);
-                if (alpha == 0 && mShowing) {
-                    if (DEBUG) Slog.v(TAG, "setAlpha hiding");
-                    mDimSurface.hide();
-                    mShowing = false;
-                } else if (alpha > 0 && !mShowing) {
-                    if (DEBUG) Slog.v(TAG, "setAlpha showing");
-                    mDimSurface.show();
-                    mShowing = true;
-                }
-            } catch (RuntimeException e) {
-                Slog.w(TAG, "Failure setting alpha immediately", e);
-            }
-            mAlpha = alpha;
-        }
-    }
-
-    void setBounds(Rect bounds) {
-        mBounds.set(bounds);
-    }
-
-    /**
-     * @param duration The time to test.
-     * @return True if the duration would lead to an earlier end to the current animation.
-     */
-    private boolean durationEndsEarlier(long duration) {
-        return SystemClock.uptimeMillis() + duration < mStartTime + mDuration;
-    }
-
-    /** Jump to the end of the animation.
-     * NOTE: Must be called with Surface transaction open. */
-    void show() {
-        if (isAnimating()) {
-            if (DEBUG) Slog.v(TAG, "show: immediate");
-            show(mLayer, mTargetAlpha, 0);
-        }
-    }
-
-    /**
-     * Begin an animation to a new dim value.
-     * NOTE: Must be called with Surface transaction open.
-     *
-     * @param layer The layer to set the surface to.
-     * @param alpha The dim value to end at.
-     * @param duration How long to take to get there in milliseconds.
-     */
-    void show(int layer, float alpha, long duration) {
-        if (DEBUG) Slog.v(TAG, "show: layer=" + layer + " alpha=" + alpha
-                + " duration=" + duration);
-        if (mDimSurface == null) {
-            Slog.e(TAG, "show: no Surface");
-            // Make sure isAnimating() returns false.
-            mTargetAlpha = mAlpha = 0;
-            return;
-        }
-
-        final int dw, dh;
-        final float xPos, yPos;
-        if (mStack.hasSibling()) {
-            dw = mBounds.width();
-            dh = mBounds.height();
-            xPos = mBounds.left;
-            yPos = mBounds.right;
-        } else {
-            // Set surface size to screen size.
-            final DisplayInfo info = mDisplayContent.getDisplayInfo();
-            // Multiply by 1.5 so that rotating a frozen surface that includes this does not expose a
-            // corner.
-            dw = (int) (info.logicalWidth * 1.5);
-            dh = (int) (info.logicalHeight * 1.5);
-            // back off position so 1/4 of Surface is before and 1/4 is after.
-            xPos = -1 * dw / 6;
-            yPos = -1 * dh / 6;
-        }
-
-        if (!mLastBounds.equals(mBounds) || mLayer != layer) {
-            try {
-                mDimSurface.setPosition(xPos, yPos);
-                mDimSurface.setSize(dw, dh);
-                mDimSurface.setLayer(layer);
-            } catch (RuntimeException e) {
-                Slog.w(TAG, "Failure setting size or layer", e);
-            }
-            mLastBounds.set(mBounds);
-            mLayer = layer;
-        }
-
-        long curTime = SystemClock.uptimeMillis();
-        final boolean animating = isAnimating();
-        if ((animating && (mTargetAlpha != alpha || durationEndsEarlier(duration)))
-                || (!animating && mAlpha != alpha)) {
-            if (duration <= 0) {
-                // No animation required, just set values.
-                setAlpha(alpha);
-            } else {
-                // Start or continue animation with new parameters.
-                mStartAlpha = mAlpha;
-                mStartTime = curTime;
-                mDuration = duration;
-            }
-        }
-        if (DEBUG) Slog.v(TAG, "show: mStartAlpha=" + mStartAlpha + " mStartTime=" + mStartTime);
-        mTargetAlpha = alpha;
-    }
-
-    /** Immediate hide.
-     * NOTE: Must be called with Surface transaction open. */
-    void hide() {
-        if (mShowing) {
-            if (DEBUG) Slog.v(TAG, "hide: immediate");
-            hide(0);
-        }
-    }
-
-    /**
-     * Gradually fade to transparent.
-     * NOTE: Must be called with Surface transaction open.
-     *
-     * @param duration Time to fade in milliseconds.
-     */
-    void hide(long duration) {
-        if (mShowing && (mTargetAlpha != 0 || durationEndsEarlier(duration))) {
-            if (DEBUG) Slog.v(TAG, "hide: duration=" + duration);
-            show(mLayer, 0, duration);
-        }
-    }
-
-    /**
-     * Advance the dimming per the last #show(int, float, long) call.
-     * NOTE: Must be called with Surface transaction open.
-     *
-     * @return True if animation is still required after this step.
-     */
-    boolean stepAnimation() {
-        if (mDimSurface == null) {
-            Slog.e(TAG, "stepAnimation: null Surface");
-            // Ensure that isAnimating() returns false;
-            mTargetAlpha = mAlpha = 0;
-            return false;
-        }
-
-        if (isAnimating()) {
-            final long curTime = SystemClock.uptimeMillis();
-            final float alphaDelta = mTargetAlpha - mStartAlpha;
-            float alpha = mStartAlpha + alphaDelta * (curTime - mStartTime) / mDuration;
-            if (alphaDelta > 0 && alpha > mTargetAlpha ||
-                    alphaDelta < 0 && alpha < mTargetAlpha) {
-                // Don't exceed limits.
-                alpha = mTargetAlpha;
-            }
-            if (DEBUG) Slog.v(TAG, "stepAnimation: curTime=" + curTime + " alpha=" + alpha);
-            setAlpha(alpha);
-        }
-
-        return isAnimating();
-    }
-
-    /** Cleanup */
-    void destroySurface() {
-        if (DEBUG) Slog.v(TAG, "destroySurface.");
-        if (mDimSurface != null) {
-            mDimSurface.destroy();
-            mDimSurface = null;
-        }
-    }
-
-    public void printTo(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("mDimSurface="); pw.print(mDimSurface);
-                pw.print(" mLayer="); pw.print(mLayer);
-                pw.print(" mAlpha="); pw.println(mAlpha);
-        pw.print(prefix); pw.print("mLastBounds="); pw.print(mLastBounds.toShortString());
-                pw.print(" mBounds="); pw.println(mBounds.toShortString());
-        pw.print(prefix); pw.print("Last animation: ");
-                pw.print(" mDuration="); pw.print(mDuration);
-                pw.print(" mStartTime="); pw.print(mStartTime);
-                pw.print(" curTime="); pw.println(SystemClock.uptimeMillis());
-        pw.print(prefix); pw.print(" mStartAlpha="); pw.print(mStartAlpha);
-                pw.print(" mTargetAlpha="); pw.println(mTargetAlpha);
-    }
-}
diff --git a/services/java/com/android/server/wm/DisplayContent.java b/services/java/com/android/server/wm/DisplayContent.java
deleted file mode 100644
index d358b4c..0000000
--- a/services/java/com/android/server/wm/DisplayContent.java
+++ /dev/null
@@ -1,523 +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.server.wm;
-
-import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
-import static com.android.server.wm.WindowManagerService.DEBUG_STACK;
-import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
-import static com.android.server.wm.WindowManagerService.TAG;
-
-import android.app.ActivityManager.StackBoxInfo;
-import android.graphics.Rect;
-import android.graphics.Region;
-import android.os.Debug;
-import android.util.EventLog;
-import android.util.Slog;
-import android.view.Display;
-import android.view.DisplayInfo;
-import com.android.server.EventLogTags;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-class DisplayContentList extends ArrayList<DisplayContent> {
-}
-
-/**
- * Utility class for keeping track of the WindowStates and other pertinent contents of a
- * particular Display.
- *
- * IMPORTANT: No method from this class should ever be used without holding
- * WindowManagerService.mWindowMap.
- */
-class DisplayContent {
-
-    /** Unique identifier of this stack. */
-    private final int mDisplayId;
-
-    /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
-     * from mDisplayWindows; */
-    private WindowList mWindows = new WindowList();
-
-    // This protects the following display size properties, so that
-    // getDisplaySize() doesn't need to acquire the global lock.  This is
-    // needed because the window manager sometimes needs to use ActivityThread
-    // while it has its global state locked (for example to load animation
-    // resources), but the ActivityThread also needs get the current display
-    // size sometimes when it has its package lock held.
-    //
-    // These will only be modified with both mWindowMap and mDisplaySizeLock
-    // held (in that order) so the window manager doesn't need to acquire this
-    // lock when needing these values in its normal operation.
-    final Object mDisplaySizeLock = new Object();
-    int mInitialDisplayWidth = 0;
-    int mInitialDisplayHeight = 0;
-    int mInitialDisplayDensity = 0;
-    int mBaseDisplayWidth = 0;
-    int mBaseDisplayHeight = 0;
-    int mBaseDisplayDensity = 0;
-    private final DisplayInfo mDisplayInfo = new DisplayInfo();
-    private final Display mDisplay;
-
-    Rect mBaseDisplayRect = new Rect();
-
-    // Accessed directly by all users.
-    boolean layoutNeeded;
-    int pendingLayoutChanges;
-    final boolean isDefaultDisplay;
-
-    /**
-     * Window tokens that are in the process of exiting, but still
-     * on screen for animations.
-     */
-    final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>();
-
-    /**
-     * Application tokens that are in the process of exiting, but still
-     * on screen for animations.
-     */
-    final AppTokenList mExitingAppTokens = new AppTokenList();
-
-    /** Array containing the home StackBox and possibly one more which would contain apps. Array
-     * is stored in display order with the current bottom stack at 0. */
-    private ArrayList<StackBox> mStackBoxes = new ArrayList<StackBox>();
-
-    /** True when the home StackBox is at the top of mStackBoxes, false otherwise. */
-    private TaskStack mHomeStack = null;
-
-    /** Detect user tapping outside of current focused stack bounds .*/
-    StackTapPointerEventListener mTapDetector;
-
-    /** Detect user tapping outside of current focused stack bounds .*/
-    Region mTouchExcludeRegion = new Region();
-
-    /** Save allocating when retrieving tasks */
-    private ArrayList<Task> mTaskHistory = new ArrayList<Task>();
-
-    /** Save allocating when calculating rects */
-    Rect mTmpRect = new Rect();
-
-    final WindowManagerService mService;
-
-    /**
-     * @param display May not be null.
-     * @param service TODO(cmautner):
-     */
-    DisplayContent(Display display, WindowManagerService service) {
-        mDisplay = display;
-        mDisplayId = display.getDisplayId();
-        display.getDisplayInfo(mDisplayInfo);
-        isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
-        mService = service;
-
-        StackBox newBox = new StackBox(service, this, null);
-        mStackBoxes.add(newBox);
-        TaskStack newStack = new TaskStack(service, HOME_STACK_ID, this);
-        newStack.mStackBox = newBox;
-        newBox.mStack = newStack;
-        mHomeStack = newStack;
-    }
-
-    int getDisplayId() {
-        return mDisplayId;
-    }
-
-    WindowList getWindowList() {
-        return mWindows;
-    }
-
-    Display getDisplay() {
-        return mDisplay;
-    }
-
-    DisplayInfo getDisplayInfo() {
-        return mDisplayInfo;
-    }
-
-    /**
-     * Returns true if the specified UID has access to this display.
-     */
-    public boolean hasAccess(int uid) {
-        return mDisplay.hasAccess(uid);
-    }
-
-    boolean homeOnTop() {
-        return mStackBoxes.get(0).mStack != mHomeStack;
-    }
-
-    public boolean isPrivate() {
-        return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
-    }
-
-    /**
-     * Retrieve the tasks on this display in stack order from the bottommost TaskStack up.
-     * @return All the Tasks, in order, on this display.
-     */
-    ArrayList<Task> getTasks() {
-        return mTaskHistory;
-    }
-
-    void addTask(Task task, boolean toTop) {
-        mTaskHistory.remove(task);
-
-        final int userId = task.mUserId;
-        int taskNdx;
-        final int numTasks = mTaskHistory.size();
-        if (toTop) {
-            for (taskNdx = numTasks - 1; taskNdx >= 0; --taskNdx) {
-                if (mTaskHistory.get(taskNdx).mUserId == userId) {
-                    break;
-                }
-            }
-            ++taskNdx;
-        } else {
-            for (taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-                if (mTaskHistory.get(taskNdx).mUserId == userId) {
-                    break;
-                }
-            }
-        }
-
-        mTaskHistory.add(taskNdx, task);
-        EventLog.writeEvent(EventLogTags.WM_TASK_MOVED, task.taskId, toTop ? 1 : 0, taskNdx);
-    }
-
-    void removeTask(Task task) {
-        mTaskHistory.remove(task);
-    }
-
-    TaskStack getHomeStack() {
-        return mHomeStack;
-    }
-
-    void updateDisplayInfo() {
-        mDisplay.getDisplayInfo(mDisplayInfo);
-    }
-
-    void getLogicalDisplayRect(Rect out) {
-        updateDisplayInfo();
-        // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
-        int width = mDisplayInfo.logicalWidth;
-        int left = (mBaseDisplayWidth - width) / 2;
-        int height = mDisplayInfo.logicalHeight;
-        int top = (mBaseDisplayHeight - height) / 2;
-        out.set(left, top, left + width, top + height);
-    }
-
-    /** @return The number of tokens in all of the Tasks on this display. */
-    int numTokens() {
-        int count = 0;
-        for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-            count += mTaskHistory.get(taskNdx).mAppTokens.size();
-        }
-        return count;
-    }
-
-    /** Refer to {@link WindowManagerService#createStack(int, int, int, float)} */
-    TaskStack createStack(int stackId, int relativeStackBoxId, int position, float weight) {
-        TaskStack newStack = null;
-        if (DEBUG_STACK) Slog.d(TAG, "createStack: stackId=" + stackId + " relativeStackBoxId="
-                + relativeStackBoxId + " position=" + position + " weight=" + weight);
-        if (stackId == HOME_STACK_ID) {
-            if (mStackBoxes.size() != 1) {
-                throw new IllegalArgumentException("createStack: HOME_STACK_ID (0) not first.");
-            }
-            newStack = mHomeStack;
-        } else {
-            int stackBoxNdx;
-            for (stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-                final StackBox box = mStackBoxes.get(stackBoxNdx);
-                if (position == StackBox.TASK_STACK_GOES_OVER
-                        || position == StackBox.TASK_STACK_GOES_UNDER) {
-                    // Position indicates a new box is added at top level only.
-                    if (box.contains(relativeStackBoxId)) {
-                        StackBox newBox = new StackBox(mService, this, null);
-                        newStack = new TaskStack(mService, stackId, this);
-                        newStack.mStackBox = newBox;
-                        newBox.mStack = newStack;
-                        final int offset = position == StackBox.TASK_STACK_GOES_OVER ? 1 : 0;
-                        if (DEBUG_STACK) Slog.d(TAG, "createStack: inserting stack at " +
-                                (stackBoxNdx + offset));
-                        mStackBoxes.add(stackBoxNdx + offset, newBox);
-                        break;
-                    }
-                } else {
-                    // Remaining position values indicate a box must be split.
-                    newStack = box.split(stackId, relativeStackBoxId, position, weight);
-                    if (newStack != null) {
-                        break;
-                    }
-                }
-            }
-            if (stackBoxNdx < 0) {
-                throw new IllegalArgumentException("createStack: stackBoxId " + relativeStackBoxId
-                        + " not found.");
-            }
-        }
-        if (newStack != null) {
-            layoutNeeded = true;
-        }
-        EventLog.writeEvent(EventLogTags.WM_STACK_CREATED, stackId, relativeStackBoxId, position,
-                (int)(weight * 100 + 0.5));
-        return newStack;
-    }
-
-    /** Refer to {@link WindowManagerService#resizeStackBox(int, float)} */
-    boolean resizeStack(int stackBoxId, float weight) {
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            final StackBox box = mStackBoxes.get(stackBoxNdx);
-            if (box.resize(stackBoxId, weight)) {
-                layoutNeeded = true;
-                return true;
-            }
-        }
-        return false;
-    }
-
-    void addStackBox(StackBox box, boolean toTop) {
-        if (mStackBoxes.size() >= 2) {
-            throw new RuntimeException("addStackBox: Too many toplevel StackBoxes!");
-        }
-        mStackBoxes.add(toTop ? mStackBoxes.size() : 0, box);
-    }
-
-    void removeStackBox(StackBox box) {
-        if (DEBUG_STACK) Slog.d(TAG, "removeStackBox: box=" + box);
-        final TaskStack stack = box.mStack;
-        if (stack != null && stack.mStackId == HOME_STACK_ID) {
-            // Never delete the home stack, even if it is empty.
-            if (DEBUG_STACK) Slog.d(TAG, "removeStackBox: Not deleting home stack.");
-            return;
-        }
-        mStackBoxes.remove(box);
-    }
-
-    StackBoxInfo getStackBoxInfo(StackBox box) {
-        StackBoxInfo info = new StackBoxInfo();
-        info.stackBoxId = box.mStackBoxId;
-        info.weight = box.mWeight;
-        info.vertical = box.mVertical;
-        info.bounds = new Rect(box.mBounds);
-        if (box.mStack != null) {
-            info.stackId = box.mStack.mStackId;
-            // ActivityManagerService will fill in the StackInfo.
-        } else {
-            info.stackId = -1;
-            info.children = new StackBoxInfo[2];
-            info.children[0] = getStackBoxInfo(box.mFirst);
-            info.children[1] = getStackBoxInfo(box.mSecond);
-        }
-        return info;
-    }
-
-    ArrayList<StackBoxInfo> getStackBoxInfos() {
-        ArrayList<StackBoxInfo> list = new ArrayList<StackBoxInfo>();
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            list.add(getStackBoxInfo(mStackBoxes.get(stackBoxNdx)));
-        }
-        return list;
-    }
-
-    /**
-     * Move the home StackBox to the top or bottom of mStackBoxes. That is the only place
-     * it is allowed to be. This is a nop if the home StackBox is already in the correct position.
-     * @param toTop Move home to the top of mStackBoxes if true, to the bottom if false.
-     * @return true if a change was made, false otherwise.
-     */
-    boolean moveHomeStackBox(boolean toTop) {
-        if (DEBUG_STACK) Slog.d(TAG, "moveHomeStackBox: toTop=" + toTop + " Callers=" +
-                Debug.getCallers(4));
-        EventLog.writeEvent(EventLogTags.WM_HOME_STACK_MOVED, toTop ? 1 : 0);
-        switch (mStackBoxes.size()) {
-            case 0: throw new RuntimeException("moveHomeStackBox: No home StackBox!");
-            case 1: return false; // Only the home StackBox exists.
-            case 2:
-                if (homeOnTop() ^ toTop) {
-                    mStackBoxes.add(mStackBoxes.remove(0));
-                    return true;
-                }
-                return false;
-            default: throw new RuntimeException("moveHomeStackBox: Too many toplevel StackBoxes!");
-        }
-    }
-
-    /**
-     * Propagate the new bounds to all child stack boxes, applying weights as we move down.
-     * @param contentRect The bounds to apply at the top level.
-     */
-    boolean setStackBoxSize(Rect contentRect) {
-        boolean change = false;
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            change |= mStackBoxes.get(stackBoxNdx).setStackBoxSizes(contentRect, true);
-        }
-        return change;
-    }
-
-    Rect getStackBounds(int stackId) {
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            Rect bounds = mStackBoxes.get(stackBoxNdx).getStackBounds(stackId);
-            if (bounds != null) {
-                return bounds;
-            }
-        }
-        return null;
-    }
-
-    int stackIdFromPoint(int x, int y) {
-        StackBox topBox = mStackBoxes.get(mStackBoxes.size() - 1);
-        return topBox.stackIdFromPoint(x, y);
-    }
-
-    void setTouchExcludeRegion(TaskStack focusedStack) {
-        mTouchExcludeRegion.set(mBaseDisplayRect);
-        WindowList windows = getWindowList();
-        for (int i = windows.size() - 1; i >= 0; --i) {
-            final WindowState win = windows.get(i);
-            final TaskStack stack = win.getStack();
-            if (win.isVisibleLw() && stack != null && stack != focusedStack) {
-                mTmpRect.set(win.mVisibleFrame);
-                mTmpRect.intersect(win.mVisibleInsets);
-                mTouchExcludeRegion.op(mTmpRect, Region.Op.DIFFERENCE);
-            }
-        }
-    }
-
-    void switchUserStacks(int oldUserId, int newUserId) {
-        final WindowList windows = getWindowList();
-        for (int i = 0; i < windows.size(); i++) {
-            final WindowState win = windows.get(i);
-            if (win.isHiddenFromUserLocked()) {
-                if (DEBUG_VISIBILITY) Slog.w(TAG, "user changing " + newUserId + " hiding "
-                        + win + ", attrs=" + win.mAttrs.type + ", belonging to "
-                        + win.mOwnerUid);
-                win.hideLw(false);
-            }
-        }
-
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            mStackBoxes.get(stackBoxNdx).switchUserStacks(newUserId);
-        }
-    }
-
-    void resetAnimationBackgroundAnimator() {
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            mStackBoxes.get(stackBoxNdx).resetAnimationBackgroundAnimator();
-        }
-    }
-
-    boolean animateDimLayers() {
-        boolean result = false;
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            result |= mStackBoxes.get(stackBoxNdx).animateDimLayers();
-        }
-        return result;
-    }
-
-    void resetDimming() {
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            mStackBoxes.get(stackBoxNdx).resetDimming();
-        }
-    }
-
-    boolean isDimming() {
-        boolean result = false;
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            result |= mStackBoxes.get(stackBoxNdx).isDimming();
-        }
-        return result;
-    }
-
-    void stopDimmingIfNeeded() {
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            mStackBoxes.get(stackBoxNdx).stopDimmingIfNeeded();
-        }
-    }
-
-    void close() {
-        for (int stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) {
-            mStackBoxes.get(stackBoxNdx).close();
-        }
-    }
-
-    public void dump(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
-        final String subPrefix = "  " + prefix;
-        pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
-            pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
-            pw.print("dpi");
-            if (mInitialDisplayWidth != mBaseDisplayWidth
-                    || mInitialDisplayHeight != mBaseDisplayHeight
-                    || mInitialDisplayDensity != mBaseDisplayDensity) {
-                pw.print(" base=");
-                pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
-                pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
-            }
-            pw.print(" cur=");
-            pw.print(mDisplayInfo.logicalWidth);
-            pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
-            pw.print(" app=");
-            pw.print(mDisplayInfo.appWidth);
-            pw.print("x"); pw.print(mDisplayInfo.appHeight);
-            pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
-            pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
-            pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
-            pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
-            pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded);
-        for (int boxNdx = 0; boxNdx < mStackBoxes.size(); ++boxNdx) {
-            pw.print(prefix); pw.print("StackBox #"); pw.println(boxNdx);
-            mStackBoxes.get(boxNdx).dump(prefix + "  ", pw);
-        }
-        int ndx = numTokens();
-        if (ndx > 0) {
-            pw.println();
-            pw.println("  Application tokens in Z order:");
-            getTasks();
-            for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
-                AppTokenList tokens = mTaskHistory.get(taskNdx).mAppTokens;
-                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
-                    final AppWindowToken wtoken = tokens.get(tokenNdx);
-                    pw.print("  App #"); pw.print(ndx--);
-                            pw.print(' '); pw.print(wtoken); pw.println(":");
-                    wtoken.dump(pw, "    ");
-                }
-            }
-        }
-        if (mExitingTokens.size() > 0) {
-            pw.println();
-            pw.println("  Exiting tokens:");
-            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);
-                pw.println(':');
-                token.dump(pw, "    ");
-            }
-        }
-        if (mExitingAppTokens.size() > 0) {
-            pw.println();
-            pw.println("  Exiting application tokens:");
-            for (int i=mExitingAppTokens.size()-1; i>=0; i--) {
-                WindowToken token = mExitingAppTokens.get(i);
-                pw.print("  Exiting App #"); pw.print(i);
-                  pw.print(' '); pw.print(token);
-                  pw.println(':');
-                  token.dump(pw, "    ");
-            }
-        }
-        pw.println();
-    }
-}
diff --git a/services/java/com/android/server/wm/FocusedStackFrame.java b/services/java/com/android/server/wm/FocusedStackFrame.java
deleted file mode 100644
index cc48b86..0000000
--- a/services/java/com/android/server/wm/FocusedStackFrame.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2013 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.wm;
-
-import static com.android.server.wm.WindowManagerService.DEBUG_STACK;
-import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.Region;
-import android.util.Slog;
-import android.view.Display;
-import android.view.Surface.OutOfResourcesException;
-import android.view.Surface;
-import android.view.SurfaceControl;
-import android.view.SurfaceSession;
-
-import com.android.server.wm.WindowStateAnimator.SurfaceTrace;
-
-class FocusedStackFrame {
-    private static final String TAG = "FocusedStackFrame";
-    private static final int THICKNESS = 10;
-    private static final float ALPHA = 0.3f;
-
-    private final SurfaceControl mSurfaceControl;
-    private final Surface mSurface = new Surface();
-    private final Rect mLastBounds = new Rect();
-    private final Rect mBounds = new Rect();
-    private final Rect mTmpDrawRect = new Rect();
-
-    public FocusedStackFrame(Display display, SurfaceSession session) {
-        SurfaceControl ctrl = null;
-        try {
-            if (DEBUG_SURFACE_TRACE) {
-                ctrl = new SurfaceTrace(session, "FocusedStackFrame",
-                    1, 1, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
-            } else {
-                ctrl = new SurfaceControl(session, "FocusedStackFrame",
-                    1, 1, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
-            }
-            ctrl.setLayerStack(display.getLayerStack());
-            ctrl.setAlpha(ALPHA);
-            mSurface.copyFrom(ctrl);
-        } catch (OutOfResourcesException e) {
-        }
-        mSurfaceControl = ctrl;
-    }
-
-    private void draw(Rect bounds, int color) {
-        if (false && DEBUG_STACK) Slog.i(TAG, "draw: bounds=" + bounds.toShortString() +
-                " color=" + Integer.toHexString(color));
-        mTmpDrawRect.set(bounds);
-        Canvas c = null;
-        try {
-            c = mSurface.lockCanvas(mTmpDrawRect);
-        } catch (IllegalArgumentException e) {
-        } catch (Surface.OutOfResourcesException e) {
-        }
-        if (c == null) {
-            return;
-        }
-
-        final int w = bounds.width();
-        final int h = bounds.height();
-
-        // Top
-        mTmpDrawRect.set(0, 0, w, THICKNESS);
-        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
-        c.drawColor(color);
-        // Left (not including Top or Bottom stripe).
-        mTmpDrawRect.set(0, THICKNESS, THICKNESS, h - THICKNESS);
-        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
-        c.drawColor(color);
-        // Right (not including Top or Bottom stripe).
-        mTmpDrawRect.set(w - THICKNESS, THICKNESS, w, h - THICKNESS);
-        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
-        c.drawColor(color);
-        // Bottom
-        mTmpDrawRect.set(0, h - THICKNESS, w, h);
-        c.clipRect(mTmpDrawRect, Region.Op.REPLACE);
-        c.drawColor(color);
-
-        mSurface.unlockCanvasAndPost(c);
-    }
-
-    private void positionSurface(Rect bounds) {
-        if (false && DEBUG_STACK) Slog.i(TAG, "positionSurface: bounds=" + bounds.toShortString());
-        mSurfaceControl.setSize(bounds.width(), bounds.height());
-        mSurfaceControl.setPosition(bounds.left, bounds.top);
-    }
-
-    // Note: caller responsible for being inside
-    // Surface.openTransaction() / closeTransaction()
-    public void setVisibility(boolean on) {
-        if (false && DEBUG_STACK) Slog.i(TAG, "setVisibility: on=" + on +
-                " mLastBounds=" + mLastBounds.toShortString() +
-                " mBounds=" + mBounds.toShortString());
-        if (mSurfaceControl == null) {
-            return;
-        }
-        if (on) {
-            if (!mLastBounds.equals(mBounds)) {
-                // Erase the previous rectangle.
-                positionSurface(mLastBounds);
-                draw(mLastBounds, Color.TRANSPARENT);
-                // Draw the latest rectangle.
-                positionSurface(mBounds);
-                draw(mBounds, Color.WHITE);
-                // Update the history.
-                mLastBounds.set(mBounds);
-            }
-            mSurfaceControl.show();
-        } else {
-            mSurfaceControl.hide();
-        }
-    }
-
-    public void setBounds(Rect bounds) {
-        if (false && DEBUG_STACK) Slog.i(TAG, "setBounds: bounds=" + bounds);
-        mBounds.set(bounds);
-    }
-
-    public void setLayer(int layer) {
-        mSurfaceControl.setLayer(layer);
-    }
-}
diff --git a/services/java/com/android/server/wm/InputMonitor.java b/services/java/com/android/server/wm/InputMonitor.java
deleted file mode 100644
index 3d2ec45..0000000
--- a/services/java/com/android/server/wm/InputMonitor.java
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
- * Copyright (C) 2010 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.wm;
-
-import com.android.server.input.InputManagerService;
-import com.android.server.input.InputApplicationHandle;
-import com.android.server.input.InputWindowHandle;
-
-import android.app.ActivityManagerNative;
-import android.graphics.Rect;
-import android.os.RemoteException;
-import android.util.Log;
-import android.util.Slog;
-import android.view.Display;
-import android.view.InputChannel;
-import android.view.KeyEvent;
-import android.view.WindowManager;
-
-import java.util.Arrays;
-
-final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
-    private final WindowManagerService mService;
-    
-    // Current window with input focus for keys and other non-touch events.  May be null.
-    private WindowState mInputFocus;
-    
-    // When true, prevents input dispatch from proceeding until set to false again.
-    private boolean mInputDispatchFrozen;
-    
-    // When true, input dispatch proceeds normally.  Otherwise all events are dropped.
-    // Initially false, so that input does not get dispatched until boot is finished at
-    // which point the ActivityManager will enable dispatching.
-    private boolean mInputDispatchEnabled;
-
-    // When true, need to call updateInputWindowsLw().
-    private boolean mUpdateInputWindowsNeeded = true;
-
-    // Array of window handles to provide to the input dispatcher.
-    private InputWindowHandle[] mInputWindowHandles;
-    private int mInputWindowHandleCount;
-
-    // Set to true when the first input device configuration change notification
-    // is received to indicate that the input devices are ready.
-    private final Object mInputDevicesReadyMonitor = new Object();
-    private boolean mInputDevicesReady;
-
-    public InputMonitor(WindowManagerService service) {
-        mService = service;
-    }
-    
-    /* Notifies the window manager about a broken input channel.
-     * 
-     * Called by the InputManager.
-     */
-    @Override
-    public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
-        if (inputWindowHandle == null) {
-            return;
-        }
-
-        synchronized (mService.mWindowMap) {
-            WindowState windowState = (WindowState) inputWindowHandle.windowState;
-            if (windowState != null) {
-                Slog.i(WindowManagerService.TAG, "WINDOW DIED " + windowState);
-                mService.removeWindowLocked(windowState.mSession, windowState);
-            }
-        }
-    }
-    
-    /* Notifies the window manager about an application that is not responding.
-     * Returns a new timeout to continue waiting in nanoseconds, or 0 to abort dispatch.
-     * 
-     * Called by the InputManager.
-     */
-    @Override
-    public long notifyANR(InputApplicationHandle inputApplicationHandle,
-            InputWindowHandle inputWindowHandle, String reason) {
-        AppWindowToken appWindowToken = null;
-        WindowState windowState = null;
-        boolean aboveSystem = false;
-        synchronized (mService.mWindowMap) {
-            if (inputWindowHandle != null) {
-                windowState = (WindowState) inputWindowHandle.windowState;
-                if (windowState != null) {
-                    appWindowToken = windowState.mAppToken;
-                }
-            }
-            if (appWindowToken == null && inputApplicationHandle != null) {
-                appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
-            }
-
-            if (windowState != null) {
-                Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
-                        + "sending to " + windowState.mAttrs.getTitle()
-                        + ".  Reason: " + reason);
-                // Figure out whether this window is layered above system windows.
-                // We need to do this here to help the activity manager know how to
-                // layer its ANR dialog.
-                int systemAlertLayer = mService.mPolicy.windowTypeToLayerLw(
-                        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
-                aboveSystem = windowState.mBaseLayer > systemAlertLayer;
-            } else if (appWindowToken != null) {
-                Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
-                        + "sending to application " + appWindowToken.stringName
-                        + ".  Reason: " + reason);
-            } else {
-                Slog.i(WindowManagerService.TAG, "Input event dispatching timed out "
-                        + ".  Reason: " + reason);
-            }
-
-            mService.saveANRStateLocked(appWindowToken, windowState, reason);
-        }
-
-        if (appWindowToken != null && appWindowToken.appToken != null) {
-            try {
-                // Notify the activity manager about the timeout and let it decide whether
-                // to abort dispatching or keep waiting.
-                boolean abort = appWindowToken.appToken.keyDispatchingTimedOut(reason);
-                if (! abort) {
-                    // The activity manager declined to abort dispatching.
-                    // Wait a bit longer and timeout again later.
-                    return appWindowToken.inputDispatchingTimeoutNanos;
-                }
-            } catch (RemoteException ex) {
-            }
-        } else if (windowState != null) {
-            try {
-                // Notify the activity manager about the timeout and let it decide whether
-                // to abort dispatching or keep waiting.
-                long timeout = ActivityManagerNative.getDefault().inputDispatchingTimedOut(
-                        windowState.mSession.mPid, aboveSystem, reason);
-                if (timeout >= 0) {
-                    // The activity manager declined to abort dispatching.
-                    // Wait a bit longer and timeout again later.
-                    return timeout;
-                }
-            } catch (RemoteException ex) {
-            }
-        }
-        return 0; // abort dispatching
-    }
-
-    private void addInputWindowHandleLw(final InputWindowHandle windowHandle) {
-        if (mInputWindowHandles == null) {
-            mInputWindowHandles = new InputWindowHandle[16];
-        }
-        if (mInputWindowHandleCount >= mInputWindowHandles.length) {
-            mInputWindowHandles = Arrays.copyOf(mInputWindowHandles,
-                    mInputWindowHandleCount * 2);
-        }
-        mInputWindowHandles[mInputWindowHandleCount++] = windowHandle;
-    }
-
-    private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle,
-            final WindowState child, int flags, int privateFlags, final int type,
-            final boolean isVisible, final boolean hasFocus, final boolean hasWallpaper) {
-        // Add a window to our list of input windows.
-        inputWindowHandle.name = child.toString();
-        final boolean modal = (flags & (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
-                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)) == 0;
-        if (modal && child.mAppToken != null) {
-            // Limit the outer touch to the activity stack region.
-            flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
-            inputWindowHandle.touchableRegion.set(child.getStackBounds());
-        } else {
-            // Not modal or full screen modal
-            child.getTouchableRegion(inputWindowHandle.touchableRegion);
-        }
-        inputWindowHandle.layoutParamsFlags = flags;
-        inputWindowHandle.layoutParamsPrivateFlags = privateFlags;
-        inputWindowHandle.layoutParamsType = type;
-        inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
-        inputWindowHandle.visible = isVisible;
-        inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
-        inputWindowHandle.hasFocus = hasFocus;
-        inputWindowHandle.hasWallpaper = hasWallpaper;
-        inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
-        inputWindowHandle.layer = child.mLayer;
-        inputWindowHandle.ownerPid = child.mSession.mPid;
-        inputWindowHandle.ownerUid = child.mSession.mUid;
-        inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
-
-        final Rect frame = child.mFrame;
-        inputWindowHandle.frameLeft = frame.left;
-        inputWindowHandle.frameTop = frame.top;
-        inputWindowHandle.frameRight = frame.right;
-        inputWindowHandle.frameBottom = frame.bottom;
-
-        if (child.mGlobalScale != 1) {
-            // If we are scaling the window, input coordinates need
-            // to be inversely scaled to map from what is on screen
-            // to what is actually being touched in the UI.
-            inputWindowHandle.scaleFactor = 1.0f/child.mGlobalScale;
-        } else {
-            inputWindowHandle.scaleFactor = 1;
-        }
-
-
-        addInputWindowHandleLw(inputWindowHandle);
-    }
-
-    private void clearInputWindowHandlesLw() {
-        while (mInputWindowHandleCount != 0) {
-            mInputWindowHandles[--mInputWindowHandleCount] = null;
-        }
-    }
-
-    public void setUpdateInputWindowsNeededLw() {
-        mUpdateInputWindowsNeeded = true;
-    }
-
-    /* Updates the cached window information provided to the input dispatcher. */
-    public void updateInputWindowsLw(boolean force) {
-        if (!force && !mUpdateInputWindowsNeeded) {
-            return;
-        }
-        mUpdateInputWindowsNeeded = false;
-
-        if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED updateInputWindowsLw");
-
-        // Populate the input window list with information about all of the windows that
-        // could potentially receive input.
-        // As an optimization, we could try to prune the list of windows but this turns
-        // out to be difficult because only the native code knows for sure which window
-        // currently has touch focus.
-        final WindowStateAnimator universeBackground = mService.mAnimator.mUniverseBackground;
-        final int aboveUniverseLayer = mService.mAnimator.mAboveUniverseLayer;
-        boolean addedUniverse = false;
-
-        // If there's a drag in flight, provide a pseudowindow to catch drag input
-        final boolean inDrag = (mService.mDragState != null);
-        if (inDrag) {
-            if (WindowManagerService.DEBUG_DRAG) {
-                Log.d(WindowManagerService.TAG, "Inserting drag window");
-            }
-            final InputWindowHandle dragWindowHandle = mService.mDragState.mDragWindowHandle;
-            if (dragWindowHandle != null) {
-                addInputWindowHandleLw(dragWindowHandle);
-            } else {
-                Slog.w(WindowManagerService.TAG, "Drag is in progress but there is no "
-                        + "drag window handle.");
-            }
-        }
-
-        final int NFW = mService.mFakeWindows.size();
-        for (int i = 0; i < NFW; i++) {
-            addInputWindowHandleLw(mService.mFakeWindows.get(i).mWindowHandle);
-        }
-
-        // Add all windows on the default display.
-        final int numDisplays = mService.mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            WindowList windows = mService.mDisplayContents.valueAt(displayNdx).getWindowList();
-            for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
-                final WindowState child = windows.get(winNdx);
-                final InputChannel inputChannel = child.mInputChannel;
-                final InputWindowHandle inputWindowHandle = child.mInputWindowHandle;
-                if (inputChannel == null || inputWindowHandle == null || child.mRemoved) {
-                    // Skip this window because it cannot possibly receive input.
-                    continue;
-                }
-
-                final int flags = child.mAttrs.flags;
-                final int privateFlags = child.mAttrs.privateFlags;
-                final int type = child.mAttrs.type;
-
-                final boolean hasFocus = (child == mInputFocus);
-                final boolean isVisible = child.isVisibleLw();
-                final boolean hasWallpaper = (child == mService.mWallpaperTarget)
-                        && (type != WindowManager.LayoutParams.TYPE_KEYGUARD);
-                final boolean onDefaultDisplay = (child.getDisplayId() == Display.DEFAULT_DISPLAY);
-
-                // If there's a drag in progress and 'child' is a potential drop target,
-                // make sure it's been told about the drag
-                if (inDrag && isVisible && onDefaultDisplay) {
-                    mService.mDragState.sendDragStartedIfNeededLw(child);
-                }
-
-                if (universeBackground != null && !addedUniverse
-                        && child.mBaseLayer < aboveUniverseLayer && onDefaultDisplay) {
-                    final WindowState u = universeBackground.mWin;
-                    if (u.mInputChannel != null && u.mInputWindowHandle != null) {
-                        addInputWindowHandleLw(u.mInputWindowHandle, u, u.mAttrs.flags,
-                                u.mAttrs.privateFlags, u.mAttrs.type,
-                                true, u == mInputFocus, false);
-                    }
-                    addedUniverse = true;
-                }
-
-                if (child.mWinAnimator != universeBackground) {
-                    addInputWindowHandleLw(inputWindowHandle, child, flags, privateFlags, type,
-                            isVisible, hasFocus, hasWallpaper);
-                }
-            }
-        }
-
-        // Send windows to native code.
-        mService.mInputManager.setInputWindows(mInputWindowHandles);
-
-        // Clear the list in preparation for the next round.
-        clearInputWindowHandlesLw();
-
-        if (false) Slog.d(WindowManagerService.TAG, "<<<<<<< EXITED updateInputWindowsLw");
-    }
-
-    /* Notifies that the input device configuration has changed. */
-    @Override
-    public void notifyConfigurationChanged() {
-        mService.sendNewConfiguration();
-
-        synchronized (mInputDevicesReadyMonitor) {
-            if (!mInputDevicesReady) {
-                mInputDevicesReady = true;
-                mInputDevicesReadyMonitor.notifyAll();
-            }
-        }
-    }
-
-    /* Waits until the built-in input devices have been configured. */
-    public boolean waitForInputDevicesReady(long timeoutMillis) {
-        synchronized (mInputDevicesReadyMonitor) {
-            if (!mInputDevicesReady) {
-                try {
-                    mInputDevicesReadyMonitor.wait(timeoutMillis);
-                } catch (InterruptedException ex) {
-                }
-            }
-            return mInputDevicesReady;
-        }
-    }
-
-    /* Notifies that the lid switch changed state. */
-    @Override
-    public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
-        mService.mPolicy.notifyLidSwitchChanged(whenNanos, lidOpen);
-    }
-
-    /* Provides an opportunity for the window manager policy to intercept early key
-     * processing as soon as the key has been read from the device. */
-    @Override
-    public int interceptKeyBeforeQueueing(
-            KeyEvent event, int policyFlags, boolean isScreenOn) {
-        return mService.mPolicy.interceptKeyBeforeQueueing(event, policyFlags, isScreenOn);
-    }
-
-    /* Provides an opportunity for the window manager policy to intercept early
-     * motion event processing when the screen is off since these events are normally
-     * dropped. */
-    @Override
-    public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
-        return mService.mPolicy.interceptMotionBeforeQueueingWhenScreenOff(policyFlags);
-    }
-
-    /* Provides an opportunity for the window manager policy to process a key before
-     * ordinary dispatch. */
-    @Override
-    public long interceptKeyBeforeDispatching(
-            InputWindowHandle focus, KeyEvent event, int policyFlags) {
-        WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
-        return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
-    }
-
-    /* Provides an opportunity for the window manager policy to process a key that
-     * the application did not handle. */
-    @Override
-    public KeyEvent dispatchUnhandledKey(
-            InputWindowHandle focus, KeyEvent event, int policyFlags) {
-        WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
-        return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
-    }
-
-    /* Callback to get pointer layer. */
-    @Override
-    public int getPointerLayer() {
-        return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER)
-                * WindowManagerService.TYPE_LAYER_MULTIPLIER
-                + WindowManagerService.TYPE_LAYER_OFFSET;
-    }
-
-    /* Called when the current input focus changes.
-     * Layer assignment is assumed to be complete by the time this is called.
-     */
-    public void setInputFocusLw(WindowState newWindow, boolean updateInputWindows) {
-        if (WindowManagerService.DEBUG_FOCUS_LIGHT || WindowManagerService.DEBUG_INPUT) {
-            Slog.d(WindowManagerService.TAG, "Input focus has changed to " + newWindow);
-        }
-
-        if (newWindow != mInputFocus) {
-            if (newWindow != null && newWindow.canReceiveKeys()) {
-                // Displaying a window implicitly causes dispatching to be unpaused.
-                // This is to protect against bugs if someone pauses dispatching but
-                // forgets to resume.
-                newWindow.mToken.paused = false;
-            }
-
-            mInputFocus = newWindow;
-            setUpdateInputWindowsNeededLw();
-
-            if (updateInputWindows) {
-                updateInputWindowsLw(false /*force*/);
-            }
-        }
-    }
-
-    public void setFocusedAppLw(AppWindowToken newApp) {
-        // Focused app has changed.
-        if (newApp == null) {
-            mService.mInputManager.setFocusedApplication(null);
-        } else {
-            final InputApplicationHandle handle = newApp.mInputApplicationHandle;
-            handle.name = newApp.toString();
-            handle.dispatchingTimeoutNanos = newApp.inputDispatchingTimeoutNanos;
-
-            mService.mInputManager.setFocusedApplication(handle);
-        }
-    }
-
-    public void pauseDispatchingLw(WindowToken window) {
-        if (! window.paused) {
-            if (WindowManagerService.DEBUG_INPUT) {
-                Slog.v(WindowManagerService.TAG, "Pausing WindowToken " + window);
-            }
-            
-            window.paused = true;
-            updateInputWindowsLw(true /*force*/);
-        }
-    }
-    
-    public void resumeDispatchingLw(WindowToken window) {
-        if (window.paused) {
-            if (WindowManagerService.DEBUG_INPUT) {
-                Slog.v(WindowManagerService.TAG, "Resuming WindowToken " + window);
-            }
-            
-            window.paused = false;
-            updateInputWindowsLw(true /*force*/);
-        }
-    }
-    
-    public void freezeInputDispatchingLw() {
-        if (! mInputDispatchFrozen) {
-            if (WindowManagerService.DEBUG_INPUT) {
-                Slog.v(WindowManagerService.TAG, "Freezing input dispatching");
-            }
-            
-            mInputDispatchFrozen = true;
-            updateInputDispatchModeLw();
-        }
-    }
-    
-    public void thawInputDispatchingLw() {
-        if (mInputDispatchFrozen) {
-            if (WindowManagerService.DEBUG_INPUT) {
-                Slog.v(WindowManagerService.TAG, "Thawing input dispatching");
-            }
-            
-            mInputDispatchFrozen = false;
-            updateInputDispatchModeLw();
-        }
-    }
-    
-    public void setEventDispatchingLw(boolean enabled) {
-        if (mInputDispatchEnabled != enabled) {
-            if (WindowManagerService.DEBUG_INPUT) {
-                Slog.v(WindowManagerService.TAG, "Setting event dispatching to " + enabled);
-            }
-            
-            mInputDispatchEnabled = enabled;
-            updateInputDispatchModeLw();
-        }
-    }
-    
-    private void updateInputDispatchModeLw() {
-        mService.mInputManager.setInputDispatchMode(mInputDispatchEnabled, mInputDispatchFrozen);
-    }
-}
diff --git a/services/java/com/android/server/wm/Session.java b/services/java/com/android/server/wm/Session.java
deleted file mode 100644
index 87cabc9..0000000
--- a/services/java/com/android/server/wm/Session.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.server.wm;
-
-import android.view.IWindowId;
-import com.android.internal.view.IInputContext;
-import com.android.internal.view.IInputMethodClient;
-import com.android.internal.view.IInputMethodManager;
-import com.android.server.wm.WindowManagerService.H;
-
-import android.content.ClipData;
-import android.content.Context;
-import android.content.res.Configuration;
-import android.graphics.Rect;
-import android.graphics.Region;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.util.Slog;
-import android.view.Display;
-import android.view.IWindow;
-import android.view.IWindowSession;
-import android.view.InputChannel;
-import android.view.Surface;
-import android.view.SurfaceControl;
-import android.view.SurfaceSession;
-import android.view.WindowManager;
-
-import java.io.PrintWriter;
-
-/**
- * This class represents an active client session.  There is generally one
- * Session object per process that is interacting with the window manager.
- */
-final class Session extends IWindowSession.Stub
-        implements IBinder.DeathRecipient {
-    final WindowManagerService mService;
-    final IInputMethodClient mClient;
-    final IInputContext mInputContext;
-    final int mUid;
-    final int mPid;
-    final String mStringName;
-    SurfaceSession mSurfaceSession;
-    int mNumWindow = 0;
-    boolean mClientDead = false;
-
-    public Session(WindowManagerService service, IInputMethodClient client,
-            IInputContext inputContext) {
-        mService = service;
-        mClient = client;
-        mInputContext = inputContext;
-        mUid = Binder.getCallingUid();
-        mPid = Binder.getCallingPid();
-        StringBuilder sb = new StringBuilder();
-        sb.append("Session{");
-        sb.append(Integer.toHexString(System.identityHashCode(this)));
-        sb.append(" ");
-        sb.append(mPid);
-        if (mUid < Process.FIRST_APPLICATION_UID) {
-            sb.append(":");
-            sb.append(mUid);
-        } else {
-            sb.append(":u");
-            sb.append(UserHandle.getUserId(mUid));
-            sb.append('a');
-            sb.append(UserHandle.getAppId(mUid));
-        }
-        sb.append("}");
-        mStringName = sb.toString();
-
-        synchronized (mService.mWindowMap) {
-            if (mService.mInputMethodManager == null && mService.mHaveInputMethods) {
-                IBinder b = ServiceManager.getService(
-                        Context.INPUT_METHOD_SERVICE);
-                mService.mInputMethodManager = IInputMethodManager.Stub.asInterface(b);
-            }
-        }
-        long ident = Binder.clearCallingIdentity();
-        try {
-            // Note: it is safe to call in to the input method manager
-            // here because we are not holding our lock.
-            if (mService.mInputMethodManager != null) {
-                mService.mInputMethodManager.addClient(client, inputContext,
-                        mUid, mPid);
-            } else {
-                client.setUsingInputMethod(false);
-            }
-            client.asBinder().linkToDeath(this, 0);
-        } catch (RemoteException e) {
-            // The caller has died, so we can just forget about this.
-            try {
-                if (mService.mInputMethodManager != null) {
-                    mService.mInputMethodManager.removeClient(client);
-                }
-            } catch (RemoteException ee) {
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
-            throws RemoteException {
-        try {
-            return super.onTransact(code, data, reply, flags);
-        } catch (RuntimeException e) {
-            // Log all 'real' exceptions thrown to the caller
-            if (!(e instanceof SecurityException)) {
-                Slog.wtf(WindowManagerService.TAG, "Window Session Crash", e);
-            }
-            throw e;
-        }
-    }
-
-    public void binderDied() {
-        // Note: it is safe to call in to the input method manager
-        // here because we are not holding our lock.
-        try {
-            if (mService.mInputMethodManager != null) {
-                mService.mInputMethodManager.removeClient(mClient);
-            }
-        } catch (RemoteException e) {
-        }
-        synchronized(mService.mWindowMap) {
-            mClient.asBinder().unlinkToDeath(this, 0);
-            mClientDead = true;
-            killSessionLocked();
-        }
-    }
-
-    @Override
-    public int add(IWindow window, int seq, WindowManager.LayoutParams attrs,
-            int viewVisibility, Rect outContentInsets, InputChannel outInputChannel) {
-        return addToDisplay(window, seq, attrs, viewVisibility, Display.DEFAULT_DISPLAY,
-                outContentInsets, outInputChannel);
-    }
-
-    @Override
-    public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
-            int viewVisibility, int displayId, Rect outContentInsets,
-            InputChannel outInputChannel) {
-        return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
-                outContentInsets, outInputChannel);
-    }
-
-    @Override
-    public int addWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
-            int viewVisibility, Rect outContentInsets) {
-        return addToDisplayWithoutInputChannel(window, seq, attrs, viewVisibility,
-                Display.DEFAULT_DISPLAY, outContentInsets);
-    }
-
-    @Override
-    public int addToDisplayWithoutInputChannel(IWindow window, int seq, WindowManager.LayoutParams attrs,
-            int viewVisibility, int displayId, Rect outContentInsets) {
-        return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
-            outContentInsets, null);
-    }
-
-    public void remove(IWindow window) {
-        mService.removeWindow(this, window);
-    }
-
-    public int relayout(IWindow window, int seq, WindowManager.LayoutParams attrs,
-            int requestedWidth, int requestedHeight, int viewFlags,
-            int flags, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
-            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
-        if (false) Slog.d(WindowManagerService.TAG, ">>>>>> ENTERED relayout from "
-                + Binder.getCallingPid());
-        int res = mService.relayoutWindow(this, window, seq, attrs,
-                requestedWidth, requestedHeight, viewFlags, flags,
-                outFrame, outOverscanInsets, outContentInsets, outVisibleInsets,
-                outConfig, outSurface);
-        if (false) Slog.d(WindowManagerService.TAG, "<<<<<< EXITING relayout to "
-                + Binder.getCallingPid());
-        return res;
-    }
-
-    public void performDeferredDestroy(IWindow window) {
-        mService.performDeferredDestroyWindow(this, window);
-    }
-
-    public boolean outOfMemory(IWindow window) {
-        return mService.outOfMemoryWindow(this, window);
-    }
-
-    public void setTransparentRegion(IWindow window, Region region) {
-        mService.setTransparentRegionWindow(this, window, region);
-    }
-
-    public void setInsets(IWindow window, int touchableInsets,
-            Rect contentInsets, Rect visibleInsets, Region touchableArea) {
-        mService.setInsetsWindow(this, window, touchableInsets, contentInsets,
-                visibleInsets, touchableArea);
-    }
-
-    public void getDisplayFrame(IWindow window, Rect outDisplayFrame) {
-        mService.getWindowDisplayFrame(this, window, outDisplayFrame);
-    }
-
-    public void finishDrawing(IWindow window) {
-        if (WindowManagerService.localLOGV) Slog.v(
-            WindowManagerService.TAG, "IWindow finishDrawing called for " + window);
-        mService.finishDrawingWindow(this, window);
-    }
-
-    public void setInTouchMode(boolean mode) {
-        synchronized(mService.mWindowMap) {
-            mService.mInTouchMode = mode;
-        }
-    }
-
-    public boolean getInTouchMode() {
-        synchronized(mService.mWindowMap) {
-            return mService.mInTouchMode;
-        }
-    }
-
-    public boolean performHapticFeedback(IWindow window, int effectId,
-            boolean always) {
-        synchronized(mService.mWindowMap) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                return mService.mPolicy.performHapticFeedbackLw(
-                        mService.windowForClientLocked(this, window, true),
-                        effectId, always);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    /* Drag/drop */
-    public IBinder prepareDrag(IWindow window, int flags,
-            int width, int height, Surface outSurface) {
-        return mService.prepareDragSurface(window, mSurfaceSession, flags,
-                width, height, outSurface);
-    }
-
-    public boolean performDrag(IWindow window, IBinder dragToken,
-            float touchX, float touchY, float thumbCenterX, float thumbCenterY,
-            ClipData data) {
-        if (WindowManagerService.DEBUG_DRAG) {
-            Slog.d(WindowManagerService.TAG, "perform drag: win=" + window + " data=" + data);
-        }
-
-        synchronized (mService.mWindowMap) {
-            if (mService.mDragState == null) {
-                Slog.w(WindowManagerService.TAG, "No drag prepared");
-                throw new IllegalStateException("performDrag() without prepareDrag()");
-            }
-
-            if (dragToken != mService.mDragState.mToken) {
-                Slog.w(WindowManagerService.TAG, "Performing mismatched drag");
-                throw new IllegalStateException("performDrag() does not match prepareDrag()");
-            }
-
-            WindowState callingWin = mService.windowForClientLocked(null, window, false);
-            if (callingWin == null) {
-                Slog.w(WindowManagerService.TAG, "Bad requesting window " + window);
-                return false;  // !!! TODO: throw here?
-            }
-
-            // !!! TODO: if input is not still focused on the initiating window, fail
-            // the drag initiation (e.g. an alarm window popped up just as the application
-            // called performDrag()
-
-            mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
-
-            // !!! TODO: extract the current touch (x, y) in screen coordinates.  That
-            // will let us eliminate the (touchX,touchY) parameters from the API.
-
-            // !!! FIXME: put all this heavy stuff onto the mH looper, as well as
-            // the actual drag event dispatch stuff in the dragstate
-
-            Display display = callingWin.mDisplayContent.getDisplay();
-            mService.mDragState.register(display);
-            mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
-            if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel,
-                    mService.mDragState.mServerChannel)) {
-                Slog.e(WindowManagerService.TAG, "Unable to transfer touch focus");
-                mService.mDragState.unregister();
-                mService.mDragState = null;
-                mService.mInputMonitor.updateInputWindowsLw(true /*force*/);
-                return false;
-            }
-
-            mService.mDragState.mData = data;
-            mService.mDragState.mCurrentX = touchX;
-            mService.mDragState.mCurrentY = touchY;
-            mService.mDragState.broadcastDragStartedLw(touchX, touchY);
-
-            // remember the thumb offsets for later
-            mService.mDragState.mThumbOffsetX = thumbCenterX;
-            mService.mDragState.mThumbOffsetY = thumbCenterY;
-
-            // Make the surface visible at the proper location
-            final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
-            if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
-                    WindowManagerService.TAG, ">>> OPEN TRANSACTION performDrag");
-            SurfaceControl.openTransaction();
-            try {
-                surfaceControl.setPosition(touchX - thumbCenterX,
-                        touchY - thumbCenterY);
-                surfaceControl.setAlpha(.7071f);
-                surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
-                surfaceControl.setLayerStack(display.getLayerStack());
-                surfaceControl.show();
-            } finally {
-                SurfaceControl.closeTransaction();
-                if (WindowManagerService.SHOW_LIGHT_TRANSACTIONS) Slog.i(
-                        WindowManagerService.TAG, "<<< CLOSE TRANSACTION performDrag");
-            }
-        }
-
-        return true;    // success!
-    }
-
-    public void reportDropResult(IWindow window, boolean consumed) {
-        IBinder token = window.asBinder();
-        if (WindowManagerService.DEBUG_DRAG) {
-            Slog.d(WindowManagerService.TAG, "Drop result=" + consumed + " reported by " + token);
-        }
-
-        synchronized (mService.mWindowMap) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                if (mService.mDragState == null) {
-                    // Most likely the drop recipient ANRed and we ended the drag
-                    // out from under it.  Log the issue and move on.
-                    Slog.w(WindowManagerService.TAG, "Drop result given but no drag in progress");
-                    return;
-                }
-
-                if (mService.mDragState.mToken != token) {
-                    // We're in a drag, but the wrong window has responded.
-                    Slog.w(WindowManagerService.TAG, "Invalid drop-result claim by " + window);
-                    throw new IllegalStateException("reportDropResult() by non-recipient");
-                }
-
-                // The right window has responded, even if it's no longer around,
-                // so be sure to halt the timeout even if the later WindowState
-                // lookup fails.
-                mService.mH.removeMessages(H.DRAG_END_TIMEOUT, window.asBinder());
-                WindowState callingWin = mService.windowForClientLocked(null, window, false);
-                if (callingWin == null) {
-                    Slog.w(WindowManagerService.TAG, "Bad result-reporting window " + window);
-                    return;  // !!! TODO: throw here?
-                }
-
-                mService.mDragState.mDragResult = consumed;
-                mService.mDragState.endDragLw();
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void dragRecipientEntered(IWindow window) {
-        if (WindowManagerService.DEBUG_DRAG) {
-            Slog.d(WindowManagerService.TAG, "Drag into new candidate view @ " + window.asBinder());
-        }
-    }
-
-    public void dragRecipientExited(IWindow window) {
-        if (WindowManagerService.DEBUG_DRAG) {
-            Slog.d(WindowManagerService.TAG, "Drag from old candidate view @ " + window.asBinder());
-        }
-    }
-
-    public void setWallpaperPosition(IBinder window, float x, float y, float xStep, float yStep) {
-        synchronized(mService.mWindowMap) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                mService.setWindowWallpaperPositionLocked(
-                        mService.windowForClientLocked(this, window, true),
-                        x, y, xStep, yStep);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void wallpaperOffsetsComplete(IBinder window) {
-        mService.wallpaperOffsetsComplete(window);
-    }
-
-    public Bundle sendWallpaperCommand(IBinder window, String action, int x, int y,
-            int z, Bundle extras, boolean sync) {
-        synchronized(mService.mWindowMap) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                return mService.sendWindowWallpaperCommandLocked(
-                        mService.windowForClientLocked(this, window, true),
-                        action, x, y, z, extras, sync);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void wallpaperCommandComplete(IBinder window, Bundle result) {
-        mService.wallpaperCommandComplete(window, result);
-    }
-
-    public void setUniverseTransform(IBinder window, float alpha, float offx, float offy,
-            float dsdx, float dtdx, float dsdy, float dtdy) {
-        synchronized(mService.mWindowMap) {
-            long ident = Binder.clearCallingIdentity();
-            try {
-                mService.setUniverseTransformLocked(
-                        mService.windowForClientLocked(this, window, true),
-                        alpha, offx, offy, dsdx, dtdx, dsdy, dtdy);
-            } finally {
-                Binder.restoreCallingIdentity(ident);
-            }
-        }
-    }
-
-    public void onRectangleOnScreenRequested(IBinder token, Rect rectangle, boolean immediate) {
-        synchronized(mService.mWindowMap) {
-            final long identity = Binder.clearCallingIdentity();
-            try {
-                mService.onRectangleOnScreenRequested(token, rectangle, immediate);
-            } finally {
-                Binder.restoreCallingIdentity(identity);
-            }
-        }
-    }
-
-    public IWindowId getWindowId(IBinder window) {
-        return mService.getWindowId(window);
-    }
-
-    void windowAddedLocked() {
-        if (mSurfaceSession == null) {
-            if (WindowManagerService.localLOGV) Slog.v(
-                WindowManagerService.TAG, "First window added to " + this + ", creating SurfaceSession");
-            mSurfaceSession = new SurfaceSession();
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
-                    WindowManagerService.TAG, "  NEW SURFACE SESSION " + mSurfaceSession);
-            mService.mSessions.add(this);
-        }
-        mNumWindow++;
-    }
-
-    void windowRemovedLocked() {
-        mNumWindow--;
-        killSessionLocked();
-    }
-
-    void killSessionLocked() {
-        if (mNumWindow <= 0 && mClientDead) {
-            mService.mSessions.remove(this);
-            if (mSurfaceSession != null) {
-                if (WindowManagerService.localLOGV) Slog.v(
-                    WindowManagerService.TAG, "Last window removed from " + this
-                    + ", destroying " + mSurfaceSession);
-                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
-                        WindowManagerService.TAG, "  KILL SURFACE SESSION " + mSurfaceSession);
-                try {
-                    mSurfaceSession.kill();
-                } catch (Exception e) {
-                    Slog.w(WindowManagerService.TAG, "Exception thrown when killing surface session "
-                        + mSurfaceSession + " in session " + this
-                        + ": " + e.toString());
-                }
-                mSurfaceSession = null;
-            }
-        }
-    }
-
-    void dump(PrintWriter pw, String prefix) {
-        pw.print(prefix); pw.print("mNumWindow="); pw.print(mNumWindow);
-                pw.print(" mClientDead="); pw.print(mClientDead);
-                pw.print(" mSurfaceSession="); pw.println(mSurfaceSession);
-    }
-
-    @Override
-    public String toString() {
-        return mStringName;
-    }
-}
\ No newline at end of file
diff --git a/services/java/com/android/server/wm/StackBox.java b/services/java/com/android/server/wm/StackBox.java
deleted file mode 100644
index d351925..0000000
--- a/services/java/com/android/server/wm/StackBox.java
+++ /dev/null
@@ -1,414 +0,0 @@
-/*
- * Copyright (C) 2013 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.wm;
-
-import android.graphics.Rect;
-import android.util.Slog;
-
-import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
-import static com.android.server.wm.WindowManagerService.DEBUG_STACK;
-import static com.android.server.wm.WindowManagerService.TAG;
-
-import java.io.PrintWriter;
-
-public class StackBox {
-    /** Used with {@link WindowManagerService#createStack}. Dependent on Configuration LTR/RTL. */
-    public static final int TASK_STACK_GOES_BEFORE = 0;
-    /** Used with {@link WindowManagerService#createStack}. Dependent on Configuration LTR/RTL. */
-    public static final int TASK_STACK_GOES_AFTER = 1;
-    /** Used with {@link WindowManagerService#createStack}. Horizontal to left of. */
-    public static final int TASK_STACK_TO_LEFT_OF = 2;
-    /** Used with {@link WindowManagerService#createStack}. Horizontal to right of. */
-    public static final int TASK_STACK_TO_RIGHT_OF = 3;
-    /** Used with {@link WindowManagerService#createStack}. Vertical: lower t/b Rect values. */
-    public static final int TASK_STACK_GOES_ABOVE = 4;
-    /** Used with {@link WindowManagerService#createStack}. Vertical: higher t/b Rect values. */
-    public static final int TASK_STACK_GOES_BELOW = 5;
-    /** Used with {@link WindowManagerService#createStack}. Put on a higher layer on display. */
-    public static final int TASK_STACK_GOES_OVER = 6;
-    /** Used with {@link WindowManagerService#createStack}. Put on a lower layer on display. */
-    public static final int TASK_STACK_GOES_UNDER = 7;
-
-    static int sCurrentBoxId = 0;
-
-    /** Unique id for this box */
-    final int mStackBoxId;
-
-    /** The service */
-    final WindowManagerService mService;
-
-    /** The display this box sits in. */
-    final DisplayContent mDisplayContent;
-
-    /** Non-null indicates this is mFirst or mSecond of a parent StackBox. Null indicates this
-     * is this entire size of mDisplayContent. */
-    StackBox mParent;
-
-    /** First child, this is null exactly when mStack is non-null. */
-    StackBox mFirst;
-
-    /** Second child, this is null exactly when mStack is non-null. */
-    StackBox mSecond;
-
-    /** Stack of Tasks, this is null exactly when mFirst and mSecond are non-null. */
-    TaskStack mStack;
-
-    /** Content limits relative to the DisplayContent this sits in. */
-    Rect mBounds = new Rect();
-
-    /** Relative orientation of mFirst and mSecond. */
-    boolean mVertical;
-
-    /** Fraction of mBounds to devote to mFirst, remainder goes to mSecond */
-    float mWeight;
-
-    /** Dirty flag. Something inside this or some descendant of this has changed. */
-    boolean layoutNeeded;
-
-    /** True if this StackBox sits below the Status Bar. */
-    boolean mUnderStatusBar;
-
-    /** Used to keep from reallocating a temporary Rect for propagating bounds to child boxes */
-    Rect mTmpRect = new Rect();
-
-    StackBox(WindowManagerService service, DisplayContent displayContent, StackBox parent) {
-        synchronized (StackBox.class) {
-            mStackBoxId = sCurrentBoxId++;
-        }
-
-        mService = service;
-        mDisplayContent = displayContent;
-        mParent = parent;
-    }
-
-    /** Propagate #layoutNeeded bottom up. */
-    void makeDirty() {
-        layoutNeeded = true;
-        if (mParent != null) {
-            mParent.makeDirty();
-        }
-    }
-
-    /**
-     * Determine if a particular StackBox is this one or a descendant of this one.
-     * @param stackBoxId The StackBox being searched for.
-     * @return true if the specified StackBox matches this or one of its descendants.
-     */
-    boolean contains(int stackBoxId) {
-        return mStackBoxId == stackBoxId ||
-                (mStack == null &&  (mFirst.contains(stackBoxId) || mSecond.contains(stackBoxId)));
-    }
-
-    /**
-     * Return the stackId of the stack that intersects the passed point.
-     * @param x coordinate of point.
-     * @param y coordinate of point.
-     * @return -1 if point is outside of mBounds, otherwise the stackId of the containing stack.
-     */
-    int stackIdFromPoint(int x, int y) {
-        if (!mBounds.contains(x, y)) {
-            return -1;
-        }
-        if (mStack != null) {
-            return mStack.mStackId;
-        }
-        int stackId = mFirst.stackIdFromPoint(x, y);
-        if (stackId >= 0) {
-            return stackId;
-        }
-        return mSecond.stackIdFromPoint(x, y);
-    }
-
-    /** Determine if this StackBox is the first child or second child.
-     * @return true if this is the first child.
-     */
-    boolean isFirstChild() {
-        return mParent != null && mParent.mFirst == this;
-    }
-
-    /** Returns the bounds of the specified TaskStack if it is contained in this StackBox.
-     * @param stackId the TaskStack to find the bounds of.
-     * @return a new Rect with the bounds of stackId if it is within this StackBox, null otherwise.
-     */
-    Rect getStackBounds(int stackId) {
-        if (mStack != null) {
-            return mStack.mStackId == stackId ? new Rect(mBounds) : null;
-        }
-        Rect bounds = mFirst.getStackBounds(stackId);
-        if (bounds != null) {
-            return bounds;
-        }
-        return mSecond.getStackBounds(stackId);
-    }
-
-    /**
-     * Create a new TaskStack relative to a specified one by splitting the StackBox containing
-     * the specified TaskStack into two children. The size and position each of the new StackBoxes
-     * is determined by the passed parameters.
-     * @param stackId The id of the new TaskStack to create.
-     * @param relativeStackBoxId The id of the StackBox to place the new TaskStack next to.
-     * @param position One of the static TASK_STACK_GOES_xxx positions defined in this class.
-     * @param weight The percentage size of the parent StackBox to devote to the new TaskStack.
-     * @return The new TaskStack.
-     */
-    TaskStack split(int stackId, int relativeStackBoxId, int position, float weight) {
-        if (mStackBoxId != relativeStackBoxId) {
-            // This is not the targeted StackBox.
-            if (mStack != null) {
-                return null;
-            }
-            // Propagate the split to see if the targeted StackBox is in either sub box.
-            TaskStack stack = mFirst.split(stackId, relativeStackBoxId, position, weight);
-            if (stack != null) {
-                return stack;
-            }
-            return mSecond.split(stackId, relativeStackBoxId, position, weight);
-        }
-
-        // Found it!
-        TaskStack stack = new TaskStack(mService, stackId, mDisplayContent);
-        TaskStack firstStack;
-        TaskStack secondStack;
-        if (position == TASK_STACK_GOES_BEFORE) {
-            // TODO: Test Configuration here for LTR/RTL.
-            position = TASK_STACK_TO_LEFT_OF;
-        } else if (position == TASK_STACK_GOES_AFTER) {
-            // TODO: Test Configuration here for LTR/RTL.
-            position = TASK_STACK_TO_RIGHT_OF;
-        }
-        switch (position) {
-            default:
-            case TASK_STACK_TO_LEFT_OF:
-            case TASK_STACK_TO_RIGHT_OF:
-                mVertical = false;
-                if (position == TASK_STACK_TO_LEFT_OF) {
-                    mWeight = weight;
-                    firstStack = stack;
-                    secondStack = mStack;
-                } else {
-                    mWeight = 1.0f - weight;
-                    firstStack = mStack;
-                    secondStack = stack;
-                }
-                break;
-            case TASK_STACK_GOES_ABOVE:
-            case TASK_STACK_GOES_BELOW:
-                mVertical = true;
-                if (position == TASK_STACK_GOES_ABOVE) {
-                    mWeight = weight;
-                    firstStack = stack;
-                    secondStack = mStack;
-                } else {
-                    mWeight = 1.0f - weight;
-                    firstStack = mStack;
-                    secondStack = stack;
-                }
-                break;
-        }
-
-        mFirst = new StackBox(mService, mDisplayContent, this);
-        firstStack.mStackBox = mFirst;
-        mFirst.mStack = firstStack;
-
-        mSecond = new StackBox(mService, mDisplayContent, this);
-        secondStack.mStackBox = mSecond;
-        mSecond.mStack = secondStack;
-
-        mStack = null;
-        return stack;
-    }
-
-    /** Return the stackId of the first mFirst StackBox with a non-null mStack */
-    int getStackId() {
-        if (mStack != null) {
-            return mStack.mStackId;
-        }
-        return mFirst.getStackId();
-    }
-
-    /** Remove this box and propagate its sibling's content up to their parent.
-     * @return The first stackId of the resulting StackBox. */
-    int remove() {
-        mDisplayContent.layoutNeeded = true;
-
-        if (mParent == null) {
-            // This is the top-plane stack.
-            if (DEBUG_STACK) Slog.i(TAG, "StackBox.remove: removing top plane.");
-            mDisplayContent.removeStackBox(this);
-            return HOME_STACK_ID;
-        }
-
-        StackBox sibling = isFirstChild() ? mParent.mSecond : mParent.mFirst;
-        StackBox grandparent = mParent.mParent;
-        sibling.mParent = grandparent;
-        if (grandparent == null) {
-            // mParent is a top-plane stack. Now sibling will be.
-            if (DEBUG_STACK) Slog.i(TAG, "StackBox.remove: grandparent null");
-            mDisplayContent.removeStackBox(mParent);
-            mDisplayContent.addStackBox(sibling, true);
-        } else {
-            if (DEBUG_STACK) Slog.i(TAG, "StackBox.remove: grandparent getting sibling");
-            if (mParent.isFirstChild()) {
-                grandparent.mFirst = sibling;
-            } else {
-                grandparent.mSecond = sibling;
-            }
-        }
-        return sibling.getStackId();
-    }
-
-    boolean resize(int stackBoxId, float weight) {
-        if (mStackBoxId != stackBoxId) {
-            return mStack == null &&
-                    (mFirst.resize(stackBoxId, weight) || mSecond.resize(stackBoxId, weight));
-        }
-        // Don't change weight on topmost stack.
-        if (mParent != null) {
-            mParent.mWeight = isFirstChild() ? weight : 1.0f - weight;
-        }
-        return true;
-    }
-
-    /** If this is a terminal StackBox (contains a TaskStack) set the bounds.
-     * @param bounds The rectangle to set the bounds to.
-     * @param underStatusBar True if the StackBox is directly below the Status Bar.
-     * @return True if the bounds changed, false otherwise. */
-    boolean setStackBoxSizes(Rect bounds, boolean underStatusBar) {
-        boolean change = false;
-        if (mUnderStatusBar != underStatusBar) {
-            change = true;
-            mUnderStatusBar = underStatusBar;
-        }
-        if (mStack != null) {
-            change |= !mBounds.equals(bounds);
-            if (change) {
-                mBounds.set(bounds);
-                mStack.setBounds(bounds, underStatusBar);
-            }
-        } else {
-            mTmpRect.set(bounds);
-            if (mVertical) {
-                final int height = bounds.height();
-                int firstHeight = (int)(height * mWeight);
-                mTmpRect.bottom = bounds.top + firstHeight;
-                change |= mFirst.setStackBoxSizes(mTmpRect, underStatusBar);
-                mTmpRect.top = mTmpRect.bottom;
-                mTmpRect.bottom = bounds.top + height;
-                change |= mSecond.setStackBoxSizes(mTmpRect, false);
-            } else {
-                final int width = bounds.width();
-                int firstWidth = (int)(width * mWeight);
-                mTmpRect.right = bounds.left + firstWidth;
-                change |= mFirst.setStackBoxSizes(mTmpRect, underStatusBar);
-                mTmpRect.left = mTmpRect.right;
-                mTmpRect.right = bounds.left + width;
-                change |= mSecond.setStackBoxSizes(mTmpRect, underStatusBar);
-            }
-        }
-        return change;
-    }
-
-    void resetAnimationBackgroundAnimator() {
-        if (mStack != null) {
-            mStack.resetAnimationBackgroundAnimator();
-            return;
-        }
-        mFirst.resetAnimationBackgroundAnimator();
-        mSecond.resetAnimationBackgroundAnimator();
-    }
-
-    boolean animateDimLayers() {
-        if (mStack != null) {
-            return mStack.animateDimLayers();
-        }
-        boolean result = mFirst.animateDimLayers();
-        result |= mSecond.animateDimLayers();
-        return result;
-    }
-
-    void resetDimming() {
-        if (mStack != null) {
-            mStack.resetDimmingTag();
-            return;
-        }
-        mFirst.resetDimming();
-        mSecond.resetDimming();
-    }
-
-    boolean isDimming() {
-        if (mStack != null) {
-            return mStack.isDimming();
-        }
-        boolean result = mFirst.isDimming();
-        result |= mSecond.isDimming();
-        return result;
-    }
-
-    void stopDimmingIfNeeded() {
-        if (mStack != null) {
-            mStack.stopDimmingIfNeeded();
-            return;
-        }
-        mFirst.stopDimmingIfNeeded();
-        mSecond.stopDimmingIfNeeded();
-    }
-
-    void switchUserStacks(int userId) {
-        if (mStack != null) {
-            mStack.switchUser(userId);
-            return;
-        }
-        mFirst.switchUserStacks(userId);
-        mSecond.switchUserStacks(userId);
-    }
-
-    void close() {
-        if (mStack != null) {
-            mStack.mDimLayer.mDimSurface.destroy();
-            mStack.mAnimationBackgroundSurface.mDimSurface.destroy();
-            return;
-        }
-        mFirst.close();
-        mSecond.close();
-    }
-
-    public void dump(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("mParent="); pw.println(mParent);
-        pw.print(prefix); pw.print("mBounds="); pw.print(mBounds.toShortString());
-            pw.print(" mVertical="); pw.print(mVertical);
-            pw.print(" layoutNeeded="); pw.println(layoutNeeded);
-        if (mFirst != null) {
-            pw.print(prefix); pw.print("mFirst="); pw.println(System.identityHashCode(mFirst));
-            mFirst.dump(prefix + "  ", pw);
-            pw.print(prefix); pw.print("mSecond="); pw.println(System.identityHashCode(mSecond));
-            mSecond.dump(prefix + "  ", pw);
-        } else {
-            pw.print(prefix); pw.print("mStack="); pw.println(mStack);
-            mStack.dump(prefix + "  ", pw);
-        }
-    }
-
-    @Override
-    public String toString() {
-        if (mStack != null) {
-            return "Box{" + hashCode() + " stack=" + mStack.mStackId + "}";
-        }
-        return "Box{" + hashCode() + " parent=" + System.identityHashCode(mParent)
-                + " first=" + System.identityHashCode(mFirst)
-                + " second=" + System.identityHashCode(mSecond) + "}";
-    }
-}
diff --git a/services/java/com/android/server/wm/Task.java b/services/java/com/android/server/wm/Task.java
deleted file mode 100644
index 13fdbc8..0000000
--- a/services/java/com/android/server/wm/Task.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2013 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.wm;
-
-import android.util.EventLog;
-import com.android.server.EventLogTags;
-
-class Task {
-//    private final String TAG = "TaskGroup";
-    TaskStack mStack;
-    final AppTokenList mAppTokens = new AppTokenList();
-    final int taskId;
-    final int mUserId;
-
-    Task(AppWindowToken wtoken, TaskStack stack, int userId) {
-        taskId = wtoken.groupId;
-        mAppTokens.add(wtoken);
-        mStack = stack;
-        mUserId = userId;
-    }
-
-    DisplayContent getDisplayContent() {
-        return mStack.getDisplayContent();
-    }
-
-    void addAppToken(int addPos, AppWindowToken wtoken) {
-        mAppTokens.add(addPos, wtoken);
-    }
-
-    boolean removeAppToken(AppWindowToken wtoken) {
-        mAppTokens.remove(wtoken);
-        if (mAppTokens.size() == 0) {
-            EventLog.writeEvent(com.android.server.EventLogTags.WM_TASK_REMOVED, taskId,
-                    "removeAppToken: last token");
-            mStack.removeTask(this);
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public String toString() {
-        return "{taskId=" + taskId + " appTokens=" + mAppTokens + "}";
-    }
-}
diff --git a/services/java/com/android/server/wm/TaskStack.java b/services/java/com/android/server/wm/TaskStack.java
deleted file mode 100644
index cb29df4..0000000
--- a/services/java/com/android/server/wm/TaskStack.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright (C) 2013 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.wm;
-
-import static com.android.server.wm.WindowManagerService.DEBUG_TASK_MOVEMENT;
-import static com.android.server.wm.WindowManagerService.TAG;
-
-import android.graphics.Rect;
-import android.os.Debug;
-import android.util.EventLog;
-import android.util.Slog;
-import android.util.TypedValue;
-import com.android.server.EventLogTags;
-
-import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-public class TaskStack {
-    /** Amount of time in milliseconds to animate the dim surface from one value to another,
-     * when no window animation is driving it. */
-    private static final int DEFAULT_DIM_DURATION = 200;
-
-    /** Unique identifier */
-    final int mStackId;
-
-    /** The service */
-    private final WindowManagerService mService;
-
-    /** The display this stack sits under. */
-    private final DisplayContent mDisplayContent;
-
-    /** The Tasks that define this stack. Oldest Tasks are at the bottom. The ordering must match
-     * mTaskHistory in the ActivityStack with the same mStackId */
-    private final ArrayList<Task> mTasks = new ArrayList<Task>();
-
-    /** The StackBox this sits in. */
-    StackBox mStackBox;
-
-    /** Used to support {@link android.view.WindowManager.LayoutParams#FLAG_DIM_BEHIND} */
-    final DimLayer mDimLayer;
-
-    /** The particular window with FLAG_DIM_BEHIND set. If null, hide mDimLayer. */
-    WindowStateAnimator mDimWinAnimator;
-
-    /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */
-    final DimLayer mAnimationBackgroundSurface;
-
-    /** The particular window with an Animation with non-zero background color. */
-    WindowStateAnimator mAnimationBackgroundAnimator;
-
-    /** Set to false at the start of performLayoutAndPlaceSurfaces. If it is still false by the end
-     * then stop any dimming. */
-    boolean mDimmingTag;
-
-    TaskStack(WindowManagerService service, int stackId, DisplayContent displayContent) {
-        mService = service;
-        mStackId = stackId;
-        mDisplayContent = displayContent;
-        mDimLayer = new DimLayer(service, this);
-        mAnimationBackgroundSurface = new DimLayer(service, this);
-    }
-
-    DisplayContent getDisplayContent() {
-        return mDisplayContent;
-    }
-
-    ArrayList<Task> getTasks() {
-        return mTasks;
-    }
-
-    boolean isHomeStack() {
-        return mStackId == HOME_STACK_ID;
-    }
-
-    boolean hasSibling() {
-        return mStackBox.mParent != null;
-    }
-
-    /**
-     * Put a Task in this stack. Used for adding and moving.
-     * @param task The task to add.
-     * @param toTop Whether to add it to the top or bottom.
-     */
-    boolean addTask(Task task, boolean toTop) {
-        mStackBox.makeDirty();
-
-        int stackNdx;
-        if (!toTop) {
-            stackNdx = 0;
-        } else {
-            stackNdx = mTasks.size();
-            final int currentUserId = mService.mCurrentUserId;
-            if (task.mUserId != currentUserId) {
-                // Place the task below all current user tasks.
-                while (--stackNdx >= 0) {
-                    if (currentUserId != mTasks.get(stackNdx).mUserId) {
-                        break;
-                    }
-                }
-                ++stackNdx;
-            }
-        }
-        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "addTask: task=" + task + " toTop=" + toTop
-                + " pos=" + stackNdx);
-        mTasks.add(stackNdx, task);
-
-        task.mStack = this;
-        mDisplayContent.addTask(task, toTop);
-        return mDisplayContent.moveHomeStackBox(mStackId == HOME_STACK_ID);
-    }
-
-    boolean moveTaskToTop(Task task) {
-        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "moveTaskToTop: task=" + task + " Callers="
-                + Debug.getCallers(6));
-        mTasks.remove(task);
-        return addTask(task, true);
-    }
-
-    boolean moveTaskToBottom(Task task) {
-        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "moveTaskToBottom: task=" + task);
-        mTasks.remove(task);
-        return addTask(task, false);
-    }
-
-    /**
-     * Delete a Task from this stack. If it is the last Task in the stack, remove this stack from
-     * its parent StackBox and merge the parent.
-     * @param task The Task to delete.
-     */
-    void removeTask(Task task) {
-        if (DEBUG_TASK_MOVEMENT) Slog.d(TAG, "removeTask: task=" + task);
-        mStackBox.makeDirty();
-        mTasks.remove(task);
-        mDisplayContent.removeTask(task);
-    }
-
-    int remove() {
-        mAnimationBackgroundSurface.destroySurface();
-        mDimLayer.destroySurface();
-        EventLog.writeEvent(EventLogTags.WM_STACK_REMOVED, mStackId);
-        return mStackBox.remove();
-    }
-
-    void resetAnimationBackgroundAnimator() {
-        mAnimationBackgroundAnimator = null;
-        mAnimationBackgroundSurface.hide();
-    }
-
-    private long getDimBehindFadeDuration(long duration) {
-        TypedValue tv = new TypedValue();
-        mService.mContext.getResources().getValue(
-                com.android.internal.R.fraction.config_dimBehindFadeDuration, tv, true);
-        if (tv.type == TypedValue.TYPE_FRACTION) {
-            duration = (long)tv.getFraction(duration, duration);
-        } else if (tv.type >= TypedValue.TYPE_FIRST_INT && tv.type <= TypedValue.TYPE_LAST_INT) {
-            duration = tv.data;
-        }
-        return duration;
-    }
-
-    boolean animateDimLayers() {
-        final int dimLayer;
-        final float dimAmount;
-        if (mDimWinAnimator == null) {
-            dimLayer = mDimLayer.getLayer();
-            dimAmount = 0;
-        } else {
-            dimLayer = mDimWinAnimator.mAnimLayer - WindowManagerService.LAYER_OFFSET_DIM;
-            dimAmount = mDimWinAnimator.mWin.mAttrs.dimAmount;
-        }
-        final float targetAlpha = mDimLayer.getTargetAlpha();
-        if (targetAlpha != dimAmount) {
-            if (mDimWinAnimator == null) {
-                mDimLayer.hide(DEFAULT_DIM_DURATION);
-            } else {
-                long duration = (mDimWinAnimator.mAnimating && mDimWinAnimator.mAnimation != null)
-                        ? mDimWinAnimator.mAnimation.computeDurationHint()
-                        : DEFAULT_DIM_DURATION;
-                if (targetAlpha > dimAmount) {
-                    duration = getDimBehindFadeDuration(duration);
-                }
-                mDimLayer.show(dimLayer, dimAmount, duration);
-            }
-        } else if (mDimLayer.getLayer() != dimLayer) {
-            mDimLayer.setLayer(dimLayer);
-        }
-        if (mDimLayer.isAnimating()) {
-            if (!mService.okToDisplay()) {
-                // Jump to the end of the animation.
-                mDimLayer.show();
-            } else {
-                return mDimLayer.stepAnimation();
-            }
-        }
-        return false;
-    }
-
-    void resetDimmingTag() {
-        mDimmingTag = false;
-    }
-
-    void setDimmingTag() {
-        mDimmingTag = true;
-    }
-
-    boolean testDimmingTag() {
-        return mDimmingTag;
-    }
-
-    boolean isDimming() {
-        return mDimLayer.isDimming();
-    }
-
-    boolean isDimming(WindowStateAnimator winAnimator) {
-        return mDimWinAnimator == winAnimator && mDimLayer.isDimming();
-    }
-
-    void startDimmingIfNeeded(WindowStateAnimator newWinAnimator) {
-        // Only set dim params on the highest dimmed layer.
-        final WindowStateAnimator existingDimWinAnimator = mDimWinAnimator;
-        // Don't turn on for an unshown surface, or for any layer but the highest dimmed layer.
-        if (newWinAnimator.mSurfaceShown && (existingDimWinAnimator == null
-                || !existingDimWinAnimator.mSurfaceShown
-                || existingDimWinAnimator.mAnimLayer < newWinAnimator.mAnimLayer)) {
-            mDimWinAnimator = newWinAnimator;
-        }
-    }
-
-    void stopDimmingIfNeeded() {
-        if (!mDimmingTag && isDimming()) {
-            mDimWinAnimator = null;
-        }
-    }
-
-    void setAnimationBackground(WindowStateAnimator winAnimator, int color) {
-        int animLayer = winAnimator.mAnimLayer;
-        if (mAnimationBackgroundAnimator == null
-                || animLayer < mAnimationBackgroundAnimator.mAnimLayer) {
-            mAnimationBackgroundAnimator = winAnimator;
-            animLayer = mService.adjustAnimationBackground(winAnimator);
-            mAnimationBackgroundSurface.show(animLayer - WindowManagerService.LAYER_OFFSET_DIM,
-                    ((color >> 24) & 0xff) / 255f, 0);
-        }
-    }
-
-    void setBounds(Rect bounds, boolean underStatusBar) {
-        mDimLayer.setBounds(bounds);
-        mAnimationBackgroundSurface.setBounds(bounds);
-
-        final ArrayList<WindowState> resizingWindows = mService.mResizingWindows;
-        for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) {
-            final ArrayList<AppWindowToken> activities = mTasks.get(taskNdx).mAppTokens;
-            for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
-                final ArrayList<WindowState> windows = activities.get(activityNdx).allAppWindows;
-                for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
-                    final WindowState win = windows.get(winNdx);
-                    if (!resizingWindows.contains(win)) {
-                        if (WindowManagerService.DEBUG_RESIZE) Slog.d(TAG,
-                                "setBounds: Resizing " + win);
-                        resizingWindows.add(win);
-                    }
-                    win.mUnderStatusBar = underStatusBar;
-                }
-            }
-        }
-    }
-
-    void switchUser(int userId) {
-        int top = mTasks.size();
-        for (int taskNdx = 0; taskNdx < top; ++taskNdx) {
-            Task task = mTasks.get(taskNdx);
-            if (task.mUserId == userId) {
-                mTasks.remove(taskNdx);
-                mTasks.add(task);
-                --top;
-            }
-        }
-    }
-
-    public void dump(String prefix, PrintWriter pw) {
-        pw.print(prefix); pw.print("mStackId="); pw.println(mStackId);
-        for (int taskNdx = 0; taskNdx < mTasks.size(); ++taskNdx) {
-            pw.print(prefix); pw.println(mTasks.get(taskNdx));
-        }
-        if (mAnimationBackgroundSurface.isDimming()) {
-            pw.print(prefix); pw.println("mWindowAnimationBackgroundSurface:");
-            mAnimationBackgroundSurface.printTo(prefix + "  ", pw);
-        }
-        if (mDimLayer.isDimming()) {
-            pw.print(prefix); pw.println("mDimLayer:");
-            mDimLayer.printTo(prefix, pw);
-            pw.print(prefix); pw.print("mDimWinAnimator="); pw.println(mDimWinAnimator);
-        }
-    }
-
-    @Override
-    public String toString() {
-        return "{stackId=" + mStackId + " tasks=" + mTasks + "}";
-    }
-}
diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java
deleted file mode 100644
index 91f15f3..0000000
--- a/services/java/com/android/server/wm/WindowAnimator.java
+++ /dev/null
@@ -1,689 +0,0 @@
-// Copyright 2012 Google Inc. All Rights Reserved.
-
-package com.android.server.wm;
-
-import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
-import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
-
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_UPDATE_ROTATION;
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_MAY_CHANGE;
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_FORCE_HIDING_CHANGED;
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_WALLPAPER_ACTION_PENDING;
-
-import android.content.Context;
-import android.os.Debug;
-import android.os.SystemClock;
-import android.util.Log;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.SparseIntArray;
-import android.util.TimeUtils;
-import android.view.Display;
-import android.view.SurfaceControl;
-import android.view.WindowManagerPolicy;
-import android.view.animation.Animation;
-
-import com.android.server.wm.WindowManagerService.LayoutFields;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-/**
- * Singleton class that carries out the animations and Surface operations in a separate task
- * on behalf of WindowManagerService.
- */
-public class WindowAnimator {
-    private static final String TAG = "WindowAnimator";
-
-    final WindowManagerService mService;
-    final Context mContext;
-    final WindowManagerPolicy mPolicy;
-
-    boolean mAnimating;
-
-    final Runnable mAnimationRunnable;
-
-    /** Time of current animation step. Reset on each iteration */
-    long mCurrentTime;
-
-    /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
-     * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
-    private int mAnimTransactionSequence;
-
-    /** Window currently running an animation that has requested it be detached
-     * from the wallpaper.  This means we need to ensure the wallpaper is
-     * visible behind it in case it animates in a way that would allow it to be
-     * seen. If multiple windows satisfy this, use the lowest window. */
-    WindowState mWindowDetachedWallpaper = null;
-
-    WindowStateAnimator mUniverseBackground = null;
-    int mAboveUniverseLayer = 0;
-
-    int mBulkUpdateParams = 0;
-    Object mLastWindowFreezeSource;
-
-    SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators =
-            new SparseArray<WindowAnimator.DisplayContentsAnimator>(2);
-
-    boolean mInitialized = false;
-
-    // forceHiding states.
-    static final int KEYGUARD_NOT_SHOWN     = 0;
-    static final int KEYGUARD_ANIMATING_IN  = 1;
-    static final int KEYGUARD_SHOWN         = 2;
-    static final int KEYGUARD_ANIMATING_OUT = 3;
-    int mForceHiding = KEYGUARD_NOT_SHOWN;
-
-    private String forceHidingToString() {
-        switch (mForceHiding) {
-            case KEYGUARD_NOT_SHOWN:    return "KEYGUARD_NOT_SHOWN";
-            case KEYGUARD_ANIMATING_IN: return "KEYGUARD_ANIMATING_IN";
-            case KEYGUARD_SHOWN:        return "KEYGUARD_SHOWN";
-            case KEYGUARD_ANIMATING_OUT:return "KEYGUARD_ANIMATING_OUT";
-            default: return "KEYGUARD STATE UNKNOWN " + mForceHiding;
-        }
-    }
-
-    WindowAnimator(final WindowManagerService service) {
-        mService = service;
-        mContext = service.mContext;
-        mPolicy = service.mPolicy;
-
-        mAnimationRunnable = new Runnable() {
-            @Override
-            public void run() {
-                synchronized (mService.mWindowMap) {
-                    mService.mAnimationScheduled = false;
-                    animateLocked();
-                }
-            }
-        };
-    }
-
-    void addDisplayLocked(final int displayId) {
-        // Create the DisplayContentsAnimator object by retrieving it.
-        getDisplayContentsAnimatorLocked(displayId);
-        if (displayId == Display.DEFAULT_DISPLAY) {
-            mInitialized = true;
-        }
-    }
-
-    void removeDisplayLocked(final int displayId) {
-        final DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
-        if (displayAnimator != null) {
-            if (displayAnimator.mScreenRotationAnimation != null) {
-                displayAnimator.mScreenRotationAnimation.kill();
-                displayAnimator.mScreenRotationAnimation = null;
-            }
-        }
-
-        mDisplayContentsAnimators.delete(displayId);
-    }
-
-    void hideWallpapersLocked(final WindowState w) {
-        final WindowState wallpaperTarget = mService.mWallpaperTarget;
-        final WindowState lowerWallpaperTarget = mService.mLowerWallpaperTarget;
-        final ArrayList<WindowToken> wallpaperTokens = mService.mWallpaperTokens;
-
-        if ((wallpaperTarget == w && lowerWallpaperTarget == null) || wallpaperTarget == null) {
-            final int numTokens = wallpaperTokens.size();
-            for (int i = numTokens - 1; i >= 0; i--) {
-                final WindowToken token = wallpaperTokens.get(i);
-                final int numWindows = token.windows.size();
-                for (int j = numWindows - 1; j >= 0; j--) {
-                    final WindowState wallpaper = token.windows.get(j);
-                    final WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
-                    if (!winAnimator.mLastHidden) {
-                        winAnimator.hide();
-                        mService.dispatchWallpaperVisibility(wallpaper, false);
-                        setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                    }
-                }
-                if (WindowManagerService.DEBUG_WALLPAPER_LIGHT && !token.hidden) Slog.d(TAG,
-                        "Hiding wallpaper " + token + " from " + w
-                        + " target=" + wallpaperTarget + " lower=" + lowerWallpaperTarget
-                        + "\n" + Debug.getCallers(5, "  "));
-                token.hidden = true;
-            }
-        }
-    }
-
-    private void updateAppWindowsLocked(int displayId) {
-        final DisplayContent displayContent = mService.getDisplayContentLocked(displayId);
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        final int numTasks = tasks.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int numTokens = tokens.size();
-            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
-                final AppWindowAnimator appAnimator = tokens.get(tokenNdx).mAppAnimator;
-                final boolean wasAnimating = appAnimator.animation != null
-                        && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
-                if (appAnimator.stepAnimationLocked(mCurrentTime)) {
-                    mAnimating = true;
-                } else if (wasAnimating) {
-                    // stopped animating, do one more pass through the layout
-                    setAppLayoutChanges(appAnimator, WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
-                            "appToken " + appAnimator.mAppToken + " done");
-                    if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
-                            "updateWindowsApps...: done animating " + appAnimator.mAppToken);
-                }
-            }
-        }
-
-        final AppTokenList exitingAppTokens = displayContent.mExitingAppTokens;
-        final int NEAT = exitingAppTokens.size();
-        for (int i = 0; i < NEAT; i++) {
-            final AppWindowAnimator appAnimator = exitingAppTokens.get(i).mAppAnimator;
-            final boolean wasAnimating = appAnimator.animation != null
-                    && appAnimator.animation != AppWindowAnimator.sDummyAnimation;
-            if (appAnimator.stepAnimationLocked(mCurrentTime)) {
-                mAnimating = true;
-            } else if (wasAnimating) {
-                // stopped animating, do one more pass through the layout
-                setAppLayoutChanges(appAnimator, WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
-                    "exiting appToken " + appAnimator.mAppToken + " done");
-                if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
-                        "updateWindowsApps...: done animating exiting " + appAnimator.mAppToken);
-            }
-        }
-    }
-
-    private void updateWindowsLocked(final int displayId) {
-        ++mAnimTransactionSequence;
-
-        final WindowList windows = mService.getWindowListLocked(displayId);
-        ArrayList<WindowStateAnimator> unForceHiding = null;
-        boolean wallpaperInUnForceHiding = false;
-        mForceHiding = KEYGUARD_NOT_SHOWN;
-
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            WindowState win = windows.get(i);
-            WindowStateAnimator winAnimator = win.mWinAnimator;
-            final int flags = winAnimator.mAttrFlags;
-
-            if (winAnimator.mSurfaceControl != null) {
-                final boolean wasAnimating = winAnimator.mWasAnimating;
-                final boolean nowAnimating = winAnimator.stepAnimationLocked(mCurrentTime);
-
-                if (WindowManagerService.DEBUG_WALLPAPER) {
-                    Slog.v(TAG, win + ": wasAnimating=" + wasAnimating +
-                            ", nowAnimating=" + nowAnimating);
-                }
-
-                if (wasAnimating && !winAnimator.mAnimating && mService.mWallpaperTarget == win) {
-                    mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
-                    setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
-                            WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                    if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
-                        mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 2",
-                                getPendingLayoutChanges(Display.DEFAULT_DISPLAY));
-                    }
-                }
-
-                if (mPolicy.doesForceHide(win, win.mAttrs)) {
-                    if (!wasAnimating && nowAnimating) {
-                        if (WindowManagerService.DEBUG_ANIM ||
-                                WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
-                                "Animation started that could impact force hide: " + win);
-                        mBulkUpdateParams |= SET_FORCE_HIDING_CHANGED;
-                        setPendingLayoutChanges(displayId,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
-                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 3",
-                                    getPendingLayoutChanges(displayId));
-                        }
-                        mService.mFocusMayChange = true;
-                    }
-                    if (win.isReadyForDisplay()) {
-                        if (nowAnimating) {
-                            if (winAnimator.mAnimationIsEntrance) {
-                                mForceHiding = KEYGUARD_ANIMATING_IN;
-                            } else {
-                                mForceHiding = KEYGUARD_ANIMATING_OUT;
-                            }
-                        } else {
-                            mForceHiding = win.isDrawnLw() ? KEYGUARD_SHOWN : KEYGUARD_NOT_SHOWN;
-                        }
-                    }
-                    if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG,
-                            "Force hide " + mForceHiding
-                            + " hasSurface=" + win.mHasSurface
-                            + " policyVis=" + win.mPolicyVisibility
-                            + " destroying=" + win.mDestroying
-                            + " attHidden=" + win.mAttachedHidden
-                            + " vis=" + win.mViewVisibility
-                            + " hidden=" + win.mRootToken.hidden
-                            + " anim=" + win.mWinAnimator.mAnimation);
-                } else if (mPolicy.canBeForceHidden(win, win.mAttrs)) {
-                    final boolean hideWhenLocked =
-                            (winAnimator.mAttrFlags & FLAG_SHOW_WHEN_LOCKED) == 0;
-                    final boolean changed;
-                    if (((mForceHiding == KEYGUARD_ANIMATING_IN)
-                                && (!winAnimator.isAnimating() || hideWhenLocked))
-                            || ((mForceHiding == KEYGUARD_SHOWN) && hideWhenLocked)) {
-                        changed = win.hideLw(false, false);
-                        if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
-                                "Now policy hidden: " + win);
-                    } else {
-                        changed = win.showLw(false, false);
-                        if (WindowManagerService.DEBUG_VISIBILITY && changed) Slog.v(TAG,
-                                "Now policy shown: " + win);
-                        if (changed) {
-                            if ((mBulkUpdateParams & SET_FORCE_HIDING_CHANGED) != 0
-                                    && win.isVisibleNow() /*w.isReadyForDisplay()*/) {
-                                if (unForceHiding == null) {
-                                    unForceHiding = new ArrayList<WindowStateAnimator>();
-                                }
-                                unForceHiding.add(winAnimator);
-                                if ((flags & FLAG_SHOW_WALLPAPER) != 0) {
-                                    wallpaperInUnForceHiding = true;
-                                }
-                            }
-                            final WindowState currentFocus = mService.mCurrentFocus;
-                            if (currentFocus == null || currentFocus.mLayer < win.mLayer) {
-                                // We are showing on to of the current
-                                // focus, so re-evaluate focus to make
-                                // sure it is correct.
-                                if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.v(TAG,
-                                        "updateWindowsLocked: setting mFocusMayChange true");
-                                mService.mFocusMayChange = true;
-                            }
-                        }
-                    }
-                    if (changed && (flags & FLAG_SHOW_WALLPAPER) != 0) {
-                        mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
-                        setPendingLayoutChanges(Display.DEFAULT_DISPLAY,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
-                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 4",
-                                    getPendingLayoutChanges(Display.DEFAULT_DISPLAY));
-                        }
-                    }
-                }
-            }
-
-            final AppWindowToken atoken = win.mAppToken;
-            if (winAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW) {
-                if (atoken == null || atoken.allDrawn) {
-                    if (winAnimator.performShowLocked()) {
-                        setPendingLayoutChanges(displayId,
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
-                        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
-                            mService.debugLayoutRepeats("updateWindowsAndWallpaperLocked 5",
-                                    getPendingLayoutChanges(displayId));
-                        }
-                    }
-                }
-            }
-            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
-            if (appAnimator != null && appAnimator.thumbnail != null) {
-                if (appAnimator.thumbnailTransactionSeq != mAnimTransactionSequence) {
-                    appAnimator.thumbnailTransactionSeq = mAnimTransactionSequence;
-                    appAnimator.thumbnailLayer = 0;
-                }
-                if (appAnimator.thumbnailLayer < winAnimator.mAnimLayer) {
-                    appAnimator.thumbnailLayer = winAnimator.mAnimLayer;
-                }
-            }
-        } // end forall windows
-
-        // If we have windows that are being show due to them no longer
-        // being force-hidden, apply the appropriate animation to them.
-        if (unForceHiding != null) {
-            for (int i=unForceHiding.size()-1; i>=0; i--) {
-                Animation a = mPolicy.createForceHideEnterAnimation(wallpaperInUnForceHiding);
-                if (a != null) {
-                    final WindowStateAnimator winAnimator = unForceHiding.get(i);
-                    winAnimator.setAnimation(a);
-                    winAnimator.mAnimationIsEntrance = true;
-                }
-            }
-        }
-    }
-
-    private void updateWallpaperLocked(int displayId) {
-        mService.getDisplayContentLocked(displayId).resetAnimationBackgroundAnimator();
-
-        final WindowList windows = mService.getWindowListLocked(displayId);
-        WindowState detachedWallpaper = null;
-
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            final WindowState win = windows.get(i);
-            WindowStateAnimator winAnimator = win.mWinAnimator;
-            if (winAnimator.mSurfaceControl == null) {
-                continue;
-            }
-
-            final int flags = winAnimator.mAttrFlags;
-
-            // If this window is animating, make a note that we have
-            // an animating window and take care of a request to run
-            // a detached wallpaper animation.
-            if (winAnimator.mAnimating) {
-                if (winAnimator.mAnimation != null) {
-                    if ((flags & FLAG_SHOW_WALLPAPER) != 0
-                            && winAnimator.mAnimation.getDetachWallpaper()) {
-                        detachedWallpaper = win;
-                    }
-                    final int color = winAnimator.mAnimation.getBackgroundColor();
-                    if (color != 0) {
-                        win.getStack().setAnimationBackground(winAnimator, color);
-                    }
-                }
-                mAnimating = true;
-            }
-
-            // If this window's app token is running a detached wallpaper
-            // animation, make a note so we can ensure the wallpaper is
-            // displayed behind it.
-            final AppWindowAnimator appAnimator = winAnimator.mAppAnimator;
-            if (appAnimator != null && appAnimator.animation != null
-                    && appAnimator.animating) {
-                if ((flags & FLAG_SHOW_WALLPAPER) != 0
-                        && appAnimator.animation.getDetachWallpaper()) {
-                    detachedWallpaper = win;
-                }
-
-                final int color = appAnimator.animation.getBackgroundColor();
-                if (color != 0) {
-                    win.getStack().setAnimationBackground(winAnimator, color);
-                }
-            }
-        } // end forall windows
-
-        if (mWindowDetachedWallpaper != detachedWallpaper) {
-            if (WindowManagerService.DEBUG_WALLPAPER) Slog.v(TAG,
-                    "Detached wallpaper changed from " + mWindowDetachedWallpaper
-                    + " to " + detachedWallpaper);
-            mWindowDetachedWallpaper = detachedWallpaper;
-            mBulkUpdateParams |= SET_WALLPAPER_MAY_CHANGE;
-        }
-    }
-
-    /** See if any windows have been drawn, so they (and others associated with them) can now be
-     *  shown. */
-    private void testTokenMayBeDrawnLocked(int displayId) {
-        // See if any windows have been drawn, so they (and others
-        // associated with them) can now be shown.
-        final ArrayList<Task> tasks = mService.getDisplayContentLocked(displayId).getTasks();
-        final int numTasks = tasks.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int numTokens = tokens.size();
-            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
-                final AppWindowToken wtoken = tokens.get(tokenNdx);
-                AppWindowAnimator appAnimator = wtoken.mAppAnimator;
-                final boolean allDrawn = wtoken.allDrawn;
-                if (allDrawn != appAnimator.allDrawn) {
-                    appAnimator.allDrawn = allDrawn;
-                    if (allDrawn) {
-                        // The token has now changed state to having all
-                        // windows shown...  what to do, what to do?
-                        if (appAnimator.freezingScreen) {
-                            appAnimator.showAllWindowsLocked();
-                            mService.unsetAppFreezingScreenLocked(wtoken, false, true);
-                            if (WindowManagerService.DEBUG_ORIENTATION) Slog.i(TAG,
-                                    "Setting mOrientationChangeComplete=true because wtoken "
-                                    + wtoken + " numInteresting=" + wtoken.numInterestingWindows
-                                    + " numDrawn=" + wtoken.numDrawnWindows);
-                            // This will set mOrientationChangeComplete and cause a pass through layout.
-                            setAppLayoutChanges(appAnimator,
-                                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER,
-                                    "testTokenMayBeDrawnLocked: freezingScreen");
-                        } else {
-                            setAppLayoutChanges(appAnimator,
-                                    WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM,
-                                    "testTokenMayBeDrawnLocked");
-
-                            // We can now show all of the drawn windows!
-                            if (!mService.mOpeningApps.contains(wtoken)) {
-                                mAnimating |= appAnimator.showAllWindowsLocked();
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    private void performAnimationsLocked(final int displayId) {
-        updateWindowsLocked(displayId);
-        updateWallpaperLocked(displayId);
-    }
-
-
-    /** Locked on mService.mWindowMap. */
-    private void animateLocked() {
-        if (!mInitialized) {
-            return;
-        }
-
-        mCurrentTime = SystemClock.uptimeMillis();
-        mBulkUpdateParams = SET_ORIENTATION_CHANGE_COMPLETE;
-        boolean wasAnimating = mAnimating;
-        mAnimating = false;
-        if (WindowManagerService.DEBUG_WINDOW_TRACE) {
-            Slog.i(TAG, "!!! animate: entry time=" + mCurrentTime);
-        }
-
-        if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
-                TAG, ">>> OPEN TRANSACTION animateLocked");
-        SurfaceControl.openTransaction();
-        SurfaceControl.setAnimationTransaction();
-        try {
-            final int numDisplays = mDisplayContentsAnimators.size();
-            for (int i = 0; i < numDisplays; i++) {
-                final int displayId = mDisplayContentsAnimators.keyAt(i);
-                updateAppWindowsLocked(displayId);
-                DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
-
-                final ScreenRotationAnimation screenRotationAnimation =
-                        displayAnimator.mScreenRotationAnimation;
-                if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
-                    if (screenRotationAnimation.stepAnimationLocked(mCurrentTime)) {
-                        mAnimating = true;
-                    } else {
-                        mBulkUpdateParams |= SET_UPDATE_ROTATION;
-                        screenRotationAnimation.kill();
-                        displayAnimator.mScreenRotationAnimation = null;
-                    }
-                }
-
-                // Update animations of all applications, including those
-                // associated with exiting/removed apps
-                performAnimationsLocked(displayId);
-
-                final WindowList windows = mService.getWindowListLocked(displayId);
-                final int N = windows.size();
-                for (int j = 0; j < N; j++) {
-                    windows.get(j).mWinAnimator.prepareSurfaceLocked(true);
-                }
-            }
-
-            for (int i = 0; i < numDisplays; i++) {
-                final int displayId = mDisplayContentsAnimators.keyAt(i);
-
-                testTokenMayBeDrawnLocked(displayId);
-
-                final ScreenRotationAnimation screenRotationAnimation =
-                        mDisplayContentsAnimators.valueAt(i).mScreenRotationAnimation;
-                if (screenRotationAnimation != null) {
-                    screenRotationAnimation.updateSurfacesInTransaction();
-                }
-
-                mAnimating |= mService.getDisplayContentLocked(displayId).animateDimLayers();
-
-                //TODO (multidisplay): Magnification is supported only for the default display.
-                if (mService.mDisplayMagnifier != null && displayId == Display.DEFAULT_DISPLAY) {
-                    mService.mDisplayMagnifier.drawMagnifiedRegionBorderIfNeededLocked();
-                }
-            }
-
-            if (mAnimating) {
-                mService.scheduleAnimationLocked();
-            }
-
-            mService.setFocusedStackLayer();
-
-            if (mService.mWatermark != null) {
-                mService.mWatermark.drawIfNeeded();
-            }
-        } catch (RuntimeException e) {
-            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
-        } finally {
-            SurfaceControl.closeTransaction();
-            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(
-                    TAG, "<<< CLOSE TRANSACTION animateLocked");
-        }
-
-        boolean hasPendingLayoutChanges = false;
-        final int numDisplays = mService.mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final DisplayContent displayContent = mService.mDisplayContents.valueAt(displayNdx);
-            final int pendingChanges = getPendingLayoutChanges(displayContent.getDisplayId());
-            if ((pendingChanges & WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0) {
-                mBulkUpdateParams |= SET_WALLPAPER_ACTION_PENDING;
-            }
-            if (pendingChanges != 0) {
-                hasPendingLayoutChanges = true;
-            }
-        }
-
-        boolean doRequest = false;
-        if (mBulkUpdateParams != 0) {
-            doRequest = mService.copyAnimToLayoutParamsLocked();
-        }
-
-        if (hasPendingLayoutChanges || doRequest) {
-            mService.requestTraversalLocked();
-        }
-
-        if (!mAnimating && wasAnimating) {
-            mService.requestTraversalLocked();
-        }
-        if (WindowManagerService.DEBUG_WINDOW_TRACE) {
-            Slog.i(TAG, "!!! animate: exit mAnimating=" + mAnimating
-                + " mBulkUpdateParams=" + Integer.toHexString(mBulkUpdateParams)
-                + " mPendingLayoutChanges(DEFAULT_DISPLAY)="
-                + Integer.toHexString(getPendingLayoutChanges(Display.DEFAULT_DISPLAY)));
-        }
-    }
-
-    static String bulkUpdateParamsToString(int bulkUpdateParams) {
-        StringBuilder builder = new StringBuilder(128);
-        if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) {
-            builder.append(" UPDATE_ROTATION");
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) {
-            builder.append(" WALLPAPER_MAY_CHANGE");
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) {
-            builder.append(" FORCE_HIDING_CHANGED");
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) != 0) {
-            builder.append(" ORIENTATION_CHANGE_COMPLETE");
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) {
-            builder.append(" TURN_ON_SCREEN");
-        }
-        return builder.toString();
-    }
-
-    public void dumpLocked(PrintWriter pw, String prefix, boolean dumpAll) {
-        final String subPrefix = "  " + prefix;
-        final String subSubPrefix = "  " + subPrefix;
-
-        for (int i = 0; i < mDisplayContentsAnimators.size(); i++) {
-            pw.print(prefix); pw.print("DisplayContentsAnimator #");
-                    pw.print(mDisplayContentsAnimators.keyAt(i));
-                    pw.println(":");
-            DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.valueAt(i);
-            final WindowList windows =
-                    mService.getWindowListLocked(mDisplayContentsAnimators.keyAt(i));
-            final int N = windows.size();
-            for (int j = 0; j < N; j++) {
-                WindowStateAnimator wanim = windows.get(j).mWinAnimator;
-                pw.print(subPrefix); pw.print("Window #"); pw.print(j);
-                        pw.print(": "); pw.println(wanim);
-            }
-            if (displayAnimator.mScreenRotationAnimation != null) {
-                pw.print(subPrefix); pw.println("mScreenRotationAnimation:");
-                displayAnimator.mScreenRotationAnimation.printTo(subSubPrefix, pw);
-            } else if (dumpAll) {
-                pw.print(subPrefix); pw.println("no ScreenRotationAnimation ");
-            }
-        }
-
-        pw.println();
-
-        if (dumpAll) {
-            pw.print(prefix); pw.print("mAnimTransactionSequence=");
-                    pw.print(mAnimTransactionSequence);
-                    pw.print(" mForceHiding="); pw.println(forceHidingToString());
-            pw.print(prefix); pw.print("mCurrentTime=");
-                    pw.println(TimeUtils.formatUptime(mCurrentTime));
-        }
-        if (mBulkUpdateParams != 0) {
-            pw.print(prefix); pw.print("mBulkUpdateParams=0x");
-                    pw.print(Integer.toHexString(mBulkUpdateParams));
-                    pw.println(bulkUpdateParamsToString(mBulkUpdateParams));
-        }
-        if (mWindowDetachedWallpaper != null) {
-            pw.print(prefix); pw.print("mWindowDetachedWallpaper=");
-                pw.println(mWindowDetachedWallpaper);
-        }
-        if (mUniverseBackground != null) {
-            pw.print(prefix); pw.print("mUniverseBackground="); pw.print(mUniverseBackground);
-                    pw.print(" mAboveUniverseLayer="); pw.println(mAboveUniverseLayer);
-        }
-    }
-
-    int getPendingLayoutChanges(final int displayId) {
-        return mService.getDisplayContentLocked(displayId).pendingLayoutChanges;
-    }
-
-    void setPendingLayoutChanges(final int displayId, final int changes) {
-        mService.getDisplayContentLocked(displayId).pendingLayoutChanges |= changes;
-    }
-
-    void setAppLayoutChanges(final AppWindowAnimator appAnimator, final int changes, String s) {
-        // Used to track which displays layout changes have been done.
-        SparseIntArray displays = new SparseIntArray(2);
-        WindowList windows = appAnimator.mAppToken.allAppWindows;
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            final int displayId = windows.get(i).getDisplayId();
-            if (displays.indexOfKey(displayId) < 0) {
-                setPendingLayoutChanges(displayId, changes);
-                if (WindowManagerService.DEBUG_LAYOUT_REPEATS) {
-                    mService.debugLayoutRepeats(s, getPendingLayoutChanges(displayId));
-                }
-                // Keep from processing this display again.
-                displays.put(displayId, changes);
-            }
-        }
-    }
-
-    private DisplayContentsAnimator getDisplayContentsAnimatorLocked(int displayId) {
-        DisplayContentsAnimator displayAnimator = mDisplayContentsAnimators.get(displayId);
-        if (displayAnimator == null) {
-            displayAnimator = new DisplayContentsAnimator();
-            mDisplayContentsAnimators.put(displayId, displayAnimator);
-        }
-        return displayAnimator;
-    }
-
-    void setScreenRotationAnimationLocked(int displayId, ScreenRotationAnimation animation) {
-        getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation = animation;
-    }
-
-    ScreenRotationAnimation getScreenRotationAnimationLocked(int displayId) {
-        return getDisplayContentsAnimatorLocked(displayId).mScreenRotationAnimation;
-    }
-
-    private class DisplayContentsAnimator {
-        ScreenRotationAnimation mScreenRotationAnimation = null;
-    }
-}
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
deleted file mode 100644
index 3ed5076..0000000
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ /dev/null
@@ -1,10865 +0,0 @@
-/*
- * Copyright (C) 2007 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.wm;
-
-import static android.view.WindowManager.LayoutParams.*;
-
-import static com.android.server.am.ActivityStackSupervisor.HOME_STACK_ID;
-
-import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-
-import android.app.AppOpsManager;
-import android.util.TimeUtils;
-import android.view.IWindowId;
-
-import com.android.internal.app.IBatteryStats;
-import com.android.internal.policy.PolicyManager;
-import com.android.internal.policy.impl.PhoneWindowManager;
-import com.android.internal.util.FastPrintWriter;
-import com.android.internal.view.IInputContext;
-import com.android.internal.view.IInputMethodClient;
-import com.android.internal.view.IInputMethodManager;
-import com.android.internal.view.WindowManagerPolicyThread;
-import com.android.server.AttributeCache;
-import com.android.server.EventLogTags;
-import com.android.server.UiThread;
-import com.android.server.Watchdog;
-import com.android.server.am.BatteryStatsService;
-import com.android.server.display.DisplayManagerService;
-import com.android.server.input.InputManagerService;
-import com.android.server.power.PowerManagerService;
-import com.android.server.power.ShutdownThread;
-
-import android.Manifest;
-import android.app.ActivityManager.StackBoxInfo;
-import android.app.ActivityManagerNative;
-import android.app.IActivityManager;
-import android.app.StatusBarManager;
-import android.app.admin.DevicePolicyManager;
-import android.animation.ValueAnimator;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.res.CompatibilityInfo;
-import android.content.res.Configuration;
-import android.graphics.Bitmap;
-import android.graphics.Bitmap.Config;
-import android.graphics.Canvas;
-import android.graphics.Matrix;
-import android.graphics.PixelFormat;
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.Region;
-import android.hardware.display.DisplayManager;
-import android.os.Binder;
-import android.os.Bundle;
-import android.os.Debug;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.IRemoteCallback;
-import android.os.Looper;
-import android.os.Message;
-import android.os.Parcel;
-import android.os.ParcelFileDescriptor;
-import android.os.PowerManager;
-import android.os.Process;
-import android.os.RemoteException;
-import android.os.ServiceManager;
-import android.os.StrictMode;
-import android.os.SystemClock;
-import android.os.SystemProperties;
-import android.os.Trace;
-import android.os.WorkSource;
-import android.provider.Settings;
-import android.util.DisplayMetrics;
-import android.util.EventLog;
-import android.util.FloatMath;
-import android.util.Log;
-import android.util.SparseArray;
-import android.util.Pair;
-import android.util.Slog;
-import android.util.SparseIntArray;
-import android.util.TypedValue;
-import android.view.Choreographer;
-import android.view.Display;
-import android.view.DisplayInfo;
-import android.view.Gravity;
-import android.view.IApplicationToken;
-import android.view.IInputFilter;
-import android.view.IMagnificationCallbacks;
-import android.view.IOnKeyguardExitResult;
-import android.view.IRotationWatcher;
-import android.view.IWindow;
-import android.view.IWindowManager;
-import android.view.IWindowSession;
-import android.view.InputChannel;
-import android.view.InputDevice;
-import android.view.InputEvent;
-import android.view.InputEventReceiver;
-import android.view.KeyEvent;
-import android.view.MagnificationSpec;
-import android.view.MotionEvent;
-import android.view.Surface.OutOfResourcesException;
-import android.view.Surface;
-import android.view.SurfaceControl;
-import android.view.SurfaceSession;
-import android.view.View;
-import android.view.ViewTreeObserver;
-import android.view.WindowManager;
-import android.view.WindowManagerGlobal;
-import android.view.WindowManagerPolicy;
-import android.view.WindowManager.LayoutParams;
-import android.view.WindowManagerPolicy.FakeWindow;
-import android.view.WindowManagerPolicy.PointerEventListener;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.view.animation.Transformation;
-
-import java.io.BufferedWriter;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.Socket;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-
-/** {@hide} */
-public class WindowManagerService extends IWindowManager.Stub
-        implements Watchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs,
-                DisplayManagerService.WindowManagerFuncs, DisplayManager.DisplayListener {
-    static final String TAG = "WindowManager";
-    static final boolean DEBUG = false;
-    static final boolean DEBUG_ADD_REMOVE = false;
-    static final boolean DEBUG_FOCUS = false;
-    static final boolean DEBUG_FOCUS_LIGHT = DEBUG_FOCUS || false;
-    static final boolean DEBUG_ANIM = false;
-    static final boolean DEBUG_LAYOUT = false;
-    static final boolean DEBUG_RESIZE = false;
-    static final boolean DEBUG_LAYERS = false;
-    static final boolean DEBUG_INPUT = false;
-    static final boolean DEBUG_INPUT_METHOD = false;
-    static final boolean DEBUG_VISIBILITY = false;
-    static final boolean DEBUG_WINDOW_MOVEMENT = false;
-    static final boolean DEBUG_TOKEN_MOVEMENT = false;
-    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_REORDER = false;
-    static final boolean DEBUG_WALLPAPER = false;
-    static final boolean DEBUG_WALLPAPER_LIGHT = false || DEBUG_WALLPAPER;
-    static final boolean DEBUG_DRAG = false;
-    static final boolean DEBUG_SCREEN_ON = false;
-    static final boolean DEBUG_SCREENSHOT = false;
-    static final boolean DEBUG_BOOT = false;
-    static final boolean DEBUG_LAYOUT_REPEATS = true;
-    static final boolean DEBUG_SURFACE_TRACE = false;
-    static final boolean DEBUG_WINDOW_TRACE = false;
-    static final boolean DEBUG_TASK_MOVEMENT = false;
-    static final boolean DEBUG_STACK = false;
-    static final boolean SHOW_SURFACE_ALLOC = false;
-    static final boolean SHOW_TRANSACTIONS = false;
-    static final boolean SHOW_LIGHT_TRANSACTIONS = false || SHOW_TRANSACTIONS;
-    static final boolean HIDE_STACK_CRAWLS = true;
-    static final int LAYOUT_REPEAT_THRESHOLD = 4;
-
-    static final boolean PROFILE_ORIENTATION = false;
-    static final boolean localLOGV = DEBUG;
-
-    /** How much to multiply the policy's type layer, to reserve room
-     * for multiple windows of the same type and Z-ordering adjustment
-     * with TYPE_LAYER_OFFSET. */
-    static final int TYPE_LAYER_MULTIPLIER = 10000;
-
-    /** Offset from TYPE_LAYER_MULTIPLIER for moving a group of windows above
-     * or below others in the same layer. */
-    static final int TYPE_LAYER_OFFSET = 1000;
-
-    /** How much to increment the layer for each window, to reserve room
-     * for effect surfaces between them.
-     */
-    static final int WINDOW_LAYER_MULTIPLIER = 5;
-
-    /**
-     * Dim surface layer is immediately below target window.
-     */
-    static final int LAYER_OFFSET_DIM = 1;
-
-    /**
-     * Blur surface layer is immediately below dim layer.
-     */
-    static final int LAYER_OFFSET_BLUR = 2;
-
-    /**
-     * FocusedStackFrame layer is immediately above focused window.
-     */
-    static final int LAYER_OFFSET_FOCUSED_STACK = 1;
-
-    /**
-     * Animation thumbnail is as far as possible below the window above
-     * the thumbnail (or in other words as far as possible above the window
-     * below it).
-     */
-    static final int LAYER_OFFSET_THUMBNAIL = WINDOW_LAYER_MULTIPLIER-1;
-
-    /**
-     * Layer at which to put the rotation freeze snapshot.
-     */
-    static final int FREEZE_LAYER = (TYPE_LAYER_MULTIPLIER * 200) + 1;
-
-    /**
-     * Layer at which to put the mask for emulated screen sizes.
-     */
-    static final int MASK_LAYER = TYPE_LAYER_MULTIPLIER * 200;
-
-    /** The maximum length we will accept for a loaded animation duration:
-     * this is 10 seconds.
-     */
-    static final int MAX_ANIMATION_DURATION = 10*1000;
-
-    /** Amount of time (in milliseconds) to animate the fade-in-out transition for
-     * compatible windows.
-     */
-    static final int DEFAULT_FADE_IN_OUT_DURATION = 400;
-
-    /** Amount of time (in milliseconds) to delay before declaring a window freeze timeout. */
-    static final int WINDOW_FREEZE_TIMEOUT_DURATION = 2000;
-
-    /** Amount of time (in milliseconds) to delay before declaring a starting window leaked. */
-    static final int STARTING_WINDOW_TIMEOUT_DURATION = 10000;
-
-    /**
-     * If true, the window manager will do its own custom freezing and general
-     * management of the screen during rotation.
-     */
-    static final boolean CUSTOM_SCREEN_ROTATION = true;
-
-    // Maximum number of milliseconds to wait for input devices to be enumerated before
-    // proceding with safe mode detection.
-    private static final int INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS = 1000;
-
-    // Default input dispatching timeout in nanoseconds.
-    static final long DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS = 5000 * 1000000L;
-
-    /** Minimum value for createStack and resizeStack weight value */
-    public static final float STACK_WEIGHT_MIN = 0.2f;
-
-    /** Maximum value for createStack and resizeStack weight value */
-    public static final float STACK_WEIGHT_MAX = 0.8f;
-
-    static final int UPDATE_FOCUS_NORMAL = 0;
-    static final int UPDATE_FOCUS_WILL_ASSIGN_LAYERS = 1;
-    static final int UPDATE_FOCUS_PLACING_SURFACES = 2;
-    static final int UPDATE_FOCUS_WILL_PLACE_SURFACES = 3;
-
-    private static final String SYSTEM_SECURE = "ro.secure";
-    private static final String SYSTEM_DEBUGGABLE = "ro.debuggable";
-
-    private static final String DENSITY_OVERRIDE = "ro.config.density_override";
-    private static final String SIZE_OVERRIDE = "ro.config.size_override";
-
-    private static final int MAX_SCREENSHOT_RETRIES = 3;
-
-    final private KeyguardDisableHandler mKeyguardDisableHandler;
-
-    private final boolean mHeadless;
-
-    final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        @Override
-        public void onReceive(Context context, Intent intent) {
-            final String action = intent.getAction();
-            if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals(action)) {
-                mKeyguardDisableHandler.sendEmptyMessage(
-                    KeyguardDisableHandler.KEYGUARD_POLICY_CHANGED);
-            }
-        }
-    };
-
-    // Current user when multi-user is enabled. Don't show windows of non-current user.
-    int mCurrentUserId;
-
-    final Context mContext;
-
-    final boolean mHaveInputMethods;
-
-    final boolean mAllowBootMessages;
-
-    final boolean mLimitedAlphaCompositing;
-
-    final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
-
-    final IActivityManager mActivityManager;
-
-    final IBatteryStats mBatteryStats;
-
-    final AppOpsManager mAppOps;
-
-    final DisplaySettings mDisplaySettings;
-
-    /**
-     * All currently active sessions with clients.
-     */
-    final HashSet<Session> mSessions = new HashSet<Session>();
-
-    /**
-     * Mapping from an IWindow IBinder to the server's Window object.
-     * This is also used as the lock for all of our state.
-     * NOTE: Never call into methods that lock ActivityManagerService while holding this object.
-     */
-    final HashMap<IBinder, WindowState> mWindowMap = new HashMap<IBinder, WindowState>();
-
-    /**
-     * Mapping from a token IBinder to a WindowToken object.
-     */
-    final HashMap<IBinder, WindowToken> mTokenMap = new HashMap<IBinder, WindowToken>();
-
-    /**
-     * List of window tokens that have finished starting their application,
-     * and now need to have the policy remove their windows.
-     */
-    final ArrayList<AppWindowToken> mFinishedStarting = new ArrayList<AppWindowToken>();
-
-    /**
-     * Fake windows added to the window manager.  Note: ordered from top to
-     * bottom, opposite of mWindows.
-     */
-    final ArrayList<FakeWindowImpl> mFakeWindows = new ArrayList<FakeWindowImpl>();
-
-    /**
-     * Windows that are being resized.  Used so we can tell the client about
-     * the resize after closing the transaction in which we resized the
-     * underlying surface.
-     */
-    final ArrayList<WindowState> mResizingWindows = new ArrayList<WindowState>();
-
-    /**
-     * Windows whose animations have ended and now must be removed.
-     */
-    final ArrayList<WindowState> mPendingRemove = new ArrayList<WindowState>();
-
-    /**
-     * Used when processing mPendingRemove to avoid working on the original array.
-     */
-    WindowState[] mPendingRemoveTmp = new WindowState[20];
-
-    /**
-     * Windows whose surface should be destroyed.
-     */
-    final ArrayList<WindowState> mDestroySurface = new ArrayList<WindowState>();
-
-    /**
-     * Windows that have lost input focus and are waiting for the new
-     * focus window to be displayed before they are told about this.
-     */
-    ArrayList<WindowState> mLosingFocus = new ArrayList<WindowState>();
-
-    /**
-     * This is set when we have run out of memory, and will either be an empty
-     * list or contain windows that need to be force removed.
-     */
-    ArrayList<WindowState> mForceRemoves;
-
-    /**
-     * Windows that clients are waiting to have drawn.
-     */
-    ArrayList<Pair<WindowState, IRemoteCallback>> mWaitingForDrawn
-            = new ArrayList<Pair<WindowState, IRemoteCallback>>();
-
-    /**
-     * Windows that have called relayout() while we were running animations,
-     * so we need to tell when the animation is done.
-     */
-    final ArrayList<WindowState> mRelayoutWhileAnimating = new ArrayList<WindowState>();
-
-    /**
-     * Used when rebuilding window list to keep track of windows that have
-     * been removed.
-     */
-    WindowState[] mRebuildTmp = new WindowState[20];
-
-    IInputMethodManager mInputMethodManager;
-
-    DisplayMagnifier mDisplayMagnifier;
-
-    final SurfaceSession mFxSession;
-    Watermark mWatermark;
-    StrictModeFlash mStrictModeFlash;
-    FocusedStackFrame mFocusedStackFrame;
-
-    int mFocusedStackLayer;
-
-    final float[] mTmpFloats = new float[9];
-    final Rect mTmpContentRect = new Rect();
-
-    boolean mDisplayReady;
-    boolean mSafeMode;
-    boolean mDisplayEnabled = false;
-    boolean mSystemBooted = false;
-    boolean mForceDisplayEnabled = false;
-    boolean mShowingBootMessages = false;
-
-    String mLastANRState;
-
-    /** All DisplayContents in the world, kept here */
-    SparseArray<DisplayContent> mDisplayContents = new SparseArray<DisplayContent>(2);
-
-    int mRotation = 0;
-    int mForcedAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-    boolean mAltOrientation = false;
-    ArrayList<IRotationWatcher> mRotationWatchers
-            = new ArrayList<IRotationWatcher>();
-    int mDeferredRotationPauseCount;
-
-    int mSystemDecorLayer = 0;
-    final Rect mScreenRect = new Rect();
-
-    boolean mTraversalScheduled = false;
-    boolean mDisplayFrozen = false;
-    long mDisplayFreezeTime = 0;
-    int mLastDisplayFreezeDuration = 0;
-    Object mLastFinishedFreezeSource = null;
-    boolean mWaitingForConfig = false;
-    boolean mWindowsFreezingScreen = false;
-    boolean mClientFreezingScreen = false;
-    int mAppsFreezingScreen = 0;
-    int mLastWindowForcedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-
-    int mLayoutSeq = 0;
-
-    int mLastStatusBarVisibility = 0;
-
-    // State while inside of layoutAndPlaceSurfacesLocked().
-    boolean mFocusMayChange;
-
-    Configuration mCurConfiguration = new Configuration();
-
-    // This is held as long as we have the screen frozen, to give us time to
-    // perform a rotation animation when turning off shows the lock screen which
-    // changes the orientation.
-    private final PowerManager.WakeLock mScreenFrozenLock;
-
-    final AppTransition mAppTransition;
-    boolean mStartingIconInTransition = false;
-    boolean mSkipAppTransitionAnimation = false;
-
-    final ArrayList<AppWindowToken> mOpeningApps = new ArrayList<AppWindowToken>();
-    final ArrayList<AppWindowToken> mClosingApps = new ArrayList<AppWindowToken>();
-
-    boolean mIsTouchDevice;
-
-    final DisplayMetrics mDisplayMetrics = new DisplayMetrics();
-    final DisplayMetrics mRealDisplayMetrics = new DisplayMetrics();
-    final DisplayMetrics mTmpDisplayMetrics = new DisplayMetrics();
-    final DisplayMetrics mCompatDisplayMetrics = new DisplayMetrics();
-
-    final H mH = new H();
-
-    final Choreographer mChoreographer = Choreographer.getInstance();
-
-    WindowState mCurrentFocus = null;
-    WindowState mLastFocus = null;
-
-    /** This just indicates the window the input method is on top of, not
-     * necessarily the window its input is going to. */
-    WindowState mInputMethodTarget = null;
-
-    /** If true hold off on modifying the animation layer of mInputMethodTarget */
-    boolean mInputMethodTargetWaitingAnim;
-    int mInputMethodAnimLayerAdjustment;
-
-    WindowState mInputMethodWindow = null;
-    final ArrayList<WindowState> mInputMethodDialogs = new ArrayList<WindowState>();
-
-    boolean mHardKeyboardAvailable;
-    boolean mHardKeyboardEnabled;
-    OnHardKeyboardStatusChangeListener mHardKeyboardStatusChangeListener;
-
-    final ArrayList<WindowToken> mWallpaperTokens = new ArrayList<WindowToken>();
-
-    // If non-null, this is the currently visible window that is associated
-    // with the wallpaper.
-    WindowState mWallpaperTarget = null;
-    // If non-null, we are in the middle of animating from one wallpaper target
-    // to another, and this is the lower one in Z-order.
-    WindowState mLowerWallpaperTarget = null;
-    // If non-null, we are in the middle of animating from one wallpaper target
-    // to another, and this is the higher one in Z-order.
-    WindowState mUpperWallpaperTarget = null;
-    int mWallpaperAnimLayerAdjustment;
-    float mLastWallpaperX = -1;
-    float mLastWallpaperY = -1;
-    float mLastWallpaperXStep = -1;
-    float mLastWallpaperYStep = -1;
-    // This is set when we are waiting for a wallpaper to tell us it is done
-    // changing its scroll position.
-    WindowState mWaitingOnWallpaper;
-    // The last time we had a timeout when waiting for a wallpaper.
-    long mLastWallpaperTimeoutTime;
-    // We give a wallpaper up to 150ms to finish scrolling.
-    static final long WALLPAPER_TIMEOUT = 150;
-    // Time we wait after a timeout before trying to wait again.
-    static final long WALLPAPER_TIMEOUT_RECOVERY = 10000;
-    boolean mAnimateWallpaperWithTarget;
-
-    AppWindowToken mFocusedApp = null;
-
-    PowerManagerService mPowerManager;
-
-    float mWindowAnimationScale = 1.0f;
-    float mTransitionAnimationScale = 1.0f;
-    float mAnimatorDurationScale = 1.0f;
-
-    final InputManagerService mInputManager;
-    final DisplayManagerService mDisplayManagerService;
-    final DisplayManager mDisplayManager;
-
-    // Who is holding the screen on.
-    Session mHoldingScreenOn;
-    PowerManager.WakeLock mHoldingScreenWakeLock;
-
-    boolean mTurnOnScreen;
-
-    DragState mDragState = null;
-
-    // For frozen screen animations.
-    int mExitAnimId, mEnterAnimId;
-
-    /** Pulled out of performLayoutAndPlaceSurfacesLockedInner in order to refactor into multiple
-     * methods. */
-    class LayoutFields {
-        static final int SET_UPDATE_ROTATION                = 1 << 0;
-        static final int SET_WALLPAPER_MAY_CHANGE           = 1 << 1;
-        static final int SET_FORCE_HIDING_CHANGED           = 1 << 2;
-        static final int SET_ORIENTATION_CHANGE_COMPLETE    = 1 << 3;
-        static final int SET_TURN_ON_SCREEN                 = 1 << 4;
-        static final int SET_WALLPAPER_ACTION_PENDING       = 1 << 5;
-
-        boolean mWallpaperForceHidingChanged = false;
-        boolean mWallpaperMayChange = false;
-        boolean mOrientationChangeComplete = true;
-        Object mLastWindowFreezeSource = null;
-        private Session mHoldScreen = null;
-        private boolean mObscured = false;
-        private boolean mSyswin = false;
-        private float mScreenBrightness = -1;
-        private float mButtonBrightness = -1;
-        private long mUserActivityTimeout = -1;
-        private boolean mUpdateRotation = false;
-        boolean mWallpaperActionPending = false;
-
-        // Set to true when the display contains content to show the user.
-        // When false, the display manager may choose to mirror or blank the display.
-        boolean mDisplayHasContent = false;
-
-        // Only set while traversing the default display based on its content.
-        // Affects the behavior of mirroring on secondary displays.
-        boolean mObscureApplicationContentOnSecondaryDisplays = false;
-    }
-    final LayoutFields mInnerFields = new LayoutFields();
-
-    boolean mAnimationScheduled;
-
-    /** Skip repeated AppWindowTokens initialization. Note that AppWindowsToken's version of this
-     * is a long initialized to Long.MIN_VALUE so that it doesn't match this value on startup. */
-    private int mTransactionSequence;
-
-    /** Only do a maximum of 6 repeated layouts. After that quit */
-    private int mLayoutRepeatCount;
-
-    final WindowAnimator mAnimator;
-
-    SparseArray<Task> mTaskIdToTask = new SparseArray<Task>();
-    SparseArray<TaskStack> mStackIdToStack = new SparseArray<TaskStack>();
-
-    private final PointerEventDispatcher mPointerEventDispatcher;
-
-    final class DragInputEventReceiver extends InputEventReceiver {
-        public DragInputEventReceiver(InputChannel inputChannel, Looper looper) {
-            super(inputChannel, looper);
-        }
-
-        @Override
-        public void onInputEvent(InputEvent event) {
-            boolean handled = false;
-            try {
-                if (event instanceof MotionEvent
-                        && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0
-                        && mDragState != null) {
-                    final MotionEvent motionEvent = (MotionEvent)event;
-                    boolean endDrag = false;
-                    final float newX = motionEvent.getRawX();
-                    final float newY = motionEvent.getRawY();
-
-                    switch (motionEvent.getAction()) {
-                    case MotionEvent.ACTION_DOWN: {
-                        if (DEBUG_DRAG) {
-                            Slog.w(TAG, "Unexpected ACTION_DOWN in drag layer");
-                        }
-                    } break;
-
-                    case MotionEvent.ACTION_MOVE: {
-                        synchronized (mWindowMap) {
-                            // move the surface and tell the involved window(s) where we are
-                            mDragState.notifyMoveLw(newX, newY);
-                        }
-                    } break;
-
-                    case MotionEvent.ACTION_UP: {
-                        if (DEBUG_DRAG) Slog.d(TAG, "Got UP on move channel; dropping at "
-                                + newX + "," + newY);
-                        synchronized (mWindowMap) {
-                            endDrag = mDragState.notifyDropLw(newX, newY);
-                        }
-                    } break;
-
-                    case MotionEvent.ACTION_CANCEL: {
-                        if (DEBUG_DRAG) Slog.d(TAG, "Drag cancelled!");
-                        endDrag = true;
-                    } break;
-                    }
-
-                    if (endDrag) {
-                        if (DEBUG_DRAG) Slog.d(TAG, "Drag ended; tearing down state");
-                        // tell all the windows that the drag has ended
-                        synchronized (mWindowMap) {
-                            mDragState.endDragLw();
-                        }
-                    }
-
-                    handled = true;
-                }
-            } catch (Exception e) {
-                Slog.e(TAG, "Exception caught by drag handleMotion", e);
-            } finally {
-                finishInputEvent(event, handled);
-            }
-        }
-    }
-
-    /**
-     * Whether the UI is currently running in touch mode (not showing
-     * navigational focus because the user is directly pressing the screen).
-     */
-    boolean mInTouchMode = true;
-
-    private ViewServer mViewServer;
-    private final ArrayList<WindowChangeListener> mWindowChangeListeners =
-        new ArrayList<WindowChangeListener>();
-    private boolean mWindowsChanged = false;
-
-    public interface WindowChangeListener {
-        public void windowsChanged();
-        public void focusChanged();
-    }
-
-    final Configuration mTempConfiguration = new Configuration();
-
-    // The desired scaling factor for compatible apps.
-    float mCompatibleScreenScale;
-
-    // If true, only the core apps and services are being launched because the device
-    // is in a special boot mode, such as being encrypted or waiting for a decryption password.
-    // For example, when this flag is true, there will be no wallpaper service.
-    final boolean mOnlyCore;
-
-    public static WindowManagerService main(final Context context,
-            final PowerManagerService pm, final DisplayManagerService dm,
-            final InputManagerService im, final Handler wmHandler,
-            final boolean haveInputMethods, final boolean showBootMsgs,
-            final boolean onlyCore) {
-        final WindowManagerService[] holder = new WindowManagerService[1];
-        wmHandler.runWithScissors(new Runnable() {
-            @Override
-            public void run() {
-                holder[0] = new WindowManagerService(context, pm, dm, im,
-                        haveInputMethods, showBootMsgs, onlyCore);
-            }
-        }, 0);
-        return holder[0];
-    }
-
-    private void initPolicy(Handler uiHandler) {
-        uiHandler.runWithScissors(new Runnable() {
-            @Override
-            public void run() {
-                WindowManagerPolicyThread.set(Thread.currentThread(), Looper.myLooper());
-
-                mPolicy.init(mContext, WindowManagerService.this, WindowManagerService.this);
-                mAnimator.mAboveUniverseLayer = mPolicy.getAboveUniverseLayer()
-                        * TYPE_LAYER_MULTIPLIER
-                        + TYPE_LAYER_OFFSET;
-            }
-        }, 0);
-    }
-
-    private WindowManagerService(Context context, PowerManagerService pm,
-            DisplayManagerService displayManager, InputManagerService inputManager,
-            boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) {
-        mContext = context;
-        mHaveInputMethods = haveInputMethods;
-        mAllowBootMessages = showBootMsgs;
-        mOnlyCore = onlyCore;
-        mLimitedAlphaCompositing = context.getResources().getBoolean(
-                com.android.internal.R.bool.config_sf_limitedAlpha);
-        mInputManager = inputManager; // Must be before createDisplayContentLocked.
-        mDisplayManagerService = displayManager;
-        mHeadless = displayManager.isHeadless();
-        mDisplaySettings = new DisplaySettings(context);
-        mDisplaySettings.readSettingsLocked();
-
-        mPointerEventDispatcher = new PointerEventDispatcher(mInputManager.monitorInput(TAG));
-
-        mFxSession = new SurfaceSession();
-        mDisplayManager = (DisplayManager)context.getSystemService(Context.DISPLAY_SERVICE);
-        mDisplayManager.registerDisplayListener(this, null);
-        Display[] displays = mDisplayManager.getDisplays();
-        for (Display display : displays) {
-            createDisplayContentLocked(display);
-        }
-
-        mKeyguardDisableHandler = new KeyguardDisableHandler(mContext, mPolicy);
-
-        mPowerManager = pm;
-        mPowerManager.setPolicy(mPolicy);
-        PowerManager pmc = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
-        mScreenFrozenLock = pmc.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SCREEN_FROZEN");
-        mScreenFrozenLock.setReferenceCounted(false);
-
-        mAppTransition = new AppTransition(context, mH);
-
-        mActivityManager = ActivityManagerNative.getDefault();
-        mBatteryStats = BatteryStatsService.getService();
-        mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
-        mAppOps.startWatchingMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, null,
-                new AppOpsManager.OnOpChangedInternalListener() {
-                    @Override
-                    public void onOpChanged(int op, String packageName) {
-                        updateAppOpsState();
-                    }
-                }
-        );
-
-        // Get persisted window scale setting
-        mWindowAnimationScale = Settings.Global.getFloat(context.getContentResolver(),
-                Settings.Global.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
-        mTransitionAnimationScale = Settings.Global.getFloat(context.getContentResolver(),
-                Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
-        setAnimatorDurationScale(Settings.Global.getFloat(context.getContentResolver(),
-                Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale));
-
-        // Track changes to DevicePolicyManager state so we can enable/disable keyguard.
-        IntentFilter filter = new IntentFilter();
-        filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
-        mContext.registerReceiver(mBroadcastReceiver, filter);
-
-        mHoldingScreenWakeLock = pmc.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
-                | PowerManager.ON_AFTER_RELEASE, TAG);
-        mHoldingScreenWakeLock.setReferenceCounted(false);
-
-        mAnimator = new WindowAnimator(this);
-
-        initPolicy(UiThread.getHandler());
-
-        // Add ourself to the Watchdog monitors.
-        Watchdog.getInstance().addMonitor(this);
-
-        SurfaceControl.openTransaction();
-        try {
-            createWatermarkInTransaction();
-            mFocusedStackFrame = new FocusedStackFrame(
-                    getDefaultDisplayContentLocked().getDisplay(), mFxSession);
-        } finally {
-            SurfaceControl.closeTransaction();
-        }
-    }
-
-    public InputMonitor getInputMonitor() {
-        return mInputMonitor;
-    }
-
-    @Override
-    public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
-            throws RemoteException {
-        try {
-            return super.onTransact(code, data, reply, flags);
-        } catch (RuntimeException e) {
-            // The window manager only throws security exceptions, so let's
-            // log all others.
-            if (!(e instanceof SecurityException)) {
-                Slog.wtf(TAG, "Window Manager Crash", e);
-            }
-            throw e;
-        }
-    }
-
-    private void placeWindowAfter(WindowState pos, WindowState window) {
-        final WindowList windows = pos.getWindowList();
-        final int i = windows.indexOf(pos);
-        if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
-            TAG, "Adding window " + window + " at "
-            + (i+1) + " of " + windows.size() + " (after " + pos + ")");
-        windows.add(i+1, window);
-        mWindowsChanged = true;
-    }
-
-    private void placeWindowBefore(WindowState pos, WindowState window) {
-        final WindowList windows = pos.getWindowList();
-        int i = windows.indexOf(pos);
-        if (DEBUG_FOCUS || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
-            TAG, "Adding window " + window + " at "
-            + i + " of " + windows.size() + " (before " + pos + ")");
-        if (i < 0) {
-            Slog.w(TAG, "placeWindowBefore: Unable to find " + pos + " in " + windows);
-            i = 0;
-        }
-        windows.add(i, window);
-        mWindowsChanged = true;
-    }
-
-    //This method finds out the index of a window that has the same app token as
-    //win. used for z ordering the windows in mWindows
-    private int findIdxBasedOnAppTokens(WindowState win) {
-        WindowList windows = win.getWindowList();
-        for(int j = windows.size() - 1; j >= 0; j--) {
-            WindowState wentry = windows.get(j);
-            if(wentry.mAppToken == win.mAppToken) {
-                return j;
-            }
-        }
-        return -1;
-    }
-
-    /**
-     * Return the list of Windows from the passed token on the given Display.
-     * @param token The token with all the windows.
-     * @param displayContent The display we are interested in.
-     * @return List of windows from token that are on displayContent.
-     */
-    WindowList getTokenWindowsOnDisplay(WindowToken token, DisplayContent displayContent) {
-        final WindowList windowList = new WindowList();
-        final int count = token.windows.size();
-        for (int i = 0; i < count; i++) {
-            final WindowState win = token.windows.get(i);
-            if (win.mDisplayContent == displayContent) {
-                windowList.add(win);
-            }
-        }
-        return windowList;
-    }
-
-    /**
-     * Recursive search through a WindowList and all of its windows' children.
-     * @param targetWin The window to search for.
-     * @param windows The list to search.
-     * @return The index of win in windows or of the window that is an ancestor of win.
-     */
-    private int indexOfWinInWindowList(WindowState targetWin, WindowList windows) {
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            final WindowState w = windows.get(i);
-            if (w == targetWin) {
-                return i;
-            }
-            if (!w.mChildWindows.isEmpty()) {
-                if (indexOfWinInWindowList(targetWin, w.mChildWindows) >= 0) {
-                    return i;
-                }
-            }
-        }
-        return -1;
-    }
-
-    private int addAppWindowToListLocked(final WindowState win) {
-        final IWindow client = win.mClient;
-        final WindowToken token = win.mToken;
-        final DisplayContent displayContent = win.mDisplayContent;
-
-        final WindowList windows = win.getWindowList();
-        final int N = windows.size();
-        WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent);
-        int tokenWindowsPos = 0;
-        int windowListPos = tokenWindowList.size();
-        if (!tokenWindowList.isEmpty()) {
-            // If this application has existing windows, we
-            // simply place the new window on top of them... but
-            // keep the starting window on top.
-            if (win.mAttrs.type == TYPE_BASE_APPLICATION) {
-                // Base windows go behind everything else.
-                WindowState lowestWindow = tokenWindowList.get(0);
-                placeWindowBefore(lowestWindow, win);
-                tokenWindowsPos = indexOfWinInWindowList(lowestWindow, token.windows);
-            } else {
-                AppWindowToken atoken = win.mAppToken;
-                WindowState lastWindow = tokenWindowList.get(windowListPos - 1);
-                if (atoken != null && lastWindow == atoken.startingWindow) {
-                    placeWindowBefore(lastWindow, win);
-                    tokenWindowsPos = indexOfWinInWindowList(lastWindow, token.windows);
-                } else {
-                    int newIdx = findIdxBasedOnAppTokens(win);
-                    //there is a window above this one associated with the same
-                    //apptoken note that the window could be a floating window
-                    //that was created later or a window at the top of the list of
-                    //windows associated with this token.
-                    if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
-                            "not Base app: Adding window " + win + " at " + (newIdx + 1) + " of " +
-                            N);
-                    windows.add(newIdx + 1, win);
-                    if (newIdx < 0) {
-                        // No window from token found on win's display.
-                        tokenWindowsPos = 0;
-                    } else {
-                        tokenWindowsPos = indexOfWinInWindowList(
-                                windows.get(newIdx), token.windows) + 1;
-                    }
-                    mWindowsChanged = true;
-                }
-            }
-            return tokenWindowsPos;
-        }
-
-        // No windows from this token on this display
-        if (localLOGV) Slog.v(TAG, "Figuring out where to add app window " + client.asBinder()
-                + " (token=" + token + ")");
-        // Figure out where the window should go, based on the
-        // order of applications.
-        WindowState pos = null;
-
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        int taskNdx;
-        int tokenNdx = -1;
-        for (taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            for (tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
-                final AppWindowToken t = tokens.get(tokenNdx);
-                if (t == token) {
-                    --tokenNdx;
-                    if (tokenNdx < 0) {
-                        --taskNdx;
-                        if (taskNdx >= 0) {
-                            tokenNdx = tasks.get(taskNdx).mAppTokens.size() - 1;
-                        }
-                    }
-                    break;
-                }
-
-                // We haven't reached the token yet; if this token
-                // is not going to the bottom and has windows on this display, we can
-                // use it as an anchor for when we do reach the token.
-                tokenWindowList = getTokenWindowsOnDisplay(t, displayContent);
-                if (!t.sendingToBottom && tokenWindowList.size() > 0) {
-                    pos = tokenWindowList.get(0);
-                }
-            }
-            if (tokenNdx >= 0) {
-                // early exit
-                break;
-            }
-        }
-
-        // We now know the index into the apps.  If we found
-        // an app window above, that gives us the position; else
-        // we need to look some more.
-        if (pos != null) {
-            // Move behind any windows attached to this one.
-            WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
-            if (atoken != null) {
-                tokenWindowList =
-                        getTokenWindowsOnDisplay(atoken, displayContent);
-                final int NC = tokenWindowList.size();
-                if (NC > 0) {
-                    WindowState bottom = tokenWindowList.get(0);
-                    if (bottom.mSubLayer < 0) {
-                        pos = bottom;
-                    }
-                }
-            }
-            placeWindowBefore(pos, win);
-            return tokenWindowsPos;
-        }
-
-        // Continue looking down until we find the first
-        // token that has windows on this display.
-        for ( ; taskNdx >= 0; --taskNdx) {
-            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            for ( ; tokenNdx >= 0; --tokenNdx) {
-                final AppWindowToken t = tokens.get(tokenNdx);
-                tokenWindowList = getTokenWindowsOnDisplay(t, displayContent);
-                final int NW = tokenWindowList.size();
-                if (NW > 0) {
-                    pos = tokenWindowList.get(NW-1);
-                    break;
-                }
-            }
-            if (tokenNdx >= 0) {
-                // found
-                break;
-            }
-        }
-
-        if (pos != null) {
-            // Move in front of any windows attached to this
-            // one.
-            WindowToken atoken = mTokenMap.get(pos.mClient.asBinder());
-            if (atoken != null) {
-                final int NC = atoken.windows.size();
-                if (NC > 0) {
-                    WindowState top = atoken.windows.get(NC-1);
-                    if (top.mSubLayer >= 0) {
-                        pos = top;
-                    }
-                }
-            }
-            placeWindowAfter(pos, win);
-            return tokenWindowsPos;
-        }
-
-        // Just search for the start of this layer.
-        final int myLayer = win.mBaseLayer;
-        int i;
-        for (i = 0; i < N; i++) {
-            WindowState w = windows.get(i);
-            if (w.mBaseLayer > myLayer) {
-                break;
-            }
-        }
-        if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
-                "Based on layer: Adding window " + win + " at " + i + " of " + N);
-        windows.add(i, win);
-        mWindowsChanged = true;
-        return tokenWindowsPos;
-    }
-
-    private void addFreeWindowToListLocked(final WindowState win) {
-        final WindowList windows = win.getWindowList();
-
-        // Figure out where window should go, based on layer.
-        final int myLayer = win.mBaseLayer;
-        int i;
-        for (i = windows.size() - 1; i >= 0; i--) {
-            if (windows.get(i).mBaseLayer <= myLayer) {
-                break;
-            }
-        }
-        i++;
-        if (DEBUG_FOCUS_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG,
-                "Free window: Adding window " + win + " at " + i + " of " + windows.size());
-        windows.add(i, win);
-        mWindowsChanged = true;
-    }
-
-    private void addAttachedWindowToListLocked(final WindowState win, boolean addToToken) {
-        final WindowToken token = win.mToken;
-        final DisplayContent displayContent = win.mDisplayContent;
-        final WindowState attached = win.mAttachedWindow;
-
-        WindowList tokenWindowList = getTokenWindowsOnDisplay(token, displayContent);
-
-        // Figure out this window's ordering relative to the window
-        // it is attached to.
-        final int NA = tokenWindowList.size();
-        final int sublayer = win.mSubLayer;
-        int largestSublayer = Integer.MIN_VALUE;
-        WindowState windowWithLargestSublayer = null;
-        int i;
-        for (i = 0; i < NA; i++) {
-            WindowState w = tokenWindowList.get(i);
-            final int wSublayer = w.mSubLayer;
-            if (wSublayer >= largestSublayer) {
-                largestSublayer = wSublayer;
-                windowWithLargestSublayer = w;
-            }
-            if (sublayer < 0) {
-                // For negative sublayers, we go below all windows
-                // in the same sublayer.
-                if (wSublayer >= sublayer) {
-                    if (addToToken) {
-                        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
-                        token.windows.add(i, win);
-                    }
-                    placeWindowBefore(wSublayer >= 0 ? attached : w, win);
-                    break;
-                }
-            } else {
-                // For positive sublayers, we go above all windows
-                // in the same sublayer.
-                if (wSublayer > sublayer) {
-                    if (addToToken) {
-                        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
-                        token.windows.add(i, win);
-                    }
-                    placeWindowBefore(w, win);
-                    break;
-                }
-            }
-        }
-        if (i >= NA) {
-            if (addToToken) {
-                if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
-                token.windows.add(win);
-            }
-            if (sublayer < 0) {
-                placeWindowBefore(attached, win);
-            } else {
-                placeWindowAfter(largestSublayer >= 0
-                                 ? windowWithLargestSublayer
-                                 : attached,
-                                 win);
-            }
-        }
-    }
-
-    private void addWindowToListInOrderLocked(final WindowState win, boolean addToToken) {
-        if (DEBUG_FOCUS_LIGHT) Slog.d(TAG, "addWindowToListInOrderLocked: win=" + win +
-                " Callers=" + Debug.getCallers(4));
-        if (win.mAttachedWindow == null) {
-            final WindowToken token = win.mToken;
-            int tokenWindowsPos = 0;
-            if (token.appWindowToken != null) {
-                tokenWindowsPos = addAppWindowToListLocked(win);
-            } else {
-                addFreeWindowToListLocked(win);
-            }
-            if (addToToken) {
-                if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + win + " to " + token);
-                token.windows.add(tokenWindowsPos, win);
-            }
-        } else {
-            addAttachedWindowToListLocked(win, addToToken);
-        }
-
-        if (win.mAppToken != null && addToToken) {
-            win.mAppToken.allAppWindows.add(win);
-        }
-    }
-
-    static boolean canBeImeTarget(WindowState w) {
-        final int fl = w.mAttrs.flags
-                & (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM);
-        if (fl == 0 || fl == (FLAG_NOT_FOCUSABLE|FLAG_ALT_FOCUSABLE_IM)
-                || w.mAttrs.type == TYPE_APPLICATION_STARTING) {
-            if (DEBUG_INPUT_METHOD) {
-                Slog.i(TAG, "isVisibleOrAdding " + w + ": " + w.isVisibleOrAdding());
-                if (!w.isVisibleOrAdding()) {
-                    Slog.i(TAG, "  mSurface=" + w.mWinAnimator.mSurfaceControl
-                            + " relayoutCalled=" + w.mRelayoutCalled + " viewVis=" + w.mViewVisibility
-                            + " policyVis=" + w.mPolicyVisibility
-                            + " policyVisAfterAnim=" + w.mPolicyVisibilityAfterAnim
-                            + " attachHid=" + w.mAttachedHidden
-                            + " exiting=" + w.mExiting + " destroying=" + w.mDestroying);
-                    if (w.mAppToken != null) {
-                        Slog.i(TAG, "  mAppToken.hiddenRequested=" + w.mAppToken.hiddenRequested);
-                    }
-                }
-            }
-            return w.isVisibleOrAdding();
-        }
-        return false;
-    }
-
-    /**
-     * Dig through the WindowStates and find the one that the Input Method will target.
-     * @param willMove
-     * @return The index+1 in mWindows of the discovered target.
-     */
-    int findDesiredInputMethodWindowIndexLocked(boolean willMove) {
-        // TODO(multidisplay): Needs some serious rethought when the target and IME are not on the
-        // same display. Or even when the current IME/target are not on the same screen as the next
-        // IME/target. For now only look for input windows on the main screen.
-        WindowList windows = getDefaultWindowListLocked();
-        WindowState w = null;
-        int i;
-        for (i = windows.size() - 1; i >= 0; --i) {
-            WindowState win = windows.get(i);
-
-            if (DEBUG_INPUT_METHOD && willMove) Slog.i(TAG, "Checking window @" + i
-                    + " " + win + " fl=0x" + Integer.toHexString(win.mAttrs.flags));
-            if (canBeImeTarget(win)) {
-                w = win;
-                //Slog.i(TAG, "Putting input method here!");
-
-                // Yet more tricksyness!  If this window is a "starting"
-                // window, we do actually want to be on top of it, but
-                // it is not -really- where input will go.  So if the caller
-                // is not actually looking to move the IME, look down below
-                // for a real window to target...
-                if (!willMove
-                        && w.mAttrs.type == TYPE_APPLICATION_STARTING
-                        && i > 0) {
-                    WindowState wb = windows.get(i-1);
-                    if (wb.mAppToken == w.mAppToken && canBeImeTarget(wb)) {
-                        i--;
-                        w = wb;
-                    }
-                }
-                break;
-            }
-        }
-
-        // Now w is either mWindows[0] or an IME (or null if mWindows is empty).
-
-        if (DEBUG_INPUT_METHOD && willMove) Slog.v(TAG, "Proposed new IME target: " + w);
-
-        // Now, a special case -- if the last target's window is in the
-        // process of exiting, and is above the new target, keep on the
-        // last target to avoid flicker.  Consider for example a Dialog with
-        // the IME shown: when the Dialog is dismissed, we want to keep
-        // the IME above it until it is completely gone so it doesn't drop
-        // behind the dialog or its full-screen scrim.
-        final WindowState curTarget = mInputMethodTarget;
-        if (curTarget != null
-                && curTarget.isDisplayedLw()
-                && curTarget.isClosing()
-                && (w == null || curTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer)) {
-            if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Current target higher, not changing");
-            return windows.indexOf(curTarget) + 1;
-        }
-
-        if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Desired input method target="
-                + w + " willMove=" + willMove);
-
-        if (willMove && w != null) {
-            AppWindowToken token = curTarget == null ? null : curTarget.mAppToken;
-            if (token != null) {
-
-                // Now some fun for dealing with window animations that
-                // modify the Z order.  We need to look at all windows below
-                // the current target that are in this app, finding the highest
-                // visible one in layering.
-                WindowState highestTarget = null;
-                int highestPos = 0;
-                if (token.mAppAnimator.animating || token.mAppAnimator.animation != null) {
-                    WindowList curWindows = curTarget.getWindowList();
-                    int pos = curWindows.indexOf(curTarget);
-                    while (pos >= 0) {
-                        WindowState win = curWindows.get(pos);
-                        if (win.mAppToken != token) {
-                            break;
-                        }
-                        if (!win.mRemoved) {
-                            if (highestTarget == null || win.mWinAnimator.mAnimLayer >
-                                    highestTarget.mWinAnimator.mAnimLayer) {
-                                highestTarget = win;
-                                highestPos = pos;
-                            }
-                        }
-                        pos--;
-                    }
-                }
-
-                if (highestTarget != null) {
-                    if (DEBUG_INPUT_METHOD) Slog.v(TAG, mAppTransition + " " + highestTarget
-                            + " animating=" + highestTarget.mWinAnimator.isAnimating()
-                            + " layer=" + highestTarget.mWinAnimator.mAnimLayer
-                            + " new layer=" + w.mWinAnimator.mAnimLayer);
-
-                    if (mAppTransition.isTransitionSet()) {
-                        // If we are currently setting up for an animation,
-                        // hold everything until we can find out what will happen.
-                        mInputMethodTargetWaitingAnim = true;
-                        mInputMethodTarget = highestTarget;
-                        return highestPos + 1;
-                    } else if (highestTarget.mWinAnimator.isAnimating() &&
-                            highestTarget.mWinAnimator.mAnimLayer > w.mWinAnimator.mAnimLayer) {
-                        // If the window we are currently targeting is involved
-                        // with an animation, and it is on top of the next target
-                        // we will be over, then hold off on moving until
-                        // that is done.
-                        mInputMethodTargetWaitingAnim = true;
-                        mInputMethodTarget = highestTarget;
-                        return highestPos + 1;
-                    }
-                }
-            }
-        }
-
-        //Slog.i(TAG, "Placing input method @" + (i+1));
-        if (w != null) {
-            if (willMove) {
-                if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to "
-                        + w + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4)));
-                mInputMethodTarget = w;
-                mInputMethodTargetWaitingAnim = false;
-                if (w.mAppToken != null) {
-                    setInputMethodAnimLayerAdjustment(w.mAppToken.mAppAnimator.animLayerAdjustment);
-                } else {
-                    setInputMethodAnimLayerAdjustment(0);
-                }
-            }
-            return i+1;
-        }
-        if (willMove) {
-            if (DEBUG_INPUT_METHOD) Slog.w(TAG, "Moving IM target from " + curTarget + " to null."
-                    + (HIDE_STACK_CRAWLS ? "" : " Callers=" + Debug.getCallers(4)));
-            mInputMethodTarget = null;
-            setInputMethodAnimLayerAdjustment(0);
-        }
-        return -1;
-    }
-
-    void addInputMethodWindowToListLocked(WindowState win) {
-        int pos = findDesiredInputMethodWindowIndexLocked(true);
-        if (pos >= 0) {
-            win.mTargetAppToken = mInputMethodTarget.mAppToken;
-            if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
-                    TAG, "Adding input method window " + win + " at " + pos);
-            // TODO(multidisplay): IMEs are only supported on the default display.
-            getDefaultWindowListLocked().add(pos, win);
-            mWindowsChanged = true;
-            moveInputMethodDialogsLocked(pos+1);
-            return;
-        }
-        win.mTargetAppToken = null;
-        addWindowToListInOrderLocked(win, true);
-        moveInputMethodDialogsLocked(pos);
-    }
-
-    void setInputMethodAnimLayerAdjustment(int adj) {
-        if (DEBUG_LAYERS) Slog.v(TAG, "Setting im layer adj to " + adj);
-        mInputMethodAnimLayerAdjustment = adj;
-        WindowState imw = mInputMethodWindow;
-        if (imw != null) {
-            imw.mWinAnimator.mAnimLayer = imw.mLayer + adj;
-            if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
-                    + " anim layer: " + imw.mWinAnimator.mAnimLayer);
-            int wi = imw.mChildWindows.size();
-            while (wi > 0) {
-                wi--;
-                WindowState cw = imw.mChildWindows.get(wi);
-                cw.mWinAnimator.mAnimLayer = cw.mLayer + adj;
-                if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + cw
-                        + " anim layer: " + cw.mWinAnimator.mAnimLayer);
-            }
-        }
-        int di = mInputMethodDialogs.size();
-        while (di > 0) {
-            di --;
-            imw = mInputMethodDialogs.get(di);
-            imw.mWinAnimator.mAnimLayer = imw.mLayer + adj;
-            if (DEBUG_LAYERS) Slog.v(TAG, "IM win " + imw
-                    + " anim layer: " + imw.mWinAnimator.mAnimLayer);
-        }
-    }
-
-    private int tmpRemoveWindowLocked(int interestingPos, WindowState win) {
-        WindowList windows = win.getWindowList();
-        int wpos = windows.indexOf(win);
-        if (wpos >= 0) {
-            if (wpos < interestingPos) interestingPos--;
-            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing at " + wpos + ": " + win);
-            windows.remove(wpos);
-            mWindowsChanged = true;
-            int NC = win.mChildWindows.size();
-            while (NC > 0) {
-                NC--;
-                WindowState cw = win.mChildWindows.get(NC);
-                int cpos = windows.indexOf(cw);
-                if (cpos >= 0) {
-                    if (cpos < interestingPos) interestingPos--;
-                    if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Temp removing child at "
-                            + cpos + ": " + cw);
-                    windows.remove(cpos);
-                }
-            }
-        }
-        return interestingPos;
-    }
-
-    private void reAddWindowToListInOrderLocked(WindowState win) {
-        addWindowToListInOrderLocked(win, false);
-        // This is a hack to get all of the child windows added as well
-        // at the right position.  Child windows should be rare and
-        // this case should be rare, so it shouldn't be that big a deal.
-        WindowList windows = win.getWindowList();
-        int wpos = windows.indexOf(win);
-        if (wpos >= 0) {
-            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "ReAdd removing from " + wpos + ": " + win);
-            windows.remove(wpos);
-            mWindowsChanged = true;
-            reAddWindowLocked(wpos, win);
-        }
-    }
-
-    void logWindowList(final WindowList windows, String prefix) {
-        int N = windows.size();
-        while (N > 0) {
-            N--;
-            Slog.v(TAG, prefix + "#" + N + ": " + windows.get(N));
-        }
-    }
-
-    void moveInputMethodDialogsLocked(int pos) {
-        ArrayList<WindowState> dialogs = mInputMethodDialogs;
-
-        // TODO(multidisplay): IMEs are only supported on the default display.
-        WindowList windows = getDefaultWindowListLocked();
-        final int N = dialogs.size();
-        if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Removing " + N + " dialogs w/pos=" + pos);
-        for (int i=0; i<N; i++) {
-            pos = tmpRemoveWindowLocked(pos, dialogs.get(i));
-        }
-        if (DEBUG_INPUT_METHOD) {
-            Slog.v(TAG, "Window list w/pos=" + pos);
-            logWindowList(windows, "  ");
-        }
-
-        if (pos >= 0) {
-            final AppWindowToken targetAppToken = mInputMethodTarget.mAppToken;
-            if (pos < windows.size()) {
-                WindowState wp = windows.get(pos);
-                if (wp == mInputMethodWindow) {
-                    pos++;
-                }
-            }
-            if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Adding " + N + " dialogs at pos=" + pos);
-            for (int i=0; i<N; i++) {
-                WindowState win = dialogs.get(i);
-                win.mTargetAppToken = targetAppToken;
-                pos = reAddWindowLocked(pos, win);
-            }
-            if (DEBUG_INPUT_METHOD) {
-                Slog.v(TAG, "Final window list:");
-                logWindowList(windows, "  ");
-            }
-            return;
-        }
-        for (int i=0; i<N; i++) {
-            WindowState win = dialogs.get(i);
-            win.mTargetAppToken = null;
-            reAddWindowToListInOrderLocked(win);
-            if (DEBUG_INPUT_METHOD) {
-                Slog.v(TAG, "No IM target, final list:");
-                logWindowList(windows, "  ");
-            }
-        }
-    }
-
-    boolean moveInputMethodWindowsIfNeededLocked(boolean needAssignLayers) {
-        final WindowState imWin = mInputMethodWindow;
-        final int DN = mInputMethodDialogs.size();
-        if (imWin == null && DN == 0) {
-            return false;
-        }
-
-        // TODO(multidisplay): IMEs are only supported on the default display.
-        WindowList windows = getDefaultWindowListLocked();
-
-        int imPos = findDesiredInputMethodWindowIndexLocked(true);
-        if (imPos >= 0) {
-            // In this case, the input method windows are to be placed
-            // immediately above the window they are targeting.
-
-            // First check to see if the input method windows are already
-            // located here, and contiguous.
-            final int N = windows.size();
-            WindowState firstImWin = imPos < N
-                    ? windows.get(imPos) : null;
-
-            // Figure out the actual input method window that should be
-            // at the bottom of their stack.
-            WindowState baseImWin = imWin != null
-                    ? imWin : mInputMethodDialogs.get(0);
-            if (baseImWin.mChildWindows.size() > 0) {
-                WindowState cw = baseImWin.mChildWindows.get(0);
-                if (cw.mSubLayer < 0) baseImWin = cw;
-            }
-
-            if (firstImWin == baseImWin) {
-                // The windows haven't moved...  but are they still contiguous?
-                // First find the top IM window.
-                int pos = imPos+1;
-                while (pos < N) {
-                    if (!(windows.get(pos)).mIsImWindow) {
-                        break;
-                    }
-                    pos++;
-                }
-                pos++;
-                // Now there should be no more input method windows above.
-                while (pos < N) {
-                    if ((windows.get(pos)).mIsImWindow) {
-                        break;
-                    }
-                    pos++;
-                }
-                if (pos >= N) {
-                    // Z order is good.
-                    // The IM target window may be changed, so update the mTargetAppToken.
-                    if (imWin != null) {
-                        imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
-                    }
-                    return false;
-                }
-            }
-
-            if (imWin != null) {
-                if (DEBUG_INPUT_METHOD) {
-                    Slog.v(TAG, "Moving IM from " + imPos);
-                    logWindowList(windows, "  ");
-                }
-                imPos = tmpRemoveWindowLocked(imPos, imWin);
-                if (DEBUG_INPUT_METHOD) {
-                    Slog.v(TAG, "List after removing with new pos " + imPos + ":");
-                    logWindowList(windows, "  ");
-                }
-                imWin.mTargetAppToken = mInputMethodTarget.mAppToken;
-                reAddWindowLocked(imPos, imWin);
-                if (DEBUG_INPUT_METHOD) {
-                    Slog.v(TAG, "List after moving IM to " + imPos + ":");
-                    logWindowList(windows, "  ");
-                }
-                if (DN > 0) moveInputMethodDialogsLocked(imPos+1);
-            } else {
-                moveInputMethodDialogsLocked(imPos);
-            }
-
-        } else {
-            // In this case, the input method windows go in a fixed layer,
-            // because they aren't currently associated with a focus window.
-
-            if (imWin != null) {
-                if (DEBUG_INPUT_METHOD) Slog.v(TAG, "Moving IM from " + imPos);
-                tmpRemoveWindowLocked(0, imWin);
-                imWin.mTargetAppToken = null;
-                reAddWindowToListInOrderLocked(imWin);
-                if (DEBUG_INPUT_METHOD) {
-                    Slog.v(TAG, "List with no IM target:");
-                    logWindowList(windows, "  ");
-                }
-                if (DN > 0) moveInputMethodDialogsLocked(-1);
-            } else {
-                moveInputMethodDialogsLocked(-1);
-            }
-
-        }
-
-        if (needAssignLayers) {
-            assignLayersLocked(windows);
-        }
-
-        return true;
-    }
-
-    final boolean isWallpaperVisible(WindowState wallpaperTarget) {
-        if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper vis: target " + wallpaperTarget + ", obscured="
-                + (wallpaperTarget != null ? Boolean.toString(wallpaperTarget.mObscured) : "??")
-                + " anim=" + ((wallpaperTarget != null && wallpaperTarget.mAppToken != null)
-                        ? wallpaperTarget.mAppToken.mAppAnimator.animation : null)
-                + " upper=" + mUpperWallpaperTarget
-                + " lower=" + mLowerWallpaperTarget);
-        return (wallpaperTarget != null
-                        && (!wallpaperTarget.mObscured || (wallpaperTarget.mAppToken != null
-                                && wallpaperTarget.mAppToken.mAppAnimator.animation != null)))
-                || mUpperWallpaperTarget != null
-                || mLowerWallpaperTarget != null;
-    }
-
-    static final int ADJUST_WALLPAPER_LAYERS_CHANGED = 1<<1;
-    static final int ADJUST_WALLPAPER_VISIBILITY_CHANGED = 1<<2;
-
-    int adjustWallpaperWindowsLocked() {
-        mInnerFields.mWallpaperMayChange = false;
-        boolean targetChanged = false;
-
-        // TODO(multidisplay): Wallpapers on main screen only.
-        final DisplayInfo displayInfo = getDefaultDisplayContentLocked().getDisplayInfo();
-        final int dw = displayInfo.logicalWidth;
-        final int dh = displayInfo.logicalHeight;
-
-        // First find top-most window that has asked to be on top of the
-        // wallpaper; all wallpapers go behind it.
-        final WindowList windows = getDefaultWindowListLocked();
-        int N = windows.size();
-        WindowState w = null;
-        WindowState foundW = null;
-        int foundI = 0;
-        WindowState topCurW = null;
-        int topCurI = 0;
-        int windowDetachedI = -1;
-        int i = N;
-        while (i > 0) {
-            i--;
-            w = windows.get(i);
-            if ((w.mAttrs.type == TYPE_WALLPAPER)) {
-                if (topCurW == null) {
-                    topCurW = w;
-                    topCurI = i;
-                }
-                continue;
-            }
-            topCurW = null;
-            if (w != mAnimator.mWindowDetachedWallpaper && w.mAppToken != null) {
-                // If this window's app token is hidden and not animating,
-                // it is of no interest to us.
-                if (w.mAppToken.hidden && w.mAppToken.mAppAnimator.animation == null) {
-                    if (DEBUG_WALLPAPER) Slog.v(TAG,
-                            "Skipping hidden and not animating token: " + w);
-                    continue;
-                }
-            }
-            if (DEBUG_WALLPAPER) Slog.v(TAG, "Win #" + i + " " + w + ": isOnScreen="
-                    + w.isOnScreen() + " mDrawState=" + w.mWinAnimator.mDrawState);
-            if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isOnScreen()
-                    && (mWallpaperTarget == w || w.isDrawFinishedLw())) {
-                if (DEBUG_WALLPAPER) Slog.v(TAG,
-                        "Found wallpaper target: #" + i + "=" + w);
-                foundW = w;
-                foundI = i;
-                if (w == mWallpaperTarget && w.mWinAnimator.isAnimating()) {
-                    // The current wallpaper target is animating, so we'll
-                    // look behind it for another possible target and figure
-                    // out what is going on below.
-                    if (DEBUG_WALLPAPER) Slog.v(TAG, "Win " + w
-                            + ": token animating, looking behind.");
-                    continue;
-                }
-                break;
-            } else if (w == mAnimator.mWindowDetachedWallpaper) {
-                windowDetachedI = i;
-            }
-        }
-
-        if (foundW == null && windowDetachedI >= 0) {
-            if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
-                    "Found animating detached wallpaper activity: #" + i + "=" + w);
-            foundW = w;
-            foundI = windowDetachedI;
-        }
-
-        if (mWallpaperTarget != foundW
-                && (mLowerWallpaperTarget == null || mLowerWallpaperTarget != foundW)) {
-            if (DEBUG_WALLPAPER_LIGHT) {
-                Slog.v(TAG, "New wallpaper target: " + foundW
-                        + " oldTarget: " + mWallpaperTarget);
-            }
-
-            mLowerWallpaperTarget = null;
-            mUpperWallpaperTarget = null;
-
-            WindowState oldW = mWallpaperTarget;
-            mWallpaperTarget = foundW;
-            targetChanged = true;
-
-            // Now what is happening...  if the current and new targets are
-            // animating, then we are in our super special mode!
-            if (foundW != null && oldW != null) {
-                boolean oldAnim = oldW.isAnimatingLw();
-                boolean foundAnim = foundW.isAnimatingLw();
-                if (DEBUG_WALLPAPER_LIGHT) {
-                    Slog.v(TAG, "New animation: " + foundAnim
-                            + " old animation: " + oldAnim);
-                }
-                if (foundAnim && oldAnim) {
-                    int oldI = windows.indexOf(oldW);
-                    if (DEBUG_WALLPAPER_LIGHT) {
-                        Slog.v(TAG, "New i: " + foundI + " old i: " + oldI);
-                    }
-                    if (oldI >= 0) {
-                        if (DEBUG_WALLPAPER_LIGHT) {
-                            Slog.v(TAG, "Animating wallpapers: old#" + oldI
-                                    + "=" + oldW + "; new#" + foundI
-                                    + "=" + foundW);
-                        }
-
-                        // Set the new target correctly.
-                        if (foundW.mAppToken != null && foundW.mAppToken.hiddenRequested) {
-                            if (DEBUG_WALLPAPER_LIGHT) {
-                                Slog.v(TAG, "Old wallpaper still the target.");
-                            }
-                            mWallpaperTarget = oldW;
-                            foundW = oldW;
-                            foundI = oldI;
-                        }
-                        // Now set the upper and lower wallpaper targets
-                        // correctly, and make sure that we are positioning
-                        // the wallpaper below the lower.
-                        else if (foundI > oldI) {
-                            // The new target is on top of the old one.
-                            if (DEBUG_WALLPAPER_LIGHT) {
-                                Slog.v(TAG, "Found target above old target.");
-                            }
-                            mUpperWallpaperTarget = foundW;
-                            mLowerWallpaperTarget = oldW;
-                            foundW = oldW;
-                            foundI = oldI;
-                        } else {
-                            // The new target is below the old one.
-                            if (DEBUG_WALLPAPER_LIGHT) {
-                                Slog.v(TAG, "Found target below old target.");
-                            }
-                            mUpperWallpaperTarget = oldW;
-                            mLowerWallpaperTarget = foundW;
-                        }
-                    }
-                }
-            }
-
-        } else if (mLowerWallpaperTarget != null) {
-            // Is it time to stop animating?
-            if (!mLowerWallpaperTarget.isAnimatingLw() || !mUpperWallpaperTarget.isAnimatingLw()) {
-                if (DEBUG_WALLPAPER_LIGHT) {
-                    Slog.v(TAG, "No longer animating wallpaper targets!");
-                }
-                mLowerWallpaperTarget = null;
-                mUpperWallpaperTarget = null;
-                mWallpaperTarget = foundW;
-                targetChanged = true;
-            }
-        }
-
-        boolean visible = foundW != null;
-        if (visible) {
-            // The window is visible to the compositor...  but is it visible
-            // to the user?  That is what the wallpaper cares about.
-            visible = isWallpaperVisible(foundW);
-            if (DEBUG_WALLPAPER) Slog.v(TAG, "Wallpaper visibility: " + visible);
-
-            // If the wallpaper target is animating, we may need to copy
-            // its layer adjustment.  Only do this if we are not transfering
-            // between two wallpaper targets.
-            mWallpaperAnimLayerAdjustment =
-                    (mLowerWallpaperTarget == null && foundW.mAppToken != null)
-                    ? foundW.mAppToken.mAppAnimator.animLayerAdjustment : 0;
-
-            final int maxLayer = mPolicy.getMaxWallpaperLayer()
-                    * TYPE_LAYER_MULTIPLIER
-                    + TYPE_LAYER_OFFSET;
-
-            // Now w is the window we are supposed to be behind...  but we
-            // need to be sure to also be behind any of its attached windows,
-            // AND any starting window associated with it, AND below the
-            // maximum layer the policy allows for wallpapers.
-            while (foundI > 0) {
-                WindowState wb = windows.get(foundI-1);
-                if (wb.mBaseLayer < maxLayer &&
-                        wb.mAttachedWindow != foundW &&
-                        (foundW.mAttachedWindow == null ||
-                                wb.mAttachedWindow != foundW.mAttachedWindow) &&
-                        (wb.mAttrs.type != TYPE_APPLICATION_STARTING ||
-                                foundW.mToken == null || wb.mToken != foundW.mToken)) {
-                    // This window is not related to the previous one in any
-                    // interesting way, so stop here.
-                    break;
-                }
-                foundW = wb;
-                foundI--;
-            }
-        } else {
-            if (DEBUG_WALLPAPER) Slog.v(TAG, "No wallpaper target");
-        }
-
-        if (foundW == null && topCurW != null) {
-            // There is no wallpaper target, so it goes at the bottom.
-            // We will assume it is the same place as last time, if known.
-            foundW = topCurW;
-            foundI = topCurI+1;
-        } else {
-            // Okay i is the position immediately above the wallpaper.  Look at
-            // what is below it for later.
-            foundW = foundI > 0 ? windows.get(foundI-1) : null;
-        }
-
-        if (visible) {
-            if (mWallpaperTarget.mWallpaperX >= 0) {
-                mLastWallpaperX = mWallpaperTarget.mWallpaperX;
-                mLastWallpaperXStep = mWallpaperTarget.mWallpaperXStep;
-            }
-            if (mWallpaperTarget.mWallpaperY >= 0) {
-                mLastWallpaperY = mWallpaperTarget.mWallpaperY;
-                mLastWallpaperYStep = mWallpaperTarget.mWallpaperYStep;
-            }
-        }
-
-        // Start stepping backwards from here, ensuring that our wallpaper windows
-        // are correctly placed.
-        int changed = 0;
-        int curTokenIndex = mWallpaperTokens.size();
-        while (curTokenIndex > 0) {
-            curTokenIndex--;
-            WindowToken token = mWallpaperTokens.get(curTokenIndex);
-            if (token.hidden == visible) {
-                if (DEBUG_WALLPAPER_LIGHT) Slog.d(TAG,
-                        "Wallpaper token " + token + " hidden=" + !visible);
-                changed |= ADJUST_WALLPAPER_VISIBILITY_CHANGED;
-                token.hidden = !visible;
-                // Need to do a layout to ensure the wallpaper now has the
-                // correct size.
-                getDefaultDisplayContentLocked().layoutNeeded = true;
-            }
-
-            int curWallpaperIndex = token.windows.size();
-            while (curWallpaperIndex > 0) {
-                curWallpaperIndex--;
-                WindowState wallpaper = token.windows.get(curWallpaperIndex);
-
-                if (visible) {
-                    updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
-                }
-
-                // First, make sure the client has the current visibility
-                // state.
-                dispatchWallpaperVisibility(wallpaper, visible);
-
-                wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + mWallpaperAnimLayerAdjustment;
-                if (DEBUG_LAYERS || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "adjustWallpaper win "
-                        + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer);
-
-                // First, if this window is at the current index, then all
-                // is well.
-                if (wallpaper == foundW) {
-                    foundI--;
-                    foundW = foundI > 0
-                            ? windows.get(foundI-1) : null;
-                    continue;
-                }
-
-                // The window didn't match...  the current wallpaper window,
-                // wherever it is, is in the wrong place, so make sure it is
-                // not in the list.
-                int oldIndex = windows.indexOf(wallpaper);
-                if (oldIndex >= 0) {
-                    if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Wallpaper removing at "
-                            + oldIndex + ": " + wallpaper);
-                    windows.remove(oldIndex);
-                    mWindowsChanged = true;
-                    if (oldIndex < foundI) {
-                        foundI--;
-                    }
-                }
-
-                // Now stick it in. For apps over wallpaper keep the wallpaper at the bottommost
-                // layer. For keyguard over wallpaper put the wallpaper under the keyguard.
-                int insertionIndex = 0;
-                if (visible && foundW != null) {
-                    final int type = foundW.mAttrs.type;
-                    if (type == TYPE_KEYGUARD || type == TYPE_KEYGUARD_SCRIM) {
-                        insertionIndex = windows.indexOf(foundW);
-                    }
-                }
-                if (DEBUG_WALLPAPER_LIGHT || DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) {
-                    Slog.v(TAG, "Moving wallpaper " + wallpaper
-                            + " from " + oldIndex + " to " + insertionIndex);
-                }
-
-                windows.add(insertionIndex, wallpaper);
-                mWindowsChanged = true;
-                changed |= ADJUST_WALLPAPER_LAYERS_CHANGED;
-            }
-        }
-
-        /*
-        final TaskStack targetStack =
-                mWallpaperTarget == null ? null : mWallpaperTarget.getStack();
-        if ((changed & ADJUST_WALLPAPER_LAYERS_CHANGED) != 0 &&
-                targetStack != null && !targetStack.isHomeStack()) {
-            // If the wallpaper target is not on the home stack then make sure that all windows
-            // from other non-home stacks are above the wallpaper.
-            for (i = foundI - 1; i >= 0; --i) {
-                WindowState win = windows.get(i);
-                if (!win.isVisibleLw()) {
-                    continue;
-                }
-                final TaskStack winStack = win.getStack();
-                if (winStack != null && !winStack.isHomeStack() && winStack != targetStack) {
-                    windows.remove(i);
-                    windows.add(foundI + 1, win);
-                }
-            }
-        }
-        */
-
-        if (targetChanged && DEBUG_WALLPAPER_LIGHT) {
-            Slog.d(TAG, "New wallpaper: target=" + mWallpaperTarget
-                    + " lower=" + mLowerWallpaperTarget + " upper="
-                    + mUpperWallpaperTarget);
-        }
-
-        return changed;
-    }
-
-    void setWallpaperAnimLayerAdjustmentLocked(int adj) {
-        if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG,
-                "Setting wallpaper layer adj to " + adj);
-        mWallpaperAnimLayerAdjustment = adj;
-        int curTokenIndex = mWallpaperTokens.size();
-        while (curTokenIndex > 0) {
-            curTokenIndex--;
-            WindowToken token = mWallpaperTokens.get(curTokenIndex);
-            int curWallpaperIndex = token.windows.size();
-            while (curWallpaperIndex > 0) {
-                curWallpaperIndex--;
-                WindowState wallpaper = token.windows.get(curWallpaperIndex);
-                wallpaper.mWinAnimator.mAnimLayer = wallpaper.mLayer + adj;
-                if (DEBUG_LAYERS || DEBUG_WALLPAPER) Slog.v(TAG, "setWallpaper win "
-                        + wallpaper + " anim layer: " + wallpaper.mWinAnimator.mAnimLayer);
-            }
-        }
-    }
-
-    boolean updateWallpaperOffsetLocked(WindowState wallpaperWin, int dw, int dh,
-            boolean sync) {
-        boolean changed = false;
-        boolean rawChanged = false;
-        float wpx = mLastWallpaperX >= 0 ? mLastWallpaperX : 0.5f;
-        float wpxs = mLastWallpaperXStep >= 0 ? mLastWallpaperXStep : -1.0f;
-        int availw = wallpaperWin.mFrame.right-wallpaperWin.mFrame.left-dw;
-        int offset = availw > 0 ? -(int)(availw*wpx+.5f) : 0;
-        changed = wallpaperWin.mXOffset != offset;
-        if (changed) {
-            if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
-                    + wallpaperWin + " x: " + offset);
-            wallpaperWin.mXOffset = offset;
-        }
-        if (wallpaperWin.mWallpaperX != wpx || wallpaperWin.mWallpaperXStep != wpxs) {
-            wallpaperWin.mWallpaperX = wpx;
-            wallpaperWin.mWallpaperXStep = wpxs;
-            rawChanged = true;
-        }
-
-        float wpy = mLastWallpaperY >= 0 ? mLastWallpaperY : 0.5f;
-        float wpys = mLastWallpaperYStep >= 0 ? mLastWallpaperYStep : -1.0f;
-        int availh = wallpaperWin.mFrame.bottom-wallpaperWin.mFrame.top-dh;
-        offset = availh > 0 ? -(int)(availh*wpy+.5f) : 0;
-        if (wallpaperWin.mYOffset != offset) {
-            if (DEBUG_WALLPAPER) Slog.v(TAG, "Update wallpaper "
-                    + wallpaperWin + " y: " + offset);
-            changed = true;
-            wallpaperWin.mYOffset = offset;
-        }
-        if (wallpaperWin.mWallpaperY != wpy || wallpaperWin.mWallpaperYStep != wpys) {
-            wallpaperWin.mWallpaperY = wpy;
-            wallpaperWin.mWallpaperYStep = wpys;
-            rawChanged = true;
-        }
-
-        if (rawChanged && (wallpaperWin.mAttrs.privateFlags &
-                    WindowManager.LayoutParams.PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS) != 0) {
-            try {
-                if (DEBUG_WALLPAPER) Slog.v(TAG, "Report new wp offset "
-                        + wallpaperWin + " x=" + wallpaperWin.mWallpaperX
-                        + " y=" + wallpaperWin.mWallpaperY);
-                if (sync) {
-                    mWaitingOnWallpaper = wallpaperWin;
-                }
-                wallpaperWin.mClient.dispatchWallpaperOffsets(
-                        wallpaperWin.mWallpaperX, wallpaperWin.mWallpaperY,
-                        wallpaperWin.mWallpaperXStep, wallpaperWin.mWallpaperYStep, sync);
-                if (sync) {
-                    if (mWaitingOnWallpaper != null) {
-                        long start = SystemClock.uptimeMillis();
-                        if ((mLastWallpaperTimeoutTime+WALLPAPER_TIMEOUT_RECOVERY)
-                                < start) {
-                            try {
-                                if (DEBUG_WALLPAPER) Slog.v(TAG,
-                                        "Waiting for offset complete...");
-                                mWindowMap.wait(WALLPAPER_TIMEOUT);
-                            } catch (InterruptedException e) {
-                            }
-                            if (DEBUG_WALLPAPER) Slog.v(TAG, "Offset complete!");
-                            if ((start+WALLPAPER_TIMEOUT)
-                                    < SystemClock.uptimeMillis()) {
-                                Slog.i(TAG, "Timeout waiting for wallpaper to offset: "
-                                        + wallpaperWin);
-                                mLastWallpaperTimeoutTime = start;
-                            }
-                        }
-                        mWaitingOnWallpaper = null;
-                    }
-                }
-            } catch (RemoteException e) {
-            }
-        }
-
-        return changed;
-    }
-
-    void wallpaperOffsetsComplete(IBinder window) {
-        synchronized (mWindowMap) {
-            if (mWaitingOnWallpaper != null &&
-                    mWaitingOnWallpaper.mClient.asBinder() == window) {
-                mWaitingOnWallpaper = null;
-                mWindowMap.notifyAll();
-            }
-        }
-    }
-
-    void updateWallpaperOffsetLocked(WindowState changingTarget, boolean sync) {
-        final DisplayContent displayContent = changingTarget.mDisplayContent;
-        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        final int dw = displayInfo.logicalWidth;
-        final int dh = displayInfo.logicalHeight;
-
-        WindowState target = mWallpaperTarget;
-        if (target != null) {
-            if (target.mWallpaperX >= 0) {
-                mLastWallpaperX = target.mWallpaperX;
-            } else if (changingTarget.mWallpaperX >= 0) {
-                mLastWallpaperX = changingTarget.mWallpaperX;
-            }
-            if (target.mWallpaperY >= 0) {
-                mLastWallpaperY = target.mWallpaperY;
-            } else if (changingTarget.mWallpaperY >= 0) {
-                mLastWallpaperY = changingTarget.mWallpaperY;
-            }
-        }
-
-        int curTokenIndex = mWallpaperTokens.size();
-        while (curTokenIndex > 0) {
-            curTokenIndex--;
-            WindowToken token = mWallpaperTokens.get(curTokenIndex);
-            int curWallpaperIndex = token.windows.size();
-            while (curWallpaperIndex > 0) {
-                curWallpaperIndex--;
-                WindowState wallpaper = token.windows.get(curWallpaperIndex);
-                if (updateWallpaperOffsetLocked(wallpaper, dw, dh, sync)) {
-                    WindowStateAnimator winAnimator = wallpaper.mWinAnimator;
-                    winAnimator.computeShownFrameLocked();
-                    // No need to lay out the windows - we can just set the wallpaper position
-                    // directly.
-                    winAnimator.setWallpaperOffset(wallpaper.mShownFrame);
-                    // We only want to be synchronous with one wallpaper.
-                    sync = false;
-                }
-            }
-        }
-    }
-
-    /**
-     * Check wallpaper for visiblity change and notify window if so.
-     * @param wallpaper The wallpaper to test and notify.
-     * @param visible Current visibility.
-     */
-    void dispatchWallpaperVisibility(final WindowState wallpaper, final boolean visible) {
-        if (wallpaper.mWallpaperVisible != visible) {
-            wallpaper.mWallpaperVisible = visible;
-            try {
-                if (DEBUG_VISIBILITY || DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
-                        "Updating vis of wallpaper " + wallpaper
-                        + ": " + visible + " from:\n" + Debug.getCallers(4, "  "));
-                wallpaper.mClient.dispatchAppVisibility(visible);
-            } catch (RemoteException e) {
-            }
-        }
-    }
-
-    void updateWallpaperVisibilityLocked() {
-        final boolean visible = isWallpaperVisible(mWallpaperTarget);
-        final DisplayContent displayContent = mWallpaperTarget.mDisplayContent;
-        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        final int dw = displayInfo.logicalWidth;
-        final int dh = displayInfo.logicalHeight;
-
-        int curTokenIndex = mWallpaperTokens.size();
-        while (curTokenIndex > 0) {
-            curTokenIndex--;
-            WindowToken token = mWallpaperTokens.get(curTokenIndex);
-            if (token.hidden == visible) {
-                token.hidden = !visible;
-                // Need to do a layout to ensure the wallpaper now has the
-                // correct size.
-                getDefaultDisplayContentLocked().layoutNeeded = true;
-            }
-
-            int curWallpaperIndex = token.windows.size();
-            while (curWallpaperIndex > 0) {
-                curWallpaperIndex--;
-                WindowState wallpaper = token.windows.get(curWallpaperIndex);
-                if (visible) {
-                    updateWallpaperOffsetLocked(wallpaper, dw, dh, false);
-                }
-
-                dispatchWallpaperVisibility(wallpaper, visible);
-            }
-        }
-    }
-
-    public int addWindow(Session session, IWindow client, int seq,
-            WindowManager.LayoutParams attrs, int viewVisibility, int displayId,
-            Rect outContentInsets, InputChannel outInputChannel) {
-        int[] appOp = new int[1];
-        int res = mPolicy.checkAddPermission(attrs, appOp);
-        if (res != WindowManagerGlobal.ADD_OKAY) {
-            return res;
-        }
-
-        boolean reportNewConfig = false;
-        WindowState attachedWindow = null;
-        WindowState win = null;
-        long origId;
-        final int type = attrs.type;
-
-        synchronized(mWindowMap) {
-            if (!mDisplayReady) {
-                throw new IllegalStateException("Display has not been initialialized");
-            }
-
-            final DisplayContent displayContent = getDisplayContentLocked(displayId);
-            if (displayContent == null) {
-                Slog.w(TAG, "Attempted to add window to a display that does not exist: "
-                        + displayId + ".  Aborting.");
-                return WindowManagerGlobal.ADD_INVALID_DISPLAY;
-            }
-            if (!displayContent.hasAccess(session.mUid)) {
-                Slog.w(TAG, "Attempted to add window to a display for which the application "
-                        + "does not have access: " + displayId + ".  Aborting.");
-                return WindowManagerGlobal.ADD_INVALID_DISPLAY;
-            }
-
-            if (mWindowMap.containsKey(client.asBinder())) {
-                Slog.w(TAG, "Window " + client + " is already added");
-                return WindowManagerGlobal.ADD_DUPLICATE_ADD;
-            }
-
-            if (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW) {
-                attachedWindow = windowForClientLocked(null, attrs.token, false);
-                if (attachedWindow == null) {
-                    Slog.w(TAG, "Attempted to add window with token that is not a window: "
-                          + attrs.token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN;
-                }
-                if (attachedWindow.mAttrs.type >= FIRST_SUB_WINDOW
-                        && attachedWindow.mAttrs.type <= LAST_SUB_WINDOW) {
-                    Slog.w(TAG, "Attempted to add window with token that is a sub-window: "
-                            + attrs.token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_BAD_SUBWINDOW_TOKEN;
-                }
-            }
-
-            if (type == TYPE_PRIVATE_PRESENTATION && !displayContent.isPrivate()) {
-                Slog.w(TAG, "Attempted to add private presentation window to a non-private display.  Aborting.");
-                return WindowManagerGlobal.ADD_PERMISSION_DENIED;
-            }
-
-            boolean addToken = false;
-            WindowToken token = mTokenMap.get(attrs.token);
-            if (token == null) {
-                if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
-                    Slog.w(TAG, "Attempted to add application window with unknown token "
-                          + attrs.token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-                if (type == TYPE_INPUT_METHOD) {
-                    Slog.w(TAG, "Attempted to add input method window with unknown token "
-                          + attrs.token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-                if (type == TYPE_WALLPAPER) {
-                    Slog.w(TAG, "Attempted to add wallpaper window with unknown token "
-                          + attrs.token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-                if (type == TYPE_DREAM) {
-                    Slog.w(TAG, "Attempted to add Dream window with unknown token "
-                          + attrs.token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-                token = new WindowToken(this, attrs.token, -1, false);
-                addToken = true;
-            } else if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
-                AppWindowToken atoken = token.appWindowToken;
-                if (atoken == null) {
-                    Slog.w(TAG, "Attempted to add window with non-application token "
-                          + token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_NOT_APP_TOKEN;
-                } else if (atoken.removed) {
-                    Slog.w(TAG, "Attempted to add window with exiting application token "
-                          + token + ".  Aborting.");
-                    return WindowManagerGlobal.ADD_APP_EXITING;
-                }
-                if (type == TYPE_APPLICATION_STARTING && atoken.firstWindowDrawn) {
-                    // No need for this guy!
-                    if (localLOGV) Slog.v(
-                            TAG, "**** NO NEED TO START: " + attrs.getTitle());
-                    return WindowManagerGlobal.ADD_STARTING_NOT_NEEDED;
-                }
-            } else if (type == TYPE_INPUT_METHOD) {
-                if (token.windowType != TYPE_INPUT_METHOD) {
-                    Slog.w(TAG, "Attempted to add input method window with bad token "
-                            + attrs.token + ".  Aborting.");
-                      return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-            } else if (type == TYPE_WALLPAPER) {
-                if (token.windowType != TYPE_WALLPAPER) {
-                    Slog.w(TAG, "Attempted to add wallpaper window with bad token "
-                            + attrs.token + ".  Aborting.");
-                      return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-            } else if (type == TYPE_DREAM) {
-                if (token.windowType != TYPE_DREAM) {
-                    Slog.w(TAG, "Attempted to add Dream window with bad token "
-                            + attrs.token + ".  Aborting.");
-                      return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
-                }
-            }
-
-            win = new WindowState(this, session, client, token,
-                    attachedWindow, appOp[0], seq, attrs, viewVisibility, displayContent);
-            if (win.mDeathRecipient == null) {
-                // Client has apparently died, so there is no reason to
-                // continue.
-                Slog.w(TAG, "Adding window client " + client.asBinder()
-                        + " that is dead, aborting.");
-                return WindowManagerGlobal.ADD_APP_EXITING;
-            }
-
-            mPolicy.adjustWindowParamsLw(win.mAttrs);
-            win.setShowToOwnerOnlyLocked(mPolicy.checkShowToOwnerOnly(attrs));
-
-            res = mPolicy.prepareAddWindowLw(win, attrs);
-            if (res != WindowManagerGlobal.ADD_OKAY) {
-                return res;
-            }
-
-            if (outInputChannel != null && (attrs.inputFeatures
-                    & WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL) == 0) {
-                String name = win.makeInputChannelName();
-                InputChannel[] inputChannels = InputChannel.openInputChannelPair(name);
-                win.setInputChannel(inputChannels[0]);
-                inputChannels[1].transferTo(outInputChannel);
-
-                mInputManager.registerInputChannel(win.mInputChannel, win.mInputWindowHandle);
-            }
-
-            // From now on, no exceptions or errors allowed!
-
-            res = WindowManagerGlobal.ADD_OKAY;
-
-            origId = Binder.clearCallingIdentity();
-
-            if (addToken) {
-                mTokenMap.put(attrs.token, token);
-            }
-            win.attach();
-            mWindowMap.put(client.asBinder(), win);
-            if (win.mAppOp != AppOpsManager.OP_NONE) {
-                if (mAppOps.startOpNoThrow(win.mAppOp, win.getOwningUid(), win.getOwningPackage())
-                        != AppOpsManager.MODE_ALLOWED) {
-                    win.setAppOpVisibilityLw(false);
-                }
-            }
-
-            if (type == TYPE_APPLICATION_STARTING && token.appWindowToken != null) {
-                token.appWindowToken.startingWindow = win;
-                if (DEBUG_STARTING_WINDOW) Slog.v (TAG, "addWindow: " + token.appWindowToken
-                        + " startingWindow=" + win);
-                Message m = mH.obtainMessage(H.REMOVE_STARTING_TIMEOUT, token.appWindowToken);
-                mH.sendMessageDelayed(m, STARTING_WINDOW_TIMEOUT_DURATION);
-            }
-
-            boolean imMayMove = true;
-
-            if (type == TYPE_INPUT_METHOD) {
-                win.mGivenInsetsPending = true;
-                mInputMethodWindow = win;
-                addInputMethodWindowToListLocked(win);
-                imMayMove = false;
-            } else if (type == TYPE_INPUT_METHOD_DIALOG) {
-                mInputMethodDialogs.add(win);
-                addWindowToListInOrderLocked(win, true);
-                moveInputMethodDialogsLocked(findDesiredInputMethodWindowIndexLocked(true));
-                imMayMove = false;
-            } else {
-                addWindowToListInOrderLocked(win, true);
-                if (type == TYPE_WALLPAPER) {
-                    mLastWallpaperTimeoutTime = 0;
-                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
-                } else if ((attrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
-                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
-                } else if (mWallpaperTarget != null
-                        && mWallpaperTarget.mLayer >= win.mBaseLayer) {
-                    // If there is currently a wallpaper being shown, and
-                    // the base layer of the new window is below the current
-                    // layer of the target window, then adjust the wallpaper.
-                    // This is to avoid a new window being placed between the
-                    // wallpaper and its target.
-                    displayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
-                }
-            }
-
-            win.mWinAnimator.mEnterAnimationPending = true;
-
-            if (displayContent.isDefaultDisplay) {
-                mPolicy.getContentInsetHintLw(attrs, outContentInsets);
-            } else {
-                outContentInsets.setEmpty();
-            }
-
-            if (mInTouchMode) {
-                res |= WindowManagerGlobal.ADD_FLAG_IN_TOUCH_MODE;
-            }
-            if (win.mAppToken == null || !win.mAppToken.clientHidden) {
-                res |= WindowManagerGlobal.ADD_FLAG_APP_VISIBLE;
-            }
-
-            mInputMonitor.setUpdateInputWindowsNeededLw();
-
-            boolean focusChanged = false;
-            if (win.canReceiveKeys()) {
-                focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
-                        false /*updateInputWindows*/);
-                if (focusChanged) {
-                    imMayMove = false;
-                }
-            }
-
-            if (imMayMove) {
-                moveInputMethodWindowsIfNeededLocked(false);
-            }
-
-            assignLayersLocked(displayContent.getWindowList());
-            // Don't do layout here, the window must call
-            // relayout to be displayed, so we'll do it there.
-
-            if (focusChanged) {
-                finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
-            }
-            mInputMonitor.updateInputWindowsLw(false /*force*/);
-
-            if (localLOGV) Slog.v(
-                TAG, "New client " + client.asBinder()
-                + ": window=" + win);
-
-            if (win.isVisibleOrAdding() && updateOrientationFromAppTokensLocked(false)) {
-                reportNewConfig = true;
-            }
-        }
-
-        if (reportNewConfig) {
-            sendNewConfiguration();
-        }
-
-        Binder.restoreCallingIdentity(origId);
-
-        return res;
-    }
-
-    public void removeWindow(Session session, IWindow client) {
-        synchronized(mWindowMap) {
-            WindowState win = windowForClientLocked(session, client, false);
-            if (win == null) {
-                return;
-            }
-            removeWindowLocked(session, win);
-        }
-    }
-
-    public void removeWindowLocked(Session session, WindowState win) {
-        if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
-            if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "Starting window removed " + win);
-            removeStartingWindowTimeout(win.mAppToken);
-        }
-
-        if (localLOGV || DEBUG_FOCUS || DEBUG_FOCUS_LIGHT && win==mCurrentFocus) Slog.v(
-                TAG, "Remove " + win + " client="
-                + Integer.toHexString(System.identityHashCode(win.mClient.asBinder()))
-                + ", surface=" + win.mWinAnimator.mSurfaceControl + " Callers="
-                + Debug.getCallers(4));
-
-        final long origId = Binder.clearCallingIdentity();
-
-        win.disposeInputChannel();
-
-        if (DEBUG_APP_TRANSITIONS) Slog.v(
-                TAG, "Remove " + win + ": mSurface=" + win.mWinAnimator.mSurfaceControl
-                + " mExiting=" + win.mExiting
-                + " isAnimating=" + win.mWinAnimator.isAnimating()
-                + " app-animation="
-                + (win.mAppToken != null ? win.mAppToken.mAppAnimator.animation : null)
-                + " inPendingTransaction="
-                + (win.mAppToken != null ? win.mAppToken.inPendingTransaction : false)
-                + " mDisplayFrozen=" + mDisplayFrozen);
-        // Visibility of the removed window. Will be used later to update orientation later on.
-        boolean wasVisible = false;
-        // First, see if we need to run an animation.  If we do, we have
-        // to hold off on removing the window until the animation is done.
-        // If the display is frozen, just remove immediately, since the
-        // animation wouldn't be seen.
-        if (win.mHasSurface && okToDisplay()) {
-            // If we are not currently running the exit animation, we
-            // need to see about starting one.
-            wasVisible = win.isWinVisibleLw();
-            if (wasVisible) {
-
-                int transit = WindowManagerPolicy.TRANSIT_EXIT;
-                if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
-                    transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
-                }
-                // Try starting an animation.
-                if (win.mWinAnimator.applyAnimationLocked(transit, false)) {
-                    win.mExiting = true;
-                }
-                //TODO (multidisplay): Magnification is supported only for the default display.
-                if (mDisplayMagnifier != null
-                        && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                    mDisplayMagnifier.onWindowTransitionLocked(win, transit);
-                }
-            }
-            if (win.mExiting || win.mWinAnimator.isAnimating()) {
-                // The exit animation is running... wait for it!
-                //Slog.i(TAG, "*** Running exit animation...");
-                win.mExiting = true;
-                win.mRemoveOnExit = true;
-                win.mDisplayContent.layoutNeeded = true;
-                updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
-                        false /*updateInputWindows*/);
-                performLayoutAndPlaceSurfacesLocked();
-                if (win.mAppToken != null) {
-                    win.mAppToken.updateReportedVisibilityLocked();
-                }
-                //dump();
-                Binder.restoreCallingIdentity(origId);
-                return;
-            }
-        }
-
-        removeWindowInnerLocked(session, win);
-        // Removing a visible window will effect the computed orientation
-        // So just update orientation if needed.
-        if (wasVisible && updateOrientationFromAppTokensLocked(false)) {
-            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-        }
-        updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    private void removeWindowInnerLocked(Session session, WindowState win) {
-        if (win.mRemoved) {
-            // Nothing to do.
-            return;
-        }
-
-        for (int i=win.mChildWindows.size()-1; i>=0; i--) {
-            WindowState cwin = win.mChildWindows.get(i);
-            Slog.w(TAG, "Force-removing child win " + cwin + " from container "
-                    + win);
-            removeWindowInnerLocked(cwin.mSession, cwin);
-        }
-
-        win.mRemoved = true;
-
-        if (mInputMethodTarget == win) {
-            moveInputMethodWindowsIfNeededLocked(false);
-        }
-
-        if (false) {
-            RuntimeException e = new RuntimeException("here");
-            e.fillInStackTrace();
-            Slog.w(TAG, "Removing window " + win, e);
-        }
-
-        mPolicy.removeWindowLw(win);
-        win.removeLocked();
-
-        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "removeWindowInnerLocked: " + win);
-        mWindowMap.remove(win.mClient.asBinder());
-        if (win.mAppOp != AppOpsManager.OP_NONE) {
-            mAppOps.finishOp(win.mAppOp, win.getOwningUid(), win.getOwningPackage());
-        }
-
-        final WindowList windows = win.getWindowList();
-        windows.remove(win);
-        mPendingRemove.remove(win);
-        mResizingWindows.remove(win);
-        mWindowsChanged = true;
-        if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Final remove of window: " + win);
-
-        if (mInputMethodWindow == win) {
-            mInputMethodWindow = null;
-        } else if (win.mAttrs.type == TYPE_INPUT_METHOD_DIALOG) {
-            mInputMethodDialogs.remove(win);
-        }
-
-        final WindowToken token = win.mToken;
-        final AppWindowToken atoken = win.mAppToken;
-        if (DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + win + " from " + token);
-        token.windows.remove(win);
-        if (atoken != null) {
-            atoken.allAppWindows.remove(win);
-        }
-        if (localLOGV) Slog.v(
-                TAG, "**** Removing window " + win + ": count="
-                + token.windows.size());
-        if (token.windows.size() == 0) {
-            if (!token.explicit) {
-                mTokenMap.remove(token.token);
-            } else if (atoken != null) {
-                atoken.firstWindowDrawn = false;
-            }
-        }
-
-        if (atoken != null) {
-            if (atoken.startingWindow == win) {
-                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling startingWindow " + win);
-                removeStartingWindowTimeout(atoken);
-                atoken.startingWindow = null;
-            } else if (atoken.allAppWindows.size() == 0 && atoken.startingData != null) {
-                // If this is the last window and we had requested a starting
-                // transition window, well there is no point now.
-                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Nulling last startingWindow");
-                atoken.startingData = null;
-            } else if (atoken.allAppWindows.size() == 1 && atoken.startingView != null) {
-                // If this is the last window except for a starting transition
-                // window, we need to get rid of the starting transition.
-                scheduleRemoveStartingWindow(atoken);
-            }
-        }
-
-        if (win.mAttrs.type == TYPE_WALLPAPER) {
-            mLastWallpaperTimeoutTime = 0;
-            getDefaultDisplayContentLocked().pendingLayoutChanges |=
-                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-        } else if ((win.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0) {
-            getDefaultDisplayContentLocked().pendingLayoutChanges |=
-                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-        }
-
-        if (!mInLayout) {
-            assignLayersLocked(windows);
-            win.mDisplayContent.layoutNeeded = true;
-            performLayoutAndPlaceSurfacesLocked();
-            if (win.mAppToken != null) {
-                win.mAppToken.updateReportedVisibilityLocked();
-            }
-        }
-
-        mInputMonitor.updateInputWindowsLw(true /*force*/);
-    }
-
-    public void updateAppOpsState() {
-        synchronized(mWindowMap) {
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-                final int numWindows = windows.size();
-                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                    final WindowState win = windows.get(winNdx);
-                    if (win.mAppOp != AppOpsManager.OP_NONE) {
-                        final int mode = mAppOps.checkOpNoThrow(win.mAppOp, win.getOwningUid(),
-                                win.getOwningPackage());
-                        win.setAppOpVisibilityLw(mode == AppOpsManager.MODE_ALLOWED);
-                    }
-                }
-            }
-        }
-    }
-
-    static void logSurface(WindowState w, String msg, RuntimeException where) {
-        String str = "  SURFACE " + msg + ": " + w;
-        if (where != null) {
-            Slog.i(TAG, str, where);
-        } else {
-            Slog.i(TAG, str);
-        }
-    }
-
-    static void logSurface(SurfaceControl s, String title, String msg, RuntimeException where) {
-        String str = "  SURFACE " + s + ": " + msg + " / " + title;
-        if (where != null) {
-            Slog.i(TAG, str, where);
-        } else {
-            Slog.i(TAG, str);
-        }
-    }
-
-    void setTransparentRegionWindow(Session session, IWindow client, Region region) {
-        long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (mWindowMap) {
-                WindowState w = windowForClientLocked(session, client, false);
-                if ((w != null) && w.mHasSurface) {
-                    w.mWinAnimator.setTransparentRegionHintLocked(region);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    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 (w != null) {
-                    w.mGivenInsetsPending = false;
-                    w.mGivenContentInsets.set(contentInsets);
-                    w.mGivenVisibleInsets.set(visibleInsets);
-                    w.mGivenTouchableRegion.set(touchableRegion);
-                    w.mTouchableInsets = touchableInsets;
-                    if (w.mGlobalScale != 1) {
-                        w.mGivenContentInsets.scale(w.mGlobalScale);
-                        w.mGivenVisibleInsets.scale(w.mGlobalScale);
-                        w.mGivenTouchableRegion.scale(w.mGlobalScale);
-                    }
-                    w.mDisplayContent.layoutNeeded = true;
-                    performLayoutAndPlaceSurfacesLocked();
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    public void getWindowDisplayFrame(Session session, IWindow client,
-            Rect outDisplayFrame) {
-        synchronized(mWindowMap) {
-            WindowState win = windowForClientLocked(session, client, false);
-            if (win == null) {
-                outDisplayFrame.setEmpty();
-                return;
-            }
-            outDisplayFrame.set(win.mDisplayFrame);
-        }
-    }
-
-    public void setWindowWallpaperPositionLocked(WindowState window, float x, float y,
-            float xStep, float yStep) {
-        if (window.mWallpaperX != x || window.mWallpaperY != y)  {
-            window.mWallpaperX = x;
-            window.mWallpaperY = y;
-            window.mWallpaperXStep = xStep;
-            window.mWallpaperYStep = yStep;
-            updateWallpaperOffsetLocked(window, true);
-        }
-    }
-
-    void wallpaperCommandComplete(IBinder window, Bundle result) {
-        synchronized (mWindowMap) {
-            if (mWaitingOnWallpaper != null &&
-                    mWaitingOnWallpaper.mClient.asBinder() == window) {
-                mWaitingOnWallpaper = null;
-                mWindowMap.notifyAll();
-            }
-        }
-    }
-
-    public Bundle sendWindowWallpaperCommandLocked(WindowState window,
-            String action, int x, int y, int z, Bundle extras, boolean sync) {
-        if (window == mWallpaperTarget || window == mLowerWallpaperTarget
-                || window == mUpperWallpaperTarget) {
-            boolean doWait = sync;
-            int curTokenIndex = mWallpaperTokens.size();
-            while (curTokenIndex > 0) {
-                curTokenIndex--;
-                WindowToken token = mWallpaperTokens.get(curTokenIndex);
-                int curWallpaperIndex = token.windows.size();
-                while (curWallpaperIndex > 0) {
-                    curWallpaperIndex--;
-                    WindowState wallpaper = token.windows.get(curWallpaperIndex);
-                    try {
-                        wallpaper.mClient.dispatchWallpaperCommand(action,
-                                x, y, z, extras, sync);
-                        // We only want to be synchronous with one wallpaper.
-                        sync = false;
-                    } catch (RemoteException e) {
-                    }
-                }
-            }
-
-            if (doWait) {
-                // XXX Need to wait for result.
-            }
-        }
-
-        return null;
-    }
-
-    public void setUniverseTransformLocked(WindowState window, float alpha,
-            float offx, float offy, float dsdx, float dtdx, float dsdy, float dtdy) {
-        Transformation transform = window.mWinAnimator.mUniverseTransform;
-        transform.setAlpha(alpha);
-        Matrix matrix = transform.getMatrix();
-        matrix.getValues(mTmpFloats);
-        mTmpFloats[Matrix.MTRANS_X] = offx;
-        mTmpFloats[Matrix.MTRANS_Y] = offy;
-        mTmpFloats[Matrix.MSCALE_X] = dsdx;
-        mTmpFloats[Matrix.MSKEW_Y] = dtdx;
-        mTmpFloats[Matrix.MSKEW_X] = dsdy;
-        mTmpFloats[Matrix.MSCALE_Y] = dtdy;
-        matrix.setValues(mTmpFloats);
-        final DisplayInfo displayInfo = window.mDisplayContent.getDisplayInfo();
-        final RectF dispRect = new RectF(0, 0,
-                displayInfo.logicalWidth, displayInfo.logicalHeight);
-        matrix.mapRect(dispRect);
-        window.mGivenTouchableRegion.set(0, 0,
-                displayInfo.logicalWidth, displayInfo.logicalHeight);
-        window.mGivenTouchableRegion.op((int)dispRect.left, (int)dispRect.top,
-                (int)dispRect.right, (int)dispRect.bottom, Region.Op.DIFFERENCE);
-        window.mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
-        window.mDisplayContent.layoutNeeded = true;
-        performLayoutAndPlaceSurfacesLocked();
-    }
-
-    public void onRectangleOnScreenRequested(IBinder token, Rect rectangle, boolean immediate) {
-        synchronized (mWindowMap) {
-            if (mDisplayMagnifier != null) {
-                WindowState window = mWindowMap.get(token);
-                //TODO (multidisplay): Magnification is supported only for the default display.
-                if (window != null && window.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                    mDisplayMagnifier.onRectangleOnScreenRequestedLocked(rectangle, immediate);
-                }
-            }
-        }
-    }
-
-    public IWindowId getWindowId(IBinder token) {
-        synchronized (mWindowMap) {
-            WindowState window = mWindowMap.get(token);
-            return window != null ? window.mWindowId : null;
-        }
-    }
-
-    public int relayoutWindow(Session session, IWindow client, int seq,
-            WindowManager.LayoutParams attrs, int requestedWidth,
-            int requestedHeight, int viewVisibility, int flags,
-            Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
-            Rect outVisibleInsets, Configuration outConfig, Surface outSurface) {
-        boolean toBeDisplayed = false;
-        boolean inTouchMode;
-        boolean configChanged;
-        boolean surfaceChanged = false;
-        boolean animating;
-
-        // if they don't have this permission, mask out the status bar bits
-        int systemUiVisibility = 0;
-        if (attrs != null) {
-            systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
-            if ((systemUiVisibility & StatusBarManager.DISABLE_MASK) != 0) {
-                if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
-                        != PackageManager.PERMISSION_GRANTED) {
-                    systemUiVisibility &= ~StatusBarManager.DISABLE_MASK;
-                }
-            }
-        }
-        long origId = Binder.clearCallingIdentity();
-
-        synchronized(mWindowMap) {
-            WindowState win = windowForClientLocked(session, client, false);
-            if (win == null) {
-                return 0;
-            }
-            WindowStateAnimator winAnimator = win.mWinAnimator;
-            if (win.mRequestedWidth != requestedWidth
-                    || win.mRequestedHeight != requestedHeight) {
-                win.mLayoutNeeded = true;
-                win.mRequestedWidth = requestedWidth;
-                win.mRequestedHeight = requestedHeight;
-            }
-            if (attrs != null && seq == win.mSeq) {
-                win.mSystemUiVisibility = systemUiVisibility;
-            }
-
-            if (attrs != null) {
-                mPolicy.adjustWindowParamsLw(attrs);
-            }
-
-            winAnimator.mSurfaceDestroyDeferred =
-                    (flags&WindowManagerGlobal.RELAYOUT_DEFER_SURFACE_DESTROY) != 0;
-
-            int attrChanges = 0;
-            int flagChanges = 0;
-            if (attrs != null) {
-                if (win.mAttrs.type != attrs.type) {
-                    throw new IllegalArgumentException(
-                            "Window type can not be changed after the window is added.");
-                }
-                flagChanges = win.mAttrs.flags ^= attrs.flags;
-                attrChanges = win.mAttrs.copyFrom(attrs);
-                if ((attrChanges & (WindowManager.LayoutParams.LAYOUT_CHANGED
-                        | WindowManager.LayoutParams.SYSTEM_UI_VISIBILITY_CHANGED)) != 0) {
-                    win.mLayoutNeeded = true;
-                }
-            }
-
-            if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": viewVisibility=" + viewVisibility
-                    + " req=" + requestedWidth + "x" + requestedHeight + " " + win.mAttrs);
-
-            win.mEnforceSizeCompat =
-                    (win.mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
-
-            if ((attrChanges & WindowManager.LayoutParams.ALPHA_CHANGED) != 0) {
-                winAnimator.mAlpha = attrs.alpha;
-            }
-
-            final boolean scaledWindow =
-                ((win.mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0);
-
-            if (scaledWindow) {
-                // requested{Width|Height} Surface's physical size
-                // attrs.{width|height} Size on screen
-                win.mHScale = (attrs.width  != requestedWidth)  ?
-                        (attrs.width  / (float)requestedWidth) : 1.0f;
-                win.mVScale = (attrs.height != requestedHeight) ?
-                        (attrs.height / (float)requestedHeight) : 1.0f;
-            } else {
-                win.mHScale = win.mVScale = 1;
-            }
-
-            boolean imMayMove = (flagChanges & (FLAG_ALT_FOCUSABLE_IM | FLAG_NOT_FOCUSABLE)) != 0;
-
-            final boolean isDefaultDisplay = win.isDefaultDisplay();
-            boolean focusMayChange = isDefaultDisplay && (win.mViewVisibility != viewVisibility
-                    || ((flagChanges & FLAG_NOT_FOCUSABLE) != 0)
-                    || (!win.mRelayoutCalled));
-
-            boolean wallpaperMayMove = win.mViewVisibility != viewVisibility
-                    && (win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0;
-            wallpaperMayMove |= (flagChanges & FLAG_SHOW_WALLPAPER) != 0;
-
-            win.mRelayoutCalled = true;
-            final int oldVisibility = win.mViewVisibility;
-            win.mViewVisibility = viewVisibility;
-            if (DEBUG_SCREEN_ON) {
-                RuntimeException stack = new RuntimeException();
-                stack.fillInStackTrace();
-                Slog.i(TAG, "Relayout " + win + ": oldVis=" + oldVisibility
-                        + " newVis=" + viewVisibility, stack);
-            }
-            if (viewVisibility == View.VISIBLE &&
-                    (win.mAppToken == null || !win.mAppToken.clientHidden)) {
-                toBeDisplayed = !win.isVisibleLw();
-                if (win.mExiting) {
-                    winAnimator.cancelExitAnimationForNextAnimationLocked();
-                    win.mExiting = false;
-                }
-                if (win.mDestroying) {
-                    win.mDestroying = false;
-                    mDestroySurface.remove(win);
-                }
-                if (oldVisibility == View.GONE) {
-                    winAnimator.mEnterAnimationPending = true;
-                }
-                if (toBeDisplayed) {
-                    if (win.isDrawnLw() && okToDisplay()) {
-                        winAnimator.applyEnterAnimationLocked();
-                    }
-                    if ((win.mAttrs.flags
-                            & WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) != 0) {
-                        if (DEBUG_VISIBILITY) Slog.v(TAG,
-                                "Relayout window turning screen on: " + win);
-                        win.mTurnOnScreen = true;
-                    }
-                    if (win.isConfigChanged()) {
-                        if (DEBUG_CONFIGURATION) Slog.i(TAG, "Window " + win
-                                + " visible with new config: " + mCurConfiguration);
-                        outConfig.setTo(mCurConfiguration);
-                    }
-                }
-                if ((attrChanges&WindowManager.LayoutParams.FORMAT_CHANGED) != 0) {
-                    // To change the format, we need to re-build the surface.
-                    winAnimator.destroySurfaceLocked();
-                    toBeDisplayed = true;
-                    surfaceChanged = true;
-                }
-                try {
-                    if (!win.mHasSurface) {
-                        surfaceChanged = true;
-                    }
-                    SurfaceControl surfaceControl = winAnimator.createSurfaceLocked();
-                    if (surfaceControl != null) {
-                        outSurface.copyFrom(surfaceControl);
-                        if (SHOW_TRANSACTIONS) Slog.i(TAG,
-                                "  OUT SURFACE " + outSurface + ": copied");
-                    } else {
-                        // For some reason there isn't a surface.  Clear the
-                        // caller's object so they see the same state.
-                        outSurface.release();
-                    }
-                } catch (Exception e) {
-                    mInputMonitor.updateInputWindowsLw(true /*force*/);
-
-                    Slog.w(TAG, "Exception thrown when creating surface for client "
-                             + client + " (" + win.mAttrs.getTitle() + ")",
-                             e);
-                    Binder.restoreCallingIdentity(origId);
-                    return 0;
-                }
-                if (toBeDisplayed) {
-                    focusMayChange = isDefaultDisplay;
-                }
-                if (win.mAttrs.type == TYPE_INPUT_METHOD
-                        && mInputMethodWindow == null) {
-                    mInputMethodWindow = win;
-                    imMayMove = true;
-                }
-                if (win.mAttrs.type == TYPE_BASE_APPLICATION
-                        && win.mAppToken != null
-                        && win.mAppToken.startingWindow != null) {
-                    // Special handling of starting window over the base
-                    // window of the app: propagate lock screen flags to it,
-                    // to provide the correct semantics while starting.
-                    final int mask =
-                        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
-                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
-                        | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
-                    WindowManager.LayoutParams sa = win.mAppToken.startingWindow.mAttrs;
-                    sa.flags = (sa.flags&~mask) | (win.mAttrs.flags&mask);
-                }
-            } else {
-                winAnimator.mEnterAnimationPending = false;
-                if (winAnimator.mSurfaceControl != null) {
-                    if (DEBUG_VISIBILITY) Slog.i(TAG, "Relayout invis " + win
-                            + ": mExiting=" + win.mExiting);
-                    // If we are not currently running the exit animation, we
-                    // need to see about starting one.
-                    if (!win.mExiting) {
-                        surfaceChanged = true;
-                        // Try starting an animation; if there isn't one, we
-                        // can destroy the surface right away.
-                        int transit = WindowManagerPolicy.TRANSIT_EXIT;
-                        if (win.mAttrs.type == TYPE_APPLICATION_STARTING) {
-                            transit = WindowManagerPolicy.TRANSIT_PREVIEW_DONE;
-                        }
-                        if (win.isWinVisibleLw() &&
-                                winAnimator.applyAnimationLocked(transit, false)) {
-                            focusMayChange = isDefaultDisplay;
-                            win.mExiting = true;
-                        } else if (win.mWinAnimator.isAnimating()) {
-                            // Currently in a hide animation... turn this into
-                            // an exit.
-                            win.mExiting = true;
-                        } else if (win == mWallpaperTarget) {
-                            // If the wallpaper is currently behind this
-                            // window, we need to change both of them inside
-                            // of a transaction to avoid artifacts.
-                            win.mExiting = true;
-                            win.mWinAnimator.mAnimating = true;
-                        } else {
-                            if (mInputMethodWindow == win) {
-                                mInputMethodWindow = null;
-                            }
-                            winAnimator.destroySurfaceLocked();
-                        }
-                        //TODO (multidisplay): Magnification is supported only for the default
-                        if (mDisplayMagnifier != null
-                                && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                            mDisplayMagnifier.onWindowTransitionLocked(win, transit);
-                        }
-                    }
-                }
-
-                outSurface.release();
-                if (DEBUG_VISIBILITY) Slog.i(TAG, "Releasing surface in: " + win);
-            }
-
-            if (focusMayChange) {
-                //System.out.println("Focus may change: " + win.mAttrs.getTitle());
-                if (updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
-                        false /*updateInputWindows*/)) {
-                    imMayMove = false;
-                }
-                //System.out.println("Relayout " + win + ": focus=" + mCurrentFocus);
-            }
-
-            // updateFocusedWindowLocked() already assigned layers so we only need to
-            // reassign them at this point if the IM window state gets shuffled
-            if (imMayMove && (moveInputMethodWindowsIfNeededLocked(false) || toBeDisplayed)) {
-                // Little hack here -- we -should- be able to rely on the
-                // function to return true if the IME has moved and needs
-                // its layer recomputed.  However, if the IME was hidden
-                // and isn't actually moved in the list, its layer may be
-                // out of data so we make sure to recompute it.
-                assignLayersLocked(win.getWindowList());
-            }
-
-            if (wallpaperMayMove) {
-                getDefaultDisplayContentLocked().pendingLayoutChanges |=
-                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-            }
-
-            win.mDisplayContent.layoutNeeded = true;
-            win.mGivenInsetsPending = (flags&WindowManagerGlobal.RELAYOUT_INSETS_PENDING) != 0;
-            configChanged = updateOrientationFromAppTokensLocked(false);
-            performLayoutAndPlaceSurfacesLocked();
-            if (toBeDisplayed && win.mIsWallpaper) {
-                DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
-                updateWallpaperOffsetLocked(win,
-                        displayInfo.logicalWidth, displayInfo.logicalHeight, false);
-            }
-            if (win.mAppToken != null) {
-                win.mAppToken.updateReportedVisibilityLocked();
-            }
-            outFrame.set(win.mCompatFrame);
-            outOverscanInsets.set(win.mOverscanInsets);
-            outContentInsets.set(win.mContentInsets);
-            outVisibleInsets.set(win.mVisibleInsets);
-            if (localLOGV) Slog.v(
-                TAG, "Relayout given client " + client.asBinder()
-                + ", requestedWidth=" + requestedWidth
-                + ", requestedHeight=" + requestedHeight
-                + ", viewVisibility=" + viewVisibility
-                + "\nRelayout returning frame=" + outFrame
-                + ", surface=" + outSurface);
-
-            if (localLOGV || DEBUG_FOCUS) Slog.v(
-                TAG, "Relayout of " + win + ": focusMayChange=" + focusMayChange);
-
-            inTouchMode = mInTouchMode;
-            animating = mAnimator.mAnimating && win.mWinAnimator.isAnimating();
-            if (animating && !mRelayoutWhileAnimating.contains(win)) {
-                mRelayoutWhileAnimating.add(win);
-            }
-
-            mInputMonitor.updateInputWindowsLw(true /*force*/);
-
-            if (DEBUG_LAYOUT) {
-                Slog.v(TAG, "Relayout complete " + win + ": outFrame=" + outFrame.toShortString());
-            }
-        }
-
-        if (configChanged) {
-            sendNewConfiguration();
-        }
-
-        Binder.restoreCallingIdentity(origId);
-
-        return (inTouchMode ? WindowManagerGlobal.RELAYOUT_RES_IN_TOUCH_MODE : 0)
-                | (toBeDisplayed ? WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME : 0)
-                | (surfaceChanged ? WindowManagerGlobal.RELAYOUT_RES_SURFACE_CHANGED : 0)
-                | (animating ? WindowManagerGlobal.RELAYOUT_RES_ANIMATING : 0);
-    }
-
-    public void performDeferredDestroyWindow(Session session, IWindow client) {
-        long origId = Binder.clearCallingIdentity();
-
-        try {
-            synchronized (mWindowMap) {
-                WindowState win = windowForClientLocked(session, client, false);
-                if (win == null) {
-                    return;
-                }
-                win.mWinAnimator.destroyDeferredSurfaceLocked();
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    public boolean outOfMemoryWindow(Session session, IWindow client) {
-        long origId = Binder.clearCallingIdentity();
-
-        try {
-            synchronized (mWindowMap) {
-                WindowState win = windowForClientLocked(session, client, false);
-                if (win == null) {
-                    return false;
-                }
-                return reclaimSomeSurfaceMemoryLocked(win.mWinAnimator, "from-client", false);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    public void finishDrawingWindow(Session session, IWindow client) {
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized (mWindowMap) {
-                WindowState win = windowForClientLocked(session, client, false);
-                if (win != null && win.mWinAnimator.finishDrawingLocked()) {
-                    if ((win.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
-                        getDefaultDisplayContentLocked().pendingLayoutChanges |=
-                                WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-                    }
-                    win.mDisplayContent.layoutNeeded = true;
-                    requestTraversalLocked();
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public void getWindowFrame(IBinder token, Rect outBounds) {
-        if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO,
-                "getWindowInfo()")) {
-            throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission.");
-        }
-        synchronized (mWindowMap) {
-            WindowState windowState = mWindowMap.get(token);
-            if (windowState != null) {
-                outBounds.set(windowState.mFrame);
-            } else {
-                outBounds.setEmpty();
-            }
-        }
-    }
-
-    @Override
-    public void setMagnificationSpec(MagnificationSpec spec) {
-        if (!checkCallingPermission(android.Manifest.permission.MAGNIFY_DISPLAY,
-                "setMagnificationSpec()")) {
-            throw new SecurityException("Requires MAGNIFY_DISPLAY permission.");
-        }
-        synchronized (mWindowMap) {
-            if (mDisplayMagnifier != null) {
-                mDisplayMagnifier.setMagnificationSpecLocked(spec);
-            } else {
-                throw new IllegalStateException("Magnification callbacks not set!");
-            }
-        }
-        if (Binder.getCallingPid() != android.os.Process.myPid()) {
-            spec.recycle();
-        }
-    }
-
-    @Override
-    public MagnificationSpec getCompatibleMagnificationSpecForWindow(IBinder windowToken) {
-        if (!checkCallingPermission(android.Manifest.permission.MAGNIFY_DISPLAY,
-                "getCompatibleMagnificationSpecForWindow()")) {
-            throw new SecurityException("Requires MAGNIFY_DISPLAY permission.");
-        }
-        synchronized (mWindowMap) {
-            WindowState windowState = mWindowMap.get(windowToken);
-            if (windowState == null) {
-                return null;
-            }
-            MagnificationSpec spec = null;
-            if (mDisplayMagnifier != null) {
-                spec = mDisplayMagnifier.getMagnificationSpecForWindowLocked(windowState);
-            }
-            if ((spec == null || spec.isNop()) && windowState.mGlobalScale == 1.0f) {
-                return null;
-            }
-            spec = (spec == null) ? MagnificationSpec.obtain() : MagnificationSpec.obtain(spec);
-            spec.scale *= windowState.mGlobalScale;
-            return spec;
-        }
-    }
-
-    @Override
-    public void setMagnificationCallbacks(IMagnificationCallbacks callbacks) {
-        if (!checkCallingPermission(android.Manifest.permission.MAGNIFY_DISPLAY,
-                "setMagnificationCallbacks()")) {
-            throw new SecurityException("Requires MAGNIFY_DISPLAY permission.");
-        }
-        synchronized (mWindowMap) {
-            if (mDisplayMagnifier == null) {
-                mDisplayMagnifier = new DisplayMagnifier(this, callbacks);
-            } else {
-                if (callbacks == null) {
-                    if (mDisplayMagnifier != null) {
-                        mDisplayMagnifier.destroyLocked();
-                        mDisplayMagnifier = null;
-                    }
-                } else {
-                    throw new IllegalStateException("Magnification callbacks already set!");
-                }
-            }
-        }
-    }
-
-    private boolean applyAnimationLocked(AppWindowToken atoken,
-            WindowManager.LayoutParams lp, int transit, boolean enter) {
-        // Only apply an animation if the display isn't frozen.  If it is
-        // frozen, there is no reason to animate and it can cause strange
-        // artifacts when we unfreeze the display if some different animation
-        // is running.
-        if (okToDisplay()) {
-            DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
-            final int width = displayInfo.appWidth;
-            final int height = displayInfo.appHeight;
-            if (DEBUG_APP_TRANSITIONS || DEBUG_ANIM) Slog.v(TAG, "applyAnimation: atoken="
-                    + atoken);
-            Animation a = mAppTransition.loadAnimation(lp, transit, enter, width, height);
-            if (a != null) {
-                if (DEBUG_ANIM) {
-                    RuntimeException e = null;
-                    if (!HIDE_STACK_CRAWLS) {
-                        e = new RuntimeException();
-                        e.fillInStackTrace();
-                    }
-                    Slog.v(TAG, "Loaded animation " + a + " for " + atoken, e);
-                }
-                atoken.mAppAnimator.setAnimation(a, width, height);
-            }
-        } else {
-            atoken.mAppAnimator.clearAnimation();
-        }
-
-        return atoken.mAppAnimator.animation != null;
-    }
-
-    // -------------------------------------------------------------
-    // Application Window Tokens
-    // -------------------------------------------------------------
-
-    public void validateAppTokens(int stackId, List<TaskGroup> tasks) {
-        synchronized (mWindowMap) {
-            int t = tasks.size() - 1;
-            if (t < 0) {
-                Slog.w(TAG, "validateAppTokens: empty task list");
-                return;
-            }
-
-            TaskGroup task = tasks.get(0);
-            int taskId = task.taskId;
-            Task targetTask = mTaskIdToTask.get(taskId);
-            DisplayContent displayContent = targetTask.getDisplayContent();
-            if (displayContent == null) {
-                Slog.w(TAG, "validateAppTokens: no Display for taskId=" + taskId);
-                return;
-            }
-
-            final ArrayList<Task> localTasks = mStackIdToStack.get(stackId).getTasks();
-            int taskNdx;
-            for (taskNdx = localTasks.size() - 1; taskNdx >= 0 && t >= 0; --taskNdx, --t) {
-                AppTokenList localTokens = localTasks.get(taskNdx).mAppTokens;
-                task = tasks.get(t);
-                List<IApplicationToken> tokens = task.tokens;
-
-                DisplayContent lastDisplayContent = displayContent;
-                displayContent = mTaskIdToTask.get(taskId).getDisplayContent();
-                if (displayContent != lastDisplayContent) {
-                    Slog.w(TAG, "validateAppTokens: displayContent changed in TaskGroup list!");
-                    return;
-                }
-
-                int tokenNdx;
-                int v;
-                for (tokenNdx = localTokens.size() - 1, v = task.tokens.size() - 1;
-                        tokenNdx >= 0 && v >= 0; ) {
-                    final AppWindowToken atoken = localTokens.get(tokenNdx);
-                    if (atoken.removed) {
-                        --tokenNdx;
-                        continue;
-                    }
-                    if (tokens.get(v) != atoken.token) {
-                        break;
-                    }
-                    --tokenNdx;
-                    v--;
-                }
-
-                if (tokenNdx >= 0 || v >= 0) {
-                    break;
-                }
-            }
-
-            if (taskNdx >= 0 || t >= 0) {
-                Slog.w(TAG, "validateAppTokens: Mismatch! ActivityManager=" + tasks);
-                Slog.w(TAG, "validateAppTokens: Mismatch! WindowManager=" + localTasks);
-                Slog.w(TAG, "validateAppTokens: Mismatch! Callers=" + Debug.getCallers(4));
-            }
-        }
-    }
-
-    public void validateStackOrder(Integer[] remoteStackIds) {
-        // TODO:
-    }
-
-    boolean checkCallingPermission(String permission, String func) {
-        // Quick check: if the calling permission is me, it's all okay.
-        if (Binder.getCallingPid() == Process.myPid()) {
-            return true;
-        }
-
-        if (mContext.checkCallingPermission(permission)
-                == PackageManager.PERMISSION_GRANTED) {
-            return true;
-        }
-        String msg = "Permission Denial: " + func + " from pid="
-                + Binder.getCallingPid()
-                + ", uid=" + Binder.getCallingUid()
-                + " requires " + permission;
-        Slog.w(TAG, msg);
-        return false;
-    }
-
-    boolean okToDisplay() {
-        return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOnFully();
-    }
-
-    AppWindowToken findAppWindowToken(IBinder token) {
-        WindowToken wtoken = mTokenMap.get(token);
-        if (wtoken == null) {
-            return null;
-        }
-        return wtoken.appWindowToken;
-    }
-
-    @Override
-    public void addWindowToken(IBinder token, int type) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "addWindowToken()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            WindowToken wtoken = mTokenMap.get(token);
-            if (wtoken != null) {
-                Slog.w(TAG, "Attempted to add existing input method token: " + token);
-                return;
-            }
-            wtoken = new WindowToken(this, token, type, true);
-            mTokenMap.put(token, wtoken);
-            if (type == TYPE_WALLPAPER) {
-                mWallpaperTokens.add(wtoken);
-            }
-        }
-    }
-
-    @Override
-    public void removeWindowToken(IBinder token) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "removeWindowToken()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        final long origId = Binder.clearCallingIdentity();
-        synchronized(mWindowMap) {
-            DisplayContent displayContent = null;
-            WindowToken wtoken = mTokenMap.remove(token);
-            if (wtoken != null) {
-                boolean delayed = false;
-                if (!wtoken.hidden) {
-                    final int N = wtoken.windows.size();
-                    boolean changed = false;
-
-                    for (int i=0; i<N; i++) {
-                        WindowState win = wtoken.windows.get(i);
-                        displayContent = win.mDisplayContent;
-
-                        if (win.mWinAnimator.isAnimating()) {
-                            delayed = true;
-                        }
-
-                        if (win.isVisibleNow()) {
-                            win.mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT,
-                                    false);
-                            //TODO (multidisplay): Magnification is supported only for the default
-                            if (mDisplayMagnifier != null && win.isDefaultDisplay()) {
-                                mDisplayMagnifier.onWindowTransitionLocked(win,
-                                        WindowManagerPolicy.TRANSIT_EXIT);
-                            }
-                            changed = true;
-                            displayContent.layoutNeeded = true;
-                        }
-                    }
-
-                    wtoken.hidden = true;
-
-                    if (changed) {
-                        performLayoutAndPlaceSurfacesLocked();
-                        updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
-                                false /*updateInputWindows*/);
-                    }
-
-                    if (delayed) {
-                        displayContent.mExitingTokens.add(wtoken);
-                    } else if (wtoken.windowType == TYPE_WALLPAPER) {
-                        mWallpaperTokens.remove(wtoken);
-                    }
-                }
-
-                mInputMonitor.updateInputWindowsLw(true /*force*/);
-            } else {
-                Slog.w(TAG, "Attempted to remove non-existing token: " + token);
-            }
-        }
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    private Task createTask(int taskId, int stackId, int userId, AppWindowToken atoken) {
-        final TaskStack stack = mStackIdToStack.get(stackId);
-        if (stack == null) {
-            throw new IllegalArgumentException("addAppToken: invalid stackId=" + stackId);
-        }
-        EventLog.writeEvent(EventLogTags.WM_TASK_CREATED, taskId, stackId);
-        Task task = new Task(atoken, stack, userId);
-        mTaskIdToTask.put(taskId, task);
-        stack.addTask(task, true);
-        return task;
-    }
-
-    @Override
-    public void addAppToken(int addPos, IApplicationToken token, int taskId, int stackId,
-            int requestedOrientation, boolean fullscreen, boolean showWhenLocked, int userId,
-            int configChanges) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "addAppToken()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        // Get the dispatching timeout here while we are not holding any locks so that it
-        // can be cached by the AppWindowToken.  The timeout value is used later by the
-        // input dispatcher in code that does hold locks.  If we did not cache the value
-        // here we would run the chance of introducing a deadlock between the window manager
-        // (which holds locks while updating the input dispatcher state) and the activity manager
-        // (which holds locks while querying the application token).
-        long inputDispatchingTimeoutNanos;
-        try {
-            inputDispatchingTimeoutNanos = token.getKeyDispatchingTimeout() * 1000000L;
-        } catch (RemoteException ex) {
-            Slog.w(TAG, "Could not get dispatching timeout.", ex);
-            inputDispatchingTimeoutNanos = DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
-        }
-
-        synchronized(mWindowMap) {
-            AppWindowToken atoken = findAppWindowToken(token.asBinder());
-            if (atoken != null) {
-                Slog.w(TAG, "Attempted to add existing app token: " + token);
-                return;
-            }
-            atoken = new AppWindowToken(this, token);
-            atoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
-            atoken.groupId = taskId;
-            atoken.appFullscreen = fullscreen;
-            atoken.showWhenLocked = showWhenLocked;
-            atoken.requestedOrientation = requestedOrientation;
-            atoken.layoutConfigChanges = (configChanges &
-                    (ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_ORIENTATION)) != 0;
-            if (DEBUG_TOKEN_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG, "addAppToken: " + atoken
-                    + " to stack=" + stackId + " task=" + taskId + " at " + addPos);
-
-            Task task = mTaskIdToTask.get(taskId);
-            if (task == null) {
-                task = createTask(taskId, stackId, userId, atoken);
-            } else {
-                task.addAppToken(addPos, atoken);
-            }
-
-            mTokenMap.put(token.asBinder(), atoken);
-
-            // Application tokens start out hidden.
-            atoken.hidden = true;
-            atoken.hiddenRequested = true;
-
-            //dump();
-        }
-    }
-
-    @Override
-    public void setAppGroupId(IBinder token, int groupId) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppGroupId()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            final AppWindowToken atoken = findAppWindowToken(token);
-            if (atoken == null) {
-                Slog.w(TAG, "Attempted to set group id of non-existing app token: " + token);
-                return;
-            }
-            Task oldTask = mTaskIdToTask.get(atoken.groupId);
-            oldTask.removeAppToken(atoken);
-
-            atoken.groupId = groupId;
-            Task newTask = mTaskIdToTask.get(groupId);
-            if (newTask == null) {
-                newTask = createTask(groupId, oldTask.mStack.mStackId, oldTask.mUserId, atoken);
-            }
-            newTask.mAppTokens.add(atoken);
-        }
-    }
-
-    public int getOrientationFromWindowsLocked() {
-        if (mDisplayFrozen || mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
-            // If the display is frozen, some activities may be in the middle
-            // of restarting, and thus have removed their old window.  If the
-            // window has the flag to hide the lock screen, then the lock screen
-            // can re-appear and inflict its own orientation on us.  Keep the
-            // orientation stable until this all settles down.
-            return mLastWindowForcedOrientation;
-        }
-
-        // TODO(multidisplay): Change to the correct display.
-        final WindowList windows = getDefaultWindowListLocked();
-        int pos = windows.size() - 1;
-        while (pos >= 0) {
-            WindowState win = windows.get(pos);
-            pos--;
-            if (win.mAppToken != null) {
-                // We hit an application window. so the orientation will be determined by the
-                // app window. No point in continuing further.
-                return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
-            }
-            if (!win.isVisibleLw() || !win.mPolicyVisibilityAfterAnim) {
-                continue;
-            }
-            int req = win.mAttrs.screenOrientation;
-            if((req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) ||
-                    (req == ActivityInfo.SCREEN_ORIENTATION_BEHIND)){
-                continue;
-            }
-
-            if (DEBUG_ORIENTATION) Slog.v(TAG, win + " forcing orientation to " + req);
-            return (mLastWindowForcedOrientation=req);
-        }
-        return (mLastWindowForcedOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
-    }
-
-    public int getOrientationFromAppTokensLocked() {
-        int lastOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-        boolean findingBehind = false;
-        boolean lastFullscreen = false;
-        // TODO: Multi window.
-        DisplayContent displayContent = getDefaultDisplayContentLocked();
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int firstToken = tokens.size() - 1;
-            for (int tokenNdx = firstToken; tokenNdx >= 0; --tokenNdx) {
-                final AppWindowToken atoken = tokens.get(tokenNdx);
-
-                if (DEBUG_APP_ORIENTATION) Slog.v(TAG, "Checking app orientation: " + atoken);
-
-                // if we're about to tear down this window and not seek for
-                // the behind activity, don't use it for orientation
-                if (!findingBehind
-                        && (!atoken.hidden && atoken.hiddenRequested)) {
-                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken
-                            + " -- going to hide");
-                    continue;
-                }
-
-                if (tokenNdx == firstToken) {
-                    // If we have hit a new Task, and the bottom
-                    // of the previous group didn't explicitly say to use
-                    // the orientation behind it, and the last app was
-                    // full screen, then we'll stick with the
-                    // user's orientation.
-                    if (lastOrientation != ActivityInfo.SCREEN_ORIENTATION_BEHIND
-                            && lastFullscreen) {
-                        if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken
-                                + " -- end of group, return " + lastOrientation);
-                        return lastOrientation;
-                    }
-                }
-
-                // We ignore any hidden applications on the top.
-                if (atoken.hiddenRequested || atoken.willBeHidden) {
-                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping " + atoken
-                            + " -- hidden on top");
-                    continue;
-                }
-
-                if (tokenNdx == 0) {
-                    // Last token in this task.
-                    lastOrientation = atoken.requestedOrientation;
-                }
-
-                int or = atoken.requestedOrientation;
-                // If this application is fullscreen, and didn't explicitly say
-                // to use the orientation behind it, then just take whatever
-                // orientation it has and ignores whatever is under it.
-                lastFullscreen = atoken.appFullscreen;
-                if (lastFullscreen
-                        && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
-                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken
-                            + " -- full screen, return " + or);
-                    return or;
-                }
-                // If this application has requested an explicit orientation,
-                // then use it.
-                if (or != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
-                        && or != ActivityInfo.SCREEN_ORIENTATION_BEHIND) {
-                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Done at " + atoken
-                            + " -- explicitly set, return " + or);
-                    return or;
-                }
-                findingBehind |= (or == ActivityInfo.SCREEN_ORIENTATION_BEHIND);
-            }
-        }
-        if (DEBUG_ORIENTATION) Slog.v(TAG, "No app is requesting an orientation");
-        return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-    }
-
-    @Override
-    public Configuration updateOrientationFromAppTokens(
-            Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "updateOrientationFromAppTokens()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        Configuration config = null;
-        long ident = Binder.clearCallingIdentity();
-
-        synchronized(mWindowMap) {
-            config = updateOrientationFromAppTokensLocked(currentConfig,
-                    freezeThisOneIfNeeded);
-        }
-
-        Binder.restoreCallingIdentity(ident);
-        return config;
-    }
-
-    private Configuration updateOrientationFromAppTokensLocked(
-            Configuration currentConfig, IBinder freezeThisOneIfNeeded) {
-        Configuration config = null;
-
-        if (updateOrientationFromAppTokensLocked(false)) {
-            if (freezeThisOneIfNeeded != null) {
-                AppWindowToken atoken = findAppWindowToken(freezeThisOneIfNeeded);
-                if (atoken != null) {
-                    startAppFreezingScreenLocked(atoken, ActivityInfo.CONFIG_ORIENTATION);
-                }
-            }
-            config = computeNewConfigurationLocked();
-
-        } else if (currentConfig != null) {
-            // No obvious action we need to take, but if our current
-            // state mismatches the activity manager's, update it,
-            // disregarding font scale, which should remain set to
-            // the value of the previous configuration.
-            mTempConfiguration.setToDefaults();
-            mTempConfiguration.fontScale = currentConfig.fontScale;
-            if (computeScreenConfigurationLocked(mTempConfiguration)) {
-                if (currentConfig.diff(mTempConfiguration) != 0) {
-                    mWaitingForConfig = true;
-                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
-                    displayContent.layoutNeeded = true;
-                    int anim[] = new int[2];
-                    if (displayContent.isDimming()) {
-                        anim[0] = anim[1] = 0;
-                    } else {
-                        mPolicy.selectRotationAnimationLw(anim);
-                    }
-                    startFreezingDisplayLocked(false, anim[0], anim[1]);
-                    config = new Configuration(mTempConfiguration);
-                }
-            }
-        }
-
-        return config;
-    }
-
-    /*
-     * Determine the new desired orientation of the display, returning
-     * a non-null new Configuration if it has changed from the current
-     * orientation.  IF TRUE IS RETURNED SOMEONE MUST CALL
-     * setNewConfiguration() TO TELL THE WINDOW MANAGER IT CAN UNFREEZE THE
-     * SCREEN.  This will typically be done for you if you call
-     * sendNewConfiguration().
-     *
-     * The orientation is computed from non-application windows first. If none of
-     * the non-application windows specify orientation, the orientation is computed from
-     * application tokens.
-     * @see android.view.IWindowManager#updateOrientationFromAppTokens(
-     * android.os.IBinder)
-     */
-    boolean updateOrientationFromAppTokensLocked(boolean inTransaction) {
-        long ident = Binder.clearCallingIdentity();
-        try {
-            int req = getOrientationFromWindowsLocked();
-            if (req == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
-                req = getOrientationFromAppTokensLocked();
-            }
-
-            if (req != mForcedAppOrientation) {
-                mForcedAppOrientation = req;
-                //send a message to Policy indicating orientation change to take
-                //action like disabling/enabling sensors etc.,
-                mPolicy.setCurrentOrientationLw(req);
-                if (updateRotationUncheckedLocked(inTransaction)) {
-                    // changed
-                    return true;
-                }
-            }
-
-            return false;
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public void setNewConfiguration(Configuration config) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setNewConfiguration()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            mCurConfiguration = new Configuration(config);
-            if (mWaitingForConfig) {
-                mWaitingForConfig = false;
-                mLastFinishedFreezeSource = "new-config";
-            }
-            performLayoutAndPlaceSurfacesLocked();
-        }
-    }
-
-    @Override
-    public void setAppOrientation(IApplicationToken token, int requestedOrientation) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppOrientation()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            AppWindowToken atoken = findAppWindowToken(token.asBinder());
-            if (atoken == null) {
-                Slog.w(TAG, "Attempted to set orientation of non-existing app token: " + token);
-                return;
-            }
-
-            atoken.requestedOrientation = requestedOrientation;
-        }
-    }
-
-    @Override
-    public int getAppOrientation(IApplicationToken token) {
-        synchronized(mWindowMap) {
-            AppWindowToken wtoken = findAppWindowToken(token.asBinder());
-            if (wtoken == null) {
-                return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-            }
-
-            return wtoken.requestedOrientation;
-        }
-    }
-
-    /** Call while in a Surface transaction. */
-    void setFocusedStackLayer() {
-        mFocusedStackLayer = 0;
-        if (mFocusedApp != null) {
-            final WindowList windows = mFocusedApp.allAppWindows;
-            for (int i = windows.size() - 1; i >= 0; --i) {
-                final WindowState win = windows.get(i);
-                final int animLayer = win.mWinAnimator.mAnimLayer;
-                if (win.mAttachedWindow == null && win.isVisibleLw() &&
-                        animLayer > mFocusedStackLayer) {
-                    mFocusedStackLayer = animLayer + LAYER_OFFSET_FOCUSED_STACK;
-                }
-            }
-        }
-        if (DEBUG_LAYERS) Slog.v(TAG, "Setting FocusedStackFrame to layer=" +
-                mFocusedStackLayer);
-        mFocusedStackFrame.setLayer(mFocusedStackLayer);
-    }
-
-    void setFocusedStackFrame() {
-        final TaskStack stack;
-        if (mFocusedApp != null) {
-            Task task = mTaskIdToTask.get(mFocusedApp.groupId);
-            stack = task.mStack;
-            task.getDisplayContent().setTouchExcludeRegion(stack);
-        } else {
-            stack = null;
-        }
-        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setFocusedStackFrame");
-        SurfaceControl.openTransaction();
-        try {
-            if (stack == null) {
-                mFocusedStackFrame.setVisibility(false);
-            } else {
-                final StackBox box = stack.mStackBox;
-                final Rect bounds = box.mBounds;
-                final boolean multipleStacks = box.mParent != null;
-                mFocusedStackFrame.setBounds(bounds);
-                mFocusedStackFrame.setVisibility(multipleStacks);
-            }
-        } finally {
-            SurfaceControl.closeTransaction();
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> CLOSE TRANSACTION setFocusedStackFrame");
-        }
-    }
-
-    @Override
-    public void setFocusedApp(IBinder token, boolean moveFocusNow) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setFocusedApp()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            boolean changed = false;
-            if (token == null) {
-                if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Clearing focused app, was " + mFocusedApp);
-                changed = mFocusedApp != null;
-                mFocusedApp = null;
-                if (changed) {
-                    mInputMonitor.setFocusedAppLw(null);
-                }
-            } else {
-                AppWindowToken newFocus = findAppWindowToken(token);
-                if (newFocus == null) {
-                    Slog.w(TAG, "Attempted to set focus to non-existing app token: " + token);
-                    return;
-                }
-                changed = mFocusedApp != newFocus;
-                if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Set focused app to: " + newFocus
-                        + " old focus=" + mFocusedApp + " moveFocusNow=" + moveFocusNow);
-                mFocusedApp = newFocus;
-                if (changed) {
-                    mInputMonitor.setFocusedAppLw(newFocus);
-                }
-            }
-
-            if (moveFocusNow && changed) {
-                final long origId = Binder.clearCallingIdentity();
-                updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
-                Binder.restoreCallingIdentity(origId);
-            }
-        }
-    }
-
-    @Override
-    public void prepareAppTransition(int transit, boolean alwaysKeepCurrent) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "prepareAppTransition()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            if (DEBUG_APP_TRANSITIONS) Slog.v(
-                    TAG, "Prepare app transition: transit=" + transit
-                    + " " + mAppTransition
-                    + " alwaysKeepCurrent=" + alwaysKeepCurrent
-                    + " Callers=" + Debug.getCallers(3));
-            if (okToDisplay()) {
-                if (!mAppTransition.isTransitionSet() || mAppTransition.isTransitionNone()) {
-                    mAppTransition.setAppTransition(transit);
-                } else if (!alwaysKeepCurrent) {
-                    if (transit == AppTransition.TRANSIT_TASK_OPEN
-                            && mAppTransition.isTransitionEqual(
-                                    AppTransition.TRANSIT_TASK_CLOSE)) {
-                        // Opening a new task always supersedes a close for the anim.
-                        mAppTransition.setAppTransition(transit);
-                    } else if (transit == AppTransition.TRANSIT_ACTIVITY_OPEN
-                            && mAppTransition.isTransitionEqual(
-                                AppTransition.TRANSIT_ACTIVITY_CLOSE)) {
-                        // Opening a new activity always supersedes a close for the anim.
-                        mAppTransition.setAppTransition(transit);
-                    }
-                }
-                mAppTransition.prepare();
-                mStartingIconInTransition = false;
-                mSkipAppTransitionAnimation = false;
-                mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
-                mH.sendEmptyMessageDelayed(H.APP_TRANSITION_TIMEOUT, 5000);
-            }
-        }
-    }
-
-    @Override
-    public int getPendingAppTransition() {
-        return mAppTransition.getAppTransition();
-    }
-
-    @Override
-    public void overridePendingAppTransition(String packageName,
-            int enterAnim, int exitAnim, IRemoteCallback startedCallback) {
-        synchronized(mWindowMap) {
-            mAppTransition.overridePendingAppTransition(packageName, enterAnim, exitAnim,
-                    startedCallback);
-        }
-    }
-
-    @Override
-    public void overridePendingAppTransitionScaleUp(int startX, int startY, int startWidth,
-            int startHeight) {
-        synchronized(mWindowMap) {
-            mAppTransition.overridePendingAppTransitionScaleUp(startX, startY, startWidth,
-                    startHeight);
-        }
-    }
-
-    @Override
-    public void overridePendingAppTransitionThumb(Bitmap srcThumb, int startX,
-            int startY, IRemoteCallback startedCallback, boolean scaleUp) {
-        synchronized(mWindowMap) {
-            mAppTransition.overridePendingAppTransitionThumb(srcThumb, startX, startY,
-                    startedCallback, scaleUp);
-        }
-    }
-
-    @Override
-    public void executeAppTransition() {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "executeAppTransition()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            if (DEBUG_APP_TRANSITIONS) {
-                RuntimeException e = new RuntimeException("here");
-                e.fillInStackTrace();
-                Slog.w(TAG, "Execute app transition: " + mAppTransition, e);
-            }
-            if (mAppTransition.isTransitionSet()) {
-                mAppTransition.setReady();
-                final long origId = Binder.clearCallingIdentity();
-                performLayoutAndPlaceSurfacesLocked();
-                Binder.restoreCallingIdentity(origId);
-            }
-        }
-    }
-
-    @Override
-    public void setAppStartingWindow(IBinder token, String pkg,
-            int theme, CompatibilityInfo compatInfo,
-            CharSequence nonLocalizedLabel, int labelRes, int icon, int logo,
-            int windowFlags, IBinder transferFrom, boolean createIfNeeded) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppStartingWindow()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            if (DEBUG_STARTING_WINDOW) Slog.v(
-                    TAG, "setAppStartingWindow: token=" + token + " pkg=" + pkg
-                    + " transferFrom=" + transferFrom);
-
-            AppWindowToken wtoken = findAppWindowToken(token);
-            if (wtoken == null) {
-                Slog.w(TAG, "Attempted to set icon of non-existing app token: " + token);
-                return;
-            }
-
-            // If the display is frozen, we won't do anything until the
-            // actual window is displayed so there is no reason to put in
-            // the starting window.
-            if (!okToDisplay()) {
-                return;
-            }
-
-            if (wtoken.startingData != null) {
-                return;
-            }
-
-            if (transferFrom != null) {
-                AppWindowToken ttoken = findAppWindowToken(transferFrom);
-                if (ttoken != null) {
-                    WindowState startingWindow = ttoken.startingWindow;
-                    if (startingWindow != null) {
-                        if (mStartingIconInTransition) {
-                            // In this case, the starting icon has already
-                            // been displayed, so start letting windows get
-                            // shown immediately without any more transitions.
-                            mSkipAppTransitionAnimation = true;
-                        }
-                        if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
-                                "Moving existing starting " + startingWindow + " from " + ttoken
-                                + " to " + wtoken);
-                        final long origId = Binder.clearCallingIdentity();
-
-                        // Transfer the starting window over to the new
-                        // token.
-                        wtoken.startingData = ttoken.startingData;
-                        wtoken.startingView = ttoken.startingView;
-                        wtoken.startingDisplayed = ttoken.startingDisplayed;
-                        ttoken.startingDisplayed = false;
-                        wtoken.startingWindow = startingWindow;
-                        wtoken.reportedVisible = ttoken.reportedVisible;
-                        ttoken.startingData = null;
-                        ttoken.startingView = null;
-                        ttoken.startingWindow = null;
-                        ttoken.startingMoved = true;
-                        startingWindow.mToken = wtoken;
-                        startingWindow.mRootToken = wtoken;
-                        startingWindow.mAppToken = wtoken;
-                        startingWindow.mWinAnimator.mAppAnimator = wtoken.mAppAnimator;
-
-                        if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE || DEBUG_STARTING_WINDOW) {
-                            Slog.v(TAG, "Removing starting window: " + startingWindow);
-                        }
-                        removeStartingWindowTimeout(ttoken);
-                        startingWindow.getWindowList().remove(startingWindow);
-                        mWindowsChanged = true;
-                        if (DEBUG_ADD_REMOVE) Slog.v(TAG,
-                                "Removing starting " + startingWindow + " from " + ttoken);
-                        ttoken.windows.remove(startingWindow);
-                        ttoken.allAppWindows.remove(startingWindow);
-                        addWindowToListInOrderLocked(startingWindow, true);
-
-                        // Propagate other interesting state between the
-                        // tokens.  If the old token is displayed, we should
-                        // immediately force the new one to be displayed.  If
-                        // it is animating, we need to move that animation to
-                        // the new one.
-                        if (ttoken.allDrawn) {
-                            wtoken.allDrawn = true;
-                            wtoken.deferClearAllDrawn = ttoken.deferClearAllDrawn;
-                        }
-                        if (ttoken.firstWindowDrawn) {
-                            wtoken.firstWindowDrawn = true;
-                        }
-                        if (!ttoken.hidden) {
-                            wtoken.hidden = false;
-                            wtoken.hiddenRequested = false;
-                            wtoken.willBeHidden = false;
-                        }
-                        if (wtoken.clientHidden != ttoken.clientHidden) {
-                            wtoken.clientHidden = ttoken.clientHidden;
-                            wtoken.sendAppVisibilityToClients();
-                        }
-                        final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator;
-                        final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator;
-                        if (tAppAnimator.animation != null) {
-                            wAppAnimator.animation = tAppAnimator.animation;
-                            wAppAnimator.animating = tAppAnimator.animating;
-                            wAppAnimator.animLayerAdjustment = tAppAnimator.animLayerAdjustment;
-                            tAppAnimator.animation = null;
-                            tAppAnimator.animLayerAdjustment = 0;
-                            wAppAnimator.updateLayers();
-                            tAppAnimator.updateLayers();
-                        }
-
-                        updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
-                                true /*updateInputWindows*/);
-                        getDefaultDisplayContentLocked().layoutNeeded = true;
-                        performLayoutAndPlaceSurfacesLocked();
-                        Binder.restoreCallingIdentity(origId);
-                        return;
-                    } else if (ttoken.startingData != null) {
-                        // The previous app was getting ready to show a
-                        // starting window, but hasn't yet done so.  Steal it!
-                        if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
-                                "Moving pending starting from " + ttoken
-                                + " to " + wtoken);
-                        wtoken.startingData = ttoken.startingData;
-                        ttoken.startingData = null;
-                        ttoken.startingMoved = true;
-                        Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
-                        // Note: we really want to do sendMessageAtFrontOfQueue() because we
-                        // want to process the message ASAP, before any other queued
-                        // messages.
-                        mH.sendMessageAtFrontOfQueue(m);
-                        return;
-                    }
-                    final AppWindowAnimator tAppAnimator = ttoken.mAppAnimator;
-                    final AppWindowAnimator wAppAnimator = wtoken.mAppAnimator;
-                    if (tAppAnimator.thumbnail != null) {
-                        // The old token is animating with a thumbnail, transfer
-                        // that to the new token.
-                        if (wAppAnimator.thumbnail != null) {
-                            wAppAnimator.thumbnail.destroy();
-                        }
-                        wAppAnimator.thumbnail = tAppAnimator.thumbnail;
-                        wAppAnimator.thumbnailX = tAppAnimator.thumbnailX;
-                        wAppAnimator.thumbnailY = tAppAnimator.thumbnailY;
-                        wAppAnimator.thumbnailLayer = tAppAnimator.thumbnailLayer;
-                        wAppAnimator.thumbnailAnimation = tAppAnimator.thumbnailAnimation;
-                        tAppAnimator.thumbnail = null;
-                    }
-                }
-            }
-
-            // There is no existing starting window, and the caller doesn't
-            // want us to create one, so that's it!
-            if (!createIfNeeded) {
-                return;
-            }
-
-            // If this is a translucent window, then don't
-            // show a starting window -- the current effect (a full-screen
-            // opaque starting window that fades away to the real contents
-            // when it is ready) does not work for this.
-            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Checking theme of starting window: 0x"
-                    + Integer.toHexString(theme));
-            if (theme != 0) {
-                AttributeCache.Entry ent = AttributeCache.instance().get(pkg, theme,
-                        com.android.internal.R.styleable.Window, mCurrentUserId);
-                if (ent == null) {
-                    // Whoops!  App doesn't exist.  Um.  Okay.  We'll just
-                    // pretend like we didn't see that.
-                    return;
-                }
-                if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Translucent="
-                        + ent.array.getBoolean(
-                                com.android.internal.R.styleable.Window_windowIsTranslucent, false)
-                        + " Floating="
-                        + ent.array.getBoolean(
-                                com.android.internal.R.styleable.Window_windowIsFloating, false)
-                        + " ShowWallpaper="
-                        + ent.array.getBoolean(
-                                com.android.internal.R.styleable.Window_windowShowWallpaper, false));
-                if (ent.array.getBoolean(
-                        com.android.internal.R.styleable.Window_windowIsTranslucent, false)) {
-                    return;
-                }
-                if (ent.array.getBoolean(
-                        com.android.internal.R.styleable.Window_windowIsFloating, false)) {
-                    return;
-                }
-                if (ent.array.getBoolean(
-                        com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
-                    if (mWallpaperTarget == null) {
-                        // If this theme is requesting a wallpaper, and the wallpaper
-                        // is not curently visible, then this effectively serves as
-                        // an opaque window and our starting window transition animation
-                        // can still work.  We just need to make sure the starting window
-                        // is also showing the wallpaper.
-                        windowFlags |= FLAG_SHOW_WALLPAPER;
-                    } else {
-                        return;
-                    }
-                }
-            }
-
-            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Creating StartingData");
-            mStartingIconInTransition = true;
-            wtoken.startingData = new StartingData(pkg, theme, compatInfo, nonLocalizedLabel,
-                    labelRes, icon, logo, windowFlags);
-            Message m = mH.obtainMessage(H.ADD_STARTING, wtoken);
-            // Note: we really want to do sendMessageAtFrontOfQueue() because we
-            // want to process the message ASAP, before any other queued
-            // messages.
-            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Enqueueing ADD_STARTING");
-            mH.sendMessageAtFrontOfQueue(m);
-        }
-    }
-
-    @Override
-    public void setAppWillBeHidden(IBinder token) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppWillBeHidden()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        AppWindowToken wtoken;
-
-        synchronized(mWindowMap) {
-            wtoken = findAppWindowToken(token);
-            if (wtoken == null) {
-                Slog.w(TAG, "Attempted to set will be hidden of non-existing app token: " + token);
-                return;
-            }
-            wtoken.willBeHidden = true;
-        }
-    }
-
-    public void setAppFullscreen(IBinder token, boolean toOpaque) {
-        AppWindowToken atoken = findAppWindowToken(token);
-        if (atoken != null) {
-            atoken.appFullscreen = toOpaque;
-            requestTraversal();
-        }
-    }
-
-    boolean setTokenVisibilityLocked(AppWindowToken wtoken, WindowManager.LayoutParams lp,
-            boolean visible, int transit, boolean performLayout) {
-        boolean delayed = false;
-
-        if (wtoken.clientHidden == visible) {
-            wtoken.clientHidden = !visible;
-            wtoken.sendAppVisibilityToClients();
-        }
-
-        wtoken.willBeHidden = false;
-        if (wtoken.hidden == visible) {
-            boolean changed = false;
-            if (DEBUG_APP_TRANSITIONS) Slog.v(
-                TAG, "Changing app " + wtoken + " hidden=" + wtoken.hidden
-                + " performLayout=" + performLayout);
-
-            boolean runningAppAnimation = false;
-
-            if (transit != AppTransition.TRANSIT_UNSET) {
-                if (wtoken.mAppAnimator.animation == AppWindowAnimator.sDummyAnimation) {
-                    wtoken.mAppAnimator.animation = null;
-                }
-                if (applyAnimationLocked(wtoken, lp, transit, visible)) {
-                    delayed = runningAppAnimation = true;
-                }
-                WindowState window = wtoken.findMainWindow();
-                //TODO (multidisplay): Magnification is supported only for the default display.
-                if (window != null && mDisplayMagnifier != null
-                        && window.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                    mDisplayMagnifier.onAppWindowTransitionLocked(window, transit);
-                }
-                changed = true;
-            }
-
-            final int N = wtoken.allAppWindows.size();
-            for (int i=0; i<N; i++) {
-                WindowState win = wtoken.allAppWindows.get(i);
-                if (win == wtoken.startingWindow) {
-                    continue;
-                }
-
-                //Slog.i(TAG, "Window " + win + ": vis=" + win.isVisible());
-                //win.dump("  ");
-                if (visible) {
-                    if (!win.isVisibleNow()) {
-                        if (!runningAppAnimation) {
-                            win.mWinAnimator.applyAnimationLocked(
-                                    WindowManagerPolicy.TRANSIT_ENTER, true);
-                            //TODO (multidisplay): Magnification is supported only for the default
-                            if (mDisplayMagnifier != null
-                                    && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                                mDisplayMagnifier.onWindowTransitionLocked(win,
-                                        WindowManagerPolicy.TRANSIT_ENTER);
-                            }
-                        }
-                        changed = true;
-                        win.mDisplayContent.layoutNeeded = true;
-                    }
-                } else if (win.isVisibleNow()) {
-                    if (!runningAppAnimation) {
-                        win.mWinAnimator.applyAnimationLocked(
-                                WindowManagerPolicy.TRANSIT_EXIT, false);
-                        //TODO (multidisplay): Magnification is supported only for the default
-                        if (mDisplayMagnifier != null
-                                && win.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                            mDisplayMagnifier.onWindowTransitionLocked(win,
-                                    WindowManagerPolicy.TRANSIT_EXIT);
-                        }
-                    }
-                    changed = true;
-                    win.mDisplayContent.layoutNeeded = true;
-                }
-            }
-
-            wtoken.hidden = wtoken.hiddenRequested = !visible;
-            if (!visible) {
-                unsetAppFreezingScreenLocked(wtoken, true, true);
-            } else {
-                // If we are being set visible, and the starting window is
-                // not yet displayed, then make sure it doesn't get displayed.
-                WindowState swin = wtoken.startingWindow;
-                if (swin != null && !swin.isDrawnLw()) {
-                    swin.mPolicyVisibility = false;
-                    swin.mPolicyVisibilityAfterAnim = false;
-                 }
-            }
-
-            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "setTokenVisibilityLocked: " + wtoken
-                      + ": hidden=" + wtoken.hidden + " hiddenRequested="
-                      + wtoken.hiddenRequested);
-
-            if (changed) {
-                mInputMonitor.setUpdateInputWindowsNeededLw();
-                if (performLayout) {
-                    updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
-                            false /*updateInputWindows*/);
-                    performLayoutAndPlaceSurfacesLocked();
-                }
-                mInputMonitor.updateInputWindowsLw(false /*force*/);
-            }
-        }
-
-        if (wtoken.mAppAnimator.animation != null) {
-            delayed = true;
-        }
-
-        for (int i = wtoken.allAppWindows.size() - 1; i >= 0 && !delayed; i--) {
-            if (wtoken.allAppWindows.get(i).mWinAnimator.isWindowAnimating()) {
-                delayed = true;
-            }
-        }
-
-        return delayed;
-    }
-
-    @Override
-    public void setAppVisibility(IBinder token, boolean visible) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppVisibility()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        AppWindowToken wtoken;
-
-        synchronized(mWindowMap) {
-            wtoken = findAppWindowToken(token);
-            if (wtoken == null) {
-                Slog.w(TAG, "Attempted to set visibility of non-existing app token: " + token);
-                return;
-            }
-
-            if (DEBUG_APP_TRANSITIONS || DEBUG_ORIENTATION) {
-                RuntimeException e = null;
-                if (!HIDE_STACK_CRAWLS) {
-                    e = new RuntimeException();
-                    e.fillInStackTrace();
-                }
-                Slog.v(TAG, "setAppVisibility(" + token + ", visible=" + visible
-                        + "): " + mAppTransition
-                        + " hidden=" + wtoken.hidden
-                        + " hiddenRequested=" + wtoken.hiddenRequested, e);
-            }
-
-            // If we are preparing an app transition, then delay changing
-            // the visibility of this token until we execute that transition.
-            if (okToDisplay() && mAppTransition.isTransitionSet()) {
-                wtoken.hiddenRequested = !visible;
-
-                if (!wtoken.startingDisplayed) {
-                    if (DEBUG_APP_TRANSITIONS) Slog.v(
-                            TAG, "Setting dummy animation on: " + wtoken);
-                    wtoken.mAppAnimator.setDummyAnimation();
-                }
-                mOpeningApps.remove(wtoken);
-                mClosingApps.remove(wtoken);
-                wtoken.waitingToShow = wtoken.waitingToHide = false;
-                wtoken.inPendingTransaction = true;
-                if (visible) {
-                    mOpeningApps.add(wtoken);
-                    wtoken.startingMoved = false;
-
-                    // If the token is currently hidden (should be the
-                    // common case), then we need to set up to wait for
-                    // its windows to be ready.
-                    if (wtoken.hidden) {
-                        wtoken.allDrawn = false;
-                        wtoken.deferClearAllDrawn = false;
-                        wtoken.waitingToShow = true;
-
-                        if (wtoken.clientHidden) {
-                            // In the case where we are making an app visible
-                            // but holding off for a transition, we still need
-                            // to tell the client to make its windows visible so
-                            // they get drawn.  Otherwise, we will wait on
-                            // performing the transition until all windows have
-                            // been drawn, they never will be, and we are sad.
-                            wtoken.clientHidden = false;
-                            wtoken.sendAppVisibilityToClients();
-                        }
-                    }
-                } else {
-                    mClosingApps.add(wtoken);
-
-                    // If the token is currently visible (should be the
-                    // common case), then set up to wait for it to be hidden.
-                    if (!wtoken.hidden) {
-                        wtoken.waitingToHide = true;
-                    }
-                }
-                return;
-            }
-
-            final long origId = Binder.clearCallingIdentity();
-            setTokenVisibilityLocked(wtoken, null, visible, AppTransition.TRANSIT_UNSET,
-                    true);
-            wtoken.updateReportedVisibilityLocked();
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    void unsetAppFreezingScreenLocked(AppWindowToken wtoken,
-            boolean unfreezeSurfaceNow, boolean force) {
-        if (wtoken.mAppAnimator.freezingScreen) {
-            if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + wtoken
-                    + " force=" + force);
-            final int N = wtoken.allAppWindows.size();
-            boolean unfrozeWindows = false;
-            for (int i=0; i<N; i++) {
-                WindowState w = wtoken.allAppWindows.get(i);
-                if (w.mAppFreezing) {
-                    w.mAppFreezing = false;
-                    if (w.mHasSurface && !w.mOrientationChanging) {
-                        if (DEBUG_ORIENTATION) Slog.v(TAG, "set mOrientationChanging of " + w);
-                        w.mOrientationChanging = true;
-                        mInnerFields.mOrientationChangeComplete = false;
-                    }
-                    w.mLastFreezeDuration = 0;
-                    unfrozeWindows = true;
-                    w.mDisplayContent.layoutNeeded = true;
-                }
-            }
-            if (force || unfrozeWindows) {
-                if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken);
-                wtoken.mAppAnimator.freezingScreen = false;
-                wtoken.mAppAnimator.lastFreezeDuration = (int)(SystemClock.elapsedRealtime()
-                        - mDisplayFreezeTime);
-                mAppsFreezingScreen--;
-                mLastFinishedFreezeSource = wtoken;
-            }
-            if (unfreezeSurfaceNow) {
-                if (unfrozeWindows) {
-                    performLayoutAndPlaceSurfacesLocked();
-                }
-                stopFreezingDisplayLocked();
-            }
-        }
-    }
-
-    public void startAppFreezingScreenLocked(AppWindowToken wtoken,
-            int configChanges) {
-        if (DEBUG_ORIENTATION) {
-            RuntimeException e = null;
-            if (!HIDE_STACK_CRAWLS) {
-                e = new RuntimeException();
-                e.fillInStackTrace();
-            }
-            Slog.i(TAG, "Set freezing of " + wtoken.appToken
-                    + ": hidden=" + wtoken.hidden + " freezing="
-                    + wtoken.mAppAnimator.freezingScreen, e);
-        }
-        if (!wtoken.hiddenRequested) {
-            if (!wtoken.mAppAnimator.freezingScreen) {
-                wtoken.mAppAnimator.freezingScreen = true;
-                wtoken.mAppAnimator.lastFreezeDuration = 0;
-                mAppsFreezingScreen++;
-                if (mAppsFreezingScreen == 1) {
-                    startFreezingDisplayLocked(false, 0, 0);
-                    mH.removeMessages(H.APP_FREEZE_TIMEOUT);
-                    mH.sendEmptyMessageDelayed(H.APP_FREEZE_TIMEOUT, 5000);
-                }
-            }
-            final int N = wtoken.allAppWindows.size();
-            for (int i=0; i<N; i++) {
-                WindowState w = wtoken.allAppWindows.get(i);
-                w.mAppFreezing = true;
-            }
-        }
-    }
-
-    @Override
-    public void startAppFreezingScreen(IBinder token, int configChanges) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppFreezingScreen()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            if (configChanges == 0 && okToDisplay()) {
-                if (DEBUG_ORIENTATION) Slog.v(TAG, "Skipping set freeze of " + token);
-                return;
-            }
-
-            AppWindowToken wtoken = findAppWindowToken(token);
-            if (wtoken == null || wtoken.appToken == null) {
-                Slog.w(TAG, "Attempted to freeze screen with non-existing app token: " + wtoken);
-                return;
-            }
-            final long origId = Binder.clearCallingIdentity();
-            startAppFreezingScreenLocked(wtoken, configChanges);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public void stopAppFreezingScreen(IBinder token, boolean force) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setAppFreezingScreen()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized(mWindowMap) {
-            AppWindowToken wtoken = findAppWindowToken(token);
-            if (wtoken == null || wtoken.appToken == null) {
-                return;
-            }
-            final long origId = Binder.clearCallingIdentity();
-            if (DEBUG_ORIENTATION) Slog.v(TAG, "Clear freezing of " + token
-                    + ": hidden=" + wtoken.hidden + " freezing=" + wtoken.mAppAnimator.freezingScreen);
-            unsetAppFreezingScreenLocked(wtoken, true, force);
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    @Override
-    public void removeAppToken(IBinder token) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "removeAppToken()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        AppWindowToken wtoken = null;
-        AppWindowToken startingToken = null;
-        boolean delayed = false;
-
-        final long origId = Binder.clearCallingIdentity();
-        synchronized(mWindowMap) {
-            WindowToken basewtoken = mTokenMap.remove(token);
-            if (basewtoken != null && (wtoken=basewtoken.appWindowToken) != null) {
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Removing app token: " + wtoken);
-                delayed = setTokenVisibilityLocked(wtoken, null, false,
-                        AppTransition.TRANSIT_UNSET, true);
-                wtoken.inPendingTransaction = false;
-                mOpeningApps.remove(wtoken);
-                wtoken.waitingToShow = false;
-                if (mClosingApps.contains(wtoken)) {
-                    delayed = true;
-                } else if (mAppTransition.isTransitionSet()) {
-                    mClosingApps.add(wtoken);
-                    wtoken.waitingToHide = true;
-                    delayed = true;
-                }
-                if (DEBUG_APP_TRANSITIONS) Slog.v(
-                        TAG, "Removing app " + wtoken + " delayed=" + delayed
-                        + " animation=" + wtoken.mAppAnimator.animation
-                        + " animating=" + wtoken.mAppAnimator.animating);
-                final Task task = mTaskIdToTask.get(wtoken.groupId);
-                DisplayContent displayContent = task.getDisplayContent();
-                if (delayed) {
-                    // set the token aside because it has an active animation to be finished
-                    if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
-                            "removeAppToken make exiting: " + wtoken);
-                    displayContent.mExitingAppTokens.add(wtoken);
-                } else {
-                    // Make sure there is no animation running on this token,
-                    // so any windows associated with it will be removed as
-                    // soon as their animations are complete
-                    wtoken.mAppAnimator.clearAnimation();
-                    wtoken.mAppAnimator.animating = false;
-                }
-                if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
-                        "removeAppToken: " + wtoken);
-
-                if (task.removeAppToken(wtoken)) {
-                    mTaskIdToTask.delete(wtoken.groupId);
-                }
-                wtoken.removed = true;
-                if (wtoken.startingData != null) {
-                    startingToken = wtoken;
-                }
-                unsetAppFreezingScreenLocked(wtoken, true, true);
-                if (mFocusedApp == wtoken) {
-                    if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "Removing focused app token:" + wtoken);
-                    mFocusedApp = null;
-                    updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
-                    mInputMonitor.setFocusedAppLw(null);
-                }
-            } else {
-                Slog.w(TAG, "Attempted to remove non-existing app token: " + token);
-            }
-
-            if (!delayed && wtoken != null) {
-                wtoken.updateReportedVisibilityLocked();
-            }
-        }
-        Binder.restoreCallingIdentity(origId);
-
-        // Will only remove if startingToken non null.
-        scheduleRemoveStartingWindow(startingToken);
-    }
-
-    void removeStartingWindowTimeout(AppWindowToken wtoken) {
-        if (wtoken != null) {
-            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, Debug.getCallers(1) +
-                    ": Remove starting window timeout " + wtoken + (wtoken != null ?
-                    " startingWindow=" + wtoken.startingWindow : ""));
-            mH.removeMessages(H.REMOVE_STARTING_TIMEOUT, wtoken);
-        }
-    }
-
-    void scheduleRemoveStartingWindow(AppWindowToken wtoken) {
-        if (wtoken != null && wtoken.startingWindow != null) {
-            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, Debug.getCallers(1) +
-                    ": Schedule remove starting " + wtoken + (wtoken != null ?
-                    " startingWindow=" + wtoken.startingWindow : ""));
-            removeStartingWindowTimeout(wtoken);
-            Message m = mH.obtainMessage(H.REMOVE_STARTING, wtoken);
-            mH.sendMessage(m);
-        }
-    }
-    private boolean tmpRemoveAppWindowsLocked(WindowToken token) {
-        final int NW = token.windows.size();
-        if (NW > 0) {
-            mWindowsChanged = true;
-        }
-        for (int i=0; i<NW; i++) {
-            WindowState win = token.windows.get(i);
-            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Tmp removing app window " + win);
-            win.getWindowList().remove(win);
-            int j = win.mChildWindows.size();
-            while (j > 0) {
-                j--;
-                WindowState cwin = win.mChildWindows.get(j);
-                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG,
-                        "Tmp removing child window " + cwin);
-                cwin.getWindowList().remove(cwin);
-            }
-        }
-        return NW > 0;
-    }
-
-    void dumpAppTokensLocked() {
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-            Slog.v(TAG, "  Display " + displayContent.getDisplayId());
-            final ArrayList<Task> tasks = displayContent.getTasks();
-            int i = displayContent.numTokens();
-            for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-                AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-                for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
-                    final AppWindowToken wtoken = tokens.get(tokenNdx);
-                    Slog.v(TAG, "  #" + --i + ": " + wtoken.token);
-                }
-            }
-        }
-    }
-
-    void dumpWindowsLocked() {
-        int i = 0;
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-            for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
-                Slog.v(TAG, "  #" + i++ + ": " + windows.get(winNdx));
-            }
-        }
-    }
-
-    private int findAppWindowInsertionPointLocked(AppWindowToken target) {
-        final int taskId = target.groupId;
-        Task targetTask = mTaskIdToTask.get(taskId);
-        if (targetTask == null) {
-            Slog.w(TAG, "findAppWindowInsertionPointLocked: no Task for " + target + " taskId="
-                    + taskId);
-            return 0;
-        }
-        DisplayContent displayContent = targetTask.getDisplayContent();
-        if (displayContent == null) {
-            Slog.w(TAG, "findAppWindowInsertionPointLocked: no DisplayContent for " + target);
-            return 0;
-        }
-        final WindowList windows = displayContent.getWindowList();
-        final int NW = windows.size();
-
-        boolean found = false;
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-            final Task task = tasks.get(taskNdx);
-            if (!found && task.taskId != taskId) {
-                continue;
-            }
-            AppTokenList tokens = task.mAppTokens;
-            for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
-                final AppWindowToken wtoken = tokens.get(tokenNdx);
-                if (!found && wtoken == target) {
-                    found = true;
-                }
-                if (found) {
-                    // Find the first app token below the new position that has
-                    // a window displayed.
-                    if (DEBUG_REORDER) Slog.v(TAG, "Looking for lower windows in " + wtoken.token);
-                    if (wtoken.sendingToBottom) {
-                        if (DEBUG_REORDER) Slog.v(TAG, "Skipping token -- currently sending to bottom");
-                        continue;
-                    }
-                    for (int i = wtoken.windows.size() - 1; i >= 0; --i) {
-                        WindowState win = wtoken.windows.get(i);
-                        for (int j = win.mChildWindows.size() - 1; j >= 0; --j) {
-                            WindowState cwin = win.mChildWindows.get(j);
-                            if (cwin.mSubLayer >= 0) {
-                                for (int pos = NW - 1; pos >= 0; pos--) {
-                                    if (windows.get(pos) == cwin) {
-                                        if (DEBUG_REORDER) Slog.v(TAG,
-                                                "Found child win @" + (pos + 1));
-                                        return pos + 1;
-                                    }
-                                }
-                            }
-                        }
-                        for (int pos = NW - 1; pos >= 0; pos--) {
-                            if (windows.get(pos) == win) {
-                                if (DEBUG_REORDER) Slog.v(TAG, "Found win @" + (pos + 1));
-                                return pos + 1;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        // Never put an app window underneath wallpaper.
-        for (int pos = NW - 1; pos >= 0; pos--) {
-            if (windows.get(pos).mIsWallpaper) {
-                if (DEBUG_REORDER) Slog.v(TAG, "Found wallpaper @" + pos);
-                return pos + 1;
-            }
-        }
-        return 0;
-    }
-
-    private final int reAddWindowLocked(int index, WindowState win) {
-        final WindowList windows = win.getWindowList();
-        final int NCW = win.mChildWindows.size();
-        boolean added = false;
-        for (int j=0; j<NCW; j++) {
-            WindowState cwin = win.mChildWindows.get(j);
-            if (!added && cwin.mSubLayer >= 0) {
-                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding child window at "
-                        + index + ": " + cwin);
-                win.mRebuilding = false;
-                windows.add(index, win);
-                index++;
-                added = true;
-            }
-            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
-                    + index + ": " + cwin);
-            cwin.mRebuilding = false;
-            windows.add(index, cwin);
-            index++;
-        }
-        if (!added) {
-            if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Re-adding window at "
-                    + index + ": " + win);
-            win.mRebuilding = false;
-            windows.add(index, win);
-            index++;
-        }
-        mWindowsChanged = true;
-        return index;
-    }
-
-    private final int reAddAppWindowsLocked(final DisplayContent displayContent, int index,
-                                            WindowToken token) {
-        final int NW = token.windows.size();
-        for (int i=0; i<NW; i++) {
-            final WindowState win = token.windows.get(i);
-            if (win.mDisplayContent == displayContent) {
-                index = reAddWindowLocked(index, win);
-            }
-        }
-        return index;
-    }
-
-    void moveStackWindowsLocked(DisplayContent displayContent) {
-        // First remove all of the windows from the list.
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        final int numTasks = tasks.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int numTokens = tokens.size();
-            for (int tokenNdx = numTokens - 1; tokenNdx >= 0; --tokenNdx) {
-                tmpRemoveAppWindowsLocked(tokens.get(tokenNdx));
-            }
-        }
-
-        // And now add them back at the correct place.
-        // Where to start adding?
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            int pos = findAppWindowInsertionPointLocked(tokens.get(0));
-            final int numTokens = tokens.size();
-            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
-                final AppWindowToken wtoken = tokens.get(tokenNdx);
-                if (wtoken != null) {
-                    final int newPos = reAddAppWindowsLocked(displayContent, pos, wtoken);
-                    if (newPos != pos) {
-                        displayContent.layoutNeeded = true;
-                    }
-                    pos = newPos;
-                }
-            }
-        }
-
-        if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
-                false /*updateInputWindows*/)) {
-            assignLayersLocked(displayContent.getWindowList());
-        }
-
-        mInputMonitor.setUpdateInputWindowsNeededLw();
-        performLayoutAndPlaceSurfacesLocked();
-        mInputMonitor.updateInputWindowsLw(false /*force*/);
-
-        //dump();
-    }
-
-    public void moveTaskToTop(int taskId) {
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                Task task = mTaskIdToTask.get(taskId);
-                if (task == null) {
-                    // Normal behavior, addAppToken will be called next and task will be created.
-                    return;
-                }
-                final TaskStack stack = task.mStack;
-                final DisplayContent displayContent = task.getDisplayContent();
-                final boolean isHomeStackTask = stack.isHomeStack();
-                if (isHomeStackTask != displayContent.homeOnTop()) {
-                    // First move the stack itself.
-                    displayContent.moveHomeStackBox(isHomeStackTask);
-                }
-                stack.moveTaskToTop(task);
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    public void moveTaskToBottom(int taskId) {
-        final long origId = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                Task task = mTaskIdToTask.get(taskId);
-                if (task == null) {
-                    Slog.e(TAG, "moveTaskToBottom: taskId=" + taskId
-                            + " not found in mTaskIdToTask");
-                    return;
-                }
-                final TaskStack stack = task.mStack;
-                stack.moveTaskToBottom(task);
-                moveStackWindowsLocked(stack.getDisplayContent());
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-    }
-
-    /**
-     * Create a new TaskStack and place it next to an existing stack.
-     * @param stackId The unique identifier of the new stack.
-     * @param relativeStackBoxId The existing stack that this stack goes before or after.
-     * @param position One of:
-     *      {@link StackBox#TASK_STACK_GOES_BEFORE}
-     *      {@link StackBox#TASK_STACK_GOES_AFTER}
-     *      {@link StackBox#TASK_STACK_GOES_ABOVE}
-     *      {@link StackBox#TASK_STACK_GOES_BELOW}
-     *      {@link StackBox#TASK_STACK_GOES_UNDER}
-     *      {@link StackBox#TASK_STACK_GOES_OVER}
-     * @param weight Relative weight for determining how big to make the new TaskStack.
-     */
-    public void createStack(int stackId, int relativeStackBoxId, int position, float weight) {
-        synchronized (mWindowMap) {
-            if (position <= StackBox.TASK_STACK_GOES_BELOW &&
-                    (weight < STACK_WEIGHT_MIN || weight > STACK_WEIGHT_MAX)) {
-                throw new IllegalArgumentException(
-                        "createStack: weight must be between " + STACK_WEIGHT_MIN + " and " +
-                        STACK_WEIGHT_MAX + ", weight=" + weight);
-            }
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-                TaskStack stack = displayContent.createStack(stackId, relativeStackBoxId, position,
-                        weight);
-                if (stack != null) {
-                    mStackIdToStack.put(stackId, stack);
-                    performLayoutAndPlaceSurfacesLocked();
-                    return;
-                }
-            }
-            Slog.e(TAG, "createStack: Unable to find relativeStackBoxId=" + relativeStackBoxId);
-        }
-    }
-
-    public int removeStack(int stackId) {
-        synchronized (mWindowMap) {
-            final TaskStack stack = mStackIdToStack.get(stackId);
-            if (stack != null) {
-                mStackIdToStack.delete(stackId);
-                int nextStackId = stack.remove();
-                stack.getDisplayContent().layoutNeeded = true;
-                requestTraversalLocked();
-                return nextStackId;
-            }
-            if (DEBUG_STACK) Slog.i(TAG, "removeStack: could not find stackId=" + stackId);
-        }
-        return HOME_STACK_ID;
-    }
-
-    public void removeTask(int taskId) {
-        synchronized (mWindowMap) {
-            Task task = mTaskIdToTask.get(taskId);
-            if (task == null) {
-                if (DEBUG_STACK) Slog.i(TAG, "removeTask: could not find taskId=" + taskId);
-                return;
-            }
-            final TaskStack stack = task.mStack;
-            EventLog.writeEvent(EventLogTags.WM_TASK_REMOVED, taskId, "removeTask");
-            stack.removeTask(task);
-            stack.getDisplayContent().layoutNeeded = true;
-        }
-    }
-
-    public void addTask(int taskId, int stackId, boolean toTop) {
-        synchronized (mWindowMap) {
-            Task task = mTaskIdToTask.get(taskId);
-            if (task == null) {
-                return;
-            }
-            TaskStack stack = mStackIdToStack.get(stackId);
-            stack.addTask(task, toTop);
-            final DisplayContent displayContent = stack.getDisplayContent();
-            displayContent.layoutNeeded = true;
-            performLayoutAndPlaceSurfacesLocked();
-        }
-    }
-
-    public void resizeStackBox(int stackBoxId, float weight) {
-        if (weight < STACK_WEIGHT_MIN || weight > STACK_WEIGHT_MAX) {
-            throw new IllegalArgumentException(
-                    "resizeStack: weight must be between " + STACK_WEIGHT_MIN + " and " +
-                    STACK_WEIGHT_MAX + ", weight=" + weight);
-        }
-        synchronized (mWindowMap) {
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                if (mDisplayContents.valueAt(displayNdx).resizeStack(stackBoxId, weight)) {
-                    performLayoutAndPlaceSurfacesLocked();
-                    return;
-                }
-            }
-        }
-        throw new IllegalArgumentException("resizeStack: stackBoxId " + stackBoxId
-                + " not found.");
-    }
-
-    public ArrayList<StackBoxInfo> getStackBoxInfos() {
-        synchronized(mWindowMap) {
-            return getDefaultDisplayContentLocked().getStackBoxInfos();
-        }
-    }
-
-    public Rect getStackBounds(int stackId) {
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            Rect bounds = mDisplayContents.valueAt(displayNdx).getStackBounds(stackId);
-            if (bounds != null) {
-                return bounds;
-            }
-        }
-        return null;
-    }
-
-    // -------------------------------------------------------------
-    // Misc IWindowSession methods
-    // -------------------------------------------------------------
-
-    @Override
-    public void startFreezingScreen(int exitAnim, int enterAnim) {
-        if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN,
-                "startFreezingScreen()")) {
-            throw new SecurityException("Requires FREEZE_SCREEN permission");
-        }
-
-        synchronized(mWindowMap) {
-            if (!mClientFreezingScreen) {
-                mClientFreezingScreen = true;
-                final long origId = Binder.clearCallingIdentity();
-                try {
-                    startFreezingDisplayLocked(false, exitAnim, enterAnim);
-                    mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT);
-                    mH.sendEmptyMessageDelayed(H.CLIENT_FREEZE_TIMEOUT, 5000);
-                } finally {
-                    Binder.restoreCallingIdentity(origId);
-                }
-            }
-        }
-    }
-
-    @Override
-    public void stopFreezingScreen() {
-        if (!checkCallingPermission(android.Manifest.permission.FREEZE_SCREEN,
-                "stopFreezingScreen()")) {
-            throw new SecurityException("Requires FREEZE_SCREEN permission");
-        }
-
-        synchronized(mWindowMap) {
-            if (mClientFreezingScreen) {
-                mClientFreezingScreen = false;
-                mLastFinishedFreezeSource = "client";
-                final long origId = Binder.clearCallingIdentity();
-                try {
-                    stopFreezingDisplayLocked();
-                } finally {
-                    Binder.restoreCallingIdentity(origId);
-                }
-            }
-        }
-    }
-
-    @Override
-    public void disableKeyguard(IBinder token, String tag) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
-            != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
-        }
-
-        mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage(
-                KeyguardDisableHandler.KEYGUARD_DISABLE, new Pair<IBinder, String>(token, tag)));
-    }
-
-    @Override
-    public void reenableKeyguard(IBinder token) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
-            != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
-        }
-
-        mKeyguardDisableHandler.sendMessage(mKeyguardDisableHandler.obtainMessage(
-                KeyguardDisableHandler.KEYGUARD_REENABLE, token));
-    }
-
-    /**
-     * @see android.app.KeyguardManager#exitKeyguardSecurely
-     */
-    @Override
-    public void exitKeyguardSecurely(final IOnKeyguardExitResult callback) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
-            != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
-        }
-        mPolicy.exitKeyguardSecurely(new WindowManagerPolicy.OnKeyguardExitResult() {
-            @Override
-            public void onKeyguardExitResult(boolean success) {
-                try {
-                    callback.onKeyguardExitResult(success);
-                } catch (RemoteException e) {
-                    // Client has died, we don't care.
-                }
-            }
-        });
-    }
-
-    @Override
-    public boolean inKeyguardRestrictedInputMode() {
-        return mPolicy.inKeyguardRestrictedKeyInputMode();
-    }
-
-    @Override
-    public boolean isKeyguardLocked() {
-        return mPolicy.isKeyguardLocked();
-    }
-
-    @Override
-    public boolean isKeyguardSecure() {
-        return mPolicy.isKeyguardSecure();
-    }
-
-    @Override
-    public void dismissKeyguard() {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DISABLE_KEYGUARD)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Requires DISABLE_KEYGUARD permission");
-        }
-        synchronized(mWindowMap) {
-            mPolicy.dismissKeyguardLw();
-        }
-    }
-
-    @Override
-    public void closeSystemDialogs(String reason) {
-        synchronized(mWindowMap) {
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-                final int numWindows = windows.size();
-                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                    final WindowState w = windows.get(winNdx);
-                    if (w.mHasSurface) {
-                        try {
-                            w.mClient.closeSystemDialogs(reason);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-    static float fixScale(float scale) {
-        if (scale < 0) scale = 0;
-        else if (scale > 20) scale = 20;
-        return Math.abs(scale);
-    }
-
-    @Override
-    public void setAnimationScale(int which, float scale) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
-                "setAnimationScale()")) {
-            throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
-        }
-
-        scale = fixScale(scale);
-        switch (which) {
-            case 0: mWindowAnimationScale = scale; break;
-            case 1: mTransitionAnimationScale = scale; break;
-            case 2: mAnimatorDurationScale = scale; break;
-        }
-
-        // Persist setting
-        mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE);
-    }
-
-    @Override
-    public void setAnimationScales(float[] scales) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_ANIMATION_SCALE,
-                "setAnimationScale()")) {
-            throw new SecurityException("Requires SET_ANIMATION_SCALE permission");
-        }
-
-        if (scales != null) {
-            if (scales.length >= 1) {
-                mWindowAnimationScale = fixScale(scales[0]);
-            }
-            if (scales.length >= 2) {
-                mTransitionAnimationScale = fixScale(scales[1]);
-            }
-            if (scales.length >= 3) {
-                setAnimatorDurationScale(fixScale(scales[2]));
-            }
-        }
-
-        // Persist setting
-        mH.sendEmptyMessage(H.PERSIST_ANIMATION_SCALE);
-    }
-
-    private void setAnimatorDurationScale(float scale) {
-        mAnimatorDurationScale = scale;
-        ValueAnimator.setDurationScale(scale);
-    }
-
-    @Override
-    public float getAnimationScale(int which) {
-        switch (which) {
-            case 0: return mWindowAnimationScale;
-            case 1: return mTransitionAnimationScale;
-            case 2: return mAnimatorDurationScale;
-        }
-        return 0;
-    }
-
-    @Override
-    public float[] getAnimationScales() {
-        return new float[] { mWindowAnimationScale, mTransitionAnimationScale,
-                mAnimatorDurationScale };
-    }
-
-    @Override
-    public void registerPointerEventListener(PointerEventListener listener) {
-        mPointerEventDispatcher.registerInputEventListener(listener);
-    }
-
-    @Override
-    public void unregisterPointerEventListener(PointerEventListener listener) {
-        mPointerEventDispatcher.unregisterInputEventListener(listener);
-    }
-
-    // Called by window manager policy. Not exposed externally.
-    @Override
-    public int getLidState() {
-        int sw = mInputManager.getSwitchState(-1, InputDevice.SOURCE_ANY,
-                InputManagerService.SW_LID);
-        if (sw > 0) {
-            // Switch state: AKEY_STATE_DOWN or AKEY_STATE_VIRTUAL.
-            return LID_CLOSED;
-        } else if (sw == 0) {
-            // Switch state: AKEY_STATE_UP.
-            return LID_OPEN;
-        } else {
-            // Switch state: AKEY_STATE_UNKNOWN.
-            return LID_ABSENT;
-        }
-    }
-
-    // Called by window manager policy.  Not exposed externally.
-    @Override
-    public void switchKeyboardLayout(int deviceId, int direction) {
-        mInputManager.switchKeyboardLayout(deviceId, direction);
-    }
-
-    // Called by window manager policy.  Not exposed externally.
-    @Override
-    public void shutdown(boolean confirm) {
-        ShutdownThread.shutdown(mContext, confirm);
-    }
-
-    // Called by window manager policy.  Not exposed externally.
-    @Override
-    public void rebootSafeMode(boolean confirm) {
-        ShutdownThread.rebootSafeMode(mContext, confirm);
-    }
-
-    @Override
-    public void setInputFilter(IInputFilter filter) {
-        if (!checkCallingPermission(android.Manifest.permission.FILTER_EVENTS, "setInputFilter()")) {
-            throw new SecurityException("Requires FILTER_EVENTS permission");
-        }
-        mInputManager.setInputFilter(filter);
-    }
-
-    @Override
-    public void setTouchExplorationEnabled(boolean enabled) {
-        mPolicy.setTouchExplorationEnabled(enabled);
-    }
-
-    public void setCurrentUser(final int newUserId) {
-        synchronized (mWindowMap) {
-            int oldUserId = mCurrentUserId;
-            mCurrentUserId = newUserId;
-            mAppTransition.setCurrentUser(newUserId);
-            mPolicy.setCurrentUserLw(newUserId);
-
-            // Hide windows that should not be seen by the new user.
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-                displayContent.switchUserStacks(oldUserId, newUserId);
-                rebuildAppWindowListLocked(displayContent);
-            }
-            performLayoutAndPlaceSurfacesLocked();
-        }
-    }
-
-    public void enableScreenAfterBoot() {
-        synchronized(mWindowMap) {
-            if (DEBUG_BOOT) {
-                RuntimeException here = new RuntimeException("here");
-                here.fillInStackTrace();
-                Slog.i(TAG, "enableScreenAfterBoot: mDisplayEnabled=" + mDisplayEnabled
-                        + " mForceDisplayEnabled=" + mForceDisplayEnabled
-                        + " mShowingBootMessages=" + mShowingBootMessages
-                        + " mSystemBooted=" + mSystemBooted, here);
-            }
-            if (mSystemBooted) {
-                return;
-            }
-            mSystemBooted = true;
-            hideBootMessagesLocked();
-            // If the screen still doesn't come up after 30 seconds, give
-            // up and turn it on.
-            mH.sendEmptyMessageDelayed(H.BOOT_TIMEOUT, 30*1000);
-        }
-
-        mPolicy.systemBooted();
-
-        performEnableScreen();
-    }
-
-    void enableScreenIfNeededLocked() {
-        if (DEBUG_BOOT) {
-            RuntimeException here = new RuntimeException("here");
-            here.fillInStackTrace();
-            Slog.i(TAG, "enableScreenIfNeededLocked: mDisplayEnabled=" + mDisplayEnabled
-                    + " mForceDisplayEnabled=" + mForceDisplayEnabled
-                    + " mShowingBootMessages=" + mShowingBootMessages
-                    + " mSystemBooted=" + mSystemBooted, here);
-        }
-        if (mDisplayEnabled) {
-            return;
-        }
-        if (!mSystemBooted && !mShowingBootMessages) {
-            return;
-        }
-        mH.sendEmptyMessage(H.ENABLE_SCREEN);
-    }
-
-    public void performBootTimeout() {
-        synchronized(mWindowMap) {
-            if (mDisplayEnabled || mHeadless) {
-                return;
-            }
-            Slog.w(TAG, "***** BOOT TIMEOUT: forcing display enabled");
-            mForceDisplayEnabled = true;
-        }
-        performEnableScreen();
-    }
-
-    public void performEnableScreen() {
-        synchronized(mWindowMap) {
-            if (DEBUG_BOOT) {
-                RuntimeException here = new RuntimeException("here");
-                here.fillInStackTrace();
-                Slog.i(TAG, "performEnableScreen: mDisplayEnabled=" + mDisplayEnabled
-                        + " mForceDisplayEnabled=" + mForceDisplayEnabled
-                        + " mShowingBootMessages=" + mShowingBootMessages
-                        + " mSystemBooted=" + mSystemBooted
-                        + " mOnlyCore=" + mOnlyCore, here);
-            }
-            if (mDisplayEnabled) {
-                return;
-            }
-            if (!mSystemBooted && !mShowingBootMessages) {
-                return;
-            }
-
-            if (!mForceDisplayEnabled) {
-                // Don't enable the screen until all existing windows
-                // have been drawn.
-                boolean haveBootMsg = false;
-                boolean haveApp = false;
-                // if the wallpaper service is disabled on the device, we're never going to have
-                // wallpaper, don't bother waiting for it
-                boolean haveWallpaper = false;
-                boolean wallpaperEnabled = mContext.getResources().getBoolean(
-                        com.android.internal.R.bool.config_enableWallpaperService)
-                        && !mOnlyCore;
-                boolean haveKeyguard = true;
-                // TODO(multidisplay): Expand to all displays?
-                final WindowList windows = getDefaultWindowListLocked();
-                final int N = windows.size();
-                for (int i=0; i<N; i++) {
-                    WindowState w = windows.get(i);
-                    if (w.mAttrs.type == TYPE_KEYGUARD) {
-                        // Only if there is a keyguard attached to the window manager
-                        // will we consider ourselves as having a keyguard.  If it
-                        // isn't attached, we don't know if it wants to be shown or
-                        // hidden.  If it is attached, we will say we have a keyguard
-                        // if the window doesn't want to be visible, because in that
-                        // case it explicitly doesn't want to be shown so we should
-                        // not delay turning the screen on for it.
-                        boolean vis = w.mViewVisibility == View.VISIBLE
-                                && w.mPolicyVisibility;
-                        haveKeyguard = !vis;
-                    }
-                    if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
-                        return;
-                    }
-                    if (w.isDrawnLw()) {
-                        if (w.mAttrs.type == TYPE_BOOT_PROGRESS) {
-                            haveBootMsg = true;
-                        } else if (w.mAttrs.type == TYPE_APPLICATION) {
-                            haveApp = true;
-                        } else if (w.mAttrs.type == TYPE_WALLPAPER) {
-                            haveWallpaper = true;
-                        } else if (w.mAttrs.type == TYPE_KEYGUARD) {
-                            haveKeyguard = true;
-                        }
-                    }
-                }
-
-                if (DEBUG_SCREEN_ON || DEBUG_BOOT) {
-                    Slog.i(TAG, "******** booted=" + mSystemBooted + " msg=" + mShowingBootMessages
-                            + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
-                            + " haveWall=" + haveWallpaper + " wallEnabled=" + wallpaperEnabled
-                            + " haveKeyguard=" + haveKeyguard);
-                }
-
-                // If we are turning on the screen to show the boot message,
-                // don't do it until the boot message is actually displayed.
-                if (!mSystemBooted && !haveBootMsg) {
-                    return;
-                }
-
-                // If we are turning on the screen after the boot is completed
-                // normally, don't do so until we have the application and
-                // wallpaper.
-                if (mSystemBooted && ((!haveApp && !haveKeyguard) ||
-                        (wallpaperEnabled && !haveWallpaper))) {
-                    return;
-                }
-            }
-
-            mDisplayEnabled = true;
-            if (DEBUG_SCREEN_ON || DEBUG_BOOT) Slog.i(TAG, "******************** ENABLING SCREEN!");
-            if (false) {
-                StringWriter sw = new StringWriter();
-                PrintWriter pw = new FastPrintWriter(sw, false, 1024);
-                this.dump(null, pw, null);
-                pw.flush();
-                Slog.i(TAG, sw.toString());
-            }
-            try {
-                IBinder surfaceFlinger = ServiceManager.getService("SurfaceFlinger");
-                if (surfaceFlinger != null) {
-                    //Slog.i(TAG, "******* TELLING SURFACE FLINGER WE ARE BOOTED!");
-                    Parcel data = Parcel.obtain();
-                    data.writeInterfaceToken("android.ui.ISurfaceComposer");
-                    surfaceFlinger.transact(IBinder.FIRST_CALL_TRANSACTION, // BOOT_FINISHED
-                                            data, null, 0);
-                    data.recycle();
-                }
-            } catch (RemoteException ex) {
-                Slog.e(TAG, "Boot completed: SurfaceFlinger is dead!");
-            }
-
-            // Enable input dispatch.
-            mInputMonitor.setEventDispatchingLw(mEventDispatchingEnabled);
-        }
-
-        mPolicy.enableScreenAfterBoot();
-
-        // Make sure the last requested orientation has been applied.
-        updateRotationUnchecked(false, false);
-    }
-
-    public void showBootMessage(final CharSequence msg, final boolean always) {
-        boolean first = false;
-        synchronized(mWindowMap) {
-            if (DEBUG_BOOT) {
-                RuntimeException here = new RuntimeException("here");
-                here.fillInStackTrace();
-                Slog.i(TAG, "showBootMessage: msg=" + msg + " always=" + always
-                        + " mAllowBootMessages=" + mAllowBootMessages
-                        + " mShowingBootMessages=" + mShowingBootMessages
-                        + " mSystemBooted=" + mSystemBooted, here);
-            }
-            if (!mAllowBootMessages) {
-                return;
-            }
-            if (!mShowingBootMessages) {
-                if (!always) {
-                    return;
-                }
-                first = true;
-            }
-            if (mSystemBooted) {
-                return;
-            }
-            mShowingBootMessages = true;
-            mPolicy.showBootMessage(msg, always);
-        }
-        if (first) {
-            performEnableScreen();
-        }
-    }
-
-    public void hideBootMessagesLocked() {
-        if (DEBUG_BOOT) {
-            RuntimeException here = new RuntimeException("here");
-            here.fillInStackTrace();
-            Slog.i(TAG, "hideBootMessagesLocked: mDisplayEnabled=" + mDisplayEnabled
-                    + " mForceDisplayEnabled=" + mForceDisplayEnabled
-                    + " mShowingBootMessages=" + mShowingBootMessages
-                    + " mSystemBooted=" + mSystemBooted, here);
-        }
-        if (mShowingBootMessages) {
-            mShowingBootMessages = false;
-            mPolicy.hideBootMessages();
-        }
-    }
-
-    @Override
-    public void setInTouchMode(boolean mode) {
-        synchronized(mWindowMap) {
-            mInTouchMode = mode;
-        }
-    }
-
-    // TODO: more accounting of which pid(s) turned it on, keep count,
-    // only allow disables from pids which have count on, etc.
-    @Override
-    public void showStrictModeViolation(boolean on) {
-        if (mHeadless) return;
-        int pid = Binder.getCallingPid();
-        mH.sendMessage(mH.obtainMessage(H.SHOW_STRICT_MODE_VIOLATION, on ? 1 : 0, pid));
-    }
-
-    private void showStrictModeViolation(int arg, int pid) {
-        final boolean on = arg != 0;
-        synchronized(mWindowMap) {
-            // Ignoring requests to enable the red border from clients
-            // which aren't on screen.  (e.g. Broadcast Receivers in
-            // the background..)
-            if (on) {
-                boolean isVisible = false;
-                final int numDisplays = mDisplayContents.size();
-                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                    final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-                    final int numWindows = windows.size();
-                    for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                        final WindowState ws = windows.get(winNdx);
-                        if (ws.mSession.mPid == pid && ws.isVisibleLw()) {
-                            isVisible = true;
-                            break;
-                        }
-                    }
-                }
-                if (!isVisible) {
-                    return;
-                }
-            }
-
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                    ">>> OPEN TRANSACTION showStrictModeViolation");
-            SurfaceControl.openTransaction();
-            try {
-                // TODO(multi-display): support multiple displays
-                if (mStrictModeFlash == null) {
-                    mStrictModeFlash = new StrictModeFlash(
-                            getDefaultDisplayContentLocked().getDisplay(), mFxSession);
-                }
-                mStrictModeFlash.setVisibility(on);
-            } finally {
-                SurfaceControl.closeTransaction();
-                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                        "<<< CLOSE TRANSACTION showStrictModeViolation");
-            }
-        }
-    }
-
-    @Override
-    public void setStrictModeVisualIndicatorPreference(String value) {
-        SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
-    }
-
-    /**
-     * Takes a snapshot of the screen.  In landscape mode this grabs the whole screen.
-     * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
-     * of the target image.
-     *
-     * @param displayId the Display to take a screenshot of.
-     * @param width the width of the target bitmap
-     * @param height the height of the target bitmap
-     * @param force565 if true the returned bitmap will be RGB_565, otherwise it
-     *                 will be the same config as the surface
-     */
-    @Override
-    public Bitmap screenshotApplications(IBinder appToken, int displayId, int width,
-            int height, boolean force565) {
-        if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER,
-                "screenshotApplications()")) {
-            throw new SecurityException("Requires READ_FRAME_BUFFER permission");
-        }
-
-        Bitmap rawss = null;
-
-        int maxLayer = 0;
-        final Rect frame = new Rect();
-
-        float scale = 0;
-        int dw, dh;
-        int rot = Surface.ROTATION_0;
-
-        boolean screenshotReady;
-        int minLayer;
-        if (appToken == null) {
-            screenshotReady = true;
-            minLayer = 0;
-        } else {
-            screenshotReady = false;
-            minLayer = Integer.MAX_VALUE;
-        }
-
-        int retryCount = 0;
-        WindowState appWin = null;
-
-        do {
-            if (retryCount++ > 0) {
-                try {
-                    Thread.sleep(100);
-                } catch (InterruptedException e) {
-                }
-            }
-            synchronized(mWindowMap) {
-                final DisplayContent displayContent = getDisplayContentLocked(displayId);
-                if (displayContent == null) {
-                    return null;
-                }
-                final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-                dw = displayInfo.logicalWidth;
-                dh = displayInfo.logicalHeight;
-
-                int aboveAppLayer = mPolicy.windowTypeToLayerLw(TYPE_APPLICATION)
-                        * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
-                aboveAppLayer += TYPE_LAYER_MULTIPLIER;
-
-                boolean isImeTarget = mInputMethodTarget != null
-                        && mInputMethodTarget.mAppToken != null
-                        && mInputMethodTarget.mAppToken.appToken != null
-                        && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
-
-                // Figure out the part of the screen that is actually the app.
-                boolean including = false;
-                appWin = null;
-                final WindowList windows = displayContent.getWindowList();
-                final Rect stackBounds = new Rect();
-                for (int i = windows.size() - 1; i >= 0; i--) {
-                    WindowState ws = windows.get(i);
-                    if (!ws.mHasSurface) {
-                        continue;
-                    }
-                    if (ws.mLayer >= aboveAppLayer) {
-                        continue;
-                    }
-                    // When we will skip windows: when we are not including
-                    // ones behind a window we didn't skip, and we are actually
-                    // taking a screenshot of a specific app.
-                    if (!including && appToken != null) {
-                        // Also, we can possibly skip this window if it is not
-                        // an IME target or the application for the screenshot
-                        // is not the current IME target.
-                        if (!ws.mIsImWindow || !isImeTarget) {
-                            // And finally, this window is of no interest if it
-                            // is not associated with the screenshot app.
-                            if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
-                                continue;
-                            }
-                            appWin = ws;
-                            stackBounds.set(ws.getStackBounds());
-                        }
-                    }
-
-                    // We keep on including windows until we go past a full-screen
-                    // window.
-                    boolean fullscreen = ws.isFullscreen(dw, dh);
-                    including = !ws.mIsImWindow && !fullscreen;
-
-                    final WindowStateAnimator winAnim = ws.mWinAnimator;
-                    if (maxLayer < winAnim.mSurfaceLayer) {
-                        maxLayer = winAnim.mSurfaceLayer;
-                    }
-                    if (minLayer > winAnim.mSurfaceLayer) {
-                        minLayer = winAnim.mSurfaceLayer;
-                    }
-
-                    // Don't include wallpaper in bounds calculation
-                    if (!ws.mIsWallpaper) {
-                        final Rect wf = ws.mFrame;
-                        final Rect cr = ws.mContentInsets;
-                        int left = wf.left + cr.left;
-                        int top = wf.top + cr.top;
-                        int right = wf.right - cr.right;
-                        int bottom = wf.bottom - cr.bottom;
-                        frame.union(left, top, right, bottom);
-                        frame.intersect(stackBounds);
-                    }
-
-                    if (ws.mAppToken != null && ws.mAppToken.token == appToken &&
-                            ws.isDisplayedLw()) {
-                        screenshotReady = true;
-                    }
-
-                    if (fullscreen) {
-                        // No point in continuing down through windows.
-                        break;
-                    }
-                }
-
-                if (appToken != null && appWin == null) {
-                    // Can't find a window to snapshot.
-                    if (DEBUG_SCREENSHOT) Slog.i(TAG,
-                            "Screenshot: Couldn't find a surface matching " + appToken);
-                    return null;
-                }
-                if (!screenshotReady) {
-                    // Delay and hope that window gets drawn.
-                    if (DEBUG_SCREENSHOT) Slog.i(TAG, "Screenshot: No image ready for " + appToken
-                            + ", " + appWin + " drawState=" + appWin.mWinAnimator.mDrawState);
-                    continue;
-                }
-
-                // Constrain frame to the screen size.
-                frame.intersect(0, 0, dw, dh);
-
-                if (frame.isEmpty() || maxLayer == 0) {
-                    if (DEBUG_SCREENSHOT) Slog.i(TAG, "Screenshot of " + appToken
-                            + ": returning null frame=" + frame.toShortString() + " maxLayer="
-                            + maxLayer);
-                    return null;
-                }
-
-                // The screenshot API does not apply the current screen rotation.
-                rot = getDefaultDisplayContentLocked().getDisplay().getRotation();
-                int fw = frame.width();
-                int fh = frame.height();
-
-                // Constrain thumbnail to smaller of screen width or height. Assumes aspect
-                // of thumbnail is the same as the screen (in landscape) or square.
-                scale = Math.max(width / (float) fw, height / (float) fh);
-                /*
-                float targetWidthScale = width / (float) fw;
-                float targetHeightScale = height / (float) fh;
-                if (fw <= fh) {
-                    scale = targetWidthScale;
-                    // If aspect of thumbnail is the same as the screen (in landscape),
-                    // select the slightly larger value so we fill the entire bitmap
-                    if (targetHeightScale > scale && (int) (targetHeightScale * fw) == width) {
-                        scale = targetHeightScale;
-                    }
-                } else {
-                    scale = targetHeightScale;
-                    // If aspect of thumbnail is the same as the screen (in landscape),
-                    // select the slightly larger value so we fill the entire bitmap
-                    if (targetWidthScale > scale && (int) (targetWidthScale * fh) == height) {
-                        scale = targetWidthScale;
-                    }
-                }
-                */
-
-                // The screen shot will contain the entire screen.
-                dw = (int)(dw*scale);
-                dh = (int)(dh*scale);
-                if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
-                    int tmp = dw;
-                    dw = dh;
-                    dh = tmp;
-                    rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
-                }
-                if (DEBUG_SCREENSHOT) {
-                    Slog.i(TAG, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to "
-                            + maxLayer + " appToken=" + appToken);
-                    for (int i = 0; i < windows.size(); i++) {
-                        WindowState win = windows.get(i);
-                        Slog.i(TAG, win + ": " + win.mLayer
-                                + " animLayer=" + win.mWinAnimator.mAnimLayer
-                                + " surfaceLayer=" + win.mWinAnimator.mSurfaceLayer);
-                    }
-                }
-                rawss = SurfaceControl.screenshot(dw, dh, minLayer, maxLayer);
-            }
-        } while (!screenshotReady && retryCount <= MAX_SCREENSHOT_RETRIES);
-        if (retryCount > MAX_SCREENSHOT_RETRIES)  Slog.i(TAG, "Screenshot max retries " +
-                retryCount + " of " + appToken + " appWin=" + (appWin == null ?
-                        "null" : (appWin + " drawState=" + appWin.mWinAnimator.mDrawState)));
-
-        if (rawss == null) {
-            Slog.w(TAG, "Screenshot failure taking screenshot for (" + dw + "x" + dh
-                    + ") to layer " + maxLayer);
-            return null;
-        }
-
-        Bitmap bm = Bitmap.createBitmap(width, height, force565 ? Config.RGB_565 : rawss.getConfig());
-        frame.scale(scale);
-        Matrix matrix = new Matrix();
-        ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
-        // TODO: Test for RTL vs. LTR and use frame.right-width instead of -frame.left
-        matrix.postTranslate(-FloatMath.ceil(frame.left), -FloatMath.ceil(frame.top));
-        Canvas canvas = new Canvas(bm);
-        canvas.drawColor(0xFF000000);
-        canvas.drawBitmap(rawss, matrix, null);
-        canvas.setBitmap(null);
-
-        if (DEBUG_SCREENSHOT) {
-            // TEST IF IT's ALL BLACK
-            int[] buffer = new int[bm.getWidth() * bm.getHeight()];
-            bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
-            boolean allBlack = true;
-            final int firstColor = buffer[0];
-            for (int i = 0; i < buffer.length; i++) {
-                if (buffer[i] != firstColor) {
-                    allBlack = false;
-                    break;
-                }
-            }
-            if (allBlack) {
-                Slog.i(TAG, "Screenshot " + appWin + " was monochrome(" +
-                        Integer.toHexString(firstColor) + ")! mSurfaceLayer=" +
-                        (appWin != null ? appWin.mWinAnimator.mSurfaceLayer : "null") +
-                        " minLayer=" + minLayer + " maxLayer=" + maxLayer);
-            }
-        }
-
-        rawss.recycle();
-        return bm;
-    }
-
-    /**
-     * Freeze rotation changes.  (Enable "rotation lock".)
-     * Persists across reboots.
-     * @param rotation The desired rotation to freeze to, or -1 to use the
-     * current rotation.
-     */
-    @Override
-    public void freezeRotation(int rotation) {
-        if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
-                "freezeRotation()")) {
-            throw new SecurityException("Requires SET_ORIENTATION permission");
-        }
-        if (rotation < -1 || rotation > Surface.ROTATION_270) {
-            throw new IllegalArgumentException("Rotation argument must be -1 or a valid "
-                    + "rotation constant.");
-        }
-
-        if (DEBUG_ORIENTATION) Slog.v(TAG, "freezeRotation: mRotation=" + mRotation);
-
-        long origId = Binder.clearCallingIdentity();
-        try {
-            mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED,
-                    rotation == -1 ? mRotation : rotation);
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-
-        updateRotationUnchecked(false, false);
-    }
-
-    /**
-     * Thaw rotation changes.  (Disable "rotation lock".)
-     * Persists across reboots.
-     */
-    @Override
-    public void thawRotation() {
-        if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
-                "thawRotation()")) {
-            throw new SecurityException("Requires SET_ORIENTATION permission");
-        }
-
-        if (DEBUG_ORIENTATION) Slog.v(TAG, "thawRotation: mRotation=" + mRotation);
-
-        long origId = Binder.clearCallingIdentity();
-        try {
-            mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_FREE,
-                    777); // rot not used
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-
-        updateRotationUnchecked(false, false);
-    }
-
-    /**
-     * Recalculate the current rotation.
-     *
-     * Called by the window manager policy whenever the state of the system changes
-     * such that the current rotation might need to be updated, such as when the
-     * device is docked or rotated into a new posture.
-     */
-    @Override
-    public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
-        updateRotationUnchecked(alwaysSendConfiguration, forceRelayout);
-    }
-
-    /**
-     * Temporarily pauses rotation changes until resumed.
-     *
-     * This can be used to prevent rotation changes from occurring while the user is
-     * performing certain operations, such as drag and drop.
-     *
-     * This call nests and must be matched by an equal number of calls to
-     * {@link #resumeRotationLocked}.
-     */
-    void pauseRotationLocked() {
-        mDeferredRotationPauseCount += 1;
-    }
-
-    /**
-     * Resumes normal rotation changes after being paused.
-     */
-    void resumeRotationLocked() {
-        if (mDeferredRotationPauseCount > 0) {
-            mDeferredRotationPauseCount -= 1;
-            if (mDeferredRotationPauseCount == 0) {
-                boolean changed = updateRotationUncheckedLocked(false);
-                if (changed) {
-                    mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-                }
-            }
-        }
-    }
-
-    public void updateRotationUnchecked(boolean alwaysSendConfiguration, boolean forceRelayout) {
-        if(DEBUG_ORIENTATION) Slog.v(TAG, "updateRotationUnchecked("
-                   + "alwaysSendConfiguration=" + alwaysSendConfiguration + ")");
-
-        long origId = Binder.clearCallingIdentity();
-        boolean changed;
-        synchronized(mWindowMap) {
-            changed = updateRotationUncheckedLocked(false);
-            if (!changed || forceRelayout) {
-                getDefaultDisplayContentLocked().layoutNeeded = true;
-                performLayoutAndPlaceSurfacesLocked();
-            }
-        }
-
-        if (changed || alwaysSendConfiguration) {
-            sendNewConfiguration();
-        }
-
-        Binder.restoreCallingIdentity(origId);
-    }
-
-    // TODO(multidisplay): Rotate any display?
-    /**
-     * Updates the current rotation.
-     *
-     * Returns true if the rotation has been changed.  In this case YOU
-     * MUST CALL sendNewConfiguration() TO UNFREEZE THE SCREEN.
-     */
-    public boolean updateRotationUncheckedLocked(boolean inTransaction) {
-        if (mDeferredRotationPauseCount > 0) {
-            // Rotation updates have been paused temporarily.  Defer the update until
-            // updates have been resumed.
-            if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, rotation is paused.");
-            return false;
-        }
-
-        ScreenRotationAnimation screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
-        if (screenRotationAnimation != null && screenRotationAnimation.isAnimating()) {
-            // Rotation updates cannot be performed while the previous rotation change
-            // animation is still in progress.  Skip this update.  We will try updating
-            // again after the animation is finished and the display is unfrozen.
-            if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, animation in progress.");
-            return false;
-        }
-
-        if (!mDisplayEnabled) {
-            // No point choosing a rotation if the display is not enabled.
-            if (DEBUG_ORIENTATION) Slog.v(TAG, "Deferring rotation, display is not enabled.");
-            return false;
-        }
-
-        // TODO: Implement forced rotation changes.
-        //       Set mAltOrientation to indicate that the application is receiving
-        //       an orientation that has different metrics than it expected.
-        //       eg. Portrait instead of Landscape.
-
-        int rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation);
-        boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw(
-                mForcedAppOrientation, rotation);
-
-        if (DEBUG_ORIENTATION) {
-            Slog.v(TAG, "Application requested orientation "
-                    + mForcedAppOrientation + ", got rotation " + rotation
-                    + " which has " + (altOrientation ? "incompatible" : "compatible")
-                    + " metrics");
-        }
-
-        if (mRotation == rotation && mAltOrientation == altOrientation) {
-            // No change.
-            return false;
-        }
-
-        if (DEBUG_ORIENTATION) {
-            Slog.v(TAG,
-                "Rotation changed to " + rotation + (altOrientation ? " (alt)" : "")
-                + " from " + mRotation + (mAltOrientation ? " (alt)" : "")
-                + ", forceApp=" + mForcedAppOrientation);
-        }
-
-        mRotation = rotation;
-        mAltOrientation = altOrientation;
-        mPolicy.setRotationLw(mRotation);
-
-        mWindowsFreezingScreen = true;
-        mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
-        mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT, WINDOW_FREEZE_TIMEOUT_DURATION);
-        mWaitingForConfig = true;
-        final DisplayContent displayContent = getDefaultDisplayContentLocked();
-        displayContent.layoutNeeded = true;
-        final int[] anim = new int[2];
-        if (displayContent.isDimming()) {
-            anim[0] = anim[1] = 0;
-        } else {
-            mPolicy.selectRotationAnimationLw(anim);
-        }
-        startFreezingDisplayLocked(inTransaction, anim[0], anim[1]);
-        // startFreezingDisplayLocked can reset the ScreenRotationAnimation.
-        screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(Display.DEFAULT_DISPLAY);
-
-        // We need to update our screen size information to match the new
-        // rotation.  Note that this is redundant with the later call to
-        // sendNewConfiguration() that must be called after this function
-        // returns...  however we need to do the screen size part of that
-        // before then so we have the correct size to use when initializing
-        // the rotation animation for the new rotation.
-        computeScreenConfigurationLocked(null);
-
-        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        if (!inTransaction) {
-            if (SHOW_TRANSACTIONS) {
-                Slog.i(TAG, ">>> OPEN TRANSACTION setRotationUnchecked");
-            }
-            SurfaceControl.openTransaction();
-        }
-        try {
-            // NOTE: We disable the rotation in the emulator because
-            //       it doesn't support hardware OpenGL emulation yet.
-            if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
-                    && screenRotationAnimation.hasScreenshot()) {
-                if (screenRotationAnimation.setRotationInTransaction(
-                        rotation, mFxSession,
-                        MAX_ANIMATION_DURATION, mTransitionAnimationScale,
-                        displayInfo.logicalWidth, displayInfo.logicalHeight)) {
-                    scheduleAnimationLocked();
-                }
-            }
-
-            mDisplayManagerService.performTraversalInTransactionFromWindowManager();
-        } finally {
-            if (!inTransaction) {
-                SurfaceControl.closeTransaction();
-                if (SHOW_LIGHT_TRANSACTIONS) {
-                    Slog.i(TAG, "<<< CLOSE TRANSACTION setRotationUnchecked");
-                }
-            }
-        }
-
-        final WindowList windows = displayContent.getWindowList();
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            WindowState w = windows.get(i);
-            if (w.mHasSurface) {
-                if (DEBUG_ORIENTATION) Slog.v(TAG, "Set mOrientationChanging of " + w);
-                w.mOrientationChanging = true;
-                mInnerFields.mOrientationChangeComplete = false;
-            }
-            w.mLastFreezeDuration = 0;
-        }
-
-        for (int i=mRotationWatchers.size()-1; i>=0; i--) {
-            try {
-                mRotationWatchers.get(i).onRotationChanged(rotation);
-            } catch (RemoteException e) {
-            }
-        }
-
-        //TODO (multidisplay): Magnification is supported only for the default display.
-        if (mDisplayMagnifier != null
-                && displayContent.getDisplayId() == Display.DEFAULT_DISPLAY) {
-            mDisplayMagnifier.onRotationChangedLocked(getDefaultDisplayContentLocked(), rotation);
-        }
-
-        return true;
-    }
-
-    @Override
-    public int getRotation() {
-        return mRotation;
-    }
-
-    @Override
-    public boolean isRotationFrozen() {
-        return mPolicy.getUserRotationMode() == WindowManagerPolicy.USER_ROTATION_LOCKED;
-    }
-
-    @Override
-    public int watchRotation(IRotationWatcher watcher) {
-        final IBinder watcherBinder = watcher.asBinder();
-        IBinder.DeathRecipient dr = new IBinder.DeathRecipient() {
-            @Override
-            public void binderDied() {
-                synchronized (mWindowMap) {
-                    for (int i=0; i<mRotationWatchers.size(); i++) {
-                        if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
-                            IRotationWatcher removed = mRotationWatchers.remove(i);
-                            if (removed != null) {
-                                removed.asBinder().unlinkToDeath(this, 0);
-                            }
-                            i--;
-                        }
-                    }
-                }
-            }
-        };
-
-        synchronized (mWindowMap) {
-            try {
-                watcher.asBinder().linkToDeath(dr, 0);
-                mRotationWatchers.add(watcher);
-            } catch (RemoteException e) {
-                // Client died, no cleanup needed.
-            }
-
-            return mRotation;
-        }
-    }
-
-    @Override
-    public void removeRotationWatcher(IRotationWatcher watcher) {
-        final IBinder watcherBinder = watcher.asBinder();
-        synchronized (mWindowMap) {
-            for (int i=0; i<mRotationWatchers.size(); i++) {
-                if (watcherBinder == mRotationWatchers.get(i).asBinder()) {
-                    mRotationWatchers.remove(i);
-                    i--;
-                }
-            }
-        }
-    }
-
-    /**
-     * Apps that use the compact menu panel (as controlled by the panelMenuIsCompact
-     * theme attribute) on devices that feature a physical options menu key attempt to position
-     * their menu panel window along the edge of the screen nearest the physical menu key.
-     * This lowers the travel distance between invoking the menu panel and selecting
-     * a menu option.
-     *
-     * This method helps control where that menu is placed. Its current implementation makes
-     * assumptions about the menu key and its relationship to the screen based on whether
-     * the device's natural orientation is portrait (width < height) or landscape.
-     *
-     * The menu key is assumed to be located along the bottom edge of natural-portrait
-     * devices and along the right edge of natural-landscape devices. If these assumptions
-     * do not hold for the target device, this method should be changed to reflect that.
-     *
-     * @return A {@link Gravity} value for placing the options menu window
-     */
-    @Override
-    public int getPreferredOptionsPanelGravity() {
-        synchronized (mWindowMap) {
-            final int rotation = getRotation();
-
-            // TODO(multidisplay): Assume that such devices physical keys are on the main screen.
-            final DisplayContent displayContent = getDefaultDisplayContentLocked();
-            if (displayContent.mInitialDisplayWidth < displayContent.mInitialDisplayHeight) {
-                // On devices with a natural orientation of portrait
-                switch (rotation) {
-                    default:
-                    case Surface.ROTATION_0:
-                        return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
-                    case Surface.ROTATION_90:
-                        return Gravity.RIGHT | Gravity.BOTTOM;
-                    case Surface.ROTATION_180:
-                        return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
-                    case Surface.ROTATION_270:
-                        return Gravity.START | Gravity.BOTTOM;
-                }
-            }
-
-            // On devices with a natural orientation of landscape
-            switch (rotation) {
-                default:
-                case Surface.ROTATION_0:
-                    return Gravity.RIGHT | Gravity.BOTTOM;
-                case Surface.ROTATION_90:
-                    return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
-                case Surface.ROTATION_180:
-                    return Gravity.START | Gravity.BOTTOM;
-                case Surface.ROTATION_270:
-                    return Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
-            }
-        }
-    }
-
-    /**
-     * Starts the view server on the specified port.
-     *
-     * @param port The port to listener to.
-     *
-     * @return True if the server was successfully started, false otherwise.
-     *
-     * @see com.android.server.wm.ViewServer
-     * @see com.android.server.wm.ViewServer#VIEW_SERVER_DEFAULT_PORT
-     */
-    @Override
-    public boolean startViewServer(int port) {
-        if (isSystemSecure()) {
-            return false;
-        }
-
-        if (!checkCallingPermission(Manifest.permission.DUMP, "startViewServer")) {
-            return false;
-        }
-
-        if (port < 1024) {
-            return false;
-        }
-
-        if (mViewServer != null) {
-            if (!mViewServer.isRunning()) {
-                try {
-                    return mViewServer.start();
-                } catch (IOException e) {
-                    Slog.w(TAG, "View server did not start");
-                }
-            }
-            return false;
-        }
-
-        try {
-            mViewServer = new ViewServer(this, port);
-            return mViewServer.start();
-        } catch (IOException e) {
-            Slog.w(TAG, "View server did not start");
-        }
-        return false;
-    }
-
-    private boolean isSystemSecure() {
-        return "1".equals(SystemProperties.get(SYSTEM_SECURE, "1")) &&
-                "0".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"));
-    }
-
-    /**
-     * Stops the view server if it exists.
-     *
-     * @return True if the server stopped, false if it wasn't started or
-     *         couldn't be stopped.
-     *
-     * @see com.android.server.wm.ViewServer
-     */
-    @Override
-    public boolean stopViewServer() {
-        if (isSystemSecure()) {
-            return false;
-        }
-
-        if (!checkCallingPermission(Manifest.permission.DUMP, "stopViewServer")) {
-            return false;
-        }
-
-        if (mViewServer != null) {
-            return mViewServer.stop();
-        }
-        return false;
-    }
-
-    /**
-     * Indicates whether the view server is running.
-     *
-     * @return True if the server is running, false otherwise.
-     *
-     * @see com.android.server.wm.ViewServer
-     */
-    @Override
-    public boolean isViewServerRunning() {
-        if (isSystemSecure()) {
-            return false;
-        }
-
-        if (!checkCallingPermission(Manifest.permission.DUMP, "isViewServerRunning")) {
-            return false;
-        }
-
-        return mViewServer != null && mViewServer.isRunning();
-    }
-
-    /**
-     * Lists all availble windows in the system. The listing is written in the
-     * specified Socket's output stream with the following syntax:
-     * windowHashCodeInHexadecimal windowName
-     * Each line of the ouput represents a different window.
-     *
-     * @param client The remote client to send the listing to.
-     * @return False if an error occured, true otherwise.
-     */
-    boolean viewServerListWindows(Socket client) {
-        if (isSystemSecure()) {
-            return false;
-        }
-
-        boolean result = true;
-
-        WindowList windows = new WindowList();
-        synchronized (mWindowMap) {
-            //noinspection unchecked
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-                windows.addAll(displayContent.getWindowList());
-            }
-        }
-
-        BufferedWriter out = null;
-
-        // Any uncaught exception will crash the system process
-        try {
-            OutputStream clientStream = client.getOutputStream();
-            out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
-
-            final int count = windows.size();
-            for (int i = 0; i < count; i++) {
-                final WindowState w = windows.get(i);
-                out.write(Integer.toHexString(System.identityHashCode(w)));
-                out.write(' ');
-                out.append(w.mAttrs.getTitle());
-                out.write('\n');
-            }
-
-            out.write("DONE.\n");
-            out.flush();
-        } catch (Exception e) {
-            result = false;
-        } finally {
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    result = false;
-                }
-            }
-        }
-
-        return result;
-    }
-
-    // TODO(multidisplay): Extend to multiple displays.
-    /**
-     * Returns the focused window in the following format:
-     * windowHashCodeInHexadecimal windowName
-     *
-     * @param client The remote client to send the listing to.
-     * @return False if an error occurred, true otherwise.
-     */
-    boolean viewServerGetFocusedWindow(Socket client) {
-        if (isSystemSecure()) {
-            return false;
-        }
-
-        boolean result = true;
-
-        WindowState focusedWindow = getFocusedWindow();
-
-        BufferedWriter out = null;
-
-        // Any uncaught exception will crash the system process
-        try {
-            OutputStream clientStream = client.getOutputStream();
-            out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
-
-            if(focusedWindow != null) {
-                out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
-                out.write(' ');
-                out.append(focusedWindow.mAttrs.getTitle());
-            }
-            out.write('\n');
-            out.flush();
-        } catch (Exception e) {
-            result = false;
-        } finally {
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    result = false;
-                }
-            }
-        }
-
-        return result;
-    }
-
-    /**
-     * Sends a command to a target window. The result of the command, if any, will be
-     * written in the output stream of the specified socket.
-     *
-     * The parameters must follow this syntax:
-     * windowHashcode extra
-     *
-     * Where XX is the length in characeters of the windowTitle.
-     *
-     * The first parameter is the target window. The window with the specified hashcode
-     * will be the target. If no target can be found, nothing happens. The extra parameters
-     * will be delivered to the target window and as parameters to the command itself.
-     *
-     * @param client The remote client to sent the result, if any, to.
-     * @param command The command to execute.
-     * @param parameters The command parameters.
-     *
-     * @return True if the command was successfully delivered, false otherwise. This does
-     *         not indicate whether the command itself was successful.
-     */
-    boolean viewServerWindowCommand(Socket client, String command, String parameters) {
-        if (isSystemSecure()) {
-            return false;
-        }
-
-        boolean success = true;
-        Parcel data = null;
-        Parcel reply = null;
-
-        BufferedWriter out = null;
-
-        // Any uncaught exception will crash the system process
-        try {
-            // Find the hashcode of the window
-            int index = parameters.indexOf(' ');
-            if (index == -1) {
-                index = parameters.length();
-            }
-            final String code = parameters.substring(0, index);
-            int hashCode = (int) Long.parseLong(code, 16);
-
-            // Extract the command's parameter after the window description
-            if (index < parameters.length()) {
-                parameters = parameters.substring(index + 1);
-            } else {
-                parameters = "";
-            }
-
-            final WindowState window = findWindow(hashCode);
-            if (window == null) {
-                return false;
-            }
-
-            data = Parcel.obtain();
-            data.writeInterfaceToken("android.view.IWindow");
-            data.writeString(command);
-            data.writeString(parameters);
-            data.writeInt(1);
-            ParcelFileDescriptor.fromSocket(client).writeToParcel(data, 0);
-
-            reply = Parcel.obtain();
-
-            final IBinder binder = window.mClient.asBinder();
-            // TODO: GET THE TRANSACTION CODE IN A SAFER MANNER
-            binder.transact(IBinder.FIRST_CALL_TRANSACTION, data, reply, 0);
-
-            reply.readException();
-
-            if (!client.isOutputShutdown()) {
-                out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
-                out.write("DONE\n");
-                out.flush();
-            }
-
-        } catch (Exception e) {
-            Slog.w(TAG, "Could not send command " + command + " with parameters " + parameters, e);
-            success = false;
-        } finally {
-            if (data != null) {
-                data.recycle();
-            }
-            if (reply != null) {
-                reply.recycle();
-            }
-            if (out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-
-                }
-            }
-        }
-
-        return success;
-    }
-
-    public void addWindowChangeListener(WindowChangeListener listener) {
-        synchronized(mWindowMap) {
-            mWindowChangeListeners.add(listener);
-        }
-    }
-
-    public void removeWindowChangeListener(WindowChangeListener listener) {
-        synchronized(mWindowMap) {
-            mWindowChangeListeners.remove(listener);
-        }
-    }
-
-    private void notifyWindowsChanged() {
-        WindowChangeListener[] windowChangeListeners;
-        synchronized(mWindowMap) {
-            if(mWindowChangeListeners.isEmpty()) {
-                return;
-            }
-            windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
-            windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
-        }
-        int N = windowChangeListeners.length;
-        for(int i = 0; i < N; i++) {
-            windowChangeListeners[i].windowsChanged();
-        }
-    }
-
-    private void notifyFocusChanged() {
-        WindowChangeListener[] windowChangeListeners;
-        synchronized(mWindowMap) {
-            if(mWindowChangeListeners.isEmpty()) {
-                return;
-            }
-            windowChangeListeners = new WindowChangeListener[mWindowChangeListeners.size()];
-            windowChangeListeners = mWindowChangeListeners.toArray(windowChangeListeners);
-        }
-        int N = windowChangeListeners.length;
-        for(int i = 0; i < N; i++) {
-            windowChangeListeners[i].focusChanged();
-        }
-    }
-
-    private WindowState findWindow(int hashCode) {
-        if (hashCode == -1) {
-            // TODO(multidisplay): Extend to multiple displays.
-            return getFocusedWindow();
-        }
-
-        synchronized (mWindowMap) {
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-                final int numWindows = windows.size();
-                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                    final WindowState w = windows.get(winNdx);
-                    if (System.identityHashCode(w) == hashCode) {
-                        return w;
-                    }
-                }
-            }
-        }
-
-        return null;
-    }
-
-    /*
-     * Instruct the Activity Manager to fetch the current configuration and broadcast
-     * that to config-changed listeners if appropriate.
-     */
-    void sendNewConfiguration() {
-        try {
-            mActivityManager.updateConfiguration(null);
-        } catch (RemoteException e) {
-        }
-    }
-
-    public Configuration computeNewConfiguration() {
-        synchronized (mWindowMap) {
-            Configuration config = computeNewConfigurationLocked();
-            if (config == null && mWaitingForConfig) {
-                // Nothing changed but we are waiting for something... stop that!
-                mWaitingForConfig = false;
-                mLastFinishedFreezeSource = "new-config";
-                performLayoutAndPlaceSurfacesLocked();
-            }
-            return config;
-        }
-    }
-
-    Configuration computeNewConfigurationLocked() {
-        Configuration config = new Configuration();
-        config.fontScale = 0;
-        if (!computeScreenConfigurationLocked(config)) {
-            return null;
-        }
-        return config;
-    }
-
-    private void adjustDisplaySizeRanges(DisplayInfo displayInfo, int rotation, int dw, int dh) {
-        // TODO: Multidisplay: for now only use with default display.
-        final int width = mPolicy.getConfigDisplayWidth(dw, dh, rotation);
-        if (width < displayInfo.smallestNominalAppWidth) {
-            displayInfo.smallestNominalAppWidth = width;
-        }
-        if (width > displayInfo.largestNominalAppWidth) {
-            displayInfo.largestNominalAppWidth = width;
-        }
-        final int height = mPolicy.getConfigDisplayHeight(dw, dh, rotation);
-        if (height < displayInfo.smallestNominalAppHeight) {
-            displayInfo.smallestNominalAppHeight = height;
-        }
-        if (height > displayInfo.largestNominalAppHeight) {
-            displayInfo.largestNominalAppHeight = height;
-        }
-    }
-
-    private int reduceConfigLayout(int curLayout, int rotation, float density,
-            int dw, int dh) {
-        // 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);
-
-        // Compute the screen layout size class for this rotation.
-        int longSize = w;
-        int shortSize = h;
-        if (longSize < shortSize) {
-            int tmp = longSize;
-            longSize = shortSize;
-            shortSize = tmp;
-        }
-        longSize = (int)(longSize/density);
-        shortSize = (int)(shortSize/density);
-        return Configuration.reduceScreenLayout(curLayout, longSize, shortSize);
-    }
-
-    private void computeSizeRangesAndScreenLayout(DisplayInfo displayInfo, boolean rotated,
-                  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
-        // operation.  To this, start with the base screen size and compute the
-        // width under the different possible rotations.  We need to un-rotate
-        // the current screen dimensions before doing this.
-        int unrotDw, unrotDh;
-        if (rotated) {
-            unrotDw = dh;
-            unrotDh = dw;
-        } else {
-            unrotDw = dw;
-            unrotDh = dh;
-        }
-        displayInfo.smallestNominalAppWidth = 1<<30;
-        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);
-        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);
-        outConfig.smallestScreenWidthDp = (int)(displayInfo.smallestNominalAppWidth / density);
-        outConfig.screenLayout = sl;
-    }
-
-    private int reduceCompatConfigWidthSize(int curSize, int rotation, 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);
-        float scale = CompatibilityInfo.computeCompatibleScaling(dm, null);
-        int size = (int)(((dm.noncompatWidthPixels / scale) / dm.density) + .5f);
-        if (curSize == 0 || size < curSize) {
-            curSize = size;
-        }
-        return curSize;
-    }
-
-    private int computeCompatSmallestWidth(boolean rotated, DisplayMetrics dm, int dw, int dh) {
-        // TODO: Multidisplay: for now only use with default display.
-        mTmpDisplayMetrics.setTo(dm);
-        final DisplayMetrics tmpDm = mTmpDisplayMetrics;
-        final int unrotDw, unrotDh;
-        if (rotated) {
-            unrotDw = dh;
-            unrotDh = dw;
-        } else {
-            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);
-        return sw;
-    }
-
-    boolean computeScreenConfigurationLocked(Configuration config) {
-        if (!mDisplayReady) {
-            return false;
-        }
-
-        // TODO(multidisplay): For now, apply Configuration to main screen only.
-        final DisplayContent displayContent = getDefaultDisplayContentLocked();
-
-        // Use the effective "visual" dimensions based on current rotation
-        final boolean rotated = (mRotation == Surface.ROTATION_90
-                || mRotation == Surface.ROTATION_270);
-        final int realdw = rotated ?
-                displayContent.mBaseDisplayHeight : displayContent.mBaseDisplayWidth;
-        final int realdh = rotated ?
-                displayContent.mBaseDisplayWidth : displayContent.mBaseDisplayHeight;
-        int dw = realdw;
-        int dh = realdh;
-
-        if (mAltOrientation) {
-            if (realdw > realdh) {
-                // Turn landscape into portrait.
-                int maxw = (int)(realdh/1.3f);
-                if (maxw < realdw) {
-                    dw = maxw;
-                }
-            } else {
-                // Turn portrait into landscape.
-                int maxh = (int)(realdw/1.3f);
-                if (maxh < realdh) {
-                    dh = maxh;
-                }
-            }
-        }
-
-        if (config != null) {
-            config.orientation = (dw <= dh) ? Configuration.ORIENTATION_PORTRAIT :
-                    Configuration.ORIENTATION_LANDSCAPE;
-        }
-
-        // Update application display metrics.
-        final int appWidth = mPolicy.getNonDecorDisplayWidth(dw, dh, mRotation);
-        final int appHeight = mPolicy.getNonDecorDisplayHeight(dw, dh, mRotation);
-        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        synchronized(displayContent.mDisplaySizeLock) {
-            displayInfo.rotation = mRotation;
-            displayInfo.logicalWidth = dw;
-            displayInfo.logicalHeight = dh;
-            displayInfo.logicalDensityDpi = displayContent.mBaseDisplayDensity;
-            displayInfo.appWidth = appWidth;
-            displayInfo.appHeight = appHeight;
-            displayInfo.getLogicalMetrics(mRealDisplayMetrics,
-                    CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
-            displayInfo.getAppMetrics(mDisplayMetrics);
-            mDisplayManagerService.setDisplayInfoOverrideFromWindowManager(
-                    displayContent.getDisplayId(), displayInfo);
-        }
-        if (false) {
-            Slog.i(TAG, "Set app display size: " + appWidth + " x " + appHeight);
-        }
-
-        final DisplayMetrics dm = mDisplayMetrics;
-        mCompatibleScreenScale = CompatibilityInfo.computeCompatibleScaling(dm,
-                mCompatDisplayMetrics);
-
-        if (config != null) {
-            config.screenWidthDp = (int)(mPolicy.getConfigDisplayWidth(dw, dh, mRotation)
-                    / dm.density);
-            config.screenHeightDp = (int)(mPolicy.getConfigDisplayHeight(dw, dh, mRotation)
-                    / dm.density);
-            computeSizeRangesAndScreenLayout(displayInfo, rotated, dw, dh, dm.density, config);
-
-            config.compatScreenWidthDp = (int)(config.screenWidthDp / mCompatibleScreenScale);
-            config.compatScreenHeightDp = (int)(config.screenHeightDp / mCompatibleScreenScale);
-            config.compatSmallestScreenWidthDp = computeCompatSmallestWidth(rotated, dm, dw, dh);
-            config.densityDpi = displayContent.mBaseDisplayDensity;
-
-            // Update the configuration based on available input devices, lid switch,
-            // and platform configuration.
-            config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
-            config.keyboard = Configuration.KEYBOARD_NOKEYS;
-            config.navigation = Configuration.NAVIGATION_NONAV;
-
-            int keyboardPresence = 0;
-            int navigationPresence = 0;
-            final InputDevice[] devices = mInputManager.getInputDevices();
-            final int len = devices.length;
-            for (int i = 0; i < len; i++) {
-                InputDevice device = devices[i];
-                if (!device.isVirtual()) {
-                    final int sources = device.getSources();
-                    final int presenceFlag = device.isExternal() ?
-                            WindowManagerPolicy.PRESENCE_EXTERNAL :
-                                    WindowManagerPolicy.PRESENCE_INTERNAL;
-
-                    if (mIsTouchDevice) {
-                        if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
-                                InputDevice.SOURCE_TOUCHSCREEN) {
-                            config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
-                        }
-                    } else {
-                        config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
-                    }
-
-                    if ((sources & InputDevice.SOURCE_TRACKBALL) == InputDevice.SOURCE_TRACKBALL) {
-                        config.navigation = Configuration.NAVIGATION_TRACKBALL;
-                        navigationPresence |= presenceFlag;
-                    } else if ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD
-                            && config.navigation == Configuration.NAVIGATION_NONAV) {
-                        config.navigation = Configuration.NAVIGATION_DPAD;
-                        navigationPresence |= presenceFlag;
-                    }
-
-                    if (device.getKeyboardType() == InputDevice.KEYBOARD_TYPE_ALPHABETIC) {
-                        config.keyboard = Configuration.KEYBOARD_QWERTY;
-                        keyboardPresence |= presenceFlag;
-                    }
-                }
-            }
-
-            // Determine whether a hard keyboard is available and enabled.
-            boolean hardKeyboardAvailable = config.keyboard != Configuration.KEYBOARD_NOKEYS;
-            if (hardKeyboardAvailable != mHardKeyboardAvailable) {
-                mHardKeyboardAvailable = hardKeyboardAvailable;
-                mHardKeyboardEnabled = hardKeyboardAvailable;
-                mH.removeMessages(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
-                mH.sendEmptyMessage(H.REPORT_HARD_KEYBOARD_STATUS_CHANGE);
-            }
-            if (!mHardKeyboardEnabled) {
-                config.keyboard = Configuration.KEYBOARD_NOKEYS;
-            }
-
-            // Let the policy update hidden states.
-            config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
-            config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
-            config.navigationHidden = Configuration.NAVIGATIONHIDDEN_NO;
-            mPolicy.adjustConfigurationLw(config, keyboardPresence, navigationPresence);
-        }
-
-        return true;
-    }
-
-    public boolean isHardKeyboardAvailable() {
-        synchronized (mWindowMap) {
-            return mHardKeyboardAvailable;
-        }
-    }
-
-    public boolean isHardKeyboardEnabled() {
-        synchronized (mWindowMap) {
-            return mHardKeyboardEnabled;
-        }
-    }
-
-    public void setHardKeyboardEnabled(boolean enabled) {
-        synchronized (mWindowMap) {
-            if (mHardKeyboardEnabled != enabled) {
-                mHardKeyboardEnabled = enabled;
-                mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-            }
-        }
-    }
-
-    public void setOnHardKeyboardStatusChangeListener(
-            OnHardKeyboardStatusChangeListener listener) {
-        synchronized (mWindowMap) {
-            mHardKeyboardStatusChangeListener = listener;
-        }
-    }
-
-    void notifyHardKeyboardStatusChange() {
-        final boolean available, enabled;
-        final OnHardKeyboardStatusChangeListener listener;
-        synchronized (mWindowMap) {
-            listener = mHardKeyboardStatusChangeListener;
-            available = mHardKeyboardAvailable;
-            enabled = mHardKeyboardEnabled;
-        }
-        if (listener != null) {
-            listener.onHardKeyboardStatusChange(available, enabled);
-        }
-    }
-
-    // -------------------------------------------------------------
-    // Drag and drop
-    // -------------------------------------------------------------
-
-    IBinder prepareDragSurface(IWindow window, SurfaceSession session,
-            int flags, int width, int height, Surface outSurface) {
-        if (DEBUG_DRAG) {
-            Slog.d(TAG, "prepare drag surface: w=" + width + " h=" + height
-                    + " flags=" + Integer.toHexString(flags) + " win=" + window
-                    + " asbinder=" + window.asBinder());
-        }
-
-        final int callerPid = Binder.getCallingPid();
-        final long origId = Binder.clearCallingIdentity();
-        IBinder token = null;
-
-        try {
-            synchronized (mWindowMap) {
-                try {
-                    if (mDragState == null) {
-                        // TODO(multi-display): support other displays
-                        final DisplayContent displayContent = getDefaultDisplayContentLocked();
-                        final Display display = displayContent.getDisplay();
-                        SurfaceControl surface = new SurfaceControl(session, "drag surface",
-                                width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
-                        surface.setLayerStack(display.getLayerStack());
-                        if (SHOW_TRANSACTIONS) Slog.i(TAG, "  DRAG "
-                                + surface + ": CREATE");
-                        outSurface.copyFrom(surface);
-                        final IBinder winBinder = window.asBinder();
-                        token = new Binder();
-                        mDragState = new DragState(this, token, surface, /*flags*/ 0, winBinder);
-                        token = mDragState.mToken = new Binder();
-
-                        // 5 second timeout for this window to actually begin the drag
-                        mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
-                        Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
-                        mH.sendMessageDelayed(msg, 5000);
-                    } else {
-                        Slog.w(TAG, "Drag already in progress");
-                    }
-                } catch (OutOfResourcesException e) {
-                    Slog.e(TAG, "Can't allocate drag surface w=" + width + " h=" + height, e);
-                    if (mDragState != null) {
-                        mDragState.reset();
-                        mDragState = null;
-                    }
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(origId);
-        }
-
-        return token;
-    }
-
-    // -------------------------------------------------------------
-    // Input Events and Focus Management
-    // -------------------------------------------------------------
-
-    final InputMonitor mInputMonitor = new InputMonitor(this);
-    private boolean mEventDispatchingEnabled;
-
-    @Override
-    public void pauseKeyDispatching(IBinder _token) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "pauseKeyDispatching()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized (mWindowMap) {
-            WindowToken token = mTokenMap.get(_token);
-            if (token != null) {
-                mInputMonitor.pauseDispatchingLw(token);
-            }
-        }
-    }
-
-    @Override
-    public void resumeKeyDispatching(IBinder _token) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "resumeKeyDispatching()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized (mWindowMap) {
-            WindowToken token = mTokenMap.get(_token);
-            if (token != null) {
-                mInputMonitor.resumeDispatchingLw(token);
-            }
-        }
-    }
-
-    @Override
-    public void setEventDispatching(boolean enabled) {
-        if (!checkCallingPermission(android.Manifest.permission.MANAGE_APP_TOKENS,
-                "setEventDispatching()")) {
-            throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
-        }
-
-        synchronized (mWindowMap) {
-            mEventDispatchingEnabled = enabled;
-            if (mDisplayEnabled) {
-                mInputMonitor.setEventDispatchingLw(enabled);
-            }
-            sendScreenStatusToClientsLocked();
-        }
-    }
-
-    @Override
-    public IBinder getFocusedWindowToken() {
-        if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO,
-                "getFocusedWindowToken()")) {
-            throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission.");
-        }
-        synchronized (mWindowMap) {
-            WindowState windowState = getFocusedWindowLocked();
-            if (windowState != null) {
-                return windowState.mClient.asBinder();
-            }
-            return null;
-        }
-    }
-
-    private WindowState getFocusedWindow() {
-        synchronized (mWindowMap) {
-            return getFocusedWindowLocked();
-        }
-    }
-
-    private WindowState getFocusedWindowLocked() {
-        return mCurrentFocus;
-    }
-
-    public boolean detectSafeMode() {
-        if (!mInputMonitor.waitForInputDevicesReady(
-                INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS)) {
-            Slog.w(TAG, "Devices still not ready after waiting "
-                   + INPUT_DEVICES_READY_FOR_SAFE_MODE_DETECTION_TIMEOUT_MILLIS
-                   + " milliseconds before attempting to detect safe mode.");
-        }
-
-        int menuState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY,
-                KeyEvent.KEYCODE_MENU);
-        int sState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY, KeyEvent.KEYCODE_S);
-        int dpadState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_DPAD,
-                KeyEvent.KEYCODE_DPAD_CENTER);
-        int trackballState = mInputManager.getScanCodeState(-1, InputDevice.SOURCE_TRACKBALL,
-                InputManagerService.BTN_MOUSE);
-        int volumeDownState = mInputManager.getKeyCodeState(-1, InputDevice.SOURCE_ANY,
-                KeyEvent.KEYCODE_VOLUME_DOWN);
-        mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0
-                || volumeDownState > 0;
-        try {
-            if (SystemProperties.getInt(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, 0) != 0) {
-                mSafeMode = true;
-                SystemProperties.set(ShutdownThread.REBOOT_SAFEMODE_PROPERTY, "");
-            }
-        } catch (IllegalArgumentException e) {
-        }
-        if (mSafeMode) {
-            Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState
-                    + " dpad=" + dpadState + " trackball=" + trackballState + ")");
-        } else {
-            Log.i(TAG, "SAFE MODE not enabled");
-        }
-        mPolicy.setSafeMode(mSafeMode);
-        return mSafeMode;
-    }
-
-    public void displayReady() {
-        displayReady(Display.DEFAULT_DISPLAY);
-
-        synchronized(mWindowMap) {
-            final DisplayContent displayContent = getDefaultDisplayContentLocked();
-            readForcedDisplaySizeAndDensityLocked(displayContent);
-            mDisplayReady = true;
-        }
-
-        try {
-            mActivityManager.updateConfiguration(null);
-        } catch (RemoteException e) {
-        }
-
-        synchronized(mWindowMap) {
-            mIsTouchDevice = mContext.getPackageManager().hasSystemFeature(
-                    PackageManager.FEATURE_TOUCHSCREEN);
-            configureDisplayPolicyLocked(getDefaultDisplayContentLocked());
-        }
-
-        try {
-            mActivityManager.updateConfiguration(null);
-        } catch (RemoteException e) {
-        }
-    }
-
-    private void displayReady(int displayId) {
-        synchronized(mWindowMap) {
-            final DisplayContent displayContent = getDisplayContentLocked(displayId);
-            if (displayContent != null) {
-                mAnimator.addDisplayLocked(displayId);
-                synchronized(displayContent.mDisplaySizeLock) {
-                    // Bootstrap the default logical display from the display manager.
-                    final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-                    DisplayInfo newDisplayInfo = mDisplayManagerService.getDisplayInfo(displayId);
-                    if (newDisplayInfo != null) {
-                        displayInfo.copyFrom(newDisplayInfo);
-                    }
-                    displayContent.mInitialDisplayWidth = displayInfo.logicalWidth;
-                    displayContent.mInitialDisplayHeight = displayInfo.logicalHeight;
-                    displayContent.mInitialDisplayDensity = displayInfo.logicalDensityDpi;
-                    displayContent.mBaseDisplayWidth = displayContent.mInitialDisplayWidth;
-                    displayContent.mBaseDisplayHeight = displayContent.mInitialDisplayHeight;
-                    displayContent.mBaseDisplayDensity = displayContent.mInitialDisplayDensity;
-                    displayContent.mBaseDisplayRect.set(0, 0,
-                            displayContent.mBaseDisplayWidth, displayContent.mBaseDisplayHeight);
-                }
-            }
-        }
-    }
-
-    public void systemReady() {
-        mPolicy.systemReady();
-    }
-
-    // TODO(multidisplay): Call isScreenOn for each display.
-    private void sendScreenStatusToClientsLocked() {
-        final boolean on = mPowerManager.isScreenOn();
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-            final int numWindows = windows.size();
-            for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                try {
-                    windows.get(winNdx).mClient.dispatchScreenState(on);
-                } catch (RemoteException e) {
-                    // Ignored
-                }
-            }
-        }
-    }
-
-    // -------------------------------------------------------------
-    // Async Handler
-    // -------------------------------------------------------------
-
-    final class H extends Handler {
-        public static final int REPORT_FOCUS_CHANGE = 2;
-        public static final int REPORT_LOSING_FOCUS = 3;
-        public static final int DO_TRAVERSAL = 4;
-        public static final int ADD_STARTING = 5;
-        public static final int REMOVE_STARTING = 6;
-        public static final int FINISHED_STARTING = 7;
-        public static final int REPORT_APPLICATION_TOKEN_WINDOWS = 8;
-        public static final int REPORT_APPLICATION_TOKEN_DRAWN = 9;
-        public static final int WINDOW_FREEZE_TIMEOUT = 11;
-
-        public static final int APP_TRANSITION_TIMEOUT = 13;
-        public static final int PERSIST_ANIMATION_SCALE = 14;
-        public static final int FORCE_GC = 15;
-        public static final int ENABLE_SCREEN = 16;
-        public static final int APP_FREEZE_TIMEOUT = 17;
-        public static final int SEND_NEW_CONFIGURATION = 18;
-        public static final int REPORT_WINDOWS_CHANGE = 19;
-        public static final int DRAG_START_TIMEOUT = 20;
-        public static final int DRAG_END_TIMEOUT = 21;
-        public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
-        public static final int BOOT_TIMEOUT = 23;
-        public static final int WAITING_FOR_DRAWN_TIMEOUT = 24;
-        public static final int SHOW_STRICT_MODE_VIOLATION = 25;
-        public static final int DO_ANIMATION_CALLBACK = 26;
-
-        public static final int DO_DISPLAY_ADDED = 27;
-        public static final int DO_DISPLAY_REMOVED = 28;
-        public static final int DO_DISPLAY_CHANGED = 29;
-
-        public static final int CLIENT_FREEZE_TIMEOUT = 30;
-        public static final int TAP_OUTSIDE_STACK = 31;
-        public static final int NOTIFY_ACTIVITY_DRAWN = 32;
-
-        public static final int REMOVE_STARTING_TIMEOUT = 33;
-
-        @Override
-        public void handleMessage(Message msg) {
-            if (DEBUG_WINDOW_TRACE) {
-                Slog.v(TAG, "handleMessage: entry what=" + msg.what);
-            }
-            switch (msg.what) {
-                case REPORT_FOCUS_CHANGE: {
-                    WindowState lastFocus;
-                    WindowState newFocus;
-
-                    synchronized(mWindowMap) {
-                        lastFocus = mLastFocus;
-                        newFocus = mCurrentFocus;
-                        if (lastFocus == newFocus) {
-                            // Focus is not changing, so nothing to do.
-                            return;
-                        }
-                        mLastFocus = newFocus;
-                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Focus moving from " + lastFocus +
-                                " to " + newFocus);
-                        if (newFocus != null && lastFocus != null
-                                && !newFocus.isDisplayedLw()) {
-                            //Slog.i(TAG, "Delaying loss of focus...");
-                            mLosingFocus.add(lastFocus);
-                            lastFocus = null;
-                        }
-                    }
-
-                    //System.out.println("Changing focus from " + lastFocus
-                    //                   + " to " + newFocus);
-                    if (newFocus != null) {
-                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Gaining focus: " + newFocus);
-                        newFocus.reportFocusChangedSerialized(true, mInTouchMode);
-                        notifyFocusChanged();
-                    }
-
-                    if (lastFocus != null) {
-                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Losing focus: " + lastFocus);
-                        lastFocus.reportFocusChangedSerialized(false, mInTouchMode);
-                    }
-                } break;
-
-                case REPORT_LOSING_FOCUS: {
-                    ArrayList<WindowState> losers;
-
-                    synchronized(mWindowMap) {
-                        losers = mLosingFocus;
-                        mLosingFocus = new ArrayList<WindowState>();
-                    }
-
-                    final int N = losers.size();
-                    for (int i=0; i<N; i++) {
-                        if (DEBUG_FOCUS_LIGHT) Slog.i(TAG, "Losing delayed focus: " +
-                                losers.get(i));
-                        losers.get(i).reportFocusChangedSerialized(false, mInTouchMode);
-                    }
-                } break;
-
-                case DO_TRAVERSAL: {
-                    synchronized(mWindowMap) {
-                        mTraversalScheduled = false;
-                        performLayoutAndPlaceSurfacesLocked();
-                    }
-                } break;
-
-                case ADD_STARTING: {
-                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
-                    final StartingData sd = wtoken.startingData;
-
-                    if (sd == null) {
-                        // Animation has been canceled... do nothing.
-                        return;
-                    }
-
-                    if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Add starting "
-                            + wtoken + ": pkg=" + sd.pkg);
-
-                    View view = null;
-                    try {
-                        view = mPolicy.addStartingWindow(
-                            wtoken.token, sd.pkg, sd.theme, sd.compatInfo,
-                            sd.nonLocalizedLabel, sd.labelRes, sd.icon, sd.logo, sd.windowFlags);
-                    } catch (Exception e) {
-                        Slog.w(TAG, "Exception when adding starting window", e);
-                    }
-
-                    if (view != null) {
-                        boolean abort = false;
-
-                        synchronized(mWindowMap) {
-                            if (wtoken.removed || wtoken.startingData == null) {
-                                // If the window was successfully added, then
-                                // we need to remove it.
-                                if (wtoken.startingWindow != null) {
-                                    if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
-                                            "Aborted starting " + wtoken
-                                            + ": removed=" + wtoken.removed
-                                            + " startingData=" + wtoken.startingData);
-                                    removeStartingWindowTimeout(wtoken);
-                                    wtoken.startingWindow = null;
-                                    wtoken.startingData = null;
-                                    abort = true;
-                                }
-                            } else {
-                                wtoken.startingView = view;
-                            }
-                            if (DEBUG_STARTING_WINDOW && !abort) Slog.v(TAG,
-                                    "Added starting " + wtoken
-                                    + ": startingWindow="
-                                    + wtoken.startingWindow + " startingView="
-                                    + wtoken.startingView);
-                        }
-
-                        if (abort) {
-                            try {
-                                mPolicy.removeStartingWindow(wtoken.token, view);
-                            } catch (Exception e) {
-                                Slog.w(TAG, "Exception when removing starting window", e);
-                            }
-                        }
-                    }
-                } break;
-
-                case REMOVE_STARTING_TIMEOUT: {
-                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
-                    Slog.e(TAG, "Starting window " + wtoken + " timed out");
-                    // Fall through.
-                }
-                case REMOVE_STARTING: {
-                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
-                    IBinder token = null;
-                    View view = null;
-                    synchronized (mWindowMap) {
-                        if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Remove starting "
-                                + wtoken + ": startingWindow="
-                                + wtoken.startingWindow + " startingView="
-                                + wtoken.startingView);
-                        if (wtoken.startingWindow != null) {
-                            view = wtoken.startingView;
-                            token = wtoken.token;
-                            wtoken.startingData = null;
-                            wtoken.startingView = null;
-                            wtoken.startingWindow = null;
-                            wtoken.startingDisplayed = false;
-                        }
-                    }
-                    if (view != null) {
-                        try {
-                            mPolicy.removeStartingWindow(token, view);
-                        } catch (Exception e) {
-                            Slog.w(TAG, "Exception when removing starting window", e);
-                        }
-                    }
-                } break;
-
-                case FINISHED_STARTING: {
-                    IBinder token = null;
-                    View view = null;
-                    while (true) {
-                        synchronized (mWindowMap) {
-                            final int N = mFinishedStarting.size();
-                            if (N <= 0) {
-                                break;
-                            }
-                            AppWindowToken wtoken = mFinishedStarting.remove(N-1);
-
-                            if (DEBUG_STARTING_WINDOW) Slog.v(TAG,
-                                    "Finished starting " + wtoken
-                                    + ": startingWindow=" + wtoken.startingWindow
-                                    + " startingView=" + wtoken.startingView);
-
-                            if (wtoken.startingWindow == null) {
-                                continue;
-                            }
-
-                            view = wtoken.startingView;
-                            token = wtoken.token;
-                            wtoken.startingData = null;
-                            wtoken.startingView = null;
-                            wtoken.startingWindow = null;
-                            wtoken.startingDisplayed = false;
-                        }
-
-                        try {
-                            mPolicy.removeStartingWindow(token, view);
-                        } catch (Exception e) {
-                            Slog.w(TAG, "Exception when removing starting window", e);
-                        }
-                    }
-                } break;
-
-                case REPORT_APPLICATION_TOKEN_DRAWN: {
-                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
-
-                    try {
-                        if (DEBUG_VISIBILITY) Slog.v(
-                                TAG, "Reporting drawn in " + wtoken);
-                        wtoken.appToken.windowsDrawn();
-                    } catch (RemoteException ex) {
-                    }
-                } break;
-
-                case REPORT_APPLICATION_TOKEN_WINDOWS: {
-                    final AppWindowToken wtoken = (AppWindowToken)msg.obj;
-
-                    boolean nowVisible = msg.arg1 != 0;
-                    boolean nowGone = msg.arg2 != 0;
-
-                    try {
-                        if (DEBUG_VISIBILITY) Slog.v(
-                                TAG, "Reporting visible in " + wtoken
-                                + " visible=" + nowVisible
-                                + " gone=" + nowGone);
-                        if (nowVisible) {
-                            wtoken.appToken.windowsVisible();
-                        } else {
-                            wtoken.appToken.windowsGone();
-                        }
-                    } catch (RemoteException ex) {
-                    }
-                } break;
-
-                case WINDOW_FREEZE_TIMEOUT: {
-                    // TODO(multidisplay): Can non-default displays rotate?
-                    synchronized (mWindowMap) {
-                        Slog.w(TAG, "Window freeze timeout expired.");
-                        final WindowList windows = getDefaultWindowListLocked();
-                        int i = windows.size();
-                        while (i > 0) {
-                            i--;
-                            WindowState w = windows.get(i);
-                            if (w.mOrientationChanging) {
-                                w.mOrientationChanging = false;
-                                w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
-                                        - mDisplayFreezeTime);
-                                Slog.w(TAG, "Force clearing orientation change: " + w);
-                            }
-                        }
-                        performLayoutAndPlaceSurfacesLocked();
-                    }
-                    break;
-                }
-
-                case APP_TRANSITION_TIMEOUT: {
-                    synchronized (mWindowMap) {
-                        if (mAppTransition.isTransitionSet()) {
-                            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "*** APP TRANSITION TIMEOUT");
-                            mAppTransition.setTimeout();
-                            performLayoutAndPlaceSurfacesLocked();
-                        }
-                    }
-                    break;
-                }
-
-                case PERSIST_ANIMATION_SCALE: {
-                    Settings.Global.putFloat(mContext.getContentResolver(),
-                            Settings.Global.WINDOW_ANIMATION_SCALE, mWindowAnimationScale);
-                    Settings.Global.putFloat(mContext.getContentResolver(),
-                            Settings.Global.TRANSITION_ANIMATION_SCALE, mTransitionAnimationScale);
-                    Settings.Global.putFloat(mContext.getContentResolver(),
-                            Settings.Global.ANIMATOR_DURATION_SCALE, mAnimatorDurationScale);
-                    break;
-                }
-
-                case FORCE_GC: {
-                    synchronized (mWindowMap) {
-                        // Since we're holding both mWindowMap and mAnimator we don't need to
-                        // hold mAnimator.mLayoutToAnim.
-                        if (mAnimator.mAnimating || mAnimationScheduled) {
-                            // If we are animating, don't do the gc now but
-                            // delay a bit so we don't interrupt the animation.
-                            sendEmptyMessageDelayed(H.FORCE_GC, 2000);
-                            return;
-                        }
-                        // If we are currently rotating the display, it will
-                        // schedule a new message when done.
-                        if (mDisplayFrozen) {
-                            return;
-                        }
-                    }
-                    Runtime.getRuntime().gc();
-                    break;
-                }
-
-                case ENABLE_SCREEN: {
-                    performEnableScreen();
-                    break;
-                }
-
-                case APP_FREEZE_TIMEOUT: {
-                    synchronized (mWindowMap) {
-                        Slog.w(TAG, "App freeze timeout expired.");
-                        DisplayContent displayContent = getDefaultDisplayContentLocked();
-                        final ArrayList<Task> tasks = displayContent.getTasks();
-                        for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-                            AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-                            for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
-                                AppWindowToken tok = tokens.get(tokenNdx);
-                                if (tok.mAppAnimator.freezingScreen) {
-                                    Slog.w(TAG, "Force clearing freeze: " + tok);
-                                    unsetAppFreezingScreenLocked(tok, true, true);
-                                }
-                            }
-                        }
-                    }
-                    break;
-                }
-
-                case CLIENT_FREEZE_TIMEOUT: {
-                    synchronized (mWindowMap) {
-                        if (mClientFreezingScreen) {
-                            mClientFreezingScreen = false;
-                            mLastFinishedFreezeSource = "client-timeout";
-                            stopFreezingDisplayLocked();
-                        }
-                    }
-                    break;
-                }
-
-                case SEND_NEW_CONFIGURATION: {
-                    removeMessages(SEND_NEW_CONFIGURATION);
-                    sendNewConfiguration();
-                    break;
-                }
-
-                case REPORT_WINDOWS_CHANGE: {
-                    if (mWindowsChanged) {
-                        synchronized (mWindowMap) {
-                            mWindowsChanged = false;
-                        }
-                        notifyWindowsChanged();
-                    }
-                    break;
-                }
-
-                case DRAG_START_TIMEOUT: {
-                    IBinder win = (IBinder)msg.obj;
-                    if (DEBUG_DRAG) {
-                        Slog.w(TAG, "Timeout starting drag by win " + win);
-                    }
-                    synchronized (mWindowMap) {
-                        // !!! TODO: ANR the app that has failed to start the drag in time
-                        if (mDragState != null) {
-                            mDragState.unregister();
-                            mInputMonitor.updateInputWindowsLw(true /*force*/);
-                            mDragState.reset();
-                            mDragState = null;
-                        }
-                    }
-                    break;
-                }
-
-                case DRAG_END_TIMEOUT: {
-                    IBinder win = (IBinder)msg.obj;
-                    if (DEBUG_DRAG) {
-                        Slog.w(TAG, "Timeout ending drag to win " + win);
-                    }
-                    synchronized (mWindowMap) {
-                        // !!! TODO: ANR the drag-receiving app
-                        if (mDragState != null) {
-                            mDragState.mDragResult = false;
-                            mDragState.endDragLw();
-                        }
-                    }
-                    break;
-                }
-
-                case REPORT_HARD_KEYBOARD_STATUS_CHANGE: {
-                    notifyHardKeyboardStatusChange();
-                    break;
-                }
-
-                case BOOT_TIMEOUT: {
-                    performBootTimeout();
-                    break;
-                }
-
-                case WAITING_FOR_DRAWN_TIMEOUT: {
-                    Pair<WindowState, IRemoteCallback> pair;
-                    synchronized (mWindowMap) {
-                        pair = (Pair<WindowState, IRemoteCallback>)msg.obj;
-                        Slog.w(TAG, "Timeout waiting for drawn: " + pair.first);
-                        if (!mWaitingForDrawn.remove(pair)) {
-                            return;
-                        }
-                    }
-                    try {
-                        pair.second.sendResult(null);
-                    } catch (RemoteException e) {
-                    }
-                    break;
-                }
-
-                case SHOW_STRICT_MODE_VIOLATION: {
-                    showStrictModeViolation(msg.arg1, msg.arg2);
-                    break;
-                }
-
-                case DO_ANIMATION_CALLBACK: {
-                    try {
-                        ((IRemoteCallback)msg.obj).sendResult(null);
-                    } catch (RemoteException e) {
-                    }
-                    break;
-                }
-
-                case DO_DISPLAY_ADDED:
-                    synchronized (mWindowMap) {
-                        handleDisplayAddedLocked(msg.arg1);
-                    }
-                    break;
-
-                case DO_DISPLAY_REMOVED:
-                    synchronized (mWindowMap) {
-                        handleDisplayRemovedLocked(msg.arg1);
-                    }
-                    break;
-
-                case DO_DISPLAY_CHANGED:
-                    synchronized (mWindowMap) {
-                        handleDisplayChangedLocked(msg.arg1);
-                    }
-                    break;
-
-                case TAP_OUTSIDE_STACK: {
-                    int stackId;
-                    synchronized (mWindowMap) {
-                        stackId = ((DisplayContent)msg.obj).stackIdFromPoint(msg.arg1, msg.arg2);
-                    }
-                    if (stackId >= 0) {
-                        try {
-                            mActivityManager.setFocusedStack(stackId);
-                        } catch (RemoteException e) {
-                        }
-                    }
-                }
-                break;
-                case NOTIFY_ACTIVITY_DRAWN:
-                    try {
-                        mActivityManager.notifyActivityDrawn((IBinder) msg.obj);
-                    } catch (RemoteException e) {
-                    }
-                    break;
-            }
-            if (DEBUG_WINDOW_TRACE) {
-                Slog.v(TAG, "handleMessage: exit");
-            }
-        }
-    }
-
-    // -------------------------------------------------------------
-    // IWindowManager API
-    // -------------------------------------------------------------
-
-    @Override
-    public IWindowSession openSession(IInputMethodClient client,
-            IInputContext inputContext) {
-        if (client == null) throw new IllegalArgumentException("null client");
-        if (inputContext == null) throw new IllegalArgumentException("null inputContext");
-        Session session = new Session(this, client, inputContext);
-        return session;
-    }
-
-    @Override
-    public boolean inputMethodClientHasFocus(IInputMethodClient client) {
-        synchronized (mWindowMap) {
-            // The focus for the client is the window immediately below
-            // where we would place the input method window.
-            int idx = findDesiredInputMethodWindowIndexLocked(false);
-            if (idx > 0) {
-                // TODO(multidisplay): IMEs are only supported on the default display.
-                WindowState imFocus = getDefaultWindowListLocked().get(idx-1);
-                if (DEBUG_INPUT_METHOD) {
-                    Slog.i(TAG, "Desired input method target: " + imFocus);
-                    Slog.i(TAG, "Current focus: " + mCurrentFocus);
-                    Slog.i(TAG, "Last focus: " + mLastFocus);
-                }
-                if (imFocus != null) {
-                    // This may be a starting window, in which case we still want
-                    // to count it as okay.
-                    if (imFocus.mAttrs.type == LayoutParams.TYPE_APPLICATION_STARTING
-                            && imFocus.mAppToken != null) {
-                        // The client has definitely started, so it really should
-                        // have a window in this app token.  Let's look for it.
-                        for (int i=0; i<imFocus.mAppToken.windows.size(); i++) {
-                            WindowState w = imFocus.mAppToken.windows.get(i);
-                            if (w != imFocus) {
-                                Log.i(TAG, "Switching to real app window: " + w);
-                                imFocus = w;
-                                break;
-                            }
-                        }
-                    }
-                    if (DEBUG_INPUT_METHOD) {
-                        Slog.i(TAG, "IM target client: " + imFocus.mSession.mClient);
-                        if (imFocus.mSession.mClient != null) {
-                            Slog.i(TAG, "IM target client binder: "
-                                    + imFocus.mSession.mClient.asBinder());
-                            Slog.i(TAG, "Requesting client binder: " + client.asBinder());
-                        }
-                    }
-                    if (imFocus.mSession.mClient != null &&
-                            imFocus.mSession.mClient.asBinder() == client.asBinder()) {
-                        return true;
-                    }
-                }
-            }
-
-            // Okay, how about this...  what is the current focus?
-            // It seems in some cases we may not have moved the IM
-            // target window, such as when it was in a pop-up window,
-            // so let's also look at the current focus.  (An example:
-            // go to Gmail, start searching so the keyboard goes up,
-            // press home.  Sometimes the IME won't go down.)
-            // Would be nice to fix this more correctly, but it's
-            // way at the end of a release, and this should be good enough.
-            if (mCurrentFocus != null && mCurrentFocus.mSession.mClient != null
-                    && mCurrentFocus.mSession.mClient.asBinder() == client.asBinder()) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public void getInitialDisplaySize(int displayId, Point size) {
-        synchronized (mWindowMap) {
-            final DisplayContent displayContent = getDisplayContentLocked(displayId);
-            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
-                synchronized(displayContent.mDisplaySizeLock) {
-                    size.x = displayContent.mInitialDisplayWidth;
-                    size.y = displayContent.mInitialDisplayHeight;
-                }
-            }
-        }
-    }
-
-    @Override
-    public void getBaseDisplaySize(int displayId, Point size) {
-        synchronized (mWindowMap) {
-            final DisplayContent displayContent = getDisplayContentLocked(displayId);
-            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
-                synchronized(displayContent.mDisplaySizeLock) {
-                    size.x = displayContent.mBaseDisplayWidth;
-                    size.y = displayContent.mBaseDisplayHeight;
-                }
-            }
-        }
-    }
-
-    @Override
-    public void setForcedDisplaySize(int displayId, int width, int height) {
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
-                PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Must hold permission " +
-                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
-        }
-        if (displayId != Display.DEFAULT_DISPLAY) {
-            throw new IllegalArgumentException("Can only set the default display");
-        }
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                // Set some sort of reasonable bounds on the size of the display that we
-                // will try to emulate.
-                final int MIN_WIDTH = 200;
-                final int MIN_HEIGHT = 200;
-                final int MAX_SCALE = 2;
-                final DisplayContent displayContent = getDisplayContentLocked(displayId);
-                if (displayContent != null) {
-                    width = Math.min(Math.max(width, MIN_WIDTH),
-                            displayContent.mInitialDisplayWidth * MAX_SCALE);
-                    height = Math.min(Math.max(height, MIN_HEIGHT),
-                            displayContent.mInitialDisplayHeight * MAX_SCALE);
-                    setForcedDisplaySizeLocked(displayContent, width, height);
-                    Settings.Global.putString(mContext.getContentResolver(),
-                            Settings.Global.DISPLAY_SIZE_FORCED, width + "," + height);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void readForcedDisplaySizeAndDensityLocked(final DisplayContent displayContent) {
-        String sizeStr = Settings.Global.getString(mContext.getContentResolver(),
-                Settings.Global.DISPLAY_SIZE_FORCED);
-        if (sizeStr == null || sizeStr.length() == 0) {
-            sizeStr = SystemProperties.get(SIZE_OVERRIDE, null);
-        }
-        if (sizeStr != null && sizeStr.length() > 0) {
-            final int pos = sizeStr.indexOf(',');
-            if (pos > 0 && sizeStr.lastIndexOf(',') == pos) {
-                int width, height;
-                try {
-                    width = Integer.parseInt(sizeStr.substring(0, pos));
-                    height = Integer.parseInt(sizeStr.substring(pos+1));
-                    synchronized(displayContent.mDisplaySizeLock) {
-                        if (displayContent.mBaseDisplayWidth != width
-                                || displayContent.mBaseDisplayHeight != height) {
-                            Slog.i(TAG, "FORCED DISPLAY SIZE: " + width + "x" + height);
-                            displayContent.mBaseDisplayWidth = width;
-                            displayContent.mBaseDisplayHeight = height;
-                        }
-                    }
-                } catch (NumberFormatException ex) {
-                }
-            }
-        }
-        String densityStr = Settings.Global.getString(mContext.getContentResolver(),
-                Settings.Global.DISPLAY_DENSITY_FORCED);
-        if (densityStr == null || densityStr.length() == 0) {
-            densityStr = SystemProperties.get(DENSITY_OVERRIDE, null);
-        }
-        if (densityStr != null && densityStr.length() > 0) {
-            int density;
-            try {
-                density = Integer.parseInt(densityStr);
-                synchronized(displayContent.mDisplaySizeLock) {
-                    if (displayContent.mBaseDisplayDensity != density) {
-                        Slog.i(TAG, "FORCED DISPLAY DENSITY: " + density);
-                        displayContent.mBaseDisplayDensity = density;
-                    }
-                }
-            } catch (NumberFormatException ex) {
-            }
-        }
-    }
-
-    // displayContent must not be null
-    private void setForcedDisplaySizeLocked(DisplayContent displayContent, int width, int height) {
-        Slog.i(TAG, "Using new display size: " + width + "x" + height);
-
-        synchronized(displayContent.mDisplaySizeLock) {
-            displayContent.mBaseDisplayWidth = width;
-            displayContent.mBaseDisplayHeight = height;
-        }
-        reconfigureDisplayLocked(displayContent);
-    }
-
-    @Override
-    public void clearForcedDisplaySize(int displayId) {
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
-                PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Must hold permission " +
-                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
-        }
-        if (displayId != Display.DEFAULT_DISPLAY) {
-            throw new IllegalArgumentException("Can only set the default display");
-        }
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                final DisplayContent displayContent = getDisplayContentLocked(displayId);
-                if (displayContent != null) {
-                    setForcedDisplaySizeLocked(displayContent, displayContent.mInitialDisplayWidth,
-                            displayContent.mInitialDisplayHeight);
-                    Settings.Global.putString(mContext.getContentResolver(),
-                            Settings.Global.DISPLAY_SIZE_FORCED, "");
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    @Override
-    public int getInitialDisplayDensity(int displayId) {
-        synchronized (mWindowMap) {
-            final DisplayContent displayContent = getDisplayContentLocked(displayId);
-            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
-                synchronized(displayContent.mDisplaySizeLock) {
-                    return displayContent.mInitialDisplayDensity;
-                }
-            }
-        }
-        return -1;
-    }
-
-    @Override
-    public int getBaseDisplayDensity(int displayId) {
-        synchronized (mWindowMap) {
-            final DisplayContent displayContent = getDisplayContentLocked(displayId);
-            if (displayContent != null && displayContent.hasAccess(Binder.getCallingUid())) {
-                synchronized(displayContent.mDisplaySizeLock) {
-                    return displayContent.mBaseDisplayDensity;
-                }
-            }
-        }
-        return -1;
-    }
-
-    @Override
-    public void setForcedDisplayDensity(int displayId, int density) {
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
-                PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Must hold permission " +
-                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
-        }
-        if (displayId != Display.DEFAULT_DISPLAY) {
-            throw new IllegalArgumentException("Can only set the default display");
-        }
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                final DisplayContent displayContent = getDisplayContentLocked(displayId);
-                if (displayContent != null) {
-                    setForcedDisplayDensityLocked(displayContent, density);
-                    Settings.Global.putString(mContext.getContentResolver(),
-                            Settings.Global.DISPLAY_DENSITY_FORCED, Integer.toString(density));
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    // displayContent must not be null
-    private void setForcedDisplayDensityLocked(DisplayContent displayContent, int density) {
-        Slog.i(TAG, "Using new display density: " + density);
-
-        synchronized(displayContent.mDisplaySizeLock) {
-            displayContent.mBaseDisplayDensity = density;
-        }
-        reconfigureDisplayLocked(displayContent);
-    }
-
-    @Override
-    public void clearForcedDisplayDensity(int displayId) {
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
-                PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Must hold permission " +
-                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
-        }
-        if (displayId != Display.DEFAULT_DISPLAY) {
-            throw new IllegalArgumentException("Can only set the default display");
-        }
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                final DisplayContent displayContent = getDisplayContentLocked(displayId);
-                if (displayContent != null) {
-                    setForcedDisplayDensityLocked(displayContent,
-                            displayContent.mInitialDisplayDensity);
-                    Settings.Global.putString(mContext.getContentResolver(),
-                            Settings.Global.DISPLAY_DENSITY_FORCED, "");
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    // displayContent must not be null
-    private void reconfigureDisplayLocked(DisplayContent displayContent) {
-        // TODO: Multidisplay: for now only use with default display.
-        configureDisplayPolicyLocked(displayContent);
-        displayContent.layoutNeeded = true;
-
-        boolean configChanged = updateOrientationFromAppTokensLocked(false);
-        mTempConfiguration.setToDefaults();
-        mTempConfiguration.fontScale = mCurConfiguration.fontScale;
-        if (computeScreenConfigurationLocked(mTempConfiguration)) {
-            if (mCurConfiguration.diff(mTempConfiguration) != 0) {
-                configChanged = true;
-            }
-        }
-
-        if (configChanged) {
-            mWaitingForConfig = true;
-            startFreezingDisplayLocked(false, 0, 0);
-            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-        }
-
-        performLayoutAndPlaceSurfacesLocked();
-    }
-
-    private void configureDisplayPolicyLocked(DisplayContent displayContent) {
-        mPolicy.setInitialDisplaySize(displayContent.getDisplay(),
-                displayContent.mBaseDisplayWidth,
-                displayContent.mBaseDisplayHeight,
-                displayContent.mBaseDisplayDensity);
-
-        DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        mPolicy.setDisplayOverscan(displayContent.getDisplay(),
-                displayInfo.overscanLeft, displayInfo.overscanTop,
-                displayInfo.overscanRight, displayInfo.overscanBottom);
-    }
-
-    @Override
-    public void setOverscan(int displayId, int left, int top, int right, int bottom) {
-        if (mContext.checkCallingOrSelfPermission(
-                android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
-                PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Must hold permission " +
-                    android.Manifest.permission.WRITE_SECURE_SETTINGS);
-        }
-        final long ident = Binder.clearCallingIdentity();
-        try {
-            synchronized(mWindowMap) {
-                DisplayContent displayContent = getDisplayContentLocked(displayId);
-                if (displayContent != null) {
-                    setOverscanLocked(displayContent, left, top, right, bottom);
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(ident);
-        }
-    }
-
-    private void setOverscanLocked(DisplayContent displayContent,
-            int left, int top, int right, int bottom) {
-        final DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        synchronized (displayContent.mDisplaySizeLock) {
-            displayInfo.overscanLeft = left;
-            displayInfo.overscanTop = top;
-            displayInfo.overscanRight = right;
-            displayInfo.overscanBottom = bottom;
-        }
-
-        mDisplaySettings.setOverscanLocked(displayInfo.name, left, top, right, bottom);
-        mDisplaySettings.writeSettingsLocked();
-
-        reconfigureDisplayLocked(displayContent);
-    }
-
-    // -------------------------------------------------------------
-    // Internals
-    // -------------------------------------------------------------
-
-    final WindowState windowForClientLocked(Session session, IWindow client,
-            boolean throwOnError) {
-        return windowForClientLocked(session, client.asBinder(), throwOnError);
-    }
-
-    final WindowState windowForClientLocked(Session session, IBinder client,
-            boolean throwOnError) {
-        WindowState win = mWindowMap.get(client);
-        if (localLOGV) Slog.v(
-            TAG, "Looking up client " + client + ": " + win);
-        if (win == null) {
-            RuntimeException ex = new IllegalArgumentException(
-                    "Requested window " + client + " does not exist");
-            if (throwOnError) {
-                throw ex;
-            }
-            Slog.w(TAG, "Failed looking up window", ex);
-            return null;
-        }
-        if (session != null && win.mSession != session) {
-            RuntimeException ex = new IllegalArgumentException(
-                    "Requested window " + client + " is in session " +
-                    win.mSession + ", not " + session);
-            if (throwOnError) {
-                throw ex;
-            }
-            Slog.w(TAG, "Failed looking up window", ex);
-            return null;
-        }
-
-        return win;
-    }
-
-    final void rebuildAppWindowListLocked() {
-        // TODO: Multidisplay, when ActivityStacks and tasks exist on more than one display.
-        rebuildAppWindowListLocked(getDefaultDisplayContentLocked());
-    }
-
-    private void rebuildAppWindowListLocked(final DisplayContent displayContent) {
-        final WindowList windows = displayContent.getWindowList();
-        int NW = windows.size();
-        int i;
-        int lastBelow = -1;
-        int numRemoved = 0;
-
-        if (mRebuildTmp.length < NW) {
-            mRebuildTmp = new WindowState[NW+10];
-        }
-
-        // First remove all existing app windows.
-        i=0;
-        while (i < NW) {
-            WindowState w = windows.get(i);
-            if (w.mAppToken != null) {
-                WindowState win = windows.remove(i);
-                win.mRebuilding = true;
-                mRebuildTmp[numRemoved] = win;
-                mWindowsChanged = true;
-                if (DEBUG_WINDOW_MOVEMENT) Slog.v(TAG, "Rebuild removing window: " + win);
-                NW--;
-                numRemoved++;
-                continue;
-            } else if (lastBelow == i-1) {
-                if (w.mAttrs.type == TYPE_WALLPAPER || w.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) {
-                    lastBelow = i;
-                }
-            }
-            i++;
-        }
-
-        // Keep whatever windows were below the app windows still below,
-        // by skipping them.
-        lastBelow++;
-        i = lastBelow;
-
-        // First add all of the exiting app tokens...  these are no longer
-        // in the main app list, but still have windows shown.  We put them
-        // in the back because now that the animation is over we no longer
-        // will care about them.
-        AppTokenList exitingAppTokens = displayContent.mExitingAppTokens;
-        int NT = exitingAppTokens.size();
-        for (int j=0; j<NT; j++) {
-            i = reAddAppWindowsLocked(displayContent, i, exitingAppTokens.get(j));
-        }
-
-        // And add in the still active app tokens in Z order.
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        final int numTasks = tasks.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int numTokens = tokens.size();
-            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
-                final AppWindowToken wtoken = tokens.get(tokenNdx);
-                i = reAddAppWindowsLocked(displayContent, i, wtoken);
-            }
-        }
-
-        i -= lastBelow;
-        if (i != numRemoved) {
-            Slog.w(TAG, "Rebuild removed " + numRemoved + " windows but added " + i,
-                    new RuntimeException("here").fillInStackTrace());
-            for (i=0; i<numRemoved; i++) {
-                WindowState ws = mRebuildTmp[i];
-                if (ws.mRebuilding) {
-                    StringWriter sw = new StringWriter();
-                    PrintWriter pw = new FastPrintWriter(sw, false, 1024);
-                    ws.dump(pw, "", true);
-                    pw.flush();
-                    Slog.w(TAG, "This window was lost: " + ws);
-                    Slog.w(TAG, sw.toString());
-                    ws.mWinAnimator.destroySurfaceLocked();
-                }
-            }
-            Slog.w(TAG, "Current app token list:");
-            dumpAppTokensLocked();
-            Slog.w(TAG, "Final window list:");
-            dumpWindowsLocked();
-        }
-    }
-
-    private final void assignLayersLocked(WindowList windows) {
-        int N = windows.size();
-        int curBaseLayer = 0;
-        int curLayer = 0;
-        int i;
-
-        if (DEBUG_LAYERS) Slog.v(TAG, "Assigning layers based on windows=" + windows,
-                new RuntimeException("here").fillInStackTrace());
-
-        boolean anyLayerChanged = false;
-
-        for (i=0; i<N; i++) {
-            final WindowState w = windows.get(i);
-            final WindowStateAnimator winAnimator = w.mWinAnimator;
-            boolean layerChanged = false;
-            int oldLayer = w.mLayer;
-            if (w.mBaseLayer == curBaseLayer || w.mIsImWindow
-                    || (i > 0 && w.mIsWallpaper)) {
-                curLayer += WINDOW_LAYER_MULTIPLIER;
-                w.mLayer = curLayer;
-            } else {
-                curBaseLayer = curLayer = w.mBaseLayer;
-                w.mLayer = curLayer;
-            }
-            if (w.mLayer != oldLayer) {
-                layerChanged = true;
-                anyLayerChanged = true;
-            }
-            final AppWindowToken wtoken = w.mAppToken;
-            oldLayer = winAnimator.mAnimLayer;
-            if (w.mTargetAppToken != null) {
-                winAnimator.mAnimLayer =
-                        w.mLayer + w.mTargetAppToken.mAppAnimator.animLayerAdjustment;
-            } else if (wtoken != null) {
-                winAnimator.mAnimLayer =
-                        w.mLayer + wtoken.mAppAnimator.animLayerAdjustment;
-            } else {
-                winAnimator.mAnimLayer = w.mLayer;
-            }
-            if (w.mIsImWindow) {
-                winAnimator.mAnimLayer += mInputMethodAnimLayerAdjustment;
-            } else if (w.mIsWallpaper) {
-                winAnimator.mAnimLayer += mWallpaperAnimLayerAdjustment;
-            }
-            if (winAnimator.mAnimLayer != oldLayer) {
-                layerChanged = true;
-                anyLayerChanged = true;
-            }
-            if (layerChanged && w.getStack().isDimming(winAnimator)) {
-                // Force an animation pass just to update the mDimLayer layer.
-                scheduleAnimationLocked();
-            }
-            if (DEBUG_LAYERS) Slog.v(TAG, "Assign layer " + w + ": "
-                    + "mBase=" + w.mBaseLayer
-                    + " mLayer=" + w.mLayer
-                    + (wtoken == null ?
-                            "" : " mAppLayer=" + wtoken.mAppAnimator.animLayerAdjustment)
-                    + " =mAnimLayer=" + winAnimator.mAnimLayer);
-            //System.out.println(
-            //    "Assigned layer " + curLayer + " to " + w.mClient.asBinder());
-        }
-
-        //TODO (multidisplay): Magnification is supported only for the default display.
-        if (mDisplayMagnifier != null && anyLayerChanged
-                && windows.get(windows.size() - 1).getDisplayId() == Display.DEFAULT_DISPLAY) {
-            mDisplayMagnifier.onWindowLayersChangedLocked();
-        }
-    }
-
-    private final void performLayoutAndPlaceSurfacesLocked() {
-        int loopCount = 6;
-        do {
-            mTraversalScheduled = false;
-            performLayoutAndPlaceSurfacesLockedLoop();
-            mH.removeMessages(H.DO_TRAVERSAL);
-            loopCount--;
-        } while (mTraversalScheduled && loopCount > 0);
-        mInnerFields.mWallpaperActionPending = false;
-    }
-
-    private boolean mInLayout = false;
-    private final void performLayoutAndPlaceSurfacesLockedLoop() {
-        if (mInLayout) {
-            if (DEBUG) {
-                throw new RuntimeException("Recursive call!");
-            }
-            Slog.w(TAG, "performLayoutAndPlaceSurfacesLocked called while in layout. Callers="
-                    + Debug.getCallers(3));
-            return;
-        }
-
-        if (mWaitingForConfig) {
-            // Our configuration has changed (most likely rotation), but we
-            // don't yet have the complete configuration to report to
-            // applications.  Don't do any window layout until we have it.
-            return;
-        }
-
-        if (!mDisplayReady) {
-            // Not yet initialized, nothing to do.
-            return;
-        }
-
-        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmLayout");
-        mInLayout = true;
-        boolean recoveringMemory = false;
-
-        try {
-            if (mForceRemoves != null) {
-                recoveringMemory = true;
-                // Wait a little bit for things to settle down, and off we go.
-                for (int i=0; i<mForceRemoves.size(); i++) {
-                    WindowState ws = mForceRemoves.get(i);
-                    Slog.i(TAG, "Force removing: " + ws);
-                    removeWindowInnerLocked(ws.mSession, ws);
-                }
-                mForceRemoves = null;
-                Slog.w(TAG, "Due to memory failure, waiting a bit for next layout");
-                Object tmp = new Object();
-                synchronized (tmp) {
-                    try {
-                        tmp.wait(250);
-                    } catch (InterruptedException e) {
-                    }
-                }
-            }
-        } catch (RuntimeException e) {
-            Log.wtf(TAG, "Unhandled exception while force removing for memory", e);
-        }
-
-        try {
-            performLayoutAndPlaceSurfacesLockedInner(recoveringMemory);
-
-            mInLayout = false;
-
-            if (needsLayout()) {
-                if (++mLayoutRepeatCount < 6) {
-                    requestTraversalLocked();
-                } else {
-                    Slog.e(TAG, "Performed 6 layouts in a row. Skipping");
-                    mLayoutRepeatCount = 0;
-                }
-            } else {
-                mLayoutRepeatCount = 0;
-            }
-
-            if (mWindowsChanged && !mWindowChangeListeners.isEmpty()) {
-                mH.removeMessages(H.REPORT_WINDOWS_CHANGE);
-                mH.sendEmptyMessage(H.REPORT_WINDOWS_CHANGE);
-            }
-        } catch (RuntimeException e) {
-            mInLayout = false;
-            Log.wtf(TAG, "Unhandled exception while laying out windows", e);
-        }
-
-        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
-    }
-
-    private final void performLayoutLockedInner(final DisplayContent displayContent,
-                                    boolean initial, boolean updateInputWindows) {
-        if (!displayContent.layoutNeeded) {
-            return;
-        }
-        displayContent.layoutNeeded = false;
-        WindowList windows = displayContent.getWindowList();
-        boolean isDefaultDisplay = displayContent.isDefaultDisplay;
-
-        DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        final int dw = displayInfo.logicalWidth;
-        final int dh = displayInfo.logicalHeight;
-
-        final int NFW = mFakeWindows.size();
-        for (int i=0; i<NFW; i++) {
-            mFakeWindows.get(i).layout(dw, dh);
-        }
-
-        final int N = windows.size();
-        int i;
-
-        if (DEBUG_LAYOUT) {
-            Slog.v(TAG, "-------------------------------------");
-            Slog.v(TAG, "performLayout: needed="
-                    + displayContent.layoutNeeded + " dw=" + dw + " dh=" + dh);
-        }
-
-        WindowStateAnimator universeBackground = null;
-
-        mPolicy.beginLayoutLw(isDefaultDisplay, dw, dh, mRotation);
-        if (isDefaultDisplay) {
-            // Not needed on non-default displays.
-            mSystemDecorLayer = mPolicy.getSystemDecorLayerLw();
-            mScreenRect.set(0, 0, dw, dh);
-        }
-
-        mPolicy.getContentRectLw(mTmpContentRect);
-        displayContent.setStackBoxSize(mTmpContentRect);
-
-        int seq = mLayoutSeq+1;
-        if (seq < 0) seq = 0;
-        mLayoutSeq = seq;
-
-        boolean behindDream = false;
-
-        // First perform layout of any root windows (not attached
-        // to another window).
-        int topAttached = -1;
-        for (i = N-1; i >= 0; i--) {
-            final WindowState win = windows.get(i);
-
-            // Don't do layout of a window if it is not visible, or
-            // soon won't be visible, to avoid wasting time and funky
-            // changes while a window is animating away.
-            final boolean gone = (behindDream && mPolicy.canBeForceHidden(win, win.mAttrs))
-                    || win.isGoneForLayoutLw();
-
-            if (DEBUG_LAYOUT && !win.mLayoutAttached) {
-                Slog.v(TAG, "1ST PASS " + win
-                        + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame
-                        + " mLayoutAttached=" + win.mLayoutAttached
-                        + " screen changed=" + win.isConfigChanged());
-                final AppWindowToken atoken = win.mAppToken;
-                if (gone) Slog.v(TAG, "  GONE: mViewVisibility="
-                        + win.mViewVisibility + " mRelayoutCalled="
-                        + win.mRelayoutCalled + " hidden="
-                        + win.mRootToken.hidden + " hiddenRequested="
-                        + (atoken != null && atoken.hiddenRequested)
-                        + " mAttachedHidden=" + win.mAttachedHidden);
-                else Slog.v(TAG, "  VIS: mViewVisibility="
-                        + win.mViewVisibility + " mRelayoutCalled="
-                        + win.mRelayoutCalled + " hidden="
-                        + win.mRootToken.hidden + " hiddenRequested="
-                        + (atoken != null && atoken.hiddenRequested)
-                        + " mAttachedHidden=" + win.mAttachedHidden);
-            }
-
-            // If this view is GONE, then skip it -- keep the current
-            // frame, and let the caller know so they can ignore it
-            // if they want.  (We do the normal layout for INVISIBLE
-            // windows, since that means "perform layout as normal,
-            // just don't display").
-            if (!gone || !win.mHaveFrame || win.mLayoutNeeded
-                    || ((win.isConfigChanged() || win.setInsetsChanged()) &&
-                            (win.mAttrs.type == TYPE_KEYGUARD ||
-                            win.mAppToken != null && win.mAppToken.layoutConfigChanges))
-                    || win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) {
-                if (!win.mLayoutAttached) {
-                    if (initial) {
-                        //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
-                        win.mContentChanged = false;
-                    }
-                    if (win.mAttrs.type == TYPE_DREAM) {
-                        // Don't layout windows behind a dream, so that if it
-                        // does stuff like hide the status bar we won't get a
-                        // bad transition when it goes away.
-                        behindDream = true;
-                    }
-                    win.mLayoutNeeded = false;
-                    win.prelayout();
-                    mPolicy.layoutWindowLw(win, win.mAttrs, null);
-                    win.mLayoutSeq = seq;
-                    if (DEBUG_LAYOUT) Slog.v(TAG, "  LAYOUT: mFrame="
-                            + win.mFrame + " mContainingFrame="
-                            + win.mContainingFrame + " mDisplayFrame="
-                            + win.mDisplayFrame);
-                } else {
-                    if (topAttached < 0) topAttached = i;
-                }
-            }
-            if (win.mViewVisibility == View.VISIBLE
-                    && win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND
-                    && universeBackground == null) {
-                universeBackground = win.mWinAnimator;
-            }
-        }
-
-        if (mAnimator.mUniverseBackground  != universeBackground) {
-            mFocusMayChange = true;
-            mAnimator.mUniverseBackground = universeBackground;
-        }
-
-        boolean attachedBehindDream = false;
-
-        // Now perform layout of attached windows, which usually
-        // depend on the position of the window they are attached to.
-        // XXX does not deal with windows that are attached to windows
-        // that are themselves attached.
-        for (i = topAttached; i >= 0; i--) {
-            final WindowState win = windows.get(i);
-
-            if (win.mLayoutAttached) {
-                if (DEBUG_LAYOUT) Slog.v(TAG, "2ND PASS " + win
-                        + " mHaveFrame=" + win.mHaveFrame
-                        + " mViewVisibility=" + win.mViewVisibility
-                        + " mRelayoutCalled=" + win.mRelayoutCalled);
-                // If this view is GONE, then skip it -- keep the current
-                // frame, and let the caller know so they can ignore it
-                // if they want.  (We do the normal layout for INVISIBLE
-                // windows, since that means "perform layout as normal,
-                // just don't display").
-                if (attachedBehindDream && mPolicy.canBeForceHidden(win, win.mAttrs)) {
-                    continue;
-                }
-                if ((win.mViewVisibility != View.GONE && win.mRelayoutCalled)
-                        || !win.mHaveFrame || win.mLayoutNeeded) {
-                    if (initial) {
-                        //Slog.i(TAG, "Window " + this + " clearing mContentChanged - initial");
-                        win.mContentChanged = false;
-                    }
-                    win.mLayoutNeeded = false;
-                    win.prelayout();
-                    mPolicy.layoutWindowLw(win, win.mAttrs, win.mAttachedWindow);
-                    win.mLayoutSeq = seq;
-                    if (DEBUG_LAYOUT) Slog.v(TAG, "  LAYOUT: mFrame="
-                            + win.mFrame + " mContainingFrame="
-                            + win.mContainingFrame + " mDisplayFrame="
-                            + win.mDisplayFrame);
-                }
-            } else if (win.mAttrs.type == TYPE_DREAM) {
-                // Don't layout windows behind a dream, so that if it
-                // does stuff like hide the status bar we won't get a
-                // bad transition when it goes away.
-                attachedBehindDream = behindDream;
-            }
-        }
-
-        // Window frames may have changed.  Tell the input dispatcher about it.
-        mInputMonitor.setUpdateInputWindowsNeededLw();
-        if (updateInputWindows) {
-            mInputMonitor.updateInputWindowsLw(false /*force*/);
-        }
-
-        mPolicy.finishLayoutLw();
-    }
-
-    void makeWindowFreezingScreenIfNeededLocked(WindowState w) {
-        // If the screen is currently frozen or off, then keep
-        // it frozen/off until this window draws at its new
-        // orientation.
-        if (!okToDisplay()) {
-            if (DEBUG_ORIENTATION) Slog.v(TAG,
-                    "Changing surface while display frozen: " + w);
-            w.mOrientationChanging = true;
-            w.mLastFreezeDuration = 0;
-            mInnerFields.mOrientationChangeComplete = false;
-            if (!mWindowsFreezingScreen) {
-                mWindowsFreezingScreen = true;
-                // XXX should probably keep timeout from
-                // when we first froze the display.
-                mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
-                mH.sendEmptyMessageDelayed(H.WINDOW_FREEZE_TIMEOUT,
-                        WINDOW_FREEZE_TIMEOUT_DURATION);
-            }
-        }
-    }
-
-    /**
-     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
-     * @param windows List of windows on default display.
-     * @return bitmap indicating if another pass through layout must be made.
-     */
-    public int handleAppTransitionReadyLocked(WindowList windows) {
-        int changes = 0;
-        int i;
-        int NN = mOpeningApps.size();
-        boolean goodToGo = true;
-        if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
-                "Checking " + NN + " opening apps (frozen="
-                + mDisplayFrozen + " timeout="
-                + mAppTransition.isTimeout() + ")...");
-        if (!mDisplayFrozen && !mAppTransition.isTimeout()) {
-            // If the display isn't frozen, wait to do anything until
-            // all of the apps are ready.  Otherwise just go because
-            // we'll unfreeze the display when everyone is ready.
-            for (i=0; i<NN && goodToGo; i++) {
-                AppWindowToken wtoken = mOpeningApps.get(i);
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
-                        "Check opening app=" + wtoken + ": allDrawn="
-                        + wtoken.allDrawn + " startingDisplayed="
-                        + wtoken.startingDisplayed + " startingMoved="
-                        + wtoken.startingMoved);
-                if (!wtoken.allDrawn && !wtoken.startingDisplayed
-                        && !wtoken.startingMoved) {
-                    goodToGo = false;
-                }
-            }
-        }
-        if (goodToGo) {
-            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "**** GOOD TO GO");
-            int transit = mAppTransition.getAppTransition();
-            if (mSkipAppTransitionAnimation) {
-                transit = AppTransition.TRANSIT_UNSET;
-            }
-            mAppTransition.goodToGo();
-            mStartingIconInTransition = false;
-            mSkipAppTransitionAnimation = false;
-
-            mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
-
-            rebuildAppWindowListLocked();
-
-            // if wallpaper is animating in or out set oldWallpaper to null else to wallpaper
-            WindowState oldWallpaper =
-                    mWallpaperTarget != null && mWallpaperTarget.mWinAnimator.isAnimating()
-                        && !mWallpaperTarget.mWinAnimator.isDummyAnimation()
-                    ? null : mWallpaperTarget;
-
-            mInnerFields.mWallpaperMayChange = false;
-
-            // The top-most window will supply the layout params,
-            // and we will determine it below.
-            LayoutParams animLp = null;
-            int bestAnimLayer = -1;
-            boolean fullscreenAnim = false;
-
-            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
-                    "New wallpaper target=" + mWallpaperTarget
-                    + ", oldWallpaper=" + oldWallpaper
-                    + ", lower target=" + mLowerWallpaperTarget
-                    + ", upper target=" + mUpperWallpaperTarget);
-
-            boolean openingAppHasWallpaper = false;
-            boolean closingAppHasWallpaper = false;
-            final AppWindowToken lowerWallpaperAppToken;
-            final AppWindowToken upperWallpaperAppToken;
-            if (mLowerWallpaperTarget == null) {
-                lowerWallpaperAppToken = upperWallpaperAppToken = null;
-            } else {
-                lowerWallpaperAppToken = mLowerWallpaperTarget.mAppToken;
-                upperWallpaperAppToken = mUpperWallpaperTarget.mAppToken;
-            }
-
-            // Do a first pass through the tokens for two
-            // things:
-            // (1) Determine if both the closing and opening
-            // app token sets are wallpaper targets, in which
-            // case special animations are needed
-            // (since the wallpaper needs to stay static
-            // behind them).
-            // (2) Find the layout params of the top-most
-            // application window in the tokens, which is
-            // what will control the animation theme.
-            final int NC = mClosingApps.size();
-            NN = NC + mOpeningApps.size();
-            for (i=0; i<NN; i++) {
-                final AppWindowToken wtoken;
-                if (i < NC) {
-                    wtoken = mClosingApps.get(i);
-                    if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
-                        closingAppHasWallpaper = true;
-                    }
-                } else {
-                    wtoken = mOpeningApps.get(i - NC);
-                    if (wtoken == lowerWallpaperAppToken || wtoken == upperWallpaperAppToken) {
-                        openingAppHasWallpaper = true;
-                    }
-                }
-
-                if (wtoken.appFullscreen) {
-                    WindowState ws = wtoken.findMainWindow();
-                    if (ws != null) {
-                        animLp = ws.mAttrs;
-                        bestAnimLayer = ws.mLayer;
-                        fullscreenAnim = true;
-                    }
-                } else if (!fullscreenAnim) {
-                    WindowState ws = wtoken.findMainWindow();
-                    if (ws != null) {
-                        if (ws.mLayer > bestAnimLayer) {
-                            animLp = ws.mAttrs;
-                            bestAnimLayer = ws.mLayer;
-                        }
-                    }
-                }
-            }
-
-            mAnimateWallpaperWithTarget = false;
-            if (closingAppHasWallpaper && openingAppHasWallpaper) {
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Wallpaper animation!");
-                switch (transit) {
-                    case AppTransition.TRANSIT_ACTIVITY_OPEN:
-                    case AppTransition.TRANSIT_TASK_OPEN:
-                    case AppTransition.TRANSIT_TASK_TO_FRONT:
-                        transit = AppTransition.TRANSIT_WALLPAPER_INTRA_OPEN;
-                        break;
-                    case AppTransition.TRANSIT_ACTIVITY_CLOSE:
-                    case AppTransition.TRANSIT_TASK_CLOSE:
-                    case AppTransition.TRANSIT_TASK_TO_BACK:
-                        transit = AppTransition.TRANSIT_WALLPAPER_INTRA_CLOSE;
-                        break;
-                }
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "New transit: " + transit);
-            } else if ((oldWallpaper != null) && !mOpeningApps.isEmpty()
-                    && !mOpeningApps.contains(oldWallpaper.mAppToken)) {
-                // We are transitioning from an activity with
-                // a wallpaper to one without.
-                transit = AppTransition.TRANSIT_WALLPAPER_CLOSE;
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
-                        "New transit away from wallpaper: " + transit);
-            } else if (mWallpaperTarget != null && mWallpaperTarget.isVisibleLw()) {
-                // We are transitioning from an activity without
-                // a wallpaper to now showing the wallpaper
-                transit = AppTransition.TRANSIT_WALLPAPER_OPEN;
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
-                        "New transit into wallpaper: " + transit);
-            } else {
-                mAnimateWallpaperWithTarget = true;
-            }
-
-            // If all closing windows are obscured, then there is
-            // no need to do an animation.  This is the case, for
-            // example, when this transition is being done behind
-            // the lock screen.
-            if (!mPolicy.allowAppAnimationsLw()) {
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG,
-                        "Animations disallowed by keyguard or dream.");
-                animLp = null;
-            }
-
-            AppWindowToken topOpeningApp = null;
-            int topOpeningLayer = 0;
-
-            NN = mOpeningApps.size();
-            for (i=0; i<NN; i++) {
-                AppWindowToken wtoken = mOpeningApps.get(i);
-                final AppWindowAnimator appAnimator = wtoken.mAppAnimator;
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now opening app" + wtoken);
-                appAnimator.clearThumbnail();
-                wtoken.inPendingTransaction = false;
-                appAnimator.animation = null;
-                setTokenVisibilityLocked(wtoken, animLp, true, transit, false);
-                wtoken.updateReportedVisibilityLocked();
-                wtoken.waitingToShow = false;
-
-                appAnimator.mAllAppWinAnimators.clear();
-                final int N = wtoken.allAppWindows.size();
-                for (int j = 0; j < N; j++) {
-                    appAnimator.mAllAppWinAnimators.add(wtoken.allAppWindows.get(j).mWinAnimator);
-                }
-                mAnimator.mAnimating |= appAnimator.showAllWindowsLocked();
-
-                if (animLp != null) {
-                    int layer = -1;
-                    for (int j=0; j<wtoken.windows.size(); j++) {
-                        WindowState win = wtoken.windows.get(j);
-                        if (win.mWinAnimator.mAnimLayer > layer) {
-                            layer = win.mWinAnimator.mAnimLayer;
-                        }
-                    }
-                    if (topOpeningApp == null || layer > topOpeningLayer) {
-                        topOpeningApp = wtoken;
-                        topOpeningLayer = layer;
-                    }
-                }
-            }
-            NN = mClosingApps.size();
-            for (i=0; i<NN; i++) {
-                AppWindowToken wtoken = mClosingApps.get(i);
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG, "Now closing app " + wtoken);
-                wtoken.mAppAnimator.clearThumbnail();
-                wtoken.inPendingTransaction = false;
-                wtoken.mAppAnimator.animation = null;
-                setTokenVisibilityLocked(wtoken, animLp, false, transit, false);
-                wtoken.updateReportedVisibilityLocked();
-                wtoken.waitingToHide = false;
-                // Force the allDrawn flag, because we want to start
-                // this guy's animations regardless of whether it's
-                // gotten drawn.
-                wtoken.allDrawn = true;
-                wtoken.deferClearAllDrawn = false;
-            }
-
-            AppWindowAnimator appAnimator =
-                    topOpeningApp == null ? null : topOpeningApp.mAppAnimator;
-            Bitmap nextAppTransitionThumbnail = mAppTransition.getNextAppTransitionThumbnail();
-            if (nextAppTransitionThumbnail != null && appAnimator != null
-                    && appAnimator.animation != null) {
-                // This thumbnail animation is very special, we need to have
-                // an extra surface with the thumbnail included with the animation.
-                Rect dirty = new Rect(0, 0, nextAppTransitionThumbnail.getWidth(),
-                        nextAppTransitionThumbnail.getHeight());
-                try {
-                    // TODO(multi-display): support other displays
-                    final DisplayContent displayContent = getDefaultDisplayContentLocked();
-                    final Display display = displayContent.getDisplay();
-                    SurfaceControl surfaceControl = new SurfaceControl(mFxSession,
-                            "thumbnail anim",
-                            dirty.width(), dirty.height(),
-                            PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
-                    surfaceControl.setLayerStack(display.getLayerStack());
-                    appAnimator.thumbnail = surfaceControl;
-                    if (SHOW_TRANSACTIONS) Slog.i(TAG, "  THUMBNAIL " + surfaceControl + ": CREATE");
-                    Surface drawSurface = new Surface();
-                    drawSurface.copyFrom(surfaceControl);
-                    Canvas c = drawSurface.lockCanvas(dirty);
-                    c.drawBitmap(nextAppTransitionThumbnail, 0, 0, null);
-                    drawSurface.unlockCanvasAndPost(c);
-                    drawSurface.release();
-                    appAnimator.thumbnailLayer = topOpeningLayer;
-                    DisplayInfo displayInfo = getDefaultDisplayInfoLocked();
-                    Animation anim = mAppTransition.createThumbnailAnimationLocked(
-                            transit, true, true, displayInfo.appWidth, displayInfo.appHeight);
-                    appAnimator.thumbnailAnimation = anim;
-                    anim.restrictDuration(MAX_ANIMATION_DURATION);
-                    anim.scaleCurrentDuration(mTransitionAnimationScale);
-                    Point p = new Point();
-                    mAppTransition.getStartingPoint(p);
-                    appAnimator.thumbnailX = p.x;
-                    appAnimator.thumbnailY = p.y;
-                } catch (OutOfResourcesException e) {
-                    Slog.e(TAG, "Can't allocate thumbnail/Canvas surface w=" + dirty.width()
-                            + " h=" + dirty.height(), e);
-                    appAnimator.clearThumbnail();
-                }
-            }
-
-            mAppTransition.postAnimationCallback();
-            mAppTransition.clear();
-
-            mOpeningApps.clear();
-            mClosingApps.clear();
-
-            // This has changed the visibility of windows, so perform
-            // a new layout to get them all up-to-date.
-            changes |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT
-                    | WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG;
-            getDefaultDisplayContentLocked().layoutNeeded = true;
-
-            // TODO(multidisplay): IMEs are only supported on the default display.
-            if (windows == getDefaultWindowListLocked()
-                    && !moveInputMethodWindowsIfNeededLocked(true)) {
-                assignLayersLocked(windows);
-            }
-            updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false /*updateInputWindows*/);
-            mFocusMayChange = false;
-        }
-
-        return changes;
-    }
-
-    /**
-     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
-     * @return bitmap indicating if another pass through layout must be made.
-     */
-    private int handleAnimatingStoppedAndTransitionLocked() {
-        int changes = 0;
-
-        mAppTransition.setIdle();
-        // Restore window app tokens to the ActivityManager views
-        final DisplayContent displayContent = getDefaultDisplayContentLocked();
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        final int numTasks = tasks.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int numTokens = tokens.size();
-            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
-                final AppWindowToken wtoken = tokens.get(tokenNdx);
-                wtoken.sendingToBottom = false;
-            }
-        }
-        rebuildAppWindowListLocked();
-
-        changes |= PhoneWindowManager.FINISH_LAYOUT_REDO_LAYOUT;
-        if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
-                "Wallpaper layer changed: assigning layers + relayout");
-        moveInputMethodWindowsIfNeededLocked(true);
-        mInnerFields.mWallpaperMayChange = true;
-        // Since the window list has been rebuilt, focus might
-        // have to be recomputed since the actual order of windows
-        // might have changed again.
-        mFocusMayChange = true;
-
-        return changes;
-    }
-
-    private void updateResizingWindows(final WindowState w) {
-        final WindowStateAnimator winAnimator = w.mWinAnimator;
-        if (w.mHasSurface && w.mLayoutSeq == mLayoutSeq) {
-            w.setInsetsChanged();
-            boolean configChanged = w.isConfigChanged();
-            if (DEBUG_CONFIGURATION && configChanged) {
-                Slog.v(TAG, "Win " + w + " config changed: "
-                        + mCurConfiguration);
-            }
-            if (localLOGV) Slog.v(TAG, "Resizing " + w
-                    + ": configChanged=" + configChanged
-                    + " last=" + w.mLastFrame + " frame=" + w.mFrame);
-            w.mLastFrame.set(w.mFrame);
-            if (w.mContentInsetsChanged
-                    || w.mVisibleInsetsChanged
-                    || winAnimator.mSurfaceResized
-                    || configChanged) {
-                if (DEBUG_RESIZE || DEBUG_ORIENTATION) {
-                    Slog.v(TAG, "Resize reasons for w=" + w + ": "
-                            + " contentInsetsChanged=" + w.mContentInsetsChanged
-                            + " " + w.mContentInsets.toShortString()
-                            + " visibleInsetsChanged=" + w.mVisibleInsetsChanged
-                            + " " + w.mVisibleInsets.toShortString()
-                            + " surfaceResized=" + winAnimator.mSurfaceResized
-                            + " configChanged=" + configChanged);
-                }
-
-                w.mLastOverscanInsets.set(w.mOverscanInsets);
-                w.mLastContentInsets.set(w.mContentInsets);
-                w.mLastVisibleInsets.set(w.mVisibleInsets);
-                makeWindowFreezingScreenIfNeededLocked(w);
-                // If the orientation is changing, then we need to
-                // hold off on unfreezing the display until this
-                // window has been redrawn; to do that, we need
-                // to go through the process of getting informed
-                // by the application when it has finished drawing.
-                if (w.mOrientationChanging) {
-                    if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || DEBUG_ORIENTATION) Slog.v(TAG,
-                            "Orientation start waiting for draw mDrawState=DRAW_PENDING in "
-                            + w + ", surface " + winAnimator.mSurfaceControl);
-                    winAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
-                    if (w.mAppToken != null) {
-                        w.mAppToken.allDrawn = false;
-                        w.mAppToken.deferClearAllDrawn = false;
-                    }
-                }
-                if (!mResizingWindows.contains(w)) {
-                    if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
-                            "Resizing window " + w + " to " + winAnimator.mSurfaceW
-                            + "x" + winAnimator.mSurfaceH);
-                    mResizingWindows.add(w);
-                }
-            } else if (w.mOrientationChanging) {
-                if (w.isDrawnLw()) {
-                    if (DEBUG_ORIENTATION) Slog.v(TAG,
-                            "Orientation not waiting for draw in "
-                            + w + ", surface " + winAnimator.mSurfaceControl);
-                    w.mOrientationChanging = false;
-                    w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
-                            - mDisplayFreezeTime);
-                }
-            }
-        }
-    }
-
-    /**
-     * Extracted from {@link #performLayoutAndPlaceSurfacesLockedInner} to reduce size of method.
-     *
-     * @param w WindowState this method is applied to.
-     * @param currentTime The time which animations use for calculating transitions.
-     * @param innerDw Width of app window.
-     * @param innerDh Height of app window.
-     */
-    private void handleNotObscuredLocked(final WindowState w, final long currentTime,
-                                         final int innerDw, final int innerDh) {
-        final WindowManager.LayoutParams attrs = w.mAttrs;
-        final int attrFlags = attrs.flags;
-        final boolean canBeSeen = w.isDisplayedLw();
-        final boolean opaqueDrawn = canBeSeen && w.isOpaqueDrawn();
-
-        if (opaqueDrawn && w.isFullscreen(innerDw, innerDh)) {
-            // This window completely covers everything behind it,
-            // so we want to leave all of them as undimmed (for
-            // performance reasons).
-            mInnerFields.mObscured = true;
-        }
-
-        if (w.mHasSurface) {
-            if ((attrFlags&FLAG_KEEP_SCREEN_ON) != 0) {
-                mInnerFields.mHoldScreen = w.mSession;
-            }
-            if (!mInnerFields.mSyswin && w.mAttrs.screenBrightness >= 0
-                    && mInnerFields.mScreenBrightness < 0) {
-                mInnerFields.mScreenBrightness = w.mAttrs.screenBrightness;
-            }
-            if (!mInnerFields.mSyswin && w.mAttrs.buttonBrightness >= 0
-                    && mInnerFields.mButtonBrightness < 0) {
-                mInnerFields.mButtonBrightness = w.mAttrs.buttonBrightness;
-            }
-            if (!mInnerFields.mSyswin && w.mAttrs.userActivityTimeout >= 0
-                    && mInnerFields.mUserActivityTimeout < 0) {
-                mInnerFields.mUserActivityTimeout = w.mAttrs.userActivityTimeout;
-            }
-
-            final int type = attrs.type;
-            if (canBeSeen
-                    && (type == TYPE_SYSTEM_DIALOG
-                     || type == TYPE_RECENTS_OVERLAY
-                     || type == TYPE_KEYGUARD
-                     || type == TYPE_SYSTEM_ERROR)) {
-                mInnerFields.mSyswin = true;
-            }
-
-            if (canBeSeen) {
-                // This function assumes that the contents of the default display are
-                // processed first before secondary displays.
-                if (w.mDisplayContent.isDefaultDisplay) {
-                    // While a dream or keyguard is showing, obscure ordinary application
-                    // content on secondary displays (by forcibly enabling mirroring unless
-                    // there is other content we want to show) but still allow opaque
-                    // keyguard dialogs to be shown.
-                    if (type == TYPE_DREAM || type == TYPE_KEYGUARD) {
-                        mInnerFields.mObscureApplicationContentOnSecondaryDisplays = true;
-                    }
-                    mInnerFields.mDisplayHasContent = true;
-                } else if (!mInnerFields.mObscureApplicationContentOnSecondaryDisplays
-                        || (mInnerFields.mObscured && type == TYPE_KEYGUARD_DIALOG)) {
-                    // Allow full screen keyguard presentation dialogs to be seen.
-                    mInnerFields.mDisplayHasContent = true;
-                }
-            }
-        }
-    }
-
-    private void handleFlagDimBehind(WindowState w, int innerDw, int innerDh) {
-        final WindowManager.LayoutParams attrs = w.mAttrs;
-        if ((attrs.flags & FLAG_DIM_BEHIND) != 0
-                && w.isDisplayedLw()
-                && !w.mExiting) {
-            final WindowStateAnimator winAnimator = w.mWinAnimator;
-            final TaskStack stack = w.getStack();
-            stack.setDimmingTag();
-            if (!stack.isDimming(winAnimator)) {
-                if (localLOGV) Slog.v(TAG, "Win " + w + " start dimming.");
-                stack.startDimmingIfNeeded(winAnimator);
-            }
-        }
-    }
-
-    private void updateAllDrawnLocked(DisplayContent displayContent) {
-        // See if any windows have been drawn, so they (and others
-        // associated with them) can now be shown.
-        final ArrayList<Task> tasks = displayContent.getTasks();
-        final int numTasks = tasks.size();
-        for (int taskNdx = 0; taskNdx < numTasks; ++taskNdx) {
-            final AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-            final int numTokens = tokens.size();
-            for (int tokenNdx = 0; tokenNdx < numTokens; ++tokenNdx) {
-                final AppWindowToken wtoken = tokens.get(tokenNdx);
-                if (!wtoken.allDrawn) {
-                    int numInteresting = wtoken.numInterestingWindows;
-                    if (numInteresting > 0 && wtoken.numDrawnWindows >= numInteresting) {
-                        if (DEBUG_VISIBILITY) Slog.v(TAG,
-                                "allDrawn: " + wtoken
-                                + " interesting=" + numInteresting
-                                + " drawn=" + wtoken.numDrawnWindows);
-                        wtoken.allDrawn = true;
-                        mH.obtainMessage(H.NOTIFY_ACTIVITY_DRAWN, wtoken.token).sendToTarget();
-                    }
-                }
-            }
-        }
-    }
-
-    // "Something has changed!  Let's make it correct now."
-    private final void performLayoutAndPlaceSurfacesLockedInner(boolean recoveringMemory) {
-        if (DEBUG_WINDOW_TRACE) {
-            Slog.v(TAG, "performLayoutAndPlaceSurfacesLockedInner: entry. Called by "
-                    + Debug.getCallers(3));
-        }
-
-        final long currentTime = SystemClock.uptimeMillis();
-
-        int i;
-
-        if (mFocusMayChange) {
-            mFocusMayChange = false;
-            updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
-                    false /*updateInputWindows*/);
-        }
-
-        // Initialize state of exiting tokens.
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-            for (i=displayContent.mExitingTokens.size()-1; i>=0; i--) {
-                displayContent.mExitingTokens.get(i).hasVisible = false;
-            }
-
-            // Initialize state of exiting applications.
-            for (i=displayContent.mExitingAppTokens.size()-1; i>=0; i--) {
-                displayContent.mExitingAppTokens.get(i).hasVisible = false;
-            }
-        }
-
-        mInnerFields.mHoldScreen = null;
-        mInnerFields.mScreenBrightness = -1;
-        mInnerFields.mButtonBrightness = -1;
-        mInnerFields.mUserActivityTimeout = -1;
-        mInnerFields.mObscureApplicationContentOnSecondaryDisplays = false;
-
-        mTransactionSequence++;
-
-        final DisplayContent defaultDisplay = getDefaultDisplayContentLocked();
-        final DisplayInfo defaultInfo = defaultDisplay.getDisplayInfo();
-        final int defaultDw = defaultInfo.logicalWidth;
-        final int defaultDh = defaultInfo.logicalHeight;
-
-        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                ">>> OPEN TRANSACTION performLayoutAndPlaceSurfaces");
-        SurfaceControl.openTransaction();
-        try {
-
-            if (mWatermark != null) {
-                mWatermark.positionSurface(defaultDw, defaultDh);
-            }
-            if (mStrictModeFlash != null) {
-                mStrictModeFlash.positionSurface(defaultDw, defaultDh);
-            }
-
-            boolean focusDisplayed = false;
-
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-                boolean updateAllDrawn = false;
-                WindowList windows = displayContent.getWindowList();
-                DisplayInfo displayInfo = displayContent.getDisplayInfo();
-                final int displayId = displayContent.getDisplayId();
-                final int dw = displayInfo.logicalWidth;
-                final int dh = displayInfo.logicalHeight;
-                final int innerDw = displayInfo.appWidth;
-                final int innerDh = displayInfo.appHeight;
-                final boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
-
-                // Reset for each display.
-                mInnerFields.mDisplayHasContent = false;
-
-                int repeats = 0;
-                do {
-                    repeats++;
-                    if (repeats > 6) {
-                        Slog.w(TAG, "Animation repeat aborted after too many iterations");
-                        displayContent.layoutNeeded = false;
-                        break;
-                    }
-
-                    if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("On entry to LockedInner",
-                        displayContent.pendingLayoutChanges);
-
-                    if ((displayContent.pendingLayoutChanges &
-                            WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER) != 0 &&
-                            (adjustWallpaperWindowsLocked() &
-                                    ADJUST_WALLPAPER_LAYERS_CHANGED) != 0) {
-                        assignLayersLocked(windows);
-                        displayContent.layoutNeeded = true;
-                    }
-
-                    if (isDefaultDisplay && (displayContent.pendingLayoutChanges
-                            & WindowManagerPolicy.FINISH_LAYOUT_REDO_CONFIG) != 0) {
-                        if (DEBUG_LAYOUT) Slog.v(TAG, "Computing new config from layout");
-                        if (updateOrientationFromAppTokensLocked(true)) {
-                            displayContent.layoutNeeded = true;
-                            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-                        }
-                    }
-
-                    if ((displayContent.pendingLayoutChanges
-                            & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
-                        displayContent.layoutNeeded = true;
-                    }
-
-                    // FIRST LOOP: Perform a layout, if needed.
-                    if (repeats < 4) {
-                        performLayoutLockedInner(displayContent, repeats == 1,
-                                false /*updateInputWindows*/);
-                    } else {
-                        Slog.w(TAG, "Layout repeat skipped after too many iterations");
-                    }
-
-                    // FIRST AND ONE HALF LOOP: Make WindowManagerPolicy think
-                    // it is animating.
-                    displayContent.pendingLayoutChanges = 0;
-
-                    if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("loop number "
-                            + mLayoutRepeatCount, displayContent.pendingLayoutChanges);
-
-                    if (isDefaultDisplay) {
-                        mPolicy.beginPostLayoutPolicyLw(dw, dh);
-                        for (i = windows.size() - 1; i >= 0; i--) {
-                            WindowState w = windows.get(i);
-                            if (w.mHasSurface) {
-                                mPolicy.applyPostLayoutPolicyLw(w, w.mAttrs);
-                            }
-                        }
-                        displayContent.pendingLayoutChanges |= mPolicy.finishPostLayoutPolicyLw();
-                        if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats(
-                            "after finishPostLayoutPolicyLw", displayContent.pendingLayoutChanges);
-                    }
-                } while (displayContent.pendingLayoutChanges != 0);
-
-                mInnerFields.mObscured = false;
-                mInnerFields.mSyswin = false;
-                displayContent.resetDimming();
-
-                // Only used if default window
-                final boolean someoneLosingFocus = !mLosingFocus.isEmpty();
-
-                final int N = windows.size();
-                for (i=N-1; i>=0; i--) {
-                    WindowState w = windows.get(i);
-
-                    final boolean obscuredChanged = w.mObscured != mInnerFields.mObscured;
-
-                    // Update effect.
-                    w.mObscured = mInnerFields.mObscured;
-                    if (!mInnerFields.mObscured) {
-                        handleNotObscuredLocked(w, currentTime, innerDw, innerDh);
-                    }
-
-                    if (!w.getStack().testDimmingTag()) {
-                        handleFlagDimBehind(w, innerDw, innerDh);
-                    }
-
-                    if (isDefaultDisplay && obscuredChanged && (mWallpaperTarget == w)
-                            && w.isVisibleLw()) {
-                        // This is the wallpaper target and its obscured state
-                        // changed... make sure the current wallaper's visibility
-                        // has been updated accordingly.
-                        updateWallpaperVisibilityLocked();
-                    }
-
-                    final WindowStateAnimator winAnimator = w.mWinAnimator;
-
-                    // If the window has moved due to its containing
-                    // content frame changing, then we'd like to animate
-                    // it.
-                    if (w.mHasSurface && w.shouldAnimateMove()) {
-                        // Frame has moved, containing content frame
-                        // has also moved, and we're not currently animating...
-                        // let's do something.
-                        Animation a = AnimationUtils.loadAnimation(mContext,
-                                com.android.internal.R.anim.window_move_from_decor);
-                        winAnimator.setAnimation(a);
-                        winAnimator.mAnimDw = w.mLastFrame.left - w.mFrame.left;
-                        winAnimator.mAnimDh = w.mLastFrame.top - w.mFrame.top;
-                        try {
-                            w.mClient.moved(w.mFrame.left, w.mFrame.top);
-                        } catch (RemoteException e) {
-                        }
-                    }
-
-                    //Slog.i(TAG, "Window " + this + " clearing mContentChanged - done placing");
-                    w.mContentChanged = false;
-
-                    // Moved from updateWindowsAndWallpaperLocked().
-                    if (w.mHasSurface) {
-                        // Take care of the window being ready to display.
-                        final boolean committed =
-                                winAnimator.commitFinishDrawingLocked(currentTime);
-                        if (isDefaultDisplay && committed) {
-                            if (w.mAttrs.type == TYPE_DREAM) {
-                                // HACK: When a dream is shown, it may at that
-                                // point hide the lock screen.  So we need to
-                                // redo the layout to let the phone window manager
-                                // make this happen.
-                                displayContent.pendingLayoutChanges |=
-                                        WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
-                                if (DEBUG_LAYOUT_REPEATS) {
-                                    debugLayoutRepeats(
-                                        "dream and commitFinishDrawingLocked true",
-                                        displayContent.pendingLayoutChanges);
-                                }
-                            }
-                            if ((w.mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
-                                if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG,
-                                        "First draw done in potential wallpaper target " + w);
-                                mInnerFields.mWallpaperMayChange = true;
-                                displayContent.pendingLayoutChanges |=
-                                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-                                if (DEBUG_LAYOUT_REPEATS) {
-                                    debugLayoutRepeats(
-                                        "wallpaper and commitFinishDrawingLocked true",
-                                        displayContent.pendingLayoutChanges);
-                                }
-                            }
-                        }
-
-                        winAnimator.setSurfaceBoundariesLocked(recoveringMemory);
-
-                        final AppWindowToken atoken = w.mAppToken;
-                        if (DEBUG_STARTING_WINDOW && atoken != null
-                                && w == atoken.startingWindow) {
-                            Slog.d(TAG, "updateWindows: starting " + w + " isOnScreen="
-                                + w.isOnScreen() + " allDrawn=" + atoken.allDrawn
-                                + " freezingScreen=" + atoken.mAppAnimator.freezingScreen);
-                        }
-                        if (atoken != null
-                                && (!atoken.allDrawn || atoken.mAppAnimator.freezingScreen)) {
-                            if (atoken.lastTransactionSequence != mTransactionSequence) {
-                                atoken.lastTransactionSequence = mTransactionSequence;
-                                atoken.numInterestingWindows = atoken.numDrawnWindows = 0;
-                                atoken.startingDisplayed = false;
-                            }
-                            if ((w.isOnScreen() || winAnimator.mAttrType == TYPE_BASE_APPLICATION)
-                                    && !w.mExiting && !w.mDestroying) {
-                                if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) {
-                                    Slog.v(TAG, "Eval win " + w + ": isDrawn=" + w.isDrawnLw()
-                                            + ", isAnimating=" + winAnimator.isAnimating());
-                                    if (!w.isDrawnLw()) {
-                                        Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceControl
-                                                + " pv=" + w.mPolicyVisibility
-                                                + " mDrawState=" + winAnimator.mDrawState
-                                                + " ah=" + w.mAttachedHidden
-                                                + " th=" + atoken.hiddenRequested
-                                                + " a=" + winAnimator.mAnimating);
-                                    }
-                                }
-                                if (w != atoken.startingWindow) {
-                                    if (!atoken.mAppAnimator.freezingScreen || !w.mAppFreezing) {
-                                        atoken.numInterestingWindows++;
-                                        if (w.isDrawnLw()) {
-                                            atoken.numDrawnWindows++;
-                                            if (DEBUG_VISIBILITY || DEBUG_ORIENTATION) Slog.v(TAG,
-                                                    "tokenMayBeDrawn: " + atoken
-                                                    + " freezingScreen=" + atoken.mAppAnimator.freezingScreen
-                                                    + " mAppFreezing=" + w.mAppFreezing);
-                                            updateAllDrawn = true;
-                                        }
-                                    }
-                                } else if (w.isDrawnLw()) {
-                                    atoken.startingDisplayed = true;
-                                }
-                            }
-                        }
-                    }
-
-                    if (isDefaultDisplay && someoneLosingFocus && (w == mCurrentFocus)
-                            && w.isDisplayedLw()) {
-                        focusDisplayed = true;
-                    }
-
-                    updateResizingWindows(w);
-                }
-
-                mDisplayManagerService.setDisplayHasContent(displayId,
-                        mInnerFields.mDisplayHasContent,
-                        true /* inTraversal, must call performTraversalInTrans... below */);
-
-                getDisplayContentLocked(displayId).stopDimmingIfNeeded();
-
-                if (updateAllDrawn) {
-                    updateAllDrawnLocked(displayContent);
-                }
-            }
-
-            if (focusDisplayed) {
-                mH.sendEmptyMessage(H.REPORT_LOSING_FOCUS);
-            }
-
-            // Give the display manager a chance to adjust properties
-            // like display rotation if it needs to.
-            mDisplayManagerService.performTraversalInTransactionFromWindowManager();
-
-        } catch (RuntimeException e) {
-            Log.wtf(TAG, "Unhandled exception in Window Manager", e);
-        } finally {
-            SurfaceControl.closeTransaction();
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                    "<<< CLOSE TRANSACTION performLayoutAndPlaceSurfaces");
-        }
-
-        final WindowList defaultWindows = defaultDisplay.getWindowList();
-
-        // If we are ready to perform an app transition, check through
-        // all of the app tokens to be shown and see if they are ready
-        // to go.
-        if (mAppTransition.isReady()) {
-            defaultDisplay.pendingLayoutChanges |= handleAppTransitionReadyLocked(defaultWindows);
-            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAppTransitionReadyLocked",
-                    defaultDisplay.pendingLayoutChanges);
-        }
-
-        if (!mAnimator.mAnimating && mAppTransition.isRunning()) {
-            // We have finished the animation of an app transition.  To do
-            // this, we have delayed a lot of operations like showing and
-            // hiding apps, moving apps in Z-order, etc.  The app token list
-            // reflects the correct Z-order, but the window list may now
-            // be out of sync with it.  So here we will just rebuild the
-            // entire app window list.  Fun!
-            defaultDisplay.pendingLayoutChanges |= handleAnimatingStoppedAndTransitionLocked();
-            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after handleAnimStopAndXitionLock",
-                defaultDisplay.pendingLayoutChanges);
-        }
-
-        if (mInnerFields.mWallpaperForceHidingChanged && defaultDisplay.pendingLayoutChanges == 0
-                && !mAppTransition.isReady()) {
-            // At this point, there was a window with a wallpaper that
-            // was force hiding other windows behind it, but now it
-            // is going away.  This may be simple -- just animate
-            // away the wallpaper and its window -- or it may be
-            // hard -- the wallpaper now needs to be shown behind
-            // something that was hidden.
-            defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
-            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("after animateAwayWallpaperLocked",
-                defaultDisplay.pendingLayoutChanges);
-        }
-        mInnerFields.mWallpaperForceHidingChanged = false;
-
-        if (mInnerFields.mWallpaperMayChange) {
-            if (DEBUG_WALLPAPER_LIGHT) Slog.v(TAG, "Wallpaper may change!  Adjusting");
-            defaultDisplay.pendingLayoutChanges |=
-                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("WallpaperMayChange",
-                    defaultDisplay.pendingLayoutChanges);
-        }
-
-        if (mFocusMayChange) {
-            mFocusMayChange = false;
-            if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
-                    false /*updateInputWindows*/)) {
-                defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
-            }
-        }
-
-        if (needsLayout()) {
-            defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
-            if (DEBUG_LAYOUT_REPEATS) debugLayoutRepeats("mLayoutNeeded",
-                    defaultDisplay.pendingLayoutChanges);
-        }
-
-        for (i = mResizingWindows.size() - 1; i >= 0; i--) {
-            WindowState win = mResizingWindows.get(i);
-            if (win.mAppFreezing) {
-                // Don't remove this window until rotation has completed.
-                continue;
-            }
-            final WindowStateAnimator winAnimator = win.mWinAnimator;
-            try {
-                if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG,
-                        "Reporting new frame to " + win + ": " + win.mCompatFrame);
-                int diff = 0;
-                boolean configChanged = win.isConfigChanged();
-                if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION)
-                        && configChanged) {
-                    Slog.i(TAG, "Sending new config to window " + win + ": "
-                            + winAnimator.mSurfaceW + "x" + winAnimator.mSurfaceH
-                            + " / " + mCurConfiguration + " / 0x"
-                            + Integer.toHexString(diff));
-                }
-                win.setConfiguration(mCurConfiguration);
-                if (DEBUG_ORIENTATION &&
-                        winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING) Slog.i(
-                        TAG, "Resizing " + win + " WITH DRAW PENDING");
-                final IWindow client = win.mClient;
-                final Rect frame = win.mFrame;
-                final Rect overscanInsets = win.mLastOverscanInsets;
-                final Rect contentInsets = win.mLastContentInsets;
-                final Rect visibleInsets = win.mLastVisibleInsets;
-                final boolean reportDraw
-                        = winAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
-                final Configuration newConfig = configChanged ? win.mConfiguration : null;
-                if (win.mClient instanceof IWindow.Stub) {
-                    // To prevent deadlock simulate one-way call if win.mClient is a local object.
-                    mH.post(new Runnable() {
-                        @Override
-                        public void run() {
-                            try {
-                                client.resized(frame, overscanInsets, contentInsets,
-                                        visibleInsets, reportDraw, newConfig);
-                            } catch (RemoteException e) {
-                                // Not a remote call, RemoteException won't be raised.
-                            }
-                        }
-                    });
-                } else {
-                   client.resized(frame, overscanInsets, contentInsets, visibleInsets, reportDraw,
-                           newConfig);
-                }
-                win.mOverscanInsetsChanged = false;
-                win.mContentInsetsChanged = false;
-                win.mVisibleInsetsChanged = false;
-                winAnimator.mSurfaceResized = false;
-            } catch (RemoteException e) {
-                win.mOrientationChanging = false;
-                win.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime()
-                        - mDisplayFreezeTime);
-            }
-            mResizingWindows.remove(i);
-        }
-
-        if (DEBUG_ORIENTATION && mDisplayFrozen) Slog.v(TAG,
-                "With display frozen, orientationChangeComplete="
-                + mInnerFields.mOrientationChangeComplete);
-        if (mInnerFields.mOrientationChangeComplete) {
-            if (mWindowsFreezingScreen) {
-                mWindowsFreezingScreen = false;
-                mLastFinishedFreezeSource = mInnerFields.mLastWindowFreezeSource;
-                mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT);
-            }
-            stopFreezingDisplayLocked();
-        }
-
-        // Destroy the surface of any windows that are no longer visible.
-        boolean wallpaperDestroyed = false;
-        i = mDestroySurface.size();
-        if (i > 0) {
-            do {
-                i--;
-                WindowState win = mDestroySurface.get(i);
-                win.mDestroying = false;
-                if (mInputMethodWindow == win) {
-                    mInputMethodWindow = null;
-                }
-                if (win == mWallpaperTarget) {
-                    wallpaperDestroyed = true;
-                }
-                win.mWinAnimator.destroySurfaceLocked();
-            } while (i > 0);
-            mDestroySurface.clear();
-        }
-
-        // Time to remove any exiting tokens?
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-            ArrayList<WindowToken> exitingTokens = displayContent.mExitingTokens;
-            for (i = exitingTokens.size() - 1; i >= 0; i--) {
-                WindowToken token = exitingTokens.get(i);
-                if (!token.hasVisible) {
-                    exitingTokens.remove(i);
-                    if (token.windowType == TYPE_WALLPAPER) {
-                        mWallpaperTokens.remove(token);
-                    }
-                }
-            }
-
-            // Time to remove any exiting applications?
-            AppTokenList exitingAppTokens = displayContent.mExitingAppTokens;
-            for (i = exitingAppTokens.size() - 1; i >= 0; i--) {
-                AppWindowToken token = exitingAppTokens.get(i);
-                if (!token.hasVisible && !mClosingApps.contains(token)) {
-                    // Make sure there is no animation running on this token,
-                    // so any windows associated with it will be removed as
-                    // soon as their animations are complete
-                    token.mAppAnimator.clearAnimation();
-                    token.mAppAnimator.animating = false;
-                    if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG,
-                            "performLayout: App token exiting now removed" + token);
-                    final Task task = mTaskIdToTask.get(token.groupId);
-                    if (task != null && task.removeAppToken(token)) {
-                        mTaskIdToTask.delete(token.groupId);
-                    }
-                    exitingAppTokens.remove(i);
-                }
-            }
-        }
-
-        if (!mAnimator.mAnimating && mRelayoutWhileAnimating.size() > 0) {
-            for (int j=mRelayoutWhileAnimating.size()-1; j>=0; j--) {
-                try {
-                    mRelayoutWhileAnimating.get(j).mClient.doneAnimating();
-                } catch (RemoteException e) {
-                }
-            }
-            mRelayoutWhileAnimating.clear();
-        }
-
-        if (wallpaperDestroyed) {
-            defaultDisplay.pendingLayoutChanges |=
-                    WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
-            defaultDisplay.layoutNeeded = true;
-        }
-
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-            if (displayContent.pendingLayoutChanges != 0) {
-                displayContent.layoutNeeded = true;
-            }
-        }
-
-        // Finally update all input windows now that the window changes have stabilized.
-        mInputMonitor.updateInputWindowsLw(true /*force*/);
-
-        setHoldScreenLocked(mInnerFields.mHoldScreen);
-        if (!mDisplayFrozen) {
-            if (mInnerFields.mScreenBrightness < 0 || mInnerFields.mScreenBrightness > 1.0f) {
-                mPowerManager.setScreenBrightnessOverrideFromWindowManager(-1);
-            } else {
-                mPowerManager.setScreenBrightnessOverrideFromWindowManager(
-                        toBrightnessOverride(mInnerFields.mScreenBrightness));
-            }
-            if (mInnerFields.mButtonBrightness < 0 || mInnerFields.mButtonBrightness > 1.0f) {
-                mPowerManager.setButtonBrightnessOverrideFromWindowManager(-1);
-            } else {
-                mPowerManager.setButtonBrightnessOverrideFromWindowManager(
-                        toBrightnessOverride(mInnerFields.mButtonBrightness));
-            }
-            mPowerManager.setUserActivityTimeoutOverrideFromWindowManager(
-                    mInnerFields.mUserActivityTimeout);
-        }
-
-        if (mTurnOnScreen) {
-            if (DEBUG_VISIBILITY) Slog.v(TAG, "Turning screen on after layout!");
-            mPowerManager.wakeUp(SystemClock.uptimeMillis());
-            mTurnOnScreen = false;
-        }
-
-        if (mInnerFields.mUpdateRotation) {
-            if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
-            if (updateRotationUncheckedLocked(false)) {
-                mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-            } else {
-                mInnerFields.mUpdateRotation = false;
-            }
-        }
-
-        if (mInnerFields.mOrientationChangeComplete && !defaultDisplay.layoutNeeded
-                && !mInnerFields.mUpdateRotation) {
-            checkDrawnWindowsLocked();
-        }
-
-        final int N = mPendingRemove.size();
-        if (N > 0) {
-            if (mPendingRemoveTmp.length < N) {
-                mPendingRemoveTmp = new WindowState[N+10];
-            }
-            mPendingRemove.toArray(mPendingRemoveTmp);
-            mPendingRemove.clear();
-            DisplayContentList displayList = new DisplayContentList();
-            for (i = 0; i < N; i++) {
-                WindowState w = mPendingRemoveTmp[i];
-                removeWindowInnerLocked(w.mSession, w);
-                if (!displayList.contains(w.mDisplayContent)) {
-                    displayList.add(w.mDisplayContent);
-                }
-            }
-
-            for (DisplayContent displayContent : displayList) {
-                assignLayersLocked(displayContent.getWindowList());
-                displayContent.layoutNeeded = true;
-            }
-        }
-
-        setFocusedStackFrame();
-
-        // Check to see if we are now in a state where the screen should
-        // be enabled, because the window obscured flags have changed.
-        enableScreenIfNeededLocked();
-
-        scheduleAnimationLocked();
-
-        if (DEBUG_WINDOW_TRACE) {
-            Slog.e(TAG, "performLayoutAndPlaceSurfacesLockedInner exit: animating="
-                    + mAnimator.mAnimating);
-        }
-    }
-
-    private int toBrightnessOverride(float value) {
-        return (int)(value * PowerManager.BRIGHTNESS_ON);
-    }
-
-    void checkDrawnWindowsLocked() {
-        if (mWaitingForDrawn.size() > 0) {
-            for (int j=mWaitingForDrawn.size()-1; j>=0; j--) {
-                Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(j);
-                WindowState win = pair.first;
-                //Slog.i(TAG, "Waiting for drawn " + win + ": removed="
-                //        + win.mRemoved + " visible=" + win.isVisibleLw()
-                //        + " shown=" + win.mSurfaceShown);
-                if (win.mRemoved) {
-                    // Window has been removed; no draw will now happen, so stop waiting.
-                    Slog.w(TAG, "Aborted waiting for drawn: " + pair.first);
-                    try {
-                        pair.second.sendResult(null);
-                    } catch (RemoteException e) {
-                    }
-                    mWaitingForDrawn.remove(pair);
-                    mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
-                } else if (win.mWinAnimator.mSurfaceShown) {
-                    // Window is now drawn (and shown).
-                    try {
-                        pair.second.sendResult(null);
-                    } catch (RemoteException e) {
-                    }
-                    mWaitingForDrawn.remove(pair);
-                    mH.removeMessages(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
-                }
-            }
-        }
-    }
-
-    @Override
-    public boolean waitForWindowDrawn(IBinder token, IRemoteCallback callback) {
-        if (token != null && callback != null) {
-            synchronized (mWindowMap) {
-                WindowState win = windowForClientLocked(null, token, true);
-                if (win != null) {
-                    Pair<WindowState, IRemoteCallback> pair =
-                            new Pair<WindowState, IRemoteCallback>(win, callback);
-                    Message m = mH.obtainMessage(H.WAITING_FOR_DRAWN_TIMEOUT, pair);
-                    mH.sendMessageDelayed(m, 2000);
-                    mWaitingForDrawn.add(pair);
-                    checkDrawnWindowsLocked();
-                    return true;
-                }
-                Slog.i(TAG, "waitForWindowDrawn: win null");
-            }
-        }
-        return false;
-    }
-
-    void setHoldScreenLocked(final Session newHoldScreen) {
-        final boolean hold = newHoldScreen != null;
-
-        if (hold && mHoldingScreenOn != newHoldScreen) {
-            mHoldingScreenWakeLock.setWorkSource(new WorkSource(newHoldScreen.mUid));
-        }
-        mHoldingScreenOn = newHoldScreen;
-
-        final boolean state = mHoldingScreenWakeLock.isHeld();
-        if (hold != state) {
-            if (hold) {
-                mHoldingScreenWakeLock.acquire();
-                mPolicy.keepScreenOnStartedLw();
-            } else {
-                mPolicy.keepScreenOnStoppedLw();
-                mHoldingScreenWakeLock.release();
-            }
-        }
-    }
-
-    @Override
-    public void requestTraversal() {
-        synchronized (mWindowMap) {
-            requestTraversalLocked();
-        }
-    }
-
-    void requestTraversalLocked() {
-        if (!mTraversalScheduled) {
-            mTraversalScheduled = true;
-            mH.sendEmptyMessage(H.DO_TRAVERSAL);
-        }
-    }
-
-    /** Note that Locked in this case is on mLayoutToAnim */
-    void scheduleAnimationLocked() {
-        if (!mAnimationScheduled) {
-            mAnimationScheduled = true;
-            mChoreographer.postCallback(
-                    Choreographer.CALLBACK_ANIMATION, mAnimator.mAnimationRunnable, null);
-        }
-    }
-
-    private boolean needsLayout() {
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-            if (displayContent.layoutNeeded) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    boolean copyAnimToLayoutParamsLocked() {
-        boolean doRequest = false;
-
-        final int bulkUpdateParams = mAnimator.mBulkUpdateParams;
-        if ((bulkUpdateParams & LayoutFields.SET_UPDATE_ROTATION) != 0) {
-            mInnerFields.mUpdateRotation = true;
-            doRequest = true;
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_MAY_CHANGE) != 0) {
-            mInnerFields.mWallpaperMayChange = true;
-            doRequest = true;
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_FORCE_HIDING_CHANGED) != 0) {
-            mInnerFields.mWallpaperForceHidingChanged = true;
-            doRequest = true;
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE) == 0) {
-            mInnerFields.mOrientationChangeComplete = false;
-        } else {
-            mInnerFields.mOrientationChangeComplete = true;
-            mInnerFields.mLastWindowFreezeSource = mAnimator.mLastWindowFreezeSource;
-            if (mWindowsFreezingScreen) {
-                doRequest = true;
-            }
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_TURN_ON_SCREEN) != 0) {
-            mTurnOnScreen = true;
-        }
-        if ((bulkUpdateParams & LayoutFields.SET_WALLPAPER_ACTION_PENDING) != 0) {
-            mInnerFields.mWallpaperActionPending = true;
-        }
-
-        return doRequest;
-    }
-
-    /** If a window that has an animation specifying a colored background and the current wallpaper
-     * is visible, then the color goes *below* the wallpaper so we don't cause the wallpaper to
-     * suddenly disappear. */
-    int adjustAnimationBackground(WindowStateAnimator winAnimator) {
-        WindowList windows = winAnimator.mWin.getWindowList();
-        for (int i = windows.size() - 1; i >= 0; --i) {
-            WindowState testWin = windows.get(i);
-            if (testWin.mIsWallpaper && testWin.isVisibleNow()) {
-                return testWin.mWinAnimator.mAnimLayer;
-            }
-        }
-        return winAnimator.mAnimLayer;
-    }
-
-    boolean reclaimSomeSurfaceMemoryLocked(WindowStateAnimator winAnimator, String operation,
-                                           boolean secure) {
-        final SurfaceControl surface = winAnimator.mSurfaceControl;
-        boolean leakedSurface = false;
-        boolean killedApps = false;
-
-        EventLog.writeEvent(EventLogTags.WM_NO_SURFACE_MEMORY, winAnimator.mWin.toString(),
-                winAnimator.mSession.mPid, operation);
-
-        if (mForceRemoves == null) {
-            mForceRemoves = new ArrayList<WindowState>();
-        }
-
-        long callingIdentity = Binder.clearCallingIdentity();
-        try {
-            // There was some problem...   first, do a sanity check of the
-            // window list to make sure we haven't left any dangling surfaces
-            // around.
-
-            Slog.i(TAG, "Out of memory for surface!  Looking for leaks...");
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-                final int numWindows = windows.size();
-                for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                    final WindowState ws = windows.get(winNdx);
-                    WindowStateAnimator wsa = ws.mWinAnimator;
-                    if (wsa.mSurfaceControl != null) {
-                        if (!mSessions.contains(wsa.mSession)) {
-                            Slog.w(TAG, "LEAKED SURFACE (session doesn't exist): "
-                                    + ws + " surface=" + wsa.mSurfaceControl
-                                    + " token=" + ws.mToken
-                                    + " pid=" + ws.mSession.mPid
-                                    + " uid=" + ws.mSession.mUid);
-                            if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
-                            wsa.mSurfaceControl.destroy();
-                            wsa.mSurfaceShown = false;
-                            wsa.mSurfaceControl = null;
-                            ws.mHasSurface = false;
-                            mForceRemoves.add(ws);
-                            leakedSurface = true;
-                        } else if (ws.mAppToken != null && ws.mAppToken.clientHidden) {
-                            Slog.w(TAG, "LEAKED SURFACE (app token hidden): "
-                                    + ws + " surface=" + wsa.mSurfaceControl
-                                    + " token=" + ws.mAppToken);
-                            if (SHOW_TRANSACTIONS) logSurface(ws, "LEAK DESTROY", null);
-                            wsa.mSurfaceControl.destroy();
-                            wsa.mSurfaceShown = false;
-                            wsa.mSurfaceControl = null;
-                            ws.mHasSurface = false;
-                            leakedSurface = true;
-                        }
-                    }
-                }
-            }
-
-            if (!leakedSurface) {
-                Slog.w(TAG, "No leaked surfaces; killing applicatons!");
-                SparseIntArray pidCandidates = new SparseIntArray();
-                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                    final WindowList windows = mDisplayContents.valueAt(displayNdx).getWindowList();
-                    final int numWindows = windows.size();
-                    for (int winNdx = 0; winNdx < numWindows; ++winNdx) {
-                        final WindowState ws = windows.get(winNdx);
-                        if (mForceRemoves.contains(ws)) {
-                            continue;
-                        }
-                        WindowStateAnimator wsa = ws.mWinAnimator;
-                        if (wsa.mSurfaceControl != null) {
-                            pidCandidates.append(wsa.mSession.mPid, wsa.mSession.mPid);
-                        }
-                    }
-                    if (pidCandidates.size() > 0) {
-                        int[] pids = new int[pidCandidates.size()];
-                        for (int i=0; i<pids.length; i++) {
-                            pids[i] = pidCandidates.keyAt(i);
-                        }
-                        try {
-                            if (mActivityManager.killPids(pids, "Free memory", secure)) {
-                                killedApps = true;
-                            }
-                        } catch (RemoteException e) {
-                        }
-                    }
-                }
-            }
-
-            if (leakedSurface || killedApps) {
-                // We managed to reclaim some memory, so get rid of the trouble
-                // surface and ask the app to request another one.
-                Slog.w(TAG, "Looks like we have reclaimed some memory, clearing surface for retry.");
-                if (surface != null) {
-                    if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) logSurface(winAnimator.mWin,
-                            "RECOVER DESTROY", null);
-                    surface.destroy();
-                    winAnimator.mSurfaceShown = false;
-                    winAnimator.mSurfaceControl = null;
-                    winAnimator.mWin.mHasSurface = false;
-                    scheduleRemoveStartingWindow(winAnimator.mWin.mAppToken);
-                }
-
-                try {
-                    winAnimator.mWin.mClient.dispatchGetNewSurface();
-                } catch (RemoteException e) {
-                }
-            }
-        } finally {
-            Binder.restoreCallingIdentity(callingIdentity);
-        }
-
-        return leakedSurface || killedApps;
-    }
-
-    private boolean updateFocusedWindowLocked(int mode, boolean updateInputWindows) {
-        WindowState newFocus = computeFocusedWindowLocked();
-        if (mCurrentFocus != newFocus) {
-            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "wmUpdateFocus");
-            // This check makes sure that we don't already have the focus
-            // change message pending.
-            mH.removeMessages(H.REPORT_FOCUS_CHANGE);
-            mH.sendEmptyMessage(H.REPORT_FOCUS_CHANGE);
-            // TODO(multidisplay): Focused windows on default display only.
-            final DisplayContent displayContent = getDefaultDisplayContentLocked();
-            final boolean imWindowChanged = moveInputMethodWindowsIfNeededLocked(
-                    mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS
-                            && mode != UPDATE_FOCUS_WILL_PLACE_SURFACES);
-            if (imWindowChanged) {
-                displayContent.layoutNeeded = true;
-                newFocus = computeFocusedWindowLocked();
-            }
-
-            if (DEBUG_FOCUS_LIGHT || localLOGV) Slog.v(TAG, "Changing focus from " +
-                    mCurrentFocus + " to " + newFocus + " Callers=" + Debug.getCallers(4));
-            final WindowState oldFocus = mCurrentFocus;
-            mCurrentFocus = newFocus;
-            mLosingFocus.remove(newFocus);
-            int focusChanged = mPolicy.focusChangedLw(oldFocus, newFocus);
-
-            if (imWindowChanged && oldFocus != mInputMethodWindow) {
-                // Focus of the input method window changed. Perform layout if needed.
-                if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
-                    performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows);
-                    focusChanged &= ~WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
-                } else if (mode == UPDATE_FOCUS_WILL_PLACE_SURFACES) {
-                    // Client will do the layout, but we need to assign layers
-                    // for handleNewWindowLocked() below.
-                    assignLayersLocked(displayContent.getWindowList());
-                }
-            }
-
-            if ((focusChanged & WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT) != 0) {
-                // The change in focus caused us to need to do a layout.  Okay.
-                displayContent.layoutNeeded = true;
-                if (mode == UPDATE_FOCUS_PLACING_SURFACES) {
-                    performLayoutLockedInner(displayContent, true /*initial*/, updateInputWindows);
-                }
-            }
-
-            if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
-                // If we defer assigning layers, then the caller is responsible for
-                // doing this part.
-                finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
-            }
-
-            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
-            return true;
-        }
-        return false;
-    }
-
-    private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
-        mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
-    }
-
-    private WindowState computeFocusedWindowLocked() {
-        if (mAnimator.mUniverseBackground != null
-                && mAnimator.mUniverseBackground.mWin.canReceiveKeys()) {
-            return mAnimator.mUniverseBackground.mWin;
-        }
-
-        final int displayCount = mDisplayContents.size();
-        for (int i = 0; i < displayCount; i++) {
-            final DisplayContent displayContent = mDisplayContents.valueAt(i);
-            WindowState win = findFocusedWindowLocked(displayContent);
-            if (win != null) {
-                return win;
-            }
-        }
-        return null;
-    }
-
-    private WindowState findFocusedWindowLocked(DisplayContent displayContent) {
-        final WindowList windows = displayContent.getWindowList();
-        for (int i = windows.size() - 1; i >= 0; i--) {
-            final WindowState win = windows.get(i);
-
-            if (localLOGV || DEBUG_FOCUS) Slog.v(
-                TAG, "Looking for focus: " + i
-                + " = " + win
-                + ", flags=" + win.mAttrs.flags
-                + ", canReceive=" + win.canReceiveKeys());
-
-            AppWindowToken wtoken = win.mAppToken;
-
-            // If this window's application has been removed, just skip it.
-            if (wtoken != null && (wtoken.removed || wtoken.sendingToBottom)) {
-                if (DEBUG_FOCUS) Slog.v(TAG, "Skipping " + wtoken + " because "
-                        + (wtoken.removed ? "removed" : "sendingToBottom"));
-                continue;
-            }
-
-            if (!win.canReceiveKeys()) {
-                continue;
-            }
-
-            // Descend through all of the app tokens and find the first that either matches
-            // win.mAppToken (return win) or mFocusedApp (return null).
-            if (wtoken != null && win.mAttrs.type != TYPE_APPLICATION_STARTING &&
-                    mFocusedApp != null) {
-                ArrayList<Task> tasks = displayContent.getTasks();
-                for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
-                    AppTokenList tokens = tasks.get(taskNdx).mAppTokens;
-                    int tokenNdx = tokens.size() - 1;
-                    for ( ; tokenNdx >= 0; --tokenNdx) {
-                        final AppWindowToken token = tokens.get(tokenNdx);
-                        if (wtoken == token) {
-                            break;
-                        }
-                        if (mFocusedApp == token) {
-                            // Whoops, we are below the focused app...  no focus for you!
-                            if (localLOGV || DEBUG_FOCUS_LIGHT) Slog.v(TAG,
-                                    "findFocusedWindow: Reached focused app=" + mFocusedApp);
-                            return null;
-                        }
-                    }
-                    if (tokenNdx >= 0) {
-                        // Early exit from loop, must have found the matching token.
-                        break;
-                    }
-                }
-            }
-
-            if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: Found new focus @ " + i +
-                        " = " + win);
-            return win;
-        }
-
-        if (DEBUG_FOCUS_LIGHT) Slog.v(TAG, "findFocusedWindow: No focusable windows.");
-        return null;
-    }
-
-    private void startFreezingDisplayLocked(boolean inTransaction, int exitAnim, int enterAnim) {
-        if (mDisplayFrozen) {
-            return;
-        }
-
-        if (!mDisplayReady || !mPolicy.isScreenOnFully()) {
-            // No need to freeze the screen before the system is ready or if
-            // the screen is off.
-            return;
-        }
-
-        mScreenFrozenLock.acquire();
-
-        mDisplayFrozen = true;
-        mDisplayFreezeTime = SystemClock.elapsedRealtime();
-        mLastFinishedFreezeSource = null;
-
-        mInputMonitor.freezeInputDispatchingLw();
-
-        // Clear the last input window -- that is just used for
-        // clean transitions between IMEs, and if we are freezing
-        // the screen then the whole world is changing behind the scenes.
-        mPolicy.setLastInputMethodWindowLw(null, null);
-
-        if (mAppTransition.isTransitionSet()) {
-            mAppTransition.freeze();
-        }
-
-        if (PROFILE_ORIENTATION) {
-            File file = new File("/data/system/frozen");
-            Debug.startMethodTracing(file.toString(), 8 * 1024 * 1024);
-        }
-
-        if (CUSTOM_SCREEN_ROTATION) {
-            mExitAnimId = exitAnim;
-            mEnterAnimId = enterAnim;
-            final DisplayContent displayContent = getDefaultDisplayContentLocked();
-            final int displayId = displayContent.getDisplayId();
-            ScreenRotationAnimation screenRotationAnimation =
-                    mAnimator.getScreenRotationAnimationLocked(displayId);
-            if (screenRotationAnimation != null) {
-                screenRotationAnimation.kill();
-            }
-
-            // TODO(multidisplay): rotation on main screen only.
-            screenRotationAnimation = new ScreenRotationAnimation(mContext, displayContent,
-                    mFxSession, inTransaction, mPolicy.isDefaultOrientationForced());
-            mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
-        }
-    }
-
-    private void stopFreezingDisplayLocked() {
-        if (!mDisplayFrozen) {
-            return;
-        }
-
-        if (mWaitingForConfig || mAppsFreezingScreen > 0 || mWindowsFreezingScreen
-                || mClientFreezingScreen) {
-            if (DEBUG_ORIENTATION) Slog.d(TAG,
-                "stopFreezingDisplayLocked: Returning mWaitingForConfig=" + mWaitingForConfig
-                + ", mAppsFreezingScreen=" + mAppsFreezingScreen
-                + ", mWindowsFreezingScreen=" + mWindowsFreezingScreen
-                + ", mClientFreezingScreen=" + mClientFreezingScreen);
-            return;
-        }
-
-        mDisplayFrozen = false;
-        mLastDisplayFreezeDuration = (int)(SystemClock.elapsedRealtime() - mDisplayFreezeTime);
-        StringBuilder sb = new StringBuilder(128);
-        sb.append("Screen frozen for ");
-        TimeUtils.formatDuration(mLastDisplayFreezeDuration, sb);
-        if (mLastFinishedFreezeSource != null) {
-            sb.append(" due to ");
-            sb.append(mLastFinishedFreezeSource);
-        }
-        Slog.i(TAG, sb.toString());
-        mH.removeMessages(H.APP_FREEZE_TIMEOUT);
-        mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT);
-        if (PROFILE_ORIENTATION) {
-            Debug.stopMethodTracing();
-        }
-
-        boolean updateRotation = false;
-
-        final DisplayContent displayContent = getDefaultDisplayContentLocked();
-        final int displayId = displayContent.getDisplayId();
-        ScreenRotationAnimation screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(displayId);
-        if (CUSTOM_SCREEN_ROTATION && screenRotationAnimation != null
-                && screenRotationAnimation.hasScreenshot()) {
-            if (DEBUG_ORIENTATION) Slog.i(TAG, "**** Dismissing screen rotation animation");
-            // TODO(multidisplay): rotation on main screen only.
-            DisplayInfo displayInfo = displayContent.getDisplayInfo();
-            // Get rotation animation again, with new top window
-            boolean isDimming = displayContent.isDimming();
-            if (!mPolicy.validateRotationAnimationLw(mExitAnimId, mEnterAnimId, isDimming)) {
-                mExitAnimId = mEnterAnimId = 0;
-            }
-            if (screenRotationAnimation.dismiss(mFxSession, MAX_ANIMATION_DURATION,
-                    mTransitionAnimationScale, displayInfo.logicalWidth,
-                        displayInfo.logicalHeight, mExitAnimId, mEnterAnimId)) {
-                scheduleAnimationLocked();
-            } else {
-                screenRotationAnimation.kill();
-                screenRotationAnimation = null;
-                mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
-                updateRotation = true;
-            }
-        } else {
-            if (screenRotationAnimation != null) {
-                screenRotationAnimation.kill();
-                screenRotationAnimation = null;
-                mAnimator.setScreenRotationAnimationLocked(displayId, screenRotationAnimation);
-            }
-            updateRotation = true;
-        }
-
-        mInputMonitor.thawInputDispatchingLw();
-
-        boolean configChanged;
-
-        // While the display is frozen we don't re-compute the orientation
-        // to avoid inconsistent states.  However, something interesting
-        // could have actually changed during that time so re-evaluate it
-        // now to catch that.
-        configChanged = updateOrientationFromAppTokensLocked(false);
-
-        // A little kludge: a lot could have happened while the
-        // display was frozen, so now that we are coming back we
-        // do a gc so that any remote references the system
-        // processes holds on others can be released if they are
-        // no longer needed.
-        mH.removeMessages(H.FORCE_GC);
-        mH.sendEmptyMessageDelayed(H.FORCE_GC, 2000);
-
-        mScreenFrozenLock.release();
-
-        if (updateRotation) {
-            if (DEBUG_ORIENTATION) Slog.d(TAG, "Performing post-rotate rotation");
-            configChanged |= updateRotationUncheckedLocked(false);
-        }
-
-        if (configChanged) {
-            mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
-        }
-    }
-
-    static int getPropertyInt(String[] tokens, int index, int defUnits, int defDps,
-            DisplayMetrics dm) {
-        if (index < tokens.length) {
-            String str = tokens[index];
-            if (str != null && str.length() > 0) {
-                try {
-                    int val = Integer.parseInt(str);
-                    return val;
-                } catch (Exception e) {
-                }
-            }
-        }
-        if (defUnits == TypedValue.COMPLEX_UNIT_PX) {
-            return defDps;
-        }
-        int val = (int)TypedValue.applyDimension(defUnits, defDps, dm);
-        return val;
-    }
-
-    void createWatermarkInTransaction() {
-        if (mWatermark != null) {
-            return;
-        }
-
-        File file = new File("/system/etc/setup.conf");
-        FileInputStream in = null;
-        DataInputStream ind = null;
-        try {
-            in = new FileInputStream(file);
-            ind = new DataInputStream(in);
-            String line = ind.readLine();
-            if (line != null) {
-                String[] toks = line.split("%");
-                if (toks != null && toks.length > 0) {
-                    mWatermark = new Watermark(getDefaultDisplayContentLocked().getDisplay(),
-                            mRealDisplayMetrics, mFxSession, toks);
-                }
-            }
-        } catch (FileNotFoundException e) {
-        } catch (IOException e) {
-        } finally {
-            if (ind != null) {
-                try {
-                    ind.close();
-                } catch (IOException e) {
-                }
-            } else if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                }
-            }
-        }
-    }
-
-    @Override
-    public void statusBarVisibilityChanged(int visibility) {
-        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR)
-                != PackageManager.PERMISSION_GRANTED) {
-            throw new SecurityException("Caller does not hold permission "
-                    + android.Manifest.permission.STATUS_BAR);
-        }
-
-        synchronized (mWindowMap) {
-            mLastStatusBarVisibility = visibility;
-            visibility = mPolicy.adjustSystemUiVisibilityLw(visibility);
-            updateStatusBarVisibilityLocked(visibility);
-        }
-    }
-
-    // TOOD(multidisplay): StatusBar on multiple screens?
-    void updateStatusBarVisibilityLocked(int visibility) {
-        mInputManager.setSystemUiVisibility(visibility);
-        final WindowList windows = getDefaultWindowListLocked();
-        final int N = windows.size();
-        for (int i = 0; i < N; i++) {
-            WindowState ws = windows.get(i);
-            try {
-                int curValue = ws.mSystemUiVisibility;
-                int diff = curValue ^ visibility;
-                // We are only interested in differences of one of the
-                // clearable flags...
-                diff &= View.SYSTEM_UI_CLEARABLE_FLAGS;
-                // ...if it has actually been cleared.
-                diff &= ~visibility;
-                int newValue = (curValue&~diff) | (visibility&diff);
-                if (newValue != curValue) {
-                    ws.mSeq++;
-                    ws.mSystemUiVisibility = newValue;
-                }
-                if (newValue != curValue || ws.mAttrs.hasSystemUiListeners) {
-                    ws.mClient.dispatchSystemUiVisibilityChanged(ws.mSeq,
-                            visibility, newValue, diff);
-                }
-            } catch (RemoteException e) {
-                // so sorry
-            }
-        }
-    }
-
-    @Override
-    public void reevaluateStatusBarVisibility() {
-        synchronized (mWindowMap) {
-            int visibility = mPolicy.adjustSystemUiVisibilityLw(mLastStatusBarVisibility);
-            updateStatusBarVisibilityLocked(visibility);
-            performLayoutAndPlaceSurfacesLocked();
-        }
-    }
-
-    @Override
-    public FakeWindow addFakeWindow(Looper looper,
-            InputEventReceiver.Factory inputEventReceiverFactory,
-            String name, int windowType, int layoutParamsFlags, int layoutParamsPrivateFlags,
-            boolean canReceiveKeys, boolean hasFocus, boolean touchFullscreen) {
-        synchronized (mWindowMap) {
-            FakeWindowImpl fw = new FakeWindowImpl(this, looper, inputEventReceiverFactory,
-                    name, windowType,
-                    layoutParamsFlags, layoutParamsPrivateFlags, canReceiveKeys,
-                    hasFocus, touchFullscreen);
-            int i=0;
-            while (i<mFakeWindows.size()) {
-                if (mFakeWindows.get(i).mWindowLayer <= fw.mWindowLayer) {
-                    break;
-                }
-            }
-            mFakeWindows.add(i, fw);
-            mInputMonitor.updateInputWindowsLw(true);
-            return fw;
-        }
-    }
-
-    boolean removeFakeWindowLocked(FakeWindow window) {
-        synchronized (mWindowMap) {
-            if (mFakeWindows.remove(window)) {
-                mInputMonitor.updateInputWindowsLw(true);
-                return true;
-            }
-            return false;
-        }
-    }
-
-    // It is assumed that this method is called only by InputMethodManagerService.
-    public void saveLastInputMethodWindowForTransition() {
-        synchronized (mWindowMap) {
-            // TODO(multidisplay): Pass in the displayID.
-            DisplayContent displayContent = getDefaultDisplayContentLocked();
-            if (mInputMethodWindow != null) {
-                mPolicy.setLastInputMethodWindowLw(mInputMethodWindow, mInputMethodTarget);
-            }
-        }
-    }
-
-    @Override
-    public boolean hasNavigationBar() {
-        return mPolicy.hasNavigationBar();
-    }
-
-    @Override
-    public void lockNow(Bundle options) {
-        mPolicy.lockNow(options);
-    }
-
-    @Override
-    public boolean isSafeModeEnabled() {
-        return mSafeMode;
-    }
-
-    void dumpPolicyLocked(PrintWriter pw, String[] args, boolean dumpAll) {
-        pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)");
-        mPolicy.dump("    ", pw, args);
-    }
-
-    void dumpAnimatorLocked(PrintWriter pw, String[] args, boolean dumpAll) {
-        pw.println("WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)");
-        mAnimator.dumpLocked(pw, "    ", dumpAll);
-    }
-
-    void dumpTokensLocked(PrintWriter pw, boolean dumpAll) {
-        pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)");
-        if (mTokenMap.size() > 0) {
-            pw.println("  All tokens:");
-            Iterator<WindowToken> it = mTokenMap.values().iterator();
-            while (it.hasNext()) {
-                WindowToken token = it.next();
-                pw.print("  "); pw.print(token);
-                if (dumpAll) {
-                    pw.println(':');
-                    token.dump(pw, "    ");
-                } else {
-                    pw.println();
-                }
-            }
-        }
-        if (mWallpaperTokens.size() > 0) {
-            pw.println();
-            pw.println("  Wallpaper tokens:");
-            for (int i=mWallpaperTokens.size()-1; i>=0; i--) {
-                WindowToken token = mWallpaperTokens.get(i);
-                pw.print("  Wallpaper #"); pw.print(i);
-                        pw.print(' '); pw.print(token);
-                if (dumpAll) {
-                    pw.println(':');
-                    token.dump(pw, "    ");
-                } else {
-                    pw.println();
-                }
-            }
-        }
-        if (mFinishedStarting.size() > 0) {
-            pw.println();
-            pw.println("  Finishing start of application tokens:");
-            for (int i=mFinishedStarting.size()-1; i>=0; i--) {
-                WindowToken token = mFinishedStarting.get(i);
-                pw.print("  Finished Starting #"); pw.print(i);
-                        pw.print(' '); pw.print(token);
-                if (dumpAll) {
-                    pw.println(':');
-                    token.dump(pw, "    ");
-                } else {
-                    pw.println();
-                }
-            }
-        }
-        if (mOpeningApps.size() > 0 || mClosingApps.size() > 0) {
-            pw.println();
-            if (mOpeningApps.size() > 0) {
-                pw.print("  mOpeningApps="); pw.println(mOpeningApps);
-            }
-            if (mClosingApps.size() > 0) {
-                pw.print("  mClosingApps="); pw.println(mClosingApps);
-            }
-        }
-    }
-
-    void dumpSessionsLocked(PrintWriter pw, boolean dumpAll) {
-        pw.println("WINDOW MANAGER SESSIONS (dumpsys window sessions)");
-        if (mSessions.size() > 0) {
-            Iterator<Session> it = mSessions.iterator();
-            while (it.hasNext()) {
-                Session s = it.next();
-                pw.print("  Session "); pw.print(s); pw.println(':');
-                s.dump(pw, "    ");
-            }
-        }
-    }
-
-    void dumpDisplayContentsLocked(PrintWriter pw, boolean dumpAll) {
-        pw.println("WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)");
-        if (mDisplayReady) {
-            final int numDisplays = mDisplayContents.size();
-            for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-                displayContent.dump("  ", pw);
-            }
-        } else {
-            pw.println("  NO DISPLAY");
-        }
-    }
-
-    void dumpWindowsLocked(PrintWriter pw, boolean dumpAll,
-            ArrayList<WindowState> windows) {
-        pw.println("WINDOW MANAGER WINDOWS (dumpsys window windows)");
-        dumpWindowsNoHeaderLocked(pw, dumpAll, windows);
-    }
-
-    void dumpWindowsNoHeaderLocked(PrintWriter pw, boolean dumpAll,
-            ArrayList<WindowState> windows) {
-        final int numDisplays = mDisplayContents.size();
-        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-            final WindowList windowList = mDisplayContents.valueAt(displayNdx).getWindowList();
-            for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
-                final WindowState w = windowList.get(winNdx);
-                if (windows == null || windows.contains(w)) {
-                    pw.print("  Window #"); pw.print(winNdx); pw.print(' ');
-                            pw.print(w); pw.println(":");
-                    w.dump(pw, "    ", dumpAll || windows != null);
-                }
-            }
-        }
-        if (mInputMethodDialogs.size() > 0) {
-            pw.println();
-            pw.println("  Input method dialogs:");
-            for (int i=mInputMethodDialogs.size()-1; i>=0; i--) {
-                WindowState w = mInputMethodDialogs.get(i);
-                if (windows == null || windows.contains(w)) {
-                    pw.print("  IM Dialog #"); pw.print(i); pw.print(": "); pw.println(w);
-                }
-            }
-        }
-        if (mPendingRemove.size() > 0) {
-            pw.println();
-            pw.println("  Remove pending for:");
-            for (int i=mPendingRemove.size()-1; i>=0; i--) {
-                WindowState w = mPendingRemove.get(i);
-                if (windows == null || windows.contains(w)) {
-                    pw.print("  Remove #"); pw.print(i); pw.print(' ');
-                            pw.print(w);
-                    if (dumpAll) {
-                        pw.println(":");
-                        w.dump(pw, "    ", true);
-                    } else {
-                        pw.println();
-                    }
-                }
-            }
-        }
-        if (mForceRemoves != null && mForceRemoves.size() > 0) {
-            pw.println();
-            pw.println("  Windows force removing:");
-            for (int i=mForceRemoves.size()-1; i>=0; i--) {
-                WindowState w = mForceRemoves.get(i);
-                pw.print("  Removing #"); pw.print(i); pw.print(' ');
-                        pw.print(w);
-                if (dumpAll) {
-                    pw.println(":");
-                    w.dump(pw, "    ", true);
-                } else {
-                    pw.println();
-                }
-            }
-        }
-        if (mDestroySurface.size() > 0) {
-            pw.println();
-            pw.println("  Windows waiting to destroy their surface:");
-            for (int i=mDestroySurface.size()-1; i>=0; i--) {
-                WindowState w = mDestroySurface.get(i);
-                if (windows == null || windows.contains(w)) {
-                    pw.print("  Destroy #"); pw.print(i); pw.print(' ');
-                            pw.print(w);
-                    if (dumpAll) {
-                        pw.println(":");
-                        w.dump(pw, "    ", true);
-                    } else {
-                        pw.println();
-                    }
-                }
-            }
-        }
-        if (mLosingFocus.size() > 0) {
-            pw.println();
-            pw.println("  Windows losing focus:");
-            for (int i=mLosingFocus.size()-1; i>=0; i--) {
-                WindowState w = mLosingFocus.get(i);
-                if (windows == null || windows.contains(w)) {
-                    pw.print("  Losing #"); pw.print(i); pw.print(' ');
-                            pw.print(w);
-                    if (dumpAll) {
-                        pw.println(":");
-                        w.dump(pw, "    ", true);
-                    } else {
-                        pw.println();
-                    }
-                }
-            }
-        }
-        if (mResizingWindows.size() > 0) {
-            pw.println();
-            pw.println("  Windows waiting to resize:");
-            for (int i=mResizingWindows.size()-1; i>=0; i--) {
-                WindowState w = mResizingWindows.get(i);
-                if (windows == null || windows.contains(w)) {
-                    pw.print("  Resizing #"); pw.print(i); pw.print(' ');
-                            pw.print(w);
-                    if (dumpAll) {
-                        pw.println(":");
-                        w.dump(pw, "    ", true);
-                    } else {
-                        pw.println();
-                    }
-                }
-            }
-        }
-        if (mWaitingForDrawn.size() > 0) {
-            pw.println();
-            pw.println("  Clients waiting for these windows to be drawn:");
-            for (int i=mWaitingForDrawn.size()-1; i>=0; i--) {
-                Pair<WindowState, IRemoteCallback> pair = mWaitingForDrawn.get(i);
-                pw.print("  Waiting #"); pw.print(i); pw.print(' '); pw.print(pair.first);
-                        pw.print(": "); pw.println(pair.second);
-            }
-        }
-        pw.println();
-        pw.print("  mCurConfiguration="); pw.println(this.mCurConfiguration);
-        pw.print("  mCurrentFocus="); pw.println(mCurrentFocus);
-        if (mLastFocus != mCurrentFocus) {
-            pw.print("  mLastFocus="); pw.println(mLastFocus);
-        }
-        pw.print("  mFocusedApp="); pw.println(mFocusedApp);
-        if (mInputMethodTarget != null) {
-            pw.print("  mInputMethodTarget="); pw.println(mInputMethodTarget);
-        }
-        pw.print("  mInTouchMode="); pw.print(mInTouchMode);
-                pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
-        pw.print("  mLastDisplayFreezeDuration=");
-                TimeUtils.formatDuration(mLastDisplayFreezeDuration, pw);
-                if ( mLastFinishedFreezeSource != null) {
-                    pw.print(" due to ");
-                    pw.print(mLastFinishedFreezeSource);
-                }
-                pw.println();
-        if (dumpAll) {
-            pw.print("  mSystemDecorLayer="); pw.print(mSystemDecorLayer);
-                    pw.print(" mScreenRect="); pw.println(mScreenRect.toShortString());
-            if (mLastStatusBarVisibility != 0) {
-                pw.print("  mLastStatusBarVisibility=0x");
-                        pw.println(Integer.toHexString(mLastStatusBarVisibility));
-            }
-            if (mInputMethodWindow != null) {
-                pw.print("  mInputMethodWindow="); pw.println(mInputMethodWindow);
-            }
-            pw.print("  mWallpaperTarget="); pw.println(mWallpaperTarget);
-            if (mLowerWallpaperTarget != null || mUpperWallpaperTarget != null) {
-                pw.print("  mLowerWallpaperTarget="); pw.println(mLowerWallpaperTarget);
-                pw.print("  mUpperWallpaperTarget="); pw.println(mUpperWallpaperTarget);
-            }
-            pw.print("  mLastWallpaperX="); pw.print(mLastWallpaperX);
-                    pw.print(" mLastWallpaperY="); pw.println(mLastWallpaperY);
-            if (mInputMethodAnimLayerAdjustment != 0 ||
-                    mWallpaperAnimLayerAdjustment != 0) {
-                pw.print("  mInputMethodAnimLayerAdjustment=");
-                        pw.print(mInputMethodAnimLayerAdjustment);
-                        pw.print("  mWallpaperAnimLayerAdjustment=");
-                        pw.println(mWallpaperAnimLayerAdjustment);
-            }
-            pw.print("  mSystemBooted="); pw.print(mSystemBooted);
-                    pw.print(" mDisplayEnabled="); pw.println(mDisplayEnabled);
-            if (needsLayout()) {
-                pw.print("  layoutNeeded on displays=");
-                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                    final DisplayContent displayContent = mDisplayContents.valueAt(displayNdx);
-                    if (displayContent.layoutNeeded) {
-                        pw.print(displayContent.getDisplayId());
-                    }
-                }
-                pw.println();
-            }
-            pw.print("  mTransactionSequence="); pw.println(mTransactionSequence);
-            pw.print("  mDisplayFrozen="); pw.print(mDisplayFrozen);
-                    pw.print(" windows="); pw.print(mWindowsFreezingScreen);
-                    pw.print(" client="); pw.print(mClientFreezingScreen);
-                    pw.print(" apps="); pw.print(mAppsFreezingScreen);
-                    pw.print(" waitingForConfig="); pw.println(mWaitingForConfig);
-            pw.print("  mRotation="); pw.print(mRotation);
-                    pw.print(" mAltOrientation="); pw.println(mAltOrientation);
-            pw.print("  mLastWindowForcedOrientation="); pw.print(mLastWindowForcedOrientation);
-                    pw.print(" mForcedAppOrientation="); pw.println(mForcedAppOrientation);
-            pw.print("  mDeferredRotationPauseCount="); pw.println(mDeferredRotationPauseCount);
-            pw.print("  mWindowAnimationScale="); pw.print(mWindowAnimationScale);
-                    pw.print(" mTransitionWindowAnimationScale="); pw.print(mTransitionAnimationScale);
-                    pw.print(" mAnimatorDurationScale="); pw.println(mAnimatorDurationScale);
-            pw.print("  mTraversalScheduled="); pw.println(mTraversalScheduled);
-            pw.print("  mStartingIconInTransition="); pw.print(mStartingIconInTransition);
-                    pw.print(" mSkipAppTransitionAnimation="); pw.println(mSkipAppTransitionAnimation);
-            pw.println("  mLayoutToAnim:");
-            mAppTransition.dump(pw);
-        }
-    }
-
-    boolean dumpWindows(PrintWriter pw, String name, String[] args,
-            int opti, boolean dumpAll) {
-        WindowList windows = new WindowList();
-        if ("visible".equals(name)) {
-            synchronized(mWindowMap) {
-                final int numDisplays = mDisplayContents.size();
-                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                    final WindowList windowList =
-                            mDisplayContents.valueAt(displayNdx).getWindowList();
-                    for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
-                        final WindowState w = windowList.get(winNdx);
-                        if (w.mWinAnimator.mSurfaceShown) {
-                            windows.add(w);
-                        }
-                    }
-                }
-            }
-        } else {
-            int objectId = 0;
-            // See if this is an object ID.
-            try {
-                objectId = Integer.parseInt(name, 16);
-                name = null;
-            } catch (RuntimeException e) {
-            }
-            synchronized(mWindowMap) {
-                final int numDisplays = mDisplayContents.size();
-                for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
-                    final WindowList windowList =
-                            mDisplayContents.valueAt(displayNdx).getWindowList();
-                    for (int winNdx = windowList.size() - 1; winNdx >= 0; --winNdx) {
-                        final WindowState w = windowList.get(winNdx);
-                        if (name != null) {
-                            if (w.mAttrs.getTitle().toString().contains(name)) {
-                                windows.add(w);
-                            }
-                        } else if (System.identityHashCode(w) == objectId) {
-                            windows.add(w);
-                        }
-                    }
-                }
-            }
-        }
-
-        if (windows.size() <= 0) {
-            return false;
-        }
-
-        synchronized(mWindowMap) {
-            dumpWindowsLocked(pw, dumpAll, windows);
-        }
-        return true;
-    }
-
-    void dumpLastANRLocked(PrintWriter pw) {
-        pw.println("WINDOW MANAGER LAST ANR (dumpsys window lastanr)");
-        if (mLastANRState == null) {
-            pw.println("  <no ANR has occurred since boot>");
-        } else {
-            pw.println(mLastANRState);
-        }
-    }
-
-    /**
-     * Saves information about the state of the window manager at
-     * the time an ANR occurred before anything else in the system changes
-     * in response.
-     *
-     * @param appWindowToken The application that ANR'd, may be null.
-     * @param windowState The window that ANR'd, may be null.
-     * @param reason The reason for the ANR, may be null.
-     */
-    public void saveANRStateLocked(AppWindowToken appWindowToken, WindowState windowState,
-            String reason) {
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = new FastPrintWriter(sw, false, 1024);
-        pw.println("  ANR time: " + DateFormat.getInstance().format(new Date()));
-        if (appWindowToken != null) {
-            pw.println("  Application at fault: " + appWindowToken.stringName);
-        }
-        if (windowState != null) {
-            pw.println("  Window at fault: " + windowState.mAttrs.getTitle());
-        }
-        if (reason != null) {
-            pw.println("  Reason: " + reason);
-        }
-        pw.println();
-        dumpWindowsNoHeaderLocked(pw, true, null);
-        pw.close();
-        mLastANRState = sw.toString();
-    }
-
-    @Override
-    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
-        if (mContext.checkCallingOrSelfPermission("android.permission.DUMP")
-                != PackageManager.PERMISSION_GRANTED) {
-            pw.println("Permission Denial: can't dump WindowManager from from pid="
-                    + Binder.getCallingPid()
-                    + ", uid=" + Binder.getCallingUid());
-            return;
-        }
-
-        boolean dumpAll = false;
-
-        int opti = 0;
-        while (opti < args.length) {
-            String opt = args[opti];
-            if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
-                break;
-            }
-            opti++;
-            if ("-a".equals(opt)) {
-                dumpAll = true;
-            } else if ("-h".equals(opt)) {
-                pw.println("Window manager dump options:");
-                pw.println("  [-a] [-h] [cmd] ...");
-                pw.println("  cmd may be one of:");
-                pw.println("    l[astanr]: last ANR information");
-                pw.println("    p[policy]: policy state");
-                pw.println("    a[animator]: animator state");
-                pw.println("    s[essions]: active sessions");
-                pw.println("    d[isplays]: active display contents");
-                pw.println("    t[okens]: token list");
-                pw.println("    w[indows]: window list");
-                pw.println("  cmd may also be a NAME to dump windows.  NAME may");
-                pw.println("    be a partial substring in a window name, a");
-                pw.println("    Window hex object identifier, or");
-                pw.println("    \"all\" for all windows, or");
-                pw.println("    \"visible\" for the visible windows.");
-                pw.println("  -a: include all available server state.");
-                return;
-            } else {
-                pw.println("Unknown argument: " + opt + "; use -h for help");
-            }
-        }
-
-        // Is the caller requesting to dump a particular piece of data?
-        if (opti < args.length) {
-            String cmd = args[opti];
-            opti++;
-            if ("lastanr".equals(cmd) || "l".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpLastANRLocked(pw);
-                }
-                return;
-            } else if ("policy".equals(cmd) || "p".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpPolicyLocked(pw, args, true);
-                }
-                return;
-            } else if ("animator".equals(cmd) || "a".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpAnimatorLocked(pw, args, true);
-                }
-                return;
-            } else if ("sessions".equals(cmd) || "s".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpSessionsLocked(pw, true);
-                }
-                return;
-            } else if ("displays".equals(cmd) || "d".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpDisplayContentsLocked(pw, true);
-                }
-                return;
-            } else if ("tokens".equals(cmd) || "t".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpTokensLocked(pw, true);
-                }
-                return;
-            } else if ("windows".equals(cmd) || "w".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpWindowsLocked(pw, true, null);
-                }
-                return;
-            } else if ("all".equals(cmd) || "a".equals(cmd)) {
-                synchronized(mWindowMap) {
-                    dumpWindowsLocked(pw, true, null);
-                }
-                return;
-            } else {
-                // Dumping a single name?
-                if (!dumpWindows(pw, cmd, args, opti, dumpAll)) {
-                    pw.println("Bad window command, or no windows match: " + cmd);
-                    pw.println("Use -h for help.");
-                }
-                return;
-            }
-        }
-
-        synchronized(mWindowMap) {
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpLastANRLocked(pw);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpPolicyLocked(pw, args, dumpAll);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpAnimatorLocked(pw, args, dumpAll);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpSessionsLocked(pw, dumpAll);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpDisplayContentsLocked(pw, dumpAll);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpTokensLocked(pw, dumpAll);
-            pw.println();
-            if (dumpAll) {
-                pw.println("-------------------------------------------------------------------------------");
-            }
-            dumpWindowsLocked(pw, dumpAll, null);
-        }
-    }
-
-    // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
-    @Override
-    public void monitor() {
-        synchronized (mWindowMap) { }
-    }
-
-    public interface OnHardKeyboardStatusChangeListener {
-        public void onHardKeyboardStatusChange(boolean available, boolean enabled);
-    }
-
-    void debugLayoutRepeats(final String msg, int pendingLayoutChanges) {
-        if (mLayoutRepeatCount >= LAYOUT_REPEAT_THRESHOLD) {
-            Slog.v(TAG, "Layouts looping: " + msg + ", mPendingLayoutChanges = 0x" +
-                    Integer.toHexString(pendingLayoutChanges));
-        }
-    }
-
-    private DisplayContent newDisplayContentLocked(final Display display) {
-        DisplayContent displayContent = new DisplayContent(display, this);
-        final int displayId = display.getDisplayId();
-        mDisplayContents.put(displayId, displayContent);
-
-        DisplayInfo displayInfo = displayContent.getDisplayInfo();
-        final Rect rect = new Rect();
-        mDisplaySettings.getOverscanLocked(displayInfo.name, rect);
-        synchronized (displayContent.mDisplaySizeLock) {
-            displayInfo.overscanLeft = rect.left;
-            displayInfo.overscanTop = rect.top;
-            displayInfo.overscanRight = rect.right;
-            displayInfo.overscanBottom = rect.bottom;
-            mDisplayManagerService.setDisplayInfoOverrideFromWindowManager(
-                    displayId, displayInfo);
-        }
-        configureDisplayPolicyLocked(displayContent);
-
-        // TODO: Create an input channel for each display with touch capability.
-        if (displayId == Display.DEFAULT_DISPLAY) {
-            displayContent.mTapDetector = new StackTapPointerEventListener(this, displayContent);
-            registerPointerEventListener(displayContent.mTapDetector);
-        }
-
-        return displayContent;
-    }
-
-    public void createDisplayContentLocked(final Display display) {
-        if (display == null) {
-            throw new IllegalArgumentException("getDisplayContent: display must not be null");
-        }
-        getDisplayContentLocked(display.getDisplayId());
-    }
-
-    /**
-     * Retrieve the DisplayContent for the specified displayId. Will create a new DisplayContent if
-     * there is a Display for the displayId.
-     * @param displayId The display the caller is interested in.
-     * @return The DisplayContent associated with displayId or null if there is no Display for it.
-     */
-    public DisplayContent getDisplayContentLocked(final int displayId) {
-        DisplayContent displayContent = mDisplayContents.get(displayId);
-        if (displayContent == null) {
-            final Display display = mDisplayManager.getDisplay(displayId);
-            if (display != null) {
-                displayContent = newDisplayContentLocked(display);
-            }
-        }
-        return displayContent;
-    }
-
-    // There is an inherent assumption that this will never return null.
-    public DisplayContent getDefaultDisplayContentLocked() {
-        return getDisplayContentLocked(Display.DEFAULT_DISPLAY);
-    }
-
-    public WindowList getDefaultWindowListLocked() {
-        return getDefaultDisplayContentLocked().getWindowList();
-    }
-
-    public DisplayInfo getDefaultDisplayInfoLocked() {
-        return getDefaultDisplayContentLocked().getDisplayInfo();
-    }
-
-    /**
-     * Return the list of WindowStates associated on the passed display.
-     * @param display The screen to return windows from.
-     * @return The list of WindowStates on the screen, or null if the there is no screen.
-     */
-    public WindowList getWindowListLocked(final Display display) {
-        return getWindowListLocked(display.getDisplayId());
-    }
-
-    /**
-     * Return the list of WindowStates associated on the passed display.
-     * @param displayId The screen to return windows from.
-     * @return The list of WindowStates on the screen, or null if the there is no screen.
-     */
-    public WindowList getWindowListLocked(final int displayId) {
-        final DisplayContent displayContent = getDisplayContentLocked(displayId);
-        return displayContent != null ? displayContent.getWindowList() : null;
-    }
-
-    @Override
-    public void onDisplayAdded(int displayId) {
-        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0));
-    }
-
-    private void handleDisplayAddedLocked(int displayId) {
-        final Display display = mDisplayManager.getDisplay(displayId);
-        if (display != null) {
-            createDisplayContentLocked(display);
-            displayReady(displayId);
-        }
-    }
-
-    @Override
-    public void onDisplayRemoved(int displayId) {
-        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0));
-    }
-
-    private void handleDisplayRemovedLocked(int displayId) {
-        final DisplayContent displayContent = getDisplayContentLocked(displayId);
-        if (displayContent != null) {
-            mDisplayContents.delete(displayId);
-            displayContent.close();
-            if (displayId == Display.DEFAULT_DISPLAY) {
-                unregisterPointerEventListener(displayContent.mTapDetector);
-            }
-            WindowList windows = displayContent.getWindowList();
-            while (!windows.isEmpty()) {
-                final WindowState win = windows.get(windows.size() - 1);
-                removeWindowLocked(win.mSession, win);
-            }
-        }
-        mAnimator.removeDisplayLocked(displayId);
-    }
-
-    @Override
-    public void onDisplayChanged(int displayId) {
-        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0));
-    }
-
-    private void handleDisplayChangedLocked(int displayId) {
-        final DisplayContent displayContent = getDisplayContentLocked(displayId);
-        if (displayContent != null) {
-            displayContent.updateDisplayInfo();
-        }
-    }
-
-    @Override
-    public Object getWindowManagerLock() {
-        return mWindowMap;
-    }
-}
diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java
deleted file mode 100644
index 4d53cea..0000000
--- a/services/java/com/android/server/wm/WindowState.java
+++ /dev/null
@@ -1,1481 +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.server.wm;
-
-import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
-import static com.android.server.wm.WindowManagerService.DEBUG_LAYOUT;
-
-import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
-import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
-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_KEYGUARD;
-import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
-
-import android.app.AppOpsManager;
-import android.os.RemoteCallbackList;
-import android.util.TimeUtils;
-import android.view.IWindowFocusObserver;
-import android.view.IWindowId;
-import com.android.server.input.InputWindowHandle;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.graphics.Matrix;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.Region;
-import android.os.IBinder;
-import android.os.RemoteException;
-import android.os.UserHandle;
-import android.util.Slog;
-import android.view.DisplayInfo;
-import android.view.Gravity;
-import android.view.IApplicationToken;
-import android.view.IWindow;
-import android.view.InputChannel;
-import android.view.View;
-import android.view.ViewTreeObserver;
-import android.view.WindowManager;
-import android.view.WindowManagerPolicy;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-class WindowList extends ArrayList<WindowState> {
-}
-
-/**
- * A window in the window manager.
- */
-final class WindowState implements WindowManagerPolicy.WindowState {
-    static final String TAG = "WindowState";
-
-    final WindowManagerService mService;
-    final WindowManagerPolicy mPolicy;
-    final Context mContext;
-    final Session mSession;
-    final IWindow mClient;
-    final int mAppOp;
-    // UserId and appId of the owner. Don't display windows of non-current user.
-    final int mOwnerUid;
-    final IWindowId mWindowId;
-    WindowToken mToken;
-    WindowToken mRootToken;
-    AppWindowToken mAppToken;
-    AppWindowToken mTargetAppToken;
-
-    // mAttrs.flags is tested in animation without being locked. If the bits tested are ever
-    // modified they will need to be locked.
-    final WindowManager.LayoutParams mAttrs = new WindowManager.LayoutParams();
-    final DeathRecipient mDeathRecipient;
-    final WindowState mAttachedWindow;
-    final WindowList mChildWindows = new WindowList();
-    final int mBaseLayer;
-    final int mSubLayer;
-    final boolean mLayoutAttached;
-    final boolean mIsImWindow;
-    final boolean mIsWallpaper;
-    final boolean mIsFloatingLayer;
-    int mSeq;
-    boolean mEnforceSizeCompat;
-    int mViewVisibility;
-    int mSystemUiVisibility;
-    boolean mPolicyVisibility = true;
-    boolean mPolicyVisibilityAfterAnim = true;
-    boolean mAppOpVisibility = true;
-    boolean mAppFreezing;
-    boolean mAttachedHidden;    // is our parent window hidden?
-    boolean mWallpaperVisible;  // for wallpaper, what was last vis report?
-
-    RemoteCallbackList<IWindowFocusObserver> mFocusCallbacks;
-
-    /**
-     * The window size that was requested by the application.  These are in
-     * the application's coordinate space (without compatibility scale applied).
-     */
-    int mRequestedWidth;
-    int mRequestedHeight;
-    int mLastRequestedWidth;
-    int mLastRequestedHeight;
-
-    int mLayer;
-    boolean mHaveFrame;
-    boolean mObscured;
-    boolean mTurnOnScreen;
-
-    int mLayoutSeq = -1;
-
-    Configuration mConfiguration = null;
-    // Sticky answer to isConfigChanged(), remains true until new Configuration is assigned.
-    // Used only on {@link #TYPE_KEYGUARD}.
-    private boolean mConfigHasChanged;
-
-    /**
-     * Actual frame shown on-screen (may be modified by animation).  These
-     * are in the screen's coordinate space (WITH the compatibility scale
-     * applied).
-     */
-    final RectF mShownFrame = new RectF();
-
-    /**
-     * Insets that determine the actually visible area.  These are in the application's
-     * coordinate space (without compatibility scale applied).
-     */
-    final Rect mVisibleInsets = new Rect();
-    final Rect mLastVisibleInsets = new Rect();
-    boolean mVisibleInsetsChanged;
-
-    /**
-     * Insets that are covered by system windows (such as the status bar) and
-     * transient docking windows (such as the IME).  These are in the application's
-     * coordinate space (without compatibility scale applied).
-     */
-    final Rect mContentInsets = new Rect();
-    final Rect mLastContentInsets = new Rect();
-    boolean mContentInsetsChanged;
-
-    /**
-     * Insets that determine the area covered by the display overscan region.  These are in the
-     * application's coordinate space (without compatibility scale applied).
-     */
-    final Rect mOverscanInsets = new Rect();
-    final Rect mLastOverscanInsets = new Rect();
-    boolean mOverscanInsetsChanged;
-
-    /**
-     * Set to true if we are waiting for this window to receive its
-     * given internal insets before laying out other windows based on it.
-     */
-    boolean mGivenInsetsPending;
-
-    /**
-     * These are the content insets that were given during layout for
-     * this window, to be applied to windows behind it.
-     */
-    final Rect mGivenContentInsets = new Rect();
-
-    /**
-     * These are the visible insets that were given during layout for
-     * this window, to be applied to windows behind it.
-     */
-    final Rect mGivenVisibleInsets = new Rect();
-
-    /**
-     * This is the given touchable area relative to the window frame, or null if none.
-     */
-    final Region mGivenTouchableRegion = new Region();
-
-    /**
-     * Flag indicating whether the touchable region should be adjusted by
-     * the visible insets; if false the area outside the visible insets is
-     * NOT touchable, so we must use those to adjust the frame during hit
-     * tests.
-     */
-    int mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME;
-
-    /**
-     * This is rectangle of the window's surface that is not covered by
-     * system decorations.
-     */
-    final Rect mSystemDecorRect = new Rect();
-    final Rect mLastSystemDecorRect = new Rect();
-
-    // Current transformation being applied.
-    float mGlobalScale=1;
-    float mInvGlobalScale=1;
-    float mHScale=1, mVScale=1;
-    float mLastHScale=1, mLastVScale=1;
-    final Matrix mTmpMatrix = new Matrix();
-
-    // "Real" frame that the application sees, in display coordinate space.
-    final Rect mFrame = new Rect();
-    final Rect mLastFrame = new Rect();
-    // Frame that is scaled to the application's coordinate space when in
-    // screen size compatibility mode.
-    final Rect mCompatFrame = new Rect();
-
-    final Rect mContainingFrame = new Rect();
-    final Rect mDisplayFrame = new Rect();
-    final Rect mOverscanFrame = new Rect();
-    final Rect mContentFrame = new Rect();
-    final Rect mParentFrame = new Rect();
-    final Rect mVisibleFrame = new Rect();
-    final Rect mDecorFrame = new Rect();
-
-    boolean mContentChanged;
-
-    // If a window showing a wallpaper: the requested offset for the
-    // wallpaper; if a wallpaper window: the currently applied offset.
-    float mWallpaperX = -1;
-    float mWallpaperY = -1;
-
-    // If a window showing a wallpaper: what fraction of the offset
-    // range corresponds to a full virtual screen.
-    float mWallpaperXStep = -1;
-    float mWallpaperYStep = -1;
-
-    // Wallpaper windows: pixels offset based on above variables.
-    int mXOffset;
-    int mYOffset;
-
-    /**
-     * This is set after IWindowSession.relayout() has been called at
-     * least once for the window.  It allows us to detect the situation
-     * where we don't yet have a surface, but should have one soon, so
-     * we can give the window focus before waiting for the relayout.
-     */
-    boolean mRelayoutCalled;
-
-    /**
-     * If the application has called relayout() with changes that can
-     * impact its window's size, we need to perform a layout pass on it
-     * even if it is not currently visible for layout.  This is set
-     * when in that case until the layout is done.
-     */
-    boolean mLayoutNeeded;
-
-    /** Currently running an exit animation? */
-    boolean mExiting;
-
-    /** Currently on the mDestroySurface list? */
-    boolean mDestroying;
-
-    /** Completely remove from window manager after exit animation? */
-    boolean mRemoveOnExit;
-
-    /**
-     * Set when the orientation is changing and this window has not yet
-     * been updated for the new orientation.
-     */
-    boolean mOrientationChanging;
-
-    /**
-     * How long we last kept the screen frozen.
-     */
-    int mLastFreezeDuration;
-
-    /** Is this window now (or just being) removed? */
-    boolean mRemoved;
-
-    /**
-     * Temp for keeping track of windows that have been removed when
-     * rebuilding window list.
-     */
-    boolean mRebuilding;
-
-    // Input channel and input window handle used by the input dispatcher.
-    final InputWindowHandle mInputWindowHandle;
-    InputChannel mInputChannel;
-
-    // Used to improve performance of toString()
-    String mStringNameCache;
-    CharSequence mLastTitle;
-    boolean mWasExiting;
-
-    final WindowStateAnimator mWinAnimator;
-
-    boolean mHasSurface = false;
-
-    DisplayContent  mDisplayContent;
-
-    /** When true this window can be displayed on screens owther than mOwnerUid's */
-    private boolean mShowToOwnerOnly;
-
-    /** When true this window is at the top of the screen and should be layed out to extend under
-     * the status bar */
-    boolean mUnderStatusBar = true;
-
-    WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
-           WindowState attachedWindow, int appOp, int seq, WindowManager.LayoutParams a,
-           int viewVisibility, final DisplayContent displayContent) {
-        mService = service;
-        mSession = s;
-        mClient = c;
-        mAppOp = appOp;
-        mToken = token;
-        mOwnerUid = s.mUid;
-        mWindowId = new IWindowId.Stub() {
-            @Override
-            public void registerFocusObserver(IWindowFocusObserver observer) {
-                WindowState.this.registerFocusObserver(observer);
-            }
-            @Override
-            public void unregisterFocusObserver(IWindowFocusObserver observer) {
-                WindowState.this.unregisterFocusObserver(observer);
-            }
-            @Override
-            public boolean isFocused() {
-                return WindowState.this.isFocused();
-            }
-        };
-        mAttrs.copyFrom(a);
-        mViewVisibility = viewVisibility;
-        mDisplayContent = displayContent;
-        mPolicy = mService.mPolicy;
-        mContext = mService.mContext;
-        DeathRecipient deathRecipient = new DeathRecipient();
-        mSeq = seq;
-        mEnforceSizeCompat = (mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0;
-        if (WindowManagerService.localLOGV) Slog.v(
-            TAG, "Window " + this + " client=" + c.asBinder()
-            + " token=" + token + " (" + mAttrs.token + ")" + " params=" + a);
-        try {
-            c.asBinder().linkToDeath(deathRecipient, 0);
-        } catch (RemoteException e) {
-            mDeathRecipient = null;
-            mAttachedWindow = null;
-            mLayoutAttached = false;
-            mIsImWindow = false;
-            mIsWallpaper = false;
-            mIsFloatingLayer = false;
-            mBaseLayer = 0;
-            mSubLayer = 0;
-            mInputWindowHandle = null;
-            mWinAnimator = null;
-            return;
-        }
-        mDeathRecipient = deathRecipient;
-
-        if ((mAttrs.type >= FIRST_SUB_WINDOW &&
-                mAttrs.type <= LAST_SUB_WINDOW)) {
-            // The multiplier here is to reserve space for multiple
-            // windows in the same type layer.
-            mBaseLayer = mPolicy.windowTypeToLayerLw(
-                    attachedWindow.mAttrs.type) * WindowManagerService.TYPE_LAYER_MULTIPLIER
-                    + WindowManagerService.TYPE_LAYER_OFFSET;
-            mSubLayer = mPolicy.subWindowTypeToLayerLw(a.type);
-            mAttachedWindow = attachedWindow;
-            if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Adding " + this + " to " + mAttachedWindow);
-
-            int children_size = mAttachedWindow.mChildWindows.size();
-            if (children_size == 0) {
-                mAttachedWindow.mChildWindows.add(this);
-            } else {
-                for (int i = 0; i < children_size; i++) {
-                    WindowState child = (WindowState)mAttachedWindow.mChildWindows.get(i);
-                    if (this.mSubLayer < child.mSubLayer) {
-                        mAttachedWindow.mChildWindows.add(i, this);
-                        break;
-                    } else if (this.mSubLayer > child.mSubLayer) {
-                        continue;
-                    }
-
-                    if (this.mBaseLayer <= child.mBaseLayer) {
-                        mAttachedWindow.mChildWindows.add(i, this);
-                        break;
-                    } else {
-                        continue;
-                    }
-                }
-                if (children_size == mAttachedWindow.mChildWindows.size()) {
-                    mAttachedWindow.mChildWindows.add(this);
-                }
-            }
-
-            mLayoutAttached = mAttrs.type !=
-                    WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
-            mIsImWindow = attachedWindow.mAttrs.type == TYPE_INPUT_METHOD
-                    || attachedWindow.mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
-            mIsWallpaper = attachedWindow.mAttrs.type == TYPE_WALLPAPER;
-            mIsFloatingLayer = mIsImWindow || mIsWallpaper;
-        } else {
-            // The multiplier here is to reserve space for multiple
-            // windows in the same type layer.
-            mBaseLayer = mPolicy.windowTypeToLayerLw(a.type)
-                    * WindowManagerService.TYPE_LAYER_MULTIPLIER
-                    + WindowManagerService.TYPE_LAYER_OFFSET;
-            mSubLayer = 0;
-            mAttachedWindow = null;
-            mLayoutAttached = false;
-            mIsImWindow = mAttrs.type == TYPE_INPUT_METHOD
-                    || mAttrs.type == TYPE_INPUT_METHOD_DIALOG;
-            mIsWallpaper = mAttrs.type == TYPE_WALLPAPER;
-            mIsFloatingLayer = mIsImWindow || mIsWallpaper;
-        }
-
-        WindowState appWin = this;
-        while (appWin.mAttachedWindow != null) {
-            appWin = appWin.mAttachedWindow;
-        }
-        WindowToken appToken = appWin.mToken;
-        while (appToken.appWindowToken == null) {
-            WindowToken parent = mService.mTokenMap.get(appToken.token);
-            if (parent == null || appToken == parent) {
-                break;
-            }
-            appToken = parent;
-        }
-        mRootToken = appToken;
-        mAppToken = appToken.appWindowToken;
-
-        mWinAnimator = new WindowStateAnimator(this);
-        mWinAnimator.mAlpha = a.alpha;
-
-        mRequestedWidth = 0;
-        mRequestedHeight = 0;
-        mLastRequestedWidth = 0;
-        mLastRequestedHeight = 0;
-        mXOffset = 0;
-        mYOffset = 0;
-        mLayer = 0;
-        mInputWindowHandle = new InputWindowHandle(
-                mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
-                displayContent.getDisplayId());
-    }
-
-    void attach() {
-        if (WindowManagerService.localLOGV) Slog.v(
-            TAG, "Attaching " + this + " token=" + mToken
-            + ", list=" + mToken.windows);
-        mSession.windowAddedLocked();
-    }
-
-    @Override
-    public int getOwningUid() {
-        return mOwnerUid;
-    }
-
-    @Override
-    public String getOwningPackage() {
-        return mAttrs.packageName;
-    }
-
-    @Override
-    public void computeFrameLw(Rect pf, Rect df, Rect of, Rect cf, Rect vf, Rect dcf) {
-        mHaveFrame = true;
-
-        TaskStack stack = mAppToken != null ? getStack() : null;
-        if (stack != null && stack.hasSibling()) {
-            mContainingFrame.set(getStackBounds(stack));
-            if (mUnderStatusBar) {
-                mContainingFrame.top = pf.top;
-            }
-        } else {
-            mContainingFrame.set(pf);
-        }
-
-        mDisplayFrame.set(df);
-
-        final int pw = mContainingFrame.width();
-        final int ph = mContainingFrame.height();
-
-        int w,h;
-        if ((mAttrs.flags & WindowManager.LayoutParams.FLAG_SCALED) != 0) {
-            if (mAttrs.width < 0) {
-                w = pw;
-            } else if (mEnforceSizeCompat) {
-                w = (int)(mAttrs.width * mGlobalScale + .5f);
-            } else {
-                w = mAttrs.width;
-            }
-            if (mAttrs.height < 0) {
-                h = ph;
-            } else if (mEnforceSizeCompat) {
-                h = (int)(mAttrs.height * mGlobalScale + .5f);
-            } else {
-                h = mAttrs.height;
-            }
-        } else {
-            if (mAttrs.width == WindowManager.LayoutParams.MATCH_PARENT) {
-                w = pw;
-            } else if (mEnforceSizeCompat) {
-                w = (int)(mRequestedWidth * mGlobalScale + .5f);
-            } else {
-                w = mRequestedWidth;
-            }
-            if (mAttrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
-                h = ph;
-            } else if (mEnforceSizeCompat) {
-                h = (int)(mRequestedHeight * mGlobalScale + .5f);
-            } else {
-                h = mRequestedHeight;
-            }
-        }
-
-        if (!mParentFrame.equals(pf)) {
-            //Slog.i(TAG, "Window " + this + " content frame from " + mParentFrame
-            //        + " to " + pf);
-            mParentFrame.set(pf);
-            mContentChanged = true;
-        }
-        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
-            mLastRequestedWidth = mRequestedWidth;
-            mLastRequestedHeight = mRequestedHeight;
-            mContentChanged = true;
-        }
-
-        mOverscanFrame.set(of);
-        mContentFrame.set(cf);
-        mVisibleFrame.set(vf);
-        mDecorFrame.set(dcf);
-
-        final int fw = mFrame.width();
-        final int fh = mFrame.height();
-
-        //System.out.println("In: w=" + w + " h=" + h + " container=" +
-        //                   container + " x=" + mAttrs.x + " y=" + mAttrs.y);
-
-        float x, y;
-        if (mEnforceSizeCompat) {
-            x = mAttrs.x * mGlobalScale;
-            y = mAttrs.y * mGlobalScale;
-        } else {
-            x = mAttrs.x;
-            y = mAttrs.y;
-        }
-
-        Gravity.apply(mAttrs.gravity, w, h, mContainingFrame,
-                (int) (x + mAttrs.horizontalMargin * pw),
-                (int) (y + mAttrs.verticalMargin * ph), mFrame);
-
-        //System.out.println("Out: " + mFrame);
-
-        // Now make sure the window fits in the overall display.
-        Gravity.applyDisplay(mAttrs.gravity, df, mFrame);
-
-        // Make sure the content and visible frames are inside of the
-        // final window frame.
-        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));
-
-        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));
-
-        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));
-
-        mContentInsets.set(mContentFrame.left - mFrame.left,
-                mContentFrame.top - mFrame.top,
-                mFrame.right - mContentFrame.right,
-                mFrame.bottom - mContentFrame.bottom);
-
-        mVisibleInsets.set(mVisibleFrame.left - mFrame.left,
-                mVisibleFrame.top - mFrame.top,
-                mFrame.right - mVisibleFrame.right,
-                mFrame.bottom - mVisibleFrame.bottom);
-
-        mCompatFrame.set(mFrame);
-        if (mEnforceSizeCompat) {
-            // If there is a size compatibility scale being applied to the
-            // window, we need to apply this to its insets so that they are
-            // reported to the app in its coordinate space.
-            mOverscanInsets.scale(mInvGlobalScale);
-            mContentInsets.scale(mInvGlobalScale);
-            mVisibleInsets.scale(mInvGlobalScale);
-
-            // Also the scaled frame that we report to the app needs to be
-            // adjusted to be in its coordinate space.
-            mCompatFrame.scale(mInvGlobalScale);
-        }
-
-        if (mIsWallpaper && (fw != mFrame.width() || fh != mFrame.height())) {
-            final DisplayInfo displayInfo = mDisplayContent.getDisplayInfo();
-            mService.updateWallpaperOffsetLocked(this,
-                    displayInfo.logicalWidth, displayInfo.logicalHeight, false);
-        }
-
-        if (DEBUG_LAYOUT || WindowManagerService.localLOGV) Slog.v(TAG,
-                "Resolving (mRequestedWidth="
-                + mRequestedWidth + ", mRequestedheight="
-                + mRequestedHeight + ") to" + " (pw=" + pw + ", ph=" + ph
-                + "): frame=" + mFrame.toShortString()
-                + " ci=" + mContentInsets.toShortString()
-                + " vi=" + mVisibleInsets.toShortString());
-    }
-
-    @Override
-    public Rect getFrameLw() {
-        return mFrame;
-    }
-
-    @Override
-    public RectF getShownFrameLw() {
-        return mShownFrame;
-    }
-
-    @Override
-    public Rect getDisplayFrameLw() {
-        return mDisplayFrame;
-    }
-
-    @Override
-    public Rect getOverscanFrameLw() {
-        return mOverscanFrame;
-    }
-
-    @Override
-    public Rect getContentFrameLw() {
-        return mContentFrame;
-    }
-
-    @Override
-    public Rect getVisibleFrameLw() {
-        return mVisibleFrame;
-    }
-
-    @Override
-    public boolean getGivenInsetsPendingLw() {
-        return mGivenInsetsPending;
-    }
-
-    @Override
-    public Rect getGivenContentInsetsLw() {
-        return mGivenContentInsets;
-    }
-
-    @Override
-    public Rect getGivenVisibleInsetsLw() {
-        return mGivenVisibleInsets;
-    }
-
-    @Override
-    public WindowManager.LayoutParams getAttrs() {
-        return mAttrs;
-    }
-
-    @Override
-    public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
-        int index = -1;
-        WindowState ws = this;
-        WindowList windows = getWindowList();
-        while (true) {
-            if ((ws.mAttrs.privateFlags
-                    & WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
-                return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
-            }
-            // If we reached the bottom of the range of windows we are considering,
-            // assume no menu is needed.
-            if (ws == bottom) {
-                return false;
-            }
-            // The current window hasn't specified whether menu key is needed;
-            // look behind it.
-            // First, we may need to determine the starting position.
-            if (index < 0) {
-                index = windows.indexOf(ws);
-            }
-            index--;
-            if (index < 0) {
-                return false;
-            }
-            ws = windows.get(index);
-        }
-    }
-
-    @Override
-    public int getSystemUiVisibility() {
-        return mSystemUiVisibility;
-    }
-
-    @Override
-    public int getSurfaceLayer() {
-        return mLayer;
-    }
-
-    @Override
-    public IApplicationToken getAppToken() {
-        return mAppToken != null ? mAppToken.appToken : null;
-    }
-
-    boolean setInsetsChanged() {
-        mOverscanInsetsChanged |= !mLastOverscanInsets.equals(mOverscanInsets);
-        mContentInsetsChanged |= !mLastContentInsets.equals(mContentInsets);
-        mVisibleInsetsChanged |= !mLastVisibleInsets.equals(mVisibleInsets);
-        return mOverscanInsetsChanged || mContentInsetsChanged || mVisibleInsetsChanged;
-    }
-
-    public int getDisplayId() {
-        return mDisplayContent.getDisplayId();
-    }
-
-    TaskStack getStack() {
-        AppWindowToken wtoken = mAppToken == null ? mService.mFocusedApp : mAppToken;
-        if (wtoken != null) {
-            Task task = mService.mTaskIdToTask.get(wtoken.groupId);
-            if (task != null) {
-                return task.mStack;
-            }
-        }
-        return mDisplayContent.getHomeStack();
-    }
-
-    Rect getStackBounds() {
-        return getStackBounds(getStack());
-    }
-
-    private Rect getStackBounds(TaskStack stack) {
-        if (stack != null) {
-            return stack.mStackBox.mBounds;
-        }
-        return mFrame;
-    }
-
-    public long getInputDispatchingTimeoutNanos() {
-        return mAppToken != null
-                ? mAppToken.inputDispatchingTimeoutNanos
-                : WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
-    }
-
-    @Override
-    public boolean hasAppShownWindows() {
-        return mAppToken != null && (mAppToken.firstWindowDrawn || mAppToken.startingDisplayed);
-    }
-
-    boolean isIdentityMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
-        if (dsdx < .99999f || dsdx > 1.00001f) return false;
-        if (dtdy < .99999f || dtdy > 1.00001f) return false;
-        if (dtdx < -.000001f || dtdx > .000001f) return false;
-        if (dsdy < -.000001f || dsdy > .000001f) return false;
-        return true;
-    }
-
-    void prelayout() {
-        if (mEnforceSizeCompat) {
-            mGlobalScale = mService.mCompatibleScreenScale;
-            mInvGlobalScale = 1/mGlobalScale;
-        } else {
-            mGlobalScale = mInvGlobalScale = 1;
-        }
-    }
-
-    /**
-     * Is this window visible?  It is not visible if there is no
-     * surface, or we are in the process of running an exit animation
-     * that will remove the surface, or its app token has been hidden.
-     */
-    @Override
-    public boolean isVisibleLw() {
-        final AppWindowToken atoken = mAppToken;
-        return mHasSurface && mPolicyVisibility && !mAttachedHidden
-                && (atoken == null || !atoken.hiddenRequested)
-                && !mExiting && !mDestroying;
-    }
-
-    /**
-     * Like {@link #isVisibleLw}, but also counts a window that is currently
-     * "hidden" behind the keyguard as visible.  This allows us to apply
-     * things like window flags that impact the keyguard.
-     * XXX I am starting to think we need to have ANOTHER visibility flag
-     * for this "hidden behind keyguard" state rather than overloading
-     * mPolicyVisibility.  Ungh.
-     */
-    @Override
-    public boolean isVisibleOrBehindKeyguardLw() {
-        if (mRootToken.waitingToShow &&
-                mService.mAppTransition.isTransitionSet()) {
-            return false;
-        }
-        final AppWindowToken atoken = mAppToken;
-        final boolean animating = atoken != null
-                ? (atoken.mAppAnimator.animation != null) : false;
-        return mHasSurface && !mDestroying && !mExiting
-                && (atoken == null ? mPolicyVisibility : !atoken.hiddenRequested)
-                && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
-                                && !mRootToken.hidden)
-                        || mWinAnimator.mAnimation != null || animating);
-    }
-
-    /**
-     * Is this window visible, ignoring its app token?  It is not visible
-     * if there is no surface, or we are in the process of running an exit animation
-     * that will remove the surface.
-     */
-    public boolean isWinVisibleLw() {
-        final AppWindowToken atoken = mAppToken;
-        return mHasSurface && mPolicyVisibility && !mAttachedHidden
-                && (atoken == null || !atoken.hiddenRequested || atoken.mAppAnimator.animating)
-                && !mExiting && !mDestroying;
-    }
-
-    /**
-     * The same as isVisible(), but follows the current hidden state of
-     * the associated app token, not the pending requested hidden state.
-     */
-    boolean isVisibleNow() {
-        return mHasSurface && mPolicyVisibility && !mAttachedHidden
-                && !mRootToken.hidden && !mExiting && !mDestroying;
-    }
-
-    /**
-     * Can this window possibly be a drag/drop target?  The test here is
-     * a combination of the above "visible now" with the check that the
-     * Input Manager uses when discarding windows from input consideration.
-     */
-    boolean isPotentialDragTarget() {
-        return isVisibleNow() && !mRemoved
-                && mInputChannel != null && mInputWindowHandle != null;
-    }
-
-    /**
-     * Same as isVisible(), but we also count it as visible between the
-     * call to IWindowSession.add() and the first relayout().
-     */
-    boolean isVisibleOrAdding() {
-        final AppWindowToken atoken = mAppToken;
-        return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
-                && mPolicyVisibility && !mAttachedHidden
-                && (atoken == null || !atoken.hiddenRequested)
-                && !mExiting && !mDestroying;
-    }
-
-    /**
-     * Is this window currently on-screen?  It is on-screen either if it
-     * is visible or it is currently running an animation before no longer
-     * being visible.
-     */
-    boolean isOnScreen() {
-        if (!mHasSurface || !mPolicyVisibility || mDestroying) {
-            return false;
-        }
-        final AppWindowToken atoken = mAppToken;
-        if (atoken != null) {
-            return ((!mAttachedHidden && !atoken.hiddenRequested)
-                    || mWinAnimator.mAnimation != null || atoken.mAppAnimator.animation != null);
-        }
-        return !mAttachedHidden || mWinAnimator.mAnimation != null;
-    }
-
-    /**
-     * Like isOnScreen(), but we don't return true if the window is part
-     * of a transition that has not yet been started.
-     */
-    boolean isReadyForDisplay() {
-        if (mRootToken.waitingToShow &&
-                mService.mAppTransition.isTransitionSet()) {
-            return false;
-        }
-        return mHasSurface && mPolicyVisibility && !mDestroying
-                && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
-                                && !mRootToken.hidden)
-                        || mWinAnimator.mAnimation != null
-                        || ((mAppToken != null) && (mAppToken.mAppAnimator.animation != null)));
-    }
-
-    /**
-     * Like isReadyForDisplay(), but ignores any force hiding of the window due
-     * to the keyguard.
-     */
-    boolean isReadyForDisplayIgnoringKeyguard() {
-        if (mRootToken.waitingToShow && mService.mAppTransition.isTransitionSet()) {
-            return false;
-        }
-        final AppWindowToken atoken = mAppToken;
-        if (atoken == null && !mPolicyVisibility) {
-            // If this is not an app window, and the policy has asked to force
-            // hide, then we really do want to hide.
-            return false;
-        }
-        return mHasSurface && !mDestroying
-                && ((!mAttachedHidden && mViewVisibility == View.VISIBLE
-                                && !mRootToken.hidden)
-                        || mWinAnimator.mAnimation != null
-                        || ((atoken != null) && (atoken.mAppAnimator.animation != null)
-                                && !mWinAnimator.isDummyAnimation()));
-    }
-
-    /**
-     * Like isOnScreen, but returns false if the surface hasn't yet
-     * been drawn.
-     */
-    @Override
-    public boolean isDisplayedLw() {
-        final AppWindowToken atoken = mAppToken;
-        return isDrawnLw() && mPolicyVisibility
-            && ((!mAttachedHidden &&
-                    (atoken == null || !atoken.hiddenRequested))
-                        || mWinAnimator.mAnimating
-                        || (atoken != null && atoken.mAppAnimator.animation != null));
-    }
-
-    /**
-     * Return true if this window or its app token is currently animating.
-     */
-    @Override
-    public boolean isAnimatingLw() {
-        return mWinAnimator.mAnimation != null
-                || (mAppToken != null && mAppToken.mAppAnimator.animation != null);
-    }
-
-    @Override
-    public boolean isGoneForLayoutLw() {
-        final AppWindowToken atoken = mAppToken;
-        return mViewVisibility == View.GONE
-                || !mRelayoutCalled
-                || (atoken == null && mRootToken.hidden)
-                || (atoken != null && (atoken.hiddenRequested || atoken.hidden))
-                || mAttachedHidden
-                || (mExiting && !isAnimatingLw())
-                || mDestroying;
-    }
-
-    /**
-     * Returns true if the window has a surface that it has drawn a
-     * complete UI in to.
-     */
-    public boolean isDrawFinishedLw() {
-        return mHasSurface && !mDestroying &&
-                (mWinAnimator.mDrawState == WindowStateAnimator.COMMIT_DRAW_PENDING
-                || mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
-                || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
-    }
-
-    /**
-     * Returns true if the window has a surface that it has drawn a
-     * complete UI in to.
-     */
-    public boolean isDrawnLw() {
-        return mHasSurface && !mDestroying &&
-                (mWinAnimator.mDrawState == WindowStateAnimator.READY_TO_SHOW
-                || mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN);
-    }
-
-    /**
-     * Return true if the window is opaque and fully drawn.  This indicates
-     * it may obscure windows behind it.
-     */
-    boolean isOpaqueDrawn() {
-        return (mAttrs.format == PixelFormat.OPAQUE
-                        || mAttrs.type == TYPE_WALLPAPER)
-                && isDrawnLw() && mWinAnimator.mAnimation == null
-                && (mAppToken == null || mAppToken.mAppAnimator.animation == null);
-    }
-
-    /**
-     * Return whether this window is wanting to have a translation
-     * animation applied to it for an in-progress move.  (Only makes
-     * sense to call from performLayoutAndPlaceSurfacesLockedInner().)
-     */
-    boolean shouldAnimateMove() {
-        return mContentChanged && !mExiting && !mWinAnimator.mLastHidden && mService.okToDisplay()
-                && (mFrame.top != mLastFrame.top
-                        || mFrame.left != mLastFrame.left)
-                && (mAttrs.privateFlags&PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
-                && (mAttachedWindow == null || !mAttachedWindow.shouldAnimateMove());
-    }
-
-    boolean isFullscreen(int screenWidth, int screenHeight) {
-        return mFrame.left <= 0 && mFrame.top <= 0 &&
-                mFrame.right >= screenWidth && mFrame.bottom >= screenHeight;
-    }
-
-    boolean isConfigChanged() {
-        boolean configChanged = mConfiguration != mService.mCurConfiguration
-                && (mConfiguration == null
-                        || (mConfiguration.diff(mService.mCurConfiguration) != 0));
-
-        if (mAttrs.type == TYPE_KEYGUARD) {
-            // Retain configuration changed status until resetConfiguration called.
-            mConfigHasChanged |= configChanged;
-            configChanged = mConfigHasChanged;
-        }
-
-        return configChanged;
-    }
-
-    void removeLocked() {
-        disposeInputChannel();
-
-        if (mAttachedWindow != null) {
-            if (WindowManagerService.DEBUG_ADD_REMOVE) Slog.v(TAG, "Removing " + this + " from " + mAttachedWindow);
-            mAttachedWindow.mChildWindows.remove(this);
-        }
-        mWinAnimator.destroyDeferredSurfaceLocked();
-        mWinAnimator.destroySurfaceLocked();
-        mSession.windowRemovedLocked();
-        try {
-            mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
-        } catch (RuntimeException e) {
-            // Ignore if it has already been removed (usually because
-            // we are doing this as part of processing a death note.)
-        }
-    }
-
-    void setConfiguration(final Configuration newConfig) {
-        mConfiguration = newConfig;
-        mConfigHasChanged = false;
-    }
-
-    void setInputChannel(InputChannel inputChannel) {
-        if (mInputChannel != null) {
-            throw new IllegalStateException("Window already has an input channel.");
-        }
-
-        mInputChannel = inputChannel;
-        mInputWindowHandle.inputChannel = inputChannel;
-    }
-
-    void disposeInputChannel() {
-        if (mInputChannel != null) {
-            mService.mInputManager.unregisterInputChannel(mInputChannel);
-
-            mInputChannel.dispose();
-            mInputChannel = null;
-        }
-
-        mInputWindowHandle.inputChannel = null;
-    }
-
-    private class DeathRecipient implements IBinder.DeathRecipient {
-        @Override
-        public void binderDied() {
-            try {
-                synchronized(mService.mWindowMap) {
-                    WindowState win = mService.windowForClientLocked(mSession, mClient, false);
-                    Slog.i(TAG, "WIN DEATH: " + win);
-                    if (win != null) {
-                        mService.removeWindowLocked(mSession, win);
-                    } else if (mHasSurface) {
-                        Slog.e(TAG, "!!! LEAK !!! Window removed but surface still valid.");
-                        mService.removeWindowLocked(mSession, WindowState.this);
-                    }
-                }
-            } catch (IllegalArgumentException ex) {
-                // This will happen if the window has already been
-                // removed.
-            }
-        }
-    }
-
-    /**
-     * @return true if this window desires key events.
-     */
-    public final boolean canReceiveKeys() {
-        return isVisibleOrAdding()
-                && (mViewVisibility == View.VISIBLE)
-                && ((mAttrs.flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) == 0);
-    }
-
-    @Override
-    public boolean hasDrawnLw() {
-        return mWinAnimator.mDrawState == WindowStateAnimator.HAS_DRAWN;
-    }
-
-    @Override
-    public boolean showLw(boolean doAnimation) {
-        return showLw(doAnimation, true);
-    }
-
-    boolean showLw(boolean doAnimation, boolean requestAnim) {
-        if (isHiddenFromUserLocked()) {
-            Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
-                    + this + ", type " + mAttrs.type + ", belonging to " + mOwnerUid);
-            return false;
-        }
-        if (!mAppOpVisibility) {
-            // Being hidden due to app op request.
-            return false;
-        }
-        if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
-            // Already showing.
-            return false;
-        }
-        if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
-        if (doAnimation) {
-            if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
-                    + mPolicyVisibility + " mAnimation=" + mWinAnimator.mAnimation);
-            if (!mService.okToDisplay()) {
-                doAnimation = false;
-            } else if (mPolicyVisibility && mWinAnimator.mAnimation == null) {
-                // Check for the case where we are currently visible and
-                // not animating; we do not want to do animation at such a
-                // point to become visible when we already are.
-                doAnimation = false;
-            }
-        }
-        mPolicyVisibility = true;
-        mPolicyVisibilityAfterAnim = true;
-        if (doAnimation) {
-            mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_ENTER, true);
-        }
-        if (requestAnim) {
-            mService.scheduleAnimationLocked();
-        }
-        return true;
-    }
-
-    @Override
-    public boolean hideLw(boolean doAnimation) {
-        return hideLw(doAnimation, true);
-    }
-
-    boolean hideLw(boolean doAnimation, boolean requestAnim) {
-        if (doAnimation) {
-            if (!mService.okToDisplay()) {
-                doAnimation = false;
-            }
-        }
-        boolean current = doAnimation ? mPolicyVisibilityAfterAnim
-                : mPolicyVisibility;
-        if (!current) {
-            // Already hiding.
-            return false;
-        }
-        if (doAnimation) {
-            mWinAnimator.applyAnimationLocked(WindowManagerPolicy.TRANSIT_EXIT, false);
-            if (mWinAnimator.mAnimation == null) {
-                doAnimation = false;
-            }
-        }
-        if (doAnimation) {
-            mPolicyVisibilityAfterAnim = false;
-        } else {
-            if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
-            mPolicyVisibilityAfterAnim = false;
-            mPolicyVisibility = false;
-            // Window is no longer visible -- make sure if we were waiting
-            // for it to be displayed before enabling the display, that
-            // we allow the display to be enabled now.
-            mService.enableScreenIfNeededLocked();
-            if (mService.mCurrentFocus == this) {
-                if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
-                        "WindowState.hideLw: setting mFocusMayChange true");
-                mService.mFocusMayChange = true;
-            }
-        }
-        if (requestAnim) {
-            mService.scheduleAnimationLocked();
-        }
-        return true;
-    }
-
-    public void setAppOpVisibilityLw(boolean state) {
-        if (mAppOpVisibility != state) {
-            mAppOpVisibility = state;
-            if (state) {
-                // If the policy visibility had last been to hide, then this
-                // will incorrectly show at this point since we lost that
-                // information.  Not a big deal -- for the windows that have app
-                // ops modifies they should only be hidden by policy due to the
-                // lock screen, and the user won't be changing this if locked.
-                // Plus it will quickly be fixed the next time we do a layout.
-                showLw(true, true);
-            } else {
-                hideLw(true, true);
-            }
-        }
-    }
-
-    @Override
-    public boolean isAlive() {
-        return mClient.asBinder().isBinderAlive();
-    }
-
-    boolean isClosing() {
-        return mExiting || (mService.mClosingApps.contains(mAppToken));
-    }
-
-    @Override
-    public boolean isDefaultDisplay() {
-        return mDisplayContent.isDefaultDisplay;
-    }
-
-    public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
-        mShowToOwnerOnly = showToOwnerOnly;
-    }
-
-    boolean isHiddenFromUserLocked() {
-        // Attached windows are evaluated based on the window that they are attached to.
-        WindowState win = this;
-        while (win.mAttachedWindow != null) {
-            win = win.mAttachedWindow;
-        }
-        if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
-                && win.mAppToken != null && win.mAppToken.showWhenLocked) {
-            // Save some cycles by not calling getDisplayInfo unless it is an application
-            // window intended for all users.
-            final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
-            if (win.mFrame.left <= 0 && win.mFrame.top <= 0
-                    && win.mFrame.right >= displayInfo.appWidth
-                    && win.mFrame.bottom >= displayInfo.appHeight) {
-                // Is a fullscreen window, like the clock alarm. Show to everyone.
-                return false;
-            }
-        }
-
-        return win.mShowToOwnerOnly
-                && UserHandle.getUserId(win.mOwnerUid) != mService.mCurrentUserId;
-    }
-
-    private static void applyInsets(Region outRegion, Rect frame, Rect inset) {
-        outRegion.set(
-                frame.left + inset.left, frame.top + inset.top,
-                frame.right - inset.right, frame.bottom - inset.bottom);
-    }
-
-    public void getTouchableRegion(Region outRegion) {
-        final Rect frame = mFrame;
-        switch (mTouchableInsets) {
-            default:
-            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME:
-                outRegion.set(frame);
-                break;
-            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_CONTENT:
-                applyInsets(outRegion, frame, mGivenContentInsets);
-                break;
-            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE:
-                applyInsets(outRegion, frame, mGivenVisibleInsets);
-                break;
-            case ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION: {
-                final Region givenTouchableRegion = mGivenTouchableRegion;
-                outRegion.set(givenTouchableRegion);
-                outRegion.translate(frame.left, frame.top);
-                break;
-            }
-        }
-    }
-
-    WindowList getWindowList() {
-        return mDisplayContent.getWindowList();
-    }
-
-    /**
-     * Report a focus change.  Must be called with no locks held, and consistently
-     * from the same serialized thread (such as dispatched from a handler).
-     */
-    public void reportFocusChangedSerialized(boolean focused, boolean inTouchMode) {
-        try {
-            mClient.windowFocusChanged(focused, inTouchMode);
-        } catch (RemoteException e) {
-        }
-        if (mFocusCallbacks != null) {
-            final int N = mFocusCallbacks.beginBroadcast();
-            for (int i=0; i<N; i++) {
-                IWindowFocusObserver obs = mFocusCallbacks.getBroadcastItem(i);
-                try {
-                    if (focused) {
-                        obs.focusGained(mWindowId.asBinder());
-                    } else {
-                        obs.focusLost(mWindowId.asBinder());
-                    }
-                } catch (RemoteException e) {
-                }
-            }
-            mFocusCallbacks.finishBroadcast();
-        }
-    }
-
-    public void registerFocusObserver(IWindowFocusObserver observer) {
-        synchronized(mService.mWindowMap) {
-            if (mFocusCallbacks == null) {
-                mFocusCallbacks = new RemoteCallbackList<IWindowFocusObserver>();
-            }
-            mFocusCallbacks.register(observer);
-        }
-    }
-
-    public void unregisterFocusObserver(IWindowFocusObserver observer) {
-        synchronized(mService.mWindowMap) {
-            if (mFocusCallbacks != null) {
-                mFocusCallbacks.unregister(observer);
-            }
-        }
-    }
-
-    public boolean isFocused() {
-        synchronized(mService.mWindowMap) {
-            return mService.mCurrentFocus == this;
-        }
-    }
-
-    void dump(PrintWriter pw, String prefix, boolean dumpAll) {
-        pw.print(prefix); pw.print("mDisplayId="); pw.print(mDisplayContent.getDisplayId());
-                pw.print(" mSession="); pw.print(mSession);
-                pw.print(" mClient="); pw.println(mClient.asBinder());
-        pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
-                pw.print(" mShowToOwnerOnly="); pw.print(mShowToOwnerOnly);
-                pw.print(" package="); pw.print(mAttrs.packageName);
-                pw.print(" appop="); pw.println(AppOpsManager.opToName(mAppOp));
-        pw.print(prefix); pw.print("mAttrs="); pw.println(mAttrs);
-        pw.print(prefix); pw.print("Requested w="); pw.print(mRequestedWidth);
-                pw.print(" h="); pw.print(mRequestedHeight);
-                pw.print(" mLayoutSeq="); pw.println(mLayoutSeq);
-        if (mRequestedWidth != mLastRequestedWidth || mRequestedHeight != mLastRequestedHeight) {
-            pw.print(prefix); pw.print("LastRequested w="); pw.print(mLastRequestedWidth);
-                    pw.print(" h="); pw.println(mLastRequestedHeight);
-        }
-        if (mAttachedWindow != null || mLayoutAttached) {
-            pw.print(prefix); pw.print("mAttachedWindow="); pw.print(mAttachedWindow);
-                    pw.print(" mLayoutAttached="); pw.println(mLayoutAttached);
-        }
-        if (mIsImWindow || mIsWallpaper || mIsFloatingLayer) {
-            pw.print(prefix); pw.print("mIsImWindow="); pw.print(mIsImWindow);
-                    pw.print(" mIsWallpaper="); pw.print(mIsWallpaper);
-                    pw.print(" mIsFloatingLayer="); pw.print(mIsFloatingLayer);
-                    pw.print(" mWallpaperVisible="); pw.println(mWallpaperVisible);
-        }
-        if (dumpAll) {
-            pw.print(prefix); pw.print("mBaseLayer="); pw.print(mBaseLayer);
-                    pw.print(" mSubLayer="); pw.print(mSubLayer);
-                    pw.print(" mAnimLayer="); pw.print(mLayer); pw.print("+");
-                    pw.print((mTargetAppToken != null ?
-                            mTargetAppToken.mAppAnimator.animLayerAdjustment
-                          : (mAppToken != null ? mAppToken.mAppAnimator.animLayerAdjustment : 0)));
-                    pw.print("="); pw.print(mWinAnimator.mAnimLayer);
-                    pw.print(" mLastLayer="); pw.println(mWinAnimator.mLastLayer);
-        }
-        if (dumpAll) {
-            pw.print(prefix); pw.print("mToken="); pw.println(mToken);
-            pw.print(prefix); pw.print("mRootToken="); pw.println(mRootToken);
-            if (mAppToken != null) {
-                pw.print(prefix); pw.print("mAppToken="); pw.println(mAppToken);
-            }
-            if (mTargetAppToken != null) {
-                pw.print(prefix); pw.print("mTargetAppToken="); pw.println(mTargetAppToken);
-            }
-            pw.print(prefix); pw.print("mViewVisibility=0x");
-            pw.print(Integer.toHexString(mViewVisibility));
-            pw.print(" mHaveFrame="); pw.print(mHaveFrame);
-            pw.print(" mObscured="); pw.println(mObscured);
-            pw.print(prefix); pw.print("mSeq="); pw.print(mSeq);
-            pw.print(" mSystemUiVisibility=0x");
-            pw.println(Integer.toHexString(mSystemUiVisibility));
-        }
-        if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
-                || mAttachedHidden) {
-            pw.print(prefix); pw.print("mPolicyVisibility=");
-                    pw.print(mPolicyVisibility);
-                    pw.print(" mPolicyVisibilityAfterAnim=");
-                    pw.print(mPolicyVisibilityAfterAnim);
-                    pw.print(" mAppOpVisibility=");
-                    pw.print(mAppOpVisibility);
-                    pw.print(" mAttachedHidden="); pw.println(mAttachedHidden);
-        }
-        if (!mRelayoutCalled || mLayoutNeeded) {
-            pw.print(prefix); pw.print("mRelayoutCalled="); pw.print(mRelayoutCalled);
-                    pw.print(" mLayoutNeeded="); pw.println(mLayoutNeeded);
-        }
-        if (mXOffset != 0 || mYOffset != 0) {
-            pw.print(prefix); pw.print("Offsets x="); pw.print(mXOffset);
-                    pw.print(" y="); pw.println(mYOffset);
-        }
-        if (dumpAll) {
-            pw.print(prefix); pw.print("mGivenContentInsets=");
-                    mGivenContentInsets.printShortString(pw);
-                    pw.print(" mGivenVisibleInsets=");
-                    mGivenVisibleInsets.printShortString(pw);
-                    pw.println();
-            if (mTouchableInsets != 0 || mGivenInsetsPending) {
-                pw.print(prefix); pw.print("mTouchableInsets="); pw.print(mTouchableInsets);
-                        pw.print(" mGivenInsetsPending="); pw.println(mGivenInsetsPending);
-                Region region = new Region();
-                getTouchableRegion(region);
-                pw.print(prefix); pw.print("touchable region="); pw.println(region);
-            }
-            pw.print(prefix); pw.print("mConfiguration="); pw.println(mConfiguration);
-        }
-        pw.print(prefix); pw.print("mHasSurface="); pw.print(mHasSurface);
-                pw.print(" mShownFrame="); mShownFrame.printShortString(pw);
-                pw.print(" isReadyForDisplay()="); pw.println(isReadyForDisplay());
-        if (dumpAll) {
-            pw.print(prefix); pw.print("mFrame="); mFrame.printShortString(pw);
-                    pw.print(" last="); mLastFrame.printShortString(pw);
-                    pw.println();
-            pw.print(prefix); pw.print("mSystemDecorRect="); mSystemDecorRect.printShortString(pw);
-                    pw.print(" last="); mLastSystemDecorRect.printShortString(pw);
-                    pw.println();
-        }
-        if (mEnforceSizeCompat) {
-            pw.print(prefix); pw.print("mCompatFrame="); mCompatFrame.printShortString(pw);
-                    pw.println();
-        }
-        if (dumpAll) {
-            pw.print(prefix); pw.print("Frames: containing=");
-                    mContainingFrame.printShortString(pw);
-                    pw.print(" parent="); mParentFrame.printShortString(pw);
-                    pw.println();
-            pw.print(prefix); pw.print("    display="); mDisplayFrame.printShortString(pw);
-                    pw.print(" overscan="); mOverscanFrame.printShortString(pw);
-                    pw.println();
-            pw.print(prefix); pw.print("    content="); mContentFrame.printShortString(pw);
-                    pw.print(" visible="); mVisibleFrame.printShortString(pw);
-                    pw.println();
-            pw.print(prefix); pw.print("    decor="); mDecorFrame.printShortString(pw);
-                    pw.println();
-            pw.print(prefix); pw.print("Cur insets: overscan=");
-                    mOverscanInsets.printShortString(pw);
-                    pw.print(" content="); mContentInsets.printShortString(pw);
-                    pw.print(" visible="); mVisibleInsets.printShortString(pw);
-                    pw.println();
-            pw.print(prefix); pw.print("Lst insets: overscan=");
-                    mLastOverscanInsets.printShortString(pw);
-                    pw.print(" content="); mLastContentInsets.printShortString(pw);
-                    pw.print(" visible="); mLastVisibleInsets.printShortString(pw);
-                    pw.println();
-        }
-        pw.print(prefix); pw.print(mWinAnimator); pw.println(":");
-        mWinAnimator.dump(pw, prefix + "  ", dumpAll);
-        if (mExiting || mRemoveOnExit || mDestroying || mRemoved) {
-            pw.print(prefix); pw.print("mExiting="); pw.print(mExiting);
-                    pw.print(" mRemoveOnExit="); pw.print(mRemoveOnExit);
-                    pw.print(" mDestroying="); pw.print(mDestroying);
-                    pw.print(" mRemoved="); pw.println(mRemoved);
-        }
-        if (mOrientationChanging || mAppFreezing || mTurnOnScreen) {
-            pw.print(prefix); pw.print("mOrientationChanging=");
-                    pw.print(mOrientationChanging);
-                    pw.print(" mAppFreezing="); pw.print(mAppFreezing);
-                    pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen);
-        }
-        if (mLastFreezeDuration != 0) {
-            pw.print(prefix); pw.print("mLastFreezeDuration=");
-                    TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println();
-        }
-        if (mHScale != 1 || mVScale != 1) {
-            pw.print(prefix); pw.print("mHScale="); pw.print(mHScale);
-                    pw.print(" mVScale="); pw.println(mVScale);
-        }
-        if (mWallpaperX != -1 || mWallpaperY != -1) {
-            pw.print(prefix); pw.print("mWallpaperX="); pw.print(mWallpaperX);
-                    pw.print(" mWallpaperY="); pw.println(mWallpaperY);
-        }
-        if (mWallpaperXStep != -1 || mWallpaperYStep != -1) {
-            pw.print(prefix); pw.print("mWallpaperXStep="); pw.print(mWallpaperXStep);
-                    pw.print(" mWallpaperYStep="); pw.println(mWallpaperYStep);
-        }
-    }
-
-    String makeInputChannelName() {
-        return Integer.toHexString(System.identityHashCode(this))
-            + " " + mAttrs.getTitle();
-    }
-
-    @Override
-    public String toString() {
-        CharSequence title = mAttrs.getTitle();
-        if (title == null || title.length() <= 0) {
-            title = mAttrs.packageName;
-        }
-        if (mStringNameCache == null || mLastTitle != title || mWasExiting != mExiting) {
-            mLastTitle = title;
-            mWasExiting = mExiting;
-            mStringNameCache = "Window{" + Integer.toHexString(System.identityHashCode(this))
-                    + " u" + UserHandle.getUserId(mSession.mUid)
-                    + " " + mLastTitle + (mExiting ? " EXITING}" : "}");
-        }
-        return mStringNameCache;
-    }
-}
diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java
deleted file mode 100644
index c405170..0000000
--- a/services/java/com/android/server/wm/WindowStateAnimator.java
+++ /dev/null
@@ -1,1660 +0,0 @@
-// Copyright 2012 Google Inc. All Rights Reserved.
-
-package com.android.server.wm;
-
-import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
-import static com.android.server.wm.WindowManagerService.DEBUG_ANIM;
-import static com.android.server.wm.WindowManagerService.DEBUG_LAYERS;
-import static com.android.server.wm.WindowManagerService.DEBUG_ORIENTATION;
-import static com.android.server.wm.WindowManagerService.DEBUG_STARTING_WINDOW;
-import static com.android.server.wm.WindowManagerService.DEBUG_SURFACE_TRACE;
-import static com.android.server.wm.WindowManagerService.SHOW_TRANSACTIONS;
-import static com.android.server.wm.WindowManagerService.DEBUG_VISIBILITY;
-import static com.android.server.wm.WindowManagerService.SHOW_LIGHT_TRANSACTIONS;
-import static com.android.server.wm.WindowManagerService.SHOW_SURFACE_ALLOC;
-import static com.android.server.wm.WindowManagerService.localLOGV;
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_ORIENTATION_CHANGE_COMPLETE;
-import static com.android.server.wm.WindowManagerService.LayoutFields.SET_TURN_ON_SCREEN;
-
-import android.content.Context;
-import android.graphics.Matrix;
-import android.graphics.PixelFormat;
-import android.graphics.Point;
-import android.graphics.PointF;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.Region;
-import android.os.Debug;
-import android.util.Slog;
-import android.view.Display;
-import android.view.DisplayInfo;
-import android.view.MagnificationSpec;
-import android.view.Surface.OutOfResourcesException;
-import android.view.SurfaceControl;
-import android.view.SurfaceSession;
-import android.view.WindowManager;
-import android.view.WindowManagerPolicy;
-import android.view.WindowManager.LayoutParams;
-import android.view.animation.Animation;
-import android.view.animation.AnimationUtils;
-import android.view.animation.Transformation;
-
-import com.android.server.wm.WindowManagerService.H;
-
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-class WinAnimatorList extends ArrayList<WindowStateAnimator> {
-}
-
-/**
- * Keep track of animations and surface operations for a single WindowState.
- **/
-class WindowStateAnimator {
-    static final String TAG = "WindowStateAnimator";
-
-    // Unchanging local convenience fields.
-    final WindowManagerService mService;
-    final WindowState mWin;
-    final WindowStateAnimator mAttachedWinAnimator;
-    final WindowAnimator mAnimator;
-    AppWindowAnimator mAppAnimator;
-    final Session mSession;
-    final WindowManagerPolicy mPolicy;
-    final Context mContext;
-    final boolean mIsWallpaper;
-
-    // If this is a universe background window, this is the transformation
-    // it is applying to the rest of the universe.
-    final Transformation mUniverseTransform = new Transformation();
-
-    // Currently running animation.
-    boolean mAnimating;
-    boolean mLocalAnimating;
-    Animation mAnimation;
-    boolean mAnimationIsEntrance;
-    boolean mHasTransformation;
-    boolean mHasLocalTransformation;
-    final Transformation mTransformation = new Transformation();
-    boolean mWasAnimating;      // Were we animating going into the most recent animation step?
-    int mAnimLayer;
-    int mLastLayer;
-
-    SurfaceControl mSurfaceControl;
-    SurfaceControl mPendingDestroySurface;
-
-    /**
-     * Set when we have changed the size of the surface, to know that
-     * we must tell them application to resize (and thus redraw itself).
-     */
-    boolean mSurfaceResized;
-
-    /**
-     * Set if the client has asked that the destroy of its surface be delayed
-     * until it explicitly says it is okay.
-     */
-    boolean mSurfaceDestroyDeferred;
-
-    float mShownAlpha = 0;
-    float mAlpha = 0;
-    float mLastAlpha = 0;
-
-    // Used to save animation distances between the time they are calculated and when they are
-    // used.
-    int mAnimDw;
-    int mAnimDh;
-    float mDsDx=1, mDtDx=0, mDsDy=0, mDtDy=1;
-    float mLastDsDx=1, mLastDtDx=0, mLastDsDy=0, mLastDtDy=1;
-
-    boolean mHaveMatrix;
-
-    // For debugging, this is the last information given to the surface flinger.
-    boolean mSurfaceShown;
-    float mSurfaceX, mSurfaceY, mSurfaceW, mSurfaceH;
-    int mSurfaceLayer;
-    float mSurfaceAlpha;
-
-    // Set to true if, when the window gets displayed, it should perform
-    // an enter animation.
-    boolean mEnterAnimationPending;
-
-    /** This is set when there is no Surface */
-    static final int NO_SURFACE = 0;
-    /** This is set after the Surface has been created but before the window has been drawn. During
-     * this time the surface is hidden. */
-    static final int DRAW_PENDING = 1;
-    /** This is set after the window has finished drawing for the first time but before its surface
-     * is shown.  The surface will be displayed when the next layout is run. */
-    static final int COMMIT_DRAW_PENDING = 2;
-    /** This is set during the time after the window's drawing has been committed, and before its
-     * surface is actually shown.  It is used to delay showing the surface until all windows in a
-     * token are ready to be shown. */
-    static final int READY_TO_SHOW = 3;
-    /** Set when the window has been shown in the screen the first time. */
-    static final int HAS_DRAWN = 4;
-    static String drawStateToString(int state) {
-        switch (state) {
-            case NO_SURFACE: return "NO_SURFACE";
-            case DRAW_PENDING: return "DRAW_PENDING";
-            case COMMIT_DRAW_PENDING: return "COMMIT_DRAW_PENDING";
-            case READY_TO_SHOW: return "READY_TO_SHOW";
-            case HAS_DRAWN: return "HAS_DRAWN";
-            default: return Integer.toString(state);
-        }
-    }
-    int mDrawState;
-
-    /** Was this window last hidden? */
-    boolean mLastHidden;
-
-    int mAttrFlags;
-    int mAttrType;
-
-    final int mLayerStack;
-
-    public WindowStateAnimator(final WindowState win) {
-        final WindowManagerService service = win.mService;
-
-        mService = service;
-        mAnimator = service.mAnimator;
-        mPolicy = service.mPolicy;
-        mContext = service.mContext;
-        final DisplayInfo displayInfo = win.mDisplayContent.getDisplayInfo();
-        mAnimDw = displayInfo.appWidth;
-        mAnimDh = displayInfo.appHeight;
-
-        mWin = win;
-        mAttachedWinAnimator = win.mAttachedWindow == null
-                ? null : win.mAttachedWindow.mWinAnimator;
-        mAppAnimator = win.mAppToken == null ? null : win.mAppToken.mAppAnimator;
-        mSession = win.mSession;
-        mAttrFlags = win.mAttrs.flags;
-        mAttrType = win.mAttrs.type;
-        mIsWallpaper = win.mIsWallpaper;
-        mLayerStack = win.mDisplayContent.getDisplay().getLayerStack();
-    }
-
-    public void setAnimation(Animation anim) {
-        if (localLOGV) Slog.v(TAG, "Setting animation in " + this + ": " + anim);
-        mAnimating = false;
-        mLocalAnimating = false;
-        mAnimation = anim;
-        mAnimation.restrictDuration(WindowManagerService.MAX_ANIMATION_DURATION);
-        mAnimation.scaleCurrentDuration(mService.mWindowAnimationScale);
-        // Start out animation gone if window is gone, or visible if window is visible.
-        mTransformation.clear();
-        mTransformation.setAlpha(mLastHidden ? 0 : 1);
-        mHasLocalTransformation = true;
-    }
-
-    public void clearAnimation() {
-        if (mAnimation != null) {
-            mAnimating = true;
-            mLocalAnimating = false;
-            mAnimation.cancel();
-            mAnimation = null;
-        }
-    }
-
-    /** Is the window or its container currently animating? */
-    boolean isAnimating() {
-        return mAnimation != null
-                || (mAttachedWinAnimator != null && mAttachedWinAnimator.mAnimation != null)
-                || (mAppAnimator != null &&
-                        (mAppAnimator.animation != null
-                                || mAppAnimator.mAppToken.inPendingTransaction));
-    }
-
-    /** Is the window animating the DummyAnimation? */
-    boolean isDummyAnimation() {
-        return mAppAnimator != null
-                && mAppAnimator.animation == AppWindowAnimator.sDummyAnimation;
-    }
-
-    /** Is this window currently animating? */
-    boolean isWindowAnimating() {
-        return mAnimation != null;
-    }
-
-    void cancelExitAnimationForNextAnimationLocked() {
-        if (mAnimation != null) {
-            mAnimation.cancel();
-            mAnimation = null;
-            mLocalAnimating = false;
-            destroySurfaceLocked();
-        }
-    }
-
-    private boolean stepAnimation(long currentTime) {
-        if ((mAnimation == null) || !mLocalAnimating) {
-            return false;
-        }
-        mTransformation.clear();
-        final boolean more = mAnimation.getTransformation(currentTime, mTransformation);
-        if (false && DEBUG_ANIM) Slog.v(
-            TAG, "Stepped animation in " + this +
-            ": more=" + more + ", xform=" + mTransformation);
-        return more;
-    }
-
-    // This must be called while inside a transaction.  Returns true if
-    // there is more animation to run.
-    boolean stepAnimationLocked(long currentTime) {
-        // Save the animation state as it was before this step so WindowManagerService can tell if
-        // we just started or just stopped animating by comparing mWasAnimating with isAnimating().
-        mWasAnimating = mAnimating;
-        if (mService.okToDisplay()) {
-            // We will run animations as long as the display isn't frozen.
-
-            if (mWin.isDrawnLw() && mAnimation != null) {
-                mHasTransformation = true;
-                mHasLocalTransformation = true;
-                if (!mLocalAnimating) {
-                    if (DEBUG_ANIM) Slog.v(
-                        TAG, "Starting animation in " + this +
-                        " @ " + currentTime + ": ww=" + mWin.mFrame.width() +
-                        " wh=" + mWin.mFrame.height() +
-                        " dw=" + mAnimDw + " dh=" + mAnimDh +
-                        " scale=" + mService.mWindowAnimationScale);
-                    mAnimation.initialize(mWin.mFrame.width(), mWin.mFrame.height(),
-                            mAnimDw, mAnimDh);
-                    final DisplayInfo displayInfo = mWin.mDisplayContent.getDisplayInfo();
-                    mAnimDw = displayInfo.appWidth;
-                    mAnimDh = displayInfo.appHeight;
-                    mAnimation.setStartTime(currentTime);
-                    mLocalAnimating = true;
-                    mAnimating = true;
-                }
-                if ((mAnimation != null) && mLocalAnimating) {
-                    if (stepAnimation(currentTime)) {
-                        return true;
-                    }
-                }
-                if (DEBUG_ANIM) Slog.v(
-                    TAG, "Finished animation in " + this +
-                    " @ " + currentTime);
-                //WindowManagerService.this.dump();
-            }
-            mHasLocalTransformation = false;
-            if ((!mLocalAnimating || mAnimationIsEntrance) && mAppAnimator != null
-                    && mAppAnimator.animation != null) {
-                // When our app token is animating, we kind-of pretend like
-                // we are as well.  Note the mLocalAnimating mAnimationIsEntrance
-                // part of this check means that we will only do this if
-                // our window is not currently exiting, or it is not
-                // locally animating itself.  The idea being that one that
-                // is exiting and doing a local animation should be removed
-                // once that animation is done.
-                mAnimating = true;
-                mHasTransformation = true;
-                mTransformation.clear();
-                return false;
-            } else if (mHasTransformation) {
-                // Little trick to get through the path below to act like
-                // we have finished an animation.
-                mAnimating = true;
-            } else if (isAnimating()) {
-                mAnimating = true;
-            }
-        } else if (mAnimation != null) {
-            // If the display is frozen, and there is a pending animation,
-            // clear it and make sure we run the cleanup code.
-            mAnimating = true;
-        }
-
-        if (!mAnimating && !mLocalAnimating) {
-            return false;
-        }
-
-        // Done animating, clean up.
-        if (DEBUG_ANIM) Slog.v(
-            TAG, "Animation done in " + this + ": exiting=" + mWin.mExiting
-            + ", reportedVisible="
-            + (mWin.mAppToken != null ? mWin.mAppToken.reportedVisible : false));
-
-        mAnimating = false;
-        mLocalAnimating = false;
-        if (mAnimation != null) {
-            mAnimation.cancel();
-            mAnimation = null;
-        }
-        if (mAnimator.mWindowDetachedWallpaper == mWin) {
-            mAnimator.mWindowDetachedWallpaper = null;
-        }
-        mAnimLayer = mWin.mLayer;
-        if (mWin.mIsImWindow) {
-            mAnimLayer += mService.mInputMethodAnimLayerAdjustment;
-        } else if (mIsWallpaper) {
-            mAnimLayer += mService.mWallpaperAnimLayerAdjustment;
-        }
-        if (DEBUG_LAYERS) Slog.v(TAG, "Stepping win " + this
-                + " anim layer: " + mAnimLayer);
-        mHasTransformation = false;
-        mHasLocalTransformation = false;
-        if (mWin.mPolicyVisibility != mWin.mPolicyVisibilityAfterAnim) {
-            if (DEBUG_VISIBILITY) {
-                Slog.v(TAG, "Policy visibility changing after anim in " + this + ": "
-                        + mWin.mPolicyVisibilityAfterAnim);
-            }
-            mWin.mPolicyVisibility = mWin.mPolicyVisibilityAfterAnim;
-            mWin.mDisplayContent.layoutNeeded = true;
-            if (!mWin.mPolicyVisibility) {
-                if (mService.mCurrentFocus == mWin) {
-                    if (WindowManagerService.DEBUG_FOCUS_LIGHT) Slog.i(TAG,
-                            "setAnimationLocked: setting mFocusMayChange true");
-                    mService.mFocusMayChange = true;
-                }
-                // Window is no longer visible -- make sure if we were waiting
-                // for it to be displayed before enabling the display, that
-                // we allow the display to be enabled now.
-                mService.enableScreenIfNeededLocked();
-            }
-        }
-        mTransformation.clear();
-        if (mDrawState == HAS_DRAWN
-                && mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
-                && mWin.mAppToken != null
-                && mWin.mAppToken.firstWindowDrawn
-                && mWin.mAppToken.startingData != null) {
-            if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Finish starting "
-                    + mWin.mToken + ": first real window done animating");
-            mService.mFinishedStarting.add(mWin.mAppToken);
-            mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
-        } else if (mAttrType == LayoutParams.TYPE_STATUS_BAR && mWin.mPolicyVisibility) {
-            // Upon completion of a not-visible to visible status bar animation a relayout is
-            // required.
-            mWin.mDisplayContent.layoutNeeded = true;
-        }
-
-        finishExit();
-        final int displayId = mWin.mDisplayContent.getDisplayId();
-        mAnimator.setPendingLayoutChanges(displayId, WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
-        if (WindowManagerService.DEBUG_LAYOUT_REPEATS) mService.debugLayoutRepeats(
-                "WindowStateAnimator", mAnimator.getPendingLayoutChanges(displayId));
-
-        if (mWin.mAppToken != null) {
-            mWin.mAppToken.updateReportedVisibilityLocked();
-        }
-
-        return false;
-    }
-
-    void finishExit() {
-        if (WindowManagerService.DEBUG_ANIM) Slog.v(
-                TAG, "finishExit in " + this
-                + ": exiting=" + mWin.mExiting
-                + " remove=" + mWin.mRemoveOnExit
-                + " windowAnimating=" + isWindowAnimating());
-
-        final int N = mWin.mChildWindows.size();
-        for (int i=0; i<N; i++) {
-            mWin.mChildWindows.get(i).mWinAnimator.finishExit();
-        }
-
-        if (!mWin.mExiting) {
-            return;
-        }
-
-        if (isWindowAnimating()) {
-            return;
-        }
-
-        if (WindowManagerService.localLOGV) Slog.v(
-                TAG, "Exit animation finished in " + this
-                + ": remove=" + mWin.mRemoveOnExit);
-        if (mSurfaceControl != null) {
-            mService.mDestroySurface.add(mWin);
-            mWin.mDestroying = true;
-            if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(
-                mWin, "HIDE (finishExit)", null);
-            hide();
-        }
-        mWin.mExiting = false;
-        if (mWin.mRemoveOnExit) {
-            mService.mPendingRemove.add(mWin);
-            mWin.mRemoveOnExit = false;
-        }
-        mAnimator.hideWallpapersLocked(mWin);
-    }
-
-    void hide() {
-        if (!mLastHidden) {
-            //dump();
-            mLastHidden = true;
-            if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
-                    "HIDE (performLayout)", null);
-            if (mSurfaceControl != null) {
-                mSurfaceShown = false;
-                try {
-                    mSurfaceControl.hide();
-                } catch (RuntimeException e) {
-                    Slog.w(TAG, "Exception hiding surface in " + mWin);
-                }
-            }
-        }
-    }
-
-    boolean finishDrawingLocked() {
-        if (DEBUG_STARTING_WINDOW &&
-                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
-            Slog.v(TAG, "Finishing drawing window " + mWin + ": mDrawState="
-                    + drawStateToString(mDrawState));
-        }
-        if (mDrawState == DRAW_PENDING) {
-            if (DEBUG_SURFACE_TRACE || DEBUG_ANIM || SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
-                Slog.v(TAG, "finishDrawingLocked: mDrawState=COMMIT_DRAW_PENDING " + this + " in "
-                        + mSurfaceControl);
-            if (DEBUG_STARTING_WINDOW &&
-                    mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
-                Slog.v(TAG, "Draw state now committed in " + mWin);
-            }
-            mDrawState = COMMIT_DRAW_PENDING;
-            return true;
-        }
-        return false;
-    }
-
-    // This must be called while inside a transaction.
-    boolean commitFinishDrawingLocked(long currentTime) {
-        if (DEBUG_STARTING_WINDOW &&
-                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING) {
-            Slog.i(TAG, "commitFinishDrawingLocked: " + mWin + " cur mDrawState="
-                    + drawStateToString(mDrawState));
-        }
-        if (mDrawState != COMMIT_DRAW_PENDING) {
-            return false;
-        }
-        if (DEBUG_SURFACE_TRACE || DEBUG_ANIM) {
-            Slog.i(TAG, "commitFinishDrawingLocked: mDrawState=READY_TO_SHOW " + mSurfaceControl);
-        }
-        mDrawState = READY_TO_SHOW;
-        final boolean starting = mWin.mAttrs.type == TYPE_APPLICATION_STARTING;
-        final AppWindowToken atoken = mWin.mAppToken;
-        if (atoken == null || atoken.allDrawn || starting) {
-            performShowLocked();
-        }
-        return true;
-    }
-
-    static class SurfaceTrace extends SurfaceControl {
-        private final static String SURFACE_TAG = "SurfaceTrace";
-        final static ArrayList<SurfaceTrace> sSurfaces = new ArrayList<SurfaceTrace>();
-
-        private float mSurfaceTraceAlpha = 0;
-        private int mLayer;
-        private final PointF mPosition = new PointF();
-        private final Point mSize = new Point();
-        private final Rect mWindowCrop = new Rect();
-        private boolean mShown = false;
-        private int mLayerStack;
-        private final String mName;
-
-        public SurfaceTrace(SurfaceSession s,
-                       String name, int w, int h, int format, int flags)
-                   throws OutOfResourcesException {
-            super(s, name, w, h, format, flags);
-            mName = name != null ? name : "Not named";
-            mSize.set(w, h);
-            Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
-                    + Debug.getCallers(3));
-        }
-
-        @Override
-        public void setAlpha(float alpha) {
-            if (mSurfaceTraceAlpha != alpha) {
-                Slog.v(SURFACE_TAG, "setAlpha(" + alpha + "): OLD:" + this + ". Called by "
-                        + Debug.getCallers(3));
-                mSurfaceTraceAlpha = alpha;
-            }
-            super.setAlpha(alpha);
-        }
-
-        @Override
-        public void setLayer(int zorder) {
-            if (zorder != mLayer) {
-                Slog.v(SURFACE_TAG, "setLayer(" + zorder + "): OLD:" + this + ". Called by "
-                        + Debug.getCallers(3));
-                mLayer = zorder;
-            }
-            super.setLayer(zorder);
-
-            sSurfaces.remove(this);
-            int i;
-            for (i = sSurfaces.size() - 1; i >= 0; i--) {
-                SurfaceTrace s = sSurfaces.get(i);
-                if (s.mLayer < zorder) {
-                    break;
-                }
-            }
-            sSurfaces.add(i + 1, this);
-        }
-
-        @Override
-        public void setPosition(float x, float y) {
-            if (x != mPosition.x || y != mPosition.y) {
-                Slog.v(SURFACE_TAG, "setPosition(" + x + "," + y + "): OLD:" + this
-                        + ". Called by " + Debug.getCallers(3));
-                mPosition.set(x, y);
-            }
-            super.setPosition(x, y);
-        }
-
-        @Override
-        public void setSize(int w, int h) {
-            if (w != mSize.x || h != mSize.y) {
-                Slog.v(SURFACE_TAG, "setSize(" + w + "," + h + "): OLD:" + this + ". Called by "
-                        + Debug.getCallers(3));
-                mSize.set(w, h);
-            }
-            super.setSize(w, h);
-        }
-
-        @Override
-        public void setWindowCrop(Rect crop) {
-            if (crop != null) {
-                if (!crop.equals(mWindowCrop)) {
-                    Slog.v(SURFACE_TAG, "setWindowCrop(" + crop.toShortString() + "): OLD:" + this
-                            + ". Called by " + Debug.getCallers(3));
-                    mWindowCrop.set(crop);
-                }
-            }
-            super.setWindowCrop(crop);
-        }
-
-        @Override
-        public void setLayerStack(int layerStack) {
-            if (layerStack != mLayerStack) {
-                Slog.v(SURFACE_TAG, "setLayerStack(" + layerStack + "): OLD:" + this
-                        + ". Called by " + Debug.getCallers(3));
-                mLayerStack = layerStack;
-            }
-            super.setLayerStack(layerStack);
-        }
-
-        @Override
-        public void hide() {
-            if (mShown) {
-                Slog.v(SURFACE_TAG, "hide: OLD:" + this + ". Called by " + Debug.getCallers(3));
-                mShown = false;
-            }
-            super.hide();
-        }
-
-        @Override
-        public void show() {
-            if (!mShown) {
-                Slog.v(SURFACE_TAG, "show: OLD:" + this + ". Called by " + Debug.getCallers(3));
-                mShown = true;
-            }
-            super.show();
-        }
-
-        @Override
-        public void destroy() {
-            super.destroy();
-            Slog.v(SURFACE_TAG, "destroy: " + this + ". Called by " + Debug.getCallers(3));
-            sSurfaces.remove(this);
-        }
-
-        @Override
-        public void release() {
-            super.release();
-            Slog.v(SURFACE_TAG, "release: " + this + ". Called by "
-                    + Debug.getCallers(3));
-            sSurfaces.remove(this);
-        }
-
-        static void dumpAllSurfaces() {
-            final int N = sSurfaces.size();
-            for (int i = 0; i < N; i++) {
-                Slog.i(TAG, "SurfaceDump: " + sSurfaces.get(i));
-            }
-        }
-
-        @Override
-        public String toString() {
-            return "Surface " + Integer.toHexString(System.identityHashCode(this)) + " "
-                    + mName + " (" + mLayerStack + "): shown=" + mShown + " layer=" + mLayer
-                    + " alpha=" + mSurfaceTraceAlpha + " " + mPosition.x + "," + mPosition.y
-                    + " " + mSize.x + "x" + mSize.y
-                    + " crop=" + mWindowCrop.toShortString();
-        }
-    }
-
-    SurfaceControl createSurfaceLocked() {
-        if (mSurfaceControl == null) {
-            if (DEBUG_ANIM || DEBUG_ORIENTATION) Slog.i(TAG,
-                    "createSurface " + this + ": mDrawState=DRAW_PENDING");
-            mDrawState = DRAW_PENDING;
-            if (mWin.mAppToken != null) {
-                if (mWin.mAppToken.mAppAnimator.animation == null) {
-                    mWin.mAppToken.allDrawn = false;
-                    mWin.mAppToken.deferClearAllDrawn = false;
-                } else {
-                    // Currently animating, persist current state of allDrawn until animation
-                    // is complete.
-                    mWin.mAppToken.deferClearAllDrawn = true;
-                }
-            }
-
-            mService.makeWindowFreezingScreenIfNeededLocked(mWin);
-
-            int flags = SurfaceControl.HIDDEN;
-            final WindowManager.LayoutParams attrs = mWin.mAttrs;
-
-            if ((attrs.flags&WindowManager.LayoutParams.FLAG_SECURE) != 0) {
-                flags |= SurfaceControl.SECURE;
-            }
-            if (DEBUG_VISIBILITY) Slog.v(
-                TAG, "Creating surface in session "
-                + mSession.mSurfaceSession + " window " + this
-                + " w=" + mWin.mCompatFrame.width()
-                + " h=" + mWin.mCompatFrame.height() + " format="
-                + attrs.format + " flags=" + flags);
-
-            int w = mWin.mCompatFrame.width();
-            int h = mWin.mCompatFrame.height();
-            if ((attrs.flags & LayoutParams.FLAG_SCALED) != 0) {
-                // for a scaled surface, we always want the requested
-                // size.
-                w = mWin.mRequestedWidth;
-                h = mWin.mRequestedHeight;
-            }
-
-            // Something is wrong and SurfaceFlinger will not like this,
-            // try to revert to sane values
-            if (w <= 0) w = 1;
-            if (h <= 0) h = 1;
-
-            mSurfaceShown = false;
-            mSurfaceLayer = 0;
-            mSurfaceAlpha = 0;
-            mSurfaceX = 0;
-            mSurfaceY = 0;
-            mSurfaceW = w;
-            mSurfaceH = h;
-            mWin.mLastSystemDecorRect.set(0, 0, 0, 0);
-            try {
-                final boolean isHwAccelerated = (attrs.flags &
-                        WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
-                final int format = isHwAccelerated ? PixelFormat.TRANSLUCENT : attrs.format;
-                if (!PixelFormat.formatHasAlpha(attrs.format)) {
-                    flags |= SurfaceControl.OPAQUE;
-                }
-                if (DEBUG_SURFACE_TRACE) {
-                    mSurfaceControl = new SurfaceTrace(
-                            mSession.mSurfaceSession,
-                            attrs.getTitle().toString(),
-                            w, h, format, flags);
-                } else {
-                    mSurfaceControl = new SurfaceControl(
-                        mSession.mSurfaceSession,
-                        attrs.getTitle().toString(),
-                        w, h, format, flags);
-                }
-                mWin.mHasSurface = true;
-                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) Slog.i(TAG,
-                        "  CREATE SURFACE "
-                        + mSurfaceControl + " IN SESSION "
-                        + mSession.mSurfaceSession
-                        + ": pid=" + mSession.mPid + " format="
-                        + attrs.format + " flags=0x"
-                        + Integer.toHexString(flags)
-                        + " / " + this);
-            } catch (OutOfResourcesException e) {
-                mWin.mHasSurface = false;
-                Slog.w(TAG, "OutOfResourcesException creating surface");
-                mService.reclaimSomeSurfaceMemoryLocked(this, "create", true);
-                mDrawState = NO_SURFACE;
-                return null;
-            } catch (Exception e) {
-                mWin.mHasSurface = false;
-                Slog.e(TAG, "Exception creating surface", e);
-                mDrawState = NO_SURFACE;
-                return null;
-            }
-
-            if (WindowManagerService.localLOGV) Slog.v(
-                TAG, "Got surface: " + mSurfaceControl
-                + ", set left=" + mWin.mFrame.left + " top=" + mWin.mFrame.top
-                + ", animLayer=" + mAnimLayer);
-            if (SHOW_LIGHT_TRANSACTIONS) {
-                Slog.i(TAG, ">>> OPEN TRANSACTION createSurfaceLocked");
-                WindowManagerService.logSurface(mWin, "CREATE pos=("
-                        + mWin.mFrame.left + "," + mWin.mFrame.top + ") ("
-                        + mWin.mCompatFrame.width() + "x" + mWin.mCompatFrame.height()
-                        + "), layer=" + mAnimLayer + " HIDE", null);
-            }
-            SurfaceControl.openTransaction();
-            try {
-                try {
-                    mSurfaceX = mWin.mFrame.left + mWin.mXOffset;
-                    mSurfaceY = mWin.mFrame.top + mWin.mYOffset;
-                    mSurfaceControl.setPosition(mSurfaceX, mSurfaceY);
-                    mSurfaceLayer = mAnimLayer;
-                    mSurfaceControl.setLayerStack(mLayerStack);
-                    mSurfaceControl.setLayer(mAnimLayer);
-                    mSurfaceControl.setAlpha(0);
-                    mSurfaceShown = false;
-                } catch (RuntimeException e) {
-                    Slog.w(TAG, "Error creating surface in " + w, e);
-                    mService.reclaimSomeSurfaceMemoryLocked(this, "create-init", true);
-                }
-                mLastHidden = true;
-            } finally {
-                SurfaceControl.closeTransaction();
-                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                        "<<< CLOSE TRANSACTION createSurfaceLocked");
-            }
-            if (WindowManagerService.localLOGV) Slog.v(
-                    TAG, "Created surface " + this);
-        }
-        return mSurfaceControl;
-    }
-
-    void destroySurfaceLocked() {
-        if (mWin.mAppToken != null && mWin == mWin.mAppToken.startingWindow) {
-            mWin.mAppToken.startingDisplayed = false;
-        }
-
-        if (mSurfaceControl != null) {
-
-            int i = mWin.mChildWindows.size();
-            while (i > 0) {
-                i--;
-                WindowState c = mWin.mChildWindows.get(i);
-                c.mAttachedHidden = true;
-            }
-
-            try {
-                if (DEBUG_VISIBILITY) {
-                    RuntimeException e = null;
-                    if (!WindowManagerService.HIDE_STACK_CRAWLS) {
-                        e = new RuntimeException();
-                        e.fillInStackTrace();
-                    }
-                    Slog.w(TAG, "Window " + this + " destroying surface "
-                            + mSurfaceControl + ", session " + mSession, e);
-                }
-                if (mSurfaceDestroyDeferred) {
-                    if (mSurfaceControl != null && mPendingDestroySurface != mSurfaceControl) {
-                        if (mPendingDestroySurface != null) {
-                            if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
-                                RuntimeException e = null;
-                                if (!WindowManagerService.HIDE_STACK_CRAWLS) {
-                                    e = new RuntimeException();
-                                    e.fillInStackTrace();
-                                }
-                                WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
-                            }
-                            mPendingDestroySurface.destroy();
-                        }
-                        mPendingDestroySurface = mSurfaceControl;
-                    }
-                } else {
-                    if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
-                        RuntimeException e = null;
-                        if (!WindowManagerService.HIDE_STACK_CRAWLS) {
-                            e = new RuntimeException();
-                            e.fillInStackTrace();
-                        }
-                        WindowManagerService.logSurface(mWin, "DESTROY", e);
-                    }
-                    mSurfaceControl.destroy();
-                }
-                mAnimator.hideWallpapersLocked(mWin);
-            } catch (RuntimeException e) {
-                Slog.w(TAG, "Exception thrown when destroying Window " + this
-                    + " surface " + mSurfaceControl + " session " + mSession
-                    + ": " + e.toString());
-            }
-
-            mSurfaceShown = false;
-            mSurfaceControl = null;
-            mWin.mHasSurface = false;
-            mDrawState = NO_SURFACE;
-        }
-    }
-
-    void destroyDeferredSurfaceLocked() {
-        try {
-            if (mPendingDestroySurface != null) {
-                if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
-                    RuntimeException e = null;
-                    if (!WindowManagerService.HIDE_STACK_CRAWLS) {
-                        e = new RuntimeException();
-                        e.fillInStackTrace();
-                    }
-                    WindowManagerService.logSurface(mWin, "DESTROY PENDING", e);
-                }
-                mPendingDestroySurface.destroy();
-                mAnimator.hideWallpapersLocked(mWin);
-            }
-        } catch (RuntimeException e) {
-            Slog.w(TAG, "Exception thrown when destroying Window "
-                    + this + " surface " + mPendingDestroySurface
-                    + " session " + mSession + ": " + e.toString());
-        }
-        mSurfaceDestroyDeferred = false;
-        mPendingDestroySurface = null;
-    }
-
-    void computeShownFrameLocked() {
-        final boolean selfTransformation = mHasLocalTransformation;
-        Transformation attachedTransformation =
-                (mAttachedWinAnimator != null && mAttachedWinAnimator.mHasLocalTransformation)
-                ? mAttachedWinAnimator.mTransformation : null;
-        Transformation appTransformation = (mAppAnimator != null && mAppAnimator.hasTransformation)
-                ? mAppAnimator.transformation : null;
-
-        // Wallpapers are animated based on the "real" window they
-        // are currently targeting.
-        final WindowState wallpaperTarget = mService.mWallpaperTarget;
-        if (mIsWallpaper && wallpaperTarget != null && mService.mAnimateWallpaperWithTarget) {
-            final WindowStateAnimator wallpaperAnimator = wallpaperTarget.mWinAnimator;
-            if (wallpaperAnimator.mHasLocalTransformation &&
-                    wallpaperAnimator.mAnimation != null &&
-                    !wallpaperAnimator.mAnimation.getDetachWallpaper()) {
-                attachedTransformation = wallpaperAnimator.mTransformation;
-                if (WindowManagerService.DEBUG_WALLPAPER && attachedTransformation != null) {
-                    Slog.v(TAG, "WP target attached xform: " + attachedTransformation);
-                }
-            }
-            final AppWindowAnimator wpAppAnimator = wallpaperTarget.mAppToken == null ?
-                    null : wallpaperTarget.mAppToken.mAppAnimator;
-                if (wpAppAnimator != null && wpAppAnimator.hasTransformation
-                    && wpAppAnimator.animation != null
-                    && !wpAppAnimator.animation.getDetachWallpaper()) {
-                appTransformation = wpAppAnimator.transformation;
-                if (WindowManagerService.DEBUG_WALLPAPER && appTransformation != null) {
-                    Slog.v(TAG, "WP target app xform: " + appTransformation);
-                }
-            }
-        }
-
-        final int displayId = mWin.getDisplayId();
-        final ScreenRotationAnimation screenRotationAnimation =
-                mAnimator.getScreenRotationAnimationLocked(displayId);
-        final boolean screenAnimation =
-                screenRotationAnimation != null && screenRotationAnimation.isAnimating();
-        if (selfTransformation || attachedTransformation != null
-                || appTransformation != null || screenAnimation) {
-            // cache often used attributes locally
-            final Rect frame = mWin.mFrame;
-            final float tmpFloats[] = mService.mTmpFloats;
-            final Matrix tmpMatrix = mWin.mTmpMatrix;
-
-            // Compute the desired transformation.
-            if (screenAnimation && screenRotationAnimation.isRotating()) {
-                // If we are doing a screen animation, the global rotation
-                // applied to windows can result in windows that are carefully
-                // aligned with each other to slightly separate, allowing you
-                // to see what is behind them.  An unsightly mess.  This...
-                // thing...  magically makes it call good: scale each window
-                // slightly (two pixels larger in each dimension, from the
-                // window's center).
-                final float w = frame.width();
-                final float h = frame.height();
-                if (w>=1 && h>=1) {
-                    tmpMatrix.setScale(1 + 2/w, 1 + 2/h, w/2, h/2);
-                } else {
-                    tmpMatrix.reset();
-                }
-            } else {
-                tmpMatrix.reset();
-            }
-            tmpMatrix.postScale(mWin.mGlobalScale, mWin.mGlobalScale);
-            if (selfTransformation) {
-                tmpMatrix.postConcat(mTransformation.getMatrix());
-            }
-            tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
-            if (attachedTransformation != null) {
-                tmpMatrix.postConcat(attachedTransformation.getMatrix());
-            }
-            if (appTransformation != null) {
-                tmpMatrix.postConcat(appTransformation.getMatrix());
-            }
-            if (mAnimator.mUniverseBackground != null) {
-                tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
-            }
-            if (screenAnimation) {
-                tmpMatrix.postConcat(screenRotationAnimation.getEnterTransformation().getMatrix());
-            }
-            //TODO (multidisplay): Magnification is supported only for the default display.
-            if (mService.mDisplayMagnifier != null
-                    && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
-                MagnificationSpec spec = mService.mDisplayMagnifier
-                        .getMagnificationSpecForWindowLocked(mWin);
-                if (spec != null && !spec.isNop()) {
-                    tmpMatrix.postScale(spec.scale, spec.scale);
-                    tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
-                }
-            }
-
-            // "convert" it into SurfaceFlinger's format
-            // (a 2x2 matrix + an offset)
-            // Here we must not transform the position of the surface
-            // since it is already included in the transformation.
-            //Slog.i(TAG, "Transform: " + matrix);
-
-            mHaveMatrix = true;
-            tmpMatrix.getValues(tmpFloats);
-            mDsDx = tmpFloats[Matrix.MSCALE_X];
-            mDtDx = tmpFloats[Matrix.MSKEW_Y];
-            mDsDy = tmpFloats[Matrix.MSKEW_X];
-            mDtDy = tmpFloats[Matrix.MSCALE_Y];
-            float x = tmpFloats[Matrix.MTRANS_X];
-            float y = tmpFloats[Matrix.MTRANS_Y];
-            int w = frame.width();
-            int h = frame.height();
-            mWin.mShownFrame.set(x, y, x+w, y+h);
-
-            // Now set the alpha...  but because our current hardware
-            // can't do alpha transformation on a non-opaque surface,
-            // turn it off if we are running an animation that is also
-            // transforming since it is more important to have that
-            // animation be smooth.
-            mShownAlpha = mAlpha;
-            if (!mService.mLimitedAlphaCompositing
-                    || (!PixelFormat.formatHasAlpha(mWin.mAttrs.format)
-                    || (mWin.isIdentityMatrix(mDsDx, mDtDx, mDsDy, mDtDy)
-                            && x == frame.left && y == frame.top))) {
-                //Slog.i(TAG, "Applying alpha transform");
-                if (selfTransformation) {
-                    mShownAlpha *= mTransformation.getAlpha();
-                }
-                if (attachedTransformation != null) {
-                    mShownAlpha *= attachedTransformation.getAlpha();
-                }
-                if (appTransformation != null) {
-                    mShownAlpha *= appTransformation.getAlpha();
-                }
-                if (mAnimator.mUniverseBackground != null) {
-                    mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
-                }
-                if (screenAnimation) {
-                    mShownAlpha *= screenRotationAnimation.getEnterTransformation().getAlpha();
-                }
-            } else {
-                //Slog.i(TAG, "Not applying alpha transform");
-            }
-
-            if ((DEBUG_SURFACE_TRACE || WindowManagerService.localLOGV)
-                    && (mShownAlpha == 1.0 || mShownAlpha == 0.0)) Slog.v(
-                    TAG, "computeShownFrameLocked: Animating " + this + " mAlpha=" + mAlpha
-                    + " self=" + (selfTransformation ? mTransformation.getAlpha() : "null")
-                    + " attached=" + (attachedTransformation == null ?
-                            "null" : attachedTransformation.getAlpha())
-                    + " app=" + (appTransformation == null ? "null" : appTransformation.getAlpha())
-                    + " screen=" + (screenAnimation ?
-                            screenRotationAnimation.getEnterTransformation().getAlpha() : "null"));
-            return;
-        } else if (mIsWallpaper && mService.mInnerFields.mWallpaperActionPending) {
-            return;
-        }
-
-        if (WindowManagerService.localLOGV) Slog.v(
-                TAG, "computeShownFrameLocked: " + this +
-                " not attached, mAlpha=" + mAlpha);
-
-        final boolean applyUniverseTransformation = (mAnimator.mUniverseBackground != null
-                && mWin.mAttrs.type != WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
-                && mWin.mBaseLayer < mAnimator.mAboveUniverseLayer);
-        MagnificationSpec spec = null;
-        //TODO (multidisplay): Magnification is supported only for the default display.
-        if (mService.mDisplayMagnifier != null && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
-            spec = mService.mDisplayMagnifier.getMagnificationSpecForWindowLocked(mWin);
-        }
-        if (applyUniverseTransformation || spec != null) {
-            final Rect frame = mWin.mFrame;
-            final float tmpFloats[] = mService.mTmpFloats;
-            final Matrix tmpMatrix = mWin.mTmpMatrix;
-
-            tmpMatrix.setScale(mWin.mGlobalScale, mWin.mGlobalScale);
-            tmpMatrix.postTranslate(frame.left + mWin.mXOffset, frame.top + mWin.mYOffset);
-
-            if (applyUniverseTransformation) {
-                tmpMatrix.postConcat(mAnimator.mUniverseBackground.mUniverseTransform.getMatrix());
-            }
-
-            if (spec != null && !spec.isNop()) {
-                tmpMatrix.postScale(spec.scale, spec.scale);
-                tmpMatrix.postTranslate(spec.offsetX, spec.offsetY);
-            }
-
-            tmpMatrix.getValues(tmpFloats);
-
-            mHaveMatrix = true;
-            mDsDx = tmpFloats[Matrix.MSCALE_X];
-            mDtDx = tmpFloats[Matrix.MSKEW_Y];
-            mDsDy = tmpFloats[Matrix.MSKEW_X];
-            mDtDy = tmpFloats[Matrix.MSCALE_Y];
-            float x = tmpFloats[Matrix.MTRANS_X];
-            float y = tmpFloats[Matrix.MTRANS_Y];
-            int w = frame.width();
-            int h = frame.height();
-            mWin.mShownFrame.set(x, y, x + w, y + h);
-
-            mShownAlpha = mAlpha;
-            if (applyUniverseTransformation) {
-                mShownAlpha *= mAnimator.mUniverseBackground.mUniverseTransform.getAlpha();
-            }
-        } else {
-            mWin.mShownFrame.set(mWin.mFrame);
-            if (mWin.mXOffset != 0 || mWin.mYOffset != 0) {
-                mWin.mShownFrame.offset(mWin.mXOffset, mWin.mYOffset);
-            }
-            mShownAlpha = mAlpha;
-            mHaveMatrix = false;
-            mDsDx = mWin.mGlobalScale;
-            mDtDx = 0;
-            mDsDy = 0;
-            mDtDy = mWin.mGlobalScale;
-        }
-    }
-
-    void applyDecorRect(final Rect decorRect) {
-        final WindowState w = mWin;
-        // Compute the offset of the window in relation to the decor rect.
-        final int offX = w.mXOffset + w.mFrame.left;
-        final int offY = w.mYOffset + w.mFrame.top;
-        // Initialize the decor rect to the entire frame.
-        w.mSystemDecorRect.set(0, 0, w.mFrame.width(), w.mFrame.height());
-        // Intersect with the decor rect, offsetted by window position.
-        w.mSystemDecorRect.intersect(decorRect.left-offX, decorRect.top-offY,
-                decorRect.right-offX, decorRect.bottom-offY);
-        // If size compatibility is being applied to the window, the
-        // surface is scaled relative to the screen.  Also apply this
-        // scaling to the crop rect.  We aren't using the standard rect
-        // scale function because we want to round things to make the crop
-        // always round to a larger rect to ensure we don't crop too
-        // much and hide part of the window that should be seen.
-        if (w.mEnforceSizeCompat && w.mInvGlobalScale != 1.0f) {
-            final float scale = w.mInvGlobalScale;
-            w.mSystemDecorRect.left = (int) (w.mSystemDecorRect.left * scale - 0.5f);
-            w.mSystemDecorRect.top = (int) (w.mSystemDecorRect.top * scale - 0.5f);
-            w.mSystemDecorRect.right = (int) ((w.mSystemDecorRect.right+1) * scale - 0.5f);
-            w.mSystemDecorRect.bottom = (int) ((w.mSystemDecorRect.bottom+1) * scale - 0.5f);
-        }
-    }
-
-    void updateSurfaceWindowCrop(final boolean recoveringMemory) {
-        final WindowState w = mWin;
-        DisplayInfo displayInfo = w.mDisplayContent.getDisplayInfo();
-
-        // Need to recompute a new system decor rect each time.
-        if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
-            // Currently can't do this cropping for scaled windows.  We'll
-            // just keep the crop rect the same as the source surface.
-            w.mSystemDecorRect.set(0, 0, w.mRequestedWidth, w.mRequestedHeight);
-        } else if (!w.isDefaultDisplay()) {
-            // On a different display there is no system decor.  Crop the window
-            // by the screen boundaries.
-            w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(), w.mCompatFrame.height());
-            w.mSystemDecorRect.intersect(-w.mCompatFrame.left, -w.mCompatFrame.top,
-                    displayInfo.logicalWidth - w.mCompatFrame.left,
-                    displayInfo.logicalHeight - w.mCompatFrame.top);
-        } else if (w.mLayer >= mService.mSystemDecorLayer) {
-            // Above the decor layer is easy, just use the entire window.
-            // Unless we have a universe background...  in which case all the
-            // windows need to be cropped by the screen, so they don't cover
-            // the universe background.
-            if (mAnimator.mUniverseBackground == null) {
-                w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
-                        w.mCompatFrame.height());
-            } else {
-                applyDecorRect(mService.mScreenRect);
-            }
-        } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND
-                || w.mDecorFrame.isEmpty()) {
-            // The universe background isn't cropped, nor windows without policy decor.
-            w.mSystemDecorRect.set(0, 0, w.mCompatFrame.width(),
-                    w.mCompatFrame.height());
-        } else {
-            // Crop to the system decor specified by policy.
-            applyDecorRect(w.mDecorFrame);
-        }
-
-        if (!w.mSystemDecorRect.equals(w.mLastSystemDecorRect)) {
-            w.mLastSystemDecorRect.set(w.mSystemDecorRect);
-            try {
-                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
-                        "CROP " + w.mSystemDecorRect.toShortString(), null);
-                mSurfaceControl.setWindowCrop(w.mSystemDecorRect);
-            } catch (RuntimeException e) {
-                Slog.w(TAG, "Error setting crop surface of " + w
-                        + " crop=" + w.mSystemDecorRect.toShortString(), e);
-                if (!recoveringMemory) {
-                    mService.reclaimSomeSurfaceMemoryLocked(this, "crop", true);
-                }
-            }
-        }
-    }
-
-    void setSurfaceBoundariesLocked(final boolean recoveringMemory) {
-        final WindowState w = mWin;
-        int width, height;
-        if ((w.mAttrs.flags & LayoutParams.FLAG_SCALED) != 0) {
-            // for a scaled surface, we just want to use
-            // the requested size.
-            width  = w.mRequestedWidth;
-            height = w.mRequestedHeight;
-        } else {
-            width = w.mCompatFrame.width();
-            height = w.mCompatFrame.height();
-        }
-
-        if (width < 1) {
-            width = 1;
-        }
-        if (height < 1) {
-            height = 1;
-        }
-        final boolean surfaceResized = mSurfaceW != width || mSurfaceH != height;
-        if (surfaceResized) {
-            mSurfaceW = width;
-            mSurfaceH = height;
-        }
-
-        final float left = w.mShownFrame.left;
-        final float top = w.mShownFrame.top;
-        if (mSurfaceX != left || mSurfaceY != top) {
-            try {
-                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
-                        "POS " + left + ", " + top, null);
-                mSurfaceX = left;
-                mSurfaceY = top;
-                mSurfaceControl.setPosition(left, top);
-            } catch (RuntimeException e) {
-                Slog.w(TAG, "Error positioning surface of " + w
-                        + " pos=(" + left
-                        + "," + top + ")", e);
-                if (!recoveringMemory) {
-                    mService.reclaimSomeSurfaceMemoryLocked(this, "position", true);
-                }
-            }
-        }
-
-        if (surfaceResized) {
-            try {
-                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
-                        "SIZE " + width + "x" + height, null);
-                mSurfaceResized = true;
-                mSurfaceControl.setSize(width, height);
-                final int displayId = w.mDisplayContent.getDisplayId();
-                mAnimator.setPendingLayoutChanges(displayId,
-                        WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER);
-                if ((w.mAttrs.flags & LayoutParams.FLAG_DIM_BEHIND) != 0) {
-                    w.getStack().startDimmingIfNeeded(this);
-                }
-            } catch (RuntimeException e) {
-                // If something goes wrong with the surface (such
-                // as running out of memory), don't take down the
-                // entire system.
-                Slog.e(TAG, "Error resizing surface of " + w
-                        + " size=(" + width + "x" + height + ")", e);
-                if (!recoveringMemory) {
-                    mService.reclaimSomeSurfaceMemoryLocked(this, "size", true);
-                }
-            }
-        }
-
-        updateSurfaceWindowCrop(recoveringMemory);
-    }
-
-    public void prepareSurfaceLocked(final boolean recoveringMemory) {
-        final WindowState w = mWin;
-        if (mSurfaceControl == null) {
-            if (w.mOrientationChanging) {
-                if (DEBUG_ORIENTATION) {
-                    Slog.v(TAG, "Orientation change skips hidden " + w);
-                }
-                w.mOrientationChanging = false;
-            }
-            return;
-        }
-
-        boolean displayed = false;
-
-        computeShownFrameLocked();
-
-        setSurfaceBoundariesLocked(recoveringMemory);
-
-        if (mIsWallpaper && !mWin.mWallpaperVisible) {
-            // Wallpaper is no longer visible and there is no wp target => hide it.
-            hide();
-        } else if (w.mAttachedHidden || !w.isOnScreen()) {
-            hide();
-            mAnimator.hideWallpapersLocked(w);
-
-            // If we are waiting for this window to handle an
-            // orientation change, well, it is hidden, so
-            // doesn't really matter.  Note that this does
-            // introduce a potential glitch if the window
-            // becomes unhidden before it has drawn for the
-            // new orientation.
-            if (w.mOrientationChanging) {
-                w.mOrientationChanging = false;
-                if (DEBUG_ORIENTATION) Slog.v(TAG,
-                        "Orientation change skips hidden " + w);
-            }
-        } else if (mLastLayer != mAnimLayer
-                || mLastAlpha != mShownAlpha
-                || mLastDsDx != mDsDx
-                || mLastDtDx != mDtDx
-                || mLastDsDy != mDsDy
-                || mLastDtDy != mDtDy
-                || w.mLastHScale != w.mHScale
-                || w.mLastVScale != w.mVScale
-                || mLastHidden) {
-            displayed = true;
-            mLastAlpha = mShownAlpha;
-            mLastLayer = mAnimLayer;
-            mLastDsDx = mDsDx;
-            mLastDtDx = mDtDx;
-            mLastDsDy = mDsDy;
-            mLastDtDy = mDtDy;
-            w.mLastHScale = w.mHScale;
-            w.mLastVScale = w.mVScale;
-            if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
-                    "alpha=" + mShownAlpha + " layer=" + mAnimLayer
-                    + " matrix=[" + (mDsDx*w.mHScale)
-                    + "," + (mDtDx*w.mVScale)
-                    + "][" + (mDsDy*w.mHScale)
-                    + "," + (mDtDy*w.mVScale) + "]", null);
-            if (mSurfaceControl != null) {
-                try {
-                    mSurfaceAlpha = mShownAlpha;
-                    mSurfaceControl.setAlpha(mShownAlpha);
-                    mSurfaceLayer = mAnimLayer;
-                    mSurfaceControl.setLayer(mAnimLayer);
-                    mSurfaceControl.setMatrix(
-                        mDsDx*w.mHScale, mDtDx*w.mVScale,
-                        mDsDy*w.mHScale, mDtDy*w.mVScale);
-
-                    if (mLastHidden && mDrawState == HAS_DRAWN) {
-                        if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(w,
-                                "SHOW (performLayout)", null);
-                        if (WindowManagerService.DEBUG_VISIBILITY) Slog.v(TAG, "Showing " + w
-                                + " during relayout");
-                        if (showSurfaceRobustlyLocked()) {
-                            mLastHidden = false;
-                            if (mIsWallpaper) {
-                                mService.dispatchWallpaperVisibility(w, true);
-                            }
-                            // This draw means the difference between unique content and mirroring.
-                            // Run another pass through performLayout to set mHasContent in the
-                            // LogicalDisplay.
-                            mAnimator.setPendingLayoutChanges(w.getDisplayId(),
-                                    WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM);
-                        } else {
-                            w.mOrientationChanging = false;
-                        }
-                    }
-                    if (mSurfaceControl != null) {
-                        w.mToken.hasVisible = true;
-                    }
-                } catch (RuntimeException e) {
-                    Slog.w(TAG, "Error updating surface in " + w, e);
-                    if (!recoveringMemory) {
-                        mService.reclaimSomeSurfaceMemoryLocked(this, "update", true);
-                    }
-                }
-            }
-        } else {
-            if (DEBUG_ANIM && isAnimating()) {
-                Slog.v(TAG, "prepareSurface: No changes in animation for " + this);
-            }
-            displayed = true;
-        }
-
-        if (displayed) {
-            if (w.mOrientationChanging) {
-                if (!w.isDrawnLw()) {
-                    mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE;
-                    mAnimator.mLastWindowFreezeSource = w;
-                    if (DEBUG_ORIENTATION) Slog.v(TAG,
-                            "Orientation continue waiting for draw in " + w);
-                } else {
-                    w.mOrientationChanging = false;
-                    if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation change complete in " + w);
-                }
-            }
-            w.mToken.hasVisible = true;
-        }
-    }
-
-    void setTransparentRegionHintLocked(final Region region) {
-        if (mSurfaceControl == null) {
-            Slog.w(TAG, "setTransparentRegionHint: null mSurface after mHasSurface true");
-            return;
-        }
-        if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-            ">>> OPEN TRANSACTION setTransparentRegion");
-        SurfaceControl.openTransaction();
-        try {
-            if (SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
-                    "transparentRegionHint=" + region, null);
-            mSurfaceControl.setTransparentRegionHint(region);
-        } finally {
-            SurfaceControl.closeTransaction();
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                    "<<< CLOSE TRANSACTION setTransparentRegion");
-        }
-    }
-
-    void setWallpaperOffset(RectF shownFrame) {
-        final int left = (int) shownFrame.left;
-        final int top = (int) shownFrame.top;
-        if (mSurfaceX != left || mSurfaceY != top) {
-            mSurfaceX = left;
-            mSurfaceY = top;
-            if (mAnimating) {
-                // If this window (or its app token) is animating, then the position
-                // of the surface will be re-computed on the next animation frame.
-                // We can't poke it directly here because it depends on whatever
-                // transformation is being applied by the animation.
-                return;
-            }
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                    ">>> OPEN TRANSACTION setWallpaperOffset");
-            SurfaceControl.openTransaction();
-            try {
-                if (WindowManagerService.SHOW_TRANSACTIONS) WindowManagerService.logSurface(mWin,
-                        "POS " + left + ", " + top, null);
-                mSurfaceControl.setPosition(mWin.mFrame.left + left, mWin.mFrame.top + top);
-                updateSurfaceWindowCrop(false);
-            } catch (RuntimeException e) {
-                Slog.w(TAG, "Error positioning surface of " + mWin
-                        + " pos=(" + left + "," + top + ")", e);
-            } finally {
-                SurfaceControl.closeTransaction();
-                if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                        "<<< CLOSE TRANSACTION setWallpaperOffset");
-            }
-        }
-    }
-
-    // This must be called while inside a transaction.
-    boolean performShowLocked() {
-        if (mWin.isHiddenFromUserLocked()) {
-            Slog.w(TAG, "current user violation " + mService.mCurrentUserId + " trying to display "
-                    + this + ", type " + mWin.mAttrs.type + ", belonging to " + mWin.mOwnerUid);
-            return false;
-        }
-        if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
-                mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
-            RuntimeException e = null;
-            if (!WindowManagerService.HIDE_STACK_CRAWLS) {
-                e = new RuntimeException();
-                e.fillInStackTrace();
-            }
-            Slog.v(TAG, "performShow on " + this
-                    + ": mDrawState=" + mDrawState + " readyForDisplay="
-                    + mWin.isReadyForDisplayIgnoringKeyguard()
-                    + " starting=" + (mWin.mAttrs.type == TYPE_APPLICATION_STARTING)
-                    + " during animation: policyVis=" + mWin.mPolicyVisibility
-                    + " attHidden=" + mWin.mAttachedHidden
-                    + " tok.hiddenRequested="
-                    + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
-                    + " tok.hidden="
-                    + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
-                    + " animating=" + mAnimating
-                    + " tok animating="
-                    + (mAppAnimator != null ? mAppAnimator.animating : false), e);
-        }
-        if (mDrawState == READY_TO_SHOW && mWin.isReadyForDisplayIgnoringKeyguard()) {
-            if (SHOW_TRANSACTIONS || DEBUG_ORIENTATION)
-                WindowManagerService.logSurface(mWin, "SHOW (performShowLocked)", null);
-            if (DEBUG_VISIBILITY || (DEBUG_STARTING_WINDOW &&
-                    mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_STARTING)) {
-                Slog.v(TAG, "Showing " + this
-                        + " during animation: policyVis=" + mWin.mPolicyVisibility
-                        + " attHidden=" + mWin.mAttachedHidden
-                        + " tok.hiddenRequested="
-                        + (mWin.mAppToken != null ? mWin.mAppToken.hiddenRequested : false)
-                        + " tok.hidden="
-                        + (mWin.mAppToken != null ? mWin.mAppToken.hidden : false)
-                        + " animating=" + mAnimating
-                        + " tok animating="
-                        + (mAppAnimator != null ? mAppAnimator.animating : false));
-            }
-
-            mService.enableScreenIfNeededLocked();
-
-            applyEnterAnimationLocked();
-
-            // Force the show in the next prepareSurfaceLocked() call.
-            mLastAlpha = -1;
-            if (DEBUG_SURFACE_TRACE || DEBUG_ANIM)
-                Slog.v(TAG, "performShowLocked: mDrawState=HAS_DRAWN in " + this);
-            mDrawState = HAS_DRAWN;
-            mService.scheduleAnimationLocked();
-
-            int i = mWin.mChildWindows.size();
-            while (i > 0) {
-                i--;
-                WindowState c = mWin.mChildWindows.get(i);
-                if (c.mAttachedHidden) {
-                    c.mAttachedHidden = false;
-                    if (c.mWinAnimator.mSurfaceControl != null) {
-                        c.mWinAnimator.performShowLocked();
-                        // It hadn't been shown, which means layout not
-                        // performed on it, so now we want to make sure to
-                        // do a layout.  If called from within the transaction
-                        // loop, this will cause it to restart with a new
-                        // layout.
-                        c.mDisplayContent.layoutNeeded = true;
-                    }
-                }
-            }
-
-            if (mWin.mAttrs.type != TYPE_APPLICATION_STARTING
-                    && mWin.mAppToken != null) {
-                mWin.mAppToken.firstWindowDrawn = true;
-
-                if (mWin.mAppToken.startingData != null) {
-                    if (WindowManagerService.DEBUG_STARTING_WINDOW ||
-                            WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
-                            "Finish starting " + mWin.mToken
-                            + ": first real window is shown, no animation");
-                    // If this initial window is animating, stop it -- we
-                    // will do an animation to reveal it from behind the
-                    // starting window, so there is no need for it to also
-                    // be doing its own stuff.
-                    clearAnimation();
-                    mService.mFinishedStarting.add(mWin.mAppToken);
-                    mService.mH.sendEmptyMessage(H.FINISHED_STARTING);
-                }
-                mWin.mAppToken.updateReportedVisibilityLocked();
-            }
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /**
-     * Have the surface flinger show a surface, robustly dealing with
-     * error conditions.  In particular, if there is not enough memory
-     * to show the surface, then we will try to get rid of other surfaces
-     * in order to succeed.
-     *
-     * @return Returns true if the surface was successfully shown.
-     */
-    boolean showSurfaceRobustlyLocked() {
-        try {
-            if (mSurfaceControl != null) {
-                mSurfaceShown = true;
-                mSurfaceControl.show();
-                if (mWin.mTurnOnScreen) {
-                    if (DEBUG_VISIBILITY) Slog.v(TAG,
-                            "Show surface turning screen on: " + mWin);
-                    mWin.mTurnOnScreen = false;
-                    mAnimator.mBulkUpdateParams |= SET_TURN_ON_SCREEN;
-                }
-            }
-            return true;
-        } catch (RuntimeException e) {
-            Slog.w(TAG, "Failure showing surface " + mSurfaceControl + " in " + mWin, e);
-        }
-
-        mService.reclaimSomeSurfaceMemoryLocked(this, "show", true);
-
-        return false;
-    }
-
-    void applyEnterAnimationLocked() {
-        final int transit;
-        if (mEnterAnimationPending) {
-            mEnterAnimationPending = false;
-            transit = WindowManagerPolicy.TRANSIT_ENTER;
-        } else {
-            transit = WindowManagerPolicy.TRANSIT_SHOW;
-        }
-        applyAnimationLocked(transit, true);
-        //TODO (multidisplay): Magnification is supported only for the default display.
-        if (mService.mDisplayMagnifier != null
-                && mWin.getDisplayId() == Display.DEFAULT_DISPLAY) {
-            mService.mDisplayMagnifier.onWindowTransitionLocked(mWin, transit);
-        }
-    }
-
-    /**
-     * Choose the correct animation and set it to the passed WindowState.
-     * @param transit If AppTransition.TRANSIT_PREVIEW_DONE and the app window has been drawn
-     *      then the animation will be app_starting_exit. Any other value loads the animation from
-     *      the switch statement below.
-     * @param isEntrance The animation type the last time this was called. Used to keep from
-     *      loading the same animation twice.
-     * @return true if an animation has been loaded.
-     */
-    boolean applyAnimationLocked(int transit, boolean isEntrance) {
-        if (mLocalAnimating && mAnimationIsEntrance == isEntrance) {
-            // If we are trying to apply an animation, but already running
-            // an animation of the same type, then just leave that one alone.
-            return true;
-        }
-
-        // Only apply an animation if the display isn't frozen.  If it is
-        // frozen, there is no reason to animate and it can cause strange
-        // artifacts when we unfreeze the display if some different animation
-        // is running.
-        if (mService.okToDisplay()) {
-            int anim = mPolicy.selectAnimationLw(mWin, transit);
-            int attr = -1;
-            Animation a = null;
-            if (anim != 0) {
-                a = anim != -1 ? AnimationUtils.loadAnimation(mContext, anim) : null;
-            } else {
-                switch (transit) {
-                    case WindowManagerPolicy.TRANSIT_ENTER:
-                        attr = com.android.internal.R.styleable.WindowAnimation_windowEnterAnimation;
-                        break;
-                    case WindowManagerPolicy.TRANSIT_EXIT:
-                        attr = com.android.internal.R.styleable.WindowAnimation_windowExitAnimation;
-                        break;
-                    case WindowManagerPolicy.TRANSIT_SHOW:
-                        attr = com.android.internal.R.styleable.WindowAnimation_windowShowAnimation;
-                        break;
-                    case WindowManagerPolicy.TRANSIT_HIDE:
-                        attr = com.android.internal.R.styleable.WindowAnimation_windowHideAnimation;
-                        break;
-                }
-                if (attr >= 0) {
-                    a = mService.mAppTransition.loadAnimation(mWin.mAttrs, attr);
-                }
-            }
-            if (WindowManagerService.DEBUG_ANIM) Slog.v(TAG,
-                    "applyAnimation: win=" + this
-                    + " anim=" + anim + " attr=0x" + Integer.toHexString(attr)
-                    + " a=" + a
-                    + " transit=" + transit
-                    + " isEntrance=" + isEntrance + " Callers " + Debug.getCallers(3));
-            if (a != null) {
-                if (WindowManagerService.DEBUG_ANIM) {
-                    RuntimeException e = null;
-                    if (!WindowManagerService.HIDE_STACK_CRAWLS) {
-                        e = new RuntimeException();
-                        e.fillInStackTrace();
-                    }
-                    Slog.v(TAG, "Loaded animation " + a + " for " + this, e);
-                }
-                setAnimation(a);
-                mAnimationIsEntrance = isEntrance;
-            }
-        } else {
-            clearAnimation();
-        }
-
-        return mAnimation != null;
-    }
-
-    public void dump(PrintWriter pw, String prefix, boolean dumpAll) {
-        if (mAnimating || mLocalAnimating || mAnimationIsEntrance
-                || mAnimation != null) {
-            pw.print(prefix); pw.print("mAnimating="); pw.print(mAnimating);
-                    pw.print(" mLocalAnimating="); pw.print(mLocalAnimating);
-                    pw.print(" mAnimationIsEntrance="); pw.print(mAnimationIsEntrance);
-                    pw.print(" mAnimation="); pw.println(mAnimation);
-        }
-        if (mHasTransformation || mHasLocalTransformation) {
-            pw.print(prefix); pw.print("XForm: has=");
-                    pw.print(mHasTransformation);
-                    pw.print(" hasLocal="); pw.print(mHasLocalTransformation);
-                    pw.print(" "); mTransformation.printShortString(pw);
-                    pw.println();
-        }
-        if (mSurfaceControl != null) {
-            if (dumpAll) {
-                pw.print(prefix); pw.print("mSurface="); pw.println(mSurfaceControl);
-                pw.print(prefix); pw.print("mDrawState=");
-                pw.print(drawStateToString(mDrawState));
-                pw.print(" mLastHidden="); pw.println(mLastHidden);
-            }
-            pw.print(prefix); pw.print("Surface: shown="); pw.print(mSurfaceShown);
-                    pw.print(" layer="); pw.print(mSurfaceLayer);
-                    pw.print(" alpha="); pw.print(mSurfaceAlpha);
-                    pw.print(" rect=("); pw.print(mSurfaceX);
-                    pw.print(","); pw.print(mSurfaceY);
-                    pw.print(") "); pw.print(mSurfaceW);
-                    pw.print(" x "); pw.println(mSurfaceH);
-        }
-        if (mPendingDestroySurface != null) {
-            pw.print(prefix); pw.print("mPendingDestroySurface=");
-                    pw.println(mPendingDestroySurface);
-        }
-        if (mSurfaceResized || mSurfaceDestroyDeferred) {
-            pw.print(prefix); pw.print("mSurfaceResized="); pw.print(mSurfaceResized);
-                    pw.print(" mSurfaceDestroyDeferred="); pw.println(mSurfaceDestroyDeferred);
-        }
-        if (mWin.mAttrs.type == WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND) {
-            pw.print(prefix); pw.print("mUniverseTransform=");
-                    mUniverseTransform.printShortString(pw);
-                    pw.println();
-        }
-        if (mShownAlpha != 1 || mAlpha != 1 || mLastAlpha != 1) {
-            pw.print(prefix); pw.print("mShownAlpha="); pw.print(mShownAlpha);
-                    pw.print(" mAlpha="); pw.print(mAlpha);
-                    pw.print(" mLastAlpha="); pw.println(mLastAlpha);
-        }
-        if (mHaveMatrix || mWin.mGlobalScale != 1) {
-            pw.print(prefix); pw.print("mGlobalScale="); pw.print(mWin.mGlobalScale);
-                    pw.print(" mDsDx="); pw.print(mDsDx);
-                    pw.print(" mDtDx="); pw.print(mDtDx);
-                    pw.print(" mDsDy="); pw.print(mDsDy);
-                    pw.print(" mDtDy="); pw.println(mDtDy);
-        }
-    }
-
-    @Override
-    public String toString() {
-        StringBuffer sb = new StringBuffer("WindowStateAnimator{");
-        sb.append(Integer.toHexString(System.identityHashCode(this)));
-        sb.append(' ');
-        sb.append(mWin.mAttrs.getTitle());
-        sb.append('}');
-        return sb.toString();
-    }
-}
diff --git a/services/jni/Android.mk b/services/jni/Android.mk
deleted file mode 100644
index 98e9b30..0000000
--- a/services/jni/Android.mk
+++ /dev/null
@@ -1,63 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    com_android_server_AlarmManagerService.cpp \
-    com_android_server_AssetAtlasService.cpp \
-    com_android_server_ConsumerIrService.cpp \
-    com_android_server_input_InputApplicationHandle.cpp \
-    com_android_server_input_InputManagerService.cpp \
-    com_android_server_input_InputWindowHandle.cpp \
-    com_android_server_LightsService.cpp \
-    com_android_server_power_PowerManagerService.cpp \
-    com_android_server_SerialService.cpp \
-    com_android_server_SystemServer.cpp \
-    com_android_server_UsbDeviceManager.cpp \
-    com_android_server_UsbHostManager.cpp \
-    com_android_server_VibratorService.cpp \
-    com_android_server_location_GpsLocationProvider.cpp \
-    com_android_server_location_FlpHardwareProvider.cpp \
-    com_android_server_connectivity_Vpn.cpp \
-    onload.cpp
-
-LOCAL_C_INCLUDES += \
-    $(JNI_H_INCLUDE) \
-    frameworks/base/services \
-    frameworks/base/core/jni \
-    frameworks/native/services \
-    external/skia/include/core \
-    libcore/include \
-    libcore/include/libsuspend \
-	$(call include-path-for, libhardware)/hardware \
-	$(call include-path-for, libhardware_legacy)/hardware_legacy \
-
-LOCAL_SHARED_LIBRARIES := \
-    libandroid_runtime \
-    libandroidfw \
-    libbinder \
-    libcutils \
-    liblog \
-    libhardware \
-    libhardware_legacy \
-    libnativehelper \
-    libutils \
-    libui \
-    libinput \
-    libinputservice \
-    libsensorservice \
-    libskia \
-    libgui \
-    libusbhost \
-    libsuspend \
-    libEGL \
-    libGLESv2
-
-LOCAL_CFLAGS += -DEGL_EGLEXT_PROTOTYPES -DGL_GLEXT_PROTOTYPES
-
-ifeq ($(WITH_MALLOC_LEAK_CHECK),true)
-    LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK
-endif
-
-LOCAL_MODULE:= libandroid_servers
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/services/jni/com_android_server_AlarmManagerService.cpp b/services/jni/com_android_server_AlarmManagerService.cpp
deleted file mode 100644
index c2f6151..0000000
--- a/services/jni/com_android_server_AlarmManagerService.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/* //device/libs/android_runtime/android_server_AlarmManagerService.cpp
-**
-** Copyright 2006, 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.
-*/
-
-#define LOG_TAG "AlarmManagerService"
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include <utils/Log.h>
-#include <utils/misc.h>
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <linux/ioctl.h>
-#include <linux/android_alarm.h>
-
-namespace android {
-
-static jint android_server_AlarmManagerService_setKernelTimezone(JNIEnv* env, jobject obj, jint fd, jint minswest)
-{
-    struct timezone tz;
-
-    tz.tz_minuteswest = minswest;
-    tz.tz_dsttime = 0;
-
-    int result = settimeofday(NULL, &tz);
-    if (result < 0) {
-        ALOGE("Unable to set kernel timezone to %d: %s\n", minswest, strerror(errno));
-        return -1;
-    } else {
-        ALOGD("Kernel timezone updated to %d minutes west of GMT\n", minswest);
-    }
-
-    return 0;
-}
-
-static jint android_server_AlarmManagerService_init(JNIEnv* env, jobject obj)
-{
-    return open("/dev/alarm", O_RDWR);
-}
-
-static void android_server_AlarmManagerService_close(JNIEnv* env, jobject obj, jint fd)
-{
-	close(fd);
-}
-
-static void android_server_AlarmManagerService_set(JNIEnv* env, jobject obj, jint fd, jint type, jlong seconds, jlong nanoseconds)
-{
-    struct timespec ts;
-    ts.tv_sec = seconds;
-    ts.tv_nsec = nanoseconds;
-
-	int result = ioctl(fd, ANDROID_ALARM_SET(type), &ts);
-	if (result < 0)
-	{
-        ALOGE("Unable to set alarm to %lld.%09lld: %s\n", seconds, nanoseconds, strerror(errno));
-    }
-}
-
-static jint android_server_AlarmManagerService_waitForAlarm(JNIEnv* env, jobject obj, jint fd)
-{
-	int result = 0;
-
-	do
-	{
-		result = ioctl(fd, ANDROID_ALARM_WAIT);
-	} while (result < 0 && errno == EINTR);
-
-	if (result < 0)
-	{
-        ALOGE("Unable to wait on alarm: %s\n", strerror(errno));
-        return 0;
-    }
-
-    return result;
-}
-
-static JNINativeMethod sMethods[] = {
-     /* name, signature, funcPtr */
-	{"init", "()I", (void*)android_server_AlarmManagerService_init},
-	{"close", "(I)V", (void*)android_server_AlarmManagerService_close},
-	{"set", "(IIJJ)V", (void*)android_server_AlarmManagerService_set},
-    {"waitForAlarm", "(I)I", (void*)android_server_AlarmManagerService_waitForAlarm},
-    {"setKernelTimezone", "(II)I", (void*)android_server_AlarmManagerService_setKernelTimezone},
-};
-
-int register_android_server_AlarmManagerService(JNIEnv* env)
-{
-    return jniRegisterNativeMethods(env, "com/android/server/AlarmManagerService",
-                                    sMethods, NELEM(sMethods));
-}
-
-} /* namespace android */
diff --git a/services/jni/com_android_server_AssetAtlasService.cpp b/services/jni/com_android_server_AssetAtlasService.cpp
deleted file mode 100644
index 885d21e..0000000
--- a/services/jni/com_android_server_AssetAtlasService.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#define LOG_TAG "AssetAtlasService"
-
-#include "jni.h"
-#include "JNIHelp.h"
-
-#include <android_view_GraphicBuffer.h>
-#include <cutils/log.h>
-
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-#include <SkCanvas.h>
-#include <SkBitmap.h>
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-// Defines
-// ----------------------------------------------------------------------------
-
-// Defines how long to wait for the GPU when uploading the atlas
-// This timeout is defined in nanoseconds (see EGL_KHR_fence_sync extension)
-#define FENCE_TIMEOUT 2000000000
-
-// ----------------------------------------------------------------------------
-// JNI Helpers
-// ----------------------------------------------------------------------------
-
-static struct {
-    jfieldID mFinalizer;
-    jfieldID mNativeCanvas;
-} gCanvasClassInfo;
-
-static struct {
-    jfieldID mNativeCanvas;
-} gCanvasFinalizerClassInfo;
-
-#define GET_INT(object, field) \
-    env->GetIntField(object, field)
-
-#define SET_INT(object, field, value) \
-    env->SetIntField(object, field, value)
-
-// ----------------------------------------------------------------------------
-// Canvas management
-// ----------------------------------------------------------------------------
-
-static inline void swapCanvasPtr(JNIEnv* env, jobject canvasObj, SkCanvas* newCanvas) {
-    jobject canvasFinalizerObj = env->GetObjectField(canvasObj, gCanvasClassInfo.mFinalizer);
-    SkCanvas* previousCanvas = reinterpret_cast<SkCanvas*>(
-            GET_INT(canvasObj, gCanvasClassInfo.mNativeCanvas));
-    SET_INT(canvasObj, gCanvasClassInfo.mNativeCanvas, (int) newCanvas);
-    SET_INT(canvasFinalizerObj, gCanvasFinalizerClassInfo.mNativeCanvas, (int) newCanvas);
-    SkSafeUnref(previousCanvas);
-}
-
-static SkBitmap* com_android_server_AssetAtlasService_acquireCanvas(JNIEnv* env, jobject,
-        jobject canvas, jint width, jint height) {
-
-    SkBitmap* bitmap = new SkBitmap;
-    bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
-    bitmap->allocPixels();
-    bitmap->eraseColor(0);
-
-    SkCanvas* nativeCanvas = SkNEW_ARGS(SkCanvas, (*bitmap));
-    swapCanvasPtr(env, canvas, nativeCanvas);
-
-    return bitmap;
-}
-
-static void com_android_server_AssetAtlasService_releaseCanvas(JNIEnv* env, jobject,
-        jobject canvas, SkBitmap* bitmap) {
-
-    SkCanvas* nativeCanvas = SkNEW(SkCanvas);
-    swapCanvasPtr(env, canvas, nativeCanvas);
-
-    delete bitmap;
-}
-
-#define CLEANUP_GL_AND_RETURN(result) \
-    if (fence != EGL_NO_SYNC_KHR) eglDestroySyncKHR(display, fence); \
-    if (image) eglDestroyImageKHR(display, image); \
-    if (texture) glDeleteTextures(1, &texture); \
-    if (surface != EGL_NO_SURFACE) eglDestroySurface(display, surface); \
-    if (context != EGL_NO_CONTEXT) eglDestroyContext(display, context); \
-    eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \
-    eglReleaseThread(); \
-    eglTerminate(display); \
-    return result;
-
-static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject,
-        jobject graphicBuffer, SkBitmap* bitmap) {
-
-    // The goal of this method is to copy the bitmap into the GraphicBuffer
-    // using the GPU to swizzle the texture content
-    sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer));
-
-    if (buffer != NULL) {
-        EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-        if (display == EGL_NO_DISPLAY) return false;
-
-        EGLint major;
-        EGLint minor;
-        if (!eglInitialize(display, &major, &minor)) {
-            ALOGW("Could not initialize EGL");
-            return false;
-        }
-
-        // We're going to use a 1x1 pbuffer surface later on
-        // The configuration doesn't really matter for what we're trying to do
-        EGLint configAttrs[] = {
-                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-                EGL_RED_SIZE, 8,
-                EGL_GREEN_SIZE, 8,
-                EGL_BLUE_SIZE, 8,
-                EGL_ALPHA_SIZE, 0,
-                EGL_DEPTH_SIZE, 0,
-                EGL_STENCIL_SIZE, 0,
-                EGL_NONE
-        };
-        EGLConfig configs[1];
-        EGLint configCount;
-        if (!eglChooseConfig(display, configAttrs, configs, 1, &configCount)) {
-            ALOGW("Could not select EGL configuration");
-            eglReleaseThread();
-            eglTerminate(display);
-            return false;
-        }
-        if (configCount <= 0) {
-            ALOGW("Could not find EGL configuration");
-            eglReleaseThread();
-            eglTerminate(display);
-            return false;
-        }
-
-        // These objects are initialized below but the default "null"
-        // values are used to cleanup properly at any point in the
-        // initialization sequence
-        GLuint texture = 0;
-        EGLImageKHR image = EGL_NO_IMAGE_KHR;
-        EGLSurface surface = EGL_NO_SURFACE;
-        EGLSyncKHR fence = EGL_NO_SYNC_KHR;
-
-        EGLint attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
-        EGLContext context = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, attrs);
-        if (context == EGL_NO_CONTEXT) {
-            ALOGW("Could not create EGL context");
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        // Create the 1x1 pbuffer
-        EGLint surfaceAttrs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
-        surface = eglCreatePbufferSurface(display, configs[0], surfaceAttrs);
-        if (surface == EGL_NO_SURFACE) {
-            ALOGW("Could not create EGL surface");
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        if (!eglMakeCurrent(display, surface, surface, context)) {
-            ALOGW("Could not change current EGL context");
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        // We use an EGLImage to access the content of the GraphicBuffer
-        // The EGL image is later bound to a 2D texture
-        EGLClientBuffer clientBuffer = (EGLClientBuffer) buffer->getNativeBuffer();
-        EGLint imageAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
-        image = eglCreateImageKHR(display, EGL_NO_CONTEXT,
-                EGL_NATIVE_BUFFER_ANDROID, clientBuffer, imageAttrs);
-        if (image == EGL_NO_IMAGE_KHR) {
-            ALOGW("Could not create EGL image");
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        glGenTextures(1, &texture);
-        glBindTexture(GL_TEXTURE_2D, texture);
-        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
-        if (glGetError() != GL_NO_ERROR) {
-            ALOGW("Could not create/bind texture");
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        // Upload the content of the bitmap in the GraphicBuffer
-        glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
-        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap->width(), bitmap->height(),
-                GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels());
-        if (glGetError() != GL_NO_ERROR) {
-            ALOGW("Could not upload to texture");
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        // The fence is used to wait for the texture upload to finish
-        // properly. We cannot rely on glFlush() and glFinish() as
-        // some drivers completely ignore these API calls
-        fence = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
-        if (fence == EGL_NO_SYNC_KHR) {
-            ALOGW("Could not create sync fence %#x", eglGetError());
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        // The flag EGL_SYNC_FLUSH_COMMANDS_BIT_KHR will trigger a
-        // pipeline flush (similar to what a glFlush() would do.)
-        EGLint waitStatus = eglClientWaitSyncKHR(display, fence,
-                EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, FENCE_TIMEOUT);
-        if (waitStatus != EGL_CONDITION_SATISFIED_KHR) {
-            ALOGW("Failed to wait for the fence %#x", eglGetError());
-            CLEANUP_GL_AND_RETURN(false);
-        }
-
-        CLEANUP_GL_AND_RETURN(true);
-    }
-
-    return false;
-}
-
-// ----------------------------------------------------------------------------
-// JNI Glue
-// ----------------------------------------------------------------------------
-
-#define FIND_CLASS(var, className) \
-        var = env->FindClass(className); \
-        LOG_FATAL_IF(! var, "Unable to find class " className);
-
-#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
-        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
-        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
-
-const char* const kClassPathName = "com/android/server/AssetAtlasService";
-
-static JNINativeMethod gMethods[] = {
-    { "nAcquireAtlasCanvas", "(Landroid/graphics/Canvas;II)I",
-            (void*) com_android_server_AssetAtlasService_acquireCanvas },
-    { "nReleaseAtlasCanvas", "(Landroid/graphics/Canvas;I)V",
-            (void*) com_android_server_AssetAtlasService_releaseCanvas },
-    { "nUploadAtlas", "(Landroid/view/GraphicBuffer;I)Z",
-            (void*) com_android_server_AssetAtlasService_upload },
-};
-
-int register_android_server_AssetAtlasService(JNIEnv* env) {
-    jclass clazz;
-
-    FIND_CLASS(clazz, "android/graphics/Canvas");
-    GET_FIELD_ID(gCanvasClassInfo.mFinalizer, clazz, "mFinalizer",
-            "Landroid/graphics/Canvas$CanvasFinalizer;");
-    GET_FIELD_ID(gCanvasClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
-
-    FIND_CLASS(clazz, "android/graphics/Canvas$CanvasFinalizer");
-    GET_FIELD_ID(gCanvasFinalizerClassInfo.mNativeCanvas, clazz, "mNativeCanvas", "I");
-
-    return jniRegisterNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
-}
-
-};
diff --git a/services/jni/com_android_server_LightsService.cpp b/services/jni/com_android_server_LightsService.cpp
deleted file mode 100644
index 401e1aa..0000000
--- a/services/jni/com_android_server_LightsService.cpp
+++ /dev/null
@@ -1,141 +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.
- */
-
-#define LOG_TAG "LightsService"
-
-#include "jni.h"
-#include "JNIHelp.h"
-#include "android_runtime/AndroidRuntime.h"
-
-#include <utils/misc.h>
-#include <utils/Log.h>
-#include <hardware/hardware.h>
-#include <hardware/lights.h>
-
-#include <stdio.h>
-
-namespace android
-{
-
-// These values must correspond with the LIGHT_ID constants in
-// LightsService.java
-enum {
-    LIGHT_INDEX_BACKLIGHT = 0,
-    LIGHT_INDEX_KEYBOARD = 1,
-    LIGHT_INDEX_BUTTONS = 2,
-    LIGHT_INDEX_BATTERY = 3,
-    LIGHT_INDEX_NOTIFICATIONS = 4,
-    LIGHT_INDEX_ATTENTION = 5,
-    LIGHT_INDEX_BLUETOOTH = 6,
-    LIGHT_INDEX_WIFI = 7,
-    LIGHT_COUNT
-};
-
-struct Devices {
-    light_device_t* lights[LIGHT_COUNT];
-};
-
-static light_device_t* get_device(hw_module_t* module, char const* name)
-{
-    int err;
-    hw_device_t* device;
-    err = module->methods->open(module, name, &device);
-    if (err == 0) {
-        return (light_device_t*)device;
-    } else {
-        return NULL;
-    }
-}
-
-static jint init_native(JNIEnv *env, jobject clazz)
-{
-    int err;
-    hw_module_t* module;
-    Devices* devices;
-    
-    devices = (Devices*)malloc(sizeof(Devices));
-
-    err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
-    if (err == 0) {
-        devices->lights[LIGHT_INDEX_BACKLIGHT]
-                = get_device(module, LIGHT_ID_BACKLIGHT);
-        devices->lights[LIGHT_INDEX_KEYBOARD]
-                = get_device(module, LIGHT_ID_KEYBOARD);
-        devices->lights[LIGHT_INDEX_BUTTONS]
-                = get_device(module, LIGHT_ID_BUTTONS);
-        devices->lights[LIGHT_INDEX_BATTERY]
-                = get_device(module, LIGHT_ID_BATTERY);
-        devices->lights[LIGHT_INDEX_NOTIFICATIONS]
-                = get_device(module, LIGHT_ID_NOTIFICATIONS);
-        devices->lights[LIGHT_INDEX_ATTENTION]
-                = get_device(module, LIGHT_ID_ATTENTION);
-        devices->lights[LIGHT_INDEX_BLUETOOTH]
-                = get_device(module, LIGHT_ID_BLUETOOTH);
-        devices->lights[LIGHT_INDEX_WIFI]
-                = get_device(module, LIGHT_ID_WIFI);
-    } else {
-        memset(devices, 0, sizeof(Devices));
-    }
-
-    return (jint)devices;
-}
-
-static void finalize_native(JNIEnv *env, jobject clazz, int ptr)
-{
-    Devices* devices = (Devices*)ptr;
-    if (devices == NULL) {
-        return;
-    }
-
-    free(devices);
-}
-
-static void setLight_native(JNIEnv *env, jobject clazz, int ptr,
-        int light, int colorARGB, int flashMode, int onMS, int offMS, int brightnessMode)
-{
-    Devices* devices = (Devices*)ptr;
-    light_state_t state;
-
-    if (light < 0 || light >= LIGHT_COUNT || devices->lights[light] == NULL) {
-        return ;
-    }
-
-    memset(&state, 0, sizeof(light_state_t));
-    state.color = colorARGB;
-    state.flashMode = flashMode;
-    state.flashOnMS = onMS;
-    state.flashOffMS = offMS;
-    state.brightnessMode = brightnessMode;
-
-    {
-        ALOGD_IF_SLOW(50, "Excessive delay setting light");
-        devices->lights[light]->set_light(devices->lights[light], &state);
-    }
-}
-
-static JNINativeMethod method_table[] = {
-    { "init_native", "()I", (void*)init_native },
-    { "finalize_native", "(I)V", (void*)finalize_native },
-    { "setLight_native", "(IIIIIII)V", (void*)setLight_native },
-};
-
-int register_android_server_LightsService(JNIEnv *env)
-{
-    return jniRegisterNativeMethods(env, "com/android/server/LightsService",
-            method_table, NELEM(method_table));
-}
-
-};
diff --git a/services/jni/com_android_server_UsbHostManager.cpp b/services/jni/com_android_server_UsbHostManager.cpp
deleted file mode 100644
index 639790b7..0000000
--- a/services/jni/com_android_server_UsbHostManager.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#define LOG_TAG "UsbHostManagerJNI"
-#include "utils/Log.h"
-
-#include "jni.h"
-#include "JNIHelp.h"
-#include "android_runtime/AndroidRuntime.h"
-#include "android_runtime/Log.h"
-#include "utils/Vector.h"
-
-#include <usbhost/usbhost.h>
-
-#include <stdio.h>
-#include <asm/byteorder.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-
-namespace android
-{
-
-static struct parcel_file_descriptor_offsets_t
-{
-    jclass mClass;
-    jmethodID mConstructor;
-} gParcelFileDescriptorOffsets;
-
-static jmethodID method_usbDeviceAdded;
-static jmethodID method_usbDeviceRemoved;
-
-static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
-    if (env->ExceptionCheck()) {
-        ALOGE("An exception was thrown by callback '%s'.", methodName);
-        LOGE_EX(env);
-        env->ExceptionClear();
-    }
-}
-
-static int usb_device_added(const char *devname, void* client_data) {
-    struct usb_descriptor_header* desc;
-    struct usb_descriptor_iter iter;
-
-    struct usb_device *device = usb_device_open(devname);
-    if (!device) {
-        ALOGE("usb_device_open failed\n");
-        return 0;
-    }
-
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jobject thiz = (jobject)client_data;
-    Vector<int> interfaceValues;
-    Vector<int> endpointValues;
-    const usb_device_descriptor* deviceDesc = usb_device_get_device_descriptor(device);
-
-    uint16_t vendorId = usb_device_get_vendor_id(device);
-    uint16_t productId = usb_device_get_product_id(device);
-    uint8_t deviceClass = deviceDesc->bDeviceClass;
-    uint8_t deviceSubClass = deviceDesc->bDeviceSubClass;
-    uint8_t protocol = deviceDesc->bDeviceProtocol;
-
-    usb_descriptor_iter_init(device, &iter);
-
-    while ((desc = usb_descriptor_iter_next(&iter)) != NULL) {
-        if (desc->bDescriptorType == USB_DT_INTERFACE) {
-            struct usb_interface_descriptor *interface = (struct usb_interface_descriptor *)desc;
-
-            // push class, subclass, protocol and number of endpoints into interfaceValues vector
-            interfaceValues.add(interface->bInterfaceNumber);
-            interfaceValues.add(interface->bInterfaceClass);
-            interfaceValues.add(interface->bInterfaceSubClass);
-            interfaceValues.add(interface->bInterfaceProtocol);
-            interfaceValues.add(interface->bNumEndpoints);
-        } else if (desc->bDescriptorType == USB_DT_ENDPOINT) {
-            struct usb_endpoint_descriptor *endpoint = (struct usb_endpoint_descriptor *)desc;
-
-            // push address, attributes, max packet size and interval into endpointValues vector
-            endpointValues.add(endpoint->bEndpointAddress);
-            endpointValues.add(endpoint->bmAttributes);
-            endpointValues.add(__le16_to_cpu(endpoint->wMaxPacketSize));
-            endpointValues.add(endpoint->bInterval);
-        }
-    }
-
-    usb_device_close(device);
-
-    // handle generic device notification
-    int length = interfaceValues.size();
-    jintArray interfaceArray = env->NewIntArray(length);
-    env->SetIntArrayRegion(interfaceArray, 0, length, interfaceValues.array());
-
-    length = endpointValues.size();
-    jintArray endpointArray = env->NewIntArray(length);
-    env->SetIntArrayRegion(endpointArray, 0, length, endpointValues.array());
-
-    jstring deviceName = env->NewStringUTF(devname);
-    env->CallVoidMethod(thiz, method_usbDeviceAdded,
-            deviceName, vendorId, productId, deviceClass,
-            deviceSubClass, protocol, interfaceArray, endpointArray);
-
-    env->DeleteLocalRef(interfaceArray);
-    env->DeleteLocalRef(endpointArray);
-    env->DeleteLocalRef(deviceName);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-
-    return 0;
-}
-
-static int usb_device_removed(const char *devname, void* client_data) {
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jobject thiz = (jobject)client_data;
-
-    jstring deviceName = env->NewStringUTF(devname);
-    env->CallVoidMethod(thiz, method_usbDeviceRemoved, deviceName);
-    env->DeleteLocalRef(deviceName);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-    return 0;
-}
-
-static void android_server_UsbHostManager_monitorUsbHostBus(JNIEnv *env, jobject thiz)
-{
-    struct usb_host_context* context = usb_host_init();
-    if (!context) {
-        ALOGE("usb_host_init failed");
-        return;
-    }
-    // this will never return so it is safe to pass thiz directly
-    usb_host_run(context, usb_device_added, usb_device_removed, NULL, (void *)thiz);
-}
-
-static jobject android_server_UsbHostManager_openDevice(JNIEnv *env, jobject thiz, jstring deviceName)
-{
-    const char *deviceNameStr = env->GetStringUTFChars(deviceName, NULL);
-    struct usb_device* device = usb_device_open(deviceNameStr);
-    env->ReleaseStringUTFChars(deviceName, deviceNameStr);
-
-    if (!device)
-        return NULL;
-
-    int fd = usb_device_get_fd(device);
-    if (fd < 0)
-        return NULL;
-    int newFD = dup(fd);
-    usb_device_close(device);
-
-    jobject fileDescriptor = jniCreateFileDescriptor(env, newFD);
-    if (fileDescriptor == NULL) {
-        return NULL;
-    }
-    return env->NewObject(gParcelFileDescriptorOffsets.mClass,
-        gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
-}
-
-static JNINativeMethod method_table[] = {
-    { "monitorUsbHostBus", "()V", (void*)android_server_UsbHostManager_monitorUsbHostBus },
-    { "nativeOpenDevice",  "(Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;",
-                                  (void*)android_server_UsbHostManager_openDevice },
-};
-
-int register_android_server_UsbHostManager(JNIEnv *env)
-{
-    jclass clazz = env->FindClass("com/android/server/usb/UsbHostManager");
-    if (clazz == NULL) {
-        ALOGE("Can't find com/android/server/usb/UsbHostManager");
-        return -1;
-    }
-    method_usbDeviceAdded = env->GetMethodID(clazz, "usbDeviceAdded", "(Ljava/lang/String;IIIII[I[I)V");
-    if (method_usbDeviceAdded == NULL) {
-        ALOGE("Can't find usbDeviceAdded");
-        return -1;
-    }
-    method_usbDeviceRemoved = env->GetMethodID(clazz, "usbDeviceRemoved", "(Ljava/lang/String;)V");
-    if (method_usbDeviceRemoved == NULL) {
-        ALOGE("Can't find usbDeviceRemoved");
-        return -1;
-    }
-
-    clazz = env->FindClass("android/os/ParcelFileDescriptor");
-    LOG_FATAL_IF(clazz == NULL, "Unable to find class android.os.ParcelFileDescriptor");
-    gParcelFileDescriptorOffsets.mClass = (jclass) env->NewGlobalRef(clazz);
-    gParcelFileDescriptorOffsets.mConstructor = env->GetMethodID(clazz, "<init>", "(Ljava/io/FileDescriptor;)V");
-    LOG_FATAL_IF(gParcelFileDescriptorOffsets.mConstructor == NULL,
-                 "Unable to find constructor for android.os.ParcelFileDescriptor");
-
-    return jniRegisterNativeMethods(env, "com/android/server/usb/UsbHostManager",
-            method_table, NELEM(method_table));
-}
-
-};
diff --git a/services/jni/com_android_server_input_InputApplicationHandle.cpp b/services/jni/com_android_server_input_InputApplicationHandle.cpp
deleted file mode 100644
index b9681ab..0000000
--- a/services/jni/com_android_server_input_InputApplicationHandle.cpp
+++ /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.
- */
-
-#define LOG_TAG "InputApplicationHandle"
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include <android_runtime/AndroidRuntime.h>
-#include <utils/threads.h>
-
-#include "com_android_server_input_InputApplicationHandle.h"
-
-namespace android {
-
-static struct {
-    jfieldID ptr;
-    jfieldID name;
-    jfieldID dispatchingTimeoutNanos;
-} gInputApplicationHandleClassInfo;
-
-static Mutex gHandleMutex;
-
-
-// --- NativeInputApplicationHandle ---
-
-NativeInputApplicationHandle::NativeInputApplicationHandle(jweak objWeak) :
-        mObjWeak(objWeak) {
-}
-
-NativeInputApplicationHandle::~NativeInputApplicationHandle() {
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->DeleteWeakGlobalRef(mObjWeak);
-}
-
-jobject NativeInputApplicationHandle::getInputApplicationHandleObjLocalRef(JNIEnv* env) {
-    return env->NewLocalRef(mObjWeak);
-}
-
-bool NativeInputApplicationHandle::updateInfo() {
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jobject obj = env->NewLocalRef(mObjWeak);
-    if (!obj) {
-        releaseInfo();
-        return false;
-    }
-
-    if (!mInfo) {
-        mInfo = new InputApplicationInfo();
-    }
-
-    jstring nameObj = jstring(env->GetObjectField(obj,
-            gInputApplicationHandleClassInfo.name));
-    if (nameObj) {
-        const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
-        mInfo->name.setTo(nameStr);
-        env->ReleaseStringUTFChars(nameObj, nameStr);
-        env->DeleteLocalRef(nameObj);
-    } else {
-        mInfo->name.setTo("<null>");
-    }
-
-    mInfo->dispatchingTimeout = env->GetLongField(obj,
-            gInputApplicationHandleClassInfo.dispatchingTimeoutNanos);
-
-    env->DeleteLocalRef(obj);
-    return true;
-}
-
-
-// --- Global functions ---
-
-sp<InputApplicationHandle> android_server_InputApplicationHandle_getHandle(
-        JNIEnv* env, jobject inputApplicationHandleObj) {
-    if (!inputApplicationHandleObj) {
-        return NULL;
-    }
-
-    AutoMutex _l(gHandleMutex);
-
-    int ptr = env->GetIntField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr);
-    NativeInputApplicationHandle* handle;
-    if (ptr) {
-        handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
-    } else {
-        jweak objWeak = env->NewWeakGlobalRef(inputApplicationHandleObj);
-        handle = new NativeInputApplicationHandle(objWeak);
-        handle->incStrong((void*)android_server_InputApplicationHandle_getHandle);
-        env->SetIntField(inputApplicationHandleObj, gInputApplicationHandleClassInfo.ptr,
-                reinterpret_cast<int>(handle));
-    }
-    return handle;
-}
-
-
-// --- JNI ---
-
-static void android_server_InputApplicationHandle_nativeDispose(JNIEnv* env, jobject obj) {
-    AutoMutex _l(gHandleMutex);
-
-    int ptr = env->GetIntField(obj, gInputApplicationHandleClassInfo.ptr);
-    if (ptr) {
-        env->SetIntField(obj, gInputApplicationHandleClassInfo.ptr, 0);
-
-        NativeInputApplicationHandle* handle = reinterpret_cast<NativeInputApplicationHandle*>(ptr);
-        handle->decStrong((void*)android_server_InputApplicationHandle_getHandle);
-    }
-}
-
-
-static JNINativeMethod gInputApplicationHandleMethods[] = {
-    /* name, signature, funcPtr */
-    { "nativeDispose", "()V",
-            (void*) android_server_InputApplicationHandle_nativeDispose },
-};
-
-#define FIND_CLASS(var, className) \
-        var = env->FindClass(className); \
-        LOG_FATAL_IF(! var, "Unable to find class " className);
-
-#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
-        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
-        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
-
-int register_android_server_InputApplicationHandle(JNIEnv* env) {
-    int res = jniRegisterNativeMethods(env, "com/android/server/input/InputApplicationHandle",
-            gInputApplicationHandleMethods, NELEM(gInputApplicationHandleMethods));
-    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
-
-    jclass clazz;
-    FIND_CLASS(clazz, "com/android/server/input/InputApplicationHandle");
-
-    GET_FIELD_ID(gInputApplicationHandleClassInfo.ptr, clazz,
-            "ptr", "I");
-
-    GET_FIELD_ID(gInputApplicationHandleClassInfo.name, clazz,
-            "name", "Ljava/lang/String;");
-
-    GET_FIELD_ID(gInputApplicationHandleClassInfo.dispatchingTimeoutNanos,
-            clazz,
-            "dispatchingTimeoutNanos", "J");
-
-    return 0;
-}
-
-} /* namespace android */
diff --git a/services/jni/com_android_server_input_InputManagerService.cpp b/services/jni/com_android_server_input_InputManagerService.cpp
deleted file mode 100644
index 4ab2086..0000000
--- a/services/jni/com_android_server_input_InputManagerService.cpp
+++ /dev/null
@@ -1,1464 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#define LOG_TAG "InputManager-JNI"
-
-//#define LOG_NDEBUG 0
-
-// Log debug messages about InputReaderPolicy
-#define DEBUG_INPUT_READER_POLICY 0
-
-// Log debug messages about InputDispatcherPolicy
-#define DEBUG_INPUT_DISPATCHER_POLICY 0
-
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include <limits.h>
-#include <android_runtime/AndroidRuntime.h>
-#include <android_runtime/Log.h>
-
-#include <utils/Log.h>
-#include <utils/Looper.h>
-#include <utils/threads.h>
-
-#include <input/InputManager.h>
-#include <input/PointerController.h>
-#include <input/SpriteController.h>
-
-#include <android_os_MessageQueue.h>
-#include <android_view_InputDevice.h>
-#include <android_view_KeyEvent.h>
-#include <android_view_MotionEvent.h>
-#include <android_view_InputChannel.h>
-#include <android_view_PointerIcon.h>
-#include <android/graphics/GraphicsJNI.h>
-
-#include <ScopedLocalRef.h>
-#include <ScopedUtfChars.h>
-
-#include "com_android_server_power_PowerManagerService.h"
-#include "com_android_server_input_InputApplicationHandle.h"
-#include "com_android_server_input_InputWindowHandle.h"
-
-namespace android {
-
-// The exponent used to calculate the pointer speed scaling factor.
-// The scaling factor is calculated as 2 ^ (speed * exponent),
-// where the speed ranges from -7 to + 7 and is supplied by the user.
-static const float POINTER_SPEED_EXPONENT = 1.0f / 4;
-
-static struct {
-    jmethodID notifyConfigurationChanged;
-    jmethodID notifyInputDevicesChanged;
-    jmethodID notifySwitch;
-    jmethodID notifyInputChannelBroken;
-    jmethodID notifyANR;
-    jmethodID filterInputEvent;
-    jmethodID interceptKeyBeforeQueueing;
-    jmethodID interceptMotionBeforeQueueingWhenScreenOff;
-    jmethodID interceptKeyBeforeDispatching;
-    jmethodID dispatchUnhandledKey;
-    jmethodID checkInjectEventsPermission;
-    jmethodID getVirtualKeyQuietTimeMillis;
-    jmethodID getExcludedDeviceNames;
-    jmethodID getKeyRepeatTimeout;
-    jmethodID getKeyRepeatDelay;
-    jmethodID getHoverTapTimeout;
-    jmethodID getHoverTapSlop;
-    jmethodID getDoubleTapTimeout;
-    jmethodID getLongPressTimeout;
-    jmethodID getPointerLayer;
-    jmethodID getPointerIcon;
-    jmethodID getKeyboardLayoutOverlay;
-    jmethodID getDeviceAlias;
-} gServiceClassInfo;
-
-static struct {
-    jclass clazz;
-} gInputDeviceClassInfo;
-
-static struct {
-    jclass clazz;
-} gKeyEventClassInfo;
-
-static struct {
-    jclass clazz;
-} gMotionEventClassInfo;
-
-
-// --- Global functions ---
-
-template<typename T>
-inline static T min(const T& a, const T& b) {
-    return a < b ? a : b;
-}
-
-template<typename T>
-inline static T max(const T& a, const T& b) {
-    return a > b ? a : b;
-}
-
-static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
-        const sp<InputApplicationHandle>& inputApplicationHandle) {
-    if (inputApplicationHandle == NULL) {
-        return NULL;
-    }
-    return static_cast<NativeInputApplicationHandle*>(inputApplicationHandle.get())->
-            getInputApplicationHandleObjLocalRef(env);
-}
-
-static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
-        const sp<InputWindowHandle>& inputWindowHandle) {
-    if (inputWindowHandle == NULL) {
-        return NULL;
-    }
-    return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
-            getInputWindowHandleObjLocalRef(env);
-}
-
-static void loadSystemIconAsSprite(JNIEnv* env, jobject contextObj, int32_t style,
-        SpriteIcon* outSpriteIcon) {
-    PointerIcon pointerIcon;
-    status_t status = android_view_PointerIcon_loadSystemIcon(env,
-            contextObj, style, &pointerIcon);
-    if (!status) {
-        pointerIcon.bitmap.copyTo(&outSpriteIcon->bitmap, SkBitmap::kARGB_8888_Config);
-        outSpriteIcon->hotSpotX = pointerIcon.hotSpotX;
-        outSpriteIcon->hotSpotY = pointerIcon.hotSpotY;
-    }
-}
-
-enum {
-    WM_ACTION_PASS_TO_USER = 1,
-    WM_ACTION_WAKE_UP = 2,
-    WM_ACTION_GO_TO_SLEEP = 4,
-};
-
-
-// --- NativeInputManager ---
-
-class NativeInputManager : public virtual RefBase,
-    public virtual InputReaderPolicyInterface,
-    public virtual InputDispatcherPolicyInterface,
-    public virtual PointerControllerPolicyInterface {
-protected:
-    virtual ~NativeInputManager();
-
-public:
-    NativeInputManager(jobject contextObj, jobject serviceObj, const sp<Looper>& looper);
-
-    inline sp<InputManager> getInputManager() const { return mInputManager; }
-
-    void dump(String8& dump);
-
-    void setDisplayViewport(bool external, const DisplayViewport& viewport);
-
-    status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
-            const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
-    status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
-
-    void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray);
-    void setFocusedApplication(JNIEnv* env, jobject applicationHandleObj);
-    void setInputDispatchMode(bool enabled, bool frozen);
-    void setSystemUiVisibility(int32_t visibility);
-    void setPointerSpeed(int32_t speed);
-    void setShowTouches(bool enabled);
-
-    /* --- InputReaderPolicyInterface implementation --- */
-
-    virtual void getReaderConfiguration(InputReaderConfiguration* outConfig);
-    virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId);
-    virtual void notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices);
-    virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const String8& inputDeviceDescriptor);
-    virtual String8 getDeviceAlias(const InputDeviceIdentifier& identifier);
-
-    /* --- InputDispatcherPolicyInterface implementation --- */
-
-    virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
-            uint32_t policyFlags);
-    virtual void notifyConfigurationChanged(nsecs_t when);
-    virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
-            const sp<InputWindowHandle>& inputWindowHandle,
-            const String8& reason);
-    virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
-    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
-    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
-    virtual bool isKeyRepeatEnabled();
-    virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
-    virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
-    virtual nsecs_t interceptKeyBeforeDispatching(
-            const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags);
-    virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
-            const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
-    virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
-    virtual bool checkInjectEventsPermissionNonReentrant(
-            int32_t injectorPid, int32_t injectorUid);
-
-    /* --- PointerControllerPolicyInterface implementation --- */
-
-    virtual void loadPointerResources(PointerResources* outResources);
-
-private:
-    sp<InputManager> mInputManager;
-
-    jobject mContextObj;
-    jobject mServiceObj;
-    sp<Looper> mLooper;
-
-    Mutex mLock;
-    struct Locked {
-        // Display size information.
-        DisplayViewport internalViewport;
-        DisplayViewport externalViewport;
-
-        // System UI visibility.
-        int32_t systemUiVisibility;
-
-        // Pointer speed.
-        int32_t pointerSpeed;
-
-        // True if pointer gestures are enabled.
-        bool pointerGesturesEnabled;
-
-        // Show touches feature enable/disable.
-        bool showTouches;
-
-        // Sprite controller singleton, created on first use.
-        sp<SpriteController> spriteController;
-
-        // Pointer controller singleton, created and destroyed as needed.
-        wp<PointerController> pointerController;
-    } mLocked;
-
-    void updateInactivityTimeoutLocked(const sp<PointerController>& controller);
-    void handleInterceptActions(jint wmActions, nsecs_t when, uint32_t& policyFlags);
-    void ensureSpriteControllerLocked();
-
-    // Power manager interactions.
-    bool isScreenOn();
-    bool isScreenBright();
-
-    static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName);
-
-    static inline JNIEnv* jniEnv() {
-        return AndroidRuntime::getJNIEnv();
-    }
-};
-
-
-
-NativeInputManager::NativeInputManager(jobject contextObj,
-        jobject serviceObj, const sp<Looper>& looper) :
-        mLooper(looper) {
-    JNIEnv* env = jniEnv();
-
-    mContextObj = env->NewGlobalRef(contextObj);
-    mServiceObj = env->NewGlobalRef(serviceObj);
-
-    {
-        AutoMutex _l(mLock);
-        mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
-        mLocked.pointerSpeed = 0;
-        mLocked.pointerGesturesEnabled = true;
-        mLocked.showTouches = false;
-    }
-
-    sp<EventHub> eventHub = new EventHub();
-    mInputManager = new InputManager(eventHub, this, this);
-}
-
-NativeInputManager::~NativeInputManager() {
-    JNIEnv* env = jniEnv();
-
-    env->DeleteGlobalRef(mContextObj);
-    env->DeleteGlobalRef(mServiceObj);
-}
-
-void NativeInputManager::dump(String8& dump) {
-    mInputManager->getReader()->dump(dump);
-    dump.append("\n");
-
-    mInputManager->getDispatcher()->dump(dump);
-    dump.append("\n");
-}
-
-bool NativeInputManager::checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
-    if (env->ExceptionCheck()) {
-        ALOGE("An exception was thrown by callback '%s'.", methodName);
-        LOGE_EX(env);
-        env->ExceptionClear();
-        return true;
-    }
-    return false;
-}
-
-void NativeInputManager::setDisplayViewport(bool external, const DisplayViewport& viewport) {
-    bool changed = false;
-    {
-        AutoMutex _l(mLock);
-
-        DisplayViewport& v = external ? mLocked.externalViewport : mLocked.internalViewport;
-        if (v != viewport) {
-            changed = true;
-            v = viewport;
-
-            if (!external) {
-                sp<PointerController> controller = mLocked.pointerController.promote();
-                if (controller != NULL) {
-                    controller->setDisplayViewport(
-                            viewport.logicalRight - viewport.logicalLeft,
-                            viewport.logicalBottom - viewport.logicalTop,
-                            viewport.orientation);
-                }
-            }
-        }
-    }
-
-    if (changed) {
-        mInputManager->getReader()->requestRefreshConfiguration(
-                InputReaderConfiguration::CHANGE_DISPLAY_INFO);
-    }
-}
-
-status_t NativeInputManager::registerInputChannel(JNIEnv* env,
-        const sp<InputChannel>& inputChannel,
-        const sp<InputWindowHandle>& inputWindowHandle, bool monitor) {
-    return mInputManager->getDispatcher()->registerInputChannel(
-            inputChannel, inputWindowHandle, monitor);
-}
-
-status_t NativeInputManager::unregisterInputChannel(JNIEnv* env,
-        const sp<InputChannel>& inputChannel) {
-    return mInputManager->getDispatcher()->unregisterInputChannel(inputChannel);
-}
-
-void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outConfig) {
-    JNIEnv* env = jniEnv();
-
-    jint virtualKeyQuietTime = env->CallIntMethod(mServiceObj,
-            gServiceClassInfo.getVirtualKeyQuietTimeMillis);
-    if (!checkAndClearExceptionFromCallback(env, "getVirtualKeyQuietTimeMillis")) {
-        outConfig->virtualKeyQuietTime = milliseconds_to_nanoseconds(virtualKeyQuietTime);
-    }
-
-    outConfig->excludedDeviceNames.clear();
-    jobjectArray excludedDeviceNames = jobjectArray(env->CallObjectMethod(mServiceObj,
-            gServiceClassInfo.getExcludedDeviceNames));
-    if (!checkAndClearExceptionFromCallback(env, "getExcludedDeviceNames") && excludedDeviceNames) {
-        jsize length = env->GetArrayLength(excludedDeviceNames);
-        for (jsize i = 0; i < length; i++) {
-            jstring item = jstring(env->GetObjectArrayElement(excludedDeviceNames, i));
-            const char* deviceNameChars = env->GetStringUTFChars(item, NULL);
-            outConfig->excludedDeviceNames.add(String8(deviceNameChars));
-            env->ReleaseStringUTFChars(item, deviceNameChars);
-            env->DeleteLocalRef(item);
-        }
-        env->DeleteLocalRef(excludedDeviceNames);
-    }
-
-    jint hoverTapTimeout = env->CallIntMethod(mServiceObj,
-            gServiceClassInfo.getHoverTapTimeout);
-    if (!checkAndClearExceptionFromCallback(env, "getHoverTapTimeout")) {
-        jint doubleTapTimeout = env->CallIntMethod(mServiceObj,
-                gServiceClassInfo.getDoubleTapTimeout);
-        if (!checkAndClearExceptionFromCallback(env, "getDoubleTapTimeout")) {
-            jint longPressTimeout = env->CallIntMethod(mServiceObj,
-                    gServiceClassInfo.getLongPressTimeout);
-            if (!checkAndClearExceptionFromCallback(env, "getLongPressTimeout")) {
-                outConfig->pointerGestureTapInterval = milliseconds_to_nanoseconds(hoverTapTimeout);
-
-                // We must ensure that the tap-drag interval is significantly shorter than
-                // the long-press timeout because the tap is held down for the entire duration
-                // of the double-tap timeout.
-                jint tapDragInterval = max(min(longPressTimeout - 100,
-                        doubleTapTimeout), hoverTapTimeout);
-                outConfig->pointerGestureTapDragInterval =
-                        milliseconds_to_nanoseconds(tapDragInterval);
-            }
-        }
-    }
-
-    jint hoverTapSlop = env->CallIntMethod(mServiceObj,
-            gServiceClassInfo.getHoverTapSlop);
-    if (!checkAndClearExceptionFromCallback(env, "getHoverTapSlop")) {
-        outConfig->pointerGestureTapSlop = hoverTapSlop;
-    }
-
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed
-                * POINTER_SPEED_EXPONENT);
-        outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled;
-
-        outConfig->showTouches = mLocked.showTouches;
-
-        outConfig->setDisplayInfo(false /*external*/, mLocked.internalViewport);
-        outConfig->setDisplayInfo(true /*external*/, mLocked.externalViewport);
-    } // release lock
-}
-
-sp<PointerControllerInterface> NativeInputManager::obtainPointerController(int32_t deviceId) {
-    AutoMutex _l(mLock);
-
-    sp<PointerController> controller = mLocked.pointerController.promote();
-    if (controller == NULL) {
-        ensureSpriteControllerLocked();
-
-        controller = new PointerController(this, mLooper, mLocked.spriteController);
-        mLocked.pointerController = controller;
-
-        DisplayViewport& v = mLocked.internalViewport;
-        controller->setDisplayViewport(
-                v.logicalRight - v.logicalLeft,
-                v.logicalBottom - v.logicalTop,
-                v.orientation);
-
-        JNIEnv* env = jniEnv();
-        jobject pointerIconObj = env->CallObjectMethod(mServiceObj,
-                gServiceClassInfo.getPointerIcon);
-        if (!checkAndClearExceptionFromCallback(env, "getPointerIcon")) {
-            PointerIcon pointerIcon;
-            status_t status = android_view_PointerIcon_load(env, pointerIconObj,
-                    mContextObj, &pointerIcon);
-            if (!status && !pointerIcon.isNullIcon()) {
-                controller->setPointerIcon(SpriteIcon(pointerIcon.bitmap,
-                        pointerIcon.hotSpotX, pointerIcon.hotSpotY));
-            } else {
-                controller->setPointerIcon(SpriteIcon());
-            }
-            env->DeleteLocalRef(pointerIconObj);
-        }
-
-        updateInactivityTimeoutLocked(controller);
-    }
-    return controller;
-}
-
-void NativeInputManager::ensureSpriteControllerLocked() {
-    if (mLocked.spriteController == NULL) {
-        JNIEnv* env = jniEnv();
-        jint layer = env->CallIntMethod(mServiceObj, gServiceClassInfo.getPointerLayer);
-        if (checkAndClearExceptionFromCallback(env, "getPointerLayer")) {
-            layer = -1;
-        }
-        mLocked.spriteController = new SpriteController(mLooper, layer);
-    }
-}
-
-void NativeInputManager::notifyInputDevicesChanged(const Vector<InputDeviceInfo>& inputDevices) {
-    JNIEnv* env = jniEnv();
-
-    size_t count = inputDevices.size();
-    jobjectArray inputDevicesObjArray = env->NewObjectArray(
-            count, gInputDeviceClassInfo.clazz, NULL);
-    if (inputDevicesObjArray) {
-        bool error = false;
-        for (size_t i = 0; i < count; i++) {
-            jobject inputDeviceObj = android_view_InputDevice_create(env, inputDevices.itemAt(i));
-            if (!inputDeviceObj) {
-                error = true;
-                break;
-            }
-
-            env->SetObjectArrayElement(inputDevicesObjArray, i, inputDeviceObj);
-            env->DeleteLocalRef(inputDeviceObj);
-        }
-
-        if (!error) {
-            env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputDevicesChanged,
-                    inputDevicesObjArray);
-        }
-
-        env->DeleteLocalRef(inputDevicesObjArray);
-    }
-
-    checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged");
-}
-
-sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay(
-        const String8& inputDeviceDescriptor) {
-    JNIEnv* env = jniEnv();
-
-    sp<KeyCharacterMap> result;
-    ScopedLocalRef<jstring> descriptorObj(env, env->NewStringUTF(inputDeviceDescriptor.string()));
-    ScopedLocalRef<jobjectArray> arrayObj(env, jobjectArray(env->CallObjectMethod(mServiceObj,
-                gServiceClassInfo.getKeyboardLayoutOverlay, descriptorObj.get())));
-    if (arrayObj.get()) {
-        ScopedLocalRef<jstring> filenameObj(env,
-                jstring(env->GetObjectArrayElement(arrayObj.get(), 0)));
-        ScopedLocalRef<jstring> contentsObj(env,
-                jstring(env->GetObjectArrayElement(arrayObj.get(), 1)));
-        ScopedUtfChars filenameChars(env, filenameObj.get());
-        ScopedUtfChars contentsChars(env, contentsObj.get());
-
-        KeyCharacterMap::loadContents(String8(filenameChars.c_str()),
-                String8(contentsChars.c_str()), KeyCharacterMap::FORMAT_OVERLAY, &result);
-    }
-    checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay");
-    return result;
-}
-
-String8 NativeInputManager::getDeviceAlias(const InputDeviceIdentifier& identifier) {
-    JNIEnv* env = jniEnv();
-
-    ScopedLocalRef<jstring> uniqueIdObj(env, env->NewStringUTF(identifier.uniqueId.string()));
-    ScopedLocalRef<jstring> aliasObj(env, jstring(env->CallObjectMethod(mServiceObj,
-            gServiceClassInfo.getDeviceAlias, uniqueIdObj.get())));
-    String8 result;
-    if (aliasObj.get()) {
-        ScopedUtfChars aliasChars(env, aliasObj.get());
-        result.setTo(aliasChars.c_str());
-    }
-    checkAndClearExceptionFromCallback(env, "getDeviceAlias");
-    return result;
-}
-
-void NativeInputManager::notifySwitch(nsecs_t when,
-        uint32_t switchValues, uint32_t switchMask, uint32_t policyFlags) {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-    ALOGD("notifySwitch - when=%lld, switchValues=0x%08x, switchMask=0x%08x, policyFlags=0x%x",
-            when, switchValues, switchMask, policyFlags);
-#endif
-
-    JNIEnv* env = jniEnv();
-
-    env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifySwitch,
-            when, switchValues, switchMask);
-    checkAndClearExceptionFromCallback(env, "notifySwitch");
-}
-
-void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-    ALOGD("notifyConfigurationChanged - when=%lld", when);
-#endif
-
-    JNIEnv* env = jniEnv();
-
-    env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyConfigurationChanged, when);
-    checkAndClearExceptionFromCallback(env, "notifyConfigurationChanged");
-}
-
-nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
-        const sp<InputWindowHandle>& inputWindowHandle, const String8& reason) {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-    ALOGD("notifyANR");
-#endif
-
-    JNIEnv* env = jniEnv();
-
-    jobject inputApplicationHandleObj =
-            getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
-    jobject inputWindowHandleObj =
-            getInputWindowHandleObjLocalRef(env, inputWindowHandle);
-    jstring reasonObj = env->NewStringUTF(reason.string());
-
-    jlong newTimeout = env->CallLongMethod(mServiceObj,
-                gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
-                reasonObj);
-    if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
-        newTimeout = 0; // abort dispatch
-    } else {
-        assert(newTimeout >= 0);
-    }
-
-    env->DeleteLocalRef(reasonObj);
-    env->DeleteLocalRef(inputWindowHandleObj);
-    env->DeleteLocalRef(inputApplicationHandleObj);
-    return newTimeout;
-}
-
-void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-    ALOGD("notifyInputChannelBroken");
-#endif
-
-    JNIEnv* env = jniEnv();
-
-    jobject inputWindowHandleObj =
-            getInputWindowHandleObjLocalRef(env, inputWindowHandle);
-    if (inputWindowHandleObj) {
-        env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
-                inputWindowHandleObj);
-        checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
-
-        env->DeleteLocalRef(inputWindowHandleObj);
-    }
-}
-
-void NativeInputManager::getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) {
-    JNIEnv* env = jniEnv();
-
-    jint keyRepeatTimeout = env->CallIntMethod(mServiceObj,
-            gServiceClassInfo.getKeyRepeatTimeout);
-    if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatTimeout")) {
-        outConfig->keyRepeatTimeout = milliseconds_to_nanoseconds(keyRepeatTimeout);
-    }
-
-    jint keyRepeatDelay = env->CallIntMethod(mServiceObj,
-            gServiceClassInfo.getKeyRepeatDelay);
-    if (!checkAndClearExceptionFromCallback(env, "getKeyRepeatDelay")) {
-        outConfig->keyRepeatDelay = milliseconds_to_nanoseconds(keyRepeatDelay);
-    }
-}
-
-bool NativeInputManager::isKeyRepeatEnabled() {
-    // Only enable automatic key repeating when the screen is on.
-    return isScreenOn();
-}
-
-void NativeInputManager::setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray) {
-    Vector<sp<InputWindowHandle> > windowHandles;
-
-    if (windowHandleObjArray) {
-        jsize length = env->GetArrayLength(windowHandleObjArray);
-        for (jsize i = 0; i < length; i++) {
-            jobject windowHandleObj = env->GetObjectArrayElement(windowHandleObjArray, i);
-            if (! windowHandleObj) {
-                break; // found null element indicating end of used portion of the array
-            }
-
-            sp<InputWindowHandle> windowHandle =
-                    android_server_InputWindowHandle_getHandle(env, windowHandleObj);
-            if (windowHandle != NULL) {
-                windowHandles.push(windowHandle);
-            }
-            env->DeleteLocalRef(windowHandleObj);
-        }
-    }
-
-    mInputManager->getDispatcher()->setInputWindows(windowHandles);
-
-    // Do this after the dispatcher has updated the window handle state.
-    bool newPointerGesturesEnabled = true;
-    size_t numWindows = windowHandles.size();
-    for (size_t i = 0; i < numWindows; i++) {
-        const sp<InputWindowHandle>& windowHandle = windowHandles.itemAt(i);
-        const InputWindowInfo* windowInfo = windowHandle->getInfo();
-        if (windowInfo && windowInfo->hasFocus && (windowInfo->inputFeatures
-                & InputWindowInfo::INPUT_FEATURE_DISABLE_TOUCH_PAD_GESTURES)) {
-            newPointerGesturesEnabled = false;
-        }
-    }
-
-    uint32_t changes = 0;
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (mLocked.pointerGesturesEnabled != newPointerGesturesEnabled) {
-            mLocked.pointerGesturesEnabled = newPointerGesturesEnabled;
-            changes |= InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT;
-        }
-    } // release lock
-
-    if (changes) {
-        mInputManager->getReader()->requestRefreshConfiguration(changes);
-    }
-}
-
-void NativeInputManager::setFocusedApplication(JNIEnv* env, jobject applicationHandleObj) {
-    sp<InputApplicationHandle> applicationHandle =
-            android_server_InputApplicationHandle_getHandle(env, applicationHandleObj);
-    mInputManager->getDispatcher()->setFocusedApplication(applicationHandle);
-}
-
-void NativeInputManager::setInputDispatchMode(bool enabled, bool frozen) {
-    mInputManager->getDispatcher()->setInputDispatchMode(enabled, frozen);
-}
-
-void NativeInputManager::setSystemUiVisibility(int32_t visibility) {
-    AutoMutex _l(mLock);
-
-    if (mLocked.systemUiVisibility != visibility) {
-        mLocked.systemUiVisibility = visibility;
-
-        sp<PointerController> controller = mLocked.pointerController.promote();
-        if (controller != NULL) {
-            updateInactivityTimeoutLocked(controller);
-        }
-    }
-}
-
-void NativeInputManager::updateInactivityTimeoutLocked(const sp<PointerController>& controller) {
-    bool lightsOut = mLocked.systemUiVisibility & ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN;
-    controller->setInactivityTimeout(lightsOut
-            ? PointerController::INACTIVITY_TIMEOUT_SHORT
-            : PointerController::INACTIVITY_TIMEOUT_NORMAL);
-}
-
-void NativeInputManager::setPointerSpeed(int32_t speed) {
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (mLocked.pointerSpeed == speed) {
-            return;
-        }
-
-        ALOGI("Setting pointer speed to %d.", speed);
-        mLocked.pointerSpeed = speed;
-    } // release lock
-
-    mInputManager->getReader()->requestRefreshConfiguration(
-            InputReaderConfiguration::CHANGE_POINTER_SPEED);
-}
-
-void NativeInputManager::setShowTouches(bool enabled) {
-    { // acquire lock
-        AutoMutex _l(mLock);
-
-        if (mLocked.showTouches == enabled) {
-            return;
-        }
-
-        ALOGI("Setting show touches feature to %s.", enabled ? "enabled" : "disabled");
-        mLocked.showTouches = enabled;
-    } // release lock
-
-    mInputManager->getReader()->requestRefreshConfiguration(
-            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
-}
-
-bool NativeInputManager::isScreenOn() {
-    return android_server_PowerManagerService_isScreenOn();
-}
-
-bool NativeInputManager::isScreenBright() {
-    return android_server_PowerManagerService_isScreenBright();
-}
-
-bool NativeInputManager::filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
-    jobject inputEventObj;
-
-    JNIEnv* env = jniEnv();
-    switch (inputEvent->getType()) {
-    case AINPUT_EVENT_TYPE_KEY:
-        inputEventObj = android_view_KeyEvent_fromNative(env,
-                static_cast<const KeyEvent*>(inputEvent));
-        break;
-    case AINPUT_EVENT_TYPE_MOTION:
-        inputEventObj = android_view_MotionEvent_obtainAsCopy(env,
-                static_cast<const MotionEvent*>(inputEvent));
-        break;
-    default:
-        return true; // dispatch the event normally
-    }
-
-    if (!inputEventObj) {
-        ALOGE("Failed to obtain input event object for filterInputEvent.");
-        return true; // dispatch the event normally
-    }
-
-    // The callee is responsible for recycling the event.
-    jboolean pass = env->CallBooleanMethod(mServiceObj, gServiceClassInfo.filterInputEvent,
-            inputEventObj, policyFlags);
-    if (checkAndClearExceptionFromCallback(env, "filterInputEvent")) {
-        pass = true;
-    }
-    env->DeleteLocalRef(inputEventObj);
-    return pass;
-}
-
-void NativeInputManager::interceptKeyBeforeQueueing(const KeyEvent* keyEvent,
-        uint32_t& policyFlags) {
-    // Policy:
-    // - Ignore untrusted events and pass them along.
-    // - Ask the window manager what to do with normal events and trusted injected events.
-    // - For normal events wake and brighten the screen if currently off or dim.
-    if ((policyFlags & POLICY_FLAG_TRUSTED)) {
-        nsecs_t when = keyEvent->getEventTime();
-        bool isScreenOn = this->isScreenOn();
-        bool isScreenBright = this->isScreenBright();
-
-        JNIEnv* env = jniEnv();
-        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
-        jint wmActions;
-        if (keyEventObj) {
-            wmActions = env->CallIntMethod(mServiceObj,
-                    gServiceClassInfo.interceptKeyBeforeQueueing,
-                    keyEventObj, policyFlags, isScreenOn);
-            if (checkAndClearExceptionFromCallback(env, "interceptKeyBeforeQueueing")) {
-                wmActions = 0;
-            }
-            android_view_KeyEvent_recycle(env, keyEventObj);
-            env->DeleteLocalRef(keyEventObj);
-        } else {
-            ALOGE("Failed to obtain key event object for interceptKeyBeforeQueueing.");
-            wmActions = 0;
-        }
-
-        if (!(policyFlags & POLICY_FLAG_INJECTED)) {
-            if (!isScreenOn) {
-                policyFlags |= POLICY_FLAG_WOKE_HERE;
-            }
-
-            if (!isScreenBright) {
-                policyFlags |= POLICY_FLAG_BRIGHT_HERE;
-            }
-        }
-
-        handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
-    } else {
-        policyFlags |= POLICY_FLAG_PASS_TO_USER;
-    }
-}
-
-void NativeInputManager::interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags) {
-    // Policy:
-    // - Ignore untrusted events and pass them along.
-    // - No special filtering for injected events required at this time.
-    // - Filter normal events based on screen state.
-    // - For normal events brighten (but do not wake) the screen if currently dim.
-    if ((policyFlags & POLICY_FLAG_TRUSTED) && !(policyFlags & POLICY_FLAG_INJECTED)) {
-        if (isScreenOn()) {
-            policyFlags |= POLICY_FLAG_PASS_TO_USER;
-
-            if (!isScreenBright()) {
-                policyFlags |= POLICY_FLAG_BRIGHT_HERE;
-            }
-        } else {
-            JNIEnv* env = jniEnv();
-            jint wmActions = env->CallIntMethod(mServiceObj,
-                        gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
-                        policyFlags);
-            if (checkAndClearExceptionFromCallback(env,
-                    "interceptMotionBeforeQueueingWhenScreenOff")) {
-                wmActions = 0;
-            }
-
-            policyFlags |= POLICY_FLAG_WOKE_HERE | POLICY_FLAG_BRIGHT_HERE;
-            handleInterceptActions(wmActions, when, /*byref*/ policyFlags);
-        }
-    } else {
-        policyFlags |= POLICY_FLAG_PASS_TO_USER;
-    }
-}
-
-void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
-        uint32_t& policyFlags) {
-    if (wmActions & WM_ACTION_GO_TO_SLEEP) {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-        ALOGD("handleInterceptActions: Going to sleep.");
-#endif
-        android_server_PowerManagerService_goToSleep(when);
-    }
-
-    if (wmActions & WM_ACTION_WAKE_UP) {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-        ALOGD("handleInterceptActions: Waking up.");
-#endif
-        android_server_PowerManagerService_wakeUp(when);
-    }
-
-    if (wmActions & WM_ACTION_PASS_TO_USER) {
-        policyFlags |= POLICY_FLAG_PASS_TO_USER;
-    } else {
-#if DEBUG_INPUT_DISPATCHER_POLICY
-        ALOGD("handleInterceptActions: Not passing key to user.");
-#endif
-    }
-}
-
-nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
-        const sp<InputWindowHandle>& inputWindowHandle,
-        const KeyEvent* keyEvent, uint32_t policyFlags) {
-    // Policy:
-    // - Ignore untrusted events and pass them along.
-    // - Filter normal events and trusted injected events through the window manager policy to
-    //   handle the HOME key and the like.
-    nsecs_t result = 0;
-    if (policyFlags & POLICY_FLAG_TRUSTED) {
-        JNIEnv* env = jniEnv();
-
-        // Note: inputWindowHandle may be null.
-        jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
-        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
-        if (keyEventObj) {
-            jlong delayMillis = env->CallLongMethod(mServiceObj,
-                    gServiceClassInfo.interceptKeyBeforeDispatching,
-                    inputWindowHandleObj, keyEventObj, policyFlags);
-            bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
-            android_view_KeyEvent_recycle(env, keyEventObj);
-            env->DeleteLocalRef(keyEventObj);
-            if (!error) {
-                if (delayMillis < 0) {
-                    result = -1;
-                } else if (delayMillis > 0) {
-                    result = milliseconds_to_nanoseconds(delayMillis);
-                }
-            }
-        } else {
-            ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
-        }
-        env->DeleteLocalRef(inputWindowHandleObj);
-    }
-    return result;
-}
-
-bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
-        const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
-    // Policy:
-    // - Ignore untrusted events and do not perform default handling.
-    bool result = false;
-    if (policyFlags & POLICY_FLAG_TRUSTED) {
-        JNIEnv* env = jniEnv();
-
-        // Note: inputWindowHandle may be null.
-        jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
-        jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
-        if (keyEventObj) {
-            jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
-                    gServiceClassInfo.dispatchUnhandledKey,
-                    inputWindowHandleObj, keyEventObj, policyFlags);
-            if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
-                fallbackKeyEventObj = NULL;
-            }
-            android_view_KeyEvent_recycle(env, keyEventObj);
-            env->DeleteLocalRef(keyEventObj);
-
-            if (fallbackKeyEventObj) {
-                // Note: outFallbackKeyEvent may be the same object as keyEvent.
-                if (!android_view_KeyEvent_toNative(env, fallbackKeyEventObj,
-                        outFallbackKeyEvent)) {
-                    result = true;
-                }
-                android_view_KeyEvent_recycle(env, fallbackKeyEventObj);
-                env->DeleteLocalRef(fallbackKeyEventObj);
-            }
-        } else {
-            ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
-        }
-        env->DeleteLocalRef(inputWindowHandleObj);
-    }
-    return result;
-}
-
-void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType) {
-    android_server_PowerManagerService_userActivity(eventTime, eventType);
-}
-
-
-bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
-        int32_t injectorPid, int32_t injectorUid) {
-    JNIEnv* env = jniEnv();
-    jboolean result = env->CallBooleanMethod(mServiceObj,
-            gServiceClassInfo.checkInjectEventsPermission, injectorPid, injectorUid);
-    if (checkAndClearExceptionFromCallback(env, "checkInjectEventsPermission")) {
-        result = false;
-    }
-    return result;
-}
-
-void NativeInputManager::loadPointerResources(PointerResources* outResources) {
-    JNIEnv* env = jniEnv();
-
-    loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_HOVER,
-            &outResources->spotHover);
-    loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_TOUCH,
-            &outResources->spotTouch);
-    loadSystemIconAsSprite(env, mContextObj, POINTER_ICON_STYLE_SPOT_ANCHOR,
-            &outResources->spotAnchor);
-}
-
-
-// ----------------------------------------------------------------------------
-
-static jint nativeInit(JNIEnv* env, jclass clazz,
-        jobject serviceObj, jobject contextObj, jobject messageQueueObj) {
-    sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, messageQueueObj);
-    if (messageQueue == NULL) {
-        jniThrowRuntimeException(env, "MessageQueue is not initialized.");
-        return 0;
-    }
-
-    NativeInputManager* im = new NativeInputManager(contextObj, serviceObj,
-            messageQueue->getLooper());
-    im->incStrong(0);
-    return reinterpret_cast<jint>(im);
-}
-
-static void nativeStart(JNIEnv* env, jclass clazz, jint ptr) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    status_t result = im->getInputManager()->start();
-    if (result) {
-        jniThrowRuntimeException(env, "Input manager could not be started.");
-    }
-}
-
-static void nativeSetDisplayViewport(JNIEnv* env, jclass clazz, jint ptr, jboolean external,
-        jint displayId, jint orientation,
-        jint logicalLeft, jint logicalTop, jint logicalRight, jint logicalBottom,
-        jint physicalLeft, jint physicalTop, jint physicalRight, jint physicalBottom,
-        jint deviceWidth, jint deviceHeight) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    DisplayViewport v;
-    v.displayId = displayId;
-    v.orientation = orientation;
-    v.logicalLeft = logicalLeft;
-    v.logicalTop = logicalTop;
-    v.logicalRight = logicalRight;
-    v.logicalBottom = logicalBottom;
-    v.physicalLeft = physicalLeft;
-    v.physicalTop = physicalTop;
-    v.physicalRight = physicalRight;
-    v.physicalBottom = physicalBottom;
-    v.deviceWidth = deviceWidth;
-    v.deviceHeight = deviceHeight;
-    im->setDisplayViewport(external, v);
-}
-
-static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
-        jint ptr, jint deviceId, jint sourceMask, jint scanCode) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    return im->getInputManager()->getReader()->getScanCodeState(
-            deviceId, uint32_t(sourceMask), scanCode);
-}
-
-static jint nativeGetKeyCodeState(JNIEnv* env, jclass clazz,
-        jint ptr, jint deviceId, jint sourceMask, jint keyCode) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    return im->getInputManager()->getReader()->getKeyCodeState(
-            deviceId, uint32_t(sourceMask), keyCode);
-}
-
-static jint nativeGetSwitchState(JNIEnv* env, jclass clazz,
-        jint ptr, jint deviceId, jint sourceMask, jint sw) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    return im->getInputManager()->getReader()->getSwitchState(
-            deviceId, uint32_t(sourceMask), sw);
-}
-
-static jboolean nativeHasKeys(JNIEnv* env, jclass clazz,
-        jint ptr, jint deviceId, jint sourceMask, jintArray keyCodes, jbooleanArray outFlags) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    int32_t* codes = env->GetIntArrayElements(keyCodes, NULL);
-    uint8_t* flags = env->GetBooleanArrayElements(outFlags, NULL);
-    jsize numCodes = env->GetArrayLength(keyCodes);
-    jboolean result;
-    if (numCodes == env->GetArrayLength(keyCodes)) {
-        result = im->getInputManager()->getReader()->hasKeys(
-                deviceId, uint32_t(sourceMask), numCodes, codes, flags);
-    } else {
-        result = JNI_FALSE;
-    }
-
-    env->ReleaseBooleanArrayElements(outFlags, flags, 0);
-    env->ReleaseIntArrayElements(keyCodes, codes, 0);
-    return result;
-}
-
-static void throwInputChannelNotInitialized(JNIEnv* env) {
-    jniThrowException(env, "java/lang/IllegalStateException",
-             "inputChannel is not initialized");
-}
-
-static void handleInputChannelDisposed(JNIEnv* env,
-        jobject inputChannelObj, const sp<InputChannel>& inputChannel, void* data) {
-    NativeInputManager* im = static_cast<NativeInputManager*>(data);
-
-    ALOGW("Input channel object '%s' was disposed without first being unregistered with "
-            "the input manager!", inputChannel->getName().string());
-    im->unregisterInputChannel(env, inputChannel);
-}
-
-static void nativeRegisterInputChannel(JNIEnv* env, jclass clazz,
-        jint ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jboolean monitor) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
-            inputChannelObj);
-    if (inputChannel == NULL) {
-        throwInputChannelNotInitialized(env);
-        return;
-    }
-
-    sp<InputWindowHandle> inputWindowHandle =
-            android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
-
-    status_t status = im->registerInputChannel(
-            env, inputChannel, inputWindowHandle, monitor);
-    if (status) {
-        String8 message;
-        message.appendFormat("Failed to register input channel.  status=%d", status);
-        jniThrowRuntimeException(env, message.string());
-        return;
-    }
-
-    if (! monitor) {
-        android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
-                handleInputChannelDisposed, im);
-    }
-}
-
-static void nativeUnregisterInputChannel(JNIEnv* env, jclass clazz,
-        jint ptr, jobject inputChannelObj) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
-            inputChannelObj);
-    if (inputChannel == NULL) {
-        throwInputChannelNotInitialized(env);
-        return;
-    }
-
-    android_view_InputChannel_setDisposeCallback(env, inputChannelObj, NULL, NULL);
-
-    status_t status = im->unregisterInputChannel(env, inputChannel);
-    if (status && status != BAD_VALUE) { // ignore already unregistered channel
-        String8 message;
-        message.appendFormat("Failed to unregister input channel.  status=%d", status);
-        jniThrowRuntimeException(env, message.string());
-    }
-}
-
-static void nativeSetInputFilterEnabled(JNIEnv* env, jclass clazz,
-        jint ptr, jboolean enabled) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
-}
-
-static jint nativeInjectInputEvent(JNIEnv* env, jclass clazz,
-        jint ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
-        jint syncMode, jint timeoutMillis, jint policyFlags) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    if (env->IsInstanceOf(inputEventObj, gKeyEventClassInfo.clazz)) {
-        KeyEvent keyEvent;
-        status_t status = android_view_KeyEvent_toNative(env, inputEventObj, & keyEvent);
-        if (status) {
-            jniThrowRuntimeException(env, "Could not read contents of KeyEvent object.");
-            return INPUT_EVENT_INJECTION_FAILED;
-        }
-
-        return im->getInputManager()->getDispatcher()->injectInputEvent(
-                & keyEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
-                uint32_t(policyFlags));
-    } else if (env->IsInstanceOf(inputEventObj, gMotionEventClassInfo.clazz)) {
-        const MotionEvent* motionEvent = android_view_MotionEvent_getNativePtr(env, inputEventObj);
-        if (!motionEvent) {
-            jniThrowRuntimeException(env, "Could not read contents of MotionEvent object.");
-            return INPUT_EVENT_INJECTION_FAILED;
-        }
-
-        return im->getInputManager()->getDispatcher()->injectInputEvent(
-                motionEvent, injectorPid, injectorUid, syncMode, timeoutMillis,
-                uint32_t(policyFlags));
-    } else {
-        jniThrowRuntimeException(env, "Invalid input event type.");
-        return INPUT_EVENT_INJECTION_FAILED;
-    }
-}
-
-static void nativeSetInputWindows(JNIEnv* env, jclass clazz,
-        jint ptr, jobjectArray windowHandleObjArray) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->setInputWindows(env, windowHandleObjArray);
-}
-
-static void nativeSetFocusedApplication(JNIEnv* env, jclass clazz,
-        jint ptr, jobject applicationHandleObj) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->setFocusedApplication(env, applicationHandleObj);
-}
-
-static void nativeSetInputDispatchMode(JNIEnv* env,
-        jclass clazz, jint ptr, jboolean enabled, jboolean frozen) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->setInputDispatchMode(enabled, frozen);
-}
-
-static void nativeSetSystemUiVisibility(JNIEnv* env,
-        jclass clazz, jint ptr, jint visibility) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->setSystemUiVisibility(visibility);
-}
-
-static jboolean nativeTransferTouchFocus(JNIEnv* env,
-        jclass clazz, jint ptr, jobject fromChannelObj, jobject toChannelObj) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    sp<InputChannel> fromChannel =
-            android_view_InputChannel_getInputChannel(env, fromChannelObj);
-    sp<InputChannel> toChannel =
-            android_view_InputChannel_getInputChannel(env, toChannelObj);
-
-    if (fromChannel == NULL || toChannel == NULL) {
-        return false;
-    }
-
-    return im->getInputManager()->getDispatcher()->
-            transferTouchFocus(fromChannel, toChannel);
-}
-
-static void nativeSetPointerSpeed(JNIEnv* env,
-        jclass clazz, jint ptr, jint speed) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->setPointerSpeed(speed);
-}
-
-static void nativeSetShowTouches(JNIEnv* env,
-        jclass clazz, jint ptr, jboolean enabled) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->setShowTouches(enabled);
-}
-
-static void nativeVibrate(JNIEnv* env,
-        jclass clazz, jint ptr, jint deviceId, jlongArray patternObj,
-        jint repeat, jint token) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    size_t patternSize = env->GetArrayLength(patternObj);
-    if (patternSize > MAX_VIBRATE_PATTERN_SIZE) {
-        ALOGI("Skipped requested vibration because the pattern size is %d "
-                "which is more than the maximum supported size of %d.",
-                patternSize, MAX_VIBRATE_PATTERN_SIZE);
-        return; // limit to reasonable size
-    }
-
-    jlong* patternMillis = static_cast<jlong*>(env->GetPrimitiveArrayCritical(
-            patternObj, NULL));
-    nsecs_t pattern[patternSize];
-    for (size_t i = 0; i < patternSize; i++) {
-        pattern[i] = max(jlong(0), min(patternMillis[i],
-                MAX_VIBRATE_PATTERN_DELAY_NSECS / 1000000LL)) * 1000000LL;
-    }
-    env->ReleasePrimitiveArrayCritical(patternObj, patternMillis, JNI_ABORT);
-
-    im->getInputManager()->getReader()->vibrate(deviceId, pattern, patternSize, repeat, token);
-}
-
-static void nativeCancelVibrate(JNIEnv* env,
-        jclass clazz, jint ptr, jint deviceId, jint token) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->getInputManager()->getReader()->cancelVibrate(deviceId, token);
-}
-
-static void nativeReloadKeyboardLayouts(JNIEnv* env,
-        jclass clazz, jint ptr) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->getInputManager()->getReader()->requestRefreshConfiguration(
-            InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS);
-}
-
-static void nativeReloadDeviceAliases(JNIEnv* env,
-        jclass clazz, jint ptr) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->getInputManager()->getReader()->requestRefreshConfiguration(
-            InputReaderConfiguration::CHANGE_DEVICE_ALIAS);
-}
-
-static jstring nativeDump(JNIEnv* env, jclass clazz, jint ptr) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    String8 dump;
-    im->dump(dump);
-    return env->NewStringUTF(dump.string());
-}
-
-static void nativeMonitor(JNIEnv* env, jclass clazz, jint ptr) {
-    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
-
-    im->getInputManager()->getReader()->monitor();
-    im->getInputManager()->getDispatcher()->monitor();
-}
-
-// ----------------------------------------------------------------------------
-
-static JNINativeMethod gInputManagerMethods[] = {
-    /* name, signature, funcPtr */
-    { "nativeInit",
-            "(Lcom/android/server/input/InputManagerService;Landroid/content/Context;Landroid/os/MessageQueue;)I",
-            (void*) nativeInit },
-    { "nativeStart", "(I)V",
-            (void*) nativeStart },
-    { "nativeSetDisplayViewport", "(IZIIIIIIIIIIII)V",
-            (void*) nativeSetDisplayViewport },
-    { "nativeGetScanCodeState", "(IIII)I",
-            (void*) nativeGetScanCodeState },
-    { "nativeGetKeyCodeState", "(IIII)I",
-            (void*) nativeGetKeyCodeState },
-    { "nativeGetSwitchState", "(IIII)I",
-            (void*) nativeGetSwitchState },
-    { "nativeHasKeys", "(III[I[Z)Z",
-            (void*) nativeHasKeys },
-    { "nativeRegisterInputChannel",
-            "(ILandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;Z)V",
-            (void*) nativeRegisterInputChannel },
-    { "nativeUnregisterInputChannel", "(ILandroid/view/InputChannel;)V",
-            (void*) nativeUnregisterInputChannel },
-    { "nativeSetInputFilterEnabled", "(IZ)V",
-            (void*) nativeSetInputFilterEnabled },
-    { "nativeInjectInputEvent", "(ILandroid/view/InputEvent;IIIII)I",
-            (void*) nativeInjectInputEvent },
-    { "nativeSetInputWindows", "(I[Lcom/android/server/input/InputWindowHandle;)V",
-            (void*) nativeSetInputWindows },
-    { "nativeSetFocusedApplication", "(ILcom/android/server/input/InputApplicationHandle;)V",
-            (void*) nativeSetFocusedApplication },
-    { "nativeSetInputDispatchMode", "(IZZ)V",
-            (void*) nativeSetInputDispatchMode },
-    { "nativeSetSystemUiVisibility", "(II)V",
-            (void*) nativeSetSystemUiVisibility },
-    { "nativeTransferTouchFocus", "(ILandroid/view/InputChannel;Landroid/view/InputChannel;)Z",
-            (void*) nativeTransferTouchFocus },
-    { "nativeSetPointerSpeed", "(II)V",
-            (void*) nativeSetPointerSpeed },
-    { "nativeSetShowTouches", "(IZ)V",
-            (void*) nativeSetShowTouches },
-    { "nativeVibrate", "(II[JII)V",
-            (void*) nativeVibrate },
-    { "nativeCancelVibrate", "(III)V",
-            (void*) nativeCancelVibrate },
-    { "nativeReloadKeyboardLayouts", "(I)V",
-            (void*) nativeReloadKeyboardLayouts },
-    { "nativeReloadDeviceAliases", "(I)V",
-            (void*) nativeReloadDeviceAliases },
-    { "nativeDump", "(I)Ljava/lang/String;",
-            (void*) nativeDump },
-    { "nativeMonitor", "(I)V",
-            (void*) nativeMonitor },
-};
-
-#define FIND_CLASS(var, className) \
-        var = env->FindClass(className); \
-        LOG_FATAL_IF(! var, "Unable to find class " className);
-
-#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
-        var = env->GetMethodID(clazz, methodName, methodDescriptor); \
-        LOG_FATAL_IF(! var, "Unable to find method " methodName);
-
-#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
-        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
-        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
-
-int register_android_server_InputManager(JNIEnv* env) {
-    int res = jniRegisterNativeMethods(env, "com/android/server/input/InputManagerService",
-            gInputManagerMethods, NELEM(gInputManagerMethods));
-    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
-
-    // Callbacks
-
-    jclass clazz;
-    FIND_CLASS(clazz, "com/android/server/input/InputManagerService");
-
-    GET_METHOD_ID(gServiceClassInfo.notifyConfigurationChanged, clazz,
-            "notifyConfigurationChanged", "(J)V");
-
-    GET_METHOD_ID(gServiceClassInfo.notifyInputDevicesChanged, clazz,
-            "notifyInputDevicesChanged", "([Landroid/view/InputDevice;)V");
-
-    GET_METHOD_ID(gServiceClassInfo.notifySwitch, clazz,
-            "notifySwitch", "(JII)V");
-
-    GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
-            "notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
-
-    GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
-            "notifyANR",
-            "(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
-
-    GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
-            "filterInputEvent", "(Landroid/view/InputEvent;I)Z");
-
-    GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeQueueing, clazz,
-            "interceptKeyBeforeQueueing", "(Landroid/view/KeyEvent;IZ)I");
-
-    GET_METHOD_ID(gServiceClassInfo.interceptMotionBeforeQueueingWhenScreenOff,
-            clazz,
-            "interceptMotionBeforeQueueingWhenScreenOff", "(I)I");
-
-    GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
-            "interceptKeyBeforeDispatching",
-            "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
-
-    GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
-            "dispatchUnhandledKey",
-            "(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
-
-    GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
-            "checkInjectEventsPermission", "(II)Z");
-
-    GET_METHOD_ID(gServiceClassInfo.getVirtualKeyQuietTimeMillis, clazz,
-            "getVirtualKeyQuietTimeMillis", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getExcludedDeviceNames, clazz,
-            "getExcludedDeviceNames", "()[Ljava/lang/String;");
-
-    GET_METHOD_ID(gServiceClassInfo.getKeyRepeatTimeout, clazz,
-            "getKeyRepeatTimeout", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getKeyRepeatDelay, clazz,
-            "getKeyRepeatDelay", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getHoverTapTimeout, clazz,
-            "getHoverTapTimeout", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getHoverTapSlop, clazz,
-            "getHoverTapSlop", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getDoubleTapTimeout, clazz,
-            "getDoubleTapTimeout", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getLongPressTimeout, clazz,
-            "getLongPressTimeout", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getPointerLayer, clazz,
-            "getPointerLayer", "()I");
-
-    GET_METHOD_ID(gServiceClassInfo.getPointerIcon, clazz,
-            "getPointerIcon", "()Landroid/view/PointerIcon;");
-
-    GET_METHOD_ID(gServiceClassInfo.getKeyboardLayoutOverlay, clazz,
-            "getKeyboardLayoutOverlay", "(Ljava/lang/String;)[Ljava/lang/String;");
-
-    GET_METHOD_ID(gServiceClassInfo.getDeviceAlias, clazz,
-            "getDeviceAlias", "(Ljava/lang/String;)Ljava/lang/String;");
-
-    // InputDevice
-
-    FIND_CLASS(gInputDeviceClassInfo.clazz, "android/view/InputDevice");
-    gInputDeviceClassInfo.clazz = jclass(env->NewGlobalRef(gInputDeviceClassInfo.clazz));
-
-    // KeyEvent
-
-    FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
-    gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
-
-    // MotionEvent
-
-    FIND_CLASS(gMotionEventClassInfo.clazz, "android/view/MotionEvent");
-    gMotionEventClassInfo.clazz = jclass(env->NewGlobalRef(gMotionEventClassInfo.clazz));
-
-    return 0;
-}
-
-} /* namespace android */
diff --git a/services/jni/com_android_server_input_InputWindowHandle.cpp b/services/jni/com_android_server_input_InputWindowHandle.cpp
deleted file mode 100644
index 82e3dad..0000000
--- a/services/jni/com_android_server_input_InputWindowHandle.cpp
+++ /dev/null
@@ -1,309 +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.
- */
-
-#define LOG_TAG "InputWindowHandle"
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include <android_runtime/AndroidRuntime.h>
-#include <utils/threads.h>
-
-#include <android_view_InputChannel.h>
-#include <android/graphics/Region.h>
-
-#include "com_android_server_input_InputWindowHandle.h"
-#include "com_android_server_input_InputApplicationHandle.h"
-
-namespace android {
-
-static struct {
-    jfieldID ptr;
-    jfieldID inputApplicationHandle;
-    jfieldID inputChannel;
-    jfieldID name;
-    jfieldID layoutParamsFlags;
-    jfieldID layoutParamsPrivateFlags;
-    jfieldID layoutParamsType;
-    jfieldID dispatchingTimeoutNanos;
-    jfieldID frameLeft;
-    jfieldID frameTop;
-    jfieldID frameRight;
-    jfieldID frameBottom;
-    jfieldID scaleFactor;
-    jfieldID touchableRegion;
-    jfieldID visible;
-    jfieldID canReceiveKeys;
-    jfieldID hasFocus;
-    jfieldID hasWallpaper;
-    jfieldID paused;
-    jfieldID layer;
-    jfieldID ownerPid;
-    jfieldID ownerUid;
-    jfieldID inputFeatures;
-    jfieldID displayId;
-} gInputWindowHandleClassInfo;
-
-static Mutex gHandleMutex;
-
-
-// --- NativeInputWindowHandle ---
-
-NativeInputWindowHandle::NativeInputWindowHandle(
-        const sp<InputApplicationHandle>& inputApplicationHandle, jweak objWeak) :
-        InputWindowHandle(inputApplicationHandle),
-        mObjWeak(objWeak) {
-}
-
-NativeInputWindowHandle::~NativeInputWindowHandle() {
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->DeleteWeakGlobalRef(mObjWeak);
-}
-
-jobject NativeInputWindowHandle::getInputWindowHandleObjLocalRef(JNIEnv* env) {
-    return env->NewLocalRef(mObjWeak);
-}
-
-bool NativeInputWindowHandle::updateInfo() {
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jobject obj = env->NewLocalRef(mObjWeak);
-    if (!obj) {
-        releaseInfo();
-        return false;
-    }
-
-    if (!mInfo) {
-        mInfo = new InputWindowInfo();
-    }
-
-    jobject inputChannelObj = env->GetObjectField(obj,
-            gInputWindowHandleClassInfo.inputChannel);
-    if (inputChannelObj) {
-        mInfo->inputChannel = android_view_InputChannel_getInputChannel(env, inputChannelObj);
-        env->DeleteLocalRef(inputChannelObj);
-    } else {
-        mInfo->inputChannel.clear();
-    }
-
-    jstring nameObj = jstring(env->GetObjectField(obj,
-            gInputWindowHandleClassInfo.name));
-    if (nameObj) {
-        const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
-        mInfo->name.setTo(nameStr);
-        env->ReleaseStringUTFChars(nameObj, nameStr);
-        env->DeleteLocalRef(nameObj);
-    } else {
-        mInfo->name.setTo("<null>");
-    }
-
-    mInfo->layoutParamsFlags = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.layoutParamsFlags);
-    mInfo->layoutParamsPrivateFlags = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.layoutParamsPrivateFlags);
-    mInfo->layoutParamsType = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.layoutParamsType);
-    mInfo->dispatchingTimeout = env->GetLongField(obj,
-            gInputWindowHandleClassInfo.dispatchingTimeoutNanos);
-    mInfo->frameLeft = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.frameLeft);
-    mInfo->frameTop = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.frameTop);
-    mInfo->frameRight = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.frameRight);
-    mInfo->frameBottom = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.frameBottom);
-    mInfo->scaleFactor = env->GetFloatField(obj,
-            gInputWindowHandleClassInfo.scaleFactor);
-
-    jobject regionObj = env->GetObjectField(obj,
-            gInputWindowHandleClassInfo.touchableRegion);
-    if (regionObj) {
-        SkRegion* region = android_graphics_Region_getSkRegion(env, regionObj);
-        mInfo->touchableRegion.set(*region);
-        env->DeleteLocalRef(regionObj);
-    } else {
-        mInfo->touchableRegion.setEmpty();
-    }
-
-    mInfo->visible = env->GetBooleanField(obj,
-            gInputWindowHandleClassInfo.visible);
-    mInfo->canReceiveKeys = env->GetBooleanField(obj,
-            gInputWindowHandleClassInfo.canReceiveKeys);
-    mInfo->hasFocus = env->GetBooleanField(obj,
-            gInputWindowHandleClassInfo.hasFocus);
-    mInfo->hasWallpaper = env->GetBooleanField(obj,
-            gInputWindowHandleClassInfo.hasWallpaper);
-    mInfo->paused = env->GetBooleanField(obj,
-            gInputWindowHandleClassInfo.paused);
-    mInfo->layer = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.layer);
-    mInfo->ownerPid = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.ownerPid);
-    mInfo->ownerUid = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.ownerUid);
-    mInfo->inputFeatures = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.inputFeatures);
-    mInfo->displayId = env->GetIntField(obj,
-            gInputWindowHandleClassInfo.displayId);
-
-    env->DeleteLocalRef(obj);
-    return true;
-}
-
-
-// --- Global functions ---
-
-sp<NativeInputWindowHandle> android_server_InputWindowHandle_getHandle(
-        JNIEnv* env, jobject inputWindowHandleObj) {
-    if (!inputWindowHandleObj) {
-        return NULL;
-    }
-
-    AutoMutex _l(gHandleMutex);
-
-    int ptr = env->GetIntField(inputWindowHandleObj, gInputWindowHandleClassInfo.ptr);
-    NativeInputWindowHandle* handle;
-    if (ptr) {
-        handle = reinterpret_cast<NativeInputWindowHandle*>(ptr);
-    } else {
-        jobject inputApplicationHandleObj = env->GetObjectField(inputWindowHandleObj,
-                gInputWindowHandleClassInfo.inputApplicationHandle);
-        sp<InputApplicationHandle> inputApplicationHandle =
-                android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj);
-        env->DeleteLocalRef(inputApplicationHandleObj);
-
-        jweak objWeak = env->NewWeakGlobalRef(inputWindowHandleObj);
-        handle = new NativeInputWindowHandle(inputApplicationHandle, objWeak);
-        handle->incStrong((void*)android_server_InputWindowHandle_getHandle);
-        env->SetIntField(inputWindowHandleObj, gInputWindowHandleClassInfo.ptr,
-                reinterpret_cast<int>(handle));
-    }
-    return handle;
-}
-
-
-// --- JNI ---
-
-static void android_server_InputWindowHandle_nativeDispose(JNIEnv* env, jobject obj) {
-    AutoMutex _l(gHandleMutex);
-
-    int ptr = env->GetIntField(obj, gInputWindowHandleClassInfo.ptr);
-    if (ptr) {
-        env->SetIntField(obj, gInputWindowHandleClassInfo.ptr, 0);
-
-        NativeInputWindowHandle* handle = reinterpret_cast<NativeInputWindowHandle*>(ptr);
-        handle->decStrong((void*)android_server_InputWindowHandle_getHandle);
-    }
-}
-
-
-static JNINativeMethod gInputWindowHandleMethods[] = {
-    /* name, signature, funcPtr */
-    { "nativeDispose", "()V",
-            (void*) android_server_InputWindowHandle_nativeDispose },
-};
-
-#define FIND_CLASS(var, className) \
-        var = env->FindClass(className); \
-        LOG_FATAL_IF(! var, "Unable to find class " className);
-
-#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
-        var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
-        LOG_FATAL_IF(! var, "Unable to find field " fieldName);
-
-int register_android_server_InputWindowHandle(JNIEnv* env) {
-    int res = jniRegisterNativeMethods(env, "com/android/server/input/InputWindowHandle",
-            gInputWindowHandleMethods, NELEM(gInputWindowHandleMethods));
-    LOG_FATAL_IF(res < 0, "Unable to register native methods.");
-
-    jclass clazz;
-    FIND_CLASS(clazz, "com/android/server/input/InputWindowHandle");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.ptr, clazz,
-            "ptr", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle,
-            clazz,
-            "inputApplicationHandle", "Lcom/android/server/input/InputApplicationHandle;");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.inputChannel, clazz,
-            "inputChannel", "Landroid/view/InputChannel;");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.name, clazz,
-            "name", "Ljava/lang/String;");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.layoutParamsFlags, clazz,
-            "layoutParamsFlags", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.layoutParamsPrivateFlags, clazz,
-            "layoutParamsPrivateFlags", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.layoutParamsType, clazz,
-            "layoutParamsType", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.dispatchingTimeoutNanos, clazz,
-            "dispatchingTimeoutNanos", "J");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.frameLeft, clazz,
-            "frameLeft", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.frameTop, clazz,
-            "frameTop", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.frameRight, clazz,
-            "frameRight", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.frameBottom, clazz,
-            "frameBottom", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.scaleFactor, clazz,
-            "scaleFactor", "F");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegion, clazz,
-            "touchableRegion", "Landroid/graphics/Region;");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.visible, clazz,
-            "visible", "Z");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.canReceiveKeys, clazz,
-            "canReceiveKeys", "Z");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.hasFocus, clazz,
-            "hasFocus", "Z");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.hasWallpaper, clazz,
-            "hasWallpaper", "Z");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.paused, clazz,
-            "paused", "Z");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.layer, clazz,
-            "layer", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.ownerPid, clazz,
-            "ownerPid", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.ownerUid, clazz,
-            "ownerUid", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.inputFeatures, clazz,
-            "inputFeatures", "I");
-
-    GET_FIELD_ID(gInputWindowHandleClassInfo.displayId, clazz,
-            "displayId", "I");
-    return 0;
-}
-
-} /* namespace android */
diff --git a/services/jni/com_android_server_location_GpsLocationProvider.cpp b/services/jni/com_android_server_location_GpsLocationProvider.cpp
deleted file mode 100644
index aec254b..0000000
--- a/services/jni/com_android_server_location_GpsLocationProvider.cpp
+++ /dev/null
@@ -1,777 +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.
- */
-
-#define LOG_TAG "GpsLocationProvider"
-
-#define LOG_NDEBUG 0
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include "hardware/hardware.h"
-#include "hardware/gps.h"
-#include "hardware_legacy/power.h"
-#include "utils/Log.h"
-#include "utils/misc.h"
-#include "android_runtime/AndroidRuntime.h"
-#include "android_runtime/Log.h"
-
-#include <string.h>
-#include <pthread.h>
-
-static jobject mCallbacksObj = NULL;
-
-static jmethodID method_reportLocation;
-static jmethodID method_reportStatus;
-static jmethodID method_reportSvStatus;
-static jmethodID method_reportAGpsStatus;
-static jmethodID method_reportNmea;
-static jmethodID method_setEngineCapabilities;
-static jmethodID method_xtraDownloadRequest;
-static jmethodID method_reportNiNotification;
-static jmethodID method_requestRefLocation;
-static jmethodID method_requestSetID;
-static jmethodID method_requestUtcTime;
-static jmethodID method_reportGeofenceTransition;
-static jmethodID method_reportGeofenceStatus;
-static jmethodID method_reportGeofenceAddStatus;
-static jmethodID method_reportGeofenceRemoveStatus;
-static jmethodID method_reportGeofencePauseStatus;
-static jmethodID method_reportGeofenceResumeStatus;
-
-static const GpsInterface* sGpsInterface = NULL;
-static const GpsXtraInterface* sGpsXtraInterface = NULL;
-static const AGpsInterface* sAGpsInterface = NULL;
-static const GpsNiInterface* sGpsNiInterface = NULL;
-static const GpsDebugInterface* sGpsDebugInterface = NULL;
-static const AGpsRilInterface* sAGpsRilInterface = NULL;
-static const GpsGeofencingInterface* sGpsGeofencingInterface = NULL;
-
-// temporary storage for GPS callbacks
-static GpsSvStatus  sGpsSvStatus;
-static const char* sNmeaString;
-static int sNmeaStringLength;
-
-#define WAKE_LOCK_NAME  "GPS"
-
-namespace android {
-
-static void checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
-    if (env->ExceptionCheck()) {
-        ALOGE("An exception was thrown by callback '%s'.", methodName);
-        LOGE_EX(env);
-        env->ExceptionClear();
-    }
-}
-
-static void location_callback(GpsLocation* location)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags,
-            (jdouble)location->latitude, (jdouble)location->longitude,
-            (jdouble)location->altitude,
-            (jfloat)location->speed, (jfloat)location->bearing,
-            (jfloat)location->accuracy, (jlong)location->timestamp);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static void status_callback(GpsStatus* status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_reportStatus, status->status);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static void sv_status_callback(GpsSvStatus* sv_status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    memcpy(&sGpsSvStatus, sv_status, sizeof(sGpsSvStatus));
-    env->CallVoidMethod(mCallbacksObj, method_reportSvStatus);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    // The Java code will call back to read these values
-    // We do this to avoid creating unnecessary String objects
-    sNmeaString = nmea;
-    sNmeaStringLength = length;
-    env->CallVoidMethod(mCallbacksObj, method_reportNmea, timestamp);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static void set_capabilities_callback(uint32_t capabilities)
-{
-    ALOGD("set_capabilities_callback: %du\n", capabilities);
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_setEngineCapabilities, capabilities);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static void acquire_wakelock_callback()
-{
-    acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
-}
-
-static void release_wakelock_callback()
-{
-    release_wake_lock(WAKE_LOCK_NAME);
-}
-
-static void request_utc_time_callback()
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_requestUtcTime);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg)
-{
-    return (pthread_t)AndroidRuntime::createJavaThread(name, start, arg);
-}
-
-GpsCallbacks sGpsCallbacks = {
-    sizeof(GpsCallbacks),
-    location_callback,
-    status_callback,
-    sv_status_callback,
-    nmea_callback,
-    set_capabilities_callback,
-    acquire_wakelock_callback,
-    release_wakelock_callback,
-    create_thread_callback,
-    request_utc_time_callback,
-};
-
-static void xtra_download_request_callback()
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_xtraDownloadRequest);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-GpsXtraCallbacks sGpsXtraCallbacks = {
-    xtra_download_request_callback,
-    create_thread_callback,
-};
-
-static void agps_status_callback(AGpsStatus* agps_status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-
-    uint32_t ipaddr;
-    // ipaddr field was not included in original AGpsStatus
-    if (agps_status->size >= sizeof(AGpsStatus))
-        ipaddr = agps_status->ipaddr;
-    else
-        ipaddr = 0xFFFFFFFF;
-    env->CallVoidMethod(mCallbacksObj, method_reportAGpsStatus,
-                        agps_status->type, agps_status->status, ipaddr);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-AGpsCallbacks sAGpsCallbacks = {
-    agps_status_callback,
-    create_thread_callback,
-};
-
-static void gps_ni_notify_callback(GpsNiNotification *notification)
-{
-    ALOGD("gps_ni_notify_callback\n");
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jstring requestor_id = env->NewStringUTF(notification->requestor_id);
-    jstring text = env->NewStringUTF(notification->text);
-    jstring extras = env->NewStringUTF(notification->extras);
-
-    if (requestor_id && text && extras) {
-        env->CallVoidMethod(mCallbacksObj, method_reportNiNotification,
-            notification->notification_id, notification->ni_type,
-            notification->notify_flags, notification->timeout,
-            notification->default_response, requestor_id, text,
-            notification->requestor_id_encoding,
-            notification->text_encoding, extras);
-    } else {
-        ALOGE("out of memory in gps_ni_notify_callback\n");
-    }
-
-    if (requestor_id)
-        env->DeleteLocalRef(requestor_id);
-    if (text)
-        env->DeleteLocalRef(text);
-    if (extras)
-        env->DeleteLocalRef(extras);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-GpsNiCallbacks sGpsNiCallbacks = {
-    gps_ni_notify_callback,
-    create_thread_callback,
-};
-
-static void agps_request_set_id(uint32_t flags)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_requestSetID, flags);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-static void agps_request_ref_location(uint32_t flags)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    env->CallVoidMethod(mCallbacksObj, method_requestRefLocation, flags);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-}
-
-AGpsRilCallbacks sAGpsRilCallbacks = {
-    agps_request_set_id,
-    agps_request_ref_location,
-    create_thread_callback,
-};
-
-static void gps_geofence_transition_callback(int32_t geofence_id,  GpsLocation* location,
-        int32_t transition, GpsUtcTime timestamp)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-
-    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceTransition, geofence_id,
-            location->flags, (jdouble)location->latitude, (jdouble)location->longitude,
-            (jdouble)location->altitude,
-            (jfloat)location->speed, (jfloat)location->bearing,
-            (jfloat)location->accuracy, (jlong)location->timestamp,
-            transition, timestamp);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-};
-
-static void gps_geofence_status_callback(int32_t status, GpsLocation* location)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    jint flags = 0;
-    jdouble latitude = 0;
-    jdouble longitude = 0;
-    jdouble altitude = 0;
-    jfloat speed = 0;
-    jfloat bearing = 0;
-    jfloat accuracy = 0;
-    jlong timestamp = 0;
-    if (location != NULL) {
-        flags = location->flags;
-        latitude = location->latitude;
-        longitude = location->longitude;
-        altitude = location->altitude;
-        speed = location->speed;
-        bearing = location->bearing;
-        accuracy = location->accuracy;
-        timestamp = location->timestamp;
-    }
-
-    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceStatus, status,
-            flags, latitude, longitude, altitude, speed, bearing, accuracy, timestamp);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-};
-
-static void gps_geofence_add_callback(int32_t geofence_id, int32_t status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
-        ALOGE("Error in geofence_add_callback: %d\n", status);
-    }
-    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceAddStatus, geofence_id, status);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-};
-
-static void gps_geofence_remove_callback(int32_t geofence_id, int32_t status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
-        ALOGE("Error in geofence_remove_callback: %d\n", status);
-    }
-    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceRemoveStatus, geofence_id, status);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-};
-
-static void gps_geofence_resume_callback(int32_t geofence_id, int32_t status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
-        ALOGE("Error in geofence_resume_callback: %d\n", status);
-    }
-    env->CallVoidMethod(mCallbacksObj, method_reportGeofenceResumeStatus, geofence_id, status);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-};
-
-static void gps_geofence_pause_callback(int32_t geofence_id, int32_t status)
-{
-    JNIEnv* env = AndroidRuntime::getJNIEnv();
-    if (status != GPS_GEOFENCE_OPERATION_SUCCESS) {
-        ALOGE("Error in geofence_pause_callback: %d\n", status);
-    }
-    env->CallVoidMethod(mCallbacksObj, method_reportGeofencePauseStatus, geofence_id, status);
-    checkAndClearExceptionFromCallback(env, __FUNCTION__);
-};
-
-GpsGeofenceCallbacks sGpsGeofenceCallbacks = {
-    gps_geofence_transition_callback,
-    gps_geofence_status_callback,
-    gps_geofence_add_callback,
-    gps_geofence_remove_callback,
-    gps_geofence_pause_callback,
-    gps_geofence_resume_callback,
-    create_thread_callback,
-};
-
-static void android_location_GpsLocationProvider_class_init_native(JNIEnv* env, jclass clazz) {
-    int err;
-    hw_module_t* module;
-
-    method_reportLocation = env->GetMethodID(clazz, "reportLocation", "(IDDDFFFJ)V");
-    method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
-    method_reportSvStatus = env->GetMethodID(clazz, "reportSvStatus", "()V");
-    method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(III)V");
-    method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V");
-    method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V");
-    method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
-    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification",
-            "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");
-    method_requestRefLocation = env->GetMethodID(clazz,"requestRefLocation","(I)V");
-    method_requestSetID = env->GetMethodID(clazz,"requestSetID","(I)V");
-    method_requestUtcTime = env->GetMethodID(clazz,"requestUtcTime","()V");
-    method_reportGeofenceTransition = env->GetMethodID(clazz,"reportGeofenceTransition",
-            "(IIDDDFFFJIJ)V");
-    method_reportGeofenceStatus = env->GetMethodID(clazz,"reportGeofenceStatus",
-            "(IIDDDFFFJ)V");
-    method_reportGeofenceAddStatus = env->GetMethodID(clazz,"reportGeofenceAddStatus",
-            "(II)V");
-    method_reportGeofenceRemoveStatus = env->GetMethodID(clazz,"reportGeofenceRemoveStatus",
-            "(II)V");
-    method_reportGeofenceResumeStatus = env->GetMethodID(clazz,"reportGeofenceResumeStatus",
-            "(II)V");
-    method_reportGeofencePauseStatus = env->GetMethodID(clazz,"reportGeofencePauseStatus",
-            "(II)V");
-
-    err = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
-    if (err == 0) {
-        hw_device_t* device;
-        err = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
-        if (err == 0) {
-            gps_device_t* gps_device = (gps_device_t *)device;
-            sGpsInterface = gps_device->get_gps_interface(gps_device);
-        }
-    }
-    if (sGpsInterface) {
-        sGpsXtraInterface =
-            (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE);
-        sAGpsInterface =
-            (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
-        sGpsNiInterface =
-            (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
-        sGpsDebugInterface =
-            (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE);
-        sAGpsRilInterface =
-            (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE);
-        sGpsGeofencingInterface =
-            (const GpsGeofencingInterface*)sGpsInterface->get_extension(GPS_GEOFENCING_INTERFACE);
-    }
-}
-
-static jboolean android_location_GpsLocationProvider_is_supported(JNIEnv* env, jclass clazz) {
-    return (sGpsInterface != NULL);
-}
-
-static jboolean android_location_GpsLocationProvider_init(JNIEnv* env, jobject obj)
-{
-    // this must be set before calling into the HAL library
-    if (!mCallbacksObj)
-        mCallbacksObj = env->NewGlobalRef(obj);
-
-    // fail if the main interface fails to initialize
-    if (!sGpsInterface || sGpsInterface->init(&sGpsCallbacks) != 0)
-        return false;
-
-    // if XTRA initialization fails we will disable it by sGpsXtraInterface to NULL,
-    // but continue to allow the rest of the GPS interface to work.
-    if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0)
-        sGpsXtraInterface = NULL;
-    if (sAGpsInterface)
-        sAGpsInterface->init(&sAGpsCallbacks);
-    if (sGpsNiInterface)
-        sGpsNiInterface->init(&sGpsNiCallbacks);
-    if (sAGpsRilInterface)
-        sAGpsRilInterface->init(&sAGpsRilCallbacks);
-    if (sGpsGeofencingInterface)
-        sGpsGeofencingInterface->init(&sGpsGeofenceCallbacks);
-
-    return true;
-}
-
-static void android_location_GpsLocationProvider_cleanup(JNIEnv* env, jobject obj)
-{
-    if (sGpsInterface)
-        sGpsInterface->cleanup();
-}
-
-static jboolean android_location_GpsLocationProvider_set_position_mode(JNIEnv* env, jobject obj,
-        jint mode, jint recurrence, jint min_interval, jint preferred_accuracy, jint preferred_time)
-{
-    if (sGpsInterface)
-        return (sGpsInterface->set_position_mode(mode, recurrence, min_interval, preferred_accuracy,
-                preferred_time) == 0);
-    else
-        return false;
-}
-
-static jboolean android_location_GpsLocationProvider_start(JNIEnv* env, jobject obj)
-{
-    if (sGpsInterface)
-        return (sGpsInterface->start() == 0);
-    else
-        return false;
-}
-
-static jboolean android_location_GpsLocationProvider_stop(JNIEnv* env, jobject obj)
-{
-    if (sGpsInterface)
-        return (sGpsInterface->stop() == 0);
-    else
-        return false;
-}
-
-static void android_location_GpsLocationProvider_delete_aiding_data(JNIEnv* env, jobject obj, jint flags)
-{
-    if (sGpsInterface)
-        sGpsInterface->delete_aiding_data(flags);
-}
-
-static jint android_location_GpsLocationProvider_read_sv_status(JNIEnv* env, jobject obj,
-        jintArray prnArray, jfloatArray snrArray, jfloatArray elevArray, jfloatArray azumArray,
-        jintArray maskArray)
-{
-    // this should only be called from within a call to reportSvStatus
-
-    jint* prns = env->GetIntArrayElements(prnArray, 0);
-    jfloat* snrs = env->GetFloatArrayElements(snrArray, 0);
-    jfloat* elev = env->GetFloatArrayElements(elevArray, 0);
-    jfloat* azim = env->GetFloatArrayElements(azumArray, 0);
-    jint* mask = env->GetIntArrayElements(maskArray, 0);
-
-    int num_svs = sGpsSvStatus.num_svs;
-    for (int i = 0; i < num_svs; i++) {
-        prns[i] = sGpsSvStatus.sv_list[i].prn;
-        snrs[i] = sGpsSvStatus.sv_list[i].snr;
-        elev[i] = sGpsSvStatus.sv_list[i].elevation;
-        azim[i] = sGpsSvStatus.sv_list[i].azimuth;
-    }
-    mask[0] = sGpsSvStatus.ephemeris_mask;
-    mask[1] = sGpsSvStatus.almanac_mask;
-    mask[2] = sGpsSvStatus.used_in_fix_mask;
-
-    env->ReleaseIntArrayElements(prnArray, prns, 0);
-    env->ReleaseFloatArrayElements(snrArray, snrs, 0);
-    env->ReleaseFloatArrayElements(elevArray, elev, 0);
-    env->ReleaseFloatArrayElements(azumArray, azim, 0);
-    env->ReleaseIntArrayElements(maskArray, mask, 0);
-    return num_svs;
-}
-
-static void android_location_GpsLocationProvider_agps_set_reference_location_cellid(JNIEnv* env,
-        jobject obj, jint type, jint mcc, jint mnc, jint lac, jint cid)
-{
-    AGpsRefLocation location;
-
-    if (!sAGpsRilInterface) {
-        ALOGE("no AGPS RIL interface in agps_set_reference_location_cellid");
-        return;
-    }
-
-    switch(type) {
-        case AGPS_REF_LOCATION_TYPE_GSM_CELLID:
-        case AGPS_REF_LOCATION_TYPE_UMTS_CELLID:
-            location.type = type;
-            location.u.cellID.mcc = mcc;
-            location.u.cellID.mnc = mnc;
-            location.u.cellID.lac = lac;
-            location.u.cellID.cid = cid;
-            break;
-        default:
-            ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).",__FUNCTION__,__LINE__);
-            return;
-            break;
-    }
-    sAGpsRilInterface->set_ref_location(&location, sizeof(location));
-}
-
-static void android_location_GpsLocationProvider_agps_send_ni_message(JNIEnv* env,
-        jobject obj, jbyteArray ni_msg, jint size)
-{
-    size_t sz;
-
-    if (!sAGpsRilInterface) {
-        ALOGE("no AGPS RIL interface in send_ni_message");
-        return;
-    }
-    if (size < 0)
-        return;
-    sz = (size_t)size;
-    jbyte* b = env->GetByteArrayElements(ni_msg, 0);
-    sAGpsRilInterface->ni_message((uint8_t *)b,sz);
-    env->ReleaseByteArrayElements(ni_msg,b,0);
-}
-
-static void android_location_GpsLocationProvider_agps_set_id(JNIEnv *env,
-        jobject obj, jint type, jstring  setid_string)
-{
-    if (!sAGpsRilInterface) {
-        ALOGE("no AGPS RIL interface in agps_set_id");
-        return;
-    }
-
-    const char *setid = env->GetStringUTFChars(setid_string, NULL);
-    sAGpsRilInterface->set_set_id(type, setid);
-    env->ReleaseStringUTFChars(setid_string, setid);
-}
-
-static jint android_location_GpsLocationProvider_read_nmea(JNIEnv* env, jobject obj,
-                                            jbyteArray nmeaArray, jint buffer_size)
-{
-    // this should only be called from within a call to reportNmea
-    jbyte* nmea = (jbyte *)env->GetPrimitiveArrayCritical(nmeaArray, 0);
-    int length = sNmeaStringLength;
-    if (length > buffer_size)
-        length = buffer_size;
-    memcpy(nmea, sNmeaString, length);
-    env->ReleasePrimitiveArrayCritical(nmeaArray, nmea, JNI_ABORT);
-    return length;
-}
-
-static void android_location_GpsLocationProvider_inject_time(JNIEnv* env, jobject obj,
-        jlong time, jlong timeReference, jint uncertainty)
-{
-    if (sGpsInterface)
-        sGpsInterface->inject_time(time, timeReference, uncertainty);
-}
-
-static void android_location_GpsLocationProvider_inject_location(JNIEnv* env, jobject obj,
-        jdouble latitude, jdouble longitude, jfloat accuracy)
-{
-    if (sGpsInterface)
-        sGpsInterface->inject_location(latitude, longitude, accuracy);
-}
-
-static jboolean android_location_GpsLocationProvider_supports_xtra(JNIEnv* env, jobject obj)
-{
-    return (sGpsXtraInterface != NULL);
-}
-
-static void android_location_GpsLocationProvider_inject_xtra_data(JNIEnv* env, jobject obj,
-        jbyteArray data, jint length)
-{
-    if (!sGpsXtraInterface) {
-        ALOGE("no XTRA interface in inject_xtra_data");
-        return;
-    }
-
-    jbyte* bytes = (jbyte *)env->GetPrimitiveArrayCritical(data, 0);
-    sGpsXtraInterface->inject_xtra_data((char *)bytes, length);
-    env->ReleasePrimitiveArrayCritical(data, bytes, JNI_ABORT);
-}
-
-static void android_location_GpsLocationProvider_agps_data_conn_open(JNIEnv* env, jobject obj, jstring apn)
-{
-    if (!sAGpsInterface) {
-        ALOGE("no AGPS interface in agps_data_conn_open");
-        return;
-    }
-    if (apn == NULL) {
-        jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return;
-    }
-    const char *apnStr = env->GetStringUTFChars(apn, NULL);
-    sAGpsInterface->data_conn_open(apnStr);
-    env->ReleaseStringUTFChars(apn, apnStr);
-}
-
-static void android_location_GpsLocationProvider_agps_data_conn_closed(JNIEnv* env, jobject obj)
-{
-    if (!sAGpsInterface) {
-        ALOGE("no AGPS interface in agps_data_conn_closed");
-        return;
-    }
-    sAGpsInterface->data_conn_closed();
-}
-
-static void android_location_GpsLocationProvider_agps_data_conn_failed(JNIEnv* env, jobject obj)
-{
-    if (!sAGpsInterface) {
-        ALOGE("no AGPS interface in agps_data_conn_failed");
-        return;
-    }
-    sAGpsInterface->data_conn_failed();
-}
-
-static void android_location_GpsLocationProvider_set_agps_server(JNIEnv* env, jobject obj,
-        jint type, jstring hostname, jint port)
-{
-    if (!sAGpsInterface) {
-        ALOGE("no AGPS interface in set_agps_server");
-        return;
-    }
-    const char *c_hostname = env->GetStringUTFChars(hostname, NULL);
-    sAGpsInterface->set_server(type, c_hostname, port);
-    env->ReleaseStringUTFChars(hostname, c_hostname);
-}
-
-static void android_location_GpsLocationProvider_send_ni_response(JNIEnv* env, jobject obj,
-      jint notifId, jint response)
-{
-    if (!sGpsNiInterface) {
-        ALOGE("no NI interface in send_ni_response");
-        return;
-    }
-
-    sGpsNiInterface->respond(notifId, response);
-}
-
-static jstring android_location_GpsLocationProvider_get_internal_state(JNIEnv* env, jobject obj)
-{
-    jstring result = NULL;
-    if (sGpsDebugInterface) {
-        const size_t maxLength = 2047;
-        char buffer[maxLength+1];
-        size_t length = sGpsDebugInterface->get_internal_state(buffer, maxLength);
-        if (length > maxLength) length = maxLength;
-        buffer[length] = 0;
-        result = env->NewStringUTF(buffer);
-    }
-    return result;
-}
-
-static void android_location_GpsLocationProvider_update_network_state(JNIEnv* env, jobject obj,
-        jboolean connected, int type, jboolean roaming, jboolean available, jstring extraInfo, jstring apn)
-{
-
-    if (sAGpsRilInterface && sAGpsRilInterface->update_network_state) {
-        if (extraInfo) {
-            const char *extraInfoStr = env->GetStringUTFChars(extraInfo, NULL);
-            sAGpsRilInterface->update_network_state(connected, type, roaming, extraInfoStr);
-            env->ReleaseStringUTFChars(extraInfo, extraInfoStr);
-        } else {
-            sAGpsRilInterface->update_network_state(connected, type, roaming, NULL);
-        }
-
-        // update_network_availability callback was not included in original AGpsRilInterface
-        if (sAGpsRilInterface->size >= sizeof(AGpsRilInterface)
-                && sAGpsRilInterface->update_network_availability) {
-            const char *c_apn = env->GetStringUTFChars(apn, NULL);
-            sAGpsRilInterface->update_network_availability(available, c_apn);
-            env->ReleaseStringUTFChars(apn, c_apn);
-        }
-    }
-}
-
-static jboolean android_location_GpsLocationProvider_is_geofence_supported(JNIEnv* env,
-          jobject obj) {
-    if (sGpsGeofencingInterface != NULL) {
-        return JNI_TRUE;
-    }
-    return JNI_FALSE;
-}
-
-static jboolean android_location_GpsLocationProvider_add_geofence(JNIEnv* env, jobject obj,
-        jint geofence_id, jdouble latitude, jdouble longitude, jdouble radius,
-        jint last_transition, jint monitor_transition, jint notification_responsiveness,
-        jint unknown_timer) {
-    if (sGpsGeofencingInterface != NULL) {
-        sGpsGeofencingInterface->add_geofence_area(geofence_id, latitude, longitude,
-                radius, last_transition, monitor_transition, notification_responsiveness,
-                unknown_timer);
-        return JNI_TRUE;
-    } else {
-        ALOGE("Geofence interface not available");
-    }
-    return JNI_FALSE;
-}
-
-static jboolean android_location_GpsLocationProvider_remove_geofence(JNIEnv* env, jobject obj,
-        jint geofence_id) {
-    if (sGpsGeofencingInterface != NULL) {
-        sGpsGeofencingInterface->remove_geofence_area(geofence_id);
-        return JNI_TRUE;
-    } else {
-        ALOGE("Geofence interface not available");
-    }
-    return JNI_FALSE;
-}
-
-static jboolean android_location_GpsLocationProvider_pause_geofence(JNIEnv* env, jobject obj,
-        jint geofence_id) {
-    if (sGpsGeofencingInterface != NULL) {
-        sGpsGeofencingInterface->pause_geofence(geofence_id);
-        return JNI_TRUE;
-    } else {
-        ALOGE("Geofence interface not available");
-    }
-    return JNI_FALSE;
-}
-
-static jboolean android_location_GpsLocationProvider_resume_geofence(JNIEnv* env, jobject obj,
-        jint geofence_id, jint monitor_transition) {
-    if (sGpsGeofencingInterface != NULL) {
-        sGpsGeofencingInterface->resume_geofence(geofence_id, monitor_transition);
-        return JNI_TRUE;
-    } else {
-        ALOGE("Geofence interface not available");
-    }
-    return JNI_FALSE;
-}
-
-static JNINativeMethod sMethods[] = {
-     /* name, signature, funcPtr */
-    {"class_init_native", "()V", (void *)android_location_GpsLocationProvider_class_init_native},
-    {"native_is_supported", "()Z", (void*)android_location_GpsLocationProvider_is_supported},
-    {"native_init", "()Z", (void*)android_location_GpsLocationProvider_init},
-    {"native_cleanup", "()V", (void*)android_location_GpsLocationProvider_cleanup},
-    {"native_set_position_mode", "(IIIII)Z", (void*)android_location_GpsLocationProvider_set_position_mode},
-    {"native_start", "()Z", (void*)android_location_GpsLocationProvider_start},
-    {"native_stop", "()Z", (void*)android_location_GpsLocationProvider_stop},
-    {"native_delete_aiding_data", "(I)V", (void*)android_location_GpsLocationProvider_delete_aiding_data},
-    {"native_read_sv_status", "([I[F[F[F[I)I", (void*)android_location_GpsLocationProvider_read_sv_status},
-    {"native_read_nmea", "([BI)I", (void*)android_location_GpsLocationProvider_read_nmea},
-    {"native_inject_time", "(JJI)V", (void*)android_location_GpsLocationProvider_inject_time},
-    {"native_inject_location", "(DDF)V", (void*)android_location_GpsLocationProvider_inject_location},
-    {"native_supports_xtra", "()Z", (void*)android_location_GpsLocationProvider_supports_xtra},
-    {"native_inject_xtra_data", "([BI)V", (void*)android_location_GpsLocationProvider_inject_xtra_data},
-    {"native_agps_data_conn_open", "(Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_agps_data_conn_open},
-    {"native_agps_data_conn_closed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_closed},
-    {"native_agps_data_conn_failed", "()V", (void*)android_location_GpsLocationProvider_agps_data_conn_failed},
-    {"native_agps_set_id","(ILjava/lang/String;)V",(void*)android_location_GpsLocationProvider_agps_set_id},
-    {"native_agps_set_ref_location_cellid","(IIIII)V",(void*)android_location_GpsLocationProvider_agps_set_reference_location_cellid},
-    {"native_set_agps_server", "(ILjava/lang/String;I)V", (void*)android_location_GpsLocationProvider_set_agps_server},
-    {"native_send_ni_response", "(II)V", (void*)android_location_GpsLocationProvider_send_ni_response},
-    {"native_agps_ni_message", "([BI)V", (void *)android_location_GpsLocationProvider_agps_send_ni_message},
-    {"native_get_internal_state", "()Ljava/lang/String;", (void*)android_location_GpsLocationProvider_get_internal_state},
-    {"native_update_network_state", "(ZIZZLjava/lang/String;Ljava/lang/String;)V", (void*)android_location_GpsLocationProvider_update_network_state },
-    {"native_is_geofence_supported", "()Z", (void*) android_location_GpsLocationProvider_is_geofence_supported},
-    {"native_add_geofence", "(IDDDIIII)Z", (void *)android_location_GpsLocationProvider_add_geofence},
-    {"native_remove_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_remove_geofence},
-    {"native_pause_geofence", "(I)Z", (void *)android_location_GpsLocationProvider_pause_geofence},
-    {"native_resume_geofence", "(II)Z", (void *)android_location_GpsLocationProvider_resume_geofence}
-};
-
-int register_android_server_location_GpsLocationProvider(JNIEnv* env)
-{
-    return jniRegisterNativeMethods(env, "com/android/server/location/GpsLocationProvider", sMethods, NELEM(sMethods));
-}
-
-} /* namespace android */
diff --git a/services/jni/onload.cpp b/services/jni/onload.cpp
deleted file mode 100644
index efc34a2..0000000
--- a/services/jni/onload.cpp
+++ /dev/null
@@ -1,73 +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.
- */
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include "utils/Log.h"
-#include "utils/misc.h"
-
-namespace android {
-int register_android_server_AlarmManagerService(JNIEnv* env);
-int register_android_server_ConsumerIrService(JNIEnv *env);
-int register_android_server_InputApplicationHandle(JNIEnv* env);
-int register_android_server_InputWindowHandle(JNIEnv* env);
-int register_android_server_InputManager(JNIEnv* env);
-int register_android_server_LightsService(JNIEnv* env);
-int register_android_server_PowerManagerService(JNIEnv* env);
-int register_android_server_SerialService(JNIEnv* env);
-int register_android_server_UsbDeviceManager(JNIEnv* env);
-int register_android_server_UsbHostManager(JNIEnv* env);
-int register_android_server_VibratorService(JNIEnv* env);
-int register_android_server_SystemServer(JNIEnv* env);
-int register_android_server_location_GpsLocationProvider(JNIEnv* env);
-int register_android_server_location_FlpHardwareProvider(JNIEnv* env);
-int register_android_server_connectivity_Vpn(JNIEnv* env);
-int register_android_server_AssetAtlasService(JNIEnv* env);
-};
-
-using namespace android;
-
-extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
-{
-    JNIEnv* env = NULL;
-    jint result = -1;
-
-    if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
-        ALOGE("GetEnv failed!");
-        return result;
-    }
-    ALOG_ASSERT(env, "Could not retrieve the env!");
-
-    register_android_server_PowerManagerService(env);
-    register_android_server_SerialService(env);
-    register_android_server_InputApplicationHandle(env);
-    register_android_server_InputWindowHandle(env);
-    register_android_server_InputManager(env);
-    register_android_server_LightsService(env);
-    register_android_server_AlarmManagerService(env);
-    register_android_server_UsbDeviceManager(env);
-    register_android_server_UsbHostManager(env);
-    register_android_server_VibratorService(env);
-    register_android_server_SystemServer(env);
-    register_android_server_location_GpsLocationProvider(env);
-    register_android_server_location_FlpHardwareProvider(env);
-    register_android_server_connectivity_Vpn(env);
-    register_android_server_AssetAtlasService(env);
-    register_android_server_ConsumerIrService(env);
-
-
-    return JNI_VERSION_1_4;
-}
diff --git a/services/print/Android.mk b/services/print/Android.mk
new file mode 100644
index 0000000..33604b7
--- /dev/null
+++ b/services/print/Android.mk
@@ -0,0 +1,10 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.print
+
+LOCAL_SRC_FILES += \
+      $(call all-java-files-under,java)
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/print/java/com/android/server/print/PrintManagerService.java b/services/print/java/com/android/server/print/PrintManagerService.java
new file mode 100644
index 0000000..c6fdbe5
--- /dev/null
+++ b/services/print/java/com/android/server/print/PrintManagerService.java
@@ -0,0 +1,689 @@
+/*
+ * Copyright (C) 2013 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.print;
+
+import android.Manifest;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+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.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.Process;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.print.IPrintDocumentAdapter;
+import android.print.IPrintJobStateChangeListener;
+import android.print.IPrintManager;
+import android.print.IPrinterDiscoveryObserver;
+import android.print.PrintAttributes;
+import android.print.PrintJobId;
+import android.print.PrintJobInfo;
+import android.print.PrinterId;
+import android.printservice.PrintServiceInfo;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.util.SparseArray;
+
+import com.android.internal.R;
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.os.BackgroundThread;
+import com.android.server.SystemService;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * SystemService wrapper for the PrintManager implementation. Publishes
+ * Context.PRINT_SERVICE.
+ * PrintManager implementation is contained within.
+ */
+
+public final class PrintManagerService extends SystemService {
+    private final PrintManagerImpl mPrintManagerImpl;
+
+    public PrintManagerService(Context context) {
+        super(context);
+        mPrintManagerImpl = new PrintManagerImpl(context);
+    }
+
+    @Override
+    public void onStart() {
+        publishBinderService(Context.PRINT_SERVICE, mPrintManagerImpl);
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+        if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
+            mPrintManagerImpl.systemRunning();
+        }
+    }
+
+    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 final Object mLock = new Object();
+
+        private final Context mContext;
+
+        private final SparseArray<UserState> mUserStates = new SparseArray<UserState>();
+
+        private int mCurrentUserId = UserHandle.USER_OWNER;
+
+        PrintManagerImpl(Context context) {
+            mContext = context;
+            registerContentObservers();
+            registerBoradcastReceivers();
+        }
+
+        public void systemRunning() {
+            BackgroundThread.getHandler().post(new Runnable() {
+                @Override
+                public void run() {
+                    final UserState userState;
+                    synchronized (mLock) {
+                        userState = getCurrentUserStateLocked();
+                        userState.updateIfNeededLocked();
+                    }
+                    // This is the first time we switch to this user after boot, so
+                    // now is the time to remove obsolete print jobs since they
+                    // are from the last boot and no application would query them.
+                    userState.removeObsoletePrintJobs();
+                }
+            });
+        }
+
+        @Override
+        public Bundle print(String printJobName, IPrintDocumentAdapter adapter,
+                PrintAttributes attributes, String packageName, int appId, int userId) {
+            final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            String resolvedPackageName = resolveCallingPackageNameEnforcingSecurity(packageName);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                return userState.print(printJobName, adapter, attributes,
+                        resolvedPackageName, resolvedAppId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public List<PrintJobInfo> getPrintJobInfos(int appId, int userId) {
+            final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                return userState.getPrintJobInfos(resolvedAppId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public PrintJobInfo getPrintJobInfo(PrintJobId printJobId, int appId, int userId) {
+            final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                return userState.getPrintJobInfo(printJobId, resolvedAppId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void cancelPrintJob(PrintJobId printJobId, int appId, int userId) {
+            final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.cancelPrintJob(printJobId, resolvedAppId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void restartPrintJob(PrintJobId printJobId, int appId, int userId) {
+            final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.restartPrintJob(printJobId, resolvedAppId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public List<PrintServiceInfo> getEnabledPrintServices(int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                return userState.getEnabledPrintServices();
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public List<PrintServiceInfo> getInstalledPrintServices(int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                return userState.getInstalledPrintServices();
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void createPrinterDiscoverySession(IPrinterDiscoveryObserver observer,
+                int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.createPrinterDiscoverySession(observer);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void destroyPrinterDiscoverySession(IPrinterDiscoveryObserver observer,
+                int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.destroyPrinterDiscoverySession(observer);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void startPrinterDiscovery(IPrinterDiscoveryObserver observer,
+                List<PrinterId> priorityList, int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.startPrinterDiscovery(observer, priorityList);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void stopPrinterDiscovery(IPrinterDiscoveryObserver observer, int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.stopPrinterDiscovery(observer);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void validatePrinters(List<PrinterId> printerIds, int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.validatePrinters(printerIds);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void startPrinterStateTracking(PrinterId printerId, int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.startPrinterStateTracking(printerId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void stopPrinterStateTracking(PrinterId printerId, int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.stopPrinterStateTracking(printerId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void addPrintJobStateChangeListener(IPrintJobStateChangeListener listener,
+                int appId, int userId) throws RemoteException {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final int resolvedAppId = resolveCallingAppEnforcingPermissions(appId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.addPrintJobStateChangeListener(listener, resolvedAppId);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void removePrintJobStateChangeListener(IPrintJobStateChangeListener listener,
+                int userId) {
+            final int resolvedUserId = resolveCallingUserEnforcingPermissions(userId);
+            final UserState userState;
+            synchronized (mLock) {
+                userState = getOrCreateUserStateLocked(resolvedUserId);
+            }
+            final long identity = Binder.clearCallingIdentity();
+            try {
+                userState.removePrintJobStateChangeListener(listener);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        @Override
+        public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (mContext.checkCallingOrSelfPermission(Manifest.permission.DUMP)
+                    != PackageManager.PERMISSION_GRANTED) {
+                pw.println("Permission Denial: can't dump PrintManager from from pid="
+                        + Binder.getCallingPid()
+                        + ", uid=" + Binder.getCallingUid());
+                return;
+            }
+
+            synchronized (mLock) {
+                final long identity = Binder.clearCallingIdentity();
+                try {
+                    pw.println("PRINT MANAGER STATE (dumpsys print)");
+                    final int userStateCount = mUserStates.size();
+                    for (int i = 0; i < userStateCount; i++) {
+                        UserState userState = mUserStates.valueAt(i);
+                        userState.dump(fd, pw, "");
+                        pw.println();
+                    }
+                } finally {
+                    Binder.restoreCallingIdentity(identity);
+                }
+            }
+        }
+
+        private void registerContentObservers() {
+            final Uri enabledPrintServicesUri = Settings.Secure.getUriFor(
+                    Settings.Secure.ENABLED_PRINT_SERVICES);
+
+            ContentObserver observer = new ContentObserver(BackgroundThread.getHandler()) {
+                @Override
+                public void onChange(boolean selfChange, Uri uri) {
+                    if (enabledPrintServicesUri.equals(uri)) {
+                        synchronized (mLock) {
+                            UserState userState = getCurrentUserStateLocked();
+                            userState.updateIfNeededLocked();
+                        }
+                    }
+                }
+            };
+
+            mContext.getContentResolver().registerContentObserver(enabledPrintServicesUri,
+                    false, observer, UserHandle.USER_ALL);
+        }
+
+        private void registerBoradcastReceivers() {
+            PackageMonitor monitor = new PackageMonitor() {
+                @Override
+                public boolean onPackageChanged(String packageName, int uid, String[] components) {
+                    synchronized (mLock) {
+                        UserState userState = getOrCreateUserStateLocked(getChangingUserId());
+                        Iterator<ComponentName> iterator = userState.getEnabledServices()
+                                .iterator();
+                        while (iterator.hasNext()) {
+                            ComponentName componentName = iterator.next();
+                            if (packageName.equals(componentName.getPackageName())) {
+                                userState.updateIfNeededLocked();
+                                return true;
+                            }
+                        }
+                    }
+                    return false;
+                }
+
+                @Override
+                public void onPackageRemoved(String packageName, int uid) {
+                    synchronized (mLock) {
+                        UserState userState = getOrCreateUserStateLocked(getChangingUserId());
+                        Iterator<ComponentName> iterator = userState.getEnabledServices()
+                                .iterator();
+                        while (iterator.hasNext()) {
+                            ComponentName componentName = iterator.next();
+                            if (packageName.equals(componentName.getPackageName())) {
+                                iterator.remove();
+                                persistComponentNamesToSettingLocked(
+                                        Settings.Secure.ENABLED_PRINT_SERVICES,
+                                        userState.getEnabledServices(), getChangingUserId());
+                                userState.updateIfNeededLocked();
+                                return;
+                            }
+                        }
+                    }
+                }
+
+                @Override
+                public boolean onHandleForceStop(Intent intent, String[] stoppedPackages,
+                        int uid, boolean doit) {
+                    synchronized (mLock) {
+                        UserState userState = getOrCreateUserStateLocked(getChangingUserId());
+                        boolean stoppedSomePackages = false;
+                        Iterator<ComponentName> iterator = userState.getEnabledServices()
+                                .iterator();
+                        while (iterator.hasNext()) {
+                            ComponentName componentName = iterator.next();
+                            String componentPackage = componentName.getPackageName();
+                            for (String stoppedPackage : stoppedPackages) {
+                                if (componentPackage.equals(stoppedPackage)) {
+                                    if (!doit) {
+                                        return true;
+                                    }
+                                    stoppedSomePackages = true;
+                                    break;
+                                }
+                            }
+                        }
+                        if (stoppedSomePackages) {
+                            userState.updateIfNeededLocked();
+                        }
+                        return false;
+                    }
+                }
+
+                @Override
+                public void onPackageAdded(String packageName, int uid) {
+                    Intent intent = new Intent(android.printservice.PrintService.SERVICE_INTERFACE);
+                    intent.setPackage(packageName);
+
+                    List<ResolveInfo> installedServices = mContext.getPackageManager()
+                            .queryIntentServicesAsUser(intent, PackageManager.GET_SERVICES,
+                                    getChangingUserId());
+
+                    if (installedServices == null) {
+                        return;
+                    }
+
+                    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);
+                        String label = serviceInfo.loadLabel(mContext.getPackageManager())
+                                .toString();
+                        showEnableInstalledPrintServiceNotification(component, label,
+                                getChangingUserId());
+                    }
+                }
+
+                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
+            monitor.register(mContext, BackgroundThread.getHandler().getLooper(),
+                    UserHandle.ALL, true);
+
+            // user changes
+            IntentFilter intentFilter = new IntentFilter();
+            intentFilter.addAction(Intent.ACTION_USER_SWITCHED);
+            intentFilter.addAction(Intent.ACTION_USER_REMOVED);
+
+            mContext.registerReceiverAsUser(new BroadcastReceiver() {
+                @Override
+                public void onReceive(Context context, Intent intent) {
+                    String action = intent.getAction();
+                    if (Intent.ACTION_USER_SWITCHED.equals(action)) {
+                        switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
+                    } else if (Intent.ACTION_USER_REMOVED.equals(action)) {
+                        removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0));
+                    }
+                }
+            }, UserHandle.ALL, intentFilter, null, BackgroundThread.getHandler());
+        }
+
+        private UserState getCurrentUserStateLocked() {
+            return getOrCreateUserStateLocked(mCurrentUserId);
+        }
+
+        private UserState getOrCreateUserStateLocked(int userId) {
+            UserState userState = mUserStates.get(userId);
+            if (userState == null) {
+                userState = new UserState(mContext, userId, mLock);
+                mUserStates.put(userId, userState);
+            }
+            return userState;
+        }
+
+        private void switchUser(int newUserId) {
+            UserState userState;
+            synchronized (mLock) {
+                if (newUserId == mCurrentUserId) {
+                    return;
+                }
+                mCurrentUserId = newUserId;
+                userState = mUserStates.get(mCurrentUserId);
+                if (userState == null) {
+                    userState = getCurrentUserStateLocked();
+                    userState.updateIfNeededLocked();
+                } else {
+                    userState.updateIfNeededLocked();
+                }
+            }
+            // This is the first time we switch to this user after boot, so
+            // now is the time to remove obsolete print jobs since they
+            // are from the last boot and no application would query them.
+            userState.removeObsoletePrintJobs();
+        }
+
+        private void removeUser(int removedUserId) {
+            synchronized (mLock) {
+                UserState userState = mUserStates.get(removedUserId);
+                if (userState != null) {
+                    userState.destroyLocked();
+                    mUserStates.remove(removedUserId);
+                }
+            }
+        }
+
+        private int resolveCallingAppEnforcingPermissions(int appId) {
+            final int callingUid = Binder.getCallingUid();
+            if (callingUid == 0 || callingUid == Process.SYSTEM_UID
+                    || callingUid == Process.SHELL_UID) {
+                return appId;
+            }
+            final int callingAppId = UserHandle.getAppId(callingUid);
+            if (appId == callingAppId) {
+                return appId;
+            }
+            if (mContext.checkCallingPermission(
+                    "com.android.printspooler.permission.ACCESS_ALL_PRINT_JOBS")
+                    != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("Call from app " + callingAppId + " as app "
+                        + appId + " without com.android.printspooler.permission"
+                        + ".ACCESS_ALL_PRINT_JOBS");
+            }
+            return appId;
+        }
+
+        private int resolveCallingUserEnforcingPermissions(int userId) {
+            final int callingUid = Binder.getCallingUid();
+            if (callingUid == 0 || callingUid == Process.SYSTEM_UID
+                    || callingUid == Process.SHELL_UID) {
+                return userId;
+            }
+            final int callingUserId = UserHandle.getUserId(callingUid);
+            if (callingUserId == userId) {
+                return userId;
+            }
+            if (mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+                    != PackageManager.PERMISSION_GRANTED
+                ||  mContext.checkCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS)
+                    != PackageManager.PERMISSION_GRANTED) {
+                if (userId == UserHandle.USER_CURRENT_OR_SELF) {
+                    return callingUserId;
+                }
+                throw new SecurityException("Call from user " + callingUserId + " as user "
+                    + userId + " without permission INTERACT_ACROSS_USERS or "
+                    + "INTERACT_ACROSS_USERS_FULL not allowed.");
+            }
+            if (userId == UserHandle.USER_CURRENT || userId == UserHandle.USER_CURRENT_OR_SELF) {
+                return mCurrentUserId;
+            }
+            throw new IllegalArgumentException("Calling user can be changed to only "
+                    + "UserHandle.USER_CURRENT or UserHandle.USER_CURRENT_OR_SELF.");
+        }
+
+        private String resolveCallingPackageNameEnforcingSecurity(String packageName) {
+            if (TextUtils.isEmpty(packageName)) {
+                return null;
+            }
+            String[] packages = mContext.getPackageManager().getPackagesForUid(
+                    Binder.getCallingUid());
+            final int packageCount = packages.length;
+            for (int i = 0; i < packageCount; i++) {
+                if (packageName.equals(packages[i])) {
+                    return packageName;
+                }
+            }
+            return null;
+        }
+
+        private void showEnableInstalledPrintServiceNotification(ComponentName component,
+                String label, int userId) {
+            UserHandle userHandle = new UserHandle(userId);
+
+            Intent intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
+            intent.putExtra(EXTRA_PRINT_SERVICE_COMPONENT_NAME, component.flattenToString());
+
+            PendingIntent pendingIntent = PendingIntent.getActivityAsUser(mContext, 0, intent,
+                    PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT, null,
+                    userHandle);
+
+            Notification.Builder builder = new Notification.Builder(mContext)
+                    .setSmallIcon(R.drawable.ic_print)
+                    .setContentTitle(mContext.getString(R.string.print_service_installed_title,
+                            label))
+                    .setContentText(mContext.getString(R.string.print_service_installed_message))
+                    .setContentIntent(pendingIntent)
+                    .setWhen(System.currentTimeMillis())
+                    .setAutoCancel(true)
+                    .setShowWhen(true);
+
+            NotificationManager notificationManager = (NotificationManager) mContext
+                    .getSystemService(Context.NOTIFICATION_SERVICE);
+
+            String notificationTag = getClass().getName() + ":" + component.flattenToString();
+            notificationManager.notifyAsUser(notificationTag, 0, builder.build(),
+                    userHandle);
+        }
+    }
+}
diff --git a/services/java/com/android/server/print/RemotePrintService.java b/services/print/java/com/android/server/print/RemotePrintService.java
similarity index 100%
rename from services/java/com/android/server/print/RemotePrintService.java
rename to services/print/java/com/android/server/print/RemotePrintService.java
diff --git a/services/java/com/android/server/print/RemotePrintSpooler.java b/services/print/java/com/android/server/print/RemotePrintSpooler.java
similarity index 100%
rename from services/java/com/android/server/print/RemotePrintSpooler.java
rename to services/print/java/com/android/server/print/RemotePrintSpooler.java
diff --git a/services/java/com/android/server/print/UserState.java b/services/print/java/com/android/server/print/UserState.java
similarity index 100%
rename from services/java/com/android/server/print/UserState.java
rename to services/print/java/com/android/server/print/UserState.java
diff --git a/services/tests/Android.mk b/services/tests/Android.mk
new file mode 100644
index 0000000..40369ee
--- /dev/null
+++ b/services/tests/Android.mk
@@ -0,0 +1,3 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(call all-makefiles-under, $(LOCAL_PATH))
diff --git a/services/tests/servicestests/src/com/android/server/EntropyMixerTest.java b/services/tests/servicestests/src/com/android/server/EntropyMixerTest.java
index 58d6dae..50e7a03 100644
--- a/services/tests/servicestests/src/com/android/server/EntropyMixerTest.java
+++ b/services/tests/servicestests/src/com/android/server/EntropyMixerTest.java
@@ -34,7 +34,7 @@
         assertEquals(0, FileUtils.readTextFile(file, 0, null).length());
 
         // The constructor has the side effect of writing to file
-        new EntropyMixer(getContext(), "/dev/null", file.getCanonicalPath());
+        new EntropyMixer(getContext(), "/dev/null", file.getCanonicalPath(), "/dev/null");
 
         assertTrue(FileUtils.readTextFile(file, 0, null).length() > 0);
     }
diff --git a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
index 56dd7c4..7a30d31 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java
@@ -17,6 +17,7 @@
 package com.android.server;
 
 import android.content.Context;
+import android.net.LinkAddress;
 import android.net.LocalSocket;
 import android.net.LocalServerSocket;
 import android.os.Binder;
@@ -157,18 +158,61 @@
          * IP address changes.
          */
         sendMessage("614 Address updated fe80::1/64 wlan0 128 253");
-        expectSoon(observer).addressUpdated("fe80::1/64", "wlan0", 128, 253);
+        expectSoon(observer).addressUpdated("wlan0", new LinkAddress("fe80::1/64", 128, 253));
 
-        // There is no "added".
+        // There is no "added", so we take this as "removed".
         sendMessage("614 Address added fe80::1/64 wlan0 128 253");
-        expectSoon(observer).addressRemoved("fe80::1/64", "wlan0", 128, 253);
+        expectSoon(observer).addressRemoved("wlan0", new LinkAddress("fe80::1/64", 128, 253));
 
         sendMessage("614 Address removed 2001:db8::1/64 wlan0 1 0");
-        expectSoon(observer).addressRemoved("2001:db8::1/64", "wlan0", 1, 0);
+        expectSoon(observer).addressRemoved("wlan0", new LinkAddress("2001:db8::1/64", 1, 0));
 
-        sendMessage("666 Address added 2001:db8::1/64 wlan0 1 0");
+        sendMessage("614 Address removed 2001:db8::1/64 wlan0 1");
+        // Not enough arguments.
+
+        sendMessage("666 Address removed 2001:db8::1/64 wlan0 1 0");
         // Invalid code.
 
+
+        /**
+         * DNS information broadcasts.
+         */
+        sendMessage("615 DnsInfo servers rmnet_usb0 3600 2001:db8::1");
+        expectSoon(observer).interfaceDnsServerInfo("rmnet_usb0", 3600,
+                new String[]{"2001:db8::1"});
+
+        sendMessage("615 DnsInfo servers wlan0 14400 2001:db8::1,2001:db8::2");
+        expectSoon(observer).interfaceDnsServerInfo("wlan0", 14400,
+                new String[]{"2001:db8::1", "2001:db8::2"});
+
+        // We don't check for negative lifetimes, only for parse errors.
+        sendMessage("615 DnsInfo servers wlan0 -3600 ::1");
+        expectSoon(observer).interfaceDnsServerInfo("wlan0", -3600,
+                new String[]{"::1"});
+
+        sendMessage("615 DnsInfo servers wlan0 SIXHUNDRED ::1");
+        // Non-numeric lifetime.
+
+        sendMessage("615 DnsInfo servers wlan0 2001:db8::1");
+        // Missing lifetime.
+
+        sendMessage("615 DnsInfo servers wlan0 3600");
+        // No servers.
+
+        sendMessage("615 DnsInfo servers 3600 wlan0 2001:db8::1,2001:db8::2");
+        // Non-numeric lifetime.
+
+        sendMessage("615 DnsInfo wlan0 7200 2001:db8::1,2001:db8::2");
+        // Invalid tokens.
+
+        sendMessage("666 DnsInfo servers wlan0 5400 2001:db8::1");
+        // Invalid code.
+
+        // No syntax checking on the addresses.
+        sendMessage("615 DnsInfo servers wlan0 600 ,::,,foo,::1,");
+        expectSoon(observer).interfaceDnsServerInfo("wlan0", 600,
+                new String[]{"", "::", "", "foo", "::1"});
+
         // Make sure nothing else was called.
         verifyNoMoreInteractions(observer);
     }
diff --git a/services/usb/Android.mk b/services/usb/Android.mk
new file mode 100644
index 0000000..feabf0a
--- /dev/null
+++ b/services/usb/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := services.usb
+
+LOCAL_SRC_FILES += \
+      $(call all-java-files-under,java)
+
+LOCAL_JAVA_LIBRARIES := services.core
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
diff --git a/services/java/com/android/server/usb/UsbDebuggingManager.java b/services/usb/java/com/android/server/usb/UsbDebuggingManager.java
similarity index 100%
rename from services/java/com/android/server/usb/UsbDebuggingManager.java
rename to services/usb/java/com/android/server/usb/UsbDebuggingManager.java
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
new file mode 100644
index 0000000..bef33b9
--- /dev/null
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -0,0 +1,905 @@
+/*
+ * 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 an
+ * limitations under the License.
+ */
+
+package com.android.server.usb;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.hardware.usb.UsbAccessory;
+import android.hardware.usb.UsbManager;
+import android.os.FileUtils;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.ParcelFileDescriptor;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.os.UEventObserver;
+import android.os.UserHandle;
+import android.os.storage.StorageManager;
+import android.os.storage.StorageVolume;
+import android.provider.Settings;
+import android.util.Pair;
+import android.util.Slog;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.server.FgThread;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Scanner;
+
+/**
+ * UsbDeviceManager manages USB state in device mode.
+ */
+public class UsbDeviceManager {
+
+    private static final String TAG = UsbDeviceManager.class.getSimpleName();
+    private static final boolean DEBUG = false;
+
+    private static final String USB_STATE_MATCH =
+            "DEVPATH=/devices/virtual/android_usb/android0";
+    private static final String ACCESSORY_START_MATCH =
+            "DEVPATH=/devices/virtual/misc/usb_accessory";
+    private static final String FUNCTIONS_PATH =
+            "/sys/class/android_usb/android0/functions";
+    private static final String STATE_PATH =
+            "/sys/class/android_usb/android0/state";
+    private static final String MASS_STORAGE_FILE_PATH =
+            "/sys/class/android_usb/android0/f_mass_storage/lun/file";
+    private static final String RNDIS_ETH_ADDR_PATH =
+            "/sys/class/android_usb/android0/f_rndis/ethaddr";
+    private static final String AUDIO_SOURCE_PCM_PATH =
+            "/sys/class/android_usb/android0/f_audio_source/pcm";
+
+    private static final int MSG_UPDATE_STATE = 0;
+    private static final int MSG_ENABLE_ADB = 1;
+    private static final int MSG_SET_CURRENT_FUNCTIONS = 2;
+    private static final int MSG_SYSTEM_READY = 3;
+    private static final int MSG_BOOT_COMPLETED = 4;
+    private static final int MSG_USER_SWITCHED = 5;
+
+    private static final int AUDIO_MODE_NONE = 0;
+    private static final int AUDIO_MODE_SOURCE = 1;
+
+    // Delay for debouncing USB disconnects.
+    // We often get rapid connect/disconnect events when enabling USB functions,
+    // which need debouncing.
+    private static final int UPDATE_DELAY = 1000;
+
+    // Time we received a request to enter USB accessory mode
+    private long mAccessoryModeRequestTime = 0;
+
+    // Timeout for entering USB request mode.
+    // Request is cancelled if host does not configure device within 10 seconds.
+    private static final int ACCESSORY_REQUEST_TIMEOUT = 10 * 1000;
+
+    private static final String BOOT_MODE_PROPERTY = "ro.bootmode";
+
+    private UsbHandler mHandler;
+    private boolean mBootCompleted;
+
+    private final Object mLock = new Object();
+
+    private final Context mContext;
+    private final ContentResolver mContentResolver;
+    @GuardedBy("mLock")
+    private UsbSettingsManager mCurrentSettings;
+    private NotificationManager mNotificationManager;
+    private final boolean mHasUsbAccessory;
+    private boolean mUseUsbNotification;
+    private boolean mAdbEnabled;
+    private boolean mAudioSourceEnabled;
+    private Map<String, List<Pair<String, String>>> mOemModeMap;
+    private String[] mAccessoryStrings;
+    private UsbDebuggingManager mDebuggingManager;
+
+    private class AdbSettingsObserver extends ContentObserver {
+        public AdbSettingsObserver() {
+            super(null);
+        }
+        @Override
+        public void onChange(boolean selfChange) {
+            boolean enable = (Settings.Global.getInt(mContentResolver,
+                    Settings.Global.ADB_ENABLED, 0) > 0);
+            mHandler.sendMessage(MSG_ENABLE_ADB, enable);
+        }
+    }
+
+    /*
+     * Listens for uevent messages from the kernel to monitor the USB state
+     */
+    private final UEventObserver mUEventObserver = new UEventObserver() {
+        @Override
+        public void onUEvent(UEventObserver.UEvent event) {
+            if (DEBUG) Slog.v(TAG, "USB UEVENT: " + event.toString());
+
+            String state = event.get("USB_STATE");
+            String accessory = event.get("ACCESSORY");
+            if (state != null) {
+                mHandler.updateState(state);
+            } else if ("START".equals(accessory)) {
+                if (DEBUG) Slog.d(TAG, "got accessory start");
+                startAccessoryMode();
+            }
+        }
+    };
+
+    public UsbDeviceManager(Context context) {
+        mContext = context;
+        mContentResolver = context.getContentResolver();
+        PackageManager pm = mContext.getPackageManager();
+        mHasUsbAccessory = pm.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
+        initRndisAddress();
+
+        readOemUsbOverrideConfig();
+
+        mHandler = new UsbHandler(FgThread.get().getLooper());
+
+        if (nativeIsStartRequested()) {
+            if (DEBUG) Slog.d(TAG, "accessory attached at boot");
+            startAccessoryMode();
+        }
+
+        boolean secureAdbEnabled = SystemProperties.getBoolean("ro.adb.secure", false);
+        boolean dataEncrypted = "1".equals(SystemProperties.get("vold.decrypt"));
+        if (secureAdbEnabled && !dataEncrypted) {
+            mDebuggingManager = new UsbDebuggingManager(context);
+        }
+    }
+
+    public void setCurrentSettings(UsbSettingsManager settings) {
+        synchronized (mLock) {
+            mCurrentSettings = settings;
+        }
+    }
+
+    private UsbSettingsManager getCurrentSettings() {
+        synchronized (mLock) {
+            return mCurrentSettings;
+        }
+    }
+
+    public void systemReady() {
+        if (DEBUG) Slog.d(TAG, "systemReady");
+
+        mNotificationManager = (NotificationManager)
+                mContext.getSystemService(Context.NOTIFICATION_SERVICE);
+
+        // We do not show the USB notification if the primary volume supports mass storage.
+        // The legacy mass storage UI will be used instead.
+        boolean massStorageSupported = false;
+        final StorageManager storageManager = StorageManager.from(mContext);
+        final StorageVolume primary = storageManager.getPrimaryVolume();
+        massStorageSupported = primary != null && primary.allowMassStorage();
+        mUseUsbNotification = !massStorageSupported;
+
+        // make sure the ADB_ENABLED setting value matches the current state
+        Settings.Global.putInt(mContentResolver, Settings.Global.ADB_ENABLED, mAdbEnabled ? 1 : 0);
+
+        mHandler.sendEmptyMessage(MSG_SYSTEM_READY);
+    }
+
+    private void startAccessoryMode() {
+        if (!mHasUsbAccessory) return;
+
+        mAccessoryStrings = nativeGetAccessoryStrings();
+        boolean enableAudio = (nativeGetAudioMode() == AUDIO_MODE_SOURCE);
+        // don't start accessory mode if our mandatory strings have not been set
+        boolean enableAccessory = (mAccessoryStrings != null &&
+                        mAccessoryStrings[UsbAccessory.MANUFACTURER_STRING] != null &&
+                        mAccessoryStrings[UsbAccessory.MODEL_STRING] != null);
+        String functions = null;
+
+        if (enableAccessory && enableAudio) {
+            functions = UsbManager.USB_FUNCTION_ACCESSORY + ","
+                    + UsbManager.USB_FUNCTION_AUDIO_SOURCE;
+        } else if (enableAccessory) {
+            functions = UsbManager.USB_FUNCTION_ACCESSORY;
+        } else if (enableAudio) {
+            functions = UsbManager.USB_FUNCTION_AUDIO_SOURCE;
+        }
+
+        if (functions != null) {
+            mAccessoryModeRequestTime = SystemClock.elapsedRealtime();
+            setCurrentFunctions(functions, false);
+        }
+    }
+
+    private static void initRndisAddress() {
+        // configure RNDIS ethernet address based on our serial number using the same algorithm
+        // we had been previously using in kernel board files
+        final int ETH_ALEN = 6;
+        int address[] = new int[ETH_ALEN];
+        // first byte is 0x02 to signify a locally administered address
+        address[0] = 0x02;
+
+        String serial = SystemProperties.get("ro.serialno", "1234567890ABCDEF");
+        int serialLength = serial.length();
+        // XOR the USB serial across the remaining 5 bytes
+        for (int i = 0; i < serialLength; i++) {
+            address[i % (ETH_ALEN - 1) + 1] ^= (int)serial.charAt(i);
+        }
+        String addrString = String.format(Locale.US, "%02X:%02X:%02X:%02X:%02X:%02X",
+            address[0], address[1], address[2], address[3], address[4], address[5]);
+        try {
+            FileUtils.stringToFile(RNDIS_ETH_ADDR_PATH, addrString);
+        } catch (IOException e) {
+           Slog.e(TAG, "failed to write to " + RNDIS_ETH_ADDR_PATH);
+        }
+    }
+
+     private static String addFunction(String functions, String function) {
+         if ("none".equals(functions)) {
+             return function;
+         }
+        if (!containsFunction(functions, function)) {
+            if (functions.length() > 0) {
+                functions += ",";
+            }
+            functions += function;
+        }
+        return functions;
+    }
+
+    private static String removeFunction(String functions, String function) {
+        String[] split = functions.split(",");
+        for (int i = 0; i < split.length; i++) {
+            if (function.equals(split[i])) {
+                split[i] = null;
+            }
+        }
+        if (split.length == 1 && split[0] == null) {
+            return "none";
+        }
+        StringBuilder builder = new StringBuilder();
+         for (int i = 0; i < split.length; i++) {
+            String s = split[i];
+            if (s != null) {
+                if (builder.length() > 0) {
+                    builder.append(",");
+                }
+                builder.append(s);
+            }
+        }
+        return builder.toString();
+    }
+
+    private static boolean containsFunction(String functions, String function) {
+        int index = functions.indexOf(function);
+        if (index < 0) return false;
+        if (index > 0 && functions.charAt(index - 1) != ',') return false;
+        int charAfter = index + function.length();
+        if (charAfter < functions.length() && functions.charAt(charAfter) != ',') return false;
+        return true;
+    }
+
+    private final class UsbHandler extends Handler {
+
+        // current USB state
+        private boolean mConnected;
+        private boolean mConfigured;
+        private String mCurrentFunctions;
+        private String mDefaultFunctions;
+        private UsbAccessory mCurrentAccessory;
+        private int mUsbNotificationId;
+        private boolean mAdbNotificationShown;
+        private int mCurrentUser = UserHandle.USER_NULL;
+
+        private final BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                if (DEBUG) Slog.d(TAG, "boot completed");
+                mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED);
+            }
+        };
+
+        private final BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+                mHandler.obtainMessage(MSG_USER_SWITCHED, userId, 0).sendToTarget();
+            }
+        };
+
+        public UsbHandler(Looper looper) {
+            super(looper);
+            try {
+                // persist.sys.usb.config should never be unset.  But if it is, set it to "adb"
+                // so we have a chance of debugging what happened.
+                mDefaultFunctions = SystemProperties.get("persist.sys.usb.config", "adb");
+
+                // Check if USB mode needs to be overridden depending on OEM specific bootmode.
+                mDefaultFunctions = processOemUsbOverride(mDefaultFunctions);
+
+                // sanity check the sys.usb.config system property
+                // this may be necessary if we crashed while switching USB configurations
+                String config = SystemProperties.get("sys.usb.config", "none");
+                if (!config.equals(mDefaultFunctions)) {
+                    Slog.w(TAG, "resetting config to persistent property: " + mDefaultFunctions);
+                    SystemProperties.set("sys.usb.config", mDefaultFunctions);
+                }
+
+                mCurrentFunctions = mDefaultFunctions;
+                String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
+                updateState(state);
+                mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
+
+                // Upgrade step for previous versions that used persist.service.adb.enable
+                String value = SystemProperties.get("persist.service.adb.enable", "");
+                if (value.length() > 0) {
+                    char enable = value.charAt(0);
+                    if (enable == '1') {
+                        setAdbEnabled(true);
+                    } else if (enable == '0') {
+                        setAdbEnabled(false);
+                    }
+                    SystemProperties.set("persist.service.adb.enable", "");
+                }
+
+                // register observer to listen for settings changes
+                mContentResolver.registerContentObserver(
+                        Settings.Global.getUriFor(Settings.Global.ADB_ENABLED),
+                                false, new AdbSettingsObserver());
+
+                // Watch for USB configuration changes
+                mUEventObserver.startObserving(USB_STATE_MATCH);
+                mUEventObserver.startObserving(ACCESSORY_START_MATCH);
+
+                mContext.registerReceiver(
+                        mBootCompletedReceiver, new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
+                mContext.registerReceiver(
+                        mUserSwitchedReceiver, new IntentFilter(Intent.ACTION_USER_SWITCHED));
+            } catch (Exception e) {
+                Slog.e(TAG, "Error initializing UsbHandler", e);
+            }
+        }
+
+        public void sendMessage(int what, boolean arg) {
+            removeMessages(what);
+            Message m = Message.obtain(this, what);
+            m.arg1 = (arg ? 1 : 0);
+            sendMessage(m);
+        }
+
+        public void sendMessage(int what, Object arg) {
+            removeMessages(what);
+            Message m = Message.obtain(this, what);
+            m.obj = arg;
+            sendMessage(m);
+        }
+
+        public void sendMessage(int what, Object arg0, boolean arg1) {
+            removeMessages(what);
+            Message m = Message.obtain(this, what);
+            m.obj = arg0;
+            m.arg1 = (arg1 ? 1 : 0);
+            sendMessage(m);
+        }
+
+        public void updateState(String state) {
+            int connected, configured;
+
+            if ("DISCONNECTED".equals(state)) {
+                connected = 0;
+                configured = 0;
+            } else if ("CONNECTED".equals(state)) {
+                connected = 1;
+                configured = 0;
+            } else if ("CONFIGURED".equals(state)) {
+                connected = 1;
+                configured = 1;
+            } else {
+                Slog.e(TAG, "unknown state " + state);
+                return;
+            }
+            removeMessages(MSG_UPDATE_STATE);
+            Message msg = Message.obtain(this, MSG_UPDATE_STATE);
+            msg.arg1 = connected;
+            msg.arg2 = configured;
+            // debounce disconnects to avoid problems bringing up USB tethering
+            sendMessageDelayed(msg, (connected == 0) ? UPDATE_DELAY : 0);
+        }
+
+        private boolean waitForState(String state) {
+            // wait for the transition to complete.
+            // give up after 1 second.
+            for (int i = 0; i < 20; i++) {
+                // State transition is done when sys.usb.state is set to the new configuration
+                if (state.equals(SystemProperties.get("sys.usb.state"))) return true;
+                SystemClock.sleep(50);
+            }
+            Slog.e(TAG, "waitForState(" + state + ") FAILED");
+            return false;
+        }
+
+        private boolean setUsbConfig(String config) {
+            if (DEBUG) Slog.d(TAG, "setUsbConfig(" + config + ")");
+            // set the new configuration
+            SystemProperties.set("sys.usb.config", config);
+            return waitForState(config);
+        }
+
+        private void setAdbEnabled(boolean enable) {
+            if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable);
+            if (enable != mAdbEnabled) {
+                mAdbEnabled = enable;
+                // Due to the persist.sys.usb.config property trigger, changing adb state requires
+                // switching to default function
+                setEnabledFunctions(mDefaultFunctions, true);
+                updateAdbNotification();
+            }
+            if (mDebuggingManager != null) {
+                mDebuggingManager.setAdbEnabled(mAdbEnabled);
+            }
+        }
+
+        private void setEnabledFunctions(String functions, boolean makeDefault) {
+            if (DEBUG) Slog.d(TAG, "setEnabledFunctions " + functions
+                    + " makeDefault: " + makeDefault);
+
+            // Do not update persystent.sys.usb.config if the device is booted up
+            // with OEM specific mode.
+            if (functions != null && makeDefault && !needsOemUsbOverride()) {
+
+                if (mAdbEnabled) {
+                    functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
+                } else {
+                    functions = removeFunction(functions, UsbManager.USB_FUNCTION_ADB);
+                }
+                if (!mDefaultFunctions.equals(functions)) {
+                    if (!setUsbConfig("none")) {
+                        Slog.e(TAG, "Failed to disable USB");
+                        // revert to previous configuration if we fail
+                        setUsbConfig(mCurrentFunctions);
+                        return;
+                    }
+                    // setting this property will also change the current USB state
+                    // via a property trigger
+                    SystemProperties.set("persist.sys.usb.config", functions);
+                    if (waitForState(functions)) {
+                        mCurrentFunctions = functions;
+                        mDefaultFunctions = functions;
+                    } else {
+                        Slog.e(TAG, "Failed to switch persistent USB config to " + functions);
+                        // revert to previous configuration if we fail
+                        SystemProperties.set("persist.sys.usb.config", mDefaultFunctions);
+                    }
+                }
+            } else {
+                if (functions == null) {
+                    functions = mDefaultFunctions;
+                }
+
+                // Override with bootmode specific usb mode if needed
+                functions = processOemUsbOverride(functions);
+
+                if (mAdbEnabled) {
+                    functions = addFunction(functions, UsbManager.USB_FUNCTION_ADB);
+                } else {
+                    functions = removeFunction(functions, UsbManager.USB_FUNCTION_ADB);
+                }
+                if (!mCurrentFunctions.equals(functions)) {
+                    if (!setUsbConfig("none")) {
+                        Slog.e(TAG, "Failed to disable USB");
+                        // revert to previous configuration if we fail
+                        setUsbConfig(mCurrentFunctions);
+                        return;
+                    }
+                    if (setUsbConfig(functions)) {
+                        mCurrentFunctions = functions;
+                    } else {
+                        Slog.e(TAG, "Failed to switch USB config to " + functions);
+                        // revert to previous configuration if we fail
+                        setUsbConfig(mCurrentFunctions);
+                    }
+                }
+            }
+        }
+
+        private void updateCurrentAccessory() {
+            // We are entering accessory mode if we have received a request from the host
+            // and the request has not timed out yet.
+            boolean enteringAccessoryMode =
+                    mAccessoryModeRequestTime > 0 &&
+                        SystemClock.elapsedRealtime() <
+                            mAccessoryModeRequestTime + ACCESSORY_REQUEST_TIMEOUT;
+
+            if (mConfigured && enteringAccessoryMode) {
+                // successfully entered accessory mode
+                mAccessoryModeRequestTime = 0;
+
+                if (mAccessoryStrings != null) {
+                    mCurrentAccessory = new UsbAccessory(mAccessoryStrings);
+                    Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);
+                    // defer accessoryAttached if system is not ready
+                    if (mBootCompleted) {
+                        getCurrentSettings().accessoryAttached(mCurrentAccessory);
+                    } // else handle in mBootCompletedReceiver
+                } else {
+                    Slog.e(TAG, "nativeGetAccessoryStrings failed");
+                }
+            } else if (!enteringAccessoryMode) {
+                // make sure accessory mode is off
+                // and restore default functions
+                Slog.d(TAG, "exited USB accessory mode");
+                setEnabledFunctions(mDefaultFunctions, false);
+
+                if (mCurrentAccessory != null) {
+                    if (mBootCompleted) {
+                        getCurrentSettings().accessoryDetached(mCurrentAccessory);
+                    }
+                    mCurrentAccessory = null;
+                    mAccessoryStrings = null;
+                }
+            }
+        }
+
+        private void updateUsbState() {
+            // send a sticky broadcast containing current USB state
+            Intent intent = new Intent(UsbManager.ACTION_USB_STATE);
+            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+            intent.putExtra(UsbManager.USB_CONNECTED, mConnected);
+            intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured);
+
+            if (mCurrentFunctions != null) {
+                String[] functions = mCurrentFunctions.split(",");
+                for (int i = 0; i < functions.length; i++) {
+                    intent.putExtra(functions[i], true);
+                }
+            }
+
+            if (DEBUG) Slog.d(TAG, "broadcasting " + intent + " connected: " + mConnected
+                                    + " configured: " + mConfigured);
+            mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
+        }
+
+        private void updateAudioSourceFunction() {
+            boolean enabled = containsFunction(mCurrentFunctions,
+                    UsbManager.USB_FUNCTION_AUDIO_SOURCE);
+            if (enabled != mAudioSourceEnabled) {
+                // send a sticky broadcast containing current USB state
+                Intent intent = new Intent(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG);
+                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+                intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+                intent.putExtra("state", (enabled ? 1 : 0));
+                if (enabled) {
+                    try {
+                        Scanner scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH));
+                        int card = scanner.nextInt();
+                        int device = scanner.nextInt();
+                        intent.putExtra("card", card);
+                        intent.putExtra("device", device);
+                    } catch (FileNotFoundException e) {
+                        Slog.e(TAG, "could not open audio source PCM file", e);
+                    }
+                }
+                mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
+                mAudioSourceEnabled = enabled;
+            }
+        }
+
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case MSG_UPDATE_STATE:
+                    mConnected = (msg.arg1 == 1);
+                    mConfigured = (msg.arg2 == 1);
+                    updateUsbNotification();
+                    updateAdbNotification();
+                    if (containsFunction(mCurrentFunctions,
+                            UsbManager.USB_FUNCTION_ACCESSORY)) {
+                        updateCurrentAccessory();
+                    } else if (!mConnected) {
+                        // restore defaults when USB is disconnected
+                        setEnabledFunctions(mDefaultFunctions, false);
+                    }
+                    if (mBootCompleted) {
+                        updateUsbState();
+                        updateAudioSourceFunction();
+                    }
+                    break;
+                case MSG_ENABLE_ADB:
+                    setAdbEnabled(msg.arg1 == 1);
+                    break;
+                case MSG_SET_CURRENT_FUNCTIONS:
+                    String functions = (String)msg.obj;
+                    boolean makeDefault = (msg.arg1 == 1);
+                    setEnabledFunctions(functions, makeDefault);
+                    break;
+                case MSG_SYSTEM_READY:
+                    updateUsbNotification();
+                    updateAdbNotification();
+                    updateUsbState();
+                    updateAudioSourceFunction();
+                    break;
+                case MSG_BOOT_COMPLETED:
+                    mBootCompleted = true;
+                    if (mCurrentAccessory != null) {
+                        getCurrentSettings().accessoryAttached(mCurrentAccessory);
+                    }
+                    if (mDebuggingManager != null) {
+                        mDebuggingManager.setAdbEnabled(mAdbEnabled);
+                    }
+                    break;
+                case MSG_USER_SWITCHED: {
+                    final boolean mtpActive =
+                            containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)
+                            || containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP);
+                    if (mtpActive && mCurrentUser != UserHandle.USER_NULL) {
+                        Slog.v(TAG, "Current user switched; resetting USB host stack for MTP");
+                        setUsbConfig("none");
+                        setUsbConfig(mCurrentFunctions);
+                    }
+                    mCurrentUser = msg.arg1;
+                    break;
+                }
+            }
+        }
+
+        public UsbAccessory getCurrentAccessory() {
+            return mCurrentAccessory;
+        }
+
+        private void updateUsbNotification() {
+            if (mNotificationManager == null || !mUseUsbNotification) return;
+            int id = 0;
+            Resources r = mContext.getResources();
+            if (mConnected) {
+                if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP)) {
+                    id = com.android.internal.R.string.usb_mtp_notification_title;
+                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP)) {
+                    id = com.android.internal.R.string.usb_ptp_notification_title;
+                } else if (containsFunction(mCurrentFunctions,
+                        UsbManager.USB_FUNCTION_MASS_STORAGE)) {
+                    id = com.android.internal.R.string.usb_cd_installer_notification_title;
+                } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
+                    id = com.android.internal.R.string.usb_accessory_notification_title;
+                } else {
+                    // There is a different notification for USB tethering so we don't need one here
+                    //if (!containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_RNDIS)) {
+                    //    Slog.e(TAG, "No known USB function in updateUsbNotification");
+                    //}
+                }
+            }
+            if (id != mUsbNotificationId) {
+                // clear notification if title needs changing
+                if (mUsbNotificationId != 0) {
+                    mNotificationManager.cancelAsUser(null, mUsbNotificationId,
+                            UserHandle.ALL);
+                    mUsbNotificationId = 0;
+                }
+                if (id != 0) {
+                    CharSequence message = r.getText(
+                            com.android.internal.R.string.usb_notification_message);
+                    CharSequence title = r.getText(id);
+
+                    Notification notification = new Notification();
+                    notification.icon = com.android.internal.R.drawable.stat_sys_data_usb;
+                    notification.when = 0;
+                    notification.flags = Notification.FLAG_ONGOING_EVENT;
+                    notification.tickerText = title;
+                    notification.defaults = 0; // please be quiet
+                    notification.sound = null;
+                    notification.vibrate = null;
+                    notification.priority = Notification.PRIORITY_MIN;
+
+                    Intent intent = Intent.makeRestartActivityTask(
+                            new ComponentName("com.android.settings",
+                                    "com.android.settings.UsbSettings"));
+                    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
+                            intent, 0, null, UserHandle.CURRENT);
+                    notification.setLatestEventInfo(mContext, title, message, pi);
+                    mNotificationManager.notifyAsUser(null, id, notification,
+                            UserHandle.ALL);
+                    mUsbNotificationId = id;
+                }
+            }
+        }
+
+        private void updateAdbNotification() {
+            if (mNotificationManager == null) return;
+            final int id = com.android.internal.R.string.adb_active_notification_title;
+            if (mAdbEnabled && mConnected) {
+                if ("0".equals(SystemProperties.get("persist.adb.notify"))) return;
+
+                if (!mAdbNotificationShown) {
+                    Resources r = mContext.getResources();
+                    CharSequence title = r.getText(id);
+                    CharSequence message = r.getText(
+                            com.android.internal.R.string.adb_active_notification_message);
+
+                    Notification notification = new Notification();
+                    notification.icon = com.android.internal.R.drawable.stat_sys_adb;
+                    notification.when = 0;
+                    notification.flags = Notification.FLAG_ONGOING_EVENT;
+                    notification.tickerText = title;
+                    notification.defaults = 0; // please be quiet
+                    notification.sound = null;
+                    notification.vibrate = null;
+                    notification.priority = Notification.PRIORITY_LOW;
+
+                    Intent intent = Intent.makeRestartActivityTask(
+                            new ComponentName("com.android.settings",
+                                    "com.android.settings.DevelopmentSettings"));
+                    PendingIntent pi = PendingIntent.getActivityAsUser(mContext, 0,
+                            intent, 0, null, UserHandle.CURRENT);
+                    notification.setLatestEventInfo(mContext, title, message, pi);
+                    mAdbNotificationShown = true;
+                    mNotificationManager.notifyAsUser(null, id, notification,
+                            UserHandle.ALL);
+                }
+            } else if (mAdbNotificationShown) {
+                mAdbNotificationShown = false;
+                mNotificationManager.cancelAsUser(null, id, UserHandle.ALL);
+            }
+        }
+
+        public void dump(FileDescriptor fd, PrintWriter pw) {
+            pw.println("  USB Device State:");
+            pw.println("    Current Functions: " + mCurrentFunctions);
+            pw.println("    Default Functions: " + mDefaultFunctions);
+            pw.println("    mConnected: " + mConnected);
+            pw.println("    mConfigured: " + mConfigured);
+            pw.println("    mCurrentAccessory: " + mCurrentAccessory);
+            try {
+                pw.println("    Kernel state: "
+                        + FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim());
+                pw.println("    Kernel function list: "
+                        + FileUtils.readTextFile(new File(FUNCTIONS_PATH), 0, null).trim());
+                pw.println("    Mass storage backing file: "
+                        + FileUtils.readTextFile(new File(MASS_STORAGE_FILE_PATH), 0, null).trim());
+            } catch (IOException e) {
+                pw.println("IOException: " + e);
+            }
+        }
+    }
+
+    /* returns the currently attached USB accessory */
+    public UsbAccessory getCurrentAccessory() {
+        return mHandler.getCurrentAccessory();
+    }
+
+    /* opens the currently attached USB accessory */
+    public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
+        UsbAccessory currentAccessory = mHandler.getCurrentAccessory();
+        if (currentAccessory == null) {
+            throw new IllegalArgumentException("no accessory attached");
+        }
+        if (!currentAccessory.equals(accessory)) {
+            String error = accessory.toString()
+                    + " does not match current accessory "
+                    + currentAccessory;
+            throw new IllegalArgumentException(error);
+        }
+        getCurrentSettings().checkPermission(accessory);
+        return nativeOpenAccessory();
+    }
+
+    public void setCurrentFunctions(String functions, boolean makeDefault) {
+        if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ") default: " + makeDefault);
+        mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, makeDefault);
+    }
+
+    public void setMassStorageBackingFile(String path) {
+        if (path == null) path = "";
+        try {
+            FileUtils.stringToFile(MASS_STORAGE_FILE_PATH, path);
+        } catch (IOException e) {
+           Slog.e(TAG, "failed to write to " + MASS_STORAGE_FILE_PATH);
+        }
+    }
+
+    private void readOemUsbOverrideConfig() {
+        String[] configList = mContext.getResources().getStringArray(
+            com.android.internal.R.array.config_oemUsbModeOverride);
+
+        if (configList != null) {
+            for (String config: configList) {
+                String[] items = config.split(":");
+                if (items.length == 3) {
+                    if (mOemModeMap == null) {
+                        mOemModeMap = new HashMap<String, List<Pair<String, String>>>();
+                    }
+                    List<Pair<String, String>> overrideList = mOemModeMap.get(items[0]);
+                    if (overrideList == null) {
+                        overrideList = new LinkedList<Pair<String, String>>();
+                        mOemModeMap.put(items[0], overrideList);
+                    }
+                    overrideList.add(new Pair<String, String>(items[1], items[2]));
+                }
+            }
+        }
+    }
+
+    private boolean needsOemUsbOverride() {
+        if (mOemModeMap == null) return false;
+
+        String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown");
+        return (mOemModeMap.get(bootMode) != null) ? true : false;
+    }
+
+    private String processOemUsbOverride(String usbFunctions) {
+        if ((usbFunctions == null) || (mOemModeMap == null)) return usbFunctions;
+
+        String bootMode = SystemProperties.get(BOOT_MODE_PROPERTY, "unknown");
+
+        List<Pair<String, String>> overrides = mOemModeMap.get(bootMode);
+        if (overrides != null) {
+            for (Pair<String, String> pair: overrides) {
+                if (pair.first.equals(usbFunctions)) {
+                    Slog.d(TAG, "OEM USB override: " + pair.first + " ==> " + pair.second);
+                    return pair.second;
+                }
+            }
+        }
+        // return passed in functions as is.
+        return usbFunctions;
+    }
+
+    public void allowUsbDebugging(boolean alwaysAllow, String publicKey) {
+        if (mDebuggingManager != null) {
+            mDebuggingManager.allowUsbDebugging(alwaysAllow, publicKey);
+        }
+    }
+
+    public void denyUsbDebugging() {
+        if (mDebuggingManager != null) {
+            mDebuggingManager.denyUsbDebugging();
+        }
+    }
+
+    public void clearUsbDebuggingKeys() {
+        if (mDebuggingManager != null) {
+            mDebuggingManager.clearUsbDebuggingKeys();
+        } else {
+            throw new RuntimeException("Cannot clear Usb Debugging keys, "
+                        + "UsbDebuggingManager not enabled");
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw) {
+        if (mHandler != null) {
+            mHandler.dump(fd, pw);
+        }
+        if (mDebuggingManager != null) {
+            mDebuggingManager.dump(fd, pw);
+        }
+    }
+
+    private native String[] nativeGetAccessoryStrings();
+    private native ParcelFileDescriptor nativeOpenAccessory();
+    private native boolean nativeIsStartRequested();
+    private native int nativeGetAudioMode();
+}
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
new file mode 100644
index 0000000..dfaad0b
--- /dev/null
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -0,0 +1,222 @@
+/*
+ * 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 an
+ * limitations under the License.
+ */
+
+package com.android.server.usb;
+
+import android.content.Context;
+import android.hardware.usb.UsbConstants;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbEndpoint;
+import android.hardware.usb.UsbInterface;
+import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.os.Parcelable;
+import android.util.Slog;
+
+import com.android.internal.annotations.GuardedBy;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.HashMap;
+
+/**
+ * UsbHostManager manages USB state in host mode.
+ */
+public class UsbHostManager {
+    private static final String TAG = UsbHostManager.class.getSimpleName();
+    private static final boolean LOG = false;
+
+    // contains all connected USB devices
+    private final HashMap<String, UsbDevice> mDevices = new HashMap<String, UsbDevice>();
+
+    // USB busses to exclude from USB host support
+    private final String[] mHostBlacklist;
+
+    private final Context mContext;
+    private final Object mLock = new Object();
+
+    @GuardedBy("mLock")
+    private UsbSettingsManager mCurrentSettings;
+
+    public UsbHostManager(Context context) {
+        mContext = context;
+        mHostBlacklist = context.getResources().getStringArray(
+                com.android.internal.R.array.config_usbHostBlacklist);
+    }
+
+    public void setCurrentSettings(UsbSettingsManager settings) {
+        synchronized (mLock) {
+            mCurrentSettings = settings;
+        }
+    }
+
+    private UsbSettingsManager getCurrentSettings() {
+        synchronized (mLock) {
+            return mCurrentSettings;
+        }
+    }
+
+    private boolean isBlackListed(String deviceName) {
+        int count = mHostBlacklist.length;
+        for (int i = 0; i < count; i++) {
+            if (deviceName.startsWith(mHostBlacklist[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /* returns true if the USB device should not be accessible by applications */
+    private boolean isBlackListed(int clazz, int subClass, int protocol) {
+        // blacklist hubs
+        if (clazz == UsbConstants.USB_CLASS_HUB) return true;
+
+        // blacklist HID boot devices (mouse and keyboard)
+        if (clazz == UsbConstants.USB_CLASS_HID &&
+                subClass == UsbConstants.USB_INTERFACE_SUBCLASS_BOOT) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /* Called from JNI in monitorUsbHostBus() to report new USB devices */
+    private void usbDeviceAdded(String deviceName, int vendorID, int productID,
+            int deviceClass, int deviceSubclass, int deviceProtocol,
+            String manufacturerName, String productName, String serialNumber,
+            /* array of quintuples containing id, class, subclass, protocol
+               and number of endpoints for each interface */
+            int[] interfaceValues,
+           /* array of quadruples containing address, attributes, max packet size
+              and interval for each endpoint */
+            int[] endpointValues) {
+
+        if (isBlackListed(deviceName) ||
+                isBlackListed(deviceClass, deviceSubclass, deviceProtocol)) {
+            return;
+        }
+
+        synchronized (mLock) {
+            if (mDevices.get(deviceName) != null) {
+                Slog.w(TAG, "device already on mDevices list: " + deviceName);
+                return;
+            }
+
+            int numInterfaces = interfaceValues.length / 5;
+            Parcelable[] interfaces = new UsbInterface[numInterfaces];
+            try {
+                // repackage interfaceValues as an array of UsbInterface
+                int intf, endp, ival = 0, eval = 0;
+                for (intf = 0; intf < numInterfaces; intf++) {
+                    int interfaceId = interfaceValues[ival++];
+                    int interfaceClass = interfaceValues[ival++];
+                    int interfaceSubclass = interfaceValues[ival++];
+                    int interfaceProtocol = interfaceValues[ival++];
+                    int numEndpoints = interfaceValues[ival++];
+
+                    Parcelable[] endpoints = new UsbEndpoint[numEndpoints];
+                    for (endp = 0; endp < numEndpoints; endp++) {
+                        int address = endpointValues[eval++];
+                        int attributes = endpointValues[eval++];
+                        int maxPacketSize = endpointValues[eval++];
+                        int interval = endpointValues[eval++];
+                        endpoints[endp] = new UsbEndpoint(address, attributes,
+                                maxPacketSize, interval);
+                    }
+
+                    // don't allow if any interfaces are blacklisted
+                    if (isBlackListed(interfaceClass, interfaceSubclass, interfaceProtocol)) {
+                        return;
+                    }
+                    interfaces[intf] = new UsbInterface(interfaceId, interfaceClass,
+                            interfaceSubclass, interfaceProtocol, endpoints);
+                }
+            } catch (Exception e) {
+                // beware of index out of bound exceptions, which might happen if
+                // a device does not set bNumEndpoints correctly
+                Slog.e(TAG, "error parsing USB descriptors", e);
+                return;
+            }
+
+            UsbDevice device = new UsbDevice(deviceName, vendorID, productID,
+                    deviceClass, deviceSubclass, deviceProtocol,
+                    manufacturerName, productName, serialNumber, interfaces);
+            mDevices.put(deviceName, device);
+            getCurrentSettings().deviceAttached(device);
+        }
+    }
+
+    /* Called from JNI in monitorUsbHostBus to report USB device removal */
+    private void usbDeviceRemoved(String deviceName) {
+        synchronized (mLock) {
+            UsbDevice device = mDevices.remove(deviceName);
+            if (device != null) {
+                getCurrentSettings().deviceDetached(device);
+            }
+        }
+    }
+
+    public void systemReady() {
+        synchronized (mLock) {
+            // Create a thread to call into native code to wait for USB host events.
+            // This thread will call us back on usbDeviceAdded and usbDeviceRemoved.
+            Runnable runnable = new Runnable() {
+                public void run() {
+                    monitorUsbHostBus();
+                }
+            };
+            new Thread(null, runnable, "UsbService host thread").start();
+        }
+    }
+
+    /* Returns a list of all currently attached USB devices */
+    public void getDeviceList(Bundle devices) {
+        synchronized (mLock) {
+            for (String name : mDevices.keySet()) {
+                devices.putParcelable(name, mDevices.get(name));
+            }
+        }
+    }
+
+    /* Opens the specified USB device */
+    public ParcelFileDescriptor openDevice(String deviceName) {
+        synchronized (mLock) {
+            if (isBlackListed(deviceName)) {
+                throw new SecurityException("USB device is on a restricted bus");
+            }
+            UsbDevice device = mDevices.get(deviceName);
+            if (device == null) {
+                // if it is not in mDevices, it either does not exist or is blacklisted
+                throw new IllegalArgumentException(
+                        "device " + deviceName + " does not exist or is restricted");
+            }
+            getCurrentSettings().checkPermission(device);
+            return nativeOpenDevice(deviceName);
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println("  USB Host State:");
+            for (String name : mDevices.keySet()) {
+                pw.println("    " + name + ": " + mDevices.get(name));
+            }
+        }
+    }
+
+    private native void monitorUsbHostBus();
+    private native ParcelFileDescriptor nativeOpenDevice(String deviceName);
+}
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
new file mode 100644
index 0000000..b6ae192
--- /dev/null
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (C) 2010 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 an
+ * limitations under the License.
+ */
+
+package com.android.server.usb;
+
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.hardware.usb.IUsbManager;
+import android.hardware.usb.UsbAccessory;
+import android.hardware.usb.UsbDevice;
+import android.os.Bundle;
+import android.os.ParcelFileDescriptor;
+import android.os.UserHandle;
+import android.util.SparseArray;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.util.IndentingPrintWriter;
+import com.android.server.SystemService;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * UsbService manages all USB related state, including both host and device support.
+ * Host related events and calls are delegated to UsbHostManager, and device related
+ * support is delegated to UsbDeviceManager.
+ */
+public class UsbService extends IUsbManager.Stub {
+
+    public static class Lifecycle extends SystemService {
+        private UsbService mUsbService;
+
+        public Lifecycle(Context context) {
+            super(context);
+        }
+
+        @Override
+        public void onStart() {
+            mUsbService = new UsbService(getContext());
+            publishBinderService(Context.USB_SERVICE, mUsbService);
+        }
+
+        @Override
+        public void onBootPhase(int phase) {
+            if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY) {
+                mUsbService.systemReady();
+            }
+        }
+    }
+
+    private static final String TAG = "UsbService";
+
+    private final Context mContext;
+
+    private UsbDeviceManager mDeviceManager;
+    private UsbHostManager mHostManager;
+
+    private final Object mLock = new Object();
+
+    /** Map from {@link UserHandle} to {@link UsbSettingsManager} */
+    @GuardedBy("mLock")
+    private final SparseArray<UsbSettingsManager>
+            mSettingsByUser = new SparseArray<UsbSettingsManager>();
+
+    private UsbSettingsManager getSettingsForUser(int userId) {
+        synchronized (mLock) {
+            UsbSettingsManager settings = mSettingsByUser.get(userId);
+            if (settings == null) {
+                settings = new UsbSettingsManager(mContext, new UserHandle(userId));
+                mSettingsByUser.put(userId, settings);
+            }
+            return settings;
+        }
+    }
+
+    public UsbService(Context context) {
+        mContext = context;
+
+        final PackageManager pm = mContext.getPackageManager();
+        if (pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST)) {
+            mHostManager = new UsbHostManager(context);
+        }
+        if (new File("/sys/class/android_usb").exists()) {
+            mDeviceManager = new UsbDeviceManager(context);
+        }
+
+        setCurrentUser(UserHandle.USER_OWNER);
+
+        final IntentFilter userFilter = new IntentFilter();
+        userFilter.addAction(Intent.ACTION_USER_SWITCHED);
+        userFilter.addAction(Intent.ACTION_USER_STOPPED);
+        mContext.registerReceiver(mUserReceiver, userFilter, null, null);
+    }
+
+    private BroadcastReceiver mUserReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
+            final String action = intent.getAction();
+            if (Intent.ACTION_USER_SWITCHED.equals(action)) {
+                setCurrentUser(userId);
+            } else if (Intent.ACTION_USER_STOPPED.equals(action)) {
+                synchronized (mLock) {
+                    mSettingsByUser.remove(userId);
+                }
+            }
+        }
+    };
+
+    private void setCurrentUser(int userId) {
+        final UsbSettingsManager userSettings = getSettingsForUser(userId);
+        if (mHostManager != null) {
+            mHostManager.setCurrentSettings(userSettings);
+        }
+        if (mDeviceManager != null) {
+            mDeviceManager.setCurrentSettings(userSettings);
+        }
+    }
+
+    public void systemReady() {
+        if (mDeviceManager != null) {
+            mDeviceManager.systemReady();
+        }
+        if (mHostManager != null) {
+            mHostManager.systemReady();
+        }
+    }
+
+    /* Returns a list of all currently attached USB devices (host mdoe) */
+    @Override
+    public void getDeviceList(Bundle devices) {
+        if (mHostManager != null) {
+            mHostManager.getDeviceList(devices);
+        }
+    }
+
+    /* Opens the specified USB device (host mode) */
+    @Override
+    public ParcelFileDescriptor openDevice(String deviceName) {
+        if (mHostManager != null) {
+            return mHostManager.openDevice(deviceName);
+        } else {
+            return null;
+        }
+    }
+
+    /* returns the currently attached USB accessory (device mode) */
+    @Override
+    public UsbAccessory getCurrentAccessory() {
+        if (mDeviceManager != null) {
+            return mDeviceManager.getCurrentAccessory();
+        } else {
+            return null;
+        }
+    }
+
+    /* opens the currently attached USB accessory (device mode) */
+    @Override
+    public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
+        if (mDeviceManager != null) {
+            return mDeviceManager.openAccessory(accessory);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public void setDevicePackage(UsbDevice device, String packageName, int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        getSettingsForUser(userId).setDevicePackage(device, packageName);
+    }
+
+    @Override
+    public void setAccessoryPackage(UsbAccessory accessory, String packageName, int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        getSettingsForUser(userId).setAccessoryPackage(accessory, packageName);
+    }
+
+    @Override
+    public boolean hasDevicePermission(UsbDevice device) {
+        final int userId = UserHandle.getCallingUserId();
+        return getSettingsForUser(userId).hasPermission(device);
+    }
+
+    @Override
+    public boolean hasAccessoryPermission(UsbAccessory accessory) {
+        final int userId = UserHandle.getCallingUserId();
+        return getSettingsForUser(userId).hasPermission(accessory);
+    }
+
+    @Override
+    public void requestDevicePermission(UsbDevice device, String packageName, PendingIntent pi) {
+        final int userId = UserHandle.getCallingUserId();
+        getSettingsForUser(userId).requestPermission(device, packageName, pi);
+    }
+
+    @Override
+    public void requestAccessoryPermission(
+            UsbAccessory accessory, String packageName, PendingIntent pi) {
+        final int userId = UserHandle.getCallingUserId();
+        getSettingsForUser(userId).requestPermission(accessory, packageName, pi);
+    }
+
+    @Override
+    public void grantDevicePermission(UsbDevice device, int uid) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        final int userId = UserHandle.getUserId(uid);
+        getSettingsForUser(userId).grantDevicePermission(device, uid);
+    }
+
+    @Override
+    public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        final int userId = UserHandle.getUserId(uid);
+        getSettingsForUser(userId).grantAccessoryPermission(accessory, uid);
+    }
+
+    @Override
+    public boolean hasDefaults(String packageName, int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        return getSettingsForUser(userId).hasDefaults(packageName);
+    }
+
+    @Override
+    public void clearDefaults(String packageName, int userId) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        getSettingsForUser(userId).clearDefaults(packageName);
+    }
+
+    @Override
+    public void setCurrentFunction(String function, boolean makeDefault) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        if (mDeviceManager != null) {
+            mDeviceManager.setCurrentFunctions(function, makeDefault);
+        } else {
+            throw new IllegalStateException("USB device mode not supported");
+        }
+    }
+
+    @Override
+    public void setMassStorageBackingFile(String path) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        if (mDeviceManager != null) {
+            mDeviceManager.setMassStorageBackingFile(path);
+        } else {
+            throw new IllegalStateException("USB device mode not supported");
+        }
+    }
+
+    @Override
+    public void allowUsbDebugging(boolean alwaysAllow, String publicKey) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        mDeviceManager.allowUsbDebugging(alwaysAllow, publicKey);
+    }
+
+    @Override
+    public void denyUsbDebugging() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        mDeviceManager.denyUsbDebugging();
+    }
+
+    @Override
+    public void clearUsbDebuggingKeys() {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
+        mDeviceManager.clearUsbDebuggingKeys();
+    }
+
+    @Override
+    public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
+        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
+
+        pw.println("USB Manager State:");
+        if (mDeviceManager != null) {
+            mDeviceManager.dump(fd, pw);
+        }
+        if (mHostManager != null) {
+            mHostManager.dump(fd, pw);
+        }
+
+        synchronized (mLock) {
+            for (int i = 0; i < mSettingsByUser.size(); i++) {
+                final int userId = mSettingsByUser.keyAt(i);
+                final UsbSettingsManager settings = mSettingsByUser.valueAt(i);
+                pw.increaseIndent();
+                pw.println("Settings for user " + userId + ":");
+                settings.dump(fd, pw);
+                pw.decreaseIndent();
+            }
+        }
+        pw.decreaseIndent();
+    }
+}
diff --git a/services/usb/java/com/android/server/usb/UsbSettingsManager.java b/services/usb/java/com/android/server/usb/UsbSettingsManager.java
new file mode 100644
index 0000000..ff4857b
--- /dev/null
+++ b/services/usb/java/com/android/server/usb/UsbSettingsManager.java
@@ -0,0 +1,1215 @@
+/*
+ * 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.server.usb;
+
+import android.app.PendingIntent;
+import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.pm.ResolveInfo;
+import android.content.res.XmlResourceParser;
+import android.hardware.usb.UsbAccessory;
+import android.hardware.usb.UsbDevice;
+import android.hardware.usb.UsbInterface;
+import android.hardware.usb.UsbManager;
+import android.os.Binder;
+import android.os.Environment;
+import android.os.Process;
+import android.os.UserHandle;
+import android.util.AtomicFile;
+import android.util.Log;
+import android.util.Slog;
+import android.util.SparseBooleanArray;
+import android.util.Xml;
+
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.util.FastXmlSerializer;
+import com.android.internal.util.XmlUtils;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import libcore.io.IoUtils;
+
+class UsbSettingsManager {
+    private static final String TAG = "UsbSettingsManager";
+    private static final boolean DEBUG = false;
+
+    /** Legacy settings file, before multi-user */
+    private static final File sSingleUserSettingsFile = new File(
+            "/data/system/usb_device_manager.xml");
+
+    private final UserHandle mUser;
+    private final AtomicFile mSettingsFile;
+
+    private final Context mContext;
+    private final Context mUserContext;
+    private final PackageManager mPackageManager;
+
+    // Temporary mapping USB device name to list of UIDs with permissions for the device
+    private final HashMap<String, SparseBooleanArray> mDevicePermissionMap =
+            new HashMap<String, SparseBooleanArray>();
+    // Temporary mapping UsbAccessory to list of UIDs with permissions for the accessory
+    private final HashMap<UsbAccessory, SparseBooleanArray> mAccessoryPermissionMap =
+            new HashMap<UsbAccessory, SparseBooleanArray>();
+    // Maps DeviceFilter to user preferred application package
+    private final HashMap<DeviceFilter, String> mDevicePreferenceMap =
+            new HashMap<DeviceFilter, String>();
+    // Maps AccessoryFilter to user preferred application package
+    private final HashMap<AccessoryFilter, String> mAccessoryPreferenceMap =
+            new HashMap<AccessoryFilter, String>();
+
+    private final Object mLock = new Object();
+
+    // This class is used to describe a USB device.
+    // When used in HashMaps all values must be specified,
+    // but wildcards can be used for any of the fields in
+    // the package meta-data.
+    private static class DeviceFilter {
+        // USB Vendor ID (or -1 for unspecified)
+        public final int mVendorId;
+        // USB Product ID (or -1 for unspecified)
+        public final int mProductId;
+        // USB device or interface class (or -1 for unspecified)
+        public final int mClass;
+        // USB device subclass (or -1 for unspecified)
+        public final int mSubclass;
+        // USB device protocol (or -1 for unspecified)
+        public final int mProtocol;
+        // USB device manufacturer name string (or null for unspecified)
+        public final String mManufacturerName;
+        // USB device product name string (or null for unspecified)
+        public final String mProductName;
+        // USB device serial number string (or null for unspecified)
+        public final String mSerialNumber;
+
+        public DeviceFilter(int vid, int pid, int clasz, int subclass, int protocol,
+                            String manufacturer, String product, String serialnum) {
+            mVendorId = vid;
+            mProductId = pid;
+            mClass = clasz;
+            mSubclass = subclass;
+            mProtocol = protocol;
+            mManufacturerName = manufacturer;
+            mProductName = product;
+            mSerialNumber = serialnum;
+        }
+
+        public DeviceFilter(UsbDevice device) {
+            mVendorId = device.getVendorId();
+            mProductId = device.getProductId();
+            mClass = device.getDeviceClass();
+            mSubclass = device.getDeviceSubclass();
+            mProtocol = device.getDeviceProtocol();
+            mManufacturerName = device.getManufacturerName();
+            mProductName = device.getProductName();
+            mSerialNumber = device.getSerialNumber();
+        }
+
+        public static DeviceFilter read(XmlPullParser parser)
+                throws XmlPullParserException, IOException {
+            int vendorId = -1;
+            int productId = -1;
+            int deviceClass = -1;
+            int deviceSubclass = -1;
+            int deviceProtocol = -1;
+            String manufacturerName = null;
+            String productName = null;
+            String serialNumber = null;
+
+            int count = parser.getAttributeCount();
+            for (int i = 0; i < count; i++) {
+                String name = parser.getAttributeName(i);
+                String value = parser.getAttributeValue(i);
+                // Attribute values are ints or strings
+                if ("manufacturer-name".equals(name)) {
+                    manufacturerName = value;
+                } else if ("product-name".equals(name)) {
+                    productName = value;
+                } else if ("serial-number".equals(name)) {
+                    serialNumber = value;
+                } else {
+                    int intValue = -1;
+                    int radix = 10;
+                    if (value != null && value.length() > 2 && value.charAt(0) == '0' &&
+                        (value.charAt(1) == 'x' || value.charAt(1) == 'X')) {
+                        // allow hex values starting with 0x or 0X
+                        radix = 16;
+                        value = value.substring(2);
+                    }
+                    try {
+                        intValue = Integer.parseInt(value, radix);
+                    } catch (NumberFormatException e) {
+                        Slog.e(TAG, "invalid number for field " + name, e);
+                        continue;
+                    }
+                    if ("vendor-id".equals(name)) {
+                        vendorId = intValue;
+                    } else if ("product-id".equals(name)) {
+                        productId = intValue;
+                    } else if ("class".equals(name)) {
+                        deviceClass = intValue;
+                    } else if ("subclass".equals(name)) {
+                        deviceSubclass = intValue;
+                    } else if ("protocol".equals(name)) {
+                        deviceProtocol = intValue;
+                    }
+                }
+            }
+            return new DeviceFilter(vendorId, productId,
+                    deviceClass, deviceSubclass, deviceProtocol,
+                    manufacturerName, productName, serialNumber);
+        }
+
+        public void write(XmlSerializer serializer) throws IOException {
+            serializer.startTag(null, "usb-device");
+            if (mVendorId != -1) {
+                serializer.attribute(null, "vendor-id", Integer.toString(mVendorId));
+            }
+            if (mProductId != -1) {
+                serializer.attribute(null, "product-id", Integer.toString(mProductId));
+            }
+            if (mClass != -1) {
+                serializer.attribute(null, "class", Integer.toString(mClass));
+            }
+            if (mSubclass != -1) {
+                serializer.attribute(null, "subclass", Integer.toString(mSubclass));
+            }
+            if (mProtocol != -1) {
+                serializer.attribute(null, "protocol", Integer.toString(mProtocol));
+            }
+            if (mManufacturerName != null) {
+                serializer.attribute(null, "manufacturer-name", mManufacturerName);
+            }
+            if (mProductName != null) {
+                serializer.attribute(null, "product-name", mProductName);
+            }
+            if (mSerialNumber != null) {
+                serializer.attribute(null, "serial-number", mSerialNumber);
+            }
+            serializer.endTag(null, "usb-device");
+        }
+
+        private boolean matches(int clasz, int subclass, int protocol) {
+            return ((mClass == -1 || clasz == mClass) &&
+                    (mSubclass == -1 || subclass == mSubclass) &&
+                    (mProtocol == -1 || protocol == mProtocol));
+        }
+
+        public boolean matches(UsbDevice device) {
+            if (mVendorId != -1 && device.getVendorId() != mVendorId) return false;
+            if (mProductId != -1 && device.getProductId() != mProductId) return false;
+            if (mManufacturerName != null && device.getManufacturerName() == null) return false;
+            if (mProductName != null && device.getProductName() == null) return false;
+            if (mSerialNumber != null && device.getSerialNumber() == null) return false;
+            if (mManufacturerName != null && device.getManufacturerName() != null &&
+                !mManufacturerName.equals(device.getManufacturerName())) return false;
+            if (mProductName != null && device.getProductName() != null &&
+                !mProductName.equals(device.getProductName())) return false;
+            if (mSerialNumber != null && device.getSerialNumber() != null &&
+                !mSerialNumber.equals(device.getSerialNumber())) return false;
+
+            // check device class/subclass/protocol
+            if (matches(device.getDeviceClass(), device.getDeviceSubclass(),
+                    device.getDeviceProtocol())) return true;
+
+            // if device doesn't match, check the interfaces
+            int count = device.getInterfaceCount();
+            for (int i = 0; i < count; i++) {
+                UsbInterface intf = device.getInterface(i);
+                 if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(),
+                        intf.getInterfaceProtocol())) return true;
+            }
+
+            return false;
+        }
+
+        public boolean matches(DeviceFilter f) {
+            if (mVendorId != -1 && f.mVendorId != mVendorId) return false;
+            if (mProductId != -1 && f.mProductId != mProductId) return false;
+            if (f.mManufacturerName != null && mManufacturerName == null) return false;
+            if (f.mProductName != null && mProductName == null) return false;
+            if (f.mSerialNumber != null && mSerialNumber == null) return false;
+            if (mManufacturerName != null && f.mManufacturerName != null &&
+                !mManufacturerName.equals(f.mManufacturerName)) return false;
+            if (mProductName != null && f.mProductName != null &&
+                !mProductName.equals(f.mProductName)) return false;
+            if (mSerialNumber != null && f.mSerialNumber != null &&
+                !mSerialNumber.equals(f.mSerialNumber)) return false;
+
+            // check device class/subclass/protocol
+            return matches(f.mClass, f.mSubclass, f.mProtocol);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            // can't compare if we have wildcard strings
+            if (mVendorId == -1 || mProductId == -1 ||
+                    mClass == -1 || mSubclass == -1 || mProtocol == -1) {
+                return false;
+            }
+            if (obj instanceof DeviceFilter) {
+                DeviceFilter filter = (DeviceFilter)obj;
+
+                if (filter.mVendorId != mVendorId ||
+                        filter.mProductId != mProductId ||
+                        filter.mClass != mClass ||
+                        filter.mSubclass != mSubclass ||
+                        filter.mProtocol != mProtocol) {
+                    return(false);
+                }
+                if ((filter.mManufacturerName != null &&
+                        mManufacturerName == null) ||
+                    (filter.mManufacturerName == null &&
+                        mManufacturerName != null) ||
+                    (filter.mProductName != null &&
+                        mProductName == null)  ||
+                    (filter.mProductName == null &&
+                        mProductName != null) ||
+                    (filter.mSerialNumber != null &&
+                        mSerialNumber == null)  ||
+                    (filter.mSerialNumber == null &&
+                        mSerialNumber != null)) {
+                    return(false);
+                }
+                if  ((filter.mManufacturerName != null &&
+                        mManufacturerName != null &&
+                        !mManufacturerName.equals(filter.mManufacturerName)) ||
+                     (filter.mProductName != null &&
+                        mProductName != null &&
+                        !mProductName.equals(filter.mProductName)) ||
+                     (filter.mSerialNumber != null &&
+                        mSerialNumber != null &&
+                        !mSerialNumber.equals(filter.mSerialNumber))) {
+                    return(false);
+                }
+                return(true);
+            }
+            if (obj instanceof UsbDevice) {
+                UsbDevice device = (UsbDevice)obj;
+                if (device.getVendorId() != mVendorId ||
+                        device.getProductId() != mProductId ||
+                        device.getDeviceClass() != mClass ||
+                        device.getDeviceSubclass() != mSubclass ||
+                        device.getDeviceProtocol() != mProtocol) {
+                    return(false);
+                }
+                if ((mManufacturerName != null && device.getManufacturerName() == null) ||
+                        (mManufacturerName == null && device.getManufacturerName() != null) ||
+                        (mProductName != null && device.getProductName() == null) ||
+                        (mProductName == null && device.getProductName() != null) ||
+                        (mSerialNumber != null && device.getSerialNumber() == null) ||
+                        (mSerialNumber == null && device.getSerialNumber() != null)) {
+                    return(false);
+                }
+                if ((device.getManufacturerName() != null &&
+                        !mManufacturerName.equals(device.getManufacturerName())) ||
+                        (device.getProductName() != null &&
+                            !mProductName.equals(device.getProductName())) ||
+                        (device.getSerialNumber() != null &&
+                            !mSerialNumber.equals(device.getSerialNumber()))) {
+                    return(false);
+                }
+                return true;
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return (((mVendorId << 16) | mProductId) ^
+                    ((mClass << 16) | (mSubclass << 8) | mProtocol));
+        }
+
+        @Override
+        public String toString() {
+            return "DeviceFilter[mVendorId=" + mVendorId + ",mProductId=" + mProductId +
+                    ",mClass=" + mClass + ",mSubclass=" + mSubclass +
+                    ",mProtocol=" + mProtocol + ",mManufacturerName=" + mManufacturerName +
+                    ",mProductName=" + mProductName + ",mSerialNumber=" + mSerialNumber +
+                    "]";
+        }
+    }
+
+    // This class is used to describe a USB accessory.
+    // When used in HashMaps all values must be specified,
+    // but wildcards can be used for any of the fields in
+    // the package meta-data.
+    private static class AccessoryFilter {
+        // USB accessory manufacturer (or null for unspecified)
+        public final String mManufacturer;
+        // USB accessory model (or null for unspecified)
+        public final String mModel;
+        // USB accessory version (or null for unspecified)
+        public final String mVersion;
+
+        public AccessoryFilter(String manufacturer, String model, String version) {
+            mManufacturer = manufacturer;
+            mModel = model;
+            mVersion = version;
+        }
+
+        public AccessoryFilter(UsbAccessory accessory) {
+            mManufacturer = accessory.getManufacturer();
+            mModel = accessory.getModel();
+            mVersion = accessory.getVersion();
+        }
+
+        public static AccessoryFilter read(XmlPullParser parser)
+                throws XmlPullParserException, IOException {
+            String manufacturer = null;
+            String model = null;
+            String version = null;
+
+            int count = parser.getAttributeCount();
+            for (int i = 0; i < count; i++) {
+                String name = parser.getAttributeName(i);
+                String value = parser.getAttributeValue(i);
+
+                if ("manufacturer".equals(name)) {
+                    manufacturer = value;
+                } else if ("model".equals(name)) {
+                    model = value;
+                } else if ("version".equals(name)) {
+                    version = value;
+                }
+             }
+             return new AccessoryFilter(manufacturer, model, version);
+        }
+
+        public void write(XmlSerializer serializer)throws IOException {
+            serializer.startTag(null, "usb-accessory");
+            if (mManufacturer != null) {
+                serializer.attribute(null, "manufacturer", mManufacturer);
+            }
+            if (mModel != null) {
+                serializer.attribute(null, "model", mModel);
+            }
+            if (mVersion != null) {
+                serializer.attribute(null, "version", mVersion);
+            }
+            serializer.endTag(null, "usb-accessory");
+        }
+
+        public boolean matches(UsbAccessory acc) {
+            if (mManufacturer != null && !acc.getManufacturer().equals(mManufacturer)) return false;
+            if (mModel != null && !acc.getModel().equals(mModel)) return false;
+            if (mVersion != null && !acc.getVersion().equals(mVersion)) return false;
+            return true;
+        }
+
+        public boolean matches(AccessoryFilter f) {
+            if (mManufacturer != null && !f.mManufacturer.equals(mManufacturer)) return false;
+            if (mModel != null && !f.mModel.equals(mModel)) return false;
+            if (mVersion != null && !f.mVersion.equals(mVersion)) return false;
+            return true;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            // can't compare if we have wildcard strings
+            if (mManufacturer == null || mModel == null || mVersion == null) {
+                return false;
+            }
+            if (obj instanceof AccessoryFilter) {
+                AccessoryFilter filter = (AccessoryFilter)obj;
+                return (mManufacturer.equals(filter.mManufacturer) &&
+                        mModel.equals(filter.mModel) &&
+                        mVersion.equals(filter.mVersion));
+            }
+            if (obj instanceof UsbAccessory) {
+                UsbAccessory accessory = (UsbAccessory)obj;
+                return (mManufacturer.equals(accessory.getManufacturer()) &&
+                        mModel.equals(accessory.getModel()) &&
+                        mVersion.equals(accessory.getVersion()));
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^
+                    (mModel == null ? 0 : mModel.hashCode()) ^
+                    (mVersion == null ? 0 : mVersion.hashCode()));
+        }
+
+        @Override
+        public String toString() {
+            return "AccessoryFilter[mManufacturer=\"" + mManufacturer +
+                                "\", mModel=\"" + mModel +
+                                "\", mVersion=\"" + mVersion + "\"]";
+        }
+    }
+
+    private class MyPackageMonitor extends PackageMonitor {
+        @Override
+        public void onPackageAdded(String packageName, int uid) {
+            handlePackageUpdate(packageName);
+        }
+
+        @Override
+        public boolean onPackageChanged(String packageName, int uid, String[] components) {
+            handlePackageUpdate(packageName);
+            return false;
+        }
+
+        @Override
+        public void onPackageRemoved(String packageName, int uid) {
+            clearDefaults(packageName);
+        }
+    }
+
+    MyPackageMonitor mPackageMonitor = new MyPackageMonitor();
+
+    public UsbSettingsManager(Context context, UserHandle user) {
+        if (DEBUG) Slog.v(TAG, "Creating settings for " + user);
+
+        try {
+            mUserContext = context.createPackageContextAsUser("android", 0, user);
+        } catch (NameNotFoundException e) {
+            throw new RuntimeException("Missing android package");
+        }
+
+        mContext = context;
+        mPackageManager = mUserContext.getPackageManager();
+
+        mUser = user;
+        mSettingsFile = new AtomicFile(new File(
+                Environment.getUserSystemDirectory(user.getIdentifier()),
+                "usb_device_manager.xml"));
+
+        synchronized (mLock) {
+            if (UserHandle.OWNER.equals(user)) {
+                upgradeSingleUserLocked();
+            }
+            readSettingsLocked();
+        }
+
+        mPackageMonitor.register(mUserContext, null, true);
+    }
+
+    private void readPreference(XmlPullParser parser)
+            throws XmlPullParserException, IOException {
+        String packageName = null;
+        int count = parser.getAttributeCount();
+        for (int i = 0; i < count; i++) {
+            if ("package".equals(parser.getAttributeName(i))) {
+                packageName = parser.getAttributeValue(i);
+                break;
+            }
+        }
+        XmlUtils.nextElement(parser);
+        if ("usb-device".equals(parser.getName())) {
+            DeviceFilter filter = DeviceFilter.read(parser);
+            mDevicePreferenceMap.put(filter, packageName);
+        } else if ("usb-accessory".equals(parser.getName())) {
+            AccessoryFilter filter = AccessoryFilter.read(parser);
+            mAccessoryPreferenceMap.put(filter, packageName);
+        }
+        XmlUtils.nextElement(parser);
+    }
+
+    /**
+     * Upgrade any single-user settings from {@link #sSingleUserSettingsFile}.
+     * Should only by called by owner.
+     */
+    private void upgradeSingleUserLocked() {
+        if (sSingleUserSettingsFile.exists()) {
+            mDevicePreferenceMap.clear();
+            mAccessoryPreferenceMap.clear();
+
+            FileInputStream fis = null;
+            try {
+                fis = new FileInputStream(sSingleUserSettingsFile);
+                XmlPullParser parser = Xml.newPullParser();
+                parser.setInput(fis, null);
+
+                XmlUtils.nextElement(parser);
+                while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                    final String tagName = parser.getName();
+                    if ("preference".equals(tagName)) {
+                        readPreference(parser);
+                    } else {
+                        XmlUtils.nextElement(parser);
+                    }
+                }
+            } catch (IOException e) {
+                Log.wtf(TAG, "Failed to read single-user settings", e);
+            } catch (XmlPullParserException e) {
+                Log.wtf(TAG, "Failed to read single-user settings", e);
+            } finally {
+                IoUtils.closeQuietly(fis);
+            }
+
+            writeSettingsLocked();
+
+            // Success or failure, we delete single-user file
+            sSingleUserSettingsFile.delete();
+        }
+    }
+
+    private void readSettingsLocked() {
+        if (DEBUG) Slog.v(TAG, "readSettingsLocked()");
+
+        mDevicePreferenceMap.clear();
+        mAccessoryPreferenceMap.clear();
+
+        FileInputStream stream = null;
+        try {
+            stream = mSettingsFile.openRead();
+            XmlPullParser parser = Xml.newPullParser();
+            parser.setInput(stream, null);
+
+            XmlUtils.nextElement(parser);
+            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                String tagName = parser.getName();
+                if ("preference".equals(tagName)) {
+                    readPreference(parser);
+                } else {
+                    XmlUtils.nextElement(parser);
+                }
+            }
+        } catch (FileNotFoundException e) {
+            if (DEBUG) Slog.d(TAG, "settings file not found");
+        } catch (Exception e) {
+            Slog.e(TAG, "error reading settings file, deleting to start fresh", e);
+            mSettingsFile.delete();
+        } finally {
+            IoUtils.closeQuietly(stream);
+        }
+    }
+
+    private void writeSettingsLocked() {
+        if (DEBUG) Slog.v(TAG, "writeSettingsLocked()");
+
+        FileOutputStream fos = null;
+        try {
+            fos = mSettingsFile.startWrite();
+
+            FastXmlSerializer serializer = new FastXmlSerializer();
+            serializer.setOutput(fos, "utf-8");
+            serializer.startDocument(null, true);
+            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+            serializer.startTag(null, "settings");
+
+            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
+                serializer.startTag(null, "preference");
+                serializer.attribute(null, "package", mDevicePreferenceMap.get(filter));
+                filter.write(serializer);
+                serializer.endTag(null, "preference");
+            }
+
+            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
+                serializer.startTag(null, "preference");
+                serializer.attribute(null, "package", mAccessoryPreferenceMap.get(filter));
+                filter.write(serializer);
+                serializer.endTag(null, "preference");
+            }
+
+            serializer.endTag(null, "settings");
+            serializer.endDocument();
+
+            mSettingsFile.finishWrite(fos);
+        } catch (IOException e) {
+            Slog.e(TAG, "Failed to write settings", e);
+            if (fos != null) {
+                mSettingsFile.failWrite(fos);
+            }
+        }
+    }
+
+    // Checks to see if a package matches a device or accessory.
+    // Only one of device and accessory should be non-null.
+    private boolean packageMatchesLocked(ResolveInfo info, String metaDataName,
+            UsbDevice device, UsbAccessory accessory) {
+        ActivityInfo ai = info.activityInfo;
+
+        XmlResourceParser parser = null;
+        try {
+            parser = ai.loadXmlMetaData(mPackageManager, metaDataName);
+            if (parser == null) {
+                Slog.w(TAG, "no meta-data for " + info);
+                return false;
+            }
+
+            XmlUtils.nextElement(parser);
+            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                String tagName = parser.getName();
+                if (device != null && "usb-device".equals(tagName)) {
+                    DeviceFilter filter = DeviceFilter.read(parser);
+                    if (filter.matches(device)) {
+                        return true;
+                    }
+                }
+                else if (accessory != null && "usb-accessory".equals(tagName)) {
+                    AccessoryFilter filter = AccessoryFilter.read(parser);
+                    if (filter.matches(accessory)) {
+                        return true;
+                    }
+                }
+                XmlUtils.nextElement(parser);
+            }
+        } catch (Exception e) {
+            Slog.w(TAG, "Unable to load component info " + info.toString(), e);
+        } finally {
+            if (parser != null) parser.close();
+        }
+        return false;
+    }
+
+    private final ArrayList<ResolveInfo> getDeviceMatchesLocked(UsbDevice device, Intent intent) {
+        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
+        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
+                PackageManager.GET_META_DATA);
+        int count = resolveInfos.size();
+        for (int i = 0; i < count; i++) {
+            ResolveInfo resolveInfo = resolveInfos.get(i);
+            if (packageMatchesLocked(resolveInfo, intent.getAction(), device, null)) {
+                matches.add(resolveInfo);
+            }
+        }
+        return matches;
+    }
+
+    private final ArrayList<ResolveInfo> getAccessoryMatchesLocked(
+            UsbAccessory accessory, Intent intent) {
+        ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
+        List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent,
+                PackageManager.GET_META_DATA);
+        int count = resolveInfos.size();
+        for (int i = 0; i < count; i++) {
+            ResolveInfo resolveInfo = resolveInfos.get(i);
+            if (packageMatchesLocked(resolveInfo, intent.getAction(), null, accessory)) {
+                matches.add(resolveInfo);
+            }
+        }
+        return matches;
+    }
+
+    public void deviceAttached(UsbDevice device) {
+        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        ArrayList<ResolveInfo> matches;
+        String defaultPackage;
+        synchronized (mLock) {
+            matches = getDeviceMatchesLocked(device, intent);
+            // Launch our default activity directly, if we have one.
+            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
+            defaultPackage = mDevicePreferenceMap.get(new DeviceFilter(device));
+        }
+
+        // Send broadcast to running activity with registered intent
+        mUserContext.sendBroadcast(intent);
+
+        // Start activity with registered intent
+        resolveActivity(intent, matches, defaultPackage, device, null);
+    }
+
+    public void deviceDetached(UsbDevice device) {
+        // clear temporary permissions for the device
+        mDevicePermissionMap.remove(device.getDeviceName());
+
+        Intent intent = new Intent(UsbManager.ACTION_USB_DEVICE_DETACHED);
+        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+        if (DEBUG) Slog.d(TAG, "usbDeviceRemoved, sending " + intent);
+        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+    }
+
+    public void accessoryAttached(UsbAccessory accessory) {
+        Intent intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
+        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        ArrayList<ResolveInfo> matches;
+        String defaultPackage;
+        synchronized (mLock) {
+            matches = getAccessoryMatchesLocked(accessory, intent);
+            // Launch our default activity directly, if we have one.
+            // Otherwise we will start the UsbResolverActivity to allow the user to choose.
+            defaultPackage = mAccessoryPreferenceMap.get(new AccessoryFilter(accessory));
+        }
+
+        resolveActivity(intent, matches, defaultPackage, null, accessory);
+    }
+
+    public void accessoryDetached(UsbAccessory accessory) {
+        // clear temporary permissions for the accessory
+        mAccessoryPermissionMap.remove(accessory);
+
+        Intent intent = new Intent(
+                UsbManager.ACTION_USB_ACCESSORY_DETACHED);
+        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+        mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
+    }
+
+    private void resolveActivity(Intent intent, ArrayList<ResolveInfo> matches,
+            String defaultPackage, UsbDevice device, UsbAccessory accessory) {
+        int count = matches.size();
+
+        // don't show the resolver activity if there are no choices available
+        if (count == 0) {
+            if (accessory != null) {
+                String uri = accessory.getUri();
+                if (uri != null && uri.length() > 0) {
+                    // display URI to user
+                    // start UsbResolverActivity so user can choose an activity
+                    Intent dialogIntent = new Intent();
+                    dialogIntent.setClassName("com.android.systemui",
+                            "com.android.systemui.usb.UsbAccessoryUriActivity");
+                    dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                    dialogIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+                    dialogIntent.putExtra("uri", uri);
+                    try {
+                        mUserContext.startActivityAsUser(dialogIntent, mUser);
+                    } catch (ActivityNotFoundException e) {
+                        Slog.e(TAG, "unable to start UsbAccessoryUriActivity");
+                    }
+                }
+            }
+
+            // do nothing
+            return;
+        }
+
+        ResolveInfo defaultRI = null;
+        if (count == 1 && defaultPackage == null) {
+            // Check to see if our single choice is on the system partition.
+            // If so, treat it as our default without calling UsbResolverActivity
+            ResolveInfo rInfo = matches.get(0);
+            if (rInfo.activityInfo != null &&
+                    rInfo.activityInfo.applicationInfo != null &&
+                    (rInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+                defaultRI = rInfo;
+            }
+        }
+
+        if (defaultRI == null && defaultPackage != null) {
+            // look for default activity
+            for (int i = 0; i < count; i++) {
+                ResolveInfo rInfo = matches.get(i);
+                if (rInfo.activityInfo != null &&
+                        defaultPackage.equals(rInfo.activityInfo.packageName)) {
+                    defaultRI = rInfo;
+                    break;
+                }
+            }
+        }
+
+        if (defaultRI != null) {
+            // grant permission for default activity
+            if (device != null) {
+                grantDevicePermission(device, defaultRI.activityInfo.applicationInfo.uid);
+            } else if (accessory != null) {
+                grantAccessoryPermission(accessory, defaultRI.activityInfo.applicationInfo.uid);
+            }
+
+            // start default activity directly
+            try {
+                intent.setComponent(
+                        new ComponentName(defaultRI.activityInfo.packageName,
+                                defaultRI.activityInfo.name));
+                mUserContext.startActivityAsUser(intent, mUser);
+            } catch (ActivityNotFoundException e) {
+                Slog.e(TAG, "startActivity failed", e);
+            }
+        } else {
+            Intent resolverIntent = new Intent();
+            resolverIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+            if (count == 1) {
+                // start UsbConfirmActivity if there is only one choice
+                resolverIntent.setClassName("com.android.systemui",
+                        "com.android.systemui.usb.UsbConfirmActivity");
+                resolverIntent.putExtra("rinfo", matches.get(0));
+
+                if (device != null) {
+                    resolverIntent.putExtra(UsbManager.EXTRA_DEVICE, device);
+                } else {
+                    resolverIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+                }
+            } else {
+                // start UsbResolverActivity so user can choose an activity
+                resolverIntent.setClassName("com.android.systemui",
+                        "com.android.systemui.usb.UsbResolverActivity");
+                resolverIntent.putParcelableArrayListExtra("rlist", matches);
+                resolverIntent.putExtra(Intent.EXTRA_INTENT, intent);
+            }
+            try {
+                mUserContext.startActivityAsUser(resolverIntent, mUser);
+            } catch (ActivityNotFoundException e) {
+                Slog.e(TAG, "unable to start activity " + resolverIntent);
+            }
+        }
+    }
+
+    private boolean clearCompatibleMatchesLocked(String packageName, DeviceFilter filter) {
+        boolean changed = false;
+        for (DeviceFilter test : mDevicePreferenceMap.keySet()) {
+            if (filter.matches(test)) {
+                mDevicePreferenceMap.remove(test);
+                changed = true;
+            }
+        }
+        return changed;
+    }
+
+    private boolean clearCompatibleMatchesLocked(String packageName, AccessoryFilter filter) {
+        boolean changed = false;
+        for (AccessoryFilter test : mAccessoryPreferenceMap.keySet()) {
+            if (filter.matches(test)) {
+                mAccessoryPreferenceMap.remove(test);
+                changed = true;
+            }
+        }
+        return changed;
+    }
+
+    private boolean handlePackageUpdateLocked(String packageName, ActivityInfo aInfo,
+            String metaDataName) {
+        XmlResourceParser parser = null;
+        boolean changed = false;
+
+        try {
+            parser = aInfo.loadXmlMetaData(mPackageManager, metaDataName);
+            if (parser == null) return false;
+
+            XmlUtils.nextElement(parser);
+            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+                String tagName = parser.getName();
+                if ("usb-device".equals(tagName)) {
+                    DeviceFilter filter = DeviceFilter.read(parser);
+                    if (clearCompatibleMatchesLocked(packageName, filter)) {
+                        changed = true;
+                    }
+                }
+                else if ("usb-accessory".equals(tagName)) {
+                    AccessoryFilter filter = AccessoryFilter.read(parser);
+                    if (clearCompatibleMatchesLocked(packageName, filter)) {
+                        changed = true;
+                    }
+                }
+                XmlUtils.nextElement(parser);
+            }
+        } catch (Exception e) {
+            Slog.w(TAG, "Unable to load component info " + aInfo.toString(), e);
+        } finally {
+            if (parser != null) parser.close();
+        }
+        return changed;
+    }
+
+    // Check to see if the package supports any USB devices or accessories.
+    // If so, clear any non-matching preferences for matching devices/accessories.
+    private void handlePackageUpdate(String packageName) {
+        synchronized (mLock) {
+            PackageInfo info;
+            boolean changed = false;
+
+            try {
+                info = mPackageManager.getPackageInfo(packageName,
+                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);
+            } catch (NameNotFoundException e) {
+                Slog.e(TAG, "handlePackageUpdate could not find package " + packageName, e);
+                return;
+            }
+
+            ActivityInfo[] activities = info.activities;
+            if (activities == null) return;
+            for (int i = 0; i < activities.length; i++) {
+                // check for meta-data, both for devices and accessories
+                if (handlePackageUpdateLocked(packageName, activities[i],
+                        UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
+                    changed = true;
+                }
+                if (handlePackageUpdateLocked(packageName, activities[i],
+                        UsbManager.ACTION_USB_ACCESSORY_ATTACHED)) {
+                    changed = true;
+                }
+            }
+
+            if (changed) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    public boolean hasPermission(UsbDevice device) {
+        synchronized (mLock) {
+            int uid = Binder.getCallingUid();
+            if (uid == Process.SYSTEM_UID) {
+                return true;
+            }
+            SparseBooleanArray uidList = mDevicePermissionMap.get(device.getDeviceName());
+            if (uidList == null) {
+                return false;
+            }
+            return uidList.get(uid);
+        }
+    }
+
+    public boolean hasPermission(UsbAccessory accessory) {
+        synchronized (mLock) {
+            int uid = Binder.getCallingUid();
+            if (uid == Process.SYSTEM_UID) {
+                return true;
+            }
+            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
+            if (uidList == null) {
+                return false;
+            }
+            return uidList.get(uid);
+        }
+    }
+
+    public void checkPermission(UsbDevice device) {
+        if (!hasPermission(device)) {
+            throw new SecurityException("User has not given permission to device " + device);
+        }
+    }
+
+    public void checkPermission(UsbAccessory accessory) {
+        if (!hasPermission(accessory)) {
+            throw new SecurityException("User has not given permission to accessory " + accessory);
+        }
+    }
+
+    private void requestPermissionDialog(Intent intent, String packageName, PendingIntent pi) {
+        final int uid = Binder.getCallingUid();
+
+        // compare uid with packageName to foil apps pretending to be someone else
+        try {
+            ApplicationInfo aInfo = mPackageManager.getApplicationInfo(packageName, 0);
+            if (aInfo.uid != uid) {
+                throw new IllegalArgumentException("package " + packageName +
+                        " does not match caller's uid " + uid);
+            }
+        } catch (PackageManager.NameNotFoundException e) {
+            throw new IllegalArgumentException("package " + packageName + " not found");
+        }
+
+        long identity = Binder.clearCallingIdentity();
+        intent.setClassName("com.android.systemui",
+                "com.android.systemui.usb.UsbPermissionActivity");
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.putExtra(Intent.EXTRA_INTENT, pi);
+        intent.putExtra("package", packageName);
+        intent.putExtra(Intent.EXTRA_UID, uid);
+        try {
+            mUserContext.startActivityAsUser(intent, mUser);
+        } catch (ActivityNotFoundException e) {
+            Slog.e(TAG, "unable to start UsbPermissionActivity");
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
+    }
+
+    public void requestPermission(UsbDevice device, String packageName, PendingIntent pi) {
+      Intent intent = new Intent();
+
+        // respond immediately if permission has already been granted
+      if (hasPermission(device)) {
+            intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
+            try {
+                pi.send(mUserContext, 0, intent);
+            } catch (PendingIntent.CanceledException e) {
+                if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled");
+            }
+            return;
+        }
+
+        // start UsbPermissionActivity so user can choose an activity
+        intent.putExtra(UsbManager.EXTRA_DEVICE, device);
+        requestPermissionDialog(intent, packageName, pi);
+    }
+
+    public void requestPermission(UsbAccessory accessory, String packageName, PendingIntent pi) {
+        Intent intent = new Intent();
+
+        // respond immediately if permission has already been granted
+        if (hasPermission(accessory)) {
+            intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+            intent.putExtra(UsbManager.EXTRA_PERMISSION_GRANTED, true);
+            try {
+                pi.send(mUserContext, 0, intent);
+            } catch (PendingIntent.CanceledException e) {
+                if (DEBUG) Slog.d(TAG, "requestPermission PendingIntent was cancelled");
+            }
+            return;
+        }
+
+        intent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
+        requestPermissionDialog(intent, packageName, pi);
+    }
+
+    public void setDevicePackage(UsbDevice device, String packageName) {
+        DeviceFilter filter = new DeviceFilter(device);
+        boolean changed = false;
+        synchronized (mLock) {
+            if (packageName == null) {
+                changed = (mDevicePreferenceMap.remove(filter) != null);
+            } else {
+                changed = !packageName.equals(mDevicePreferenceMap.get(filter));
+                if (changed) {
+                    mDevicePreferenceMap.put(filter, packageName);
+                }
+            }
+            if (changed) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    public void setAccessoryPackage(UsbAccessory accessory, String packageName) {
+        AccessoryFilter filter = new AccessoryFilter(accessory);
+        boolean changed = false;
+        synchronized (mLock) {
+            if (packageName == null) {
+                changed = (mAccessoryPreferenceMap.remove(filter) != null);
+            } else {
+                changed = !packageName.equals(mAccessoryPreferenceMap.get(filter));
+                if (changed) {
+                    mAccessoryPreferenceMap.put(filter, packageName);
+                }
+            }
+            if (changed) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    public void grantDevicePermission(UsbDevice device, int uid) {
+        synchronized (mLock) {
+            String deviceName = device.getDeviceName();
+            SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
+            if (uidList == null) {
+                uidList = new SparseBooleanArray(1);
+                mDevicePermissionMap.put(deviceName, uidList);
+            }
+            uidList.put(uid, true);
+        }
+    }
+
+    public void grantAccessoryPermission(UsbAccessory accessory, int uid) {
+        synchronized (mLock) {
+            SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
+            if (uidList == null) {
+                uidList = new SparseBooleanArray(1);
+                mAccessoryPermissionMap.put(accessory, uidList);
+            }
+            uidList.put(uid, true);
+        }
+    }
+
+    public boolean hasDefaults(String packageName) {
+        synchronized (mLock) {
+            if (mDevicePreferenceMap.values().contains(packageName)) return true;
+            if (mAccessoryPreferenceMap.values().contains(packageName)) return true;
+            return false;
+        }
+    }
+
+    public void clearDefaults(String packageName) {
+        synchronized (mLock) {
+            if (clearPackageDefaultsLocked(packageName)) {
+                writeSettingsLocked();
+            }
+        }
+    }
+
+    private boolean clearPackageDefaultsLocked(String packageName) {
+        boolean cleared = false;
+        synchronized (mLock) {
+            if (mDevicePreferenceMap.containsValue(packageName)) {
+                // make a copy of the key set to avoid ConcurrentModificationException
+                Object[] keys = mDevicePreferenceMap.keySet().toArray();
+                for (int i = 0; i < keys.length; i++) {
+                    Object key = keys[i];
+                    if (packageName.equals(mDevicePreferenceMap.get(key))) {
+                        mDevicePreferenceMap.remove(key);
+                        cleared = true;
+                    }
+                }
+            }
+            if (mAccessoryPreferenceMap.containsValue(packageName)) {
+                // make a copy of the key set to avoid ConcurrentModificationException
+                Object[] keys = mAccessoryPreferenceMap.keySet().toArray();
+                for (int i = 0; i < keys.length; i++) {
+                    Object key = keys[i];
+                    if (packageName.equals(mAccessoryPreferenceMap.get(key))) {
+                        mAccessoryPreferenceMap.remove(key);
+                        cleared = true;
+                    }
+                }
+            }
+            return cleared;
+        }
+    }
+
+    public void dump(FileDescriptor fd, PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println("  Device permissions:");
+            for (String deviceName : mDevicePermissionMap.keySet()) {
+                pw.print("    " + deviceName + ": ");
+                SparseBooleanArray uidList = mDevicePermissionMap.get(deviceName);
+                int count = uidList.size();
+                for (int i = 0; i < count; i++) {
+                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
+                }
+                pw.println("");
+            }
+            pw.println("  Accessory permissions:");
+            for (UsbAccessory accessory : mAccessoryPermissionMap.keySet()) {
+                pw.print("    " + accessory + ": ");
+                SparseBooleanArray uidList = mAccessoryPermissionMap.get(accessory);
+                int count = uidList.size();
+                for (int i = 0; i < count; i++) {
+                    pw.print(Integer.toString(uidList.keyAt(i)) + " ");
+                }
+                pw.println("");
+            }
+            pw.println("  Device preferences:");
+            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
+                pw.println("    " + filter + ": " + mDevicePreferenceMap.get(filter));
+            }
+            pw.println("  Accessory preferences:");
+            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
+                pw.println("    " + filter + ": " + mAccessoryPreferenceMap.get(filter));
+            }
+        }
+    }
+}
diff --git a/telephony/java/android/telephony/CellSignalStrengthCdma.java b/telephony/java/android/telephony/CellSignalStrengthCdma.java
index c945094..46d09f6 100644
--- a/telephony/java/android/telephony/CellSignalStrengthCdma.java
+++ b/telephony/java/android/telephony/CellSignalStrengthCdma.java
@@ -21,7 +21,7 @@
 import android.telephony.Rlog;
 
 /**
- * LTE signal strength related information.
+ * Signal strength related information.
  */
 public final class CellSignalStrengthCdma extends CellSignalStrength implements Parcelable {
 
@@ -136,7 +136,7 @@
     }
 
     /**
-     * Get the LTE signal level as an asu value between 0..97, 99 is unknown
+     * Get the signal level as an asu value between 0..97, 99 is unknown
      * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
      */
     @Override
diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java
index 821a11c..8e445d9 100644
--- a/telephony/java/com/android/internal/telephony/RILConstants.java
+++ b/telephony/java/com/android/internal/telephony/RILConstants.java
@@ -55,6 +55,8 @@
     int ILLEGAL_SIM_OR_ME = 15;               /* network selection failure due
                                                  to wrong SIM/ME and no
                                                  retries needed */
+    int MISSING_RESOURCE = 16;                /* no logical channel available */
+    int NO_SUCH_ELEMENT = 17;                 /* application not found on SIM */
 
     /* NETWORK_MODE_* See ril.h RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE */
     int NETWORK_MODE_WCDMA_PREF     = 0; /* GSM/WCDMA (WCDMA preferred) */
@@ -265,6 +267,10 @@
     int RIL_REQUEST_SET_INITIAL_ATTACH_APN = 111;
     int RIL_REQUEST_IMS_REGISTRATION_STATE = 112;
     int RIL_REQUEST_IMS_SEND_SMS = 113;
+    int RIL_REQUEST_SIM_TRANSMIT_APDU_BASIC = 114;
+    int RIL_REQUEST_SIM_OPEN_CHANNEL = 115;
+    int RIL_REQUEST_SIM_CLOSE_CHANNEL = 116;
+    int RIL_REQUEST_SIM_TRANSMIT_APDU_CHANNEL = 117;
     int RIL_UNSOL_RESPONSE_BASE = 1000;
     int RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED = 1000;
     int RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED = 1001;
diff --git a/test-runner/src/android/test/mock/MockPackageManager.java b/test-runner/src/android/test/mock/MockPackageManager.java
index 661bd41..c1305bc 100644
--- a/test-runner/src/android/test/mock/MockPackageManager.java
+++ b/test-runner/src/android/test/mock/MockPackageManager.java
@@ -338,6 +338,27 @@
     }
 
     @Override
+    public Drawable getActivityBanner(ComponentName activityName)
+            throws NameNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Drawable getActivityBanner(Intent intent) throws NameNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Drawable getApplicationBanner(ApplicationInfo info) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Drawable getApplicationBanner(String packageName) throws NameNotFoundException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
     public Drawable getApplicationIcon(ApplicationInfo info) {
         throw new UnsupportedOperationException();
     }
diff --git a/tests/DozeTest/Android.mk b/tests/DozeTest/Android.mk
new file mode 100644
index 0000000..01f10e5
--- /dev/null
+++ b/tests/DozeTest/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := DozeTest
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/DozeTest/AndroidManifest.xml b/tests/DozeTest/AndroidManifest.xml
new file mode 100644
index 0000000..c199f69
--- /dev/null
+++ b/tests/DozeTest/AndroidManifest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.dreams.dozetest">
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+
+    <application android:label="@string/app_name">
+        <service
+            android:name="DozeTestDream"
+            android:exported="true"
+            android:icon="@drawable/ic_app"
+            android:label="@string/doze_dream_name">
+            <!-- Commented out to prevent this dream from appearing in the list of
+                 dreams that the user can select via the Settings application.
+            <intent-filter>
+                <action android:name="android.service.dreams.DreamService" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+            -->
+        </service>
+    </application>
+</manifest>
diff --git a/tests/DozeTest/res/drawable-hdpi/ic_app.png b/tests/DozeTest/res/drawable-hdpi/ic_app.png
new file mode 100755
index 0000000..66a1984
--- /dev/null
+++ b/tests/DozeTest/res/drawable-hdpi/ic_app.png
Binary files differ
diff --git a/tests/DozeTest/res/drawable-mdpi/ic_app.png b/tests/DozeTest/res/drawable-mdpi/ic_app.png
new file mode 100644
index 0000000..5ae7701
--- /dev/null
+++ b/tests/DozeTest/res/drawable-mdpi/ic_app.png
Binary files differ
diff --git a/tests/DozeTest/res/layout/dream.xml b/tests/DozeTest/res/layout/dream.xml
new file mode 100644
index 0000000..1c8fd3f
--- /dev/null
+++ b/tests/DozeTest/res/layout/dream.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:gravity="center_vertical"
+        android:orientation="vertical">
+    <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/alarm_clock_label" />
+    <TextView android:id="@+id/alarm_clock"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+    <Space
+            android:layout_width="match_parent"
+            android:layout_height="32dp" />
+
+    <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:text="@string/tick_clock_label" />
+    <TextClock android:id="@+id/tick_clock"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+</LinearLayout>
diff --git a/tests/DozeTest/res/values/strings.xml b/tests/DozeTest/res/values/strings.xml
new file mode 100644
index 0000000..f21911f
--- /dev/null
+++ b/tests/DozeTest/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+    <!-- Name of the package of basic screensavers, shown in Settings > Apps. [CHAR LIMIT=40] -->
+    <string name="app_name">Doze Test</string>
+
+    <!-- Name of the screensaver. [CHAR LIMIT=40] -->
+    <string name="doze_dream_name">Doze Test</string>
+
+    <string name="alarm_clock_label">This clock is updated using the Alarm Manager</string>
+    <string name="tick_clock_label">This clock is updated using TIME_TICK Broadcasts</string>
+</resources>
diff --git a/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
new file mode 100644
index 0000000..bf35db4
--- /dev/null
+++ b/tests/DozeTest/src/com/android/dreams/dozetest/DozeTestDream.java
@@ -0,0 +1,165 @@
+/*
+ * 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.dreams.dozetest;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.PowerManager;
+import android.service.dreams.DozeHardware;
+import android.service.dreams.DreamService;
+import android.text.format.DateFormat;
+import android.util.Log;
+import android.widget.TextView;
+
+import java.util.Date;
+
+/**
+ * Simple test for doze mode.
+ * <p>
+ * adb shell setprop debug.doze.component com.android.dreams.dozetest/.DozeTestDream
+ * </p>
+ */
+public class DozeTestDream extends DreamService {
+    private static final String TAG = DozeTestDream.class.getSimpleName();
+    private static final boolean DEBUG = false;
+
+    // Amount of time to allow to update the time shown on the screen before releasing
+    // the wakelock.  This timeout is design to compensate for the fact that we don't
+    // currently have a way to know when time display contents have actually been
+    // refreshed once the dream has finished rendering a new frame.
+    private static final int UPDATE_TIME_TIMEOUT = 100;
+
+    // A doze hardware message string we use for end-to-end testing.
+    // Doesn't mean anything.  Real hardware won't handle it.
+    private static final String TEST_PING_MESSAGE = "test.ping";
+
+    private PowerManager mPowerManager;
+    private PowerManager.WakeLock mWakeLock;
+    private AlarmManager mAlarmManager;
+    private PendingIntent mAlarmIntent;
+
+    private TextView mAlarmClock;
+
+    private final Date mTime = new Date();
+    private java.text.DateFormat mTimeFormat;
+
+    private boolean mDreaming;
+    private DozeHardware mDozeHardware;
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+
+        mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
+        mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+
+        mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
+
+        Intent intent = new Intent("com.android.dreams.dozetest.ACTION_ALARM");
+        intent.setPackage(getPackageName());
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(intent.getAction());
+        registerReceiver(mAlarmReceiver, filter);
+        mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent,
+                PendingIntent.FLAG_CANCEL_CURRENT);
+    }
+
+    @Override
+    public void onDestroy() {
+        super.onDestroy();
+
+        unregisterReceiver(mAlarmReceiver);
+        mAlarmIntent.cancel();
+    }
+
+    @Override
+    public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        setInteractive(false);
+        setLowProfile(true);
+        setFullscreen(true);
+        setContentView(R.layout.dream);
+
+        mAlarmClock = (TextView)findViewById(R.id.alarm_clock);
+
+        mTimeFormat = DateFormat.getTimeFormat(this);
+    }
+
+    @Override
+    public void onDreamingStarted() {
+        super.onDreamingStarted();
+
+        mDreaming = true;
+        mDozeHardware = getDozeHardware();
+
+        Log.d(TAG, "Dream started: canDoze=" + canDoze()
+                + ", dozeHardware=" + mDozeHardware);
+
+        performTimeUpdate();
+
+        if (mDozeHardware != null) {
+            mDozeHardware.sendMessage(TEST_PING_MESSAGE, null);
+            mDozeHardware.setEnableMcu(true);
+        }
+        startDozing();
+    }
+
+    @Override
+    public void onDreamingStopped() {
+        super.onDreamingStopped();
+
+        mDreaming = false;
+        if (mDozeHardware != null) {
+            mDozeHardware.setEnableMcu(false);
+            mDozeHardware = null;
+        }
+
+        Log.d(TAG, "Dream ended: isDozing=" + isDozing());
+
+        stopDozing();
+        cancelTimeUpdate();
+    }
+
+    private void performTimeUpdate() {
+        if (mDreaming) {
+            long now = System.currentTimeMillis();
+            now -= now % 60000; // back up to last minute boundary
+
+            mTime.setTime(now);
+            mAlarmClock.setText(mTimeFormat.format(mTime));
+
+            mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, now + 60000, mAlarmIntent);
+
+            mWakeLock.acquire(UPDATE_TIME_TIMEOUT);
+        }
+    }
+
+    private void cancelTimeUpdate() {
+        mAlarmManager.cancel(mAlarmIntent);
+    }
+
+    private final BroadcastReceiver mAlarmReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            performTimeUpdate();
+        }
+    };
+}
diff --git a/tests/TileBenchmark/Android.mk b/tests/TileBenchmark/Android.mk
index 5851113..9a057af 100644
--- a/tests/TileBenchmark/Android.mk
+++ b/tests/TileBenchmark/Android.mk
@@ -17,7 +17,7 @@
 
 LOCAL_MODULE_TAGS := optional
 
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_SRC_FILES :=
 
 LOCAL_PACKAGE_NAME := TileBenchmark
 
@@ -25,4 +25,4 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-include $(BUILD_PACKAGE)
\ No newline at end of file
+include $(BUILD_PACKAGE)
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index d8e113a..62200d9 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -1631,9 +1631,18 @@
 // =========================================================================
 // =========================================================================
 
-status_t AaptGroup::addFile(const sp<AaptFile>& file)
+status_t AaptGroup::addFile(const sp<AaptFile>& file, const bool overwriteDuplicate)
 {
-    if (mFiles.indexOfKey(file->getGroupEntry()) < 0) {
+    ssize_t index = mFiles.indexOfKey(file->getGroupEntry());
+    if (index >= 0 && overwriteDuplicate) {
+        fprintf(stderr, "warning: overwriting '%s' with '%s'\n",
+                mFiles[index]->getSourceFile().string(),
+                file->getSourceFile().string());
+        removeFile(index);
+        index = -1;
+    }
+
+    if (index < 0) {
         file->mPath = mPath;
         mFiles.add(file->getGroupEntry(), file);
         return NO_ERROR;
@@ -1739,7 +1748,8 @@
     mDirs.removeItem(name);
 }
 
-status_t AaptDir::addLeafFile(const String8& leafName, const sp<AaptFile>& file)
+status_t AaptDir::addLeafFile(const String8& leafName, const sp<AaptFile>& file,
+        const bool overwrite)
 {
     sp<AaptGroup> group;
     if (mFiles.indexOfKey(leafName) >= 0) {
@@ -1749,12 +1759,12 @@
         mFiles.add(leafName, group);
     }
 
-    return group->addFile(file);
+    return group->addFile(file, overwrite);
 }
 
 ssize_t AaptDir::slurpFullTree(Bundle* bundle, const String8& srcDir,
                             const AaptGroupEntry& kind, const String8& resType,
-                            sp<FilePathStore>& fullResPaths)
+                            sp<FilePathStore>& fullResPaths, const bool overwrite)
 {
     Vector<String8> fileNames;
     {
@@ -1813,7 +1823,7 @@
                 notAdded = true;
             }
             ssize_t res = subdir->slurpFullTree(bundle, pathName, kind,
-                                                resType, fullResPaths);
+                                                resType, fullResPaths, overwrite);
             if (res < NO_ERROR) {
                 return res;
             }
@@ -1823,7 +1833,7 @@
             count += res;
         } else if (type == kFileTypeRegular) {
             sp<AaptFile> file = new AaptFile(pathName, kind, resType);
-            status_t err = addLeafFile(fileNames[i], file);
+            status_t err = addLeafFile(fileNames[i], file, overwrite);
             if (err != NO_ERROR) {
                 return err;
             }
@@ -2089,24 +2099,24 @@
     /*
      * If a directory of custom assets was supplied, slurp 'em up.
      */
-    if (bundle->getAssetSourceDir()) {
-        const char* assetDir = bundle->getAssetSourceDir();
-
-        FileType type = getFileType(assetDir);
+    const Vector<const char*>& assetDirs = bundle->getAssetSourceDirs();
+    const int AN = assetDirs.size();
+    for (int i = 0; i < AN; i++) {
+        FileType type = getFileType(assetDirs[i]);
         if (type == kFileTypeNonexistent) {
-            fprintf(stderr, "ERROR: asset directory '%s' does not exist\n", assetDir);
+            fprintf(stderr, "ERROR: asset directory '%s' does not exist\n", assetDirs[i]);
             return UNKNOWN_ERROR;
         }
         if (type != kFileTypeDirectory) {
-            fprintf(stderr, "ERROR: '%s' is not a directory\n", assetDir);
+            fprintf(stderr, "ERROR: '%s' is not a directory\n", assetDirs[i]);
             return UNKNOWN_ERROR;
         }
 
-        String8 assetRoot(assetDir);
+        String8 assetRoot(assetDirs[i]);
         sp<AaptDir> assetAaptDir = makeDir(String8(kAssetDir));
         AaptGroupEntry group;
         count = assetAaptDir->slurpFullTree(bundle, assetRoot, group,
-                                            String8(), mFullAssetPaths);
+                                            String8(), mFullAssetPaths, true);
         if (count < 0) {
             totalCount = count;
             goto bail;
@@ -2116,9 +2126,10 @@
         }
         totalCount += count;
 
-        if (bundle->getVerbose())
+        if (bundle->getVerbose()) {
             printf("Found %d custom asset file%s in %s\n",
-                   count, (count==1) ? "" : "s", assetDir);
+                   count, (count==1) ? "" : "s", assetDirs[i]);
+        }
     }
 
     /*
diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h
index 5cfa913..9cc9007 100644
--- a/tools/aapt/AaptAssets.h
+++ b/tools/aapt/AaptAssets.h
@@ -235,7 +235,7 @@
     const DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> >& getFiles() const
         { return mFiles; }
 
-    status_t addFile(const sp<AaptFile>& file);
+    status_t addFile(const sp<AaptFile>& file, const bool overwriteDuplicate=false);
     void removeFile(size_t index);
 
     void print(const String8& prefix) const;
@@ -301,12 +301,14 @@
     status_t addDir(const String8& name, const sp<AaptDir>& dir);
     sp<AaptDir> makeDir(const String8& name);
     status_t addLeafFile(const String8& leafName,
-                         const sp<AaptFile>& file);
+                         const sp<AaptFile>& file,
+                         const bool overwrite=false);
     virtual ssize_t slurpFullTree(Bundle* bundle,
                                   const String8& srcDir,
                                   const AaptGroupEntry& kind,
                                   const String8& resType,
-                                  sp<FilePathStore>& fullResPaths);
+                                  sp<FilePathStore>& fullResPaths,
+                                  const bool overwrite=false);
 
     String8 mLeaf;
     String8 mPath;
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk
index 452c60a..806f8ff 100644
--- a/tools/aapt/Android.mk
+++ b/tools/aapt/Android.mk
@@ -5,7 +5,7 @@
 #
 
 # This tool is prebuilt if we're doing an app-only build.
-ifeq ($(TARGET_BUILD_APPS),)
+ifeq ($(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)),)
 
 
 aapt_src_files := \
@@ -50,7 +50,8 @@
 	libcutils \
 	libexpat \
 	libpng \
-	liblog
+	liblog \
+	libziparchive-host
 
 ifeq ($(HOST_OS),linux)
 LOCAL_LDLIBS += -lrt -ldl -lpthread
@@ -100,4 +101,4 @@
 include $(BUILD_EXECUTABLE)
 endif
 
-endif # TARGET_BUILD_APPS
+endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK
diff --git a/tools/aapt/Bundle.h b/tools/aapt/Bundle.h
index 5089b9d..26b10a6 100644
--- a/tools/aapt/Bundle.h
+++ b/tools/aapt/Bundle.h
@@ -55,7 +55,6 @@
           mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL),
           mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL),
           mAutoAddOverlay(false), mGenDependencies(false),
-          mAssetSourceDir(NULL), 
           mCrunchedOutputDir(NULL), mProguardFile(NULL),
           mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
           mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL),
@@ -123,8 +122,8 @@
     /*
      * Input options.
      */
-    const char* getAssetSourceDir() const { return mAssetSourceDir; }
-    void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
+    const android::Vector<const char*>& getAssetSourceDirs() const { return mAssetSourceDirs; }
+    void addAssetSourceDir(const char* dir) { mAssetSourceDirs.insertAt(dir,0); }
     const char* getCrunchedOutputDir() const { return mCrunchedOutputDir; }
     void setCrunchedOutputDir(const char* dir) { mCrunchedOutputDir = dir; }
     const char* getProguardFile() const { return mProguardFile; }
@@ -272,6 +271,7 @@
     android::Vector<const char*> mPackageIncludes;
     android::Vector<const char*> mJarFiles;
     android::Vector<const char*> mNoCompressExtensions;
+    android::Vector<const char*> mAssetSourceDirs;
     android::Vector<const char*> mResourceSourceDirs;
 
     const char* mManifestMinSdkVersion;
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 632efe0..d9e2dc5 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -375,6 +375,7 @@
     LARGEST_WIDTH_LIMIT_DP_ATTR = 0x01010366,
     PUBLIC_KEY_ATTR = 0x010103a6,
     CATEGORY_ATTR = 0x010103e8,
+    BANNER_ATTR = 0x10103f2,
 };
 
 const char *getComponentName(String8 &pkgName, String8 &componentName) {
@@ -505,7 +506,7 @@
     const char* filename = bundle->getFileSpecEntry(1);
 
     AssetManager assets;
-    void* assetsCookie;
+    int32_t assetsCookie;
     if (!assets.addAssetPath(String8(filename), &assetsCookie)) {
         fprintf(stderr, "ERROR: dump failed because assets could not be loaded\n");
         return 1;
@@ -677,6 +678,7 @@
             bool withinActivity = false;
             bool isMainActivity = false;
             bool isLauncherActivity = false;
+            bool isLeanbackLauncherActivity = false;
             bool isSearchable = false;
             bool withinApplication = false;
             bool withinSupportsInput = false;
@@ -787,6 +789,7 @@
             String8 activityName;
             String8 activityLabel;
             String8 activityIcon;
+            String8 activityBanner;
             String8 receiverName;
             String8 serviceName;
             Vector<String8> supportedInput;
@@ -810,15 +813,27 @@
                         withinApplication = false;
                         withinSupportsInput = false;
                     } else if (depth < 3) {
-                        if (withinActivity && isMainActivity && isLauncherActivity) {
+                        if (withinActivity && isMainActivity) {
                             const char *aName = getComponentName(pkg, activityName);
-                            printf("launchable-activity:");
-                            if (aName != NULL) {
-                                printf(" name='%s' ", aName);
+                            if (isLauncherActivity) {
+                                printf("launchable-activity:");
+                                if (aName != NULL) {
+                                    printf(" name='%s' ", aName);
+                                }
+                                printf(" label='%s' icon='%s'\n",
+                                        activityLabel.string(),
+                                        activityIcon.string());
                             }
-                            printf(" label='%s' icon='%s'\n",
-                                    activityLabel.string(),
-                                    activityIcon.string());
+                            if (isLeanbackLauncherActivity) {
+                                printf("leanback-launchable-activity:");
+                                if (aName != NULL) {
+                                    printf(" name='%s' ", aName);
+                                }
+                                printf(" label='%s' icon='%s' banner='%s'\n",
+                                        activityLabel.string(),
+                                        activityIcon.string(),
+                                        activityBanner.string());
+                            }
                         }
                         if (!hasIntentFilter) {
                             hasOtherActivities |= withinActivity;
@@ -836,7 +851,7 @@
                         withinService = false;
                         withinReceiver = false;
                         hasIntentFilter = false;
-                        isMainActivity = isLauncherActivity = false;
+                        isMainActivity = isLauncherActivity = isLeanbackLauncherActivity = false;
                     } else if (depth < 4) {
                         if (withinIntentFilter) {
                             if (withinActivity) {
@@ -1231,6 +1246,13 @@
                                 goto bail;
                             }
 
+                            activityBanner = getResolvedAttribute(&res, tree, BANNER_ATTR, &error);
+                            if (error != "") {
+                                fprintf(stderr, "ERROR getting 'android:banner' attribute: %s\n",
+                                        error.string());
+                                goto bail;
+                            }
+
                             int32_t orien = getResolvedIntegerAttribute(&res, tree,
                                     SCREEN_ORIENTATION_ATTR, &error);
                             if (error == "") {
@@ -1412,6 +1434,8 @@
                         if (withinActivity) {
                             if (category == "android.intent.category.LAUNCHER") {
                                 isLauncherActivity = true;
+                            } else if (category == "android.intent.category.LEANBACK_LAUNCHER") {
+                                isLeanbackLauncherActivity = true;
                             }
                         }
                     }
@@ -1896,7 +1920,7 @@
 
     N = bundle->getFileSpecCount();
     if (N < 1 && bundle->getResourceSourceDirs().size() == 0 && bundle->getJarFiles().size() == 0
-            && bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDir() == NULL) {
+            && bundle->getAndroidManifestFile() == NULL && bundle->getAssetSourceDirs().size() == 0) {
         fprintf(stderr, "ERROR: no input files\n");
         goto bail;
     }
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index 9de685a..25a948d 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -12,13 +12,15 @@
 #include <utils/ByteOrder.h>
 
 #include <png.h>
+#include <zlib.h>
 
 #define NOISY(x) //x
 
 static void
 png_write_aapt_file(png_structp png_ptr, png_bytep data, png_size_t length)
 {
-    status_t err = ((AaptFile*)png_ptr->io_ptr)->writeData(data, length);
+    AaptFile* aaptfile = (AaptFile*) png_get_io_ptr(png_ptr);
+    status_t err = aaptfile->writeData(data, length);
     if (err != NO_ERROR) {
         png_error(png_ptr, "Write Error");
     }
@@ -90,7 +92,7 @@
         png_set_palette_to_rgb(read_ptr);
 
     if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
-        png_set_gray_1_2_4_to_8(read_ptr);
+        png_set_expand_gray_1_2_4_to_8(read_ptr);
 
     if (png_get_valid(read_ptr, read_info, PNG_INFO_tRNS)) {
         //printf("Has PNG_INFO_tRNS!\n");
@@ -109,7 +111,7 @@
     png_read_update_info(read_ptr, read_info);
 
     outImageInfo->rows = (png_bytepp)malloc(
-        outImageInfo->height * png_sizeof(png_bytep));
+        outImageInfo->height * sizeof(png_bytep));
     outImageInfo->allocHeight = outImageInfo->height;
     outImageInfo->allocRows = outImageInfo->rows;
 
@@ -450,10 +452,11 @@
 
     int maxSizeXDivs = W * sizeof(int32_t);
     int maxSizeYDivs = H * sizeof(int32_t);
-    int32_t* xDivs = (int32_t*) malloc(maxSizeXDivs);
-    int32_t* yDivs = (int32_t*) malloc(maxSizeYDivs);
-    uint8_t  numXDivs = 0;
-    uint8_t  numYDivs = 0;
+    int32_t* xDivs = image->info9Patch.xDivs = (int32_t*) malloc(maxSizeXDivs);
+    int32_t* yDivs = image->info9Patch.yDivs = (int32_t*) malloc(maxSizeYDivs);
+    uint8_t numXDivs = 0;
+    uint8_t numYDivs = 0;
+
     int8_t numColors;
     int numRows;
     int numCols;
@@ -508,6 +511,10 @@
         goto getout;
     }
 
+    // Copy patch size data into image...
+    image->info9Patch.numXDivs = numXDivs;
+    image->info9Patch.numYDivs = numYDivs;
+
     // Find left and right of padding area...
     if (get_horizontal_ticks(image->rows[H-1], W, transparent, false, &image->info9Patch.paddingLeft,
                              &image->info9Patch.paddingRight, &errorMsg, NULL, false) != NO_ERROR) {
@@ -543,12 +550,6 @@
                 image->layoutBoundsRight, image->layoutBoundsBottom));
     }
 
-    // Copy patch data into image
-    image->info9Patch.numXDivs = numXDivs;
-    image->info9Patch.numYDivs = numYDivs;
-    image->info9Patch.xDivs = xDivs;
-    image->info9Patch.yDivs = yDivs;
-
     // If padding is not yet specified, take values from size.
     if (image->info9Patch.paddingLeft < 0) {
         image->info9Patch.paddingLeft = xDivs[0];
@@ -573,7 +574,7 @@
                  image->info9Patch.paddingTop, image->info9Patch.paddingBottom));
 
     // Remove frame from image.
-    image->rows = (png_bytepp)malloc((H-2) * png_sizeof(png_bytep));
+    image->rows = (png_bytepp)malloc((H-2) * sizeof(png_bytep));
     for (i=0; i<(H-2); i++) {
         image->rows[i] = image->allocRows[i+1];
         memmove(image->rows[i], image->rows[i]+4, (W-2)*4);
@@ -955,7 +956,7 @@
                 gg = *row++;
                 bb = *row++;
                 aa = *row++;
-                
+
                 if (isGrayscale) {
                     *out++ = rr;
                 } else {
@@ -984,7 +985,7 @@
     unknowns[0].data = NULL;
     unknowns[1].data = NULL;
 
-    png_bytepp outRows = (png_bytepp) malloc((int) imageInfo.height * png_sizeof(png_bytep));
+    png_bytepp outRows = (png_bytepp) malloc((int) imageInfo.height * sizeof(png_bytep));
     if (outRows == (png_bytepp) 0) {
         printf("Can't allocate output buffer!\n");
         exit(1);
@@ -1073,18 +1074,19 @@
             unknowns[b_index].size = chunk_size;
         }
 
+        for (int i = 0; i < chunk_count; i++) {
+            unknowns[i].location = PNG_HAVE_PLTE;
+        }
         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);
-        // XXX I can't get this to work without forcibly changing
-        // the location to what I want...  which apparently is supposed
-        // to be a private API, but everything else I have tried results
-        // in the location being set to what I -last- wrote so I never
-        // get written. :p
+#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
     }
 
 
@@ -1092,7 +1094,9 @@
 
     png_bytepp rows;
     if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
-        png_set_filler(write_ptr, 0, PNG_FILLER_AFTER);
+        if (color_type == PNG_COLOR_TYPE_RGB) {
+            png_set_filler(write_ptr, 0, PNG_FILLER_AFTER);
+        }
         rows = imageInfo.rows;
     } else {
         rows = outRows;
diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp
index 977226b..d1d3deb 100644
--- a/tools/aapt/Main.cpp
+++ b/tools/aapt/Main.cpp
@@ -345,7 +345,7 @@
                     goto bail;
                 }
                 convertPath(argv[0]);
-                bundle.setAssetSourceDir(argv[0]);
+                bundle.addAssetSourceDir(argv[0]);
                 break;
             case 'G':
                 argc--;
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp
index 08ad7a0..386888b 100644
--- a/tools/aapt/Resource.cpp
+++ b/tools/aapt/Resource.cpp
@@ -469,7 +469,7 @@
                         value.data);
                 return ATTR_NOT_FOUND;
             }
-            
+
             pool = table.getTableStringBlock(strIdx);
             #if 0
             if (pool != NULL) {
@@ -705,7 +705,7 @@
         // don't stop the build.
         return true;
     }
-    
+
     node->addAttribute(ns, attr, String16(value));
     return true;
 }
@@ -756,7 +756,7 @@
             bundle->getVersionName(), errorOnFailedInsert)) {
         return UNKNOWN_ERROR;
     }
-    
+
     if (bundle->getMinSdkVersion() != NULL
             || bundle->getTargetSdkVersion() != NULL
             || bundle->getMaxSdkVersion() != NULL) {
@@ -765,7 +765,7 @@
             vers = XMLNode::newElement(root->getFilename(), String16(), String16("uses-sdk"));
             root->insertChildAt(vers, 0);
         }
-        
+
         if (!addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "minSdkVersion",
                 bundle->getMinSdkVersion(), errorOnFailedInsert)) {
             return UNKNOWN_ERROR;
@@ -840,7 +840,7 @@
             }
         }
     }
-    
+
     return NO_ERROR;
 }
 
@@ -924,7 +924,7 @@
     // --------------------------------------------------------------
 
     // resType -> leafName -> group
-    KeyedVector<String8, sp<ResourceTypeSet> > *resources = 
+    KeyedVector<String8, sp<ResourceTypeSet> > *resources =
             new KeyedVector<String8, sp<ResourceTypeSet> >;
     collect_files(assets, resources);
 
@@ -956,7 +956,7 @@
     // now go through any resource overlays and collect their files
     sp<AaptAssets> current = assets->getOverlay();
     while(current.get()) {
-        KeyedVector<String8, sp<ResourceTypeSet> > *resources = 
+        KeyedVector<String8, sp<ResourceTypeSet> > *resources =
                 new KeyedVector<String8, sp<ResourceTypeSet> >;
         current->setResources(resources);
         collect_files(current, resources);
@@ -1059,7 +1059,7 @@
     // compile resources
     current = assets;
     while(current.get()) {
-        KeyedVector<String8, sp<ResourceTypeSet> > *resources = 
+        KeyedVector<String8, sp<ResourceTypeSet> > *resources =
                 current->getResources();
 
         ssize_t index = resources->indexOfKey(String8("values"));
@@ -1068,7 +1068,7 @@
             ssize_t res;
             while ((res=it.next()) == NO_ERROR) {
                 sp<AaptFile> file = it.getFile();
-                res = compileResourceFile(bundle, assets, file, it.getParams(), 
+                res = compileResourceFile(bundle, assets, file, it.getParams(),
                                           (current!=assets), &table);
                 if (res != NO_ERROR) {
                     hasErrors = true;
@@ -1253,7 +1253,7 @@
     if (table.validateLocalizations()) {
         hasErrors = true;
     }
-    
+
     if (hasErrors) {
         return UNKNOWN_ERROR;
     }
@@ -1286,7 +1286,7 @@
 
     ResTable finalResTable;
     sp<AaptFile> resFile;
-    
+
     if (table.hasResources()) {
         sp<AaptSymbols> symbols = assets->getSymbolsFor(String8("R"));
         err = table.addSymbols(symbols);
@@ -1318,10 +1318,10 @@
             table.writePublicDefinitions(String16(assets->getPackage()), fp);
             fclose(fp);
         }
-        
+
         // Read resources back in,
         finalResTable.add(resFile->getData(), resFile->getSize(), NULL);
-        
+
 #if 0
         NOISY(
               printf("Generated resources:\n");
@@ -1329,7 +1329,7 @@
         )
 #endif
     }
-    
+
     // Perform a basic validation of the manifest file.  This time we
     // parse it with the comments intact, so that we can use them to
     // generate java docs...  so we are not going to write this one
@@ -1424,7 +1424,7 @@
                 ssize_t index = block.indexOfAttribute(RESOURCES_ANDROID_NAMESPACE, "name");
                 const uint16_t* id = block.getAttributeStringValue(index, &len);
                 if (id == NULL) {
-                    fprintf(stderr, "%s:%d: missing name attribute in element <%s>.\n", 
+                    fprintf(stderr, "%s:%d: missing name attribute in element <%s>.\n",
                             manifestPath.string(), block.getLineNumber(),
                             String8(block.getElementName(&len)).string());
                     hasErrors = true;
@@ -1582,7 +1582,7 @@
             return err;
         }
     }
-    
+
     return err;
 }
 
@@ -1704,7 +1704,7 @@
         NA = idents.size();
 
         bool deprecated = false;
-        
+
         String16 comment = symbols->getComment(realClassName);
         fprintf(fp, "%s/** ", indentStr);
         if (comment.size() > 0) {
@@ -1787,7 +1787,7 @@
         if (deprecated) {
             fprintf(fp, "%s@Deprecated\n", indentStr);
         }
-        
+
         fprintf(fp,
                 "%spublic static final int[] %s = {\n"
                 "%s",
@@ -1832,9 +1832,9 @@
                 //printf("%s:%s/%s: 0x%08x\n", String8(package16).string(),
                 //    String8(attr16).string(), String8(name16).string(), typeSpecFlags);
                 const bool pub = (typeSpecFlags&ResTable_typeSpec::SPEC_PUBLIC) != 0;
-                
+
                 bool deprecated = false;
-                
+
                 fprintf(fp, "%s/**\n", indentStr);
                 if (comment.size() > 0) {
                     String8 cmt(comment);
@@ -2219,10 +2219,10 @@
 
         status_t err = writeSymbolClass(fp, assets, includePrivate, symbols,
                 className, 0, bundle->getNonConstantId());
+        fclose(fp);
         if (err != NO_ERROR) {
             return err;
         }
-        fclose(fp);
 
         if (textSymbolsDest != NULL && R == className) {
             String8 textDest(textSymbolsDest);
@@ -2241,10 +2241,10 @@
 
             status_t err = writeTextSymbolClass(fp, assets, includePrivate, symbols,
                     className);
+            fclose(fp);
             if (err != NO_ERROR) {
                 return err;
             }
-            fclose(fp);
         }
 
         // If we were asked to generate a dependency file, we'll go ahead and add this R.java
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index f2e5254..6ced8b3 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -1342,7 +1342,7 @@
                 curType = string16;
                 curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_STRING;
                 curIsStyled = true;
-                curIsPseudolocalizable = true;
+                curIsPseudolocalizable = (translatable != false16);
             } else if (strcmp16(block.getElementName(&len), drawable16.string()) == 0) {
                 curTag = &drawable16;
                 curType = drawable16;
@@ -1408,15 +1408,24 @@
                 // Check whether these strings need valid formats.
                 // (simplified form of what string16 does above)
                 size_t n = block.getAttributeCount();
+
+                // Pseudolocalizable by default, unless this string array isn't
+                // translatable.
+                curIsPseudolocalizable = true;
                 for (size_t i = 0; i < n; i++) {
                     size_t length;
                     const uint16_t* attr = block.getAttributeName(i, &length);
-                    if (strcmp16(attr, translatable16.string()) == 0
-                            || strcmp16(attr, formatted16.string()) == 0) {
+                    if (strcmp16(attr, translatable16.string()) == 0) {
+                        const uint16_t* value = block.getAttributeStringValue(i, &length);
+                        if (strcmp16(value, false16.string()) == 0) {
+                            curIsPseudolocalizable = false;
+                        }
+                    }
+
+                    if (strcmp16(attr, formatted16.string()) == 0) {
                         const uint16_t* value = block.getAttributeStringValue(i, &length);
                         if (strcmp16(value, false16.string()) == 0) {
                             curIsFormatted = false;
-                            break;
                         }
                     }
                 }
@@ -1426,7 +1435,6 @@
                 curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_STRING;
                 curIsBag = true;
                 curIsBagReplaceOnOverwrite = true;
-                curIsPseudolocalizable = true;
             } else if (strcmp16(block.getElementName(&len), integer_array16.string()) == 0) {
                 curTag = &integer_array16;
                 curType = array16;
diff --git a/tools/aidl/Android.mk b/tools/aidl/Android.mk
index 77d46ab..efd60a2 100644
--- a/tools/aidl/Android.mk
+++ b/tools/aidl/Android.mk
@@ -3,7 +3,7 @@
 # Copies files into the directory structure described by a manifest
 
 # This tool is prebuilt if we're doing an app-only build.
-ifeq ($(TARGET_BUILD_APPS),)
+ifeq ($(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)),)
 
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
@@ -26,4 +26,4 @@
 
 include $(BUILD_HOST_EXECUTABLE)
 
-endif # TARGET_BUILD_APPS
+endif # No TARGET_BUILD_APPS or TARGET_BUILD_PDK
diff --git a/tools/aidl/aidl.cpp b/tools/aidl/aidl.cpp
index b8a4803..a84d743 100644
--- a/tools/aidl/aidl.cpp
+++ b/tools/aidl/aidl.cpp
@@ -207,7 +207,7 @@
     p = strchr(name->data, '.');
     len = p ? p-name->data : strlen(name->data);
     expected.append(name->data, len);
-    
+
     expected += ".aidl";
 
     len = fn.length();
@@ -473,7 +473,7 @@
             err = 1;
             goto next;
         }
-        
+
         if (!(kind == INTERFACE_TYPE_BINDER ? t->CanWriteToParcel() : t->CanWriteToRpcData())) {
             fprintf(stderr, "%s:%d parameter %d: '%s %s' can't be marshalled.\n",
                         filename, m->type.type.lineno, index,
@@ -536,7 +536,7 @@
                     filename, m->name.lineno, index, arg->name.data);
             err = 1;
         }
-        
+
 next:
         index++;
         arg = arg->next;
@@ -797,7 +797,7 @@
         //printf("%s:%d:...%s...%s...%s...\n", filename.c_str(), lineno,
         //        type, packagename, classname);
         document_item_type* doc;
-        
+
         if (0 == strcmp("parcelable", type)) {
             user_data_type* parcl = (user_data_type*)malloc(
                     sizeof(user_data_type));
@@ -847,6 +847,7 @@
         else {
             fprintf(stderr, "%s:%d: bad type in line: %s\n",
                     filename.c_str(), lineno, line);
+            fclose(f);
             return 1;
         }
         err = gather_types(filename.c_str(), doc);
@@ -1103,13 +1104,13 @@
     }
 
     // write preprocessed file
-    int fd = open( options.outputFileName.c_str(), 
+    int fd = open( options.outputFileName.c_str(),
                    O_RDWR|O_CREAT|O_TRUNC|O_BINARY,
 #ifdef HAVE_MS_C_RUNTIME
                    _S_IREAD|_S_IWRITE);
-#else    
+#else
                    S_IRUSR|S_IWUSR|S_IRGRP);
-#endif            
+#endif
     if (fd == -1) {
         fprintf(stderr, "aidl: could not open file for write: %s\n",
                 options.outputFileName.c_str());
diff --git a/tools/layoutlib/bridge/src/android/graphics/AvoidXfermode_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/AvoidXfermode_Delegate.java
index a50a2bd..34ae825 100644
--- a/tools/layoutlib/bridge/src/android/graphics/AvoidXfermode_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/AvoidXfermode_Delegate.java
@@ -61,7 +61,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(int opColor, int tolerance, int nativeMode) {
+    /*package*/ static long nativeCreate(int opColor, int tolerance, int nativeMode) {
         AvoidXfermode_Delegate newDelegate = new AvoidXfermode_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
index 65a75b0..cdbbe46 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java
@@ -65,7 +65,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(int native_bitmap, int shaderTileModeX,
+    /*package*/ static long nativeCreate(long native_bitmap, int shaderTileModeX,
             int shaderTileModeY) {
         Bitmap_Delegate bitmap = Bitmap_Delegate.getDelegate(native_bitmap);
         if (bitmap == null) {
@@ -80,7 +80,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate(int native_shader, int native_bitmap,
+    /*package*/ static long nativePostCreate(long native_shader, long native_bitmap,
             int shaderTileModeX, int shaderTileModeY) {
         // pass, not needed.
         return 0;
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index 13d2ba1..89d7e23 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -83,7 +83,7 @@
     /**
      * Returns the native delegate associated to a given an int referencing a {@link Bitmap} object.
      */
-    public static Bitmap_Delegate getDelegate(int native_bitmap) {
+    public static Bitmap_Delegate getDelegate(long native_bitmap) {
         return sManager.getDelegate(native_bitmap);
     }
 
@@ -274,7 +274,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static Bitmap nativeCopy(int srcBitmap, int nativeConfig, boolean isMutable) {
+    /*package*/ static Bitmap nativeCopy(long srcBitmap, int nativeConfig, boolean isMutable) {
         Bitmap_Delegate srcBmpDelegate = sManager.getDelegate(srcBitmap);
         if (srcBmpDelegate == null) {
             return null;
@@ -303,25 +303,25 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDestructor(int nativeBitmap) {
+    /*package*/ static void nativeDestructor(long nativeBitmap) {
         sManager.removeJavaReferenceFor(nativeBitmap);
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeRecycle(int nativeBitmap) {
+    /*package*/ static boolean nativeRecycle(long nativeBitmap) {
         sManager.removeJavaReferenceFor(nativeBitmap);
         return true;
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeReconfigure(int nativeBitmap, int width, int height,
+    /*package*/ static void nativeReconfigure(long nativeBitmap, int width, int height,
             int config, int allocSize) {
         Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
                 "Bitmap.reconfigure() is not supported", null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeCompress(int nativeBitmap, int format, int quality,
+    /*package*/ static boolean nativeCompress(long nativeBitmap, int format, int quality,
             OutputStream stream, byte[] tempStorage) {
         Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
                 "Bitmap.compress() is not supported", null /*data*/);
@@ -329,7 +329,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeErase(int nativeBitmap, int color) {
+    /*package*/ static void nativeErase(long nativeBitmap, int color) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -349,7 +349,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeRowBytes(int nativeBitmap) {
+    /*package*/ static int nativeRowBytes(long nativeBitmap) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -360,7 +360,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeConfig(int nativeBitmap) {
+    /*package*/ static int nativeConfig(long nativeBitmap) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -371,7 +371,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeHasAlpha(int nativeBitmap) {
+    /*package*/ static boolean nativeHasAlpha(long nativeBitmap) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -382,7 +382,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeHasMipMap(int nativeBitmap) {
+    /*package*/ static boolean nativeHasMipMap(long nativeBitmap) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -393,7 +393,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeGetPixel(int nativeBitmap, int x, int y,
+    /*package*/ static int nativeGetPixel(long nativeBitmap, int x, int y,
             boolean isPremultiplied) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
@@ -406,7 +406,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeGetPixels(int nativeBitmap, int[] pixels, int offset,
+    /*package*/ static void nativeGetPixels(long nativeBitmap, int[] pixels, int offset,
             int stride, int x, int y, int width, int height, boolean isPremultiplied) {
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -418,7 +418,7 @@
 
 
     @LayoutlibDelegate
-    /*package*/ static void nativeSetPixel(int nativeBitmap, int x, int y, int color,
+    /*package*/ static void nativeSetPixel(long nativeBitmap, int x, int y, int color,
             boolean isPremultiplied) {
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -429,7 +429,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeSetPixels(int nativeBitmap, int[] colors, int offset,
+    /*package*/ static void nativeSetPixels(long nativeBitmap, int[] colors, int offset,
             int stride, int x, int y, int width, int height, boolean isPremultiplied) {
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -440,21 +440,21 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeCopyPixelsToBuffer(int nativeBitmap, Buffer dst) {
+    /*package*/ static void nativeCopyPixelsToBuffer(long nativeBitmap, Buffer dst) {
         // FIXME implement native delegate
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Bitmap.copyPixelsToBuffer is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeCopyPixelsFromBuffer(int nb, Buffer src) {
+    /*package*/ static void nativeCopyPixelsFromBuffer(long nb, Buffer src) {
         // FIXME implement native delegate
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Bitmap.copyPixelsFromBuffer is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeGenerationId(int nativeBitmap) {
+    /*package*/ static int nativeGenerationId(long nativeBitmap) {
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
             return 0;
@@ -474,7 +474,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeWriteToParcel(int nativeBitmap, boolean isMutable,
+    /*package*/ static boolean nativeWriteToParcel(long nativeBitmap, boolean isMutable,
             int density, Parcel p) {
         // This is only called when sending a bitmap through aidl, so really this should not
         // be called.
@@ -485,7 +485,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static Bitmap nativeExtractAlpha(int nativeBitmap, int nativePaint,
+    /*package*/ static Bitmap nativeExtractAlpha(long nativeBitmap, long nativePaint,
             int[] offsetXY) {
         Bitmap_Delegate bitmap = sManager.getDelegate(nativeBitmap);
         if (bitmap == null) {
@@ -513,12 +513,12 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativePrepareToDraw(int nativeBitmap) {
+    /*package*/ static void nativePrepareToDraw(long nativeBitmap) {
         // nothing to be done here.
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeSetHasAlpha(int nativeBitmap, boolean hasAlpha) {
+    /*package*/ static void nativeSetHasAlpha(long nativeBitmap, boolean hasAlpha) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -529,7 +529,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeSetHasMipMap(int nativeBitmap, boolean hasMipMap) {
+    /*package*/ static void nativeSetHasMipMap(long nativeBitmap, boolean hasMipMap) {
         // get the delegate from the native int.
         Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
         if (delegate == null) {
@@ -540,7 +540,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeSameAs(int nb0, int nb1) {
+    /*package*/ static boolean nativeSameAs(long nb0, long nb1) {
         Bitmap_Delegate delegate1 = sManager.getDelegate(nb0);
         if (delegate1 == null) {
             return false;
@@ -593,7 +593,7 @@
     private static Bitmap createBitmap(Bitmap_Delegate delegate,
             Set<BitmapCreateFlags> createFlags, int density) {
         // get its native_int
-        int nativeInt = sManager.addNewDelegate(delegate);
+        long nativeInt = sManager.addNewDelegate(delegate);
 
         int width = delegate.mImage.getWidth();
         int height = delegate.mImage.getHeight();
diff --git a/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java
index 4becba1..d2569c7 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java
@@ -55,7 +55,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeConstructor(float radius, int style) {
+    /*package*/ static long nativeConstructor(float radius, int style) {
         BlurMaskFilter_Delegate newDelegate = new BlurMaskFilter_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index 10ad0a3..9d21866 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -77,7 +77,7 @@
     /**
      * Returns the native delegate associated to a given an int referencing a {@link Canvas} object.
      */
-    public static Canvas_Delegate getDelegate(int native_canvas) {
+    public static Canvas_Delegate getDelegate(long native_canvas) {
         return sManager.getDelegate(native_canvas);
     }
 
@@ -310,7 +310,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int initRaster(int nativeBitmapOrZero) {
+    /*package*/ static long initRaster(long nativeBitmapOrZero) {
         if (nativeBitmapOrZero > 0) {
             // get the Bitmap from the int
             Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero);
@@ -328,7 +328,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void copyNativeCanvasState(int srcCanvas, int dstCanvas) {
+    /*package*/ static void copyNativeCanvasState(long srcCanvas, long dstCanvas) {
         // get the delegate from the native int.
         Canvas_Delegate srcCanvasDelegate = sManager.getDelegate(srcCanvas);
         if (srcCanvasDelegate == null) {
@@ -344,8 +344,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_saveLayer(int nativeCanvas, RectF bounds,
-                                               int paint, int layerFlags) {
+    /*package*/ static long native_saveLayer(long nativeCanvas, RectF bounds,
+                                               long paint, int layerFlags) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
@@ -361,9 +361,9 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_saveLayer(int nativeCanvas, float l,
+    /*package*/ static long native_saveLayer(long nativeCanvas, float l,
                                                float t, float r, float b,
-                                               int paint, int layerFlags) {
+                                               long paint, int layerFlags) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
@@ -380,7 +380,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_saveLayerAlpha(int nativeCanvas,
+    /*package*/ static long native_saveLayerAlpha(long nativeCanvas,
                                                     RectF bounds, int alpha,
                                                     int layerFlags) {
         // get the delegate from the native int.
@@ -393,7 +393,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_saveLayerAlpha(int nativeCanvas, float l,
+    /*package*/ static long native_saveLayerAlpha(long nativeCanvas, float l,
                                                     float t, float r, float b,
                                                     int alpha, int layerFlags) {
         // get the delegate from the native int.
@@ -407,7 +407,7 @@
 
 
     @LayoutlibDelegate
-    /*package*/ static void native_concat(int nCanvas, int nMatrix) {
+    /*package*/ static void native_concat(long nCanvas, long nMatrix) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
         if (canvasDelegate == null) {
@@ -435,7 +435,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setMatrix(int nCanvas, int nMatrix) {
+    /*package*/ static void native_setMatrix(long nCanvas, long nMatrix) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
         if (canvasDelegate == null) {
@@ -465,7 +465,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_clipRect(int nCanvas,
+    /*package*/ static boolean native_clipRect(long nCanvas,
                                                   float left, float top,
                                                   float right, float bottom,
                                                   int regionOp) {
@@ -480,8 +480,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_clipPath(int nativeCanvas,
-                                                  int nativePath,
+    /*package*/ static boolean native_clipPath(long nativeCanvas,
+                                                  long nativePath,
                                                   int regionOp) {
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
@@ -497,8 +497,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_clipRegion(int nativeCanvas,
-                                                    int nativeRegion,
+    /*package*/ static boolean native_clipRegion(long nativeCanvas,
+                                                    long nativeRegion,
                                                     int regionOp) {
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
@@ -514,7 +514,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeSetDrawFilter(int nativeCanvas, int nativeFilter) {
+    /*package*/ static void nativeSetDrawFilter(long nativeCanvas, long nativeFilter) {
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
             return;
@@ -530,7 +530,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_getClipBounds(int nativeCanvas,
+    /*package*/ static boolean native_getClipBounds(long nativeCanvas,
                                                        Rect bounds) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
@@ -551,7 +551,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_getCTM(int canvas, int matrix) {
+    /*package*/ static void native_getCTM(long canvas, long matrix) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas);
         if (canvasDelegate == null) {
@@ -568,21 +568,21 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_quickReject(int nativeCanvas,
+    /*package*/ static boolean native_quickReject(long nativeCanvas,
                                                      RectF rect) {
         // FIXME properly implement quickReject
         return false;
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_quickReject(int nativeCanvas,
-                                                     int path) {
+    /*package*/ static boolean native_quickReject(long nativeCanvas,
+                                                     long path) {
         // FIXME properly implement quickReject
         return false;
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_quickReject(int nativeCanvas,
+    /*package*/ static boolean native_quickReject(long nativeCanvas,
                                                      float left, float top,
                                                      float right, float bottom) {
         // FIXME properly implement quickReject
@@ -590,25 +590,25 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawRGB(int nativeCanvas, int r, int g, int b) {
+    /*package*/ static void native_drawRGB(long nativeCanvas, int r, int g, int b) {
         native_drawColor(nativeCanvas, 0xFF000000 | r << 16 | (g&0xFF) << 8 | (b&0xFF),
                 PorterDuff.Mode.SRC_OVER.nativeInt);
 
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawARGB(int nativeCanvas, int a, int r, int g, int b) {
+    /*package*/ static void native_drawARGB(long nativeCanvas, int a, int r, int g, int b) {
         native_drawColor(nativeCanvas, a << 24 | (r&0xFF) << 16 | (g&0xFF) << 8 | (b&0xFF),
                 PorterDuff.Mode.SRC_OVER.nativeInt);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawColor(int nativeCanvas, int color) {
+    /*package*/ static void native_drawColor(long nativeCanvas, int color) {
         native_drawColor(nativeCanvas, color, PorterDuff.Mode.SRC_OVER.nativeInt);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawColor(int nativeCanvas, final int color, final int mode) {
+    /*package*/ static void native_drawColor(long nativeCanvas, final int color, final int mode) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
@@ -639,16 +639,16 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawPaint(int nativeCanvas, int paint) {
+    /*package*/ static void native_drawPaint(long nativeCanvas, long paint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawPaint is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawLine(int nativeCanvas,
+    /*package*/ static void native_drawLine(long nativeCanvas,
             final float startX, final float startY, final float stopX, final float stopY,
-            int paint) {
+            long paint) {
 
         draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                 new GcSnapshot.Drawable() {
@@ -660,14 +660,13 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawRect(int nativeCanvas, RectF rect,
-                                               int paint) {
+    /*package*/ static void native_drawRect(long nativeCanvas, RectF rect, long paint) {
         native_drawRect(nativeCanvas, rect.left, rect.top, rect.right, rect.bottom, paint);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawRect(int nativeCanvas,
-            final float left, final float top, final float right, final float bottom, int paint) {
+    /*package*/ static void native_drawRect(long nativeCanvas,
+            final float left, final float top, final float right, final float bottom, long paint) {
 
         draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                 new GcSnapshot.Drawable() {
@@ -692,7 +691,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawOval(int nativeCanvas, final RectF oval, int paint) {
+    /*package*/ static void native_drawOval(long nativeCanvas, final RectF oval, long paint) {
         if (oval.right > oval.left && oval.bottom > oval.top) {
             draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                     new GcSnapshot.Drawable() {
@@ -718,17 +717,17 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawCircle(int nativeCanvas,
-            float cx, float cy, float radius, int paint) {
+    /*package*/ static void native_drawCircle(long nativeCanvas,
+            float cx, float cy, float radius, long paint) {
         native_drawOval(nativeCanvas,
                 new RectF(cx - radius, cy - radius, cx + radius, cy + radius),
                 paint);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawArc(int nativeCanvas,
+    /*package*/ static void native_drawArc(long nativeCanvas,
             final RectF oval, final float startAngle, final float sweep,
-            final boolean useCenter, int paint) {
+            final boolean useCenter, long paint) {
         if (oval.right > oval.left && oval.bottom > oval.top) {
             draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                     new GcSnapshot.Drawable() {
@@ -757,8 +756,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawRoundRect(int nativeCanvas,
-            final RectF rect, final float rx, final float ry, int paint) {
+    /*package*/ static void native_drawRoundRect(long nativeCanvas,
+            final RectF rect, final float rx, final float ry, long paint) {
 
         draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                 new GcSnapshot.Drawable() {
@@ -787,7 +786,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawPath(int nativeCanvas, int path, int paint) {
+    /*package*/ static void native_drawPath(long nativeCanvas, int path, long paint) {
         final Path_Delegate pathDelegate = Path_Delegate.getDelegate(path);
         if (pathDelegate == null) {
             return;
@@ -814,9 +813,9 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawBitmap(Canvas thisCanvas, int nativeCanvas, int bitmap,
+    /*package*/ static void native_drawBitmap(Canvas thisCanvas, long nativeCanvas, long bitmap,
                                                  float left, float top,
-                                                 int nativePaintOrZero,
+                                                 long nativePaintOrZero,
                                                  int canvasDensity,
                                                  int screenDensity,
                                                  int bitmapDensity) {
@@ -836,9 +835,9 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawBitmap(Canvas thisCanvas, int nativeCanvas, int bitmap,
+    /*package*/ static void native_drawBitmap(Canvas thisCanvas, long nativeCanvas, long bitmap,
                                                  Rect src, RectF dst,
-                                                 int nativePaintOrZero,
+                                                 long nativePaintOrZero,
                                                  int screenDensity,
                                                  int bitmapDensity) {
         // get the delegate from the native int.
@@ -861,9 +860,9 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawBitmap(int nativeCanvas, int bitmap,
+    /*package*/ static void native_drawBitmap(long nativeCanvas, long bitmap,
                                                  Rect src, Rect dst,
-                                                 int nativePaintOrZero,
+                                                 long nativePaintOrZero,
                                                  int screenDensity,
                                                  int bitmapDensity) {
         // get the delegate from the native int.
@@ -886,11 +885,11 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawBitmap(int nativeCanvas, int[] colors,
+    /*package*/ static void native_drawBitmap(long nativeCanvas, int[] colors,
                                                 int offset, int stride, final float x,
                                                  final float y, int width, int height,
                                                  boolean hasAlpha,
-                                                 int nativePaintOrZero) {
+                                                 long nativePaintOrZero) {
 
         // create a temp BufferedImage containing the content.
         final BufferedImage image = new BufferedImage(width, height,
@@ -912,8 +911,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDrawBitmapMatrix(int nCanvas, int nBitmap,
-                                                      int nMatrix, int nPaint) {
+    /*package*/ static void nativeDrawBitmapMatrix(long nCanvas, long nBitmap,
+                                                      long nMatrix, long nPaint) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
         if (canvasDelegate == null) {
@@ -953,30 +952,30 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDrawBitmapMesh(int nCanvas, int nBitmap,
+    /*package*/ static void nativeDrawBitmapMesh(long nCanvas, long nBitmap,
             int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors,
-            int colorOffset, int nPaint) {
+            int colorOffset, long nPaint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawBitmapMesh is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDrawVertices(int nCanvas, int mode, int n,
+    /*package*/ static void nativeDrawVertices(long nCanvas, int mode, int n,
             float[] verts, int vertOffset,
             float[] texs, int texOffset,
             int[] colors, int colorOffset,
             short[] indices, int indexOffset,
-            int indexCount, int nPaint) {
+            int indexCount, long nPaint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawVertices is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawText(int nativeCanvas,
+    /*package*/ static void native_drawText(long nativeCanvas,
             final char[] text, final int index, final int count,
-            final float startX, final float startY, final int flags, int paint) {
+            final float startX, final float startY, final int flags, long paint) {
 
         draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/,
                 new GcSnapshot.Drawable() {
@@ -1006,8 +1005,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawText(int nativeCanvas, String text,
-            int start, int end, float x, float y, final int flags, int paint) {
+    /*package*/ static void native_drawText(long nativeCanvas, String text,
+            int start, int end, float x, float y, final int flags, long paint) {
         int count = end - start;
         char[] buffer = TemporaryBuffer.obtain(count);
         TextUtils.getChars(text, start, end, buffer, 0);
@@ -1016,9 +1015,9 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawTextRun(int nativeCanvas, String text,
+    /*package*/ static void native_drawTextRun(long nativeCanvas, String text,
             int start, int end, int contextStart, int contextEnd,
-            float x, float y, int flags, int paint) {
+            float x, float y, int flags, long paint) {
         int count = end - start;
         char[] buffer = TemporaryBuffer.obtain(count);
         TextUtils.getChars(text, start, end, buffer, 0);
@@ -1027,56 +1026,56 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawTextRun(int nativeCanvas, char[] text,
+    /*package*/ static void native_drawTextRun(long nativeCanvas, char[] text,
             int start, int count, int contextStart, int contextCount,
-            float x, float y, int flags, int paint) {
+            float x, float y, int flags, long paint) {
         native_drawText(nativeCanvas, text, start, count, x, y, flags, paint);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawPosText(int nativeCanvas,
+    /*package*/ static void native_drawPosText(long nativeCanvas,
                                                   char[] text, int index,
                                                   int count, float[] pos,
-                                                  int paint) {
+                                                  long paint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawPosText is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawPosText(int nativeCanvas,
+    /*package*/ static void native_drawPosText(long nativeCanvas,
                                                   String text, float[] pos,
-                                                  int paint) {
+                                                  long paint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawPosText is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawTextOnPath(int nativeCanvas,
+    /*package*/ static void native_drawTextOnPath(long nativeCanvas,
                                                      char[] text, int index,
-                                                     int count, int path,
+                                                     int count, long path,
                                                      float hOffset,
                                                      float vOffset, int bidiFlags,
-                                                     int paint) {
+                                                     long paint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawTextOnPath is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_drawTextOnPath(int nativeCanvas,
-                                                     String text, int path,
+    /*package*/ static void native_drawTextOnPath(long nativeCanvas,
+                                                     String text, long path,
                                                      float hOffset,
                                                      float vOffset,
-                                                     int flags, int paint) {
+                                                     int flags, long paint) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Canvas.drawTextOnPath is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int nativeCanvas) {
+    /*package*/ static void finalizer(long nativeCanvas) {
         // get the delegate from the native int so that it can be disposed.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
         if (canvasDelegate == null) {
@@ -1096,7 +1095,7 @@
      * <p>Note that the drawable may actually be executed several times if there are
      * layers involved (see {@link #saveLayer(RectF, int, int)}.
      */
-    private static void draw(int nCanvas, int nPaint, boolean compositeOnly, boolean forceSrcMode,
+    private static void draw(long nCanvas, long nPaint, boolean compositeOnly, boolean forceSrcMode,
             GcSnapshot.Drawable drawable) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
@@ -1116,7 +1115,7 @@
      * <p>Note that the drawable may actually be executed several times if there are
      * layers involved (see {@link #saveLayer(RectF, int, int)}.
      */
-    private static void draw(int nCanvas, GcSnapshot.Drawable drawable) {
+    private static void draw(long nCanvas, GcSnapshot.Drawable drawable) {
         // get the delegate from the native int.
         Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
         if (canvasDelegate == null) {
@@ -1194,9 +1193,9 @@
     }
 
     private static void drawBitmap(
-            int nativeCanvas,
+            long nativeCanvas,
             Bitmap_Delegate bitmap,
-            int nativePaintOrZero,
+            long nativePaintOrZero,
             final int sleft, final int stop, final int sright, final int sbottom,
             final int dleft, final int dtop, final int dright, final int dbottom) {
         // get the delegate from the native int.
diff --git a/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java
index e5a7ab6..d6b3da1 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java
@@ -46,7 +46,7 @@
 
     // ---- Public Helper methods ----
 
-    public static ColorFilter_Delegate getDelegate(int nativeShader) {
+    public static ColorFilter_Delegate getDelegate(long nativeShader) {
         return sManager.getDelegate(nativeShader);
     }
 
@@ -56,7 +56,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int native_instance, int nativeColorFilter) {
+    /*package*/ static void finalizer(long native_instance, long nativeColorFilter) {
         sManager.removeJavaReferenceFor(native_instance);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java
index 2de344b..ca8f450 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java
@@ -55,13 +55,13 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeColorMatrixFilter(float[] array) {
+    /*package*/ static long nativeColorMatrixFilter(float[] array) {
         ColorMatrixColorFilter_Delegate newDelegate = new ColorMatrixColorFilter_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nColorMatrixFilter(int nativeFilter, float[] array) {
+    /*package*/ static long nColorMatrixFilter(long nativeFilter, float[] array) {
         // pass
         return 0;
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/ComposePathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ComposePathEffect_Delegate.java
index 7c04a87..bc3df7d 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ComposePathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ComposePathEffect_Delegate.java
@@ -62,7 +62,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(int outerpe, int innerpe) {
+    /*package*/ static long nativeCreate(long outerpe, long innerpe) {
         ComposePathEffect_Delegate newDelegate = new ComposePathEffect_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java
index f6e1d00..fae8aef 100644
--- a/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/ComposeShader_Delegate.java
@@ -63,15 +63,15 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate1(int native_shaderA, int native_shaderB,
-            int native_mode) {
+    /*package*/ static long nativeCreate1(long native_shaderA, long native_shaderB,
+            long native_mode) {
         // FIXME not supported yet.
         ComposeShader_Delegate newDelegate = new ComposeShader_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate2(int native_shaderA, int native_shaderB,
+    /*package*/ static long nativeCreate2(long native_shaderA, long native_shaderB,
             int porterDuffMode) {
         // FIXME not supported yet.
         ComposeShader_Delegate newDelegate = new ComposeShader_Delegate();
@@ -79,15 +79,15 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate1(int native_shader, int native_skiaShaderA,
-            int native_skiaShaderB, int native_mode) {
+    /*package*/ static long nativePostCreate1(long native_shader, long native_skiaShaderA,
+            long native_skiaShaderB, long native_mode) {
         // pass, not needed.
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate2(int native_shader, int native_skiaShaderA,
-            int native_skiaShaderB, int porterDuffMode) {
+    /*package*/ static long nativePostCreate2(long native_shader, long native_skiaShaderA,
+            long native_skiaShaderB, int porterDuffMode) {
         // pass, not needed.
         return 0;
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/CornerPathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/CornerPathEffect_Delegate.java
index b0f8168..73745c3 100644
--- a/tools/layoutlib/bridge/src/android/graphics/CornerPathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/CornerPathEffect_Delegate.java
@@ -62,7 +62,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(float radius) {
+    /*package*/ static long nativeCreate(float radius) {
         CornerPathEffect_Delegate newDelegate = new CornerPathEffect_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
index d97c2ec..881afde 100644
--- a/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/DashPathEffect_Delegate.java
@@ -73,7 +73,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(float intervals[], float phase) {
+    /*package*/ static long nativeCreate(float intervals[], float phase) {
         DashPathEffect_Delegate newDelegate = new DashPathEffect_Delegate(intervals, phase);
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/DiscretePathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/DiscretePathEffect_Delegate.java
index ec4a810..46109f3 100644
--- a/tools/layoutlib/bridge/src/android/graphics/DiscretePathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/DiscretePathEffect_Delegate.java
@@ -62,7 +62,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(float length, float deviation) {
+    /*package*/ static long nativeCreate(float length, float deviation) {
         DiscretePathEffect_Delegate newDelegate = new DiscretePathEffect_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java
index 870c46b..2e10740 100644
--- a/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java
@@ -46,7 +46,7 @@
 
     // ---- Public Helper methods ----
 
-    public static DrawFilter_Delegate getDelegate(int nativeDrawFilter) {
+    public static DrawFilter_Delegate getDelegate(long nativeDrawFilter) {
         return sManager.getDelegate(nativeDrawFilter);
     }
 
@@ -56,7 +56,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDestructor(int nativeDrawFilter) {
+    /*package*/ static void nativeDestructor(long nativeDrawFilter) {
         sManager.removeJavaReferenceFor(nativeDrawFilter);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java
index ebc1c1d..e5040cc 100644
--- a/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java
@@ -55,7 +55,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeConstructor(float[] direction, float ambient,
+    /*package*/ static long nativeConstructor(float[] direction, float ambient,
             float specular, float blurRadius) {
         EmbossMaskFilter_Delegate newDelegate = new EmbossMaskFilter_Delegate();
         return sManager.addNewDelegate(newDelegate);
diff --git a/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java
index 51e0576..10cc572 100644
--- a/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java
@@ -55,13 +55,13 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeConstructor() {
+    /*package*/ static long nativeConstructor() {
         LayerRasterizer_Delegate newDelegate = new LayerRasterizer_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeAddLayer(int native_layer, int native_paint, float dx, float dy) {
+    /*package*/ static void nativeAddLayer(long native_layer, long native_paint, float dx, float dy) {
 
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java
index 0ee883d..defaac3 100644
--- a/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java
@@ -55,13 +55,13 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int native_CreateLightingFilter(int mul, int add) {
+    /*package*/ static long native_CreateLightingFilter(int mul, int add) {
         LightingColorFilter_Delegate newDelegate = new LightingColorFilter_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nCreateLightingFilter(int nativeFilter, int mul, int add) {
+    /*package*/ static int nCreateLightingFilter(long nativeFilter, int mul, int add) {
         // pass
         return 0;
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
index f117fca..ac77377 100644
--- a/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/LinearGradient_Delegate.java
@@ -54,7 +54,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate1(LinearGradient thisGradient,
+    /*package*/ static long nativeCreate1(LinearGradient thisGradient,
             float x0, float y0, float x1, float y1,
             int colors[], float positions[], int tileMode) {
         LinearGradient_Delegate newDelegate = new LinearGradient_Delegate(x0, y0, x1, y1,
@@ -63,7 +63,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate2(LinearGradient thisGradient,
+    /*package*/ static long nativeCreate2(LinearGradient thisGradient,
             float x0, float y0, float x1, float y1,
             int color0, int color1, int tileMode) {
         return nativeCreate1(thisGradient,
@@ -72,16 +72,16 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate1(LinearGradient thisGradient,
-            int native_shader, float x0, float y0, float x1, float y1,
+    /*package*/ static long nativePostCreate1(LinearGradient thisGradient,
+            long native_shader, float x0, float y0, float x1, float y1,
             int colors[], float positions[], int tileMode) {
         // nothing to be done here.
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate2(LinearGradient thisGradient,
-            int native_shader, float x0, float y0, float x1, float y1,
+    /*package*/ static long nativePostCreate2(LinearGradient thisGradient,
+            long native_shader, float x0, float y0, float x1, float y1,
             int color0, int color1, int tileMode) {
         // nothing to be done here.
         return 0;
diff --git a/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java
index c2f27e4..e726c59 100644
--- a/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java
@@ -46,7 +46,7 @@
 
     // ---- Public Helper methods ----
 
-    public static MaskFilter_Delegate getDelegate(int nativeShader) {
+    public static MaskFilter_Delegate getDelegate(long nativeShader) {
         return sManager.getDelegate(nativeShader);
     }
 
@@ -56,7 +56,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDestructor(int native_filter) {
+    /*package*/ static void nativeDestructor(long native_filter) {
         sManager.removeJavaReferenceFor(native_filter);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
index 5df2a21..1d66586 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java
@@ -53,7 +53,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Matrix_Delegate getDelegate(int native_instance) {
+    public static Matrix_Delegate getDelegate(long native_instance) {
         return sManager.getDelegate(native_instance);
     }
 
@@ -174,7 +174,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int native_create(int native_src_or_zero) {
+    /*package*/ static long native_create(long native_src_or_zero) {
         // create the delegate
         Matrix_Delegate newDelegate = new Matrix_Delegate();
 
@@ -193,7 +193,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_isIdentity(int native_object) {
+    /*package*/ static boolean native_isIdentity(long native_object) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -203,7 +203,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_rectStaysRect(int native_object) {
+    /*package*/ static boolean native_rectStaysRect(long native_object) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return true;
@@ -213,7 +213,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_reset(int native_object) {
+    /*package*/ static void native_reset(long native_object) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -223,7 +223,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_set(int native_object, int other) {
+    /*package*/ static void native_set(long native_object, long other) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -238,7 +238,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setTranslate(int native_object, float dx, float dy) {
+    /*package*/ static void native_setTranslate(long native_object, float dx, float dy) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -248,7 +248,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setScale(int native_object, float sx, float sy,
+    /*package*/ static void native_setScale(long native_object, float sx, float sy,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -259,7 +259,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setScale(int native_object, float sx, float sy) {
+    /*package*/ static void native_setScale(long native_object, float sx, float sy) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -277,7 +277,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setRotate(int native_object, float degrees, float px, float py) {
+    /*package*/ static void native_setRotate(long native_object, float degrees, float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -287,7 +287,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setRotate(int native_object, float degrees) {
+    /*package*/ static void native_setRotate(long native_object, float degrees) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -297,7 +297,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setSinCos(int native_object, float sinValue, float cosValue,
+    /*package*/ static void native_setSinCos(long native_object, float sinValue, float cosValue,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -316,7 +316,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setSinCos(int native_object, float sinValue, float cosValue) {
+    /*package*/ static void native_setSinCos(long native_object, float sinValue, float cosValue) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -326,7 +326,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setSkew(int native_object, float kx, float ky,
+    /*package*/ static void native_setSkew(long native_object, float kx, float ky,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -337,7 +337,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setSkew(int native_object, float kx, float ky) {
+    /*package*/ static void native_setSkew(long native_object, float kx, float ky) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -355,7 +355,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_setConcat(int native_object, int a, int b) {
+    /*package*/ static boolean native_setConcat(long native_object, long a, long b) {
         if (a == native_object) {
             return native_preConcat(native_object, b);
         } else if (b == native_object) {
@@ -383,7 +383,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preTranslate(int native_object, float dx, float dy) {
+    /*package*/ static boolean native_preTranslate(long native_object, float dx, float dy) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -394,7 +394,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preScale(int native_object, float sx, float sy,
+    /*package*/ static boolean native_preScale(long native_object, float sx, float sy,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -406,7 +406,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preScale(int native_object, float sx, float sy) {
+    /*package*/ static boolean native_preScale(long native_object, float sx, float sy) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -417,7 +417,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preRotate(int native_object, float degrees,
+    /*package*/ static boolean native_preRotate(long native_object, float degrees,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -429,7 +429,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preRotate(int native_object, float degrees) {
+    /*package*/ static boolean native_preRotate(long native_object, float degrees) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -444,7 +444,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preSkew(int native_object, float kx, float ky,
+    /*package*/ static boolean native_preSkew(long native_object, float kx, float ky,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -456,7 +456,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preSkew(int native_object, float kx, float ky) {
+    /*package*/ static boolean native_preSkew(long native_object, float kx, float ky) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -467,7 +467,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_preConcat(int native_object, int other_matrix) {
+    /*package*/ static boolean native_preConcat(long native_object, long other_matrix) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -483,7 +483,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postTranslate(int native_object, float dx, float dy) {
+    /*package*/ static boolean native_postTranslate(long native_object, float dx, float dy) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -494,7 +494,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postScale(int native_object, float sx, float sy,
+    /*package*/ static boolean native_postScale(long native_object, float sx, float sy,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -506,7 +506,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postScale(int native_object, float sx, float sy) {
+    /*package*/ static boolean native_postScale(long native_object, float sx, float sy) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -517,7 +517,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postRotate(int native_object, float degrees,
+    /*package*/ static boolean native_postRotate(long native_object, float degrees,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -529,7 +529,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postRotate(int native_object, float degrees) {
+    /*package*/ static boolean native_postRotate(long native_object, float degrees) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -540,7 +540,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postSkew(int native_object, float kx, float ky,
+    /*package*/ static boolean native_postSkew(long native_object, float kx, float ky,
             float px, float py) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -552,7 +552,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postSkew(int native_object, float kx, float ky) {
+    /*package*/ static boolean native_postSkew(long native_object, float kx, float ky) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -563,7 +563,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_postConcat(int native_object, int other_matrix) {
+    /*package*/ static boolean native_postConcat(long native_object, long other_matrix) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -579,7 +579,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_setRectToRect(int native_object, RectF src,
+    /*package*/ static boolean native_setRectToRect(long native_object, RectF src,
             RectF dst, int stf) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -644,7 +644,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_setPolyToPoly(int native_object, float[] src, int srcIndex,
+    /*package*/ static boolean native_setPolyToPoly(long native_object, float[] src, int srcIndex,
             float[] dst, int dstIndex, int pointCount) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -654,7 +654,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_invert(int native_object, int inverse) {
+    /*package*/ static boolean native_invert(long native_object, int inverse) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -682,7 +682,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_mapPoints(int native_object, float[] dst, int dstIndex,
+    /*package*/ static void native_mapPoints(long native_object, float[] dst, int dstIndex,
             float[] src, int srcIndex, int ptCount, boolean isPts) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
@@ -697,7 +697,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_mapRect(int native_object, RectF dst, RectF src) {
+    /*package*/ static boolean native_mapRect(long native_object, RectF dst, RectF src) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return false;
@@ -707,7 +707,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static float native_mapRadius(int native_object, float radius) {
+    /*package*/ static float native_mapRadius(long native_object, float radius) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return 0.f;
@@ -723,7 +723,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_getValues(int native_object, float[] values) {
+    /*package*/ static void native_getValues(long native_object, float[] values) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -733,7 +733,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setValues(int native_object, float[] values) {
+    /*package*/ static void native_setValues(long native_object, float[] values) {
         Matrix_Delegate d = sManager.getDelegate(native_object);
         if (d == null) {
             return;
@@ -743,7 +743,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_equals(int native_a, int native_b) {
+    /*package*/ static boolean native_equals(long native_a, long native_b) {
         Matrix_Delegate a = sManager.getDelegate(native_a);
         if (a == null) {
             return false;
@@ -764,7 +764,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int native_instance) {
+    /*package*/ static void finalizer(long native_instance) {
         sManager.removeJavaReferenceFor(native_instance);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
index a79ec8f..74b2893 100644
--- a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java
@@ -158,7 +158,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int validateNinePatchChunk(int bitmap, byte[] chunk) {
+    /*package*/ static long validateNinePatchChunk(long bitmap, byte[] chunk) {
         // the default JNI implementation only checks that the byte[] has the same
         // size as the C struct it represent. Since we cannot do the same check (serialization
         // will return different size depending on content), we do nothing.
@@ -168,13 +168,13 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeFinalize(int chunk) {
+    /*package*/ static void nativeFinalize(long chunk) {
         sManager.removeJavaReferenceFor(chunk);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDraw(int canvas_instance, RectF loc, int bitmap_instance,
-            int chunk, int paint_instance_or_null, int destDensity, int srcDensity) {
+    /*package*/ static void nativeDraw(long canvas_instance, RectF loc, long bitmap_instance,
+            long chunk, long paint_instance_or_null, int destDensity, int srcDensity) {
         draw(canvas_instance,
                 (int) loc.left, (int) loc.top, (int) loc.right, (int) loc.bottom,
                 bitmap_instance, chunk, paint_instance_or_null,
@@ -182,8 +182,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDraw(int canvas_instance, Rect loc, int bitmap_instance,
-            int chunk, int paint_instance_or_null, int destDensity, int srcDensity) {
+    /*package*/ static void nativeDraw(long canvas_instance, Rect loc, long bitmap_instance,
+            long chunk, long paint_instance_or_null, int destDensity, int srcDensity) {
         draw(canvas_instance,
                 loc.left, loc.top, loc.right, loc.bottom,
                 bitmap_instance, chunk, paint_instance_or_null,
@@ -191,15 +191,15 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeGetTransparentRegion(int bitmap, int chunk, Rect location) {
+    /*package*/ static long nativeGetTransparentRegion(long bitmap, long chunk, Rect location) {
         return 0;
     }
 
     // ---- Private Helper methods ----
 
-    private static void draw(int canvas_instance,
+    private static void draw(long canvas_instance,
             final int left, final int top, final int right, final int bottom,
-            int bitmap_instance, int chunk, int paint_instance_or_null,
+            long bitmap_instance, long chunk, long paint_instance_or_null,
             final int destDensity, final int srcDensity) {
         // get the delegate from the native int.
         final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance);
diff --git a/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java
index 71d346a..fa20746 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java
@@ -55,7 +55,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeConstructor(int clearBits, int setBits) {
+    /*package*/ static long nativeConstructor(int clearBits, int setBits) {
         PaintFlagsDrawFilter_Delegate newDelegate = new PaintFlagsDrawFilter_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
index 4ad1a17..7007b71 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java
@@ -96,7 +96,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Paint_Delegate getDelegate(int native_paint) {
+    public static Paint_Delegate getDelegate(long native_paint) {
         return sManager.getDelegate(native_paint);
     }
 
@@ -642,13 +642,13 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_init() {
+    /*package*/ static long native_init() {
         Paint_Delegate newDelegate = new Paint_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_initWithPaint(int paint) {
+    /*package*/ static long native_initWithPaint(long paint) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(paint);
         if (delegate == null) {
@@ -660,7 +660,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_reset(int native_object) {
+    /*package*/ static void native_reset(long native_object) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -671,7 +671,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_set(int native_dst, int native_src) {
+    /*package*/ static void native_set(long native_dst, long native_src) {
         // get the delegate from the native int.
         Paint_Delegate delegate_dst = sManager.getDelegate(native_dst);
         if (delegate_dst == null) {
@@ -688,7 +688,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getStyle(int native_object) {
+    /*package*/ static long native_getStyle(long native_object) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -699,7 +699,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setStyle(int native_object, int style) {
+    /*package*/ static void native_setStyle(long native_object, int style) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -710,7 +710,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getStrokeCap(int native_object) {
+    /*package*/ static long native_getStrokeCap(long native_object) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -721,7 +721,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setStrokeCap(int native_object, int cap) {
+    /*package*/ static void native_setStrokeCap(long native_object, int cap) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -732,7 +732,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getStrokeJoin(int native_object) {
+    /*package*/ static long native_getStrokeJoin(long native_object) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -743,7 +743,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setStrokeJoin(int native_object, int join) {
+    /*package*/ static void native_setStrokeJoin(long native_object, int join) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -754,7 +754,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_getFillPath(int native_object, int src, int dst) {
+    /*package*/ static boolean native_getFillPath(long native_object, long src, long dst) {
         Paint_Delegate paint = sManager.getDelegate(native_object);
         if (paint == null) {
             return false;
@@ -780,7 +780,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setShader(int native_object, int shader) {
+    /*package*/ static long native_setShader(long native_object, long shader) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -793,7 +793,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setColorFilter(int native_object, int filter) {
+    /*package*/ static long native_setColorFilter(long native_object, long filter) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -812,7 +812,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setXfermode(int native_object, int xfermode) {
+    /*package*/ static long native_setXfermode(long native_object, long xfermode) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -825,7 +825,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setPathEffect(int native_object, int effect) {
+    /*package*/ static long native_setPathEffect(long native_object, long effect) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -838,7 +838,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setMaskFilter(int native_object, int maskfilter) {
+    /*package*/ static long native_setMaskFilter(long native_object, long maskfilter) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -857,7 +857,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setTypeface(int native_object, int typeface) {
+    /*package*/ static long native_setTypeface(long native_object, long typeface) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -870,7 +870,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_setRasterizer(int native_object, int rasterizer) {
+    /*package*/ static long native_setRasterizer(long native_object, long rasterizer) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -889,7 +889,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getTextAlign(int native_object) {
+    /*package*/ static long native_getTextAlign(long native_object) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -900,7 +900,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setTextAlign(int native_object, int align) {
+    /*package*/ static void native_setTextAlign(long native_object, int align) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -911,7 +911,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setTextLocale(int native_object, String locale) {
+    /*package*/ static void native_setTextLocale(long native_object, String locale) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
         if (delegate == null) {
@@ -922,7 +922,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getTextWidths(int native_object, char[] text, int index,
+    /*package*/ static long native_getTextWidths(long native_object, char[] text, int index,
             int count, int bidiFlags, float[] widths) {
         // get the delegate from the native int.
         Paint_Delegate delegate = sManager.getDelegate(native_object);
@@ -964,21 +964,21 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getTextWidths(int native_object, String text, int start,
+    /*package*/ static long native_getTextWidths(long native_object, String text, int start,
             int end, int bidiFlags, float[] widths) {
         return native_getTextWidths(native_object, text.toCharArray(), start, end - start,
                 bidiFlags, widths);
     }
 
     @LayoutlibDelegate
-    /* package */static int native_getTextGlyphs(int native_object, String text, int start,
+    /* package */static long native_getTextGlyphs(long native_object, String text, int start,
             int end, int contextStart, int contextEnd, int flags, char[] glyphs) {
         // FIXME
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static float native_getTextRunAdvances(int native_object,
+    /*package*/ static float native_getTextRunAdvances(long native_object,
             char[] text, int index, int count, int contextIndex, int contextCount,
             int flags, float[] advances, int advancesIndex) {
 
@@ -999,7 +999,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static float native_getTextRunAdvances(int native_object,
+    /*package*/ static float native_getTextRunAdvances(long native_object,
             String text, int start, int end, int contextStart, int contextEnd,
             int flags, float[] advances, int advancesIndex) {
         // FIXME: support contextStart and contextEnd
@@ -1012,7 +1012,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, char[] text,
+    /*package*/ static long native_getTextRunCursor(Paint thisPaint, long native_object, char[] text,
             int contextStart, int contextLength, int flags, int offset, int cursorOpt) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -1021,7 +1021,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, String text,
+    /*package*/ static long native_getTextRunCursor(Paint thisPaint, long native_object, String text,
             int contextStart, int contextEnd, int flags, int offset, int cursorOpt) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
@@ -1030,30 +1030,30 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_getTextPath(int native_object, int bidiFlags,
-                char[] text, int index, int count, float x, float y, int path) {
+    /*package*/ static void native_getTextPath(long native_object, int bidiFlags,
+                char[] text, int index, int count, float x, float y, long path) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Paint.getTextPath is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_getTextPath(int native_object, int bidiFlags,
-            String text, int start, int end, float x, float y, int path) {
+    /*package*/ static void native_getTextPath(long native_object, int bidiFlags,
+            String text, int start, int end, float x, float y, long path) {
         // FIXME
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Paint.getTextPath is not supported.", null, null /*data*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start,
+    /*package*/ static void nativeGetStringBounds(long nativePaint, String text, int start,
             int end, int bidiFlags, Rect bounds) {
         nativeGetCharArrayBounds(nativePaint, text.toCharArray(), start, end - start, bidiFlags,
                 bounds);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index,
+    /*package*/ static void nativeGetCharArrayBounds(long nativePaint, char[] text, int index,
             int count, int bidiFlags, Rect bounds) {
 
         // get the delegate from the native int.
@@ -1065,7 +1065,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int nativePaint) {
+    /*package*/ static void finalizer(long nativePaint) {
         sManager.removeJavaReferenceFor(nativePaint);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/PathDashPathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PathDashPathEffect_Delegate.java
index c448f0e..fd9ba62e 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PathDashPathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PathDashPathEffect_Delegate.java
@@ -62,7 +62,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(int native_path, float advance, float phase,
+    /*package*/ static long nativeCreate(long native_path, float advance, float phase,
             int native_style) {
         PathDashPathEffect_Delegate newDelegate = new PathDashPathEffect_Delegate();
         return sManager.addNewDelegate(newDelegate);
diff --git a/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java
index bd2b6de..000481e 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PathEffect_Delegate.java
@@ -48,7 +48,7 @@
 
     // ---- Public Helper methods ----
 
-    public static PathEffect_Delegate getDelegate(int nativeShader) {
+    public static PathEffect_Delegate getDelegate(long nativeShader) {
         return sManager.getDelegate(nativeShader);
     }
 
@@ -60,7 +60,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDestructor(int native_patheffect) {
+    /*package*/ static void nativeDestructor(long native_patheffect) {
         sManager.removeJavaReferenceFor(native_patheffect);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java
index 9d80be9..4e9c129 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java
@@ -63,7 +63,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Path_Delegate getDelegate(int nPath) {
+    public static Path_Delegate getDelegate(long nPath) {
         return sManager.getDelegate(nPath);
     }
 
@@ -88,7 +88,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int init1() {
+    /*package*/ static long init1() {
         // create the delegate
         Path_Delegate newDelegate = new Path_Delegate();
 
@@ -96,7 +96,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int init2(int nPath) {
+    /*package*/ static long init2(long nPath) {
         // create the delegate
         Path_Delegate newDelegate = new Path_Delegate();
 
@@ -110,7 +110,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_reset(int nPath) {
+    /*package*/ static void native_reset(long nPath) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -120,14 +120,14 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_rewind(int nPath) {
+    /*package*/ static void native_rewind(long nPath) {
         // call out to reset since there's nothing to optimize in
         // terms of data structs.
         native_reset(nPath);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_set(int native_dst, int native_src) {
+    /*package*/ static void native_set(long native_dst, long native_src) {
         Path_Delegate pathDstDelegate = sManager.getDelegate(native_dst);
         if (pathDstDelegate == null) {
             return;
@@ -142,7 +142,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int native_getFillType(int nPath) {
+    /*package*/ static long native_getFillType(long nPath) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return 0;
@@ -152,7 +152,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setFillType(int nPath, int ft) {
+    /*package*/ static void native_setFillType(long nPath, int ft) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -162,7 +162,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_isEmpty(int nPath) {
+    /*package*/ static boolean native_isEmpty(long nPath) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return true;
@@ -172,7 +172,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_isRect(int nPath, RectF rect) {
+    /*package*/ static boolean native_isRect(long nPath, RectF rect) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return false;
@@ -192,7 +192,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_computeBounds(int nPath, RectF bounds) {
+    /*package*/ static void native_computeBounds(long nPath, RectF bounds) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -202,13 +202,13 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_incReserve(int nPath, int extraPtCount) {
+    /*package*/ static void native_incReserve(long nPath, int extraPtCount) {
         // since we use a java2D path, there's no way to pre-allocate new points,
         // so we do nothing.
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_moveTo(int nPath, float x, float y) {
+    /*package*/ static void native_moveTo(long nPath, float x, float y) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -218,7 +218,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_rMoveTo(int nPath, float dx, float dy) {
+    /*package*/ static void native_rMoveTo(long nPath, float dx, float dy) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -228,7 +228,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_lineTo(int nPath, float x, float y) {
+    /*package*/ static void native_lineTo(long nPath, float x, float y) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -238,7 +238,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_rLineTo(int nPath, float dx, float dy) {
+    /*package*/ static void native_rLineTo(long nPath, float dx, float dy) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -248,7 +248,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_quadTo(int nPath, float x1, float y1, float x2, float y2) {
+    /*package*/ static void native_quadTo(long nPath, float x1, float y1, float x2, float y2) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -258,7 +258,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_rQuadTo(int nPath, float dx1, float dy1, float dx2, float dy2) {
+    /*package*/ static void native_rQuadTo(long nPath, float dx1, float dy1, float dx2, float dy2) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -268,7 +268,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_cubicTo(int nPath, float x1, float y1,
+    /*package*/ static void native_cubicTo(long nPath, float x1, float y1,
             float x2, float y2, float x3, float y3) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
@@ -279,7 +279,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_rCubicTo(int nPath, float x1, float y1,
+    /*package*/ static void native_rCubicTo(long nPath, float x1, float y1,
             float x2, float y2, float x3, float y3) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
@@ -290,7 +290,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_arcTo(int nPath, RectF oval,
+    /*package*/ static void native_arcTo(long nPath, RectF oval,
                     float startAngle, float sweepAngle, boolean forceMoveTo) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
@@ -301,7 +301,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_close(int nPath) {
+    /*package*/ static void native_close(long nPath) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -311,7 +311,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addRect(int nPath, RectF rect, int dir) {
+    /*package*/ static void native_addRect(long nPath, RectF rect, int dir) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -321,7 +321,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addRect(int nPath,
+    /*package*/ static void native_addRect(long nPath,
             float left, float top, float right, float bottom, int dir) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
@@ -332,7 +332,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addOval(int nPath, RectF oval, int dir) {
+    /*package*/ static void native_addOval(long nPath, RectF oval, int dir) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -343,7 +343,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addCircle(int nPath, float x, float y, float radius, int dir) {
+    /*package*/ static void native_addCircle(long nPath, float x, float y, float radius, int dir) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -355,7 +355,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addArc(int nPath, RectF oval,
+    /*package*/ static void native_addArc(long nPath, RectF oval,
             float startAngle, float sweepAngle) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
@@ -370,7 +370,7 @@
 
     @LayoutlibDelegate
     /*package*/ static void native_addRoundRect(
-            int nPath, RectF rect, float rx, float ry, int dir) {
+            long nPath, RectF rect, float rx, float ry, int dir) {
 
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
@@ -382,7 +382,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addRoundRect(int nPath, RectF rect, float[] radii, int dir) {
+    /*package*/ static void native_addRoundRect(long nPath, RectF rect, float[] radii, int dir) {
         // Java2D doesn't support different rounded corners in each corner, so just use the
         // first value.
         native_addRoundRect(nPath, rect, radii[0], radii[1], dir);
@@ -401,17 +401,17 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addPath(int nPath, int src, float dx, float dy) {
+    /*package*/ static void native_addPath(long nPath, int src, float dx, float dy) {
         addPath(nPath, src, AffineTransform.getTranslateInstance(dx, dy));
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addPath(int nPath, int src) {
+    /*package*/ static void native_addPath(long nPath, int src) {
         addPath(nPath, src, null /*transform*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_addPath(int nPath, int src, int matrix) {
+    /*package*/ static void native_addPath(long nPath, int src, long matrix) {
         Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(matrix);
         if (matrixDelegate == null) {
             return;
@@ -421,7 +421,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_offset(int nPath, float dx, float dy, int dst_path) {
+    /*package*/ static void native_offset(long nPath, float dx, float dy, long dst_path) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -434,12 +434,12 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_offset(int nPath, float dx, float dy) {
+    /*package*/ static void native_offset(long nPath, float dx, float dy) {
         native_offset(nPath, dx, dy, 0);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_setLastPoint(int nPath, float dx, float dy) {
+    /*package*/ static void native_setLastPoint(long nPath, float dx, float dy) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -450,8 +450,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_transform(int nPath, int matrix,
-                                                int dst_path) {
+    /*package*/ static void native_transform(long nPath, long matrix,
+                                                long dst_path) {
         Path_Delegate pathDelegate = sManager.getDelegate(nPath);
         if (pathDelegate == null) {
             return;
@@ -469,18 +469,18 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void native_transform(int nPath, int matrix) {
+    /*package*/ static void native_transform(long nPath, long matrix) {
         native_transform(nPath, matrix, 0);
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean native_op(int nPath1, int nPath2, int op, int result) {
+    /*package*/ static boolean native_op(long nPath1, long nPath2, int op, int result) {
         Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED, "Path.op() not supported", null);
         return false;
     }
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int nPath) {
+    /*package*/ static void finalizer(long nPath) {
         sManager.removeJavaReferenceFor(nPath);
     }
 
@@ -528,7 +528,7 @@
         return null;
     }
 
-    private static void addPath(int destPath, int srcPath, AffineTransform transform) {
+    private static void addPath(long destPath, long srcPath, AffineTransform transform) {
         Path_Delegate destPathDelegate = sManager.getDelegate(destPath);
         if (destPathDelegate == null) {
             return;
diff --git a/tools/layoutlib/bridge/src/android/graphics/PixelXorXfermode_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PixelXorXfermode_Delegate.java
index 4ab044b..f27144f 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PixelXorXfermode_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PixelXorXfermode_Delegate.java
@@ -61,7 +61,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(int opColor) {
+    /*package*/ static long nativeCreate(int opColor) {
         PixelXorXfermode_Delegate newDelegate = new PixelXorXfermode_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java
index c45dbaa..6049919 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java
@@ -55,13 +55,13 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int native_CreatePorterDuffFilter(int srcColor, int porterDuffMode) {
+    /*package*/ static long native_CreatePorterDuffFilter(int srcColor, int porterDuffMode) {
         PorterDuffColorFilter_Delegate newDelegate = new PorterDuffColorFilter_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nCreatePorterDuffFilter(int nativeFilter, int srcColor,
+    /*package*/ static long nCreatePorterDuffFilter(long nativeFilter, int srcColor,
             int porterDuffMode) {
         // pass
         return 0;
diff --git a/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java
index 4301c1a..a89fd57 100644
--- a/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/PorterDuffXfermode_Delegate.java
@@ -127,7 +127,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreateXfermode(int mode) {
+    /*package*/ static long nativeCreateXfermode(int mode) {
         PorterDuffXfermode_Delegate newDelegate = new PorterDuffXfermode_Delegate(mode);
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
index 3fe45fa..4f16dcf 100644
--- a/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/RadialGradient_Delegate.java
@@ -54,7 +54,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate1(float x, float y, float radius,
+    /*package*/ static long nativeCreate1(float x, float y, float radius,
             int colors[], float positions[], int tileMode) {
         RadialGradient_Delegate newDelegate = new RadialGradient_Delegate(x, y, radius,
                 colors, positions, Shader_Delegate.getTileMode(tileMode));
@@ -62,21 +62,21 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate2(float x, float y, float radius,
+    /*package*/ static long nativeCreate2(float x, float y, float radius,
             int color0, int color1, int tileMode) {
         return nativeCreate1(x, y, radius, new int[] { color0, color1 }, null /*positions*/,
                 tileMode);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate1(int native_shader, float x, float y, float radius,
+    /*package*/ static long nativePostCreate1(long native_shader, float x, float y, float radius,
             int colors[], float positions[], int tileMode) {
         // nothing to be done here.
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate2(int native_shader, float x, float y, float radius,
+    /*package*/ static long nativePostCreate2(long native_shader, float x, float y, float radius,
             int color0, int color1, int tileMode) {
         // nothing to be done here.
         return 0;
diff --git a/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java
index 2812b6b..a742840 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java
@@ -46,7 +46,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Rasterizer_Delegate getDelegate(int nativeShader) {
+    public static Rasterizer_Delegate getDelegate(long nativeShader) {
         return sManager.getDelegate(nativeShader);
     }
 
@@ -56,7 +56,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int native_instance) {
+    /*package*/ static void finalizer(long native_instance) {
         sManager.removeJavaReferenceFor(native_instance);
     }
 
diff --git a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
index cb31b8f..ea23649 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Region_Delegate.java
@@ -57,7 +57,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Region_Delegate getDelegate(int nativeShader) {
+    public static Region_Delegate getDelegate(long nativeShader) {
         return sManager.getDelegate(nativeShader);
     }
 
@@ -264,18 +264,18 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeConstructor() {
+    /*package*/ static long nativeConstructor() {
         Region_Delegate newDelegate = new Region_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDestructor(int native_region) {
+    /*package*/ static void nativeDestructor(long native_region) {
         sManager.removeJavaReferenceFor(native_region);
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeSetRegion(int native_dst, int native_src) {
+    /*package*/ static boolean nativeSetRegion(long native_dst, long native_src) {
         Region_Delegate dstRegion = sManager.getDelegate(native_dst);
         if (dstRegion == null) {
             return true;
@@ -293,7 +293,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeSetRect(int native_dst,
+    /*package*/ static boolean nativeSetRect(long native_dst,
             int left, int top, int right, int bottom) {
         Region_Delegate dstRegion = sManager.getDelegate(native_dst);
         if (dstRegion == null) {
@@ -305,7 +305,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeSetPath(int native_dst, int native_path, int native_clip) {
+    /*package*/ static boolean nativeSetPath(long native_dst, long native_path, long native_clip) {
         Region_Delegate dstRegion = sManager.getDelegate(native_dst);
         if (dstRegion == null) {
             return true;
@@ -327,7 +327,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeGetBounds(int native_region, Rect rect) {
+    /*package*/ static boolean nativeGetBounds(long native_region, Rect rect) {
         Region_Delegate region = sManager.getDelegate(native_region);
         if (region == null) {
             return true;
@@ -347,7 +347,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeGetBoundaryPath(int native_region, int native_path) {
+    /*package*/ static boolean nativeGetBoundaryPath(long native_region, long native_path) {
         Region_Delegate region = sManager.getDelegate(native_region);
         if (region == null) {
             return false;
@@ -368,7 +368,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeOp(int native_dst,
+    /*package*/ static boolean nativeOp(long native_dst,
             int left, int top, int right, int bottom, int op) {
         Region_Delegate region = sManager.getDelegate(native_dst);
         if (region == null) {
@@ -387,7 +387,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeOp(int native_dst, Rect rect, int native_region, int op) {
+    /*package*/ static boolean nativeOp(long native_dst, Rect rect, long native_region, int op) {
         Region_Delegate region = sManager.getDelegate(native_dst);
         if (region == null) {
             return false;
@@ -405,8 +405,8 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeOp(int native_dst,
-            int native_region1, int native_region2, int op) {
+    /*package*/ static boolean nativeOp(long native_dst,
+            long native_region1, long native_region2, int op) {
         Region_Delegate dstRegion = sManager.getDelegate(native_dst);
         if (dstRegion == null) {
             return true;
@@ -434,7 +434,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreateFromParcel(Parcel p) {
+    /*package*/ static long nativeCreateFromParcel(Parcel p) {
         // This is only called by Region.CREATOR (Parcelable.Creator<Region>), which is only
         // used during aidl call so really this should not be called.
         Bridge.getLog().error(LayoutLog.TAG_UNSUPPORTED,
@@ -444,7 +444,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeWriteToParcel(int native_region,
+    /*package*/ static boolean nativeWriteToParcel(long native_region,
                                                       Parcel p) {
         // This is only called when sending a region through aidl, so really this should not
         // be called.
@@ -455,7 +455,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static boolean nativeEquals(int native_r1, int native_r2) {
+    /*package*/ static boolean nativeEquals(long native_r1, long native_r2) {
         Region_Delegate region1 = sManager.getDelegate(native_r1);
         if (region1 == null) {
             return false;
@@ -470,7 +470,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static String nativeToString(int native_region) {
+    /*package*/ static String nativeToString(long native_region) {
         Region_Delegate region = sManager.getDelegate(native_region);
         if (region == null) {
             return "not found";
diff --git a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
index 368c0384..70a0a43 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java
@@ -49,7 +49,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Shader_Delegate getDelegate(int nativeShader) {
+    public static Shader_Delegate getDelegate(long nativeShader) {
         return sManager.getDelegate(nativeShader);
     }
 
@@ -76,13 +76,13 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void nativeDestructor(int native_shader, int native_skiaShader) {
+    /*package*/ static void nativeDestructor(long native_shader, long native_skiaShader) {
         sManager.removeJavaReferenceFor(native_shader);
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeSetLocalMatrix(int native_shader, int native_skiaShader,
-            int matrix_instance) {
+    /*package*/ static void nativeSetLocalMatrix(long native_shader, long native_skiaShader,
+            long matrix_instance) {
         // get the delegate from the native int.
         Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
         if (shaderDelegate == null) {
diff --git a/tools/layoutlib/bridge/src/android/graphics/SumPathEffect_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/SumPathEffect_Delegate.java
index 410df0c..6d2e9b4 100644
--- a/tools/layoutlib/bridge/src/android/graphics/SumPathEffect_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/SumPathEffect_Delegate.java
@@ -62,7 +62,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate(int first, int second) {
+    /*package*/ static long nativeCreate(long first, long second) {
         SumPathEffect_Delegate newDelegate = new SumPathEffect_Delegate();
         return sManager.addNewDelegate(newDelegate);
     }
diff --git a/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
index 13ae12e..f2b3e8d 100644
--- a/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/SweepGradient_Delegate.java
@@ -52,25 +52,25 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate1(float x, float y, int colors[], float positions[]) {
+    /*package*/ static long nativeCreate1(float x, float y, int colors[], float positions[]) {
         SweepGradient_Delegate newDelegate = new SweepGradient_Delegate(x, y, colors, positions);
         return sManager.addNewDelegate(newDelegate);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeCreate2(float x, float y, int color0, int color1) {
+    /*package*/ static long nativeCreate2(float x, float y, int color0, int color1) {
         return nativeCreate1(x, y, new int[] { color0, color1 }, null /*positions*/);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate1(int native_shader, float cx, float cy,
+    /*package*/ static long nativePostCreate1(long native_shader, float cx, float cy,
             int[] colors, float[] positions) {
         // nothing to be done here.
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativePostCreate2(int native_shader, float cx, float cy,
+    /*package*/ static long nativePostCreate2(long native_shader, float cx, float cy,
             int color0, int color1) {
         // nothing to be done here.
         return 0;
diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
index b50e98b8..60cd157 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java
@@ -75,7 +75,7 @@
         sPostInitDelegate.clear();
     }
 
-    public static Typeface_Delegate getDelegate(int nativeTypeface) {
+    public static Typeface_Delegate getDelegate(long nativeTypeface) {
         return sManager.getDelegate(nativeTypeface);
     }
 
@@ -83,7 +83,7 @@
         return getFonts(typeface.native_instance);
     }
 
-    public static List<Font> getFonts(int native_int) {
+    public static List<Font> getFonts(long native_int) {
         Typeface_Delegate delegate = sManager.getDelegate(native_int);
         if (delegate == null) {
             return null;
@@ -99,7 +99,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static synchronized int nativeCreate(String familyName, int style) {
+    /*package*/ static synchronized long nativeCreate(String familyName, int style) {
         if (familyName == null) {
             familyName = DEFAULT_FAMILY;
         }
@@ -121,7 +121,7 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static synchronized int nativeCreateFromTypeface(int native_instance, int style) {
+    /*package*/ static synchronized long nativeCreateFromTypeface(long native_instance, int style) {
         Typeface_Delegate delegate = sManager.getDelegate(native_instance);
         if (delegate == null) {
             return 0;
@@ -141,14 +141,14 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static synchronized int nativeCreateFromAsset(AssetManager mgr, String path) {
+    /*package*/ static synchronized long nativeCreateFromAsset(AssetManager mgr, String path) {
         Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                 "Typeface.createFromAsset() is not supported.", null /*throwable*/, null /*data*/);
         return 0;
     }
 
     @LayoutlibDelegate
-    /*package*/ static synchronized int nativeCreateFromFile(String path) {
+    /*package*/ static synchronized long nativeCreateFromFile(String path) {
         if (path.startsWith(SYSTEM_FONTS) ) {
             String relativePath = path.substring(SYSTEM_FONTS.length());
             File f = new File(sFontLoader.getOsFontsLocation(), relativePath);
@@ -177,12 +177,12 @@
     }
 
     @LayoutlibDelegate
-    /*package*/ static void nativeUnref(int native_instance) {
+    /*package*/ static void nativeUnref(long native_instance) {
         sManager.removeJavaReferenceFor(native_instance);
     }
 
     @LayoutlibDelegate
-    /*package*/ static int nativeGetStyle(int native_instance) {
+    /*package*/ static int nativeGetStyle(long native_instance) {
         Typeface_Delegate delegate = sManager.getDelegate(native_instance);
         if (delegate == null) {
             return 0;
diff --git a/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java
index 962d69c..94a6d76 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Xfermode_Delegate.java
@@ -48,7 +48,7 @@
 
     // ---- Public Helper methods ----
 
-    public static Xfermode_Delegate getDelegate(int native_instance) {
+    public static Xfermode_Delegate getDelegate(long native_instance) {
         return sManager.getDelegate(native_instance);
     }
 
@@ -60,7 +60,7 @@
     // ---- native methods ----
 
     @LayoutlibDelegate
-    /*package*/ static void finalizer(int native_instance) {
+    /*package*/ static void finalizer(long native_instance) {
         sManager.removeJavaReferenceFor(native_instance);
     }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
index ae1217d..261cc98 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
@@ -94,7 +94,7 @@
      * @param native_object the native int.
      * @return the delegate or null if not found.
      */
-    public T getDelegate(int native_object) {
+    public T getDelegate(long native_object) {
         if (native_object > 0) {
             T delegate =  mDelegates.get(native_object);
 
@@ -116,8 +116,8 @@
      * @param newDelegate the delegate to add
      * @return a unique native int to identify the delegate
      */
-    public int addNewDelegate(T newDelegate) {
-        int native_object = ++mDelegateCounter;
+    public long addNewDelegate(T newDelegate) {
+        long native_object = ++mDelegateCounter;
         mDelegates.put(native_object, newDelegate);
         assert !mJavaReferences.contains(newDelegate);
         mJavaReferences.add(newDelegate);
@@ -133,7 +133,7 @@
      * Removes the main reference on the given delegate.
      * @param native_object the native integer representing the delegate.
      */
-    public void removeJavaReferenceFor(int native_object) {
+    public void removeJavaReferenceFor(long native_object) {
         T delegate = getDelegate(native_object);
 
         if (Debug.DEBUG) {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/SparseWeakArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/SparseWeakArray.java
index 4d0c9ce..53e1640 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/SparseWeakArray.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/util/SparseWeakArray.java
@@ -30,13 +30,14 @@
  *
  * The code is taken from {@link SparseArray} directly and adapted to use weak references.
  *
- * Because our usage means that we never actually call {@link #remove(int)} or {@link #delete(int)},
- * we must manually check if there are reclaimed references to trigger an internal compact step
- * (which is normally only triggered when an item is manually removed).
+ * Because our usage means that we never actually call {@link #remove(long)} or
+ * {@link #delete(long)}, we must manually check if there are reclaimed references to
+ * trigger an internal compact step (which is normally only triggered when an item is manually
+ * removed).
  *
- * SparseArrays map integers to Objects.  Unlike a normal array of Objects,
+ * SparseArrays map integral values to Objects.  Unlike a normal array of Objects,
  * there can be gaps in the indices.  It is intended to be more efficient
- * than using a HashMap to map Integers to Objects.
+ * than using a HashMap to map Integers (or Longs) to Objects.
  */
 @SuppressWarnings("unchecked")
 public class SparseWeakArray<E> {
@@ -58,9 +59,9 @@
      * number of mappings.
      */
     public SparseWeakArray(int initialCapacity) {
-        initialCapacity = ArrayUtils.idealIntArraySize(initialCapacity);
+        initialCapacity = ArrayUtils.idealLongArraySize(initialCapacity);
 
-        mKeys = new int[initialCapacity];
+        mKeys = new long[initialCapacity];
         mValues = new WeakReference[initialCapacity];
         mSize = 0;
     }
@@ -69,7 +70,7 @@
      * Gets the Object mapped from the specified key, or <code>null</code>
      * if no such mapping has been made.
      */
-    public E get(int key) {
+    public E get(long key) {
         return get(key, null);
     }
 
@@ -77,7 +78,7 @@
      * Gets the Object mapped from the specified key, or the specified Object
      * if no such mapping has been made.
      */
-    public E get(int key, E valueIfKeyNotFound) {
+    public E get(long key, E valueIfKeyNotFound) {
         int i = binarySearch(mKeys, 0, mSize, key);
 
         if (i < 0 || mValues[i] == DELETED || mValues[i].get() == null) {
@@ -90,7 +91,7 @@
     /**
      * Removes the mapping from the specified key, if there was any.
      */
-    public void delete(int key) {
+    public void delete(long key) {
         int i = binarySearch(mKeys, 0, mSize, key);
 
         if (i >= 0) {
@@ -102,9 +103,9 @@
     }
 
     /**
-     * Alias for {@link #delete(int)}.
+     * Alias for {@link #delete(long)}.
      */
-    public void remove(int key) {
+    public void remove(long key) {
         delete(key);
     }
 
@@ -121,7 +122,7 @@
     private void gc() {
         int n = mSize;
         int o = 0;
-        int[] keys = mKeys;
+        long[] keys = mKeys;
         WeakReference<?>[] values = mValues;
 
         for (int i = 0; i < n; i++) {
@@ -142,9 +143,9 @@
         mGarbage = false;
         mSize = o;
 
-        int newSize = ArrayUtils.idealIntArraySize(mSize);
+        int newSize = ArrayUtils.idealLongArraySize(mSize);
         if (newSize < mKeys.length) {
-            int[] nkeys = new int[newSize];
+            long[] nkeys = new long[newSize];
             WeakReference<?>[] nvalues = new WeakReference[newSize];
 
             System.arraycopy(mKeys, 0, nkeys, 0, newSize);
@@ -160,7 +161,7 @@
      * replacing the previous mapping from the specified key if there
      * was one.
      */
-    public void put(int key, E value) {
+    public void put(long key, E value) {
         int i = binarySearch(mKeys, 0, mSize, key);
 
         if (i >= 0) {
@@ -182,9 +183,9 @@
             }
 
             if (mSize >= mKeys.length) {
-                int n = ArrayUtils.idealIntArraySize(mSize + 1);
+                int n = ArrayUtils.idealLongArraySize(mSize + 1);
 
-                int[] nkeys = new int[n];
+                long[] nkeys = new long[n];
                 WeakReference<?>[] nvalues = new WeakReference[n];
 
                 // Log.e("SparseArray", "grow " + mKeys.length + " to " + n);
@@ -224,7 +225,7 @@
      * the key from the <code>index</code>th key-value mapping that this
      * SparseArray stores.
      */
-    public int keyAt(int index) {
+    public long keyAt(int index) {
         if (mGarbage) {
             gc();
         }
@@ -263,7 +264,7 @@
      * specified key, or a negative number if the specified
      * key is not mapped.
      */
-    public int indexOfKey(int key) {
+    public int indexOfKey(long key) {
         if (mGarbage) {
             gc();
         }
@@ -310,7 +311,7 @@
      * Puts a key/value pair into the array, optimizing for the case where
      * the key is greater than all existing keys in the array.
      */
-    public void append(int key, E value) {
+    public void append(long key, E value) {
         if (mSize != 0 && key <= mKeys[mSize - 1]) {
             put(key, value);
             return;
@@ -322,9 +323,9 @@
 
         int pos = mSize;
         if (pos >= mKeys.length) {
-            int n = ArrayUtils.idealIntArraySize(pos + 1);
+            int n = ArrayUtils.idealLongArraySize(pos + 1);
 
-            int[] nkeys = new int[n];
+            long[] nkeys = new long[n];
             WeakReference<?>[] nvalues = new WeakReference[n];
 
             // Log.e("SparseArray", "grow " + mKeys.length + " to " + n);
@@ -350,7 +351,7 @@
         return false;
     }
 
-    private static int binarySearch(int[] a, int start, int len, int key) {
+    private static int binarySearch(long[] a, int start, int len, long key) {
         int high = start + len, low = start - 1, guess;
 
         while (high - low > 1) {
@@ -370,7 +371,7 @@
             return ~high;
     }
 
-    private int[] mKeys;
+    private long[] mKeys;
     private WeakReference<?>[] mValues;
     private int mSize;
 }
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 3dda56a..cf1669c 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -245,25 +245,26 @@
             mWifiStateMachine = wifiStateMachine;
         }
 
-        @Override
-        public void addressUpdated(String address, String iface, int flags, int scope) {
-            if (mWifiStateMachine.mInterfaceName.equals(iface)) {
-                if (DBG) {
-                    log("addressUpdated: " + address + " on " + iface +
-                        " flags " + flags + " scope " + scope);
-                }
-                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_UPDATED, new LinkAddress(address));
+        private void maybeLog(String operation, String iface, LinkAddress address) {
+            if (DBG) {
+                log(operation + ": " + address + " on " + iface +
+                    " flags " + address.getFlags() + " scope " + address.getScope());
             }
         }
 
         @Override
-        public void addressRemoved(String address, String iface, int flags, int scope) {
+        public void addressUpdated(String iface, LinkAddress address) {
             if (mWifiStateMachine.mInterfaceName.equals(iface)) {
-                if (DBG) {
-                    log("addressRemoved: " + address + " on " + iface +
-                        " flags " + flags + " scope " + scope);
-                }
-                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_REMOVED, new LinkAddress(address));
+                maybeLog("addressUpdated", iface, address);
+                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_UPDATED, address);
+            }
+        }
+
+        @Override
+        public void addressRemoved(String iface, LinkAddress address) {
+            if (mWifiStateMachine.mInterfaceName.equals(iface)) {
+                maybeLog("addressRemoved", iface, address);
+                mWifiStateMachine.sendMessage(CMD_IP_ADDRESS_REMOVED, address);
             }
         }
     }